commit cf5fe03033701c91e73137644c47af8826e1c298 Author: Anson Yu Date: Mon Jun 22 17:49:02 2020 +0800 first commit diff --git a/CSA.sql b/CSA.sql new file mode 100644 index 0000000..4c26e61 --- /dev/null +++ b/CSA.sql @@ -0,0 +1,535 @@ +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- 数据库: `CSA` +-- + +-- -------------------------------------------------------- + +-- +-- 表的结构 `capturepet` +-- + +CREATE TABLE IF NOT EXISTS `capturepet` ( + `unicode` varchar(32) NOT NULL, + `id` int(11) NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `type` int(11) NOT NULL, + `lv` int(11) NOT NULL, + `hp` int(11) NOT NULL, + `attack` int(11) NOT NULL, + `def` int(11) NOT NULL, + `quick` int(11) NOT NULL, + `sum` double NOT NULL, + `author` varchar(32) CHARACTER SET gbk NOT NULL, + `cdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `check` tinyint(1) NOT NULL DEFAULT '0', + `inserttime` datetime NOT NULL, + PRIMARY KEY (`unicode`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `CashDraw` +-- + +CREATE TABLE IF NOT EXISTS `CashDraw` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `type` varchar(16) NOT NULL, + `point` int(11) NOT NULL, + `fixtime` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `check` +-- + +CREATE TABLE IF NOT EXISTS `check` ( + `itemcode` varchar(64) NOT NULL, + `cdkey` varchar(32) NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `mac` varchar(64) NOT NULL, + `type` varchar(32) CHARACTER SET gbk NOT NULL, + `value` int(11) NOT NULL, + `time` datetime NOT NULL, + `check` tinyint(4) NOT NULL DEFAULT '0', + `usecdkey` varchar(32) DEFAULT NULL, + `usename` varchar(32) CHARACTER SET gbk DEFAULT NULL, + `usemac` varchar(64) DEFAULT NULL, + `usetime` datetime DEFAULT NULL, + PRIMARY KEY (`itemcode`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `consignment` +-- + +CREATE TABLE IF NOT EXISTS `consignment` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) COLLATE gb2312_bin NOT NULL, + `name` varchar(32) COLLATE gb2312_bin NOT NULL, + `alive` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `time` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `counter` +-- + +CREATE TABLE IF NOT EXISTS `counter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `type` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `alive` int(11) NOT NULL, + `fame` int(11) NOT NULL, + `fixtime` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `CSAinfo` +-- + +CREATE TABLE IF NOT EXISTS `CSAinfo` ( + `cdkey` varchar(32) CHARACTER SET gbk NOT NULL, + `saveindex` int(11) NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `famename` varchar(32) CHARACTER SET gbk COLLATE gbk_bin NOT NULL, + `CE` int(16) NOT NULL DEFAULT '0', + `level` int(11) NOT NULL, + `trans` int(11) NOT NULL, + `alive` int(11) NOT NULL, + `cameo` int(11) NOT NULL, + `fame` int(11) NOT NULL, + `TITLE_LV` int(11) NOT NULL, + `DUELBATTLECOUNT` int(11) NOT NULL, + `DUELWINCOUNT` int(11) NOT NULL, + `DUELLOSECOUNT` int(11) NOT NULL, + `DUELSTWINCOUNT` int(11) NOT NULL, + `DUELSTLOSECOUNT` int(11) NOT NULL, + `DUELMAXSTWINCOUNT` int(11) NOT NULL, + `RESETPETCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '洗宠次数', + `AWAKEPETCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '变异次数', + `SEALEVNTCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '任务封印次数', + `TRANSPETCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '转宠次数', + `KILLBOSSCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '击杀BOSS次数', + `BOSSKILLCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '被BOSS杀次数', + `CAPPETCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '抓宠次数', + `FEEDMMCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '练MM次数', + `EQUIPUPCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '强化成功次数', + `EQUIPFAILCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '强化失败次数', + `MAGICADDCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '附魔次数', + `HORSEWINCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '跑马押中次数', + `HUNTFISHCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '捕鱼次数', + `HUNTBIGFISHCOUNT` int(16) NOT NULL DEFAULT '0' COMMENT '大鱼次数', + `vip` int(11) NOT NULL, + `time` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `CSAlogin` +-- + +CREATE TABLE IF NOT EXISTS `CSAlogin` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `Name` varchar(32) CHARACTER SET gbk NOT NULL, + `PassWord` varchar(32) CHARACTER SET gbk NOT NULL, + `IP` varchar(16) NOT NULL DEFAULT '-', + `MAC` varchar(64) NOT NULL, + `RegTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `LoginTime` datetime DEFAULT '0000-00-00 00:00:00', + `OnlineName` varchar(32) CHARACTER SET gbk DEFAULT NULL, + `OnlineName1` varchar(30) CHARACTER SET gbk DEFAULT NULL, + `OnlineName2` varchar(32) CHARACTER SET gbk DEFAULT NULL, + `Online` tinyint(4) DEFAULT '0', + `Path` varchar(16) DEFAULT '', + `CE` int(16) NOT NULL DEFAULT '0', + `VipPoint` int(11) DEFAULT '0', + `PayPoint` int(11) NOT NULL, + `GamblePoint` int(11) NOT NULL, + `TrialPoint` int(16) NOT NULL DEFAULT '0', + `GoldPoint` int(16) NOT NULL DEFAULT '0', + `SQLPoint` int(16) NOT NULL DEFAULT '0', + `SafePasswd` varchar(32) DEFAULT '', + `ServerId` int(4) NOT NULL DEFAULT '0', + `Regip` varchar(32) NOT NULL, + `qq` varchar(32) NOT NULL, + `tel` varchar(32) NOT NULL, + `ServerName` varchar(32) NOT NULL, + `Recommender` int(11) NOT NULL, + `Lock` int(4) NOT NULL DEFAULT '0', + `LockTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `LockInfo` varchar(32) NOT NULL DEFAULT '', + `Offline` tinyint(4) NOT NULL DEFAULT '0', + `Trust` tinyint(4) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `Name` (`Name`) +) ENGINE=MyISAM DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `dice` +-- + +CREATE TABLE IF NOT EXISTS `dice` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `type` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `alive` int(11) NOT NULL, + `fame` int(11) NOT NULL, + `dicenum` int(11) NOT NULL, + `fixtime` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `dicelog` +-- + +CREATE TABLE IF NOT EXISTS `dicelog` ( + `type` int(11) NOT NULL DEFAULT '0', + `winpoint` int(11) NOT NULL DEFAULT '0', + `losepoint` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`type`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `loan` +-- + +CREATE TABLE IF NOT EXISTS `loan` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `PetName` varchar(32) CHARACTER SET gb2312 NOT NULL, + `PetInfo` varchar(512) CHARACTER SET gb2312 NOT NULL, + `PetString` varchar(2048) CHARACTER SET gb2312 NOT NULL, + `day` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `stat` int(11) NOT NULL DEFAULT '0', + `loancdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `loanname` varchar(32) CHARACTER SET gb2312 NOT NULL, + `fixtime` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `LOCK` +-- + +CREATE TABLE IF NOT EXISTS `LOCK` ( + `Name` varchar(64) NOT NULL, + `LockTime` datetime NOT NULL, + PRIMARY KEY (`Name`) +) ENGINE=MyISAM DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `OnlineBuy` +-- + +CREATE TABLE IF NOT EXISTS `OnlineBuy` ( + `CostPasswd` varchar(32) NOT NULL, + `CostStr` varchar(64) DEFAULT NULL, + `cdkey` varchar(32) DEFAULT NULL, + `CostTime` datetime DEFAULT NULL, + `check` tinyint(1) DEFAULT '1', + PRIMARY KEY (`CostPasswd`) +) ENGINE=MyISAM DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `OnlineCard` +-- + +CREATE TABLE IF NOT EXISTS `OnlineCard` ( + `CostPasswd` varchar(32) NOT NULL, + `CostStr` varchar(64) DEFAULT NULL, + `cdkey` varchar(32) DEFAULT NULL, + `CostTime` datetime DEFAULT NULL, + `check` tinyint(1) DEFAULT '1', + PRIMARY KEY (`CostPasswd`) +) ENGINE=MyISAM DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `OnlineCost` +-- + +CREATE TABLE IF NOT EXISTS `OnlineCost` ( + `CostPasswd` varchar(32) NOT NULL, + `CostVal` int(11) NOT NULL, + `PayVal` int(11) NOT NULL, + `cdkey` varchar(32) DEFAULT '', + `CostTime` datetime NOT NULL, + `check` tinyint(1) NOT NULL DEFAULT '1', + `creator` varchar(32) DEFAULT NULL, + UNIQUE KEY `CostPasswd` (`CostPasswd`) +) ENGINE=MyISAM DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `OnlinePlayer` +-- + +CREATE TABLE IF NOT EXISTS `OnlinePlayer` ( + `cdkey` varchar(32) NOT NULL, + `MAC` varchar(64) NOT NULL, + `Name` varchar(32) NOT NULL, + `LoginTime` datetime NOT NULL, + `ServerId` int(11) NOT NULL, + PRIMARY KEY (`cdkey`) +) ENGINE=InnoDB DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `PauctionInfo` +-- + +CREATE TABLE IF NOT EXISTS `PauctionInfo` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) CHARACTER SET gbk NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `effect` varchar(1024) CHARACTER SET gbk NOT NULL, + `cost` int(11) NOT NULL, + `type` int(11) NOT NULL, + `info` varchar(1024) CHARACTER SET gbk NOT NULL, + `string` varchar(1024) CHARACTER SET gb2312 NOT NULL, + `day` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `petbilling` +-- + +CREATE TABLE IF NOT EXISTS `petbilling` ( + `id` int(11) NOT NULL, + `type` tinyint(4) NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `lv` int(11) NOT NULL, + `hp` int(11) NOT NULL, + `attack` int(11) NOT NULL, + `def` int(11) NOT NULL, + `quick` int(11) NOT NULL, + `author` varchar(32) CHARACTER SET gb2312 NOT NULL, + PRIMARY KEY (`id`,`type`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `pklist` +-- + +CREATE TABLE IF NOT EXISTS `pklist` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `player1` varchar(32) CHARACTER SET gb2312 NOT NULL, + `player2` varchar(32) CHARACTER SET gb2312 NOT NULL, + `player3` varchar(32) CHARACTER SET gb2312 NOT NULL, + `player4` varchar(32) CHARACTER SET gb2312 NOT NULL, + `player5` varchar(32) CHARACTER SET gb2312 NOT NULL, + `seesion` int(11) NOT NULL, + `stat` int(11) NOT NULL DEFAULT '0', + UNIQUE KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `safedata` +-- + +CREATE TABLE IF NOT EXISTS `safedata` ( + `cdkey` varchar(32) NOT NULL DEFAULT '', + `newsafe` varchar(64) DEFAULT NULL, + `oldsafe` varchar(64) DEFAULT NULL, + `flg` int(1) NOT NULL, + `FixTime` datetime NOT NULL, + PRIMARY KEY (`cdkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `SaleVipPoint` +-- + +CREATE TABLE IF NOT EXISTS `SaleVipPoint` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `Vippoint` int(11) NOT NULL, + `rate` int(11) NOT NULL, + `price` int(11) NOT NULL, + `stat` int(11) NOT NULL, + `CreateTime` datetime NOT NULL, + `PayTime` datetime NOT NULL, + `banktype` varchar(32) CHARACTER SET gb2312 NOT NULL DEFAULT '', + `bankcdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `bankname` varchar(8) CHARACTER SET gb2312 NOT NULL, + `QQ` varchar(11) CHARACTER SET gb2312 NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `SuperStar` +-- + +CREATE TABLE IF NOT EXISTS `SuperStar` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `award` varchar(32) CHARACTER SET gb2312 NOT NULL, + `check` int(11) NOT NULL, + `datatime` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `transpointlog` +-- + +CREATE TABLE IF NOT EXISTS `transpointlog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `incdkey` varchar(32) DEFAULT NULL, + `outcdkey` varchar(32) DEFAULT NULL, + `type` varchar(32) DEFAULT NULL, + `inpoint` int(11) DEFAULT '0', + `outpoint` int(11) DEFAULT '0', + `datetime` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=gb2312; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `VipShop` +-- + +CREATE TABLE IF NOT EXISTS `VipShop` ( + `cdkey` varchar(32) COLLATE gb2312_bin NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `itemid` int(11) NOT NULL, + `itemname` varchar(32) CHARACTER SET gb2312 NOT NULL, + `itemnum` int(11) NOT NULL, + `totalcost` int(16) NOT NULL, + `time` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `weekpay` +-- + +CREATE TABLE IF NOT EXISTS `weekpay` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `term` int(11) NOT NULL, + `cdkey` varchar(32) NOT NULL, + `itemid` int(11) NOT NULL, + `check` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `YamaKing` +-- + +CREATE TABLE IF NOT EXISTS `YamaKing` ( + `index` int(13) NOT NULL AUTO_INCREMENT, + `cdkey` varchar(32) CHARACTER SET gbk NOT NULL, + `name` varchar(32) CHARACTER SET gbk NOT NULL, + `floor` int(16) NOT NULL, + `itemid` int(16) NOT NULL, + `itemname` varchar(16) CHARACTER SET gbk NOT NULL, + `time` datetime NOT NULL, + `mac` varchar(64) CHARACTER SET gbk NOT NULL, + `servername` varchar(32) CHARACTER SET gbk NOT NULL, + PRIMARY KEY (`index`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `yuxiaxie` +-- + +CREATE TABLE IF NOT EXISTS `yuxiaxie` ( + `date` date NOT NULL, + `cdkey` varchar(32) CHARACTER SET gb2312 NOT NULL, + `name` varchar(32) CHARACTER SET gb2312 NOT NULL, + `type` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `fame` int(11) NOT NULL, + `alive` int(11) NOT NULL, + `fixtime` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `yuxiaxielog` +-- + +CREATE TABLE IF NOT EXISTS `yuxiaxielog` ( + `date` date NOT NULL, + `type` int(11) NOT NULL, + `vippoint` int(11) NOT NULL, + `alive` int(11) NOT NULL, + `fame` int(11) NOT NULL, + `sumvippoint` int(11) NOT NULL, + `sumalive` int(11) NOT NULL, + `sumfame` int(11) NOT NULL, + `fixtime` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/acserv.cf b/acserv.cf new file mode 100644 index 0000000..c122ebe --- /dev/null +++ b/acserv.cf @@ -0,0 +1,138 @@ +CPUUSE 2 +############################## +#SAAC基本参数设置 +# 帐户服务器端卿 +port 10001 + +# 帐户服务器密瞿 +pass test + +# rotale_internal +rotale_internal 1000 + +# dbdir文件目录 +dbdir data + +# LOG文件目录 +logdir log + +# LOCK文件目录 +lockdir lock + +# CHAR文件目录 +chardir char + +# CHAR_SLEEP文件目录 +sleepchardir char_sleep + +# WKLOG文件目录 +wklogdir data/wklog + +# MAIL文件目录 +maildir mail + +# family文件目录 +familydir data/family + +# fmpoint文件目录 +fmpointdir data/fmpointdir + +# fmsmemo文件目录 +fmsmemodir data/fmsmemodir + +# SA名称 +SANAME Test + +# LSADDRESS +LSADDRESS localhost + +# LS端口 +LSPORT 3334 + +# TEST名称 +TESTNAME Test + +# OACBIND +OACBIND + +# 星系名称 +saacname Test + +############################## +# 更新人物点数间隔xx祿 +Total_Charlist 3600 +# 更新进期邮件间隔xx祿 +Expired_mail 600 +# 删除家族成员间隔xx祿 +Del_Family_or_Member 3600 +# 更新家族信息间隔xx祿 +Write_Family 600 + +############################## +#MYSQL基本配置 +#ifdef _SASQL +#sql服务器IP +sql_IP 127.0.0.1 +#sql服务器端卿 +sql_Port 3306 +#sql服务器账卿 +sql_ID root +#sql服务器密瞿 +sql_PS 123456 +#sql数据库名 +sql_DataBase CSA +#sql人物信息表名 +sql_Table CSAlogin +#sql用户名字欿 +sql_NAME Name +#sql密码字段县 +sql_PASS PassWord +#sql锁定账号表名 +sql_LOCK LOCK + +########后台功能############ +#是台开始后台功聿 +openbackground 1 +#openbackground值为1则开始以下功聿 +sql_RegIP IP +sql_RegTime RegTime +sql_LoginTime LoginTime +sql_Path Path +sql_OnlineName OnlineName + +#禁止多少天未上线的账号登闿 +uLoginDay 60 + +############################ + +#是否限制同一IP登陆次数(0为不限制) +SameIpMun 0 + + +#是否使用MD5(0为否ﺿ为是) +USEMD5 0 + +#每隔几天自动备份一次数拿 +AUTOBACKUPDAY 1 + +#几点进行自动备份 +AUTOBACKUPHOUR 2 + +#是否自动注册 +AutoReg 0 + +#六合彩间格时长墿 +LOTTERYSYSTEM 1000 + +#充值积分倍数 +DoublePayPoint 1 + +#IP验证 +ip1 127.0.0.1 +ip2 127.0.0.2 +ip3 127.0.0.3 +ip4 127.0.0.4 +ip5 127.0.0.5 + +savezip 1 +#endif diff --git a/setup.cf b/setup.cf new file mode 100644 index 0000000..0504e3c --- /dev/null +++ b/setup.cf @@ -0,0 +1,795 @@ +#ChangeRunLevel +#еȼ Χ-20~19 -20м +runlevel=0 + +#ܵڣŵCPUʹʴЩֵЩ +CPUUSE=1 + +#recvbufferʾÿҽջС Χ0K-128K +recvbuffer=64 +#recvbufferʾÿҷͻС Χ0K-128K +sendbuffer=64 +#readbufferʾÿҽջ Χ128-1024 +recvlowatbuffer=128 + +# Debug Level 0 for none +#Եȼ +#õֵΪ013 +#0κδ +#1: ֻؼ 󽫺 +#3д +debuglevel=3 + +#ѭʱ +charlooptime=3 + +#ص½ߺ +LOGINNOKICK=1 + +#ת +CTRLTRANS=1 + +#ڰھǰ[][] +FMMAGICMPRATE1=0.2 +FMMAGICMPRATE2=0.2 + +#Ż,ԭ״̬VS(1ȫ,2˿,3Ա,0ر) +VSFLG=1 + +#ʱõ +Connectnum=40 +PetEnemyDevelopUp=0 + +#Ź +NOATTTYPE=0 +NOATTTIME=15 + +#ͼ +NOFAMEMAP=34567 + +#˵С +TALKMIN=2 + +#˵ +TALKMAX=3 + +#徫0ת100² +NOMPMAGIC=,10, + +#ǰ·ս +FMWARPLAYERNUM=50 + +#·սʾ +FMWARPLAYERNUMBUFF=ʯһ,50,ʯPK,60,ʯPK,80,ʯPK,100,ʯPK,200 + +#ԭʱ +BATTLESPEED=2000 +#սغӳ() +battletime=200 + +ģʽ0ΪĬϣ1ΪԶ壩 +PETUPGETEXP=1 + +#ߵһνԶ +FirstLockItem=1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + +#˺̶(ĬΪ100) +dammagecalc=85 + +#ˢNPCãRELOADNPCTIME*10 0Ϊر ֵ10000 RELOADNPCTYPE 0Ϊر 1Ϊ͵ǰ꣩ +RELOADNPCTIME=0 +RELOADNPCTYPE=1 + +#####################################ȫ##################################### +#IP +NOATTIP1= +NOATTIP2= +NOATTIP3= +NOATTIP4= +NOATTIP5= + + +#˿ڷ +MANRENNUM=500 +#ԱϷе,ʱ,FENGTYPE 1 Աݿ 2 Աݿ 3 ֻTˣ +NOFULLPLAYER=100 +NOFULLTIME=5 +FENGTYPE=1 +#˺ţ10+6+?,NOCDKEYMODE 0Ϊر 1ΪID 2Ϊ˺,NOCDKEYTYPE 0ΪԱݿ 1ΪԱݿ⣩ +NOCDKEYPLAYER=50 +NOCDKEYMODE=1 +NOCDKEYTYPE=1 + +#ȷ(¼ǰ,0ǶԱݿ,1DzԱݿ) +RIGHTNUM=4000 +RIGHTMODE=0 +#¼ǰ +BIGBAO=300 +#½ +BIGBAO2=800 + + +#սNPC͵߶Ի֤𰸷Χ +TALKCHECKMIN=50 +TALKCHECKMAX=100 + +#IP +serverip=127.0.0.1,120.25.121.212,58.96.187.218,115.28.12.42,101.200.174.216 +#ͬһIP½ +sameiponlinenum=2 + +#ITEMPETLOCKED=0ʱʹðȫ +ITEMPETLOCKED=1 + +####################################̯###################################### + +#תſ԰̯ +streetvendortrans=0 +#ð̯ÿγɹ˰շ(λ:%) +STREETVENDORPOINT=0,0,0,0 + +########################################################################## + +#ʹƵ +#ת +ALLSERVTRANS=5 +#ȼ +ALLSERVLEVEL=140 +# +ALLSERVSNED=10000 + +#ʹƵ +THEWORLDTRANS=1 +THEWORLDLEVEL=100 +THEWORLDSNED=10 + +#ÿ/SAVEһ +SAVEFAME=0 + +##################################ͼ####################################### + +#HELPĵͼ +nohelpmap=40001,40002,40003,40004,40005,40006,40007,40008,40009,40010,33020,33040,33060,33080,33100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#صʱPK +PLAYEROVERLAPPK=-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#ֹܵĵͼ +NOTESCAPE=12345,140,40001,40002,40003,40004,40005,40006,40007,40008,40009,40010,8252,8253,8254,8256,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#ֹԭǵͼ +UNLAWTHISLOGOUT=-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#ֹӵͼ +NOJOINFLOOR=33020,33040,33060,33080,33100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#ͼսԶָ +MAPHEAL=2000,40001,40002,40003,40004,40005,40006,40007,40008,40009,40010,40011,2005,3000,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + +###################################ת####################################### + +#תǷȡж(10) +CANCELANGLETRANS=1 +#ٻʱ(ANGELPLAYERTIME/) +ANGELPLAYERTIME=5000 +#ٻ(СΪ2) +ANGELPLAYERMUN=1000 + +########################################################################### + +#óתֵ +#ѡdzתתӵ2һתͼ2ת򷭱4 +#Ĭ0 +PETTRANSABILITY=0 +#Ƿһתתɳ +#һתĬ200 +PETTRANSABILITY1=180 +#תĬ200 +PETTRANSABILITY2=200 + +#輼ƷLUAжϽű· +PETSKILLSHOPPATH=data/ablua/freepetskillshop.lua + +#DELNEEDITEM=0ʱ,ץƷԶɾ +DELNEEDITEM=1 + +#ʲô(̱) +NOENEMYIDGROUP=1661,1662,1663,1664 + +###################################ս###################################### + +#ԶսƬʱ,ռ,-1Ϊսʱ䣨ʱã +FIMALYPKTIME=20 + +########################################################################## + +#ֹҿ(0Ϊı,1Ϊֹ,2Ϊҿʱ,Զԭ) +NOSTWENEMY=0 +#NOSTWENEMY=2ʱ,ÿγɹԶ۳ʯҵ +NOSTWENEMYGOLD=0 + +#ʹ˲ +#-1Ϊرմ˹,0Ϊ,1Ϊʯ,2Ϊ,3ΪĻ,4Ϊ,5Ϊڣģ +STWSENDTYPE=2 +#ʹƹ˲ĵ +STWSENDPOINT=100 + +#Ƿֿ߲ǿ +#0Ϊǿ +#1Ϊֿǿ⵫ֿͬⲻǿ +#2Ϊֿͬǿ⵫ֿⲻǿ +#3ֹǿ +POOLITEMBUG=3 + +###################################Ա##################################### + +#Ա鱶 +vipbattleexp=1 + +#ǷѷΪԱʱר(10) +VIPBOUNDTIME=0 +#VIPBOUNDTIME=1ʱЧ +UNBOUNDTIMETRANS=0 +UNBOUNDTIMELEVEL=120 +#תȼԽãֻõͼ +UNBOUNDTIMEMAP=2000,65,65 + +######################################################################## + + +#սƷѡ +#սƷ(ԽǰԽ) +BATTLEGETITEMRATE=-1 +#սƷͼ +BATTLEGETITEMRATEMAP=0 + + +#ǹ趨data/luckstar.txt +#Ǵʱ(λ10)(1Сʱ) +LUCKSTARTIME=-1 +#Ǵ¼ɹ(60%ɹ) +LUCKSTARCHANCES=100 + +#PKÿ켸㿪ʼ(-1) +AUTOPK=-1 +#μʸת볡 +AUTOPKTRANS=1 +#μʸȼ볡 +AUTOPKLV=100 +#迪ʼͻ +AUTOPKPOINT=100 +#ÿɱһ˻û +KILLPOINT=10 + +#ԱPKͼ۵(ͼ˳11111,22222,33333,44444) +PKMAP=10,20,30,40 +#ԱPKÿʤȡ +PKMAPCOST=10 + +###################################Σѡ##################################### + + +#ǿBTǧBT +#ÿɳֵ +BTPET=1 +#ֵ() +BTITEM=1 + +#ɾָIDij(ɶ30) +AUTODELPET=-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +#ɾָIDĵ(ɶ30) +AUTODELITEM=-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + +#ͼ(ŵͼ) +SPECIALMAP=-1,-1,-1,-1 + +###################################ϵͳ##################################### + +#ʾ +#0½Աʾʹ +#1ʹõ½ͻԱʾ +#2ʹõ½浫ʹûԱʾ +#3Աʾ½һԱʾ +LOGINDISPLAY=3 + +#ֳټµij +RIDEPETLEVEL=140 + +#˳ټӵʱ(Сʱ) +JOINFAMILYTIME=0 + +#Ƿ(1Ϊ,0Ϊ) +CHECKPEPEAT=0 + +#ںǷת +#(0ת1Ϊ1תֻ2ת) +FUSIONBEIT=1 + +#ҲƵʱ +ENEMYACTION=3 + +#ׯ԰廥ׯ԰ģʽ +FMPOINTPK=0 + +#ģʽ +#0Ϊ8.0 +#1Ϊ2.0֤ģʽ(ڰ챩) +#2Ϊ2.0֤ģʽ(ڰ챩) +#3 +RIDEMODE=0 + +#Զ(++) +PLAYERNUM=0 + +#ֳɻûԱ +GIVEVIPPOINT=0 + +#սýǮ(ȼı) +BATTLEGOLD=0 + +#VIPֶʾ +#0ΪʾVIP +#1ΪڼʾVIP +#2ΪʾVIP +SHOWVIP=1 + +#ʹô˲ÿ(-1Ϊر) +PMOVE=0 +#ʹСÿ(-1Ϊر) +PANNOUNCE=1 +#ħʯʱ䱶(ʱ0.1*)--ʧЧ +CHARLOOPS=1 + +#Զȼ +RIDELEVEL=5 +#Զת +RIDETRANS=1 + +#Զ +SKILLUPPOINT=3 + +#ÿת޶(-1ʾĬ) +TRANSPOINTUP=-1,-1,-1,-1,-1,610,-1 +#ֹ޸(POINT=0ʱ,ÿתЧ) +POINT=1 +#ɳԽ(ָʹöף) +TRANS0=5 +TRANS1=10 +TRANS2=15 +TRANS3=20 +TRANS4=30 +TRANS5=40 +TRANS6=5 +TRANS7=5 + +#ѭѭʱ() +ANNOUNCETIME=30 +#ѭ· +ANNOUNCEPATH=loopannounce.txt + +#Ƿеͼǿս(1Ϊ0Ϊ) +BATTLEFLOOR=0 +#ǿսͼ +BATTLEFLOORCF=-1,-1,-1,-1,-1 + +#Ƿеͼɹս +WATCHFLOOR=0 +#Զɹսͼ +WATCHFLOOR1= +WATCHFLOOR2= +WATCHFLOOR3= +WATCHFLOOR4= +WATCHFLOOR5= + +#ijǷԸ˼(0Ϊ1Ϊ) +PETUP=1 +#ĵǷԸ˼(0Ϊ1Ϊ) +ITEMUP=1 + +#ýֹʹְҵܵĵͼ +DISABLEPROFESSION=2000,100 + +#ֹIPļ +LOCKIP=lockip.txt + +#ֹһഫ͵ +UNLAWWARPFLOOR=32021,8213,850,30695,60034,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + +#ֹʹ(ԭϵͳ֧) +NAME1= +NAME2= +NAME3= +NAME4= +NAME5= + +#ֹʹ(֧32ŷָ) +ILLEGALNAME=GM,ͷ,ٷ, + +#Զȼ +USEREXP=data/exp.txt + +#תɳԽһȼﵽ߼(Ŀǰ汾160) +#ת +CHARTRANS=5 +#ת(ںϳҲܴﵽߵȼ)(Ϊ-1) +PETTRANS=0 + +#ҵȼԽȼʱԭȼ +REVLEVEL=1 +#ȼ +MAXLEVEL=140 +#һȼ +LEVEL=120 + +#սþ鱶 +battleexp=1 + +#Զת +TRANS=0 + +#Զȼ +LV=1 + +#Զ(1Ϊͻ2Ϊף3Ϊͻ) +NPRIDE=1 +#Զ +PET1=-1 +PET2=-1 +PET3=-1 +PET4=-1 + +#ԶƷ +ITEM1=23757 +ITEM2=22144 +ITEM3=20626 +ITEM4=30008 +ITEM5= +ITEM6= +ITEM7= +ITEM8= +ITEM9= +ITEM10= +ITEM11= +ITEM12= +ITEM13= +ITEM14= +ITEM15= + +#Զȼ +PETLV=1 + +#ԶǮ +GOLD=100000 + +# Size of unit that will allocate +#ÿڴ浥ԪС λֽ +usememoryunit=128 + +# Number of unit +#жٸڴ浥Ԫ +usememoryunitnum=16000000 + +#GMSVռڴʽΪ (usememoryunit*usememoryunitnum)/(1024*1024) + + +# Account Server Name +# ʺŷ SAACķIPַ +acserv=127.0.0.1 +#acserv=192.168.0.123 +# Account Server Port +# ʺŷ SAACķ˿ +#acservport=9208 +acservport=10001 +# Account Server password +# ӵʺŷ SAAC +acpasswd=test + +# Game Server Name +# +gameservname=ʯһ + +#ID +gameservlistid=1 + +# ID +gameservid=1 + +================================================== + ԷκӰ +#ifdef _SERVICE (??) +#config.apid, sizeof(config.apid), NULL, 0}, +apid= +#NULL ,0 ,(void*)&config.apport ,SHORT}, +apport= +#NULL,0,(void*)&config.looptime,INT}, +looptime= +#NULL,0,(void*)&config.enableservice,INT}, +enableservice= +#endif +================================================== + +#NULL, 0, (void*)&config.allowmanorpk, SHORT}, +# Ƿս +allowmanorpk=1 +#NULL ,0 , (void*)&config.port,SHORT}, +# ˿ +port=19065 + +# Server Number +# SN +servernumber=1 + +# Re-use addr +# ظʹsocketַ +# 9065˿ڱռõ»᲻ʹøö˿ +reuseaddr=1 + +# delay. If set to 1, may increase network load... +# socket׽ӳ TCP_NODELAY 鿪 +nodelay=0 + +================================================== +Ϊ0 д־ +# How long should logfile be wrote? In seconds? + +log_write_time=0 +# ? +log_io_time=0 +# ? +log_game_time=0 +================================================== + + +# ¼netloop_faster() LOG +log_netloop_faster=0 + +# ÿζȡSAACĿ +saacwritenum=10000 + +# ÿдSAACĿ +saacreadnum=10000 + +# Max fds, should be larger than online ppls +# +fdnum=1000 +# +charnum=800 +# Max pets numbers +# ߳ +petnum=30000 +# Max other char numbers +# Ŀ NPCĿ+Ŀ +othercharnum=45000 + +# Max object numbers +# Ŀ +objnum=45000 + +# Max item numbers +# Ŀ +itemnum=50000 + +# Max battle numbers +# սĿ +battlenum=500 + +# Top directory(ļ?) +topdir=. +# Map file directory(ͼļ) +mapdir=data/map +# Map tile file directory(ͼļ) +maptilefile=data/map/mapset.txt + +# Map2 file directory(µͼļ) +mapdir2=./data/map2 +# Map2 tile file directory(µͼļ) +maptilefile2=./data/map2/mapset2.txt + + +# Battle map file(սͼļ) +battlemapfile=data/map/battlemap.txt + +#ifdef _ITEMSET6_TXT(ļ) +itemset6file=data/itemset6.txt +itemset5file=data/itemset5.txt +itemset4file=data/itemset4.txt +itemset3file=data/itemset3.txt + +======================================================== + п +#else(ûitemset6.txtĻѡļ,Ӧ) +#ifdef _ITEMSET5_TXT +# { "itemset5file", config.itemfile, sizeof(config.invfile), NULL, 0}, +#else +#ifdef _ITEMSET4_TXT +# { "itemset4file" , config.itemfile,sizeof(config.invfile),NULL,0}, +#else +#ifdef _ITEMSET3_ITEM +# { "itemset3file" , config.itemfile,sizeof(config.invfile),NULL,0}, +#endif +#endif +#endif +#endif +======================================================== +# ?(޵NPC򲻿սNPC???) +invinciblefile=data/inv.txt + +# ?(ʾλļ) +appearpositionfile=data/appear.txt + +# ?(ļ?) +titlenamefile=data/titlename.txt + +# ?(ļ?) +titleconfigfile=./data/titleconfig.txt + +# ?(ֵļ?) +encountfile=./data/encount.txt + +# ?(ļ?) +enemyfile=./data/enemy1.txt + +# ?(ļ?) +enemybasefile=./data/enemybase1.txt + +# ?(ļ?) +groupfile=./data/group1.txt + +# ?(ħļ?) +magicfile=./data/magic.txt + +#ifdef __ATTACK_MAGIC(ħļ?) +attmagicfile=./data/attmagic.bin +#endif + +#ifdef _PETSKILL2_TXT(\ļ) +petskillfile2=./data/petskill2.txt +#else +petskillfile1=./data/petskill.txt +#endif + +# ?(Ʒļ?زļ?) +itematomfile=./data/itematom.txt +# ?(?) +effectfile=data/effect.txt +# Եļ +quizfile=data/question.txt +# ? +#lsgenlogfilename=log/genlog +#ifdef _GMRELOAD(GMʺļ) +gmsetfile=./data/gmset.txt +#endif + +# Store DB? +# ԭĿ¼ ɷֹص +storedir=../saac/char +# Npc dir +# NPC Ŀ¼ +npcdir=data/npc +# Log dir +# ־Ŀ¼ +logdir=./log +# Log configuration file +# ־ļ +logconfname=log.cf +# ?GM PASSWORD(GM) +chatmagicpasswd=gm +#ifdef _STORECHAR +# { "storechar", config.storechar, sizeof( config.storechar),NULL,0}, +#endif + +# (ǷGMʹȨ0Ϊ,1Ϊ) +chatmagiccdkeycheck=1 + +# NPCʹļ +filesearchnum=10000 + +# עNPC_fuctionļ +npctemplatenum=256 + +# NPC +npccreatenum=10000 + +# Walk Send Interval +# · (GMSVûMUTLITHREADģʽʱ ) +walkinterval=10 + +# ?CA send interval (ms) +# CleanAll (GMSVûMUTLITHREADģʽʱ ) +CAinterval=10 + +# ?CD send interval (ms) +# CleanDest (GMSVûMUTLITHREADģʽʱ ) +CDinterval=10 + +# Character data save interval(ݴ洢?) +CharSaveinterval=900 + +# ִһ netloop_faster ʱ +Onelooptime=10 + +# How long a pet will be deleted (30 min?) +# (ʧʱ) +Petdeletetime=60 + +# How long a item will be deleted (5 minutes?) +# (Ʒʧʱ) +Itemdeletetime=60 + + +#ɾʯʱ +Golddeletetime=30 + +# Ƭص ǷƬ ûϸ +addressbookoffmesgnum=500 + +# ӿƵʵ ֵԽƵԽԽʡԴ +protocolreadfrequency=3000 + +# ÿӴ ޵ӽر +allowerrornum=100 + +# ÿӴ ޵ӽر +allowerrornum2=1 + +# ?(logʱ?) +loghour=0 + +# ?(սϢ?) +battledebugmsg=0 + +# //ttom add because the second had +# ͻ֤ ½Ч +encodekey=1 +# writebufferдݴС λֽ +acwritesize=1048576 +# С +acwbsize=1048576 +# ʹ÷Ƿֶ ˵ķNPCж ߵ쳣 ؽ +erruser_down=1 +# //ttom end + +==================================================================== +#¿ʡ +#ifdef _AUCTIONEER +# { "auctiondir" , config.auctiondir, sizeof(config.auctiondir),NULL,0}, +#endif +#ifdef _BLACK_MARKET +# { "blackmarketfile", config.blackmarketfile, sizeof(config.blackmarketfile), NULL, 0}, +#endif +#ifdef _M_SERVER +# { "msname", config.msname,sizeof(config.msname) ,NULL , 0}, +# { "msport", NULL ,0 , (void*)&config.msport ,SHORT}, +#endif +#ifdef _NPCSERVER_NEW +# { "npcaddress", config.nsaddress, sizeof(config.nsaddress) ,NULL , 0}, +# { "nsport", NULL, 0 , (void*)&config.nsport ,SHORT}, +#endif + +==================================================================== + +#ְҵ +profession=./data/profession.txt +#endif + +#˳Ŷӵĵ +itemquitparty=./data/itemquitparty.txt +#endif + +#ifdef _MUSEUM +# { "museum", NULL , 0 , (void*)&config.museum , INT}, +#endif + +#LNS +LUAFILE=./data/lua/init.lua + +#ֻֿɴװ +ROOKIEITEM=20627 +ROOKIEITEM2=22161 +ROOKIEITEM3=-1 +ROOKIEITEM4=-1 +ROOKIEITEM5=-1 + +#鹲 0رչ 1 +EXPSHARE=1 + +#ֹתЯ +NOTRANSITEM=18543 + +#ߺϳɵߵȼitemset6еװȼ 10Ϊ60 20Ϊ110 +MAXMERGELEVEL=200 diff --git a/sql.cf b/sql.cf new file mode 100644 index 0000000..d7dd7b0 --- /dev/null +++ b/sql.cf @@ -0,0 +1,19 @@ +############################## +#MYSQL基本配置 +#ifdef _SASQL +#sql服务器IP +sql_IP 127.0.0.1 +#sql服务器端口 +sql_Port 3306 +#sql服务器账号 +sql_ID root +#sql服务器密码 +sql_PS 123456 +#sql数据库名 +sql_DataBase CSA +#sql人物信息表名 +sql_Table CSAlogin +#sql用户名字段 +sql_NAME Name +#sql密码字段名 +sql_PASS PassWord diff --git a/客户端lua文件/list.lua b/客户端lua文件/list.lua new file mode 100644 index 0000000..e7b3036 --- /dev/null +++ b/客户端lua文件/list.lua @@ -0,0 +1,21 @@ +function data() + grouplist = {{1, 2, 0, "·"} + } + + serlist = { + {"192.168.1.2","19065","·"}, + {"192.168.1.2","19065","ͨ·"}, + } +end + +function main() + data() + ServerList.SetGroupMaxNum(table.getn(grouplist)) + for i = 1, table.getn(grouplist) do + ServerList.SetGroupList(i - 1, grouplist[i][1], grouplist[i][2], grouplist[i][3], grouplist[i][4]) + end + for i = 1, table.getn(serlist) do + ServerList.SetServerList(i - 1, serlist[i][1], serlist[i][2], serlist[i][3]) + end +end + diff --git a/客户端lua文件/map/battlemap.lua b/客户端lua文件/map/battlemap.lua new file mode 100644 index 0000000..91efae0 --- /dev/null +++ b/客户端lua文件/map/battlemap.lua @@ -0,0 +1,32 @@ + + +function FreeGetBattleMap(floor) + math.randomseed(os.time()); + local ret=0; + for i=1,table.getn(BattleMapList) do + if floor >= BattleMapList[i][1][1] and floor <= BattleMapList[i][1][2] then + local index = math.mod(math.random(9999,999999),table.getn(BattleMapList[i][2])); + if index == 0 then + index = table.getn(BattleMapList[i][2]); + end + ret = BattleMapList[i][2][index]; + break; + end + end + return ret; +end + +function main() +BattleMapList = { + {{60403,60403},{59301}}, + {{33001,33020},{59314}}, + {{33021,33040},{59315}}, + {{33041,33060},{59316}}, + {{33060,33080},{59317}}, + {{33081,33101},{59318}}, + {{35001,35016},{59300}}, + };--{ʼͼ,ͼ},{սͼ1,սͼ2...սͼn} +end + +function data() +end diff --git a/客户端lua文件/map/shiqi.la.url b/客户端lua文件/map/shiqi.la.url new file mode 100644 index 0000000..d7dcf24 --- /dev/null +++ b/客户端lua文件/map/shiqi.la.url @@ -0,0 +1,7 @@ +[InternetShortcut] +URL=http://www.shiqi.la/ +Modified=200AD33B9EC9C60166 +HotKey=0 +IDList= +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,2 diff --git a/客户端lua文件/title.lua b/客户端lua文件/title.lua new file mode 100644 index 0000000..8253a1d --- /dev/null +++ b/客户端lua文件/title.lua @@ -0,0 +1,57 @@ +function GetTitleStr(id) + local num = table.getn(titleinfo); + if id >=1 and id <= num then + return titleinfo[id] + else + return ""; + end +end + +function data() + titleinfo = { + "[style c=9]صľ[/style]", + "[style c=1]ˮľ[/style]", + "[style c=6]׾[/style]", + "[style c=4]羫[/style]", + "[style c=3]ľ[/style]", + "[style c=1][/style][style c=2][/style][style c=5][/style][style c=3][/style][style c=4][/style]", + "[style c=7]ʹ[/style]", + "[style c=7][/style]", + "[style c=8]·ߵҶ[/style]", + "[style c=9]ˮС[/style]", + "[style c=10]૵ĸ[/style]", + "[style c=11]ϵӰ[/style]", + "[style c=12]ܵĴ[/style]", + "[style c=13]ķ[/style]", + "[style c=14]ҡҷĽ[/style]", + "[style c=15]ϲĴ[/style]", + "[style c=16]̺̫[/style]", + "[style c=17]ηļž[/style]", + "[style c=3]`ӡ[/style]", + "[style c=2]תֻ[/style]", + "[style c=4]ַ[/style]", + "[style c=6][/style]", + "[style c=25]ᱦ[/style]", + "[style c=10]´ᱦ[/style]", + "[style c=4]ϳɴ[/style]", + "[style c=6]ϳɸ[/style]", + "[style c=4][/style]", + "[style c=6][/style]", + "[style c=4][/style]", + "[style c=6][/style]", + "[style c=0]սʿ[/style]", + "[style c=8]ʥʿ[/style]", + "[style c=21]˿Ӣ[/style]", + "[style c=23]ķӢ[/style]", + "[style c=18]˹ʹ[/style]", + "[style c=15]˹½Ӣ[/style]" + } +end + +function main() + data() +end + + + + \ No newline at end of file diff --git a/客户端lua文件/win/1020.lua b/客户端lua文件/win/1020.lua new file mode 100644 index 0000000..a0f3a6e --- /dev/null +++ b/客户端lua文件/win/1020.lua @@ -0,0 +1,132 @@ + +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function lua_string_split(str, split_char) + local sub_str_tab = {}; + while (true) do + local pos = string.find(str, split_char); + if (not pos) then + sub_str_tab[#sub_str_tab + 1] = str; + break; + end + local sub_str = string.sub(str, 1, pos - 1); + sub_str_tab[#sub_str_tab + 1] = sub_str; + str = string.sub(str, pos + 1, #str); + end + + return sub_str_tab; +end + +function WindowInit(data) + winW = 8 + winH = 6 + winX = (800 - winW*64)/2 + winY = (600 - winH*48)/2 + msgWNLen = (winW*64-48)/7 + totalMsgLine = (winH*48-56)/20; + win.InitWindow(winW, winH, msgWNLen, data) + nowtime = os.time() + if addr ~= 0 then + sa.DeathAction(addr) + addr = 0 + end + btnCnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + btnCnt = btnCnt + 1 + end + end + +end + +function CreateWinType() + if addr == 0 then + -- addr = sa.MakeWindowDisp(winX,winY,winW, winH, 0, 1) + addr = sa.MakeWindowDisp(60,100,winW, winH, 0, 1) + end + + sa.PlaySe(202, 320, 240) + return addr +end + +function ServerWindowType() + if string.len(win.getMessageData(0)) > 0 then + sa.StockFontBuffer(winX + winW*64 / 2 - string.len(win.getMessageData(0)) * 4,winY + 20, 1, 4, "" .. win.getMessageData(0) .. "", 0) + end + sa.StockFontBuffer(winX + 20,winY + 40, 1, 10, " ׯ ԰ ֡ ռʱ䡱 ռʱ", 0) + for i = 1, 10 do + if string.len(win.getMessageData(i)) > 0 then + str = lua_string_split(win.getMessageData(i), "|") + + sa.StockFontBuffer(winX + 32,winY + 40 + i * 20, 1, 11, fmpoint[i], 0) + + local fmnamelen = string.len(str[1])-1 + if fmnamelen > 0 then + sa.StockFontBuffer(winX + 185 - fmnamelen * 4,winY + 40 + i * 20, 1, 2, str[1], 0) + + local hadtime = tonumber(str[2]) + if hadtime > 0 then + sa.StockFontBuffer(winX + 263,winY + 40 + i * 20, 1, 1, os.date("%Y%m%d", hadtime), 0) + end + local hadday = tonumber(str[3]) - hadtime + if hadday > 0 then + local strhadday = string.format("%d%02dСʱ", getIntPart(hadday/(3600*24)), getIntPart(hadday%(3600*24)/(3600))) + local strhaddaylen = string.len(strhadday) - 1 + sa.StockFontBuffer(winX + 442 - strhaddaylen * 4,winY + 40 + i * 20, 1, 0, strhadday, 0) + end + else + sa.StockFontBuffer(winX + 185 - 24,winY + 40 + i * 20, 1, 7, "δռ δռ δռ", 0) + end + end + end + if btnCnt > 0 then + local cnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + cnt = cnt + 1 + local id = sa.StockFontBuffer(winX + cnt * winW*64 / (btnCnt + 1) - 27,winY + winH*48 - 25,1, 4, button[i], 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == id then + lssproto.windows(win.getIndexWN(), win.getIdWN(), sa.LeftShift(1, i-1), "") + win.CloseWindow() + break + end + end + end + end + end + + if win.DelWindow() == 1 then + sa.DeathAction(addr) + win.CloseFlg() + addr = 0 + win.CloseWindow() + end + return addr +end + +function data() + button = {" ȷ ", " ȡ ", " ȷ ", " ȡ ", "һҳ", "һҳ"} + btnCnt = 0 + addr = 0 + winW = 0 + winH = 0 + winX = 0 + winY = 0 + fmpoint = {"ķ", "˿", "ӡ", "³", " ԰", " ", " ˹", " ", " ŷ", "˹"} +end + +function main() + data() +end diff --git a/客户端lua文件/win/1021.lua b/客户端lua文件/win/1021.lua new file mode 100644 index 0000000..d534201 --- /dev/null +++ b/客户端lua文件/win/1021.lua @@ -0,0 +1,139 @@ + +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function lua_string_split(str, split_char) + local sub_str_tab = {}; + while (true) do + local pos = string.find(str, split_char); + if (not pos) then + sub_str_tab[#sub_str_tab + 1] = str; + break; + end + local sub_str = string.sub(str, 1, pos - 1); + sub_str_tab[#sub_str_tab + 1] = sub_str; + str = string.sub(str, pos + 1, #str); + end + + return sub_str_tab; +end + +function WindowInit(data) + winW = 9 + winH = 6 + winX = (800 - winW*64)/2 + winY = (600 - winH*48)/2 + msgWNLen = (winW*64-48)/7 + totalMsgLine = (winH*48-56)/20; + win.InitWindow(winW, winH, msgWNLen, data) + nowtime = os.time() + if addr ~= 0 then + sa.DeathAction(addr) + addr = 0 + end + btnCnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + btnCnt = btnCnt + 1 + end + end + +end + +function CreateWinType() + if addr == 0 then + -- addr = sa.MakeWindowDisp(winX,winY,winW, winH, 0, 1) + addr = sa.MakeWindowDisp(45,100,winW, winH, 0, 1) + end + + sa.PlaySe(202, 320, 240) + return addr +end + +function ServerWindowType() + if string.len(win.getMessageData(0)) > 0 then + sa.StockFontBuffer(winX + winW*64 / 2 - string.len(win.getMessageData(0)) * 4,winY + 20, 1, 4, "" .. win.getMessageData(0) .. "", 0) + end + sa.StockFontBuffer(winX + 20,winY + 40, 1, 10, "ׯ ԰ ׯ塱 塱 սʱ䡱 ս״̬", 0) + for i = 1, 10 do + if string.len(win.getMessageData(i)) > 0 then + str = lua_string_split(win.getMessageData(i), "|") + + sa.StockFontBuffer(winX + 32,winY + 40 + i * 20, 1, 11, fmpoint[i], 0) + + if tonumber(str[1]) == 7 or tonumber(str[1]) == 8 or tonumber(str[1]) == 10 then + local fmnamelen = string.len(str[4])-1 + if fmnamelen > 0 then + sa.StockFontBuffer(winX + 160 - fmnamelen * 4,winY + 40 + i * 20, 1, 2, str[4], 0) + end + local fmnamelen = string.len(str[3])-1 + if fmnamelen > 0 then + sa.StockFontBuffer(winX + 295 - fmnamelen * 4,winY + 40 + i * 20, 1, 2, str[3], 0) + end + sa.StockFontBuffer(winX + 365,winY + 40 + i * 20, 1, 1, os.date("%m%d %H:%M", tonumber(str[2])), 0) + sa.StockFontBuffer(winX + 480,winY + 40 + i * 20, 1, 0, string.format("%3s֣%s", str[5], str[5]), 0) + elseif tonumber(str[1]) == 9 then + sa.StockFontBuffer(winX + 160 - 6,winY + 40 + i * 20, 1, 2, "", 0) + sa.StockFontBuffer(winX + 295 - 6,winY + 40 + i * 20, 1, 2, "", 0) + sa.StockFontBuffer(winX + 365,winY + 40 + i * 20, 1, 1, os.date("%m%d %H:%M", tonumber(str[2])), 0) + sa.StockFontBuffer(winX + 480,winY + 40 + i * 20, 1, 0, string.format("ֹս", str[5], str[5]), 0) + elseif tonumber(str[1]) == 15 then + sa.StockFontBuffer(winX + 160 - 6,winY + 40 + i * 20, 1, 2, "", 0) + sa.StockFontBuffer(winX + 295 - 6,winY + 40 + i * 20, 1, 2, "", 0) + sa.StockFontBuffer(winX + 365,winY + 40 + i * 20, 1, 1, os.date("%m%d %H:%M", tonumber(str[2])), 0) + sa.StockFontBuffer(winX + 480,winY + 40 + i * 20, 1, 0, string.format("ֹ", str[5], str[5]), 0) + else + sa.StockFontBuffer(winX + 124,winY + 40 + i * 20, 1, 7, " սų սų սų սų", 0) + end + end + end + if btnCnt > 0 then + local cnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + cnt = cnt + 1 + local id = sa.StockFontBuffer(winX + cnt * winW*64 / (btnCnt + 1) - 12,winY + winH*48 - 25,1, 4, button[i], 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == id then + lssproto.windows(win.getIndexWN(), win.getIdWN(), sa.LeftShift(1, i-1), "") + win.CloseWindow() + break + end + end + end + end + end + + if win.DelWindow() == 1 then + sa.DeathAction(addr) + win.CloseFlg() + addr = 0 + win.CloseWindow() + end + return addr +end + +function data() + button = {" ȷ ", " ȡ ", " ȷ ", " ȡ ", "һҳ", "һҳ"} + btnCnt = 0 + addr = 0 + winW = 0 + winH = 0 + winX = 0 + winY = 0 + fmpoint = {"ķ", "˿", "ӡ", "³", " ԰", " ", " ˹", " ", " ŷ", "˹"} +end + +function main() + data() +end diff --git a/客户端lua文件/win/1022.lua b/客户端lua文件/win/1022.lua new file mode 100644 index 0000000..405326a --- /dev/null +++ b/客户端lua文件/win/1022.lua @@ -0,0 +1,129 @@ + +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function lua_string_split(str, split_char) + local sub_str_tab = {}; + while (true) do + local pos = string.find(str, split_char); + if (not pos) then + sub_str_tab[#sub_str_tab + 1] = str; + break; + end + local sub_str = string.sub(str, 1, pos - 1); + sub_str_tab[#sub_str_tab + 1] = sub_str; + str = string.sub(str, pos + 1, #str); + end + + return sub_str_tab; +end + +function WindowInit(data) + winW = 9 + winH = 9 + winX = (800 - winW*64)/2 + winY = (600 - winH*48)/2 + msgWNLen = (winW*64-48)/7 + totalMsgLine = (winH*48-56)/20; + win.InitWindow(winW, winH, msgWNLen, data) + nowtime = os.time() + if addr ~= 0 then + sa.DeathAction(addr) + addr = 0 + end + btnCnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + btnCnt = btnCnt + 1 + end + end + +end + +function CreateWinType() + if addr == 0 then + -- addr = sa.MakeWindowDisp(winX,winY,winW, winH, 0, 1) + addr = sa.MakeWindowDisp(50,41,winW, winH, 0, 1) + + end + sa.PlaySe(202, 320, 240) + return addr +end + +function ServerWindowType() + if string.len(win.getMessageData(0)) > 0 then + sa.StockFontBuffer(winX + winW*64 / 2 - string.len(win.getMessageData(0)) * 4,winY + 20, 1, 4, "" .. win.getMessageData(0) .. "", 0) + end + sa.StockFontBuffer(winX + winW*64 / 2 - 64,winY + 230, 0, 1, "һţ֣һ", 0) + for i = 1, 10 do + if string.len(win.getMessageData(i)) > 0 then + str = lua_string_split(win.getMessageData(i), "|") + local metamo = tonumber(str[1]) + if metamo > 0 then + local fmnamelen = string.len(str[2])-1 + if fmnamelen > 0 then + sa.StockFontBuffer(winX - 45 + xy[i] - fmnamelen * 4,winY + 200 + (i % 2) * 180, 0, 5, str[2], 0) + end + if pklist[i] == -1 then + pklist[i] = sa.MakeAnimDisp(winX - 40 + xy[i],winY + 150 + (i % 2) * 200,tonumber(str[1]), 0) + end + end + end + end + if btnCnt > 0 then + local cnt = 0 + for i = 1, 6 do + if sa.SaD1AndD2(win.getButtonTypeWN(),sa.LeftShift(1, i-1)) > 0 then + cnt = cnt + 1 + local id = sa.StockFontBuffer(winX + cnt * winW*64 / (btnCnt + 1) - 12,winY + winH*48 - 25,1, 4, button[i], 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == id then + lssproto.windows(win.getIndexWN(), win.getIdWN(), sa.LeftShift(1, i-1), "") + win.CloseWindow() + break + end + end + end + end + end + + if win.DelWindow() == 1 then + for i = 1, 10 do + if pklist[i] ~= -1 then + sa.DeathAction(pklist[i]) + pklist[i] = -1 + end + end + sa.DeathAction(addr) + win.CloseFlg() + addr = 0 + win.CloseWindow() + end + return addr +end + +function data() + button = {"ս", "ȡս", "ս", "ȡս", " һҳ ", " һҳ "} + btnCnt = 0 + addr = 0 + winW = 0 + winH = 0 + winX = 0 + winY = 0 + xy = {330, 330, 220, 220, 440, 440, 110, 110, 550, 550} + pklist = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1} +end + +function main() + data() +end diff --git a/客户端lua文件/win/1023.lua b/客户端lua文件/win/1023.lua new file mode 100644 index 0000000..8a7d125 --- /dev/null +++ b/客户端lua文件/win/1023.lua @@ -0,0 +1,199 @@ + +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function lua_string_split(str, split_char) + local sub_str_tab = {}; + while (true) do + local pos = string.find(str, split_char); + if (not pos) then + sub_str_tab[#sub_str_tab + 1] = str; + break; + end + local sub_str = string.sub(str, 1, pos - 1); + sub_str_tab[#sub_str_tab + 1] = sub_str; + str = string.sub(str, pos + 1, #str); + end + + return sub_str_tab; +end + +function WindowInit(data) + winW = 8 + winH = 7 + winX = (800 - winW*64)/4 + winY = (600 - winH*48)/4 + if addr ~= 0 then + sa.DeathAction(addr) + addr = 0 + end + if petaddr ~= 0 then + sa.DeathAction(petaddr); + petaddr=0; + end + local data = lua_string_split(data,"|"); + RideNum = tonumber(data[1]); + for i=1,RideNum do + RideData[""][i] = data[2+(i-1)*3]; + if data[3+(i-1)*3] == "1" then + RideData[""][i] = ""; + else + RideData[""][i] = ""; + end + RideData[""][i] = tonumber(data[4+(i-1)*3]); + end + TotalPages = 1; + if math.mod(RideNum,Row) > 0 then + if RideNum > Row then + TotalPages = getIntPart(RideNum/Row) + 1; + end + else + if RideNum > Row then + TotalPages = getIntPart(RideNum/Row); + end + end + Pages=0; +end + +function CreateWinType() + if addr == 0 then + addr = sa.MakeWindowDisp(winX,winY,winW, winH, 0, 1) + end + sa.PlaySe(202, 320, 240) + return addr; +end + + +function ServerWindowType() + local str = "Ԥѯ" + sa.StockFontBuffer(winX*2+256-sa.getTextLength(str)/2,winY*2+20, 1, 4, str, 0) + str = string.format("֡ ɡ ͡"); + sa.StockFontBuffer(winX*2+256-sa.getTextLength(str)/2,winY*2+44, 1, 5, str, 0) + local lstart,lend,butid; + lstart = Pages * Row +1; + if RideNum > Pages * Row + 11 then + lend = Pages * Row + Row; + else + lend = Pages * Row + Row + RideNum - (Pages+1) * Row; + end + local index=1; + for i =lstart,lend do + str = " "; + butid = sa.StockFontBuffer(winX*2+70,winY*2+44+index*24, 1, 5, str, 2); + sa.StockFontBuffer(winX*2+125-sa.getTextLength(RideData[""][i])/2,winY*2+44+index*24, 1, 5, RideData[""][i], 0); + sa.StockFontBuffer(winX*2+250,winY*2+44+index*24, 1, 5, RideData[""][i], 0); + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + if petaddr ~= 0 then + sa.DeathAction(petaddr); + end + petaddr = sa.MakeAnimDisp(winX +460, winY + 260,RideData[""][i], 0); + end + end + index=index+1; + end + + if TotalPages > 1 then + if Pages == 0 then + str = "һҳ" + butid = sa.StockFontBuffer(winX*2+180,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + Pages = Pages+1; + end + end + str = " " + butid = sa.StockFontBuffer(winX*2+270,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + win.CloseWindow(); + end + end + else + if Pages == (TotalPages-1) then + str = "һҳ" + butid = sa.StockFontBuffer(winX*2+180,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + Pages = Pages-1; + end + end + str = " " + butid = sa.StockFontBuffer(winX*2+270,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + win.CloseWindow(); + end + end + else + str = "һҳ" + butid = sa.StockFontBuffer(winX*2+170,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + Pages = Pages-1; + end + end + str = "һҳ" + butid = sa.StockFontBuffer(winX*2+235,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + Pages = Pages+1; + end + end + str = " " + butid = sa.StockFontBuffer(winX*2+300,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + win.CloseWindow(); + end + end + end + end + else + str = " " + butid = sa.StockFontBuffer(winX*2+256-sa.getTextLength(str)/2,winY*2+44+(Row+1)*24, 1, 4, str, 2) + if win.getMouseLeftCrick() > 0 then + if win.getHitFontNo() == butid then + win.CloseWindow(); + end + end + end + + if win.DelWindow() == 1 then + sa.DeathAction(petaddr); + sa.DeathAction(addr) + win.CloseFlg() + addr = 0; + petaddr=0; + win.CloseWindow() + end + return addr; +end + + +function data() + Row=9; + TotalPages = 0; + petaddr=0; + addr = 0; + RideData = {}; + RideNum=0; + RideData[""] = {}; + RideData[""] = {}; + RideData[""] = {}; + Pages = 0; +end + +function main() + data() +end diff --git a/客户端lua文件/win/1024.lua b/客户端lua文件/win/1024.lua new file mode 100644 index 0000000..49e1700 --- /dev/null +++ b/客户端lua文件/win/1024.lua @@ -0,0 +1,217 @@ +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function lua_string_split(str, split_char) + local sub_str_tab = {}; + while (true) do + local pos = string.find(str, split_char); + if (not pos) then + sub_str_tab[#sub_str_tab + 1] = str; + break; + end + local sub_str = string.sub(str, 1, pos - 1); + sub_str_tab[#sub_str_tab + 1] = sub_str; + str = string.sub(str, pos + 1, #str); + end + + return sub_str_tab; +end + +function WindowInit(strdata) + winW = 6 + winH = 4 + winX = (800 - winW*64)/4 + winY = (600 - winH*48)/4 + if addr ~= 0 then + sa.DeathAction(addr) + addr = 0 + end + data() + vippoint = tonumber(strdata); + win.InitStrBuffer(winX + 180,winY + 180,6,0,1); + +end + +function CreateWinType() + if addr == 0 then + addr = sa.MakeWindowDisp(winX,winY,winW, winH, 0, 1) + end + sa.PlaySe(202, 320, 240) + return addr; +end + +function ServerWindowType() + win.SetInputMsgNum() + + sa.StockFontBuffer(winX + 230,winY + 80, 1, 10, "", 0) + local id ; + local color={}; + + local posy = 0 + + sa.StockFontBuffer(winX + 100,winY + 100 + posy, 1, 0, "ǰң", 0) + + sa.StockFontBuffer(winX + 180,winY + 100 + posy, 1, 0,"".. vippoint, 0); + + sa.StockFontBuffer(winX + 100,winY + 120 + posy, 1, 0, "ģʽ", 0); + + + if familymode == 0 then + color[1]=1; + color[2]=0; + color[3]=0; + elseif familymode == 1 then + color[1]=0; + color[2]=1; + color[3]=0; + elseif familymode == 2 then + color[1]=0; + color[2]=0; + color[3]=1; + end + + id = sa.StockFontBuffer(winX + 180,winY + 120 + posy, 1, color[1], "", 2); + + if win.getHitFontNo() == id then + win.ShowBottomLineString(0,"ֻмԱȡ"); + if win.getMouseLeftCrick() > 0 then + familymode=0; + end + end + id = sa.StockFontBuffer(winX + 240,winY + 120 + posy, 1, color[2], "ȫ", 2); + if win.getHitFontNo() == id then + win.ShowBottomLineString(0,"ȫҶȡ"); + if win.getMouseLeftCrick() > 0 then + familymode=1; + end + end + + sa.StockFontBuffer(winX + 100,winY + 140 + posy, 1, 0, "ȡʽ", 0); + + if getmode == 0 then + color[1]=1; + color[2]=0; + else + color[1]=0; + color[2]=1; + end + + id = sa.StockFontBuffer(winX + 180,winY + 140 + posy, 1, color[1], "ƴ", 2); + if win.getHitFontNo() == id then + win.ShowBottomLineString(0,"ȡĺƴ"); + if win.getMouseLeftCrick() > 0 then + getmode=0; + end + end + id = sa.StockFontBuffer(winX + 240,winY + 140 + posy, 1, color[2], "ƽ", 2); + if win.getHitFontNo() == id then + win.ShowBottomLineString(0,"ȡĺÿһ"); + if win.getMouseLeftCrick() > 0 then + getmode=1; + end + end + + sa.StockFontBuffer(winX + 100,winY + 160 + posy, 1, 0, "", 0); + + id = sa.StockFontBuffer(winX + 180,winY + 160 + posy, 1, 0, " ", 2); + if win.getHitFontNo() == id then + if win.getMouseLeftCrick() > 0 then + win.InitStrBuffer(winX + 180,winY + 160,2,0,1); + win.GetKeyInputFocus(); + Focus=1; + end + end + + + if Focus == -1 then + sa.StockFontBuffer(winX + 180,winY + 160 + posy, 1, 0,rednum , 2); + sa.StockFontBuffer(winX + 180,winY + 180 + posy, 1, 0,redValue, 0); + elseif Focus == 1 then + sa.StockFontBuffer(winX + 180,winY + 180 + posy, 1, 0,redValue, 0); + if string.len(win.GetInputMsg()) > 0 then + rednum = tonumber(win.GetInputMsg()); + end + elseif Focus == 2 then + if string.len(win.GetInputMsg()) > 0 then + redValue = tonumber(win.GetInputMsg()); + end + sa.StockFontBuffer(winX + 180,winY + 160 + posy, 1, 0,rednum , 2); + end + + + sa.StockFontBuffer(winX + 100,winY + 180 + posy, 1, 0, " ", 0); + id = sa.StockFontBuffer(winX + 180,winY + 180 + posy, 1, 0, " ", 2); + if win.getHitFontNo() == id then + if win.getMouseLeftCrick() > 0 then + win.InitStrBuffer(winX + 180,winY + 180,6,0,1); + win.GetKeyInputFocus(); + Focus=2; + end + end + if getmode==0 then + sa.StockFontBuffer(winX + 300,winY + 180 + posy, 1, 4, "ǰΪƴ", 0); + else + sa.StockFontBuffer(winX + 300,winY + 180 + posy, 1, 4, "ǰΪƽ", 0); + end + + id = sa.StockFontBuffer( winX + 180 , winY + 210 + posy, 1, 4, "", 2); + if win.getHitFontNo() == id then + if win.getMouseLeftCrick() > 0 then + if rednum > 0 then + if redValue > 0 and redValue >= rednum * 10 then + if redValue <= vippoint then + local token = familymode.."|"..getmode.."|"..rednum.."|"..redValue + lssproto.windows(win.getIndexWN(), win.getIdWN(),1,token); + win.CloseWindow() + else + sa.ShowMessage("ǰĽҲ㣡",4) + end + else + sa.ShowMessage("СΪ0Ҵڻں10",4) + end + else + sa.ShowMessage("Ϊ0",4) + end + end + end + id = sa.StockFontBuffer(winX + 310,winY + 210 + posy, 1, 4, " ", 2); + if win.getHitFontNo() == id then + if win.getMouseLeftCrick() > 0 then + win.CloseWindow() + end + end + win.StockFontBuffer2(); + if win.DelWindow() == 1 then + sa.DeathAction(addr) + win.CloseFlg() + addr = 0; + sa.GetKeyInputFocus() + win.CloseWindow() + end + return addr; +end + + +function data() + addr=0; + familymode=0; + getmode=0; + rednum=0; + redValue=0; + Focus=-1; +end + + +function main() + data() +end diff --git a/服务器端lua文件/ablua/equipeffectfunction.lua b/服务器端lua文件/ablua/equipeffectfunction.lua new file mode 100644 index 0000000..ad6a901 --- /dev/null +++ b/服务器端lua文件/ablua/equipeffectfunction.lua @@ -0,0 +1,57 @@ +function EquipEffectFunction( charaindex, id ) + if id == 2 then + + itemindex = char.getItemIndex(charaindex,id) + if itemindex > -1 then + local itemlv = GetItemShowIndex(itemindex) + if itemlv>0 then + char.setWorkInt(charaindex,"ׯ԰Ч",itemshow[itemlv][2]) + return 1 + end + else + char.setWorkInt(charaindex,"ׯ԰Ч",0) + end + end + if id == 6 then + itemindex = char.getItemIndex(charaindex,id) + if itemindex > -1 then + local data = item.getChar(itemindex, "ֶ") + local effectid = other.atoi(other.getString(data, "|", 4)) + char.setInt(charaindex,"Ч",effectid) + else + char.setInt(charaindex,"Ч",0) + end + end + return 1 + +end + +function GetItemShowIndex(itemindex) + local name = item.getChar(itemindex,"") + for i = 1,table.getn(itemshow) do + local tagindex = string.find(name,itemshow[i][1]) + if tagindex ~= nil then + return i + end + end + return 0 +end + + +function data() + itemshow = { + {"", 102201} + ,{" 14", 102203} + ,{" 15", 102220} + ,{" 16", 102223} + ,{" 17", 102219} + ,{" 18",102232} + ,{" 19",102248} + ,{" 20",102234} + } + +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/familyridefunction.lua b/服务器端lua文件/ablua/familyridefunction.lua new file mode 100644 index 0000000..ea9a1d7 --- /dev/null +++ b/服务器端lua文件/ablua/familyridefunction.lua @@ -0,0 +1,441 @@ +function FamilyRideCheck( meindex, petindex,pethaveindex) + local petNo = char.getInt( petindex, "ԭͼ") + for i=1,table.getn(ridepet) do + if petNo == ridepet[i] then + return 1 + end + end + return 0 +end + +function FreeRideQuery(charaindex) + local petNo = 0 + local token = "".. table.getn(ridepet) + for i=1,table.getn(ridepet) do + token = token .. "|"..petname[i].."|"..CheckPetRideByPetNo( charaindex, ridepet[i]).."|"..ridepet[i] + end + lssproto.windows(charaindex, 1023, 0, 1, char.getWorkInt( npcindex, ""), token) +end + +function CheckPetRideByPetNo( meindex, petNo) + local playerid = getNOindex(char.getInt( meindex, "ԭͼ")) + + if char.getInt( meindex, "ͼ") == 101178 then + if petNo == 101177 then + return 101179 + end + elseif char.getInt( meindex, "ͼ") == 101177 then + if petNo == 101178 then + return 101179 + end + elseif playerid > 0 then + for i = 1, table.getn(petlist) do + if petNo == petlist[i] then + if other.DataAndData(char.getInt(meindex, "֤"), i - 1) ~= 0 then + return 1 + end + end + end + + for i = 1, table.getn(PlayerColor[1]) do + if PlayerColor[playerid][i] == char.getInt( meindex, "ԭͼ") or (char.getInt( meindex, "ԭͼ") >= 100700 and char.getInt( meindex, "ԭͼ") < 108400) then + if petNo == CommonPetList[i] then + return 1 + end + end + end + + for i = 1, table.getn(CommonPetList1) do + if char.getInt( meindex, "ԭͼ") == CommonPetList1[i][2] and petNo == CommonPetList1[i][3] then + return 1 + end + end + + + for i = 1, table.getn(Pointpetlist) do + if petNo == Pointpetlist[i][1] then + floorid = char.getWorkInt( meindex, "ͼ") + for j = 1, table.getn(Pointpetlist[i][2]) do + if Pointpetlist[i][2][j] == floorid then + if char.getInt( meindex, "λ") > 0 and char.getInt( meindex, "λ") ~= 2 then + if char.getInt( meindex, "") == Pointpetlist[i][3] then + if PointRideNoList[playerid][i] > -1 then + return 1 + end + end + end + end + end + end + end + for i = 1, table.getn(EquipagePetlist) do + if petNo == EquipagePetlist[i][1] then + for j = 0, 5 do + itemindex = char.getItemIndex(meindex, j) + if itemindex > -1 then + if item.getChar(itemindex, "ʹ") == "INSLAY" or other.getString(item.getChar(itemindex, "ʹ"), " ", 1) == "INSLAY" then + local field = {"", "", "", "", ""} + local data = item.getChar(itemindex, "Ƕ") + + field[1] = other.getString(data, "|", 1) + field[2] = other.getString(data, "|", 2) + field[3] = other.getString(data, "|", 3) + field[4] = other.getString(data, "|", 4) + field[5] = other.getString(data, "|", 5) + for k = 1, table.getn(field) do + if field[k] == EquipagePetlist[i][2] then + return 1 + end + end + end + end + end + end + end + end + return 0 + +end + +function Loop(meindex) + if char.getWorkInt(meindex,"NPCʱ7") == char.getInt(meindex, "ͼ") then + char.setInt(meindex, "ͼ", 102201) + char.ToAroundChar(meindex) + char.setInt(meindex, "ѭ¼ʱ", 300) + else + char.setInt(meindex, "ͼ", char.getWorkInt(meindex,"NPCʱ7")) + char.ToAroundChar(meindex) + char.setInt(meindex, "ѭ¼ʱ", 0) + char.delFunctionPointer(meindex, "ѭ¼") + char.setWorkInt(meindex,"NPCʱ7",0) + end +end + +function FamilyRideFunction( meindex, petindex,pethaveindex) + if char.getInt( petindex, "ת") >0 then + char.TalkToCli(meindex, -1, "ϵͳʾ[" .. char.getChar(petindex, "") .. "]Ѿת޷ˡ", "ɫ") + return 0 + end + + local playerid = getNOindex(char.getInt( meindex, "ԭͼ")) + + local petNo = char.getInt( petindex, "ԭͼ") + if char.getInt( meindex, "ͼ") == 101178 then + if petNo == 101177 then + char.setWorkInt(meindex,"NPCʱ7",101179) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return 101179 + end + elseif char.getInt( meindex, "ͼ") == 101177 then + if petNo == 101178 then + char.setWorkInt(meindex,"NPCʱ7",101179) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return 101179 + end + elseif playerid > 0 then + for i = 1, table.getn(petlist) do + if petNo == petlist[i] then + if other.DataAndData(char.getInt(meindex, "֤"), i - 1) ~= 0 then + char.setWorkInt(meindex,"NPCʱ7",NewRideNoList[playerid][i]) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return NewRideNoList[playerid][i] + end + end + end + + for i = 1, table.getn(PlayerColor[1]) do + if PlayerColor[playerid][i] == char.getInt( meindex, "ԭͼ") or (char.getInt( meindex, "ԭͼ") >= 100700 and char.getInt( meindex, "ԭͼ") < 108400) then + if petNo == CommonPetList[i] then + char.setWorkInt(meindex,"NPCʱ7",CommonRideNoList[playerid][i]) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return CommonRideNoList[playerid][i] + end + end + end + + for i = 1, table.getn(CommonPetList1) do + if char.getInt( meindex, "ԭͼ") == CommonPetList1[i][2] and petNo == CommonPetList1[i][3] then + char.setWorkInt(meindex,"NPCʱ7",CommonPetList1[i][1]) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return CommonPetList1[i][1] + end + end + + + for i = 1, table.getn(Pointpetlist) do + if petNo == Pointpetlist[i][1] then + floorid = char.getWorkInt( meindex, "ͼ") + for j = 1, table.getn(Pointpetlist[i][2]) do + if Pointpetlist[i][2][j] == floorid then + if char.getInt( meindex, "λ") > 0 and char.getInt( meindex, "λ") ~= 2 then + if char.getInt( meindex, "") == Pointpetlist[i][3] then + if PointRideNoList[playerid][i] > -1 then + char.setWorkInt(meindex,"NPCʱ7",PointRideNoList[playerid][i]) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + return PointRideNoList[playerid][i] + end + end + end + end + end + end + end + for i = 1, table.getn(EquipagePetlist) do + if petNo == EquipagePetlist[i][1] then + for j = 0, 5 do + itemindex = char.getItemIndex(meindex, j) + if itemindex > -1 then + if item.getChar(itemindex, "ʹ") == "INSLAY" or other.getString(item.getChar(itemindex, "ʹ"), " ", 1) == "INSLAY" then + local field = {"", "", "", "", ""} + local data = item.getChar(itemindex, "Ƕ") + + field[1] = other.getString(data, "|", 1) + field[2] = other.getString(data, "|", 2) + field[3] = other.getString(data, "|", 3) + field[4] = other.getString(data, "|", 4) + field[5] = other.getString(data, "|", 5) + for k = 1, table.getn(field) do + if field[k] == EquipagePetlist[i][2] then + char.setWorkInt(meindex,"NPCʱ7",EquipageRideNoList[playerid][i]) + char.setFunctionPointer(meindex, "ѭ¼", "Loop", "") + char.setInt(meindex, "ѭ¼ʱ", 1000) + + return EquipageRideNoList[playerid][i] + end + end + end + end + end + end + end + end + return 0 +end + + + +function getNOindex( baseNo) + if baseNo >= 100000 and baseNo < 100240 then + metamo = baseNo - 100000 + for i = 1, 12 do + if metamo >= (i-2) * 20 and metamo < i * 20 then + return i; + end + end + elseif baseNo >= 100700 and baseNo < 100820 then + metamo = baseNo - 100700 + for i = 1, 12 do + if metamo >= (i-2) * 10 and metamo < i * 10 then + return i; + end + end + elseif baseNo >= 100400 and baseNo < 100410 then + return 13; + end + return -1 +end + +function data() + ridepet = {100329, 100327, 100330, 100328, 100351, 100352, 100353, 100354, 100396, 100374, 100358, 100362, 100279, 100288, 100283, 100346, 100310, 100372, 100373, 101532, 101576,100907} + petname = {"³˹","³","³","³","˹","˹","˹","˹˹","˹","", "Ħ˹", "˹", "³", "˹", "³˹", "", "", "˹", "Ͷ", "ʷ³", "޶","Ͽ"} + + --˵, 00, 01, 02, 칷03, 04, ̼05, 06, 07, 08, 챩09, ˮ10, ˮ11, ׻12,Ͽ13 + petlist = {100374, 100358, 100362, 100279, 100288, 100283, 100346, 100310, -1, -1, 101532, 101576, 100872, 100907} + + --˵, 00, 01, 02, 칷03, 04, ̼05, 06, 07, 08, 챩09, ˮ10, ˮ11, ׻12, 13 + NewRideNoList = {{101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009, 101978, 101989, 104025, 103266} + ,{101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019, 101986, 101988, 104026, 103262} + ,{101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029, 101975, 101965, 104027, 103263} + ,{101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039, 101976, 101966, 104028, 103264} + ,{101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049, 101984, 101973, 104029, 103272} + ,{101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059, 101985, 101974, 104030, 103273} + ,{101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069, 101977, 101967, 104031, 103265} + ,{101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079, 101979, 101968, 104032, 103267} + ,{101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089, 101981, 101970, 104033, 103269} + ,{101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099, 101980, 101969, 104034, 103268} + ,{101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109, 101983, 101972, 104035, 103271} + ,{101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119, 101982, 101971, 104036, 103270} + } + + PlayerColor = {{ 100000, 100005, 100010, 100015} + ,{ 100025, 100030, 100035, 100020} + ,{ 100055, 100050, 100045, 100040} + ,{ 100060, 100065, 100070, 100075} + ,{ 100095, 100085, 100090, 100080} + ,{ 100100, 100115, 100110, 100105} + ,{ 100135, 100120, 100125, 100130} + ,{ 100145, 100140, 100150, 100155} + ,{ 100165, 100170, 100160, 100175} + ,{ 100190, 100195, 100185, 100180} + ,{ 100200, 100210, 100215, 100205} + ,{ 100230, 100225, 100220, 100235} + } + + + -- 컢, ̻, , ƻ + CommonPetList = {100329, 100327, 100330, 100328} + CommonRideNoList = {{101004, 101005, 101006, 101007} + ,{101015, 101016, 101017, 101014} + ,{101027, 101026, 101025, 101024} + ,{101034, 101035, 101036, 101037} + ,{101047, 101045, 101046, 101044} + ,{101054, 101057, 101056, 101055} + ,{101067, 101064, 101065, 101066} + ,{101075, 101074, 101076, 101077} + ,{101085, 101086, 101084, 101087} + ,{101096, 101097, 101095, 101094} + ,{101104, 101106, 101107, 101105} + ,{101116, 101115, 101114, 101117} + } + CommonPetList1 = {{ 101000, 100000, 100352} + ,{ 101001, 100005, 100352} + ,{ 101002, 100010, 100352} + ,{ 101003, 100015, 100352} + ,{ 101000, 100700, 100352} + ,{ 101000, 100705, 100352} + + ,{ 101010, 100020, 100396} + ,{ 101011, 100025, 100396} + ,{ 101012, 100030, 100396} + ,{ 101013, 100035, 100396} + ,{ 101010, 100710, 100396} + ,{ 101010, 100715, 100396} + + ,{ 101020, 100040, 100351} + ,{ 101021, 100045, 100351} + ,{ 101022, 100050, 100351} + ,{ 101023, 100055, 100351} + ,{ 101020, 100720, 100351} + ,{ 101020, 100725, 100351} + + ,{ 101030, 100060, 100353} + ,{ 101031, 100065, 100353} + ,{ 101032, 100070, 100353} + ,{ 101033, 100075, 100353} + ,{ 101030, 100730, 100353} + ,{ 101030, 100735, 100353} + + ,{ 101040, 100080, 100396} + ,{ 101041, 100085, 100396} + ,{ 101042, 100090, 100396} + ,{ 101043, 100095, 100396} + ,{ 101040, 100740, 100396} + ,{ 101040, 100745, 100396} + + ,{ 101050, 100100, 100353} + ,{ 101051, 100105, 100353} + ,{ 101052, 100110, 100353} + ,{ 101053, 100115, 100353} + ,{ 101050, 100750, 100353} + ,{ 101050, 100755, 100353} + + ,{ 101060, 100120, 100354} + ,{ 101061, 100125, 100354} + ,{ 101062, 100130, 100354} + ,{ 101063, 100135, 100354} + ,{ 101060, 100760, 100354} + ,{ 101060, 100765, 100354} + + ,{ 101070, 100140, 100354} + ,{ 101071, 100145, 100354} + ,{ 101072, 100150, 100354} + ,{ 101073, 100155, 100354} + ,{ 101070, 100770, 100354} + ,{ 101070, 100775, 100354} + + ,{ 101080, 100160, 100352} + ,{ 101081, 100165, 100352} + ,{ 101082, 100170, 100352} + ,{ 101083, 100175, 100352} + ,{ 101080, 100780, 100352} + ,{ 101080, 100785, 100352} + + ,{ 101090, 100180, 100351} + ,{ 101091, 100185, 100351} + ,{ 101092, 100190, 100351} + ,{ 101093, 100195, 100351} + ,{ 101090, 100790, 100351} + ,{ 101090, 100795, 100351} + + ,{ 101100, 100200, 100353} + ,{ 101101, 100205, 100353} + ,{ 101102, 100210, 100353} + ,{ 101103, 100215, 100353} + ,{ 101100, 100800, 100353} + ,{ 101100, 100805, 100353} + + ,{ 101110, 100220, 100396} + ,{ 101111, 100225, 100396} + ,{ 101112, 100230, 100396} + ,{ 101113, 100235, 100396} + ,{ 101110, 100810, 100396} + ,{ 101110, 100815, 100396} + } + + Pointpetlist = {-- + {100372, {1041, 2031, 3031, 4031, 5031}, 0} + --챩 + ,{100373, {1041, 2031, 3031, 4031, 5031}, 1} + } + --, --챩 + PointRideNoList = {{101008, 101009} --С + ,{101018, 101019} -- + ,{101028, 101029} --к + ,{101038, 101039} -- + ,{101048, 101049} --Ƥ + ,{101058, 101059} -- + ,{101068, 101069} --С + ,{101078, 101079} --Ƥ + ,{101088, 101089} --ñ + ,{101098, 101099} --̷ + ,{101108, 101109} --Ů + ,{101118, 101119} -- + } + + EquipagePetlist = {--ʯ + {100307, "Cb"} + -- + ,{100348, "Ca"} + -- + ,{100360, "Cc"} + -- + ,{104124, "Cd"} + --ڼ + ,{100904, "Ce"} + --켦 + ,{100370, "Cf"} + --Ҽ + ,{100369, "Cg"} + } + --ʯ,, , , ڼ , 켦 , Ҽ + EquipageRideNoList = {{104100, 104112, 104137, 104125, 100444, 100425, 100424} --С + ,{104101, 104113, 104138, 104126, 100444, 100425, 100424} -- + ,{104102, 104114, 104139, 104127, 100444, 100425, 100424} --к + ,{104103, 104115, 104140, 104128, 100444, 100425, 100424} -- + ,{104104, 104116, 104141, 104129, 100444, 100425, 100424} --Ƥ + ,{104105, 104117, 104142, 104130, 100444, 100425, 100424} -- + ,{104106, 104118, 104143, 104131, 100444, 100425, 100424} --С + ,{104107, 104119, 104144, 104132, 100444, 100425, 100424} --Ƥ + ,{104108, 104120, 104145, 104133, 100444, 100425, 100424} --ñ + ,{104109, 104121, 104146, 104134, 100444, 100425, 100424} --̷ + ,{104110, 104122, 104147, 104135, 100444, 100425, 100424} --Ů + ,{104111, 104123, 104148, 104136, 100444, 100425, 100424} -- + } +end + + +function Create(name, metamo, floor, x, y, dir) + --NPC(NPC֣ͼţͼţXY)һNPC + npcindex = npc.CreateNpc(name, metamo, floor, x, y, dir) +end + +function main() + data() + Create("ѯNPCʱ", 100000, 777, 20, 20, 4) +end diff --git a/服务器端lua文件/ablua/freecharlogin.lua b/服务器端lua文件/ablua/freecharlogin.lua new file mode 100644 index 0000000..54513d7 --- /dev/null +++ b/服务器端lua文件/ablua/freecharlogin.lua @@ -0,0 +1,151 @@ +function FreeCharLogin( charindex ) + if char.getWorkInt(charindex, "ID") == 48 then + char.TalkToCli(charindex, -1, "汾ڣµѻҺ½Ϸ", "ɫ") + char.logou(charindex) + return 0; + end + if char.getWorkInt(charindex, "ID") == 4096 and config.getGameservername() == "ʯư浥" then + char.TalkToCli(charindex, -1, "ʾΪϷƽ⣬·ֻҵ½", "ɫ") + char.logou(charindex) + return 0; + end + for i = 1, table.getn(unlawthislogut) do + if char.getInt(charindex, "ʱ") <= other.time() then + if char.getInt(charindex, "ͼ") == unlawthislogut[i][1] then + char.setInt(charindex, "ͼ", unlawthislogut[i][2][1] ) + char.setInt(charindex, "X", unlawthislogut[i][2][2] ) + char.setInt(charindex, "Y", unlawthislogut[i][2][3] ) + end + end + end + if char.getInt(charindex, "ͼ") >=800 and char.getInt(charindex, "ͼ") <=851 then + char.WarpToSpecificPoint(charindex, 1000, 71, 49) + end + + if char.getInt(charindex, "ͼ") == 500 then + if char.getInt(charindex, "ȼ")< 80 then + char.WarpToSpecificPoint(charindex, 1000, 71, 49) + end + end + if char.getInt(charindex,"λ")>0 and char.getInt(charindex,"λ")~=2 then + if char.getChar(charindex, "") == other.getString(family.ShowPointListArray(0), "|", 6) then + char.setWorkInt(charindex,"ׯ԰Ч",103213) + elseif char.getChar(charindex, "") == other.getString(family.ShowPointListArray(1), "|", 6) then + char.setWorkInt(charindex,"ׯ԰Ч",103214) + end + end + if char.getInt(charindex, "ʱ") < 0 then + char.setInt(charindex, "ʱ", 0) + end + + if char.getInt(charindex, "Ʒ") ~=1 then + local vital = char.getInt(charindex, "") + local str = char.getInt(charindex, "") + local tgh = char.getInt(charindex, "") + local dex = char.getInt(charindex, "ٶ") + local skillpoint = char.getInt(charindex, "ܵ") + local sum = vital + str + tgh + dex + skillpoint * 100 + if sum > 63700 then + char.setInt(charindex, "", 1000) + char.setInt(charindex, "", 0) + char.setInt(charindex, "", 0) + char.setInt(charindex, "ٶ", 0) + char.setInt(charindex, "ܵ", 627) + end + else + local vital = char.getInt(charindex, "") + local str = char.getInt(charindex, "") + local tgh = char.getInt(charindex, "") + local dex = char.getInt(charindex, "ٶ") + local skillpoint = char.getInt(charindex, "ܵ") + local sum = vital + str + tgh + dex + skillpoint * 100 + if sum > 61000 then + char.setInt(charindex, "", 1000) + char.setInt(charindex, "", 0) + char.setInt(charindex, "", 0) + char.setInt(charindex, "ٶ", 0) + char.setInt(charindex, "ܵ", 600) + end + end + + token = "UPDATE CSAlogin set Offline = 0 , MAC = '" .. char.getWorkChar(charindex, "MAC") .. "', ServerName = '" .. config.getGameservername() .. "', ServerId = " .. char.getWorkInt(charindex, "ID") + 1 .. " WHERE Name=BINARY'" .. char.getChar(charindex, "˺") .. "'" + + ret = sasql.query(token) + token = "SELECT `newsafe`, `flg` FROM `safedata` " + .. " WHERE `cdkey` = '" .. char.getChar(charindex, "˺") .. "'" + ret = sasql.query(token) + if ret == 1 then + sasql.free_result() + sasql.store_result() + num = sasql.num_rows() + if num > 0 then + sasql.fetch_row(0) + if sasql.data(1) ~= char.getWorkChar(charindex, "MAC2") then + if sasql.data(2) == "0" then + char.setInt(charindex, "ȫ", 2) + end + token = "UPDATE `safedata` SET " + .. "`newsafe` = '" .. char.getWorkChar(charindex, "MAC2") .. "'," + .. "`oldsafe` = '" .. sasql.data(1) .. "'," + .. "`FixTime` = NOW()" + .. " WHERE `cdkey` = '" .. char.getChar(charindex, "˺") .. "'" + ret = sasql.query(token) + end + else + token = "INSERT INTO `safedata` ( " + .. "`cdkey` ," + .. "`newsafe` ," + .. "`oldsafe` ," + .. "`flg`," + .. "`FixTime`" + .. ")" + .. " VALUES (" + .. "'" .. char.getChar(charindex, "˺") + .. "', '" .. char.getWorkChar(charindex, "MAC2") + .. "', '" .. char.getWorkChar(charindex, "MAC2") + .. "', 0, NOW()" + .. ");" + ret = sasql.query(token) + end + end + + return 1; +end + + +function data() + + unlawthislogut = {{125, {1000, 92, 99}} + ,{126, {1000, 92, 99}} + ,{127, {1000, 92, 99}} + ,{128, {1000, 92, 99}} + ,{140, {141, 25, 17}} + ,{8190, {2000, 44, 67}} + ,{12345, {1000, 92, 99}} + ,{40001, {1000, 92, 99}} + ,{40002, {1000, 92, 99}} + ,{40003, {1000, 92, 99}} + ,{40004, {1000, 92, 99}} + ,{40005, {1000, 92, 99}} + ,{40006, {1000, 92, 99}} + ,{40007, {1000, 92, 99}} + ,{40008, {1000, 92, 99}} + ,{40009, {1000, 92, 99}} + ,{40010, {1000, 92, 99}} + ,{50001, {1000, 92, 99}} + ,{50002, {1000, 92, 99}} + ,{50003, {1000, 92, 99}} + ,{50004, {1000, 92, 99}} + ,{104, {1000, 92, 99}} + ,{133, {1000, 92, 99}} + ,{130, {1000, 92, 99}} + ,{602, {1000, 92, 99}} + ,{61001, {1000, 92, 99}} + ,{65501, {1000, 92, 99}} + ,{50005, {1000, 92, 99}} + } +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/freecharlogout.lua b/服务器端lua文件/ablua/freecharlogout.lua new file mode 100644 index 0000000..113e475 --- /dev/null +++ b/服务器端lua文件/ablua/freecharlogout.lua @@ -0,0 +1,124 @@ +--LUAжʱͿ۳ʱ仹ߺ¼һڼĸϢ! +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + + if math.ceil(x) == x then + x = math.ceil(x); + else + x = math.ceil(x) - 1; + end + return x; +end + +function FreeCharLogout( charindex ) + if char.getWorkInt(charindex, "") == 1 then + --if char.getWorkInt(charindex, "̯") == -1 then + -- if config.getGameservername() ~= "ʯ" and config.getGameservername() ~= "ʯ" then + -- local offtime = other.time() - char.getWorkInt(charindex, "½ʱ") + -- char.setInt(charindex, "ʱ", math.max(char.getInt(charindex, "ʱ") - offtime / 60), 0) + -- end + --end + other.setLuaPLayerNum(other.getLuaPLayerNum()-1) + else + local offtime = other.time() - char.getWorkInt(charindex, "½ʱ") + if char.getInt(charindex, "ȼ") == 140 then + local onlinetime = char.getInt(charindex, "ʱ") - char.getWorkInt(charindex, "½ʱ") + if char.getInt(charindex, "ת") == 5 then + char.setInt(charindex, "ʱ", char.getInt(charindex, "ʱ") + getIntPart(onlinetime / 2) ) + elseif char.getInt(charindex, "ת") == 6 then + char.setInt(charindex, "ʱ", char.getInt(charindex, "ʱ") + onlinetime) + end + end + end + + --if config.getGameservername() == "ʯ" then + -- token = "DELETE FROM `OnlinePlayer` " + -- .. " WHERE `cdkey` = '" .. char.getChar(charindex, "˺") .. "'" + -- ret = sasql.query(token) + --end + + token = "SELECT * FROM `CSAinfo` " + .. " WHERE `cdkey` = '" .. char.getChar(charindex, "˺") .. "'" + .. " AND `saveindex` = '" .. char.getInt(charindex, "浵") .. "'" + ret = sasql.query(token) + if ret == 1 then + sasql.free_result() + sasql.store_result() + num = sasql.num_rows() + if num > 0 then + token = "UPDATE `CSAinfo` SET " + .. "`name` = '" .. char.getChar(charindex, "") .. "'," + .. "`famename` = '" .. char.getChar(charindex, "") .. "', " + .. "`level` = '" .. char.getInt(charindex, "ȼ") .. "'," + .. "`trans` = '" .. char.getInt(charindex, "ת") .. "'," + .. "`alive` = '" .. char.getInt(charindex, "") .. "'," + .. "`fame` = '" .. char.getInt(charindex, "") .. "'," + .. "`TITLE_LV` = '" .. 0 .. "'," + .. "`DUELBATTLECOUNT` = '" .. char.getInt(charindex, "PK") .. "'," + .. "`DUELWINCOUNT` = '" .. char.getInt(charindex, "PKӮ") .. "'," + .. "`DUELLOSECOUNT` = '" .. char.getInt(charindex, "PK") .. "'," + .. "`DUELSTWINCOUNT` = '" .. char.getInt(charindex, "PKʤ") .. "'," + .. "`DUELSTLOSECOUNT` = '" .. char.getInt(charindex, "PK") .. "'," + .. "`DUELMAXSTWINCOUNT` = '" .. char.getInt(charindex, "PKʤ") .. "'," + .. "`vip` = '" .. char.getInt(charindex, "Ա") .. "'," + .. "`time` = NOW()" + .. " WHERE `cdkey` = '" .. char.getChar(charindex, "˺") .. "'" + .. " AND `saveindex` = '" .. char.getInt(charindex, "浵") .. "'" + ret = sasql.query(token) + else + token = "INSERT INTO `CSAinfo` ( " + .. "`cdkey` ," + .. "`saveindex` ," + .. "`name` ," + .. "`famename` ," + .. "`level` ," + .. "`trans` ," + .. "`alive` ," + .. "`fame` ," + .. "`TITLE_LV` ," + .. "`DUELBATTLECOUNT` ," + .. "`DUELWINCOUNT` ," + .. "`DUELLOSECOUNT` ," + .. "`DUELSTWINCOUNT` ," + .. "`DUELSTLOSECOUNT` ," + .. "`DUELMAXSTWINCOUNT` ," + .. "`vip` ," + .. "`time`" + .. ")" + .. "VALUES (" + .. "'" .. char.getChar(charindex, "˺") + .. "', '" .. char.getInt(charindex, "浵") + .. "', '" .. char.getChar(charindex, "") + .. "', '" .. char.getChar(charindex, "") + .. "', '" .. char.getInt(charindex, "ȼ") + .. "', '" .. char.getInt(charindex, "ת") + .. "', '" .. char.getInt(charindex, "") + .. "', '" .. char.getInt(charindex, "") + .. "', '" .. char.getInt(charindex, "Ӣ۳ƺ") + .. "', '" .. char.getInt(charindex, "PK") + .. "', '" .. char.getInt(charindex, "PKӮ") + .. "', '" .. char.getInt(charindex, "PK") + .. "', '" .. char.getInt(charindex, "PKʤ") + .. "', '" .. char.getInt(charindex, "PK") + .. "', '" .. char.getInt(charindex, "PKʤ") + .. "', '" .. char.getInt(charindex, "Ա") + .. "', NOW()" + .. ");" + + ret = sasql.query(token) + end + end + token = "update `CSAlogin` set `Offline`=0 where `Name`='" .. char.getChar(charindex,"˺") .. "'" + sasql.query(token) + +end + +function data() + +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/freechartitle.lua b/服务器端lua文件/ablua/freechartitle.lua new file mode 100644 index 0000000..5109835 --- /dev/null +++ b/服务器端lua文件/ablua/freechartitle.lua @@ -0,0 +1,219 @@ +function GetCharNewTitleNo(charaindex,id) + if char.check(charaindex)~=1 then + return 0 + end + if id< 32 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬1"),id)~= 0 then + return titleinfo[id+1][2] + end + elseif id< 64 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬2"),id-32)~= 0 then + return titleinfo[id+1][2] + end + elseif id< 96 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬3"),id-64)~= 0 then + return titleinfo[id+1][2] + end + end + return 0 +end + +function GetCharNewTitleString(charaindex,id) + if char.check(charaindex)~=1 then + return 0 + end + if id< 32 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬1"),id)~= 0 then + return titleinfo[id+1][2] + end + elseif id< 64 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬2"),id-32)~= 0 then + return titleinfo[id+1][2] + end + elseif id< 96 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬3"),id-64)~= 0 then + return titleinfo[id+1][2] + end + end + return "" +end + + +function GetCharNewTitleName(charaindex,id) + if char.check(charaindex)~=1 then + return 0 + end + + if id< 32 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬1"),id)~= 0 then + return titleinfo[id+1][1] + end + elseif (id >=32 and id< 64) then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬2"),id-32)~= 0 then + return titleinfo[id+1][1] + end + elseif(id >=64 and id< 96) then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬3"),id-64)~= 0 then + return titleinfo[id+1][1] + end + end + return "" +end + +function GetCharNewTitleMode(charaindex,id) + if char.check(charaindex)~=1 then + return 0 + end + + if id< 32 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬1"),id)~= 0 then + return 1 + end + elseif (id >=32 and id< 64) then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬2"),id-32)~= 0 then + return 1 + end + elseif(id >=64 and id< 96) then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬3"),id-64)~= 0 then + return 1 + end + end + return 0 +end + +function TitleListSend(charaindex) + if char.check(charaindex)~=1 then + return + end + local Nodata="" + local jiedata="" + local indexdata="" + local num=0 + local fd = char.getFd(charaindex) + for i = 1,96 do + if GetCharNewTitleMode(charaindex,i-1)>0 then + num = num + 1 +-- print(num, GetCharNewTitleMode(charaindex,i-1)) + Nodata = Nodata..GetCharNewTitleString(charaindex,i-1).."|" + jiedata = jiedata..GetCharNewTitleName(charaindex,i-1).."|" + indexdata = indexdata..(i-1).."|" + end + end + local data = string.format("%d|%d#@%s#@%s#@%s#@",char.getInt(charaindex,"ֳƺ"),num,Nodata,jiedata,indexdata) + lssproto.CharTitleSend(fd,data) +-- print("CharTitleSendͳɹ"..data.."\n") +end + +function GetTtileBuff(id) + if id >96 or id < 1 then + return 0,0,0,0 + end + return titleinfo[id][3],titleinfo[id][4],titleinfo[id][5],titleinfo[id][6] +end + +function data() + titleinfo = { -- ˯ ʯ + {"صľ +5",1,0,0,5,0,0,0,0,0,0} + ,{"ˮľ HP+20",2,20,0,0,0,0,0,0,0,0} + ,{"׵ľ +5",3,0,5,0,0,0,0,0,0,0} + ,{"ľ +5",4,0,0,0,5,0,0,0,0,0} + ,{"ľ ȫ+1",5,1,1,1,1,0,0,0,0,0} + ,{"ʺľ ȫ+2",6,2,2,2,2,0,0,0,0,0} + ,{"ʹ HP+10",7,10,0,0,0,0,0,0,0,0} + ,{" ȫ+2",8,2,2,2,2,0,0,0,0,0} + ,{"·ߵҶ ȫ+4",9,4,4,4,4,0,0,0,0,0} + ,{"ˮС ȫ+6",10,6,6,6,6,0,0,0,0,0} + ,{"૵ĸ ȫ+8",11,8,8,8,8,0,0,0,0,0} + ,{"ϵӰ ȫ+10",12,10,10,10,10,0,0,0,0,0} + ,{"ܵĴ ȫ+12",13,12,12,12,12,0,0,0,0,0} + ,{"ķ ȫ+14",14,14,14,14,14,0,0,0,0,0} + ,{"ҡҷĽ ȫ+16",15,16,16,16,16,0,0,0,0,0} + ,{"ϲĴ ȫ+18",16,18,18,18,18,0,0,0,0,0} + ,{"̺̫ ȫ+20",17,20,20,20,20,0,0,0,0,0} + ,{"ηļž ȫ+30",18,30,30,30,30,0,0,0,0,0} + ,{"`ӡ +5",19,0,5,0,0,0,0,0,0,0} + ,{"תֻ +20",20,0,0,20,0,0,0,0,0,0} + ,{"ַ +5",21,0,5,0,0,0,0,0,0,0} + ,{" ҿ+5",22,0,0,0,0,0,0,0,0,5} + ,{"ᱦ ʯ+5",23,0,0,0,0,0,0,0,5,0} + ,{"´ᱦ ˯+5",24,0,0,0,0,0,0,5,0,0} + ,{"ϳɴ +5",25,0,0,0,5,0,0,0,0,0} + ,{"ϳɸ +3",26,0,0,0,3,0,0,0,0,0} + ,{" +5",27,0,5,0,0,0,0,0,0,0} + ,{" +3",28,0,3,0,0,0,0,0,0,0} + ,{" +5",29,0,0,5,0,0,0,0,0,0} + ,{" +3",30,0,0,3,0,0,0,0,0,0} + ,{"սʿ HP+10",31,10,0,0,0,0,0,0,0,0} + ,{"ʥʿ HP+15",32,15,0,0,0,0,0,0,0,0} + ,{"˿Ӣ HP+20",33,20,0,0,0,0,0,0,0,0} + ,{"ķӢ HP+25",34,25,0,0,0,0,0,0,0,0} + ,{"˹ʹ HP+30",35,30,0,0,0,0,0,0,0,0} + ,{"˹½Ӣ HP+100",36,100,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + } + +end + +function main() + data(); +end diff --git a/服务器端lua文件/ablua/freecomplianceparameter.lua b/服务器端lua文件/ablua/freecomplianceparameter.lua new file mode 100644 index 0000000..c3e1bd9 --- /dev/null +++ b/服务器端lua文件/ablua/freecomplianceparameter.lua @@ -0,0 +1,188 @@ +--luaӦװǶںCأӿ! +function getIntPart(x) + if x <= 0 then + return math.ceil(x); + end + if math.ceil(x) == x then + return math.ceil(x); + else + return math.ceil(x) - 1; + end +end + +function GetTtileBuff(id) + if id >96 or id < 1 then + return 0,0,0,0 + end + return titleinfo[id][3],titleinfo[id][4],titleinfo[id][5],titleinfo[id][6],titleinfo[id][7],titleinfo[id][8],titleinfo[id][9],titleinfo[id][10],titleinfo[id][11] +end + +function FreeComplianceParameter( charaindex ) + if char.getInt(charaindex, "") == 3 then + local data= char.getChar(charaindex,"ף״̬") + if data~="" then + local hp = other.atoi(other.getString(data, "|", 1)) + local at = other.atoi(other.getString(data, "|", 2)) + local df = other.atoi(other.getString(data, "|", 3)) + local dx = other.atoi(other.getString(data, "|", 4)) + + char.setWorkInt(charaindex, "HP", char.getWorkInt(charaindex, "HP") + hp) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + at) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + df) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + dx) + + end + end + + + + if char.getInt(charaindex, "") == 1 then + local itemindex = char.getItemIndex(charaindex,6) + if itemindex > 0 then + local data1 = item.getChar(itemindex, "ֶ") + local attrate = other.atoi(other.getString(data1, "|", 1)) + local defrate = other.atoi(other.getString(data1, "|", 2)) + local dexrate = other.atoi(other.getString(data1, "|", 3)) + char.setWorkInt(charaindex, "", math.floor(char.getWorkInt(charaindex, "") * (100+attrate)/100)) + char.setWorkInt(charaindex, "", math.floor(char.getWorkInt(charaindex, "") * (100+defrate)/100)) + char.setWorkInt(charaindex, "", math.floor(char.getWorkInt(charaindex, "") * (100+dexrate)/100)) + char.setWorkInt(charaindex, "HP", char.getWorkInt(charaindex, "HP") + 150) + end + + for i = 1,96 do + if char.getCharNewTitleMode(charaindex,i-1)== 1 then + temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9 = GetTtileBuff(i) + addhp = addhp + temp1 + addat = addat + temp2 + adddf = adddf + temp3 + adddx = adddx + temp4 + addpo = addpo + temp5 + addpa = addpa + temp6 + addsl = addsl + temp7 + addst = addst + temp8 + addco = addco + temp9 + end + end + char.setWorkInt(charaindex, "HP", char.getWorkInt(charaindex, "HP") + addhp) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + addat) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + adddf) + char.setWorkInt(charaindex, "", char.getWorkInt(charaindex, "") + adddx) + char.setWorkInt(charaindex, "", addpo) + char.setWorkInt(charaindex, "鿹", addpa) + char.setWorkInt(charaindex, "˯", addsl) + char.setWorkInt(charaindex, "ʯ", addst) + char.setWorkInt(charaindex, "쿹", addco) + + end + +end + +function data() + titleinfo = { -- ˯ ʯ + {"صľ +5",1,0,0,5,0,0,0,0,0,0} + ,{"ˮľ HP+20",2,20,0,0,0,0,0,0,0,0} + ,{"׵ľ +5",3,0,5,0,0,0,0,0,0,0} + ,{"ľ +5",4,0,0,0,5,0,0,0,0,0} + ,{"ľ ȫ+1",5,1,1,1,1,0,0,0,0,0} + ,{"ʺľ ȫ+2",6,2,2,2,2,0,0,0,0,0} + ,{"ʹ HP+10",7,10,0,0,0,0,0,0,0,0} + ,{" ȫ+2",8,2,2,2,2,0,0,0,0,0} + ,{"·ߵҶ ȫ+4",9,4,4,4,4,0,0,0,0,0} + ,{"ˮС ȫ+6",10,6,6,6,6,0,0,0,0,0} + ,{"૵ĸ ȫ+8",11,8,8,8,8,0,0,0,0,0} + ,{"ϵӰ ȫ+10",12,10,10,10,10,0,0,0,0,0} + ,{"ܵĴ ȫ+12",13,12,12,12,12,0,0,0,0,0} + ,{"ķ ȫ+14",14,14,14,14,14,0,0,0,0,0} + ,{"ҡҷĽ ȫ+16",15,16,16,16,16,0,0,0,0,0} + ,{"ϲĴ ȫ+18",16,18,18,18,18,0,0,0,0,0} + ,{"̺̫ ȫ+20",17,20,20,20,20,0,0,0,0,0} + ,{"ηļž ȫ+30",18,30,30,30,30,0,0,0,0,0} + ,{"`ӡ +5",19,0,5,0,0,0,0,0,0,0} + ,{"תֻ +20",20,0,0,20,0,0,0,0,0,0} + ,{"ַ +5",21,0,5,0,0,0,0,0,0,0} + ,{" ҿ+5",22,0,0,0,0,0,0,0,0,5} + ,{"ᱦ ʯ+5",23,0,0,0,0,0,0,0,5,0} + ,{"´ᱦ ˯+5",24,0,0,0,0,0,0,5,0,0} + ,{"ϳɴ +5",25,0,0,0,5,0,0,0,0,0} + ,{"ϳɸ +3",26,0,0,0,3,0,0,0,0,0} + ,{" +5",27,0,5,0,0,0,0,0,0,0} + ,{" +3",28,0,3,0,0,0,0,0,0,0} + ,{" +5",29,0,0,5,0,0,0,0,0,0} + ,{" +3",30,0,0,3,0,0,0,0,0,0} + ,{"սʿ HP+10",31,10,0,0,0,0,0,0,0,0} + ,{"ʥʿ HP+15",32,15,0,0,0,0,0,0,0,0} + ,{"˿Ӣ HP+20",33,20,0,0,0,0,0,0,0,0} + ,{"ķӢ HP+25",34,25,0,0,0,0,0,0,0,0} + ,{"˹ʹ HP+30",35,30,0,0,0,0,0,0,0,0} + ,{"˹½Ӣ HP+100",36,100,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + ,{"","",0,0,0,0,0,0,0,0,0} + } + + + + +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/freelogincheck.lua b/服务器端lua文件/ablua/freelogincheck.lua new file mode 100644 index 0000000..974615b --- /dev/null +++ b/服务器端lua文件/ablua/freelogincheck.lua @@ -0,0 +1,75 @@ +--¼̶ȡ֤ +function FreeLoginCheck(fd) + local mun = 0 + local maxnum = 0 + local maxplayer = config.getFdnum() - 1 + local mac = net.getMac(fd) + local ip = net.getIP(fd) + + if mac == "" then + lssproto.CharList(fd, "ʹ÷DZϿɵijϷԽֹĵ½") + return 0 + end + if string.len(mac) < 32 then + lssproto.CharList(fd, "ʹ÷DZϿɵijϷԽֹĵ½") + return 0 + end + local key = other.getString(mac, "-", 1) + if key ~= "ver100" then + lssproto.CharList(fd, "İ汾ɣºٽϷ") + return 0 + end + + local mainmac = other.getString(mac, "-", 2) + + maxnum = 2 + for i = 5, maxplayer do + if net.getUse(i) == 1 then + if mac == net.getMac(i) then + mun = mun + 1 + if mun > maxnum then + lssproto.CharList(fd, "Ϸ˺ŵ½Դ" .. mun - 1 .. "벻ҪϷ") + return 0 + end + end + end + end + + token = "SELECT count(*) FROM `CSAlogin` " + .. " WHERE `MAC` = '" .. mac .. "' and `Online` > 0" + ret = sasql.query(token) + local totalnum = 1 + if ret == 1 then + sasql.free_result() + sasql.store_result() + num = sasql.num_rows() + if num > 0 then + sasql.fetch_row(0) + onlinenum = other.atoi(sasql.data(1)) + if onlinenum > totalnum then + lssproto.CharList(fd, "Ϸ¼˺Ѵޣ벻ҪϷ") + return 0 + end + end + end + + return 1 +end + +function CheckNologin(mac) + for j=1,table.getn(nologin) do + if mac==nologin[j] then + return 1 + end + end + return 0 +end + +function data() + + +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/freemodeexp.lua b/服务器端lua文件/ablua/freemodeexp.lua new file mode 100644 index 0000000..d82f8fa --- /dev/null +++ b/服务器端lua文件/ablua/freemodeexp.lua @@ -0,0 +1,22 @@ +function FreeModeExp( charindex, getexp, modexp ) + local exp = getexp*config.getBattleexp() + ((getexp*modexp*2)/100) + local fmmap = char.getWorkInt(charindex,"ͼ") + + if char.getInt(charindex,"λ")>0 and char.getInt(charindex,"λ")~=2 then + if char.getChar(charindex, "") == other.getString(family.ShowPointListArray(0), "|", 6) then + exp = math.floor(exp*1.2) + elseif char.getChar(charindex, "") == other.getString(family.ShowPointListArray(1), "|", 6) then + exp = math.floor(exp*1.2) + end + end + + return exp +end + +function data() + +end + +function main() + data() +end diff --git a/服务器端lua文件/ablua/freesamenu.lua b/服务器端lua文件/ablua/freesamenu.lua new file mode 100644 index 0000000..4d03872 --- /dev/null +++ b/服务器端lua文件/ablua/freesamenu.lua @@ -0,0 +1,107 @@ +function FreeSaMenu(meindex, index) +-- char.TalkToCli(meindex, -1, char.getWorkInt(meindex,"NPCʱ3"), "ɫ") + local սģ = char.getWorkInt(meindex,"ս"); + parameter = {meindex} + if index == 11 then + if սģ ==0 then + char.Encounter(meindex) + char.TalkToCli(meindex, -1, "ԭУ", "ɫ") + else + char.TalkToCli(meindex, -1, "ѾսУ", "ɫ") + end + elseif index == 12 then + char.ClearEncounter(meindex); + char.TalkToCli(meindex, -1, "رԭУ", "ɫ") + elseif index == 13 then + if սģ == 0 then + other.CallFunction("CheckTalked", "data/ablua/npc/check/check.lua", parameter) + end + -- other.CallFunction("ShowHead", "data/ablua/npc/vipshop/vipshop.lua", parameter) + elseif index == 14 then + other.CallFunction("QueryMissionTalked", "data/ablua/npc/querymission/querymission.lua", parameter) + elseif index == 16 then + other.CallFunction("FreeDataInfoShow", "data/ablua/freedatainfoshow.lua", parameter) + elseif index == 17 then + lssproto.SaMenu(meindex, index, "http://www.stoneage.es") + elseif index == 18 then + lssproto.SaMenu(meindex, index, "http://www.stoneage.es/forum.php") + elseif index == 19 then + lssproto.SaMenu(meindex, index, "http://www.stoneage.es/pay.php") + elseif index == 20 then + char.setWorkInt(meindex,"NPCʱ3",1) + other.CallFunction("OnlineService", "data/ablua/npc/onlineservice/onlineservice.lua", parameter) + elseif index == 21 then + lssproto.SaMenu(meindex, index, "http://www.stoneage.es/forum.php?mod=viewthread&tid=54&extra=page%3D1") + elseif index == 22 then + lssproto.SaMenu(meindex, index, "http://www.stoneage.es/bbs/forum.php?mod=viewthread&tid=226") + elseif index == 30 then--лӳ + if char.getWorkInt(meindex, "") == 1 then + תƶ[meindex]={}; + local Ա = ""; + local =0; + for i=1,4 do + local Ա = char.getWorkInt(meindex, "Ա" .. i+1) + if char.check(Ա) == 1 then + = + 1; + תƶ[meindex][] = Ա; + Ա = string.format("%s %s\n",Ա,char.getChar(תƶ[meindex][],"")); + end + end + local = "1 ѡµĶӳ\n"..Ա; + lssproto.windows(meindex, 2, 8, 0, char.getWorkInt( npcindex, ""), ) + else + char.TalkToCli(meindex, -1, "ùҪӳȨ", "ɫ") + end + else + char.TalkToCli(meindex, -1, "δ", "ɫ") + end +end + + +function WindowTalked( NPC, , , ť, ) + if == 0 then + local ѡ = tonumber(); + if ѡ > 0 and ѡ < 5 then + char.DischargeParty(,0); + char.JoinParty(תƶ[][ѡ],,0); + char.TalkToCli(תƶ[][ѡ], -1, "Ķѡ"..char.getChar(,"").."ѶӳȨ", "ɫ") + char.TalkToCli(, -1, "ɹѶӳȨѡ"..char.getChar(תƶ[][ѡ],"").."", "ɫ"); + for i =1,table.getn(תƶ[]) do + if i ~= ѡ then + char.JoinParty(תƶ[][ѡ],תƶ[][i],0); + end + end + char.Encounter(תƶ[][ѡ]) + end + end +end + +function Create(name, metamo, floor, x, y, dir) + npcindex = npc.CreateNpc(name, metamo, floor, x, y, dir) + char.setFunctionPointer(npcindex, "¼", "WindowTalked", "") +end + +function data() + תƶ={}; +--[[ + +11 ԭ +12 ȡԭ +13 ֧Ʊ +14 ѯ +16 Ϣ +20 ʹ +21 +22 ְ + + +]] + + +end + +function main() + data() + Create("ѯNPCʱ", 100000, 777, 20, 21, 4); +end + diff --git a/服务器端lua文件/ablua/item/attcteffect.lua b/服务器端lua文件/ablua/item/attcteffect.lua new file mode 100644 index 0000000..26a9812 --- /dev/null +++ b/服务器端lua文件/ablua/item/attcteffect.lua @@ -0,0 +1,47 @@ +¼߼¼={}; + + +function WindowTalked ( meindex, charaindex, seqno, select, data) + if seqno == 1 then + local λ = other.atoi(data); + if λ >=1 and λ<=4 then + local = char.getCharPet(charaindex, λ-1); + if char.check() == 1 then + ¼߼¼[charaindex][3] = ; + local Ի = "Ƿ "..char.getChar(,"") .." ѧϰЧ" + lssproto.windows(charaindex, "Ի", "ȷ|ȡ", 2, char.getWorkInt( npcindex, ""),Ի ) + end + end + elseif seqno == 2 then + if select == 1 then + local ЧID = other.atoi(item.getChar(¼߼¼[charaindex][1], "ֶ")) + char.setInt(¼߼¼[charaindex][3],"Ч",ЧID); + char.DelItem(charaindex, ¼߼¼[charaindex][2]); + char.TalkToCli(charaindex, -1, "ij"..char.getChar(¼߼¼[charaindex][3],"").."ϰùЧ,ȥɣ", "ɫ") + ¼߼¼[charaindex]=nil; + end + end +end + +function attackeffect(itemindex, charaindex, toindex, haveitemindex) + ¼߼¼[charaindex]={}; + ¼߼¼[charaindex][1]=itemindex; + ¼߼¼[charaindex][2]=haveitemindex; + lssproto.windows(charaindex, "", "ȷ", 1, char.getWorkInt( npcindex, ""), "") +end + +function Create(name, metamo, floor, x, y, dir) + --NPC(NPC֣ͼţͼţXY)һNPC + npcindex = npc.CreateNpc(name, metamo, floor, x, y, dir) + char.setFunctionPointer(npcindex, "¼", "WindowTalked", "") +end + + +function data() +end + +function main() + Create("ЧNPC",100000,777,20,20,3); + + item.addLUAListFunction( "ITEM_ATTACKEFFECT", "attackeffect", "") +end diff --git a/服务器端lua文件/ablua/item/chartitle.lua b/服务器端lua文件/ablua/item/chartitle.lua new file mode 100644 index 0000000..74000ae --- /dev/null +++ b/服务器端lua文件/ablua/item/chartitle.lua @@ -0,0 +1,38 @@ +function titleuse(itemindex, charaindex, toindex, haveitemindex) + local id = other.atoi(item.getChar(itemindex, "ֶ")) + if GetCharNewTitleMode(charaindex,id -1)== 1 then + char.TalkToCli(charaindex, -1, "ӵиóƺţ", "ɫ") + return + end + local titlename = item.getChar(itemindex,"ʾ") + char.DelItem(charaindex, haveitemindex) + char.setCharNewTitleMode(charaindex,id -1) +-- char.setInt(charaindex, "ƺ״̬2", 0) +--- char.setInt(charaindex, "ƺ״̬3", 0) + + char.TalkToCli(charaindex, -1, "ϲ³ƺ"..titlename.."", "ɫ") + char.talkToServer(-1, "[]ϲ " .. char.getChar(charaindex, "") .. " "..titlename.."ƺ", "ɫ") + local param = {charaindex} + other.CallFunction("TitleListSend", "data/ablua/freechartitle.lua", param) +end + +function GetCharNewTitleMode(charaindex,id) + if id< 32 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬1"),id)~= 0 then + return 1 + end + elseif id< 64 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬2"),id-32)~= 0 then + return 1 + end + elseif id< 96 then + if other.DataAndData(char.getInt(charaindex,"ƺ״̬3"),id-64)~= 0 then + return 1 + end + end + return 0 +end + +function main() + item.addLUAListFunction( "ITEM_TITLE", "titleuse", "") +end diff --git a/服务器端lua文件/ablua/item/itemMax.lua b/服务器端lua文件/ablua/item/itemMax.lua new file mode 100644 index 0000000..1b89cae --- /dev/null +++ b/服务器端lua文件/ablua/item/itemMax.lua @@ -0,0 +1,26 @@ +function useitemmax(itemindex, charaindex, toindex, haveitemindex) + + local data = other.atoi(item.getChar(itemindex, "ֶ")) + if (char.getInt(charaindex,"״̬")~=2 and data == 3) + or (char.getInt(charaindex,"״̬")~=0 and data == 2) then + char.TalkToCli(charaindex, -1,"Ӧչչ", "ɫ") + return + end + if char.getInt(charaindex,"״̬") == 2 then + char.setInt(charaindex,"״̬",6); + char.DelItem(charaindex, haveitemindex) + char.TalkToCli(charaindex, -1,"ϲ!", "ɫ") + char.UpCahrData(charaindex,"p"); + elseif char.getInt(charaindex,"״̬") == 6 then + char.TalkToCli(charaindex, -1,"Ѿȫ!", "ɫ") + else + char.DelItem(charaindex, haveitemindex) + char.setInt(charaindex,"״̬",2); + char.TalkToCli(charaindex, -1,"ϲڶ!", "ɫ") + char.UpCahrData(charaindex,"p"); + end +end + +function main() + item.addLUAListFunction( "ITEM_USEITEMMAX", "useitemmax", "") +end diff --git a/服务器端lua文件/ablua/item/opentrump.lua b/服务器端lua文件/ablua/item/opentrump.lua new file mode 100644 index 0000000..ca78cb7 --- /dev/null +++ b/服务器端lua文件/ablua/item/opentrump.lua @@ -0,0 +1,15 @@ +function opentrump(itemindex, charaindex, toindex, haveitemindex) + + if char.getInt(charaindex,"״̬")>0 then + char.TalkToCli(charaindex, -1,"Ѿ˷װ!", "ɫ") + return + end + char.DelItem(charaindex, haveitemindex) + char.setInt(charaindex,"״̬",1); + char.UpCahrData(charaindex,"p"); + char.TalkToCli(charaindex, -1,"ķװѳɹ!", "ɫ") +end + +function main() + item.addLUAListFunction( "ITEM_OPENTRUMP", "opentrump", "") +end diff --git a/服务器端lua文件/ablua/magic/addpaypoint.lua b/服务器端lua文件/ablua/magic/addpaypoint.lua new file mode 100644 index 0000000..be8b91d --- /dev/null +++ b/服务器端lua文件/ablua/magic/addpaypoint.lua @@ -0,0 +1,29 @@ +function addpay(charaindex, data) + local value = other.atoi(other.getString(data, " ", 1)) + local cdkey = other.getString(data, " ", 2) + if cdkey == "" then + local oldvalue = sasql.getPayPoint(charaindex) + sasql.setPayPoint(charaindex, sasql.getPayPoint(charaindex) + value) + char.TalkToCli(charaindex, -1, "ɹ˺[" .. char.getChar(charaindex, "˺") .. "][" .. char.getChar(charaindex, "") .. "]˳ֵԭ" .. oldvalue .. "Ϊ" .. sasql.getPayPoint(charaindex), "ɫ") + else + local maxplayer = char.getPlayerMaxNum() + local cimelia = other.atoi(data) + for i = 0, maxplayer - 1 do + if char.check(i) == 1 then + if char.getChar(i, "˺") == cdkey then + local oldvalue = sasql.getPayPoint(i) + sasql.setPayPoint(i, sasql.getPayPoint(i) + value) + char.TalkToCli(charaindex, -1, "ɹ˺[" .. char.getChar(i, "˺") .. "][" .. char.getChar(i, "") .. "]˳ֵԭ" .. oldvalue .. "Ϊ" .. sasql.getPayPoint(i), "ɫ") + char.TalkToCli(i, -1, "GM[" .. char.getChar(charaindex, "") .. "]ĸ˳ֵԭ" .. oldvalue .. "Ϊ" .. sasql.getPayPoint(i), "ɫ") + return + end + end + end + end +end + +function main() + minute = 0 + magic.addLUAListFunction("ֵ", "addpay", "", 1, "[]") +end + diff --git a/服务器端lua文件/ablua/magic/addvippoint.lua b/服务器端lua文件/ablua/magic/addvippoint.lua new file mode 100644 index 0000000..1a637e7 --- /dev/null +++ b/服务器端lua文件/ablua/magic/addvippoint.lua @@ -0,0 +1,29 @@ +function addvip(charaindex, data) + local value = other.atoi(other.getString(data, " ", 1)) + local cdkey = other.getString(data, " ", 2) + if cdkey == "" then + local oldvalue = sasql.getVipPoint(charaindex) + sasql.setVipPoint(charaindex, sasql.getVipPoint(charaindex) + value) + char.TalkToCli(charaindex, -1, "ɹ˺[" .. char.getChar(charaindex, "˺") .. "][" .. char.getChar(charaindex, "") .. "]˻Աԭ" .. oldvalue .. "Ϊ" .. sasql.getVipPoint(charaindex), "ɫ") + else + local maxplayer = char.getPlayerMaxNum() + local cimelia = other.atoi(data) + for i = 0, maxplayer - 1 do + if char.check(i) == 1 then + if char.getChar(i, "˺") == cdkey then + local oldvalue = sasql.getVipPoint(i) + sasql.setVipPoint(i, sasql.getVipPoint(i) + value) + char.TalkToCli(charaindex, -1, "ɹ˺[" .. char.getChar(i, "˺") .. "][" .. char.getChar(i, "") .. "]˻Աԭ" .. oldvalue .. "Ϊ" .. sasql.getVipPoint(i), "ɫ") + char.TalkToCli(i, -1, "GM[" .. char.getChar(charaindex, "") .. "]ĸ˻Աԭ" .. oldvalue .. "Ϊ" .. sasql.getVipPoint(i), "ɫ") + return + end + end + end + end +end + +function main() + minute = 0 + magic.addLUAListFunction("Ա", "addvip", "", 1, "[]") +end + diff --git a/服务器端lua文件/ablua/magic/announce.lua b/服务器端lua文件/ablua/magic/announce.lua new file mode 100644 index 0000000..24b2487 --- /dev/null +++ b/服务器端lua文件/ablua/magic/announce.lua @@ -0,0 +1,22 @@ +function NetLoopFunction() + if minute > 0 then + if math.mod(looptime , minute) == 0 then + char.talkToAllServer("[ܰʾ]" .. message) + end + + looptime = looptime + 1 + end +end + +function announce(charaindex, data) + message = other.getString(data, " ", 1) + char.talkToAllServer("[ܰʾ]" .. message) + minute = other.atoi(other.getString(data, " ", 2)) + looptime = 1 +end + +function main() + minute = 0 + magic.addLUAListFunction("", "announce", "", 1, "[ ()") +end + diff --git a/服务器端lua文件/ablua/magic/attackeffect.lua b/服务器端lua文件/ablua/magic/attackeffect.lua new file mode 100644 index 0000000..bbd37dc --- /dev/null +++ b/服务器端lua文件/ablua/magic/attackeffect.lua @@ -0,0 +1,9 @@ +function Ч(charaindex, data) + local ЧID = other.atoi(other.getString(data, " ", 2)); + char.setWorkInt(char.getCharPet(charaindex,0),"Ч",ЧID); + --char.setWorkInt(charaindex,"Ч",ЧID); +end + +function main() + magic.addLUAListFunction("Ч", "Ч", "", 1, "[gm Ч ]") +end diff --git a/服务器端lua文件/ablua/other/familybadge/data.txt b/服务器端lua文件/ablua/other/familybadge/data.txt new file mode 100644 index 0000000..ea60963 --- /dev/null +++ b/服务器端lua文件/ablua/other/familybadge/data.txt @@ -0,0 +1,101 @@ +59000 +59001 +59002 +59003 +59004 +59005 +59006 +59007 +59008 +59009 +59010 +59011 +59012 +59013 +59014 +59015 +59016 +59017 +59018 +59019 +59020 +59021 +59022 +59023 +59024 +59025 +59026 +59027 +59028 +59029 +59030 +59031 +59032 +59033 +59034 +59035 +59036 +59037 +59038 +59039 +59040 +59041 +59042 +59043 +59044 +59045 +59046 +59047 +59048 +59049 +59050 +59051 +59052 +59053 +59054 +59055 +59056 +59057 +59058 +59059 +59060 +59061 +59062 +59063 +59064 +59065 +59066 +59067 +59068 +59069 +59070 +59071 +59072 +59073 +59074 +59075 +59076 +59077 +59078 +59079 +59080 +59081 +59082 +59083 +59084 +59085 +59086 +59087 +59088 +59089 +59090 +59091 +59092 +59093 +59094 +59095 +59096 +59097 +59098 +59099 +59100 \ No newline at end of file diff --git a/服务器端lua文件/ablua/other/familybadge/init.lua b/服务器端lua文件/ablua/other/familybadge/init.lua new file mode 100644 index 0000000..22ae099 --- /dev/null +++ b/服务器端lua文件/ablua/other/familybadge/init.lua @@ -0,0 +1,55 @@ +local ={}; +local =""; + + + +function ַи(,иַ) + = .. иַ + local t = {} + local Ŀǰλ = 1 + repeat + local nexti = string.find(, иַ, Ŀǰλ) + table.insert(t, string.sub(, Ŀǰλ,nexti-string.len(иַ))) + Ŀǰλ = nexti + string.len(иַ) + until Ŀǰλ > string.len() + return t +end + + +function LoadFamilyBadge(fd) + lssproto.FamilyBadge(fd,); +end + +function ȡ() + local ļ; + local ,; + ļ = assert(io.open("./data/ablua/other/familybadge/data.txt", "r")) + = ļ:read("*a"); -- ȡ + ļ:close(); + = ¼۸.."|" + if ~= "" then + = 0; + = ַи(,"\n"); + for b = 1,table.getn() do + if string.sub([b],1,1) ~= "#" then + = + 1; + [] = tonumber([b]); + end + end + for b=1,table.getn() do + if b~=table.getn() then + = .. [b].."|"; + else + = .. [b]; + end + end + end +end + +function main() + ¼۸=1000; + ȡ(); + lssproto.GetFBData(,¼۸); +end +main(); + diff --git a/服务器端lua文件/lua/init.lua b/服务器端lua文件/lua/init.lua new file mode 100644 index 0000000..a0ff654 --- /dev/null +++ b/服务器端lua文件/lua/init.lua @@ -0,0 +1,12 @@ +function ű(·) + return dofile(·); +end + +function () + ű("./data/lua/onlineshop/main.lua"); + --ʱ + math.randomseed(os.time()); +end + +() + diff --git a/服务器端lua文件/lua/onlineshop/main.lua b/服务器端lua文件/lua/onlineshop/main.lua new file mode 100644 index 0000000..cdf3a04 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/main.lua @@ -0,0 +1,256 @@ +function ַи(,иַ) + = .. иַ + local t = {} + local Ŀǰλ = 1 + repeat + local nexti = string.find(, иַ, Ŀǰλ) + table.insert(t, string.sub(, Ŀǰλ,nexti-string.len(иַ))) + Ŀǰλ = nexti + string.len(иַ) + until Ŀǰλ > string.len() + return t +end +ʱNPC = {}; +--[[=========̳DZ===========]] +̳ = {}; +̳.ϼ={}; +̳.Ʒ={}; +̳.Ʒ={}; +̳.Ʒ={}; +̳.Ʒ={}; + +̳ǵ = {{"צ",1},{"ͷ",1},{"",1},{"ǹ",1},{"",1},{"",1},{"",1},{"",1},{"ֻ",1},{"",1} +,{"",1},{"",1},{"",1},{"",1},{"ǻ",1},{"",1},{"",0},{"",1},{"Ͷ",1},{"Ͷʯ",1} +,{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0},{"",1},{"",1},{"ѥ",1},{"",1},{"ʹ",0},{"",0}, +{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0},{"δ֪",0}} + + = {{"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {";",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"˯",%_˯%,1}, + {"ʯ",%_ʯ%,1}, + {"",%_%,1}, + {"",%_%,1}, + {"һ",%_һ%,1} + }--˵ǵЩֵҪ100ã +--[[=========================================================================]] + +function ̳NPCص(NPC) + .עԻص("", "̳ǶԻص", NPC) + return true; +end + +function ̳NPC() + ȡ̳(); + local Ʒ={}; + Ʒ[1] = ̳ݽ(̳.ϼ,""); + Ʒ[2] = ̳ݽ(̳.Ʒ,""); + Ʒ[3] = ̳ݽ(̳.Ʒ,""); + Ʒ[4] = ̳ݽ(̳.Ʒ,""); + Ʒ[5] = ̳ݽ(̳.Ʒ,""); + ϵͳ.д̳(0,Ʒ[1]); + ϵͳ.д̳(1,Ʒ[2]); + ϵͳ.д̳(2,Ʒ[3]); + ϵͳ.д̳(3,Ʒ[4]); + ϵͳ.д̳(4,Ʒ[5]); + Ʒ=nil; + ʱNPC.̳=ϵͳ.NPC("","̳NPCص") +end + +function ̳д־(,ﳵ,۳,ʱ̳,û۳ǰ) + local ¼۸=0; + local д־; + local ̳ǵ=""; + for i=1,table.getn(ﳵ) do + ̳ǵ = ̳ǵ .. .ȡģ(ﳵ[i][1],%_ԭ%).."*"..ﳵ[i][2].."("..ʱ̳[ﳵ[i][3]][2]*ﳵ[i][2]..")|"; + ¼۸=¼۸+ʱ̳[ﳵ[i][3]][2]*ﳵ[i][2]; + end + if ¼۸ > ۳ then + ̳ǵ = ̳ǵ.."#۳۸쳣" + end + д־ = string.format("%s Ʒļ۸%d ʵʿ۳%d û۳ǰ%d ۳%d\nƷ%s\n\n",Char.GetData(,%_ԭ%), + ¼۸,۳,û۳ǰ,.ȡ(,%_VIP%),̳ǵ); + + ļ=assert(io.open("./data/lua/onlineshop/shoplog.txt", "a+")) + ļ:write(д־); -- ȡ + ļ:close(); +end + +function ̳ǶԻص( NPC, , , ť, ) +--[[ + ťΪ0ʱѡҳ + Ϊ0ʱ,еݷֽ + ,#,# +]] + if ť == 0 then + local ̳ID = ת() + if ̳ID == 1 then + .ͶԻ(,1001,1,1,.ȡ߿().."|"...ȡ(,%_VIP%).."|1",NPC) + elseif ̳ID == 2 then + .ͶԻ(,1001,2,2,.ȡ߿().."|"...ȡ(,%_VIP%).."|2",NPC) + elseif ̳ID == 3 then + .ͶԻ(,1001,3,3,.ȡ߿().."|"...ȡ(,%_VIP%).."|3",NPC) + elseif ̳ID == 4 then + .ͶԻ(,1001,4,4,.ȡ߿().."|"...ȡ(,%_VIP%).."|4",NPC) + elseif ̳ID == 5 then + .ͶԻ(,1001,5,5,.ȡ߿().."|"...ȡ(,%_VIP%).."|5",NPC) + end + elseif ~= "" then + local ﳵ = ַи(,"#"); + local Ʒ = 0; + local Ʒܼ = 0; + local ƷID = {}; + local ʱ̳; + if ť == 1 then + ʱ̳ = ̳.ϼ; + elseif ť == 2 then + ʱ̳ = ̳.Ʒ; + elseif ť == 3 then + ʱ̳ = ̳.Ʒ; + elseif ť == 4 then + ʱ̳ = ̳.Ʒ; + elseif ť == 5 then + ʱ̳ = ̳.Ʒ; + end + for i=1,table.getn(ﳵ) do + if ﳵ[i] ~="" then + local ﳵٷ = ַи(ﳵ[i],"|"); + ƷID[i]={}; + ƷID[i][1] = ʱ̳[ת(ﳵٷ[1])][1]; + ƷID[i][2] = ת(ﳵٷ[2]); + ƷID[i][3] = ת(ﳵٷ[1]); + Ʒܼ = Ʒܼ + ʱ̳[ƷID[i][3]][2]*ƷID[i][2]; + Ʒ = Ʒ + ƷID[i][2]; + end + end + local Ҳʱ = .ȡ(,%_VIP%); + if Ҳʱ < Ʒܼ then + .˵(,"ϵͳϵĽҲ㡣",%ɫ%); + return; + end + if .ȡ߿() < Ʒ then + .˵(,"ϵͳϵĵλ㡣",%ɫ%); + return; + end + .(,%_VIP%,Ҳʱ-Ʒܼ); + for i=1,table.getn(ƷID) do + .(,ƷID[i][1],ƷID[i][2]); + end + + ̳д־(,ƷID,Ʒܼ,ʱ̳,Ҳʱ); + .˵(,"ϵͳ۳"..Ʒܼ.."ң",%ɫ%); + end +end + + +function ̳ݽ(ID,) + local = ""; + if table.getn(ID) < 1 then + return ""; + end + for =1,table.getn(ID) do + local ID = ID[][1]; + local = .ȡģ(ID,%_%); + local ͼ = .ȡģ(ID,%_ͼ%); + + = string.format("%s%s|%d|%d|%d|ͣ%s\n",,.ȡģ(ID,%_ԭ%),ͼ,ͼ,ID[][2],̳ǵ[+1][1]); + if ̳ǵ[+1][2]== 1 then + if .ȡģ(ID,%_MAX;%) == 0 then + = ..";öȣ\n\n" + else + = string.format("%s;öȣ%d/%d\n\n",,math.ceil(.ȡģ(ID,%_;%)/100),math.ceil(.ȡģ(ID,%_MAX;%)/100)); + end + for = 1,table.getn() do --//Եֵ + local ֵ = .ȡģ(ID,[][2]); + if ֵ ~= 0 then + = string.format("%s%s %s\n",,[][1],Է(ֵ)); + end + end + if .ȡģ(ID,%_%) >= 0 then + = string.format("%s\n %s",,.ȡ鼼(.ȡģ(ID,%_%),%_%)); + end + = .."#"; + else + = ...ȡģ(ID,%_˵%).."#"; + end + end + return ; +end + +function Է()--//ӵֵ + if > 0 then + return "+"..; + else + return ; + end +end + +function ְҵ(ID)--صҪְҵ + local ְҵ = .ȡģ(ID,%_ְҵ%); + if ְҵ == 0 then + return "(ͨ)" + elseif ְҵ == 1 then + return "(ʿ)" + elseif ְҵ == 2 then + return "(鷨ʦ)" + elseif ְҵ == 3 then + return "(׷)" + end +end + +function ITRF_NEWSHOP()--౾ص Ϊ ̳ +--[[ +̳˵ +߿|ʱ|ҳ| +]] + if .ȡ(,%_սģ%) == 0 and .ȡ(,%_̯%) <= 0 then + .ͶԻ(,1001,1,1,.ȡ߿().."|"...ȡ(,%_VIP%).."|1",ʱNPC.̳) + end +end + + +function ȡ̳() + local ļ; + local ,,ʱ̳; + for i =1,5 do + if i == 1 then + ʱ̳ = ̳.ϼ; + elseif i == 2 then + ʱ̳ = ̳.Ʒ; + elseif i == 3 then + ʱ̳ = ̳.Ʒ; + elseif i == 4 then + ʱ̳ = ̳.Ʒ; + elseif i == 5 then + ʱ̳ = ̳.Ʒ; + end + ļ = assert(io.open("./data/lua/onlineshop/shop"..i..".txt", "r")) + = ļ:read("*a"); -- ȡ + ļ:close(); + if ~= "" then + = 0; + = ַи(,"\n"); + for b = 1,table.getn() do + if string.sub([b],1,1) ~= "#" and string.sub([b],1,1) ~= "" then + = + 1; + ʱ̳[] = ַи([b],"|"); + ʱ̳[][1] = tonumber(ʱ̳[][1]); + ʱ̳[][2] = tonumber(ʱ̳[][2]); + end + end + end + end +end + +̳NPC(); + diff --git a/服务器端lua文件/lua/onlineshop/shop1.txt b/服务器端lua文件/lua/onlineshop/shop1.txt new file mode 100644 index 0000000..3059055 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/shop1.txt @@ -0,0 +1,3 @@ +#################ϼ###################### +#ʽ˵ID|۸ +18557|288 diff --git a/服务器端lua文件/lua/onlineshop/shop2.txt b/服务器端lua文件/lua/onlineshop/shop2.txt new file mode 100644 index 0000000..3059055 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/shop2.txt @@ -0,0 +1,3 @@ +#################ϼ###################### +#ʽ˵ID|۸ +18557|288 diff --git a/服务器端lua文件/lua/onlineshop/shop3.txt b/服务器端lua文件/lua/onlineshop/shop3.txt new file mode 100644 index 0000000..3059055 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/shop3.txt @@ -0,0 +1,3 @@ +#################ϼ###################### +#ʽ˵ID|۸ +18557|288 diff --git a/服务器端lua文件/lua/onlineshop/shop4.txt b/服务器端lua文件/lua/onlineshop/shop4.txt new file mode 100644 index 0000000..3059055 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/shop4.txt @@ -0,0 +1,3 @@ +#################ϼ###################### +#ʽ˵ID|۸ +18557|288 diff --git a/服务器端lua文件/lua/onlineshop/shop5.txt b/服务器端lua文件/lua/onlineshop/shop5.txt new file mode 100644 index 0000000..3059055 --- /dev/null +++ b/服务器端lua文件/lua/onlineshop/shop5.txt @@ -0,0 +1,3 @@ +#################ϼ###################### +#ʽ˵ID|۸ +18557|288 diff --git a/服务器端lua文件/lua/onlineshop/shoplog.txt b/服务器端lua文件/lua/onlineshop/shoplog.txt new file mode 100644 index 0000000..e69de29 diff --git a/石器时代8.5客户端最新源代码/.vs/石器源码/v14/.suo b/石器时代8.5客户端最新源代码/.vs/石器源码/v14/.suo new file mode 100644 index 0000000..4822907 Binary files /dev/null and b/石器时代8.5客户端最新源代码/.vs/石器源码/v14/.suo differ diff --git a/石器时代8.5客户端最新源代码/石器源码.sln b/石器时代8.5客户端最新源代码/石器源码.sln new file mode 100644 index 0000000..d8d87c3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "石器源码", "石器源码\石器源码.vcxproj", "{7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + VER25_DEBUG|Win32 = VER25_DEBUG|Win32 + VER25_RELEASE|Win32 = VER25_RELEASE|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE}.VER25_DEBUG|Win32.ActiveCfg = VER25_DEBUG|Win32 + {7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE}.VER25_DEBUG|Win32.Build.0 = VER25_DEBUG|Win32 + {7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE}.VER25_RELEASE|Win32.ActiveCfg = VER25_RELEASE|Win32 + {7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE}.VER25_RELEASE|Win32.Build.0 = VER25_RELEASE|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/石器时代8.5客户端最新源代码/石器源码.suo b/石器时代8.5客户端最新源代码/石器源码.suo new file mode 100644 index 0000000..1c05661 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码.suo differ diff --git a/石器时代8.5客户端最新源代码/石器源码/123.cur b/石器时代8.5客户端最新源代码/石器源码/123.cur new file mode 100644 index 0000000..8e2ead1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/123.cur differ diff --git a/石器时代8.5客户端最新源代码/石器源码/CharTitle.cpp b/石器时代8.5客户端最新源代码/石器源码/CharTitle.cpp new file mode 100644 index 0000000..b3fad18 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/CharTitle.cpp @@ -0,0 +1,403 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/font.h" +#include "../systeminc/action.h" +#include "systeminc\sprdisp.h" +#include "systeminc\menu.h" +#include "systeminc\mouse.h" +#include "newproto\autil.h" +#include "newproto\protocol.h" +#ifdef _CHARTITLE_STR_ +extern unsigned int sockfd; +typedef struct{ + BOOL ʾ; + BOOL ȷʾ; + int ǰҳ; + int ȷͼ; + char [100][32]; + int ƺ[100]; + TITLE_STR title;//ǰƺ + TITLE_STR titledata[100];//ƺ + BOOL رմ; +}ƺݽṹ; +extern int play_se(int tone, int x, int y); +ƺݽṹ ƺ; + +void 򿪳ƺŴڳʼ() +{ + if(ƺ.ʾ){ + ƺ.ʾ=FALSE; + ƺ.ȷʾ=FALSE; + }else{ + ƺ.ǰҳ=0; + ƺ.ʾ=TRUE; + ƺ.ȷʾ=FALSE; + } +} + +extern void PutTitleText(int x,int y,char fontPrio,TITLE_STR str,BOOL hitFlag); + +BOOL ȡƺȡ() +{ + return ƺ.رմ; +} + +void óƺȡ() +{ + if(ƺ.رմ) ƺ.رմ=FALSE; + else ƺ.رմ=TRUE; +} + +BOOL ȡǰƺǷ() +{ + return ƺ.title.flg; +} + +void ƺչʾ() +{ + if(ƺ.title.flg){ + PutTitleText(78-ƺ.title.len/2,49,FONT_PRIO_FRONT,ƺ.title,0); + } + int bnt; + bnt = StockFontBuffer(18,49,1,FONT_PAL_GREEN," ",2); + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(HitFontNo == bnt){ + if(ƺ.رմ) ƺ.رմ=FALSE; + else ƺ.رմ=TRUE; + play_se(203, 320, 240); + } + } +} + +BOOL ƺŴ(ACTION * pct) +{ + int x,y; + x = pct->x; + y = pct->y + 133; + int ť=-1; + int ť=-1; + int ťر=-1; + int ťID; + ť = StockDispBuffer( x -55, y + 7, DISP_PRIO_IME3, 55250, 2 ); + ť = StockDispBuffer( x -20, y + 7, DISP_PRIO_IME3, 55251, 2 ); + ťر = StockDispBuffer( x+40, y + 7, DISP_PRIO_IME3, 55252, 2 ); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if(!ƺ.ȷʾ){ + if(ť == HitDispNo){ + if(ƺ.ǰҳ){ + ƺ.ǰҳ--; + } + } + if(ť == HitDispNo){ + if(ƺ.ǰҳ!=19 && ƺ.titledata[(ƺ.ǰҳ+1)*5].flg) + { + ƺ.ǰҳ++; + } + } + if(ťر == HitDispNo){ + DeathAction(pct); + ƺ.ʾ=FALSE; + ƺ.ȷʾ=FALSE; + return TRUE; + } + } + } + + int i=0; + int ƺͼ; + for(;i<5;i++){ + ƺͼ = ƺ.ǰҳ*5+i; + if(ƺ.titledata[ƺͼ].flg) + { + PutTitleText(380-ƺ.titledata[ƺͼ].len/2,43+i*0x20,FONT_PRIO_FRONT,ƺ.titledata[ƺͼ],0); + char ƺ[128]; + sprintf_s(ƺ,"%03d",ƺͼ+1); + StockFontBufferExt(0x130,0x2D+i*0x20,1,FONT_PAL_GREEN,ƺ,0,19); + if(!ƺ.ȷʾ){ + if(MakeHitBox(0x124,0x26+i*0x20,0x1B8,0x44+i*0x20,0x6D)==1){ + StockFontBuffer(0x123,0xD1,2,0,ƺ.[ƺͼ],0); + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + ƺ.ȷͼ=ƺ.ƺ[ ƺͼ]; + ƺ.ȷʾ=TRUE; + } + } + } + }else break; + } + if(ƺ.ȷʾ){ + StockFontBuffer(0x123,0xD1,2,0,ƺ.[ƺ.ȷͼ],0); + StockFontBuffer(0x130,0x118,2,0,"ȷʹøóƺ",0); + StockDispBuffer(0x16D,0x130,0x6C,55253,1);//ȷڵͼ + ťID = StockDispBuffer(0x194,0x148,109,55252,2);//ر + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(ťID == HitDispNo){ + ƺ.ȷʾ=FALSE; + ƺ.ȷͼ=0; + } + } + ťID = StockDispBuffer(0x148,0x148,109,55254,2);//ȷ + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(ťID == HitDispNo){ + int checksum=0; + char buf[1024*4]; + memset(buf,0,1024*4); + checksum += util_mkint(buf, ƺ.ȷͼ); + util_mkint(buf, checksum); + util_SendMesg(sockfd, LSSPROTO_CHARTITLE_SEND, buf); + ƺ.ȷʾ=FALSE; + ƺ.ȷͼ=0; + } + } + } + return FALSE; +} +extern void getCharTitleSplit( char *str,TITLE_STR* title); +void ƺݸ(char *) +{ + char [126],ͼ[1024],ͼ[1024],ݽ[4000],ʱ[126]; + memset(,0,126); + memset(ͼ,0,1024); + memset(ͼ,0,1024); + memset(ݽ,0,4000); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",1,,126); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",1,ʱ,126); + int titleindex = atoi(ʱ); + extern char* FreeGetTitleStr(int id); + if(titleindex>0) getCharTitleSplit(FreeGetTitleStr(titleindex),&ƺ.title); + else memset(&ƺ.title,0,sizeof(TITLE_STR)); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",2,ʱ,126); + int = atoi(ʱ); + if(!=0){ + memset(&ƺ.titledata,0,sizeof(ƺ.titledata[0])*100); + memset(&ƺ.ƺ,0,sizeof(int)*100); + memset(&ƺ.,0,32*100); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",2,ͼ,1024); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",3,ݽ,4000); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",4,ͼ,1024); + int i=0; + extern char* FreeGetTitleStr(int id); + for(i;i<;i++){ + getStringFromIndexWithDelim_body((char *)ͼ,(char *)"|",i+1,ʱ,126); + titleindex = atoi(ʱ); + getCharTitleSplit(FreeGetTitleStr(titleindex),&ƺ.titledata[i]); + getStringFromIndexWithDelim_body((char *)ͼ,(char *)"|",i+1,ʱ,126); + ƺ.ƺ[i]=atoi(ʱ); + getStringFromIndexWithDelim_body((char *)ݽ,(char *)"|",i+1,ʱ,126); + sprintf_s(ƺ.[i],32,"%s",ʱ); + } + } +} + +void ʼƺŽṹ() +{ + memset(&ƺ,0,sizeof(ƺݽṹ)); +} +#endif + + + +#ifdef _CHARTITLE_ +extern unsigned int sockfd; +typedef struct{ + int ƺŴڽṹ; + ACTION *ƺŽṹ[5]; + ACTION * ǰƺŽṹ; + int ǰƺͼ; + BOOL ʾ; + int ͼ[100]; + int ƺ[100]; + char [100][32]; + int ǰҳ; + BOOL ȷʾ; + int ȷͼ; +}ƺݽṹ; + +ƺݽṹ ƺ; + +void ƺչʾ() +{ + int i=0; + for(i;i<5;i++){ + if(ƺ.ƺŽṹ[i]){ + if(ƺ.ƺŽṹ[i]) DeathAction(ƺ.ƺŽṹ[i]); + ƺ.ƺŽṹ[i]=0; + } + } +} + +void 򿪳ƺŴڳʼ() +{ + if(ƺ.ʾ){ + ƺչʾ(); + ƺ.ʾ=FALSE; + ƺ.ȷʾ=FALSE; + }else{ + ƺ.ǰҳ=0; + ƺ.ʾ=TRUE; + ƺ.ȷʾ=FALSE; + } +} + + +void ƺչʾ() +{ + + if(ƺ.ǰƺͼ) + if(!ƺ.ǰƺŽṹ){ + if(ƺ.ǰƺͼ < 100000){ + ƺ.ǰƺŽṹ = 0; + StockDispBuffer(0x7F,0x40,109,ƺ.ǰƺͼ,0); + }else{ + ƺ.ǰƺŽṹ = MakeAnimDisp(0x7F,0x59,ƺ.ǰƺͼ,0); + } + }else if(*(int *)(ƺ.ǰƺŽṹ+0x140)!= ƺ.ǰƺͼ){ + DeathAction(ƺ.ǰƺŽṹ); + if(ƺ.ǰƺͼ < 100000){ + ƺ.ǰƺŽṹ = 0; + StockDispBuffer(0x7F,0x40,109,ƺ.ǰƺͼ,0); + }else{ + ƺ.ǰƺŽṹ = MakeAnimDisp(0x7F,0x59,ƺ.ǰƺͼ,0); + } + } +} + +BOOL ƺŴ(ACTION * pct) +{ + int x,y; + x = pct->x; + y = pct->y + 133; + int ť=-1; + int ť=-1; + int ťر=-1; + int ťID; + ť = StockDispBuffer( x -55, y + 7, DISP_PRIO_IME3, 55250, 2 ); + ť = StockDispBuffer( x -20, y + 7, DISP_PRIO_IME3, 55251, 2 ); + ťر = StockDispBuffer( x+40, y + 7, DISP_PRIO_IME3, 55252, 2 ); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if(!ƺ.ȷʾ){ + if(ť == HitDispNo){ + if(ƺ.ǰҳ){ + ƺ.ǰҳ--; + ƺչʾ(); + } + } + if(ť == HitDispNo){ + if(ƺ.ǰҳ!=19 && ƺ.ͼ[(ƺ.ǰҳ+1)*5]){ + ƺ.ǰҳ++; + ƺչʾ(); + } + } + if(ťر == HitDispNo){ + DeathAction(pct); + ƺչʾ(); + ƺ.ʾ=FALSE; + ƺ.ȷʾ=FALSE; + return TRUE; + } + } + } + + int i=0; + int ƺͼ; + for(;i<5;i++){ + ƺͼ = ƺ.ǰҳ*5+i; + if(ƺ.ͼ[ƺͼ]){ + if(!ƺ.ƺŽṹ[i]){ + if(ƺ.ͼ[ƺͼ] < 100000){ + ƺ.ƺŽṹ[i] = 0; + StockDispBuffer(0x16D+20,0x35+i*0x20,109,ƺ.ͼ[ƺͼ],0); + }else{ + ƺ.ƺŽṹ[i] = MakeAnimDisp(0x16D+20,0x35+i*0x20,ƺ.ͼ[ƺͼ],0); + } + }else if(ƺ.ǰƺŽṹ==0) StockDispBuffer(0x16D,0x35+i*0x20,109,ƺ.ͼ[ƺͼ],0); + char ƺ[128]; + sprintf_s(ƺ,"%03d",ƺͼ+1); + + StockFontBufferExt(0x130,0x2D+i*0x20,1,FONT_PAL_GREEN,ƺ,0,16); + if(!ƺ.ȷʾ){ + if(MakeHitBox(0x124,0x26+i*0x20,0x1B8,0x44+i*0x20,0x6D)==1){ + StockFontBuffer(0x123,0xD1,2,0,ƺ.[ƺͼ],0); + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + ƺ.ȷͼ=ƺ.ƺ[ ƺͼ]; + ƺ.ȷʾ=TRUE; + } + } + } + }else break; + } + if(ƺ.ȷʾ){ + StockFontBuffer(0x123,0xD1,2,0,ƺ.[ƺ.ȷͼ],0); + StockFontBuffer(0x130,0x118,2,0,"ȷʹøóƺ",0); + StockDispBuffer(0x16D,0x130,0x6C,55253,1);//ȷڵͼ + ťID = StockDispBuffer(0x194,0x148,109,55252,2);//ر + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(ťID == HitDispNo){ + ƺ.ȷʾ=FALSE; + ƺ.ȷͼ=0; + } + } + ťID = StockDispBuffer(0x148,0x148,109,55254,2);//ȷ + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(ťID == HitDispNo){ + int checksum=0; + char buf[1024*4]; + memset(buf,0,1024*4); + checksum += util_mkint(buf, ƺ.ȷͼ); + util_mkint(buf, checksum); + util_SendMesg(sockfd, LSSPROTO_CHARTITLE_SEND, buf); + ƺ.ȷʾ=FALSE; + ƺ.ȷͼ=0; + } + } + } + return FALSE; +} + +void ڽ(ACTION* ID)//ʾ +{ + ƺ.ʾ=FALSE; + ƺչʾ(); + if(ƺ.ǰƺŽṹ) DeathAction(ƺ.ǰƺŽṹ); + ƺ.ǰƺŽṹ=0; + DeathAction(ID); +} + +void ƺݸ(char *) +{ + char [126],ͼ[1024],ͼ[1024],ݽ[4000],ʱ[126]; + memset(,0,126); + memset(ͼ,0,1024); + memset(ͼ,0,1024); + memset(ݽ,0,4000); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",1,,126); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",1,ʱ,126); + int ֵ = atoi(ʱ); + if(ֵ) ƺ.ǰƺͼ=ֵ; + getStringFromIndexWithDelim_body((char *) ,(char *)"|",2,ʱ,126); + int = atoi(ʱ); + if(!=0){ + memset(&ƺ.ͼ,0,sizeof(int)*100); + memset(&ƺ.ƺ,0,sizeof(int)*100); + memset(&ƺ.,0,32*100); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",2,ͼ,1024); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",3,ݽ,4000); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",4,ͼ,1024); + int i=0; + for(i;i<;i++){ + getStringFromIndexWithDelim_body((char *)ͼ,(char *)"|",i+1,ʱ,126); + ƺ.ͼ[i]=atoi(ʱ); + getStringFromIndexWithDelim_body((char *)ͼ,(char *)"|",i+1,ʱ,126); + ƺ.ƺ[i]=atoi(ʱ); + getStringFromIndexWithDelim_body((char *)ݽ,(char *)"|",i+1,ʱ,126); + sprintf_s(ƺ.[i],32,"%s",ʱ); + } + } +} + +void ʼƺŽṹ() +{ + memset(&ƺ,0,sizeof(ƺݽṹ)); +} +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/CharTitle.h b/石器时代8.5客户端最新源代码/石器源码/CharTitle.h new file mode 100644 index 0000000..ebdc319 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/CharTitle.h @@ -0,0 +1,4 @@ +void ƺųʼ(); +void ƺݸ(char *); + + diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/AutoDump.obj b/石器时代8.5客户端最新源代码/石器源码/Release/AutoDump.obj new file mode 100644 index 0000000..b2e10ad Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/AutoDump.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/CL.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/CL.read.1.tlog new file mode 100644 index 0000000..1c9695c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/CL.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/CL.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/CL.write.1.tlog new file mode 100644 index 0000000..35e8abc Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/CL.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/CharSignDay.obj b/石器时代8.5客户端最新源代码/石器源码/Release/CharSignDay.obj new file mode 100644 index 0000000..3402552 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/CharSignDay.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/CharTitle.obj b/石器时代8.5客户端最新源代码/石器源码/Release/CharTitle.obj new file mode 100644 index 0000000..32e4b40 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/CharTitle.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ItemsMall.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ItemsMall.obj new file mode 100644 index 0000000..79eaa28 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ItemsMall.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/Ping.obj b/石器时代8.5客户端最新源代码/石器源码/Release/Ping.obj new file mode 100644 index 0000000..cd98c65 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/Ping.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/PtternSeparationBin.obj b/石器时代8.5客户端最新源代码/石器源码/Release/PtternSeparationBin.obj new file mode 100644 index 0000000..5664389 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/PtternSeparationBin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/SDLDraw.obj b/石器时代8.5客户端最新源代码/石器源码/Release/SDLDraw.obj new file mode 100644 index 0000000..9463520 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/SDLDraw.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/Script1.res b/石器时代8.5客户端最新源代码/石器源码/Release/Script1.res new file mode 100644 index 0000000..191c6b3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/Script1.res differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ServerList.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ServerList.obj new file mode 100644 index 0000000..c0bf146 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ServerList.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/StoneageNg.obj b/石器时代8.5客户端最新源代码/石器源码/Release/StoneageNg.obj new file mode 100644 index 0000000..d147df5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/StoneageNg.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/Turntable.obj b/石器时代8.5客户端最新源代码/石器源码/Release/Turntable.obj new file mode 100644 index 0000000..6b5e712 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/Turntable.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/action.obj b/石器时代8.5客户端最新源代码/石器源码/Release/action.obj new file mode 100644 index 0000000..dece7eb Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/action.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ai_setting.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ai_setting.obj new file mode 100644 index 0000000..514fd68 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ai_setting.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/autil.obj b/石器时代8.5客户端最新源代码/石器源码/Release/autil.obj new file mode 100644 index 0000000..b75bc36 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/autil.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/battlemap.obj b/石器时代8.5客户端最新源代码/石器源码/Release/battlemap.obj new file mode 100644 index 0000000..75f34d3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/battlemap.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/battlemenu.obj b/石器时代8.5客户端最新源代码/石器源码/Release/battlemenu.obj new file mode 100644 index 0000000..daac114 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/battlemenu.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/battleproc.obj b/石器时代8.5客户端最新源代码/石器源码/Release/battleproc.obj new file mode 100644 index 0000000..a99c288 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/battleproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/character.obj b/石器时代8.5客户端最新源代码/石器源码/Release/character.obj new file mode 100644 index 0000000..6990166 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/character.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/chat.obj b/石器时代8.5客户端最新源代码/石器源码/Release/chat.obj new file mode 100644 index 0000000..22447a7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/chat.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/cl.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/cl.command.1.tlog new file mode 100644 index 0000000..c41ca33 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/cl.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/common.obj b/石器时代8.5客户端最新源代码/石器源码/Release/common.obj new file mode 100644 index 0000000..e61a770 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/common.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/creatwth.obj b/石器时代8.5客户端最新源代码/石器源码/Release/creatwth.obj new file mode 100644 index 0000000..e4d726e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/creatwth.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/data.obj b/石器时代8.5客户端最新源代码/石器源码/Release/data.obj new file mode 100644 index 0000000..124e509 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/data.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/descrypt.obj b/石器时代8.5客户端最新源代码/石器源码/Release/descrypt.obj new file mode 100644 index 0000000..436c525 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/descrypt.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/detours.obj b/石器时代8.5客户端最新源代码/石器源码/Release/detours.obj new file mode 100644 index 0000000..5cb7364 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/detours.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/directdraw.obj b/石器时代8.5客户端最新源代码/石器源码/Release/directdraw.obj new file mode 100644 index 0000000..be7ab8b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/directdraw.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/disasm.obj b/石器时代8.5客户端最新源代码/石器源码/Release/disasm.obj new file mode 100644 index 0000000..6d79d68 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/disasm.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/field.obj b/石器时代8.5客户端最新源代码/石器源码/Release/field.obj new file mode 100644 index 0000000..0ac7f84 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/field.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/font.obj b/石器时代8.5客户端最新源代码/石器源码/Release/font.obj new file mode 100644 index 0000000..05f0f24 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/font.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/gamemain.obj b/石器时代8.5客户端最新源代码/石器源码/Release/gamemain.obj new file mode 100644 index 0000000..8ff4ce5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/gamemain.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/gemini.obj b/石器时代8.5客户端最新源代码/石器源码/Release/gemini.obj new file mode 100644 index 0000000..d63f2d0 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/gemini.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/getip.obj b/石器时代8.5客户端最新源代码/石器源码/Release/getip.obj new file mode 100644 index 0000000..dab26c9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/getip.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/handletime.obj b/石器时代8.5客户端最新源代码/石器源码/Release/handletime.obj new file mode 100644 index 0000000..ac2c2a6 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/handletime.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/help.obj b/石器时代8.5客户端最新源代码/石器源码/Release/help.obj new file mode 100644 index 0000000..87d4e9d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/help.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/image.obj b/石器时代8.5客户端最新源代码/石器源码/Release/image.obj new file mode 100644 index 0000000..96ff473 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/image.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ime.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ime.obj new file mode 100644 index 0000000..0e48d1b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ime.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/init.obj b/石器时代8.5客户端最新源代码/石器源码/Release/init.obj new file mode 100644 index 0000000..299281f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/init.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.read.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Release/link-cvtres.write.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/link.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/link.command.1.tlog new file mode 100644 index 0000000..bb3fe21 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/link.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/link.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/link.read.1.tlog new file mode 100644 index 0000000..51804e3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/link.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/link.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/link.write.1.tlog new file mode 100644 index 0000000..282fc64 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/link.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/loadrealbin.obj b/石器时代8.5客户端最新源代码/石器源码/Release/loadrealbin.obj new file mode 100644 index 0000000..3559205 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/loadrealbin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/loadsprbin.obj b/石器时代8.5客户端最新源代码/石器源码/Release/loadsprbin.obj new file mode 100644 index 0000000..e3bbee2 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/loadsprbin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/login.obj b/石器时代8.5客户端最新源代码/石器源码/Release/login.obj new file mode 100644 index 0000000..e011fb1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/login.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/lssproto.obj b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto.obj new file mode 100644 index 0000000..ae211bd Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_cli.obj b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_cli.obj new file mode 100644 index 0000000..f0a39bb Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_cli.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_util.obj b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_util.obj new file mode 100644 index 0000000..77a0bf1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/lssproto_util.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/magicitem.obj b/石器时代8.5客户端最新源代码/石器源码/Release/magicitem.obj new file mode 100644 index 0000000..09c60d0 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/magicitem.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/main.obj b/石器时代8.5客户端最新源代码/石器源码/Release/main.obj new file mode 100644 index 0000000..d6a4c41 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/main.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/map.obj b/石器时代8.5客户端最新源代码/石器源码/Release/map.obj new file mode 100644 index 0000000..8ea113d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/map.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/math2.obj b/石器时代8.5客户端最新源代码/石器源码/Release/math2.obj new file mode 100644 index 0000000..b7896ee Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/math2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/md5_encrypt.obj b/石器时代8.5客户端最新源代码/石器源码/Release/md5_encrypt.obj new file mode 100644 index 0000000..9992c63 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/md5_encrypt.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/menu.obj b/石器时代8.5客户端最新源代码/石器源码/Release/menu.obj new file mode 100644 index 0000000..2f3f52d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/menu.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/menu2.obj b/石器时代8.5客户端最新源代码/石器源码/Release/menu2.obj new file mode 100644 index 0000000..7068f07 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/menu2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/message.obj b/石器时代8.5客户端最新源代码/石器源码/Release/message.obj new file mode 100644 index 0000000..eca3f09 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/message.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/modules.obj b/石器时代8.5客户端最新源代码/石器源码/Release/modules.obj new file mode 100644 index 0000000..e6b260e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/modules.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/mouse.obj b/石器时代8.5客户端最新源代码/石器源码/Release/mouse.obj new file mode 100644 index 0000000..e0dfe7c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/mouse.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/mt.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/mt.command.1.tlog new file mode 100644 index 0000000..f08930f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/mt.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/mt.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/mt.read.1.tlog new file mode 100644 index 0000000..a1c4bd0 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/mt.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/mt.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/mt.write.1.tlog new file mode 100644 index 0000000..80b6087 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/mt.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/netmain.obj b/石器时代8.5客户端最新源代码/石器源码/Release/netmain.obj new file mode 100644 index 0000000..6f61806 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/netmain.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/netproc.obj b/石器时代8.5客户端最新源代码/石器源码/Release/netproc.obj new file mode 100644 index 0000000..e93be70 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/netproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/oft.obj b/石器时代8.5客户端最新源代码/石器源码/Release/oft.obj new file mode 100644 index 0000000..342fa22 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/oft.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ohta.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ohta.obj new file mode 100644 index 0000000..bcf0c0f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ohta.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/ohta_proc.obj b/石器时代8.5客户端最新源代码/石器源码/Release/ohta_proc.obj new file mode 100644 index 0000000..4ecf694 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/ohta_proc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/onlinegm.obj b/石器时代8.5客户端最新源代码/石器源码/Release/onlinegm.obj new file mode 100644 index 0000000..72e9d0f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/onlinegm.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/pat_dat.obj b/石器时代8.5客户端最新源代码/石器源码/Release/pat_dat.obj new file mode 100644 index 0000000..3a9f4dd Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/pat_dat.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/pattern.obj b/石器时代8.5客户端最新源代码/石器源码/Release/pattern.obj new file mode 100644 index 0000000..3eb109a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/pattern.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/pc.obj b/石器时代8.5客户端最新源代码/石器源码/Release/pc.obj new file mode 100644 index 0000000..06cfca6 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/pc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/phonemsg.obj b/石器时代8.5客户端最新源代码/石器源码/Release/phonemsg.obj new file mode 100644 index 0000000..10c8efc Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/phonemsg.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/process.obj b/石器时代8.5客户端最新源代码/石器源码/Release/process.obj new file mode 100644 index 0000000..42d34ab Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/process.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/produce.obj b/石器时代8.5客户端最新源代码/石器源码/Release/produce.obj new file mode 100644 index 0000000..3c6d7be Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/produce.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/protocol.obj b/石器时代8.5客户端最新源代码/石器源码/Release/protocol.obj new file mode 100644 index 0000000..3b76345 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/protocol.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/radar.obj b/石器时代8.5客户端最新源代码/石器源码/Release/radar.obj new file mode 100644 index 0000000..1784a77 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/radar.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/rc.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/rc.command.1.tlog new file mode 100644 index 0000000..b3ac1bb Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/rc.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/rc.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/rc.read.1.tlog new file mode 100644 index 0000000..46767b3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/rc.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/rc.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/rc.write.1.tlog new file mode 100644 index 0000000..c3e1506 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/rc.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/readip.obj b/石器时代8.5客户端最新源代码/石器源码/Release/readip.obj new file mode 100644 index 0000000..1e3a45c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/readip.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/redMemoy.obj b/石器时代8.5客户端最新源代码/石器源码/Release/redMemoy.obj new file mode 100644 index 0000000..5869a03 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/redMemoy.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/reproc.obj b/石器时代8.5客户端最新源代码/石器源码/Release/reproc.obj new file mode 100644 index 0000000..5cf071c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/reproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/sa.exe.intermediate.manifest b/石器时代8.5客户端最新源代码/石器源码/Release/sa.exe.intermediate.manifest new file mode 100644 index 0000000..1c06b61 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Release/sa.exe.intermediate.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/sa.obj b/石器时代8.5客户端最新源代码/石器源码/Release/sa.obj new file mode 100644 index 0000000..b441c07 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/sa.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/savedata.obj b/石器时代8.5客户端最新源代码/石器源码/Release/savedata.obj new file mode 100644 index 0000000..4d7c345 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/savedata.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/shop.obj b/石器时代8.5客户端最新源代码/石器源码/Release/shop.obj new file mode 100644 index 0000000..5265e60 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/shop.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/skyisland.obj b/石器时代8.5客户端最新源代码/石器源码/Release/skyisland.obj new file mode 100644 index 0000000..aeefb3b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/skyisland.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/sprdisp.obj b/石器时代8.5客户端最新源代码/石器源码/Release/sprdisp.obj new file mode 100644 index 0000000..b2183fc Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/sprdisp.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/sprmgr.obj b/石器时代8.5客户端最新源代码/石器源码/Release/sprmgr.obj new file mode 100644 index 0000000..fe85b48 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/sprmgr.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/sys2.obj b/石器时代8.5客户端最新源代码/石器源码/Release/sys2.obj new file mode 100644 index 0000000..0e0369e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/sys2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/t_music.obj b/石器时代8.5客户端最新源代码/石器源码/Release/t_music.obj new file mode 100644 index 0000000..84e621a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/t_music.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/talkwindow.obj b/石器时代8.5客户端最新源代码/石器源码/Release/talkwindow.obj new file mode 100644 index 0000000..fd8a05f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/talkwindow.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/tea.obj b/石器时代8.5客户端最新源代码/石器源码/Release/tea.obj new file mode 100644 index 0000000..9cc15c8 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/tea.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/tekecess.obj b/石器时代8.5客户端最新源代码/石器源码/Release/tekecess.obj new file mode 100644 index 0000000..0ba03f7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/tekecess.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/test.obj b/石器时代8.5客户端最新源代码/石器源码/Release/test.obj new file mode 100644 index 0000000..8b072d4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/test.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/testview.obj b/石器时代8.5客户端最新源代码/石器源码/Release/testview.obj new file mode 100644 index 0000000..2b5909f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/testview.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/tool.obj b/石器时代8.5客户端最新源代码/石器源码/Release/tool.obj new file mode 100644 index 0000000..2cc7bdd Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/tool.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/trade.obj b/石器时代8.5客户端最新源代码/石器源码/Release/trade.obj new file mode 100644 index 0000000..488c89f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/trade.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/unpack.obj b/石器时代8.5客户端最新源代码/石器源码/Release/unpack.obj new file mode 100644 index 0000000..da16cee Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/unpack.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/vc100.pdb b/石器时代8.5客户端最新源代码/石器源码/Release/vc100.pdb new file mode 100644 index 0000000..046c9e9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/vc100.pdb differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/win.obj b/石器时代8.5客户端最新源代码/石器源码/Release/win.obj new file mode 100644 index 0000000..f50714f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/win.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/winlua.obj b/石器时代8.5客户端最新源代码/石器源码/Release/winlua.obj new file mode 100644 index 0000000..aff6a80 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/winlua.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/work.obj b/石器时代8.5客户端最新源代码/石器源码/Release/work.obj new file mode 100644 index 0000000..0305bbc Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/work.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.lastbuildstate b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.lastbuildstate new file mode 100644 index 0000000..b6a1f05 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.lastbuildstate @@ -0,0 +1,2 @@ +#v4.0:v100:false +Release|Win32|J:\Dev\石器时代1\轻石器\CLIENT\| diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.log b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.log new file mode 100644 index 0000000..ac3f388 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.log @@ -0,0 +1,354 @@ +生成启动时间为 2016/9/3 星期六 下午 9:47:06。 + 1>项目“J:\Dev\石器时代1\轻石器\CLIENT\石器源码\石器源码.vcxproj”在节点 2 上(build 个目标)。 + 项目文件包含 ToolsVersion="12.0"。此工具集可能未知或缺失(您可以通过安装相应版本的 MSBuild 来解决该问题),或者该生成因策略原因已被强制更改为特殊 ToolsVersion。将此项目视作具有 ToolsVersion="4.0"。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkId=291333。 + 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(299,5): warning MSB8004: Output 目录未以斜杠结尾。此生成实例将添加斜杠,因为必须有这个斜杠才能正确计算 Output 目录。 + 1>InitializeBuildStatus: + 正在对“Release\石器源码.unsuccessfulbuild”执行 Touch 任务。 + ClCompile: + D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /Ilua /Zi /nologo /W0 /WX- /Od /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D DI_2 /D _SA_VERSION_SPECIAL /D _SA_VERSION_182 /D _MBCS /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt AutoDump.cpp CharTitle.cpp mylua\ServerList.cpp mylua\data.cpp mylua\lssproto.cpp mylua\sa.cpp mylua\win.cpp mylua\winlua.cpp newproto\protocol.cpp oft\oft.cpp oft\pat_dat.cpp oft\sys2.cpp oft\tekecess.cpp oft\work.cpp ohta\ohta.cpp ohta\ohta_proc.cpp other\PtternSeparationBin.cpp other\StoneageNg.cpp other\getip.cpp redMemoy.cpp system\CharSignDay.cpp system\Turntable.cpp system\action.cpp system\ai_setting.cpp system\battlemap.cpp system\battlemenu.cpp system\battleproc.cpp system\character.cpp system\chat.cpp system\directdraw.cpp system\field.cpp system\font.cpp system\gamemain.cpp system\gemini.cpp system\handletime.cpp system\help.cpp system\ime.cpp system\init.cpp system\loadrealbin.cpp system\loadsprbin.cpp system\login.cpp system\lssproto_cli.cpp system\lssproto_util.cpp system\magicitem.cpp system\main.cpp system\map.cpp system\math2.cpp system\menu.cpp system\menu2.cpp system\mouse.cpp system\netmain.cpp system\netproc.cpp system\onlinegm.cpp system\pattern.cpp system\pc.cpp system\phonemsg.cpp system\process.cpp system\produce.cpp system\radar.cpp system\savedata.cpp system\shop.cpp system\skyisland.cpp system\sprdisp.cpp system\sprmgr.cpp system\t_music.cpp system\talkwindow.cpp system\test.cpp system\testview.cpp system\tool.cpp system\unpack.cpp wgs\common.cpp wgs\descrypt.cpp wgs\message.cpp wgs\reproc.cpp + AutoDump.cpp + CharTitle.cpp + 1>CharTitle.cpp(213): error C2371: “称号数据结构”: 重定义;不同的基类型 + CharTitle.cpp(22) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(215): error C2086: “称号数据结构 称号”: 重定义 + CharTitle.cpp(24) : 参见“称号”的声明 + 1>CharTitle.cpp(221): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(222): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(222): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(223): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(229): error C2084: 函数“void 打开称号窗口初始化(void)”已有主体 + CharTitle.cpp(26) : 参见“打开称号窗口初始化”的前一个定义 + 1>CharTitle.cpp(243): error C2084: 函数“void 称号展示(void)”已有主体 + CharTitle.cpp(56) : 参见“称号展示”的前一个定义 + 1>CharTitle.cpp(245): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(246): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(247): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(248): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(249): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(251): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(251): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(253): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(253): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(254): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(255): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(256): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(257): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(259): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(259): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(265): error C2084: 函数“BOOL 人物称号处理(ACTION *)”已有主体 + CharTitle.cpp(72) : 参见“人物称号处理”的前一个定义 + 1>CharTitle.cpp(285): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(304): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(305): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(306): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(307): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(308): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(310): error C2039: “称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(310): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(312): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(312): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(360): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(360): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(361): error C2039: “当前称号结构”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(366): error C2084: 函数“void 人物称号数据更新(char *)”已有主体 + CharTitle.cpp(155) : 参见“人物称号数据更新”的前一个定义 + 1>CharTitle.cpp(375): error C2039: “当前称号图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(379): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(388): error C2039: “图档”: 不是“称号数据结构”的成员 + CharTitle.cpp(12) : 参见“称号数据结构”的声明 + 1>CharTitle.cpp(398): error C2084: 函数“void 初始化称号结构(void)”已有主体 + CharTitle.cpp(191) : 参见“初始化称号结构”的前一个定义 + ServerList.cpp + data.cpp + lssproto.cpp + sa.cpp + win.cpp + winlua.cpp + protocol.cpp + oft.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\oft\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + pat_dat.cpp + sys2.cpp + tekecess.cpp + work.cpp + ohta.cpp + ohta_proc.cpp + PtternSeparationBin.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\other\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + StoneageNg.cpp + getip.cpp + redMemoy.cpp + 正在编译... + CharSignDay.cpp + 1>c1xx : fatal error C1083: 无法打开源文件:“system\CharSignDay.cpp”: No such file or directory + Turntable.cpp + action.cpp + ai_setting.cpp + battlemap.cpp + battlemenu.cpp + battleproc.cpp + character.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + chat.cpp + directdraw.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + field.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + 1>system\field.cpp(4059): error C2181: 没有匹配 if 的非法 else + font.cpp + gamemain.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + gemini.cpp + handletime.cpp + help.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + ime.cpp + init.cpp + loadrealbin.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + loadsprbin.cpp + 正在编译... + login.cpp + lssproto_cli.cpp + lssproto_util.cpp + magicitem.cpp + main.cpp + 1>system\main.cpp(252): error C2059: 语法错误:“)” + 1>system\main.cpp(268): error C2059: 语法错误:“)” + map.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + math2.cpp + menu.cpp + 1>system\menu.cpp(8930): error C2011: “InitItem::_tagInitXY”:“struct”类型重定义 + system\menu.cpp(8917) : 参见“InitItem::_tagInitXY”的声明 + 1>system\menu.cpp(8973): error C2027: 使用了未定义类型“InitItem::_tagInitXY” + system\menu.cpp(8917) : 参见“InitItem::_tagInitXY”的声明 + 1>system\menu.cpp(8973): error C2228: “.x”的左边必须有类/结构/联合 + 1>system\menu.cpp(8974): error C2027: 使用了未定义类型“InitItem::_tagInitXY” + system\menu.cpp(8917) : 参见“InitItem::_tagInitXY”的声明 + 1>system\menu.cpp(8974): error C2228: “.y”的左边必须有类/结构/联合 + menu2.cpp + mouse.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + netmain.cpp + netproc.cpp + onlinegm.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + pattern.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + pc.cpp + phonemsg.cpp + process.cpp + produce.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + radar.cpp + savedata.cpp + 正在编译... + shop.cpp + 1>system\shop.cpp(538): error C2084: 函数“void StockFontBufferSplit(int,int,char,int,char *,int,int)”已有主体 + system\shop.cpp(33) : 参见“StockFontBufferSplit”的前一个定义 + 1>system\shop.cpp(564): error C2371: “商品数据结构”: 重定义;不同的基类型 + system\shop.cpp(59) : 参见“商品数据结构”的声明 + 1>system\shop.cpp(567): error C2086: “商城文件_ 商城文件[5]”: 重定义 + system\shop.cpp(62) : 参见“商城文件”的声明 + 1>system\shop.cpp(572): error C2371: “滚动条结构”: 重定义;不同的基类型 + system\shop.cpp(67) : 参见“滚动条结构”的声明 + 1>system\shop.cpp(606): error C2371: “商城结构”: 重定义;不同的基类型 + system\shop.cpp(87) : 参见“商城结构”的声明 + 1>system\shop.cpp(610): error C2086: “商品数据结构 商品数据[200]”: 重定义 + system\shop.cpp(91) : 参见“商品数据”的声明 + 1>system\shop.cpp(611): error C2086: “商城结构 商城数据”: 重定义 + system\shop.cpp(92) : 参见“商城数据”的声明 + 1>system\shop.cpp(613): error C2374: “商城道具坐标”: 重定义;多次初始化 + system\shop.cpp(100) : 参见“商城道具坐标”的声明 + 1>system\shop.cpp(624): error C2374: “道具内容坐标”: 重定义;多次初始化 + system\shop.cpp(111) : 参见“道具内容坐标”的声明 + 1>system\shop.cpp(633): error C2374: “窗口显示”: 重定义;多次初始化 + system\shop.cpp(120) : 参见“窗口显示”的声明 + 1>system\shop.cpp(642): error C2084: 函数“void 在线商城数据初始化(void)”已有主体 + system\shop.cpp(128) : 参见“在线商城数据初始化”的前一个定义 + 1>system\shop.cpp(648): error C2084: 函数“int 字符串切割(char *[],char *,const char *)”已有主体 + system\shop.cpp(134) : 参见“字符串切割”的前一个定义 + 1>system\shop.cpp(664): error C2084: 函数“void 在线商城窗口初始化(char *)”已有主体 + system\shop.cpp(150) : 参见“在线商城窗口初始化”的前一个定义 + 1>system\shop.cpp(670): error C3861: “在线商城数据初始化”: 找不到标识符 + 1>system\shop.cpp(682): error C2440: “=”: 无法从“int (__cdecl *)(char *[],char *,const char *)”转换为“short” + 1>system\shop.cpp(682): error C2440: “=”: 无法从“int (__cdecl *)(char *[],char *,const char *)”转换为“short” + 没有使该转换得以执行的上下文 + 1>system\shop.cpp(682): error C3861: “字符串切割”: 找不到标识符 + 1>system\shop.cpp(685): error C3861: “字符串切割”: 找不到标识符 + 1>system\shop.cpp(711): error C2084: 函数“ACTION *创建商城窗口(void)”已有主体 + system\shop.cpp(197) : 参见“创建商城窗口”的前一个定义 + 1>system\shop.cpp(722): error C2084: 函数“ACTION *商城数据显示(void)”已有主体 + system\shop.cpp(206) : 参见“商城数据显示”的前一个定义 + 1>system\shop.cpp(768): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(768): error C2228: “.商品总数”的左边必须有类/结构/联合 + 1>system\shop.cpp(784): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(784): error C2228: “.当前页数”的左边必须有类/结构/联合 + 1>system\shop.cpp(785): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(785): error C2228: “.总页数”的左边必须有类/结构/联合 + 1>system\shop.cpp(786): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(786): error C2228: “.商品类型个数”的左边必须有类/结构/联合 + 1>system\shop.cpp(787): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(787): error C2228: “.商品总数”的左边必须有类/结构/联合 + 1>system\shop.cpp(788): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(788): error C2228: “.总价格”的左边必须有类/结构/联合 + 1>system\shop.cpp(789): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(789): error C2228: “.总页数”的左边必须有类/结构/联合 + 1>system\shop.cpp(790): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(790): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(861): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(861): error C2228: “.总价格”的左边必须有类/结构/联合 + 1>system\shop.cpp(865): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(865): error C2228: “.商品总数”的左边必须有类/结构/联合 + 1>system\shop.cpp(869): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(869): error C2228: “.商品类型个数”的左边必须有类/结构/联合 + 1>system\shop.cpp(870): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(870): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(871): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(871): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(871): error C2228: “.使用”的左边必须有类/结构/联合 + 1>system\shop.cpp(872): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(872): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(872): error C2228: “.数量”的左边必须有类/结构/联合 + 1>system\shop.cpp(873): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(873): error C2228: “.当前页数”的左边必须有类/结构/联合 + 1>system\shop.cpp(874): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(874): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(874): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(875): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(875): error C2228: “.商品类型个数”的左边必须有类/结构/联合 + 1>system\shop.cpp(876): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(876): error C2228: “.商品总数”的左边必须有类/结构/联合 + 1>system\shop.cpp(877): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(877): error C2228: “.总价格”的左边必须有类/结构/联合 + 1>system\shop.cpp(877): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(877): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(877): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(877): error C2227: “->商品价格”的左边必须指向类/结构/联合/泛型类型 + 1>system\shop.cpp(882): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(882): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(882): error C2228: “.使用”的左边必须有类/结构/联合 + 1>system\shop.cpp(884): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(884): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(884): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(886): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(886): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(886): error C2228: “.数量”的左边必须有类/结构/联合 + 1>system\shop.cpp(887): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(887): error C2228: “.商品总数”的左边必须有类/结构/联合 + 1>system\shop.cpp(888): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(888): error C2228: “.总价格”的左边必须有类/结构/联合 + 1>system\shop.cpp(888): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(888): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(888): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(888): error C2227: “->商品价格”的左边必须指向类/结构/联合/泛型类型 + 1>system\shop.cpp(894): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(894): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(894): error C2228: “.使用”的左边必须有类/结构/联合 + 1>system\shop.cpp(897): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(897): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(897): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(898): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(898): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(898): error C2228: “.数量”的左边必须有类/结构/联合 + 1>system\shop.cpp(901): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(901): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(901): error C2228: “.使用”的左边必须有类/结构/联合 + 1>system\shop.cpp(902): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(902): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(902): error C2228: “.商品”的左边必须有类/结构/联合 + 1>system\shop.cpp(903): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(903): error C2228: “.购物栏”的左边必须有类/结构/联合 + 1>system\shop.cpp(903): error C2228: “.数量”的左边必须有类/结构/联合 + 1>system\shop.cpp(904): error C2039: “购物车”: 不是“商城结构”的成员 + system\shop.cpp(69) : 参见“商城结构”的声明 + 1>system\shop.cpp(904): fatal error C1003: 错误计数超过 100;正在停止编译 + skyisland.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + sprdisp.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + sprmgr.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + t_music.cpp + talkwindow.cpp + 1>j:\dev\石器时代1\轻石器\client\石器源码\system\../systeminc/loadrealbin.h(152): error C2078: 初始值设定项太多 + test.cpp + testview.cpp + tool.cpp + unpack.cpp + common.cpp + descrypt.cpp + message.cpp + reproc.cpp + 1>已完成生成项目“J:\Dev\石器时代1\轻石器\CLIENT\石器源码\石器源码.vcxproj”(build 个目标)的操作 - 失败。 + +生成失败。 + +已用时间 00:00:29.74 diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.unsuccessfulbuild b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.vcxprojResolveAssemblyReference.cache b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.vcxprojResolveAssemblyReference.cache new file mode 100644 index 0000000..bde9b77 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.vcxprojResolveAssemblyReference.cache differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/Release/石器源码.write.1.tlog new file mode 100644 index 0000000..e69de29 diff --git a/石器时代8.5客户端最新源代码/石器源码/Script1.aps b/石器时代8.5客户端最新源代码/石器源码/Script1.aps new file mode 100644 index 0000000..aeb206b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/Script1.aps differ diff --git a/石器时代8.5客户端最新源代码/石器源码/Script1.rc b/石器时代8.5客户端最新源代码/石器源码/Script1.rc new file mode 100644 index 0000000..d042cec --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/Script1.rc @@ -0,0 +1,127 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// (壬й) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) +LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED +#pragma code_page(936) + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +SA_ICON ICON "icon2.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Cursor +// + +SA_MOUSE CURSOR "pointer.cur" +SA_MOUSE1 CURSOR ".\\123.cur" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080404b0" + BEGIN + VALUE "CompanyName", "ʯʱ" + VALUE "FileDescription", "Stoneage" + VALUE "FileVersion", "1, 0, 0, 1" + VALUE "InternalName", "ʯʱ" + VALUE "LegalCopyright", "Copyright c 2010" + VALUE "OriginalFilename", "Sa.exe" + VALUE "ProductName", "ʯʱ" + VALUE "ProductVersion", "1, 0, 0, 1" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x804, 1200 + END +END + +#endif // (壬й) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// (壬̨) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHT) +LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL +#pragma code_page(950) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // (壬̨) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/AutoDump.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/AutoDump.obj new file mode 100644 index 0000000..27d3c9d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/AutoDump.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.read.1.tlog new file mode 100644 index 0000000..3785eb3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.write.1.tlog new file mode 100644 index 0000000..d58d1b3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CL.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharSignDay.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharSignDay.obj new file mode 100644 index 0000000..aaf287e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharSignDay.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharTitle.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharTitle.obj new file mode 100644 index 0000000..05258b8 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/CharTitle.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ItemsMall.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ItemsMall.obj new file mode 100644 index 0000000..944207d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ItemsMall.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Ping.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Ping.obj new file mode 100644 index 0000000..5757249 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Ping.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/PtternSeparationBin.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/PtternSeparationBin.obj new file mode 100644 index 0000000..40dd230 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/PtternSeparationBin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/SDLDraw.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/SDLDraw.obj new file mode 100644 index 0000000..4236722 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/SDLDraw.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Script1.res b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Script1.res new file mode 100644 index 0000000..191c6b3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Script1.res differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ServerList.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ServerList.obj new file mode 100644 index 0000000..1272d8c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ServerList.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/StoneageNg.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/StoneageNg.obj new file mode 100644 index 0000000..1a2f171 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/StoneageNg.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Turntable.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Turntable.obj new file mode 100644 index 0000000..b85cef9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/Turntable.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/action.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/action.obj new file mode 100644 index 0000000..ec67d82 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/action.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ai_setting.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ai_setting.obj new file mode 100644 index 0000000..109f7e6 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ai_setting.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/autil.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/autil.obj new file mode 100644 index 0000000..bcb75d2 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/autil.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemap.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemap.obj new file mode 100644 index 0000000..4698b7a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemap.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemenu.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemenu.obj new file mode 100644 index 0000000..f300b6f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battlemenu.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battleproc.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battleproc.obj new file mode 100644 index 0000000..c227229 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/battleproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/character.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/character.obj new file mode 100644 index 0000000..5d35a65 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/character.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/chat.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/chat.obj new file mode 100644 index 0000000..6e559d4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/chat.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/cl.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/cl.command.1.tlog new file mode 100644 index 0000000..e6192c3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/cl.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/common.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/common.obj new file mode 100644 index 0000000..e875659 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/common.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/creatwth.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/creatwth.obj new file mode 100644 index 0000000..05f42cf Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/creatwth.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/data.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/data.obj new file mode 100644 index 0000000..1c21e40 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/data.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/descrypt.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/descrypt.obj new file mode 100644 index 0000000..f393407 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/descrypt.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/detours.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/detours.obj new file mode 100644 index 0000000..7cb7bdf Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/detours.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/directdraw.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/directdraw.obj new file mode 100644 index 0000000..abab3cd Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/directdraw.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/disasm.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/disasm.obj new file mode 100644 index 0000000..f00b7d9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/disasm.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/field.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/field.obj new file mode 100644 index 0000000..e6b50ed Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/field.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/font.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/font.obj new file mode 100644 index 0000000..3609be4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/font.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gamemain.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gamemain.obj new file mode 100644 index 0000000..3a8755a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gamemain.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gemini.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gemini.obj new file mode 100644 index 0000000..c3dee82 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/gemini.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/getip.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/getip.obj new file mode 100644 index 0000000..fd253d1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/getip.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/handletime.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/handletime.obj new file mode 100644 index 0000000..39b4968 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/handletime.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/help.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/help.obj new file mode 100644 index 0000000..e3d0133 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/help.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/image.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/image.obj new file mode 100644 index 0000000..7fca334 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/image.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ime.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ime.obj new file mode 100644 index 0000000..3e2e216 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ime.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/init.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/init.obj new file mode 100644 index 0000000..00dfd7f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/init.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.read.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link-cvtres.write.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.command.1.tlog new file mode 100644 index 0000000..4dc3208 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.1.tlog new file mode 100644 index 0000000..93028b1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.2.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.2.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.read.2.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.write.1.tlog new file mode 100644 index 0000000..de4841b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/link.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadrealbin.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadrealbin.obj new file mode 100644 index 0000000..25f268b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadrealbin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadsprbin.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadsprbin.obj new file mode 100644 index 0000000..8027fe9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/loadsprbin.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/login.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/login.obj new file mode 100644 index 0000000..da82f19 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/login.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto.obj new file mode 100644 index 0000000..32f8cb4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_cli.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_cli.obj new file mode 100644 index 0000000..26ca781 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_cli.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_util.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_util.obj new file mode 100644 index 0000000..718f1cb Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/lssproto_util.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/magicitem.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/magicitem.obj new file mode 100644 index 0000000..d6ad91f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/magicitem.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/main.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/main.obj new file mode 100644 index 0000000..6cc6f73 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/main.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/map.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/map.obj new file mode 100644 index 0000000..7e195d4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/map.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/math2.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/math2.obj new file mode 100644 index 0000000..43a8bfa Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/math2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/md5_encrypt.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/md5_encrypt.obj new file mode 100644 index 0000000..25fcd6c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/md5_encrypt.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu.obj new file mode 100644 index 0000000..672a29a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu2.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu2.obj new file mode 100644 index 0000000..788ce22 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/menu2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/message.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/message.obj new file mode 100644 index 0000000..62be416 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/message.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/modules.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/modules.obj new file mode 100644 index 0000000..66affe9 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/modules.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mouse.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mouse.obj new file mode 100644 index 0000000..2f0dc0b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mouse.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.command.1.tlog new file mode 100644 index 0000000..31cec02 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.read.1.tlog new file mode 100644 index 0000000..a34fcc7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.write.1.tlog new file mode 100644 index 0000000..a34fcc7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/mt.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netmain.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netmain.obj new file mode 100644 index 0000000..40fb9db Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netmain.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netproc.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netproc.obj new file mode 100644 index 0000000..d3115f4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/netproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/oft.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/oft.obj new file mode 100644 index 0000000..f076178 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/oft.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta.obj new file mode 100644 index 0000000..48296aa Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta_proc.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta_proc.obj new file mode 100644 index 0000000..6eaa12b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/ohta_proc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/onlinegm.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/onlinegm.obj new file mode 100644 index 0000000..c1ee214 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/onlinegm.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pat_dat.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pat_dat.obj new file mode 100644 index 0000000..c59ed37 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pat_dat.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pattern.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pattern.obj new file mode 100644 index 0000000..e8f3e52 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pattern.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pc.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pc.obj new file mode 100644 index 0000000..b4d0546 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/pc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/phonemsg.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/phonemsg.obj new file mode 100644 index 0000000..c691908 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/phonemsg.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/process.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/process.obj new file mode 100644 index 0000000..930d72e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/process.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/produce.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/produce.obj new file mode 100644 index 0000000..351c884 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/produce.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/protocol.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/protocol.obj new file mode 100644 index 0000000..948e1e5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/protocol.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/radar.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/radar.obj new file mode 100644 index 0000000..d9e3de3 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/radar.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.command.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.command.1.tlog new file mode 100644 index 0000000..871aedc Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.command.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.read.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.read.1.tlog new file mode 100644 index 0000000..8a87188 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.read.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.write.1.tlog new file mode 100644 index 0000000..b1136e7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/rc.write.1.tlog differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/readip.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/readip.obj new file mode 100644 index 0000000..792161e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/readip.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/redMemoy.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/redMemoy.obj new file mode 100644 index 0000000..6e4df36 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/redMemoy.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/reproc.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/reproc.obj new file mode 100644 index 0000000..7c92115 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/reproc.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa.obj new file mode 100644 index 0000000..70b2a2d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest new file mode 100644 index 0000000..e693382 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest.res b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest.res new file mode 100644 index 0000000..9c8df0e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.embed.manifest.res differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.intermediate.manifest b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.intermediate.manifest new file mode 100644 index 0000000..1c06b61 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25.exe.intermediate.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25_manifest.rc b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25_manifest.rc new file mode 100644 index 0000000..253503b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sa25_manifest.rc differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/savedata.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/savedata.obj new file mode 100644 index 0000000..2f4af9e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/savedata.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/shop.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/shop.obj new file mode 100644 index 0000000..b6531ba Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/shop.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/skyisland.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/skyisland.obj new file mode 100644 index 0000000..e71b4ca Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/skyisland.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprdisp.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprdisp.obj new file mode 100644 index 0000000..8cc6cd4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprdisp.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprmgr.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprmgr.obj new file mode 100644 index 0000000..9b6c7a5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sprmgr.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sys2.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sys2.obj new file mode 100644 index 0000000..2191d49 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/sys2.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/t_music.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/t_music.obj new file mode 100644 index 0000000..4b1ba96 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/t_music.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/talkwindow.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/talkwindow.obj new file mode 100644 index 0000000..d971002 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/talkwindow.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tea.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tea.obj new file mode 100644 index 0000000..a86ef0a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tea.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tekecess.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tekecess.obj new file mode 100644 index 0000000..c96d993 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tekecess.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/test.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/test.obj new file mode 100644 index 0000000..0196d2b Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/test.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/testview.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/testview.obj new file mode 100644 index 0000000..8eb05ae Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/testview.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tool.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tool.obj new file mode 100644 index 0000000..f8cdd8f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/tool.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/trade.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/trade.obj new file mode 100644 index 0000000..266b9d1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/trade.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/unpack.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/unpack.obj new file mode 100644 index 0000000..6aae629 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/unpack.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.idb b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.idb new file mode 100644 index 0000000..9b23018 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.idb differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.pdb b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.pdb new file mode 100644 index 0000000..a7edc0d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/vc100.pdb differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/win.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/win.obj new file mode 100644 index 0000000..31d0e1e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/win.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/winlua.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/winlua.obj new file mode 100644 index 0000000..ef97f36 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/winlua.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/work.obj b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/work.obj new file mode 100644 index 0000000..339f2ec Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/work.obj differ diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.lastbuildstate b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.lastbuildstate new file mode 100644 index 0000000..d2d453a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.lastbuildstate @@ -0,0 +1,2 @@ +#v4.0:v100:false +VER25_DEBUG|Win32|J:\Dev\石器时代1\轻石器\CLIENT\| diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.log b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.log new file mode 100644 index 0000000..380f973 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.log @@ -0,0 +1,24 @@ +生成启动时间为 2016/9/26 星期一 下午 5:38:39。 + 1>项目“J:\Dev\石器时代1\轻石器\CLIENT\石器源码\石器源码.vcxproj”在节点 2 上(build 个目标)。 + 项目文件包含 ToolsVersion="12.0"。此工具集可能未知或缺失(您可以通过安装相应版本的 MSBuild 来解决该问题),或者该生成因策略原因已被强制更改为特殊 ToolsVersion。将此项目视作具有 ToolsVersion="4.0"。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkId=291333。 + 1>InitializeBuildStatus: + 正在创建“VER25_DEBUG\石器源码.unsuccessfulbuild”,因为已指定“AlwaysCreate”。 + ClCompile: + 所有输出均为最新。 + ResourceCompile: + 所有输出均为最新。 + ManifestResourceCompile: + 所有输出均为最新。 + 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(F:\石器时代\7-sa\sa25.exe) 与 Linker 的 OutputFile 属性值(F:\7-sa\sa25.exe)不匹配。这可能导致项目生成不正确。若要更正此问题,请确保 $(OutDir)、$(TargetName) 和 $(TargetExt) 属性值与 %(Link.OutputFile) 中指定的值匹配。 + Link: + 所有输出均为最新。 + Manifest: + 所有输出均为最新。 + FinalizeBuildStatus: + 正在删除文件“VER25_DEBUG\石器源码.unsuccessfulbuild”。 + 正在对“VER25_DEBUG\石器源码.lastbuildstate”执行 Touch 任务。 + 1>已完成生成项目“J:\Dev\石器时代1\轻石器\CLIENT\石器源码\石器源码.vcxproj”(build 个目标)的操作。 + +生成成功。 + +已用时间 00:00:00.08 diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.write.1.tlog b/石器时代8.5客户端最新源代码/石器源码/VER25_DEBUG/石器源码.write.1.tlog new file mode 100644 index 0000000..e69de29 diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/sa25.Build.CppClean.log b/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/sa25.Build.CppClean.log new file mode 100644 index 0000000..f1d9c86 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/sa25.Build.CppClean.log @@ -0,0 +1,106 @@ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\ACTION.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\AI_SETTING.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\AUTIL.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\BATTLEMAP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\BATTLEMENU.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\BATTLEPROC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\CHARACTER.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\CHARSIGNDAY.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\CHARTITLE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\CHAT.OBJ +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\cl.command.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\CL.read.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\CL.write.1.tlog +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\COMMON.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\CREATWTH.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\DATA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\DESCRYPT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\DETOURS.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\DIRECTDRAW.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\DISASM.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\FIELD.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\FONT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\GAMEMAIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\GEMINI.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\GETIP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\HANDLETIME.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\HELP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\IMAGE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\IME.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\INIT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\ITEMSMALL.OBJ +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\link.command.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\link.read.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\link.write.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\link-cvtres.read.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\link-cvtres.write.1.tlog +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LOADREALBIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LOADSPRBIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LOGIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LSSPROTO.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LSSPROTO_CLI.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\LSSPROTO_UTIL.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MAGICITEM.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MAIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MAP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MATH2.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MD5_ENCRYPT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MENU.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MENU2.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MESSAGE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MODULES.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\MOUSE.OBJ +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\mt.command.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\mt.read.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\mt.write.1.tlog +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\NETMAIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\NETPROC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\OFT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\OHTA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\OHTA_PROC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\ONLINEGM.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PAT_DAT.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PATTERN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PHONEMSG.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PING.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PROCESS.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PRODUCE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PROTOCOL.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\PTTERNSEPARATIONBIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\RADAR.OBJ +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\rc.command.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\rc.read.1.tlog +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\rc.write.1.tlog +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\READIP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\REDMEMOY.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\REPROC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SA25.EXE.INTERMEDIATE.MANIFEST +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SAVEDATA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SCRIPT1.RES +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SDLDRAW.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SERVERLIST.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SHOP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SKYISLAND.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SPRDISP.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SPRMGR.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\SYS2.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\T_MUSIC.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TALKWINDOW.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TEA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TEKECESS.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TEST.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TESTVIEW.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TOOL.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TRADE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\TURNTABLE.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\UNPACK.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\VC100.PDB +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\WIN.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\WINLUA.OBJ +C:\USERS\ADMINISTRATOR\DESKTOP\WGCODE\客户端代码\石器源码\VER25_RELEASE\WORK.OBJ +C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\VER25_RELEASE\石器源码.write.1.tlog +F:\7-SA\SA25.EXE +F:\7-SA\SA25.MAP +F:\7-SA\SA25.PDB diff --git a/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/石器源码.log b/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/石器源码.log new file mode 100644 index 0000000..a2978ff --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/VER25_RELEASE/石器源码.log @@ -0,0 +1,10 @@ +生成启动时间为 2016/12/5 星期一 下午 8:40:55。 + 1>项目“C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\石器源码.vcxproj”在节点 2 上(clean 个目标)。 + 项目文件包含 ToolsVersion="12.0"。此工具集可能未知或缺失(您可以通过安装相应版本的 MSBuild 来解决该问题),或者该生成因策略原因已被强制更改为特殊 ToolsVersion。将此项目视作具有 ToolsVersion="4.0"。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkId=291333。 + 1>_PrepareForClean: + 正在删除文件“VER25_RELEASE\石器源码.lastbuildstate”。 + 1>已完成生成项目“C:\Users\Administrator\Desktop\WGCODE\客户端代码\石器源码\石器源码.vcxproj”(clean 个目标)的操作。 + +生成成功。 + +已用时间 00:00:00.05 diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/curl.h b/石器时代8.5客户端最新源代码/石器源码/curl/curl.h new file mode 100644 index 0000000..eab2f6e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/curl.h @@ -0,0 +1,2376 @@ +#ifndef __CURL_CURL_H +#define __CURL_CURL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2015, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * If you have libcurl problems, all docs and details are found here: + * http://curl.haxx.se/libcurl/ + * + * curl-library mailing list subscription and unsubscription web interface: + * http://cool.haxx.se/mailman/listinfo/curl-library/ + */ + +#include "curlver.h" /* libcurl version defines */ +#include "curlbuild.h" /* libcurl build definitions */ +#include "curlrules.h" /* libcurl rules enforcement */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && \ + !defined(WIN32) && !defined(__SYMBIAN32__) +#define WIN32 +#endif + +#include +#include + +#if defined(__FreeBSD__) && (__FreeBSD__ >= 2) +/* Needed for __FreeBSD_version symbol definition */ +#include +#endif + +/* The include stuff here below is mainly for time_t! */ +#include +#include + +#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || defined(__LWIP_OPT_H__)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include +#include +#endif +#endif + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on systems that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ + defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ + (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) +#include +#endif + +#if !defined(WIN32) && !defined(_WIN32_WCE) +#include +#endif + +#if !defined(WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) +#include +#endif + +#ifdef __BEOS__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void CURL; + +/* + * libcurl external API function linkage decorations. + */ + +#ifdef CURL_STATICLIB +# define CURL_EXTERN +#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__) +# if defined(BUILDING_LIBCURL) +# define CURL_EXTERN __declspec(dllexport) +# else +# define CURL_EXTERN __declspec(dllimport) +# endif +#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS) +# define CURL_EXTERN CURL_EXTERN_SYMBOL +#else +# define CURL_EXTERN +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#if defined(WIN32) && !defined(__LWIP_OPT_H__) +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + +struct curl_httppost { + struct curl_httppost *next; /* next entry in the list */ + char *name; /* pointer to allocated name */ + long namelength; /* length of name length */ + char *contents; /* pointer to allocated data contents */ + long contentslength; /* length of contents field */ + char *buffer; /* pointer to allocated buffer contents */ + long bufferlength; /* length of buffer field */ + char *contenttype; /* Content-Type */ + struct curl_slist* contentheader; /* list of extra headers for this form */ + struct curl_httppost *more; /* if one field name has more than one + file, this link should link to following + files */ + long flags; /* as defined below */ +#define HTTPPOST_FILENAME (1<<0) /* specified content is a file name */ +#define HTTPPOST_READFILE (1<<1) /* specified content is a file name */ +#define HTTPPOST_PTRNAME (1<<2) /* name is only stored pointer + do not free in formfree */ +#define HTTPPOST_PTRCONTENTS (1<<3) /* contents is only stored pointer + do not free in formfree */ +#define HTTPPOST_BUFFER (1<<4) /* upload file from buffer */ +#define HTTPPOST_PTRBUFFER (1<<5) /* upload file from pointer contents */ +#define HTTPPOST_CALLBACK (1<<6) /* upload file contents by using the + regular read callback to get the data + and pass the given pointer as custom + pointer */ + + char *showfilename; /* The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /* custom pointer used for + HTTPPOST_CALLBACK posts */ +}; + +/* This is the CURLOPT_PROGRESSFUNCTION callback proto. It is now considered + deprecated but was the only choice up until 7.31.0 */ +typedef int (*curl_progress_callback)(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + +/* This is the CURLOPT_XFERINFOFUNCTION callback proto. It was introduced in + 7.32.0, it avoids floating point and provides more detailed information. */ +typedef int (*curl_xferinfo_callback)(void *clientp, + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow); + +#ifndef CURL_MAX_WRITE_SIZE + /* Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +#define CURL_MAX_WRITE_SIZE 16384 +#endif + +#ifndef CURL_MAX_HTTP_HEADER +/* The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +#define CURL_MAX_HTTP_HEADER (100*1024) +#endif + +/* This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +#define CURL_WRITEFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_write_callback)(char *buffer, + size_t size, + size_t nitems, + void *outstream); + + + +/* enumeration of file types */ +typedef enum { + CURLFILETYPE_FILE = 0, + CURLFILETYPE_DIRECTORY, + CURLFILETYPE_SYMLINK, + CURLFILETYPE_DEVICE_BLOCK, + CURLFILETYPE_DEVICE_CHAR, + CURLFILETYPE_NAMEDPIPE, + CURLFILETYPE_SOCKET, + CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ + + CURLFILETYPE_UNKNOWN /* should never occur */ +} curlfiletype; + +#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) +#define CURLFINFOFLAG_KNOWN_TIME (1<<2) +#define CURLFINFOFLAG_KNOWN_PERM (1<<3) +#define CURLFINFOFLAG_KNOWN_UID (1<<4) +#define CURLFINFOFLAG_KNOWN_GID (1<<5) +#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) + +/* Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ +struct curl_fileinfo { + char *filename; + curlfiletype filetype; + time_t time; + unsigned int perm; + int uid; + int gid; + curl_off_t size; + long int hardlinks; + + struct { + /* If some of these fields is not NULL, it is a pointer to b_data. */ + char *time; + char *perm; + char *user; + char *group; + char *target; /* pointer to the target filename of a symlink */ + } strings; + + unsigned int flags; + + /* used internally */ + char * b_data; + size_t b_size; + size_t b_used; +}; + +/* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +#define CURL_CHUNK_BGN_FUNC_OK 0 +#define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ +#define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ + +/* if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, + void *ptr, + int remains); + +/* return codes for CURLOPT_CHUNK_END_FUNCTION */ +#define CURL_CHUNK_END_FUNC_OK 0 +#define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ + +/* If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +typedef long (*curl_chunk_end_callback)(void *ptr); + +/* return codes for FNMATCHFUNCTION */ +#define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ +#define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ +#define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ + +/* callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +typedef int (*curl_fnmatch_callback)(void *ptr, + const char *pattern, + const char *string); + +/* These are the return codes for the seek callbacks */ +#define CURL_SEEKFUNC_OK 0 +#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ +#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so + libcurl might try other means instead */ +typedef int (*curl_seek_callback)(void *instream, + curl_off_t offset, + int origin); /* 'whence' */ + +/* This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ +#define CURL_READFUNC_ABORT 0x10000000 +/* This is a return code for the read callback that, when returned, will + signal libcurl to pause sending data on the current transfer. */ +#define CURL_READFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_read_callback)(char *buffer, + size_t size, + size_t nitems, + void *instream); + +typedef enum { + CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ + CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */ + CURLSOCKTYPE_LAST /* never use */ +} curlsocktype; + +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + +typedef int (*curl_sockopt_callback)(void *clientp, + curl_socket_t curlfd, + curlsocktype purpose); + +struct curl_sockaddr { + int family; + int socktype; + int protocol; + unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + struct sockaddr addr; +}; + +typedef curl_socket_t +(*curl_opensocket_callback)(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address); + +typedef int +(*curl_closesocket_callback)(void *clientp, curl_socket_t item); + +typedef enum { + CURLIOE_OK, /* I/O operation successful */ + CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ + CURLIOE_FAILRESTART, /* failed to restart the read */ + CURLIOE_LAST /* never use */ +} curlioerr; + +typedef enum { + CURLIOCMD_NOP, /* no operation */ + CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ + CURLIOCMD_LAST /* never use */ +} curliocmd; + +typedef curlioerr (*curl_ioctl_callback)(CURL *handle, + int cmd, + void *clientp); + +/* + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +typedef void *(*curl_malloc_callback)(size_t size); +typedef void (*curl_free_callback)(void *ptr); +typedef void *(*curl_realloc_callback)(void *ptr, size_t size); +typedef char *(*curl_strdup_callback)(const char *str); +typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); + +/* the kind of data that is passed to information_callback*/ +typedef enum { + CURLINFO_TEXT = 0, + CURLINFO_HEADER_IN, /* 1 */ + CURLINFO_HEADER_OUT, /* 2 */ + CURLINFO_DATA_IN, /* 3 */ + CURLINFO_DATA_OUT, /* 4 */ + CURLINFO_SSL_DATA_IN, /* 5 */ + CURLINFO_SSL_DATA_OUT, /* 6 */ + CURLINFO_END +} curl_infotype; + +typedef int (*curl_debug_callback) + (CURL *handle, /* the handle/transfer this concerns */ + curl_infotype type, /* what kind of data */ + char *data, /* points to the data */ + size_t size, /* size of the data pointed to */ + void *userptr); /* whatever the user please */ + +/* All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ + +typedef enum { + CURLE_OK = 0, + CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ + CURLE_FAILED_INIT, /* 2 */ + CURLE_URL_MALFORMAT, /* 3 */ + CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ + CURLE_COULDNT_RESOLVE_HOST, /* 6 */ + CURLE_COULDNT_CONNECT, /* 7 */ + CURLE_FTP_WEIRD_SERVER_REPLY, /* 8 */ + CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for + 7.15.4, reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ + CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server + [was obsoleted in August 2007 for 7.17.0, + reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ + CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ + CURLE_FTP_CANT_GET_HOST, /* 15 */ + CURLE_HTTP2, /* 16 - A problem in the http2 framing layer. + [was obsoleted in August 2007 for 7.17.0, + reused in July 2014 for 7.38.0] */ + CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ + CURLE_PARTIAL_FILE, /* 18 */ + CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ + CURLE_OBSOLETE20, /* 20 - NOT USED */ + CURLE_QUOTE_ERROR, /* 21 - quote command failure */ + CURLE_HTTP_RETURNED_ERROR, /* 22 */ + CURLE_WRITE_ERROR, /* 23 */ + CURLE_OBSOLETE24, /* 24 - NOT USED */ + CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ + CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ + CURLE_OUT_OF_MEMORY, /* 27 */ + /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ + CURLE_OBSOLETE29, /* 29 - NOT USED */ + CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ + CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ + CURLE_OBSOLETE32, /* 32 - NOT USED */ + CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ + CURLE_HTTP_POST_ERROR, /* 34 */ + CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ + CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ + CURLE_FILE_COULDNT_READ_FILE, /* 37 */ + CURLE_LDAP_CANNOT_BIND, /* 38 */ + CURLE_LDAP_SEARCH_FAILED, /* 39 */ + CURLE_OBSOLETE40, /* 40 - NOT USED */ + CURLE_FUNCTION_NOT_FOUND, /* 41 */ + CURLE_ABORTED_BY_CALLBACK, /* 42 */ + CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ + CURLE_OBSOLETE44, /* 44 - NOT USED */ + CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ + CURLE_OBSOLETE46, /* 46 - NOT USED */ + CURLE_TOO_MANY_REDIRECTS , /* 47 - catch endless re-direct loops */ + CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ + CURLE_TELNET_OPTION_SYNTAX , /* 49 - Malformed telnet option */ + CURLE_OBSOLETE50, /* 50 - NOT USED */ + CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint + wasn't verified fine */ + CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ + CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ + CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as + default */ + CURLE_SEND_ERROR, /* 55 - failed sending network data */ + CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ + CURLE_OBSOLETE57, /* 57 - NOT IN USE */ + CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ + CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ + CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */ + CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ + CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ + CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ + CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ + CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind + that failed */ + CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ + CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not + accepted and we failed to login */ + CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ + CURLE_TFTP_PERM, /* 69 - permission problem on server */ + CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ + CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ + CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ + CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ + CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ + CURLE_CONV_FAILED, /* 75 - conversion failed */ + CURLE_CONV_REQD, /* 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing + or wrong format */ + CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ + CURLE_SSH, /* 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + + CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL + connection */ + CURLE_AGAIN, /* 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or + wrong format (Added in 7.19.0) */ + CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in + 7.19.0) */ + CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ + CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ + CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */ + CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ + CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ + CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the + session will be queued */ + CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not + match */ + CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */ + CURL_LAST /* never use! */ +} CURLcode; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Previously obsolete error code re-used in 7.38.0 */ +#define CURLE_OBSOLETE16 CURLE_HTTP2 + +/* Previously obsolete error codes re-used in 7.24.0 */ +#define CURLE_OBSOLETE10 CURLE_FTP_ACCEPT_FAILED +#define CURLE_OBSOLETE12 CURLE_FTP_ACCEPT_TIMEOUT + +/* compatibility with older names */ +#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING + +/* The following were added in 7.21.5, April 2011 */ +#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION + +/* The following were added in 7.17.1 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.17.0 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ +#define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 +#define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 +#define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 +#define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 +#define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 +#define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 +#define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 +#define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 +#define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 +#define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 +#define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 +#define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN + +#define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED +#define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE +#define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR +#define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL +#define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS +#define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR +#define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED + +/* The following were added earlier */ + +#define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT + +#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR +#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED +#define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED + +#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE +#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME + +/* This was the error code 50 in 7.7.3 and a few earlier versions, this + is no longer used by libcurl but is instead #defined here only to not + make programs break */ +#define CURLE_ALREADY_COMPLETE 99999 + +/* Provide defines for really old option names */ +#define CURLOPT_FILE CURLOPT_WRITEDATA /* name changed in 7.9.7 */ +#define CURLOPT_INFILE CURLOPT_READDATA /* name changed in 7.9.7 */ +#define CURLOPT_WRITEHEADER CURLOPT_HEADERDATA + +/* Since long deprecated options with no code in the lib that does anything + with them. */ +#define CURLOPT_WRITEINFO CURLOPT_OBSOLETE40 +#define CURLOPT_CLOSEPOLICY CURLOPT_OBSOLETE72 + +#endif /*!CURL_NO_OLDIES*/ + +/* This prototype applies to all conversion callbacks */ +typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); + +typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ + void *ssl_ctx, /* actually an + OpenSSL SSL_CTX */ + void *userptr); + +typedef enum { + CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use + CONNECT HTTP/1.1 */ + CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT + HTTP/1.0 */ + CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already + in 7.10 */ + CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ + CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ + CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} curl_proxytype; /* this enum was added in 7.10 */ + +/* + * Bitmasks for CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH options: + * + * CURLAUTH_NONE - No HTTP authentication + * CURLAUTH_BASIC - HTTP Basic authentication (default) + * CURLAUTH_DIGEST - HTTP Digest authentication + * CURLAUTH_NEGOTIATE - HTTP Negotiate (SPNEGO) authentication + * CURLAUTH_GSSNEGOTIATE - Alias for CURLAUTH_NEGOTIATE (deprecated) + * CURLAUTH_NTLM - HTTP NTLM authentication + * CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour + * CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper + * CURLAUTH_ONLY - Use together with a single other type to force no + * authentication or just that single type + * CURLAUTH_ANY - All fine types set + * CURLAUTH_ANYSAFE - All fine types except Basic + */ + +#define CURLAUTH_NONE ((unsigned long)0) +#define CURLAUTH_BASIC (((unsigned long)1)<<0) +#define CURLAUTH_DIGEST (((unsigned long)1)<<1) +#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) +/* Deprecated since the advent of CURLAUTH_NEGOTIATE */ +#define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE +#define CURLAUTH_NTLM (((unsigned long)1)<<3) +#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) +#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) +#define CURLAUTH_ONLY (((unsigned long)1)<<31) +#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ +#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ +#define CURLSSH_AUTH_HOST (1<<2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ +#define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY + +#define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */ +#define CURLGSSAPI_DELEGATION_POLICY_FLAG (1<<0) /* if permitted by policy */ +#define CURLGSSAPI_DELEGATION_FLAG (1<<1) /* delegate always */ + +#define CURL_ERROR_SIZE 256 + +enum curl_khtype { + CURLKHTYPE_UNKNOWN, + CURLKHTYPE_RSA1, + CURLKHTYPE_RSA, + CURLKHTYPE_DSS +}; + +struct curl_khkey { + const char *key; /* points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; + enum curl_khtype keytype; +}; + +/* this is the set of return values expected from the curl_sshkeycallback + callback */ +enum curl_khstat { + CURLKHSTAT_FINE_ADD_TO_FILE, + CURLKHSTAT_FINE, + CURLKHSTAT_REJECT, /* reject the connection, return an error */ + CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ +}; + +/* this is the set of status codes pass in to the callback */ +enum curl_khmatch { + CURLKHMATCH_OK, /* match */ + CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ + CURLKHMATCH_MISSING, /* no matching host/key found */ + CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ +}; + +typedef int + (*curl_sshkeycallback) (CURL *easy, /* easy handle */ + const struct curl_khkey *knownkey, /* known */ + const struct curl_khkey *foundkey, /* found */ + enum curl_khmatch, /* libcurl's view on the keys */ + void *clientp); /* custom pointer passed from app */ + +/* parameter for the CURLOPT_USE_SSL option */ +typedef enum { + CURLUSESSL_NONE, /* do not attempt to use SSL */ + CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ + CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ + CURLUSESSL_ALL, /* SSL for all communication or fail */ + CURLUSESSL_LAST /* not an option, never use */ +} curl_usessl; + +/* Definition of bits for the CURLOPT_SSL_OPTIONS argument: */ + +/* - ALLOW_BEAST tells libcurl to allow the BEAST SSL vulnerability in the + name of improving interoperability with older servers. Some SSL libraries + have introduced work-arounds for this flaw but those work-arounds sometimes + make the SSL communication fail. To regain functionality with those broken + servers, a user can this way allow the vulnerability back. */ +#define CURLSSLOPT_ALLOW_BEAST (1<<0) + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2009 */ + +#define CURLFTPSSL_NONE CURLUSESSL_NONE +#define CURLFTPSSL_TRY CURLUSESSL_TRY +#define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL +#define CURLFTPSSL_ALL CURLUSESSL_ALL +#define CURLFTPSSL_LAST CURLUSESSL_LAST +#define curl_ftpssl curl_usessl +#endif /*!CURL_NO_OLDIES*/ + +/* parameter for the CURLOPT_FTP_SSL_CCC option */ +typedef enum { + CURLFTPSSL_CCC_NONE, /* do not send CCC */ + CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ + CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ + CURLFTPSSL_CCC_LAST /* not an option, never use */ +} curl_ftpccc; + +/* parameter for the CURLOPT_FTPSSLAUTH option */ +typedef enum { + CURLFTPAUTH_DEFAULT, /* let libcurl decide */ + CURLFTPAUTH_SSL, /* use "AUTH SSL" */ + CURLFTPAUTH_TLS, /* use "AUTH TLS" */ + CURLFTPAUTH_LAST /* not an option, never use */ +} curl_ftpauth; + +/* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +typedef enum { + CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ + CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD + again if MKD succeeded, for SFTP this does + similar magic */ + CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD + again even if MKD failed! */ + CURLFTP_CREATE_DIR_LAST /* not an option, never use */ +} curl_ftpcreatedir; + +/* parameter for the CURLOPT_FTP_FILEMETHOD option */ +typedef enum { + CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ + CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ + CURLFTPMETHOD_NOCWD, /* no CWD at all */ + CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ + CURLFTPMETHOD_LAST /* not an option, never use */ +} curl_ftpmethod; + +/* bitmask defines for CURLOPT_HEADEROPT */ +#define CURLHEADER_UNIFIED 0 +#define CURLHEADER_SEPARATE (1<<0) + +/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +#define CURLPROTO_HTTP (1<<0) +#define CURLPROTO_HTTPS (1<<1) +#define CURLPROTO_FTP (1<<2) +#define CURLPROTO_FTPS (1<<3) +#define CURLPROTO_SCP (1<<4) +#define CURLPROTO_SFTP (1<<5) +#define CURLPROTO_TELNET (1<<6) +#define CURLPROTO_LDAP (1<<7) +#define CURLPROTO_LDAPS (1<<8) +#define CURLPROTO_DICT (1<<9) +#define CURLPROTO_FILE (1<<10) +#define CURLPROTO_TFTP (1<<11) +#define CURLPROTO_IMAP (1<<12) +#define CURLPROTO_IMAPS (1<<13) +#define CURLPROTO_POP3 (1<<14) +#define CURLPROTO_POP3S (1<<15) +#define CURLPROTO_SMTP (1<<16) +#define CURLPROTO_SMTPS (1<<17) +#define CURLPROTO_RTSP (1<<18) +#define CURLPROTO_RTMP (1<<19) +#define CURLPROTO_RTMPT (1<<20) +#define CURLPROTO_RTMPE (1<<21) +#define CURLPROTO_RTMPTE (1<<22) +#define CURLPROTO_RTMPS (1<<23) +#define CURLPROTO_RTMPTS (1<<24) +#define CURLPROTO_GOPHER (1<<25) +#define CURLPROTO_SMB (1<<26) +#define CURLPROTO_SMBS (1<<27) +#define CURLPROTO_ALL (~0) /* enable everything */ + +/* long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +#define CURLOPTTYPE_LONG 0 +#define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_FUNCTIONPOINT 20000 +#define CURLOPTTYPE_OFF_T 30000 + +/* name is uppercase CURLOPT_, + type is one of the defined CURLOPTTYPE_ + number is unique identifier */ +#ifdef CINIT +#undef CINIT +#endif + +#ifdef CURL_ISOCPP +#define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLOPT_/**/name = type + number +#endif + +/* + * This macro-mania below setups the CURLOPT_[what] enum, to be used with + * curl_easy_setopt(). The first argument in the CINIT() macro is the [what] + * word. + */ + +typedef enum { + /* This is the FILE * or void * the regular output should be written to. */ + CINIT(WRITEDATA, OBJECTPOINT, 1), + + /* The full URL to get/put */ + CINIT(URL, OBJECTPOINT, 2), + + /* Port number to connect to, if other than default. */ + CINIT(PORT, LONG, 3), + + /* Name of proxy to use. */ + CINIT(PROXY, OBJECTPOINT, 4), + + /* "user:password;options" to use when fetching. */ + CINIT(USERPWD, OBJECTPOINT, 5), + + /* "user:password" to use with proxy. */ + CINIT(PROXYUSERPWD, OBJECTPOINT, 6), + + /* Range to get, specified as an ASCII string. */ + CINIT(RANGE, OBJECTPOINT, 7), + + /* not used */ + + /* Specified file stream to upload from (use as input): */ + CINIT(READDATA, OBJECTPOINT, 9), + + /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. If this is not used, error messages go to stderr instead: */ + CINIT(ERRORBUFFER, OBJECTPOINT, 10), + + /* Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11), + + /* Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + CINIT(READFUNCTION, FUNCTIONPOINT, 12), + + /* Time-out the read operation after this amount of seconds */ + CINIT(TIMEOUT, LONG, 13), + + /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + CINIT(INFILESIZE, LONG, 14), + + /* POST static input fields. */ + CINIT(POSTFIELDS, OBJECTPOINT, 15), + + /* Set the referrer page (needed by some CGIs) */ + CINIT(REFERER, OBJECTPOINT, 16), + + /* Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + CINIT(FTPPORT, OBJECTPOINT, 17), + + /* Set the User-Agent string (examined by some CGIs) */ + CINIT(USERAGENT, OBJECTPOINT, 18), + + /* If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /* Set the "low speed limit" */ + CINIT(LOW_SPEED_LIMIT, LONG, 19), + + /* Set the "low speed time" */ + CINIT(LOW_SPEED_TIME, LONG, 20), + + /* Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + CINIT(RESUME_FROM, LONG, 21), + + /* Set cookie in request: */ + CINIT(COOKIE, OBJECTPOINT, 22), + + /* This points to a linked list of headers, struct curl_slist kind. This + list is also used for RTSP (in spite of its name) */ + CINIT(HTTPHEADER, OBJECTPOINT, 23), + + /* This points to a linked list of post entries, struct curl_httppost */ + CINIT(HTTPPOST, OBJECTPOINT, 24), + + /* name of the file keeping your private SSL-certificate */ + CINIT(SSLCERT, OBJECTPOINT, 25), + + /* password for the SSL or SSH private key */ + CINIT(KEYPASSWD, OBJECTPOINT, 26), + + /* send TYPE parameter? */ + CINIT(CRLF, LONG, 27), + + /* send linked-list of QUOTE commands */ + CINIT(QUOTE, OBJECTPOINT, 28), + + /* send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + CINIT(HEADERDATA, OBJECTPOINT, 29), + + /* point to a file to read the initial cookies from, also enables + "cookie awareness" */ + CINIT(COOKIEFILE, OBJECTPOINT, 31), + + /* What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + CINIT(SSLVERSION, LONG, 32), + + /* What kind of HTTP time condition to use, see defines */ + CINIT(TIMECONDITION, LONG, 33), + + /* Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + CINIT(TIMEVALUE, LONG, 34), + + /* 35 = OBSOLETE */ + + /* Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + CINIT(CUSTOMREQUEST, OBJECTPOINT, 36), + + /* HTTP request, for odd commands like DELETE, TRACE and others */ + CINIT(STDERR, OBJECTPOINT, 37), + + /* 38 is not used */ + + /* send linked-list of post-transfer QUOTE commands */ + CINIT(POSTQUOTE, OBJECTPOINT, 39), + + CINIT(OBSOLETE40, OBJECTPOINT, 40), /* OBSOLETE, do not use! */ + + CINIT(VERBOSE, LONG, 41), /* talk a lot */ + CINIT(HEADER, LONG, 42), /* throw the header out too */ + CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */ + CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */ + CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 400 */ + CINIT(UPLOAD, LONG, 46), /* this is an upload */ + CINIT(POST, LONG, 47), /* HTTP POST method */ + CINIT(DIRLISTONLY, LONG, 48), /* bare names when listing directories */ + + CINIT(APPEND, LONG, 50), /* Append instead of overwrite on upload! */ + + /* Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + CINIT(NETRC, LONG, 51), + + CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ + + CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */ + CINIT(PUT, LONG, 54), /* HTTP PUT */ + + /* 55 = OBSOLETE */ + + /* DEPRECATED + * Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56), + + /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION + callbacks */ + CINIT(PROGRESSDATA, OBJECTPOINT, 57), +#define CURLOPT_XFERINFODATA CURLOPT_PROGRESSDATA + + /* We want the referrer field set automatically when following locations */ + CINIT(AUTOREFERER, LONG, 58), + + /* Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + CINIT(PROXYPORT, LONG, 59), + + /* size of the POST input data, if strlen() is not good to use */ + CINIT(POSTFIELDSIZE, LONG, 60), + + /* tunnel non-http operations through a HTTP proxy */ + CINIT(HTTPPROXYTUNNEL, LONG, 61), + + /* Set the interface string to use as outgoing network interface */ + CINIT(INTERFACE, OBJECTPOINT, 62), + + /* Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + CINIT(KRBLEVEL, OBJECTPOINT, 63), + + /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ + CINIT(SSL_VERIFYPEER, LONG, 64), + + /* The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAINFO, OBJECTPOINT, 65), + + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /* Maximum number of http redirects to follow */ + CINIT(MAXREDIRS, LONG, 68), + + /* Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + CINIT(FILETIME, LONG, 69), + + /* This points to a linked list of telnet options */ + CINIT(TELNETOPTIONS, OBJECTPOINT, 70), + + /* Max amount of cached alive connections */ + CINIT(MAXCONNECTS, LONG, 71), + + CINIT(OBSOLETE72, LONG, 72), /* OBSOLETE, do not use! */ + + /* 73 = OBSOLETE */ + + /* Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + CINIT(FRESH_CONNECT, LONG, 74), + + /* Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + CINIT(FORBID_REUSE, LONG, 75), + + /* Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + CINIT(RANDOM_FILE, OBJECTPOINT, 76), + + /* Set to the Entropy Gathering Daemon socket pathname */ + CINIT(EGDSOCKET, OBJECTPOINT, 77), + + /* Time-out connect operations after this amount of seconds, if connects are + OK within this time, then fine... This only aborts the connect phase. */ + CINIT(CONNECTTIMEOUT, LONG, 78), + + /* Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79), + + /* Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + CINIT(HTTPGET, LONG, 80), + + /* Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + CINIT(SSL_VERIFYHOST, LONG, 81), + + /* Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + CINIT(COOKIEJAR, OBJECTPOINT, 82), + + /* Specify which SSL ciphers to use */ + CINIT(SSL_CIPHER_LIST, OBJECTPOINT, 83), + + /* Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + CINIT(HTTP_VERSION, LONG, 84), + + /* Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + CINIT(FTP_USE_EPSV, LONG, 85), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + CINIT(SSLCERTTYPE, OBJECTPOINT, 86), + + /* name of the file keeping your private SSL-key */ + CINIT(SSLKEY, OBJECTPOINT, 87), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + CINIT(SSLKEYTYPE, OBJECTPOINT, 88), + + /* crypto engine for the SSL-sub system */ + CINIT(SSLENGINE, OBJECTPOINT, 89), + + /* set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + CINIT(SSLENGINE_DEFAULT, LONG, 90), + + /* Non-zero value means to use the global dns cache */ + CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* DEPRECATED, do not use! */ + + /* DNS cache timeout */ + CINIT(DNS_CACHE_TIMEOUT, LONG, 92), + + /* send linked-list of pre-transfer QUOTE commands */ + CINIT(PREQUOTE, OBJECTPOINT, 93), + + /* set the debug function */ + CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94), + + /* set the data for the debug function */ + CINIT(DEBUGDATA, OBJECTPOINT, 95), + + /* mark this as start of a cookie session */ + CINIT(COOKIESESSION, LONG, 96), + + /* The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAPATH, OBJECTPOINT, 97), + + /* Instruct libcurl to use a smaller receive buffer */ + CINIT(BUFFERSIZE, LONG, 98), + + /* Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + CINIT(NOSIGNAL, LONG, 99), + + /* Provide a CURLShare for mutexing non-ts data */ + CINIT(SHARE, OBJECTPOINT, 100), + + /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5. */ + CINIT(PROXYTYPE, LONG, 101), + + /* Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. Before 7.21.6, this was known as + CURLOPT_ENCODING */ + CINIT(ACCEPT_ENCODING, OBJECTPOINT, 102), + + /* Set pointer to private data */ + CINIT(PRIVATE, OBJECTPOINT, 103), + + /* Set aliases for HTTP 200 in the HTTP Response header */ + CINIT(HTTP200ALIASES, OBJECTPOINT, 104), + + /* Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + CINIT(UNRESTRICTED_AUTH, LONG, 105), + + /* Specifically switch on or off the FTP engine's use of the EPRT command ( + it also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + CINIT(FTP_USE_EPRT, LONG, 106), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(HTTPAUTH, LONG, 107), + + /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx + in second argument. The function must be matching the + curl_ssl_ctx_callback proto. */ + CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108), + + /* Set the userdata for the ssl context callback function's third + argument */ + CINIT(SSL_CTX_DATA, OBJECTPOINT, 109), + + /* FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(PROXYAUTH, LONG, 111), + + /* FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112), +#define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT + + /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to resolve names to those IP versions only. This only has + affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ + CINIT(IPRESOLVE, LONG, 113), + + /* Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + CINIT(MAXFILESIZE, LONG, 114), + + /* See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + CINIT(INFILESIZE_LARGE, OFF_T, 115), + + /* Sets the continuation offset. There is also a LONG version of this; + * look above for RESUME_FROM. + */ + CINIT(RESUME_FROM_LARGE, OFF_T, 116), + + /* Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + CINIT(MAXFILESIZE_LARGE, OFF_T, 117), + + /* Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + CINIT(NETRC_FILE, OBJECTPOINT, 118), + + /* Enable SSL/TLS for FTP, pick one of: + CURLUSESSL_TRY - try using SSL, proceed anyway otherwise + CURLUSESSL_CONTROL - SSL for the control connection or fail + CURLUSESSL_ALL - SSL for all communication or fail + */ + CINIT(USE_SSL, LONG, 119), + + /* The _LARGE version of the standard POSTFIELDSIZE option */ + CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120), + + /* Enable/disable the TCP Nagle algorithm */ + CINIT(TCP_NODELAY, LONG, 121), + + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + CINIT(FTPSSLAUTH, LONG, 129), + + CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130), + CINIT(IOCTLDATA, OBJECTPOINT, 131), + + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /* zero terminated string for pass on to the FTP server when asked for + "account" info */ + CINIT(FTP_ACCOUNT, OBJECTPOINT, 134), + + /* feed cookies into cookie engine */ + CINIT(COOKIELIST, OBJECTPOINT, 135), + + /* ignore Content-Length */ + CINIT(IGNORE_CONTENT_LENGTH, LONG, 136), + + /* Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + CINIT(FTP_SKIP_PASV_IP, LONG, 137), + + /* Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + CINIT(FTP_FILEMETHOD, LONG, 138), + + /* Local port number to bind the socket to */ + CINIT(LOCALPORT, LONG, 139), + + /* Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + CINIT(LOCALPORTRANGE, LONG, 140), + + /* no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + CINIT(CONNECT_ONLY, LONG, 141), + + /* Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142), + + /* Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143), + + /* Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144), + + /* if the connection proceeds too quickly then need to slow it down */ + /* limit-rate: maximum number of bytes per second to send or receive */ + CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145), + CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146), + + /* Pointer to command string to send if USER/PASS fails. */ + CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147), + + /* callback function for setting socket options */ + CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), + CINIT(SOCKOPTDATA, OBJECTPOINT, 149), + + /* set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + CINIT(SSL_SESSIONID_CACHE, LONG, 150), + + /* allowed SSH authentication methods */ + CINIT(SSH_AUTH_TYPES, LONG, 151), + + /* Used by scp/sftp to do public/private key authentication */ + CINIT(SSH_PUBLIC_KEYFILE, OBJECTPOINT, 152), + CINIT(SSH_PRIVATE_KEYFILE, OBJECTPOINT, 153), + + /* Send CCC (Clear Command Channel) after authentication */ + CINIT(FTP_SSL_CCC, LONG, 154), + + /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + CINIT(TIMEOUT_MS, LONG, 155), + CINIT(CONNECTTIMEOUT_MS, LONG, 156), + + /* set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + CINIT(HTTP_TRANSFER_DECODING, LONG, 157), + CINIT(HTTP_CONTENT_DECODING, LONG, 158), + + /* Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + CINIT(NEW_FILE_PERMS, LONG, 159), + CINIT(NEW_DIRECTORY_PERMS, LONG, 160), + + /* Set the behaviour of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + CINIT(POSTREDIR, LONG, 161), + + /* used by scp/sftp to verify the host's public key */ + CINIT(SSH_HOST_PUBLIC_KEY_MD5, OBJECTPOINT, 162), + + /* Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163), + CINIT(OPENSOCKETDATA, OBJECTPOINT, 164), + + /* POST volatile input fields. */ + CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165), + + /* set transfer mode (;type=) when doing FTP via an HTTP proxy */ + CINIT(PROXY_TRANSFER_MODE, LONG, 166), + + /* Callback function for seeking in the input stream */ + CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167), + CINIT(SEEKDATA, OBJECTPOINT, 168), + + /* CRL file */ + CINIT(CRLFILE, OBJECTPOINT, 169), + + /* Issuer certificate */ + CINIT(ISSUERCERT, OBJECTPOINT, 170), + + /* (IPv6) Address scope */ + CINIT(ADDRESS_SCOPE, LONG, 171), + + /* Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. */ + CINIT(CERTINFO, LONG, 172), + + /* "name" and "pwd" to use when fetching. */ + CINIT(USERNAME, OBJECTPOINT, 173), + CINIT(PASSWORD, OBJECTPOINT, 174), + + /* "name" and "pwd" to use with Proxy when fetching. */ + CINIT(PROXYUSERNAME, OBJECTPOINT, 175), + CINIT(PROXYPASSWORD, OBJECTPOINT, 176), + + /* Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + CINIT(NOPROXY, OBJECTPOINT, 177), + + /* block size for TFTP transfers */ + CINIT(TFTP_BLKSIZE, LONG, 178), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_SERVICE, OBJECTPOINT, 179), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_NEC, LONG, 180), + + /* set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + CINIT(PROTOCOLS, LONG, 181), + + /* set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. Defaults + to all protocols except FILE and SCP. */ + CINIT(REDIR_PROTOCOLS, LONG, 182), + + /* set the SSH knownhost file name to use */ + CINIT(SSH_KNOWNHOSTS, OBJECTPOINT, 183), + + /* set the SSH host key callback, must point to a curl_sshkeycallback + function */ + CINIT(SSH_KEYFUNCTION, FUNCTIONPOINT, 184), + + /* set the SSH host key callback custom pointer */ + CINIT(SSH_KEYDATA, OBJECTPOINT, 185), + + /* set the SMTP mail originator */ + CINIT(MAIL_FROM, OBJECTPOINT, 186), + + /* set the SMTP mail receiver(s) */ + CINIT(MAIL_RCPT, OBJECTPOINT, 187), + + /* FTP: send PRET before PASV */ + CINIT(FTP_USE_PRET, LONG, 188), + + /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + CINIT(RTSP_REQUEST, LONG, 189), + + /* The RTSP session identifier */ + CINIT(RTSP_SESSION_ID, OBJECTPOINT, 190), + + /* The RTSP stream URI */ + CINIT(RTSP_STREAM_URI, OBJECTPOINT, 191), + + /* The Transport: header to use in RTSP requests */ + CINIT(RTSP_TRANSPORT, OBJECTPOINT, 192), + + /* Manually initialize the client RTSP CSeq for this handle */ + CINIT(RTSP_CLIENT_CSEQ, LONG, 193), + + /* Manually initialize the server RTSP CSeq for this handle */ + CINIT(RTSP_SERVER_CSEQ, LONG, 194), + + /* The stream to pass to INTERLEAVEFUNCTION. */ + CINIT(INTERLEAVEDATA, OBJECTPOINT, 195), + + /* Let the application define a custom write method for RTP data */ + CINIT(INTERLEAVEFUNCTION, FUNCTIONPOINT, 196), + + /* Turn on wildcard matching */ + CINIT(WILDCARDMATCH, LONG, 197), + + /* Directory matching callback called before downloading of an + individual file (chunk) started */ + CINIT(CHUNK_BGN_FUNCTION, FUNCTIONPOINT, 198), + + /* Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + CINIT(CHUNK_END_FUNCTION, FUNCTIONPOINT, 199), + + /* Change match (fnmatch-like) callback for wildcard matching */ + CINIT(FNMATCH_FUNCTION, FUNCTIONPOINT, 200), + + /* Let the application define custom chunk data pointer */ + CINIT(CHUNK_DATA, OBJECTPOINT, 201), + + /* FNMATCH_FUNCTION user pointer */ + CINIT(FNMATCH_DATA, OBJECTPOINT, 202), + + /* send linked-list of name:port:address sets */ + CINIT(RESOLVE, OBJECTPOINT, 203), + + /* Set a username for authenticated TLS */ + CINIT(TLSAUTH_USERNAME, OBJECTPOINT, 204), + + /* Set a password for authenticated TLS */ + CINIT(TLSAUTH_PASSWORD, OBJECTPOINT, 205), + + /* Set authentication type for authenticated TLS */ + CINIT(TLSAUTH_TYPE, OBJECTPOINT, 206), + + /* Set to 1 to enable the "TE:" header in HTTP requests to ask for + compressed transfer-encoded responses. Set to 0 to disable the use of TE: + in outgoing requests. The current default is 0, but it might change in a + future libcurl release. + + libcurl will ask for the compressed methods it knows of, and if that + isn't any, it will not ask for transfer-encoding at all even if this + option is set to 1. + + */ + CINIT(TRANSFER_ENCODING, LONG, 207), + + /* Callback function for closing socket (instead of close(2)). The callback + should have type curl_closesocket_callback */ + CINIT(CLOSESOCKETFUNCTION, FUNCTIONPOINT, 208), + CINIT(CLOSESOCKETDATA, OBJECTPOINT, 209), + + /* allow GSSAPI credential delegation */ + CINIT(GSSAPI_DELEGATION, LONG, 210), + + /* Set the name servers to use for DNS resolution */ + CINIT(DNS_SERVERS, OBJECTPOINT, 211), + + /* Time-out accept operations (currently for FTP only) after this amount + of miliseconds. */ + CINIT(ACCEPTTIMEOUT_MS, LONG, 212), + + /* Set TCP keepalive */ + CINIT(TCP_KEEPALIVE, LONG, 213), + + /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */ + CINIT(TCP_KEEPIDLE, LONG, 214), + CINIT(TCP_KEEPINTVL, LONG, 215), + + /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */ + CINIT(SSL_OPTIONS, LONG, 216), + + /* Set the SMTP auth originator */ + CINIT(MAIL_AUTH, OBJECTPOINT, 217), + + /* Enable/disable SASL initial response */ + CINIT(SASL_IR, LONG, 218), + + /* Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_xferinfo_callback + * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */ + CINIT(XFERINFOFUNCTION, FUNCTIONPOINT, 219), + + /* The XOAUTH2 bearer token */ + CINIT(XOAUTH2_BEARER, OBJECTPOINT, 220), + + /* Set the interface string to use as outgoing network + * interface for DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_INTERFACE, OBJECTPOINT, 221), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP4, OBJECTPOINT, 222), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP6, OBJECTPOINT, 223), + + /* Set authentication options directly */ + CINIT(LOGIN_OPTIONS, OBJECTPOINT, 224), + + /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_NPN, LONG, 225), + + /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_ALPN, LONG, 226), + + /* Time to wait for a response to a HTTP request containing an + * Expect: 100-continue header before sending the data anyway. */ + CINIT(EXPECT_100_TIMEOUT_MS, LONG, 227), + + /* This points to a linked list of headers used for proxy requests only, + struct curl_slist kind */ + CINIT(PROXYHEADER, OBJECTPOINT, 228), + + /* Pass in a bitmask of "header options" */ + CINIT(HEADEROPT, LONG, 229), + + /* The public key in DER form used to validate the peer public key + this option is used only if SSL_VERIFYPEER is true */ + CINIT(PINNEDPUBLICKEY, OBJECTPOINT, 230), + + /* Path to Unix domain socket */ + CINIT(UNIX_SOCKET_PATH, OBJECTPOINT, 231), + + /* Set if we should verify the certificate status. */ + CINIT(SSL_VERIFYSTATUS, LONG, 232), + + /* Set if we should enable TLS false start. */ + CINIT(SSL_FALSESTART, LONG, 233), + + /* Do not squash dot-dot sequences */ + CINIT(PATH_AS_IS, LONG, 234), + + /* Proxy Service Name */ + CINIT(PROXY_SERVICE_NAME, OBJECTPOINT, 235), + + /* Service Name */ + CINIT(SERVICE_NAME, OBJECTPOINT, 236), + + /* Wait/don't wait for pipe/mutex to clarify */ + CINIT(PIPEWAIT, LONG, 237), + + CURLOPT_LASTENTRY /* the last unused */ +} CURLoption; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2011 */ + +/* This was added in version 7.19.1 */ +#define CURLOPT_POST301 CURLOPT_POSTREDIR + +/* These are scheduled to disappear by 2009 */ + +/* The following were added in 7.17.0 */ +#define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_FTPAPPEND CURLOPT_APPEND +#define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY +#define CURLOPT_FTP_SSL CURLOPT_USE_SSL + +/* The following were added earlier */ + +#define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL + +#else +/* This is set if CURL_NO_OLDIES is defined at compile-time */ +#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ +#endif + + + /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +#define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP + versions that your system allows */ +#define CURL_IPRESOLVE_V4 1 /* resolve to IPv4 addresses */ +#define CURL_IPRESOLVE_V6 2 /* resolve to IPv6 addresses */ + + /* three convenient "aliases" that follow the name scheme better */ +#define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER + + /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum { + CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ + CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ + CURL_HTTP_VERSION_2_0, /* please use HTTP 2.0 in the request */ + + CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ +}; + +/* Convenience definition simple because the name of the version is HTTP/2 and + not 2.0. The 2_0 version of the enum name was set while the version was + still planned to be 2.0 and we stick to it for compatibility. */ +#define CURL_HTTP_VERSION_2 CURL_HTTP_VERSION_2_0 + +/* + * Public API enums for RTSP requests + */ +enum { + CURL_RTSPREQ_NONE, /* first in list */ + CURL_RTSPREQ_OPTIONS, + CURL_RTSPREQ_DESCRIBE, + CURL_RTSPREQ_ANNOUNCE, + CURL_RTSPREQ_SETUP, + CURL_RTSPREQ_PLAY, + CURL_RTSPREQ_PAUSE, + CURL_RTSPREQ_TEARDOWN, + CURL_RTSPREQ_GET_PARAMETER, + CURL_RTSPREQ_SET_PARAMETER, + CURL_RTSPREQ_RECORD, + CURL_RTSPREQ_RECEIVE, + CURL_RTSPREQ_LAST /* last in list */ +}; + + /* These enums are for use with the CURLOPT_NETRC option. */ +enum CURL_NETRC_OPTION { + CURL_NETRC_IGNORED, /* The .netrc will never be read. + * This is the default. */ + CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred + * to one in the .netrc. */ + CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + CURL_NETRC_LAST +}; + +enum { + CURL_SSLVERSION_DEFAULT, + CURL_SSLVERSION_TLSv1, /* TLS 1.x */ + CURL_SSLVERSION_SSLv2, + CURL_SSLVERSION_SSLv3, + CURL_SSLVERSION_TLSv1_0, + CURL_SSLVERSION_TLSv1_1, + CURL_SSLVERSION_TLSv1_2, + + CURL_SSLVERSION_LAST /* never use, keep last */ +}; + +enum CURL_TLSAUTH { + CURL_TLSAUTH_NONE, + CURL_TLSAUTH_SRP, + CURL_TLSAUTH_LAST /* never use, keep last */ +}; + +/* symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301, CURL_REDIR_POST_302 and CURL_REDIR_POST_303 + can be bitwise ORed so that CURL_REDIR_POST_301 | CURL_REDIR_POST_302 + | CURL_REDIR_POST_303 == CURL_REDIR_POST_ALL */ + +#define CURL_REDIR_GET_ALL 0 +#define CURL_REDIR_POST_301 1 +#define CURL_REDIR_POST_302 2 +#define CURL_REDIR_POST_303 4 +#define CURL_REDIR_POST_ALL \ + (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) + +typedef enum { + CURL_TIMECOND_NONE, + + CURL_TIMECOND_IFMODSINCE, + CURL_TIMECOND_IFUNMODSINCE, + CURL_TIMECOND_LASTMOD, + + CURL_TIMECOND_LAST +} curl_TimeCond; + + +/* curl_strequal() and curl_strnequal() are subject for removal in a future + libcurl, see lib/README.curlx for details */ +CURL_EXTERN int (curl_strequal)(const char *s1, const char *s2); +CURL_EXTERN int (curl_strnequal)(const char *s1, const char *s2, size_t n); + +/* name is uppercase CURLFORM_ */ +#ifdef CFINIT +#undef CFINIT +#endif + +#ifdef CURL_ISOCPP +#define CFINIT(name) CURLFORM_ ## name +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define CFINIT(name) CURLFORM_/**/name +#endif + +typedef enum { + CFINIT(NOTHING), /********* the first one is unused ************/ + + /* */ + CFINIT(COPYNAME), + CFINIT(PTRNAME), + CFINIT(NAMELENGTH), + CFINIT(COPYCONTENTS), + CFINIT(PTRCONTENTS), + CFINIT(CONTENTSLENGTH), + CFINIT(FILECONTENT), + CFINIT(ARRAY), + CFINIT(OBSOLETE), + CFINIT(FILE), + + CFINIT(BUFFER), + CFINIT(BUFFERPTR), + CFINIT(BUFFERLENGTH), + + CFINIT(CONTENTTYPE), + CFINIT(CONTENTHEADER), + CFINIT(FILENAME), + CFINIT(END), + CFINIT(OBSOLETE2), + + CFINIT(STREAM), + + CURLFORM_LASTENTRY /* the last unused */ +} CURLformoption; + +#undef CFINIT /* done */ + +/* structure to be used as parameter for CURLFORM_ARRAY */ +struct curl_forms { + CURLformoption option; + const char *value; +}; + +/* use this for multipart formpost building */ +/* Returns code for curl_formadd() + * + * Returns: + * CURL_FORMADD_OK on success + * CURL_FORMADD_MEMORY if the FormInfo allocation fails + * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form + * CURL_FORMADD_NULL if a null pointer was given for a char + * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed + * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used + * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) + * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated + * CURL_FORMADD_MEMORY if some allocation for string copying failed. + * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array + * + ***************************************************************************/ +typedef enum { + CURL_FORMADD_OK, /* first, no error */ + + CURL_FORMADD_MEMORY, + CURL_FORMADD_OPTION_TWICE, + CURL_FORMADD_NULL, + CURL_FORMADD_UNKNOWN_OPTION, + CURL_FORMADD_INCOMPLETE, + CURL_FORMADD_ILLEGAL_ARRAY, + CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ + + CURL_FORMADD_LAST /* last */ +} CURLFORMcode; + +/* + * NAME curl_formadd() + * + * DESCRIPTION + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, + struct curl_httppost **last_post, + ...); + +/* + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +typedef size_t (*curl_formget_callback)(void *arg, const char *buf, + size_t len); + +/* + * NAME curl_formget() + * + * DESCRIPTION + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, + curl_formget_callback append); +/* + * NAME curl_formfree() + * + * DESCRIPTION + * + * Free a multipart formpost previously built with curl_formadd(). + */ +CURL_EXTERN void curl_formfree(struct curl_httppost *form); + +/* + * NAME curl_getenv() + * + * DESCRIPTION + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +CURL_EXTERN char *curl_getenv(const char *variable); + +/* + * NAME curl_version() + * + * DESCRIPTION + * + * Returns a static ascii string of the libcurl version. + */ +CURL_EXTERN char *curl_version(void); + +/* + * NAME curl_easy_escape() + * + * DESCRIPTION + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +CURL_EXTERN char *curl_easy_escape(CURL *handle, + const char *string, + int length); + +/* the previous version: */ +CURL_EXTERN char *curl_escape(const char *string, + int length); + + +/* + * NAME curl_easy_unescape() + * + * DESCRIPTION + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +CURL_EXTERN char *curl_easy_unescape(CURL *handle, + const char *string, + int length, + int *outlength); + +/* the previous version */ +CURL_EXTERN char *curl_unescape(const char *string, + int length); + +/* + * NAME curl_free() + * + * DESCRIPTION + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +CURL_EXTERN void curl_free(void *p); + +/* + * NAME curl_global_init() + * + * DESCRIPTION + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURL_EXTERN CURLcode curl_global_init(long flags); + +/* + * NAME curl_global_init_mem() + * + * DESCRIPTION + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines with be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURL_EXTERN CURLcode curl_global_init_mem(long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c); + +/* + * NAME curl_global_cleanup() + * + * DESCRIPTION + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +CURL_EXTERN void curl_global_cleanup(void); + +/* linked-list structure for the CURLOPT_QUOTE option (and other) */ +struct curl_slist { + char *data; + struct curl_slist *next; +}; + +/* + * NAME curl_slist_append() + * + * DESCRIPTION + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, + const char *); + +/* + * NAME curl_slist_free_all() + * + * DESCRIPTION + * + * free a previously built curl_slist. + */ +CURL_EXTERN void curl_slist_free_all(struct curl_slist *); + +/* + * NAME curl_getdate() + * + * DESCRIPTION + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); + +/* info about the certificate chain, only for OpenSSL builds. Asked + for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo { + int num_of_certs; /* number of certificates with information */ + struct curl_slist **certinfo; /* for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +}; + +/* enum for the different supported SSL backends */ +typedef enum { + CURLSSLBACKEND_NONE = 0, + CURLSSLBACKEND_OPENSSL = 1, + CURLSSLBACKEND_GNUTLS = 2, + CURLSSLBACKEND_NSS = 3, + CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */ + CURLSSLBACKEND_GSKIT = 5, + CURLSSLBACKEND_POLARSSL = 6, + CURLSSLBACKEND_CYASSL = 7, + CURLSSLBACKEND_SCHANNEL = 8, + CURLSSLBACKEND_DARWINSSL = 9, + CURLSSLBACKEND_AXTLS = 10 +} curl_sslbackend; + +/* Information about the SSL library used and the respective internal SSL + handle, which can be used to obtain further information regarding the + connection. Asked for with CURLINFO_TLS_SESSION. */ +struct curl_tlssessioninfo { + curl_sslbackend backend; + void *internals; +}; + +#define CURLINFO_STRING 0x100000 +#define CURLINFO_LONG 0x200000 +#define CURLINFO_DOUBLE 0x300000 +#define CURLINFO_SLIST 0x400000 +#define CURLINFO_MASK 0x0fffff +#define CURLINFO_TYPEMASK 0xf00000 + +typedef enum { + CURLINFO_NONE, /* first, never use this */ + CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, + CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, + CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, + CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, + CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, + CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, + CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, + CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, + CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, + CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, + CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, + CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, + CURLINFO_FILETIME = CURLINFO_LONG + 14, + CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, + CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, + CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, + CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, + CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, + CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, + CURLINFO_PRIVATE = CURLINFO_STRING + 21, + CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, + CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, + CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, + CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, + CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, + CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, + CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, + CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, + CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, + CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, + CURLINFO_CERTINFO = CURLINFO_SLIST + 34, + CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, + CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, + CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, + CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, + CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, + CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, + CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, + CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, + CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43, + /* Fill in new entries below here! */ + + CURLINFO_LASTONE = 43 +} CURLINFO; + +/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE + +typedef enum { + CURLCLOSEPOLICY_NONE, /* first, never use this */ + + CURLCLOSEPOLICY_OLDEST, + CURLCLOSEPOLICY_LEAST_RECENTLY_USED, + CURLCLOSEPOLICY_LEAST_TRAFFIC, + CURLCLOSEPOLICY_SLOWEST, + CURLCLOSEPOLICY_CALLBACK, + + CURLCLOSEPOLICY_LAST /* last, never use this */ +} curl_closepolicy; + +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_NOTHING 0 +#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL +#define CURL_GLOBAL_ACK_EINTR (1<<2) + + +/***************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/* Different data locks for a single share */ +typedef enum { + CURL_LOCK_DATA_NONE = 0, + /* CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + CURL_LOCK_DATA_SHARE, + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_CONNECT, + CURL_LOCK_DATA_LAST +} curl_lock_data; + +/* Different lock access types */ +typedef enum { + CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ + CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ + CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ + CURL_LOCK_ACCESS_LAST /* never use */ +} curl_lock_access; + +typedef void (*curl_lock_function)(CURL *handle, + curl_lock_data data, + curl_lock_access locktype, + void *userptr); +typedef void (*curl_unlock_function)(CURL *handle, + curl_lock_data data, + void *userptr); + +typedef void CURLSH; + +typedef enum { + CURLSHE_OK, /* all is fine */ + CURLSHE_BAD_OPTION, /* 1 */ + CURLSHE_IN_USE, /* 2 */ + CURLSHE_INVALID, /* 3 */ + CURLSHE_NOMEM, /* 4 out of memory */ + CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */ + CURLSHE_LAST /* never use */ +} CURLSHcode; + +typedef enum { + CURLSHOPT_NONE, /* don't use */ + CURLSHOPT_SHARE, /* specify a data type to share */ + CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ + CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ + CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ + CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock + callback functions */ + CURLSHOPT_LAST /* never use */ +} CURLSHoption; + +CURL_EXTERN CURLSH *curl_share_init(void); +CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); +CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); + +/**************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +typedef enum { + CURLVERSION_FIRST, + CURLVERSION_SECOND, + CURLVERSION_THIRD, + CURLVERSION_FOURTH, + CURLVERSION_LAST /* never actually use this */ +} CURLversion; + +/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +#define CURLVERSION_NOW CURLVERSION_FOURTH + +typedef struct { + CURLversion age; /* age of the returned struct */ + const char *version; /* LIBCURL_VERSION */ + unsigned int version_num; /* LIBCURL_VERSION_NUM */ + const char *host; /* OS/host/cpu/machine when configured */ + int features; /* bitmask, see defines below */ + const char *ssl_version; /* human readable string */ + long ssl_version_num; /* not used anymore, always 0 */ + const char *libz_version; /* human readable string */ + /* protocols is terminated by an entry with a NULL protoname */ + const char * const *protocols; + + /* The fields below this were added in CURLVERSION_SECOND */ + const char *ares; + int ares_num; + + /* This field was added in CURLVERSION_THIRD */ + const char *libidn; + + /* These field were added in CURLVERSION_FOURTH */ + + /* Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + + const char *libssh_version; /* human readable string */ + +} curl_version_info_data; + +#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ +#define CURL_VERSION_KERBEROS4 (1<<1) /* Kerberos V4 auth is supported + (deprecated) */ +#define CURL_VERSION_SSL (1<<2) /* SSL options are present */ +#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ +#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ +#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth is supported + (deprecated) */ +#define CURL_VERSION_DEBUG (1<<6) /* Built with debug capabilities */ +#define CURL_VERSION_ASYNCHDNS (1<<7) /* Asynchronous DNS resolves */ +#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth is supported */ +#define CURL_VERSION_LARGEFILE (1<<9) /* Supports files larger than 2GB */ +#define CURL_VERSION_IDN (1<<10) /* Internationized Domain Names are + supported */ +#define CURL_VERSION_SSPI (1<<11) /* Built against Windows SSPI */ +#define CURL_VERSION_CONV (1<<12) /* Character conversions supported */ +#define CURL_VERSION_CURLDEBUG (1<<13) /* Debug memory tracking supported */ +#define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ +#define CURL_VERSION_NTLM_WB (1<<15) /* NTLM delegation to winbind helper + is suported */ +#define CURL_VERSION_HTTP2 (1<<16) /* HTTP2 support built-in */ +#define CURL_VERSION_GSSAPI (1<<17) /* Built against a GSS-API library */ +#define CURL_VERSION_KERBEROS5 (1<<18) /* Kerberos V5 auth is supported */ +#define CURL_VERSION_UNIX_SOCKETS (1<<19) /* Unix domain sockets support */ + + /* + * NAME curl_version_info() + * + * DESCRIPTION + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); + +/* + * NAME curl_easy_strerror() + * + * DESCRIPTION + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_easy_strerror(CURLcode); + +/* + * NAME curl_share_strerror() + * + * DESCRIPTION + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_share_strerror(CURLSHcode); + +/* + * NAME curl_easy_pause() + * + * DESCRIPTION + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); + +#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV_CONT (0) + +#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND_CONT (0) + +#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) + +#ifdef __cplusplus +} +#endif + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +#include "easy.h" /* nothing in curl is fun without the easy stuff */ +#include "multi.h" + +/* the typechecker doesn't work in C++ (yet) */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ + !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) +#include "typecheck-gcc.h" +#else +#if defined(__STDC__) && (__STDC__ >= 1) +/* This preprocessor magic that replaces a call with the exact same call is + only done to make sure application authors pass exactly three arguments + to these functions. */ +#define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) +#define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) +#endif /* __STDC__ >= 1 */ +#endif /* gcc >= 4.3 && !__cplusplus */ + +#endif /* __CURL_CURL_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/curlbuild.h b/石器时代8.5客户端最新源代码/石器源码/curl/curlbuild.h new file mode 100644 index 0000000..f09419a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/curlbuild.h @@ -0,0 +1,585 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * See file include/curl/curlbuild.h.in, run configure, and forget + * that this file exists it is only used for non-configure systems. + * But you can keep reading if you want ;-) + * + */ + +/* ================================================================ */ +/* NOTES FOR NON-CONFIGURE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: http://cool.haxx.se/mailman/listinfo/curl-library/ + * + * Try to keep one section per platform, compiler and architecture, + * otherwise, if an existing section is reused for a different one and + * later on the original is adjusted, probably the piggybacking one can + * be adversely changed. + * + * In order to differentiate between platforms/compilers/architectures + * use only compiler built in predefined preprocessor symbols. + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a + * 64-bit wide signed integral data type. The width of this data type + * must remain constant and independent of any possible large file + * support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a + * 32-bit wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This + * rule shall only be violated if off_t is the only 64-bit data type + * available and the size of off_t is independent of large file support + * settings. Keep your build on the safe side avoiding an off_t gating. + * If you have a 64-bit off_t then take for sure that another 64-bit + * data type exists, dig deeper and you will find it. + * + * NOTE 3: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.dist or + * at file include/curl/curlbuild.h, this is due to the following reason: + * file include/curl/curlbuild.h.dist is renamed to include/curl/curlbuild.h + * when the libcurl source code distribution archive file is created. + * + * File include/curl/curlbuild.h.dist is not included in the distribution + * archive. File include/curl/curlbuild.h is not present in the git tree. + * + * The distributed include/curl/curlbuild.h file is only intended to be used + * on systems which can not run the also distributed configure script. + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + * If you check out from git on a non-configure platform, you must run the + * appropriate buildconf* script to set up curlbuild.h and other local files. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */ +/* ================================================================ */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SALFORDC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TURBOC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__LCC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MWERKS__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(_WIN32_WCE) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MINGW32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) +# if defined(__ILP32__) || \ + defined(__i386__) || defined(__ppc__) || defined(__arm__) || defined(__sparc__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#else +# error "Unknown non-configure build target!" + Error Compilation_aborted_Unknown_non_configure_build_target +#endif + +/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Data type definition of curl_socklen_t. */ + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T + typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURL_TYPEOF_CURL_OFF_T + typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; +#endif + +#endif /* __CURL_CURLBUILD_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/curlrules.h b/石器时代8.5客户端最新源代码/石器源码/curl/curlrules.h new file mode 100644 index 0000000..7c2ede3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/curlrules.h @@ -0,0 +1,262 @@ +#ifndef __CURL_CURLRULES_H +#define __CURL_CURLRULES_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* COMPILE TIME SANITY CHECKS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * All checks done in this file are intentionally placed in a public + * header file which is pulled by curl/curl.h when an application is + * being built using an already built libcurl library. Additionally + * this file is also included and used when building the library. + * + * If compilation fails on this file it is certainly sure that the + * problem is elsewhere. It could be a problem in the curlbuild.h + * header file, or simply that you are using different compilation + * settings than those used to build the library. + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * Do not deactivate any check, these are done to make sure that the + * library is properly built and used. + * + * You can find further help on the libcurl development mailing list: + * http://cool.haxx.se/mailman/listinfo/curl-library/ + * + * NOTE 2 + * ------ + * + * Some of the following compile time checks are based on the fact + * that the dimension of a constant array can not be a negative one. + * In this way if the compile time verification fails, the compilation + * will fail issuing an error. The error description wording is compiler + * dependent but it will be quite similar to one of the following: + * + * "negative subscript or subscript is too large" + * "array must have at least one element" + * "-1 is an illegal array size" + * "size of array is negative" + * + * If you are building an application which tries to use an already + * built libcurl library and you are getting this kind of errors on + * this file, it is a clear indication that there is a mismatch between + * how the library was built and how you are trying to use it for your + * application. Your already compiled or binary library provider is the + * only one who can give you the details you need to properly use it. + */ + +/* + * Verify that some macros are actually defined. + */ + +#ifndef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing +#endif + +#ifndef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_OFF_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing +#endif + +/* + * Macros private to this header file. + */ + +#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1 + +#define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 + +/* + * Verify that the size previously defined and expected for long + * is the same as the one reported by sizeof() at compile time. + */ + +typedef char + __curl_rule_01__ + [CurlchkszEQ(long, CURL_SIZEOF_LONG)]; + +/* + * Verify that the size previously defined and expected for + * curl_off_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_02__ + [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)]; + +/* + * Verify at compile time that the size of curl_off_t as reported + * by sizeof() is greater or equal than the one reported for long + * for the current compilation. + */ + +typedef char + __curl_rule_03__ + [CurlchkszGE(curl_off_t, long)]; + +/* + * Verify that the size previously defined and expected for + * curl_socklen_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_04__ + [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)]; + +/* + * Verify at compile time that the size of curl_socklen_t as reported + * by sizeof() is greater or equal than the one reported for int for + * the current compilation. + */ + +typedef char + __curl_rule_05__ + [CurlchkszGE(curl_socklen_t, int)]; + +/* ================================================================ */ +/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ +/* ================================================================ */ + +/* + * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow + * these to be visible and exported by the external libcurl interface API, + * while also making them visible to the library internals, simply including + * curl_setup.h, without actually needing to include curl.h internally. + * If some day this section would grow big enough, all this should be moved + * to its own header file. + */ + +/* + * Figure out if we can use the ## preprocessor operator, which is supported + * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ + * or __cplusplus so we need to carefully check for them too. + */ + +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ + defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ + defined(__ILEC400__) + /* This compiler is believed to have an ISO compatible preprocessor */ +#define CURL_ISOCPP +#else + /* This compiler is believed NOT to have an ISO compatible preprocessor */ +#undef CURL_ISOCPP +#endif + +/* + * Macros for minimum-width signed and unsigned curl_off_t integer constants. + */ + +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) +# define __CURL_OFF_T_C_HLPR2(x) x +# define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) +#else +# ifdef CURL_ISOCPP +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix +# else +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix +# endif +# define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) +#endif + +/* + * Get rid of macros private to this header file. + */ + +#undef CurlchkszEQ +#undef CurlchkszGE + +/* + * Get rid of macros not intended to exist beyond this point. + */ + +#undef CURL_PULL_WS2TCPIP_H +#undef CURL_PULL_SYS_TYPES_H +#undef CURL_PULL_SYS_SOCKET_H +#undef CURL_PULL_SYS_POLL_H +#undef CURL_PULL_STDINT_H +#undef CURL_PULL_INTTYPES_H + +#undef CURL_TYPEOF_CURL_SOCKLEN_T +#undef CURL_TYPEOF_CURL_OFF_T + +#ifdef CURL_NO_OLDIES +#undef CURL_FORMAT_OFF_T /* not required since 7.19.0 - obsoleted in 7.20.0 */ +#endif + +#endif /* __CURL_CURLRULES_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/curlver.h b/石器时代8.5客户端最新源代码/石器源码/curl/curlver.h new file mode 100644 index 0000000..f7075bf --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/curlver.h @@ -0,0 +1,77 @@ +#ifndef __CURL_CURLVER_H +#define __CURL_CURLVER_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2015, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* This header file contains nothing but libcurl version info, generated by + a script at release-time. This was made its own header file in 7.11.2 */ + +/* This is the global package copyright */ +#define LIBCURL_COPYRIGHT "1996 - 2015 Daniel Stenberg, ." + +/* This is the version number of the libcurl package from which this header + file origins: */ +#define LIBCURL_VERSION "7.43.0" + +/* The numeric version number is also available "in parts" by using these + defines: */ +#define LIBCURL_VERSION_MAJOR 7 +#define LIBCURL_VERSION_MINOR 43 +#define LIBCURL_VERSION_PATCH 0 + +/* This is the numeric version of the libcurl version number, meant for easier + parsing and comparions by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. + + Note: This define is the full hex number and _does not_ use the + CURL_VERSION_BITS() macro since curl's own configure script greps for it + and needs it to contain the full number. +*/ +#define LIBCURL_VERSION_NUM 0x072b00 + +/* + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date should follow this template: + * + * "Mon Feb 12 11:35:33 UTC 2007" + */ +#define LIBCURL_TIMESTAMP "Wed Jun 17 05:56:00 UTC 2015" + +#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) +#define CURL_AT_LEAST_VERSION(x,y,z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) + +#endif /* __CURL_CURLVER_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/easy.h b/石器时代8.5客户端最新源代码/石器源码/curl/easy.h new file mode 100644 index 0000000..c1e3e76 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/easy.h @@ -0,0 +1,102 @@ +#ifndef __CURL_EASY_H +#define __CURL_EASY_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN CURL *curl_easy_init(void); +CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); +CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); +CURL_EXTERN void curl_easy_cleanup(CURL *curl); + +/* + * NAME curl_easy_getinfo() + * + * DESCRIPTION + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); + + +/* + * NAME curl_easy_duphandle() + * + * DESCRIPTION + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistent connections cannot + * be transferred. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl); + +/* + * NAME curl_easy_reset() + * + * DESCRIPTION + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +CURL_EXTERN void curl_easy_reset(CURL *curl); + +/* + * NAME curl_easy_recv() + * + * DESCRIPTION + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, + size_t *n); + +/* + * NAME curl_easy_send() + * + * DESCRIPTION + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, + size_t buflen, size_t *n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/mprintf.h b/石器时代8.5客户端最新源代码/石器源码/curl/mprintf.h new file mode 100644 index 0000000..c6b0d76 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/mprintf.h @@ -0,0 +1,74 @@ +#ifndef __CURL_MPRINTF_H +#define __CURL_MPRINTF_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2015, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include +#include /* needed for FILE */ + +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN int curl_mprintf(const char *format, ...); +CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); +CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); +CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, + const char *format, ...); +CURL_EXTERN int curl_mvprintf(const char *format, va_list args); +CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); +CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); +CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, + const char *format, va_list args); +CURL_EXTERN char *curl_maprintf(const char *format, ...); +CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); + +#ifdef _MPRINTF_REPLACE +# undef printf +# undef fprintf +# undef sprintf +# undef vsprintf +# undef snprintf +# undef vprintf +# undef vfprintf +# undef vsnprintf +# undef aprintf +# undef vaprintf +# define printf curl_mprintf +# define fprintf curl_mfprintf +# define sprintf curl_msprintf +# define vsprintf curl_mvsprintf +# define snprintf curl_msnprintf +# define vprintf curl_mvprintf +# define vfprintf curl_mvfprintf +# define vsnprintf curl_mvsnprintf +# define aprintf curl_maprintf +# define vaprintf curl_mvaprintf +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __CURL_MPRINTF_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/multi.h b/石器时代8.5客户端最新源代码/石器源码/curl/multi.h new file mode 100644 index 0000000..0d859f8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/multi.h @@ -0,0 +1,404 @@ +#ifndef __CURL_MULTI_H +#define __CURL_MULTI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2015, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* + This is an "external" header file. Don't give away any internals here! + + GOALS + + o Enable a "pull" interface. The application that uses libcurl decides where + and when to ask libcurl to get/send data. + + o Enable multiple simultaneous transfers in the same thread without making it + complicated for the application. + + o Enable the application to select() on its own file descriptors and curl's + file descriptors simultaneous easily. + +*/ + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void CURLM; + +typedef enum { + CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or + curl_multi_socket*() soon */ + CURLM_OK, + CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ + CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ + CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ + CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ + CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ + CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ + CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was + attempted to get added - again */ + CURLM_LAST +} CURLMcode; + +/* just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM + +/* bitmask bits for CURLMOPT_PIPELINING */ +#define CURLPIPE_NOTHING 0L +#define CURLPIPE_HTTP1 1L +#define CURLPIPE_MULTIPLEX 2L + +typedef enum { + CURLMSG_NONE, /* first, not used */ + CURLMSG_DONE, /* This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + CURLMSG_LAST /* last, not used */ +} CURLMSG; + +struct CURLMsg { + CURLMSG msg; /* what this message means */ + CURL *easy_handle; /* the handle it concerns */ + union { + void *whatever; /* message-specific data */ + CURLcode result; /* return code for transfer */ + } data; +}; +typedef struct CURLMsg CURLMsg; + +/* Based on poll(2) structure and values. + * We don't use pollfd and POLL* constants explicitly + * to cover platforms without poll(). */ +#define CURL_WAIT_POLLIN 0x0001 +#define CURL_WAIT_POLLPRI 0x0002 +#define CURL_WAIT_POLLOUT 0x0004 + +struct curl_waitfd { + curl_socket_t fd; + short events; + short revents; /* not supported yet */ +}; + +/* + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +CURL_EXTERN CURLM *curl_multi_init(void); + +/* + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd); + +/* + * Name: curl_multi_wait() + * + * Desc: Poll on all fds within a CURLM set as well as any + * additional fds passed to the function. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, + struct curl_waitfd extra_fds[], + unsigned int extra_nfds, + int timeout_ms, + int *ret); + + /* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on invidual transfers even when this + * returns OK. + */ +CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, + int *running_handles); + + /* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/* + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic informations. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, + int *msgs_in_queue); + +/* + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a zero-terminated error message. + */ +CURL_EXTERN const char *curl_multi_strerror(CURLMcode); + +/* + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +#define CURL_POLL_NONE 0 +#define CURL_POLL_IN 1 +#define CURL_POLL_OUT 2 +#define CURL_POLL_INOUT 3 +#define CURL_POLL_REMOVE 4 + +#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD + +#define CURL_CSELECT_IN 0x01 +#define CURL_CSELECT_OUT 0x02 +#define CURL_CSELECT_ERR 0x04 + +typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ + curl_socket_t s, /* socket */ + int what, /* see above */ + void *userp, /* private callback + pointer */ + void *socketp); /* private socket + pointer */ +/* + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ +typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ + long timeout_ms, /* see above */ + void *userp); /* private callback + pointer */ + +CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, + curl_socket_t s, + int ev_bitmask, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, + int *running_handles); + +#ifndef CURL_ALLOW_OLD_MULTI_SOCKET +/* This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ +#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) +#endif + +/* + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, + long *milliseconds); + +#undef CINIT /* re-using the same name as in curl.h */ + +#ifdef CURL_ISOCPP +#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLMOPT_/**/name = type + number +#endif + +typedef enum { + /* This is the socket callback function pointer */ + CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), + + /* This is the argument passed to the socket callback */ + CINIT(SOCKETDATA, OBJECTPOINT, 2), + + /* set to 1 to enable pipelining for this multi handle */ + CINIT(PIPELINING, LONG, 3), + + /* This is the timer callback function pointer */ + CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), + + /* This is the argument passed to the timer callback */ + CINIT(TIMERDATA, OBJECTPOINT, 5), + + /* maximum number of entries in the connection cache */ + CINIT(MAXCONNECTS, LONG, 6), + + /* maximum number of (pipelining) connections to one host */ + CINIT(MAX_HOST_CONNECTIONS, LONG, 7), + + /* maximum number of requests in a pipeline */ + CINIT(MAX_PIPELINE_LENGTH, LONG, 8), + + /* a connection with a content-length longer than this + will not be considered for pipelining */ + CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9), + + /* a connection with a chunk length longer than this + will not be considered for pipelining */ + CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10), + + /* a list of site names(+port) that are blacklisted from + pipelining */ + CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11), + + /* a list of server types that are blacklisted from + pipelining */ + CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12), + + /* maximum number of open connections in total */ + CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13), + + CURLMOPT_LASTENTRY /* the last unused */ +} CURLMoption; + + +/* + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, + CURLMoption option, ...); + + +/* + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, void *sockp); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/stdcheaders.h b/石器时代8.5客户端最新源代码/石器源码/curl/stdcheaders.h new file mode 100644 index 0000000..ad82ef6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/stdcheaders.h @@ -0,0 +1,33 @@ +#ifndef __STDC_HEADERS_H +#define __STDC_HEADERS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include + +size_t fread (void *, size_t, size_t, FILE *); +size_t fwrite (const void *, size_t, size_t, FILE *); + +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#endif /* __STDC_HEADERS_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/curl/typecheck-gcc.h b/石器时代8.5客户端最新源代码/石器源码/curl/typecheck-gcc.h new file mode 100644 index 0000000..13fb0fa --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/curl/typecheck-gcc.h @@ -0,0 +1,612 @@ +#ifndef __CURL_TYPECHECK_GCC_H +#define __CURL_TYPECHECK_GCC_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* wraps curl_easy_setopt() with typechecking */ + +/* To add a new kind of warning, add an + * if(_curl_is_sometype_option(_curl_opt)) + * if(!_curl_is_sometype(value)) + * _curl_easy_setopt_err_sometype(); + * block and define _curl_is_sometype_option, _curl_is_sometype and + * _curl_easy_setopt_err_sometype below + * + * NOTE: We use two nested 'if' statements here instead of the && operator, in + * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x + * when compiling with -Wlogical-op. + * + * To add an option that uses the same type as an existing option, you'll just + * need to extend the appropriate _curl_*_option macro + */ +#define curl_easy_setopt(handle, option, value) \ +__extension__ ({ \ + __typeof__ (option) _curl_opt = option; \ + if(__builtin_constant_p(_curl_opt)) { \ + if(_curl_is_long_option(_curl_opt)) \ + if(!_curl_is_long(value)) \ + _curl_easy_setopt_err_long(); \ + if(_curl_is_off_t_option(_curl_opt)) \ + if(!_curl_is_off_t(value)) \ + _curl_easy_setopt_err_curl_off_t(); \ + if(_curl_is_string_option(_curl_opt)) \ + if(!_curl_is_string(value)) \ + _curl_easy_setopt_err_string(); \ + if(_curl_is_write_cb_option(_curl_opt)) \ + if(!_curl_is_write_cb(value)) \ + _curl_easy_setopt_err_write_callback(); \ + if((_curl_opt) == CURLOPT_READFUNCTION) \ + if(!_curl_is_read_cb(value)) \ + _curl_easy_setopt_err_read_cb(); \ + if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ + if(!_curl_is_ioctl_cb(value)) \ + _curl_easy_setopt_err_ioctl_cb(); \ + if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ + if(!_curl_is_sockopt_cb(value)) \ + _curl_easy_setopt_err_sockopt_cb(); \ + if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ + if(!_curl_is_opensocket_cb(value)) \ + _curl_easy_setopt_err_opensocket_cb(); \ + if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ + if(!_curl_is_progress_cb(value)) \ + _curl_easy_setopt_err_progress_cb(); \ + if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ + if(!_curl_is_debug_cb(value)) \ + _curl_easy_setopt_err_debug_cb(); \ + if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ + if(!_curl_is_ssl_ctx_cb(value)) \ + _curl_easy_setopt_err_ssl_ctx_cb(); \ + if(_curl_is_conv_cb_option(_curl_opt)) \ + if(!_curl_is_conv_cb(value)) \ + _curl_easy_setopt_err_conv_cb(); \ + if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ + if(!_curl_is_seek_cb(value)) \ + _curl_easy_setopt_err_seek_cb(); \ + if(_curl_is_cb_data_option(_curl_opt)) \ + if(!_curl_is_cb_data(value)) \ + _curl_easy_setopt_err_cb_data(); \ + if((_curl_opt) == CURLOPT_ERRORBUFFER) \ + if(!_curl_is_error_buffer(value)) \ + _curl_easy_setopt_err_error_buffer(); \ + if((_curl_opt) == CURLOPT_STDERR) \ + if(!_curl_is_FILE(value)) \ + _curl_easy_setopt_err_FILE(); \ + if(_curl_is_postfields_option(_curl_opt)) \ + if(!_curl_is_postfields(value)) \ + _curl_easy_setopt_err_postfields(); \ + if((_curl_opt) == CURLOPT_HTTPPOST) \ + if(!_curl_is_arr((value), struct curl_httppost)) \ + _curl_easy_setopt_err_curl_httpost(); \ + if(_curl_is_slist_option(_curl_opt)) \ + if(!_curl_is_arr((value), struct curl_slist)) \ + _curl_easy_setopt_err_curl_slist(); \ + if((_curl_opt) == CURLOPT_SHARE) \ + if(!_curl_is_ptr((value), CURLSH)) \ + _curl_easy_setopt_err_CURLSH(); \ + } \ + curl_easy_setopt(handle, _curl_opt, value); \ +}) + +/* wraps curl_easy_getinfo() with typechecking */ +/* FIXME: don't allow const pointers */ +#define curl_easy_getinfo(handle, info, arg) \ +__extension__ ({ \ + __typeof__ (info) _curl_info = info; \ + if(__builtin_constant_p(_curl_info)) { \ + if(_curl_is_string_info(_curl_info)) \ + if(!_curl_is_arr((arg), char *)) \ + _curl_easy_getinfo_err_string(); \ + if(_curl_is_long_info(_curl_info)) \ + if(!_curl_is_arr((arg), long)) \ + _curl_easy_getinfo_err_long(); \ + if(_curl_is_double_info(_curl_info)) \ + if(!_curl_is_arr((arg), double)) \ + _curl_easy_getinfo_err_double(); \ + if(_curl_is_slist_info(_curl_info)) \ + if(!_curl_is_arr((arg), struct curl_slist *)) \ + _curl_easy_getinfo_err_curl_slist(); \ + } \ + curl_easy_getinfo(handle, _curl_info, arg); \ +}) + +/* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(), + * for now just make sure that the functions are called with three + * arguments + */ +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) + + +/* the actual warnings, triggered by calling the _curl_easy_setopt_err* + * functions */ + +/* To define a new warning, use _CURL_WARNING(identifier, "message") */ +#define _CURL_WARNING(id, message) \ + static void __attribute__((__warning__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) { __asm__(""); } + +_CURL_WARNING(_curl_easy_setopt_err_long, + "curl_easy_setopt expects a long argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_off_t, + "curl_easy_setopt expects a curl_off_t argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_string, + "curl_easy_setopt expects a " + "string (char* or char[]) argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_write_callback, + "curl_easy_setopt expects a curl_write_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_read_cb, + "curl_easy_setopt expects a curl_read_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, + "curl_easy_setopt expects a curl_ioctl_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, + "curl_easy_setopt expects a curl_sockopt_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, + "curl_easy_setopt expects a " + "curl_opensocket_callback argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_progress_cb, + "curl_easy_setopt expects a curl_progress_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_debug_cb, + "curl_easy_setopt expects a curl_debug_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, + "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_conv_cb, + "curl_easy_setopt expects a curl_conv_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_seek_cb, + "curl_easy_setopt expects a curl_seek_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_cb_data, + "curl_easy_setopt expects a " + "private data pointer as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_error_buffer, + "curl_easy_setopt expects a " + "char buffer of CURL_ERROR_SIZE as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_FILE, + "curl_easy_setopt expects a FILE* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_postfields, + "curl_easy_setopt expects a void* or char* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_httpost, + "curl_easy_setopt expects a struct curl_httppost* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_slist, + "curl_easy_setopt expects a struct curl_slist* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_CURLSH, + "curl_easy_setopt expects a CURLSH* argument for this option") + +_CURL_WARNING(_curl_easy_getinfo_err_string, + "curl_easy_getinfo expects a pointer to char * for this info") +_CURL_WARNING(_curl_easy_getinfo_err_long, + "curl_easy_getinfo expects a pointer to long for this info") +_CURL_WARNING(_curl_easy_getinfo_err_double, + "curl_easy_getinfo expects a pointer to double for this info") +_CURL_WARNING(_curl_easy_getinfo_err_curl_slist, + "curl_easy_getinfo expects a pointer to struct curl_slist * for this info") + +/* groups of curl_easy_setops options that take the same type of argument */ + +/* To add a new option to one of the groups, just add + * (option) == CURLOPT_SOMETHING + * to the or-expression. If the option takes a long or curl_off_t, you don't + * have to do anything + */ + +/* evaluates to true if option takes a long argument */ +#define _curl_is_long_option(option) \ + (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) + +#define _curl_is_off_t_option(option) \ + ((option) > CURLOPTTYPE_OFF_T) + +/* evaluates to true if option takes a char* argument */ +#define _curl_is_string_option(option) \ + ((option) == CURLOPT_URL || \ + (option) == CURLOPT_PROXY || \ + (option) == CURLOPT_INTERFACE || \ + (option) == CURLOPT_NETRC_FILE || \ + (option) == CURLOPT_USERPWD || \ + (option) == CURLOPT_USERNAME || \ + (option) == CURLOPT_PASSWORD || \ + (option) == CURLOPT_PROXYUSERPWD || \ + (option) == CURLOPT_PROXYUSERNAME || \ + (option) == CURLOPT_PROXYPASSWORD || \ + (option) == CURLOPT_NOPROXY || \ + (option) == CURLOPT_ACCEPT_ENCODING || \ + (option) == CURLOPT_REFERER || \ + (option) == CURLOPT_USERAGENT || \ + (option) == CURLOPT_COOKIE || \ + (option) == CURLOPT_COOKIEFILE || \ + (option) == CURLOPT_COOKIEJAR || \ + (option) == CURLOPT_COOKIELIST || \ + (option) == CURLOPT_FTPPORT || \ + (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ + (option) == CURLOPT_FTP_ACCOUNT || \ + (option) == CURLOPT_RANGE || \ + (option) == CURLOPT_CUSTOMREQUEST || \ + (option) == CURLOPT_SSLCERT || \ + (option) == CURLOPT_SSLCERTTYPE || \ + (option) == CURLOPT_SSLKEY || \ + (option) == CURLOPT_SSLKEYTYPE || \ + (option) == CURLOPT_KEYPASSWD || \ + (option) == CURLOPT_SSLENGINE || \ + (option) == CURLOPT_CAINFO || \ + (option) == CURLOPT_CAPATH || \ + (option) == CURLOPT_RANDOM_FILE || \ + (option) == CURLOPT_EGDSOCKET || \ + (option) == CURLOPT_SSL_CIPHER_LIST || \ + (option) == CURLOPT_KRBLEVEL || \ + (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ + (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ + (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ + (option) == CURLOPT_CRLFILE || \ + (option) == CURLOPT_ISSUERCERT || \ + (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ + (option) == CURLOPT_SSH_KNOWNHOSTS || \ + (option) == CURLOPT_MAIL_FROM || \ + (option) == CURLOPT_RTSP_SESSION_ID || \ + (option) == CURLOPT_RTSP_STREAM_URI || \ + (option) == CURLOPT_RTSP_TRANSPORT || \ + (option) == CURLOPT_XOAUTH2_BEARER || \ + (option) == CURLOPT_DNS_SERVERS || \ + (option) == CURLOPT_DNS_INTERFACE || \ + (option) == CURLOPT_DNS_LOCAL_IP4 || \ + (option) == CURLOPT_DNS_LOCAL_IP6 || \ + (option) == CURLOPT_LOGIN_OPTIONS || \ + (option) == CURLOPT_PROXY_SERVICE_NAME || \ + (option) == CURLOPT_SERVICE_NAME || \ + 0) + +/* evaluates to true if option takes a curl_write_callback argument */ +#define _curl_is_write_cb_option(option) \ + ((option) == CURLOPT_HEADERFUNCTION || \ + (option) == CURLOPT_WRITEFUNCTION) + +/* evaluates to true if option takes a curl_conv_callback argument */ +#define _curl_is_conv_cb_option(option) \ + ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) + +/* evaluates to true if option takes a data argument to pass to a callback */ +#define _curl_is_cb_data_option(option) \ + ((option) == CURLOPT_WRITEDATA || \ + (option) == CURLOPT_READDATA || \ + (option) == CURLOPT_IOCTLDATA || \ + (option) == CURLOPT_SOCKOPTDATA || \ + (option) == CURLOPT_OPENSOCKETDATA || \ + (option) == CURLOPT_PROGRESSDATA || \ + (option) == CURLOPT_HEADERDATA || \ + (option) == CURLOPT_DEBUGDATA || \ + (option) == CURLOPT_SSL_CTX_DATA || \ + (option) == CURLOPT_SEEKDATA || \ + (option) == CURLOPT_PRIVATE || \ + (option) == CURLOPT_SSH_KEYDATA || \ + (option) == CURLOPT_INTERLEAVEDATA || \ + (option) == CURLOPT_CHUNK_DATA || \ + (option) == CURLOPT_FNMATCH_DATA || \ + 0) + +/* evaluates to true if option takes a POST data argument (void* or char*) */ +#define _curl_is_postfields_option(option) \ + ((option) == CURLOPT_POSTFIELDS || \ + (option) == CURLOPT_COPYPOSTFIELDS || \ + 0) + +/* evaluates to true if option takes a struct curl_slist * argument */ +#define _curl_is_slist_option(option) \ + ((option) == CURLOPT_HTTPHEADER || \ + (option) == CURLOPT_HTTP200ALIASES || \ + (option) == CURLOPT_QUOTE || \ + (option) == CURLOPT_POSTQUOTE || \ + (option) == CURLOPT_PREQUOTE || \ + (option) == CURLOPT_TELNETOPTIONS || \ + (option) == CURLOPT_MAIL_RCPT || \ + 0) + +/* groups of curl_easy_getinfo infos that take the same type of argument */ + +/* evaluates to true if info expects a pointer to char * argument */ +#define _curl_is_string_info(info) \ + (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) + +/* evaluates to true if info expects a pointer to long argument */ +#define _curl_is_long_info(info) \ + (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) + +/* evaluates to true if info expects a pointer to double argument */ +#define _curl_is_double_info(info) \ + (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) + +/* true if info expects a pointer to struct curl_slist * argument */ +#define _curl_is_slist_info(info) \ + (CURLINFO_SLIST < (info)) + + +/* typecheck helpers -- check whether given expression has requested type*/ + +/* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, + * otherwise define a new macro. Search for __builtin_types_compatible_p + * in the GCC manual. + * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is + * the actual expression passed to the curl_easy_setopt macro. This + * means that you can only apply the sizeof and __typeof__ operators, no + * == or whatsoever. + */ + +/* XXX: should evaluate to true iff expr is a pointer */ +#define _curl_is_any_ptr(expr) \ + (sizeof(expr) == sizeof(void*)) + +/* evaluates to true if expr is NULL */ +/* XXX: must not evaluate expr, so this check is not accurate */ +#define _curl_is_NULL(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) + +/* evaluates to true if expr is type*, const type* or NULL */ +#define _curl_is_ptr(expr, type) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), type *) || \ + __builtin_types_compatible_p(__typeof__(expr), const type *)) + +/* evaluates to true if expr is one of type[], type*, NULL or const type* */ +#define _curl_is_arr(expr, type) \ + (_curl_is_ptr((expr), type) || \ + __builtin_types_compatible_p(__typeof__(expr), type [])) + +/* evaluates to true if expr is a string */ +#define _curl_is_string(expr) \ + (_curl_is_arr((expr), char) || \ + _curl_is_arr((expr), signed char) || \ + _curl_is_arr((expr), unsigned char)) + +/* evaluates to true if expr is a long (no matter the signedness) + * XXX: for now, int is also accepted (and therefore short and char, which + * are promoted to int when passed to a variadic function) */ +#define _curl_is_long(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), long) || \ + __builtin_types_compatible_p(__typeof__(expr), signed long) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ + __builtin_types_compatible_p(__typeof__(expr), int) || \ + __builtin_types_compatible_p(__typeof__(expr), signed int) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ + __builtin_types_compatible_p(__typeof__(expr), short) || \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), char) || \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char)) + +/* evaluates to true if expr is of type curl_off_t */ +#define _curl_is_off_t(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) + +/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ +/* XXX: also check size of an char[] array? */ +#define _curl_is_error_buffer(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), char *) || \ + __builtin_types_compatible_p(__typeof__(expr), char[])) + +/* evaluates to true if expr is of type (const) void* or (const) FILE* */ +#if 0 +#define _curl_is_cb_data(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_ptr((expr), FILE)) +#else /* be less strict */ +#define _curl_is_cb_data(expr) \ + _curl_is_any_ptr(expr) +#endif + +/* evaluates to true if expr is of type FILE* */ +#define _curl_is_FILE(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), FILE *)) + +/* evaluates to true if expr can be passed as POST data (void* or char*) */ +#define _curl_is_postfields(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_arr((expr), char)) + +/* FIXME: the whole callback checking is messy... + * The idea is to tolerate char vs. void and const vs. not const + * pointers in arguments at least + */ +/* helper: __builtin_types_compatible_p distinguishes between functions and + * function pointers, hide it */ +#define _curl_callback_compatible(func, type) \ + (__builtin_types_compatible_p(__typeof__(func), type) || \ + __builtin_types_compatible_p(__typeof__(func), type*)) + +/* evaluates to true if expr is of type curl_read_callback or "similar" */ +#define _curl_is_read_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \ + _curl_callback_compatible((expr), _curl_read_callback1) || \ + _curl_callback_compatible((expr), _curl_read_callback2) || \ + _curl_callback_compatible((expr), _curl_read_callback3) || \ + _curl_callback_compatible((expr), _curl_read_callback4) || \ + _curl_callback_compatible((expr), _curl_read_callback5) || \ + _curl_callback_compatible((expr), _curl_read_callback6)) +typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void*); +typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void*); +typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE*); +typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void*); +typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void*); +typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE*); + +/* evaluates to true if expr is of type curl_write_callback or "similar" */ +#define _curl_is_write_cb(expr) \ + (_curl_is_read_cb(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \ + _curl_callback_compatible((expr), _curl_write_callback1) || \ + _curl_callback_compatible((expr), _curl_write_callback2) || \ + _curl_callback_compatible((expr), _curl_write_callback3) || \ + _curl_callback_compatible((expr), _curl_write_callback4) || \ + _curl_callback_compatible((expr), _curl_write_callback5) || \ + _curl_callback_compatible((expr), _curl_write_callback6)) +typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void*); +typedef size_t (_curl_write_callback2)(const char *, size_t, size_t, + const void*); +typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE*); +typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void*); +typedef size_t (_curl_write_callback5)(const void *, size_t, size_t, + const void*); +typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE*); + +/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ +#define _curl_is_ioctl_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback4)) +typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void*); +typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void*); +typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void*); +typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void*); + +/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ +#define _curl_is_sockopt_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback2)) +typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); +typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t, + curlsocktype); + +/* evaluates to true if expr is of type curl_opensocket_callback or + "similar" */ +#define _curl_is_opensocket_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\ + _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback4)) +typedef curl_socket_t (_curl_opensocket_callback1) + (void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback2) + (void *, curlsocktype, const struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback3) + (const void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback4) + (const void *, curlsocktype, const struct curl_sockaddr *); + +/* evaluates to true if expr is of type curl_progress_callback or "similar" */ +#define _curl_is_progress_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \ + _curl_callback_compatible((expr), _curl_progress_callback1) || \ + _curl_callback_compatible((expr), _curl_progress_callback2)) +typedef int (_curl_progress_callback1)(void *, + double, double, double, double); +typedef int (_curl_progress_callback2)(const void *, + double, double, double, double); + +/* evaluates to true if expr is of type curl_debug_callback or "similar" */ +#define _curl_is_debug_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \ + _curl_callback_compatible((expr), _curl_debug_callback1) || \ + _curl_callback_compatible((expr), _curl_debug_callback2) || \ + _curl_callback_compatible((expr), _curl_debug_callback3) || \ + _curl_callback_compatible((expr), _curl_debug_callback4) || \ + _curl_callback_compatible((expr), _curl_debug_callback5) || \ + _curl_callback_compatible((expr), _curl_debug_callback6) || \ + _curl_callback_compatible((expr), _curl_debug_callback7) || \ + _curl_callback_compatible((expr), _curl_debug_callback8)) +typedef int (_curl_debug_callback1) (CURL *, + curl_infotype, char *, size_t, void *); +typedef int (_curl_debug_callback2) (CURL *, + curl_infotype, char *, size_t, const void *); +typedef int (_curl_debug_callback3) (CURL *, + curl_infotype, const char *, size_t, void *); +typedef int (_curl_debug_callback4) (CURL *, + curl_infotype, const char *, size_t, const void *); +typedef int (_curl_debug_callback5) (CURL *, + curl_infotype, unsigned char *, size_t, void *); +typedef int (_curl_debug_callback6) (CURL *, + curl_infotype, unsigned char *, size_t, const void *); +typedef int (_curl_debug_callback7) (CURL *, + curl_infotype, const unsigned char *, size_t, void *); +typedef int (_curl_debug_callback8) (CURL *, + curl_infotype, const unsigned char *, size_t, const void *); + +/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ +/* this is getting even messier... */ +#define _curl_is_ssl_ctx_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) +typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *); +typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *); +#ifdef HEADER_SSL_H +/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX + * this will of course break if we're included before OpenSSL headers... + */ +typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); +typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, + const void *); +#else +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; +#endif + +/* evaluates to true if expr is of type curl_conv_callback or "similar" */ +#define _curl_is_conv_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \ + _curl_callback_compatible((expr), _curl_conv_callback1) || \ + _curl_callback_compatible((expr), _curl_conv_callback2) || \ + _curl_callback_compatible((expr), _curl_conv_callback3) || \ + _curl_callback_compatible((expr), _curl_conv_callback4)) +typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); +typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); +typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); +typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); + +/* evaluates to true if expr is of type curl_seek_callback or "similar" */ +#define _curl_is_seek_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \ + _curl_callback_compatible((expr), _curl_seek_callback1) || \ + _curl_callback_compatible((expr), _curl_seek_callback2)) +typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); +typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); + + +#endif /* __CURL_TYPECHECK_GCC_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/ShareInfo.h b/石器时代8.5客户端最新源代码/石器源码/detours/ShareInfo.h new file mode 100644 index 0000000..2baaccd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/ShareInfo.h @@ -0,0 +1,8 @@ +typedef struct +{ + GUID StartGuid; + DWORD dwPluginCookie; + DWORD dwLevel; + HANDLE hEvent; + +}PIPE_INFO; \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/creatwth.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/creatwth.cpp new file mode 100644 index 0000000..671b7e6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/creatwth.cpp @@ -0,0 +1,1361 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Create a process with a DLL (creatwth.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#include +#include +#if (_MSC_VER < 1299) +typedef DWORD DWORD_PTR; +#endif +#if (_MSC_VER < 1310) +#else +#include +#endif + +// #define DETOUR_DEBUG 1 +// #define IGNORE_CHECKSUMS 1 +#define DETOURS_INTERNAL + +#include "detours.h" + +#define IMPORT_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] +#define BOUND_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT] +#define CLR_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] +#define IAT_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] + +////////////////////////////////////////////////////////////////////////////// +// +#ifndef _STRSAFE_H_INCLUDED_ +static inline HRESULT StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch) +{ + HRESULT hr = S_OK; + size_t cchMaxPrev = cchMax; + + if (cchMax > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + while (cchMax && (*psz != '\0')) + { + psz++; + cchMax--; + } + + if (cchMax == 0) + { + // the string is longer than cchMax + hr = ERROR_INVALID_PARAMETER; + } + + if (SUCCEEDED(hr) && pcch) + { + *pcch = cchMaxPrev - cchMax; + } + + return hr; +} + +static inline HRESULT StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr = S_OK; + + if (cchDest == 0) + { + // can not null terminate a zero-byte dest buffer + hr = ERROR_INVALID_PARAMETER; + } + else + { + while (cchDest && (*pszSrc != '\0')) + { + *pszDest++ = *pszSrc++; + cchDest--; + } + + if (cchDest == 0) + { + // we are going to truncate pszDest + pszDest--; + hr = ERROR_INVALID_PARAMETER; + } + + *pszDest= '\0'; + } + + return hr; +} + +static inline HRESULT StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr; + size_t cchDestCurrent; + + if (cchDest > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + hr = StringCchLengthA(pszDest, cchDest, &cchDestCurrent); + + if (SUCCEEDED(hr)) + { + hr = StringCchCopyA(pszDest + cchDestCurrent, + cchDest - cchDestCurrent, + pszSrc); + } + + return hr; +} + +#endif + +////////////////////////////////////////////////////////////////////////////// +// +#if IGNORE_CHECKSUMS +static WORD detour_sum_minus(WORD wSum, WORD wMinus) +{ + wSum = (WORD)(wSum - ((wSum < wMinus) ? 1 : 0)); + wSum = (WORD)(wSum - wMinus); + return wSum; +} + +static WORD detour_sum_done(DWORD PartialSum) +{ + // Fold final carry into a single word result and return the resultant value. + return (WORD)(((PartialSum >> 16) + PartialSum) & 0xffff); +} + +static WORD detour_sum_data(DWORD dwSum, PBYTE pbData, DWORD cbData) +{ + while (cbData > 0) { + dwSum += *((PWORD&)pbData)++; + dwSum = (dwSum >> 16) + (dwSum & 0xffff); + cbData -= sizeof(WORD); + } + return detour_sum_done(dwSum); +} + +static WORD detour_sum_final(WORD wSum, PIMAGE_NT_HEADERS pinh) +{ + DETOUR_TRACE((".... : %08x (value: %08x)\n", wSum, pinh->OptionalHeader.CheckSum)); + + // Subtract the two checksum words in the optional header from the computed. + wSum = detour_sum_minus(wSum, ((PWORD)(&pinh->OptionalHeader.CheckSum))[0]); + wSum = detour_sum_minus(wSum, ((PWORD)(&pinh->OptionalHeader.CheckSum))[1]); + + return wSum; +} + +static WORD ChkSumRange(WORD wSum, HANDLE hProcess, PBYTE pbBeg, PBYTE pbEnd) +{ + BYTE rbPage[4096]; + + while (pbBeg < pbEnd) { + if (!ReadProcessMemory(hProcess, pbBeg, rbPage, sizeof(rbPage), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(chk@%p..%p) failed: %d\n", + pbBeg, pbEnd, GetLastError())); + break; + } + wSum = detour_sum_data(wSum, rbPage, sizeof(rbPage)); + pbBeg += sizeof(rbPage); + } + return wSum; +} + +static WORD ComputeChkSum(HANDLE hProcess, PBYTE pbModule, PIMAGE_NT_HEADERS pinh) +{ + // See LdrVerifyMappedImageMatchesChecksum. + + MEMORY_BASIC_INFORMATION mbi; + ZeroMemory(&mbi, sizeof(mbi)); + WORD wSum = 0; + + PBYTE pbLast = pbModule; + for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { + ZeroMemory(&mbi, sizeof(mbi)); + if (VirtualQueryEx(hProcess, (PVOID)pbLast, &mbi, sizeof(mbi)) == 0) { + if (GetLastError() == ERROR_INVALID_PARAMETER) { + break; + } + DETOUR_TRACE(("VirtualQueryEx(%p) failed: %d\n", + pbLast, GetLastError())); + break; + } + + if (mbi.AllocationBase != pbModule) { + break; + } + + wSum = ChkSumRange(wSum, + hProcess, + (PBYTE)mbi.BaseAddress, + (PBYTE)mbi.BaseAddress + mbi.RegionSize); + + DETOUR_TRACE(("[%p..%p] : %04x\n", + (PBYTE)mbi.BaseAddress, + (PBYTE)mbi.BaseAddress + mbi.RegionSize, + wSum)); + } + + return detour_sum_final(wSum, pinh); +} +#endif // IGNORE_CHECKSUMS + +////////////////////////////////////////////////////////////////////////////// +// +// Enumate through modules in the target process. +// +static HMODULE WINAPI EnumerateModulesInProcess(HANDLE hProcess, + HMODULE hModuleLast, + PIMAGE_NT_HEADERS32 pNtHeader) +{ + PBYTE pbLast; + + if (hModuleLast == NULL) { + pbLast = (PBYTE)0x10000; + } + else { + pbLast = (PBYTE)hModuleLast + 0x10000; + } + + MEMORY_BASIC_INFORMATION mbi; + ZeroMemory(&mbi, sizeof(mbi)); + + // Find the next memory region that contains a mapped PE image. + // + + for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { + if (VirtualQueryEx(hProcess, (PVOID)pbLast, &mbi, sizeof(mbi)) == 0) { + break; + } + if ((mbi.RegionSize & 0xfff) == 0xfff) { + break; + } + if (((PBYTE)mbi.BaseAddress + mbi.RegionSize) < pbLast) { + break; + } + + // Skip uncommitted regions and guard pages. + // + if ((mbi.State != MEM_COMMIT) || + ((mbi.Protect & 0xff) == PAGE_NOACCESS) || + (mbi.Protect & PAGE_GUARD)) { + continue; + } + + __try { + IMAGE_DOS_HEADER idh; + if (!ReadProcessMemory(hProcess, pbLast, &idh, sizeof(idh), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(idh@%p..%p) failed: %d\n", + pbLast, pbLast + sizeof(idh), GetLastError())); + continue; + } + + if (idh.e_magic != IMAGE_DOS_SIGNATURE || + (DWORD)idh.e_lfanew > mbi.RegionSize || + (DWORD)idh.e_lfanew < sizeof(idh)) { + continue; + } + + if (!ReadProcessMemory(hProcess, pbLast + idh.e_lfanew, + pNtHeader, sizeof(*pNtHeader), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p:%p) failed: %d\n", + pbLast + idh.e_lfanew, + pbLast + idh.e_lfanew + sizeof(*pNtHeader), + pbLast, + GetLastError())); + continue; + } + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + continue; + } + + return (HMODULE)pbLast; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + continue; + } + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////////// +// +// Find a region of memory in which we can create a replacement import table. +// +static PBYTE FindAndAllocateNearBase(HANDLE hProcess, PBYTE pbBase, DWORD cbAlloc) +{ + MEMORY_BASIC_INFORMATION mbi; + ZeroMemory(&mbi, sizeof(mbi)); + + PBYTE pbLast = pbBase; + for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { + + ZeroMemory(&mbi, sizeof(mbi)); + if (VirtualQueryEx(hProcess, (PVOID)pbLast, &mbi, sizeof(mbi)) == 0) { + if (GetLastError() == ERROR_INVALID_PARAMETER) { + break; + } + DETOUR_TRACE(("VirtualQueryEx(%p) failed: %d\n", + pbLast, GetLastError())); + break; + } + if ((mbi.RegionSize & 0xfff) == 0xfff) { + break; + } + + // Skip anything other than a pure free region. + // + if (mbi.State != MEM_FREE) { + continue; + } + + PBYTE pbAddress = (PBYTE)(((DWORD_PTR)mbi.BaseAddress + 0xffff) & ~(DWORD_PTR)0xffff); + + DETOUR_TRACE(("Free region %p..%p\n", + mbi.BaseAddress, + (PBYTE)mbi.BaseAddress + mbi.RegionSize)); + + for (; pbAddress < (PBYTE)mbi.BaseAddress + mbi.RegionSize; pbAddress += 0x10000) { + PBYTE pbAlloc = (PBYTE)VirtualAllocEx(hProcess, pbAddress, cbAlloc, + MEM_RESERVE, PAGE_READWRITE); + if (pbAlloc == NULL) { + DETOUR_TRACE(("VirtualAllocEx(%p) failed: %d\n", pbAddress, GetLastError())); + continue; + } + pbAlloc = (PBYTE)VirtualAllocEx(hProcess, pbAddress, cbAlloc, + MEM_COMMIT, PAGE_READWRITE); + if (pbAlloc == NULL) { + DETOUR_TRACE(("VirtualAllocEx(%p) failed: %d\n", pbAddress, GetLastError())); + continue; + } + DETOUR_TRACE(("[%p..%p] Allocated for import table.\n", + pbAlloc, pbAlloc + cbAlloc)); + return pbAlloc; + } + } + return NULL; +} + +static inline DWORD PadToDword(DWORD dw) +{ + return (dw + 3) & ~3u; +} + +static inline DWORD PadToDwordPtr(DWORD dw) +{ + return (dw + 7) & ~7u; +} + +static inline HRESULT ReplaceOptionalSizeA(char* pszDest, + size_t cchDest, + const char* pszSize) +{ + if (cchDest == 0 || pszDest == NULL || pszSize == NULL || + pszSize[0] == '\0' || pszSize[1] == '\0' || pszSize[2] != '\0') { + + // can not write into empty buffer or with string other than two chars. + return ERROR_INVALID_PARAMETER; + } + else { + for (; cchDest >= 2; cchDest--, pszDest++) { + if (pszDest[0] == '?' && pszDest[1] == '?') { + pszDest[0] = pszSize[0]; + pszDest[1] = pszSize[1]; + break; + } + } + } + return S_OK; +} + +////////////////////////////////////////////////////////////////////////////// +// +#if DETOURS_32BIT +#define DWORD_XX DWORD32 +#define IMAGE_NT_HEADERS_XX IMAGE_NT_HEADERS32 +#define IMAGE_NT_OPTIONAL_HDR_MAGIC_XX IMAGE_NT_OPTIONAL_HDR32_MAGIC +#define IMAGE_ORDINAL_FLAG_XX IMAGE_ORDINAL_FLAG32 +#define UPDATE_IMPORTS_XX UpdateImports32 +#define DETOURS_BITS_XX 32 +#include "uimports.cpp" +#undef DETOUR_EXE_RESTORE_FIELD_XX +#undef DWORD_XX +#undef IMAGE_NT_HEADERS_XX +#undef IMAGE_NT_OPTIONAL_HDR_MAGIC_XX +#undef IMAGE_ORDINAL_FLAG_XX +#undef UPDATE_IMPORTS_XX +#endif // DETOURS_32BIT + +#if DETOURS_64BIT +#define DWORD_XX DWORD64 +#define IMAGE_NT_HEADERS_XX IMAGE_NT_HEADERS64 +#define IMAGE_NT_OPTIONAL_HDR_MAGIC_XX IMAGE_NT_OPTIONAL_HDR64_MAGIC +#define IMAGE_ORDINAL_FLAG_XX IMAGE_ORDINAL_FLAG64 +#define UPDATE_IMPORTS_XX UpdateImports64 +#define DETOURS_BITS_XX 64 +#include "uimports.cpp" +#undef DETOUR_EXE_RESTORE_FIELD_XX +#undef DWORD_XX +#undef IMAGE_NT_HEADERS_XX +#undef IMAGE_NT_OPTIONAL_HDR_MAGIC_XX +#undef IMAGE_ORDINAL_FLAG_XX +#undef UPDATE_IMPORTS_XX +#endif // DETOURS_64BIT + +////////////////////////////////////////////////////////////////////////////// +// +#if DETOURS_64BIT + +C_ASSERT(sizeof(IMAGE_NT_HEADERS64) == sizeof(IMAGE_NT_HEADERS32) + 16); + +static BOOL UpdateFrom32To64(HANDLE hProcess, HANDLE hModule, WORD machine) +{ + IMAGE_DOS_HEADER idh; + IMAGE_NT_HEADERS32 inh32; + IMAGE_NT_HEADERS64 inh64; + IMAGE_SECTION_HEADER sects[32]; + PBYTE pbModule = (PBYTE)hModule; + DWORD n; + + ZeroMemory(&inh32, sizeof(inh32)); + ZeroMemory(&inh64, sizeof(inh64)); + ZeroMemory(sects, sizeof(sects)); + + DETOUR_TRACE(("UpdateFrom32To64(%04x)\n", machine)); + //////////////////////////////////////////////////////// Read old headers. + // + if (!ReadProcessMemory(hProcess, pbModule, &idh, sizeof(idh), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(idh@%p..%p) failed: %d\n", + pbModule, pbModule + sizeof(idh), GetLastError())); + return FALSE; + } + DETOUR_TRACE(("ReadProcessMemory(idh@%p..%p)\n", + pbModule, pbModule + sizeof(idh))); + + PBYTE pnh = pbModule + idh.e_lfanew; + if (!ReadProcessMemory(hProcess, pnh, &inh32, sizeof(inh32), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p) failed: %d\n", + pnh, pnh + sizeof(inh32), GetLastError())); + return FALSE; + } + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p)\n", pnh, pnh + sizeof(inh32))); + + if (inh32.FileHeader.NumberOfSections > (sizeof(sects)/sizeof(sects[0]))) { + return FALSE; + } + + PBYTE psects = pnh + + FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + + inh32.FileHeader.SizeOfOptionalHeader; + ULONG cb = inh32.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); + if (!ReadProcessMemory(hProcess, psects, §s, cb, NULL)) { + DETOUR_TRACE(("ReadProcessMemory(ish@%p..%p) failed: %d\n", + psects, psects + cb, GetLastError())); + return FALSE; + } + DETOUR_TRACE(("ReadProcessMemory(ish@%p..%p)\n", psects, psects + cb)); + + ////////////////////////////////////////////////////////// Convert header. + // + inh64.Signature = inh32.Signature; + inh64.FileHeader = inh32.FileHeader; + inh64.FileHeader.Machine = machine; + inh64.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER64); + + inh64.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC; + inh64.OptionalHeader.MajorLinkerVersion = inh32.OptionalHeader.MajorLinkerVersion; + inh64.OptionalHeader.MinorLinkerVersion = inh32.OptionalHeader.MinorLinkerVersion; + inh64.OptionalHeader.SizeOfCode = inh32.OptionalHeader.SizeOfCode; + inh64.OptionalHeader.SizeOfInitializedData = inh32.OptionalHeader.SizeOfInitializedData; + inh64.OptionalHeader.SizeOfUninitializedData = inh32.OptionalHeader.SizeOfUninitializedData; + inh64.OptionalHeader.AddressOfEntryPoint = inh32.OptionalHeader.AddressOfEntryPoint; + inh64.OptionalHeader.BaseOfCode = inh32.OptionalHeader.BaseOfCode; + inh64.OptionalHeader.ImageBase = inh32.OptionalHeader.ImageBase; + inh64.OptionalHeader.SectionAlignment = inh32.OptionalHeader.SectionAlignment; + inh64.OptionalHeader.FileAlignment = inh32.OptionalHeader.FileAlignment; + inh64.OptionalHeader.MajorOperatingSystemVersion + = inh32.OptionalHeader.MajorOperatingSystemVersion; + inh64.OptionalHeader.MinorOperatingSystemVersion + = inh32.OptionalHeader.MinorOperatingSystemVersion; + inh64.OptionalHeader.MajorImageVersion = inh32.OptionalHeader.MajorImageVersion; + inh64.OptionalHeader.MinorImageVersion = inh32.OptionalHeader.MinorImageVersion; + inh64.OptionalHeader.MajorSubsystemVersion = inh32.OptionalHeader.MajorSubsystemVersion; + inh64.OptionalHeader.MinorSubsystemVersion = inh32.OptionalHeader.MinorSubsystemVersion; + inh64.OptionalHeader.Win32VersionValue = inh32.OptionalHeader.Win32VersionValue; + inh64.OptionalHeader.SizeOfImage = inh32.OptionalHeader.SizeOfImage; + inh64.OptionalHeader.SizeOfHeaders = inh32.OptionalHeader.SizeOfHeaders; + inh64.OptionalHeader.CheckSum = inh32.OptionalHeader.CheckSum; + inh64.OptionalHeader.Subsystem = inh32.OptionalHeader.Subsystem; + inh64.OptionalHeader.DllCharacteristics = inh32.OptionalHeader.DllCharacteristics; + inh64.OptionalHeader.SizeOfStackReserve = inh32.OptionalHeader.SizeOfStackReserve; + inh64.OptionalHeader.SizeOfStackCommit = inh32.OptionalHeader.SizeOfStackCommit; + inh64.OptionalHeader.SizeOfHeapReserve = inh32.OptionalHeader.SizeOfHeapReserve; + inh64.OptionalHeader.SizeOfHeapCommit = inh32.OptionalHeader.SizeOfHeapCommit; + inh64.OptionalHeader.LoaderFlags = inh32.OptionalHeader.LoaderFlags; + inh64.OptionalHeader.NumberOfRvaAndSizes = inh32.OptionalHeader.NumberOfRvaAndSizes; + for (n = 0; n < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; n++) { + inh64.OptionalHeader.DataDirectory[n] = inh32.OptionalHeader.DataDirectory[n]; + } + + inh64.IMPORT_DIRECTORY.VirtualAddress = 0; + inh64.IMPORT_DIRECTORY.Size = 0; + + /////////////////////////////////////////////////////// Write new headers. + // + DWORD dwProtect = 0; + if (!VirtualProtectEx(hProcess, pbModule, inh64.OptionalHeader.SizeOfHeaders, + PAGE_EXECUTE_READWRITE, &dwProtect)) { + return FALSE; + } + + if (!WriteProcessMemory(hProcess, pnh, &inh64, sizeof(inh64), NULL)) { + DETOUR_TRACE(("WriteProcessMemory(inh@%p..%p) failed: %d\n", + pnh, pnh + sizeof(inh64), GetLastError())); + return FALSE; + } + DETOUR_TRACE(("WriteProcessMemory(inh@%p..%p)\n", pnh, pnh + sizeof(inh64))); + + psects = pnh + + FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + + inh64.FileHeader.SizeOfOptionalHeader; + cb = inh64.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); + if (!WriteProcessMemory(hProcess, psects, §s, cb, NULL)) { + DETOUR_TRACE(("WriteProcessMemory(ish@%p..%p) failed: %d\n", + psects, psects + cb, GetLastError())); + return FALSE; + } + DETOUR_TRACE(("WriteProcessMemory(ish@%p..%p)\n", psects, psects + cb)); + + DWORD dwOld = 0; + if (!VirtualProtectEx(hProcess, pbModule, inh64.OptionalHeader.SizeOfHeaders, + dwProtect, &dwOld)) { + return FALSE; + } + + return TRUE; +} +#endif // DETOURS_64BIT + +////////////////////////////////////////////////////////////////////////////// +// +BOOL WINAPI DetourUpdateProcessWithDll(HANDLE hProcess, LPCSTR *plpDlls, DWORD nDlls) +{ + // Find the next memory region that contains a mapped PE image. + // + WORD mach32Bit = 0; + WORD mach64Bit = 0; + WORD exe32Bit = 0; + HMODULE hModule = NULL; + HMODULE hLast = NULL; + + for (;;) { + IMAGE_NT_HEADERS32 inh; + + if ((hLast = EnumerateModulesInProcess(hProcess, hLast, &inh)) == NULL) { + break; + } + + DETOUR_TRACE(("%p machine=%04x magic=%04x\n", + hLast, inh.FileHeader.Machine, inh.OptionalHeader.Magic)); + + if ((inh.FileHeader.Characteristics & IMAGE_FILE_DLL) == 0) { + hModule = hLast; + if (inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + exe32Bit = inh.FileHeader.Machine; + } + DETOUR_TRACE(("%p Found EXE\n", hLast)); + } + else { + if (inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + mach32Bit = inh.FileHeader.Machine; + } + else if (inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + mach64Bit = inh.FileHeader.Machine; + } + } + } + DETOUR_TRACE((" mach32Bit=%04x mach64Bit=%04x\n", mach32Bit, mach64Bit)); + + if (hModule == NULL) { + SetLastError(ERROR_INVALID_OPERATION); + return FALSE; + } + + // Save the various headers for DetourRestoreAfterWith. + // + DETOUR_EXE_RESTORE der; + ZeroMemory(&der, sizeof(der)); + der.cb = sizeof(der); + + der.pidh = (PBYTE)hModule; + der.cbidh = sizeof(der.idh); + if (!ReadProcessMemory(hProcess, der.pidh, &der.idh, sizeof(der.idh), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(idh@%p..%p) failed: %d\n", + der.pidh, der.pidh + der.cbidh, GetLastError())); + return FALSE; + } + DETOUR_TRACE(("IDH: %p..%p\n", der.pidh, der.pidh + der.cbidh)); + + // We read the NT header in two passes to get the full size. + // First we read just the Signature and FileHeader. + der.pinh = der.pidh + der.idh.e_lfanew; + der.cbinh = FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader); + if (!ReadProcessMemory(hProcess, der.pinh, &der.inh, der.cbinh, NULL)) { + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p) failed: %d\n", + der.pinh, der.pinh + der.cbinh, GetLastError())); + return FALSE; + } + + // Second we read the OptionalHeader and Section headers. + der.cbinh = (FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + + der.inh.FileHeader.SizeOfOptionalHeader + + der.inh.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER)); +#if DETOURS_64BIT + if (exe32Bit && !mach32Bit) { + // Include the Save the extra 16-bytes that will be overwritten with 64-bit header. + der.cbinh += sizeof(IMAGE_NT_HEADERS64) - sizeof(IMAGE_NT_HEADERS32); + } +#endif // DETOURS_64BIT + + if (der.cbinh > sizeof(der.raw)) { + return FALSE; + } + + if (!ReadProcessMemory(hProcess, der.pinh, &der.inh, der.cbinh, NULL)) { + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p) failed: %d\n", + der.pinh, der.pinh + der.cbinh, GetLastError())); + return FALSE; + } + DETOUR_TRACE(("INH: %p..%p\n", der.pinh, der.pinh + der.cbinh)); + + // Third, we read the CLR header + + if (der.inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (der.inh32.CLR_DIRECTORY.VirtualAddress != 0 && + der.inh32.CLR_DIRECTORY.Size != 0) { + } + DETOUR_TRACE(("CLR32.VirtAddr=%x, CLR.Size=%x\n", + der.inh32.CLR_DIRECTORY.VirtualAddress, + der.inh32.CLR_DIRECTORY.Size)); + + der.pclr = ((PBYTE)hModule) + der.inh32.CLR_DIRECTORY.VirtualAddress; + } + else if (der.inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + if (der.inh64.CLR_DIRECTORY.VirtualAddress != 0 && + der.inh64.CLR_DIRECTORY.Size != 0) { + } + + DETOUR_TRACE(("CLR64.VirtAddr=%x, CLR.Size=%x\n", + der.inh64.CLR_DIRECTORY.VirtualAddress, + der.inh64.CLR_DIRECTORY.Size)); + + der.pclr = ((PBYTE)hModule) + der.inh64.CLR_DIRECTORY.VirtualAddress; + } + + if (der.pclr != 0) { + der.cbclr = sizeof(der.clr); + if (!ReadProcessMemory(hProcess, der.pclr, &der.clr, der.cbclr, NULL)) { + DETOUR_TRACE(("ReadProcessMemory(clr@%p..%p) failed: %d\n", + der.pclr, der.pclr + der.cbclr, GetLastError())); + return FALSE; + } + DETOUR_TRACE(("CLR: %p..%p\n", der.pclr, der.pclr + der.cbclr)); + } + + // Fourth, adjust for a 32-bit WOW64 process. + + if (exe32Bit && mach64Bit) { + if (!der.pclr // Native binary + || (der.clr.Flags & 1) == 0 // Or mixed-mode MSIL + || (der.clr.Flags & 2) != 0) { // Or 32BIT Required MSIL + + mach64Bit = 0; + if (mach32Bit == 0) { + mach32Bit = exe32Bit; + } + } + } + + // Now decide if we can insert the detour. + +#if DETOURS_32BIT + if (!mach32Bit && mach64Bit) { + // 64-bit native or 64-bit managed process. + // + // Can't detour a 64-bit process with 32-bit code. + // Note: This happens for 32-bit PE binaries containing only + // manage code that have been marked as 64-bit ready. + // + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + else if (mach32Bit) { + // 32-bit native or 32-bit managed process on any platform. + if (!UpdateImports32(hProcess, hModule, plpDlls, nDlls)) { + return FALSE; + } + } + else { + // Who knows!? + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } +#endif // DETOURS_32BIT + +#if DETOURS_64BIT + if (mach32Bit) { + // Can't detour a 32-bit process with 64-bit code. + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + else if (exe32Bit && !mach32Bit) { + // Try to convert the 32-bit managed binary to a 64-bit managed binary. + if (!UpdateFrom32To64(hProcess, hModule, mach64Bit)) { + return FALSE; + } + + // 64-bit process from 32-bit managed binary. + if (!UpdateImports64(hProcess, hModule, plpDlls, nDlls)) { + return FALSE; + } + } + else if (mach64Bit) { + // 64-bit native or 64-bit managed process on any platform. + if (!UpdateImports64(hProcess, hModule, plpDlls, nDlls)) { + return FALSE; + } + } + else { + // Who knows!? + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } +#endif // DETOURS_64BIT + + /////////////////////////////////////////////////// Update the CLR header. + // + if (der.pclr != NULL) { + DETOUR_CLR_HEADER clr; + CopyMemory(&clr, &der.clr, sizeof(clr)); + clr.Flags &= 0xfffffffe; // Clear the IL_ONLY flag. + + DWORD dwProtect; + if (!VirtualProtectEx(hProcess, der.pclr, sizeof(clr), PAGE_READWRITE, &dwProtect)) { + DETOUR_TRACE(("VirtualProtectEx(clr) write failed: %d\n", GetLastError())); + return FALSE; + } + + if (!WriteProcessMemory(hProcess, der.pclr, &clr, sizeof(clr), NULL)) { + DETOUR_TRACE(("WriteProcessMemory(clr) failed: %d\n", GetLastError())); + return FALSE; + } + + if (!VirtualProtectEx(hProcess, der.pclr, sizeof(clr), dwProtect, &dwProtect)) { + DETOUR_TRACE(("VirtualProtectEx(clr) restore failed: %d\n", GetLastError())); + return FALSE; + } + DETOUR_TRACE(("CLR: %p..%p\n", der.pclr, der.pclr + der.cbclr)); + +#if DETOURS_64BIT + if (der.clr.Flags & 0x2) { // Is the 32BIT Required Flag set? + // X64 never gets here because the process appears as a WOW64 process. + // However, on IA64, it doesn't appear to be a WOW process. + DETOUR_TRACE(("CLR Requires 32-bit\n", der.pclr, der.pclr + der.cbclr)); + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } +#endif // DETOURS_64BIT + } + + //////////////////////////////// Save the undo data to the target process. + // + if (!DetourCopyPayloadToProcess(hProcess, DETOUR_EXE_RESTORE_GUID, &der, sizeof(der))) { + DETOUR_TRACE(("DetourCopyPayloadToProcess failed: %d\n", GetLastError())); + return FALSE; + } + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////// +// +BOOL WINAPI DetourCreateProcessWithDllA(LPCSTR lpApplicationName, + __in_z LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA) +{ + DWORD dwMyCreationFlags = (dwCreationFlags | CREATE_SUSPENDED); + PROCESS_INFORMATION pi; + + if (pfCreateProcessA == NULL) { + pfCreateProcessA = CreateProcessA; + } + + if (!pfCreateProcessA(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwMyCreationFlags, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + &pi)) { + return FALSE; + } + + LPCSTR rlpDlls[2]; + DWORD nDlls = 0; + if (lpDllName != NULL) { + rlpDlls[nDlls++] = lpDllName; + } + + if (!DetourUpdateProcessWithDll(pi.hProcess, rlpDlls, nDlls)) { + TerminateProcess(pi.hProcess, ~0u); + return FALSE; + } + + if (lpProcessInformation) { + CopyMemory(lpProcessInformation, &pi, sizeof(pi)); + } + + if (!(dwCreationFlags & CREATE_SUSPENDED)) { + ResumeThread(pi.hThread); + } + return TRUE; +} + + +BOOL WINAPI DetourCreateProcessWithDllW(LPCWSTR lpApplicationName, + __in_z LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW) +{ + DWORD dwMyCreationFlags = (dwCreationFlags | CREATE_SUSPENDED); + PROCESS_INFORMATION pi; + + if (pfCreateProcessW == NULL) { + pfCreateProcessW = CreateProcessW; + } + + if (!pfCreateProcessW(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwMyCreationFlags, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + &pi)) { + return FALSE; + } + + LPCSTR rlpDlls[2]; + DWORD nDlls = 0; + if (lpDllName != NULL) { + rlpDlls[nDlls++] = lpDllName; + } + + if (!DetourUpdateProcessWithDll(pi.hProcess, rlpDlls, nDlls)) { + TerminateProcess(pi.hProcess, ~0u); + return FALSE; + } + + if (lpProcessInformation) { + CopyMemory(lpProcessInformation, &pi, sizeof(pi)); + } + + if (!(dwCreationFlags & CREATE_SUSPENDED)) { + ResumeThread(pi.hThread); + } + return TRUE; +} + +BOOL WINAPI DetourCopyPayloadToProcess(HANDLE hProcess, + REFGUID rguid, + PVOID pData, + DWORD cbData) +{ + DWORD cbTotal = (sizeof(IMAGE_DOS_HEADER) + + sizeof(IMAGE_NT_HEADERS) + + sizeof(IMAGE_SECTION_HEADER) + + sizeof(DETOUR_SECTION_HEADER) + + sizeof(DETOUR_SECTION_RECORD) + + cbData); + + PBYTE pbBase = (PBYTE)VirtualAllocEx(hProcess, NULL, cbTotal, + MEM_COMMIT, PAGE_READWRITE); + if (pbBase == NULL) { + DETOUR_TRACE(("VirtualAllocEx(%d) failed: %d\n", cbTotal, GetLastError())); + return FALSE; + } + + PBYTE pbTarget = pbBase; + IMAGE_DOS_HEADER idh; + IMAGE_NT_HEADERS inh; + IMAGE_SECTION_HEADER ish; + DETOUR_SECTION_HEADER dsh; + DETOUR_SECTION_RECORD dsr; + SIZE_T cbWrote = 0; + + ZeroMemory(&idh, sizeof(idh)); + idh.e_magic = IMAGE_DOS_SIGNATURE; + idh.e_lfanew = sizeof(idh); + if (!WriteProcessMemory(hProcess, pbTarget, &idh, sizeof(idh), &cbWrote) || + cbWrote != sizeof(idh)) { + DETOUR_TRACE(("WriteProcessMemory(idh) failed: %d\n", GetLastError())); + return FALSE; + } + pbTarget += sizeof(idh); + + ZeroMemory(&inh, sizeof(inh)); + inh.Signature = IMAGE_NT_SIGNATURE; + inh.FileHeader.SizeOfOptionalHeader = sizeof(inh.OptionalHeader); + inh.FileHeader.Characteristics = IMAGE_FILE_DLL; + inh.FileHeader.NumberOfSections = 1; + inh.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; + if (!WriteProcessMemory(hProcess, pbTarget, &inh, sizeof(inh), &cbWrote) || + cbWrote != sizeof(inh)) { + return FALSE; + } + pbTarget += sizeof(inh); + + ZeroMemory(&ish, sizeof(ish)); + memcpy(ish.Name, ".detour", sizeof(ish.Name)); + ish.VirtualAddress = (DWORD)((pbTarget + sizeof(ish)) - pbBase); + ish.SizeOfRawData = (sizeof(DETOUR_SECTION_HEADER) + + sizeof(DETOUR_SECTION_RECORD) + + cbData); + if (!WriteProcessMemory(hProcess, pbTarget, &ish, sizeof(ish), &cbWrote) || + cbWrote != sizeof(ish)) { + return FALSE; + } + pbTarget += sizeof(ish); + + ZeroMemory(&dsh, sizeof(dsh)); + dsh.cbHeaderSize = sizeof(dsh); + dsh.nSignature = DETOUR_SECTION_HEADER_SIGNATURE; + dsh.nDataOffset = sizeof(DETOUR_SECTION_HEADER); + dsh.cbDataSize = (sizeof(DETOUR_SECTION_HEADER) + + sizeof(DETOUR_SECTION_RECORD) + + cbData); + if (!WriteProcessMemory(hProcess, pbTarget, &dsh, sizeof(dsh), &cbWrote) || + cbWrote != sizeof(dsh)) { + return FALSE; + } + pbTarget += sizeof(dsh); + + ZeroMemory(&dsr, sizeof(dsr)); + dsr.cbBytes = cbData + sizeof(DETOUR_SECTION_RECORD); + dsr.nReserved = 0; + dsr.guid = rguid; + if (!WriteProcessMemory(hProcess, pbTarget, &dsr, sizeof(dsr), &cbWrote) || + cbWrote != sizeof(dsr)) { + return FALSE; + } + pbTarget += sizeof(dsr); + + if (!WriteProcessMemory(hProcess, pbTarget, pData, cbData, &cbWrote) || + cbWrote != cbData) { + return FALSE; + } + pbTarget += cbData; + + DETOUR_TRACE(("Copied %d byte payload into target process at %p\n", + cbTotal, pbTarget - cbTotal)); + return TRUE; +} + +static BOOL fSearchedForHelper = FALSE; +static PDETOUR_EXE_HELPER pHelper = NULL; + +VOID CALLBACK DetourFinishHelperProcess(HWND, HINSTANCE, LPSTR, INT) +{ + HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pHelper->pid); + if (hProcess == NULL) { + DETOUR_TRACE(("OpenProcess(pid=%d) failed: %d\n", + pHelper->pid, GetLastError())); + ExitProcess(9901); + } + + PCSTR pszModule = pHelper->DllName; + if (!DetourUpdateProcessWithDll(hProcess, &pszModule, 1)) { + DETOUR_TRACE(("DetourUpdateProcessWithDll(pid=%d) failed: %d\n", + pHelper->pid, GetLastError())); + ExitProcess(9902); + } +} + +BOOL WINAPI DetourIsHelperProcess(VOID) +{ + PVOID pvData; + DWORD cbData; + + if (fSearchedForHelper) { + return (pHelper != NULL); + } + + fSearchedForHelper = TRUE; + pvData = DetourFindPayloadEx(DETOUR_EXE_HELPER_GUID, &cbData); + + if (pvData == NULL || cbData < sizeof(DETOUR_EXE_HELPER)) { + return FALSE; + } + + pHelper = (PDETOUR_EXE_HELPER)pvData; + if (pHelper->cb < sizeof(*pHelper)) { + pHelper = NULL; + return FALSE; + } + + return TRUE; +} + +BOOL WINAPI DetourProcessViaHelperA(DWORD dwTargetPid, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA) +{ + PROCESS_INFORMATION pi; + STARTUPINFOA si; + CHAR szExe[MAX_PATH]; + CHAR szCommand[MAX_PATH]; + DETOUR_EXE_HELPER helper; + + ZeroMemory(&helper, sizeof(helper)); + helper.cb = sizeof(helper); + helper.pid = dwTargetPid; + strcpy_s(helper.DllName, ARRAYSIZE(helper.DllName), lpDllName); + + DWORD nLen = GetEnvironmentVariableA("WINDIR", szExe, ARRAYSIZE(szExe)); + if (nLen == 0 || nLen >= ARRAYSIZE(szExe)) { + return FALSE; + } + +#if DETOURS_OPTION_BITS +#if DETOURS_32BIT + strcat_s(szExe, ARRAYSIZE(szExe), "\\sysnative\\rundll32.exe"); +#else // !DETOURS_32BIT + strcat_s(szExe, ARRAYSIZE(szExe), "\\syswow64\\rundll32.exe"); +#endif // !DETOURS_32BIT + + PCHAR pszDll; + if ((pszDll = strrchr(helper.DllName, '\\')) != NULL) { + pszDll++; + } + else if ((pszDll = strrchr(helper.DllName, ':')) != NULL) { + pszDll++; + } + else { + pszDll = helper.DllName; + } + + // Replace "32." with "64." or "64." with "32." + for (; *pszDll; pszDll++) { +#if DETOURS_32BIT + if (pszDll[0] == '3' && pszDll[1] == '2' && pszDll[2] == '.') { + pszDll[0] = '6'; pszDll[1] = '4'; + break; + } +#else + if (pszDll[0] == '6' && pszDll[1] == '4' && pszDll[2] == '.') { + pszDll[0] = '3'; pszDll[1] = '2'; + break; + } +#endif + } + +#else // DETOURS_OPTIONS_BITS + strcat_s(szExe, ARRAYSIZE(szExe), "\\system32\\rundll32.exe"); +#endif // DETOURS_OPTIONS_BITS + + sprintf_s(szCommand, ARRAYSIZE(szCommand), + "rundll32.exe \"%hs\",#1", helper.DllName); + + ZeroMemory(&pi, sizeof(pi)); + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + if (pfCreateProcessA(szExe, szCommand, NULL, NULL, FALSE, CREATE_SUSPENDED, + NULL, NULL, &si, &pi)) { + + if (!DetourCopyPayloadToProcess(pi.hProcess, + DETOUR_EXE_HELPER_GUID, + &helper, sizeof(helper))) { + DETOUR_TRACE(("DetourCopyPayloadToProcess failed: %d\n", GetLastError())); + TerminateProcess(pi.hProcess, ~0u); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return FALSE; + } + + ResumeThread(pi.hThread); + WaitForSingleObject(pi.hProcess, INFINITE); + + DWORD dwResult = 500; + GetExitCodeProcess(pi.hProcess, &dwResult); + + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + if (dwResult != 0) { + DETOUR_TRACE(("Rundll32.exe failed: result=%d\n", dwResult)); + return FALSE; + } + return TRUE; + } + else { + DETOUR_TRACE(("CreateProcess failed: %d\n", GetLastError())); + return FALSE; + } +} + +BOOL WINAPI DetourProcessViaHelperW(DWORD dwTargetPid, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW) +{ + PROCESS_INFORMATION pi; + STARTUPINFOW si; + WCHAR szExe[MAX_PATH]; + WCHAR szCommand[MAX_PATH]; + DETOUR_EXE_HELPER helper; + + ZeroMemory(&helper, sizeof(helper)); + helper.cb = sizeof(helper); + helper.pid = dwTargetPid; + strcpy_s(helper.DllName, ARRAYSIZE(helper.DllName), lpDllName); + + DWORD nLen = GetEnvironmentVariableW(L"WINDIR", szExe, ARRAYSIZE(szExe)); + if (nLen == 0 || nLen >= ARRAYSIZE(szExe)) { + return FALSE; + } + +#if DETOURS_OPTION_BITS +#if DETOURS_32BIT + wcscat_s(szExe, ARRAYSIZE(szExe), L"\\sysnative\\rundll32.exe"); +#else // !DETOURS_32BIT + wcscat_s(szExe, ARRAYSIZE(szExe), L"\\syswow64\\rundll32.exe"); +#endif // !DETOURS_32BIT + + PCHAR pszDll; + if ((pszDll = strrchr(helper.DllName, '\\')) != NULL) { + pszDll++; + } + else if ((pszDll = strrchr(helper.DllName, ':')) != NULL) { + pszDll++; + } + else { + pszDll = helper.DllName; + } + + // Replace "32." with "64." or "64." with "32." + for (; *pszDll; pszDll++) { +#if DETOURS_32BIT + if (pszDll[0] == '3' && pszDll[1] == '2' && pszDll[2] == '.') { + pszDll[0] = '6'; pszDll[1] = '4'; + break; + } +#else + if (pszDll[0] == '6' && pszDll[1] == '4' && pszDll[2] == '.') { + pszDll[0] = '3'; pszDll[1] = '2'; + break; + } +#endif + } + +#else // DETOURS_OPTIONS_BITS + wcscat_s(szExe, ARRAYSIZE(szExe), L"\\system32\\rundll32.exe"); +#endif // DETOURS_OPTIONS_BITS + + swprintf_s(szCommand, ARRAYSIZE(szCommand), + L"rundll32.exe \"%hs\",#1", helper.DllName); + + ZeroMemory(&pi, sizeof(pi)); + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + if (pfCreateProcessW(szExe, szCommand, NULL, NULL, FALSE, CREATE_SUSPENDED, + NULL, NULL, &si, &pi)) { + + if (!DetourCopyPayloadToProcess(pi.hProcess, + DETOUR_EXE_HELPER_GUID, + &helper, sizeof(helper))) { + DETOUR_TRACE(("DetourCopyPayloadToProcess failed: %d\n", GetLastError())); + TerminateProcess(pi.hProcess, ~0u); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return FALSE; + } + + ResumeThread(pi.hThread); + + ResumeThread(pi.hThread); + WaitForSingleObject(pi.hProcess, INFINITE); + + DWORD dwResult = 500; + GetExitCodeProcess(pi.hProcess, &dwResult); + + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + if (dwResult != 0) { + DETOUR_TRACE(("Rundll32.exe failed: result=%d\n", dwResult)); + return FALSE; + } + return TRUE; + } + else { + DETOUR_TRACE(("CreateProcess failed: %d\n", GetLastError())); + return FALSE; + } +} + +BOOL WINAPI DetourCreateProcessWithDllExA(LPCSTR lpApplicationName, + __in_z LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA + pfCreateProcessA) +{ + if (pfCreateProcessA == NULL) { + pfCreateProcessA = CreateProcessA; + } + + PROCESS_INFORMATION backup; + if (lpProcessInformation == NULL) { + lpProcessInformation = &backup; + ZeroMemory(&backup, sizeof(backup)); + } + + if (!pfCreateProcessA(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags | CREATE_SUSPENDED, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + lpProcessInformation)) { + return FALSE; + } + + LPCSTR szDll = lpDllName; + + if (!DetourUpdateProcessWithDll(lpProcessInformation->hProcess, &szDll, 1) && + !DetourProcessViaHelperA(lpProcessInformation->dwProcessId, + lpDllName, + pfCreateProcessA)) { + + TerminateProcess(lpProcessInformation->hProcess, ~0u); + CloseHandle(lpProcessInformation->hProcess); + CloseHandle(lpProcessInformation->hThread); + return FALSE; + } + + if (!(dwCreationFlags & CREATE_SUSPENDED)) { + ResumeThread(lpProcessInformation->hThread); + } + + if (lpProcessInformation == &backup) { + CloseHandle(lpProcessInformation->hProcess); + CloseHandle(lpProcessInformation->hThread); + } + + return TRUE; +} + +BOOL WINAPI DetourCreateProcessWithDllExW(LPCWSTR lpApplicationName, + __in_z LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW + pfCreateProcessW) +{ + if (pfCreateProcessW == NULL) { + pfCreateProcessW = CreateProcessW; + } + + PROCESS_INFORMATION backup; + if (lpProcessInformation == NULL) { + lpProcessInformation = &backup; + ZeroMemory(&backup, sizeof(backup)); + } + + if (!pfCreateProcessW(lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags | CREATE_SUSPENDED, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + lpProcessInformation)) { + return FALSE; + } + + + LPCSTR sz = lpDllName; + + if (!DetourUpdateProcessWithDll(lpProcessInformation->hProcess, &sz, 1) && + !DetourProcessViaHelperW(lpProcessInformation->dwProcessId, + lpDllName, + pfCreateProcessW)) { + + TerminateProcess(lpProcessInformation->hProcess, ~0u); + CloseHandle(lpProcessInformation->hProcess); + CloseHandle(lpProcessInformation->hThread); + return FALSE; + } + + if (!(dwCreationFlags & CREATE_SUSPENDED)) { + ResumeThread(lpProcessInformation->hThread); + } + + if (lpProcessInformation == &backup) { + CloseHandle(lpProcessInformation->hProcess); + CloseHandle(lpProcessInformation->hThread); + } + return TRUE; +} + +// +///////////////////////////////////////////////////////////////// End of File. diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/detours.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/detours.cpp new file mode 100644 index 0000000..a8e8c59 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/detours.cpp @@ -0,0 +1,1873 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Core Detours Functionality (detours.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +#include + +#if (_MSC_VER < 1299) +#pragma warning(disable: 4710) +#endif + +//#define DETOUR_DEBUG 1 +#define DETOURS_INTERNAL + +#include "detours.h" + +#if defined(DETOURS_X86) +#elif defined(DETOURS_X64) +#elif defined(DETOURS_IA64) +#elif defined(DETOURS_ARM) +#else +#error Must define one of DETOURS_X86, DETOURS_X64, DETOURS_IA64, or DETOURS_ARM +#endif + +#if !defined(DETOURS_32BIT) && !defined(DETOURS_64BIT) +#error Must define one of DETOURS_32BIT or DETOURS_64BIT +#endif + +////////////////////////////////////////////////////////////////////////////// +// +struct _DETOUR_ALIGN +{ + BYTE obTarget : 3; + BYTE obTrampoline : 5; +}; + +C_ASSERT(sizeof(_DETOUR_ALIGN) == 1); + +////////////////////////////////////////////////////////////////////////////// +// +static bool detour_is_imported(PBYTE pbCode, PBYTE pbAddress) +{ + MEMORY_BASIC_INFORMATION mbi; + VirtualQuery((PVOID)pbCode, &mbi, sizeof(mbi)); + __try { + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)mbi.AllocationBase; + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + return false; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + return false; + } + + if (pbAddress >= ((PBYTE)pDosHeader + + pNtHeader->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress) && + pbAddress < ((PBYTE)pDosHeader + + pNtHeader->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress + + pNtHeader->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size)) { + return true; + } + return false; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + return false; + } +} + +///////////////////////////////////////////////////////////////////////// X86. +// +#ifdef DETOURS_X86 + +struct _DETOUR_TRAMPOLINE +{ + BYTE rbCode[30]; // target code + jmp to pbRemain + BYTE cbCode; // size of moved target code. + BYTE cbCodeBreak; // padding to make debugging easier. + BYTE rbRestore[22]; // original target code. + BYTE cbRestore; // size of original target code. + BYTE cbRestoreBreak; // padding to make debugging easier. + _DETOUR_ALIGN rAlign[8]; // instruction alignment array. + PBYTE pbRemain; // first instruction after moved code. [free list] + PBYTE pbDetour; // first instruction of detour function. +}; + +C_ASSERT(sizeof(_DETOUR_TRAMPOLINE) == 72); + +enum { + SIZE_OF_JMP = 5 +}; + +inline PBYTE detour_gen_jmp_immediate(PBYTE pbCode, PBYTE pbJmpVal) +{ + PBYTE pbJmpSrc = pbCode + 5; + *pbCode++ = 0xE9; // jmp +imm32 + *((INT32*&)pbCode)++ = (INT32)(pbJmpVal - pbJmpSrc); + return pbCode; +} + +inline PBYTE detour_gen_jmp_indirect(PBYTE pbCode, PBYTE *ppbJmpVal) +{ + PBYTE pbJmpSrc = pbCode + 6; + *pbCode++ = 0xff; // jmp [+imm32] + *pbCode++ = 0x25; + *((INT32*&)pbCode)++ = (INT32)((PBYTE)ppbJmpVal - pbJmpSrc); + return pbCode; +} + +inline PBYTE detour_gen_brk(PBYTE pbCode, PBYTE pbLimit) +{ + while (pbCode < pbLimit) { + *pbCode++ = 0xcc; // brk; + } + return pbCode; +} + +inline PBYTE detour_skip_jmp(PBYTE pbCode, PVOID *ppGlobals) +{ + if (pbCode == NULL) { + return NULL; + } + if (ppGlobals != NULL) { + *ppGlobals = NULL; + } + + // First, skip over the import vector if there is one. + if (pbCode[0] == 0xff && pbCode[1] == 0x25) { // jmp [imm32] + // Looks like an import alias jump, then get the code it points to. + PBYTE pbTarget = *(PBYTE *)&pbCode[2]; + if (detour_is_imported(pbCode, pbTarget)) { + PBYTE pbNew = *(PBYTE *)pbTarget; + DETOUR_TRACE(("%p->%p: skipped over import table.\n", pbCode, pbNew)); + pbCode = pbNew; + } + } + + // Then, skip over a patch jump + if (pbCode[0] == 0xeb) { // jmp +imm8 + PBYTE pbNew = pbCode + 2 + *(CHAR *)&pbCode[1]; + DETOUR_TRACE(("%p->%p: skipped over short jump.\n", pbCode, pbNew)); + pbCode = pbNew; + + // First, skip over the import vector if there is one. + if (pbCode[0] == 0xff && pbCode[1] == 0x25) { // jmp [imm32] + // Looks like an import alias jump, then get the code it points to. + PBYTE pbTarget = *(PBYTE *)&pbCode[2]; + if (detour_is_imported(pbCode, pbTarget)) { + PBYTE pbNew = *(PBYTE *)pbTarget; + DETOUR_TRACE(("%p->%p: skipped over import table.\n", pbCode, pbNew)); + pbCode = pbNew; + } + } + // Finally, skip over a long jump if it is the target of the patch jump. + else if (pbCode[0] == 0xe9) { // jmp +imm32 + PBYTE pbNew = pbCode + 5 + *(INT32 *)&pbCode[1]; + DETOUR_TRACE(("%p->%p: skipped over long jump.\n", pbCode, pbNew)); + pbCode = pbNew; + } + } + return pbCode; +} + +inline BOOL detour_does_code_end_function(PBYTE pbCode) +{ + if (pbCode[0] == 0xeb || // jmp +imm8 + pbCode[0] == 0xe9 || // jmp +imm32 + pbCode[0] == 0xe0 || // jmp eax + pbCode[0] == 0xc2 || // ret +imm8 + pbCode[0] == 0xc3 || // ret + pbCode[0] == 0xcc) { // brk + return TRUE; + } + else if (pbCode[0] == 0xff && pbCode[1] == 0x25) { // jmp [+imm32] + return TRUE; + } + else if ((pbCode[0] == 0x26 || // jmp es: + pbCode[0] == 0x2e || // jmp cs: + pbCode[0] == 0x36 || // jmp ss: + pbCode[0] == 0xe3 || // jmp ds: + pbCode[0] == 0x64 || // jmp fs: + pbCode[0] == 0x65) && // jmp gs: + pbCode[1] == 0xff && // jmp [+imm32] + pbCode[2] == 0x25) { + return TRUE; + } + return FALSE; +} + +inline ULONG detour_is_code_filler(PBYTE pbCode) +{ + if (pbCode[0] == 0x90) { // nop + return 1; + } + return 0; +} + +#endif // DETOURS_X86 + +///////////////////////////////////////////////////////////////////////// X64. +// +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_X64 + +//////////////////////////////////////////////////////////////////////// IA64. +// +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_ARM + +//////////////////////////////////////////////// Trampoline Memory Management. +// +struct DETOUR_REGION +{ + ULONG dwSignature; + DETOUR_REGION * pNext; // Next region in list of regions. + DETOUR_TRAMPOLINE * pFree; // List of free trampolines in this region. +}; +typedef DETOUR_REGION * PDETOUR_REGION; + +const ULONG DETOUR_REGION_SIGNATURE = 'Rrtd'; +const ULONG DETOUR_REGION_SIZE = 0x10000; +const ULONG DETOUR_TRAMPOLINES_PER_REGION = (DETOUR_REGION_SIZE + / sizeof(DETOUR_TRAMPOLINE)) - 1; +static PDETOUR_REGION s_pRegions = NULL; // List of all regions. +static PDETOUR_REGION s_pRegion = NULL; // Default region. + +static void detour_writable_trampoline_regions() +{ + // Mark all of the regions as writable. + for (PDETOUR_REGION pRegion = s_pRegions; pRegion != NULL; pRegion = pRegion->pNext) { + DWORD dwOld; + VirtualProtect(pRegion, DETOUR_REGION_SIZE, PAGE_EXECUTE_READWRITE, &dwOld); + } +} + +static void detour_runnable_trampoline_regions() +{ + HANDLE hProcess = GetCurrentProcess(); + + // Mark all of the regions as executable. + for (PDETOUR_REGION pRegion = s_pRegions; pRegion != NULL; pRegion = pRegion->pNext) { + DWORD dwOld; + VirtualProtect(pRegion, DETOUR_REGION_SIZE, PAGE_EXECUTE_READ, &dwOld); + FlushInstructionCache(hProcess, pRegion, DETOUR_REGION_SIZE); + } +} + +static PBYTE detour_alloc_round_down_to_region(PBYTE pbTry) +{ + // WinXP64 returns free areas that aren't REGION aligned to 32-bit applications. + ULONG_PTR extra = ((ULONG_PTR)pbTry) & (DETOUR_REGION_SIZE - 1); + if (extra != 0) { + pbTry -= extra; + } + return pbTry; +} + +static PBYTE detour_alloc_round_up_to_region(PBYTE pbTry) +{ + // WinXP64 returns free areas that aren't REGION aligned to 32-bit applications. + ULONG_PTR extra = ((ULONG_PTR)pbTry) & (DETOUR_REGION_SIZE - 1); + if (extra != 0) { + ULONG_PTR adjust = DETOUR_REGION_SIZE - extra; + pbTry += adjust; + } + return pbTry; +} + +// Starting at pbLo, try to allocate a memory region, continue until pbHi. + +static PVOID detour_alloc_region_from_lo(PBYTE pbLo, PBYTE pbHi) +{ + PBYTE pbTry = detour_alloc_round_up_to_region(pbLo); + + DETOUR_TRACE((" Looking for free region in %p..%p from %p:\n", pbLo, pbHi, pbTry)); + + for (; pbTry < pbHi;) { + MEMORY_BASIC_INFORMATION mbi; + + if (pbTry >= (PBYTE)(ULONG_PTR)0x50000000 && + pbTry <= (PBYTE)(ULONG_PTR)0x80000000) { + // Skip region reserved for system DLLs. + pbTry = (PBYTE)(ULONG_PTR)(0x80000000 + DETOUR_REGION_SIZE); + continue; + } + + ZeroMemory(&mbi, sizeof(mbi)); + if (!VirtualQuery(pbTry, &mbi, sizeof(mbi))) { + break; + } + + DETOUR_TRACE((" Try %p => %p..%p %6x\n", + pbTry, + mbi.BaseAddress, + (PBYTE)mbi.BaseAddress + mbi.RegionSize - 1, + mbi.State)); + + if (mbi.State == MEM_FREE && mbi.RegionSize >= DETOUR_REGION_SIZE) { + + PVOID pv = VirtualAlloc(pbTry, + DETOUR_REGION_SIZE, + MEM_COMMIT|MEM_RESERVE, + PAGE_EXECUTE_READWRITE); + if (pv != NULL) { + return pv; + } + pbTry += DETOUR_REGION_SIZE; + } + else { + pbTry = detour_alloc_round_up_to_region((PBYTE)mbi.BaseAddress + mbi.RegionSize); + } + } + return NULL; +} + +// Starting at pbHi, try to allocate a memory region, continue until pbLo. + +static PVOID detour_alloc_region_from_hi(PBYTE pbLo, PBYTE pbHi) +{ + PBYTE pbTry = detour_alloc_round_down_to_region(pbHi - DETOUR_REGION_SIZE); + + DETOUR_TRACE((" Looking for free region in %p..%p from %p:\n", pbLo, pbHi, pbTry)); + + for (; pbTry > pbLo;) { + MEMORY_BASIC_INFORMATION mbi; + + DETOUR_TRACE((" Try %p\n", pbTry)); + if (pbTry >= (PBYTE)(ULONG_PTR)0x50000000 && + pbTry <= (PBYTE)(ULONG_PTR)0x80000000) { + // Skip region reserved for system DLLs. + pbTry = (PBYTE)(ULONG_PTR)(0x50000000 - DETOUR_REGION_SIZE); + continue; + } + + ZeroMemory(&mbi, sizeof(mbi)); + if (!VirtualQuery(pbTry, &mbi, sizeof(mbi))) { + break; + } + + DETOUR_TRACE((" Try %p => %p..%p %6x\n", + pbTry, + mbi.BaseAddress, + (PBYTE)mbi.BaseAddress + mbi.RegionSize - 1, + mbi.State)); + + if (mbi.State == MEM_FREE && mbi.RegionSize >= DETOUR_REGION_SIZE) { + + PVOID pv = VirtualAlloc(pbTry, + DETOUR_REGION_SIZE, + MEM_COMMIT|MEM_RESERVE, + PAGE_EXECUTE_READWRITE); + if (pv != NULL) { + return pv; + } + pbTry -= DETOUR_REGION_SIZE; + } + else { + pbTry = detour_alloc_round_down_to_region((PBYTE)mbi.AllocationBase + - DETOUR_REGION_SIZE); + } + } + return NULL; +} + +static PDETOUR_TRAMPOLINE detour_alloc_trampoline(PBYTE pbTarget) +{ + // We have to place trampolines within +/- 2GB of target. + + PDETOUR_TRAMPOLINE pLo = (PDETOUR_TRAMPOLINE) + ((pbTarget > (PBYTE)0x7ff80000) + ? pbTarget - 0x7ff80000 : (PBYTE)(ULONG_PTR)DETOUR_REGION_SIZE); + PDETOUR_TRAMPOLINE pHi = (PDETOUR_TRAMPOLINE) + ((pbTarget < (PBYTE)0xffffffff80000000) + ? pbTarget + 0x7ff80000 : (PBYTE)0xfffffffffff80000); + DETOUR_TRACE(("[%p..%p..%p]\n", pLo, pbTarget, pHi)); + + PDETOUR_TRAMPOLINE pTrampoline = NULL; + + // Insure that there is a default region. + if (s_pRegion == NULL && s_pRegions != NULL) { + s_pRegion = s_pRegions; + } + + // First check the default region for an valid free block. + if (s_pRegion != NULL && s_pRegion->pFree != NULL && + s_pRegion->pFree >= pLo && s_pRegion->pFree <= pHi) { + + found_region: + pTrampoline = s_pRegion->pFree; + // do a last sanity check on region. + if (pTrampoline < pLo || pTrampoline > pHi) { + return NULL; + } + s_pRegion->pFree = (PDETOUR_TRAMPOLINE)pTrampoline->pbRemain; + memset(pTrampoline, 0xcc, sizeof(*pTrampoline)); + return pTrampoline; + } + + // Then check the existing regions for a valid free block. + for (s_pRegion = s_pRegions; s_pRegion != NULL; s_pRegion = s_pRegion->pNext) { + if (s_pRegion != NULL && s_pRegion->pFree != NULL && + s_pRegion->pFree >= pLo && s_pRegion->pFree <= pHi) { + goto found_region; + } + } + + // We need to allocate a new region. + + // Round pbTarget down to 64KB block. + pbTarget = pbTarget - (PtrToUlong(pbTarget) & 0xffff); + + PVOID pbTry = NULL; + + // Try looking 1GB below or lower. + if (pbTry == NULL && pbTarget > (PBYTE)0x40000000) { + pbTry = detour_alloc_region_from_hi((PBYTE)pLo, pbTarget - 0x40000000); + } + // Try looking 1GB above or higher. + if (pbTry == NULL && pbTarget < (PBYTE)0xffffffff40000000) { + pbTry = detour_alloc_region_from_lo(pbTarget + 0x40000000, (PBYTE)pHi); + } + // Try looking 1GB below or higher. + if (pbTry == NULL && pbTarget > (PBYTE)0x40000000) { + pbTry = detour_alloc_region_from_lo(pbTarget - 0x40000000, pbTarget); + } + // Try looking 1GB above or lower. + if (pbTry == NULL && pbTarget < (PBYTE)0xffffffff40000000) { + pbTry = detour_alloc_region_from_hi(pbTarget, pbTarget + 0x40000000); + } + // Try anything below. + if (pbTry == NULL) { + pbTry = detour_alloc_region_from_hi((PBYTE)pLo, pbTarget); + } + // try anything above. + if (pbTry == NULL) { + pbTry = detour_alloc_region_from_lo(pbTarget, (PBYTE)pHi); + } + + if (pbTry != NULL) { + s_pRegion = (DETOUR_REGION*)pbTry; + s_pRegion->dwSignature = DETOUR_REGION_SIGNATURE; + s_pRegion->pFree = NULL; + s_pRegion->pNext = s_pRegions; + s_pRegions = s_pRegion; + DETOUR_TRACE((" Allocated region %p..%p\n\n", + s_pRegion, ((PBYTE)s_pRegion) + DETOUR_REGION_SIZE - 1)); + + // Put everything but the first trampoline on the free list. + PBYTE pFree = NULL; + pTrampoline = ((PDETOUR_TRAMPOLINE)s_pRegion) + 1; + for (int i = DETOUR_TRAMPOLINES_PER_REGION - 1; i > 1; i--) { + pTrampoline[i].pbRemain = pFree; + pFree = (PBYTE)&pTrampoline[i]; + } + s_pRegion->pFree = (PDETOUR_TRAMPOLINE)pFree; + goto found_region; + } + + DETOUR_TRACE(("Couldn't find available memory region!\n")); + return NULL; +} + +static void detour_free_trampoline(PDETOUR_TRAMPOLINE pTrampoline) +{ + PDETOUR_REGION pRegion = (PDETOUR_REGION) + ((ULONG_PTR)pTrampoline & ~(ULONG_PTR)0xffff); + + memset(pTrampoline, 0, sizeof(*pTrampoline)); + pTrampoline->pbRemain = (PBYTE)pRegion->pFree; + pRegion->pFree = pTrampoline; +} + +static BOOL detour_is_region_empty(PDETOUR_REGION pRegion) +{ + // Stop if the region isn't a region (this would be bad). + if (pRegion->dwSignature != DETOUR_REGION_SIGNATURE) { + return FALSE; + } + + PBYTE pbRegionBeg = (PBYTE)pRegion; + PBYTE pbRegionLim = pbRegionBeg + DETOUR_REGION_SIZE; + + // Stop if any of the trampolines aren't free. + PDETOUR_TRAMPOLINE pTrampoline = ((PDETOUR_TRAMPOLINE)pRegion) + 1; + for (int i = 0; i < DETOUR_TRAMPOLINES_PER_REGION; i++) { + if (pTrampoline[i].pbRemain != NULL && + (pTrampoline[i].pbRemain < pbRegionBeg || + pTrampoline[i].pbRemain >= pbRegionLim)) { + return FALSE; + } + } + + // OK, the region is empty. + return TRUE; +} + +static void detour_free_unused_trampoline_regions() +{ + PDETOUR_REGION *ppRegionBase = &s_pRegions; + PDETOUR_REGION pRegion = s_pRegions; + + while (pRegion != NULL) { + if (detour_is_region_empty(pRegion)) { + *ppRegionBase = pRegion->pNext; + + VirtualFree(pRegion, 0, MEM_RELEASE); + s_pRegion = NULL; + } + else { + ppRegionBase = &pRegion->pNext; + } + pRegion = *ppRegionBase; + } +} + +///////////////////////////////////////////////////////// Transaction Structs. +// +struct DetourThread +{ + DetourThread * pNext; + HANDLE hThread; +}; + +struct DetourOperation +{ + DetourOperation * pNext; + BOOL fIsRemove; + PBYTE * ppbPointer; + PBYTE pbTarget; + PDETOUR_TRAMPOLINE pTrampoline; + ULONG dwPerm; +}; + +static BOOL s_fIgnoreTooSmall = FALSE; +static BOOL s_fRetainRegions = FALSE; + +static LONG s_nPendingThreadId = 0; // Thread owning pending transaction. +static LONG s_nPendingError = NO_ERROR; +static PVOID * s_ppPendingError = NULL; +static DetourThread * s_pPendingThreads = NULL; +static DetourOperation * s_pPendingOperations = NULL; + +////////////////////////////////////////////////////////////////////////////// +// +PVOID WINAPI DetourCodeFromPointer(PVOID pPointer, PVOID *ppGlobals) +{ + return detour_skip_jmp((PBYTE)pPointer, ppGlobals); +} + +//////////////////////////////////////////////////////////// Transaction APIs. +// +BOOL WINAPI DetourSetIgnoreTooSmall(BOOL fIgnore) +{ + BOOL fPrevious = s_fIgnoreTooSmall; + s_fIgnoreTooSmall = fIgnore; + return fPrevious; +} + +BOOL WINAPI DetourSetRetainRegions(BOOL fRetain) +{ + BOOL fPrevious = s_fRetainRegions; + s_fRetainRegions = fRetain; + return fPrevious; +} + +LONG WINAPI DetourTransactionBegin() +{ + // Only one transaction is allowed at a time. + if (s_nPendingThreadId != 0) { + return ERROR_INVALID_OPERATION; + } + // Make sure only one thread can start a transaction. + if (InterlockedCompareExchange(&s_nPendingThreadId, (LONG)GetCurrentThreadId(), 0) != 0) { + return ERROR_INVALID_OPERATION; + } + + s_pPendingOperations = NULL; + s_pPendingThreads = NULL; + s_nPendingError = NO_ERROR; + s_ppPendingError = NULL; + + // Make sure the trampoline pages are writable. + detour_writable_trampoline_regions(); + + return NO_ERROR; +} + +LONG WINAPI DetourTransactionAbort() +{ + if (s_nPendingThreadId != (LONG)GetCurrentThreadId()) { + return ERROR_INVALID_OPERATION; + } + + // Restore all of the page permissions. + for (DetourOperation *o = s_pPendingOperations; o != NULL;) { + // We don't care if this fails, because the code is still accessible. + DWORD dwOld; + VirtualProtect(o->pbTarget, o->pTrampoline->cbRestore, + o->dwPerm, &dwOld); + + if (!o->fIsRemove) { + if (o->pTrampoline) { + detour_free_trampoline(o->pTrampoline); + o->pTrampoline = NULL; + } + } + + DetourOperation *n = o->pNext; + delete o; + o = n; + } + s_pPendingOperations = NULL; + + // Make sure the trampoline pages are no longer writable. + detour_runnable_trampoline_regions(); + + // Resume any suspended threads. + for (DetourThread *t = s_pPendingThreads; t != NULL;) { + // There is nothing we can do if this fails. + ResumeThread(t->hThread); + + DetourThread *n = t->pNext; + delete t; + t = n; + } + s_pPendingThreads = NULL; + s_nPendingThreadId = 0; + + return NO_ERROR; +} + +LONG WINAPI DetourTransactionCommit() +{ + return DetourTransactionCommitEx(NULL); +} + +static BYTE detour_align_from_trampoline(PDETOUR_TRAMPOLINE pTrampoline, BYTE obTrampoline) +{ + for (LONG n = 0; n < ARRAYSIZE(pTrampoline->rAlign); n++) { + if (pTrampoline->rAlign[n].obTrampoline == obTrampoline) { + return pTrampoline->rAlign[n].obTarget; + } + } + return 0; +} + +static LONG detour_align_from_target(PDETOUR_TRAMPOLINE pTrampoline, LONG obTarget) +{ + for (LONG n = 0; n < ARRAYSIZE(pTrampoline->rAlign); n++) { + if (pTrampoline->rAlign[n].obTarget == obTarget) { + return pTrampoline->rAlign[n].obTrampoline; + } + } + return 0; +} + +LONG WINAPI DetourTransactionCommitEx(PVOID **pppFailedPointer) +{ + if (pppFailedPointer != NULL) { + // Used to get the last error. + *pppFailedPointer = s_ppPendingError; + } + if (s_nPendingThreadId != (LONG)GetCurrentThreadId()) { + return ERROR_INVALID_OPERATION; + } + + // If any of the pending operations failed, then we abort the whole transaction. + if (s_nPendingError != NO_ERROR) { + DETOUR_BREAK(); + DetourTransactionAbort(); + return s_nPendingError; + } + + // Common variables. + DetourOperation *o; + DetourThread *t; + BOOL freed = FALSE; + + // Insert or remove each of the detours. + for (o = s_pPendingOperations; o != NULL; o = o->pNext) { + if (o->fIsRemove) { + CopyMemory(o->pbTarget, + o->pTrampoline->rbRestore, + o->pTrampoline->cbRestore); +#ifdef DETOURS_IA64 +#error Feature not supported in this release. +#endif // DETOURS_IA64 + +#ifdef DETOURS_X86 + *o->ppbPointer = o->pbTarget; +#endif // DETOURS_X86 + +#ifdef DETOURS_X64 +#error Feature not supported in this release. +#endif // DETOURS_X64 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. +#endif // DETOURS_ARM + } + else { + DETOUR_TRACE(("detours: pbTramp =%p, pbRemain=%p, pbDetour=%p, cbRestore=%d\n", + o->pTrampoline, + o->pTrampoline->pbRemain, + o->pTrampoline->pbDetour, + o->pTrampoline->cbRestore)); + + DETOUR_TRACE(("detours: pbTarget=%p: " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x [before]\n", + o->pbTarget, + o->pbTarget[0], o->pbTarget[1], o->pbTarget[2], o->pbTarget[3], + o->pbTarget[4], o->pbTarget[5], o->pbTarget[6], o->pbTarget[7], + o->pbTarget[8], o->pbTarget[9], o->pbTarget[10], o->pbTarget[11])); + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + +#endif // DETOURS_IA64 + +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + + +#endif // DETOURS_X64 + +#ifdef DETOURS_X86 + PBYTE pbCode = detour_gen_jmp_immediate(o->pbTarget, o->pTrampoline->pbDetour); + pbCode = detour_gen_brk(pbCode, o->pTrampoline->pbRemain); + *o->ppbPointer = o->pTrampoline->rbCode; +#endif // DETOURS_X86 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + + +#endif // DETOURS_ARM + + DETOUR_TRACE(("detours: pbTarget=%p: " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x [after]\n", + o->pbTarget, + o->pbTarget[0], o->pbTarget[1], o->pbTarget[2], o->pbTarget[3], + o->pbTarget[4], o->pbTarget[5], o->pbTarget[6], o->pbTarget[7], + o->pbTarget[8], o->pbTarget[9], o->pbTarget[10], o->pbTarget[11])); + + DETOUR_TRACE(("detours: pbTramp =%p: " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x\n", + o->pTrampoline, + o->pTrampoline->rbCode[0], o->pTrampoline->rbCode[1], + o->pTrampoline->rbCode[2], o->pTrampoline->rbCode[3], + o->pTrampoline->rbCode[4], o->pTrampoline->rbCode[5], + o->pTrampoline->rbCode[6], o->pTrampoline->rbCode[7], + o->pTrampoline->rbCode[8], o->pTrampoline->rbCode[9], + o->pTrampoline->rbCode[10], o->pTrampoline->rbCode[11])); + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_IA64 + } + } + + // Update any suspended threads. + for (t = s_pPendingThreads; t != NULL; t = t->pNext) { + CONTEXT cxt; + cxt.ContextFlags = CONTEXT_CONTROL; + +#undef DETOURS_EIP +#undef DETOURS_EIP_TYPE + +#ifdef DETOURS_X86 +#define DETOURS_EIP Eip +#define DETOURS_EIP_TYPE DWORD +#endif // DETOURS_X86 + +#ifdef DETOURS_X64 +#error Feature not supported in this release. + +#endif // DETOURS_X64 + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + +#endif // DETOURS_ARM + + if (GetThreadContext(t->hThread, &cxt)) { + for (DetourOperation *o = s_pPendingOperations; o != NULL; o = o->pNext) { + if (o->fIsRemove) { + if (cxt.DETOURS_EIP >= (DETOURS_EIP_TYPE)(ULONG_PTR)o->pTrampoline && + cxt.DETOURS_EIP < (DETOURS_EIP_TYPE)((ULONG_PTR)o->pTrampoline + + sizeof(o->pTrampoline)) + ) { + + cxt.DETOURS_EIP = (DETOURS_EIP_TYPE) + ((ULONG_PTR)o->pbTarget + + detour_align_from_trampoline(o->pTrampoline, + (BYTE)(cxt.DETOURS_EIP + - (DETOURS_EIP_TYPE)(ULONG_PTR) + o->pTrampoline))); + + SetThreadContext(t->hThread, &cxt); + } + } + else { + if (cxt.DETOURS_EIP >= (DETOURS_EIP_TYPE)(ULONG_PTR)o->pbTarget && + cxt.DETOURS_EIP < (DETOURS_EIP_TYPE)((ULONG_PTR)o->pbTarget + + o->pTrampoline->cbRestore) + ) { + + cxt.DETOURS_EIP = (DETOURS_EIP_TYPE) + ((ULONG_PTR)o->pTrampoline + + detour_align_from_target(o->pTrampoline, + (BYTE)(cxt.DETOURS_EIP + - (DETOURS_EIP_TYPE)(ULONG_PTR) + o->pbTarget))); + + SetThreadContext(t->hThread, &cxt); + } + } + } + } +#undef DETOURS_EIP + } + + // Restore all of the page permissions and flush the icache. + HANDLE hProcess = GetCurrentProcess(); + for (o = s_pPendingOperations; o != NULL;) { + // We don't care if this fails, because the code is still accessible. + DWORD dwOld; + VirtualProtect(o->pbTarget, o->pTrampoline->cbRestore, o->dwPerm, &dwOld); + FlushInstructionCache(hProcess, o->pbTarget, o->pTrampoline->cbRestore); + + if (o->fIsRemove && o->pTrampoline) { + detour_free_trampoline(o->pTrampoline); + o->pTrampoline = NULL; + freed = true; + } + + DetourOperation *n = o->pNext; + delete o; + o = n; + } + s_pPendingOperations = NULL; + + // Free any trampoline regions that are now unused. + if (freed && !s_fRetainRegions) { + detour_free_unused_trampoline_regions(); + } + + // Make sure the trampoline pages are no longer writable. + detour_runnable_trampoline_regions(); + + // Resume any suspended threads. + for (t = s_pPendingThreads; t != NULL;) { + // There is nothing we can do if this fails. + ResumeThread(t->hThread); + + DetourThread *n = t->pNext; + delete t; + t = n; + } + s_pPendingThreads = NULL; + s_nPendingThreadId = 0; + + if (pppFailedPointer != NULL) { + *pppFailedPointer = s_ppPendingError; + } + + return s_nPendingError; +} + +LONG WINAPI DetourUpdateThread(HANDLE hThread) +{ + LONG error; + + // If any of the pending operations failed, then we don't need to do this. + if (s_nPendingError != NO_ERROR) { + return s_nPendingError; + } + + // Silently (and safely) drop any attempt to suspend our own thread. + if (hThread == GetCurrentThread()) { + return NO_ERROR; + } + + DetourThread *t = new DetourThread; + if (t == NULL) { + error = ERROR_NOT_ENOUGH_MEMORY; + fail: + if (t != NULL) { + delete t; + t = NULL; + } + s_nPendingError = error; + s_ppPendingError = NULL; + DETOUR_BREAK(); + return error; + } + + if (SuspendThread(hThread) == (DWORD)-1) { + error = GetLastError(); + DETOUR_BREAK(); + goto fail; + } + + t->hThread = hThread; + t->pNext = s_pPendingThreads; + s_pPendingThreads = t; + + return NO_ERROR; +} + +///////////////////////////////////////////////////////////// Transacted APIs. +// +LONG WINAPI DetourAttach(PVOID *ppPointer, + PVOID pDetour) +{ + return DetourAttachEx(ppPointer, pDetour, NULL, NULL, NULL); +} + +LONG WINAPI DetourAttachEx(PVOID *ppPointer, + PVOID pDetour, + PDETOUR_TRAMPOLINE *ppRealTrampoline, + PVOID *ppRealTarget, + PVOID *ppRealDetour) +{ + LONG error = NO_ERROR; + + if (ppRealTrampoline != NULL) { + *ppRealTrampoline = NULL; + } + if (ppRealTarget != NULL) { + *ppRealTarget = NULL; + } + if (ppRealDetour != NULL) { + *ppRealDetour = NULL; + } + + if (s_nPendingThreadId != (LONG)GetCurrentThreadId()) { + DETOUR_TRACE(("transaction conflict with thread id=%d\n", s_nPendingThreadId)); + return ERROR_INVALID_OPERATION; + } + + // If any of the pending operations failed, then we don't need to do this. + if (s_nPendingError != NO_ERROR) { + DETOUR_TRACE(("pending transaction error=%d\n", s_nPendingError)); + return s_nPendingError; + } + + if (ppPointer == NULL) { + DETOUR_TRACE(("ppPointer is null\n")); + return ERROR_INVALID_HANDLE; + } + if (*ppPointer == NULL) { + error = ERROR_INVALID_HANDLE; + s_nPendingError = error; + s_ppPendingError = ppPointer; + DETOUR_TRACE(("*ppPointer is null (ppPointer=%p)\n", ppPointer)); + DETOUR_BREAK(); + return error; + } + + PBYTE pbTarget = (PBYTE)*ppPointer; + PDETOUR_TRAMPOLINE pTrampoline = NULL; + DetourOperation *o = NULL; + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + +#else // DETOURS_IA64 + pbTarget = (PBYTE)DetourCodeFromPointer(pbTarget, NULL); + pDetour = DetourCodeFromPointer(pDetour, NULL); +#endif // !DETOURS_IA64 + + // Don't follow a jump if its destination is the target function. + // This happens when the detour does nothing other than call the target. + if (pDetour == (PVOID)pbTarget) { + if (s_fIgnoreTooSmall) { + goto stop; + } + else { + DETOUR_BREAK(); + goto fail; + } + } + + if (ppRealTarget != NULL) { + *ppRealTarget = pbTarget; + } + if (ppRealDetour != NULL) { + *ppRealDetour = pDetour; + } + + o = new DetourOperation; + if (o == NULL) { + error = ERROR_NOT_ENOUGH_MEMORY; + fail: + s_nPendingError = error; + DETOUR_BREAK(); + stop: + if (pTrampoline != NULL) { + detour_free_trampoline(pTrampoline); + pTrampoline = NULL; + if (ppRealTrampoline != NULL) { + *ppRealTrampoline = NULL; + } + } + if (o != NULL) { + delete o; + o = NULL; + } + s_ppPendingError = ppPointer; + return error; + } + + pTrampoline = detour_alloc_trampoline(pbTarget); + if (pTrampoline == NULL) { + error = ERROR_NOT_ENOUGH_MEMORY; + DETOUR_BREAK(); + goto fail; + } + + if (ppRealTrampoline != NULL) { + *ppRealTrampoline = pTrampoline; + } + + DETOUR_TRACE(("detours: pbTramp=%p, pDetour=%p\n", pTrampoline, pDetour)); + + memset(pTrampoline->rAlign, 0, sizeof(pTrampoline->rAlign)); + + // Determine the number of movable target instructions. + PBYTE pbSrc = pbTarget; + PBYTE pbTrampoline = pTrampoline->rbCode; + PBYTE pbPool = pbTrampoline + sizeof(pTrampoline->rbCode); + ULONG cbTarget = 0; + ULONG cbJump = SIZE_OF_JMP; + ULONG nAlign = 0; + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif + + while (cbTarget < cbJump) { + PBYTE pbOp = pbSrc; + LONG lExtra = 0; + + DETOUR_TRACE((" DetourCopyInstruction(%p,%p)\n", + pbTrampoline, pbSrc)); + pbSrc = (PBYTE) + DetourCopyInstruction(pbTrampoline, (PVOID*)&pbPool, pbSrc, NULL, &lExtra); + DETOUR_TRACE((" DetourCopyInstruction() = %p (%d bytes)\n", + pbSrc, (int)(pbSrc - pbOp))); + pbTrampoline += (pbSrc - pbOp) + lExtra; + cbTarget = (LONG)(pbSrc - pbTarget); + pTrampoline->rAlign[nAlign].obTarget = cbTarget; + pTrampoline->rAlign[nAlign].obTrampoline = pbTrampoline - pTrampoline->rbCode; + + if (detour_does_code_end_function(pbOp)) { + break; + } + } + + // Consume, but don't duplicate padding if it is needed and available. + while (cbTarget < cbJump) { + LONG cFiller = detour_is_code_filler(pbSrc); + if (cFiller == 0) { + break; + } + + pbSrc += cFiller; + cbTarget = (LONG)(pbSrc - pbTarget); + } + +#if DETOUR_DEBUG + { + DETOUR_TRACE((" detours: rAlign [")); + LONG n = 0; + for (n = 0; n < ARRAYSIZE(pTrampoline->rAlign); n++) { + if (pTrampoline->rAlign[n].obTarget == 0 && + pTrampoline->rAlign[n].obTrampoline == 0) { + break; + } + DETOUR_TRACE((" %d/%d", + pTrampoline->rAlign[n].obTarget, + pTrampoline->rAlign[n].obTrampoline + )); + + } + DETOUR_TRACE((" ]\n")); + } +#endif + + if (cbTarget < cbJump || nAlign > ARRAYSIZE(pTrampoline->rAlign)) { + // Too few instructions. + + error = ERROR_INVALID_BLOCK; + if (s_fIgnoreTooSmall) { + goto stop; + } + else { + DETOUR_BREAK(); + goto fail; + } + } + + if (pbTrampoline > pbPool) { + __debugbreak(); + } + +#if 0 // [GalenH] + if (cbTarget < pbTrampoline - pTrampoline->rbCode) { + __debugbreak(); + } +#endif + + pTrampoline->cbCode = (BYTE)(pbTrampoline - pTrampoline->rbCode); + pTrampoline->cbRestore = (BYTE)cbTarget; + CopyMemory(pTrampoline->rbRestore, pbTarget, cbTarget); + +#if !defined(DETOURS_IA64) + if (cbTarget > sizeof(pTrampoline->rbCode) - cbJump) { + // Too many instructions. + error = ERROR_INVALID_HANDLE; + DETOUR_BREAK(); + goto fail; + } +#endif // !DETOURS_IA64 + + pTrampoline->pbRemain = pbTarget + cbTarget; + pTrampoline->pbDetour = (PBYTE)pDetour; + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_IA64 + + pbTrampoline = pTrampoline->rbCode + pTrampoline->cbCode; +#ifdef DETOURS_X64 +#error Feature not supported in this release. + +#endif // DETOURS_X64 + +#ifdef DETOURS_X86 + pbTrampoline = detour_gen_jmp_immediate(pbTrampoline, pTrampoline->pbRemain); + pbTrampoline = detour_gen_brk(pbTrampoline, pbPool); +#endif // DETOURS_X86 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + +#endif // DETOURS_ARM + + DWORD dwOld = 0; + if (!VirtualProtect(pbTarget, cbTarget, PAGE_EXECUTE_READWRITE, &dwOld)) { + error = GetLastError(); + DETOUR_BREAK(); + goto fail; + } + + DETOUR_TRACE(("detours: pbTarget=%p: " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x\n", + pbTarget, + pbTarget[0], pbTarget[1], pbTarget[2], pbTarget[3], + pbTarget[4], pbTarget[5], pbTarget[6], pbTarget[7], + pbTarget[8], pbTarget[9], pbTarget[10], pbTarget[11])); + DETOUR_TRACE(("detours: pbTramp =%p: " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x\n", + pTrampoline, + pTrampoline->rbCode[0], pTrampoline->rbCode[1], + pTrampoline->rbCode[2], pTrampoline->rbCode[3], + pTrampoline->rbCode[4], pTrampoline->rbCode[5], + pTrampoline->rbCode[6], pTrampoline->rbCode[7], + pTrampoline->rbCode[8], pTrampoline->rbCode[9], + pTrampoline->rbCode[10], pTrampoline->rbCode[11])); + + o->fIsRemove = FALSE; + o->ppbPointer = (PBYTE*)ppPointer; + o->pTrampoline = pTrampoline; + o->pbTarget = pbTarget; + o->dwPerm = dwOld; + o->pNext = s_pPendingOperations; + s_pPendingOperations = o; + + return NO_ERROR; +} + +LONG WINAPI DetourDetach(PVOID *ppPointer, + PVOID pDetour) +{ + LONG error = NO_ERROR; + + if (s_nPendingThreadId != (LONG)GetCurrentThreadId()) { + return ERROR_INVALID_OPERATION; + } + + // If any of the pending operations failed, then we don't need to do this. + if (s_nPendingError != NO_ERROR) { + return s_nPendingError; + } + + if (ppPointer == NULL) { + return ERROR_INVALID_HANDLE; + } + if (*ppPointer == NULL) { + error = ERROR_INVALID_HANDLE; + s_nPendingError = error; + s_ppPendingError = ppPointer; + DETOUR_BREAK(); + return error; + } + + DetourOperation *o = new DetourOperation; + if (o == NULL) { + error = ERROR_NOT_ENOUGH_MEMORY; + fail: + s_nPendingError = error; + DETOUR_BREAK(); + stop: + if (o != NULL) { + delete o; + o = NULL; + } + s_ppPendingError = ppPointer; + return error; + } + + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#else // !DETOURS_IA64 + PDETOUR_TRAMPOLINE pTrampoline = + (PDETOUR_TRAMPOLINE)DetourCodeFromPointer(*ppPointer, NULL); + pDetour = DetourCodeFromPointer(pDetour, NULL); +#endif // !DETOURS_IA64 + + ////////////////////////////////////// Verify that Trampoline is in place. + // + LONG cbTarget = pTrampoline->cbRestore; + PBYTE pbTarget = pTrampoline->pbRemain - cbTarget; + if (cbTarget == 0 || cbTarget > sizeof(pTrampoline->rbCode)) { + error = ERROR_INVALID_BLOCK; + if (s_fIgnoreTooSmall) { + goto stop; + } + else { + DETOUR_BREAK(); + goto fail; + } + } + + if (pTrampoline->pbDetour != pDetour) { + error = ERROR_INVALID_BLOCK; + if (s_fIgnoreTooSmall) { + goto stop; + } + else { + DETOUR_BREAK(); + goto fail; + } + } + + DWORD dwOld = 0; + if (!VirtualProtect(pbTarget, cbTarget, + PAGE_EXECUTE_READWRITE, &dwOld)) { + error = GetLastError(); + DETOUR_BREAK(); + goto fail; + } + + o->fIsRemove = TRUE; + o->ppbPointer = (PBYTE*)ppPointer; + o->pTrampoline = pTrampoline; + o->pbTarget = pbTarget; + o->dwPerm = dwOld; + o->pNext = s_pPendingOperations; + s_pPendingOperations = o; + + return NO_ERROR; +} + +// End of File diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/detours.h b/石器时代8.5客户端最新源代码/石器源码/detours/detours.h new file mode 100644 index 0000000..9bcb2ff --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/detours.h @@ -0,0 +1,629 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Core Detours Functionality (detours.h of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#pragma once +#ifndef _DETOURS_H_ +#define _DETOURS_H_ + +#define DETOURS_VERSION 30000 // 3.00.00 + +#define DETOURS_X86 1 +#define DETOURS_32BIT 1 + +////////////////////////////////////////////////////////////////////////////// +// + +#if (_MSC_VER < 1299) +typedef LONG LONG_PTR; +typedef ULONG ULONG_PTR; +#endif + +#ifndef __in_z +#define __in_z +#endif + +////////////////////////////////////////////////////////////////////////////// +// +#ifndef GUID_DEFINED +#define GUID_DEFINED +typedef struct _GUID +{ + DWORD Data1; + WORD Data2; + WORD Data3; + BYTE Data4[ 8 ]; +} GUID; + +#ifdef INITGUID +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name \ + = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#else +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name +#endif // INITGUID +#endif // !GUID_DEFINED + +#if defined(__cplusplus) +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID & +#endif // !_REFGUID_DEFINED +#else // !__cplusplus +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID * const +#endif // !_REFGUID_DEFINED +#endif // !__cplusplus + +// +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/////////////////////////////////////////////////// Instruction Target Macros. +// +#define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0) +#define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1) +#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0" + +extern const GUID DETOUR_EXE_RESTORE_GUID; +extern const GUID DETOUR_EXE_HELPER_GUID; + +#define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr! +typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE; + +/////////////////////////////////////////////////////////// Binary Structures. +// +#pragma pack(push, 8) +typedef struct _DETOUR_SECTION_HEADER +{ + DWORD cbHeaderSize; + DWORD nSignature; + DWORD nDataOffset; + DWORD cbDataSize; + + DWORD nOriginalImportVirtualAddress; + DWORD nOriginalImportSize; + DWORD nOriginalBoundImportVirtualAddress; + DWORD nOriginalBoundImportSize; + + DWORD nOriginalIatVirtualAddress; + DWORD nOriginalIatSize; + DWORD nOriginalSizeOfImage; + DWORD cbPrePE; + + DWORD nOriginalClrFlags; + DWORD reserved1; + DWORD reserved2; + DWORD reserved3; + + // Followed by cbPrePE bytes of data. +} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER; + +typedef struct _DETOUR_SECTION_RECORD +{ + DWORD cbBytes; + DWORD nReserved; + GUID guid; +} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD; + +typedef struct _DETOUR_CLR_HEADER +{ + // Header versioning + ULONG cb; + USHORT MajorRuntimeVersion; + USHORT MinorRuntimeVersion; + + // Symbol table and startup information + IMAGE_DATA_DIRECTORY MetaData; + ULONG Flags; + + // Followed by the rest of the IMAGE_COR20_HEADER +} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER; + +typedef struct _DETOUR_EXE_RESTORE +{ + DWORD cb; + DWORD cbidh; + DWORD cbinh; + DWORD cbclr; + + PBYTE pidh; + PBYTE pinh; + PBYTE pclr; + + IMAGE_DOS_HEADER idh; + union { + IMAGE_NT_HEADERS inh; + IMAGE_NT_HEADERS32 inh32; + IMAGE_NT_HEADERS64 inh64; + BYTE raw[sizeof(IMAGE_NT_HEADERS64) + + sizeof(IMAGE_SECTION_HEADER) * 32]; + }; + DETOUR_CLR_HEADER clr; + +} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE; + +typedef struct _DETOUR_EXE_HELPER +{ + DWORD cb; + DWORD pid; + CHAR DllName[MAX_PATH]; + +} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER; + +#pragma pack(pop) + +#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \ +{ \ + sizeof(DETOUR_SECTION_HEADER),\ + DETOUR_SECTION_HEADER_SIGNATURE,\ + sizeof(DETOUR_SECTION_HEADER),\ + (cbSectionSize),\ + \ + 0,\ + 0,\ + 0,\ + 0,\ + \ + 0,\ + 0,\ + 0,\ + 0,\ +} + +/////////////////////////////////////////////////////////////// Helper Macros. +// +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x + +///////////////////////////////////////////////////////////// Binary Typedefs. +// +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(PVOID pContext, + PCHAR pszFile, + PCHAR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(PVOID pContext, + PCHAR pszOrigFile, + PCHAR pszFile, + PCHAR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(PVOID pContext, + ULONG nOrigOrdinal, + ULONG nOrdinal, + ULONG *pnOutOrdinal, + PCHAR pszOrigSymbol, + PCHAR pszSymbol, + PCHAR *ppszOutSymbol); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)(PVOID pContext); + +typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(PVOID pContext, + ULONG nOrdinal, + PCHAR pszName, + PVOID pCode); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(PVOID pContext, + HMODULE hModule, + PCSTR pszFile); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(PVOID pContext, + DWORD nOrdinal, + PCSTR pszFunc, + PVOID pvFunc); + +typedef VOID * PDETOUR_BINARY; +typedef VOID * PDETOUR_LOADED_BINARY; + +//////////////////////////////////////////////////////////// Transaction APIs. +// +LONG WINAPI DetourTransactionBegin(VOID); +LONG WINAPI DetourTransactionAbort(VOID); +LONG WINAPI DetourTransactionCommit(VOID); +LONG WINAPI DetourTransactionCommitEx(PVOID **pppFailedPointer); + +LONG WINAPI DetourUpdateThread(HANDLE hThread); + +LONG WINAPI DetourAttach(PVOID *ppPointer, + PVOID pDetour); + +LONG WINAPI DetourAttachEx(PVOID *ppPointer, + PVOID pDetour, + PDETOUR_TRAMPOLINE *ppRealTrampoline, + PVOID *ppRealTarget, + PVOID *ppRealDetour); + +LONG WINAPI DetourDetach(PVOID *ppPointer, + PVOID pDetour); + +BOOL WINAPI DetourSetIgnoreTooSmall(BOOL fIgnore); +BOOL WINAPI DetourSetRetainRegions(BOOL fRetain); + +////////////////////////////////////////////////////////////// Code Functions. +// +PVOID WINAPI DetourFindFunction(PCSTR pszModule, PCSTR pszFunction); +PVOID WINAPI DetourCodeFromPointer(PVOID pPointer, PVOID *ppGlobals); +PVOID WINAPI DetourCopyInstruction(PVOID pDst, + PVOID *pDstPool, + PVOID pSrc, + PVOID *ppTarget, + LONG *plExtra); + +///////////////////////////////////////////////////// Loaded Binary Functions. +// +HMODULE WINAPI DetourGetContainingModule(PVOID pvAddr); +HMODULE WINAPI DetourEnumerateModules(HMODULE hModuleLast); +PVOID WINAPI DetourGetEntryPoint(HMODULE hModule); +ULONG WINAPI DetourGetModuleSize(HMODULE hModule); +BOOL WINAPI DetourEnumerateExports(HMODULE hModule, + PVOID pContext, + PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport); +BOOL WINAPI DetourEnumerateImports(HMODULE hModule, + PVOID pContext, + PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc); + +PVOID WINAPI DetourFindPayload(HMODULE hModule, REFGUID rguid, DWORD *pcbData); +PVOID WINAPI DetourFindPayloadEx(REFGUID rguid, DWORD * pcbData); +DWORD WINAPI DetourGetSizeOfPayloads(HMODULE hModule); + +///////////////////////////////////////////////// Persistent Binary Functions. +// + +PDETOUR_BINARY WINAPI DetourBinaryOpen(HANDLE hFile); +PVOID WINAPI DetourBinaryEnumeratePayloads(PDETOUR_BINARY pBinary, + GUID *pGuid, + DWORD *pcbData, + DWORD *pnIterator); +PVOID WINAPI DetourBinaryFindPayload(PDETOUR_BINARY pBinary, + REFGUID rguid, + DWORD *pcbData); +PVOID WINAPI DetourBinarySetPayload(PDETOUR_BINARY pBinary, + REFGUID rguid, + PVOID pData, + DWORD cbData); +BOOL WINAPI DetourBinaryDeletePayload(PDETOUR_BINARY pBinary, REFGUID rguid); +BOOL WINAPI DetourBinaryPurgePayloads(PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryResetImports(PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryEditImports(PDETOUR_BINARY pBinary, + PVOID pContext, + PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway, + PF_DETOUR_BINARY_FILE_CALLBACK pfFile, + PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol, + PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit); +BOOL WINAPI DetourBinaryWrite(PDETOUR_BINARY pBinary, HANDLE hFile); +BOOL WINAPI DetourBinaryClose(PDETOUR_BINARY pBinary); + +/////////////////////////////////////////////////// Create Process & Load Dll. +// +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA) + (LPCSTR lpApplicationName, + LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation); + +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW) + (LPCWSTR lpApplicationName, + LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation); + +BOOL WINAPI DetourCreateProcessWithDllA(LPCSTR lpApplicationName, + __in_z LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA + pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllW(LPCWSTR lpApplicationName, + __in_z LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW + pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDll DetourCreateProcessWithDllW +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW +#else +#define DetourCreateProcessWithDll DetourCreateProcessWithDllA +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA +#endif // !UNICODE + +BOOL WINAPI DetourCreateProcessWithDllExA(LPCSTR lpApplicationName, + __in_z LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA + pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllExW(LPCWSTR lpApplicationName, + __in_z LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFOW lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW + pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW +#else +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA +#endif // !UNICODE + +BOOL WINAPI DetourProcessViaHelperA(DWORD dwTargetPid, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourProcessViaHelperW(DWORD dwTargetPid, + LPCSTR lpDllName, + PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourProcessViaHelper DetourProcessViaHelperW +#else +#define DetourProcessViaHelper DetourProcessViaHelperA +#endif // !UNICODE + +BOOL WINAPI DetourUpdateProcessWithDll(HANDLE hProcess, + LPCSTR *plpDlls, + DWORD nDlls); + +BOOL WINAPI DetourCopyPayloadToProcess(HANDLE hProcess, + REFGUID rguid, + PVOID pvData, + DWORD cbData); +BOOL WINAPI DetourRestoreAfterWith(VOID); +BOOL WINAPI DetourRestoreAfterWithEx(PVOID pvData, DWORD cbData); +BOOL WINAPI DetourIsHelperProcess(VOID); +VOID CALLBACK DetourFinishHelperProcess(HWND, HINSTANCE, LPSTR, INT); + +// +////////////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +} +#endif // __cplusplus + +//////////////////////////////////////////////// Detours Internal Definitions. +// +#ifdef __cplusplus +#ifdef DETOURS_INTERNAL + +#ifndef __deref_out +#define __deref_out +#endif + +#ifndef __deref +#define __deref +#endif + +////////////////////////////////////////////////////////////////////////////// +// +#if (_MSC_VER < 1299) +#include +typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64; +typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64; +typedef IMAGEHLP_SYMBOL SYMBOL_INFO; +typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO; + +static inline +LONG InterlockedCompareExchange(LONG *ptr, LONG nval, LONG oval) +{ + return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval); +} +#else +#include +#endif + +#ifdef IMAGEAPI // defined by DBGHELP.H +typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(LPAPI_VERSION AppVersion); + +typedef BOOL (NTAPI *PF_SymInitialize)(IN HANDLE hProcess, + IN LPCSTR UserSearchPath, + IN BOOL fInvadeProcess); +typedef DWORD (NTAPI *PF_SymSetOptions)(IN DWORD SymOptions); +typedef DWORD (NTAPI *PF_SymGetOptions)(VOID); +typedef DWORD64 (NTAPI *PF_SymLoadModule64)(IN HANDLE hProcess, + IN HANDLE hFile, + IN PSTR ImageName, + IN PSTR ModuleName, + IN DWORD64 BaseOfDll, + IN DWORD SizeOfDll); +typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(IN HANDLE hProcess, + IN DWORD64 qwAddr, + OUT PIMAGEHLP_MODULE64 ModuleInfo); +typedef BOOL (NTAPI *PF_SymFromName)(IN HANDLE hProcess, + IN LPSTR Name, + OUT PSYMBOL_INFO Symbol); + +typedef struct _DETOUR_SYM_INFO +{ + HANDLE hProcess; + HMODULE hDbgHelp; + PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx; + PF_SymInitialize pfSymInitialize; + PF_SymSetOptions pfSymSetOptions; + PF_SymGetOptions pfSymGetOptions; + PF_SymLoadModule64 pfSymLoadModule64; + PF_SymGetModuleInfo64 pfSymGetModuleInfo64; + PF_SymFromName pfSymFromName; +} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO; + +PDETOUR_SYM_INFO DetourLoadDbgHelp(VOID); + +#endif // IMAGEAPI + +#ifndef DETOUR_TRACE +#if DETOUR_DEBUG +#define DETOUR_TRACE(x) printf x +#define DETOUR_BREAK() __debugbreak() +#include +#include +#else +#define DETOUR_TRACE(x) +#define DETOUR_BREAK() +#endif +#endif + +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + + + +#endif // DETOURS_ARM + +////////////////////////////////////////////////////////////////////////////// + +#endif // DETOURS_INTERNAL +#endif // __cplusplus + +#endif // _DETOURS_H_ +// +//////////////////////////////////////////////////////////////// End of File. diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/detver.h b/石器时代8.5客户端最新源代码/石器源码/detours/detver.h new file mode 100644 index 0000000..bf4a52d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/detver.h @@ -0,0 +1,21 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Common version parameters. +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#ifndef DETOURS_STRINGIFY +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x +#endif + +#define VER_FILEFLAGSMASK 0x3fL +#define VER_FILEFLAGS 0x0L +#define VER_FILEOS 0x00040004L +#define VER_FILETYPE 0x00000002L +#define VER_FILESUBTYPE 0x00000000L + +#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/disasm.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/disasm.cpp new file mode 100644 index 0000000..cd8b942 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/disasm.cpp @@ -0,0 +1,2902 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Detours Disassembler (disasm.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#include +#include + +// #define DETOUR_DEBUG 1 +#define DETOURS_INTERNAL + +#include "detours.h" + +#if defined(DETOURS_X86) +#elif defined(DETOURS_X64) +#elif defined(DETOURS_IA64) +#elif defined(DETOURS_ARM) +#else +#error Must define one of DETOURS_X86, DETOURS_X64, DETOURS_IA64, or DETOURS_ARM +#endif + +#undef ASSERT +#define ASSERT(x) + +////////////////////////////////////////////////////////////////////////////// +// +// Function: +// DetourCopyInstruction(PVOID pDst, +// PVOID *ppDstPool +// PVOID pSrc, +// PVOID *ppTarget, +// LONG *plExtra) +// Purpose: +// Copy a single instruction from pSrc to pDst. +// +// Arguments: +// pDst: +// Destination address for the instruction. May be NULL in which +// case DetourCopyInstruction is used to measure an instruction. +// If not NULL then the source instruction is copied to the +// destination instruction and any relative arguments are adjusted. +// ppDstPool: +// Destination address for the end of the constant pool. The +// constant pool works backwards toward pDst. All memory between +// pDst and *ppDstPool must be available for use by this function. +// ppDstPool may be NULL if pDst is NULL. +// pSrc: +// Source address of the instruction. +// ppTarget: +// Out parameter for any target instruction address pointed to by +// the instruction. For example, a branch or a jump insruction has +// a target, but a load or store instruction doesn't. A target is +// another instruction that may be executed as a result of this +// instruction. ppTarget may be NULL. +// plExtra: +// Out parameter for the number of extra bytes needed by the +// instruction to reach the target. For example, lExtra = 3 if the +// instruction had an 8-bit relative offset, but needs a 32-bit +// relative offset. +// +// Returns: +// Returns the address of the next instruction (following in the source) +// instruction. By subtracting pSrc from the return value, the caller +// can determinte the size of the instruction copied. +// +// Comments: +// By following the pTarget, the caller can follow alternate +// instruction streams. However, it is not always possible to determine +// the target based on static analysis. For example, the destination of +// a jump relative to a register cannot be determined from just the +// instruction stream. The output value, pTarget, can have any of the +// following outputs: +// DETOUR_INSTRUCTION_TARGET_NONE: +// The instruction has no targets. +// DETOUR_INSTRUCTION_TARGET_DYNAMIC: +// The instruction has a non-deterministic (dynamic) target. +// (i.e. the jump is to an address held in a register.) +// Address: The instruction has the specified target. +// +// When copying instructions, DetourCopyInstruction insures that any +// targets remain constant. It does so by adjusting any IP relative +// offsets. +// + +//////////////////////////////////////////////////// X86 and X64 Disassembler. +// +// Includes full support for all x86 chips prior to the Pentium III. +// +#if defined(DETOURS_X64) || defined(DETOURS_X86) + +class CDetourDis +{ + public: + CDetourDis(PBYTE *ppbTarget, LONG *plExtra); + + PBYTE CopyInstruction(PBYTE pbDst, PBYTE pbSrc); + static BOOL SanityCheckSystem(); + + public: + struct COPYENTRY; + typedef const COPYENTRY * REFCOPYENTRY; + + typedef PBYTE (CDetourDis::* COPYFUNC)(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + + enum { + DYNAMIC = 0x1u, + ADDRESS = 0x2u, + NOENLARGE = 0x4u, + RAX = 0x8u, + + SIB = 0x10u, + RIP = 0x20u, + NOTSIB = 0x0fu, + }; + struct COPYENTRY + { + ULONG nOpcode : 8; // Opcode + ULONG nFixedSize : 4; // Fixed size of opcode + ULONG nFixedSize16 : 4; // Fixed size when 16 bit operand + ULONG nModOffset : 4; // Offset to mod/rm byte (0=none) + LONG nRelOffset : 4; // Offset to relative target. + LONG nTargetBack : 4; // Offset back to absolute or rip target + ULONG nFlagBits : 4; // Flags for DYNAMIC, etc. + COPYFUNC pfCopy; // Function pointer. + }; + + protected: + // These macros define common uses of nFixedSize..pfCopy. +#define ENTRY_CopyBytes1 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes1Dynamic 1, 1, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2 2, 2, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2Jump 2, 2, 0, 1, 0, 0, &CDetourDis::CopyBytesJump +#define ENTRY_CopyBytes2CantJump 2, 2, 0, 1, 0, NOENLARGE, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2Dynamic 2, 2, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3 3, 3, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Dynamic 3, 3, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Or5 5, 3, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Or5Rax 5, 3, 0, 0, 0, RAX, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Or5Target 5, 3, 0, 1, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes5Or7Dynamic 7, 5, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Or5Address 5, 3, 0, 0, 0, ADDRESS, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes4 4, 4, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes5 5, 5, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes7 7, 7, 0, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2Mod 2, 2, 1, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2Mod1 3, 3, 1, 0, 1, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes2ModOperand 6, 4, 1, 0, 4, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytes3Mod 3, 3, 2, 0, 0, 0, &CDetourDis::CopyBytes +#define ENTRY_CopyBytesPrefix 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytesPrefix +#define ENTRY_CopyBytesRax 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytesRax +#define ENTRY_Copy0F 1, 1, 0, 0, 0, 0, &CDetourDis::Copy0F +#define ENTRY_Copy66 1, 1, 0, 0, 0, 0, &CDetourDis::Copy66 +#define ENTRY_Copy67 1, 1, 0, 0, 0, 0, &CDetourDis::Copy67 +#define ENTRY_CopyF6 0, 0, 0, 0, 0, 0, &CDetourDis::CopyF6 +#define ENTRY_CopyF7 0, 0, 0, 0, 0, 0, &CDetourDis::CopyF7 +#define ENTRY_CopyFF 0, 0, 0, 0, 0, 0, &CDetourDis::CopyFF +#define ENTRY_Invalid 1, 1, 0, 0, 0, 0, &CDetourDis::Invalid +#define ENTRY_End 0, 0, 0, 0, 0, 0, NULL + + PBYTE CopyBytes(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyBytesPrefix(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyBytesRax(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyBytesJump(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + + PBYTE Invalid(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + + PBYTE AdjustTarget(PBYTE pbDst, PBYTE pbSrc, LONG cbOp, + LONG cbTargetOffset, LONG cbTargetSize); + + protected: + PBYTE Copy0F(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE Copy66(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE Copy67(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyF6(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyF7(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + PBYTE CopyFF(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc); + + protected: + static const COPYENTRY s_rceCopyTable[257]; + static const COPYENTRY s_rceCopyTable0F[257]; + static const BYTE s_rbModRm[256]; + + protected: + BOOL m_bOperandOverride; + BOOL m_bAddressOverride; + BOOL m_bRaxOverride; + + PBYTE * m_ppbTarget; + LONG * m_plExtra; + + LONG m_lScratchExtra; + PBYTE m_pbScratchTarget; + BYTE m_rbScratchDst[64]; +}; + +PVOID WINAPI DetourCopyInstruction(PVOID pDst, + PVOID *ppDstPool, + PVOID pSrc, + PVOID *ppTarget, + LONG *plExtra) +{ + (void)ppDstPool; // x86 & x64 don't use a constant pool. + CDetourDis oDetourDisasm((PBYTE*)ppTarget, plExtra); + return oDetourDisasm.CopyInstruction((PBYTE)pDst, (PBYTE)pSrc); +} + +/////////////////////////////////////////////////////////// Disassembler Code. +// +CDetourDis::CDetourDis(PBYTE *ppbTarget, LONG *plExtra) +{ + m_bOperandOverride = FALSE; + m_bAddressOverride = FALSE; + m_bRaxOverride = FALSE; + + m_ppbTarget = ppbTarget ? ppbTarget : &m_pbScratchTarget; + m_plExtra = plExtra ? plExtra : &m_lScratchExtra; + + *m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_NONE; + *m_plExtra = 0; +} + +PBYTE CDetourDis::CopyInstruction(PBYTE pbDst, PBYTE pbSrc) +{ + // Configure scratch areas if real areas are not available. + if (NULL == pbDst) { + pbDst = m_rbScratchDst; + } + if (NULL == pbSrc) { + // We can't copy a non-existent instruction. + SetLastError(ERROR_INVALID_DATA); + return NULL; + } + + // Figure out how big the instruction is, do the appropriate copy, + // and figure out what the target of the instruction is if any. + // + REFCOPYENTRY pEntry = &s_rceCopyTable[pbSrc[0]]; + return (this->*pEntry->pfCopy)(pEntry, pbDst, pbSrc); +} + +PBYTE CDetourDis::CopyBytes(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + + + +#else + LONG nBytesFixed = (pEntry->nFlagBits & ADDRESS) + ? (m_bAddressOverride ? pEntry->nFixedSize16 : pEntry->nFixedSize) + : (m_bOperandOverride ? pEntry->nFixedSize16 : pEntry->nFixedSize); +#endif + + LONG nBytes = nBytesFixed; + LONG nRelOffset = pEntry->nRelOffset; + LONG cbTarget = nBytes - nRelOffset; + if (pEntry->nModOffset > 0) { + BYTE bModRm = pbSrc[pEntry->nModOffset]; + BYTE bFlags = s_rbModRm[bModRm]; + + nBytes += bFlags & NOTSIB; + + if (bFlags & SIB) { + BYTE bSib = pbSrc[pEntry->nModOffset + 1]; + + if ((bSib & 0x07) == 0x05) { + if ((bModRm & 0xc0) == 0x00) { + nBytes += 4; + } + else if ((bModRm & 0xc0) == 0x40) { + nBytes += 1; + } + else if ((bModRm & 0xc0) == 0x80) { + nBytes += 4; + } + } + cbTarget = nBytes - nRelOffset; + } + else if (bFlags & RIP) { +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + +#endif + } + } + CopyMemory(pbDst, pbSrc, nBytes); + + if (nRelOffset) { + *m_ppbTarget = AdjustTarget(pbDst, pbSrc, nBytesFixed, nRelOffset, cbTarget); +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + + +#endif + } + if (pEntry->nFlagBits & NOENLARGE) { + *m_plExtra = -*m_plExtra; + } + if (pEntry->nFlagBits & DYNAMIC) { + *m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_DYNAMIC; + } + return pbSrc + nBytes; +} + +PBYTE CDetourDis::CopyBytesPrefix(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + CopyBytes(pEntry, pbDst, pbSrc); + + pEntry = &s_rceCopyTable[pbSrc[1]]; + return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1); +} + +PBYTE CDetourDis::CopyBytesRax(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + CopyBytes(pEntry, pbDst, pbSrc); + + if (*pbSrc & 0x8) { + m_bRaxOverride = TRUE; + } + + pEntry = &s_rceCopyTable[pbSrc[1]]; + return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1); +} + +PBYTE CDetourDis::CopyBytesJump(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + (void)pEntry; + + PVOID pvSrcAddr = &pbSrc[1]; + PVOID pvDstAddr = NULL; + LONG_PTR nOldOffset = (LONG_PTR)*(CHAR*&)pvSrcAddr; + LONG_PTR nNewOffset = 0; + + *m_ppbTarget = pbSrc + 2 + nOldOffset; + + if (pbSrc[0] == 0xeb) { + pbDst[0] = 0xe9; + pvDstAddr = &pbDst[1]; + nNewOffset = nOldOffset - ((pbDst - pbSrc) + 3); + *(LONG*&)pvDstAddr = (LONG)nNewOffset; + + *m_plExtra = 3; + return pbSrc + 2; + } + + ASSERT(pbSrc[0] >= 0x70 && pbSrc[0] <= 0x7f); + + pbDst[0] = 0x0f; + pbDst[1] = 0x80 | (pbSrc[0] & 0xf); + pvDstAddr = &pbDst[2]; + nNewOffset = nOldOffset - ((pbDst - pbSrc) + 4); + *(LONG*&)pvDstAddr = (LONG)nNewOffset; + + *m_plExtra = 4; + return pbSrc + 2; +} + +PBYTE CDetourDis::AdjustTarget(PBYTE pbDst, PBYTE pbSrc, LONG cbOp, + LONG cbTargetOffset, LONG cbTargetSize) +{ + PBYTE pbTarget = NULL; + PVOID pvTargetAddr = &pbDst[cbTargetOffset]; + LONG_PTR nOldOffset = 0; + + switch (cbTargetSize) { + case 1: + nOldOffset = (LONG_PTR)*(CHAR*&)pvTargetAddr; + break; + case 2: + nOldOffset = (LONG_PTR)*(SHORT*&)pvTargetAddr; + break; + case 4: + nOldOffset = (LONG_PTR)*(LONG*&)pvTargetAddr; + break; + case 8: + nOldOffset = (LONG_PTR)*(LONG_PTR*&)pvTargetAddr; + break; + default: + ASSERT(!"cbTargetSize is invalid."); + break; + } + + pbTarget = pbSrc + cbOp + nOldOffset; + LONG_PTR nNewOffset = nOldOffset - (pbDst - pbSrc); + + switch (cbTargetSize) { + case 1: + *(CHAR*&)pvTargetAddr = (CHAR)nNewOffset; + if (nNewOffset < SCHAR_MIN || nNewOffset > SCHAR_MAX) { + *m_plExtra = sizeof(ULONG) - 1; + } + break; + case 2: + *(SHORT*&)pvTargetAddr = (SHORT)nNewOffset; + if (nNewOffset < SHRT_MIN || nNewOffset > SHRT_MAX) { + *m_plExtra = sizeof(ULONG) - 2; + } + break; + case 4: + *(LONG*&)pvTargetAddr = (LONG)nNewOffset; + if (nNewOffset < LONG_MIN || nNewOffset > LONG_MAX) { + *m_plExtra = sizeof(ULONG) - 4; + } + break; + case 8: + *(LONG_PTR*&)pvTargetAddr = (LONG_PTR)nNewOffset; + break; + } + ASSERT(pbDst + cbOp + nNewOffset == pbTarget); + return pbTarget; +} + +PBYTE CDetourDis::Invalid(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + (void)pbDst; + (void)pEntry; + ASSERT(!"Invalid Instruction"); + return pbSrc + 1; +} + +////////////////////////////////////////////////////// Individual Bytes Codes. +// +PBYTE CDetourDis::Copy0F(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + CopyBytes(pEntry, pbDst, pbSrc); + + pEntry = &s_rceCopyTable0F[pbSrc[1]]; + return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1); +} + +PBYTE CDetourDis::Copy66(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ // Operand-size override prefix + m_bOperandOverride = TRUE; + return CopyBytesPrefix(pEntry, pbDst, pbSrc); +} + +PBYTE CDetourDis::Copy67(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ // Address size override prefix + m_bAddressOverride = TRUE; + return CopyBytesPrefix(pEntry, pbDst, pbSrc); +} + +PBYTE CDetourDis::CopyF6(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + (void)pEntry; + + // TEST BYTE /0 + if (0x00 == (0x38 & pbSrc[1])) { // reg(bits 543) of ModR/M == 0 + const COPYENTRY ce = { 0xf6, ENTRY_CopyBytes2Mod1 }; + return (this->*ce.pfCopy)(&ce, pbDst, pbSrc); + } + // DIV /6 + // IDIV /7 + // IMUL /5 + // MUL /4 + // NEG /3 + // NOT /2 + + const COPYENTRY ce = { 0xf6, ENTRY_CopyBytes2Mod }; + return (this->*ce.pfCopy)(&ce, pbDst, pbSrc); +} + +PBYTE CDetourDis::CopyF7(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ + (void)pEntry; + + // TEST WORD /0 + if (0x00 == (0x38 & pbSrc[1])) { // reg(bits 543) of ModR/M == 0 + const COPYENTRY ce = { 0xf7, ENTRY_CopyBytes2ModOperand }; + return (this->*ce.pfCopy)(&ce, pbDst, pbSrc); + } + + // DIV /6 + // IDIV /7 + // IMUL /5 + // MUL /4 + // NEG /3 + // NOT /2 + const COPYENTRY ce = { 0xf7, ENTRY_CopyBytes2Mod }; + return (this->*ce.pfCopy)(&ce, pbDst, pbSrc); +} + +PBYTE CDetourDis::CopyFF(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc) +{ // CALL /2 + // CALL /3 + // INC /0 + // JMP /4 + // JMP /5 + // PUSH /6 + (void)pEntry; + + if (0x15 == pbSrc[1] || 0x25 == pbSrc[1]) { // CALL [], JMP [] +#ifdef DETOURS_X64 +#error Feature not supported in this release. + + +#else + PBYTE *ppbTarget = *(PBYTE**)&pbSrc[2]; + *m_ppbTarget = *ppbTarget; +#endif + } + else if (0x10 == (0x38 & pbSrc[1]) || // CALL /2 --> reg(bits 543) of ModR/M == 010 + 0x18 == (0x38 & pbSrc[1]) || // CALL /3 --> reg(bits 543) of ModR/M == 011 + 0x20 == (0x38 & pbSrc[1]) || // JMP /4 --> reg(bits 543) of ModR/M == 100 + 0x28 == (0x38 & pbSrc[1]) // JMP /5 --> reg(bits 543) of ModR/M == 101 + ) { + *m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_DYNAMIC; + } + const COPYENTRY ce = { 0xff, ENTRY_CopyBytes2Mod }; + return (this->*ce.pfCopy)(&ce, pbDst, pbSrc); +} + +///////////////////////////////////////////////////////// Disassembler Tables. +// +const BYTE CDetourDis::s_rbModRm[256] = { + 0,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 0x + 0,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 1x + 0,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 2x + 0,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 3x + 1,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 4x + 1,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 5x + 1,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 6x + 1,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 7x + 4,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // 8x + 4,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // 9x + 4,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // Ax + 4,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // Bx + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Cx + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Dx + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Ex + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 // Fx +}; + +const CDetourDis::COPYENTRY CDetourDis::s_rceCopyTable[257] = +{ + { 0x00, ENTRY_CopyBytes2Mod }, // ADD /r + { 0x01, ENTRY_CopyBytes2Mod }, // ADD /r + { 0x02, ENTRY_CopyBytes2Mod }, // ADD /r + { 0x03, ENTRY_CopyBytes2Mod }, // ADD /r + { 0x04, ENTRY_CopyBytes2 }, // ADD ib + { 0x05, ENTRY_CopyBytes3Or5 }, // ADD iw + { 0x06, ENTRY_CopyBytes1 }, // PUSH + { 0x07, ENTRY_CopyBytes1 }, // POP + { 0x08, ENTRY_CopyBytes2Mod }, // OR /r + { 0x09, ENTRY_CopyBytes2Mod }, // OR /r + { 0x0A, ENTRY_CopyBytes2Mod }, // OR /r + { 0x0B, ENTRY_CopyBytes2Mod }, // OR /r + { 0x0C, ENTRY_CopyBytes2 }, // OR ib + { 0x0D, ENTRY_CopyBytes3Or5 }, // OR iw + { 0x0E, ENTRY_CopyBytes1 }, // PUSH + { 0x0F, ENTRY_Copy0F }, // Extension Ops + { 0x10, ENTRY_CopyBytes2Mod }, // ADC /r + { 0x11, ENTRY_CopyBytes2Mod }, // ADC /r + { 0x12, ENTRY_CopyBytes2Mod }, // ADC /r + { 0x13, ENTRY_CopyBytes2Mod }, // ADC /r + { 0x14, ENTRY_CopyBytes2 }, // ADC ib + { 0x15, ENTRY_CopyBytes3Or5 }, // ADC id + { 0x16, ENTRY_CopyBytes1 }, // PUSH + { 0x17, ENTRY_CopyBytes1 }, // POP + { 0x18, ENTRY_CopyBytes2Mod }, // SBB /r + { 0x19, ENTRY_CopyBytes2Mod }, // SBB /r + { 0x1A, ENTRY_CopyBytes2Mod }, // SBB /r + { 0x1B, ENTRY_CopyBytes2Mod }, // SBB /r + { 0x1C, ENTRY_CopyBytes2 }, // SBB ib + { 0x1D, ENTRY_CopyBytes3Or5 }, // SBB id + { 0x1E, ENTRY_CopyBytes1 }, // PUSH + { 0x1F, ENTRY_CopyBytes1 }, // POP + { 0x20, ENTRY_CopyBytes2Mod }, // AND /r + { 0x21, ENTRY_CopyBytes2Mod }, // AND /r + { 0x22, ENTRY_CopyBytes2Mod }, // AND /r + { 0x23, ENTRY_CopyBytes2Mod }, // AND /r + { 0x24, ENTRY_CopyBytes2 }, // AND ib + { 0x25, ENTRY_CopyBytes3Or5 }, // AND id + { 0x26, ENTRY_CopyBytesPrefix }, // ES prefix + { 0x27, ENTRY_CopyBytes1 }, // DAA + { 0x28, ENTRY_CopyBytes2Mod }, // SUB /r + { 0x29, ENTRY_CopyBytes2Mod }, // SUB /r + { 0x2A, ENTRY_CopyBytes2Mod }, // SUB /r + { 0x2B, ENTRY_CopyBytes2Mod }, // SUB /r + { 0x2C, ENTRY_CopyBytes2 }, // SUB ib + { 0x2D, ENTRY_CopyBytes3Or5 }, // SUB id + { 0x2E, ENTRY_CopyBytesPrefix }, // CS prefix + { 0x2F, ENTRY_CopyBytes1 }, // DAS + { 0x30, ENTRY_CopyBytes2Mod }, // XOR /r + { 0x31, ENTRY_CopyBytes2Mod }, // XOR /r + { 0x32, ENTRY_CopyBytes2Mod }, // XOR /r + { 0x33, ENTRY_CopyBytes2Mod }, // XOR /r + { 0x34, ENTRY_CopyBytes2 }, // XOR ib + { 0x35, ENTRY_CopyBytes3Or5 }, // XOR id + { 0x36, ENTRY_CopyBytesPrefix }, // SS prefix + { 0x37, ENTRY_CopyBytes1 }, // AAA + { 0x38, ENTRY_CopyBytes2Mod }, // CMP /r + { 0x39, ENTRY_CopyBytes2Mod }, // CMP /r + { 0x3A, ENTRY_CopyBytes2Mod }, // CMP /r + { 0x3B, ENTRY_CopyBytes2Mod }, // CMP /r + { 0x3C, ENTRY_CopyBytes2 }, // CMP ib + { 0x3D, ENTRY_CopyBytes3Or5 }, // CMP id + { 0x3E, ENTRY_CopyBytesPrefix }, // DS prefix + { 0x3F, ENTRY_CopyBytes1 }, // AAS +#ifdef DETOURS_X64 // For Rax Prefix +#error Feature not supported in this release. + + + + + + + + + + + + + + + +#else + { 0x40, ENTRY_CopyBytes1 }, // INC + { 0x41, ENTRY_CopyBytes1 }, // INC + { 0x42, ENTRY_CopyBytes1 }, // INC + { 0x43, ENTRY_CopyBytes1 }, // INC + { 0x44, ENTRY_CopyBytes1 }, // INC + { 0x45, ENTRY_CopyBytes1 }, // INC + { 0x46, ENTRY_CopyBytes1 }, // INC + { 0x47, ENTRY_CopyBytes1 }, // INC + { 0x48, ENTRY_CopyBytes1 }, // DEC + { 0x49, ENTRY_CopyBytes1 }, // DEC + { 0x4A, ENTRY_CopyBytes1 }, // DEC + { 0x4B, ENTRY_CopyBytes1 }, // DEC + { 0x4C, ENTRY_CopyBytes1 }, // DEC + { 0x4D, ENTRY_CopyBytes1 }, // DEC + { 0x4E, ENTRY_CopyBytes1 }, // DEC + { 0x4F, ENTRY_CopyBytes1 }, // DEC +#endif + { 0x50, ENTRY_CopyBytes1 }, // PUSH + { 0x51, ENTRY_CopyBytes1 }, // PUSH + { 0x52, ENTRY_CopyBytes1 }, // PUSH + { 0x53, ENTRY_CopyBytes1 }, // PUSH + { 0x54, ENTRY_CopyBytes1 }, // PUSH + { 0x55, ENTRY_CopyBytes1 }, // PUSH + { 0x56, ENTRY_CopyBytes1 }, // PUSH + { 0x57, ENTRY_CopyBytes1 }, // PUSH + { 0x58, ENTRY_CopyBytes1 }, // POP + { 0x59, ENTRY_CopyBytes1 }, // POP + { 0x5A, ENTRY_CopyBytes1 }, // POP + { 0x5B, ENTRY_CopyBytes1 }, // POP + { 0x5C, ENTRY_CopyBytes1 }, // POP + { 0x5D, ENTRY_CopyBytes1 }, // POP + { 0x5E, ENTRY_CopyBytes1 }, // POP + { 0x5F, ENTRY_CopyBytes1 }, // POP + { 0x60, ENTRY_CopyBytes1 }, // PUSHAD + { 0x61, ENTRY_CopyBytes1 }, // POPAD + { 0x62, ENTRY_CopyBytes2Mod }, // BOUND /r + { 0x63, ENTRY_CopyBytes2Mod }, // ARPL /r + { 0x64, ENTRY_CopyBytesPrefix }, // FS prefix + { 0x65, ENTRY_CopyBytesPrefix }, // GS prefix + { 0x66, ENTRY_Copy66 }, // Operand Prefix + { 0x67, ENTRY_Copy67 }, // Address Prefix + { 0x68, ENTRY_CopyBytes3Or5 }, // PUSH + { 0x69, ENTRY_CopyBytes2ModOperand }, // + { 0x6A, ENTRY_CopyBytes2 }, // PUSH + { 0x6B, ENTRY_CopyBytes2Mod1 }, // IMUL /r ib + { 0x6C, ENTRY_CopyBytes1 }, // INS + { 0x6D, ENTRY_CopyBytes1 }, // INS + { 0x6E, ENTRY_CopyBytes1 }, // OUTS/OUTSB + { 0x6F, ENTRY_CopyBytes1 }, // OUTS/OUTSW + { 0x70, ENTRY_CopyBytes2Jump }, // JO // 0f80 + { 0x71, ENTRY_CopyBytes2Jump }, // JNO // 0f81 + { 0x72, ENTRY_CopyBytes2Jump }, // JB/JC/JNAE // 0f82 + { 0x73, ENTRY_CopyBytes2Jump }, // JAE/JNB/JNC // 0f83 + { 0x74, ENTRY_CopyBytes2Jump }, // JE/JZ // 0f84 + { 0x75, ENTRY_CopyBytes2Jump }, // JNE/JNZ // 0f85 + { 0x76, ENTRY_CopyBytes2Jump }, // JBE/JNA // 0f86 + { 0x77, ENTRY_CopyBytes2Jump }, // JA/JNBE // 0f87 + { 0x78, ENTRY_CopyBytes2Jump }, // JS // 0f88 + { 0x79, ENTRY_CopyBytes2Jump }, // JNS // 0f89 + { 0x7A, ENTRY_CopyBytes2Jump }, // JP/JPE // 0f8a + { 0x7B, ENTRY_CopyBytes2Jump }, // JNP/JPO // 0f8b + { 0x7C, ENTRY_CopyBytes2Jump }, // JL/JNGE // 0f8c + { 0x7D, ENTRY_CopyBytes2Jump }, // JGE/JNL // 0f8d + { 0x7E, ENTRY_CopyBytes2Jump }, // JLE/JNG // 0f8e + { 0x7F, ENTRY_CopyBytes2Jump }, // JG/JNLE // 0f8f + { 0x80, ENTRY_CopyBytes2Mod1 }, // ADC/2 ib, etc.s + { 0x81, ENTRY_CopyBytes2ModOperand }, // + { 0x82, ENTRY_CopyBytes2 }, // MOV al,x + { 0x83, ENTRY_CopyBytes2Mod1 }, // ADC/2 ib, etc. + { 0x84, ENTRY_CopyBytes2Mod }, // TEST /r + { 0x85, ENTRY_CopyBytes2Mod }, // TEST /r + { 0x86, ENTRY_CopyBytes2Mod }, // XCHG /r @todo + { 0x87, ENTRY_CopyBytes2Mod }, // XCHG /r @todo + { 0x88, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x89, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x8A, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x8B, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x8C, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x8D, ENTRY_CopyBytes2Mod }, // LEA /r + { 0x8E, ENTRY_CopyBytes2Mod }, // MOV /r + { 0x8F, ENTRY_CopyBytes2Mod }, // POP /0 + { 0x90, ENTRY_CopyBytes1 }, // NOP + { 0x91, ENTRY_CopyBytes1 }, // XCHG + { 0x92, ENTRY_CopyBytes1 }, // XCHG + { 0x93, ENTRY_CopyBytes1 }, // XCHG + { 0x94, ENTRY_CopyBytes1 }, // XCHG + { 0x95, ENTRY_CopyBytes1 }, // XCHG + { 0x96, ENTRY_CopyBytes1 }, // XCHG + { 0x97, ENTRY_CopyBytes1 }, // XCHG + { 0x98, ENTRY_CopyBytes1 }, // CWDE + { 0x99, ENTRY_CopyBytes1 }, // CDQ + { 0x9A, ENTRY_CopyBytes5Or7Dynamic }, // CALL cp + { 0x9B, ENTRY_CopyBytes1 }, // WAIT/FWAIT + { 0x9C, ENTRY_CopyBytes1 }, // PUSHFD + { 0x9D, ENTRY_CopyBytes1 }, // POPFD + { 0x9E, ENTRY_CopyBytes1 }, // SAHF + { 0x9F, ENTRY_CopyBytes1 }, // LAHF + { 0xA0, ENTRY_CopyBytes3Or5Address }, // MOV + { 0xA1, ENTRY_CopyBytes3Or5Address }, // MOV + { 0xA2, ENTRY_CopyBytes3Or5Address }, // MOV + { 0xA3, ENTRY_CopyBytes3Or5Address }, // MOV + { 0xA4, ENTRY_CopyBytes1 }, // MOVS + { 0xA5, ENTRY_CopyBytes1 }, // MOVS/MOVSD + { 0xA6, ENTRY_CopyBytes1 }, // CMPS/CMPSB + { 0xA7, ENTRY_CopyBytes1 }, // CMPS/CMPSW + { 0xA8, ENTRY_CopyBytes2 }, // TEST + { 0xA9, ENTRY_CopyBytes3Or5 }, // TEST + { 0xAA, ENTRY_CopyBytes1 }, // STOS/STOSB + { 0xAB, ENTRY_CopyBytes1 }, // STOS/STOSW + { 0xAC, ENTRY_CopyBytes1 }, // LODS/LODSB + { 0xAD, ENTRY_CopyBytes1 }, // LODS/LODSW + { 0xAE, ENTRY_CopyBytes1 }, // SCAS/SCASB + { 0xAF, ENTRY_CopyBytes1 }, // SCAS/SCASD + { 0xB0, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB1, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB2, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB3, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB4, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB5, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB6, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB7, ENTRY_CopyBytes2 }, // MOV B0+rb + { 0xB8, ENTRY_CopyBytes3Or5Rax }, // MOV B8+rb + { 0xB9, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBA, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBB, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBC, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBD, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBE, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xBF, ENTRY_CopyBytes3Or5 }, // MOV B8+rb + { 0xC0, ENTRY_CopyBytes2Mod1 }, // RCL/2 ib, etc. + { 0xC1, ENTRY_CopyBytes2Mod1 }, // RCL/2 ib, etc. + { 0xC2, ENTRY_CopyBytes3 }, // RET + { 0xC3, ENTRY_CopyBytes1 }, // RET + { 0xC4, ENTRY_CopyBytes2Mod }, // LES + { 0xC5, ENTRY_CopyBytes2Mod }, // LDS + { 0xC6, ENTRY_CopyBytes2Mod1 }, // MOV + { 0xC7, ENTRY_CopyBytes2ModOperand }, // MOV + { 0xC8, ENTRY_CopyBytes4 }, // ENTER + { 0xC9, ENTRY_CopyBytes1 }, // LEAVE + { 0xCA, ENTRY_CopyBytes3Dynamic }, // RET + { 0xCB, ENTRY_CopyBytes1Dynamic }, // RET + { 0xCC, ENTRY_CopyBytes1Dynamic }, // INT 3 + { 0xCD, ENTRY_CopyBytes2Dynamic }, // INT ib + { 0xCE, ENTRY_CopyBytes1Dynamic }, // INTO + { 0xCF, ENTRY_CopyBytes1Dynamic }, // IRET + { 0xD0, ENTRY_CopyBytes2Mod }, // RCL/2, etc. + { 0xD1, ENTRY_CopyBytes2Mod }, // RCL/2, etc. + { 0xD2, ENTRY_CopyBytes2Mod }, // RCL/2, etc. + { 0xD3, ENTRY_CopyBytes2Mod }, // RCL/2, etc. + { 0xD4, ENTRY_CopyBytes2 }, // AAM + { 0xD5, ENTRY_CopyBytes2 }, // AAD + { 0xD6, ENTRY_Invalid }, // + { 0xD7, ENTRY_CopyBytes1 }, // XLAT/XLATB + { 0xD8, ENTRY_CopyBytes2Mod }, // FADD, etc. + { 0xD9, ENTRY_CopyBytes2Mod }, // F2XM1, etc. + { 0xDA, ENTRY_CopyBytes2Mod }, // FLADD, etc. + { 0xDB, ENTRY_CopyBytes2Mod }, // FCLEX, etc. + { 0xDC, ENTRY_CopyBytes2Mod }, // FADD/0, etc. + { 0xDD, ENTRY_CopyBytes2Mod }, // FFREE, etc. + { 0xDE, ENTRY_CopyBytes2Mod }, // FADDP, etc. + { 0xDF, ENTRY_CopyBytes2Mod }, // FBLD/4, etc. + { 0xE0, ENTRY_CopyBytes2CantJump }, // LOOPNE cb + { 0xE1, ENTRY_CopyBytes2CantJump }, // LOOPE cb + { 0xE2, ENTRY_CopyBytes2CantJump }, // LOOP cb + { 0xE3, ENTRY_CopyBytes2Jump }, // JCXZ/JECXZ + { 0xE4, ENTRY_CopyBytes2 }, // IN ib + { 0xE5, ENTRY_CopyBytes2 }, // IN id + { 0xE6, ENTRY_CopyBytes2 }, // OUT ib + { 0xE7, ENTRY_CopyBytes2 }, // OUT ib + { 0xE8, ENTRY_CopyBytes3Or5Target }, // CALL cd + { 0xE9, ENTRY_CopyBytes3Or5Target }, // JMP cd + { 0xEA, ENTRY_CopyBytes5Or7Dynamic }, // JMP cp + { 0xEB, ENTRY_CopyBytes2Jump }, // JMP cb + { 0xEC, ENTRY_CopyBytes1 }, // IN ib + { 0xED, ENTRY_CopyBytes1 }, // IN id + { 0xEE, ENTRY_CopyBytes1 }, // OUT + { 0xEF, ENTRY_CopyBytes1 }, // OUT + { 0xF0, ENTRY_CopyBytesPrefix }, // LOCK prefix + { 0xF1, ENTRY_Invalid }, // + { 0xF2, ENTRY_CopyBytesPrefix }, // REPNE prefix + { 0xF3, ENTRY_CopyBytesPrefix }, // REPE prefix + { 0xF4, ENTRY_CopyBytes1 }, // HLT + { 0xF5, ENTRY_CopyBytes1 }, // CMC + { 0xF6, ENTRY_CopyF6 }, // TEST/0, DIV/6 + { 0xF7, ENTRY_CopyF7 }, // TEST/0, DIV/6 + { 0xF8, ENTRY_CopyBytes1 }, // CLC + { 0xF9, ENTRY_CopyBytes1 }, // STC + { 0xFA, ENTRY_CopyBytes1 }, // CLI + { 0xFB, ENTRY_CopyBytes1 }, // STI + { 0xFC, ENTRY_CopyBytes1 }, // CLD + { 0xFD, ENTRY_CopyBytes1 }, // STD + { 0xFE, ENTRY_CopyBytes2Mod }, // DEC/1,INC/0 + { 0xFF, ENTRY_CopyFF }, // CALL/2 + { 0, ENTRY_End }, +}; + +const CDetourDis::COPYENTRY CDetourDis::s_rceCopyTable0F[257] = +{ + { 0x00, ENTRY_CopyBytes2Mod }, // LLDT/2, etc. + { 0x01, ENTRY_CopyBytes2Mod }, // INVLPG/7, etc. + { 0x02, ENTRY_CopyBytes2Mod }, // LAR/r + { 0x03, ENTRY_CopyBytes2Mod }, // LSL/r + { 0x04, ENTRY_Invalid }, // _04 + { 0x05, ENTRY_Invalid }, // _05 + { 0x06, ENTRY_CopyBytes2 }, // CLTS + { 0x07, ENTRY_Invalid }, // _07 + { 0x08, ENTRY_CopyBytes2 }, // INVD + { 0x09, ENTRY_CopyBytes2 }, // WBINVD + { 0x0A, ENTRY_Invalid }, // _0A + { 0x0B, ENTRY_CopyBytes2 }, // UD2 + { 0x0C, ENTRY_Invalid }, // _0C + { 0x0D, ENTRY_CopyBytes2Mod }, // PREFETCH + { 0x0E, ENTRY_CopyBytes2 }, // FEMMS + { 0x0F, ENTRY_CopyBytes3Mod }, // 3DNow Opcodes + { 0x10, ENTRY_CopyBytes2Mod }, // MOVSS MOVUPD MOVSD + { 0x11, ENTRY_CopyBytes2Mod }, // MOVSS MOVUPD MOVSD + { 0x12, ENTRY_CopyBytes2Mod }, // MOVLPD + { 0x13, ENTRY_CopyBytes2Mod }, // MOVLPD + { 0x14, ENTRY_CopyBytes2Mod }, // UNPCKLPD + { 0x15, ENTRY_CopyBytes2Mod }, // UNPCKHPD + { 0x16, ENTRY_CopyBytes2Mod }, // MOVHPD + { 0x17, ENTRY_CopyBytes2Mod }, // MOVHPD + { 0x18, ENTRY_CopyBytes2Mod }, // PREFETCHINTA... + { 0x19, ENTRY_Invalid }, // _19 + { 0x1A, ENTRY_Invalid }, // _1A + { 0x1B, ENTRY_Invalid }, // _1B + { 0x1C, ENTRY_Invalid }, // _1C + { 0x1D, ENTRY_Invalid }, // _1D + { 0x1E, ENTRY_Invalid }, // _1E + { 0x1F, ENTRY_CopyBytes2Mod }, // NOP/r + { 0x20, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x21, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x22, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x23, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x24, ENTRY_Invalid }, // _24 + { 0x25, ENTRY_Invalid }, // _25 + { 0x26, ENTRY_Invalid }, // _26 + { 0x27, ENTRY_Invalid }, // _27 + { 0x28, ENTRY_CopyBytes2Mod }, // MOVAPS MOVAPD + { 0x29, ENTRY_CopyBytes2Mod }, // MOVAPS MOVAPD + { 0x2A, ENTRY_CopyBytes2Mod }, // CVPI2PS & + { 0x2B, ENTRY_CopyBytes2Mod }, // MOVNTPS MOVNTPD + { 0x2C, ENTRY_CopyBytes2Mod }, // CVTTPS2PI & + { 0x2D, ENTRY_CopyBytes2Mod }, // CVTPS2PI & + { 0x2E, ENTRY_CopyBytes2Mod }, // UCOMISS UCOMISD + { 0x2F, ENTRY_CopyBytes2Mod }, // COMISS COMISD + { 0x30, ENTRY_CopyBytes2 }, // WRMSR + { 0x31, ENTRY_CopyBytes2 }, // RDTSC + { 0x32, ENTRY_CopyBytes2 }, // RDMSR + { 0x33, ENTRY_CopyBytes2 }, // RDPMC + { 0x34, ENTRY_CopyBytes2 }, // SYSENTER + { 0x35, ENTRY_CopyBytes2 }, // SYSEXIT + { 0x36, ENTRY_Invalid }, // _36 + { 0x37, ENTRY_Invalid }, // _37 + { 0x38, ENTRY_Invalid }, // _38 + { 0x39, ENTRY_Invalid }, // _39 + { 0x3A, ENTRY_Invalid }, // _3A + { 0x3B, ENTRY_Invalid }, // _3B + { 0x3C, ENTRY_Invalid }, // _3C + { 0x3D, ENTRY_Invalid }, // _3D + { 0x3E, ENTRY_Invalid }, // _3E + { 0x3F, ENTRY_Invalid }, // _3F + { 0x40, ENTRY_CopyBytes2Mod }, // CMOVO (0F 40) + { 0x41, ENTRY_CopyBytes2Mod }, // CMOVNO (0F 41) + { 0x42, ENTRY_CopyBytes2Mod }, // CMOVB & CMOVNE (0F 42) + { 0x43, ENTRY_CopyBytes2Mod }, // CMOVAE & CMOVNB (0F 43) + { 0x44, ENTRY_CopyBytes2Mod }, // CMOVE & CMOVZ (0F 44) + { 0x45, ENTRY_CopyBytes2Mod }, // CMOVNE & CMOVNZ (0F 45) + { 0x46, ENTRY_CopyBytes2Mod }, // CMOVBE & CMOVNA (0F 46) + { 0x47, ENTRY_CopyBytes2Mod }, // CMOVA & CMOVNBE (0F 47) + { 0x48, ENTRY_CopyBytes2Mod }, // CMOVS (0F 48) + { 0x49, ENTRY_CopyBytes2Mod }, // CMOVNS (0F 49) + { 0x4A, ENTRY_CopyBytes2Mod }, // CMOVP & CMOVPE (0F 4A) + { 0x4B, ENTRY_CopyBytes2Mod }, // CMOVNP & CMOVPO (0F 4B) + { 0x4C, ENTRY_CopyBytes2Mod }, // CMOVL & CMOVNGE (0F 4C) + { 0x4D, ENTRY_CopyBytes2Mod }, // CMOVGE & CMOVNL (0F 4D) + { 0x4E, ENTRY_CopyBytes2Mod }, // CMOVLE & CMOVNG (0F 4E) + { 0x4F, ENTRY_CopyBytes2Mod }, // CMOVG & CMOVNLE (0F 4F) + { 0x50, ENTRY_CopyBytes2Mod }, // MOVMSKPD MOVMSKPD + { 0x51, ENTRY_CopyBytes2Mod }, // SQRTPS & + { 0x52, ENTRY_CopyBytes2Mod }, // RSQRTTS RSQRTPS + { 0x53, ENTRY_CopyBytes2Mod }, // RCPPS RCPSS + { 0x54, ENTRY_CopyBytes2Mod }, // ANDPS ANDPD + { 0x55, ENTRY_CopyBytes2Mod }, // ANDNPS ANDNPD + { 0x56, ENTRY_CopyBytes2Mod }, // ORPS ORPD + { 0x57, ENTRY_CopyBytes2Mod }, // XORPS XORPD + { 0x58, ENTRY_CopyBytes2Mod }, // ADDPS & + { 0x59, ENTRY_CopyBytes2Mod }, // MULPS & + { 0x5A, ENTRY_CopyBytes2Mod }, // CVTPS2PD & + { 0x5B, ENTRY_CopyBytes2Mod }, // CVTDQ2PS & + { 0x5C, ENTRY_CopyBytes2Mod }, // SUBPS & + { 0x5D, ENTRY_CopyBytes2Mod }, // MINPS & + { 0x5E, ENTRY_CopyBytes2Mod }, // DIVPS & + { 0x5F, ENTRY_CopyBytes2Mod }, // MASPS & + { 0x60, ENTRY_CopyBytes2Mod }, // PUNPCKLBW/r + { 0x61, ENTRY_CopyBytes2Mod }, // PUNPCKLWD/r + { 0x62, ENTRY_CopyBytes2Mod }, // PUNPCKLWD/r + { 0x63, ENTRY_CopyBytes2Mod }, // PACKSSWB/r + { 0x64, ENTRY_CopyBytes2Mod }, // PCMPGTB/r + { 0x65, ENTRY_CopyBytes2Mod }, // PCMPGTW/r + { 0x66, ENTRY_CopyBytes2Mod }, // PCMPGTD/r + { 0x67, ENTRY_CopyBytes2Mod }, // PACKUSWB/r + { 0x68, ENTRY_CopyBytes2Mod }, // PUNPCKHBW/r + { 0x69, ENTRY_CopyBytes2Mod }, // PUNPCKHWD/r + { 0x6A, ENTRY_CopyBytes2Mod }, // PUNPCKHDQ/r + { 0x6B, ENTRY_CopyBytes2Mod }, // PACKSSDW/r + { 0x6C, ENTRY_CopyBytes2Mod }, // PUNPCKLQDQ + { 0x6D, ENTRY_CopyBytes2Mod }, // PUNPCKHQDQ + { 0x6E, ENTRY_CopyBytes2Mod }, // MOVD/r + { 0x6F, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x70, ENTRY_CopyBytes2Mod1 }, // PSHUFW/r ib + { 0x71, ENTRY_CopyBytes2Mod1 }, // PSLLW/6 ib,PSRAW/4 ib,PSRLW/2 ib + { 0x72, ENTRY_CopyBytes2Mod1 }, // PSLLD/6 ib,PSRAD/4 ib,PSRLD/2 ib + { 0x73, ENTRY_CopyBytes2Mod1 }, // PSLLQ/6 ib,PSRLQ/2 ib + { 0x74, ENTRY_CopyBytes2Mod }, // PCMPEQB/r + { 0x75, ENTRY_CopyBytes2Mod }, // PCMPEQW/r + { 0x76, ENTRY_CopyBytes2Mod }, // PCMPEQD/r + { 0x77, ENTRY_CopyBytes2 }, // EMMS + { 0x78, ENTRY_Invalid }, // _78 + { 0x79, ENTRY_Invalid }, // _79 + { 0x7A, ENTRY_Invalid }, // _7A + { 0x7B, ENTRY_Invalid }, // _7B + { 0x7C, ENTRY_Invalid }, // _7C + { 0x7D, ENTRY_Invalid }, // _7D + { 0x7E, ENTRY_CopyBytes2Mod }, // MOVD/r + { 0x7F, ENTRY_CopyBytes2Mod }, // MOV/r + { 0x80, ENTRY_CopyBytes3Or5Target }, // JO + { 0x81, ENTRY_CopyBytes3Or5Target }, // JNO + { 0x82, ENTRY_CopyBytes3Or5Target }, // JB,JC,JNAE + { 0x83, ENTRY_CopyBytes3Or5Target }, // JAE,JNB,JNC + { 0x84, ENTRY_CopyBytes3Or5Target }, // JE,JZ,JZ + { 0x85, ENTRY_CopyBytes3Or5Target }, // JNE,JNZ + { 0x86, ENTRY_CopyBytes3Or5Target }, // JBE,JNA + { 0x87, ENTRY_CopyBytes3Or5Target }, // JA,JNBE + { 0x88, ENTRY_CopyBytes3Or5Target }, // JS + { 0x89, ENTRY_CopyBytes3Or5Target }, // JNS + { 0x8A, ENTRY_CopyBytes3Or5Target }, // JP,JPE + { 0x8B, ENTRY_CopyBytes3Or5Target }, // JNP,JPO + { 0x8C, ENTRY_CopyBytes3Or5Target }, // JL,NGE + { 0x8D, ENTRY_CopyBytes3Or5Target }, // JGE,JNL + { 0x8E, ENTRY_CopyBytes3Or5Target }, // JLE,JNG + { 0x8F, ENTRY_CopyBytes3Or5Target }, // JG,JNLE + { 0x90, ENTRY_CopyBytes2Mod }, // CMOVO (0F 40) + { 0x91, ENTRY_CopyBytes2Mod }, // CMOVNO (0F 41) + { 0x92, ENTRY_CopyBytes2Mod }, // CMOVB & CMOVC & CMOVNAE (0F 42) + { 0x93, ENTRY_CopyBytes2Mod }, // CMOVAE & CMOVNB & CMOVNC (0F 43) + { 0x94, ENTRY_CopyBytes2Mod }, // CMOVE & CMOVZ (0F 44) + { 0x95, ENTRY_CopyBytes2Mod }, // CMOVNE & CMOVNZ (0F 45) + { 0x96, ENTRY_CopyBytes2Mod }, // CMOVBE & CMOVNA (0F 46) + { 0x97, ENTRY_CopyBytes2Mod }, // CMOVA & CMOVNBE (0F 47) + { 0x98, ENTRY_CopyBytes2Mod }, // CMOVS (0F 48) + { 0x99, ENTRY_CopyBytes2Mod }, // CMOVNS (0F 49) + { 0x9A, ENTRY_CopyBytes2Mod }, // CMOVP & CMOVPE (0F 4A) + { 0x9B, ENTRY_CopyBytes2Mod }, // CMOVNP & CMOVPO (0F 4B) + { 0x9C, ENTRY_CopyBytes2Mod }, // CMOVL & CMOVNGE (0F 4C) + { 0x9D, ENTRY_CopyBytes2Mod }, // CMOVGE & CMOVNL (0F 4D) + { 0x9E, ENTRY_CopyBytes2Mod }, // CMOVLE & CMOVNG (0F 4E) + { 0x9F, ENTRY_CopyBytes2Mod }, // CMOVG & CMOVNLE (0F 4F) + { 0xA0, ENTRY_CopyBytes2 }, // PUSH + { 0xA1, ENTRY_CopyBytes2 }, // POP + { 0xA2, ENTRY_CopyBytes2 }, // CPUID + { 0xA3, ENTRY_CopyBytes2Mod }, // BT (0F A3) + { 0xA4, ENTRY_CopyBytes2Mod1 }, // SHLD + { 0xA5, ENTRY_CopyBytes2Mod }, // SHLD + { 0xA6, ENTRY_Invalid }, // _A6 + { 0xA7, ENTRY_Invalid }, // _A7 + { 0xA8, ENTRY_CopyBytes2 }, // PUSH + { 0xA9, ENTRY_CopyBytes2 }, // POP + { 0xAA, ENTRY_CopyBytes2 }, // RSM + { 0xAB, ENTRY_CopyBytes2Mod }, // BTS (0F AB) + { 0xAC, ENTRY_CopyBytes2Mod1 }, // SHRD + { 0xAD, ENTRY_CopyBytes2Mod }, // SHRD + { 0xAE, ENTRY_CopyBytes2Mod }, // FXRSTOR/1,FXSAVE/0 + { 0xAF, ENTRY_CopyBytes2Mod }, // IMUL (0F AF) + { 0xB0, ENTRY_CopyBytes2Mod }, // CMPXCHG (0F B0) + { 0xB1, ENTRY_CopyBytes2Mod }, // CMPXCHG (0F B1) + { 0xB2, ENTRY_CopyBytes2Mod }, // LSS/r + { 0xB3, ENTRY_CopyBytes2Mod }, // BTR (0F B3) + { 0xB4, ENTRY_CopyBytes2Mod }, // LFS/r + { 0xB5, ENTRY_CopyBytes2Mod }, // LGS/r + { 0xB6, ENTRY_CopyBytes2Mod }, // MOVZX/r + { 0xB7, ENTRY_CopyBytes2Mod }, // MOVZX/r + { 0xB8, ENTRY_Invalid }, // _B8 + { 0xB9, ENTRY_Invalid }, // _B9 + { 0xBA, ENTRY_CopyBytes2Mod1 }, // BT & BTC & BTR & BTS (0F BA) + { 0xBB, ENTRY_CopyBytes2Mod }, // BTC (0F BB) + { 0xBC, ENTRY_CopyBytes2Mod }, // BSF (0F BC) + { 0xBD, ENTRY_CopyBytes2Mod }, // BSR (0F BD) + { 0xBE, ENTRY_CopyBytes2Mod }, // MOVSX/r + { 0xBF, ENTRY_CopyBytes2Mod }, // MOVSX/r + { 0xC0, ENTRY_CopyBytes2Mod }, // XADD/r + { 0xC1, ENTRY_CopyBytes2Mod }, // XADD/r + { 0xC2, ENTRY_CopyBytes2Mod }, // CMPPS & + { 0xC3, ENTRY_CopyBytes2Mod }, // MOVNTI + { 0xC4, ENTRY_CopyBytes2Mod1 }, // PINSRW /r ib + { 0xC5, ENTRY_CopyBytes2Mod1 }, // PEXTRW /r ib + { 0xC6, ENTRY_CopyBytes2Mod1 }, // SHUFPS & SHUFPD + { 0xC7, ENTRY_CopyBytes2Mod }, // CMPXCHG8B (0F C7) + { 0xC8, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xC9, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xCA, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xCB, ENTRY_CopyBytes2 }, //CVTPD2PI BSWAP 0F C8 + rd + { 0xCC, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xCD, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xCE, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xCF, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd + { 0xD0, ENTRY_Invalid }, // _D0 + { 0xD1, ENTRY_CopyBytes2Mod }, // PSRLW/r + { 0xD2, ENTRY_CopyBytes2Mod }, // PSRLD/r + { 0xD3, ENTRY_CopyBytes2Mod }, // PSRLQ/r + { 0xD4, ENTRY_CopyBytes2Mod }, // PADDQ + { 0xD5, ENTRY_CopyBytes2Mod }, // PMULLW/r + { 0xD6, ENTRY_CopyBytes2Mod }, // MOVDQ2Q / MOVQ2DQ + { 0xD7, ENTRY_CopyBytes2Mod }, // PMOVMSKB/r + { 0xD8, ENTRY_CopyBytes2Mod }, // PSUBUSB/r + { 0xD9, ENTRY_CopyBytes2Mod }, // PSUBUSW/r + { 0xDA, ENTRY_CopyBytes2Mod }, // PMINUB/r + { 0xDB, ENTRY_CopyBytes2Mod }, // PAND/r + { 0xDC, ENTRY_CopyBytes2Mod }, // PADDUSB/r + { 0xDD, ENTRY_CopyBytes2Mod }, // PADDUSW/r + { 0xDE, ENTRY_CopyBytes2Mod }, // PMAXUB/r + { 0xDF, ENTRY_CopyBytes2Mod }, // PANDN/r + { 0xE0, ENTRY_CopyBytes2Mod }, // PAVGB + { 0xE1, ENTRY_CopyBytes2Mod }, // PSRAW/r + { 0xE2, ENTRY_CopyBytes2Mod }, // PSRAD/r + { 0xE3, ENTRY_CopyBytes2Mod }, // PAVGW + { 0xE4, ENTRY_CopyBytes2Mod }, // PMULHUW/r + { 0xE5, ENTRY_CopyBytes2Mod }, // PMULHW/r + { 0xE6, ENTRY_CopyBytes2Mod }, // CTDQ2PD & + { 0xE7, ENTRY_CopyBytes2Mod }, // MOVNTQ + { 0xE8, ENTRY_CopyBytes2Mod }, // PSUBB/r + { 0xE9, ENTRY_CopyBytes2Mod }, // PSUBW/r + { 0xEA, ENTRY_CopyBytes2Mod }, // PMINSW/r + { 0xEB, ENTRY_CopyBytes2Mod }, // POR/r + { 0xEC, ENTRY_CopyBytes2Mod }, // PADDSB/r + { 0xED, ENTRY_CopyBytes2Mod }, // PADDSW/r + { 0xEE, ENTRY_CopyBytes2Mod }, // PMAXSW /r + { 0xEF, ENTRY_CopyBytes2Mod }, // PXOR/r + { 0xF0, ENTRY_Invalid }, // _F0 + { 0xF1, ENTRY_CopyBytes2Mod }, // PSLLW/r + { 0xF2, ENTRY_CopyBytes2Mod }, // PSLLD/r + { 0xF3, ENTRY_CopyBytes2Mod }, // PSLLQ/r + { 0xF4, ENTRY_CopyBytes2Mod }, // PMULUDQ/r + { 0xF5, ENTRY_CopyBytes2Mod }, // PMADDWD/r + { 0xF6, ENTRY_CopyBytes2Mod }, // PSADBW/r + { 0xF7, ENTRY_CopyBytes2Mod }, // MASKMOVQ + { 0xF8, ENTRY_CopyBytes2Mod }, // PSUBB/r + { 0xF9, ENTRY_CopyBytes2Mod }, // PSUBW/r + { 0xFA, ENTRY_CopyBytes2Mod }, // PSUBD/r + { 0xFB, ENTRY_CopyBytes2Mod }, // FSUBQ/r + { 0xFC, ENTRY_CopyBytes2Mod }, // PADDB/r + { 0xFD, ENTRY_CopyBytes2Mod }, // PADDW/r + { 0xFE, ENTRY_CopyBytes2Mod }, // PADDD/r + { 0xFF, ENTRY_Invalid }, // _FF + { 0, ENTRY_End }, +}; + +BOOL CDetourDis::SanityCheckSystem() +{ + ULONG n = 0; + for (; n < 256; n++) { + REFCOPYENTRY pEntry = &s_rceCopyTable[n]; + + if (n != pEntry->nOpcode) { + ASSERT(n == pEntry->nOpcode); + return FALSE; + } + } + if (s_rceCopyTable[256].pfCopy != NULL) { + ASSERT(!"Missing end marker."); + return FALSE; + } + + for (n = 0; n < 256; n++) { + REFCOPYENTRY pEntry = &s_rceCopyTable0F[n]; + + if (n != pEntry->nOpcode) { + ASSERT(n == pEntry->nOpcode); + return FALSE; + } + } + if (s_rceCopyTable0F[256].pfCopy != NULL) { + ASSERT(!"Missing end marker."); + return FALSE; + } + + return TRUE; +} +#endif // defined(DETOURS_X64) || defined(DETOURS_X86) + +/////////////////////////////////////////////////////////// IA64 Disassembler. +// +#ifdef DETOURS_IA64 +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM +#error Feature not supported in this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // DETOURS_ARM + +// +///////////////////////////////////////////////////////////////// End of File. diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/image.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/image.cpp new file mode 100644 index 0000000..0015f70 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/image.cpp @@ -0,0 +1,2192 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Image manipulation functions (image.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Used for for payloads, byways, and imports. +// + +#include +#if (_MSC_VER < 1310) +#else +#include +#endif + +#if (_MSC_VER < 1299) +#pragma warning(disable: 4710) +#else +#endif + +//#define DETOUR_DEBUG 1 +#define DETOURS_INTERNAL + +#include "detours.h" + +namespace Detour +{ +////////////////////////////////////////////////////////////////////////////// +// +#ifndef _STRSAFE_H_INCLUDED_ +static inline HRESULT StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch) +{ + HRESULT hr = S_OK; + size_t cchMaxPrev = cchMax; + + if (cchMax > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + while (cchMax && (*psz != '\0')) + { + psz++; + cchMax--; + } + + if (cchMax == 0) + { + // the string is longer than cchMax + hr = ERROR_INVALID_PARAMETER; + } + + if (SUCCEEDED(hr) && pcch) + { + *pcch = cchMaxPrev - cchMax; + } + + return hr; +} + + +static inline HRESULT StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr = S_OK; + + if (cchDest == 0) + { + // can not null terminate a zero-byte dest buffer + hr = ERROR_INVALID_PARAMETER; + } + else + { + while (cchDest && (*pszSrc != '\0')) + { + *pszDest++ = *pszSrc++; + cchDest--; + } + + if (cchDest == 0) + { + // we are going to truncate pszDest + pszDest--; + hr = ERROR_INVALID_PARAMETER; + } + + *pszDest= '\0'; + } + + return hr; +} + +static inline HRESULT StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr; + size_t cchDestCurrent; + + if (cchDest > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + hr = StringCchLengthA(pszDest, cchDest, &cchDestCurrent); + + if (SUCCEEDED(hr)) + { + hr = StringCchCopyA(pszDest + cchDestCurrent, + cchDest - cchDestCurrent, + pszSrc); + } + + return hr; +} + +#endif + +/////////////////////////////////////////////////////////////////////////////// +// +class CImageData +{ + friend class CImage; + +public: + CImageData(PBYTE pbData, DWORD cbData); + ~CImageData(); + + PBYTE Enumerate(GUID *pGuid, DWORD *pcbData, DWORD *pnIterator); + PBYTE Find(REFGUID rguid, DWORD *pcbData); + PBYTE Set(REFGUID rguid, PBYTE pbData, DWORD cbData); + + BOOL Delete(REFGUID rguid); + BOOL Purge(); + + BOOL IsEmpty() { return m_cbData == 0; } + BOOL IsValid(); + +protected: + BOOL SizeTo(DWORD cbData); + +protected: + PBYTE m_pbData; + DWORD m_cbData; + DWORD m_cbAlloc; +}; + +class CImageImportFile +{ + friend class CImage; + friend class CImageImportName; + +public: + CImageImportFile(); + ~CImageImportFile(); + +public: + CImageImportFile * m_pNextFile; + BOOL m_fByway; + + CImageImportName * m_pImportNames; + DWORD m_nImportNames; + + DWORD m_rvaOriginalFirstThunk; + DWORD m_rvaFirstThunk; + + DWORD m_nForwarderChain; + PCHAR m_pszOrig; + PCHAR m_pszName; +}; + +class CImageImportName +{ + friend class CImage; + friend class CImageImportFile; + +public: + CImageImportName(); + ~CImageImportName(); + +public: + WORD m_nHint; + ULONG m_nOrig; + ULONG m_nOrdinal; + PCHAR m_pszOrig; + PCHAR m_pszName; +}; + +class CImage +{ + friend class CImageThunks; + friend class CImageChars; + friend class CImageImportFile; + friend class CImageImportName; + +public: + CImage(); + ~CImage(); + + static CImage * IsValid(PDETOUR_BINARY pBinary); + +public: // File Functions + BOOL Read(HANDLE hFile); + BOOL Write(HANDLE hFile); + BOOL Close(); + +public: // Manipulation Functions + PBYTE DataEnum(GUID *pGuid, DWORD *pcbData, DWORD *pnIterator); + PBYTE DataFind(REFGUID rguid, DWORD *pcbData); + PBYTE DataSet(REFGUID rguid, PBYTE pbData, DWORD cbData); + BOOL DataDelete(REFGUID rguid); + BOOL DataPurge(); + + BOOL EditImports(PVOID pContext, + PF_DETOUR_BINARY_BYWAY_CALLBACK pfBywayCallback, + PF_DETOUR_BINARY_FILE_CALLBACK pfFileCallback, + PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbolCallback, + PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommitCallback); + +protected: + BOOL WriteFile(HANDLE hFile, + LPCVOID lpBuffer, + DWORD nNumberOfBytesToWrite, + LPDWORD lpNumberOfBytesWritten); + BOOL CopyFileData(HANDLE hFile, DWORD nOldPos, DWORD cbData); + BOOL ZeroFileData(HANDLE hFile, DWORD cbData); + BOOL AlignFileData(HANDLE hFile); + + BOOL SizeOutputBuffer(DWORD cbData); + PBYTE AllocateOutput(DWORD cbData, DWORD *pnVirtAddr); + + PVOID RvaToVa(ULONG_PTR nRva); + DWORD RvaToFileOffset(DWORD nRva); + + DWORD FileAlign(DWORD nAddr); + DWORD SectionAlign(DWORD nAddr); + + BOOL CheckImportsNeeded(DWORD *pnTables, + DWORD *pnThunks, + DWORD *pnChars); + + CImageImportFile * NewByway(__in_z PCHAR pszName); + +private: + DWORD m_dwValidSignature; + CImageData * m_pImageData; // Read & Write + + HANDLE m_hMap; // Read & Write + PBYTE m_pMap; // Read & Write + + DWORD m_nNextFileAddr; // Write + DWORD m_nNextVirtAddr; // Write + + IMAGE_DOS_HEADER m_DosHeader; // Read & Write + IMAGE_NT_HEADERS m_NtHeader; // Read & Write + IMAGE_SECTION_HEADER m_SectionHeaders[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; + + DWORD m_nPrePE; + DWORD m_cbPrePE; + DWORD m_cbPostPE; + + DWORD m_nPeOffset; + DWORD m_nSectionsOffset; + DWORD m_nExtraOffset; + DWORD m_nFileSize; + + DWORD m_nOutputVirtAddr; + DWORD m_nOutputVirtSize; + DWORD m_nOutputFileAddr; + + PBYTE m_pbOutputBuffer; + DWORD m_cbOutputBuffer; + + CImageImportFile * m_pImportFiles; + DWORD m_nImportFiles; + + BOOL m_fHadDetourSection; + +private: + enum { + DETOUR_IMAGE_VALID_SIGNATURE = 0xfedcba01, // "Dtr\0" + }; +}; + +////////////////////////////////////////////////////////////////////////////// +// +static BYTE s_rbDosCode[0x10] = { + 0x0E,0x1F,0xBA,0x0E,0x00,0xB4,0x09,0xCD, + 0x21,0xB8,0x01,0x4C,0xCD,0x21,'*','*' +}; + +static inline DWORD Max(DWORD a, DWORD b) +{ + return a > b ? a : b; +} + +static inline DWORD Align(DWORD a, DWORD size) +{ + size--; + return (a + size) & ~size; +} + +static inline DWORD QuadAlign(DWORD a) +{ + return Align(a, 8); +} + +static PCHAR DuplicateString(__in_z PCHAR pszIn) +{ + if (pszIn) { + UINT nIn = (UINT)strlen(pszIn); + PCHAR pszOut = new CHAR [nIn + 1]; + if (pszOut == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + } + else { + CopyMemory(pszOut, pszIn, nIn + 1); + } + return pszOut; + } + return NULL; +} + +static PCHAR ReplaceString(__deref_out PCHAR *ppsz, __in_z PCHAR pszIn) +{ + if (ppsz == NULL) { + return NULL; + } + + UINT nIn; + if (*ppsz != NULL) { + if (strcmp(*ppsz, pszIn) == 0) { + return *ppsz; + } + nIn = (UINT)strlen(pszIn); + + if (strlen(*ppsz) == nIn) { + CopyMemory(*ppsz, pszIn, nIn + 1); + return *ppsz; + } + else { + delete[] *ppsz; + *ppsz = NULL; + } + } + else { + nIn = (UINT)strlen(pszIn); + } + + *ppsz = new CHAR [nIn + 1]; + if (*ppsz == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + } + else { + CopyMemory(*ppsz, pszIn, nIn + 1); + } + return *ppsz; +} + +////////////////////////////////////////////////////////////////////////////// +// +CImageImportFile::CImageImportFile() +{ + m_pNextFile = NULL; + m_fByway = FALSE; + + m_pImportNames = NULL; + m_nImportNames = 0; + + m_rvaOriginalFirstThunk = 0; + m_rvaFirstThunk = 0; + + m_nForwarderChain = (UINT)0; + m_pszName = NULL; + m_pszOrig = NULL; +} + +CImageImportFile::~CImageImportFile() +{ + if (m_pNextFile) { + delete m_pNextFile; + m_pNextFile = NULL; + } + if (m_pImportNames) { + delete[] m_pImportNames; + m_pImportNames = NULL; + m_nImportNames = 0; + } + if (m_pszName) { + delete[] m_pszName; + m_pszName = NULL; + } + if (m_pszOrig) { + delete[] m_pszOrig; + m_pszOrig = NULL; + } +} + +CImageImportName::CImageImportName() +{ + m_nOrig = 0; + m_nOrdinal = 0; + m_nHint = 0; + m_pszName = NULL; + m_pszOrig = NULL; +} + +CImageImportName::~CImageImportName() +{ + if (m_pszName) { + delete[] m_pszName; + m_pszName = NULL; + } + if (m_pszOrig) { + delete[] m_pszOrig; + m_pszOrig = NULL; + } +} + +////////////////////////////////////////////////////////////////////////////// +// +CImageData::CImageData(PBYTE pbData, DWORD cbData) +{ + m_pbData = pbData; + m_cbData = cbData; + m_cbAlloc = 0; +} + +CImageData::~CImageData() +{ + IsValid(); + + if (m_cbAlloc == 0) { + m_pbData = NULL; + } + if (m_pbData) { + delete[] m_pbData; + m_pbData = NULL; + } + m_cbData = 0; + m_cbAlloc = 0; +} + +BOOL CImageData::SizeTo(DWORD cbData) +{ + IsValid(); + + if (cbData <= m_cbAlloc) { + return TRUE; + } + + PBYTE pbNew = new BYTE [cbData]; + if (pbNew == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + if (m_pbData) { + CopyMemory(pbNew, m_pbData, m_cbData); + if (m_cbAlloc > 0) { + delete[] m_pbData; + } + m_pbData = NULL; + } + m_pbData = pbNew; + m_cbAlloc = cbData; + + IsValid(); + + return TRUE; +} + +BOOL CImageData::Purge() +{ + m_cbData = 0; + + IsValid(); + + return TRUE; +} + +BOOL CImageData::IsValid() +{ + if (m_pbData == NULL) { + return TRUE; + } + + PBYTE pbBeg = m_pbData; + PBYTE pbEnd = m_pbData + m_cbData; + + for (PBYTE pbIter = pbBeg; pbIter < pbEnd;) { + PDETOUR_SECTION_RECORD pRecord = (PDETOUR_SECTION_RECORD)pbIter; + + if (pRecord->cbBytes < sizeof(DETOUR_SECTION_RECORD)) { + return FALSE; + } + if (pRecord->nReserved != 0) { + return FALSE; + } + + pbIter += pRecord->cbBytes; + } + return TRUE; +} + +PBYTE CImageData::Enumerate(GUID *pGuid, DWORD *pcbData, DWORD *pnIterator) +{ + IsValid(); + + if (pnIterator == NULL || + m_cbData < *pnIterator + sizeof(DETOUR_SECTION_RECORD)) { + + if (pcbData) { + *pcbData = 0; + } + if (pGuid) { + ZeroMemory(pGuid, sizeof(*pGuid)); + } + return NULL; + } + + PDETOUR_SECTION_RECORD pRecord = (PDETOUR_SECTION_RECORD)(m_pbData + *pnIterator); + + if (pGuid) { + *pGuid = pRecord->guid; + } + if (pcbData) { + *pcbData = pRecord->cbBytes - sizeof(DETOUR_SECTION_RECORD); + } + *pnIterator = (LONG)(((PBYTE)pRecord - m_pbData) + pRecord->cbBytes); + + return (PBYTE)(pRecord + 1); +} + +PBYTE CImageData::Find(REFGUID rguid, DWORD *pcbData) +{ + IsValid(); + + DWORD cbBytes = sizeof(DETOUR_SECTION_RECORD); + for (DWORD nOffset = 0; nOffset < m_cbData; nOffset += cbBytes) { + PDETOUR_SECTION_RECORD pRecord = (PDETOUR_SECTION_RECORD)(m_pbData + nOffset); + + cbBytes = pRecord->cbBytes; + if (cbBytes > m_cbData) { + break; + } + if (cbBytes < sizeof(DETOUR_SECTION_RECORD)) { + continue; + } + + if (pRecord->guid.Data1 == rguid.Data1 && + pRecord->guid.Data2 == rguid.Data2 && + pRecord->guid.Data3 == rguid.Data3 && + pRecord->guid.Data4[0] == rguid.Data4[0] && + pRecord->guid.Data4[1] == rguid.Data4[1] && + pRecord->guid.Data4[2] == rguid.Data4[2] && + pRecord->guid.Data4[3] == rguid.Data4[3] && + pRecord->guid.Data4[4] == rguid.Data4[4] && + pRecord->guid.Data4[5] == rguid.Data4[5] && + pRecord->guid.Data4[6] == rguid.Data4[6] && + pRecord->guid.Data4[7] == rguid.Data4[7]) { + + *pcbData = cbBytes - sizeof(DETOUR_SECTION_RECORD); + return (PBYTE)(pRecord + 1); + } + } + + if (pcbData) { + *pcbData = 0; + } + return NULL; +} + +BOOL CImageData::Delete(REFGUID rguid) +{ + IsValid(); + + PBYTE pbFound = NULL; + DWORD cbFound = 0; + + pbFound = Find(rguid, &cbFound); + if (pbFound == NULL) { + SetLastError(ERROR_MOD_NOT_FOUND); + return FALSE; + } + + pbFound -= sizeof(DETOUR_SECTION_RECORD); + cbFound += sizeof(DETOUR_SECTION_RECORD); + + PBYTE pbRestData = pbFound + cbFound; + DWORD cbRestData = m_cbData - (LONG)(pbRestData - m_pbData); + + if (cbRestData) { + MoveMemory(pbFound, pbRestData, cbRestData); + } + m_cbData -= cbFound; + + IsValid(); + return TRUE; +} + +PBYTE CImageData::Set(REFGUID rguid, PBYTE pbData, DWORD cbData) +{ + IsValid(); + Delete(rguid); + + DWORD cbAlloc = QuadAlign(cbData); + + if (!SizeTo(m_cbData + cbAlloc + sizeof(DETOUR_SECTION_RECORD))) { + return NULL; + } + + PDETOUR_SECTION_RECORD pRecord = (PDETOUR_SECTION_RECORD)(m_pbData + m_cbData); + pRecord->cbBytes = cbAlloc + sizeof(DETOUR_SECTION_RECORD); + pRecord->nReserved = 0; + pRecord->guid = rguid; + + PBYTE pbDest = (PBYTE)(pRecord + 1); + if (pbData) { + CopyMemory(pbDest, pbData, cbData); + if (cbData < cbAlloc) { + ZeroMemory(pbDest + cbData, cbAlloc - cbData); + } + } + else { + if (cbAlloc > 0) { + ZeroMemory(pbDest, cbAlloc); + } + } + + m_cbData += cbAlloc + sizeof(DETOUR_SECTION_RECORD); + + IsValid(); + return pbDest; +} + +////////////////////////////////////////////////////////////////////////////// +// +class CImageThunks +{ +private: + CImage * m_pImage; + PIMAGE_THUNK_DATA m_pThunks; + DWORD m_nThunks; + DWORD m_nThunksMax; + DWORD m_nThunkVirtAddr; + +public: + CImageThunks(CImage *pImage, DWORD nThunksMax, DWORD *pnAddr) + { + m_pImage = pImage; + m_nThunks = 0; + m_nThunksMax = nThunksMax; + m_pThunks = (PIMAGE_THUNK_DATA) + m_pImage->AllocateOutput(sizeof(IMAGE_THUNK_DATA) * nThunksMax, + &m_nThunkVirtAddr); + *pnAddr = m_nThunkVirtAddr; + } + + PIMAGE_THUNK_DATA Current(DWORD *pnVirtAddr) + { + if (m_nThunksMax > 1) { + *pnVirtAddr = m_nThunkVirtAddr; + return m_pThunks; + } + *pnVirtAddr = 0; + return NULL; + } + + PIMAGE_THUNK_DATA Allocate(ULONG_PTR nData, DWORD *pnVirtAddr) + { + if (m_nThunks < m_nThunksMax) { + *pnVirtAddr = m_nThunkVirtAddr; + + m_nThunks++; + m_nThunkVirtAddr += sizeof(IMAGE_THUNK_DATA); + m_pThunks->u1.Ordinal = (DWORD)nData; + return m_pThunks++; + } + *pnVirtAddr = 0; + return NULL; + } + + DWORD Size() + { + return m_nThunksMax * sizeof(IMAGE_THUNK_DATA); + } +}; + +////////////////////////////////////////////////////////////////////////////// +// +class CImageChars +{ +private: + CImage * m_pImage; + PCHAR m_pChars; + DWORD m_nChars; + DWORD m_nCharsMax; + DWORD m_nCharVirtAddr; + +public: + CImageChars(CImage *pImage, DWORD nCharsMax, DWORD *pnAddr) + { + m_pImage = pImage; + m_nChars = 0; + m_nCharsMax = nCharsMax; + m_pChars = (PCHAR)m_pImage->AllocateOutput(nCharsMax, &m_nCharVirtAddr); + *pnAddr = m_nCharVirtAddr; + } + + PCHAR Allocate(__in_z PCHAR pszString, DWORD *pnVirtAddr) + { + DWORD nLen = (DWORD)strlen(pszString) + 1; + nLen += (nLen & 1); + + if (m_nChars + nLen > m_nCharsMax) { + *pnVirtAddr = 0; + return NULL; + } + + *pnVirtAddr = m_nCharVirtAddr; + HRESULT hrRet = StringCchCopyA(m_pChars,m_nCharsMax, pszString); + + if (FAILED(hrRet)) { + return NULL; + } + + pszString = m_pChars; + + m_pChars += nLen; + m_nChars += nLen; + m_nCharVirtAddr += nLen; + + return pszString; + } + + PCHAR Allocate(PCHAR pszString, DWORD nHint, DWORD *pnVirtAddr) + { + DWORD nLen = (DWORD)strlen(pszString) + 1 + sizeof(USHORT); + nLen += (nLen & 1); + + if (m_nChars + nLen > m_nCharsMax) { + *pnVirtAddr = 0; + return NULL; + } + + *pnVirtAddr = m_nCharVirtAddr; + *(USHORT *)m_pChars = (USHORT)nHint; + + HRESULT hrRet = StringCchCopyA(m_pChars + sizeof(USHORT), m_nCharsMax, pszString); + if (FAILED(hrRet)) { + return NULL; + } + + pszString = m_pChars + sizeof(USHORT); + + m_pChars += nLen; + m_nChars += nLen; + m_nCharVirtAddr += nLen; + + return pszString; + } + + DWORD Size() + { + return m_nChars; + } +}; + +////////////////////////////////////////////////////////////////////////////// +// +CImage * CImage::IsValid(PDETOUR_BINARY pBinary) +{ + if (pBinary) { + CImage *pImage = (CImage *)pBinary; + + if (pImage->m_dwValidSignature == DETOUR_IMAGE_VALID_SIGNATURE) { + return pImage; + } + } + SetLastError(ERROR_INVALID_HANDLE); + return NULL; +} + +CImage::CImage() +{ + m_dwValidSignature = (DWORD)DETOUR_IMAGE_VALID_SIGNATURE; + + m_hMap = NULL; + m_pMap = NULL; + + m_nPeOffset = 0; + m_nSectionsOffset = 0; + + m_pbOutputBuffer = NULL; + m_cbOutputBuffer = 0; + + m_pImageData = NULL; + + m_pImportFiles = NULL; + m_nImportFiles = 0; + + m_fHadDetourSection = FALSE; +} + +CImage::~CImage() +{ + Close(); + m_dwValidSignature = 0; +} + +BOOL CImage::Close() +{ + if (m_pImportFiles) { + delete m_pImportFiles; + m_pImportFiles = NULL; + m_nImportFiles = 0; + } + + if (m_pImageData) { + delete m_pImageData; + m_pImageData = NULL; + } + + if (m_pMap != NULL) { + UnmapViewOfFile(m_pMap); + m_pMap = NULL; + } + + if (m_hMap) { + CloseHandle(m_hMap); + m_hMap = NULL; + } + + if (m_pbOutputBuffer) { + delete[] m_pbOutputBuffer; + m_pbOutputBuffer = NULL; + m_cbOutputBuffer = 0; + } + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////// +// +PBYTE CImage::DataEnum(GUID *pGuid, DWORD *pcbData, DWORD *pnIterator) +{ + if (m_pImageData == NULL) { + return NULL; + } + return m_pImageData->Enumerate(pGuid, pcbData, pnIterator); +} + +PBYTE CImage::DataFind(REFGUID rguid, DWORD *pcbData) +{ + if (m_pImageData == NULL) { + return NULL; + } + return m_pImageData->Find(rguid, pcbData); +} + +PBYTE CImage::DataSet(REFGUID rguid, PBYTE pbData, DWORD cbData) +{ + if (m_pImageData == NULL) { + return NULL; + } + return m_pImageData->Set(rguid, pbData, cbData); +} + +BOOL CImage::DataDelete(REFGUID rguid) +{ + if (m_pImageData == NULL) { + return FALSE; + } + return m_pImageData->Delete(rguid); +} + +BOOL CImage::DataPurge() +{ + if (m_pImageData == NULL) { + return TRUE; + } + return m_pImageData->Purge(); +} + +////////////////////////////////////////////////////////////////////////////// +// +BOOL CImage::SizeOutputBuffer(DWORD cbData) +{ + if (m_cbOutputBuffer < cbData) { + if (cbData < 1024) {//65536 + cbData = 1024; + } + cbData = FileAlign(cbData); + + PBYTE pOutput = new BYTE [cbData]; + if (pOutput == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + if (m_pbOutputBuffer) { + CopyMemory(pOutput, m_pbOutputBuffer, m_cbOutputBuffer); + + delete[] m_pbOutputBuffer; + m_pbOutputBuffer = NULL; + } + + ZeroMemory(pOutput + m_cbOutputBuffer, cbData - m_cbOutputBuffer), + + m_pbOutputBuffer = pOutput; + m_cbOutputBuffer = cbData; + } + return TRUE; +} + +PBYTE CImage::AllocateOutput(DWORD cbData, DWORD *pnVirtAddr) +{ + cbData = QuadAlign(cbData); + + PBYTE pbData = m_pbOutputBuffer + m_nOutputVirtSize; + + *pnVirtAddr = m_nOutputVirtAddr + m_nOutputVirtSize; + m_nOutputVirtSize += cbData; + + if (m_nOutputVirtSize > m_cbOutputBuffer) { + SetLastError(ERROR_OUTOFMEMORY); + return NULL; + } + + ZeroMemory(pbData, cbData); + + return pbData; +} + +////////////////////////////////////////////////////////////////////////////// +// +DWORD CImage::FileAlign(DWORD nAddr) +{ + return Align(nAddr, m_NtHeader.OptionalHeader.FileAlignment); +} + +DWORD CImage::SectionAlign(DWORD nAddr) +{ + return Align(nAddr, m_NtHeader.OptionalHeader.SectionAlignment); +} + +////////////////////////////////////////////////////////////////////////////// +// +PVOID CImage::RvaToVa(ULONG_PTR nRva) +{ + if (nRva == 0) { + return NULL; + } + + for (DWORD n = 0; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + DWORD vaStart = m_SectionHeaders[n].VirtualAddress; + DWORD vaEnd = vaStart + m_SectionHeaders[n].SizeOfRawData; + + if (nRva >= vaStart && nRva < vaEnd) { + return (PBYTE)m_pMap + + m_SectionHeaders[n].PointerToRawData + + nRva - m_SectionHeaders[n].VirtualAddress; + } + } + return NULL; +} + +DWORD CImage::RvaToFileOffset(DWORD nRva) +{ + DWORD n; + for (n = 0; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + DWORD vaStart = m_SectionHeaders[n].VirtualAddress; + DWORD vaEnd = vaStart + m_SectionHeaders[n].SizeOfRawData; + + if (nRva >= vaStart && nRva < vaEnd) { + return m_SectionHeaders[n].PointerToRawData + + nRva - m_SectionHeaders[n].VirtualAddress; + } + } + return 0; +} + +////////////////////////////////////////////////////////////////////////////// +// +BOOL CImage::WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, + LPDWORD lpNumberOfBytesWritten) +{ + return ::WriteFile(hFile, + lpBuffer, + nNumberOfBytesToWrite, + lpNumberOfBytesWritten, + NULL); +} + + +BOOL CImage::CopyFileData(HANDLE hFile, DWORD nOldPos, DWORD cbData) +{ + DWORD cbDone = 0; + return WriteFile(hFile, m_pMap + nOldPos, cbData, &cbDone); +} + +BOOL CImage::ZeroFileData(HANDLE hFile, DWORD cbData) +{ + if (!SizeOutputBuffer(4096)) { + return FALSE; + } + + ZeroMemory(m_pbOutputBuffer, 4096); + + for (DWORD cbLeft = cbData; cbLeft > 0;) { + DWORD cbStep = cbLeft > sizeof(m_pbOutputBuffer) + ? sizeof(m_pbOutputBuffer) : cbLeft; + DWORD cbDone = 0; + + if (!WriteFile(hFile, m_pbOutputBuffer, cbStep, &cbDone)) { + return FALSE; + } + if (cbDone == 0) { + break; + } + + cbLeft -= cbDone; + } + return TRUE; +} + +BOOL CImage::AlignFileData(HANDLE hFile) +{ + DWORD nLastFileAddr = m_nNextFileAddr; + + m_nNextFileAddr = FileAlign(m_nNextFileAddr); + m_nNextVirtAddr = SectionAlign(m_nNextVirtAddr); + + if (hFile != INVALID_HANDLE_VALUE) { + if (m_nNextFileAddr > nLastFileAddr) { + if (SetFilePointer(hFile, nLastFileAddr, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + return ZeroFileData(hFile, m_nNextFileAddr - nLastFileAddr); + } + } + return TRUE; +} + +BOOL CImage::Read(HANDLE hFile) +{ + DWORD n; + PBYTE pbData = NULL; + DWORD cbData = 0; + + if (hFile == INVALID_HANDLE_VALUE) { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + ///////////////////////////////////////////////////////// Create mapping. + // + m_nFileSize = GetFileSize(hFile, NULL); + if (m_nFileSize == (DWORD)-1) { + return FALSE; + } + + m_hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL); + if (m_hMap == NULL) { + return FALSE; + } + + m_pMap = (PBYTE)MapViewOfFileEx(m_hMap, FILE_MAP_READ, 0, 0, 0, NULL); + if (m_pMap == NULL) { + return FALSE; + } + + ////////////////////////////////////////////////////// Process DOS Header. + // + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)m_pMap; + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return FALSE; + } + m_nPeOffset = pDosHeader->e_lfanew; + m_nPrePE = 0; + m_cbPrePE = QuadAlign(pDosHeader->e_lfanew); + + CopyMemory(&m_DosHeader, m_pMap + m_nPrePE, sizeof(m_DosHeader)); + + /////////////////////////////////////////////////////// Process PE Header. + // + CopyMemory(&m_NtHeader, m_pMap + m_nPeOffset, sizeof(m_NtHeader)); + if (m_NtHeader.Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return FALSE; + } + if (m_NtHeader.FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + m_nSectionsOffset = m_nPeOffset + + sizeof(m_NtHeader.Signature) + + sizeof(m_NtHeader.FileHeader) + + m_NtHeader.FileHeader.SizeOfOptionalHeader; + + ///////////////////////////////////////////////// Process Section Headers. + // + if (m_NtHeader.FileHeader.NumberOfSections > (sizeof(m_SectionHeaders) / + sizeof(m_SectionHeaders[0]))) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + CopyMemory(&m_SectionHeaders, + m_pMap + m_nSectionsOffset, + sizeof(m_SectionHeaders[0]) * m_NtHeader.FileHeader.NumberOfSections); + + /////////////////////////////////////////////////// Parse .detour Section. + // + DWORD rvaOriginalImageDirectory = 0; + DWORD rvaDetourBeg = 0; + DWORD rvaDetourEnd = 0; + + for (n = 0; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + if (strcmp((PCHAR)m_SectionHeaders[n].Name, ".detour") == 0) { + DETOUR_SECTION_HEADER dh; + CopyMemory(&dh, + m_pMap + m_SectionHeaders[n].PointerToRawData, + sizeof(dh)); + + rvaOriginalImageDirectory = dh.nOriginalImportVirtualAddress; + if (dh.cbPrePE != 0) { + m_nPrePE = m_SectionHeaders[n].PointerToRawData + sizeof(dh); + m_cbPrePE = dh.cbPrePE; + } + rvaDetourBeg = m_SectionHeaders[n].VirtualAddress; + rvaDetourEnd = rvaDetourBeg + m_SectionHeaders[n].SizeOfRawData; + } + } + + //////////////////////////////////////////////////////// Get Import Table. + // + DWORD rvaImageDirectory = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; + PIMAGE_IMPORT_DESCRIPTOR iidp + = (PIMAGE_IMPORT_DESCRIPTOR)RvaToVa(rvaImageDirectory); + PIMAGE_IMPORT_DESCRIPTOR oidp + = (PIMAGE_IMPORT_DESCRIPTOR)RvaToVa(rvaOriginalImageDirectory); + + if (oidp == NULL) { + oidp = iidp; + } + if (iidp == NULL || oidp == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + DWORD nFiles = 0; + for (; iidp[nFiles].OriginalFirstThunk != 0 || iidp[nFiles].FirstThunk != 0; nFiles++) { + } + + CImageImportFile **ppLastFile = &m_pImportFiles; + m_pImportFiles = NULL; + + for (n = 0; n < nFiles; n++, iidp++) { + ULONG_PTR rvaName = iidp->Name; + PCHAR pszName = (PCHAR)RvaToVa(rvaName); + if (pszName == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + goto fail; + } + + CImageImportFile *pImportFile = new CImageImportFile; + if (pImportFile == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + goto fail; + } + + *ppLastFile = pImportFile; + ppLastFile = &pImportFile->m_pNextFile; + m_nImportFiles++; + + pImportFile->m_pszName = DuplicateString(pszName); + if (pImportFile->m_pszName == NULL) { + goto fail; + } + + pImportFile->m_rvaOriginalFirstThunk = iidp->OriginalFirstThunk; + pImportFile->m_rvaFirstThunk = iidp->FirstThunk; + pImportFile->m_nForwarderChain = iidp->ForwarderChain; + pImportFile->m_pImportNames = NULL; + pImportFile->m_nImportNames = 0; + pImportFile->m_fByway = FALSE; + + if ((ULONG)iidp->FirstThunk >= rvaDetourBeg && + (ULONG)iidp->FirstThunk < rvaDetourEnd) { + + pImportFile->m_pszOrig = NULL; + pImportFile->m_fByway = TRUE; + continue; + } + + rvaName = oidp->Name; + pszName = (PCHAR)RvaToVa(rvaName); + if (pszName == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + goto fail; + } + pImportFile->m_pszOrig = DuplicateString(pszName); + if (pImportFile->m_pszOrig == NULL) { + goto fail; + } + + DWORD rvaThunk = iidp->OriginalFirstThunk; + if( !rvaThunk ) { + rvaThunk = iidp->FirstThunk; + } + PIMAGE_THUNK_DATA pAddrThunk = (PIMAGE_THUNK_DATA)RvaToVa(rvaThunk); + rvaThunk = oidp->OriginalFirstThunk; + if( !rvaThunk ) { + rvaThunk = oidp->FirstThunk; + } + PIMAGE_THUNK_DATA pLookThunk = (PIMAGE_THUNK_DATA)RvaToVa(rvaThunk); + + DWORD nNames = 0; + if (pAddrThunk) { + for (; pAddrThunk[nNames].u1.Ordinal; nNames++) { + } + } + + if (pAddrThunk && nNames) { + pImportFile->m_nImportNames = nNames; + pImportFile->m_pImportNames = new CImageImportName [nNames]; + if (pImportFile->m_pImportNames == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + goto fail; + } + + CImageImportName *pImportName = &pImportFile->m_pImportNames[0]; + + for (DWORD f = 0; f < nNames; f++, pImportName++) { + pImportName->m_nOrig = 0; + pImportName->m_nOrdinal = 0; + pImportName->m_nHint = 0; + pImportName->m_pszName = NULL; + pImportName->m_pszOrig = NULL; + + rvaName = pAddrThunk[f].u1.Ordinal; + if (rvaName & IMAGE_ORDINAL_FLAG) { + pImportName->m_nOrig = (ULONG)IMAGE_ORDINAL(rvaName); + pImportName->m_nOrdinal = pImportName->m_nOrig; + } + else { + PIMAGE_IMPORT_BY_NAME pName + = (PIMAGE_IMPORT_BY_NAME)RvaToVa(rvaName); + if (pName) { + pImportName->m_nHint = pName->Hint; + pImportName->m_pszName = DuplicateString((PCHAR)pName->Name); + if (pImportName->m_pszName == NULL) { + goto fail; + } + } + + rvaName = pLookThunk[f].u1.Ordinal; + if (rvaName & IMAGE_ORDINAL_FLAG) { + pImportName->m_nOrig = (ULONG)IMAGE_ORDINAL(rvaName); + pImportName->m_nOrdinal = (ULONG)IMAGE_ORDINAL(rvaName); + } + else { + pName = (PIMAGE_IMPORT_BY_NAME)RvaToVa(rvaName); + if (pName) { + pImportName->m_pszOrig + = DuplicateString((PCHAR)pName->Name); + if (pImportName->m_pszOrig == NULL) { + goto fail; + } + } + } + } + } + } + oidp++; + } + + ////////////////////////////////////////////////////////// Parse Sections. + // + m_nExtraOffset = 0; + for (n = 0; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + m_nExtraOffset = Max(m_SectionHeaders[n].PointerToRawData + + m_SectionHeaders[n].SizeOfRawData, + m_nExtraOffset); + + if (strcmp((PCHAR)m_SectionHeaders[n].Name, ".detour") == 0) { + DETOUR_SECTION_HEADER dh; + CopyMemory(&dh, + m_pMap + m_SectionHeaders[n].PointerToRawData, + sizeof(dh)); + + if (dh.nDataOffset == 0) { + dh.nDataOffset = dh.cbHeaderSize; + } + + cbData = dh.cbDataSize - dh.nDataOffset; + pbData = (m_pMap + + m_SectionHeaders[n].PointerToRawData + + dh.nDataOffset); + + m_nExtraOffset = Max(m_SectionHeaders[n].PointerToRawData + + m_SectionHeaders[n].SizeOfRawData, + m_nExtraOffset); + + m_NtHeader.FileHeader.NumberOfSections--; + + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress + = dh.nOriginalImportVirtualAddress; + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size + = dh.nOriginalImportSize; + + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress + = dh.nOriginalBoundImportVirtualAddress; + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size + = dh.nOriginalBoundImportSize; + + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress + = dh.nOriginalIatVirtualAddress; + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size + = dh.nOriginalIatSize; + + m_NtHeader.OptionalHeader.CheckSum = 0; + m_NtHeader.OptionalHeader.SizeOfImage + = dh.nOriginalSizeOfImage; + + m_fHadDetourSection = TRUE; + } + } + + m_pImageData = new CImageData(pbData, cbData); + if (m_pImageData == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + } + return TRUE; + +fail: + return FALSE; +} + +static inline BOOL strneq(__in_z PCHAR pszOne, __in_z PCHAR pszTwo) +{ + if (pszOne == pszTwo) { + return FALSE; + } + if (!pszOne || !pszTwo) { + return TRUE; + } + return (strcmp(pszOne, pszTwo) != 0); +} + +BOOL CImage::CheckImportsNeeded(DWORD *pnTables, DWORD *pnThunks, DWORD *pnChars) +{ + DWORD nTables = 0; + DWORD nThunks = 0; + DWORD nChars = 0; + BOOL fNeedDetourSection = FALSE; + + for (CImageImportFile *pImportFile = m_pImportFiles; + pImportFile != NULL; pImportFile = pImportFile->m_pNextFile) { + + nChars += (int)strlen(pImportFile->m_pszName) + 1; + nChars += nChars & 1; + + if (pImportFile->m_fByway) { + fNeedDetourSection = TRUE; + nThunks++; + } + else { + if (!fNeedDetourSection && + strneq(pImportFile->m_pszName, pImportFile->m_pszOrig)) { + + fNeedDetourSection = TRUE; + } + for (DWORD n = 0; n < pImportFile->m_nImportNames; n++) { + CImageImportName *pImportName = &pImportFile->m_pImportNames[n]; + + if (!fNeedDetourSection && + strneq(pImportName->m_pszName, pImportName->m_pszOrig)) { + + fNeedDetourSection = TRUE; + } + + if (pImportName->m_pszName) { + nChars += sizeof(WORD); // Hint + nChars += (int)strlen(pImportName->m_pszName) + 1; + nChars += nChars & 1; + } + nThunks++; + } + } + nThunks++; + nTables++; + } + nTables++; + + *pnTables = nTables; + *pnThunks = nThunks; + *pnChars = nChars; + + return fNeedDetourSection; +} + +////////////////////////////////////////////////////////////////////////////// +// +CImageImportFile * CImage::NewByway(__in_z PCHAR pszName) +{ + CImageImportFile *pImportFile = new CImageImportFile; + if (pImportFile == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + goto fail; + } + + pImportFile->m_pNextFile = NULL; + pImportFile->m_fByway = TRUE; + + pImportFile->m_pszName = DuplicateString(pszName); + if (pImportFile->m_pszName == NULL) { + goto fail; + } + + pImportFile->m_rvaOriginalFirstThunk = 0; + pImportFile->m_rvaFirstThunk = 0; + pImportFile->m_nForwarderChain = (UINT)0; + pImportFile->m_pImportNames = NULL; + pImportFile->m_nImportNames = 0; + + m_nImportFiles++; + return pImportFile; + +fail: + if (pImportFile) { + delete pImportFile; + pImportFile = NULL; + } + return NULL; +} + +BOOL CImage::EditImports(PVOID pContext, + PF_DETOUR_BINARY_BYWAY_CALLBACK pfBywayCallback, + PF_DETOUR_BINARY_FILE_CALLBACK pfFileCallback, + PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbolCallback, + PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommitCallback) +{ + CImageImportFile *pImportFile = NULL; + CImageImportFile **ppLastFile = &m_pImportFiles; + + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + + while ((pImportFile = *ppLastFile) != NULL) { + + if (pfBywayCallback) { + PCHAR pszFile = NULL; + if (!(*pfBywayCallback)(pContext, pszFile, &pszFile)) { + goto fail; + } + + if (pszFile) { + // Insert a new Byway. + CImageImportFile *pByway = NewByway(pszFile); + if (pByway == NULL) { + return FALSE; + } + + pByway->m_pNextFile = pImportFile; + *ppLastFile = pByway; + ppLastFile = &pByway->m_pNextFile; + continue; // Retry after Byway. + } + } + + if (pImportFile->m_fByway) { + if (pfBywayCallback) { + PCHAR pszFile = pImportFile->m_pszName; + + if (!(*pfBywayCallback)(pContext, pszFile, &pszFile)) { + goto fail; + } + + if (pszFile) { // Replace? Byway + if (ReplaceString(&pImportFile->m_pszName, pszFile) == NULL) { + goto fail; + } + } + else { // Delete Byway + *ppLastFile = pImportFile->m_pNextFile; + pImportFile->m_pNextFile = NULL; + delete pImportFile; + pImportFile = *ppLastFile; + m_nImportFiles--; + continue; // Retry after delete. + } + } + } + else { + if (pfFileCallback) { + PCHAR pszFile = pImportFile->m_pszName; + + if (!(*pfFileCallback)(pContext, pImportFile->m_pszOrig, + pszFile, &pszFile)) { + goto fail; + } + + if (pszFile != NULL) { + if (ReplaceString(&pImportFile->m_pszName, pszFile) == NULL) { + goto fail; + } + } + } + + if (pfSymbolCallback) { + for (DWORD n = 0; n < pImportFile->m_nImportNames; n++) { + CImageImportName *pImportName = &pImportFile->m_pImportNames[n]; + + PCHAR pszName = pImportName->m_pszName; + ULONG nOrdinal = pImportName->m_nOrdinal; + if (!(*pfSymbolCallback)(pContext, + pImportName->m_nOrig, + nOrdinal, + &nOrdinal, + pImportName->m_pszOrig, + pszName, + &pszName)) { + goto fail; + } + + if (pszName != NULL) { + pImportName->m_nOrdinal = 0; + if (ReplaceString(&pImportName->m_pszName, pszName) == NULL) { + goto fail; + } + } + else if (nOrdinal != 0) { + pImportName->m_nOrdinal = nOrdinal; + + if (pImportName->m_pszName != NULL) { + delete[] pImportName->m_pszName; + pImportName->m_pszName = NULL; + } + } + } + } + } + + ppLastFile = &pImportFile->m_pNextFile; + pImportFile = pImportFile->m_pNextFile; + } + + for (;;) { + if (pfBywayCallback) { + PCHAR pszFile = NULL; + if (!(*pfBywayCallback)(pContext, NULL, &pszFile)) { + goto fail; + } + if (pszFile) { + // Insert a new Byway. + CImageImportFile *pByway = NewByway(pszFile); + if (pByway == NULL) { + return FALSE; + } + + pByway->m_pNextFile = pImportFile; + *ppLastFile = pByway; + ppLastFile = &pByway->m_pNextFile; + continue; // Retry after Byway. + } + } + break; + } + + if (pfCommitCallback) { + if (!(*pfCommitCallback)(pContext)) { + goto fail; + } + } + + SetLastError(NO_ERROR); + return TRUE; + + fail: + return FALSE; +} + +BOOL CImage::Write(HANDLE hFile) +{ + DWORD cbDone; + + if (hFile == INVALID_HANDLE_VALUE) { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + m_nNextFileAddr = 0; + m_nNextVirtAddr = 0; + + DWORD nTables = 0; + DWORD nThunks = 0; + DWORD nChars = 0; + BOOL fNeedDetourSection = CheckImportsNeeded(&nTables, &nThunks, &nChars); + + //////////////////////////////////////////////////////////// Copy Headers. + // + if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!CopyFileData(hFile, 0, m_NtHeader.OptionalHeader.SizeOfHeaders)) { + return FALSE; + } + + if (fNeedDetourSection || !m_pImageData->IsEmpty()) { + // Replace the file's DOS header with our own. + m_nPeOffset = sizeof(m_DosHeader) + sizeof(s_rbDosCode); + m_nSectionsOffset = m_nPeOffset + + sizeof(m_NtHeader.Signature) + + sizeof(m_NtHeader.FileHeader) + + m_NtHeader.FileHeader.SizeOfOptionalHeader; + m_DosHeader.e_lfanew = m_nPeOffset; + + if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!WriteFile(hFile, &m_DosHeader, sizeof(m_DosHeader), &cbDone)) { + return FALSE; + } + if (!WriteFile(hFile, &s_rbDosCode, sizeof(s_rbDosCode), &cbDone)) { + return FALSE; + } + } + else { + // Restore the file's original DOS header. + if (m_nPrePE != 0) { + m_nPeOffset = m_cbPrePE; + m_nSectionsOffset = m_nPeOffset + + sizeof(m_NtHeader.Signature) + + sizeof(m_NtHeader.FileHeader) + + m_NtHeader.FileHeader.SizeOfOptionalHeader; + m_DosHeader.e_lfanew = m_nPeOffset; + + + if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!CopyFileData(hFile, m_nPrePE, m_cbPrePE)) { + return FALSE; + } + } + } + + m_nNextFileAddr = m_NtHeader.OptionalHeader.SizeOfHeaders; + m_nNextVirtAddr = 0; + if (!AlignFileData(hFile)) { + return FALSE; + } + + /////////////////////////////////////////////////////////// Copy Sections. + // + DWORD n = 0; + for (; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + if (m_SectionHeaders[n].SizeOfRawData) { + if (SetFilePointer(hFile, + m_SectionHeaders[n].PointerToRawData, + NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!CopyFileData(hFile, + m_SectionHeaders[n].PointerToRawData, + m_SectionHeaders[n].SizeOfRawData)) { + return FALSE; + } + } + m_nNextFileAddr = Max(m_SectionHeaders[n].PointerToRawData + + m_SectionHeaders[n].SizeOfRawData, + m_nNextFileAddr); + m_nNextVirtAddr = Max(m_SectionHeaders[n].VirtualAddress + + m_SectionHeaders[n].Misc.VirtualSize, + m_nNextVirtAddr); + m_nExtraOffset = Max(m_nNextFileAddr, m_nExtraOffset); + + if (!AlignFileData(hFile)) { + return FALSE; + } + } + + if (fNeedDetourSection || !m_pImageData->IsEmpty()) { + ////////////////////////////////////////////// Insert .detour Section. + // + DWORD nSection = m_NtHeader.FileHeader.NumberOfSections++; + DETOUR_SECTION_HEADER dh; + + ZeroMemory(&dh, sizeof(dh)); + ZeroMemory(&m_SectionHeaders[nSection], sizeof(m_SectionHeaders[nSection])); + + dh.cbHeaderSize = sizeof(DETOUR_SECTION_HEADER); + dh.nSignature = DETOUR_SECTION_HEADER_SIGNATURE; + + dh.nOriginalImportVirtualAddress = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; + dh.nOriginalImportSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size; + + dh.nOriginalBoundImportVirtualAddress + = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress; + dh.nOriginalBoundImportSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size; + + dh.nOriginalIatVirtualAddress = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; + dh.nOriginalIatSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size; + + dh.nOriginalSizeOfImage = m_NtHeader.OptionalHeader.SizeOfImage; + + DWORD clrAddr = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; + DWORD clrSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; + if (clrAddr && clrSize) { + PDETOUR_CLR_HEADER pHdr = (PDETOUR_CLR_HEADER)RvaToVa(clrAddr); + if (pHdr != NULL) { + DETOUR_CLR_HEADER hdr; + hdr = *pHdr; + + dh.nOriginalClrFlags = hdr.Flags; + } + } + + HRESULT hrRet = StringCchCopyA((PCHAR)m_SectionHeaders[nSection].Name, IMAGE_SIZEOF_SHORT_NAME , ".detour"); + if (FAILED(hrRet)) + return FALSE; + + m_SectionHeaders[nSection].Characteristics + = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE; + + m_nOutputVirtAddr = m_nNextVirtAddr; + m_nOutputVirtSize = 0; + m_nOutputFileAddr = m_nNextFileAddr; + + dh.nDataOffset = 0; // pbData + dh.cbDataSize = m_pImageData->m_cbData; + dh.cbPrePE = m_cbPrePE; + + ////////////////////////////////////////////////////////////////////////// + // + + DWORD rvaImportTable = 0; + DWORD rvaLookupTable = 0; + DWORD rvaBoundTable = 0; + DWORD rvaNameTable = 0; + DWORD nImportTableSize = nTables * sizeof(IMAGE_IMPORT_DESCRIPTOR); + + if (!SizeOutputBuffer(QuadAlign(sizeof(dh)) + + m_cbPrePE + + QuadAlign(m_pImageData->m_cbData) + + QuadAlign(sizeof(IMAGE_THUNK_DATA) * nThunks) + + QuadAlign(sizeof(IMAGE_THUNK_DATA) * nThunks) + + QuadAlign(nChars) + + QuadAlign(nImportTableSize))) { + return FALSE; + } + + DWORD vaHead = 0; + PBYTE pbHead = NULL; + DWORD vaPrePE = 0; + PBYTE pbPrePE = NULL; + DWORD vaData = 0; + PBYTE pbData = NULL; + + if ((pbHead = AllocateOutput(sizeof(dh), &vaHead)) == NULL) { + return FALSE; + } + + if ((pbPrePE = AllocateOutput(m_cbPrePE, &vaPrePE)) == NULL) { + return FALSE; + } + + CImageThunks lookupTable(this, nThunks, &rvaLookupTable); + CImageThunks boundTable(this, nThunks, &rvaBoundTable); + CImageChars nameTable(this, nChars, &rvaNameTable); + + if ((pbData = AllocateOutput(m_pImageData->m_cbData, &vaData)) == NULL) { + return FALSE; + } + + dh.nDataOffset = vaData - vaHead; + dh.cbDataSize = dh.nDataOffset + m_pImageData->m_cbData; + CopyMemory(pbHead, &dh, sizeof(dh)); + CopyMemory(pbPrePE, m_pMap + m_nPrePE, m_cbPrePE); + CopyMemory(pbData, m_pImageData->m_pbData, m_pImageData->m_cbData); + + PIMAGE_IMPORT_DESCRIPTOR piidDst = (PIMAGE_IMPORT_DESCRIPTOR) + AllocateOutput(nImportTableSize, &rvaImportTable); + if (piidDst == NULL) { + return FALSE; + } + + //////////////////////////////////////////////// Step Through Imports. + // + for (CImageImportFile *pImportFile = m_pImportFiles; + pImportFile != NULL; pImportFile = pImportFile->m_pNextFile) { + + ZeroMemory(piidDst, sizeof(piidDst)); + nameTable.Allocate(pImportFile->m_pszName, (DWORD *)&piidDst->Name); + piidDst->TimeDateStamp = 0; + piidDst->ForwarderChain = pImportFile->m_nForwarderChain; + + if (pImportFile->m_fByway) { + ULONG rvaIgnored; + + lookupTable.Allocate(IMAGE_ORDINAL_FLAG+1, + (DWORD *)&piidDst->OriginalFirstThunk); + boundTable.Allocate(IMAGE_ORDINAL_FLAG+1, + (DWORD *)&piidDst->FirstThunk); + + lookupTable.Allocate(0, &rvaIgnored); + boundTable.Allocate(0, &rvaIgnored); + } + else { + ULONG rvaIgnored; + + piidDst->FirstThunk = (ULONG)pImportFile->m_rvaFirstThunk; + lookupTable.Current((DWORD *)&piidDst->OriginalFirstThunk); + + for (n = 0; n < pImportFile->m_nImportNames; n++) { + CImageImportName *pImportName = &pImportFile->m_pImportNames[n]; + + if (pImportName->m_pszName) { + ULONG nDstName = 0; + + nameTable.Allocate(pImportName->m_pszName, + pImportName->m_nHint, + &nDstName); + lookupTable.Allocate(nDstName, &rvaIgnored); + } + else { + lookupTable.Allocate(IMAGE_ORDINAL_FLAG + pImportName->m_nOrdinal, + &rvaIgnored); + } + } + lookupTable.Allocate(0, &rvaIgnored); + } + piidDst++; + } + ZeroMemory(piidDst, sizeof(piidDst)); + + ////////////////////////////////////////////////////////////////////////// + // + m_nNextVirtAddr += m_nOutputVirtSize; + m_nNextFileAddr += FileAlign(m_nOutputVirtSize); + + if (!AlignFileData(hFile)) { + return FALSE; + } + + ////////////////////////////////////////////////////////////////////////// + // + m_SectionHeaders[nSection].VirtualAddress = m_nOutputVirtAddr; + m_SectionHeaders[nSection].Misc.VirtualSize = m_nOutputVirtSize; + m_SectionHeaders[nSection].PointerToRawData = m_nOutputFileAddr; + m_SectionHeaders[nSection].SizeOfRawData = FileAlign(m_nOutputVirtSize); + + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress + = rvaImportTable; + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size + = nImportTableSize; + + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress = 0; + m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size = 0; + + ////////////////////////////////////////////////////////////////////////// + // + if (SetFilePointer(hFile, m_SectionHeaders[nSection].PointerToRawData, + NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!WriteFile(hFile, m_pbOutputBuffer, m_SectionHeaders[nSection].SizeOfRawData, + &cbDone)) { + return FALSE; + } + } + + ///////////////////////////////////////////////////// Adjust Extra Data. + // + LONG nExtraAdjust = m_nNextFileAddr - m_nExtraOffset; + for (n = 0; n < m_NtHeader.FileHeader.NumberOfSections; n++) { + if (m_SectionHeaders[n].PointerToRawData > m_nExtraOffset) { + m_SectionHeaders[n].PointerToRawData += nExtraAdjust; + } + if (m_SectionHeaders[n].PointerToRelocations > m_nExtraOffset) { + m_SectionHeaders[n].PointerToRelocations += nExtraAdjust; + } + if (m_SectionHeaders[n].PointerToLinenumbers > m_nExtraOffset) { + m_SectionHeaders[n].PointerToLinenumbers += nExtraAdjust; + } + } + if (m_NtHeader.FileHeader.PointerToSymbolTable > m_nExtraOffset) { + m_NtHeader.FileHeader.PointerToSymbolTable += nExtraAdjust; + } + + m_NtHeader.OptionalHeader.CheckSum = 0; + m_NtHeader.OptionalHeader.SizeOfImage = m_nNextVirtAddr; + + ////////////////////////////////////////////////// Adjust Debug Directory. + // + DWORD debugAddr = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; + DWORD debugSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size; + if (debugAddr && debugSize) { + DWORD nFileOffset = RvaToFileOffset(debugAddr); + if (SetFilePointer(hFile, nFileOffset, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + + PIMAGE_DEBUG_DIRECTORY pDir = (PIMAGE_DEBUG_DIRECTORY)RvaToVa(debugAddr); + if (pDir == NULL) { + return FALSE; + } + + DWORD nEntries = debugSize / sizeof(*pDir); + for (n = 0; n < nEntries; n++) { + IMAGE_DEBUG_DIRECTORY dir = pDir[n]; + + if (dir.PointerToRawData > m_nExtraOffset) { + dir.PointerToRawData += nExtraAdjust; + } + if (!WriteFile(hFile, &dir, sizeof(dir), &cbDone)) { + return FALSE; + } + } + } + + /////////////////////////////////////////////////////// Adjust CLR Header. + // + DWORD clrAddr = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; + DWORD clrSize = m_NtHeader.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; + if (clrAddr && clrSize && fNeedDetourSection) { + DWORD nFileOffset = RvaToFileOffset(clrAddr); + if (SetFilePointer(hFile, nFileOffset, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + + PDETOUR_CLR_HEADER pHdr = (PDETOUR_CLR_HEADER)RvaToVa(clrAddr); + if (pHdr == NULL) { + return FALSE; + } + + DETOUR_CLR_HEADER hdr; + hdr = *pHdr; + hdr.Flags &= 0xfffffffe; // Clear the IL_ONLY flag. + + if (!WriteFile(hFile, &hdr, sizeof(hdr), &cbDone)) { + return FALSE; + } + } + + ///////////////////////////////////////////////// Copy Left-over Data. + // + if (m_nFileSize > m_nExtraOffset) { + if (SetFilePointer(hFile, m_nNextFileAddr, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!CopyFileData(hFile, m_nExtraOffset, m_nFileSize - m_nExtraOffset)) { + return FALSE; + } + } + + + //////////////////////////////////////////////////// Finalize Headers. + // + + if (SetFilePointer(hFile, m_nPeOffset, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!WriteFile(hFile, &m_NtHeader, sizeof(m_NtHeader), &cbDone)) { + return FALSE; + } + + if (SetFilePointer(hFile, m_nSectionsOffset, NULL, FILE_BEGIN) == ~0u) { + return FALSE; + } + if (!WriteFile(hFile, &m_SectionHeaders, + sizeof(m_SectionHeaders[0]) + * m_NtHeader.FileHeader.NumberOfSections, + &cbDone)) { + return FALSE; + } + + m_cbPostPE = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if (m_cbPostPE == ~0u) { + return FALSE; + } + m_cbPostPE = m_NtHeader.OptionalHeader.SizeOfHeaders - m_cbPostPE; + + return TRUE; +} + +}; // namespace Detour + + +////////////////////////////////////////////////////////////////////////////// +// +PDETOUR_BINARY WINAPI DetourBinaryOpen(HANDLE hFile) +{ + Detour::CImage *pImage = new Detour::CImage; + if (pImage == NULL) { + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + + if (!pImage->Read(hFile)) { + delete pImage; + return FALSE; + } + + return (PDETOUR_BINARY)pImage; +} + +BOOL WINAPI DetourBinaryWrite(PDETOUR_BINARY pdi, HANDLE hFile) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->Write(hFile); +} + +PVOID WINAPI DetourBinaryEnumeratePayloads(PDETOUR_BINARY pdi, + GUID *pGuid, + DWORD *pcbData, + DWORD *pnIterator) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->DataEnum(pGuid, pcbData, pnIterator); +} + +PVOID WINAPI DetourBinaryFindPayload(PDETOUR_BINARY pdi, + REFGUID rguid, + DWORD *pcbData) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->DataFind(rguid, pcbData); +} + +PVOID WINAPI DetourBinarySetPayload(PDETOUR_BINARY pdi, + REFGUID rguid, + PVOID pvData, + DWORD cbData) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->DataSet(rguid, (PBYTE)pvData, cbData); +} + +BOOL WINAPI DetourBinaryDeletePayload(PDETOUR_BINARY pdi, + REFGUID rguid) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->DataDelete(rguid); +} + +BOOL WINAPI DetourBinaryPurgePayloads(PDETOUR_BINARY pdi) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->DataPurge(); +} + +////////////////////////////////////////////////////////////////////////////// +// +static BOOL CALLBACK ResetBywayCallback(PVOID pContext, + __in_z PCHAR pszFile, + __deref PCHAR *ppszOutFile) +{ + (void)pContext; + (void)pszFile; + + *ppszOutFile = NULL; + return TRUE; +} + +static BOOL CALLBACK ResetFileCallback(PVOID pContext, + __in_z PCHAR pszOrigFile, + __in_z PCHAR pszFile, + __deref PCHAR *ppszOutFile) +{ + (void)pContext; + (void)pszFile; + + *ppszOutFile = pszOrigFile; + return TRUE; +} + +static BOOL CALLBACK ResetSymbolCallback(PVOID pContext, + ULONG nOrigOrdinal, + ULONG nOrdinal, + ULONG *pnOutOrdinal, + __in_z PCHAR pszOrigSymbol, + __in_z PCHAR pszSymbol, + __deref PCHAR *ppszOutSymbol) +{ + (void)pContext; + (void)nOrdinal; + (void)pszSymbol; + + *pnOutOrdinal = nOrigOrdinal; + *ppszOutSymbol = pszOrigSymbol; + return TRUE; +} + +BOOL WINAPI DetourBinaryResetImports(PDETOUR_BINARY pdi) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->EditImports(NULL, + ResetBywayCallback, + ResetFileCallback, + ResetSymbolCallback, + NULL); +} + +////////////////////////////////////////////////////////////////////////////// +// +BOOL WINAPI DetourBinaryEditImports(PDETOUR_BINARY pdi, + PVOID pContext, + PF_DETOUR_BINARY_BYWAY_CALLBACK pfBywayCallback, + PF_DETOUR_BINARY_FILE_CALLBACK pfFileCallback, + PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbolCallback, + PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommitCallback) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + return pImage->EditImports(pContext, + pfBywayCallback, + pfFileCallback, + pfSymbolCallback, + pfCommitCallback); +} + +BOOL WINAPI DetourBinaryClose(PDETOUR_BINARY pdi) +{ + Detour::CImage *pImage = Detour::CImage::IsValid(pdi); + if (pImage == NULL) { + return FALSE; + } + + BOOL bSuccess = pImage->Close(); + delete pImage; + pImage = NULL; + + return bSuccess; +} + +// +///////////////////////////////////////////////////////////////// End of File. diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/modules.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/modules.cpp new file mode 100644 index 0000000..a84b0ca --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/modules.cpp @@ -0,0 +1,928 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Module Enumeration Functions (modules.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Module enumeration functions. +// + +#include +#if (_MSC_VER < 1310) +#else +#include +#endif + +//#define DETOUR_DEBUG 1 +#define DETOURS_INTERNAL +#include "detours.h" + +#define CLR_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] +#define IAT_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] + +////////////////////////////////////////////////////////////////////////////// +// +#ifndef _STRSAFE_H_INCLUDED_ +static inline HRESULT StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch) +{ + HRESULT hr = S_OK; + size_t cchMaxPrev = cchMax; + + if (cchMax > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + while (cchMax && (*psz != '\0')) + { + psz++; + cchMax--; + } + + if (cchMax == 0) + { + // the string is longer than cchMax + hr = ERROR_INVALID_PARAMETER; + } + + if (SUCCEEDED(hr) && pcch) + { + *pcch = cchMaxPrev - cchMax; + } + + return hr; +} + + +static inline HRESULT StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr = S_OK; + + if (cchDest == 0) + { + // can not null terminate a zero-byte dest buffer + hr = ERROR_INVALID_PARAMETER; + } + else + { + while (cchDest && (*pszSrc != '\0')) + { + *pszDest++ = *pszSrc++; + cchDest--; + } + + if (cchDest == 0) + { + // we are going to truncate pszDest + pszDest--; + hr = ERROR_INVALID_PARAMETER; + } + + *pszDest= '\0'; + } + + return hr; +} + +static inline HRESULT StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc) +{ + HRESULT hr; + size_t cchDestCurrent; + + if (cchDest > 2147483647) + { + return ERROR_INVALID_PARAMETER; + } + + hr = StringCchLengthA(pszDest, cchDest, &cchDestCurrent); + + if (SUCCEEDED(hr)) + { + hr = StringCchCopyA(pszDest + cchDestCurrent, + cchDest - cchDestCurrent, + pszSrc); + } + + return hr; +} + +#endif + +////////////////////////////////////////////////////////////////////////////// +// +const GUID DETOUR_EXE_RESTORE_GUID = { + 0x2ed7a3ff, 0x3339, 0x4a8d, + { 0x80, 0x5c, 0xd4, 0x98, 0x15, 0x3f, 0xc2, 0x8f }}; + +const GUID DETOUR_EXE_HELPER_GUID = { /* ea0251b9-5cde-41b5-98d0-2af4a26b0fee */ + 0xea0251b9, 0x5cde, 0x41b5, + { 0x98, 0xd0, 0x2a, 0xf4, 0xa2, 0x6b, 0x0f, 0xee }}; + +////////////////////////////////////////////////////////////////////////////// +// +PDETOUR_SYM_INFO DetourLoadImageHlp(VOID) +{ + static DETOUR_SYM_INFO symInfo; + static PDETOUR_SYM_INFO pSymInfo = NULL; + static BOOL failed = false; + + if (failed) { + return NULL; + } + if (pSymInfo != NULL) { + return pSymInfo; + } + + ZeroMemory(&symInfo, sizeof(symInfo)); + // Create a real handle to the process. +#if 0 + DuplicateHandle(GetCurrentProcess(), + GetCurrentProcess(), + GetCurrentProcess(), + &symInfo.hProcess, + 0, + FALSE, + DUPLICATE_SAME_ACCESS); +#else + symInfo.hProcess = GetCurrentProcess(); +#endif + + symInfo.hDbgHelp = LoadLibraryExW(L"dbghelp.dll", NULL, 0); + if (symInfo.hDbgHelp == NULL) { + abort: + failed = true; + if (symInfo.hDbgHelp != NULL) { + FreeLibrary(symInfo.hDbgHelp); + } + symInfo.pfImagehlpApiVersionEx = NULL; + symInfo.pfSymInitialize = NULL; + symInfo.pfSymSetOptions = NULL; + symInfo.pfSymGetOptions = NULL; + symInfo.pfSymLoadModule64 = NULL; + symInfo.pfSymGetModuleInfo64 = NULL; + symInfo.pfSymFromName = NULL; + return NULL; + } + + symInfo.pfImagehlpApiVersionEx + = (PF_ImagehlpApiVersionEx)GetProcAddress(symInfo.hDbgHelp, + "ImagehlpApiVersionEx"); + symInfo.pfSymInitialize + = (PF_SymInitialize)GetProcAddress(symInfo.hDbgHelp, "SymInitialize"); + symInfo.pfSymSetOptions + = (PF_SymSetOptions)GetProcAddress(symInfo.hDbgHelp, "SymSetOptions"); + symInfo.pfSymGetOptions + = (PF_SymGetOptions)GetProcAddress(symInfo.hDbgHelp, "SymGetOptions"); + symInfo.pfSymLoadModule64 + = (PF_SymLoadModule64)GetProcAddress(symInfo.hDbgHelp, "SymLoadModule64"); + symInfo.pfSymGetModuleInfo64 + = (PF_SymGetModuleInfo64)GetProcAddress(symInfo.hDbgHelp, "SymGetModuleInfo64"); + symInfo.pfSymFromName + = (PF_SymFromName)GetProcAddress(symInfo.hDbgHelp, "SymFromName"); + + API_VERSION av; + ZeroMemory(&av, sizeof(av)); + av.MajorVersion = API_VERSION_NUMBER; + + if (symInfo.pfImagehlpApiVersionEx == NULL || + symInfo.pfSymInitialize == NULL || + symInfo.pfSymLoadModule64 == NULL || + symInfo.pfSymGetModuleInfo64 == NULL || + symInfo.pfSymFromName == NULL) { + goto abort; + } + + symInfo.pfImagehlpApiVersionEx(&av); + if (av.MajorVersion < API_VERSION_NUMBER) { + goto abort; + } + + if (!symInfo.pfSymInitialize(symInfo.hProcess, NULL, FALSE)) { + // We won't retry the initialize if it fails. + goto abort; + } + + if (symInfo.pfSymGetOptions != NULL && symInfo.pfSymSetOptions != NULL) { + DWORD dw = symInfo.pfSymGetOptions(); + + dw &= ~(SYMOPT_CASE_INSENSITIVE | + SYMOPT_UNDNAME | + SYMOPT_DEFERRED_LOADS | + 0); + dw |= ( +#if defined(SYMOPT_EXACT_SYMBOLS) + SYMOPT_EXACT_SYMBOLS | +#endif +#if defined(SYMOPT_NO_UNQUALIFIED_LOADS) + SYMOPT_NO_UNQUALIFIED_LOADS | +#endif + SYMOPT_DEFERRED_LOADS | +#if defined(SYMOPT_FAIL_CRITICAL_ERRORS) + SYMOPT_FAIL_CRITICAL_ERRORS | +#endif +#if defined(SYMOPT_INCLUDE_32BIT_MODULES) + SYMOPT_INCLUDE_32BIT_MODULES | +#endif + 0); + symInfo.pfSymSetOptions(dw); + } + + pSymInfo = &symInfo; + return pSymInfo; +} + +PVOID WINAPI DetourFindFunction(PCSTR pszModule, PCSTR pszFunction) +{ + /////////////////////////////////////////////// First, try GetProcAddress. + // + HMODULE hModule = LoadLibraryExA(pszModule, NULL, 0); + if (hModule == NULL) { + return NULL; + } + + PBYTE pbCode = (PBYTE)GetProcAddress(hModule, pszFunction); + if (pbCode) { + return pbCode; + } + + ////////////////////////////////////////////////////// Then try ImageHelp. + // + DETOUR_TRACE(("DetourFindFunction(%s, %s)\n", pszModule, pszFunction)); + PDETOUR_SYM_INFO pSymInfo = DetourLoadImageHlp(); + if (pSymInfo == NULL) { + DETOUR_TRACE(("DetourLoadImageHlp failed: %d\n", + GetLastError())); + return NULL; + } + + if (pSymInfo->pfSymLoadModule64(pSymInfo->hProcess, NULL, + (PCHAR)pszModule, NULL, + (DWORD64)hModule, 0) == 0) { + if (ERROR_SUCCESS != GetLastError()) { + DETOUR_TRACE(("SymLoadModule64(%p) failed: %d\n", + pSymInfo->hProcess, GetLastError())); + return NULL; + } + } + + HRESULT hrRet; + CHAR szFullName[512]; + IMAGEHLP_MODULE64 modinfo; + ZeroMemory(&modinfo, sizeof(modinfo)); + modinfo.SizeOfStruct = sizeof(modinfo); + if (!pSymInfo->pfSymGetModuleInfo64(pSymInfo->hProcess, (DWORD64)hModule, &modinfo)) { + DETOUR_TRACE(("SymGetModuleInfo64(%p, %p) failed: %d\n", + pSymInfo->hProcess, hModule, GetLastError())); + return NULL; + } + + hrRet = StringCchCopyA(szFullName, sizeof(szFullName)/sizeof(CHAR), modinfo.ModuleName); + if (FAILED(hrRet)) { + DETOUR_TRACE(("StringCchCopyA failed: %08x\n", hrRet)); + return NULL; + } + hrRet = StringCchCatA(szFullName, sizeof(szFullName)/sizeof(CHAR), "!"); + if (FAILED(hrRet)) { + DETOUR_TRACE(("StringCchCatA failed: %08x\n", hrRet)); + return NULL; + } + hrRet = StringCchCatA(szFullName, sizeof(szFullName)/sizeof(CHAR), pszFunction); + if (FAILED(hrRet)) { + DETOUR_TRACE(("StringCchCatA failed: %08x\n", hrRet)); + return NULL; + } + + struct CFullSymbol : SYMBOL_INFO { + CHAR szRestOfName[512]; + } symbol; + ZeroMemory(&symbol, sizeof(symbol)); + //symbol.ModBase = (ULONG64)hModule; + symbol.SizeOfStruct = sizeof(SYMBOL_INFO); +#ifdef DBHLPAPI + symbol.MaxNameLen = sizeof(symbol.szRestOfName)/sizeof(symbol.szRestOfName[0]); +#else + symbol.MaxNameLength = sizeof(symbol.szRestOfName)/sizeof(symbol.szRestOfName[0]); +#endif + + if (!pSymInfo->pfSymFromName(pSymInfo->hProcess, szFullName, &symbol)) { + DETOUR_TRACE(("SymFromName(%s) failed: %d\n", szFullName, GetLastError())); + return NULL; + } + +#if defined(DETOURS_IA64) + // On the IA64, we get a raw code pointer from the symbol engine + // and have to convert it to a wrapped [code pointer, global pointer]. + // + PPLABEL_DESCRIPTOR pldEntry = (PPLABEL_DESCRIPTOR)DetourGetEntryPoint(hModule); + PPLABEL_DESCRIPTOR pldSymbol = new PLABEL_DESCRIPTOR; + + pldSymbol->EntryPoint = symbol.Address; + pldSymbol->GlobalPointer = pldEntry->GlobalPointer; + return (PBYTE)pldSymbol; +#elif defined(DETOURS_ARM) + // On the ARM, we get a raw code pointer, which we must convert into a + // valied Thumb2 function pointer. + return DETOURS_PBYTE_TO_PFUNC(symbol.Address); +#else + return (PBYTE)symbol.Address; +#endif +} + +//////////////////////////////////////////////////// Module Image Functions. +// +HMODULE WINAPI DetourEnumerateModules(HMODULE hModuleLast) +{ + PBYTE pbLast; + + if (hModuleLast == NULL) { + pbLast = (PBYTE)0x10000; + } + else { + pbLast = (PBYTE)hModuleLast + 0x10000; + } + + MEMORY_BASIC_INFORMATION mbi; + ZeroMemory(&mbi, sizeof(mbi)); + + // Find the next memory region that contains a mapped PE image. + // + for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { + if (VirtualQuery((PVOID)pbLast, &mbi, sizeof(mbi)) <= 0) { + break; + } + + // Skip uncommitted regions and guard pages. + // + if ((mbi.State != MEM_COMMIT) || + ((mbi.Protect & 0xff) == PAGE_NOACCESS) || + (mbi.Protect & PAGE_GUARD)) { + continue; + } + + __try { + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pbLast; + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE || + (DWORD)pDosHeader->e_lfanew > mbi.RegionSize || + (DWORD)pDosHeader->e_lfanew < sizeof(*pDosHeader)) { + continue; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + continue; + } + + return (HMODULE)pDosHeader; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + continue; + } + } + return NULL; +} + +PVOID WINAPI DetourGetEntryPoint(HMODULE hModule) +{ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; + if (hModule == NULL) { + pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); + } + + __try { + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } + + PDETOUR_CLR_HEADER pClrHeader = NULL; + if (pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.VirtualAddress != 0 && + ((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.Size != 0) { + pClrHeader = (PDETOUR_CLR_HEADER) + (((PBYTE)pDosHeader) + + ((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.VirtualAddress); + } + } + else if (pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + if (((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.VirtualAddress != 0 && + ((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.Size != 0) { + pClrHeader = (PDETOUR_CLR_HEADER) + (((PBYTE)pDosHeader) + + ((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.VirtualAddress); + } + } + + if (pClrHeader != NULL) { + // For MSIL assemblies, we want to use the _Cor entry points. + + HMODULE hClr = GetModuleHandleW(L"MSCOREE.DLL"); + if (hClr == NULL) { + return NULL; + } + + SetLastError(NO_ERROR); + return GetProcAddress(hClr, "_CorExeMain"); + } + + SetLastError(NO_ERROR); + return ((PBYTE)pDosHeader) + + pNtHeader->OptionalHeader.AddressOfEntryPoint; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } +} + +ULONG WINAPI DetourGetModuleSize(HMODULE hModule) +{ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; + if (hModule == NULL) { + pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); + } + + __try { + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } + SetLastError(NO_ERROR); + + return (pNtHeader->OptionalHeader.SizeOfImage); + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } +} + +HMODULE WINAPI DetourGetContainingModule(PVOID pvAddr) +{ + MEMORY_BASIC_INFORMATION mbi; + ZeroMemory(&mbi, sizeof(mbi)); + + __try { + if (VirtualQuery(pvAddr, &mbi, sizeof(mbi)) <= 0) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + // Skip uncommitted regions and guard pages. + // + if ((mbi.State != MEM_COMMIT) || + ((mbi.Protect & 0xff) == PAGE_NOACCESS) || + (mbi.Protect & PAGE_GUARD)) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)mbi.AllocationBase; + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } + SetLastError(NO_ERROR); + + return (HMODULE)pDosHeader; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } +} + + +static inline PBYTE RvaAdjust(PIMAGE_DOS_HEADER pDosHeader, DWORD raddr) +{ + if (raddr != NULL) { + return ((PBYTE)pDosHeader) + raddr; + } + return NULL; +} + +BOOL WINAPI DetourEnumerateExports(HMODULE hModule, + PVOID pContext, + PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport) +{ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; + if (hModule == NULL) { + pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); + } + + __try { + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return FALSE; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + PIMAGE_EXPORT_DIRECTORY pExportDir + = (PIMAGE_EXPORT_DIRECTORY) + RvaAdjust(pDosHeader, + pNtHeader->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + + if (pExportDir == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + PDWORD pdwFunctions = (PDWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfFunctions); + PDWORD pdwNames = (PDWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfNames); + PWORD pwOrdinals = (PWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfNameOrdinals); + + for (DWORD nFunc = 0; nFunc < pExportDir->NumberOfFunctions; nFunc++) { + PBYTE pbCode = (pdwFunctions != NULL) + ? (PBYTE)RvaAdjust(pDosHeader, pdwFunctions[nFunc]) : NULL; + PCHAR pszName = NULL; + for (DWORD n = 0; n < pExportDir->NumberOfNames; n++) { + if (pwOrdinals[n] == nFunc) { + pszName = (pdwNames != NULL) + ? (PCHAR)RvaAdjust(pDosHeader, pdwNames[n]) : NULL; + break; + } + } + ULONG nOrdinal = pExportDir->Base + nFunc; + + if (!pfExport(pContext, nOrdinal, pszName, pbCode)) { + break; + } + } + SetLastError(NO_ERROR); + return TRUE; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } +} + +BOOL WINAPI DetourEnumerateImports(HMODULE hModule, + PVOID pContext, + PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc) +{ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; + if (hModule == NULL) { + pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); + } + + __try { + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return FALSE; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return FALSE; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + PIMAGE_IMPORT_DESCRIPTOR iidp + = (PIMAGE_IMPORT_DESCRIPTOR) + RvaAdjust(pDosHeader, + pNtHeader->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); + + if (iidp == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + for (; iidp->OriginalFirstThunk != 0; iidp++) { + + PCSTR pszName = (PCHAR)RvaAdjust(pDosHeader, iidp->Name); + if (pszName == NULL) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } + + PIMAGE_THUNK_DATA pThunks = (PIMAGE_THUNK_DATA) + RvaAdjust(pDosHeader, iidp->OriginalFirstThunk); + PVOID * pAddrs = (PVOID *) + RvaAdjust(pDosHeader, iidp->FirstThunk); + + HMODULE hFile = DetourGetContainingModule(pAddrs[0]); + + if (pfImportFile != NULL) { + if (!pfImportFile(pContext, hFile, pszName)) { + break; + } + } + + DWORD nNames = 0; + if (pThunks) { + for (; pThunks[nNames].u1.Ordinal; nNames++) { + DWORD nOrdinal = 0; + PCSTR pszFunc = NULL; + + if (IMAGE_SNAP_BY_ORDINAL(pThunks[nNames].u1.Ordinal)) { + nOrdinal = (DWORD)IMAGE_ORDINAL(pThunks[nNames].u1.Ordinal); + } + else { + pszFunc = (PCSTR)RvaAdjust(pDosHeader, + (DWORD)pThunks[nNames].u1.AddressOfData + 2); + } + + if (pfImportFunc != NULL) { + if (!pfImportFunc(pContext, + nOrdinal, + pszFunc, + pAddrs[nNames])) { + break; + } + } + } + if (pfImportFunc != NULL) { + pfImportFunc(pContext, 0, NULL, NULL); + } + } + } + if (pfImportFile != NULL) { + pfImportFile(pContext, NULL, NULL); + } + SetLastError(NO_ERROR); + return TRUE; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return FALSE; + } +} + +static PDETOUR_LOADED_BINARY WINAPI GetPayloadSectionFromModule(HMODULE hModule) +{ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; + if (hModule == NULL) { + pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); + } + + __try { + if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return NULL; + } + + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + + pDosHeader->e_lfanew); + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } + if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } + + PIMAGE_SECTION_HEADER pSectionHeaders + = (PIMAGE_SECTION_HEADER)((PBYTE)pNtHeader + + sizeof(pNtHeader->Signature) + + sizeof(pNtHeader->FileHeader) + + pNtHeader->FileHeader.SizeOfOptionalHeader); + + for (DWORD n = 0; n < pNtHeader->FileHeader.NumberOfSections; n++) { + if (strcmp((PCHAR)pSectionHeaders[n].Name, ".detour") == 0) { + if (pSectionHeaders[n].VirtualAddress == 0 || + pSectionHeaders[n].SizeOfRawData == 0) { + + break; + } + + PBYTE pbData = (PBYTE)pDosHeader + pSectionHeaders[n].VirtualAddress; + DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pbData; + if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || + pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { + + break; + } + + if (pHeader->nDataOffset == 0) { + pHeader->nDataOffset = pHeader->cbHeaderSize; + } + SetLastError(NO_ERROR); + return (PBYTE)pHeader; + } + } + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_EXE_MARKED_INVALID); + return NULL; + } +} + +DWORD WINAPI DetourGetSizeOfPayloads(HMODULE hModule) +{ + PDETOUR_LOADED_BINARY pBinary = GetPayloadSectionFromModule(hModule); + if (pBinary == NULL) { + // Error set by GetPayloadSectionFromModule. + return 0; + } + + __try { + DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pBinary; + if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || + pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { + + SetLastError(ERROR_INVALID_HANDLE); + return 0; + } + SetLastError(NO_ERROR); + return pHeader->cbDataSize; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_INVALID_HANDLE); + return 0; + } +} + +PVOID WINAPI DetourFindPayload(HMODULE hModule, REFGUID rguid, DWORD * pcbData) +{ + PBYTE pbData = NULL; + if (pcbData) { + *pcbData = 0; + } + + PDETOUR_LOADED_BINARY pBinary = GetPayloadSectionFromModule(hModule); + if (pBinary == NULL) { + // Error set by GetPayloadSectionFromModule. + return NULL; + } + + __try { + DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pBinary; + if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || + pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { + + SetLastError(ERROR_INVALID_EXE_SIGNATURE); + return NULL; + } + + PBYTE pbBeg = ((PBYTE)pHeader) + pHeader->nDataOffset; + PBYTE pbEnd = ((PBYTE)pHeader) + pHeader->cbDataSize; + + for (pbData = pbBeg; pbData < pbEnd;) { + DETOUR_SECTION_RECORD *pSection = (DETOUR_SECTION_RECORD *)pbData; + + if (pSection->guid.Data1 == rguid.Data1 && + pSection->guid.Data2 == rguid.Data2 && + pSection->guid.Data3 == rguid.Data3 && + pSection->guid.Data4[0] == rguid.Data4[0] && + pSection->guid.Data4[1] == rguid.Data4[1] && + pSection->guid.Data4[2] == rguid.Data4[2] && + pSection->guid.Data4[3] == rguid.Data4[3] && + pSection->guid.Data4[4] == rguid.Data4[4] && + pSection->guid.Data4[5] == rguid.Data4[5] && + pSection->guid.Data4[6] == rguid.Data4[6] && + pSection->guid.Data4[7] == rguid.Data4[7]) { + + if (pcbData) { + *pcbData = pSection->cbBytes - sizeof(*pSection); + SetLastError(NO_ERROR); + return (PBYTE)(pSection + 1); + } + } + + pbData = (PBYTE)pSection + pSection->cbBytes; + } + SetLastError(ERROR_INVALID_HANDLE); + return NULL; + } + __except(EXCEPTION_EXECUTE_HANDLER) { + SetLastError(ERROR_INVALID_HANDLE); + return NULL; + } +} + +PVOID WINAPI DetourFindPayloadEx(REFGUID rguid, DWORD * pcbData) +{ + for (HMODULE hMod = NULL; (hMod = DetourEnumerateModules(hMod)) != NULL;) { + PVOID pvData; + + pvData = DetourFindPayload(hMod, rguid, pcbData); + if (pvData != NULL) { + return pvData; + } + } + SetLastError(ERROR_MOD_NOT_FOUND); + return NULL; +} + +BOOL WINAPI DetourRestoreAfterWithEx(PVOID pvData, DWORD cbData) +{ + PDETOUR_EXE_RESTORE pder = (PDETOUR_EXE_RESTORE)pvData; + + if (pder->cb != sizeof(*pder) || pder->cb > cbData) { + SetLastError(ERROR_BAD_EXE_FORMAT); + return FALSE; + } + + DWORD dwPermIdh = ~0u; + DWORD dwPermInh = ~0u; + DWORD dwPermClr = ~0u; + DWORD dwIgnore; + BOOL fSucceeded = FALSE; + +#if 0 + if (pder->pclr != NULL && pder->clr.Flags != ((PDETOUR_CLR_HEADER)pder->pclr)->Flags) { + // If we had to promote the 32/64-bit agnostic IL to 64-bit, we don't want + // to restore its IAT. + __debugbreak(); + return TRUE; + } +#endif + + if (VirtualProtect(pder->pidh, pder->cbidh, + PAGE_EXECUTE_READWRITE, &dwPermIdh)) { + if (VirtualProtect(pder->pinh, pder->cbinh, + PAGE_EXECUTE_READWRITE, &dwPermInh)) { + + CopyMemory(pder->pidh, &pder->idh, pder->cbidh); + CopyMemory(pder->pinh, &pder->inh, pder->cbinh); + + if (pder->pclr != NULL) { + if (VirtualProtect(pder->pclr, pder->cbclr, + PAGE_EXECUTE_READWRITE, &dwPermClr)) { + CopyMemory(pder->pclr, &pder->clr, pder->cbclr); + VirtualProtect(pder->pclr, pder->cbclr, dwPermClr, &dwIgnore); + fSucceeded = TRUE; + } + } + else { + fSucceeded = TRUE; + } + VirtualProtect(pder->pinh, pder->cbinh, dwPermInh, &dwIgnore); + } + VirtualProtect(pder->pidh, pder->cbidh, dwPermIdh, &dwIgnore); + } + return fSucceeded; +} + +BOOL WINAPI DetourRestoreAfterWith() +{ + PVOID pvData; + DWORD cbData; + + pvData = DetourFindPayloadEx(DETOUR_EXE_RESTORE_GUID, &cbData); + + if (pvData != NULL && cbData != 0) { + return DetourRestoreAfterWithEx(pvData, cbData); + } + SetLastError(ERROR_MOD_NOT_FOUND); + return FALSE; +} + +// End of File diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/shiqi.la.url b/石器时代8.5客户端最新源代码/石器源码/detours/shiqi.la.url new file mode 100644 index 0000000..d7dcf24 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/shiqi.la.url @@ -0,0 +1,7 @@ +[InternetShortcut] +URL=http://www.shiqi.la/ +Modified=200AD33B9EC9C60166 +HotKey=0 +IDList= +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,2 diff --git a/石器时代8.5客户端最新源代码/石器源码/detours/uimports.cpp b/石器时代8.5客户端最新源代码/石器源码/detours/uimports.cpp new file mode 100644 index 0000000..9d999ee --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/detours/uimports.cpp @@ -0,0 +1,298 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Add DLLs to a module import table (uimports.cpp of detours.lib) +// +// Microsoft Research Detours Package, Version 3.0 Build_316. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Note that this file is included into creatwth.cpp one or more times +// (once for each supported module format). +// + +// UpdateImports32 aka UpdateImports64 +static BOOL UPDATE_IMPORTS_XX(HANDLE hProcess, + HMODULE hModule, + LPCSTR *plpDlls, + DWORD nDlls) +{ + BOOL fSucceeded = FALSE; + BYTE * pbNew = NULL; + DWORD i; + + PBYTE pbModule = (PBYTE)hModule; + + IMAGE_DOS_HEADER idh; + ZeroMemory(&idh, sizeof(idh)); + if (!ReadProcessMemory(hProcess, pbModule, &idh, sizeof(idh), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(idh@%p..%p) failed: %d\n", + pbModule, pbModule + sizeof(idh), GetLastError())); + + finish: + if (pbNew != NULL) { + delete[] pbNew; + pbNew = NULL; + } + return fSucceeded; + } + + IMAGE_NT_HEADERS_XX inh; + ZeroMemory(&inh, sizeof(inh)); + + if (!ReadProcessMemory(hProcess, pbModule + idh.e_lfanew, &inh, sizeof(inh), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(inh@%p..%p) failed: %d\n", + pbModule + idh.e_lfanew, + pbModule + idh.e_lfanew + sizeof(inh), + GetLastError())); + goto finish; + } + + if (inh.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC_XX) { + DETOUR_TRACE(("Wrong size image (%04x != %04x).\n", + inh.OptionalHeader.Magic, IMAGE_NT_OPTIONAL_HDR_MAGIC_XX)); + SetLastError(ERROR_INVALID_BLOCK); + goto finish; + } + + // Zero out the bound table so loader doesn't use it instead of our new table. + inh.BOUND_DIRECTORY.VirtualAddress = 0; + inh.BOUND_DIRECTORY.Size = 0; + + // Find the size of the mapped file. + DWORD dwFileSize = 0; + DWORD dwSec = idh.e_lfanew + + FIELD_OFFSET(IMAGE_NT_HEADERS_XX, OptionalHeader) + + inh.FileHeader.SizeOfOptionalHeader; + + for (i = 0; i < inh.FileHeader.NumberOfSections; i++) { + IMAGE_SECTION_HEADER ish; + ZeroMemory(&ish, sizeof(ish)); + + if (!ReadProcessMemory(hProcess, pbModule + dwSec + sizeof(ish) * i, &ish, + sizeof(ish), NULL)) { + DETOUR_TRACE(("ReadProcessMemory(ish@%p..%p) failed: %d\n", + pbModule + dwSec + sizeof(ish) * i, + pbModule + dwSec + sizeof(ish) * (i + 1), + GetLastError())); + goto finish; + } + + DETOUR_TRACE(("ish[%d] : va=%08x sr=%d\n", i, ish.VirtualAddress, ish.SizeOfRawData)); + + // If the file didn't have an IAT_DIRECTORY, we assign it... + if (inh.IAT_DIRECTORY.VirtualAddress == 0 && + inh.IMPORT_DIRECTORY.VirtualAddress >= ish.VirtualAddress && + inh.IMPORT_DIRECTORY.VirtualAddress < ish.VirtualAddress + ish.SizeOfRawData) { + + inh.IAT_DIRECTORY.VirtualAddress = ish.VirtualAddress; + inh.IAT_DIRECTORY.Size = ish.SizeOfRawData; + } + + // Find the end of the file... + if (dwFileSize < ish.PointerToRawData + ish.SizeOfRawData) { + dwFileSize = ish.PointerToRawData + ish.SizeOfRawData; + } + } + DETOUR_TRACE(("dwFileSize = %08x\n", dwFileSize)); + +#if IGNORE_CHECKSUMS + // Find the current checksum. + WORD wBefore = ComputeChkSum(hProcess, pbModule, &inh); + DETOUR_TRACE(("ChkSum: %04x + %08x => %08x\n", wBefore, dwFileSize, wBefore + dwFileSize)); +#endif + + DETOUR_TRACE((" Imports: %p..%p\n", + (DWORD_PTR)pbModule + inh.IMPORT_DIRECTORY.VirtualAddress, + (DWORD_PTR)pbModule + inh.IMPORT_DIRECTORY.VirtualAddress + + inh.IMPORT_DIRECTORY.Size)); + + DWORD obRem = sizeof(IMAGE_IMPORT_DESCRIPTOR) * nDlls; + DWORD obTab = PadToDwordPtr(obRem + + inh.IMPORT_DIRECTORY.Size + + sizeof(IMAGE_IMPORT_DESCRIPTOR)); + DWORD obDll = obTab + sizeof(DWORD_XX) * 4 * nDlls; + DWORD obStr = obDll; + DWORD cbNew = obStr; + DWORD n; + for (n = 0; n < nDlls; n++) { + cbNew += PadToDword((DWORD)strlen(plpDlls[n]) + 1); + } + + pbNew = new BYTE [cbNew]; + if (pbNew == NULL) { + DETOUR_TRACE(("new BYTE [cbNew] failed.\n")); + goto finish; + } + ZeroMemory(pbNew, cbNew); + + PBYTE pbBase = pbModule; + PBYTE pbNext = pbBase + + inh.OptionalHeader.BaseOfCode + + inh.OptionalHeader.SizeOfCode + + inh.OptionalHeader.SizeOfInitializedData + + inh.OptionalHeader.SizeOfUninitializedData; + if (pbBase < pbNext) { + pbBase = pbNext; + } + DETOUR_TRACE(("pbBase = %p\n", pbBase)); + + PBYTE pbNewIid = FindAndAllocateNearBase(hProcess, pbBase, cbNew); + if (pbNewIid == NULL) { + DETOUR_TRACE(("FindAndAllocateNearBase failed.\n")); + goto finish; + } + + DWORD obBase = (DWORD)(pbNewIid - pbModule); + DWORD dwProtect = 0; + if (inh.IMPORT_DIRECTORY.VirtualAddress != 0) { + // Read the old import directory if it exists. +#if 0 + if (!VirtualProtectEx(hProcess, + pbModule + inh.IMPORT_DIRECTORY.VirtualAddress, + inh.IMPORT_DIRECTORY.Size, PAGE_EXECUTE_READWRITE, &dwProtect)) { + DETOUR_TRACE(("VirtualProtectEx(import) write failed: %d\n", GetLastError())); + goto finish; + } +#endif + DETOUR_TRACE(("IMPORT_DIRECTORY perms=%x\n", dwProtect)); + + if (!ReadProcessMemory(hProcess, + pbModule + inh.IMPORT_DIRECTORY.VirtualAddress, + pbNew + obRem, + inh.IMPORT_DIRECTORY.Size, NULL)) { + DETOUR_TRACE(("ReadProcessMemory(imports) failed: %d\n", GetLastError())); + goto finish; + } + } + + PIMAGE_IMPORT_DESCRIPTOR piid = (PIMAGE_IMPORT_DESCRIPTOR)pbNew; + DWORD_XX *pt; + + for (n = 0; n < nDlls; n++) { + HRESULT hrRet = StringCchCopyA((char*)pbNew + obStr, cbNew - obStr, plpDlls[n]); + if (FAILED(hrRet)) { + DETOUR_TRACE(("StringCchCopyA failed: %d\n", GetLastError())); + goto finish; + } + + // After copying the string, we patch up the size "??" bits if any. + hrRet = ReplaceOptionalSizeA((char*)pbNew + obStr, + cbNew - obStr, + DETOURS_STRINGIFY(DETOURS_BITS_XX)); + if (FAILED(hrRet)) { + DETOUR_TRACE(("ReplaceOptionalSizeA failed: %d\n", GetLastError())); + goto finish; + } + + DWORD nOffset = obTab + (sizeof(DWORD_XX) * (4 * n)); + piid[n].OriginalFirstThunk = obBase + nOffset; + pt = ((DWORD_XX*)(pbNew + nOffset)); + pt[0] = IMAGE_ORDINAL_FLAG_XX + 1; + pt[1] = 0; + + nOffset = obTab + (sizeof(DWORD_XX) * ((4 * n) + 2)); + piid[n].FirstThunk = obBase + nOffset; + pt = ((DWORD_XX*)(pbNew + nOffset)); + pt[0] = IMAGE_ORDINAL_FLAG_XX + 1; + pt[1] = 0; + piid[n].TimeDateStamp = 0; + piid[n].ForwarderChain = 0; + piid[n].Name = obBase + obStr; + + obStr += PadToDword((DWORD)strlen(plpDlls[n]) + 1); + } + + for (i = 0; i < nDlls + (inh.IMPORT_DIRECTORY.Size / sizeof(*piid)); i++) { + DETOUR_TRACE(("%8d. Look=%08x Time=%08x Fore=%08x Name=%08x Addr=%08x\n", + i, + piid[i].OriginalFirstThunk, + piid[i].TimeDateStamp, + piid[i].ForwarderChain, + piid[i].Name, + piid[i].FirstThunk)); + if (piid[i].OriginalFirstThunk == 0 && piid[i].FirstThunk == 0) { + break; + } + } + + if (!WriteProcessMemory(hProcess, pbNewIid, pbNew, obStr, NULL)) { + DETOUR_TRACE(("WriteProcessMemory(iid) failed: %d\n", GetLastError())); + goto finish; + } + + DETOUR_TRACE(("obBaseBef = %08x..%08x\n", + inh.IMPORT_DIRECTORY.VirtualAddress, + inh.IMPORT_DIRECTORY.VirtualAddress + inh.IMPORT_DIRECTORY.Size)); + DETOUR_TRACE(("obBaseAft = %08x..%08x\n", obBase, obBase + obStr)); + + // If the file doesn't have an IAT_DIRECTORY, we create it... + if (inh.IAT_DIRECTORY.VirtualAddress == 0) { + inh.IAT_DIRECTORY.VirtualAddress = obBase; + inh.IAT_DIRECTORY.Size = cbNew; + } + + inh.IMPORT_DIRECTORY.VirtualAddress = obBase; + inh.IMPORT_DIRECTORY.Size = cbNew; + + /////////////////////// Update the NT header for the new import directory. + /////////////////////////////// Update the DOS header to fix the checksum. + // + if (!VirtualProtectEx(hProcess, pbModule, inh.OptionalHeader.SizeOfHeaders, + PAGE_EXECUTE_READWRITE, &dwProtect)) { + DETOUR_TRACE(("VirtualProtectEx(inh) write failed: %d\n", GetLastError())); + goto finish; + } + +#if IGNORE_CHECKSUMS + idh.e_res[0] = 0; +#else + inh.OptionalHeader.CheckSum = 0; +#endif // IGNORE_CHECKSUMS + + if (!WriteProcessMemory(hProcess, pbModule, &idh, sizeof(idh), NULL)) { + DETOUR_TRACE(("WriteProcessMemory(idh) failed: %d\n", GetLastError())); + goto finish; + } + DETOUR_TRACE(("WriteProcessMemory(idh:%p..%p)\n", pbModule, pbModule + sizeof(idh))); + + if (!WriteProcessMemory(hProcess, pbModule + idh.e_lfanew, &inh, sizeof(inh), NULL)) { + DETOUR_TRACE(("WriteProcessMemory(inh) failed: %d\n", GetLastError())); + goto finish; + } + DETOUR_TRACE(("WriteProcessMemory(inh:%p..%p)\n", + pbModule + idh.e_lfanew, + pbModule + idh.e_lfanew + sizeof(inh))); + +#if IGNORE_CHECKSUMS + WORD wDuring = ComputeChkSum(hProcess, pbModule, &inh); + DETOUR_TRACE(("ChkSum: %04x + %08x => %08x\n", wDuring, dwFileSize, wDuring + dwFileSize)); + + idh.e_res[0] = detour_sum_minus(idh.e_res[0], detour_sum_minus(wDuring, wBefore)); + + if (!WriteProcessMemory(hProcess, pbModule, &idh, sizeof(idh), NULL)) { + DETOUR_TRACE(("WriteProcessMemory(idh) failed: %d\n", GetLastError())); + goto finish; + } +#endif // IGNORE_CHECKSUMS + + if (!VirtualProtectEx(hProcess, pbModule, inh.OptionalHeader.SizeOfHeaders, + dwProtect, &dwProtect)) { + DETOUR_TRACE(("VirtualProtectEx(idh) restore failed: %d\n", GetLastError())); + goto finish; + } + +#if IGNORE_CHECKSUMS + WORD wAfter = ComputeChkSum(hProcess, pbModule, &inh); + DETOUR_TRACE(("ChkSum: %04x + %08x => %08x\n", wAfter, dwFileSize, wAfter + dwFileSize)); + DETOUR_TRACE(("Before: %08x, After: %08x\n", wBefore + dwFileSize, wAfter + dwFileSize)); + + if (wBefore != wAfter) { + DETOUR_TRACE(("Restore of checksum failed %04x != %04x.\n", wBefore, wAfter)); + goto finish; + } +#endif // IGNORE_CHECKSUMS + + fSucceeded = TRUE; + goto finish; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/icon182.ico b/石器时代8.5客户端最新源代码/石器源码/icon182.ico new file mode 100644 index 0000000..112d2ef Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/icon182.ico differ diff --git a/石器时代8.5客户端最新源代码/石器源码/icon2.5.ico b/石器时代8.5客户端最新源代码/石器源码/icon2.5.ico new file mode 100644 index 0000000..4052a11 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/icon2.5.ico differ diff --git a/石器时代8.5客户端最新源代码/石器源码/icon2.ico b/石器时代8.5客户端最新源代码/石器源码/icon2.ico new file mode 100644 index 0000000..112d2ef Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/icon2.ico differ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/ServerList.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/ServerList.cpp new file mode 100644 index 0000000..9af0a80 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/ServerList.cpp @@ -0,0 +1,67 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/netmain.h" +#include "winlua.h" + +#include +#include +#ifdef _WIN_LUAJIT_ +extern int nGroup; +extern struct gameserver gmsv[]; +extern struct gamegroup gmgroup[]; +static int SetGroupMaxNum(lua_State *L) +{ + const int num = luaL_checkint(L, 1); + nGroup = num; + return 1; +} + +static int SetGroupList(lua_State *L) +{ + size_t l; + const int id = luaL_checkint(L, 1); + const int GroupUse = luaL_checkint(L, 2); + const int ServerMaxNum = luaL_checkint(L, 3); + const int ServerIndex = luaL_checkint(L, 4); + const char *GroupName = luaL_checklstring(L, 5, &l); + gmgroup[id].used = GroupUse; + gmgroup[id].num = ServerMaxNum; + gmgroup[id].startindex = ServerIndex; + strcpy(gmgroup[id].name, GroupName); + return 1; +} + + + +static int SetServerList(lua_State *L) +{ + size_t l; + const int id = luaL_checkint(L, 1); + const char *ServerIP = luaL_checklstring(L, 2, &l); + const char *ServerPort = luaL_checklstring(L, 3, &l); + const char *ServerName = luaL_checklstring(L, 4, &l); + + strcpy(gmsv[id].ipaddr, ServerIP); + strcpy(gmsv[id].port, ServerPort); + strcpy(gmsv[id].name, ServerName); + + gmsv[id].used = '1'; + return 1; +} + + + +static const luaL_Reg ServerListlib[] = { + {"SetGroupList", SetGroupList}, + {"SetGroupMaxNum", SetGroupMaxNum}, + {"SetServerList", SetServerList}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_ServerList (lua_State *L) { + luaL_register(L, "ServerList", ServerListlib); + return 1; +} +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/data.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/data.cpp new file mode 100644 index 0000000..e4cc2da --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/data.cpp @@ -0,0 +1,82 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/pc.h" +#include "winlua.h" + +#include +#include +#ifdef _WIN_LUAJIT_ +extern PET pet[]; +static int getPetData(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + size_t l; + const char *attribute=luaL_checklstring(L, 2, &l); + + if(strcmp(attribute, "λ") == 0){ + lua_pushnumber(L, pet[id].index); + }else if(strcmp(attribute, "ͼ") == 0){ + lua_pushnumber(L, pet[id].graNo); + }else if(strcmp(attribute, "HP") == 0){ + lua_pushnumber(L, pet[id].hp); + }else if(strcmp(attribute, "MaxHP") == 0){ + lua_pushnumber(L, pet[id].maxHp); + }else if(strcmp(attribute, "MP") == 0){ + lua_pushnumber(L, pet[id].graNo); + }else if(strcmp(attribute, "MaxMP") == 0){ + lua_pushnumber(L, pet[id].graNo); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].exp); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].maxExp); + }else if(strcmp(attribute, "ȼ") == 0){ + lua_pushnumber(L, pet[id].level); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].atk); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].def); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].quick); + }else if(strcmp(attribute, "ҳ") == 0){ + lua_pushnumber(L, pet[id].ai); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].earth); + }else if(strcmp(attribute, "ˮ") == 0){ + lua_pushnumber(L, pet[id].water); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].fire); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].wind); + }else if(strcmp(attribute, "") == 0){ + lua_pushnumber(L, pet[id].maxSkill); + }else if(strcmp(attribute, "ת") == 0){ + lua_pushnumber(L, pet[id].trn); + }else if(strcmp(attribute, "ֱ") == 0){ + lua_pushnumber(L, pet[id].fusion); + }else if(strcmp(attribute, "״̬") == 0){ + lua_pushnumber(L, pet[id].status); + }else if(strcmp(attribute, "") == 0){ + lua_pushstring(L, pet[id].name); + }else if(strcmp(attribute, "dz") == 0){ + lua_pushstring(L, pet[id].freeName); + }else if(strcmp(attribute, "ʹ") == 0){ + lua_pushnumber(L, pet[id].useFlag); + }else if(strcmp(attribute, "ʶ") == 0){ + lua_pushnumber(L, pet[id].changeNameFlag); + } + return 1; +} + + +static const luaL_Reg Datalib[] = { + {"pet", getPetData}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Data (lua_State *L) { + luaL_register(L, "chardata", Datalib); + return 1; +} +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.cpp new file mode 100644 index 0000000..83ca39b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.cpp @@ -0,0 +1,38 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "winlua.h" + +#include +#include +#ifdef _WIN_LUAJIT_ +void lssproto_WN_send(int fd,int x,int y,int seqno,int objindex,int select,char* data); + + +extern unsigned int sockfd; +extern int nowGx, nowGy; +static int windows_send(lua_State *L) +{ + size_t l; + const int indexWN = luaL_checkint(L, 1); + const int idWN = luaL_checkint(L, 2); + const int btn = luaL_checkint(L, 3); + const char *data=luaL_checklstring(L, 4, &l); + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN, idWN, btn, (char *)data) ; + return 1; +} + + +static const luaL_Reg Lssprotolib[] = { + {"windows", windows_send}, + + {NULL, NULL} +}; + +LUALIB_API int luaopen_Lssproto (lua_State *L) { + luaL_register(L, "lssproto", Lssprotolib); + return 1; +} + +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.h new file mode 100644 index 0000000..9845b82 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lssproto.h @@ -0,0 +1,3 @@ +#ifdef _WIN_LUAJIT_ + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile new file mode 100644 index 0000000..3cbabe3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile @@ -0,0 +1,686 @@ +############################################################################## +# LuaJIT Makefile. Requires GNU Make. +# +# Please read doc/install.html before changing any variables! +# +# Suitable for POSIX platforms (Linux, *BSD, OSX etc.). +# Also works with MinGW and Cygwin on Windows. +# Please check msvcbuild.bat for building with MSVC on Windows. +# +# Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +############################################################################## + +MAJVER= 2 +MINVER= 0 +RELVER= 3 +ABIVER= 5.1 +NODOTABIVER= 51 + +############################################################################## +############################# COMPILER OPTIONS ############################# +############################################################################## +# These options mainly affect the speed of the JIT compiler itself, not the +# speed of the JIT-compiled code. Turn any of the optional settings on by +# removing the '#' in front of them. Make sure you force a full recompile +# with "make clean", followed by "make" if you change any options. +# +# LuaJIT builds as a native 32 or 64 bit binary by default. +CC= gcc +# +# Use this if you want to force a 32 bit build on a 64 bit multilib OS. +#CC= gcc -m32 +# +# Since the assembler part does NOT maintain a frame pointer, it's pointless +# to slow down the C part by not omitting it. Debugging, tracebacks and +# unwinding are not affected -- the assembler part has frame unwind +# information and GCC emits it where needed (x64) or with -g (see CCDEBUG). +CCOPT= -O2 -fomit-frame-pointer +# Use this if you want to generate a smaller binary (but it's slower): +#CCOPT= -Os -fomit-frame-pointer +# Note: it's no longer recommended to use -O3 with GCC 4.x. +# The I-Cache bloat usually outweighs the benefits from aggressive inlining. +# +# Target-specific compiler options: +# +# x86 only: it's recommended to compile at least for i686. Better yet, +# compile for an architecture that has SSE2, too (-msse -msse2). +# +# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute +# the binaries to a different machine you could also use: -march=native +# +CCOPT_x86= -march=i686 +CCOPT_x64= +CCOPT_arm= +CCOPT_ppc= +CCOPT_ppcspe= +CCOPT_mips= +# +CCDEBUG= +# Uncomment the next line to generate debug information: +#CCDEBUG= -g +# +CCWARN= -Wall +# Uncomment the next line to enable more warnings: +#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith +# +############################################################################## + +############################################################################## +################################ BUILD MODE ################################ +############################################################################## +# The default build mode is mixed mode on POSIX. On Windows this is the same +# as dynamic mode. +# +# Mixed mode creates a static + dynamic library and a statically linked luajit. +#BUILDMODE= mixed +# +# Static mode creates a static library and a statically linked luajit. +BUILDMODE= static +# +# Dynamic mode creates a dynamic library and a dynamically linked luajit. +# Note: this executable will only run when the library is installed! +#BUILDMODE= dynamic +# +############################################################################## + +############################################################################## +################################# FEATURES ################################# +############################################################################## +# Enable/disable these features as needed, but make sure you force a full +# recompile with "make clean", followed by "make". +XCFLAGS= +# +# Permanently disable the FFI extension to reduce the size of the LuaJIT +# executable. But please consider that the FFI library is compiled-in, +# but NOT loaded by default. It only allocates any memory, if you actually +# make use of it. +#XCFLAGS+= -DLUAJIT_DISABLE_FFI +# +# Features from Lua 5.2 that are unlikely to break existing code are +# enabled by default. Some other features that *might* break some existing +# code (e.g. __pairs or os.execute() return values) can be enabled here. +# Note: this does not provide full compatibility with Lua 5.2 at this time. +#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT +# +# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter. +#XCFLAGS+= -DLUAJIT_DISABLE_JIT +# +# Some architectures (e.g. PPC) can use either single-number (1) or +# dual-number (2) mode. Uncomment one of these lines to override the +# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details. +#XCFLAGS+= -DLUAJIT_NUMMODE=1 +#XCFLAGS+= -DLUAJIT_NUMMODE=2 +# +############################################################################## + +############################################################################## +############################ DEBUGGING SUPPORT ############################# +############################################################################## +# Enable these options as needed, but make sure you force a full recompile +# with "make clean", followed by "make". +# Note that most of these are NOT suitable for benchmarking or release mode! +# +# Use the system provided memory allocator (realloc) instead of the +# bundled memory allocator. This is slower, but sometimes helpful for +# debugging. It's helpful for Valgrind's memcheck tool, too. This option +# cannot be enabled on x64, since the built-in allocator is mandatory. +#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC +# +# This define is required to run LuaJIT under Valgrind. The Valgrind +# header files must be installed. You should enable debug information, too. +# Use --suppressions=lj.supp to avoid some false positives. +#XCFLAGS+= -DLUAJIT_USE_VALGRIND +# +# This is the client for the GDB JIT API. GDB 7.0 or higher is required +# to make use of it. See lj_gdbjit.c for details. Enabling this causes +# a non-negligible overhead, even when not running under GDB. +#XCFLAGS+= -DLUAJIT_USE_GDBJIT +# +# Turn on assertions for the Lua/C API to debug problems with lua_* calls. +# This is rather slow -- use only while developing C libraries/embeddings. +#XCFLAGS+= -DLUA_USE_APICHECK +# +# Turn on assertions for the whole LuaJIT VM. This significantly slows down +# everything. Use only if you suspect a problem with LuaJIT itself. +#XCFLAGS+= -DLUA_USE_ASSERT +# +############################################################################## +# You probably don't need to change anything below this line! +############################################################################## + +############################################################################## +# Flags and options for host and target. +############################################################################## + +# You can override the following variables at the make command line: +# CC HOST_CC STATIC_CC DYNAMIC_CC +# CFLAGS HOST_CFLAGS TARGET_CFLAGS +# LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS +# LIBS HOST_LIBS TARGET_LIBS +# CROSS HOST_SYS TARGET_SYS TARGET_FLAGS +# +# Cross-compilation examples: +# make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows +# make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- + +CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS) +LDOPTIONS= $(CCDEBUG) $(LDFLAGS) + +HOST_CC= $(CC) +HOST_RM= rm -f +# If left blank, minilua is built and used. You can supply an installed +# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua +HOST_LUA= + +HOST_XCFLAGS= -I. +HOST_XLDFLAGS= +HOST_XLIBS= +HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS) +HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS) +HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS) + +STATIC_CC = $(CROSS)$(CC) +DYNAMIC_CC = $(CROSS)$(CC) -fPIC +TARGET_CC= $(STATIC_CC) +TARGET_STCC= $(STATIC_CC) +TARGET_DYNCC= $(DYNAMIC_CC) +TARGET_LD= $(CROSS)$(CC) +TARGET_AR= $(CROSS)ar rcus +TARGET_STRIP= $(CROSS)strip + +TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib) +TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER) +TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib +TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME) +TARGET_DLLNAME= lua$(NODOTABIVER).dll +TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME) +TARGET_DYNXLDOPTS= + +TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE +TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE +TARGET_XLDFLAGS= +TARGET_XLIBS= -lm +TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) +TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) +TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS) +TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS) +TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS) + +TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM) +ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH))) + TARGET_LJARCH= x64 +else +ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH))) + TARGET_LJARCH= x86 +else +ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH))) + TARGET_LJARCH= arm +else +ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH))) + TARGET_LJARCH= ppc +else +ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH))) + TARGET_LJARCH= ppcspe +else +ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH))) + ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH))) + TARGET_ARCH= -D__MIPSEL__=1 + endif + TARGET_LJARCH= mips +else + $(error Unsupported target architecture) +endif +endif +endif +endif +endif +endif + +ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) + TARGET_SYS= PS3 + TARGET_ARCH+= -D__CELLOS_LV2__ + TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC +endif +ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) + TARGET_ARCH+= -DLUAJIT_NO_UNWIND +endif + +TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH)) +TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH)) + +ifneq (,$(PREFIX)) +ifneq (/usr/local,$(PREFIX)) + TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\" + ifneq (/usr,$(PREFIX)) + TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH) + endif +endif +endif +ifneq (,$(MULTILIB)) + TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\" +endif +ifneq (,$(LMULTILIB)) + TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\" +endif + +############################################################################## +# System detection. +############################################################################## + +ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM)) + HOST_SYS= Windows + HOST_RM= del +else + HOST_SYS:= $(shell uname -s) + ifneq (,$(findstring MINGW,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= mingw + endif + ifneq (,$(findstring CYGWIN,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= cygwin + endif +endif + +TARGET_SYS?= $(HOST_SYS) +ifeq (Windows,$(TARGET_SYS)) + TARGET_STRIP+= --strip-unneeded + TARGET_XSHLDFLAGS= -shared + TARGET_DYNXLDOPTS= +else +ifeq (Darwin,$(TARGET_SYS)) + ifeq (,$(MACOSX_DEPLOYMENT_TARGET)) + export MACOSX_DEPLOYMENT_TARGET=10.4 + endif + TARGET_STRIP+= -x + TARGET_AR+= 2>/dev/null + ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1)) + TARGET_XCFLAGS+= -fno-stack-protector + endif + TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC + TARGET_DYNXLDOPTS= + TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER) + ifeq (x64,$(TARGET_LJARCH)) + TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000 + TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000 + endif +else +ifeq (iOS,$(TARGET_SYS)) + TARGET_STRIP+= -x + TARGET_AR+= 2>/dev/null + TARGET_XCFLAGS+= -fno-stack-protector + TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC + TARGET_DYNXLDOPTS= + TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER) +else + ifneq (,$(findstring stack-protector,$(shell $(TARGET_CC) -dumpspecs))) + TARGET_XCFLAGS+= -fno-stack-protector + endif + ifneq (SunOS,$(TARGET_SYS)) + ifneq (PS3,$(TARGET_SYS)) + TARGET_XLDFLAGS+= -Wl,-E + endif + endif + ifeq (Linux,$(TARGET_SYS)) + TARGET_XLIBS+= -ldl + endif + ifeq (GNU/kFreeBSD,$(TARGET_SYS)) + TARGET_XLIBS+= -ldl + endif +endif +endif +endif + +ifneq ($(HOST_SYS),$(TARGET_SYS)) + ifeq (Windows,$(TARGET_SYS)) + HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS + else + ifeq (Linux,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX + else + ifeq (Darwin,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX + else + ifeq (iOS,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX + else + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER + endif + endif + endif + endif +endif + +ifneq (,$(CCDEBUG)) + TARGET_STRIP= @: +endif + +############################################################################## +# Files and pathnames. +############################################################################## + +MINILUA_O= host/minilua.o +MINILUA_LIBS= -lm +MINILUA_T= host/minilua +MINILUA_X= $(MINILUA_T) + +ifeq (,$(HOST_LUA)) + HOST_LUA= $(MINILUA_X) + DASM_DEP= $(MINILUA_T) +endif + +DASM_DIR= ../dynasm +DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua +DASM_XFLAGS= +DASM_AFLAGS= +DASM_ARCH= $(TARGET_LJARCH) + +ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D P64 +endif +ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D JIT +endif +ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D FFI +endif +ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D DUALNUM +endif +ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D FPU + TARGET_ARCH+= -DLJ_ARCH_HASFPU=1 +else + TARGET_ARCH+= -DLJ_ARCH_HASFPU=0 +endif +ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D HFABI + TARGET_ARCH+= -DLJ_ABI_SOFTFP=0 +else + TARGET_ARCH+= -DLJ_ABI_SOFTFP=1 +endif +DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH)))) +ifeq (Windows,$(TARGET_SYS)) + DASM_AFLAGS+= -D WIN +endif +ifeq (x86,$(TARGET_LJARCH)) + ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D SSE + endif +else +ifeq (x64,$(TARGET_LJARCH)) + DASM_ARCH= x86 +else +ifeq (arm,$(TARGET_LJARCH)) + ifeq (iOS,$(TARGET_SYS)) + DASM_AFLAGS+= -D IOS + endif +else +ifeq (ppc,$(TARGET_LJARCH)) + ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D SQRT + endif + ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D ROUND + endif + ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D GPR64 + endif + ifeq (PS3,$(TARGET_SYS)) + DASM_AFLAGS+= -D PPE -D TOC + endif +endif +endif +endif +endif + +DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS) +DASM_DASC= vm_$(DASM_ARCH).dasc + +BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \ + host/buildvm_lib.o host/buildvm_fold.o +BUILDVM_T= host/buildvm +BUILDVM_X= $(BUILDVM_T) + +HOST_O= $(MINILUA_O) $(BUILDVM_O) +HOST_T= $(MINILUA_T) $(BUILDVM_T) + +LJVM_S= lj_vm.s +LJVM_O= lj_vm.o +LJVM_BOUT= $(LJVM_S) +LJVM_MODE= elfasm + +LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \ + lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o +LJLIB_C= $(LJLIB_O:.o=.c) + +LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \ + lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \ + lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \ + lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \ + lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \ + lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \ + lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \ + lj_asm.o lj_trace.o lj_gdbjit.o \ + lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \ + lj_carith.o lj_clib.o lj_cparse.o \ + lj_lib.o lj_alloc.o lib_aux.o \ + $(LJLIB_O) lib_init.o + +LJVMCORE_O= $(LJVM_O) $(LJCORE_O) +LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o) + +LIB_VMDEF= jit/vmdef.lua +LIB_VMDEFP= $(LIB_VMDEF) + +LUAJIT_O= luajit.o +LUAJIT_A= libluajit.a +LUAJIT_SO= libluajit.so +LUAJIT_T= luajit + +ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T) +ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \ + host/buildvm_arch.h +ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP) +WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk +ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM) + +############################################################################## +# Build mode handling. +############################################################################## + +# Mixed mode defaults. +TARGET_O= $(LUAJIT_A) +TARGET_T= $(LUAJIT_T) $(LUAJIT_SO) +TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO) + +ifeq (Windows,$(TARGET_SYS)) + TARGET_DYNCC= $(STATIC_CC) + LJVM_MODE= peobj + LJVM_BOUT= $(LJVM_O) + LUAJIT_T= luajit.exe + ifeq (cygwin,$(HOST_MSYS)) + LUAJIT_SO= cyg$(TARGET_DLLNAME) + else + LUAJIT_SO= $(TARGET_DLLNAME) + endif + # Mixed mode is not supported on Windows. And static mode doesn't work well. + # C modules cannot be loaded, because they bind to lua51.dll. + ifneq (static,$(BUILDMODE)) + BUILDMODE= dynamic + TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL + endif +endif +ifeq (Darwin,$(TARGET_SYS)) + LJVM_MODE= machasm +endif +ifeq (iOS,$(TARGET_SYS)) + LJVM_MODE= machasm +endif +ifeq (SunOS,$(TARGET_SYS)) + BUILDMODE= static +endif +ifeq (PS3,$(TARGET_SYS)) + BUILDMODE= static +endif + +ifeq (Windows,$(HOST_SYS)) + MINILUA_T= host/minilua.exe + BUILDVM_T= host/buildvm.exe + ifeq (,$(HOST_MSYS)) + MINILUA_X= host\minilua + BUILDVM_X= host\buildvm + ALL_RM:= $(subst /,\,$(ALL_RM)) + endif +endif + +ifeq (static,$(BUILDMODE)) + TARGET_DYNCC= @: + TARGET_T= $(LUAJIT_T) + TARGET_DEP= $(LIB_VMDEF) +else +ifeq (dynamic,$(BUILDMODE)) + ifneq (Windows,$(TARGET_SYS)) + TARGET_CC= $(DYNAMIC_CC) + endif + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) + TARGET_O= $(LUAJIT_SO) + TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS) +else +ifeq (Darwin,$(TARGET_SYS)) + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) +endif +ifeq (iOS,$(TARGET_SYS)) + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) +endif +endif +endif + +Q= @ +E= @echo +#Q= +#E= @: + +############################################################################## +# Make targets. +############################################################################## + +default all: $(TARGET_T) + +amalg: + @grep "^[+|]" ljamalg.c + $(MAKE) all "LJCORE_O=ljamalg.o" + +clean: + $(HOST_RM) $(ALL_RM) + +depend: + @for file in $(ALL_HDRGEN); do \ + test -f $$file || touch $$file; \ + done + @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \ + sed -e "s| [^ ]*/dasm_\S*\.h||g" \ + -e "s|^\([^l ]\)|host/\1|" \ + -e "s| lj_target_\S*\.h| lj_target_*.h|g" \ + -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \ + -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep + @for file in $(ALL_HDRGEN); do \ + test -s $$file || $(HOST_RM) $$file; \ + done + +.PHONY: default all amalg clean depend + +############################################################################## +# Rules for generated files. +############################################################################## + +$(MINILUA_T): $(MINILUA_O) + $(E) "HOSTLINK $@" + $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS) + +host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) + $(E) "DYNASM $@" + $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC) + +host/buildvm.o: $(DASM_DIR)/dasm_*.h + +$(BUILDVM_T): $(BUILDVM_O) + $(E) "HOSTLINK $@" + $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS) + +$(LJVM_BOUT): $(BUILDVM_T) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@ + +lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C) + +lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C) + +lj_libdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C) + +lj_recdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C) + +$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C) + +lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c + +############################################################################## +# Object file rules. +############################################################################## + +%.o: %.c + $(E) "CC $@" + $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $< + $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $< + +%.o: %.s + $(E) "ASM $@" + $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $< + $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $< + +$(LUAJIT_O): + $(E) "CC $@" + $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $< + +$(HOST_O): %.o: %.c + $(E) "HOSTCC $@" + $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $< + +include Makefile.dep + +############################################################################## +# Target file rules. +############################################################################## + +$(LUAJIT_A): $(LJVMCORE_O) + $(E) "AR $@" + $(Q)$(TARGET_AR) $@ $(LJVMCORE_O) + +# The dependency on _O, but linking with _DYNO is intentional. +$(LUAJIT_SO): $(LJVMCORE_O) + $(E) "DYNLINK $@" + $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS) + $(Q)$(TARGET_STRIP) $@ + +$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP) + $(E) "LINK $@" + $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS) + $(Q)$(TARGET_STRIP) $@ + $(E) "OK Successfully built LuaJIT" + +############################################################################## diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile.dep b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile.dep new file mode 100644 index 0000000..8ca3315 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/Makefile.dep @@ -0,0 +1,226 @@ +lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_state.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_lib.h lj_alloc.h +lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h \ + lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \ + lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \ + lj_lib.h lj_libdef.h +lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h +lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \ + lj_libdef.h +lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \ + lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \ + lj_ccallback.h lj_clib.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h +lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h +lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \ + lj_ffdef.h lj_lib.h lj_libdef.h +lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \ + lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ + lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \ + lj_target_*.h lj_dispatch.h lj_vm.h lj_vmevent.h lj_lib.h luajit.h \ + lj_libdef.h +lib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_libdef.h +lib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_lib.h lj_libdef.h +lib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h +lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \ + lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h lj_char.h \ + lj_lib.h lj_libdef.h +lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \ + lj_libdef.h +lj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h +lj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \ + lj_meta.h lj_state.h lj_bc.h lj_frame.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_traceerr.h lj_vm.h lj_strscan.h +lj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h \ + lj_ircall.h lj_iropt.h lj_mcode.h lj_trace.h lj_dispatch.h lj_traceerr.h \ + lj_snap.h lj_asm.h lj_vm.h lj_target.h lj_target_*.h lj_emit_*.h \ + lj_asm_*.h +lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \ + lj_bcdef.h +lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \ + lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h +lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \ + lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h +lj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_carith.h +lj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ + lj_traceerr.h +lj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \ + lj_bc.h lj_ctype.h lj_cconv.h lj_ccall.h lj_ccallback.h lj_target.h \ + lj_target_*.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h +lj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \ + lj_ccallback.h +lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ + lj_cdata.h +lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h +lj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_clib.h +lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \ + lj_bc.h lj_vm.h lj_char.h lj_strscan.h +lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \ + lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \ + lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ + lj_crecord.h +lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h +lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_state.h lj_frame.h \ + lj_bc.h lj_jit.h lj_ir.h +lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_func.h lj_str.h lj_tab.h lj_meta.h lj_debug.h \ + lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h lj_jit.h lj_ir.h \ + lj_ccallback.h lj_ctype.h lj_gc.h lj_trace.h lj_dispatch.h lj_traceerr.h \ + lj_vm.h luajit.h +lj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \ + lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \ + lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h +lj_ffrecord.o: lj_ffrecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \ + lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_crecord.h \ + lj_vm.h lj_strscan.h lj_recdef.h +lj_func.o: lj_func.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_func.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ + lj_traceerr.h lj_vm.h +lj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_udata.h lj_meta.h \ + lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h lj_jit.h \ + lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h +lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_jit.h \ + lj_ir.h lj_dispatch.h +lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h lj_carith.h \ + lj_vm.h lj_strscan.h lj_lib.h +lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h lualib.h \ + lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h +lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ + lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_lib.h +lj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_func.h lj_frame.h \ + lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h +lj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_jit.h lj_ir.h lj_mcode.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_vm.h +lj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \ + lj_vm.h lj_strscan.h +lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h +lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_jit.h lj_iropt.h +lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ + lj_bc.h lj_traceerr.h lj_ctype.h lj_gc.h lj_carith.h lj_vm.h \ + lj_strscan.h lj_folddef.h +lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h +lj_opt_mem.o: lj_opt_mem.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_tab.h lj_ir.h lj_jit.h lj_iropt.h +lj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h lj_strscan.h +lj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h +lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_ircall.h \ + lj_iropt.h lj_vm.h +lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h \ + lj_state.h lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h +lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \ + lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h \ + lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h \ + lj_ffrecord.h lj_snap.h lj_vm.h +lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \ + lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \ + lj_target_*.h lj_ctype.h lj_cdata.h +lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \ + lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h +lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_char.h +lj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_char.h lj_strscan.h +lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_tab.h +lj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_frame.h lj_bc.h \ + lj_state.h lj_ir.h lj_jit.h lj_iropt.h lj_mcode.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_snap.h lj_gdbjit.h lj_record.h lj_asm.h \ + lj_vm.h lj_vmevent.h lj_target.h lj_target_*.h +lj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_udata.h +lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \ + lj_vm.h lj_vmevent.h +lj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_vm.h +ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \ + lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h \ + lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c \ + lj_debug.h lj_ff.h lj_ffdef.h lj_char.c lj_char.h lj_bc.c lj_bcdef.h \ + lj_obj.c lj_str.c lj_tab.c lj_func.c lj_udata.c lj_meta.c lj_strscan.h \ + lj_debug.c lj_state.c lj_lex.h lj_alloc.h lj_dispatch.c lj_ccallback.h \ + luajit.h lj_vmevent.c lj_vmevent.h lj_vmmath.c lj_strscan.c lj_api.c \ + lj_lex.c lualib.h lj_parse.h lj_parse.c lj_bcread.c lj_bcdump.h \ + lj_bcwrite.c lj_load.c lj_ctype.c lj_cdata.c lj_cconv.h lj_cconv.c \ + lj_ccall.c lj_ccall.h lj_ccallback.c lj_target.h lj_target_*.h \ + lj_mcode.h lj_carith.c lj_carith.h lj_clib.c lj_clib.h lj_cparse.c \ + lj_cparse.h lj_lib.c lj_lib.h lj_ir.c lj_ircall.h lj_iropt.h \ + lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \ + lj_opt_loop.c lj_snap.h lj_opt_split.c lj_opt_sink.c lj_mcode.c \ + lj_snap.c lj_record.c lj_record.h lj_ffrecord.h lj_crecord.c \ + lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h lj_emit_*.h \ + lj_asm_*.h lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c \ + lib_base.c lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \ + lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c \ + lib_init.c +luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h +host/buildvm.o: host/buildvm.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_gc.h lj_obj.h lj_bc.h lj_ir.h \ + lj_ircall.h lj_ir.h lj_jit.h lj_frame.h lj_bc.h lj_dispatch.h lj_ctype.h \ + lj_gc.h lj_ccall.h lj_ctype.h luajit.h \ + host/buildvm_arch.h lj_traceerr.h +host/buildvm_asm.o: host/buildvm_asm.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_bc.h lj_def.h lj_arch.h +host/buildvm_fold.o: host/buildvm_fold.c host/buildvm.h lj_def.h lua.h \ + luaconf.h lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_ir.h lj_obj.h +host/buildvm_lib.o: host/buildvm_lib.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_lib.h lj_obj.h +host/buildvm_peobj.o: host/buildvm_peobj.c host/buildvm.h lj_def.h lua.h \ + luaconf.h lj_arch.h lj_bc.h lj_def.h lj_arch.h +host/minilua.o: host/minilua.c diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/README b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/README new file mode 100644 index 0000000..abfcdaa --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/README @@ -0,0 +1,4 @@ +The files in this directory are only used during the build process of LuaJIT. +For cross-compilation, they must be executed on the host, not on the target. + +These files should NOT be installed! diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.c new file mode 100644 index 0000000..7687ad7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.c @@ -0,0 +1,516 @@ +/* +** LuaJIT VM builder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** This is a tool to build the hand-tuned assembler code required for +** LuaJIT's bytecode interpreter. It supports a variety of output formats +** to feed different toolchains (see usage() below). +** +** This tool is not particularly optimized because it's only used while +** _building_ LuaJIT. There's no point in distributing or installing it. +** Only the object code generated by this tool is linked into LuaJIT. +** +** Caveat: some memory is not free'd, error handling is lazy. +** It's a one-shot tool -- any effort fixing this would be wasted. +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_ircall.h" +#include "lj_frame.h" +#include "lj_dispatch.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_ccall.h" +#endif +#include "luajit.h" + +#if defined(_WIN32) +#include +#include +#endif + +/* ------------------------------------------------------------------------ */ + +/* DynASM glue definitions. */ +#define Dst ctx +#define Dst_DECL BuildCtx *ctx +#define Dst_REF (ctx->D) +#define DASM_CHECKS 1 + +#include "../dynasm/dasm_proto.h" + +/* Glue macros for DynASM. */ +static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type); + +#define DASM_EXTERN(ctx, addr, idx, type) \ + collect_reloc(ctx, addr, idx, type) + +/* ------------------------------------------------------------------------ */ + +/* Avoid trouble if cross-compiling for an x86 target. Speed doesn't matter. */ +#define DASM_ALIGNED_WRITES 1 + +/* Embed architecture-specific DynASM encoder. */ +#if LJ_TARGET_X86ORX64 +#include "../dynasm/dasm_x86.h" +#elif LJ_TARGET_ARM +#include "../dynasm/dasm_arm.h" +#elif LJ_TARGET_PPC +#include "../dynasm/dasm_ppc.h" +#elif LJ_TARGET_PPCSPE +#include "../dynasm/dasm_ppc.h" +#elif LJ_TARGET_MIPS +#include "../dynasm/dasm_mips.h" +#else +#error "No support for this architecture (yet)" +#endif + +/* Embed generated architecture-specific backend. */ +#include "buildvm_arch.h" + +/* ------------------------------------------------------------------------ */ + +void owrite(BuildCtx *ctx, const void *ptr, size_t sz) +{ + if (fwrite(ptr, 1, sz, ctx->fp) != sz) { + fprintf(stderr, "Error: cannot write to output file: %s\n", + strerror(errno)); + exit(1); + } +} + +/* ------------------------------------------------------------------------ */ + +/* Emit code as raw bytes. Only used for DynASM debugging. */ +static void emit_raw(BuildCtx *ctx) +{ + owrite(ctx, ctx->code, ctx->codesz); +} + +/* -- Build machine code -------------------------------------------------- */ + +static const char *sym_decorate(BuildCtx *ctx, + const char *prefix, const char *suffix) +{ + char name[256]; + char *p; +#if LJ_64 + const char *symprefix = ctx->mode == BUILD_machasm ? "_" : ""; +#elif LJ_TARGET_XBOX360 + const char *symprefix = ""; +#else + const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : ""; +#endif + sprintf(name, "%s%s%s", symprefix, prefix, suffix); + p = strchr(name, '@'); + if (p) { +#if LJ_TARGET_X86ORX64 + if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj)) + name[0] = '@'; + else + *p = '\0'; +#elif (LJ_TARGET_PPC || LJ_TARGET_PPCSPE) && !LJ_TARGET_CONSOLE + /* Keep @plt. */ +#else + *p = '\0'; +#endif + } + p = (char *)malloc(strlen(name)+1); /* MSVC doesn't like strdup. */ + strcpy(p, name); + return p; +} + +#define NRELOCSYM (sizeof(extnames)/sizeof(extnames[0])-1) + +static int relocmap[NRELOCSYM]; + +/* Collect external relocations. */ +static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) +{ + if (ctx->nreloc >= BUILD_MAX_RELOC) { + fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n"); + exit(1); + } + if (relocmap[idx] < 0) { + relocmap[idx] = ctx->nrelocsym; + ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, "", extnames[idx]); + ctx->nrelocsym++; + } + ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code); + ctx->reloc[ctx->nreloc].sym = relocmap[idx]; + ctx->reloc[ctx->nreloc].type = type; + ctx->nreloc++; +#if LJ_TARGET_XBOX360 + return (int)(ctx->code - addr) + 4; /* Encode symbol offset of .text. */ +#else + return 0; /* Encode symbol offset of 0. */ +#endif +} + +/* Naive insertion sort. Performance doesn't matter here. */ +static void sym_insert(BuildCtx *ctx, int32_t ofs, + const char *prefix, const char *suffix) +{ + ptrdiff_t i = ctx->nsym++; + while (i > 0) { + if (ctx->sym[i-1].ofs <= ofs) + break; + ctx->sym[i] = ctx->sym[i-1]; + i--; + } + ctx->sym[i].ofs = ofs; + ctx->sym[i].name = sym_decorate(ctx, prefix, suffix); +} + +/* Build the machine code. */ +static int build_code(BuildCtx *ctx) +{ + int status; + int i; + + /* Initialize DynASM structures. */ + ctx->nglob = GLOB__MAX; + ctx->glob = (void **)malloc(ctx->nglob*sizeof(void *)); + memset(ctx->glob, 0, ctx->nglob*sizeof(void *)); + ctx->nreloc = 0; + + ctx->globnames = globnames; + ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); + ctx->nrelocsym = 0; + for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; + + ctx->dasm_ident = DASM_IDENT; + ctx->dasm_arch = DASM_ARCH; + + dasm_init(Dst, DASM_MAXSECTION); + dasm_setupglobal(Dst, ctx->glob, ctx->nglob); + dasm_setup(Dst, build_actionlist); + + /* Call arch-specific backend to emit the code. */ + ctx->npc = build_backend(ctx); + + /* Finalize the code. */ + (void)dasm_checkstep(Dst, -1); + if ((status = dasm_link(Dst, &ctx->codesz))) return status; + ctx->code = (uint8_t *)malloc(ctx->codesz); + if ((status = dasm_encode(Dst, (void *)ctx->code))) return status; + + /* Allocate symbol table and bytecode offsets. */ + ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin"); + ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym)); + ctx->nsym = 0; + ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t)); + + /* Collect the opcodes (PC labels). */ + for (i = 0; i < ctx->npc; i++) { + int32_t ofs = dasm_getpclabel(Dst, i); + if (ofs < 0) return 0x22000000|i; + ctx->bc_ofs[i] = ofs; + if ((LJ_HASJIT || + !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP || + i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) && + (LJ_HASFFI || i != BC_KCDATA)) + sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]); + } + + /* Collect the globals (named labels). */ + for (i = 0; i < ctx->nglob; i++) { + const char *gl = globnames[i]; + int len = (int)strlen(gl); + if (!ctx->glob[i]) { + fprintf(stderr, "Error: undefined global %s\n", gl); + exit(2); + } + /* Skip the _Z symbols. */ + if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z')) + sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code), + LABEL_PREFIX, globnames[i]); + } + + /* Close the address range. */ + sym_insert(ctx, (int32_t)ctx->codesz, "", ""); + ctx->nsym--; + + dasm_free(Dst); + + return 0; +} + +/* -- Generate VM enums --------------------------------------------------- */ + +const char *const bc_names[] = { +#define BCNAME(name, ma, mb, mc, mt) #name, +BCDEF(BCNAME) +#undef BCNAME + NULL +}; + +const char *const ir_names[] = { +#define IRNAME(name, m, m1, m2) #name, +IRDEF(IRNAME) +#undef IRNAME + NULL +}; + +const char *const irt_names[] = { +#define IRTNAME(name, size) #name, +IRTDEF(IRTNAME) +#undef IRTNAME + NULL +}; + +const char *const irfpm_names[] = { +#define FPMNAME(name) #name, +IRFPMDEF(FPMNAME) +#undef FPMNAME + NULL +}; + +const char *const irfield_names[] = { +#define FLNAME(name, ofs) #name, +IRFLDEF(FLNAME) +#undef FLNAME + NULL +}; + +const char *const ircall_names[] = { +#define IRCALLNAME(cond, name, nargs, kind, type, flags) #name, +IRCALLDEF(IRCALLNAME) +#undef IRCALLNAME + NULL +}; + +static const char *const trace_errors[] = { +#define TREDEF(name, msg) msg, +#include "lj_traceerr.h" + NULL +}; + +static const char *lower(char *buf, const char *s) +{ + char *p = buf; + while (*s) { + *p++ = (*s >= 'A' && *s <= 'Z') ? *s+0x20 : *s; + s++; + } + *p = '\0'; + return buf; +} + +/* Emit C source code for bytecode-related definitions. */ +static void emit_bcdef(BuildCtx *ctx) +{ + int i; + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_ofs[] = {\n"); + for (i = 0; i < ctx->npc; i++) { + if (i != 0) + fprintf(ctx->fp, ",\n"); + fprintf(ctx->fp, "%d", ctx->bc_ofs[i]); + } +} + +/* Emit VM definitions as Lua code for debug modules. */ +static void emit_vmdef(BuildCtx *ctx) +{ + char buf[80]; + int i; + fprintf(ctx->fp, "-- This is a generated file. DO NOT EDIT!\n\n"); + fprintf(ctx->fp, "module(...)\n\n"); + + fprintf(ctx->fp, "bcnames = \""); + for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, "%-6s", bc_names[i]); + fprintf(ctx->fp, "\"\n\n"); + + fprintf(ctx->fp, "irnames = \""); + for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, "%-6s", ir_names[i]); + fprintf(ctx->fp, "\"\n\n"); + + fprintf(ctx->fp, "irfpm = { [0]="); + for (i = 0; irfpm_names[i]; i++) + fprintf(ctx->fp, "\"%s\", ", lower(buf, irfpm_names[i])); + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "irfield = { [0]="); + for (i = 0; irfield_names[i]; i++) { + char *p; + lower(buf, irfield_names[i]); + p = strchr(buf, '_'); + if (p) *p = '.'; + fprintf(ctx->fp, "\"%s\", ", buf); + } + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "ircall = {\n[0]="); + for (i = 0; ircall_names[i]; i++) + fprintf(ctx->fp, "\"%s\",\n", ircall_names[i]); + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "traceerr = {\n[0]="); + for (i = 0; trace_errors[i]; i++) + fprintf(ctx->fp, "\"%s\",\n", trace_errors[i]); + fprintf(ctx->fp, "}\n\n"); +} + +/* -- Argument parsing ---------------------------------------------------- */ + +/* Build mode names. */ +static const char *const modenames[] = { +#define BUILDNAME(name) #name, +BUILDDEF(BUILDNAME) +#undef BUILDNAME + NULL +}; + +/* Print usage information and exit. */ +static void usage(void) +{ + int i; + fprintf(stderr, LUAJIT_VERSION " VM builder.\n"); + fprintf(stderr, LUAJIT_COPYRIGHT ", " LUAJIT_URL "\n"); + fprintf(stderr, "Target architecture: " LJ_ARCH_NAME "\n\n"); + fprintf(stderr, "Usage: buildvm -m mode [-o outfile] [infiles...]\n\n"); + fprintf(stderr, "Available modes:\n"); + for (i = 0; i < BUILD__MAX; i++) + fprintf(stderr, " %s\n", modenames[i]); + exit(1); +} + +/* Parse the output mode name. */ +static BuildMode parsemode(const char *mode) +{ + int i; + for (i = 0; modenames[i]; i++) + if (!strcmp(mode, modenames[i])) + return (BuildMode)i; + usage(); + return (BuildMode)-1; +} + +/* Parse arguments. */ +static void parseargs(BuildCtx *ctx, char **argv) +{ + const char *a; + int i; + ctx->mode = (BuildMode)-1; + ctx->outname = "-"; + for (i = 1; (a = argv[i]) != NULL; i++) { + if (a[0] != '-') + break; + switch (a[1]) { + case '-': + if (a[2]) goto err; + i++; + goto ok; + case '\0': + goto ok; + case 'm': + i++; + if (a[2] || argv[i] == NULL) goto err; + ctx->mode = parsemode(argv[i]); + break; + case 'o': + i++; + if (a[2] || argv[i] == NULL) goto err; + ctx->outname = argv[i]; + break; + default: err: + usage(); + break; + } + } +ok: + ctx->args = argv+i; + if (ctx->mode == (BuildMode)-1) goto err; +} + +int main(int argc, char **argv) +{ + BuildCtx ctx_; + BuildCtx *ctx = &ctx_; + int status, binmode; + + if (sizeof(void *) != 4*LJ_32+8*LJ_64) { + fprintf(stderr,"Error: pointer size mismatch in cross-build.\n"); + fprintf(stderr,"Try: make HOST_CC=\"gcc -m32\" CROSS=...\n\n"); + return 1; + } + + UNUSED(argc); + parseargs(ctx, argv); + + if ((status = build_code(ctx))) { + fprintf(stderr,"Error: DASM error %08x\n", status); + return 1; + } + + switch (ctx->mode) { + case BUILD_peobj: + case BUILD_raw: + binmode = 1; + break; + default: + binmode = 0; + break; + } + + if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { + ctx->fp = stdout; +#if defined(_WIN32) + if (binmode) + _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ +#endif + } else if (!(ctx->fp = fopen(ctx->outname, binmode ? "wb" : "w"))) { + fprintf(stderr, "Error: cannot open output file '%s': %s\n", + ctx->outname, strerror(errno)); + exit(1); + } + + switch (ctx->mode) { + case BUILD_elfasm: + case BUILD_coffasm: + case BUILD_machasm: + emit_asm(ctx); + emit_asm_debug(ctx); + break; + case BUILD_peobj: + emit_peobj(ctx); + break; + case BUILD_raw: + emit_raw(ctx); + break; + case BUILD_bcdef: + emit_bcdef(ctx); + emit_lib(ctx); + break; + case BUILD_vmdef: + emit_vmdef(ctx); + emit_lib(ctx); + break; + case BUILD_ffdef: + case BUILD_libdef: + case BUILD_recdef: + emit_lib(ctx); + break; + case BUILD_folddef: + emit_fold(ctx); + break; + default: + break; + } + + fflush(ctx->fp); + if (ferror(ctx->fp)) { + fprintf(stderr, "Error: cannot write to output file: %s\n", + strerror(errno)); + exit(1); + } + fclose(ctx->fp); + + return 0; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.h new file mode 100644 index 0000000..f9dc8c4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm.h @@ -0,0 +1,104 @@ +/* +** LuaJIT VM builder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _BUILDVM_H +#define _BUILDVM_H + +#include +#include +#include +#include +#include + +#include "lj_def.h" +#include "lj_arch.h" + +/* Hardcoded limits. Increase as needed. */ +#define BUILD_MAX_RELOC 200 /* Max. number of relocations. */ +#define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */ + +/* Prefix for scanned library definitions. */ +#define LIBDEF_PREFIX "LJLIB_" + +/* Prefix for scanned fold definitions. */ +#define FOLDDEF_PREFIX "LJFOLD" + +/* Prefixes for generated labels. */ +#define LABEL_PREFIX "lj_" +#define LABEL_PREFIX_BC LABEL_PREFIX "BC_" +#define LABEL_PREFIX_FF LABEL_PREFIX "ff_" +#define LABEL_PREFIX_CF LABEL_PREFIX "cf_" +#define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_" +#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_" +#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" + +/* Forward declaration. */ +struct dasm_State; + +/* Build modes. */ +#define BUILDDEF(_) \ + _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \ + _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \ + _(folddef) + +typedef enum { +#define BUILDENUM(name) BUILD_##name, +BUILDDEF(BUILDENUM) +#undef BUILDENUM + BUILD__MAX +} BuildMode; + +/* Code relocation. */ +typedef struct BuildReloc { + int32_t ofs; + int sym; + int type; +} BuildReloc; + +typedef struct BuildSym { + const char *name; + int32_t ofs; +} BuildSym; + +/* Build context structure. */ +typedef struct BuildCtx { + /* DynASM state pointer. Should be first member. */ + struct dasm_State *D; + /* Parsed command line. */ + BuildMode mode; + FILE *fp; + const char *outname; + char **args; + /* Code and symbols generated by DynASM. */ + uint8_t *code; + size_t codesz; + int npc, nglob, nsym, nreloc, nrelocsym; + void **glob; + BuildSym *sym; + const char **relocsym; + int32_t *bc_ofs; + const char *beginsym; + /* Strings generated by DynASM. */ + const char *const *globnames; + const char *dasm_ident; + const char *dasm_arch; + /* Relocations. */ + BuildReloc reloc[BUILD_MAX_RELOC]; +} BuildCtx; + +extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz); +extern void emit_asm(BuildCtx *ctx); +extern void emit_peobj(BuildCtx *ctx); +extern void emit_lib(BuildCtx *ctx); +extern void emit_fold(BuildCtx *ctx); + +extern const char *const bc_names[]; +extern const char *const ir_names[]; +extern const char *const irt_names[]; +extern const char *const irfpm_names[]; +extern const char *const irfield_names[]; +extern const char *const ircall_names[]; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_arch.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_arch.h new file mode 100644 index 0000000..3fa7a19 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_arch.h @@ -0,0 +1,2136 @@ +/* +** This file has been pre-processed with DynASM. +** http://luajit.org/dynasm.html +** DynASM version 1.3.0, DynASM x86 version 1.3.0 +** DO NOT EDIT! The original file is in "vm_x86.dasc". +*/ + +#if DASM_VERSION != 10300 +#error "Version mismatch between DynASM and included encoding engine" +#endif +#define DASM_SECTION_CODE_OP 0 +#define DASM_SECTION_CODE_SUB 1 +#define DASM_MAXSECTION 2 +static const unsigned char build_actionlist[14066] = { + 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,141, + 76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,15,132,244, + 13,137,68,36,20,252,247,198,237,15,132,244,14,248,15,129,252,246,239,252, + 247,198,237,15,133,244,10,199,131,233,237,131,230,252,248,41,214,252,247, + 222,131,232,1,15,132,244,248,248,1,255,139,44,10,137,106,252,248,139,108, + 10,4,137,106,252,252,131,194,8,131,232,1,15,133,244,1,248,2,139,108,36,48, + 137,181,233,248,3,139,68,36,20,139,76,36,56,248,4,57,193,15,133,244,252,248, + 5,131,252,234,8,137,149,233,248,16,139,76,36,52,137,141,233,49,192,248,17, + 131,196,28,91,94,95,93,195,248,6,15,130,244,253,59,149,233,15,135,244,254, + 199,66,252,252,237,255,131,194,8,131,192,1,252,233,244,4,248,7,133,201,15, + 132,244,5,41,193,141,20,202,252,233,244,5,248,8,137,149,233,137,68,36,20, + 137,202,137,252,233,232,251,1,0,139,149,233,252,233,244,3,248,13,176,235, + 252,233,244,18,248,19,137,208,137,204,248,18,139,108,36,48,139,173,233,199, + 133,233,237,255,252,233,244,17,248,20,248,21,129,225,239,137,204,248,22,139, + 108,36,48,185,252,248,252,255,252,255,252,255,184,237,139,149,233,139,157, + 233,129,195,239,139,114,252,252,199,66,252,252,237,199,131,233,237,252,233, + 244,12,248,23,186,237,252,233,244,248,248,24,255,131,232,8,252,233,244,247, + 248,25,141,68,194,252,248,248,1,15,182,142,233,131,198,4,137,149,233,137, + 133,233,137,116,36,24,137,202,248,2,137,252,233,232,251,1,0,139,149,233,139, + 133,233,139,106,252,248,41,208,193,232,3,131,192,1,139,181,233,139,14,15, + 182,252,233,15,182,205,131,198,4,252,255,36,171,248,26,85,87,86,83,131,252, + 236,28,139,108,36,48,139,76,36,52,190,237,49,192,141,188,253,36,233,139,157, + 233,129,195,239,137,189,233,137,68,36,24,137,68,36,52,56,133,233,15,132,244, + 249,255,199,131,233,237,136,133,233,139,149,233,139,133,233,41,200,193,232, + 3,131,192,1,41,209,139,114,252,252,137,68,36,20,252,247,198,237,15,132,244, + 14,252,233,244,15,248,27,85,87,86,83,131,252,236,28,190,237,252,233,244,247, + 248,28,85,87,86,83,131,252,236,28,190,237,248,1,139,108,36,48,139,76,36,52, + 139,189,233,137,124,36,52,137,108,36,24,137,165,233,248,2,255,139,157,233, + 129,195,239,248,3,199,131,233,237,139,149,233,1,206,41,214,139,133,233,41, + 200,193,232,3,131,192,1,248,29,139,105,252,248,129,121,253,252,252,239,15, + 133,244,30,248,31,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233, + 15,182,205,131,198,4,252,255,36,171,248,32,85,87,86,83,131,252,236,28,139, + 108,36,48,139,68,36,56,139,76,36,52,139,84,36,60,137,108,36,24,139,189,233, + 43,189,233,199,68,36,60,0,0,0,0,137,124,36,56,137,68,36,8,137,76,36,4,137, + 44,36,139,189,233,137,124,36,52,137,165,233,252,255,210,133,192,15,132,244, + 16,255,137,193,190,237,252,233,244,2,248,11,1,209,131,230,252,248,137,213, + 41,252,242,199,68,193,252,252,237,137,200,139,117,252,244,139,77,252,240, + 131,252,249,1,15,134,244,247,139,122,252,248,139,191,233,139,191,233,252, + 255,225,248,1,15,132,244,33,41,213,193,252,237,3,141,69,252,255,252,233,244, + 34,248,35,15,182,78,252,255,131,252,237,16,141,12,202,41,252,233,15,132,244, + 36,252,247,217,193,252,233,3,137,76,36,8,139,72,4,139,0,137,77,4,137,69,0, + 137,108,36,4,252,233,244,37,248,38,255,137,68,36,16,199,68,36,20,237,141, + 68,36,16,128,126,252,252,235,15,133,244,247,141,139,233,137,41,199,65,4,237, + 137,205,252,233,244,248,248,39,15,182,70,252,254,137,68,36,12,219,68,36,12, + 221,92,36,16,141,68,36,16,252,233,244,247,248,40,15,182,70,252,254,141,4, + 194,248,1,15,182,110,252,255,141,44,252,234,248,2,137,108,36,4,139,108,36, + 48,137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1,1,139,149,233, + 133,192,15,132,244,249,248,36,15,182,78,252,253,139,104,4,139,0,137,108,202, + 4,137,4,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171, + 248,3,255,139,141,233,137,113,252,244,141,177,233,41,214,139,105,252,248, + 184,237,252,233,244,31,248,41,137,68,36,16,199,68,36,20,237,141,68,36,16, + 128,126,252,252,235,15,133,244,247,141,139,233,137,41,199,65,4,237,137,205, + 252,233,244,248,248,42,15,182,70,252,254,137,68,36,12,219,68,36,12,221,92, + 36,16,141,68,36,16,252,233,244,247,248,43,15,182,70,252,254,141,4,194,248, + 1,15,182,110,252,255,141,44,252,234,248,2,255,137,108,36,4,139,108,36,48, + 137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1,2,139,149,233,133, + 192,15,132,244,249,15,182,78,252,253,139,108,202,4,139,12,202,137,104,4,137, + 8,248,44,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171, + 248,3,139,141,233,137,113,252,244,15,182,70,252,253,139,108,194,4,139,4,194, + 137,105,20,137,65,16,141,177,233,41,214,139,105,252,248,184,237,252,233,244, + 31,248,45,15,182,110,252,252,141,4,194,141,12,202,137,108,36,12,139,108,36, + 48,137,68,36,8,137,76,36,4,137,44,36,137,149,233,137,116,36,24,232,251,1, + 3,248,3,139,149,233,131,252,248,1,15,135,244,46,248,4,141,118,4,15,130,244, + 252,248,5,255,15,183,70,252,254,141,180,253,134,233,248,6,139,6,15,182,204, + 15,182,232,131,198,4,193,232,16,252,255,36,171,248,47,131,198,4,129,120,253, + 4,239,15,130,244,5,252,233,244,6,248,48,129,120,253,4,239,252,233,244,4,248, + 49,131,252,238,4,137,108,36,12,139,108,36,48,137,68,36,8,137,76,36,4,137, + 44,36,137,149,233,137,116,36,24,232,251,1,4,252,233,244,3,248,50,131,252, + 238,4,139,108,36,48,137,149,233,137,252,233,139,86,252,252,137,116,36,24, + 232,251,1,5,252,233,244,3,248,51,248,52,255,141,4,199,252,233,244,247,248, + 53,248,54,141,4,199,141,44,252,234,149,252,233,244,248,248,55,141,4,194,137, + 197,252,233,244,248,248,56,248,57,141,4,194,248,1,141,44,252,234,248,2,141, + 12,202,137,108,36,8,139,108,36,48,137,68,36,12,15,182,70,252,252,137,76,36, + 4,137,68,36,16,137,44,36,137,149,233,137,116,36,24,232,251,1,6,139,149,233, + 133,192,15,132,244,44,248,46,137,193,41,208,137,113,252,244,141,176,233,184, + 237,255,252,233,244,29,248,58,139,108,36,48,137,149,233,141,20,194,137,252, + 233,137,116,36,24,232,251,1,7,139,149,233,255,133,192,15,133,244,46,15,183, + 70,252,254,139,12,194,252,233,244,59,255,252,233,244,46,255,248,60,141,76, + 202,8,248,30,137,76,36,20,137,68,36,16,131,252,233,8,141,4,193,139,108,36, + 48,137,76,36,4,137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1, + 8,139,149,233,139,76,36,20,139,68,36,16,139,105,252,248,131,192,1,57,215, + 15,132,244,61,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233,15, + 182,205,131,198,4,252,255,36,171,248,62,139,108,36,48,137,149,233,137,202, + 137,252,233,137,116,36,24,232,251,1,9,139,149,233,139,70,252,252,15,182,204, + 15,182,232,193,232,16,252,255,164,253,171,233,248,63,129,252,248,239,15,130, + 244,64,139,106,4,129,252,253,239,15,131,244,64,139,114,252,252,137,68,36, + 20,137,106,252,252,139,42,137,106,252,248,131,232,2,15,132,244,248,255,137, + 209,248,1,131,193,8,139,105,4,137,105,252,252,139,41,137,105,252,248,131, + 232,1,15,133,244,1,248,2,139,68,36,20,252,233,244,65,248,66,129,252,248,239, + 15,130,244,64,139,106,4,184,237,252,247,213,57,232,15,71,197,248,2,139,106, + 252,248,139,132,253,197,233,139,114,252,252,199,66,252,252,237,137,66,252, + 248,252,233,244,67,248,68,129,252,248,239,15,130,244,64,255,139,106,4,139, + 114,252,252,129,252,253,239,15,133,244,252,248,1,139,42,139,173,233,248,2, + 133,252,237,199,66,252,252,237,15,132,244,67,139,131,233,199,66,252,252,237, + 137,106,252,248,139,141,233,35,136,233,105,201,239,3,141,233,248,3,129,185, + 233,239,15,133,244,250,255,57,129,233,15,132,244,251,248,4,139,137,233,133, + 201,15,133,244,3,252,233,244,67,248,5,139,105,4,129,252,253,239,15,132,244, + 67,139,1,137,106,252,252,137,66,252,248,252,233,244,67,248,6,129,252,253, + 239,15,132,244,1,129,252,253,239,255,15,135,244,254,189,237,248,8,252,247, + 213,139,172,253,171,233,252,233,244,2,248,69,129,252,248,239,15,130,244,64, + 129,122,253,4,239,15,133,244,64,139,42,131,189,233,0,15,133,244,64,129,122, + 253,12,239,15,133,244,64,255,139,66,8,137,133,233,139,114,252,252,199,66, + 252,252,237,137,106,252,248,252,246,133,233,235,15,132,244,247,128,165,233, + 235,139,131,233,137,171,233,137,133,233,248,1,252,233,244,67,248,70,129,252, + 248,239,15,130,244,64,129,122,253,4,239,15,133,244,64,255,139,2,139,108,36, + 48,137,68,36,4,137,44,36,137,213,131,194,8,137,84,36,8,232,251,1,10,137,252, + 234,139,40,139,64,4,139,114,252,252,137,106,252,248,137,66,252,252,252,233, + 244,67,248,71,129,252,248,239,15,133,244,64,129,122,253,4,239,15,131,244, + 64,221,2,252,233,244,72,248,73,129,252,248,239,15,130,244,64,139,114,252, + 252,129,122,253,4,239,15,133,244,249,139,2,248,2,199,66,252,252,237,255,137, + 66,252,248,252,233,244,67,248,3,129,122,253,4,239,15,135,244,64,131,187,233, + 0,15,133,244,64,139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,139, + 108,36,48,137,149,233,137,116,36,24,137,252,233,232,251,1,11,139,149,233, + 252,233,244,2,248,75,255,129,252,248,239,15,130,244,64,15,132,244,248,248, + 1,129,122,253,4,239,15,133,244,64,139,108,36,48,137,149,233,137,149,233,139, + 114,252,252,139,2,137,68,36,4,137,44,36,131,194,8,137,84,36,8,137,116,36, + 24,232,251,1,12,139,149,233,133,192,15,132,244,249,139,106,8,139,66,12,137, + 106,252,248,137,66,252,252,139,106,16,139,66,20,137,42,137,66,4,248,76,184, + 237,252,233,244,77,248,2,199,66,12,237,255,252,233,244,1,248,3,199,66,252, + 252,237,252,233,244,67,248,78,129,252,248,239,15,130,244,64,139,42,129,122, + 253,4,239,15,133,244,64,255,131,189,233,0,15,133,244,64,255,139,106,252,248, + 139,133,233,139,114,252,252,199,66,252,252,237,137,66,252,248,199,66,12,237, + 184,237,252,233,244,77,248,79,129,252,248,239,15,130,244,64,129,122,253,4, + 239,15,133,244,64,129,122,253,12,239,15,131,244,64,139,114,252,252,221,66, + 8,217,232,222,193,219,20,36,221,90,252,248,139,4,36,139,42,59,133,233,15, + 131,244,248,193,224,3,3,133,233,248,1,255,129,120,253,4,239,15,132,244,80, + 139,40,139,64,4,137,42,137,66,4,252,233,244,76,248,2,131,189,233,0,15,132, + 244,80,137,252,233,137,213,137,194,232,251,1,13,137,252,234,133,192,15,133, + 244,1,248,80,184,237,252,233,244,77,248,81,129,252,248,239,15,130,244,64, + 139,42,129,122,253,4,239,255,139,106,252,248,139,133,233,139,114,252,252, + 199,66,252,252,237,137,66,252,248,217,252,238,221,90,8,184,237,252,233,244, + 77,248,82,129,252,248,239,15,130,244,64,141,74,8,131,232,1,190,237,248,1, + 15,182,171,233,193,252,237,235,131,229,1,1,252,238,252,233,244,29,248,83, + 129,252,248,239,15,130,244,64,129,122,253,12,239,255,15,133,244,64,139,106, + 4,137,106,12,199,66,4,237,139,42,139,114,8,137,106,8,137,50,141,74,16,131, + 232,2,190,237,252,233,244,1,248,84,129,252,248,239,15,130,244,64,139,42,139, + 114,252,252,137,116,36,24,137,44,36,129,122,253,4,239,15,133,244,64,131,189, + 233,0,15,133,244,64,128,189,233,235,15,135,244,64,255,139,141,233,15,132, + 244,247,59,141,233,15,132,244,64,248,1,141,116,193,252,240,59,181,233,15, + 135,244,64,137,181,233,139,108,36,48,137,149,233,131,194,8,137,149,233,141, + 108,194,232,41,252,245,57,206,15,132,244,249,248,2,139,68,46,4,137,70,252, + 252,139,4,46,137,70,252,248,131,252,238,8,57,206,15,133,244,2,248,3,137,76, + 36,4,49,201,137,76,36,12,137,76,36,8,232,244,26,255,199,131,233,237,139,108, + 36,48,139,52,36,139,149,233,129,252,248,239,15,135,244,254,248,4,139,142, + 233,139,190,233,137,142,233,137,252,254,41,206,15,132,244,252,141,4,50,193, + 252,238,3,59,133,233,15,135,244,255,137,213,41,205,248,5,139,1,137,4,41,139, + 65,4,137,68,41,4,131,193,8,57,252,249,15,133,244,5,248,6,141,70,2,199,66, + 252,252,237,248,7,255,139,116,36,24,137,68,36,20,185,252,248,252,255,252, + 255,252,255,252,247,198,237,15,132,244,14,252,233,244,15,248,8,199,66,252, + 252,237,139,142,233,131,252,233,8,137,142,233,139,1,137,2,139,65,4,137,66, + 4,184,237,252,233,244,7,248,9,139,12,36,137,185,233,137,252,242,137,252,233, + 232,251,1,0,139,52,36,139,149,233,252,233,244,4,248,85,139,106,252,248,139, + 173,233,139,114,252,252,137,116,36,24,137,44,36,131,189,233,0,255,15,133, + 244,64,128,189,233,235,15,135,244,64,139,141,233,15,132,244,247,59,141,233, + 15,132,244,64,248,1,141,116,193,252,248,59,181,233,15,135,244,64,137,181, + 233,139,108,36,48,137,149,233,137,149,233,141,108,194,252,240,41,252,245, + 57,206,15,132,244,249,248,2,255,139,68,46,4,137,70,252,252,139,4,46,137,70, + 252,248,131,252,238,8,57,206,15,133,244,2,248,3,137,76,36,4,49,201,137,76, + 36,12,137,76,36,8,232,244,26,199,131,233,237,139,108,36,48,139,52,36,139, + 149,233,129,252,248,239,15,135,244,254,248,4,139,142,233,139,190,233,137, + 142,233,137,252,254,41,206,15,132,244,252,141,4,50,193,252,238,3,59,133,233, + 15,135,244,255,255,137,213,41,205,248,5,139,1,137,4,41,139,65,4,137,68,41, + 4,131,193,8,57,252,249,15,133,244,5,248,6,141,70,1,248,7,139,116,36,24,137, + 68,36,20,49,201,252,247,198,237,15,132,244,14,252,233,244,15,248,8,137,252, + 242,137,252,233,232,251,1,14,248,9,139,12,36,137,185,233,137,252,242,137, + 252,233,232,251,1,0,139,52,36,139,149,233,252,233,244,4,248,86,139,108,36, + 48,252,247,133,233,237,15,132,244,64,255,137,149,233,141,68,194,252,248,137, + 133,233,49,192,137,133,233,176,235,136,133,233,252,233,244,17,248,87,248, + 88,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217, + 225,248,89,248,72,139,114,252,252,221,90,252,248,248,67,184,237,248,77,255, + 137,68,36,20,248,65,252,247,198,237,15,133,244,253,248,5,56,70,252,255,15, + 135,244,252,15,182,78,252,253,252,247,209,141,20,202,139,6,15,182,204,15, + 182,232,131,198,4,193,232,16,252,255,36,171,248,6,199,68,194,252,244,237, + 131,192,1,252,233,244,5,248,7,185,252,248,252,255,252,255,252,255,252,233, + 244,15,248,90,129,122,253,4,239,15,131,244,64,221,2,232,244,91,255,252,233, + 244,72,248,92,129,122,253,4,239,15,131,244,64,221,2,232,244,93,252,233,244, + 72,248,94,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221, + 2,217,252,250,252,233,244,72,248,95,255,129,252,248,239,15,133,244,64,129, + 122,253,4,239,15,131,244,64,217,252,237,221,2,217,252,241,252,233,244,72, + 248,96,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,217, + 252,236,221,2,217,252,241,252,233,244,72,248,97,129,252,248,239,15,130,244, + 64,255,129,122,253,4,239,15,131,244,64,221,2,232,244,98,252,233,244,72,248, + 99,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217, + 252,254,252,233,244,72,248,100,129,252,248,239,15,130,244,64,255,129,122, + 253,4,239,15,131,244,64,221,2,217,252,255,252,233,244,72,248,101,129,252, + 248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217,252,242,221, + 216,252,233,244,72,248,102,129,252,248,239,15,130,244,64,129,122,253,4,239, + 15,131,244,64,255,221,2,217,192,216,200,217,232,222,225,217,252,250,217,252, + 243,252,233,244,72,248,103,129,252,248,239,15,130,244,64,129,122,253,4,239, + 15,131,244,64,221,2,217,192,216,200,217,232,222,225,217,252,250,217,201,217, + 252,243,252,233,244,72,248,104,129,252,248,239,15,130,244,64,129,122,253, + 4,239,15,131,244,64,221,2,217,232,217,252,243,252,233,244,72,248,105,255, + 129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,221,28, + 36,137,213,232,251,1,15,137,252,234,252,233,244,72,248,106,129,252,248,239, + 15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,221,28,36,137,213,232, + 251,1,16,137,252,234,252,233,244,72,248,107,129,252,248,239,15,130,244,64, + 255,129,122,253,4,239,15,131,244,64,221,2,221,28,36,137,213,232,251,1,17, + 137,252,234,252,233,244,72,248,108,248,109,129,252,248,239,15,130,244,64, + 129,122,253,4,239,15,131,244,64,221,2,139,106,252,248,220,141,233,252,233, + 244,72,248,110,129,252,248,239,15,130,244,64,255,129,122,253,4,239,15,131, + 244,64,129,122,253,12,239,15,131,244,64,221,2,221,66,8,217,252,243,252,233, + 244,72,248,111,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244, + 64,129,122,253,12,239,15,131,244,64,221,66,8,221,2,217,252,253,221,217,252, + 233,244,72,248,112,255,129,252,248,239,15,130,244,64,139,106,4,129,252,253, + 239,15,131,244,64,139,114,252,252,139,2,137,106,252,252,137,66,252,248,209, + 229,129,252,253,0,0,224,252,255,15,131,244,249,9,232,15,132,244,249,184,252, + 254,3,0,0,129,252,253,0,0,32,0,15,130,244,250,248,1,193,252,237,21,41,197, + 137,108,36,16,219,68,36,16,139,106,252,252,129,229,252,255,252,255,15,128, + 129,205,0,0,224,63,137,106,252,252,248,2,221,26,184,237,252,233,244,77,248, + 3,217,252,238,252,233,244,2,248,4,255,221,2,199,68,36,16,0,0,128,90,216,76, + 36,16,221,90,252,248,139,106,252,252,184,52,4,0,0,209,229,252,233,244,1,248, + 113,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,139, + 106,4,139,114,252,252,209,229,129,252,253,0,0,224,252,255,15,132,244,250, + 217,192,232,244,114,220,252,233,248,1,221,90,252,248,221,26,139,66,252,252, + 139,106,4,49,232,15,136,244,249,248,2,184,237,252,233,244,77,248,3,255,129, + 252,245,0,0,0,128,137,106,4,252,233,244,2,248,4,217,252,238,217,201,252,233, + 244,1,248,115,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244, + 64,129,122,253,12,239,15,131,244,64,221,66,8,221,2,248,1,217,252,248,223, + 224,158,15,138,244,1,221,217,252,233,244,72,248,116,255,129,252,248,239,15, + 130,244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,244, + 64,221,2,221,66,8,232,244,117,252,233,244,72,248,118,185,2,0,0,0,129,122, + 253,4,239,15,131,244,64,221,2,248,5,57,193,15,131,244,72,255,129,124,253, + 202,252,252,239,15,131,244,255,248,6,221,68,202,252,248,248,7,219,252,233, + 219,209,221,217,131,193,1,252,233,244,5,248,119,185,2,0,0,0,129,122,253,4, + 239,15,131,244,64,221,2,248,5,57,193,15,131,244,72,129,124,253,202,252,252, + 239,15,131,244,255,248,6,221,68,202,252,248,248,7,219,252,233,218,209,221, + 217,131,193,1,252,233,244,5,248,9,255,221,216,252,233,244,64,248,120,129, + 252,248,239,15,130,244,64,129,122,253,4,239,15,133,244,64,139,42,219,133, + 233,252,233,244,72,248,121,129,252,248,239,15,133,244,64,129,122,253,4,239, + 15,133,244,64,139,42,139,114,252,252,131,189,233,1,255,15,130,244,80,15,182, + 173,233,137,108,36,16,219,68,36,16,252,233,244,72,248,122,139,171,233,59, + 171,233,15,130,244,247,232,244,74,248,1,129,252,248,239,15,133,244,64,129, + 122,253,4,239,15,131,244,64,221,2,219,92,36,20,129,124,36,20,252,255,0,0, + 0,15,135,244,64,255,199,68,36,8,1,0,0,0,141,68,36,20,248,123,139,108,36,48, + 137,149,233,137,68,36,4,137,44,36,137,116,36,24,232,251,1,18,139,149,233, + 139,114,252,252,199,66,252,252,237,137,66,252,248,252,233,244,67,248,124, + 139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,199,68,36,20,252,255, + 252,255,252,255,252,255,129,252,248,239,15,130,244,64,15,134,244,247,129, + 122,253,20,239,255,15,131,244,64,221,66,16,219,92,36,20,248,1,129,122,253, + 4,239,15,133,244,64,129,122,253,12,239,15,131,244,64,139,42,137,108,36,12, + 139,173,233,221,66,8,219,92,36,8,139,76,36,8,139,68,36,20,57,197,15,130,244, + 251,248,2,133,201,15,142,244,253,248,3,139,108,36,12,41,200,15,140,244,125, + 141,172,253,13,233,131,192,1,248,4,255,137,68,36,8,137,232,252,233,244,123, + 248,5,15,140,244,252,141,68,40,1,252,233,244,2,248,6,137,232,252,233,244, + 2,248,7,15,132,244,254,1,252,233,131,193,1,15,143,244,3,248,8,185,1,0,0,0, + 252,233,244,3,248,125,49,192,252,233,244,4,248,126,255,139,171,233,59,171, + 233,15,130,244,247,232,244,74,248,1,129,252,248,239,15,133,244,64,129,122, + 253,4,239,15,133,244,64,129,122,253,12,239,139,42,15,131,244,64,221,66,8, + 219,92,36,20,139,68,36,20,133,192,15,142,244,125,131,189,233,1,15,130,244, + 125,255,15,133,244,127,57,131,233,15,130,244,127,15,182,141,233,139,171,233, + 137,68,36,8,248,1,136,77,0,131,197,1,131,232,1,15,133,244,1,139,131,233,252, + 233,244,123,248,128,129,252,248,239,15,130,244,64,139,171,233,59,171,233, + 15,130,244,247,255,232,244,74,248,1,129,122,253,4,239,15,133,244,64,139,42, + 139,133,233,133,192,15,132,244,125,57,131,233,15,130,244,129,129,197,239, + 137,116,36,20,137,68,36,8,139,179,233,248,1,15,182,77,0,131,197,1,131,232, + 1,136,12,6,15,133,244,1,137,252,240,139,116,36,20,252,233,244,123,248,130, + 255,129,252,248,239,15,130,244,64,139,171,233,59,171,233,15,130,244,247,232, + 244,74,248,1,129,122,253,4,239,15,133,244,64,139,42,139,133,233,57,131,233, + 15,130,244,129,129,197,239,137,116,36,20,137,68,36,8,139,179,233,252,233, + 244,249,248,1,255,15,182,76,5,0,131,252,249,65,15,130,244,248,131,252,249, + 90,15,135,244,248,131,252,241,32,248,2,136,12,6,248,3,131,232,1,15,137,244, + 1,137,252,240,139,116,36,20,252,233,244,123,248,131,129,252,248,239,15,130, + 244,64,139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,255,129,122, + 253,4,239,15,133,244,64,139,42,139,133,233,57,131,233,15,130,244,129,129, + 197,239,137,116,36,20,137,68,36,8,139,179,233,252,233,244,249,248,1,15,182, + 76,5,0,131,252,249,97,15,130,244,248,131,252,249,122,15,135,244,248,131,252, + 241,32,248,2,136,12,6,248,3,131,232,1,15,137,244,1,255,137,252,240,139,116, + 36,20,252,233,244,123,248,132,129,252,248,239,15,130,244,64,129,122,253,4, + 239,15,133,244,64,137,213,139,10,232,251,1,19,137,252,234,137,4,36,219,4, + 36,252,233,244,72,248,133,129,252,248,239,15,130,244,64,129,122,253,4,239, + 15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16,221,28,36,248,2, + 219,4,36,252,233,244,72,248,134,255,129,252,248,239,15,130,244,64,199,68, + 36,16,0,0,192,89,129,122,253,4,239,15,131,244,64,221,2,216,68,36,16,221,28, + 36,139,44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,57,208,15,134,244, + 135,129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,35,44,36, + 131,232,8,252,233,244,1,248,137,129,252,248,239,15,130,244,64,199,68,36,16, + 0,0,192,89,129,122,253,4,239,255,15,131,244,64,221,2,216,68,36,16,221,28, + 36,139,44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,57,208,15,134,244, + 135,129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,11,44,36, + 131,232,8,252,233,244,1,248,138,129,252,248,239,15,130,244,64,199,68,36,16, + 0,0,192,89,129,122,253,4,239,15,131,244,64,221,2,216,68,36,16,221,28,36,139, + 44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,255,57,208,15,134,244,135, + 129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,51,44,36,131, + 232,8,252,233,244,1,248,139,129,252,248,239,15,130,244,64,129,122,253,4,239, + 15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16,221,28,36,139,44, + 36,248,2,15,205,252,233,244,135,248,140,129,252,248,239,15,130,244,64,255, + 129,122,253,4,239,15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16, + 221,28,36,139,44,36,248,2,252,247,213,248,135,137,44,36,219,4,36,252,233, + 244,72,248,136,139,68,36,20,252,233,244,64,248,141,129,252,248,239,15,130, + 244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,255, + 221,2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36, + 16,221,28,36,139,76,36,8,139,44,36,211,229,252,233,244,135,248,142,129,252, + 248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239, + 15,131,244,64,221,2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92, + 36,8,216,68,36,16,221,28,36,139,76,36,8,139,44,36,211,252,237,252,233,244, + 135,248,143,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64, + 255,129,122,253,12,239,15,131,244,64,221,2,221,66,8,199,68,36,16,0,0,192, + 89,216,68,36,16,221,92,36,8,216,68,36,16,221,28,36,139,76,36,8,139,44,36, + 211,252,253,252,233,244,135,248,144,129,252,248,239,15,130,244,64,129,122, + 253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,221,2,221,66,8,199, + 68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36,16,221,28,36,139,76, + 36,8,139,44,36,211,197,252,233,244,135,248,145,129,252,248,239,15,130,244, + 64,255,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,221, + 2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36,16, + 221,28,36,139,76,36,8,139,44,36,211,205,252,233,244,135,248,127,184,237,252, + 233,244,64,248,129,184,237,248,64,139,108,36,48,139,114,252,252,137,116,36, + 24,137,149,233,141,68,194,252,248,141,136,233,137,133,233,139,66,252,248, + 59,141,233,15,135,244,251,255,137,44,36,252,255,144,233,139,149,233,133,192, + 15,143,244,77,248,1,139,141,233,41,209,193,252,233,3,133,192,141,65,1,139, + 106,252,248,15,133,244,34,139,181,233,139,14,15,182,252,233,15,182,205,131, + 198,4,252,255,36,171,248,34,137,209,252,247,198,237,15,133,244,249,15,182, + 110,252,253,252,247,213,141,20,252,234,252,233,244,29,248,3,137,252,245,131, + 229,252,248,41,252,234,252,233,244,29,248,5,186,237,255,137,252,233,232,251, + 1,0,139,149,233,49,192,252,233,244,1,248,74,93,137,108,36,16,139,108,36,48, + 137,116,36,24,137,149,233,141,68,194,252,248,137,252,233,137,133,233,232, + 251,1,20,139,149,233,139,133,233,41,208,193,232,3,131,192,1,139,108,36,16, + 85,195,248,146,15,182,131,233,168,235,15,133,244,251,168,235,15,133,244,247, + 168,235,15,132,244,247,252,255,139,233,255,252,233,244,247,248,147,15,182, + 131,233,168,235,15,133,244,251,252,233,244,247,248,148,15,182,131,233,168, + 235,15,133,244,251,168,235,15,132,244,251,252,255,139,233,15,132,244,247, + 255,168,235,15,132,244,251,248,1,139,108,36,48,137,149,233,137,252,242,137, + 252,233,232,251,1,21,248,3,139,149,233,248,4,15,182,78,252,253,248,5,15,182, + 110,252,252,15,183,70,252,254,252,255,164,253,171,233,248,149,131,198,4,139, + 77,232,137,76,36,20,252,233,244,4,248,150,139,106,252,248,139,173,233,15, + 182,133,233,141,4,194,139,108,36,48,137,149,233,137,133,233,137,252,242,141, + 139,233,137,171,233,255,137,116,36,24,232,251,1,22,252,233,244,3,248,151, + 137,116,36,24,252,233,244,247,248,152,137,116,36,24,131,206,1,248,1,141,68, + 194,252,248,139,108,36,48,137,149,233,137,133,233,137,252,242,137,252,233, + 232,251,1,23,199,68,36,24,0,0,0,0,131,230,252,254,139,149,233,137,193,139, + 133,233,41,208,137,205,15,182,78,252,253,193,232,3,131,192,1,252,255,229, + 248,153,85,141,108,36,12,85,83,82,81,80,15,182,69,252,252,138,101,252,248, + 137,125,252,252,137,117,252,248,139,93,0,139,139,233,199,131,233,237,137, + 131,233,137,139,233,129,252,236,239,252,242,15,17,125,216,252,242,15,17,117, + 208,252,242,15,17,109,200,252,242,15,17,101,192,252,242,15,17,93,184,252, + 242,15,17,85,176,252,242,15,17,77,168,252,242,15,17,69,160,139,171,233,139, + 147,233,255,137,171,233,199,131,233,0,0,0,0,137,149,233,141,84,36,16,141, + 139,233,232,251,1,24,139,141,233,129,225,239,137,204,137,169,233,139,149, + 233,139,177,233,248,154,133,192,15,136,244,249,137,68,36,20,139,122,252,248, + 139,191,233,139,191,233,199,131,233,0,0,0,0,199,131,233,237,139,6,15,182, + 204,15,182,232,131,198,4,193,232,16,129,252,253,239,15,130,244,248,255,139, + 68,36,20,248,2,252,255,36,171,248,3,252,247,216,137,252,233,137,194,232,251, + 1,25,248,91,217,124,36,4,137,68,36,8,102,184,0,4,102,11,68,36,4,102,37,252, + 255,252,247,102,137,68,36,6,217,108,36,6,217,252,252,217,108,36,4,139,68, + 36,8,195,248,155,102,15,252,239,210,102,15,118,210,102,15,115,210,1,184,0, + 0,48,67,102,15,110,216,102,15,112,219,81,15,40,200,102,15,84,202,102,15,46, + 217,15,134,244,247,102,15,85,208,252,242,15,88,203,252,242,15,92,203,102, + 15,86,202,184,0,0,252,240,63,102,15,110,208,102,15,112,210,81,252,242,15, + 194,193,1,102,15,84,194,252,242,15,92,200,15,40,193,248,1,195,248,93,217, + 124,36,4,137,68,36,8,102,184,0,8,102,11,68,36,4,102,37,252,255,252,251,102, + 137,68,36,6,217,108,36,6,217,252,252,217,108,36,4,139,68,36,8,195,248,156, + 102,15,252,239,210,102,15,118,210,102,15,115,210,1,184,0,0,48,67,102,15,110, + 216,102,15,112,219,81,15,40,200,102,15,84,202,102,15,46,217,15,134,244,247, + 102,15,85,208,252,242,15,88,203,252,242,15,92,203,102,15,86,202,184,0,0,252, + 240,191,102,15,110,208,102,15,112,210,81,252,242,15,194,193,6,102,15,84,194, + 252,242,15,92,200,15,40,193,248,1,195,248,114,217,124,36,4,137,68,36,8,102, + 184,0,12,102,11,68,36,4,102,137,68,36,6,217,108,36,6,217,252,252,217,108, + 36,4,139,68,36,8,195,248,157,102,15,252,239,210,102,15,118,210,102,15,115, + 210,1,184,0,0,48,67,102,15,110,216,102,15,112,219,81,15,40,200,102,15,84, + 202,102,15,46,217,15,134,244,247,102,15,85,208,15,40,193,252,242,15,88,203, + 252,242,15,92,203,184,0,0,252,240,63,102,15,110,216,102,15,112,219,81,252, + 242,15,194,193,1,102,15,84,195,252,242,15,92,200,102,15,86,202,15,40,193, + 248,1,195,248,158,217,193,216,252,241,217,124,36,4,102,184,0,4,102,11,68, + 36,4,102,37,252,255,252,247,102,137,68,36,6,217,108,36,6,217,252,252,217, + 108,36,4,222,201,222,252,233,195,248,159,217,232,221,68,36,4,217,252,241, + 195,248,98,255,217,252,234,222,201,248,160,217,84,36,4,129,124,36,4,0,0,128, + 127,15,132,244,247,129,124,36,4,0,0,128,252,255,15,132,244,248,248,161,217, + 192,217,252,252,220,252,233,217,201,217,252,240,217,232,222,193,217,252,253, + 221,217,248,1,195,248,2,221,216,217,252,238,195,248,117,219,84,36,4,219,68, + 36,4,223,252,233,15,133,244,254,15,138,244,255,221,216,139,68,36,4,131,252, + 248,1,15,142,244,252,248,1,169,1,0,0,0,15,133,244,248,216,200,209,232,252, + 233,244,1,248,2,255,209,232,15,132,244,251,217,192,248,3,216,200,209,232, + 15,132,244,250,15,131,244,3,220,201,252,233,244,3,248,4,222,201,248,5,195, + 248,6,15,132,244,5,15,130,244,253,217,232,222,252,241,252,247,216,131,252, + 248,1,15,132,244,5,252,233,244,1,248,7,255,221,216,217,232,195,248,8,217, + 84,36,4,217,201,217,84,36,8,139,68,36,4,209,224,61,0,0,0,252,255,15,132,244, + 248,139,68,36,8,209,224,15,132,244,250,61,0,0,0,252,255,15,132,244,250,217, + 252,241,252,233,244,161,248,9,217,232,223,252,234,15,132,244,247,217,201, + 248,1,221,216,195,248,2,217,225,217,232,223,252,233,15,132,244,249,221,216, + 217,225,217,252,238,184,0,0,0,0,15,146,208,209,200,51,68,36,4,15,137,244, + 249,217,201,248,3,221,217,217,225,195,248,4,255,131,124,36,4,0,15,141,244, + 3,221,216,221,216,133,192,15,132,244,251,217,252,238,195,248,5,199,68,36, + 4,0,0,128,127,217,68,36,4,195,248,162,252,242,15,45,193,252,242,15,42,208, + 102,15,46,202,15,133,244,254,15,138,244,255,248,163,131,252,248,1,15,142, + 244,252,248,1,169,1,0,0,0,15,133,244,248,252,242,15,89,192,209,232,252,233, + 244,1,248,2,209,232,15,132,244,251,255,15,40,200,248,3,252,242,15,89,192, + 209,232,15,132,244,250,15,131,244,3,252,242,15,89,200,252,233,244,3,248,4, + 252,242,15,89,193,248,5,195,248,6,15,132,244,5,15,130,244,253,252,247,216, + 232,244,1,184,0,0,252,240,63,102,15,110,200,102,15,112,201,81,252,242,15, + 94,200,15,40,193,195,248,7,184,0,0,252,240,63,102,15,110,192,102,15,112,192, + 81,195,248,8,252,242,15,17,76,36,12,252,242,15,17,68,36,4,131,124,36,12,0, + 15,133,244,247,255,139,68,36,16,209,224,61,0,0,224,252,255,15,132,244,248, + 248,1,131,124,36,4,0,15,133,244,247,139,68,36,8,209,224,15,132,244,250,61, + 0,0,224,252,255,15,132,244,251,248,1,221,68,36,12,221,68,36,4,217,252,241, + 217,192,217,252,252,220,252,233,217,201,217,252,240,217,232,222,193,217,252, + 253,221,217,221,92,36,4,252,242,15,16,68,36,4,195,248,9,184,0,0,252,240,63, + 102,15,110,208,102,15,112,210,81,102,15,46,194,15,132,244,247,15,40,193,248, + 1,195,248,2,102,15,252,239,210,102,15,118,210,102,15,115,210,1,102,15,84, + 194,184,0,0,252,240,63,102,15,110,208,102,15,112,210,81,102,15,46,194,15, + 132,244,1,102,15,80,193,15,87,192,136,196,15,146,208,48,224,15,133,244,1, + 248,3,255,184,0,0,252,240,127,102,15,110,192,102,15,112,192,81,195,248,4, + 102,15,80,193,133,192,15,133,244,3,15,87,192,195,248,5,102,15,80,193,133, + 192,15,132,244,3,15,87,192,195,248,164,139,68,36,12,221,68,36,4,131,252,248, + 1,15,130,244,91,15,132,244,93,131,252,248,3,15,130,244,114,15,135,244,248, + 217,252,250,195,248,2,131,252,248,5,15,130,244,98,15,132,244,160,255,131, + 252,248,7,15,132,244,247,15,135,244,248,217,252,237,217,201,217,252,241,195, + 248,1,217,232,217,201,217,252,241,195,248,2,131,252,248,9,15,132,244,247, + 15,135,244,248,217,252,236,217,201,217,252,241,195,248,1,217,252,254,195, + 248,2,131,252,248,11,15,132,244,247,15,135,244,255,217,252,255,195,248,1, + 217,252,242,221,216,195,248,9,204,248,165,139,68,36,20,221,68,36,4,221,68, + 36,12,131,252,248,1,15,132,244,247,255,15,135,244,248,222,193,195,248,1,222, + 252,233,195,248,2,131,252,248,3,15,132,244,247,15,135,244,248,222,201,195, + 248,1,222,252,249,195,248,2,131,252,248,5,15,130,244,158,15,132,244,117,131, + 252,248,7,15,132,244,247,15,135,244,248,221,216,217,224,195,248,1,221,216, + 217,225,195,248,2,255,131,252,248,9,15,132,244,247,15,135,244,248,217,252, + 243,195,248,1,217,201,217,252,253,221,217,195,248,2,131,252,248,11,15,132, + 244,247,15,135,244,255,219,252,233,219,209,221,217,195,248,1,219,252,233, + 218,209,221,217,195,248,9,204,248,166,156,90,137,209,129,252,242,0,0,32,0, + 82,157,156,90,49,192,57,209,15,132,244,247,139,68,36,4,87,83,15,162,139,124, + 36,16,137,7,137,95,4,137,79,8,137,87,12,91,95,248,1,195,248,167,255,204,255, + 204,248,168,131,252,236,16,87,86,83,131,252,236,28,141,157,233,139,181,233, + 15,183,192,137,134,233,141,132,253,36,233,137,142,233,137,150,233,137,134, + 233,139,140,253,36,233,139,148,253,36,233,137,76,36,44,137,84,36,40,137,226, + 137,116,36,24,137,252,241,232,251,1,26,199,131,233,237,139,144,233,139,128, + 233,41,208,139,106,252,248,193,232,3,131,192,1,139,181,233,139,14,15,182, + 252,233,15,182,205,131,198,4,252,255,36,171,248,33,139,76,36,48,139,179,233, + 137,142,233,137,145,233,137,169,233,255,137,252,241,137,194,232,251,1,27, + 139,108,36,48,139,134,233,139,150,233,131,190,233,1,15,130,244,253,15,132, + 244,252,221,134,233,252,233,244,253,248,6,217,134,233,248,7,139,141,233,15, + 183,73,6,137,76,36,48,131,196,28,91,94,95,93,89,3,36,36,131,196,16,81,195, + 248,169,85,137,229,83,137,203,43,163,233,137,163,233,15,182,139,233,131,252, + 233,1,15,136,244,248,248,1,255,139,132,253,139,233,137,4,140,131,252,233, + 1,15,137,244,1,248,2,139,139,233,139,147,233,252,255,147,233,137,131,233, + 137,147,233,128,187,233,1,15,130,244,253,15,132,244,252,221,155,233,252,233, + 244,253,248,6,217,155,233,248,7,255,41,163,233,139,93,252,252,201,195,255, + 129,124,253,202,4,239,15,131,244,45,129,124,253,194,4,239,15,131,244,45,248, + 1,221,4,202,248,2,221,4,194,248,3,131,198,4,223,252,233,221,216,255,15,134, + 244,247,255,15,135,244,247,255,15,131,244,247,255,15,183,70,252,254,141,180, + 253,134,233,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255, + 36,171,255,139,108,194,4,131,198,4,255,129,252,253,239,15,131,244,251,129, + 124,253,202,4,239,15,131,244,251,248,1,221,4,202,248,2,221,4,194,248,4,223, + 252,233,221,216,255,15,138,244,248,15,133,244,248,255,15,138,244,248,15,132, + 244,247,255,248,1,15,183,70,252,254,141,180,253,134,233,248,2,255,248,2,15, + 183,70,252,254,141,180,253,134,233,248,1,255,252,233,244,9,255,248,5,129, + 252,253,239,15,132,244,50,129,124,253,202,4,239,15,132,244,50,57,108,202, + 4,15,133,244,2,129,252,253,239,15,131,244,1,139,12,202,139,4,194,57,193,15, + 132,244,1,129,252,253,239,15,135,244,2,139,169,233,133,252,237,15,132,244, + 2,255,252,246,133,233,235,15,133,244,2,255,49,252,237,255,189,1,0,0,0,255, + 252,233,244,49,255,248,3,129,252,253,239,255,15,133,244,9,255,252,233,244, + 50,255,252,247,208,139,108,202,4,131,198,4,129,252,253,239,15,133,244,249, + 139,12,202,59,12,135,255,139,108,202,4,131,198,4,255,129,252,253,239,15,131, + 244,249,248,1,221,4,199,248,2,221,4,202,248,4,223,252,233,221,216,255,252, + 247,208,139,108,202,4,131,198,4,57,197,255,15,133,244,249,15,183,70,252,254, + 141,180,253,134,233,248,2,139,6,15,182,204,15,182,232,131,198,4,193,232,16, + 252,255,36,171,248,3,129,252,253,239,15,133,244,2,252,233,244,50,255,15,132, + 244,248,129,252,253,239,15,132,244,50,15,183,70,252,254,141,180,253,134,233, + 248,2,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255, + 139,108,194,4,131,198,4,129,252,253,239,255,137,108,202,4,139,44,194,137, + 44,202,255,139,108,194,4,139,4,194,137,108,202,4,137,4,202,139,6,15,182,204, + 15,182,232,131,198,4,193,232,16,252,255,36,171,255,49,252,237,129,124,253, + 194,4,239,129,213,239,137,108,202,4,139,6,15,182,204,15,182,232,131,198,4, + 193,232,16,252,255,36,171,255,129,124,253,194,4,239,15,131,244,55,221,4,194, + 217,224,221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255, + 36,171,255,129,124,253,194,4,239,15,133,244,248,139,4,194,219,128,233,248, + 1,221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36, + 171,248,2,129,124,253,194,4,239,15,133,244,58,139,12,194,255,139,169,233, + 131,252,253,0,15,133,244,255,248,3,255,248,59,137,213,232,251,1,19,137,4, + 36,219,4,36,137,252,234,15,182,78,252,253,252,233,244,1,255,248,9,252,246, + 133,233,235,15,133,244,3,252,233,244,58,255,15,182,252,236,15,182,192,255, + 129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,220,4,199,255,129,124, + 253,252,234,4,239,15,131,244,54,221,4,199,220,4,252,234,255,129,124,253,252, + 234,4,239,15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252,234, + 220,4,194,255,129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,220,36, + 199,255,129,124,253,252,234,4,239,15,131,244,54,221,4,199,220,36,252,234, + 255,129,124,253,252,234,4,239,15,131,244,57,129,124,253,194,4,239,15,131, + 244,57,221,4,252,234,220,36,194,255,129,124,253,252,234,4,239,15,131,244, + 52,221,4,252,234,220,12,199,255,129,124,253,252,234,4,239,15,131,244,54,221, + 4,199,220,12,252,234,255,129,124,253,252,234,4,239,15,131,244,57,129,124, + 253,194,4,239,15,131,244,57,221,4,252,234,220,12,194,255,129,124,253,252, + 234,4,239,15,131,244,52,221,4,252,234,220,52,199,255,129,124,253,252,234, + 4,239,15,131,244,54,221,4,199,220,52,252,234,255,129,124,253,252,234,4,239, + 15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252,234,220,52,194, + 255,129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,221,4,199,255,129, + 124,253,252,234,4,239,15,131,244,54,221,4,199,221,4,252,234,255,129,124,253, + 252,234,4,239,15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252, + 234,221,4,194,255,248,170,232,244,158,221,28,202,139,6,15,182,204,15,182, + 232,131,198,4,193,232,16,252,255,36,171,255,252,233,244,170,255,232,244,117, + 221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171, + 255,15,182,252,236,15,182,192,141,12,194,41,232,137,76,36,4,137,68,36,8,248, + 37,139,108,36,48,137,44,36,137,149,233,137,116,36,24,232,251,1,28,139,149, + 233,133,192,15,133,244,46,15,182,110,252,255,15,182,78,252,253,139,68,252, + 234,4,139,44,252,234,137,68,202,4,137,44,202,139,6,15,182,204,15,182,232, + 131,198,4,193,232,16,252,255,36,171,255,252,247,208,139,4,135,199,68,202, + 4,237,137,4,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255, + 36,171,255,223,70,252,254,221,28,202,139,6,15,182,204,15,182,232,131,198, + 4,193,232,16,252,255,36,171,255,221,4,199,221,28,202,139,6,15,182,204,15, + 182,232,131,198,4,193,232,16,252,255,36,171,255,252,247,208,137,68,202,4, + 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,141,76, + 202,12,141,68,194,4,189,237,137,105,252,248,248,1,137,41,131,193,8,57,193, + 15,134,244,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36, + 171,255,139,106,252,248,139,172,253,133,233,139,173,233,139,69,4,139,109, + 0,137,68,202,4,137,44,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16, + 252,255,36,171,255,139,106,252,248,139,172,253,141,233,128,189,233,0,139, + 173,233,139,12,194,139,68,194,4,137,77,0,137,69,4,15,132,244,247,252,246, + 133,233,235,15,133,244,248,248,1,139,6,15,182,204,15,182,232,131,198,4,193, + 232,16,252,255,36,171,248,2,129,232,239,129,252,248,239,15,134,244,1,252, + 246,129,233,235,15,132,244,1,135,213,141,139,233,255,232,251,1,29,137,252, + 234,252,233,244,1,255,252,247,208,139,106,252,248,139,172,253,141,233,139, + 12,135,139,133,233,137,8,199,64,4,237,252,246,133,233,235,15,133,244,248, + 248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248, + 2,252,246,129,233,235,15,132,244,1,128,189,233,0,15,132,244,1,137,213,137, + 194,141,139,233,232,251,1,29,137,252,234,252,233,244,1,255,139,106,252,248, + 221,4,199,139,172,253,141,233,139,141,233,221,25,139,6,15,182,204,15,182, + 232,131,198,4,193,232,16,252,255,36,171,255,252,247,208,139,106,252,248,139, + 172,253,141,233,139,141,233,137,65,4,139,6,15,182,204,15,182,232,131,198, + 4,193,232,16,252,255,36,171,255,141,180,253,134,233,139,108,36,48,131,189, + 233,0,15,132,244,247,137,149,233,141,20,202,137,252,233,232,251,1,30,139, + 149,233,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36, + 171,255,252,247,208,139,74,252,248,139,4,135,139,108,36,48,137,76,36,8,137, + 68,36,4,137,44,36,137,149,233,137,116,36,24,232,251,1,31,139,149,233,15,182, + 78,252,253,137,4,202,199,68,202,4,237,139,6,15,182,204,15,182,232,131,198, + 4,193,232,16,252,255,36,171,255,139,108,36,48,137,149,233,139,139,233,59, + 139,233,137,116,36,24,15,131,244,251,248,1,137,193,37,252,255,7,0,0,193,252, + 233,11,137,76,36,8,61,252,255,7,0,0,15,132,244,249,248,2,137,44,36,137,68, + 36,4,232,251,1,32,139,149,233,15,182,78,252,253,137,4,202,199,68,202,4,237, + 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,184, + 1,8,0,0,252,233,244,2,248,5,137,252,233,232,251,1,33,15,183,70,252,254,252, + 233,244,1,255,252,247,208,139,108,36,48,139,139,233,137,116,36,24,59,139, + 233,137,149,233,15,131,244,249,248,2,139,20,135,137,252,233,232,251,1,34, + 139,149,233,15,182,78,252,253,137,4,202,199,68,202,4,237,139,6,15,182,204, + 15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,137,252,233,232,251, + 1,33,15,183,70,252,254,252,247,208,252,233,244,2,255,252,247,208,139,106, + 252,248,139,173,233,139,4,135,252,233,244,171,255,252,247,208,139,106,252, + 248,139,173,233,139,4,135,252,233,244,172,255,15,182,252,236,15,182,192,129, + 124,253,252,234,4,239,15,133,244,40,139,44,252,234,129,124,253,194,4,239, + 15,131,244,251,221,4,194,219,20,36,219,4,36,223,252,233,221,216,139,4,36, + 15,133,244,40,59,133,233,15,131,244,40,193,224,3,3,133,233,129,120,253,4, + 239,15,132,244,248,139,40,139,64,4,137,44,202,137,68,202,4,248,1,139,6,15, + 182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,2,131,189,233, + 0,15,132,244,249,255,139,141,233,252,246,129,233,235,15,132,244,40,15,182, + 78,252,253,248,3,199,68,202,4,237,252,233,244,1,248,5,129,124,253,194,4,239, + 15,133,244,40,139,4,194,252,233,244,171,255,15,182,252,236,15,182,192,252, + 247,208,139,4,135,129,124,253,252,234,4,239,15,133,244,38,139,44,252,234, + 248,171,139,141,233,35,136,233,105,201,239,3,141,233,248,1,129,185,233,239, + 15,133,244,250,57,129,233,15,133,244,250,129,121,253,4,239,15,132,244,251, + 15,182,70,252,253,139,41,139,73,4,137,44,194,137,76,194,4,248,2,255,139,6, + 15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,15,182,70, + 252,253,199,68,194,4,237,252,233,244,2,248,4,139,137,233,133,201,15,133,244, + 1,248,5,139,141,233,133,201,15,132,244,3,252,246,129,233,235,15,133,244,3, + 252,233,244,38,255,15,182,252,236,15,182,192,129,124,253,252,234,4,239,15, + 133,244,39,139,44,252,234,59,133,233,15,131,244,39,193,224,3,3,133,233,129, + 120,253,4,239,15,132,244,248,139,40,139,64,4,137,44,202,137,68,202,4,248, + 1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,2,131, + 189,233,0,15,132,244,249,139,141,233,252,246,129,233,235,15,132,244,39,255, + 15,182,78,252,253,248,3,199,68,202,4,237,252,233,244,1,255,15,182,252,236, + 15,182,192,129,124,253,252,234,4,239,15,133,244,43,139,44,252,234,129,124, + 253,194,4,239,15,131,244,251,221,4,194,219,20,36,219,4,36,223,252,233,221, + 216,139,4,36,15,133,244,43,59,133,233,15,131,244,43,193,224,3,3,133,233,129, + 120,253,4,239,15,132,244,249,248,1,252,246,133,233,235,15,133,244,253,248, + 2,255,139,108,202,4,139,12,202,137,104,4,137,8,139,6,15,182,204,15,182,232, + 131,198,4,193,232,16,252,255,36,171,248,3,131,189,233,0,15,132,244,1,139, + 141,233,252,246,129,233,235,15,132,244,43,15,182,78,252,253,252,233,244,1, + 248,5,129,124,253,194,4,239,15,133,244,43,139,4,194,252,233,244,172,248,7, + 128,165,233,235,255,139,139,233,137,171,233,137,141,233,15,182,78,252,253, + 252,233,244,2,255,15,182,252,236,15,182,192,252,247,208,139,4,135,129,124, + 253,252,234,4,239,15,133,244,41,139,44,252,234,248,172,139,141,233,35,136, + 233,105,201,239,198,133,233,0,3,141,233,248,1,129,185,233,239,15,133,244, + 251,57,129,233,15,133,244,251,129,121,253,4,239,15,132,244,250,248,2,255, + 252,246,133,233,235,15,133,244,253,248,3,15,182,70,252,253,139,108,194,4, + 139,4,194,137,105,4,137,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16, + 252,255,36,171,248,4,131,189,233,0,15,132,244,2,137,76,36,16,139,141,233, + 252,246,129,233,235,15,132,244,41,139,76,36,16,252,233,244,2,248,5,139,137, + 233,133,201,15,133,244,1,255,139,141,233,133,201,15,132,244,252,252,246,129, + 233,235,15,132,244,41,248,6,137,68,36,16,199,68,36,20,237,137,108,36,12,141, + 68,36,16,137,108,36,4,139,108,36,48,137,68,36,8,137,44,36,137,149,233,137, + 116,36,24,232,251,1,35,139,149,233,139,108,36,12,137,193,252,233,244,2,248, + 7,128,165,233,235,139,131,233,137,171,233,137,133,233,252,233,244,3,255,15, + 182,252,236,15,182,192,129,124,253,252,234,4,239,15,133,244,42,139,44,252, + 234,59,133,233,15,131,244,42,193,224,3,3,133,233,129,120,253,4,239,15,132, + 244,249,248,1,252,246,133,233,235,15,133,244,253,248,2,139,108,202,4,139, + 12,202,137,104,4,137,8,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252, + 255,36,171,248,3,131,189,233,0,15,132,244,1,255,139,141,233,252,246,129,233, + 235,15,132,244,42,15,182,78,252,253,252,233,244,1,248,7,128,165,233,235,139, + 139,233,137,171,233,137,141,233,15,182,78,252,253,252,233,244,2,255,137,124, + 36,16,139,60,199,248,1,141,12,202,139,105,252,248,252,246,133,233,235,15, + 133,244,253,248,2,139,68,36,20,131,232,1,15,132,244,250,1,252,248,59,133, + 233,15,135,244,251,41,252,248,193,231,3,3,189,233,248,3,139,41,137,47,139, + 105,4,131,193,8,137,111,4,131,199,8,131,232,1,15,133,244,3,248,4,139,124, + 36,16,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248, + 5,137,108,36,4,139,108,36,48,137,149,233,137,68,36,8,137,44,36,137,116,36, + 24,232,251,1,36,139,149,233,15,182,78,252,253,252,233,244,1,248,7,255,128, + 165,233,235,139,131,233,137,171,233,137,133,233,252,233,244,2,255,3,68,36, + 20,255,129,124,253,202,4,239,139,44,202,15,133,244,60,141,84,202,8,137,114, + 252,252,139,181,233,139,14,15,182,252,233,15,182,205,131,198,4,252,255,36, + 171,255,141,76,202,8,137,215,139,105,252,248,129,121,253,252,252,239,15,133, + 244,30,248,61,139,114,252,252,252,247,198,237,15,133,244,253,248,1,137,106, + 252,248,137,68,36,20,131,232,1,15,132,244,249,248,2,139,41,137,47,139,105, + 4,131,193,8,137,111,4,131,199,8,131,232,1,15,133,244,2,139,106,252,248,248, + 3,139,68,36,20,128,189,233,1,15,135,244,251,248,4,139,181,233,139,14,15,182, + 252,233,15,182,205,131,198,4,252,255,36,171,248,5,255,252,247,198,237,15, + 133,244,4,15,182,78,252,253,252,247,209,141,12,202,139,121,252,248,139,191, + 233,139,191,233,252,233,244,4,248,7,129,252,238,239,252,247,198,237,15,133, + 244,254,41,252,242,137,215,139,114,252,252,252,233,244,1,248,8,129,198,239, + 252,233,244,1,255,141,76,202,8,139,105,232,139,65,252,236,137,41,137,65,4, + 139,105,252,240,139,65,252,244,137,105,8,137,65,12,139,105,224,139,65,228, + 137,105,252,248,137,65,252,252,129,252,248,239,184,237,15,133,244,30,137, + 202,137,114,252,252,139,181,233,139,14,15,182,252,233,15,182,205,131,198, + 4,252,255,36,171,255,137,124,36,16,137,92,36,20,139,108,202,252,240,139,68, + 202,252,248,139,157,233,131,198,4,139,189,233,248,1,57,216,15,131,244,251, + 129,124,253,199,4,239,15,132,244,250,219,68,202,252,248,139,108,199,4,137, + 108,202,12,139,44,199,137,108,202,8,131,192,1,221,28,202,137,68,202,252,248, + 248,2,15,183,70,252,254,141,180,253,134,233,248,3,139,92,36,20,139,124,36, + 16,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,4, + 131,192,1,137,68,202,252,248,252,233,244,1,248,5,41,216,248,6,59,133,233, + 15,135,244,3,105,252,248,239,255,3,189,233,129,191,233,239,15,132,244,253, + 141,92,24,1,139,175,233,139,135,233,137,44,202,137,68,202,4,139,175,233,139, + 135,233,137,108,202,8,137,68,202,12,137,92,202,252,248,252,233,244,2,248, + 7,131,192,1,252,233,244,6,255,129,124,253,202,252,236,239,15,133,244,251, + 139,108,202,232,129,124,253,202,252,244,239,15,133,244,251,129,124,253,202, + 252,252,239,15,133,244,251,128,189,233,235,15,133,244,251,141,180,253,134, + 233,199,68,202,252,248,0,0,0,0,199,68,202,252,252,252,255,127,252,254,252, + 255,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171, + 248,5,198,70,252,252,235,141,180,253,134,233,198,6,235,252,233,244,1,255, + 15,182,252,236,15,182,192,137,124,36,16,141,188,253,194,233,141,12,202,43, + 122,252,252,133,252,237,15,132,244,251,141,108,252,233,252,248,57,215,15, + 131,244,248,248,1,139,71,252,248,137,1,139,71,252,252,131,199,8,137,65,4, + 131,193,8,57,252,233,15,131,244,249,57,215,15,130,244,1,248,2,199,65,4,237, + 131,193,8,57,252,233,15,130,244,2,248,3,139,124,36,16,139,6,15,182,204,15, + 182,232,131,198,4,193,232,16,252,255,36,171,248,5,199,68,36,20,1,0,0,0,137, + 208,41,252,248,15,134,244,3,137,197,193,252,237,3,131,197,1,137,108,36,20, + 139,108,36,48,1,200,59,133,233,15,135,244,253,248,6,255,139,71,252,248,137, + 1,139,71,252,252,131,199,8,137,65,4,131,193,8,57,215,15,130,244,6,252,233, + 244,3,248,7,137,149,233,137,141,233,137,116,36,24,41,215,139,84,36,20,131, + 252,234,1,137,252,233,232,251,1,0,139,149,233,139,141,233,1,215,252,233,244, + 6,255,193,225,3,255,248,1,139,114,252,252,137,68,36,20,252,247,198,237,15, + 133,244,253,255,248,14,137,215,131,232,1,15,132,244,249,248,2,139,44,15,137, + 111,252,248,139,108,15,4,137,111,252,252,131,199,8,131,232,1,15,133,244,2, + 248,3,139,68,36,20,15,182,110,252,255,248,5,57,197,15,135,244,252,255,139, + 108,10,4,137,106,252,252,139,44,10,137,106,252,248,255,248,5,56,70,252,255, + 15,135,244,252,255,15,182,78,252,253,252,247,209,141,20,202,139,122,252,248, + 139,191,233,139,191,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16, + 252,255,36,171,248,6,255,199,71,252,252,237,131,199,8,255,199,68,194,252, + 244,237,255,131,192,1,252,233,244,5,248,7,141,174,233,252,247,197,237,15, + 133,244,15,41,252,234,255,1,252,233,255,137,252,245,209,252,237,129,229,239, + 102,129,172,253,43,233,238,15,130,244,150,255,141,12,202,255,129,121,253, + 4,239,15,133,244,255,255,129,121,253,12,239,15,133,244,62,129,121,253,20, + 239,15,133,244,62,139,41,131,121,16,0,15,140,244,251,255,129,121,253,12,239, + 15,133,244,167,129,121,253,20,239,15,133,244,167,255,139,105,16,133,252,237, + 15,136,244,251,3,41,15,128,244,247,137,41,255,59,105,8,199,65,28,237,137, + 105,24,255,15,142,244,253,248,1,248,6,141,180,253,134,233,255,141,180,253, + 134,233,15,183,70,252,254,15,142,245,248,1,248,6,255,15,143,244,253,248,6, + 141,180,253,134,233,248,1,255,248,7,139,6,15,182,204,15,182,232,131,198,4, + 193,232,16,252,255,36,171,248,5,255,3,41,15,128,244,1,137,41,255,15,141,244, + 7,255,141,180,253,134,233,15,183,70,252,254,15,141,245,255,15,140,244,7,255, + 252,233,244,6,248,9,255,129,121,253,4,239,255,15,131,244,62,129,121,253,12, + 239,15,131,244,62,255,129,121,253,12,239,15,131,244,167,129,121,253,20,239, + 15,131,244,167,255,139,105,20,255,129,252,253,239,15,131,244,62,255,221,65, + 8,221,1,255,220,65,16,221,17,221,81,24,133,252,237,15,136,244,247,255,221, + 81,24,15,140,244,247,255,217,201,248,1,223,252,233,221,216,255,15,131,244, + 248,141,180,253,134,233,255,141,180,253,134,233,15,183,70,252,254,15,131, + 245,255,15,130,244,248,141,180,253,134,233,255,141,12,202,139,105,4,129,252, + 253,239,15,132,244,247,255,137,105,252,252,139,41,137,105,252,248,252,233, + 245,255,141,180,253,134,233,139,1,137,105,252,252,137,65,252,248,255,139, + 139,233,139,4,129,139,128,233,139,108,36,48,137,147,233,137,171,233,252,255, + 224,255,141,180,253,134,233,139,6,15,182,204,15,182,232,131,198,4,193,232, + 16,252,255,36,171,255,137,252,245,209,252,237,129,229,239,102,129,172,253, + 43,233,238,15,130,244,152,255,139,190,233,139,108,36,48,141,12,202,59,141, + 233,15,135,244,25,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70, + 252,254,252,233,245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15, + 134,244,3,252,233,244,2,255,141,44,197,237,141,4,194,139,122,252,248,137, + 104,252,252,137,120,252,248,139,108,36,48,141,12,200,59,141,233,15,135,244, + 24,137,209,137,194,15,182,174,233,133,252,237,15,132,244,248,248,1,131,193, + 8,57,209,15,131,244,249,139,121,252,248,137,56,139,121,252,252,137,120,4, + 131,192,8,199,65,252,252,237,131,252,237,1,15,133,244,1,248,2,255,139,190, + 233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,248, + 3,199,64,4,237,131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139, + 106,252,248,139,189,233,139,108,36,48,141,68,194,252,248,137,149,233,141, + 136,233,59,141,233,137,133,233,255,137,44,36,255,137,124,36,4,137,44,36,255, + 15,135,244,23,199,131,233,237,255,252,255,215,255,252,255,147,233,255,199, + 131,233,237,139,149,233,141,12,194,252,247,217,3,141,233,139,114,252,252, + 252,233,244,12,255,254,0 +}; + +enum { + GLOB_vm_returnp, + GLOB_cont_dispatch, + GLOB_vm_returnc, + GLOB_vm_unwind_yield, + GLOB_BC_RET_Z, + GLOB_vm_return, + GLOB_vm_leave_cp, + GLOB_vm_leave_unw, + GLOB_vm_unwind_c_eh, + GLOB_vm_unwind_c, + GLOB_vm_unwind_rethrow, + GLOB_vm_unwind_ff, + GLOB_vm_unwind_ff_eh, + GLOB_vm_growstack_c, + GLOB_vm_growstack_v, + GLOB_vm_growstack_f, + GLOB_vm_resume, + GLOB_vm_pcall, + GLOB_vm_call, + GLOB_vm_call_dispatch, + GLOB_vmeta_call, + GLOB_vm_call_dispatch_f, + GLOB_vm_cpcall, + GLOB_cont_ffi_callback, + GLOB_vm_call_tail, + GLOB_cont_cat, + GLOB_cont_ra, + GLOB_BC_CAT_Z, + GLOB_vmeta_tgets, + GLOB_vmeta_tgetb, + GLOB_vmeta_tgetv, + GLOB_vmeta_tsets, + GLOB_vmeta_tsetb, + GLOB_vmeta_tsetv, + GLOB_cont_nop, + GLOB_vmeta_comp, + GLOB_vmeta_binop, + GLOB_cont_condt, + GLOB_cont_condf, + GLOB_vmeta_equal, + GLOB_vmeta_equal_cd, + GLOB_vmeta_arith_vno, + GLOB_vmeta_arith_vn, + GLOB_vmeta_arith_nvo, + GLOB_vmeta_arith_nv, + GLOB_vmeta_unm, + GLOB_vmeta_arith_vvo, + GLOB_vmeta_arith_vv, + GLOB_vmeta_len, + GLOB_BC_LEN_Z, + GLOB_vmeta_call_ra, + GLOB_BC_CALLT_Z, + GLOB_vmeta_for, + GLOB_ff_assert, + GLOB_fff_fallback, + GLOB_fff_res_, + GLOB_ff_type, + GLOB_fff_res1, + GLOB_ff_getmetatable, + GLOB_ff_setmetatable, + GLOB_ff_rawget, + GLOB_ff_tonumber, + GLOB_fff_resn, + GLOB_ff_tostring, + GLOB_fff_gcstep, + GLOB_ff_next, + GLOB_fff_res2, + GLOB_fff_res, + GLOB_ff_pairs, + GLOB_ff_ipairs_aux, + GLOB_fff_res0, + GLOB_ff_ipairs, + GLOB_ff_pcall, + GLOB_ff_xpcall, + GLOB_ff_coroutine_resume, + GLOB_ff_coroutine_wrap_aux, + GLOB_ff_coroutine_yield, + GLOB_fff_resi, + GLOB_ff_math_abs, + GLOB_fff_resxmm0, + GLOB_ff_math_floor, + GLOB_vm_floor, + GLOB_ff_math_ceil, + GLOB_vm_ceil, + GLOB_ff_math_sqrt, + GLOB_ff_math_log, + GLOB_ff_math_log10, + GLOB_ff_math_exp, + GLOB_vm_exp_x87, + GLOB_ff_math_sin, + GLOB_ff_math_cos, + GLOB_ff_math_tan, + GLOB_ff_math_asin, + GLOB_ff_math_acos, + GLOB_ff_math_atan, + GLOB_ff_math_sinh, + GLOB_ff_math_cosh, + GLOB_ff_math_tanh, + GLOB_ff_math_deg, + GLOB_ff_math_rad, + GLOB_ff_math_atan2, + GLOB_ff_math_ldexp, + GLOB_ff_math_frexp, + GLOB_ff_math_modf, + GLOB_vm_trunc, + GLOB_ff_math_fmod, + GLOB_ff_math_pow, + GLOB_vm_pow, + GLOB_ff_math_min, + GLOB_ff_math_max, + GLOB_ff_string_len, + GLOB_ff_string_byte, + GLOB_ff_string_char, + GLOB_fff_newstr, + GLOB_ff_string_sub, + GLOB_fff_emptystr, + GLOB_ff_string_rep, + GLOB_fff_fallback_2, + GLOB_ff_string_reverse, + GLOB_fff_fallback_1, + GLOB_ff_string_lower, + GLOB_ff_string_upper, + GLOB_ff_table_getn, + GLOB_ff_bit_tobit, + GLOB_ff_bit_band, + GLOB_fff_resbit, + GLOB_fff_fallback_bit_op, + GLOB_ff_bit_bor, + GLOB_ff_bit_bxor, + GLOB_ff_bit_bswap, + GLOB_ff_bit_bnot, + GLOB_ff_bit_lshift, + GLOB_ff_bit_rshift, + GLOB_ff_bit_arshift, + GLOB_ff_bit_rol, + GLOB_ff_bit_ror, + GLOB_vm_record, + GLOB_vm_rethook, + GLOB_vm_inshook, + GLOB_cont_hook, + GLOB_vm_hotloop, + GLOB_vm_callhook, + GLOB_vm_hotcall, + GLOB_vm_exit_handler, + GLOB_vm_exit_interp, + GLOB_vm_floor_sse, + GLOB_vm_ceil_sse, + GLOB_vm_trunc_sse, + GLOB_vm_mod, + GLOB_vm_log2, + GLOB_vm_exp2_x87, + GLOB_vm_exp2raw, + GLOB_vm_pow_sse, + GLOB_vm_powi_sse, + GLOB_vm_foldfpm, + GLOB_vm_foldarith, + GLOB_vm_cpuid, + GLOB_assert_bad_for_arg_type, + GLOB_vm_ffi_callback, + GLOB_vm_ffi_call, + GLOB_BC_MODVN_Z, + GLOB_BC_TGETS_Z, + GLOB_BC_TSETS_Z, + GLOB__MAX +}; +static const char *const globnames[] = { + "vm_returnp", + "cont_dispatch", + "vm_returnc", + "vm_unwind_yield", + "BC_RET_Z", + "vm_return", + "vm_leave_cp", + "vm_leave_unw", + "vm_unwind_c_eh", + "vm_unwind_c@8", + "vm_unwind_rethrow", + "vm_unwind_ff@4", + "vm_unwind_ff_eh", + "vm_growstack_c", + "vm_growstack_v", + "vm_growstack_f", + "vm_resume", + "vm_pcall", + "vm_call", + "vm_call_dispatch", + "vmeta_call", + "vm_call_dispatch_f", + "vm_cpcall", + "cont_ffi_callback", + "vm_call_tail", + "cont_cat", + "cont_ra", + "BC_CAT_Z", + "vmeta_tgets", + "vmeta_tgetb", + "vmeta_tgetv", + "vmeta_tsets", + "vmeta_tsetb", + "vmeta_tsetv", + "cont_nop", + "vmeta_comp", + "vmeta_binop", + "cont_condt", + "cont_condf", + "vmeta_equal", + "vmeta_equal_cd", + "vmeta_arith_vno", + "vmeta_arith_vn", + "vmeta_arith_nvo", + "vmeta_arith_nv", + "vmeta_unm", + "vmeta_arith_vvo", + "vmeta_arith_vv", + "vmeta_len", + "BC_LEN_Z", + "vmeta_call_ra", + "BC_CALLT_Z", + "vmeta_for", + "ff_assert", + "fff_fallback", + "fff_res_", + "ff_type", + "fff_res1", + "ff_getmetatable", + "ff_setmetatable", + "ff_rawget", + "ff_tonumber", + "fff_resn", + "ff_tostring", + "fff_gcstep", + "ff_next", + "fff_res2", + "fff_res", + "ff_pairs", + "ff_ipairs_aux", + "fff_res0", + "ff_ipairs", + "ff_pcall", + "ff_xpcall", + "ff_coroutine_resume", + "ff_coroutine_wrap_aux", + "ff_coroutine_yield", + "fff_resi", + "ff_math_abs", + "fff_resxmm0", + "ff_math_floor", + "vm_floor", + "ff_math_ceil", + "vm_ceil", + "ff_math_sqrt", + "ff_math_log", + "ff_math_log10", + "ff_math_exp", + "vm_exp_x87", + "ff_math_sin", + "ff_math_cos", + "ff_math_tan", + "ff_math_asin", + "ff_math_acos", + "ff_math_atan", + "ff_math_sinh", + "ff_math_cosh", + "ff_math_tanh", + "ff_math_deg", + "ff_math_rad", + "ff_math_atan2", + "ff_math_ldexp", + "ff_math_frexp", + "ff_math_modf", + "vm_trunc", + "ff_math_fmod", + "ff_math_pow", + "vm_pow", + "ff_math_min", + "ff_math_max", + "ff_string_len", + "ff_string_byte", + "ff_string_char", + "fff_newstr", + "ff_string_sub", + "fff_emptystr", + "ff_string_rep", + "fff_fallback_2", + "ff_string_reverse", + "fff_fallback_1", + "ff_string_lower", + "ff_string_upper", + "ff_table_getn", + "ff_bit_tobit", + "ff_bit_band", + "fff_resbit", + "fff_fallback_bit_op", + "ff_bit_bor", + "ff_bit_bxor", + "ff_bit_bswap", + "ff_bit_bnot", + "ff_bit_lshift", + "ff_bit_rshift", + "ff_bit_arshift", + "ff_bit_rol", + "ff_bit_ror", + "vm_record", + "vm_rethook", + "vm_inshook", + "cont_hook", + "vm_hotloop", + "vm_callhook", + "vm_hotcall", + "vm_exit_handler", + "vm_exit_interp", + "vm_floor_sse", + "vm_ceil_sse", + "vm_trunc_sse", + "vm_mod", + "vm_log2", + "vm_exp2_x87", + "vm_exp2raw", + "vm_pow_sse", + "vm_powi_sse", + "vm_foldfpm", + "vm_foldarith", + "vm_cpuid", + "assert_bad_for_arg_type", + "vm_ffi_callback", + "vm_ffi_call@4", + "BC_MODVN_Z", + "BC_TGETS_Z", + "BC_TSETS_Z", + (const char *)0 +}; +static const char *const extnames[] = { + "lj_state_growstack@8", + "lj_meta_tget", + "lj_meta_tset", + "lj_meta_comp", + "lj_meta_equal", + "lj_meta_equal_cd@8", + "lj_meta_arith", + "lj_meta_len@8", + "lj_meta_call", + "lj_meta_for@8", + "lj_tab_get", + "lj_str_fromnum@8", + "lj_tab_next", + "lj_tab_getinth@8", + "lj_ffh_coroutine_wrap_err@8", + "lj_vm_sinh", + "lj_vm_cosh", + "lj_vm_tanh", + "lj_str_new", + "lj_tab_len@4", + "lj_gc_step@4", + "lj_dispatch_ins@8", + "lj_trace_hot@8", + "lj_dispatch_call@8", + "lj_trace_exit@8", + "lj_err_throw@8", + "lj_ccallback_enter@8", + "lj_ccallback_leave@8", + "lj_meta_cat", + "lj_gc_barrieruv@8", + "lj_func_closeuv@8", + "lj_func_newL_gc", + "lj_tab_new", + "lj_gc_step_fixtop@4", + "lj_tab_dup@8", + "lj_tab_newkey", + "lj_tab_reasize", + (const char *)0 +}; +#define Dt1(_V) (int)(ptrdiff_t)&(((lua_State *)0)_V) +#define Dt2(_V) (int)(ptrdiff_t)&(((global_State *)0)_V) +#define Dt3(_V) (int)(ptrdiff_t)&(((TValue *)0)_V) +#define Dt4(_V) (int)(ptrdiff_t)&(((GCobj *)0)_V) +#define Dt5(_V) (int)(ptrdiff_t)&(((GCstr *)0)_V) +#define Dt6(_V) (int)(ptrdiff_t)&(((GCtab *)0)_V) +#define Dt7(_V) (int)(ptrdiff_t)&(((GCfuncL *)0)_V) +#define Dt8(_V) (int)(ptrdiff_t)&(((GCfuncC *)0)_V) +#define Dt9(_V) (int)(ptrdiff_t)&(((GCproto *)0)_V) +#define DtA(_V) (int)(ptrdiff_t)&(((GCupval *)0)_V) +#define DtB(_V) (int)(ptrdiff_t)&(((Node *)0)_V) +#define DtC(_V) (int)(ptrdiff_t)&(((int *)0)_V) +#define DtD(_V) (int)(ptrdiff_t)&(((GCtrace *)0)_V) +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + dasm_put(Dst, 0); + dasm_put(Dst, 2, FRAME_P, LJ_TTRUE, FRAME_TYPE, FRAME_C, FRAME_TYPE, DISPATCH_GL(vmstate), ~LJ_VMST_C); + dasm_put(Dst, 91, Dt1(->base), Dt1(->top), Dt1(->cframe), Dt1(->maxstack), LJ_TNIL); + dasm_put(Dst, 192, Dt1(->top), Dt1(->top), LUA_YIELD, Dt1(->glref), Dt2(->vmstate), ~LJ_VMST_C); + dasm_put(Dst, 272, CFRAME_RAWMASK, 1+1, Dt1(->base), Dt1(->glref), GG_G2DISP, LJ_TFALSE, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, LUA_MINSTACK); + dasm_put(Dst, 339, -4+PC2PROTO(framesize), Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), Dt7(->pc), FRAME_CP, CFRAME_RESUME, Dt1(->glref), GG_G2DISP, Dt1(->cframe), Dt1(->status)); + dasm_put(Dst, 472, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->status), Dt1(->base), Dt1(->top), FRAME_TYPE, FRAME_CP, FRAME_C, Dt1(->cframe), Dt1(->cframe)); + dasm_put(Dst, 570, Dt1(->glref), GG_G2DISP, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top), LJ_TFUNC, Dt7(->pc), Dt1(->stack), Dt1(->top), Dt1(->cframe), Dt1(->cframe)); + dasm_put(Dst, 722, FRAME_CP, LJ_TNIL, Dt7(->pc), PC2PROTO(k)); + dasm_put(Dst, 854, LJ_TSTR, BC_GGET, DISPATCH_GL(tmptv), LJ_TTAB, Dt1(->base), Dt1(->base)); + dasm_put(Dst, 1016, Dt1(->top), FRAME_CONT, 2+1, LJ_TSTR, BC_GSET, DISPATCH_GL(tmptv), LJ_TTAB); + dasm_put(Dst, 1128, Dt1(->base), Dt1(->base), Dt1(->top), FRAME_CONT, 3+1, Dt1(->base), Dt1(->base)); + dasm_put(Dst, 1310, -BCBIAS_J*4, LJ_TISTRUECOND, LJ_TISTRUECOND, Dt1(->base), Dt1(->base)); + dasm_put(Dst, 1446, Dt1(->base), Dt1(->base), FRAME_CONT, 2+1); + dasm_put(Dst, 1562, Dt1(->base), Dt1(->base)); +#if LJ_52 + dasm_put(Dst, 1593); +#else + dasm_put(Dst, 1612); +#endif + dasm_put(Dst, 1617, Dt1(->base), Dt1(->base), Dt7(->pc), Dt1(->base), Dt1(->base), GG_DISP2STATIC, 1+1, LJ_TISTRUECOND); + dasm_put(Dst, 1806, 1+1, ~LJ_TNUMX, ((char *)(&((GCfuncC *)0)->upvalue)), LJ_TSTR, 1+1); + dasm_put(Dst, 1905, LJ_TTAB, Dt6(->metatable), LJ_TNIL, DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable), LJ_TTAB, Dt6(->hmask), Dt5(->hash), sizeof(Node), Dt6(->node), DtB(->key.it), LJ_TSTR); + dasm_put(Dst, 1976, DtB(->key.gcr), DtB(->next), LJ_TNIL, LJ_TUDATA, LJ_TISNUM); + dasm_put(Dst, 2040, LJ_TNUMX, DISPATCH_GL(gcroot[GCROOT_BASEMT]), 2+1, LJ_TTAB, Dt6(->metatable), LJ_TTAB); + dasm_put(Dst, 2099, Dt6(->metatable), LJ_TTAB, Dt6(->marked), LJ_GC_BLACK, Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist), 2+1, LJ_TTAB); + dasm_put(Dst, 2166, 1+1, LJ_TISNUM, 1+1, LJ_TSTR, LJ_TSTR); + dasm_put(Dst, 2274, LJ_TISNUM, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM]), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), Dt1(->base)); + dasm_put(Dst, 2344, 1+1, LJ_TTAB, Dt1(->base), Dt1(->top), Dt1(->base), 1+2, LJ_TNIL); + dasm_put(Dst, 2454, LJ_TNIL, 1+1, LJ_TTAB); +#if LJ_52 + dasm_put(Dst, 2491, Dt6(->metatable)); +#endif + dasm_put(Dst, 2500, Dt8(->upvalue[0]), LJ_TFUNC, LJ_TNIL, 1+3, 1+1, LJ_TTAB, LJ_TISNUM, Dt6(->asize), Dt6(->array)); + dasm_put(Dst, 2597, LJ_TNIL, Dt6(->hmask), 1+0, 1+1, LJ_TTAB); + dasm_put(Dst, 2094); +#if LJ_52 + dasm_put(Dst, 2491, Dt6(->metatable)); +#endif + dasm_put(Dst, 2676, Dt8(->upvalue[0]), LJ_TFUNC, 1+3, 1+1, 8+FRAME_PCALL, DISPATCH_GL(hookmask), HOOK_ACTIVE_SHIFT, 2+1, LJ_TFUNC); + dasm_put(Dst, 2762, LJ_TFUNC, 16+FRAME_PCALL, 1+1, LJ_TTHREAD, Dt1(->cframe), Dt1(->status), LUA_YIELD); + dasm_put(Dst, 2847, Dt1(->top), Dt1(->base), Dt1(->maxstack), Dt1(->top), Dt1(->base), Dt1(->top)); + dasm_put(Dst, 2951, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), LUA_YIELD, Dt1(->base), Dt1(->top), Dt1(->top), Dt1(->maxstack), LJ_TTRUE); + dasm_put(Dst, 3048, FRAME_TYPE, LJ_TFALSE, Dt1(->top), Dt1(->top), 1+2, Dt1(->top), Dt1(->base), Dt8(->upvalue[0].gcr), Dt1(->cframe)); + dasm_put(Dst, 3163, Dt1(->status), LUA_YIELD, Dt1(->top), Dt1(->base), Dt1(->maxstack), Dt1(->top), Dt1(->base), Dt1(->top)); + dasm_put(Dst, 3233, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), LUA_YIELD, Dt1(->base), Dt1(->top), Dt1(->top), Dt1(->maxstack)); + dasm_put(Dst, 3334, FRAME_TYPE, Dt1(->top), Dt1(->base), Dt1(->cframe), CFRAME_RESUME); + dasm_put(Dst, 3447, Dt1(->base), Dt1(->top), Dt1(->cframe), LUA_YIELD, Dt1(->status), 1+1, LJ_TISNUM, 1+1); + dasm_put(Dst, 3516, FRAME_TYPE, LJ_TNIL, LJ_TISNUM); + dasm_put(Dst, 3616, LJ_TISNUM, 1+1, LJ_TISNUM); + dasm_put(Dst, 3671, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1); + dasm_put(Dst, 3742, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1); + dasm_put(Dst, 3799, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM); + dasm_put(Dst, 3867, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM); + dasm_put(Dst, 3961, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1); + dasm_put(Dst, 4044, LJ_TISNUM, 1+1, LJ_TISNUM, Dt8(->upvalue[0]), 2+1); + dasm_put(Dst, 4116, LJ_TISNUM, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM); + dasm_put(Dst, 4191, 1+1, LJ_TISNUM, 1+2); + dasm_put(Dst, 4321, 1+1, LJ_TISNUM, 1+2); + dasm_put(Dst, 4436, 2+1, LJ_TISNUM, LJ_TISNUM); + dasm_put(Dst, 4515, 2+1, LJ_TISNUM, LJ_TISNUM, LJ_TISNUM); + dasm_put(Dst, 4580, LJ_TISNUM, LJ_TISNUM, LJ_TISNUM); + dasm_put(Dst, 4677, 1+1, LJ_TSTR, Dt5(->len), 1+1, LJ_TSTR, Dt5(->len)); + dasm_put(Dst, 4741, Dt5([1]), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 1+1, LJ_TISNUM); + dasm_put(Dst, 4815, Dt1(->base), Dt1(->base), LJ_TSTR, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 1+2, LJ_TISNUM); + dasm_put(Dst, 4918, LJ_TSTR, LJ_TISNUM, Dt5(->len), sizeof(GCstr)-1); + dasm_put(Dst, 5010); + dasm_put(Dst, 5080, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 2+1, LJ_TSTR, LJ_TISNUM, Dt5(->len)); + dasm_put(Dst, 5149, DISPATCH_GL(tmpbuf.sz), Dt5([1]), DISPATCH_GL(tmpbuf.buf), DISPATCH_GL(tmpbuf.buf), 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold)); + dasm_put(Dst, 5214, LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf)); + dasm_put(Dst, 5293, 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf)); + dasm_put(Dst, 5358, 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold)); + dasm_put(Dst, 5434, LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf)); + dasm_put(Dst, 5515, 1+1, LJ_TTAB, 1+1, LJ_TISNUM); + dasm_put(Dst, 5614, 1+1, LJ_TISNUM, LJ_TISNUM, 1+1, LJ_TISNUM); + dasm_put(Dst, 5722, LJ_TISNUM, 1+1, LJ_TISNUM); + dasm_put(Dst, 5838, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1); + dasm_put(Dst, 5930, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM); + dasm_put(Dst, 6015, 2+1, LJ_TISNUM, LJ_TISNUM, 2+1, LJ_TISNUM); + dasm_put(Dst, 6146, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM, 2+1); + dasm_put(Dst, 6277, LJ_TISNUM, LJ_TISNUM, 1+2, 1+1, Dt1(->base), 8*LUA_MINSTACK, Dt1(->top), Dt1(->maxstack)); + dasm_put(Dst, 6388, Dt8(->f), Dt1(->base), Dt1(->top), Dt7(->pc), FRAME_TYPE, LUA_MINSTACK); + dasm_put(Dst, 6496, Dt1(->base), Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), DISPATCH_GL(hookmask), HOOK_VMEVENT, HOOK_ACTIVE, LUA_MASKLINE|LUA_MASKCOUNT, DISPATCH_GL(hookcount)); + dasm_put(Dst, 6594, DISPATCH_GL(hookmask), HOOK_ACTIVE, DISPATCH_GL(hookmask), HOOK_ACTIVE, LUA_MASKLINE|LUA_MASKCOUNT, DISPATCH_GL(hookcount)); + dasm_put(Dst, 6641, LUA_MASKLINE, Dt1(->base), Dt1(->base), GG_DISP2STATIC, Dt7(->pc), PC2PROTO(framesize), Dt1(->base), Dt1(->top), GG_DISP2J, DISPATCH_J(L)); + dasm_put(Dst, 6748, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), DISPATCH_GL(vmstate), DISPATCH_GL(vmstate), ~LJ_VMST_EXIT, DISPATCH_J(exitno), DISPATCH_J(parent), 8*8+16, DISPATCH_GL(jit_L), DISPATCH_GL(jit_base)); + dasm_put(Dst, 6948, DISPATCH_J(L), DISPATCH_GL(jit_L), Dt1(->base), GG_DISP2J, Dt1(->cframe), CFRAME_RAWMASK, CFRAME_OFS_L, Dt1(->base), CFRAME_OFS_PC, Dt7(->pc), PC2PROTO(k), DISPATCH_GL(jit_L), DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, BC_FUNCF); + dasm_put(Dst, 7045); + dasm_put(Dst, 7564); + dasm_put(Dst, 7692); + dasm_put(Dst, 7760); + dasm_put(Dst, 7888); + dasm_put(Dst, 7991); + dasm_put(Dst, 8114); + dasm_put(Dst, 8303); + dasm_put(Dst, 8404); + dasm_put(Dst, 8516); + dasm_put(Dst, 8593); +#ifdef LUA_USE_ASSERT + dasm_put(Dst, 8710); +#endif +#define DtE(_V) (int)(ptrdiff_t)&(((CTState *)0)_V) + dasm_put(Dst, 8712, GG_G2DISP, Dt2(->ctype_state), DtE(->cb.slot), CFRAME_SIZE+16, DtE(->cb.gpr[0]), DtE(->cb.gpr[1]), DtE(->cb.stack), CFRAME_SIZE+12, CFRAME_SIZE+8, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top), Dt7(->pc), DISPATCH_GL(ctype_state), DtE(->L), Dt1(->base), Dt1(->top)); +#define DtF(_V) (int)(ptrdiff_t)&(((CCallState *)0)_V) + dasm_put(Dst, 8843, DtE(->cb.gpr[0]), DtE(->cb.gpr[1]), DtE(->cb.gpr[2]), DtE(->cb.fpr[0].d), DtE(->cb.fpr[0].f), Dt1(->top), DtF(->spadj), DtF(->spadj), DtF(->nsp)); + dasm_put(Dst, 8944, offsetof(CCallState, stack), DtF(->gpr[0]), DtF(->gpr[1]), DtF(->func), DtF(->gpr[0]), DtF(->gpr[1]), DtF(->resx87), DtF(->fpr[0].d[0]), DtF(->fpr[0].f[0])); + dasm_put(Dst, 9005, DtF(->spadj)); +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + dasm_put(Dst, 470, defop); + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + dasm_put(Dst, 9015, LJ_TISNUM, LJ_TISNUM); + switch (op) { + case BC_ISLT: + dasm_put(Dst, 9056); + break; + case BC_ISGE: + dasm_put(Dst, 9061); + break; + case BC_ISLE: + dasm_put(Dst, 5209); + break; + case BC_ISGT: + dasm_put(Dst, 9066); + break; + default: break; /* Shut up GCC. */ + } + dasm_put(Dst, 9071, -BCBIAS_J*4); + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + dasm_put(Dst, 9102); + if (vk) { + } else { + } + dasm_put(Dst, 9110, LJ_TISNUM, LJ_TISNUM); + iseqne_fp: + if (vk) { + dasm_put(Dst, 9146); + } else { + dasm_put(Dst, 9155); + } + iseqne_end: + if (vk) { + dasm_put(Dst, 9164, -BCBIAS_J*4); + } else { + dasm_put(Dst, 9179, -BCBIAS_J*4); + } + if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV || + op == BC_ISEQN || op == BC_ISNEN)) { + dasm_put(Dst, 9194); + } else { + dasm_put(Dst, 9083); + } + if (op == BC_ISEQV || op == BC_ISNEV) { + dasm_put(Dst, 9199, LJ_TCDATA, LJ_TCDATA, LJ_TISPRI, LJ_TISTABUD, Dt6(->metatable)); + dasm_put(Dst, 9266, Dt6(->nomm), 1<len), LJ_TTAB); +#if LJ_52 + dasm_put(Dst, 9655, Dt6(->metatable)); +#endif + dasm_put(Dst, 9669); +#if LJ_52 + dasm_put(Dst, 9696, Dt6(->nomm), 1<base), Dt1(->base)); + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + dasm_put(Dst, 10206, LJ_TSTR); + break; + case BC_KCDATA: + dasm_put(Dst, 10206, LJ_TCDATA); + break; + case BC_KSHORT: + dasm_put(Dst, 10239); + break; + case BC_KNUM: + dasm_put(Dst, 10265); + break; + case BC_KPRI: + dasm_put(Dst, 10290); + break; + case BC_KNIL: + dasm_put(Dst, 10316, LJ_TNIL); + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + dasm_put(Dst, 10362, offsetof(GCfuncL, uvptr), DtA(->v)); + break; + case BC_USETV: +#define TV2MARKOFS \ + ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)) + dasm_put(Dst, 10406, offsetof(GCfuncL, uvptr), DtA(->closed), DtA(->v), TV2MARKOFS, LJ_GC_BLACK, LJ_TISGCV, LJ_TNUMX - LJ_TISGCV, Dt4(->gch.marked), LJ_GC_WHITES, GG_DISP2G); + dasm_put(Dst, 10496); + break; +#undef TV2MARKOFS + case BC_USETS: + dasm_put(Dst, 10508, offsetof(GCfuncL, uvptr), DtA(->v), LJ_TSTR, DtA(->marked), LJ_GC_BLACK, Dt4(->gch.marked), LJ_GC_WHITES, DtA(->closed), GG_DISP2G); + break; + case BC_USETN: + dasm_put(Dst, 10599, offsetof(GCfuncL, uvptr), DtA(->v)); + break; + case BC_USETP: + dasm_put(Dst, 10635, offsetof(GCfuncL, uvptr), DtA(->v)); + break; + case BC_UCLO: + dasm_put(Dst, 10672, -BCBIAS_J*4, Dt1(->openupval), Dt1(->base), Dt1(->base)); + break; + + case BC_FNEW: + dasm_put(Dst, 10726, Dt1(->base), Dt1(->base), LJ_TFUNC); + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + dasm_put(Dst, 10797, Dt1(->base), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), LJ_TTAB); + break; + case BC_TDUP: + dasm_put(Dst, 10923, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), Dt1(->base), LJ_TTAB); + break; + + case BC_GGET: + dasm_put(Dst, 11015, Dt7(->env)); + break; + case BC_GSET: + dasm_put(Dst, 11033, Dt7(->env)); + break; + + case BC_TGETV: + dasm_put(Dst, 11051, LJ_TTAB, LJ_TISNUM, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->metatable)); + dasm_put(Dst, 11169, Dt6(->metatable), Dt6(->nomm), 1<hmask), Dt5(->hash), sizeof(Node), Dt6(->node), DtB(->key.it), LJ_TSTR, DtB(->key.gcr), LJ_TNIL); + dasm_put(Dst, 11305, LJ_TNIL, DtB(->next), Dt6(->metatable), Dt6(->nomm), 1<asize), Dt6(->array), LJ_TNIL, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<asize), Dt6(->array), LJ_TNIL, Dt6(->marked), LJ_GC_BLACK); + dasm_put(Dst, 11580, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<marked), (uint8_t)~LJ_GC_BLACK); + dasm_put(Dst, 11667, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist)); + break; + case BC_TSETS: + dasm_put(Dst, 11686, LJ_TTAB, Dt6(->hmask), Dt5(->hash), sizeof(Node), Dt6(->nomm), Dt6(->node), DtB(->key.it), LJ_TSTR, DtB(->key.gcr), LJ_TNIL); + dasm_put(Dst, 11761, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<next)); + dasm_put(Dst, 11853, Dt6(->metatable), Dt6(->nomm), 1<base), Dt1(->base), Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist)); + break; + case BC_TSETB: + dasm_put(Dst, 11949, LJ_TTAB, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable)); + dasm_put(Dst, 12047, Dt6(->metatable), Dt6(->nomm), 1<marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist)); + break; + + case BC_TSETM: + dasm_put(Dst, 12093, Dt6(->marked), LJ_GC_BLACK, Dt6(->asize), Dt6(->array), Dt1(->base), Dt1(->base)); + dasm_put(Dst, 12242, Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist)); + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALL: case BC_CALLM: + dasm_put(Dst, 9716); + if (op == BC_CALLM) { + dasm_put(Dst, 12260); + } + dasm_put(Dst, 12265, LJ_TFUNC, Dt7(->pc)); + break; + + case BC_CALLMT: + dasm_put(Dst, 12260); + break; + case BC_CALLT: + dasm_put(Dst, 12306, LJ_TFUNC, FRAME_TYPE, Dt7(->ffid), Dt7(->pc)); + dasm_put(Dst, 12424, FRAME_TYPE, Dt7(->pc), PC2PROTO(k), FRAME_VARG, FRAME_TYPEP, FRAME_VARG); + break; + + case BC_ITERC: + dasm_put(Dst, 12494, LJ_TFUNC, 2+1, Dt7(->pc)); + break; + + case BC_ITERN: + dasm_put(Dst, 12574, Dt6(->asize), Dt6(->array), LJ_TNIL, -BCBIAS_J*4, Dt6(->hmask), sizeof(Node)); + dasm_put(Dst, 12722, Dt6(->node), DtB(->val.it), LJ_TNIL, DtB(->key.gcr), DtB(->key.it), DtB(->val.gcr), DtB(->val.it)); + break; + + case BC_ISNEXT: + dasm_put(Dst, 12783, LJ_TFUNC, LJ_TTAB, LJ_TNIL, Dt8(->ffid), FF_next_N, -BCBIAS_J*4, BC_JMP, -BCBIAS_J*4, BC_ITERC); + break; + + case BC_VARG: + dasm_put(Dst, 12894, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack)); + dasm_put(Dst, 13058, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top)); + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + dasm_put(Dst, 12260); + break; + + case BC_RET: case BC_RET0: case BC_RET1: + if (op != BC_RET0) { + dasm_put(Dst, 13129); + } + dasm_put(Dst, 13133, FRAME_TYPE); + switch (op) { + case BC_RET: + dasm_put(Dst, 13152); + break; + case BC_RET1: + dasm_put(Dst, 13210); + /* fallthrough */ + case BC_RET0: + dasm_put(Dst, 13226); + default: + break; + } + dasm_put(Dst, 13237, Dt7(->pc), PC2PROTO(k)); + if (op == BC_RET) { + dasm_put(Dst, 13279, LJ_TNIL); + } else { + dasm_put(Dst, 13288, LJ_TNIL); + } + dasm_put(Dst, 13295, -FRAME_VARG, FRAME_TYPEP); + if (op != BC_RET0) { + dasm_put(Dst, 13319); + } + dasm_put(Dst, 9691); + break; + + /* -- Loops and branches ------------------------------------------------ */ + + + case BC_FORL: + dasm_put(Dst, 13323, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP); + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + vk = (op == BC_IFORL || op == BC_JFORL); + dasm_put(Dst, 13344); + if (LJ_DUALNUM) { + dasm_put(Dst, 13348, LJ_TISNUM); + if (!vk) { + dasm_put(Dst, 13358, LJ_TISNUM, LJ_TISNUM); + } else { +#ifdef LUA_USE_ASSERT + dasm_put(Dst, 13387, LJ_TISNUM, LJ_TISNUM); +#endif + dasm_put(Dst, 13406); + } + dasm_put(Dst, 13425, LJ_TISNUM); + if (op == BC_FORI) { + dasm_put(Dst, 13436, -BCBIAS_J*4); + } else if (op == BC_JFORI) { + dasm_put(Dst, 13450, -BCBIAS_J*4, BC_JLOOP); + } else if (op == BC_IFORL) { + dasm_put(Dst, 13468, -BCBIAS_J*4); + } else { + dasm_put(Dst, 13460, BC_JLOOP); + } + dasm_put(Dst, 13482); + if (vk) { + dasm_put(Dst, 13505); + } + dasm_put(Dst, 13425, LJ_TISNUM); + if (op == BC_FORI) { + dasm_put(Dst, 13514); + } else if (op == BC_JFORI) { + dasm_put(Dst, 13519, -BCBIAS_J*4, BC_JLOOP); + } else if (op == BC_IFORL) { + dasm_put(Dst, 13533); + } else { + dasm_put(Dst, 13529, BC_JLOOP); + } + dasm_put(Dst, 13538); + } else if (!vk) { + dasm_put(Dst, 13545, LJ_TISNUM); + } + if (!vk) { + dasm_put(Dst, 13551, LJ_TISNUM); + } else { +#ifdef LUA_USE_ASSERT + dasm_put(Dst, 13565, LJ_TISNUM, LJ_TISNUM); +#endif + } + dasm_put(Dst, 13584); + if (!vk) { + dasm_put(Dst, 13588, LJ_TISNUM); + } + if (vk) { + } else { + } + dasm_put(Dst, 13597); + if (vk) { + dasm_put(Dst, 13603); + } else { + dasm_put(Dst, 13619); + } + dasm_put(Dst, 13627); + if (op == BC_FORI) { + dasm_put(Dst, 13637, -BCBIAS_J*4); + } else if (op == BC_JFORI) { + dasm_put(Dst, 13647, -BCBIAS_J*4, BC_JLOOP); + } else if (op == BC_IFORL) { + dasm_put(Dst, 13661, -BCBIAS_J*4); + } else { + dasm_put(Dst, 13657, BC_JLOOP); + } + dasm_put(Dst, 9451); + break; + + case BC_ITERL: + dasm_put(Dst, 13323, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP); + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + dasm_put(Dst, 13671, LJ_TNIL); + if (op == BC_JITERL) { + dasm_put(Dst, 13686, BC_JLOOP); + } else { + dasm_put(Dst, 13700, -BCBIAS_J*4); + } + dasm_put(Dst, 9081); + break; + + case BC_LOOP: + dasm_put(Dst, 13323, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP); + break; + + case BC_ILOOP: + dasm_put(Dst, 9083); + break; + + case BC_JLOOP: + dasm_put(Dst, 13716, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L)); + break; + + case BC_JMP: + dasm_put(Dst, 13739, -BCBIAS_J*4); + break; + + /* -- Function headers -------------------------------------------------- */ + + /* + ** Reminder: A function may be called with func/args above L->maxstack, + ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot, + ** too. This means all FUNC* ops (including fast functions) must check + ** for stack overflow _before_ adding more slots! + */ + + case BC_FUNCF: + dasm_put(Dst, 13763, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_CALL); + case BC_FUNCV: /* NYI: compiled vararg functions. */ + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + dasm_put(Dst, 13784, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams)); + if (op == BC_JFUNCF) { + dasm_put(Dst, 13814, BC_JLOOP); + } else { + dasm_put(Dst, 9083); + } + dasm_put(Dst, 13823, LJ_TNIL); + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + dasm_put(Dst, 8710); + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + dasm_put(Dst, 13845, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL); + if (op == BC_JFUNCV) { + dasm_put(Dst, 13814, BC_JLOOP); + } else { + dasm_put(Dst, 13936, -4+PC2PROTO(k)); + } + dasm_put(Dst, 13958, LJ_TNIL); + break; + + case BC_FUNCC: + case BC_FUNCCW: + dasm_put(Dst, 13980, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top)); + if (op == BC_FUNCC) { + dasm_put(Dst, 14009); + } else { + dasm_put(Dst, 14013); + } + dasm_put(Dst, 14021, DISPATCH_GL(vmstate), ~LJ_VMST_C); + if (op == BC_FUNCC) { + dasm_put(Dst, 14030); + } else { + dasm_put(Dst, 14034, DISPATCH_GL(wrapf)); + } + dasm_put(Dst, 14039, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top)); + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + dasm_growpc(Dst, BC__MAX); + build_subroutines(ctx); + dasm_put(Dst, 14064); + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); +#if LJ_64 +#define SZPTR "8" +#define BSZPTR "3" +#define REG_SP "0x7" +#define REG_RA "0x10" +#else +#define SZPTR "4" +#define BSZPTR "2" +#define REG_SP "0x4" +#define REG_RA "0x8" +#endif + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad .Lbegin\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE0:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad lj_vm_ffi_call\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.long lj_vm_ffi_call\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif +#if (defined(__sun__) && defined(__svr4__)) +#if LJ_64 + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n"); +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); +#endif +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); +#endif + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.long .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.long .LASFDE2-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE2:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.long .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.long .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.long .LASFDE3-.Lframe2\n" + "\t.long lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + /* Mental note: never let Apple design an assembler. + ** Or a linker. Or a plastic case. But I digress. + */ + case BUILD_machasm: { +#if LJ_HASFFI + int fcsize = 0; +#endif + int i; + fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n"); + fprintf(ctx->fp, + "EH_frame1:\n" + "\t.set L$set$x,LECIEX-LSCIEX\n" + "\t.long L$set$x\n" + "LSCIEX:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zPR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 6\n" /* augmentation length */ + "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */ +#if LJ_64 + "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEX:\n\n"); + for (i = 0; i < ctx->nsym; i++) { + const char *name = ctx->sym[i].name; + int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; + if (size == 0) continue; +#if LJ_HASFFI + if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; } +#endif + fprintf(ctx->fp, + "%s.eh:\n" + "LSFDE%d:\n" + "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" + "\t.long L$set$%d\n" + "LASFDE%d:\n" + "\t.long LASFDE%d-EH_frame1\n" + "\t.long %s-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ +#else + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDE%d:\n\n", + name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); + } +#if LJ_HASFFI + if (fcsize) { + fprintf(ctx->fp, + "EH_frame2:\n" + "\t.set L$set$y,LECIEY-LSCIEY\n" + "\t.long L$set$y\n" + "LSCIEY:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 1\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEY:\n\n"); + fprintf(ctx->fp, + "_lj_vm_ffi_call.eh:\n" + "LSFDEY:\n" + "\t.set L$set$yy,LEFDEY-LASFDEY\n" + "\t.long L$set$yy\n" + "LASFDEY:\n" + "\t.long LASFDEY-EH_frame2\n" + "\t.long _lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */ + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDEY:\n\n", fcsize); + } +#endif +#if LJ_64 + fprintf(ctx->fp, "\t.subsections_via_symbols\n"); +#else + fprintf(ctx->fp, + "\t.non_lazy_symbol_pointer\n" + "L_lj_err_unwind_dwarf$non_lazy_ptr:\n" + ".indirect_symbol _lj_err_unwind_dwarf\n" + ".long 0\n"); +#endif + } + break; + default: /* Difficult for other modes. */ + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_asm.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_asm.c new file mode 100644 index 0000000..9b28b3b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_asm.c @@ -0,0 +1,313 @@ +/* +** LuaJIT VM builder: Assembler source code emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_bc.h" + +/* ------------------------------------------------------------------------ */ + +#if LJ_TARGET_X86ORX64 +/* Emit bytes piecewise as assembler text. */ +static void emit_asm_bytes(BuildCtx *ctx, uint8_t *p, int n) +{ + int i; + for (i = 0; i < n; i++) { + if ((i & 15) == 0) + fprintf(ctx->fp, "\t.byte %d", p[i]); + else + fprintf(ctx->fp, ",%d", p[i]); + if ((i & 15) == 15) putc('\n', ctx->fp); + } + if ((n & 15) != 0) putc('\n', ctx->fp); +} + +/* Emit relocation */ +static void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym) +{ + switch (ctx->mode) { + case BUILD_elfasm: + if (type) + fprintf(ctx->fp, "\t.long %s-.-4\n", sym); + else + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + case BUILD_coffasm: + fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", sym); + if (type) + fprintf(ctx->fp, "\t.long %s-.-4\n", sym); + else + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + default: /* BUILD_machasm for relative relocations handled below. */ + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + } +} + +static const char *const jccnames[] = { + "jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "ja", + "js", "jns", "jpe", "jpo", "jl", "jge", "jle", "jg" +}; + +/* Emit relocation for the incredibly stupid OSX assembler. */ +static void emit_asm_reloc_mach(BuildCtx *ctx, uint8_t *cp, int n, + const char *sym) +{ + const char *opname = NULL; + if (--n < 0) goto err; + if (cp[n] == 0xe8) { + opname = "call"; + } else if (cp[n] == 0xe9) { + opname = "jmp"; + } else if (cp[n] >= 0x80 && cp[n] <= 0x8f && n > 0 && cp[n-1] == 0x0f) { + opname = jccnames[cp[n]-0x80]; + n--; + } else { +err: + fprintf(stderr, "Error: unsupported opcode for %s symbol relocation.\n", + sym); + exit(1); + } + emit_asm_bytes(ctx, cp, n); + fprintf(ctx->fp, "\t%s %s\n", opname, sym); +} +#else +/* Emit words piecewise as assembler text. */ +static void emit_asm_words(BuildCtx *ctx, uint8_t *p, int n) +{ + int i; + for (i = 0; i < n; i += 4) { + if ((i & 15) == 0) + fprintf(ctx->fp, "\t.long 0x%08x", *(uint32_t *)(p+i)); + else + fprintf(ctx->fp, ",0x%08x", *(uint32_t *)(p+i)); + if ((i & 15) == 12) putc('\n', ctx->fp); + } + if ((n & 15) != 0) putc('\n', ctx->fp); +} + +/* Emit relocation as part of an instruction. */ +static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n, + const char *sym) +{ + uint32_t ins; + emit_asm_words(ctx, p, n-4); + ins = *(uint32_t *)(p+n-4); +#if LJ_TARGET_ARM + if ((ins & 0xff000000u) == 0xfa000000u) { + fprintf(ctx->fp, "\tblx %s\n", sym); + } else if ((ins & 0x0e000000u) == 0x0a000000u) { + fprintf(ctx->fp, "\t%s%.2s %s\n", (ins & 0x01000000u) ? "bl" : "b", + &"eqnecsccmiplvsvchilsgeltgtle"[2*(ins >> 28)], sym); + } else { + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); + } +#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE +#if LJ_TARGET_PS3 +#define TOCPREFIX "." +#else +#define TOCPREFIX "" +#endif + if ((ins >> 26) == 16) { + fprintf(ctx->fp, "\t%s %d, %d, " TOCPREFIX "%s\n", + (ins & 1) ? "bcl" : "bc", (ins >> 21) & 31, (ins >> 16) & 31, sym); + } else if ((ins >> 26) == 18) { + fprintf(ctx->fp, "\t%s " TOCPREFIX "%s\n", (ins & 1) ? "bl" : "b", sym); + } else { + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); + } +#elif LJ_TARGET_MIPS + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); +#else +#error "missing relocation support for this architecture" +#endif +} +#endif + +#if LJ_TARGET_ARM +#define ELFASM_PX "%%" +#else +#define ELFASM_PX "@" +#endif + +/* Emit an assembler label. */ +static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc) +{ + switch (ctx->mode) { + case BUILD_elfasm: +#if LJ_TARGET_PS3 + if (!strncmp(name, "lj_vm_", 6) && + strcmp(name, ctx->beginsym) && + !strstr(name, "hook")) { + fprintf(ctx->fp, + "\n\t.globl %s\n" + "\t.section \".opd\",\"aw\"\n" + "%s:\n" + "\t.long .%s,.TOC.@tocbase32\n" + "\t.size %s,8\n" + "\t.previous\n" + "\t.globl .%s\n" + "\t.hidden .%s\n" + "\t.type .%s, " ELFASM_PX "function\n" + "\t.size .%s, %d\n" + ".%s:\n", + name, name, name, name, name, name, name, name, size, name); + break; + } +#endif + fprintf(ctx->fp, + "\n\t.globl %s\n" + "\t.hidden %s\n" + "\t.type %s, " ELFASM_PX "%s\n" + "\t.size %s, %d\n" + "%s:\n", + name, name, name, isfunc ? "function" : "object", name, size, name); + break; + case BUILD_coffasm: + fprintf(ctx->fp, "\n\t.globl %s\n", name); + if (isfunc) + fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", name); + fprintf(ctx->fp, "%s:\n", name); + break; + case BUILD_machasm: + fprintf(ctx->fp, + "\n\t.private_extern %s\n" + "%s:\n", name, name); + break; + default: + break; + } +} + +/* Emit alignment. */ +static void emit_asm_align(BuildCtx *ctx, int bits) +{ + switch (ctx->mode) { + case BUILD_elfasm: + case BUILD_coffasm: + fprintf(ctx->fp, "\t.p2align %d\n", bits); + break; + case BUILD_machasm: + fprintf(ctx->fp, "\t.align %d\n", bits); + break; + default: + break; + } +} + +/* ------------------------------------------------------------------------ */ + +/* Emit assembler source code. */ +void emit_asm(BuildCtx *ctx) +{ + int i, rel; + + fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); + fprintf(ctx->fp, "\t.text\n"); + emit_asm_align(ctx, 4); + +#if LJ_TARGET_PS3 + emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0); +#else + emit_asm_label(ctx, ctx->beginsym, 0, 0); +#endif + if (ctx->mode != BUILD_machasm) + fprintf(ctx->fp, ".Lbegin:\n"); + +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND + /* This should really be moved into buildvm_arm.dasc. */ + fprintf(ctx->fp, + ".fnstart\n" + ".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n" + ".pad #28\n"); +#endif +#if LJ_TARGET_MIPS + fprintf(ctx->fp, ".set nomips16\n.abicalls\n.set noreorder\n.set nomacro\n"); +#endif + + for (i = rel = 0; i < ctx->nsym; i++) { + int32_t ofs = ctx->sym[i].ofs; + int32_t next = ctx->sym[i+1].ofs; +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI + if (!strcmp(ctx->sym[i].name, "lj_vm_ffi_call")) + fprintf(ctx->fp, + ".globl lj_err_unwind_arm\n" + ".personality lj_err_unwind_arm\n" + ".fnend\n" + ".fnstart\n" + ".save {r4, r5, r11, lr}\n" + ".setfp r11, sp\n"); +#endif + emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1); + while (rel < ctx->nreloc && ctx->reloc[rel].ofs <= next) { + BuildReloc *r = &ctx->reloc[rel]; + int n = r->ofs - ofs; +#if LJ_TARGET_X86ORX64 + if (ctx->mode == BUILD_machasm && r->type != 0) { + emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); + } else { + emit_asm_bytes(ctx, ctx->code+ofs, n); + emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]); + } + ofs += n+4; +#else + emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); + ofs += n; +#endif + rel++; + } +#if LJ_TARGET_X86ORX64 + emit_asm_bytes(ctx, ctx->code+ofs, next-ofs); +#else + emit_asm_words(ctx, ctx->code+ofs, next-ofs); +#endif + } + +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND + fprintf(ctx->fp, +#if !LJ_HASFFI + ".globl lj_err_unwind_arm\n" + ".personality lj_err_unwind_arm\n" +#endif + ".fnend\n"); +#endif + + fprintf(ctx->fp, "\n"); + switch (ctx->mode) { + case BUILD_elfasm: +#if !LJ_TARGET_PS3 + fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n"); +#endif +#if LJ_TARGET_PPCSPE + /* Soft-float ABI + SPE. */ + fprintf(ctx->fp, "\t.gnu_attribute 4, 2\n\t.gnu_attribute 8, 3\n"); +#elif LJ_TARGET_PPC && !LJ_TARGET_PS3 + /* Hard-float ABI. */ + fprintf(ctx->fp, "\t.gnu_attribute 4, 1\n"); +#endif + /* fallthrough */ + case BUILD_coffasm: + fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident); + break; + case BUILD_machasm: + fprintf(ctx->fp, + "\t.cstring\n" + "\t.ascii \"%s\\0\"\n", ctx->dasm_ident); + break; + default: + break; + } + fprintf(ctx->fp, "\n"); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_fold.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_fold.c new file mode 100644 index 0000000..7f5d9f2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_fold.c @@ -0,0 +1,229 @@ +/* +** LuaJIT VM builder: IR folding hash table generator. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_ir.h" + +/* Context for the folding hash table generator. */ +static int lineno; +static int funcidx; +static uint32_t foldkeys[BUILD_MAX_FOLD]; +static uint32_t nkeys; + +/* Try to fill the hash table with keys using the hash parameters. */ +static int tryhash(uint32_t *htab, uint32_t sz, uint32_t r, int dorol) +{ + uint32_t i; + if (dorol && ((r & 31) == 0 || (r>>5) == 0)) + return 0; /* Avoid zero rotates. */ + memset(htab, 0xff, (sz+1)*sizeof(uint32_t)); + for (i = 0; i < nkeys; i++) { + uint32_t key = foldkeys[i]; + uint32_t k = key & 0xffffff; + uint32_t h = (dorol ? lj_rol(lj_rol(k, r>>5) - k, r&31) : + (((k << (r>>5)) - k) << (r&31))) % sz; + if (htab[h] != 0xffffffff) { /* Collision on primary slot. */ + if (htab[h+1] != 0xffffffff) { /* Collision on secondary slot. */ + /* Try to move the colliding key, if possible. */ + if (h < sz-1 && htab[h+2] == 0xffffffff) { + uint32_t k2 = htab[h+1] & 0xffffff; + uint32_t h2 = (dorol ? lj_rol(lj_rol(k2, r>>5) - k2, r&31) : + (((k2 << (r>>5)) - k2) << (r&31))) % sz; + if (h2 != h+1) return 0; /* Cannot resolve collision. */ + htab[h+2] = htab[h+1]; /* Move colliding key to secondary slot. */ + } else { + return 0; /* Collision. */ + } + } + htab[h+1] = key; + } else { + htab[h] = key; + } + } + return 1; /* Success, all keys could be stored. */ +} + +/* Print the generated hash table. */ +static void printhash(BuildCtx *ctx, uint32_t *htab, uint32_t sz) +{ + uint32_t i; + fprintf(ctx->fp, "static const uint32_t fold_hash[%d] = {\n0x%08x", + sz+1, htab[0]); + for (i = 1; i < sz+1; i++) + fprintf(ctx->fp, ",\n0x%08x", htab[i]); + fprintf(ctx->fp, "\n};\n\n"); +} + +/* Exhaustive search for the shortest semi-perfect hash table. */ +static void makehash(BuildCtx *ctx) +{ + uint32_t htab[BUILD_MAX_FOLD*2+1]; + uint32_t sz, r; + /* Search for the smallest hash table with an odd size. */ + for (sz = (nkeys|1); sz < BUILD_MAX_FOLD*2; sz += 2) { + /* First try all shift hash combinations. */ + for (r = 0; r < 32*32; r++) { + if (tryhash(htab, sz, r, 0)) { + printhash(ctx, htab, sz); + fprintf(ctx->fp, + "#define fold_hashkey(k)\t(((((k)<<%u)-(k))<<%u)%%%u)\n\n", + r>>5, r&31, sz); + return; + } + } + /* Then try all rotate hash combinations. */ + for (r = 0; r < 32*32; r++) { + if (tryhash(htab, sz, r, 1)) { + printhash(ctx, htab, sz); + fprintf(ctx->fp, + "#define fold_hashkey(k)\t(lj_rol(lj_rol((k),%u)-(k),%u)%%%u)\n\n", + r>>5, r&31, sz); + return; + } + } + } + fprintf(stderr, "Error: search for perfect hash failed\n"); + exit(1); +} + +/* Parse one token of a fold rule. */ +static uint32_t nexttoken(char **pp, int allowlit, int allowany) +{ + char *p = *pp; + if (p) { + uint32_t i; + char *q = strchr(p, ' '); + if (q) *q++ = '\0'; + *pp = q; + if (allowlit && !strncmp(p, "IRFPM_", 6)) { + for (i = 0; irfpm_names[i]; i++) + if (!strcmp(irfpm_names[i], p+6)) + return i; + } else if (allowlit && !strncmp(p, "IRFL_", 5)) { + for (i = 0; irfield_names[i]; i++) + if (!strcmp(irfield_names[i], p+5)) + return i; + } else if (allowlit && !strncmp(p, "IRCALL_", 7)) { + for (i = 0; ircall_names[i]; i++) + if (!strcmp(ircall_names[i], p+7)) + return i; + } else if (allowlit && !strncmp(p, "IRCONV_", 7)) { + for (i = 0; irt_names[i]; i++) { + const char *r = strchr(p+7, '_'); + if (r && !strncmp(irt_names[i], p+7, r-(p+7))) { + uint32_t j; + for (j = 0; irt_names[j]; j++) + if (!strcmp(irt_names[j], r+1)) + return (i << 5) + j; + } + } + } else if (allowlit && *p >= '0' && *p <= '9') { + for (i = 0; *p >= '0' && *p <= '9'; p++) + i = i*10 + (*p - '0'); + if (*p == '\0') + return i; + } else if (allowany && !strcmp("any", p)) { + return allowany; + } else { + for (i = 0; ir_names[i]; i++) + if (!strcmp(ir_names[i], p)) + return i; + } + fprintf(stderr, "Error: bad fold definition token \"%s\" at line %d\n", p, lineno); + exit(1); + } + return 0; +} + +/* Parse a fold rule. */ +static void foldrule(char *p) +{ + uint32_t op = nexttoken(&p, 0, 0); + uint32_t left = nexttoken(&p, 0, 0x7f); + uint32_t right = nexttoken(&p, 1, 0x3ff); + uint32_t key = (funcidx << 24) | (op << 17) | (left << 10) | right; + uint32_t i; + if (nkeys >= BUILD_MAX_FOLD) { + fprintf(stderr, "Error: too many fold rules, increase BUILD_MAX_FOLD.\n"); + exit(1); + } + /* Simple insertion sort to detect duplicates. */ + for (i = nkeys; i > 0; i--) { + if ((foldkeys[i-1]&0xffffff) < (key & 0xffffff)) + break; + if ((foldkeys[i-1]&0xffffff) == (key & 0xffffff)) { + fprintf(stderr, "Error: duplicate fold definition at line %d\n", lineno); + exit(1); + } + foldkeys[i] = foldkeys[i-1]; + } + foldkeys[i] = key; + nkeys++; +} + +/* Emit C source code for IR folding hash table. */ +void emit_fold(BuildCtx *ctx) +{ + char buf[256]; /* We don't care about analyzing lines longer than that. */ + const char *fname = ctx->args[0]; + FILE *fp; + + if (fname == NULL) { + fprintf(stderr, "Error: missing input filename\n"); + exit(1); + } + + if (fname[0] == '-' && fname[1] == '\0') { + fp = stdin; + } else { + fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "Error: cannot open input file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } + } + + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + fprintf(ctx->fp, "static const FoldFunc fold_func[] = {\n"); + + lineno = 0; + funcidx = 0; + nkeys = 0; + while (fgets(buf, sizeof(buf), fp) != NULL) { + lineno++; + /* The prefix must be at the start of a line, otherwise it's ignored. */ + if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) { + char *p = buf+sizeof(FOLDDEF_PREFIX)-1; + char *q = strchr(p, ')'); + if (p[0] == '(' && q) { + p++; + *q = '\0'; + foldrule(p); + } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) { + p += 2; + *q = '\0'; + if (funcidx) + fprintf(ctx->fp, ",\n"); + if (p[-2] == 'X') + fprintf(ctx->fp, " %s", p); + else + fprintf(ctx->fp, " fold_%s", p); + funcidx++; + } else { + buf[strlen(buf)-1] = '\0'; + fprintf(stderr, "Error: unknown fold definition tag %s%s at line %d\n", + FOLDDEF_PREFIX, p, lineno); + exit(1); + } + } + } + fclose(fp); + fprintf(ctx->fp, "\n};\n\n"); + + makehash(ctx); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_lib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_lib.c new file mode 100644 index 0000000..eafdab9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_lib.c @@ -0,0 +1,398 @@ +/* +** LuaJIT VM builder: library definition compiler. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_lib.h" + +/* Context for library definitions. */ +static uint8_t obuf[8192]; +static uint8_t *optr; +static char modname[80]; +static size_t modnamelen; +static char funcname[80]; +static int modstate, regfunc; +static int ffid, recffid, ffasmfunc; + +enum { + REGFUNC_OK, + REGFUNC_NOREG, + REGFUNC_NOREGUV +}; + +static void libdef_name(const char *p, int kind) +{ + size_t n = strlen(p); + if (kind != LIBINIT_STRING) { + if (n > modnamelen && p[modnamelen] == '_' && + !strncmp(p, modname, modnamelen)) { + p += modnamelen+1; + n -= modnamelen+1; + } + } + if (n > LIBINIT_MAXSTR) { + fprintf(stderr, "Error: string too long: '%s'\n", p); + exit(1); + } + if (optr+1+n+2 > obuf+sizeof(obuf)) { /* +2 for caller. */ + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = (uint8_t)(n | kind); + memcpy(optr, p, n); + optr += n; +} + +static void libdef_endmodule(BuildCtx *ctx) +{ + if (modstate != 0) { + char line[80]; + const uint8_t *p; + int n; + if (modstate == 1) + fprintf(ctx->fp, " (lua_CFunction)0"); + fprintf(ctx->fp, "\n};\n"); + fprintf(ctx->fp, "static const uint8_t %s%s[] = {\n", + LABEL_PREFIX_LIBINIT, modname); + line[0] = '\0'; + for (n = 0, p = obuf; p < optr; p++) { + n += sprintf(line+n, "%d,", *p); + if (n >= 75) { + fprintf(ctx->fp, "%s\n", line); + n = 0; + line[0] = '\0'; + } + } + fprintf(ctx->fp, "%s%d\n};\n#endif\n\n", line, LIBINIT_END); + } +} + +static void libdef_module(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + libdef_endmodule(ctx); + optr = obuf; + *optr++ = (uint8_t)ffid; + *optr++ = (uint8_t)ffasmfunc; + *optr++ = 0; /* Hash table size. */ + modstate = 1; + fprintf(ctx->fp, "#ifdef %sMODULE_%s\n", LIBDEF_PREFIX, p); + fprintf(ctx->fp, "#undef %sMODULE_%s\n", LIBDEF_PREFIX, p); + fprintf(ctx->fp, "static const lua_CFunction %s%s[] = {\n", + LABEL_PREFIX_LIBCF, p); + } + modnamelen = strlen(p); + if (modnamelen > sizeof(modname)-1) { + fprintf(stderr, "Error: module name too long: '%s'\n", p); + exit(1); + } + strcpy(modname, p); +} + +static int find_ffofs(BuildCtx *ctx, const char *name) +{ + int i; + for (i = 0; i < ctx->nglob; i++) { + const char *gl = ctx->globnames[i]; + if (gl[0] == 'f' && gl[1] == 'f' && gl[2] == '_' && !strcmp(gl+3, name)) { + return (int)((uint8_t *)ctx->glob[i] - ctx->code); + } + } + fprintf(stderr, "Error: undefined fast function %s%s\n", + LABEL_PREFIX_FF, name); + exit(1); +} + +static void libdef_func(BuildCtx *ctx, char *p, int arg) +{ + if (arg != LIBINIT_CF) + ffasmfunc++; + if (ctx->mode == BUILD_libdef) { + if (modstate == 0) { + fprintf(stderr, "Error: no module for function definition %s\n", p); + exit(1); + } + if (regfunc == REGFUNC_NOREG) { + if (optr+1 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_FFID; + } else { + if (arg != LIBINIT_ASM_) { + if (modstate != 1) fprintf(ctx->fp, ",\n"); + modstate = 2; + fprintf(ctx->fp, " %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p); + } + if (regfunc != REGFUNC_NOREGUV) obuf[2]++; /* Bump hash table size. */ + libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg); + } + } else if (ctx->mode == BUILD_ffdef) { + fprintf(ctx->fp, "FFDEF(%s)\n", p); + } else if (ctx->mode == BUILD_recdef) { + if (strlen(p) > sizeof(funcname)-1) { + fprintf(stderr, "Error: function name too long: '%s'\n", p); + exit(1); + } + strcpy(funcname, p); + } else if (ctx->mode == BUILD_vmdef) { + int i; + for (i = 1; p[i] && modname[i-1]; i++) + if (p[i] == '_') p[i] = '.'; + fprintf(ctx->fp, "\"%s\",\n", p); + } else if (ctx->mode == BUILD_bcdef) { + if (arg != LIBINIT_CF) + fprintf(ctx->fp, ",\n%d", find_ffofs(ctx, p)); + } + ffid++; + regfunc = REGFUNC_OK; +} + +static uint32_t find_rec(char *name) +{ + char *p = (char *)obuf; + uint32_t n; + for (n = 2; *p; n++) { + if (strcmp(p, name) == 0) + return n; + p += strlen(p)+1; + } + if (p+strlen(name)+1 >= (char *)obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + strcpy(p, name); + return n; +} + +static void libdef_rec(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_recdef) { + char *q; + uint32_t n; + for (; recffid+1 < ffid; recffid++) + fprintf(ctx->fp, ",\n0"); + recffid = ffid; + if (*p == '.') p = funcname; + q = strchr(p, ' '); + if (q) *q++ = '\0'; + n = find_rec(p); + if (q) + fprintf(ctx->fp, ",\n0x%02x00+(%s)", n, q); + else + fprintf(ctx->fp, ",\n0x%02x00", n); + } +} + +static void memcpy_endian(void *dst, void *src, size_t n) +{ + union { uint8_t b; uint32_t u; } host_endian; + host_endian.u = 1; + if (host_endian.b == LJ_ENDIAN_SELECT(1, 0)) { + memcpy(dst, src, n); + } else { + size_t i; + for (i = 0; i < n; i++) + ((uint8_t *)dst)[i] = ((uint8_t *)src)[n-i-1]; + } +} + +static void libdef_push(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + int len = (int)strlen(p); + if (*p == '"') { + if (len > 1 && p[len-1] == '"') { + p[len-1] = '\0'; + libdef_name(p+1, LIBINIT_STRING); + return; + } + } else if (*p >= '0' && *p <= '9') { + char *ep; + double d = strtod(p, &ep); + if (*ep == '\0') { + if (optr+1+sizeof(double) > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_NUMBER; + memcpy_endian(optr, &d, sizeof(double)); + optr += sizeof(double); + return; + } + } else if (!strcmp(p, "lastcl")) { + if (optr+1 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_LASTCL; + return; + } else if (len > 4 && !strncmp(p, "top-", 4)) { + if (optr+2 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_COPY; + *optr++ = (uint8_t)atoi(p+4); + return; + } + fprintf(stderr, "Error: bad value for %sPUSH(%s)\n", LIBDEF_PREFIX, p); + exit(1); + } +} + +static void libdef_set(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + if (p[0] == '!' && p[1] == '\0') p[0] = '\0'; /* Set env. */ + libdef_name(p, LIBINIT_STRING); + *optr++ = LIBINIT_SET; + obuf[2]++; /* Bump hash table size. */ + } +} + +static void libdef_regfunc(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(ctx); UNUSED(p); + regfunc = arg; +} + +typedef void (*LibDefFunc)(BuildCtx *ctx, char *p, int arg); + +typedef struct LibDefHandler { + const char *suffix; + const char *stop; + const LibDefFunc func; + const int arg; +} LibDefHandler; + +static const LibDefHandler libdef_handlers[] = { + { "MODULE_", " \t\r\n", libdef_module, 0 }, + { "CF(", ")", libdef_func, LIBINIT_CF }, + { "ASM(", ")", libdef_func, LIBINIT_ASM }, + { "ASM_(", ")", libdef_func, LIBINIT_ASM_ }, + { "REC(", ")", libdef_rec, 0 }, + { "PUSH(", ")", libdef_push, 0 }, + { "SET(", ")", libdef_set, 0 }, + { "NOREGUV", NULL, libdef_regfunc, REGFUNC_NOREGUV }, + { "NOREG", NULL, libdef_regfunc, REGFUNC_NOREG }, + { NULL, NULL, (LibDefFunc)0, 0 } +}; + +/* Emit C source code for library function definitions. */ +void emit_lib(BuildCtx *ctx) +{ + const char *fname; + + if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef || + ctx->mode == BUILD_recdef) + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + else if (ctx->mode == BUILD_vmdef) + fprintf(ctx->fp, "ffnames = {\n[0]=\"Lua\",\n\"C\",\n"); + if (ctx->mode == BUILD_recdef) + fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100"); + recffid = ffid = FF_C+1; + ffasmfunc = 0; + + while ((fname = *ctx->args++)) { + char buf[256]; /* We don't care about analyzing lines longer than that. */ + FILE *fp; + if (fname[0] == '-' && fname[1] == '\0') { + fp = stdin; + } else { + fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "Error: cannot open input file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } + } + modstate = 0; + regfunc = REGFUNC_OK; + while (fgets(buf, sizeof(buf), fp) != NULL) { + char *p; + /* Simplistic pre-processor. Only handles top-level #if/#endif. */ + if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') { + int ok = 1; + if (!strcmp(buf, "#if LJ_52\n")) + ok = LJ_52; + else if (!strcmp(buf, "#if LJ_HASJIT\n")) + ok = LJ_HASJIT; + else if (!strcmp(buf, "#if LJ_HASFFI\n")) + ok = LJ_HASFFI; + if (!ok) { + int lvl = 1; + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') { + if (--lvl == 0) break; + } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') { + lvl++; + } + } + continue; + } + } + for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) { + const LibDefHandler *ldh; + p += sizeof(LIBDEF_PREFIX)-1; + for (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) { + size_t n, len = strlen(ldh->suffix); + if (!strncmp(p, ldh->suffix, len)) { + p += len; + n = ldh->stop ? strcspn(p, ldh->stop) : 0; + if (!p[n]) break; + p[n] = '\0'; + ldh->func(ctx, p, ldh->arg); + p += n+1; + break; + } + } + if (ldh->suffix == NULL) { + buf[strlen(buf)-1] = '\0'; + fprintf(stderr, "Error: unknown library definition tag %s%s\n", + LIBDEF_PREFIX, p); + exit(1); + } + } + } + fclose(fp); + if (ctx->mode == BUILD_libdef) { + libdef_endmodule(ctx); + } + } + + if (ctx->mode == BUILD_ffdef) { + fprintf(ctx->fp, "\n#undef FFDEF\n\n"); + fprintf(ctx->fp, + "#ifndef FF_NUM_ASMFUNC\n#define FF_NUM_ASMFUNC %d\n#endif\n\n", + ffasmfunc); + } else if (ctx->mode == BUILD_vmdef) { + fprintf(ctx->fp, "}\n\n"); + } else if (ctx->mode == BUILD_bcdef) { + int i; + fprintf(ctx->fp, "\n};\n\n"); + fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_mode[] = {\n"); + fprintf(ctx->fp, "BCDEF(BCMODE)\n"); + for (i = ffasmfunc-1; i > 0; i--) + fprintf(ctx->fp, "BCMODE_FF,\n"); + fprintf(ctx->fp, "BCMODE_FF\n};\n\n"); + } else if (ctx->mode == BUILD_recdef) { + char *p = (char *)obuf; + fprintf(ctx->fp, "\n};\n\n"); + fprintf(ctx->fp, "static const RecordFunc recff_func[] = {\n" + "recff_nyi,\n" + "recff_c"); + while (*p) { + fprintf(ctx->fp, ",\nrecff_%s", p); + p += strlen(p)+1; + } + fprintf(ctx->fp, "\n};\n\n"); + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_peobj.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_peobj.c new file mode 100644 index 0000000..138b042 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/buildvm_peobj.c @@ -0,0 +1,368 @@ +/* +** LuaJIT VM builder: PE object emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Only used for building on Windows, since we cannot assume the presence +** of a suitable assembler. The host and target byte order must match. +*/ + +#include "buildvm.h" +#include "lj_bc.h" + +#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC + +/* Context for PE object emitter. */ +static char *strtab; +static size_t strtabofs; + +/* -- PE object definitions ----------------------------------------------- */ + +/* PE header. */ +typedef struct PEheader { + uint16_t arch; + uint16_t nsects; + uint32_t time; + uint32_t symtabofs; + uint32_t nsyms; + uint16_t opthdrsz; + uint16_t flags; +} PEheader; + +/* PE section. */ +typedef struct PEsection { + char name[8]; + uint32_t vsize; + uint32_t vaddr; + uint32_t size; + uint32_t ofs; + uint32_t relocofs; + uint32_t lineofs; + uint16_t nreloc; + uint16_t nline; + uint32_t flags; +} PEsection; + +/* PE relocation. */ +typedef struct PEreloc { + uint32_t vaddr; + uint32_t symidx; + uint16_t type; +} PEreloc; + +/* Cannot use sizeof, because it pads up to the max. alignment. */ +#define PEOBJ_RELOC_SIZE (4+4+2) + +/* PE symbol table entry. */ +typedef struct PEsym { + union { + char name[8]; + uint32_t nameref[2]; + } n; + uint32_t value; + int16_t sect; + uint16_t type; + uint8_t scl; + uint8_t naux; +} PEsym; + +/* PE symbol table auxiliary entry for a section. */ +typedef struct PEsymaux { + uint32_t size; + uint16_t nreloc; + uint16_t nline; + uint32_t cksum; + uint16_t assoc; + uint8_t comdatsel; + uint8_t unused[3]; +} PEsymaux; + +/* Cannot use sizeof, because it pads up to the max. alignment. */ +#define PEOBJ_SYM_SIZE (8+4+2+2+1+1) + +/* PE object CPU specific defines. */ +#if LJ_TARGET_X86 +#define PEOBJ_ARCH_TARGET 0x014c +#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ +#define PEOBJ_RELOC_DIR32 0x06 +#define PEOBJ_RELOC_OFS 0 +#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */ +#elif LJ_TARGET_X64 +#define PEOBJ_ARCH_TARGET 0x8664 +#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ +#define PEOBJ_RELOC_DIR32 0x02 +#define PEOBJ_RELOC_ADDR32NB 0x03 +#define PEOBJ_RELOC_OFS 0 +#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */ +#elif LJ_TARGET_PPC +#define PEOBJ_ARCH_TARGET 0x01f2 +#define PEOBJ_RELOC_REL32 0x06 +#define PEOBJ_RELOC_DIR32 0x02 +#define PEOBJ_RELOC_OFS (-4) +#define PEOBJ_TEXT_FLAGS 0x60400020 /* 60=r+x, 40=align8, 20=code. */ +#endif + +/* Section numbers (0-based). */ +enum { + PEOBJ_SECT_ABS = -2, + PEOBJ_SECT_UNDEF = -1, + PEOBJ_SECT_TEXT, +#if LJ_TARGET_X64 + PEOBJ_SECT_PDATA, + PEOBJ_SECT_XDATA, +#endif + PEOBJ_SECT_RDATA_Z, + PEOBJ_NSECTIONS +}; + +/* Symbol types. */ +#define PEOBJ_TYPE_NULL 0 +#define PEOBJ_TYPE_FUNC 0x20 + +/* Symbol storage class. */ +#define PEOBJ_SCL_EXTERN 2 +#define PEOBJ_SCL_STATIC 3 + +/* -- PE object emitter --------------------------------------------------- */ + +/* Emit PE object symbol. */ +static void emit_peobj_sym(BuildCtx *ctx, const char *name, uint32_t value, + int sect, int type, int scl) +{ + PEsym sym; + size_t len = strlen(name); + if (!strtab) { /* Pass 1: only calculate string table length. */ + if (len > 8) strtabofs += len+1; + return; + } + if (len <= 8) { + memcpy(sym.n.name, name, len); + memset(sym.n.name+len, 0, 8-len); + } else { + sym.n.nameref[0] = 0; + sym.n.nameref[1] = (uint32_t)strtabofs; + memcpy(strtab + strtabofs, name, len); + strtab[strtabofs+len] = 0; + strtabofs += len+1; + } + sym.value = value; + sym.sect = (int16_t)(sect+1); /* 1-based section number. */ + sym.type = (uint16_t)type; + sym.scl = (uint8_t)scl; + sym.naux = 0; + owrite(ctx, &sym, PEOBJ_SYM_SIZE); +} + +/* Emit PE object section symbol. */ +static void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect) +{ + PEsym sym; + PEsymaux aux; + if (!strtab) return; /* Pass 1: no output. */ + memcpy(sym.n.name, pesect[sect].name, 8); + sym.value = 0; + sym.sect = (int16_t)(sect+1); /* 1-based section number. */ + sym.type = PEOBJ_TYPE_NULL; + sym.scl = PEOBJ_SCL_STATIC; + sym.naux = 1; + owrite(ctx, &sym, PEOBJ_SYM_SIZE); + memset(&aux, 0, sizeof(PEsymaux)); + aux.size = pesect[sect].size; + aux.nreloc = pesect[sect].nreloc; + owrite(ctx, &aux, PEOBJ_SYM_SIZE); +} + +/* Emit Windows PE object file. */ +void emit_peobj(BuildCtx *ctx) +{ + PEheader pehdr; + PEsection pesect[PEOBJ_NSECTIONS]; + uint32_t sofs; + int i, nrsym; + union { uint8_t b; uint32_t u; } host_endian; + + sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection); + + /* Fill in PE sections. */ + memset(&pesect, 0, PEOBJ_NSECTIONS*sizeof(PEsection)); + memcpy(pesect[PEOBJ_SECT_TEXT].name, ".text", sizeof(".text")-1); + pesect[PEOBJ_SECT_TEXT].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_TEXT].size = (uint32_t)ctx->codesz); + pesect[PEOBJ_SECT_TEXT].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE; + /* Flags: 60 = read+execute, 50 = align16, 20 = code. */ + pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS; + +#if LJ_TARGET_X64 + memcpy(pesect[PEOBJ_SECT_PDATA].name, ".pdata", sizeof(".pdata")-1); + pesect[PEOBJ_SECT_PDATA].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_PDATA].size = 6*4); + pesect[PEOBJ_SECT_PDATA].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_PDATA].nreloc = 6) * PEOBJ_RELOC_SIZE; + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_PDATA].flags = 0x40300040; + + memcpy(pesect[PEOBJ_SECT_XDATA].name, ".xdata", sizeof(".xdata")-1); + pesect[PEOBJ_SECT_XDATA].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_XDATA].size = 8*2+4+6*2); /* See below. */ + pesect[PEOBJ_SECT_XDATA].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_XDATA].nreloc = 1) * PEOBJ_RELOC_SIZE; + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_XDATA].flags = 0x40300040; +#endif + + memcpy(pesect[PEOBJ_SECT_RDATA_Z].name, ".rdata$Z", sizeof(".rdata$Z")-1); + pesect[PEOBJ_SECT_RDATA_Z].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_RDATA_Z].size = (uint32_t)strlen(ctx->dasm_ident)+1); + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_RDATA_Z].flags = 0x40300040; + + /* Fill in PE header. */ + pehdr.arch = PEOBJ_ARCH_TARGET; + pehdr.nsects = PEOBJ_NSECTIONS; + pehdr.time = 0; /* Timestamp is optional. */ + pehdr.symtabofs = sofs; + pehdr.opthdrsz = 0; + pehdr.flags = 0; + + /* Compute the size of the symbol table: + ** @feat.00 + nsections*2 + ** + asm_start + nsym + ** + nrsym + */ + nrsym = ctx->nrelocsym; + pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym; +#if LJ_TARGET_X64 + pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */ +#endif + + /* Write PE object header and all sections. */ + owrite(ctx, &pehdr, sizeof(PEheader)); + owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS); + + /* Write .text section. */ + host_endian.u = 1; + if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) { +#if LJ_TARGET_PPC + uint32_t *p = (uint32_t *)ctx->code; + int n = (int)(ctx->codesz >> 2); + for (i = 0; i < n; i++, p++) + *p = lj_bswap(*p); /* Byteswap .text section. */ +#else + fprintf(stderr, "Error: different byte order for host and target\n"); + exit(1); +#endif + } + owrite(ctx, ctx->code, ctx->codesz); + for (i = 0; i < ctx->nreloc; i++) { + PEreloc reloc; + reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS; + reloc.symidx = 1+2+ctx->reloc[i].sym; /* Reloc syms are after .text sym. */ + reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } + +#if LJ_TARGET_X64 + { /* Write .pdata section. */ + uint32_t fcofs = (uint32_t)ctx->sym[ctx->nsym-1].ofs; + uint32_t pdata[3]; /* Start of .text, end of .text and .xdata. */ + PEreloc reloc; + pdata[0] = 0; pdata[1] = fcofs; pdata[2] = 0; + owrite(ctx, &pdata, sizeof(pdata)); + pdata[0] = fcofs; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 20; + owrite(ctx, &pdata, sizeof(pdata)); + reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 12; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 16; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 20; reloc.symidx = 1+2+nrsym+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } + { /* Write .xdata section. */ + uint16_t xdata[8+2+6]; + PEreloc reloc; + xdata[0] = 0x01|0x08|0x10; /* Ver. 1, uhandler/ehandler, prolog size 0. */ + xdata[1] = 0x0005; /* Number of unwind codes, no frame pointer. */ + xdata[2] = 0x4200; /* Stack offset 4*8+8 = aword*5. */ + xdata[3] = 0x3000; /* Push rbx. */ + xdata[4] = 0x6000; /* Push rsi. */ + xdata[5] = 0x7000; /* Push rdi. */ + xdata[6] = 0x5000; /* Push rbp. */ + xdata[7] = 0; /* Alignment. */ + xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */ + xdata[10] = 0x01; /* Ver. 1, no handler, prolog size 0. */ + xdata[11] = 0x1504; /* Number of unwind codes, fp = rbp, fpofs = 16. */ + xdata[12] = 0x0300; /* set_fpreg. */ + xdata[13] = 0x0200; /* stack offset 0*8+8 = aword*1. */ + xdata[14] = 0x3000; /* Push rbx. */ + xdata[15] = 0x5000; /* Push rbp. */ + owrite(ctx, &xdata, sizeof(xdata)); + reloc.vaddr = 2*8; reloc.symidx = 1+2+nrsym+2+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } +#endif + + /* Write .rdata$Z section. */ + owrite(ctx, ctx->dasm_ident, strlen(ctx->dasm_ident)+1); + + /* Write symbol table. */ + strtab = NULL; /* 1st pass: collect string sizes. */ + for (;;) { + strtabofs = 4; + /* Mark as SafeSEH compliant. */ + emit_peobj_sym(ctx, "@feat.00", 1, + PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC); + + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT); + for (i = 0; i < nrsym; i++) + emit_peobj_sym(ctx, ctx->relocsym[i], 0, + PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); + +#if LJ_TARGET_X64 + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA); + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA); + emit_peobj_sym(ctx, "lj_err_unwind_win64", 0, + PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); +#endif + + emit_peobj_sym(ctx, ctx->beginsym, 0, + PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN); + for (i = 0; i < ctx->nsym; i++) + emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs, + PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); + + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z); + + if (strtab) + break; + /* 2nd pass: alloc strtab, write syms and copy strings. */ + strtab = (char *)malloc(strtabofs); + *(uint32_t *)strtab = (uint32_t)strtabofs; + } + + /* Write string table. */ + owrite(ctx, strtab, strtabofs); +} + +#else + +void emit_peobj(BuildCtx *ctx) +{ + UNUSED(ctx); + fprintf(stderr, "Error: no PE object support for this target\n"); + exit(1); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/genminilua.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/genminilua.lua new file mode 100644 index 0000000..04c5518 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/host/genminilua.lua @@ -0,0 +1,428 @@ +---------------------------------------------------------------------------- +-- Lua script to generate a customized, minified version of Lua. +-- The resulting 'minilua' is used for the build process of LuaJIT. +---------------------------------------------------------------------------- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- + +local sub, match, gsub = string.sub, string.match, string.gsub + +local LUA_VERSION = "5.1.5" +local LUA_SOURCE + +local function usage() + io.stderr:write("Usage: ", arg and arg[0] or "genminilua", + " lua-", LUA_VERSION, "-source-dir\n") + os.exit(1) +end + +local function find_sources() + LUA_SOURCE = arg and arg[1] + if not LUA_SOURCE then usage() end + if sub(LUA_SOURCE, -1) ~= "/" then LUA_SOURCE = LUA_SOURCE.."/" end + local fp = io.open(LUA_SOURCE .. "lua.h") + if not fp then + LUA_SOURCE = LUA_SOURCE.."src/" + fp = io.open(LUA_SOURCE .. "lua.h") + if not fp then usage() end + end + local all = fp:read("*a") + fp:close() + if not match(all, 'LUA_RELEASE%s*"Lua '..LUA_VERSION..'"') then + io.stderr:write("Error: version mismatch\n") + usage() + end +end + +local LUA_FILES = { +"lmem.c", "lobject.c", "ltm.c", "lfunc.c", "ldo.c", "lstring.c", "ltable.c", +"lgc.c", "lstate.c", "ldebug.c", "lzio.c", "lopcodes.c", +"llex.c", "lcode.c", "lparser.c", "lvm.c", "lapi.c", "lauxlib.c", +"lbaselib.c", "ltablib.c", "liolib.c", "loslib.c", "lstrlib.c", "linit.c", +} + +local REMOVE_LIB = {} +gsub([[ +collectgarbage dofile gcinfo getfenv getmetatable load print rawequal rawset +select tostring xpcall +foreach foreachi getn maxn setn +popen tmpfile seek setvbuf __tostring +clock date difftime execute getenv rename setlocale time tmpname +dump gfind len reverse +LUA_LOADLIBNAME LUA_MATHLIBNAME LUA_DBLIBNAME +]], "%S+", function(name) + REMOVE_LIB[name] = true +end) + +local REMOVE_EXTINC = { [""] = true, [""] = true, } + +local CUSTOM_MAIN = [[ +typedef unsigned int UB; +static UB barg(lua_State *L,int idx){ +union{lua_Number n;U64 b;}bn; +bn.n=lua_tonumber(L,idx)+6755399441055744.0; +if (bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number"); +return(UB)bn.b; +} +#define BRET(b) lua_pushnumber(L,(lua_Number)(int)(b));return 1; +static int tobit(lua_State *L){ +BRET(barg(L,1))} +static int bnot(lua_State *L){ +BRET(~barg(L,1))} +static int band(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)} +static int bor(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)} +static int bxor(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)} +static int lshift(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET(b<>n)} +static int arshift(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)} +static int rol(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b<>(32-n)))} +static int ror(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))} +static int bswap(lua_State *L){ +UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} +static int tohex(lua_State *L){ +UB b=barg(L,1); +int n=lua_isnone(L,2)?8:(int)barg(L,2); +const char *hexdigits="0123456789abcdef"; +char buf[8]; +int i; +if(n<0){n=-n;hexdigits="0123456789ABCDEF";} +if(n>8)n=8; +for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} +lua_pushlstring(L,buf,(size_t)n); +return 1; +} +static const struct luaL_Reg bitlib[] = { +{"tobit",tobit}, +{"bnot",bnot}, +{"band",band}, +{"bor",bor}, +{"bxor",bxor}, +{"lshift",lshift}, +{"rshift",rshift}, +{"arshift",arshift}, +{"rol",rol}, +{"ror",ror}, +{"bswap",bswap}, +{"tohex",tohex}, +{NULL,NULL} +}; +int main(int argc, char **argv){ + lua_State *L = luaL_newstate(); + int i; + luaL_openlibs(L); + luaL_register(L, "bit", bitlib); + if (argc < 2) return sizeof(void *); + lua_createtable(L, 0, 1); + lua_pushstring(L, argv[1]); + lua_rawseti(L, -2, 0); + lua_setglobal(L, "arg"); + if (luaL_loadfile(L, argv[1])) + goto err; + for (i = 2; i < argc; i++) + lua_pushstring(L, argv[i]); + if (lua_pcall(L, argc - 2, 0, 0)) { + err: + fprintf(stderr, "Error: %s\n", lua_tostring(L, -1)); + return 1; + } + lua_close(L); + return 0; +} +]] + +local function read_sources() + local t = {} + for i, name in ipairs(LUA_FILES) do + local fp = assert(io.open(LUA_SOURCE..name, "r")) + t[i] = fp:read("*a") + assert(fp:close()) + end + t[#t+1] = CUSTOM_MAIN + return table.concat(t) +end + +local includes = {} + +local function merge_includes(src) + return gsub(src, '#include%s*"([^"]*)"%s*\n', function(name) + if includes[name] then return "" end + includes[name] = true + local fp = assert(io.open(LUA_SOURCE..name, "r")) + local src = fp:read("*a") + assert(fp:close()) + src = gsub(src, "#ifndef%s+%w+_h\n#define%s+%w+_h\n", "") + src = gsub(src, "#endif%s*$", "") + return merge_includes(src) + end) +end + +local function get_license(src) + return match(src, "/%*+\n%* Copyright %(.-%*/\n") +end + +local function fold_lines(src) + return gsub(src, "\\\n", " ") +end + +local strings = {} + +local function save_str(str) + local n = #strings+1 + strings[n] = str + return "\1"..n.."\2" +end + +local function save_strings(src) + src = gsub(src, '"[^"\n]*"', save_str) + return gsub(src, "'[^'\n]*'", save_str) +end + +local function restore_strings(src) + return gsub(src, "\1(%d+)\2", function(numstr) + return strings[tonumber(numstr)] + end) +end + +local function def_istrue(def) + return def == "INT_MAX > 2147483640L" or + def == "LUAI_BITSINT >= 32" or + def == "SIZE_Bx < LUAI_BITSINT-1" or + def == "cast" or + def == "defined(LUA_CORE)" or + def == "MINSTRTABSIZE" or + def == "LUA_MINBUFFER" or + def == "HARDSTACKTESTS" or + def == "UNUSED" +end + +local head, defs = {[[ +#ifdef _MSC_VER +typedef unsigned __int64 U64; +#else +typedef unsigned long long U64; +#endif +int _CRT_glob = 0; +]]}, {} + +local function preprocess(src) + local t = { match(src, "^(.-)#") } + local lvl, on, oldon = 0, true, {} + for pp, def, txt in string.gmatch(src, "#(%w+) *([^\n]*)\n([^#]*)") do + if pp == "if" or pp == "ifdef" or pp == "ifndef" then + lvl = lvl + 1 + oldon[lvl] = on + on = def_istrue(def) + elseif pp == "else" then + if oldon[lvl] then + if on == false then on = true else on = false end + end + elseif pp == "elif" then + if oldon[lvl] then + on = def_istrue(def) + end + elseif pp == "endif" then + on = oldon[lvl] + lvl = lvl - 1 + elseif on then + if pp == "include" then + if not head[def] and not REMOVE_EXTINC[def] then + head[def] = true + head[#head+1] = "#include "..def.."\n" + end + elseif pp == "define" then + local k, sp, v = match(def, "([%w_]+)(%s*)(.*)") + if k and not (sp == "" and sub(v, 1, 1) == "(") then + defs[k] = gsub(v, "%a[%w_]*", function(tok) + return defs[tok] or tok + end) + else + t[#t+1] = "#define "..def.."\n" + end + elseif pp ~= "undef" then + error("unexpected directive: "..pp.." "..def) + end + end + if on then t[#t+1] = txt end + end + return gsub(table.concat(t), "%a[%w_]*", function(tok) + return defs[tok] or tok + end) +end + +local function merge_header(src, license) + local hdr = string.format([[ +/* This is a heavily customized and minimized copy of Lua %s. */ +/* It's only used to build LuaJIT. It does NOT have all standard functions! */ +]], LUA_VERSION) + return hdr..license..table.concat(head)..src +end + +local function strip_unused1(src) + return gsub(src, '( {"?([%w_]+)"?,%s+%a[%w_]*},\n)', function(line, func) + return REMOVE_LIB[func] and "" or line + end) +end + +local function strip_unused2(src) + return gsub(src, "Symbolic Execution.-}=", "") +end + +local function strip_unused3(src) + src = gsub(src, "extern", "static") + src = gsub(src, "\nstatic([^\n]-)%(([^)]*)%)%(", "\nstatic%1 %2(") + src = gsub(src, "#define lua_assert[^\n]*\n", "") + src = gsub(src, "lua_assert%b();?", "") + src = gsub(src, "default:\n}", "default:;\n}") + src = gsub(src, "lua_lock%b();", "") + src = gsub(src, "lua_unlock%b();", "") + src = gsub(src, "luai_threadyield%b();", "") + src = gsub(src, "luai_userstateopen%b();", "{}") + src = gsub(src, "luai_userstate%w+%b();", "") + src = gsub(src, "%(%(c==.*luaY_parser%)", "luaY_parser") + src = gsub(src, "trydecpoint%(ls,seminfo%)", + "luaX_lexerror(ls,\"malformed number\",TK_NUMBER)") + src = gsub(src, "int c=luaZ_lookahead%b();", "") + src = gsub(src, "luaL_register%(L,[^,]*,co_funcs%);\nreturn 2;", + "return 1;") + src = gsub(src, "getfuncname%b():", "NULL:") + src = gsub(src, "getobjname%b():", "NULL:") + src = gsub(src, "if%([^\n]*hookmask[^\n]*%)\n[^\n]*\n", "") + src = gsub(src, "if%([^\n]*hookmask[^\n]*%)%b{}\n", "") + src = gsub(src, "if%([^\n]*hookmask[^\n]*&&\n[^\n]*%b{}\n", "") + src = gsub(src, "(twoto%b()%()", "%1(size_t)") + src = gsub(src, "i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +typedef enum{ +TM_INDEX, +TM_NEWINDEX, +TM_GC, +TM_MODE, +TM_EQ, +TM_ADD, +TM_SUB, +TM_MUL, +TM_DIV, +TM_MOD, +TM_POW, +TM_UNM, +TM_LEN, +TM_LT, +TM_LE, +TM_CONCAT, +TM_CALL, +TM_N +}TMS; +enum OpMode{iABC,iABx,iAsBx}; +typedef enum{ +OP_MOVE, +OP_LOADK, +OP_LOADBOOL, +OP_LOADNIL, +OP_GETUPVAL, +OP_GETGLOBAL, +OP_GETTABLE, +OP_SETGLOBAL, +OP_SETUPVAL, +OP_SETTABLE, +OP_NEWTABLE, +OP_SELF, +OP_ADD, +OP_SUB, +OP_MUL, +OP_DIV, +OP_MOD, +OP_POW, +OP_UNM, +OP_NOT, +OP_LEN, +OP_CONCAT, +OP_JMP, +OP_EQ, +OP_LT, +OP_LE, +OP_TEST, +OP_TESTSET, +OP_CALL, +OP_TAILCALL, +OP_RETURN, +OP_FORLOOP, +OP_FORPREP, +OP_TFORLOOP, +OP_SETLIST, +OP_CLOSE, +OP_CLOSURE, +OP_VARARG +}OpCode; +enum OpArgMask{ +OpArgN, +OpArgU, +OpArgR, +OpArgK +}; +typedef enum{ +VVOID, +VNIL, +VTRUE, +VFALSE, +VK, +VKNUM, +VLOCAL, +VUPVAL, +VGLOBAL, +VINDEXED, +VJMP, +VRELOCABLE, +VNONRELOC, +VCALL, +VVARARG +}expkind; +enum RESERVED{ +TK_AND=257,TK_BREAK, +TK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION, +TK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT, +TK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE, +TK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER, +TK_NAME,TK_STRING,TK_EOS +}; +typedef enum BinOpr{ +OPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW, +OPR_CONCAT, +OPR_NE,OPR_EQ, +OPR_LT,OPR_LE,OPR_GT,OPR_GE, +OPR_AND,OPR_OR, +OPR_NOBINOPR +}BinOpr; +typedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr; +#define LUA_QL(x)"'"x"'" +#define luai_apicheck(L,o){(void)L;} +#define lua_number2str(s,n)sprintf((s),"%.14g",(n)) +#define lua_str2number(s,p)strtod((s),(p)) +#define luai_numadd(a,b)((a)+(b)) +#define luai_numsub(a,b)((a)-(b)) +#define luai_nummul(a,b)((a)*(b)) +#define luai_numdiv(a,b)((a)/(b)) +#define luai_nummod(a,b)((a)-floor((a)/(b))*(b)) +#define luai_numpow(a,b)(pow(a,b)) +#define luai_numunm(a)(-(a)) +#define luai_numeq(a,b)((a)==(b)) +#define luai_numlt(a,b)((a)<(b)) +#define luai_numle(a,b)((a)<=(b)) +#define luai_numisnan(a)(!luai_numeq((a),(a))) +#define lua_number2int(i,d)((i)=(int)(d)) +#define lua_number2integer(i,d)((i)=(lua_Integer)(d)) +#define LUAI_THROW(L,c)longjmp((c)->b,1) +#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a} +#define lua_pclose(L,file)((void)((void)L,file),0) +#define lua_upvalueindex(i)((-10002)-(i)) +typedef struct lua_State lua_State; +typedef int(*lua_CFunction)(lua_State*L); +typedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz); +typedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize); +typedef double lua_Number; +typedef ptrdiff_t lua_Integer; +static void lua_settop(lua_State*L,int idx); +static int lua_type(lua_State*L,int idx); +static const char* lua_tolstring(lua_State*L,int idx,size_t*len); +static size_t lua_objlen(lua_State*L,int idx); +static void lua_pushlstring(lua_State*L,const char*s,size_t l); +static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n); +static void lua_createtable(lua_State*L,int narr,int nrec); +static void lua_setfield(lua_State*L,int idx,const char*k); +#define lua_pop(L,n)lua_settop(L,-(n)-1) +#define lua_newtable(L)lua_createtable(L,0,0) +#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0) +#define lua_strlen(L,i)lua_objlen(L,(i)) +#define lua_isfunction(L,n)(lua_type(L,(n))==6) +#define lua_istable(L,n)(lua_type(L,(n))==5) +#define lua_isnil(L,n)(lua_type(L,(n))==0) +#define lua_isboolean(L,n)(lua_type(L,(n))==1) +#define lua_isnone(L,n)(lua_type(L,(n))==(-1)) +#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0) +#define lua_pushliteral(L,s)lua_pushlstring(L,""s,(sizeof(s)/sizeof(char))-1) +#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s)) +#define lua_tostring(L,i)lua_tolstring(L,(i),NULL) +typedef struct lua_Debug lua_Debug; +typedef void(*lua_Hook)(lua_State*L,lua_Debug*ar); +struct lua_Debug{ +int event; +const char*name; +const char*namewhat; +const char*what; +const char*source; +int currentline; +int nups; +int linedefined; +int lastlinedefined; +char short_src[60]; +int i_ci; +}; +typedef unsigned int lu_int32; +typedef size_t lu_mem; +typedef ptrdiff_t l_mem; +typedef unsigned char lu_byte; +#define IntPoint(p)((unsigned int)(lu_mem)(p)) +typedef union{double u;void*s;long l;}L_Umaxalign; +typedef double l_uacNumber; +#define check_exp(c,e)(e) +#define UNUSED(x)((void)(x)) +#define cast(t,exp)((t)(exp)) +#define cast_byte(i)cast(lu_byte,(i)) +#define cast_num(i)cast(lua_Number,(i)) +#define cast_int(i)cast(int,(i)) +typedef lu_int32 Instruction; +#define condhardstacktests(x)((void)0) +typedef union GCObject GCObject; +typedef struct GCheader{ +GCObject*next;lu_byte tt;lu_byte marked; +}GCheader; +typedef union{ +GCObject*gc; +void*p; +lua_Number n; +int b; +}Value; +typedef struct lua_TValue{ +Value value;int tt; +}TValue; +#define ttisnil(o)(ttype(o)==0) +#define ttisnumber(o)(ttype(o)==3) +#define ttisstring(o)(ttype(o)==4) +#define ttistable(o)(ttype(o)==5) +#define ttisfunction(o)(ttype(o)==6) +#define ttisboolean(o)(ttype(o)==1) +#define ttisuserdata(o)(ttype(o)==7) +#define ttisthread(o)(ttype(o)==8) +#define ttislightuserdata(o)(ttype(o)==2) +#define ttype(o)((o)->tt) +#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc) +#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p) +#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n) +#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts) +#define tsvalue(o)(&rawtsvalue(o)->tsv) +#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u) +#define uvalue(o)(&rawuvalue(o)->uv) +#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl) +#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h) +#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b) +#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th) +#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0)) +#define checkconsistency(obj) +#define checkliveness(g,obj) +#define setnilvalue(obj)((obj)->tt=0) +#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;} +#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;} +#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);} +#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);} +#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);} +#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);} +#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);} +#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);} +#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);} +#define setttype(obj,tt)(ttype(obj)=(tt)) +#define iscollectable(o)(ttype(o)>=4) +typedef TValue*StkId; +typedef union TString{ +L_Umaxalign dummy; +struct{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte reserved; +unsigned int hash; +size_t len; +}tsv; +}TString; +#define getstr(ts)cast(const char*,(ts)+1) +#define svalue(o)getstr(rawtsvalue(o)) +typedef union Udata{ +L_Umaxalign dummy; +struct{ +GCObject*next;lu_byte tt;lu_byte marked; +struct Table*metatable; +struct Table*env; +size_t len; +}uv; +}Udata; +typedef struct Proto{ +GCObject*next;lu_byte tt;lu_byte marked; +TValue*k; +Instruction*code; +struct Proto**p; +int*lineinfo; +struct LocVar*locvars; +TString**upvalues; +TString*source; +int sizeupvalues; +int sizek; +int sizecode; +int sizelineinfo; +int sizep; +int sizelocvars; +int linedefined; +int lastlinedefined; +GCObject*gclist; +lu_byte nups; +lu_byte numparams; +lu_byte is_vararg; +lu_byte maxstacksize; +}Proto; +typedef struct LocVar{ +TString*varname; +int startpc; +int endpc; +}LocVar; +typedef struct UpVal{ +GCObject*next;lu_byte tt;lu_byte marked; +TValue*v; +union{ +TValue value; +struct{ +struct UpVal*prev; +struct UpVal*next; +}l; +}u; +}UpVal; +typedef struct CClosure{ +GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; +lua_CFunction f; +TValue upvalue[1]; +}CClosure; +typedef struct LClosure{ +GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; +struct Proto*p; +UpVal*upvals[1]; +}LClosure; +typedef union Closure{ +CClosure c; +LClosure l; +}Closure; +#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC) +typedef union TKey{ +struct{ +Value value;int tt; +struct Node*next; +}nk; +TValue tvk; +}TKey; +typedef struct Node{ +TValue i_val; +TKey i_key; +}Node; +typedef struct Table{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte flags; +lu_byte lsizenode; +struct Table*metatable; +TValue*array; +Node*node; +Node*lastfree; +GCObject*gclist; +int sizearray; +}Table; +#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1))))) +#define twoto(x)((size_t)1<<(x)) +#define sizenode(t)(twoto((t)->lsizenode)) +static const TValue luaO_nilobject_; +#define ceillog2(x)(luaO_log2((x)-1)+1) +static int luaO_log2(unsigned int x); +#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e])) +#define fasttm(l,et,e)gfasttm(G(l),et,e) +static const TValue*luaT_gettm(Table*events,TMS event,TString*ename); +#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L)) +#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0) +#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0) +#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t)) +#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t)) +#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t))) +#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t))) +#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) +#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t)))) +static void*luaM_realloc_(lua_State*L,void*block,size_t oldsize, +size_t size); +static void*luaM_toobig(lua_State*L); +static void*luaM_growaux_(lua_State*L,void*block,int*size, +size_t size_elem,int limit, +const char*errormsg); +typedef struct Zio ZIO; +#define char2int(c)cast(int,cast(unsigned char,(c))) +#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z)) +typedef struct Mbuffer{ +char*buffer; +size_t n; +size_t buffsize; +}Mbuffer; +#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0) +#define luaZ_buffer(buff)((buff)->buffer) +#define luaZ_sizebuffer(buff)((buff)->buffsize) +#define luaZ_bufflen(buff)((buff)->n) +#define luaZ_resetbuffer(buff)((buff)->n=0) +#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size) +#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0) +struct Zio{ +size_t n; +const char*p; +lua_Reader reader; +void*data; +lua_State*L; +}; +static int luaZ_fill(ZIO*z); +struct lua_longjmp; +#define gt(L)(&L->l_gt) +#define registry(L)(&G(L)->l_registry) +typedef struct stringtable{ +GCObject**hash; +lu_int32 nuse; +int size; +}stringtable; +typedef struct CallInfo{ +StkId base; +StkId func; +StkId top; +const Instruction*savedpc; +int nresults; +int tailcalls; +}CallInfo; +#define curr_func(L)(clvalue(L->ci->func)) +#define ci_func(ci)(clvalue((ci)->func)) +#define f_isLua(ci)(!ci_func(ci)->c.isC) +#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci)) +typedef struct global_State{ +stringtable strt; +lua_Alloc frealloc; +void*ud; +lu_byte currentwhite; +lu_byte gcstate; +int sweepstrgc; +GCObject*rootgc; +GCObject**sweepgc; +GCObject*gray; +GCObject*grayagain; +GCObject*weak; +GCObject*tmudata; +Mbuffer buff; +lu_mem GCthreshold; +lu_mem totalbytes; +lu_mem estimate; +lu_mem gcdept; +int gcpause; +int gcstepmul; +lua_CFunction panic; +TValue l_registry; +struct lua_State*mainthread; +UpVal uvhead; +struct Table*mt[(8+1)]; +TString*tmname[TM_N]; +}global_State; +struct lua_State{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte status; +StkId top; +StkId base; +global_State*l_G; +CallInfo*ci; +const Instruction*savedpc; +StkId stack_last; +StkId stack; +CallInfo*end_ci; +CallInfo*base_ci; +int stacksize; +int size_ci; +unsigned short nCcalls; +unsigned short baseCcalls; +lu_byte hookmask; +lu_byte allowhook; +int basehookcount; +int hookcount; +lua_Hook hook; +TValue l_gt; +TValue env; +GCObject*openupval; +GCObject*gclist; +struct lua_longjmp*errorJmp; +ptrdiff_t errfunc; +}; +#define G(L)(L->l_G) +union GCObject{ +GCheader gch; +union TString ts; +union Udata u; +union Closure cl; +struct Table h; +struct Proto p; +struct UpVal uv; +struct lua_State th; +}; +#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts)) +#define gco2ts(o)(&rawgco2ts(o)->tsv) +#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u)) +#define gco2u(o)(&rawgco2u(o)->uv) +#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl)) +#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h)) +#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p)) +#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv)) +#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv)) +#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th)) +#define obj2gco(v)(cast(GCObject*,(v))) +static void luaE_freethread(lua_State*L,lua_State*L1); +#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1) +#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0) +#define resethookcount(L)(L->hookcount=L->basehookcount) +static void luaG_typeerror(lua_State*L,const TValue*o, +const char*opname); +static void luaG_runerror(lua_State*L,const char*fmt,...); +#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1)); +#define incr_top(L){luaD_checkstack(L,1);L->top++;} +#define savestack(L,p)((char*)(p)-(char*)L->stack) +#define restorestack(L,n)((TValue*)((char*)L->stack+(n))) +#define saveci(L,p)((char*)(p)-(char*)L->base_ci) +#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n))) +typedef void(*Pfunc)(lua_State*L,void*ud); +static int luaD_poscall(lua_State*L,StkId firstResult); +static void luaD_reallocCI(lua_State*L,int newsize); +static void luaD_reallocstack(lua_State*L,int newsize); +static void luaD_growstack(lua_State*L,int n); +static void luaD_throw(lua_State*L,int errcode); +static void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems, +int limit,const char*errormsg){ +void*newblock; +int newsize; +if(*size>=limit/2){ +if(*size>=limit) +luaG_runerror(L,errormsg); +newsize=limit; +} +else{ +newsize=(*size)*2; +if(newsize<4) +newsize=4; +} +newblock=luaM_reallocv(L,block,*size,newsize,size_elems); +*size=newsize; +return newblock; +} +static void*luaM_toobig(lua_State*L){ +luaG_runerror(L,"memory allocation error: block too big"); +return NULL; +} +static void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){ +global_State*g=G(L); +block=(*g->frealloc)(g->ud,block,osize,nsize); +if(block==NULL&&nsize>0) +luaD_throw(L,4); +g->totalbytes=(g->totalbytes-osize)+nsize; +return block; +} +#define resetbits(x,m)((x)&=cast(lu_byte,~(m))) +#define setbits(x,m)((x)|=(m)) +#define testbits(x,m)((x)&(m)) +#define bitmask(b)(1<<(b)) +#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2)) +#define l_setbit(x,b)setbits(x,bitmask(b)) +#define resetbit(x,b)resetbits(x,bitmask(b)) +#define testbit(x,b)testbits(x,bitmask(b)) +#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2))) +#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2))) +#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2))) +#define iswhite(x)test2bits((x)->gch.marked,0,1) +#define isblack(x)testbit((x)->gch.marked,2) +#define isgray(x)(!isblack(x)&&!iswhite(x)) +#define otherwhite(g)(g->currentwhite^bit2mask(0,1)) +#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1)) +#define changewhite(x)((x)->gch.marked^=bit2mask(0,1)) +#define gray2black(x)l_setbit((x)->gch.marked,2) +#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x))) +#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1)) +#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);} +#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));} +#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);} +#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));} +#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);} +static void luaC_step(lua_State*L); +static void luaC_link(lua_State*L,GCObject*o,lu_byte tt); +static void luaC_linkupval(lua_State*L,UpVal*uv); +static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v); +static void luaC_barrierback(lua_State*L,Table*t); +#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char)) +#define sizeudata(u)(sizeof(union Udata)+(u)->len) +#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s))) +#define luaS_newliteral(L,s)(luaS_newlstr(L,""s,(sizeof(s)/sizeof(char))-1)) +#define luaS_fix(s)l_setbit((s)->tsv.marked,5) +static TString*luaS_newlstr(lua_State*L,const char*str,size_t l); +#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o))) +#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL)) +#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2)) +static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2); +static const TValue*luaV_tonumber(const TValue*obj,TValue*n); +static int luaV_tostring(lua_State*L,StkId obj); +static void luaV_execute(lua_State*L,int nexeccalls); +static void luaV_concat(lua_State*L,int total,int last); +static const TValue luaO_nilobject_={{NULL},0}; +static int luaO_int2fb(unsigned int x){ +int e=0; +while(x>=16){ +x=(x+1)>>1; +e++; +} +if(x<8)return x; +else return((e+1)<<3)|(cast_int(x)-8); +} +static int luaO_fb2int(int x){ +int e=(x>>3)&31; +if(e==0)return x; +else return((x&7)+8)<<(e-1); +} +static int luaO_log2(unsigned int x){ +static const lu_byte log_2[256]={ +0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 +}; +int l=-1; +while(x>=256){l+=8;x>>=8;} +return l+log_2[x]; +} +static int luaO_rawequalObj(const TValue*t1,const TValue*t2){ +if(ttype(t1)!=ttype(t2))return 0; +else switch(ttype(t1)){ +case 0: +return 1; +case 3: +return luai_numeq(nvalue(t1),nvalue(t2)); +case 1: +return bvalue(t1)==bvalue(t2); +case 2: +return pvalue(t1)==pvalue(t2); +default: +return gcvalue(t1)==gcvalue(t2); +} +} +static int luaO_str2d(const char*s,lua_Number*result){ +char*endptr; +*result=lua_str2number(s,&endptr); +if(endptr==s)return 0; +if(*endptr=='x'||*endptr=='X') +*result=cast_num(strtoul(s,&endptr,16)); +if(*endptr=='\0')return 1; +while(isspace(cast(unsigned char,*endptr)))endptr++; +if(*endptr!='\0')return 0; +return 1; +} +static void pushstr(lua_State*L,const char*str){ +setsvalue(L,L->top,luaS_new(L,str)); +incr_top(L); +} +static const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){ +int n=1; +pushstr(L,""); +for(;;){ +const char*e=strchr(fmt,'%'); +if(e==NULL)break; +setsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt)); +incr_top(L); +switch(*(e+1)){ +case's':{ +const char*s=va_arg(argp,char*); +if(s==NULL)s="(null)"; +pushstr(L,s); +break; +} +case'c':{ +char buff[2]; +buff[0]=cast(char,va_arg(argp,int)); +buff[1]='\0'; +pushstr(L,buff); +break; +} +case'd':{ +setnvalue(L->top,cast_num(va_arg(argp,int))); +incr_top(L); +break; +} +case'f':{ +setnvalue(L->top,cast_num(va_arg(argp,l_uacNumber))); +incr_top(L); +break; +} +case'p':{ +char buff[4*sizeof(void*)+8]; +sprintf(buff,"%p",va_arg(argp,void*)); +pushstr(L,buff); +break; +} +case'%':{ +pushstr(L,"%"); +break; +} +default:{ +char buff[3]; +buff[0]='%'; +buff[1]=*(e+1); +buff[2]='\0'; +pushstr(L,buff); +break; +} +} +n+=2; +fmt=e+2; +} +pushstr(L,fmt); +luaV_concat(L,n+1,cast_int(L->top-L->base)-1); +L->top-=n; +return svalue(L->top-1); +} +static const char*luaO_pushfstring(lua_State*L,const char*fmt,...){ +const char*msg; +va_list argp; +va_start(argp,fmt); +msg=luaO_pushvfstring(L,fmt,argp); +va_end(argp); +return msg; +} +static void luaO_chunkid(char*out,const char*source,size_t bufflen){ +if(*source=='='){ +strncpy(out,source+1,bufflen); +out[bufflen-1]='\0'; +} +else{ +if(*source=='@'){ +size_t l; +source++; +bufflen-=sizeof(" '...' "); +l=strlen(source); +strcpy(out,""); +if(l>bufflen){ +source+=(l-bufflen); +strcat(out,"..."); +} +strcat(out,source); +} +else{ +size_t len=strcspn(source,"\n\r"); +bufflen-=sizeof(" [string \"...\"] "); +if(len>bufflen)len=bufflen; +strcpy(out,"[string \""); +if(source[len]!='\0'){ +strncat(out,source,len); +strcat(out,"..."); +} +else +strcat(out,source); +strcat(out,"\"]"); +} +} +} +#define gnode(t,i)(&(t)->node[i]) +#define gkey(n)(&(n)->i_key.nk) +#define gval(n)(&(n)->i_val) +#define gnext(n)((n)->i_key.nk.next) +#define key2tval(n)(&(n)->i_key.tvk) +static TValue*luaH_setnum(lua_State*L,Table*t,int key); +static const TValue*luaH_getstr(Table*t,TString*key); +static TValue*luaH_set(lua_State*L,Table*t,const TValue*key); +static const char*const luaT_typenames[]={ +"nil","boolean","userdata","number", +"string","table","function","userdata","thread", +"proto","upval" +}; +static void luaT_init(lua_State*L){ +static const char*const luaT_eventname[]={ +"__index","__newindex", +"__gc","__mode","__eq", +"__add","__sub","__mul","__div","__mod", +"__pow","__unm","__len","__lt","__le", +"__concat","__call" +}; +int i; +for(i=0;itmname[i]=luaS_new(L,luaT_eventname[i]); +luaS_fix(G(L)->tmname[i]); +} +} +static const TValue*luaT_gettm(Table*events,TMS event,TString*ename){ +const TValue*tm=luaH_getstr(events,ename); +if(ttisnil(tm)){ +events->flags|=cast_byte(1u<metatable; +break; +case 7: +mt=uvalue(o)->metatable; +break; +default: +mt=G(L)->mt[ttype(o)]; +} +return(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_)); +} +#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1))) +#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1))) +static Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){ +Closure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems))); +luaC_link(L,obj2gco(c),6); +c->c.isC=1; +c->c.env=e; +c->c.nupvalues=cast_byte(nelems); +return c; +} +static Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){ +Closure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems))); +luaC_link(L,obj2gco(c),6); +c->l.isC=0; +c->l.env=e; +c->l.nupvalues=cast_byte(nelems); +while(nelems--)c->l.upvals[nelems]=NULL; +return c; +} +static UpVal*luaF_newupval(lua_State*L){ +UpVal*uv=luaM_new(L,UpVal); +luaC_link(L,obj2gco(uv),(8+2)); +uv->v=&uv->u.value; +setnilvalue(uv->v); +return uv; +} +static UpVal*luaF_findupval(lua_State*L,StkId level){ +global_State*g=G(L); +GCObject**pp=&L->openupval; +UpVal*p; +UpVal*uv; +while(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){ +if(p->v==level){ +if(isdead(g,obj2gco(p))) +changewhite(obj2gco(p)); +return p; +} +pp=&p->next; +} +uv=luaM_new(L,UpVal); +uv->tt=(8+2); +uv->marked=luaC_white(g); +uv->v=level; +uv->next=*pp; +*pp=obj2gco(uv); +uv->u.l.prev=&g->uvhead; +uv->u.l.next=g->uvhead.u.l.next; +uv->u.l.next->u.l.prev=uv; +g->uvhead.u.l.next=uv; +return uv; +} +static void unlinkupval(UpVal*uv){ +uv->u.l.next->u.l.prev=uv->u.l.prev; +uv->u.l.prev->u.l.next=uv->u.l.next; +} +static void luaF_freeupval(lua_State*L,UpVal*uv){ +if(uv->v!=&uv->u.value) +unlinkupval(uv); +luaM_free(L,uv); +} +static void luaF_close(lua_State*L,StkId level){ +UpVal*uv; +global_State*g=G(L); +while(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){ +GCObject*o=obj2gco(uv); +L->openupval=uv->next; +if(isdead(g,o)) +luaF_freeupval(L,uv); +else{ +unlinkupval(uv); +setobj(L,&uv->u.value,uv->v); +uv->v=&uv->u.value; +luaC_linkupval(L,uv); +} +} +} +static Proto*luaF_newproto(lua_State*L){ +Proto*f=luaM_new(L,Proto); +luaC_link(L,obj2gco(f),(8+1)); +f->k=NULL; +f->sizek=0; +f->p=NULL; +f->sizep=0; +f->code=NULL; +f->sizecode=0; +f->sizelineinfo=0; +f->sizeupvalues=0; +f->nups=0; +f->upvalues=NULL; +f->numparams=0; +f->is_vararg=0; +f->maxstacksize=0; +f->lineinfo=NULL; +f->sizelocvars=0; +f->locvars=NULL; +f->linedefined=0; +f->lastlinedefined=0; +f->source=NULL; +return f; +} +static void luaF_freeproto(lua_State*L,Proto*f){ +luaM_freearray(L,f->code,f->sizecode,Instruction); +luaM_freearray(L,f->p,f->sizep,Proto*); +luaM_freearray(L,f->k,f->sizek,TValue); +luaM_freearray(L,f->lineinfo,f->sizelineinfo,int); +luaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar); +luaM_freearray(L,f->upvalues,f->sizeupvalues,TString*); +luaM_free(L,f); +} +static void luaF_freeclosure(lua_State*L,Closure*c){ +int size=(c->c.isC)?sizeCclosure(c->c.nupvalues): +sizeLclosure(c->l.nupvalues); +luaM_freemem(L,c,size); +} +#define MASK1(n,p)((~((~(Instruction)0)<>0)&MASK1(6,0))) +#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0)))) +#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0))) +#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6))))) +#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0))) +#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9))))) +#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0))) +#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8))))) +#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0))) +#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8))))) +#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1)) +#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1))) +#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8))) +#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8))) +#define ISK(x)((x)&(1<<(9-1))) +#define INDEXK(r)((int)(r)&~(1<<(9-1))) +#define RKASK(x)((x)|(1<<(9-1))) +static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]; +#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3)) +#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3)) +#define testTMode(m)(luaP_opmodes[m]&(1<<7)) +typedef struct expdesc{ +expkind k; +union{ +struct{int info,aux;}s; +lua_Number nval; +}u; +int t; +int f; +}expdesc; +typedef struct upvaldesc{ +lu_byte k; +lu_byte info; +}upvaldesc; +struct BlockCnt; +typedef struct FuncState{ +Proto*f; +Table*h; +struct FuncState*prev; +struct LexState*ls; +struct lua_State*L; +struct BlockCnt*bl; +int pc; +int lasttarget; +int jpc; +int freereg; +int nk; +int np; +short nlocvars; +lu_byte nactvar; +upvaldesc upvalues[60]; +unsigned short actvar[200]; +}FuncState; +static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff, +const char*name); +struct lua_longjmp{ +struct lua_longjmp*previous; +jmp_buf b; +volatile int status; +}; +static void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){ +switch(errcode){ +case 4:{ +setsvalue(L,oldtop,luaS_newliteral(L,"not enough memory")); +break; +} +case 5:{ +setsvalue(L,oldtop,luaS_newliteral(L,"error in error handling")); +break; +} +case 3: +case 2:{ +setobj(L,oldtop,L->top-1); +break; +} +} +L->top=oldtop+1; +} +static void restore_stack_limit(lua_State*L){ +if(L->size_ci>20000){ +int inuse=cast_int(L->ci-L->base_ci); +if(inuse+1<20000) +luaD_reallocCI(L,20000); +} +} +static void resetstack(lua_State*L,int status){ +L->ci=L->base_ci; +L->base=L->ci->base; +luaF_close(L,L->base); +luaD_seterrorobj(L,status,L->base); +L->nCcalls=L->baseCcalls; +L->allowhook=1; +restore_stack_limit(L); +L->errfunc=0; +L->errorJmp=NULL; +} +static void luaD_throw(lua_State*L,int errcode){ +if(L->errorJmp){ +L->errorJmp->status=errcode; +LUAI_THROW(L,L->errorJmp); +} +else{ +L->status=cast_byte(errcode); +if(G(L)->panic){ +resetstack(L,errcode); +G(L)->panic(L); +} +exit(EXIT_FAILURE); +} +} +static int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){ +struct lua_longjmp lj; +lj.status=0; +lj.previous=L->errorJmp; +L->errorJmp=&lj; +LUAI_TRY(L,&lj, +(*f)(L,ud); +); +L->errorJmp=lj.previous; +return lj.status; +} +static void correctstack(lua_State*L,TValue*oldstack){ +CallInfo*ci; +GCObject*up; +L->top=(L->top-oldstack)+L->stack; +for(up=L->openupval;up!=NULL;up=up->gch.next) +gco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack; +for(ci=L->base_ci;ci<=L->ci;ci++){ +ci->top=(ci->top-oldstack)+L->stack; +ci->base=(ci->base-oldstack)+L->stack; +ci->func=(ci->func-oldstack)+L->stack; +} +L->base=(L->base-oldstack)+L->stack; +} +static void luaD_reallocstack(lua_State*L,int newsize){ +TValue*oldstack=L->stack; +int realsize=newsize+1+5; +luaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue); +L->stacksize=realsize; +L->stack_last=L->stack+newsize; +correctstack(L,oldstack); +} +static void luaD_reallocCI(lua_State*L,int newsize){ +CallInfo*oldci=L->base_ci; +luaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo); +L->size_ci=newsize; +L->ci=(L->ci-oldci)+L->base_ci; +L->end_ci=L->base_ci+L->size_ci-1; +} +static void luaD_growstack(lua_State*L,int n){ +if(n<=L->stacksize) +luaD_reallocstack(L,2*L->stacksize); +else +luaD_reallocstack(L,L->stacksize+n); +} +static CallInfo*growCI(lua_State*L){ +if(L->size_ci>20000) +luaD_throw(L,5); +else{ +luaD_reallocCI(L,2*L->size_ci); +if(L->size_ci>20000) +luaG_runerror(L,"stack overflow"); +} +return++L->ci; +} +static StkId adjust_varargs(lua_State*L,Proto*p,int actual){ +int i; +int nfixargs=p->numparams; +Table*htab=NULL; +StkId base,fixed; +for(;actualtop++); +fixed=L->top-actual; +base=L->top; +for(i=0;itop++,fixed+i); +setnilvalue(fixed+i); +} +if(htab){ +sethvalue(L,L->top++,htab); +} +return base; +} +static StkId tryfuncTM(lua_State*L,StkId func){ +const TValue*tm=luaT_gettmbyobj(L,func,TM_CALL); +StkId p; +ptrdiff_t funcr=savestack(L,func); +if(!ttisfunction(tm)) +luaG_typeerror(L,func,"call"); +for(p=L->top;p>func;p--)setobj(L,p,p-1); +incr_top(L); +func=restorestack(L,funcr); +setobj(L,func,tm); +return func; +} +#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci)) +static int luaD_precall(lua_State*L,StkId func,int nresults){ +LClosure*cl; +ptrdiff_t funcr; +if(!ttisfunction(func)) +func=tryfuncTM(L,func); +funcr=savestack(L,func); +cl=&clvalue(func)->l; +L->ci->savedpc=L->savedpc; +if(!cl->isC){ +CallInfo*ci; +StkId st,base; +Proto*p=cl->p; +luaD_checkstack(L,p->maxstacksize); +func=restorestack(L,funcr); +if(!p->is_vararg){ +base=func+1; +if(L->top>base+p->numparams) +L->top=base+p->numparams; +} +else{ +int nargs=cast_int(L->top-func)-1; +base=adjust_varargs(L,p,nargs); +func=restorestack(L,funcr); +} +ci=inc_ci(L); +ci->func=func; +L->base=ci->base=base; +ci->top=L->base+p->maxstacksize; +L->savedpc=p->code; +ci->tailcalls=0; +ci->nresults=nresults; +for(st=L->top;sttop;st++) +setnilvalue(st); +L->top=ci->top; +return 0; +} +else{ +CallInfo*ci; +int n; +luaD_checkstack(L,20); +ci=inc_ci(L); +ci->func=restorestack(L,funcr); +L->base=ci->base=ci->func+1; +ci->top=L->top+20; +ci->nresults=nresults; +n=(*curr_func(L)->c.f)(L); +if(n<0) +return 2; +else{ +luaD_poscall(L,L->top-n); +return 1; +} +} +} +static int luaD_poscall(lua_State*L,StkId firstResult){ +StkId res; +int wanted,i; +CallInfo*ci; +ci=L->ci--; +res=ci->func; +wanted=ci->nresults; +L->base=(ci-1)->base; +L->savedpc=(ci-1)->savedpc; +for(i=wanted;i!=0&&firstResulttop;i--) +setobj(L,res++,firstResult++); +while(i-->0) +setnilvalue(res++); +L->top=res; +return(wanted-(-1)); +} +static void luaD_call(lua_State*L,StkId func,int nResults){ +if(++L->nCcalls>=200){ +if(L->nCcalls==200) +luaG_runerror(L,"C stack overflow"); +else if(L->nCcalls>=(200+(200>>3))) +luaD_throw(L,5); +} +if(luaD_precall(L,func,nResults)==0) +luaV_execute(L,1); +L->nCcalls--; +luaC_checkGC(L); +} +static int luaD_pcall(lua_State*L,Pfunc func,void*u, +ptrdiff_t old_top,ptrdiff_t ef){ +int status; +unsigned short oldnCcalls=L->nCcalls; +ptrdiff_t old_ci=saveci(L,L->ci); +lu_byte old_allowhooks=L->allowhook; +ptrdiff_t old_errfunc=L->errfunc; +L->errfunc=ef; +status=luaD_rawrunprotected(L,func,u); +if(status!=0){ +StkId oldtop=restorestack(L,old_top); +luaF_close(L,oldtop); +luaD_seterrorobj(L,status,oldtop); +L->nCcalls=oldnCcalls; +L->ci=restoreci(L,old_ci); +L->base=L->ci->base; +L->savedpc=L->ci->savedpc; +L->allowhook=old_allowhooks; +restore_stack_limit(L); +} +L->errfunc=old_errfunc; +return status; +} +struct SParser{ +ZIO*z; +Mbuffer buff; +const char*name; +}; +static void f_parser(lua_State*L,void*ud){ +int i; +Proto*tf; +Closure*cl; +struct SParser*p=cast(struct SParser*,ud); +luaC_checkGC(L); +tf=luaY_parser(L,p->z, +&p->buff,p->name); +cl=luaF_newLclosure(L,tf->nups,hvalue(gt(L))); +cl->l.p=tf; +for(i=0;inups;i++) +cl->l.upvals[i]=luaF_newupval(L); +setclvalue(L,L->top,cl); +incr_top(L); +} +static int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){ +struct SParser p; +int status; +p.z=z;p.name=name; +luaZ_initbuffer(L,&p.buff); +status=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc); +luaZ_freebuffer(L,&p.buff); +return status; +} +static void luaS_resize(lua_State*L,int newsize){ +GCObject**newhash; +stringtable*tb; +int i; +if(G(L)->gcstate==2) +return; +newhash=luaM_newvector(L,newsize,GCObject*); +tb=&G(L)->strt; +for(i=0;isize;i++){ +GCObject*p=tb->hash[i]; +while(p){ +GCObject*next=p->gch.next; +unsigned int h=gco2ts(p)->hash; +int h1=lmod(h,newsize); +p->gch.next=newhash[h1]; +newhash[h1]=p; +p=next; +} +} +luaM_freearray(L,tb->hash,tb->size,TString*); +tb->size=newsize; +tb->hash=newhash; +} +static TString*newlstr(lua_State*L,const char*str,size_t l, +unsigned int h){ +TString*ts; +stringtable*tb; +if(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char)) +luaM_toobig(L); +ts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString))); +ts->tsv.len=l; +ts->tsv.hash=h; +ts->tsv.marked=luaC_white(G(L)); +ts->tsv.tt=4; +ts->tsv.reserved=0; +memcpy(ts+1,str,l*sizeof(char)); +((char*)(ts+1))[l]='\0'; +tb=&G(L)->strt; +h=lmod(h,tb->size); +ts->tsv.next=tb->hash[h]; +tb->hash[h]=obj2gco(ts); +tb->nuse++; +if(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2) +luaS_resize(L,tb->size*2); +return ts; +} +static TString*luaS_newlstr(lua_State*L,const char*str,size_t l){ +GCObject*o; +unsigned int h=cast(unsigned int,l); +size_t step=(l>>5)+1; +size_t l1; +for(l1=l;l1>=step;l1-=step) +h=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1])); +for(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)]; +o!=NULL; +o=o->gch.next){ +TString*ts=rawgco2ts(o); +if(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){ +if(isdead(G(L),o))changewhite(o); +return ts; +} +} +return newlstr(L,str,l,h); +} +static Udata*luaS_newudata(lua_State*L,size_t s,Table*e){ +Udata*u; +if(s>((size_t)(~(size_t)0)-2)-sizeof(Udata)) +luaM_toobig(L); +u=cast(Udata*,luaM_malloc(L,s+sizeof(Udata))); +u->uv.marked=luaC_white(G(L)); +u->uv.tt=7; +u->uv.len=s; +u->uv.metatable=NULL; +u->uv.env=e; +u->uv.next=G(L)->mainthread->next; +G(L)->mainthread->next=obj2gco(u); +return u; +} +#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t)))) +#define hashstr(t,str)hashpow2(t,(str)->tsv.hash) +#define hashboolean(t,p)hashpow2(t,p) +#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1)))) +#define hashpointer(t,p)hashmod(t,IntPoint(p)) +static const Node dummynode_={ +{{NULL},0}, +{{{NULL},0,NULL}} +}; +static Node*hashnum(const Table*t,lua_Number n){ +unsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))]; +int i; +if(luai_numeq(n,0)) +return gnode(t,0); +memcpy(a,&n,sizeof(a)); +for(i=1;isizearray) +return i-1; +else{ +Node*n=mainposition(t,key); +do{ +if(luaO_rawequalObj(key2tval(n),key)|| +(ttype(gkey(n))==(8+3)&&iscollectable(key)&& +gcvalue(gkey(n))==gcvalue(key))){ +i=cast_int(n-gnode(t,0)); +return i+t->sizearray; +} +else n=gnext(n); +}while(n); +luaG_runerror(L,"invalid key to "LUA_QL("next")); +return 0; +} +} +static int luaH_next(lua_State*L,Table*t,StkId key){ +int i=findindex(L,t,key); +for(i++;isizearray;i++){ +if(!ttisnil(&t->array[i])){ +setnvalue(key,cast_num(i+1)); +setobj(L,key+1,&t->array[i]); +return 1; +} +} +for(i-=t->sizearray;i<(int)sizenode(t);i++){ +if(!ttisnil(gval(gnode(t,i)))){ +setobj(L,key,key2tval(gnode(t,i))); +setobj(L,key+1,gval(gnode(t,i))); +return 1; +} +} +return 0; +} +static int computesizes(int nums[],int*narray){ +int i; +int twotoi; +int a=0; +int na=0; +int n=0; +for(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){ +if(nums[i]>0){ +a+=nums[i]; +if(a>twotoi/2){ +n=twotoi; +na=a; +} +} +if(a==*narray)break; +} +*narray=n; +return na; +} +static int countint(const TValue*key,int*nums){ +int k=arrayindex(key); +if(0t->sizearray){ +lim=t->sizearray; +if(i>lim) +break; +} +for(;i<=lim;i++){ +if(!ttisnil(&t->array[i-1])) +lc++; +} +nums[lg]+=lc; +ause+=lc; +} +return ause; +} +static int numusehash(const Table*t,int*nums,int*pnasize){ +int totaluse=0; +int ause=0; +int i=sizenode(t); +while(i--){ +Node*n=&t->node[i]; +if(!ttisnil(gval(n))){ +ause+=countint(key2tval(n),nums); +totaluse++; +} +} +*pnasize+=ause; +return totaluse; +} +static void setarrayvector(lua_State*L,Table*t,int size){ +int i; +luaM_reallocvector(L,t->array,t->sizearray,size,TValue); +for(i=t->sizearray;iarray[i]); +t->sizearray=size; +} +static void setnodevector(lua_State*L,Table*t,int size){ +int lsize; +if(size==0){ +t->node=cast(Node*,(&dummynode_)); +lsize=0; +} +else{ +int i; +lsize=ceillog2(size); +if(lsize>(32-2)) +luaG_runerror(L,"table overflow"); +size=twoto(lsize); +t->node=luaM_newvector(L,size,Node); +for(i=0;ilsizenode=cast_byte(lsize); +t->lastfree=gnode(t,size); +} +static void resize(lua_State*L,Table*t,int nasize,int nhsize){ +int i; +int oldasize=t->sizearray; +int oldhsize=t->lsizenode; +Node*nold=t->node; +if(nasize>oldasize) +setarrayvector(L,t,nasize); +setnodevector(L,t,nhsize); +if(nasizesizearray=nasize; +for(i=nasize;iarray[i])) +setobj(L,luaH_setnum(L,t,i+1),&t->array[i]); +} +luaM_reallocvector(L,t->array,oldasize,nasize,TValue); +} +for(i=twoto(oldhsize)-1;i>=0;i--){ +Node*old=nold+i; +if(!ttisnil(gval(old))) +setobj(L,luaH_set(L,t,key2tval(old)),gval(old)); +} +if(nold!=(&dummynode_)) +luaM_freearray(L,nold,twoto(oldhsize),Node); +} +static void luaH_resizearray(lua_State*L,Table*t,int nasize){ +int nsize=(t->node==(&dummynode_))?0:sizenode(t); +resize(L,t,nasize,nsize); +} +static void rehash(lua_State*L,Table*t,const TValue*ek){ +int nasize,na; +int nums[(32-2)+1]; +int i; +int totaluse; +for(i=0;i<=(32-2);i++)nums[i]=0; +nasize=numusearray(t,nums); +totaluse=nasize; +totaluse+=numusehash(t,nums,&nasize); +nasize+=countint(ek,nums); +totaluse++; +na=computesizes(nums,&nasize); +resize(L,t,nasize,totaluse-na); +} +static Table*luaH_new(lua_State*L,int narray,int nhash){ +Table*t=luaM_new(L,Table); +luaC_link(L,obj2gco(t),5); +t->metatable=NULL; +t->flags=cast_byte(~0); +t->array=NULL; +t->sizearray=0; +t->lsizenode=0; +t->node=cast(Node*,(&dummynode_)); +setarrayvector(L,t,narray); +setnodevector(L,t,nhash); +return t; +} +static void luaH_free(lua_State*L,Table*t){ +if(t->node!=(&dummynode_)) +luaM_freearray(L,t->node,sizenode(t),Node); +luaM_freearray(L,t->array,t->sizearray,TValue); +luaM_free(L,t); +} +static Node*getfreepos(Table*t){ +while(t->lastfree-->t->node){ +if(ttisnil(gkey(t->lastfree))) +return t->lastfree; +} +return NULL; +} +static TValue*newkey(lua_State*L,Table*t,const TValue*key){ +Node*mp=mainposition(t,key); +if(!ttisnil(gval(mp))||mp==(&dummynode_)){ +Node*othern; +Node*n=getfreepos(t); +if(n==NULL){ +rehash(L,t,key); +return luaH_set(L,t,key); +} +othern=mainposition(t,key2tval(mp)); +if(othern!=mp){ +while(gnext(othern)!=mp)othern=gnext(othern); +gnext(othern)=n; +*n=*mp; +gnext(mp)=NULL; +setnilvalue(gval(mp)); +} +else{ +gnext(n)=gnext(mp); +gnext(mp)=n; +mp=n; +} +} +gkey(mp)->value=key->value;gkey(mp)->tt=key->tt; +luaC_barriert(L,t,key); +return gval(mp); +} +static const TValue*luaH_getnum(Table*t,int key){ +if(cast(unsigned int,key-1)sizearray)) +return&t->array[key-1]; +else{ +lua_Number nk=cast_num(key); +Node*n=hashnum(t,nk); +do{ +if(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk)) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +} +static const TValue*luaH_getstr(Table*t,TString*key){ +Node*n=hashstr(t,key); +do{ +if(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +static const TValue*luaH_get(Table*t,const TValue*key){ +switch(ttype(key)){ +case 0:return(&luaO_nilobject_); +case 4:return luaH_getstr(t,rawtsvalue(key)); +case 3:{ +int k; +lua_Number n=nvalue(key); +lua_number2int(k,n); +if(luai_numeq(cast_num(k),nvalue(key))) +return luaH_getnum(t,k); +} +default:{ +Node*n=mainposition(t,key); +do{ +if(luaO_rawequalObj(key2tval(n),key)) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +} +} +static TValue*luaH_set(lua_State*L,Table*t,const TValue*key){ +const TValue*p=luaH_get(t,key); +t->flags=0; +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +if(ttisnil(key))luaG_runerror(L,"table index is nil"); +else if(ttisnumber(key)&&luai_numisnan(nvalue(key))) +luaG_runerror(L,"table index is NaN"); +return newkey(L,t,key); +} +} +static TValue*luaH_setnum(lua_State*L,Table*t,int key){ +const TValue*p=luaH_getnum(t,key); +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +TValue k; +setnvalue(&k,cast_num(key)); +return newkey(L,t,&k); +} +} +static TValue*luaH_setstr(lua_State*L,Table*t,TString*key){ +const TValue*p=luaH_getstr(t,key); +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +TValue k; +setsvalue(L,&k,key); +return newkey(L,t,&k); +} +} +static int unbound_search(Table*t,unsigned int j){ +unsigned int i=j; +j++; +while(!ttisnil(luaH_getnum(t,j))){ +i=j; +j*=2; +if(j>cast(unsigned int,(INT_MAX-2))){ +i=1; +while(!ttisnil(luaH_getnum(t,i)))i++; +return i-1; +} +} +while(j-i>1){ +unsigned int m=(i+j)/2; +if(ttisnil(luaH_getnum(t,m)))j=m; +else i=m; +} +return i; +} +static int luaH_getn(Table*t){ +unsigned int j=t->sizearray; +if(j>0&&ttisnil(&t->array[j-1])){ +unsigned int i=0; +while(j-i>1){ +unsigned int m=(i+j)/2; +if(ttisnil(&t->array[m-1]))j=m; +else i=m; +} +return i; +} +else if(t->node==(&dummynode_)) +return j; +else return unbound_search(t,j); +} +#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g))) +#define white2gray(x)reset2bits((x)->gch.marked,0,1) +#define black2gray(x)resetbit((x)->gch.marked,2) +#define stringmark(s)reset2bits((s)->tsv.marked,0,1) +#define isfinalized(u)testbit((u)->marked,3) +#define markfinalized(u)l_setbit((u)->marked,3) +#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));} +#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));} +#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause) +static void removeentry(Node*n){ +if(iscollectable(gkey(n))) +setttype(gkey(n),(8+3)); +} +static void reallymarkobject(global_State*g,GCObject*o){ +white2gray(o); +switch(o->gch.tt){ +case 4:{ +return; +} +case 7:{ +Table*mt=gco2u(o)->metatable; +gray2black(o); +if(mt)markobject(g,mt); +markobject(g,gco2u(o)->env); +return; +} +case(8+2):{ +UpVal*uv=gco2uv(o); +markvalue(g,uv->v); +if(uv->v==&uv->u.value) +gray2black(o); +return; +} +case 6:{ +gco2cl(o)->c.gclist=g->gray; +g->gray=o; +break; +} +case 5:{ +gco2h(o)->gclist=g->gray; +g->gray=o; +break; +} +case 8:{ +gco2th(o)->gclist=g->gray; +g->gray=o; +break; +} +case(8+1):{ +gco2p(o)->gclist=g->gray; +g->gray=o; +break; +} +default:; +} +} +static void marktmu(global_State*g){ +GCObject*u=g->tmudata; +if(u){ +do{ +u=u->gch.next; +makewhite(g,u); +reallymarkobject(g,u); +}while(u!=g->tmudata); +} +} +static size_t luaC_separateudata(lua_State*L,int all){ +global_State*g=G(L); +size_t deadmem=0; +GCObject**p=&g->mainthread->next; +GCObject*curr; +while((curr=*p)!=NULL){ +if(!(iswhite(curr)||all)||isfinalized(gco2u(curr))) +p=&curr->gch.next; +else if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){ +markfinalized(gco2u(curr)); +p=&curr->gch.next; +} +else{ +deadmem+=sizeudata(gco2u(curr)); +markfinalized(gco2u(curr)); +*p=curr->gch.next; +if(g->tmudata==NULL) +g->tmudata=curr->gch.next=curr; +else{ +curr->gch.next=g->tmudata->gch.next; +g->tmudata->gch.next=curr; +g->tmudata=curr; +} +} +} +return deadmem; +} +static int traversetable(global_State*g,Table*h){ +int i; +int weakkey=0; +int weakvalue=0; +const TValue*mode; +if(h->metatable) +markobject(g,h->metatable); +mode=gfasttm(g,h->metatable,TM_MODE); +if(mode&&ttisstring(mode)){ +weakkey=(strchr(svalue(mode),'k')!=NULL); +weakvalue=(strchr(svalue(mode),'v')!=NULL); +if(weakkey||weakvalue){ +h->marked&=~(bitmask(3)|bitmask(4)); +h->marked|=cast_byte((weakkey<<3)| +(weakvalue<<4)); +h->gclist=g->weak; +g->weak=obj2gco(h); +} +} +if(weakkey&&weakvalue)return 1; +if(!weakvalue){ +i=h->sizearray; +while(i--) +markvalue(g,&h->array[i]); +} +i=sizenode(h); +while(i--){ +Node*n=gnode(h,i); +if(ttisnil(gval(n))) +removeentry(n); +else{ +if(!weakkey)markvalue(g,gkey(n)); +if(!weakvalue)markvalue(g,gval(n)); +} +} +return weakkey||weakvalue; +} +static void traverseproto(global_State*g,Proto*f){ +int i; +if(f->source)stringmark(f->source); +for(i=0;isizek;i++) +markvalue(g,&f->k[i]); +for(i=0;isizeupvalues;i++){ +if(f->upvalues[i]) +stringmark(f->upvalues[i]); +} +for(i=0;isizep;i++){ +if(f->p[i]) +markobject(g,f->p[i]); +} +for(i=0;isizelocvars;i++){ +if(f->locvars[i].varname) +stringmark(f->locvars[i].varname); +} +} +static void traverseclosure(global_State*g,Closure*cl){ +markobject(g,cl->c.env); +if(cl->c.isC){ +int i; +for(i=0;ic.nupvalues;i++) +markvalue(g,&cl->c.upvalue[i]); +} +else{ +int i; +markobject(g,cl->l.p); +for(i=0;il.nupvalues;i++) +markobject(g,cl->l.upvals[i]); +} +} +static void checkstacksizes(lua_State*L,StkId max){ +int ci_used=cast_int(L->ci-L->base_ci); +int s_used=cast_int(max-L->stack); +if(L->size_ci>20000) +return; +if(4*ci_usedsize_ci&&2*8size_ci) +luaD_reallocCI(L,L->size_ci/2); +condhardstacktests(luaD_reallocCI(L,ci_used+1)); +if(4*s_usedstacksize&& +2*((2*20)+5)stacksize) +luaD_reallocstack(L,L->stacksize/2); +condhardstacktests(luaD_reallocstack(L,s_used)); +} +static void traversestack(global_State*g,lua_State*l){ +StkId o,lim; +CallInfo*ci; +markvalue(g,gt(l)); +lim=l->top; +for(ci=l->base_ci;ci<=l->ci;ci++){ +if(limtop)lim=ci->top; +} +for(o=l->stack;otop;o++) +markvalue(g,o); +for(;o<=lim;o++) +setnilvalue(o); +checkstacksizes(l,lim); +} +static l_mem propagatemark(global_State*g){ +GCObject*o=g->gray; +gray2black(o); +switch(o->gch.tt){ +case 5:{ +Table*h=gco2h(o); +g->gray=h->gclist; +if(traversetable(g,h)) +black2gray(o); +return sizeof(Table)+sizeof(TValue)*h->sizearray+ +sizeof(Node)*sizenode(h); +} +case 6:{ +Closure*cl=gco2cl(o); +g->gray=cl->c.gclist; +traverseclosure(g,cl); +return(cl->c.isC)?sizeCclosure(cl->c.nupvalues): +sizeLclosure(cl->l.nupvalues); +} +case 8:{ +lua_State*th=gco2th(o); +g->gray=th->gclist; +th->gclist=g->grayagain; +g->grayagain=o; +black2gray(o); +traversestack(g,th); +return sizeof(lua_State)+sizeof(TValue)*th->stacksize+ +sizeof(CallInfo)*th->size_ci; +} +case(8+1):{ +Proto*p=gco2p(o); +g->gray=p->gclist; +traverseproto(g,p); +return sizeof(Proto)+sizeof(Instruction)*p->sizecode+ +sizeof(Proto*)*p->sizep+ +sizeof(TValue)*p->sizek+ +sizeof(int)*p->sizelineinfo+ +sizeof(LocVar)*p->sizelocvars+ +sizeof(TString*)*p->sizeupvalues; +} +default:return 0; +} +} +static size_t propagateall(global_State*g){ +size_t m=0; +while(g->gray)m+=propagatemark(g); +return m; +} +static int iscleared(const TValue*o,int iskey){ +if(!iscollectable(o))return 0; +if(ttisstring(o)){ +stringmark(rawtsvalue(o)); +return 0; +} +return iswhite(gcvalue(o))|| +(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o)))); +} +static void cleartable(GCObject*l){ +while(l){ +Table*h=gco2h(l); +int i=h->sizearray; +if(testbit(h->marked,4)){ +while(i--){ +TValue*o=&h->array[i]; +if(iscleared(o,0)) +setnilvalue(o); +} +} +i=sizenode(h); +while(i--){ +Node*n=gnode(h,i); +if(!ttisnil(gval(n))&& +(iscleared(key2tval(n),1)||iscleared(gval(n),0))){ +setnilvalue(gval(n)); +removeentry(n); +} +} +l=h->gclist; +} +} +static void freeobj(lua_State*L,GCObject*o){ +switch(o->gch.tt){ +case(8+1):luaF_freeproto(L,gco2p(o));break; +case 6:luaF_freeclosure(L,gco2cl(o));break; +case(8+2):luaF_freeupval(L,gco2uv(o));break; +case 5:luaH_free(L,gco2h(o));break; +case 8:{ +luaE_freethread(L,gco2th(o)); +break; +} +case 4:{ +G(L)->strt.nuse--; +luaM_freemem(L,o,sizestring(gco2ts(o))); +break; +} +case 7:{ +luaM_freemem(L,o,sizeudata(gco2u(o))); +break; +} +default:; +} +} +#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2)) +static GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){ +GCObject*curr; +global_State*g=G(L); +int deadmask=otherwhite(g); +while((curr=*p)!=NULL&&count-->0){ +if(curr->gch.tt==8) +sweepwholelist(L,&gco2th(curr)->openupval); +if((curr->gch.marked^bit2mask(0,1))&deadmask){ +makewhite(g,curr); +p=&curr->gch.next; +} +else{ +*p=curr->gch.next; +if(curr==g->rootgc) +g->rootgc=curr->gch.next; +freeobj(L,curr); +} +} +return p; +} +static void checkSizes(lua_State*L){ +global_State*g=G(L); +if(g->strt.nusestrt.size/4)&& +g->strt.size>32*2) +luaS_resize(L,g->strt.size/2); +if(luaZ_sizebuffer(&g->buff)>32*2){ +size_t newsize=luaZ_sizebuffer(&g->buff)/2; +luaZ_resizebuffer(L,&g->buff,newsize); +} +} +static void GCTM(lua_State*L){ +global_State*g=G(L); +GCObject*o=g->tmudata->gch.next; +Udata*udata=rawgco2u(o); +const TValue*tm; +if(o==g->tmudata) +g->tmudata=NULL; +else +g->tmudata->gch.next=udata->uv.next; +udata->uv.next=g->mainthread->next; +g->mainthread->next=o; +makewhite(g,o); +tm=fasttm(L,udata->uv.metatable,TM_GC); +if(tm!=NULL){ +lu_byte oldah=L->allowhook; +lu_mem oldt=g->GCthreshold; +L->allowhook=0; +g->GCthreshold=2*g->totalbytes; +setobj(L,L->top,tm); +setuvalue(L,L->top+1,udata); +L->top+=2; +luaD_call(L,L->top-2,0); +L->allowhook=oldah; +g->GCthreshold=oldt; +} +} +static void luaC_callGCTM(lua_State*L){ +while(G(L)->tmudata) +GCTM(L); +} +static void luaC_freeall(lua_State*L){ +global_State*g=G(L); +int i; +g->currentwhite=bit2mask(0,1)|bitmask(6); +sweepwholelist(L,&g->rootgc); +for(i=0;istrt.size;i++) +sweepwholelist(L,&g->strt.hash[i]); +} +static void markmt(global_State*g){ +int i; +for(i=0;i<(8+1);i++) +if(g->mt[i])markobject(g,g->mt[i]); +} +static void markroot(lua_State*L){ +global_State*g=G(L); +g->gray=NULL; +g->grayagain=NULL; +g->weak=NULL; +markobject(g,g->mainthread); +markvalue(g,gt(g->mainthread)); +markvalue(g,registry(L)); +markmt(g); +g->gcstate=1; +} +static void remarkupvals(global_State*g){ +UpVal*uv; +for(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){ +if(isgray(obj2gco(uv))) +markvalue(g,uv->v); +} +} +static void atomic(lua_State*L){ +global_State*g=G(L); +size_t udsize; +remarkupvals(g); +propagateall(g); +g->gray=g->weak; +g->weak=NULL; +markobject(g,L); +markmt(g); +propagateall(g); +g->gray=g->grayagain; +g->grayagain=NULL; +propagateall(g); +udsize=luaC_separateudata(L,0); +marktmu(g); +udsize+=propagateall(g); +cleartable(g->weak); +g->currentwhite=cast_byte(otherwhite(g)); +g->sweepstrgc=0; +g->sweepgc=&g->rootgc; +g->gcstate=2; +g->estimate=g->totalbytes-udsize; +} +static l_mem singlestep(lua_State*L){ +global_State*g=G(L); +switch(g->gcstate){ +case 0:{ +markroot(L); +return 0; +} +case 1:{ +if(g->gray) +return propagatemark(g); +else{ +atomic(L); +return 0; +} +} +case 2:{ +lu_mem old=g->totalbytes; +sweepwholelist(L,&g->strt.hash[g->sweepstrgc++]); +if(g->sweepstrgc>=g->strt.size) +g->gcstate=3; +g->estimate-=old-g->totalbytes; +return 10; +} +case 3:{ +lu_mem old=g->totalbytes; +g->sweepgc=sweeplist(L,g->sweepgc,40); +if(*g->sweepgc==NULL){ +checkSizes(L); +g->gcstate=4; +} +g->estimate-=old-g->totalbytes; +return 40*10; +} +case 4:{ +if(g->tmudata){ +GCTM(L); +if(g->estimate>100) +g->estimate-=100; +return 100; +} +else{ +g->gcstate=0; +g->gcdept=0; +return 0; +} +} +default:return 0; +} +} +static void luaC_step(lua_State*L){ +global_State*g=G(L); +l_mem lim=(1024u/100)*g->gcstepmul; +if(lim==0) +lim=(((lu_mem)(~(lu_mem)0)-2)-1)/2; +g->gcdept+=g->totalbytes-g->GCthreshold; +do{ +lim-=singlestep(L); +if(g->gcstate==0) +break; +}while(lim>0); +if(g->gcstate!=0){ +if(g->gcdept<1024u) +g->GCthreshold=g->totalbytes+1024u; +else{ +g->gcdept-=1024u; +g->GCthreshold=g->totalbytes; +} +} +else{ +setthreshold(g); +} +} +static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){ +global_State*g=G(L); +if(g->gcstate==1) +reallymarkobject(g,v); +else +makewhite(g,o); +} +static void luaC_barrierback(lua_State*L,Table*t){ +global_State*g=G(L); +GCObject*o=obj2gco(t); +black2gray(o); +t->gclist=g->grayagain; +g->grayagain=o; +} +static void luaC_link(lua_State*L,GCObject*o,lu_byte tt){ +global_State*g=G(L); +o->gch.next=g->rootgc; +g->rootgc=o; +o->gch.marked=luaC_white(g); +o->gch.tt=tt; +} +static void luaC_linkupval(lua_State*L,UpVal*uv){ +global_State*g=G(L); +GCObject*o=obj2gco(uv); +o->gch.next=g->rootgc; +g->rootgc=o; +if(isgray(o)){ +if(g->gcstate==1){ +gray2black(o); +luaC_barrier(L,uv,uv->v); +} +else{ +makewhite(g,o); +} +} +} +typedef union{ +lua_Number r; +TString*ts; +}SemInfo; +typedef struct Token{ +int token; +SemInfo seminfo; +}Token; +typedef struct LexState{ +int current; +int linenumber; +int lastline; +Token t; +Token lookahead; +struct FuncState*fs; +struct lua_State*L; +ZIO*z; +Mbuffer*buff; +TString*source; +char decpoint; +}LexState; +static void luaX_init(lua_State*L); +static void luaX_lexerror(LexState*ls,const char*msg,int token); +#define state_size(x)(sizeof(x)+0) +#define fromstate(l)(cast(lu_byte*,(l))-0) +#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0)) +typedef struct LG{ +lua_State l; +global_State g; +}LG; +static void stack_init(lua_State*L1,lua_State*L){ +L1->base_ci=luaM_newvector(L,8,CallInfo); +L1->ci=L1->base_ci; +L1->size_ci=8; +L1->end_ci=L1->base_ci+L1->size_ci-1; +L1->stack=luaM_newvector(L,(2*20)+5,TValue); +L1->stacksize=(2*20)+5; +L1->top=L1->stack; +L1->stack_last=L1->stack+(L1->stacksize-5)-1; +L1->ci->func=L1->top; +setnilvalue(L1->top++); +L1->base=L1->ci->base=L1->top; +L1->ci->top=L1->top+20; +} +static void freestack(lua_State*L,lua_State*L1){ +luaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo); +luaM_freearray(L,L1->stack,L1->stacksize,TValue); +} +static void f_luaopen(lua_State*L,void*ud){ +global_State*g=G(L); +UNUSED(ud); +stack_init(L,L); +sethvalue(L,gt(L),luaH_new(L,0,2)); +sethvalue(L,registry(L),luaH_new(L,0,2)); +luaS_resize(L,32); +luaT_init(L); +luaX_init(L); +luaS_fix(luaS_newliteral(L,"not enough memory")); +g->GCthreshold=4*g->totalbytes; +} +static void preinit_state(lua_State*L,global_State*g){ +G(L)=g; +L->stack=NULL; +L->stacksize=0; +L->errorJmp=NULL; +L->hook=NULL; +L->hookmask=0; +L->basehookcount=0; +L->allowhook=1; +resethookcount(L); +L->openupval=NULL; +L->size_ci=0; +L->nCcalls=L->baseCcalls=0; +L->status=0; +L->base_ci=L->ci=NULL; +L->savedpc=NULL; +L->errfunc=0; +setnilvalue(gt(L)); +} +static void close_state(lua_State*L){ +global_State*g=G(L); +luaF_close(L,L->stack); +luaC_freeall(L); +luaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*); +luaZ_freebuffer(L,&g->buff); +freestack(L,L); +(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0); +} +static void luaE_freethread(lua_State*L,lua_State*L1){ +luaF_close(L1,L1->stack); +freestack(L,L1); +luaM_freemem(L,fromstate(L1),state_size(lua_State)); +} +static lua_State*lua_newstate(lua_Alloc f,void*ud){ +int i; +lua_State*L; +global_State*g; +void*l=(*f)(ud,NULL,0,state_size(LG)); +if(l==NULL)return NULL; +L=tostate(l); +g=&((LG*)L)->g; +L->next=NULL; +L->tt=8; +g->currentwhite=bit2mask(0,5); +L->marked=luaC_white(g); +set2bits(L->marked,5,6); +preinit_state(L,g); +g->frealloc=f; +g->ud=ud; +g->mainthread=L; +g->uvhead.u.l.prev=&g->uvhead; +g->uvhead.u.l.next=&g->uvhead; +g->GCthreshold=0; +g->strt.size=0; +g->strt.nuse=0; +g->strt.hash=NULL; +setnilvalue(registry(L)); +luaZ_initbuffer(L,&g->buff); +g->panic=NULL; +g->gcstate=0; +g->rootgc=obj2gco(L); +g->sweepstrgc=0; +g->sweepgc=&g->rootgc; +g->gray=NULL; +g->grayagain=NULL; +g->weak=NULL; +g->tmudata=NULL; +g->totalbytes=sizeof(LG); +g->gcpause=200; +g->gcstepmul=200; +g->gcdept=0; +for(i=0;i<(8+1);i++)g->mt[i]=NULL; +if(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){ +close_state(L); +L=NULL; +} +else +{} +return L; +} +static void callallgcTM(lua_State*L,void*ud){ +UNUSED(ud); +luaC_callGCTM(L); +} +static void lua_close(lua_State*L){ +L=G(L)->mainthread; +luaF_close(L,L->stack); +luaC_separateudata(L,1); +L->errfunc=0; +do{ +L->ci=L->base_ci; +L->base=L->top=L->ci->base; +L->nCcalls=L->baseCcalls=0; +}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0); +close_state(L); +} +#define getcode(fs,e)((fs)->f->code[(e)->u.s.info]) +#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1)) +#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1)) +static int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx); +static int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C); +static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults); +static void luaK_patchtohere(FuncState*fs,int list); +static void luaK_concat(FuncState*fs,int*l1,int l2); +static int currentpc(lua_State*L,CallInfo*ci){ +if(!isLua(ci))return-1; +if(ci==L->ci) +ci->savedpc=L->savedpc; +return pcRel(ci->savedpc,ci_func(ci)->l.p); +} +static int currentline(lua_State*L,CallInfo*ci){ +int pc=currentpc(L,ci); +if(pc<0) +return-1; +else +return getline_(ci_func(ci)->l.p,pc); +} +static int lua_getstack(lua_State*L,int level,lua_Debug*ar){ +int status; +CallInfo*ci; +for(ci=L->ci;level>0&&ci>L->base_ci;ci--){ +level--; +if(f_isLua(ci)) +level-=ci->tailcalls; +} +if(level==0&&ci>L->base_ci){ +status=1; +ar->i_ci=cast_int(ci-L->base_ci); +} +else if(level<0){ +status=1; +ar->i_ci=0; +} +else status=0; +return status; +} +static Proto*getluaproto(CallInfo*ci){ +return(isLua(ci)?ci_func(ci)->l.p:NULL); +} +static void funcinfo(lua_Debug*ar,Closure*cl){ +if(cl->c.isC){ +ar->source="=[C]"; +ar->linedefined=-1; +ar->lastlinedefined=-1; +ar->what="C"; +} +else{ +ar->source=getstr(cl->l.p->source); +ar->linedefined=cl->l.p->linedefined; +ar->lastlinedefined=cl->l.p->lastlinedefined; +ar->what=(ar->linedefined==0)?"main":"Lua"; +} +luaO_chunkid(ar->short_src,ar->source,60); +} +static void info_tailcall(lua_Debug*ar){ +ar->name=ar->namewhat=""; +ar->what="tail"; +ar->lastlinedefined=ar->linedefined=ar->currentline=-1; +ar->source="=(tail call)"; +luaO_chunkid(ar->short_src,ar->source,60); +ar->nups=0; +} +static void collectvalidlines(lua_State*L,Closure*f){ +if(f==NULL||f->c.isC){ +setnilvalue(L->top); +} +else{ +Table*t=luaH_new(L,0,0); +int*lineinfo=f->l.p->lineinfo; +int i; +for(i=0;il.p->sizelineinfo;i++) +setbvalue(luaH_setnum(L,t,lineinfo[i]),1); +sethvalue(L,L->top,t); +} +incr_top(L); +} +static int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar, +Closure*f,CallInfo*ci){ +int status=1; +if(f==NULL){ +info_tailcall(ar); +return status; +} +for(;*what;what++){ +switch(*what){ +case'S':{ +funcinfo(ar,f); +break; +} +case'l':{ +ar->currentline=(ci)?currentline(L,ci):-1; +break; +} +case'u':{ +ar->nups=f->c.nupvalues; +break; +} +case'n':{ +ar->namewhat=(ci)?NULL:NULL; +if(ar->namewhat==NULL){ +ar->namewhat=""; +ar->name=NULL; +} +break; +} +case'L': +case'f': +break; +default:status=0; +} +} +return status; +} +static int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){ +int status; +Closure*f=NULL; +CallInfo*ci=NULL; +if(*what=='>'){ +StkId func=L->top-1; +luai_apicheck(L,ttisfunction(func)); +what++; +f=clvalue(func); +L->top--; +} +else if(ar->i_ci!=0){ +ci=L->base_ci+ar->i_ci; +f=clvalue(ci->func); +} +status=auxgetinfo(L,what,ar,f,ci); +if(strchr(what,'f')){ +if(f==NULL)setnilvalue(L->top); +else setclvalue(L,L->top,f); +incr_top(L); +} +if(strchr(what,'L')) +collectvalidlines(L,f); +return status; +} +static int isinstack(CallInfo*ci,const TValue*o){ +StkId p; +for(p=ci->base;ptop;p++) +if(o==p)return 1; +return 0; +} +static void luaG_typeerror(lua_State*L,const TValue*o,const char*op){ +const char*name=NULL; +const char*t=luaT_typenames[ttype(o)]; +const char*kind=(isinstack(L->ci,o))? +NULL: +NULL; +if(kind) +luaG_runerror(L,"attempt to %s %s "LUA_QL("%s")" (a %s value)", +op,kind,name,t); +else +luaG_runerror(L,"attempt to %s a %s value",op,t); +} +static void luaG_concaterror(lua_State*L,StkId p1,StkId p2){ +if(ttisstring(p1)||ttisnumber(p1))p1=p2; +luaG_typeerror(L,p1,"concatenate"); +} +static void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){ +TValue temp; +if(luaV_tonumber(p1,&temp)==NULL) +p2=p1; +luaG_typeerror(L,p2,"perform arithmetic on"); +} +static int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){ +const char*t1=luaT_typenames[ttype(p1)]; +const char*t2=luaT_typenames[ttype(p2)]; +if(t1[2]==t2[2]) +luaG_runerror(L,"attempt to compare two %s values",t1); +else +luaG_runerror(L,"attempt to compare %s with %s",t1,t2); +return 0; +} +static void addinfo(lua_State*L,const char*msg){ +CallInfo*ci=L->ci; +if(isLua(ci)){ +char buff[60]; +int line=currentline(L,ci); +luaO_chunkid(buff,getstr(getluaproto(ci)->source),60); +luaO_pushfstring(L,"%s:%d: %s",buff,line,msg); +} +} +static void luaG_errormsg(lua_State*L){ +if(L->errfunc!=0){ +StkId errfunc=restorestack(L,L->errfunc); +if(!ttisfunction(errfunc))luaD_throw(L,5); +setobj(L,L->top,L->top-1); +setobj(L,L->top-1,errfunc); +incr_top(L); +luaD_call(L,L->top-2,1); +} +luaD_throw(L,2); +} +static void luaG_runerror(lua_State*L,const char*fmt,...){ +va_list argp; +va_start(argp,fmt); +addinfo(L,luaO_pushvfstring(L,fmt,argp)); +va_end(argp); +luaG_errormsg(L); +} +static int luaZ_fill(ZIO*z){ +size_t size; +lua_State*L=z->L; +const char*buff; +buff=z->reader(L,z->data,&size); +if(buff==NULL||size==0)return(-1); +z->n=size-1; +z->p=buff; +return char2int(*(z->p++)); +} +static void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){ +z->L=L; +z->reader=reader; +z->data=data; +z->n=0; +z->p=NULL; +} +static char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){ +if(n>buff->buffsize){ +if(n<32)n=32; +luaZ_resizebuffer(L,buff,n); +} +return buff->buffer; +} +#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m)) +static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={ +opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgK,OpArgN,iABx) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgU,OpArgN,iABC) +,opmode(0,1,OpArgK,OpArgN,iABx) +,opmode(0,1,OpArgR,OpArgK,iABC) +,opmode(0,0,OpArgK,OpArgN,iABx) +,opmode(0,0,OpArgU,OpArgN,iABC) +,opmode(0,0,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgR,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgR,iABC) +,opmode(0,0,OpArgR,OpArgN,iAsBx) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,1,OpArgR,OpArgU,iABC) +,opmode(1,1,OpArgR,OpArgU,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,0,OpArgU,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iAsBx) +,opmode(0,1,OpArgR,OpArgN,iAsBx) +,opmode(1,0,OpArgN,OpArgU,iABC) +,opmode(0,0,OpArgU,OpArgU,iABC) +,opmode(0,0,OpArgN,OpArgN,iABC) +,opmode(0,1,OpArgU,OpArgN,iABx) +,opmode(0,1,OpArgU,OpArgN,iABC) +}; +#define next(ls)(ls->current=zgetc(ls->z)) +#define currIsNewline(ls)(ls->current=='\n'||ls->current=='\r') +static const char*const luaX_tokens[]={ +"and","break","do","else","elseif", +"end","false","for","function","if", +"in","local","nil","not","or","repeat", +"return","then","true","until","while", +"..","...","==",">=","<=","~=", +"","","","", +NULL +}; +#define save_and_next(ls)(save(ls,ls->current),next(ls)) +static void save(LexState*ls,int c){ +Mbuffer*b=ls->buff; +if(b->n+1>b->buffsize){ +size_t newsize; +if(b->buffsize>=((size_t)(~(size_t)0)-2)/2) +luaX_lexerror(ls,"lexical element too long",0); +newsize=b->buffsize*2; +luaZ_resizebuffer(ls->L,b,newsize); +} +b->buffer[b->n++]=cast(char,c); +} +static void luaX_init(lua_State*L){ +int i; +for(i=0;i<(cast(int,TK_WHILE-257+1));i++){ +TString*ts=luaS_new(L,luaX_tokens[i]); +luaS_fix(ts); +ts->tsv.reserved=cast_byte(i+1); +} +} +static const char*luaX_token2str(LexState*ls,int token){ +if(token<257){ +return(iscntrl(token))?luaO_pushfstring(ls->L,"char(%d)",token): +luaO_pushfstring(ls->L,"%c",token); +} +else +return luaX_tokens[token-257]; +} +static const char*txtToken(LexState*ls,int token){ +switch(token){ +case TK_NAME: +case TK_STRING: +case TK_NUMBER: +save(ls,'\0'); +return luaZ_buffer(ls->buff); +default: +return luaX_token2str(ls,token); +} +} +static void luaX_lexerror(LexState*ls,const char*msg,int token){ +char buff[80]; +luaO_chunkid(buff,getstr(ls->source),80); +msg=luaO_pushfstring(ls->L,"%s:%d: %s",buff,ls->linenumber,msg); +if(token) +luaO_pushfstring(ls->L,"%s near "LUA_QL("%s"),msg,txtToken(ls,token)); +luaD_throw(ls->L,3); +} +static void luaX_syntaxerror(LexState*ls,const char*msg){ +luaX_lexerror(ls,msg,ls->t.token); +} +static TString*luaX_newstring(LexState*ls,const char*str,size_t l){ +lua_State*L=ls->L; +TString*ts=luaS_newlstr(L,str,l); +TValue*o=luaH_setstr(L,ls->fs->h,ts); +if(ttisnil(o)){ +setbvalue(o,1); +luaC_checkGC(L); +} +return ts; +} +static void inclinenumber(LexState*ls){ +int old=ls->current; +next(ls); +if(currIsNewline(ls)&&ls->current!=old) +next(ls); +if(++ls->linenumber>=(INT_MAX-2)) +luaX_syntaxerror(ls,"chunk has too many lines"); +} +static void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){ +ls->decpoint='.'; +ls->L=L; +ls->lookahead.token=TK_EOS; +ls->z=z; +ls->fs=NULL; +ls->linenumber=1; +ls->lastline=1; +ls->source=source; +luaZ_resizebuffer(ls->L,ls->buff,32); +next(ls); +} +static int check_next(LexState*ls,const char*set){ +if(!strchr(set,ls->current)) +return 0; +save_and_next(ls); +return 1; +} +static void buffreplace(LexState*ls,char from,char to){ +size_t n=luaZ_bufflen(ls->buff); +char*p=luaZ_buffer(ls->buff); +while(n--) +if(p[n]==from)p[n]=to; +} +static void read_numeral(LexState*ls,SemInfo*seminfo){ +do{ +save_and_next(ls); +}while(isdigit(ls->current)||ls->current=='.'); +if(check_next(ls,"Ee")) +check_next(ls,"+-"); +while(isalnum(ls->current)||ls->current=='_') +save_and_next(ls); +save(ls,'\0'); +buffreplace(ls,'.',ls->decpoint); +if(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r)) +luaX_lexerror(ls,"malformed number",TK_NUMBER); +} +static int skip_sep(LexState*ls){ +int count=0; +int s=ls->current; +save_and_next(ls); +while(ls->current=='='){ +save_and_next(ls); +count++; +} +return(ls->current==s)?count:(-count)-1; +} +static void read_long_string(LexState*ls,SemInfo*seminfo,int sep){ +int cont=0; +(void)(cont); +save_and_next(ls); +if(currIsNewline(ls)) +inclinenumber(ls); +for(;;){ +switch(ls->current){ +case(-1): +luaX_lexerror(ls,(seminfo)?"unfinished long string": +"unfinished long comment",TK_EOS); +break; +case']':{ +if(skip_sep(ls)==sep){ +save_and_next(ls); +goto endloop; +} +break; +} +case'\n': +case'\r':{ +save(ls,'\n'); +inclinenumber(ls); +if(!seminfo)luaZ_resetbuffer(ls->buff); +break; +} +default:{ +if(seminfo)save_and_next(ls); +else next(ls); +} +} +}endloop: +if(seminfo) +seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep), +luaZ_bufflen(ls->buff)-2*(2+sep)); +} +static void read_string(LexState*ls,int del,SemInfo*seminfo){ +save_and_next(ls); +while(ls->current!=del){ +switch(ls->current){ +case(-1): +luaX_lexerror(ls,"unfinished string",TK_EOS); +continue; +case'\n': +case'\r': +luaX_lexerror(ls,"unfinished string",TK_STRING); +continue; +case'\\':{ +int c; +next(ls); +switch(ls->current){ +case'a':c='\a';break; +case'b':c='\b';break; +case'f':c='\f';break; +case'n':c='\n';break; +case'r':c='\r';break; +case't':c='\t';break; +case'v':c='\v';break; +case'\n': +case'\r':save(ls,'\n');inclinenumber(ls);continue; +case(-1):continue; +default:{ +if(!isdigit(ls->current)) +save_and_next(ls); +else{ +int i=0; +c=0; +do{ +c=10*c+(ls->current-'0'); +next(ls); +}while(++i<3&&isdigit(ls->current)); +if(c>UCHAR_MAX) +luaX_lexerror(ls,"escape sequence too large",TK_STRING); +save(ls,c); +} +continue; +} +} +save(ls,c); +next(ls); +continue; +} +default: +save_and_next(ls); +} +} +save_and_next(ls); +seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1, +luaZ_bufflen(ls->buff)-2); +} +static int llex(LexState*ls,SemInfo*seminfo){ +luaZ_resetbuffer(ls->buff); +for(;;){ +switch(ls->current){ +case'\n': +case'\r':{ +inclinenumber(ls); +continue; +} +case'-':{ +next(ls); +if(ls->current!='-')return'-'; +next(ls); +if(ls->current=='['){ +int sep=skip_sep(ls); +luaZ_resetbuffer(ls->buff); +if(sep>=0){ +read_long_string(ls,NULL,sep); +luaZ_resetbuffer(ls->buff); +continue; +} +} +while(!currIsNewline(ls)&&ls->current!=(-1)) +next(ls); +continue; +} +case'[':{ +int sep=skip_sep(ls); +if(sep>=0){ +read_long_string(ls,seminfo,sep); +return TK_STRING; +} +else if(sep==-1)return'['; +else luaX_lexerror(ls,"invalid long string delimiter",TK_STRING); +} +case'=':{ +next(ls); +if(ls->current!='=')return'='; +else{next(ls);return TK_EQ;} +} +case'<':{ +next(ls); +if(ls->current!='=')return'<'; +else{next(ls);return TK_LE;} +} +case'>':{ +next(ls); +if(ls->current!='=')return'>'; +else{next(ls);return TK_GE;} +} +case'~':{ +next(ls); +if(ls->current!='=')return'~'; +else{next(ls);return TK_NE;} +} +case'"': +case'\'':{ +read_string(ls,ls->current,seminfo); +return TK_STRING; +} +case'.':{ +save_and_next(ls); +if(check_next(ls,".")){ +if(check_next(ls,".")) +return TK_DOTS; +else return TK_CONCAT; +} +else if(!isdigit(ls->current))return'.'; +else{ +read_numeral(ls,seminfo); +return TK_NUMBER; +} +} +case(-1):{ +return TK_EOS; +} +default:{ +if(isspace(ls->current)){ +next(ls); +continue; +} +else if(isdigit(ls->current)){ +read_numeral(ls,seminfo); +return TK_NUMBER; +} +else if(isalpha(ls->current)||ls->current=='_'){ +TString*ts; +do{ +save_and_next(ls); +}while(isalnum(ls->current)||ls->current=='_'); +ts=luaX_newstring(ls,luaZ_buffer(ls->buff), +luaZ_bufflen(ls->buff)); +if(ts->tsv.reserved>0) +return ts->tsv.reserved-1+257; +else{ +seminfo->ts=ts; +return TK_NAME; +} +} +else{ +int c=ls->current; +next(ls); +return c; +} +} +} +} +} +static void luaX_next(LexState*ls){ +ls->lastline=ls->linenumber; +if(ls->lookahead.token!=TK_EOS){ +ls->t=ls->lookahead; +ls->lookahead.token=TK_EOS; +} +else +ls->t.token=llex(ls,&ls->t.seminfo); +} +static void luaX_lookahead(LexState*ls){ +ls->lookahead.token=llex(ls,&ls->lookahead.seminfo); +} +#define hasjumps(e)((e)->t!=(e)->f) +static int isnumeral(expdesc*e){ +return(e->k==VKNUM&&e->t==(-1)&&e->f==(-1)); +} +static void luaK_nil(FuncState*fs,int from,int n){ +Instruction*previous; +if(fs->pc>fs->lasttarget){ +if(fs->pc==0){ +if(from>=fs->nactvar) +return; +} +else{ +previous=&fs->f->code[fs->pc-1]; +if(GET_OPCODE(*previous)==OP_LOADNIL){ +int pfrom=GETARG_A(*previous); +int pto=GETARG_B(*previous); +if(pfrom<=from&&from<=pto+1){ +if(from+n-1>pto) +SETARG_B(*previous,from+n-1); +return; +} +} +} +} +luaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0); +} +static int luaK_jump(FuncState*fs){ +int jpc=fs->jpc; +int j; +fs->jpc=(-1); +j=luaK_codeAsBx(fs,OP_JMP,0,(-1)); +luaK_concat(fs,&j,jpc); +return j; +} +static void luaK_ret(FuncState*fs,int first,int nret){ +luaK_codeABC(fs,OP_RETURN,first,nret+1,0); +} +static int condjump(FuncState*fs,OpCode op,int A,int B,int C){ +luaK_codeABC(fs,op,A,B,C); +return luaK_jump(fs); +} +static void fixjump(FuncState*fs,int pc,int dest){ +Instruction*jmp=&fs->f->code[pc]; +int offset=dest-(pc+1); +if(abs(offset)>(((1<<(9+9))-1)>>1)) +luaX_syntaxerror(fs->ls,"control structure too long"); +SETARG_sBx(*jmp,offset); +} +static int luaK_getlabel(FuncState*fs){ +fs->lasttarget=fs->pc; +return fs->pc; +} +static int getjump(FuncState*fs,int pc){ +int offset=GETARG_sBx(fs->f->code[pc]); +if(offset==(-1)) +return(-1); +else +return(pc+1)+offset; +} +static Instruction*getjumpcontrol(FuncState*fs,int pc){ +Instruction*pi=&fs->f->code[pc]; +if(pc>=1&&testTMode(GET_OPCODE(*(pi-1)))) +return pi-1; +else +return pi; +} +static int need_value(FuncState*fs,int list){ +for(;list!=(-1);list=getjump(fs,list)){ +Instruction i=*getjumpcontrol(fs,list); +if(GET_OPCODE(i)!=OP_TESTSET)return 1; +} +return 0; +} +static int patchtestreg(FuncState*fs,int node,int reg){ +Instruction*i=getjumpcontrol(fs,node); +if(GET_OPCODE(*i)!=OP_TESTSET) +return 0; +if(reg!=((1<<8)-1)&®!=GETARG_B(*i)) +SETARG_A(*i,reg); +else +*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i)); +return 1; +} +static void removevalues(FuncState*fs,int list){ +for(;list!=(-1);list=getjump(fs,list)) +patchtestreg(fs,list,((1<<8)-1)); +} +static void patchlistaux(FuncState*fs,int list,int vtarget,int reg, +int dtarget){ +while(list!=(-1)){ +int next=getjump(fs,list); +if(patchtestreg(fs,list,reg)) +fixjump(fs,list,vtarget); +else +fixjump(fs,list,dtarget); +list=next; +} +} +static void dischargejpc(FuncState*fs){ +patchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc); +fs->jpc=(-1); +} +static void luaK_patchlist(FuncState*fs,int list,int target){ +if(target==fs->pc) +luaK_patchtohere(fs,list); +else{ +patchlistaux(fs,list,target,((1<<8)-1),target); +} +} +static void luaK_patchtohere(FuncState*fs,int list){ +luaK_getlabel(fs); +luaK_concat(fs,&fs->jpc,list); +} +static void luaK_concat(FuncState*fs,int*l1,int l2){ +if(l2==(-1))return; +else if(*l1==(-1)) +*l1=l2; +else{ +int list=*l1; +int next; +while((next=getjump(fs,list))!=(-1)) +list=next; +fixjump(fs,list,l2); +} +} +static void luaK_checkstack(FuncState*fs,int n){ +int newstack=fs->freereg+n; +if(newstack>fs->f->maxstacksize){ +if(newstack>=250) +luaX_syntaxerror(fs->ls,"function or expression too complex"); +fs->f->maxstacksize=cast_byte(newstack); +} +} +static void luaK_reserveregs(FuncState*fs,int n){ +luaK_checkstack(fs,n); +fs->freereg+=n; +} +static void freereg(FuncState*fs,int reg){ +if(!ISK(reg)&®>=fs->nactvar){ +fs->freereg--; +} +} +static void freeexp(FuncState*fs,expdesc*e){ +if(e->k==VNONRELOC) +freereg(fs,e->u.s.info); +} +static int addk(FuncState*fs,TValue*k,TValue*v){ +lua_State*L=fs->L; +TValue*idx=luaH_set(L,fs->h,k); +Proto*f=fs->f; +int oldsize=f->sizek; +if(ttisnumber(idx)){ +return cast_int(nvalue(idx)); +} +else{ +setnvalue(idx,cast_num(fs->nk)); +luaM_growvector(L,f->k,fs->nk,f->sizek,TValue, +((1<<(9+9))-1),"constant table overflow"); +while(oldsizesizek)setnilvalue(&f->k[oldsize++]); +setobj(L,&f->k[fs->nk],v); +luaC_barrier(L,f,v); +return fs->nk++; +} +} +static int luaK_stringK(FuncState*fs,TString*s){ +TValue o; +setsvalue(fs->L,&o,s); +return addk(fs,&o,&o); +} +static int luaK_numberK(FuncState*fs,lua_Number r){ +TValue o; +setnvalue(&o,r); +return addk(fs,&o,&o); +} +static int boolK(FuncState*fs,int b){ +TValue o; +setbvalue(&o,b); +return addk(fs,&o,&o); +} +static int nilK(FuncState*fs){ +TValue k,v; +setnilvalue(&v); +sethvalue(fs->L,&k,fs->h); +return addk(fs,&k,&v); +} +static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){ +if(e->k==VCALL){ +SETARG_C(getcode(fs,e),nresults+1); +} +else if(e->k==VVARARG){ +SETARG_B(getcode(fs,e),nresults+1); +SETARG_A(getcode(fs,e),fs->freereg); +luaK_reserveregs(fs,1); +} +} +static void luaK_setoneret(FuncState*fs,expdesc*e){ +if(e->k==VCALL){ +e->k=VNONRELOC; +e->u.s.info=GETARG_A(getcode(fs,e)); +} +else if(e->k==VVARARG){ +SETARG_B(getcode(fs,e),2); +e->k=VRELOCABLE; +} +} +static void luaK_dischargevars(FuncState*fs,expdesc*e){ +switch(e->k){ +case VLOCAL:{ +e->k=VNONRELOC; +break; +} +case VUPVAL:{ +e->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0); +e->k=VRELOCABLE; +break; +} +case VGLOBAL:{ +e->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info); +e->k=VRELOCABLE; +break; +} +case VINDEXED:{ +freereg(fs,e->u.s.aux); +freereg(fs,e->u.s.info); +e->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux); +e->k=VRELOCABLE; +break; +} +case VVARARG: +case VCALL:{ +luaK_setoneret(fs,e); +break; +} +default:break; +} +} +static int code_label(FuncState*fs,int A,int b,int jump){ +luaK_getlabel(fs); +return luaK_codeABC(fs,OP_LOADBOOL,A,b,jump); +} +static void discharge2reg(FuncState*fs,expdesc*e,int reg){ +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:{ +luaK_nil(fs,reg,1); +break; +} +case VFALSE:case VTRUE:{ +luaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0); +break; +} +case VK:{ +luaK_codeABx(fs,OP_LOADK,reg,e->u.s.info); +break; +} +case VKNUM:{ +luaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval)); +break; +} +case VRELOCABLE:{ +Instruction*pc=&getcode(fs,e); +SETARG_A(*pc,reg); +break; +} +case VNONRELOC:{ +if(reg!=e->u.s.info) +luaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0); +break; +} +default:{ +return; +} +} +e->u.s.info=reg; +e->k=VNONRELOC; +} +static void discharge2anyreg(FuncState*fs,expdesc*e){ +if(e->k!=VNONRELOC){ +luaK_reserveregs(fs,1); +discharge2reg(fs,e,fs->freereg-1); +} +} +static void exp2reg(FuncState*fs,expdesc*e,int reg){ +discharge2reg(fs,e,reg); +if(e->k==VJMP) +luaK_concat(fs,&e->t,e->u.s.info); +if(hasjumps(e)){ +int final; +int p_f=(-1); +int p_t=(-1); +if(need_value(fs,e->t)||need_value(fs,e->f)){ +int fj=(e->k==VJMP)?(-1):luaK_jump(fs); +p_f=code_label(fs,reg,0,1); +p_t=code_label(fs,reg,1,0); +luaK_patchtohere(fs,fj); +} +final=luaK_getlabel(fs); +patchlistaux(fs,e->f,final,reg,p_f); +patchlistaux(fs,e->t,final,reg,p_t); +} +e->f=e->t=(-1); +e->u.s.info=reg; +e->k=VNONRELOC; +} +static void luaK_exp2nextreg(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +freeexp(fs,e); +luaK_reserveregs(fs,1); +exp2reg(fs,e,fs->freereg-1); +} +static int luaK_exp2anyreg(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +if(e->k==VNONRELOC){ +if(!hasjumps(e))return e->u.s.info; +if(e->u.s.info>=fs->nactvar){ +exp2reg(fs,e,e->u.s.info); +return e->u.s.info; +} +} +luaK_exp2nextreg(fs,e); +return e->u.s.info; +} +static void luaK_exp2val(FuncState*fs,expdesc*e){ +if(hasjumps(e)) +luaK_exp2anyreg(fs,e); +else +luaK_dischargevars(fs,e); +} +static int luaK_exp2RK(FuncState*fs,expdesc*e){ +luaK_exp2val(fs,e); +switch(e->k){ +case VKNUM: +case VTRUE: +case VFALSE: +case VNIL:{ +if(fs->nk<=((1<<(9-1))-1)){ +e->u.s.info=(e->k==VNIL)?nilK(fs): +(e->k==VKNUM)?luaK_numberK(fs,e->u.nval): +boolK(fs,(e->k==VTRUE)); +e->k=VK; +return RKASK(e->u.s.info); +} +else break; +} +case VK:{ +if(e->u.s.info<=((1<<(9-1))-1)) +return RKASK(e->u.s.info); +else break; +} +default:break; +} +return luaK_exp2anyreg(fs,e); +} +static void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){ +switch(var->k){ +case VLOCAL:{ +freeexp(fs,ex); +exp2reg(fs,ex,var->u.s.info); +return; +} +case VUPVAL:{ +int e=luaK_exp2anyreg(fs,ex); +luaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0); +break; +} +case VGLOBAL:{ +int e=luaK_exp2anyreg(fs,ex); +luaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info); +break; +} +case VINDEXED:{ +int e=luaK_exp2RK(fs,ex); +luaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e); +break; +} +default:{ +break; +} +} +freeexp(fs,ex); +} +static void luaK_self(FuncState*fs,expdesc*e,expdesc*key){ +int func; +luaK_exp2anyreg(fs,e); +freeexp(fs,e); +func=fs->freereg; +luaK_reserveregs(fs,2); +luaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key)); +freeexp(fs,key); +e->u.s.info=func; +e->k=VNONRELOC; +} +static void invertjump(FuncState*fs,expdesc*e){ +Instruction*pc=getjumpcontrol(fs,e->u.s.info); +SETARG_A(*pc,!(GETARG_A(*pc))); +} +static int jumponcond(FuncState*fs,expdesc*e,int cond){ +if(e->k==VRELOCABLE){ +Instruction ie=getcode(fs,e); +if(GET_OPCODE(ie)==OP_NOT){ +fs->pc--; +return condjump(fs,OP_TEST,GETARG_B(ie),0,!cond); +} +} +discharge2anyreg(fs,e); +freeexp(fs,e); +return condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond); +} +static void luaK_goiftrue(FuncState*fs,expdesc*e){ +int pc; +luaK_dischargevars(fs,e); +switch(e->k){ +case VK:case VKNUM:case VTRUE:{ +pc=(-1); +break; +} +case VJMP:{ +invertjump(fs,e); +pc=e->u.s.info; +break; +} +default:{ +pc=jumponcond(fs,e,0); +break; +} +} +luaK_concat(fs,&e->f,pc); +luaK_patchtohere(fs,e->t); +e->t=(-1); +} +static void luaK_goiffalse(FuncState*fs,expdesc*e){ +int pc; +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:case VFALSE:{ +pc=(-1); +break; +} +case VJMP:{ +pc=e->u.s.info; +break; +} +default:{ +pc=jumponcond(fs,e,1); +break; +} +} +luaK_concat(fs,&e->t,pc); +luaK_patchtohere(fs,e->f); +e->f=(-1); +} +static void codenot(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:case VFALSE:{ +e->k=VTRUE; +break; +} +case VK:case VKNUM:case VTRUE:{ +e->k=VFALSE; +break; +} +case VJMP:{ +invertjump(fs,e); +break; +} +case VRELOCABLE: +case VNONRELOC:{ +discharge2anyreg(fs,e); +freeexp(fs,e); +e->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0); +e->k=VRELOCABLE; +break; +} +default:{ +break; +} +} +{int temp=e->f;e->f=e->t;e->t=temp;} +removevalues(fs,e->f); +removevalues(fs,e->t); +} +static void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){ +t->u.s.aux=luaK_exp2RK(fs,k); +t->k=VINDEXED; +} +static int constfolding(OpCode op,expdesc*e1,expdesc*e2){ +lua_Number v1,v2,r; +if(!isnumeral(e1)||!isnumeral(e2))return 0; +v1=e1->u.nval; +v2=e2->u.nval; +switch(op){ +case OP_ADD:r=luai_numadd(v1,v2);break; +case OP_SUB:r=luai_numsub(v1,v2);break; +case OP_MUL:r=luai_nummul(v1,v2);break; +case OP_DIV: +if(v2==0)return 0; +r=luai_numdiv(v1,v2);break; +case OP_MOD: +if(v2==0)return 0; +r=luai_nummod(v1,v2);break; +case OP_POW:r=luai_numpow(v1,v2);break; +case OP_UNM:r=luai_numunm(v1);break; +case OP_LEN:return 0; +default:r=0;break; +} +if(luai_numisnan(r))return 0; +e1->u.nval=r; +return 1; +} +static void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){ +if(constfolding(op,e1,e2)) +return; +else{ +int o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0; +int o1=luaK_exp2RK(fs,e1); +if(o1>o2){ +freeexp(fs,e1); +freeexp(fs,e2); +} +else{ +freeexp(fs,e2); +freeexp(fs,e1); +} +e1->u.s.info=luaK_codeABC(fs,op,0,o1,o2); +e1->k=VRELOCABLE; +} +} +static void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1, +expdesc*e2){ +int o1=luaK_exp2RK(fs,e1); +int o2=luaK_exp2RK(fs,e2); +freeexp(fs,e2); +freeexp(fs,e1); +if(cond==0&&op!=OP_EQ){ +int temp; +temp=o1;o1=o2;o2=temp; +cond=1; +} +e1->u.s.info=condjump(fs,op,cond,o1,o2); +e1->k=VJMP; +} +static void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){ +expdesc e2; +e2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0; +switch(op){ +case OPR_MINUS:{ +if(!isnumeral(e)) +luaK_exp2anyreg(fs,e); +codearith(fs,OP_UNM,e,&e2); +break; +} +case OPR_NOT:codenot(fs,e);break; +case OPR_LEN:{ +luaK_exp2anyreg(fs,e); +codearith(fs,OP_LEN,e,&e2); +break; +} +default:; +} +} +static void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){ +switch(op){ +case OPR_AND:{ +luaK_goiftrue(fs,v); +break; +} +case OPR_OR:{ +luaK_goiffalse(fs,v); +break; +} +case OPR_CONCAT:{ +luaK_exp2nextreg(fs,v); +break; +} +case OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV: +case OPR_MOD:case OPR_POW:{ +if(!isnumeral(v))luaK_exp2RK(fs,v); +break; +} +default:{ +luaK_exp2RK(fs,v); +break; +} +} +} +static void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){ +switch(op){ +case OPR_AND:{ +luaK_dischargevars(fs,e2); +luaK_concat(fs,&e2->f,e1->f); +*e1=*e2; +break; +} +case OPR_OR:{ +luaK_dischargevars(fs,e2); +luaK_concat(fs,&e2->t,e1->t); +*e1=*e2; +break; +} +case OPR_CONCAT:{ +luaK_exp2val(fs,e2); +if(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){ +freeexp(fs,e1); +SETARG_B(getcode(fs,e2),e1->u.s.info); +e1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info; +} +else{ +luaK_exp2nextreg(fs,e2); +codearith(fs,OP_CONCAT,e1,e2); +} +break; +} +case OPR_ADD:codearith(fs,OP_ADD,e1,e2);break; +case OPR_SUB:codearith(fs,OP_SUB,e1,e2);break; +case OPR_MUL:codearith(fs,OP_MUL,e1,e2);break; +case OPR_DIV:codearith(fs,OP_DIV,e1,e2);break; +case OPR_MOD:codearith(fs,OP_MOD,e1,e2);break; +case OPR_POW:codearith(fs,OP_POW,e1,e2);break; +case OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break; +case OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break; +case OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break; +case OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break; +case OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break; +case OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break; +default:; +} +} +static void luaK_fixline(FuncState*fs,int line){ +fs->f->lineinfo[fs->pc-1]=line; +} +static int luaK_code(FuncState*fs,Instruction i,int line){ +Proto*f=fs->f; +dischargejpc(fs); +luaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction, +(INT_MAX-2),"code size overflow"); +f->code[fs->pc]=i; +luaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int, +(INT_MAX-2),"code size overflow"); +f->lineinfo[fs->pc]=line; +return fs->pc++; +} +static int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){ +return luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline); +} +static int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){ +return luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline); +} +static void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){ +int c=(nelems-1)/50+1; +int b=(tostore==(-1))?0:tostore; +if(c<=((1<<9)-1)) +luaK_codeABC(fs,OP_SETLIST,base,b,c); +else{ +luaK_codeABC(fs,OP_SETLIST,base,b,0); +luaK_code(fs,cast(Instruction,c),fs->ls->lastline); +} +fs->freereg=base+1; +} +#define hasmultret(k)((k)==VCALL||(k)==VVARARG) +#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]]) +#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m) +typedef struct BlockCnt{ +struct BlockCnt*previous; +int breaklist; +lu_byte nactvar; +lu_byte upval; +lu_byte isbreakable; +}BlockCnt; +static void chunk(LexState*ls); +static void expr(LexState*ls,expdesc*v); +static void anchor_token(LexState*ls){ +if(ls->t.token==TK_NAME||ls->t.token==TK_STRING){ +TString*ts=ls->t.seminfo.ts; +luaX_newstring(ls,getstr(ts),ts->tsv.len); +} +} +static void error_expected(LexState*ls,int token){ +luaX_syntaxerror(ls, +luaO_pushfstring(ls->L,LUA_QL("%s")" expected",luaX_token2str(ls,token))); +} +static void errorlimit(FuncState*fs,int limit,const char*what){ +const char*msg=(fs->f->linedefined==0)? +luaO_pushfstring(fs->L,"main function has more than %d %s",limit,what): +luaO_pushfstring(fs->L,"function at line %d has more than %d %s", +fs->f->linedefined,limit,what); +luaX_lexerror(fs->ls,msg,0); +} +static int testnext(LexState*ls,int c){ +if(ls->t.token==c){ +luaX_next(ls); +return 1; +} +else return 0; +} +static void check(LexState*ls,int c){ +if(ls->t.token!=c) +error_expected(ls,c); +} +static void checknext(LexState*ls,int c){ +check(ls,c); +luaX_next(ls); +} +#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);} +static void check_match(LexState*ls,int what,int who,int where){ +if(!testnext(ls,what)){ +if(where==ls->linenumber) +error_expected(ls,what); +else{ +luaX_syntaxerror(ls,luaO_pushfstring(ls->L, +LUA_QL("%s")" expected (to close "LUA_QL("%s")" at line %d)", +luaX_token2str(ls,what),luaX_token2str(ls,who),where)); +} +} +} +static TString*str_checkname(LexState*ls){ +TString*ts; +check(ls,TK_NAME); +ts=ls->t.seminfo.ts; +luaX_next(ls); +return ts; +} +static void init_exp(expdesc*e,expkind k,int i){ +e->f=e->t=(-1); +e->k=k; +e->u.s.info=i; +} +static void codestring(LexState*ls,expdesc*e,TString*s){ +init_exp(e,VK,luaK_stringK(ls->fs,s)); +} +static void checkname(LexState*ls,expdesc*e){ +codestring(ls,e,str_checkname(ls)); +} +static int registerlocalvar(LexState*ls,TString*varname){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int oldsize=f->sizelocvars; +luaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars, +LocVar,SHRT_MAX,"too many local variables"); +while(oldsizesizelocvars)f->locvars[oldsize++].varname=NULL; +f->locvars[fs->nlocvars].varname=varname; +luaC_objbarrier(ls->L,f,varname); +return fs->nlocvars++; +} +#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,""v,(sizeof(v)/sizeof(char))-1),n) +static void new_localvar(LexState*ls,TString*name,int n){ +FuncState*fs=ls->fs; +luaY_checklimit(fs,fs->nactvar+n+1,200,"local variables"); +fs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name)); +} +static void adjustlocalvars(LexState*ls,int nvars){ +FuncState*fs=ls->fs; +fs->nactvar=cast_byte(fs->nactvar+nvars); +for(;nvars;nvars--){ +getlocvar(fs,fs->nactvar-nvars).startpc=fs->pc; +} +} +static void removevars(LexState*ls,int tolevel){ +FuncState*fs=ls->fs; +while(fs->nactvar>tolevel) +getlocvar(fs,--fs->nactvar).endpc=fs->pc; +} +static int indexupvalue(FuncState*fs,TString*name,expdesc*v){ +int i; +Proto*f=fs->f; +int oldsize=f->sizeupvalues; +for(i=0;inups;i++){ +if(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){ +return i; +} +} +luaY_checklimit(fs,f->nups+1,60,"upvalues"); +luaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues, +TString*,(INT_MAX-2),""); +while(oldsizesizeupvalues)f->upvalues[oldsize++]=NULL; +f->upvalues[f->nups]=name; +luaC_objbarrier(fs->L,f,name); +fs->upvalues[f->nups].k=cast_byte(v->k); +fs->upvalues[f->nups].info=cast_byte(v->u.s.info); +return f->nups++; +} +static int searchvar(FuncState*fs,TString*n){ +int i; +for(i=fs->nactvar-1;i>=0;i--){ +if(n==getlocvar(fs,i).varname) +return i; +} +return-1; +} +static void markupval(FuncState*fs,int level){ +BlockCnt*bl=fs->bl; +while(bl&&bl->nactvar>level)bl=bl->previous; +if(bl)bl->upval=1; +} +static int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){ +if(fs==NULL){ +init_exp(var,VGLOBAL,((1<<8)-1)); +return VGLOBAL; +} +else{ +int v=searchvar(fs,n); +if(v>=0){ +init_exp(var,VLOCAL,v); +if(!base) +markupval(fs,v); +return VLOCAL; +} +else{ +if(singlevaraux(fs->prev,n,var,0)==VGLOBAL) +return VGLOBAL; +var->u.s.info=indexupvalue(fs,n,var); +var->k=VUPVAL; +return VUPVAL; +} +} +} +static void singlevar(LexState*ls,expdesc*var){ +TString*varname=str_checkname(ls); +FuncState*fs=ls->fs; +if(singlevaraux(fs,varname,var,1)==VGLOBAL) +var->u.s.info=luaK_stringK(fs,varname); +} +static void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){ +FuncState*fs=ls->fs; +int extra=nvars-nexps; +if(hasmultret(e->k)){ +extra++; +if(extra<0)extra=0; +luaK_setreturns(fs,e,extra); +if(extra>1)luaK_reserveregs(fs,extra-1); +} +else{ +if(e->k!=VVOID)luaK_exp2nextreg(fs,e); +if(extra>0){ +int reg=fs->freereg; +luaK_reserveregs(fs,extra); +luaK_nil(fs,reg,extra); +} +} +} +static void enterlevel(LexState*ls){ +if(++ls->L->nCcalls>200) +luaX_lexerror(ls,"chunk has too many syntax levels",0); +} +#define leavelevel(ls)((ls)->L->nCcalls--) +static void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){ +bl->breaklist=(-1); +bl->isbreakable=isbreakable; +bl->nactvar=fs->nactvar; +bl->upval=0; +bl->previous=fs->bl; +fs->bl=bl; +} +static void leaveblock(FuncState*fs){ +BlockCnt*bl=fs->bl; +fs->bl=bl->previous; +removevars(fs->ls,bl->nactvar); +if(bl->upval) +luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); +fs->freereg=fs->nactvar; +luaK_patchtohere(fs,bl->breaklist); +} +static void pushclosure(LexState*ls,FuncState*func,expdesc*v){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int oldsize=f->sizep; +int i; +luaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*, +((1<<(9+9))-1),"constant table overflow"); +while(oldsizesizep)f->p[oldsize++]=NULL; +f->p[fs->np++]=func->f; +luaC_objbarrier(ls->L,f,func->f); +init_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1)); +for(i=0;if->nups;i++){ +OpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL; +luaK_codeABC(fs,o,0,func->upvalues[i].info,0); +} +} +static void open_func(LexState*ls,FuncState*fs){ +lua_State*L=ls->L; +Proto*f=luaF_newproto(L); +fs->f=f; +fs->prev=ls->fs; +fs->ls=ls; +fs->L=L; +ls->fs=fs; +fs->pc=0; +fs->lasttarget=-1; +fs->jpc=(-1); +fs->freereg=0; +fs->nk=0; +fs->np=0; +fs->nlocvars=0; +fs->nactvar=0; +fs->bl=NULL; +f->source=ls->source; +f->maxstacksize=2; +fs->h=luaH_new(L,0,0); +sethvalue(L,L->top,fs->h); +incr_top(L); +setptvalue(L,L->top,f); +incr_top(L); +} +static void close_func(LexState*ls){ +lua_State*L=ls->L; +FuncState*fs=ls->fs; +Proto*f=fs->f; +removevars(ls,0); +luaK_ret(fs,0,0); +luaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction); +f->sizecode=fs->pc; +luaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int); +f->sizelineinfo=fs->pc; +luaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue); +f->sizek=fs->nk; +luaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*); +f->sizep=fs->np; +luaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar); +f->sizelocvars=fs->nlocvars; +luaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*); +f->sizeupvalues=f->nups; +ls->fs=fs->prev; +if(fs)anchor_token(ls); +L->top-=2; +} +static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){ +struct LexState lexstate; +struct FuncState funcstate; +lexstate.buff=buff; +luaX_setinput(L,&lexstate,z,luaS_new(L,name)); +open_func(&lexstate,&funcstate); +funcstate.f->is_vararg=2; +luaX_next(&lexstate); +chunk(&lexstate); +check(&lexstate,TK_EOS); +close_func(&lexstate); +return funcstate.f; +} +static void field(LexState*ls,expdesc*v){ +FuncState*fs=ls->fs; +expdesc key; +luaK_exp2anyreg(fs,v); +luaX_next(ls); +checkname(ls,&key); +luaK_indexed(fs,v,&key); +} +static void yindex(LexState*ls,expdesc*v){ +luaX_next(ls); +expr(ls,v); +luaK_exp2val(ls->fs,v); +checknext(ls,']'); +} +struct ConsControl{ +expdesc v; +expdesc*t; +int nh; +int na; +int tostore; +}; +static void recfield(LexState*ls,struct ConsControl*cc){ +FuncState*fs=ls->fs; +int reg=ls->fs->freereg; +expdesc key,val; +int rkkey; +if(ls->t.token==TK_NAME){ +luaY_checklimit(fs,cc->nh,(INT_MAX-2),"items in a constructor"); +checkname(ls,&key); +} +else +yindex(ls,&key); +cc->nh++; +checknext(ls,'='); +rkkey=luaK_exp2RK(fs,&key); +expr(ls,&val); +luaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val)); +fs->freereg=reg; +} +static void closelistfield(FuncState*fs,struct ConsControl*cc){ +if(cc->v.k==VVOID)return; +luaK_exp2nextreg(fs,&cc->v); +cc->v.k=VVOID; +if(cc->tostore==50){ +luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); +cc->tostore=0; +} +} +static void lastlistfield(FuncState*fs,struct ConsControl*cc){ +if(cc->tostore==0)return; +if(hasmultret(cc->v.k)){ +luaK_setmultret(fs,&cc->v); +luaK_setlist(fs,cc->t->u.s.info,cc->na,(-1)); +cc->na--; +} +else{ +if(cc->v.k!=VVOID) +luaK_exp2nextreg(fs,&cc->v); +luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); +} +} +static void listfield(LexState*ls,struct ConsControl*cc){ +expr(ls,&cc->v); +luaY_checklimit(ls->fs,cc->na,(INT_MAX-2),"items in a constructor"); +cc->na++; +cc->tostore++; +} +static void constructor(LexState*ls,expdesc*t){ +FuncState*fs=ls->fs; +int line=ls->linenumber; +int pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0); +struct ConsControl cc; +cc.na=cc.nh=cc.tostore=0; +cc.t=t; +init_exp(t,VRELOCABLE,pc); +init_exp(&cc.v,VVOID,0); +luaK_exp2nextreg(ls->fs,t); +checknext(ls,'{'); +do{ +if(ls->t.token=='}')break; +closelistfield(fs,&cc); +switch(ls->t.token){ +case TK_NAME:{ +luaX_lookahead(ls); +if(ls->lookahead.token!='=') +listfield(ls,&cc); +else +recfield(ls,&cc); +break; +} +case'[':{ +recfield(ls,&cc); +break; +} +default:{ +listfield(ls,&cc); +break; +} +} +}while(testnext(ls,',')||testnext(ls,';')); +check_match(ls,'}','{',line); +lastlistfield(fs,&cc); +SETARG_B(fs->f->code[pc],luaO_int2fb(cc.na)); +SETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh)); +} +static void parlist(LexState*ls){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int nparams=0; +f->is_vararg=0; +if(ls->t.token!=')'){ +do{ +switch(ls->t.token){ +case TK_NAME:{ +new_localvar(ls,str_checkname(ls),nparams++); +break; +} +case TK_DOTS:{ +luaX_next(ls); +f->is_vararg|=2; +break; +} +default:luaX_syntaxerror(ls," or "LUA_QL("...")" expected"); +} +}while(!f->is_vararg&&testnext(ls,',')); +} +adjustlocalvars(ls,nparams); +f->numparams=cast_byte(fs->nactvar-(f->is_vararg&1)); +luaK_reserveregs(fs,fs->nactvar); +} +static void body(LexState*ls,expdesc*e,int needself,int line){ +FuncState new_fs; +open_func(ls,&new_fs); +new_fs.f->linedefined=line; +checknext(ls,'('); +if(needself){ +new_localvarliteral(ls,"self",0); +adjustlocalvars(ls,1); +} +parlist(ls); +checknext(ls,')'); +chunk(ls); +new_fs.f->lastlinedefined=ls->linenumber; +check_match(ls,TK_END,TK_FUNCTION,line); +close_func(ls); +pushclosure(ls,&new_fs,e); +} +static int explist1(LexState*ls,expdesc*v){ +int n=1; +expr(ls,v); +while(testnext(ls,',')){ +luaK_exp2nextreg(ls->fs,v); +expr(ls,v); +n++; +} +return n; +} +static void funcargs(LexState*ls,expdesc*f){ +FuncState*fs=ls->fs; +expdesc args; +int base,nparams; +int line=ls->linenumber; +switch(ls->t.token){ +case'(':{ +if(line!=ls->lastline) +luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); +luaX_next(ls); +if(ls->t.token==')') +args.k=VVOID; +else{ +explist1(ls,&args); +luaK_setmultret(fs,&args); +} +check_match(ls,')','(',line); +break; +} +case'{':{ +constructor(ls,&args); +break; +} +case TK_STRING:{ +codestring(ls,&args,ls->t.seminfo.ts); +luaX_next(ls); +break; +} +default:{ +luaX_syntaxerror(ls,"function arguments expected"); +return; +} +} +base=f->u.s.info; +if(hasmultret(args.k)) +nparams=(-1); +else{ +if(args.k!=VVOID) +luaK_exp2nextreg(fs,&args); +nparams=fs->freereg-(base+1); +} +init_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2)); +luaK_fixline(fs,line); +fs->freereg=base+1; +} +static void prefixexp(LexState*ls,expdesc*v){ +switch(ls->t.token){ +case'(':{ +int line=ls->linenumber; +luaX_next(ls); +expr(ls,v); +check_match(ls,')','(',line); +luaK_dischargevars(ls->fs,v); +return; +} +case TK_NAME:{ +singlevar(ls,v); +return; +} +default:{ +luaX_syntaxerror(ls,"unexpected symbol"); +return; +} +} +} +static void primaryexp(LexState*ls,expdesc*v){ +FuncState*fs=ls->fs; +prefixexp(ls,v); +for(;;){ +switch(ls->t.token){ +case'.':{ +field(ls,v); +break; +} +case'[':{ +expdesc key; +luaK_exp2anyreg(fs,v); +yindex(ls,&key); +luaK_indexed(fs,v,&key); +break; +} +case':':{ +expdesc key; +luaX_next(ls); +checkname(ls,&key); +luaK_self(fs,v,&key); +funcargs(ls,v); +break; +} +case'(':case TK_STRING:case'{':{ +luaK_exp2nextreg(fs,v); +funcargs(ls,v); +break; +} +default:return; +} +} +} +static void simpleexp(LexState*ls,expdesc*v){ +switch(ls->t.token){ +case TK_NUMBER:{ +init_exp(v,VKNUM,0); +v->u.nval=ls->t.seminfo.r; +break; +} +case TK_STRING:{ +codestring(ls,v,ls->t.seminfo.ts); +break; +} +case TK_NIL:{ +init_exp(v,VNIL,0); +break; +} +case TK_TRUE:{ +init_exp(v,VTRUE,0); +break; +} +case TK_FALSE:{ +init_exp(v,VFALSE,0); +break; +} +case TK_DOTS:{ +FuncState*fs=ls->fs; +check_condition(ls,fs->f->is_vararg, +"cannot use "LUA_QL("...")" outside a vararg function"); +fs->f->is_vararg&=~4; +init_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0)); +break; +} +case'{':{ +constructor(ls,v); +return; +} +case TK_FUNCTION:{ +luaX_next(ls); +body(ls,v,0,ls->linenumber); +return; +} +default:{ +primaryexp(ls,v); +return; +} +} +luaX_next(ls); +} +static UnOpr getunopr(int op){ +switch(op){ +case TK_NOT:return OPR_NOT; +case'-':return OPR_MINUS; +case'#':return OPR_LEN; +default:return OPR_NOUNOPR; +} +} +static BinOpr getbinopr(int op){ +switch(op){ +case'+':return OPR_ADD; +case'-':return OPR_SUB; +case'*':return OPR_MUL; +case'/':return OPR_DIV; +case'%':return OPR_MOD; +case'^':return OPR_POW; +case TK_CONCAT:return OPR_CONCAT; +case TK_NE:return OPR_NE; +case TK_EQ:return OPR_EQ; +case'<':return OPR_LT; +case TK_LE:return OPR_LE; +case'>':return OPR_GT; +case TK_GE:return OPR_GE; +case TK_AND:return OPR_AND; +case TK_OR:return OPR_OR; +default:return OPR_NOBINOPR; +} +} +static const struct{ +lu_byte left; +lu_byte right; +}priority[]={ +{6,6},{6,6},{7,7},{7,7},{7,7}, +{10,9},{5,4}, +{3,3},{3,3}, +{3,3},{3,3},{3,3},{3,3}, +{2,2},{1,1} +}; +static BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){ +BinOpr op; +UnOpr uop; +enterlevel(ls); +uop=getunopr(ls->t.token); +if(uop!=OPR_NOUNOPR){ +luaX_next(ls); +subexpr(ls,v,8); +luaK_prefix(ls->fs,uop,v); +} +else simpleexp(ls,v); +op=getbinopr(ls->t.token); +while(op!=OPR_NOBINOPR&&priority[op].left>limit){ +expdesc v2; +BinOpr nextop; +luaX_next(ls); +luaK_infix(ls->fs,op,v); +nextop=subexpr(ls,&v2,priority[op].right); +luaK_posfix(ls->fs,op,v,&v2); +op=nextop; +} +leavelevel(ls); +return op; +} +static void expr(LexState*ls,expdesc*v){ +subexpr(ls,v,0); +} +static int block_follow(int token){ +switch(token){ +case TK_ELSE:case TK_ELSEIF:case TK_END: +case TK_UNTIL:case TK_EOS: +return 1; +default:return 0; +} +} +static void block(LexState*ls){ +FuncState*fs=ls->fs; +BlockCnt bl; +enterblock(fs,&bl,0); +chunk(ls); +leaveblock(fs); +} +struct LHS_assign{ +struct LHS_assign*prev; +expdesc v; +}; +static void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){ +FuncState*fs=ls->fs; +int extra=fs->freereg; +int conflict=0; +for(;lh;lh=lh->prev){ +if(lh->v.k==VINDEXED){ +if(lh->v.u.s.info==v->u.s.info){ +conflict=1; +lh->v.u.s.info=extra; +} +if(lh->v.u.s.aux==v->u.s.info){ +conflict=1; +lh->v.u.s.aux=extra; +} +} +} +if(conflict){ +luaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0); +luaK_reserveregs(fs,1); +} +} +static void assignment(LexState*ls,struct LHS_assign*lh,int nvars){ +expdesc e; +check_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED, +"syntax error"); +if(testnext(ls,',')){ +struct LHS_assign nv; +nv.prev=lh; +primaryexp(ls,&nv.v); +if(nv.v.k==VLOCAL) +check_conflict(ls,lh,&nv.v); +luaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls, +"variables in assignment"); +assignment(ls,&nv,nvars+1); +} +else{ +int nexps; +checknext(ls,'='); +nexps=explist1(ls,&e); +if(nexps!=nvars){ +adjust_assign(ls,nvars,nexps,&e); +if(nexps>nvars) +ls->fs->freereg-=nexps-nvars; +} +else{ +luaK_setoneret(ls->fs,&e); +luaK_storevar(ls->fs,&lh->v,&e); +return; +} +} +init_exp(&e,VNONRELOC,ls->fs->freereg-1); +luaK_storevar(ls->fs,&lh->v,&e); +} +static int cond(LexState*ls){ +expdesc v; +expr(ls,&v); +if(v.k==VNIL)v.k=VFALSE; +luaK_goiftrue(ls->fs,&v); +return v.f; +} +static void breakstat(LexState*ls){ +FuncState*fs=ls->fs; +BlockCnt*bl=fs->bl; +int upval=0; +while(bl&&!bl->isbreakable){ +upval|=bl->upval; +bl=bl->previous; +} +if(!bl) +luaX_syntaxerror(ls,"no loop to break"); +if(upval) +luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); +luaK_concat(fs,&bl->breaklist,luaK_jump(fs)); +} +static void whilestat(LexState*ls,int line){ +FuncState*fs=ls->fs; +int whileinit; +int condexit; +BlockCnt bl; +luaX_next(ls); +whileinit=luaK_getlabel(fs); +condexit=cond(ls); +enterblock(fs,&bl,1); +checknext(ls,TK_DO); +block(ls); +luaK_patchlist(fs,luaK_jump(fs),whileinit); +check_match(ls,TK_END,TK_WHILE,line); +leaveblock(fs); +luaK_patchtohere(fs,condexit); +} +static void repeatstat(LexState*ls,int line){ +int condexit; +FuncState*fs=ls->fs; +int repeat_init=luaK_getlabel(fs); +BlockCnt bl1,bl2; +enterblock(fs,&bl1,1); +enterblock(fs,&bl2,0); +luaX_next(ls); +chunk(ls); +check_match(ls,TK_UNTIL,TK_REPEAT,line); +condexit=cond(ls); +if(!bl2.upval){ +leaveblock(fs); +luaK_patchlist(ls->fs,condexit,repeat_init); +} +else{ +breakstat(ls); +luaK_patchtohere(ls->fs,condexit); +leaveblock(fs); +luaK_patchlist(ls->fs,luaK_jump(fs),repeat_init); +} +leaveblock(fs); +} +static int exp1(LexState*ls){ +expdesc e; +int k; +expr(ls,&e); +k=e.k; +luaK_exp2nextreg(ls->fs,&e); +return k; +} +static void forbody(LexState*ls,int base,int line,int nvars,int isnum){ +BlockCnt bl; +FuncState*fs=ls->fs; +int prep,endfor; +adjustlocalvars(ls,3); +checknext(ls,TK_DO); +prep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs); +enterblock(fs,&bl,0); +adjustlocalvars(ls,nvars); +luaK_reserveregs(fs,nvars); +block(ls); +leaveblock(fs); +luaK_patchtohere(fs,prep); +endfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)): +luaK_codeABC(fs,OP_TFORLOOP,base,0,nvars); +luaK_fixline(fs,line); +luaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1); +} +static void fornum(LexState*ls,TString*varname,int line){ +FuncState*fs=ls->fs; +int base=fs->freereg; +new_localvarliteral(ls,"(for index)",0); +new_localvarliteral(ls,"(for limit)",1); +new_localvarliteral(ls,"(for step)",2); +new_localvar(ls,varname,3); +checknext(ls,'='); +exp1(ls); +checknext(ls,','); +exp1(ls); +if(testnext(ls,',')) +exp1(ls); +else{ +luaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1)); +luaK_reserveregs(fs,1); +} +forbody(ls,base,line,1,1); +} +static void forlist(LexState*ls,TString*indexname){ +FuncState*fs=ls->fs; +expdesc e; +int nvars=0; +int line; +int base=fs->freereg; +new_localvarliteral(ls,"(for generator)",nvars++); +new_localvarliteral(ls,"(for state)",nvars++); +new_localvarliteral(ls,"(for control)",nvars++); +new_localvar(ls,indexname,nvars++); +while(testnext(ls,',')) +new_localvar(ls,str_checkname(ls),nvars++); +checknext(ls,TK_IN); +line=ls->linenumber; +adjust_assign(ls,3,explist1(ls,&e),&e); +luaK_checkstack(fs,3); +forbody(ls,base,line,nvars-3,0); +} +static void forstat(LexState*ls,int line){ +FuncState*fs=ls->fs; +TString*varname; +BlockCnt bl; +enterblock(fs,&bl,1); +luaX_next(ls); +varname=str_checkname(ls); +switch(ls->t.token){ +case'=':fornum(ls,varname,line);break; +case',':case TK_IN:forlist(ls,varname);break; +default:luaX_syntaxerror(ls,LUA_QL("=")" or "LUA_QL("in")" expected"); +} +check_match(ls,TK_END,TK_FOR,line); +leaveblock(fs); +} +static int test_then_block(LexState*ls){ +int condexit; +luaX_next(ls); +condexit=cond(ls); +checknext(ls,TK_THEN); +block(ls); +return condexit; +} +static void ifstat(LexState*ls,int line){ +FuncState*fs=ls->fs; +int flist; +int escapelist=(-1); +flist=test_then_block(ls); +while(ls->t.token==TK_ELSEIF){ +luaK_concat(fs,&escapelist,luaK_jump(fs)); +luaK_patchtohere(fs,flist); +flist=test_then_block(ls); +} +if(ls->t.token==TK_ELSE){ +luaK_concat(fs,&escapelist,luaK_jump(fs)); +luaK_patchtohere(fs,flist); +luaX_next(ls); +block(ls); +} +else +luaK_concat(fs,&escapelist,flist); +luaK_patchtohere(fs,escapelist); +check_match(ls,TK_END,TK_IF,line); +} +static void localfunc(LexState*ls){ +expdesc v,b; +FuncState*fs=ls->fs; +new_localvar(ls,str_checkname(ls),0); +init_exp(&v,VLOCAL,fs->freereg); +luaK_reserveregs(fs,1); +adjustlocalvars(ls,1); +body(ls,&b,0,ls->linenumber); +luaK_storevar(fs,&v,&b); +getlocvar(fs,fs->nactvar-1).startpc=fs->pc; +} +static void localstat(LexState*ls){ +int nvars=0; +int nexps; +expdesc e; +do{ +new_localvar(ls,str_checkname(ls),nvars++); +}while(testnext(ls,',')); +if(testnext(ls,'=')) +nexps=explist1(ls,&e); +else{ +e.k=VVOID; +nexps=0; +} +adjust_assign(ls,nvars,nexps,&e); +adjustlocalvars(ls,nvars); +} +static int funcname(LexState*ls,expdesc*v){ +int needself=0; +singlevar(ls,v); +while(ls->t.token=='.') +field(ls,v); +if(ls->t.token==':'){ +needself=1; +field(ls,v); +} +return needself; +} +static void funcstat(LexState*ls,int line){ +int needself; +expdesc v,b; +luaX_next(ls); +needself=funcname(ls,&v); +body(ls,&b,needself,line); +luaK_storevar(ls->fs,&v,&b); +luaK_fixline(ls->fs,line); +} +static void exprstat(LexState*ls){ +FuncState*fs=ls->fs; +struct LHS_assign v; +primaryexp(ls,&v.v); +if(v.v.k==VCALL) +SETARG_C(getcode(fs,&v.v),1); +else{ +v.prev=NULL; +assignment(ls,&v,1); +} +} +static void retstat(LexState*ls){ +FuncState*fs=ls->fs; +expdesc e; +int first,nret; +luaX_next(ls); +if(block_follow(ls->t.token)||ls->t.token==';') +first=nret=0; +else{ +nret=explist1(ls,&e); +if(hasmultret(e.k)){ +luaK_setmultret(fs,&e); +if(e.k==VCALL&&nret==1){ +SET_OPCODE(getcode(fs,&e),OP_TAILCALL); +} +first=fs->nactvar; +nret=(-1); +} +else{ +if(nret==1) +first=luaK_exp2anyreg(fs,&e); +else{ +luaK_exp2nextreg(fs,&e); +first=fs->nactvar; +} +} +} +luaK_ret(fs,first,nret); +} +static int statement(LexState*ls){ +int line=ls->linenumber; +switch(ls->t.token){ +case TK_IF:{ +ifstat(ls,line); +return 0; +} +case TK_WHILE:{ +whilestat(ls,line); +return 0; +} +case TK_DO:{ +luaX_next(ls); +block(ls); +check_match(ls,TK_END,TK_DO,line); +return 0; +} +case TK_FOR:{ +forstat(ls,line); +return 0; +} +case TK_REPEAT:{ +repeatstat(ls,line); +return 0; +} +case TK_FUNCTION:{ +funcstat(ls,line); +return 0; +} +case TK_LOCAL:{ +luaX_next(ls); +if(testnext(ls,TK_FUNCTION)) +localfunc(ls); +else +localstat(ls); +return 0; +} +case TK_RETURN:{ +retstat(ls); +return 1; +} +case TK_BREAK:{ +luaX_next(ls); +breakstat(ls); +return 1; +} +default:{ +exprstat(ls); +return 0; +} +} +} +static void chunk(LexState*ls){ +int islast=0; +enterlevel(ls); +while(!islast&&!block_follow(ls->t.token)){ +islast=statement(ls); +testnext(ls,';'); +ls->fs->freereg=ls->fs->nactvar; +} +leavelevel(ls); +} +static const TValue*luaV_tonumber(const TValue*obj,TValue*n){ +lua_Number num; +if(ttisnumber(obj))return obj; +if(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){ +setnvalue(n,num); +return n; +} +else +return NULL; +} +static int luaV_tostring(lua_State*L,StkId obj){ +if(!ttisnumber(obj)) +return 0; +else{ +char s[32]; +lua_Number n=nvalue(obj); +lua_number2str(s,n); +setsvalue(L,obj,luaS_new(L,s)); +return 1; +} +} +static void callTMres(lua_State*L,StkId res,const TValue*f, +const TValue*p1,const TValue*p2){ +ptrdiff_t result=savestack(L,res); +setobj(L,L->top,f); +setobj(L,L->top+1,p1); +setobj(L,L->top+2,p2); +luaD_checkstack(L,3); +L->top+=3; +luaD_call(L,L->top-3,1); +res=restorestack(L,result); +L->top--; +setobj(L,res,L->top); +} +static void callTM(lua_State*L,const TValue*f,const TValue*p1, +const TValue*p2,const TValue*p3){ +setobj(L,L->top,f); +setobj(L,L->top+1,p1); +setobj(L,L->top+2,p2); +setobj(L,L->top+3,p3); +luaD_checkstack(L,4); +L->top+=4; +luaD_call(L,L->top-4,0); +} +static void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){ +int loop; +for(loop=0;loop<100;loop++){ +const TValue*tm; +if(ttistable(t)){ +Table*h=hvalue(t); +const TValue*res=luaH_get(h,key); +if(!ttisnil(res)|| +(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){ +setobj(L,val,res); +return; +} +} +else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX))) +luaG_typeerror(L,t,"index"); +if(ttisfunction(tm)){ +callTMres(L,val,tm,t,key); +return; +} +t=tm; +} +luaG_runerror(L,"loop in gettable"); +} +static void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){ +int loop; +TValue temp; +for(loop=0;loop<100;loop++){ +const TValue*tm; +if(ttistable(t)){ +Table*h=hvalue(t); +TValue*oldval=luaH_set(L,h,key); +if(!ttisnil(oldval)|| +(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){ +setobj(L,oldval,val); +h->flags=0; +luaC_barriert(L,h,val); +return; +} +} +else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX))) +luaG_typeerror(L,t,"index"); +if(ttisfunction(tm)){ +callTM(L,tm,t,key,val); +return; +} +setobj(L,&temp,tm); +t=&temp; +} +luaG_runerror(L,"loop in settable"); +} +static int call_binTM(lua_State*L,const TValue*p1,const TValue*p2, +StkId res,TMS event){ +const TValue*tm=luaT_gettmbyobj(L,p1,event); +if(ttisnil(tm)) +tm=luaT_gettmbyobj(L,p2,event); +if(ttisnil(tm))return 0; +callTMres(L,res,tm,p1,p2); +return 1; +} +static const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2, +TMS event){ +const TValue*tm1=fasttm(L,mt1,event); +const TValue*tm2; +if(tm1==NULL)return NULL; +if(mt1==mt2)return tm1; +tm2=fasttm(L,mt2,event); +if(tm2==NULL)return NULL; +if(luaO_rawequalObj(tm1,tm2)) +return tm1; +return NULL; +} +static int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2, +TMS event){ +const TValue*tm1=luaT_gettmbyobj(L,p1,event); +const TValue*tm2; +if(ttisnil(tm1))return-1; +tm2=luaT_gettmbyobj(L,p2,event); +if(!luaO_rawequalObj(tm1,tm2)) +return-1; +callTMres(L,L->top,tm1,p1,p2); +return!l_isfalse(L->top); +} +static int l_strcmp(const TString*ls,const TString*rs){ +const char*l=getstr(ls); +size_t ll=ls->tsv.len; +const char*r=getstr(rs); +size_t lr=rs->tsv.len; +for(;;){ +int temp=strcoll(l,r); +if(temp!=0)return temp; +else{ +size_t len=strlen(l); +if(len==lr) +return(len==ll)?0:1; +else if(len==ll) +return-1; +len++; +l+=len;ll-=len;r+=len;lr-=len; +} +} +} +static int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){ +int res; +if(ttype(l)!=ttype(r)) +return luaG_ordererror(L,l,r); +else if(ttisnumber(l)) +return luai_numlt(nvalue(l),nvalue(r)); +else if(ttisstring(l)) +return l_strcmp(rawtsvalue(l),rawtsvalue(r))<0; +else if((res=call_orderTM(L,l,r,TM_LT))!=-1) +return res; +return luaG_ordererror(L,l,r); +} +static int lessequal(lua_State*L,const TValue*l,const TValue*r){ +int res; +if(ttype(l)!=ttype(r)) +return luaG_ordererror(L,l,r); +else if(ttisnumber(l)) +return luai_numle(nvalue(l),nvalue(r)); +else if(ttisstring(l)) +return l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0; +else if((res=call_orderTM(L,l,r,TM_LE))!=-1) +return res; +else if((res=call_orderTM(L,r,l,TM_LT))!=-1) +return!res; +return luaG_ordererror(L,l,r); +} +static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){ +const TValue*tm; +switch(ttype(t1)){ +case 0:return 1; +case 3:return luai_numeq(nvalue(t1),nvalue(t2)); +case 1:return bvalue(t1)==bvalue(t2); +case 2:return pvalue(t1)==pvalue(t2); +case 7:{ +if(uvalue(t1)==uvalue(t2))return 1; +tm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable, +TM_EQ); +break; +} +case 5:{ +if(hvalue(t1)==hvalue(t2))return 1; +tm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ); +break; +} +default:return gcvalue(t1)==gcvalue(t2); +} +if(tm==NULL)return 0; +callTMres(L,L->top,tm,t1,t2); +return!l_isfalse(L->top); +} +static void luaV_concat(lua_State*L,int total,int last){ +do{ +StkId top=L->base+last+1; +int n=2; +if(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){ +if(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT)) +luaG_concaterror(L,top-2,top-1); +}else if(tsvalue(top-1)->len==0) +(void)tostring(L,top-2); +else{ +size_t tl=tsvalue(top-1)->len; +char*buffer; +int i; +for(n=1;nlen; +if(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,"string length overflow"); +tl+=l; +} +buffer=luaZ_openspace(L,&G(L)->buff,tl); +tl=0; +for(i=n;i>0;i--){ +size_t l=tsvalue(top-i)->len; +memcpy(buffer+tl,svalue(top-i),l); +tl+=l; +} +setsvalue(L,top-n,luaS_newlstr(L,buffer,tl)); +} +total-=n-1; +last-=n-1; +}while(total>1); +} +static void Arith(lua_State*L,StkId ra,const TValue*rb, +const TValue*rc,TMS op){ +TValue tempb,tempc; +const TValue*b,*c; +if((b=luaV_tonumber(rb,&tempb))!=NULL&& +(c=luaV_tonumber(rc,&tempc))!=NULL){ +lua_Number nb=nvalue(b),nc=nvalue(c); +switch(op){ +case TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break; +case TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break; +case TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break; +case TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break; +case TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break; +case TM_POW:setnvalue(ra,luai_numpow(nb,nc));break; +case TM_UNM:setnvalue(ra,luai_numunm(nb));break; +default:break; +} +} +else if(!call_binTM(L,rb,rc,ra,op)) +luaG_aritherror(L,rb,rc); +} +#define runtime_check(L,c){if(!(c))break;} +#define RA(i)(base+GETARG_A(i)) +#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i)) +#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i)) +#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i)) +#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i)) +#define dojump(L,pc,i){(pc)+=(i);} +#define Protect(x){L->savedpc=pc;{x;};base=L->base;} +#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));} +static void luaV_execute(lua_State*L,int nexeccalls){ +LClosure*cl; +StkId base; +TValue*k; +const Instruction*pc; +reentry: +pc=L->savedpc; +cl=&clvalue(L->ci->func)->l; +base=L->base; +k=cl->p->k; +for(;;){ +const Instruction i=*pc++; +StkId ra; +ra=RA(i); +switch(GET_OPCODE(i)){ +case OP_MOVE:{ +setobj(L,ra,RB(i)); +continue; +} +case OP_LOADK:{ +setobj(L,ra,KBx(i)); +continue; +} +case OP_LOADBOOL:{ +setbvalue(ra,GETARG_B(i)); +if(GETARG_C(i))pc++; +continue; +} +case OP_LOADNIL:{ +TValue*rb=RB(i); +do{ +setnilvalue(rb--); +}while(rb>=ra); +continue; +} +case OP_GETUPVAL:{ +int b=GETARG_B(i); +setobj(L,ra,cl->upvals[b]->v); +continue; +} +case OP_GETGLOBAL:{ +TValue g; +TValue*rb=KBx(i); +sethvalue(L,&g,cl->env); +Protect(luaV_gettable(L,&g,rb,ra)); +continue; +} +case OP_GETTABLE:{ +Protect(luaV_gettable(L,RB(i),RKC(i),ra)); +continue; +} +case OP_SETGLOBAL:{ +TValue g; +sethvalue(L,&g,cl->env); +Protect(luaV_settable(L,&g,KBx(i),ra)); +continue; +} +case OP_SETUPVAL:{ +UpVal*uv=cl->upvals[GETARG_B(i)]; +setobj(L,uv->v,ra); +luaC_barrier(L,uv,ra); +continue; +} +case OP_SETTABLE:{ +Protect(luaV_settable(L,ra,RKB(i),RKC(i))); +continue; +} +case OP_NEWTABLE:{ +int b=GETARG_B(i); +int c=GETARG_C(i); +sethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c))); +Protect(luaC_checkGC(L)); +continue; +} +case OP_SELF:{ +StkId rb=RB(i); +setobj(L,ra+1,rb); +Protect(luaV_gettable(L,rb,RKC(i),ra)); +continue; +} +case OP_ADD:{ +arith_op(luai_numadd,TM_ADD); +continue; +} +case OP_SUB:{ +arith_op(luai_numsub,TM_SUB); +continue; +} +case OP_MUL:{ +arith_op(luai_nummul,TM_MUL); +continue; +} +case OP_DIV:{ +arith_op(luai_numdiv,TM_DIV); +continue; +} +case OP_MOD:{ +arith_op(luai_nummod,TM_MOD); +continue; +} +case OP_POW:{ +arith_op(luai_numpow,TM_POW); +continue; +} +case OP_UNM:{ +TValue*rb=RB(i); +if(ttisnumber(rb)){ +lua_Number nb=nvalue(rb); +setnvalue(ra,luai_numunm(nb)); +} +else{ +Protect(Arith(L,ra,rb,rb,TM_UNM)); +} +continue; +} +case OP_NOT:{ +int res=l_isfalse(RB(i)); +setbvalue(ra,res); +continue; +} +case OP_LEN:{ +const TValue*rb=RB(i); +switch(ttype(rb)){ +case 5:{ +setnvalue(ra,cast_num(luaH_getn(hvalue(rb)))); +break; +} +case 4:{ +setnvalue(ra,cast_num(tsvalue(rb)->len)); +break; +} +default:{ +Protect( +if(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN)) +luaG_typeerror(L,rb,"get length of"); +) +} +} +continue; +} +case OP_CONCAT:{ +int b=GETARG_B(i); +int c=GETARG_C(i); +Protect(luaV_concat(L,c-b+1,c);luaC_checkGC(L)); +setobj(L,RA(i),base+b); +continue; +} +case OP_JMP:{ +dojump(L,pc,GETARG_sBx(i)); +continue; +} +case OP_EQ:{ +TValue*rb=RKB(i); +TValue*rc=RKC(i); +Protect( +if(equalobj(L,rb,rc)==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_LT:{ +Protect( +if(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_LE:{ +Protect( +if(lessequal(L,RKB(i),RKC(i))==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_TEST:{ +if(l_isfalse(ra)!=GETARG_C(i)) +dojump(L,pc,GETARG_sBx(*pc)); +pc++; +continue; +} +case OP_TESTSET:{ +TValue*rb=RB(i); +if(l_isfalse(rb)!=GETARG_C(i)){ +setobj(L,ra,rb); +dojump(L,pc,GETARG_sBx(*pc)); +} +pc++; +continue; +} +case OP_CALL:{ +int b=GETARG_B(i); +int nresults=GETARG_C(i)-1; +if(b!=0)L->top=ra+b; +L->savedpc=pc; +switch(luaD_precall(L,ra,nresults)){ +case 0:{ +nexeccalls++; +goto reentry; +} +case 1:{ +if(nresults>=0)L->top=L->ci->top; +base=L->base; +continue; +} +default:{ +return; +} +} +} +case OP_TAILCALL:{ +int b=GETARG_B(i); +if(b!=0)L->top=ra+b; +L->savedpc=pc; +switch(luaD_precall(L,ra,(-1))){ +case 0:{ +CallInfo*ci=L->ci-1; +int aux; +StkId func=ci->func; +StkId pfunc=(ci+1)->func; +if(L->openupval)luaF_close(L,ci->base); +L->base=ci->base=ci->func+((ci+1)->base-pfunc); +for(aux=0;pfunc+auxtop;aux++) +setobj(L,func+aux,pfunc+aux); +ci->top=L->top=func+aux; +ci->savedpc=L->savedpc; +ci->tailcalls++; +L->ci--; +goto reentry; +} +case 1:{ +base=L->base; +continue; +} +default:{ +return; +} +} +} +case OP_RETURN:{ +int b=GETARG_B(i); +if(b!=0)L->top=ra+b-1; +if(L->openupval)luaF_close(L,base); +L->savedpc=pc; +b=luaD_poscall(L,ra); +if(--nexeccalls==0) +return; +else{ +if(b)L->top=L->ci->top; +goto reentry; +} +} +case OP_FORLOOP:{ +lua_Number step=nvalue(ra+2); +lua_Number idx=luai_numadd(nvalue(ra),step); +lua_Number limit=nvalue(ra+1); +if(luai_numlt(0,step)?luai_numle(idx,limit) +:luai_numle(limit,idx)){ +dojump(L,pc,GETARG_sBx(i)); +setnvalue(ra,idx); +setnvalue(ra+3,idx); +} +continue; +} +case OP_FORPREP:{ +const TValue*init=ra; +const TValue*plimit=ra+1; +const TValue*pstep=ra+2; +L->savedpc=pc; +if(!tonumber(init,ra)) +luaG_runerror(L,LUA_QL("for")" initial value must be a number"); +else if(!tonumber(plimit,ra+1)) +luaG_runerror(L,LUA_QL("for")" limit must be a number"); +else if(!tonumber(pstep,ra+2)) +luaG_runerror(L,LUA_QL("for")" step must be a number"); +setnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep))); +dojump(L,pc,GETARG_sBx(i)); +continue; +} +case OP_TFORLOOP:{ +StkId cb=ra+3; +setobj(L,cb+2,ra+2); +setobj(L,cb+1,ra+1); +setobj(L,cb,ra); +L->top=cb+3; +Protect(luaD_call(L,cb,GETARG_C(i))); +L->top=L->ci->top; +cb=RA(i)+3; +if(!ttisnil(cb)){ +setobj(L,cb-1,cb); +dojump(L,pc,GETARG_sBx(*pc)); +} +pc++; +continue; +} +case OP_SETLIST:{ +int n=GETARG_B(i); +int c=GETARG_C(i); +int last; +Table*h; +if(n==0){ +n=cast_int(L->top-ra)-1; +L->top=L->ci->top; +} +if(c==0)c=cast_int(*pc++); +runtime_check(L,ttistable(ra)); +h=hvalue(ra); +last=((c-1)*50)+n; +if(last>h->sizearray) +luaH_resizearray(L,h,last); +for(;n>0;n--){ +TValue*val=ra+n; +setobj(L,luaH_setnum(L,h,last--),val); +luaC_barriert(L,h,val); +} +continue; +} +case OP_CLOSE:{ +luaF_close(L,ra); +continue; +} +case OP_CLOSURE:{ +Proto*p; +Closure*ncl; +int nup,j; +p=cl->p->p[GETARG_Bx(i)]; +nup=p->nups; +ncl=luaF_newLclosure(L,nup,cl->env); +ncl->l.p=p; +for(j=0;jl.upvals[j]=cl->upvals[GETARG_B(*pc)]; +else{ +ncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc)); +} +} +setclvalue(L,ra,ncl); +Protect(luaC_checkGC(L)); +continue; +} +case OP_VARARG:{ +int b=GETARG_B(i)-1; +int j; +CallInfo*ci=L->ci; +int n=cast_int(ci->base-ci->func)-cl->p->numparams-1; +if(b==(-1)){ +Protect(luaD_checkstack(L,n)); +ra=RA(i); +b=n; +L->top=ra+n; +} +for(j=0;jbase-n+j); +} +else{ +setnilvalue(ra+j); +} +} +continue; +} +} +} +} +#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base)) +#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_)) +#define api_incr_top(L){luai_apicheck(L,L->topci->top);L->top++;} +static TValue*index2adr(lua_State*L,int idx){ +if(idx>0){ +TValue*o=L->base+(idx-1); +luai_apicheck(L,idx<=L->ci->top-L->base); +if(o>=L->top)return cast(TValue*,(&luaO_nilobject_)); +else return o; +} +else if(idx>(-10000)){ +luai_apicheck(L,idx!=0&&-idx<=L->top-L->base); +return L->top+idx; +} +else switch(idx){ +case(-10000):return registry(L); +case(-10001):{ +Closure*func=curr_func(L); +sethvalue(L,&L->env,func->c.env); +return&L->env; +} +case(-10002):return gt(L); +default:{ +Closure*func=curr_func(L); +idx=(-10002)-idx; +return(idx<=func->c.nupvalues) +?&func->c.upvalue[idx-1] +:cast(TValue*,(&luaO_nilobject_)); +} +} +} +static Table*getcurrenv(lua_State*L){ +if(L->ci==L->base_ci) +return hvalue(gt(L)); +else{ +Closure*func=curr_func(L); +return func->c.env; +} +} +static int lua_checkstack(lua_State*L,int size){ +int res=1; +if(size>8000||(L->top-L->base+size)>8000) +res=0; +else if(size>0){ +luaD_checkstack(L,size); +if(L->ci->toptop+size) +L->ci->top=L->top+size; +} +return res; +} +static lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){ +lua_CFunction old; +old=G(L)->panic; +G(L)->panic=panicf; +return old; +} +static int lua_gettop(lua_State*L){ +return cast_int(L->top-L->base); +} +static void lua_settop(lua_State*L,int idx){ +if(idx>=0){ +luai_apicheck(L,idx<=L->stack_last-L->base); +while(L->topbase+idx) +setnilvalue(L->top++); +L->top=L->base+idx; +} +else{ +luai_apicheck(L,-(idx+1)<=(L->top-L->base)); +L->top+=idx+1; +} +} +static void lua_remove(lua_State*L,int idx){ +StkId p; +p=index2adr(L,idx); +api_checkvalidindex(L,p); +while(++ptop)setobj(L,p-1,p); +L->top--; +} +static void lua_insert(lua_State*L,int idx){ +StkId p; +StkId q; +p=index2adr(L,idx); +api_checkvalidindex(L,p); +for(q=L->top;q>p;q--)setobj(L,q,q-1); +setobj(L,p,L->top); +} +static void lua_replace(lua_State*L,int idx){ +StkId o; +if(idx==(-10001)&&L->ci==L->base_ci) +luaG_runerror(L,"no calling environment"); +api_checknelems(L,1); +o=index2adr(L,idx); +api_checkvalidindex(L,o); +if(idx==(-10001)){ +Closure*func=curr_func(L); +luai_apicheck(L,ttistable(L->top-1)); +func->c.env=hvalue(L->top-1); +luaC_barrier(L,func,L->top-1); +} +else{ +setobj(L,o,L->top-1); +if(idx<(-10002)) +luaC_barrier(L,curr_func(L),L->top-1); +} +L->top--; +} +static void lua_pushvalue(lua_State*L,int idx){ +setobj(L,L->top,index2adr(L,idx)); +api_incr_top(L); +} +static int lua_type(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return(o==(&luaO_nilobject_))?(-1):ttype(o); +} +static const char*lua_typename(lua_State*L,int t){ +UNUSED(L); +return(t==(-1))?"no value":luaT_typenames[t]; +} +static int lua_iscfunction(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return iscfunction(o); +} +static int lua_isnumber(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +return tonumber(o,&n); +} +static int lua_isstring(lua_State*L,int idx){ +int t=lua_type(L,idx); +return(t==4||t==3); +} +static int lua_rawequal(lua_State*L,int index1,int index2){ +StkId o1=index2adr(L,index1); +StkId o2=index2adr(L,index2); +return(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 +:luaO_rawequalObj(o1,o2); +} +static int lua_lessthan(lua_State*L,int index1,int index2){ +StkId o1,o2; +int i; +o1=index2adr(L,index1); +o2=index2adr(L,index2); +i=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 +:luaV_lessthan(L,o1,o2); +return i; +} +static lua_Number lua_tonumber(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +if(tonumber(o,&n)) +return nvalue(o); +else +return 0; +} +static lua_Integer lua_tointeger(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +if(tonumber(o,&n)){ +lua_Integer res; +lua_Number num=nvalue(o); +lua_number2integer(res,num); +return res; +} +else +return 0; +} +static int lua_toboolean(lua_State*L,int idx){ +const TValue*o=index2adr(L,idx); +return!l_isfalse(o); +} +static const char*lua_tolstring(lua_State*L,int idx,size_t*len){ +StkId o=index2adr(L,idx); +if(!ttisstring(o)){ +if(!luaV_tostring(L,o)){ +if(len!=NULL)*len=0; +return NULL; +} +luaC_checkGC(L); +o=index2adr(L,idx); +} +if(len!=NULL)*len=tsvalue(o)->len; +return svalue(o); +} +static size_t lua_objlen(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +switch(ttype(o)){ +case 4:return tsvalue(o)->len; +case 7:return uvalue(o)->len; +case 5:return luaH_getn(hvalue(o)); +case 3:{ +size_t l; +l=(luaV_tostring(L,o)?tsvalue(o)->len:0); +return l; +} +default:return 0; +} +} +static lua_CFunction lua_tocfunction(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return(!iscfunction(o))?NULL:clvalue(o)->c.f; +} +static void*lua_touserdata(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +switch(ttype(o)){ +case 7:return(rawuvalue(o)+1); +case 2:return pvalue(o); +default:return NULL; +} +} +static void lua_pushnil(lua_State*L){ +setnilvalue(L->top); +api_incr_top(L); +} +static void lua_pushnumber(lua_State*L,lua_Number n){ +setnvalue(L->top,n); +api_incr_top(L); +} +static void lua_pushinteger(lua_State*L,lua_Integer n){ +setnvalue(L->top,cast_num(n)); +api_incr_top(L); +} +static void lua_pushlstring(lua_State*L,const char*s,size_t len){ +luaC_checkGC(L); +setsvalue(L,L->top,luaS_newlstr(L,s,len)); +api_incr_top(L); +} +static void lua_pushstring(lua_State*L,const char*s){ +if(s==NULL) +lua_pushnil(L); +else +lua_pushlstring(L,s,strlen(s)); +} +static const char*lua_pushvfstring(lua_State*L,const char*fmt, +va_list argp){ +const char*ret; +luaC_checkGC(L); +ret=luaO_pushvfstring(L,fmt,argp); +return ret; +} +static const char*lua_pushfstring(lua_State*L,const char*fmt,...){ +const char*ret; +va_list argp; +luaC_checkGC(L); +va_start(argp,fmt); +ret=luaO_pushvfstring(L,fmt,argp); +va_end(argp); +return ret; +} +static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){ +Closure*cl; +luaC_checkGC(L); +api_checknelems(L,n); +cl=luaF_newCclosure(L,n,getcurrenv(L)); +cl->c.f=fn; +L->top-=n; +while(n--) +setobj(L,&cl->c.upvalue[n],L->top+n); +setclvalue(L,L->top,cl); +api_incr_top(L); +} +static void lua_pushboolean(lua_State*L,int b){ +setbvalue(L->top,(b!=0)); +api_incr_top(L); +} +static int lua_pushthread(lua_State*L){ +setthvalue(L,L->top,L); +api_incr_top(L); +return(G(L)->mainthread==L); +} +static void lua_gettable(lua_State*L,int idx){ +StkId t; +t=index2adr(L,idx); +api_checkvalidindex(L,t); +luaV_gettable(L,t,L->top-1,L->top-1); +} +static void lua_getfield(lua_State*L,int idx,const char*k){ +StkId t; +TValue key; +t=index2adr(L,idx); +api_checkvalidindex(L,t); +setsvalue(L,&key,luaS_new(L,k)); +luaV_gettable(L,t,&key,L->top); +api_incr_top(L); +} +static void lua_rawget(lua_State*L,int idx){ +StkId t; +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +setobj(L,L->top-1,luaH_get(hvalue(t),L->top-1)); +} +static void lua_rawgeti(lua_State*L,int idx,int n){ +StkId o; +o=index2adr(L,idx); +luai_apicheck(L,ttistable(o)); +setobj(L,L->top,luaH_getnum(hvalue(o),n)); +api_incr_top(L); +} +static void lua_createtable(lua_State*L,int narray,int nrec){ +luaC_checkGC(L); +sethvalue(L,L->top,luaH_new(L,narray,nrec)); +api_incr_top(L); +} +static int lua_getmetatable(lua_State*L,int objindex){ +const TValue*obj; +Table*mt=NULL; +int res; +obj=index2adr(L,objindex); +switch(ttype(obj)){ +case 5: +mt=hvalue(obj)->metatable; +break; +case 7: +mt=uvalue(obj)->metatable; +break; +default: +mt=G(L)->mt[ttype(obj)]; +break; +} +if(mt==NULL) +res=0; +else{ +sethvalue(L,L->top,mt); +api_incr_top(L); +res=1; +} +return res; +} +static void lua_getfenv(lua_State*L,int idx){ +StkId o; +o=index2adr(L,idx); +api_checkvalidindex(L,o); +switch(ttype(o)){ +case 6: +sethvalue(L,L->top,clvalue(o)->c.env); +break; +case 7: +sethvalue(L,L->top,uvalue(o)->env); +break; +case 8: +setobj(L,L->top,gt(thvalue(o))); +break; +default: +setnilvalue(L->top); +break; +} +api_incr_top(L); +} +static void lua_settable(lua_State*L,int idx){ +StkId t; +api_checknelems(L,2); +t=index2adr(L,idx); +api_checkvalidindex(L,t); +luaV_settable(L,t,L->top-2,L->top-1); +L->top-=2; +} +static void lua_setfield(lua_State*L,int idx,const char*k){ +StkId t; +TValue key; +api_checknelems(L,1); +t=index2adr(L,idx); +api_checkvalidindex(L,t); +setsvalue(L,&key,luaS_new(L,k)); +luaV_settable(L,t,&key,L->top-1); +L->top--; +} +static void lua_rawset(lua_State*L,int idx){ +StkId t; +api_checknelems(L,2); +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +setobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1); +luaC_barriert(L,hvalue(t),L->top-1); +L->top-=2; +} +static void lua_rawseti(lua_State*L,int idx,int n){ +StkId o; +api_checknelems(L,1); +o=index2adr(L,idx); +luai_apicheck(L,ttistable(o)); +setobj(L,luaH_setnum(L,hvalue(o),n),L->top-1); +luaC_barriert(L,hvalue(o),L->top-1); +L->top--; +} +static int lua_setmetatable(lua_State*L,int objindex){ +TValue*obj; +Table*mt; +api_checknelems(L,1); +obj=index2adr(L,objindex); +api_checkvalidindex(L,obj); +if(ttisnil(L->top-1)) +mt=NULL; +else{ +luai_apicheck(L,ttistable(L->top-1)); +mt=hvalue(L->top-1); +} +switch(ttype(obj)){ +case 5:{ +hvalue(obj)->metatable=mt; +if(mt) +luaC_objbarriert(L,hvalue(obj),mt); +break; +} +case 7:{ +uvalue(obj)->metatable=mt; +if(mt) +luaC_objbarrier(L,rawuvalue(obj),mt); +break; +} +default:{ +G(L)->mt[ttype(obj)]=mt; +break; +} +} +L->top--; +return 1; +} +static int lua_setfenv(lua_State*L,int idx){ +StkId o; +int res=1; +api_checknelems(L,1); +o=index2adr(L,idx); +api_checkvalidindex(L,o); +luai_apicheck(L,ttistable(L->top-1)); +switch(ttype(o)){ +case 6: +clvalue(o)->c.env=hvalue(L->top-1); +break; +case 7: +uvalue(o)->env=hvalue(L->top-1); +break; +case 8: +sethvalue(L,gt(thvalue(o)),hvalue(L->top-1)); +break; +default: +res=0; +break; +} +if(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1)); +L->top--; +return res; +} +#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;} +#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na))) +static void lua_call(lua_State*L,int nargs,int nresults){ +StkId func; +api_checknelems(L,nargs+1); +checkresults(L,nargs,nresults); +func=L->top-(nargs+1); +luaD_call(L,func,nresults); +adjustresults(L,nresults); +} +struct CallS{ +StkId func; +int nresults; +}; +static void f_call(lua_State*L,void*ud){ +struct CallS*c=cast(struct CallS*,ud); +luaD_call(L,c->func,c->nresults); +} +static int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){ +struct CallS c; +int status; +ptrdiff_t func; +api_checknelems(L,nargs+1); +checkresults(L,nargs,nresults); +if(errfunc==0) +func=0; +else{ +StkId o=index2adr(L,errfunc); +api_checkvalidindex(L,o); +func=savestack(L,o); +} +c.func=L->top-(nargs+1); +c.nresults=nresults; +status=luaD_pcall(L,f_call,&c,savestack(L,c.func),func); +adjustresults(L,nresults); +return status; +} +static int lua_load(lua_State*L,lua_Reader reader,void*data, +const char*chunkname){ +ZIO z; +int status; +if(!chunkname)chunkname="?"; +luaZ_init(L,&z,reader,data); +status=luaD_protectedparser(L,&z,chunkname); +return status; +} +static int lua_error(lua_State*L){ +api_checknelems(L,1); +luaG_errormsg(L); +return 0; +} +static int lua_next(lua_State*L,int idx){ +StkId t; +int more; +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +more=luaH_next(L,hvalue(t),L->top-1); +if(more){ +api_incr_top(L); +} +else +L->top-=1; +return more; +} +static void lua_concat(lua_State*L,int n){ +api_checknelems(L,n); +if(n>=2){ +luaC_checkGC(L); +luaV_concat(L,n,cast_int(L->top-L->base)-1); +L->top-=(n-1); +} +else if(n==0){ +setsvalue(L,L->top,luaS_newlstr(L,"",0)); +api_incr_top(L); +} +} +static void*lua_newuserdata(lua_State*L,size_t size){ +Udata*u; +luaC_checkGC(L); +u=luaS_newudata(L,size,getcurrenv(L)); +setuvalue(L,L->top,u); +api_incr_top(L); +return u+1; +} +#define luaL_getn(L,i)((int)lua_objlen(L,i)) +#define luaL_setn(L,i,j)((void)0) +typedef struct luaL_Reg{ +const char*name; +lua_CFunction func; +}luaL_Reg; +static void luaI_openlib(lua_State*L,const char*libname, +const luaL_Reg*l,int nup); +static int luaL_argerror(lua_State*L,int numarg,const char*extramsg); +static const char* luaL_checklstring(lua_State*L,int numArg, +size_t*l); +static const char* luaL_optlstring(lua_State*L,int numArg, +const char*def,size_t*l); +static lua_Integer luaL_checkinteger(lua_State*L,int numArg); +static lua_Integer luaL_optinteger(lua_State*L,int nArg, +lua_Integer def); +static int luaL_error(lua_State*L,const char*fmt,...); +static const char* luaL_findtable(lua_State*L,int idx, +const char*fname,int szhint); +#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg)))) +#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL)) +#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL)) +#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n))) +#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d))) +#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i))) +#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n))) +#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n))) +typedef struct luaL_Buffer{ +char*p; +int lvl; +lua_State*L; +char buffer[BUFSIZ]; +}luaL_Buffer; +#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c))) +#define luaL_addsize(B,n)((B)->p+=(n)) +static char* luaL_prepbuffer(luaL_Buffer*B); +static int luaL_argerror(lua_State*L,int narg,const char*extramsg){ +lua_Debug ar; +if(!lua_getstack(L,0,&ar)) +return luaL_error(L,"bad argument #%d (%s)",narg,extramsg); +lua_getinfo(L,"n",&ar); +if(strcmp(ar.namewhat,"method")==0){ +narg--; +if(narg==0) +return luaL_error(L,"calling "LUA_QL("%s")" on bad self (%s)", +ar.name,extramsg); +} +if(ar.name==NULL) +ar.name="?"; +return luaL_error(L,"bad argument #%d to "LUA_QL("%s")" (%s)", +narg,ar.name,extramsg); +} +static int luaL_typerror(lua_State*L,int narg,const char*tname){ +const char*msg=lua_pushfstring(L,"%s expected, got %s", +tname,luaL_typename(L,narg)); +return luaL_argerror(L,narg,msg); +} +static void tag_error(lua_State*L,int narg,int tag){ +luaL_typerror(L,narg,lua_typename(L,tag)); +} +static void luaL_where(lua_State*L,int level){ +lua_Debug ar; +if(lua_getstack(L,level,&ar)){ +lua_getinfo(L,"Sl",&ar); +if(ar.currentline>0){ +lua_pushfstring(L,"%s:%d: ",ar.short_src,ar.currentline); +return; +} +} +lua_pushliteral(L,""); +} +static int luaL_error(lua_State*L,const char*fmt,...){ +va_list argp; +va_start(argp,fmt); +luaL_where(L,1); +lua_pushvfstring(L,fmt,argp); +va_end(argp); +lua_concat(L,2); +return lua_error(L); +} +static int luaL_newmetatable(lua_State*L,const char*tname){ +lua_getfield(L,(-10000),tname); +if(!lua_isnil(L,-1)) +return 0; +lua_pop(L,1); +lua_newtable(L); +lua_pushvalue(L,-1); +lua_setfield(L,(-10000),tname); +return 1; +} +static void*luaL_checkudata(lua_State*L,int ud,const char*tname){ +void*p=lua_touserdata(L,ud); +if(p!=NULL){ +if(lua_getmetatable(L,ud)){ +lua_getfield(L,(-10000),tname); +if(lua_rawequal(L,-1,-2)){ +lua_pop(L,2); +return p; +} +} +} +luaL_typerror(L,ud,tname); +return NULL; +} +static void luaL_checkstack(lua_State*L,int space,const char*mes){ +if(!lua_checkstack(L,space)) +luaL_error(L,"stack overflow (%s)",mes); +} +static void luaL_checktype(lua_State*L,int narg,int t){ +if(lua_type(L,narg)!=t) +tag_error(L,narg,t); +} +static void luaL_checkany(lua_State*L,int narg){ +if(lua_type(L,narg)==(-1)) +luaL_argerror(L,narg,"value expected"); +} +static const char*luaL_checklstring(lua_State*L,int narg,size_t*len){ +const char*s=lua_tolstring(L,narg,len); +if(!s)tag_error(L,narg,4); +return s; +} +static const char*luaL_optlstring(lua_State*L,int narg, +const char*def,size_t*len){ +if(lua_isnoneornil(L,narg)){ +if(len) +*len=(def?strlen(def):0); +return def; +} +else return luaL_checklstring(L,narg,len); +} +static lua_Number luaL_checknumber(lua_State*L,int narg){ +lua_Number d=lua_tonumber(L,narg); +if(d==0&&!lua_isnumber(L,narg)) +tag_error(L,narg,3); +return d; +} +static lua_Integer luaL_checkinteger(lua_State*L,int narg){ +lua_Integer d=lua_tointeger(L,narg); +if(d==0&&!lua_isnumber(L,narg)) +tag_error(L,narg,3); +return d; +} +static lua_Integer luaL_optinteger(lua_State*L,int narg, +lua_Integer def){ +return luaL_opt(L,luaL_checkinteger,narg,def); +} +static int luaL_getmetafield(lua_State*L,int obj,const char*event){ +if(!lua_getmetatable(L,obj)) +return 0; +lua_pushstring(L,event); +lua_rawget(L,-2); +if(lua_isnil(L,-1)){ +lua_pop(L,2); +return 0; +} +else{ +lua_remove(L,-2); +return 1; +} +} +static void luaL_register(lua_State*L,const char*libname, +const luaL_Reg*l){ +luaI_openlib(L,libname,l,0); +} +static int libsize(const luaL_Reg*l){ +int size=0; +for(;l->name;l++)size++; +return size; +} +static void luaI_openlib(lua_State*L,const char*libname, +const luaL_Reg*l,int nup){ +if(libname){ +int size=libsize(l); +luaL_findtable(L,(-10000),"_LOADED",1); +lua_getfield(L,-1,libname); +if(!lua_istable(L,-1)){ +lua_pop(L,1); +if(luaL_findtable(L,(-10002),libname,size)!=NULL) +luaL_error(L,"name conflict for module "LUA_QL("%s"),libname); +lua_pushvalue(L,-1); +lua_setfield(L,-3,libname); +} +lua_remove(L,-2); +lua_insert(L,-(nup+1)); +} +for(;l->name;l++){ +int i; +for(i=0;ifunc,nup); +lua_setfield(L,-(nup+2),l->name); +} +lua_pop(L,nup); +} +static const char*luaL_findtable(lua_State*L,int idx, +const char*fname,int szhint){ +const char*e; +lua_pushvalue(L,idx); +do{ +e=strchr(fname,'.'); +if(e==NULL)e=fname+strlen(fname); +lua_pushlstring(L,fname,e-fname); +lua_rawget(L,-2); +if(lua_isnil(L,-1)){ +lua_pop(L,1); +lua_createtable(L,0,(*e=='.'?1:szhint)); +lua_pushlstring(L,fname,e-fname); +lua_pushvalue(L,-2); +lua_settable(L,-4); +} +else if(!lua_istable(L,-1)){ +lua_pop(L,2); +return fname; +} +lua_remove(L,-2); +fname=e+1; +}while(*e=='.'); +return NULL; +} +#define bufflen(B)((B)->p-(B)->buffer) +#define bufffree(B)((size_t)(BUFSIZ-bufflen(B))) +static int emptybuffer(luaL_Buffer*B){ +size_t l=bufflen(B); +if(l==0)return 0; +else{ +lua_pushlstring(B->L,B->buffer,l); +B->p=B->buffer; +B->lvl++; +return 1; +} +} +static void adjuststack(luaL_Buffer*B){ +if(B->lvl>1){ +lua_State*L=B->L; +int toget=1; +size_t toplen=lua_strlen(L,-1); +do{ +size_t l=lua_strlen(L,-(toget+1)); +if(B->lvl-toget+1>=(20/2)||toplen>l){ +toplen+=l; +toget++; +} +else break; +}while(togetlvl); +lua_concat(L,toget); +B->lvl=B->lvl-toget+1; +} +} +static char*luaL_prepbuffer(luaL_Buffer*B){ +if(emptybuffer(B)) +adjuststack(B); +return B->buffer; +} +static void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){ +while(l--) +luaL_addchar(B,*s++); +} +static void luaL_pushresult(luaL_Buffer*B){ +emptybuffer(B); +lua_concat(B->L,B->lvl); +B->lvl=1; +} +static void luaL_addvalue(luaL_Buffer*B){ +lua_State*L=B->L; +size_t vl; +const char*s=lua_tolstring(L,-1,&vl); +if(vl<=bufffree(B)){ +memcpy(B->p,s,vl); +B->p+=vl; +lua_pop(L,1); +} +else{ +if(emptybuffer(B)) +lua_insert(L,-2); +B->lvl++; +adjuststack(B); +} +} +static void luaL_buffinit(lua_State*L,luaL_Buffer*B){ +B->L=L; +B->p=B->buffer; +B->lvl=0; +} +typedef struct LoadF{ +int extraline; +FILE*f; +char buff[BUFSIZ]; +}LoadF; +static const char*getF(lua_State*L,void*ud,size_t*size){ +LoadF*lf=(LoadF*)ud; +(void)L; +if(lf->extraline){ +lf->extraline=0; +*size=1; +return"\n"; +} +if(feof(lf->f))return NULL; +*size=fread(lf->buff,1,sizeof(lf->buff),lf->f); +return(*size>0)?lf->buff:NULL; +} +static int errfile(lua_State*L,const char*what,int fnameindex){ +const char*serr=strerror(errno); +const char*filename=lua_tostring(L,fnameindex)+1; +lua_pushfstring(L,"cannot %s %s: %s",what,filename,serr); +lua_remove(L,fnameindex); +return(5+1); +} +static int luaL_loadfile(lua_State*L,const char*filename){ +LoadF lf; +int status,readstatus; +int c; +int fnameindex=lua_gettop(L)+1; +lf.extraline=0; +if(filename==NULL){ +lua_pushliteral(L,"=stdin"); +lf.f=stdin; +} +else{ +lua_pushfstring(L,"@%s",filename); +lf.f=fopen(filename,"r"); +if(lf.f==NULL)return errfile(L,"open",fnameindex); +} +c=getc(lf.f); +if(c=='#'){ +lf.extraline=1; +while((c=getc(lf.f))!=EOF&&c!='\n'); +if(c=='\n')c=getc(lf.f); +} +if(c=="\033Lua"[0]&&filename){ +lf.f=freopen(filename,"rb",lf.f); +if(lf.f==NULL)return errfile(L,"reopen",fnameindex); +while((c=getc(lf.f))!=EOF&&c!="\033Lua"[0]); +lf.extraline=0; +} +ungetc(c,lf.f); +status=lua_load(L,getF,&lf,lua_tostring(L,-1)); +readstatus=ferror(lf.f); +if(filename)fclose(lf.f); +if(readstatus){ +lua_settop(L,fnameindex); +return errfile(L,"read",fnameindex); +} +lua_remove(L,fnameindex); +return status; +} +typedef struct LoadS{ +const char*s; +size_t size; +}LoadS; +static const char*getS(lua_State*L,void*ud,size_t*size){ +LoadS*ls=(LoadS*)ud; +(void)L; +if(ls->size==0)return NULL; +*size=ls->size; +ls->size=0; +return ls->s; +} +static int luaL_loadbuffer(lua_State*L,const char*buff,size_t size, +const char*name){ +LoadS ls; +ls.s=buff; +ls.size=size; +return lua_load(L,getS,&ls,name); +} +static void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){ +(void)ud; +(void)osize; +if(nsize==0){ +free(ptr); +return NULL; +} +else +return realloc(ptr,nsize); +} +static int panic(lua_State*L){ +(void)L; +fprintf(stderr,"PANIC: unprotected error in call to Lua API (%s)\n", +lua_tostring(L,-1)); +return 0; +} +static lua_State*luaL_newstate(void){ +lua_State*L=lua_newstate(l_alloc,NULL); +if(L)lua_atpanic(L,&panic); +return L; +} +static int luaB_tonumber(lua_State*L){ +int base=luaL_optint(L,2,10); +if(base==10){ +luaL_checkany(L,1); +if(lua_isnumber(L,1)){ +lua_pushnumber(L,lua_tonumber(L,1)); +return 1; +} +} +else{ +const char*s1=luaL_checkstring(L,1); +char*s2; +unsigned long n; +luaL_argcheck(L,2<=base&&base<=36,2,"base out of range"); +n=strtoul(s1,&s2,base); +if(s1!=s2){ +while(isspace((unsigned char)(*s2)))s2++; +if(*s2=='\0'){ +lua_pushnumber(L,(lua_Number)n); +return 1; +} +} +} +lua_pushnil(L); +return 1; +} +static int luaB_error(lua_State*L){ +int level=luaL_optint(L,2,1); +lua_settop(L,1); +if(lua_isstring(L,1)&&level>0){ +luaL_where(L,level); +lua_pushvalue(L,1); +lua_concat(L,2); +} +return lua_error(L); +} +static int luaB_setmetatable(lua_State*L){ +int t=lua_type(L,2); +luaL_checktype(L,1,5); +luaL_argcheck(L,t==0||t==5,2, +"nil or table expected"); +if(luaL_getmetafield(L,1,"__metatable")) +luaL_error(L,"cannot change a protected metatable"); +lua_settop(L,2); +lua_setmetatable(L,1); +return 1; +} +static void getfunc(lua_State*L,int opt){ +if(lua_isfunction(L,1))lua_pushvalue(L,1); +else{ +lua_Debug ar; +int level=opt?luaL_optint(L,1,1):luaL_checkint(L,1); +luaL_argcheck(L,level>=0,1,"level must be non-negative"); +if(lua_getstack(L,level,&ar)==0) +luaL_argerror(L,1,"invalid level"); +lua_getinfo(L,"f",&ar); +if(lua_isnil(L,-1)) +luaL_error(L,"no function environment for tail call at level %d", +level); +} +} +static int luaB_setfenv(lua_State*L){ +luaL_checktype(L,2,5); +getfunc(L,0); +lua_pushvalue(L,2); +if(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){ +lua_pushthread(L); +lua_insert(L,-2); +lua_setfenv(L,-2); +return 0; +} +else if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0) +luaL_error(L, +LUA_QL("setfenv")" cannot change environment of given object"); +return 1; +} +static int luaB_rawget(lua_State*L){ +luaL_checktype(L,1,5); +luaL_checkany(L,2); +lua_settop(L,2); +lua_rawget(L,1); +return 1; +} +static int luaB_type(lua_State*L){ +luaL_checkany(L,1); +lua_pushstring(L,luaL_typename(L,1)); +return 1; +} +static int luaB_next(lua_State*L){ +luaL_checktype(L,1,5); +lua_settop(L,2); +if(lua_next(L,1)) +return 2; +else{ +lua_pushnil(L); +return 1; +} +} +static int luaB_pairs(lua_State*L){ +luaL_checktype(L,1,5); +lua_pushvalue(L,lua_upvalueindex(1)); +lua_pushvalue(L,1); +lua_pushnil(L); +return 3; +} +static int ipairsaux(lua_State*L){ +int i=luaL_checkint(L,2); +luaL_checktype(L,1,5); +i++; +lua_pushinteger(L,i); +lua_rawgeti(L,1,i); +return(lua_isnil(L,-1))?0:2; +} +static int luaB_ipairs(lua_State*L){ +luaL_checktype(L,1,5); +lua_pushvalue(L,lua_upvalueindex(1)); +lua_pushvalue(L,1); +lua_pushinteger(L,0); +return 3; +} +static int load_aux(lua_State*L,int status){ +if(status==0) +return 1; +else{ +lua_pushnil(L); +lua_insert(L,-2); +return 2; +} +} +static int luaB_loadstring(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +const char*chunkname=luaL_optstring(L,2,s); +return load_aux(L,luaL_loadbuffer(L,s,l,chunkname)); +} +static int luaB_loadfile(lua_State*L){ +const char*fname=luaL_optstring(L,1,NULL); +return load_aux(L,luaL_loadfile(L,fname)); +} +static int luaB_assert(lua_State*L){ +luaL_checkany(L,1); +if(!lua_toboolean(L,1)) +return luaL_error(L,"%s",luaL_optstring(L,2,"assertion failed!")); +return lua_gettop(L); +} +static int luaB_unpack(lua_State*L){ +int i,e,n; +luaL_checktype(L,1,5); +i=luaL_optint(L,2,1); +e=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1)); +if(i>e)return 0; +n=e-i+1; +if(n<=0||!lua_checkstack(L,n)) +return luaL_error(L,"too many results to unpack"); +lua_rawgeti(L,1,i); +while(i++e)e=pos; +for(i=e;i>pos;i--){ +lua_rawgeti(L,1,i-1); +lua_rawseti(L,1,i); +} +break; +} +default:{ +return luaL_error(L,"wrong number of arguments to "LUA_QL("insert")); +} +} +luaL_setn(L,1,e); +lua_rawseti(L,1,pos); +return 0; +} +static int tremove(lua_State*L){ +int e=aux_getn(L,1); +int pos=luaL_optint(L,2,e); +if(!(1<=pos&&pos<=e)) +return 0; +luaL_setn(L,1,e-1); +lua_rawgeti(L,1,pos); +for(;posu)luaL_error(L,"invalid order function for sorting"); +lua_pop(L,1); +} +while(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){ +if(j0); +} +l=strlen(p); +if(l==0||p[l-1]!='\n') +luaL_addsize(&b,l); +else{ +luaL_addsize(&b,l-1); +luaL_pushresult(&b); +return 1; +} +} +} +static int read_chars(lua_State*L,FILE*f,size_t n){ +size_t rlen; +size_t nr; +luaL_Buffer b; +luaL_buffinit(L,&b); +rlen=BUFSIZ; +do{ +char*p=luaL_prepbuffer(&b); +if(rlen>n)rlen=n; +nr=fread(p,sizeof(char),rlen,f); +luaL_addsize(&b,nr); +n-=nr; +}while(n>0&&nr==rlen); +luaL_pushresult(&b); +return(n==0||lua_objlen(L,-1)>0); +} +static int g_read(lua_State*L,FILE*f,int first){ +int nargs=lua_gettop(L)-1; +int success; +int n; +clearerr(f); +if(nargs==0){ +success=read_line(L,f); +n=first+1; +} +else{ +luaL_checkstack(L,nargs+20,"too many arguments"); +success=1; +for(n=first;nargs--&&success;n++){ +if(lua_type(L,n)==3){ +size_t l=(size_t)lua_tointeger(L,n); +success=(l==0)?test_eof(L,f):read_chars(L,f,l); +} +else{ +const char*p=lua_tostring(L,n); +luaL_argcheck(L,p&&p[0]=='*',n,"invalid option"); +switch(p[1]){ +case'n': +success=read_number(L,f); +break; +case'l': +success=read_line(L,f); +break; +case'a': +read_chars(L,f,~((size_t)0)); +success=1; +break; +default: +return luaL_argerror(L,n,"invalid format"); +} +} +} +} +if(ferror(f)) +return pushresult(L,0,NULL); +if(!success){ +lua_pop(L,1); +lua_pushnil(L); +} +return n-first; +} +static int io_read(lua_State*L){ +return g_read(L,getiofile(L,1),1); +} +static int f_read(lua_State*L){ +return g_read(L,tofile(L),2); +} +static int io_readline(lua_State*L){ +FILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1)); +int sucess; +if(f==NULL) +luaL_error(L,"file is already closed"); +sucess=read_line(L,f); +if(ferror(f)) +return luaL_error(L,"%s",strerror(errno)); +if(sucess)return 1; +else{ +if(lua_toboolean(L,lua_upvalueindex(2))){ +lua_settop(L,0); +lua_pushvalue(L,lua_upvalueindex(1)); +aux_close(L); +} +return 0; +} +} +static int g_write(lua_State*L,FILE*f,int arg){ +int nargs=lua_gettop(L)-1; +int status=1; +for(;nargs--;arg++){ +if(lua_type(L,arg)==3){ +status=status&& +fprintf(f,"%.14g",lua_tonumber(L,arg))>0; +} +else{ +size_t l; +const char*s=luaL_checklstring(L,arg,&l); +status=status&&(fwrite(s,sizeof(char),l,f)==l); +} +} +return pushresult(L,status,NULL); +} +static int io_write(lua_State*L){ +return g_write(L,getiofile(L,2),1); +} +static int f_write(lua_State*L){ +return g_write(L,tofile(L),2); +} +static int io_flush(lua_State*L){ +return pushresult(L,fflush(getiofile(L,2))==0,NULL); +} +static int f_flush(lua_State*L){ +return pushresult(L,fflush(tofile(L))==0,NULL); +} +static const luaL_Reg iolib[]={ +{"close",io_close}, +{"flush",io_flush}, +{"input",io_input}, +{"lines",io_lines}, +{"open",io_open}, +{"output",io_output}, +{"read",io_read}, +{"type",io_type}, +{"write",io_write}, +{NULL,NULL} +}; +static const luaL_Reg flib[]={ +{"close",io_close}, +{"flush",f_flush}, +{"lines",f_lines}, +{"read",f_read}, +{"write",f_write}, +{"__gc",io_gc}, +{NULL,NULL} +}; +static void createmeta(lua_State*L){ +luaL_newmetatable(L,"FILE*"); +lua_pushvalue(L,-1); +lua_setfield(L,-2,"__index"); +luaL_register(L,NULL,flib); +} +static void createstdfile(lua_State*L,FILE*f,int k,const char*fname){ +*newfile(L)=f; +if(k>0){ +lua_pushvalue(L,-1); +lua_rawseti(L,(-10001),k); +} +lua_pushvalue(L,-2); +lua_setfenv(L,-2); +lua_setfield(L,-3,fname); +} +static void newfenv(lua_State*L,lua_CFunction cls){ +lua_createtable(L,0,1); +lua_pushcfunction(L,cls); +lua_setfield(L,-2,"__close"); +} +static int luaopen_io(lua_State*L){ +createmeta(L); +newfenv(L,io_fclose); +lua_replace(L,(-10001)); +luaL_register(L,"io",iolib); +newfenv(L,io_noclose); +createstdfile(L,stdin,1,"stdin"); +createstdfile(L,stdout,2,"stdout"); +createstdfile(L,stderr,0,"stderr"); +lua_pop(L,1); +lua_getfield(L,-1,"popen"); +newfenv(L,io_pclose); +lua_setfenv(L,-2); +lua_pop(L,1); +return 1; +} +static int os_pushresult(lua_State*L,int i,const char*filename){ +int en=errno; +if(i){ +lua_pushboolean(L,1); +return 1; +} +else{ +lua_pushnil(L); +lua_pushfstring(L,"%s: %s",filename,strerror(en)); +lua_pushinteger(L,en); +return 3; +} +} +static int os_remove(lua_State*L){ +const char*filename=luaL_checkstring(L,1); +return os_pushresult(L,remove(filename)==0,filename); +} +static int os_exit(lua_State*L){ +exit(luaL_optint(L,1,EXIT_SUCCESS)); +} +static const luaL_Reg syslib[]={ +{"exit",os_exit}, +{"remove",os_remove}, +{NULL,NULL} +}; +static int luaopen_os(lua_State*L){ +luaL_register(L,"os",syslib); +return 1; +} +#define uchar(c)((unsigned char)(c)) +static ptrdiff_t posrelat(ptrdiff_t pos,size_t len){ +if(pos<0)pos+=(ptrdiff_t)len+1; +return(pos>=0)?pos:0; +} +static int str_sub(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +ptrdiff_t start=posrelat(luaL_checkinteger(L,2),l); +ptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l); +if(start<1)start=1; +if(end>(ptrdiff_t)l)end=(ptrdiff_t)l; +if(start<=end) +lua_pushlstring(L,s+start-1,end-start+1); +else lua_pushliteral(L,""); +return 1; +} +static int str_lower(lua_State*L){ +size_t l; +size_t i; +luaL_Buffer b; +const char*s=luaL_checklstring(L,1,&l); +luaL_buffinit(L,&b); +for(i=0;i0) +luaL_addlstring(&b,s,l); +luaL_pushresult(&b); +return 1; +} +static int str_byte(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +ptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l); +ptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l); +int n,i; +if(posi<=0)posi=1; +if((size_t)pose>l)pose=l; +if(posi>pose)return 0; +n=(int)(pose-posi+1); +if(posi+n<=pose) +luaL_error(L,"string slice too long"); +luaL_checkstack(L,n,"string slice too long"); +for(i=0;i=ms->level||ms->capture[l].len==(-1)) +return luaL_error(ms->L,"invalid capture index"); +return l; +} +static int capture_to_close(MatchState*ms){ +int level=ms->level; +for(level--;level>=0;level--) +if(ms->capture[level].len==(-1))return level; +return luaL_error(ms->L,"invalid pattern capture"); +} +static const char*classend(MatchState*ms,const char*p){ +switch(*p++){ +case'%':{ +if(*p=='\0') +luaL_error(ms->L,"malformed pattern (ends with "LUA_QL("%%")")"); +return p+1; +} +case'[':{ +if(*p=='^')p++; +do{ +if(*p=='\0') +luaL_error(ms->L,"malformed pattern (missing "LUA_QL("]")")"); +if(*(p++)=='%'&&*p!='\0') +p++; +}while(*p!=']'); +return p+1; +} +default:{ +return p; +} +} +} +static int match_class(int c,int cl){ +int res; +switch(tolower(cl)){ +case'a':res=isalpha(c);break; +case'c':res=iscntrl(c);break; +case'd':res=isdigit(c);break; +case'l':res=islower(c);break; +case'p':res=ispunct(c);break; +case's':res=isspace(c);break; +case'u':res=isupper(c);break; +case'w':res=isalnum(c);break; +case'x':res=isxdigit(c);break; +case'z':res=(c==0);break; +default:return(cl==c); +} +return(islower(cl)?res:!res); +} +static int matchbracketclass(int c,const char*p,const char*ec){ +int sig=1; +if(*(p+1)=='^'){ +sig=0; +p++; +} +while(++pL,"unbalanced pattern"); +if(*s!=*p)return NULL; +else{ +int b=*p; +int e=*(p+1); +int cont=1; +while(++ssrc_end){ +if(*s==e){ +if(--cont==0)return s+1; +} +else if(*s==b)cont++; +} +} +return NULL; +} +static const char*max_expand(MatchState*ms,const char*s, +const char*p,const char*ep){ +ptrdiff_t i=0; +while((s+i)src_end&&singlematch(uchar(*(s+i)),p,ep)) +i++; +while(i>=0){ +const char*res=match(ms,(s+i),ep+1); +if(res)return res; +i--; +} +return NULL; +} +static const char*min_expand(MatchState*ms,const char*s, +const char*p,const char*ep){ +for(;;){ +const char*res=match(ms,s,ep+1); +if(res!=NULL) +return res; +else if(ssrc_end&&singlematch(uchar(*s),p,ep)) +s++; +else return NULL; +} +} +static const char*start_capture(MatchState*ms,const char*s, +const char*p,int what){ +const char*res; +int level=ms->level; +if(level>=32)luaL_error(ms->L,"too many captures"); +ms->capture[level].init=s; +ms->capture[level].len=what; +ms->level=level+1; +if((res=match(ms,s,p))==NULL) +ms->level--; +return res; +} +static const char*end_capture(MatchState*ms,const char*s, +const char*p){ +int l=capture_to_close(ms); +const char*res; +ms->capture[l].len=s-ms->capture[l].init; +if((res=match(ms,s,p))==NULL) +ms->capture[l].len=(-1); +return res; +} +static const char*match_capture(MatchState*ms,const char*s,int l){ +size_t len; +l=check_capture(ms,l); +len=ms->capture[l].len; +if((size_t)(ms->src_end-s)>=len&& +memcmp(ms->capture[l].init,s,len)==0) +return s+len; +else return NULL; +} +static const char*match(MatchState*ms,const char*s,const char*p){ +init: +switch(*p){ +case'(':{ +if(*(p+1)==')') +return start_capture(ms,s,p+2,(-2)); +else +return start_capture(ms,s,p+1,(-1)); +} +case')':{ +return end_capture(ms,s,p+1); +} +case'%':{ +switch(*(p+1)){ +case'b':{ +s=matchbalance(ms,s,p+2); +if(s==NULL)return NULL; +p+=4;goto init; +} +case'f':{ +const char*ep;char previous; +p+=2; +if(*p!='[') +luaL_error(ms->L,"missing "LUA_QL("[")" after " +LUA_QL("%%f")" in pattern"); +ep=classend(ms,p); +previous=(s==ms->src_init)?'\0':*(s-1); +if(matchbracketclass(uchar(previous),p,ep-1)|| +!matchbracketclass(uchar(*s),p,ep-1))return NULL; +p=ep;goto init; +} +default:{ +if(isdigit(uchar(*(p+1)))){ +s=match_capture(ms,s,uchar(*(p+1))); +if(s==NULL)return NULL; +p+=2;goto init; +} +goto dflt; +} +} +} +case'\0':{ +return s; +} +case'$':{ +if(*(p+1)=='\0') +return(s==ms->src_end)?s:NULL; +else goto dflt; +} +default:dflt:{ +const char*ep=classend(ms,p); +int m=ssrc_end&&singlematch(uchar(*s),p,ep); +switch(*ep){ +case'?':{ +const char*res; +if(m&&((res=match(ms,s+1,ep+1))!=NULL)) +return res; +p=ep+1;goto init; +} +case'*':{ +return max_expand(ms,s,p,ep); +} +case'+':{ +return(m?max_expand(ms,s+1,p,ep):NULL); +} +case'-':{ +return min_expand(ms,s,p,ep); +} +default:{ +if(!m)return NULL; +s++;p=ep;goto init; +} +} +} +} +} +static const char*lmemfind(const char*s1,size_t l1, +const char*s2,size_t l2){ +if(l2==0)return s1; +else if(l2>l1)return NULL; +else{ +const char*init; +l2--; +l1=l1-l2; +while(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){ +init++; +if(memcmp(init,s2+1,l2)==0) +return init-1; +else{ +l1-=init-s1; +s1=init; +} +} +return NULL; +} +} +static void push_onecapture(MatchState*ms,int i,const char*s, +const char*e){ +if(i>=ms->level){ +if(i==0) +lua_pushlstring(ms->L,s,e-s); +else +luaL_error(ms->L,"invalid capture index"); +} +else{ +ptrdiff_t l=ms->capture[i].len; +if(l==(-1))luaL_error(ms->L,"unfinished capture"); +if(l==(-2)) +lua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1); +else +lua_pushlstring(ms->L,ms->capture[i].init,l); +} +} +static int push_captures(MatchState*ms,const char*s,const char*e){ +int i; +int nlevels=(ms->level==0&&s)?1:ms->level; +luaL_checkstack(ms->L,nlevels,"too many captures"); +for(i=0;il1)init=(ptrdiff_t)l1; +if(find&&(lua_toboolean(L,4)|| +strpbrk(p,"^$*+?.([%-")==NULL)){ +const char*s2=lmemfind(s+init,l1-init,p,l2); +if(s2){ +lua_pushinteger(L,s2-s+1); +lua_pushinteger(L,s2-s+l2); +return 2; +} +} +else{ +MatchState ms; +int anchor=(*p=='^')?(p++,1):0; +const char*s1=s+init; +ms.L=L; +ms.src_init=s; +ms.src_end=s+l1; +do{ +const char*res; +ms.level=0; +if((res=match(&ms,s1,p))!=NULL){ +if(find){ +lua_pushinteger(L,s1-s+1); +lua_pushinteger(L,res-s); +return push_captures(&ms,NULL,0)+2; +} +else +return push_captures(&ms,s1,res); +} +}while(s1++L,3,&l); +for(i=0;iL; +switch(lua_type(L,3)){ +case 3: +case 4:{ +add_s(ms,b,s,e); +return; +} +case 6:{ +int n; +lua_pushvalue(L,3); +n=push_captures(ms,s,e); +lua_call(L,n,1); +break; +} +case 5:{ +push_onecapture(ms,0,s,e); +lua_gettable(L,3); +break; +} +} +if(!lua_toboolean(L,-1)){ +lua_pop(L,1); +lua_pushlstring(L,s,e-s); +} +else if(!lua_isstring(L,-1)) +luaL_error(L,"invalid replacement value (a %s)",luaL_typename(L,-1)); +luaL_addvalue(b); +} +static int str_gsub(lua_State*L){ +size_t srcl; +const char*src=luaL_checklstring(L,1,&srcl); +const char*p=luaL_checkstring(L,2); +int tr=lua_type(L,3); +int max_s=luaL_optint(L,4,srcl+1); +int anchor=(*p=='^')?(p++,1):0; +int n=0; +MatchState ms; +luaL_Buffer b; +luaL_argcheck(L,tr==3||tr==4|| +tr==6||tr==5,3, +"string/function/table expected"); +luaL_buffinit(L,&b); +ms.L=L; +ms.src_init=src; +ms.src_end=src+srcl; +while(nsrc) +src=e; +else if(src=sizeof("-+ #0")) +luaL_error(L,"invalid format (repeated flags)"); +if(isdigit(uchar(*p)))p++; +if(isdigit(uchar(*p)))p++; +if(*p=='.'){ +p++; +if(isdigit(uchar(*p)))p++; +if(isdigit(uchar(*p)))p++; +} +if(isdigit(uchar(*p))) +luaL_error(L,"invalid format (width or precision too long)"); +*(form++)='%'; +strncpy(form,strfrmt,p-strfrmt+1); +form+=p-strfrmt+1; +*form='\0'; +return p; +} +static void addintlen(char*form){ +size_t l=strlen(form); +char spec=form[l-1]; +strcpy(form+l-1,"l"); +form[l+sizeof("l")-2]=spec; +form[l+sizeof("l")-1]='\0'; +} +static int str_format(lua_State*L){ +int top=lua_gettop(L); +int arg=1; +size_t sfl; +const char*strfrmt=luaL_checklstring(L,arg,&sfl); +const char*strfrmt_end=strfrmt+sfl; +luaL_Buffer b; +luaL_buffinit(L,&b); +while(strfrmttop) +luaL_argerror(L,arg,"no value"); +strfrmt=scanformat(L,strfrmt,form); +switch(*strfrmt++){ +case'c':{ +sprintf(buff,form,(int)luaL_checknumber(L,arg)); +break; +} +case'd':case'i':{ +addintlen(form); +sprintf(buff,form,(long)luaL_checknumber(L,arg)); +break; +} +case'o':case'u':case'x':case'X':{ +addintlen(form); +sprintf(buff,form,(unsigned long)luaL_checknumber(L,arg)); +break; +} +case'e':case'E':case'f': +case'g':case'G':{ +sprintf(buff,form,(double)luaL_checknumber(L,arg)); +break; +} +case'q':{ +addquoted(L,&b,arg); +continue; +} +case's':{ +size_t l; +const char*s=luaL_checklstring(L,arg,&l); +if(!strchr(form,'.')&&l>=100){ +lua_pushvalue(L,arg); +luaL_addvalue(&b); +continue; +} +else{ +sprintf(buff,form,s); +break; +} +} +default:{ +return luaL_error(L,"invalid option "LUA_QL("%%%c")" to " +LUA_QL("format"),*(strfrmt-1)); +} +} +luaL_addlstring(&b,buff,strlen(buff)); +} +} +luaL_pushresult(&b); +return 1; +} +static const luaL_Reg strlib[]={ +{"byte",str_byte}, +{"char",str_char}, +{"find",str_find}, +{"format",str_format}, +{"gmatch",gmatch}, +{"gsub",str_gsub}, +{"lower",str_lower}, +{"match",str_match}, +{"rep",str_rep}, +{"sub",str_sub}, +{"upper",str_upper}, +{NULL,NULL} +}; +static void createmetatable(lua_State*L){ +lua_createtable(L,0,1); +lua_pushliteral(L,""); +lua_pushvalue(L,-2); +lua_setmetatable(L,-2); +lua_pop(L,1); +lua_pushvalue(L,-2); +lua_setfield(L,-2,"__index"); +lua_pop(L,1); +} +static int luaopen_string(lua_State*L){ +luaL_register(L,"string",strlib); +createmetatable(L); +return 1; +} +static const luaL_Reg lualibs[]={ +{"",luaopen_base}, +{"table",luaopen_table}, +{"io",luaopen_io}, +{"os",luaopen_os}, +{"string",luaopen_string}, +{NULL,NULL} +}; +static void luaL_openlibs(lua_State*L){ +const luaL_Reg*lib=lualibs; +for(;lib->func;lib++){ +lua_pushcfunction(L,lib->func); +lua_pushstring(L,lib->name); +lua_call(L,1,0); +} +} +typedef unsigned int UB; +static UB barg(lua_State*L,int idx){ +union{lua_Number n;U64 b;}bn; +bn.n=lua_tonumber(L,idx)+6755399441055744.0; +if(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number"); +return(UB)bn.b; +} +#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1; +static int tobit(lua_State*L){ +BRET(barg(L,1))} +static int bnot(lua_State*L){ +BRET(~barg(L,1))} +static int band(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)} +static int bor(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)} +static int bxor(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)} +static int lshift(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET(b<>n)} +static int arshift(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)} +static int rol(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b<>(32-n)))} +static int ror(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))} +static int bswap(lua_State*L){ +UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} +static int tohex(lua_State*L){ +UB b=barg(L,1); +int n=lua_isnone(L,2)?8:(int)barg(L,2); +const char*hexdigits="0123456789abcdef"; +char buf[8]; +int i; +if(n<0){n=-n;hexdigits="0123456789ABCDEF";} +if(n>8)n=8; +for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} +lua_pushlstring(L,buf,(size_t)n); +return 1; +} +static const struct luaL_Reg bitlib[]={ +{"tobit",tobit}, +{"bnot",bnot}, +{"band",band}, +{"bor",bor}, +{"bxor",bxor}, +{"lshift",lshift}, +{"rshift",rshift}, +{"arshift",arshift}, +{"rol",rol}, +{"ror",ror}, +{"bswap",bswap}, +{"tohex",tohex}, +{NULL,NULL} +}; +int main(int argc,char**argv){ +lua_State*L=luaL_newstate(); +int i; +luaL_openlibs(L); +luaL_register(L,"bit",bitlib); +if(argc<2)return sizeof(void*); +lua_createtable(L,0,1); +lua_pushstring(L,argv[1]); +lua_rawseti(L,-2,0); +lua_setglobal(L,"arg"); +if(luaL_loadfile(L,argv[1])) +goto err; +for(i=2;i -- BYTECODE -- [...] +-- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello" +-- +-- local out = { +-- -- Do something with each line: +-- write = function(t, ...) io.write(...) end, +-- close = function(t) end, +-- flush = function(t) end, +-- } +-- bc.dump(foo, out) +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local bit = require("bit") +local sub, gsub, format = string.sub, string.gsub, string.format +local byte, band, shr = string.byte, bit.band, bit.rshift +local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck +local funcuvname = jutil.funcuvname +local bcnames = vmdef.bcnames +local stdout, stderr = io.stdout, io.stderr + +------------------------------------------------------------------------------ + +local function ctlsub(c) + if c == "\n" then return "\\n" + elseif c == "\r" then return "\\r" + elseif c == "\t" then return "\\t" + else return format("\\%03d", byte(c)) + end +end + +-- Return one bytecode line. +local function bcline(func, pc, prefix) + local ins, m = funcbc(func, pc) + if not ins then return end + local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128) + local a = band(shr(ins, 8), 0xff) + local oidx = 6*band(ins, 0xff) + local op = sub(bcnames, oidx+1, oidx+6) + local s = format("%04d %s %-6s %3s ", + pc, prefix or " ", op, ma == 0 and "" or a) + local d = shr(ins, 16) + if mc == 13*128 then -- BCMjump + return format("%s=> %04d\n", s, pc+d-0x7fff) + end + if mb ~= 0 then + d = band(d, 0xff) + elseif mc == 0 then + return s.."\n" + end + local kc + if mc == 10*128 then -- BCMstr + kc = funck(func, -d-1) + kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub)) + elseif mc == 9*128 then -- BCMnum + kc = funck(func, d) + if op == "TSETM " then kc = kc - 2^52 end + elseif mc == 12*128 then -- BCMfunc + local fi = funcinfo(funck(func, -d-1)) + if fi.ffid then + kc = vmdef.ffnames[fi.ffid] + else + kc = fi.loc + end + elseif mc == 5*128 then -- BCMuv + kc = funcuvname(func, d) + end + if ma == 5 then -- BCMuv + local ka = funcuvname(func, a) + if kc then kc = ka.." ; "..kc else kc = ka end + end + if mb ~= 0 then + local b = shr(ins, 24) + if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end + return format("%s%3d %3d\n", s, b, d) + end + if kc then return format("%s%3d ; %s\n", s, d, kc) end + if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits + return format("%s%3d\n", s, d) +end + +-- Collect branch targets of a function. +local function bctargets(func) + local target = {} + for pc=1,1000000000 do + local ins, m = funcbc(func, pc) + if not ins then break end + if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end + end + return target +end + +-- Dump bytecode instructions of a function. +local function bcdump(func, out, all) + if not out then out = stdout end + local fi = funcinfo(func) + if all and fi.children then + for n=-1,-1000000000,-1 do + local k = funck(func, n) + if not k then break end + if type(k) == "proto" then bcdump(k, out, true) end + end + end + out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined)) + local target = bctargets(func) + for pc=1,1000000000 do + local s = bcline(func, pc, target[pc] and "=>") + if not s then break end + out:write(s) + end + out:write("\n") + out:flush() +end + +------------------------------------------------------------------------------ + +-- Active flag and output file handle. +local active, out + +-- List handler. +local function h_list(func) + return bcdump(func, out) +end + +-- Detach list handler. +local function bclistoff() + if active then + active = false + jit.attach(h_list) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach list handler. +local function bcliston(outfile) + if active then bclistoff() end + if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stderr + end + jit.attach(h_list, "bc") + active = true +end + +-- Public module functions. +module(...) + +line = bcline +dump = bcdump +targets = bctargets + +on = bcliston +off = bclistoff +start = bcliston -- For -j command line option. + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/bcsave.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/bcsave.lua new file mode 100644 index 0000000..f55bda9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/bcsave.lua @@ -0,0 +1,659 @@ +---------------------------------------------------------------------------- +-- LuaJIT module to save/list bytecode. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module saves or lists the bytecode for an input file. +-- It's run by the -b command line option. +-- +------------------------------------------------------------------------------ + +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local bit = require("bit") + +-- Symbol name prefix for LuaJIT bytecode. +local LJBC_PREFIX = "luaJIT_BC_" + +------------------------------------------------------------------------------ + +local function usage() + io.stderr:write[[ +Save LuaJIT bytecode: luajit -b[options] input output + -l Only list bytecode. + -s Strip debug info (default). + -g Keep debug info. + -n name Set module name (default: auto-detect from input name). + -t type Set output file type (default: auto-detect from output name). + -a arch Override architecture for object files (default: native). + -o os Override OS for object files (default: native). + -e chunk Use chunk string as input. + -- Stop handling options. + - Use stdin as input and/or stdout as output. + +File types: c h obj o raw (default) +]] + os.exit(1) +end + +local function check(ok, ...) + if ok then return ok, ... end + io.stderr:write("luajit: ", ...) + io.stderr:write("\n") + os.exit(1) +end + +local function readfile(input) + if type(input) == "function" then return input end + if input == "-" then input = nil end + return check(loadfile(input)) +end + +local function savefile(name, mode) + if name == "-" then return io.stdout end + return check(io.open(name, mode)) +end + +------------------------------------------------------------------------------ + +local map_type = { + raw = "raw", c = "c", h = "h", o = "obj", obj = "obj", +} + +local map_arch = { + x86 = true, x64 = true, arm = true, ppc = true, ppcspe = true, + mips = true, mipsel = true, +} + +local map_os = { + linux = true, windows = true, osx = true, freebsd = true, netbsd = true, + openbsd = true, solaris = true, +} + +local function checkarg(str, map, err) + str = string.lower(str) + local s = check(map[str], "unknown ", err) + return s == true and str or s +end + +local function detecttype(str) + local ext = string.match(string.lower(str), "%.(%a+)$") + return map_type[ext] or "raw" +end + +local function checkmodname(str) + check(string.match(str, "^[%w_.%-]+$"), "bad module name") + return string.gsub(str, "[%.%-]", "_") +end + +local function detectmodname(str) + if type(str) == "string" then + local tail = string.match(str, "[^/\\]+$") + if tail then str = tail end + local head = string.match(str, "^(.*)%.[^.]*$") + if head then str = head end + str = string.match(str, "^[%w_.%-]+") + else + str = nil + end + check(str, "cannot derive module name, use -n name") + return string.gsub(str, "[%.%-]", "_") +end + +------------------------------------------------------------------------------ + +local function bcsave_tail(fp, output, s) + local ok, err = fp:write(s) + if ok and output ~= "-" then ok, err = fp:close() end + check(ok, "cannot write ", output, ": ", err) +end + +local function bcsave_raw(output, s) + local fp = savefile(output, "wb") + bcsave_tail(fp, output, s) +end + +local function bcsave_c(ctx, output, s) + local fp = savefile(output, "w") + if ctx.type == "c" then + fp:write(string.format([[ +#ifdef _cplusplus +extern "C" +#endif +#ifdef _WIN32 +__declspec(dllexport) +#endif +const char %s%s[] = { +]], LJBC_PREFIX, ctx.modname)) + else + fp:write(string.format([[ +#define %s%s_SIZE %d +static const char %s%s[] = { +]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname)) + end + local t, n, m = {}, 0, 0 + for i=1,#s do + local b = tostring(string.byte(s, i)) + m = m + #b + 1 + if m > 78 then + fp:write(table.concat(t, ",", 1, n), ",\n") + n, m = 0, #b + 1 + end + n = n + 1 + t[n] = b + end + bcsave_tail(fp, output, table.concat(t, ",", 1, n).."\n};\n") +end + +local function bcsave_elfobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct { + uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7]; + uint16_t type, machine; + uint32_t version; + uint32_t entry, phofs, shofs; + uint32_t flags; + uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx; +} ELF32header; +typedef struct { + uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7]; + uint16_t type, machine; + uint32_t version; + uint64_t entry, phofs, shofs; + uint32_t flags; + uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx; +} ELF64header; +typedef struct { + uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize; +} ELF32sectheader; +typedef struct { + uint32_t name, type; + uint64_t flags, addr, ofs, size; + uint32_t link, info; + uint64_t align, entsize; +} ELF64sectheader; +typedef struct { + uint32_t name, value, size; + uint8_t info, other; + uint16_t sectidx; +} ELF32symbol; +typedef struct { + uint32_t name; + uint8_t info, other; + uint16_t sectidx; + uint64_t value, size; +} ELF64symbol; +typedef struct { + ELF32header hdr; + ELF32sectheader sect[6]; + ELF32symbol sym[2]; + uint8_t space[4096]; +} ELF32obj; +typedef struct { + ELF64header hdr; + ELF64sectheader sect[6]; + ELF64symbol sym[2]; + uint8_t space[4096]; +} ELF64obj; +]] + local symname = LJBC_PREFIX..ctx.modname + local is64, isbe = false, false + if ctx.arch == "x64" then + is64 = true + elseif ctx.arch == "ppc" or ctx.arch == "ppcspe" or ctx.arch == "mips" then + isbe = true + end + + -- Handle different host/target endianess. + local function f32(x) return x end + local f16, fofs = f32, f32 + if ffi.abi("be") ~= isbe then + f32 = bit.bswap + function f16(x) return bit.rshift(bit.bswap(x), 16) end + if is64 then + local two32 = ffi.cast("int64_t", 2^32) + function fofs(x) return bit.bswap(x)*two32 end + else + fofs = f32 + end + end + + -- Create ELF object and fill in header. + local o = ffi.new(is64 and "ELF64obj" or "ELF32obj") + local hdr = o.hdr + if ctx.os == "bsd" or ctx.os == "other" then -- Determine native hdr.eosabi. + local bf = assert(io.open("/bin/ls", "rb")) + local bs = bf:read(9) + bf:close() + ffi.copy(o, bs, 9) + check(hdr.emagic[0] == 127, "no support for writing native object files") + else + hdr.emagic = "\127ELF" + hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0 + end + hdr.eclass = is64 and 2 or 1 + hdr.eendian = isbe and 2 or 1 + hdr.eversion = 1 + hdr.type = f16(1) + hdr.machine = f16(({ x86=3, x64=62, arm=40, ppc=20, ppcspe=20, mips=8, mipsel=8 })[ctx.arch]) + if ctx.arch == "mips" or ctx.arch == "mipsel" then + hdr.flags = 0x50001006 + end + hdr.version = f32(1) + hdr.shofs = fofs(ffi.offsetof(o, "sect")) + hdr.ehsize = f16(ffi.sizeof(hdr)) + hdr.shentsize = f16(ffi.sizeof(o.sect[0])) + hdr.shnum = f16(6) + hdr.shstridx = f16(2) + + -- Fill in sections and symbols. + local sofs, ofs = ffi.offsetof(o, "space"), 1 + for i,name in ipairs{ + ".symtab", ".shstrtab", ".strtab", ".rodata", ".note.GNU-stack", + } do + local sect = o.sect[i] + sect.align = fofs(1) + sect.name = f32(ofs) + ffi.copy(o.space+ofs, name) + ofs = ofs + #name+1 + end + o.sect[1].type = f32(2) -- .symtab + o.sect[1].link = f32(3) + o.sect[1].info = f32(1) + o.sect[1].align = fofs(8) + o.sect[1].ofs = fofs(ffi.offsetof(o, "sym")) + o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0])) + o.sect[1].size = fofs(ffi.sizeof(o.sym)) + o.sym[1].name = f32(1) + o.sym[1].sectidx = f16(4) + o.sym[1].size = fofs(#s) + o.sym[1].info = 17 + o.sect[2].type = f32(3) -- .shstrtab + o.sect[2].ofs = fofs(sofs) + o.sect[2].size = fofs(ofs) + o.sect[3].type = f32(3) -- .strtab + o.sect[3].ofs = fofs(sofs + ofs) + o.sect[3].size = fofs(#symname+1) + ffi.copy(o.space+ofs+1, symname) + ofs = ofs + #symname + 2 + o.sect[4].type = f32(1) -- .rodata + o.sect[4].flags = fofs(2) + o.sect[4].ofs = fofs(sofs + ofs) + o.sect[4].size = fofs(#s) + o.sect[5].type = f32(1) -- .note.GNU-stack + o.sect[5].ofs = fofs(sofs + ofs + #s) + + -- Write ELF object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs)) + bcsave_tail(fp, output, s) +end + +local function bcsave_peobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct { + uint16_t arch, nsects; + uint32_t time, symtabofs, nsyms; + uint16_t opthdrsz, flags; +} PEheader; +typedef struct { + char name[8]; + uint32_t vsize, vaddr, size, ofs, relocofs, lineofs; + uint16_t nreloc, nline; + uint32_t flags; +} PEsection; +typedef struct __attribute((packed)) { + union { + char name[8]; + uint32_t nameref[2]; + }; + uint32_t value; + int16_t sect; + uint16_t type; + uint8_t scl, naux; +} PEsym; +typedef struct __attribute((packed)) { + uint32_t size; + uint16_t nreloc, nline; + uint32_t cksum; + uint16_t assoc; + uint8_t comdatsel, unused[3]; +} PEsymaux; +typedef struct { + PEheader hdr; + PEsection sect[2]; + // Must be an even number of symbol structs. + PEsym sym0; + PEsymaux sym0aux; + PEsym sym1; + PEsymaux sym1aux; + PEsym sym2; + PEsym sym3; + uint32_t strtabsize; + uint8_t space[4096]; +} PEobj; +]] + local symname = LJBC_PREFIX..ctx.modname + local is64 = false + if ctx.arch == "x86" then + symname = "_"..symname + elseif ctx.arch == "x64" then + is64 = true + end + local symexport = " /EXPORT:"..symname..",DATA " + + -- The file format is always little-endian. Swap if the host is big-endian. + local function f32(x) return x end + local f16 = f32 + if ffi.abi("be") then + f32 = bit.bswap + function f16(x) return bit.rshift(bit.bswap(x), 16) end + end + + -- Create PE object and fill in header. + local o = ffi.new("PEobj") + local hdr = o.hdr + hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2, mips=0x366, mipsel=0x366 })[ctx.arch]) + hdr.nsects = f16(2) + hdr.symtabofs = f32(ffi.offsetof(o, "sym0")) + hdr.nsyms = f32(6) + + -- Fill in sections and symbols. + o.sect[0].name = ".drectve" + o.sect[0].size = f32(#symexport) + o.sect[0].flags = f32(0x00100a00) + o.sym0.sect = f16(1) + o.sym0.scl = 3 + o.sym0.name = ".drectve" + o.sym0.naux = 1 + o.sym0aux.size = f32(#symexport) + o.sect[1].name = ".rdata" + o.sect[1].size = f32(#s) + o.sect[1].flags = f32(0x40300040) + o.sym1.sect = f16(2) + o.sym1.scl = 3 + o.sym1.name = ".rdata" + o.sym1.naux = 1 + o.sym1aux.size = f32(#s) + o.sym2.sect = f16(2) + o.sym2.scl = 2 + o.sym2.nameref[1] = f32(4) + o.sym3.sect = f16(-1) + o.sym3.scl = 2 + o.sym3.value = f32(1) + o.sym3.name = "@feat.00" -- Mark as SafeSEH compliant. + ffi.copy(o.space, symname) + local ofs = #symname + 1 + o.strtabsize = f32(ofs + 4) + o.sect[0].ofs = f32(ffi.offsetof(o, "space") + ofs) + ffi.copy(o.space + ofs, symexport) + ofs = ofs + #symexport + o.sect[1].ofs = f32(ffi.offsetof(o, "space") + ofs) + + -- Write PE object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs)) + bcsave_tail(fp, output, s) +end + +local function bcsave_machobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct +{ + uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags; +} mach_header; +typedef struct +{ + mach_header; uint32_t reserved; +} mach_header_64; +typedef struct { + uint32_t cmd, cmdsize; + char segname[16]; + uint32_t vmaddr, vmsize, fileoff, filesize; + uint32_t maxprot, initprot, nsects, flags; +} mach_segment_command; +typedef struct { + uint32_t cmd, cmdsize; + char segname[16]; + uint64_t vmaddr, vmsize, fileoff, filesize; + uint32_t maxprot, initprot, nsects, flags; +} mach_segment_command_64; +typedef struct { + char sectname[16], segname[16]; + uint32_t addr, size; + uint32_t offset, align, reloff, nreloc, flags; + uint32_t reserved1, reserved2; +} mach_section; +typedef struct { + char sectname[16], segname[16]; + uint64_t addr, size; + uint32_t offset, align, reloff, nreloc, flags; + uint32_t reserved1, reserved2, reserved3; +} mach_section_64; +typedef struct { + uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize; +} mach_symtab_command; +typedef struct { + int32_t strx; + uint8_t type, sect; + int16_t desc; + uint32_t value; +} mach_nlist; +typedef struct { + uint32_t strx; + uint8_t type, sect; + uint16_t desc; + uint64_t value; +} mach_nlist_64; +typedef struct +{ + uint32_t magic, nfat_arch; +} mach_fat_header; +typedef struct +{ + uint32_t cputype, cpusubtype, offset, size, align; +} mach_fat_arch; +typedef struct { + struct { + mach_header hdr; + mach_segment_command seg; + mach_section sec; + mach_symtab_command sym; + } arch[1]; + mach_nlist sym_entry; + uint8_t space[4096]; +} mach_obj; +typedef struct { + struct { + mach_header_64 hdr; + mach_segment_command_64 seg; + mach_section_64 sec; + mach_symtab_command sym; + } arch[1]; + mach_nlist_64 sym_entry; + uint8_t space[4096]; +} mach_obj_64; +typedef struct { + mach_fat_header fat; + mach_fat_arch fat_arch[4]; + struct { + mach_header hdr; + mach_segment_command seg; + mach_section sec; + mach_symtab_command sym; + } arch[4]; + mach_nlist sym_entry; + uint8_t space[4096]; +} mach_fat_obj; +]] + local symname = '_'..LJBC_PREFIX..ctx.modname + local isfat, is64, align, mobj = false, false, 4, "mach_obj" + if ctx.arch == "x64" then + is64, align, mobj = true, 8, "mach_obj_64" + elseif ctx.arch == "arm" then + isfat, mobj = true, "mach_fat_obj" + else + check(ctx.arch == "x86", "unsupported architecture for OSX") + end + local function aligned(v, a) return bit.band(v+a-1, -a) end + local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE. + + -- Create Mach-O object and fill in header. + local o = ffi.new(mobj) + local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align) + local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12,12,12} })[ctx.arch] + local cpusubtype = ({ x86={3}, x64={3}, arm={3,6,9,11} })[ctx.arch] + if isfat then + o.fat.magic = be32(0xcafebabe) + o.fat.nfat_arch = be32(#cpusubtype) + end + + -- Fill in sections and symbols. + for i=0,#cpusubtype-1 do + local ofs = 0 + if isfat then + local a = o.fat_arch[i] + a.cputype = be32(cputype[i+1]) + a.cpusubtype = be32(cpusubtype[i+1]) + -- Subsequent slices overlap each other to share data. + ofs = ffi.offsetof(o, "arch") + i*ffi.sizeof(o.arch[0]) + a.offset = be32(ofs) + a.size = be32(mach_size-ofs+#s) + end + local a = o.arch[i] + a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface + a.hdr.cputype = cputype[i+1] + a.hdr.cpusubtype = cpusubtype[i+1] + a.hdr.filetype = 1 + a.hdr.ncmds = 2 + a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym) + a.seg.cmd = is64 and 0x19 or 0x1 + a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec) + a.seg.vmsize = #s + a.seg.fileoff = mach_size-ofs + a.seg.filesize = #s + a.seg.maxprot = 1 + a.seg.initprot = 1 + a.seg.nsects = 1 + ffi.copy(a.sec.sectname, "__data") + ffi.copy(a.sec.segname, "__DATA") + a.sec.size = #s + a.sec.offset = mach_size-ofs + a.sym.cmd = 2 + a.sym.cmdsize = ffi.sizeof(a.sym) + a.sym.symoff = ffi.offsetof(o, "sym_entry")-ofs + a.sym.nsyms = 1 + a.sym.stroff = ffi.offsetof(o, "sym_entry")+ffi.sizeof(o.sym_entry)-ofs + a.sym.strsize = aligned(#symname+2, align) + end + o.sym_entry.type = 0xf + o.sym_entry.sect = 1 + o.sym_entry.strx = 1 + ffi.copy(o.space+1, symname) + + -- Write Macho-O object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, mach_size)) + bcsave_tail(fp, output, s) +end + +local function bcsave_obj(ctx, output, s) + local ok, ffi = pcall(require, "ffi") + check(ok, "FFI library required to write this file type") + if ctx.os == "windows" then + return bcsave_peobj(ctx, output, s, ffi) + elseif ctx.os == "osx" then + return bcsave_machobj(ctx, output, s, ffi) + else + return bcsave_elfobj(ctx, output, s, ffi) + end +end + +------------------------------------------------------------------------------ + +local function bclist(input, output) + local f = readfile(input) + require("jit.bc").dump(f, savefile(output, "w"), true) +end + +local function bcsave(ctx, input, output) + local f = readfile(input) + local s = string.dump(f, ctx.strip) + local t = ctx.type + if not t then + t = detecttype(output) + ctx.type = t + end + if t == "raw" then + bcsave_raw(output, s) + else + if not ctx.modname then ctx.modname = detectmodname(input) end + if t == "obj" then + bcsave_obj(ctx, output, s) + else + bcsave_c(ctx, output, s) + end + end +end + +local function docmd(...) + local arg = {...} + local n = 1 + local list = false + local ctx = { + strip = true, arch = jit.arch, os = string.lower(jit.os), + type = false, modname = false, + } + while n <= #arg do + local a = arg[n] + if type(a) == "string" and string.sub(a, 1, 1) == "-" and a ~= "-" then + table.remove(arg, n) + if a == "--" then break end + for m=2,#a do + local opt = string.sub(a, m, m) + if opt == "l" then + list = true + elseif opt == "s" then + ctx.strip = true + elseif opt == "g" then + ctx.strip = false + else + if arg[n] == nil or m ~= #a then usage() end + if opt == "e" then + if n ~= 1 then usage() end + arg[1] = check(loadstring(arg[1])) + elseif opt == "n" then + ctx.modname = checkmodname(table.remove(arg, n)) + elseif opt == "t" then + ctx.type = checkarg(table.remove(arg, n), map_type, "file type") + elseif opt == "a" then + ctx.arch = checkarg(table.remove(arg, n), map_arch, "architecture") + elseif opt == "o" then + ctx.os = checkarg(table.remove(arg, n), map_os, "OS name") + else + usage() + end + end + end + else + n = n + 1 + end + end + if list then + if #arg == 0 or #arg > 2 then usage() end + bclist(arg[1], arg[2] or "-") + else + if #arg ~= 2 then usage() end + bcsave(ctx, arg[1], arg[2]) + end +end + +------------------------------------------------------------------------------ + +-- Public module functions. +module(...) + +start = docmd -- Process -b command line option. + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_arm.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_arm.lua new file mode 100644 index 0000000..b3d0ebc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_arm.lua @@ -0,0 +1,689 @@ +---------------------------------------------------------------------------- +-- LuaJIT ARM disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles most user-mode ARMv7 instructions +-- NYI: Advanced SIMD and VFP instructions. +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, ror, tohex = bit.band, bit.bor, bit.ror, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Opcode maps +------------------------------------------------------------------------------ + +local map_loadc = { + shift = 8, mask = 15, + [10] = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "vmovFmDN", "vstmFNdr", + _ = { + shift = 21, mask = 1, + [0] = "vstrFdl", + { shift = 16, mask = 15, [13] = "vpushFdr", _ = "vstmdbFNdr", } + }, + }, + { + shift = 23, mask = 3, + [0] = "vmovFDNm", + { shift = 16, mask = 15, [13] = "vpopFdr", _ = "vldmFNdr", }, + _ = { + shift = 21, mask = 1, + [0] = "vldrFdl", "vldmdbFNdr", + }, + }, + }, + [11] = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "vmovGmDN", "vstmGNdr", + _ = { + shift = 21, mask = 1, + [0] = "vstrGdl", + { shift = 16, mask = 15, [13] = "vpushGdr", _ = "vstmdbGNdr", } + }, + }, + { + shift = 23, mask = 3, + [0] = "vmovGDNm", + { shift = 16, mask = 15, [13] = "vpopGdr", _ = "vldmGNdr", }, + _ = { + shift = 21, mask = 1, + [0] = "vldrGdl", "vldmdbGNdr", + }, + }, + }, + _ = { + shift = 0, mask = 0 -- NYI ldc, mcrr, mrrc. + }, +} + +local map_vfps = { + shift = 6, mask = 0x2c001, + [0] = "vmlaF.dnm", "vmlsF.dnm", + [0x04000] = "vnmlsF.dnm", [0x04001] = "vnmlaF.dnm", + [0x08000] = "vmulF.dnm", [0x08001] = "vnmulF.dnm", + [0x0c000] = "vaddF.dnm", [0x0c001] = "vsubF.dnm", + [0x20000] = "vdivF.dnm", + [0x24000] = "vfnmsF.dnm", [0x24001] = "vfnmaF.dnm", + [0x28000] = "vfmaF.dnm", [0x28001] = "vfmsF.dnm", + [0x2c000] = "vmovF.dY", + [0x2c001] = { + shift = 7, mask = 0x1e01, + [0] = "vmovF.dm", "vabsF.dm", + [0x0200] = "vnegF.dm", [0x0201] = "vsqrtF.dm", + [0x0800] = "vcmpF.dm", [0x0801] = "vcmpeF.dm", + [0x0a00] = "vcmpzF.d", [0x0a01] = "vcmpzeF.d", + [0x0e01] = "vcvtG.dF.m", + [0x1000] = "vcvt.f32.u32Fdm", [0x1001] = "vcvt.f32.s32Fdm", + [0x1800] = "vcvtr.u32F.dm", [0x1801] = "vcvt.u32F.dm", + [0x1a00] = "vcvtr.s32F.dm", [0x1a01] = "vcvt.s32F.dm", + }, +} + +local map_vfpd = { + shift = 6, mask = 0x2c001, + [0] = "vmlaG.dnm", "vmlsG.dnm", + [0x04000] = "vnmlsG.dnm", [0x04001] = "vnmlaG.dnm", + [0x08000] = "vmulG.dnm", [0x08001] = "vnmulG.dnm", + [0x0c000] = "vaddG.dnm", [0x0c001] = "vsubG.dnm", + [0x20000] = "vdivG.dnm", + [0x24000] = "vfnmsG.dnm", [0x24001] = "vfnmaG.dnm", + [0x28000] = "vfmaG.dnm", [0x28001] = "vfmsG.dnm", + [0x2c000] = "vmovG.dY", + [0x2c001] = { + shift = 7, mask = 0x1e01, + [0] = "vmovG.dm", "vabsG.dm", + [0x0200] = "vnegG.dm", [0x0201] = "vsqrtG.dm", + [0x0800] = "vcmpG.dm", [0x0801] = "vcmpeG.dm", + [0x0a00] = "vcmpzG.d", [0x0a01] = "vcmpzeG.d", + [0x0e01] = "vcvtF.dG.m", + [0x1000] = "vcvt.f64.u32GdFm", [0x1001] = "vcvt.f64.s32GdFm", + [0x1800] = "vcvtr.u32FdG.m", [0x1801] = "vcvt.u32FdG.m", + [0x1a00] = "vcvtr.s32FdG.m", [0x1a01] = "vcvt.s32FdG.m", + }, +} + +local map_datac = { + shift = 24, mask = 1, + [0] = { + shift = 4, mask = 1, + [0] = { + shift = 8, mask = 15, + [10] = map_vfps, + [11] = map_vfpd, + -- NYI cdp, mcr, mrc. + }, + { + shift = 8, mask = 15, + [10] = { + shift = 20, mask = 15, + [0] = "vmovFnD", "vmovFDn", + [14] = "vmsrD", + [15] = { shift = 12, mask = 15, [15] = "vmrs", _ = "vmrsD", }, + }, + }, + }, + "svcT", +} + +local map_loadcu = { + shift = 0, mask = 0, -- NYI unconditional CP load/store. +} + +local map_datacu = { + shift = 0, mask = 0, -- NYI unconditional CP data. +} + +local map_simddata = { + shift = 0, mask = 0, -- NYI SIMD data. +} + +local map_simdload = { + shift = 0, mask = 0, -- NYI SIMD load/store, preload. +} + +local map_preload = { + shift = 0, mask = 0, -- NYI preload. +} + +local map_media = { + shift = 20, mask = 31, + [0] = false, + { --01 + shift = 5, mask = 7, + [0] = "sadd16DNM", "sasxDNM", "ssaxDNM", "ssub16DNM", + "sadd8DNM", false, false, "ssub8DNM", + }, + { --02 + shift = 5, mask = 7, + [0] = "qadd16DNM", "qasxDNM", "qsaxDNM", "qsub16DNM", + "qadd8DNM", false, false, "qsub8DNM", + }, + { --03 + shift = 5, mask = 7, + [0] = "shadd16DNM", "shasxDNM", "shsaxDNM", "shsub16DNM", + "shadd8DNM", false, false, "shsub8DNM", + }, + false, + { --05 + shift = 5, mask = 7, + [0] = "uadd16DNM", "uasxDNM", "usaxDNM", "usub16DNM", + "uadd8DNM", false, false, "usub8DNM", + }, + { --06 + shift = 5, mask = 7, + [0] = "uqadd16DNM", "uqasxDNM", "uqsaxDNM", "uqsub16DNM", + "uqadd8DNM", false, false, "uqsub8DNM", + }, + { --07 + shift = 5, mask = 7, + [0] = "uhadd16DNM", "uhasxDNM", "uhsaxDNM", "uhsub16DNM", + "uhadd8DNM", false, false, "uhsub8DNM", + }, + { --08 + shift = 5, mask = 7, + [0] = "pkhbtDNMU", false, "pkhtbDNMU", + { shift = 16, mask = 15, [15] = "sxtb16DMU", _ = "sxtab16DNMU", }, + "pkhbtDNMU", "selDNM", "pkhtbDNMU", + }, + false, + { --0a + shift = 5, mask = 7, + [0] = "ssatDxMu", "ssat16DxM", "ssatDxMu", + { shift = 16, mask = 15, [15] = "sxtbDMU", _ = "sxtabDNMU", }, + "ssatDxMu", false, "ssatDxMu", + }, + { --0b + shift = 5, mask = 7, + [0] = "ssatDxMu", "revDM", "ssatDxMu", + { shift = 16, mask = 15, [15] = "sxthDMU", _ = "sxtahDNMU", }, + "ssatDxMu", "rev16DM", "ssatDxMu", + }, + { --0c + shift = 5, mask = 7, + [3] = { shift = 16, mask = 15, [15] = "uxtb16DMU", _ = "uxtab16DNMU", }, + }, + false, + { --0e + shift = 5, mask = 7, + [0] = "usatDwMu", "usat16DwM", "usatDwMu", + { shift = 16, mask = 15, [15] = "uxtbDMU", _ = "uxtabDNMU", }, + "usatDwMu", false, "usatDwMu", + }, + { --0f + shift = 5, mask = 7, + [0] = "usatDwMu", "rbitDM", "usatDwMu", + { shift = 16, mask = 15, [15] = "uxthDMU", _ = "uxtahDNMU", }, + "usatDwMu", "revshDM", "usatDwMu", + }, + { --10 + shift = 12, mask = 15, + [15] = { + shift = 5, mask = 7, + "smuadNMS", "smuadxNMS", "smusdNMS", "smusdxNMS", + }, + _ = { + shift = 5, mask = 7, + [0] = "smladNMSD", "smladxNMSD", "smlsdNMSD", "smlsdxNMSD", + }, + }, + false, false, false, + { --14 + shift = 5, mask = 7, + [0] = "smlaldDNMS", "smlaldxDNMS", "smlsldDNMS", "smlsldxDNMS", + }, + { --15 + shift = 5, mask = 7, + [0] = { shift = 12, mask = 15, [15] = "smmulNMS", _ = "smmlaNMSD", }, + { shift = 12, mask = 15, [15] = "smmulrNMS", _ = "smmlarNMSD", }, + false, false, false, false, + "smmlsNMSD", "smmlsrNMSD", + }, + false, false, + { --18 + shift = 5, mask = 7, + [0] = { shift = 12, mask = 15, [15] = "usad8NMS", _ = "usada8NMSD", }, + }, + false, + { --1a + shift = 5, mask = 3, [2] = "sbfxDMvw", + }, + { --1b + shift = 5, mask = 3, [2] = "sbfxDMvw", + }, + { --1c + shift = 5, mask = 3, + [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", }, + }, + { --1d + shift = 5, mask = 3, + [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", }, + }, + { --1e + shift = 5, mask = 3, [2] = "ubfxDMvw", + }, + { --1f + shift = 5, mask = 3, [2] = "ubfxDMvw", + }, +} + +local map_load = { + shift = 21, mask = 9, + { + shift = 20, mask = 5, + [0] = "strtDL", "ldrtDL", [4] = "strbtDL", [5] = "ldrbtDL", + }, + _ = { + shift = 20, mask = 5, + [0] = "strDL", "ldrDL", [4] = "strbDL", [5] = "ldrbDL", + } +} + +local map_load1 = { + shift = 4, mask = 1, + [0] = map_load, map_media, +} + +local map_loadm = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "stmdaNR", "stmNR", + { shift = 16, mask = 63, [45] = "pushR", _ = "stmdbNR", }, "stmibNR", + }, + { + shift = 23, mask = 3, + [0] = "ldmdaNR", { shift = 16, mask = 63, [61] = "popR", _ = "ldmNR", }, + "ldmdbNR", "ldmibNR", + }, +} + +local map_data = { + shift = 21, mask = 15, + [0] = "andDNPs", "eorDNPs", "subDNPs", "rsbDNPs", + "addDNPs", "adcDNPs", "sbcDNPs", "rscDNPs", + "tstNP", "teqNP", "cmpNP", "cmnNP", + "orrDNPs", "movDPs", "bicDNPs", "mvnDPs", +} + +local map_mul = { + shift = 21, mask = 7, + [0] = "mulNMSs", "mlaNMSDs", "umaalDNMS", "mlsDNMS", + "umullDNMSs", "umlalDNMSs", "smullDNMSs", "smlalDNMSs", +} + +local map_sync = { + shift = 20, mask = 15, -- NYI: brackets around N. R(D+1) for ldrexd/strexd. + [0] = "swpDMN", false, false, false, + "swpbDMN", false, false, false, + "strexDMN", "ldrexDN", "strexdDN", "ldrexdDN", + "strexbDMN", "ldrexbDN", "strexhDN", "ldrexhDN", +} + +local map_mulh = { + shift = 21, mask = 3, + [0] = { shift = 5, mask = 3, + [0] = "smlabbNMSD", "smlatbNMSD", "smlabtNMSD", "smlattNMSD", }, + { shift = 5, mask = 3, + [0] = "smlawbNMSD", "smulwbNMS", "smlawtNMSD", "smulwtNMS", }, + { shift = 5, mask = 3, + [0] = "smlalbbDNMS", "smlaltbDNMS", "smlalbtDNMS", "smlalttDNMS", }, + { shift = 5, mask = 3, + [0] = "smulbbNMS", "smultbNMS", "smulbtNMS", "smulttNMS", }, +} + +local map_misc = { + shift = 4, mask = 7, + -- NYI: decode PSR bits of msr. + [0] = { shift = 21, mask = 1, [0] = "mrsD", "msrM", }, + { shift = 21, mask = 3, "bxM", false, "clzDM", }, + { shift = 21, mask = 3, "bxjM", }, + { shift = 21, mask = 3, "blxM", }, + false, + { shift = 21, mask = 3, [0] = "qaddDMN", "qsubDMN", "qdaddDMN", "qdsubDMN", }, + false, + { shift = 21, mask = 3, "bkptK", }, +} + +local map_datar = { + shift = 4, mask = 9, + [9] = { + shift = 5, mask = 3, + [0] = { shift = 24, mask = 1, [0] = map_mul, map_sync, }, + { shift = 20, mask = 1, [0] = "strhDL", "ldrhDL", }, + { shift = 20, mask = 1, [0] = "ldrdDL", "ldrsbDL", }, + { shift = 20, mask = 1, [0] = "strdDL", "ldrshDL", }, + }, + _ = { + shift = 20, mask = 25, + [16] = { shift = 7, mask = 1, [0] = map_misc, map_mulh, }, + _ = { + shift = 0, mask = 0xffffffff, + [bor(0xe1a00000)] = "nop", + _ = map_data, + } + }, +} + +local map_datai = { + shift = 20, mask = 31, -- NYI: decode PSR bits of msr. Decode imm12. + [16] = "movwDW", [20] = "movtDW", + [18] = { shift = 0, mask = 0xf00ff, [0] = "nopv6", _ = "msrNW", }, + [22] = "msrNW", + _ = map_data, +} + +local map_branch = { + shift = 24, mask = 1, + [0] = "bB", "blB" +} + +local map_condins = { + [0] = map_datar, map_datai, map_load, map_load1, + map_loadm, map_branch, map_loadc, map_datac +} + +-- NYI: setend. +local map_uncondins = { + [0] = false, map_simddata, map_simdload, map_preload, + false, "blxB", map_loadcu, map_datacu, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc", +} + +local map_cond = { + [0] = "eq", "ne", "hs", "lo", "mi", "pl", "vs", "vc", + "hi", "ls", "ge", "lt", "gt", "le", "al", +} + +local map_shift = { [0] = "lsl", "lsr", "asr", "ror", } + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then + extra = "\t->"..sym + elseif band(ctx.op, 0x0e000000) ~= 0x0a000000 then + extra = "\t; 0x"..tohex(ctx.rel) + end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-5s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-5s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +-- Format operand 2 of load/store opcodes. +local function fmtload(ctx, op, pos) + local base = map_gpr[band(rshift(op, 16), 15)] + local x, ofs + local ext = (band(op, 0x04000000) == 0) + if not ext and band(op, 0x02000000) == 0 then + ofs = band(op, 4095) + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + ofs = "#"..ofs + elseif ext and band(op, 0x00400000) ~= 0 then + ofs = band(op, 15) + band(rshift(op, 4), 0xf0) + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + ofs = "#"..ofs + else + ofs = map_gpr[band(op, 15)] + if ext or band(op, 0xfe0) == 0 then + elseif band(op, 0xfe0) == 0x60 then + ofs = format("%s, rrx", ofs) + else + local sh = band(rshift(op, 7), 31) + if sh == 0 then sh = 32 end + ofs = format("%s, %s #%d", ofs, map_shift[band(rshift(op, 5), 3)], sh) + end + if band(op, 0x00800000) == 0 then ofs = "-"..ofs end + end + if ofs == "#0" then + x = format("[%s]", base) + elseif band(op, 0x01000000) == 0 then + x = format("[%s], %s", base, ofs) + else + x = format("[%s, %s]", base, ofs) + end + if band(op, 0x01200000) == 0x01200000 then x = x.."!" end + return x +end + +-- Format operand 2 of vector load/store opcodes. +local function fmtvload(ctx, op, pos) + local base = map_gpr[band(rshift(op, 16), 15)] + local ofs = band(op, 255)*4 + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + if ofs == 0 then + return format("[%s]", base) + else + return format("[%s, #%d]", base, ofs) + end +end + +local function fmtvr(op, vr, sh0, sh1) + if vr == "s" then + return format("s%d", 2*band(rshift(op, sh0), 15)+band(rshift(op, sh1), 1)) + else + return format("d%d", band(rshift(op, sh0), 15)+band(rshift(op, sh1-4), 16)) + end +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0) + local operands = {} + local suffix = "" + local last, name, pat + local vr + ctx.op = op + ctx.rel = nil + + local cond = rshift(op, 28) + local opat + if cond == 15 then + opat = map_uncondins[band(rshift(op, 25), 7)] + else + if cond ~= 14 then suffix = map_cond[cond] end + opat = map_condins[band(rshift(op, 25), 7)] + end + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._ + end + name, pat = match(opat, "^([a-z0-9]*)(.*)") + if sub(pat, 1, 1) == "." then + local s2, p2 = match(pat, "^([a-z0-9.]*)(.*)") + suffix = suffix..s2 + pat = p2 + end + + for p in gmatch(pat, ".") do + local x = nil + if p == "D" then + x = map_gpr[band(rshift(op, 12), 15)] + elseif p == "N" then + x = map_gpr[band(rshift(op, 16), 15)] + elseif p == "S" then + x = map_gpr[band(rshift(op, 8), 15)] + elseif p == "M" then + x = map_gpr[band(op, 15)] + elseif p == "d" then + x = fmtvr(op, vr, 12, 22) + elseif p == "n" then + x = fmtvr(op, vr, 16, 7) + elseif p == "m" then + x = fmtvr(op, vr, 0, 5) + elseif p == "P" then + if band(op, 0x02000000) ~= 0 then + x = ror(band(op, 255), 2*band(rshift(op, 8), 15)) + else + x = map_gpr[band(op, 15)] + if band(op, 0xff0) ~= 0 then + operands[#operands+1] = x + local s = map_shift[band(rshift(op, 5), 3)] + local r = nil + if band(op, 0xf90) == 0 then + if s == "ror" then s = "rrx" else r = "#32" end + elseif band(op, 0x10) == 0 then + r = "#"..band(rshift(op, 7), 31) + else + r = map_gpr[band(rshift(op, 8), 15)] + end + if name == "mov" then name = s; x = r + elseif r then x = format("%s %s", s, r) + else x = s end + end + end + elseif p == "L" then + x = fmtload(ctx, op, pos) + elseif p == "l" then + x = fmtvload(ctx, op, pos) + elseif p == "B" then + local addr = ctx.addr + pos + 8 + arshift(lshift(op, 8), 6) + if cond == 15 then addr = addr + band(rshift(op, 23), 2) end + ctx.rel = addr + x = "0x"..tohex(addr) + elseif p == "F" then + vr = "s" + elseif p == "G" then + vr = "d" + elseif p == "." then + suffix = suffix..(vr == "s" and ".f32" or ".f64") + elseif p == "R" then + if band(op, 0x00200000) ~= 0 and #operands == 1 then + operands[1] = operands[1].."!" + end + local t = {} + for i=0,15 do + if band(rshift(op, i), 1) == 1 then t[#t+1] = map_gpr[i] end + end + x = "{"..concat(t, ", ").."}" + elseif p == "r" then + if band(op, 0x00200000) ~= 0 and #operands == 2 then + operands[1] = operands[1].."!" + end + local s = tonumber(sub(last, 2)) + local n = band(op, 255) + if vr == "d" then n = rshift(n, 1) end + operands[#operands] = format("{%s-%s%d}", last, vr, s+n-1) + elseif p == "W" then + x = band(op, 0x0fff) + band(rshift(op, 4), 0xf000) + elseif p == "T" then + x = "#0x"..tohex(band(op, 0x00ffffff), 6) + elseif p == "U" then + x = band(rshift(op, 7), 31) + if x == 0 then x = nil end + elseif p == "u" then + x = band(rshift(op, 7), 31) + if band(op, 0x40) == 0 then + if x == 0 then x = nil else x = "lsl #"..x end + else + if x == 0 then x = "asr #32" else x = "asr #"..x end + end + elseif p == "v" then + x = band(rshift(op, 7), 31) + elseif p == "w" then + x = band(rshift(op, 16), 31) + elseif p == "x" then + x = band(rshift(op, 16), 31) + 1 + elseif p == "X" then + x = band(rshift(op, 16), 31) - last + 1 + elseif p == "Y" then + x = band(rshift(op, 12), 0xf0) + band(op, 0x0f) + elseif p == "K" then + x = "#0x"..tohex(band(rshift(op, 4), 0x0000fff0) + band(op, 15), 4) + elseif p == "s" then + if band(op, 0x00100000) ~= 0 then suffix = "s"..suffix end + else + assert(false) + end + if x then + last = x + if type(x) == "number" then x = "#"..x end + operands[#operands+1] = x + end + end + + return putop(ctx, name..suffix, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + ctx.pos = ofs + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 16 then return map_gpr[r] end + return "d"..(r-16) +end + +-- Public module functions. +module(...) + +create = create_ +disass = disass_ +regname = regname_ + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mips.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mips.lua new file mode 100644 index 0000000..47a7a83 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mips.lua @@ -0,0 +1,428 @@ +---------------------------------------------------------------------------- +-- LuaJIT MIPS disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT/X license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles all standard MIPS32R1/R2 instructions. +-- Default mode is big-endian, but see: dis_mipsel.lua +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, tohex = bit.band, bit.bor, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Primary and extended opcode maps +------------------------------------------------------------------------------ + +local map_movci = { shift = 16, mask = 1, [0] = "movfDSC", "movtDSC", } +local map_srl = { shift = 21, mask = 1, [0] = "srlDTA", "rotrDTA", } +local map_srlv = { shift = 6, mask = 1, [0] = "srlvDTS", "rotrvDTS", } + +local map_special = { + shift = 0, mask = 63, + [0] = { shift = 0, mask = -1, [0] = "nop", _ = "sllDTA" }, + map_movci, map_srl, "sraDTA", + "sllvDTS", false, map_srlv, "sravDTS", + "jrS", "jalrD1S", "movzDST", "movnDST", + "syscallY", "breakY", false, "sync", + "mfhiD", "mthiS", "mfloD", "mtloS", + false, false, false, false, + "multST", "multuST", "divST", "divuST", + false, false, false, false, + "addDST", "addu|moveDST0", "subDST", "subu|neguDS0T", + "andDST", "orDST", "xorDST", "nor|notDST0", + false, false, "sltDST", "sltuDST", + false, false, false, false, + "tgeSTZ", "tgeuSTZ", "tltSTZ", "tltuSTZ", + "teqSTZ", false, "tneSTZ", +} + +local map_special2 = { + shift = 0, mask = 63, + [0] = "maddST", "madduST", "mulDST", false, + "msubST", "msubuST", + [32] = "clzDS", [33] = "cloDS", + [63] = "sdbbpY", +} + +local map_bshfl = { + shift = 6, mask = 31, + [2] = "wsbhDT", + [16] = "sebDT", + [24] = "sehDT", +} + +local map_special3 = { + shift = 0, mask = 63, + [0] = "extTSAK", [4] = "insTSAL", + [32] = map_bshfl, + [59] = "rdhwrTD", +} + +local map_regimm = { + shift = 16, mask = 31, + [0] = "bltzSB", "bgezSB", "bltzlSB", "bgezlSB", + false, false, false, false, + "tgeiSI", "tgeiuSI", "tltiSI", "tltiuSI", + "teqiSI", false, "tneiSI", false, + "bltzalSB", "bgezalSB", "bltzallSB", "bgezallSB", + false, false, false, false, + false, false, false, false, + false, false, false, "synciSO", +} + +local map_cop0 = { + shift = 25, mask = 1, + [0] = { + shift = 21, mask = 15, + [0] = "mfc0TDW", [4] = "mtc0TDW", + [10] = "rdpgprDT", + [11] = { shift = 5, mask = 1, [0] = "diT0", "eiT0", }, + [14] = "wrpgprDT", + }, { + shift = 0, mask = 63, + [1] = "tlbr", [2] = "tlbwi", [6] = "tlbwr", [8] = "tlbp", + [24] = "eret", [31] = "deret", + [32] = "wait", + }, +} + +local map_cop1s = { + shift = 0, mask = 63, + [0] = "add.sFGH", "sub.sFGH", "mul.sFGH", "div.sFGH", + "sqrt.sFG", "abs.sFG", "mov.sFG", "neg.sFG", + "round.l.sFG", "trunc.l.sFG", "ceil.l.sFG", "floor.l.sFG", + "round.w.sFG", "trunc.w.sFG", "ceil.w.sFG", "floor.w.sFG", + false, + { shift = 16, mask = 1, [0] = "movf.sFGC", "movt.sFGC" }, + "movz.sFGT", "movn.sFGT", + false, "recip.sFG", "rsqrt.sFG", false, + false, false, false, false, + false, false, false, false, + false, "cvt.d.sFG", false, false, + "cvt.w.sFG", "cvt.l.sFG", "cvt.ps.sFGH", false, + false, false, false, false, + false, false, false, false, + "c.f.sVGH", "c.un.sVGH", "c.eq.sVGH", "c.ueq.sVGH", + "c.olt.sVGH", "c.ult.sVGH", "c.ole.sVGH", "c.ule.sVGH", + "c.sf.sVGH", "c.ngle.sVGH", "c.seq.sVGH", "c.ngl.sVGH", + "c.lt.sVGH", "c.nge.sVGH", "c.le.sVGH", "c.ngt.sVGH", +} + +local map_cop1d = { + shift = 0, mask = 63, + [0] = "add.dFGH", "sub.dFGH", "mul.dFGH", "div.dFGH", + "sqrt.dFG", "abs.dFG", "mov.dFG", "neg.dFG", + "round.l.dFG", "trunc.l.dFG", "ceil.l.dFG", "floor.l.dFG", + "round.w.dFG", "trunc.w.dFG", "ceil.w.dFG", "floor.w.dFG", + false, + { shift = 16, mask = 1, [0] = "movf.dFGC", "movt.dFGC" }, + "movz.dFGT", "movn.dFGT", + false, "recip.dFG", "rsqrt.dFG", false, + false, false, false, false, + false, false, false, false, + "cvt.s.dFG", false, false, false, + "cvt.w.dFG", "cvt.l.dFG", false, false, + false, false, false, false, + false, false, false, false, + "c.f.dVGH", "c.un.dVGH", "c.eq.dVGH", "c.ueq.dVGH", + "c.olt.dVGH", "c.ult.dVGH", "c.ole.dVGH", "c.ule.dVGH", + "c.df.dVGH", "c.ngle.dVGH", "c.deq.dVGH", "c.ngl.dVGH", + "c.lt.dVGH", "c.nge.dVGH", "c.le.dVGH", "c.ngt.dVGH", +} + +local map_cop1ps = { + shift = 0, mask = 63, + [0] = "add.psFGH", "sub.psFGH", "mul.psFGH", false, + false, "abs.psFG", "mov.psFG", "neg.psFG", + false, false, false, false, + false, false, false, false, + false, + { shift = 16, mask = 1, [0] = "movf.psFGC", "movt.psFGC" }, + "movz.psFGT", "movn.psFGT", + false, false, false, false, + false, false, false, false, + false, false, false, false, + "cvt.s.puFG", false, false, false, + false, false, false, false, + "cvt.s.plFG", false, false, false, + "pll.psFGH", "plu.psFGH", "pul.psFGH", "puu.psFGH", + "c.f.psVGH", "c.un.psVGH", "c.eq.psVGH", "c.ueq.psVGH", + "c.olt.psVGH", "c.ult.psVGH", "c.ole.psVGH", "c.ule.psVGH", + "c.psf.psVGH", "c.ngle.psVGH", "c.pseq.psVGH", "c.ngl.psVGH", + "c.lt.psVGH", "c.nge.psVGH", "c.le.psVGH", "c.ngt.psVGH", +} + +local map_cop1w = { + shift = 0, mask = 63, + [32] = "cvt.s.wFG", [33] = "cvt.d.wFG", +} + +local map_cop1l = { + shift = 0, mask = 63, + [32] = "cvt.s.lFG", [33] = "cvt.d.lFG", +} + +local map_cop1bc = { + shift = 16, mask = 3, + [0] = "bc1fCB", "bc1tCB", "bc1flCB", "bc1tlCB", +} + +local map_cop1 = { + shift = 21, mask = 31, + [0] = "mfc1TG", false, "cfc1TG", "mfhc1TG", + "mtc1TG", false, "ctc1TG", "mthc1TG", + map_cop1bc, false, false, false, + false, false, false, false, + map_cop1s, map_cop1d, false, false, + map_cop1w, map_cop1l, map_cop1ps, +} + +local map_cop1x = { + shift = 0, mask = 63, + [0] = "lwxc1FSX", "ldxc1FSX", false, false, + false, "luxc1FSX", false, false, + "swxc1FSX", "sdxc1FSX", false, false, + false, "suxc1FSX", false, "prefxMSX", + false, false, false, false, + false, false, false, false, + false, false, false, false, + false, false, "alnv.psFGHS", false, + "madd.sFRGH", "madd.dFRGH", false, false, + false, false, "madd.psFRGH", false, + "msub.sFRGH", "msub.dFRGH", false, false, + false, false, "msub.psFRGH", false, + "nmadd.sFRGH", "nmadd.dFRGH", false, false, + false, false, "nmadd.psFRGH", false, + "nmsub.sFRGH", "nmsub.dFRGH", false, false, + false, false, "nmsub.psFRGH", false, +} + +local map_pri = { + [0] = map_special, map_regimm, "jJ", "jalJ", + "beq|beqz|bST00B", "bne|bnezST0B", "blezSB", "bgtzSB", + "addiTSI", "addiu|liTS0I", "sltiTSI", "sltiuTSI", + "andiTSU", "ori|liTS0U", "xoriTSU", "luiTU", + map_cop0, map_cop1, false, map_cop1x, + "beql|beqzlST0B", "bnel|bnezlST0B", "blezlSB", "bgtzlSB", + false, false, false, false, + map_special2, false, false, map_special3, + "lbTSO", "lhTSO", "lwlTSO", "lwTSO", + "lbuTSO", "lhuTSO", "lwrTSO", false, + "sbTSO", "shTSO", "swlTSO", "swTSO", + false, false, "swrTSO", "cacheNSO", + "llTSO", "lwc1HSO", "lwc2TSO", "prefNSO", + false, "ldc1HSO", "ldc2TSO", false, + "scTSO", "swc1HSO", "swc2TSO", false, + false, "sdc1HSO", "sdc2TSO", false, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "sp", "r30", "ra", +} + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then extra = "\t->"..sym end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-7s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-7s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +local function get_be(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3) +end + +local function get_le(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0) +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local op = ctx:get() + local operands = {} + local last = nil + ctx.op = op + ctx.rel = nil + + local opat = map_pri[rshift(op, 26)] + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._ + end + local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") + local altname, pat2 = match(pat, "|([a-z0-9_.|]*)(.*)") + if altname then pat = pat2 end + + for p in gmatch(pat, ".") do + local x = nil + if p == "S" then + x = map_gpr[band(rshift(op, 21), 31)] + elseif p == "T" then + x = map_gpr[band(rshift(op, 16), 31)] + elseif p == "D" then + x = map_gpr[band(rshift(op, 11), 31)] + elseif p == "F" then + x = "f"..band(rshift(op, 6), 31) + elseif p == "G" then + x = "f"..band(rshift(op, 11), 31) + elseif p == "H" then + x = "f"..band(rshift(op, 16), 31) + elseif p == "R" then + x = "f"..band(rshift(op, 21), 31) + elseif p == "A" then + x = band(rshift(op, 6), 31) + elseif p == "M" then + x = band(rshift(op, 11), 31) + elseif p == "N" then + x = band(rshift(op, 16), 31) + elseif p == "C" then + x = band(rshift(op, 18), 7) + if x == 0 then x = nil end + elseif p == "K" then + x = band(rshift(op, 11), 31) + 1 + elseif p == "L" then + x = band(rshift(op, 11), 31) - last + 1 + elseif p == "I" then + x = arshift(lshift(op, 16), 16) + elseif p == "U" then + x = band(op, 0xffff) + elseif p == "O" then + local disp = arshift(lshift(op, 16), 16) + operands[#operands] = format("%d(%s)", disp, last) + elseif p == "X" then + local index = map_gpr[band(rshift(op, 16), 31)] + operands[#operands] = format("%s(%s)", index, last) + elseif p == "B" then + x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4 + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "J" then + x = band(ctx.addr + ctx.pos, 0xf0000000) + band(op, 0x03ffffff)*4 + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "V" then + x = band(rshift(op, 8), 7) + if x == 0 then x = nil end + elseif p == "W" then + x = band(op, 7) + if x == 0 then x = nil end + elseif p == "Y" then + x = band(rshift(op, 6), 0x000fffff) + if x == 0 then x = nil end + elseif p == "Z" then + x = band(rshift(op, 6), 1023) + if x == 0 then x = nil end + elseif p == "0" then + if last == "r0" or last == 0 then + local n = #operands + operands[n] = nil + last = operands[n-1] + if altname then + local a1, a2 = match(altname, "([^|]*)|(.*)") + if a1 then name, altname = a1, a2 + else name = altname end + end + end + elseif p == "1" then + if last == "ra" then + operands[#operands] = nil + end + else + assert(false) + end + if x then operands[#operands+1] = x; last = x end + end + + return putop(ctx, name, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + stop = stop - stop % 4 + ctx.pos = ofs - ofs % 4 + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + ctx.get = get_be + return ctx +end + +local function create_el_(code, addr, out) + local ctx = create_(code, addr, out) + ctx.get = get_le + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +local function disass_el_(code, addr, out) + create_el_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 32 then return map_gpr[r] end + return "f"..(r-32) +end + +-- Public module functions. +module(...) + +create = create_ +create_el = create_el_ +disass = disass_ +disass_el = disass_el_ +regname = regname_ + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mipsel.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mipsel.lua new file mode 100644 index 0000000..d19de31 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_mipsel.lua @@ -0,0 +1,20 @@ +---------------------------------------------------------------------------- +-- LuaJIT MIPSEL disassembler wrapper module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This module just exports the little-endian functions from the +-- MIPS disassembler module. All the interesting stuff is there. +------------------------------------------------------------------------------ + +local require = require + +module(...) + +local dis_mips = require(_PACKAGE.."dis_mips") + +create = dis_mips.create_el +disass = dis_mips.disass_el +regname = dis_mips.regname + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_ppc.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_ppc.lua new file mode 100644 index 0000000..cfaf982 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_ppc.lua @@ -0,0 +1,591 @@ +---------------------------------------------------------------------------- +-- LuaJIT PPC disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT/X license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles all common, non-privileged 32/64 bit PowerPC instructions +-- plus the e500 SPE instructions and some Cell/Xenon extensions. +-- +-- NYI: VMX, VMX128 +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, tohex = bit.band, bit.bor, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Primary and extended opcode maps +------------------------------------------------------------------------------ + +local map_crops = { + shift = 1, mask = 1023, + [0] = "mcrfXX", + [33] = "crnor|crnotCCC=", [129] = "crandcCCC", + [193] = "crxor|crclrCCC%", [225] = "crnandCCC", + [257] = "crandCCC", [289] = "creqv|crsetCCC%", + [417] = "crorcCCC", [449] = "cror|crmoveCCC=", + [16] = "b_lrKB", [528] = "b_ctrKB", + [150] = "isync", +} + +local map_rlwinm = setmetatable({ + shift = 0, mask = -1, +}, +{ __index = function(t, x) + local rot = band(rshift(x, 11), 31) + local mb = band(rshift(x, 6), 31) + local me = band(rshift(x, 1), 31) + if mb == 0 and me == 31-rot then + return "slwiRR~A." + elseif me == 31 and mb == 32-rot then + return "srwiRR~-A." + else + return "rlwinmRR~AAA." + end + end +}) + +local map_rld = { + shift = 2, mask = 7, + [0] = "rldiclRR~HM.", "rldicrRR~HM.", "rldicRR~HM.", "rldimiRR~HM.", + { + shift = 1, mask = 1, + [0] = "rldclRR~RM.", "rldcrRR~RM.", + }, +} + +local map_ext = setmetatable({ + shift = 1, mask = 1023, + + [0] = "cmp_YLRR", [32] = "cmpl_YLRR", + [4] = "twARR", [68] = "tdARR", + + [8] = "subfcRRR.", [40] = "subfRRR.", + [104] = "negRR.", [136] = "subfeRRR.", + [200] = "subfzeRR.", [232] = "subfmeRR.", + [520] = "subfcoRRR.", [552] = "subfoRRR.", + [616] = "negoRR.", [648] = "subfeoRRR.", + [712] = "subfzeoRR.", [744] = "subfmeoRR.", + + [9] = "mulhduRRR.", [73] = "mulhdRRR.", [233] = "mulldRRR.", + [457] = "divduRRR.", [489] = "divdRRR.", + [745] = "mulldoRRR.", + [969] = "divduoRRR.", [1001] = "divdoRRR.", + + [10] = "addcRRR.", [138] = "addeRRR.", + [202] = "addzeRR.", [234] = "addmeRR.", [266] = "addRRR.", + [522] = "addcoRRR.", [650] = "addeoRRR.", + [714] = "addzeoRR.", [746] = "addmeoRR.", [778] = "addoRRR.", + + [11] = "mulhwuRRR.", [75] = "mulhwRRR.", [235] = "mullwRRR.", + [459] = "divwuRRR.", [491] = "divwRRR.", + [747] = "mullwoRRR.", + [971] = "divwouRRR.", [1003] = "divwoRRR.", + + [15] = "iselltRRR", [47] = "iselgtRRR", [79] = "iseleqRRR", + + [144] = { shift = 20, mask = 1, [0] = "mtcrfRZ~", "mtocrfRZ~", }, + [19] = { shift = 20, mask = 1, [0] = "mfcrR", "mfocrfRZ", }, + [371] = { shift = 11, mask = 1023, [392] = "mftbR", [424] = "mftbuR", }, + [339] = { + shift = 11, mask = 1023, + [32] = "mferR", [256] = "mflrR", [288] = "mfctrR", [16] = "mfspefscrR", + }, + [467] = { + shift = 11, mask = 1023, + [32] = "mtxerR", [256] = "mtlrR", [288] = "mtctrR", [16] = "mtspefscrR", + }, + + [20] = "lwarxRR0R", [84] = "ldarxRR0R", + + [21] = "ldxRR0R", [53] = "lduxRRR", + [149] = "stdxRR0R", [181] = "stduxRRR", + [341] = "lwaxRR0R", [373] = "lwauxRRR", + + [23] = "lwzxRR0R", [55] = "lwzuxRRR", + [87] = "lbzxRR0R", [119] = "lbzuxRRR", + [151] = "stwxRR0R", [183] = "stwuxRRR", + [215] = "stbxRR0R", [247] = "stbuxRRR", + [279] = "lhzxRR0R", [311] = "lhzuxRRR", + [343] = "lhaxRR0R", [375] = "lhauxRRR", + [407] = "sthxRR0R", [439] = "sthuxRRR", + + [54] = "dcbst-R0R", [86] = "dcbf-R0R", + [150] = "stwcxRR0R.", [214] = "stdcxRR0R.", + [246] = "dcbtst-R0R", [278] = "dcbt-R0R", + [310] = "eciwxRR0R", [438] = "ecowxRR0R", + [470] = "dcbi-RR", + + [598] = { + shift = 21, mask = 3, + [0] = "sync", "lwsync", "ptesync", + }, + [758] = "dcba-RR", + [854] = "eieio", [982] = "icbi-R0R", [1014] = "dcbz-R0R", + + [26] = "cntlzwRR~", [58] = "cntlzdRR~", + [122] = "popcntbRR~", + [154] = "prtywRR~", [186] = "prtydRR~", + + [28] = "andRR~R.", [60] = "andcRR~R.", [124] = "nor|notRR~R=.", + [284] = "eqvRR~R.", [316] = "xorRR~R.", + [412] = "orcRR~R.", [444] = "or|mrRR~R=.", [476] = "nandRR~R.", + [508] = "cmpbRR~R", + + [512] = "mcrxrX", + + [532] = "ldbrxRR0R", [660] = "stdbrxRR0R", + + [533] = "lswxRR0R", [597] = "lswiRR0A", + [661] = "stswxRR0R", [725] = "stswiRR0A", + + [534] = "lwbrxRR0R", [662] = "stwbrxRR0R", + [790] = "lhbrxRR0R", [918] = "sthbrxRR0R", + + [535] = "lfsxFR0R", [567] = "lfsuxFRR", + [599] = "lfdxFR0R", [631] = "lfduxFRR", + [663] = "stfsxFR0R", [695] = "stfsuxFRR", + [727] = "stfdxFR0R", [759] = "stfduxFR0R", + [855] = "lfiwaxFR0R", + [983] = "stfiwxFR0R", + + [24] = "slwRR~R.", + + [27] = "sldRR~R.", [536] = "srwRR~R.", + [792] = "srawRR~R.", [824] = "srawiRR~A.", + + [794] = "sradRR~R.", [826] = "sradiRR~H.", [827] = "sradiRR~H.", + [922] = "extshRR~.", [954] = "extsbRR~.", [986] = "extswRR~.", + + [539] = "srdRR~R.", +}, +{ __index = function(t, x) + if band(x, 31) == 15 then return "iselRRRC" end + end +}) + +local map_ld = { + shift = 0, mask = 3, + [0] = "ldRRE", "lduRRE", "lwaRRE", +} + +local map_std = { + shift = 0, mask = 3, + [0] = "stdRRE", "stduRRE", +} + +local map_fps = { + shift = 5, mask = 1, + { + shift = 1, mask = 15, + [0] = false, false, "fdivsFFF.", false, + "fsubsFFF.", "faddsFFF.", "fsqrtsF-F.", false, + "fresF-F.", "fmulsFF-F.", "frsqrtesF-F.", false, + "fmsubsFFFF~.", "fmaddsFFFF~.", "fnmsubsFFFF~.", "fnmaddsFFFF~.", + } +} + +local map_fpd = { + shift = 5, mask = 1, + [0] = { + shift = 1, mask = 1023, + [0] = "fcmpuXFF", [32] = "fcmpoXFF", [64] = "mcrfsXX", + [38] = "mtfsb1A.", [70] = "mtfsb0A.", [134] = "mtfsfiA>>-A>", + [8] = "fcpsgnFFF.", [40] = "fnegF-F.", [72] = "fmrF-F.", + [136] = "fnabsF-F.", [264] = "fabsF-F.", + [12] = "frspF-F.", + [14] = "fctiwF-F.", [15] = "fctiwzF-F.", + [583] = "mffsF.", [711] = "mtfsfZF.", + [392] = "frinF-F.", [424] = "frizF-F.", + [456] = "fripF-F.", [488] = "frimF-F.", + [814] = "fctidF-F.", [815] = "fctidzF-F.", [846] = "fcfidF-F.", + }, + { + shift = 1, mask = 15, + [0] = false, false, "fdivFFF.", false, + "fsubFFF.", "faddFFF.", "fsqrtF-F.", "fselFFFF~.", + "freF-F.", "fmulFF-F.", "frsqrteF-F.", false, + "fmsubFFFF~.", "fmaddFFFF~.", "fnmsubFFFF~.", "fnmaddFFFF~.", + } +} + +local map_spe = { + shift = 0, mask = 2047, + + [512] = "evaddwRRR", [514] = "evaddiwRAR~", + [516] = "evsubwRRR~", [518] = "evsubiwRAR~", + [520] = "evabsRR", [521] = "evnegRR", + [522] = "evextsbRR", [523] = "evextshRR", [524] = "evrndwRR", + [525] = "evcntlzwRR", [526] = "evcntlswRR", + + [527] = "brincRRR", + + [529] = "evandRRR", [530] = "evandcRRR", [534] = "evxorRRR", + [535] = "evor|evmrRRR=", [536] = "evnor|evnotRRR=", + [537] = "eveqvRRR", [539] = "evorcRRR", [542] = "evnandRRR", + + [544] = "evsrwuRRR", [545] = "evsrwsRRR", + [546] = "evsrwiuRRA", [547] = "evsrwisRRA", + [548] = "evslwRRR", [550] = "evslwiRRA", + [552] = "evrlwRRR", [553] = "evsplatiRS", + [554] = "evrlwiRRA", [555] = "evsplatfiRS", + [556] = "evmergehiRRR", [557] = "evmergeloRRR", + [558] = "evmergehiloRRR", [559] = "evmergelohiRRR", + + [560] = "evcmpgtuYRR", [561] = "evcmpgtsYRR", + [562] = "evcmpltuYRR", [563] = "evcmpltsYRR", + [564] = "evcmpeqYRR", + + [632] = "evselRRR", [633] = "evselRRRW", + [634] = "evselRRRW", [635] = "evselRRRW", + [636] = "evselRRRW", [637] = "evselRRRW", + [638] = "evselRRRW", [639] = "evselRRRW", + + [640] = "evfsaddRRR", [641] = "evfssubRRR", + [644] = "evfsabsRR", [645] = "evfsnabsRR", [646] = "evfsnegRR", + [648] = "evfsmulRRR", [649] = "evfsdivRRR", + [652] = "evfscmpgtYRR", [653] = "evfscmpltYRR", [654] = "evfscmpeqYRR", + [656] = "evfscfuiR-R", [657] = "evfscfsiR-R", + [658] = "evfscfufR-R", [659] = "evfscfsfR-R", + [660] = "evfsctuiR-R", [661] = "evfsctsiR-R", + [662] = "evfsctufR-R", [663] = "evfsctsfR-R", + [664] = "evfsctuizR-R", [666] = "evfsctsizR-R", + [668] = "evfststgtYRR", [669] = "evfststltYRR", [670] = "evfststeqYRR", + + [704] = "efsaddRRR", [705] = "efssubRRR", + [708] = "efsabsRR", [709] = "efsnabsRR", [710] = "efsnegRR", + [712] = "efsmulRRR", [713] = "efsdivRRR", + [716] = "efscmpgtYRR", [717] = "efscmpltYRR", [718] = "efscmpeqYRR", + [719] = "efscfdR-R", + [720] = "efscfuiR-R", [721] = "efscfsiR-R", + [722] = "efscfufR-R", [723] = "efscfsfR-R", + [724] = "efsctuiR-R", [725] = "efsctsiR-R", + [726] = "efsctufR-R", [727] = "efsctsfR-R", + [728] = "efsctuizR-R", [730] = "efsctsizR-R", + [732] = "efststgtYRR", [733] = "efststltYRR", [734] = "efststeqYRR", + + [736] = "efdaddRRR", [737] = "efdsubRRR", + [738] = "efdcfuidR-R", [739] = "efdcfsidR-R", + [740] = "efdabsRR", [741] = "efdnabsRR", [742] = "efdnegRR", + [744] = "efdmulRRR", [745] = "efddivRRR", + [746] = "efdctuidzR-R", [747] = "efdctsidzR-R", + [748] = "efdcmpgtYRR", [749] = "efdcmpltYRR", [750] = "efdcmpeqYRR", + [751] = "efdcfsR-R", + [752] = "efdcfuiR-R", [753] = "efdcfsiR-R", + [754] = "efdcfufR-R", [755] = "efdcfsfR-R", + [756] = "efdctuiR-R", [757] = "efdctsiR-R", + [758] = "efdctufR-R", [759] = "efdctsfR-R", + [760] = "efdctuizR-R", [762] = "efdctsizR-R", + [764] = "efdtstgtYRR", [765] = "efdtstltYRR", [766] = "efdtsteqYRR", + + [768] = "evlddxRR0R", [769] = "evlddRR8", + [770] = "evldwxRR0R", [771] = "evldwRR8", + [772] = "evldhxRR0R", [773] = "evldhRR8", + [776] = "evlhhesplatxRR0R", [777] = "evlhhesplatRR2", + [780] = "evlhhousplatxRR0R", [781] = "evlhhousplatRR2", + [782] = "evlhhossplatxRR0R", [783] = "evlhhossplatRR2", + [784] = "evlwhexRR0R", [785] = "evlwheRR4", + [788] = "evlwhouxRR0R", [789] = "evlwhouRR4", + [790] = "evlwhosxRR0R", [791] = "evlwhosRR4", + [792] = "evlwwsplatxRR0R", [793] = "evlwwsplatRR4", + [796] = "evlwhsplatxRR0R", [797] = "evlwhsplatRR4", + + [800] = "evstddxRR0R", [801] = "evstddRR8", + [802] = "evstdwxRR0R", [803] = "evstdwRR8", + [804] = "evstdhxRR0R", [805] = "evstdhRR8", + [816] = "evstwhexRR0R", [817] = "evstwheRR4", + [820] = "evstwhoxRR0R", [821] = "evstwhoRR4", + [824] = "evstwwexRR0R", [825] = "evstwweRR4", + [828] = "evstwwoxRR0R", [829] = "evstwwoRR4", + + [1027] = "evmhessfRRR", [1031] = "evmhossfRRR", [1032] = "evmheumiRRR", + [1033] = "evmhesmiRRR", [1035] = "evmhesmfRRR", [1036] = "evmhoumiRRR", + [1037] = "evmhosmiRRR", [1039] = "evmhosmfRRR", [1059] = "evmhessfaRRR", + [1063] = "evmhossfaRRR", [1064] = "evmheumiaRRR", [1065] = "evmhesmiaRRR", + [1067] = "evmhesmfaRRR", [1068] = "evmhoumiaRRR", [1069] = "evmhosmiaRRR", + [1071] = "evmhosmfaRRR", [1095] = "evmwhssfRRR", [1096] = "evmwlumiRRR", + [1100] = "evmwhumiRRR", [1101] = "evmwhsmiRRR", [1103] = "evmwhsmfRRR", + [1107] = "evmwssfRRR", [1112] = "evmwumiRRR", [1113] = "evmwsmiRRR", + [1115] = "evmwsmfRRR", [1127] = "evmwhssfaRRR", [1128] = "evmwlumiaRRR", + [1132] = "evmwhumiaRRR", [1133] = "evmwhsmiaRRR", [1135] = "evmwhsmfaRRR", + [1139] = "evmwssfaRRR", [1144] = "evmwumiaRRR", [1145] = "evmwsmiaRRR", + [1147] = "evmwsmfaRRR", + + [1216] = "evaddusiaawRR", [1217] = "evaddssiaawRR", + [1218] = "evsubfusiaawRR", [1219] = "evsubfssiaawRR", + [1220] = "evmraRR", + [1222] = "evdivwsRRR", [1223] = "evdivwuRRR", + [1224] = "evaddumiaawRR", [1225] = "evaddsmiaawRR", + [1226] = "evsubfumiaawRR", [1227] = "evsubfsmiaawRR", + + [1280] = "evmheusiaawRRR", [1281] = "evmhessiaawRRR", + [1283] = "evmhessfaawRRR", [1284] = "evmhousiaawRRR", + [1285] = "evmhossiaawRRR", [1287] = "evmhossfaawRRR", + [1288] = "evmheumiaawRRR", [1289] = "evmhesmiaawRRR", + [1291] = "evmhesmfaawRRR", [1292] = "evmhoumiaawRRR", + [1293] = "evmhosmiaawRRR", [1295] = "evmhosmfaawRRR", + [1320] = "evmhegumiaaRRR", [1321] = "evmhegsmiaaRRR", + [1323] = "evmhegsmfaaRRR", [1324] = "evmhogumiaaRRR", + [1325] = "evmhogsmiaaRRR", [1327] = "evmhogsmfaaRRR", + [1344] = "evmwlusiaawRRR", [1345] = "evmwlssiaawRRR", + [1352] = "evmwlumiaawRRR", [1353] = "evmwlsmiaawRRR", + [1363] = "evmwssfaaRRR", [1368] = "evmwumiaaRRR", + [1369] = "evmwsmiaaRRR", [1371] = "evmwsmfaaRRR", + [1408] = "evmheusianwRRR", [1409] = "evmhessianwRRR", + [1411] = "evmhessfanwRRR", [1412] = "evmhousianwRRR", + [1413] = "evmhossianwRRR", [1415] = "evmhossfanwRRR", + [1416] = "evmheumianwRRR", [1417] = "evmhesmianwRRR", + [1419] = "evmhesmfanwRRR", [1420] = "evmhoumianwRRR", + [1421] = "evmhosmianwRRR", [1423] = "evmhosmfanwRRR", + [1448] = "evmhegumianRRR", [1449] = "evmhegsmianRRR", + [1451] = "evmhegsmfanRRR", [1452] = "evmhogumianRRR", + [1453] = "evmhogsmianRRR", [1455] = "evmhogsmfanRRR", + [1472] = "evmwlusianwRRR", [1473] = "evmwlssianwRRR", + [1480] = "evmwlumianwRRR", [1481] = "evmwlsmianwRRR", + [1491] = "evmwssfanRRR", [1496] = "evmwumianRRR", + [1497] = "evmwsmianRRR", [1499] = "evmwsmfanRRR", +} + +local map_pri = { + [0] = false, false, "tdiARI", "twiARI", + map_spe, false, false, "mulliRRI", + "subficRRI", false, "cmpl_iYLRU", "cmp_iYLRI", + "addicRRI", "addic.RRI", "addi|liRR0I", "addis|lisRR0I", + "b_KBJ", "sc", "bKJ", map_crops, + "rlwimiRR~AAA.", map_rlwinm, false, "rlwnmRR~RAA.", + "oriNRR~U", "orisRR~U", "xoriRR~U", "xorisRR~U", + "andi.RR~U", "andis.RR~U", map_rld, map_ext, + "lwzRRD", "lwzuRRD", "lbzRRD", "lbzuRRD", + "stwRRD", "stwuRRD", "stbRRD", "stbuRRD", + "lhzRRD", "lhzuRRD", "lhaRRD", "lhauRRD", + "sthRRD", "sthuRRD", "lmwRRD", "stmwRRD", + "lfsFRD", "lfsuFRD", "lfdFRD", "lfduFRD", + "stfsFRD", "stfsuFRD", "stfdFRD", "stfduFRD", + false, false, map_ld, map_fps, + false, false, map_std, map_fpd, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "sp", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", +} + +local map_cond = { [0] = "lt", "gt", "eq", "so", "ge", "le", "ne", "ns", } + +-- Format a condition bit. +local function condfmt(cond) + if cond <= 3 then + return map_cond[band(cond, 3)] + else + return format("4*cr%d+%s", rshift(cond, 2), map_cond[band(cond, 3)]) + end +end + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then extra = "\t->"..sym end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-7s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-7s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + local op = bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3) + local operands = {} + local last = nil + local rs = 21 + ctx.op = op + ctx.rel = nil + + local opat = map_pri[rshift(b0, 2)] + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] + end + local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") + local altname, pat2 = match(pat, "|([a-z0-9_.]*)(.*)") + if altname then pat = pat2 end + + for p in gmatch(pat, ".") do + local x = nil + if p == "R" then + x = map_gpr[band(rshift(op, rs), 31)] + rs = rs - 5 + elseif p == "F" then + x = "f"..band(rshift(op, rs), 31) + rs = rs - 5 + elseif p == "A" then + x = band(rshift(op, rs), 31) + rs = rs - 5 + elseif p == "S" then + x = arshift(lshift(op, 27-rs), 27) + rs = rs - 5 + elseif p == "I" then + x = arshift(lshift(op, 16), 16) + elseif p == "U" then + x = band(op, 0xffff) + elseif p == "D" or p == "E" then + local disp = arshift(lshift(op, 16), 16) + if p == "E" then disp = band(disp, -4) end + if last == "r0" then last = "0" end + operands[#operands] = format("%d(%s)", disp, last) + elseif p >= "2" and p <= "8" then + local disp = band(rshift(op, rs), 31) * p + if last == "r0" then last = "0" end + operands[#operands] = format("%d(%s)", disp, last) + elseif p == "H" then + x = band(rshift(op, rs), 31) + lshift(band(op, 2), 4) + rs = rs - 5 + elseif p == "M" then + x = band(rshift(op, rs), 31) + band(op, 0x20) + elseif p == "C" then + x = condfmt(band(rshift(op, rs), 31)) + rs = rs - 5 + elseif p == "B" then + local bo = rshift(op, 21) + local cond = band(rshift(op, 16), 31) + local cn = "" + rs = rs - 10 + if band(bo, 4) == 0 then + cn = band(bo, 2) == 0 and "dnz" or "dz" + if band(bo, 0x10) == 0 then + cn = cn..(band(bo, 8) == 0 and "f" or "t") + end + if band(bo, 0x10) == 0 then x = condfmt(cond) end + name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+") + elseif band(bo, 0x10) == 0 then + cn = map_cond[band(cond, 3) + (band(bo, 8) == 0 and 4 or 0)] + if cond > 3 then x = "cr"..rshift(cond, 2) end + name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+") + end + name = gsub(name, "_", cn) + elseif p == "J" then + x = arshift(lshift(op, 27-rs), 29-rs)*4 + if band(op, 2) == 0 then x = ctx.addr + pos + x end + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "K" then + if band(op, 1) ~= 0 then name = name.."l" end + if band(op, 2) ~= 0 then name = name.."a" end + elseif p == "X" or p == "Y" then + x = band(rshift(op, rs+2), 7) + if x == 0 and p == "Y" then x = nil else x = "cr"..x end + rs = rs - 5 + elseif p == "W" then + x = "cr"..band(op, 7) + elseif p == "Z" then + x = band(rshift(op, rs-4), 255) + rs = rs - 10 + elseif p == ">" then + operands[#operands] = rshift(operands[#operands], 1) + elseif p == "0" then + if last == "r0" then + operands[#operands] = nil + if altname then name = altname end + end + elseif p == "L" then + name = gsub(name, "_", band(op, 0x00200000) ~= 0 and "d" or "w") + elseif p == "." then + if band(op, 1) == 1 then name = name.."." end + elseif p == "N" then + if op == 0x60000000 then name = "nop"; break end + elseif p == "~" then + local n = #operands + operands[n-1], operands[n] = operands[n], operands[n-1] + elseif p == "=" then + local n = #operands + if last == operands[n-1] then + operands[n] = nil + name = altname + end + elseif p == "%" then + local n = #operands + if last == operands[n-1] and last == operands[n-2] then + operands[n] = nil + operands[n-1] = nil + name = altname + end + elseif p == "-" then + rs = rs - 5 + else + assert(false) + end + if x then operands[#operands+1] = x; last = x end + end + + return putop(ctx, name, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + stop = stop - stop % 4 + ctx.pos = ofs - ofs % 4 + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 32 then return map_gpr[r] end + return "f"..(r-32) +end + +-- Public module functions. +module(...) + +create = create_ +disass = disass_ +regname = regname_ + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x64.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x64.lua new file mode 100644 index 0000000..4f49169 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x64.lua @@ -0,0 +1,20 @@ +---------------------------------------------------------------------------- +-- LuaJIT x64 disassembler wrapper module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This module just exports the 64 bit functions from the combined +-- x86/x64 disassembler module. All the interesting stuff is there. +------------------------------------------------------------------------------ + +local require = require + +module(...) + +local dis_x86 = require(_PACKAGE.."dis_x86") + +create = dis_x86.create64 +disass = dis_x86.disass64 +regname = dis_x86.regname64 + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x86.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x86.lua new file mode 100644 index 0000000..0b865ab --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dis_x86.lua @@ -0,0 +1,836 @@ +---------------------------------------------------------------------------- +-- LuaJIT x86/x64 disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- Sending small code snippets to an external disassembler and mixing the +-- output with our own stuff was too fragile. So I had to bite the bullet +-- and write yet another x86 disassembler. Oh well ... +-- +-- The output format is very similar to what ndisasm generates. But it has +-- been developed independently by looking at the opcode tables from the +-- Intel and AMD manuals. The supported instruction set is quite extensive +-- and reflects what a current generation Intel or AMD CPU implements in +-- 32 bit and 64 bit mode. Yes, this includes MMX, SSE, SSE2, SSE3, SSSE3, +-- SSE4.1, SSE4.2, SSE4a and even privileged and hypervisor (VMX/SVM) +-- instructions. +-- +-- Notes: +-- * The (useless) a16 prefix, 3DNow and pre-586 opcodes are unsupported. +-- * No attempt at optimization has been made -- it's fast enough for my needs. +-- * The public API may change when more architectures are added. +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local lower, rep = string.lower, string.rep + +-- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on. +local map_opc1_32 = { +--0x +[0]="addBmr","addVmr","addBrm","addVrm","addBai","addVai","push es","pop es", +"orBmr","orVmr","orBrm","orVrm","orBai","orVai","push cs","opc2*", +--1x +"adcBmr","adcVmr","adcBrm","adcVrm","adcBai","adcVai","push ss","pop ss", +"sbbBmr","sbbVmr","sbbBrm","sbbVrm","sbbBai","sbbVai","push ds","pop ds", +--2x +"andBmr","andVmr","andBrm","andVrm","andBai","andVai","es:seg","daa", +"subBmr","subVmr","subBrm","subVrm","subBai","subVai","cs:seg","das", +--3x +"xorBmr","xorVmr","xorBrm","xorVrm","xorBai","xorVai","ss:seg","aaa", +"cmpBmr","cmpVmr","cmpBrm","cmpVrm","cmpBai","cmpVai","ds:seg","aas", +--4x +"incVR","incVR","incVR","incVR","incVR","incVR","incVR","incVR", +"decVR","decVR","decVR","decVR","decVR","decVR","decVR","decVR", +--5x +"pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR", +"popUR","popUR","popUR","popUR","popUR","popUR","popUR","popUR", +--6x +"sz*pushaw,pusha","sz*popaw,popa","boundVrm","arplWmr", +"fs:seg","gs:seg","o16:","a16", +"pushUi","imulVrmi","pushBs","imulVrms", +"insb","insVS","outsb","outsVS", +--7x +"joBj","jnoBj","jbBj","jnbBj","jzBj","jnzBj","jbeBj","jaBj", +"jsBj","jnsBj","jpeBj","jpoBj","jlBj","jgeBj","jleBj","jgBj", +--8x +"arith!Bmi","arith!Vmi","arith!Bmi","arith!Vms", +"testBmr","testVmr","xchgBrm","xchgVrm", +"movBmr","movVmr","movBrm","movVrm", +"movVmg","leaVrm","movWgm","popUm", +--9x +"nop*xchgVaR|pause|xchgWaR|repne nop","xchgVaR","xchgVaR","xchgVaR", +"xchgVaR","xchgVaR","xchgVaR","xchgVaR", +"sz*cbw,cwde,cdqe","sz*cwd,cdq,cqo","call farViw","wait", +"sz*pushfw,pushf","sz*popfw,popf","sahf","lahf", +--Ax +"movBao","movVao","movBoa","movVoa", +"movsb","movsVS","cmpsb","cmpsVS", +"testBai","testVai","stosb","stosVS", +"lodsb","lodsVS","scasb","scasVS", +--Bx +"movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi", +"movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI", +--Cx +"shift!Bmu","shift!Vmu","retBw","ret","$lesVrm","$ldsVrm","movBmi","movVmi", +"enterBwu","leave","retfBw","retf","int3","intBu","into","iretVS", +--Dx +"shift!Bm1","shift!Vm1","shift!Bmc","shift!Vmc","aamBu","aadBu","salc","xlatb", +"fp*0","fp*1","fp*2","fp*3","fp*4","fp*5","fp*6","fp*7", +--Ex +"loopneBj","loopeBj","loopBj","sz*jcxzBj,jecxzBj,jrcxzBj", +"inBau","inVau","outBua","outVua", +"callVj","jmpVj","jmp farViw","jmpBj","inBad","inVad","outBda","outVda", +--Fx +"lock:","int1","repne:rep","rep:","hlt","cmc","testb!Bm","testv!Vm", +"clc","stc","cli","sti","cld","std","incb!Bm","incd!Vm", +} +assert(#map_opc1_32 == 255) + +-- Map for 1st opcode byte in 64 bit mode (overrides only). +local map_opc1_64 = setmetatable({ + [0x06]=false, [0x07]=false, [0x0e]=false, + [0x16]=false, [0x17]=false, [0x1e]=false, [0x1f]=false, + [0x27]=false, [0x2f]=false, [0x37]=false, [0x3f]=false, + [0x60]=false, [0x61]=false, [0x62]=false, [0x63]="movsxdVrDmt", [0x67]="a32:", + [0x40]="rex*", [0x41]="rex*b", [0x42]="rex*x", [0x43]="rex*xb", + [0x44]="rex*r", [0x45]="rex*rb", [0x46]="rex*rx", [0x47]="rex*rxb", + [0x48]="rex*w", [0x49]="rex*wb", [0x4a]="rex*wx", [0x4b]="rex*wxb", + [0x4c]="rex*wr", [0x4d]="rex*wrb", [0x4e]="rex*wrx", [0x4f]="rex*wrxb", + [0x82]=false, [0x9a]=false, [0xc4]=false, [0xc5]=false, [0xce]=false, + [0xd4]=false, [0xd5]=false, [0xd6]=false, [0xea]=false, +}, { __index = map_opc1_32 }) + +-- Map for 2nd opcode byte (0F xx). True CISC hell. Hey, I told you. +-- Prefix dependent MMX/SSE opcodes: (none)|rep|o16|repne, -|F3|66|F2 +local map_opc2 = { +--0x +[0]="sldt!Dmp","sgdt!Ump","larVrm","lslVrm",nil,"syscall","clts","sysret", +"invd","wbinvd",nil,"ud1",nil,"$prefetch!Bm","femms","3dnowMrmu", +--1x +"movupsXrm|movssXrm|movupdXrm|movsdXrm", +"movupsXmr|movssXmr|movupdXmr|movsdXmr", +"movhlpsXrm$movlpsXrm|movsldupXrm|movlpdXrm|movddupXrm", +"movlpsXmr||movlpdXmr", +"unpcklpsXrm||unpcklpdXrm", +"unpckhpsXrm||unpckhpdXrm", +"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm", +"movhpsXmr||movhpdXmr", +"$prefetcht!Bm","hintnopVm","hintnopVm","hintnopVm", +"hintnopVm","hintnopVm","hintnopVm","hintnopVm", +--2x +"movUmx$","movUmy$","movUxm$","movUym$","movUmz$",nil,"movUzm$",nil, +"movapsXrm||movapdXrm", +"movapsXmr||movapdXmr", +"cvtpi2psXrMm|cvtsi2ssXrVmt|cvtpi2pdXrMm|cvtsi2sdXrVmt", +"movntpsXmr|movntssXmr|movntpdXmr|movntsdXmr", +"cvttps2piMrXm|cvttss2siVrXm|cvttpd2piMrXm|cvttsd2siVrXm", +"cvtps2piMrXm|cvtss2siVrXm|cvtpd2piMrXm|cvtsd2siVrXm", +"ucomissXrm||ucomisdXrm", +"comissXrm||comisdXrm", +--3x +"wrmsr","rdtsc","rdmsr","rdpmc","sysenter","sysexit",nil,"getsec", +"opc3*38",nil,"opc3*3a",nil,nil,nil,nil,nil, +--4x +"cmovoVrm","cmovnoVrm","cmovbVrm","cmovnbVrm", +"cmovzVrm","cmovnzVrm","cmovbeVrm","cmovaVrm", +"cmovsVrm","cmovnsVrm","cmovpeVrm","cmovpoVrm", +"cmovlVrm","cmovgeVrm","cmovleVrm","cmovgVrm", +--5x +"movmskpsVrXm$||movmskpdVrXm$","sqrtpsXrm|sqrtssXrm|sqrtpdXrm|sqrtsdXrm", +"rsqrtpsXrm|rsqrtssXrm","rcppsXrm|rcpssXrm", +"andpsXrm||andpdXrm","andnpsXrm||andnpdXrm", +"orpsXrm||orpdXrm","xorpsXrm||xorpdXrm", +"addpsXrm|addssXrm|addpdXrm|addsdXrm","mulpsXrm|mulssXrm|mulpdXrm|mulsdXrm", +"cvtps2pdXrm|cvtss2sdXrm|cvtpd2psXrm|cvtsd2ssXrm", +"cvtdq2psXrm|cvttps2dqXrm|cvtps2dqXrm", +"subpsXrm|subssXrm|subpdXrm|subsdXrm","minpsXrm|minssXrm|minpdXrm|minsdXrm", +"divpsXrm|divssXrm|divpdXrm|divsdXrm","maxpsXrm|maxssXrm|maxpdXrm|maxsdXrm", +--6x +"punpcklbwPrm","punpcklwdPrm","punpckldqPrm","packsswbPrm", +"pcmpgtbPrm","pcmpgtwPrm","pcmpgtdPrm","packuswbPrm", +"punpckhbwPrm","punpckhwdPrm","punpckhdqPrm","packssdwPrm", +"||punpcklqdqXrm","||punpckhqdqXrm", +"movPrVSm","movqMrm|movdquXrm|movdqaXrm", +--7x +"pshufwMrmu|pshufhwXrmu|pshufdXrmu|pshuflwXrmu","pshiftw!Pmu", +"pshiftd!Pmu","pshiftq!Mmu||pshiftdq!Xmu", +"pcmpeqbPrm","pcmpeqwPrm","pcmpeqdPrm","emms|", +"vmreadUmr||extrqXmuu$|insertqXrmuu$","vmwriteUrm||extrqXrm$|insertqXrm$", +nil,nil, +"||haddpdXrm|haddpsXrm","||hsubpdXrm|hsubpsXrm", +"movVSmMr|movqXrm|movVSmXr","movqMmr|movdquXmr|movdqaXmr", +--8x +"joVj","jnoVj","jbVj","jnbVj","jzVj","jnzVj","jbeVj","jaVj", +"jsVj","jnsVj","jpeVj","jpoVj","jlVj","jgeVj","jleVj","jgVj", +--9x +"setoBm","setnoBm","setbBm","setnbBm","setzBm","setnzBm","setbeBm","setaBm", +"setsBm","setnsBm","setpeBm","setpoBm","setlBm","setgeBm","setleBm","setgBm", +--Ax +"push fs","pop fs","cpuid","btVmr","shldVmru","shldVmrc",nil,nil, +"push gs","pop gs","rsm","btsVmr","shrdVmru","shrdVmrc","fxsave!Dmp","imulVrm", +--Bx +"cmpxchgBmr","cmpxchgVmr","$lssVrm","btrVmr", +"$lfsVrm","$lgsVrm","movzxVrBmt","movzxVrWmt", +"|popcntVrm","ud2Dp","bt!Vmu","btcVmr", +"bsfVrm","bsrVrm|lzcntVrm|bsrWrm","movsxVrBmt","movsxVrWmt", +--Cx +"xaddBmr","xaddVmr", +"cmppsXrmu|cmpssXrmu|cmppdXrmu|cmpsdXrmu","$movntiVmr|", +"pinsrwPrWmu","pextrwDrPmu", +"shufpsXrmu||shufpdXrmu","$cmpxchg!Qmp", +"bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR", +--Dx +"||addsubpdXrm|addsubpsXrm","psrlwPrm","psrldPrm","psrlqPrm", +"paddqPrm","pmullwPrm", +"|movq2dqXrMm|movqXmr|movdq2qMrXm$","pmovmskbVrMm||pmovmskbVrXm", +"psubusbPrm","psubuswPrm","pminubPrm","pandPrm", +"paddusbPrm","padduswPrm","pmaxubPrm","pandnPrm", +--Ex +"pavgbPrm","psrawPrm","psradPrm","pavgwPrm", +"pmulhuwPrm","pmulhwPrm", +"|cvtdq2pdXrm|cvttpd2dqXrm|cvtpd2dqXrm","$movntqMmr||$movntdqXmr", +"psubsbPrm","psubswPrm","pminswPrm","porPrm", +"paddsbPrm","paddswPrm","pmaxswPrm","pxorPrm", +--Fx +"|||lddquXrm","psllwPrm","pslldPrm","psllqPrm", +"pmuludqPrm","pmaddwdPrm","psadbwPrm","maskmovqMrm||maskmovdquXrm$", +"psubbPrm","psubwPrm","psubdPrm","psubqPrm", +"paddbPrm","paddwPrm","padddPrm","ud", +} +assert(map_opc2[255] == "ud") + +-- Map for three-byte opcodes. Can't wait for their next invention. +local map_opc3 = { +["38"] = { -- [66] 0f 38 xx +--0x +[0]="pshufbPrm","phaddwPrm","phadddPrm","phaddswPrm", +"pmaddubswPrm","phsubwPrm","phsubdPrm","phsubswPrm", +"psignbPrm","psignwPrm","psigndPrm","pmulhrswPrm", +nil,nil,nil,nil, +--1x +"||pblendvbXrma",nil,nil,nil, +"||blendvpsXrma","||blendvpdXrma",nil,"||ptestXrm", +nil,nil,nil,nil, +"pabsbPrm","pabswPrm","pabsdPrm",nil, +--2x +"||pmovsxbwXrm","||pmovsxbdXrm","||pmovsxbqXrm","||pmovsxwdXrm", +"||pmovsxwqXrm","||pmovsxdqXrm",nil,nil, +"||pmuldqXrm","||pcmpeqqXrm","||$movntdqaXrm","||packusdwXrm", +nil,nil,nil,nil, +--3x +"||pmovzxbwXrm","||pmovzxbdXrm","||pmovzxbqXrm","||pmovzxwdXrm", +"||pmovzxwqXrm","||pmovzxdqXrm",nil,"||pcmpgtqXrm", +"||pminsbXrm","||pminsdXrm","||pminuwXrm","||pminudXrm", +"||pmaxsbXrm","||pmaxsdXrm","||pmaxuwXrm","||pmaxudXrm", +--4x +"||pmulddXrm","||phminposuwXrm", +--Fx +[0xf0] = "|||crc32TrBmt",[0xf1] = "|||crc32TrVmt", +}, + +["3a"] = { -- [66] 0f 3a xx +--0x +[0x00]=nil,nil,nil,nil,nil,nil,nil,nil, +"||roundpsXrmu","||roundpdXrmu","||roundssXrmu","||roundsdXrmu", +"||blendpsXrmu","||blendpdXrmu","||pblendwXrmu","palignrPrmu", +--1x +nil,nil,nil,nil, +"||pextrbVmXru","||pextrwVmXru","||pextrVmSXru","||extractpsVmXru", +nil,nil,nil,nil,nil,nil,nil,nil, +--2x +"||pinsrbXrVmu","||insertpsXrmu","||pinsrXrVmuS",nil, +--4x +[0x40] = "||dppsXrmu", +[0x41] = "||dppdXrmu", +[0x42] = "||mpsadbwXrmu", +--6x +[0x60] = "||pcmpestrmXrmu",[0x61] = "||pcmpestriXrmu", +[0x62] = "||pcmpistrmXrmu",[0x63] = "||pcmpistriXrmu", +}, +} + +-- Map for VMX/SVM opcodes 0F 01 C0-FF (sgdt group with register operands). +local map_opcvm = { +[0xc1]="vmcall",[0xc2]="vmlaunch",[0xc3]="vmresume",[0xc4]="vmxoff", +[0xc8]="monitor",[0xc9]="mwait", +[0xd8]="vmrun",[0xd9]="vmmcall",[0xda]="vmload",[0xdb]="vmsave", +[0xdc]="stgi",[0xdd]="clgi",[0xde]="skinit",[0xdf]="invlpga", +[0xf8]="swapgs",[0xf9]="rdtscp", +} + +-- Map for FP opcodes. And you thought stack machines are simple? +local map_opcfp = { +-- D8-DF 00-BF: opcodes with a memory operand. +-- D8 +[0]="faddFm","fmulFm","fcomFm","fcompFm","fsubFm","fsubrFm","fdivFm","fdivrFm", +"fldFm",nil,"fstFm","fstpFm","fldenvVm","fldcwWm","fnstenvVm","fnstcwWm", +-- DA +"fiaddDm","fimulDm","ficomDm","ficompDm", +"fisubDm","fisubrDm","fidivDm","fidivrDm", +-- DB +"fildDm","fisttpDm","fistDm","fistpDm",nil,"fld twordFmp",nil,"fstp twordFmp", +-- DC +"faddGm","fmulGm","fcomGm","fcompGm","fsubGm","fsubrGm","fdivGm","fdivrGm", +-- DD +"fldGm","fisttpQm","fstGm","fstpGm","frstorDmp",nil,"fnsaveDmp","fnstswWm", +-- DE +"fiaddWm","fimulWm","ficomWm","ficompWm", +"fisubWm","fisubrWm","fidivWm","fidivrWm", +-- DF +"fildWm","fisttpWm","fistWm","fistpWm", +"fbld twordFmp","fildQm","fbstp twordFmp","fistpQm", +-- xx C0-FF: opcodes with a pseudo-register operand. +-- D8 +"faddFf","fmulFf","fcomFf","fcompFf","fsubFf","fsubrFf","fdivFf","fdivrFf", +-- D9 +"fldFf","fxchFf",{"fnop"},nil, +{"fchs","fabs",nil,nil,"ftst","fxam"}, +{"fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz"}, +{"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp"}, +{"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"}, +-- DA +"fcmovbFf","fcmoveFf","fcmovbeFf","fcmovuFf",nil,{nil,"fucompp"},nil,nil, +-- DB +"fcmovnbFf","fcmovneFf","fcmovnbeFf","fcmovnuFf", +{nil,nil,"fnclex","fninit"},"fucomiFf","fcomiFf",nil, +-- DC +"fadd toFf","fmul toFf",nil,nil, +"fsub toFf","fsubr toFf","fdivr toFf","fdiv toFf", +-- DD +"ffreeFf",nil,"fstFf","fstpFf","fucomFf","fucompFf",nil,nil, +-- DE +"faddpFf","fmulpFf",nil,{nil,"fcompp"}, +"fsubrpFf","fsubpFf","fdivrpFf","fdivpFf", +-- DF +nil,nil,nil,nil,{"fnstsw ax"},"fucomipFf","fcomipFf",nil, +} +assert(map_opcfp[126] == "fcomipFf") + +-- Map for opcode groups. The subkey is sp from the ModRM byte. +local map_opcgroup = { + arith = { "add", "or", "adc", "sbb", "and", "sub", "xor", "cmp" }, + shift = { "rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar" }, + testb = { "testBmi", "testBmi", "not", "neg", "mul", "imul", "div", "idiv" }, + testv = { "testVmi", "testVmi", "not", "neg", "mul", "imul", "div", "idiv" }, + incb = { "inc", "dec" }, + incd = { "inc", "dec", "callUmp", "$call farDmp", + "jmpUmp", "$jmp farDmp", "pushUm" }, + sldt = { "sldt", "str", "lldt", "ltr", "verr", "verw" }, + sgdt = { "vm*$sgdt", "vm*$sidt", "$lgdt", "vm*$lidt", + "smsw", nil, "lmsw", "vm*$invlpg" }, + bt = { nil, nil, nil, nil, "bt", "bts", "btr", "btc" }, + cmpxchg = { nil, "sz*,cmpxchg8bQmp,cmpxchg16bXmp", nil, nil, + nil, nil, "vmptrld|vmxon|vmclear", "vmptrst" }, + pshiftw = { nil, nil, "psrlw", nil, "psraw", nil, "psllw" }, + pshiftd = { nil, nil, "psrld", nil, "psrad", nil, "pslld" }, + pshiftq = { nil, nil, "psrlq", nil, nil, nil, "psllq" }, + pshiftdq = { nil, nil, "psrlq", "psrldq", nil, nil, "psllq", "pslldq" }, + fxsave = { "$fxsave", "$fxrstor", "$ldmxcsr", "$stmxcsr", + nil, "lfenceDp$", "mfenceDp$", "sfenceDp$clflush" }, + prefetch = { "prefetch", "prefetchw" }, + prefetcht = { "prefetchnta", "prefetcht0", "prefetcht1", "prefetcht2" }, +} + +------------------------------------------------------------------------------ + +-- Maps for register names. +local map_regs = { + B = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh", + "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" }, + B64 = { "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil", + "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" }, + W = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", + "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w" }, + D = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", + "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" }, + Q = { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" }, + M = { "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", + "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7" }, -- No x64 ext! + X = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", + "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" }, +} +local map_segregs = { "es", "cs", "ss", "ds", "fs", "gs", "segr6", "segr7" } + +-- Maps for size names. +local map_sz2n = { + B = 1, W = 2, D = 4, Q = 8, M = 8, X = 16, +} +local map_sz2prefix = { + B = "byte", W = "word", D = "dword", + Q = "qword", + M = "qword", X = "xword", + F = "dword", G = "qword", -- No need for sizes/register names for these two. +} + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local code, pos, hex = ctx.code, ctx.pos, "" + local hmax = ctx.hexdump + if hmax > 0 then + for i=ctx.start,pos-1 do + hex = hex..format("%02X", byte(code, i, i)) + end + if #hex > hmax then hex = sub(hex, 1, hmax)..". " + else hex = hex..rep(" ", hmax-#hex+2) end + end + if operands then text = text.." "..operands end + if ctx.o16 then text = "o16 "..text; ctx.o16 = false end + if ctx.a32 then text = "a32 "..text; ctx.a32 = false end + if ctx.rep then text = ctx.rep.." "..text; ctx.rep = false end + if ctx.rex then + local t = (ctx.rexw and "w" or "")..(ctx.rexr and "r" or "").. + (ctx.rexx and "x" or "")..(ctx.rexb and "b" or "") + if t ~= "" then text = "rex."..t.." "..text end + ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false + ctx.rex = false + end + if ctx.seg then + local text2, n = gsub(text, "%[", "["..ctx.seg..":") + if n == 0 then text = ctx.seg.." "..text else text = text2 end + ctx.seg = false + end + if ctx.lock then text = "lock "..text; ctx.lock = false end + local imm = ctx.imm + if imm then + local sym = ctx.symtab[imm] + if sym then text = text.."\t->"..sym end + end + ctx.out(format("%08x %s%s\n", ctx.addr+ctx.start, hex, text)) + ctx.mrm = false + ctx.start = pos + ctx.imm = nil +end + +-- Clear all prefix flags. +local function clearprefixes(ctx) + ctx.o16 = false; ctx.seg = false; ctx.lock = false; ctx.rep = false + ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false + ctx.rex = false; ctx.a32 = false +end + +-- Fallback for incomplete opcodes at the end. +local function incomplete(ctx) + ctx.pos = ctx.stop+1 + clearprefixes(ctx) + return putop(ctx, "(incomplete)") +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + clearprefixes(ctx) + return putop(ctx, "(unknown)") +end + +-- Return an immediate of the specified size. +local function getimm(ctx, pos, n) + if pos+n-1 > ctx.stop then return incomplete(ctx) end + local code = ctx.code + if n == 1 then + local b1 = byte(code, pos, pos) + return b1 + elseif n == 2 then + local b1, b2 = byte(code, pos, pos+1) + return b1+b2*256 + else + local b1, b2, b3, b4 = byte(code, pos, pos+3) + local imm = b1+b2*256+b3*65536+b4*16777216 + ctx.imm = imm + return imm + end +end + +-- Process pattern string and generate the operands. +local function putpat(ctx, name, pat) + local operands, regs, sz, mode, sp, rm, sc, rx, sdisp + local code, pos, stop = ctx.code, ctx.pos, ctx.stop + + -- Chars used: 1DFGIMPQRSTUVWXacdfgijmoprstuwxyz + for p in gmatch(pat, ".") do + local x = nil + if p == "V" or p == "U" then + if ctx.rexw then sz = "Q"; ctx.rexw = false + elseif ctx.o16 then sz = "W"; ctx.o16 = false + elseif p == "U" and ctx.x64 then sz = "Q" + else sz = "D" end + regs = map_regs[sz] + elseif p == "T" then + if ctx.rexw then sz = "Q"; ctx.rexw = false else sz = "D" end + regs = map_regs[sz] + elseif p == "B" then + sz = "B" + regs = ctx.rex and map_regs.B64 or map_regs.B + elseif match(p, "[WDQMXFG]") then + sz = p + regs = map_regs[sz] + elseif p == "P" then + sz = ctx.o16 and "X" or "M"; ctx.o16 = false + regs = map_regs[sz] + elseif p == "S" then + name = name..lower(sz) + elseif p == "s" then + local imm = getimm(ctx, pos, 1); if not imm then return end + x = imm <= 127 and format("+0x%02x", imm) + or format("-0x%02x", 256-imm) + pos = pos+1 + elseif p == "u" then + local imm = getimm(ctx, pos, 1); if not imm then return end + x = format("0x%02x", imm) + pos = pos+1 + elseif p == "w" then + local imm = getimm(ctx, pos, 2); if not imm then return end + x = format("0x%x", imm) + pos = pos+2 + elseif p == "o" then -- [offset] + if ctx.x64 then + local imm1 = getimm(ctx, pos, 4); if not imm1 then return end + local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end + x = format("[0x%08x%08x]", imm2, imm1) + pos = pos+8 + else + local imm = getimm(ctx, pos, 4); if not imm then return end + x = format("[0x%08x]", imm) + pos = pos+4 + end + elseif p == "i" or p == "I" then + local n = map_sz2n[sz] + if n == 8 and ctx.x64 and p == "I" then + local imm1 = getimm(ctx, pos, 4); if not imm1 then return end + local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end + x = format("0x%08x%08x", imm2, imm1) + else + if n == 8 then n = 4 end + local imm = getimm(ctx, pos, n); if not imm then return end + if sz == "Q" and (imm < 0 or imm > 0x7fffffff) then + imm = (0xffffffff+1)-imm + x = format(imm > 65535 and "-0x%08x" or "-0x%x", imm) + else + x = format(imm > 65535 and "0x%08x" or "0x%x", imm) + end + end + pos = pos+n + elseif p == "j" then + local n = map_sz2n[sz] + if n == 8 then n = 4 end + local imm = getimm(ctx, pos, n); if not imm then return end + if sz == "B" and imm > 127 then imm = imm-256 + elseif imm > 2147483647 then imm = imm-4294967296 end + pos = pos+n + imm = imm + pos + ctx.addr + if imm > 4294967295 and not ctx.x64 then imm = imm-4294967296 end + ctx.imm = imm + if sz == "W" then + x = format("word 0x%04x", imm%65536) + elseif ctx.x64 then + local lo = imm % 0x1000000 + x = format("0x%02x%06x", (imm-lo) / 0x1000000, lo) + else + x = format("0x%08x", imm) + end + elseif p == "R" then + local r = byte(code, pos-1, pos-1)%8 + if ctx.rexb then r = r + 8; ctx.rexb = false end + x = regs[r+1] + elseif p == "a" then x = regs[1] + elseif p == "c" then x = "cl" + elseif p == "d" then x = "dx" + elseif p == "1" then x = "1" + else + if not mode then + mode = ctx.mrm + if not mode then + if pos > stop then return incomplete(ctx) end + mode = byte(code, pos, pos) + pos = pos+1 + end + rm = mode%8; mode = (mode-rm)/8 + sp = mode%8; mode = (mode-sp)/8 + sdisp = "" + if mode < 3 then + if rm == 4 then + if pos > stop then return incomplete(ctx) end + sc = byte(code, pos, pos) + pos = pos+1 + rm = sc%8; sc = (sc-rm)/8 + rx = sc%8; sc = (sc-rx)/8 + if ctx.rexx then rx = rx + 8; ctx.rexx = false end + if rx == 4 then rx = nil end + end + if mode > 0 or rm == 5 then + local dsz = mode + if dsz ~= 1 then dsz = 4 end + local disp = getimm(ctx, pos, dsz); if not disp then return end + if mode == 0 then rm = nil end + if rm or rx or (not sc and ctx.x64 and not ctx.a32) then + if dsz == 1 and disp > 127 then + sdisp = format("-0x%x", 256-disp) + elseif disp >= 0 and disp <= 0x7fffffff then + sdisp = format("+0x%x", disp) + else + sdisp = format("-0x%x", (0xffffffff+1)-disp) + end + else + sdisp = format(ctx.x64 and not ctx.a32 and + not (disp >= 0 and disp <= 0x7fffffff) + and "0xffffffff%08x" or "0x%08x", disp) + end + pos = pos+dsz + end + end + if rm and ctx.rexb then rm = rm + 8; ctx.rexb = false end + if ctx.rexr then sp = sp + 8; ctx.rexr = false end + end + if p == "m" then + if mode == 3 then x = regs[rm+1] + else + local aregs = ctx.a32 and map_regs.D or ctx.aregs + local srm, srx = "", "" + if rm then srm = aregs[rm+1] + elseif not sc and ctx.x64 and not ctx.a32 then srm = "rip" end + ctx.a32 = false + if rx then + if rm then srm = srm.."+" end + srx = aregs[rx+1] + if sc > 0 then srx = srx.."*"..(2^sc) end + end + x = format("[%s%s%s]", srm, srx, sdisp) + end + if mode < 3 and + (not match(pat, "[aRrgp]") or match(pat, "t")) then -- Yuck. + x = map_sz2prefix[sz].." "..x + end + elseif p == "r" then x = regs[sp+1] + elseif p == "g" then x = map_segregs[sp+1] + elseif p == "p" then -- Suppress prefix. + elseif p == "f" then x = "st"..rm + elseif p == "x" then + if sp == 0 and ctx.lock and not ctx.x64 then + x = "CR8"; ctx.lock = false + else + x = "CR"..sp + end + elseif p == "y" then x = "DR"..sp + elseif p == "z" then x = "TR"..sp + elseif p == "t" then + else + error("bad pattern `"..pat.."'") + end + end + if x then operands = operands and operands..", "..x or x end + end + ctx.pos = pos + return putop(ctx, name, operands) +end + +-- Forward declaration. +local map_act + +-- Fetch and cache MRM byte. +local function getmrm(ctx) + local mrm = ctx.mrm + if not mrm then + local pos = ctx.pos + if pos > ctx.stop then return nil end + mrm = byte(ctx.code, pos, pos) + ctx.pos = pos+1 + ctx.mrm = mrm + end + return mrm +end + +-- Dispatch to handler depending on pattern. +local function dispatch(ctx, opat, patgrp) + if not opat then return unknown(ctx) end + if match(opat, "%|") then -- MMX/SSE variants depending on prefix. + local p + if ctx.rep then + p = ctx.rep=="rep" and "%|([^%|]*)" or "%|[^%|]*%|[^%|]*%|([^%|]*)" + ctx.rep = false + elseif ctx.o16 then p = "%|[^%|]*%|([^%|]*)"; ctx.o16 = false + else p = "^[^%|]*" end + opat = match(opat, p) + if not opat then return unknown(ctx) end +-- ctx.rep = false; ctx.o16 = false + --XXX fails for 66 f2 0f 38 f1 06 crc32 eax,WORD PTR [esi] + --XXX remove in branches? + end + if match(opat, "%$") then -- reg$mem variants. + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + opat = match(opat, mrm >= 192 and "^[^%$]*" or "%$(.*)") + if opat == "" then return unknown(ctx) end + end + if opat == "" then return unknown(ctx) end + local name, pat = match(opat, "^([a-z0-9 ]*)(.*)") + if pat == "" and patgrp then pat = patgrp end + return map_act[sub(pat, 1, 1)](ctx, name, pat) +end + +-- Get a pattern from an opcode map and dispatch to handler. +local function dispatchmap(ctx, opcmap) + local pos = ctx.pos + local opat = opcmap[byte(ctx.code, pos, pos)] + pos = pos + 1 + ctx.pos = pos + return dispatch(ctx, opat) +end + +-- Map for action codes. The key is the first char after the name. +map_act = { + -- Simple opcodes without operands. + [""] = function(ctx, name, pat) + return putop(ctx, name) + end, + + -- Operand size chars fall right through. + B = putpat, W = putpat, D = putpat, Q = putpat, + V = putpat, U = putpat, T = putpat, + M = putpat, X = putpat, P = putpat, + F = putpat, G = putpat, + + -- Collect prefixes. + [":"] = function(ctx, name, pat) + ctx[pat == ":" and name or sub(pat, 2)] = name + if ctx.pos - ctx.start > 5 then return unknown(ctx) end -- Limit #prefixes. + end, + + -- Chain to special handler specified by name. + ["*"] = function(ctx, name, pat) + return map_act[name](ctx, name, sub(pat, 2)) + end, + + -- Use named subtable for opcode group. + ["!"] = function(ctx, name, pat) + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + return dispatch(ctx, map_opcgroup[name][((mrm-(mrm%8))/8)%8+1], sub(pat, 2)) + end, + + -- o16,o32[,o64] variants. + sz = function(ctx, name, pat) + if ctx.o16 then ctx.o16 = false + else + pat = match(pat, ",(.*)") + if ctx.rexw then + local p = match(pat, ",(.*)") + if p then pat = p; ctx.rexw = false end + end + end + pat = match(pat, "^[^,]*") + return dispatch(ctx, pat) + end, + + -- Two-byte opcode dispatch. + opc2 = function(ctx, name, pat) + return dispatchmap(ctx, map_opc2) + end, + + -- Three-byte opcode dispatch. + opc3 = function(ctx, name, pat) + return dispatchmap(ctx, map_opc3[pat]) + end, + + -- VMX/SVM dispatch. + vm = function(ctx, name, pat) + return dispatch(ctx, map_opcvm[ctx.mrm]) + end, + + -- Floating point opcode dispatch. + fp = function(ctx, name, pat) + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + local rm = mrm%8 + local idx = pat*8 + ((mrm-rm)/8)%8 + if mrm >= 192 then idx = idx + 64 end + local opat = map_opcfp[idx] + if type(opat) == "table" then opat = opat[rm+1] end + return dispatch(ctx, opat) + end, + + -- REX prefix. + rex = function(ctx, name, pat) + if ctx.rex then return unknown(ctx) end -- Only 1 REX prefix allowed. + for p in gmatch(pat, ".") do ctx["rex"..p] = true end + ctx.rex = true + end, + + -- Special case for nop with REX prefix. + nop = function(ctx, name, pat) + return dispatch(ctx, ctx.rex and pat or "nop") + end, +} + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + ofs = ofs + 1 + ctx.start = ofs + ctx.pos = ofs + ctx.stop = stop + ctx.imm = nil + ctx.mrm = false + clearprefixes(ctx) + while ctx.pos <= stop do dispatchmap(ctx, ctx.map1) end + if ctx.pos ~= ctx.start then incomplete(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = (addr or 0) - 1 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 16 + ctx.x64 = false + ctx.map1 = map_opc1_32 + ctx.aregs = map_regs.D + return ctx +end + +local function create64_(code, addr, out) + local ctx = create_(code, addr, out) + ctx.x64 = true + ctx.map1 = map_opc1_64 + ctx.aregs = map_regs.Q + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +local function disass64_(code, addr, out) + create64_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 8 then return map_regs.D[r+1] end + return map_regs.X[r-7] +end + +local function regname64_(r) + if r < 16 then return map_regs.Q[r+1] end + return map_regs.X[r-15] +end + +-- Public module functions. +module(...) + +create = create_ +create64 = create64_ +disass = disass_ +disass64 = disass64_ +regname = regname_ +regname64 = regname64_ + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dump.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dump.lua new file mode 100644 index 0000000..556ce88 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/dump.lua @@ -0,0 +1,699 @@ +---------------------------------------------------------------------------- +-- LuaJIT compiler dump module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module can be used to debug the JIT compiler itself. It dumps the +-- code representations and structures used in various compiler stages. +-- +-- Example usage: +-- +-- luajit -jdump -e "local x=0; for i=1,1e6 do x=x+i end; print(x)" +-- luajit -jdump=im -e "for i=1,1000 do for j=1,1000 do end end" | less -R +-- luajit -jdump=is myapp.lua | less -R +-- luajit -jdump=-b myapp.lua +-- luajit -jdump=+aH,myapp.html myapp.lua +-- luajit -jdump=ixT,myapp.dump myapp.lua +-- +-- The first argument specifies the dump mode. The second argument gives +-- the output file name. Default output is to stdout, unless the environment +-- variable LUAJIT_DUMPFILE is set. The file is overwritten every time the +-- module is started. +-- +-- Different features can be turned on or off with the dump mode. If the +-- mode starts with a '+', the following features are added to the default +-- set of features; a '-' removes them. Otherwise the features are replaced. +-- +-- The following dump features are available (* marks the default): +-- +-- * t Print a line for each started, ended or aborted trace (see also -jv). +-- * b Dump the traced bytecode. +-- * i Dump the IR (intermediate representation). +-- r Augment the IR with register/stack slots. +-- s Dump the snapshot map. +-- * m Dump the generated machine code. +-- x Print each taken trace exit. +-- X Print each taken trace exit and the contents of all registers. +-- a Print the IR of aborted traces, too. +-- +-- The output format can be set with the following characters: +-- +-- T Plain text output. +-- A ANSI-colored text output +-- H Colorized HTML + CSS output. +-- +-- The default output format is plain text. It's set to ANSI-colored text +-- if the COLORTERM variable is set. Note: this is independent of any output +-- redirection, which is actually considered a feature. +-- +-- You probably want to use less -R to enjoy viewing ANSI-colored text from +-- a pipe or a file. Add this to your ~/.bashrc: export LESS="-R" +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc +local traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek +local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap +local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr +local bit = require("bit") +local band, shl, shr = bit.band, bit.lshift, bit.rshift +local sub, gsub, format = string.sub, string.gsub, string.format +local byte, char, rep = string.byte, string.char, string.rep +local type, tostring = type, tostring +local stdout, stderr = io.stdout, io.stderr + +-- Load other modules on-demand. +local bcline, disass + +-- Active flag, output file handle and dump mode. +local active, out, dumpmode + +------------------------------------------------------------------------------ + +local symtabmt = { __index = false } +local symtab = {} +local nexitsym = 0 + +-- Fill nested symbol table with per-trace exit stub addresses. +local function fillsymtab_tr(tr, nexit) + local t = {} + symtabmt.__index = t + if jit.arch == "mips" or jit.arch == "mipsel" then + t[traceexitstub(tr, 0)] = "exit" + return + end + for i=0,nexit-1 do + local addr = traceexitstub(tr, i) + t[addr] = tostring(i) + end + local addr = traceexitstub(tr, nexit) + if addr then t[addr] = "stack_check" end +end + +-- Fill symbol table with trace exit stub addresses. +local function fillsymtab(tr, nexit) + local t = symtab + if nexitsym == 0 then + local ircall = vmdef.ircall + for i=0,#ircall do + local addr = ircalladdr(i) + if addr ~= 0 then t[addr] = ircall[i] end + end + end + if nexitsym == 1000000 then -- Per-trace exit stubs. + fillsymtab_tr(tr, nexit) + elseif nexit > nexitsym then -- Shared exit stubs. + for i=nexitsym,nexit-1 do + local addr = traceexitstub(i) + if addr == nil then -- Fall back to per-trace exit stubs. + fillsymtab_tr(tr, nexit) + setmetatable(symtab, symtabmt) + nexit = 1000000 + break + end + t[addr] = tostring(i) + end + nexitsym = nexit + end + return t +end + +local function dumpwrite(s) + out:write(s) +end + +-- Disassemble machine code. +local function dump_mcode(tr) + local info = traceinfo(tr) + if not info then return end + local mcode, addr, loop = tracemc(tr) + if not mcode then return end + if not disass then disass = require("jit.dis_"..jit.arch) end + out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") + local ctx = disass.create(mcode, addr, dumpwrite) + ctx.hexdump = 0 + ctx.symtab = fillsymtab(tr, info.nexit) + if loop ~= 0 then + symtab[addr+loop] = "LOOP" + ctx:disass(0, loop) + out:write("->LOOP:\n") + ctx:disass(loop, #mcode-loop) + symtab[addr+loop] = nil + else + ctx:disass(0, #mcode) + end +end + +------------------------------------------------------------------------------ + +local irtype_text = { + [0] = "nil", + "fal", + "tru", + "lud", + "str", + "p32", + "thr", + "pro", + "fun", + "p64", + "cdt", + "tab", + "udt", + "flt", + "num", + "i8 ", + "u8 ", + "i16", + "u16", + "int", + "u32", + "i64", + "u64", + "sfp", +} + +local colortype_ansi = { + [0] = "%s", + "%s", + "%s", + "\027[36m%s\027[m", + "\027[32m%s\027[m", + "%s", + "\027[1m%s\027[m", + "%s", + "\027[1m%s\027[m", + "%s", + "\027[33m%s\027[m", + "\027[31m%s\027[m", + "\027[36m%s\027[m", + "\027[34m%s\027[m", + "\027[34m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", +} + +local function colorize_text(s, t) + return s +end + +local function colorize_ansi(s, t) + return format(colortype_ansi[t], s) +end + +local irtype_ansi = setmetatable({}, + { __index = function(tab, t) + local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end }) + +local html_escape = { ["<"] = "<", [">"] = ">", ["&"] = "&", } + +local function colorize_html(s, t) + s = gsub(s, "[<>&]", html_escape) + return format('%s', irtype_text[t], s) +end + +local irtype_html = setmetatable({}, + { __index = function(tab, t) + local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end }) + +local header_html = [[ + +]] + +local colorize, irtype + +-- Lookup tables to convert some literals into names. +local litname = { + ["SLOAD "] = setmetatable({}, { __index = function(t, mode) + local s = "" + if band(mode, 1) ~= 0 then s = s.."P" end + if band(mode, 2) ~= 0 then s = s.."F" end + if band(mode, 4) ~= 0 then s = s.."T" end + if band(mode, 8) ~= 0 then s = s.."C" end + if band(mode, 16) ~= 0 then s = s.."R" end + if band(mode, 32) ~= 0 then s = s.."I" end + t[mode] = s + return s + end}), + ["XLOAD "] = { [0] = "", "R", "V", "RV", "U", "RU", "VU", "RVU", }, + ["CONV "] = setmetatable({}, { __index = function(t, mode) + local s = irtype[band(mode, 31)] + s = irtype[band(shr(mode, 5), 31)].."."..s + if band(mode, 0x400) ~= 0 then s = s.." trunc" + elseif band(mode, 0x800) ~= 0 then s = s.." sext" end + local c = shr(mode, 14) + if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end + t[mode] = s + return s + end}), + ["FLOAD "] = vmdef.irfield, + ["FREF "] = vmdef.irfield, + ["FPMATH"] = vmdef.irfpm, +} + +local function ctlsub(c) + if c == "\n" then return "\\n" + elseif c == "\r" then return "\\r" + elseif c == "\t" then return "\\t" + else return format("\\%03d", byte(c)) + end +end + +local function fmtfunc(func, pc) + local fi = funcinfo(func, pc) + if fi.loc then + return fi.loc + elseif fi.ffid then + return vmdef.ffnames[fi.ffid] + elseif fi.addr then + return format("C:%x", fi.addr) + else + return "(?)" + end +end + +local function formatk(tr, idx) + local k, t, slot = tracek(tr, idx) + local tn = type(k) + local s + if tn == "number" then + if k == 2^52+2^51 then + s = "bias" + else + s = format("%+.14g", k) + end + elseif tn == "string" then + s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) + elseif tn == "function" then + s = fmtfunc(k) + elseif tn == "table" then + s = format("{%p}", k) + elseif tn == "userdata" then + if t == 12 then + s = format("userdata:%p", k) + else + s = format("[%p]", k) + if s == "[0x00000000]" then s = "NULL" end + end + elseif t == 21 then -- int64_t + s = sub(tostring(k), 1, -3) + if sub(s, 1, 1) ~= "-" then s = "+"..s end + else + s = tostring(k) -- For primitives. + end + s = colorize(format("%-4s", s), t) + if slot then + s = format("%s @%d", s, slot) + end + return s +end + +local function printsnap(tr, snap) + local n = 2 + for s=0,snap[1]-1 do + local sn = snap[n] + if shr(sn, 24) == s then + n = n + 1 + local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS + if ref < 0 then + out:write(formatk(tr, ref)) + elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM + out:write(colorize(format("%04d/%04d", ref, ref+1), 14)) + else + local m, ot, op1, op2 = traceir(tr, ref) + out:write(colorize(format("%04d", ref), band(ot, 31))) + end + out:write(band(sn, 0x10000) == 0 and " " or "|") -- SNAP_FRAME + else + out:write("---- ") + end + end + out:write("]\n") +end + +-- Dump snapshots (not interleaved with IR). +local function dump_snap(tr) + out:write("---- TRACE ", tr, " snapshots\n") + for i=0,1000000000 do + local snap = tracesnap(tr, i) + if not snap then break end + out:write(format("#%-3d %04d [ ", i, snap[0])) + printsnap(tr, snap) + end +end + +-- Return a register name or stack slot for a rid/sp location. +local function ridsp_name(ridsp, ins) + if not disass then disass = require("jit.dis_"..jit.arch) end + local rid, slot = band(ridsp, 0xff), shr(ridsp, 8) + if rid == 253 or rid == 254 then + return (slot == 0 or slot == 255) and " {sink" or format(" {%04d", ins-slot) + end + if ridsp > 255 then return format("[%x]", slot*4) end + if rid < 128 then return disass.regname(rid) end + return "" +end + +-- Dump CALL* function ref and return optional ctype. +local function dumpcallfunc(tr, ins) + local ctype + if ins > 0 then + local m, ot, op1, op2 = traceir(tr, ins) + if band(ot, 31) == 0 then -- nil type means CARG(func, ctype). + ins = op1 + ctype = formatk(tr, op2) + end + end + if ins < 0 then + out:write(format("[0x%x](", tonumber((tracek(tr, ins))))) + else + out:write(format("%04d (", ins)) + end + return ctype +end + +-- Recursively gather CALL* args and dump them. +local function dumpcallargs(tr, ins) + if ins < 0 then + out:write(formatk(tr, ins)) + else + local m, ot, op1, op2 = traceir(tr, ins) + local oidx = 6*shr(ot, 8) + local op = sub(vmdef.irnames, oidx+1, oidx+6) + if op == "CARG " then + dumpcallargs(tr, op1) + if op2 < 0 then + out:write(" ", formatk(tr, op2)) + else + out:write(" ", format("%04d", op2)) + end + else + out:write(format("%04d", ins)) + end + end +end + +-- Dump IR and interleaved snapshots. +local function dump_ir(tr, dumpsnap, dumpreg) + local info = traceinfo(tr) + if not info then return end + local nins = info.nins + out:write("---- TRACE ", tr, " IR\n") + local irnames = vmdef.irnames + local snapref = 65536 + local snap, snapno + if dumpsnap then + snap = tracesnap(tr, 0) + snapref = snap[0] + snapno = 0 + end + for ins=1,nins do + if ins >= snapref then + if dumpreg then + out:write(format(".... SNAP #%-3d [ ", snapno)) + else + out:write(format(".... SNAP #%-3d [ ", snapno)) + end + printsnap(tr, snap) + snapno = snapno + 1 + snap = tracesnap(tr, snapno) + snapref = snap and snap[0] or 65536 + end + local m, ot, op1, op2, ridsp = traceir(tr, ins) + local oidx, t = 6*shr(ot, 8), band(ot, 31) + local op = sub(irnames, oidx+1, oidx+6) + if op == "LOOP " then + if dumpreg then + out:write(format("%04d ------------ LOOP ------------\n", ins)) + else + out:write(format("%04d ------ LOOP ------------\n", ins)) + end + elseif op ~= "NOP " and op ~= "CARG " and + (dumpreg or op ~= "RENAME") then + local rid = band(ridsp, 255) + if dumpreg then + out:write(format("%04d %-6s", ins, ridsp_name(ridsp, ins))) + else + out:write(format("%04d ", ins)) + end + out:write(format("%s%s %s %s ", + (rid == 254 or rid == 253) and "}" or + (band(ot, 128) == 0 and " " or ">"), + band(ot, 64) == 0 and " " or "+", + irtype[t], op)) + local m1, m2 = band(m, 3), band(m, 3*4) + if sub(op, 1, 4) == "CALL" then + local ctype + if m2 == 1*4 then -- op2 == IRMlit + out:write(format("%-10s (", vmdef.ircall[op2])) + else + ctype = dumpcallfunc(tr, op2) + end + if op1 ~= -1 then dumpcallargs(tr, op1) end + out:write(")") + if ctype then out:write(" ctype ", ctype) end + elseif op == "CNEW " and op2 == -1 then + out:write(formatk(tr, op1)) + elseif m1 ~= 3 then -- op1 != IRMnone + if op1 < 0 then + out:write(formatk(tr, op1)) + else + out:write(format(m1 == 0 and "%04d" or "#%-3d", op1)) + end + if m2 ~= 3*4 then -- op2 != IRMnone + if m2 == 1*4 then -- op2 == IRMlit + local litn = litname[op] + if litn and litn[op2] then + out:write(" ", litn[op2]) + elseif op == "UREFO " or op == "UREFC " then + out:write(format(" #%-3d", shr(op2, 8))) + else + out:write(format(" #%-3d", op2)) + end + elseif op2 < 0 then + out:write(" ", formatk(tr, op2)) + else + out:write(format(" %04d", op2)) + end + end + end + out:write("\n") + end + end + if snap then + if dumpreg then + out:write(format(".... SNAP #%-3d [ ", snapno)) + else + out:write(format(".... SNAP #%-3d [ ", snapno)) + end + printsnap(tr, snap) + end +end + +------------------------------------------------------------------------------ + +local recprefix = "" +local recdepth = 0 + +-- Format trace error message. +local function fmterr(err, info) + if type(err) == "number" then + if type(info) == "function" then info = fmtfunc(info) end + err = format(vmdef.traceerr[err], info) + end + return err +end + +-- Dump trace states. +local function dump_trace(what, tr, func, pc, otr, oex) + if what == "stop" or (what == "abort" and dumpmode.a) then + if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == "stop") + elseif dumpmode.s then dump_snap(tr) end + if dumpmode.m then dump_mcode(tr) end + end + if what == "start" then + if dumpmode.H then out:write('
\n') end
+    out:write("---- TRACE ", tr, " ", what)
+    if otr then out:write(" ", otr, "/", oex) end
+    out:write(" ", fmtfunc(func, pc), "\n")
+  elseif what == "stop" or what == "abort" then
+    out:write("---- TRACE ", tr, " ", what)
+    if what == "abort" then
+      out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
+    else
+      local info = traceinfo(tr)
+      local link, ltype = info.link, info.linktype
+      if link == tr or link == 0 then
+	out:write(" -> ", ltype, "\n")
+      elseif ltype == "root" then
+	out:write(" -> ", link, "\n")
+      else
+	out:write(" -> ", link, " ", ltype, "\n")
+      end
+    end
+    if dumpmode.H then out:write("
\n\n") else out:write("\n") end + else + out:write("---- TRACE ", what, "\n\n") + end + out:flush() +end + +-- Dump recorded bytecode. +local function dump_record(tr, func, pc, depth, callee) + if depth ~= recdepth then + recdepth = depth + recprefix = rep(" .", depth) + end + local line + if pc >= 0 then + line = bcline(func, pc, recprefix) + if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end + else + line = "0000 "..recprefix.." FUNCC \n" + callee = func + end + if pc <= 0 then + out:write(sub(line, 1, -2), " ; ", fmtfunc(func), "\n") + else + out:write(line) + end + if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC + out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond. + end +end + +------------------------------------------------------------------------------ + +-- Dump taken trace exits. +local function dump_texit(tr, ex, ngpr, nfpr, ...) + out:write("---- TRACE ", tr, " exit ", ex, "\n") + if dumpmode.X then + local regs = {...} + if jit.arch == "x64" then + for i=1,ngpr do + out:write(format(" %016x", regs[i])) + if i % 4 == 0 then out:write("\n") end + end + else + for i=1,ngpr do + out:write(format(" %08x", regs[i])) + if i % 8 == 0 then out:write("\n") end + end + end + if jit.arch == "mips" or jit.arch == "mipsel" then + for i=1,nfpr,2 do + out:write(format(" %+17.14g", regs[ngpr+i])) + if i % 8 == 7 then out:write("\n") end + end + else + for i=1,nfpr do + out:write(format(" %+17.14g", regs[ngpr+i])) + if i % 4 == 0 then out:write("\n") end + end + end + end +end + +------------------------------------------------------------------------------ + +-- Detach dump handlers. +local function dumpoff() + if active then + active = false + jit.attach(dump_texit) + jit.attach(dump_record) + jit.attach(dump_trace) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach dump handlers. +local function dumpon(opt, outfile) + if active then dumpoff() end + + local colormode = os.getenv("COLORTERM") and "A" or "T" + if opt then + opt = gsub(opt, "[TAH]", function(mode) colormode = mode; return ""; end) + end + + local m = { t=true, b=true, i=true, m=true, } + if opt and opt ~= "" then + local o = sub(opt, 1, 1) + if o ~= "+" and o ~= "-" then m = {} end + for i=1,#opt do m[sub(opt, i, i)] = (o ~= "-") end + end + dumpmode = m + + if m.t or m.b or m.i or m.s or m.m then + jit.attach(dump_trace, "trace") + end + if m.b then + jit.attach(dump_record, "record") + if not bcline then bcline = require("jit.bc").line end + end + if m.x or m.X then + jit.attach(dump_texit, "texit") + end + + if not outfile then outfile = os.getenv("LUAJIT_DUMPFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stdout + end + + m[colormode] = true + if colormode == "A" then + colorize = colorize_ansi + irtype = irtype_ansi + elseif colormode == "H" then + colorize = colorize_html + irtype = irtype_html + out:write(header_html) + else + colorize = colorize_text + irtype = irtype_text + end + + active = true +end + +-- Public module functions. +module(...) + +on = dumpon +off = dumpoff +start = dumpon -- For -j command line option. + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/v.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/v.lua new file mode 100644 index 0000000..197e67c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/v.lua @@ -0,0 +1,167 @@ +---------------------------------------------------------------------------- +-- Verbose mode of the LuaJIT compiler. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module shows verbose information about the progress of the +-- JIT compiler. It prints one line for each generated trace. This module +-- is useful to see which code has been compiled or where the compiler +-- punts and falls back to the interpreter. +-- +-- Example usage: +-- +-- luajit -jv -e "for i=1,1000 do for j=1,1000 do end end" +-- luajit -jv=myapp.out myapp.lua +-- +-- Default output is to stderr. To redirect the output to a file, pass a +-- filename as an argument (use '-' for stdout) or set the environment +-- variable LUAJIT_VERBOSEFILE. The file is overwritten every time the +-- module is started. +-- +-- The output from the first example should look like this: +-- +-- [TRACE 1 (command line):1 loop] +-- [TRACE 2 (1/3) (command line):1 -> 1] +-- +-- The first number in each line is the internal trace number. Next are +-- the file name ('(command line)') and the line number (':1') where the +-- trace has started. Side traces also show the parent trace number and +-- the exit number where they are attached to in parentheses ('(1/3)'). +-- An arrow at the end shows where the trace links to ('-> 1'), unless +-- it loops to itself. +-- +-- In this case the inner loop gets hot and is traced first, generating +-- a root trace. Then the last exit from the 1st trace gets hot, too, +-- and triggers generation of the 2nd trace. The side trace follows the +-- path along the outer loop and *around* the inner loop, back to its +-- start, and then links to the 1st trace. Yes, this may seem unusual, +-- if you know how traditional compilers work. Trace compilers are full +-- of surprises like this -- have fun! :-) +-- +-- Aborted traces are shown like this: +-- +-- [TRACE --- foo.lua:44 -- leaving loop in root trace at foo:lua:50] +-- +-- Don't worry -- trace aborts are quite common, even in programs which +-- can be fully compiled. The compiler may retry several times until it +-- finds a suitable trace. +-- +-- Of course this doesn't work with features that are not-yet-implemented +-- (NYI error messages). The VM simply falls back to the interpreter. This +-- may not matter at all if the particular trace is not very high up in +-- the CPU usage profile. Oh, and the interpreter is quite fast, too. +-- +-- Also check out the -jdump module, which prints all the gory details. +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo +local type, format = type, string.format +local stdout, stderr = io.stdout, io.stderr + +-- Active flag and output file handle. +local active, out + +------------------------------------------------------------------------------ + +local startloc, startex + +local function fmtfunc(func, pc) + local fi = funcinfo(func, pc) + if fi.loc then + return fi.loc + elseif fi.ffid then + return vmdef.ffnames[fi.ffid] + elseif fi.addr then + return format("C:%x", fi.addr) + else + return "(?)" + end +end + +-- Format trace error message. +local function fmterr(err, info) + if type(err) == "number" then + if type(info) == "function" then info = fmtfunc(info) end + err = format(vmdef.traceerr[err], info) + end + return err +end + +-- Dump trace states. +local function dump_trace(what, tr, func, pc, otr, oex) + if what == "start" then + startloc = fmtfunc(func, pc) + startex = otr and "("..otr.."/"..oex..") " or "" + else + if what == "abort" then + local loc = fmtfunc(func, pc) + if loc ~= startloc then + out:write(format("[TRACE --- %s%s -- %s at %s]\n", + startex, startloc, fmterr(otr, oex), loc)) + else + out:write(format("[TRACE --- %s%s -- %s]\n", + startex, startloc, fmterr(otr, oex))) + end + elseif what == "stop" then + local info = traceinfo(tr) + local link, ltype = info.link, info.linktype + if ltype == "interpreter" then + out:write(format("[TRACE %3s %s%s -- fallback to interpreter]\n", + tr, startex, startloc)) + elseif link == tr or link == 0 then + out:write(format("[TRACE %3s %s%s %s]\n", + tr, startex, startloc, ltype)) + elseif ltype == "root" then + out:write(format("[TRACE %3s %s%s -> %d]\n", + tr, startex, startloc, link)) + else + out:write(format("[TRACE %3s %s%s -> %d %s]\n", + tr, startex, startloc, link, ltype)) + end + else + out:write(format("[TRACE %s]\n", what)) + end + out:flush() + end +end + +------------------------------------------------------------------------------ + +-- Detach dump handlers. +local function dumpoff() + if active then + active = false + jit.attach(dump_trace) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach dump handlers. +local function dumpon(outfile) + if active then dumpoff() end + if not outfile then outfile = os.getenv("LUAJIT_VERBOSEFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stderr + end + jit.attach(dump_trace, "trace") + active = true +end + +-- Public module functions. +module(...) + +on = dumpon +off = dumpoff +start = dumpon -- For -j command line option. + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/vmdef.lua b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/vmdef.lua new file mode 100644 index 0000000..3c94ee7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/jit/vmdef.lua @@ -0,0 +1,331 @@ +-- This is a generated file. DO NOT EDIT! + +module(...) + +bcnames = "ISLT ISGE ISLE ISGT ISEQV ISNEV ISEQS ISNES ISEQN ISNEN ISEQP ISNEP ISTC ISFC IST ISF MOV NOT UNM LEN ADDVN SUBVN MULVN DIVVN MODVN ADDNV SUBNV MULNV DIVNV MODNV ADDVV SUBVV MULVV DIVVV MODVV POW CAT KSTR KCDATAKSHORTKNUM KPRI KNIL UGET USETV USETS USETN USETP UCLO FNEW TNEW TDUP GGET GSET TGETV TGETS TGETB TSETV TSETS TSETB TSETM CALLM CALL CALLMTCALLT ITERC ITERN VARG ISNEXTRETM RET RET0 RET1 FORI JFORI FORL IFORL JFORL ITERL IITERLJITERLLOOP ILOOP JLOOP JMP FUNCF IFUNCFJFUNCFFUNCV IFUNCVJFUNCVFUNCC FUNCCW" + +irnames = "LT GE LE GT ULT UGE ULE UGT EQ NE ABC RETF NOP BASE PVAL GCSTEPHIOP LOOP USE PHI RENAMEKPRI KINT KGC KPTR KKPTR KNULL KNUM KINT64KSLOT BNOT BSWAP BAND BOR BXOR BSHL BSHR BSAR BROL BROR ADD SUB MUL DIV MOD POW NEG ABS ATAN2 LDEXP MIN MAX FPMATHADDOV SUBOV MULOV AREF HREFK HREF NEWREFUREFO UREFC FREF STRREFALOAD HLOAD ULOAD FLOAD XLOAD SLOAD VLOAD ASTOREHSTOREUSTOREFSTOREXSTORESNEW XSNEW TNEW TDUP CNEW CNEWI TBAR OBAR XBAR CONV TOBIT TOSTR STRTO CALLN CALLL CALLS CALLXSCARG " + +irfpm = { [0]="floor", "ceil", "trunc", "sqrt", "exp", "exp2", "log", "log2", "log10", "sin", "cos", "tan", "other", } + +irfield = { [0]="str.len", "func.env", "func.pc", "tab.meta", "tab.array", "tab.node", "tab.asize", "tab.hmask", "tab.nomm", "udata.meta", "udata.udtype", "udata.file", "cdata.ctypeid", "cdata.ptr", "cdata.int", "cdata.int64", "cdata.int64_4", } + +ircall = { +[0]="lj_str_cmp", +"lj_str_new", +"lj_strscan_num", +"lj_str_fromint", +"lj_str_fromnum", +"lj_tab_new1", +"lj_tab_dup", +"lj_tab_newkey", +"lj_tab_len", +"lj_gc_step_jit", +"lj_gc_barrieruv", +"lj_mem_newgco", +"lj_math_random_step", +"lj_vm_modi", +"sinh", +"cosh", +"tanh", +"fputc", +"fwrite", +"fflush", +"lj_vm_floor", +"lj_vm_ceil", +"lj_vm_trunc", +"sqrt", +"exp", +"lj_vm_exp2", +"log", +"lj_vm_log2", +"log10", +"sin", +"cos", +"tan", +"lj_vm_powi", +"pow", +"atan2", +"ldexp", +"lj_vm_tobit", +"softfp_add", +"softfp_sub", +"softfp_mul", +"softfp_div", +"softfp_cmp", +"softfp_i2d", +"softfp_d2i", +"softfp_ui2d", +"softfp_f2d", +"softfp_d2ui", +"softfp_d2f", +"softfp_i2f", +"softfp_ui2f", +"softfp_f2i", +"softfp_f2ui", +"fp64_l2d", +"fp64_ul2d", +"fp64_l2f", +"fp64_ul2f", +"fp64_d2l", +"fp64_d2ul", +"fp64_f2l", +"fp64_f2ul", +"lj_carith_divi64", +"lj_carith_divu64", +"lj_carith_modi64", +"lj_carith_modu64", +"lj_carith_powi64", +"lj_carith_powu64", +"lj_cdata_setfin", +"strlen", +"memcpy", +"memset", +"lj_vm_errno", +"lj_carith_mul64", +} + +traceerr = { +[0]="error thrown or hook called during recording", +"trace too long", +"trace too deep", +"too many snapshots", +"blacklisted", +"NYI: bytecode %d", +"leaving loop in root trace", +"inner loop in root trace", +"loop unroll limit reached", +"bad argument type", +"JIT compilation disabled for function", +"call unroll limit reached", +"down-recursion, restarting", +"NYI: C function %p", +"NYI: FastFunc %s", +"NYI: unsupported variant of FastFunc %s", +"NYI: return to lower frame", +"store with nil or NaN key", +"missing metamethod", +"looping index lookup", +"NYI: mixed sparse/dense table", +"symbol not in cache", +"NYI: unsupported C type conversion", +"NYI: unsupported C function type", +"guard would always fail", +"too many PHIs", +"persistent type instability", +"failed to allocate mcode memory", +"machine code too long", +"hit mcode limit (retrying)", +"too many spill slots", +"inconsistent register allocation", +"NYI: cannot assemble IR instruction %d", +"NYI: PHI shuffling too complex", +"NYI: register coalescing too complex", +} + +ffnames = { +[0]="Lua", +"C", +"assert", +"type", +"next", +"pairs", +"ipairs_aux", +"ipairs", +"getmetatable", +"setmetatable", +"getfenv", +"setfenv", +"rawget", +"rawset", +"rawequal", +"unpack", +"select", +"tonumber", +"tostring", +"error", +"pcall", +"xpcall", +"loadfile", +"load", +"loadstring", +"dofile", +"gcinfo", +"collectgarbage", +"newproxy", +"print", +"coroutine.status", +"coroutine.running", +"coroutine.create", +"coroutine.yield", +"coroutine.resume", +"coroutine.wrap_aux", +"coroutine.wrap", +"math.abs", +"math.floor", +"math.ceil", +"math.sqrt", +"math.log10", +"math.exp", +"math.sin", +"math.cos", +"math.tan", +"math.asin", +"math.acos", +"math.atan", +"math.sinh", +"math.cosh", +"math.tanh", +"math.frexp", +"math.modf", +"math.deg", +"math.rad", +"math.log", +"math.atan2", +"math.pow", +"math.fmod", +"math.ldexp", +"math.min", +"math.max", +"math.random", +"math.randomseed", +"bit.tobit", +"bit.bnot", +"bit.bswap", +"bit.lshift", +"bit.rshift", +"bit.arshift", +"bit.rol", +"bit.ror", +"bit.band", +"bit.bor", +"bit.bxor", +"bit.tohex", +"string.len", +"string.byte", +"string.char", +"string.sub", +"string.rep", +"string.reverse", +"string.lower", +"string.upper", +"string.dump", +"string.find", +"string.match", +"string.gmatch_aux", +"string.gmatch", +"string.gsub", +"string.format", +"table.foreachi", +"table.foreach", +"table.getn", +"table.maxn", +"table.insert", +"table.remove", +"table.concat", +"table.sort", +"io.method.close", +"io.method.read", +"io.method.write", +"io.method.flush", +"io.method.seek", +"io.method.setvbuf", +"io.method.lines", +"io.method.__gc", +"io.method.__tostring", +"io.open", +"io.popen", +"io.tmpfile", +"io.close", +"io.read", +"io.write", +"io.flush", +"io.input", +"io.output", +"io.lines", +"io.type", +"os.execute", +"os.remove", +"os.rename", +"os.tmpname", +"os.getenv", +"os.exit", +"os.clock", +"os.date", +"os.time", +"os.difftime", +"os.setlocale", +"debug.getregistry", +"debug.getmetatable", +"debug.setmetatable", +"debug.getfenv", +"debug.setfenv", +"debug.getinfo", +"debug.getlocal", +"debug.setlocal", +"debug.getupvalue", +"debug.setupvalue", +"debug.upvalueid", +"debug.upvaluejoin", +"debug.sethook", +"debug.gethook", +"debug.debug", +"debug.traceback", +"jit.on", +"jit.off", +"jit.flush", +"jit.status", +"jit.attach", +"jit.util.funcinfo", +"jit.util.funcbc", +"jit.util.funck", +"jit.util.funcuvname", +"jit.util.traceinfo", +"jit.util.traceir", +"jit.util.tracek", +"jit.util.tracesnap", +"jit.util.tracemc", +"jit.util.traceexitstub", +"jit.util.ircalladdr", +"jit.opt.start", +"ffi.meta.__index", +"ffi.meta.__newindex", +"ffi.meta.__eq", +"ffi.meta.__len", +"ffi.meta.__lt", +"ffi.meta.__le", +"ffi.meta.__concat", +"ffi.meta.__call", +"ffi.meta.__add", +"ffi.meta.__sub", +"ffi.meta.__mul", +"ffi.meta.__div", +"ffi.meta.__mod", +"ffi.meta.__pow", +"ffi.meta.__unm", +"ffi.meta.__tostring", +"ffi.meta.__pairs", +"ffi.meta.__ipairs", +"ffi.clib.__index", +"ffi.clib.__newindex", +"ffi.clib.__gc", +"ffi.callback.free", +"ffi.callback.set", +"ffi.cdef", +"ffi.new", +"ffi.cast", +"ffi.typeof", +"ffi.istype", +"ffi.sizeof", +"ffi.alignof", +"ffi.offsetof", +"ffi.errno", +"ffi.string", +"ffi.copy", +"ffi.fill", +"ffi.abi", +"ffi.metatype", +"ffi.gc", +"ffi.load", +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.c new file mode 100644 index 0000000..ce7bcf6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.c @@ -0,0 +1,1077 @@ +/* +** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res; + lua_lock(L); + if ((L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); + else + status = 1; + lua_unlock(L); + return status; +} + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) + luaC_step(L); + if (g->gcstate == GCSpause) /* end of cycle? */ + res = 1; /* signal it */ + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.h new file mode 100644 index 0000000..9d1d435 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lapi.h @@ -0,0 +1,16 @@ +/* +** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ +** Auxiliary functions from Lua API +** See Copyright Notice in lua.h +*/ + +#ifndef lapi_h +#define lapi_h + + +#include "lobject.h" + + +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.c new file mode 100644 index 0000000..317a48d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.c @@ -0,0 +1,647 @@ +/* +** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) + luaL_typerror(L, ud, tname); + lua_pop(L, 2); /* remove both metatables */ + return p; +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ + fclose(lf.f); + lf.f = fopen(filename, "rb"); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + lf.extraline = 0; + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.h new file mode 100644 index 0000000..fed1491 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lauxlib.h @@ -0,0 +1,167 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + +LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + +/* From Lua 5.2. */ +LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname); +LUALIB_API int luaL_execresult(lua_State *L, int stat); +LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, + const char *mode); +LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, + const char *name, const char *mode); +LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, + int level); + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lbaselib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lbaselib.c new file mode 100644 index 0000000..1d922a8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lbaselib.c @@ -0,0 +1,643 @@ +/* +** $Id: lbaselib.c,v 1.189 2006/01/18 11:49:12 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = luaL_optint(L, 1, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int load_aux (lua_State *L, int status) { + if (status == 0) /* OK? */ + return 1; + else { + lua_pushnil(L); + lua_insert(L, -2); /* put before error message */ + return 2; /* return nil plus error message */ + } +} + + +static int luaB_loadstring (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + const char *chunkname = luaL_optstring(L, 2, s); + return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); +} + + +static int luaB_loadfile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + return load_aux(L, luaL_loadfile(L, fname)); +} + + +/* +** Reader for generic `load' function: `lua_load' uses the +** stack for internal stuff, so the reader cannot change the +** stack top. Instead, it keeps its resulting string in a +** reserved slot inside the stack. +*/ +static const char *generic_reader (lua_State *L, void *ud, size_t *size) { + (void)ud; /* to avoid warnings */ + luaL_checkstack(L, 2, "too many nested functions"); + lua_pushvalue(L, 1); /* get function */ + lua_call(L, 0, 1); /* call it */ + if (lua_isnil(L, -1)) { + *size = 0; + return NULL; + } + else if (lua_isstring(L, -1)) { + lua_replace(L, 3); /* save string in a reserved stack slot */ + return lua_tolstring(L, 3, size); + } + else luaL_error(L, "reader function must return a string"); + return NULL; /* to avoid warnings */ +} + + +static int luaB_load (lua_State *L) { + int status; + const char *cname = luaL_optstring(L, 2, "=(load)"); + luaL_checktype(L, 1, LUA_TFUNCTION); + lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ + status = lua_load(L, generic_reader, NULL, cname); + return load_aux(L, status); +} + + +static int luaB_dofile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); + if (luaL_loadfile(L, fname) != 0) lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + n = e - i + 1; /* number of elements */ + if (n <= 0) return 0; /* empty range */ + luaL_checkstack(L, n, "table too big to unpack"); + for (; i<=e; i++) /* push arg[i...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"dofile", luaB_dofile}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"loadfile", luaB_loadfile}, + {"load", luaB_load}, + {"loadstring", luaB_loadstring}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status; + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (lua_status(co) == 0 && lua_gettop(co) == 0) { + lua_pushliteral(L, "cannot resume dead coroutine"); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + if (L == co) lua_pushliteral(L, "running"); + else { + switch (lua_status(co)) { + case LUA_YIELD: + lua_pushliteral(L, "suspended"); + break; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + lua_pushliteral(L, "normal"); /* it is running */ + else if (lua_gettop(co) == 0) + lua_pushliteral(L, "dead"); + else + lua_pushliteral(L, "suspended"); /* initial state */ + break; + } + default: /* some error occured */ + lua_pushliteral(L, "dead"); + break; + } + } + return 1; +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + return 0; /* main thread is not a coroutine */ + else + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.c new file mode 100644 index 0000000..dd3e37e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.c @@ -0,0 +1,825 @@ +/* +** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) /* function start? */ + return; /* positions are already clean */ + if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: r = luai_numpow(v1, v2); break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o1 = luaK_exp2RK(fs, e1); + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + freeexp(fs, e2); + freeexp(fs, e1); + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (e->k == VK) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + default: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e1->f, e2->f); + e1->k = e2->k; e1->u.s.info = e2->u.s.info; + e1->u.s.aux = e2->u.s.aux; e1->t = e2->t; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e1->t, e2->t); + e1->k = e2->k; e1->u.s.info = e2->u.s.info; + e1->u.s.aux = e2->u.s.aux; e1->f = e2->f; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = e2->k; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.h new file mode 100644 index 0000000..b5668f2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lcode.h @@ -0,0 +1,77 @@ +/* +** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + +#define binopistest(op) ((op) >= OPR_NE) + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldblib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldblib.c new file mode 100644 index 0000000..26a19b6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldblib.c @@ -0,0 +1,397 @@ +/* +** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static int db_getregistry (lua_State *L) { + lua_pushvalue(L, LUA_REGISTRYINDEX); + return 1; +} + + +static int db_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); /* no metatable */ + } + return 1; +} + + +static int db_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + lua_settop(L, 2); + lua_pushboolean(L, lua_setmetatable(L, 1)); + return 1; +} + + +static int db_getfenv (lua_State *L) { + lua_getfenv(L, 1); + return 1; +} + + +static int db_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + if (lua_setfenv(L, 1) == 0) + luaL_error(L, LUA_QL("setfenv") + " cannot change environment of given object"); + return 1; +} + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int db_setlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + luaL_checkany(L, arg+3); + lua_settop(L, arg+3); + lua_xmove(L, L1, 1); + lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); + return 1; +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + +static int db_setupvalue (lua_State *L) { + luaL_checkany(L, 3); + return auxupvalue(L, 0); +} + + + +static const char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + lua_sethook(L1, NULL, 0, 0); /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + int count = luaL_optint(L, arg+3, 0); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + lua_sethook(L1, hookf, makemask(smask, count), count); + } + gethooktable(L1); + lua_pushlightuserdata(L1, L1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + lua_rawset(L1, -3); /* set new hook */ + lua_pop(L1, 1); /* remove hook table */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L1); + lua_pushlightuserdata(L1, L1); + lua_rawget(L1, -2); /* get hook */ + lua_remove(L1, -2); /* remove hook table */ + lua_xmove(L1, L, 1); + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +static int db_debug (lua_State *L) { + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"debug", db_debug}, + {"getfenv", db_getfenv}, + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getregistry", db_getregistry}, + {"getmetatable", db_getmetatable}, + {"getupvalue", db_getupvalue}, + {"setfenv", db_setfenv}, + {"sethook", db_sethook}, + {"setlocal", db_setlocal}, + {"setmetatable", db_setmetatable}, + {"setupvalue", db_setupvalue}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.c new file mode 100644 index 0000000..8919a01 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.c @@ -0,0 +1,620 @@ +/* +** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + lua_assert(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + lua_assert(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + /* cannot jump to a setlist count */ + Instruction d = pt->code[dest-1]; + check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + check(c == 0 || pc+2 < pt->sizecode); /* check its jump */ + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) pc++; + break; + } + case OP_CLOSURE: { + int nup; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (; nup>0; nup--) { + OpCode op1 = GET_OPCODE(pt->code[pc+nup]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1)) p1 = p2; + lua_assert(!ttisstring(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.h new file mode 100644 index 0000000..9c76aa1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.c new file mode 100644 index 0000000..b8eb1a8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.c @@ -0,0 +1,515 @@ +/* +** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + + + + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + + +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { + switch (errcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = 0; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +void luaD_throw (lua_State *L, int errcode) { + if (L->errorJmp) { + L->errorJmp->status = errcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(errcode); + if (G(L)->panic) { + resetstack(L, errcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while (L->ci->tailcalls--) /* call hook for eventual tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status != LUA_YIELD) { /* start coroutine */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + L->status = 0; + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD) { + if (L->status != 0) + return resume_error(L, "cannot resume dead coroutine"); + else if (L->ci != L->base_ci) + return resume_error(L, "cannot resume non-suspended coroutine"); + } + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0 && L->nCcalls == 0); + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else + status = L->status; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > 0) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.h new file mode 100644 index 0000000..b2de92b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldo.h @@ -0,0 +1,57 @@ +/* +** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldump.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldump.c new file mode 100644 index 0000000..f08277d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.c new file mode 100644 index 0000000..b8cd67b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.c @@ -0,0 +1,174 @@ +/* +** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.h new file mode 100644 index 0000000..2e02419 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.c new file mode 100644 index 0000000..691565d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.c @@ -0,0 +1,707 @@ +/* +** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static void propagateall (global_State *g) { + while (g->gray) propagatemark(g); +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.h new file mode 100644 index 0000000..5f69acb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_aux.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_aux.c new file mode 100644 index 0000000..1b01fe0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_aux.c @@ -0,0 +1,356 @@ +/* +** Auxiliary library for the Lua/C API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major parts taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define lib_aux_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_state.h" +#include "lj_trace.h" +#include "lj_lib.h" + +#if LJ_TARGET_POSIX +#include +#endif + +/* -- I/O error handling -------------------------------------------------- */ + +LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname) +{ + if (stat) { + setboolV(L->top++, 1); + return 1; + } else { + int en = errno; /* Lua API calls may change this value. */ + setnilV(L->top++); + if (fname) + lua_pushfstring(L, "%s: %s", fname, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + setintV(L->top++, en); + lj_trace_abort(G(L)); + return 3; + } +} + +LUALIB_API int luaL_execresult(lua_State *L, int stat) +{ + if (stat != -1) { +#if LJ_TARGET_POSIX + if (WIFSIGNALED(stat)) { + stat = WTERMSIG(stat); + setnilV(L->top++); + lua_pushliteral(L, "signal"); + } else { + if (WIFEXITED(stat)) + stat = WEXITSTATUS(stat); + if (stat == 0) + setboolV(L->top++, 1); + else + setnilV(L->top++); + lua_pushliteral(L, "exit"); + } +#else + if (stat == 0) + setboolV(L->top++, 1); + else + setnilV(L->top++); + lua_pushliteral(L, "exit"); +#endif + setintV(L->top++, stat); + return 3; + } + return luaL_fileresult(L, 0, NULL); +} + +/* -- Module registration ------------------------------------------------- */ + +LUALIB_API const char *luaL_findtable(lua_State *L, int idx, + const char *fname, int szhint) +{ + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, (size_t)(e - fname)); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, (size_t)(e - fname)); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + +static int libsize(const luaL_Reg *l) +{ + int size = 0; + for (; l->name; l++) size++; + return size; +} + +LUALIB_API void luaL_openlib(lua_State *L, const char *libname, + const luaL_Reg *l, int nup) +{ + lj_lib_checkfpu(L); + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + +LUALIB_API void luaL_register(lua_State *L, const char *libname, + const luaL_Reg *l) +{ + luaL_openlib(L, libname, l, 0); +} + +LUALIB_API const char *luaL_gsub(lua_State *L, const char *s, + const char *p, const char *r) +{ + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, (size_t)(wild - s)); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + +/* -- Buffer handling ----------------------------------------------------- */ + +#define bufflen(B) ((size_t)((B)->p - (B)->buffer)) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +static int emptybuffer(luaL_Buffer *B) +{ + size_t l = bufflen(B); + if (l == 0) + return 0; /* put nothing on stack */ + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; +} + +static void adjuststack(luaL_Buffer *B) +{ + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l)) + break; + toplen += l; + toget++; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + +LUALIB_API char *luaL_prepbuffer(luaL_Buffer *B) +{ + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + +LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l) +{ + while (l--) + luaL_addchar(B, *s++); +} + +LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s) +{ + luaL_addlstring(B, s, strlen(s)); +} + +LUALIB_API void luaL_pushresult(luaL_Buffer *B) +{ + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + +LUALIB_API void luaL_addvalue(luaL_Buffer *B) +{ + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + +LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B) +{ + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* -- Reference management ------------------------------------------------ */ + +#define FREELIST_REF 0 + +/* Convert a stack index to an absolute index. */ +#define abs_index(L, i) \ + ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) + +LUALIB_API int luaL_ref(lua_State *L, int t) +{ + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + +LUALIB_API void luaL_unref(lua_State *L, int t, int ref) +{ + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + +/* -- Default allocator and panic function -------------------------------- */ + +static int panic(lua_State *L) +{ + const char *s = lua_tostring(L, -1); + fputs("PANIC: unprotected error in call to Lua API (", stderr); + fputs(s ? s : "?", stderr); + fputc(')', stderr); fputc('\n', stderr); + fflush(stderr); + return 0; +} + +#ifdef LUAJIT_USE_SYSMALLOC + +#if LJ_64 +#error "Must use builtin allocator for 64 bit target" +#endif + +static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +{ + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, nsize); + } +} + +LUALIB_API lua_State *luaL_newstate(void) +{ + lua_State *L = lua_newstate(mem_alloc, NULL); + if (L) G(L)->panic = panic; + return L; +} + +#else + +#include "lj_alloc.h" + +LUALIB_API lua_State *luaL_newstate(void) +{ + lua_State *L; + void *ud = lj_alloc_create(); + if (ud == NULL) return NULL; +#if LJ_64 + L = lj_state_newstate(lj_alloc_f, ud); +#else + L = lua_newstate(lj_alloc_f, ud); +#endif + if (L) G(L)->panic = panic; + return L; +} + +#if LJ_64 +LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) +{ + UNUSED(f); UNUSED(ud); + fputs("Must use luaL_newstate() for 64 bit target\n", stderr); + return NULL; +} +#endif + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_base.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_base.c new file mode 100644 index 0000000..30e88f1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_base.c @@ -0,0 +1,683 @@ +/* +** Base and coroutine library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lib_base_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_state.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cconv.h" +#endif +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_dispatch.h" +#include "lj_char.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* -- Base library: checks ------------------------------------------------ */ + +#define LJLIB_MODULE_base + +LJLIB_ASM(assert) LJLIB_REC(.) +{ + GCstr *s; + lj_lib_checkany(L, 1); + s = lj_lib_optstr(L, 2); + if (s) + lj_err_callermsg(L, strdata(s)); + else + lj_err_caller(L, LJ_ERR_ASSERT); + return FFH_UNREACHABLE; +} + +/* ORDER LJ_T */ +LJLIB_PUSH("nil") +LJLIB_PUSH("boolean") +LJLIB_PUSH(top-1) /* boolean */ +LJLIB_PUSH("userdata") +LJLIB_PUSH("string") +LJLIB_PUSH("upval") +LJLIB_PUSH("thread") +LJLIB_PUSH("proto") +LJLIB_PUSH("function") +LJLIB_PUSH("trace") +LJLIB_PUSH("cdata") +LJLIB_PUSH("table") +LJLIB_PUSH(top-9) /* userdata */ +LJLIB_PUSH("number") +LJLIB_ASM_(type) LJLIB_REC(.) +/* Recycle the lj_lib_checkany(L, 1) from assert. */ + +/* -- Base library: iterators --------------------------------------------- */ + +/* This solves a circular dependency problem -- change FF_next_N as needed. */ +LJ_STATIC_ASSERT((int)FF_next == FF_next_N); + +LJLIB_ASM(next) +{ + lj_lib_checktab(L, 1); + return FFH_UNREACHABLE; +} + +#if LJ_52 || LJ_HASFFI +static int ffh_pairs(lua_State *L, MMS mm) +{ + TValue *o = lj_lib_checkany(L, 1); + cTValue *mo = lj_meta_lookup(L, o, mm); + if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) { + L->top = o+1; /* Only keep one argument. */ + copyTV(L, L->base-1, mo); /* Replace callable. */ + return FFH_TAILCALL; + } else { + if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE); + setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1))); + if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0); + return FFH_RES(3); + } +} +#else +#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE) +#endif + +LJLIB_PUSH(lastcl) +LJLIB_ASM(pairs) +{ + return ffh_pairs(L, MM_pairs); +} + +LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkint(L, 2); + return FFH_UNREACHABLE; +} + +LJLIB_PUSH(lastcl) +LJLIB_ASM(ipairs) LJLIB_REC(.) +{ + return ffh_pairs(L, MM_ipairs); +} + +/* -- Base library: getters and setters ----------------------------------- */ + +LJLIB_ASM_(getmetatable) LJLIB_REC(.) +/* Recycle the lj_lib_checkany(L, 1) from assert. */ + +LJLIB_ASM(setmetatable) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + GCtab *mt = lj_lib_checktabornil(L, 2); + if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable))) + lj_err_caller(L, LJ_ERR_PROTMT); + setgcref(t->metatable, obj2gco(mt)); + if (mt) { lj_gc_objbarriert(L, t, mt); } + settabV(L, L->base-1, t); + return FFH_RES(1); +} + +LJLIB_CF(getfenv) +{ + GCfunc *fn; + cTValue *o = L->base; + if (!(o < L->top && tvisfunc(o))) { + int level = lj_lib_optint(L, 1, 1); + o = lj_debug_frame(L, level, &level); + if (o == NULL) + lj_err_arg(L, 1, LJ_ERR_INVLVL); + } + fn = &gcval(o)->fn; + settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env)); + return 1; +} + +LJLIB_CF(setfenv) +{ + GCfunc *fn; + GCtab *t = lj_lib_checktab(L, 2); + cTValue *o = L->base; + if (!(o < L->top && tvisfunc(o))) { + int level = lj_lib_checkint(L, 1); + if (level == 0) { + /* NOBARRIER: A thread (i.e. L) is never black. */ + setgcref(L->env, obj2gco(t)); + return 0; + } + o = lj_debug_frame(L, level, &level); + if (o == NULL) + lj_err_arg(L, 1, LJ_ERR_INVLVL); + } + fn = &gcval(o)->fn; + if (!isluafunc(fn)) + lj_err_caller(L, LJ_ERR_SETFENV); + setgcref(fn->l.env, obj2gco(t)); + lj_gc_objbarrier(L, obj2gco(fn), t); + setfuncV(L, L->top++, fn); + return 1; +} + +LJLIB_ASM(rawget) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkany(L, 2); + return FFH_UNREACHABLE; +} + +LJLIB_CF(rawset) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkany(L, 2); + L->top = 1+lj_lib_checkany(L, 3); + lua_rawset(L, 1); + return 1; +} + +LJLIB_CF(rawequal) LJLIB_REC(.) +{ + cTValue *o1 = lj_lib_checkany(L, 1); + cTValue *o2 = lj_lib_checkany(L, 2); + setboolV(L->top-1, lj_obj_equal(o1, o2)); + return 1; +} + +#if LJ_52 +LJLIB_CF(rawlen) LJLIB_REC(.) +{ + cTValue *o = L->base; + int32_t len; + if (L->top > o && tvisstr(o)) + len = (int32_t)strV(o)->len; + else + len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1)); + setintV(L->top-1, len); + return 1; +} +#endif + +LJLIB_CF(unpack) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t n, i = lj_lib_optint(L, 2, 1); + int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ? + lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t); + if (i > e) return 0; + n = e - i + 1; + if (n <= 0 || !lua_checkstack(L, n)) + lj_err_caller(L, LJ_ERR_UNPACK); + do { + cTValue *tv = lj_tab_getint(t, i); + if (tv) { + copyTV(L, L->top++, tv); + } else { + setnilV(L->top++); + } + } while (i++ < e); + return n; +} + +LJLIB_CF(select) LJLIB_REC(.) +{ + int32_t n = (int32_t)(L->top - L->base); + if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') { + setintV(L->top-1, n-1); + return 1; + } else { + int32_t i = lj_lib_checkint(L, 1); + if (i < 0) i = n + i; else if (i > n) i = n; + if (i < 1) + lj_err_arg(L, 1, LJ_ERR_IDXRNG); + return n - i; + } +} + +/* -- Base library: conversions ------------------------------------------- */ + +LJLIB_ASM(tonumber) LJLIB_REC(.) +{ + int32_t base = lj_lib_optint(L, 2, 10); + if (base == 10) { + TValue *o = lj_lib_checkany(L, 1); + if (lj_strscan_numberobj(o)) { + copyTV(L, L->base-1, o); + return FFH_RES(1); + } +#if LJ_HASFFI + if (tviscdata(o)) { + CTState *cts = ctype_cts(L); + CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) { + if (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) && + ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) { + int32_t i; + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0); + setintV(L->base-1, i); + return FFH_RES(1); + } + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE), + (uint8_t *)&(L->base-1)->n, o, 0); + return FFH_RES(1); + } + } +#endif + } else { + const char *p = strdata(lj_lib_checkstr(L, 1)); + char *ep; + unsigned long ul; + if (base < 2 || base > 36) + lj_err_arg(L, 2, LJ_ERR_BASERNG); + ul = strtoul(p, &ep, base); + if (p != ep) { + while (lj_char_isspace((unsigned char)(*ep))) ep++; + if (*ep == '\0') { + if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u)) + setintV(L->base-1, (int32_t)ul); + else + setnumV(L->base-1, (lua_Number)ul); + return FFH_RES(1); + } + } + } + setnilV(L->base-1); + return FFH_RES(1); +} + +LJLIB_PUSH("nil") +LJLIB_PUSH("false") +LJLIB_PUSH("true") +LJLIB_ASM(tostring) LJLIB_REC(.) +{ + TValue *o = lj_lib_checkany(L, 1); + cTValue *mo; + L->top = o+1; /* Only keep one argument. */ + if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { + copyTV(L, L->base-1, mo); /* Replace callable. */ + return FFH_TAILCALL; + } else { + GCstr *s; + if (tvisnumber(o)) { + s = lj_str_fromnumber(L, o); + } else if (tvispri(o)) { + s = strV(lj_lib_upvalue(L, -(int32_t)itype(o))); + } else { + if (tvisfunc(o) && isffunc(funcV(o))) + lua_pushfstring(L, "function: builtin#%d", funcV(o)->c.ffid); + else + lua_pushfstring(L, "%s: %p", lj_typename(o), lua_topointer(L, 1)); + /* Note: lua_pushfstring calls the GC which may invalidate o. */ + s = strV(L->top-1); + } + setstrV(L, L->base-1, s); + return FFH_RES(1); + } +} + +/* -- Base library: throw and catch errors -------------------------------- */ + +LJLIB_CF(error) +{ + int32_t level = lj_lib_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + +LJLIB_ASM(pcall) LJLIB_REC(.) +{ + lj_lib_checkany(L, 1); + lj_lib_checkfunc(L, 2); /* For xpcall only. */ + return FFH_UNREACHABLE; +} +LJLIB_ASM_(xpcall) LJLIB_REC(.) + +/* -- Base library: load Lua code ----------------------------------------- */ + +static int load_aux(lua_State *L, int status, int envarg) +{ + if (status == 0) { + if (tvistab(L->base+envarg-1)) { + GCfunc *fn = funcV(L->top-1); + GCtab *t = tabV(L->base+envarg-1); + setgcref(fn->c.env, obj2gco(t)); + lj_gc_objbarrier(L, fn, t); + } + return 1; + } else { + setnilV(L->top-2); + return 2; + } +} + +LJLIB_CF(loadfile) +{ + GCstr *fname = lj_lib_optstr(L, 1); + GCstr *mode = lj_lib_optstr(L, 2); + int status; + lua_settop(L, 3); /* Ensure env arg exists. */ + status = luaL_loadfilex(L, fname ? strdata(fname) : NULL, + mode ? strdata(mode) : NULL); + return load_aux(L, status, 3); +} + +static const char *reader_func(lua_State *L, void *ud, size_t *size) +{ + UNUSED(ud); + luaL_checkstack(L, 2, "too many nested functions"); + copyTV(L, L->top++, L->base); + lua_call(L, 0, 1); /* Call user-supplied function. */ + L->top--; + if (tvisnil(L->top)) { + *size = 0; + return NULL; + } else if (tvisstr(L->top) || tvisnumber(L->top)) { + copyTV(L, L->base+4, L->top); /* Anchor string in reserved stack slot. */ + return lua_tolstring(L, 5, size); + } else { + lj_err_caller(L, LJ_ERR_RDRSTR); + return NULL; + } +} + +LJLIB_CF(load) +{ + GCstr *name = lj_lib_optstr(L, 2); + GCstr *mode = lj_lib_optstr(L, 3); + int status; + if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) { + GCstr *s = lj_lib_checkstr(L, 1); + lua_settop(L, 4); /* Ensure env arg exists. */ + status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s), + mode ? strdata(mode) : NULL); + } else { + lj_lib_checkfunc(L, 1); + lua_settop(L, 5); /* Reserve a slot for the string from the reader. */ + status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : "=(load)", + mode ? strdata(mode) : NULL); + } + return load_aux(L, status, 4); +} + +LJLIB_CF(loadstring) +{ + return lj_cf_load(L); +} + +LJLIB_CF(dofile) +{ + GCstr *fname = lj_lib_optstr(L, 1); + setnilV(L->top); + L->top = L->base+1; + if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0) + lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return (int)(L->top - L->base) - 1; +} + +/* -- Base library: GC control -------------------------------------------- */ + +LJLIB_CF(gcinfo) +{ + setintV(L->top++, (G(L)->gc.total >> 10)); + return 1; +} + +LJLIB_CF(collectgarbage) +{ + int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */ + "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul"); + int32_t data = lj_lib_optint(L, 2, 0); + if (opt == LUA_GCCOUNT) { + setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0); + } else { + int res = lua_gc(L, opt, data); + if (opt == LUA_GCSTEP) + setboolV(L->top, res); + else + setintV(L->top, res); + } + L->top++; + return 1; +} + +/* -- Base library: miscellaneous functions ------------------------------- */ + +LJLIB_PUSH(top-2) /* Upvalue holds weak table. */ +LJLIB_CF(newproxy) +{ + lua_settop(L, 1); + lua_newuserdata(L, 0); + if (lua_toboolean(L, 1) == 0) { /* newproxy(): without metatable. */ + return 1; + } else if (lua_isboolean(L, 1)) { /* newproxy(true): with metatable. */ + lua_newtable(L); + lua_pushvalue(L, -1); + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* Remember mt in weak table. */ + } else { /* newproxy(proxy): inherit metatable. */ + int validproxy = 0; + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); + } + if (!validproxy) + lj_err_arg(L, 1, LJ_ERR_NOPROXY); + lua_getmetatable(L, 1); + } + lua_setmetatable(L, 2); + return 1; +} + +LJLIB_PUSH("tostring") +LJLIB_CF(print) +{ + ptrdiff_t i, nargs = L->top - L->base; + cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1))); + int shortcut; + if (tv && !tvisnil(tv)) { + copyTV(L, L->top++, tv); + } else { + setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1))); + lua_gettable(L, LUA_GLOBALSINDEX); + tv = L->top-1; + } + shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring); + for (i = 0; i < nargs; i++) { + const char *str; + size_t size; + cTValue *o = &L->base[i]; + if (shortcut && tvisstr(o)) { + str = strVdata(o); + size = strV(o)->len; + } else if (shortcut && tvisint(o)) { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, intV(o)); + size = (size_t)(buf+LJ_STR_INTBUF-p); + str = p; + } else if (shortcut && tvisnum(o)) { + char buf[LJ_STR_NUMBUF]; + size = lj_str_bufnum(buf, o); + str = buf; + } else { + copyTV(L, L->top+1, o); + copyTV(L, L->top, L->top-1); + L->top += 2; + lua_call(L, 1, 1); + str = lua_tolstring(L, -1, &size); + if (!str) + lj_err_caller(L, LJ_ERR_PRTOSTR); + L->top--; + } + if (i) + putchar('\t'); + fwrite(str, 1, size, stdout); + } + putchar('\n'); + return 0; +} + +LJLIB_PUSH(top-3) +LJLIB_SET(_VERSION) + +#include "lj_libdef.h" + +/* -- Coroutine library --------------------------------------------------- */ + +#define LJLIB_MODULE_coroutine + +LJLIB_CF(coroutine_status) +{ + const char *s; + lua_State *co; + if (!(L->top > L->base && tvisthread(L->base))) + lj_err_arg(L, 1, LJ_ERR_NOCORO); + co = threadV(L->base); + if (co == L) s = "running"; + else if (co->status == LUA_YIELD) s = "suspended"; + else if (co->status != 0) s = "dead"; + else if (co->base > tvref(co->stack)+1) s = "normal"; + else if (co->top == co->base) s = "dead"; + else s = "suspended"; + lua_pushstring(L, s); + return 1; +} + +LJLIB_CF(coroutine_running) +{ +#if LJ_52 + int ismain = lua_pushthread(L); + setboolV(L->top++, ismain); + return 2; +#else + if (lua_pushthread(L)) + setnilV(L->top++); + return 1; +#endif +} + +LJLIB_CF(coroutine_create) +{ + lua_State *L1; + if (!(L->base < L->top && tvisfunc(L->base))) + lj_err_argt(L, 1, LUA_TFUNCTION); + L1 = lua_newthread(L); + setfuncV(L, L1->top++, funcV(L->base)); + return 1; +} + +LJLIB_ASM(coroutine_yield) +{ + lj_err_caller(L, LJ_ERR_CYIELD); + return FFH_UNREACHABLE; +} + +static int ffh_resume(lua_State *L, lua_State *co, int wrap) +{ + if (co->cframe != NULL || co->status > LUA_YIELD || + (co->status == 0 && co->top == co->base)) { + ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD; + if (wrap) lj_err_caller(L, em); + setboolV(L->base-1, 0); + setstrV(L, L->base, lj_err_str(L, em)); + return FFH_RES(2); + } + lj_state_growstack(co, (MSize)(L->top - L->base)); + return FFH_RETRY; +} + +LJLIB_ASM(coroutine_resume) +{ + if (!(L->top > L->base && tvisthread(L->base))) + lj_err_arg(L, 1, LJ_ERR_NOCORO); + return ffh_resume(L, threadV(L->base), 0); +} + +LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux) +{ + return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1); +} + +/* Inline declarations. */ +LJ_ASMF void lj_ff_coroutine_wrap_aux(void); +#if !(LJ_TARGET_MIPS && defined(ljamalg_c)) +LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, + lua_State *co); +#endif + +/* Error handler, called from assembler VM. */ +void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co) +{ + co->top--; copyTV(L, L->top, co->top); L->top++; + if (tvisstr(L->top-1)) + lj_err_callermsg(L, strVdata(L->top-1)); + else + lj_err_run(L); +} + +/* Forward declaration. */ +static void setpc_wrap_aux(lua_State *L, GCfunc *fn); + +LJLIB_CF(coroutine_wrap) +{ + lj_cf_coroutine_create(L); + lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1); + setpc_wrap_aux(L, funcV(L->top-1)); + return 1; +} + +#include "lj_libdef.h" + +/* Fix the PC of wrap_aux. Really ugly workaround. */ +static void setpc_wrap_aux(lua_State *L, GCfunc *fn) +{ + setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]); +} + +/* ------------------------------------------------------------------------ */ + +static void newproxy_weaktable(lua_State *L) +{ + /* NOBARRIER: The table is new (marked white). */ + GCtab *t = lj_tab_new(L, 0, 1); + settabV(L, L->top++, t); + setgcref(t->metatable, obj2gco(t)); + setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), + lj_str_newlit(L, "kv")); + t->nomm = (uint8_t)(~(1u<env); + settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, "_G")), env); + lua_pushliteral(L, LUA_VERSION); /* top-3. */ + newproxy_weaktable(L); /* top-2. */ + LJ_LIB_REG(L, "_G", base); + LJ_LIB_REG(L, LUA_COLIBNAME, coroutine); + return 2; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_bit.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_bit.c new file mode 100644 index 0000000..739924b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_bit.c @@ -0,0 +1,74 @@ +/* +** Bit manipulation library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_bit_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_bit + +LJLIB_ASM(bit_tobit) LJLIB_REC(bit_unary IR_TOBIT) +{ + lj_lib_checknumber(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(bit_bnot) LJLIB_REC(bit_unary IR_BNOT) +LJLIB_ASM_(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP) + +LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL) +{ + lj_lib_checknumber(L, 1); + lj_lib_checkbit(L, 2); + return FFH_RETRY; +} +LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR) +LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR) +LJLIB_ASM_(bit_rol) LJLIB_REC(bit_shift IR_BROL) +LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR) + +LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND) +{ + int i = 0; + do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top); + return FFH_RETRY; +} +LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR) +LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR) + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(bit_tohex) +{ + uint32_t b = (uint32_t)lj_lib_checkbit(L, 1); + int32_t i, n = L->base+1 >= L->top ? 8 : lj_lib_checkbit(L, 2); + const char *hexdigits = "0123456789abcdef"; + char buf[8]; + if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } + if (n > 8) n = 8; + for (i = n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; } + lua_pushlstring(L, buf, (size_t)n); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_bit(lua_State *L) +{ + LJ_LIB_REG(L, LUA_BITLIBNAME, bit); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_debug.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_debug.c new file mode 100644 index 0000000..97f032f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_debug.c @@ -0,0 +1,405 @@ +/* +** Debug library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_debug_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_debug + +LJLIB_CF(debug_getregistry) +{ + copyTV(L, L->top++, registry(L)); + return 1; +} + +LJLIB_CF(debug_getmetatable) +{ + lj_lib_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + setnilV(L->top-1); + } + return 1; +} + +LJLIB_CF(debug_setmetatable) +{ + lj_lib_checktabornil(L, 2); + L->top = L->base+2; + lua_setmetatable(L, 1); +#if !LJ_52 + setboolV(L->top-1, 1); +#endif + return 1; +} + +LJLIB_CF(debug_getfenv) +{ + lj_lib_checkany(L, 1); + lua_getfenv(L, 1); + return 1; +} + +LJLIB_CF(debug_setfenv) +{ + lj_lib_checktab(L, 2); + L->top = L->base+2; + if (!lua_setfenv(L, 1)) + lj_err_caller(L, LJ_ERR_SETFENV); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void settabss(lua_State *L, const char *i, const char *v) +{ + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + +static void settabsi(lua_State *L, const char *i, int v) +{ + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + +static void settabsb(lua_State *L, const char *i, int v) +{ + lua_pushboolean(L, v); + lua_setfield(L, -2, i); +} + +static lua_State *getthread(lua_State *L, int *arg) +{ + if (L->base < L->top && tvisthread(L->base)) { + *arg = 1; + return threadV(L->base); + } else { + *arg = 0; + return L; + } +} + +static void treatstackoption(lua_State *L, lua_State *L1, const char *fname) +{ + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + +LJLIB_CF(debug_getinfo) +{ + lj_Debug ar; + int arg, opt_f = 0, opt_L = 0; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) { + setnilV(L->top-1); + return 1; + } + } else if (L->base+arg < L->top && tvisfunc(L->base+arg)) { + options = lua_pushfstring(L, ">%s", options); + setfuncV(L1, L1->top++, funcV(L->base+arg)); + } else { + lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL); + } + if (!lj_debug_getinfo(L1, options, &ar, 1)) + lj_err_arg(L, arg+2, LJ_ERR_INVOPT); + lua_createtable(L, 0, 16); /* Create result table. */ + for (; *options; options++) { + switch (*options) { + case 'S': + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + break; + case 'l': + settabsi(L, "currentline", ar.currentline); + break; + case 'u': + settabsi(L, "nups", ar.nups); + settabsi(L, "nparams", ar.nparams); + settabsb(L, "isvararg", ar.isvararg); + break; + case 'n': + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + break; + case 'f': opt_f = 1; break; + case 'L': opt_L = 1; break; + default: break; + } + } + if (opt_L) treatstackoption(L, L1, "activelines"); + if (opt_f) treatstackoption(L, L1, "func"); + return 1; /* Return result table. */ +} + +LJLIB_CF(debug_getlocal) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + int slot = lj_lib_checkint(L, arg+2); + if (tvisfunc(L->base+arg)) { + L->top = L->base+arg+1; + lua_pushstring(L, lua_getlocal(L, NULL, slot)); + return 1; + } + if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) + lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); + name = lua_getlocal(L1, &ar, slot); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } else { + setnilV(L->top-1); + return 1; + } +} + +LJLIB_CF(debug_setlocal) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + TValue *tv; + if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) + lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); + tv = lj_lib_checkany(L, arg+3); + copyTV(L1, L1->top++, tv); + lua_pushstring(L, lua_setlocal(L1, &ar, lj_lib_checkint(L, arg+2))); + return 1; +} + +static int debug_getupvalue(lua_State *L, int get) +{ + int32_t n = lj_lib_checkint(L, 2); + const char *name; + lj_lib_checkfunc(L, 1); + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name) { + lua_pushstring(L, name); + if (!get) return 1; + copyTV(L, L->top, L->top-2); + L->top++; + return 2; + } + return 0; +} + +LJLIB_CF(debug_getupvalue) +{ + return debug_getupvalue(L, 1); +} + +LJLIB_CF(debug_setupvalue) +{ + lj_lib_checkany(L, 3); + return debug_getupvalue(L, 0); +} + +LJLIB_CF(debug_upvalueid) +{ + GCfunc *fn = lj_lib_checkfunc(L, 1); + int32_t n = lj_lib_checkint(L, 2) - 1; + if ((uint32_t)n >= fn->l.nupvalues) + lj_err_arg(L, 2, LJ_ERR_IDXRNG); + setlightudV(L->top-1, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : + (void *)&fn->c.upvalue[n]); + return 1; +} + +LJLIB_CF(debug_upvaluejoin) +{ + GCfunc *fn[2]; + GCRef *p[2]; + int i; + for (i = 0; i < 2; i++) { + int32_t n; + fn[i] = lj_lib_checkfunc(L, 2*i+1); + if (!isluafunc(fn[i])) + lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC); + n = lj_lib_checkint(L, 2*i+2) - 1; + if ((uint32_t)n >= fn[i]->l.nupvalues) + lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG); + p[i] = &fn[i]->l.uvptr[n]; + } + setgcrefr(*p[0], *p[1]); + lj_gc_objbarrier(L, fn[0], gcref(*p[1])); + return 0; +} + +#if LJ_52 +LJLIB_CF(debug_getuservalue) +{ + TValue *o = L->base; + if (o < L->top && tvisudata(o)) + settabV(L, o, tabref(udataV(o)->env)); + else + setnilV(o); + L->top = o+1; + return 1; +} + +LJLIB_CF(debug_setuservalue) +{ + TValue *o = L->base; + if (!(o < L->top && tvisudata(o))) + lj_err_argt(L, 1, LUA_TUSERDATA); + if (!(o+1 < L->top && tvistab(o+1))) + lj_err_argt(L, 2, LUA_TTABLE); + L->top = o+2; + lua_setfenv(L, 1); + return 1; +} +#endif + +/* ------------------------------------------------------------------------ */ + +static const char KEY_HOOK = 'h'; + +static void hookf(lua_State *L, lua_Debug *ar) +{ + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_call(L, 2, 0); + } +} + +static int makemask(const char *smask, int count) +{ + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + +static char *unmakemask(int mask, char *smask) +{ + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + +LJLIB_CF(debug_sethook) +{ + int arg, mask, count; + lua_Hook func; + (void)getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, arg+1); + lua_rawset(L, LUA_REGISTRYINDEX); + lua_sethook(L, func, mask, count); + return 0; +} + +LJLIB_CF(debug_gethook) +{ + char buff[5]; + int mask = lua_gethookmask(L); + lua_Hook hook = lua_gethook(L); + if (hook != NULL && hook != hookf) { /* external hook? */ + lua_pushliteral(L, "external hook"); + } else { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L)); + return 3; +} + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(debug_debug) +{ + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + +/* ------------------------------------------------------------------------ */ + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +LJLIB_CF(debug_traceback) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + const char *msg = lua_tostring(L, arg+1); + if (msg == NULL && L->top > L->base+arg) + L->top = L->base+arg+1; + else + luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1))); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_debug(lua_State *L) +{ + LJ_LIB_REG(L, LUA_DBLIBNAME, debug); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_ffi.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_ffi.c new file mode 100644 index 0000000..e789ad6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_ffi.c @@ -0,0 +1,850 @@ +/* +** FFI library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_ffi_c +#define LUA_LIB + +#include + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_ctype.h" +#include "lj_cparse.h" +#include "lj_cdata.h" +#include "lj_cconv.h" +#include "lj_carith.h" +#include "lj_ccall.h" +#include "lj_ccallback.h" +#include "lj_clib.h" +#include "lj_ff.h" +#include "lj_lib.h" + +/* -- C type checks ------------------------------------------------------- */ + +/* Check first argument for a C type and returns its ID. */ +static CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param) +{ + TValue *o = L->base; + if (!(o < L->top)) { + err_argtype: + lj_err_argtype(L, 1, "C type"); + } + if (tvisstr(o)) { /* Parse an abstract C type declaration. */ + GCstr *s = strV(o); + CPState cp; + int errcode; + cp.L = L; + cp.cts = cts; + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = param; + cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT; + errcode = lj_cparse(&cp); + if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */ + return cp.val.id; + } else { + GCcdata *cd; + if (!tviscdata(o)) goto err_argtype; + if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM); + cd = cdataV(o); + return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid; + } +} + +/* Check argument for C data and return it. */ +static GCcdata *ffi_checkcdata(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tviscdata(o))) + lj_err_argt(L, narg, LUA_TCDATA); + return cdataV(o); +} + +/* Convert argument to C pointer. */ +static void *ffi_checkptr(lua_State *L, int narg, CTypeID id) +{ + CTState *cts = ctype_cts(L); + TValue *o = L->base + narg-1; + void *p; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg)); + return p; +} + +/* Convert argument to int32_t. */ +static int32_t ffi_checkint(lua_State *L, int narg) +{ + CTState *cts = ctype_cts(L); + TValue *o = L->base + narg-1; + int32_t i; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, + CCF_ARG(narg)); + return i; +} + +/* -- C type metamethods -------------------------------------------------- */ + +#define LJLIB_MODULE_ffi_meta + +/* Handle ctype __index/__newindex metamethods. */ +static int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm) +{ + CTypeID id = ctype_typeid(cts, ct); + cTValue *tv = lj_ctype_meta(cts, id, mm); + TValue *base = L->base; + if (!tv) { + const char *s; + err_index: + s = strdata(lj_ctype_repr(L, id, NULL)); + if (tvisstr(L->base+1)) { + lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1)); + } else { + const char *key = tviscdata(L->base+1) ? + strdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) : + lj_typename(L->base+1); + lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key); + } + } + if (!tvisfunc(tv)) { + if (mm == MM_index) { + cTValue *o = lj_meta_tget(L, tv, base+1); + if (o) { + if (tvisnil(o)) goto err_index; + copyTV(L, L->top-1, o); + return 1; + } + } else { + TValue *o = lj_meta_tset(L, tv, base+1); + if (o) { + copyTV(L, o, base+2); + return 0; + } + } + tv = L->top-1; + } + return lj_meta_tailcall(L, tv); +} + +LJLIB_CF(ffi_meta___index) LJLIB_REC(cdata_index 0) +{ + CTState *cts = ctype_cts(L); + CTInfo qual = 0; + CType *ct; + uint8_t *p; + TValue *o = L->base; + if (!(o+1 < L->top && tviscdata(o))) /* Also checks for presence of key. */ + lj_err_argt(L, 1, LUA_TCDATA); + ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual); + if ((qual & 1)) + return ffi_index_meta(L, cts, ct, MM_index); + if (lj_cdata_get(cts, ct, L->top-1, p)) + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_meta___newindex) LJLIB_REC(cdata_index 1) +{ + CTState *cts = ctype_cts(L); + CTInfo qual = 0; + CType *ct; + uint8_t *p; + TValue *o = L->base; + if (!(o+2 < L->top && tviscdata(o))) /* Also checks for key and value. */ + lj_err_argt(L, 1, LUA_TCDATA); + ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual); + if ((qual & 1)) { + if ((qual & CTF_CONST)) + lj_err_caller(L, LJ_ERR_FFI_WRCONST); + return ffi_index_meta(L, cts, ct, MM_newindex); + } + lj_cdata_set(cts, ct, p, o+2, qual); + return 0; +} + +/* Common handler for cdata arithmetic. */ +static int ffi_arith(lua_State *L) +{ + MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq); + return lj_carith_op(L, mm); +} + +/* The following functions must be in contiguous ORDER MM. */ +LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___le) LJLIB_REC(cdata_arith MM_le) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___concat) LJLIB_REC(cdata_arith MM_concat) +{ + return ffi_arith(L); +} + +/* Forward declaration. */ +static int lj_cf_ffi_new(lua_State *L); + +LJLIB_CF(ffi_meta___call) LJLIB_REC(cdata_call) +{ + CTState *cts = ctype_cts(L); + GCcdata *cd = ffi_checkcdata(L, 1); + CTypeID id = cd->ctypeid; + CType *ct; + cTValue *tv; + MMS mm = MM_call; + if (cd->ctypeid == CTID_CTYPEID) { + id = *(CTypeID *)cdataptr(cd); + mm = MM_new; + } else { + int ret = lj_ccall_func(L, cd); + if (ret >= 0) + return ret; + } + /* Handle ctype __call/__new metamethod. */ + ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + if (tv) + return lj_meta_tailcall(L, tv); + else if (mm == MM_call) + lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL))); + return lj_cf_ffi_new(L); +} + +LJLIB_CF(ffi_meta___add) LJLIB_REC(cdata_arith MM_add) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___sub) LJLIB_REC(cdata_arith MM_sub) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___mul) LJLIB_REC(cdata_arith MM_mul) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___div) LJLIB_REC(cdata_arith MM_div) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___mod) LJLIB_REC(cdata_arith MM_mod) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___pow) LJLIB_REC(cdata_arith MM_pow) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___unm) LJLIB_REC(cdata_arith MM_unm) +{ + return ffi_arith(L); +} +/* End of contiguous ORDER MM. */ + +LJLIB_CF(ffi_meta___tostring) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + const char *msg = "cdata<%s>: %p"; + CTypeID id = cd->ctypeid; + void *p = cdataptr(cd); + if (id == CTID_CTYPEID) { + msg = "ctype<%s>"; + id = *(CTypeID *)p; + } else { + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, id); + if (ctype_isref(ct->info)) { + p = *(void **)p; + ct = ctype_rawchild(cts, ct); + } + if (ctype_iscomplex(ct->info)) { + setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size)); + goto checkgc; + } else if (ct->size == 8 && ctype_isinteger(ct->info)) { + setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd), + (ct->info & CTF_UNSIGNED))); + goto checkgc; + } else if (ctype_isfunc(ct->info)) { + p = *(void **)p; + } else if (ctype_isenum(ct->info)) { + msg = "cdata<%s>: %d"; + p = (void *)(uintptr_t)*(uint32_t **)p; + } else { + if (ctype_isptr(ct->info)) { + p = cdata_getptr(p, ct->size); + ct = ctype_rawchild(cts, ct); + } + if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) { + /* Handle ctype __tostring metamethod. */ + cTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring); + if (tv) + return lj_meta_tailcall(L, tv); + } + } + } + lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); +checkgc: + lj_gc_check(L); + return 1; +} + +static int ffi_pairs(lua_State *L, MMS mm) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkcdata(L, 1)->ctypeid; + CType *ct = ctype_raw(cts, id); + cTValue *tv; + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + if (!tv) + lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)), + strdata(mmname_str(G(L), mm))); + return lj_meta_tailcall(L, tv); +} + +LJLIB_CF(ffi_meta___pairs) +{ + return ffi_pairs(L, MM_pairs); +} + +LJLIB_CF(ffi_meta___ipairs) +{ + return ffi_pairs(L, MM_ipairs); +} + +LJLIB_PUSH("ffi") LJLIB_SET(__metatable) + +#include "lj_libdef.h" + +/* -- C library metamethods ----------------------------------------------- */ + +#define LJLIB_MODULE_ffi_clib + +/* Index C library by a name. */ +static TValue *ffi_clib_index(lua_State *L) +{ + TValue *o = L->base; + CLibrary *cl; + if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)) + lj_err_argt(L, 1, LUA_TUSERDATA); + cl = (CLibrary *)uddata(udataV(o)); + if (!(o+1 < L->top && tvisstr(o+1))) + lj_err_argt(L, 2, LUA_TSTRING); + return lj_clib_index(L, cl, strV(o+1)); +} + +LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index 1) +{ + TValue *tv = ffi_clib_index(L); + if (tviscdata(tv)) { + CTState *cts = ctype_cts(L); + GCcdata *cd = cdataV(tv); + CType *s = ctype_get(cts, cd->ctypeid); + if (ctype_isextern(s->info)) { + CTypeID sid = ctype_cid(s->info); + void *sp = *(void **)cdataptr(cd); + CType *ct = ctype_raw(cts, sid); + if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp)) + lj_gc_check(L); + return 1; + } + } + copyTV(L, L->top-1, tv); + return 1; +} + +LJLIB_CF(ffi_clib___newindex) LJLIB_REC(clib_index 0) +{ + TValue *tv = ffi_clib_index(L); + TValue *o = L->base+2; + if (o < L->top && tviscdata(tv)) { + CTState *cts = ctype_cts(L); + GCcdata *cd = cdataV(tv); + CType *d = ctype_get(cts, cd->ctypeid); + if (ctype_isextern(d->info)) { + CTInfo qual = 0; + for (;;) { /* Skip attributes and collect qualifiers. */ + d = ctype_child(cts, d); + if (!ctype_isattrib(d->info)) break; + if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size; + } + if (!((d->info|qual) & CTF_CONST)) { + lj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0); + return 0; + } + } + } + lj_err_caller(L, LJ_ERR_FFI_WRCONST); + return 0; /* unreachable */ +} + +LJLIB_CF(ffi_clib___gc) +{ + TValue *o = L->base; + if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB) + lj_clib_unload((CLibrary *)uddata(udataV(o))); + return 0; +} + +#include "lj_libdef.h" + +/* -- Callback function metamethods --------------------------------------- */ + +#define LJLIB_MODULE_ffi_callback + +static int ffi_callback_set(lua_State *L, GCfunc *fn) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, cd->ctypeid); + if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) { + MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd)); + if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) { + GCtab *t = cts->miscmap; + TValue *tv = lj_tab_setint(L, t, (int32_t)slot); + if (fn) { + setfuncV(L, tv, fn); + lj_gc_anybarriert(L, t); + } else { + setnilV(tv); + cts->cb.cbid[slot] = 0; + cts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid; + } + return 0; + } + } + lj_err_caller(L, LJ_ERR_FFI_BADCBACK); + return 0; +} + +LJLIB_CF(ffi_callback_free) +{ + return ffi_callback_set(L, NULL); +} + +LJLIB_CF(ffi_callback_set) +{ + GCfunc *fn = lj_lib_checkfunc(L, 2); + return ffi_callback_set(L, fn); +} + +LJLIB_PUSH(top-1) LJLIB_SET(__index) + +#include "lj_libdef.h" + +/* -- FFI library functions ----------------------------------------------- */ + +#define LJLIB_MODULE_ffi + +LJLIB_CF(ffi_cdef) +{ + GCstr *s = lj_lib_checkstr(L, 1); + CPState cp; + int errcode; + cp.L = L; + cp.cts = ctype_cts(L); + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = L->base+1; + cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT; + errcode = lj_cparse(&cp); + if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */ + lj_gc_check(L); + return 0; +} + +LJLIB_CF(ffi_new) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CType *ct = ctype_raw(cts, id); + CTSize sz; + CTInfo info = lj_ctype_info(cts, id, &sz); + TValue *o = L->base+1; + GCcdata *cd; + if ((info & CTF_VLA)) { + o++; + sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2)); + } + if (sz == CTSIZE_INVALID) + lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE); + if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN) + cd = lj_cdata_new(cts, id, sz); + else + cd = lj_cdata_newv(cts, id, sz, ctype_align(info)); + setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */ + lj_cconv_ct_init(cts, ct, sz, cdataptr(cd), + o, (MSize)(L->top - o)); /* Initialize cdata. */ + if (ctype_isstruct(ct->info)) { + /* Handle ctype __gc metamethod. Use the fast lookup here. */ + cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id); + if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) { + GCtab *t = cts->finalizer; + if (gcref(t->metatable)) { + /* Add to finalizer table, if still enabled. */ + copyTV(L, lj_tab_set(L, t, o-1), tv); + lj_gc_anybarriert(L, t); + cd->marked |= LJ_GC_CDATA_FIN; + } + } + } + L->top = o; /* Only return the cdata itself. */ + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_cast) LJLIB_REC(ffi_new) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CType *d = ctype_raw(cts, id); + TValue *o = lj_lib_checkany(L, 2); + L->top = o+1; /* Make sure this is the last item on the stack. */ + if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) { + GCcdata *cd = lj_cdata_new(cts, id, d->size); + lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST); + setcdataV(L, o, cd); + lj_gc_check(L); + } + return 1; +} + +LJLIB_CF(ffi_typeof) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, L->base+1); + GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4); + *(CTypeID *)cdataptr(cd) = id; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_istype) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id1 = ffi_checkctype(L, cts, NULL); + TValue *o = lj_lib_checkany(L, 2); + int b = 0; + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : + cd->ctypeid; + CType *ct1 = lj_ctype_rawref(cts, id1); + CType *ct2 = lj_ctype_rawref(cts, id2); + if (ct1 == ct2) { + b = 1; + } else if (ctype_type(ct1->info) == ctype_type(ct2->info) && + ct1->size == ct2->size) { + if (ctype_ispointer(ct1->info)) + b = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL); + else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info)) + b = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0); + } else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) && + ct1 == ctype_rawchild(cts, ct2)) { + b = 1; + } + } + setboolV(L->top-1, b); + setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */ + return 1; +} + +LJLIB_CF(ffi_sizeof) LJLIB_REC(ffi_xof FF_ffi_sizeof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CTSize sz; + if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) { + sz = cdatavlen(cdataV(L->base)); + } else { + CType *ct = lj_ctype_rawref(cts, id); + if (ctype_isvltype(ct->info)) + sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2)); + else + sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID; + if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) { + setnilV(L->top-1); + return 1; + } + } + setintV(L->top-1, (int32_t)sz); + return 1; +} + +LJLIB_CF(ffi_alignof) LJLIB_REC(ffi_xof FF_ffi_alignof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CTSize sz = 0; + CTInfo info = lj_ctype_info(cts, id, &sz); + setintV(L->top-1, 1 << ctype_align(info)); + return 1; +} + +LJLIB_CF(ffi_offsetof) LJLIB_REC(ffi_xof FF_ffi_offsetof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + GCstr *name = lj_lib_checkstr(L, 2); + CType *ct = lj_ctype_rawref(cts, id); + CTSize ofs; + if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) { + CType *fct = lj_ctype_getfield(cts, ct, name, &ofs); + if (fct) { + setintV(L->top-1, ofs); + if (ctype_isfield(fct->info)) { + return 1; + } else if (ctype_isbitfield(fct->info)) { + setintV(L->top++, ctype_bitpos(fct->info)); + setintV(L->top++, ctype_bitbsz(fct->info)); + return 3; + } + } + } + return 0; +} + +LJLIB_CF(ffi_errno) LJLIB_REC(.) +{ + int err = errno; + if (L->top > L->base) + errno = ffi_checkint(L, 1); + setintV(L->top++, err); + return 1; +} + +LJLIB_CF(ffi_string) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + TValue *o = lj_lib_checkany(L, 1); + const char *p; + size_t len; + if (o+1 < L->top && !tvisnil(o+1)) { + len = (size_t)ffi_checkint(L, 2); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o, + CCF_ARG(1)); + } else { + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o, + CCF_ARG(1)); + len = strlen(p); + } + L->top = o+1; /* Make sure this is the last item on the stack. */ + setstrV(L, o, lj_str_new(L, p, len)); + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_copy) LJLIB_REC(.) +{ + void *dp = ffi_checkptr(L, 1, CTID_P_VOID); + void *sp = ffi_checkptr(L, 2, CTID_P_CVOID); + TValue *o = L->base+1; + CTSize len; + if (tvisstr(o) && o+1 >= L->top) + len = strV(o)->len+1; /* Copy Lua string including trailing '\0'. */ + else + len = (CTSize)ffi_checkint(L, 3); + memcpy(dp, sp, len); + return 0; +} + +LJLIB_CF(ffi_fill) LJLIB_REC(.) +{ + void *dp = ffi_checkptr(L, 1, CTID_P_VOID); + CTSize len = (CTSize)ffi_checkint(L, 2); + int32_t fill = 0; + if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3); + memset(dp, fill, len); + return 0; +} + +#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be) + +/* Test ABI string. */ +LJLIB_CF(ffi_abi) LJLIB_REC(.) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int b = 0; + switch (s->hash) { +#if LJ_64 + case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */ +#else + case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */ +#endif +#if LJ_ARCH_HASFPU + case H_(e33ee463,e33ee463): b = 1; break; /* fpu */ +#endif +#if LJ_ABI_SOFTFP + case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */ +#else + case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */ +#endif +#if LJ_ABI_EABI + case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */ +#endif +#if LJ_ABI_WIN + case H_(4ab624a8,4ab624a8): b = 1; break; /* win */ +#endif + case H_(3af93066,1f001464): b = 1; break; /* le/be */ + default: + break; + } + setboolV(L->top-1, b); + setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */ + return 1; +} + +#undef H_ + +LJLIB_PUSH(top-8) LJLIB_SET(!) /* Store reference to miscmap table. */ + +LJLIB_CF(ffi_metatype) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + GCtab *mt = lj_lib_checktab(L, 2); + GCtab *t = cts->miscmap; + CType *ct = ctype_get(cts, id); /* Only allow raw types. */ + TValue *tv; + GCcdata *cd; + if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) || + ctype_isvector(ct->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + tv = lj_tab_setinth(L, t, -(int32_t)id); + if (!tvisnil(tv)) + lj_err_caller(L, LJ_ERR_PROTMT); + settabV(L, tv, mt); + lj_gc_anybarriert(L, t); + cd = lj_cdata_new(cts, CTID_CTYPEID, 4); + *(CTypeID *)cdataptr(cd) = id; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */ + +LJLIB_CF(ffi_gc) LJLIB_REC(.) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + TValue *fin = lj_lib_checkany(L, 2); + CTState *cts = ctype_cts(L); + GCtab *t = cts->finalizer; + CType *ct = ctype_raw(cts, cd->ctypeid); + if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) || + ctype_isrefarray(ct->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + if (gcref(t->metatable)) { /* Update finalizer table, if still enabled. */ + copyTV(L, lj_tab_set(L, t, L->base), fin); + lj_gc_anybarriert(L, t); + if (!tvisnil(fin)) + cd->marked |= LJ_GC_CDATA_FIN; + else + cd->marked &= ~LJ_GC_CDATA_FIN; + } + L->top = L->base+1; /* Pass through the cdata object. */ + return 1; +} + +LJLIB_PUSH(top-5) LJLIB_SET(!) /* Store clib metatable in func environment. */ + +LJLIB_CF(ffi_load) +{ + GCstr *name = lj_lib_checkstr(L, 1); + int global = (L->base+1 < L->top && tvistruecond(L->base+1)); + lj_clib_load(L, tabref(curr_func(L)->c.env), name, global); + return 1; +} + +LJLIB_PUSH(top-4) LJLIB_SET(C) +LJLIB_PUSH(top-3) LJLIB_SET(os) +LJLIB_PUSH(top-2) LJLIB_SET(arch) + +#include "lj_libdef.h" + +/* ------------------------------------------------------------------------ */ + +/* Create special weak-keyed finalizer table. */ +static GCtab *ffi_finalizer(lua_State *L) +{ + /* NOBARRIER: The table is new (marked white). */ + GCtab *t = lj_tab_new(L, 0, 1); + settabV(L, L->top++, t); + setgcref(t->metatable, obj2gco(t)); + setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), + lj_str_newlit(L, "K")); + t->nomm = (uint8_t)(~(1u<top-1); + lj_gc_anybarriert(L, t); + } +} + +LUALIB_API int luaopen_ffi(lua_State *L) +{ + CTState *cts = lj_ctype_init(L); + settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1))); + cts->finalizer = ffi_finalizer(L); + LJ_LIB_REG(L, NULL, ffi_meta); + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1))); + LJ_LIB_REG(L, NULL, ffi_clib); + LJ_LIB_REG(L, NULL, ffi_callback); + /* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */ + settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1)); + L->top--; + lj_clib_default(L, tabV(L->top-1)); /* Create ffi.C default namespace. */ + lua_pushliteral(L, LJ_OS_NAME); + lua_pushliteral(L, LJ_ARCH_NAME); + LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */ + ffi_register_module(L); + return 1; +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_init.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_init.c new file mode 100644 index 0000000..a729d12 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_init.c @@ -0,0 +1,55 @@ +/* +** Library initialization. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major parts taken verbatim from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_init_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_arch.h" + +static const luaL_Reg lj_lib_load[] = { + { "", luaopen_base }, + { LUA_LOADLIBNAME, luaopen_package }, + { LUA_TABLIBNAME, luaopen_table }, + { LUA_IOLIBNAME, luaopen_io }, + { LUA_OSLIBNAME, luaopen_os }, + { LUA_STRLIBNAME, luaopen_string }, + { LUA_MATHLIBNAME, luaopen_math }, + { LUA_DBLIBNAME, luaopen_debug }, + { LUA_BITLIBNAME, luaopen_bit }, + { LUA_JITLIBNAME, luaopen_jit }, + { NULL, NULL } +}; + +static const luaL_Reg lj_lib_preload[] = { +#if LJ_HASFFI + { LUA_FFILIBNAME, luaopen_ffi }, +#endif + { NULL, NULL } +}; + +LUALIB_API void luaL_openlibs(lua_State *L) +{ + const luaL_Reg *lib; + for (lib = lj_lib_load; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } + luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", + sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1); + for (lib = lj_lib_preload; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_setfield(L, -2, lib->name); + } + lua_pop(L, 1); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_io.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_io.c new file mode 100644 index 0000000..04f0f73 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_io.c @@ -0,0 +1,539 @@ +/* +** I/O library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include + +#define lib_io_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_state.h" +#include "lj_ff.h" +#include "lj_lib.h" + +/* Userdata payload for I/O file. */ +typedef struct IOFileUD { + FILE *fp; /* File handle. */ + uint32_t type; /* File type. */ +} IOFileUD; + +#define IOFILE_TYPE_FILE 0 /* Regular file. */ +#define IOFILE_TYPE_PIPE 1 /* Pipe. */ +#define IOFILE_TYPE_STDF 2 /* Standard file handle. */ +#define IOFILE_TYPE_MASK 3 + +#define IOFILE_FLAG_CLOSE 4 /* Close after io.lines() iterator. */ + +#define IOSTDF_UD(L, id) (&gcref(G(L)->gcroot[(id)])->ud) +#define IOSTDF_IOF(L, id) ((IOFileUD *)uddata(IOSTDF_UD(L, (id)))) + +/* -- Open/close helpers -------------------------------------------------- */ + +static IOFileUD *io_tofilep(lua_State *L) +{ + if (!(L->base < L->top && tvisudata(L->base) && + udataV(L->base)->udtype == UDTYPE_IO_FILE)) + lj_err_argtype(L, 1, "FILE*"); + return (IOFileUD *)uddata(udataV(L->base)); +} + +static IOFileUD *io_tofile(lua_State *L) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOCLFL); + return iof; +} + +static FILE *io_stdfile(lua_State *L, ptrdiff_t id) +{ + IOFileUD *iof = IOSTDF_IOF(L, id); + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOSTDCL); + return iof->fp; +} + +static IOFileUD *io_file_new(lua_State *L) +{ + IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD)); + GCudata *ud = udataV(L->top-1); + ud->udtype = UDTYPE_IO_FILE; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcrefr(ud->metatable, curr_func(L)->c.env); + iof->fp = NULL; + iof->type = IOFILE_TYPE_FILE; + return iof; +} + +static IOFileUD *io_file_open(lua_State *L, const char *mode) +{ + const char *fname = strdata(lj_lib_checkstr(L, 1)); + IOFileUD *iof = io_file_new(L); + iof->fp = fopen(fname, mode); + if (iof->fp == NULL) + luaL_argerror(L, 1, lj_str_pushf(L, "%s: %s", fname, strerror(errno))); + return iof; +} + +static int io_file_close(lua_State *L, IOFileUD *iof) +{ + int ok; + if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) { + ok = (fclose(iof->fp) == 0); + } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) { + int stat = -1; +#if LJ_TARGET_POSIX + stat = pclose(iof->fp); +#elif LJ_TARGET_WINDOWS + stat = _pclose(iof->fp); +#else + lua_assert(0); + return 0; +#endif +#if LJ_52 + iof->fp = NULL; + return luaL_execresult(L, stat); +#else + ok = (stat != -1); +#endif + } else { + lua_assert((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_STDF); + setnilV(L->top++); + lua_pushliteral(L, "cannot close standard file"); + return 2; + } + iof->fp = NULL; + return luaL_fileresult(L, ok, NULL); +} + +/* -- Read/write helpers -------------------------------------------------- */ + +static int io_file_readnum(lua_State *L, FILE *fp) +{ + lua_Number d; + if (fscanf(fp, LUA_NUMBER_SCAN, &d) == 1) { + if (LJ_DUALNUM) { + int32_t i = lj_num2int(d); + if (d == (lua_Number)i && !tvismzero((cTValue *)&d)) { + setintV(L->top++, i); + return 1; + } + } + setnumV(L->top++, d); + return 1; + } else { + setnilV(L->top++); + return 0; + } +} + +static int io_file_readline(lua_State *L, FILE *fp, MSize chop) +{ + MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0; + char *buf; + for (;;) { + buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + if (fgets(buf+n, m-n, fp) == NULL) break; + n += (MSize)strlen(buf+n); + ok |= n; + if (n && buf[n-1] == '\n') { n -= chop; break; } + if (n >= m - 64) m += m; + } + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return (int)ok; +} + +static void io_file_readall(lua_State *L, FILE *fp) +{ + MSize m, n; + for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) { + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + n += (MSize)fread(buf+n, 1, m-n, fp); + if (n != m) { + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return; + } + } +} + +static int io_file_readlen(lua_State *L, FILE *fp, MSize m) +{ + if (m) { + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + MSize n = (MSize)fread(buf, 1, m, fp); + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return (n > 0 || m == 0); + } else { + int c = getc(fp); + ungetc(c, fp); + setstrV(L, L->top++, &G(L)->strempty); + return (c != EOF); + } +} + +static int io_file_read(lua_State *L, FILE *fp, int start) +{ + int ok, n, nargs = (int)(L->top - L->base) - start; + clearerr(fp); + if (nargs == 0) { + ok = io_file_readline(L, fp, 1); + n = start+1; /* Return 1 result. */ + } else { + /* The results plus the buffers go on top of the args. */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + ok = 1; + for (n = start; nargs-- && ok; n++) { + if (tvisstr(L->base+n)) { + const char *p = strVdata(L->base+n); + if (p[0] != '*') + lj_err_arg(L, n+1, LJ_ERR_INVOPT); + if (p[1] == 'n') + ok = io_file_readnum(L, fp); + else if ((p[1] & ~0x20) == 'L') + ok = io_file_readline(L, fp, (p[1] == 'l')); + else if (p[1] == 'a') + io_file_readall(L, fp); + else + lj_err_arg(L, n+1, LJ_ERR_INVFMT); + } else if (tvisnumber(L->base+n)) { + ok = io_file_readlen(L, fp, (MSize)lj_lib_checkint(L, n+1)); + } else { + lj_err_arg(L, n+1, LJ_ERR_INVOPT); + } + } + } + if (ferror(fp)) + return luaL_fileresult(L, 0, NULL); + if (!ok) + setnilV(L->top-1); /* Replace last result with nil. */ + return n - start; +} + +static int io_file_write(lua_State *L, FILE *fp, int start) +{ + cTValue *tv; + int status = 1; + for (tv = L->base+start; tv < L->top; tv++) { + if (tvisstr(tv)) { + MSize len = strV(tv)->len; + status = status && (fwrite(strVdata(tv), 1, len, fp) == len); + } else if (tvisint(tv)) { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, intV(tv)); + size_t len = (size_t)(buf+LJ_STR_INTBUF-p); + status = status && (fwrite(p, 1, len, fp) == len); + } else if (tvisnum(tv)) { + status = status && (fprintf(fp, LUA_NUMBER_FMT, numV(tv)) > 0); + } else { + lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING); + } + } + if (LJ_52 && status) { + L->top = L->base+1; + if (start == 0) + setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT)); + return 1; + } + return luaL_fileresult(L, status, NULL); +} + +static int io_file_iter(lua_State *L) +{ + GCfunc *fn = curr_func(L); + IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0])); + int n = fn->c.nupvalues - 1; + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOCLFL); + L->top = L->base; + if (n) { /* Copy upvalues with options to stack. */ + if (n > LUAI_MAXCSTACK) + lj_err_caller(L, LJ_ERR_STKOV); + lj_state_checkstack(L, (MSize)n); + memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue)); + L->top += n; + } + n = io_file_read(L, iof->fp, 0); + if (ferror(iof->fp)) + lj_err_callermsg(L, strVdata(L->top-2)); + if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) { + io_file_close(L, iof); /* Return values are ignored. */ + return 0; + } + return n; +} + +/* -- I/O file methods ---------------------------------------------------- */ + +#define LJLIB_MODULE_io_method + +LJLIB_CF(io_method_close) +{ + IOFileUD *iof = L->base < L->top ? io_tofile(L) : + IOSTDF_IOF(L, GCROOT_IO_OUTPUT); + return io_file_close(L, iof); +} + +LJLIB_CF(io_method_read) +{ + return io_file_read(L, io_tofile(L)->fp, 1); +} + +LJLIB_CF(io_method_write) LJLIB_REC(io_write 0) +{ + return io_file_write(L, io_tofile(L)->fp, 1); +} + +LJLIB_CF(io_method_flush) LJLIB_REC(io_flush 0) +{ + return luaL_fileresult(L, fflush(io_tofile(L)->fp) == 0, NULL); +} + +LJLIB_CF(io_method_seek) +{ + FILE *fp = io_tofile(L)->fp; + int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); + int64_t ofs = 0; + cTValue *o; + int res; + if (opt == 0) opt = SEEK_SET; + else if (opt == 1) opt = SEEK_CUR; + else if (opt == 2) opt = SEEK_END; + o = L->base+2; + if (o < L->top) { + if (tvisint(o)) + ofs = (int64_t)intV(o); + else if (tvisnum(o)) + ofs = (int64_t)numV(o); + else if (!tvisnil(o)) + lj_err_argt(L, 3, LUA_TNUMBER); + } +#if LJ_TARGET_POSIX + res = fseeko(fp, ofs, opt); +#elif _MSC_VER >= 1400 + res = _fseeki64(fp, ofs, opt); +#elif defined(__MINGW32__) + res = fseeko64(fp, ofs, opt); +#else + res = fseek(fp, (long)ofs, opt); +#endif + if (res) + return luaL_fileresult(L, 0, NULL); +#if LJ_TARGET_POSIX + ofs = ftello(fp); +#elif _MSC_VER >= 1400 + ofs = _ftelli64(fp); +#elif defined(__MINGW32__) + ofs = ftello64(fp); +#else + ofs = (int64_t)ftell(fp); +#endif + setint64V(L->top-1, ofs); + return 1; +} + +LJLIB_CF(io_method_setvbuf) +{ + FILE *fp = io_tofile(L)->fp; + int opt = lj_lib_checkopt(L, 2, -1, "\4full\4line\2no"); + size_t sz = (size_t)lj_lib_optint(L, 3, LUAL_BUFFERSIZE); + if (opt == 0) opt = _IOFBF; + else if (opt == 1) opt = _IOLBF; + else if (opt == 2) opt = _IONBF; + return luaL_fileresult(L, setvbuf(fp, NULL, opt, sz) == 0, NULL); +} + +LJLIB_CF(io_method_lines) +{ + io_tofile(L); + lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); + return 1; +} + +LJLIB_CF(io_method___gc) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp != NULL && (iof->type & IOFILE_TYPE_MASK) != IOFILE_TYPE_STDF) + io_file_close(L, iof); + return 0; +} + +LJLIB_CF(io_method___tostring) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp != NULL) + lua_pushfstring(L, "file (%p)", iof->fp); + else + lua_pushliteral(L, "file (closed)"); + return 1; +} + +LJLIB_PUSH(top-1) LJLIB_SET(__index) + +#include "lj_libdef.h" + +/* -- I/O library functions ----------------------------------------------- */ + +#define LJLIB_MODULE_io + +LJLIB_PUSH(top-2) LJLIB_SET(!) /* Set environment. */ + +LJLIB_CF(io_open) +{ + const char *fname = strdata(lj_lib_checkstr(L, 1)); + GCstr *s = lj_lib_optstr(L, 2); + const char *mode = s ? strdata(s) : "r"; + IOFileUD *iof = io_file_new(L); + iof->fp = fopen(fname, mode); + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname); +} + +LJLIB_CF(io_popen) +{ +#if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS + const char *fname = strdata(lj_lib_checkstr(L, 1)); + GCstr *s = lj_lib_optstr(L, 2); + const char *mode = s ? strdata(s) : "r"; + IOFileUD *iof = io_file_new(L); + iof->type = IOFILE_TYPE_PIPE; +#if LJ_TARGET_POSIX + fflush(NULL); + iof->fp = popen(fname, mode); +#else + iof->fp = _popen(fname, mode); +#endif + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname); +#else + return luaL_error(L, LUA_QL("popen") " not supported"); +#endif +} + +LJLIB_CF(io_tmpfile) +{ + IOFileUD *iof = io_file_new(L); +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 + iof->fp = NULL; errno = ENOSYS; +#else + iof->fp = tmpfile(); +#endif + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL); +} + +LJLIB_CF(io_close) +{ + return lj_cf_io_method_close(L); +} + +LJLIB_CF(io_read) +{ + return io_file_read(L, io_stdfile(L, GCROOT_IO_INPUT), 0); +} + +LJLIB_CF(io_write) LJLIB_REC(io_write GCROOT_IO_OUTPUT) +{ + return io_file_write(L, io_stdfile(L, GCROOT_IO_OUTPUT), 0); +} + +LJLIB_CF(io_flush) LJLIB_REC(io_flush GCROOT_IO_OUTPUT) +{ + return luaL_fileresult(L, fflush(io_stdfile(L, GCROOT_IO_OUTPUT)) == 0, NULL); +} + +static int io_std_getset(lua_State *L, ptrdiff_t id, const char *mode) +{ + if (L->base < L->top && !tvisnil(L->base)) { + if (tvisudata(L->base)) { + io_tofile(L); + L->top = L->base+1; + } else { + io_file_open(L, mode); + } + /* NOBARRIER: The standard I/O handles are GC roots. */ + setgcref(G(L)->gcroot[id], gcV(L->top-1)); + } else { + setudataV(L, L->top++, IOSTDF_UD(L, id)); + } + return 1; +} + +LJLIB_CF(io_input) +{ + return io_std_getset(L, GCROOT_IO_INPUT, "r"); +} + +LJLIB_CF(io_output) +{ + return io_std_getset(L, GCROOT_IO_OUTPUT, "w"); +} + +LJLIB_CF(io_lines) +{ + if (L->base == L->top) setnilV(L->top++); + if (!tvisnil(L->base)) { /* io.lines(fname) */ + IOFileUD *iof = io_file_open(L, "r"); + iof->type = IOFILE_TYPE_FILE|IOFILE_FLAG_CLOSE; + L->top--; + setudataV(L, L->base, udataV(L->top)); + } else { /* io.lines() iterates over stdin. */ + setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); + } + lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); + return 1; +} + +LJLIB_CF(io_type) +{ + cTValue *o = lj_lib_checkany(L, 1); + if (!(tvisudata(o) && udataV(o)->udtype == UDTYPE_IO_FILE)) + setnilV(L->top++); + else if (((IOFileUD *)uddata(udataV(o)))->fp != NULL) + lua_pushliteral(L, "file"); + else + lua_pushliteral(L, "closed file"); + return 1; +} + +#include "lj_libdef.h" + +/* ------------------------------------------------------------------------ */ + +static GCobj *io_std_new(lua_State *L, FILE *fp, const char *name) +{ + IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD)); + GCudata *ud = udataV(L->top-1); + ud->udtype = UDTYPE_IO_FILE; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcref(ud->metatable, gcV(L->top-3)); + iof->fp = fp; + iof->type = IOFILE_TYPE_STDF; + lua_setfield(L, -2, name); + return obj2gco(ud); +} + +LUALIB_API int luaopen_io(lua_State *L) +{ + LJ_LIB_REG(L, NULL, io_method); + copyTV(L, L->top, L->top-1); L->top++; + lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + LJ_LIB_REG(L, LUA_IOLIBNAME, io); + setgcref(G(L)->gcroot[GCROOT_IO_INPUT], io_std_new(L, stdin, "stdin")); + setgcref(G(L)->gcroot[GCROOT_IO_OUTPUT], io_std_new(L, stdout, "stdout")); + io_std_new(L, stderr, "stderr"); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_jit.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_jit.c new file mode 100644 index 0000000..0fadf8b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_jit.c @@ -0,0 +1,663 @@ +/* +** JIT library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_jit_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_arch.h" +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_target.h" +#endif +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" +#include "lj_lib.h" + +#include "luajit.h" + +/* -- jit.* functions ----------------------------------------------------- */ + +#define LJLIB_MODULE_jit + +static int setjitmode(lua_State *L, int mode) +{ + int idx = 0; + if (L->base == L->top || tvisnil(L->base)) { /* jit.on/off/flush([nil]) */ + mode |= LUAJIT_MODE_ENGINE; + } else { + /* jit.on/off/flush(func|proto, nil|true|false) */ + if (tvisfunc(L->base) || tvisproto(L->base)) + idx = 1; + else if (!tvistrue(L->base)) /* jit.on/off/flush(true, nil|true|false) */ + goto err; + if (L->base+1 < L->top && tvisbool(L->base+1)) + mode |= boolV(L->base+1) ? LUAJIT_MODE_ALLFUNC : LUAJIT_MODE_ALLSUBFUNC; + else + mode |= LUAJIT_MODE_FUNC; + } + if (luaJIT_setmode(L, idx, mode) != 1) { + if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE) + lj_err_caller(L, LJ_ERR_NOJIT); + err: + lj_err_argt(L, 1, LUA_TFUNCTION); + } + return 0; +} + +LJLIB_CF(jit_on) +{ + return setjitmode(L, LUAJIT_MODE_ON); +} + +LJLIB_CF(jit_off) +{ + return setjitmode(L, LUAJIT_MODE_OFF); +} + +LJLIB_CF(jit_flush) +{ +#if LJ_HASJIT + if (L->base < L->top && tvisnumber(L->base)) { + int traceno = lj_lib_checkint(L, 1); + luaJIT_setmode(L, traceno, LUAJIT_MODE_FLUSH|LUAJIT_MODE_TRACE); + return 0; + } +#endif + return setjitmode(L, LUAJIT_MODE_FLUSH); +} + +#if LJ_HASJIT +/* Push a string for every flag bit that is set. */ +static void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base, + const char *str) +{ + for (; *str; base <<= 1, str += 1+*str) + if (flags & base) + setstrV(L, L->top++, lj_str_new(L, str+1, *(uint8_t *)str)); +} +#endif + +LJLIB_CF(jit_status) +{ +#if LJ_HASJIT + jit_State *J = L2J(L); + L->top = L->base; + setboolV(L->top++, (J->flags & JIT_F_ON) ? 1 : 0); + flagbits_to_strings(L, J->flags, JIT_F_CPU_FIRST, JIT_F_CPUSTRING); + flagbits_to_strings(L, J->flags, JIT_F_OPT_FIRST, JIT_F_OPTSTRING); + return (int)(L->top - L->base); +#else + setboolV(L->top++, 0); + return 1; +#endif +} + +LJLIB_CF(jit_attach) +{ +#ifdef LUAJIT_DISABLE_VMEVENT + luaL_error(L, "vmevent API disabled"); +#else + GCfunc *fn = lj_lib_checkfunc(L, 1); + GCstr *s = lj_lib_optstr(L, 2); + luaL_findtable(L, LUA_REGISTRYINDEX, LJ_VMEVENTS_REGKEY, LJ_VMEVENTS_HSIZE); + if (s) { /* Attach to given event. */ + const uint8_t *p = (const uint8_t *)strdata(s); + uint32_t h = s->len; + while (*p) h = h ^ (lj_rol(h, 6) + *p++); + lua_pushvalue(L, 1); + lua_rawseti(L, -2, VMEVENT_HASHIDX(h)); + G(L)->vmevmask = VMEVENT_NOCACHE; /* Invalidate cache. */ + } else { /* Detach if no event given. */ + setnilV(L->top++); + while (lua_next(L, -2)) { + L->top--; + if (tvisfunc(L->top) && funcV(L->top) == fn) { + setnilV(lj_tab_set(L, tabV(L->top-2), L->top-1)); + } + } + } +#endif + return 0; +} + +LJLIB_PUSH(top-5) LJLIB_SET(os) +LJLIB_PUSH(top-4) LJLIB_SET(arch) +LJLIB_PUSH(top-3) LJLIB_SET(version_num) +LJLIB_PUSH(top-2) LJLIB_SET(version) + +#include "lj_libdef.h" + +/* -- jit.util.* functions ------------------------------------------------ */ + +#define LJLIB_MODULE_jit_util + +/* -- Reflection API for Lua functions ------------------------------------ */ + +/* Return prototype of first argument (Lua function or prototype object) */ +static GCproto *check_Lproto(lua_State *L, int nolua) +{ + TValue *o = L->base; + if (L->top > o) { + if (tvisproto(o)) { + return protoV(o); + } else if (tvisfunc(o)) { + if (isluafunc(funcV(o))) + return funcproto(funcV(o)); + else if (nolua) + return NULL; + } + } + lj_err_argt(L, 1, LUA_TFUNCTION); + return NULL; /* unreachable */ +} + +static void setintfield(lua_State *L, GCtab *t, const char *name, int32_t val) +{ + setintV(lj_tab_setstr(L, t, lj_str_newz(L, name)), val); +} + +/* local info = jit.util.funcinfo(func [,pc]) */ +LJLIB_CF(jit_util_funcinfo) +{ + GCproto *pt = check_Lproto(L, 1); + if (pt) { + BCPos pc = (BCPos)lj_lib_optint(L, 2, 0); + GCtab *t; + lua_createtable(L, 0, 16); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + setintfield(L, t, "linedefined", pt->firstline); + setintfield(L, t, "lastlinedefined", pt->firstline + pt->numline); + setintfield(L, t, "stackslots", pt->framesize); + setintfield(L, t, "params", pt->numparams); + setintfield(L, t, "bytecodes", (int32_t)pt->sizebc); + setintfield(L, t, "gcconsts", (int32_t)pt->sizekgc); + setintfield(L, t, "nconsts", (int32_t)pt->sizekn); + setintfield(L, t, "upvalues", (int32_t)pt->sizeuv); + if (pc < pt->sizebc) + setintfield(L, t, "currentline", lj_debug_line(pt, pc)); + lua_pushboolean(L, (pt->flags & PROTO_VARARG)); + lua_setfield(L, -2, "isvararg"); + lua_pushboolean(L, (pt->flags & PROTO_CHILD)); + lua_setfield(L, -2, "children"); + setstrV(L, L->top++, proto_chunkname(pt)); + lua_setfield(L, -2, "source"); + lj_debug_pushloc(L, pt, pc); + lua_setfield(L, -2, "loc"); + } else { + GCfunc *fn = funcV(L->base); + GCtab *t; + lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + if (!iscfunc(fn)) + setintfield(L, t, "ffid", fn->c.ffid); + setintptrV(lj_tab_setstr(L, t, lj_str_newlit(L, "addr")), + (intptr_t)(void *)fn->c.f); + setintfield(L, t, "upvalues", fn->c.nupvalues); + } + return 1; +} + +/* local ins, m = jit.util.funcbc(func, pc) */ +LJLIB_CF(jit_util_funcbc) +{ + GCproto *pt = check_Lproto(L, 0); + BCPos pc = (BCPos)lj_lib_checkint(L, 2); + if (pc < pt->sizebc) { + BCIns ins = proto_bc(pt)[pc]; + BCOp op = bc_op(ins); + lua_assert(op < BC__MAX); + setintV(L->top, ins); + setintV(L->top+1, lj_bc_mode[op]); + L->top += 2; + return 2; + } + return 0; +} + +/* local k = jit.util.funck(func, idx) */ +LJLIB_CF(jit_util_funck) +{ + GCproto *pt = check_Lproto(L, 0); + ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2); + if (idx >= 0) { + if (idx < (ptrdiff_t)pt->sizekn) { + copyTV(L, L->top-1, proto_knumtv(pt, idx)); + return 1; + } + } else { + if (~idx < (ptrdiff_t)pt->sizekgc) { + GCobj *gc = proto_kgc(pt, idx); + setgcV(L, L->top-1, gc, ~gc->gch.gct); + return 1; + } + } + return 0; +} + +/* local name = jit.util.funcuvname(func, idx) */ +LJLIB_CF(jit_util_funcuvname) +{ + GCproto *pt = check_Lproto(L, 0); + uint32_t idx = (uint32_t)lj_lib_checkint(L, 2); + if (idx < pt->sizeuv) { + setstrV(L, L->top-1, lj_str_newz(L, lj_debug_uvname(pt, idx))); + return 1; + } + return 0; +} + +/* -- Reflection API for traces ------------------------------------------- */ + +#if LJ_HASJIT + +/* Check trace argument. Must not throw for non-existent trace numbers. */ +static GCtrace *jit_checktrace(lua_State *L) +{ + TraceNo tr = (TraceNo)lj_lib_checkint(L, 1); + jit_State *J = L2J(L); + if (tr > 0 && tr < J->sizetrace) + return traceref(J, tr); + return NULL; +} + +/* Names of link types. ORDER LJ_TRLINK */ +static const char *const jit_trlinkname[] = { + "none", "root", "loop", "tail-recursion", "up-recursion", "down-recursion", + "interpreter", "return" +}; + +/* local info = jit.util.traceinfo(tr) */ +LJLIB_CF(jit_util_traceinfo) +{ + GCtrace *T = jit_checktrace(L); + if (T) { + GCtab *t; + lua_createtable(L, 0, 8); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + setintfield(L, t, "nins", (int32_t)T->nins - REF_BIAS - 1); + setintfield(L, t, "nk", REF_BIAS - (int32_t)T->nk); + setintfield(L, t, "link", T->link); + setintfield(L, t, "nexit", T->nsnap); + setstrV(L, L->top++, lj_str_newz(L, jit_trlinkname[T->linktype])); + lua_setfield(L, -2, "linktype"); + /* There are many more fields. Add them only when needed. */ + return 1; + } + return 0; +} + +/* local m, ot, op1, op2, prev = jit.util.traceir(tr, idx) */ +LJLIB_CF(jit_util_traceir) +{ + GCtrace *T = jit_checktrace(L); + IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS; + if (T && ref >= REF_BIAS && ref < T->nins) { + IRIns *ir = &T->ir[ref]; + int32_t m = lj_ir_mode[ir->o]; + setintV(L->top-2, m); + setintV(L->top-1, ir->ot); + setintV(L->top++, (int32_t)ir->op1 - (irm_op1(m)==IRMref ? REF_BIAS : 0)); + setintV(L->top++, (int32_t)ir->op2 - (irm_op2(m)==IRMref ? REF_BIAS : 0)); + setintV(L->top++, ir->prev); + return 5; + } + return 0; +} + +/* local k, t [, slot] = jit.util.tracek(tr, idx) */ +LJLIB_CF(jit_util_tracek) +{ + GCtrace *T = jit_checktrace(L); + IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS; + if (T && ref >= T->nk && ref < REF_BIAS) { + IRIns *ir = &T->ir[ref]; + int32_t slot = -1; + if (ir->o == IR_KSLOT) { + slot = ir->op2; + ir = &T->ir[ir->op1]; + } + lj_ir_kvalue(L, L->top-2, ir); + setintV(L->top-1, (int32_t)irt_type(ir->t)); + if (slot == -1) + return 2; + setintV(L->top++, slot); + return 3; + } + return 0; +} + +/* local snap = jit.util.tracesnap(tr, sn) */ +LJLIB_CF(jit_util_tracesnap) +{ + GCtrace *T = jit_checktrace(L); + SnapNo sn = (SnapNo)lj_lib_checkint(L, 2); + if (T && sn < T->nsnap) { + SnapShot *snap = &T->snap[sn]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + GCtab *t; + lua_createtable(L, nent+2, 0); + t = tabV(L->top-1); + setintV(lj_tab_setint(L, t, 0), (int32_t)snap->ref - REF_BIAS); + setintV(lj_tab_setint(L, t, 1), (int32_t)snap->nslots); + for (n = 0; n < nent; n++) + setintV(lj_tab_setint(L, t, (int32_t)(n+2)), (int32_t)map[n]); + setintV(lj_tab_setint(L, t, (int32_t)(nent+2)), (int32_t)SNAP(255, 0, 0)); + return 1; + } + return 0; +} + +/* local mcode, addr, loop = jit.util.tracemc(tr) */ +LJLIB_CF(jit_util_tracemc) +{ + GCtrace *T = jit_checktrace(L); + if (T && T->mcode != NULL) { + setstrV(L, L->top-1, lj_str_new(L, (const char *)T->mcode, T->szmcode)); + setintptrV(L->top++, (intptr_t)(void *)T->mcode); + setintV(L->top++, T->mcloop); + return 3; + } + return 0; +} + +/* local addr = jit.util.traceexitstub([tr,] exitno) */ +LJLIB_CF(jit_util_traceexitstub) +{ +#ifdef EXITSTUBS_PER_GROUP + ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1); + jit_State *J = L2J(L); + if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) { + setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno)); + return 1; + } +#else + if (L->top > L->base+1) { /* Don't throw for one-argument variant. */ + GCtrace *T = jit_checktrace(L); + ExitNo exitno = (ExitNo)lj_lib_checkint(L, 2); + ExitNo maxexit = T->root ? T->nsnap+1 : T->nsnap; + if (T && T->mcode != NULL && exitno < maxexit) { + setintptrV(L->top-1, (intptr_t)(void *)exitstub_trace_addr(T, exitno)); + return 1; + } + } +#endif + return 0; +} + +/* local addr = jit.util.ircalladdr(idx) */ +LJLIB_CF(jit_util_ircalladdr) +{ + uint32_t idx = (uint32_t)lj_lib_checkint(L, 1); + if (idx < IRCALL__MAX) { + setintptrV(L->top-1, (intptr_t)(void *)lj_ir_callinfo[idx].func); + return 1; + } + return 0; +} + +#endif + +#include "lj_libdef.h" + +/* -- jit.opt module ------------------------------------------------------ */ + +#if LJ_HASJIT + +#define LJLIB_MODULE_jit_opt + +/* Parse optimization level. */ +static int jitopt_level(jit_State *J, const char *str) +{ + if (str[0] >= '0' && str[0] <= '9' && str[1] == '\0') { + uint32_t flags; + if (str[0] == '0') flags = JIT_F_OPT_0; + else if (str[0] == '1') flags = JIT_F_OPT_1; + else if (str[0] == '2') flags = JIT_F_OPT_2; + else flags = JIT_F_OPT_3; + J->flags = (J->flags & ~JIT_F_OPT_MASK) | flags; + return 1; /* Ok. */ + } + return 0; /* No match. */ +} + +/* Parse optimization flag. */ +static int jitopt_flag(jit_State *J, const char *str) +{ + const char *lst = JIT_F_OPTSTRING; + uint32_t opt; + int set = 1; + if (str[0] == '+') { + str++; + } else if (str[0] == '-') { + str++; + set = 0; + } else if (str[0] == 'n' && str[1] == 'o') { + str += str[2] == '-' ? 3 : 2; + set = 0; + } + for (opt = JIT_F_OPT_FIRST; ; opt <<= 1) { + size_t len = *(const uint8_t *)lst; + if (len == 0) + break; + if (strncmp(str, lst+1, len) == 0 && str[len] == '\0') { + if (set) J->flags |= opt; else J->flags &= ~opt; + return 1; /* Ok. */ + } + lst += 1+len; + } + return 0; /* No match. */ +} + +/* Parse optimization parameter. */ +static int jitopt_param(jit_State *J, const char *str) +{ + const char *lst = JIT_P_STRING; + int i; + for (i = 0; i < JIT_P__MAX; i++) { + size_t len = *(const uint8_t *)lst; + lua_assert(len != 0); + if (strncmp(str, lst+1, len) == 0 && str[len] == '=') { + int32_t n = 0; + const char *p = &str[len+1]; + while (*p >= '0' && *p <= '9') + n = n*10 + (*p++ - '0'); + if (*p) return 0; /* Malformed number. */ + J->param[i] = n; + if (i == JIT_P_hotloop) + lj_dispatch_init_hotcount(J2G(J)); + return 1; /* Ok. */ + } + lst += 1+len; + } + return 0; /* No match. */ +} + +/* jit.opt.start(flags...) */ +LJLIB_CF(jit_opt_start) +{ + jit_State *J = L2J(L); + int nargs = (int)(L->top - L->base); + if (nargs == 0) { + J->flags = (J->flags & ~JIT_F_OPT_MASK) | JIT_F_OPT_DEFAULT; + } else { + int i; + for (i = 1; i <= nargs; i++) { + const char *str = strdata(lj_lib_checkstr(L, i)); + if (!jitopt_level(J, str) && + !jitopt_flag(J, str) && + !jitopt_param(J, str)) + lj_err_callerv(L, LJ_ERR_JITOPT, str); + } + } + return 0; +} + +#include "lj_libdef.h" + +#endif + +/* -- JIT compiler initialization ----------------------------------------- */ + +#if LJ_HASJIT +/* Default values for JIT parameters. */ +static const int32_t jit_param_default[JIT_P__MAX+1] = { +#define JIT_PARAMINIT(len, name, value) (value), +JIT_PARAMDEF(JIT_PARAMINIT) +#undef JIT_PARAMINIT + 0 +}; +#endif + +#if LJ_TARGET_ARM && LJ_TARGET_LINUX +#include +#endif + +/* Arch-dependent CPU detection. */ +static uint32_t jit_cpudetect(lua_State *L) +{ + uint32_t flags = 0; +#if LJ_TARGET_X86ORX64 + uint32_t vendor[4]; + uint32_t features[4]; + if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { +#if !LJ_HASJIT +#define JIT_F_CMOV 1 +#define JIT_F_SSE2 2 +#endif + flags |= ((features[3] >> 15)&1) * JIT_F_CMOV; + flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; +#if LJ_HASJIT + flags |= ((features[2] >> 0)&1) * JIT_F_SSE3; + flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; + if (vendor[2] == 0x6c65746e) { /* Intel. */ + if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */ + flags |= JIT_F_P4; /* Currently unused. */ + else if ((features[0] & 0x0fff0ff0) == 0x000106c0) /* Atom. */ + flags |= JIT_F_LEA_AGU; + } else if (vendor[2] == 0x444d4163) { /* AMD. */ + uint32_t fam = (features[0] & 0x0ff00f00); + if (fam == 0x00000f00) /* K8. */ + flags |= JIT_F_SPLIT_XMM; + if (fam >= 0x00000f00) /* K8, K10. */ + flags |= JIT_F_PREFER_IMUL; + } +#endif + } + /* Check for required instruction set support on x86 (unnecessary on x64). */ +#if LJ_TARGET_X86 +#if !defined(LUAJIT_CPU_NOCMOV) + if (!(flags & JIT_F_CMOV)) + luaL_error(L, "CPU not supported"); +#endif +#if defined(LUAJIT_CPU_SSE2) + if (!(flags & JIT_F_SSE2)) + luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); +#endif +#endif +#elif LJ_TARGET_ARM +#if LJ_HASJIT + int ver = LJ_ARCH_VERSION; /* Compile-time ARM CPU detection. */ +#if LJ_TARGET_LINUX + if (ver < 70) { /* Runtime ARM CPU detection. */ + struct utsname ut; + uname(&ut); + if (strncmp(ut.machine, "armv", 4) == 0) { + if (ut.machine[4] >= '7') + ver = 70; + else if (ut.machine[4] == '6') + ver = 60; + } + } +#endif + flags |= ver >= 70 ? JIT_F_ARMV7 : + ver >= 61 ? JIT_F_ARMV6T2_ : + ver >= 60 ? JIT_F_ARMV6_ : 0; + flags |= LJ_ARCH_HASFPU == 0 ? 0 : ver >= 70 ? JIT_F_VFPV3 : JIT_F_VFPV2; +#endif +#elif LJ_TARGET_PPC +#if LJ_HASJIT +#if LJ_ARCH_SQRT + flags |= JIT_F_SQRT; +#endif +#if LJ_ARCH_ROUND + flags |= JIT_F_ROUND; +#endif +#endif +#elif LJ_TARGET_PPCSPE + /* Nothing to do. */ +#elif LJ_TARGET_MIPS +#if LJ_HASJIT + /* Compile-time MIPS CPU detection. */ +#if LJ_ARCH_VERSION >= 20 + flags |= JIT_F_MIPS32R2; +#endif + /* Runtime MIPS CPU detection. */ +#if defined(__GNUC__) + if (!(flags & JIT_F_MIPS32R2)) { + int x; + /* On MIPS32R1 rotr is treated as srl. rotr r2,r2,1 -> srl r2,r2,1. */ + __asm__("li $2, 1\n\t.long 0x00221042\n\tmove %0, $2" : "=r"(x) : : "$2"); + if (x) flags |= JIT_F_MIPS32R2; /* Either 0x80000000 (R2) or 0 (R1). */ + } +#endif +#endif +#else +#error "Missing CPU detection for this architecture" +#endif + UNUSED(L); + return flags; +} + +/* Initialize JIT compiler. */ +static void jit_init(lua_State *L) +{ + uint32_t flags = jit_cpudetect(L); +#if LJ_HASJIT + jit_State *J = L2J(L); +#if LJ_TARGET_X86 + /* Silently turn off the JIT compiler on CPUs without SSE2. */ + if ((flags & JIT_F_SSE2)) +#endif + J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; + memcpy(J->param, jit_param_default, sizeof(J->param)); + lj_dispatch_update(G(L)); +#else + UNUSED(flags); +#endif +} + +LUALIB_API int luaopen_jit(lua_State *L) +{ + lua_pushliteral(L, LJ_OS_NAME); + lua_pushliteral(L, LJ_ARCH_NAME); + lua_pushinteger(L, LUAJIT_VERSION_NUM); + lua_pushliteral(L, LUAJIT_VERSION); + LJ_LIB_REG(L, LUA_JITLIBNAME, jit); +#ifndef LUAJIT_DISABLE_JITUTIL + LJ_LIB_REG(L, "jit.util", jit_util); +#endif +#if LJ_HASJIT + LJ_LIB_REG(L, "jit.opt", jit_opt); +#endif + L->top -= 2; + jit_init(L); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_math.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_math.c new file mode 100644 index 0000000..3aa5c6b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_math.c @@ -0,0 +1,233 @@ +/* +** Math library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lib_math_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_lib.h" +#include "lj_vm.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_math + +LJLIB_ASM(math_abs) LJLIB_REC(.) +{ + lj_lib_checknumber(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(math_floor) LJLIB_REC(math_round IRFPM_FLOOR) +LJLIB_ASM_(math_ceil) LJLIB_REC(math_round IRFPM_CEIL) + +LJLIB_ASM(math_sqrt) LJLIB_REC(math_unary IRFPM_SQRT) +{ + lj_lib_checknum(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(math_log10) LJLIB_REC(math_unary IRFPM_LOG10) +LJLIB_ASM_(math_exp) LJLIB_REC(math_unary IRFPM_EXP) +LJLIB_ASM_(math_sin) LJLIB_REC(math_unary IRFPM_SIN) +LJLIB_ASM_(math_cos) LJLIB_REC(math_unary IRFPM_COS) +LJLIB_ASM_(math_tan) LJLIB_REC(math_unary IRFPM_TAN) +LJLIB_ASM_(math_asin) LJLIB_REC(math_atrig FF_math_asin) +LJLIB_ASM_(math_acos) LJLIB_REC(math_atrig FF_math_acos) +LJLIB_ASM_(math_atan) LJLIB_REC(math_atrig FF_math_atan) +LJLIB_ASM_(math_sinh) LJLIB_REC(math_htrig IRCALL_sinh) +LJLIB_ASM_(math_cosh) LJLIB_REC(math_htrig IRCALL_cosh) +LJLIB_ASM_(math_tanh) LJLIB_REC(math_htrig IRCALL_tanh) +LJLIB_ASM_(math_frexp) +LJLIB_ASM_(math_modf) LJLIB_REC(.) + +LJLIB_PUSH(57.29577951308232) +LJLIB_ASM_(math_deg) LJLIB_REC(math_degrad) + +LJLIB_PUSH(0.017453292519943295) +LJLIB_ASM_(math_rad) LJLIB_REC(math_degrad) + +LJLIB_ASM(math_log) LJLIB_REC(math_log) +{ + double x = lj_lib_checknum(L, 1); + if (L->base+1 < L->top) { + double y = lj_lib_checknum(L, 2); +#ifdef LUAJIT_NO_LOG2 + x = log(x); y = 1.0 / log(y); +#else + x = lj_vm_log2(x); y = 1.0 / lj_vm_log2(y); +#endif + setnumV(L->base-1, x*y); /* Do NOT join the expression to x / y. */ + return FFH_RES(1); + } + return FFH_RETRY; +} + +LJLIB_ASM(math_atan2) LJLIB_REC(.) +{ + lj_lib_checknum(L, 1); + lj_lib_checknum(L, 2); + return FFH_RETRY; +} +LJLIB_ASM_(math_pow) LJLIB_REC(.) +LJLIB_ASM_(math_fmod) + +LJLIB_ASM(math_ldexp) LJLIB_REC(.) +{ + lj_lib_checknum(L, 1); +#if LJ_DUALNUM && !LJ_TARGET_X86ORX64 + lj_lib_checkint(L, 2); +#else + lj_lib_checknum(L, 2); +#endif + return FFH_RETRY; +} + +LJLIB_ASM(math_min) LJLIB_REC(math_minmax IR_MIN) +{ + int i = 0; + do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top); + return FFH_RETRY; +} +LJLIB_ASM_(math_max) LJLIB_REC(math_minmax IR_MAX) + +LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) +LJLIB_PUSH(1e310) LJLIB_SET(huge) + +/* ------------------------------------------------------------------------ */ + +/* This implements a Tausworthe PRNG with period 2^223. Based on: +** Tables of maximally-equidistributed combined LFSR generators, +** Pierre L'Ecuyer, 1991, table 3, 1st entry. +** Full-period ME-CF generator with L=64, J=4, k=223, N1=49. +*/ + +/* PRNG state. */ +struct RandomState { + uint64_t gen[4]; /* State of the 4 LFSR generators. */ + int valid; /* State is valid. */ +}; + +/* Union needed for bit-pattern conversion between uint64_t and double. */ +typedef union { uint64_t u64; double d; } U64double; + +/* Update generator i and compute a running xor of all states. */ +#define TW223_GEN(i, k, q, s) \ + z = rs->gen[i]; \ + z = (((z<> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<gen[i] = z; + +/* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */ +LJ_NOINLINE uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs) +{ + uint64_t z, r = 0; + TW223_GEN(0, 63, 31, 18) + TW223_GEN(1, 58, 19, 28) + TW223_GEN(2, 55, 24, 7) + TW223_GEN(3, 47, 21, 8) + return (r & U64x(000fffff,ffffffff)) | U64x(3ff00000,00000000); +} + +/* PRNG initialization function. */ +static void random_init(RandomState *rs, double d) +{ + uint32_t r = 0x11090601; /* 64-k[i] as four 8 bit constants. */ + int i; + for (i = 0; i < 4; i++) { + U64double u; + uint32_t m = 1u << (r&255); + r >>= 8; + u.d = d = d * 3.14159265358979323846 + 2.7182818284590452354; + if (u.u64 < m) u.u64 += m; /* Ensure k[i] MSB of gen[i] are non-zero. */ + rs->gen[i] = u.u64; + } + rs->valid = 1; + for (i = 0; i < 10; i++) + lj_math_random_step(rs); +} + +/* PRNG extract function. */ +LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */ +LJLIB_CF(math_random) LJLIB_REC(.) +{ + int n = (int)(L->top - L->base); + RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); + U64double u; + double d; + if (LJ_UNLIKELY(!rs->valid)) random_init(rs, 0.0); + u.u64 = lj_math_random_step(rs); + d = u.d - 1.0; + if (n > 0) { +#if LJ_DUALNUM + int isint = 1; + double r1; + lj_lib_checknumber(L, 1); + if (tvisint(L->base)) { + r1 = (lua_Number)intV(L->base); + } else { + isint = 0; + r1 = numV(L->base); + } +#else + double r1 = lj_lib_checknum(L, 1); +#endif + if (n == 1) { + d = lj_vm_floor(d*r1) + 1.0; /* d is an int in range [1, r1] */ + } else { +#if LJ_DUALNUM + double r2; + lj_lib_checknumber(L, 2); + if (tvisint(L->base+1)) { + r2 = (lua_Number)intV(L->base+1); + } else { + isint = 0; + r2 = numV(L->base+1); + } +#else + double r2 = lj_lib_checknum(L, 2); +#endif + d = lj_vm_floor(d*(r2-r1+1.0)) + r1; /* d is an int in range [r1, r2] */ + } +#if LJ_DUALNUM + if (isint) { + setintV(L->top-1, lj_num2int(d)); + return 1; + } +#endif + } /* else: d is a double in range [0, 1] */ + setnumV(L->top++, d); + return 1; +} + +/* PRNG seed function. */ +LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */ +LJLIB_CF(math_randomseed) +{ + RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); + random_init(rs, lj_lib_checknum(L, 1)); + return 0; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_math(lua_State *L) +{ + RandomState *rs; + rs = (RandomState *)lua_newuserdata(L, sizeof(RandomState)); + rs->valid = 0; /* Use lazy initialization to save some time on startup. */ + LJ_LIB_REG(L, LUA_MATHLIBNAME, math); +#if defined(LUA_COMPAT_MOD) && !LJ_52 + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_os.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_os.c new file mode 100644 index 0000000..f62e8c8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_os.c @@ -0,0 +1,280 @@ +/* +** OS library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define lib_os_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_lib.h" + +#if LJ_TARGET_POSIX +#include +#else +#include +#endif + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_os + +LJLIB_CF(os_execute) +{ +#if LJ_TARGET_CONSOLE +#if LJ_52 + errno = ENOSYS; + return luaL_fileresult(L, 0, NULL); +#else + lua_pushinteger(L, -1); + return 1; +#endif +#else + const char *cmd = luaL_optstring(L, 1, NULL); + int stat = system(cmd); +#if LJ_52 + if (cmd) + return luaL_execresult(L, stat); + setboolV(L->top++, 1); +#else + setintV(L->top++, stat); +#endif + return 1; +#endif +} + +LJLIB_CF(os_remove) +{ + const char *filename = luaL_checkstring(L, 1); + return luaL_fileresult(L, remove(filename) == 0, filename); +} + +LJLIB_CF(os_rename) +{ + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return luaL_fileresult(L, rename(fromname, toname) == 0, fromname); +} + +LJLIB_CF(os_tmpname) +{ +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 + lj_err_caller(L, LJ_ERR_OSUNIQF); + return 0; +#else +#if LJ_TARGET_POSIX + char buf[15+1]; + int fp; + strcpy(buf, "/tmp/lua_XXXXXX"); + fp = mkstemp(buf); + if (fp != -1) + close(fp); + else + lj_err_caller(L, LJ_ERR_OSUNIQF); +#else + char buf[L_tmpnam]; + if (tmpnam(buf) == NULL) + lj_err_caller(L, LJ_ERR_OSUNIQF); +#endif + lua_pushstring(L, buf); + return 1; +#endif +} + +LJLIB_CF(os_getenv) +{ +#if LJ_TARGET_CONSOLE + lua_pushnil(L); +#else + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ +#endif + return 1; +} + +LJLIB_CF(os_exit) +{ + int status; + if (L->base < L->top && tvisbool(L->base)) + status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE; + else + status = lj_lib_optint(L, 1, EXIT_SUCCESS); + if (L->base+1 < L->top && tvistruecond(L->base+1)) + lua_close(L); + exit(status); + return 0; /* Unreachable. */ +} + +LJLIB_CF(os_clock) +{ + setnumV(L->top++, ((lua_Number)clock())*(1.0/(lua_Number)CLOCKS_PER_SEC)); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void setfield(lua_State *L, const char *key, int value) +{ + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield(lua_State *L, const char *key, int value) +{ + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield(lua_State *L, const char *key) +{ + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + +static int getfield(lua_State *L, const char *key, int d) +{ + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) { + res = (int)lua_tointeger(L, -1); + } else { + if (d < 0) + lj_err_callerv(L, LJ_ERR_OSDATEF, key); + res = d; + } + lua_pop(L, 1); + return res; +} + +LJLIB_CF(os_date) +{ + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; +#if LJ_TARGET_POSIX + struct tm rtm; +#endif + if (*s == '!') { /* UTC? */ + s++; /* Skip '!' */ +#if LJ_TARGET_POSIX + stm = gmtime_r(&t, &rtm); +#else + stm = gmtime(&t); +#endif + } else { +#if LJ_TARGET_POSIX + stm = localtime_r(&t, &rtm); +#else + stm = localtime(&t); +#endif + } + if (stm == NULL) { /* Invalid date? */ + setnilV(L->top-1); + } else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') { /* No conversion specifier? */ + luaL_addchar(&b, *s); + } else { + size_t reslen; + char buff[200]; /* Should be big enough for any conversion result. */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + +LJLIB_CF(os_time) +{ + time_t t; + if (lua_isnoneornil(L, 1)) { /* called without args? */ + t = time(NULL); /* get current time */ + } else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + +LJLIB_CF(os_difftime) +{ + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, (lua_Number)0)))); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(os_setlocale) +{ + GCstr *s = lj_lib_optstr(L, 1); + const char *str = s ? strdata(s) : NULL; + int opt = lj_lib_checkopt(L, 2, 6, + "\5ctype\7numeric\4time\7collate\10monetary\1\377\3all"); + if (opt == 0) opt = LC_CTYPE; + else if (opt == 1) opt = LC_NUMERIC; + else if (opt == 2) opt = LC_TIME; + else if (opt == 3) opt = LC_COLLATE; + else if (opt == 4) opt = LC_MONETARY; + else if (opt == 6) opt = LC_ALL; + lua_pushstring(L, setlocale(opt, str)); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_os(lua_State *L) +{ + LJ_LIB_REG(L, LUA_OSLIBNAME, os); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_package.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_package.c new file mode 100644 index 0000000..e341039 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_package.c @@ -0,0 +1,602 @@ +/* +** Package library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_package_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +/* Error codes for ll_loadfunc. */ +#define PACKAGE_ERR_LIB 1 +#define PACKAGE_ERR_FUNC 2 +#define PACKAGE_ERR_LOAD 3 + +/* Redefined in platform specific part. */ +#define PACKAGE_LIB_FAIL "open" +#define setprogdir(L) ((void)0) + +/* Symbol name prefixes. */ +#define SYMPREFIX_CF "luaopen_%s" +#define SYMPREFIX_BC "luaJIT_BC_%s" + +#if LJ_TARGET_DLOPEN + +#include + +static void ll_unloadlib(void *lib) +{ + dlclose(lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL)); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ +#if defined(RTLD_DEFAULT) + if (lib == NULL) lib = RTLD_DEFAULT; +#elif LJ_TARGET_OSX || LJ_TARGET_BSD + if (lib == NULL) lib = (void *)(intptr_t)-2; +#endif + return (const char *)dlsym(lib, sym); +} + +#elif LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4 +#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2 +BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*); +#endif + +#undef setprogdir + +static void setprogdir(lua_State *L) +{ + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) { + luaL_error(L, "unable to get ModuleFileName"); + } else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + +static void pusherror(lua_State *L) +{ + DWORD error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib(void *lib) +{ + FreeLibrary((HINSTANCE)lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + UNUSED(gl); + return lib; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ + if (lib) { + return (const char *)GetProcAddress((HINSTANCE)lib, sym); + } else { + HINSTANCE h = GetModuleHandleA(NULL); + const char *p = (const char *)GetProcAddress(h, sym); + if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)ll_bcsym, &h)) + p = (const char *)GetProcAddress(h, sym); + return p; + } +} + +#else + +#undef PACKAGE_LIB_FAIL +#define PACKAGE_LIB_FAIL "absent" + +#define DLMSG "dynamic libraries not enabled; no support for target OS" + +static void ll_unloadlib(void *lib) +{ + UNUSED(lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + UNUSED(path); UNUSED(gl); + lua_pushliteral(L, DLMSG); + return NULL; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + UNUSED(lib); UNUSED(sym); + lua_pushliteral(L, DLMSG); + return NULL; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ + UNUSED(lib); UNUSED(sym); + return NULL; +} + +#endif + +/* ------------------------------------------------------------------------ */ + +static void **ll_register(lua_State *L, const char *path) +{ + void **plib; + lua_pushfstring(L, "LOADLIB: %s", path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) { /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + } else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "LOADLIB: %s", path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + +static const char *mksymname(lua_State *L, const char *modname, + const char *prefix) +{ + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", "_"); + funcname = lua_pushfstring(L, prefix, funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + +static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) +{ + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path, (*name == '*')); + if (*reg == NULL) { + return PACKAGE_ERR_LIB; /* Unable to load library. */ + } else if (*name == '*') { /* Only load library into global namespace. */ + lua_pushboolean(L, 1); + return 0; + } else { + const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF); + lua_CFunction f = ll_sym(L, *reg, sym); + if (f) { + lua_pushcfunction(L, f); + return 0; + } + if (!r) { + const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); + lua_pop(L, 1); + if (bcdata) { + if (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) + return PACKAGE_ERR_LOAD; + return 0; + } + } + return PACKAGE_ERR_FUNC; /* Unable to find function. */ + } +} + +static int lj_cf_package_loadlib(lua_State *L) +{ + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int st = ll_loadfunc(L, path, init, 1); + if (st == 0) { /* no errors? */ + return 1; /* return the loaded function */ + } else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (st == PACKAGE_ERR_LIB) ? PACKAGE_LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + +static int lj_cf_package_unloadlib(lua_State *L) +{ + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int readable(const char *filename) +{ + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + +static const char *pushnexttemplate(lua_State *L, const char *path) +{ + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, (size_t)(l - path)); /* template */ + return l; +} + +static const char *searchpath (lua_State *L, const char *name, + const char *path, const char *sep, + const char *dirsep) +{ + luaL_Buffer msg; /* to build error message */ + luaL_buffinit(L, &msg); + if (*sep != '\0') /* non-empty separator? */ + name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename = luaL_gsub(L, lua_tostring(L, -1), + LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + luaL_addvalue(&msg); /* concatenate error msg. entry */ + } + luaL_pushresult(&msg); /* create error message */ + return NULL; /* not found */ +} + +static int lj_cf_package_searchpath(lua_State *L) +{ + const char *f = searchpath(L, luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_optstring(L, 3, "."), + luaL_optstring(L, 4, LUA_DIRSEP)); + if (f != NULL) { + return 1; + } else { /* error message is on top of the stack */ + lua_pushnil(L); + lua_insert(L, -2); + return 2; /* return nil + error message */ + } +} + +static const char *findfile(lua_State *L, const char *name, + const char *pname) +{ + const char *path; + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + return searchpath(L, name, path, ".", LUA_DIRSEP); +} + +static void loaderror(lua_State *L, const char *filename) +{ + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + +static int lj_cf_package_loader_lua(lua_State *L) +{ + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + +static int lj_cf_package_loader_c(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + if (ll_loadfunc(L, filename, name, 0) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + +static int lj_cf_package_loader_croot(lua_State *L) +{ + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int st; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, (size_t)(p - name)); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + if ((st = ll_loadfunc(L, filename, name, 0)) != 0) { + if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + +static int lj_cf_package_loader_preload(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) { /* Not found? */ + const char *bcname = mksymname(L, name, SYMPREFIX_BC); + const char *bcdata = ll_bcsym(NULL, bcname); + if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + } + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + +static int lj_cf_package_require(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i = 1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + lj_lib_checkfpu(L); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void setfenv(lua_State *L) +{ + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + +static void dooptions(lua_State *L, int n) +{ + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + +static void modinit(lua_State *L, const char *modname) +{ + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, (size_t)(dot - modname)); + lua_setfield(L, -2, "_PACKAGE"); +} + +static int lj_cf_package_module(lua_State *L) +{ + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) { /* is table an initialized module? */ + lua_pop(L, 1); + } else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + +static int lj_cf_package_seeall(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + +/* ------------------------------------------------------------------------ */ + +#define AUXMARK "\1" + +static void setpath(lua_State *L, const char *fieldname, const char *envname, + const char *def, int noenv) +{ +#if LJ_TARGET_CONSOLE + const char *path = NULL; + UNUSED(envname); +#else + const char *path = getenv(envname); +#endif + if (path == NULL || noenv) { + lua_pushstring(L, def); + } else { + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + +static const luaL_Reg package_lib[] = { + { "loadlib", lj_cf_package_loadlib }, + { "searchpath", lj_cf_package_searchpath }, + { "seeall", lj_cf_package_seeall }, + { NULL, NULL } +}; + +static const luaL_Reg package_global[] = { + { "module", lj_cf_package_module }, + { "require", lj_cf_package_require }, + { NULL, NULL } +}; + +static const lua_CFunction package_loaders[] = +{ + lj_cf_package_loader_preload, + lj_cf_package_loader_lua, + lj_cf_package_loader_c, + lj_cf_package_loader_croot, + NULL +}; + +LUALIB_API int luaopen_package(lua_State *L) +{ + int i; + int noenv; + luaL_newmetatable(L, "_LOADLIB"); + lj_lib_pushcf(L, lj_cf_package_unloadlib, 1); + lua_setfield(L, -2, "__gc"); + luaL_register(L, LUA_LOADLIBNAME, package_lib); + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0); + for (i = 0; package_loaders[i] != NULL; i++) { + lj_lib_pushcf(L, package_loaders[i], 1); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); + noenv = lua_toboolean(L, -1); + lua_pop(L, 1); + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv); + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv); + lua_pushliteral(L, LUA_PATH_CONFIG); + lua_setfield(L, -2, "config"); + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_setfield(L, -2, "loaded"); + luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, package_global); + lua_pop(L, 1); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_string.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_string.c new file mode 100644 index 0000000..9ec6d0c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lib_string.c @@ -0,0 +1,940 @@ +/* +** String library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lib_string_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_ff.h" +#include "lj_bcdump.h" +#include "lj_char.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_string + +LJLIB_ASM(string_len) LJLIB_REC(.) +{ + lj_lib_checkstr(L, 1); + return FFH_RETRY; +} + +LJLIB_ASM(string_byte) LJLIB_REC(string_range 0) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int32_t len = (int32_t)s->len; + int32_t start = lj_lib_optint(L, 2, 1); + int32_t stop = lj_lib_optint(L, 3, start); + int32_t n, i; + const unsigned char *p; + if (stop < 0) stop += len+1; + if (start < 0) start += len+1; + if (start <= 0) start = 1; + if (stop > len) stop = len; + if (start > stop) return FFH_RES(0); /* Empty interval: return no results. */ + start--; + n = stop - start; + if ((uint32_t)n > LUAI_MAXCSTACK) + lj_err_caller(L, LJ_ERR_STRSLC); + lj_state_checkstack(L, (MSize)n); + p = (const unsigned char *)strdata(s) + start; + for (i = 0; i < n; i++) + setintV(L->base + i-1, p[i]); + return FFH_RES(n); +} + +LJLIB_ASM(string_char) +{ + int i, nargs = (int)(L->top - L->base); + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, (MSize)nargs); + for (i = 1; i <= nargs; i++) { + int32_t k = lj_lib_checkint(L, i); + if (!checku8(k)) + lj_err_arg(L, i, LJ_ERR_BADVAL); + buf[i-1] = (char)k; + } + setstrV(L, L->base-1, lj_str_new(L, buf, (size_t)nargs)); + return FFH_RES(1); +} + +LJLIB_ASM(string_sub) LJLIB_REC(string_range 1) +{ + lj_lib_checkstr(L, 1); + lj_lib_checkint(L, 2); + setintV(L->base+2, lj_lib_optint(L, 3, -1)); + return FFH_RETRY; +} + +LJLIB_ASM(string_rep) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int32_t k = lj_lib_checkint(L, 2); + GCstr *sep = lj_lib_optstr(L, 3); + int32_t len = (int32_t)s->len; + global_State *g = G(L); + int64_t tlen; + const char *src; + char *buf; + if (k <= 0) { + empty: + setstrV(L, L->base-1, &g->strempty); + return FFH_RES(1); + } + if (sep) { + tlen = (int64_t)len + sep->len; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + tlen *= k; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + } else { + tlen = (int64_t)k * len; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + } + if (tlen == 0) goto empty; + buf = lj_str_needbuf(L, &g->tmpbuf, (MSize)tlen); + src = strdata(s); + if (sep) { + tlen -= sep->len; /* Ignore trailing separator. */ + if (k > 1) { /* Paste one string and one separator. */ + int32_t i; + i = 0; while (i < len) *buf++ = src[i++]; + src = strdata(sep); len = sep->len; + i = 0; while (i < len) *buf++ = src[i++]; + src = g->tmpbuf.buf; len += s->len; k--; /* Now copy that k-1 times. */ + } + } + do { + int32_t i = 0; + do { *buf++ = src[i++]; } while (i < len); + } while (--k > 0); + setstrV(L, L->base-1, lj_str_new(L, g->tmpbuf.buf, (size_t)tlen)); + return FFH_RES(1); +} + +LJLIB_ASM(string_reverse) +{ + GCstr *s = lj_lib_checkstr(L, 1); + lj_str_needbuf(L, &G(L)->tmpbuf, s->len); + return FFH_RETRY; +} +LJLIB_ASM_(string_lower) +LJLIB_ASM_(string_upper) + +/* ------------------------------------------------------------------------ */ + +static int writer_buf(lua_State *L, const void *p, size_t size, void *b) +{ + luaL_addlstring((luaL_Buffer *)b, (const char *)p, size); + UNUSED(L); + return 0; +} + +LJLIB_CF(string_dump) +{ + GCfunc *fn = lj_lib_checkfunc(L, 1); + int strip = L->base+1 < L->top && tvistruecond(L->base+1); + luaL_Buffer b; + L->top = L->base+1; + luaL_buffinit(L, &b); + if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, &b, strip)) + lj_err_caller(L, LJ_ERR_STRDUMP); + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + +#define CAP_UNFINISHED (-1) +#define CAP_POSITION (-2) + +typedef struct MatchState { + const char *src_init; /* init of source string */ + const char *src_end; /* end (`\0') of source string */ + lua_State *L; + int level; /* total number of captures (finished or unfinished) */ + int depth; + struct { + const char *init; + ptrdiff_t len; + } capture[LUA_MAXCAPTURES]; +} MatchState; + +#define L_ESC '%' +#define SPECIALS "^$*+?.([%-" + +static int check_capture(MatchState *ms, int l) +{ + l -= '1'; + if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) + lj_err_caller(ms->L, LJ_ERR_STRCAPI); + return l; +} + +static int capture_to_close(MatchState *ms) +{ + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + lj_err_caller(ms->L, LJ_ERR_STRPATC); + return 0; /* unreachable */ +} + +static const char *classend(MatchState *ms, const char *p) +{ + switch (*p++) { + case L_ESC: + if (*p == '\0') + lj_err_caller(ms->L, LJ_ERR_STRPATE); + return p+1; + case '[': + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + lj_err_caller(ms->L, LJ_ERR_STRPATM); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + default: + return p; + } +} + +static const unsigned char match_class_map[32] = { + 0,LJ_CHAR_ALPHA,0,LJ_CHAR_CNTRL,LJ_CHAR_DIGIT,0,0,LJ_CHAR_GRAPH,0,0,0,0, + LJ_CHAR_LOWER,0,0,0,LJ_CHAR_PUNCT,0,0,LJ_CHAR_SPACE,0, + LJ_CHAR_UPPER,0,LJ_CHAR_ALNUM,LJ_CHAR_XDIGIT,0,0,0,0,0,0,0 +}; + +static int match_class(int c, int cl) +{ + if ((cl & 0xc0) == 0x40) { + int t = match_class_map[(cl&0x1f)]; + if (t) { + t = lj_char_isa(c, t); + return (cl & 0x20) ? t : !t; + } + if (cl == 'z') return c == 0; + if (cl == 'Z') return c != 0; + } + return (cl == c); +} + +static int matchbracketclass(int c, const char *p, const char *ec) +{ + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + +static int singlematch(int c, const char *p, const char *ep) +{ + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + +static const char *match(MatchState *ms, const char *s, const char *p); + +static const char *matchbalance(MatchState *ms, const char *s, const char *p) +{ + if (*p == 0 || *(p+1) == 0) + lj_err_caller(ms->L, LJ_ERR_STRPATU); + if (*s != *p) { + return NULL; + } else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } else if (*s == b) { + cont++; + } + } + } + return NULL; /* string ends out of balance */ +} + +static const char *max_expand(MatchState *ms, const char *s, + const char *p, const char *ep) +{ + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + +static const char *min_expand(MatchState *ms, const char *s, + const char *p, const char *ep) +{ + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else + return NULL; + } +} + +static const char *start_capture(MatchState *ms, const char *s, + const char *p, int what) +{ + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) lj_err_caller(ms->L, LJ_ERR_STRCAPN); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + +static const char *end_capture(MatchState *ms, const char *s, + const char *p) +{ + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + +static const char *match_capture(MatchState *ms, const char *s, int l) +{ + size_t len; + l = check_capture(ms, l); + len = (size_t)ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else + return NULL; +} + +static const char *match(MatchState *ms, const char *s, const char *p) +{ + if (++ms->depth > LJ_MAX_XLEVEL) + lj_err_caller(ms->L, LJ_ERR_STRPATX); + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': /* start capture */ + if (*(p+1) == ')') /* position capture? */ + s = start_capture(ms, s, p+2, CAP_POSITION); + else + s = start_capture(ms, s, p+1, CAP_UNFINISHED); + break; + case ')': /* end capture */ + s = end_capture(ms, s, p+1); + break; + case L_ESC: + switch (*(p+1)) { + case 'b': /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) break; + p+=4; + goto init; /* else s = match(ms, s, p+4); */ + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + lj_err_caller(ms->L, LJ_ERR_STRPATB); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) { s = NULL; break; } + p=ep; + goto init; /* else s = match(ms, s, ep); */ + } + default: + if (lj_char_isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) break; + p+=2; + goto init; /* else s = match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + break; + case '\0': /* end of pattern */ + break; /* match succeeded */ + case '$': + /* is the `$' the last char in pattern? */ + if (*(p+1) != '\0') goto dflt; + if (s != ms->src_end) s = NULL; /* check end of string */ + break; + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) { + s = res; + break; + } + p=ep+1; + goto init; /* else s = match(ms, s, ep+1); */ + } + case '*': /* 0 or more repetitions */ + s = max_expand(ms, s, p, ep); + break; + case '+': /* 1 or more repetitions */ + s = (m ? max_expand(ms, s+1, p, ep) : NULL); + break; + case '-': /* 0 or more repetitions (minimum) */ + s = min_expand(ms, s, p, ep); + break; + default: + if (m) { s++; p=ep; goto init; } /* else s = match(ms, s+1, ep); */ + s = NULL; + break; + } + break; + } + } + ms->depth--; + return s; +} + +static const char *lmemfind(const char *s1, size_t l1, + const char *s2, size_t l2) +{ + if (l2 == 0) { + return s1; /* empty strings are everywhere */ + } else if (l2 > l1) { + return NULL; /* avoids a negative `l1' */ + } else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) { + return init-1; + } else { /* correct `l1' and `s1' to try again */ + l1 -= (size_t)(init-s1); + s1 = init; + } + } + return NULL; /* not found */ + } +} + +static void push_onecapture(MatchState *ms, int i, const char *s, const char *e) +{ + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, (size_t)(e - s)); /* add whole match */ + else + lj_err_caller(ms->L, LJ_ERR_STRCAPI); + } else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) lj_err_caller(ms->L, LJ_ERR_STRCAPU); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, (size_t)l); + } +} + +static int push_captures(MatchState *ms, const char *s, const char *e) +{ + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + +static ptrdiff_t posrelat(ptrdiff_t pos, size_t len) +{ + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + +static int str_find_aux(lua_State *L, int find) +{ + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) { + init = 0; + } else if ((size_t)(init) > l1) { +#if LJ_52 + setnilV(L->top-1); + return 1; +#else + init = (ptrdiff_t)l1; +#endif + } + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-(size_t)init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+(ptrdiff_t)l2); + return 2; + } + } else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = ms.depth = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } else { + return push_captures(&ms, s1, res); + } + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + +LJLIB_CF(string_find) +{ + return str_find_aux(L, 1); +} + +LJLIB_CF(string_match) +{ + return str_find_aux(L, 0); +} + +LJLIB_NOREG LJLIB_CF(string_gmatch_aux) +{ + const char *p = strVdata(lj_lib_upvalue(L, 2)); + GCstr *str = strV(lj_lib_upvalue(L, 1)); + const char *s = strdata(str); + TValue *tvpos = lj_lib_upvalue(L, 3); + const char *src = s + tvpos->u32.lo; + MatchState ms; + ms.L = L; + ms.src_init = s; + ms.src_end = s + str->len; + for (; src <= ms.src_end; src++) { + const char *e; + ms.level = ms.depth = 0; + if ((e = match(&ms, src, p)) != NULL) { + int32_t pos = (int32_t)(e - s); + if (e == src) pos++; /* Ensure progress for empty match. */ + tvpos->u32.lo = (uint32_t)pos; + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + +LJLIB_CF(string_gmatch) +{ + lj_lib_checkstr(L, 1); + lj_lib_checkstr(L, 2); + L->top = L->base+3; + (L->top-1)->u64 = 0; + lj_lib_pushcc(L, lj_cf_string_gmatch_aux, FF_string_gmatch_aux, 3); + return 1; +} + +static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e) +{ + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) { + luaL_addchar(b, news[i]); + } else { + i++; /* skip ESC */ + if (!lj_char_isdigit(uchar(news[i]))) { + luaL_addchar(b, news[i]); + } else if (news[i] == '0') { + luaL_addlstring(b, s, (size_t)(e - s)); + } else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + +static void add_value(MatchState *ms, luaL_Buffer *b, + const char *s, const char *e) +{ + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, (size_t)(e - s)); /* keep original text */ + } else if (!lua_isstring(L, -1)) { + lj_err_callerv(L, LJ_ERR_STRGSRV, luaL_typename(L, -1)); + } + luaL_addvalue(b); /* add result to accumulator */ +} + +LJLIB_CF(string_gsub) +{ + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, (int)(srcl+1)); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + if (!(tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE)) + lj_err_arg(L, 3, LJ_ERR_NOSFT); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = ms.depth = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else + break; + if (anchor) + break; + } + luaL_addlstring(&b, src, (size_t)(ms.src_end-src)); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* ------------------------------------------------------------------------ */ + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_FMTITEM 512 +/* valid flags in a format specification */ +#define FMT_FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FMTSPEC (sizeof(FMT_FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + +static void addquoted(lua_State *L, luaL_Buffer *b, int arg) +{ + GCstr *str = lj_lib_checkstr(L, arg); + int32_t len = (int32_t)str->len; + const char *s = strdata(str); + luaL_addchar(b, '"'); + while (len--) { + uint32_t c = uchar(*s); + if (c == '"' || c == '\\' || c == '\n') { + luaL_addchar(b, '\\'); + } else if (lj_char_iscntrl(c)) { /* This can only be 0-31 or 127. */ + uint32_t d; + luaL_addchar(b, '\\'); + if (c >= 100 || lj_char_isdigit(uchar(s[1]))) { + luaL_addchar(b, '0'+(c >= 100)); if (c >= 100) c -= 100; + goto tens; + } else if (c >= 10) { + tens: + d = (c * 205) >> 11; c -= d * 10; luaL_addchar(b, '0'+d); + } + c += '0'; + } + luaL_addchar(b, c); + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat(lua_State *L, const char *strfrmt, char *form) +{ + const char *p = strfrmt; + while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS)) + lj_err_caller(L, LJ_ERR_STRFMTR); + if (lj_char_isdigit(uchar(*p))) p++; /* skip width */ + if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (lj_char_isdigit(uchar(*p))) p++; /* skip precision */ + if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (lj_char_isdigit(uchar(*p))) + lj_err_caller(L, LJ_ERR_STRFMTW); + *(form++) = '%'; + strncpy(form, strfrmt, (size_t)(p - strfrmt + 1)); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + +static void addintlen(char *form) +{ + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + +static unsigned LUA_INTFRM_T num2intfrm(lua_State *L, int arg) +{ + if (sizeof(LUA_INTFRM_T) == 4) { + return (LUA_INTFRM_T)lj_lib_checkbit(L, arg); + } else { + cTValue *o; + lj_lib_checknumber(L, arg); + o = L->base+arg-1; + if (tvisint(o)) + return (LUA_INTFRM_T)intV(o); + else + return (LUA_INTFRM_T)numV(o); + } +} + +static unsigned LUA_INTFRM_T num2uintfrm(lua_State *L, int arg) +{ + if (sizeof(LUA_INTFRM_T) == 4) { + return (unsigned LUA_INTFRM_T)lj_lib_checkbit(L, arg); + } else { + cTValue *o; + lj_lib_checknumber(L, arg); + o = L->base+arg-1; + if (tvisint(o)) + return (unsigned LUA_INTFRM_T)intV(o); + else if ((int32_t)o->u32.hi < 0) + return (unsigned LUA_INTFRM_T)(LUA_INTFRM_T)numV(o); + else + return (unsigned LUA_INTFRM_T)numV(o); + } +} + +static GCstr *meta_tostring(lua_State *L, int arg) +{ + TValue *o = L->base+arg-1; + cTValue *mo; + lua_assert(o < L->top); /* Caller already checks for existence. */ + if (LJ_LIKELY(tvisstr(o))) + return strV(o); + if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { + copyTV(L, L->top++, mo); + copyTV(L, L->top++, o); + lua_call(L, 1, 1); + L->top--; + if (tvisstr(L->top)) + return strV(L->top); + o = L->base+arg-1; + copyTV(L, o, L->top); + } + if (tvisnumber(o)) { + return lj_str_fromnumber(L, o); + } else if (tvisnil(o)) { + return lj_str_newlit(L, "nil"); + } else if (tvisfalse(o)) { + return lj_str_newlit(L, "false"); + } else if (tvistrue(o)) { + return lj_str_newlit(L, "true"); + } else { + if (tvisfunc(o) && isffunc(funcV(o))) + lj_str_pushf(L, "function: builtin#%d", funcV(o)->c.ffid); + else + lj_str_pushf(L, "%s: %p", lj_typename(o), lua_topointer(L, arg)); + L->top--; + return strV(L->top); + } +} + +LJLIB_CF(string_format) +{ + int arg = 1, top = (int)(L->top - L->base); + GCstr *fmt = lj_lib_checkstr(L, arg); + const char *strfrmt = strdata(fmt); + const char *strfrmt_end = strfrmt + fmt->len; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) { + luaL_addchar(&b, *strfrmt++); + } else if (*++strfrmt == L_ESC) { + luaL_addchar(&b, *strfrmt++); /* %% */ + } else { /* format item */ + char form[MAX_FMTSPEC]; /* to store the format (`%...') */ + char buff[MAX_FMTITEM]; /* to store the formatted item */ + if (++arg > top) + luaL_argerror(L, arg, lj_obj_typename[0]); + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': + sprintf(buff, form, lj_lib_checkint(L, arg)); + break; + case 'd': case 'i': + addintlen(form); + sprintf(buff, form, num2intfrm(L, arg)); + break; + case 'o': case 'u': case 'x': case 'X': + addintlen(form); + sprintf(buff, form, num2uintfrm(L, arg)); + break; + case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A': { + TValue tv; + tv.n = lj_lib_checknum(L, arg); + if (LJ_UNLIKELY((tv.u32.hi << 1) >= 0xffe00000)) { + /* Canonicalize output of non-finite values. */ + char *p, nbuf[LJ_STR_NUMBUF]; + size_t len = lj_str_bufnum(nbuf, &tv); + if (strfrmt[-1] < 'a') { + nbuf[len-3] = nbuf[len-3] - 0x20; + nbuf[len-2] = nbuf[len-2] - 0x20; + nbuf[len-1] = nbuf[len-1] - 0x20; + } + nbuf[len] = '\0'; + for (p = form; *p < 'A' && *p != '.'; p++) ; + *p++ = 's'; *p = '\0'; + sprintf(buff, form, nbuf); + break; + } + sprintf(buff, form, (double)tv.n); + break; + } + case 'q': + addquoted(L, &b, arg); + continue; + case 'p': + lj_str_pushf(L, "%p", lua_topointer(L, arg)); + luaL_addvalue(&b); + continue; + case 's': { + GCstr *str = meta_tostring(L, arg); + if (!strchr(form, '.') && str->len >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + setstrV(L, L->top++, str); + luaL_addvalue(&b); + continue; + } + sprintf(buff, form, strdata(str)); + break; + } + default: + lj_err_callerv(L, LJ_ERR_STRFMTO, *(strfrmt -1)); + break; + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_string(lua_State *L) +{ + GCtab *mt; + global_State *g; + LJ_LIB_REG(L, LUA_STRLIBNAME, string); +#if defined(LUA_COMPAT_GFIND) && !LJ_52 + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + mt = lj_tab_new(L, 0, 1); + /* NOBARRIER: basemt is a GC root. */ + g = G(L); + setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt)); + settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1)); + mt->nomm = (uint8_t)(~(1u<top, func); + setintV(L->top+1, i); + val = lj_tab_getint(t, (int32_t)i); + if (val) { copyTV(L, L->top+2, val); } else { setnilV(L->top+2); } + L->top += 3; + lua_call(L, 2, 1); + if (!tvisnil(L->top-1)) + return 1; + L->top--; + } + return 0; +} + +LJLIB_CF(table_foreach) +{ + GCtab *t = lj_lib_checktab(L, 1); + GCfunc *func = lj_lib_checkfunc(L, 2); + L->top = L->base+3; + setnilV(L->top-1); + while (lj_tab_next(L, t, L->top-1)) { + copyTV(L, L->top+2, L->top); + copyTV(L, L->top+1, L->top-1); + setfuncV(L, L->top, func); + L->top += 3; + lua_call(L, 2, 1); + if (!tvisnil(L->top-1)) + return 1; + L->top--; + } + return 0; +} + +LJLIB_ASM(table_getn) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + return FFH_UNREACHABLE; +} + +LJLIB_CF(table_maxn) +{ + GCtab *t = lj_lib_checktab(L, 1); + TValue *array = tvref(t->array); + Node *node; + lua_Number m = 0; + ptrdiff_t i; + for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--) + if (!tvisnil(&array[i])) { + m = (lua_Number)(int32_t)i; + break; + } + node = noderef(t->node); + for (i = (ptrdiff_t)t->hmask; i >= 0; i--) + if (!tvisnil(&node[i].val) && tvisnumber(&node[i].key)) { + lua_Number n = numberVnum(&node[i].key); + if (n > m) m = n; + } + setnumV(L->top-1, m); + return 1; +} + +LJLIB_CF(table_insert) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t n, i = (int32_t)lj_tab_len(t) + 1; + int nargs = (int)((char *)L->top - (char *)L->base); + if (nargs != 2*sizeof(TValue)) { + if (nargs != 3*sizeof(TValue)) + lj_err_caller(L, LJ_ERR_TABINS); + /* NOBARRIER: This just moves existing elements around. */ + for (n = lj_lib_checkint(L, 2); i > n; i--) { + /* The set may invalidate the get pointer, so need to do it first! */ + TValue *dst = lj_tab_setint(L, t, i); + cTValue *src = lj_tab_getint(t, i-1); + if (src) { + copyTV(L, dst, src); + } else { + setnilV(dst); + } + } + i = n; + } + { + TValue *dst = lj_tab_setint(L, t, i); + copyTV(L, dst, L->top-1); /* Set new value. */ + lj_gc_barriert(L, t, dst); + } + return 0; +} + +LJLIB_CF(table_remove) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t e = (int32_t)lj_tab_len(t); + int32_t pos = lj_lib_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* Nothing to remove? */ + return 0; + lua_rawgeti(L, 1, pos); /* Get previous value. */ + /* NOBARRIER: This just moves existing elements around. */ + for (; pos < e; pos++) { + cTValue *src = lj_tab_getint(t, pos+1); + TValue *dst = lj_tab_setint(L, t, pos); + if (src) { + copyTV(L, dst, src); + } else { + setnilV(dst); + } + } + setnilV(lj_tab_setint(L, t, e)); /* Remove (last) value. */ + return 1; /* Return previous value. */ +} + +LJLIB_CF(table_concat) +{ + luaL_Buffer b; + GCtab *t = lj_lib_checktab(L, 1); + GCstr *sep = lj_lib_optstr(L, 2); + MSize seplen = sep ? sep->len : 0; + int32_t i = lj_lib_optint(L, 3, 1); + int32_t e = (L->base+3 < L->top && !tvisnil(L->base+3)) ? + lj_lib_checkint(L, 4) : (int32_t)lj_tab_len(t); + luaL_buffinit(L, &b); + if (i <= e) { + for (;;) { + cTValue *o; + lua_rawgeti(L, 1, i); + o = L->top-1; + if (!(tvisstr(o) || tvisnumber(o))) + lj_err_callerv(L, LJ_ERR_TABCAT, lj_typename(o), i); + luaL_addvalue(&b); + if (i++ == e) break; + if (seplen) + luaL_addlstring(&b, strdata(sep), seplen); + } + } + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void set2(lua_State *L, int i, int j) +{ + lua_rawseti(L, 1, i); + lua_rawseti(L, 1, j); +} + +static int sort_comp(lua_State *L, int a, int b) +{ + if (!lua_isnil(L, 2)) { /* function? */ + int res; + lua_pushvalue(L, 2); + lua_pushvalue(L, a-1); /* -1 to compensate function */ + lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */ + lua_call(L, 2, 1); + res = lua_toboolean(L, -1); + lua_pop(L, 1); + return res; + } else { /* a < b? */ + return lua_lessthan(L, a, b); + } +} + +static void auxsort(lua_State *L, int l, int u) +{ + while (l < u) { /* for tail recursion */ + int i, j; + /* sort elements a[l], a[(l+u)/2] and a[u] */ + lua_rawgeti(L, 1, l); + lua_rawgeti(L, 1, u); + if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */ + set2(L, l, u); /* swap a[l] - a[u] */ + else + lua_pop(L, 2); + if (u-l == 1) break; /* only 2 elements */ + i = (l+u)/2; + lua_rawgeti(L, 1, i); + lua_rawgeti(L, 1, l); + if (sort_comp(L, -2, -1)) { /* a[i]= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>=u) lj_err_caller(L, LJ_ERR_TABSORT); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j<=l) lj_err_caller(L, LJ_ERR_TABSORT); + lua_pop(L, 1); /* remove a[j] */ + } + if (jbase+1)) + lj_lib_checkfunc(L, 2); + auxsort(L, 1, n); + return 0; +} + +#if LJ_52 +LJLIB_PUSH("n") +LJLIB_CF(table_pack) +{ + TValue *array, *base = L->base; + MSize i, n = (uint32_t)(L->top - base); + GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1); + /* NOBARRIER: The table is new (marked white). */ + setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n); + for (array = tvref(t->array) + 1, i = 0; i < n; i++) + copyTV(L, &array[i], &base[i]); + settabV(L, base, t); + L->top = base+1; + lj_gc_check(L); + return 1; +} +#endif + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_table(lua_State *L) +{ + LJ_LIB_REG(L, LUA_TABLIBNAME, table); +#if LJ_52 + lua_getglobal(L, "unpack"); + lua_setfield(L, -2, "unpack"); +#endif + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/linit.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/linit.c new file mode 100644 index 0000000..483d9c8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/linit.c @@ -0,0 +1,38 @@ +/* +** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/liolib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/liolib.c new file mode 100644 index 0000000..bb3b519 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/liolib.c @@ -0,0 +1,532 @@ +/* +** $Id: liolib.c,v 2.72 2006/01/28 12:59:13 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define liolib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + + +static const char *const fnames[] = {"input", "output"}; + + +static int pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror (lua_State *L, int arg, const char *filename) { + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type (lua_State *L) { + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile (lua_State *L) { + FILE **f = topfile(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile (lua_State *L) { + FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_pclose (lua_State *L) { + FILE **p = topfile(L); + int ok = lua_pclose(L, *p); + if (ok) *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int io_fclose (lua_State *L) { + FILE **p = topfile(L); + int ok = (fclose(*p) == 0); + if (ok) *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close (lua_State *L) { + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1))(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc (lua_State *L) { + FILE *f = *topfile(L); + /* ignore closed files and standard files */ + if (f != NULL && f != stdin && f != stdout && f != stderr) + aux_close(L); + return 0; +} + + +static int io_tostring (lua_State *L) { + FILE *f = *topfile(L); + if (f == NULL) + lua_pushstring(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = lua_popen(L, filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, int findex) { + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **)lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile (lua_State *L, int f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +static void aux_lines (lua_State *L, int idx, int toclose) { + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } + else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number (lua_State *L, FILE *f) { + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } + else return 0; /* read fails */ +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f) { + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_strlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l-1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_strlen(L, -1) > 0); +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f); + break; + case 'a': /* file */ + read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + return g_write(L, tofile(L), 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_setfield(L, -2, fname); +} + + +LUALIB_API int luaopen_io (lua_State *L) { + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + lua_createtable(L, 2, 1); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + /* create environment for 'popen' */ + lua_getfield(L, -1, "popen"); + lua_createtable(L, 0, 1); + lua_pushcfunction(L, io_pclose); + lua_setfield(L, -2, "__close"); + lua_setfenv(L, -2); + lua_pop(L, 1); /* pop 'popen' */ + /* set default close function */ + lua_pushcfunction(L, io_fclose); + lua_setfield(L, LUA_ENVIRONINDEX, "__close"); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj.supp b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj.supp new file mode 100644 index 0000000..411f261 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj.supp @@ -0,0 +1,26 @@ +# Valgrind suppression file for LuaJIT 2.0. +{ + Optimized string compare + Memcheck:Addr4 + fun:lj_str_cmp +} +{ + Optimized string compare + Memcheck:Addr1 + fun:lj_str_cmp +} +{ + Optimized string compare + Memcheck:Addr4 + fun:lj_str_new +} +{ + Optimized string compare + Memcheck:Addr1 + fun:lj_str_new +} +{ + Optimized string compare + Memcheck:Cond + fun:lj_str_new +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.c new file mode 100644 index 0000000..f856a7a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.c @@ -0,0 +1,1390 @@ +/* +** Bundled memory allocator. +** +** Beware: this is a HEAVILY CUSTOMIZED version of dlmalloc. +** The original bears the following remark: +** +** This is a version (aka dlmalloc) of malloc/free/realloc written by +** Doug Lea and released to the public domain, as explained at +** http://creativecommons.org/licenses/publicdomain. +** +** * Version pre-2.8.4 Wed Mar 29 19:46:29 2006 (dl at gee) +** +** No additional copyright is claimed over the customizations. +** Please do NOT bother the original author about this version here! +** +** If you want to use dlmalloc in another project, you should get +** the original from: ftp://gee.cs.oswego.edu/pub/misc/ +** For thread-safe derivatives, take a look at: +** - ptmalloc: http://www.malloc.de/ +** - nedmalloc: http://www.nedprod.com/programs/portable/nedmalloc/ +*/ + +#define lj_alloc_c +#define LUA_CORE + +/* To get the mremap prototype. Must be defined before any system includes. */ +#if defined(__linux__) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + +#include "lj_def.h" +#include "lj_arch.h" +#include "lj_alloc.h" + +#ifndef LUAJIT_USE_SYSMALLOC + +#define MAX_SIZE_T (~(size_t)0) +#define MALLOC_ALIGNMENT ((size_t)8U) + +#define DEFAULT_GRANULARITY ((size_t)128U * (size_t)1024U) +#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) +#define DEFAULT_MMAP_THRESHOLD ((size_t)128U * (size_t)1024U) +#define MAX_RELEASE_CHECK_RATE 255 + +/* ------------------- size_t and alignment properties -------------------- */ + +/* The byte and bit size of a size_t */ +#define SIZE_T_SIZE (sizeof(size_t)) +#define SIZE_T_BITSIZE (sizeof(size_t) << 3) + +/* Some constants coerced to size_t */ +/* Annoying but necessary to avoid errors on some platforms */ +#define SIZE_T_ZERO ((size_t)0) +#define SIZE_T_ONE ((size_t)1) +#define SIZE_T_TWO ((size_t)2) +#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) +#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) +#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) + +/* The bit mask value corresponding to MALLOC_ALIGNMENT */ +#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) + +/* the number of bytes to offset an address to align it */ +#define align_offset(A)\ + ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ + ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) + +/* -------------------------- MMAP support ------------------------------- */ + +#define MFAIL ((void *)(MAX_SIZE_T)) +#define CMFAIL ((char *)(MFAIL)) /* defined for convenience */ + +#define IS_DIRECT_BIT (SIZE_T_ONE) + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#if LJ_64 + +/* Undocumented, but hey, that's what we all love so much about Windows. */ +typedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits, + size_t *size, ULONG alloctype, ULONG prot); +static PNTAVM ntavm; + +/* Number of top bits of the lower 32 bits of an address that must be zero. +** Apparently 0 gives us full 64 bit addresses and 1 gives us the lower 2GB. +*/ +#define NTAVM_ZEROBITS 1 + +static void INIT_MMAP(void) +{ + ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA("ntdll.dll"), + "NtAllocateVirtualMemory"); +} + +/* Win64 32 bit MMAP via NtAllocateVirtualMemory. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = NULL; + long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size, + MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + SetLastError(olderr); + return st == 0 ? ptr : MFAIL; +} + +/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ +static LJ_AINLINE void *DIRECT_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = NULL; + long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size, + MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE); + SetLastError(olderr); + return st == 0 ? ptr : MFAIL; +} + +#else + +#define INIT_MMAP() ((void)0) + +/* Win32 MMAP via VirtualAlloc */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + SetLastError(olderr); + return ptr ? ptr : MFAIL; +} + +/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ +static LJ_AINLINE void *DIRECT_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, + PAGE_READWRITE); + SetLastError(olderr); + return ptr ? ptr : MFAIL; +} + +#endif + +/* This function supports releasing coalesed segments */ +static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size) +{ + DWORD olderr = GetLastError(); + MEMORY_BASIC_INFORMATION minfo; + char *cptr = (char *)ptr; + while (size) { + if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) + return -1; + if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || + minfo.State != MEM_COMMIT || minfo.RegionSize > size) + return -1; + if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) + return -1; + cptr += minfo.RegionSize; + size -= minfo.RegionSize; + } + SetLastError(olderr); + return 0; +} + +#else + +#include +#include + +#define MMAP_PROT (PROT_READ|PROT_WRITE) +#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) +#define MAP_ANONYMOUS MAP_ANON +#endif +#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) + +#if LJ_64 +/* 64 bit mode needs special support for allocating memory in the lower 2GB. */ + +#if defined(MAP_32BIT) + +/* Actually this only gives us max. 1GB in current Linux kernels. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + void *ptr = mmap(NULL, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0); + errno = olderr; + return ptr; +} + +#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) + +/* OSX and FreeBSD mmap() use a naive first-fit linear search. +** That's perfect for us. Except that -pagezero_size must be set for OSX, +** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs +** to be reduced to 250MB on FreeBSD. +*/ +#if LJ_TARGET_OSX +#define MMAP_REGION_START ((uintptr_t)0x10000) +#elif LJ_TARGET_PS4 +#define MMAP_REGION_START ((uintptr_t)0x4000) +#else +#define MMAP_REGION_START ((uintptr_t)0x10000000) +#endif +#define MMAP_REGION_END ((uintptr_t)0x80000000) + +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 +#include +#endif + +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + /* Hint for next allocation. Doesn't need to be thread-safe. */ + static uintptr_t alloc_hint = MMAP_REGION_START; + int retry = 0; +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 + static int rlimit_modified = 0; + if (LJ_UNLIKELY(rlimit_modified == 0)) { + struct rlimit rlim; + rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START; + setrlimit(RLIMIT_DATA, &rlim); /* Ignore result. May fail below. */ + rlimit_modified = 1; + } +#endif + for (;;) { + void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0); + if ((uintptr_t)p >= MMAP_REGION_START && + (uintptr_t)p + size < MMAP_REGION_END) { + alloc_hint = (uintptr_t)p + size; + errno = olderr; + return p; + } + if (p != CMFAIL) munmap(p, size); +#ifdef __sun__ + alloc_hint += 0x1000000; /* Need near-exhaustive linear scan. */ + if (alloc_hint + size < MMAP_REGION_END) continue; +#endif + if (retry) break; + retry = 1; + alloc_hint = MMAP_REGION_START; + } + errno = olderr; + return CMFAIL; +} + +#else + +#error "NYI: need an equivalent of MAP_32BIT for this 64 bit OS" + +#endif + +#else + +/* 32 bit mode is easy. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0); + errno = olderr; + return ptr; +} + +#endif + +#define INIT_MMAP() ((void)0) +#define DIRECT_MMAP(s) CALL_MMAP(s) + +static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size) +{ + int olderr = errno; + int ret = munmap(ptr, size); + errno = olderr; + return ret; +} + +#if LJ_TARGET_LINUX +/* Need to define _GNU_SOURCE to get the mremap prototype. */ +static LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz, + int flags) +{ + int olderr = errno; + ptr = mremap(ptr, osz, nsz, flags); + errno = olderr; + return ptr; +} + +#define CALL_MREMAP(addr, osz, nsz, mv) CALL_MREMAP_((addr), (osz), (nsz), (mv)) +#define CALL_MREMAP_NOMOVE 0 +#define CALL_MREMAP_MAYMOVE 1 +#if LJ_64 +#define CALL_MREMAP_MV CALL_MREMAP_NOMOVE +#else +#define CALL_MREMAP_MV CALL_MREMAP_MAYMOVE +#endif +#endif + +#endif + +#ifndef CALL_MREMAP +#define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL) +#endif + +/* ----------------------- Chunk representations ------------------------ */ + +struct malloc_chunk { + size_t prev_foot; /* Size of previous chunk (if free). */ + size_t head; /* Size and inuse bits. */ + struct malloc_chunk *fd; /* double links -- used only if free. */ + struct malloc_chunk *bk; +}; + +typedef struct malloc_chunk mchunk; +typedef struct malloc_chunk *mchunkptr; +typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */ +typedef size_t bindex_t; /* Described below */ +typedef unsigned int binmap_t; /* Described below */ +typedef unsigned int flag_t; /* The type of various bit flag sets */ + +/* ------------------- Chunks sizes and alignments ----------------------- */ + +#define MCHUNK_SIZE (sizeof(mchunk)) + +#define CHUNK_OVERHEAD (SIZE_T_SIZE) + +/* Direct chunks need a second word of overhead ... */ +#define DIRECT_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) +/* ... and additional padding for fake next-chunk at foot */ +#define DIRECT_FOOT_PAD (FOUR_SIZE_T_SIZES) + +/* The smallest size we can malloc is an aligned minimal chunk */ +#define MIN_CHUNK_SIZE\ + ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* conversion from malloc headers to user pointers, and back */ +#define chunk2mem(p) ((void *)((char *)(p) + TWO_SIZE_T_SIZES)) +#define mem2chunk(mem) ((mchunkptr)((char *)(mem) - TWO_SIZE_T_SIZES)) +/* chunk associated with aligned address A */ +#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) + +/* Bounds on request (not chunk) sizes. */ +#define MAX_REQUEST ((~MIN_CHUNK_SIZE+1) << 2) +#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) + +/* pad request bytes into a usable size */ +#define pad_request(req) \ + (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* pad request, checking for minimum (but not maximum) */ +#define request2size(req) \ + (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) + +/* ------------------ Operations on head and foot fields ----------------- */ + +#define PINUSE_BIT (SIZE_T_ONE) +#define CINUSE_BIT (SIZE_T_TWO) +#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) + +/* Head value for fenceposts */ +#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) + +/* extraction of fields from head words */ +#define cinuse(p) ((p)->head & CINUSE_BIT) +#define pinuse(p) ((p)->head & PINUSE_BIT) +#define chunksize(p) ((p)->head & ~(INUSE_BITS)) + +#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) +#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) + +/* Treat space at ptr +/- offset as a chunk */ +#define chunk_plus_offset(p, s) ((mchunkptr)(((char *)(p)) + (s))) +#define chunk_minus_offset(p, s) ((mchunkptr)(((char *)(p)) - (s))) + +/* Ptr to next or previous physical malloc_chunk. */ +#define next_chunk(p) ((mchunkptr)(((char *)(p)) + ((p)->head & ~INUSE_BITS))) +#define prev_chunk(p) ((mchunkptr)(((char *)(p)) - ((p)->prev_foot) )) + +/* extract next chunk's pinuse bit */ +#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) + +/* Get/set size at footer */ +#define get_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot) +#define set_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot = (s)) + +/* Set size, pinuse bit, and foot */ +#define set_size_and_pinuse_of_free_chunk(p, s)\ + ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) + +/* Set size, pinuse bit, foot, and clear next pinuse */ +#define set_free_with_pinuse(p, s, n)\ + (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) + +#define is_direct(p)\ + (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_DIRECT_BIT)) + +/* Get the internal overhead associated with chunk p */ +#define overhead_for(p)\ + (is_direct(p)? DIRECT_CHUNK_OVERHEAD : CHUNK_OVERHEAD) + +/* ---------------------- Overlaid data structures ----------------------- */ + +struct malloc_tree_chunk { + /* The first four fields must be compatible with malloc_chunk */ + size_t prev_foot; + size_t head; + struct malloc_tree_chunk *fd; + struct malloc_tree_chunk *bk; + + struct malloc_tree_chunk *child[2]; + struct malloc_tree_chunk *parent; + bindex_t index; +}; + +typedef struct malloc_tree_chunk tchunk; +typedef struct malloc_tree_chunk *tchunkptr; +typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */ + +/* A little helper macro for trees */ +#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) + +/* ----------------------------- Segments -------------------------------- */ + +struct malloc_segment { + char *base; /* base address */ + size_t size; /* allocated size */ + struct malloc_segment *next; /* ptr to next segment */ +}; + +typedef struct malloc_segment msegment; +typedef struct malloc_segment *msegmentptr; + +/* ---------------------------- malloc_state ----------------------------- */ + +/* Bin types, widths and sizes */ +#define NSMALLBINS (32U) +#define NTREEBINS (32U) +#define SMALLBIN_SHIFT (3U) +#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) +#define TREEBIN_SHIFT (8U) +#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) +#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) +#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) + +struct malloc_state { + binmap_t smallmap; + binmap_t treemap; + size_t dvsize; + size_t topsize; + mchunkptr dv; + mchunkptr top; + size_t trim_check; + size_t release_checks; + mchunkptr smallbins[(NSMALLBINS+1)*2]; + tbinptr treebins[NTREEBINS]; + msegment seg; +}; + +typedef struct malloc_state *mstate; + +#define is_initialized(M) ((M)->top != 0) + +/* -------------------------- system alloc setup ------------------------- */ + +/* page-align a size */ +#define page_align(S)\ + (((S) + (LJ_PAGESIZE - SIZE_T_ONE)) & ~(LJ_PAGESIZE - SIZE_T_ONE)) + +/* granularity-align a size */ +#define granularity_align(S)\ + (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\ + & ~(DEFAULT_GRANULARITY - SIZE_T_ONE)) + +#if LJ_TARGET_WINDOWS +#define mmap_align(S) granularity_align(S) +#else +#define mmap_align(S) page_align(S) +#endif + +/* True if segment S holds address A */ +#define segment_holds(S, A)\ + ((char *)(A) >= S->base && (char *)(A) < S->base + S->size) + +/* Return segment holding given address */ +static msegmentptr segment_holding(mstate m, char *addr) +{ + msegmentptr sp = &m->seg; + for (;;) { + if (addr >= sp->base && addr < sp->base + sp->size) + return sp; + if ((sp = sp->next) == 0) + return 0; + } +} + +/* Return true if segment contains a segment link */ +static int has_segment_link(mstate m, msegmentptr ss) +{ + msegmentptr sp = &m->seg; + for (;;) { + if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size) + return 1; + if ((sp = sp->next) == 0) + return 0; + } +} + +/* + TOP_FOOT_SIZE is padding at the end of a segment, including space + that may be needed to place segment records and fenceposts when new + noncontiguous segments are added. +*/ +#define TOP_FOOT_SIZE\ + (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) + +/* ---------------------------- Indexing Bins ---------------------------- */ + +#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) +#define small_index(s) ((s) >> SMALLBIN_SHIFT) +#define small_index2size(i) ((i) << SMALLBIN_SHIFT) +#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) + +/* addressing by index. See above about smallbin repositioning */ +#define smallbin_at(M, i) ((sbinptr)((char *)&((M)->smallbins[(i)<<1]))) +#define treebin_at(M,i) (&((M)->treebins[i])) + +/* assign tree index for size S to variable I */ +#define compute_tree_index(S, I)\ +{\ + unsigned int X = (unsigned int)(S >> TREEBIN_SHIFT);\ + if (X == 0) {\ + I = 0;\ + } else if (X > 0xFFFF) {\ + I = NTREEBINS-1;\ + } else {\ + unsigned int K = lj_fls(X);\ + I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ + }\ +} + +/* Bit representing maximum resolved size in a treebin at i */ +#define bit_for_tree_index(i) \ + (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) + +/* Shift placing maximum resolved bit in a treebin at i as sign bit */ +#define leftshift_for_tree_index(i) \ + ((i == NTREEBINS-1)? 0 : \ + ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) + +/* The size of the smallest chunk held in bin with index i */ +#define minsize_for_tree_index(i) \ + ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ + (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) + +/* ------------------------ Operations on bin maps ----------------------- */ + +/* bit corresponding to given index */ +#define idx2bit(i) ((binmap_t)(1) << (i)) + +/* Mark/Clear bits with given index */ +#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) +#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) +#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) + +#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) +#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) +#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) + +/* mask with all bits to left of least bit of x on */ +#define left_bits(x) ((x<<1) | (~(x<<1)+1)) + +/* Set cinuse bit and pinuse bit of next chunk */ +#define set_inuse(M,p,s)\ + ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ + ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set cinuse and pinuse of this chunk and pinuse of next chunk */ +#define set_inuse_and_pinuse(M,p,s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ + ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set size, cinuse and pinuse bit of this chunk */ +#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) + +/* ----------------------- Operations on smallbins ----------------------- */ + +/* Link a free chunk into a smallbin */ +#define insert_small_chunk(M, P, S) {\ + bindex_t I = small_index(S);\ + mchunkptr B = smallbin_at(M, I);\ + mchunkptr F = B;\ + if (!smallmap_is_marked(M, I))\ + mark_smallmap(M, I);\ + else\ + F = B->fd;\ + B->fd = P;\ + F->bk = P;\ + P->fd = F;\ + P->bk = B;\ +} + +/* Unlink a chunk from a smallbin */ +#define unlink_small_chunk(M, P, S) {\ + mchunkptr F = P->fd;\ + mchunkptr B = P->bk;\ + bindex_t I = small_index(S);\ + if (F == B) {\ + clear_smallmap(M, I);\ + } else {\ + F->bk = B;\ + B->fd = F;\ + }\ +} + +/* Unlink the first chunk from a smallbin */ +#define unlink_first_small_chunk(M, B, P, I) {\ + mchunkptr F = P->fd;\ + if (B == F) {\ + clear_smallmap(M, I);\ + } else {\ + B->fd = F;\ + F->bk = B;\ + }\ +} + +/* Replace dv node, binning the old one */ +/* Used only when dvsize known to be small */ +#define replace_dv(M, P, S) {\ + size_t DVS = M->dvsize;\ + if (DVS != 0) {\ + mchunkptr DV = M->dv;\ + insert_small_chunk(M, DV, DVS);\ + }\ + M->dvsize = S;\ + M->dv = P;\ +} + +/* ------------------------- Operations on trees ------------------------- */ + +/* Insert chunk into tree */ +#define insert_large_chunk(M, X, S) {\ + tbinptr *H;\ + bindex_t I;\ + compute_tree_index(S, I);\ + H = treebin_at(M, I);\ + X->index = I;\ + X->child[0] = X->child[1] = 0;\ + if (!treemap_is_marked(M, I)) {\ + mark_treemap(M, I);\ + *H = X;\ + X->parent = (tchunkptr)H;\ + X->fd = X->bk = X;\ + } else {\ + tchunkptr T = *H;\ + size_t K = S << leftshift_for_tree_index(I);\ + for (;;) {\ + if (chunksize(T) != S) {\ + tchunkptr *C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ + K <<= 1;\ + if (*C != 0) {\ + T = *C;\ + } else {\ + *C = X;\ + X->parent = T;\ + X->fd = X->bk = X;\ + break;\ + }\ + } else {\ + tchunkptr F = T->fd;\ + T->fd = F->bk = X;\ + X->fd = F;\ + X->bk = T;\ + X->parent = 0;\ + break;\ + }\ + }\ + }\ +} + +#define unlink_large_chunk(M, X) {\ + tchunkptr XP = X->parent;\ + tchunkptr R;\ + if (X->bk != X) {\ + tchunkptr F = X->fd;\ + R = X->bk;\ + F->bk = R;\ + R->fd = F;\ + } else {\ + tchunkptr *RP;\ + if (((R = *(RP = &(X->child[1]))) != 0) ||\ + ((R = *(RP = &(X->child[0]))) != 0)) {\ + tchunkptr *CP;\ + while ((*(CP = &(R->child[1])) != 0) ||\ + (*(CP = &(R->child[0])) != 0)) {\ + R = *(RP = CP);\ + }\ + *RP = 0;\ + }\ + }\ + if (XP != 0) {\ + tbinptr *H = treebin_at(M, X->index);\ + if (X == *H) {\ + if ((*H = R) == 0) \ + clear_treemap(M, X->index);\ + } else {\ + if (XP->child[0] == X) \ + XP->child[0] = R;\ + else \ + XP->child[1] = R;\ + }\ + if (R != 0) {\ + tchunkptr C0, C1;\ + R->parent = XP;\ + if ((C0 = X->child[0]) != 0) {\ + R->child[0] = C0;\ + C0->parent = R;\ + }\ + if ((C1 = X->child[1]) != 0) {\ + R->child[1] = C1;\ + C1->parent = R;\ + }\ + }\ + }\ +} + +/* Relays to large vs small bin operations */ + +#define insert_chunk(M, P, S)\ + if (is_small(S)) { insert_small_chunk(M, P, S)\ + } else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } + +#define unlink_chunk(M, P, S)\ + if (is_small(S)) { unlink_small_chunk(M, P, S)\ + } else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } + +/* ----------------------- Direct-mmapping chunks ----------------------- */ + +static void *direct_alloc(size_t nb) +{ + size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + if (LJ_LIKELY(mmsize > nb)) { /* Check for wrap around 0 */ + char *mm = (char *)(DIRECT_MMAP(mmsize)); + if (mm != CMFAIL) { + size_t offset = align_offset(chunk2mem(mm)); + size_t psize = mmsize - offset - DIRECT_FOOT_PAD; + mchunkptr p = (mchunkptr)(mm + offset); + p->prev_foot = offset | IS_DIRECT_BIT; + p->head = psize|CINUSE_BIT; + chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; + return chunk2mem(p); + } + } + return NULL; +} + +static mchunkptr direct_resize(mchunkptr oldp, size_t nb) +{ + size_t oldsize = chunksize(oldp); + if (is_small(nb)) /* Can't shrink direct regions below small size */ + return NULL; + /* Keep old chunk if big enough but not too big */ + if (oldsize >= nb + SIZE_T_SIZE && + (oldsize - nb) <= (DEFAULT_GRANULARITY >> 1)) { + return oldp; + } else { + size_t offset = oldp->prev_foot & ~IS_DIRECT_BIT; + size_t oldmmsize = oldsize + offset + DIRECT_FOOT_PAD; + size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + char *cp = (char *)CALL_MREMAP((char *)oldp - offset, + oldmmsize, newmmsize, CALL_MREMAP_MV); + if (cp != CMFAIL) { + mchunkptr newp = (mchunkptr)(cp + offset); + size_t psize = newmmsize - offset - DIRECT_FOOT_PAD; + newp->head = psize|CINUSE_BIT; + chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; + return newp; + } + } + return NULL; +} + +/* -------------------------- mspace management -------------------------- */ + +/* Initialize top chunk and its size */ +static void init_top(mstate m, mchunkptr p, size_t psize) +{ + /* Ensure alignment */ + size_t offset = align_offset(chunk2mem(p)); + p = (mchunkptr)((char *)p + offset); + psize -= offset; + + m->top = p; + m->topsize = psize; + p->head = psize | PINUSE_BIT; + /* set size of fake trailing chunk holding overhead space only once */ + chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; + m->trim_check = DEFAULT_TRIM_THRESHOLD; /* reset on each update */ +} + +/* Initialize bins for a new mstate that is otherwise zeroed out */ +static void init_bins(mstate m) +{ + /* Establish circular links for smallbins */ + bindex_t i; + for (i = 0; i < NSMALLBINS; i++) { + sbinptr bin = smallbin_at(m,i); + bin->fd = bin->bk = bin; + } +} + +/* Allocate chunk and prepend remainder with chunk in successor base. */ +static void *prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb) +{ + mchunkptr p = align_as_chunk(newbase); + mchunkptr oldfirst = align_as_chunk(oldbase); + size_t psize = (size_t)((char *)oldfirst - (char *)p); + mchunkptr q = chunk_plus_offset(p, nb); + size_t qsize = psize - nb; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + + /* consolidate remainder with first chunk of old base */ + if (oldfirst == m->top) { + size_t tsize = m->topsize += qsize; + m->top = q; + q->head = tsize | PINUSE_BIT; + } else if (oldfirst == m->dv) { + size_t dsize = m->dvsize += qsize; + m->dv = q; + set_size_and_pinuse_of_free_chunk(q, dsize); + } else { + if (!cinuse(oldfirst)) { + size_t nsize = chunksize(oldfirst); + unlink_chunk(m, oldfirst, nsize); + oldfirst = chunk_plus_offset(oldfirst, nsize); + qsize += nsize; + } + set_free_with_pinuse(q, qsize, oldfirst); + insert_chunk(m, q, qsize); + } + + return chunk2mem(p); +} + +/* Add a segment to hold a new noncontiguous region */ +static void add_segment(mstate m, char *tbase, size_t tsize) +{ + /* Determine locations and sizes of segment, fenceposts, old top */ + char *old_top = (char *)m->top; + msegmentptr oldsp = segment_holding(m, old_top); + char *old_end = oldsp->base + oldsp->size; + size_t ssize = pad_request(sizeof(struct malloc_segment)); + char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + size_t offset = align_offset(chunk2mem(rawsp)); + char *asp = rawsp + offset; + char *csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; + mchunkptr sp = (mchunkptr)csp; + msegmentptr ss = (msegmentptr)(chunk2mem(sp)); + mchunkptr tnext = chunk_plus_offset(sp, ssize); + mchunkptr p = tnext; + + /* reset top to new space */ + init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); + + /* Set up segment record */ + set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); + *ss = m->seg; /* Push current record */ + m->seg.base = tbase; + m->seg.size = tsize; + m->seg.next = ss; + + /* Insert trailing fenceposts */ + for (;;) { + mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); + p->head = FENCEPOST_HEAD; + if ((char *)(&(nextp->head)) < old_end) + p = nextp; + else + break; + } + + /* Insert the rest of old top into a bin as an ordinary free chunk */ + if (csp != old_top) { + mchunkptr q = (mchunkptr)old_top; + size_t psize = (size_t)(csp - old_top); + mchunkptr tn = chunk_plus_offset(q, psize); + set_free_with_pinuse(q, psize, tn); + insert_chunk(m, q, psize); + } +} + +/* -------------------------- System allocation -------------------------- */ + +static void *alloc_sys(mstate m, size_t nb) +{ + char *tbase = CMFAIL; + size_t tsize = 0; + + /* Directly map large chunks */ + if (LJ_UNLIKELY(nb >= DEFAULT_MMAP_THRESHOLD)) { + void *mem = direct_alloc(nb); + if (mem != 0) + return mem; + } + + { + size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE; + size_t rsize = granularity_align(req); + if (LJ_LIKELY(rsize > nb)) { /* Fail if wraps around zero */ + char *mp = (char *)(CALL_MMAP(rsize)); + if (mp != CMFAIL) { + tbase = mp; + tsize = rsize; + } + } + } + + if (tbase != CMFAIL) { + msegmentptr sp = &m->seg; + /* Try to merge with an existing segment */ + while (sp != 0 && tbase != sp->base + sp->size) + sp = sp->next; + if (sp != 0 && segment_holds(sp, m->top)) { /* append */ + sp->size += tsize; + init_top(m, m->top, m->topsize + tsize); + } else { + sp = &m->seg; + while (sp != 0 && sp->base != tbase + tsize) + sp = sp->next; + if (sp != 0) { + char *oldbase = sp->base; + sp->base = tbase; + sp->size += tsize; + return prepend_alloc(m, tbase, oldbase, nb); + } else { + add_segment(m, tbase, tsize); + } + } + + if (nb < m->topsize) { /* Allocate from new or extended top space */ + size_t rsize = m->topsize -= nb; + mchunkptr p = m->top; + mchunkptr r = m->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + return chunk2mem(p); + } + } + + return NULL; +} + +/* ----------------------- system deallocation -------------------------- */ + +/* Unmap and unlink any mmapped segments that don't contain used chunks */ +static size_t release_unused_segments(mstate m) +{ + size_t released = 0; + size_t nsegs = 0; + msegmentptr pred = &m->seg; + msegmentptr sp = pred->next; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + msegmentptr next = sp->next; + nsegs++; + { + mchunkptr p = align_as_chunk(base); + size_t psize = chunksize(p); + /* Can unmap if first chunk holds entire segment and not pinned */ + if (!cinuse(p) && (char *)p + psize >= base + size - TOP_FOOT_SIZE) { + tchunkptr tp = (tchunkptr)p; + if (p == m->dv) { + m->dv = 0; + m->dvsize = 0; + } else { + unlink_large_chunk(m, tp); + } + if (CALL_MUNMAP(base, size) == 0) { + released += size; + /* unlink obsoleted record */ + sp = pred; + sp->next = next; + } else { /* back out if cannot unmap */ + insert_large_chunk(m, tp, psize); + } + } + } + pred = sp; + sp = next; + } + /* Reset check counter */ + m->release_checks = nsegs > MAX_RELEASE_CHECK_RATE ? + nsegs : MAX_RELEASE_CHECK_RATE; + return released; +} + +static int alloc_trim(mstate m, size_t pad) +{ + size_t released = 0; + if (pad < MAX_REQUEST && is_initialized(m)) { + pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ + + if (m->topsize > pad) { + /* Shrink top space in granularity-size units, keeping at least one */ + size_t unit = DEFAULT_GRANULARITY; + size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - + SIZE_T_ONE) * unit; + msegmentptr sp = segment_holding(m, (char *)m->top); + + if (sp->size >= extra && + !has_segment_link(m, sp)) { /* can't shrink if pinned */ + size_t newsize = sp->size - extra; + /* Prefer mremap, fall back to munmap */ + if ((CALL_MREMAP(sp->base, sp->size, newsize, CALL_MREMAP_NOMOVE) != MFAIL) || + (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { + released = extra; + } + } + + if (released != 0) { + sp->size -= released; + init_top(m, m->top, m->topsize - released); + } + } + + /* Unmap any unused mmapped segments */ + released += release_unused_segments(m); + + /* On failure, disable autotrim to avoid repeated failed future calls */ + if (released == 0 && m->topsize > m->trim_check) + m->trim_check = MAX_SIZE_T; + } + + return (released != 0)? 1 : 0; +} + +/* ---------------------------- malloc support --------------------------- */ + +/* allocate a large request from the best fitting chunk in a treebin */ +static void *tmalloc_large(mstate m, size_t nb) +{ + tchunkptr v = 0; + size_t rsize = ~nb+1; /* Unsigned negation */ + tchunkptr t; + bindex_t idx; + compute_tree_index(nb, idx); + + if ((t = *treebin_at(m, idx)) != 0) { + /* Traverse tree for this bin looking for node with size == nb */ + size_t sizebits = nb << leftshift_for_tree_index(idx); + tchunkptr rst = 0; /* The deepest untaken right subtree */ + for (;;) { + tchunkptr rt; + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + v = t; + if ((rsize = trem) == 0) + break; + } + rt = t->child[1]; + t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; + if (rt != 0 && rt != t) + rst = rt; + if (t == 0) { + t = rst; /* set t to least subtree holding sizes > nb */ + break; + } + sizebits <<= 1; + } + } + + if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ + binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; + if (leftbits != 0) + t = *treebin_at(m, lj_ffs(leftbits)); + } + + while (t != 0) { /* find smallest of tree or subtree */ + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + t = leftmost_child(t); + } + + /* If dv is a better fit, return NULL so malloc will use it */ + if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { + mchunkptr r = chunk_plus_offset(v, nb); + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(m, v, (rsize + nb)); + } else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + insert_chunk(m, r, rsize); + } + return chunk2mem(v); + } + return NULL; +} + +/* allocate a small request from the best fitting chunk in a treebin */ +static void *tmalloc_small(mstate m, size_t nb) +{ + tchunkptr t, v; + mchunkptr r; + size_t rsize; + bindex_t i = lj_ffs(m->treemap); + + v = t = *treebin_at(m, i); + rsize = chunksize(t) - nb; + + while ((t = leftmost_child(t)) != 0) { + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + } + + r = chunk_plus_offset(v, nb); + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(m, v, (rsize + nb)); + } else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(m, r, rsize); + } + return chunk2mem(v); +} + +/* ----------------------------------------------------------------------- */ + +void *lj_alloc_create(void) +{ + size_t tsize = DEFAULT_GRANULARITY; + char *tbase; + INIT_MMAP(); + tbase = (char *)(CALL_MMAP(tsize)); + if (tbase != CMFAIL) { + size_t msize = pad_request(sizeof(struct malloc_state)); + mchunkptr mn; + mchunkptr msp = align_as_chunk(tbase); + mstate m = (mstate)(chunk2mem(msp)); + memset(m, 0, msize); + msp->head = (msize|PINUSE_BIT|CINUSE_BIT); + m->seg.base = tbase; + m->seg.size = tsize; + m->release_checks = MAX_RELEASE_CHECK_RATE; + init_bins(m); + mn = next_chunk(mem2chunk(m)); + init_top(m, mn, (size_t)((tbase + tsize) - (char *)mn) - TOP_FOOT_SIZE); + return m; + } + return NULL; +} + +void lj_alloc_destroy(void *msp) +{ + mstate ms = (mstate)msp; + msegmentptr sp = &ms->seg; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + sp = sp->next; + CALL_MUNMAP(base, size); + } +} + +static LJ_NOINLINE void *lj_alloc_malloc(void *msp, size_t nsize) +{ + mstate ms = (mstate)msp; + void *mem; + size_t nb; + if (nsize <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (nsize < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(nsize); + idx = small_index(nb); + smallbits = ms->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at(ms, idx); + p = b->fd; + unlink_first_small_chunk(ms, b, p, idx); + set_inuse_and_pinuse(ms, p, small_index2size(idx)); + mem = chunk2mem(p); + return mem; + } else if (nb > ms->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); + bindex_t i = lj_ffs(leftbits); + b = smallbin_at(ms, i); + p = b->fd; + unlink_first_small_chunk(ms, b, p, i); + rsize = small_index2size(i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(ms, p, small_index2size(i)); + } else { + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + r = chunk_plus_offset(p, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(ms, r, rsize); + } + mem = chunk2mem(p); + return mem; + } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { + return mem; + } + } + } else if (nsize >= MAX_REQUEST) { + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + } else { + nb = pad_request(nsize); + if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { + return mem; + } + } + + if (nb <= ms->dvsize) { + size_t rsize = ms->dvsize - nb; + mchunkptr p = ms->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = ms->dv = chunk_plus_offset(p, nb); + ms->dvsize = rsize; + set_size_and_pinuse_of_free_chunk(r, rsize); + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + } else { /* exhaust dv */ + size_t dvs = ms->dvsize; + ms->dvsize = 0; + ms->dv = 0; + set_inuse_and_pinuse(ms, p, dvs); + } + mem = chunk2mem(p); + return mem; + } else if (nb < ms->topsize) { /* Split top */ + size_t rsize = ms->topsize -= nb; + mchunkptr p = ms->top; + mchunkptr r = ms->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + mem = chunk2mem(p); + return mem; + } + return alloc_sys(ms, nb); +} + +static LJ_NOINLINE void *lj_alloc_free(void *msp, void *ptr) +{ + if (ptr != 0) { + mchunkptr p = mem2chunk(ptr); + mstate fm = (mstate)msp; + size_t psize = chunksize(p); + mchunkptr next = chunk_plus_offset(p, psize); + if (!pinuse(p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_DIRECT_BIT) != 0) { + prevsize &= ~IS_DIRECT_BIT; + psize += prevsize + DIRECT_FOOT_PAD; + CALL_MUNMAP((char *)p - prevsize, psize); + return NULL; + } else { + mchunkptr prev = chunk_minus_offset(p, prevsize); + psize += prevsize; + p = prev; + /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk(fm, p, prevsize); + } else if ((next->head & INUSE_BITS) == INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse(p, psize, next); + return NULL; + } + } + } + if (!cinuse(next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (tsize > fm->trim_check) + alloc_trim(fm, 0); + return NULL; + } else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk(p, dsize); + return NULL; + } else { + size_t nsize = chunksize(next); + psize += nsize; + unlink_chunk(fm, next, nsize); + set_size_and_pinuse_of_free_chunk(p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + return NULL; + } + } + } else { + set_free_with_pinuse(p, psize, next); + } + + if (is_small(psize)) { + insert_small_chunk(fm, p, psize); + } else { + tchunkptr tp = (tchunkptr)p; + insert_large_chunk(fm, tp, psize); + if (--fm->release_checks == 0) + release_unused_segments(fm); + } + } + return NULL; +} + +static LJ_NOINLINE void *lj_alloc_realloc(void *msp, void *ptr, size_t nsize) +{ + if (nsize >= MAX_REQUEST) { + return NULL; + } else { + mstate m = (mstate)msp; + mchunkptr oldp = mem2chunk(ptr); + size_t oldsize = chunksize(oldp); + mchunkptr next = chunk_plus_offset(oldp, oldsize); + mchunkptr newp = 0; + size_t nb = request2size(nsize); + + /* Try to either shrink or extend into top. Else malloc-copy-free */ + if (is_direct(oldp)) { + newp = direct_resize(oldp, nb); /* this may return NULL. */ + } else if (oldsize >= nb) { /* already big enough */ + size_t rsize = oldsize - nb; + newp = oldp; + if (rsize >= MIN_CHUNK_SIZE) { + mchunkptr rem = chunk_plus_offset(newp, nb); + set_inuse(m, newp, nb); + set_inuse(m, rem, rsize); + lj_alloc_free(m, chunk2mem(rem)); + } + } else if (next == m->top && oldsize + m->topsize > nb) { + /* Expand into top */ + size_t newsize = oldsize + m->topsize; + size_t newtopsize = newsize - nb; + mchunkptr newtop = chunk_plus_offset(oldp, nb); + set_inuse(m, oldp, nb); + newtop->head = newtopsize |PINUSE_BIT; + m->top = newtop; + m->topsize = newtopsize; + newp = oldp; + } + + if (newp != 0) { + return chunk2mem(newp); + } else { + void *newmem = lj_alloc_malloc(m, nsize); + if (newmem != 0) { + size_t oc = oldsize - overhead_for(oldp); + memcpy(newmem, ptr, oc < nsize ? oc : nsize); + lj_alloc_free(m, ptr); + } + return newmem; + } + } +} + +void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize) +{ + (void)osize; + if (nsize == 0) { + return lj_alloc_free(msp, ptr); + } else if (ptr == NULL) { + return lj_alloc_malloc(msp, nsize); + } else { + return lj_alloc_realloc(msp, ptr, nsize); + } +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.h new file mode 100644 index 0000000..f87a7cf --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_alloc.h @@ -0,0 +1,17 @@ +/* +** Bundled memory allocator. +** Donated to the public domain. +*/ + +#ifndef _LJ_ALLOC_H +#define _LJ_ALLOC_H + +#include "lj_def.h" + +#ifndef LUAJIT_USE_SYSMALLOC +LJ_FUNC void *lj_alloc_create(void); +LJ_FUNC void lj_alloc_destroy(void *msp); +LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_api.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_api.c new file mode 100644 index 0000000..bc5290b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_api.c @@ -0,0 +1,1200 @@ +/* +** Public Lua/C API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_api_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_udata.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_bc.h" +#include "lj_frame.h" +#include "lj_trace.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* -- Common helper functions --------------------------------------------- */ + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) +#define api_checkvalidindex(L, i) api_check(L, (i) != niltv(L)) + +static TValue *index2adr(lua_State *L, int idx) +{ + if (idx > 0) { + TValue *o = L->base + (idx - 1); + return o < L->top ? o : niltv(L); + } else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } else if (idx == LUA_GLOBALSINDEX) { + TValue *o = &G(L)->tmptv; + settabV(L, o, tabref(L->env)); + return o; + } else if (idx == LUA_REGISTRYINDEX) { + return registry(L); + } else { + GCfunc *fn = curr_func(L); + api_check(L, fn->c.gct == ~LJ_TFUNC && !isluafunc(fn)); + if (idx == LUA_ENVIRONINDEX) { + TValue *o = &G(L)->tmptv; + settabV(L, o, tabref(fn->c.env)); + return o; + } else { + idx = LUA_GLOBALSINDEX - idx; + return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L); + } + } +} + +static TValue *stkindex2adr(lua_State *L, int idx) +{ + if (idx > 0) { + TValue *o = L->base + (idx - 1); + return o < L->top ? o : niltv(L); + } else { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } +} + +static GCtab *getcurrenv(lua_State *L) +{ + GCfunc *fn = curr_func(L); + return fn->c.gct == ~LJ_TFUNC ? tabref(fn->c.env) : tabref(L->env); +} + +/* -- Miscellaneous API functions ----------------------------------------- */ + +LUA_API int lua_status(lua_State *L) +{ + return L->status; +} + +LUA_API int lua_checkstack(lua_State *L, int size) +{ + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) { + return 0; /* Stack overflow. */ + } else if (size > 0) { + lj_state_checkstack(L, (MSize)size); + } + return 1; +} + +LUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg) +{ + if (!lua_checkstack(L, size)) + lj_err_callerv(L, LJ_ERR_STKOVM, msg); +} + +LUA_API void lua_xmove(lua_State *from, lua_State *to, int n) +{ + TValue *f, *t; + if (from == to) return; + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + lj_state_checkstack(to, (MSize)n); + f = from->top; + t = to->top = to->top + n; + while (--n >= 0) copyTV(to, --t, --f); + from->top = f; +} + +/* -- Stack manipulation -------------------------------------------------- */ + +LUA_API int lua_gettop(lua_State *L) +{ + return (int)(L->top - L->base); +} + +LUA_API void lua_settop(lua_State *L, int idx) +{ + if (idx >= 0) { + api_check(L, idx <= tvref(L->maxstack) - L->base); + if (L->base + idx > L->top) { + if (L->base + idx >= tvref(L->maxstack)) + lj_state_growstack(L, (MSize)idx - (MSize)(L->top - L->base)); + do { setnilV(L->top++); } while (L->top < L->base + idx); + } else { + L->top = L->base + idx; + } + } else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* Shrinks top (idx < 0). */ + } +} + +LUA_API void lua_remove(lua_State *L, int idx) +{ + TValue *p = stkindex2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) copyTV(L, p-1, p); + L->top--; +} + +LUA_API void lua_insert(lua_State *L, int idx) +{ + TValue *q, *p = stkindex2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q > p; q--) copyTV(L, q, q-1); + copyTV(L, p, L->top); +} + +LUA_API void lua_replace(lua_State *L, int idx) +{ + api_checknelems(L, 1); + if (idx == LUA_GLOBALSINDEX) { + api_check(L, tvistab(L->top-1)); + /* NOBARRIER: A thread (i.e. L) is never black. */ + setgcref(L->env, obj2gco(tabV(L->top-1))); + } else if (idx == LUA_ENVIRONINDEX) { + GCfunc *fn = curr_func(L); + if (fn->c.gct != ~LJ_TFUNC) + lj_err_msg(L, LJ_ERR_NOENV); + api_check(L, tvistab(L->top-1)); + setgcref(fn->c.env, obj2gco(tabV(L->top-1))); + lj_gc_barrier(L, fn, L->top-1); + } else { + TValue *o = index2adr(L, idx); + api_checkvalidindex(L, o); + copyTV(L, o, L->top-1); + if (idx < LUA_GLOBALSINDEX) /* Need a barrier for upvalues. */ + lj_gc_barrier(L, curr_func(L), L->top-1); + } + L->top--; +} + +LUA_API void lua_pushvalue(lua_State *L, int idx) +{ + copyTV(L, L->top, index2adr(L, idx)); + incr_top(L); +} + +/* -- Stack getters ------------------------------------------------------- */ + +LUA_API int lua_type(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisnumber(o)) { + return LUA_TNUMBER; +#if LJ_64 + } else if (tvislightud(o)) { + return LUA_TLIGHTUSERDATA; +#endif + } else if (o == niltv(L)) { + return LUA_TNONE; + } else { /* Magic internal/external tag conversion. ORDER LJ_T */ + uint32_t t = ~itype(o); +#if LJ_64 + int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u); +#else + int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u); +#endif + lua_assert(tt != LUA_TNIL || tvisnil(o)); + return tt; + } +} + +LUALIB_API void luaL_checktype(lua_State *L, int idx, int tt) +{ + if (lua_type(L, idx) != tt) + lj_err_argt(L, idx, tt); +} + +LUALIB_API void luaL_checkany(lua_State *L, int idx) +{ + if (index2adr(L, idx) == niltv(L)) + lj_err_arg(L, idx, LJ_ERR_NOVAL); +} + +LUA_API const char *lua_typename(lua_State *L, int t) +{ + UNUSED(L); + return lj_obj_typename[t+1]; +} + +LUA_API int lua_iscfunction(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return tvisfunc(o) && !isluafunc(funcV(o)); +} + +LUA_API int lua_isnumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + return (tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), &tmp))); +} + +LUA_API int lua_isstring(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (tvisstr(o) || tvisnumber(o)); +} + +LUA_API int lua_isuserdata(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (tvisudata(o) || tvislightud(o)); +} + +LUA_API int lua_rawequal(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + return (o1 == niltv(L) || o2 == niltv(L)) ? 0 : lj_obj_equal(o1, o2); +} + +LUA_API int lua_equal(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + if (tvisint(o1) && tvisint(o2)) { + return intV(o1) == intV(o2); + } else if (tvisnumber(o1) && tvisnumber(o2)) { + return numberVnum(o1) == numberVnum(o2); + } else if (itype(o1) != itype(o2)) { + return 0; + } else if (tvispri(o1)) { + return o1 != niltv(L) && o2 != niltv(L); +#if LJ_64 + } else if (tvislightud(o1)) { + return o1->u64 == o2->u64; +#endif + } else if (gcrefeq(o1->gcr, o2->gcr)) { + return 1; + } else if (!tvistabud(o1)) { + return 0; + } else { + TValue *base = lj_meta_equal(L, gcV(o1), gcV(o2), 0); + if ((uintptr_t)base <= 1) { + return (int)(uintptr_t)base; + } else { + L->top = base+2; + lj_vm_call(L, base, 1+1); + L->top -= 2; + return tvistruecond(L->top+1); + } + } +} + +LUA_API int lua_lessthan(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + if (o1 == niltv(L) || o2 == niltv(L)) { + return 0; + } else if (tvisint(o1) && tvisint(o2)) { + return intV(o1) < intV(o2); + } else if (tvisnumber(o1) && tvisnumber(o2)) { + return numberVnum(o1) < numberVnum(o2); + } else { + TValue *base = lj_meta_comp(L, o1, o2, 0); + if ((uintptr_t)base <= 1) { + return (int)(uintptr_t)base; + } else { + L->top = base+2; + lj_vm_call(L, base, 1+1); + L->top -= 2; + return tvistruecond(L->top+1); + } + } +} + +LUA_API lua_Number lua_tonumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp)) + return numV(&tmp); + else + return 0; +} + +LUALIB_API lua_Number luaL_checknumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + return numV(&tmp); +} + +LUALIB_API lua_Number luaL_optnumber(lua_State *L, int idx, lua_Number def) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (tvisnil(o)) + return def; + else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + return numV(&tmp); +} + +LUA_API lua_Integer lua_tointeger(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + return 0; + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else if (tvisnil(o)) { + return def; + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUA_API int lua_toboolean(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return tvistruecond(o); +} + +LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + if (len != NULL) *len = 0; + return NULL; + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + lj_err_argt(L, idx, LUA_TSTRING); + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API const char *luaL_optlstring(lua_State *L, int idx, + const char *def, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnil(o)) { + if (len != NULL) *len = def ? strlen(def) : 0; + return def; + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + lj_err_argt(L, idx, LUA_TSTRING); + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def, + const char *const lst[]) +{ + ptrdiff_t i; + const char *s = lua_tolstring(L, idx, NULL); + if (s == NULL && (s = def) == NULL) + lj_err_argt(L, idx, LUA_TSTRING); + for (i = 0; lst[i]; i++) + if (strcmp(lst[i], s) == 0) + return (int)i; + lj_err_argv(L, idx, LJ_ERR_INVOPTM, s); +} + +LUA_API size_t lua_objlen(lua_State *L, int idx) +{ + TValue *o = index2adr(L, idx); + if (tvisstr(o)) { + return strV(o)->len; + } else if (tvistab(o)) { + return (size_t)lj_tab_len(tabV(o)); + } else if (tvisudata(o)) { + return udataV(o)->len; + } else if (tvisnumber(o)) { + GCstr *s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + return s->len; + } else { + return 0; + } +} + +LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisfunc(o)) { + BCOp op = bc_op(*mref(funcV(o)->c.pc, BCIns)); + if (op == BC_FUNCC || op == BC_FUNCCW) + return funcV(o)->c.f; + } + return NULL; +} + +LUA_API void *lua_touserdata(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) + return uddata(udataV(o)); + else if (tvislightud(o)) + return lightudV(o); + else + return NULL; +} + +LUA_API lua_State *lua_tothread(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (!tvisthread(o)) ? NULL : threadV(o); +} + +LUA_API const void *lua_topointer(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) + return uddata(udataV(o)); + else if (tvislightud(o)) + return lightudV(o); + else if (tviscdata(o)) + return cdataptr(cdataV(o)); + else if (tvisgcv(o)) + return gcV(o); + else + return NULL; +} + +/* -- Stack setters (object creation) ------------------------------------- */ + +LUA_API void lua_pushnil(lua_State *L) +{ + setnilV(L->top); + incr_top(L); +} + +LUA_API void lua_pushnumber(lua_State *L, lua_Number n) +{ + setnumV(L->top, n); + if (LJ_UNLIKELY(tvisnan(L->top))) + setnanV(L->top); /* Canonicalize injected NaNs. */ + incr_top(L); +} + +LUA_API void lua_pushinteger(lua_State *L, lua_Integer n) +{ + setintptrV(L->top, n); + incr_top(L); +} + +LUA_API void lua_pushlstring(lua_State *L, const char *str, size_t len) +{ + GCstr *s; + lj_gc_check(L); + s = lj_str_new(L, str, len); + setstrV(L, L->top, s); + incr_top(L); +} + +LUA_API void lua_pushstring(lua_State *L, const char *str) +{ + if (str == NULL) { + setnilV(L->top); + } else { + GCstr *s; + lj_gc_check(L); + s = lj_str_newz(L, str); + setstrV(L, L->top, s); + } + incr_top(L); +} + +LUA_API const char *lua_pushvfstring(lua_State *L, const char *fmt, + va_list argp) +{ + lj_gc_check(L); + return lj_str_pushvf(L, fmt, argp); +} + +LUA_API const char *lua_pushfstring(lua_State *L, const char *fmt, ...) +{ + const char *ret; + va_list argp; + lj_gc_check(L); + va_start(argp, fmt); + ret = lj_str_pushvf(L, fmt, argp); + va_end(argp); + return ret; +} + +LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction f, int n) +{ + GCfunc *fn; + lj_gc_check(L); + api_checknelems(L, n); + fn = lj_func_newC(L, (MSize)n, getcurrenv(L)); + fn->c.f = f; + L->top -= n; + while (n--) + copyTV(L, &fn->c.upvalue[n], L->top+n); + setfuncV(L, L->top, fn); + lua_assert(iswhite(obj2gco(fn))); + incr_top(L); +} + +LUA_API void lua_pushboolean(lua_State *L, int b) +{ + setboolV(L->top, (b != 0)); + incr_top(L); +} + +LUA_API void lua_pushlightuserdata(lua_State *L, void *p) +{ + setlightudV(L->top, checklightudptr(L, p)); + incr_top(L); +} + +LUA_API void lua_createtable(lua_State *L, int narray, int nrec) +{ + GCtab *t; + lj_gc_check(L); + t = lj_tab_new(L, (uint32_t)(narray > 0 ? narray+1 : 0), hsize2hbits(nrec)); + settabV(L, L->top, t); + incr_top(L); +} + +LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname) +{ + GCtab *regt = tabV(registry(L)); + TValue *tv = lj_tab_setstr(L, regt, lj_str_newz(L, tname)); + if (tvisnil(tv)) { + GCtab *mt = lj_tab_new(L, 0, 1); + settabV(L, tv, mt); + settabV(L, L->top++, mt); + lj_gc_anybarriert(L, regt); + return 1; + } else { + copyTV(L, L->top++, tv); + return 0; + } +} + +LUA_API int lua_pushthread(lua_State *L) +{ + setthreadV(L, L->top, L); + incr_top(L); + return (mainthread(G(L)) == L); +} + +LUA_API lua_State *lua_newthread(lua_State *L) +{ + lua_State *L1; + lj_gc_check(L); + L1 = lj_state_new(L); + setthreadV(L, L->top, L1); + incr_top(L); + return L1; +} + +LUA_API void *lua_newuserdata(lua_State *L, size_t size) +{ + GCudata *ud; + lj_gc_check(L); + if (size > LJ_MAX_UDATA) + lj_err_msg(L, LJ_ERR_UDATAOV); + ud = lj_udata_new(L, (MSize)size, getcurrenv(L)); + setudataV(L, L->top, ud); + incr_top(L); + return uddata(ud); +} + +LUA_API void lua_concat(lua_State *L, int n) +{ + api_checknelems(L, n); + if (n >= 2) { + n--; + do { + TValue *top = lj_meta_cat(L, L->top-1, -n); + if (top == NULL) { + L->top -= n; + break; + } + n -= (int)(L->top - top); + L->top = top+2; + lj_vm_call(L, top, 1+1); + L->top--; + copyTV(L, L->top-1, L->top); + } while (--n > 0); + } else if (n == 0) { /* Push empty string. */ + setstrV(L, L->top, &G(L)->strempty); + incr_top(L); + } + /* else n == 1: nothing to do. */ +} + +/* -- Object getters ------------------------------------------------------ */ + +LUA_API void lua_gettable(lua_State *L, int idx) +{ + cTValue *v, *t = index2adr(L, idx); + api_checkvalidindex(L, t); + v = lj_meta_tget(L, t, L->top-1); + if (v == NULL) { + L->top += 2; + lj_vm_call(L, L->top-2, 1+1); + L->top -= 2; + v = L->top+1; + } + copyTV(L, L->top-1, v); +} + +LUA_API void lua_getfield(lua_State *L, int idx, const char *k) +{ + cTValue *v, *t = index2adr(L, idx); + TValue key; + api_checkvalidindex(L, t); + setstrV(L, &key, lj_str_newz(L, k)); + v = lj_meta_tget(L, t, &key); + if (v == NULL) { + L->top += 2; + lj_vm_call(L, L->top-2, 1+1); + L->top -= 2; + v = L->top+1; + } + copyTV(L, L->top, v); + incr_top(L); +} + +LUA_API void lua_rawget(lua_State *L, int idx) +{ + cTValue *t = index2adr(L, idx); + api_check(L, tvistab(t)); + copyTV(L, L->top-1, lj_tab_get(L, tabV(t), L->top-1)); +} + +LUA_API void lua_rawgeti(lua_State *L, int idx, int n) +{ + cTValue *v, *t = index2adr(L, idx); + api_check(L, tvistab(t)); + v = lj_tab_getint(tabV(t), n); + if (v) { + copyTV(L, L->top, v); + } else { + setnilV(L->top); + } + incr_top(L); +} + +LUA_API int lua_getmetatable(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + GCtab *mt = NULL; + if (tvistab(o)) + mt = tabref(tabV(o)->metatable); + else if (tvisudata(o)) + mt = tabref(udataV(o)->metatable); + else + mt = tabref(basemt_obj(G(L), o)); + if (mt == NULL) + return 0; + settabV(L, L->top, mt); + incr_top(L); + return 1; +} + +LUALIB_API int luaL_getmetafield(lua_State *L, int idx, const char *field) +{ + if (lua_getmetatable(L, idx)) { + cTValue *tv = lj_tab_getstr(tabV(L->top-1), lj_str_newz(L, field)); + if (tv && !tvisnil(tv)) { + copyTV(L, L->top-1, tv); + return 1; + } + L->top--; + } + return 0; +} + +LUA_API void lua_getfenv(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (tvisfunc(o)) { + settabV(L, L->top, tabref(funcV(o)->c.env)); + } else if (tvisudata(o)) { + settabV(L, L->top, tabref(udataV(o)->env)); + } else if (tvisthread(o)) { + settabV(L, L->top, tabref(threadV(o)->env)); + } else { + setnilV(L->top); + } + incr_top(L); +} + +LUA_API int lua_next(lua_State *L, int idx) +{ + cTValue *t = index2adr(L, idx); + int more; + api_check(L, tvistab(t)); + more = lj_tab_next(L, tabV(t), L->top-1); + if (more) { + incr_top(L); /* Return new key and value slot. */ + } else { /* End of traversal. */ + L->top--; /* Remove key slot. */ + } + return more; +} + +LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) +{ + TValue *val; + const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val); + if (name) { + copyTV(L, L->top, val); + incr_top(L); + } + return name; +} + +LUA_API void *lua_upvalueid(lua_State *L, int idx, int n) +{ + GCfunc *fn = funcV(index2adr(L, idx)); + n--; + api_check(L, (uint32_t)n < fn->l.nupvalues); + return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : + (void *)&fn->c.upvalue[n]; +} + +LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2) +{ + GCfunc *fn1 = funcV(index2adr(L, idx1)); + GCfunc *fn2 = funcV(index2adr(L, idx2)); + n1--; n2--; + api_check(L, isluafunc(fn1) && (uint32_t)n1 < fn1->l.nupvalues); + api_check(L, isluafunc(fn2) && (uint32_t)n2 < fn2->l.nupvalues); + setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]); + lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1])); +} + +LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) { + GCudata *ud = udataV(o); + cTValue *tv = lj_tab_getstr(tabV(registry(L)), lj_str_newz(L, tname)); + if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable)) + return uddata(ud); + } + lj_err_argtype(L, idx, tname); + return NULL; /* unreachable */ +} + +/* -- Object setters ------------------------------------------------------ */ + +LUA_API void lua_settable(lua_State *L, int idx) +{ + TValue *o; + cTValue *t = index2adr(L, idx); + api_checknelems(L, 2); + api_checkvalidindex(L, t); + o = lj_meta_tset(L, t, L->top-2); + if (o) { + /* NOBARRIER: lj_meta_tset ensures the table is not black. */ + copyTV(L, o, L->top-1); + L->top -= 2; + } else { + L->top += 3; + copyTV(L, L->top-1, L->top-6); + lj_vm_call(L, L->top-3, 0+1); + L->top -= 3; + } +} + +LUA_API void lua_setfield(lua_State *L, int idx, const char *k) +{ + TValue *o; + TValue key; + cTValue *t = index2adr(L, idx); + api_checknelems(L, 1); + api_checkvalidindex(L, t); + setstrV(L, &key, lj_str_newz(L, k)); + o = lj_meta_tset(L, t, &key); + if (o) { + L->top--; + /* NOBARRIER: lj_meta_tset ensures the table is not black. */ + copyTV(L, o, L->top); + } else { + L->top += 3; + copyTV(L, L->top-1, L->top-6); + lj_vm_call(L, L->top-3, 0+1); + L->top -= 2; + } +} + +LUA_API void lua_rawset(lua_State *L, int idx) +{ + GCtab *t = tabV(index2adr(L, idx)); + TValue *dst, *key; + api_checknelems(L, 2); + key = L->top-2; + dst = lj_tab_set(L, t, key); + copyTV(L, dst, key+1); + lj_gc_anybarriert(L, t); + L->top = key; +} + +LUA_API void lua_rawseti(lua_State *L, int idx, int n) +{ + GCtab *t = tabV(index2adr(L, idx)); + TValue *dst, *src; + api_checknelems(L, 1); + dst = lj_tab_setint(L, t, n); + src = L->top-1; + copyTV(L, dst, src); + lj_gc_barriert(L, t, dst); + L->top = src; +} + +LUA_API int lua_setmetatable(lua_State *L, int idx) +{ + global_State *g; + GCtab *mt; + cTValue *o = index2adr(L, idx); + api_checknelems(L, 1); + api_checkvalidindex(L, o); + if (tvisnil(L->top-1)) { + mt = NULL; + } else { + api_check(L, tvistab(L->top-1)); + mt = tabV(L->top-1); + } + g = G(L); + if (tvistab(o)) { + setgcref(tabV(o)->metatable, obj2gco(mt)); + if (mt) + lj_gc_objbarriert(L, tabV(o), mt); + } else if (tvisudata(o)) { + setgcref(udataV(o)->metatable, obj2gco(mt)); + if (mt) + lj_gc_objbarrier(L, udataV(o), mt); + } else { + /* Flush cache, since traces specialize to basemt. But not during __gc. */ + if (lj_trace_flushall(L)) + lj_err_caller(L, LJ_ERR_NOGCMM); + if (tvisbool(o)) { + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_it(g, LJ_TTRUE), obj2gco(mt)); + setgcref(basemt_it(g, LJ_TFALSE), obj2gco(mt)); + } else { + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_obj(g, o), obj2gco(mt)); + } + } + L->top--; + return 1; +} + +LUA_API int lua_setfenv(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + GCtab *t; + api_checknelems(L, 1); + api_checkvalidindex(L, o); + api_check(L, tvistab(L->top-1)); + t = tabV(L->top-1); + if (tvisfunc(o)) { + setgcref(funcV(o)->c.env, obj2gco(t)); + } else if (tvisudata(o)) { + setgcref(udataV(o)->env, obj2gco(t)); + } else if (tvisthread(o)) { + setgcref(threadV(o)->env, obj2gco(t)); + } else { + L->top--; + return 0; + } + lj_gc_objbarrier(L, gcV(o), t); + L->top--; + return 1; +} + +LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n) +{ + cTValue *f = index2adr(L, idx); + TValue *val; + const char *name; + api_checknelems(L, 1); + name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val); + if (name) { + L->top--; + copyTV(L, val, L->top); + lj_gc_barrier(L, funcV(f), L->top); + } + return name; +} + +/* -- Calls --------------------------------------------------------------- */ + +LUA_API void lua_call(lua_State *L, int nargs, int nresults) +{ + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + api_checknelems(L, nargs+1); + lj_vm_call(L, L->top - nargs, nresults+1); +} + +LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc) +{ + global_State *g = G(L); + uint8_t oldh = hook_save(g); + ptrdiff_t ef; + int status; + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + api_checknelems(L, nargs+1); + if (errfunc == 0) { + ef = 0; + } else { + cTValue *o = stkindex2adr(L, errfunc); + api_checkvalidindex(L, o); + ef = savestack(L, o); + } + status = lj_vm_pcall(L, L->top - nargs, nresults+1, ef); + if (status) hook_restore(g, oldh); + return status; +} + +static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud) +{ + GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L)); + fn->c.f = func; + setfuncV(L, L->top, fn); + setlightudV(L->top+1, checklightudptr(L, ud)); + cframe_nres(L->cframe) = 1+0; /* Zero results. */ + L->top += 2; + return L->top-1; /* Now call the newly allocated C function. */ +} + +LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud) +{ + global_State *g = G(L); + uint8_t oldh = hook_save(g); + int status; + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + status = lj_vm_cpcall(L, func, ud, cpcall); + if (status) hook_restore(g, oldh); + return status; +} + +LUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field) +{ + if (luaL_getmetafield(L, idx, field)) { + TValue *base = L->top--; + copyTV(L, base, index2adr(L, idx)); + L->top = base+1; + lj_vm_call(L, base, 1+1); + return 1; + } + return 0; +} + +/* -- Coroutine yield and resume ------------------------------------------ */ + +LUA_API int lua_yield(lua_State *L, int nresults) +{ + void *cf = L->cframe; + global_State *g = G(L); + if (cframe_canyield(cf)) { + cf = cframe_raw(cf); + if (!hook_active(g)) { /* Regular yield: move results down if needed. */ + cTValue *f = L->top - nresults; + if (f > L->base) { + TValue *t = L->base; + while (--nresults >= 0) copyTV(L, t++, f++); + L->top = t; + } + L->cframe = NULL; + L->status = LUA_YIELD; + return -1; + } else { /* Yield from hook: add a pseudo-frame. */ + TValue *top = L->top; + hook_leave(g); + top->u64 = cframe_multres(cf); + setcont(top+1, lj_cont_hook); + setframe_pc(top+1, cframe_pc(cf)-1); + setframe_gc(top+2, obj2gco(L)); + setframe_ftsz(top+2, (int)((char *)(top+3)-(char *)L->base)+FRAME_CONT); + L->top = L->base = top+3; +#if LJ_TARGET_X64 + lj_err_throw(L, LUA_YIELD); +#else + L->cframe = NULL; + L->status = LUA_YIELD; + lj_vm_unwind_c(cf, LUA_YIELD); +#endif + } + } + lj_err_msg(L, LJ_ERR_CYIELD); + return 0; /* unreachable */ +} + +LUA_API int lua_resume(lua_State *L, int nargs) +{ + if (L->cframe == NULL && L->status <= LUA_YIELD) + return lj_vm_resume(L, L->top - nargs, 0, 0); + L->top = L->base; + setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP)); + incr_top(L); + return LUA_ERRRUN; +} + +/* -- GC and memory management -------------------------------------------- */ + +LUA_API int lua_gc(lua_State *L, int what, int data) +{ + global_State *g = G(L); + int res = 0; + switch (what) { + case LUA_GCSTOP: + g->gc.threshold = LJ_MAX_MEM; + break; + case LUA_GCRESTART: + g->gc.threshold = data == -1 ? (g->gc.total/100)*g->gc.pause : g->gc.total; + break; + case LUA_GCCOLLECT: + lj_gc_fullgc(L); + break; + case LUA_GCCOUNT: + res = (int)(g->gc.total >> 10); + break; + case LUA_GCCOUNTB: + res = (int)(g->gc.total & 0x3ff); + break; + case LUA_GCSTEP: { + MSize a = (MSize)data << 10; + g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0; + while (g->gc.total >= g->gc.threshold) + if (lj_gc_step(L) > 0) { + res = 1; + break; + } + break; + } + case LUA_GCSETPAUSE: + res = (int)(g->gc.pause); + g->gc.pause = (MSize)data; + break; + case LUA_GCSETSTEPMUL: + res = (int)(g->gc.stepmul); + g->gc.stepmul = (MSize)data; + break; + default: + res = -1; /* Invalid option. */ + } + return res; +} + +LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud) +{ + global_State *g = G(L); + if (ud) *ud = g->allocd; + return g->allocf; +} + +LUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud) +{ + global_State *g = G(L); + g->allocd = ud; + g->allocf = f; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_arch.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_arch.h new file mode 100644 index 0000000..0196eed --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_arch.h @@ -0,0 +1,426 @@ +/* +** Target architecture selection. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_ARCH_H +#define _LJ_ARCH_H + +#include "lua.h" + +/* Target endianess. */ +#define LUAJIT_LE 0 +#define LUAJIT_BE 1 + +/* Target architectures. */ +#define LUAJIT_ARCH_X86 1 +#define LUAJIT_ARCH_x86 1 +#define LUAJIT_ARCH_X64 2 +#define LUAJIT_ARCH_x64 2 +#define LUAJIT_ARCH_ARM 3 +#define LUAJIT_ARCH_arm 3 +#define LUAJIT_ARCH_PPC 4 +#define LUAJIT_ARCH_ppc 4 +#define LUAJIT_ARCH_PPCSPE 5 +#define LUAJIT_ARCH_ppcspe 5 +#define LUAJIT_ARCH_MIPS 6 +#define LUAJIT_ARCH_mips 6 + +/* Target OS. */ +#define LUAJIT_OS_OTHER 0 +#define LUAJIT_OS_WINDOWS 1 +#define LUAJIT_OS_LINUX 2 +#define LUAJIT_OS_OSX 3 +#define LUAJIT_OS_BSD 4 +#define LUAJIT_OS_POSIX 5 + +/* Select native target if no target defined. */ +#ifndef LUAJIT_TARGET + +#if defined(__i386) || defined(__i386__) || defined(_M_IX86) +#define LUAJIT_TARGET LUAJIT_ARCH_X86 +#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) +#define LUAJIT_TARGET LUAJIT_ARCH_X64 +#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM) +#define LUAJIT_TARGET LUAJIT_ARCH_ARM +#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC) +#ifdef __NO_FPRS__ +#define LUAJIT_TARGET LUAJIT_ARCH_PPCSPE +#else +#define LUAJIT_TARGET LUAJIT_ARCH_PPC +#endif +#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS) +#define LUAJIT_TARGET LUAJIT_ARCH_MIPS +#else +#error "No support for this architecture (yet)" +#endif + +#endif + +/* Select native OS if no target OS defined. */ +#ifndef LUAJIT_OS + +#if defined(_WIN32) && !defined(_XBOX_VER) +#define LUAJIT_OS LUAJIT_OS_WINDOWS +#elif defined(__linux__) +#define LUAJIT_OS LUAJIT_OS_LINUX +#elif defined(__MACH__) && defined(__APPLE__) +#define LUAJIT_OS LUAJIT_OS_OSX +#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__) +#define LUAJIT_OS LUAJIT_OS_BSD +#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__) +#define LUAJIT_OS LUAJIT_OS_POSIX +#else +#define LUAJIT_OS LUAJIT_OS_OTHER +#endif + +#endif + +/* Set target OS properties. */ +#if LUAJIT_OS == LUAJIT_OS_WINDOWS +#define LJ_OS_NAME "Windows" +#elif LUAJIT_OS == LUAJIT_OS_LINUX +#define LJ_OS_NAME "Linux" +#elif LUAJIT_OS == LUAJIT_OS_OSX +#define LJ_OS_NAME "OSX" +#elif LUAJIT_OS == LUAJIT_OS_BSD +#define LJ_OS_NAME "BSD" +#elif LUAJIT_OS == LUAJIT_OS_POSIX +#define LJ_OS_NAME "POSIX" +#else +#define LJ_OS_NAME "Other" +#endif + +#define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS) +#define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX) +#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX) +#define LJ_TARGET_IOS (LJ_TARGET_OSX && LUAJIT_TARGET == LUAJIT_ARCH_ARM) +#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS) +#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX + +#ifdef __CELLOS_LV2__ +#define LJ_TARGET_PS3 1 +#define LJ_TARGET_CONSOLE 1 +#endif + +#ifdef __ORBIS__ +#define LJ_TARGET_PS4 1 +#define LJ_TARGET_CONSOLE 1 +#undef NULL +#define NULL ((void*)0) +#endif + +#if _XBOX_VER >= 200 +#define LJ_TARGET_XBOX360 1 +#define LJ_TARGET_CONSOLE 1 +#endif + +#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */ +#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */ +#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */ +#define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */ + +/* Set target architecture properties. */ +#if LUAJIT_TARGET == LUAJIT_ARCH_X86 + +#define LJ_ARCH_NAME "x86" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#if LJ_TARGET_WINDOWS || __CYGWIN__ +#define LJ_ABI_WIN 1 +#else +#define LJ_ABI_WIN 0 +#endif +#define LJ_TARGET_X86 1 +#define LJ_TARGET_X86ORX64 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNALIGNED 1 +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL + +#elif LUAJIT_TARGET == LUAJIT_ARCH_X64 + +#define LJ_ARCH_NAME "x64" +#define LJ_ARCH_BITS 64 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#define LJ_ABI_WIN LJ_TARGET_WINDOWS +#define LJ_TARGET_X64 1 +#define LJ_TARGET_X86ORX64 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */ +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNALIGNED 1 +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL + +#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM + +#define LJ_ARCH_NAME "arm" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__ +#define LJ_ARCH_HASFPU 0 +#endif +#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP +#define LJ_ABI_SOFTFP 1 +#endif +#define LJ_ABI_EABI 1 +#define LJ_TARGET_ARM 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL + +#if __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ +#define LJ_ARCH_VERSION 70 +#elif __ARM_ARCH_6T2__ +#define LJ_ARCH_VERSION 61 +#elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__ +#define LJ_ARCH_VERSION 60 +#else +#define LJ_ARCH_VERSION 50 +#endif + +#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC + +#define LJ_ARCH_NAME "ppc" +#if _LP64 +#define LJ_ARCH_BITS 64 +#else +#define LJ_ARCH_BITS 32 +#endif +#define LJ_ARCH_ENDIAN LUAJIT_BE +#define LJ_TARGET_PPC 1 +#define LJ_TARGET_EHRETREG 3 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE + +#if _ARCH_PWR7 +#define LJ_ARCH_VERSION 70 +#elif _ARCH_PWR6 +#define LJ_ARCH_VERSION 60 +#elif _ARCH_PWR5X +#define LJ_ARCH_VERSION 51 +#elif _ARCH_PWR5 +#define LJ_ARCH_VERSION 50 +#elif _ARCH_PWR4 +#define LJ_ARCH_VERSION 40 +#else +#define LJ_ARCH_VERSION 0 +#endif +#if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE +#define LJ_ARCH_PPC64 1 +#define LJ_ARCH_NOFFI 1 +#endif +#if _ARCH_PPCSQ +#define LJ_ARCH_SQRT 1 +#endif +#if _ARCH_PWR5X +#define LJ_ARCH_ROUND 1 +#endif +#if __PPU__ +#define LJ_ARCH_CELL 1 +#endif +#if LJ_TARGET_XBOX360 +#define LJ_ARCH_XENON 1 +#endif + +#elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE + +#define LJ_ARCH_NAME "ppcspe" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_BE +#ifndef LJ_ABI_SOFTFP +#define LJ_ABI_SOFTFP 1 +#endif +#define LJ_ABI_EABI 1 +#define LJ_TARGET_PPCSPE 1 +#define LJ_TARGET_EHRETREG 3 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE +#define LJ_ARCH_NOFFI 1 /* NYI: comparisons, calls. */ +#define LJ_ARCH_NOJIT 1 + +#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS + +#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) +#define LJ_ARCH_NAME "mipsel" +#define LJ_ARCH_ENDIAN LUAJIT_LE +#else +#define LJ_ARCH_NAME "mips" +#define LJ_ARCH_ENDIAN LUAJIT_BE +#endif +#define LJ_ARCH_BITS 32 +#define LJ_TARGET_MIPS 1 +#define LJ_TARGET_EHRETREG 4 +#define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */ +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE + +#if _MIPS_ARCH_MIPS32R2 +#define LJ_ARCH_VERSION 20 +#else +#define LJ_ARCH_VERSION 10 +#endif + +#else +#error "No target architecture defined" +#endif + +#ifndef LJ_PAGESIZE +#define LJ_PAGESIZE 4096 +#endif + +/* Check for minimum required compiler versions. */ +#if defined(__GNUC__) +#if LJ_TARGET_X86 +#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4) +#error "Need at least GCC 3.4 or newer" +#endif +#elif LJ_TARGET_X64 +#if __GNUC__ < 4 +#error "Need at least GCC 4.0 or newer" +#endif +#elif LJ_TARGET_ARM +#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2) +#error "Need at least GCC 4.2 or newer" +#endif +#elif !LJ_TARGET_PS3 +#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3) +#error "Need at least GCC 4.3 or newer" +#endif +#endif +#endif + +/* Check target-specific constraints. */ +#ifndef _BUILDVM_H +#if LJ_TARGET_X64 +#if __USING_SJLJ_EXCEPTIONS__ +#error "Need a C compiler with native exception handling on x64" +#endif +#elif LJ_TARGET_ARM +#if defined(__ARMEB__) +#error "No support for big-endian ARM" +#endif +#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ +#error "No support for Cortex-M CPUs" +#endif +#if !(__ARM_EABI__ || LJ_TARGET_IOS) +#error "Only ARM EABI or iOS 3.0+ ABI is supported" +#endif +#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE +#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE) +#error "No support for PowerPC CPUs without double-precision FPU" +#endif +#if defined(_LITTLE_ENDIAN) +#error "No support for little-endian PowerPC" +#endif +#if defined(_LP64) +#error "No support for PowerPC 64 bit mode" +#endif +#elif LJ_TARGET_MIPS +#if defined(__mips_soft_float) +#error "No support for MIPS CPUs without FPU" +#endif +#endif +#endif + +/* Enable or disable the dual-number mode for the VM. */ +#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1) +#error "No support for this number mode on this architecture" +#endif +#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2) +#define LJ_DUALNUM 1 +#else +#define LJ_DUALNUM 0 +#endif + +#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE +/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */ +/* Ditto for the consoles. Complain to Sony or MS, not me. */ +#ifndef LUAJIT_ENABLE_JIT +#define LJ_OS_NOJIT 1 +#endif +#endif + +/* Disable or enable the JIT compiler. */ +#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT) +#define LJ_HASJIT 0 +#else +#define LJ_HASJIT 1 +#endif + +/* Disable or enable the FFI extension. */ +#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI) +#define LJ_HASFFI 0 +#else +#define LJ_HASFFI 1 +#endif + +#ifndef LJ_ARCH_HASFPU +#define LJ_ARCH_HASFPU 1 +#endif +#ifndef LJ_ABI_SOFTFP +#define LJ_ABI_SOFTFP 0 +#endif +#define LJ_SOFTFP (!LJ_ARCH_HASFPU) + +#if LJ_ARCH_ENDIAN == LUAJIT_BE +#define LJ_LE 0 +#define LJ_BE 1 +#define LJ_ENDIAN_SELECT(le, be) be +#define LJ_ENDIAN_LOHI(lo, hi) hi lo +#else +#define LJ_LE 1 +#define LJ_BE 0 +#define LJ_ENDIAN_SELECT(le, be) le +#define LJ_ENDIAN_LOHI(lo, hi) lo hi +#endif + +#if LJ_ARCH_BITS == 32 +#define LJ_32 1 +#define LJ_64 0 +#else +#define LJ_32 0 +#define LJ_64 1 +#endif + +#ifndef LJ_TARGET_UNALIGNED +#define LJ_TARGET_UNALIGNED 0 +#endif + +/* Various workarounds for embedded operating systems. */ +#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360 +#define LUAJIT_NO_LOG2 +#endif +#if defined(__symbian__) +#define LUAJIT_NO_EXP2 +#endif + +#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 +#define LJ_NO_UNWIND 1 +#endif + +/* Compatibility with Lua 5.1 vs. 5.2. */ +#ifdef LUAJIT_ENABLE_LUA52COMPAT +#define LJ_52 1 +#else +#define LJ_52 0 +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.c new file mode 100644 index 0000000..264649a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.c @@ -0,0 +1,1914 @@ +/* +** IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_asm_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_mcode.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_asm.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_target.h" + +#ifdef LUA_USE_ASSERT +#include +#endif + +/* -- Assembler state and common macros ----------------------------------- */ + +/* Assembler state. */ +typedef struct ASMState { + RegCost cost[RID_MAX]; /* Reference and blended allocation cost for regs. */ + + MCode *mcp; /* Current MCode pointer (grows down). */ + MCode *mclim; /* Lower limit for MCode memory + red zone. */ +#ifdef LUA_USE_ASSERT + MCode *mcp_prev; /* Red zone overflow check. */ +#endif + + IRIns *ir; /* Copy of pointer to IR instructions/constants. */ + jit_State *J; /* JIT compiler state. */ + +#if LJ_TARGET_X86ORX64 + x86ModRM mrm; /* Fused x86 address operand. */ +#endif + + RegSet freeset; /* Set of free registers. */ + RegSet modset; /* Set of registers modified inside the loop. */ + RegSet weakset; /* Set of weakly referenced registers. */ + RegSet phiset; /* Set of PHI registers. */ + + uint32_t flags; /* Copy of JIT compiler flags. */ + int loopinv; /* Loop branch inversion (0:no, 1:yes, 2:yes+CC_P). */ + + int32_t evenspill; /* Next even spill slot. */ + int32_t oddspill; /* Next odd spill slot (or 0). */ + + IRRef curins; /* Reference of current instruction. */ + IRRef stopins; /* Stop assembly before hitting this instruction. */ + IRRef orignins; /* Original T->nins. */ + + IRRef snapref; /* Current snapshot is active after this reference. */ + IRRef snaprename; /* Rename highwater mark for snapshot check. */ + SnapNo snapno; /* Current snapshot number. */ + SnapNo loopsnapno; /* Loop snapshot number. */ + + IRRef fuseref; /* Fusion limit (loopref, 0 or FUSE_DISABLED). */ + IRRef sectref; /* Section base reference (loopref or 0). */ + IRRef loopref; /* Reference of LOOP instruction (or 0). */ + + BCReg topslot; /* Number of slots for stack check (unless 0). */ + int32_t gcsteps; /* Accumulated number of GC steps (per section). */ + + GCtrace *T; /* Trace to assemble. */ + GCtrace *parent; /* Parent trace (or NULL). */ + + MCode *mcbot; /* Bottom of reserved MCode. */ + MCode *mctop; /* Top of generated MCode. */ + MCode *mcloop; /* Pointer to loop MCode (or NULL). */ + MCode *invmcp; /* Points to invertible loop branch (or NULL). */ + MCode *flagmcp; /* Pending opportunity to merge flag setting ins. */ + MCode *realign; /* Realign loop if not NULL. */ + +#ifdef RID_NUM_KREF + int32_t krefk[RID_NUM_KREF]; +#endif + IRRef1 phireg[RID_MAX]; /* PHI register references. */ + uint16_t parentmap[LJ_MAX_JSLOTS]; /* Parent instruction to RegSP map. */ +} ASMState; + +#define IR(ref) (&as->ir[(ref)]) + +#define ASMREF_TMP1 REF_TRUE /* Temp. register. */ +#define ASMREF_TMP2 REF_FALSE /* Temp. register. */ +#define ASMREF_L REF_NIL /* Stores register for L. */ + +/* Check for variant to invariant references. */ +#define iscrossref(as, ref) ((ref) < as->sectref) + +/* Inhibit memory op fusion from variant to invariant references. */ +#define FUSE_DISABLED (~(IRRef)0) +#define mayfuse(as, ref) ((ref) > as->fuseref) +#define neverfuse(as) (as->fuseref == FUSE_DISABLED) +#define canfuse(as, ir) (!neverfuse(as) && !irt_isphi((ir)->t)) +#define opisfusableload(o) \ + ((o) == IR_ALOAD || (o) == IR_HLOAD || (o) == IR_ULOAD || \ + (o) == IR_FLOAD || (o) == IR_XLOAD || (o) == IR_SLOAD || (o) == IR_VLOAD) + +/* Sparse limit checks using a red zone before the actual limit. */ +#define MCLIM_REDZONE 64 + +static LJ_NORET LJ_NOINLINE void asm_mclimit(ASMState *as) +{ + lj_mcode_limiterr(as->J, (size_t)(as->mctop - as->mcp + 4*MCLIM_REDZONE)); +} + +static LJ_AINLINE void checkmclim(ASMState *as) +{ +#ifdef LUA_USE_ASSERT + if (as->mcp + MCLIM_REDZONE < as->mcp_prev) { + IRIns *ir = IR(as->curins+1); + fprintf(stderr, "RED ZONE OVERFLOW: %p IR %04d %02d %04d %04d\n", as->mcp, + as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS); + lua_assert(0); + } +#endif + if (LJ_UNLIKELY(as->mcp < as->mclim)) asm_mclimit(as); +#ifdef LUA_USE_ASSERT + as->mcp_prev = as->mcp; +#endif +} + +#ifdef RID_NUM_KREF +#define ra_iskref(ref) ((ref) < RID_NUM_KREF) +#define ra_krefreg(ref) ((Reg)(RID_MIN_KREF + (Reg)(ref))) +#define ra_krefk(as, ref) (as->krefk[(ref)]) + +static LJ_AINLINE void ra_setkref(ASMState *as, Reg r, int32_t k) +{ + IRRef ref = (IRRef)(r - RID_MIN_KREF); + as->krefk[ref] = k; + as->cost[r] = REGCOST(ref, ref); +} + +#else +#define ra_iskref(ref) 0 +#define ra_krefreg(ref) RID_MIN_GPR +#define ra_krefk(as, ref) 0 +#endif + +/* Arch-specific field offsets. */ +static const uint8_t field_ofs[IRFL__MAX+1] = { +#define FLOFS(name, ofs) (uint8_t)(ofs), +IRFLDEF(FLOFS) +#undef FLOFS + 0 +}; + +/* -- Target-specific instruction emitter --------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_emit_x86.h" +#elif LJ_TARGET_ARM +#include "lj_emit_arm.h" +#elif LJ_TARGET_PPC +#include "lj_emit_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_emit_mips.h" +#else +#error "Missing instruction emitter for target CPU" +#endif + +/* -- Register allocator debugging ---------------------------------------- */ + +/* #define LUAJIT_DEBUG_RA */ + +#ifdef LUAJIT_DEBUG_RA + +#include +#include + +#define RIDNAME(name) #name, +static const char *const ra_regname[] = { + GPRDEF(RIDNAME) + FPRDEF(RIDNAME) + VRIDDEF(RIDNAME) + NULL +}; +#undef RIDNAME + +static char ra_dbg_buf[65536]; +static char *ra_dbg_p; +static char *ra_dbg_merge; +static MCode *ra_dbg_mcp; + +static void ra_dstart(void) +{ + ra_dbg_p = ra_dbg_buf; + ra_dbg_merge = NULL; + ra_dbg_mcp = NULL; +} + +static void ra_dflush(void) +{ + fwrite(ra_dbg_buf, 1, (size_t)(ra_dbg_p-ra_dbg_buf), stdout); + ra_dstart(); +} + +static void ra_dprintf(ASMState *as, const char *fmt, ...) +{ + char *p; + va_list argp; + va_start(argp, fmt); + p = ra_dbg_mcp == as->mcp ? ra_dbg_merge : ra_dbg_p; + ra_dbg_mcp = NULL; + p += sprintf(p, "%08x \e[36m%04d ", (uintptr_t)as->mcp, as->curins-REF_BIAS); + for (;;) { + const char *e = strchr(fmt, '$'); + if (e == NULL) break; + memcpy(p, fmt, (size_t)(e-fmt)); + p += e-fmt; + if (e[1] == 'r') { + Reg r = va_arg(argp, Reg) & RID_MASK; + if (r <= RID_MAX) { + const char *q; + for (q = ra_regname[r]; *q; q++) + *p++ = *q >= 'A' && *q <= 'Z' ? *q + 0x20 : *q; + } else { + *p++ = '?'; + lua_assert(0); + } + } else if (e[1] == 'f' || e[1] == 'i') { + IRRef ref; + if (e[1] == 'f') + ref = va_arg(argp, IRRef); + else + ref = va_arg(argp, IRIns *) - as->ir; + if (ref >= REF_BIAS) + p += sprintf(p, "%04d", ref - REF_BIAS); + else + p += sprintf(p, "K%03d", REF_BIAS - ref); + } else if (e[1] == 's') { + uint32_t slot = va_arg(argp, uint32_t); + p += sprintf(p, "[sp+0x%x]", sps_scale(slot)); + } else if (e[1] == 'x') { + p += sprintf(p, "%08x", va_arg(argp, int32_t)); + } else { + lua_assert(0); + } + fmt = e+2; + } + va_end(argp); + while (*fmt) + *p++ = *fmt++; + *p++ = '\e'; *p++ = '['; *p++ = 'm'; *p++ = '\n'; + if (p > ra_dbg_buf+sizeof(ra_dbg_buf)-256) { + fwrite(ra_dbg_buf, 1, (size_t)(p-ra_dbg_buf), stdout); + p = ra_dbg_buf; + } + ra_dbg_p = p; +} + +#define RA_DBG_START() ra_dstart() +#define RA_DBG_FLUSH() ra_dflush() +#define RA_DBG_REF() \ + do { char *_p = ra_dbg_p; ra_dprintf(as, ""); \ + ra_dbg_merge = _p; ra_dbg_mcp = as->mcp; } while (0) +#define RA_DBGX(x) ra_dprintf x + +#else +#define RA_DBG_START() ((void)0) +#define RA_DBG_FLUSH() ((void)0) +#define RA_DBG_REF() ((void)0) +#define RA_DBGX(x) ((void)0) +#endif + +/* -- Register allocator -------------------------------------------------- */ + +#define ra_free(as, r) rset_set(as->freeset, (r)) +#define ra_modified(as, r) rset_set(as->modset, (r)) +#define ra_weak(as, r) rset_set(as->weakset, (r)) +#define ra_noweak(as, r) rset_clear(as->weakset, (r)) + +#define ra_used(ir) (ra_hasreg((ir)->r) || ra_hasspill((ir)->s)) + +/* Setup register allocator. */ +static void ra_setup(ASMState *as) +{ + Reg r; + /* Initially all regs (except the stack pointer) are free for use. */ + as->freeset = RSET_INIT; + as->modset = RSET_EMPTY; + as->weakset = RSET_EMPTY; + as->phiset = RSET_EMPTY; + memset(as->phireg, 0, sizeof(as->phireg)); + for (r = RID_MIN_GPR; r < RID_MAX; r++) + as->cost[r] = REGCOST(~0u, 0u); +} + +/* Rematerialize constants. */ +static Reg ra_rematk(ASMState *as, IRRef ref) +{ + IRIns *ir; + Reg r; + if (ra_iskref(ref)) { + r = ra_krefreg(ref); + lua_assert(!rset_test(as->freeset, r)); + ra_free(as, r); + ra_modified(as, r); + emit_loadi(as, r, ra_krefk(as, ref)); + return r; + } + ir = IR(ref); + r = ir->r; + lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s)); + ra_free(as, r); + ra_modified(as, r); + ir->r = RID_INIT; /* Do not keep any hint. */ + RA_DBGX((as, "remat $i $r", ir, r)); +#if !LJ_SOFTFP + if (ir->o == IR_KNUM) { + emit_loadn(as, r, ir_knum(ir)); + } else +#endif + if (emit_canremat(REF_BASE) && ir->o == IR_BASE) { + ra_sethint(ir->r, RID_BASE); /* Restore BASE register hint. */ + emit_getgl(as, r, jit_base); + } else if (emit_canremat(ASMREF_L) && ir->o == IR_KPRI) { + lua_assert(irt_isnil(ir->t)); /* REF_NIL stores ASMREF_L register. */ + emit_getgl(as, r, jit_L); +#if LJ_64 + } else if (ir->o == IR_KINT64) { + emit_loadu64(as, r, ir_kint64(ir)->u64); +#endif + } else { + lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || + ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); + emit_loadi(as, r, ir->i); + } + return r; +} + +/* Force a spill. Allocate a new spill slot if needed. */ +static int32_t ra_spill(ASMState *as, IRIns *ir) +{ + int32_t slot = ir->s; + if (!ra_hasspill(slot)) { + if (irt_is64(ir->t)) { + slot = as->evenspill; + as->evenspill += 2; + } else if (as->oddspill) { + slot = as->oddspill; + as->oddspill = 0; + } else { + slot = as->evenspill; + as->oddspill = slot+1; + as->evenspill += 2; + } + if (as->evenspill > 256) + lj_trace_err(as->J, LJ_TRERR_SPILLOV); + ir->s = (uint8_t)slot; + } + return sps_scale(slot); +} + +/* Release the temporarily allocated register in ASMREF_TMP1/ASMREF_TMP2. */ +static Reg ra_releasetmp(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + Reg r = ir->r; + lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s)); + ra_free(as, r); + ra_modified(as, r); + ir->r = RID_INIT; + return r; +} + +/* Restore a register (marked as free). Rematerialize or force a spill. */ +static Reg ra_restore(ASMState *as, IRRef ref) +{ + if (emit_canremat(ref)) { + return ra_rematk(as, ref); + } else { + IRIns *ir = IR(ref); + int32_t ofs = ra_spill(as, ir); /* Force a spill slot. */ + Reg r = ir->r; + lua_assert(ra_hasreg(r)); + ra_sethint(ir->r, r); /* Keep hint. */ + ra_free(as, r); + if (!rset_test(as->weakset, r)) { /* Only restore non-weak references. */ + ra_modified(as, r); + RA_DBGX((as, "restore $i $r", ir, r)); + emit_spload(as, ir, r, ofs); + } + return r; + } +} + +/* Save a register to a spill slot. */ +static void ra_save(ASMState *as, IRIns *ir, Reg r) +{ + RA_DBGX((as, "save $i $r", ir, r)); + emit_spstore(as, ir, r, sps_scale(ir->s)); +} + +#define MINCOST(name) \ + if (rset_test(RSET_ALL, RID_##name) && \ + LJ_LIKELY(allow&RID2RSET(RID_##name)) && as->cost[RID_##name] < cost) \ + cost = as->cost[RID_##name]; + +/* Evict the register with the lowest cost, forcing a restore. */ +static Reg ra_evict(ASMState *as, RegSet allow) +{ + IRRef ref; + RegCost cost = ~(RegCost)0; + lua_assert(allow != RSET_EMPTY); + if (RID_NUM_FPR == 0 || allow < RID2RSET(RID_MAX_GPR)) { + GPRDEF(MINCOST) + } else { + FPRDEF(MINCOST) + } + ref = regcost_ref(cost); + lua_assert(ra_iskref(ref) || (ref >= as->T->nk && ref < as->T->nins)); + /* Preferably pick any weak ref instead of a non-weak, non-const ref. */ + if (!irref_isk(ref) && (as->weakset & allow)) { + IRIns *ir = IR(ref); + if (!rset_test(as->weakset, ir->r)) + ref = regcost_ref(as->cost[rset_pickbot((as->weakset & allow))]); + } + return ra_restore(as, ref); +} + +/* Pick any register (marked as free). Evict on-demand. */ +static Reg ra_pick(ASMState *as, RegSet allow) +{ + RegSet pick = as->freeset & allow; + if (!pick) + return ra_evict(as, allow); + else + return rset_picktop(pick); +} + +/* Get a scratch register (marked as free). */ +static Reg ra_scratch(ASMState *as, RegSet allow) +{ + Reg r = ra_pick(as, allow); + ra_modified(as, r); + RA_DBGX((as, "scratch $r", r)); + return r; +} + +/* Evict all registers from a set (if not free). */ +static void ra_evictset(ASMState *as, RegSet drop) +{ + RegSet work; + as->modset |= drop; +#if !LJ_SOFTFP + work = (drop & ~as->freeset) & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +#endif + work = (drop & ~as->freeset); + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +} + +/* Evict (rematerialize) all registers allocated to constants. */ +static void ra_evictk(ASMState *as) +{ + RegSet work; +#if !LJ_SOFTFP + work = ~as->freeset & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + if (emit_canremat(ref) && irref_isk(ref)) { + ra_rematk(as, ref); + checkmclim(as); + } + rset_clear(work, r); + } +#endif + work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + if (emit_canremat(ref) && irref_isk(ref)) { + ra_rematk(as, ref); + checkmclim(as); + } + rset_clear(work, r); + } +} + +#ifdef RID_NUM_KREF +/* Allocate a register for a constant. */ +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow) +{ + /* First try to find a register which already holds the same constant. */ + RegSet pick, work = ~as->freeset & RSET_GPR; + Reg r; + while (work) { + IRRef ref; + r = rset_pickbot(work); + ref = regcost_ref(as->cost[r]); + if (ref < ASMREF_L && + k == (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i)) + return r; + rset_clear(work, r); + } + pick = as->freeset & allow; + if (pick) { + /* Constants should preferably get unmodified registers. */ + if ((pick & ~as->modset)) + pick &= ~as->modset; + r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */ + } else { + r = ra_evict(as, allow); + } + RA_DBGX((as, "allock $x $r", k, r)); + ra_setkref(as, r, k); + rset_clear(as->freeset, r); + ra_noweak(as, r); + return r; +} + +/* Allocate a specific register for a constant. */ +static void ra_allockreg(ASMState *as, int32_t k, Reg r) +{ + Reg kr = ra_allock(as, k, RID2RSET(r)); + if (kr != r) { + IRIns irdummy; + irdummy.t.irt = IRT_INT; + ra_scratch(as, RID2RSET(r)); + emit_movrr(as, &irdummy, r, kr); + } +} +#else +#define ra_allockreg(as, k, r) emit_loadi(as, (r), (k)) +#endif + +/* Allocate a register for ref from the allowed set of registers. +** Note: this function assumes the ref does NOT have a register yet! +** Picks an optimal register, sets the cost and marks the register as non-free. +*/ +static Reg ra_allocref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + RegSet pick = as->freeset & allow; + Reg r; + lua_assert(ra_noreg(ir->r)); + if (pick) { + /* First check register hint from propagation or PHI. */ + if (ra_hashint(ir->r)) { + r = ra_gethint(ir->r); + if (rset_test(pick, r)) /* Use hint register if possible. */ + goto found; + /* Rematerialization is cheaper than missing a hint. */ + if (rset_test(allow, r) && emit_canremat(regcost_ref(as->cost[r]))) { + ra_rematk(as, regcost_ref(as->cost[r])); + goto found; + } + RA_DBGX((as, "hintmiss $f $r", ref, r)); + } + /* Invariants should preferably get unmodified registers. */ + if (ref < as->loopref && !irt_isphi(ir->t)) { + if ((pick & ~as->modset)) + pick &= ~as->modset; + r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */ + } else { + /* We've got plenty of regs, so get callee-save regs if possible. */ + if (RID_NUM_GPR > 8 && (pick & ~RSET_SCRATCH)) + pick &= ~RSET_SCRATCH; + r = rset_picktop(pick); + } + } else { + r = ra_evict(as, allow); + } +found: + RA_DBGX((as, "alloc $f $r", ref, r)); + ir->r = (uint8_t)r; + rset_clear(as->freeset, r); + ra_noweak(as, r); + as->cost[r] = REGCOST_REF_T(ref, irt_t(ir->t)); + return r; +} + +/* Allocate a register on-demand. */ +static Reg ra_alloc1(ASMState *as, IRRef ref, RegSet allow) +{ + Reg r = IR(ref)->r; + /* Note: allow is ignored if the register is already allocated. */ + if (ra_noreg(r)) r = ra_allocref(as, ref, allow); + ra_noweak(as, r); + return r; +} + +/* Rename register allocation and emit move. */ +static void ra_rename(ASMState *as, Reg down, Reg up) +{ + IRRef ren, ref = regcost_ref(as->cost[up] = as->cost[down]); + IRIns *ir = IR(ref); + ir->r = (uint8_t)up; + as->cost[down] = 0; + lua_assert((down < RID_MAX_GPR) == (up < RID_MAX_GPR)); + lua_assert(!rset_test(as->freeset, down) && rset_test(as->freeset, up)); + ra_free(as, down); /* 'down' is free ... */ + ra_modified(as, down); + rset_clear(as->freeset, up); /* ... and 'up' is now allocated. */ + ra_noweak(as, up); + RA_DBGX((as, "rename $f $r $r", regcost_ref(as->cost[up]), down, up)); + emit_movrr(as, ir, down, up); /* Backwards codegen needs inverse move. */ + if (!ra_hasspill(IR(ref)->s)) { /* Add the rename to the IR. */ + lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), ref, as->snapno); + ren = tref_ref(lj_ir_emit(as->J)); + as->ir = as->T->ir; /* The IR may have been reallocated. */ + IR(ren)->r = (uint8_t)down; + IR(ren)->s = SPS_NONE; + } +} + +/* Pick a destination register (marked as free). +** Caveat: allow is ignored if there's already a destination register. +** Use ra_destreg() to get a specific register. +*/ +static Reg ra_dest(ASMState *as, IRIns *ir, RegSet allow) +{ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + } else { + if (ra_hashint(dest) && rset_test((as->freeset&allow), ra_gethint(dest))) { + dest = ra_gethint(dest); + ra_modified(as, dest); + RA_DBGX((as, "dest $r", dest)); + } else { + dest = ra_scratch(as, allow); + } + ir->r = dest; + } + if (LJ_UNLIKELY(ra_hasspill(ir->s))) ra_save(as, ir, dest); + return dest; +} + +/* Force a specific destination register (marked as free). */ +static void ra_destreg(ASMState *as, IRIns *ir, Reg r) +{ + Reg dest = ra_dest(as, ir, RID2RSET(r)); + if (dest != r) { + lua_assert(rset_test(as->freeset, r)); + ra_modified(as, r); + emit_movrr(as, ir, dest, r); + } +} + +#if LJ_TARGET_X86ORX64 +/* Propagate dest register to left reference. Emit moves as needed. +** This is a required fixup step for all 2-operand machine instructions. +*/ +static void ra_left(ASMState *as, Reg dest, IRRef lref) +{ + IRIns *ir = IR(lref); + Reg left = ir->r; + if (ra_noreg(left)) { + if (irref_isk(lref)) { + if (ir->o == IR_KNUM) { + cTValue *tv = ir_knum(ir); + /* FP remat needs a load except for +0. Still better than eviction. */ + if (tvispzero(tv) || !(as->freeset & RSET_FPR)) { + emit_loadn(as, dest, tv); + return; + } +#if LJ_64 + } else if (ir->o == IR_KINT64) { + emit_loadu64(as, dest, ir_kint64(ir)->u64); + return; +#endif + } else { + lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || + ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); + emit_loadi(as, dest, ir->i); + return; + } + } + if (!ra_hashint(left) && !iscrossref(as, lref)) + ra_sethint(ir->r, dest); /* Propagate register hint. */ + left = ra_allocref(as, lref, dest < RID_MAX_GPR ? RSET_GPR : RSET_FPR); + } + ra_noweak(as, left); + /* Move needed for true 3-operand instruction: y=a+b ==> y=a; y+=b. */ + if (dest != left) { + /* Use register renaming if dest is the PHI reg. */ + if (irt_isphi(ir->t) && as->phireg[dest] == lref) { + ra_modified(as, left); + ra_rename(as, left, dest); + } else { + emit_movrr(as, ir, dest, left); + } + } +} +#else +/* Similar to ra_left, except we override any hints. */ +static void ra_leftov(ASMState *as, Reg dest, IRRef lref) +{ + IRIns *ir = IR(lref); + Reg left = ir->r; + if (ra_noreg(left)) { + ra_sethint(ir->r, dest); /* Propagate register hint. */ + left = ra_allocref(as, lref, + (LJ_SOFTFP || dest < RID_MAX_GPR) ? RSET_GPR : RSET_FPR); + } + ra_noweak(as, left); + if (dest != left) { + /* Use register renaming if dest is the PHI reg. */ + if (irt_isphi(ir->t) && as->phireg[dest] == lref) { + ra_modified(as, left); + ra_rename(as, left, dest); + } else { + emit_movrr(as, ir, dest, left); + } + } +} +#endif + +#if !LJ_64 +/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */ +static void ra_destpair(ASMState *as, IRIns *ir) +{ + Reg destlo = ir->r, desthi = (ir+1)->r; + /* First spill unrelated refs blocking the destination registers. */ + if (!rset_test(as->freeset, RID_RETLO) && + destlo != RID_RETLO && desthi != RID_RETLO) + ra_restore(as, regcost_ref(as->cost[RID_RETLO])); + if (!rset_test(as->freeset, RID_RETHI) && + destlo != RID_RETHI && desthi != RID_RETHI) + ra_restore(as, regcost_ref(as->cost[RID_RETHI])); + /* Next free the destination registers (if any). */ + if (ra_hasreg(destlo)) { + ra_free(as, destlo); + ra_modified(as, destlo); + } else { + destlo = RID_RETLO; + } + if (ra_hasreg(desthi)) { + ra_free(as, desthi); + ra_modified(as, desthi); + } else { + desthi = RID_RETHI; + } + /* Check for conflicts and shuffle the registers as needed. */ + if (destlo == RID_RETHI) { + if (desthi == RID_RETLO) { +#if LJ_TARGET_X86 + *--as->mcp = XI_XCHGa + RID_RETHI; +#else + emit_movrr(as, ir, RID_RETHI, RID_TMP); + emit_movrr(as, ir, RID_RETLO, RID_RETHI); + emit_movrr(as, ir, RID_TMP, RID_RETLO); +#endif + } else { + emit_movrr(as, ir, RID_RETHI, RID_RETLO); + if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI); + } + } else if (desthi == RID_RETLO) { + emit_movrr(as, ir, RID_RETLO, RID_RETHI); + if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO); + } else { + if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI); + if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO); + } + /* Restore spill slots (if any). */ + if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI); + if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO); +} +#endif + +/* -- Snapshot handling --------- ----------------------------------------- */ + +/* Can we rematerialize a KNUM instead of forcing a spill? */ +static int asm_snap_canremat(ASMState *as) +{ + Reg r; + for (r = RID_MIN_FPR; r < RID_MAX_FPR; r++) + if (irref_isk(regcost_ref(as->cost[r]))) + return 1; + return 0; +} + +/* Check whether a sunk store corresponds to an allocation. */ +static int asm_sunk_store(ASMState *as, IRIns *ira, IRIns *irs) +{ + if (irs->s == 255) { + if (irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE) { + IRIns *irk = IR(irs->op1); + if (irk->o == IR_AREF || irk->o == IR_HREFK) + irk = IR(irk->op1); + return (IR(irk->op1) == ira); + } + return 0; + } else { + return (ira + irs->s == irs); /* Quick check. */ + } +} + +/* Allocate register or spill slot for a ref that escapes to a snapshot. */ +static void asm_snap_alloc1(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (!irref_isk(ref) && (!(ra_used(ir) || ir->r == RID_SUNK))) { + if (ir->r == RID_SINK) { + ir->r = RID_SUNK; +#if LJ_HASFFI + if (ir->o == IR_CNEWI) { /* Allocate CNEWI value. */ + asm_snap_alloc1(as, ir->op2); + if (LJ_32 && (ir+1)->o == IR_HIOP) + asm_snap_alloc1(as, (ir+1)->op2); + } else +#endif + { /* Allocate stored values for TNEW, TDUP and CNEW. */ + IRIns *irs; + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW); + for (irs = IR(as->snapref-1); irs > ir; irs--) + if (irs->r == RID_SINK && asm_sunk_store(as, ir, irs)) { + lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE); + asm_snap_alloc1(as, irs->op2); + if (LJ_32 && (irs+1)->o == IR_HIOP) + asm_snap_alloc1(as, (irs+1)->op2); + } + } + } else { + RegSet allow; + if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) { + IRIns *irc; + for (irc = IR(as->curins); irc > ir; irc--) + if ((irc->op1 == ref || irc->op2 == ref) && + !(irc->r == RID_SINK || irc->r == RID_SUNK)) + goto nosink; /* Don't sink conversion if result is used. */ + asm_snap_alloc1(as, ir->op1); + return; + } + nosink: + allow = (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR; + if ((as->freeset & allow) || + (allow == RSET_FPR && asm_snap_canremat(as))) { + /* Get a weak register if we have a free one or can rematerialize. */ + Reg r = ra_allocref(as, ref, allow); /* Allocate a register. */ + if (!irt_isphi(ir->t)) + ra_weak(as, r); /* But mark it as weakly referenced. */ + checkmclim(as); + RA_DBGX((as, "snapreg $f $r", ref, ir->r)); + } else { + ra_spill(as, ir); /* Otherwise force a spill slot. */ + RA_DBGX((as, "snapspill $f $s", ref, ir->s)); + } + } + } +} + +/* Allocate refs escaping to a snapshot. */ +static void asm_snap_alloc(ASMState *as) +{ + SnapShot *snap = &as->T->snap[as->snapno]; + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef ref = snap_ref(sn); + if (!irref_isk(ref)) { + asm_snap_alloc1(as, ref); + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) { + lua_assert(irt_type(IR(ref+1)->t) == IRT_SOFTFP); + asm_snap_alloc1(as, ref+1); + } + } + } +} + +/* All guards for a snapshot use the same exitno. This is currently the +** same as the snapshot number. Since the exact origin of the exit cannot +** be determined, all guards for the same snapshot must exit with the same +** RegSP mapping. +** A renamed ref which has been used in a prior guard for the same snapshot +** would cause an inconsistency. The easy way out is to force a spill slot. +*/ +static int asm_snap_checkrename(ASMState *as, IRRef ren) +{ + SnapShot *snap = &as->T->snap[as->snapno]; + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef ref = snap_ref(sn); + if (ref == ren || (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && ++ref == ren)) { + IRIns *ir = IR(ref); + ra_spill(as, ir); /* Register renamed, so force a spill slot. */ + RA_DBGX((as, "snaprensp $f $s", ref, ir->s)); + return 1; /* Found. */ + } + } + return 0; /* Not found. */ +} + +/* Prepare snapshot for next guard instruction. */ +static void asm_snap_prep(ASMState *as) +{ + if (as->curins < as->snapref) { + do { + if (as->snapno == 0) return; /* Called by sunk stores before snap #0. */ + as->snapno--; + as->snapref = as->T->snap[as->snapno].ref; + } while (as->curins < as->snapref); + asm_snap_alloc(as); + as->snaprename = as->T->nins; + } else { + /* Process any renames above the highwater mark. */ + for (; as->snaprename < as->T->nins; as->snaprename++) { + IRIns *ir = IR(as->snaprename); + if (asm_snap_checkrename(as, ir->op1)) + ir->op2 = REF_BIAS-1; /* Kill rename. */ + } + } +} + +/* -- Miscellaneous helpers ----------------------------------------------- */ + +/* Collect arguments from CALL* and CARG instructions. */ +static void asm_collectargs(ASMState *as, IRIns *ir, + const CCallInfo *ci, IRRef *args) +{ + uint32_t n = CCI_NARGS(ci); + lua_assert(n <= CCI_NARGS_MAX*2); /* Account for split args. */ + if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; } + while (n-- > 1) { + ir = IR(ir->op1); + lua_assert(ir->o == IR_CARG); + args[n] = ir->op2 == REF_NIL ? 0 : ir->op2; + } + args[0] = ir->op1 == REF_NIL ? 0 : ir->op1; + lua_assert(IR(ir->op1)->o != IR_CARG); +} + +/* Reconstruct CCallInfo flags for CALLX*. */ +static uint32_t asm_callx_flags(ASMState *as, IRIns *ir) +{ + uint32_t nargs = 0; + if (ir->op1 != REF_NIL) { /* Count number of arguments first. */ + IRIns *ira = IR(ir->op1); + nargs++; + while (ira->o == IR_CARG) { nargs++; ira = IR(ira->op1); } + } +#if LJ_HASFFI + if (IR(ir->op2)->o == IR_CARG) { /* Copy calling convention info. */ + CTypeID id = (CTypeID)IR(IR(ir->op2)->op2)->i; + CType *ct = ctype_get(ctype_ctsG(J2G(as->J)), id); + nargs |= ((ct->info & CTF_VARARG) ? CCI_VARARG : 0); +#if LJ_TARGET_X86 + nargs |= (ctype_cconv(ct->info) << CCI_CC_SHIFT); +#endif + } +#endif + return (nargs | (ir->t.irt << CCI_OTSHIFT)); +} + +/* Calculate stack adjustment. */ +static int32_t asm_stack_adjust(ASMState *as) +{ + if (as->evenspill <= SPS_FIXED) + return 0; + return sps_scale(sps_align(as->evenspill)); +} + +/* Must match with hash*() in lj_tab.c. */ +static uint32_t ir_khash(IRIns *ir) +{ + uint32_t lo, hi; + if (irt_isstr(ir->t)) { + return ir_kstr(ir)->hash; + } else if (irt_isnum(ir->t)) { + lo = ir_knum(ir)->u32.lo; + hi = ir_knum(ir)->u32.hi << 1; + } else if (irt_ispri(ir->t)) { + lua_assert(!irt_isnil(ir->t)); + return irt_type(ir->t)-IRT_FALSE; + } else { + lua_assert(irt_isgcv(ir->t)); + lo = u32ptr(ir_kgc(ir)); + hi = lo + HASH_BIAS; + } + return hashrot(lo, hi); +} + +/* -- Allocations --------------------------------------------------------- */ + +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args); +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci); + +static void asm_snew(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_new]; + IRRef args[3]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* const char *str */ + args[2] = ir->op2; /* size_t len */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); +} + +static void asm_tnew(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_new1]; + IRRef args[2]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* uint32_t ahsize */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCtab * */ + asm_gencall(as, ci, args); + ra_allockreg(as, ir->op1 | (ir->op2 << 24), ra_releasetmp(as, ASMREF_TMP1)); +} + +static void asm_tdup(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_dup]; + IRRef args[2]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* const GCtab *kt */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCtab * */ + asm_gencall(as, ci, args); +} + +static void asm_gc_check(ASMState *as); + +/* Explicit GC step. */ +static void asm_gcstep(ASMState *as, IRIns *ir) +{ + IRIns *ira; + for (ira = IR(as->stopins+1); ira < ir; ira++) + if ((ira->o == IR_TNEW || ira->o == IR_TDUP || + (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI))) && + ra_used(ira)) + as->gcsteps++; + if (as->gcsteps) + asm_gc_check(as); + as->gcsteps = 0x80000000; /* Prevent implicit GC check further up. */ +} + +/* -- PHI and loop handling ----------------------------------------------- */ + +/* Break a PHI cycle by renaming to a free register (evict if needed). */ +static void asm_phi_break(ASMState *as, RegSet blocked, RegSet blockedby, + RegSet allow) +{ + RegSet candidates = blocked & allow; + if (candidates) { /* If this register file has candidates. */ + /* Note: the set for ra_pick cannot be empty, since each register file + ** has some registers never allocated to PHIs. + */ + Reg down, up = ra_pick(as, ~blocked & allow); /* Get a free register. */ + if (candidates & ~blockedby) /* Optimize shifts, else it's a cycle. */ + candidates = candidates & ~blockedby; + down = rset_picktop(candidates); /* Pick candidate PHI register. */ + ra_rename(as, down, up); /* And rename it to the free register. */ + } +} + +/* PHI register shuffling. +** +** The allocator tries hard to preserve PHI register assignments across +** the loop body. Most of the time this loop does nothing, since there +** are no register mismatches. +** +** If a register mismatch is detected and ... +** - the register is currently free: rename it. +** - the register is blocked by an invariant: restore/remat and rename it. +** - Otherwise the register is used by another PHI, so mark it as blocked. +** +** The renames are order-sensitive, so just retry the loop if a register +** is marked as blocked, but has been freed in the meantime. A cycle is +** detected if all of the blocked registers are allocated. To break the +** cycle rename one of them to a free register and retry. +** +** Note that PHI spill slots are kept in sync and don't need to be shuffled. +*/ +static void asm_phi_shuffle(ASMState *as) +{ + RegSet work; + + /* Find and resolve PHI register mismatches. */ + for (;;) { + RegSet blocked = RSET_EMPTY; + RegSet blockedby = RSET_EMPTY; + RegSet phiset = as->phiset; + while (phiset) { /* Check all left PHI operand registers. */ + Reg r = rset_pickbot(phiset); + IRIns *irl = IR(as->phireg[r]); + Reg left = irl->r; + if (r != left) { /* Mismatch? */ + if (!rset_test(as->freeset, r)) { /* PHI register blocked? */ + IRRef ref = regcost_ref(as->cost[r]); + /* Blocked by other PHI (w/reg)? */ + if (!ra_iskref(ref) && irt_ismarked(IR(ref)->t)) { + rset_set(blocked, r); + if (ra_hasreg(left)) + rset_set(blockedby, left); + left = RID_NONE; + } else { /* Otherwise grab register from invariant. */ + ra_restore(as, ref); + checkmclim(as); + } + } + if (ra_hasreg(left)) { + ra_rename(as, left, r); + checkmclim(as); + } + } + rset_clear(phiset, r); + } + if (!blocked) break; /* Finished. */ + if (!(as->freeset & blocked)) { /* Break cycles if none are free. */ + asm_phi_break(as, blocked, blockedby, RSET_GPR); + if (!LJ_SOFTFP) asm_phi_break(as, blocked, blockedby, RSET_FPR); + checkmclim(as); + } /* Else retry some more renames. */ + } + + /* Restore/remat invariants whose registers are modified inside the loop. */ +#if !LJ_SOFTFP + work = as->modset & ~(as->freeset | as->phiset) & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +#endif + work = as->modset & ~(as->freeset | as->phiset); + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } + + /* Allocate and save all unsaved PHI regs and clear marks. */ + work = as->phiset; + while (work) { + Reg r = rset_picktop(work); + IRRef lref = as->phireg[r]; + IRIns *ir = IR(lref); + if (ra_hasspill(ir->s)) { /* Left PHI gained a spill slot? */ + irt_clearmark(ir->t); /* Handled here, so clear marker now. */ + ra_alloc1(as, lref, RID2RSET(r)); + ra_save(as, ir, r); /* Save to spill slot inside the loop. */ + checkmclim(as); + } + rset_clear(work, r); + } +} + +/* Copy unsynced left/right PHI spill slots. Rarely needed. */ +static void asm_phi_copyspill(ASMState *as) +{ + int need = 0; + IRIns *ir; + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) + if (ra_hasspill(ir->s) && ra_hasspill(IR(ir->op1)->s)) + need |= irt_isfp(ir->t) ? 2 : 1; /* Unsynced spill slot? */ + if ((need & 1)) { /* Copy integer spill slots. */ +#if !LJ_TARGET_X86ORX64 + Reg r = RID_TMP; +#else + Reg r = RID_RET; + if ((as->freeset & RSET_GPR)) + r = rset_pickbot((as->freeset & RSET_GPR)); + else + emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); +#endif + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) { + if (ra_hasspill(ir->s)) { + IRIns *irl = IR(ir->op1); + if (ra_hasspill(irl->s) && !irt_isfp(ir->t)) { + emit_spstore(as, irl, r, sps_scale(irl->s)); + emit_spload(as, ir, r, sps_scale(ir->s)); + checkmclim(as); + } + } + } +#if LJ_TARGET_X86ORX64 + if (!rset_test(as->freeset, r)) + emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); +#endif + } +#if !LJ_SOFTFP + if ((need & 2)) { /* Copy FP spill slots. */ +#if LJ_TARGET_X86 + Reg r = RID_XMM0; +#else + Reg r = RID_FPRET; +#endif + if ((as->freeset & RSET_FPR)) + r = rset_pickbot((as->freeset & RSET_FPR)); + if (!rset_test(as->freeset, r)) + emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) { + if (ra_hasspill(ir->s)) { + IRIns *irl = IR(ir->op1); + if (ra_hasspill(irl->s) && irt_isfp(ir->t)) { + emit_spstore(as, irl, r, sps_scale(irl->s)); + emit_spload(as, ir, r, sps_scale(ir->s)); + checkmclim(as); + } + } + } + if (!rset_test(as->freeset, r)) + emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); + } +#endif +} + +/* Emit renames for left PHIs which are only spilled outside the loop. */ +static void asm_phi_fixup(ASMState *as) +{ + RegSet work = as->phiset; + while (work) { + Reg r = rset_picktop(work); + IRRef lref = as->phireg[r]; + IRIns *ir = IR(lref); + if (irt_ismarked(ir->t)) { + irt_clearmark(ir->t); + /* Left PHI gained a spill slot before the loop? */ + if (ra_hasspill(ir->s)) { + IRRef ren; + lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), lref, as->loopsnapno); + ren = tref_ref(lj_ir_emit(as->J)); + as->ir = as->T->ir; /* The IR may have been reallocated. */ + IR(ren)->r = (uint8_t)r; + IR(ren)->s = SPS_NONE; + } + } + rset_clear(work, r); + } +} + +/* Setup right PHI reference. */ +static void asm_phi(ASMState *as, IRIns *ir) +{ + RegSet allow = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & + ~as->phiset; + RegSet afree = (as->freeset & allow); + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + if (ir->r == RID_SINK) /* Sink PHI. */ + return; + /* Spill slot shuffling is not implemented yet (but rarely needed). */ + if (ra_hasspill(irl->s) || ra_hasspill(irr->s)) + lj_trace_err(as->J, LJ_TRERR_NYIPHI); + /* Leave at least one register free for non-PHIs (and PHI cycle breaking). */ + if ((afree & (afree-1))) { /* Two or more free registers? */ + Reg r; + if (ra_noreg(irr->r)) { /* Get a register for the right PHI. */ + r = ra_allocref(as, ir->op2, allow); + } else { /* Duplicate right PHI, need a copy (rare). */ + r = ra_scratch(as, allow); + emit_movrr(as, irr, r, irr->r); + } + ir->r = (uint8_t)r; + rset_set(as->phiset, r); + as->phireg[r] = (IRRef1)ir->op1; + irt_setmark(irl->t); /* Marks left PHIs _with_ register. */ + if (ra_noreg(irl->r)) + ra_sethint(irl->r, r); /* Set register hint for left PHI. */ + } else { /* Otherwise allocate a spill slot. */ + /* This is overly restrictive, but it triggers only on synthetic code. */ + if (ra_hasreg(irl->r) || ra_hasreg(irr->r)) + lj_trace_err(as->J, LJ_TRERR_NYIPHI); + ra_spill(as, ir); + irr->s = ir->s; /* Set right PHI spill slot. Sync left slot later. */ + } +} + +static void asm_loop_fixup(ASMState *as); + +/* Middle part of a loop. */ +static void asm_loop(ASMState *as) +{ + MCode *mcspill; + /* LOOP is a guard, so the snapno is up to date. */ + as->loopsnapno = as->snapno; + if (as->gcsteps) + asm_gc_check(as); + /* LOOP marks the transition from the variant to the invariant part. */ + as->flagmcp = as->invmcp = NULL; + as->sectref = 0; + if (!neverfuse(as)) as->fuseref = 0; + asm_phi_shuffle(as); + mcspill = as->mcp; + asm_phi_copyspill(as); + asm_loop_fixup(as); + as->mcloop = as->mcp; + RA_DBGX((as, "===== LOOP =====")); + if (!as->realign) RA_DBG_FLUSH(); + if (as->mcp != mcspill) + emit_jmp(as, mcspill); +} + +/* -- Target-specific assembler ------------------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_asm_x86.h" +#elif LJ_TARGET_ARM +#include "lj_asm_arm.h" +#elif LJ_TARGET_PPC +#include "lj_asm_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_asm_mips.h" +#else +#error "Missing assembler for target CPU" +#endif + +/* -- Head of trace ------------------------------------------------------- */ + +/* Head of a root trace. */ +static void asm_head_root(ASMState *as) +{ + int32_t spadj; + asm_head_root_base(as); + emit_setvmstate(as, (int32_t)as->T->traceno); + spadj = asm_stack_adjust(as); + as->T->spadjust = (uint16_t)spadj; + emit_spsub(as, spadj); + /* Root traces assume a checked stack for the starting proto. */ + as->T->topslot = gcref(as->T->startpt)->pt.framesize; +} + +/* Head of a side trace. +** +** The current simplistic algorithm requires that all slots inherited +** from the parent are live in a register between pass 2 and pass 3. This +** avoids the complexity of stack slot shuffling. But of course this may +** overflow the register set in some cases and cause the dreaded error: +** "NYI: register coalescing too complex". A refined algorithm is needed. +*/ +static void asm_head_side(ASMState *as) +{ + IRRef1 sloadins[RID_MAX]; + RegSet allow = RSET_ALL; /* Inverse of all coalesced registers. */ + RegSet live = RSET_EMPTY; /* Live parent registers. */ + IRIns *irp = &as->parent->ir[REF_BASE]; /* Parent base. */ + int32_t spadj, spdelta; + int pass2 = 0; + int pass3 = 0; + IRRef i; + + allow = asm_head_side_base(as, irp, allow); + + /* Scan all parent SLOADs and collect register dependencies. */ + for (i = as->stopins; i > REF_BASE; i--) { + IRIns *ir = IR(i); + RegSP rs; + lua_assert((ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_PARENT)) || + (LJ_SOFTFP && ir->o == IR_HIOP) || ir->o == IR_PVAL); + rs = as->parentmap[i - REF_FIRST]; + if (ra_hasreg(ir->r)) { + rset_clear(allow, ir->r); + if (ra_hasspill(ir->s)) { + ra_save(as, ir, ir->r); + checkmclim(as); + } + } else if (ra_hasspill(ir->s)) { + irt_setmark(ir->t); + pass2 = 1; + } + if (ir->r == rs) { /* Coalesce matching registers right now. */ + ra_free(as, ir->r); + } else if (ra_hasspill(regsp_spill(rs))) { + if (ra_hasreg(ir->r)) + pass3 = 1; + } else if (ra_used(ir)) { + sloadins[rs] = (IRRef1)i; + rset_set(live, rs); /* Block live parent register. */ + } + } + + /* Calculate stack frame adjustment. */ + spadj = asm_stack_adjust(as); + spdelta = spadj - (int32_t)as->parent->spadjust; + if (spdelta < 0) { /* Don't shrink the stack frame. */ + spadj = (int32_t)as->parent->spadjust; + spdelta = 0; + } + as->T->spadjust = (uint16_t)spadj; + + /* Reload spilled target registers. */ + if (pass2) { + for (i = as->stopins; i > REF_BASE; i--) { + IRIns *ir = IR(i); + if (irt_ismarked(ir->t)) { + RegSet mask; + Reg r; + RegSP rs; + irt_clearmark(ir->t); + rs = as->parentmap[i - REF_FIRST]; + if (!ra_hasspill(regsp_spill(rs))) + ra_sethint(ir->r, rs); /* Hint may be gone, set it again. */ + else if (sps_scale(regsp_spill(rs))+spdelta == sps_scale(ir->s)) + continue; /* Same spill slot, do nothing. */ + mask = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & allow; + if (mask == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + r = ra_allocref(as, i, mask); + ra_save(as, ir, r); + rset_clear(allow, r); + if (r == rs) { /* Coalesce matching registers right now. */ + ra_free(as, r); + rset_clear(live, r); + } else if (ra_hasspill(regsp_spill(rs))) { + pass3 = 1; + } + checkmclim(as); + } + } + } + + /* Store trace number and adjust stack frame relative to the parent. */ + emit_setvmstate(as, (int32_t)as->T->traceno); + emit_spsub(as, spdelta); + +#if !LJ_TARGET_X86ORX64 + /* Restore BASE register from parent spill slot. */ + if (ra_hasspill(irp->s)) + emit_spload(as, IR(REF_BASE), IR(REF_BASE)->r, sps_scale(irp->s)); +#endif + + /* Restore target registers from parent spill slots. */ + if (pass3) { + RegSet work = ~as->freeset & RSET_ALL; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + RegSP rs = as->parentmap[ref - REF_FIRST]; + rset_clear(work, r); + if (ra_hasspill(regsp_spill(rs))) { + int32_t ofs = sps_scale(regsp_spill(rs)); + ra_free(as, r); + emit_spload(as, IR(ref), r, ofs); + checkmclim(as); + } + } + } + + /* Shuffle registers to match up target regs with parent regs. */ + for (;;) { + RegSet work; + + /* Repeatedly coalesce free live registers by moving to their target. */ + while ((work = as->freeset & live) != RSET_EMPTY) { + Reg rp = rset_pickbot(work); + IRIns *ir = IR(sloadins[rp]); + rset_clear(live, rp); + rset_clear(allow, rp); + ra_free(as, ir->r); + emit_movrr(as, ir, ir->r, rp); + checkmclim(as); + } + + /* We're done if no live registers remain. */ + if (live == RSET_EMPTY) + break; + + /* Break cycles by renaming one target to a temp. register. */ + if (live & RSET_GPR) { + RegSet tmpset = as->freeset & ~live & allow & RSET_GPR; + if (tmpset == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + ra_rename(as, rset_pickbot(live & RSET_GPR), rset_pickbot(tmpset)); + } + if (!LJ_SOFTFP && (live & RSET_FPR)) { + RegSet tmpset = as->freeset & ~live & allow & RSET_FPR; + if (tmpset == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + ra_rename(as, rset_pickbot(live & RSET_FPR), rset_pickbot(tmpset)); + } + checkmclim(as); + /* Continue with coalescing to fix up the broken cycle(s). */ + } + + /* Inherit top stack slot already checked by parent trace. */ + as->T->topslot = as->parent->topslot; + if (as->topslot > as->T->topslot) { /* Need to check for higher slot? */ +#ifdef EXITSTATE_CHECKEXIT + /* Highest exit + 1 indicates stack check. */ + ExitNo exitno = as->T->nsnap; +#else + /* Reuse the parent exit in the context of the parent trace. */ + ExitNo exitno = as->J->exitno; +#endif + as->T->topslot = (uint8_t)as->topslot; /* Remember for child traces. */ + asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno); + } +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Get base slot for a snapshot. */ +static BCReg asm_baseslot(ASMState *as, SnapShot *snap, int *gotframe) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n; + for (n = snap->nent; n > 0; n--) { + SnapEntry sn = map[n-1]; + if ((sn & SNAP_FRAME)) { + *gotframe = 1; + return snap_slot(sn); + } + } + return 0; +} + +/* Link to another trace. */ +static void asm_tail_link(ASMState *as) +{ + SnapNo snapno = as->T->nsnap-1; /* Last snapshot. */ + SnapShot *snap = &as->T->snap[snapno]; + int gotframe = 0; + BCReg baseslot = asm_baseslot(as, snap, &gotframe); + + as->topslot = snap->topslot; + checkmclim(as); + ra_allocref(as, REF_BASE, RID2RSET(RID_BASE)); + + if (as->T->link == 0) { + /* Setup fixed registers for exit to interpreter. */ + const BCIns *pc = snap_pc(as->T->snapmap[snap->mapofs + snap->nent]); + int32_t mres; + if (bc_op(*pc) == BC_JLOOP) { /* NYI: find a better way to do this. */ + BCIns *retpc = &traceref(as->J, bc_d(*pc))->startins; + if (bc_isret(bc_op(*retpc))) + pc = retpc; + } + ra_allockreg(as, i32ptr(J2GG(as->J)->dispatch), RID_DISPATCH); + ra_allockreg(as, i32ptr(pc), RID_LPC); + mres = (int32_t)(snap->nslots - baseslot); + switch (bc_op(*pc)) { + case BC_CALLM: case BC_CALLMT: + mres -= (int32_t)(1 + bc_a(*pc) + bc_c(*pc)); break; + case BC_RETM: mres -= (int32_t)(bc_a(*pc) + bc_d(*pc)); break; + case BC_TSETM: mres -= (int32_t)bc_a(*pc); break; + default: if (bc_op(*pc) < BC_FUNCF) mres = 0; break; + } + ra_allockreg(as, mres, RID_RET); /* Return MULTRES or 0. */ + } else if (baseslot) { + /* Save modified BASE for linking to trace with higher start frame. */ + emit_setgl(as, RID_BASE, jit_base); + } + emit_addptr(as, RID_BASE, 8*(int32_t)baseslot); + + /* Sync the interpreter state with the on-trace state. */ + asm_stack_restore(as, snap); + + /* Root traces that add frames need to check the stack at the end. */ + if (!as->parent && gotframe) + asm_stack_check(as, as->topslot, NULL, as->freeset & RSET_GPR, snapno); +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Clear reg/sp for all instructions and add register hints. */ +static void asm_setup_regsp(ASMState *as) +{ + GCtrace *T = as->T; + int sink = T->sinktags; + IRRef nins = T->nins; + IRIns *ir, *lastir; + int inloop; +#if LJ_TARGET_ARM + uint32_t rload = 0xa6402a64; +#endif + + ra_setup(as); + + /* Clear reg/sp for constants. */ + for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++) + ir->prev = REGSP_INIT; + + /* REF_BASE is used for implicit references to the BASE register. */ + lastir->prev = REGSP_HINT(RID_BASE); + + ir = IR(nins-1); + if (ir->o == IR_RENAME) { + do { ir--; nins--; } while (ir->o == IR_RENAME); + T->nins = nins; /* Remove any renames left over from ASM restart. */ + } + as->snaprename = nins; + as->snapref = nins; + as->snapno = T->nsnap; + + as->stopins = REF_BASE; + as->orignins = nins; + as->curins = nins; + + /* Setup register hints for parent link instructions. */ + ir = IR(REF_FIRST); + if (as->parent) { + uint16_t *p; + lastir = lj_snap_regspmap(as->parent, as->J->exitno, ir); + if (lastir - ir > LJ_MAX_JSLOTS) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + as->stopins = (IRRef)((lastir-1) - as->ir); + for (p = as->parentmap; ir < lastir; ir++) { + RegSP rs = ir->prev; + *p++ = (uint16_t)rs; /* Copy original parent RegSP to parentmap. */ + if (!ra_hasspill(regsp_spill(rs))) + ir->prev = (uint16_t)REGSP_HINT(regsp_reg(rs)); + else + ir->prev = REGSP_INIT; + } + } + + inloop = 0; + as->evenspill = SPS_FIRST; + for (lastir = IR(nins); ir < lastir; ir++) { + if (sink) { + if (ir->r == RID_SINK) + continue; + if (ir->r == RID_SUNK) { /* Revert after ASM restart. */ + ir->r = RID_SINK; + continue; + } + } + switch (ir->o) { + case IR_LOOP: + inloop = 1; + break; +#if LJ_TARGET_ARM + case IR_SLOAD: + if (!((ir->op2 & IRSLOAD_TYPECHECK) || (ir+1)->o == IR_HIOP)) + break; + /* fallthrough */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + if (!LJ_SOFTFP && irt_isnum(ir->t)) break; + ir->prev = (uint16_t)REGSP_HINT((rload & 15)); + rload = lj_ror(rload, 4); + continue; +#endif + case IR_CALLXS: { + CCallInfo ci; + ci.flags = asm_callx_flags(as, ir); + ir->prev = asm_setup_call_slots(as, ir, &ci); + if (inloop) + as->modset |= RSET_SCRATCH; + continue; + } + case IR_CALLN: case IR_CALLL: case IR_CALLS: { + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + ir->prev = asm_setup_call_slots(as, ir, ci); + if (inloop) + as->modset |= (ci->flags & CCI_NOFPRCLOBBER) ? + (RSET_SCRATCH & ~RSET_FPR) : RSET_SCRATCH; + continue; + } +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) + case IR_HIOP: + switch ((ir-1)->o) { +#if LJ_SOFTFP && LJ_TARGET_ARM + case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + if (ra_hashint((ir-1)->r)) { + ir->prev = (ir-1)->prev + 1; + continue; + } + break; +#endif +#if !LJ_SOFTFP && LJ_NEED_FP64 + case IR_CONV: + if (irt_isfp((ir-1)->t)) { + ir->prev = REGSP_HINT(RID_FPRET); + continue; + } + /* fallthrough */ +#endif + case IR_CALLN: case IR_CALLXS: +#if LJ_SOFTFP + case IR_MIN: case IR_MAX: +#endif + (ir-1)->prev = REGSP_HINT(RID_RETLO); + ir->prev = REGSP_HINT(RID_RETHI); + continue; + default: + break; + } + break; +#endif +#if LJ_SOFTFP + case IR_MIN: case IR_MAX: + if ((ir+1)->o != IR_HIOP) break; + /* fallthrough */ +#endif + /* C calls evict all scratch regs and return results in RID_RET. */ + case IR_SNEW: case IR_XSNEW: case IR_NEWREF: + if (REGARG_NUMGPR < 3 && as->evenspill < 3) + as->evenspill = 3; /* lj_str_new and lj_tab_newkey need 3 args. */ + case IR_TNEW: case IR_TDUP: case IR_CNEW: case IR_CNEWI: case IR_TOSTR: + ir->prev = REGSP_HINT(RID_RET); + if (inloop) + as->modset = RSET_SCRATCH; + continue; + case IR_STRTO: case IR_OBAR: + if (inloop) + as->modset = RSET_SCRATCH; + break; +#if !LJ_TARGET_X86ORX64 && !LJ_SOFTFP + case IR_ATAN2: case IR_LDEXP: +#endif + case IR_POW: + if (!LJ_SOFTFP && irt_isnum(ir->t)) { +#if LJ_TARGET_X86ORX64 + ir->prev = REGSP_HINT(RID_XMM0); + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX); +#else + ir->prev = REGSP_HINT(RID_FPRET); + if (inloop) + as->modset |= RSET_SCRATCH; +#endif + continue; + } + /* fallthrough for integer POW */ + case IR_DIV: case IR_MOD: + if (!irt_isnum(ir->t)) { + ir->prev = REGSP_HINT(RID_RET); + if (inloop) + as->modset |= (RSET_SCRATCH & RSET_GPR); + continue; + } + break; + case IR_FPMATH: +#if LJ_TARGET_X86ORX64 + if (ir->op2 == IRFPM_EXP2) { /* May be joined to lj_vm_pow_sse. */ + ir->prev = REGSP_HINT(RID_XMM0); +#if !LJ_64 + if (as->evenspill < 4) /* Leave room for 16 byte scratch area. */ + as->evenspill = 4; +#endif + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX); + continue; + } else if (ir->op2 <= IRFPM_TRUNC && !(as->flags & JIT_F_SSE4_1)) { + ir->prev = REGSP_HINT(RID_XMM0); + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX); + continue; + } + break; +#else + ir->prev = REGSP_HINT(RID_FPRET); + if (inloop) + as->modset |= RSET_SCRATCH; + continue; +#endif +#if LJ_TARGET_X86ORX64 + /* Non-constant shift counts need to be in RID_ECX on x86/x64. */ + case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR: + if (!irref_isk(ir->op2) && !ra_hashint(IR(ir->op2)->r)) { + IR(ir->op2)->r = REGSP_HINT(RID_ECX); + if (inloop) + rset_set(as->modset, RID_ECX); + } + break; +#endif + /* Do not propagate hints across type conversions or loads. */ + case IR_TOBIT: + case IR_XLOAD: +#if !LJ_TARGET_ARM + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: +#endif + break; + case IR_CONV: + if (irt_isfp(ir->t) || (ir->op2 & IRCONV_SRCMASK) == IRT_NUM || + (ir->op2 & IRCONV_SRCMASK) == IRT_FLOAT) + break; + /* fallthrough */ + default: + /* Propagate hints across likely 'op reg, imm' or 'op reg'. */ + if (irref_isk(ir->op2) && !irref_isk(ir->op1) && + ra_hashint(regsp_reg(IR(ir->op1)->prev))) { + ir->prev = IR(ir->op1)->prev; + continue; + } + break; + } + ir->prev = REGSP_INIT; + } + if ((as->evenspill & 1)) + as->oddspill = as->evenspill++; + else + as->oddspill = 0; +} + +/* -- Assembler core ------------------------------------------------------ */ + +/* Assemble a trace. */ +void lj_asm_trace(jit_State *J, GCtrace *T) +{ + ASMState as_; + ASMState *as = &as_; + MCode *origtop; + + /* Ensure an initialized instruction beyond the last one for HIOP checks. */ + J->cur.nins = lj_ir_nextins(J); + J->cur.ir[J->cur.nins].o = IR_NOP; + + /* Setup initial state. Copy some fields to reduce indirections. */ + as->J = J; + as->T = T; + as->ir = T->ir; + as->flags = J->flags; + as->loopref = J->loopref; + as->realign = NULL; + as->loopinv = 0; + as->parent = J->parent ? traceref(J, J->parent) : NULL; + + /* Reserve MCode memory. */ + as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot); + as->mcp = as->mctop; + as->mclim = as->mcbot + MCLIM_REDZONE; + asm_setup_target(as); + + do { + as->mcp = as->mctop; +#ifdef LUA_USE_ASSERT + as->mcp_prev = as->mcp; +#endif + as->curins = T->nins; + RA_DBG_START(); + RA_DBGX((as, "===== STOP =====")); + + /* General trace setup. Emit tail of trace. */ + asm_tail_prep(as); + as->mcloop = NULL; + as->flagmcp = NULL; + as->topslot = 0; + as->gcsteps = 0; + as->sectref = as->loopref; + as->fuseref = (as->flags & JIT_F_OPT_FUSE) ? as->loopref : FUSE_DISABLED; + asm_setup_regsp(as); + if (!as->loopref) + asm_tail_link(as); + + /* Assemble a trace in linear backwards order. */ + for (as->curins--; as->curins > as->stopins; as->curins--) { + IRIns *ir = IR(as->curins); + lua_assert(!(LJ_32 && irt_isint64(ir->t))); /* Handled by SPLIT. */ + if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE)) + continue; /* Dead-code elimination can be soooo easy. */ + if (irt_isguard(ir->t)) + asm_snap_prep(as); + RA_DBG_REF(); + checkmclim(as); + asm_ir(as, ir); + } + } while (as->realign); /* Retry in case the MCode needs to be realigned. */ + + /* Emit head of trace. */ + RA_DBG_REF(); + checkmclim(as); + if (as->gcsteps > 0) { + as->curins = as->T->snap[0].ref; + asm_snap_prep(as); /* The GC check is a guard. */ + asm_gc_check(as); + } + ra_evictk(as); + if (as->parent) + asm_head_side(as); + else + asm_head_root(as); + asm_phi_fixup(as); + + RA_DBGX((as, "===== START ====")); + RA_DBG_FLUSH(); + if (as->freeset != RSET_ALL) + lj_trace_err(as->J, LJ_TRERR_BADRA); /* Ouch! Should never happen. */ + + /* Set trace entry point before fixing up tail to allow link to self. */ + T->mcode = as->mcp; + T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0; + if (!as->loopref) + asm_tail_fixup(as, T->link); /* Note: this may change as->mctop! */ + T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp); + lj_mcode_sync(T->mcode, origtop); +} + +#undef IR + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.h new file mode 100644 index 0000000..f5d0159 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm.h @@ -0,0 +1,17 @@ +/* +** IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_ASM_H +#define _LJ_ASM_H + +#include "lj_jit.h" + +#if LJ_HASJIT +LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T); +LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, + MCode *target); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_arm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_arm.h new file mode 100644 index 0000000..72f205d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_arm.h @@ -0,0 +1,2361 @@ +/* +** ARM IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate a scratch register pair. */ +static Reg ra_scratchpair(ASMState *as, RegSet allow) +{ + RegSet pick1 = as->freeset & allow; + RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN; + Reg r; + if (pick2) { + r = rset_picktop(pick2); + } else { + RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN; + if (pick) { + r = rset_picktop(pick); + ra_restore(as, regcost_ref(as->cost[r+1])); + } else { + pick = pick1 & (allow << 1) & RSET_GPRODD; + if (pick) { + r = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1])); + } else { + r = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN); + ra_restore(as, regcost_ref(as->cost[r+1])); + } + } + } + lua_assert(rset_test(RSET_GPREVEN, r)); + ra_modified(as, r); + ra_modified(as, r+1); + RA_DBGX((as, "scratchpair $r $r", r, r+1)); + return r; +} + +#if !LJ_SOFTFP +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_allocref(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_allocref(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_allocref(as, ir->op2, allow); + left = ra_alloc1(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_allocref(as, ir->op1, allow); + right = ra_alloc1(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} +#endif + +/* -- Guard handling ------------------------------------------------------ */ + +/* Generate an exit stub group at the bottom of the reserved MCode memory. */ +static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) +{ + MCode *mxp = as->mcbot; + int i; + if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop) + asm_mclimit(as); + /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */ + *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP); + *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu); + mxp++; + *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch); /* DISPATCH address */ + *mxp++ = group*EXITSTUBS_PER_GROUP; + for (i = 0; i < EXITSTUBS_PER_GROUP; i++) + *mxp++ = ARMI_B|((-6-i)&0x00ffffffu); + lj_mcode_sync(as->mcbot, mxp); + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + return mxp - EXITSTUBS_PER_GROUP; +} + +/* Setup all needed exit stubs. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) + lj_trace_err(as->J, LJ_TRERR_SNAPOV); + for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++) + if (as->J->exitstubgroup[i] == NULL) + as->J->exitstubgroup[i] = asm_exitstub_gen(as, i); +} + +/* Emit conditional branch to exit for guard. */ +static void asm_guardcc(ASMState *as, ARMCC cc) +{ + MCode *target = exitstub_addr(as->J, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *p = ARMI_BL | ((target-p-2) & 0x00ffffffu); + emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1); + return; + } + emit_branch(as, ARMF_CC(ARMI_BL, cc), target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow, + int lim) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (ofs > -lim && ofs < lim) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (ofs < lim) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + *ofsp = (ofs & 255); /* Mask out less bits to allow LDRD. */ + return ra_allock(as, (ofs & ~255), allow); + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse m operand into arithmetic/logic instructions. */ +static uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_hasreg(ir->r)) { + ra_noweak(as, ir->r); + return ARMF_M(ir->r); + } else if (irref_isk(ref)) { + uint32_t k = emit_isk12(ai, ir->i); + if (k) + return k; + } else if (mayfuse(as, ref)) { + if (ir->o >= IR_BSHL && ir->o <= IR_BROR) { + Reg m = ra_alloc1(as, ir->op1, allow); + ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL : + ir->o == IR_BSHR ? ARMSH_LSR : + ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR; + if (irref_isk(ir->op2)) { + return m | ARMF_SH(sh, (IR(ir->op2)->i & 31)); + } else { + Reg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m)); + return m | ARMF_RSH(sh, s); + } + } else if (ir->o == IR_ADD && ir->op1 == ir->op2) { + Reg m = ra_alloc1(as, ir->op1, allow); + return m | ARMF_SH(ARMSH_LSL, 1); + } + } + return ra_allocref(as, ref, allow); +} + +/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */ +static IRRef asm_fuselsl2(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL && + irref_isk(ir->op2) && IR(ir->op2)->i == 2) + return ir->op1; + return 0; /* No fusion. */ +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 : + (ai & 0x04000000) ? 4096 : 256; + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && + (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim && + (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) { + ofs = ofs2; + ref = ir->op1; + } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) { + IRRef lref = ir->op1, rref = ir->op2; + Reg rn, rm; + if ((ai & 0x04000000)) { + IRRef sref = asm_fuselsl2(as, rref); + if (sref) { + rref = sref; + ai |= ARMF_SH(ARMSH_LSL, 2); + } else if ((sref = asm_fuselsl2(as, lref)) != 0) { + lref = rref; + rref = sref; + ai |= ARMF_SH(ARMSH_LSL, 2); + } + } + rn = ra_alloc1(as, lref, allow); + rm = ra_alloc1(as, rref, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) ai |= ARMI_LS_R; + emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm); + return; + } + } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) { + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs += IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs += IR(ir->op1)->i; + ref = ir->op2; + } else { + /* NYI: Fuse ADD with constant. */ + Reg rn = ra_alloc1(as, ir->op1, allow); + uint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) + emit_lso(as, ai, rd, rd, ofs); + else + emit_lsox(as, ai, rd, rd, ofs); + emit_dn(as, ARMI_ADD^m, rd, rn); + return; + } + if (ofs <= -lim || ofs >= lim) { + Reg rn = ra_alloc1(as, ref, allow); + Reg rm = ra_allock(as, ofs, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) ai |= ARMI_LS_R; + emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm); + return; + } + } + } + base = ra_alloc1(as, ref, allow); +#if !LJ_SOFTFP + if ((ai & 0x08000000)) + emit_vlso(as, ai, rd, base, ofs); + else +#endif + if ((ai & 0x04000000)) + emit_lso(as, ai, rd, base, ofs); + else + emit_lsox(as, ai, rd, base, ofs); +} + +#if !LJ_SOFTFP +/* Fuse to multiply-add/sub instruction. */ +static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air) +{ + IRRef lref = ir->op1, rref = ir->op2; + IRIns *irm; + if (lref != rref && + ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && + ra_noreg(irm->r)) || + (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && + (rref = lref, ai = air, ra_noreg(irm->r))))) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg add = ra_hintalloc(as, rref, dest, RSET_FPR); + Reg right, left = ra_alloc2(as, irm, + rset_exclude(rset_exclude(RSET_FPR, dest), add)); + right = (left >> 8); left &= 255; + emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15)); + if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15)); + return 1; + } + return 0; +} +#endif + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 0; +#if LJ_SOFTFP + Reg gpr = REGARG_FIRSTGPR; +#else + Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0; +#endif + if ((void *)ci->func) + emit_call(as, (void *)ci->func); +#if !LJ_SOFTFP + for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) + as->cost[gpr] = REGCOST(~0u, ASMREF_L); + gpr = REGARG_FIRSTGPR; +#endif + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + IRIns *ir = IR(ref); +#if !LJ_SOFTFP + if (ref && irt_isfp(ir->t)) { + RegSet of = as->freeset; + Reg src; + if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { + if (irt_isnum(ir->t)) { + if (fpr <= REGARG_LASTFPR) { + ra_leftov(as, fpr, ref); + fpr++; + continue; + } + } else if (fprodd) { /* Ick. */ + src = ra_alloc1(as, ref, RSET_FPR); + emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000); + fprodd = 0; + continue; + } else if (fpr <= REGARG_LASTFPR) { + ra_leftov(as, fpr, ref); + fprodd = fpr++; + continue; + } + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + fprodd = 0; + goto stackfp; + } + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u; + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */ + if (irt_isnum(ir->t)) { + lua_assert(rset_test(as->freeset, gpr+1)); /* Ditto. */ + emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15)); + gpr += 2; + } else { + emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15)); + gpr++; + } + } else { + stackfp: + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, src, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } else +#endif + { + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */ + if (ref) ra_leftov(as, gpr, ref); + gpr++; + } else { + if (ref) { + Reg r = ra_alloc1(as, ref, RSET_GPR); + emit_spstore(as, ir, r, ofs); + } + ofs += 4; + } + } + } +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (!LJ_SOFTFP && irt_isfp(ir->t)) { + if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) { + Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); + if (irt_isnum(ir->t)) + emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest); + else + emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest); + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } + UNUSED(ci); +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need a non-argument register for indirect calls. */ + Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1)); + emit_m(as, ARMI_BLXr, freg); + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + /* Need to force a spill on REF_BASE now to update the stack slot. */ + emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE))); + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_nm(as, ARMI_CMP, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_lso(as, ARMI_LDR, RID_TMP, base, -4); +} + +/* -- Type conversions ---------------------------------------------------- */ + +#if !LJ_SOFTFP +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guardcc(as, CC_NE); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15)); + emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15)); + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15)); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15)); +} +#endif + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if !LJ_SOFTFP + int stfp = (st == IRT_NUM || st == IRT_FLOAT); +#endif + IRRef lref = ir->op1; + /* 64 bit integer conversions are handled by SPLIT. */ + lua_assert(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64)); +#if LJ_SOFTFP + /* FP conversions are handled by SPLIT. */ + lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT)); + /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */ +#else + lua_assert(irt_type(ir->t) != st); + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32, + (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15)); + } else { /* Integer to FP conversion. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + ARMIns ai = irt_isfloat(ir->t) ? + (st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) : + (st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32); + emit_dm(as, ai, (dest & 15), (dest & 15)); + emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15)); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + ARMIns ai; + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + ai = irt_isint(ir->t) ? + (st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) : + (st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32); + emit_dm(as, ai, (tmp & 15), (left & 15)); + } + } else +#endif + { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((as->flags & JIT_F_ARMV6)) { + ARMIns ai = st == IRT_I8 ? ARMI_SXTB : + st == IRT_U8 ? ARMI_UXTB : + st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH; + emit_dm(as, ai, dest, left); + } else if (st == IRT_U8) { + emit_dn(as, ARMI_AND|ARMI_K12|255, dest, left); + } else { + uint32_t shift = st == IRT_I8 ? 24 : 16; + ARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR; + emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP); + emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left); + } + } else { /* Handle 32/32 bit no-op (cast). */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if !LJ_SOFTFP && LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + CCallInfo ci; + IRRef args[2]; + args[0] = (ir-1)->op1; + args[1] = ir->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = lj_ir_callinfo[id]; +#if !LJ_ABI_SOFTFP + ci.flags |= CCI_VARARG; /* These calls don't use the hard-float ABI! */ +#endif + asm_setupresult(as, ir, &ci); + asm_gencall(as, &ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + Reg rlo = 0, rhi = 0, tmp; + int destused = ra_used(ir); + int32_t ofs = 0; + ra_evictset(as, RSET_SCRATCH); +#if LJ_SOFTFP + if (destused) { + if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) && + (ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) { + int i; + for (i = 0; i < 2; i++) { + Reg r = (ir+i)->r; + if (ra_hasreg(r)) { + ra_free(as, r); + ra_modified(as, r); + emit_spload(as, ir+i, r, sps_scale((ir+i)->s)); + } + } + ofs = sps_scale(ir->s); + destused = 0; + } else { + rhi = ra_dest(as, ir+1, RSET_GPR); + rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi)); + } + } + asm_guardcc(as, CC_EQ); + if (destused) { + emit_lso(as, ARMI_LDR, rhi, RID_SP, 4); + emit_lso(as, ARMI_LDR, rlo, RID_SP, 0); + } +#else + UNUSED(rhi); + if (destused) { + if (ra_hasspill(ir->s)) { + ofs = sps_scale(ir->s); + destused = 0; + if (ra_hasreg(ir->r)) { + ra_free(as, ir->r); + ra_modified(as, ir->r); + emit_spload(as, ir, ir->r, ofs); + } + } else { + rlo = ra_dest(as, ir, RSET_FPR); + } + } + asm_guardcc(as, CC_EQ); + if (destused) + emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0); +#endif + emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + if (ofs == 0) + emit_dm(as, ARMI_MOV, tmp, RID_SP); + else + emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) { + /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + } else { +#if LJ_SOFTFP + lua_assert(0); +#else + /* Otherwise force a spill and use the spill slot. */ + emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR); +#endif + } + } else { + /* Otherwise use [sp] and [sp+4] to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_dm(as, ARMI_MOV, dest, RID_SP); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_lso(as, ARMI_STR, src, RID_SP, 0); + } + if ((ir+1)->o == IR_HIOP) + type = ra_alloc1(as, ref+1, allow); + else + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_lso(as, ARMI_STR, type, RID_SP, 4); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i); + if (k) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_dn(as, ARMI_ADD^k, dest, base); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir, IROp merge) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt)); + uint32_t khash; + MCLabel l_end, l_loop; + rset_clear(allow, tab); + if (!irref_isk(refkey) || irt_isstr(kt)) { +#if LJ_SOFTFP + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + if (irkey[1].o == IR_HIOP) { + if (ra_hasreg((irkey+1)->r)) { + keynumhi = (irkey+1)->r; + keyhi = RID_TMP; + ra_noweak(as, keynumhi); + } else { + keyhi = keynumhi = ra_allocref(as, refkey+1, allow); + } + rset_clear(allow, keynumhi); + khi = 0; + } +#else + if (irt_isnum(kt)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + keyhi = keynumhi = ra_scratch(as, allow); + rset_clear(allow, keyhi); + khi = 0; + } else { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } +#endif + } else if (irt_isnum(kt)) { + int32_t val = (int32_t)ir_knum(irkey)->u32.lo; + k = emit_isk12(ARMI_CMP, val); + if (!k) { + key = ra_allock(as, val, allow); + rset_clear(allow, key); + } + val = (int32_t)ir_knum(irkey)->u32.hi; + khi = emit_isk12(ARMI_CMP, val); + if (!khi) { + keyhi = ra_allock(as, val, allow); + rset_clear(allow, keyhi); + } + } else if (!irt_ispri(kt)) { + k = emit_isk12(ARMI_CMP, irkey->i); + if (!k) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } + } + if (!irt_ispri(kt)) + tmp = ra_scratchpair(as, allow); + + /* Key not found in chain: jump to exit (if merged) or load niltv. */ + l_end = emit_label(as); + as->invmcp = NULL; + if (merge == IR_NE) + asm_guardcc(as, CC_AL); + else if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + + /* Follow hash chain until the end. */ + l_loop = --as->mcp; + emit_n(as, ARMI_CMP|ARMI_K12|0, dest); + emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next)); + + /* Type and value comparison. */ + if (merge == IR_EQ) + asm_guardcc(as, CC_EQ); + else + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + if (!irt_ispri(kt)) { + emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key); + emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi); + emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key)); + } else { + emit_n(as, ARMI_CMP^khi, tmp); + emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it)); + } + *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp); + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp); + if (irt_isstr(kt)) { /* Fetch of str->hash is cheaper than ra_allock. */ + emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, hash)); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + } else if (irref_isk(refkey)) { + emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash, + rset_exclude(rset_exclude(RSET_GPR, tab), dest)); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + } else { /* Must match with hash*() in lj_tab.c. */ + if (ra_hasreg(keynumhi)) { /* Canonicalize +-0.0 to 0.0. */ + if (keyhi == RID_TMP) + emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi); + emit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi); + } + emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP); + emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)), + tmp, tmp+1, tmp); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp); + if (ra_hasreg(keynumhi)) { + emit_dnm(as, ARMI_EOR, tmp+1, tmp, key); + emit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key); /* Test for +-0.0. */ + emit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi); +#if !LJ_SOFTFP + emit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi, + (ra_alloc1(as, refkey, RSET_FPR) & 15)); +#endif + } else { + emit_dnm(as, ARMI_EOR, tmp+1, tmp, key); + emit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS, + rset_exclude(rset_exclude(RSET_GPR, tab), key)); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 4095) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_opk(as, ARMI_ADD, dest, node, ofs, allow); + } + asm_guardcc(as, CC_NE); + if (!irt_ispri(irkey->t)) { + RegSet even = (as->freeset & allow); + even = even & (even >> 1) & RSET_GPREVEN; + if (even) { + key = ra_scratch(as, even); + if (rset_test(as->freeset, key+1)) { + type = key+1; + ra_modified(as, type); + } + } else { + key = ra_scratch(as, allow); + } + rset_clear(allow, key); + } + rset_clear(allow, type); + if (irt_isnum(irkey->t)) { + emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type, + (int32_t)ir_knum(irkey)->u32.hi, allow); + emit_opk(as, ARMI_CMP, 0, key, + (int32_t)ir_knum(irkey)->u32.lo, allow); + } else { + if (ra_hasreg(key)) + emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type); + } + emit_lso(as, ARMI_LDR, type, idx, kofs+4); + if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs); + if (ofs > 4095) + emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR); +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, ARMI_LDR, dest, v); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guardcc(as, CC_NE); + emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP); + emit_opk(as, ARMI_ADD, dest, uv, + (int32_t)offsetof(GCupval, tv), RSET_GPR); + emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_lso(as, ARMI_LDR, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + uint32_t k, m = ARMI_K12|sizeof(GCstr); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + (k = emit_isk12(ARMI_ADD, + (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) { + m = k; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_dn(as, ARMI_ADD^m, dest, dest); + emit_dnm(as, ARMI_ADD, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + emit_opk(as, ARMI_ADD, dest, r, + sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r)); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static ARMIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return ARMI_LDRSB; + case IRT_U8: return ARMI_LDRB; + case IRT_I16: return ARMI_LDRSH; + case IRT_U16: return ARMI_LDRH; + case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VLDR_D; + case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S; + default: return ARMI_LDR; + } +} + +static ARMIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return ARMI_STRB; + case IRT_I16: case IRT_U16: return ARMI_STRH; + case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VSTR_D; + case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S; + default: return ARMI_STR; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + ARMIns ai = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx); + return; + } + } + ofs = field_ofs[ir->op2]; + if ((ai & 0x04000000)) + emit_lso(as, ai, dest, idx, ofs); + else + emit_lsox(as, ai, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + ARMIns ai = asm_fxstoreins(ir); + if ((ai & 0x04000000)) + emit_lso(as, ai, src, idx, ofs); + else + emit_lsox(as, ai, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, + (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, + (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + IRType t = hiop ? IRT_NUM : irt_type(ir->t); + Reg dest = RID_NONE, type = RID_NONE, idx; + RegSet allow = RSET_GPR; + int32_t ofs = 0; + if (hiop && ra_used(ir+1)) { + type = ra_dest(as, ir+1, allow); + rset_clear(allow, type); + } + if (ra_used(ir)) { + lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || + irt_isint(ir->t) || irt_isaddr(ir->t)); + dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow, + (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096); + if (!hiop || type == RID_NONE) { + rset_clear(allow, idx); + if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && + rset_test((as->freeset & allow), dest+1)) { + type = dest+1; + ra_modified(as, type); + } else { + type = RID_TMP; + } + } + asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type); + if (ra_hasreg(dest)) { +#if !LJ_SOFTFP + if (t == IRT_NUM) + emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs); + else +#endif + emit_lso(as, ARMI_LDR, dest, idx, ofs); + } + emit_lso(as, ARMI_LDR, type, idx, ofs+4); +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = 0; +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024); + emit_vlso(as, ARMI_VSTR_D, src, idx, ofs); + } else +#endif + { + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + if (hiop) + type = ra_alloc1(as, (ir+1)->op2, allow); + else + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096); + if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs); + emit_lso(as, ARMI_STR, type, idx, ofs+4); + } + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + IRType t = hiop ? IRT_NUM : irt_type(ir->t); + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK)); +#if LJ_SOFTFP + lua_assert(!(ir->op2 & IRSLOAD_CONVERT)); /* Handled by LJ_SOFTFP SPLIT. */ + if (hiop && ra_used(ir+1)) { + type = ra_dest(as, ir+1, allow); + rset_clear(allow, type); + } +#else + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t = IRT_NUM; /* Continue with a regular number type check. */ + } else +#endif + if (ra_used(ir)) { + Reg tmp = RID_NONE; + if ((ir->op2 & IRSLOAD_CONVERT)) + tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR); + lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || + irt_isint(ir->t) || irt_isaddr(ir->t)); + dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (t == IRT_INT) { + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15)); + t = IRT_NUM; /* Check for original type. */ + } else { + emit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15)); + emit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15)); + t = IRT_INT; /* Check for original type. */ + } + dest = tmp; + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); +dotypecheck: + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + if (ra_noreg(type)) { + if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && + rset_test((as->freeset & allow), dest+1)) { + type = dest+1; + ra_modified(as, type); + } else { + type = RID_TMP; + } + } + asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type); + } + if (ra_hasreg(dest)) { +#if !LJ_SOFTFP + if (t == IRT_NUM) { + if (ofs < 1024) { + emit_vlso(as, ARMI_VLDR_D, dest, base, ofs); + } else { + if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4); + emit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0); + emit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow); + return; + } + } else +#endif + emit_lso(as, ARMI_LDR, dest, base, ofs); + } + if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; ir++; + lua_assert(ir->o == IR_HIOP); + } + for (;;) { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_lso(as, ARMI_STR, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir--; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + { + uint32_t k = emit_isk12(ARMI_MOV, ctypeid); + Reg r = k ? RID_R1 : ra_allock(as, ctypeid, allow); + emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct)); + emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid)); + emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP); + if (k) emit_d(as, ARMI_MOV^k, RID_R1); + } + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg gr = ra_allock(as, i32ptr(J2G(as->J)), + rset_exclude(rset_exclude(RSET_GPR, tab), link)); + Reg mark = RID_TMP; + MCLabel l_end = emit_label(as); + emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_lso(as, ARMI_STR, tab, gr, + (int32_t)offsetof(global_State, gc.grayagain)); + emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark); + emit_lso(as, ARMI_LDR, link, gr, + (int32_t)offsetof(global_State, gc.grayagain)); + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark); + emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + if ((l_end[-1] >> 28) == CC_AL) + l_end[-1] = ARMF_CC(l_end[-1], CC_NE); + else + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1)); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp); + emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_lso(as, ARMI_LDRB, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +#if !LJ_SOFTFP +static void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15)); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_dm(as, ai, (dest & 15), (left & 15)); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} +#endif + +static int asm_swapops(ASMState *as, IRRef lref, IRRef rref) +{ + IRIns *ir; + if (irref_isk(rref)) + return 0; /* Don't swap constants to the left. */ + if (irref_isk(lref)) + return 1; /* But swap constants to the right. */ + ir = IR(rref); + if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || + (ir->o == IR_ADD && ir->op1 == ir->op2)) + return 0; /* Don't swap fusable operands to the left. */ + ir = IR(lref); + if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || + (ir->o == IR_ADD && ir->op1 == ir->op2)) + return 1; /* But swap fusable operands to the right. */ + return 0; /* Otherwise don't swap. */ +} + +static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai) +{ + IRRef lref = ir->op1, rref = ir->op2; + Reg left, dest = ra_dest(as, ir, RSET_GPR); + uint32_t m; + if (asm_swapops(as, lref, rref)) { + IRRef tmp = lref; lref = rref; rref = tmp; + if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC) + ai ^= (ARMI_SUB^ARMI_RSB); + } + left = ra_hintalloc(as, lref, dest, RSET_GPR); + m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left)); + if (irt_isguard(ir->t)) { /* For IR_ADDOV etc. */ + asm_guardcc(as, CC_VS); + ai |= ARMI_S; + } + emit_dn(as, ai^m, dest, left); +} + +static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai) +{ + if (as->flagmcp == as->mcp) { /* Drop cmp r, #0. */ + as->flagmcp = NULL; + as->mcp++; + ai |= ARMI_S; + } + asm_intop(as, ir, ai); +} + +static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai) +{ + if (as->flagmcp == as->mcp) { /* Try to drop cmp r, #0. */ + uint32_t cc = (as->mcp[1] >> 28); + as->flagmcp = NULL; + if (cc <= CC_NE) { + as->mcp++; + ai |= ARMI_S; + } else if (cc == CC_GE) { + *++as->mcp ^= ((CC_GE^CC_PL) << 28); + ai |= ARMI_S; + } else if (cc == CC_LT) { + *++as->mcp ^= ((CC_LT^CC_MI) << 28); + ai |= ARMI_S; + } /* else: other conds don't work with bit ops. */ + } + if (ir->op2 == 0) { + Reg dest = ra_dest(as, ir, RSET_GPR); + uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR); + emit_d(as, ai^m, dest); + } else { + /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */ + asm_intop(as, ir, ai); + } +} + +static void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_dn(as, ai|ARMI_K12|0, dest, left); +} + +/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */ +static void asm_intmul(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest)); + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + Reg tmp = RID_NONE; + /* ARMv5 restriction: dest != left and dest_hi != left. */ + if (dest == left && left != right) { left = right; right = dest; } + if (irt_isguard(ir->t)) { /* IR_MULOV */ + if (!(as->flags & JIT_F_ARMV6) && dest == left) + tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left)); + asm_guardcc(as, CC_NE); + emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest); + emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left); + } else { + if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP; + emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left); + } + /* Only need this for the dest == left == right case. */ + if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right); +} + +static void asm_add(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D)) + asm_fparith(as, ir, ARMI_VADD_D); + return; + } +#endif + asm_intop_s(as, ir, ARMI_ADD); +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D)) + asm_fparith(as, ir, ARMI_VSUB_D); + return; + } +#endif + asm_intop_s(as, ir, ARMI_SUB); +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, ARMI_VMUL_D); + return; + } +#endif + asm_intmul(as, ir); +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, ARMI_VNEG_D); + return; + } +#endif + asm_intneg(as, ir, ARMI_RSB); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +#if !LJ_SOFTFP +static void asm_callround(ASMState *as, IRIns *ir, int id) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)| + RID2RSET(RID_R3)|RID2RSET(RID_R12); + RegSet of; + Reg dest, src; + ra_evictset(as, drop); + dest = ra_dest(as, ir, RSET_FPR); + emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15)); + emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf : + id == IRFPM_CEIL ? (void *)lj_vm_ceil_sf : + (void *)lj_vm_trunc_sf); + /* Workaround to protect argument GPRs from being used for remat. */ + of = as->freeset; + as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1); + as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L); + src = ra_alloc1(as, ir->op1, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1)); + emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15)); +} +#endif + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + if ((as->flags & JIT_F_ARMV6)) { + emit_dm(as, ARMI_REV, dest, left); + } else { + Reg tmp2 = dest; + if (tmp2 == left) + tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left)); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP); + emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left); + emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left); + } +} + +static void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh) +{ + if (irref_isk(ir->op2)) { /* Constant shifts. */ + /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */ + /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + int32_t shift = (IR(ir->op2)->i & 31); + emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left); + } +} + +static void asm_intmin_max(ASMState *as, IRIns *ir, int cc) +{ + uint32_t kcmp = 0, kmov = 0; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + Reg right = 0; + if (irref_isk(ir->op2)) { + kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i); + if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i); + } + if (!kmov) { + kcmp = 0; + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + if (kmov || dest != right) { + emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right); + cc ^= 1; /* Must use opposite conditions for paired moves. */ + } else { + cc ^= (CC_LT^CC_GT); /* Otherwise may swap CC_LT <-> CC_GT. */ + } + if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left); + emit_nm(as, ARMI_CMP^kcmp, left, right); +} + +#if LJ_SOFTFP +static void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; + RegSet drop = RSET_SCRATCH; + Reg r; + IRRef args[4]; + args[0] = ir->op1; args[1] = (ir+1)->op1; + args[2] = ir->op2; args[3] = (ir+1)->op2; + /* __aeabi_cdcmple preserves r0-r3. */ + if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); + if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r); + if (!rset_test(as->freeset, RID_R2) && + regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2); + if (!rset_test(as->freeset, RID_R3) && + regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3); + ra_evictset(as, drop); + ra_destpair(as, ir); + emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3); + emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2); + emit_call(as, (void *)ci->func); + for (r = RID_R0; r <= RID_R3; r++) + ra_leftov(as, r, args[r-RID_R0]); +} +#else +static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc) +{ + Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = ((left >> 8) & 15); left &= 15; + if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left); + if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ARMI_VCMP_D, left, right); +} +#endif + +static void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc) +{ +#if LJ_SOFTFP + UNUSED(fcc); +#else + if (irt_isnum(ir->t)) + asm_fpmin_max(as, ir, fcc); + else +#endif + asm_intmin_max(as, ir, cc); +} + +/* -- Comparisons --------------------------------------------------------- */ + +/* Map of comparisons to flags. ORDER IR. */ +static const uint8_t asm_compmap[IR_ABC+1] = { + /* op FP swp int cc FP cc */ + /* LT */ CC_GE + (CC_HS << 4), + /* GE x */ CC_LT + (CC_HI << 4), + /* LE */ CC_GT + (CC_HI << 4), + /* GT x */ CC_LE + (CC_HS << 4), + /* ULT x */ CC_HS + (CC_LS << 4), + /* UGE */ CC_LO + (CC_LO << 4), + /* ULE x */ CC_HI + (CC_LO << 4), + /* UGT */ CC_LS + (CC_LS << 4), + /* EQ */ CC_NE + (CC_NE << 4), + /* NE */ CC_EQ + (CC_EQ << 4), + /* ABC */ CC_LS + (CC_LS << 4) /* Same as UGT. */ +}; + +#if LJ_SOFTFP +/* FP comparisons. */ +static void asm_sfpcomp(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; + RegSet drop = RSET_SCRATCH; + Reg r; + IRRef args[4]; + int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1); + args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1; + args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2; + /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */ + for (r = RID_R0; r <= RID_R3; r++) + if (!rset_test(as->freeset, r) && + regcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r); + ra_evictset(as, drop); + asm_guardcc(as, (asm_compmap[ir->o] >> 4)); + emit_call(as, (void *)ci->func); + for (r = RID_R0; r <= RID_R3; r++) + ra_leftov(as, r, args[r-RID_R0]); +} +#else +/* FP comparisons. */ +static void asm_fpcomp(ASMState *as, IRIns *ir) +{ + Reg left, right; + ARMIns ai; + int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1); + if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) { + left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15); + right = 0; + ai = ARMI_VCMPZ_D; + } else { + left = ra_alloc2(as, ir, RSET_FPR); + if (swp) { + right = (left & 15); left = ((left >> 8) & 15); + } else { + right = ((left >> 8) & 15); left &= 15; + } + ai = ARMI_VCMP_D; + } + asm_guardcc(as, (asm_compmap[ir->o] >> 4)); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ai, left, right); +} +#endif + +/* Integer comparisons. */ +static void asm_intcomp(ASMState *as, IRIns *ir) +{ + ARMCC cc = (asm_compmap[ir->o] & 15); + IRRef lref = ir->op1, rref = ir->op2; + Reg left; + uint32_t m; + int cmpprev0 = 0; + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + if (asm_swapops(as, lref, rref)) { + Reg tmp = lref; lref = rref; rref = tmp; + if (cc >= CC_GE) cc ^= 7; /* LT <-> GT, LE <-> GE */ + else if (cc > CC_NE) cc ^= 11; /* LO <-> HI, LS <-> HS */ + } + if (irref_isk(rref) && IR(rref)->i == 0) { + IRIns *irl = IR(lref); + cmpprev0 = (irl+1 == ir); + /* Combine comp(BAND(left, right), 0) into tst left, right. */ + if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) { + IRRef blref = irl->op1, brref = irl->op2; + uint32_t m2 = 0; + Reg bleft; + if (asm_swapops(as, blref, brref)) { + Reg tmp = blref; blref = brref; brref = tmp; + } + if (irref_isk(brref)) { + m2 = emit_isk12(ARMI_AND, IR(brref)->i); + if ((m2 & (ARMI_AND^ARMI_BIC))) + goto notst; /* Not beneficial if we miss a constant operand. */ + } + if (cc == CC_GE) cc = CC_PL; + else if (cc == CC_LT) cc = CC_MI; + else if (cc > CC_NE) goto notst; /* Other conds don't work with tst. */ + bleft = ra_alloc1(as, blref, RSET_GPR); + if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft)); + asm_guardcc(as, cc); + emit_n(as, ARMI_TST^m2, bleft); + return; + } + } +notst: + left = ra_alloc1(as, lref, RSET_GPR); + m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left)); + asm_guardcc(as, cc); + emit_n(as, ARMI_CMP^m, left); + /* Signed comparison with zero and referencing previous ins? */ + if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE)) + as->flagmcp = as->mcp; /* Allow elimination of the compare. */ +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_int64comp(ASMState *as, IRIns *ir) +{ + int signedcomp = (ir->o <= IR_GT); + ARMCC cclo, cchi; + Reg leftlo, lefthi; + uint32_t mlo, mhi; + RegSet allow = RSET_GPR, oldfree; + + /* Always use unsigned comparison for loword. */ + cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15; + leftlo = ra_alloc1(as, ir->op1, allow); + oldfree = as->freeset; + mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo)); + allow &= ~(oldfree & ~as->freeset); /* Update for allocs of asm_fuseopm. */ + + /* Use signed or unsigned comparison for hiword. */ + cchi = asm_compmap[ir->o] & 15; + lefthi = ra_alloc1(as, (ir+1)->op1, allow); + mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi)); + + /* All register allocations must be performed _before_ this point. */ + if (signedcomp) { + MCLabel l_around = emit_label(as); + asm_guardcc(as, cclo); + emit_n(as, ARMI_CMP^mlo, leftlo); + emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around); + if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6; /* GE -> GT, LE -> LT */ + asm_guardcc(as, cchi); + } else { + asm_guardcc(as, cclo); + emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo); + } + emit_n(as, ARMI_CMP^mhi, lefthi); +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI || LJ_SOFTFP + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o <= IR_NE) { /* 64 bit integer or FP comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ +#if LJ_SOFTFP + if (!irt_isint(ir->t)) { + asm_sfpcomp(as, ir-1); + return; + } +#endif +#if LJ_HASFFI + asm_int64comp(as, ir-1); +#endif + return; +#if LJ_SOFTFP + } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) { + as->curins--; /* Always skip the loword min/max. */ + if (uselo || usehi) + asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_HI : CC_LO); + return; +#elif LJ_HASFFI + } else if ((ir-1)->o == IR_CONV) { + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; +#endif + } else if ((ir-1)->o == IR_XSTORE) { + if ((ir-1)->r != RID_SINK) + asm_xstore(as, ir, 4); + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { +#if LJ_HASFFI + case IR_ADD: + as->curins--; + asm_intop(as, ir, ARMI_ADC); + asm_intop(as, ir-1, ARMI_ADD|ARMI_S); + break; + case IR_SUB: + as->curins--; + asm_intop(as, ir, ARMI_SBC); + asm_intop(as, ir-1, ARMI_SUB|ARMI_S); + break; + case IR_NEG: + as->curins--; + asm_intneg(as, ir, ARMI_RSC); + asm_intneg(as, ir-1, ARMI_RSB|ARMI_S); + break; +#endif +#if LJ_SOFTFP + case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + case IR_STRTO: + if (!uselo) + ra_allocref(as, ir->op1, RSET_GPR); /* Mark lo op as used. */ + break; +#endif + case IR_CALLN: + case IR_CALLS: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; +#if LJ_SOFTFP + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: +#endif + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + Reg pbase; + uint32_t k; + if (irp) { + if (!ra_hasspill(irp->s)) { + pbase = irp->r; + lua_assert(ra_hasreg(pbase)); + } else if (allow) { + pbase = rset_pickbot(allow); + } else { + pbase = RID_RET; + emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0); /* Restore temp. register. */ + } + } else { + pbase = RID_BASE; + } + emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno)); + k = emit_isk12(0, (int32_t)(8*topslot)); + lua_assert(k); + emit_n(as, ARMI_CMP^k, RID_TMP); + emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase); + emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, + (int32_t)offsetof(lua_State, maxstack)); + if (irp) { /* Must not spill arbitrary registers in head of side trace. */ + int32_t i = i32ptr(&J2G(as->J)->jit_L); + if (ra_hasspill(irp->s)) + emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s)); + emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095)); + if (ra_hasspill(irp->s) && !allow) + emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0); /* Save temp. register. */ + emit_loadi(as, RID_TMP, (i & ~4095)); + } else { + emit_getgl(as, RID_TMP, jit_L); + } +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { +#if LJ_SOFTFP + RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); + Reg tmp; + lua_assert(irref_isk(ref)); /* LJ_SOFTFP: must be a number constant. */ + tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, + rset_exclude(RSET_GPREVEN, RID_BASE)); + emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs); + if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1); + tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd); + emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4); +#else + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs); +#endif + } else { + RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); + Reg type; + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE)); + emit_lso(as, ARMI_STR, src, RID_BASE, ofs); + if (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), odd); +#if LJ_SOFTFP + } else if ((sn & SNAP_SOFTFPNUM)) { + type = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE)); +#endif + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), odd); + } + emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp1, tmp2; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + tmp1 = ra_releasetmp(as, ASMREF_TMP1); + tmp2 = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp2, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end); + emit_nm(as, ARMI_CMP, RID_TMP, tmp2); + emit_lso(as, ARMI_LDR, tmp2, tmp1, + (int32_t)offsetof(global_State, gc.threshold)); + emit_lso(as, ARMI_LDR, RID_TMP, tmp1, + (int32_t)offsetof(global_State, gc.total)); + ra_allockreg(as, i32ptr(J2G(as->J)), tmp1); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the bcc and patched the final bl. */ + p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu); + } else { + p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Reload L register from g->jit_L. */ +static void asm_head_lreg(ASMState *as) +{ + IRIns *ir = IR(ASMREF_L); + if (ra_used(ir)) { + Reg r = ra_dest(as, ir, RSET_GPR); + emit_getgl(as, r, jit_L); + ra_evictk(as); + } +} + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir; + asm_head_lreg(as); + ir = IR(REF_BASE); + if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) + ra_spill(as, ir); + ra_destreg(as, ir, RID_BASE); +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir; + asm_head_lreg(as); + ir = IR(REF_BASE); + if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) + ra_spill(as, ir); + if (ra_hasspill(irp->s)) { + rset_clear(allow, ra_dest(as, ir, allow)); + } else { + Reg r = irp->r; + lua_assert(ra_hasreg(r)); + rset_clear(allow, r); + if (r != ir->r && !rset_test(as->freeset, r)) + ra_restore(as, regcost_ref(as->cost[r])); + ra_destreg(as, ir, r); + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *p = as->mctop; + MCode *target; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + as->mctop = --p; + } else { + /* Patch stack adjustment. */ + uint32_t k = emit_isk12(ARMI_ADD, spadj); + lua_assert(k); + p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP); + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop - 1; /* Leave room for exit branch. */ + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + as->mcp = p-1; /* Leave room for stack pointer adjustment. */ + as->invmcp = NULL; + } + *p = 0; /* Prevent load/store merging. */ +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: + if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) { + as->curins--; + asm_href(as, ir-1, (IROp)ir->o); + break; + } + /* fallthrough */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { asm_fpcomp(as, ir); break; } +#endif + asm_intcomp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitop(as, ir, ARMI_MVN); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitop(as, ir, ARMI_AND); break; + case IR_BOR: asm_bitop(as, ir, ARMI_ORR); break; + case IR_BXOR: asm_bitop(as, ir, ARMI_EOR); break; + + case IR_BSHL: asm_bitshift(as, ir, ARMSH_LSL); break; + case IR_BSHR: asm_bitshift(as, ir, ARMSH_LSR); break; + case IR_BSAR: asm_bitshift(as, ir, ARMSH_ASR); break; + case IR_BROR: asm_bitshift(as, ir, ARMSH_ROR); break; + case IR_BROL: lua_assert(0); break; + + /* Arithmetic ops. */ + case IR_ADD: case IR_ADDOV: asm_add(as, ir); break; + case IR_SUB: case IR_SUBOV: asm_sub(as, ir); break; + case IR_MUL: case IR_MULOV: asm_mul(as, ir); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_NEG: asm_neg(as, ir); break; + +#if LJ_SOFTFP + case IR_DIV: case IR_POW: case IR_ABS: + case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT: + lua_assert(0); /* Unused for LJ_SOFTFP. */ + break; +#else + case IR_DIV: asm_fparith(as, ir, ARMI_VDIV_D); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_ABS: asm_fpunary(as, ir, ARMI_VABS_D); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 <= IRFPM_TRUNC) + asm_callround(as, ir, ir->op2); + else if (ir->op2 == IRFPM_SQRT) + asm_fpunary(as, ir, ARMI_VSQRT_D); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + case IR_TOBIT: asm_tobit(as, ir); break; +#endif + + case IR_MIN: asm_min_max(as, ir, CC_GT, CC_HI); break; + case IR_MAX: asm_min_max(as, ir, CC_LT, CC_LO); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir, 0); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) { + if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) { + if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { + if (irt_isnum(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; + else fprodd = 0, nslots = (nslots + 3) & ~1; + } else { + if (fprodd) fprodd--; + else if (nfpr > 0) fprodd = 1, nfpr--; + else nslots++; + } + } else if (irt_isnum(IR(args[i])->t)) { + ngpr &= ~1; + if (ngpr > 0) ngpr -= 2; else nslots += 2; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + /* May need extra exit for asm_stack_check on side traces. */ + asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0)); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *cstart = NULL, *cend = p; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MCode *px = exitstub_addr(J, exitno) - 2; + for (; p < pe; p++) { + /* Look for bl_cc exitstub, replace with b_cc target. */ + uint32_t ins = *p; + if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u && + ((ins ^ (px-p)) & 0x00ffffffu) == 0) { + *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu); + cend = p+1; + if (!cstart) cstart = p; + } + } + lua_assert(cstart != NULL); + lj_mcode_sync(cstart, cend); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_mips.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_mips.h new file mode 100644 index 0000000..e5c67b5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_mips.h @@ -0,0 +1,1977 @@ +/* +** MIPS IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate a register or RID_ZERO. */ +static Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!(allow & RSET_FPR) && irref_isk(ref) && IR(ref)->i == 0) + return RID_ZERO; + r = ra_allocref(as, ref, allow); + } else { + ra_noweak(as, r); + } + return r; +} + +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_alloc1z(as, ir->op2, allow); + left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_alloc1z(as, ir->op1, allow); + right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} + +/* -- Guard handling ------------------------------------------------------ */ + +/* Need some spare long-range jump slots, for out-of-range branches. */ +#define MIPS_SPAREJUMP 4 + +/* Setup spare long-range jump slots per mcarea. */ +static void asm_sparejump_setup(ASMState *as) +{ + MCode *mxp = as->mcbot; + /* Assumes sizeof(MCLink) == 8. */ + if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == 8) { + lua_assert(MIPSI_NOP == 0); + memset(mxp+2, 0, MIPS_SPAREJUMP*8); + mxp += MIPS_SPAREJUMP*2; + lua_assert(mxp < as->mctop); + lj_mcode_sync(as->mcbot, mxp); + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + } +} + +/* Setup exit stub after the end of each trace. */ +static void asm_exitstub_setup(ASMState *as) +{ + MCode *mxp = as->mctop; + /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */ + *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno; + *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu); + lua_assert(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0); + *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0; + as->mctop = mxp; +} + +/* Keep this in-sync with exitstub_trace_addr(). */ +#define asm_exitstub_addr(as) ((as)->mctop) + +/* Emit conditional branch to exit for guard. */ +static void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt) +{ + MCode *target = asm_exitstub_addr(as); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->invmcp = NULL; + as->loopinv = 1; + as->mcp = p+1; + mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u); /* Invert cond. */ + target = p; /* Patch target later in asm_loop_fixup. */ + } + emit_ti(as, MIPSI_LI, RID_TMP, as->snapno); + emit_branch(as, mi, rs, rt, target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + int32_t jgl = (intptr_t)J2G(as->J); + if ((uint32_t)(ofs-jgl) < 65536) { + *ofsp = ofs-jgl-32768; + return RID_JGL; + } else { + *ofsp = (int16_t)ofs; + return ra_allock(as, ofs-(int16_t)ofs, allow); + } + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) { + ref = ir->op1; + ofs = ofs2; + } + } else if (ir->o == IR_STRREF) { + int32_t ofs2 = 65536; + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs2 = ofs + IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs2 = ofs + IR(ir->op1)->i; + ref = ir->op2; + } + if (!checki16(ofs2)) { + /* NYI: Fuse ADD with constant. */ + Reg right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + emit_hsi(as, mi, rt, RID_TMP, ofs); + emit_dst(as, MIPSI_ADDU, RID_TMP, left, right); + return; + } + ofs = ofs2; + } + } + base = ra_alloc1(as, ref, allow); + emit_hsi(as, mi, rt, base, ofs); +} + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 16; + Reg gpr, fpr = REGARG_FIRSTFPR; + if ((void *)ci->func) + emit_call(as, (void *)ci->func); + for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) + as->cost[gpr] = REGCOST(~0u, ASMREF_L); + gpr = REGARG_FIRSTGPR; + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + if (ref) { + IRIns *ir = IR(ref); + if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR && + !(ci->flags & CCI_VARARG)) { + lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */ + ra_leftov(as, fpr, ref); + fpr += 2; + gpr += irt_isnum(ir->t) ? 2 : 1; + } else { + fpr = REGARG_LASTFPR+1; + if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1; + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */ + if (irt_isfp(ir->t)) { + RegSet of = as->freeset; + Reg r; + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + r = ra_alloc1(as, ref, RSET_FPR); + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + if (irt_isnum(ir->t)) { + emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1); + emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r); + lua_assert(rset_test(as->freeset, gpr+1)); /* Already evicted. */ + gpr += 2; + } else if (irt_isfloat(ir->t)) { + emit_tg(as, MIPSI_MFC1, gpr, r); + gpr++; + } + } else { + ra_leftov(as, gpr, ref); + gpr++; + } + } else { + Reg r = ra_alloc1z(as, ref, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, r, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } + } else { + fpr = REGARG_LASTFPR+1; + if (gpr <= REGARG_LASTGPR) + gpr++; + else + ofs += 4; + } + checkmclim(as); + } +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (irt_isfp(ir->t)) { + if ((ci->flags & CCI_CASTU64)) { + int32_t ofs = sps_scale(ir->s); + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1); + emit_tg(as, MIPSI_MTC1, RID_RETLO, dest); + } + if (ofs) { + emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4)); + } + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need specific register for indirect calls. */ + Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR)); + MCode *p = as->mcp; + if (r == RID_CFUNCADDR) + *--p = MIPSI_NOP; + else + *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r); + *--p = MIPSI_JALR | MIPSF_S(r); + as->mcp = p; + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callround(ASMState *as, IRIns *ir, IRCallID id) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)| + RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR); + if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); + ra_evictset(as, drop); + ra_destreg(as, ir, RID_FPRET); + emit_call(as, (void *)lj_ir_callinfo[id].func); + ra_leftov(as, REGARG_FIRSTFPR, ir->op1); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guard(as, MIPSI_BNE, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_tsi(as, MIPSI_LW, RID_TMP, base, -8); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guard(as, MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left); + emit_fg(as, MIPSI_CVT_D_W, tmp, tmp); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, MIPSI_CVT_W_D, tmp, left); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fgh(as, MIPSI_ADD_D, tmp, left, right); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(irt_isint64(ir->t) || + (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S, + dest, ra_alloc1(as, lref, RSET_FPR)); + } else if (st == IRT_U32) { /* U32 to FP conversion. */ + /* y = (x ^ 0x8000000) + 2147483648.0 */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + emit_fgh(as, irt_isfloat(ir->t) ? MIPSI_ADD_S : MIPSI_ADD_D, + dest, dest, tmp); + emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W, + dest, dest); + if (irt_isfloat(ir->t)) + emit_lsptr(as, MIPSI_LWC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)), + RSET_GPR); + else + emit_lsptr(as, MIPSI_LDC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)), + RSET_GPR); + emit_tg(as, MIPSI_MTC1, RID_TMP, dest); + emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left); + emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000); + } else { /* Integer to FP conversion. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W, + dest, dest); + emit_tg(as, MIPSI_MTC1, left, dest); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + if (irt_isu32(ir->t)) { + /* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */ + emit_dst(as, MIPSI_XOR, dest, dest, RID_TMP); + emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D, + tmp, tmp); + emit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D, + tmp, left, tmp); + if (st == IRT_FLOAT) + emit_lsptr(as, MIPSI_LWC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)), + RSET_GPR); + else + emit_lsptr(as, MIPSI_LDC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)), + RSET_GPR); + } else { + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D, + tmp, left); + } + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((ir->op2 & IRCONV_SEXT)) { + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left); + } else { + uint32_t shift = st == IRT_I8 ? 24 : 16; + emit_dta(as, MIPSI_SRA, dest, dest, shift); + emit_dta(as, MIPSI_SLL, dest, left, shift); + } + } else { + emit_tsi(as, MIPSI_ANDI, dest, left, + (int32_t)(st == IRT_U8 ? 0xff : 0xffff)); + } + } else { /* 32/64 bit integer conversions. */ + /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + const CCallInfo *ci; + IRRef args[2]; + args[LJ_BE?0:1] = ir->op1; + args[LJ_BE?1:0] = (ir-1)->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = &lj_ir_callinfo[id]; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + RegSet drop = RSET_SCRATCH; + if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */ + ra_evictset(as, drop); + asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), + RID_SP, sps_scale(ir->s)); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + else /* Otherwise force a spill and use the spill slot. */ + emit_tsi(as, MIPSI_ADDIU, dest, RID_SP, ra_spill(as, ir)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, offsetof(global_State, tmptv)-32768); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_setgl(as, src, tmptv.gcr); + } + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_setgl(as, type, tmptv.it); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_tsi(as, MIPSI_ADDIU, dest, base, ofs); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_dst(as, MIPSI_ADDU, dest, RID_TMP, base); + emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + rset_clear(allow, tab); + if (irt_isnum(kt)) { + key = ra_alloc1(as, refkey, RSET_FPR); + tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key)); + } else if (!irt_ispri(kt)) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + type = ra_allock(as, irt_toitype(irkey->t), allow); + rset_clear(allow, type); + } + tmp2 = ra_scratch(as, allow); + rset_clear(allow, tmp2); + + /* Key not found in chain: load niltv. */ + l_end = emit_label(as); + if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + else + *--as->mcp = MIPSI_NOP; + /* Follow hash chain until the end. */ + emit_move(as, dest, tmp1); + l_loop = --as->mcp; + emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (irt_isnum(kt)) { + emit_branch(as, MIPSI_BC1T, 0, 0, l_end); + emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key); + emit_tg(as, MIPSI_MFC1, tmp1, key+1); + emit_branch(as, MIPSI_BEQ, tmp1, RID_ZERO, l_next); + emit_tsi(as, MIPSI_SLTIU, tmp1, tmp1, (int32_t)LJ_TISNUM); + emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n)); + } else { + if (irt_ispri(kt)) { + emit_branch(as, MIPSI_BEQ, tmp1, type, l_end); + } else { + emit_branch(as, MIPSI_BEQ, tmp2, key, l_end); + emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.gcr)); + emit_branch(as, MIPSI_BNE, tmp1, type, l_next); + } + } + emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.it)); + *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + Reg tmphash = tmp1; + if (irref_isk(refkey)) + tmphash = ra_allock(as, khash, allow); + emit_dst(as, MIPSI_ADDU, dest, dest, tmp1); + lua_assert(sizeof(Node) == 24); + emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1); + emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3); + emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5); + emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash); + emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask)); + if (irref_isk(refkey)) { + /* Nothing to do. */ + } else if (irt_isstr(kt)) { + emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, hash)); + } else { /* Must match with hash*() in lj_tab.c. */ + emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2); + emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31); + emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2); + emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31); + emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest); + if (irt_isnum(kt)) { + emit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1); + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31); + } else { + emit_dst(as, MIPSI_OR, dest, dest, tmp1); + emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1); + emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31); + } + emit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1); + emit_tg(as, MIPSI_MFC1, tmp2, key); + emit_tg(as, MIPSI_MFC1, tmp1, key+1); + } else { + emit_dst(as, MIPSI_XOR, tmp2, key, tmp1); + emit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31); + emit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow)); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + int32_t lo, hi; + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 32736) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_tsi(as, MIPSI_ADDIU, dest, node, ofs); + } + if (!irt_ispri(irkey->t)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + } + if (irt_isnum(irkey->t)) { + lo = (int32_t)ir_knum(irkey)->u32.lo; + hi = (int32_t)ir_knum(irkey)->u32.hi; + } else { + lo = irkey->i; + hi = irt_toitype(irkey->t); + if (!ra_hasreg(key)) + goto nolo; + } + asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO); +nolo: + asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO); + if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4)); + if (ofs > 32736) + emit_tsi(as, MIPSI_ADDU, dest, node, ra_allock(as, ofs, allow)); +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); + } +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, MIPSI_LW, dest, v, RSET_GPR); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, MIPSI_ADDIU, dest, uv, (int32_t)offsetof(GCupval, tv)); + emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_tsi(as, MIPSI_LW, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_tsi(as, MIPSI_LW, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + int32_t ofs = (int32_t)sizeof(GCstr); + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + checki16(ofs + IR(irr->op2)->i)) { + ofs += IR(irr->op2)->i; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs); + emit_dst(as, MIPSI_ADDU, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + ofs += IR(refk)->i; + if (checki16(ofs)) + emit_tsi(as, MIPSI_ADDIU, dest, r, ofs); + else + emit_dst(as, MIPSI_ADDU, dest, r, + ra_allock(as, ofs, rset_exclude(RSET_GPR, r))); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static MIPSIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return MIPSI_LB; + case IRT_U8: return MIPSI_LBU; + case IRT_I16: return MIPSI_LH; + case IRT_U16: return MIPSI_LHU; + case IRT_NUM: return MIPSI_LDC1; + case IRT_FLOAT: return MIPSI_LWC1; + default: return MIPSI_LW; + } +} + +static MIPSIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return MIPSI_SB; + case IRT_I16: case IRT_U16: return MIPSI_SH; + case IRT_NUM: return MIPSI_SDC1; + case IRT_FLOAT: return MIPSI_SWC1; + default: return MIPSI_SW; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + MIPSIns mi = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_tsi(as, MIPSI_ADDIU, dest, idx, ofs); + return; + } + } + ofs = field_ofs[ir->op2]; + lua_assert(!irt_isfp(ir->t)); + emit_tsi(as, mi, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1z(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + MIPSIns mi = asm_fxstoreins(ir); + lua_assert(!irt_isfp(ir->t)); + emit_tsi(as, mi, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1z(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_TMP, idx; + RegSet allow = RSET_GPR; + int32_t ofs = 0; + if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + rset_clear(allow, idx); + if (irt_isnum(t)) { + asm_guard(as, MIPSI_BEQ, type, RID_ZERO); + emit_tsi(as, MIPSI_SLTIU, type, type, (int32_t)LJ_TISNUM); + if (ra_hasreg(dest)) + emit_hsi(as, MIPSI_LDC1, dest, idx, ofs); + } else { + asm_guard(as, MIPSI_BNE, type, ra_allock(as, irt_toitype(t), allow)); + if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0)); + } + emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4)); +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = 0; + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + } else { + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + rset_clear(allow, type); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(ir->t)) { + emit_hsi(as, MIPSI_SDC1, src, idx, ofs); + } else { + if (ra_hasreg(src)) + emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4)); + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(!irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ + } else if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (irt_isint(t)) { + Reg tmp = ra_scratch(as, RSET_FPR); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, MIPSI_CVT_W_D, tmp, tmp); + dest = tmp; + t.irt = IRT_NUM; /* Check for original type. */ + } else { + Reg tmp = ra_scratch(as, RSET_GPR); + emit_fg(as, MIPSI_CVT_D_W, dest, dest); + emit_tg(as, MIPSI_MTC1, tmp, dest); + dest = tmp; + t.irt = IRT_INT; /* Check for original type. */ + } + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); +dotypecheck: + if (irt_isnum(t)) { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)LJ_TISNUM); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_hsi(as, MIPSI_LDC1, dest, base, ofs); + } else { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + Reg ktype = ra_allock(as, irt_toitype(t), allow); + asm_guard(as, MIPSI_BNE, RID_TMP, ktype); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0)); + } + if (ra_hasreg(type)) emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4)); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; + lua_assert((ir+1)->o == IR_HIOP); + if (LJ_LE) ir++; + } + for (;;) { + Reg r = ra_alloc1z(as, ir->op2, allow); + emit_tsi(as, MIPSI_SW, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; if (LJ_BE) ir++; else ir--; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct)); + emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid)); + emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA); + emit_ti(as, MIPSI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */ + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg link = RID_TMP; + MCLabel l_end = emit_label(as); + emit_tsi(as, MIPSI_SW, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_setgl(as, tab, gc.grayagain); + emit_getgl(as, link, gc.grayagain); + emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP); /* Clear black bit. */ + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK); + emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK); + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_tsi(as, MIPSI_LBU, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +static void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + emit_fgh(as, mi, dest, left, right); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_fg(as, mi, dest, left); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_ADD_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, MIPSI_ADDU, dest, left, right); + } +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_SUB_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_SUBU, dest, left, right); + } +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_MUL_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_MUL, dest, left, right); + } +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, MIPSI_NEG_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); + } +} + +static void asm_arithov(ASMState *as, IRIns *ir) +{ + Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { + int k = IR(ir->op2)->i; + if (ir->o == IR_SUBOV) k = -k; + if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */ + left = ra_alloc1(as, ir->op1, RSET_GPR); + asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + if (dest == left) emit_move(as, RID_TMP, left); + return; + } + } + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left), + right), dest)); + asm_guard(as, MIPSI_BLTZ, RID_TMP, 0); + emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp); + if (ir->o == IR_ADDOV) { /* ((dest^left) & (dest^right)) < 0 */ + emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right); + } else { /* ((dest^left) & (dest^~right)) < 0 */ + emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest); + emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO); + } + emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left); + emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right); + if (dest == left || dest == right) + emit_move(as, RID_TMP, dest == left ? left : right); +} + +static void asm_mulov(ASMState *as, IRIns *ir) +{ +#if LJ_DUALNUM +#error "NYI: MULOV" +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused in single-number mode. */ +#endif +} + +#if LJ_HASFFI +static void asm_add64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) { + emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP); + goto loarith; + } else if (checki16(k)) { + emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + goto loarith; + } + } + emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP); + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, MIPSI_ADDU, dest, left, right); +loarith: + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) { + if (dest != left) + emit_move(as, dest, left); + return; + } else if (checki16(k)) { + if (dest == left) { + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + if (dest == left && dest == right) { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left); + emit_dst(as, MIPSI_ADDU, dest, left, right); +} + +static void asm_sub64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SUBU, dest, left, right); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (dest == left) { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest); + emit_dst(as, MIPSI_SUBU, dest, left, right); +} + +static void asm_neg64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); +} +#endif + +static void asm_bitnot(ASMState *as, IRIns *ir) +{ + Reg left, right, dest = ra_dest(as, ir, RSET_GPR); + IRIns *irl = IR(ir->op1); + if (mayfuse(as, ir->op1) && irl->o == IR_BOR) { + left = ra_alloc2(as, irl, RSET_GPR); + right = (left >> 8); left &= 255; + } else { + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + right = RID_ZERO; + } + emit_dst(as, MIPSI_NOR, dest, left, right); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16); + emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left); + } else { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest)); + emit_dst(as, MIPSI_OR, dest, dest, tmp); + emit_dst(as, MIPSI_OR, dest, dest, RID_TMP); + emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00); + emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8); + emit_dta(as, MIPSI_SRL, dest, left, 8); + emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00); + emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP); + emit_dta(as, MIPSI_SRL, tmp, left, 24); + emit_dta(as, MIPSI_SLL, RID_TMP, left, 24); + } +} + +static void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checku16(k)) { + emit_tsi(as, mik, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, mi, dest, left, right); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31); + emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR), shift); + } else { + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, mi, dest, right, left); /* Shift amount is in rs. */ + } +} + +static void asm_bitror(ASMState *as, IRIns *ir) +{ + if ((as->flags & JIT_F_MIPS32R2)) { + asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_rotr(as, dest, left, RID_TMP, shift); + } else { + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_OR, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SRLV, dest, right, left); + emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left); + emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right); + } + } +} + +static void asm_min_max(ASMState *as, IRIns *ir, int ismax) +{ + if (irt_isnum(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (dest == left) { + emit_fg(as, MIPSI_MOVT_D, dest, right); + } else { + emit_fg(as, MIPSI_MOVF_D, dest, left); + if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right); + } + emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? left : right, ismax ? right : left); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (dest == left) { + emit_dst(as, MIPSI_MOVN, dest, right, RID_TMP); + } else { + emit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP); + if (dest != right) emit_move(as, dest, right); + } + emit_dst(as, MIPSI_SLT, RID_TMP, + ismax ? left : right, ismax ? right : left); + } +} + +/* -- Comparisons --------------------------------------------------------- */ + +static void asm_comp(ASMState *as, IRIns *ir) +{ + /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */ + IROp op = ir->o; + if (irt_isnum(ir->t)) { + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right); + } else { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + if (op == IR_ABC) op = IR_UGT; + if ((op&4) == 0 && irref_isk(ir->op2) && IR(ir->op2)->i == 0) { + MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) : + ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ); + asm_guard(as, mi, left, 0); + } else { + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if ((op&2)) k++; + if (checki16(k)) { + asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI, + RID_TMP, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, + RID_TMP, (op&2) ? right : left, (op&2) ? left : right); + } + } +} + +static void asm_compeq(ASMState *as, IRIns *ir) +{ + Reg right, left = ra_alloc2(as, ir, irt_isnum(ir->t) ? RSET_FPR : RSET_GPR); + right = (left >> 8); left &= 255; + if (irt_isnum(ir->t)) { + asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_EQ_D, 0, left, right); + } else { + asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right); + } +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_comp64(ASMState *as, IRIns *ir) +{ + /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */ + IROp op = (ir-1)->o; + MCLabel l_end; + Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR); + righthi = (lefthi >> 8); lefthi &= 255; + leftlo = ra_alloc2(as, ir-1, + rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi)); + rightlo = (leftlo >> 8); leftlo &= 255; + asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + l_end = emit_label(as); + if (lefthi != righthi) + emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP, + (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi); + emit_dst(as, MIPSI_SLTU, RID_TMP, + (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo); + if (lefthi != righthi) + emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end); +} + +static void asm_comp64eq(ASMState *as, IRIns *ir) +{ + Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO); + tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp); + emit_dst(as, MIPSI_XOR, tmp, left, right); + left = ra_alloc2(as, ir-1, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_XOR, RID_TMP, left, right); +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; + } else if ((ir-1)->o < IR_EQ) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64(as, ir); + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64eq(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + as->curins--; /* Handle both stores here. */ + if ((ir-1)->r != RID_SINK) { + asm_xstore(as, ir, LJ_LE ? 4 : 0); + asm_xstore(as, ir-1, LJ_LE ? 0 : 4); + } + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: as->curins--; asm_add64(as, ir); break; + case IR_SUB: as->curins--; asm_sub64(as, ir); break; + case IR_NEG: as->curins--; asm_neg64(as, ir); break; + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */ + Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE; + ExitNo oldsnap = as->snapno; + rset_clear(allow, pbase); + tmp = allow ? rset_pickbot(allow) : + (pbase == RID_RETHI ? RID_RETLO : RID_RETHI); + as->snapno = exitno; + asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO); + as->snapno = oldsnap; + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_tsi(as, MIPSI_LW, tmp, RID_SP, 0); + else + ra_modified(as, tmp); + emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot)); + emit_dst(as, MIPSI_SUBU, RID_TMP, tmp, pbase); + emit_tsi(as, MIPSI_LW, tmp, tmp, offsetof(lua_State, maxstack)); + if (pbase == RID_TMP) + emit_getgl(as, RID_TMP, jit_base); + emit_getgl(as, tmp, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_tsi(as, MIPSI_SW, tmp, RID_SP, 0); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs); + } else { + Reg type; + RegSet allow = rset_exclude(RSET_GPR, RID_BASE); + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + rset_clear(allow, src); + emit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0)); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), allow); + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + } + emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4)); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + /* Assumes asm_snap_prep() already done. */ + asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + tmp = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end); + emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp); + emit_getgl(as, tmp, gc.threshold); + emit_getgl(as, RID_TMP, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + p[-1] = MIPSI_NOP; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guard already inverted the cond branch. Only patch the target. */ + p[-3] |= ((target-p+2) & 0x0000ffffu); + } else { + p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (as->loopinv) as->mctop--; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_move(as, r, RID_BASE); + } +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (as->loopinv) as->mctop--; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_move(as, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp; + int32_t spadj = as->T->spadjust; + MCode *p = as->mctop-1; + *p = spadj ? (MIPSI_ADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP; + p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + as->mcp = as->mctop-2; /* Leave room for branch plus nop or stack adj. */ + as->invmcp = as->loopref ? as->mcp : NULL; +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: asm_compeq(as, ir); break; + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: + asm_comp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitnot(as, ir); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI); break; + case IR_BOR: asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI); break; + case IR_BXOR: asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI); break; + + case IR_BSHL: asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL); break; + case IR_BSHR: asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL); break; + case IR_BSAR: asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA); break; + case IR_BROL: lua_assert(0); break; + case IR_BROR: asm_bitror(as, ir); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: asm_sub(as, ir); break; + case IR_MUL: asm_mul(as, ir); break; + case IR_DIV: asm_fparith(as, ir, MIPSI_DIV_D); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_NEG: asm_neg(as, ir); break; + + case IR_ABS: asm_fpunary(as, ir, MIPSI_ABS_D); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_MIN: asm_min_max(as, ir, 0); break; + case IR_MAX: asm_min_max(as, ir, 1); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 <= IRFPM_TRUNC) + asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2); + else if (ir->op2 == IRFPM_SQRT) + asm_fpunary(as, ir, MIPSI_SQRT_D); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + + /* Overflow-checking arithmetic ops. */ + case IR_ADDOV: asm_arithov(as, ir); break; + case IR_SUBOV: asm_arithov(as, ir); break; + case IR_MULOV: asm_mulov(as, ir); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) { + if (args[i] && irt_isfp(IR(args[i])->t) && + nfpr > 0 && !(ci->flags & CCI_VARARG)) { + nfpr--; + ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1; + } else if (args[i] && irt_isnum(IR(args[i])->t)) { + nfpr = 0; + ngpr = ngpr & ~1; + if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1; + } else { + nfpr = 0; + if (ngpr > 0) ngpr--; else nslots++; + } + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + asm_sparejump_setup(as); + asm_exitstub_setup(as); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *px = exitstub_trace_addr(T, exitno); + MCode *cstart = NULL, *cstop = NULL; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno; + MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); + for (p++; p < pe; p++) { + if (*p == exitload) { /* Look for load of exit number. */ + if (((p[-1] ^ (px-p)) & 0xffffu) == 0) { /* Look for exitstub branch. */ + ptrdiff_t delta = target - p; + if (((delta + 0x8000) >> 16) == 0) { /* Patch in-range branch. */ + patchbranch: + p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu); + *p = MIPSI_NOP; /* Replace the load of the exit number. */ + cstop = p; + if (!cstart) cstart = p-1; + } else { /* Branch out of range. Use spare jump slot in mcarea. */ + int i; + for (i = 2; i < 2+MIPS_SPAREJUMP*2; i += 2) { + if (mcarea[i] == tjump) { + delta = mcarea+i - p; + goto patchbranch; + } else if (mcarea[i] == MIPSI_NOP) { + mcarea[i] = tjump; + cstart = mcarea+i; + delta = mcarea+i - p; + goto patchbranch; + } + } + /* Ignore jump slot overflow. Child trace is simply not attached. */ + } + } else if (p+1 == pe) { + /* Patch NOP after code for inverted loop branch. Use of J is ok. */ + lua_assert(p[1] == MIPSI_NOP); + p[1] = tjump; + *p = MIPSI_NOP; /* Replace the load of the exit number. */ + cstop = p+2; + if (!cstart) cstart = p+1; + } + } + } + if (cstart) lj_mcode_sync(cstart, cstop); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_ppc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_ppc.h new file mode 100644 index 0000000..e1a496a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_ppc.h @@ -0,0 +1,2167 @@ +/* +** PPC IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_allocref(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_allocref(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_allocref(as, ir->op2, allow); + left = ra_alloc1(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_allocref(as, ir->op1, allow); + right = ra_alloc1(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} + +/* -- Guard handling ------------------------------------------------------ */ + +/* Setup exit stubs after the end of each trace. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + MCode *mxp = as->mctop; + /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */ + for (i = nexits-1; (int32_t)i >= 0; i--) + *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2); + *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno; /* Read by exit handler. */ + mxp--; + *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2); + *--mxp = PPCI_MFLR|PPCF_T(RID_TMP); + as->mctop = mxp; +} + +static MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno) +{ + /* Keep this in-sync with exitstub_trace_addr(). */ + return as->mctop + exitno + 3; +} + +/* Emit conditional branch to exit for guard. */ +static void asm_guardcc(ASMState *as, PPCCC cc) +{ + MCode *target = asm_exitstub_addr(as, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2); + emit_condbranch(as, PPCI_BC, cc^4, p); + return; + } + emit_condbranch(as, PPCI_BC, cc, target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Indicates load/store indexed is ok. */ +#define AHUREF_LSX ((int32_t)0x80000000) + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + if (*ofsp == AHUREF_LSX) { + Reg base = ra_alloc1(as, ir->op1, allow); + Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + return base | (idx << 8); + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + int32_t jgl = (intptr_t)J2G(as->J); + if ((uint32_t)(ofs-jgl) < 65536) { + *ofsp = ofs-jgl-32768; + return RID_JGL; + } else { + *ofsp = (int16_t)ofs; + return ra_allock(as, ofs-(int16_t)ofs, allow); + } + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) { + ofs = ofs2; + ref = ir->op1; + } else if (ofs == 0) { + Reg right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right); + return; + } + } else if (ir->o == IR_STRREF) { + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs += IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs += IR(ir->op1)->i; + ref = ir->op2; + } else { + /* NYI: Fuse ADD with constant. */ + Reg tmp, right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + tmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right)); + emit_fai(as, pi, rt, tmp, ofs); + emit_tab(as, PPCI_ADD, tmp, left, right); + return; + } + if (!checki16(ofs)) { + Reg left = ra_alloc1(as, ref, allow); + Reg right = ra_allock(as, ofs, rset_exclude(allow, left)); + emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right); + return; + } + } + } + base = ra_alloc1(as, ref, allow); + emit_fai(as, pi, rt, base, ofs); +} + +/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */ +static void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref, + RegSet allow) +{ + IRIns *ira = IR(ref); + Reg right, left; + if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) { + left = ra_alloc2(as, ira, allow); + right = (left >> 8); left &= 255; + } else { + right = ra_alloc1(as, ref, allow); + left = RID_R0; + } + emit_tab(as, pi, rt, left, right); +} + +/* Fuse to multiply-add/sub instruction. */ +static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir) +{ + IRRef lref = ir->op1, rref = ir->op2; + IRIns *irm; + if (lref != rref && + ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && + ra_noreg(irm->r)) || + (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && + (rref = lref, pi = pir, ra_noreg(irm->r))))) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg add = ra_alloc1(as, rref, RSET_FPR); + Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add)); + right = (left >> 8); left &= 255; + emit_facb(as, pi, dest, left, right, add); + return 1; + } + return 0; +} + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 8; + Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR; + if ((void *)ci->func) + emit_call(as, (void *)ci->func); + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + if (ref) { + IRIns *ir = IR(ref); + if (irt_isfp(ir->t)) { + if (fpr <= REGARG_LASTFPR) { + lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */ + ra_leftov(as, fpr, ref); + fpr++; + } else { + Reg r = ra_alloc1(as, ref, RSET_FPR); + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, r, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } else { + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */ + ra_leftov(as, gpr, ref); + gpr++; + } else { + Reg r = ra_alloc1(as, ref, RSET_GPR); + emit_spstore(as, ir, r, ofs); + ofs += 4; + } + } + } else { + if (gpr <= REGARG_LASTGPR) + gpr++; + else + ofs += 4; + } + checkmclim(as); + } + if ((ci->flags & CCI_VARARG)) /* Vararg calls need to know about FPR use. */ + emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6); +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (irt_isfp(ir->t)) { + if ((ci->flags & CCI_CASTU64)) { + /* Use spill slot or temp slots. */ + int32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP; + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_fai(as, PPCI_LFD, dest, RID_SP, ofs); + } + emit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs); + emit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4); + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need a non-argument register for indirect calls. */ + RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1); + Reg freg = ra_alloc1(as, func, allow); + *--as->mcp = PPCI_BCTRL; + *--as->mcp = PPCI_MTCTR | PPCF_T(freg); + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_ab(as, PPCI_CMPW, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_tai(as, PPCI_LWZ, RID_TMP, base, -8); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + RegSet allow = RSET_FPR; + Reg tmp = ra_scratch(as, rset_clear(allow, left)); + Reg fbias = ra_scratch(as, rset_clear(allow, tmp)); + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest)); + asm_guardcc(as, CC_NE); + emit_fab(as, PPCI_FCMPU, 0, tmp, left); + emit_fab(as, PPCI_FSUB, tmp, tmp, fbias); + emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP); + emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000); + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_lsptr(as, PPCI_LFS, (fbias & 31), + (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)), + RSET_GPR); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, left); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fab(as, PPCI_FADD, tmp, left, right); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(irt_isint64(ir->t) || + (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + if (st == IRT_NUM) /* double -> float conversion. */ + emit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR)); + else /* float -> double conversion is a no-op on PPC. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else { /* Integer to FP conversion. */ + /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */ + /* IRT_U32: Bias with 2^52, subtract 2^52. */ + RegSet allow = RSET_GPR; + Reg left = ra_alloc1(as, lref, allow); + Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left)); + Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + const float *kbias; + if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest); + emit_fab(as, PPCI_FSUB, dest, dest, fbias); + emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP); + kbias = (const float *)lj_ir_k64_find(as->J, U64x(59800004,59800000)); + if (st == IRT_U32) kbias++; + emit_lsptr(as, PPCI_LFS, (fbias & 31), (void *)kbias, + rset_clear(allow, hibias)); + emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP, + RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + if (irt_isu32(ir->t)) { + /* Convert both x and x-2^31 to int and merge results. */ + Reg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest)); + emit_asb(as, PPCI_OR, dest, dest, tmpi); /* Select with mask idiom. */ + emit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP); + emit_asb(as, PPCI_ANDC, dest, dest, RID_TMP); + emit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO); /* tmp = (int)(x) */ + emit_tai(as, PPCI_ADDIS, dest, dest, 0x8000); /* dest += 2^31 */ + emit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31); /* mask = -(dest < 0) */ + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_tai(as, PPCI_LWZ, dest, + RID_SP, SPOFS_TMPLO); /* dest = (int)(x-2^31) */ + emit_fb(as, PPCI_FCTIWZ, tmp, left); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, tmp); + emit_fab(as, PPCI_FSUB, tmp, left, tmp); + emit_lsptr(as, PPCI_LFS, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,00000000)), + RSET_GPR); + } else { + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, left); + } + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((ir->op2 & IRCONV_SEXT)) + emit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left); + else + emit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31); + } else { /* 32/64 bit integer conversions. */ + /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + const CCallInfo *ci; + IRRef args[2]; + args[0] = ir->op1; + args[1] = (ir-1)->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = &lj_ir_callinfo[id]; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + int32_t ofs; + RegSet drop = RSET_SCRATCH; + if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */ + ra_evictset(as, drop); + asm_guardcc(as, CC_EQ); + emit_ai(as, PPCI_CMPWI, RID_RET, 0); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP; + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + else /* Otherwise force a spill and use the spill slot. */ + emit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_tai(as, PPCI_ADDI, dest, RID_JGL, offsetof(global_State, tmptv)-32768); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_setgl(as, src, tmptv.gcr); + } + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_setgl(as, type, tmptv.it); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_tai(as, PPCI_ADDI, dest, base, ofs); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_tab(as, PPCI_ADD, dest, RID_TMP, base); + emit_slwi(as, RID_TMP, idx, 3); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir, IROp merge) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, tmp1 = RID_TMP, tmp2; + Reg tisnum = RID_NONE, tmpnum = RID_NONE; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + rset_clear(allow, tab); + if (irt_isnum(kt)) { + key = ra_alloc1(as, refkey, RSET_FPR); + tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key)); + tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow); + rset_clear(allow, tisnum); + } else if (!irt_ispri(kt)) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } + tmp2 = ra_scratch(as, allow); + rset_clear(allow, tmp2); + + /* Key not found in chain: jump to exit (if merged) or load niltv. */ + l_end = emit_label(as); + as->invmcp = NULL; + if (merge == IR_NE) + asm_guardcc(as, CC_EQ); + else if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + + /* Follow hash chain until the end. */ + l_loop = --as->mcp; + emit_ai(as, PPCI_CMPWI, dest, 0); + emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (merge == IR_EQ) + asm_guardcc(as, CC_EQ); + else + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + if (irt_isnum(kt)) { + emit_fab(as, PPCI_FCMPU, 0, tmpnum, key); + emit_condbranch(as, PPCI_BC, CC_GE, l_next); + emit_ab(as, PPCI_CMPLW, tmp1, tisnum); + emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n)); + } else { + if (!irt_ispri(kt)) { + emit_ab(as, PPCI_CMPW, tmp2, key); + emit_condbranch(as, PPCI_BC, CC_NE, l_next); + } + emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t)); + if (!irt_ispri(kt)) + emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr)); + } + emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it)); + *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) | + (((char *)as->mcp-(char *)l_loop) & 0xffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + Reg tmphash = tmp1; + if (irref_isk(refkey)) + tmphash = ra_allock(as, khash, allow); + emit_tab(as, PPCI_ADD, dest, dest, tmp1); + emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node)); + emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash); + emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask)); + if (irref_isk(refkey)) { + /* Nothing to do. */ + } else if (irt_isstr(kt)) { + emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, hash)); + } else { /* Must match with hash*() in lj_tab.c. */ + emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1); + emit_rotlwi(as, tmp2, tmp2, HASH_ROT3); + emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2); + emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31); + emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2); + if (irt_isnum(kt)) { + int32_t ofs = ra_spill(as, irkey); + emit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1); + emit_rotlwi(as, dest, tmp1, HASH_ROT1); + emit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1); + emit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4); + emit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs); + } else { + emit_asb(as, PPCI_XOR, tmp2, key, tmp1); + emit_rotlwi(as, dest, tmp1, HASH_ROT1); + emit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS); + emit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 32736) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_tai(as, PPCI_ADDI, dest, node, ofs); + } + asm_guardcc(as, CC_NE); + if (!irt_ispri(irkey->t)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + } + rset_clear(allow, type); + if (irt_isnum(irkey->t)) { + emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo); + asm_guardcc(as, CC_NE); + emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi); + } else { + if (ra_hasreg(key)) { + emit_cmpi(as, key, irkey->i); /* May use RID_TMP, i.e. type. */ + asm_guardcc(as, CC_NE); + } + emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t)); + } + if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4); + emit_tai(as, PPCI_LWZ, type, idx, kofs); + if (ofs > 32736) { + emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16); + emit_tai(as, PPCI_ADDI, dest, node, ofs); + } +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, RID_TMP, 1); + emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv)); + emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_tai(as, PPCI_LWZ, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + int32_t ofs = (int32_t)sizeof(GCstr); + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + checki16(ofs + IR(irr->op2)->i)) { + ofs += IR(irr->op2)->i; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tai(as, PPCI_ADDI, dest, dest, ofs); + emit_tab(as, PPCI_ADD, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + ofs += IR(refk)->i; + if (checki16(ofs)) + emit_tai(as, PPCI_ADDI, dest, r, ofs); + else + emit_tab(as, PPCI_ADD, dest, r, + ra_allock(as, ofs, rset_exclude(RSET_GPR, r))); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static PPCIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return PPCI_LBZ; /* Needs sign-extension. */ + case IRT_U8: return PPCI_LBZ; + case IRT_I16: return PPCI_LHA; + case IRT_U16: return PPCI_LHZ; + case IRT_NUM: return PPCI_LFD; + case IRT_FLOAT: return PPCI_LFS; + default: return PPCI_LWZ; + } +} + +static PPCIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return PPCI_STB; + case IRT_I16: case IRT_U16: return PPCI_STH; + case IRT_NUM: return PPCI_STFD; + case IRT_FLOAT: return PPCI_STFS; + default: return PPCI_STW; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + PPCIns pi = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_tai(as, PPCI_ADDI, dest, idx, ofs); + return; + } + } + ofs = field_ofs[ir->op2]; + lua_assert(!irt_isi8(ir->t)); + emit_tai(as, pi, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + PPCIns pi = asm_fxstoreins(ir); + emit_tai(as, pi, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + if (irt_isi8(ir->t)) + emit_as(as, PPCI_EXTSB, dest, dest); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + IRIns *irb; + if (ir->r == RID_SINK) + return; + if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP && + ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) { + /* Fuse BSWAP with XSTORE to stwbrx. */ + Reg src = ra_alloc1(as, irb->op1, RSET_GPR); + asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src)); + } else { + Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx; + RegSet allow = RSET_GPR; + int32_t ofs = AHUREF_LSX; + if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + if (!irt_isnum(t)) ofs = 0; + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(t)) { + Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx)); + asm_guardcc(as, CC_GE); + emit_ab(as, PPCI_CMPLW, type, tisnum); + if (ra_hasreg(dest)) { + if (ofs == AHUREF_LSX) { + tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, + (idx&255)), (idx>>8))); + emit_fab(as, PPCI_LFDX, dest, (idx&255), tmp); + } else { + emit_fai(as, PPCI_LFD, dest, idx, ofs); + } + } + } else { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, type, irt_toitype(t)); + if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4); + } + if (ofs == AHUREF_LSX) { + emit_tab(as, PPCI_LWZX, type, (idx&255), tmp); + emit_slwi(as, tmp, (idx>>8), 3); + } else { + emit_tai(as, PPCI_LWZ, type, idx, ofs); + } +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = AHUREF_LSX; + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + } else { + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + ofs = 0; + } + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + rset_clear(allow, type); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(ir->t)) { + if (ofs == AHUREF_LSX) { + emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP); + emit_slwi(as, RID_TMP, (idx>>8), 3); + } else { + emit_fai(as, PPCI_STFD, src, idx, ofs); + } + } else { + if (ra_hasreg(src)) + emit_tai(as, PPCI_STW, src, idx, ofs+4); + if (ofs == AHUREF_LSX) { + emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP); + emit_slwi(as, RID_TMP, (idx>>8), 3); + } else { + emit_tai(as, PPCI_STW, type, idx, ofs); + } + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4); + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(LJ_DUALNUM || + !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ + } else if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (irt_isint(t)) { + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + dest = ra_scratch(as, RSET_FPR); + emit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, dest, dest); + t.irt = IRT_NUM; /* Check for original type. */ + } else { + Reg tmp = ra_scratch(as, allow); + Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp)); + Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + emit_fab(as, PPCI_FSUB, dest, dest, fbias); + emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP); + emit_lsptr(as, PPCI_LFS, (fbias & 31), + (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)), + rset_clear(allow, hibias)); + emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + emit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000); + dest = tmp; + t.irt = IRT_INT; /* Check for original type. */ + } + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); +dotypecheck: + if (irt_isnum(t)) { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow); + asm_guardcc(as, CC_GE); + emit_ab(as, PPCI_CMPLW, RID_TMP, tisnum); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_fai(as, PPCI_LFD, dest, base, ofs-4); + } else { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t)); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs); + } + if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; + lua_assert((ir+1)->o == IR_HIOP); + } + for (;;) { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_tai(as, PPCI_STW, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir++; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct)); + emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid)); + emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA); + emit_ti(as, PPCI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */ + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg link = RID_TMP; + MCLabel l_end = emit_label(as); + emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_setgl(as, tab, gc.grayagain); + lua_assert(LJ_GC_BLACK == 0x04); + emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28); /* Clear black bit. */ + emit_getgl(as, link, gc.grayagain); + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK); + emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK); + emit_condbranch(as, PPCI_BC, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_tai(as, PPCI_LBZ, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +static void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (pi == PPCI_FMUL) + emit_fac(as, pi, dest, left, right); + else + emit_fab(as, pi, dest, left, right); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_fb(as, pi, dest, left); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD)) + asm_fparith(as, ir, PPCI_FADD); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + PPCIns pi; + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + pi = PPCI_ADDI; + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi = PPCI_ADDICDOT; + } + emit_tai(as, pi, dest, left, k); + return; + } else if ((k & 0xffff) == 0) { + emit_tai(as, PPCI_ADDIS, dest, left, (k >> 16)); + return; + } else if (!as->sectref) { + emit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16); + emit_tai(as, PPCI_ADDI, dest, left, k); + return; + } + } + pi = PPCI_ADD; + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, left, right); + } +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB)) + asm_fparith(as, ir, PPCI_FSUB); + } else { + PPCIns pi = PPCI_SUBF; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left, right; + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (checki16(k)) { + right = ra_alloc1(as, ir->op2, RSET_GPR); + emit_tai(as, PPCI_SUBFIC, dest, right, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */ + } +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, PPCI_FMUL); + } else { + PPCIns pi = PPCI_MULLW; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tai(as, PPCI_MULLI, dest, left, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, left, right); + } +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, PPCI_FNEG); + } else { + Reg dest, left; + PPCIns pi = PPCI_NEG; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_tab(as, pi, dest, left, 0); + } +} + +static void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest, left, right; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + } + asm_guardcc(as, CC_SO); + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; } + emit_tab(as, pi|PPCF_DOT, dest, left, right); +} + +#if LJ_HASFFI +static void asm_add64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + PPCIns pi = PPCI_ADDE; + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) + pi = PPCI_ADDZE; + else if (k == -1) + pi = PPCI_ADDME; + else + goto needright; + right = 0; + } else { + needright: + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tab(as, pi, dest, left, right); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tai(as, PPCI_ADDIC, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, PPCI_ADDC, dest, left, right); +} + +static void asm_sub64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR); + PPCIns pi = PPCI_SUBFE; + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (k == 0) + pi = PPCI_SUBFZE; + else if (k == -1) + pi = PPCI_SUBFME; + else + goto needleft; + left = 0; + } else { + needleft: + left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right)); + } + emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */ + ir--; + dest = ra_dest(as, ir, RSET_GPR); + right = ra_alloc1(as, ir->op2, RSET_GPR); + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (checki16(k)) { + emit_tai(as, PPCI_SUBFIC, dest, right, k); + return; + } + } + left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right)); + emit_tab(as, PPCI_SUBFC, dest, right, left); +} + +static void asm_neg64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_tab(as, PPCI_SUBFZE, dest, left, 0); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_tai(as, PPCI_SUBFIC, dest, left, 0); +} +#endif + +static void asm_bitnot(ASMState *as, IRIns *ir) +{ + Reg dest, left, right; + PPCIns pi = PPCI_NOR; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + if (mayfuse(as, ir->op1)) { + IRIns *irl = IR(ir->op1); + if (irl->o == IR_BAND) + pi ^= (PPCI_NOR ^ PPCI_NAND); + else if (irl->o == IR_BXOR) + pi ^= (PPCI_NOR ^ PPCI_EQV); + else if (irl->o != IR_BOR) + goto nofuse; + left = ra_hintalloc(as, irl->op1, dest, RSET_GPR); + right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left)); + } else { +nofuse: + left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + } + emit_asb(as, pi, dest, left, right); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRIns *irx; + if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD && + ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) { + /* Fuse BSWAP with XLOAD to lwbrx. */ + asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR); + } else { + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + Reg tmp = dest; + if (tmp == left) { + tmp = RID_TMP; + emit_mr(as, dest, RID_TMP); + } + emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23); + emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7); + emit_rotlwi(as, tmp, left, 8); + } +} + +static void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + Reg tmp = left; + if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) { + if (!checku16(k)) { + emit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16)); + if ((k & 0xffff) == 0) return; + } + emit_asi(as, pik, dest, left, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, pi, dest, left, right); +} + +/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */ +static void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref) +{ + IRIns *ir; + Reg left; + if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) && + irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) { + int32_t sh = (IR(ir->op2)->i & 31); + switch (ir->o) { + case IR_BSHL: + if ((mask & ((1u<>sh))) goto nofuse; + sh = ((32-sh)&31); + break; + case IR_BROL: + break; + default: + goto nofuse; + } + left = ra_alloc1(as, ir->op1, RSET_GPR); + *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh); + return; + } +nofuse: + left = ra_alloc1(as, ref, RSET_GPR); + *--as->mcp = pi | PPCF_T(left); +} + +static void asm_bitand(ASMState *as, IRIns *ir) +{ + Reg dest, left, right; + IRRef lref = ir->op1; + PPCIns dot = 0; + IRRef op2; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + dot = PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k) { + /* First check for a contiguous bitmask as used by rlwinm. */ + uint32_t s1 = lj_ffs((uint32_t)k); + uint32_t k1 = ((uint32_t)k >> s1); + if ((k1 & (k1+1)) == 0) { + asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) | + PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1), + k, lref); + return; + } + if (~(uint32_t)k) { + uint32_t s2 = lj_ffs(~(uint32_t)k); + uint32_t k2 = (~(uint32_t)k >> s2); + if ((k2 & (k2+1)) == 0) { + asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) | + PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)), + k, lref); + return; + } + } + } + if (checku16(k)) { + left = ra_alloc1(as, lref, RSET_GPR); + emit_asi(as, PPCI_ANDIDOT, dest, left, k); + return; + } else if ((k & 0xffff) == 0) { + left = ra_alloc1(as, lref, RSET_GPR); + emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16)); + return; + } + } + op2 = ir->op2; + if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) { + dot ^= (PPCI_AND ^ PPCI_ANDC); + op2 = IR(op2)->op1; + } + left = ra_hintalloc(as, lref, dest, RSET_GPR); + right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, PPCI_AND ^ dot, dest, left, right); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik) +{ + Reg dest, left; + Reg dot = 0; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + dot = PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + int32_t shift = (IR(ir->op2)->i & 31); + if (pik == 0) /* SLWI */ + emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift); + else if (pik == 1) /* SRWI */ + emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31); + else + emit_asb(as, pik|dot, dest, left, shift); + } else { + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, pi|dot, dest, left, right); + } +} + +static void asm_min_max(ASMState *as, IRIns *ir, int ismax) +{ + if (irt_isnum(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg tmp = dest; + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (tmp == left || tmp == right) + tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR, + dest), left), right)); + emit_facb(as, PPCI_FSEL, dest, tmp, + ismax ? left : right, ismax ? right : left); + emit_fab(as, PPCI_FSUB, tmp, left, right); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg tmp1 = RID_TMP, tmp2 = dest; + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (tmp2 == left || tmp2 == right) + tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, + dest), left), right)); + emit_tab(as, PPCI_ADD, dest, tmp2, right); + emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1); + emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1); + emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1); + emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000); + emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000); + } +} + +/* -- Comparisons --------------------------------------------------------- */ + +#define CC_UNSIGNED 0x08 /* Unsigned integer comparison. */ +#define CC_TWO 0x80 /* Check two flags for FP comparison. */ + +/* Map of comparisons to flags. ORDER IR. */ +static const uint8_t asm_compmap[IR_ABC+1] = { + /* op int cc FP cc */ + /* LT */ CC_GE + (CC_GE<<4), + /* GE */ CC_LT + (CC_LE<<4) + CC_TWO, + /* LE */ CC_GT + (CC_GE<<4) + CC_TWO, + /* GT */ CC_LE + (CC_LE<<4), + /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO, + /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4), + /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4), + /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO, + /* EQ */ CC_NE + (CC_NE<<4), + /* NE */ CC_EQ + (CC_EQ<<4), + /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO /* Same as UGT. */ +}; + +static void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc) +{ + Reg right, left = ra_alloc1(as, lref, RSET_GPR); + if (irref_isk(rref)) { + int32_t k = IR(rref)->i; + if ((cc & CC_UNSIGNED) == 0) { /* Signed comparison with constant. */ + if (checki16(k)) { + emit_tai(as, PPCI_CMPWI, cr, left, k); + /* Signed comparison with zero and referencing previous ins? */ + if (k == 0 && lref == as->curins-1) + as->flagmcp = as->mcp; /* Allow elimination of the compare. */ + return; + } else if ((cc & 3) == (CC_EQ & 3)) { /* Use CMPLWI for EQ or NE. */ + if (checku16(k)) { + emit_tai(as, PPCI_CMPLWI, cr, left, k); + return; + } else if (!as->sectref && ra_noreg(IR(rref)->r)) { + emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k); + emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16)); + return; + } + } + } else { /* Unsigned comparison with constant. */ + if (checku16(k)) { + emit_tai(as, PPCI_CMPLWI, cr, left, k); + return; + } + } + } + right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left)); + emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right); +} + +static void asm_comp(ASMState *as, IRIns *ir) +{ + PPCCC cc = asm_compmap[ir->o]; + if (irt_isnum(ir->t)) { + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + asm_guardcc(as, (cc >> 4)); + if ((cc & CC_TWO)) + emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3)); + emit_fab(as, PPCI_FCMPU, 0, left, right); + } else { + IRRef lref = ir->op1, rref = ir->op2; + if (irref_isk(lref) && !irref_isk(rref)) { + /* Swap constants to the right (only for ABC). */ + IRRef tmp = lref; lref = rref; rref = tmp; + if ((cc & 2) == 0) cc ^= 1; /* LT <-> GT, LE <-> GE */ + } + asm_guardcc(as, cc); + asm_intcomp_(as, lref, rref, 0, cc); + } +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_comp64(ASMState *as, IRIns *ir) +{ + PPCCC cc = asm_compmap[(ir-1)->o]; + if ((cc&3) == (CC_EQ&3)) { + asm_guardcc(as, cc); + emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR, + (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3)); + } else { + asm_guardcc(as, CC_EQ); + emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1)); + emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC, + (CC_EQ&3), (CC_EQ&3), 4+(cc&3)); + } + /* Loword comparison sets cr1 and is unsigned, except for equality. */ + asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4, + cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED)); + /* Hiword comparison sets cr0. */ + asm_intcomp_(as, ir->op1, ir->op2, 0, cc); + as->flagmcp = NULL; /* Doesn't work here. */ +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + as->curins--; /* Handle both stores here. */ + if ((ir-1)->r != RID_SINK) { + asm_xstore(as, ir, 0); + asm_xstore(as, ir-1, 4); + } + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: as->curins--; asm_add64(as, ir); break; + case IR_SUB: as->curins--; asm_sub64(as, ir); break; + case IR_NEG: as->curins--; asm_neg64(as, ir); break; + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */ + Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE; + rset_clear(allow, pbase); + tmp = allow ? rset_pickbot(allow) : + (pbase == RID_RETHI ? RID_RETLO : RID_RETHI); + emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno)); + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW); + else + ra_modified(as, tmp); + emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot)); + emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp); + emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack)); + if (pbase == RID_TMP) + emit_getgl(as, RID_TMP, jit_base); + emit_getgl(as, tmp, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_fai(as, PPCI_STFD, src, RID_BASE, ofs); + } else { + Reg type; + RegSet allow = rset_exclude(RSET_GPR, RID_BASE); + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + rset_clear(allow, src); + emit_tai(as, PPCI_STW, src, RID_BASE, ofs+4); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), allow); + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + } + emit_tai(as, PPCI_STW, type, RID_BASE, ofs); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_ai(as, PPCI_CMPWI, RID_RET, 0); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + tmp = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end); + emit_ab(as, PPCI_CMPLW, RID_TMP, tmp); + emit_getgl(as, tmp, gc.threshold); + emit_getgl(as, RID_TMP, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the cond branch and patched the final b. */ + p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2); + } else { + p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_mr(as, r, RID_BASE); + } +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_mr(as, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *p = as->mctop; + MCode *target; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + *--p = PPCI_NOP; + *--p = PPCI_NOP; + as->mctop = p; + } else { + /* Patch stack adjustment. */ + lua_assert(checki16(CFRAME_SIZE+spadj)); + p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj); + p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj; + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop - 1; /* Leave room for exit branch. */ + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + as->mcp = p-2; /* Leave room for stack pointer adjustment. */ + as->invmcp = NULL; + } +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: + if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) { + as->curins--; + asm_href(as, ir-1, (IROp)ir->o); + break; + } + /* fallthrough */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: + asm_comp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitnot(as, ir); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitand(as, ir); break; + case IR_BOR: asm_bitop(as, ir, PPCI_OR, PPCI_ORI); break; + case IR_BXOR: asm_bitop(as, ir, PPCI_XOR, PPCI_XORI); break; + + case IR_BSHL: asm_bitshift(as, ir, PPCI_SLW, 0); break; + case IR_BSHR: asm_bitshift(as, ir, PPCI_SRW, 1); break; + case IR_BSAR: asm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI); break; + case IR_BROL: asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31), + PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31)); break; + case IR_BROR: lua_assert(0); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: asm_sub(as, ir); break; + case IR_MUL: asm_mul(as, ir); break; + case IR_DIV: asm_fparith(as, ir, PPCI_FDIV); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_NEG: asm_neg(as, ir); break; + + case IR_ABS: asm_fpunary(as, ir, PPCI_FABS); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_MIN: asm_min_max(as, ir, 0); break; + case IR_MAX: asm_min_max(as, ir, 1); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT)) + asm_fpunary(as, ir, PPCI_FSQRT); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + + /* Overflow-checking arithmetic ops. */ + case IR_ADDOV: asm_arithov(as, ir, PPCI_ADDO); break; + case IR_SUBOV: asm_arithov(as, ir, PPCI_SUBFO); break; + case IR_MULOV: asm_arithov(as, ir, PPCI_MULLWO); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir, 0); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0)); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *px = exitstub_trace_addr(T, exitno); + MCode *cstart = NULL; + MCode *mcarea = lj_mcode_patch(J, p, 0); + int clearso = 0; + for (; p < pe; p++) { + /* Look for exitstub branch, try to replace with branch to target. */ + uint32_t ins = *p; + if ((ins & 0xfc000000u) == 0x40000000u && + ((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) { + ptrdiff_t delta = (char *)target - (char *)p; + if (((ins >> 16) & 3) == (CC_SO&3)) { + clearso = sizeof(MCode); + delta -= sizeof(MCode); + } + /* Many, but not all short-range branches can be patched directly. */ + if (((delta + 0x8000) >> 16) == 0) { + *p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) | + ((delta & 0x8000) * (PPCF_Y/0x8000)); + if (!cstart) cstart = p; + } + } else if ((ins & 0xfc000000u) == PPCI_B && + ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) { + ptrdiff_t delta = (char *)target - (char *)p; + lua_assert(((delta + 0x02000000) >> 26) == 0); + *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu); + if (!cstart) cstart = p; + } + } + { /* Always patch long-range branch in exit stub itself. */ + ptrdiff_t delta = (char *)target - (char *)px - clearso; + lua_assert(((delta + 0x02000000) >> 26) == 0); + *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu); + } + if (!cstart) cstart = px; + lj_mcode_sync(cstart, px+1); + if (clearso) { /* Extend the current trace. Ugly workaround. */ + MCode *pp = J->cur.mcode; + J->cur.szmcode += sizeof(MCode); + *--pp = PPCI_MCRXR; /* Clear SO flag. */ + J->cur.mcode = pp; + lj_mcode_sync(pp, pp+1); + } + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_x86.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_x86.h new file mode 100644 index 0000000..fda911e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_asm_x86.h @@ -0,0 +1,2794 @@ +/* +** x86/x64 IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Guard handling ------------------------------------------------------ */ + +/* Generate an exit stub group at the bottom of the reserved MCode memory. */ +static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) +{ + ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff; + MCode *mxp = as->mcbot; + MCode *mxpstart = mxp; + if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop) + asm_mclimit(as); + /* Push low byte of exitno for each exit stub. */ + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs; + for (i = 1; i < EXITSTUBS_PER_GROUP; i++) { + *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2); + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i); + } + /* Push the high byte of the exitno for each exit stub group. */ + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8); + /* Store DISPATCH at original stack slot 0. Account for the two push ops. */ + *mxp++ = XI_MOVmi; + *mxp++ = MODRM(XM_OFS8, 0, RID_ESP); + *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + *mxp++ = 2*sizeof(void *); + *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4; + /* Jump to exit handler which fills in the ExitState. */ + *mxp++ = XI_JMP; mxp += 4; + *((int32_t *)(mxp-4)) = jmprel(mxp, (MCode *)(void *)lj_vm_exit_handler); + /* Commit the code for this group (even if assembly fails later on). */ + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + return mxpstart; +} + +/* Setup all needed exit stubs. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) + lj_trace_err(as->J, LJ_TRERR_SNAPOV); + for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++) + if (as->J->exitstubgroup[i] == NULL) + as->J->exitstubgroup[i] = asm_exitstub_gen(as, i); +} + +/* Emit conditional branch to exit for guard. +** It's important to emit this *after* all registers have been allocated, +** because rematerializations may invalidate the flags. +*/ +static void asm_guardcc(ASMState *as, int cc) +{ + MCode *target = exitstub_addr(as->J, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *(int32_t *)(p+1) = jmprel(p+5, target); + target = p; + cc ^= 1; + if (as->realign) { + emit_sjcc(as, cc, target); + return; + } + } + emit_jcc(as, cc, target); +} + +/* -- Memory operand fusion ----------------------------------------------- */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if a reference is a signed 32 bit constant. */ +static int asm_isk32(ASMState *as, IRRef ref, int32_t *k) +{ + if (irref_isk(ref)) { + IRIns *ir = IR(ref); + if (ir->o != IR_KINT64) { + *k = ir->i; + return 1; + } else if (checki32((int64_t)ir_kint64(ir)->u64)) { + *k = (int32_t)ir_kint64(ir)->u64; + return 1; + } + } + return 0; +} + +/* Check if there's no conflicting instruction between curins and ref. +** Also avoid fusing loads if there are multiple references. +*/ +static int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) { + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref)) + return 0; + } + return 1; /* Ok, no conflict. */ +} + +/* Fuse array base into memory operand. */ +static IRRef asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *irb = IR(ref); + as->mrm.ofs = 0; + if (irb->o == IR_FLOAD) { + IRIns *ira = IR(irb->op1); + lua_assert(irb->op2 == IRFL_TAB_ARRAY); + /* We can avoid the FLOAD of t->array for colocated arrays. */ + if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) { + as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */ + return irb->op1; /* Table obj. */ + } + } else if (irb->o == IR_ADD && irref_isk(irb->op2)) { + /* Fuse base offset (vararg load). */ + as->mrm.ofs = IR(irb->op2)->i; + return irb->op1; + } + return ref; /* Otherwise use the given array base. */ +} + +/* Fuse array reference into memory operand. */ +static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irx; + lua_assert(ir->o == IR_AREF); + as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow); + irx = IR(ir->op2); + if (irref_isk(ir->op2)) { + as->mrm.ofs += 8*irx->i; + as->mrm.idx = RID_NONE; + } else { + rset_clear(allow, as->mrm.base); + as->mrm.scale = XM_SCALE8; + /* Fuse a constant ADD (e.g. t[i+1]) into the offset. + ** Doesn't help much without ABCelim, but reduces register pressure. + */ + if (!LJ_64 && /* Has bad effects with negative index on x64. */ + mayfuse(as, ir->op2) && ra_noreg(irx->r) && + irx->o == IR_ADD && irref_isk(irx->op2)) { + as->mrm.ofs += 8*IR(irx->op2)->i; + as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow); + } else { + as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow); + } + } +} + +/* Fuse array/hash/upvalue reference into memory operand. +** Caveat: this may allocate GPRs for the base/idx registers. Be sure to +** pass the final allow mask, excluding any GPRs used for other inputs. +** In particular: 2-operand GPR instructions need to call ra_dest() first! +*/ +static void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + switch ((IROp)ir->o) { + case IR_AREF: + if (mayfuse(as, ref)) { + asm_fusearef(as, ir, allow); + return; + } + break; + case IR_HREFK: + if (mayfuse(as, ref)) { + as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); + as->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + as->mrm.idx = RID_NONE; + return; + } + break; + case IR_UREFC: + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + GCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv; + as->mrm.ofs = ptr2addr(&uv->tv); + as->mrm.base = as->mrm.idx = RID_NONE; + return; + } + break; + default: + lua_assert(ir->o == IR_HREF || ir->o == IR_NEWREF || ir->o == IR_UREFO || + ir->o == IR_KKPTR); + break; + } + } + as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow); + as->mrm.ofs = 0; + as->mrm.idx = RID_NONE; +} + +/* Fuse FLOAD/FREF reference into memory operand. */ +static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow) +{ + lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF); + as->mrm.ofs = field_ofs[ir->op2]; + as->mrm.idx = RID_NONE; + if (irref_isk(ir->op1)) { + as->mrm.ofs += IR(ir->op1)->i; + as->mrm.base = RID_NONE; + } else { + as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); + } +} + +/* Fuse string reference into memory operand. */ +static void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irr; + lua_assert(ir->o == IR_STRREF); + as->mrm.base = as->mrm.idx = RID_NONE; + as->mrm.scale = XM_SCALE1; + as->mrm.ofs = sizeof(GCstr); + if (irref_isk(ir->op1)) { + as->mrm.ofs += IR(ir->op1)->i; + } else { + Reg r = ra_alloc1(as, ir->op1, allow); + rset_clear(allow, r); + as->mrm.base = (uint8_t)r; + } + irr = IR(ir->op2); + if (irref_isk(ir->op2)) { + as->mrm.ofs += irr->i; + } else { + Reg r; + /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */ + if (!LJ_64 && /* Has bad effects with negative index on x64. */ + mayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) { + as->mrm.ofs += IR(irr->op2)->i; + r = ra_alloc1(as, irr->op1, allow); + } else { + r = ra_alloc1(as, ir->op2, allow); + } + if (as->mrm.base == RID_NONE) + as->mrm.base = (uint8_t)r; + else + as->mrm.idx = (uint8_t)r; + } +} + +static void asm_fusexref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + as->mrm.idx = RID_NONE; + if (ir->o == IR_KPTR || ir->o == IR_KKPTR) { + as->mrm.ofs = ir->i; + as->mrm.base = RID_NONE; + } else if (ir->o == IR_STRREF) { + asm_fusestrref(as, ir, allow); + } else { + as->mrm.ofs = 0; + if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) { + /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */ + IRIns *irx; + IRRef idx; + Reg r; + if (asm_isk32(as, ir->op2, &as->mrm.ofs)) { /* Recognize x+ofs. */ + ref = ir->op1; + ir = IR(ref); + if (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r))) + goto noadd; + } + as->mrm.scale = XM_SCALE1; + idx = ir->op1; + ref = ir->op2; + irx = IR(idx); + if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) { /* Try other operand. */ + idx = ir->op2; + ref = ir->op1; + irx = IR(idx); + } + if (canfuse(as, irx) && ra_noreg(irx->r)) { + if (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) { + /* Recognize idx<op1; + as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6); + } else if (irx->o == IR_ADD && irx->op1 == irx->op2) { + /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */ + idx = irx->op1; + as->mrm.scale = XM_SCALE2; + } + } + r = ra_alloc1(as, idx, allow); + rset_clear(allow, r); + as->mrm.idx = (uint8_t)r; + } + noadd: + as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow); + } +} + +/* Fuse load into memory operand. */ +static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_hasreg(ir->r)) { + if (allow != RSET_EMPTY) { /* Fast path. */ + ra_noweak(as, ir->r); + return ir->r; + } + fusespill: + /* Force a spill if only memory operands are allowed (asm_x87load). */ + as->mrm.base = RID_ESP; + as->mrm.ofs = ra_spill(as, ir); + as->mrm.idx = RID_NONE; + return RID_MRM; + } + if (ir->o == IR_KNUM) { + RegSet avail = as->freeset & ~as->modset & RSET_FPR; + lua_assert(allow != RSET_EMPTY); + if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */ + as->mrm.ofs = ptr2addr(ir_knum(ir)); + as->mrm.base = as->mrm.idx = RID_NONE; + return RID_MRM; + } + } else if (mayfuse(as, ref)) { + RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR; + if (ir->o == IR_SLOAD) { + if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) && + noconflict(as, ref, IR_RETF, 0)) { + as->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow); + as->mrm.ofs = 8*((int32_t)ir->op1-1) + ((ir->op2&IRSLOAD_FRAME)?4:0); + as->mrm.idx = RID_NONE; + return RID_MRM; + } + } else if (ir->o == IR_FLOAD) { + /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */ + if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) && + noconflict(as, ref, IR_FSTORE, 0)) { + asm_fusefref(as, ir, xallow); + return RID_MRM; + } + } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) { + if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0)) { + asm_fuseahuref(as, ir->op1, xallow); + return RID_MRM; + } + } else if (ir->o == IR_XLOAD) { + /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp). + ** Fusing unaligned memory operands is ok on x86 (except for SIMD types). + */ + if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) && + noconflict(as, ref, IR_XSTORE, 0)) { + asm_fusexref(as, ir->op1, xallow); + return RID_MRM; + } + } else if (ir->o == IR_VLOAD) { + asm_fuseahuref(as, ir->op1, xallow); + return RID_MRM; + } + } + if (!(as->freeset & allow) && + (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref))) + goto fusespill; + return ra_allocref(as, ref, allow); +} + +#if LJ_64 +/* Don't fuse a 32 bit load into a 64 bit operation. */ +static Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64) +{ + if (is64 && !irt_is64(IR(ref)->t)) + return ra_alloc1(as, ref, allow); + return asm_fuseload(as, ref, allow); +} +#else +#define asm_fuseloadm(as, ref, allow, is64) asm_fuseload(as, (ref), (allow)) +#endif + +/* -- Calls --------------------------------------------------------------- */ + +/* Count the required number of stack slots for a call. */ +static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t i, nargs = CCI_NARGS(ci); + int nslots = 0; +#if LJ_64 + if (LJ_ABI_WIN) { + nslots = (int)(nargs*2); /* Only matters for more than four args. */ + } else { + int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; else nslots += 2; + } else { + if (ngpr > 0) ngpr--; else nslots += 2; + } + } +#else + int ngpr = 0; + if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL) + ngpr = 2; + else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL) + ngpr = 1; + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + nslots += irt_isnum(IR(args[i])->t) ? 2 : 1; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } +#endif + return nslots; +} + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = STACKARG_OFS; +#if LJ_64 + uint32_t gprs = REGARG_GPRS; + Reg fpr = REGARG_FIRSTFPR; +#if !LJ_ABI_WIN + MCode *patchnfpr = NULL; +#endif +#else + uint32_t gprs = 0; + if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) { + if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL) + gprs = (REGARG_GPRS & 31); + else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL) + gprs = REGARG_GPRS; + } +#endif + if ((void *)ci->func) + emit_call(as, ci->func); +#if LJ_64 + if ((ci->flags & CCI_VARARG)) { /* Special handling for vararg calls. */ +#if LJ_ABI_WIN + for (n = 0; n < 4 && n < nargs; n++) { + IRIns *ir = IR(args[n]); + if (irt_isfp(ir->t)) /* Duplicate FPRs in GPRs. */ + emit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n), + ((gprs >> (n*5)) & 31)); /* Either MOVD or MOVQ. */ + } +#else + patchnfpr = --as->mcp; /* Indicate number of used FPRs in register al. */ + *--as->mcp = XI_MOVrib | RID_EAX; +#endif + } +#endif + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + IRIns *ir = IR(ref); + Reg r; +#if LJ_64 && LJ_ABI_WIN + /* Windows/x64 argument registers are strictly positional. */ + r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31); + fpr++; gprs >>= 5; +#elif LJ_64 + /* POSIX/x64 argument registers are used in order of appearance. */ + if (irt_isfp(ir->t)) { + r = fpr <= REGARG_LASTFPR ? fpr++ : 0; + } else { + r = gprs & 31; gprs >>= 5; + } +#else + if (ref && irt_isfp(ir->t)) { + r = 0; + } else { + r = gprs & 31; gprs >>= 5; + if (!ref) continue; + } +#endif + if (r) { /* Argument is in a register. */ + if (r < RID_MAX_GPR && ref < ASMREF_TMP1) { +#if LJ_64 + if (ir->o == IR_KINT64) + emit_loadu64(as, r, ir_kint64(ir)->u64); + else +#endif + emit_loadi(as, r, ir->i); + } else { + lua_assert(rset_test(as->freeset, r)); /* Must have been evicted. */ + if (ra_hasreg(ir->r)) { + ra_noweak(as, ir->r); + emit_movrr(as, ir, r, ir->r); + } else { + ra_allocref(as, ref, RID2RSET(r)); + } + } + } else if (irt_isfp(ir->t)) { /* FP argument is on stack. */ + lua_assert(!(irt_isfloat(ir->t) && irref_isk(ref))); /* No float k. */ + if (LJ_32 && (ofs & 4) && irref_isk(ref)) { + /* Split stores for unaligned FP consts. */ + emit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo); + emit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi); + } else { + r = ra_alloc1(as, ref, RSET_FPR); + emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, + r, RID_ESP, ofs); + } + ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8; + } else { /* Non-FP argument is on stack. */ + if (LJ_32 && ref < ASMREF_TMP1) { + emit_movmroi(as, RID_ESP, ofs, ir->i); + } else { + r = ra_alloc1(as, ref, RSET_GPR); + emit_movtomro(as, REX_64 + r, RID_ESP, ofs); + } + ofs += sizeof(intptr_t); + } + checkmclim(as); + } +#if LJ_64 && !LJ_ABI_WIN + if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR; +#endif +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = (LJ_32 && (ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + if (irt_isfp(ir->t)) { + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ +#if LJ_64 + if ((ci->flags & CCI_CASTU64)) { + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rr(as, XO_MOVD, dest|REX_64, RID_RET); /* Really MOVQ. */ + } + if (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs); + } else { + ra_destreg(as, ir, RID_FPRET); + } +#else + /* Number result is in x87 st0 for x86 calling convention. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, + dest, RID_ESP, ofs); + } + if ((ci->flags & CCI_CASTU64)) { + emit_movtomro(as, RID_RETLO, RID_ESP, ofs); + emit_movtomro(as, RID_RETHI, RID_ESP, ofs+4); + } else { + emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd, + irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs); + } +#endif +#if LJ_32 + } else if (hiop) { + ra_destpair(as, ir); +#endif + } else { + lua_assert(!irt_ispri(ir->t)); + ra_destreg(as, ir, RID_RET); + } + } else if (LJ_32 && irt_isfp(ir->t)) { + emit_x87op(as, XI_FPOP); /* Pop unused result from x87 st0. */ + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +/* Return a constant function pointer or NULL for indirect calls. */ +static void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func) +{ +#if LJ_32 + UNUSED(as); + if (irref_isk(func)) + return (void *)irf->i; +#else + if (irref_isk(func)) { + MCode *p; + if (irf->o == IR_KINT64) + p = (MCode *)(void *)ir_k64(irf)->u64; + else + p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i; + if (p - as->mcp == (int32_t)(p - as->mcp)) + return p; /* Call target is still in +-2GB range. */ + /* Avoid the indirect case of emit_call(). Try to hoist func addr. */ + } +#endif + return NULL; +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + int32_t spadj = 0; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); +#if LJ_32 + /* Have to readjust stack after non-cdecl calls due to callee cleanup. */ + if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL) + spadj = 4 * asm_count_call_slots(as, &ci, args); +#endif + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + ci.func = (ASMFunction)asm_callx_func(as, irf, func); + if (!(void *)ci.func) { + /* Use a (hoistable) non-scratch register for indirect calls. */ + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + Reg r = ra_alloc1(as, func, allow); + if (LJ_32) emit_spsub(as, spadj); /* Above code may cause restores! */ + emit_rr(as, XO_GROUP5, XOg_CALL, r); + } else if (LJ_32) { + emit_spsub(as, spadj); + } + asm_gencall(as, &ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc)); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guardcc(as, CC_P); + asm_guardcc(as, CC_NE); + emit_rr(as, XO_UCOMISD, left, tmp); + emit_rr(as, XO_CVTSI2SD, tmp, dest); + if (!(as->flags & JIT_F_SPLIT_XMM)) + emit_rr(as, XO_XORPS, tmp, tmp); /* Avoid partial register stall. */ + emit_rr(as, XO_CVTTSD2SI, dest, left); + /* Can't fuse since left is needed twice. */ +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg tmp = ra_noreg(IR(ir->op1)->r) ? + ra_alloc1(as, ir->op1, RSET_FPR) : + ra_scratch(as, RSET_FPR); + Reg right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp)); + emit_rr(as, XO_MOVDto, tmp, dest); + emit_mrm(as, XO_ADDSD, tmp, right); + ra_left(as, tmp, ir->op1); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64)); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(LJ_32 && (irt_isint64(ir->t) || st64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + Reg left = asm_fuseload(as, lref, RSET_FPR); + emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left); + if (left == dest) return; /* Avoid the XO_XORPS. */ + } else if (LJ_32 && st == IRT_U32) { /* U32 to FP conversion on x86. */ + /* number = (2^52+2^51 .. u32) - (2^52+2^51) */ + cTValue *k = lj_ir_k64_find(as->J, U64x(43380000,00000000)); + Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + if (irt_isfloat(ir->t)) + emit_rr(as, XO_CVTSD2SS, dest, dest); + emit_rr(as, XO_SUBSD, dest, bias); /* Subtract 2^52+2^51 bias. */ + emit_rr(as, XO_XORPS, dest, bias); /* Merge bias and integer. */ + emit_loadn(as, bias, k); + emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR)); + return; + } else { /* Integer to FP conversion. */ + Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ? + ra_alloc1(as, lref, RSET_GPR) : + asm_fuseloadm(as, lref, RSET_GPR, st64); + if (LJ_64 && st == IRT_U64) { + MCLabel l_end = emit_label(as); + const void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000)); + emit_rma(as, XO_ADDSD, dest, k); /* Add 2^64 to compensate. */ + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, left|REX_64, left); /* Check if u64 >= 2^63. */ + } + emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS, + dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left); + } + if (!(as->flags & JIT_F_SPLIT_XMM)) + emit_rr(as, XO_XORPS, dest, dest); /* Avoid partial register stall. */ + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + x86Op op = st == IRT_NUM ? + ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) : + ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI); + if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) { + /* LJ_64: For inputs >= 2^63 add -2^64, convert again. */ + /* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */ + Reg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) : + ra_scratch(as, RSET_FPR); + MCLabel l_end = emit_label(as); + if (LJ_32) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000); + emit_rr(as, op, dest|REX_64, tmp); + if (st == IRT_NUM) + emit_rma(as, XO_ADDSD, tmp, lj_ir_k64_find(as->J, + LJ_64 ? U64x(c3f00000,00000000) : U64x(c1e00000,00000000))); + else + emit_rma(as, XO_ADDSS, tmp, lj_ir_k64_find(as->J, + LJ_64 ? U64x(00000000,df800000) : U64x(00000000,cf000000))); + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, dest|REX_64, dest); /* Check if dest negative. */ + emit_rr(as, op, dest|REX_64, tmp); + ra_left(as, tmp, lref); + } else { + Reg left = asm_fuseload(as, lref, RSET_FPR); + if (LJ_64 && irt_isu32(ir->t)) + emit_rr(as, XO_MOV, dest, dest); /* Zero hiword. */ + emit_mrm(as, op, + dest|((LJ_64 && + (irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0), + left); + } + } + } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left, dest = ra_dest(as, ir, RSET_GPR); + RegSet allow = RSET_GPR; + x86Op op; + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if (st == IRT_I8) { + op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX; + } else if (st == IRT_U8) { + op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX; + } else if (st == IRT_I16) { + op = XO_MOVSXw; + } else { + op = XO_MOVZXw; + } + left = asm_fuseload(as, lref, allow); + /* Add extra MOV if source is already in wrong register. */ + if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) { + Reg tmp = ra_scratch(as, allow); + emit_rr(as, op, dest, tmp); + emit_rr(as, XO_MOV, tmp, left); + } else { + emit_mrm(as, op, dest, left); + } + } else { /* 32/64 bit integer conversions. */ + if (LJ_32) { /* Only need to handle 32/32 bit no-op (cast) on x86. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else if (irt_is64(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st64 || !(ir->op2 & IRCONV_SEXT)) { + /* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */ + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else { /* 32 to 64 bit sign extension. */ + Reg left = asm_fuseload(as, lref, RSET_GPR); + emit_mrm(as, XO_MOVSXd, dest|REX_64, left); + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st64) { + Reg left = asm_fuseload(as, lref, RSET_GPR); + /* This is either a 32 bit reg/reg mov which zeroes the hiword + ** or a load of the loword from a 64 bit address. + */ + emit_mrm(as, XO_MOV, dest, left); + } else { /* 32/32 bit no-op (cast). */ + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } + } +} + +#if LJ_32 && LJ_HASFFI +/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */ + +/* 64 bit integer to FP conversion in 32 bit mode. */ +static void asm_conv_fp_int64(ASMState *as, IRIns *ir) +{ + Reg hi = ra_alloc1(as, ir->op1, RSET_GPR); + Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi)); + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, + dest, RID_ESP, ofs); + } + emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd, + irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs); + if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) { + /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */ + MCLabel l_end = emit_label(as); + emit_rma(as, XO_FADDq, XOg_FADDq, + lj_ir_k64_find(as->J, U64x(43f00000,00000000))); + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, hi, hi); /* Check if u64 >= 2^63. */ + } else { + lua_assert(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64); + } + emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0); + /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */ + emit_rmro(as, XO_MOVto, hi, RID_ESP, 4); + emit_rmro(as, XO_MOVto, lo, RID_ESP, 0); +} + +/* FP to 64 bit integer conversion in 32 bit mode. */ +static void asm_conv_int64_fp(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + Reg lo, hi; + lua_assert(st == IRT_NUM || st == IRT_FLOAT); + lua_assert(dt == IRT_I64 || dt == IRT_U64); + lua_assert(((ir-1)->op2 & IRCONV_TRUNC)); + hi = ra_dest(as, ir, RSET_GPR); + lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi)); + if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0); + /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */ + if (!(as->flags & JIT_F_SSE3)) { /* Set FPU rounding mode to default. */ + emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4); + emit_rmro(as, XO_MOVto, lo, RID_ESP, 4); + emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff); + } + if (dt == IRT_U64) { + /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */ + MCLabel l_pop, l_end = emit_label(as); + emit_x87op(as, XI_FPOP); + l_pop = emit_label(as); + emit_sjmp(as, l_end); + emit_rmro(as, XO_MOV, hi, RID_ESP, 4); + if ((as->flags & JIT_F_SSE3)) + emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0); + else + emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0); + emit_rma(as, XO_FADDq, XOg_FADDq, + lj_ir_k64_find(as->J, U64x(c3f00000,00000000))); + emit_sjcc(as, CC_NS, l_pop); + emit_rr(as, XO_TEST, hi, hi); /* Check if out-of-range (2^63). */ + } + emit_rmro(as, XO_MOV, hi, RID_ESP, 4); + if ((as->flags & JIT_F_SSE3)) { /* Truncation is easy with SSE3. */ + emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0); + } else { /* Otherwise set FPU rounding mode to truncate before the store. */ + emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0); + emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0); + emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0); + emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0); + emit_loadi(as, lo, 0xc00); + emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0); + } + if (dt == IRT_U64) + emit_x87op(as, XI_FDUP); + emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd, + st == IRT_NUM ? XOg_FLDq: XOg_FLDd, + asm_fuseload(as, ir->op1, RSET_EMPTY)); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + /* Force a spill slot for the destination register (if any). */ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + RegSet drop = RSET_SCRATCH; + if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r)) + rset_set(drop, ir->r); /* WIN64 doesn't spill all FPRs. */ + ra_evictset(as, drop); + asm_guardcc(as, CC_E); + emit_rr(as, XO_TEST, RID_RET, RID_RET); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64, + RID_ESP, sps_scale(ir->s)); +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(irl->t)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64, + RID_ESP, ra_spill(as, irl)); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusearef(as, ir, RSET_GPR); + if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0)) + emit_mrm(as, XO_LEA, dest, RID_MRM); + else if (as->mrm.base != dest) + emit_rr(as, XO_MOV, dest, as->mrm.base); +} + +/* Merge NE(HREF, niltv) check. */ +static MCode *merge_href_niltv(ASMState *as, IRIns *ir) +{ + /* Assumes nothing else generates NE of HREF. */ + if ((ir[1].o == IR_NE || ir[1].o == IR_EQ) && ir[1].op1 == as->curins && + ra_hasreg(ir->r)) { + MCode *p = as->mcp; + p += (LJ_64 && *p != XI_ARITHi) ? 7+6 : 6+6; + /* Ensure no loop branch inversion happened. */ + if (p[-6] == 0x0f && p[-5] == XI_JCCn+(CC_NE^(ir[1].o & 1))) { + as->mcp = p; /* Kill cmp reg, imm32 + jz exit. */ + return p + *(int32_t *)(p-4); /* Return exit address. */ + } + } + return NULL; +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir) +{ + MCode *nilexit = merge_href_niltv(as, ir); /* Do this before any restores. */ + RegSet allow = RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, tmp = RID_NONE; + IRIns *irkey = IR(ir->op2); + int isk = irref_isk(ir->op2); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + if (!isk) { + rset_clear(allow, tab); + key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow); + if (!irt_isstr(kt)) + tmp = ra_scratch(as, rset_exclude(allow, key)); + } + + /* Key not found in chain: jump to exit (if merged with NE) or load niltv. */ + l_end = emit_label(as); + if (nilexit && ir[1].o == IR_NE) { + emit_jcc(as, CC_E, nilexit); /* XI_JMP is not found by lj_asm_patchexit. */ + nilexit = NULL; + } else { + emit_loada(as, dest, niltvg(J2G(as->J))); + } + + /* Follow hash chain until the end. */ + l_loop = emit_sjcc_label(as, CC_NZ); + emit_rr(as, XO_TEST, dest, dest); + emit_rmro(as, XO_MOV, dest, dest, offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (nilexit) + emit_jcc(as, CC_E, nilexit); + else + emit_sjcc(as, CC_E, l_end); + if (irt_isnum(kt)) { + if (isk) { + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo), + (int32_t)ir_knum(irkey)->u32.lo); + emit_sjcc(as, CC_NE, l_next); + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi), + (int32_t)ir_knum(irkey)->u32.hi); + } else { + emit_sjcc(as, CC_P, l_next); + emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n)); + emit_sjcc(as, CC_AE, l_next); + /* The type check avoids NaN penalties and complaints from Valgrind. */ +#if LJ_64 + emit_u32(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it)); +#else + emit_i8(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it)); +#endif + } +#if LJ_64 + } else if (irt_islightud(kt)) { + emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64)); +#endif + } else { + if (!irt_ispri(kt)) { + lua_assert(irt_isaddr(kt)); + if (isk) + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr), + ptr2addr(ir_kgc(irkey))); + else + emit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr)); + emit_sjcc(as, CC_NE, l_next); + } + lua_assert(!irt_isnil(kt)); + emit_i8(as, irt_toitype(kt)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it)); + } + emit_sfixup(as, l_loop); + checkmclim(as); + + /* Load main position relative to tab->node into dest. */ + khash = isk ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, node)); + } else { + emit_rmro(as, XO_ARITH(XOg_ADD), dest, tab, offsetof(GCtab, node)); + if ((as->flags & JIT_F_PREFER_IMUL)) { + emit_i8(as, sizeof(Node)); + emit_rr(as, XO_IMULi8, dest, dest); + } else { + emit_shifti(as, XOg_SHL, dest, 3); + emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0); + } + if (isk) { + emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash); + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask)); + } else if (irt_isstr(kt)) { + emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, hash)); + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask)); + } else { /* Must match with hashrot() in lj_tab.c. */ + emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask)); + emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp); + emit_shifti(as, XOg_ROL, tmp, HASH_ROT3); + emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp); + emit_shifti(as, XOg_ROL, dest, HASH_ROT2); + emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest); + emit_shifti(as, XOg_ROL, dest, HASH_ROT1); + emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest); + if (irt_isnum(kt)) { + emit_rr(as, XO_ARITH(XOg_ADD), dest, dest); +#if LJ_64 + emit_shifti(as, XOg_SHR|REX_64, dest, 32); + emit_rr(as, XO_MOV, tmp, dest); + emit_rr(as, XO_MOVDto, key|REX_64, dest); +#else + emit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4); + emit_rr(as, XO_MOVDto, key, tmp); +#endif + } else { + emit_rr(as, XO_MOV, tmp, key); + emit_rmro(as, XO_LEA, dest, key, HASH_BIAS); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); +#if !LJ_64 + MCLabel l_exit; +#endif + lua_assert(ofs % sizeof(Node) == 0); + if (ra_hasreg(dest)) { + if (ofs != 0) { + if (dest == node && !(as->flags & JIT_F_LEA_AGU)) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, ofs); + else + emit_rmro(as, XO_LEA, dest, node, ofs); + } else if (dest != node) { + emit_rr(as, XO_MOV, dest, node); + } + } + asm_guardcc(as, CC_NE); +#if LJ_64 + if (!irt_ispri(irkey->t)) { + Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node)); + emit_rmro(as, XO_CMP, key|REX_64, node, + ofs + (int32_t)offsetof(Node, key.u64)); + lua_assert(irt_isnum(irkey->t) || irt_isgcv(irkey->t)); + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 : + ((uint64_t)irt_toitype(irkey->t) << 32) | + (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey))); + } else { + lua_assert(!irt_isnil(irkey->t)); + emit_i8(as, irt_toitype(irkey->t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, node, + ofs + (int32_t)offsetof(Node, key.it)); + } +#else + l_exit = emit_label(as); + if (irt_isnum(irkey->t)) { + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.u32.lo), + (int32_t)ir_knum(irkey)->u32.lo); + emit_sjcc(as, CC_NE, l_exit); + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.u32.hi), + (int32_t)ir_knum(irkey)->u32.hi); + } else { + if (!irt_ispri(irkey->t)) { + lua_assert(irt_isgcv(irkey->t)); + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.gcr), + ptr2addr(ir_kgc(irkey))); + emit_sjcc(as, CC_NE, l_exit); + } + lua_assert(!irt_isnil(irkey->t)); + emit_i8(as, irt_toitype(irkey->t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, node, + ofs + (int32_t)offsetof(Node, key.it)); + } +#endif +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + IRIns *irkey; + Reg tmp; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + irkey = IR(ir->op2); + if (irt_isnum(irkey->t)) { + /* For numbers use the constant itself or a spill slot as a TValue. */ + if (irref_isk(ir->op2)) + emit_loada(as, tmp, ir_knum(irkey)); + else + emit_rmro(as, XO_LEA, tmp|REX_64, RID_ESP, ra_spill(as, irkey)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + if (!irref_isk(ir->op2)) { + Reg src = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, tmp)); + emit_movtomro(as, REX_64IR(irkey, src), tmp, 0); + } else if (!irt_ispri(irkey->t)) { + emit_movmroi(as, tmp, 0, irkey->i); + } + if (!(LJ_64 && irt_islightud(irkey->t))) + emit_movmroi(as, tmp, 4, irt_toitype(irkey->t)); + emit_loada(as, tmp, &J2G(as->J)->tmptv); + } +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_rma(as, XO_MOV, dest, v); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + emit_rmro(as, XO_LEA, dest, uv, offsetof(GCupval, tv)); + asm_guardcc(as, CC_NE); + emit_i8(as, 1); + emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed)); + } else { + emit_rmro(as, XO_MOV, dest, uv, offsetof(GCupval, v)); + } + emit_rmro(as, XO_MOV, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusefref(as, ir, RSET_GPR); + emit_mrm(as, XO_LEA, dest, RID_MRM); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusestrref(as, ir, RSET_GPR); + if (as->mrm.base == RID_NONE) + emit_loadi(as, dest, as->mrm.ofs); + else if (as->mrm.base == dest && as->mrm.idx == RID_NONE) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, as->mrm.ofs); + else + emit_mrm(as, XO_LEA, dest, RID_MRM); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static void asm_fxload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + x86Op xo; + if (ir->o == IR_FLOAD) + asm_fusefref(as, ir, RSET_GPR); + else + asm_fusexref(as, ir->op1, RSET_GPR); + /* ir->op2 is ignored -- unaligned loads are ok on x86. */ + switch (irt_type(ir->t)) { + case IRT_I8: xo = XO_MOVSXb; break; + case IRT_U8: xo = XO_MOVZXb; break; + case IRT_I16: xo = XO_MOVSXw; break; + case IRT_U16: xo = XO_MOVZXw; break; + case IRT_NUM: xo = XMM_MOVRM(as); break; + case IRT_FLOAT: xo = XO_MOVSS; break; + default: + if (LJ_64 && irt_is64(ir->t)) + dest |= REX_64; + else + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + xo = XO_MOV; + break; + } + emit_mrm(as, xo, dest, RID_MRM); +} + +static void asm_fxstore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg src = RID_NONE, osrc = RID_NONE; + int32_t k = 0; + if (ir->r == RID_SINK) + return; + /* The IRT_I16/IRT_U16 stores should never be simplified for constant + ** values since mov word [mem], imm16 has a length-changing prefix. + */ + if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) || + !asm_isk32(as, ir->op2, &k)) { + RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR : + (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR; + src = osrc = ra_alloc1(as, ir->op2, allow8); + if (!LJ_64 && !rset_test(allow8, src)) { /* Already in wrong register. */ + rset_clear(allow, osrc); + src = ra_scratch(as, allow8); + } + rset_clear(allow, src); + } + if (ir->o == IR_FSTORE) { + asm_fusefref(as, IR(ir->op1), allow); + } else { + asm_fusexref(as, ir->op1, allow); + if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4; + } + if (ra_hasreg(src)) { + x86Op xo; + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break; + case IRT_I16: case IRT_U16: xo = XO_MOVtow; break; + case IRT_NUM: xo = XO_MOVSDto; break; + case IRT_FLOAT: xo = XO_MOVSSto; break; +#if LJ_64 + case IRT_LIGHTUD: lua_assert(0); /* NYI: mask 64 bit lightuserdata. */ +#endif + default: + if (LJ_64 && irt_is64(ir->t)) + src |= REX_64; + else + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + xo = XO_MOVto; + break; + } + emit_mrm(as, xo, src, RID_MRM); + if (!LJ_64 && src != osrc) { + ra_noweak(as, osrc); + emit_rr(as, XO_MOV, src, osrc); + } + } else { + if (irt_isi8(ir->t) || irt_isu8(ir->t)) { + emit_i8(as, k); + emit_mrm(as, XO_MOVmib, 0, RID_MRM); + } else { + lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) || + irt_isaddr(ir->t)); + emit_i32(as, k); + emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM); + } + } +} + +#if LJ_64 +static Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck) +{ + if (ra_used(ir) || typecheck) { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (typecheck) { + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest)); + asm_guardcc(as, CC_NE); + emit_i8(as, -2); + emit_rr(as, XO_ARITHi8, XOg_CMP, tmp); + emit_shifti(as, XOg_SAR|REX_64, tmp, 47); + emit_rr(as, XO_MOV, tmp|REX_64, dest); + } + return dest; + } else { + return RID_NONE; + } +} +#endif + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + lua_assert(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) || + (LJ_DUALNUM && irt_isint(ir->t))); +#if LJ_64 + if (irt_islightud(ir->t)) { + Reg dest = asm_load_lightud64(as, ir, 1); + if (ra_hasreg(dest)) { + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM); + } + return; + } else +#endif + if (ra_used(ir)) { + RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XMM_MOVRM(as), dest, RID_MRM); + } else { + asm_fuseahuref(as, ir->op1, RSET_GPR); + } + /* Always do the type check, even if the load result is unused. */ + as->mrm.ofs += 4; + asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE); + if (LJ_64 && irt_type(ir->t) >= IRT_NUM) { + lua_assert(irt_isinteger(ir->t) || irt_isnum(ir->t)); + emit_u32(as, LJ_TISNUM); + emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM); + } else { + emit_i8(as, irt_toitype(ir->t)); + emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM); + } +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ir->op2, RSET_FPR); + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, XO_MOVSDto, src, RID_MRM); +#if LJ_64 + } else if (irt_islightud(ir->t)) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src)); + emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM); +#endif + } else { + IRIns *irr = IR(ir->op2); + RegSet allow = RSET_GPR; + Reg src = RID_NONE; + if (!irref_isk(ir->op2)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + asm_fuseahuref(as, ir->op1, allow); + if (ra_hasreg(src)) { + emit_mrm(as, XO_MOVto, src, RID_MRM); + } else if (!irt_ispri(irr->t)) { + lua_assert(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t))); + emit_i32(as, irr->i); + emit_mrm(as, XO_MOVmi, 0, RID_MRM); + } + as->mrm.ofs += 4; + emit_i32(as, (int32_t)irt_toitype(ir->t)); + emit_mrm(as, XO_MOVmi, 0, RID_MRM); + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + IRType1 t = ir->t; + Reg base; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(LJ_DUALNUM || + !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + Reg left = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, left); /* Frees dest reg. Do this before base alloc. */ + base = ra_alloc1(as, REF_BASE, RSET_GPR); + emit_rmro(as, XMM_MOVRM(as), left, base, ofs); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ +#if LJ_64 + } else if (irt_islightud(t)) { + Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK)); + if (ra_hasreg(dest)) { + base = ra_alloc1(as, REF_BASE, RSET_GPR); + emit_rmro(as, XO_MOV, dest|REX_64, base, ofs); + } + return; +#endif + } else if (ra_used(ir)) { + RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + base = ra_alloc1(as, REF_BASE, RSET_GPR); + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + if ((ir->op2 & IRSLOAD_CONVERT)) { + t.irt = irt_isint(t) ? IRT_NUM : IRT_INT; /* Check for original type. */ + emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTSD2SI, dest, base, ofs); + } else if (irt_isnum(t)) { + emit_rmro(as, XMM_MOVRM(as), dest, base, ofs); + } else { + emit_rmro(as, XO_MOV, dest, base, ofs); + } + } else { + if (!(ir->op2 & IRSLOAD_TYPECHECK)) + return; /* No type check: avoid base alloc. */ + base = ra_alloc1(as, REF_BASE, RSET_GPR); + } + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + /* Need type check, even if the load result is unused. */ + asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE); + if (LJ_64 && irt_type(t) >= IRT_NUM) { + lua_assert(irt_isinteger(t) || irt_isnum(t)); + emit_u32(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4); + } else { + emit_i8(as, irt_toitype(t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4); + } + } +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); +#if LJ_64 + Reg r64 = sz == 8 ? REX_64 : 0; + if (irref_isk(ir->op2)) { + IRIns *irk = IR(ir->op2); + uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 : + (uint64_t)(uint32_t)irk->i; + if (sz == 4 || checki32((int64_t)k)) { + emit_i32(as, (int32_t)k); + emit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata)); + } else { + emit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata)); + emit_loadu64(as, RID_ECX, k); + } + } else { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata)); + } +#else + int32_t ofs = sizeof(GCcdata); + if (sz == 8) { + ofs += 4; ir++; + lua_assert(ir->o == IR_HIOP); + } + do { + if (irref_isk(ir->op2)) { + emit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i); + } else { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_movtomro(as, r, RID_RET, ofs); + rset_clear(allow, r); + } + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir--; + } while (1); +#endif + lua_assert(sz == 4 || sz == 8); + } + + /* Combine initialization of marked, gct and ctypeid. */ + emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked)); + emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX, + (int32_t)((~LJ_TCDATA<<8)+(ctypeid<<16))); + emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES); + emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite); + + asm_gencall(as, ci, args); + emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata))); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + MCLabel l_end = emit_label(as); + emit_movtomro(as, tmp, tab, offsetof(GCtab, gclist)); + emit_setgl(as, tab, gc.grayagain); + emit_getgl(as, tmp, gc.grayagain); + emit_i8(as, ~LJ_GC_BLACK); + emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked)); + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_BLACK); + emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J)); + obj = IR(ir->op1)->r; + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_WHITES); + if (irref_isk(ir->op2)) { + GCobj *vp = ir_kgc(IR(ir->op2)); + emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked); + } else { + Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj)); + emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked)); + } + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_BLACK); + emit_rmro(as, XO_GROUP3b, XOg_TEST, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); +} + +/* -- FP/int arithmetic and logic operations ------------------------------ */ + +/* Load reference onto x87 stack. Force a spill to memory if needed. */ +static void asm_x87load(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_KNUM) { + cTValue *tv = ir_knum(ir); + if (tvispzero(tv)) /* Use fldz only for +0. */ + emit_x87op(as, XI_FLDZ); + else if (tvispone(tv)) + emit_x87op(as, XI_FLD1); + else + emit_rma(as, XO_FLDq, XOg_FLDq, tv); + } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) && + !irref_isk(ir->op1) && mayfuse(as, ir->op1)) { + IRIns *iri = IR(ir->op1); + emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri)); + } else { + emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY)); + } +} + +/* Try to rejoin pow from EXP2, MUL and LOG2 (if still unsplit). */ +static int fpmjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX); + IRIns *irx; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, lj_vm_pow_sse); + irx = IR(irpp->op1); + if (ra_noreg(irx->r) && ra_gethint(irx->r) == RID_XMM1) + irx->r = RID_INIT; /* Avoid allocating xmm1 for x. */ + ra_left(as, RID_XMM0, irpp->op1); + ra_left(as, RID_XMM1, irp->op2); + return 1; + } + } + return 0; +} + +static void asm_fpmath(ASMState *as, IRIns *ir) +{ + IRFPMathOp fpm = ir->o == IR_FPMATH ? (IRFPMathOp)ir->op2 : IRFPM_OTHER; + if (fpm == IRFPM_SQRT) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = asm_fuseload(as, ir->op1, RSET_FPR); + emit_mrm(as, XO_SQRTSD, dest, left); + } else if (fpm <= IRFPM_TRUNC) { + if (as->flags & JIT_F_SSE4_1) { /* SSE4.1 has a rounding instruction. */ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = asm_fuseload(as, ir->op1, RSET_FPR); + /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op. + ** Let's pretend it's a 3-byte opcode, and compensate afterwards. + ** This is atrocious, but the alternatives are much worse. + */ + /* Round down/up/trunc == 1001/1010/1011. */ + emit_i8(as, 0x09 + fpm); + emit_mrm(as, XO_ROUNDSD, dest, left); + if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) { + as->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f; /* Swap 0F and REX. */ + } + *--as->mcp = 0x66; /* 1st byte of ROUNDSD opcode. */ + } else { /* Call helper functions for SSE2 variant. */ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse : + fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse); + ra_left(as, RID_XMM0, ir->op1); + } + } else if (fpm == IRFPM_EXP2 && fpmjoin_pow(as, ir)) { + /* Rejoined to pow(). */ + } else { /* Handle x87 ops. */ + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, XMM_MOVRM(as), dest, RID_ESP, ofs); + } + emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs); + switch (fpm) { /* st0 = lj_vm_*(st0) */ + case IRFPM_EXP: emit_call(as, lj_vm_exp_x87); break; + case IRFPM_EXP2: emit_call(as, lj_vm_exp2_x87); break; + case IRFPM_SIN: emit_x87op(as, XI_FSIN); break; + case IRFPM_COS: emit_x87op(as, XI_FCOS); break; + case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break; + case IRFPM_LOG: case IRFPM_LOG2: case IRFPM_LOG10: + /* Note: the use of fyl2xp1 would be pointless here. When computing + ** log(1.0+eps) the precision is already lost after 1.0 is added. + ** Subtracting 1.0 won't recover it. OTOH math.log1p would make sense. + */ + emit_x87op(as, XI_FYL2X); break; + case IRFPM_OTHER: + switch (ir->o) { + case IR_ATAN2: + emit_x87op(as, XI_FPATAN); asm_x87load(as, ir->op2); break; + case IR_LDEXP: + emit_x87op(as, XI_FPOP1); emit_x87op(as, XI_FSCALE); break; + default: lua_assert(0); break; + } + break; + default: lua_assert(0); break; + } + asm_x87load(as, ir->op1); + switch (fpm) { + case IRFPM_LOG: emit_x87op(as, XI_FLDLN2); break; + case IRFPM_LOG2: emit_x87op(as, XI_FLD1); break; + case IRFPM_LOG10: emit_x87op(as, XI_FLDLG2); break; + case IRFPM_OTHER: + if (ir->o == IR_LDEXP) asm_x87load(as, ir->op2); + break; + default: break; + } + } +} + +static void asm_fppowi(ASMState *as, IRIns *ir) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, lj_vm_powi_sse); + ra_left(as, RID_XMM0, ir->op1); + ra_left(as, RID_EAX, ir->op2); +} + +#if LJ_64 && LJ_HASFFI +static void asm_arith64(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_intmod(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_vm_modi]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static int asm_swapops(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + lua_assert(ra_noreg(irr->r)); + if (!irm_iscomm(lj_ir_mode[ir->o])) + return 0; /* Can't swap non-commutative operations. */ + if (irref_isk(ir->op2)) + return 0; /* Don't swap constants to the left. */ + if (ra_hasreg(irl->r)) + return 1; /* Swap if left already has a register. */ + if (ra_samehint(ir->r, irr->r)) + return 1; /* Swap if dest and right have matching hints. */ + if (as->curins > as->loopref) { /* In variant part? */ + if (ir->op2 < as->loopref && !irt_isphi(irr->t)) + return 0; /* Keep invariants on the right. */ + if (ir->op1 < as->loopref && !irt_isphi(irl->t)) + return 1; /* Swap invariants to the right. */ + } + if (opisfusableload(irl->o)) + return 1; /* Swap fusable loads to the right. */ + return 0; /* Otherwise don't swap. */ +} + +static void asm_fparith(ASMState *as, IRIns *ir, x86Op xo) +{ + IRRef lref = ir->op1; + IRRef rref = ir->op2; + RegSet allow = RSET_FPR; + Reg dest; + Reg right = IR(rref)->r; + if (ra_hasreg(right)) { + rset_clear(allow, right); + ra_noweak(as, right); + } + dest = ra_dest(as, ir, allow); + if (lref == rref) { + right = dest; + } else if (ra_noreg(right)) { + if (asm_swapops(as, ir)) { + IRRef tmp = lref; lref = rref; rref = tmp; + } + right = asm_fuseload(as, rref, rset_clear(allow, dest)); + } + emit_mrm(as, xo, dest, right); + ra_left(as, dest, lref); +} + +static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa) +{ + IRRef lref = ir->op1; + IRRef rref = ir->op2; + RegSet allow = RSET_GPR; + Reg dest, right; + int32_t k = 0; + if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */ + as->flagmcp = NULL; + as->mcp += (LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2; + } + right = IR(rref)->r; + if (ra_hasreg(right)) { + rset_clear(allow, right); + ra_noweak(as, right); + } + dest = ra_dest(as, ir, allow); + if (lref == rref) { + right = dest; + } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) { + if (asm_swapops(as, ir)) { + IRRef tmp = lref; lref = rref; rref = tmp; + } + right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t)); + } + if (irt_isguard(ir->t)) /* For IR_ADDOV etc. */ + asm_guardcc(as, CC_O); + if (xa != XOg_X_IMUL) { + if (ra_hasreg(right)) + emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right); + else + emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k); + } else if (ra_hasreg(right)) { /* IMUL r, mrm. */ + emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right); + } else { /* IMUL r, r, k. */ + /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */ + Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t)); + x86Op xo; + if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8; + } else { emit_i32(as, k); xo = XO_IMULi; } + emit_mrm(as, xo, REX_64IR(ir, dest), left); + return; + } + ra_left(as, dest, lref); +} + +/* LEA is really a 4-operand ADD with an independent destination register, +** up to two source registers and an immediate. One register can be scaled +** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several +** instructions. +** +** Currently only a few common cases are supported: +** - 3-operand ADD: y = a+b; y = a+k with a and b already allocated +** - Left ADD fusion: y = (a+b)+k; y = (a+k)+b +** - Right ADD fusion: y = a+(b+k) +** The ommited variants have already been reduced by FOLD. +** +** There are more fusion opportunities, like gathering shifts or joining +** common references. But these are probably not worth the trouble, since +** array indexing is not decomposed and already makes use of all fields +** of the ModRM operand. +*/ +static int asm_lea(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + RegSet allow = RSET_GPR; + Reg dest; + as->mrm.base = as->mrm.idx = RID_NONE; + as->mrm.scale = XM_SCALE1; + as->mrm.ofs = 0; + if (ra_hasreg(irl->r)) { + rset_clear(allow, irl->r); + ra_noweak(as, irl->r); + as->mrm.base = irl->r; + if (irref_isk(ir->op2) || ra_hasreg(irr->r)) { + /* The PHI renaming logic does a better job in some cases. */ + if (ra_hasreg(ir->r) && + ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) || + (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2))) + return 0; + if (irref_isk(ir->op2)) { + as->mrm.ofs = irr->i; + } else { + rset_clear(allow, irr->r); + ra_noweak(as, irr->r); + as->mrm.idx = irr->r; + } + } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) && + irref_isk(irr->op2)) { + Reg idx = ra_alloc1(as, irr->op1, allow); + rset_clear(allow, idx); + as->mrm.idx = (uint8_t)idx; + as->mrm.ofs = IR(irr->op2)->i; + } else { + return 0; + } + } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) && + (irref_isk(ir->op2) || irref_isk(irl->op2))) { + Reg idx, base = ra_alloc1(as, irl->op1, allow); + rset_clear(allow, base); + as->mrm.base = (uint8_t)base; + if (irref_isk(ir->op2)) { + as->mrm.ofs = irr->i; + idx = ra_alloc1(as, irl->op2, allow); + } else { + as->mrm.ofs = IR(irl->op2)->i; + idx = ra_alloc1(as, ir->op2, allow); + } + rset_clear(allow, idx); + as->mrm.idx = (uint8_t)idx; + } else { + return 0; + } + dest = ra_dest(as, ir, allow); + emit_mrm(as, XO_LEA, dest, RID_MRM); + return 1; /* Success. */ +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_ADDSD); + else if ((as->flags & JIT_F_LEA_AGU) || as->flagmcp == as->mcp || + irt_is64(ir->t) || !asm_lea(as, ir)) + asm_intarith(as, ir, XOg_ADD); +} + +static void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest); + ra_left(as, dest, ir->op1); +} + +static void asm_min_max(ASMState *as, IRIns *ir, int cc) +{ + Reg right, dest = ra_dest(as, ir, RSET_GPR); + IRRef lref = ir->op1, rref = ir->op2; + if (irref_isk(rref)) { lref = rref; rref = ir->op1; } + right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest)); + emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right); + emit_rr(as, XO_CMP, REX_64IR(ir, dest), right); + ra_left(as, dest, lref); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24), + REX_64IR(ir, 0), dest, 0, as->mcp, 1); + ra_left(as, dest, ir->op1); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs) +{ + IRRef rref = ir->op2; + IRIns *irr = IR(rref); + Reg dest; + if (irref_isk(rref)) { /* Constant shifts. */ + int shift; + dest = ra_dest(as, ir, RSET_GPR); + shift = irr->i & (irt_is64(ir->t) ? 63 : 31); + switch (shift) { + case 0: break; + case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break; + default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break; + } + } else { /* Variable shifts implicitly use register cl (i.e. ecx). */ + Reg right; + dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX)); + if (dest == RID_ECX) { + dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX)); + emit_rr(as, XO_MOV, RID_ECX, dest); + } + right = irr->r; + if (ra_noreg(right)) + right = ra_allocref(as, rref, RID2RSET(RID_ECX)); + else if (right != RID_ECX) + ra_scratch(as, RID2RSET(RID_ECX)); + emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest); + ra_noweak(as, right); + if (right != RID_ECX) + emit_rr(as, XO_MOV, RID_ECX, right); + } + ra_left(as, dest, ir->op1); + /* + ** Note: avoid using the flags resulting from a shift or rotate! + ** All of them cause a partial flag stall, except for r,1 shifts + ** (but not rotates). And a shift count of 0 leaves the flags unmodified. + */ +} + +/* -- Comparisons --------------------------------------------------------- */ + +/* Virtual flags for unordered FP comparisons. */ +#define VCC_U 0x1000 /* Unordered. */ +#define VCC_P 0x2000 /* Needs extra CC_P branch. */ +#define VCC_S 0x4000 /* Swap avoids CC_P branch. */ +#define VCC_PS (VCC_P|VCC_S) + +/* Map of comparisons to flags. ORDER IR. */ +#define COMPFLAGS(ci, cin, cu, cf) ((ci)+((cu)<<4)+((cin)<<8)+(cf)) +static const uint16_t asm_compmap[IR_ABC+1] = { + /* signed non-eq unsigned flags */ + /* LT */ COMPFLAGS(CC_GE, CC_G, CC_AE, VCC_PS), + /* GE */ COMPFLAGS(CC_L, CC_L, CC_B, 0), + /* LE */ COMPFLAGS(CC_G, CC_G, CC_A, VCC_PS), + /* GT */ COMPFLAGS(CC_LE, CC_L, CC_BE, 0), + /* ULT */ COMPFLAGS(CC_AE, CC_A, CC_AE, VCC_U), + /* UGE */ COMPFLAGS(CC_B, CC_B, CC_B, VCC_U|VCC_PS), + /* ULE */ COMPFLAGS(CC_A, CC_A, CC_A, VCC_U), + /* UGT */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS), + /* EQ */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P), + /* NE */ COMPFLAGS(CC_E, CC_E, CC_E, VCC_U|VCC_P), + /* ABC */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS) /* Same as UGT. */ +}; + +/* FP and integer comparisons. */ +static void asm_comp(ASMState *as, IRIns *ir, uint32_t cc) +{ + if (irt_isnum(ir->t)) { + IRRef lref = ir->op1; + IRRef rref = ir->op2; + Reg left, right; + MCLabel l_around; + /* + ** An extra CC_P branch is required to preserve ordered/unordered + ** semantics for FP comparisons. This can be avoided by swapping + ** the operands and inverting the condition (except for EQ and UNE). + ** So always try to swap if possible. + ** + ** Another option would be to swap operands to achieve better memory + ** operand fusion. But it's unlikely that this outweighs the cost + ** of the extra branches. + */ + if (cc & VCC_S) { /* Swap? */ + IRRef tmp = lref; lref = rref; rref = tmp; + cc ^= (VCC_PS|(5<<4)); /* A <-> B, AE <-> BE, PS <-> none */ + } + left = ra_alloc1(as, lref, RSET_FPR); + right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left)); + l_around = emit_label(as); + asm_guardcc(as, cc >> 4); + if (cc & VCC_P) { /* Extra CC_P branch required? */ + if (!(cc & VCC_U)) { + asm_guardcc(as, CC_P); /* Branch to exit for ordered comparisons. */ + } else if (l_around != as->invmcp) { + emit_sjcc(as, CC_P, l_around); /* Branch around for unordered. */ + } else { + /* Patched to mcloop by asm_loop_fixup. */ + as->loopinv = 2; + if (as->realign) + emit_sjcc(as, CC_P, as->mcp); + else + emit_jcc(as, CC_P, as->mcp); + } + } + emit_mrm(as, XO_UCOMISD, left, right); + } else { + IRRef lref = ir->op1, rref = ir->op2; + IROp leftop = (IROp)(IR(lref)->o); + Reg r64 = REX_64IR(ir, 0); + int32_t imm = 0; + lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || + irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t)); + /* Swap constants (only for ABC) and fusable loads to the right. */ + if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) { + if ((cc & 0xc) == 0xc) cc ^= 0x53; /* L <-> G, LE <-> GE */ + else if ((cc & 0xa) == 0x2) cc ^= 0x55; /* A <-> B, AE <-> BE */ + lref = ir->op2; rref = ir->op1; + } + if (asm_isk32(as, rref, &imm)) { + IRIns *irl = IR(lref); + /* Check wether we can use test ins. Not for unsigned, since CF=0. */ + int usetest = (imm == 0 && (cc & 0xa) != 0x2); + if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) { + /* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */ + Reg right, left = RID_NONE; + RegSet allow = RSET_GPR; + if (!asm_isk32(as, irl->op2, &imm)) { + left = ra_alloc1(as, irl->op2, allow); + rset_clear(allow, left); + } else { /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */ + IRIns *irll = IR(irl->op1); + if (opisfusableload((IROp)irll->o) && + (irt_isi8(irll->t) || irt_isu8(irll->t))) { + IRType1 origt = irll->t; /* Temporarily flip types. */ + irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT; + as->curins--; /* Skip to BAND to avoid failing in noconflict(). */ + right = asm_fuseload(as, irl->op1, RSET_GPR); + as->curins++; + irll->t = origt; + if (right != RID_MRM) goto test_nofuse; + /* Fusion succeeded, emit test byte mrm, imm8. */ + asm_guardcc(as, cc); + emit_i8(as, (imm & 0xff)); + emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM); + return; + } + } + as->curins--; /* Skip to BAND to avoid failing in noconflict(). */ + right = asm_fuseloadm(as, irl->op1, allow, r64); + as->curins++; /* Undo the above. */ + test_nofuse: + asm_guardcc(as, cc); + if (ra_noreg(left)) { + emit_i32(as, imm); + emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right); + } else { + emit_mrm(as, XO_TEST, r64 + left, right); + } + } else { + Reg left; + if (opisfusableload((IROp)irl->o) && + ((irt_isu8(irl->t) && checku8(imm)) || + ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) || + (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) { + /* Only the IRT_INT case is fused by asm_fuseload. + ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads + ** are handled here. + ** Note that cmp word [mem], imm16 should not be generated, + ** since it has a length-changing prefix. Compares of a word + ** against a sign-extended imm8 are ok, however. + */ + IRType1 origt = irl->t; /* Temporarily flip types. */ + irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT; + left = asm_fuseload(as, lref, RSET_GPR); + irl->t = origt; + if (left == RID_MRM) { /* Fusion succeeded? */ + if (irt_isu8(irl->t) || irt_isu16(irl->t)) + cc >>= 4; /* Need unsigned compare. */ + asm_guardcc(as, cc); + emit_i8(as, imm); + emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ? + XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM); + return; + } /* Otherwise handle register case as usual. */ + } else { + left = asm_fuseloadm(as, lref, + irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64); + } + asm_guardcc(as, cc); + if (usetest && left != RID_MRM) { + /* Use test r,r instead of cmp r,0. */ + x86Op xo = XO_TEST; + if (irt_isu8(ir->t)) { + lua_assert(ir->o == IR_EQ || ir->o == IR_NE); + xo = XO_TESTb; + if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) { + if (LJ_64) { + left |= FORCE_REX; + } else { + emit_i32(as, 0xff); + emit_mrm(as, XO_GROUP3, XOg_TEST, left); + return; + } + } + } + emit_rr(as, xo, r64 + left, left); + if (irl+1 == ir) /* Referencing previous ins? */ + as->flagmcp = as->mcp; /* Set flag to drop test r,r if possible. */ + } else { + emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm); + } + } + } else { + Reg left = ra_alloc1(as, lref, RSET_GPR); + Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64); + asm_guardcc(as, cc); + emit_mrm(as, XO_CMP, r64 + left, right); + } + } +} + +#if LJ_32 && LJ_HASFFI +/* 64 bit integer comparisons in 32 bit mode. */ +static void asm_comp_int64(ASMState *as, IRIns *ir) +{ + uint32_t cc = asm_compmap[(ir-1)->o]; + RegSet allow = RSET_GPR; + Reg lefthi = RID_NONE, leftlo = RID_NONE; + Reg righthi = RID_NONE, rightlo = RID_NONE; + MCLabel l_around; + x86ModRM mrm; + + as->curins--; /* Skip loword ins. Avoids failing in noconflict(), too. */ + + /* Allocate/fuse hiword operands. */ + if (irref_isk(ir->op2)) { + lefthi = asm_fuseload(as, ir->op1, allow); + } else { + lefthi = ra_alloc1(as, ir->op1, allow); + rset_clear(allow, lefthi); + righthi = asm_fuseload(as, ir->op2, allow); + if (righthi == RID_MRM) { + if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base); + if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx); + } else { + rset_clear(allow, righthi); + } + } + mrm = as->mrm; /* Save state for hiword instruction. */ + + /* Allocate/fuse loword operands. */ + if (irref_isk((ir-1)->op2)) { + leftlo = asm_fuseload(as, (ir-1)->op1, allow); + } else { + leftlo = ra_alloc1(as, (ir-1)->op1, allow); + rset_clear(allow, leftlo); + rightlo = asm_fuseload(as, (ir-1)->op2, allow); + } + + /* All register allocations must be performed _before_ this point. */ + l_around = emit_label(as); + as->invmcp = as->flagmcp = NULL; /* Cannot use these optimizations. */ + + /* Loword comparison and branch. */ + asm_guardcc(as, cc >> 4); /* Always use unsigned compare for loword. */ + if (ra_noreg(rightlo)) { + int32_t imm = IR((ir-1)->op2)->i; + if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM) + emit_rr(as, XO_TEST, leftlo, leftlo); + else + emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm); + } else { + emit_mrm(as, XO_CMP, leftlo, rightlo); + } + + /* Hiword comparison and branches. */ + if ((cc & 15) != CC_NE) + emit_sjcc(as, CC_NE, l_around); /* Hiword unequal: skip loword compare. */ + if ((cc & 15) != CC_E) + asm_guardcc(as, cc >> 8); /* Hiword compare without equality check. */ + as->mrm = mrm; /* Restore state. */ + if (ra_noreg(righthi)) { + int32_t imm = IR(ir->op2)->i; + if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM) + emit_rr(as, XO_TEST, lefthi, lefthi); + else + emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm); + } else { + emit_mrm(as, XO_CMP, lefthi, righthi); + } +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_32 && LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + if (usehi || uselo) { + if (irt_isfp(ir->t)) + asm_conv_fp_int64(as, ir); + else + asm_conv_int64_fp(as, ir); + } + as->curins--; /* Always skip the CONV. */ + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + asm_comp_int64(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + if ((ir-1)->r != RID_SINK) + asm_fxstore(as, ir); + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: + as->flagmcp = NULL; + as->curins--; + asm_intarith(as, ir, XOg_ADC); + asm_intarith(as, ir-1, XOg_ADD); + break; + case IR_SUB: + as->flagmcp = NULL; + as->curins--; + asm_intarith(as, ir, XOg_SBB); + asm_intarith(as, ir-1, XOg_SUB); + break; + case IR_NEG: { + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_rr(as, XO_GROUP3, XOg_NEG, dest); + emit_i8(as, 0); + emit_rr(as, XO_ARITHi8, XOg_ADC, dest); + ra_left(as, dest, ir->op1); + as->curins--; + asm_neg_not(as, ir-1, XOg_NEG); + break; + } + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by CNEWI itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused on x64 or without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore eax. */ + Reg pbase = irp ? irp->r : RID_BASE; + Reg r = allow ? rset_pickbot(allow) : RID_EAX; + emit_jcc(as, CC_B, exitstub_addr(as->J, exitno)); + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0); + else + ra_modified(as, r); + emit_gri(as, XG_ARITHi(XOg_CMP), r, (int32_t)(8*topslot)); + if (ra_hasreg(pbase) && pbase != r) + emit_rr(as, XO_ARITH(XOg_SUB), r, pbase); + else + emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE, + ptr2addr(&J2G(as->J)->jit_base)); + emit_rmro(as, XO_MOV, r, r, offsetof(lua_State, maxstack)); + emit_getgl(as, r, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs); + } else { + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || + (LJ_DUALNUM && irt_isinteger(ir->t))); + if (!irref_isk(ref)) { + Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE)); + emit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs); + } else if (!irt_ispri(ir->t)) { + emit_movmroi(as, RID_BASE, ofs, ir->i); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s != 0) /* Do not overwrite link to previous frame. */ + emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--)); + } else { + if (!(LJ_64 && irt_islightud(ir->t))) + emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t)); + } + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_rr(as, XO_TEST, RID_RET, RID_RET); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + emit_loada(as, tmp, J2G(as->J)); + emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_sjcc(as, CC_B, l_end); + emit_opgl(as, XO_ARITH(XOg_CMP), tmp, gc.threshold); + emit_getgl(as, tmp, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->realign) { /* Realigned loops use short jumps. */ + as->realign = NULL; /* Stop another retry. */ + lua_assert(((intptr_t)target & 15) == 0); + if (as->loopinv) { /* Inverted loop branch? */ + p -= 5; + p[0] = XI_JMP; + lua_assert(target - p >= -128); + p[-1] = (MCode)(target - p); /* Patch sjcc. */ + if (as->loopinv == 2) + p[-3] = (MCode)(target - p + 2); /* Patch opt. short jp. */ + } else { + lua_assert(target - p >= -128); + p[-1] = (MCode)(int8_t)(target - p); /* Patch short jmp. */ + p[-2] = XI_JMPs; + } + } else { + MCode *newloop; + p[-5] = XI_JMP; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the jcc and patched the jmp. */ + p -= 5; + newloop = target+4; + *(int32_t *)(p-4) = (int32_t)(target - p); /* Patch jcc. */ + if (as->loopinv == 2) { + *(int32_t *)(p-10) = (int32_t)(target - p + 6); /* Patch opt. jp. */ + newloop = target+8; + } + } else { /* Otherwise just patch jmp. */ + *(int32_t *)(p-4) = (int32_t)(target - p); + newloop = target+3; + } + /* Realign small loops and shorten the loop branch. */ + if (newloop >= p - 128) { + as->realign = newloop; /* Force a retry and remember alignment. */ + as->curins = as->stopins; /* Abort asm_trace now. */ + as->T->nins = as->orignins; /* Remove any added renames. */ + } + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_rr(as, XO_MOV, r, RID_BASE); + } +} + +/* Coalesce or reload BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_rr(as, XO_MOV, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */ + MCode *p = as->mctop; + MCode *target, *q; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + p -= ((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0); + } else { + MCode *p1; + /* Patch stack adjustment. */ + if (checki8(spadj)) { + p -= 3; + p1 = p-6; + *p1 = (MCode)spadj; + } else { + p1 = p-9; + *(int32_t *)p1 = spadj; + } + if ((as->flags & JIT_F_LEA_AGU)) { +#if LJ_64 + p1[-4] = 0x48; +#endif + p1[-3] = (MCode)XI_LEA; + p1[-2] = MODRM(checki8(spadj) ? XM_OFS8 : XM_OFS32, RID_ESP, RID_ESP); + p1[-1] = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } else { +#if LJ_64 + p1[-3] = 0x48; +#endif + p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi); + p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP); + } + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_JMP; + /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */ + for (q = as->mctop-1; q >= p; q--) + *q = XI_NOP; + as->mctop = p; +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop; + /* Realign and leave room for backwards loop branch or exit branch. */ + if (as->realign) { + int i = ((int)(intptr_t)as->realign) & 15; + /* Fill unused mcode tail with NOPs to make the prefetcher happy. */ + while (i-- > 0) + *--p = XI_NOP; + as->mctop = p; + p -= (as->loopinv ? 5 : 2); /* Space for short/near jmp. */ + } else { + p -= 5; /* Space for exit branch (near jmp). */ + } + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */ + as->mcp = p - (((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0)); + as->invmcp = NULL; + } +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_EQ: case IR_NE: case IR_ABC: + asm_comp(as, ir, asm_compmap[ir->o]); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_neg_not(as, ir, XOg_NOT); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_intarith(as, ir, XOg_AND); break; + case IR_BOR: asm_intarith(as, ir, XOg_OR); break; + case IR_BXOR: asm_intarith(as, ir, XOg_XOR); break; + + case IR_BSHL: asm_bitshift(as, ir, XOg_SHL); break; + case IR_BSHR: asm_bitshift(as, ir, XOg_SHR); break; + case IR_BSAR: asm_bitshift(as, ir, XOg_SAR); break; + case IR_BROL: asm_bitshift(as, ir, XOg_ROL); break; + case IR_BROR: asm_bitshift(as, ir, XOg_ROR); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_SUBSD); + else /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */ + asm_intarith(as, ir, XOg_SUB); + break; + case IR_MUL: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MULSD); + else + asm_intarith(as, ir, XOg_X_IMUL); + break; + case IR_DIV: +#if LJ_64 && LJ_HASFFI + if (!irt_isnum(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 : + IRCALL_lj_carith_divu64); + else +#endif + asm_fparith(as, ir, XO_DIVSD); + break; + case IR_MOD: +#if LJ_64 && LJ_HASFFI + if (!irt_isint(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 : + IRCALL_lj_carith_modu64); + else +#endif + asm_intmod(as, ir); + break; + + case IR_NEG: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_XORPS); + else + asm_neg_not(as, ir, XOg_NEG); + break; + case IR_ABS: asm_fparith(as, ir, XO_ANDPS); break; + + case IR_MIN: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MINSD); + else + asm_min_max(as, ir, CC_G); + break; + case IR_MAX: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MAXSD); + else + asm_min_max(as, ir, CC_L); + break; + + case IR_FPMATH: case IR_ATAN2: case IR_LDEXP: + asm_fpmath(as, ir); + break; + case IR_POW: +#if LJ_64 && LJ_HASFFI + if (!irt_isnum(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 : + IRCALL_lj_carith_powu64); + else +#endif + asm_fppowi(as, ir); + break; + + /* Overflow-checking arithmetic ops. Note: don't use LEA here! */ + case IR_ADDOV: asm_intarith(as, ir, XOg_ADD); break; + case IR_SUBOV: asm_intarith(as, ir, XOg_SUB); break; + case IR_MULOV: asm_intarith(as, ir, XOg_X_IMUL); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: case IR_XLOAD: asm_fxload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: case IR_XSTORE: asm_fxstore(as, ir); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_CONV: asm_conv(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + int nslots; + asm_collectargs(as, ir, ci, args); + nslots = asm_count_call_slots(as, ci, args); + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; +#if LJ_64 + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +#else + return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET); +#endif +} + +/* Target-specific setup. */ +static void asm_setup_target(ASMState *as) +{ + asm_exitstub_setup(as, as->T->nsnap); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MSize len = T->szmcode; + MCode *px = exitstub_addr(J, exitno) - 6; + MCode *pe = p+len-6; + uint32_t stateaddr = u32ptr(&J2G(J)->vmstate); + if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px) + *(int32_t *)(p+len-4) = jmprel(p+len, target); + /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */ + for (; p < pe; p++) + if (*(uint32_t *)(p+(LJ_64 ? 3 : 2)) == stateaddr && p[0] == XI_MOVmi) { + p += LJ_64 ? 11 : 10; + break; + } + lua_assert(p < pe); + for (; p < pe; p++) { + if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px) { + *(int32_t *)(p+2) = jmprel(p+6, target); + p += 5; + } + } + lj_mcode_sync(T->mcode, T->mcode + T->szmcode); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.c new file mode 100644 index 0000000..d5d3d78 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.c @@ -0,0 +1,14 @@ +/* +** Bytecode instruction modes. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bc_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_bc.h" + +/* Bytecode offsets and bytecode instruction modes. */ +#include "lj_bcdef.h" + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.h new file mode 100644 index 0000000..1a4ade3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bc.h @@ -0,0 +1,261 @@ +/* +** Bytecode instruction format. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_BC_H +#define _LJ_BC_H + +#include "lj_def.h" +#include "lj_arch.h" + +/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit: +** +** +----+----+----+----+ +** | B | C | A | OP | Format ABC +** +----+----+----+----+ +** | D | A | OP | Format AD +** +-------------------- +** MSB LSB +** +** In-memory instructions are always stored in host byte order. +*/ + +/* Operand ranges and related constants. */ +#define BCMAX_A 0xff +#define BCMAX_B 0xff +#define BCMAX_C 0xff +#define BCMAX_D 0xffff +#define BCBIAS_J 0x8000 +#define NO_REG BCMAX_A +#define NO_JMP (~(BCPos)0) + +/* Macros to get instruction fields. */ +#define bc_op(i) ((BCOp)((i)&0xff)) +#define bc_a(i) ((BCReg)(((i)>>8)&0xff)) +#define bc_b(i) ((BCReg)((i)>>24)) +#define bc_c(i) ((BCReg)(((i)>>16)&0xff)) +#define bc_d(i) ((BCReg)((i)>>16)) +#define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J) + +/* Macros to set instruction fields. */ +#define setbc_byte(p, x, ofs) \ + ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x) +#define setbc_op(p, x) setbc_byte(p, (x), 0) +#define setbc_a(p, x) setbc_byte(p, (x), 1) +#define setbc_b(p, x) setbc_byte(p, (x), 3) +#define setbc_c(p, x) setbc_byte(p, (x), 2) +#define setbc_d(p, x) \ + ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x) +#define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J)) + +/* Macros to compose instructions. */ +#define BCINS_ABC(o, a, b, c) \ + (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16)) +#define BCINS_AD(o, a, d) \ + (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16)) +#define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J)) + +/* Bytecode instruction definition. Order matters, see below. +** +** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod) +** +** The opcode name suffixes specify the type for RB/RC or RD: +** V = variable slot +** S = string const +** N = number const +** P = primitive type (~itype) +** B = unsigned byte literal +** M = multiple args/results +*/ +#define BCDEF(_) \ + /* Comparison ops. ORDER OPR. */ \ + _(ISLT, var, ___, var, lt) \ + _(ISGE, var, ___, var, lt) \ + _(ISLE, var, ___, var, le) \ + _(ISGT, var, ___, var, le) \ + \ + _(ISEQV, var, ___, var, eq) \ + _(ISNEV, var, ___, var, eq) \ + _(ISEQS, var, ___, str, eq) \ + _(ISNES, var, ___, str, eq) \ + _(ISEQN, var, ___, num, eq) \ + _(ISNEN, var, ___, num, eq) \ + _(ISEQP, var, ___, pri, eq) \ + _(ISNEP, var, ___, pri, eq) \ + \ + /* Unary test and copy ops. */ \ + _(ISTC, dst, ___, var, ___) \ + _(ISFC, dst, ___, var, ___) \ + _(IST, ___, ___, var, ___) \ + _(ISF, ___, ___, var, ___) \ + \ + /* Unary ops. */ \ + _(MOV, dst, ___, var, ___) \ + _(NOT, dst, ___, var, ___) \ + _(UNM, dst, ___, var, unm) \ + _(LEN, dst, ___, var, len) \ + \ + /* Binary ops. ORDER OPR. VV last, POW must be next. */ \ + _(ADDVN, dst, var, num, add) \ + _(SUBVN, dst, var, num, sub) \ + _(MULVN, dst, var, num, mul) \ + _(DIVVN, dst, var, num, div) \ + _(MODVN, dst, var, num, mod) \ + \ + _(ADDNV, dst, var, num, add) \ + _(SUBNV, dst, var, num, sub) \ + _(MULNV, dst, var, num, mul) \ + _(DIVNV, dst, var, num, div) \ + _(MODNV, dst, var, num, mod) \ + \ + _(ADDVV, dst, var, var, add) \ + _(SUBVV, dst, var, var, sub) \ + _(MULVV, dst, var, var, mul) \ + _(DIVVV, dst, var, var, div) \ + _(MODVV, dst, var, var, mod) \ + \ + _(POW, dst, var, var, pow) \ + _(CAT, dst, rbase, rbase, concat) \ + \ + /* Constant ops. */ \ + _(KSTR, dst, ___, str, ___) \ + _(KCDATA, dst, ___, cdata, ___) \ + _(KSHORT, dst, ___, lits, ___) \ + _(KNUM, dst, ___, num, ___) \ + _(KPRI, dst, ___, pri, ___) \ + _(KNIL, base, ___, base, ___) \ + \ + /* Upvalue and function ops. */ \ + _(UGET, dst, ___, uv, ___) \ + _(USETV, uv, ___, var, ___) \ + _(USETS, uv, ___, str, ___) \ + _(USETN, uv, ___, num, ___) \ + _(USETP, uv, ___, pri, ___) \ + _(UCLO, rbase, ___, jump, ___) \ + _(FNEW, dst, ___, func, gc) \ + \ + /* Table ops. */ \ + _(TNEW, dst, ___, lit, gc) \ + _(TDUP, dst, ___, tab, gc) \ + _(GGET, dst, ___, str, index) \ + _(GSET, var, ___, str, newindex) \ + _(TGETV, dst, var, var, index) \ + _(TGETS, dst, var, str, index) \ + _(TGETB, dst, var, lit, index) \ + _(TSETV, var, var, var, newindex) \ + _(TSETS, var, var, str, newindex) \ + _(TSETB, var, var, lit, newindex) \ + _(TSETM, base, ___, num, newindex) \ + \ + /* Calls and vararg handling. T = tail call. */ \ + _(CALLM, base, lit, lit, call) \ + _(CALL, base, lit, lit, call) \ + _(CALLMT, base, ___, lit, call) \ + _(CALLT, base, ___, lit, call) \ + _(ITERC, base, lit, lit, call) \ + _(ITERN, base, lit, lit, call) \ + _(VARG, base, lit, lit, ___) \ + _(ISNEXT, base, ___, jump, ___) \ + \ + /* Returns. */ \ + _(RETM, base, ___, lit, ___) \ + _(RET, rbase, ___, lit, ___) \ + _(RET0, rbase, ___, lit, ___) \ + _(RET1, rbase, ___, lit, ___) \ + \ + /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \ + _(FORI, base, ___, jump, ___) \ + _(JFORI, base, ___, jump, ___) \ + \ + _(FORL, base, ___, jump, ___) \ + _(IFORL, base, ___, jump, ___) \ + _(JFORL, base, ___, lit, ___) \ + \ + _(ITERL, base, ___, jump, ___) \ + _(IITERL, base, ___, jump, ___) \ + _(JITERL, base, ___, lit, ___) \ + \ + _(LOOP, rbase, ___, jump, ___) \ + _(ILOOP, rbase, ___, jump, ___) \ + _(JLOOP, rbase, ___, lit, ___) \ + \ + _(JMP, rbase, ___, jump, ___) \ + \ + /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \ + _(FUNCF, rbase, ___, ___, ___) \ + _(IFUNCF, rbase, ___, ___, ___) \ + _(JFUNCF, rbase, ___, lit, ___) \ + _(FUNCV, rbase, ___, ___, ___) \ + _(IFUNCV, rbase, ___, ___, ___) \ + _(JFUNCV, rbase, ___, lit, ___) \ + _(FUNCC, rbase, ___, ___, ___) \ + _(FUNCCW, rbase, ___, ___, ___) + +/* Bytecode opcode numbers. */ +typedef enum { +#define BCENUM(name, ma, mb, mc, mt) BC_##name, +BCDEF(BCENUM) +#undef BCENUM + BC__MAX +} BCOp; + +LJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV); +LJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV); +LJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES); +LJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN); +LJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP); +LJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE); +LJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT); +LJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT); +LJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC); +LJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM); +LJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT); +LJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET); +LJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL); +LJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL); +LJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL); +LJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL); +LJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP); +LJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP); +LJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF); +LJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF); +LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV); +LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV); + +/* This solves a circular dependency problem, change as needed. */ +#define FF_next_N 4 + +/* Stack slots used by FORI/FORL, relative to operand A. */ +enum { + FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT +}; + +/* Bytecode operand modes. ORDER BCMode */ +typedef enum { + BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */ + BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata, + BCM_max +} BCMode; +#define BCM___ BCMnone + +#define bcmode_a(op) ((BCMode)(lj_bc_mode[op] & 7)) +#define bcmode_b(op) ((BCMode)((lj_bc_mode[op]>>3) & 15)) +#define bcmode_c(op) ((BCMode)((lj_bc_mode[op]>>7) & 15)) +#define bcmode_d(op) bcmode_c(op) +#define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3)) +#define bcmode_mm(op) ((MMS)(lj_bc_mode[op]>>11)) + +#define BCMODE(name, ma, mb, mc, mm) \ + (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)), +#define BCMODE_FF 0 + +static LJ_AINLINE int bc_isret(BCOp op) +{ + return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1); +} + +LJ_DATA const uint16_t lj_bc_mode[]; +LJ_DATA const uint16_t lj_bc_ofs[]; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdef.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdef.h new file mode 100644 index 0000000..45c6bed --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdef.h @@ -0,0 +1,226 @@ +/* This is a generated file. DO NOT EDIT! */ + +LJ_DATADEF const uint16_t lj_bc_ofs[] = { +0, +65, +130, +195, +260, +387, +517, +577, +637, +701, +765, +816, +866, +916, +966, +1006, +1046, +1077, +1108, +1144, +1212, +1255, +1298, +1341, +1384, +1432, +1475, +1518, +1561, +1604, +1632, +1686, +1740, +1794, +1848, +1887, +1946, +2034, +2067, +2100, +2123, +2146, +2169, +2211, +2251, +2334, +2412, +2444, +2476, +2526, +2596, +2709, +2796, +2812, +2828, +2976, +3102, +3205, +3376, +3615, +3741, +3883, +3928, +3969, +3973, +4119, +4194, +4364, +4552, +4639, +4643, +4772, +4859, +4964, +5041, +5126, +5145, +5200, +5252, +5271, +5314, +5352, +5371, +5388, +5418, +5442, +5461, +5522, +5575, +5575, +5692, +5693, +5769, +7416, +7487, +7961, +8081, +8138, +8253, +7536, +7678, +7768, +7835, +7861, +8308, +8348, +8980, +8403, +8719, +9022, +9122, +9141, +9160, +9218, +9248, +9279, +9307, +9335, +9365, +9403, +9443, +9473, +9511, +9549, +9703, +9838, +9587, +9587, +9188, +9619, +9974, +9926, +9660, +10018, +10065, +10972, +11297, +11254, +11358, +11426, +11497, +11568, +11639, +11016, +11098, +11180, +10119, +10148, +10199, +10313, +10478, +10603, +10709, +10820, +10931 +}; + +LJ_DATADEF const uint16_t lj_bc_mode[] = { +BCDEF(BCMODE) +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF, +BCMODE_FF +}; + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdump.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdump.h new file mode 100644 index 0000000..77a789e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcdump.h @@ -0,0 +1,66 @@ +/* +** Bytecode dump definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_BCDUMP_H +#define _LJ_BCDUMP_H + +#include "lj_obj.h" +#include "lj_lex.h" + +/* -- Bytecode dump format ------------------------------------------------ */ + +/* +** dump = header proto+ 0U +** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*] +** proto = lengthU pdata +** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*] +** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU +** [debuglenU [firstlineU numlineU]] +** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* } +** knum = intU0 | (loU1 hiU) +** ktab = narrayU nhashU karray* khash* +** karray = ktabk +** khash = ktabk ktabk +** ktabk = ktabtypeU { intU | (loU hiU) | strB* } +** +** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1 +*/ + +/* Bytecode dump header. */ +#define BCDUMP_HEAD1 0x1b +#define BCDUMP_HEAD2 0x4c +#define BCDUMP_HEAD3 0x4a + +/* If you perform *any* kind of private modifications to the bytecode itself +** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher. +*/ +#define BCDUMP_VERSION 1 + +/* Compatibility flags. */ +#define BCDUMP_F_BE 0x01 +#define BCDUMP_F_STRIP 0x02 +#define BCDUMP_F_FFI 0x04 + +#define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1) + +/* Type codes for the GC constants of a prototype. Plus length for strings. */ +enum { + BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64, + BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR +}; + +/* Type codes for the keys/values of a constant table. */ +enum { + BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE, + BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR +}; + +/* -- Bytecode reader/writer ---------------------------------------------- */ + +LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, + void *data, int strip); +LJ_FUNC GCproto *lj_bcread(LexState *ls); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcread.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcread.c new file mode 100644 index 0000000..c0baece --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcread.c @@ -0,0 +1,476 @@ +/* +** Bytecode reader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bcread_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lualib.h" +#endif +#include "lj_lex.h" +#include "lj_bcdump.h" +#include "lj_state.h" + +/* Reuse some lexer fields for our own purposes. */ +#define bcread_flags(ls) ls->level +#define bcread_swap(ls) \ + ((bcread_flags(ls) & BCDUMP_F_BE) != LJ_BE*BCDUMP_F_BE) +#define bcread_oldtop(L, ls) restorestack(L, ls->lastline) +#define bcread_savetop(L, ls, top) \ + ls->lastline = (BCLine)savestack(L, (top)) + +/* -- Input buffer handling ----------------------------------------------- */ + +/* Throw reader error. */ +static LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em) +{ + lua_State *L = ls->L; + const char *name = ls->chunkarg; + if (*name == BCDUMP_HEAD1) name = "(binary)"; + else if (*name == '@' || *name == '=') name++; + lj_str_pushf(L, "%s: %s", name, err2msg(em)); + lj_err_throw(L, LUA_ERRSYNTAX); +} + +/* Resize input buffer. */ +static void bcread_resize(LexState *ls, MSize len) +{ + if (ls->sb.sz < len) { + MSize sz = ls->sb.sz * 2; + while (len > sz) sz = sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, sz); + /* Caveat: this may change ls->sb.buf which may affect ls->p. */ + } +} + +/* Refill buffer if needed. */ +static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) +{ + lua_assert(len != 0); + if (len > LJ_MAX_MEM || ls->current < 0) + bcread_error(ls, LJ_ERR_BCBAD); + do { + const char *buf; + size_t size; + if (ls->n) { /* Copy remainder to buffer. */ + if (ls->sb.n) { /* Move down in buffer. */ + lua_assert(ls->p + ls->n == ls->sb.buf + ls->sb.n); + if (ls->n != ls->sb.n) + memmove(ls->sb.buf, ls->p, ls->n); + } else { /* Copy from buffer provided by reader. */ + bcread_resize(ls, len); + memcpy(ls->sb.buf, ls->p, ls->n); + } + ls->p = ls->sb.buf; + } + ls->sb.n = ls->n; + buf = ls->rfunc(ls->L, ls->rdata, &size); /* Get more data from reader. */ + if (buf == NULL || size == 0) { /* EOF? */ + if (need) bcread_error(ls, LJ_ERR_BCBAD); + ls->current = -1; /* Only bad if we get called again. */ + break; + } + if (ls->sb.n) { /* Append to buffer. */ + MSize n = ls->sb.n + (MSize)size; + bcread_resize(ls, n < len ? len : n); + memcpy(ls->sb.buf + ls->sb.n, buf, size); + ls->n = ls->sb.n = n; + ls->p = ls->sb.buf; + } else { /* Return buffer provided by reader. */ + ls->n = (MSize)size; + ls->p = buf; + } + } while (ls->n < len); +} + +/* Need a certain number of bytes. */ +static LJ_AINLINE void bcread_need(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->n < len)) + bcread_fill(ls, len, 1); +} + +/* Want to read up to a certain number of bytes, but may need less. */ +static LJ_AINLINE void bcread_want(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->n < len)) + bcread_fill(ls, len, 0); +} + +#define bcread_dec(ls) check_exp(ls->n > 0, ls->n--) +#define bcread_consume(ls, len) check_exp(ls->n >= (len), ls->n -= (len)) + +/* Return memory block from buffer. */ +static uint8_t *bcread_mem(LexState *ls, MSize len) +{ + uint8_t *p = (uint8_t *)ls->p; + bcread_consume(ls, len); + ls->p = (char *)p + len; + return p; +} + +/* Copy memory block from buffer. */ +static void bcread_block(LexState *ls, void *q, MSize len) +{ + memcpy(q, bcread_mem(ls, len), len); +} + +/* Read byte from buffer. */ +static LJ_AINLINE uint32_t bcread_byte(LexState *ls) +{ + bcread_dec(ls); + return (uint32_t)(uint8_t)*ls->p++; +} + +/* Read ULEB128 value from buffer. */ +static uint32_t bcread_uleb128(LexState *ls) +{ + const uint8_t *p = (const uint8_t *)ls->p; + uint32_t v = *p++; + if (LJ_UNLIKELY(v >= 0x80)) { + int sh = 0; + v &= 0x7f; + do { + v |= ((*p & 0x7f) << (sh += 7)); + bcread_dec(ls); + } while (*p++ >= 0x80); + } + bcread_dec(ls); + ls->p = (char *)p; + return v; +} + +/* Read top 32 bits of 33 bit ULEB128 value from buffer. */ +static uint32_t bcread_uleb128_33(LexState *ls) +{ + const uint8_t *p = (const uint8_t *)ls->p; + uint32_t v = (*p++ >> 1); + if (LJ_UNLIKELY(v >= 0x40)) { + int sh = -1; + v &= 0x3f; + do { + v |= ((*p & 0x7f) << (sh += 7)); + bcread_dec(ls); + } while (*p++ >= 0x80); + } + bcread_dec(ls); + ls->p = (char *)p; + return v; +} + +/* -- Bytecode reader ----------------------------------------------------- */ + +/* Read debug info of a prototype. */ +static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg) +{ + void *lineinfo = (void *)proto_lineinfo(pt); + bcread_block(ls, lineinfo, sizedbg); + /* Swap lineinfo if the endianess differs. */ + if (bcread_swap(ls) && pt->numline >= 256) { + MSize i, n = pt->sizebc-1; + if (pt->numline < 65536) { + uint16_t *p = (uint16_t *)lineinfo; + for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8)); + } else { + uint32_t *p = (uint32_t *)lineinfo; + for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]); + } + } +} + +/* Find pointer to varinfo. */ +static const void *bcread_varinfo(GCproto *pt) +{ + const uint8_t *p = proto_uvinfo(pt); + MSize n = pt->sizeuv; + if (n) while (*p++ || --n) ; + return p; +} + +/* Read a single constant key/value of a template table. */ +static void bcread_ktabk(LexState *ls, TValue *o) +{ + MSize tp = bcread_uleb128(ls); + if (tp >= BCDUMP_KTAB_STR) { + MSize len = tp - BCDUMP_KTAB_STR; + const char *p = (const char *)bcread_mem(ls, len); + setstrV(ls->L, o, lj_str_new(ls->L, p, len)); + } else if (tp == BCDUMP_KTAB_INT) { + setintV(o, (int32_t)bcread_uleb128(ls)); + } else if (tp == BCDUMP_KTAB_NUM) { + o->u32.lo = bcread_uleb128(ls); + o->u32.hi = bcread_uleb128(ls); + } else { + lua_assert(tp <= BCDUMP_KTAB_TRUE); + setitype(o, ~tp); + } +} + +/* Read a template table. */ +static GCtab *bcread_ktab(LexState *ls) +{ + MSize narray = bcread_uleb128(ls); + MSize nhash = bcread_uleb128(ls); + GCtab *t = lj_tab_new(ls->L, narray, hsize2hbits(nhash)); + if (narray) { /* Read array entries. */ + MSize i; + TValue *o = tvref(t->array); + for (i = 0; i < narray; i++, o++) + bcread_ktabk(ls, o); + } + if (nhash) { /* Read hash entries. */ + MSize i; + for (i = 0; i < nhash; i++) { + TValue key; + bcread_ktabk(ls, &key); + lua_assert(!tvisnil(&key)); + bcread_ktabk(ls, lj_tab_set(ls->L, t, &key)); + } + } + return t; +} + +/* Read GC constants of a prototype. */ +static void bcread_kgc(LexState *ls, GCproto *pt, MSize sizekgc) +{ + MSize i; + GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc; + for (i = 0; i < sizekgc; i++, kr++) { + MSize tp = bcread_uleb128(ls); + if (tp >= BCDUMP_KGC_STR) { + MSize len = tp - BCDUMP_KGC_STR; + const char *p = (const char *)bcread_mem(ls, len); + setgcref(*kr, obj2gco(lj_str_new(ls->L, p, len))); + } else if (tp == BCDUMP_KGC_TAB) { + setgcref(*kr, obj2gco(bcread_ktab(ls))); +#if LJ_HASFFI + } else if (tp != BCDUMP_KGC_CHILD) { + CTypeID id = tp == BCDUMP_KGC_COMPLEX ? CTID_COMPLEX_DOUBLE : + tp == BCDUMP_KGC_I64 ? CTID_INT64 : CTID_UINT64; + CTSize sz = tp == BCDUMP_KGC_COMPLEX ? 16 : 8; + GCcdata *cd = lj_cdata_new_(ls->L, id, sz); + TValue *p = (TValue *)cdataptr(cd); + setgcref(*kr, obj2gco(cd)); + p[0].u32.lo = bcread_uleb128(ls); + p[0].u32.hi = bcread_uleb128(ls); + if (tp == BCDUMP_KGC_COMPLEX) { + p[1].u32.lo = bcread_uleb128(ls); + p[1].u32.hi = bcread_uleb128(ls); + } +#endif + } else { + lua_State *L = ls->L; + lua_assert(tp == BCDUMP_KGC_CHILD); + if (L->top <= bcread_oldtop(L, ls)) /* Stack underflow? */ + bcread_error(ls, LJ_ERR_BCBAD); + L->top--; + setgcref(*kr, obj2gco(protoV(L->top))); + } + } +} + +/* Read number constants of a prototype. */ +static void bcread_knum(LexState *ls, GCproto *pt, MSize sizekn) +{ + MSize i; + TValue *o = mref(pt->k, TValue); + for (i = 0; i < sizekn; i++, o++) { + int isnum = (ls->p[0] & 1); + uint32_t lo = bcread_uleb128_33(ls); + if (isnum) { + o->u32.lo = lo; + o->u32.hi = bcread_uleb128(ls); + } else { + setintV(o, lo); + } + } +} + +/* Read bytecode instructions. */ +static void bcread_bytecode(LexState *ls, GCproto *pt, MSize sizebc) +{ + BCIns *bc = proto_bc(pt); + bc[0] = BCINS_AD((pt->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF, + pt->framesize, 0); + bcread_block(ls, bc+1, (sizebc-1)*(MSize)sizeof(BCIns)); + /* Swap bytecode instructions if the endianess differs. */ + if (bcread_swap(ls)) { + MSize i; + for (i = 1; i < sizebc; i++) bc[i] = lj_bswap(bc[i]); + } +} + +/* Read upvalue refs. */ +static void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv) +{ + if (sizeuv) { + uint16_t *uv = proto_uv(pt); + bcread_block(ls, uv, sizeuv*2); + /* Swap upvalue refs if the endianess differs. */ + if (bcread_swap(ls)) { + MSize i; + for (i = 0; i < sizeuv; i++) + uv[i] = (uint16_t)((uv[i] >> 8)|(uv[i] << 8)); + } + } +} + +/* Read a prototype. */ +static GCproto *bcread_proto(LexState *ls) +{ + GCproto *pt; + MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept; + MSize ofsk, ofsuv, ofsdbg; + MSize sizedbg = 0; + BCLine firstline = 0, numline = 0; + MSize len, startn; + + /* Read length. */ + if (ls->n > 0 && ls->p[0] == 0) { /* Shortcut EOF. */ + ls->n--; ls->p++; + return NULL; + } + bcread_want(ls, 5); + len = bcread_uleb128(ls); + if (!len) return NULL; /* EOF */ + bcread_need(ls, len); + startn = ls->n; + + /* Read prototype header. */ + flags = bcread_byte(ls); + numparams = bcread_byte(ls); + framesize = bcread_byte(ls); + sizeuv = bcread_byte(ls); + sizekgc = bcread_uleb128(ls); + sizekn = bcread_uleb128(ls); + sizebc = bcread_uleb128(ls) + 1; + if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) { + sizedbg = bcread_uleb128(ls); + if (sizedbg) { + firstline = bcread_uleb128(ls); + numline = bcread_uleb128(ls); + } + } + + /* Calculate total size of prototype including all colocated arrays. */ + sizept = (MSize)sizeof(GCproto) + + sizebc*(MSize)sizeof(BCIns) + + sizekgc*(MSize)sizeof(GCRef); + sizept = (sizept + (MSize)sizeof(TValue)-1) & ~((MSize)sizeof(TValue)-1); + ofsk = sizept; sizept += sizekn*(MSize)sizeof(TValue); + ofsuv = sizept; sizept += ((sizeuv+1)&~1)*2; + ofsdbg = sizept; sizept += sizedbg; + + /* Allocate prototype object and initialize its fields. */ + pt = (GCproto *)lj_mem_newgco(ls->L, (MSize)sizept); + pt->gct = ~LJ_TPROTO; + pt->numparams = (uint8_t)numparams; + pt->framesize = (uint8_t)framesize; + pt->sizebc = sizebc; + setmref(pt->k, (char *)pt + ofsk); + setmref(pt->uv, (char *)pt + ofsuv); + pt->sizekgc = 0; /* Set to zero until fully initialized. */ + pt->sizekn = sizekn; + pt->sizept = sizept; + pt->sizeuv = (uint8_t)sizeuv; + pt->flags = (uint8_t)flags; + pt->trace = 0; + setgcref(pt->chunkname, obj2gco(ls->chunkname)); + + /* Close potentially uninitialized gap between bc and kgc. */ + *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(sizekgc+1)) = 0; + + /* Read bytecode instructions and upvalue refs. */ + bcread_bytecode(ls, pt, sizebc); + bcread_uv(ls, pt, sizeuv); + + /* Read constants. */ + bcread_kgc(ls, pt, sizekgc); + pt->sizekgc = sizekgc; + bcread_knum(ls, pt, sizekn); + + /* Read and initialize debug info. */ + pt->firstline = firstline; + pt->numline = numline; + if (sizedbg) { + MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2); + setmref(pt->lineinfo, (char *)pt + ofsdbg); + setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli); + bcread_dbg(ls, pt, sizedbg); + setmref(pt->varinfo, bcread_varinfo(pt)); + } else { + setmref(pt->lineinfo, NULL); + setmref(pt->uvinfo, NULL); + setmref(pt->varinfo, NULL); + } + + if (len != startn - ls->n) + bcread_error(ls, LJ_ERR_BCBAD); + return pt; +} + +/* Read and check header of bytecode dump. */ +static int bcread_header(LexState *ls) +{ + uint32_t flags; + bcread_want(ls, 3+5+5); + if (bcread_byte(ls) != BCDUMP_HEAD2 || + bcread_byte(ls) != BCDUMP_HEAD3 || + bcread_byte(ls) != BCDUMP_VERSION) return 0; + bcread_flags(ls) = flags = bcread_uleb128(ls); + if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0; + if ((flags & BCDUMP_F_FFI)) { +#if LJ_HASFFI + lua_State *L = ls->L; + if (!ctype_ctsG(G(L))) { + ptrdiff_t oldtop = savestack(L, L->top); + luaopen_ffi(L); /* Load FFI library on-demand. */ + L->top = restorestack(L, oldtop); + } +#else + return 0; +#endif + } + if ((flags & BCDUMP_F_STRIP)) { + ls->chunkname = lj_str_newz(ls->L, ls->chunkarg); + } else { + MSize len = bcread_uleb128(ls); + bcread_need(ls, len); + ls->chunkname = lj_str_new(ls->L, (const char *)bcread_mem(ls, len), len); + } + return 1; /* Ok. */ +} + +/* Read a bytecode dump. */ +GCproto *lj_bcread(LexState *ls) +{ + lua_State *L = ls->L; + lua_assert(ls->current == BCDUMP_HEAD1); + bcread_savetop(L, ls, L->top); + lj_str_resetbuf(&ls->sb); + /* Check for a valid bytecode dump header. */ + if (!bcread_header(ls)) + bcread_error(ls, LJ_ERR_BCFMT); + for (;;) { /* Process all prototypes in the bytecode dump. */ + GCproto *pt = bcread_proto(ls); + if (!pt) break; + setprotoV(L, L->top, pt); + incr_top(L); + } + if ((int32_t)ls->n > 0 || L->top-1 != bcread_oldtop(L, ls)) + bcread_error(ls, LJ_ERR_BCBAD); + /* Pop off last prototype. */ + L->top--; + return protoV(L->top); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcwrite.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcwrite.c new file mode 100644 index 0000000..dcdaa10 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_bcwrite.c @@ -0,0 +1,396 @@ +/* +** Bytecode writer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bcwrite_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#if LJ_HASJIT +#include "lj_dispatch.h" +#include "lj_jit.h" +#endif +#include "lj_bcdump.h" +#include "lj_vm.h" + +/* Context for bytecode writer. */ +typedef struct BCWriteCtx { + SBuf sb; /* Output buffer. */ + lua_State *L; /* Lua state. */ + GCproto *pt; /* Root prototype. */ + lua_Writer wfunc; /* Writer callback. */ + void *wdata; /* Writer callback data. */ + int strip; /* Strip debug info. */ + int status; /* Status from writer callback. */ +} BCWriteCtx; + +/* -- Output buffer handling ---------------------------------------------- */ + +/* Resize buffer if needed. */ +static LJ_NOINLINE void bcwrite_resize(BCWriteCtx *ctx, MSize len) +{ + MSize sz = ctx->sb.sz * 2; + while (ctx->sb.n + len > sz) sz = sz * 2; + lj_str_resizebuf(ctx->L, &ctx->sb, sz); +} + +/* Need a certain amount of buffer space. */ +static LJ_AINLINE void bcwrite_need(BCWriteCtx *ctx, MSize len) +{ + if (LJ_UNLIKELY(ctx->sb.n + len > ctx->sb.sz)) + bcwrite_resize(ctx, len); +} + +/* Add memory block to buffer. */ +static void bcwrite_block(BCWriteCtx *ctx, const void *p, MSize len) +{ + uint8_t *q = (uint8_t *)(ctx->sb.buf + ctx->sb.n); + MSize i; + ctx->sb.n += len; + for (i = 0; i < len; i++) q[i] = ((uint8_t *)p)[i]; +} + +/* Add byte to buffer. */ +static LJ_AINLINE void bcwrite_byte(BCWriteCtx *ctx, uint8_t b) +{ + ctx->sb.buf[ctx->sb.n++] = b; +} + +/* Add ULEB128 value to buffer. */ +static void bcwrite_uleb128(BCWriteCtx *ctx, uint32_t v) +{ + MSize n = ctx->sb.n; + uint8_t *p = (uint8_t *)ctx->sb.buf; + for (; v >= 0x80; v >>= 7) + p[n++] = (uint8_t)((v & 0x7f) | 0x80); + p[n++] = (uint8_t)v; + ctx->sb.n = n; +} + +/* -- Bytecode writer ----------------------------------------------------- */ + +/* Write a single constant key/value of a template table. */ +static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow) +{ + bcwrite_need(ctx, 1+10); + if (tvisstr(o)) { + const GCstr *str = strV(o); + MSize len = str->len; + bcwrite_need(ctx, 5+len); + bcwrite_uleb128(ctx, BCDUMP_KTAB_STR+len); + bcwrite_block(ctx, strdata(str), len); + } else if (tvisint(o)) { + bcwrite_byte(ctx, BCDUMP_KTAB_INT); + bcwrite_uleb128(ctx, intV(o)); + } else if (tvisnum(o)) { + if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ + lua_Number num = numV(o); + int32_t k = lj_num2int(num); + if (num == (lua_Number)k) { /* -0 is never a constant. */ + bcwrite_byte(ctx, BCDUMP_KTAB_INT); + bcwrite_uleb128(ctx, k); + return; + } + } + bcwrite_byte(ctx, BCDUMP_KTAB_NUM); + bcwrite_uleb128(ctx, o->u32.lo); + bcwrite_uleb128(ctx, o->u32.hi); + } else { + lua_assert(tvispri(o)); + bcwrite_byte(ctx, BCDUMP_KTAB_NIL+~itype(o)); + } +} + +/* Write a template table. */ +static void bcwrite_ktab(BCWriteCtx *ctx, const GCtab *t) +{ + MSize narray = 0, nhash = 0; + if (t->asize > 0) { /* Determine max. length of array part. */ + ptrdiff_t i; + TValue *array = tvref(t->array); + for (i = (ptrdiff_t)t->asize-1; i >= 0; i--) + if (!tvisnil(&array[i])) + break; + narray = (MSize)(i+1); + } + if (t->hmask > 0) { /* Count number of used hash slots. */ + MSize i, hmask = t->hmask; + Node *node = noderef(t->node); + for (i = 0; i <= hmask; i++) + nhash += !tvisnil(&node[i].val); + } + /* Write number of array slots and hash slots. */ + bcwrite_uleb128(ctx, narray); + bcwrite_uleb128(ctx, nhash); + if (narray) { /* Write array entries (may contain nil). */ + MSize i; + TValue *o = tvref(t->array); + for (i = 0; i < narray; i++, o++) + bcwrite_ktabk(ctx, o, 1); + } + if (nhash) { /* Write hash entries. */ + MSize i = nhash; + Node *node = noderef(t->node) + t->hmask; + for (;; node--) + if (!tvisnil(&node->val)) { + bcwrite_ktabk(ctx, &node->key, 0); + bcwrite_ktabk(ctx, &node->val, 1); + if (--i == 0) break; + } + } +} + +/* Write GC constants of a prototype. */ +static void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt) +{ + MSize i, sizekgc = pt->sizekgc; + GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc; + for (i = 0; i < sizekgc; i++, kr++) { + GCobj *o = gcref(*kr); + MSize tp, need = 1; + /* Determine constant type and needed size. */ + if (o->gch.gct == ~LJ_TSTR) { + tp = BCDUMP_KGC_STR + gco2str(o)->len; + need = 5+gco2str(o)->len; + } else if (o->gch.gct == ~LJ_TPROTO) { + lua_assert((pt->flags & PROTO_CHILD)); + tp = BCDUMP_KGC_CHILD; +#if LJ_HASFFI + } else if (o->gch.gct == ~LJ_TCDATA) { + CTypeID id = gco2cd(o)->ctypeid; + need = 1+4*5; + if (id == CTID_INT64) { + tp = BCDUMP_KGC_I64; + } else if (id == CTID_UINT64) { + tp = BCDUMP_KGC_U64; + } else { + lua_assert(id == CTID_COMPLEX_DOUBLE); + tp = BCDUMP_KGC_COMPLEX; + } +#endif + } else { + lua_assert(o->gch.gct == ~LJ_TTAB); + tp = BCDUMP_KGC_TAB; + need = 1+2*5; + } + /* Write constant type. */ + bcwrite_need(ctx, need); + bcwrite_uleb128(ctx, tp); + /* Write constant data (if any). */ + if (tp >= BCDUMP_KGC_STR) { + bcwrite_block(ctx, strdata(gco2str(o)), gco2str(o)->len); + } else if (tp == BCDUMP_KGC_TAB) { + bcwrite_ktab(ctx, gco2tab(o)); +#if LJ_HASFFI + } else if (tp != BCDUMP_KGC_CHILD) { + cTValue *p = (TValue *)cdataptr(gco2cd(o)); + bcwrite_uleb128(ctx, p[0].u32.lo); + bcwrite_uleb128(ctx, p[0].u32.hi); + if (tp == BCDUMP_KGC_COMPLEX) { + bcwrite_uleb128(ctx, p[1].u32.lo); + bcwrite_uleb128(ctx, p[1].u32.hi); + } +#endif + } + } +} + +/* Write number constants of a prototype. */ +static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt) +{ + MSize i, sizekn = pt->sizekn; + cTValue *o = mref(pt->k, TValue); + bcwrite_need(ctx, 10*sizekn); + for (i = 0; i < sizekn; i++, o++) { + int32_t k; + if (tvisint(o)) { + k = intV(o); + goto save_int; + } else { + /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */ + if (!LJ_DUALNUM) { /* Narrow number constants to integers. */ + lua_Number num = numV(o); + k = lj_num2int(num); + if (num == (lua_Number)k) { /* -0 is never a constant. */ + save_int: + bcwrite_uleb128(ctx, 2*(uint32_t)k | ((uint32_t)k & 0x80000000u)); + if (k < 0) { + char *p = &ctx->sb.buf[ctx->sb.n-1]; + *p = (*p & 7) | ((k>>27) & 0x18); + } + continue; + } + } + bcwrite_uleb128(ctx, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u))); + if (o->u32.lo >= 0x80000000u) { + char *p = &ctx->sb.buf[ctx->sb.n-1]; + *p = (*p & 7) | ((o->u32.lo>>27) & 0x18); + } + bcwrite_uleb128(ctx, o->u32.hi); + } + } +} + +/* Write bytecode instructions. */ +static void bcwrite_bytecode(BCWriteCtx *ctx, GCproto *pt) +{ + MSize nbc = pt->sizebc-1; /* Omit the [JI]FUNC* header. */ +#if LJ_HASJIT + uint8_t *p = (uint8_t *)&ctx->sb.buf[ctx->sb.n]; +#endif + bcwrite_block(ctx, proto_bc(pt)+1, nbc*(MSize)sizeof(BCIns)); +#if LJ_HASJIT + /* Unpatch modified bytecode containing ILOOP/JLOOP etc. */ + if ((pt->flags & PROTO_ILOOP) || pt->trace) { + jit_State *J = L2J(ctx->L); + MSize i; + for (i = 0; i < nbc; i++, p += sizeof(BCIns)) { + BCOp op = (BCOp)p[LJ_ENDIAN_SELECT(0, 3)]; + if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP || + op == BC_JFORI) { + p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_IFORL+BC_FORL); + } else if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) { + BCReg rd = p[LJ_ENDIAN_SELECT(2, 1)] + (p[LJ_ENDIAN_SELECT(3, 0)] << 8); + BCIns ins = traceref(J, rd)->startins; + p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_JFORL+BC_FORL); + p[LJ_ENDIAN_SELECT(2, 1)] = bc_c(ins); + p[LJ_ENDIAN_SELECT(3, 0)] = bc_b(ins); + } + } + } +#endif +} + +/* Write prototype. */ +static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt) +{ + MSize sizedbg = 0; + + /* Recursively write children of prototype. */ + if ((pt->flags & PROTO_CHILD)) { + ptrdiff_t i, n = pt->sizekgc; + GCRef *kr = mref(pt->k, GCRef) - 1; + for (i = 0; i < n; i++, kr--) { + GCobj *o = gcref(*kr); + if (o->gch.gct == ~LJ_TPROTO) + bcwrite_proto(ctx, gco2pt(o)); + } + } + + /* Start writing the prototype info to a buffer. */ + lj_str_resetbuf(&ctx->sb); + ctx->sb.n = 5; /* Leave room for final size. */ + bcwrite_need(ctx, 4+6*5+(pt->sizebc-1)*(MSize)sizeof(BCIns)+pt->sizeuv*2); + + /* Write prototype header. */ + bcwrite_byte(ctx, (pt->flags & (PROTO_CHILD|PROTO_VARARG|PROTO_FFI))); + bcwrite_byte(ctx, pt->numparams); + bcwrite_byte(ctx, pt->framesize); + bcwrite_byte(ctx, pt->sizeuv); + bcwrite_uleb128(ctx, pt->sizekgc); + bcwrite_uleb128(ctx, pt->sizekn); + bcwrite_uleb128(ctx, pt->sizebc-1); + if (!ctx->strip) { + if (proto_lineinfo(pt)) + sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt); + bcwrite_uleb128(ctx, sizedbg); + if (sizedbg) { + bcwrite_uleb128(ctx, pt->firstline); + bcwrite_uleb128(ctx, pt->numline); + } + } + + /* Write bytecode instructions and upvalue refs. */ + bcwrite_bytecode(ctx, pt); + bcwrite_block(ctx, proto_uv(pt), pt->sizeuv*2); + + /* Write constants. */ + bcwrite_kgc(ctx, pt); + bcwrite_knum(ctx, pt); + + /* Write debug info, if not stripped. */ + if (sizedbg) { + bcwrite_need(ctx, sizedbg); + bcwrite_block(ctx, proto_lineinfo(pt), sizedbg); + } + + /* Pass buffer to writer function. */ + if (ctx->status == 0) { + MSize n = ctx->sb.n - 5; + MSize nn = (lj_fls(n)+8)*9 >> 6; + ctx->sb.n = 5 - nn; + bcwrite_uleb128(ctx, n); /* Fill in final size. */ + lua_assert(ctx->sb.n == 5); + ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf+5-nn, nn+n, ctx->wdata); + } +} + +/* Write header of bytecode dump. */ +static void bcwrite_header(BCWriteCtx *ctx) +{ + GCstr *chunkname = proto_chunkname(ctx->pt); + const char *name = strdata(chunkname); + MSize len = chunkname->len; + lj_str_resetbuf(&ctx->sb); + bcwrite_need(ctx, 5+5+len); + bcwrite_byte(ctx, BCDUMP_HEAD1); + bcwrite_byte(ctx, BCDUMP_HEAD2); + bcwrite_byte(ctx, BCDUMP_HEAD3); + bcwrite_byte(ctx, BCDUMP_VERSION); + bcwrite_byte(ctx, (ctx->strip ? BCDUMP_F_STRIP : 0) + + (LJ_BE ? BCDUMP_F_BE : 0) + + ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0)); + if (!ctx->strip) { + bcwrite_uleb128(ctx, len); + bcwrite_block(ctx, name, len); + } + ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf, ctx->sb.n, ctx->wdata); +} + +/* Write footer of bytecode dump. */ +static void bcwrite_footer(BCWriteCtx *ctx) +{ + if (ctx->status == 0) { + uint8_t zero = 0; + ctx->status = ctx->wfunc(ctx->L, &zero, 1, ctx->wdata); + } +} + +/* Protected callback for bytecode writer. */ +static TValue *cpwriter(lua_State *L, lua_CFunction dummy, void *ud) +{ + BCWriteCtx *ctx = (BCWriteCtx *)ud; + UNUSED(dummy); + lj_str_resizebuf(L, &ctx->sb, 1024); /* Avoids resize for most prototypes. */ + bcwrite_header(ctx); + bcwrite_proto(ctx, ctx->pt); + bcwrite_footer(ctx); + return NULL; +} + +/* Write bytecode for a prototype. */ +int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, void *data, + int strip) +{ + BCWriteCtx ctx; + int status; + ctx.L = L; + ctx.pt = pt; + ctx.wfunc = writer; + ctx.wdata = data; + ctx.strip = strip; + ctx.status = 0; + lj_str_initbuf(&ctx.sb); + status = lj_vm_cpcall(L, NULL, &ctx, cpwriter); + if (status == 0) status = ctx.status; + lj_str_freebuf(G(ctx.L), &ctx.sb); + return status; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.c new file mode 100644 index 0000000..9f94091 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.c @@ -0,0 +1,351 @@ +/* +** C data arithmetic. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_carith.h" + +/* -- C data arithmetic --------------------------------------------------- */ + +/* Binary operands of an operator converted to ctypes. */ +typedef struct CDArith { + uint8_t *p[2]; + CType *ct[2]; +} CDArith; + +/* Check arguments for arithmetic metamethods. */ +static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) +{ + TValue *o = L->base; + int ok = 1; + MSize i; + if (o+1 >= L->top) + lj_err_argt(L, 1, LUA_TCDATA); + for (i = 0; i < 2; i++, o++) { + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + CTypeID id = (CTypeID)cd->ctypeid; + CType *ct = ctype_raw(cts, id); + uint8_t *p = (uint8_t *)cdataptr(cd); + if (ctype_isptr(ct->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); + } else if (ctype_isfunc(ct->info)) { + p = (uint8_t *)*(void **)p; + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); + } + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + ca->ct[i] = ct; + ca->p[i] = p; + } else if (tvisint(o)) { + ca->ct[i] = ctype_get(cts, CTID_INT32); + ca->p[i] = (uint8_t *)&o->i; + } else if (tvisnum(o)) { + ca->ct[i] = ctype_get(cts, CTID_DOUBLE); + ca->p[i] = (uint8_t *)&o->n; + } else if (tvisnil(o)) { + ca->ct[i] = ctype_get(cts, CTID_P_VOID); + ca->p[i] = (uint8_t *)0; + } else if (tvisstr(o)) { + TValue *o2 = i == 0 ? o+1 : o-1; + CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid); + ca->ct[i] = NULL; + ca->p[i] = NULL; + ok = 0; + if (ctype_isenum(ct->info)) { + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, ct, strV(o), &ofs); + if (cct && ctype_isconstval(cct->info)) { + ca->ct[i] = ctype_child(cts, cct); + ca->p[i] = (uint8_t *)&cct->size; /* Assumes ct does not grow. */ + ok = 1; + } else { + ca->ct[1-i] = ct; /* Use enum to improve error message. */ + ca->p[1-i] = NULL; + break; + } + } + } else { + ca->ct[i] = NULL; + ca->p[i] = NULL; + ok = 0; + } + } + return ok; +} + +/* Pointer arithmetic. */ +static int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + CType *ctp = ca->ct[0]; + uint8_t *pp = ca->p[0]; + ptrdiff_t idx; + CTSize sz; + CTypeID id; + GCcdata *cd; + if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) { + if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) && + (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) { + uint8_t *pp2 = ca->p[1]; + if (mm == MM_eq) { /* Pointer equality. Incompatible pointers are ok. */ + setboolV(L->top-1, (pp == pp2)); + return 1; + } + if (!lj_cconv_compatptr(cts, ctp, ca->ct[1], CCF_IGNQUAL)) + return 0; + if (mm == MM_sub) { /* Pointer difference. */ + intptr_t diff; + sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */ + if (sz == 0 || sz == CTSIZE_INVALID) + return 0; + diff = ((intptr_t)pp - (intptr_t)pp2) / (int32_t)sz; + /* All valid pointer differences on x64 are in (-2^47, +2^47), + ** which fits into a double without loss of precision. + */ + setintptrV(L->top-1, (int32_t)diff); + return 1; + } else if (mm == MM_lt) { /* Pointer comparison (unsigned). */ + setboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2)); + return 1; + } else { + lua_assert(mm == MM_le); + setboolV(L->top-1, ((uintptr_t)pp <= (uintptr_t)pp2)); + return 1; + } + } + if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(ca->ct[1]->info))) + return 0; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[1], + (uint8_t *)&idx, ca->p[1], 0); + if (mm == MM_sub) idx = -idx; + } else if (mm == MM_add && ctype_isnum(ctp->info) && + (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) { + /* Swap pointer and index. */ + ctp = ca->ct[1]; pp = ca->p[1]; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[0], + (uint8_t *)&idx, ca->p[0], 0); + } else { + return 0; + } + sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */ + if (sz == CTSIZE_INVALID) + return 0; + pp += idx*(int32_t)sz; /* Compute pointer + index. */ + id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)), + CTSIZE_PTR); + cd = lj_cdata_new(cts, id, CTSIZE_PTR); + *(uint8_t **)cdataptr(cd) = pp; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +/* 64 bit integer arithmetic. */ +static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + if (ctype_isnum(ca->ct[0]->info) && ca->ct[0]->size <= 8 && + ctype_isnum(ca->ct[1]->info) && ca->ct[1]->size <= 8) { + CTypeID id = (((ca->ct[0]->info & CTF_UNSIGNED) && ca->ct[0]->size == 8) || + ((ca->ct[1]->info & CTF_UNSIGNED) && ca->ct[1]->size == 8)) ? + CTID_UINT64 : CTID_INT64; + CType *ct = ctype_get(cts, id); + GCcdata *cd; + uint64_t u0, u1, *up; + lj_cconv_ct_ct(cts, ct, ca->ct[0], (uint8_t *)&u0, ca->p[0], 0); + if (mm != MM_unm) + lj_cconv_ct_ct(cts, ct, ca->ct[1], (uint8_t *)&u1, ca->p[1], 0); + switch (mm) { + case MM_eq: + setboolV(L->top-1, (u0 == u1)); + return 1; + case MM_lt: + setboolV(L->top-1, + id == CTID_INT64 ? ((int64_t)u0 < (int64_t)u1) : (u0 < u1)); + return 1; + case MM_le: + setboolV(L->top-1, + id == CTID_INT64 ? ((int64_t)u0 <= (int64_t)u1) : (u0 <= u1)); + return 1; + default: break; + } + cd = lj_cdata_new(cts, id, 8); + up = (uint64_t *)cdataptr(cd); + setcdataV(L, L->top-1, cd); + switch (mm) { + case MM_add: *up = u0 + u1; break; + case MM_sub: *up = u0 - u1; break; + case MM_mul: *up = u0 * u1; break; + case MM_div: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_divi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_divu64(u0, u1); + break; + case MM_mod: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_modi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_modu64(u0, u1); + break; + case MM_pow: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_powi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_powu64(u0, u1); + break; + case MM_unm: *up = (uint64_t)-(int64_t)u0; break; + default: lua_assert(0); break; + } + lj_gc_check(L); + return 1; + } + return 0; +} + +/* Handle ctype arithmetic metamethods. */ +static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + cTValue *tv = NULL; + if (tviscdata(L->base)) { + CTypeID id = cdataV(L->base)->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + } + if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) { + CTypeID id = cdataV(L->base+1)->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + } + if (!tv) { + const char *repr[2]; + int i, isenum = -1, isstr = -1; + if (mm == MM_eq) { /* Equality checks never raise an error. */ + setboolV(L->top-1, 0); + return 1; + } + for (i = 0; i < 2; i++) { + if (ca->ct[i] && tviscdata(L->base+i)) { + if (ctype_isenum(ca->ct[i]->info)) isenum = i; + repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); + } else { + if (tvisstr(&L->base[i])) isstr = i; + repr[i] = lj_typename(&L->base[i]); + } + } + if ((isenum ^ isstr) == 1) + lj_err_callerv(L, LJ_ERR_FFI_BADCONV, repr[isstr], repr[isenum]); + lj_err_callerv(L, mm == MM_len ? LJ_ERR_FFI_BADLEN : + mm == MM_concat ? LJ_ERR_FFI_BADCONCAT : + mm < MM_add ? LJ_ERR_FFI_BADCOMP : LJ_ERR_FFI_BADARITH, + repr[0], repr[1]); + } + return lj_meta_tailcall(L, tv); +} + +/* Arithmetic operators for cdata. */ +int lj_carith_op(lua_State *L, MMS mm) +{ + CTState *cts = ctype_cts(L); + CDArith ca; + if (carith_checkarg(L, cts, &ca)) { + if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) { + copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */ + return 1; + } + } + return lj_carith_meta(L, cts, &ca, mm); +} + +/* -- 64 bit integer arithmetic helpers ----------------------------------- */ + +#if LJ_32 && LJ_HASJIT +/* Signed/unsigned 64 bit multiplication. */ +int64_t lj_carith_mul64(int64_t a, int64_t b) +{ + return a * b; +} +#endif + +/* Unsigned 64 bit division. */ +uint64_t lj_carith_divu64(uint64_t a, uint64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + return a / b; +} + +/* Signed 64 bit division. */ +int64_t lj_carith_divi64(int64_t a, int64_t b) +{ + if (b == 0 || (a == (int64_t)U64x(80000000,00000000) && b == -1)) + return U64x(80000000,00000000); + return a / b; +} + +/* Unsigned 64 bit modulo. */ +uint64_t lj_carith_modu64(uint64_t a, uint64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + return a % b; +} + +/* Signed 64 bit modulo. */ +int64_t lj_carith_modi64(int64_t a, int64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + if (a == (int64_t)U64x(80000000,00000000) && b == -1) return 0; + return a % b; +} + +/* Unsigned 64 bit x^k. */ +uint64_t lj_carith_powu64(uint64_t x, uint64_t k) +{ + uint64_t y; + if (k == 0) + return 1; + for (; (k & 1) == 0; k >>= 1) x *= x; + y = x; + if ((k >>= 1) != 0) { + for (;;) { + x *= x; + if (k == 1) break; + if (k & 1) y *= x; + k >>= 1; + } + y *= x; + } + return y; +} + +/* Signed 64 bit x^k. */ +int64_t lj_carith_powi64(int64_t x, int64_t k) +{ + if (k == 0) + return 1; + if (k < 0) { + if (x == 0) + return U64x(7fffffff,ffffffff); + else if (x == 1) + return 1; + else if (x == -1) + return (k & 1) ? -1 : 1; + else + return 0; + } + return (int64_t)lj_carith_powu64((uint64_t)x, (uint64_t)k); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.h new file mode 100644 index 0000000..8b28556 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_carith.h @@ -0,0 +1,27 @@ +/* +** C data arithmetic. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CARITH_H +#define _LJ_CARITH_H + +#include "lj_obj.h" + +#if LJ_HASFFI + +LJ_FUNC int lj_carith_op(lua_State *L, MMS mm); + +#if LJ_32 && LJ_HASJIT +LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k); +#endif +LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b); +LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b); +LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b); +LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b); +LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k); +LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.c new file mode 100644 index 0000000..70c9ba5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.c @@ -0,0 +1,900 @@ +/* +** FFI C call handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_ccall.h" +#include "lj_trace.h" + +/* Target-specific handling of register arguments. */ +#if LJ_TARGET_X86 +/* -- x86 calling conventions --------------------------------------------- */ + +#if LJ_ABI_WIN + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs bigger than 8 by reference (on stack only). */ \ + cc->retref = (sz > 8); \ + if (cc->retref) cc->stack[nsp++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET + +#else + +#if LJ_TARGET_OSX + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size 1, 2, 4 or 8 in registers. */ \ + cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \ + if (cc->retref) { \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; \ + } else { /* Struct with single FP field ends up in FPR. */ \ + cc->resx87 = ccall_classify_struct(cts, ctr); \ + } + +#define CCALL_HANDLE_STRUCTRET2 \ + if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \ + memcpy(dp, sp, ctr->size); + +#else + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference (in reg or on stack). */ \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; + +#endif + +#define CCALL_HANDLE_COMPLEXRET \ + /* Return complex float in GPRs and complex double by reference. */ \ + cc->retref = (sz > 8); \ + if (cc->retref) { \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; \ + } + +#endif + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!cc->retref) \ + *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + ngpr = maxgpr; /* Pass all structs by value on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 1; /* Pass complex by value on stack. */ + +#define CCALL_HANDLE_REGARG \ + if (!isfp) { /* Only non-FP values may be passed in registers. */ \ + if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \ + if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \ + } else if (ngpr + 1 <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_X64 && LJ_ABI_WIN +/* -- Windows/x64 calling conventions ------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \ + cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!cc->retref) \ + *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \ + if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all other structs by reference. */ \ + } + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex float in a GPR and complex double by reference. */ \ + if (sz != 2*sizeof(float)) { \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; \ + } + +/* Windows/x64 argument registers are strictly positional (use ngpr). */ +#define CCALL_HANDLE_REGARG \ + if (isfp) { \ + if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \ + } else { \ + if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \ + } + +#elif LJ_TARGET_X64 +/* -- POSIX/x64 calling conventions --------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + if (ccall_classify_struct(cts, ctr, rcl, 0)) { \ + cc->retref = 1; /* Return struct by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + } else { \ + cc->retref = 0; /* Return small structs in registers. */ \ + } + +#define CCALL_HANDLE_STRUCTRET2 \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + ccall_classify_struct(cts, ctr, rcl, 0); \ + ccall_struct_ret(cc, rcl, dp, ctr->size); + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in one or two FPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPR. */ \ + *(int64_t *)dp = cc->fpr[0].l[0]; \ + } else { /* Copy non-contiguous complex double from FPRs. */ \ + ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \ + ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \ + } + +#define CCALL_HANDLE_STRUCTARG \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + if (!ccall_classify_struct(cts, d, rcl, 0)) { \ + cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \ + if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \ + nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \ + continue; \ + } /* Pass all other structs by value on stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 2; /* Pass complex in FPRs or on stack. Needs postprocessing. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp) { /* Try to pass argument in FPRs. */ \ + int n2 = ctype_isvector(d->info) ? 1 : n; \ + if (nfpr + n2 <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += n2; \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + /* Note that reordering is explicitly allowed in the x64 ABI. */ \ + if (n <= 2 && ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_ARM +/* -- ARM calling conventions --------------------------------------------- */ + +#if LJ_ABI_SOFTFP + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size <= 4 in a GPR. */ \ + cc->retref = !(sz <= 4); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + cc->retref = 1; /* Return all complex values by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET2 \ + UNUSED(dp); /* Nothing to do. */ + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG_FP1 +#define CCALL_HANDLE_REGARG_FP2 + +#else + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = !ccall_classify_struct(cts, ctr, ct); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_STRUCTRET2 \ + if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \ + memcpy(dp, sp, ctr->size); + +#define CCALL_HANDLE_COMPLEXRET \ + if (!(ct->info & CTF_VARARG)) cc->retref = 0; /* Return complex in FPRs. */ + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size); + +#define CCALL_HANDLE_STRUCTARG \ + isfp = (ccall_classify_struct(cts, d, ct) > 1); + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 1; /* Pass complex by value in FPRs or on stack. */ + +#define CCALL_HANDLE_REGARG_FP1 \ + if (isfp && !(ct->info & CTF_VARARG)) { \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \ + if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += (n >> 1); \ + goto done; \ + } \ + } else { \ + if (sz > 1 && fprodd != nfpr) fprodd = 0; \ + if (fprodd) { \ + if (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \ + dp = (void *)&cc->fpr[fprodd-1].f[1]; \ + nfpr += (n >> 1); \ + if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \ + goto done; \ + } \ + } else { \ + if (2*nfpr+n <= 2*CCALL_NARG_FPR) { \ + dp = (void *)&cc->fpr[nfpr]; \ + nfpr += (n >> 1); \ + if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \ + goto done; \ + } \ + } \ + } \ + fprodd = 0; /* No reordering after the first FP value is on stack. */ \ + } else { + +#define CCALL_HANDLE_REGARG_FP2 } + +#endif + +#define CCALL_HANDLE_REGARG \ + CCALL_HANDLE_REGARG_FP1 \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \ + if (ngpr < maxgpr) \ + ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + } \ + if (ngpr < maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + if (ngpr + n > maxgpr) { \ + nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \ + if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \ + ngpr = maxgpr; \ + } else { \ + ngpr += n; \ + } \ + goto done; \ + } CCALL_HANDLE_REGARG_FP2 + +#define CCALL_HANDLE_RET \ + if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0]; + +#elif LJ_TARGET_PPC +/* -- PPC calling conventions --------------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 2 or 4 GPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all structs by reference. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp) { /* Try to pass argument in FPRs. */ \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += 1; \ + d = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + if (n > 1) { \ + lua_assert(n == 2 || n == 4); /* int64_t or complex (float). */ \ + if (ctype_isinteger(d->info)) \ + ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \ + else if (ngpr + n > maxgpr) \ + ngpr = maxgpr; /* Prevent reordering. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CCALL_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + ctr = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ + +#elif LJ_TARGET_PPCSPE +/* -- PPC/SPE calling conventions ----------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 2 or 4 GPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all structs by reference. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +/* PPC/SPE has a softfp ABI. */ +#define CCALL_HANDLE_REGARG \ + if (n > 1) { /* Doesn't fit in a single GPR? */ \ + lua_assert(n == 2 || n == 4); /* int64_t, double or complex (float). */ \ + if (n == 2) \ + ngpr = (ngpr + 1u) & ~1u; /* Only align 64 bit value to regpair. */ \ + else if (ngpr + n > maxgpr) \ + ngpr = maxgpr; /* Prevent reordering. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } + +#elif LJ_TARGET_MIPS +/* -- MIPS calling conventions -------------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 1 or 2 FPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPRs. */ \ + ((float *)dp)[0] = cc->fpr[0].f; \ + ((float *)dp)[1] = cc->fpr[1].f; \ + } else { /* Copy complex double from FPRs. */ \ + ((double *)dp)[0] = cc->fpr[0].d; \ + ((double *)dp)[1] = cc->fpr[1].d; \ + } + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \ + /* Try to pass argument in FPRs. */ \ + dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \ + nfpr++; ngpr += n; \ + goto done; \ + } else { /* Try to pass argument in GPRs. */ \ + nfpr = CCALL_NARG_FPR; \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \ + ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr < maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + if (ngpr + n > maxgpr) { \ + nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \ + if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \ + ngpr = maxgpr; \ + } else { \ + ngpr += n; \ + } \ + goto done; \ + } \ + } + +#define CCALL_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + sp = (uint8_t *)&cc->fpr[0].f; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +#ifndef CCALL_HANDLE_STRUCTRET2 +#define CCALL_HANDLE_STRUCTRET2 \ + memcpy(dp, sp, ctr->size); /* Copy struct return value from GPRs. */ +#endif + +/* -- x86 OSX ABI struct classification ----------------------------------- */ + +#if LJ_TARGET_X86 && LJ_TARGET_OSX + +/* Check for struct with single FP field. */ +static int ccall_classify_struct(CTState *cts, CType *ct) +{ + CTSize sz = ct->size; + if (!(sz == sizeof(float) || sz == sizeof(double))) return 0; + if ((ct->info & CTF_UNION)) return 0; + while (ct->sib) { + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + CType *sct = ctype_rawchild(cts, ct); + if (ctype_isfp(sct->info)) { + if (sct->size == sz) + return (sz >> 2); /* Return 1 for float or 2 for double. */ + } else if (ctype_isstruct(sct->info)) { + if (sct->size) + return ccall_classify_struct(cts, sct); + } else { + break; + } + } else if (ctype_isbitfield(ct->info)) { + break; + } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + CType *sct = ctype_rawchild(cts, ct); + if (sct->size) + return ccall_classify_struct(cts, sct); + } + } + return 0; +} + +#endif + +/* -- x64 struct classification ------------------------------------------- */ + +#if LJ_TARGET_X64 && !LJ_ABI_WIN + +/* Register classes for x64 struct classification. */ +#define CCALL_RCL_INT 1 +#define CCALL_RCL_SSE 2 +#define CCALL_RCL_MEM 4 +/* NYI: classify vectors. */ + +static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs); + +/* Classify a C type. */ +static void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs) +{ + if (ctype_isarray(ct->info)) { + CType *cct = ctype_rawchild(cts, ct); + CTSize eofs, esz = cct->size, asz = ct->size; + for (eofs = 0; eofs < asz; eofs += esz) + ccall_classify_ct(cts, cct, rcl, ofs+eofs); + } else if (ctype_isstruct(ct->info)) { + ccall_classify_struct(cts, ct, rcl, ofs); + } else { + int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT; + lua_assert(ctype_hassize(ct->info)); + if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM; /* Unaligned. */ + rcl[(ofs >= 8)] |= cl; + } +} + +/* Recursively classify a struct based on its fields. */ +static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs) +{ + if (ct->size > 16) return CCALL_RCL_MEM; /* Too big, gets memory class. */ + while (ct->sib) { + CTSize fofs; + ct = ctype_get(cts, ct->sib); + fofs = ofs+ct->size; + if (ctype_isfield(ct->info)) + ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs); + else if (ctype_isbitfield(ct->info)) + rcl[(fofs >= 8)] |= CCALL_RCL_INT; /* NYI: unaligned bitfields? */ + else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) + ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs); + } + return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM); /* Memory class? */ +} + +/* Try to split up a small struct into registers. */ +static int ccall_struct_reg(CCallState *cc, GPRArg *dp, int *rcl) +{ + MSize ngpr = cc->ngpr, nfpr = cc->nfpr; + uint32_t i; + for (i = 0; i < 2; i++) { + lua_assert(!(rcl[i] & CCALL_RCL_MEM)); + if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */ + if (ngpr >= CCALL_NARG_GPR) return 1; /* Register overflow. */ + cc->gpr[ngpr++] = dp[i]; + } else if ((rcl[i] & CCALL_RCL_SSE)) { + if (nfpr >= CCALL_NARG_FPR) return 1; /* Register overflow. */ + cc->fpr[nfpr++].l[0] = dp[i]; + } + } + cc->ngpr = ngpr; cc->nfpr = nfpr; + return 0; /* Ok. */ +} + +/* Pass a small struct argument. */ +static int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl, + TValue *o, int narg) +{ + GPRArg dp[2]; + dp[0] = dp[1] = 0; + /* Convert to temp. struct. */ + lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg)); + if (ccall_struct_reg(cc, dp, rcl)) { /* Register overflow? Pass on stack. */ + MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1; + if (nsp + n > CCALL_MAXSTACK) return 1; /* Too many arguments. */ + cc->nsp = nsp + n; + memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR); + } + return 0; /* Ok. */ +} + +/* Combine returned small struct. */ +static void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz) +{ + GPRArg sp[2]; + MSize ngpr = 0, nfpr = 0; + uint32_t i; + for (i = 0; i < 2; i++) { + if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */ + sp[i] = cc->gpr[ngpr++]; + } else if ((rcl[i] & CCALL_RCL_SSE)) { + sp[i] = cc->fpr[nfpr++].l[0]; + } + } + memcpy(dp, sp, sz); +} +#endif + +/* -- ARM hard-float ABI struct classification ---------------------------- */ + +#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP + +/* Classify a struct based on its fields. */ +static unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf) +{ + CTSize sz = ct->size; + unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION); + if ((ctf->info & CTF_VARARG)) goto noth; + while (ct->sib) { + CType *sct; + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + sct = ctype_rawchild(cts, ct); + if (ctype_isfp(sct->info)) { + r |= sct->size; + if (!isu) n++; else if (n == 0) n = 1; + } else if (ctype_iscomplex(sct->info)) { + r |= (sct->size >> 1); + if (!isu) n += 2; else if (n < 2) n = 2; + } else if (ctype_isstruct(sct->info)) { + goto substruct; + } else { + goto noth; + } + } else if (ctype_isbitfield(ct->info)) { + goto noth; + } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + sct = ctype_rawchild(cts, ct); + substruct: + if (sct->size > 0) { + unsigned int s = ccall_classify_struct(cts, sct, ctf); + if (s <= 1) goto noth; + r |= (s & 255); + if (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8); + } + } + } + if ((r == 4 || r == 8) && n <= 4) + return r + (n << 8); +noth: /* Not a homogeneous float/double aggregate. */ + return (sz <= 4); /* Return structs of size <= 4 in a GPR. */ +} + +#endif + +/* -- Common C call handling ---------------------------------------------- */ + +/* Infer the destination CTypeID for a vararg argument. */ +CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o) +{ + if (tvisnumber(o)) { + return CTID_DOUBLE; + } else if (tviscdata(o)) { + CTypeID id = cdataV(o)->ctypeid; + CType *s = ctype_get(cts, id); + if (ctype_isrefarray(s->info)) { + return lj_ctype_intern(cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR); + } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) { + /* NYI: how to pass a struct by value in a vararg argument? */ + return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR); + } else if (ctype_isfp(s->info) && s->size == sizeof(float)) { + return CTID_DOUBLE; + } else { + return id; + } + } else if (tvisstr(o)) { + return CTID_P_CCHAR; + } else if (tvisbool(o)) { + return CTID_BOOL; + } else { + return CTID_P_VOID; + } +} + +/* Setup arguments for C call. */ +static int ccall_set_args(lua_State *L, CTState *cts, CType *ct, + CCallState *cc) +{ + int gcsteps = 0; + TValue *o, *top = L->top; + CTypeID fid; + CType *ctr; + MSize maxgpr, ngpr = 0, nsp = 0, narg; +#if CCALL_NARG_FPR + MSize nfpr = 0; +#if LJ_TARGET_ARM + MSize fprodd = 0; +#endif +#endif + + /* Clear unused regs to get some determinism in case of misdeclaration. */ + memset(cc->gpr, 0, sizeof(cc->gpr)); +#if CCALL_NUM_FPR + memset(cc->fpr, 0, sizeof(cc->fpr)); +#endif + +#if LJ_TARGET_X86 + /* x86 has several different calling conventions. */ + cc->resx87 = 0; + switch (ctype_cconv(ct->info)) { + case CTCC_FASTCALL: maxgpr = 2; break; + case CTCC_THISCALL: maxgpr = 1; break; + default: maxgpr = 0; break; + } +#else + maxgpr = CCALL_NARG_GPR; +#endif + + /* Perform required setup for some result types. */ + ctr = ctype_rawchild(cts, ct); + if (ctype_isvector(ctr->info)) { + if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16))) + goto err_nyi; + } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) { + /* Preallocate cdata object and anchor it after arguments. */ + CTSize sz = ctr->size; + GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz); + void *dp = cdataptr(cd); + setcdataV(L, L->top++, cd); + if (ctype_isstruct(ctr->info)) { + CCALL_HANDLE_STRUCTRET + } else { + CCALL_HANDLE_COMPLEXRET + } +#if LJ_TARGET_X86 + } else if (ctype_isfp(ctr->info)) { + cc->resx87 = ctr->size == sizeof(float) ? 1 : 2; +#endif + } + + /* Skip initial attributes. */ + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) break; + fid = ctf->sib; + } + + /* Walk through all passed arguments. */ + for (o = L->base+1, narg = 1; o < top; o++, narg++) { + CTypeID did; + CType *d; + CTSize sz; + MSize n, isfp = 0, isva = 0; + void *dp, *rp = NULL; + + if (fid) { /* Get argument type from field. */ + CType *ctf = ctype_get(cts, fid); + fid = ctf->sib; + lua_assert(ctype_isfield(ctf->info)); + did = ctype_cid(ctf->info); + } else { + if (!(ct->info & CTF_VARARG)) + lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too many arguments. */ + did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */ + isva = 1; + } + d = ctype_raw(cts, did); + sz = d->size; + + /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */ + if (ctype_isnum(d->info)) { + if (sz > 8) goto err_nyi; + if ((d->info & CTF_FP)) + isfp = 1; + } else if (ctype_isvector(d->info)) { + if (CCALL_VECTOR_REG && (sz == 8 || sz == 16)) + isfp = 1; + else + goto err_nyi; + } else if (ctype_isstruct(d->info)) { + CCALL_HANDLE_STRUCTARG + } else if (ctype_iscomplex(d->info)) { + CCALL_HANDLE_COMPLEXARG + } else { + sz = CTSIZE_PTR; + } + sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1); + n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */ + + CCALL_HANDLE_REGARG /* Handle register arguments. */ + + /* Otherwise pass argument on stack. */ + if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) { + MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1; + nsp = (nsp + align) & ~align; /* Align argument on stack. */ + } + if (nsp + n > CCALL_MAXSTACK) { /* Too many arguments. */ + err_nyi: + lj_err_caller(L, LJ_ERR_FFI_NYICALL); + } + dp = &cc->stack[nsp]; + nsp += n; + isva = 0; + + done: + if (rp) { /* Pass by reference. */ + gcsteps++; + *(void **)dp = rp; + dp = rp; + } + lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg)); + /* Extend passed integers to 32 bits at least. */ + if (ctype_isinteger_or_bool(d->info) && d->size < 4) { + if (d->info & CTF_UNSIGNED) + *(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp : + (uint32_t)*(uint16_t *)dp; + else + *(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp : + (int32_t)*(int16_t *)dp; + } +#if LJ_TARGET_X64 && LJ_ABI_WIN + if (isva) { /* Windows/x64 mirrors varargs in both register sets. */ + if (nfpr == ngpr) + cc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0]; + else + cc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1]; + } +#else + UNUSED(isva); +#endif +#if LJ_TARGET_X64 && !LJ_ABI_WIN + if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) { + cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1]; /* Split complex double. */ + cc->fpr[nfpr-2].d[1] = 0; + } +#else + UNUSED(isfp); +#endif + } + if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too few arguments. */ + +#if LJ_TARGET_X64 || LJ_TARGET_PPC + cc->nfpr = nfpr; /* Required for vararg functions. */ +#endif + cc->nsp = nsp; + cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR; + if (nsp > CCALL_SPS_FREE) + cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u); + return gcsteps; +} + +/* Get results from C call. */ +static int ccall_get_results(lua_State *L, CTState *cts, CType *ct, + CCallState *cc, int *ret) +{ + CType *ctr = ctype_rawchild(cts, ct); + uint8_t *sp = (uint8_t *)&cc->gpr[0]; + if (ctype_isvoid(ctr->info)) { + *ret = 0; /* Zero results. */ + return 0; /* No additional GC step. */ + } + *ret = 1; /* One result. */ + if (ctype_isstruct(ctr->info)) { + /* Return cdata object which is already on top of stack. */ + if (!cc->retref) { + void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */ + CCALL_HANDLE_STRUCTRET2 + } + return 1; /* One GC step. */ + } + if (ctype_iscomplex(ctr->info)) { + /* Return cdata object which is already on top of stack. */ + void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */ + CCALL_HANDLE_COMPLEXRET2 + return 1; /* One GC step. */ + } + if (LJ_BE && ctype_isinteger_or_bool(ctr->info) && ctr->size < CTSIZE_PTR) + sp += (CTSIZE_PTR - ctr->size); +#if CCALL_NUM_FPR + if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info)) + sp = (uint8_t *)&cc->fpr[0]; +#endif +#ifdef CCALL_HANDLE_RET + CCALL_HANDLE_RET +#endif + /* No reference types end up here, so there's no need for the CTypeID. */ + lua_assert(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info))); + return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp); +} + +/* Call C function. */ +int lj_ccall_func(lua_State *L, GCcdata *cd) +{ + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, cd->ctypeid); + CTSize sz = CTSIZE_PTR; + if (ctype_isptr(ct->info)) { + sz = ct->size; + ct = ctype_rawchild(cts, ct); + } + if (ctype_isfunc(ct->info)) { + CCallState cc; + int gcsteps, ret; + cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz); + gcsteps = ccall_set_args(L, cts, ct, &cc); + ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab); + cts->cb.slot = ~0u; + lj_vm_ffi_call(&cc); + if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */ + TValue tv; + setlightudV(&tv, (void *)cc.func); + setboolV(lj_tab_set(L, cts->miscmap, &tv), 1); + } + ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab); /* May be reallocated. */ + gcsteps += ccall_get_results(L, cts, ct, &cc, &ret); +#if LJ_TARGET_X86 && LJ_ABI_WIN + /* Automatically detect __stdcall and fix up C function declaration. */ + if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) { + CTF_INSERT(ct->info, CCONV, CTCC_STDCALL); + lj_trace_abort(G(L)); + } +#endif + while (gcsteps-- > 0) + lj_gc_check(L); + return ret; + } + return -1; /* Not a function. */ +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.h new file mode 100644 index 0000000..c3ea9e6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccall.h @@ -0,0 +1,171 @@ +/* +** FFI C call handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCALL_H +#define _LJ_CCALL_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* -- C calling conventions ----------------------------------------------- */ + +#if LJ_TARGET_X86ORX64 + +#if LJ_TARGET_X86 +#define CCALL_NARG_GPR 2 /* For fastcall arguments. */ +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 1 /* For FP results on x87 stack. */ +#define CCALL_ALIGN_STACKARG 0 /* Don't align argument on stack. */ +#elif LJ_ABI_WIN +#define CCALL_NARG_GPR 4 +#define CCALL_NARG_FPR 4 +#define CCALL_NRET_GPR 1 +#define CCALL_NRET_FPR 1 +#define CCALL_SPS_EXTRA 4 +#else +#define CCALL_NARG_GPR 6 +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 2 +#define CCALL_VECTOR_REG 1 /* Pass vectors in registers. */ +#endif + +#define CCALL_SPS_FREE 1 +#define CCALL_ALIGN_CALLSTATE 16 + +typedef LJ_ALIGN(16) union FPRArg { + double d[2]; + float f[4]; + uint8_t b[16]; + uint16_t s[8]; + int i[4]; + int64_t l[2]; +} FPRArg; + +typedef intptr_t GPRArg; + +#elif LJ_TARGET_ARM + +#define CCALL_NARG_GPR 4 +#define CCALL_NRET_GPR 2 /* For softfp double. */ +#if LJ_ABI_SOFTFP +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_FPR 0 +#else +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_FPR 4 +#endif +#define CCALL_SPS_FREE 0 + +typedef intptr_t GPRArg; +typedef union FPRArg { + double d; + float f[2]; +} FPRArg; + +#elif LJ_TARGET_PPC + +#define CCALL_NARG_GPR 8 +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_GPR 4 /* For complex double. */ +#define CCALL_NRET_FPR 1 +#define CCALL_SPS_EXTRA 4 +#define CCALL_SPS_FREE 0 + +typedef intptr_t GPRArg; +typedef double FPRArg; + +#elif LJ_TARGET_PPCSPE + +#define CCALL_NARG_GPR 8 +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_GPR 4 /* For softfp complex double. */ +#define CCALL_NRET_FPR 0 +#define CCALL_SPS_FREE 0 /* NYI */ + +typedef intptr_t GPRArg; + +#elif LJ_TARGET_MIPS + +#define CCALL_NARG_GPR 4 +#define CCALL_NARG_FPR 2 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 2 +#define CCALL_SPS_EXTRA 7 +#define CCALL_SPS_FREE 1 + +typedef intptr_t GPRArg; +typedef union FPRArg { + double d; + struct { LJ_ENDIAN_LOHI(float f; , float g;) }; +} FPRArg; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +#ifndef CCALL_SPS_EXTRA +#define CCALL_SPS_EXTRA 0 +#endif +#ifndef CCALL_VECTOR_REG +#define CCALL_VECTOR_REG 0 +#endif +#ifndef CCALL_ALIGN_STACKARG +#define CCALL_ALIGN_STACKARG 1 +#endif +#ifndef CCALL_ALIGN_CALLSTATE +#define CCALL_ALIGN_CALLSTATE 8 +#endif + +#define CCALL_NUM_GPR \ + (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR) +#define CCALL_NUM_FPR \ + (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR) + +/* Check against constants in lj_ctype.h. */ +LJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR); +LJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR); + +#define CCALL_MAXSTACK 32 + +/* -- C call state -------------------------------------------------------- */ + +typedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState { + void (*func)(void); /* Pointer to called function. */ + uint32_t spadj; /* Stack pointer adjustment. */ + uint8_t nsp; /* Number of stack slots. */ + uint8_t retref; /* Return value by reference. */ +#if LJ_TARGET_X64 + uint8_t ngpr; /* Number of arguments in GPRs. */ + uint8_t nfpr; /* Number of arguments in FPRs. */ +#elif LJ_TARGET_X86 + uint8_t resx87; /* Result on x87 stack: 1:float, 2:double. */ +#elif LJ_TARGET_PPC + uint8_t nfpr; /* Number of arguments in FPRs. */ +#endif +#if LJ_32 + int32_t align1; +#endif +#if CCALL_NUM_FPR + FPRArg fpr[CCALL_NUM_FPR]; /* Arguments/results in FPRs. */ +#endif + GPRArg gpr[CCALL_NUM_GPR]; /* Arguments/results in GPRs. */ + GPRArg stack[CCALL_MAXSTACK]; /* Stack slots. */ +} CCallState; + +/* -- C call handling ----------------------------------------------------- */ + +/* Really belongs to lj_vm.h. */ +LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc); + +LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o); +LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.c new file mode 100644 index 0000000..d872d67 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.c @@ -0,0 +1,644 @@ +/* +** FFI C callback handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_ccall.h" +#include "lj_ccallback.h" +#include "lj_target.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* -- Target-specific handling of callback slots -------------------------- */ + +#define CALLBACK_MCODE_SIZE (LJ_PAGESIZE * LJ_NUM_CBPAGE) + +#if LJ_OS_NOJIT + +/* Disabled callback support. */ +#define CALLBACK_SLOT2OFS(slot) (0*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) +#define CALLBACK_MAX_SLOT 0 + +#elif LJ_TARGET_X86ORX64 + +#define CALLBACK_MCODE_HEAD (LJ_64 ? 8 : 0) +#define CALLBACK_MCODE_GROUP (-2+1+2+5+(LJ_64 ? 6 : 5)) + +#define CALLBACK_SLOT2OFS(slot) \ + (CALLBACK_MCODE_HEAD + CALLBACK_MCODE_GROUP*((slot)/32) + 4*(slot)) + +static MSize CALLBACK_OFS2SLOT(MSize ofs) +{ + MSize group; + ofs -= CALLBACK_MCODE_HEAD; + group = ofs / (32*4 + CALLBACK_MCODE_GROUP); + return (ofs % (32*4 + CALLBACK_MCODE_GROUP))/4 + group*32; +} + +#define CALLBACK_MAX_SLOT \ + (((CALLBACK_MCODE_SIZE-CALLBACK_MCODE_HEAD)/(CALLBACK_MCODE_GROUP+4*32))*32) + +#elif LJ_TARGET_ARM + +#define CALLBACK_MCODE_HEAD 32 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#elif LJ_TARGET_PPC + +#define CALLBACK_MCODE_HEAD 24 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#elif LJ_TARGET_MIPS + +#define CALLBACK_MCODE_HEAD 24 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#else + +/* Missing support for this architecture. */ +#define CALLBACK_SLOT2OFS(slot) (0*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) +#define CALLBACK_MAX_SLOT 0 + +#endif + +/* Convert callback slot number to callback function pointer. */ +static void *callback_slot2ptr(CTState *cts, MSize slot) +{ + return (uint8_t *)cts->cb.mcode + CALLBACK_SLOT2OFS(slot); +} + +/* Convert callback function pointer to slot number. */ +MSize lj_ccallback_ptr2slot(CTState *cts, void *p) +{ + uintptr_t ofs = (uintptr_t)((uint8_t *)p -(uint8_t *)cts->cb.mcode); + if (ofs < CALLBACK_MCODE_SIZE) { + MSize slot = CALLBACK_OFS2SLOT((MSize)ofs); + if (CALLBACK_SLOT2OFS(slot) == (MSize)ofs) + return slot; + } + return ~0u; /* Not a known callback function pointer. */ +} + +/* Initialize machine code for callback function pointers. */ +#if LJ_OS_NOJIT +/* Disabled callback support. */ +#define callback_mcode_init(g, p) UNUSED(p) +#elif LJ_TARGET_X86ORX64 +static void callback_mcode_init(global_State *g, uint8_t *page) +{ + uint8_t *p = page; + uint8_t *target = (uint8_t *)(void *)lj_vm_ffi_callback; + MSize slot; +#if LJ_64 + *(void **)p = target; p += 8; +#endif + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + /* mov al, slot; jmp group */ + *p++ = XI_MOVrib | RID_EAX; *p++ = (uint8_t)slot; + if ((slot & 31) == 31 || slot == CALLBACK_MAX_SLOT-1) { + /* push ebp/rbp; mov ah, slot>>8; mov ebp, &g. */ + *p++ = XI_PUSH + RID_EBP; + *p++ = XI_MOVrib | (RID_EAX+4); *p++ = (uint8_t)(slot >> 8); + *p++ = XI_MOVri | RID_EBP; + *(int32_t *)p = i32ptr(g); p += 4; +#if LJ_64 + /* jmp [rip-pageofs] where lj_vm_ffi_callback is stored. */ + *p++ = XI_GROUP5; *p++ = XM_OFS0 + (XOg_JMP<<3) + RID_EBP; + *(int32_t *)p = (int32_t)(page-(p+4)); p += 4; +#else + /* jmp lj_vm_ffi_callback. */ + *p++ = XI_JMP; *(int32_t *)p = target-(p+4); p += 4; +#endif + } else { + *p++ = XI_JMPs; *p++ = (uint8_t)((2+2)*(31-(slot&31)) - 2); + } + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_ARM +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + /* This must match with the saveregs macro in buildvm_arm.dasc. */ + *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC); + *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR); + *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD; + *p++ = ARMI_STR|ARMI_LS_P|ARMI_LS_W|ARMF_D(RID_R12)|ARMF_N(RID_SP)|(CFRAME_SIZE-4*9); + *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_R12)|ARMF_N(RID_PC); + *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_PC)|ARMF_N(RID_PC); + *p++ = u32ptr(g); + *p++ = u32ptr(target); + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p++ = ARMI_MOV|ARMF_D(RID_R12)|ARMF_M(RID_PC); + *p = ARMI_B | ((page-p-2) & 0x00ffffffu); + p++; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_PPC +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + *p++ = PPCI_LIS | PPCF_T(RID_TMP) | (u32ptr(target) >> 16); + *p++ = PPCI_LIS | PPCF_T(RID_R12) | (u32ptr(g) >> 16); + *p++ = PPCI_ORI | PPCF_A(RID_TMP)|PPCF_T(RID_TMP) | (u32ptr(target) & 0xffff); + *p++ = PPCI_ORI | PPCF_A(RID_R12)|PPCF_T(RID_R12) | (u32ptr(g) & 0xffff); + *p++ = PPCI_MTCTR | PPCF_T(RID_TMP); + *p++ = PPCI_BCTR; + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p++ = PPCI_LI | PPCF_T(RID_R11) | slot; + *p = PPCI_B | (((page-p) & 0x00ffffffu) << 2); + p++; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_MIPS +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + *p++ = MIPSI_SW | MIPSF_T(RID_R1)|MIPSF_S(RID_SP) | 0; + *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (u32ptr(target) >> 16); + *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (u32ptr(g) >> 16); + *p++ = MIPSI_ORI | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) |(u32ptr(target)&0xffff); + *p++ = MIPSI_JR | MIPSF_S(RID_R3); + *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (u32ptr(g)&0xffff); + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p = MIPSI_B | ((page-p-1) & 0x0000ffffu); + p++; + *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#else +/* Missing support for this architecture. */ +#define callback_mcode_init(g, p) UNUSED(p) +#endif + +/* -- Machine code management --------------------------------------------- */ + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#elif LJ_TARGET_POSIX + +#include +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +#endif + +/* Allocate and initialize area for callback function pointers. */ +static void callback_mcode_new(CTState *cts) +{ + size_t sz = (size_t)CALLBACK_MCODE_SIZE; + void *p; + if (CALLBACK_MAX_SLOT == 0) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#if LJ_TARGET_WINDOWS + p = VirtualAlloc(NULL, sz, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + if (!p) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#elif LJ_TARGET_POSIX + p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS, + -1, 0); + if (p == MAP_FAILED) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#else + /* Fallback allocator. Fails if memory is not executable by default. */ + p = lj_mem_new(cts->L, sz); +#endif + cts->cb.mcode = p; + callback_mcode_init(cts->g, p); + lj_mcode_sync(p, (char *)p + sz); +#if LJ_TARGET_WINDOWS + { + DWORD oprot; + VirtualProtect(p, sz, PAGE_EXECUTE_READ, &oprot); + } +#elif LJ_TARGET_POSIX + mprotect(p, sz, (PROT_READ|PROT_EXEC)); +#endif +} + +/* Free area for callback function pointers. */ +void lj_ccallback_mcode_free(CTState *cts) +{ + size_t sz = (size_t)CALLBACK_MCODE_SIZE; + void *p = cts->cb.mcode; + if (p == NULL) return; +#if LJ_TARGET_WINDOWS + VirtualFree(p, 0, MEM_RELEASE); + UNUSED(sz); +#elif LJ_TARGET_POSIX + munmap(p, sz); +#else + lj_mem_free(cts->g, p, sz); +#endif +} + +/* -- C callback entry ---------------------------------------------------- */ + +/* Target-specific handling of register arguments. Similar to lj_ccall.c. */ +#if LJ_TARGET_X86 + +#define CALLBACK_HANDLE_REGARG \ + if (!isfp) { /* Only non-FP values may be passed in registers. */ \ + if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \ + if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \ + } else if (ngpr + 1 <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_X64 && LJ_ABI_WIN + +/* Windows/x64 argument registers are strictly positional (use ngpr). */ +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (ngpr < maxgpr) { sp = &cts->cb.fpr[ngpr++]; UNUSED(nfpr); goto done; } \ + } else { \ + if (ngpr < maxgpr) { sp = &cts->cb.gpr[ngpr++]; goto done; } \ + } + +#elif LJ_TARGET_X64 + +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (nfpr + n <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr]; \ + nfpr += n; \ + goto done; \ + } \ + } else { \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_ARM + +#if LJ_ABI_SOFTFP + +#define CALLBACK_HANDLE_REGARG_FP1 UNUSED(isfp); +#define CALLBACK_HANDLE_REGARG_FP2 + +#else + +#define CALLBACK_HANDLE_REGARG_FP1 \ + if (isfp) { \ + if (n == 1) { \ + if (fprodd) { \ + sp = &cts->cb.fpr[fprodd-1]; \ + fprodd = 0; \ + goto done; \ + } else if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + fprodd = nfpr; \ + goto done; \ + } \ + } else { \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + goto done; \ + } \ + } \ + fprodd = 0; /* No reordering after the first FP value is on stack. */ \ + } else { + +#define CALLBACK_HANDLE_REGARG_FP2 } + +#endif + +#define CALLBACK_HANDLE_REGARG \ + CALLBACK_HANDLE_REGARG_FP1 \ + if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } CALLBACK_HANDLE_REGARG_FP2 + +#elif LJ_TARGET_PPC + +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + cta = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + if (n > 1) { \ + lua_assert(ctype_isinteger(cta->info) && n == 2); /* int64_t. */ \ + ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CALLBACK_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + *(double *)dp = *(float *)dp; /* FPRs always hold doubles. */ + +#elif LJ_TARGET_MIPS + +#define CALLBACK_HANDLE_REGARG \ + if (isfp && nfpr < CCALL_NARG_FPR) { /* Try to pass argument in FPRs. */ \ + sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \ + nfpr++; ngpr += n; \ + goto done; \ + } else { /* Try to pass argument in GPRs. */ \ + nfpr = CCALL_NARG_FPR; \ + if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CALLBACK_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + ((float *)dp)[1] = *(float *)dp; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +/* Convert and push callback arguments to Lua stack. */ +static void callback_conv_args(CTState *cts, lua_State *L) +{ + TValue *o = L->top; + intptr_t *stack = cts->cb.stack; + MSize slot = cts->cb.slot; + CTypeID id = 0, rid, fid; + int gcsteps = 0; + CType *ct; + GCfunc *fn; + MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR; +#if CCALL_NARG_FPR + MSize nfpr = 0; +#if LJ_TARGET_ARM + MSize fprodd = 0; +#endif +#endif + + if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) { + ct = ctype_get(cts, id); + rid = ctype_cid(ct->info); + fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot)); + } else { /* Must set up frame first, before throwing the error. */ + ct = NULL; + rid = 0; + fn = (GCfunc *)L; + } + o->u32.lo = LJ_CONT_FFI_CALLBACK; /* Continuation returns from callback. */ + o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */ + o++; + setframe_gc(o, obj2gco(fn)); + setframe_ftsz(o, (int)((char *)(o+1) - (char *)L->base) + FRAME_CONT); + L->top = L->base = ++o; + if (!ct) + lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK); + if (isluafunc(fn)) + setcframe_pc(L->cframe, proto_bc(funcproto(fn))+1); + lj_state_checkstack(L, LUA_MINSTACK); /* May throw. */ + o = L->base; /* Might have been reallocated. */ + +#if LJ_TARGET_X86 + /* x86 has several different calling conventions. */ + switch (ctype_cconv(ct->info)) { + case CTCC_FASTCALL: maxgpr = 2; break; + case CTCC_THISCALL: maxgpr = 1; break; + default: maxgpr = 0; break; + } +#endif + + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) { + CType *cta; + void *sp; + CTSize sz; + int isfp; + MSize n; + lua_assert(ctype_isfield(ctf->info)); + cta = ctype_rawchild(cts, ctf); + isfp = ctype_isfp(cta->info); + sz = (cta->size + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1); + n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */ + + CALLBACK_HANDLE_REGARG /* Handle register arguments. */ + + /* Otherwise pass argument on stack. */ + if (CCALL_ALIGN_STACKARG && LJ_32 && sz == 8) + nsp = (nsp + 1) & ~1u; /* Align 64 bit argument on stack. */ + sp = &stack[nsp]; + nsp += n; + + done: + if (LJ_BE && cta->size < CTSIZE_PTR) + sp = (void *)((uint8_t *)sp + CTSIZE_PTR-cta->size); + gcsteps += lj_cconv_tv_ct(cts, cta, 0, o++, sp); + } + fid = ctf->sib; + } + L->top = o; +#if LJ_TARGET_X86 + /* Store stack adjustment for returns from non-cdecl callbacks. */ + if (ctype_cconv(ct->info) != CTCC_CDECL) + (L->base-2)->u32.hi |= (nsp << (16+2)); +#endif + while (gcsteps-- > 0) + lj_gc_check(L); +} + +/* Convert Lua object to callback result. */ +static void callback_conv_result(CTState *cts, lua_State *L, TValue *o) +{ + CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi); +#if LJ_TARGET_X86 + cts->cb.gpr[2] = 0; +#endif + if (!ctype_isvoid(ctr->info)) { + uint8_t *dp = (uint8_t *)&cts->cb.gpr[0]; +#if CCALL_NUM_FPR + if (ctype_isfp(ctr->info)) + dp = (uint8_t *)&cts->cb.fpr[0]; +#endif + lj_cconv_ct_tv(cts, ctr, dp, o, 0); +#ifdef CALLBACK_HANDLE_RET + CALLBACK_HANDLE_RET +#endif + /* Extend returned integers to (at least) 32 bits. */ + if (ctype_isinteger_or_bool(ctr->info) && ctr->size < 4) { + if (ctr->info & CTF_UNSIGNED) + *(uint32_t *)dp = ctr->size == 1 ? (uint32_t)*(uint8_t *)dp : + (uint32_t)*(uint16_t *)dp; + else + *(int32_t *)dp = ctr->size == 1 ? (int32_t)*(int8_t *)dp : + (int32_t)*(int16_t *)dp; + } +#if LJ_TARGET_X86 + if (ctype_isfp(ctr->info)) + cts->cb.gpr[2] = ctr->size == sizeof(float) ? 1 : 2; +#endif + } +} + +/* Enter callback. */ +lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf) +{ + lua_State *L = cts->L; + global_State *g = cts->g; + lua_assert(L != NULL); + if (gcref(g->jit_L)) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_FFI_BADCBACK)); + if (g->panic) g->panic(L); + exit(EXIT_FAILURE); + } + lj_trace_abort(g); /* Never record across callback. */ + /* Setup C frame. */ + cframe_prev(cf) = L->cframe; + setcframe_L(cf, L); + cframe_errfunc(cf) = -1; + cframe_nres(cf) = 0; + L->cframe = cf; + callback_conv_args(cts, L); + return L; /* Now call the function on this stack. */ +} + +/* Leave callback. */ +void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o) +{ + lua_State *L = cts->L; + GCfunc *fn; + TValue *obase = L->base; + L->base = L->top; /* Keep continuation frame for throwing errors. */ + if (o >= L->base) { + /* PC of RET* is lost. Point to last line for result conv. errors. */ + fn = curr_func(L); + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + setcframe_pc(L->cframe, proto_bc(pt)+pt->sizebc+1); + } + } + callback_conv_result(cts, L, o); + /* Finally drop C frame and continuation frame. */ + L->cframe = cframe_prev(L->cframe); + L->top -= 2; + L->base = obase; + cts->cb.slot = 0; /* Blacklist C function that called the callback. */ +} + +/* -- C callback management ----------------------------------------------- */ + +/* Get an unused slot in the callback slot table. */ +static MSize callback_slot_new(CTState *cts, CType *ct) +{ + CTypeID id = ctype_typeid(cts, ct); + CTypeID1 *cbid = cts->cb.cbid; + MSize top; + for (top = cts->cb.topid; top < cts->cb.sizeid; top++) + if (LJ_LIKELY(cbid[top] == 0)) + goto found; +#if CALLBACK_MAX_SLOT + if (top >= CALLBACK_MAX_SLOT) +#endif + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); + if (!cts->cb.mcode) + callback_mcode_new(cts); + lj_mem_growvec(cts->L, cbid, cts->cb.sizeid, CALLBACK_MAX_SLOT, CTypeID1); + cts->cb.cbid = cbid; + memset(cbid+top, 0, (cts->cb.sizeid-top)*sizeof(CTypeID1)); +found: + cbid[top] = id; + cts->cb.topid = top+1; + return top; +} + +/* Check for function pointer and supported argument/result types. */ +static CType *callback_checkfunc(CTState *cts, CType *ct) +{ + int narg = 0; + if (!ctype_isptr(ct->info) || (LJ_64 && ct->size != CTSIZE_PTR)) + return NULL; + ct = ctype_rawchild(cts, ct); + if (ctype_isfunc(ct->info)) { + CType *ctr = ctype_rawchild(cts, ct); + CTypeID fid = ct->sib; + if (!(ctype_isvoid(ctr->info) || ctype_isenum(ctr->info) || + ctype_isptr(ctr->info) || (ctype_isnum(ctr->info) && ctr->size <= 8))) + return NULL; + if ((ct->info & CTF_VARARG)) + return NULL; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) { + CType *cta; + lua_assert(ctype_isfield(ctf->info)); + cta = ctype_rawchild(cts, ctf); + if (!(ctype_isenum(cta->info) || ctype_isptr(cta->info) || + (ctype_isnum(cta->info) && cta->size <= 8)) || + ++narg >= LUA_MINSTACK-3) + return NULL; + } + fid = ctf->sib; + } + return ct; + } + return NULL; +} + +/* Create a new callback and return the callback function pointer. */ +void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn) +{ + ct = callback_checkfunc(cts, ct); + if (ct) { + MSize slot = callback_slot_new(cts, ct); + GCtab *t = cts->miscmap; + setfuncV(cts->L, lj_tab_setint(cts->L, t, (int32_t)slot), fn); + lj_gc_anybarriert(cts->L, t); + return callback_slot2ptr(cts, slot); + } + return NULL; /* Bad conversion. */ +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.h new file mode 100644 index 0000000..45b5ff0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ccallback.h @@ -0,0 +1,25 @@ +/* +** FFI C callback handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCALLBACK_H +#define _LJ_CCALLBACK_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Really belongs to lj_vm.h. */ +LJ_ASMF void lj_vm_ffi_callback(void); + +LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p); +LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf); +LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o); +LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn); +LJ_FUNC void lj_ccallback_mcode_free(CTState *cts); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.c new file mode 100644 index 0000000..de4938e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.c @@ -0,0 +1,751 @@ +/* +** C type conversions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_cconv.h" +#include "lj_ccallback.h" + +/* -- Conversion errors --------------------------------------------------- */ + +/* Bad conversion. */ +LJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s, + CTInfo flags) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + const char *src; + if ((flags & CCF_FROMTV)) + src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER : + ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)]; + else + src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL)); + if (CCF_GETARG(flags)) + lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst); + else + lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst); +} + +/* Bad conversion from TValue. */ +LJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o, + CTInfo flags) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + const char *src = lj_typename(o); + if (CCF_GETARG(flags)) + lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst); + else + lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst); +} + +/* Initializer overflow. */ +LJ_NORET static void cconv_err_initov(CTState *cts, CType *d) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst); +} + +/* -- C type compatibility checks ----------------------------------------- */ + +/* Get raw type and qualifiers for a child type. Resolves enums, too. */ +static CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual) +{ + ct = ctype_child(cts, ct); + for (;;) { + if (ctype_isattrib(ct->info)) { + if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; + } else if (!ctype_isenum(ct->info)) { + break; + } + ct = ctype_child(cts, ct); + } + *qual |= (ct->info & CTF_QUAL); + return ct; +} + +/* Check for compatible types when converting to a pointer. +** Note: these checks are more relaxed than what C99 mandates. +*/ +int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags) +{ + if (!((flags & CCF_CAST) || d == s)) { + CTInfo dqual = 0, squal = 0; + d = cconv_childqual(cts, d, &dqual); + if (!ctype_isstruct(s->info)) + s = cconv_childqual(cts, s, &squal); + if ((flags & CCF_SAME)) { + if (dqual != squal) + return 0; /* Different qualifiers. */ + } else if (!(flags & CCF_IGNQUAL)) { + if ((dqual & squal) != squal) + return 0; /* Discarded qualifiers. */ + if (ctype_isvoid(d->info) || ctype_isvoid(s->info)) + return 1; /* Converting to/from void * is always ok. */ + } + if (ctype_type(d->info) != ctype_type(s->info) || + d->size != s->size) + return 0; /* Different type or different size. */ + if (ctype_isnum(d->info)) { + if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP))) + return 0; /* Different numeric types. */ + } else if (ctype_ispointer(d->info)) { + /* Check child types for compatibility. */ + return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME); + } else if (ctype_isstruct(d->info)) { + if (d != s) + return 0; /* Must be exact same type for struct/union. */ + } else if (ctype_isfunc(d->info)) { + /* NYI: structural equality of functions. */ + } + } + return 1; /* Types are compatible. */ +} + +/* -- C type to C type conversion ----------------------------------------- */ + +/* Convert C type to C type. Caveat: expects to get the raw CType! +** +** Note: This is only used by the interpreter and not optimized at all. +** The JIT compiler will do a much better job specializing for each case. +*/ +void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, + uint8_t *dp, uint8_t *sp, CTInfo flags) +{ + CTSize dsize = d->size, ssize = s->size; + CTInfo dinfo = d->info, sinfo = s->info; + void *tmpptr; + + lua_assert(!ctype_isenum(dinfo) && !ctype_isenum(sinfo)); + lua_assert(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo)); + + if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT) + goto err_conv; + + /* Some basic sanity checks. */ + lua_assert(!ctype_isnum(dinfo) || dsize > 0); + lua_assert(!ctype_isnum(sinfo) || ssize > 0); + lua_assert(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4); + lua_assert(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4); + lua_assert(!ctype_isinteger(dinfo) || (1u< ssize) { /* Zero-extend or sign-extend LSB. */ +#if LJ_LE + uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0; + memcpy(dp, sp, ssize); + memset(dp + ssize, fill, dsize-ssize); +#else + uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0; + memset(dp, fill, dsize-ssize); + memcpy(dp + (dsize-ssize), sp, ssize); +#endif + } else { /* Copy LSB. */ +#if LJ_LE + memcpy(dp, sp, dsize); +#else + memcpy(dp, sp + (ssize-dsize), dsize); +#endif + } + break; + case CCX(I, F): { + double n; /* Always convert via double. */ + conv_I_F: + /* Convert source to double. */ + if (ssize == sizeof(double)) n = *(double *)sp; + else if (ssize == sizeof(float)) n = (double)*(float *)sp; + else goto err_conv; /* NYI: long double. */ + /* Then convert double to integer. */ + /* The conversion must exactly match the semantics of JIT-compiled code! */ + if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) { + int32_t i = (int32_t)n; + if (dsize == 4) *(int32_t *)dp = i; + else if (dsize == 2) *(int16_t *)dp = (int16_t)i; + else *(int8_t *)dp = (int8_t)i; + } else if (dsize == 4) { + *(uint32_t *)dp = (uint32_t)n; + } else if (dsize == 8) { + if (!(dinfo & CTF_UNSIGNED)) + *(int64_t *)dp = (int64_t)n; + else + *(uint64_t *)dp = lj_num2u64(n); + } else { + goto err_conv; /* NYI: conversion to >64 bit integers. */ + } + break; + } + case CCX(I, C): + s = ctype_child(cts, s); + sinfo = s->info; + ssize = s->size; + goto conv_I_F; /* Just convert re. */ + case CCX(I, P): + if (!(flags & CCF_CAST)) goto err_conv; + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + goto conv_I_I; + case CCX(I, A): + if (!(flags & CCF_CAST)) goto err_conv; + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + ssize = CTSIZE_PTR; + tmpptr = sp; + sp = (uint8_t *)&tmpptr; + goto conv_I_I; + + /* Destination is a floating-point number. */ + case CCX(F, B): + case CCX(F, I): { + double n; /* Always convert via double. */ + conv_F_I: + /* First convert source to double. */ + /* The conversion must exactly match the semantics of JIT-compiled code! */ + if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) { + int32_t i; + if (ssize == 4) { + i = *(int32_t *)sp; + } else if (!(sinfo & CTF_UNSIGNED)) { + if (ssize == 2) i = *(int16_t *)sp; + else i = *(int8_t *)sp; + } else { + if (ssize == 2) i = *(uint16_t *)sp; + else i = *(uint8_t *)sp; + } + n = (double)i; + } else if (ssize == 4) { + n = (double)*(uint32_t *)sp; + } else if (ssize == 8) { + if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp; + else n = (double)*(uint64_t *)sp; + } else { + goto err_conv; /* NYI: conversion from >64 bit integers. */ + } + /* Convert double to destination. */ + if (dsize == sizeof(double)) *(double *)dp = n; + else if (dsize == sizeof(float)) *(float *)dp = (float)n; + else goto err_conv; /* NYI: long double. */ + break; + } + case CCX(F, F): { + double n; /* Always convert via double. */ + conv_F_F: + if (ssize == dsize) goto copyval; + /* Convert source to double. */ + if (ssize == sizeof(double)) n = *(double *)sp; + else if (ssize == sizeof(float)) n = (double)*(float *)sp; + else goto err_conv; /* NYI: long double. */ + /* Convert double to destination. */ + if (dsize == sizeof(double)) *(double *)dp = n; + else if (dsize == sizeof(float)) *(float *)dp = (float)n; + else goto err_conv; /* NYI: long double. */ + break; + } + case CCX(F, C): + s = ctype_child(cts, s); + sinfo = s->info; + ssize = s->size; + goto conv_F_F; /* Ignore im, and convert from re. */ + + /* Destination is a complex number. */ + case CCX(C, I): + d = ctype_child(cts, d); + dinfo = d->info; + dsize = d->size; + memset(dp + dsize, 0, dsize); /* Clear im. */ + goto conv_F_I; /* Convert to re. */ + case CCX(C, F): + d = ctype_child(cts, d); + dinfo = d->info; + dsize = d->size; + memset(dp + dsize, 0, dsize); /* Clear im. */ + goto conv_F_F; /* Convert to re. */ + + case CCX(C, C): + if (dsize != ssize) { /* Different types: convert re/im separately. */ + CType *dc = ctype_child(cts, d); + CType *sc = ctype_child(cts, s); + lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags); + lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags); + return; + } + goto copyval; /* Otherwise this is easy. */ + + /* Destination is a vector. */ + case CCX(V, I): + case CCX(V, F): + case CCX(V, C): { + CType *dc = ctype_child(cts, d); + CTSize esize; + /* First convert the scalar to the first element. */ + lj_cconv_ct_ct(cts, dc, s, dp, sp, flags); + /* Then replicate it to the other elements (splat). */ + for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) { + dp += esize; + memcpy(dp, sp, esize); + } + break; + } + + case CCX(V, V): + /* Copy same-sized vectors, even for different lengths/element-types. */ + if (dsize != ssize) goto err_conv; + goto copyval; + + /* Destination is a pointer. */ + case CCX(P, I): + if (!(flags & CCF_CAST)) goto err_conv; + dinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + goto conv_I_I; + + case CCX(P, F): + if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv; + /* The signed conversion is cheaper. x64 really has 47 bit pointers. */ + dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED); + goto conv_I_F; + + case CCX(P, P): + if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv; + cdata_setptr(dp, dsize, cdata_getptr(sp, ssize)); + break; + + case CCX(P, A): + case CCX(P, S): + if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv; + cdata_setptr(dp, dsize, sp); + break; + + /* Destination is an array. */ + case CCX(A, A): + if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize || + d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags)) + goto err_conv; + goto copyval; + + /* Destination is a struct/union. */ + case CCX(S, S): + if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s) + goto err_conv; /* Must be exact same type. */ +copyval: /* Copy value. */ + lua_assert(dsize == ssize); + memcpy(dp, sp, dsize); + break; + + default: + err_conv: + cconv_err_conv(cts, d, s, flags); + } +} + +/* -- C type to TValue conversion ----------------------------------------- */ + +/* Convert C type to TValue. Caveat: expects to get the raw CType! */ +int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, + TValue *o, uint8_t *sp) +{ + CTInfo sinfo = s->info; + if (ctype_isnum(sinfo)) { + if (!ctype_isbool(sinfo)) { + if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; + if (LJ_DUALNUM && ctype_isinteger(sinfo)) { + int32_t i; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s, + (uint8_t *)&i, sp, 0); + if ((sinfo & CTF_UNSIGNED) && i < 0) + setnumV(o, (lua_Number)(uint32_t)i); + else + setintV(o, i); + } else { + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s, + (uint8_t *)&o->n, sp, 0); + /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ + lua_assert(tvisnum(o)); + } + } else { + uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0); + setboolV(o, b); + setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */ + } + return 0; + } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { + /* Create reference. */ + setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid)); + return 1; /* Need GC step. */ + } else { + GCcdata *cd; + CTSize sz; + copyval: /* Copy value. */ + sz = s->size; + lua_assert(sz != CTSIZE_INVALID); + /* Attributes are stripped, qualifiers are kept (but mostly ignored). */ + cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz); + setcdataV(cts->L, o, cd); + memcpy(cdataptr(cd), sp, sz); + return 1; /* Need GC step. */ + } +} + +/* Convert bitfield to TValue. */ +int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp) +{ + CTInfo info = s->info; + CTSize pos, bsz; + uint32_t val; + lua_assert(ctype_isbitfield(info)); + /* NYI: packed bitfields may cause misaligned reads. */ + switch (ctype_bitcsz(info)) { + case 4: val = *(uint32_t *)sp; break; + case 2: val = *(uint16_t *)sp; break; + case 1: val = *(uint8_t *)sp; break; + default: lua_assert(0); val = 0; break; + } + /* Check if a packed bitfield crosses a container boundary. */ + pos = ctype_bitpos(info); + bsz = ctype_bitbsz(info); + lua_assert(pos < 8*ctype_bitcsz(info)); + lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info)); + if (pos + bsz > 8*ctype_bitcsz(info)) + lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); + if (!(info & CTF_BOOL)) { + CTSize shift = 32 - bsz; + if (!(info & CTF_UNSIGNED)) { + setintV(o, (int32_t)(val << (shift-pos)) >> shift); + } else { + val = (val << (shift-pos)) >> shift; + if (!LJ_DUALNUM || (int32_t)val < 0) + setnumV(o, (lua_Number)(uint32_t)val); + else + setintV(o, (int32_t)val); + } + } else { + lua_assert(bsz == 1); + setboolV(o, (val >> pos) & 1); + } + return 0; /* No GC step needed. */ +} + +/* -- TValue to C type conversion ----------------------------------------- */ + +/* Convert table to array. */ +static void cconv_array_tab(CTState *cts, CType *d, + uint8_t *dp, GCtab *t, CTInfo flags) +{ + int32_t i; + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize size = d->size, esize = dc->size, ofs = 0; + for (i = 0; ; i++) { + TValue *tv = (TValue *)lj_tab_getint(t, i); + if (!tv || tvisnil(tv)) { + if (i == 0) continue; /* Try again for 1-based tables. */ + break; /* Stop at first nil. */ + } + if (ofs >= size) + cconv_err_initov(cts, d); + lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags); + ofs += esize; + } + if (size != CTSIZE_INVALID) { /* Only fill up arrays with known size. */ + if (ofs == esize) { /* Replicate a single element. */ + for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize); + } else { /* Otherwise fill the remainder with zero. */ + memset(dp + ofs, 0, size - ofs); + } + } +} + +/* Convert table to sub-struct/union. */ +static void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp, + GCtab *t, int32_t *ip, CTInfo flags) +{ + CTypeID id = d->sib; + while (id) { + CType *df = ctype_get(cts, id); + id = df->sib; + if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) { + TValue *tv; + int32_t i = *ip, iz = i; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + if (i >= 0) { + retry: + tv = (TValue *)lj_tab_getint(t, i); + if (!tv || tvisnil(tv)) { + if (i == 0) { i = 1; goto retry; } /* 1-based tables. */ + if (iz == 0) { *ip = i = -1; goto tryname; } /* Init named fields. */ + break; /* Stop at first nil. */ + } + *ip = i + 1; + } else { + tryname: + tv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name))); + if (!tv || tvisnil(tv)) continue; + } + if (ctype_isfield(df->info)) + lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags); + else + lj_cconv_bf_tv(cts, df, dp+df->size, tv); + if ((d->info & CTF_UNION)) break; + } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) { + cconv_substruct_tab(cts, ctype_rawchild(cts, df), + dp+df->size, t, ip, flags); + } /* Ignore all other entries in the chain. */ + } +} + +/* Convert table to struct/union. */ +static void cconv_struct_tab(CTState *cts, CType *d, + uint8_t *dp, GCtab *t, CTInfo flags) +{ + int32_t i = 0; + memset(dp, 0, d->size); /* Much simpler to clear the struct first. */ + cconv_substruct_tab(cts, d, dp, t, &i, flags); +} + +/* Convert TValue to C type. Caveat: expects to get the raw CType! */ +void lj_cconv_ct_tv(CTState *cts, CType *d, + uint8_t *dp, TValue *o, CTInfo flags) +{ + CTypeID sid = CTID_P_VOID; + CType *s; + void *tmpptr; + uint8_t tmpbool, *sp = (uint8_t *)&tmpptr; + if (LJ_LIKELY(tvisint(o))) { + sp = (uint8_t *)&o->i; + sid = CTID_INT32; + flags |= CCF_FROMTV; + } else if (LJ_LIKELY(tvisnum(o))) { + sp = (uint8_t *)&o->n; + sid = CTID_DOUBLE; + flags |= CCF_FROMTV; + } else if (tviscdata(o)) { + sp = cdataptr(cdataV(o)); + sid = cdataV(o)->ctypeid; + s = ctype_get(cts, sid); + if (ctype_isref(s->info)) { /* Resolve reference for value. */ + lua_assert(s->size == CTSIZE_PTR); + sp = *(void **)sp; + sid = ctype_cid(s->info); + } + s = ctype_raw(cts, sid); + if (ctype_isfunc(s->info)) { + sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR); + } else { + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + goto doconv; + } + } else if (tvisstr(o)) { + GCstr *str = strV(o); + if (ctype_isenum(d->info)) { /* Match string against enum constant. */ + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, d, str, &ofs); + if (!cct || !ctype_isconstval(cct->info)) + goto err_conv; + lua_assert(d->size == 4); + sp = (uint8_t *)&cct->size; + sid = ctype_cid(cct->info); + } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */ + CType *dc = ctype_rawchild(cts, d); + CTSize sz = str->len+1; + if (!ctype_isinteger(dc->info) || dc->size != 1) + goto err_conv; + if (d->size != 0 && d->size < sz) + sz = d->size; + memcpy(dp, strdata(str), sz); + return; + } else { /* Otherwise pass it as a const char[]. */ + sp = (uint8_t *)strdata(str); + sid = CTID_A_CCHAR; + flags |= CCF_FROMTV; + } + } else if (tvistab(o)) { + if (ctype_isarray(d->info)) { + cconv_array_tab(cts, d, dp, tabV(o), flags); + return; + } else if (ctype_isstruct(d->info)) { + cconv_struct_tab(cts, d, dp, tabV(o), flags); + return; + } else { + goto err_conv; + } + } else if (tvisbool(o)) { + tmpbool = boolV(o); + sp = &tmpbool; + sid = CTID_BOOL; + } else if (tvisnil(o)) { + tmpptr = (void *)0; + flags |= CCF_FROMTV; + } else if (tvisudata(o)) { + GCudata *ud = udataV(o); + tmpptr = uddata(ud); + if (ud->udtype == UDTYPE_IO_FILE) + tmpptr = *(void **)tmpptr; + } else if (tvislightud(o)) { + tmpptr = lightudV(o); + } else if (tvisfunc(o)) { + void *p = lj_ccallback_new(cts, d, funcV(o)); + if (p) { + *(void **)dp = p; + return; + } + goto err_conv; + } else { + err_conv: + cconv_err_convtv(cts, d, o, flags); + } + s = ctype_get(cts, sid); +doconv: + if (ctype_isenum(d->info)) d = ctype_child(cts, d); + lj_cconv_ct_ct(cts, d, s, dp, sp, flags); +} + +/* Convert TValue to bitfield. */ +void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o) +{ + CTInfo info = d->info; + CTSize pos, bsz; + uint32_t val, mask; + lua_assert(ctype_isbitfield(info)); + if ((info & CTF_BOOL)) { + uint8_t tmpbool; + lua_assert(ctype_bitbsz(info) == 1); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0); + val = tmpbool; + } else { + CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32; + lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0); + } + pos = ctype_bitpos(info); + bsz = ctype_bitbsz(info); + lua_assert(pos < 8*ctype_bitcsz(info)); + lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info)); + /* Check if a packed bitfield crosses a container boundary. */ + if (pos + bsz > 8*ctype_bitcsz(info)) + lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); + mask = ((1u << bsz) - 1u) << pos; + val = (val << pos) & mask; + /* NYI: packed bitfields may cause misaligned reads/writes. */ + switch (ctype_bitcsz(info)) { + case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break; + case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break; + case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break; + default: lua_assert(0); break; + } +} + +/* -- Initialize C type with TValues -------------------------------------- */ + +/* Initialize an array with TValues. */ +static void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp, + TValue *o, MSize len) +{ + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize ofs, esize = dc->size; + MSize i; + if (len*esize > sz) + cconv_err_initov(cts, d); + for (i = 0, ofs = 0; i < len; i++, ofs += esize) + lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0); + if (ofs == esize) { /* Replicate a single element. */ + for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize); + } else { /* Otherwise fill the remainder with zero. */ + memset(dp + ofs, 0, sz - ofs); + } +} + +/* Initialize a sub-struct/union with TValues. */ +static void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp, + TValue *o, MSize len, MSize *ip) +{ + CTypeID id = d->sib; + while (id) { + CType *df = ctype_get(cts, id); + id = df->sib; + if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) { + MSize i = *ip; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + if (i >= len) break; + *ip = i + 1; + if (ctype_isfield(df->info)) + lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0); + else + lj_cconv_bf_tv(cts, df, dp+df->size, o + i); + if ((d->info & CTF_UNION)) break; + } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) { + cconv_substruct_init(cts, ctype_rawchild(cts, df), + dp+df->size, o, len, ip); + } /* Ignore all other entries in the chain. */ + } +} + +/* Initialize a struct/union with TValues. */ +static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp, + TValue *o, MSize len) +{ + MSize i = 0; + memset(dp, 0, sz); /* Much simpler to clear the struct first. */ + cconv_substruct_init(cts, d, dp, o, len, &i); + if (i < len) + cconv_err_initov(cts, d); +} + +/* Check whether to use a multi-value initializer. +** This is true if an aggregate is to be initialized with a value. +** Valarrays are treated as values here so ct_tv handles (V|C, I|F). +*/ +int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o) +{ + if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info))) + return 0; /* Destination is not an aggregate. */ + if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info))) + return 0; /* Initializer is not a value. */ + if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d) + return 0; /* Source and destination are identical aggregates. */ + return 1; /* Otherwise the initializer is a value. */ +} + +/* Initialize C type with TValues. Caveat: expects to get the raw CType! */ +void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, + uint8_t *dp, TValue *o, MSize len) +{ + if (len == 0) + memset(dp, 0, sz); + else if (len == 1 && !lj_cconv_multi_init(cts, d, o)) + lj_cconv_ct_tv(cts, d, dp, o, 0); + else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */ + cconv_array_init(cts, d, sz, dp, o, len); + else if (ctype_isstruct(d->info)) + cconv_struct_init(cts, d, sz, dp, o, len); + else + cconv_err_initov(cts, d); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.h new file mode 100644 index 0000000..17e0f05 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cconv.h @@ -0,0 +1,70 @@ +/* +** C type conversions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCONV_H +#define _LJ_CCONV_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Compressed C type index. ORDER CCX. */ +enum { + CCX_B, /* Bool. */ + CCX_I, /* Integer. */ + CCX_F, /* Floating-point number. */ + CCX_C, /* Complex. */ + CCX_V, /* Vector. */ + CCX_P, /* Pointer. */ + CCX_A, /* Refarray. */ + CCX_S /* Struct/union. */ +}; + +/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */ +static LJ_AINLINE uint32_t cconv_idx(CTInfo info) +{ + uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */ + lua_assert(ctype_type(info) <= CT_MAYCONVERT); +#if LJ_64 + idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u); +#else + idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u); +#endif + lua_assert(idx < 8); + return idx; +} + +#define cconv_idx2(dinfo, sinfo) \ + ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo))) + +#define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src) + +/* Conversion flags. */ +#define CCF_CAST 0x00000001u +#define CCF_FROMTV 0x00000002u +#define CCF_SAME 0x00000004u +#define CCF_IGNQUAL 0x00000008u + +#define CCF_ARG_SHIFT 8 +#define CCF_ARG(n) ((n) << CCF_ARG_SHIFT) +#define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT) + +LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags); +LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, + uint8_t *dp, uint8_t *sp, CTInfo flags); +LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, + TValue *o, uint8_t *sp); +LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp); +LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, + uint8_t *dp, TValue *o, CTInfo flags); +LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); +LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o); +LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, + uint8_t *dp, TValue *o, MSize len); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.c new file mode 100644 index 0000000..590ddf1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.c @@ -0,0 +1,285 @@ +/* +** C data management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" + +/* -- C data allocation --------------------------------------------------- */ + +/* Allocate a new C data object holding a reference to another object. */ +GCcdata *lj_cdata_newref(CTState *cts, const void *p, CTypeID id) +{ + CTypeID refid = lj_ctype_intern(cts, CTINFO_REF(id), CTSIZE_PTR); + GCcdata *cd = lj_cdata_new(cts, refid, CTSIZE_PTR); + *(const void **)cdataptr(cd) = p; + return cd; +} + +/* Allocate variable-sized or specially aligned C data object. */ +GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, CTSize align) +{ + global_State *g; + MSize extra = sizeof(GCcdataVar) + sizeof(GCcdata) + + (align > CT_MEMALIGN ? (1u<L, extra + sz, char); + uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata); + uintptr_t almask = (1u << align) - 1u; + GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata)); + lua_assert((char *)cd - p < 65536); + cdatav(cd)->offset = (uint16_t)((char *)cd - p); + cdatav(cd)->extra = extra; + cdatav(cd)->len = sz; + g = cts->g; + setgcrefr(cd->nextgc, g->gc.root); + setgcref(g->gc.root, obj2gco(cd)); + newwhite(g, obj2gco(cd)); + cd->marked |= 0x80; + cd->gct = ~LJ_TCDATA; + cd->ctypeid = id; + return cd; +} + +/* Free a C data object. */ +void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd) +{ + if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) { + GCobj *root; + makewhite(g, obj2gco(cd)); + markfinalized(obj2gco(cd)); + if ((root = gcref(g->gc.mmudata)) != NULL) { + setgcrefr(cd->nextgc, root->gch.nextgc); + setgcref(root->gch.nextgc, obj2gco(cd)); + setgcref(g->gc.mmudata, obj2gco(cd)); + } else { + setgcref(cd->nextgc, obj2gco(cd)); + setgcref(g->gc.mmudata, obj2gco(cd)); + } + } else if (LJ_LIKELY(!cdataisv(cd))) { + CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid); + CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR; + lua_assert(ctype_hassize(ct->info) || ctype_isfunc(ct->info) || + ctype_isextern(ct->info)); + lj_mem_free(g, cd, sizeof(GCcdata) + sz); + } else { + lj_mem_free(g, memcdatav(cd), sizecdatav(cd)); + } +} + +TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd) +{ + global_State *g = G(L); + GCtab *t = ctype_ctsG(g)->finalizer; + if (gcref(t->metatable)) { + /* Add cdata to finalizer table, if still enabled. */ + TValue *tv, tmp; + setcdataV(L, &tmp, cd); + lj_gc_anybarriert(L, t); + tv = lj_tab_set(L, t, &tmp); + cd->marked |= LJ_GC_CDATA_FIN; + return tv; + } else { + /* Otherwise return dummy TValue. */ + return &g->tmptv; + } +} + +/* -- C data indexing ----------------------------------------------------- */ + +/* Index C data by a TValue. Return CType and pointer. */ +CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp, + CTInfo *qual) +{ + uint8_t *p = (uint8_t *)cdataptr(cd); + CType *ct = ctype_get(cts, cd->ctypeid); + ptrdiff_t idx; + + /* Resolve reference for cdata object. */ + if (ctype_isref(ct->info)) { + lua_assert(ct->size == CTSIZE_PTR); + p = *(uint8_t **)p; + ct = ctype_child(cts, ct); + } + +collect_attrib: + /* Skip attributes and collect qualifiers. */ + while (ctype_isattrib(ct->info)) { + if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; + ct = ctype_child(cts, ct); + } + lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ + + if (tvisint(key)) { + idx = (ptrdiff_t)intV(key); + goto integer_key; + } else if (tvisnum(key)) { /* Numeric key. */ + idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); + integer_key: + if (ctype_ispointer(ct->info)) { + CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */ + if (sz != CTSIZE_INVALID) { + if (ctype_isptr(ct->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) { + if ((ct->info & CTF_COMPLEX)) idx &= 1; + *qual |= CTF_CONST; /* Valarray elements are constant. */ + } + *pp = p + idx*(int32_t)sz; + return ct; + } + } + } else if (tviscdata(key)) { /* Integer cdata key. */ + GCcdata *cdk = cdataV(key); + CType *ctk = ctype_raw(cts, cdk->ctypeid); + if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk); + if (ctype_isinteger(ctk->info)) { + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk, + (uint8_t *)&idx, cdataptr(cdk), 0); + goto integer_key; + } + } else if (tvisstr(key)) { /* String key. */ + GCstr *name = strV(key); + if (ctype_isstruct(ct->info)) { + CTSize ofs; + CType *fct = lj_ctype_getfieldq(cts, ct, name, &ofs, qual); + if (fct) { + *pp = p + ofs; + return fct; + } + } else if (ctype_iscomplex(ct->info)) { + if (name->len == 2) { + *qual |= CTF_CONST; /* Complex fields are constant. */ + if (strdata(name)[0] == 'r' && strdata(name)[1] == 'e') { + *pp = p; + return ct; + } else if (strdata(name)[0] == 'i' && strdata(name)[1] == 'm') { + *pp = p + (ct->size >> 1); + return ct; + } + } + } else if (cd->ctypeid == CTID_CTYPEID) { + /* Allow indexing a (pointer to) struct constructor to get constants. */ + CType *sct = ctype_raw(cts, *(CTypeID *)p); + if (ctype_isptr(sct->info)) + sct = ctype_rawchild(cts, sct); + if (ctype_isstruct(sct->info)) { + CTSize ofs; + CType *fct = lj_ctype_getfield(cts, sct, name, &ofs); + if (fct && ctype_isconstval(fct->info)) + return fct; + } + ct = sct; /* Allow resolving metamethods for constructors, too. */ + } + } + if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ + if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + ct = ctype_child(cts, ct); + goto collect_attrib; + } + } + *qual |= 1; /* Lookup failed. */ + return ct; /* But return the resolved raw type. */ +} + +/* -- C data getters ------------------------------------------------------ */ + +/* Get constant value and convert to TValue. */ +static void cdata_getconst(CTState *cts, TValue *o, CType *ct) +{ + CType *ctt = ctype_child(cts, ct); + lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); + /* Constants are already zero-extended/sign-extended to 32 bits. */ + if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) + setnumV(o, (lua_Number)(uint32_t)ct->size); + else + setintV(o, (int32_t)ct->size); +} + +/* Get C data value and convert to TValue. */ +int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp) +{ + CTypeID sid; + + if (ctype_isconstval(s->info)) { + cdata_getconst(cts, o, s); + return 0; /* No GC step needed. */ + } else if (ctype_isbitfield(s->info)) { + return lj_cconv_tv_bf(cts, s, o, sp); + } + + /* Get child type of pointer/array/field. */ + lua_assert(ctype_ispointer(s->info) || ctype_isfield(s->info)); + sid = ctype_cid(s->info); + s = ctype_get(cts, sid); + + /* Resolve reference for field. */ + if (ctype_isref(s->info)) { + lua_assert(s->size == CTSIZE_PTR); + sp = *(uint8_t **)sp; + sid = ctype_cid(s->info); + s = ctype_get(cts, sid); + } + + /* Skip attributes. */ + while (ctype_isattrib(s->info)) + s = ctype_child(cts, s); + + return lj_cconv_tv_ct(cts, s, sid, o, sp); +} + +/* -- C data setters ------------------------------------------------------ */ + +/* Convert TValue and set C data value. */ +void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual) +{ + if (ctype_isconstval(d->info)) { + goto err_const; + } else if (ctype_isbitfield(d->info)) { + if (((d->info|qual) & CTF_CONST)) goto err_const; + lj_cconv_bf_tv(cts, d, dp, o); + return; + } + + /* Get child type of pointer/array/field. */ + lua_assert(ctype_ispointer(d->info) || ctype_isfield(d->info)); + d = ctype_child(cts, d); + + /* Resolve reference for field. */ + if (ctype_isref(d->info)) { + lua_assert(d->size == CTSIZE_PTR); + dp = *(uint8_t **)dp; + d = ctype_child(cts, d); + } + + /* Skip attributes and collect qualifiers. */ + for (;;) { + if (ctype_isattrib(d->info)) { + if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size; + } else { + break; + } + d = ctype_child(cts, d); + } + + lua_assert(ctype_hassize(d->info) && !ctype_isvoid(d->info)); + + if (((d->info|qual) & CTF_CONST)) { + err_const: + lj_err_caller(cts->L, LJ_ERR_FFI_WRCONST); + } + + lj_cconv_ct_tv(cts, d, dp, o, 0); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.h new file mode 100644 index 0000000..6c8e7a1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cdata.h @@ -0,0 +1,75 @@ +/* +** C data management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CDATA_H +#define _LJ_CDATA_H + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Get C data pointer. */ +static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz) +{ + if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ + return ((void *)(uintptr_t)*(uint32_t *)p); + } else { + lua_assert(sz == CTSIZE_PTR); + return *(void **)p; + } +} + +/* Set C data pointer. */ +static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v) +{ + if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ + *(uint32_t *)p = (uint32_t)(uintptr_t)v; + } else { + lua_assert(sz == CTSIZE_PTR); + *(void **)p = (void *)v; + } +} + +/* Allocate fixed-size C data object. */ +static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz) +{ + GCcdata *cd; +#ifdef LUA_USE_ASSERT + CType *ct = ctype_raw(cts, id); + lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz); +#endif + cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz); + cd->gct = ~LJ_TCDATA; + cd->ctypeid = ctype_check(cts, id); + return cd; +} + +/* Variant which works without a valid CTState. */ +static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz) +{ + GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz); + cd->gct = ~LJ_TCDATA; + cd->ctypeid = id; + return cd; +} + +LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id); +LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, + CTSize align); + +LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd); +LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd); + +LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, + uint8_t **pp, CTInfo *qual); +LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp); +LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, + CTInfo qual); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.c new file mode 100644 index 0000000..11f23ef --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.c @@ -0,0 +1,43 @@ +/* +** Character types. +** Donated to the public domain. +** +** This is intended to replace the problematic libc single-byte NLS functions. +** These just don't make sense anymore with UTF-8 locales becoming the norm +** on POSIX systems. It never worked too well on Windows systems since hardly +** anyone bothered to call setlocale(). +** +** This table is hardcoded for ASCII. Identifiers include the characters +** 128-255, too. This allows for the use of all non-ASCII chars as identifiers +** in the lexer. This is a broad definition, but works well in practice +** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*). +** +** If you really need proper character types for UTF-8 strings, please use +** an add-on library such as slnunicode: http://luaforge.net/projects/sln/ +*/ + +#define lj_char_c +#define LUA_CORE + +#include "lj_char.h" + +LJ_DATADEF const uint8_t lj_char_bits[257] = { + 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 152,152,152,152,152,152,152,152,152,152, 4, 4, 4, 4, 4, 4, + 4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160, + 160,160,160,160,160,160,160,160,160,160,160, 4, 4, 4, 4,132, + 4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192, + 192,192,192,192,192,192,192,192,192,192,192, 4, 4, 4, 4, 1, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128 +}; + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.h new file mode 100644 index 0000000..c3c86d3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_char.h @@ -0,0 +1,42 @@ +/* +** Character types. +** Donated to the public domain. +*/ + +#ifndef _LJ_CHAR_H +#define _LJ_CHAR_H + +#include "lj_def.h" + +#define LJ_CHAR_CNTRL 0x01 +#define LJ_CHAR_SPACE 0x02 +#define LJ_CHAR_PUNCT 0x04 +#define LJ_CHAR_DIGIT 0x08 +#define LJ_CHAR_XDIGIT 0x10 +#define LJ_CHAR_UPPER 0x20 +#define LJ_CHAR_LOWER 0x40 +#define LJ_CHAR_IDENT 0x80 +#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER) +#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT) +#define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT) + +/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */ +#define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t) +#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL) +#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE) +#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT) +#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT) +#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT) +#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER) +#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER) +#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT) +#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA) +#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM) +#define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH) + +#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1)) +#define lj_char_tolower(c) ((c) + lj_char_isupper(c)) + +LJ_DATA const uint8_t lj_char_bits[257]; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.c new file mode 100644 index 0000000..ccb99e5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.c @@ -0,0 +1,409 @@ +/* +** FFI C library loader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_str.h" +#include "lj_udata.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_clib.h" + +/* -- OS-specific functions ----------------------------------------------- */ + +#if LJ_TARGET_DLOPEN + +#include +#include + +#if defined(RTLD_DEFAULT) +#define CLIB_DEFHANDLE RTLD_DEFAULT +#elif LJ_TARGET_OSX || LJ_TARGET_BSD +#define CLIB_DEFHANDLE ((void *)(intptr_t)-2) +#else +#define CLIB_DEFHANDLE NULL +#endif + +LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L) +{ + lj_err_callermsg(L, dlerror()); +} + +#define clib_error(L, fmt, name) clib_error_(L) + +#if defined(__CYGWIN__) +#define CLIB_SOPREFIX "cyg" +#else +#define CLIB_SOPREFIX "lib" +#endif + +#if LJ_TARGET_OSX +#define CLIB_SOEXT "%s.dylib" +#elif defined(__CYGWIN__) +#define CLIB_SOEXT "%s.dll" +#else +#define CLIB_SOEXT "%s.so" +#endif + +static const char *clib_extname(lua_State *L, const char *name) +{ + if (!strchr(name, '/') +#ifdef __CYGWIN__ + && !strchr(name, '\\') +#endif + ) { + if (!strchr(name, '.')) { + name = lj_str_pushf(L, CLIB_SOEXT, name); + L->top--; +#ifdef __CYGWIN__ + } else { + return name; +#endif + } + if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] && + name[2] == CLIB_SOPREFIX[2])) { + name = lj_str_pushf(L, CLIB_SOPREFIX "%s", name); + L->top--; + } + } + return name; +} + +/* Check for a recognized ld script line. */ +static const char *clib_check_lds(lua_State *L, const char *buf) +{ + char *p, *e; + if ((!strncmp(buf, "GROUP", 5) || !strncmp(buf, "INPUT", 5)) && + (p = strchr(buf, '('))) { + while (*++p == ' ') ; + for (e = p; *e && *e != ' ' && *e != ')'; e++) ; + return strdata(lj_str_new(L, p, e-p)); + } + return NULL; +} + +/* Quick and dirty solution to resolve shared library name from ld script. */ +static const char *clib_resolve_lds(lua_State *L, const char *name) +{ + FILE *fp = fopen(name, "r"); + const char *p = NULL; + if (fp) { + char buf[256]; + if (fgets(buf, sizeof(buf), fp)) { + if (!strncmp(buf, "/* GNU ld script", 16)) { /* ld script magic? */ + while (fgets(buf, sizeof(buf), fp)) { /* Check all lines. */ + p = clib_check_lds(L, buf); + if (p) break; + } + } else { /* Otherwise check only the first line. */ + p = clib_check_lds(L, buf); + } + } + fclose(fp); + } + return p; +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + void *h = dlopen(clib_extname(L, name), + RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL)); + if (!h) { + const char *e, *err = dlerror(); + if (*err == '/' && (e = strchr(err, ':')) && + (name = clib_resolve_lds(L, strdata(lj_str_new(L, err, e-err))))) { + h = dlopen(name, RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL)); + if (h) return h; + err = dlerror(); + } + lj_err_callermsg(L, err); + } + return h; +} + +static void clib_unloadlib(CLibrary *cl) +{ + if (cl->handle && cl->handle != CLIB_DEFHANDLE) + dlclose(cl->handle); +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + void *p = dlsym(cl->handle, name); + return p; +} + +#elif LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4 +#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2 +BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*); +#endif + +#define CLIB_DEFHANDLE ((void *)-1) + +/* Default libraries. */ +enum { + CLIB_HANDLE_EXE, + CLIB_HANDLE_DLL, + CLIB_HANDLE_CRT, + CLIB_HANDLE_KERNEL32, + CLIB_HANDLE_USER32, + CLIB_HANDLE_GDI32, + CLIB_HANDLE_MAX +}; + +static void *clib_def_handle[CLIB_HANDLE_MAX]; + +LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt, + const char *name) +{ + DWORD err = GetLastError(); + char buf[128]; + if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, err, 0, buf, sizeof(buf), NULL)) + buf[0] = '\0'; + lj_err_callermsg(L, lj_str_pushf(L, fmt, name, buf)); +} + +static int clib_needext(const char *s) +{ + while (*s) { + if (*s == '/' || *s == '\\' || *s == '.') return 0; + s++; + } + return 1; +} + +static const char *clib_extname(lua_State *L, const char *name) +{ + if (clib_needext(name)) { + name = lj_str_pushf(L, "%s.dll", name); + L->top--; + } + return name; +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + DWORD oldwerr = GetLastError(); + void *h = (void *)LoadLibraryA(clib_extname(L, name)); + if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); + SetLastError(oldwerr); + UNUSED(global); + return h; +} + +static void clib_unloadlib(CLibrary *cl) +{ + if (cl->handle == CLIB_DEFHANDLE) { + MSize i; + for (i = CLIB_HANDLE_KERNEL32; i < CLIB_HANDLE_MAX; i++) { + void *h = clib_def_handle[i]; + if (h) { + clib_def_handle[i] = NULL; + FreeLibrary((HINSTANCE)h); + } + } + } else if (cl->handle) { + FreeLibrary((HINSTANCE)cl->handle); + } +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + void *p = NULL; + if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */ + MSize i; + for (i = 0; i < CLIB_HANDLE_MAX; i++) { + HINSTANCE h = (HINSTANCE)clib_def_handle[i]; + if (!(void *)h) { /* Resolve default library handles (once). */ + switch (i) { + case CLIB_HANDLE_EXE: GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, &h); break; + case CLIB_HANDLE_DLL: + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)clib_def_handle, &h); + break; + case CLIB_HANDLE_CRT: + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)&_fmode, &h); + break; + case CLIB_HANDLE_KERNEL32: h = LoadLibraryA("kernel32.dll"); break; + case CLIB_HANDLE_USER32: h = LoadLibraryA("user32.dll"); break; + case CLIB_HANDLE_GDI32: h = LoadLibraryA("gdi32.dll"); break; + } + if (!h) continue; + clib_def_handle[i] = (void *)h; + } + p = (void *)GetProcAddress(h, name); + if (p) break; + } + } else { + p = (void *)GetProcAddress((HINSTANCE)cl->handle, name); + } + return p; +} + +#else + +#define CLIB_DEFHANDLE NULL + +LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt, + const char *name) +{ + lj_err_callermsg(L, lj_str_pushf(L, fmt, name, "no support for this OS")); +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + lj_err_callermsg(L, "no support for loading dynamic libraries for this OS"); + UNUSED(name); UNUSED(global); + return NULL; +} + +static void clib_unloadlib(CLibrary *cl) +{ + UNUSED(cl); +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + UNUSED(cl); UNUSED(name); + return NULL; +} + +#endif + +/* -- C library indexing -------------------------------------------------- */ + +#if LJ_TARGET_X86 && LJ_ABI_WIN +/* Compute argument size for fastcall/stdcall functions. */ +static CTSize clib_func_argsize(CTState *cts, CType *ct) +{ + CTSize n = 0; + while (ct->sib) { + CType *d; + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + d = ctype_rawchild(cts, ct); + n += ((d->size + 3) & ~3); + } + } + return n; +} +#endif + +/* Get redirected or mangled external symbol. */ +static const char *clib_extsym(CTState *cts, CType *ct, GCstr *name) +{ + if (ct->sib) { + CType *ctf = ctype_get(cts, ct->sib); + if (ctype_isxattrib(ctf->info, CTA_REDIR)) + return strdata(gco2str(gcref(ctf->name))); + } + return strdata(name); +} + +/* Index a C library by name. */ +TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name) +{ + TValue *tv = lj_tab_setstr(L, cl->cache, name); + if (LJ_UNLIKELY(tvisnil(tv))) { + CTState *cts = ctype_cts(L); + CType *ct; + CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); + if (!id) + lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name)); + if (ctype_isconstval(ct->info)) { + CType *ctt = ctype_child(cts, ct); + lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); + if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) + setnumV(tv, (lua_Number)(uint32_t)ct->size); + else + setintV(tv, (int32_t)ct->size); + } else { + const char *sym = clib_extsym(cts, ct, name); +#if LJ_TARGET_WINDOWS + DWORD oldwerr = GetLastError(); +#endif + void *p = clib_getsym(cl, sym); + GCcdata *cd; + lua_assert(ctype_isfunc(ct->info) || ctype_isextern(ct->info)); +#if LJ_TARGET_X86 && LJ_ABI_WIN + /* Retry with decorated name for fastcall/stdcall functions. */ + if (!p && ctype_isfunc(ct->info)) { + CTInfo cconv = ctype_cconv(ct->info); + if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) { + CTSize sz = clib_func_argsize(cts, ct); + const char *symd = lj_str_pushf(L, + cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d", + sym, sz); + L->top--; + p = clib_getsym(cl, symd); + } + } +#endif + if (!p) + clib_error(L, "cannot resolve symbol " LUA_QS ": %s", sym); +#if LJ_TARGET_WINDOWS + SetLastError(oldwerr); +#endif + cd = lj_cdata_new(cts, id, CTSIZE_PTR); + *(void **)cdataptr(cd) = p; + setcdataV(L, tv, cd); + } + } + return tv; +} + +/* -- C library management ------------------------------------------------ */ + +/* Create a new CLibrary object and push it on the stack. */ +static CLibrary *clib_new(lua_State *L, GCtab *mt) +{ + GCtab *t = lj_tab_new(L, 0, 0); + GCudata *ud = lj_udata_new(L, sizeof(CLibrary), t); + CLibrary *cl = (CLibrary *)uddata(ud); + cl->cache = t; + ud->udtype = UDTYPE_FFI_CLIB; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcref(ud->metatable, obj2gco(mt)); + setudataV(L, L->top++, ud); + return cl; +} + +/* Load a C library. */ +void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global) +{ + void *handle = clib_loadlib(L, strdata(name), global); + CLibrary *cl = clib_new(L, mt); + cl->handle = handle; +} + +/* Unload a C library. */ +void lj_clib_unload(CLibrary *cl) +{ + clib_unloadlib(cl); + cl->handle = NULL; +} + +/* Create the default C library object. */ +void lj_clib_default(lua_State *L, GCtab *mt) +{ + CLibrary *cl = clib_new(L, mt); + cl->handle = CLIB_DEFHANDLE; +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.h new file mode 100644 index 0000000..4737328 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_clib.h @@ -0,0 +1,29 @@ +/* +** FFI C library loader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CLIB_H +#define _LJ_CLIB_H + +#include "lj_obj.h" + +#if LJ_HASFFI + +/* Namespace for C library indexing. */ +#define CLNS_INDEX ((1u<env. */ +} CLibrary; + +LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name); +LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global); +LJ_FUNC void lj_clib_unload(CLibrary *cl); +LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.c new file mode 100644 index 0000000..6ffe16a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.c @@ -0,0 +1,1872 @@ +/* +** C declaration parser. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ctype.h" +#include "lj_cparse.h" +#include "lj_frame.h" +#include "lj_vm.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* +** Important note: this is NOT a validating C parser! This is a minimal +** C declaration parser, solely for use by the LuaJIT FFI. +** +** It ought to return correct results for properly formed C declarations, +** but it may accept some invalid declarations, too (and return nonsense). +** Also, it shows rather generic error messages to avoid unnecessary bloat. +** If in doubt, please check the input against your favorite C compiler. +*/ + +/* -- C lexer ------------------------------------------------------------- */ + +/* C lexer token names. */ +static const char *const ctoknames[] = { +#define CTOKSTR(name, str) str, +CTOKDEF(CTOKSTR) +#undef CTOKSTR + NULL +}; + +/* Forward declaration. */ +LJ_NORET static void cp_err(CPState *cp, ErrMsg em); + +static const char *cp_tok2str(CPState *cp, CPToken tok) +{ + lua_assert(tok < CTOK_FIRSTDECL); + if (tok > CTOK_OFS) + return ctoknames[tok-CTOK_OFS-1]; + else if (!lj_char_iscntrl(tok)) + return lj_str_pushf(cp->L, "%c", tok); + else + return lj_str_pushf(cp->L, "char(%d)", tok); +} + +/* End-of-line? */ +static LJ_AINLINE int cp_iseol(CPChar c) +{ + return (c == '\n' || c == '\r'); +} + +/* Peek next raw character. */ +static LJ_AINLINE CPChar cp_rawpeek(CPState *cp) +{ + return (CPChar)(uint8_t)(*cp->p); +} + +static LJ_NOINLINE CPChar cp_get_bs(CPState *cp); + +/* Get next character. */ +static LJ_AINLINE CPChar cp_get(CPState *cp) +{ + cp->c = (CPChar)(uint8_t)(*cp->p++); + if (LJ_LIKELY(cp->c != '\\')) return cp->c; + return cp_get_bs(cp); +} + +/* Transparently skip backslash-escaped line breaks. */ +static LJ_NOINLINE CPChar cp_get_bs(CPState *cp) +{ + CPChar c2, c = cp_rawpeek(cp); + if (!cp_iseol(c)) return cp->c; + cp->p++; + c2 = cp_rawpeek(cp); + if (cp_iseol(c2) && c2 != c) cp->p++; + cp->linenumber++; + return cp_get(cp); +} + +/* Grow save buffer. */ +static LJ_NOINLINE void cp_save_grow(CPState *cp, CPChar c) +{ + MSize newsize; + if (cp->sb.sz >= CPARSE_MAX_BUF/2) + cp_err(cp, LJ_ERR_XELEM); + newsize = cp->sb.sz * 2; + lj_str_resizebuf(cp->L, &cp->sb, newsize); + cp->sb.buf[cp->sb.n++] = (char)c; +} + +/* Save character in buffer. */ +static LJ_AINLINE void cp_save(CPState *cp, CPChar c) +{ + if (LJ_UNLIKELY(cp->sb.n + 1 > cp->sb.sz)) + cp_save_grow(cp, c); + else + cp->sb.buf[cp->sb.n++] = (char)c; +} + +/* Skip line break. Handles "\n", "\r", "\r\n" or "\n\r". */ +static void cp_newline(CPState *cp) +{ + CPChar c = cp_rawpeek(cp); + if (cp_iseol(c) && c != cp->c) cp->p++; + cp->linenumber++; +} + +LJ_NORET static void cp_errmsg(CPState *cp, CPToken tok, ErrMsg em, ...) +{ + const char *msg, *tokstr; + lua_State *L; + va_list argp; + if (tok == 0) { + tokstr = NULL; + } else if (tok == CTOK_IDENT || tok == CTOK_INTEGER || tok == CTOK_STRING || + tok >= CTOK_FIRSTDECL) { + if (cp->sb.n == 0) cp_save(cp, '$'); + cp_save(cp, '\0'); + tokstr = cp->sb.buf; + } else { + tokstr = cp_tok2str(cp, tok); + } + L = cp->L; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + if (tokstr) + msg = lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tokstr); + if (cp->linenumber > 1) + msg = lj_str_pushf(L, "%s at line %d", msg, cp->linenumber); + lj_err_callermsg(L, msg); +} + +LJ_NORET LJ_NOINLINE static void cp_err_token(CPState *cp, CPToken tok) +{ + cp_errmsg(cp, cp->tok, LJ_ERR_XTOKEN, cp_tok2str(cp, tok)); +} + +LJ_NORET LJ_NOINLINE static void cp_err_badidx(CPState *cp, CType *ct) +{ + GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL); + cp_errmsg(cp, 0, LJ_ERR_FFI_BADIDX, strdata(s)); +} + +LJ_NORET LJ_NOINLINE static void cp_err(CPState *cp, ErrMsg em) +{ + cp_errmsg(cp, 0, em); +} + +/* -- Main lexical scanner ------------------------------------------------ */ + +/* Parse number literal. Only handles int32_t/uint32_t right now. */ +static CPToken cp_number(CPState *cp) +{ + StrScanFmt fmt; + TValue o; + do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp))); + cp_save(cp, '\0'); + fmt = lj_strscan_scan((const uint8_t *)cp->sb.buf, &o, STRSCAN_OPT_C); + if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32; + else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32; + else if (!(cp->mode & CPARSE_MODE_SKIP)) + cp_errmsg(cp, CTOK_INTEGER, LJ_ERR_XNUMBER); + cp->val.u32 = (uint32_t)o.i; + return CTOK_INTEGER; +} + +/* Parse identifier or keyword. */ +static CPToken cp_ident(CPState *cp) +{ + do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp))); + cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n); + cp->val.id = lj_ctype_getname(cp->cts, &cp->ct, cp->str, cp->tmask); + if (ctype_type(cp->ct->info) == CT_KW) + return ctype_cid(cp->ct->info); + return CTOK_IDENT; +} + +/* Parse parameter. */ +static CPToken cp_param(CPState *cp) +{ + CPChar c = cp_get(cp); + TValue *o = cp->param; + if (lj_char_isident(c) || c == '$') /* Reserve $xyz for future extensions. */ + cp_errmsg(cp, c, LJ_ERR_XSYNTAX); + if (!o || o >= cp->L->top) + cp_err(cp, LJ_ERR_FFI_NUMPARAM); + cp->param = o+1; + if (tvisstr(o)) { + cp->str = strV(o); + cp->val.id = 0; + cp->ct = &cp->cts->tab[0]; + return CTOK_IDENT; + } else if (tvisnumber(o)) { + cp->val.i32 = numberVint(o); + cp->val.id = CTID_INT32; + return CTOK_INTEGER; + } else { + GCcdata *cd; + if (!tviscdata(o)) + lj_err_argtype(cp->L, (int)(o-cp->L->base)+1, "type parameter"); + cd = cdataV(o); + if (cd->ctypeid == CTID_CTYPEID) + cp->val.id = *(CTypeID *)cdataptr(cd); + else + cp->val.id = cd->ctypeid; + return '$'; + } +} + +/* Parse string or character constant. */ +static CPToken cp_string(CPState *cp) +{ + CPChar delim = cp->c; + cp_get(cp); + while (cp->c != delim) { + CPChar c = cp->c; + if (c == '\0') cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); + if (c == '\\') { + c = cp_get(cp); + switch (c) { + case '\0': cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); break; + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'e': c = 27; break; + case 'x': + c = 0; + while (lj_char_isxdigit(cp_get(cp))) + c = (c<<4) + (lj_char_isdigit(cp->c) ? cp->c-'0' : (cp->c&15)+9); + cp_save(cp, (c & 0xff)); + continue; + default: + if (lj_char_isdigit(c)) { + c -= '0'; + if (lj_char_isdigit(cp_get(cp))) { + c = c*8 + (cp->c - '0'); + if (lj_char_isdigit(cp_get(cp))) { + c = c*8 + (cp->c - '0'); + cp_get(cp); + } + } + cp_save(cp, (c & 0xff)); + continue; + } + break; + } + } + cp_save(cp, c); + cp_get(cp); + } + cp_get(cp); + if (delim == '"') { + cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n); + return CTOK_STRING; + } else { + if (cp->sb.n != 1) cp_err_token(cp, '\''); + cp->val.i32 = (int32_t)(char)cp->sb.buf[0]; + cp->val.id = CTID_INT32; + return CTOK_INTEGER; + } +} + +/* Skip C comment. */ +static void cp_comment_c(CPState *cp) +{ + do { + if (cp_get(cp) == '*') { + do { + if (cp_get(cp) == '/') { cp_get(cp); return; } + } while (cp->c == '*'); + } + if (cp_iseol(cp->c)) cp_newline(cp); + } while (cp->c != '\0'); +} + +/* Skip C++ comment. */ +static void cp_comment_cpp(CPState *cp) +{ + while (!cp_iseol(cp_get(cp)) && cp->c != '\0') + ; +} + +/* Lexical scanner for C. Only a minimal subset is implemented. */ +static CPToken cp_next_(CPState *cp) +{ + lj_str_resetbuf(&cp->sb); + for (;;) { + if (lj_char_isident(cp->c)) + return lj_char_isdigit(cp->c) ? cp_number(cp) : cp_ident(cp); + switch (cp->c) { + case '\n': case '\r': cp_newline(cp); /* fallthrough. */ + case ' ': case '\t': case '\v': case '\f': cp_get(cp); break; + case '"': case '\'': return cp_string(cp); + case '/': + if (cp_get(cp) == '*') cp_comment_c(cp); + else if (cp->c == '/') cp_comment_cpp(cp); + else return '/'; + break; + case '|': + if (cp_get(cp) != '|') return '|'; cp_get(cp); return CTOK_OROR; + case '&': + if (cp_get(cp) != '&') return '&'; cp_get(cp); return CTOK_ANDAND; + case '=': + if (cp_get(cp) != '=') return '='; cp_get(cp); return CTOK_EQ; + case '!': + if (cp_get(cp) != '=') return '!'; cp_get(cp); return CTOK_NE; + case '<': + if (cp_get(cp) == '=') { cp_get(cp); return CTOK_LE; } + else if (cp->c == '<') { cp_get(cp); return CTOK_SHL; } + return '<'; + case '>': + if (cp_get(cp) == '=') { cp_get(cp); return CTOK_GE; } + else if (cp->c == '>') { cp_get(cp); return CTOK_SHR; } + return '>'; + case '-': + if (cp_get(cp) != '>') return '-'; cp_get(cp); return CTOK_DEREF; + case '$': + return cp_param(cp); + case '\0': return CTOK_EOF; + default: { CPToken c = cp->c; cp_get(cp); return c; } + } + } +} + +static LJ_NOINLINE CPToken cp_next(CPState *cp) +{ + return (cp->tok = cp_next_(cp)); +} + +/* -- C parser ------------------------------------------------------------ */ + +/* Namespaces for resolving identifiers. */ +#define CPNS_DEFAULT \ + ((1u<linenumber = 1; + cp->depth = 0; + cp->curpack = 0; + cp->packstack[0] = 255; + lj_str_initbuf(&cp->sb); + lj_str_resizebuf(cp->L, &cp->sb, LJ_MIN_SBUF); + lua_assert(cp->p != NULL); + cp_get(cp); /* Read-ahead first char. */ + cp->tok = 0; + cp->tmask = CPNS_DEFAULT; + cp_next(cp); /* Read-ahead first token. */ +} + +/* Cleanup C parser state. */ +static void cp_cleanup(CPState *cp) +{ + global_State *g = G(cp->L); + lj_str_freebuf(g, &cp->sb); +} + +/* Check and consume optional token. */ +static int cp_opt(CPState *cp, CPToken tok) +{ + if (cp->tok == tok) { cp_next(cp); return 1; } + return 0; +} + +/* Check and consume token. */ +static void cp_check(CPState *cp, CPToken tok) +{ + if (cp->tok != tok) cp_err_token(cp, tok); + cp_next(cp); +} + +/* Check if the next token may start a type declaration. */ +static int cp_istypedecl(CPState *cp) +{ + if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECL) return 1; + if (cp->tok == CTOK_IDENT && ctype_istypedef(cp->ct->info)) return 1; + if (cp->tok == '$') return 1; + return 0; +} + +/* -- Constant expression evaluator --------------------------------------- */ + +/* Forward declarations. */ +static void cp_expr_unary(CPState *cp, CPValue *k); +static void cp_expr_sub(CPState *cp, CPValue *k, int pri); + +/* Please note that type handling is very weak here. Most ops simply +** assume integer operands. Accessors are only needed to compute types and +** return synthetic values. The only purpose of the expression evaluator +** is to compute the values of constant expressions one would typically +** find in C header files. And again: this is NOT a validating C parser! +*/ + +/* Parse comma separated expression and return last result. */ +static void cp_expr_comma(CPState *cp, CPValue *k) +{ + do { cp_expr_sub(cp, k, 0); } while (cp_opt(cp, ',')); +} + +/* Parse sizeof/alignof operator. */ +static void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz) +{ + CTSize sz; + CTInfo info; + if (cp_opt(cp, '(')) { + if (cp_istypedecl(cp)) + k->id = cp_decl_abstract(cp); + else + cp_expr_comma(cp, k); + cp_check(cp, ')'); + } else { + cp_expr_unary(cp, k); + } + info = lj_ctype_info(cp->cts, k->id, &sz); + if (wantsz) { + if (sz != CTSIZE_INVALID) + k->u32 = sz; + else if (k->id != CTID_A_CCHAR) /* Special case for sizeof("string"). */ + cp_err(cp, LJ_ERR_FFI_INVSIZE); + } else { + k->u32 = 1u << ctype_align(info); + } + k->id = CTID_UINT32; /* Really size_t. */ +} + +/* Parse prefix operators. */ +static void cp_expr_prefix(CPState *cp, CPValue *k) +{ + if (cp->tok == CTOK_INTEGER) { + *k = cp->val; cp_next(cp); + } else if (cp_opt(cp, '+')) { + cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */ + } else if (cp_opt(cp, '-')) { + cp_expr_unary(cp, k); k->i32 = -k->i32; + } else if (cp_opt(cp, '~')) { + cp_expr_unary(cp, k); k->i32 = ~k->i32; + } else if (cp_opt(cp, '!')) { + cp_expr_unary(cp, k); k->i32 = !k->i32; k->id = CTID_INT32; + } else if (cp_opt(cp, '(')) { + if (cp_istypedecl(cp)) { /* Cast operator. */ + CTypeID id = cp_decl_abstract(cp); + cp_check(cp, ')'); + cp_expr_unary(cp, k); + k->id = id; /* No conversion performed. */ + } else { /* Sub-expression. */ + cp_expr_comma(cp, k); + cp_check(cp, ')'); + } + } else if (cp_opt(cp, '*')) { /* Indirection. */ + CType *ct; + cp_expr_unary(cp, k); + ct = lj_ctype_rawref(cp->cts, k->id); + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + k->u32 = 0; k->id = ctype_cid(ct->info); + } else if (cp_opt(cp, '&')) { /* Address operator. */ + cp_expr_unary(cp, k); + k->id = lj_ctype_intern(cp->cts, CTINFO(CT_PTR, CTALIGN_PTR+k->id), + CTSIZE_PTR); + } else if (cp_opt(cp, CTOK_SIZEOF)) { + cp_expr_sizeof(cp, k, 1); + } else if (cp_opt(cp, CTOK_ALIGNOF)) { + cp_expr_sizeof(cp, k, 0); + } else if (cp->tok == CTOK_IDENT) { + if (ctype_type(cp->ct->info) == CT_CONSTVAL) { + k->u32 = cp->ct->size; k->id = ctype_cid(cp->ct->info); + } else if (ctype_type(cp->ct->info) == CT_EXTERN) { + k->u32 = cp->val.id; k->id = ctype_cid(cp->ct->info); + } else if (ctype_type(cp->ct->info) == CT_FUNC) { + k->u32 = cp->val.id; k->id = cp->val.id; + } else { + goto err_expr; + } + cp_next(cp); + } else if (cp->tok == CTOK_STRING) { + CTSize sz = cp->str->len; + while (cp_next(cp) == CTOK_STRING) + sz += cp->str->len; + k->u32 = sz + 1; + k->id = CTID_A_CCHAR; + } else { + err_expr: + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + } +} + +/* Parse postfix operators. */ +static void cp_expr_postfix(CPState *cp, CPValue *k) +{ + for (;;) { + CType *ct; + if (cp_opt(cp, '[')) { /* Array/pointer index. */ + CPValue k2; + cp_expr_comma(cp, &k2); + ct = lj_ctype_rawref(cp->cts, k->id); + if (!ctype_ispointer(ct->info)) { + ct = lj_ctype_rawref(cp->cts, k2.id); + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + } + cp_check(cp, ']'); + k->u32 = 0; + } else if (cp->tok == '.' || cp->tok == CTOK_DEREF) { /* Struct deref. */ + CTSize ofs; + CType *fct; + ct = lj_ctype_rawref(cp->cts, k->id); + if (cp->tok == CTOK_DEREF) { + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + ct = lj_ctype_rawref(cp->cts, ctype_cid(ct->info)); + } + cp_next(cp); + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (!ctype_isstruct(ct->info) || ct->size == CTSIZE_INVALID || + !(fct = lj_ctype_getfield(cp->cts, ct, cp->str, &ofs)) || + ctype_isbitfield(fct->info)) { + GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL); + cp_errmsg(cp, 0, LJ_ERR_FFI_BADMEMBER, strdata(s), strdata(cp->str)); + } + ct = fct; + k->u32 = ctype_isconstval(ct->info) ? ct->size : 0; + cp_next(cp); + } else { + return; + } + k->id = ctype_cid(ct->info); + } +} + +/* Parse infix operators. */ +static void cp_expr_infix(CPState *cp, CPValue *k, int pri) +{ + CPValue k2; + k2.u32 = 0; k2.id = 0; /* Silence the compiler. */ + for (;;) { + switch (pri) { + case 0: + if (cp_opt(cp, '?')) { + CPValue k3; + cp_expr_comma(cp, &k2); /* Right-associative. */ + cp_check(cp, ':'); + cp_expr_sub(cp, &k3, 0); + k->u32 = k->u32 ? k2.u32 : k3.u32; + k->id = k2.id > k3.id ? k2.id : k3.id; + continue; + } + case 1: + if (cp_opt(cp, CTOK_OROR)) { + cp_expr_sub(cp, &k2, 2); k->i32 = k->u32 || k2.u32; k->id = CTID_INT32; + continue; + } + case 2: + if (cp_opt(cp, CTOK_ANDAND)) { + cp_expr_sub(cp, &k2, 3); k->i32 = k->u32 && k2.u32; k->id = CTID_INT32; + continue; + } + case 3: + if (cp_opt(cp, '|')) { + cp_expr_sub(cp, &k2, 4); k->u32 = k->u32 | k2.u32; goto arith_result; + } + case 4: + if (cp_opt(cp, '^')) { + cp_expr_sub(cp, &k2, 5); k->u32 = k->u32 ^ k2.u32; goto arith_result; + } + case 5: + if (cp_opt(cp, '&')) { + cp_expr_sub(cp, &k2, 6); k->u32 = k->u32 & k2.u32; goto arith_result; + } + case 6: + if (cp_opt(cp, CTOK_EQ)) { + cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 == k2.u32; k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_NE)) { + cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 != k2.u32; k->id = CTID_INT32; + continue; + } + case 7: + if (cp_opt(cp, '<')) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 < k2.i32; + else + k->i32 = k->u32 < k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, '>')) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 > k2.i32; + else + k->i32 = k->u32 > k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_LE)) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 <= k2.i32; + else + k->i32 = k->u32 <= k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_GE)) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 >= k2.i32; + else + k->i32 = k->u32 >= k2.u32; + k->id = CTID_INT32; + continue; + } + case 8: + if (cp_opt(cp, CTOK_SHL)) { + cp_expr_sub(cp, &k2, 9); k->u32 = k->u32 << k2.u32; + continue; + } else if (cp_opt(cp, CTOK_SHR)) { + cp_expr_sub(cp, &k2, 9); + if (k->id == CTID_INT32) + k->i32 = k->i32 >> k2.i32; + else + k->u32 = k->u32 >> k2.u32; + continue; + } + case 9: + if (cp_opt(cp, '+')) { + cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 + k2.u32; + arith_result: + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + continue; + } else if (cp_opt(cp, '-')) { + cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 - k2.u32; goto arith_result; + } + case 10: + if (cp_opt(cp, '*')) { + cp_expr_unary(cp, &k2); k->u32 = k->u32 * k2.u32; goto arith_result; + } else if (cp_opt(cp, '/')) { + cp_expr_unary(cp, &k2); + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + if (k2.u32 == 0 || + (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1)) + cp_err(cp, LJ_ERR_BADVAL); + if (k->id == CTID_INT32) + k->i32 = k->i32 / k2.i32; + else + k->u32 = k->u32 / k2.u32; + continue; + } else if (cp_opt(cp, '%')) { + cp_expr_unary(cp, &k2); + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + if (k2.u32 == 0 || + (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1)) + cp_err(cp, LJ_ERR_BADVAL); + if (k->id == CTID_INT32) + k->i32 = k->i32 % k2.i32; + else + k->u32 = k->u32 % k2.u32; + continue; + } + default: + return; + } + } +} + +/* Parse and evaluate unary expression. */ +static void cp_expr_unary(CPState *cp, CPValue *k) +{ + if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS); + cp_expr_prefix(cp, k); + cp_expr_postfix(cp, k); + cp->depth--; +} + +/* Parse and evaluate sub-expression. */ +static void cp_expr_sub(CPState *cp, CPValue *k, int pri) +{ + cp_expr_unary(cp, k); + cp_expr_infix(cp, k, pri); +} + +/* Parse constant integer expression. */ +static void cp_expr_kint(CPState *cp, CPValue *k) +{ + CType *ct; + cp_expr_sub(cp, k, 0); + ct = ctype_raw(cp->cts, k->id); + if (!ctype_isinteger(ct->info)) cp_err(cp, LJ_ERR_BADVAL); +} + +/* Parse (non-negative) size expression. */ +static CTSize cp_expr_ksize(CPState *cp) +{ + CPValue k; + cp_expr_kint(cp, &k); + if (k.u32 >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE); + return k.u32; +} + +/* -- Type declaration stack management ----------------------------------- */ + +/* Add declaration element behind the insertion position. */ +static CPDeclIdx cp_add(CPDecl *decl, CTInfo info, CTSize size) +{ + CPDeclIdx top = decl->top; + if (top >= CPARSE_MAX_DECLSTACK) cp_err(decl->cp, LJ_ERR_XLEVELS); + decl->stack[top].info = info; + decl->stack[top].size = size; + decl->stack[top].sib = 0; + setgcrefnull(decl->stack[top].name); + decl->stack[top].next = decl->stack[decl->pos].next; + decl->stack[decl->pos].next = (CTypeID1)top; + decl->top = top+1; + return top; +} + +/* Push declaration element before the insertion position. */ +static CPDeclIdx cp_push(CPDecl *decl, CTInfo info, CTSize size) +{ + return (decl->pos = cp_add(decl, info, size)); +} + +/* Push or merge attributes. */ +static void cp_push_attributes(CPDecl *decl) +{ + CType *ct = &decl->stack[decl->pos]; + if (ctype_isfunc(ct->info)) { /* Ok to modify in-place. */ +#if LJ_TARGET_X86 + if ((decl->fattr & CTFP_CCONV)) + ct->info = (ct->info & (CTMASK_NUM|CTF_VARARG|CTMASK_CID)) + + (decl->fattr & ~CTMASK_CID); +#endif + } else { + if ((decl->attr & CTFP_ALIGNED) && !(decl->mode & CPARSE_MODE_FIELD)) + cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_ALIGN)), + ctype_align(decl->attr)); + } +} + +/* Push unrolled type to declaration stack and merge qualifiers. */ +static void cp_push_type(CPDecl *decl, CTypeID id) +{ + CType *ct = ctype_get(decl->cp->cts, id); + CTInfo info = ct->info; + CTSize size = ct->size; + switch (ctype_type(info)) { + case CT_STRUCT: case CT_ENUM: + cp_push(decl, CTINFO(CT_TYPEDEF, id), 0); /* Don't copy unique types. */ + if ((decl->attr & CTF_QUAL)) { /* Push unmerged qualifiers. */ + cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_QUAL)), + (decl->attr & CTF_QUAL)); + decl->attr &= ~CTF_QUAL; + } + break; + case CT_ATTRIB: + if (ctype_isxattrib(info, CTA_QUAL)) + decl->attr &= ~size; /* Remove redundant qualifiers. */ + cp_push_type(decl, ctype_cid(info)); /* Unroll. */ + cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ + break; + case CT_ARRAY: + cp_push_type(decl, ctype_cid(info)); /* Unroll. */ + cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ + decl->stack[decl->pos].sib = 1; /* Mark as already checked and sized. */ + /* Note: this is not copied to the ct->sib in the C type table. */ + break; + case CT_FUNC: + /* Copy type, link parameters (shared). */ + decl->stack[cp_push(decl, info, size)].sib = ct->sib; + break; + default: + /* Copy type, merge common qualifiers. */ + cp_push(decl, info|(decl->attr & CTF_QUAL), size); + decl->attr &= ~CTF_QUAL; + break; + } +} + +/* Consume the declaration element chain and intern the C type. */ +static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl) +{ + CTypeID id = 0; + CPDeclIdx idx = 0; + CTSize csize = CTSIZE_INVALID; + CTSize cinfo = 0; + do { + CType *ct = &decl->stack[idx]; + CTInfo info = ct->info; + CTInfo size = ct->size; + /* The cid is already part of info for copies of pointers/functions. */ + idx = ct->next; + if (ctype_istypedef(info)) { + lua_assert(id == 0); + id = ctype_cid(info); + /* Always refetch info/size, since struct/enum may have been completed. */ + cinfo = ctype_get(cp->cts, id)->info; + csize = ctype_get(cp->cts, id)->size; + lua_assert(ctype_isstruct(cinfo) || ctype_isenum(cinfo)); + } else if (ctype_isfunc(info)) { /* Intern function. */ + CType *fct; + CTypeID fid; + CTypeID sib; + if (id) { + CType *refct = ctype_raw(cp->cts, id); + /* Reject function or refarray return types. */ + if (ctype_isfunc(refct->info) || ctype_isrefarray(refct->info)) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + } + /* No intervening attributes allowed, skip forward. */ + while (idx) { + CType *ctn = &decl->stack[idx]; + if (!ctype_isattrib(ctn->info)) break; + idx = ctn->next; /* Skip attribute. */ + } + sib = ct->sib; /* Next line may reallocate the C type table. */ + fid = lj_ctype_new(cp->cts, &fct); + csize = CTSIZE_INVALID; + fct->info = cinfo = info + id; + fct->size = size; + fct->sib = sib; + id = fid; + } else if (ctype_isattrib(info)) { + if (ctype_isxattrib(info, CTA_QUAL)) + cinfo |= size; + else if (ctype_isxattrib(info, CTA_ALIGN)) + CTF_INSERT(cinfo, ALIGN, size); + id = lj_ctype_intern(cp->cts, info+id, size); + /* Inherit csize/cinfo from original type. */ + } else { + if (ctype_isnum(info)) { /* Handle mode/vector-size attributes. */ + lua_assert(id == 0); + if (!(info & CTF_BOOL)) { + CTSize msize = ctype_msizeP(decl->attr); + CTSize vsize = ctype_vsizeP(decl->attr); + if (msize && (!(info & CTF_FP) || (msize == 4 || msize == 8))) { + CTSize malign = lj_fls(msize); + if (malign > 4) malign = 4; /* Limit alignment. */ + CTF_INSERT(info, ALIGN, malign); + size = msize; /* Override size via mode. */ + } + if (vsize) { /* Vector size set? */ + CTSize esize = lj_fls(size); + if (vsize >= esize) { + /* Intern the element type first. */ + id = lj_ctype_intern(cp->cts, info, size); + /* Then create a vector (array) with vsize alignment. */ + size = (1u << vsize); + if (vsize > 4) vsize = 4; /* Limit alignment. */ + if (ctype_align(info) > vsize) vsize = ctype_align(info); + info = CTINFO(CT_ARRAY, (info & CTF_QUAL) + CTF_VECTOR + + CTALIGN(vsize)); + } + } + } + } else if (ctype_isptr(info)) { + /* Reject pointer/ref to ref. */ + if (id && ctype_isref(ctype_raw(cp->cts, id)->info)) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + if (ctype_isref(info)) { + info &= ~CTF_VOLATILE; /* Refs are always const, never volatile. */ + /* No intervening attributes allowed, skip forward. */ + while (idx) { + CType *ctn = &decl->stack[idx]; + if (!ctype_isattrib(ctn->info)) break; + idx = ctn->next; /* Skip attribute. */ + } + } + } else if (ctype_isarray(info)) { /* Check for valid array size etc. */ + if (ct->sib == 0) { /* Only check/size arrays not copied by unroll. */ + if (ctype_isref(cinfo)) /* Reject arrays of refs. */ + cp_err(cp, LJ_ERR_FFI_INVTYPE); + /* Reject VLS or unknown-sized types. */ + if (ctype_isvltype(cinfo) || csize == CTSIZE_INVALID) + cp_err(cp, LJ_ERR_FFI_INVSIZE); + /* a[] and a[?] keep their invalid size. */ + if (size != CTSIZE_INVALID) { + uint64_t xsz = (uint64_t)size * csize; + if (xsz >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE); + size = (CTSize)xsz; + } + } + if ((cinfo & CTF_ALIGN) > (info & CTF_ALIGN)) /* Find max. align. */ + info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN); + info |= (cinfo & CTF_QUAL); /* Inherit qual. */ + } else { + lua_assert(ctype_isvoid(info)); + } + csize = size; + cinfo = info+id; + id = lj_ctype_intern(cp->cts, info+id, size); + } + } while (idx); + return id; +} + +/* -- C declaration parser ------------------------------------------------ */ + +#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be) + +/* Reset declaration state to declaration specifier. */ +static void cp_decl_reset(CPDecl *decl) +{ + decl->pos = decl->specpos; + decl->top = decl->specpos+1; + decl->stack[decl->specpos].next = 0; + decl->attr = decl->specattr; + decl->fattr = decl->specfattr; + decl->name = NULL; + decl->redir = NULL; +} + +/* Parse constant initializer. */ +/* NYI: FP constants and strings as initializers. */ +static CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID ctypeid) +{ + CType *ctt = ctype_get(cp->cts, ctypeid); + CTInfo info; + CTSize size; + CPValue k; + CTypeID constid; + while (ctype_isattrib(ctt->info)) { /* Skip attributes. */ + ctypeid = ctype_cid(ctt->info); /* Update ID, too. */ + ctt = ctype_get(cp->cts, ctypeid); + } + info = ctt->info; + size = ctt->size; + if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + cp_check(cp, '='); + cp_expr_sub(cp, &k, 0); + constid = lj_ctype_new(cp->cts, ctp); + (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|ctypeid); + k.u32 <<= 8*(4-size); + if ((info & CTF_UNSIGNED)) + k.u32 >>= 8*(4-size); + else + k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size)); + (*ctp)->size = k.u32; + return constid; +} + +/* Parse size in parentheses as part of attribute. */ +static CTSize cp_decl_sizeattr(CPState *cp) +{ + CTSize sz; + uint32_t oldtmask = cp->tmask; + cp->tmask = CPNS_DEFAULT; /* Required for expression evaluator. */ + cp_check(cp, '('); + sz = cp_expr_ksize(cp); + cp->tmask = oldtmask; + cp_check(cp, ')'); + return sz; +} + +/* Parse alignment attribute. */ +static void cp_decl_align(CPState *cp, CPDecl *decl) +{ + CTSize al = 4; /* Unspecified alignment is 16 bytes. */ + if (cp->tok == '(') { + al = cp_decl_sizeattr(cp); + al = al ? lj_fls(al) : 0; + } + CTF_INSERT(decl->attr, ALIGN, al); + decl->attr |= CTFP_ALIGNED; +} + +/* Parse GCC asm("name") redirect. */ +static void cp_decl_asm(CPState *cp, CPDecl *decl) +{ + UNUSED(decl); + cp_next(cp); + cp_check(cp, '('); + if (cp->tok == CTOK_STRING) { + GCstr *str = cp->str; + while (cp_next(cp) == CTOK_STRING) { + lj_str_pushf(cp->L, "%s%s", strdata(str), strdata(cp->str)); + cp->L->top--; + str = strV(cp->L->top); + } + decl->redir = str; + } + cp_check(cp, ')'); +} + +/* Parse GCC __attribute__((mode(...))). */ +static void cp_decl_mode(CPState *cp, CPDecl *decl) +{ + cp_check(cp, '('); + if (cp->tok == CTOK_IDENT) { + const char *s = strdata(cp->str); + CTSize sz = 0, vlen = 0; + if (s[0] == '_' && s[1] == '_') s += 2; + if (*s == 'V') { + s++; + vlen = *s++ - '0'; + if (*s >= '0' && *s <= '9') + vlen = vlen*10 + (*s++ - '0'); + } + switch (*s++) { + case 'Q': sz = 1; break; + case 'H': sz = 2; break; + case 'S': sz = 4; break; + case 'D': sz = 8; break; + case 'T': sz = 16; break; + case 'O': sz = 32; break; + default: goto bad_size; + } + if (*s == 'I' || *s == 'F') { + CTF_INSERT(decl->attr, MSIZEP, sz); + if (vlen) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vlen*sz)); + } + bad_size: + cp_next(cp); + } + cp_check(cp, ')'); +} + +/* Parse GCC __attribute__((...)). */ +static void cp_decl_gccattribute(CPState *cp, CPDecl *decl) +{ + cp_next(cp); + cp_check(cp, '('); + cp_check(cp, '('); + while (cp->tok != ')') { + if (cp->tok == CTOK_IDENT) { + GCstr *attrstr = cp->str; + cp_next(cp); + switch (attrstr->hash) { + case H_(64a9208e,8ce14319): case H_(8e6331b2,95a282af): /* aligned */ + cp_decl_align(cp, decl); + break; + case H_(42eb47de,f0ede26c): case H_(29f48a09,cf383e0c): /* packed */ + decl->attr |= CTFP_PACKED; + break; + case H_(0a84eef6,8dfab04c): case H_(995cf92c,d5696591): /* mode */ + cp_decl_mode(cp, decl); + break; + case H_(0ab31997,2d5213fa): case H_(bf875611,200e9990): /* vector_size */ + { + CTSize vsize = cp_decl_sizeattr(cp); + if (vsize) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vsize)); + } + break; +#if LJ_TARGET_X86 + case H_(5ad22db8,c689b848): case H_(439150fa,65ea78cb): /* regparm */ + CTF_INSERT(decl->fattr, REGPARM, cp_decl_sizeattr(cp)); + decl->fattr |= CTFP_CCONV; + break; + case H_(18fc0b98,7ff4c074): case H_(4e62abed,0a747424): /* cdecl */ + CTF_INSERT(decl->fattr, CCONV, CTCC_CDECL); + decl->fattr |= CTFP_CCONV; + break; + case H_(72b2e41b,494c5a44): case H_(f2356d59,f25fc9bd): /* thiscall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_THISCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(0d0ffc42,ab746f88): case H_(21c54ba1,7f0ca7e3): /* fastcall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_FASTCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(ef76b040,9412e06a): case H_(de56697b,c750e6e1): /* stdcall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_STDCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(ea78b622,f234bd8e): case H_(252ffb06,8d50f34b): /* sseregparm */ + decl->fattr |= CTF_SSEREGPARM; + decl->fattr |= CTFP_CCONV; + break; +#endif + default: /* Skip all other attributes. */ + goto skip_attr; + } + } else if (cp->tok >= CTOK_FIRSTDECL) { /* For __attribute((const)) etc. */ + cp_next(cp); + skip_attr: + if (cp_opt(cp, '(')) { + while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp); + cp_check(cp, ')'); + } + } else { + break; + } + if (!cp_opt(cp, ',')) break; + } + cp_check(cp, ')'); + cp_check(cp, ')'); +} + +/* Parse MSVC __declspec(...). */ +static void cp_decl_msvcattribute(CPState *cp, CPDecl *decl) +{ + cp_next(cp); + cp_check(cp, '('); + while (cp->tok == CTOK_IDENT) { + GCstr *attrstr = cp->str; + cp_next(cp); + switch (attrstr->hash) { + case H_(bc2395fa,98f267f8): /* align */ + cp_decl_align(cp, decl); + break; + default: /* Ignore all other attributes. */ + if (cp_opt(cp, '(')) { + while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp); + cp_check(cp, ')'); + } + break; + } + } + cp_check(cp, ')'); +} + +/* Parse declaration attributes (and common qualifiers). */ +static void cp_decl_attributes(CPState *cp, CPDecl *decl) +{ + for (;;) { + switch (cp->tok) { + case CTOK_CONST: decl->attr |= CTF_CONST; break; + case CTOK_VOLATILE: decl->attr |= CTF_VOLATILE; break; + case CTOK_RESTRICT: break; /* Ignore. */ + case CTOK_EXTENSION: break; /* Ignore. */ + case CTOK_ATTRIBUTE: cp_decl_gccattribute(cp, decl); continue; + case CTOK_ASM: cp_decl_asm(cp, decl); continue; + case CTOK_DECLSPEC: cp_decl_msvcattribute(cp, decl); continue; + case CTOK_CCDECL: +#if LJ_TARGET_X86 + CTF_INSERT(decl->fattr, CCONV, cp->ct->size); + decl->fattr |= CTFP_CCONV; +#endif + break; + case CTOK_PTRSZ: +#if LJ_64 + CTF_INSERT(decl->attr, MSIZEP, cp->ct->size); +#endif + break; + default: return; + } + cp_next(cp); + } +} + +/* Parse struct/union/enum name. */ +static CTypeID cp_struct_name(CPState *cp, CPDecl *sdecl, CTInfo info) +{ + CTypeID sid; + CType *ct; + cp->tmask = CPNS_STRUCT; + cp_next(cp); + cp_decl_attributes(cp, sdecl); + cp->tmask = CPNS_DEFAULT; + if (cp->tok != '{') { + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (cp->val.id) { /* Name of existing struct/union/enum. */ + sid = cp->val.id; + ct = cp->ct; + if ((ct->info ^ info) & (CTMASK_NUM|CTF_UNION)) /* Wrong type. */ + cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name)))); + } else { /* Create named, incomplete struct/union/enum. */ + if ((cp->mode & CPARSE_MODE_NOIMPLICIT)) + cp_errmsg(cp, 0, LJ_ERR_FFI_BADTAG, strdata(cp->str)); + sid = lj_ctype_new(cp->cts, &ct); + ct->info = info; + ct->size = CTSIZE_INVALID; + ctype_setname(ct, cp->str); + lj_ctype_addname(cp->cts, ct, sid); + } + cp_next(cp); + } else { /* Create anonymous, incomplete struct/union/enum. */ + sid = lj_ctype_new(cp->cts, &ct); + ct->info = info; + ct->size = CTSIZE_INVALID; + } + if (cp->tok == '{') { + if (ct->size != CTSIZE_INVALID || ct->sib) + cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name)))); + ct->sib = 1; /* Indicate the type is currently being defined. */ + } + return sid; +} + +/* Determine field alignment. */ +static CTSize cp_field_align(CPState *cp, CType *ct, CTInfo info) +{ + CTSize align = ctype_align(info); + UNUSED(cp); UNUSED(ct); +#if (LJ_TARGET_X86 && !LJ_ABI_WIN) || (LJ_TARGET_ARM && __APPLE__) + /* The SYSV i386 and iOS ABIs limit alignment of non-vector fields to 2^2. */ + if (align > 2 && !(info & CTFP_ALIGNED)) { + if (ctype_isarray(info) && !(info & CTF_VECTOR)) { + do { + ct = ctype_rawchild(cp->cts, ct); + info = ct->info; + } while (ctype_isarray(info) && !(info & CTF_VECTOR)); + } + if (ctype_isnum(info) || ctype_isenum(info)) + align = 2; + } +#endif + return align; +} + +/* Layout struct/union fields. */ +static void cp_struct_layout(CPState *cp, CTypeID sid, CTInfo sattr) +{ + CTSize bofs = 0, bmaxofs = 0; /* Bit offset and max. bit offset. */ + CTSize maxalign = ctype_align(sattr); + CType *sct = ctype_get(cp->cts, sid); + CTInfo sinfo = sct->info; + CTypeID fieldid = sct->sib; + while (fieldid) { + CType *ct = ctype_get(cp->cts, fieldid); + CTInfo attr = ct->size; /* Field declaration attributes (temp.). */ + + if (ctype_isfield(ct->info) || + (ctype_isxattrib(ct->info, CTA_SUBTYPE) && attr)) { + CTSize align, amask; /* Alignment (pow2) and alignment mask (bits). */ + CTSize sz; + CTInfo info = lj_ctype_info(cp->cts, ctype_cid(ct->info), &sz); + CTSize bsz, csz = 8*sz; /* Field size and container size (in bits). */ + sinfo |= (info & (CTF_QUAL|CTF_VLA)); /* Merge pseudo-qualifiers. */ + + /* Check for size overflow and determine alignment. */ + if (sz >= 0x20000000u || bofs + csz < bofs || (info & CTF_VLA)) { + if (!(sz == CTSIZE_INVALID && ctype_isarray(info) && + !(sinfo & CTF_UNION))) + cp_err(cp, LJ_ERR_FFI_INVSIZE); + csz = sz = 0; /* Treat a[] and a[?] as zero-sized. */ + } + align = cp_field_align(cp, ct, info); + if (((attr|sattr) & CTFP_PACKED) || + ((attr & CTFP_ALIGNED) && ctype_align(attr) > align)) + align = ctype_align(attr); + if (cp->packstack[cp->curpack] < align) + align = cp->packstack[cp->curpack]; + if (align > maxalign) maxalign = align; + amask = (8u << align) - 1; + + bsz = ctype_bitcsz(ct->info); /* Bitfield size (temp.). */ + if (bsz == CTBSZ_FIELD || !ctype_isfield(ct->info)) { + bsz = csz; /* Regular fields or subtypes always fill the container. */ + bofs = (bofs + amask) & ~amask; /* Start new aligned field. */ + ct->size = (bofs >> 3); /* Store field offset. */ + } else { /* Bitfield. */ + if (bsz == 0 || (attr & CTFP_ALIGNED) || + (!((attr|sattr) & CTFP_PACKED) && (bofs & amask) + bsz > csz)) + bofs = (bofs + amask) & ~amask; /* Start new aligned field. */ + + /* Prefer regular field over bitfield. */ + if (bsz == csz && (bofs & amask) == 0) { + ct->info = CTINFO(CT_FIELD, ctype_cid(ct->info)); + ct->size = (bofs >> 3); /* Store field offset. */ + } else { + ct->info = CTINFO(CT_BITFIELD, + (info & (CTF_QUAL|CTF_UNSIGNED|CTF_BOOL)) + + (csz << (CTSHIFT_BITCSZ-3)) + (bsz << CTSHIFT_BITBSZ)); +#if LJ_BE + ct->info += ((csz - (bofs & (csz-1)) - bsz) << CTSHIFT_BITPOS); +#else + ct->info += ((bofs & (csz-1)) << CTSHIFT_BITPOS); +#endif + ct->size = ((bofs & ~(csz-1)) >> 3); /* Store container offset. */ + } + } + + /* Determine next offset or max. offset. */ + if ((sinfo & CTF_UNION)) { + if (bsz > bmaxofs) bmaxofs = bsz; + } else { + bofs += bsz; + } + } /* All other fields in the chain are already set up. */ + + fieldid = ct->sib; + } + + /* Complete struct/union. */ + sct->info = sinfo + CTALIGN(maxalign); + bofs = (sinfo & CTF_UNION) ? bmaxofs : bofs; + maxalign = (8u << maxalign) - 1; + sct->size = (((bofs + maxalign) & ~maxalign) >> 3); +} + +/* Parse struct/union declaration. */ +static CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo) +{ + CTypeID sid = cp_struct_name(cp, sdecl, sinfo); + if (cp_opt(cp, '{')) { /* Struct/union definition. */ + CTypeID lastid = sid; + int lastdecl = 0; + while (cp->tok != '}') { + CPDecl decl; + CPscl scl = cp_decl_spec(cp, &decl, CDF_STATIC); + decl.mode = scl ? CPARSE_MODE_DIRECT : + CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD; + + for (;;) { + CTypeID ctypeid; + + if (lastdecl) cp_err_token(cp, '}'); + + /* Parse field declarator. */ + decl.bits = CTSIZE_INVALID; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + + if ((scl & CDF_STATIC)) { /* Static constant in struct namespace. */ + CType *ct; + CTypeID fieldid = cp_decl_constinit(cp, &ct, ctypeid); + ctype_get(cp->cts, lastid)->sib = fieldid; + lastid = fieldid; + ctype_setname(ct, decl.name); + } else { + CTSize bsz = CTBSZ_FIELD; /* Temp. for layout phase. */ + CType *ct; + CTypeID fieldid = lj_ctype_new(cp->cts, &ct); /* Do this first. */ + CType *tct = ctype_raw(cp->cts, ctypeid); + + if (decl.bits == CTSIZE_INVALID) { /* Regular field. */ + if (ctype_isarray(tct->info) && tct->size == CTSIZE_INVALID) + lastdecl = 1; /* a[] or a[?] must be the last declared field. */ + + /* Accept transparent struct/union/enum. */ + if (!decl.name) { + if (!((ctype_isstruct(tct->info) && !(tct->info & CTF_VLA)) || + ctype_isenum(tct->info))) + cp_err_token(cp, CTOK_IDENT); + ct->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_SUBTYPE) + ctypeid); + ct->size = ctype_isstruct(tct->info) ? + (decl.attr|0x80000000u) : 0; /* For layout phase. */ + goto add_field; + } + } else { /* Bitfield. */ + bsz = decl.bits; + if (!ctype_isinteger_or_bool(tct->info) || + (bsz == 0 && decl.name) || 8*tct->size > CTBSZ_MAX || + bsz > ((tct->info & CTF_BOOL) ? 1 : 8*tct->size)) + cp_errmsg(cp, ':', LJ_ERR_BADVAL); + } + + /* Create temporary field for layout phase. */ + ct->info = CTINFO(CT_FIELD, ctypeid + (bsz << CTSHIFT_BITCSZ)); + ct->size = decl.attr; + if (decl.name) ctype_setname(ct, decl.name); + + add_field: + ctype_get(cp->cts, lastid)->sib = fieldid; + lastid = fieldid; + } + if (!cp_opt(cp, ',')) break; + cp_decl_reset(&decl); + } + cp_check(cp, ';'); + } + cp_check(cp, '}'); + ctype_get(cp->cts, lastid)->sib = 0; /* Drop sib = 1 for empty structs. */ + cp_decl_attributes(cp, sdecl); /* Layout phase needs postfix attributes. */ + cp_struct_layout(cp, sid, sdecl->attr); + } + return sid; +} + +/* Parse enum declaration. */ +static CTypeID cp_decl_enum(CPState *cp, CPDecl *sdecl) +{ + CTypeID eid = cp_struct_name(cp, sdecl, CTINFO(CT_ENUM, CTID_VOID)); + CTInfo einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_UINT32); + CTSize esize = 4; /* Only 32 bit enums are supported. */ + if (cp_opt(cp, '{')) { /* Enum definition. */ + CPValue k; + CTypeID lastid = eid; + k.u32 = 0; + k.id = CTID_INT32; + do { + GCstr *name = cp->str; + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (cp->val.id) cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(name)); + cp_next(cp); + if (cp_opt(cp, '=')) { + cp_expr_kint(cp, &k); + if (k.id == CTID_UINT32) { + /* C99 says that enum constants are always (signed) integers. + ** But since unsigned constants like 0x80000000 are quite common, + ** those are left as uint32_t. + */ + if (k.i32 >= 0) k.id = CTID_INT32; + } else { + /* OTOH it's common practice and even mandated by some ABIs + ** that the enum type itself is unsigned, unless there are any + ** negative constants. + */ + k.id = CTID_INT32; + if (k.i32 < 0) einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_INT32); + } + } + /* Add named enum constant. */ + { + CType *ct; + CTypeID constid = lj_ctype_new(cp->cts, &ct); + ctype_get(cp->cts, lastid)->sib = constid; + lastid = constid; + ctype_setname(ct, name); + ct->info = CTINFO(CT_CONSTVAL, CTF_CONST|k.id); + ct->size = k.u32++; + if (k.u32 == 0x80000000u) k.id = CTID_UINT32; + lj_ctype_addname(cp->cts, ct, constid); + } + if (!cp_opt(cp, ',')) break; + } while (cp->tok != '}'); /* Trailing ',' is ok. */ + cp_check(cp, '}'); + /* Complete enum. */ + ctype_get(cp->cts, eid)->info = einfo; + ctype_get(cp->cts, eid)->size = esize; + } + return eid; +} + +/* Parse declaration specifiers. */ +static CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl) +{ + uint32_t cds = 0, sz = 0; + CTypeID tdef = 0; + + decl->cp = cp; + decl->mode = cp->mode; + decl->name = NULL; + decl->redir = NULL; + decl->attr = 0; + decl->fattr = 0; + decl->pos = decl->top = 0; + decl->stack[0].next = 0; + + for (;;) { /* Parse basic types. */ + cp_decl_attributes(cp, decl); + if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) { + uint32_t cbit; + if (cp->ct->size) { + if (sz) goto end_decl; + sz = cp->ct->size; + } + cbit = (1u << (cp->tok - CTOK_FIRSTDECL)); + cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1); + if (cp->tok >= CTOK_FIRSTSCL) { + if (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL); + } else if (tdef) { + goto end_decl; + } + cp_next(cp); + continue; + } + if (sz || tdef || + (cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX))) + break; + switch (cp->tok) { + case CTOK_STRUCT: + tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0)); + continue; + case CTOK_UNION: + tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION)); + continue; + case CTOK_ENUM: + tdef = cp_decl_enum(cp, decl); + continue; + case CTOK_IDENT: + if (ctype_istypedef(cp->ct->info)) { + tdef = ctype_cid(cp->ct->info); /* Get typedef. */ + cp_next(cp); + continue; + } + break; + case '$': + tdef = cp->val.id; + cp_next(cp); + continue; + default: + break; + } + break; + } +end_decl: + + if ((cds & CDF_COMPLEX)) /* Use predefined complex types. */ + tdef = sz == 4 ? CTID_COMPLEX_FLOAT : CTID_COMPLEX_DOUBLE; + + if (tdef) { + cp_push_type(decl, tdef); + } else if ((cds & CDF_VOID)) { + cp_push(decl, CTINFO(CT_VOID, (decl->attr & CTF_QUAL)), CTSIZE_INVALID); + decl->attr &= ~CTF_QUAL; + } else { + /* Determine type info and size. */ + CTInfo info = CTINFO(CT_NUM, (cds & CDF_UNSIGNED) ? CTF_UNSIGNED : 0); + if ((cds & CDF_BOOL)) { + if ((cds & ~(CDF_SCL|CDF_BOOL|CDF_INT|CDF_SIGNED|CDF_UNSIGNED))) + cp_errmsg(cp, 0, LJ_ERR_FFI_INVTYPE); + info |= CTF_BOOL; + if (!(cds & CDF_SIGNED)) info |= CTF_UNSIGNED; + if (!sz) { + sz = 1; + } + } else if ((cds & CDF_FP)) { + info = CTINFO(CT_NUM, CTF_FP); + if ((cds & CDF_LONG)) sz = sizeof(long double); + } else if ((cds & CDF_CHAR)) { + if ((cds & (CDF_CHAR|CDF_SIGNED|CDF_UNSIGNED)) == CDF_CHAR) + info |= CTF_UCHAR; /* Handle platforms where char is unsigned. */ + } else if ((cds & CDF_SHORT)) { + sz = sizeof(short); + } else if ((cds & CDF_LONGLONG)) { + sz = 8; + } else if ((cds & CDF_LONG)) { + info |= CTF_LONG; + sz = sizeof(long); + } else if (!sz) { + if (!(cds & (CDF_SIGNED|CDF_UNSIGNED))) + cp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC); + sz = sizeof(int); + } + lua_assert(sz != 0); + info += CTALIGN(lj_fls(sz)); /* Use natural alignment. */ + info += (decl->attr & CTF_QUAL); /* Merge qualifiers. */ + cp_push(decl, info, sz); + decl->attr &= ~CTF_QUAL; + } + decl->specpos = decl->pos; + decl->specattr = decl->attr; + decl->specfattr = decl->fattr; + return (cds & CDF_SCL); /* Return storage class. */ +} + +/* Parse array declaration. */ +static void cp_decl_array(CPState *cp, CPDecl *decl) +{ + CTInfo info = CTINFO(CT_ARRAY, 0); + CTSize nelem = CTSIZE_INVALID; /* Default size for a[] or a[?]. */ + cp_decl_attributes(cp, decl); + if (cp_opt(cp, '?')) + info |= CTF_VLA; /* Create variable-length array a[?]. */ + else if (cp->tok != ']') + nelem = cp_expr_ksize(cp); + cp_check(cp, ']'); + cp_add(decl, info, nelem); +} + +/* Parse function declaration. */ +static void cp_decl_func(CPState *cp, CPDecl *fdecl) +{ + CTSize nargs = 0; + CTInfo info = CTINFO(CT_FUNC, 0); + CTypeID lastid = 0, anchor = 0; + if (cp->tok != ')') { + do { + CPDecl decl; + CTypeID ctypeid, fieldid; + CType *ct; + if (cp_opt(cp, '.')) { /* Vararg function. */ + cp_check(cp, '.'); /* Workaround for the minimalistic lexer. */ + cp_check(cp, '.'); + info |= CTF_VARARG; + break; + } + cp_decl_spec(cp, &decl, CDF_REGISTER); + decl.mode = CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + ct = ctype_raw(cp->cts, ctypeid); + if (ctype_isvoid(ct->info)) + break; + else if (ctype_isrefarray(ct->info)) + ctypeid = lj_ctype_intern(cp->cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ct->info)), CTSIZE_PTR); + else if (ctype_isfunc(ct->info)) + ctypeid = lj_ctype_intern(cp->cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctypeid), CTSIZE_PTR); + /* Add new parameter. */ + fieldid = lj_ctype_new(cp->cts, &ct); + if (anchor) + ctype_get(cp->cts, lastid)->sib = fieldid; + else + anchor = fieldid; + lastid = fieldid; + if (decl.name) ctype_setname(ct, decl.name); + ct->info = CTINFO(CT_FIELD, ctypeid); + ct->size = nargs++; + } while (cp_opt(cp, ',')); + } + cp_check(cp, ')'); + if (cp_opt(cp, '{')) { /* Skip function definition. */ + int level = 1; + cp->mode |= CPARSE_MODE_SKIP; + for (;;) { + if (cp->tok == '{') level++; + else if (cp->tok == '}' && --level == 0) break; + else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}'); + cp_next(cp); + } + cp->mode &= ~CPARSE_MODE_SKIP; + cp->tok = ';'; /* Ok for cp_decl_multi(), error in cp_decl_single(). */ + } + info |= (fdecl->fattr & ~CTMASK_CID); + fdecl->fattr = 0; + fdecl->stack[cp_add(fdecl, info, nargs)].sib = anchor; +} + +/* Parse declarator. */ +static void cp_declarator(CPState *cp, CPDecl *decl) +{ + if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS); + + for (;;) { /* Head of declarator. */ + if (cp_opt(cp, '*')) { /* Pointer. */ + CTSize sz; + CTInfo info; + cp_decl_attributes(cp, decl); + sz = CTSIZE_PTR; + info = CTINFO(CT_PTR, CTALIGN_PTR); +#if LJ_64 + if (ctype_msizeP(decl->attr) == 4) { + sz = 4; + info = CTINFO(CT_PTR, CTALIGN(2)); + } +#endif + info += (decl->attr & (CTF_QUAL|CTF_REF)); + decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<mode & CPARSE_MODE_ABSTRACT) && + (cp->tok == ')' || cp_istypedecl(cp))) goto func_decl; + pos = decl->pos; + cp_declarator(cp, decl); + cp_check(cp, ')'); + decl->pos = pos; + } else if (cp->tok == CTOK_IDENT) { /* Direct declarator. */ + if (!(decl->mode & CPARSE_MODE_DIRECT)) cp_err_token(cp, CTOK_EOF); + decl->name = cp->str; + decl->nameid = cp->val.id; + cp_next(cp); + } else { /* Abstract declarator. */ + if (!(decl->mode & CPARSE_MODE_ABSTRACT)) cp_err_token(cp, CTOK_IDENT); + } + + for (;;) { /* Tail of declarator. */ + if (cp_opt(cp, '[')) { /* Array. */ + cp_decl_array(cp, decl); + } else if (cp_opt(cp, '(')) { /* Function. */ + func_decl: + cp_decl_func(cp, decl); + } else { + break; + } + } + + if ((decl->mode & CPARSE_MODE_FIELD) && cp_opt(cp, ':')) /* Field width. */ + decl->bits = cp_expr_ksize(cp); + + /* Process postfix attributes. */ + cp_decl_attributes(cp, decl); + cp_push_attributes(decl); + + cp->depth--; +} + +/* Parse an abstract type declaration and return it's C type ID. */ +static CTypeID cp_decl_abstract(CPState *cp) +{ + CPDecl decl; + cp_decl_spec(cp, &decl, 0); + decl.mode = CPARSE_MODE_ABSTRACT; + cp_declarator(cp, &decl); + return cp_decl_intern(cp, &decl); +} + +/* Handle pragmas. */ +static void cp_pragma(CPState *cp, BCLine pragmaline) +{ + cp_next(cp); + if (cp->tok == CTOK_IDENT && + cp->str->hash == H_(e79b999f,42ca3e85)) { /* pack */ + cp_next(cp); + cp_check(cp, '('); + if (cp->tok == CTOK_IDENT) { + if (cp->str->hash == H_(738e923c,a1b65954)) { /* push */ + if (cp->curpack < CPARSE_MAX_PACKSTACK) { + cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack]; + cp->curpack++; + } + } else if (cp->str->hash == H_(6c71cf27,6c71cf27)) { /* pop */ + if (cp->curpack > 0) cp->curpack--; + } else { + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + } + cp_next(cp); + if (!cp_opt(cp, ',')) goto end_pack; + } + if (cp->tok == CTOK_INTEGER) { + cp->packstack[cp->curpack] = cp->val.u32 ? lj_fls(cp->val.u32) : 0; + cp_next(cp); + } else { + cp->packstack[cp->curpack] = 255; + } + end_pack: + cp_check(cp, ')'); + } else { /* Ignore all other pragmas. */ + while (cp->tok != CTOK_EOF && cp->linenumber == pragmaline) + cp_next(cp); + } +} + +/* Parse multiple C declarations of types or extern identifiers. */ +static void cp_decl_multi(CPState *cp) +{ + int first = 1; + while (cp->tok != CTOK_EOF) { + CPDecl decl; + CPscl scl; + if (cp_opt(cp, ';')) { /* Skip empty statements. */ + first = 0; + continue; + } + if (cp->tok == '#') { /* Workaround, since we have no preprocessor, yet. */ + BCLine pragmaline = cp->linenumber; + if (!(cp_next(cp) == CTOK_IDENT && + cp->str->hash == H_(f5e6b4f8,1d509107))) /* pragma */ + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + cp_pragma(cp, pragmaline); + continue; + } + scl = cp_decl_spec(cp, &decl, CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC); + if ((cp->tok == ';' || cp->tok == CTOK_EOF) && + ctype_istypedef(decl.stack[0].info)) { + CTInfo info = ctype_rawchild(cp->cts, &decl.stack[0])->info; + if (ctype_isstruct(info) || ctype_isenum(info)) + goto decl_end; /* Accept empty declaration of struct/union/enum. */ + } + for (;;) { + CTypeID ctypeid; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + if (decl.name && !decl.nameid) { /* NYI: redeclarations are ignored. */ + CType *ct; + CTypeID id; + if ((scl & CDF_TYPEDEF)) { /* Create new typedef. */ + id = lj_ctype_new(cp->cts, &ct); + ct->info = CTINFO(CT_TYPEDEF, ctypeid); + goto noredir; + } else if (ctype_isfunc(ctype_get(cp->cts, ctypeid)->info)) { + /* Treat both static and extern function declarations as extern. */ + ct = ctype_get(cp->cts, ctypeid); + /* We always get new anonymous functions (typedefs are copied). */ + lua_assert(gcref(ct->name) == NULL); + id = ctypeid; /* Just name it. */ + } else if ((scl & CDF_STATIC)) { /* Accept static constants. */ + id = cp_decl_constinit(cp, &ct, ctypeid); + goto noredir; + } else { /* External references have extern or no storage class. */ + id = lj_ctype_new(cp->cts, &ct); + ct->info = CTINFO(CT_EXTERN, ctypeid); + } + if (decl.redir) { /* Add attribute for redirected symbol name. */ + CType *cta; + CTypeID aid = lj_ctype_new(cp->cts, &cta); + ct = ctype_get(cp->cts, id); /* Table may have been reallocated. */ + cta->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_REDIR)); + cta->sib = ct->sib; + ct->sib = aid; + ctype_setname(cta, decl.redir); + } + noredir: + ctype_setname(ct, decl.name); + lj_ctype_addname(cp->cts, ct, id); + } + if (!cp_opt(cp, ',')) break; + cp_decl_reset(&decl); + } + decl_end: + if (cp->tok == CTOK_EOF && first) break; /* May omit ';' for 1 decl. */ + first = 0; + cp_check(cp, ';'); + } +} + +/* Parse a single C type declaration. */ +static void cp_decl_single(CPState *cp) +{ + CPDecl decl; + cp_decl_spec(cp, &decl, 0); + cp_declarator(cp, &decl); + cp->val.id = cp_decl_intern(cp, &decl); + if (cp->tok != CTOK_EOF) cp_err_token(cp, CTOK_EOF); +} + +#undef H_ + +/* ------------------------------------------------------------------------ */ + +/* Protected callback for C parser. */ +static TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud) +{ + CPState *cp = (CPState *)ud; + UNUSED(dummy); + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + cp_init(cp); + if ((cp->mode & CPARSE_MODE_MULTI)) + cp_decl_multi(cp); + else + cp_decl_single(cp); + if (cp->param && cp->param != cp->L->top) + cp_err(cp, LJ_ERR_FFI_NUMPARAM); + lua_assert(cp->depth == 0); + return NULL; +} + +/* C parser. */ +int lj_cparse(CPState *cp) +{ + LJ_CTYPE_SAVE(cp->cts); + int errcode = lj_vm_cpcall(cp->L, NULL, cp, cpcparser); + if (errcode) + LJ_CTYPE_RESTORE(cp->cts); + cp_cleanup(cp); + return errcode; +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.h new file mode 100644 index 0000000..586f494 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_cparse.h @@ -0,0 +1,65 @@ +/* +** C declaration parser. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CPARSE_H +#define _LJ_CPARSE_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* C parser limits. */ +#define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */ +#define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */ +#define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */ +#define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */ + +/* Flags for C parser mode. */ +#define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */ +#define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */ +#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */ +#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */ +#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */ +#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */ + +typedef int CPChar; /* C parser character. Unsigned ext. from char. */ +typedef int CPToken; /* C parser token. */ + +/* C parser internal value representation. */ +typedef struct CPValue { + union { + int32_t i32; /* Value for CTID_INT32. */ + uint32_t u32; /* Value for CTID_UINT32. */ + }; + CTypeID id; /* C Type ID of the value. */ +} CPValue; + +/* C parser state. */ +typedef struct CPState { + CPChar c; /* Current character. */ + CPToken tok; /* Current token. */ + CPValue val; /* Token value. */ + GCstr *str; /* Interned string of identifier/keyword. */ + CType *ct; /* C type table entry. */ + const char *p; /* Current position in input buffer. */ + SBuf sb; /* String buffer for tokens. */ + lua_State *L; /* Lua state. */ + CTState *cts; /* C type state. */ + TValue *param; /* C type parameters. */ + const char *srcname; /* Current source name. */ + BCLine linenumber; /* Input line counter. */ + int depth; /* Recursive declaration depth. */ + uint32_t tmask; /* Type mask for next identifier. */ + uint32_t mode; /* C parser mode. */ + uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */ + uint8_t curpack; /* Current position in pack pragma stack. */ +} CPState; + +LJ_FUNC int lj_cparse(CPState *cp); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.c new file mode 100644 index 0000000..da9013f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.c @@ -0,0 +1,1653 @@ +/* +** Trace recorder for C data operations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ffrecord_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT && LJ_HASFFI + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_cparse.h" +#include "lj_cconv.h" +#include "lj_clib.h" +#include "lj_ccall.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_snap.h" +#include "lj_crecord.h" +#include "lj_dispatch.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +#define emitconv(a, dt, st, flags) \ + emitir(IRT(IR_CONV, (dt)), (a), (st)|((dt) << 5)|(flags)) + +/* -- C type checks ------------------------------------------------------- */ + +static GCcdata *argv2cdata(jit_State *J, TRef tr, cTValue *o) +{ + GCcdata *cd; + TRef trtypeid; + if (!tref_iscdata(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + cd = cdataV(o); + /* Specialize to the CTypeID. */ + trtypeid = emitir(IRT(IR_FLOAD, IRT_U16), tr, IRFL_CDATA_CTYPEID); + emitir(IRTG(IR_EQ, IRT_INT), trtypeid, lj_ir_kint(J, (int32_t)cd->ctypeid)); + return cd; +} + +/* Specialize to the CTypeID held by a cdata constructor. */ +static CTypeID crec_constructor(jit_State *J, GCcdata *cd, TRef tr) +{ + CTypeID id; + lua_assert(tref_iscdata(tr) && cd->ctypeid == CTID_CTYPEID); + id = *(CTypeID *)cdataptr(cd); + tr = emitir(IRT(IR_FLOAD, IRT_INT), tr, IRFL_CDATA_INT); + emitir(IRTG(IR_EQ, IRT_INT), tr, lj_ir_kint(J, (int32_t)id)); + return id; +} + +static CTypeID argv2ctype(jit_State *J, TRef tr, cTValue *o) +{ + if (tref_isstr(tr)) { + GCstr *s = strV(o); + CPState cp; + CTypeID oldtop; + /* Specialize to the string containing the C type declaration. */ + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, s)); + cp.L = J->L; + cp.cts = ctype_ctsG(J2G(J)); + oldtop = cp.cts->top; + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = NULL; + cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT; + if (lj_cparse(&cp) || cp.cts->top > oldtop) /* Avoid new struct defs. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + return cp.val.id; + } else { + GCcdata *cd = argv2cdata(J, tr, o); + return cd->ctypeid == CTID_CTYPEID ? crec_constructor(J, cd, tr) : + cd->ctypeid; + } +} + +/* Convert CType to IRType (if possible). */ +static IRType crec_ct2irt(CTState *cts, CType *ct) +{ + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (LJ_LIKELY(ctype_isnum(ct->info))) { + if ((ct->info & CTF_FP)) { + if (ct->size == sizeof(double)) + return IRT_NUM; + else if (ct->size == sizeof(float)) + return IRT_FLOAT; + } else { + uint32_t b = lj_fls(ct->size); + if (b <= 3) + return IRT_I8 + 2*b + ((ct->info & CTF_UNSIGNED) ? 1 : 0); + } + } else if (ctype_isptr(ct->info)) { + return (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + } else if (ctype_iscomplex(ct->info)) { + if (ct->size == 2*sizeof(double)) + return IRT_NUM; + else if (ct->size == 2*sizeof(float)) + return IRT_FLOAT; + } + return IRT_CDATA; +} + +/* -- Optimized memory fill and copy -------------------------------------- */ + +/* Maximum length and unroll of inlined copy/fill. */ +#define CREC_COPY_MAXUNROLL 16 +#define CREC_COPY_MAXLEN 128 + +#define CREC_FILL_MAXUNROLL 16 + +/* Number of windowed registers used for optimized memory copy. */ +#if LJ_TARGET_X86 +#define CREC_COPY_REGWIN 2 +#elif LJ_TARGET_PPC || LJ_TARGET_MIPS +#define CREC_COPY_REGWIN 8 +#else +#define CREC_COPY_REGWIN 4 +#endif + +/* List of memory offsets for copy/fill. */ +typedef struct CRecMemList { + CTSize ofs; /* Offset in bytes. */ + IRType tp; /* Type of load/store. */ + TRef trofs; /* TRef of interned offset. */ + TRef trval; /* TRef of load value. */ +} CRecMemList; + +/* Generate copy list for element-wise struct copy. */ +static MSize crec_copy_struct(CRecMemList *ml, CTState *cts, CType *ct) +{ + CTypeID fid = ct->sib; + MSize mlp = 0; + while (fid) { + CType *df = ctype_get(cts, fid); + fid = df->sib; + if (ctype_isfield(df->info)) { + CType *cct; + IRType tp; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + cct = ctype_rawchild(cts, df); /* Field type. */ + tp = crec_ct2irt(cts, cct); + if (tp == IRT_CDATA) return 0; /* NYI: aggregates. */ + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = df->size; + ml[mlp].tp = tp; + mlp++; + if (ctype_iscomplex(cct->info)) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = df->size + (cct->size >> 1); + ml[mlp].tp = tp; + mlp++; + } + } else if (!ctype_isconstval(df->info)) { + /* NYI: bitfields and sub-structures. */ + return 0; + } + } + return mlp; +} + +/* Generate unrolled copy list, from highest to lowest step size/alignment. */ +static MSize crec_copy_unroll(CRecMemList *ml, CTSize len, CTSize step, + IRType tp) +{ + CTSize ofs = 0; + MSize mlp = 0; + if (tp == IRT_CDATA) tp = IRT_U8 + 2*lj_fls(step); + do { + while (ofs + step <= len) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = ofs; + ml[mlp].tp = tp; + mlp++; + ofs += step; + } + step >>= 1; + tp -= 2; + } while (ofs < len); + return mlp; +} + +/* +** Emit copy list with windowed loads/stores. +** LJ_TARGET_UNALIGNED: may emit unaligned loads/stores (not marked as such). +*/ +static void crec_copy_emit(jit_State *J, CRecMemList *ml, MSize mlp, + TRef trdst, TRef trsrc) +{ + MSize i, j, rwin = 0; + for (i = 0, j = 0; i < mlp; ) { + TRef trofs = lj_ir_kintp(J, ml[i].ofs); + TRef trsptr = emitir(IRT(IR_ADD, IRT_PTR), trsrc, trofs); + ml[i].trval = emitir(IRT(IR_XLOAD, ml[i].tp), trsptr, 0); + ml[i].trofs = trofs; + i++; + rwin += (LJ_SOFTFP && ml[i].tp == IRT_NUM) ? 2 : 1; + if (rwin >= CREC_COPY_REGWIN || i >= mlp) { /* Flush buffered stores. */ + rwin = 0; + for ( ; j < i; j++) { + TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, ml[j].trofs); + emitir(IRT(IR_XSTORE, ml[j].tp), trdptr, ml[j].trval); + } + } + } +} + +/* Optimized memory copy. */ +static void crec_copy(jit_State *J, TRef trdst, TRef trsrc, TRef trlen, + CType *ct) +{ + if (tref_isk(trlen)) { /* Length must be constant. */ + CRecMemList ml[CREC_COPY_MAXUNROLL]; + MSize mlp = 0; + CTSize step = 1, len = (CTSize)IR(tref_ref(trlen))->i; + IRType tp = IRT_CDATA; + int needxbar = 0; + if (len == 0) return; /* Shortcut. */ + if (len > CREC_COPY_MAXLEN) goto fallback; + if (ct) { + CTState *cts = ctype_ctsG(J2G(J)); + lua_assert(ctype_isarray(ct->info) || ctype_isstruct(ct->info)); + if (ctype_isarray(ct->info)) { + CType *cct = ctype_rawchild(cts, ct); + tp = crec_ct2irt(cts, cct); + if (tp == IRT_CDATA) goto rawcopy; + step = lj_ir_type_size[tp]; + lua_assert((len & (step-1)) == 0); + } else if ((ct->info & CTF_UNION)) { + step = (1u << ctype_align(ct->info)); + goto rawcopy; + } else { + mlp = crec_copy_struct(ml, cts, ct); + goto emitcopy; + } + } else { + rawcopy: + needxbar = 1; + if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR) + step = CTSIZE_PTR; + } + mlp = crec_copy_unroll(ml, len, step, tp); + emitcopy: + if (mlp) { + crec_copy_emit(J, ml, mlp, trdst, trsrc); + if (needxbar) + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); + return; + } + } +fallback: + /* Call memcpy. Always needs a barrier to disable alias analysis. */ + lj_ir_call(J, IRCALL_memcpy, trdst, trsrc, trlen); + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); +} + +/* Generate unrolled fill list, from highest to lowest step size/alignment. */ +static MSize crec_fill_unroll(CRecMemList *ml, CTSize len, CTSize step) +{ + CTSize ofs = 0; + MSize mlp = 0; + IRType tp = IRT_U8 + 2*lj_fls(step); + do { + while (ofs + step <= len) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = ofs; + ml[mlp].tp = tp; + mlp++; + ofs += step; + } + step >>= 1; + tp -= 2; + } while (ofs < len); + return mlp; +} + +/* +** Emit stores for fill list. +** LJ_TARGET_UNALIGNED: may emit unaligned stores (not marked as such). +*/ +static void crec_fill_emit(jit_State *J, CRecMemList *ml, MSize mlp, + TRef trdst, TRef trfill) +{ + MSize i; + for (i = 0; i < mlp; i++) { + TRef trofs = lj_ir_kintp(J, ml[i].ofs); + TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, trofs); + emitir(IRT(IR_XSTORE, ml[i].tp), trdptr, trfill); + } +} + +/* Optimized memory fill. */ +static void crec_fill(jit_State *J, TRef trdst, TRef trlen, TRef trfill, + CTSize step) +{ + if (tref_isk(trlen)) { /* Length must be constant. */ + CRecMemList ml[CREC_FILL_MAXUNROLL]; + MSize mlp; + CTSize len = (CTSize)IR(tref_ref(trlen))->i; + if (len == 0) return; /* Shortcut. */ + if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR) + step = CTSIZE_PTR; + if (step * CREC_FILL_MAXUNROLL < len) goto fallback; + mlp = crec_fill_unroll(ml, len, step); + if (!mlp) goto fallback; + if (tref_isk(trfill) || ml[0].tp != IRT_U8) + trfill = emitconv(trfill, IRT_INT, IRT_U8, 0); + if (ml[0].tp != IRT_U8) { /* Scatter U8 to U16/U32/U64. */ + if (CTSIZE_PTR == 8 && ml[0].tp == IRT_U64) { + if (tref_isk(trfill)) /* Pointless on x64 with zero-extended regs. */ + trfill = emitconv(trfill, IRT_U64, IRT_U32, 0); + trfill = emitir(IRT(IR_MUL, IRT_U64), trfill, + lj_ir_kint64(J, U64x(01010101,01010101))); + } else { + trfill = emitir(IRTI(IR_MUL), trfill, + lj_ir_kint(J, ml[0].tp == IRT_U16 ? 0x0101 : 0x01010101)); + } + } + crec_fill_emit(J, ml, mlp, trdst, trfill); + } else { +fallback: + /* Call memset. Always needs a barrier to disable alias analysis. */ + lj_ir_call(J, IRCALL_memset, trdst, trfill, trlen); /* Note: arg order! */ + } + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); +} + +/* -- Convert C type to C type -------------------------------------------- */ + +/* +** This code mirrors the code in lj_cconv.c. It performs the same steps +** for the trace recorder that lj_cconv.c does for the interpreter. +** +** One major difference is that we can get away with much fewer checks +** here. E.g. checks for casts, constness or correct types can often be +** omitted, even if they might fail. The interpreter subsequently throws +** an error, which aborts the trace. +** +** All operations are specialized to their C types, so the on-trace +** outcome must be the same as the outcome in the interpreter. If the +** interpreter doesn't throw an error, then the trace is correct, too. +** Care must be taken not to generate invalid (temporary) IR or to +** trigger asserts. +*/ + +/* Determine whether a passed number or cdata number is non-zero. */ +static int crec_isnonzero(CType *s, void *p) +{ + if (p == (void *)0) + return 0; + if (p == (void *)1) + return 1; + if ((s->info & CTF_FP)) { + if (s->size == sizeof(float)) + return (*(float *)p != 0); + else + return (*(double *)p != 0); + } else { + if (s->size == 1) + return (*(uint8_t *)p != 0); + else if (s->size == 2) + return (*(uint16_t *)p != 0); + else if (s->size == 4) + return (*(uint32_t *)p != 0); + else + return (*(uint64_t *)p != 0); + } +} + +static TRef crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp, + void *svisnz) +{ + IRType dt = crec_ct2irt(ctype_ctsG(J2G(J)), d); + IRType st = crec_ct2irt(ctype_ctsG(J2G(J)), s); + CTSize dsize = d->size, ssize = s->size; + CTInfo dinfo = d->info, sinfo = s->info; + + if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT) + goto err_conv; + + /* + ** Note: Unlike lj_cconv_ct_ct(), sp holds the _value_ of pointers and + ** numbers up to 8 bytes. Otherwise sp holds a pointer. + */ + + switch (cconv_idx2(dinfo, sinfo)) { + /* Destination is a bool. */ + case CCX(B, B): + goto xstore; /* Source operand is already normalized. */ + case CCX(B, I): + case CCX(B, F): + if (st != IRT_CDATA) { + /* Specialize to the result of a comparison against 0. */ + TRef zero = (st == IRT_NUM || st == IRT_FLOAT) ? lj_ir_knum(J, 0) : + (st == IRT_I64 || st == IRT_U64) ? lj_ir_kint64(J, 0) : + lj_ir_kint(J, 0); + int isnz = crec_isnonzero(s, svisnz); + emitir(IRTG(isnz ? IR_NE : IR_EQ, st), sp, zero); + sp = lj_ir_kint(J, isnz); + goto xstore; + } + goto err_nyi; + + /* Destination is an integer. */ + case CCX(I, B): + case CCX(I, I): + conv_I_I: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + /* Extend 32 to 64 bit integer. */ + if (dsize == 8 && ssize < 8 && !(LJ_64 && (sinfo & CTF_UNSIGNED))) + sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, + (sinfo & CTF_UNSIGNED) ? 0 : IRCONV_SEXT); + else if (dsize < 8 && ssize == 8) /* Truncate from 64 bit integer. */ + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, 0); + else if (st == IRT_INT) + sp = lj_opt_narrow_toint(J, sp); + xstore: + if (dt == IRT_I64 || dt == IRT_U64) lj_needsplit(J); + if (dp == 0) return sp; + emitir(IRT(IR_XSTORE, dt), dp, sp); + break; + case CCX(I, C): + sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */ + /* fallthrough */ + case CCX(I, F): + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, IRCONV_TRUNC|IRCONV_ANY); + goto xstore; + case CCX(I, P): + case CCX(I, A): + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + ssize = CTSIZE_PTR; + st = IRT_UINTP; + if (((dsize ^ ssize) & 8) == 0) { /* Must insert no-op type conversion. */ + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, IRT_PTR, 0); + goto xstore; + } + goto conv_I_I; + + /* Destination is a floating-point number. */ + case CCX(F, B): + case CCX(F, I): + conv_F_I: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, 0); + goto xstore; + case CCX(F, C): + sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */ + /* fallthrough */ + case CCX(F, F): + conv_F_F: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + if (dt != st) sp = emitconv(sp, dt, st, 0); + goto xstore; + + /* Destination is a complex number. */ + case CCX(C, I): + case CCX(C, F): + { /* Clear im. */ + TRef ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1))); + emitir(IRT(IR_XSTORE, dt), ptr, lj_ir_knum(J, 0)); + } + /* Convert to re. */ + if ((sinfo & CTF_FP)) goto conv_F_F; else goto conv_F_I; + + case CCX(C, C): + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + { + TRef re, im, ptr; + re = emitir(IRT(IR_XLOAD, st), sp, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, (ssize >> 1))); + im = emitir(IRT(IR_XLOAD, st), ptr, 0); + if (dt != st) { + re = emitconv(re, dt, st, 0); + im = emitconv(im, dt, st, 0); + } + emitir(IRT(IR_XSTORE, dt), dp, re); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1))); + emitir(IRT(IR_XSTORE, dt), ptr, im); + } + break; + + /* Destination is a vector. */ + case CCX(V, I): + case CCX(V, F): + case CCX(V, C): + case CCX(V, V): + goto err_nyi; + + /* Destination is a pointer. */ + case CCX(P, P): + case CCX(P, A): + case CCX(P, S): + /* There are only 32 bit pointers/addresses on 32 bit machines. + ** Also ok on x64, since all 32 bit ops clear the upper part of the reg. + */ + goto xstore; + case CCX(P, I): + if (st == IRT_CDATA) goto err_nyi; + if (!LJ_64 && ssize == 8) /* Truncate from 64 bit integer. */ + sp = emitconv(sp, IRT_U32, st, 0); + goto xstore; + case CCX(P, F): + if (st == IRT_CDATA) goto err_nyi; + /* The signed conversion is cheaper. x64 really has 47 bit pointers. */ + sp = emitconv(sp, (LJ_64 && dsize == 8) ? IRT_I64 : IRT_U32, + st, IRCONV_TRUNC|IRCONV_ANY); + goto xstore; + + /* Destination is an array. */ + case CCX(A, A): + /* Destination is a struct/union. */ + case CCX(S, S): + if (dp == 0) goto err_conv; + crec_copy(J, dp, sp, lj_ir_kint(J, dsize), d); + break; + + default: + err_conv: + err_nyi: + lj_trace_err(J, LJ_TRERR_NYICONV); + break; + } + return 0; +} + +/* -- Convert C type to TValue (load) ------------------------------------- */ + +static TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp) +{ + CTState *cts = ctype_ctsG(J2G(J)); + IRType t = crec_ct2irt(cts, s); + CTInfo sinfo = s->info; + if (ctype_isnum(sinfo)) { + TRef tr; + if (t == IRT_CDATA) + goto err_nyi; /* NYI: copyval of >64 bit integers. */ + tr = emitir(IRT(IR_XLOAD, t), sp, 0); + if (t == IRT_FLOAT || t == IRT_U32) { /* Keep uint32_t/float as numbers. */ + return emitconv(tr, IRT_NUM, t, 0); + } else if (t == IRT_I64 || t == IRT_U64) { /* Box 64 bit integer. */ + sp = tr; + lj_needsplit(J); + } else if ((sinfo & CTF_BOOL)) { + /* Assume not equal to zero. Fixup and emit pending guard later. */ + lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } else { + return tr; + } + } else if (ctype_isptr(sinfo) || ctype_isenum(sinfo)) { + sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Box pointers and enums. */ + } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { + cts->L = J->L; + sid = lj_ctype_intern(cts, CTINFO_REF(sid), CTSIZE_PTR); /* Create ref. */ + } else if (ctype_iscomplex(sinfo)) { /* Unbox/box complex. */ + ptrdiff_t esz = (ptrdiff_t)(s->size >> 1); + TRef ptr, tr1, tr2, dp; + dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL); + tr1 = emitir(IRT(IR_XLOAD, t), sp, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz)); + tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata))); + emitir(IRT(IR_XSTORE, t), ptr, tr1); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)+esz)); + emitir(IRT(IR_XSTORE, t), ptr, tr2); + return dp; + } else { + /* NYI: copyval of vectors. */ + err_nyi: + lj_trace_err(J, LJ_TRERR_NYICONV); + } + /* Box pointer, ref, enum or 64 bit integer. */ + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, sid), sp); +} + +/* -- Convert TValue to C type (store) ------------------------------------ */ + +static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CTypeID sid = CTID_P_VOID; + void *svisnz = 0; + CType *s; + if (LJ_LIKELY(tref_isinteger(sp))) { + sid = CTID_INT32; + svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval)); + } else if (tref_isnum(sp)) { + sid = CTID_DOUBLE; + svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval)); + } else if (tref_isbool(sp)) { + sp = lj_ir_kint(J, tref_istrue(sp) ? 1 : 0); + sid = CTID_BOOL; + } else if (tref_isnil(sp)) { + sp = lj_ir_kptr(J, NULL); + } else if (tref_isudata(sp)) { + GCudata *ud = udataV(sval); + if (ud->udtype == UDTYPE_IO_FILE) { + TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); + sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_UDATA_FILE); + } else { + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCudata))); + } + } else if (tref_isstr(sp)) { + if (ctype_isenum(d->info)) { /* Match string against enum constant. */ + GCstr *str = strV(sval); + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, d, str, &ofs); + /* Specialize to the name of the enum constant. */ + emitir(IRTG(IR_EQ, IRT_STR), sp, lj_ir_kstr(J, str)); + if (cct && ctype_isconstval(cct->info)) { + lua_assert(ctype_child(cts, cct)->size == 4); + svisnz = (void *)(intptr_t)(ofs != 0); + sp = lj_ir_kint(J, (int32_t)ofs); + sid = ctype_cid(cct->info); + } /* else: interpreter will throw. */ + } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); /* NYI */ + } else { /* Otherwise pass the string data as a const char[]. */ + /* Don't use STRREF. It folds with SNEW, which loses the trailing NUL. */ + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCstr))); + sid = CTID_A_CCHAR; + } + } else { /* NYI: tref_istab(sp), tref_islightud(sp). */ + IRType t; + sid = argv2cdata(J, sp, sval)->ctypeid; + s = ctype_raw(cts, sid); + svisnz = cdataptr(cdataV(sval)); + t = crec_ct2irt(cts, s); + if (ctype_isptr(s->info)) { + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR); + if (ctype_isref(s->info)) { + svisnz = *(void **)svisnz; + s = ctype_rawchild(cts, s); + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + t = crec_ct2irt(cts, s); + } else { + goto doconv; + } + } else if (t == IRT_I64 || t == IRT_U64) { + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64); + lj_needsplit(J); + goto doconv; + } else if (t == IRT_INT || t == IRT_U32) { + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT); + goto doconv; + } else { + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata))); + } + if (ctype_isnum(s->info) && t != IRT_CDATA) + sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Load number value. */ + goto doconv; + } + s = ctype_get(cts, sid); +doconv: + if (ctype_isenum(d->info)) d = ctype_child(cts, d); + return crec_ct_ct(J, d, s, dp, sp, svisnz); +} + +/* -- C data metamethods -------------------------------------------------- */ + +/* This would be rather difficult in FOLD, so do it here: +** (base+k)+(idx*sz)+ofs ==> (base+idx*sz)+(ofs+k) +** (base+(idx+k)*sz)+ofs ==> (base+idx*sz)+(ofs+k*sz) +*/ +static TRef crec_reassoc_ofs(jit_State *J, TRef tr, ptrdiff_t *ofsp, MSize sz) +{ + IRIns *ir = IR(tref_ref(tr)); + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && irref_isk(ir->op2) && + (ir->o == IR_ADD || ir->o == IR_ADDOV || ir->o == IR_SUBOV)) { + IRIns *irk = IR(ir->op2); + ptrdiff_t k; + if (LJ_64 && irk->o == IR_KINT64) + k = (ptrdiff_t)ir_kint64(irk)->u64 * sz; + else + k = (ptrdiff_t)irk->i * sz; + if (ir->o == IR_SUBOV) *ofsp -= k; else *ofsp += k; + tr = ir->op1; /* Not a TRef, but the caller doesn't care. */ + } + return tr; +} + +/* Record ctype __index/__newindex metamethods. */ +static void crec_index_meta(jit_State *J, CTState *cts, CType *ct, + RecordFFData *rd) +{ + CTypeID id = ctype_typeid(cts, ct); + cTValue *tv = lj_ctype_meta(cts, id, rd->data ? MM_newindex : MM_index); + if (!tv) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + } else if (rd->data == 0 && tvistab(tv) && tref_isstr(J->base[1])) { + /* Specialize to result of __index lookup. */ + cTValue *o = lj_tab_get(J->L, tabV(tv), &rd->argv[1]); + J->base[0] = lj_record_constify(J, o); + if (!J->base[0]) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* Always specialize to the key. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1]))); + } else { + /* NYI: resolving of non-function metamethods. */ + /* NYI: non-string keys for __index table. */ + /* NYI: stores to __newindex table. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + } +} + +void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) +{ + TRef idx, ptr = J->base[0]; + ptrdiff_t ofs = sizeof(GCcdata); + GCcdata *cd = argv2cdata(J, ptr, &rd->argv[0]); + CTState *cts = ctype_ctsG(J2G(J)); + CType *ct = ctype_raw(cts, cd->ctypeid); + CTypeID sid = 0; + + /* Resolve pointer or reference for cdata object. */ + if (ctype_isptr(ct->info)) { + IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); + ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR); + ofs = 0; + ptr = crec_reassoc_ofs(J, ptr, &ofs, 1); + } + +again: + idx = J->base[1]; + if (tref_isnumber(idx)) { + idx = lj_opt_narrow_cindex(J, idx); + if (ctype_ispointer(ct->info)) { + CTSize sz; + integer_key: + if ((ct->info & CTF_COMPLEX)) + idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1)); + sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info))); + idx = crec_reassoc_ofs(J, idx, &ofs, sz); +#if LJ_TARGET_ARM || LJ_TARGET_PPC + /* Hoist base add to allow fusion of index/shift into operands. */ + if (LJ_LIKELY(J->flags & JIT_F_OPT_LOOP) && ofs +#if LJ_TARGET_ARM + && (sz == 1 || sz == 4) +#endif + ) { + ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs)); + ofs = 0; + } +#endif + idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz)); + ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr); + } + } else if (tref_iscdata(idx)) { + GCcdata *cdk = cdataV(&rd->argv[1]); + CType *ctk = ctype_raw(cts, cdk->ctypeid); + IRType t = crec_ct2irt(cts, ctk); + if (ctype_ispointer(ct->info) && t >= IRT_I8 && t <= IRT_U64) { + if (ctk->size == 8) { + idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT64); + } else if (ctk->size == 4) { + idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT); + } else { + idx = emitir(IRT(IR_ADD, IRT_PTR), idx, + lj_ir_kintp(J, sizeof(GCcdata))); + idx = emitir(IRT(IR_XLOAD, t), idx, 0); + } + if (LJ_64 && ctk->size < sizeof(intptr_t) && !(ctk->info & CTF_UNSIGNED)) + idx = emitconv(idx, IRT_INTP, IRT_INT, IRCONV_SEXT); + if (!LJ_64 && ctk->size > sizeof(intptr_t)) { + idx = emitconv(idx, IRT_INTP, t, 0); + lj_needsplit(J); + } + goto integer_key; + } + } else if (tref_isstr(idx)) { + GCstr *name = strV(&rd->argv[1]); + if (cd->ctypeid == CTID_CTYPEID) + ct = ctype_raw(cts, crec_constructor(J, cd, ptr)); + if (ctype_isstruct(ct->info)) { + CTSize fofs; + CType *fct; + fct = lj_ctype_getfield(cts, ct, name, &fofs); + if (fct) { + /* Always specialize to the field name. */ + emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); + if (ctype_isconstval(fct->info)) { + if (fct->size >= 0x80000000u && + (ctype_child(cts, fct)->info & CTF_UNSIGNED)) { + J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)fct->size); + return; + } + J->base[0] = lj_ir_kint(J, (int32_t)fct->size); + return; /* Interpreter will throw for newindex. */ + } else if (ctype_isbitfield(fct->info)) { + lj_trace_err(J, LJ_TRERR_NYICONV); + } else { + lua_assert(ctype_isfield(fct->info)); + sid = ctype_cid(fct->info); + } + ofs += (ptrdiff_t)fofs; + } + } else if (ctype_iscomplex(ct->info)) { + if (name->len == 2 && + ((strdata(name)[0] == 'r' && strdata(name)[1] == 'e') || + (strdata(name)[0] == 'i' && strdata(name)[1] == 'm'))) { + /* Always specialize to the field name. */ + emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); + if (strdata(name)[0] == 'i') ofs += (ct->size >> 1); + sid = ctype_cid(ct->info); + } + } + } + if (!sid) { + if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ + CType *cct = ctype_rawchild(cts, ct); + if (ctype_isstruct(cct->info)) { + ct = cct; + if (tref_isstr(idx)) goto again; + } + } + crec_index_meta(J, cts, ct, rd); + return; + } + + if (ofs) + ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs)); + + /* Resolve reference for field. */ + ct = ctype_get(cts, sid); + if (ctype_isref(ct->info)) + ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0); + + while (ctype_isattrib(ct->info)) + ct = ctype_child(cts, ct); /* Skip attributes. */ + + if (rd->data == 0) { /* __index metamethod. */ + J->base[0] = crec_tv_ct(J, ct, sid, ptr); + } else { /* __newindex metamethod. */ + rd->nres = 0; + J->needsnap = 1; + crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]); + } +} + +/* Record setting a finalizer. */ +static void crec_finalizer(jit_State *J, TRef trcd, cTValue *fin) +{ + TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd); + TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4)); + if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; } + if (tvisfunc(fin)) { + emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin))); + emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC)); + } else if (tviscdata(fin)) { + emitir(IRT(IR_XSTORE, IRT_P32), trlo, + lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA)); + emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA)); + } else { + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + J->needsnap = 1; +} + +/* Record cdata allocation. */ +static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CTSize sz; + CTInfo info = lj_ctype_info(cts, id, &sz); + CType *d = ctype_raw(cts, id); + TRef trid; + if (!sz || sz > 128 || (info & CTF_VLA) || ctype_align(info) > CT_MEMALIGN) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: large/special allocations. */ + trid = lj_ir_kint(J, id); + /* Use special instruction to box pointer or 32/64 bit integer. */ + if (ctype_isptr(info) || (ctype_isinteger(info) && (sz == 4 || sz == 8))) { + TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) : + ctype_isptr(info) ? lj_ir_kptr(J, NULL) : + sz == 4 ? lj_ir_kint(J, 0) : + (lj_needsplit(J), lj_ir_kint64(J, 0)); + J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, sp); + } else { + TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL); + cTValue *fin; + J->base[0] = trcd; + if (J->base[1] && !J->base[2] && + !lj_cconv_multi_init(cts, d, &rd->argv[1])) { + goto single_init; + } else if (ctype_isarray(d->info)) { + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize ofs, esize = dc->size; + TRef sp = 0; + TValue tv; + TValue *sval = &tv; + MSize i; + tv.u64 = 0; + if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info))) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init array of aggregates. */ + for (i = 1, ofs = 0; ofs < sz; ofs += esize) { + TRef dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, + lj_ir_kintp(J, ofs + sizeof(GCcdata))); + if (J->base[i]) { + sp = J->base[i]; + sval = &rd->argv[i]; + i++; + } else if (i != 2) { + sp = ctype_isnum(dc->info) ? lj_ir_kint(J, 0) : TREF_NIL; + } + crec_ct_tv(J, dc, dp, sp, sval); + } + } else if (ctype_isstruct(d->info)) { + CTypeID fid = d->sib; + MSize i = 1; + while (fid) { + CType *df = ctype_get(cts, fid); + fid = df->sib; + if (ctype_isfield(df->info)) { + CType *dc; + TRef sp, dp; + TValue tv; + TValue *sval = &tv; + setintV(&tv, 0); + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + dc = ctype_rawchild(cts, df); /* Field type. */ + if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) || + ctype_isenum(dc->info))) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init aggregates. */ + if (J->base[i]) { + sp = J->base[i]; + sval = &rd->argv[i]; + i++; + } else { + sp = ctype_isptr(dc->info) ? TREF_NIL : lj_ir_kint(J, 0); + } + dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, + lj_ir_kintp(J, df->size + sizeof(GCcdata))); + crec_ct_tv(J, dc, dp, sp, sval); + } else if (!ctype_isconstval(df->info)) { + /* NYI: init bitfields and sub-structures. */ + lj_trace_err(J, LJ_TRERR_NYICONV); + } + } + } else { + TRef dp; + single_init: + dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata))); + if (J->base[1]) { + crec_ct_tv(J, d, dp, J->base[1], &rd->argv[1]); + } else { + TValue tv; + tv.u64 = 0; + crec_ct_tv(J, d, dp, lj_ir_kint(J, 0), &tv); + } + } + /* Handle __gc metamethod. */ + fin = lj_ctype_meta(cts, id, MM_gc); + if (fin) + crec_finalizer(J, trcd, fin); + } +} + +/* Record argument conversions. */ +static TRef crec_call_args(jit_State *J, RecordFFData *rd, + CTState *cts, CType *ct) +{ + TRef args[CCI_NARGS_MAX]; + CTypeID fid; + MSize i, n; + TRef tr, *base; + cTValue *o; +#if LJ_TARGET_X86 +#if LJ_ABI_WIN + TRef *arg0 = NULL, *arg1 = NULL; +#endif + int ngpr = 0; + if (ctype_cconv(ct->info) == CTCC_THISCALL) + ngpr = 1; + else if (ctype_cconv(ct->info) == CTCC_FASTCALL) + ngpr = 2; +#endif + + /* Skip initial attributes. */ + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) break; + fid = ctf->sib; + } + args[0] = TREF_NIL; + for (n = 0, base = J->base+1, o = rd->argv+1; *base; n++, base++, o++) { + CTypeID did; + CType *d; + + if (n >= CCI_NARGS_MAX) + lj_trace_err(J, LJ_TRERR_NYICALL); + + if (fid) { /* Get argument type from field. */ + CType *ctf = ctype_get(cts, fid); + fid = ctf->sib; + lua_assert(ctype_isfield(ctf->info)); + did = ctype_cid(ctf->info); + } else { + if (!(ct->info & CTF_VARARG)) + lj_trace_err(J, LJ_TRERR_NYICALL); /* Too many arguments. */ + did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */ + } + d = ctype_raw(cts, did); + if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || + ctype_isenum(d->info))) + lj_trace_err(J, LJ_TRERR_NYICALL); + tr = crec_ct_tv(J, d, 0, *base, o); + if (ctype_isinteger_or_bool(d->info)) { + if (d->size < 4) { + if ((d->info & CTF_UNSIGNED)) + tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_U8 : IRT_U16, 0); + else + tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_I8 : IRT_I16,IRCONV_SEXT); + } + } else if (LJ_SOFTFP && ctype_isfp(d->info) && d->size > 4) { + lj_needsplit(J); + } +#if LJ_TARGET_X86 + /* 64 bit args must not end up in registers for fastcall/thiscall. */ +#if LJ_ABI_WIN + if (!ctype_isfp(d->info)) { + /* Sigh, the Windows/x86 ABI allows reordering across 64 bit args. */ + if (tref_typerange(tr, IRT_I64, IRT_U64)) { + if (ngpr) { + arg0 = &args[n]; args[n++] = TREF_NIL; ngpr--; + if (ngpr) { + arg1 = &args[n]; args[n++] = TREF_NIL; ngpr--; + } + } + } else { + if (arg0) { *arg0 = tr; arg0 = NULL; n--; continue; } + if (arg1) { *arg1 = tr; arg1 = NULL; n--; continue; } + if (ngpr) ngpr--; + } + } +#else + if (!ctype_isfp(d->info) && ngpr) { + if (tref_typerange(tr, IRT_I64, IRT_U64)) { + /* No reordering for other x86 ABIs. Simply add alignment args. */ + do { args[n++] = TREF_NIL; } while (--ngpr); + } else { + ngpr--; + } + } +#endif +#endif + args[n] = tr; + } + tr = args[0]; + for (i = 1; i < n; i++) + tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]); + return tr; +} + +/* Create a snapshot for the caller, simulating a 'false' return value. */ +static void crec_snap_caller(jit_State *J) +{ + lua_State *L = J->L; + TValue *base = L->base, *top = L->top; + const BCIns *pc = J->pc; + TRef ftr = J->base[-1]; + ptrdiff_t delta; + if (!frame_islua(base-1) || J->framedepth <= 0) + lj_trace_err(J, LJ_TRERR_NYICALL); + J->pc = frame_pc(base-1); delta = 1+bc_a(J->pc[-1]); + L->top = base; L->base = base - delta; + J->base[-1] = TREF_FALSE; + J->base -= delta; J->baseslot -= (BCReg)delta; + J->maxslot = (BCReg)delta; J->framedepth--; + lj_snap_add(J); + L->base = base; L->top = top; + J->framedepth++; J->maxslot = 1; + J->base += delta; J->baseslot += (BCReg)delta; + J->base[-1] = ftr; J->pc = pc; +} + +/* Record function call. */ +static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *ct = ctype_raw(cts, cd->ctypeid); + IRType tp = IRT_PTR; + if (ctype_isptr(ct->info)) { + tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + ct = ctype_rawchild(cts, ct); + } + if (ctype_isfunc(ct->info)) { + TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR); + CType *ctr = ctype_rawchild(cts, ct); + IRType t = crec_ct2irt(cts, ctr); + TRef tr; + TValue tv; + /* Check for blacklisted C functions that might call a callback. */ + setlightudV(&tv, + cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4)); + if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv))) + lj_trace_err(J, LJ_TRERR_BLACKL); + if (ctype_isvoid(ctr->info)) { + t = IRT_NIL; + rd->nres = 0; + } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) || + ctype_isenum(ctr->info)) || t == IRT_CDATA) { + lj_trace_err(J, LJ_TRERR_NYICALL); + } + if ((ct->info & CTF_VARARG) +#if LJ_TARGET_X86 + || ctype_cconv(ct->info) != CTCC_CDECL +#endif + ) + func = emitir(IRT(IR_CARG, IRT_NIL), func, + lj_ir_kint(J, ctype_typeid(cts, ct))); + tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); + if (ctype_isbool(ctr->info)) { + if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) { + /* Don't check result if ignored. */ + tr = TREF_NIL; + } else { + crec_snap_caller(J); +#if LJ_TARGET_X86ORX64 + /* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */ + lj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0)); +#else + lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); +#endif + J->postproc = LJ_POST_FIXGUARDSNAP; + tr = TREF_TRUE; + } + } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) || + t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) { + TRef trid = lj_ir_kint(J, ctype_cid(ct->info)); + tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr); + if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); + } else if (t == IRT_FLOAT || t == IRT_U32) { + tr = emitconv(tr, IRT_NUM, t, 0); + } else if (t == IRT_I8 || t == IRT_I16) { + tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT); + } else if (t == IRT_U8 || t == IRT_U16) { + tr = emitconv(tr, IRT_INT, t, 0); + } + J->base[0] = tr; + J->needsnap = 1; + return 1; + } + return 0; +} + +void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]); + CTypeID id = cd->ctypeid; + CType *ct; + cTValue *tv; + MMS mm = MM_call; + if (id == CTID_CTYPEID) { + id = crec_constructor(J, cd, J->base[0]); + mm = MM_new; + } else if (crec_call(J, rd, cd)) { + return; + } + /* Record ctype __call/__new metamethod. */ + ct = ctype_raw(cts, id); + tv = lj_ctype_meta(cts, ctype_isptr(ct->info) ? ctype_cid(ct->info) : id, mm); + if (tv) { + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + return; + } + } else if (mm == MM_new) { + crec_alloc(J, rd, id); + return; + } + /* No metamethod or NYI: non-function metamethods. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); +} + +static TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm) +{ + if (ctype_isnum(s[0]->info) && ctype_isnum(s[1]->info)) { + IRType dt; + CTypeID id; + TRef tr; + MSize i; + IROp op; + lj_needsplit(J); + if (((s[0]->info & CTF_UNSIGNED) && s[0]->size == 8) || + ((s[1]->info & CTF_UNSIGNED) && s[1]->size == 8)) { + dt = IRT_U64; id = CTID_UINT64; + } else { + dt = IRT_I64; id = CTID_INT64; + if (mm < MM_add && + !((s[0]->info | s[1]->info) & CTF_FP) && + s[0]->size == 4 && s[1]->size == 4) { /* Try to narrow comparison. */ + if (!((s[0]->info ^ s[1]->info) & CTF_UNSIGNED) || + (tref_isk(sp[1]) && IR(tref_ref(sp[1]))->i >= 0)) { + dt = (s[0]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT; + goto comp; + } else if (tref_isk(sp[0]) && IR(tref_ref(sp[0]))->i >= 0) { + dt = (s[1]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT; + goto comp; + } + } + } + for (i = 0; i < 2; i++) { + IRType st = tref_type(sp[i]); + if (st == IRT_NUM || st == IRT_FLOAT) + sp[i] = emitconv(sp[i], dt, st, IRCONV_TRUNC|IRCONV_ANY); + else if (!(st == IRT_I64 || st == IRT_U64)) + sp[i] = emitconv(sp[i], dt, IRT_INT, + (s[i]->info & CTF_UNSIGNED) ? 0 : IRCONV_SEXT); + } + if (mm < MM_add) { + comp: + /* Assume true comparison. Fixup and emit pending guard later. */ + if (mm == MM_eq) { + op = IR_EQ; + } else { + op = mm == MM_lt ? IR_LT : IR_LE; + if (dt == IRT_U32 || dt == IRT_U64) + op += (IR_ULT-IR_LT); + } + lj_ir_set(J, IRTG(op, dt), sp[0], sp[1]); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } else { + tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, dt), sp[0], sp[1]); + } + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); + } + return 0; +} + +static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *ctp = s[0]; + if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) { + if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) && + (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) { + if (mm == MM_sub) { /* Pointer difference. */ + TRef tr; + CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info)); + if (sz == 0 || (sz & (sz-1)) != 0) + return 0; /* NYI: integer division. */ + tr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]); + tr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz))); +#if LJ_64 + tr = emitconv(tr, IRT_NUM, IRT_INTP, 0); +#endif + return tr; + } else { /* Pointer comparison (unsigned). */ + /* Assume true comparison. Fixup and emit pending guard later. */ + IROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE; + lj_ir_set(J, IRTG(op, IRT_PTR), sp[0], sp[1]); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } + } + if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(s[1]->info))) + return 0; + } else if (mm == MM_add && ctype_isnum(ctp->info) && + (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) { + TRef tr = sp[0]; sp[0] = sp[1]; sp[1] = tr; /* Swap pointer and index. */ + ctp = s[1]; + } else { + return 0; + } + { + TRef tr = sp[1]; + IRType t = tref_type(tr); + CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info)); + CTypeID id; +#if LJ_64 + if (t == IRT_NUM || t == IRT_FLOAT) + tr = emitconv(tr, IRT_INTP, t, IRCONV_TRUNC|IRCONV_ANY); + else if (!(t == IRT_I64 || t == IRT_U64)) + tr = emitconv(tr, IRT_INTP, IRT_INT, + ((t - IRT_I8) & 1) ? 0 : IRCONV_SEXT); +#else + if (!tref_typerange(sp[1], IRT_I8, IRT_U32)) { + tr = emitconv(tr, IRT_INTP, t, + (t == IRT_NUM || t == IRT_FLOAT) ? + IRCONV_TRUNC|IRCONV_ANY : 0); + } +#endif + tr = emitir(IRT(IR_MUL, IRT_INTP), tr, lj_ir_kintp(J, sz)); + tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, IRT_PTR), sp[0], tr); + id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)), + CTSIZE_PTR); + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); + } +} + +/* Record ctype arithmetic metamethods. */ +static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd) +{ + cTValue *tv = NULL; + if (J->base[0]) { + if (tviscdata(&rd->argv[0])) { + CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, (MMS)rd->data); + } + if (!tv && J->base[1] && tviscdata(&rd->argv[1])) { + CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, (MMS)rd->data); + } + } + if (tv) { + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + return; + } /* NYI: non-function metamethods. */ + } else if ((MMS)rd->data == MM_eq) { + J->base[0] = TREF_FALSE; + return; + } + lj_trace_err(J, LJ_TRERR_BADTYPE); +} + +void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef sp[2]; + CType *s[2]; + MSize i; + for (i = 0; i < 2; i++) { + TRef tr = J->base[i]; + CType *ct = ctype_get(cts, CTID_DOUBLE); + if (!tr) { + goto trymeta; + } else if (tref_iscdata(tr)) { + CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid; + IRType t; + ct = ctype_raw(cts, id); + t = crec_ct2irt(cts, ct); + if (ctype_isptr(ct->info)) { /* Resolve pointer or reference. */ + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR); + if (ctype_isref(ct->info)) { + ct = ctype_rawchild(cts, ct); + t = crec_ct2irt(cts, ct); + } + } else if (t == IRT_I64 || t == IRT_U64) { + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64); + lj_needsplit(J); + goto ok; + } else if (t == IRT_INT || t == IRT_U32) { + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + goto ok; + } else if (ctype_isfunc(ct->info)) { + tr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR); + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); + goto ok; + } else { + tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata))); + } + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info)) { + if (t == IRT_CDATA) goto trymeta; + if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); + tr = emitir(IRT(IR_XLOAD, t), tr, 0); + } else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) { + goto trymeta; + } + } else if (tref_isnil(tr)) { + tr = lj_ir_kptr(J, NULL); + ct = ctype_get(cts, CTID_P_VOID); + } else if (tref_isinteger(tr)) { + ct = ctype_get(cts, CTID_INT32); + } else if (tref_isstr(tr)) { + TRef tr2 = J->base[1-i]; + CTypeID id = argv2cdata(J, tr2, &rd->argv[1-i])->ctypeid; + ct = ctype_raw(cts, id); + if (ctype_isenum(ct->info)) { /* Match string against enum constant. */ + GCstr *str = strV(&rd->argv[i]); + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, ct, str, &ofs); + if (cct && ctype_isconstval(cct->info)) { + /* Specialize to the name of the enum constant. */ + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str)); + ct = ctype_child(cts, cct); + tr = lj_ir_kint(J, (int32_t)ofs); + } /* else: interpreter will throw. */ + } /* else: interpreter will throw. */ + } else if (!tref_isnum(tr)) { + goto trymeta; + } + ok: + s[i] = ct; + sp[i] = tr; + } + { + TRef tr; + if ((tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) || + (tr = crec_arith_ptr(J, sp, s, (MMS)rd->data))) { + J->base[0] = tr; + /* Fixup cdata comparisons, too. Avoids some cdata escapes. */ + if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) && + !irt_isguard(J->guardemit)) { + const BCIns *pc = frame_contpc(J->L->base-1) - 1; + if (bc_op(*pc) <= BC_ISNEP) { + setframe_pc(&J2G(J)->tmptv, pc); + J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1); + J->postproc = LJ_POST_FIXCOMP; + } + } + } else { + trymeta: + crec_arith_meta(J, cts, rd); + } + } +} + +/* -- C library namespace metamethods ------------------------------------- */ + +void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) && + udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) { + CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0])); + GCstr *name = strV(&rd->argv[1]); + CType *ct; + CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); + cTValue *tv = lj_tab_getstr(cl->cache, name); + rd->nres = rd->data; + if (id && tv && !tvisnil(tv)) { + /* Specialize to the symbol name and make the result a constant. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name)); + if (ctype_isconstval(ct->info)) { + if (ct->size >= 0x80000000u && + (ctype_child(cts, ct)->info & CTF_UNSIGNED)) + J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size); + else + J->base[0] = lj_ir_kint(J, (int32_t)ct->size); + } else if (ctype_isextern(ct->info)) { + CTypeID sid = ctype_cid(ct->info); + void *sp = *(void **)cdataptr(cdataV(tv)); + TRef ptr; + ct = ctype_raw(cts, sid); + if (LJ_64 && !checkptr32(sp)) + ptr = lj_ir_kintp(J, (uintptr_t)sp); + else + ptr = lj_ir_kptr(J, sp); + if (rd->data) { + J->base[0] = crec_tv_ct(J, ct, sid, ptr); + } else { + J->needsnap = 1; + crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]); + } + } else { + J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA); + } + } else { + lj_trace_err(J, LJ_TRERR_NOCACHE); + } + } /* else: interpreter will throw. */ +} + +/* -- FFI library functions ----------------------------------------------- */ + +static TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval) +{ + return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval); +} + +void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd) +{ + crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0])); +} + +void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd) +{ + UNUSED(rd); + if (J->base[0]) + lj_trace_err(J, LJ_TRERR_NYICALL); + J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno); +} + +void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef tr = J->base[0]; + if (tr) { + TRef trlen = J->base[1]; + if (!tref_isnil(trlen)) { + trlen = crec_toint(J, cts, trlen, &rd->argv[1]); + tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]); + } else { + tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]); + trlen = lj_ir_call(J, IRCALL_strlen, tr); + } + J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), tr, trlen); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2]; + if (trdst && trsrc && (trlen || tref_isstr(trsrc))) { + trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]); + trsrc = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, trsrc, &rd->argv[1]); + if (trlen) { + trlen = crec_toint(J, cts, trlen, &rd->argv[2]); + } else { + trlen = emitir(IRTI(IR_FLOAD), J->base[1], IRFL_STR_LEN); + trlen = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1)); + } + rd->nres = 0; + crec_copy(J, trdst, trsrc, trlen, NULL); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2]; + if (trdst && trlen) { + CTSize step = 1; + if (tviscdata(&rd->argv[0])) { /* Get alignment of original destination. */ + CTSize sz; + CType *ct = ctype_raw(cts, cdataV(&rd->argv[0])->ctypeid); + if (ctype_isptr(ct->info)) + ct = ctype_rawchild(cts, ct); + step = (1u<argv[0]); + trlen = crec_toint(J, cts, trlen, &rd->argv[1]); + if (trfill) + trfill = crec_toint(J, cts, trfill, &rd->argv[2]); + else + trfill = lj_ir_kint(J, 0); + rd->nres = 0; + crec_fill(J, trdst, trlen, trfill, step); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd) +{ + if (tref_iscdata(J->base[0])) { + TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0])); + J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), + lj_ir_kint(J, CTID_CTYPEID), trid); + } else { + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFFU); + } +} + +void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd) +{ + argv2ctype(J, J->base[0], &rd->argv[0]); + if (tref_iscdata(J->base[1])) { + argv2ctype(J, J->base[1], &rd->argv[1]); + J->postproc = LJ_POST_FIXBOOL; + J->base[0] = TREF_TRUE; + } else { + J->base[0] = TREF_FALSE; + } +} + +void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd) +{ + if (tref_isstr(J->base[0])) { + /* Specialize to the ABI string to make the boolean result a constant. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0]))); + J->postproc = LJ_POST_FIXBOOL; + J->base[0] = TREF_TRUE; + } else { + lj_trace_err(J, LJ_TRERR_BADTYPE); + } +} + +/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */ +void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd) +{ + CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]); + if (rd->data == FF_ffi_sizeof) { + CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id); + if (ctype_isvltype(ct->info)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + } else if (rd->data == FF_ffi_offsetof) { /* Specialize to the field name. */ + if (!tref_isstr(J->base[1])) + lj_trace_err(J, LJ_TRERR_BADTYPE); + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1]))); + rd->nres = 3; /* Just in case. */ + } + J->postproc = LJ_POST_FIXCONST; + J->base[0] = J->base[1] = J->base[2] = TREF_NIL; +} + +void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd) +{ + argv2cdata(J, J->base[0], &rd->argv[0]); + crec_finalizer(J, J->base[0], &rd->argv[1]); +} + +/* -- Miscellaneous library functions ------------------------------------- */ + +void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) { + if (ctype_isinteger_or_bool(ct->info) && ct->size <= 4 && + !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) + d = ctype_get(cts, CTID_INT32); + else + d = ctype_get(cts, CTID_DOUBLE); + J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]); + } else { + J->base[0] = TREF_NIL; + } +} + +#undef IR +#undef emitir +#undef emitconv + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.h new file mode 100644 index 0000000..fb77ca6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_crecord.h @@ -0,0 +1,31 @@ +/* +** Trace recorder for C data operations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CRECORD_H +#define _LJ_CRECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" +#include "lj_ffrecord.h" + +#if LJ_HASJIT && LJ_HASFFI +LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.c new file mode 100644 index 0000000..e9fe094 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.c @@ -0,0 +1,634 @@ +/* +** C type management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_ccallback.h" + +/* -- C type definitions -------------------------------------------------- */ + +/* Predefined typedefs. */ +#define CTTDDEF(_) \ + /* Vararg handling. */ \ + _("va_list", P_VOID) \ + _("__builtin_va_list", P_VOID) \ + _("__gnuc_va_list", P_VOID) \ + /* From stddef.h. */ \ + _("ptrdiff_t", INT_PSZ) \ + _("size_t", UINT_PSZ) \ + _("wchar_t", WCHAR) \ + /* Subset of stdint.h. */ \ + _("int8_t", INT8) \ + _("int16_t", INT16) \ + _("int32_t", INT32) \ + _("int64_t", INT64) \ + _("uint8_t", UINT8) \ + _("uint16_t", UINT16) \ + _("uint32_t", UINT32) \ + _("uint64_t", UINT64) \ + _("intptr_t", INT_PSZ) \ + _("uintptr_t", UINT_PSZ) \ + /* End of typedef list. */ + +/* Keywords (only the ones we actually care for). */ +#define CTKWDEF(_) \ + /* Type specifiers. */ \ + _("void", -1, CTOK_VOID) \ + _("_Bool", 0, CTOK_BOOL) \ + _("bool", 1, CTOK_BOOL) \ + _("char", 1, CTOK_CHAR) \ + _("int", 4, CTOK_INT) \ + _("__int8", 1, CTOK_INT) \ + _("__int16", 2, CTOK_INT) \ + _("__int32", 4, CTOK_INT) \ + _("__int64", 8, CTOK_INT) \ + _("float", 4, CTOK_FP) \ + _("double", 8, CTOK_FP) \ + _("long", 0, CTOK_LONG) \ + _("short", 0, CTOK_SHORT) \ + _("_Complex", 0, CTOK_COMPLEX) \ + _("complex", 0, CTOK_COMPLEX) \ + _("__complex", 0, CTOK_COMPLEX) \ + _("__complex__", 0, CTOK_COMPLEX) \ + _("signed", 0, CTOK_SIGNED) \ + _("__signed", 0, CTOK_SIGNED) \ + _("__signed__", 0, CTOK_SIGNED) \ + _("unsigned", 0, CTOK_UNSIGNED) \ + /* Type qualifiers. */ \ + _("const", 0, CTOK_CONST) \ + _("__const", 0, CTOK_CONST) \ + _("__const__", 0, CTOK_CONST) \ + _("volatile", 0, CTOK_VOLATILE) \ + _("__volatile", 0, CTOK_VOLATILE) \ + _("__volatile__", 0, CTOK_VOLATILE) \ + _("restrict", 0, CTOK_RESTRICT) \ + _("__restrict", 0, CTOK_RESTRICT) \ + _("__restrict__", 0, CTOK_RESTRICT) \ + _("inline", 0, CTOK_INLINE) \ + _("__inline", 0, CTOK_INLINE) \ + _("__inline__", 0, CTOK_INLINE) \ + /* Storage class specifiers. */ \ + _("typedef", 0, CTOK_TYPEDEF) \ + _("extern", 0, CTOK_EXTERN) \ + _("static", 0, CTOK_STATIC) \ + _("auto", 0, CTOK_AUTO) \ + _("register", 0, CTOK_REGISTER) \ + /* GCC Attributes. */ \ + _("__extension__", 0, CTOK_EXTENSION) \ + _("__attribute", 0, CTOK_ATTRIBUTE) \ + _("__attribute__", 0, CTOK_ATTRIBUTE) \ + _("asm", 0, CTOK_ASM) \ + _("__asm", 0, CTOK_ASM) \ + _("__asm__", 0, CTOK_ASM) \ + /* MSVC Attributes. */ \ + _("__declspec", 0, CTOK_DECLSPEC) \ + _("__cdecl", CTCC_CDECL, CTOK_CCDECL) \ + _("__thiscall", CTCC_THISCALL, CTOK_CCDECL) \ + _("__fastcall", CTCC_FASTCALL, CTOK_CCDECL) \ + _("__stdcall", CTCC_STDCALL, CTOK_CCDECL) \ + _("__ptr32", 4, CTOK_PTRSZ) \ + _("__ptr64", 8, CTOK_PTRSZ) \ + /* Other type specifiers. */ \ + _("struct", 0, CTOK_STRUCT) \ + _("union", 0, CTOK_UNION) \ + _("enum", 0, CTOK_ENUM) \ + /* Operators. */ \ + _("sizeof", 0, CTOK_SIZEOF) \ + _("__alignof", 0, CTOK_ALIGNOF) \ + _("__alignof__", 0, CTOK_ALIGNOF) \ + /* End of keyword list. */ + +/* Type info for predefined types. Size merged in. */ +static CTInfo lj_ctype_typeinfo[] = { +#define CTTYINFODEF(id, sz, ct, info) CTINFO((ct),(((sz)&0x3fu)<<10)+(info)), +#define CTTDINFODEF(name, id) CTINFO(CT_TYPEDEF, CTID_##id), +#define CTKWINFODEF(name, sz, kw) CTINFO(CT_KW,(((sz)&0x3fu)<<10)+(kw)), +CTTYDEF(CTTYINFODEF) +CTTDDEF(CTTDINFODEF) +CTKWDEF(CTKWINFODEF) +#undef CTTYINFODEF +#undef CTTDINFODEF +#undef CTKWINFODEF + 0 +}; + +/* Predefined type names collected in a single string. */ +static const char * const lj_ctype_typenames = +#define CTTDNAMEDEF(name, id) name "\0" +#define CTKWNAMEDEF(name, sz, cds) name "\0" +CTTDDEF(CTTDNAMEDEF) +CTKWDEF(CTKWNAMEDEF) +#undef CTTDNAMEDEF +#undef CTKWNAMEDEF +; + +#define CTTYPEINFO_NUM (sizeof(lj_ctype_typeinfo)/sizeof(CTInfo)-1) +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR +#define CTTYPETAB_MIN CTTYPEINFO_NUM +#else +#define CTTYPETAB_MIN 128 +#endif + +/* -- C type interning ---------------------------------------------------- */ + +#define ct_hashtype(info, size) (hashrot(info, size) & CTHASH_MASK) +#define ct_hashname(name) \ + (hashrot(u32ptr(name), u32ptr(name) + HASH_BIAS) & CTHASH_MASK) + +/* Create new type element. */ +CTypeID lj_ctype_new(CTState *cts, CType **ctp) +{ + CTypeID id = cts->top; + CType *ct; + lua_assert(cts->L); + if (LJ_UNLIKELY(id >= cts->sizetab)) { + if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV); +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR + ct = lj_mem_newvec(cts->L, id+1, CType); + memcpy(ct, cts->tab, id*sizeof(CType)); + memset(cts->tab, 0, id*sizeof(CType)); + lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType); + cts->tab = ct; + cts->sizetab = id+1; +#else + lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType); +#endif + } + cts->top = id+1; + *ctp = ct = &cts->tab[id]; + ct->info = 0; + ct->size = 0; + ct->sib = 0; + ct->next = 0; + setgcrefnull(ct->name); + return id; +} + +/* Intern a type element. */ +CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size) +{ + uint32_t h = ct_hashtype(info, size); + CTypeID id = cts->hash[h]; + lua_assert(cts->L); + while (id) { + CType *ct = ctype_get(cts, id); + if (ct->info == info && ct->size == size) + return id; + id = ct->next; + } + id = cts->top; + if (LJ_UNLIKELY(id >= cts->sizetab)) { + if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV); + lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType); + } + cts->top = id+1; + cts->tab[id].info = info; + cts->tab[id].size = size; + cts->tab[id].sib = 0; + cts->tab[id].next = cts->hash[h]; + setgcrefnull(cts->tab[id].name); + cts->hash[h] = (CTypeID1)id; + return id; +} + +/* Add type element to hash table. */ +static void ctype_addtype(CTState *cts, CType *ct, CTypeID id) +{ + uint32_t h = ct_hashtype(ct->info, ct->size); + ct->next = cts->hash[h]; + cts->hash[h] = (CTypeID1)id; +} + +/* Add named element to hash table. */ +void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id) +{ + uint32_t h = ct_hashname(gcref(ct->name)); + ct->next = cts->hash[h]; + cts->hash[h] = (CTypeID1)id; +} + +/* Get a C type by name, matching the type mask. */ +CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, uint32_t tmask) +{ + CTypeID id = cts->hash[ct_hashname(name)]; + while (id) { + CType *ct = ctype_get(cts, id); + if (gcref(ct->name) == obj2gco(name) && + ((tmask >> ctype_type(ct->info)) & 1)) { + *ctp = ct; + return id; + } + id = ct->next; + } + *ctp = &cts->tab[0]; /* Simplify caller logic. ctype_get() would assert. */ + return 0; +} + +/* Get a struct/union/enum/function field by name. */ +CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, CTSize *ofs, + CTInfo *qual) +{ + while (ct->sib) { + ct = ctype_get(cts, ct->sib); + if (gcref(ct->name) == obj2gco(name)) { + *ofs = ct->size; + return ct; + } + if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + CType *fct, *cct = ctype_child(cts, ct); + CTInfo q = 0; + while (ctype_isattrib(cct->info)) { + if (ctype_attrib(cct->info) == CTA_QUAL) q |= cct->size; + cct = ctype_child(cts, cct); + } + fct = lj_ctype_getfieldq(cts, cct, name, ofs, qual); + if (fct) { + if (qual) *qual |= q; + *ofs += ct->size; + return fct; + } + } + } + return NULL; /* Not found. */ +} + +/* -- C type information -------------------------------------------------- */ + +/* Follow references and get raw type for a C type ID. */ +CType *lj_ctype_rawref(CTState *cts, CTypeID id) +{ + CType *ct = ctype_get(cts, id); + while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) + ct = ctype_child(cts, ct); + return ct; +} + +/* Get size for a C type ID. Does NOT support VLA/VLS. */ +CTSize lj_ctype_size(CTState *cts, CTypeID id) +{ + CType *ct = ctype_raw(cts, id); + return ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID; +} + +/* Get size for a variable-length C type. Does NOT support other C types. */ +CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem) +{ + uint64_t xsz = 0; + if (ctype_isstruct(ct->info)) { + CTypeID arrid = 0, fid = ct->sib; + xsz = ct->size; /* Add the struct size. */ + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (ctype_type(ctf->info) == CT_FIELD) + arrid = ctype_cid(ctf->info); /* Remember last field of VLS. */ + fid = ctf->sib; + } + ct = ctype_raw(cts, arrid); + } + lua_assert(ctype_isvlarray(ct->info)); /* Must be a VLA. */ + ct = ctype_rawchild(cts, ct); /* Get array element. */ + lua_assert(ctype_hassize(ct->info)); + /* Calculate actual size of VLA and check for overflow. */ + xsz += (uint64_t)ct->size * nelem; + return xsz < 0x80000000u ? (CTSize)xsz : CTSIZE_INVALID; +} + +/* Get type, qualifiers, size and alignment for a C type ID. */ +CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp) +{ + CTInfo qual = 0; + CType *ct = ctype_get(cts, id); + for (;;) { + CTInfo info = ct->info; + if (ctype_isenum(info)) { + /* Follow child. Need to look at its attributes, too. */ + } else if (ctype_isattrib(info)) { + if (ctype_isxattrib(info, CTA_QUAL)) + qual |= ct->size; + else if (ctype_isxattrib(info, CTA_ALIGN) && !(qual & CTFP_ALIGNED)) + qual |= CTFP_ALIGNED + CTALIGN(ct->size); + } else { + if (!(qual & CTFP_ALIGNED)) qual |= (info & CTF_ALIGN); + qual |= (info & ~(CTF_ALIGN|CTMASK_CID)); + lua_assert(ctype_hassize(info) || ctype_isfunc(info)); + *szp = ctype_isfunc(info) ? CTSIZE_INVALID : ct->size; + break; + } + ct = ctype_get(cts, ctype_cid(info)); + } + return qual; +} + +/* Get ctype metamethod. */ +cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm) +{ + CType *ct = ctype_get(cts, id); + cTValue *tv; + while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) { + id = ctype_cid(ct->info); + ct = ctype_get(cts, id); + } + if (ctype_isptr(ct->info) && + ctype_isfunc(ctype_get(cts, ctype_cid(ct->info))->info)) + tv = lj_tab_getstr(cts->miscmap, &cts->g->strempty); + else + tv = lj_tab_getinth(cts->miscmap, -(int32_t)id); + if (tv && tvistab(tv) && + (tv = lj_tab_getstr(tabV(tv), mmname_str(cts->g, mm))) && !tvisnil(tv)) + return tv; + return NULL; +} + +/* -- C type representation ----------------------------------------------- */ + +/* Fixed max. length of a C type representation. */ +#define CTREPR_MAX 512 + +typedef struct CTRepr { + char *pb, *pe; + CTState *cts; + lua_State *L; + int needsp; + int ok; + char buf[CTREPR_MAX]; +} CTRepr; + +/* Prepend string. */ +static void ctype_prepstr(CTRepr *ctr, const char *str, MSize len) +{ + char *p = ctr->pb; + if (ctr->buf + len+1 > p) { ctr->ok = 0; return; } + if (ctr->needsp) *--p = ' '; + ctr->needsp = 1; + p -= len; + while (len-- > 0) p[len] = str[len]; + ctr->pb = p; +} + +#define ctype_preplit(ctr, str) ctype_prepstr((ctr), "" str, sizeof(str)-1) + +/* Prepend char. */ +static void ctype_prepc(CTRepr *ctr, int c) +{ + if (ctr->buf >= ctr->pb) { ctr->ok = 0; return; } + *--ctr->pb = c; +} + +/* Prepend number. */ +static void ctype_prepnum(CTRepr *ctr, uint32_t n) +{ + char *p = ctr->pb; + if (ctr->buf + 10+1 > p) { ctr->ok = 0; return; } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + ctr->pb = p; + ctr->needsp = 0; +} + +/* Append char. */ +static void ctype_appc(CTRepr *ctr, int c) +{ + if (ctr->pe >= ctr->buf + CTREPR_MAX) { ctr->ok = 0; return; } + *ctr->pe++ = c; +} + +/* Append number. */ +static void ctype_appnum(CTRepr *ctr, uint32_t n) +{ + char buf[10]; + char *p = buf+sizeof(buf); + char *q = ctr->pe; + if (q > ctr->buf + CTREPR_MAX - 10) { ctr->ok = 0; return; } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + do { *q++ = *p++; } while (p < buf+sizeof(buf)); + ctr->pe = q; +} + +/* Prepend qualifiers. */ +static void ctype_prepqual(CTRepr *ctr, CTInfo info) +{ + if ((info & CTF_VOLATILE)) ctype_preplit(ctr, "volatile"); + if ((info & CTF_CONST)) ctype_preplit(ctr, "const"); +} + +/* Prepend named type. */ +static void ctype_preptype(CTRepr *ctr, CType *ct, CTInfo qual, const char *t) +{ + if (gcref(ct->name)) { + GCstr *str = gco2str(gcref(ct->name)); + ctype_prepstr(ctr, strdata(str), str->len); + } else { + if (ctr->needsp) ctype_prepc(ctr, ' '); + ctype_prepnum(ctr, ctype_typeid(ctr->cts, ct)); + ctr->needsp = 1; + } + ctype_prepstr(ctr, t, (MSize)strlen(t)); + ctype_prepqual(ctr, qual); +} + +static void ctype_repr(CTRepr *ctr, CTypeID id) +{ + CType *ct = ctype_get(ctr->cts, id); + CTInfo qual = 0; + int ptrto = 0; + for (;;) { + CTInfo info = ct->info; + CTSize size = ct->size; + switch (ctype_type(info)) { + case CT_NUM: + if ((info & CTF_BOOL)) { + ctype_preplit(ctr, "bool"); + } else if ((info & CTF_FP)) { + if (size == sizeof(double)) ctype_preplit(ctr, "double"); + else if (size == sizeof(float)) ctype_preplit(ctr, "float"); + else ctype_preplit(ctr, "long double"); + } else if (size == 1) { + if (!((info ^ CTF_UCHAR) & CTF_UNSIGNED)) ctype_preplit(ctr, "char"); + else if (CTF_UCHAR) ctype_preplit(ctr, "signed char"); + else ctype_preplit(ctr, "unsigned char"); + } else if (size < 8) { + if (size == 4) ctype_preplit(ctr, "int"); + else ctype_preplit(ctr, "short"); + if ((info & CTF_UNSIGNED)) ctype_preplit(ctr, "unsigned"); + } else { + ctype_preplit(ctr, "_t"); + ctype_prepnum(ctr, size*8); + ctype_preplit(ctr, "int"); + if ((info & CTF_UNSIGNED)) ctype_prepc(ctr, 'u'); + } + ctype_prepqual(ctr, (qual|info)); + return; + case CT_VOID: + ctype_preplit(ctr, "void"); + ctype_prepqual(ctr, (qual|info)); + return; + case CT_STRUCT: + ctype_preptype(ctr, ct, qual, (info & CTF_UNION) ? "union" : "struct"); + return; + case CT_ENUM: + if (id == CTID_CTYPEID) { + ctype_preplit(ctr, "ctype"); + return; + } + ctype_preptype(ctr, ct, qual, "enum"); + return; + case CT_ATTRIB: + if (ctype_attrib(info) == CTA_QUAL) qual |= size; + break; + case CT_PTR: + if ((info & CTF_REF)) { + ctype_prepc(ctr, '&'); + } else { + ctype_prepqual(ctr, (qual|info)); + if (LJ_64 && size == 4) ctype_preplit(ctr, "__ptr32"); + ctype_prepc(ctr, '*'); + } + qual = 0; + ptrto = 1; + ctr->needsp = 1; + break; + case CT_ARRAY: + if (ctype_isrefarray(info)) { + ctr->needsp = 1; + if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); } + ctype_appc(ctr, '['); + if (size != CTSIZE_INVALID) { + CTSize csize = ctype_child(ctr->cts, ct)->size; + ctype_appnum(ctr, csize ? size/csize : 0); + } else if ((info & CTF_VLA)) { + ctype_appc(ctr, '?'); + } + ctype_appc(ctr, ']'); + } else if ((info & CTF_COMPLEX)) { + if (size == 2*sizeof(float)) ctype_preplit(ctr, "float"); + ctype_preplit(ctr, "complex"); + return; + } else { + ctype_preplit(ctr, ")))"); + ctype_prepnum(ctr, size); + ctype_preplit(ctr, "__attribute__((vector_size("); + } + break; + case CT_FUNC: + ctr->needsp = 1; + if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); } + ctype_appc(ctr, '('); + ctype_appc(ctr, ')'); + break; + default: + lua_assert(0); + break; + } + ct = ctype_get(ctr->cts, ctype_cid(info)); + } +} + +/* Return a printable representation of a C type. */ +GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name) +{ + global_State *g = G(L); + CTRepr ctr; + ctr.pb = ctr.pe = &ctr.buf[CTREPR_MAX/2]; + ctr.cts = ctype_ctsG(g); + ctr.L = L; + ctr.ok = 1; + ctr.needsp = 0; + if (name) ctype_prepstr(&ctr, strdata(name), name->len); + ctype_repr(&ctr, id); + if (LJ_UNLIKELY(!ctr.ok)) return lj_str_newlit(L, "?"); + return lj_str_new(L, ctr.pb, ctr.pe - ctr.pb); +} + +/* Convert int64_t/uint64_t to string with 'LL' or 'ULL' suffix. */ +GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned) +{ + char buf[1+20+3]; + char *p = buf+sizeof(buf); + int sign = 0; + *--p = 'L'; *--p = 'L'; + if (isunsigned) { + *--p = 'U'; + } else if ((int64_t)n < 0) { + n = (uint64_t)-(int64_t)n; + sign = 1; + } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + if (sign) *--p = '-'; + return lj_str_new(L, p, (size_t)(buf+sizeof(buf)-p)); +} + +/* Convert complex to string with 'i' or 'I' suffix. */ +GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size) +{ + char buf[2*LJ_STR_NUMBUF+2+1]; + TValue re, im; + size_t len; + if (size == 2*sizeof(double)) { + re.n = *(double *)sp; im.n = ((double *)sp)[1]; + } else { + re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1]; + } + len = lj_str_bufnum(buf, &re); + if (!(im.u32.hi & 0x80000000u) || im.n != im.n) buf[len++] = '+'; + len += lj_str_bufnum(buf+len, &im); + buf[len] = buf[len-1] >= 'a' ? 'I' : 'i'; + return lj_str_new(L, buf, len+1); +} + +/* -- C type state -------------------------------------------------------- */ + +/* Initialize C type table and state. */ +CTState *lj_ctype_init(lua_State *L) +{ + CTState *cts = lj_mem_newt(L, sizeof(CTState), CTState); + CType *ct = lj_mem_newvec(L, CTTYPETAB_MIN, CType); + const char *name = lj_ctype_typenames; + CTypeID id; + memset(cts, 0, sizeof(CTState)); + cts->tab = ct; + cts->sizetab = CTTYPETAB_MIN; + cts->top = CTTYPEINFO_NUM; + cts->L = NULL; + cts->g = G(L); + for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) { + CTInfo info = lj_ctype_typeinfo[id]; + ct->size = (CTSize)((int32_t)(info << 16) >> 26); + ct->info = info & 0xffff03ffu; + ct->sib = 0; + if (ctype_type(info) == CT_KW || ctype_istypedef(info)) { + size_t len = strlen(name); + GCstr *str = lj_str_new(L, name, len); + ctype_setname(ct, str); + name += len+1; + lj_ctype_addname(cts, ct, id); + } else { + setgcrefnull(ct->name); + ct->next = 0; + if (!ctype_isenum(info)) ctype_addtype(cts, ct, id); + } + } + setmref(G(L)->ctype_state, cts); + return cts; +} + +/* Free C type table and state. */ +void lj_ctype_freestate(global_State *g) +{ + CTState *cts = ctype_ctsG(g); + if (cts) { + lj_ccallback_mcode_free(cts); + lj_mem_freevec(g, cts->tab, cts->sizetab, CType); + lj_mem_freevec(g, cts->cb.cbid, cts->cb.sizeid, CTypeID1); + lj_mem_freet(g, cts); + } +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.h new file mode 100644 index 0000000..ff8ee06 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ctype.h @@ -0,0 +1,461 @@ +/* +** C type management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CTYPE_H +#define _LJ_CTYPE_H + +#include "lj_obj.h" +#include "lj_gc.h" + +#if LJ_HASFFI + +/* -- C type definitions -------------------------------------------------- */ + +/* C type numbers. Highest 4 bits of C type info. ORDER CT. */ +enum { + /* Externally visible types. */ + CT_NUM, /* Integer or floating-point numbers. */ + CT_STRUCT, /* Struct or union. */ + CT_PTR, /* Pointer or reference. */ + CT_ARRAY, /* Array or complex type. */ + CT_MAYCONVERT = CT_ARRAY, + CT_VOID, /* Void type. */ + CT_ENUM, /* Enumeration. */ + CT_HASSIZE = CT_ENUM, /* Last type where ct->size holds the actual size. */ + CT_FUNC, /* Function. */ + CT_TYPEDEF, /* Typedef. */ + CT_ATTRIB, /* Miscellaneous attributes. */ + /* Internal element types. */ + CT_FIELD, /* Struct/union field or function parameter. */ + CT_BITFIELD, /* Struct/union bitfield. */ + CT_CONSTVAL, /* Constant value. */ + CT_EXTERN, /* External reference. */ + CT_KW /* Keyword. */ +}; + +LJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR); +LJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT); + +/* +** ---------- info ------------ +** |type flags... A cid | size | sib | next | name | +** +----------------------------+--------+-------+-------+-------+-- +** |NUM BFvcUL.. A | size | | type | | +** |STRUCT ..vcU..V A | size | field | name? | name? | +** |PTR ..vcR... A cid | size | | type | | +** |ARRAY VCvc...V A cid | size | | type | | +** |VOID ..vc.... A | size | | type | | +** |ENUM A cid | size | const | name? | name? | +** |FUNC ....VS.. cc cid | nargs | field | name? | name? | +** |TYPEDEF cid | | | name | name | +** |ATTRIB attrnum cid | attr | sib? | type? | | +** |FIELD cid | offset | field | | name? | +** |BITFIELD B.vcU csz bsz pos | offset | field | | name? | +** |CONSTVAL c cid | value | const | name | name | +** |EXTERN cid | | sib? | name | name | +** |KW tok | size | | name | name | +** +----------------------------+--------+-------+-------+-------+-- +** ^^ ^^--- bits used for C type conversion dispatch +*/ + +/* C type info flags. TFFArrrr */ +#define CTF_BOOL 0x08000000u /* Boolean: NUM, BITFIELD. */ +#define CTF_FP 0x04000000u /* Floating-point: NUM. */ +#define CTF_CONST 0x02000000u /* Const qualifier. */ +#define CTF_VOLATILE 0x01000000u /* Volatile qualifier. */ +#define CTF_UNSIGNED 0x00800000u /* Unsigned: NUM, BITFIELD. */ +#define CTF_LONG 0x00400000u /* Long: NUM. */ +#define CTF_VLA 0x00100000u /* Variable-length: ARRAY, STRUCT. */ +#define CTF_REF 0x00800000u /* Reference: PTR. */ +#define CTF_VECTOR 0x08000000u /* Vector: ARRAY. */ +#define CTF_COMPLEX 0x04000000u /* Complex: ARRAY. */ +#define CTF_UNION 0x00800000u /* Union: STRUCT. */ +#define CTF_VARARG 0x00800000u /* Vararg: FUNC. */ +#define CTF_SSEREGPARM 0x00400000u /* SSE register parameters: FUNC. */ + +#define CTF_QUAL (CTF_CONST|CTF_VOLATILE) +#define CTF_ALIGN (CTMASK_ALIGN< 0 ? CTF_UNSIGNED : 0) + +/* Flags used in parser. .F.Ammvf cp->attr */ +#define CTFP_ALIGNED 0x00000001u /* cp->attr + ALIGN */ +#define CTFP_PACKED 0x00000002u /* cp->attr */ +/* ...C...f cp->fattr */ +#define CTFP_CCONV 0x00000001u /* cp->fattr + CCONV/[SSE]REGPARM */ + +/* C type info bitfields. */ +#define CTMASK_CID 0x0000ffffu /* Max. 65536 type IDs. */ +#define CTMASK_NUM 0xf0000000u /* Max. 16 type numbers. */ +#define CTSHIFT_NUM 28 +#define CTMASK_ALIGN 15 /* Max. alignment is 2^15. */ +#define CTSHIFT_ALIGN 16 +#define CTMASK_ATTRIB 255 /* Max. 256 attributes. */ +#define CTSHIFT_ATTRIB 16 +#define CTMASK_CCONV 3 /* Max. 4 calling conventions. */ +#define CTSHIFT_CCONV 16 +#define CTMASK_REGPARM 3 /* Max. 0-3 regparms. */ +#define CTSHIFT_REGPARM 18 +/* Bitfields only used in parser. */ +#define CTMASK_VSIZEP 15 /* Max. vector size is 2^15. */ +#define CTSHIFT_VSIZEP 4 +#define CTMASK_MSIZEP 255 /* Max. type size (via mode) is 128. */ +#define CTSHIFT_MSIZEP 8 + +/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */ +#define CTBSZ_MAX 32 /* Max. size of bitfield is 32 bit. */ +#define CTBSZ_FIELD 127 /* Temp. marker for regular field. */ +#define CTMASK_BITPOS 127 +#define CTMASK_BITBSZ 127 +#define CTMASK_BITCSZ 127 +#define CTSHIFT_BITPOS 0 +#define CTSHIFT_BITBSZ 8 +#define CTSHIFT_BITCSZ 16 + +#define CTF_INSERT(info, field, val) \ + info = (info & ~(CTMASK_##field<> CTSHIFT_NUM) +#define ctype_cid(info) ((CTypeID)((info) & CTMASK_CID)) +#define ctype_align(info) (((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN) +#define ctype_attrib(info) (((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB) +#define ctype_bitpos(info) (((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS) +#define ctype_bitbsz(info) (((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ) +#define ctype_bitcsz(info) (((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ) +#define ctype_vsizeP(info) (((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP) +#define ctype_msizeP(info) (((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP) +#define ctype_cconv(info) (((info) >> CTSHIFT_CCONV) & CTMASK_CCONV) + +/* Simple type checks. */ +#define ctype_isnum(info) (ctype_type((info)) == CT_NUM) +#define ctype_isvoid(info) (ctype_type((info)) == CT_VOID) +#define ctype_isptr(info) (ctype_type((info)) == CT_PTR) +#define ctype_isarray(info) (ctype_type((info)) == CT_ARRAY) +#define ctype_isstruct(info) (ctype_type((info)) == CT_STRUCT) +#define ctype_isfunc(info) (ctype_type((info)) == CT_FUNC) +#define ctype_isenum(info) (ctype_type((info)) == CT_ENUM) +#define ctype_istypedef(info) (ctype_type((info)) == CT_TYPEDEF) +#define ctype_isattrib(info) (ctype_type((info)) == CT_ATTRIB) +#define ctype_isfield(info) (ctype_type((info)) == CT_FIELD) +#define ctype_isbitfield(info) (ctype_type((info)) == CT_BITFIELD) +#define ctype_isconstval(info) (ctype_type((info)) == CT_CONSTVAL) +#define ctype_isextern(info) (ctype_type((info)) == CT_EXTERN) +#define ctype_hassize(info) (ctype_type((info)) <= CT_HASSIZE) + +/* Combined type and flag checks. */ +#define ctype_isinteger(info) \ + (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0)) +#define ctype_isinteger_or_bool(info) \ + (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0)) +#define ctype_isbool(info) \ + (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL)) +#define ctype_isfp(info) \ + (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP)) + +#define ctype_ispointer(info) \ + ((ctype_type(info) >> 1) == (CT_PTR >> 1)) /* Pointer or array. */ +#define ctype_isref(info) \ + (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF)) + +#define ctype_isrefarray(info) \ + (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0)) +#define ctype_isvector(info) \ + (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR)) +#define ctype_iscomplex(info) \ + (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX)) + +#define ctype_isvltype(info) \ + (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<") _(STRING, "") \ + _(INTEGER, "") _(EOF, "") \ + _(OROR, "||") _(ANDAND, "&&") _(EQ, "==") _(NE, "!=") \ + _(LE, "<=") _(GE, ">=") _(SHL, "<<") _(SHR, ">>") _(DEREF, "->") + +/* Simple declaration specifiers. */ +#define CDSDEF(_) \ + _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \ + _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \ + _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \ + _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER) + +/* C keywords. */ +#define CKWDEF(_) \ + CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \ + _(DECLSPEC) _(CCDECL) _(PTRSZ) \ + _(STRUCT) _(UNION) _(ENUM) \ + _(SIZEOF) _(ALIGNOF) + +/* C token numbers. */ +enum { + CTOK_OFS = 255, +#define CTOKNUM(name, sym) CTOK_##name, +#define CKWNUM(name) CTOK_##name, +CTOKDEF(CTOKNUM) +CKWDEF(CKWNUM) +#undef CTOKNUM +#undef CKWNUM + CTOK_FIRSTDECL = CTOK_VOID, + CTOK_FIRSTSCL = CTOK_TYPEDEF, + CTOK_LASTDECLFLAG = CTOK_REGISTER, + CTOK_LASTDECL = CTOK_ENUM +}; + +/* Declaration specifier flags. */ +enum { +#define CDSFLAG(name) CDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)), +CDSDEF(CDSFLAG) +#undef CDSFLAG + CDF__END +}; + +#define CDF_SCL (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER) + +/* -- C type management --------------------------------------------------- */ + +#define ctype_ctsG(g) (mref((g)->ctype_state, CTState)) + +/* Get C type state. */ +static LJ_AINLINE CTState *ctype_cts(lua_State *L) +{ + CTState *cts = ctype_ctsG(G(L)); + cts->L = L; /* Save L for errors and allocations. */ + return cts; +} + +/* Save and restore state of C type table. */ +#define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts) +#define LJ_CTYPE_RESTORE(cts) \ + ((cts)->top = savects_.top, \ + memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash))) + +/* Check C type ID for validity when assertions are enabled. */ +static LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id) +{ + lua_assert(id > 0 && id < cts->top); UNUSED(cts); + return id; +} + +/* Get C type for C type ID. */ +static LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id) +{ + return &cts->tab[ctype_check(cts, id)]; +} + +/* Get C type ID for a C type. */ +#define ctype_typeid(cts, ct) ((CTypeID)((ct) - (cts)->tab)) + +/* Get child C type. */ +static LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct) +{ + lua_assert(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) || + ctype_isbitfield(ct->info))); /* These don't have children. */ + return ctype_get(cts, ctype_cid(ct->info)); +} + +/* Get raw type for a C type ID. */ +static LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id) +{ + CType *ct = ctype_get(cts, id); + while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct); + return ct; +} + +/* Get raw type of the child of a C type. */ +static LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct) +{ + do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info)); + return ct; +} + +/* Set the name of a C type table element. */ +static LJ_AINLINE void ctype_setname(CType *ct, GCstr *s) +{ + /* NOBARRIER: mark string as fixed -- the C type table is never collected. */ + fixstring(s); + setgcref(ct->name, obj2gco(s)); +} + +LJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp); +LJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size); +LJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id); +LJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, + uint32_t tmask); +LJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, + CTSize *ofs, CTInfo *qual); +#define lj_ctype_getfield(cts, ct, name, ofs) \ + lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL) +LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id); +LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id); +LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem); +LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp); +LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm); +LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name); +LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned); +LJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size); +LJ_FUNC CTState *lj_ctype_init(lua_State *L); +LJ_FUNC void lj_ctype_freestate(global_State *g); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.c new file mode 100644 index 0000000..4653a4e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.c @@ -0,0 +1,603 @@ +/* +** Debugging and introspection. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_debug_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif + +/* -- Frames -------------------------------------------------------------- */ + +/* Get frame corresponding to a level. */ +cTValue *lj_debug_frame(lua_State *L, int level, int *size) +{ + cTValue *frame, *nextframe, *bot = tvref(L->stack); + /* Traverse frames backwards. */ + for (nextframe = frame = L->base-1; frame > bot; ) { + if (frame_gc(frame) == obj2gco(L)) + level++; /* Skip dummy frames. See lj_meta_call(). */ + if (level-- == 0) { + *size = (int)(nextframe - frame); + return frame; /* Level found. */ + } + nextframe = frame; + if (frame_islua(frame)) { + frame = frame_prevl(frame); + } else { + if (frame_isvarg(frame)) + level++; /* Skip vararg pseudo-frame. */ + frame = frame_prevd(frame); + } + } + *size = level; + return NULL; /* Level not found. */ +} + +/* Invalid bytecode position. */ +#define NO_BCPOS (~(BCPos)0) + +/* Return bytecode position for function/frame or NO_BCPOS. */ +static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) +{ + const BCIns *ins; + GCproto *pt; + BCPos pos; + lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD); + if (!isluafunc(fn)) { /* Cannot derive a PC for non-Lua functions. */ + return NO_BCPOS; + } else if (nextframe == NULL) { /* Lua function on top. */ + void *cf = cframe_raw(L->cframe); + if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf)) + return NO_BCPOS; + ins = cframe_pc(cf); /* Only happens during error/hook handling. */ + } else { + if (frame_islua(nextframe)) { + ins = frame_pc(nextframe); + } else if (frame_iscont(nextframe)) { + ins = frame_contpc(nextframe); + } else { + /* Lua function below errfunc/gc/hook: find cframe to get the PC. */ + void *cf = cframe_raw(L->cframe); + TValue *f = L->base-1; + for (;;) { + if (cf == NULL) + return NO_BCPOS; + while (cframe_nres(cf) < 0) { + if (f >= restorestack(L, -cframe_nres(cf))) + break; + cf = cframe_raw(cframe_prev(cf)); + if (cf == NULL) + return NO_BCPOS; + } + if (f < nextframe) + break; + if (frame_islua(f)) { + f = frame_prevl(f); + } else { + if (frame_isc(f)) + cf = cframe_raw(cframe_prev(cf)); + f = frame_prevd(f); + } + } + ins = cframe_pc(cf); + } + } + pt = funcproto(fn); + pos = proto_bcpos(pt, ins) - 1; +#if LJ_HASJIT + if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */ + GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); + lua_assert(bc_isret(bc_op(ins[-1]))); + pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + } +#endif + return pos; +} + +/* -- Line numbers -------------------------------------------------------- */ + +/* Get line number for a bytecode position. */ +BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc) +{ + const void *lineinfo = proto_lineinfo(pt); + if (pc <= pt->sizebc && lineinfo) { + BCLine first = pt->firstline; + if (pc == pt->sizebc) return first + pt->numline; + if (pc-- == 0) return first; + if (pt->numline < 256) + return first + (BCLine)((const uint8_t *)lineinfo)[pc]; + else if (pt->numline < 65536) + return first + (BCLine)((const uint16_t *)lineinfo)[pc]; + else + return first + (BCLine)((const uint32_t *)lineinfo)[pc]; + } + return 0; +} + +/* Get line number for function/frame. */ +static BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe) +{ + BCPos pc = debug_framepc(L, fn, nextframe); + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + lua_assert(pc <= pt->sizebc); + return lj_debug_line(pt, pc); + } + return -1; +} + +/* -- Variable names ------------------------------------------------------ */ + +/* Read ULEB128 value. */ +static uint32_t debug_read_uleb128(const uint8_t **pp) +{ + const uint8_t *p = *pp; + uint32_t v = *p++; + if (LJ_UNLIKELY(v >= 0x80)) { + int sh = 0; + v &= 0x7f; + do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80); + } + *pp = p; + return v; +} + +/* Get name of a local variable from slot number and PC. */ +static const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot) +{ + const uint8_t *p = proto_varinfo(pt); + if (p) { + BCPos lastpc = 0; + for (;;) { + const char *name = (const char *)p; + uint32_t vn = *p++; + BCPos startpc, endpc; + if (vn < VARNAME__MAX) { + if (vn == VARNAME_END) break; /* End of varinfo. */ + } else { + while (*p++) ; /* Skip over variable name string. */ + } + lastpc = startpc = lastpc + debug_read_uleb128(&p); + if (startpc > pc) break; + endpc = startpc + debug_read_uleb128(&p); + if (pc < endpc && slot-- == 0) { + if (vn < VARNAME__MAX) { +#define VARNAMESTR(name, str) str "\0" + name = VARNAMEDEF(VARNAMESTR); +#undef VARNAMESTR + if (--vn) while (*name++ || --vn) ; + } + return name; + } + } + } + return NULL; +} + +/* Get name of local variable from 1-based slot number and function/frame. */ +static TValue *debug_localname(lua_State *L, const lua_Debug *ar, + const char **name, BCReg slot1) +{ + uint32_t offset = (uint32_t)ar->i_ci & 0xffff; + uint32_t size = (uint32_t)ar->i_ci >> 16; + TValue *frame = tvref(L->stack) + offset; + TValue *nextframe = size ? frame + size : NULL; + GCfunc *fn = frame_func(frame); + BCPos pc = debug_framepc(L, fn, nextframe); + if (!nextframe) nextframe = L->top; + if ((int)slot1 < 0) { /* Negative slot number is for varargs. */ + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + if ((pt->flags & PROTO_VARARG)) { + slot1 = pt->numparams + (BCReg)(-(int)slot1); + if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */ + nextframe = frame; + frame = frame_prevd(frame); + } + if (frame + slot1 < nextframe) { + *name = "(*vararg)"; + return frame+slot1; + } + } + } + return NULL; + } + if (pc != NO_BCPOS && + (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL) + ; + else if (slot1 > 0 && frame + slot1 < nextframe) + *name = "(*temporary)"; + return frame+slot1; +} + +/* Get name of upvalue. */ +const char *lj_debug_uvname(GCproto *pt, uint32_t idx) +{ + const uint8_t *p = proto_uvinfo(pt); + lua_assert(idx < pt->sizeuv); + if (!p) return ""; + if (idx) while (*p++ || --idx) ; + return (const char *)p; +} + +/* Get name and value of upvalue. */ +const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp) +{ + if (tvisfunc(o)) { + GCfunc *fn = funcV(o); + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + if (idx < pt->sizeuv) { + *tvp = uvval(&gcref(fn->l.uvptr[idx])->uv); + return lj_debug_uvname(pt, idx); + } + } else { + if (idx < fn->c.nupvalues) { + *tvp = &fn->c.upvalue[idx]; + return ""; + } + } + } + return NULL; +} + +/* Deduce name of an object from slot number and PC. */ +const char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot, + const char **name) +{ + const char *lname; +restart: + lname = debug_varname(pt, proto_bcpos(pt, ip), slot); + if (lname != NULL) { *name = lname; return "local"; } + while (--ip > proto_bc(pt)) { + BCIns ins = *ip; + BCOp op = bc_op(ins); + BCReg ra = bc_a(ins); + if (bcmode_a(op) == BCMbase) { + if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins))) + return NULL; + } else if (bcmode_a(op) == BCMdst && ra == slot) { + switch (bc_op(ins)) { + case BC_MOV: + if (ra == slot) { slot = bc_d(ins); goto restart; } + break; + case BC_GGET: + *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins)))); + return "global"; + case BC_TGETS: + *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins)))); + if (ip > proto_bc(pt)) { + BCIns insp = ip[-1]; + if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 && + bc_d(insp) == bc_b(ins)) + return "method"; + } + return "field"; + case BC_UGET: + *name = lj_debug_uvname(pt, bc_d(ins)); + return "upvalue"; + default: + return NULL; + } + } + } + return NULL; +} + +/* Deduce function name from caller of a frame. */ +const char *lj_debug_funcname(lua_State *L, TValue *frame, const char **name) +{ + TValue *pframe; + GCfunc *fn; + BCPos pc; + if (frame <= tvref(L->stack)) + return NULL; + if (frame_isvarg(frame)) + frame = frame_prevd(frame); + pframe = frame_prev(frame); + fn = frame_func(pframe); + pc = debug_framepc(L, fn, frame); + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)]; + MMS mm = bcmode_mm(bc_op(*ip)); + if (mm == MM_call) { + BCReg slot = bc_a(*ip); + if (bc_op(*ip) == BC_ITERC) slot -= 3; + return lj_debug_slotname(pt, ip, slot, name); + } else if (mm != MM__MAX) { + *name = strdata(mmname_str(G(L), mm)); + return "metamethod"; + } + } + return NULL; +} + +/* -- Source code locations ----------------------------------------------- */ + +/* Generate shortened source name. */ +void lj_debug_shortname(char *out, GCstr *str) +{ + const char *src = strdata(str); + if (*src == '=') { + strncpy(out, src+1, LUA_IDSIZE); /* Remove first char. */ + out[LUA_IDSIZE-1] = '\0'; /* Ensures null termination. */ + } else if (*src == '@') { /* Output "source", or "...source". */ + size_t len = str->len-1; + src++; /* Skip the `@' */ + if (len >= LUA_IDSIZE) { + src += len-(LUA_IDSIZE-4); /* Get last part of file name. */ + *out++ = '.'; *out++ = '.'; *out++ = '.'; + } + strcpy(out, src); + } else { /* Output [string "string"]. */ + size_t len; /* Length, up to first control char. */ + for (len = 0; len < LUA_IDSIZE-12; len++) + if (((const unsigned char *)src)[len] < ' ') break; + strcpy(out, "[string \""); out += 9; + if (src[len] != '\0') { /* Must truncate? */ + if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15; + strncpy(out, src, len); out += len; + strcpy(out, "..."); out += 3; + } else { + strcpy(out, src); out += len; + } + strcpy(out, "\"]"); + } +} + +/* Add current location of a frame to error message. */ +void lj_debug_addloc(lua_State *L, const char *msg, + cTValue *frame, cTValue *nextframe) +{ + if (frame) { + GCfunc *fn = frame_func(frame); + if (isluafunc(fn)) { + BCLine line = debug_frameline(L, fn, nextframe); + if (line >= 0) { + char buf[LUA_IDSIZE]; + lj_debug_shortname(buf, proto_chunkname(funcproto(fn))); + lj_str_pushf(L, "%s:%d: %s", buf, line, msg); + return; + } + } + } + lj_str_pushf(L, "%s", msg); +} + +/* Push location string for a bytecode position to Lua stack. */ +void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc) +{ + GCstr *name = proto_chunkname(pt); + const char *s = strdata(name); + MSize i, len = name->len; + BCLine line = lj_debug_line(pt, pc); + if (*s == '@') { + s++; len--; + for (i = len; i > 0; i--) + if (s[i] == '/' || s[i] == '\\') { + s += i+1; + break; + } + lj_str_pushf(L, "%s:%d", s, line); + } else if (len > 40) { + lj_str_pushf(L, "%p:%d", pt, line); + } else if (*s == '=') { + lj_str_pushf(L, "%s:%d", s+1, line); + } else { + lj_str_pushf(L, "\"%s\":%d", s, line); + } +} + +/* -- Public debug API ---------------------------------------------------- */ + +/* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */ + +LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) +{ + const char *name = NULL; + if (ar) { + TValue *o = debug_localname(L, ar, &name, (BCReg)n); + if (name) { + copyTV(L, L->top, o); + incr_top(L); + } + } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) { + name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1); + } + return name; +} + +LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) +{ + const char *name = NULL; + TValue *o = debug_localname(L, ar, &name, (BCReg)n); + if (name) + copyTV(L, o, L->top-1); + L->top--; + return name; +} + +int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext) +{ + int opt_f = 0, opt_L = 0; + TValue *frame = NULL; + TValue *nextframe = NULL; + GCfunc *fn; + if (*what == '>') { + TValue *func = L->top - 1; + api_check(L, tvisfunc(func)); + fn = funcV(func); + L->top--; + what++; + } else { + uint32_t offset = (uint32_t)ar->i_ci & 0xffff; + uint32_t size = (uint32_t)ar->i_ci >> 16; + lua_assert(offset != 0); + frame = tvref(L->stack) + offset; + if (size) nextframe = frame + size; + lua_assert(frame <= tvref(L->maxstack) && + (!nextframe || nextframe <= tvref(L->maxstack))); + fn = frame_func(frame); + lua_assert(fn->c.gct == ~LJ_TFUNC); + } + for (; *what; what++) { + if (*what == 'S') { + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + BCLine firstline = pt->firstline; + GCstr *name = proto_chunkname(pt); + ar->source = strdata(name); + lj_debug_shortname(ar->short_src, name); + ar->linedefined = (int)firstline; + ar->lastlinedefined = (int)(firstline + pt->numline); + ar->what = firstline ? "Lua" : "main"; + } else { + ar->source = "=[C]"; + ar->short_src[0] = '['; + ar->short_src[1] = 'C'; + ar->short_src[2] = ']'; + ar->short_src[3] = '\0'; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + } else if (*what == 'l') { + ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1; + } else if (*what == 'u') { + ar->nups = fn->c.nupvalues; + if (ext) { + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + ar->nparams = pt->numparams; + ar->isvararg = !!(pt->flags & PROTO_VARARG); + } else { + ar->nparams = 0; + ar->isvararg = 1; + } + } + } else if (*what == 'n') { + ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; + ar->name = NULL; + } + } else if (*what == 'f') { + opt_f = 1; + } else if (*what == 'L') { + opt_L = 1; + } else { + return 0; /* Bad option. */ + } + } + if (opt_f) { + setfuncV(L, L->top, fn); + incr_top(L); + } + if (opt_L) { + if (isluafunc(fn)) { + GCtab *t = lj_tab_new(L, 0, 0); + GCproto *pt = funcproto(fn); + const void *lineinfo = proto_lineinfo(pt); + if (lineinfo) { + BCLine first = pt->firstline; + int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4; + MSize i, szl = pt->sizebc-1; + for (i = 0; i < szl; i++) { + BCLine line = first + + (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] : + sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] : + (BCLine)((const uint32_t *)lineinfo)[i]); + setboolV(lj_tab_setint(L, t, line), 1); + } + } + settabV(L, L->top, t); + } else { + setnilV(L->top); + } + incr_top(L); + } + return 1; /* Ok. */ +} + +LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) +{ + return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0); +} + +LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) +{ + int size; + cTValue *frame = lj_debug_frame(L, level, &size); + if (frame) { + ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack)); + return 1; + } else { + ar->i_ci = level - size; + return 0; + } +} + +/* Number of frames for the leading and trailing part of a traceback. */ +#define TRACEBACK_LEVELS1 12 +#define TRACEBACK_LEVELS2 10 + +LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, + int level) +{ + int top = (int)(L->top - L->base); + int lim = TRACEBACK_LEVELS1; + lua_Debug ar; + if (msg) lua_pushfstring(L, "%s\n", msg); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + GCfunc *fn; + if (level > lim) { + if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) { + level--; + } else { + lua_pushliteral(L, "\n\t..."); + lua_getstack(L1, -10, &ar); + level = ar.i_ci - TRACEBACK_LEVELS2; + } + lim = 2147483647; + continue; + } + lua_getinfo(L1, "Snlf", &ar); + fn = funcV(L1->top-1); L1->top--; + if (isffunc(fn) && !*ar.namewhat) + lua_pushfstring(L, "\n\t[builtin#%d]:", fn->c.ffid); + else + lua_pushfstring(L, "\n\t%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat) { + lua_pushfstring(L, " in function " LUA_QS, ar.name); + } else { + if (*ar.what == 'm') { + lua_pushliteral(L, " in main chunk"); + } else if (*ar.what == 'C') { + lua_pushfstring(L, " at %p", fn->c.f); + } else { + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + } + if ((int)(L->top - L->base) - top >= 15) + lua_concat(L, (int)(L->top - L->base) - top); + } + lua_concat(L, (int)(L->top - L->base) - top); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.h new file mode 100644 index 0000000..bec6b4f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_debug.h @@ -0,0 +1,61 @@ +/* +** Debugging and introspection. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DEBUG_H +#define _LJ_DEBUG_H + +#include "lj_obj.h" + +typedef struct lj_Debug { + /* Common fields. Must be in the same order as in lua.h. */ + int event; + const char *name; + const char *namewhat; + const char *what; + const char *source; + int currentline; + int nups; + int linedefined; + int lastlinedefined; + char short_src[LUA_IDSIZE]; + int i_ci; + /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/ + int nparams; + int isvararg; +} lj_Debug; + +LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); +LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); +LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); +LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp); +LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc, + BCReg slot, const char **name); +LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame, + const char **name); +LJ_FUNC void lj_debug_shortname(char *out, GCstr *str); +LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg, + cTValue *frame, cTValue *nextframe); +LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc); +LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, + int ext); + +/* Fixed internal variable names. */ +#define VARNAMEDEF(_) \ + _(FOR_IDX, "(for index)") \ + _(FOR_STOP, "(for limit)") \ + _(FOR_STEP, "(for step)") \ + _(FOR_GEN, "(for generator)") \ + _(FOR_STATE, "(for state)") \ + _(FOR_CTL, "(for control)") + +enum { + VARNAME_END, +#define VARNAMEENUM(name, str) VARNAME_##name, + VARNAMEDEF(VARNAMEENUM) +#undef VARNAMEENUM + VARNAME__MAX +}; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_def.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_def.h new file mode 100644 index 0000000..3c43be7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_def.h @@ -0,0 +1,349 @@ +/* +** LuaJIT common internal definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DEF_H +#define _LJ_DEF_H + +#include "lua.h" + +#if defined(_MSC_VER) +/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#ifdef _WIN64 +typedef __int64 intptr_t; +typedef unsigned __int64 uintptr_t; +#else +typedef __int32 intptr_t; +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef int intptr_t; +typedef unsigned int uintptr_t; +#else +#include +#endif + +/* Needed everywhere. */ +#include +#include + +/* Various VM limits. */ +#define LJ_MAX_MEM 0x7fffff00 /* Max. total memory allocation. */ +#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */ +#define LJ_MAX_STR LJ_MAX_MEM /* Max. string length. */ +#define LJ_MAX_UDATA LJ_MAX_MEM /* Max. userdata length. */ + +#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */ +#define LJ_MAX_HBITS 26 /* Max. hash bits. */ +#define LJ_MAX_ABITS 28 /* Max. bits of array key. */ +#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */ +#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */ + +#define LJ_MAX_LINE LJ_MAX_MEM /* Max. source code line number. */ +#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */ +#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */ +#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */ +#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */ +#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */ + +#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */ +#define LJ_STACK_EXTRA 5 /* Extra stack space (metamethods). */ + +#define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */ + +/* Minimum table/buffer sizes. */ +#define LJ_MIN_GLOBAL 6 /* Min. global table size (hbits). */ +#define LJ_MIN_REGISTRY 2 /* Min. registry size (hbits). */ +#define LJ_MIN_STRTAB 256 /* Min. string table size (pow2). */ +#define LJ_MIN_SBUF 32 /* Min. string buffer length. */ +#define LJ_MIN_VECSZ 8 /* Min. size for growable vectors. */ +#define LJ_MIN_IRSZ 32 /* Min. size for growable IR. */ +#define LJ_MIN_K64SZ 16 /* Min. size for chained K64Array. */ + +/* JIT compiler limits. */ +#define LJ_MAX_JSLOTS 250 /* Max. # of stack slots for a trace. */ +#define LJ_MAX_PHI 64 /* Max. # of PHIs for a loop. */ +#define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */ + +/* Various macros. */ +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + +#define U64x(hi, lo) (((uint64_t)0x##hi << 32) + (uint64_t)0x##lo) +#define i32ptr(p) ((int32_t)(intptr_t)(void *)(p)) +#define u32ptr(p) ((uint32_t)(intptr_t)(void *)(p)) + +#define checki8(x) ((x) == (int32_t)(int8_t)(x)) +#define checku8(x) ((x) == (int32_t)(uint8_t)(x)) +#define checki16(x) ((x) == (int32_t)(int16_t)(x)) +#define checku16(x) ((x) == (int32_t)(uint16_t)(x)) +#define checki32(x) ((x) == (int32_t)(x)) +#define checku32(x) ((x) == (uint32_t)(x)) +#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) + +/* Every half-decent C compiler transforms this into a rotate instruction. */ +#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1)))) +#define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n))) + +/* A really naive Bloom filter. But sufficient for our needs. */ +typedef uintptr_t BloomFilter; +#define BLOOM_MASK (8*sizeof(BloomFilter) - 1) +#define bloombit(x) ((uintptr_t)1 << ((x) & BLOOM_MASK)) +#define bloomset(b, x) ((b) |= bloombit((x))) +#define bloomtest(b, x) ((b) & bloombit((x))) + +#if defined(__GNUC__) + +#define LJ_NORET __attribute__((noreturn)) +#define LJ_ALIGN(n) __attribute__((aligned(n))) +#define LJ_INLINE inline +#define LJ_AINLINE inline __attribute__((always_inline)) +#define LJ_NOINLINE __attribute__((noinline)) + +#if defined(__ELF__) || defined(__MACH__) +#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__)) +#define LJ_NOAPI extern __attribute__((visibility("hidden"))) +#endif +#endif + +/* Note: it's only beneficial to use fastcall on x86 and then only for up to +** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only +** indirect calls and related tail-called C functions are marked as fastcall. +*/ +#if defined(__i386__) +#define LJ_FASTCALL __attribute__((fastcall)) +#endif + +#define LJ_LIKELY(x) __builtin_expect(!!(x), 1) +#define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0) + +#define lj_ffs(x) ((uint32_t)__builtin_ctz(x)) +/* Don't ask ... */ +#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__)) +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r; +} +#else +#define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31)) +#endif + +#if defined(__arm__) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + uint32_t r; +#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\ + __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ + __asm__("rev %0, %1" : "=r" (r) : "r" (x)); + return r; +#else +#ifdef __thumb__ + r = x ^ lj_ror(x, 16); +#else + __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x)); +#endif + return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8); +#endif +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32)); +} +#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + return (uint32_t)__builtin_bswap32((int32_t)x); +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return (uint64_t)__builtin_bswap64((int64_t)x); +} +#elif defined(__i386__) || defined(__x86_64__) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; +} + +#if defined(__i386__) +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32)); +} +#else +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; +} +#endif +#else +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24); +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return (uint64_t)lj_bswap((uint32_t)(x >> 32)) | + ((uint64_t)lj_bswap((uint32_t)x) << 32); +} +#endif + +typedef union __attribute__((packed)) Unaligned16 { + uint16_t u; + uint8_t b[2]; +} Unaligned16; + +typedef union __attribute__((packed)) Unaligned32 { + uint32_t u; + uint8_t b[4]; +} Unaligned32; + +/* Unaligned load of uint16_t. */ +static LJ_AINLINE uint16_t lj_getu16(const void *p) +{ + return ((const Unaligned16 *)p)->u; +} + +/* Unaligned load of uint32_t. */ +static LJ_AINLINE uint32_t lj_getu32(const void *p) +{ + return ((const Unaligned32 *)p)->u; +} + +#elif defined(_MSC_VER) + +#define LJ_NORET __declspec(noreturn) +#define LJ_ALIGN(n) __declspec(align(n)) +#define LJ_INLINE __inline +#define LJ_AINLINE __forceinline +#define LJ_NOINLINE __declspec(noinline) +#if defined(_M_IX86) +#define LJ_FASTCALL __fastcall +#endif + +#ifdef _M_PPC +unsigned int _CountLeadingZeros(long); +#pragma intrinsic(_CountLeadingZeros) +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + return _CountLeadingZeros(x) ^ 31; +} +#else +unsigned char _BitScanForward(uint32_t *, unsigned long); +unsigned char _BitScanReverse(uint32_t *, unsigned long); +#pragma intrinsic(_BitScanForward) +#pragma intrinsic(_BitScanReverse) + +static LJ_AINLINE uint32_t lj_ffs(uint32_t x) +{ + uint32_t r; _BitScanForward(&r, x); return r; +} + +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + uint32_t r; _BitScanReverse(&r, x); return r; +} +#endif + +unsigned long _byteswap_ulong(unsigned long); +uint64_t _byteswap_uint64(uint64_t); +#define lj_bswap(x) (_byteswap_ulong((x))) +#define lj_bswap64(x) (_byteswap_uint64((x))) + +#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED) +/* +** Replacement for unaligned loads on Xbox 360. Disabled by default since it's +** usually more costly than the occasional stall when crossing a cache-line. +*/ +static LJ_AINLINE uint16_t lj_getu16(const void *v) +{ + const uint8_t *p = (const uint8_t *)v; + return (uint16_t)((p[0]<<8) | p[1]); +} +static LJ_AINLINE uint32_t lj_getu32(const void *v) +{ + const uint8_t *p = (const uint8_t *)v; + return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]); +} +#else +/* Unaligned loads are generally ok on x86/x64. */ +#define lj_getu16(p) (*(uint16_t *)(p)) +#define lj_getu32(p) (*(uint32_t *)(p)) +#endif + +#else +#error "missing defines for your compiler" +#endif + +/* Optional defines. */ +#ifndef LJ_FASTCALL +#define LJ_FASTCALL +#endif +#ifndef LJ_NORET +#define LJ_NORET +#endif +#ifndef LJ_NOAPI +#define LJ_NOAPI extern +#endif +#ifndef LJ_LIKELY +#define LJ_LIKELY(x) (x) +#define LJ_UNLIKELY(x) (x) +#endif + +/* Attributes for internal functions. */ +#define LJ_DATA LJ_NOAPI +#define LJ_DATADEF +#define LJ_ASMF LJ_NOAPI +#define LJ_FUNCA LJ_NOAPI +#if defined(ljamalg_c) +#define LJ_FUNC static +#else +#define LJ_FUNC LJ_NOAPI +#endif +#define LJ_FUNC_NORET LJ_FUNC LJ_NORET +#define LJ_FUNCA_NORET LJ_FUNCA LJ_NORET +#define LJ_ASMF_NORET LJ_ASMF LJ_NORET + +/* Runtime assertions. */ +#ifdef lua_assert +#define check_exp(c, e) (lua_assert(c), (e)) +#define api_check(l, e) lua_assert(e) +#else +#define lua_assert(c) ((void)0) +#define check_exp(c, e) (e) +#define api_check luai_apicheck +#endif + +/* Static assertions. */ +#define LJ_ASSERT_NAME2(name, line) name ## line +#define LJ_ASSERT_NAME(line) LJ_ASSERT_NAME2(lj_assert_, line) +#ifdef __COUNTER__ +#define LJ_STATIC_ASSERT(cond) \ + extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) +#else +#define LJ_STATIC_ASSERT(cond) \ + extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.c new file mode 100644 index 0000000..58d6c3e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.c @@ -0,0 +1,494 @@ +/* +** Instruction dispatch handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_dispatch_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_func.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_debug.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ff.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif +#if LJ_HASFFI +#include "lj_ccallback.h" +#endif +#include "lj_trace.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "luajit.h" + +/* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */ +LJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC); + +/* -- Dispatch table management ------------------------------------------- */ + +#if LJ_TARGET_MIPS +#include +LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, + lua_State *co); + +#define GOTFUNC(name) (ASMFunction)name, +static const ASMFunction dispatch_got[] = { + GOTDEF(GOTFUNC) +}; +#undef GOTFUNC +#endif + +/* Initialize instruction dispatch table and hot counters. */ +void lj_dispatch_init(GG_State *GG) +{ + uint32_t i; + ASMFunction *disp = GG->dispatch; + for (i = 0; i < GG_LEN_SDISP; i++) + disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]); + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = makeasmfunc(lj_bc_ofs[i]); + /* The JIT engine is off by default. luaopen_jit() turns it on. */ + disp[BC_FORL] = disp[BC_IFORL]; + disp[BC_ITERL] = disp[BC_IITERL]; + disp[BC_LOOP] = disp[BC_ILOOP]; + disp[BC_FUNCF] = disp[BC_IFUNCF]; + disp[BC_FUNCV] = disp[BC_IFUNCV]; + GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0); + for (i = 0; i < GG_NUM_ASMFF; i++) + GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0); +#if LJ_TARGET_MIPS + memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4); +#endif +} + +#if LJ_HASJIT +/* Initialize hotcount table. */ +void lj_dispatch_init_hotcount(global_State *g) +{ + int32_t hotloop = G2J(g)->param[JIT_P_hotloop]; + HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1); + HotCount *hotcount = G2GG(g)->hotcount; + uint32_t i; + for (i = 0; i < HOTCOUNT_SIZE; i++) + hotcount[i] = start; +} +#endif + +/* Internal dispatch mode bits. */ +#define DISPMODE_JIT 0x01 /* JIT compiler on. */ +#define DISPMODE_REC 0x02 /* Recording active. */ +#define DISPMODE_INS 0x04 /* Override instruction dispatch. */ +#define DISPMODE_CALL 0x08 /* Override call dispatch. */ +#define DISPMODE_RET 0x10 /* Override return dispatch. */ + +/* Update dispatch table depending on various flags. */ +void lj_dispatch_update(global_State *g) +{ + uint8_t oldmode = g->dispatchmode; + uint8_t mode = 0; +#if LJ_HASJIT + mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0; + mode |= G2J(g)->state != LJ_TRACE_IDLE ? + (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0; +#endif + mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0; + mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0; + mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0; + if (oldmode != mode) { /* Mode changed? */ + ASMFunction *disp = G2GG(g)->dispatch; + ASMFunction f_forl, f_iterl, f_loop, f_funcf, f_funcv; + g->dispatchmode = mode; + + /* Hotcount if JIT is on, but not while recording. */ + if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) { + f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]); + f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]); + f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]); + f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]); + f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]); + } else { /* Otherwise use the non-hotcounting instructions. */ + f_forl = disp[GG_LEN_DDISP+BC_IFORL]; + f_iterl = disp[GG_LEN_DDISP+BC_IITERL]; + f_loop = disp[GG_LEN_DDISP+BC_ILOOP]; + f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]); + f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]); + } + /* Init static counting instruction dispatch first (may be copied below). */ + disp[GG_LEN_DDISP+BC_FORL] = f_forl; + disp[GG_LEN_DDISP+BC_ITERL] = f_iterl; + disp[GG_LEN_DDISP+BC_LOOP] = f_loop; + + /* Set dynamic instruction dispatch. */ + if ((oldmode ^ mode) & (DISPMODE_REC|DISPMODE_INS)) { + /* Need to update the whole table. */ + if (!(mode & (DISPMODE_REC|DISPMODE_INS))) { /* No ins dispatch? */ + /* Copy static dispatch table to dynamic dispatch table. */ + memcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction)); + /* Overwrite with dynamic return dispatch. */ + if ((mode & DISPMODE_RET)) { + disp[BC_RETM] = lj_vm_rethook; + disp[BC_RET] = lj_vm_rethook; + disp[BC_RET0] = lj_vm_rethook; + disp[BC_RET1] = lj_vm_rethook; + } + } else { + /* The recording dispatch also checks for hooks. */ + ASMFunction f = (mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook; + uint32_t i; + for (i = 0; i < GG_LEN_SDISP; i++) + disp[i] = f; + } + } else if (!(mode & (DISPMODE_REC|DISPMODE_INS))) { + /* Otherwise set dynamic counting ins. */ + disp[BC_FORL] = f_forl; + disp[BC_ITERL] = f_iterl; + disp[BC_LOOP] = f_loop; + /* Set dynamic return dispatch. */ + if ((mode & DISPMODE_RET)) { + disp[BC_RETM] = lj_vm_rethook; + disp[BC_RET] = lj_vm_rethook; + disp[BC_RET0] = lj_vm_rethook; + disp[BC_RET1] = lj_vm_rethook; + } else { + disp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM]; + disp[BC_RET] = disp[GG_LEN_DDISP+BC_RET]; + disp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0]; + disp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1]; + } + } + + /* Set dynamic call dispatch. */ + if ((oldmode ^ mode) & DISPMODE_CALL) { /* Update the whole table? */ + uint32_t i; + if ((mode & DISPMODE_CALL) == 0) { /* No call hooks? */ + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = makeasmfunc(lj_bc_ofs[i]); + } else { + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = lj_vm_callhook; + } + } + if (!(mode & DISPMODE_CALL)) { /* Overwrite dynamic counting ins. */ + disp[BC_FUNCF] = f_funcf; + disp[BC_FUNCV] = f_funcv; + } + +#if LJ_HASJIT + /* Reset hotcounts for JIT off to on transition. */ + if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT)) + lj_dispatch_init_hotcount(g); +#endif + } +} + +/* -- JIT mode setting ---------------------------------------------------- */ + +#if LJ_HASJIT +/* Set JIT mode for a single prototype. */ +static void setptmode(global_State *g, GCproto *pt, int mode) +{ + if ((mode & LUAJIT_MODE_ON)) { /* (Re-)enable JIT compilation. */ + pt->flags &= ~PROTO_NOJIT; + lj_trace_reenableproto(pt); /* Unpatch all ILOOP etc. bytecodes. */ + } else { /* Flush and/or disable JIT compilation. */ + if (!(mode & LUAJIT_MODE_FLUSH)) + pt->flags |= PROTO_NOJIT; + lj_trace_flushproto(g, pt); /* Flush all traces of prototype. */ + } +} + +/* Recursively set the JIT mode for all children of a prototype. */ +static void setptmode_all(global_State *g, GCproto *pt, int mode) +{ + ptrdiff_t i; + if (!(pt->flags & PROTO_CHILD)) return; + for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) { + GCobj *o = proto_kgc(pt, i); + if (o->gch.gct == ~LJ_TPROTO) { + setptmode(g, gco2pt(o), mode); + setptmode_all(g, gco2pt(o), mode); + } + } +} +#endif + +/* Public API function: control the JIT engine. */ +int luaJIT_setmode(lua_State *L, int idx, int mode) +{ + global_State *g = G(L); + int mm = mode & LUAJIT_MODE_MASK; + lj_trace_abort(g); /* Abort recording on any state change. */ + /* Avoid pulling the rug from under our own feet. */ + if ((g->hookmask & HOOK_GC)) + lj_err_caller(L, LJ_ERR_NOGCMM); + switch (mm) { +#if LJ_HASJIT + case LUAJIT_MODE_ENGINE: + if ((mode & LUAJIT_MODE_FLUSH)) { + lj_trace_flushall(L); + } else { + if (!(mode & LUAJIT_MODE_ON)) + G2J(g)->flags &= ~(uint32_t)JIT_F_ON; +#if LJ_TARGET_X86ORX64 + else if ((G2J(g)->flags & JIT_F_SSE2)) + G2J(g)->flags |= (uint32_t)JIT_F_ON; + else + return 0; /* Don't turn on JIT compiler without SSE2 support. */ +#else + else + G2J(g)->flags |= (uint32_t)JIT_F_ON; +#endif + lj_dispatch_update(g); + } + break; + case LUAJIT_MODE_FUNC: + case LUAJIT_MODE_ALLFUNC: + case LUAJIT_MODE_ALLSUBFUNC: { + cTValue *tv = idx == 0 ? frame_prev(L->base-1) : + idx > 0 ? L->base + (idx-1) : L->top + idx; + GCproto *pt; + if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn)) + pt = funcproto(&gcval(tv)->fn); /* Cannot use funcV() for frame slot. */ + else if (tvisproto(tv)) + pt = protoV(tv); + else + return 0; /* Failed. */ + if (mm != LUAJIT_MODE_ALLSUBFUNC) + setptmode(g, pt, mode); + if (mm != LUAJIT_MODE_FUNC) + setptmode_all(g, pt, mode); + break; + } + case LUAJIT_MODE_TRACE: + if (!(mode & LUAJIT_MODE_FLUSH)) + return 0; /* Failed. */ + lj_trace_flush(G2J(g), idx); + break; +#else + case LUAJIT_MODE_ENGINE: + case LUAJIT_MODE_FUNC: + case LUAJIT_MODE_ALLFUNC: + case LUAJIT_MODE_ALLSUBFUNC: + UNUSED(idx); + if ((mode & LUAJIT_MODE_ON)) + return 0; /* Failed. */ + break; +#endif + case LUAJIT_MODE_WRAPCFUNC: + if ((mode & LUAJIT_MODE_ON)) { + if (idx != 0) { + cTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx; + if (tvislightud(tv)) + g->wrapf = (lua_CFunction)lightudV(tv); + else + return 0; /* Failed. */ + } else { + return 0; /* Failed. */ + } + g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0); + } else { + g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0); + } + break; + default: + return 0; /* Failed. */ + } + return 1; /* OK. */ +} + +/* Enforce (dynamic) linker error for version mismatches. See luajit.c. */ +LUA_API void LUAJIT_VERSION_SYM(void) +{ +} + +/* -- Hooks --------------------------------------------------------------- */ + +/* This function can be called asynchronously (e.g. during a signal). */ +LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count) +{ + global_State *g = G(L); + mask &= HOOK_EVENTMASK; + if (func == NULL || mask == 0) { mask = 0; func = NULL; } /* Consistency. */ + g->hookf = func; + g->hookcount = g->hookcstart = (int32_t)count; + g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask); + lj_trace_abort(g); /* Abort recording on any hook change. */ + lj_dispatch_update(g); + return 1; +} + +LUA_API lua_Hook lua_gethook(lua_State *L) +{ + return G(L)->hookf; +} + +LUA_API int lua_gethookmask(lua_State *L) +{ + return G(L)->hookmask & HOOK_EVENTMASK; +} + +LUA_API int lua_gethookcount(lua_State *L) +{ + return (int)G(L)->hookcstart; +} + +/* Call a hook. */ +static void callhook(lua_State *L, int event, BCLine line) +{ + global_State *g = G(L); + lua_Hook hookf = g->hookf; + if (hookf && !hook_active(g)) { + lua_Debug ar; + lj_trace_abort(g); /* Abort recording on any hook call. */ + ar.event = event; + ar.currentline = line; + /* Top frame, nextframe = NULL. */ + ar.i_ci = (int)((L->base-1) - tvref(L->stack)); + lj_state_checkstack(L, 1+LUA_MINSTACK); + hook_enter(g); + hookf(L, &ar); + lua_assert(hook_active(g)); + hook_leave(g); + } +} + +/* -- Dispatch callbacks -------------------------------------------------- */ + +/* Calculate number of used stack slots in the current frame. */ +static BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres) +{ + BCIns ins = pc[-1]; + if (bc_op(ins) == BC_UCLO) + ins = pc[bc_j(ins)]; + switch (bc_op(ins)) { + case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1; + case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1; + case BC_TSETM: return bc_a(ins) + nres-1; + default: return pt->framesize; + } +} + +/* Instruction dispatch. Used by instr/line/return hooks or when recording. */ +void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc) +{ + ERRNO_SAVE + GCfunc *fn = curr_func(L); + GCproto *pt = funcproto(fn); + void *cf = cframe_raw(L->cframe); + const BCIns *oldpc = cframe_pc(cf); + global_State *g = G(L); + BCReg slots; + setcframe_pc(cf, pc); + slots = cur_topslot(pt, pc, cframe_multres_n(cf)); + L->top = L->base + slots; /* Fix top. */ +#if LJ_HASJIT + { + jit_State *J = G2J(g); + if (J->state != LJ_TRACE_IDLE) { +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + J->L = L; + lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */ + lua_assert(L->top - L->base == delta); + } + } +#endif + if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) { + g->hookcount = g->hookcstart; + callhook(L, LUA_HOOKCOUNT, -1); + L->top = L->base + slots; /* Fix top again. */ + } + if ((g->hookmask & LUA_MASKLINE)) { + BCPos npc = proto_bcpos(pt, pc) - 1; + BCPos opc = proto_bcpos(pt, oldpc) - 1; + BCLine line = lj_debug_line(pt, npc); + if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) { + callhook(L, LUA_HOOKLINE, line); + L->top = L->base + slots; /* Fix top again. */ + } + } + if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1]))) + callhook(L, LUA_HOOKRET, -1); + ERRNO_RESTORE +} + +/* Initialize call. Ensure stack space and return # of missing parameters. */ +static int call_init(lua_State *L, GCfunc *fn) +{ + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + int numparams = pt->numparams; + int gotparams = (int)(L->top - L->base); + int need = pt->framesize; + if ((pt->flags & PROTO_VARARG)) need += 1+gotparams; + lj_state_checkstack(L, (MSize)need); + numparams -= gotparams; + return numparams >= 0 ? numparams : 0; + } else { + lj_state_checkstack(L, LUA_MINSTACK); + return 0; + } +} + +/* Call dispatch. Used by call hooks, hot calls or when recording. */ +ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc) +{ + ERRNO_SAVE + GCfunc *fn = curr_func(L); + BCOp op; + global_State *g = G(L); +#if LJ_HASJIT + jit_State *J = G2J(g); +#endif + int missing = call_init(L, fn); +#if LJ_HASJIT + J->L = L; + if ((uintptr_t)pc & 1) { /* Marker for hot call. */ +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1); + lj_trace_hot(J, pc); + lua_assert(L->top - L->base == delta); + goto out; + } else if (J->state != LJ_TRACE_IDLE && + !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) { +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + /* Record the FUNC* bytecodes, too. */ + lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */ + lua_assert(L->top - L->base == delta); + } +#endif + if ((g->hookmask & LUA_MASKCALL)) { + int i; + for (i = 0; i < missing; i++) /* Add missing parameters. */ + setnilV(L->top++); + callhook(L, LUA_HOOKCALL, -1); + /* Preserve modifications of missing parameters by lua_setlocal(). */ + while (missing-- > 0 && tvisnil(L->top - 1)) + L->top--; + } +#if LJ_HASJIT +out: +#endif + op = bc_op(pc[-1]); /* Get FUNC* op. */ +#if LJ_HASJIT + /* Use the non-hotcounting variants if JIT is off or while recording. */ + if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) && + (op == BC_FUNCF || op == BC_FUNCV)) + op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF); +#endif + ERRNO_RESTORE + return makeasmfunc(lj_bc_ofs[op]); /* Return static dispatch target. */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.h new file mode 100644 index 0000000..5960e64 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_dispatch.h @@ -0,0 +1,131 @@ +/* +** Instruction dispatch handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DISPATCH_H +#define _LJ_DISPATCH_H + +#include "lj_obj.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif + +#if LJ_TARGET_MIPS +/* Need our own global offset table for the dreaded MIPS calling conventions. */ +#if LJ_HASJIT +#define JITGOTDEF(_) _(lj_trace_exit) _(lj_trace_hot) +#else +#define JITGOTDEF(_) +#endif +#if LJ_HASFFI +#define FFIGOTDEF(_) \ + _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave) +#else +#define FFIGOTDEF(_) +#endif +#define GOTDEF(_) \ + _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \ + _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \ + _(pow) _(fmod) _(ldexp) \ + _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_err_throw) \ + _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \ + _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \ + _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \ + _(lj_meta_for) _(lj_meta_len) _(lj_meta_tget) _(lj_meta_tset) \ + _(lj_state_growstack) _(lj_str_fromnum) _(lj_str_fromnumber) _(lj_str_new) \ + _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) _(lj_tab_new) \ + _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \ + JITGOTDEF(_) FFIGOTDEF(_) + +enum { +#define GOTENUM(name) LJ_GOT_##name, +GOTDEF(GOTENUM) +#undef GOTENUM + LJ_GOT__MAX +}; +#endif + +/* Type of hot counter. Must match the code in the assembler VM. */ +/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */ +typedef uint16_t HotCount; + +/* Number of hot counter hash table entries (must be a power of two). */ +#define HOTCOUNT_SIZE 64 +#define HOTCOUNT_PCMASK ((HOTCOUNT_SIZE-1)*sizeof(HotCount)) + +/* Hotcount decrements. */ +#define HOTCOUNT_LOOP 2 +#define HOTCOUNT_CALL 1 + +/* This solves a circular dependency problem -- bump as needed. Sigh. */ +#define GG_NUM_ASMFF 62 + +#define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF) +#define GG_LEN_SDISP BC_FUNCF +#define GG_LEN_DISP (GG_LEN_DDISP + GG_LEN_SDISP) + +/* Global state, main thread and extra fields are allocated together. */ +typedef struct GG_State { + lua_State L; /* Main thread. */ + global_State g; /* Global state. */ +#if LJ_TARGET_MIPS + ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */ +#endif +#if LJ_HASJIT + jit_State J; /* JIT state. */ + HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */ +#endif + ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */ + BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */ +} GG_State; + +#define GG_OFS(field) ((int)offsetof(GG_State, field)) +#define G2GG(gl) ((GG_State *)((char *)(gl) - GG_OFS(g))) +#define J2GG(j) ((GG_State *)((char *)(j) - GG_OFS(J))) +#define L2GG(L) (G2GG(G(L))) +#define J2G(J) (&J2GG(J)->g) +#define G2J(gl) (&G2GG(gl)->J) +#define L2J(L) (&L2GG(L)->J) +#define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g)) +#define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch)) +#define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch)) +#define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch)) +#define GG_DISP2STATIC (GG_LEN_DDISP*(int)sizeof(ASMFunction)) + +#define hotcount_get(gg, pc) \ + (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)] +#define hotcount_set(gg, pc, val) \ + (hotcount_get((gg), (pc)) = (HotCount)(val)) + +/* Dispatch table management. */ +LJ_FUNC void lj_dispatch_init(GG_State *GG); +#if LJ_HASJIT +LJ_FUNC void lj_dispatch_init_hotcount(global_State *g); +#endif +LJ_FUNC void lj_dispatch_update(global_State *g); + +/* Instruction dispatch callback for hooks or when recording. */ +LJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc); +LJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc); +LJ_FUNCA void LJ_FASTCALL lj_dispatch_return(lua_State *L, const BCIns *pc); + +#if LJ_HASFFI && !defined(_BUILDVM_H) +/* Save/restore errno and GetLastError() around hooks, exits and recording. */ +#include +#if LJ_TARGET_WINDOWS +#define WIN32_LEAN_AND_MEAN +#include +#define ERRNO_SAVE int olderr = errno; DWORD oldwerr = GetLastError(); +#define ERRNO_RESTORE errno = olderr; SetLastError(oldwerr); +#else +#define ERRNO_SAVE int olderr = errno; +#define ERRNO_RESTORE errno = olderr; +#endif +#else +#define ERRNO_SAVE +#define ERRNO_RESTORE +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_arm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_arm.h new file mode 100644 index 0000000..3bac367 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_arm.h @@ -0,0 +1,356 @@ +/* +** ARM instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Constant encoding --------------------------------------------------- */ + +static uint8_t emit_invai[16] = { + /* AND */ (ARMI_AND^ARMI_BIC) >> 21, + /* EOR */ 0, + /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21, + /* RSB */ 0, + /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21, + /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21, + /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21, + /* RSC */ 0, + /* TST */ 0, + /* TEQ */ 0, + /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21, + /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21, + /* ORR */ 0, + /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21, + /* BIC */ (ARMI_BIC^ARMI_AND) >> 21, + /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21 +}; + +/* Encode constant in K12 format for data processing instructions. */ +static uint32_t emit_isk12(ARMIns ai, int32_t n) +{ + uint32_t invai, i, m = (uint32_t)n; + /* K12: unsigned 8 bit value, rotated in steps of two bits. */ + for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2)) + if (m <= 255) return ARMI_K12|m|i; + /* Otherwise try negation/complement with the inverse instruction. */ + invai = emit_invai[((ai >> 21) & 15)]; + if (!invai) return 0; /* Failed. No inverse instruction. */ + m = ~(uint32_t)n; + if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) || + invai == (ARMI_CMP^ARMI_CMN) >> 21) m++; + for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2)) + if (m <= 255) return ARMI_K12|(invai<<21)|m|i; + return 0; /* Failed. */ +} + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm); +} + +static void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm); +} + +static void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn); +} + +static void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm) +{ + *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm); +} + +static void emit_d(ASMState *as, ARMIns ai, Reg rd) +{ + *--as->mcp = ai | ARMF_D(rd); +} + +static void emit_n(ASMState *as, ARMIns ai, Reg rn) +{ + *--as->mcp = ai | ARMF_N(rn); +} + +static void emit_m(ASMState *as, ARMIns ai, Reg rm) +{ + *--as->mcp = ai | ARMF_M(rm); +} + +static void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -255 && ofs <= 255); + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) | + ((ofs & 0xf0) << 4) | (ofs & 0x0f); +} + +static void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -4095 && ofs <= 4095); + /* Combine LDR/STR pairs to LDRD/STRD. */ + if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) && + (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn && + (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) && + as->mcp != as->mcloop) { + as->mcp++; + emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4); + return; + } + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs; +} + +#if !LJ_SOFTFP +static void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0); + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2); +} +#endif + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer spills of BASE/L. */ +#define emit_canremat(ref) ((ref) < ASMREF_L) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg d, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != d); + if (emit_canremat(ref)) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + uint32_t k = emit_isk12(ARMI_ADD, delta); + if (k) { + if (k == ARMI_K12) + emit_dm(as, ARMI_MOV, d, r); + else + emit_dn(as, ARMI_ADD^k, d, r); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Try to find a two step delta relative to another constant. */ +static int emit_kdelta2(ASMState *as, Reg d, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != d); + if (emit_canremat(ref)) { + int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i; + if (other) { + int32_t delta = i - other; + uint32_t sh, inv = 0, k2, k; + if (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; } + sh = lj_ffs(delta) & ~1; + k2 = emit_isk12(0, delta & (255 << sh)); + k = emit_isk12(0, delta & ~(255 << sh)); + if (k) { + emit_dn(as, ARMI_ADD^k2^inv, d, d); + emit_dn(as, ARMI_ADD^k^inv, d, r); + return 1; + } + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + uint32_t k = emit_isk12(ARMI_MOV, i); + lua_assert(rset_test(as->freeset, r) || r == RID_TMP); + if (k) { + /* Standard K12 constant. */ + emit_d(as, ARMI_MOV^k, r); + } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) { + /* 16 bit loword constant for ARMv6T2. */ + emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r); + } else if (emit_kdelta1(as, r, i)) { + /* One step delta relative to another constant. */ + } else if ((as->flags & JIT_F_ARMV6T2)) { + /* 32 bit hiword/loword constant for ARMv6T2. */ + emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), r); + emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r); + } else if (emit_kdelta2(as, r, i)) { + /* Two step delta relative to another constant. */ + } else { + /* Otherwise construct the constant with up to 4 instructions. */ + /* NYI: use mvn+bic, use pc-relative loads. */ + for (;;) { + uint32_t sh = lj_ffs(i) & ~1; + int32_t m = i & (255 << sh); + i &= ~(255 << sh); + if (i == 0) { + emit_d(as, ARMI_MOV ^ emit_isk12(0, m), r); + break; + } + emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), r, r); + } + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p) +{ + int32_t i = i32ptr(p); + emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)), + (i & 4095)); +} + +#if !LJ_SOFTFP +/* Load a number constant into an FPR. */ +static void emit_loadn(ASMState *as, Reg r, cTValue *tv) +{ + int32_t i; + if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) { + uint32_t hi = tv->u32.hi; + uint32_t b = ((hi >> 22) & 0x1ff); + if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) { + *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) | + ((tv->u32.hi >> 12) & 0x00080000) | + ((tv->u32.hi >> 4) & 0x00070000) | + ((tv->u32.hi >> 16) & 0x0000000f); + return; + } + } + i = i32ptr(tv); + emit_vlso(as, ARMI_VLDR_D, r, + ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020)); +} +#endif + +/* Get/set global_State fields. */ +#define emit_getgl(as, r, field) \ + emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field) +#define emit_setgl(as, r, field) \ + emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field) + +/* Trace number is determined from pc of exit instruction. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_branch(ASMState *as, ARMIns ai, MCode *target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = (target - p) - 1; + lua_assert(((delta + 0x00800000) >> 24) == 0); + *--p = ai | ((uint32_t)delta & 0x00ffffffu); + as->mcp = p; +} + +#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target)) + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = ((char *)target - (char *)p) - 8; + if ((((delta>>2) + 0x00800000) >> 24) == 0) { + if ((delta & 1)) + *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 27); + else + *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu); + } else { /* Target out of range: need indirect call. But don't use R0-R3. */ + Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1)); + *p = ARMI_BLXr | ARMF_M(r); + } +} + +/* -- Emit generic operations --------------------------------------------- */ + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (dst >= RID_MAX_GPR) { + emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S, + (dst & 15), (src & 15)); + return; + } +#endif + if (as->mcp != as->mcloop) { /* Swap early registers for loads/stores. */ + MCode ins = *as->mcp, swp = (src^dst); + if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) { + if (!((ins ^ (dst << 16)) & 0x000f0000)) + *as->mcp = ins ^ (swp << 16); /* Swap N in load/store. */ + if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000)) + *as->mcp = ins ^ (swp << 12); /* Swap D in store. */ + } + } + emit_dm(as, ARMI_MOV, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (r >= RID_MAX_GPR) + emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, RID_SP, ofs); + else +#endif + emit_lso(as, ARMI_LDR, r, RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (r >= RID_MAX_GPR) + emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, RID_SP, ofs); + else +#endif + emit_lso(as, ARMI_STR, r, RID_SP, ofs); +} + +/* Emit an arithmetic/logic operation with a constant operand. */ +static void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src, + int32_t i, RegSet allow) +{ + uint32_t k = emit_isk12(ai, i); + if (k) + emit_dn(as, ai^k, dest, src); + else + emit_dnm(as, ai, dest, src, ra_allock(as, i, allow)); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) + emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r)); +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_mips.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_mips.h new file mode 100644 index 0000000..dc9197a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_mips.h @@ -0,0 +1,211 @@ +/* +** MIPS instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt) +{ + *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt); +} + +static void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a) +{ + *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a); +} + +#define emit_ds(as, mi, rd, rs) emit_dst(as, (mi), (rd), (rs), 0) +#define emit_tg(as, mi, rt, rg) emit_dst(as, (mi), (rg)&31, 0, (rt)) + +static void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i) +{ + *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff); +} + +#define emit_ti(as, mi, rt, i) emit_tsi(as, (mi), (rt), 0, (i)) +#define emit_hsi(as, mi, rh, rs, i) emit_tsi(as, (mi), (rh) & 31, (rs), (i)) + +static void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh) +{ + *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31); +} + +#define emit_fg(as, mi, rf, rg) emit_fgh(as, (mi), (rf), (rg), 0) + +static void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift) +{ + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, src, shift); + } else { + emit_dst(as, MIPSI_OR, dest, dest, tmp); + emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31); + emit_dta(as, MIPSI_SRL, tmp, src, shift); + } +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg t, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != t); + if (ref < ASMREF_L) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + if (checki16(delta)) { + emit_tsi(as, MIPSI_ADDIU, t, r, delta); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + if (checki16(i)) { + emit_ti(as, MIPSI_LI, r, i); + } else { + if ((i & 0xffff)) { + int32_t jgl = i32ptr(J2G(as->J)); + if ((uint32_t)(i-jgl) < 65536) { + emit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768); + return; + } else if (emit_kdelta1(as, r, i)) { + return; + } else if ((i >> 16) == 0) { + emit_tsi(as, MIPSI_ORI, r, RID_ZERO, i); + return; + } + emit_tsi(as, MIPSI_ORI, r, r, i); + } + emit_ti(as, MIPSI_LUI, r, (i >> 16)); + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); +static void ra_allockreg(ASMState *as, int32_t k, Reg r); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow) +{ + int32_t jgl = i32ptr(J2G(as->J)); + int32_t i = i32ptr(p); + Reg base; + if ((uint32_t)(i-jgl) < 65536) { + i = i-jgl-32768; + base = RID_JGL; + } else { + base = ra_allock(as, i-(int16_t)i, allow); + } + emit_tsi(as, mi, r, base, i); +} + +#define emit_loadn(as, r, tv) \ + emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)(tv), RSET_GPR) + +/* Get/set global_State fields. */ +static void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs) +{ + emit_tsi(as, mi, r, RID_JGL, ofs-32768); +} + +#define emit_getgl(as, r, field) \ + emit_lsglptr(as, MIPSI_LW, (r), (int32_t)offsetof(global_State, field)) +#define emit_setgl(as, r, field) \ + emit_lsglptr(as, MIPSI_SW, (r), (int32_t)offsetof(global_State, field)) + +/* Trace number is determined from per-trace exit stubs. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(((delta + 0x8000) >> 16) == 0); + *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu); + as->mcp = p; +} + +static void emit_jmp(ASMState *as, MCode *target) +{ + *--as->mcp = MIPSI_NOP; + emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target)); +} + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = as->mcp; + *--p = MIPSI_NOP; + if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0) + *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu); + else /* Target out of range: need indirect call. */ + *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR); + as->mcp = p; + ra_allockreg(as, i32ptr(target), RID_CFUNCADDR); +} + +/* -- Emit generic operations --------------------------------------------- */ + +#define emit_move(as, dst, src) \ + emit_ds(as, MIPSI_MOVE, (dst), (src)) + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + if (dst < RID_MAX_GPR) + emit_move(as, dst, src); + else + emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tsi(as, MIPSI_LW, r, RID_SP, ofs); + else + emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1, + (r & 31), RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tsi(as, MIPSI_SW, r, RID_SP, ofs); + else + emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1, + (r&31), RID_SP, ofs); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + lua_assert(checki16(ofs)); + emit_tsi(as, MIPSI_ADDIU, r, r, ofs); + } +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_ppc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_ppc.h new file mode 100644 index 0000000..3a2ae38 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_ppc.h @@ -0,0 +1,238 @@ +/* +** PPC instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb) +{ + *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb); +} + +#define emit_asb(as, pi, ra, rs, rb) emit_tab(as, (pi), (rs), (ra), (rb)) +#define emit_as(as, pi, ra, rs) emit_tab(as, (pi), (rs), (ra), 0) +#define emit_ab(as, pi, ra, rb) emit_tab(as, (pi), 0, (ra), (rb)) + +static void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i) +{ + *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff); +} + +#define emit_ti(as, pi, rt, i) emit_tai(as, (pi), (rt), 0, (i)) +#define emit_ai(as, pi, ra, i) emit_tai(as, (pi), 0, (ra), (i)) +#define emit_asi(as, pi, ra, rs, i) emit_tai(as, (pi), (rs), (ra), (i)) + +#define emit_fab(as, pi, rf, ra, rb) \ + emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31) +#define emit_fb(as, pi, rf, rb) emit_tab(as, (pi), (rf)&31, 0, (rb)&31) +#define emit_fac(as, pi, rf, ra, rc) \ + emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0) +#define emit_facb(as, pi, rf, ra, rc, rb) \ + emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31) +#define emit_fai(as, pi, rf, ra, i) emit_tai(as, (pi), (rf)&31, (ra), (i)) + +static void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs, + int32_t n, int32_t b, int32_t e) +{ + *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) | + PPCF_MB(b) | PPCF_ME(e); +} + +static void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n) +{ + lua_assert(n >= 0 && n < 32); + emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n); +} + +static void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n) +{ + lua_assert(n >= 0 && n < 32); + emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31); +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg t, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != t); + if (ref < ASMREF_L) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + if (checki16(delta)) { + emit_tai(as, PPCI_ADDI, t, r, delta); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + if (checki16(i)) { + emit_ti(as, PPCI_LI, r, i); + } else { + if ((i & 0xffff)) { + int32_t jgl = i32ptr(J2G(as->J)); + if ((uint32_t)(i-jgl) < 65536) { + emit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768); + return; + } else if (emit_kdelta1(as, r, i)) { + return; + } + emit_asi(as, PPCI_ORI, r, r, i); + } + emit_ti(as, PPCI_LIS, r, (i >> 16)); + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow) +{ + int32_t jgl = i32ptr(J2G(as->J)); + int32_t i = i32ptr(p); + Reg base; + if ((uint32_t)(i-jgl) < 65536) { + i = i-jgl-32768; + base = RID_JGL; + } else { + base = ra_allock(as, i-(int16_t)i, allow); + } + emit_tai(as, pi, r, base, i); +} + +#define emit_loadn(as, r, tv) \ + emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)(tv), RSET_GPR) + +/* Get/set global_State fields. */ +static void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs) +{ + emit_tai(as, pi, r, RID_JGL, ofs-32768); +} + +#define emit_getgl(as, r, field) \ + emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field)) +#define emit_setgl(as, r, field) \ + emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field)) + +/* Trace number is determined from per-trace exit stubs. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + lua_assert(((delta + 0x8000) >> 16) == 0); + pi ^= (delta & 0x8000) * (PPCF_Y/0x8000); + *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu); +} + +static void emit_jmp(ASMState *as, MCode *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + *p = PPCI_B | (delta & 0x03fffffcu); +} + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + if ((((delta>>2) + 0x00800000) >> 24) == 0) { + *p = PPCI_BL | (delta & 0x03fffffcu); + } else { /* Target out of range: need indirect call. Don't use arg reg. */ + RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1); + Reg r = ra_allock(as, i32ptr(target), allow); + *p = PPCI_BCTRL; + p[-1] = PPCI_MTCTR | PPCF_T(r); + as->mcp = p-1; + } +} + +/* -- Emit generic operations --------------------------------------------- */ + +#define emit_mr(as, dst, src) \ + emit_asb(as, PPCI_MR, (dst), (src), (src)) + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + UNUSED(ir); + if (dst < RID_MAX_GPR) + emit_mr(as, dst, src); + else + emit_fb(as, PPCI_FMR, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tai(as, PPCI_LWZ, r, RID_SP, ofs); + else + emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tai(as, PPCI_STW, r, RID_SP, ofs); + else + emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, RID_SP, ofs); +} + +/* Emit a compare (for equality) with a constant operand. */ +static void emit_cmpi(ASMState *as, Reg r, int32_t k) +{ + if (checki16(k)) { + emit_ai(as, PPCI_CMPWI, r, k); + } else if (checku16(k)) { + emit_ai(as, PPCI_CMPLWI, r, k); + } else { + emit_ai(as, PPCI_CMPLWI, RID_TMP, k); + emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16)); + } +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + emit_tai(as, PPCI_ADDI, r, r, ofs); + if (!checki16(ofs)) + emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16); + } +} + +static void emit_spsub(ASMState *as, int32_t ofs) +{ + if (ofs) { + emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs); + emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP, + CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0)); + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_x86.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_x86.h new file mode 100644 index 0000000..8cfb654 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_emit_x86.h @@ -0,0 +1,466 @@ +/* +** x86/x64 instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +#define MODRM(mode, r1, r2) ((MCode)((mode)+(((r1)&7)<<3)+((r2)&7))) + +#if LJ_64 +#define REXRB(p, rr, rb) \ + { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \ + if (rex != 0x40) *--(p) = rex; } +#define FORCE_REX 0x200 +#define REX_64 (FORCE_REX|0x080000) +#else +#define REXRB(p, rr, rb) ((void)0) +#define FORCE_REX 0 +#define REX_64 0 +#endif + +#define emit_i8(as, i) (*--as->mcp = (MCode)(i)) +#define emit_i32(as, i) (*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4) +#define emit_u32(as, u) (*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4) + +#define emit_x87op(as, xo) \ + (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2) + +/* op */ +static LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx, + MCode *p, int delta) +{ + int n = (int8_t)xo; +#if defined(__GNUC__) + if (__builtin_constant_p(xo) && n == -2) + p[delta-2] = (MCode)(xo >> 24); + else if (__builtin_constant_p(xo) && n == -3) + *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16); + else +#endif + *(uint32_t *)(p+delta-5) = (uint32_t)xo; + p += n + delta; +#if LJ_64 + { + uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1); + if (rex != 0x40) { + rex |= (rr >> 16); + if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); } + else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; } + *--p = (MCode)rex; + } + } +#else + UNUSED(rr); UNUSED(rb); UNUSED(rx); +#endif + return p; +} + +/* op + modrm */ +#define emit_opm(xo, mode, rr, rb, p, delta) \ + (p[(delta)-1] = MODRM((mode), (rr), (rb)), \ + emit_op((xo), (rr), (rb), 0, (p), (delta))) + +/* op + modrm + sib */ +#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \ + (p[-1] = MODRM((scale), (rx), (rb)), \ + p[-2] = MODRM((mode), (rr), RID_ESP), \ + emit_op((xo), (rr), (rb), (rx), (p), -1)) + +/* op r1, r2 */ +static void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2) +{ + MCode *p = as->mcp; + as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0); +} + +#if LJ_64 && defined(LUA_USE_ASSERT) +/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */ +static int32_t ptr2addr(const void *p) +{ + lua_assert((uintptr_t)p < (uintptr_t)0x80000000); + return i32ptr(p); +} +#else +#define ptr2addr(p) (i32ptr((p))) +#endif + +/* op r, [addr] */ +static void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = ptr2addr(addr); +#if LJ_64 + p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5); +#else + as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4); +#endif +} + +/* op r, [base+ofs] */ +static void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs) +{ + MCode *p = as->mcp; + x86Mode mode; + if (ra_hasreg(rb)) { + if (ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(ofs)) { + *--p = (MCode)ofs; + mode = XM_OFS8; + } else { + p -= 4; + *(int32_t *)p = ofs; + mode = XM_OFS32; + } + if ((rb&7) == RID_ESP) + *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } else { + *(int32_t *)(p-4) = ofs; +#if LJ_64 + p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + p -= 5; + rb = RID_ESP; +#else + p -= 4; + rb = RID_EBP; +#endif + mode = XM_OFS0; + } + as->mcp = emit_opm(xo, mode, rr, rb, p, 0); +} + +/* op r, [base+idx*scale+ofs] */ +static void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx, + x86Mode scale, int32_t ofs) +{ + MCode *p = as->mcp; + x86Mode mode; + if (ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(ofs)) { + mode = XM_OFS8; + *--p = (MCode)ofs; + } else { + mode = XM_OFS32; + p -= 4; + *(int32_t *)p = ofs; + } + as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p); +} + +/* op r, i */ +static void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i) +{ + MCode *p = as->mcp; + x86Op xo; + if (checki8(i)) { + *--p = (MCode)i; + xo = XG_TOXOi8(xg); + } else { + p -= 4; + *(int32_t *)p = i; + xo = XG_TOXOi(xg); + } + as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0); +} + +/* op [base+ofs], i */ +static void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs, + int32_t i) +{ + x86Op xo; + if (checki8(i)) { + emit_i8(as, i); + xo = XG_TOXOi8(xg); + } else { + emit_i32(as, i); + xo = XG_TOXOi(xg); + } + emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs); +} + +#define emit_shifti(as, xg, r, i) \ + (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r))) + +/* op r, rm/mrm */ +static void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb) +{ + MCode *p = as->mcp; + x86Mode mode = XM_REG; + if (rb == RID_MRM) { + rb = as->mrm.base; + if (rb == RID_NONE) { + rb = RID_EBP; + mode = XM_OFS0; + p -= 4; + *(int32_t *)p = as->mrm.ofs; + if (as->mrm.idx != RID_NONE) + goto mrmidx; +#if LJ_64 + *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + rb = RID_ESP; +#endif + } else { + if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(as->mrm.ofs)) { + *--p = (MCode)as->mrm.ofs; + mode = XM_OFS8; + } else { + p -= 4; + *(int32_t *)p = as->mrm.ofs; + mode = XM_OFS32; + } + if (as->mrm.idx != RID_NONE) { + mrmidx: + as->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p); + return; + } + if ((rb&7) == RID_ESP) + *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } + } + as->mcp = emit_opm(xo, mode, rr, rb, p, 0); +} + +/* op rm/mrm, i */ +static void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i) +{ + x86Op xo; + if (checki8(i)) { + emit_i8(as, i); + xo = XG_TOXOi8(xg); + } else { + emit_i32(as, i); + xo = XG_TOXOi(xg); + } + emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64)); +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Instruction selection for XMM moves. */ +#define XMM_MOVRR(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVSD : XO_MOVAPS) +#define XMM_MOVRM(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVLPD : XO_MOVSD) + +/* mov [base+ofs], i */ +static void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i) +{ + emit_i32(as, i); + emit_rmro(as, XO_MOVmi, 0, base, ofs); +} + +/* mov [base+ofs], r */ +#define emit_movtomro(as, r, base, ofs) \ + emit_rmro(as, XO_MOVto, (r), (base), (ofs)) + +/* Get/set global_State fields. */ +#define emit_opgl(as, xo, r, field) \ + emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field) +#define emit_getgl(as, r, field) emit_opgl(as, XO_MOV, (r), field) +#define emit_setgl(as, r, field) emit_opgl(as, XO_MOVto, (r), field) + +#define emit_setvmstate(as, i) \ + (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate)) + +/* mov r, i / xor r, r */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP. */ + if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP || + (as->curins+1 < as->T->nins && + IR(as->curins+1)->o == IR_HIOP)))) { + emit_rr(as, XO_ARITH(XOg_XOR), r, r); + } else { + MCode *p = as->mcp; + *(int32_t *)(p-4) = i; + p[-5] = (MCode)(XI_MOVri+(r&7)); + p -= 5; + REXRB(p, 0, r); + as->mcp = p; + } +} + +/* mov r, addr */ +#define emit_loada(as, r, addr) \ + emit_loadi(as, (r), ptr2addr((addr))) + +#if LJ_64 +/* mov r, imm64 or shorter 32 bit extended load. */ +static void emit_loadu64(ASMState *as, Reg r, uint64_t u64) +{ + if (checku32(u64)) { /* 32 bit load clears upper 32 bits. */ + emit_loadi(as, r, (int32_t)u64); + } else if (checki32((int64_t)u64)) { /* Sign-extended 32 bit load. */ + MCode *p = as->mcp; + *(int32_t *)(p-4) = (int32_t)u64; + as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4); + } else { /* Full-size 64 bit load. */ + MCode *p = as->mcp; + *(uint64_t *)(p-8) = u64; + p[-9] = (MCode)(XI_MOVri+(r&7)); + p[-10] = 0x48 + ((r>>3)&1); + p -= 10; + as->mcp = p; + } +} +#endif + +/* movsd r, [&tv->n] / xorps r, r */ +static void emit_loadn(ASMState *as, Reg r, cTValue *tv) +{ + if (tvispzero(tv)) /* Use xor only for +0. */ + emit_rr(as, XO_XORPS, r, r); + else + emit_rma(as, XMM_MOVRM(as), r, &tv->n); +} + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for short jumps. */ +typedef MCode *MCLabel; + +#if LJ_32 && LJ_HASFFI +/* jmp short target */ +static void emit_sjmp(ASMState *as, MCLabel target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(delta == (int8_t)delta); + p[-1] = (MCode)(int8_t)delta; + p[-2] = XI_JMPs; + as->mcp = p - 2; +} +#endif + +/* jcc short target */ +static void emit_sjcc(ASMState *as, int cc, MCLabel target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(delta == (int8_t)delta); + p[-1] = (MCode)(int8_t)delta; + p[-2] = (MCode)(XI_JCCs+(cc&15)); + as->mcp = p - 2; +} + +/* jcc short (pending target) */ +static MCLabel emit_sjcc_label(ASMState *as, int cc) +{ + MCode *p = as->mcp; + p[-1] = 0; + p[-2] = (MCode)(XI_JCCs+(cc&15)); + as->mcp = p - 2; + return p; +} + +/* Fixup jcc short target. */ +static void emit_sfixup(ASMState *as, MCLabel source) +{ + source[-1] = (MCode)(as->mcp-source); +} + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +/* Compute relative 32 bit offset for jump and call instructions. */ +static LJ_AINLINE int32_t jmprel(MCode *p, MCode *target) +{ + ptrdiff_t delta = target - p; + lua_assert(delta == (int32_t)delta); + return (int32_t)delta; +} + +/* jcc target */ +static void emit_jcc(ASMState *as, int cc, MCode *target) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = (MCode)(XI_JCCn+(cc&15)); + p[-6] = 0x0f; + as->mcp = p - 6; +} + +/* jmp target */ +static void emit_jmp(ASMState *as, MCode *target) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_JMP; + as->mcp = p - 5; +} + +/* call target */ +static void emit_call_(ASMState *as, MCode *target) +{ + MCode *p = as->mcp; +#if LJ_64 + if (target-p != (int32_t)(target-p)) { + /* Assumes RID_RET is never an argument to calls and always clobbered. */ + emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET); + emit_loadu64(as, RID_RET, (uint64_t)target); + return; + } +#endif + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_CALL; + as->mcp = p - 5; +} + +#define emit_call(as, f) emit_call_(as, (MCode *)(void *)(f)) + +/* -- Emit generic operations --------------------------------------------- */ + +/* Use 64 bit operations to handle 64 bit IR types. */ +#if LJ_64 +#define REX_64IR(ir, r) ((r) + (irt_is64((ir)->t) ? REX_64 : 0)) +#else +#define REX_64IR(ir, r) (r) +#endif + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + UNUSED(ir); + if (dst < RID_MAX_GPR) + emit_rr(as, XO_MOV, REX_64IR(ir, dst), src); + else + emit_rr(as, XMM_MOVRR(as), dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_rmro(as, XO_MOV, REX_64IR(ir, r), RID_ESP, ofs); + else + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, r, RID_ESP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_rmro(as, XO_MOVto, REX_64IR(ir, r), RID_ESP, ofs); + else + emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, RID_ESP, ofs); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + if ((as->flags & JIT_F_LEA_AGU)) + emit_rmro(as, XO_LEA, r, r, ofs); + else + emit_gri(as, XG_ARITHi(XOg_ADD), r, ofs); + } +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_ESP|REX_64, -(ofs)) + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.c new file mode 100644 index 0000000..db18267 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.c @@ -0,0 +1,785 @@ +/* +** Error handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_err_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_func.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_ff.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* +** LuaJIT can either use internal or external frame unwinding: +** +** - Internal frame unwinding (INT) is free-standing and doesn't require +** any OS or library support. +** +** - External frame unwinding (EXT) uses the system-provided unwind handler. +** +** Pros and Cons: +** +** - EXT requires unwind tables for *all* functions on the C stack between +** the pcall/catch and the error/throw. This is the default on x64, +** but needs to be manually enabled on x86/PPC for non-C++ code. +** +** - INT is faster when actually throwing errors (but this happens rarely). +** Setting up error handlers is zero-cost in any case. +** +** - EXT provides full interoperability with C++ exceptions. You can throw +** Lua errors or C++ exceptions through a mix of Lua frames and C++ frames. +** C++ destructors are called as needed. C++ exceptions caught by pcall +** are converted to the string "C++ exception". Lua errors can be caught +** with catch (...) in C++. +** +** - INT has only limited support for automatically catching C++ exceptions +** on POSIX systems using DWARF2 stack unwinding. Other systems may use +** the wrapper function feature. Lua errors thrown through C++ frames +** cannot be caught by C++ code and C++ destructors are not run. +** +** EXT is the default on x64 systems, INT is the default on all other systems. +** +** EXT can be manually enabled on POSIX systems using GCC and DWARF2 stack +** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled +** with -funwind-tables (or -fexceptions). This includes LuaJIT itself (set +** TARGET_CFLAGS), all of your C/Lua binding code, all loadable C modules +** and all C libraries that have callbacks which may be used to call back +** into Lua. C++ code must *not* be compiled with -fno-exceptions. +** +** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH. +** EXT is mandatory on WIN64 since the calling convention has an abundance +** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15). +** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. +*/ + +#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) +#define LJ_UNWIND_EXT 1 +#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS +#define LJ_UNWIND_EXT 1 +#endif + +/* -- Error messages ------------------------------------------------------ */ + +/* Error message strings. */ +LJ_DATADEF const char *lj_err_allmsg = +#define ERRDEF(name, msg) msg "\0" +#include "lj_errmsg.h" +; + +/* -- Internal frame unwinding -------------------------------------------- */ + +/* Unwind Lua stack and move error message to new top. */ +LJ_NOINLINE static void unwindstack(lua_State *L, TValue *top) +{ + lj_func_closeuv(L, top); + if (top < L->top-1) { + copyTV(L, top, L->top-1); + L->top = top+1; + } + lj_state_relimitstack(L); +} + +/* Unwind until stop frame. Optionally cleanup frames. */ +static void *err_unwind(lua_State *L, void *stopcf, int errcode) +{ + TValue *frame = L->base-1; + void *cf = L->cframe; + while (cf) { + int32_t nres = cframe_nres(cframe_raw(cf)); + if (nres < 0) { /* C frame without Lua frame? */ + TValue *top = restorestack(L, -nres); + if (frame < top) { /* Frame reached? */ + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame+1; + unwindstack(L, top); + } + return cf; + } + } + if (frame <= tvref(L->stack)) + break; + switch (frame_typep(frame)) { + case FRAME_LUA: /* Lua frame. */ + case FRAME_LUAP: + frame = frame_prevl(frame); + break; + case FRAME_C: /* C frame. */ +#if LJ_HASFFI + unwind_c: +#endif +#if LJ_UNWIND_EXT + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame_prevd(frame) + 1; + unwindstack(L, frame); + } else if (cf != stopcf) { + cf = cframe_prev(cf); + frame = frame_prevd(frame); + break; + } + return NULL; /* Continue unwinding. */ +#else + UNUSED(stopcf); + cf = cframe_prev(cf); + frame = frame_prevd(frame); + break; +#endif + case FRAME_CP: /* Protected C frame. */ + if (cframe_canyield(cf)) { /* Resume? */ + if (errcode) { + hook_leave(G(L)); /* Assumes nobody uses coroutines inside hooks. */ + L->cframe = NULL; + L->status = (uint8_t)errcode; + } + return cf; + } + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame_prevd(frame) + 1; + unwindstack(L, frame); + } + return cf; + case FRAME_CONT: /* Continuation frame. */ +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) + goto unwind_c; +#endif + case FRAME_VARG: /* Vararg frame. */ + frame = frame_prevd(frame); + break; + case FRAME_PCALL: /* FF pcall() frame. */ + case FRAME_PCALLH: /* FF pcall() frame inside hook. */ + if (errcode) { + if (errcode == LUA_YIELD) { + frame = frame_prevd(frame); + break; + } + if (frame_typep(frame) == FRAME_PCALL) + hook_leave(G(L)); + L->cframe = cf; + L->base = frame_prevd(frame) + 1; + unwindstack(L, L->base); + } + return (void *)((intptr_t)cf | CFRAME_UNWIND_FF); + } + } + /* No C frame. */ + if (errcode) { + L->cframe = NULL; + L->base = tvref(L->stack)+1; + unwindstack(L, L->base); + if (G(L)->panic) + G(L)->panic(L); + exit(EXIT_FAILURE); + } + return L; /* Anything non-NULL will do. */ +} + +/* -- External frame unwinding -------------------------------------------- */ + +#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_TARGET_WINDOWS + +/* +** We have to use our own definitions instead of the mandatory (!) unwind.h, +** since various OS, distros and compilers mess up the header installation. +*/ + +typedef struct _Unwind_Exception +{ + uint64_t exclass; + void (*excleanup)(int, struct _Unwind_Exception *); + uintptr_t p1, p2; +} __attribute__((__aligned__)) _Unwind_Exception; + +typedef struct _Unwind_Context _Unwind_Context; + +#define _URC_OK 0 +#define _URC_FATAL_PHASE1_ERROR 3 +#define _URC_HANDLER_FOUND 6 +#define _URC_INSTALL_CONTEXT 7 +#define _URC_CONTINUE_UNWIND 8 +#define _URC_FAILURE 9 + +#if !LJ_TARGET_ARM + +extern uintptr_t _Unwind_GetCFA(_Unwind_Context *); +extern void _Unwind_SetGR(_Unwind_Context *, int, uintptr_t); +extern void _Unwind_SetIP(_Unwind_Context *, uintptr_t); +extern void _Unwind_DeleteException(_Unwind_Exception *); +extern int _Unwind_RaiseException(_Unwind_Exception *); + +#define _UA_SEARCH_PHASE 1 +#define _UA_CLEANUP_PHASE 2 +#define _UA_HANDLER_FRAME 4 +#define _UA_FORCE_UNWIND 8 + +#define LJ_UEXCLASS 0x4c55414a49543200ULL /* LUAJIT2\0 */ +#define LJ_UEXCLASS_MAKE(c) (LJ_UEXCLASS | (uint64_t)(c)) +#define LJ_UEXCLASS_CHECK(cl) (((cl) ^ LJ_UEXCLASS) <= 0xff) +#define LJ_UEXCLASS_ERRCODE(cl) ((int)((cl) & 0xff)) + +/* DWARF2 personality handler referenced from interpreter .eh_frame. */ +LJ_FUNCA int lj_err_unwind_dwarf(int version, int actions, + uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx) +{ + void *cf; + lua_State *L; + if (version != 1) + return _URC_FATAL_PHASE1_ERROR; + UNUSED(uexclass); + cf = (void *)_Unwind_GetCFA(ctx); + L = cframe_L(cf); + if ((actions & _UA_SEARCH_PHASE)) { +#if LJ_UNWIND_EXT + if (err_unwind(L, cf, 0) == NULL) + return _URC_CONTINUE_UNWIND; +#endif + if (!LJ_UEXCLASS_CHECK(uexclass)) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + } + return _URC_HANDLER_FOUND; + } + if ((actions & _UA_CLEANUP_PHASE)) { + int errcode; + if (LJ_UEXCLASS_CHECK(uexclass)) { + errcode = LJ_UEXCLASS_ERRCODE(uexclass); + } else { + if ((actions & _UA_HANDLER_FRAME)) + _Unwind_DeleteException(uex); + errcode = LUA_ERRRUN; + } +#if LJ_UNWIND_EXT + cf = err_unwind(L, cf, errcode); + if ((actions & _UA_FORCE_UNWIND)) { + return _URC_CONTINUE_UNWIND; + } else if (cf) { + _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode); + _Unwind_SetIP(ctx, (uintptr_t)(cframe_unwind_ff(cf) ? + lj_vm_unwind_ff_eh : + lj_vm_unwind_c_eh)); + return _URC_INSTALL_CONTEXT; + } +#if LJ_TARGET_X86ORX64 + else if ((actions & _UA_HANDLER_FRAME)) { + /* Workaround for ancient libgcc bug. Still present in RHEL 5.5. :-/ + ** Real fix: http://gcc.gnu.org/viewcvs/trunk/gcc/unwind-dw2.c?r1=121165&r2=124837&pathrev=153877&diff_format=h + */ + _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode); + _Unwind_SetIP(ctx, (uintptr_t)lj_vm_unwind_rethrow); + return _URC_INSTALL_CONTEXT; + } +#endif +#else + /* This is not the proper way to escape from the unwinder. We get away with + ** it on non-x64 because the interpreter restores all callee-saved regs. + */ + lj_err_throw(L, errcode); +#endif + } + return _URC_CONTINUE_UNWIND; +} + +#if LJ_UNWIND_EXT +#if LJ_TARGET_OSX || defined(__OpenBSD__) +/* Sorry, no thread safety for OSX. Complain to Apple, not me. */ +static _Unwind_Exception static_uex; +#else +static __thread _Unwind_Exception static_uex; +#endif + +/* Raise DWARF2 exception. */ +static void err_raise_ext(int errcode) +{ + static_uex.exclass = LJ_UEXCLASS_MAKE(errcode); + static_uex.excleanup = NULL; + _Unwind_RaiseException(&static_uex); +} +#endif + +#else + +extern void _Unwind_DeleteException(void *); +extern int __gnu_unwind_frame (void *, _Unwind_Context *); +extern int _Unwind_VRS_Set(_Unwind_Context *, int, uint32_t, int, void *); +extern int _Unwind_VRS_Get(_Unwind_Context *, int, uint32_t, int, void *); + +static inline uint32_t _Unwind_GetGR(_Unwind_Context *ctx, int r) +{ + uint32_t v; + _Unwind_VRS_Get(ctx, 0, r, 0, &v); + return v; +} + +static inline void _Unwind_SetGR(_Unwind_Context *ctx, int r, uint32_t v) +{ + _Unwind_VRS_Set(ctx, 0, r, 0, &v); +} + +#define _US_VIRTUAL_UNWIND_FRAME 0 +#define _US_UNWIND_FRAME_STARTING 1 +#define _US_ACTION_MASK 3 +#define _US_FORCE_UNWIND 8 + +/* ARM unwinder personality handler referenced from interpreter .ARM.extab. */ +LJ_FUNCA int lj_err_unwind_arm(int state, void *ucb, _Unwind_Context *ctx) +{ + void *cf = (void *)_Unwind_GetGR(ctx, 13); + lua_State *L = cframe_L(cf); + if ((state & _US_ACTION_MASK) == _US_VIRTUAL_UNWIND_FRAME) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + return _URC_HANDLER_FOUND; + } + if ((state&(_US_ACTION_MASK|_US_FORCE_UNWIND)) == _US_UNWIND_FRAME_STARTING) { + _Unwind_DeleteException(ucb); + _Unwind_SetGR(ctx, 15, (uint32_t)(void *)lj_err_throw); + _Unwind_SetGR(ctx, 0, (uint32_t)L); + _Unwind_SetGR(ctx, 1, (uint32_t)LUA_ERRRUN); + return _URC_INSTALL_CONTEXT; + } + if (__gnu_unwind_frame(ucb, ctx) != _URC_OK) + return _URC_FAILURE; + return _URC_CONTINUE_UNWIND; +} + +#endif + +#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS + +/* +** Someone in Redmond owes me several days of my life. A lot of this is +** undocumented or just plain wrong on MSDN. Some of it can be gathered +** from 3rd party docs or must be found by trial-and-error. They really +** don't want you to write your own language-specific exception handler +** or to interact gracefully with MSVC. :-( +** +** Apparently MSVC doesn't call C++ destructors for foreign exceptions +** unless you compile your C++ code with /EHa. Unfortunately this means +** catch (...) also catches things like access violations. The use of +** _set_se_translator doesn't really help, because it requires /EHa, too. +*/ + +#define WIN32_LEAN_AND_MEAN +#include + +/* Taken from: http://www.nynaeve.net/?p=99 */ +typedef struct UndocumentedDispatcherContext { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} UndocumentedDispatcherContext; + +/* Another wild guess. */ +extern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow); + +#ifdef MINGW_SDK_INIT +/* Workaround for broken MinGW64 declaration. */ +VOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm("RtlUnwindEx"); +#define RtlUnwindEx RtlUnwindEx_FIXED +#endif + +#define LJ_MSVC_EXCODE ((DWORD)0xe06d7363) +#define LJ_GCC_EXCODE ((DWORD)0x20474343) + +#define LJ_EXCODE ((DWORD)0xe24c4a00) +#define LJ_EXCODE_MAKE(c) (LJ_EXCODE | (DWORD)(c)) +#define LJ_EXCODE_CHECK(cl) (((cl) ^ LJ_EXCODE) <= 0xff) +#define LJ_EXCODE_ERRCODE(cl) ((int)((cl) & 0xff)) + +/* Win64 exception handler for interpreter frame. */ +LJ_FUNCA EXCEPTION_DISPOSITION lj_err_unwind_win64(EXCEPTION_RECORD *rec, + void *cf, CONTEXT *ctx, UndocumentedDispatcherContext *dispatch) +{ + lua_State *L = cframe_L(cf); + int errcode = LJ_EXCODE_CHECK(rec->ExceptionCode) ? + LJ_EXCODE_ERRCODE(rec->ExceptionCode) : LUA_ERRRUN; + if ((rec->ExceptionFlags & 6)) { /* EH_UNWINDING|EH_EXIT_UNWIND */ + /* Unwind internal frames. */ + err_unwind(L, cf, errcode); + } else { + void *cf2 = err_unwind(L, cf, 0); + if (cf2) { /* We catch it, so start unwinding the upper frames. */ + if (rec->ExceptionCode == LJ_MSVC_EXCODE || + rec->ExceptionCode == LJ_GCC_EXCODE) { + __DestructExceptionObject(rec, 1); + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) { + /* Don't catch access violations etc. */ + return ExceptionContinueSearch; + } + /* Unwind the stack and call all handlers for all lower C frames + ** (including ourselves) again with EH_UNWINDING set. Then set + ** rsp = cf, rax = errcode and jump to the specified target. + */ + RtlUnwindEx(cf, (void *)((cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ? + lj_vm_unwind_ff_eh : + lj_vm_unwind_c_eh), + rec, (void *)(uintptr_t)errcode, ctx, dispatch->HistoryTable); + /* RtlUnwindEx should never return. */ + } + } + return ExceptionContinueSearch; +} + +/* Raise Windows exception. */ +static void err_raise_ext(int errcode) +{ + RaiseException(LJ_EXCODE_MAKE(errcode), 1 /* EH_NONCONTINUABLE */, 0, NULL); +} + +#endif + +/* -- Error handling ------------------------------------------------------ */ + +/* Throw error. Find catch frame, unwind stack and continue. */ +LJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode) +{ + global_State *g = G(L); + lj_trace_abort(g); + setgcrefnull(g->jit_L); + L->status = 0; +#if LJ_UNWIND_EXT + err_raise_ext(errcode); + /* + ** A return from this function signals a corrupt C stack that cannot be + ** unwound. We have no choice but to call the panic function and exit. + ** + ** Usually this is caused by a C function without unwind information. + ** This should never happen on x64, but may happen if you've manually + ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every* + ** non-C++ file with -funwind-tables. + */ + if (G(L)->panic) + G(L)->panic(L); +#else + { + void *cf = err_unwind(L, NULL, errcode); + if (cframe_unwind_ff(cf)) + lj_vm_unwind_ff(cframe_raw(cf)); + else + lj_vm_unwind_c(cframe_raw(cf), errcode); + } +#endif + exit(EXIT_FAILURE); +} + +/* Return string object for error message. */ +LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em) +{ + return lj_str_newz(L, err2msg(em)); +} + +/* Out-of-memory error. */ +LJ_NOINLINE void lj_err_mem(lua_State *L) +{ + if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ + lj_vm_unwind_c(L->cframe, LUA_ERRMEM); + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); + lj_err_throw(L, LUA_ERRMEM); +} + +/* Find error function for runtime errors. Requires an extra stack traversal. */ +static ptrdiff_t finderrfunc(lua_State *L) +{ + cTValue *frame = L->base-1, *bot = tvref(L->stack); + void *cf = L->cframe; + while (frame > bot) { + lua_assert(cf != NULL); + while (cframe_nres(cframe_raw(cf)) < 0) { /* cframe without frame? */ + if (frame >= restorestack(L, -cframe_nres(cf))) + break; + if (cframe_errfunc(cf) >= 0) /* Error handler not inherited (-1)? */ + return cframe_errfunc(cf); + cf = cframe_prev(cf); /* Else unwind cframe and continue searching. */ + if (cf == NULL) + return 0; + } + switch (frame_typep(frame)) { + case FRAME_LUA: + case FRAME_LUAP: + frame = frame_prevl(frame); + break; + case FRAME_C: + cf = cframe_prev(cf); + /* fallthrough */ + case FRAME_CONT: +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) + cf = cframe_prev(cf); +#endif + case FRAME_VARG: + frame = frame_prevd(frame); + break; + case FRAME_CP: + if (cframe_canyield(cf)) return 0; + if (cframe_errfunc(cf) >= 0) + return cframe_errfunc(cf); + frame = frame_prevd(frame); + break; + case FRAME_PCALL: + case FRAME_PCALLH: + if (frame_ftsz(frame) >= (ptrdiff_t)(2*sizeof(TValue))) /* xpcall? */ + return savestack(L, frame-1); /* Point to xpcall's errorfunc. */ + return 0; + default: + lua_assert(0); + return 0; + } + } + return 0; +} + +/* Runtime error. */ +LJ_NOINLINE void lj_err_run(lua_State *L) +{ + ptrdiff_t ef = finderrfunc(L); + if (ef) { + TValue *errfunc = restorestack(L, ef); + TValue *top = L->top; + lj_trace_abort(G(L)); + if (!tvisfunc(errfunc) || L->status == LUA_ERRERR) { + setstrV(L, top-1, lj_err_str(L, LJ_ERR_ERRERR)); + lj_err_throw(L, LUA_ERRERR); + } + L->status = LUA_ERRERR; + copyTV(L, top, top-1); + copyTV(L, top-1, errfunc); + L->top = top+1; + lj_vm_call(L, top, 1+1); /* Stack: |errfunc|msg| -> |msg| */ + } + lj_err_throw(L, LUA_ERRRUN); +} + +/* Formatted runtime error message. */ +LJ_NORET LJ_NOINLINE static void err_msgv(lua_State *L, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + if (curr_funcisL(L)) L->top = curr_topL(L); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + lj_debug_addloc(L, msg, L->base-1, NULL); + lj_err_run(L); +} + +/* Non-vararg variant for better calling conventions. */ +LJ_NOINLINE void lj_err_msg(lua_State *L, ErrMsg em) +{ + err_msgv(L, em); +} + +/* Lexer error. */ +LJ_NOINLINE void lj_err_lex(lua_State *L, GCstr *src, const char *tok, + BCLine line, ErrMsg em, va_list argp) +{ + char buff[LUA_IDSIZE]; + const char *msg; + lj_debug_shortname(buff, src); + msg = lj_str_pushvf(L, err2msg(em), argp); + msg = lj_str_pushf(L, "%s:%d: %s", buff, line, msg); + if (tok) + lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tok); + lj_err_throw(L, LUA_ERRSYNTAX); +} + +/* Typecheck error for operands. */ +LJ_NOINLINE void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm) +{ + const char *tname = lj_typename(o); + const char *opname = err2msg(opm); + if (curr_funcisL(L)) { + GCproto *pt = curr_proto(L); + const BCIns *pc = cframe_Lpc(L) - 1; + const char *oname = NULL; + const char *kind = lj_debug_slotname(pt, pc, (BCReg)(o-L->base), &oname); + if (kind) + err_msgv(L, LJ_ERR_BADOPRT, opname, kind, oname, tname); + } + err_msgv(L, LJ_ERR_BADOPRV, opname, tname); +} + +/* Typecheck error for ordered comparisons. */ +LJ_NOINLINE void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2) +{ + const char *t1 = lj_typename(o1); + const char *t2 = lj_typename(o2); + err_msgv(L, t1 == t2 ? LJ_ERR_BADCMPV : LJ_ERR_BADCMPT, t1, t2); + /* This assumes the two "boolean" entries are commoned by the C compiler. */ +} + +/* Typecheck error for __call. */ +LJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o) +{ + /* Gross hack if lua_[p]call or pcall/xpcall fail for a non-callable object: + ** L->base still points to the caller. So add a dummy frame with L instead + ** of a function. See lua_getstack(). + */ + const BCIns *pc = cframe_Lpc(L); + if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) { + const char *tname = lj_typename(o); + setframe_pc(o, pc); + setframe_gc(o, obj2gco(L)); + L->top = L->base = o+1; + err_msgv(L, LJ_ERR_BADCALL, tname); + } + lj_err_optype(L, o, LJ_ERR_OPCALL); +} + +/* Error in context of caller. */ +LJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg) +{ + TValue *frame = L->base-1; + TValue *pframe = NULL; + if (frame_islua(frame)) { + pframe = frame_prevl(frame); + } else if (frame_iscont(frame)) { +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) { + pframe = frame; + frame = NULL; + } else +#endif + { + pframe = frame_prevd(frame); +#if LJ_HASFFI + /* Remove frame for FFI metamethods. */ + if (frame_func(frame)->c.ffid >= FF_ffi_meta___index && + frame_func(frame)->c.ffid <= FF_ffi_meta___tostring) { + L->base = pframe+1; + L->top = frame; + setcframe_pc(cframe_raw(L->cframe), frame_contpc(frame)); + } +#endif + } + } + lj_debug_addloc(L, msg, pframe, frame); + lj_err_run(L); +} + +/* Formatted error in context of caller. */ +LJ_NOINLINE void lj_err_callerv(lua_State *L, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + lj_err_callermsg(L, msg); +} + +/* Error in context of caller. */ +LJ_NOINLINE void lj_err_caller(lua_State *L, ErrMsg em) +{ + lj_err_callermsg(L, err2msg(em)); +} + +/* Argument error message. */ +LJ_NORET LJ_NOINLINE static void err_argmsg(lua_State *L, int narg, + const char *msg) +{ + const char *fname = "?"; + const char *ftype = lj_debug_funcname(L, L->base - 1, &fname); + if (narg < 0 && narg > LUA_REGISTRYINDEX) + narg = (int)(L->top - L->base) + narg + 1; + if (ftype && ftype[3] == 'h' && --narg == 0) /* Check for "method". */ + msg = lj_str_pushf(L, err2msg(LJ_ERR_BADSELF), fname, msg); + else + msg = lj_str_pushf(L, err2msg(LJ_ERR_BADARG), narg, fname, msg); + lj_err_callermsg(L, msg); +} + +/* Formatted argument error. */ +LJ_NOINLINE void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + err_argmsg(L, narg, msg); +} + +/* Argument error. */ +LJ_NOINLINE void lj_err_arg(lua_State *L, int narg, ErrMsg em) +{ + err_argmsg(L, narg, err2msg(em)); +} + +/* Typecheck error for arguments. */ +LJ_NOINLINE void lj_err_argtype(lua_State *L, int narg, const char *xname) +{ + TValue *o = narg < 0 ? L->top + narg : L->base + narg-1; + const char *tname = o < L->top ? lj_typename(o) : lj_obj_typename[0]; + const char *msg = lj_str_pushf(L, err2msg(LJ_ERR_BADTYPE), xname, tname); + err_argmsg(L, narg, msg); +} + +/* Typecheck error for arguments. */ +LJ_NOINLINE void lj_err_argt(lua_State *L, int narg, int tt) +{ + lj_err_argtype(L, narg, lj_obj_typename[tt+1]); +} + +/* -- Public error handling API ------------------------------------------- */ + +LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf) +{ + lua_CFunction old = G(L)->panic; + G(L)->panic = panicf; + return old; +} + +/* Forwarders for the public API (C calling convention and no LJ_NORET). */ +LUA_API int lua_error(lua_State *L) +{ + lj_err_run(L); + return 0; /* unreachable */ +} + +LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *msg) +{ + err_argmsg(L, narg, msg); + return 0; /* unreachable */ +} + +LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *xname) +{ + lj_err_argtype(L, narg, xname); + return 0; /* unreachable */ +} + +LUALIB_API void luaL_where(lua_State *L, int level) +{ + int size; + cTValue *frame = lj_debug_frame(L, level, &size); + lj_debug_addloc(L, "", frame, size ? frame+size : NULL); +} + +LUALIB_API int luaL_error(lua_State *L, const char *fmt, ...) +{ + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = lj_str_pushvf(L, fmt, argp); + va_end(argp); + lj_err_callermsg(L, msg); + return 0; /* unreachable */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.h new file mode 100644 index 0000000..7ea512a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_err.h @@ -0,0 +1,41 @@ +/* +** Error handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_ERR_H +#define _LJ_ERR_H + +#include + +#include "lj_obj.h" + +typedef enum { +#define ERRDEF(name, msg) \ + LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1, +#include "lj_errmsg.h" + LJ_ERR__MAX +} ErrMsg; + +LJ_DATA const char *lj_err_allmsg; +#define err2msg(em) (lj_err_allmsg+(int)(em)) + +LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em); +LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode); +LJ_FUNC_NORET void lj_err_mem(lua_State *L); +LJ_FUNC_NORET void lj_err_run(lua_State *L); +LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em); +LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok, + BCLine line, ErrMsg em, va_list argp); +LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm); +LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2); +LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o); +LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg); +LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...); +LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em); +LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em); +LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...); +LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname); +LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_errmsg.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_errmsg.h new file mode 100644 index 0000000..137831e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_errmsg.h @@ -0,0 +1,193 @@ +/* +** VM error messages. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* This file may be included multiple times with different ERRDEF macros. */ + +/* Basic error handling. */ +ERRDEF(ERRMEM, "not enough memory") +ERRDEF(ERRERR, "error in error handling") +ERRDEF(ERRCPP, "C++ exception") + +/* Allocations. */ +ERRDEF(STROV, "string length overflow") +ERRDEF(UDATAOV, "userdata length overflow") +ERRDEF(STKOV, "stack overflow") +ERRDEF(STKOVM, "stack overflow (%s)") +ERRDEF(TABOV, "table overflow") + +/* Table indexing. */ +ERRDEF(NANIDX, "table index is NaN") +ERRDEF(NILIDX, "table index is nil") +ERRDEF(NEXTIDX, "invalid key to " LUA_QL("next")) + +/* Metamethod resolving. */ +ERRDEF(BADCALL, "attempt to call a %s value") +ERRDEF(BADOPRT, "attempt to %s %s " LUA_QS " (a %s value)") +ERRDEF(BADOPRV, "attempt to %s a %s value") +ERRDEF(BADCMPT, "attempt to compare %s with %s") +ERRDEF(BADCMPV, "attempt to compare two %s values") +ERRDEF(GETLOOP, "loop in gettable") +ERRDEF(SETLOOP, "loop in settable") +ERRDEF(OPCALL, "call") +ERRDEF(OPINDEX, "index") +ERRDEF(OPARITH, "perform arithmetic on") +ERRDEF(OPCAT, "concatenate") +ERRDEF(OPLEN, "get length of") + +/* Type checks. */ +ERRDEF(BADSELF, "calling " LUA_QS " on bad self (%s)") +ERRDEF(BADARG, "bad argument #%d to " LUA_QS " (%s)") +ERRDEF(BADTYPE, "%s expected, got %s") +ERRDEF(BADVAL, "invalid value") +ERRDEF(NOVAL, "value expected") +ERRDEF(NOCORO, "coroutine expected") +ERRDEF(NOTABN, "nil or table expected") +ERRDEF(NOLFUNC, "Lua function expected") +ERRDEF(NOFUNCL, "function or level expected") +ERRDEF(NOSFT, "string/function/table expected") +ERRDEF(NOPROXY, "boolean or proxy expected") +ERRDEF(FORINIT, LUA_QL("for") " initial value must be a number") +ERRDEF(FORLIM, LUA_QL("for") " limit must be a number") +ERRDEF(FORSTEP, LUA_QL("for") " step must be a number") + +/* C API checks. */ +ERRDEF(NOENV, "no calling environment") +ERRDEF(CYIELD, "attempt to yield across C-call boundary") +ERRDEF(BADLU, "bad light userdata pointer") +ERRDEF(NOGCMM, "bad action while in __gc metamethod") +#if LJ_TARGET_WINDOWS +ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)") +#endif + +/* Standard library function errors. */ +ERRDEF(ASSERT, "assertion failed!") +ERRDEF(PROTMT, "cannot change a protected metatable") +ERRDEF(UNPACK, "too many results to unpack") +ERRDEF(RDRSTR, "reader function must return a string") +ERRDEF(PRTOSTR, LUA_QL("tostring") " must return a string to " LUA_QL("print")) +ERRDEF(IDXRNG, "index out of range") +ERRDEF(BASERNG, "base out of range") +ERRDEF(LVLRNG, "level out of range") +ERRDEF(INVLVL, "invalid level") +ERRDEF(INVOPT, "invalid option") +ERRDEF(INVOPTM, "invalid option " LUA_QS) +ERRDEF(INVFMT, "invalid format") +ERRDEF(SETFENV, LUA_QL("setfenv") " cannot change environment of given object") +ERRDEF(CORUN, "cannot resume running coroutine") +ERRDEF(CODEAD, "cannot resume dead coroutine") +ERRDEF(COSUSP, "cannot resume non-suspended coroutine") +ERRDEF(TABINS, "wrong number of arguments to " LUA_QL("insert")) +ERRDEF(TABCAT, "invalid value (%s) at index %d in table for " LUA_QL("concat")) +ERRDEF(TABSORT, "invalid order function for sorting") +ERRDEF(IOCLFL, "attempt to use a closed file") +ERRDEF(IOSTDCL, "standard file is closed") +ERRDEF(OSUNIQF, "unable to generate a unique filename") +ERRDEF(OSDATEF, "field " LUA_QS " missing in date table") +ERRDEF(STRDUMP, "unable to dump given function") +ERRDEF(STRSLC, "string slice too long") +ERRDEF(STRPATB, "missing " LUA_QL("[") " after " LUA_QL("%f") " in pattern") +ERRDEF(STRPATC, "invalid pattern capture") +ERRDEF(STRPATE, "malformed pattern (ends with " LUA_QL("%") ")") +ERRDEF(STRPATM, "malformed pattern (missing " LUA_QL("]") ")") +ERRDEF(STRPATU, "unbalanced pattern") +ERRDEF(STRPATX, "pattern too complex") +ERRDEF(STRCAPI, "invalid capture index") +ERRDEF(STRCAPN, "too many captures") +ERRDEF(STRCAPU, "unfinished capture") +ERRDEF(STRFMTO, "invalid option " LUA_QL("%%%c") " to " LUA_QL("format")) +ERRDEF(STRFMTR, "invalid format (repeated flags)") +ERRDEF(STRFMTW, "invalid format (width or precision too long)") +ERRDEF(STRGSRV, "invalid replacement value (a %s)") +ERRDEF(BADMODN, "name conflict for module " LUA_QS) +#if LJ_HASJIT +ERRDEF(JITPROT, "runtime code generation failed, restricted kernel?") +#if LJ_TARGET_X86ORX64 +ERRDEF(NOJIT, "JIT compiler disabled, CPU does not support SSE2") +#else +ERRDEF(NOJIT, "JIT compiler disabled") +#endif +#elif defined(LJ_ARCH_NOJIT) +ERRDEF(NOJIT, "no JIT compiler for this architecture (yet)") +#else +ERRDEF(NOJIT, "JIT compiler permanently disabled by build option") +#endif +ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS) + +/* Lexer/parser errors. */ +ERRDEF(XMODE, "attempt to load chunk with wrong mode") +ERRDEF(XNEAR, "%s near " LUA_QS) +ERRDEF(XELEM, "lexical element too long") +ERRDEF(XLINES, "chunk has too many lines") +ERRDEF(XLEVELS, "chunk has too many syntax levels") +ERRDEF(XNUMBER, "malformed number") +ERRDEF(XLSTR, "unfinished long string") +ERRDEF(XLCOM, "unfinished long comment") +ERRDEF(XSTR, "unfinished string") +ERRDEF(XESC, "invalid escape sequence") +ERRDEF(XLDELIM, "invalid long string delimiter") +ERRDEF(XTOKEN, LUA_QS " expected") +ERRDEF(XJUMP, "control structure too long") +ERRDEF(XSLOTS, "function or expression too complex") +ERRDEF(XLIMC, "chunk has more than %d local variables") +ERRDEF(XLIMM, "main function has more than %d %s") +ERRDEF(XLIMF, "function at line %d has more than %d %s") +ERRDEF(XMATCH, LUA_QS " expected (to close " LUA_QS " at line %d)") +ERRDEF(XFIXUP, "function too long for return fixup") +ERRDEF(XPARAM, " or " LUA_QL("...") " expected") +#if !LJ_52 +ERRDEF(XAMBIG, "ambiguous syntax (function call x new statement)") +#endif +ERRDEF(XFUNARG, "function arguments expected") +ERRDEF(XSYMBOL, "unexpected symbol") +ERRDEF(XDOTS, "cannot use " LUA_QL("...") " outside a vararg function") +ERRDEF(XSYNTAX, "syntax error") +ERRDEF(XFOR, LUA_QL("=") " or " LUA_QL("in") " expected") +ERRDEF(XBREAK, "no loop to break") +ERRDEF(XLUNDEF, "undefined label " LUA_QS) +ERRDEF(XLDUP, "duplicate label " LUA_QS) +ERRDEF(XGSCOPE, " jumps into the scope of local " LUA_QS) + +/* Bytecode reader errors. */ +ERRDEF(BCFMT, "cannot load incompatible bytecode") +ERRDEF(BCBAD, "cannot load malformed bytecode") + +#if LJ_HASFFI +/* FFI errors. */ +ERRDEF(FFI_INVTYPE, "invalid C type") +ERRDEF(FFI_INVSIZE, "size of C type is unknown or too large") +ERRDEF(FFI_BADSCL, "bad storage class") +ERRDEF(FFI_DECLSPEC, "declaration specifier expected") +ERRDEF(FFI_BADTAG, "undeclared or implicit tag " LUA_QS) +ERRDEF(FFI_REDEF, "attempt to redefine " LUA_QS) +ERRDEF(FFI_NUMPARAM, "wrong number of type parameters") +ERRDEF(FFI_INITOV, "too many initializers for " LUA_QS) +ERRDEF(FFI_BADCONV, "cannot convert " LUA_QS " to " LUA_QS) +ERRDEF(FFI_BADLEN, "attempt to get length of " LUA_QS) +ERRDEF(FFI_BADCONCAT, "attempt to concatenate " LUA_QS " and " LUA_QS) +ERRDEF(FFI_BADARITH, "attempt to perform arithmetic on " LUA_QS " and " LUA_QS) +ERRDEF(FFI_BADCOMP, "attempt to compare " LUA_QS " with " LUA_QS) +ERRDEF(FFI_BADCALL, LUA_QS " is not callable") +ERRDEF(FFI_NUMARG, "wrong number of arguments for function call") +ERRDEF(FFI_BADMEMBER, LUA_QS " has no member named " LUA_QS) +ERRDEF(FFI_BADIDX, LUA_QS " cannot be indexed") +ERRDEF(FFI_BADIDXW, LUA_QS " cannot be indexed with " LUA_QS) +ERRDEF(FFI_BADMM, LUA_QS " has no " LUA_QS " metamethod") +ERRDEF(FFI_WRCONST, "attempt to write to constant location") +ERRDEF(FFI_NODECL, "missing declaration for symbol " LUA_QS) +ERRDEF(FFI_BADCBACK, "bad callback") +#if LJ_OS_NOJIT +ERRDEF(FFI_CBACKOV, "no support for callbacks on this OS") +#else +ERRDEF(FFI_CBACKOV, "too many callbacks") +#endif +ERRDEF(FFI_NYIPACKBIT, "NYI: packed bit fields") +ERRDEF(FFI_NYICALL, "NYI: cannot call this C function (yet)") +#endif + +#undef ERRDEF + +/* Detecting unused error messages: + awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, ""); printf "grep -q LJ_ERR_%s *.[ch] || echo %s\n", $1, $1}' lj_errmsg.h | sh +*/ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ff.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ff.h new file mode 100644 index 0000000..d91a739 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ff.h @@ -0,0 +1,18 @@ +/* +** Fast function IDs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FF_H +#define _LJ_FF_H + +/* Fast function ID. */ +typedef enum { + FF_LUA_ = FF_LUA, /* Lua function (must be 0). */ + FF_C_ = FF_C, /* Regular C function (must be 1). */ +#define FFDEF(name) FF_##name, +#include "lj_ffdef.h" + FF__MAX +} FastFunc; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffdef.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffdef.h new file mode 100644 index 0000000..3c6abe2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffdef.h @@ -0,0 +1,210 @@ +/* This is a generated file. DO NOT EDIT! */ + +FFDEF(assert) +FFDEF(type) +FFDEF(next) +FFDEF(pairs) +FFDEF(ipairs_aux) +FFDEF(ipairs) +FFDEF(getmetatable) +FFDEF(setmetatable) +FFDEF(getfenv) +FFDEF(setfenv) +FFDEF(rawget) +FFDEF(rawset) +FFDEF(rawequal) +FFDEF(unpack) +FFDEF(select) +FFDEF(tonumber) +FFDEF(tostring) +FFDEF(error) +FFDEF(pcall) +FFDEF(xpcall) +FFDEF(loadfile) +FFDEF(load) +FFDEF(loadstring) +FFDEF(dofile) +FFDEF(gcinfo) +FFDEF(collectgarbage) +FFDEF(newproxy) +FFDEF(print) +FFDEF(coroutine_status) +FFDEF(coroutine_running) +FFDEF(coroutine_create) +FFDEF(coroutine_yield) +FFDEF(coroutine_resume) +FFDEF(coroutine_wrap_aux) +FFDEF(coroutine_wrap) +FFDEF(math_abs) +FFDEF(math_floor) +FFDEF(math_ceil) +FFDEF(math_sqrt) +FFDEF(math_log10) +FFDEF(math_exp) +FFDEF(math_sin) +FFDEF(math_cos) +FFDEF(math_tan) +FFDEF(math_asin) +FFDEF(math_acos) +FFDEF(math_atan) +FFDEF(math_sinh) +FFDEF(math_cosh) +FFDEF(math_tanh) +FFDEF(math_frexp) +FFDEF(math_modf) +FFDEF(math_deg) +FFDEF(math_rad) +FFDEF(math_log) +FFDEF(math_atan2) +FFDEF(math_pow) +FFDEF(math_fmod) +FFDEF(math_ldexp) +FFDEF(math_min) +FFDEF(math_max) +FFDEF(math_random) +FFDEF(math_randomseed) +FFDEF(bit_tobit) +FFDEF(bit_bnot) +FFDEF(bit_bswap) +FFDEF(bit_lshift) +FFDEF(bit_rshift) +FFDEF(bit_arshift) +FFDEF(bit_rol) +FFDEF(bit_ror) +FFDEF(bit_band) +FFDEF(bit_bor) +FFDEF(bit_bxor) +FFDEF(bit_tohex) +FFDEF(string_len) +FFDEF(string_byte) +FFDEF(string_char) +FFDEF(string_sub) +FFDEF(string_rep) +FFDEF(string_reverse) +FFDEF(string_lower) +FFDEF(string_upper) +FFDEF(string_dump) +FFDEF(string_find) +FFDEF(string_match) +FFDEF(string_gmatch_aux) +FFDEF(string_gmatch) +FFDEF(string_gsub) +FFDEF(string_format) +FFDEF(table_foreachi) +FFDEF(table_foreach) +FFDEF(table_getn) +FFDEF(table_maxn) +FFDEF(table_insert) +FFDEF(table_remove) +FFDEF(table_concat) +FFDEF(table_sort) +FFDEF(io_method_close) +FFDEF(io_method_read) +FFDEF(io_method_write) +FFDEF(io_method_flush) +FFDEF(io_method_seek) +FFDEF(io_method_setvbuf) +FFDEF(io_method_lines) +FFDEF(io_method___gc) +FFDEF(io_method___tostring) +FFDEF(io_open) +FFDEF(io_popen) +FFDEF(io_tmpfile) +FFDEF(io_close) +FFDEF(io_read) +FFDEF(io_write) +FFDEF(io_flush) +FFDEF(io_input) +FFDEF(io_output) +FFDEF(io_lines) +FFDEF(io_type) +FFDEF(os_execute) +FFDEF(os_remove) +FFDEF(os_rename) +FFDEF(os_tmpname) +FFDEF(os_getenv) +FFDEF(os_exit) +FFDEF(os_clock) +FFDEF(os_date) +FFDEF(os_time) +FFDEF(os_difftime) +FFDEF(os_setlocale) +FFDEF(debug_getregistry) +FFDEF(debug_getmetatable) +FFDEF(debug_setmetatable) +FFDEF(debug_getfenv) +FFDEF(debug_setfenv) +FFDEF(debug_getinfo) +FFDEF(debug_getlocal) +FFDEF(debug_setlocal) +FFDEF(debug_getupvalue) +FFDEF(debug_setupvalue) +FFDEF(debug_upvalueid) +FFDEF(debug_upvaluejoin) +FFDEF(debug_sethook) +FFDEF(debug_gethook) +FFDEF(debug_debug) +FFDEF(debug_traceback) +FFDEF(jit_on) +FFDEF(jit_off) +FFDEF(jit_flush) +FFDEF(jit_status) +FFDEF(jit_attach) +FFDEF(jit_util_funcinfo) +FFDEF(jit_util_funcbc) +FFDEF(jit_util_funck) +FFDEF(jit_util_funcuvname) +FFDEF(jit_util_traceinfo) +FFDEF(jit_util_traceir) +FFDEF(jit_util_tracek) +FFDEF(jit_util_tracesnap) +FFDEF(jit_util_tracemc) +FFDEF(jit_util_traceexitstub) +FFDEF(jit_util_ircalladdr) +FFDEF(jit_opt_start) +FFDEF(ffi_meta___index) +FFDEF(ffi_meta___newindex) +FFDEF(ffi_meta___eq) +FFDEF(ffi_meta___len) +FFDEF(ffi_meta___lt) +FFDEF(ffi_meta___le) +FFDEF(ffi_meta___concat) +FFDEF(ffi_meta___call) +FFDEF(ffi_meta___add) +FFDEF(ffi_meta___sub) +FFDEF(ffi_meta___mul) +FFDEF(ffi_meta___div) +FFDEF(ffi_meta___mod) +FFDEF(ffi_meta___pow) +FFDEF(ffi_meta___unm) +FFDEF(ffi_meta___tostring) +FFDEF(ffi_meta___pairs) +FFDEF(ffi_meta___ipairs) +FFDEF(ffi_clib___index) +FFDEF(ffi_clib___newindex) +FFDEF(ffi_clib___gc) +FFDEF(ffi_callback_free) +FFDEF(ffi_callback_set) +FFDEF(ffi_cdef) +FFDEF(ffi_new) +FFDEF(ffi_cast) +FFDEF(ffi_typeof) +FFDEF(ffi_istype) +FFDEF(ffi_sizeof) +FFDEF(ffi_alignof) +FFDEF(ffi_offsetof) +FFDEF(ffi_errno) +FFDEF(ffi_string) +FFDEF(ffi_copy) +FFDEF(ffi_fill) +FFDEF(ffi_abi) +FFDEF(ffi_metatype) +FFDEF(ffi_gc) +FFDEF(ffi_load) + +#undef FFDEF + +#ifndef FF_NUM_ASMFUNC +#define FF_NUM_ASMFUNC 62 +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.c new file mode 100644 index 0000000..794bbd4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.c @@ -0,0 +1,888 @@ +/* +** Fast function call recorder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ffrecord_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_crecord.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* -- Fast function recording handlers ------------------------------------ */ + +/* Conventions for fast function call handlers: +** +** The argument slots start at J->base[0]. All of them are guaranteed to be +** valid and type-specialized references. J->base[J->maxslot] is set to 0 +** as a sentinel. The runtime argument values start at rd->argv[0]. +** +** In general fast functions should check for presence of all of their +** arguments and for the correct argument types. Some simplifications +** are allowed if the interpreter throws instead. But even if recording +** is aborted, the generated IR must be consistent (no zero-refs). +** +** The number of results in rd->nres is set to 1. Handlers that return +** a different number of results need to override it. A negative value +** prevents return processing (e.g. for pending calls). +** +** Results need to be stored starting at J->base[0]. Return processing +** moves them to the right slots later. +** +** The per-ffid auxiliary data is the value of the 2nd part of the +** LJLIB_REC() annotation. This allows handling similar functionality +** in a common handler. +*/ + +/* Type of handler to record a fast function. */ +typedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd); + +/* Get runtime value of int argument. */ +static int32_t argv2int(jit_State *J, TValue *o) +{ + if (!lj_strscan_numberobj(o)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + return tvisint(o) ? intV(o) : lj_num2int(numV(o)); +} + +/* Get runtime value of string argument. */ +static GCstr *argv2str(jit_State *J, TValue *o) +{ + if (LJ_LIKELY(tvisstr(o))) { + return strV(o); + } else { + GCstr *s; + if (!tvisnumber(o)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if (tvisint(o)) + s = lj_str_fromint(J->L, intV(o)); + else + s = lj_str_fromnum(J->L, &o->n); + setstrV(J->L, o, s); + return s; + } +} + +/* Return number of results wanted by caller. */ +static ptrdiff_t results_wanted(jit_State *J) +{ + TValue *frame = J->L->base-1; + if (frame_islua(frame)) + return (ptrdiff_t)bc_b(frame_pc(frame)[-1]) - 1; + else + return -1; +} + +/* Throw error for unsupported variant of fast function. */ +LJ_NORET static void recff_nyiu(jit_State *J) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFFU); +} + +/* Fallback handler for all fast functions that are not recorded (yet). */ +static void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFF); + UNUSED(rd); +} + +/* C functions can have arbitrary side-effects and are not recorded (yet). */ +static void LJ_FASTCALL recff_c(jit_State *J, RecordFFData *rd) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYICF); + UNUSED(rd); +} + +/* -- Base library fast functions ----------------------------------------- */ + +static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd) +{ + /* Arguments already specialized. The interpreter throws for nil/false. */ + rd->nres = J->maxslot; /* Pass through all arguments. */ +} + +static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd) +{ + /* Arguments already specialized. Result is a constant string. Neat, huh? */ + uint32_t t; + if (tvisnumber(&rd->argv[0])) + t = ~LJ_TNUMX; + else if (LJ_64 && tvislightud(&rd->argv[0])) + t = ~LJ_TLIGHTUD; + else + t = ~itype(&rd->argv[0]); + J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[t])); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tr) { + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + if (lj_record_mm_lookup(J, &ix, MM_metatable)) + J->base[0] = ix.mobj; + else + J->base[0] = ix.mt; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + TRef mt = J->base[1]; + if (tref_istab(tr) && (tref_istab(mt) || (mt && tref_isnil(mt)))) { + TRef fref, mtref; + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + lj_record_mm_lookup(J, &ix, MM_metatable); /* Guard for no __metatable. */ + fref = emitir(IRT(IR_FREF, IRT_P32), tr, IRFL_TAB_META); + mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt; + emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref); + if (!tref_isnil(mt)) + emitir(IRT(IR_TBAR, IRT_TAB), tr, 0); + J->base[0] = tr; + J->needsnap = 1; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawget(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; ix.key = J->base[1]; + if (tref_istab(ix.tab) && ix.key) { + ix.val = 0; ix.idxchain = 0; + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + copyTV(J->L, &ix.keyv, &rd->argv[1]); + J->base[0] = lj_record_idx(J, &ix); + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawset(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; ix.key = J->base[1]; ix.val = J->base[2]; + if (tref_istab(ix.tab) && ix.key && ix.val) { + ix.idxchain = 0; + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + copyTV(J->L, &ix.keyv, &rd->argv[1]); + copyTV(J->L, &ix.valv, &rd->argv[2]); + lj_record_idx(J, &ix); + /* Pass through table at J->base[0] as result. */ + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd) +{ + TRef tra = J->base[0]; + TRef trb = J->base[1]; + if (tra && trb) { + int diff = lj_record_objcmp(J, tra, trb, &rd->argv[0], &rd->argv[1]); + J->base[0] = diff ? TREF_FALSE : TREF_TRUE; + } /* else: Interpreter will throw. */ +} + +#if LJ_52 +static void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isstr(tr)) + J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN); + else if (tref_istab(tr)) + J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr); + /* else: Interpreter will throw. */ + UNUSED(rd); +} +#endif + +/* Determine mode of select() call. */ +int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv) +{ + if (tref_isstr(tr) && *strVdata(tv) == '#') { /* select('#', ...) */ + if (strV(tv)->len == 1) { + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, strV(tv))); + } else { + TRef trptr = emitir(IRT(IR_STRREF, IRT_P32), tr, lj_ir_kint(J, 0)); + TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY); + emitir(IRTG(IR_EQ, IRT_INT), trchar, lj_ir_kint(J, '#')); + } + return 0; + } else { /* select(n, ...) */ + int32_t start = argv2int(J, tv); + if (start == 0) lj_trace_err(J, LJ_TRERR_BADTYPE); /* A bit misleading. */ + return start; + } +} + +static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tr) { + ptrdiff_t start = lj_ffrecord_select_mode(J, tr, &rd->argv[0]); + if (start == 0) { /* select('#', ...) */ + J->base[0] = lj_ir_kint(J, J->maxslot - 1); + } else if (tref_isk(tr)) { /* select(k, ...) */ + ptrdiff_t n = (ptrdiff_t)J->maxslot; + if (start < 0) start += n; + else if (start > n) start = n; + rd->nres = n - start; + if (start >= 1) { + ptrdiff_t i; + for (i = 0; i < n - start; i++) + J->base[i] = J->base[start+i]; + } /* else: Interpreter will throw. */ + } else { + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + TRef base = J->base[1]; + if (tr && !tref_isnil(base)) { + base = lj_opt_narrow_toint(J, base); + if (!tref_isk(base) || IR(tref_ref(base))->i != 10) + recff_nyiu(J); + } + if (tref_isnumber_str(tr)) { + if (tref_isstr(tr)) { + TValue tmp; + if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) + recff_nyiu(J); /* Would need an inverted STRTO for this case. */ + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + } +#if LJ_HASFFI + } else if (tref_iscdata(tr)) { + lj_crecord_tonumber(J, rd); + return; +#endif + } else { + tr = TREF_NIL; + } + J->base[0] = tr; + UNUSED(rd); +} + +static TValue *recff_metacall_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + lj_record_tailcall(J, 0, 1); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +static int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm) +{ + RecordIndex ix; + ix.tab = J->base[0]; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + if (lj_record_mm_lookup(J, &ix, mm)) { /* Has metamethod? */ + int errcode; + TValue argv0; + /* Temporarily insert metamethod below object. */ + J->base[1] = J->base[0]; + J->base[0] = ix.mobj; + copyTV(J->L, &argv0, &rd->argv[0]); + copyTV(J->L, &rd->argv[1], &rd->argv[0]); + copyTV(J->L, &rd->argv[0], &ix.mobjv); + /* Need to protect lj_record_tailcall because it may throw. */ + errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp); + /* Always undo Lua stack changes to avoid confusing the interpreter. */ + copyTV(J->L, &rd->argv[0], &argv0); + if (errcode) + lj_err_throw(J->L, errcode); /* Propagate errors. */ + rd->nres = -1; /* Pending call. */ + return 1; /* Tailcalled to metamethod. */ + } + return 0; +} + +static void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isstr(tr)) { + /* Ignore __tostring in the string base metatable. */ + /* Pass on result in J->base[0]. */ + } else if (!recff_metacall(J, rd, MM_tostring)) { + if (tref_isnumber(tr)) { + J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); + } else if (tref_ispri(tr)) { + J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[tref_type(tr)])); + } else { + recff_nyiu(J); + } + } +} + +static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; + if (tref_istab(ix.tab)) { + if (!tvisnumber(&rd->argv[1])) /* No support for string coercion. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + setintV(&ix.keyv, numberVint(&rd->argv[1])+1); + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + ix.val = 0; ix.idxchain = 0; + ix.key = lj_opt_narrow_toint(J, J->base[1]); + J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1)); + J->base[1] = lj_record_idx(J, &ix); + rd->nres = tref_isnil(J->base[1]) ? 0 : 2; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) +{ + if (!(LJ_52 && recff_metacall(J, rd, MM_ipairs))) { + TRef tab = J->base[0]; + if (tref_istab(tab)) { + J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); + J->base[1] = tab; + J->base[2] = lj_ir_kint(J, 0); + rd->nres = 3; + } /* else: Interpreter will throw. */ + } +} + +static void LJ_FASTCALL recff_pcall(jit_State *J, RecordFFData *rd) +{ + if (J->maxslot >= 1) { + lj_record_call(J, 0, J->maxslot - 1); + rd->nres = -1; /* Pending call. */ + } /* else: Interpreter will throw. */ +} + +static TValue *recff_xpcall_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + lj_record_call(J, 1, J->maxslot - 2); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd) +{ + if (J->maxslot >= 2) { + TValue argv0, argv1; + TRef tmp; + int errcode; + /* Swap function and traceback. */ + tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp; + copyTV(J->L, &argv0, &rd->argv[0]); + copyTV(J->L, &argv1, &rd->argv[1]); + copyTV(J->L, &rd->argv[0], &argv1); + copyTV(J->L, &rd->argv[1], &argv0); + /* Need to protect lj_record_call because it may throw. */ + errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp); + /* Always undo Lua stack swap to avoid confusing the interpreter. */ + copyTV(J->L, &rd->argv[0], &argv0); + copyTV(J->L, &rd->argv[1], &argv1); + if (errcode) + lj_err_throw(J->L, errcode); /* Propagate errors. */ + rd->nres = -1; /* Pending call. */ + } /* else: Interpreter will throw. */ +} + +/* -- Math library fast functions ----------------------------------------- */ + +static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + J->base[0] = emitir(IRTN(IR_ABS), tr, lj_ir_knum_abs(J)); + UNUSED(rd); +} + +/* Record rounding functions math.floor and math.ceil. */ +static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (!tref_isinteger(tr)) { /* Pass through integers unmodified. */ + tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data); + /* Result is integral (or NaN/Inf), but may not fit an int32_t. */ + if (LJ_DUALNUM) { /* Try to narrow using a guarded conversion to int. */ + lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data); + if (n == (lua_Number)lj_num2int(n)) + tr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK); + } + J->base[0] = tr; + } +} + +/* Record unary math.* functions, mapped to IR_FPMATH opcode. */ +static void LJ_FASTCALL recff_math_unary(jit_State *J, RecordFFData *rd) +{ + J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data); +} + +/* Record math.log. */ +static void LJ_FASTCALL recff_math_log(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + if (J->base[1]) { +#ifdef LUAJIT_NO_LOG2 + uint32_t fpm = IRFPM_LOG; +#else + uint32_t fpm = IRFPM_LOG2; +#endif + TRef trb = lj_ir_tonum(J, J->base[1]); + tr = emitir(IRTN(IR_FPMATH), tr, fpm); + trb = emitir(IRTN(IR_FPMATH), trb, fpm); + trb = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), trb); + tr = emitir(IRTN(IR_MUL), tr, trb); + } else { + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_LOG); + } + J->base[0] = tr; + UNUSED(rd); +} + +/* Record math.atan2. */ +static void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + TRef tr2 = lj_ir_tonum(J, J->base[1]); + J->base[0] = emitir(IRTN(IR_ATAN2), tr, tr2); + UNUSED(rd); +} + +/* Record math.ldexp. */ +static void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); +#if LJ_TARGET_X86ORX64 + TRef tr2 = lj_ir_tonum(J, J->base[1]); +#else + TRef tr2 = lj_opt_narrow_toint(J, J->base[1]); +#endif + J->base[0] = emitir(IRTN(IR_LDEXP), tr, tr2); + UNUSED(rd); +} + +/* Record math.asin, math.acos, math.atan. */ +static void LJ_FASTCALL recff_math_atrig(jit_State *J, RecordFFData *rd) +{ + TRef y = lj_ir_tonum(J, J->base[0]); + TRef x = lj_ir_knum_one(J); + uint32_t ffid = rd->data; + if (ffid != FF_math_atan) { + TRef tmp = emitir(IRTN(IR_MUL), y, y); + tmp = emitir(IRTN(IR_SUB), x, tmp); + tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_SQRT); + if (ffid == FF_math_asin) { x = tmp; } else { x = y; y = tmp; } + } + J->base[0] = emitir(IRTN(IR_ATAN2), y, x); +} + +static void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data); +} + +static void LJ_FASTCALL recff_math_modf(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isinteger(tr)) { + J->base[0] = tr; + J->base[1] = lj_ir_kint(J, 0); + } else { + TRef trt; + tr = lj_ir_tonum(J, tr); + trt = emitir(IRTN(IR_FPMATH), tr, IRFPM_TRUNC); + J->base[0] = trt; + J->base[1] = emitir(IRTN(IR_SUB), tr, trt); + } + rd->nres = 2; +} + +static void LJ_FASTCALL recff_math_degrad(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + TRef trm = lj_ir_knum(J, numV(&J->fn->c.upvalue[0])); + J->base[0] = emitir(IRTN(IR_MUL), tr, trm); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + if (!tref_isnumber_str(J->base[1])) + lj_trace_err(J, LJ_TRERR_BADTYPE); + J->base[0] = lj_opt_narrow_pow(J, tr, J->base[1], &rd->argv[1]); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_math_minmax(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonumber(J, J->base[0]); + uint32_t op = rd->data; + BCReg i; + for (i = 1; J->base[i] != 0; i++) { + TRef tr2 = lj_ir_tonumber(J, J->base[i]); + IRType t = IRT_INT; + if (!(tref_isinteger(tr) && tref_isinteger(tr2))) { + if (tref_isinteger(tr)) tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + if (tref_isinteger(tr2)) tr2 = emitir(IRTN(IR_CONV), tr2, IRCONV_NUM_INT); + t = IRT_NUM; + } + tr = emitir(IRT(op, t), tr, tr2); + } + J->base[0] = tr; +} + +static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd) +{ + GCudata *ud = udataV(&J->fn->c.upvalue[0]); + TRef tr, one; + lj_ir_kgc(J, obj2gco(ud), IRT_UDATA); /* Prevent collection. */ + tr = lj_ir_call(J, IRCALL_lj_math_random_step, lj_ir_kptr(J, uddata(ud))); + one = lj_ir_knum_one(J); + tr = emitir(IRTN(IR_SUB), tr, one); + if (J->base[0]) { + TRef tr1 = lj_ir_tonum(J, J->base[0]); + if (J->base[1]) { /* d = floor(d*(r2-r1+1.0)) + r1 */ + TRef tr2 = lj_ir_tonum(J, J->base[1]); + tr2 = emitir(IRTN(IR_SUB), tr2, tr1); + tr2 = emitir(IRTN(IR_ADD), tr2, one); + tr = emitir(IRTN(IR_MUL), tr, tr2); + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); + tr = emitir(IRTN(IR_ADD), tr, tr1); + } else { /* d = floor(d*r1) + 1.0 */ + tr = emitir(IRTN(IR_MUL), tr, tr1); + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); + tr = emitir(IRTN(IR_ADD), tr, one); + } + } + J->base[0] = tr; + UNUSED(rd); +} + +/* -- Bit library fast functions ------------------------------------------ */ + +/* Record unary bit.tobit, bit.bnot, bit.bswap. */ +static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + J->base[0] = (rd->data == IR_TOBIT) ? tr : emitir(IRTI(rd->data), tr, 0); +} + +/* Record N-ary bit.band, bit.bor, bit.bxor. */ +static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + uint32_t op = rd->data; + BCReg i; + for (i = 1; J->base[i] != 0; i++) + tr = emitir(IRTI(op), tr, lj_opt_narrow_tobit(J, J->base[i])); + J->base[0] = tr; +} + +/* Record bit shifts. */ +static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + TRef tsh = lj_opt_narrow_tobit(J, J->base[1]); + IROp op = (IROp)rd->data; + if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && + !tref_isk(tsh)) + tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31)); +#ifdef LJ_TARGET_UNIFYROT + if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) { + op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR; + tsh = emitir(IRTI(IR_NEG), tsh, tsh); + } +#endif + J->base[0] = emitir(IRTI(op), tr, tsh); +} + +/* -- String library fast functions --------------------------------------- */ + +static void LJ_FASTCALL recff_string_len(jit_State *J, RecordFFData *rd) +{ + J->base[0] = emitir(IRTI(IR_FLOAD), lj_ir_tostr(J, J->base[0]), IRFL_STR_LEN); + UNUSED(rd); +} + +/* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */ +static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) +{ + TRef trstr = lj_ir_tostr(J, J->base[0]); + TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN); + TRef tr0 = lj_ir_kint(J, 0); + TRef trstart, trend; + GCstr *str = argv2str(J, &rd->argv[0]); + int32_t start, end; + if (rd->data) { /* string.sub(str, start [,end]) */ + start = argv2int(J, &rd->argv[1]); + trstart = lj_opt_narrow_toint(J, J->base[1]); + trend = J->base[2]; + if (tref_isnil(trend)) { + trend = lj_ir_kint(J, -1); + end = -1; + } else { + trend = lj_opt_narrow_toint(J, trend); + end = argv2int(J, &rd->argv[2]); + } + } else { /* string.byte(str, [,start [,end]]) */ + if (tref_isnil(J->base[1])) { + start = 1; + trstart = lj_ir_kint(J, 1); + } else { + start = argv2int(J, &rd->argv[1]); + trstart = lj_opt_narrow_toint(J, J->base[1]); + } + if (J->base[1] && !tref_isnil(J->base[2])) { + trend = lj_opt_narrow_toint(J, J->base[2]); + end = argv2int(J, &rd->argv[2]); + } else { + trend = trstart; + end = start; + } + } + if (end < 0) { + emitir(IRTGI(IR_LT), trend, tr0); + trend = emitir(IRTI(IR_ADD), emitir(IRTI(IR_ADD), trlen, trend), + lj_ir_kint(J, 1)); + end = end+(int32_t)str->len+1; + } else if ((MSize)end <= str->len) { + emitir(IRTGI(IR_ULE), trend, trlen); + } else { + emitir(IRTGI(IR_GT), trend, trlen); + end = (int32_t)str->len; + trend = trlen; + } + if (start < 0) { + emitir(IRTGI(IR_LT), trstart, tr0); + trstart = emitir(IRTI(IR_ADD), trlen, trstart); + start = start+(int32_t)str->len; + emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), trstart, tr0); + if (start < 0) { + trstart = tr0; + start = 0; + } + } else { + if (start == 0) { + emitir(IRTGI(IR_EQ), trstart, tr0); + trstart = tr0; + } else { + trstart = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1)); + emitir(IRTGI(IR_GE), trstart, tr0); + start--; + } + } + if (rd->data) { /* Return string.sub result. */ + if (end - start >= 0) { + /* Also handle empty range here, to avoid extra traces. */ + TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart); + emitir(IRTGI(IR_GE), trslen, tr0); + trptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart); + J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen); + } else { /* Range underflow: return empty string. */ + emitir(IRTGI(IR_LT), trend, trstart); + J->base[0] = lj_ir_kstr(J, lj_str_new(J->L, strdata(str), 0)); + } + } else { /* Return string.byte result(s). */ + ptrdiff_t i, len = end - start; + if (len > 0) { + TRef trslen = emitir(IRTI(IR_SUB), trend, trstart); + emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len)); + if (J->baseslot + len > LJ_MAX_JSLOTS) + lj_trace_err_info(J, LJ_TRERR_STACKOV); + rd->nres = len; + for (i = 0; i < len; i++) { + TRef tmp = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, (int32_t)i)); + tmp = emitir(IRT(IR_STRREF, IRT_P32), trstr, tmp); + J->base[i] = emitir(IRT(IR_XLOAD, IRT_U8), tmp, IRXLOAD_READONLY); + } + } else { /* Empty range or range underflow: return no results. */ + emitir(IRTGI(IR_LE), trend, trstart); + rd->nres = 0; + } + } +} + +/* -- Table library fast functions ---------------------------------------- */ + +static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd) +{ + if (tref_istab(J->base[0])) + J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]); + /* else: Interpreter will throw. */ + UNUSED(rd); +} + +static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) +{ + TRef tab = J->base[0]; + rd->nres = 0; + if (tref_istab(tab)) { + if (tref_isnil(J->base[1])) { /* Simple pop: t[#t] = nil */ + TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, tab); + GCtab *t = tabV(&rd->argv[0]); + MSize len = lj_tab_len(t); + emitir(IRTGI(len ? IR_NE : IR_EQ), trlen, lj_ir_kint(J, 0)); + if (len) { + RecordIndex ix; + ix.tab = tab; + ix.key = trlen; + settabV(J->L, &ix.tabv, t); + setintV(&ix.keyv, len); + ix.idxchain = 0; + if (results_wanted(J) != 0) { /* Specialize load only if needed. */ + ix.val = 0; + J->base[0] = lj_record_idx(J, &ix); /* Load previous value. */ + rd->nres = 1; + /* Assumes ix.key/ix.tab is not modified for raw lj_record_idx(). */ + } + ix.val = TREF_NIL; + lj_record_idx(J, &ix); /* Remove value. */ + } + } else { /* Complex case: remove in the middle. */ + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; + ix.val = J->base[1]; + rd->nres = 0; + if (tref_istab(ix.tab) && ix.val) { + if (!J->base[2]) { /* Simple push: t[#t+1] = v */ + TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, ix.tab); + GCtab *t = tabV(&rd->argv[0]); + ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1)); + settabV(J->L, &ix.tabv, t); + setintV(&ix.keyv, lj_tab_len(t) + 1); + ix.idxchain = 0; + lj_record_idx(J, &ix); /* Set new value. */ + } else { /* Complex case: insert in the middle. */ + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +/* -- I/O library fast functions ------------------------------------------ */ + +/* Get FILE* for I/O function. Any I/O error aborts recording, so there's +** no need to encode the alternate cases for any of the guards. +*/ +static TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id) +{ + TRef tr, ud, fp; + if (id) { /* io.func() */ + tr = lj_ir_kptr(J, &J2G(J)->gcroot[id]); + ud = emitir(IRT(IR_XLOAD, IRT_UDATA), tr, 0); + } else { /* fp:method() */ + ud = J->base[0]; + if (!tref_isudata(ud)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); + } + *udp = ud; + fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE); + emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR)); + return fp; +} + +static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd) +{ + TRef ud, fp = recff_io_fp(J, &ud, rd->data); + TRef zero = lj_ir_kint(J, 0); + TRef one = lj_ir_kint(J, 1); + ptrdiff_t i = rd->data == 0 ? 1 : 0; + for (; J->base[i]; i++) { + TRef str = lj_ir_tostr(J, J->base[i]); + TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero); + TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN); + if (tref_isk(len) && IR(tref_ref(len))->i == 1) { + TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY); + tr = lj_ir_call(J, IRCALL_fputc, tr, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1)); + } else { + TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_EQ), tr, len); + } + } + J->base[0] = LJ_52 ? ud : TREF_TRUE; +} + +static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) +{ + TRef ud, fp = recff_io_fp(J, &ud, rd->data); + TRef tr = lj_ir_call(J, IRCALL_fflush, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); + J->base[0] = TREF_TRUE; +} + +/* -- Record calls to fast functions -------------------------------------- */ + +#include "lj_recdef.h" + +static uint32_t recdef_lookup(GCfunc *fn) +{ + if (fn->c.ffid < sizeof(recff_idmap)/sizeof(recff_idmap[0])) + return recff_idmap[fn->c.ffid]; + else + return 0; +} + +/* Record entry to a fast function or C function. */ +void lj_ffrecord_func(jit_State *J) +{ + RecordFFData rd; + uint32_t m = recdef_lookup(J->fn); + rd.data = m & 0xff; + rd.nres = 1; /* Default is one result. */ + rd.argv = J->L->base; + J->base[J->maxslot] = 0; /* Mark end of arguments. */ + (recff_func[m >> 8])(J, &rd); /* Call recff_* handler. */ + if (rd.nres >= 0) { + if (J->postproc == LJ_POST_NONE) J->postproc = LJ_POST_FFRETRY; + lj_record_ret(J, 0, rd.nres); + } +} + +#undef IR +#undef emitir + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.h new file mode 100644 index 0000000..b3bc662 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ffrecord.h @@ -0,0 +1,24 @@ +/* +** Fast function call recorder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FFRECORD_H +#define _LJ_FFRECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* Data used by handlers to record a fast function. */ +typedef struct RecordFFData { + TValue *argv; /* Runtime argument values. */ + ptrdiff_t nres; /* Number of returned results (defaults to 1). */ + uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */ +} RecordFFData; + +LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv); +LJ_FUNC void lj_ffrecord_func(jit_State *J); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_folddef.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_folddef.h new file mode 100644 index 0000000..ebda3b1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_folddef.h @@ -0,0 +1,1068 @@ +/* This is a generated file. DO NOT EDIT! */ + +static const FoldFunc fold_func[] = { + fold_kfold_numarith, + fold_kfold_ldexp, + fold_kfold_fpmath, + fold_kfold_numpow, + fold_kfold_numcomp, + fold_kfold_intarith, + fold_kfold_intovarith, + fold_kfold_bnot, + fold_kfold_bswap, + fold_kfold_intcomp, + fold_kfold_intcomp0, + fold_kfold_int64arith, + fold_kfold_int64arith2, + fold_kfold_int64shift, + fold_kfold_bnot64, + fold_kfold_bswap64, + fold_kfold_int64comp, + fold_kfold_int64comp0, + fold_kfold_snew_kptr, + fold_kfold_snew_empty, + fold_kfold_strref, + fold_kfold_strref_snew, + fold_kfold_strcmp, + fold_kfold_add_kgc, + fold_kfold_add_kptr, + fold_kfold_add_kright, + fold_kfold_tobit, + fold_kfold_conv_kint_num, + fold_kfold_conv_kintu32_num, + fold_kfold_conv_kint_ext, + fold_kfold_conv_kint_i64, + fold_kfold_conv_kint64_num_i64, + fold_kfold_conv_kint64_num_u64, + fold_kfold_conv_kint64_int_i64, + fold_kfold_conv_knum_int_num, + fold_kfold_conv_knum_u32_num, + fold_kfold_conv_knum_i64_num, + fold_kfold_conv_knum_u64_num, + fold_kfold_tostr_knum, + fold_kfold_tostr_kint, + fold_kfold_strto, + lj_opt_cse, + fold_kfold_kref, + fold_shortcut_round, + fold_shortcut_left, + fold_shortcut_dropleft, + fold_shortcut_leftleft, + fold_simplify_numadd_negx, + fold_simplify_numadd_xneg, + fold_simplify_numsub_k, + fold_simplify_numsub_negk, + fold_simplify_numsub_xneg, + fold_simplify_nummuldiv_k, + fold_simplify_nummuldiv_negk, + fold_simplify_nummuldiv_negneg, + fold_simplify_numpow_xk, + fold_simplify_numpow_kx, + fold_shortcut_conv_num_int, + fold_simplify_conv_int_num, + fold_simplify_conv_i64_num, + fold_simplify_conv_int_i64, + fold_simplify_conv_flt_num, + fold_simplify_tobit_conv, + fold_simplify_floor_conv, + fold_simplify_conv_sext, + fold_simplify_conv_narrow, + fold_cse_conv, + fold_narrow_convert, + fold_simplify_intadd_k, + fold_simplify_intmul_k, + fold_simplify_intsub_k, + fold_simplify_intsub_kleft, + fold_simplify_intadd_k64, + fold_simplify_intsub_k64, + fold_simplify_intmul_k32, + fold_simplify_intmul_k64, + fold_simplify_intmod_k, + fold_simplify_intmod_kleft, + fold_simplify_intsub, + fold_simplify_intsubadd_leftcancel, + fold_simplify_intsubsub_leftcancel, + fold_simplify_intsubsub_rightcancel, + fold_simplify_intsubadd_rightcancel, + fold_simplify_intsubaddadd_cancel, + fold_simplify_band_k, + fold_simplify_bor_k, + fold_simplify_bxor_k, + fold_simplify_shift_ik, + fold_simplify_shift_andk, + fold_simplify_shift1_ki, + fold_simplify_shift2_ki, + fold_simplify_shiftk_andk, + fold_simplify_andk_shiftk, + fold_reassoc_intarith_k, + fold_reassoc_intarith_k64, + fold_reassoc_dup, + fold_reassoc_bxor, + fold_reassoc_shift, + fold_reassoc_minmax_k, + fold_reassoc_minmax_left, + fold_reassoc_minmax_right, + fold_abc_fwd, + fold_abc_k, + fold_abc_invar, + fold_comm_swap, + fold_comm_equal, + fold_comm_comp, + fold_comm_dup, + fold_comm_bxor, + fold_merge_eqne_snew_kgc, + lj_opt_fwd_aload, + fold_kfold_hload_kkptr, + lj_opt_fwd_hload, + lj_opt_fwd_uload, + lj_opt_fwd_tab_len, + fold_cse_uref, + lj_opt_fwd_hrefk, + fold_fwd_href_tnew, + fold_fwd_href_tdup, + fold_fload_tab_tnew_asize, + fold_fload_tab_tnew_hmask, + fold_fload_tab_tdup_asize, + fold_fload_tab_tdup_hmask, + fold_fload_tab_ah, + fold_fload_str_len_kgc, + fold_fload_str_len_snew, + fold_fload_cdata_typeid_kgc, + fold_fload_cdata_int64_kgc, + fold_fload_cdata_typeid_cnew, + fold_fload_cdata_ptr_int64_cnew, + lj_opt_cse, + lj_opt_fwd_fload, + fold_fwd_sload, + fold_xload_kptr, + lj_opt_fwd_xload, + fold_barrier_tab, + fold_barrier_tnew_tdup, + lj_opt_dse_ahstore, + lj_opt_dse_ustore, + lj_opt_dse_fstore, + lj_opt_dse_xstore, + lj_ir_emit +}; + +static const uint32_t fold_hash[916] = { +0xffffffff, +0xffffffff, +0x5b4c8016, +0x0d4e7016, +0xffffffff, +0x1000701c, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x29110c1a, +0xffffffff, +0xffffffff, +0x5b488016, +0x0d4a7016, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x7b87fc07, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x0d467016, +0xffffffff, +0x5a4c73ff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x5153fc29, +0xffffffff, +0xffffffff, +0xffffffff, +0x5d408016, +0xffffffff, +0x594873ff, +0x8187440f, +0xffffffff, +0xffffffff, +0xffffffff, +0x8287fc0f, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6715ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a11fc1a, +0xffffffff, +0x1daa5a70, +0xffffffff, +0xffffffff, +0x0a0bfc16, +0x5c408c16, +0x6911ffff, +0x8db7ffff, +0xffffffff, +0xffffffff, +0x1caa59d4, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6a0dffff, +0x2b68d002, +0xffffffff, +0x3cab5695, +0xffffffff, +0x41aaa675, +0xffffffff, +0xffffffff, +0xffffffff, +0x27ae5800, +0xffffffff, +0x6a09ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x7f865c0f, +0xffffffff, +0xffffffff, +0xffffffff, +0x6a05ffff, +0x42abffff, +0x5e44881c, +0x5d50a016, +0x066c5816, +0x00646c1b, +0x75753bff, +0x1951fc18, +0x6264c81b, +0x1850641c, +0xffffffff, +0x6a01ffff, +0x87a7ffff, +0x4953fc1c, +0x8da80000, +0x4f52a3ff, +0x00606c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0x5d428416, +0x88a53800, +0xffffffff, +0xffffffff, +0xffffffff, +0x05645816, +0xffffffff, +0x005c6c1b, +0x20aa71d6, +0xffffffff, +0xffffffff, +0xffffffff, +0x1399fc16, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x157f33ff, +0xffffffff, +0xffffffff, +0x584dfc20, +0xffffffff, +0xffffffff, +0xffffffff, +0x8d9bffff, +0xffffffff, +0x055c5816, +0xffffffff, +0x00546c1b, +0xffffffff, +0xffffffff, +0x5849fc20, +0xffffffff, +0xffffffff, +0xffffffff, +0x8c97ffff, +0x5543fc1c, +0x05585816, +0xffffffff, +0x00506c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x8a93ffff, +0x26ae6c00, +0x05545816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x76753c17, +0x41aaa695, +0xffffffff, +0x898fffff, +0xffffffff, +0x05505816, +0xffffffff, +0xffffffff, +0xffffffff, +0x858867ff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x848bffff, +0xffffffff, +0x054c5816, +0x79873c06, +0x47525bff, +0xffffffff, +0x3f695401, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x8387ffff, +0xffffffff, +0x05485816, +0xffffffff, +0x5a4e5bff, +0xffffffff, +0xffffffff, +0x6264c816, +0x43aaa26e, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x05445816, +0xffffffff, +0x5a4a5bff, +0xffffffff, +0xffffffff, +0xffffffff, +0x3455fc1b, +0x0c5a701c, +0x6366cbff, +0x0e3c7000, +0xffffffff, +0x05405816, +0xffffffff, +0x59465bff, +0xffffffff, +0xffffffff, +0xffffffff, +0x41aaa276, +0x0c56701c, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x21aa7275, +0x0b52701c, +0x61489016, +0x6465fc33, +0x8d77ffff, +0xffffffff, +0x7b87fc05, +0xffffffff, +0xffffffff, +0x2a126bff, +0x385a6fff, +0xffffffff, +0x446dfc16, +0xffffffff, +0x7473ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x7d873000, +0xffffffff, +0x5c409016, +0x686fffff, +0x8187440d, +0xffffffff, +0xffffffff, +0x3554b81b, +0x8287fc0d, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x686bffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x8d9ffc00, +0x737a5fff, +0x41aaaa75, +0xffffffff, +0xffffffff, +0x5e40801c, +0x0b42701c, +0x6b67ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2b68d000, +0xffffffff, +0xffffffff, +0x6d133017, +0xffffffff, +0xffffffff, +0x4c59fc16, +0xffffffff, +0xffffffff, +0x110bfc1c, +0x3aab566e, +0xffffffff, +0x5052a7ff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6515fc28, +0x4a55fc16, +0x7f865c0d, +0x88a53c00, +0x41aaa296, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x4451fc16, +0xffffffff, +0x60448bff, +0x21aa7295, +0xffffffff, +0x3cab5676, +0x04106c1b, +0xffffffff, +0x78873807, +0xffffffff, +0xffffffff, +0x574dfc16, +0xffffffff, +0x4e53ffff, +0xffffffff, +0x09145816, +0xffffffff, +0x040c6c1b, +0x8287fc00, +0x5e50a01c, +0x6467fc32, +0xffffffff, +0x5749fc16, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a105816, +0x2e3e7c00, +0x04086c1b, +0x7083fc00, +0xffffffff, +0xffffffff, +0xffffffff, +0x5645fc16, +0xffffffff, +0x22aa6e6e, +0x5e42841c, +0x614e9c16, +0x090c5816, +0x04046c1b, +0x1eaa5ab3, +0xffffffff, +0xffffffff, +0xffffffff, +0x5441fc16, +0x41aaaa95, +0xffffffff, +0x5352a028, +0x09085816, +0x17505c16, +0x04006c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6b43ffff, +0xffffffff, +0x09045816, +0xffffffff, +0x43aaa2ae, +0xffffffff, +0xffffffff, +0xffffffff, +0x083e5800, +0x7c865c00, +0xffffffff, +0x76753c15, +0x3051fc2e, +0x09005816, +0xffffffff, +0xffffffff, +0xffffffff, +0x3aab568e, +0xffffffff, +0x43aaa66e, +0xffffffff, +0x1daa5a71, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a12701c, +0x5f66cfff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x3cab5696, +0xffffffff, +0x100e701c, +0x41aaa676, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a125c17, +0x3654b82e, +0x100a701c, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x1006701c, +0xffffffff, +0x1951fc19, +0xffffffff, +0xffffffff, +0xffffffff, +0x23aa6e8e, +0xffffffff, +0x5b4e8016, +0xffffffff, +0x1eaa5ad3, +0x1002701c, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x29130c1a, +0xffffffff, +0xffffffff, +0x0d4c7016, +0xffffffff, +0x475273ff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x5b468016, +0x0d487016, +0x5a4e73ff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x5d54a816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x5a4a73ff, +0x6615fc16, +0x3bab56ae, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x594673ff, +0xffffffff, +0x61468c16, +0x8d17ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a13fc1a, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6913ffff, +0x40abfeb3, +0x8db9ffff, +0x41aaa696, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6a0fffff, +0x8db5ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x7a873c07, +0xffffffff, +0xffffffff, +0xffffffff, +0x6a0bffff, +0x3f695402, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x24aa6eae, +0xffffffff, +0xffffffff, +0x6a07ffff, +0xffffffff, +0xffffffff, +0x066e5816, +0xffffffff, +0x00666c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6a03ffff, +0xffffffff, +0x4b55fc1c, +0x066a5816, +0xffffffff, +0x00626c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x4851fc1c, +0x05665816, +0x18506016, +0x005e6c1b, +0x12986416, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x8da1ffff, +0xffffffff, +0x3bab56ce, +0xffffffff, +0x43aaa6ae, +0xffffffff, +0xffffffff, +0x584ffc20, +0x7b87fc06, +0xffffffff, +0x5f4287ff, +0x8d9dffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x00566c1b, +0xffffffff, +0xffffffff, +0x584bfc20, +0x5253fc28, +0xffffffff, +0xffffffff, +0xffffffff, +0x5645fc1c, +0xffffffff, +0x40abfed3, +0x00526c1b, +0x8187440e, +0xffffffff, +0x5847fc20, +0x8287fc0e, +0xffffffff, +0xffffffff, +0x8b95ffff, +0x2e3c7800, +0x5441fc1c, +0xffffffff, +0xffffffff, +0xffffffff, +0x17505c1c, +0xffffffff, +0xffffffff, +0x41aaaa76, +0xffffffff, +0x614c9816, +0x8991ffff, +0x1daa5a6f, +0x05525816, +0x4d585bff, +0xffffffff, +0x8087400c, +0xffffffff, +0xffffffff, +0xffffffff, +0x1baa59d3, +0x828dffff, +0x25aa6ece, +0x054e5816, +0x76753c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0x2b68d001, +0xffffffff, +0xffffffff, +0xffffffff, +0x8689ffff, +0xffffffff, +0x054a5816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x43aca01b, +0x05465816, +0x7f865c0e, +0x5a4c5bff, +0x39ab55d3, +0x01626c16, +0x02686fff, +0x3457fc1b, +0xffffffff, +0xffffffff, +0x0f3e7000, +0x3dab55ae, +0x05425816, +0x1951fc17, +0x59485bff, +0xffffffff, +0xffffffff, +0xffffffff, +0x3153fc1b, +0x0c58701c, +0x5f64cbff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x035a6c16, +0xffffffff, +0xffffffff, +0xffffffff, +0x0b54701c, +0xffffffff, +0x8779ffff, +0x1faa71d5, +0xffffffff, +0xffffffff, +0x2d5eb81b, +0x72b5fc08, +0xffffffff, +0xffffffff, +0xffffffff, +0x0b50701c, +0x456ffc16, +0x7b75ffff, +0xffffffff, +0xffffffff, +0x147e5c16, +0xffffffff, +0xffffffff, +0x2a106bff, +0xffffffff, +0x1eaa5ab4, +0x446bfc16, +0xffffffff, +0xffffffff, +0xffffffff, +0x41aaaa96, +0xffffffff, +0x3556b81b, +0x87a5fc00, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x4e6dffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x3252b81b, +0xffffffff, +0x5e54a81c, +0xffffffff, +0xffffffff, +0x0b44701c, +0x28b05c00, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x73785fff, +0xffffffff, +0xffffffff, +0xffffffff, +0x0b40701c, +0xffffffff, +0x6b65ffff, +0xffffffff, +0xffffffff, +0x1daa5a72, +0xffffffff, +0xffffffff, +0xffffffff, +0x6266cc1b, +0xffffffff, +0x375bfc16, +0xffffffff, +0xffffffff, +0xffffffff, +0x3f695400, +0xffffffff, +0xffffffff, +0xffffffff, +0x6d113017, +0x3ead541b, +0xffffffff, +0x5d448816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x18506416, +0xffffffff, +0xffffffff, +0x16b37400, +0xffffffff, +0x4653fc16, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x04126c1b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x574ffc16, +0xffffffff, +0x6855ffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x040e6c1b, +0x41aaa275, +0xffffffff, +0xffffffff, +0xffffffff, +0x574bfc16, +0x6f826400, +0x6851ffff, +0x1eaa5ad4, +0x2a125816, +0xffffffff, +0x040a6c1b, +0x7185fc00, +0xffffffff, +0xffffffff, +0xffffffff, +0x5747fc16, +0x7b87fc04, +0xffffffff, +0xffffffff, +0x090e5816, +0xffffffff, +0x04066c1b, +0x6e81fc00, +0x1aac6c1b, +0x1850601c, +0x2e5cbbff, +0x5543fc16, +0xffffffff, +0xffffffff, +0xffffffff, +0x090a5816, +0xffffffff, +0x04026c1b, +0xffffffff, +0xffffffff, +0x8087440c, +0xffffffff, +0xffffffff, +0xffffffff, +0x6c45ffff, +0x8287fc0c, +0x09065816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x6b41ffff, +0x3353fc2e, +0x09025816, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2f50bbff, +0x073c5800, +0x6266cc16, +0x5f4083ff, +0xffffffff, +0xffffffff, +0x43aca41b, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2a10701c, +0x6364cfff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x7e865c0c, +0xffffffff, +0xffffffff, +0x3656b82e, +0x41aaa295, +0x100c701c, +0x614a9416, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x2c5ebc1b, +0xffffffff, +0x2a105c17, +0xffffffff, +0x1008701c, +0x3cab5675, +0xffffffff, +0xffffffff, +0x77873806, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0x1004701c, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff, +0xffffffff +}; + +#define fold_hashkey(k) (lj_rol(lj_rol((k),17)-(k),16)%915) + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_frame.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_frame.h new file mode 100644 index 0000000..fb533b0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_frame.h @@ -0,0 +1,183 @@ +/* +** Stack frames. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FRAME_H +#define _LJ_FRAME_H + +#include "lj_obj.h" +#include "lj_bc.h" + +/* -- Lua stack frame ----------------------------------------------------- */ + +/* Frame type markers in callee function slot (callee base-1). */ +enum { + FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG, + FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH +}; +#define FRAME_TYPE 3 +#define FRAME_P 4 +#define FRAME_TYPEP (FRAME_TYPE|FRAME_P) + +/* Macros to access and modify Lua frames. */ +#define frame_gc(f) (gcref((f)->fr.func)) +#define frame_func(f) (&frame_gc(f)->fn) +#define frame_ftsz(f) ((f)->fr.tp.ftsz) + +#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE) +#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP) +#define frame_islua(f) (frame_type(f) == FRAME_LUA) +#define frame_isc(f) (frame_type(f) == FRAME_C) +#define frame_iscont(f) (frame_typep(f) == FRAME_CONT) +#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG) +#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL) + +#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns)) +#define frame_contpc(f) (frame_pc((f)-1)) +#if LJ_64 +#define frame_contf(f) \ + ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \ + (intptr_t)(int32_t)((f)-1)->u32.lo)) +#else +#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void)) +#endif +#define frame_delta(f) (frame_ftsz(f) >> 3) +#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP) + +#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1]))) +#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f))) +#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f)) +/* Note: this macro does not skip over FRAME_VARG. */ + +#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc))) +#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz)) +#define setframe_gc(f, p) (setgcref((f)->fr.func, (p))) + +/* -- C stack frame ------------------------------------------------------- */ + +/* Macros to access and modify the C stack frame chain. */ + +/* These definitions must match with the arch-specific *.dasc files. */ +#if LJ_TARGET_X86 +#define CFRAME_OFS_ERRF (15*4) +#define CFRAME_OFS_NRES (14*4) +#define CFRAME_OFS_PREV (13*4) +#define CFRAME_OFS_L (12*4) +#define CFRAME_OFS_PC (6*4) +#define CFRAME_OFS_MULTRES (5*4) +#define CFRAME_SIZE (12*4) +#define CFRAME_SHIFT_MULTRES 0 +#elif LJ_TARGET_X64 +#if LJ_ABI_WIN +#define CFRAME_OFS_PREV (13*8) +#define CFRAME_OFS_PC (25*4) +#define CFRAME_OFS_L (24*4) +#define CFRAME_OFS_ERRF (23*4) +#define CFRAME_OFS_NRES (22*4) +#define CFRAME_OFS_MULTRES (21*4) +#define CFRAME_SIZE (10*8) +#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8) +#define CFRAME_SHIFT_MULTRES 0 +#else +#define CFRAME_OFS_PREV (4*8) +#define CFRAME_OFS_PC (7*4) +#define CFRAME_OFS_L (6*4) +#define CFRAME_OFS_ERRF (5*4) +#define CFRAME_OFS_NRES (4*4) +#define CFRAME_OFS_MULTRES (1*4) +#define CFRAME_SIZE (10*8) +#define CFRAME_SIZE_JIT (CFRAME_SIZE + 16) +#define CFRAME_SHIFT_MULTRES 0 +#endif +#elif LJ_TARGET_ARM +#define CFRAME_OFS_ERRF 24 +#define CFRAME_OFS_NRES 20 +#define CFRAME_OFS_PREV 16 +#define CFRAME_OFS_L 12 +#define CFRAME_OFS_PC 8 +#define CFRAME_OFS_MULTRES 4 +#if LJ_ARCH_HASFPU +#define CFRAME_SIZE 128 +#else +#define CFRAME_SIZE 64 +#endif +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_TARGET_PPC +#if LJ_TARGET_XBOX360 +#define CFRAME_OFS_ERRF 424 +#define CFRAME_OFS_NRES 420 +#define CFRAME_OFS_PREV 400 +#define CFRAME_OFS_L 416 +#define CFRAME_OFS_PC 412 +#define CFRAME_OFS_MULTRES 408 +#define CFRAME_SIZE 384 +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_ARCH_PPC64 +#define CFRAME_OFS_ERRF 472 +#define CFRAME_OFS_NRES 468 +#define CFRAME_OFS_PREV 448 +#define CFRAME_OFS_L 464 +#define CFRAME_OFS_PC 460 +#define CFRAME_OFS_MULTRES 456 +#define CFRAME_SIZE 400 +#define CFRAME_SHIFT_MULTRES 3 +#else +#define CFRAME_OFS_ERRF 48 +#define CFRAME_OFS_NRES 44 +#define CFRAME_OFS_PREV 40 +#define CFRAME_OFS_L 36 +#define CFRAME_OFS_PC 32 +#define CFRAME_OFS_MULTRES 28 +#define CFRAME_SIZE 272 +#define CFRAME_SHIFT_MULTRES 3 +#endif +#elif LJ_TARGET_PPCSPE +#define CFRAME_OFS_ERRF 28 +#define CFRAME_OFS_NRES 24 +#define CFRAME_OFS_PREV 20 +#define CFRAME_OFS_L 16 +#define CFRAME_OFS_PC 12 +#define CFRAME_OFS_MULTRES 8 +#define CFRAME_SIZE 184 +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_TARGET_MIPS +#define CFRAME_OFS_ERRF 124 +#define CFRAME_OFS_NRES 120 +#define CFRAME_OFS_PREV 116 +#define CFRAME_OFS_L 112 +#define CFRAME_OFS_PC 20 +#define CFRAME_OFS_MULTRES 16 +#define CFRAME_SIZE 112 +#define CFRAME_SHIFT_MULTRES 3 +#else +#error "Missing CFRAME_* definitions for this architecture" +#endif + +#ifndef CFRAME_SIZE_JIT +#define CFRAME_SIZE_JIT CFRAME_SIZE +#endif + +#define CFRAME_RESUME 1 +#define CFRAME_UNWIND_FF 2 /* Only used in unwinder. */ +#define CFRAME_RAWMASK (~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF)) + +#define cframe_errfunc(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF)) +#define cframe_nres(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES)) +#define cframe_prev(cf) (*(void **)(((char *)(cf))+CFRAME_OFS_PREV)) +#define cframe_multres(cf) (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES)) +#define cframe_multres_n(cf) (cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES) +#define cframe_L(cf) \ + (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th) +#define cframe_pc(cf) \ + (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns)) +#define setcframe_L(cf, L) \ + (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L))) +#define setcframe_pc(cf, pc) \ + (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc))) +#define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_RESUME) +#define cframe_unwind_ff(cf) ((intptr_t)(cf) & CFRAME_UNWIND_FF) +#define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK)) +#define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe)) + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.c new file mode 100644 index 0000000..9a59b0f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.c @@ -0,0 +1,185 @@ +/* +** Function handling (prototypes, functions and upvalues). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_func_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_func.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* -- Prototypes ---------------------------------------------------------- */ + +void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt) +{ + lj_mem_free(g, pt, pt->sizept); +} + +/* -- Upvalues ------------------------------------------------------------ */ + +static void unlinkuv(GCupval *uv) +{ + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + setgcrefr(uvnext(uv)->prev, uv->prev); + setgcrefr(uvprev(uv)->next, uv->next); +} + +/* Find existing open upvalue for a stack slot or create a new one. */ +static GCupval *func_finduv(lua_State *L, TValue *slot) +{ + global_State *g = G(L); + GCRef *pp = &L->openupval; + GCupval *p; + GCupval *uv; + /* Search the sorted list of open upvalues. */ + while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) { + lua_assert(!p->closed && uvval(p) != &p->tv); + if (uvval(p) == slot) { /* Found open upvalue pointing to same slot? */ + if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */ + flipwhite(obj2gco(p)); + return p; + } + pp = &p->nextgc; + } + /* No matching upvalue found. Create a new one. */ + uv = lj_mem_newt(L, sizeof(GCupval), GCupval); + newwhite(g, uv); + uv->gct = ~LJ_TUPVAL; + uv->closed = 0; /* Still open. */ + setmref(uv->v, slot); /* Pointing to the stack slot. */ + /* NOBARRIER: The GCupval is new (marked white) and open. */ + setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */ + setgcref(*pp, obj2gco(uv)); + setgcref(uv->prev, obj2gco(&g->uvhead)); /* Insert into GC list, too. */ + setgcrefr(uv->next, g->uvhead.next); + setgcref(uvnext(uv)->prev, obj2gco(uv)); + setgcref(g->uvhead.next, obj2gco(uv)); + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + return uv; +} + +/* Create an empty and closed upvalue. */ +static GCupval *func_emptyuv(lua_State *L) +{ + GCupval *uv = (GCupval *)lj_mem_newgco(L, sizeof(GCupval)); + uv->gct = ~LJ_TUPVAL; + uv->closed = 1; + setnilV(&uv->tv); + setmref(uv->v, &uv->tv); + return uv; +} + +/* Close all open upvalues pointing to some stack level or above. */ +void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level) +{ + GCupval *uv; + global_State *g = G(L); + while (gcref(L->openupval) != NULL && + uvval((uv = gco2uv(gcref(L->openupval)))) >= level) { + GCobj *o = obj2gco(uv); + lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv); + setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */ + if (isdead(g, o)) { + lj_func_freeuv(g, uv); + } else { + unlinkuv(uv); + lj_gc_closeuv(g, uv); + } + } +} + +void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv) +{ + if (!uv->closed) + unlinkuv(uv); + lj_mem_freet(g, uv); +} + +/* -- Functions (closures) ------------------------------------------------ */ + +GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env) +{ + GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeCfunc(nelems)); + fn->c.gct = ~LJ_TFUNC; + fn->c.ffid = FF_C; + fn->c.nupvalues = (uint8_t)nelems; + /* NOBARRIER: The GCfunc is new (marked white). */ + setmref(fn->c.pc, &G(L)->bc_cfunc_ext); + setgcref(fn->c.env, obj2gco(env)); + return fn; +} + +static GCfunc *func_newL(lua_State *L, GCproto *pt, GCtab *env) +{ + uint32_t count; + GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeLfunc((MSize)pt->sizeuv)); + fn->l.gct = ~LJ_TFUNC; + fn->l.ffid = FF_LUA; + fn->l.nupvalues = 0; /* Set to zero until upvalues are initialized. */ + /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */ + setmref(fn->l.pc, proto_bc(pt)); + setgcref(fn->l.env, obj2gco(env)); + /* Saturating 3 bit counter (0..7) for created closures. */ + count = (uint32_t)pt->flags + PROTO_CLCOUNT; + pt->flags = (uint8_t)(count - ((count >> PROTO_CLC_BITS) & PROTO_CLCOUNT)); + return fn; +} + +/* Create a new Lua function with empty upvalues. */ +GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env) +{ + GCfunc *fn = func_newL(L, pt, env); + MSize i, nuv = pt->sizeuv; + /* NOBARRIER: The GCfunc is new (marked white). */ + for (i = 0; i < nuv; i++) { + GCupval *uv = func_emptyuv(L); + uv->dhash = (uint32_t)(uintptr_t)pt ^ ((uint32_t)proto_uv(pt)[i] << 24); + setgcref(fn->l.uvptr[i], obj2gco(uv)); + } + fn->l.nupvalues = (uint8_t)nuv; + return fn; +} + +/* Do a GC check and create a new Lua function with inherited upvalues. */ +GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent) +{ + GCfunc *fn; + GCRef *puv; + MSize i, nuv; + TValue *base; + lj_gc_check_fixtop(L); + fn = func_newL(L, pt, tabref(parent->env)); + /* NOBARRIER: The GCfunc is new (marked white). */ + puv = parent->uvptr; + nuv = pt->sizeuv; + base = L->base; + for (i = 0; i < nuv; i++) { + uint32_t v = proto_uv(pt)[i]; + GCupval *uv; + if ((v & PROTO_UV_LOCAL)) { + uv = func_finduv(L, base + (v & 0xff)); + uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1); + uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24); + } else { + uv = &gcref(puv[v])->uv; + } + setgcref(fn->l.uvptr[i], obj2gco(uv)); + } + fn->l.nupvalues = (uint8_t)nuv; + return fn; +} + +void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *fn) +{ + MSize size = isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) : + sizeCfunc((MSize)fn->c.nupvalues); + lj_mem_free(g, fn, size); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.h new file mode 100644 index 0000000..88732e8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_func.h @@ -0,0 +1,24 @@ +/* +** Function handling (prototypes, functions and upvalues). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FUNC_H +#define _LJ_FUNC_H + +#include "lj_obj.h" + +/* Prototypes. */ +LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt); + +/* Upvalues. */ +LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level); +LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv); + +/* Functions (closures). */ +LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env); +LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env); +LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent); +LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.c new file mode 100644 index 0000000..c2bc397 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.c @@ -0,0 +1,849 @@ +/* +** Garbage collector. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_gc_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_udata.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#endif +#include "lj_trace.h" +#include "lj_vm.h" + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + +/* Macros to set GCobj colors and flags. */ +#define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES) +#define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK) +#define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED) + +/* -- Mark phase ---------------------------------------------------------- */ + +/* Mark a TValue (if needed). */ +#define gc_marktv(g, tv) \ + { lua_assert(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct)); \ + if (tviswhite(tv)) gc_mark(g, gcV(tv)); } + +/* Mark a GCobj (if needed). */ +#define gc_markobj(g, o) \ + { if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); } + +/* Mark a string object. */ +#define gc_mark_str(s) ((s)->marked &= (uint8_t)~LJ_GC_WHITES) + +/* Mark a white GCobj. */ +static void gc_mark(global_State *g, GCobj *o) +{ + int gct = o->gch.gct; + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) { + GCtab *mt = tabref(gco2ud(o)->metatable); + gray2black(o); /* Userdata are never gray. */ + if (mt) gc_markobj(g, mt); + gc_markobj(g, tabref(gco2ud(o)->env)); + } else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) { + GCupval *uv = gco2uv(o); + gc_marktv(g, uvval(uv)); + if (uv->closed) + gray2black(o); /* Closed upvalues are never gray. */ + } else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) { + lua_assert(gct == ~LJ_TFUNC || gct == ~LJ_TTAB || + gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO); + setgcrefr(o->gch.gclist, g->gc.gray); + setgcref(g->gc.gray, o); + } +} + +/* Mark GC roots. */ +static void gc_mark_gcroot(global_State *g) +{ + ptrdiff_t i; + for (i = 0; i < GCROOT_MAX; i++) + if (gcref(g->gcroot[i]) != NULL) + gc_markobj(g, gcref(g->gcroot[i])); +} + +/* Start a GC cycle and mark the root set. */ +static void gc_mark_start(global_State *g) +{ + setgcrefnull(g->gc.gray); + setgcrefnull(g->gc.grayagain); + setgcrefnull(g->gc.weak); + gc_markobj(g, mainthread(g)); + gc_markobj(g, tabref(mainthread(g)->env)); + gc_marktv(g, &g->registrytv); + gc_mark_gcroot(g); + g->gc.state = GCSpropagate; +} + +/* Mark open upvalues. */ +static void gc_mark_uv(global_State *g) +{ + GCupval *uv; + for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) { + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + if (isgray(obj2gco(uv))) + gc_marktv(g, uvval(uv)); + } +} + +/* Mark userdata in mmudata list. */ +static void gc_mark_mmudata(global_State *g) +{ + GCobj *root = gcref(g->gc.mmudata); + GCobj *u = root; + if (u) { + do { + u = gcnext(u); + makewhite(g, u); /* Could be from previous GC. */ + gc_mark(g, u); + } while (u != root); + } +} + +/* Separate userdata objects to be finalized to mmudata list. */ +size_t lj_gc_separateudata(global_State *g, int all) +{ + size_t m = 0; + GCRef *p = &mainthread(g)->nextgc; + GCobj *o; + while ((o = gcref(*p)) != NULL) { + if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) { + p = &o->gch.nextgc; /* Nothing to do. */ + } else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) { + markfinalized(o); /* Done, as there's no __gc metamethod. */ + p = &o->gch.nextgc; + } else { /* Otherwise move userdata to be finalized to mmudata list. */ + m += sizeudata(gco2ud(o)); + markfinalized(o); + *p = o->gch.nextgc; + if (gcref(g->gc.mmudata)) { /* Link to end of mmudata list. */ + GCobj *root = gcref(g->gc.mmudata); + setgcrefr(o->gch.nextgc, root->gch.nextgc); + setgcref(root->gch.nextgc, o); + setgcref(g->gc.mmudata, o); + } else { /* Create circular list. */ + setgcref(o->gch.nextgc, o); + setgcref(g->gc.mmudata, o); + } + } + } + return m; +} + +/* -- Propagation phase --------------------------------------------------- */ + +/* Traverse a table. */ +static int gc_traverse_tab(global_State *g, GCtab *t) +{ + int weak = 0; + cTValue *mode; + GCtab *mt = tabref(t->metatable); + if (mt) + gc_markobj(g, mt); + mode = lj_meta_fastg(g, mt, MM_mode); + if (mode && tvisstr(mode)) { /* Valid __mode field? */ + const char *modestr = strVdata(mode); + int c; + while ((c = *modestr++)) { + if (c == 'k') weak |= LJ_GC_WEAKKEY; + else if (c == 'v') weak |= LJ_GC_WEAKVAL; + else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL); + } + if (weak > 0) { /* Weak tables are cleared in the atomic phase. */ + t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); + setgcrefr(t->gclist, g->gc.weak); + setgcref(g->gc.weak, obj2gco(t)); + } + } + if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */ + return 1; + if (!(weak & LJ_GC_WEAKVAL)) { /* Mark array part. */ + MSize i, asize = t->asize; + for (i = 0; i < asize; i++) + gc_marktv(g, arrayslot(t, i)); + } + if (t->hmask > 0) { /* Mark hash part. */ + Node *node = noderef(t->node); + MSize i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (!tvisnil(&n->val)) { /* Mark non-empty slot. */ + lua_assert(!tvisnil(&n->key)); + if (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key); + if (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val); + } + } + } + return weak; +} + +/* Traverse a function. */ +static void gc_traverse_func(global_State *g, GCfunc *fn) +{ + gc_markobj(g, tabref(fn->c.env)); + if (isluafunc(fn)) { + uint32_t i; + lua_assert(fn->l.nupvalues <= funcproto(fn)->sizeuv); + gc_markobj(g, funcproto(fn)); + for (i = 0; i < fn->l.nupvalues; i++) /* Mark Lua function upvalues. */ + gc_markobj(g, &gcref(fn->l.uvptr[i])->uv); + } else { + uint32_t i; + for (i = 0; i < fn->c.nupvalues; i++) /* Mark C function upvalues. */ + gc_marktv(g, &fn->c.upvalue[i]); + } +} + +#if LJ_HASJIT +/* Mark a trace. */ +static void gc_marktrace(global_State *g, TraceNo traceno) +{ + GCobj *o = obj2gco(traceref(G2J(g), traceno)); + lua_assert(traceno != G2J(g)->cur.traceno); + if (iswhite(o)) { + white2gray(o); + setgcrefr(o->gch.gclist, g->gc.gray); + setgcref(g->gc.gray, o); + } +} + +/* Traverse a trace. */ +static void gc_traverse_trace(global_State *g, GCtrace *T) +{ + IRRef ref; + if (T->traceno == 0) return; + for (ref = T->nk; ref < REF_TRUE; ref++) { + IRIns *ir = &T->ir[ref]; + if (ir->o == IR_KGC) + gc_markobj(g, ir_kgc(ir)); + } + if (T->link) gc_marktrace(g, T->link); + if (T->nextroot) gc_marktrace(g, T->nextroot); + if (T->nextside) gc_marktrace(g, T->nextside); + gc_markobj(g, gcref(T->startpt)); +} + +/* The current trace is a GC root while not anchored in the prototype (yet). */ +#define gc_traverse_curtrace(g) gc_traverse_trace(g, &G2J(g)->cur) +#else +#define gc_traverse_curtrace(g) UNUSED(g) +#endif + +/* Traverse a prototype. */ +static void gc_traverse_proto(global_State *g, GCproto *pt) +{ + ptrdiff_t i; + gc_mark_str(proto_chunkname(pt)); + for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */ + gc_markobj(g, proto_kgc(pt, i)); +#if LJ_HASJIT + if (pt->trace) gc_marktrace(g, pt->trace); +#endif +} + +/* Traverse the frame structure of a stack. */ +static MSize gc_traverse_frames(global_State *g, lua_State *th) +{ + TValue *frame, *top = th->top-1, *bot = tvref(th->stack); + /* Note: extra vararg frame not skipped, marks function twice (harmless). */ + for (frame = th->base-1; frame > bot; frame = frame_prev(frame)) { + GCfunc *fn = frame_func(frame); + TValue *ftop = frame; + if (isluafunc(fn)) ftop += funcproto(fn)->framesize; + if (ftop > top) top = ftop; + gc_markobj(g, fn); /* Need to mark hidden function (or L). */ + } + top++; /* Correct bias of -1 (frame == base-1). */ + if (top > tvref(th->maxstack)) top = tvref(th->maxstack); + return (MSize)(top - bot); /* Return minimum needed stack size. */ +} + +/* Traverse a thread object. */ +static void gc_traverse_thread(global_State *g, lua_State *th) +{ + TValue *o, *top = th->top; + for (o = tvref(th->stack)+1; o < top; o++) + gc_marktv(g, o); + if (g->gc.state == GCSatomic) { + top = tvref(th->stack) + th->stacksize; + for (; o < top; o++) /* Clear unmarked slots. */ + setnilV(o); + } + gc_markobj(g, tabref(th->env)); + lj_state_shrinkstack(th, gc_traverse_frames(g, th)); +} + +/* Propagate one gray object. Traverse it and turn it black. */ +static size_t propagatemark(global_State *g) +{ + GCobj *o = gcref(g->gc.gray); + int gct = o->gch.gct; + lua_assert(isgray(o)); + gray2black(o); + setgcrefr(g->gc.gray, o->gch.gclist); /* Remove from gray list. */ + if (LJ_LIKELY(gct == ~LJ_TTAB)) { + GCtab *t = gco2tab(o); + if (gc_traverse_tab(g, t) > 0) + black2gray(o); /* Keep weak tables gray. */ + return sizeof(GCtab) + sizeof(TValue) * t->asize + + sizeof(Node) * (t->hmask + 1); + } else if (LJ_LIKELY(gct == ~LJ_TFUNC)) { + GCfunc *fn = gco2func(o); + gc_traverse_func(g, fn); + return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) : + sizeCfunc((MSize)fn->c.nupvalues); + } else if (LJ_LIKELY(gct == ~LJ_TPROTO)) { + GCproto *pt = gco2pt(o); + gc_traverse_proto(g, pt); + return pt->sizept; + } else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) { + lua_State *th = gco2th(o); + setgcrefr(th->gclist, g->gc.grayagain); + setgcref(g->gc.grayagain, o); + black2gray(o); /* Threads are never black. */ + gc_traverse_thread(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize; + } else { +#if LJ_HASJIT + GCtrace *T = gco2trace(o); + gc_traverse_trace(g, T); + return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) + + T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry); +#else + lua_assert(0); + return 0; +#endif + } +} + +/* Propagate all gray objects. */ +static size_t gc_propagate_gray(global_State *g) +{ + size_t m = 0; + while (gcref(g->gc.gray) != NULL) + m += propagatemark(g); + return m; +} + +/* -- Sweep phase --------------------------------------------------------- */ + +/* Try to shrink some common data structures. */ +static void gc_shrink(global_State *g, lua_State *L) +{ + if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1) + lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */ + if (g->tmpbuf.sz > LJ_MIN_SBUF*2) + lj_str_resizebuf(L, &g->tmpbuf, g->tmpbuf.sz >> 1); /* Shrink temp buf. */ +} + +/* Type of GC free functions. */ +typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o); + +/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */ +static const GCFreeFunc gc_freefunc[] = { + (GCFreeFunc)lj_str_free, + (GCFreeFunc)lj_func_freeuv, + (GCFreeFunc)lj_state_free, + (GCFreeFunc)lj_func_freeproto, + (GCFreeFunc)lj_func_free, +#if LJ_HASJIT + (GCFreeFunc)lj_trace_free, +#else + (GCFreeFunc)0, +#endif +#if LJ_HASFFI + (GCFreeFunc)lj_cdata_free, +#else + (GCFreeFunc)0, +#endif + (GCFreeFunc)lj_tab_free, + (GCFreeFunc)lj_udata_free +}; + +/* Full sweep of a GC list. */ +#define gc_fullsweep(g, p) gc_sweep(g, (p), LJ_MAX_MEM) + +/* Partial sweep of a GC list. */ +static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim) +{ + /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */ + int ow = otherwhite(g); + GCobj *o; + while ((o = gcref(*p)) != NULL && lim-- > 0) { + if (o->gch.gct == ~LJ_TTHREAD) /* Need to sweep open upvalues, too. */ + gc_fullsweep(g, &gco2th(o)->openupval); + if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) { /* Black or current white? */ + lua_assert(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED)); + makewhite(g, o); /* Value is alive, change to the current white. */ + p = &o->gch.nextgc; + } else { /* Otherwise value is dead, free it. */ + lua_assert(isdead(g, o) || ow == LJ_GC_SFIXED); + setgcrefr(*p, o->gch.nextgc); + if (o == gcref(g->gc.root)) + setgcrefr(g->gc.root, o->gch.nextgc); /* Adjust list anchor. */ + gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o); + } + } + return p; +} + +/* Check whether we can clear a key or a value slot from a table. */ +static int gc_mayclear(cTValue *o, int val) +{ + if (tvisgcv(o)) { /* Only collectable objects can be weak references. */ + if (tvisstr(o)) { /* But strings cannot be used as weak references. */ + gc_mark_str(strV(o)); /* And need to be marked. */ + return 0; + } + if (iswhite(gcV(o))) + return 1; /* Object is about to be collected. */ + if (tvisudata(o) && val && isfinalized(udataV(o))) + return 1; /* Finalized userdata is dropped only from values. */ + } + return 0; /* Cannot clear. */ +} + +/* Clear collected entries from weak tables. */ +static void gc_clearweak(GCobj *o) +{ + while (o) { + GCtab *t = gco2tab(o); + lua_assert((t->marked & LJ_GC_WEAK)); + if ((t->marked & LJ_GC_WEAKVAL)) { + MSize i, asize = t->asize; + for (i = 0; i < asize; i++) { + /* Clear array slot when value is about to be collected. */ + TValue *tv = arrayslot(t, i); + if (gc_mayclear(tv, 1)) + setnilV(tv); + } + } + if (t->hmask > 0) { + Node *node = noderef(t->node); + MSize i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + /* Clear hash slot when key or value is about to be collected. */ + if (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) || + gc_mayclear(&n->val, 1))) + setnilV(&n->val); + } + } + o = gcref(t->gclist); + } +} + +/* Call a userdata or cdata finalizer. */ +static void gc_call_finalizer(global_State *g, lua_State *L, + cTValue *mo, GCobj *o) +{ + /* Save and restore lots of state around the __gc callback. */ + uint8_t oldh = hook_save(g); + MSize oldt = g->gc.threshold; + int errcode; + TValue *top; + lj_trace_abort(g); + top = L->top; + L->top = top+2; + hook_entergc(g); /* Disable hooks and new traces during __gc. */ + g->gc.threshold = LJ_MAX_MEM; /* Prevent GC steps. */ + copyTV(L, top, mo); + setgcV(L, top+1, o, ~o->gch.gct); + errcode = lj_vm_pcall(L, top+1, 1+0, -1); /* Stack: |mo|o| -> | */ + hook_restore(g, oldh); + g->gc.threshold = oldt; /* Restore GC threshold. */ + if (errcode) + lj_err_throw(L, errcode); /* Propagate errors. */ +} + +/* Finalize one userdata or cdata object from the mmudata list. */ +static void gc_finalize(lua_State *L) +{ + global_State *g = G(L); + GCobj *o = gcnext(gcref(g->gc.mmudata)); + cTValue *mo; + lua_assert(gcref(g->jit_L) == NULL); /* Must not be called on trace. */ + /* Unchain from list of userdata to be finalized. */ + if (o == gcref(g->gc.mmudata)) + setgcrefnull(g->gc.mmudata); + else + setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc); +#if LJ_HASFFI + if (o->gch.gct == ~LJ_TCDATA) { + TValue tmp, *tv; + /* Add cdata back to the GC list and make it white. */ + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + makewhite(g, o); + o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN; + /* Resolve finalizer. */ + setcdataV(L, &tmp, gco2cd(o)); + tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp); + if (!tvisnil(tv)) { + g->gc.nocdatafin = 0; + copyTV(L, &tmp, tv); + setnilV(tv); /* Clear entry in finalizer table. */ + gc_call_finalizer(g, L, &tmp, o); + } + return; + } +#endif + /* Add userdata back to the main userdata list and make it white. */ + setgcrefr(o->gch.nextgc, mainthread(g)->nextgc); + setgcref(mainthread(g)->nextgc, o); + makewhite(g, o); + /* Resolve the __gc metamethod. */ + mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc); + if (mo) + gc_call_finalizer(g, L, mo, o); +} + +/* Finalize all userdata objects from mmudata list. */ +void lj_gc_finalize_udata(lua_State *L) +{ + while (gcref(G(L)->gc.mmudata) != NULL) + gc_finalize(L); +} + +#if LJ_HASFFI +/* Finalize all cdata objects from finalizer table. */ +void lj_gc_finalize_cdata(lua_State *L) +{ + global_State *g = G(L); + CTState *cts = ctype_ctsG(g); + if (cts) { + GCtab *t = cts->finalizer; + Node *node = noderef(t->node); + ptrdiff_t i; + setgcrefnull(t->metatable); /* Mark finalizer table as disabled. */ + for (i = (ptrdiff_t)t->hmask; i >= 0; i--) + if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) { + GCobj *o = gcV(&node[i].key); + TValue tmp; + makewhite(g, o); + o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN; + copyTV(L, &tmp, &node[i].val); + setnilV(&node[i].val); + gc_call_finalizer(g, L, &tmp, o); + } + } +} +#endif + +/* Free all remaining GC objects. */ +void lj_gc_freeall(global_State *g) +{ + MSize i, strmask; + /* Free everything, except super-fixed objects (the main thread). */ + g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED; + gc_fullsweep(g, &g->gc.root); + strmask = g->strmask; + for (i = 0; i <= strmask; i++) /* Free all string hash chains. */ + gc_fullsweep(g, &g->strhash[i]); +} + +/* -- Collector ----------------------------------------------------------- */ + +/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */ +static void atomic(global_State *g, lua_State *L) +{ + size_t udsize; + + gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */ + gc_propagate_gray(g); /* Propagate any left-overs. */ + + setgcrefr(g->gc.gray, g->gc.weak); /* Empty the list of weak tables. */ + setgcrefnull(g->gc.weak); + lua_assert(!iswhite(obj2gco(mainthread(g)))); + gc_markobj(g, L); /* Mark running thread. */ + gc_traverse_curtrace(g); /* Traverse current trace. */ + gc_mark_gcroot(g); /* Mark GC roots (again). */ + gc_propagate_gray(g); /* Propagate all of the above. */ + + setgcrefr(g->gc.gray, g->gc.grayagain); /* Empty the 2nd chance list. */ + setgcrefnull(g->gc.grayagain); + gc_propagate_gray(g); /* Propagate it. */ + + udsize = lj_gc_separateudata(g, 0); /* Separate userdata to be finalized. */ + gc_mark_mmudata(g); /* Mark them. */ + udsize += gc_propagate_gray(g); /* And propagate the marks. */ + + /* All marking done, clear weak tables. */ + gc_clearweak(gcref(g->gc.weak)); + + /* Prepare for sweep phase. */ + g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ + g->strempty.marked = g->gc.currentwhite; + setmref(g->gc.sweep, &g->gc.root); + g->gc.estimate = g->gc.total - (MSize)udsize; /* Initial estimate. */ +} + +/* GC state machine. Returns a cost estimate for each step performed. */ +static size_t gc_onestep(lua_State *L) +{ + global_State *g = G(L); + switch (g->gc.state) { + case GCSpause: + gc_mark_start(g); /* Start a new GC cycle by marking all GC roots. */ + return 0; + case GCSpropagate: + if (gcref(g->gc.gray) != NULL) + return propagatemark(g); /* Propagate one gray object. */ + g->gc.state = GCSatomic; /* End of mark phase. */ + return 0; + case GCSatomic: + if (gcref(g->jit_L)) /* Don't run atomic phase on trace. */ + return LJ_MAX_MEM; + atomic(g, L); + g->gc.state = GCSsweepstring; /* Start of sweep phase. */ + g->gc.sweepstr = 0; + return 0; + case GCSsweepstring: { + MSize old = g->gc.total; + gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */ + if (g->gc.sweepstr > g->strmask) + g->gc.state = GCSsweep; /* All string hash chains sweeped. */ + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; + return GCSWEEPCOST; + } + case GCSsweep: { + MSize old = g->gc.total; + setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); + if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { + gc_shrink(g, L); + if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ + g->gc.state = GCSfinalize; +#if LJ_HASFFI + g->gc.nocdatafin = 1; +#endif + } else { /* Otherwise skip this phase to help the JIT. */ + g->gc.state = GCSpause; /* End of GC cycle. */ + g->gc.debt = 0; + } + } + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: + if (gcref(g->gc.mmudata) != NULL) { + if (gcref(g->jit_L)) /* Don't call finalizers on trace. */ + return LJ_MAX_MEM; + gc_finalize(L); /* Finalize one userdata object. */ + if (g->gc.estimate > GCFINALIZECOST) + g->gc.estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } +#if LJ_HASFFI + if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer); +#endif + g->gc.state = GCSpause; /* End of GC cycle. */ + g->gc.debt = 0; + return 0; + default: + lua_assert(0); + return 0; + } +} + +/* Perform a limited amount of incremental GC steps. */ +int LJ_FASTCALL lj_gc_step(lua_State *L) +{ + global_State *g = G(L); + MSize lim; + int32_t ostate = g->vmstate; + setvmstate(g, GC); + lim = (GCSTEPSIZE/100) * g->gc.stepmul; + if (lim == 0) + lim = LJ_MAX_MEM; + if (g->gc.total > g->gc.threshold) + g->gc.debt += g->gc.total - g->gc.threshold; + do { + lim -= (MSize)gc_onestep(L); + if (g->gc.state == GCSpause) { + g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; + g->vmstate = ostate; + return 1; /* Finished a GC cycle. */ + } + } while ((int32_t)lim > 0); + if (g->gc.debt < GCSTEPSIZE) { + g->gc.threshold = g->gc.total + GCSTEPSIZE; + g->vmstate = ostate; + return -1; + } else { + g->gc.debt -= GCSTEPSIZE; + g->gc.threshold = g->gc.total; + g->vmstate = ostate; + return 0; + } +} + +/* Ditto, but fix the stack top first. */ +void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L) +{ + if (curr_funcisL(L)) L->top = curr_topL(L); + lj_gc_step(L); +} + +#if LJ_HASJIT +/* Perform multiple GC steps. Called from JIT-compiled code. */ +int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps) +{ + lua_State *L = gco2th(gcref(g->jit_L)); + L->base = mref(G(L)->jit_base, TValue); + L->top = curr_topL(L); + while (steps-- > 0 && lj_gc_step(L) == 0) + ; + /* Return 1 to force a trace exit. */ + return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize); +} +#endif + +/* Perform a full GC cycle. */ +void lj_gc_fullgc(lua_State *L) +{ + global_State *g = G(L); + int32_t ostate = g->vmstate; + setvmstate(g, GC); + if (g->gc.state <= GCSatomic) { /* Caught somewhere in the middle. */ + setmref(g->gc.sweep, &g->gc.root); /* Sweep everything (preserving it). */ + setgcrefnull(g->gc.gray); /* Reset lists from partial propagation. */ + setgcrefnull(g->gc.grayagain); + setgcrefnull(g->gc.weak); + g->gc.state = GCSsweepstring; /* Fast forward to the sweep phase. */ + g->gc.sweepstr = 0; + } + while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep) + gc_onestep(L); /* Finish sweep. */ + lua_assert(g->gc.state == GCSfinalize || g->gc.state == GCSpause); + /* Now perform a full GC. */ + g->gc.state = GCSpause; + do { gc_onestep(L); } while (g->gc.state != GCSpause); + g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; + g->vmstate = ostate; +} + +/* -- Write barriers ------------------------------------------------------ */ + +/* Move the GC propagation frontier forward. */ +void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v) +{ + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + lua_assert(o->gch.gct != ~LJ_TTAB); + /* Preserve invariant during propagation. Otherwise it doesn't matter. */ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_mark(g, v); /* Move frontier forward. */ + else + makewhite(g, o); /* Make it white to avoid the following barrier. */ +} + +/* Specialized barrier for closed upvalue. Pass &uv->tv. */ +void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv) +{ +#define TV2MARKED(x) \ + (*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked))) + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_mark(g, gcV(tv)); + else + TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g); +#undef TV2MARKED +} + +/* Close upvalue. Also needs a write barrier. */ +void lj_gc_closeuv(global_State *g, GCupval *uv) +{ + GCobj *o = obj2gco(uv); + /* Copy stack slot to upvalue itself and point to the copy. */ + copyTV(mainthread(g), &uv->tv, uvval(uv)); + setmref(uv->v, &uv->tv); + uv->closed = 1; + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) { + gray2black(o); /* Make it black and preserve invariant. */ + if (tviswhite(&uv->tv)) + lj_gc_barrierf(g, o, gcV(&uv->tv)); + } else { + makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */ + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + } + } +} + +#if LJ_HASJIT +/* Mark a trace if it's saved during the propagation phase. */ +void lj_gc_barriertrace(global_State *g, uint32_t traceno) +{ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_marktrace(g, traceno); +} +#endif + +/* -- Allocator ----------------------------------------------------------- */ + +/* Call pluggable memory allocator to allocate or resize a fragment. */ +void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) +{ + global_State *g = G(L); + lua_assert((osz == 0) == (p == NULL)); + p = g->allocf(g->allocd, p, osz, nsz); + if (p == NULL && nsz > 0) + lj_err_mem(L); + lua_assert((nsz == 0) == (p == NULL)); + lua_assert(checkptr32(p)); + g->gc.total = (g->gc.total - osz) + nsz; + return p; +} + +/* Allocate new GC object and link it to the root set. */ +void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size) +{ + global_State *g = G(L); + GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); + if (o == NULL) + lj_err_mem(L); + lua_assert(checkptr32(o)); + g->gc.total += size; + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + newwhite(g, o); + return o; +} + +/* Resize growable vector. */ +void *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz) +{ + MSize sz = (*szp) << 1; + if (sz < LJ_MIN_VECSZ) + sz = LJ_MIN_VECSZ; + if (sz > lim) + sz = lim; + p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz); + *szp = sz; + return p; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.h new file mode 100644 index 0000000..c85d075 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gc.h @@ -0,0 +1,134 @@ +/* +** Garbage collector. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_GC_H +#define _LJ_GC_H + +#include "lj_obj.h" + +/* Garbage collector states. Order matters. */ +enum { + GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize +}; + +/* Bitmasks for marked field of GCobj. */ +#define LJ_GC_WHITE0 0x01 +#define LJ_GC_WHITE1 0x02 +#define LJ_GC_BLACK 0x04 +#define LJ_GC_FINALIZED 0x08 +#define LJ_GC_WEAKKEY 0x08 +#define LJ_GC_WEAKVAL 0x10 +#define LJ_GC_CDATA_FIN 0x10 +#define LJ_GC_FIXED 0x20 +#define LJ_GC_SFIXED 0x40 + +#define LJ_GC_WHITES (LJ_GC_WHITE0 | LJ_GC_WHITE1) +#define LJ_GC_COLORS (LJ_GC_WHITES | LJ_GC_BLACK) +#define LJ_GC_WEAK (LJ_GC_WEAKKEY | LJ_GC_WEAKVAL) + +/* Macros to test and set GCobj colors. */ +#define iswhite(x) ((x)->gch.marked & LJ_GC_WHITES) +#define isblack(x) ((x)->gch.marked & LJ_GC_BLACK) +#define isgray(x) (!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES))) +#define tviswhite(x) (tvisgcv(x) && iswhite(gcV(x))) +#define otherwhite(g) (g->gc.currentwhite ^ LJ_GC_WHITES) +#define isdead(g, v) ((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES) + +#define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES) +#define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g)) +#define makewhite(g, x) \ + ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g)) +#define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES) +#define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK) +#define fixstring(s) ((s)->marked |= LJ_GC_FIXED) +#define markfinalized(x) ((x)->gch.marked |= LJ_GC_FINALIZED) + +/* Collector. */ +LJ_FUNC size_t lj_gc_separateudata(global_State *g, int all); +LJ_FUNC void lj_gc_finalize_udata(lua_State *L); +#if LJ_HASFFI +LJ_FUNC void lj_gc_finalize_cdata(lua_State *L); +#else +#define lj_gc_finalize_cdata(L) UNUSED(L) +#endif +LJ_FUNC void lj_gc_freeall(global_State *g); +LJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L); +LJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L); +#if LJ_HASJIT +LJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps); +#endif +LJ_FUNC void lj_gc_fullgc(lua_State *L); + +/* GC check: drive collector forward if the GC threshold has been reached. */ +#define lj_gc_check(L) \ + { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \ + lj_gc_step(L); } +#define lj_gc_check_fixtop(L) \ + { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \ + lj_gc_step_fixtop(L); } + +/* Write barriers. */ +LJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v); +LJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv); +LJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv); +#if LJ_HASJIT +LJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno); +#endif + +/* Move the GC propagation frontier back for tables (make it gray again). */ +static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t) +{ + GCobj *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + black2gray(o); + setgcrefr(t->gclist, g->gc.grayagain); + setgcref(g->gc.grayagain, o); +} + +/* Barrier for stores to table objects. TValue and GCobj variant. */ +#define lj_gc_anybarriert(L, t) \ + { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); } +#define lj_gc_barriert(L, t, tv) \ + { if (tviswhite(tv) && isblack(obj2gco(t))) \ + lj_gc_barrierback(G(L), (t)); } +#define lj_gc_objbarriert(L, t, o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \ + lj_gc_barrierback(G(L), (t)); } + +/* Barrier for stores to any other object. TValue and GCobj variant. */ +#define lj_gc_barrier(L, p, tv) \ + { if (tviswhite(tv) && isblack(obj2gco(p))) \ + lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); } +#define lj_gc_objbarrier(L, p, o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); } + +/* Allocator. */ +LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz); +LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size); +LJ_FUNC void *lj_mem_grow(lua_State *L, void *p, + MSize *szp, MSize lim, MSize esz); + +#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s)) + +static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize) +{ + g->gc.total -= (MSize)osize; + g->allocf(g->allocd, p, osize, 0); +} + +#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t)))) +#define lj_mem_reallocvec(L, p, on, n, t) \ + ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (MSize)((n)*sizeof(t)))) +#define lj_mem_growvec(L, p, n, m, t) \ + ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t))) +#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t)) + +#define lj_mem_newobj(L, t) ((t *)lj_mem_newgco(L, sizeof(t))) +#define lj_mem_newt(L, s, t) ((t *)lj_mem_new(L, (s))) +#define lj_mem_freet(g, p) lj_mem_free(g, (p), sizeof(*(p))) + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.c new file mode 100644 index 0000000..5e7fca1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.c @@ -0,0 +1,793 @@ +/* +** Client for the GDB JIT API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_gdbjit_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_frame.h" +#include "lj_jit.h" +#include "lj_dispatch.h" + +/* This is not compiled in by default. +** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything. +*/ +#ifdef LUAJIT_USE_GDBJIT + +/* The GDB JIT API allows JIT compilers to pass debug information about +** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher +** to see it in action. +** +** This is a passive API, so it works even when not running under GDB +** or when attaching to an already running process. Alas, this implies +** enabling it always has a non-negligible overhead -- do not use in +** release mode! +** +** The LuaJIT GDB JIT client is rather minimal at the moment. It gives +** each trace a symbol name and adds a source location and frame unwind +** information. Obviously LuaJIT itself and any embedding C application +** should be compiled with debug symbols, too (see the Makefile). +** +** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace +** numbers from -jv or -jdump. Use "break TRACE_1" or "tbreak TRACE_1" etc. +** to set breakpoints on specific traces (even ahead of their creation). +** +** The source location for each trace allows listing the corresponding +** source lines with the GDB command "list" (but only if the Lua source +** has been loaded from a file). Currently this is always set to the +** location where the trace has been started. +** +** Frame unwind information can be inspected with the GDB command +** "info frame". This also allows proper backtraces across JIT-compiled +** code with the GDB command "bt". +** +** You probably want to add the following settings to a .gdbinit file +** (or add them to ~/.gdbinit): +** set disassembly-flavor intel +** set breakpoint pending on +** +** Here's a sample GDB session: +** ------------------------------------------------------------------------ + +$ cat >x.lua +for outer=1,100 do + for inner=1,100 do end +end +^D + +$ luajit -jv x.lua +[TRACE 1 x.lua:2] +[TRACE 2 (1/3) x.lua:1 -> 1] + +$ gdb --quiet --args luajit x.lua +(gdb) tbreak TRACE_1 +Function "TRACE_1" not defined. +Temporary breakpoint 1 (TRACE_1) pending. +(gdb) run +Starting program: luajit x.lua + +Temporary breakpoint 1, TRACE_1 () at x.lua:2 +2 for inner=1,100 do end +(gdb) list +1 for outer=1,100 do +2 for inner=1,100 do end +3 end +(gdb) bt +#0 TRACE_1 () at x.lua:2 +#1 0x08053690 in lua_pcall [...] +[...] +#7 0x0806ff90 in main [...] +(gdb) disass TRACE_1 +Dump of assembler code for function TRACE_1: +0xf7fd9fba : mov DWORD PTR ds:0xf7e0e2a0,0x1 +0xf7fd9fc4 : movsd xmm7,QWORD PTR [edx+0x20] +[...] +0xf7fd9ff8 : jmp 0xf7fd2014 +End of assembler dump. +(gdb) tbreak TRACE_2 +Function "TRACE_2" not defined. +Temporary breakpoint 2 (TRACE_2) pending. +(gdb) cont +Continuing. + +Temporary breakpoint 2, TRACE_2 () at x.lua:1 +1 for outer=1,100 do +(gdb) info frame +Stack level 0, frame at 0xffffd7c0: + eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690 + called by frame at 0xffffd7e0 + source language unknown. + Arglist at 0xffffd78c, args: + Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0 + Saved registers: + ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4, + eip at 0xffffd7bc +(gdb) + +** ------------------------------------------------------------------------ +*/ + +/* -- GDB JIT API --------------------------------------------------------- */ + +/* GDB JIT actions. */ +enum { + GDBJIT_NOACTION = 0, + GDBJIT_REGISTER, + GDBJIT_UNREGISTER +}; + +/* GDB JIT entry. */ +typedef struct GDBJITentry { + struct GDBJITentry *next_entry; + struct GDBJITentry *prev_entry; + const char *symfile_addr; + uint64_t symfile_size; +} GDBJITentry; + +/* GDB JIT descriptor. */ +typedef struct GDBJITdesc { + uint32_t version; + uint32_t action_flag; + GDBJITentry *relevant_entry; + GDBJITentry *first_entry; +} GDBJITdesc; + +GDBJITdesc __jit_debug_descriptor = { + 1, GDBJIT_NOACTION, NULL, NULL +}; + +/* GDB sets a breakpoint at this function. */ +void LJ_NOINLINE __jit_debug_register_code() +{ + __asm__ __volatile__(""); +}; + +/* -- In-memory ELF object definitions ------------------------------------ */ + +/* ELF definitions. */ +typedef struct ELFheader { + uint8_t emagic[4]; + uint8_t eclass; + uint8_t eendian; + uint8_t eversion; + uint8_t eosabi; + uint8_t eabiversion; + uint8_t epad[7]; + uint16_t type; + uint16_t machine; + uint32_t version; + uintptr_t entry; + uintptr_t phofs; + uintptr_t shofs; + uint32_t flags; + uint16_t ehsize; + uint16_t phentsize; + uint16_t phnum; + uint16_t shentsize; + uint16_t shnum; + uint16_t shstridx; +} ELFheader; + +typedef struct ELFsectheader { + uint32_t name; + uint32_t type; + uintptr_t flags; + uintptr_t addr; + uintptr_t ofs; + uintptr_t size; + uint32_t link; + uint32_t info; + uintptr_t align; + uintptr_t entsize; +} ELFsectheader; + +#define ELFSECT_IDX_ABS 0xfff1 + +enum { + ELFSECT_TYPE_PROGBITS = 1, + ELFSECT_TYPE_SYMTAB = 2, + ELFSECT_TYPE_STRTAB = 3, + ELFSECT_TYPE_NOBITS = 8 +}; + +#define ELFSECT_FLAGS_WRITE 1 +#define ELFSECT_FLAGS_ALLOC 2 +#define ELFSECT_FLAGS_EXEC 4 + +typedef struct ELFsymbol { +#if LJ_64 + uint32_t name; + uint8_t info; + uint8_t other; + uint16_t sectidx; + uintptr_t value; + uint64_t size; +#else + uint32_t name; + uintptr_t value; + uint32_t size; + uint8_t info; + uint8_t other; + uint16_t sectidx; +#endif +} ELFsymbol; + +enum { + ELFSYM_TYPE_FUNC = 2, + ELFSYM_TYPE_FILE = 4, + ELFSYM_BIND_LOCAL = 0 << 4, + ELFSYM_BIND_GLOBAL = 1 << 4, +}; + +/* DWARF definitions. */ +#define DW_CIE_VERSION 1 + +enum { + DW_CFA_nop = 0x0, + DW_CFA_offset_extended = 0x5, + DW_CFA_def_cfa = 0xc, + DW_CFA_def_cfa_offset = 0xe, + DW_CFA_offset_extended_sf = 0x11, + DW_CFA_advance_loc = 0x40, + DW_CFA_offset = 0x80 +}; + +enum { + DW_EH_PE_udata4 = 3, + DW_EH_PE_textrel = 0x20 +}; + +enum { + DW_TAG_compile_unit = 0x11 +}; + +enum { + DW_children_no = 0, + DW_children_yes = 1 +}; + +enum { + DW_AT_name = 0x03, + DW_AT_stmt_list = 0x10, + DW_AT_low_pc = 0x11, + DW_AT_high_pc = 0x12 +}; + +enum { + DW_FORM_addr = 0x01, + DW_FORM_data4 = 0x06, + DW_FORM_string = 0x08 +}; + +enum { + DW_LNS_extended_op = 0, + DW_LNS_copy = 1, + DW_LNS_advance_pc = 2, + DW_LNS_advance_line = 3 +}; + +enum { + DW_LNE_end_sequence = 1, + DW_LNE_set_address = 2 +}; + +enum { +#if LJ_TARGET_X86 + DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX, + DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI, + DW_REG_RA, +#elif LJ_TARGET_X64 + /* Yes, the order is strange, but correct. */ + DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX, + DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP, + DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11, + DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15, + DW_REG_RA, +#elif LJ_TARGET_ARM + DW_REG_SP = 13, + DW_REG_RA = 14, +#elif LJ_TARGET_PPC + DW_REG_SP = 1, + DW_REG_RA = 65, + DW_REG_CR = 70, +#elif LJ_TARGET_MIPS + DW_REG_SP = 29, + DW_REG_RA = 31, +#else +#error "Unsupported target architecture" +#endif +}; + +/* Minimal list of sections for the in-memory ELF object. */ +enum { + GDBJIT_SECT_NULL, + GDBJIT_SECT_text, + GDBJIT_SECT_eh_frame, + GDBJIT_SECT_shstrtab, + GDBJIT_SECT_strtab, + GDBJIT_SECT_symtab, + GDBJIT_SECT_debug_info, + GDBJIT_SECT_debug_abbrev, + GDBJIT_SECT_debug_line, + GDBJIT_SECT__MAX +}; + +enum { + GDBJIT_SYM_UNDEF, + GDBJIT_SYM_FILE, + GDBJIT_SYM_FUNC, + GDBJIT_SYM__MAX +}; + +/* In-memory ELF object. */ +typedef struct GDBJITobj { + ELFheader hdr; /* ELF header. */ + ELFsectheader sect[GDBJIT_SECT__MAX]; /* ELF sections. */ + ELFsymbol sym[GDBJIT_SYM__MAX]; /* ELF symbol table. */ + uint8_t space[4096]; /* Space for various section data. */ +} GDBJITobj; + +/* Combined structure for GDB JIT entry and ELF object. */ +typedef struct GDBJITentryobj { + GDBJITentry entry; + size_t sz; + GDBJITobj obj; +} GDBJITentryobj; + +/* Template for in-memory ELF header. */ +static const ELFheader elfhdr_template = { + .emagic = { 0x7f, 'E', 'L', 'F' }, + .eclass = LJ_64 ? 2 : 1, + .eendian = LJ_ENDIAN_SELECT(1, 2), + .eversion = 1, +#if LJ_TARGET_LINUX + .eosabi = 0, /* Nope, it's not 3. */ +#elif defined(__FreeBSD__) + .eosabi = 9, +#elif defined(__NetBSD__) + .eosabi = 2, +#elif defined(__OpenBSD__) + .eosabi = 12, +#elif (defined(__sun__) && defined(__svr4__)) + .eosabi = 6, +#else + .eosabi = 0, +#endif + .eabiversion = 0, + .epad = { 0, 0, 0, 0, 0, 0, 0 }, + .type = 1, +#if LJ_TARGET_X86 + .machine = 3, +#elif LJ_TARGET_X64 + .machine = 62, +#elif LJ_TARGET_ARM + .machine = 40, +#elif LJ_TARGET_PPC + .machine = 20, +#elif LJ_TARGET_MIPS + .machine = 8, +#else +#error "Unsupported target architecture" +#endif + .version = 1, + .entry = 0, + .phofs = 0, + .shofs = offsetof(GDBJITobj, sect), + .flags = 0, + .ehsize = sizeof(ELFheader), + .phentsize = 0, + .phnum = 0, + .shentsize = sizeof(ELFsectheader), + .shnum = GDBJIT_SECT__MAX, + .shstridx = GDBJIT_SECT_shstrtab +}; + +/* -- In-memory ELF object generation ------------------------------------- */ + +/* Context for generating the ELF object for the GDB JIT API. */ +typedef struct GDBJITctx { + uint8_t *p; /* Pointer to next address in obj.space. */ + uint8_t *startp; /* Pointer to start address in obj.space. */ + GCtrace *T; /* Generate symbols for this trace. */ + uintptr_t mcaddr; /* Machine code address. */ + MSize szmcode; /* Size of machine code. */ + MSize spadjp; /* Stack adjustment for parent trace or interpreter. */ + MSize spadj; /* Stack adjustment for trace itself. */ + BCLine lineno; /* Starting line number. */ + const char *filename; /* Starting file name. */ + size_t objsize; /* Final size of ELF object. */ + GDBJITobj obj; /* In-memory ELF object. */ +} GDBJITctx; + +/* Add a zero-terminated string. */ +static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str) +{ + uint8_t *p = ctx->p; + uint32_t ofs = (uint32_t)(p - ctx->startp); + do { + *p++ = (uint8_t)*str; + } while (*str++); + ctx->p = p; + return ofs; +} + +/* Append a decimal number. */ +static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n) +{ + if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); } + *ctx->p++ = '0' + n; +} + +/* Add a ULEB128 value. */ +static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v) +{ + uint8_t *p = ctx->p; + for (; v >= 0x80; v >>= 7) + *p++ = (uint8_t)((v & 0x7f) | 0x80); + *p++ = (uint8_t)v; + ctx->p = p; +} + +/* Add a SLEB128 value. */ +static void gdbjit_sleb128(GDBJITctx *ctx, int32_t v) +{ + uint8_t *p = ctx->p; + for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7) + *p++ = (uint8_t)((v & 0x7f) | 0x80); + *p++ = (uint8_t)(v & 0x7f); + ctx->p = p; +} + +/* Shortcuts to generate DWARF structures. */ +#define DB(x) (*p++ = (x)) +#define DI8(x) (*(int8_t *)p = (x), p++) +#define DU16(x) (*(uint16_t *)p = (x), p += 2) +#define DU32(x) (*(uint32_t *)p = (x), p += 4) +#define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t)) +#define DUV(x) (ctx->p = p, gdbjit_uleb128(ctx, (x)), p = ctx->p) +#define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p) +#define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p) +#define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop +#define DSECT(name, stmt) \ + { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \ + *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \ + +/* Initialize ELF section headers. */ +static void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx) +{ + ELFsectheader *sect; + + *ctx->p++ = '\0'; /* Empty string at start of string table. */ + +#define SECTDEF(id, tp, al) \ + sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \ + sect->name = gdbjit_strz(ctx, "." #id); \ + sect->type = ELFSECT_TYPE_##tp; \ + sect->align = (al) + + SECTDEF(text, NOBITS, 16); + sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC; + sect->addr = ctx->mcaddr; + sect->ofs = 0; + sect->size = ctx->szmcode; + + SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t)); + sect->flags = ELFSECT_FLAGS_ALLOC; + + SECTDEF(shstrtab, STRTAB, 1); + SECTDEF(strtab, STRTAB, 1); + + SECTDEF(symtab, SYMTAB, sizeof(uintptr_t)); + sect->ofs = offsetof(GDBJITobj, sym); + sect->size = sizeof(ctx->obj.sym); + sect->link = GDBJIT_SECT_strtab; + sect->entsize = sizeof(ELFsymbol); + sect->info = GDBJIT_SYM_FUNC; + + SECTDEF(debug_info, PROGBITS, 1); + SECTDEF(debug_abbrev, PROGBITS, 1); + SECTDEF(debug_line, PROGBITS, 1); + +#undef SECTDEF +} + +/* Initialize symbol table. */ +static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx) +{ + ELFsymbol *sym; + + *ctx->p++ = '\0'; /* Empty string at start of string table. */ + + sym = &ctx->obj.sym[GDBJIT_SYM_FILE]; + sym->name = gdbjit_strz(ctx, "JIT mcode"); + sym->sectidx = ELFSECT_IDX_ABS; + sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL; + + sym = &ctx->obj.sym[GDBJIT_SYM_FUNC]; + sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--; + gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0'; + sym->sectidx = GDBJIT_SECT_text; + sym->value = 0; + sym->size = ctx->szmcode; + sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL; +} + +/* Initialize .eh_frame section. */ +static void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + uint8_t *framep = p; + + /* Emit DWARF EH CIE. */ + DSECT(CIE, + DU32(0); /* Offset to CIE itself. */ + DB(DW_CIE_VERSION); + DSTR("zR"); /* Augmentation. */ + DUV(1); /* Code alignment factor. */ + DSV(-(int32_t)sizeof(uintptr_t)); /* Data alignment factor. */ + DB(DW_REG_RA); /* Return address register. */ + DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4); /* Augmentation data. */ + DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t)); +#if LJ_TARGET_PPC + DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1); +#else + DB(DW_CFA_offset|DW_REG_RA); DUV(1); +#endif + DALIGNNOP(sizeof(uintptr_t)); + ) + + /* Emit DWARF EH FDE. */ + DSECT(FDE, + DU32((uint32_t)(p-framep)); /* Offset to CIE. */ + DU32(0); /* Machine code offset relative to .text. */ + DU32(ctx->szmcode); /* Machine code length. */ + DB(0); /* Augmentation data. */ + /* Registers saved in CFRAME. */ +#if LJ_TARGET_X86 + DB(DW_CFA_offset|DW_REG_BP); DUV(2); + DB(DW_CFA_offset|DW_REG_DI); DUV(3); + DB(DW_CFA_offset|DW_REG_SI); DUV(4); + DB(DW_CFA_offset|DW_REG_BX); DUV(5); +#elif LJ_TARGET_X64 + DB(DW_CFA_offset|DW_REG_BP); DUV(2); + DB(DW_CFA_offset|DW_REG_BX); DUV(3); + DB(DW_CFA_offset|DW_REG_15); DUV(4); + DB(DW_CFA_offset|DW_REG_14); DUV(5); + /* Extra registers saved for JIT-compiled code. */ + DB(DW_CFA_offset|DW_REG_13); DUV(9); + DB(DW_CFA_offset|DW_REG_12); DUV(10); +#elif LJ_TARGET_ARM + { + int i; + for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); } + } +#elif LJ_TARGET_PPC + { + int i; + DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55); + for (i = 14; i <= 31; i++) { + DB(DW_CFA_offset|i); DUV(37+(31-i)); + DB(DW_CFA_offset|32|i); DUV(2+2*(31-i)); + } + } +#elif LJ_TARGET_MIPS + { + int i; + DB(DW_CFA_offset|30); DUV(2); + for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); } + for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); } + } +#else +#error "Unsupported target architecture" +#endif + if (ctx->spadjp != ctx->spadj) { /* Parent/interpreter stack frame size. */ + DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp); + DB(DW_CFA_advance_loc|1); /* Only an approximation. */ + } + DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj); /* Trace stack frame size. */ + DALIGNNOP(sizeof(uintptr_t)); + ) + + ctx->p = p; +} + +/* Initialize .debug_info section. */ +static void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + DSECT(info, + DU16(2); /* DWARF version. */ + DU32(0); /* Abbrev offset. */ + DB(sizeof(uintptr_t)); /* Pointer size. */ + + DUV(1); /* Abbrev #1: DW_TAG_compile_unit. */ + DSTR(ctx->filename); /* DW_AT_name. */ + DADDR(ctx->mcaddr); /* DW_AT_low_pc. */ + DADDR(ctx->mcaddr + ctx->szmcode); /* DW_AT_high_pc. */ + DU32(0); /* DW_AT_stmt_list. */ + ) + + ctx->p = p; +} + +/* Initialize .debug_abbrev section. */ +static void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + /* Abbrev #1: DW_TAG_compile_unit. */ + DUV(1); DUV(DW_TAG_compile_unit); + DB(DW_children_no); + DUV(DW_AT_name); DUV(DW_FORM_string); + DUV(DW_AT_low_pc); DUV(DW_FORM_addr); + DUV(DW_AT_high_pc); DUV(DW_FORM_addr); + DUV(DW_AT_stmt_list); DUV(DW_FORM_data4); + DB(0); DB(0); + + ctx->p = p; +} + +#define DLNE(op, s) (DB(DW_LNS_extended_op), DUV(1+(s)), DB((op))) + +/* Initialize .debug_line section. */ +static void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + DSECT(line, + DU16(2); /* DWARF version. */ + DSECT(header, + DB(1); /* Minimum instruction length. */ + DB(1); /* is_stmt. */ + DI8(0); /* Line base for special opcodes. */ + DB(2); /* Line range for special opcodes. */ + DB(3+1); /* Opcode base at DW_LNS_advance_line+1. */ + DB(0); DB(1); DB(1); /* Standard opcode lengths. */ + /* Directory table. */ + DB(0); + /* File name table. */ + DSTR(ctx->filename); DUV(0); DUV(0); DUV(0); + DB(0); + ) + + DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr); + if (ctx->lineno) { + DB(DW_LNS_advance_line); DSV(ctx->lineno-1); + } + DB(DW_LNS_copy); + DB(DW_LNS_advance_pc); DUV(ctx->szmcode); + DLNE(DW_LNE_end_sequence, 0); + ) + + ctx->p = p; +} + +#undef DLNE + +/* Undef shortcuts. */ +#undef DB +#undef DI8 +#undef DU16 +#undef DU32 +#undef DADDR +#undef DUV +#undef DSV +#undef DSTR +#undef DALIGNNOP +#undef DSECT + +/* Type of a section initializer callback. */ +typedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx); + +/* Call section initializer and set the section offset and size. */ +static void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf) +{ + ctx->startp = ctx->p; + ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj); + initf(ctx); + ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp); +} + +#define SECTALIGN(p, a) \ + ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1))) + +/* Build in-memory ELF object. */ +static void gdbjit_buildobj(GDBJITctx *ctx) +{ + GDBJITobj *obj = &ctx->obj; + /* Fill in ELF header and clear structures. */ + memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader)); + memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX); + memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX); + /* Initialize sections. */ + ctx->p = obj->space; + gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr); + gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline); + SECTALIGN(ctx->p, sizeof(uintptr_t)); + gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe); + ctx->objsize = (size_t)((char *)ctx->p - (char *)obj); + lua_assert(ctx->objsize < sizeof(GDBJITobj)); +} + +#undef SECTALIGN + +/* -- Interface to GDB JIT API -------------------------------------------- */ + +/* Add new entry to GDB JIT symbol chain. */ +static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) +{ + /* Allocate memory for GDB JIT entry and ELF object. */ + MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize); + GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj); + memcpy(&eo->obj, &ctx->obj, ctx->objsize); /* Copy ELF object. */ + eo->sz = sz; + ctx->T->gdbjit_entry = (void *)eo; + /* Link new entry to chain and register it. */ + eo->entry.prev_entry = NULL; + eo->entry.next_entry = __jit_debug_descriptor.first_entry; + if (eo->entry.next_entry) + eo->entry.next_entry->prev_entry = &eo->entry; + eo->entry.symfile_addr = (const char *)&eo->obj; + eo->entry.symfile_size = ctx->objsize; + __jit_debug_descriptor.first_entry = &eo->entry; + __jit_debug_descriptor.relevant_entry = &eo->entry; + __jit_debug_descriptor.action_flag = GDBJIT_REGISTER; + __jit_debug_register_code(); +} + +/* Add debug info for newly compiled trace and notify GDB. */ +void lj_gdbjit_addtrace(jit_State *J, GCtrace *T) +{ + GDBJITctx ctx; + GCproto *pt = &gcref(T->startpt)->pt; + TraceNo parent = T->ir[REF_BASE].op1; + const BCIns *startpc = mref(T->startpc, const BCIns); + ctx.T = T; + ctx.mcaddr = (uintptr_t)T->mcode; + ctx.szmcode = T->szmcode; + ctx.spadjp = CFRAME_SIZE_JIT + + (MSize)(parent ? traceref(J, parent)->spadjust : 0); + ctx.spadj = CFRAME_SIZE_JIT + T->spadjust; + lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc); + ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc)); + ctx.filename = proto_chunknamestr(pt); + if (*ctx.filename == '@' || *ctx.filename == '=') + ctx.filename++; + else + ctx.filename = "(string)"; + gdbjit_buildobj(&ctx); + gdbjit_newentry(J->L, &ctx); +} + +/* Delete debug info for trace and notify GDB. */ +void lj_gdbjit_deltrace(jit_State *J, GCtrace *T) +{ + GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry; + if (eo) { + if (eo->entry.prev_entry) + eo->entry.prev_entry->next_entry = eo->entry.next_entry; + else + __jit_debug_descriptor.first_entry = eo->entry.next_entry; + if (eo->entry.next_entry) + eo->entry.next_entry->prev_entry = eo->entry.prev_entry; + __jit_debug_descriptor.relevant_entry = &eo->entry; + __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER; + __jit_debug_register_code(); + lj_mem_free(J2G(J), eo, eo->sz); + } +} + +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.h new file mode 100644 index 0000000..9ae504f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_gdbjit.h @@ -0,0 +1,22 @@ +/* +** Client for the GDB JIT API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_GDBJIT_H +#define _LJ_GDBJIT_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT) + +LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T); +LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T); + +#else +#define lj_gdbjit_addtrace(J, T) UNUSED(T) +#define lj_gdbjit_deltrace(J, T) UNUSED(T) +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.c new file mode 100644 index 0000000..b2170a1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.c @@ -0,0 +1,501 @@ +/* +** SSA IR (Intermediate Representation) emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ir_c +#define LUA_CORE + +/* For pointers to libc/libm functions. */ +#include +#include + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_carith.h" +#endif +#include "lj_vm.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* -- IR tables ----------------------------------------------------------- */ + +/* IR instruction modes. */ +LJ_DATADEF const uint8_t lj_ir_mode[IR__MAX+1] = { +IRDEF(IRMODE) + 0 +}; + +/* IR type sizes. */ +LJ_DATADEF const uint8_t lj_ir_type_size[IRT__MAX+1] = { +#define IRTSIZE(name, size) size, +IRTDEF(IRTSIZE) +#undef IRTSIZE + 0 +}; + +/* C call info for CALL* instructions. */ +LJ_DATADEF const CCallInfo lj_ir_callinfo[] = { +#define IRCALLCI(cond, name, nargs, kind, type, flags) \ + { (ASMFunction)IRCALLCOND_##cond(name), \ + (nargs)|(CCI_CALL_##kind)|(IRT_##type<irbuf + J->irbotlim; + MSize szins = J->irtoplim - J->irbotlim; + if (szins) { + baseir = (IRIns *)lj_mem_realloc(J->L, baseir, szins*sizeof(IRIns), + 2*szins*sizeof(IRIns)); + J->irtoplim = J->irbotlim + 2*szins; + } else { + baseir = (IRIns *)lj_mem_realloc(J->L, NULL, 0, LJ_MIN_IRSZ*sizeof(IRIns)); + J->irbotlim = REF_BASE - LJ_MIN_IRSZ/4; + J->irtoplim = J->irbotlim + LJ_MIN_IRSZ; + } + J->cur.ir = J->irbuf = baseir - J->irbotlim; +} + +/* Grow IR buffer at the bottom or shift it up. */ +static void lj_ir_growbot(jit_State *J) +{ + IRIns *baseir = J->irbuf + J->irbotlim; + MSize szins = J->irtoplim - J->irbotlim; + lua_assert(szins != 0); + lua_assert(J->cur.nk == J->irbotlim); + if (J->cur.nins + (szins >> 1) < J->irtoplim) { + /* More than half of the buffer is free on top: shift up by a quarter. */ + MSize ofs = szins >> 2; + memmove(baseir + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns)); + J->irbotlim -= ofs; + J->irtoplim -= ofs; + J->cur.ir = J->irbuf = baseir - J->irbotlim; + } else { + /* Double the buffer size, but split the growth amongst top/bottom. */ + IRIns *newbase = lj_mem_newt(J->L, 2*szins*sizeof(IRIns), IRIns); + MSize ofs = szins >= 256 ? 128 : (szins >> 1); /* Limit bottom growth. */ + memcpy(newbase + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns)); + lj_mem_free(G(J->L), baseir, szins*sizeof(IRIns)); + J->irbotlim -= ofs; + J->irtoplim = J->irbotlim + 2*szins; + J->cur.ir = J->irbuf = newbase - J->irbotlim; + } +} + +/* Emit IR without any optimizations. */ +TRef LJ_FASTCALL lj_ir_emit(jit_State *J) +{ + IRRef ref = lj_ir_nextins(J); + IRIns *ir = IR(ref); + IROp op = fins->o; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; + ir->o = op; + ir->op1 = fins->op1; + ir->op2 = fins->op2; + J->guardemit.irt |= fins->t.irt; + return TREF(ref, irt_t((ir->t = fins->t))); +} + +/* Emit call to a C function. */ +TRef lj_ir_call(jit_State *J, IRCallID id, ...) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + uint32_t n = CCI_NARGS(ci); + TRef tr = TREF_NIL; + va_list argp; + va_start(argp, id); + if ((ci->flags & CCI_L)) n--; + if (n > 0) + tr = va_arg(argp, IRRef); + while (n-- > 1) + tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef)); + va_end(argp); + if (CCI_OP(ci) == IR_CALLS) + J->needsnap = 1; /* Need snapshot after call with side effect. */ + return emitir(CCI_OPTYPE(ci), tr, id); +} + +/* -- Interning of constants ---------------------------------------------- */ + +/* +** IR instructions for constants are kept between J->cur.nk >= ref < REF_BIAS. +** They are chained like all other instructions, but grow downwards. +** The are interned (like strings in the VM) to facilitate reference +** comparisons. The same constant must get the same reference. +*/ + +/* Get ref of next IR constant and optionally grow IR. +** Note: this may invalidate all IRIns *! +*/ +static LJ_AINLINE IRRef ir_nextk(jit_State *J) +{ + IRRef ref = J->cur.nk; + if (LJ_UNLIKELY(ref <= J->irbotlim)) lj_ir_growbot(J); + J->cur.nk = --ref; + return ref; +} + +/* Intern int32_t constant. */ +TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + for (ref = J->chain[IR_KINT]; ref; ref = cir[ref].prev) + if (cir[ref].i == k) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->i = k; + ir->t.irt = IRT_INT; + ir->o = IR_KINT; + ir->prev = J->chain[IR_KINT]; + J->chain[IR_KINT] = (IRRef1)ref; +found: + return TREF(ref, IRT_INT); +} + +/* The MRef inside the KNUM/KINT64 IR instructions holds the address of the +** 64 bit constant. The constants themselves are stored in a chained array +** and shared across traces. +** +** Rationale for choosing this data structure: +** - The address of the constants is embedded in the generated machine code +** and must never move. A resizable array or hash table wouldn't work. +** - Most apps need very few non-32 bit integer constants (less than a dozen). +** - Linear search is hard to beat in terms of speed and low complexity. +*/ +typedef struct K64Array { + MRef next; /* Pointer to next list. */ + MSize numk; /* Number of used elements in this array. */ + TValue k[LJ_MIN_K64SZ]; /* Array of constants. */ +} K64Array; + +/* Free all chained arrays. */ +void lj_ir_k64_freeall(jit_State *J) +{ + K64Array *k; + for (k = mref(J->k64, K64Array); k; ) { + K64Array *next = mref(k->next, K64Array); + lj_mem_free(J2G(J), k, sizeof(K64Array)); + k = next; + } +} + +/* Find 64 bit constant in chained array or add it. */ +cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) +{ + K64Array *k, *kp = NULL; + TValue *ntv; + MSize idx; + /* Search for the constant in the whole chain of arrays. */ + for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) { + kp = k; /* Remember previous element in list. */ + for (idx = 0; idx < k->numk; idx++) { /* Search one array. */ + TValue *tv = &k->k[idx]; + if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */ + return tv; + } + } + /* Constant was not found, need to add it. */ + if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ + K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); + setmref(kn->next, NULL); + kn->numk = 0; + if (kp) + setmref(kp->next, kn); /* Chain to the end of the list. */ + else + setmref(J->k64, kn); /* Link first array. */ + kp = kn; + } + ntv = &kp->k[kp->numk++]; /* Add to current array. */ + ntv->u64 = u64; + return ntv; +} + +/* Intern 64 bit constant, given by its address. */ +TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64; + for (ref = J->chain[op]; ref; ref = cir[ref].prev) + if (ir_k64(&cir[ref]) == tv) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + lua_assert(checkptr32(tv)); + setmref(ir->ptr, tv); + ir->t.irt = t; + ir->o = op; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern FP constant, given by its 64 bit pattern. */ +TRef lj_ir_knum_u64(jit_State *J, uint64_t u64) +{ + return lj_ir_k64(J, IR_KNUM, lj_ir_k64_find(J, u64)); +} + +/* Intern 64 bit integer constant. */ +TRef lj_ir_kint64(jit_State *J, uint64_t u64) +{ + return lj_ir_k64(J, IR_KINT64, lj_ir_k64_find(J, u64)); +} + +/* Check whether a number is int and return it. -0 is NOT considered an int. */ +static int numistrueint(lua_Number n, int32_t *kp) +{ + int32_t k = lj_num2int(n); + if (n == (lua_Number)k) { + if (kp) *kp = k; + if (k == 0) { /* Special check for -0. */ + TValue tv; + setnumV(&tv, n); + if (tv.u32.hi != 0) + return 0; + } + return 1; + } + return 0; +} + +/* Intern number as int32_t constant if possible, otherwise as FP constant. */ +TRef lj_ir_knumint(jit_State *J, lua_Number n) +{ + int32_t k; + if (numistrueint(n, &k)) + return lj_ir_kint(J, k); + else + return lj_ir_knum(J, n); +} + +/* Intern GC object "constant". */ +TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + lua_assert(!isdead(J2G(J), o)); + for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev) + if (ir_kgc(&cir[ref]) == o) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + /* NOBARRIER: Current trace is a GC root. */ + setgcref(ir->gcr, o); + ir->t.irt = (uint8_t)t; + ir->o = IR_KGC; + ir->prev = J->chain[IR_KGC]; + J->chain[IR_KGC] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern 32 bit pointer constant. */ +TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr); + for (ref = J->chain[op]; ref; ref = cir[ref].prev) + if (mref(cir[ref].ptr, void) == ptr) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + setmref(ir->ptr, ptr); + ir->t.irt = IRT_P32; + ir->o = op; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; +found: + return TREF(ref, IRT_P32); +} + +/* Intern typed NULL constant. */ +TRef lj_ir_knull(jit_State *J, IRType t) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + for (ref = J->chain[IR_KNULL]; ref; ref = cir[ref].prev) + if (irt_t(cir[ref].t) == t) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->i = 0; + ir->t.irt = (uint8_t)t; + ir->o = IR_KNULL; + ir->prev = J->chain[IR_KNULL]; + J->chain[IR_KNULL] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern key slot. */ +TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot); + IRRef ref; + /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */ + lua_assert(tref_isk(key) && slot == (IRRef)(IRRef1)slot); + for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev) + if (cir[ref].op12 == op12) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->op12 = op12; + ir->t.irt = IRT_P32; + ir->o = IR_KSLOT; + ir->prev = J->chain[IR_KSLOT]; + J->chain[IR_KSLOT] = (IRRef1)ref; +found: + return TREF(ref, IRT_P32); +} + +/* -- Access to IR constants ---------------------------------------------- */ + +/* Copy value of IR constant. */ +void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir) +{ + UNUSED(L); + lua_assert(ir->o != IR_KSLOT); /* Common mistake. */ + switch (ir->o) { + case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break; + case IR_KINT: setintV(tv, ir->i); break; + case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; + case IR_KPTR: case IR_KKPTR: case IR_KNULL: + setlightudV(tv, mref(ir->ptr, void)); + break; + case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; +#if LJ_HASFFI + case IR_KINT64: { + GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8); + *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64; + setcdataV(L, tv, cd); + break; + } +#endif + default: lua_assert(0); break; + } +} + +/* -- Convert IR operand types -------------------------------------------- */ + +/* Convert from string to number. */ +TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr) +{ + if (!tref_isnumber(tr)) { + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + else + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + return tr; +} + +/* Convert from integer or string to number. */ +TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr) +{ + if (!tref_isnum(tr)) { + if (tref_isinteger(tr)) + tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + else if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + else + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + return tr; +} + +/* Convert from integer or number to string. */ +TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr) +{ + if (!tref_isstr(tr)) { + if (!tref_isnumber(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + tr = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); + } + return tr; +} + +/* -- Miscellaneous IR ops ------------------------------------------------ */ + +/* Evaluate numeric comparison. */ +int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op) +{ + switch (op) { + case IR_EQ: return (a == b); + case IR_NE: return (a != b); + case IR_LT: return (a < b); + case IR_GE: return (a >= b); + case IR_LE: return (a <= b); + case IR_GT: return (a > b); + case IR_ULT: return !(a >= b); + case IR_UGE: return !(a < b); + case IR_ULE: return !(a > b); + case IR_UGT: return !(a <= b); + default: lua_assert(0); return 0; + } +} + +/* Evaluate string comparison. */ +int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op) +{ + int res = lj_str_cmp(a, b); + switch (op) { + case IR_LT: return (res < 0); + case IR_GE: return (res >= 0); + case IR_LE: return (res <= 0); + case IR_GT: return (res > 0); + default: lua_assert(0); return 0; + } +} + +/* Rollback IR to previous state. */ +void lj_ir_rollback(jit_State *J, IRRef ref) +{ + IRRef nins = J->cur.nins; + while (nins > ref) { + IRIns *ir; + nins--; + ir = IR(nins); + J->chain[ir->o] = ir->prev; + } + J->cur.nins = nins; +} + +#undef IR +#undef fins +#undef emitir + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.h new file mode 100644 index 0000000..80763d8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ir.h @@ -0,0 +1,551 @@ +/* +** SSA IR (Intermediate Representation) format. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IR_H +#define _LJ_IR_H + +#include "lj_obj.h" + +/* -- IR instructions ----------------------------------------------------- */ + +/* IR instruction definition. Order matters, see below. ORDER IR */ +#define IRDEF(_) \ + /* Guarded assertions. */ \ + /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \ + _(LT, N , ref, ref) \ + _(GE, N , ref, ref) \ + _(LE, N , ref, ref) \ + _(GT, N , ref, ref) \ + \ + _(ULT, N , ref, ref) \ + _(UGE, N , ref, ref) \ + _(ULE, N , ref, ref) \ + _(UGT, N , ref, ref) \ + \ + _(EQ, C , ref, ref) \ + _(NE, C , ref, ref) \ + \ + _(ABC, N , ref, ref) \ + _(RETF, S , ref, ref) \ + \ + /* Miscellaneous ops. */ \ + _(NOP, N , ___, ___) \ + _(BASE, N , lit, lit) \ + _(PVAL, N , lit, ___) \ + _(GCSTEP, S , ___, ___) \ + _(HIOP, S , ref, ref) \ + _(LOOP, S , ___, ___) \ + _(USE, S , ref, ___) \ + _(PHI, S , ref, ref) \ + _(RENAME, S , ref, lit) \ + \ + /* Constants. */ \ + _(KPRI, N , ___, ___) \ + _(KINT, N , cst, ___) \ + _(KGC, N , cst, ___) \ + _(KPTR, N , cst, ___) \ + _(KKPTR, N , cst, ___) \ + _(KNULL, N , cst, ___) \ + _(KNUM, N , cst, ___) \ + _(KINT64, N , cst, ___) \ + _(KSLOT, N , ref, lit) \ + \ + /* Bit ops. */ \ + _(BNOT, N , ref, ___) \ + _(BSWAP, N , ref, ___) \ + _(BAND, C , ref, ref) \ + _(BOR, C , ref, ref) \ + _(BXOR, C , ref, ref) \ + _(BSHL, N , ref, ref) \ + _(BSHR, N , ref, ref) \ + _(BSAR, N , ref, ref) \ + _(BROL, N , ref, ref) \ + _(BROR, N , ref, ref) \ + \ + /* Arithmetic ops. ORDER ARITH */ \ + _(ADD, C , ref, ref) \ + _(SUB, N , ref, ref) \ + _(MUL, C , ref, ref) \ + _(DIV, N , ref, ref) \ + _(MOD, N , ref, ref) \ + _(POW, N , ref, ref) \ + _(NEG, N , ref, ref) \ + \ + _(ABS, N , ref, ref) \ + _(ATAN2, N , ref, ref) \ + _(LDEXP, N , ref, ref) \ + _(MIN, C , ref, ref) \ + _(MAX, C , ref, ref) \ + _(FPMATH, N , ref, lit) \ + \ + /* Overflow-checking arithmetic ops. */ \ + _(ADDOV, CW, ref, ref) \ + _(SUBOV, NW, ref, ref) \ + _(MULOV, CW, ref, ref) \ + \ + /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \ + \ + /* Memory references. */ \ + _(AREF, R , ref, ref) \ + _(HREFK, R , ref, ref) \ + _(HREF, L , ref, ref) \ + _(NEWREF, S , ref, ref) \ + _(UREFO, LW, ref, lit) \ + _(UREFC, LW, ref, lit) \ + _(FREF, R , ref, lit) \ + _(STRREF, N , ref, ref) \ + \ + /* Loads and Stores. These must be in the same order. */ \ + _(ALOAD, L , ref, ___) \ + _(HLOAD, L , ref, ___) \ + _(ULOAD, L , ref, ___) \ + _(FLOAD, L , ref, lit) \ + _(XLOAD, L , ref, lit) \ + _(SLOAD, L , lit, lit) \ + _(VLOAD, L , ref, ___) \ + \ + _(ASTORE, S , ref, ref) \ + _(HSTORE, S , ref, ref) \ + _(USTORE, S , ref, ref) \ + _(FSTORE, S , ref, ref) \ + _(XSTORE, S , ref, ref) \ + \ + /* Allocations. */ \ + _(SNEW, N , ref, ref) /* CSE is ok, not marked as A. */ \ + _(XSNEW, A , ref, ref) \ + _(TNEW, AW, lit, lit) \ + _(TDUP, AW, ref, ___) \ + _(CNEW, AW, ref, ref) \ + _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \ + \ + /* Barriers. */ \ + _(TBAR, S , ref, ___) \ + _(OBAR, S , ref, ref) \ + _(XBAR, S , ___, ___) \ + \ + /* Type conversions. */ \ + _(CONV, NW, ref, lit) \ + _(TOBIT, N , ref, ref) \ + _(TOSTR, N , ref, ___) \ + _(STRTO, N , ref, ___) \ + \ + /* Calls. */ \ + _(CALLN, N , ref, lit) \ + _(CALLL, L , ref, lit) \ + _(CALLS, S , ref, lit) \ + _(CALLXS, S , ref, ref) \ + _(CARG, N , ref, ref) \ + \ + /* End of list. */ + +/* IR opcodes (max. 256). */ +typedef enum { +#define IRENUM(name, m, m1, m2) IR_##name, +IRDEF(IRENUM) +#undef IRENUM + IR__MAX +} IROp; + +/* Stored opcode. */ +typedef uint8_t IROp1; + +LJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE); +LJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE); +LJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT); +LJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT); +LJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT); + +/* Delta between xLOAD and xSTORE. */ +#define IRDELTA_L2S ((int)IR_ASTORE - (int)IR_ALOAD) + +LJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE); +LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE); +LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE); +LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE); + +/* -- Named IR literals --------------------------------------------------- */ + +/* FPMATH sub-functions. ORDER FPM. */ +#define IRFPMDEF(_) \ + _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \ + _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \ + _(SIN) _(COS) _(TAN) \ + _(OTHER) + +typedef enum { +#define FPMENUM(name) IRFPM_##name, +IRFPMDEF(FPMENUM) +#undef FPMENUM + IRFPM__MAX +} IRFPMathOp; + +/* FLOAD fields. */ +#define IRFLDEF(_) \ + _(STR_LEN, offsetof(GCstr, len)) \ + _(FUNC_ENV, offsetof(GCfunc, l.env)) \ + _(FUNC_PC, offsetof(GCfunc, l.pc)) \ + _(TAB_META, offsetof(GCtab, metatable)) \ + _(TAB_ARRAY, offsetof(GCtab, array)) \ + _(TAB_NODE, offsetof(GCtab, node)) \ + _(TAB_ASIZE, offsetof(GCtab, asize)) \ + _(TAB_HMASK, offsetof(GCtab, hmask)) \ + _(TAB_NOMM, offsetof(GCtab, nomm)) \ + _(UDATA_META, offsetof(GCudata, metatable)) \ + _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \ + _(UDATA_FILE, sizeof(GCudata)) \ + _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \ + _(CDATA_PTR, sizeof(GCcdata)) \ + _(CDATA_INT, sizeof(GCcdata)) \ + _(CDATA_INT64, sizeof(GCcdata)) \ + _(CDATA_INT64_4, sizeof(GCcdata) + 4) + +typedef enum { +#define FLENUM(name, ofs) IRFL_##name, +IRFLDEF(FLENUM) +#undef FLENUM + IRFL__MAX +} IRFieldID; + +/* SLOAD mode bits, stored in op2. */ +#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */ +#define IRSLOAD_FRAME 0x02 /* Load hiword of frame. */ +#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */ +#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */ +#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */ +#define IRSLOAD_INHERIT 0x20 /* Inherited by exits/side traces. */ + +/* XLOAD mode, stored in op2. */ +#define IRXLOAD_READONLY 1 /* Load from read-only data. */ +#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */ +#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */ + +/* CONV mode, stored in op2. */ +#define IRCONV_SRCMASK 0x001f /* Source IRType. */ +#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */ +#define IRCONV_DSH 5 +#define IRCONV_NUM_INT ((IRT_NUM<>2)&3)) +#define irm_iscomm(m) ((m) & IRM_C) +#define irm_kind(m) ((m) & IRM_S) + +#define IRMODE(name, m, m1, m2) (((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W), + +LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1]; + +/* -- IR instruction types ------------------------------------------------ */ + +/* Map of itypes to non-negative numbers. ORDER LJ_T. +** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for +** IRT_P32 and IRT_P64, which never escape the IR. +** The various integers are only used in the IR and can only escape to +** a TValue after implicit or explicit conversion. Their types must be +** contiguous and next to IRT_NUM (see the typerange macros below). +*/ +#define IRTDEF(_) \ + _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \ + _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \ + _(TAB, 4) _(UDATA, 4) \ + _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \ + _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \ + _(SOFTFP, 4) /* There is room for 9 more types. */ + +/* IR result type and flags (8 bit). */ +typedef enum { +#define IRTENUM(name, size) IRT_##name, +IRTDEF(IRTENUM) +#undef IRTENUM + IRT__MAX, + + /* Native pointer type and the corresponding integer type. */ + IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32, + IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT, + IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32, + + /* Additional flags. */ + IRT_MARK = 0x20, /* Marker for misc. purposes. */ + IRT_ISPHI = 0x40, /* Instruction is left or right PHI operand. */ + IRT_GUARD = 0x80, /* Instruction is a guard. */ + + /* Masks. */ + IRT_TYPE = 0x1f, + IRT_T = 0xff +} IRType; + +#define irtype_ispri(irt) ((uint32_t)(irt) <= IRT_TRUE) + +/* Stored IRType. */ +typedef struct IRType1 { uint8_t irt; } IRType1; + +#define IRT(o, t) ((uint32_t)(((o)<<8) | (t))) +#define IRTI(o) (IRT((o), IRT_INT)) +#define IRTN(o) (IRT((o), IRT_NUM)) +#define IRTG(o, t) (IRT((o), IRT_GUARD|(t))) +#define IRTGI(o) (IRT((o), IRT_GUARD|IRT_INT)) + +#define irt_t(t) ((IRType)(t).irt) +#define irt_type(t) ((IRType)((t).irt & IRT_TYPE)) +#define irt_sametype(t1, t2) ((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0) +#define irt_typerange(t, first, last) \ + ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first)) + +#define irt_isnil(t) (irt_type(t) == IRT_NIL) +#define irt_ispri(t) ((uint32_t)irt_type(t) <= IRT_TRUE) +#define irt_islightud(t) (irt_type(t) == IRT_LIGHTUD) +#define irt_isstr(t) (irt_type(t) == IRT_STR) +#define irt_istab(t) (irt_type(t) == IRT_TAB) +#define irt_iscdata(t) (irt_type(t) == IRT_CDATA) +#define irt_isfloat(t) (irt_type(t) == IRT_FLOAT) +#define irt_isnum(t) (irt_type(t) == IRT_NUM) +#define irt_isint(t) (irt_type(t) == IRT_INT) +#define irt_isi8(t) (irt_type(t) == IRT_I8) +#define irt_isu8(t) (irt_type(t) == IRT_U8) +#define irt_isi16(t) (irt_type(t) == IRT_I16) +#define irt_isu16(t) (irt_type(t) == IRT_U16) +#define irt_isu32(t) (irt_type(t) == IRT_U32) +#define irt_isi64(t) (irt_type(t) == IRT_I64) +#define irt_isu64(t) (irt_type(t) == IRT_U64) + +#define irt_isfp(t) (irt_isnum(t) || irt_isfloat(t)) +#define irt_isinteger(t) (irt_typerange((t), IRT_I8, IRT_INT)) +#define irt_isgcv(t) (irt_typerange((t), IRT_STR, IRT_UDATA)) +#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA)) +#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64)) + +#if LJ_64 +#define IRT_IS64 \ + ((1u<> irt_type(t)) & 1) +#define irt_is64orfp(t) (((IRT_IS64|(1u<>irt_type(t)) & 1) + +#define irt_size(t) (lj_ir_type_size[irt_t((t))]) + +LJ_DATA const uint8_t lj_ir_type_size[]; + +static LJ_AINLINE IRType itype2irt(const TValue *tv) +{ + if (tvisint(tv)) + return IRT_INT; + else if (tvisnum(tv)) + return IRT_NUM; +#if LJ_64 + else if (tvislightud(tv)) + return IRT_LIGHTUD; +#endif + else + return (IRType)~itype(tv); +} + +static LJ_AINLINE uint32_t irt_toitype_(IRType t) +{ + lua_assert(!LJ_64 || t != IRT_LIGHTUD); + if (LJ_DUALNUM && t > IRT_NUM) { + return LJ_TISNUM; + } else { + lua_assert(t <= IRT_NUM); + return ~(uint32_t)t; + } +} + +#define irt_toitype(t) irt_toitype_(irt_type((t))) + +#define irt_isguard(t) ((t).irt & IRT_GUARD) +#define irt_ismarked(t) ((t).irt & IRT_MARK) +#define irt_setmark(t) ((t).irt |= IRT_MARK) +#define irt_clearmark(t) ((t).irt &= ~IRT_MARK) +#define irt_isphi(t) ((t).irt & IRT_ISPHI) +#define irt_setphi(t) ((t).irt |= IRT_ISPHI) +#define irt_clearphi(t) ((t).irt &= ~IRT_ISPHI) + +/* Stored combined IR opcode and type. */ +typedef uint16_t IROpT; + +/* -- IR references ------------------------------------------------------- */ + +/* IR references. */ +typedef uint16_t IRRef1; /* One stored reference. */ +typedef uint32_t IRRef2; /* Two stored references. */ +typedef uint32_t IRRef; /* Used to pass around references. */ + +/* Fixed references. */ +enum { + REF_BIAS = 0x8000, + REF_TRUE = REF_BIAS-3, + REF_FALSE = REF_BIAS-2, + REF_NIL = REF_BIAS-1, /* \--- Constants grow downwards. */ + REF_BASE = REF_BIAS, /* /--- IR grows upwards. */ + REF_FIRST = REF_BIAS+1, + REF_DROP = 0xffff +}; + +/* Note: IRMlit operands must be < REF_BIAS, too! +** This allows for fast and uniform manipulation of all operands +** without looking up the operand mode in lj_ir_mode: +** - CSE calculates the maximum reference of two operands. +** This must work with mixed reference/literal operands, too. +** - DCE marking only checks for operand >= REF_BIAS. +** - LOOP needs to substitute reference operands. +** Constant references and literals must not be modified. +*/ + +#define IRREF2(lo, hi) ((IRRef2)(lo) | ((IRRef2)(hi) << 16)) + +#define irref_isk(ref) ((ref) < REF_BIAS) + +/* Tagged IR references (32 bit). +** +** +-------+-------+---------------+ +** | irt | flags | ref | +** +-------+-------+---------------+ +** +** The tag holds a copy of the IRType and speeds up IR type checks. +*/ +typedef uint32_t TRef; + +#define TREF_REFMASK 0x0000ffff +#define TREF_FRAME 0x00010000 +#define TREF_CONT 0x00020000 + +#define TREF(ref, t) ((TRef)((ref) + ((t)<<24))) + +#define tref_ref(tr) ((IRRef1)(tr)) +#define tref_t(tr) ((IRType)((tr)>>24)) +#define tref_type(tr) ((IRType)(((tr)>>24) & IRT_TYPE)) +#define tref_typerange(tr, first, last) \ + ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first)) + +#define tref_istype(tr, t) (((tr) & (IRT_TYPE<<24)) == ((t)<<24)) +#define tref_isnil(tr) (tref_istype((tr), IRT_NIL)) +#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE)) +#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE)) +#define tref_isstr(tr) (tref_istype((tr), IRT_STR)) +#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC)) +#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA)) +#define tref_istab(tr) (tref_istype((tr), IRT_TAB)) +#define tref_isudata(tr) (tref_istype((tr), IRT_UDATA)) +#define tref_isnum(tr) (tref_istype((tr), IRT_NUM)) +#define tref_isint(tr) (tref_istype((tr), IRT_INT)) + +#define tref_isbool(tr) (tref_typerange((tr), IRT_FALSE, IRT_TRUE)) +#define tref_ispri(tr) (tref_typerange((tr), IRT_NIL, IRT_TRUE)) +#define tref_istruecond(tr) (!tref_typerange((tr), IRT_NIL, IRT_FALSE)) +#define tref_isinteger(tr) (tref_typerange((tr), IRT_I8, IRT_INT)) +#define tref_isnumber(tr) (tref_typerange((tr), IRT_NUM, IRT_INT)) +#define tref_isnumber_str(tr) (tref_isnumber((tr)) || tref_isstr((tr))) +#define tref_isgcv(tr) (tref_typerange((tr), IRT_STR, IRT_UDATA)) + +#define tref_isk(tr) (irref_isk(tref_ref((tr)))) +#define tref_isk2(tr1, tr2) (irref_isk(tref_ref((tr1) | (tr2)))) + +#define TREF_PRI(t) (TREF(REF_NIL-(t), (t))) +#define TREF_NIL (TREF_PRI(IRT_NIL)) +#define TREF_FALSE (TREF_PRI(IRT_FALSE)) +#define TREF_TRUE (TREF_PRI(IRT_TRUE)) + +/* -- IR format ----------------------------------------------------------- */ + +/* IR instruction format (64 bit). +** +** 16 16 8 8 8 8 +** +-------+-------+---+---+---+---+ +** | op1 | op2 | t | o | r | s | +** +-------+-------+---+---+---+---+ +** | op12/i/gco | ot | prev | (alternative fields in union) +** +---------------+-------+-------+ +** 32 16 16 +** +** prev is only valid prior to register allocation and then reused for r + s. +*/ + +typedef union IRIns { + struct { + LJ_ENDIAN_LOHI( + IRRef1 op1; /* IR operand 1. */ + , IRRef1 op2; /* IR operand 2. */ + ) + IROpT ot; /* IR opcode and type (overlaps t and o). */ + IRRef1 prev; /* Previous ins in same chain (overlaps r and s). */ + }; + struct { + IRRef2 op12; /* IR operand 1 and 2 (overlaps op1 and op2). */ + LJ_ENDIAN_LOHI( + IRType1 t; /* IR type. */ + , IROp1 o; /* IR opcode. */ + ) + LJ_ENDIAN_LOHI( + uint8_t r; /* Register allocation (overlaps prev). */ + , uint8_t s; /* Spill slot allocation (overlaps prev). */ + ) + }; + int32_t i; /* 32 bit signed integer literal (overlaps op12). */ + GCRef gcr; /* GCobj constant (overlaps op12). */ + MRef ptr; /* Pointer constant (overlaps op12). */ +} IRIns; + +#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr)) +#define ir_kstr(ir) (gco2str(ir_kgc((ir)))) +#define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) +#define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) +#define ir_kcdata(ir) (gco2cd(ir_kgc((ir)))) +#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue)) +#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) +#define ir_k64(ir) \ + check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) +#define ir_kptr(ir) \ + check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void)) + +/* A store or any other op with a non-weak guard has a side-effect. */ +static LJ_AINLINE int ir_sideeff(IRIns *ir) +{ + return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S); +} + +LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ircall.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ircall.h new file mode 100644 index 0000000..af30ba8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_ircall.h @@ -0,0 +1,271 @@ +/* +** IR CALL* instruction definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IRCALL_H +#define _LJ_IRCALL_H + +#include "lj_obj.h" +#include "lj_ir.h" +#include "lj_jit.h" + +/* C call info for CALL* instructions. */ +typedef struct CCallInfo { + ASMFunction func; /* Function pointer. */ + uint32_t flags; /* Number of arguments and flags. */ +} CCallInfo; + +#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */ +#define CCI_NARGS_MAX 32 /* Max. # of args. */ + +#define CCI_OTSHIFT 16 +#define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */ +#define CCI_OPSHIFT 24 +#define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */ + +#define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT) +#define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT) +#define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT) +#define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL) +#define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL) +#define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL) + +/* C call info flags. */ +#define CCI_L 0x0100 /* Implicit L arg. */ +#define CCI_CASTU64 0x0200 /* Cast u64 result to number. */ +#define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */ +#define CCI_VARARG 0x0800 /* Vararg function. */ + +#define CCI_CC_MASK 0x3000 /* Calling convention mask. */ +#define CCI_CC_SHIFT 12 +/* ORDER CC */ +#define CCI_CC_CDECL 0x0000 /* Default cdecl calling convention. */ +#define CCI_CC_THISCALL 0x1000 /* Thiscall calling convention. */ +#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */ +#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */ + +/* Helpers for conditional function definitions. */ +#define IRCALLCOND_ANY(x) x + +#if LJ_TARGET_X86ORX64 +#define IRCALLCOND_FPMATH(x) NULL +#else +#define IRCALLCOND_FPMATH(x) x +#endif + +#if LJ_SOFTFP +#define IRCALLCOND_SOFTFP(x) x +#if LJ_HASFFI +#define IRCALLCOND_SOFTFP_FFI(x) x +#else +#define IRCALLCOND_SOFTFP_FFI(x) NULL +#endif +#else +#define IRCALLCOND_SOFTFP(x) NULL +#define IRCALLCOND_SOFTFP_FFI(x) NULL +#endif + +#define LJ_NEED_FP64 (LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS) + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +#define IRCALLCOND_FP64_FFI(x) x +#else +#define IRCALLCOND_FP64_FFI(x) NULL +#endif + +#if LJ_HASFFI +#define IRCALLCOND_FFI(x) x +#if LJ_32 +#define IRCALLCOND_FFI32(x) x +#else +#define IRCALLCOND_FFI32(x) NULL +#endif +#else +#define IRCALLCOND_FFI(x) NULL +#define IRCALLCOND_FFI32(x) NULL +#endif + +#if LJ_SOFTFP +#define ARG1_FP 2 /* Treat as 2 32 bit arguments. */ +#else +#define ARG1_FP 1 +#endif + +#if LJ_32 +#define ARG2_64 4 /* Treat as 4 32 bit arguments. */ +#else +#define ARG2_64 2 +#endif + +/* Function definitions for CALL* instructions. */ +#define IRCALLDEF(_) \ + _(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \ + _(ANY, lj_str_new, 3, S, STR, CCI_L) \ + _(ANY, lj_strscan_num, 2, FN, INT, 0) \ + _(ANY, lj_str_fromint, 2, FN, STR, CCI_L) \ + _(ANY, lj_str_fromnum, 2, FN, STR, CCI_L) \ + _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \ + _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \ + _(ANY, lj_tab_newkey, 3, S, P32, CCI_L) \ + _(ANY, lj_tab_len, 1, FL, INT, 0) \ + _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \ + _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \ + _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \ + _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \ + _(ANY, lj_vm_modi, 2, FN, INT, 0) \ + _(ANY, sinh, ARG1_FP, N, NUM, 0) \ + _(ANY, cosh, ARG1_FP, N, NUM, 0) \ + _(ANY, tanh, ARG1_FP, N, NUM, 0) \ + _(ANY, fputc, 2, S, INT, 0) \ + _(ANY, fwrite, 4, S, INT, 0) \ + _(ANY, fflush, 1, S, INT, 0) \ + /* ORDER FPM */ \ + _(FPMATH, lj_vm_floor, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_ceil, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_trunc, ARG1_FP, N, NUM, 0) \ + _(FPMATH, sqrt, ARG1_FP, N, NUM, 0) \ + _(FPMATH, exp, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_exp2, ARG1_FP, N, NUM, 0) \ + _(FPMATH, log, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_log2, ARG1_FP, N, NUM, 0) \ + _(FPMATH, log10, ARG1_FP, N, NUM, 0) \ + _(FPMATH, sin, ARG1_FP, N, NUM, 0) \ + _(FPMATH, cos, ARG1_FP, N, NUM, 0) \ + _(FPMATH, tan, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_powi, ARG1_FP+1, N, NUM, 0) \ + _(FPMATH, pow, ARG1_FP*2, N, NUM, 0) \ + _(FPMATH, atan2, ARG1_FP*2, N, NUM, 0) \ + _(FPMATH, ldexp, ARG1_FP+1, N, NUM, 0) \ + _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \ + _(SOFTFP, softfp_add, 4, N, NUM, 0) \ + _(SOFTFP, softfp_sub, 4, N, NUM, 0) \ + _(SOFTFP, softfp_mul, 4, N, NUM, 0) \ + _(SOFTFP, softfp_div, 4, N, NUM, 0) \ + _(SOFTFP, softfp_cmp, 4, N, NIL, 0) \ + _(SOFTFP, softfp_i2d, 1, N, NUM, 0) \ + _(SOFTFP, softfp_d2i, 2, N, INT, 0) \ + _(SOFTFP_FFI, softfp_ui2d, 1, N, NUM, 0) \ + _(SOFTFP_FFI, softfp_f2d, 1, N, NUM, 0) \ + _(SOFTFP_FFI, softfp_d2ui, 2, N, INT, 0) \ + _(SOFTFP_FFI, softfp_d2f, 2, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_i2f, 1, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \ + _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \ + _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_d2l, ARG1_FP, N, I64, 0) \ + _(FP64_FFI, fp64_d2ul, ARG1_FP, N, U64, 0) \ + _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \ + _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \ + _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \ + _(FFI, strlen, 1, L, INTP, 0) \ + _(FFI, memcpy, 3, S, PTR, 0) \ + _(FFI, memset, 3, S, PTR, 0) \ + _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \ + _(FFI32, lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) + \ + /* End of list. */ + +typedef enum { +#define IRCALLENUM(cond, name, nargs, kind, type, flags) IRCALL_##name, +IRCALLDEF(IRCALLENUM) +#undef IRCALLENUM + IRCALL__MAX +} IRCallID; + +LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...); + +LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1]; + +/* Soft-float declarations. */ +#if LJ_SOFTFP +#if LJ_TARGET_ARM +#define softfp_add __aeabi_dadd +#define softfp_sub __aeabi_dsub +#define softfp_mul __aeabi_dmul +#define softfp_div __aeabi_ddiv +#define softfp_cmp __aeabi_cdcmple +#define softfp_i2d __aeabi_i2d +#define softfp_d2i __aeabi_d2iz +#define softfp_ui2d __aeabi_ui2d +#define softfp_f2d __aeabi_f2d +#define softfp_d2ui __aeabi_d2uiz +#define softfp_d2f __aeabi_d2f +#define softfp_i2f __aeabi_i2f +#define softfp_ui2f __aeabi_ui2f +#define softfp_f2i __aeabi_f2iz +#define softfp_f2ui __aeabi_f2uiz +#define fp64_l2d __aeabi_l2d +#define fp64_ul2d __aeabi_ul2d +#define fp64_l2f __aeabi_l2f +#define fp64_ul2f __aeabi_ul2f +#if LJ_TARGET_IOS +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi +#else +#define fp64_d2l __aeabi_d2lz +#define fp64_d2ul __aeabi_d2ulz +#define fp64_f2l __aeabi_f2lz +#define fp64_f2ul __aeabi_f2ulz +#endif +#else +#error "Missing soft-float definitions for target architecture" +#endif +extern double softfp_add(double a, double b); +extern double softfp_sub(double a, double b); +extern double softfp_mul(double a, double b); +extern double softfp_div(double a, double b); +extern void softfp_cmp(double a, double b); +extern double softfp_i2d(int32_t a); +extern int32_t softfp_d2i(double a); +#if LJ_HASFFI +extern double softfp_ui2d(uint32_t a); +extern double softfp_f2d(float a); +extern uint32_t softfp_d2ui(double a); +extern float softfp_d2f(double a); +extern float softfp_i2f(int32_t a); +extern float softfp_ui2f(uint32_t a); +extern int32_t softfp_f2i(float a); +extern uint32_t softfp_f2ui(float a); +#endif +#endif + +#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP) +#ifdef __GNUC__ +#define fp64_l2d __floatdidf +#define fp64_ul2d __floatundidf +#define fp64_l2f __floatdisf +#define fp64_ul2f __floatundisf +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi +#else +#error "Missing fp64 helper definitions for this compiler" +#endif +#endif + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +extern double fp64_l2d(int64_t a); +extern double fp64_ul2d(uint64_t a); +extern float fp64_l2f(int64_t a); +extern float fp64_ul2f(uint64_t a); +extern int64_t fp64_d2l(double a); +extern uint64_t fp64_d2ul(double a); +extern int64_t fp64_f2l(float a); +extern uint64_t fp64_f2ul(float a); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_iropt.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_iropt.h new file mode 100644 index 0000000..e45ae2b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_iropt.h @@ -0,0 +1,161 @@ +/* +** Common header for IR emitter and optimizations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IROPT_H +#define _LJ_IROPT_H + +#include + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* IR emitter. */ +LJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J); + +/* Save current IR in J->fold.ins, but do not emit it (yet). */ +static LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b) +{ + J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b; +} + +#define lj_ir_set(J, ot, a, b) \ + lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b)) + +/* Get ref of next IR instruction and optionally grow IR. +** Note: this may invalidate all IRIns*! +*/ +static LJ_AINLINE IRRef lj_ir_nextins(jit_State *J) +{ + IRRef ref = J->cur.nins; + if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J); + J->cur.nins = ref + 1; + return ref; +} + +/* Interning of constants. */ +LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k); +LJ_FUNC void lj_ir_k64_freeall(jit_State *J); +LJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv); +LJ_FUNC cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n); +LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t); +LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr); +LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t); +LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot); + +#if LJ_64 +#define lj_ir_kintp(J, k) lj_ir_kint64(J, (uint64_t)(k)) +#else +#define lj_ir_kintp(J, k) lj_ir_kint(J, (int32_t)(k)) +#endif + +static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n) +{ + TValue tv; + tv.n = n; + return lj_ir_knum_u64(J, tv.u64); +} + +#define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR) +#define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB) +#define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC) +#define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr)) +#define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr)) + +/* Special FP constants. */ +#define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000)) +#define lj_ir_knum_one(J) lj_ir_knum_u64(J, U64x(3ff00000,00000000)) +#define lj_ir_knum_tobit(J) lj_ir_knum_u64(J, U64x(43380000,00000000)) + +/* Special 128 bit SIMD constants. */ +#define lj_ir_knum_abs(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_ABS)) +#define lj_ir_knum_neg(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_NEG)) + +/* Access to constants. */ +LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir); + +/* Convert IR operand types. */ +LJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr); + +/* Miscellaneous IR ops. */ +LJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op); +LJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op); +LJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref); + +/* Emit IR instructions with on-the-fly optimizations. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim); + +/* Special return values for the fold functions. */ +enum { + NEXTFOLD, /* Couldn't fold, pass on. */ + RETRYFOLD, /* Retry fold with modified fins. */ + KINTFOLD, /* Return ref for int constant in fins->i. */ + FAILFOLD, /* Guard would always fail. */ + DROPFOLD, /* Guard eliminated. */ + MAX_FOLD +}; + +#define INTFOLD(k) ((J->fold.ins.i = (k)), (TRef)KINTFOLD) +#define INT64FOLD(k) (lj_ir_kint64(J, (k))) +#define CONDFOLD(cond) ((TRef)FAILFOLD + (TRef)(cond)) +#define LEFTFOLD (J->fold.ins.op1) +#define RIGHTFOLD (J->fold.ins.op2) +#define CSEFOLD (lj_opt_cse(J)) +#define EMITFOLD (lj_ir_emit(J)) + +/* Load/store forwarding. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J); +LJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J); +LJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim); +LJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref); + +/* Dead-store elimination. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J); + +/* Narrowing. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr); +#if LJ_HASFFI +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key); +#endif +LJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc, + TValue *vb, TValue *vc, IROp op); +LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc); +LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc); +LJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc); +LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase); + +/* Optimization passes. */ +LJ_FUNC void lj_opt_dce(jit_State *J); +LJ_FUNC int lj_opt_loop(jit_State *J); +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) +LJ_FUNC void lj_opt_split(jit_State *J); +#else +#define lj_opt_split(J) UNUSED(J) +#endif +LJ_FUNC void lj_opt_sink(jit_State *J); + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_jit.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_jit.h new file mode 100644 index 0000000..b69e4f4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_jit.h @@ -0,0 +1,416 @@ +/* +** Common definitions for the JIT compiler. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_JIT_H +#define _LJ_JIT_H + +#include "lj_obj.h" +#include "lj_ir.h" + +/* JIT engine flags. */ +#define JIT_F_ON 0x00000001 + +/* CPU-specific JIT engine flags. */ +#if LJ_TARGET_X86ORX64 +#define JIT_F_CMOV 0x00000010 +#define JIT_F_SSE2 0x00000020 +#define JIT_F_SSE3 0x00000040 +#define JIT_F_SSE4_1 0x00000080 +#define JIT_F_P4 0x00000100 +#define JIT_F_PREFER_IMUL 0x00000200 +#define JIT_F_SPLIT_XMM 0x00000400 +#define JIT_F_LEA_AGU 0x00000800 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_CMOV +#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM" +#elif LJ_TARGET_ARM +#define JIT_F_ARMV6_ 0x00000010 +#define JIT_F_ARMV6T2_ 0x00000020 +#define JIT_F_ARMV7 0x00000040 +#define JIT_F_VFPV2 0x00000080 +#define JIT_F_VFPV3 0x00000100 + +#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7) +#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7) +#define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3) + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_ARMV6_ +#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3" +#elif LJ_TARGET_PPC +#define JIT_F_SQRT 0x00000010 +#define JIT_F_ROUND 0x00000020 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_SQRT +#define JIT_F_CPUSTRING "\4SQRT\5ROUND" +#elif LJ_TARGET_MIPS +#define JIT_F_MIPS32R2 0x00000010 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_MIPS32R2 +#define JIT_F_CPUSTRING "\010MIPS32R2" +#else +#define JIT_F_CPU_FIRST 0 +#define JIT_F_CPUSTRING "" +#endif + +/* Optimization flags. */ +#define JIT_F_OPT_MASK 0x0fff0000 + +#define JIT_F_OPT_FOLD 0x00010000 +#define JIT_F_OPT_CSE 0x00020000 +#define JIT_F_OPT_DCE 0x00040000 +#define JIT_F_OPT_FWD 0x00080000 +#define JIT_F_OPT_DSE 0x00100000 +#define JIT_F_OPT_NARROW 0x00200000 +#define JIT_F_OPT_LOOP 0x00400000 +#define JIT_F_OPT_ABC 0x00800000 +#define JIT_F_OPT_SINK 0x01000000 +#define JIT_F_OPT_FUSE 0x02000000 + +/* Optimizations names for -O. Must match the order above. */ +#define JIT_F_OPT_FIRST JIT_F_OPT_FOLD +#define JIT_F_OPTSTRING \ + "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse" + +/* Optimization levels set a fixed combination of flags. */ +#define JIT_F_OPT_0 0 +#define JIT_F_OPT_1 (JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE) +#define JIT_F_OPT_2 (JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP) +#define JIT_F_OPT_3 (JIT_F_OPT_2|\ + JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE) +#define JIT_F_OPT_DEFAULT JIT_F_OPT_3 + +#if LJ_TARGET_WINDOWS || LJ_64 +/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ +#define JIT_P_sizemcode_DEFAULT 64 +#else +/* Could go as low as 4K, but the mmap() overhead would be rather high. */ +#define JIT_P_sizemcode_DEFAULT 32 +#endif + +/* Optimization parameters and their defaults. Length is a char in octal! */ +#define JIT_PARAMDEF(_) \ + _(\010, maxtrace, 1000) /* Max. # of traces in cache. */ \ + _(\011, maxrecord, 4000) /* Max. # of recorded IR instructions. */ \ + _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \ + _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \ + _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \ + \ + _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \ + _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \ + _(\007, tryside, 4) /* # of attempts to compile a side trace. */ \ + \ + _(\012, instunroll, 4) /* Max. unroll for instable loops. */ \ + _(\012, loopunroll, 15) /* Max. unroll for loop ops in side traces. */ \ + _(\012, callunroll, 3) /* Max. unroll for recursive calls. */ \ + _(\011, recunroll, 2) /* Min. unroll for true recursion. */ \ + \ + /* Size of each machine code area (in KBytes). */ \ + _(\011, sizemcode, JIT_P_sizemcode_DEFAULT) \ + /* Max. total size of all machine code areas (in KBytes). */ \ + _(\010, maxmcode, 512) \ + /* End of list. */ + +enum { +#define JIT_PARAMENUM(len, name, value) JIT_P_##name, +JIT_PARAMDEF(JIT_PARAMENUM) +#undef JIT_PARAMENUM + JIT_P__MAX +}; + +#define JIT_PARAMSTR(len, name, value) #len #name +#define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR) + +/* Trace compiler state. */ +typedef enum { + LJ_TRACE_IDLE, /* Trace compiler idle. */ + LJ_TRACE_ACTIVE = 0x10, + LJ_TRACE_RECORD, /* Bytecode recording active. */ + LJ_TRACE_START, /* New trace started. */ + LJ_TRACE_END, /* End of trace. */ + LJ_TRACE_ASM, /* Assemble trace. */ + LJ_TRACE_ERR /* Trace aborted with error. */ +} TraceState; + +/* Post-processing action. */ +typedef enum { + LJ_POST_NONE, /* No action. */ + LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */ + LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */ + LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */ + LJ_POST_FIXBOOL, /* Fixup boolean result. */ + LJ_POST_FIXCONST, /* Fixup constant results. */ + LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */ +} PostProc; + +/* Machine code type. */ +#if LJ_TARGET_X86ORX64 +typedef uint8_t MCode; +#else +typedef uint32_t MCode; +#endif + +/* Stack snapshot header. */ +typedef struct SnapShot { + uint16_t mapofs; /* Offset into snapshot map. */ + IRRef1 ref; /* First IR ref for this snapshot. */ + uint8_t nslots; /* Number of valid slots. */ + uint8_t topslot; /* Maximum frame extent. */ + uint8_t nent; /* Number of compressed entries. */ + uint8_t count; /* Count of taken exits for this snapshot. */ +} SnapShot; + +#define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */ + +/* Compressed snapshot entry. */ +typedef uint32_t SnapEntry; + +#define SNAP_FRAME 0x010000 /* Frame slot. */ +#define SNAP_CONT 0x020000 /* Continuation slot. */ +#define SNAP_NORESTORE 0x040000 /* No need to restore slot. */ +#define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */ +LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME); +LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT); + +#define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref)) +#define SNAP_TR(slot, tr) \ + (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK))) +#define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc)) +#define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz)) +#define snap_ref(sn) ((sn) & 0xffff) +#define snap_slot(sn) ((BCReg)((sn) >> 24)) +#define snap_isframe(sn) ((sn) & SNAP_FRAME) +#define snap_pc(sn) ((const BCIns *)(uintptr_t)(sn)) +#define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref)) + +/* Snapshot and exit numbers. */ +typedef uint32_t SnapNo; +typedef uint32_t ExitNo; + +/* Trace number. */ +typedef uint32_t TraceNo; /* Used to pass around trace numbers. */ +typedef uint16_t TraceNo1; /* Stored trace number. */ + +/* Type of link. ORDER LJ_TRLINK */ +typedef enum { + LJ_TRLINK_NONE, /* Incomplete trace. No link, yet. */ + LJ_TRLINK_ROOT, /* Link to other root trace. */ + LJ_TRLINK_LOOP, /* Loop to same trace. */ + LJ_TRLINK_TAILREC, /* Tail-recursion. */ + LJ_TRLINK_UPREC, /* Up-recursion. */ + LJ_TRLINK_DOWNREC, /* Down-recursion. */ + LJ_TRLINK_INTERP, /* Fallback to interpreter. */ + LJ_TRLINK_RETURN /* Return to interpreter. */ +} TraceLink; + +/* Trace object. */ +typedef struct GCtrace { + GCHeader; + uint8_t topslot; /* Top stack slot already checked to be allocated. */ + uint8_t linktype; /* Type of link. */ + IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */ + GCRef gclist; + IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */ + IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */ + uint16_t nsnap; /* Number of snapshots. */ + uint16_t nsnapmap; /* Number of snapshot map elements. */ + SnapShot *snap; /* Snapshot array. */ + SnapEntry *snapmap; /* Snapshot map. */ + GCRef startpt; /* Starting prototype. */ + MRef startpc; /* Bytecode PC of starting instruction. */ + BCIns startins; /* Original bytecode of starting instruction. */ + MSize szmcode; /* Size of machine code. */ + MCode *mcode; /* Start of machine code. */ + MSize mcloop; /* Offset of loop start in machine code. */ + uint16_t nchild; /* Number of child traces (root trace only). */ + uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */ + TraceNo1 traceno; /* Trace number. */ + TraceNo1 link; /* Linked trace (or self for loops). */ + TraceNo1 root; /* Root trace of side trace (or 0 for root traces). */ + TraceNo1 nextroot; /* Next root trace for same prototype. */ + TraceNo1 nextside; /* Next side trace of same root trace. */ + uint8_t sinktags; /* Trace has SINK tags. */ + uint8_t unused1; +#ifdef LUAJIT_USE_GDBJIT + void *gdbjit_entry; /* GDB JIT entry. */ +#endif +} GCtrace; + +#define gco2trace(o) check_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o)) +#define traceref(J, n) \ + check_exp((n)>0 && (MSize)(n)sizetrace, (GCtrace *)gcref(J->trace[(n)])) + +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist)); + +static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap) +{ + if (snap+1 == &T->snap[T->nsnap]) + return T->nsnapmap; + else + return (snap+1)->mapofs; +} + +/* Round-robin penalty cache for bytecodes leading to aborted traces. */ +typedef struct HotPenalty { + MRef pc; /* Starting bytecode PC. */ + uint16_t val; /* Penalty value, i.e. hotcount start. */ + uint16_t reason; /* Abort reason (really TraceErr). */ +} HotPenalty; + +#define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */ +#define PENALTY_MIN (36*2) /* Minimum penalty value. */ +#define PENALTY_MAX 60000 /* Maximum penalty value. */ +#define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */ + +/* Round-robin backpropagation cache for narrowing conversions. */ +typedef struct BPropEntry { + IRRef1 key; /* Key: original reference. */ + IRRef1 val; /* Value: reference after conversion. */ + IRRef mode; /* Mode for this entry (currently IRCONV_*). */ +} BPropEntry; + +/* Number of slots for the backpropagation cache. Must be a power of 2. */ +#define BPROP_SLOTS 16 + +/* Scalar evolution analysis cache. */ +typedef struct ScEvEntry { + IRRef1 idx; /* Index reference. */ + IRRef1 start; /* Constant start reference. */ + IRRef1 stop; /* Constant stop reference. */ + IRRef1 step; /* Constant step reference. */ + IRType1 t; /* Scalar type. */ + uint8_t dir; /* Direction. 1: +, 0: -. */ +} ScEvEntry; + +/* 128 bit SIMD constants. */ +enum { + LJ_KSIMD_ABS, + LJ_KSIMD_NEG, + LJ_KSIMD__MAX +}; + +/* Get 16 byte aligned pointer to SIMD constant. */ +#define LJ_KSIMD(J, n) \ + ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15)) + +/* Set/reset flag to activate the SPLIT pass for the current trace. */ +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) +#define lj_needsplit(J) (J->needsplit = 1) +#define lj_resetsplit(J) (J->needsplit = 0) +#else +#define lj_needsplit(J) UNUSED(J) +#define lj_resetsplit(J) UNUSED(J) +#endif + +/* Fold state is used to fold instructions on-the-fly. */ +typedef struct FoldState { + IRIns ins; /* Currently emitted instruction. */ + IRIns left; /* Instruction referenced by left operand. */ + IRIns right; /* Instruction referenced by right operand. */ +} FoldState; + +/* JIT compiler state. */ +typedef struct jit_State { + GCtrace cur; /* Current trace. */ + + lua_State *L; /* Current Lua state. */ + const BCIns *pc; /* Current PC. */ + GCfunc *fn; /* Current function. */ + GCproto *pt; /* Current prototype. */ + TRef *base; /* Current frame base, points into J->slots. */ + + uint32_t flags; /* JIT engine flags. */ + BCReg maxslot; /* Relative to baseslot. */ + BCReg baseslot; /* Current frame base, offset into J->slots. */ + + uint8_t mergesnap; /* Allowed to merge with next snapshot. */ + uint8_t needsnap; /* Need snapshot before recording next bytecode. */ + IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */ + uint8_t bcskip; /* Number of bytecode instructions to skip. */ + + FoldState fold; /* Fold state. */ + + const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */ + MSize bc_extent; /* Extent of the range. */ + + TraceState state; /* Trace compiler state. */ + + int32_t instunroll; /* Unroll counter for instable loops. */ + int32_t loopunroll; /* Unroll counter for loop ops in side traces. */ + int32_t tailcalled; /* Number of successive tailcalls. */ + int32_t framedepth; /* Current frame depth. */ + int32_t retdepth; /* Return frame depth (count of RETF). */ + + MRef k64; /* Pointer to chained array of 64 bit constants. */ + TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */ + + IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */ + IRRef irtoplim; /* Upper limit of instuction buffer (biased). */ + IRRef irbotlim; /* Lower limit of instuction buffer (biased). */ + IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */ + + MSize sizesnap; /* Size of temp. snapshot buffer. */ + SnapShot *snapbuf; /* Temp. snapshot buffer. */ + SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */ + MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ + + PostProc postproc; /* Required post-processing after execution. */ +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) + int needsplit; /* Need SPLIT pass. */ +#endif + + GCRef *trace; /* Array of traces. */ + TraceNo freetrace; /* Start of scan for next free trace. */ + MSize sizetrace; /* Size of trace array. */ + + IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */ + TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */ + + int32_t param[JIT_P__MAX]; /* JIT engine parameters. */ + + MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */ + + HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ + uint32_t penaltyslot; /* Round-robin index into penalty slots. */ + uint32_t prngstate; /* PRNG state. */ + + BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ + uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ + + ScEvEntry scev; /* Scalar evolution analysis cache slots. */ + + const BCIns *startpc; /* Bytecode PC of starting instruction. */ + TraceNo parent; /* Parent of current side trace (0 for root traces). */ + ExitNo exitno; /* Exit number in parent of current side trace. */ + + BCIns *patchpc; /* PC for pending re-patch. */ + BCIns patchins; /* Instruction for pending re-patch. */ + + int mcprot; /* Protection of current mcode area. */ + MCode *mcarea; /* Base of current mcode area. */ + MCode *mctop; /* Top of current mcode area. */ + MCode *mcbot; /* Bottom of current mcode area. */ + size_t szmcarea; /* Size of current mcode area. */ + size_t szallmcarea; /* Total size of all allocated mcode areas. */ + + TValue errinfo; /* Additional info element for trace errors. */ +} +#if LJ_TARGET_ARM +LJ_ALIGN(16) /* For DISPATCH-relative addresses in assembler part. */ +#endif +jit_State; + +/* Trivial PRNG e.g. used for penalty randomization. */ +static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits) +{ + /* Yes, this LCG is very weak, but that doesn't matter for our use case. */ + J->prngstate = J->prngstate * 1103515245 + 12345; + return J->prngstate >> (32-bits); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.c new file mode 100644 index 0000000..4fa3931 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.c @@ -0,0 +1,481 @@ +/* +** Lexical analyzer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_lex_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#if LJ_HASFFI +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lualib.h" +#endif +#include "lj_state.h" +#include "lj_lex.h" +#include "lj_parse.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* Lua lexer token names. */ +static const char *const tokennames[] = { +#define TKSTR1(name) #name, +#define TKSTR2(name, sym) #sym, +TKDEF(TKSTR1, TKSTR2) +#undef TKSTR1 +#undef TKSTR2 + NULL +}; + +/* -- Buffer handling ----------------------------------------------------- */ + +#define char2int(c) ((int)(uint8_t)(c)) +#define next(ls) \ + (ls->current = (ls->n--) > 0 ? char2int(*ls->p++) : fillbuf(ls)) +#define save_and_next(ls) (save(ls, ls->current), next(ls)) +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') +#define END_OF_STREAM (-1) + +static int fillbuf(LexState *ls) +{ + size_t sz; + const char *buf = ls->rfunc(ls->L, ls->rdata, &sz); + if (buf == NULL || sz == 0) return END_OF_STREAM; + ls->n = (MSize)sz - 1; + ls->p = buf; + return char2int(*(ls->p++)); +} + +static LJ_NOINLINE void save_grow(LexState *ls, int c) +{ + MSize newsize; + if (ls->sb.sz >= LJ_MAX_STR/2) + lj_lex_error(ls, 0, LJ_ERR_XELEM); + newsize = ls->sb.sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, newsize); + ls->sb.buf[ls->sb.n++] = (char)c; +} + +static LJ_AINLINE void save(LexState *ls, int c) +{ + if (LJ_UNLIKELY(ls->sb.n + 1 > ls->sb.sz)) + save_grow(ls, c); + else + ls->sb.buf[ls->sb.n++] = (char)c; +} + +static void inclinenumber(LexState *ls) +{ + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= LJ_MAX_LINE) + lj_lex_error(ls, ls->token, LJ_ERR_XLINES); +} + +/* -- Scanner for terminals ----------------------------------------------- */ + +/* Parse a number literal. */ +static void lex_number(LexState *ls, TValue *tv) +{ + StrScanFmt fmt; + int c, xp = 'e'; + lua_assert(lj_char_isdigit(ls->current)); + if ((c = ls->current) == '0') { + save_and_next(ls); + if ((ls->current | 0x20) == 'x') xp = 'p'; + } + while (lj_char_isident(ls->current) || ls->current == '.' || + ((ls->current == '-' || ls->current == '+') && (c | 0x20) == xp)) { + c = ls->current; + save_and_next(ls); + } + save(ls, '\0'); + fmt = lj_strscan_scan((const uint8_t *)ls->sb.buf, tv, + (LJ_DUALNUM ? STRSCAN_OPT_TOINT : STRSCAN_OPT_TONUM) | + (LJ_HASFFI ? (STRSCAN_OPT_LL|STRSCAN_OPT_IMAG) : 0)); + if (LJ_DUALNUM && fmt == STRSCAN_INT) { + setitype(tv, LJ_TISNUM); + } else if (fmt == STRSCAN_NUM) { + /* Already in correct format. */ +#if LJ_HASFFI + } else if (fmt != STRSCAN_ERROR) { + lua_State *L = ls->L; + GCcdata *cd; + lua_assert(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG); + if (!ctype_ctsG(G(L))) { + ptrdiff_t oldtop = savestack(L, L->top); + luaopen_ffi(L); /* Load FFI library on-demand. */ + L->top = restorestack(L, oldtop); + } + if (fmt == STRSCAN_IMAG) { + cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); + ((double *)cdataptr(cd))[0] = 0; + ((double *)cdataptr(cd))[1] = numV(tv); + } else { + cd = lj_cdata_new_(L, fmt==STRSCAN_I64 ? CTID_INT64 : CTID_UINT64, 8); + *(uint64_t *)cdataptr(cd) = tv->u64; + } + lj_parse_keepcdata(ls, tv, cd); +#endif + } else { + lua_assert(fmt == STRSCAN_ERROR); + lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER); + } +} + +static int skip_sep(LexState *ls) +{ + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + +static void read_long_string(LexState *ls, TValue *tv, int sep) +{ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case END_OF_STREAM: + lj_lex_error(ls, TK_eof, tv ? LJ_ERR_XLSTR : LJ_ERR_XLCOM); + break; + case ']': + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ + goto endloop; + } + break; + case '\n': + case '\r': + save(ls, '\n'); + inclinenumber(ls); + if (!tv) lj_str_resetbuf(&ls->sb); /* avoid wasting space */ + break; + default: + if (tv) save_and_next(ls); + else next(ls); + break; + } + } endloop: + if (tv) { + GCstr *str = lj_parse_keepstr(ls, ls->sb.buf + (2 + (MSize)sep), + ls->sb.n - 2*(2 + (MSize)sep)); + setstrV(ls->L, tv, str); + } +} + +static void read_string(LexState *ls, int delim, TValue *tv) +{ + save_and_next(ls); + while (ls->current != delim) { + switch (ls->current) { + case END_OF_STREAM: + lj_lex_error(ls, TK_eof, LJ_ERR_XSTR); + continue; + case '\n': + case '\r': + lj_lex_error(ls, TK_string, LJ_ERR_XSTR); + continue; + case '\\': { + int c = next(ls); /* Skip the '\\'. */ + switch (c) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'x': /* Hexadecimal escape '\xXX'. */ + c = (next(ls) & 15u) << 4; + if (!lj_char_isdigit(ls->current)) { + if (!lj_char_isxdigit(ls->current)) goto err_xesc; + c += 9 << 4; + } + c += (next(ls) & 15u); + if (!lj_char_isdigit(ls->current)) { + if (!lj_char_isxdigit(ls->current)) goto err_xesc; + c += 9; + } + break; + case 'z': /* Skip whitespace. */ + next(ls); + while (lj_char_isspace(ls->current)) + if (currIsNewline(ls)) inclinenumber(ls); else next(ls); + continue; + case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case '\\': case '\"': case '\'': break; + case END_OF_STREAM: continue; + default: + if (!lj_char_isdigit(c)) + goto err_xesc; + c -= '0'; /* Decimal escape '\ddd'. */ + if (lj_char_isdigit(next(ls))) { + c = c*10 + (ls->current - '0'); + if (lj_char_isdigit(next(ls))) { + c = c*10 + (ls->current - '0'); + if (c > 255) { + err_xesc: + lj_lex_error(ls, TK_string, LJ_ERR_XESC); + } + next(ls); + } + } + save(ls, c); + continue; + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + break; + } + } + save_and_next(ls); /* skip delimiter */ + setstrV(ls->L, tv, lj_parse_keepstr(ls, ls->sb.buf + 1, ls->sb.n - 2)); +} + +/* -- Main lexical scanner ------------------------------------------------ */ + +static int llex(LexState *ls, TValue *tv) +{ + lj_str_resetbuf(&ls->sb); + for (;;) { + if (lj_char_isident(ls->current)) { + GCstr *s; + if (lj_char_isdigit(ls->current)) { /* Numeric literal. */ + lex_number(ls, tv); + return TK_number; + } + /* Identifier or reserved word. */ + do { + save_and_next(ls); + } while (lj_char_isident(ls->current)); + s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n); + setstrV(ls->L, tv, s); + if (s->reserved > 0) /* Reserved word? */ + return TK_OFS + s->reserved; + return TK_name; + } + switch (ls->current) { + case '\n': + case '\r': + inclinenumber(ls); + continue; + case ' ': + case '\t': + case '\v': + case '\f': + next(ls); + continue; + case '-': + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + lj_str_resetbuf(&ls->sb); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + lj_str_resetbuf(&ls->sb); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != END_OF_STREAM) + next(ls); + continue; + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, tv, sep); + return TK_string; + } else if (sep == -1) { + return '['; + } else { + lj_lex_error(ls, TK_string, LJ_ERR_XLDELIM); + continue; + } + } + case '=': + next(ls); + if (ls->current != '=') return '='; else { next(ls); return TK_eq; } + case '<': + next(ls); + if (ls->current != '=') return '<'; else { next(ls); return TK_le; } + case '>': + next(ls); + if (ls->current != '=') return '>'; else { next(ls); return TK_ge; } + case '~': + next(ls); + if (ls->current != '=') return '~'; else { next(ls); return TK_ne; } + case ':': + next(ls); + if (ls->current != ':') return ':'; else { next(ls); return TK_label; } + case '"': + case '\'': + read_string(ls, ls->current, tv); + return TK_string; + case '.': + save_and_next(ls); + if (ls->current == '.') { + next(ls); + if (ls->current == '.') { + next(ls); + return TK_dots; /* ... */ + } + return TK_concat; /* .. */ + } else if (!lj_char_isdigit(ls->current)) { + return '.'; + } else { + lex_number(ls, tv); + return TK_number; + } + case END_OF_STREAM: + return TK_eof; + default: { + int c = ls->current; + next(ls); + return c; /* Single-char tokens (+ - / ...). */ + } + } + } +} + +/* -- Lexer API ----------------------------------------------------------- */ + +/* Setup lexer state. */ +int lj_lex_setup(lua_State *L, LexState *ls) +{ + int header = 0; + ls->L = L; + ls->fs = NULL; + ls->n = 0; + ls->p = NULL; + ls->vstack = NULL; + ls->sizevstack = 0; + ls->vtop = 0; + ls->bcstack = NULL; + ls->sizebcstack = 0; + ls->lookahead = TK_eof; /* No look-ahead token. */ + ls->linenumber = 1; + ls->lastline = 1; + lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); + next(ls); /* Read-ahead first char. */ + if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && + char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ + ls->n -= 2; + ls->p += 2; + next(ls); + header = 1; + } + if (ls->current == '#') { /* Skip POSIX #! header line. */ + do { + next(ls); + if (ls->current == END_OF_STREAM) return 0; + } while (!currIsNewline(ls)); + inclinenumber(ls); + header = 1; + } + if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */ + if (header) { + /* + ** Loading bytecode with an extra header is disabled for security + ** reasons. This may circumvent the usual check for bytecode vs. + ** Lua code by looking at the first char. Since this is a potential + ** security violation no attempt is made to echo the chunkname either. + */ + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD)); + lj_err_throw(L, LUA_ERRSYNTAX); + } + return 1; + } + return 0; +} + +/* Cleanup lexer state. */ +void lj_lex_cleanup(lua_State *L, LexState *ls) +{ + global_State *g = G(L); + lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine); + lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo); + lj_str_freebuf(g, &ls->sb); +} + +void lj_lex_next(LexState *ls) +{ + ls->lastline = ls->linenumber; + if (LJ_LIKELY(ls->lookahead == TK_eof)) { /* No lookahead token? */ + ls->token = llex(ls, &ls->tokenval); /* Get next token. */ + } else { /* Otherwise return lookahead token. */ + ls->token = ls->lookahead; + ls->lookahead = TK_eof; + ls->tokenval = ls->lookaheadval; + } +} + +LexToken lj_lex_lookahead(LexState *ls) +{ + lua_assert(ls->lookahead == TK_eof); + ls->lookahead = llex(ls, &ls->lookaheadval); + return ls->lookahead; +} + +const char *lj_lex_token2str(LexState *ls, LexToken token) +{ + if (token > TK_OFS) + return tokennames[token-TK_OFS-1]; + else if (!lj_char_iscntrl(token)) + return lj_str_pushf(ls->L, "%c", token); + else + return lj_str_pushf(ls->L, "char(%d)", token); +} + +void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...) +{ + const char *tok; + va_list argp; + if (token == 0) { + tok = NULL; + } else if (token == TK_name || token == TK_string || token == TK_number) { + save(ls, '\0'); + tok = ls->sb.buf; + } else { + tok = lj_lex_token2str(ls, token); + } + va_start(argp, em); + lj_err_lex(ls->L, ls->chunkname, tok, ls->linenumber, em, argp); + va_end(argp); +} + +void lj_lex_init(lua_State *L) +{ + uint32_t i; + for (i = 0; i < TK_RESERVED; i++) { + GCstr *s = lj_str_newz(L, tokennames[i]); + fixstring(s); /* Reserved words are never collected. */ + s->reserved = (uint8_t)(i+1); + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.h new file mode 100644 index 0000000..a7ff29a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lex.h @@ -0,0 +1,85 @@ +/* +** Lexical analyzer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_LEX_H +#define _LJ_LEX_H + +#include + +#include "lj_obj.h" +#include "lj_err.h" + +/* Lua lexer tokens. */ +#define TKDEF(_, __) \ + _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \ + _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \ + _(repeat) _(return) _(then) _(true) _(until) _(while) \ + __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \ + __(label, ::) __(number, ) __(name, ) __(string, ) \ + __(eof, ) + +enum { + TK_OFS = 256, +#define TKENUM1(name) TK_##name, +#define TKENUM2(name, sym) TK_##name, +TKDEF(TKENUM1, TKENUM2) +#undef TKENUM1 +#undef TKENUM2 + TK_RESERVED = TK_while - TK_OFS +}; + +typedef int LexToken; + +/* Combined bytecode ins/line. Only used during bytecode generation. */ +typedef struct BCInsLine { + BCIns ins; /* Bytecode instruction. */ + BCLine line; /* Line number for this bytecode. */ +} BCInsLine; + +/* Info for local variables. Only used during bytecode generation. */ +typedef struct VarInfo { + GCRef name; /* Local variable name or goto/label name. */ + BCPos startpc; /* First point where the local variable is active. */ + BCPos endpc; /* First point where the local variable is dead. */ + uint8_t slot; /* Variable slot. */ + uint8_t info; /* Variable/goto/label info. */ +} VarInfo; + +/* Lua lexer state. */ +typedef struct LexState { + struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */ + struct lua_State *L; /* Lua state. */ + TValue tokenval; /* Current token value. */ + TValue lookaheadval; /* Lookahead token value. */ + int current; /* Current character (charint). */ + LexToken token; /* Current token. */ + LexToken lookahead; /* Lookahead token. */ + MSize n; /* Bytes left in input buffer. */ + const char *p; /* Current position in input buffer. */ + SBuf sb; /* String buffer for tokens. */ + lua_Reader rfunc; /* Reader callback. */ + void *rdata; /* Reader callback data. */ + BCLine linenumber; /* Input line counter. */ + BCLine lastline; /* Line of last token. */ + GCstr *chunkname; /* Current chunk name (interned string). */ + const char *chunkarg; /* Chunk name argument. */ + const char *mode; /* Allow loading bytecode (b) and/or source text (t). */ + VarInfo *vstack; /* Stack for names and extents of local variables. */ + MSize sizevstack; /* Size of variable stack. */ + MSize vtop; /* Top of variable stack. */ + BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */ + MSize sizebcstack; /* Size of bytecode stack. */ + uint32_t level; /* Syntactical nesting level. */ +} LexState; + +LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls); +LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls); +LJ_FUNC void lj_lex_next(LexState *ls); +LJ_FUNC LexToken lj_lex_lookahead(LexState *ls); +LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token); +LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...); +LJ_FUNC void lj_lex_init(lua_State *L); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.c new file mode 100644 index 0000000..76c8a06 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.c @@ -0,0 +1,258 @@ +/* +** Library function support. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_lib_c +#define LUA_CORE + +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_bc.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* -- Library initialization ---------------------------------------------- */ + +static GCtab *lib_create_table(lua_State *L, const char *libname, int hsize) +{ + if (libname) { + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_getfield(L, -1, libname); + if (!tvistab(L->top-1)) { + L->top--; + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, hsize) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, libname); + settabV(L, L->top, tabV(L->top-1)); + L->top++; + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + L->top--; + settabV(L, L->top-1, tabV(L->top)); + } else { + lua_createtable(L, 0, hsize); + } + return tabV(L->top-1); +} + +void lj_lib_register(lua_State *L, const char *libname, + const uint8_t *p, const lua_CFunction *cf) +{ + GCtab *env = tabref(L->env); + GCfunc *ofn = NULL; + int ffid = *p++; + BCIns *bcff = &L2GG(L)->bcff[*p++]; + GCtab *tab = lib_create_table(L, libname, *p++); + ptrdiff_t tpos = L->top - L->base; + + /* Avoid barriers further down. */ + lj_gc_anybarriert(L, tab); + tab->nomm = 0; + + for (;;) { + uint32_t tag = *p++; + MSize len = tag & LIBINIT_LENMASK; + tag &= LIBINIT_TAGMASK; + if (tag != LIBINIT_STRING) { + const char *name; + MSize nuv = (MSize)(L->top - L->base - tpos); + GCfunc *fn = lj_func_newC(L, nuv, env); + if (nuv) { + L->top = L->base + tpos; + memcpy(fn->c.upvalue, L->top, sizeof(TValue)*nuv); + } + fn->c.ffid = (uint8_t)(ffid++); + name = (const char *)p; + p += len; + if (tag == LIBINIT_CF) + setmref(fn->c.pc, &G(L)->bc_cfunc_int); + else + setmref(fn->c.pc, bcff++); + if (tag == LIBINIT_ASM_) + fn->c.f = ofn->c.f; /* Copy handler from previous function. */ + else + fn->c.f = *cf++; /* Get cf or handler from C function table. */ + if (len) { + /* NOBARRIER: See above for common barrier. */ + setfuncV(L, lj_tab_setstr(L, tab, lj_str_new(L, name, len)), fn); + } + ofn = fn; + } else { + switch (tag | len) { + case LIBINIT_SET: + L->top -= 2; + if (tvisstr(L->top+1) && strV(L->top+1)->len == 0) + env = tabV(L->top); + else /* NOBARRIER: See above for common barrier. */ + copyTV(L, lj_tab_set(L, tab, L->top+1), L->top); + break; + case LIBINIT_NUMBER: + memcpy(&L->top->n, p, sizeof(double)); + L->top++; + p += sizeof(double); + break; + case LIBINIT_COPY: + copyTV(L, L->top, L->top - *p++); + L->top++; + break; + case LIBINIT_LASTCL: + setfuncV(L, L->top++, ofn); + break; + case LIBINIT_FFID: + ffid++; + break; + case LIBINIT_END: + return; + default: + setstrV(L, L->top++, lj_str_new(L, (const char *)p, len)); + p += len; + break; + } + } + } +} + +/* -- Type checks --------------------------------------------------------- */ + +TValue *lj_lib_checkany(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + return o; +} + +GCstr *lj_lib_checkstr(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o < L->top) { + if (LJ_LIKELY(tvisstr(o))) { + return strV(o); + } else if (tvisnumber(o)) { + GCstr *s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + return s; + } + } + lj_err_argt(L, narg, LUA_TSTRING); + return NULL; /* unreachable */ +} + +GCstr *lj_lib_optstr(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL; +} + +#if LJ_DUALNUM +void lj_lib_checknumber(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); +} +#endif + +lua_Number lj_lib_checknum(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && + (tvisnumber(o) || (tvisstr(o) && lj_strscan_num(strV(o), o))))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_UNLIKELY(tvisint(o))) { + lua_Number n = (lua_Number)intV(o); + setnumV(o, n); + return n; + } else { + return numV(o); + } +} + +int32_t lj_lib_checkint(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else { + int32_t i = lj_num2int(numV(o)); + if (LJ_DUALNUM) setintV(o, i); + return i; + } +} + +int32_t lj_lib_optint(lua_State *L, int narg, int32_t def) +{ + TValue *o = L->base + narg-1; + return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def; +} + +int32_t lj_lib_checkbit(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else { + int32_t i = lj_num2bit(numV(o)); + if (LJ_DUALNUM) setintV(o, i); + return i; + } +} + +GCfunc *lj_lib_checkfunc(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tvisfunc(o))) + lj_err_argt(L, narg, LUA_TFUNCTION); + return funcV(o); +} + +GCtab *lj_lib_checktab(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tvistab(o))) + lj_err_argt(L, narg, LUA_TTABLE); + return tabV(o); +} + +GCtab *lj_lib_checktabornil(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o < L->top) { + if (tvistab(o)) + return tabV(o); + else if (tvisnil(o)) + return NULL; + } + lj_err_arg(L, narg, LJ_ERR_NOTABN); + return NULL; /* unreachable */ +} + +int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst) +{ + GCstr *s = def >= 0 ? lj_lib_optstr(L, narg) : lj_lib_checkstr(L, narg); + if (s) { + const char *opt = strdata(s); + MSize len = s->len; + int i; + for (i = 0; *(const uint8_t *)lst; i++) { + if (*(const uint8_t *)lst == len && memcmp(opt, lst+1, len) == 0) + return i; + lst += 1+*(const uint8_t *)lst; + } + lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt); + } + return def; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.h new file mode 100644 index 0000000..daacb92 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_lib.h @@ -0,0 +1,112 @@ +/* +** Library function support. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_LIB_H +#define _LJ_LIB_H + +#include "lj_obj.h" + +/* +** A fallback handler is called by the assembler VM if the fast path fails: +** +** - too few arguments: unrecoverable. +** - wrong argument type: recoverable, if coercion succeeds. +** - bad argument value: unrecoverable. +** - stack overflow: recoverable, if stack reallocation succeeds. +** - extra handling: recoverable. +** +** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(), +** lj_err_caller() or lj_err_callermsg(). +** The recoverable cases return 0 or the number of results + 1. +** The assembler VM retries the fast path only if 0 is returned. +** This time the fallback must not be called again or it gets stuck in a loop. +*/ + +/* Return values from fallback handler. */ +#define FFH_RETRY 0 +#define FFH_UNREACHABLE FFH_RETRY +#define FFH_RES(n) ((n)+1) +#define FFH_TAILCALL (-1) + +LJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg); +LJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg); +LJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg); +#if LJ_DUALNUM +LJ_FUNC void lj_lib_checknumber(lua_State *L, int narg); +#else +#define lj_lib_checknumber(L, narg) lj_lib_checknum((L), (narg)) +#endif +LJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg); +LJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg); +LJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def); +LJ_FUNC int32_t lj_lib_checkbit(lua_State *L, int narg); +LJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg); +LJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg); +LJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg); +LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst); + +/* Avoid including lj_frame.h. */ +#define lj_lib_upvalue(L, n) \ + (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1]) + +#if LJ_TARGET_WINDOWS +#define lj_lib_checkfpu(L) \ + do { setnumV(L->top++, (lua_Number)1437217655); \ + if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \ + L->top--; } while (0) +#else +#define lj_lib_checkfpu(L) UNUSED(L) +#endif + +/* Push internal function on the stack. */ +static LJ_AINLINE void lj_lib_pushcc(lua_State *L, lua_CFunction f, + int id, int n) +{ + GCfunc *fn; + lua_pushcclosure(L, f, n); + fn = funcV(L->top-1); + fn->c.ffid = (uint8_t)id; + setmref(fn->c.pc, &G(L)->bc_cfunc_int); +} + +#define lj_lib_pushcf(L, fn, id) (lj_lib_pushcc(L, (fn), (id), 0)) + +/* Library function declarations. Scanned by buildvm. */ +#define LJLIB_CF(name) static int lj_cf_##name(lua_State *L) +#define LJLIB_ASM(name) static int lj_ffh_##name(lua_State *L) +#define LJLIB_ASM_(name) +#define LJLIB_SET(name) +#define LJLIB_PUSH(arg) +#define LJLIB_REC(handler) +#define LJLIB_NOREGUV +#define LJLIB_NOREG + +#define LJ_LIB_REG(L, regname, name) \ + lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name) + +LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, + const uint8_t *init, const lua_CFunction *cf); + +/* Library init data tags. */ +#define LIBINIT_LENMASK 0x3f +#define LIBINIT_TAGMASK 0xc0 +#define LIBINIT_CF 0x00 +#define LIBINIT_ASM 0x40 +#define LIBINIT_ASM_ 0x80 +#define LIBINIT_STRING 0xc0 +#define LIBINIT_MAXSTR 0x39 +#define LIBINIT_SET 0xfa +#define LIBINIT_NUMBER 0xfb +#define LIBINIT_COPY 0xfc +#define LIBINIT_LASTCL 0xfd +#define LIBINIT_FFID 0xfe +#define LIBINIT_END 0xff + +/* Exported library functions. */ + +typedef struct RandomState RandomState; +LJ_FUNC uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_libdef.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_libdef.h new file mode 100644 index 0000000..c52f874 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_libdef.h @@ -0,0 +1,393 @@ +/* This is a generated file. DO NOT EDIT! */ + +#ifdef LJLIB_MODULE_base +#undef LJLIB_MODULE_base +static const lua_CFunction lj_lib_cf_base[] = { + lj_ffh_assert, + lj_ffh_next, + lj_ffh_pairs, + lj_ffh_ipairs_aux, + lj_ffh_ipairs, + lj_ffh_setmetatable, + lj_cf_getfenv, + lj_cf_setfenv, + lj_ffh_rawget, + lj_cf_rawset, + lj_cf_rawequal, + lj_cf_unpack, + lj_cf_select, + lj_ffh_tonumber, + lj_ffh_tostring, + lj_cf_error, + lj_ffh_pcall, + lj_cf_loadfile, + lj_cf_load, + lj_cf_loadstring, + lj_cf_dofile, + lj_cf_gcinfo, + lj_cf_collectgarbage, + lj_cf_newproxy, + lj_cf_print +}; +static const uint8_t lj_lib_init_base[] = { +2,0,28,70,97,115,115,101,114,116,195,110,105,108,199,98,111,111,108,101,97, +110,252,1,200,117,115,101,114,100,97,116,97,198,115,116,114,105,110,103,197, +117,112,118,97,108,198,116,104,114,101,97,100,197,112,114,111,116,111,200,102, +117,110,99,116,105,111,110,197,116,114,97,99,101,197,99,100,97,116,97,197,116, +97,98,108,101,252,9,198,110,117,109,98,101,114,132,116,121,112,101,68,110,101, +120,116,253,69,112,97,105,114,115,64,253,70,105,112,97,105,114,115,140,103, +101,116,109,101,116,97,116,97,98,108,101,76,115,101,116,109,101,116,97,116, +97,98,108,101,7,103,101,116,102,101,110,118,7,115,101,116,102,101,110,118,70, +114,97,119,103,101,116,6,114,97,119,115,101,116,8,114,97,119,101,113,117,97, +108,6,117,110,112,97,99,107,6,115,101,108,101,99,116,72,116,111,110,117,109, +98,101,114,195,110,105,108,197,102,97,108,115,101,196,116,114,117,101,72,116, +111,115,116,114,105,110,103,5,101,114,114,111,114,69,112,99,97,108,108,134, +120,112,99,97,108,108,8,108,111,97,100,102,105,108,101,4,108,111,97,100,10, +108,111,97,100,115,116,114,105,110,103,6,100,111,102,105,108,101,6,103,99,105, +110,102,111,14,99,111,108,108,101,99,116,103,97,114,98,97,103,101,252,2,8,110, +101,119,112,114,111,120,121,200,116,111,115,116,114,105,110,103,5,112,114,105, +110,116,252,3,200,95,86,69,82,83,73,79,78,250,255 +}; +#endif + +#ifdef LJLIB_MODULE_coroutine +#undef LJLIB_MODULE_coroutine +static const lua_CFunction lj_lib_cf_coroutine[] = { + lj_cf_coroutine_status, + lj_cf_coroutine_running, + lj_cf_coroutine_create, + lj_ffh_coroutine_yield, + lj_ffh_coroutine_resume, + lj_cf_coroutine_wrap +}; +static const uint8_t lj_lib_init_coroutine[] = { +30,13,6,6,115,116,97,116,117,115,7,114,117,110,110,105,110,103,6,99,114,101, +97,116,101,69,121,105,101,108,100,70,114,101,115,117,109,101,254,4,119,114, +97,112,255 +}; +#endif + +#ifdef LJLIB_MODULE_math +#undef LJLIB_MODULE_math +static const lua_CFunction lj_lib_cf_math[] = { + lj_ffh_math_abs, + lj_ffh_math_sqrt, + lj_ffh_math_log, + lj_ffh_math_atan2, + lj_ffh_math_ldexp, + lj_ffh_math_min, + lj_cf_math_random, + lj_cf_math_randomseed +}; +static const uint8_t lj_lib_init_math[] = { +37,16,30,67,97,98,115,133,102,108,111,111,114,132,99,101,105,108,68,115,113, +114,116,133,108,111,103,49,48,131,101,120,112,131,115,105,110,131,99,111,115, +131,116,97,110,132,97,115,105,110,132,97,99,111,115,132,97,116,97,110,132,115, +105,110,104,132,99,111,115,104,132,116,97,110,104,133,102,114,101,120,112,132, +109,111,100,102,251,248,193,99,26,220,165,76,64,131,100,101,103,251,57,157, +82,162,70,223,145,63,131,114,97,100,67,108,111,103,69,97,116,97,110,50,131, +112,111,119,132,102,109,111,100,69,108,100,101,120,112,67,109,105,110,131,109, +97,120,251,24,45,68,84,251,33,9,64,194,112,105,250,251,0,0,0,0,0,0,240,127, +196,104,117,103,101,250,252,2,6,114,97,110,100,111,109,252,2,10,114,97,110, +100,111,109,115,101,101,100,255 +}; +#endif + +#ifdef LJLIB_MODULE_bit +#undef LJLIB_MODULE_bit +static const lua_CFunction lj_lib_cf_bit[] = { + lj_ffh_bit_tobit, + lj_ffh_bit_lshift, + lj_ffh_bit_band, + lj_cf_bit_tohex +}; +static const uint8_t lj_lib_init_bit[] = { +65,42,12,69,116,111,98,105,116,132,98,110,111,116,133,98,115,119,97,112,70, +108,115,104,105,102,116,134,114,115,104,105,102,116,135,97,114,115,104,105, +102,116,131,114,111,108,131,114,111,114,68,98,97,110,100,131,98,111,114,132, +98,120,111,114,5,116,111,104,101,120,255 +}; +#endif + +#ifdef LJLIB_MODULE_string +#undef LJLIB_MODULE_string +static const lua_CFunction lj_lib_cf_string[] = { + lj_ffh_string_len, + lj_ffh_string_byte, + lj_ffh_string_char, + lj_ffh_string_sub, + lj_ffh_string_rep, + lj_ffh_string_reverse, + lj_cf_string_dump, + lj_cf_string_find, + lj_cf_string_match, + lj_cf_string_gmatch, + lj_cf_string_gsub, + lj_cf_string_format +}; +static const uint8_t lj_lib_init_string[] = { +77,53,14,67,108,101,110,68,98,121,116,101,68,99,104,97,114,67,115,117,98,67, +114,101,112,71,114,101,118,101,114,115,101,133,108,111,119,101,114,133,117, +112,112,101,114,4,100,117,109,112,4,102,105,110,100,5,109,97,116,99,104,254, +6,103,109,97,116,99,104,4,103,115,117,98,6,102,111,114,109,97,116,255 +}; +#endif + +#ifdef LJLIB_MODULE_table +#undef LJLIB_MODULE_table +static const lua_CFunction lj_lib_cf_table[] = { + lj_cf_table_foreachi, + lj_cf_table_foreach, + lj_ffh_table_getn, + lj_cf_table_maxn, + lj_cf_table_insert, + lj_cf_table_remove, + lj_cf_table_concat, + lj_cf_table_sort +}; +static const uint8_t lj_lib_init_table[] = { +92,61,8,8,102,111,114,101,97,99,104,105,7,102,111,114,101,97,99,104,68,103, +101,116,110,4,109,97,120,110,6,105,110,115,101,114,116,6,114,101,109,111,118, +101,6,99,111,110,99,97,116,4,115,111,114,116,255 +}; +#endif + +#ifdef LJLIB_MODULE_io_method +#undef LJLIB_MODULE_io_method +static const lua_CFunction lj_lib_cf_io_method[] = { + lj_cf_io_method_close, + lj_cf_io_method_read, + lj_cf_io_method_write, + lj_cf_io_method_flush, + lj_cf_io_method_seek, + lj_cf_io_method_setvbuf, + lj_cf_io_method_lines, + lj_cf_io_method___gc, + lj_cf_io_method___tostring +}; +static const uint8_t lj_lib_init_io_method[] = { +100,62,10,5,99,108,111,115,101,4,114,101,97,100,5,119,114,105,116,101,5,102, +108,117,115,104,4,115,101,101,107,7,115,101,116,118,98,117,102,5,108,105,110, +101,115,4,95,95,103,99,10,95,95,116,111,115,116,114,105,110,103,252,1,199,95, +95,105,110,100,101,120,250,255 +}; +#endif + +#ifdef LJLIB_MODULE_io +#undef LJLIB_MODULE_io +static const lua_CFunction lj_lib_cf_io[] = { + lj_cf_io_open, + lj_cf_io_popen, + lj_cf_io_tmpfile, + lj_cf_io_close, + lj_cf_io_read, + lj_cf_io_write, + lj_cf_io_flush, + lj_cf_io_input, + lj_cf_io_output, + lj_cf_io_lines, + lj_cf_io_type +}; +static const uint8_t lj_lib_init_io[] = { +109,62,12,252,2,192,250,4,111,112,101,110,5,112,111,112,101,110,7,116,109,112, +102,105,108,101,5,99,108,111,115,101,4,114,101,97,100,5,119,114,105,116,101, +5,102,108,117,115,104,5,105,110,112,117,116,6,111,117,116,112,117,116,5,108, +105,110,101,115,4,116,121,112,101,255 +}; +#endif + +#ifdef LJLIB_MODULE_os +#undef LJLIB_MODULE_os +static const lua_CFunction lj_lib_cf_os[] = { + lj_cf_os_execute, + lj_cf_os_remove, + lj_cf_os_rename, + lj_cf_os_tmpname, + lj_cf_os_getenv, + lj_cf_os_exit, + lj_cf_os_clock, + lj_cf_os_date, + lj_cf_os_time, + lj_cf_os_difftime, + lj_cf_os_setlocale +}; +static const uint8_t lj_lib_init_os[] = { +120,62,11,7,101,120,101,99,117,116,101,6,114,101,109,111,118,101,6,114,101, +110,97,109,101,7,116,109,112,110,97,109,101,6,103,101,116,101,110,118,4,101, +120,105,116,5,99,108,111,99,107,4,100,97,116,101,4,116,105,109,101,8,100,105, +102,102,116,105,109,101,9,115,101,116,108,111,99,97,108,101,255 +}; +#endif + +#ifdef LJLIB_MODULE_debug +#undef LJLIB_MODULE_debug +static const lua_CFunction lj_lib_cf_debug[] = { + lj_cf_debug_getregistry, + lj_cf_debug_getmetatable, + lj_cf_debug_setmetatable, + lj_cf_debug_getfenv, + lj_cf_debug_setfenv, + lj_cf_debug_getinfo, + lj_cf_debug_getlocal, + lj_cf_debug_setlocal, + lj_cf_debug_getupvalue, + lj_cf_debug_setupvalue, + lj_cf_debug_upvalueid, + lj_cf_debug_upvaluejoin, + lj_cf_debug_sethook, + lj_cf_debug_gethook, + lj_cf_debug_debug, + lj_cf_debug_traceback +}; +static const uint8_t lj_lib_init_debug[] = { +131,62,16,11,103,101,116,114,101,103,105,115,116,114,121,12,103,101,116,109, +101,116,97,116,97,98,108,101,12,115,101,116,109,101,116,97,116,97,98,108,101, +7,103,101,116,102,101,110,118,7,115,101,116,102,101,110,118,7,103,101,116,105, +110,102,111,8,103,101,116,108,111,99,97,108,8,115,101,116,108,111,99,97,108, +10,103,101,116,117,112,118,97,108,117,101,10,115,101,116,117,112,118,97,108, +117,101,9,117,112,118,97,108,117,101,105,100,11,117,112,118,97,108,117,101, +106,111,105,110,7,115,101,116,104,111,111,107,7,103,101,116,104,111,111,107, +5,100,101,98,117,103,9,116,114,97,99,101,98,97,99,107,255 +}; +#endif + +#ifdef LJLIB_MODULE_jit +#undef LJLIB_MODULE_jit +static const lua_CFunction lj_lib_cf_jit[] = { + lj_cf_jit_on, + lj_cf_jit_off, + lj_cf_jit_flush, + lj_cf_jit_status, + lj_cf_jit_attach +}; +static const uint8_t lj_lib_init_jit[] = { +147,62,9,2,111,110,3,111,102,102,5,102,108,117,115,104,6,115,116,97,116,117, +115,6,97,116,116,97,99,104,252,5,194,111,115,250,252,4,196,97,114,99,104,250, +252,3,203,118,101,114,115,105,111,110,95,110,117,109,250,252,2,199,118,101, +114,115,105,111,110,250,255 +}; +#endif + +#ifdef LJLIB_MODULE_jit_util +#undef LJLIB_MODULE_jit_util +static const lua_CFunction lj_lib_cf_jit_util[] = { + lj_cf_jit_util_funcinfo, + lj_cf_jit_util_funcbc, + lj_cf_jit_util_funck, + lj_cf_jit_util_funcuvname, + lj_cf_jit_util_traceinfo, + lj_cf_jit_util_traceir, + lj_cf_jit_util_tracek, + lj_cf_jit_util_tracesnap, + lj_cf_jit_util_tracemc, + lj_cf_jit_util_traceexitstub, + lj_cf_jit_util_ircalladdr +}; +static const uint8_t lj_lib_init_jit_util[] = { +152,62,11,8,102,117,110,99,105,110,102,111,6,102,117,110,99,98,99,5,102,117, +110,99,107,10,102,117,110,99,117,118,110,97,109,101,9,116,114,97,99,101,105, +110,102,111,7,116,114,97,99,101,105,114,6,116,114,97,99,101,107,9,116,114,97, +99,101,115,110,97,112,7,116,114,97,99,101,109,99,13,116,114,97,99,101,101,120, +105,116,115,116,117,98,10,105,114,99,97,108,108,97,100,100,114,255 +}; +#endif + +#ifdef LJLIB_MODULE_jit_opt +#undef LJLIB_MODULE_jit_opt +static const lua_CFunction lj_lib_cf_jit_opt[] = { + lj_cf_jit_opt_start +}; +static const uint8_t lj_lib_init_jit_opt[] = { +163,62,1,5,115,116,97,114,116,255 +}; +#endif + +#ifdef LJLIB_MODULE_ffi_meta +#undef LJLIB_MODULE_ffi_meta +static const lua_CFunction lj_lib_cf_ffi_meta[] = { + lj_cf_ffi_meta___index, + lj_cf_ffi_meta___newindex, + lj_cf_ffi_meta___eq, + lj_cf_ffi_meta___len, + lj_cf_ffi_meta___lt, + lj_cf_ffi_meta___le, + lj_cf_ffi_meta___concat, + lj_cf_ffi_meta___call, + lj_cf_ffi_meta___add, + lj_cf_ffi_meta___sub, + lj_cf_ffi_meta___mul, + lj_cf_ffi_meta___div, + lj_cf_ffi_meta___mod, + lj_cf_ffi_meta___pow, + lj_cf_ffi_meta___unm, + lj_cf_ffi_meta___tostring, + lj_cf_ffi_meta___pairs, + lj_cf_ffi_meta___ipairs +}; +static const uint8_t lj_lib_init_ffi_meta[] = { +164,62,19,7,95,95,105,110,100,101,120,10,95,95,110,101,119,105,110,100,101, +120,4,95,95,101,113,5,95,95,108,101,110,4,95,95,108,116,4,95,95,108,101,8,95, +95,99,111,110,99,97,116,6,95,95,99,97,108,108,5,95,95,97,100,100,5,95,95,115, +117,98,5,95,95,109,117,108,5,95,95,100,105,118,5,95,95,109,111,100,5,95,95, +112,111,119,5,95,95,117,110,109,10,95,95,116,111,115,116,114,105,110,103,7, +95,95,112,97,105,114,115,8,95,95,105,112,97,105,114,115,195,102,102,105,203, +95,95,109,101,116,97,116,97,98,108,101,250,255 +}; +#endif + +#ifdef LJLIB_MODULE_ffi_clib +#undef LJLIB_MODULE_ffi_clib +static const lua_CFunction lj_lib_cf_ffi_clib[] = { + lj_cf_ffi_clib___index, + lj_cf_ffi_clib___newindex, + lj_cf_ffi_clib___gc +}; +static const uint8_t lj_lib_init_ffi_clib[] = { +182,62,3,7,95,95,105,110,100,101,120,10,95,95,110,101,119,105,110,100,101,120, +4,95,95,103,99,255 +}; +#endif + +#ifdef LJLIB_MODULE_ffi_callback +#undef LJLIB_MODULE_ffi_callback +static const lua_CFunction lj_lib_cf_ffi_callback[] = { + lj_cf_ffi_callback_free, + lj_cf_ffi_callback_set +}; +static const uint8_t lj_lib_init_ffi_callback[] = { +185,62,3,4,102,114,101,101,3,115,101,116,252,1,199,95,95,105,110,100,101,120, +250,255 +}; +#endif + +#ifdef LJLIB_MODULE_ffi +#undef LJLIB_MODULE_ffi +static const lua_CFunction lj_lib_cf_ffi[] = { + lj_cf_ffi_cdef, + lj_cf_ffi_new, + lj_cf_ffi_cast, + lj_cf_ffi_typeof, + lj_cf_ffi_istype, + lj_cf_ffi_sizeof, + lj_cf_ffi_alignof, + lj_cf_ffi_offsetof, + lj_cf_ffi_errno, + lj_cf_ffi_string, + lj_cf_ffi_copy, + lj_cf_ffi_fill, + lj_cf_ffi_abi, + lj_cf_ffi_metatype, + lj_cf_ffi_gc, + lj_cf_ffi_load +}; +static const uint8_t lj_lib_init_ffi[] = { +187,62,22,4,99,100,101,102,3,110,101,119,4,99,97,115,116,6,116,121,112,101, +111,102,6,105,115,116,121,112,101,6,115,105,122,101,111,102,7,97,108,105,103, +110,111,102,8,111,102,102,115,101,116,111,102,5,101,114,114,110,111,6,115,116, +114,105,110,103,4,99,111,112,121,4,102,105,108,108,3,97,98,105,252,8,192,250, +8,109,101,116,97,116,121,112,101,252,7,192,250,2,103,99,252,5,192,250,4,108, +111,97,100,252,4,193,67,250,252,3,194,111,115,250,252,2,196,97,114,99,104,250, +255 +}; +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_load.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_load.c new file mode 100644 index 0000000..edfdc90 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_load.c @@ -0,0 +1,168 @@ +/* +** Load and dump code. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include +#include + +#define lj_load_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_func.h" +#include "lj_frame.h" +#include "lj_vm.h" +#include "lj_lex.h" +#include "lj_bcdump.h" +#include "lj_parse.h" + +/* -- Load Lua source code and bytecode ----------------------------------- */ + +static TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud) +{ + LexState *ls = (LexState *)ud; + GCproto *pt; + GCfunc *fn; + int bc; + UNUSED(dummy); + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + bc = lj_lex_setup(L, ls); + if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE)); + lj_err_throw(L, LUA_ERRSYNTAX); + } + pt = bc ? lj_bcread(ls) : lj_parse(ls); + fn = lj_func_newL_empty(L, pt, tabref(L->env)); + /* Don't combine above/below into one statement. */ + setfuncV(L, L->top++, fn); + return NULL; +} + +LUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data, + const char *chunkname, const char *mode) +{ + LexState ls; + int status; + ls.rfunc = reader; + ls.rdata = data; + ls.chunkarg = chunkname ? chunkname : "?"; + ls.mode = mode; + lj_str_initbuf(&ls.sb); + status = lj_vm_cpcall(L, NULL, &ls, cpparser); + lj_lex_cleanup(L, &ls); + lj_gc_check(L); + return status; +} + +LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, + const char *chunkname) +{ + return lua_loadx(L, reader, data, chunkname, NULL); +} + +typedef struct FileReaderCtx { + FILE *fp; + char buf[LUAL_BUFFERSIZE]; +} FileReaderCtx; + +static const char *reader_file(lua_State *L, void *ud, size_t *size) +{ + FileReaderCtx *ctx = (FileReaderCtx *)ud; + UNUSED(L); + if (feof(ctx->fp)) return NULL; + *size = fread(ctx->buf, 1, sizeof(ctx->buf), ctx->fp); + return *size > 0 ? ctx->buf : NULL; +} + +LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename, + const char *mode) +{ + FileReaderCtx ctx; + int status; + const char *chunkname; + if (filename) { + ctx.fp = fopen(filename, "rb"); + if (ctx.fp == NULL) { + lua_pushfstring(L, "cannot open %s: %s", filename, strerror(errno)); + return LUA_ERRFILE; + } + chunkname = lua_pushfstring(L, "@%s", filename); + } else { + ctx.fp = stdin; + chunkname = "=stdin"; + } + status = lua_loadx(L, reader_file, &ctx, chunkname, mode); + if (ferror(ctx.fp)) { + L->top -= filename ? 2 : 1; + lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno)); + if (filename) + fclose(ctx.fp); + return LUA_ERRFILE; + } + if (filename) { + L->top--; + copyTV(L, L->top-1, L->top); + fclose(ctx.fp); + } + return status; +} + +LUALIB_API int luaL_loadfile(lua_State *L, const char *filename) +{ + return luaL_loadfilex(L, filename, NULL); +} + +typedef struct StringReaderCtx { + const char *str; + size_t size; +} StringReaderCtx; + +static const char *reader_string(lua_State *L, void *ud, size_t *size) +{ + StringReaderCtx *ctx = (StringReaderCtx *)ud; + UNUSED(L); + if (ctx->size == 0) return NULL; + *size = ctx->size; + ctx->size = 0; + return ctx->str; +} + +LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size, + const char *name, const char *mode) +{ + StringReaderCtx ctx; + ctx.str = buf; + ctx.size = size; + return lua_loadx(L, reader_string, &ctx, name, mode); +} + +LUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size, + const char *name) +{ + return luaL_loadbufferx(L, buf, size, name, NULL); +} + +LUALIB_API int luaL_loadstring(lua_State *L, const char *s) +{ + return luaL_loadbuffer(L, s, strlen(s), s); +} + +/* -- Dump bytecode ------------------------------------------------------- */ + +LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data) +{ + cTValue *o = L->top-1; + api_check(L, L->top > L->base); + if (tvisfunc(o) && isluafunc(funcV(o))) + return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0); + else + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.c new file mode 100644 index 0000000..5a73296 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.c @@ -0,0 +1,373 @@ +/* +** Machine code management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_mcode_c +#define LUA_CORE + +#include "lj_obj.h" +#if LJ_HASJIT +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_jit.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_dispatch.h" +#endif +#if LJ_HASJIT || LJ_HASFFI +#include "lj_vm.h" +#endif + +/* -- OS-specific functions ----------------------------------------------- */ + +#if LJ_HASJIT || LJ_HASFFI + +/* Define this if you want to run LuaJIT with Valgrind. */ +#ifdef LUAJIT_USE_VALGRIND +#include +#endif + +#if LJ_TARGET_IOS +void sys_icache_invalidate(void *start, size_t len); +#endif + +/* Synchronize data/instruction cache. */ +void lj_mcode_sync(void *start, void *end) +{ +#ifdef LUAJIT_USE_VALGRIND + VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start); +#endif +#if LJ_TARGET_X86ORX64 + UNUSED(start); UNUSED(end); +#elif LJ_TARGET_IOS + sys_icache_invalidate(start, (char *)end-(char *)start); +#elif LJ_TARGET_PPC + lj_vm_cachesync(start, end); +#elif defined(__GNUC__) + __clear_cache(start, end); +#else +#error "Missing builtin to flush instruction cache" +#endif +} + +#endif + +#if LJ_HASJIT + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#define MCPROT_RW PAGE_READWRITE +#define MCPROT_RX PAGE_EXECUTE_READ +#define MCPROT_RWX PAGE_EXECUTE_READWRITE + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, DWORD prot) +{ + void *p = VirtualAlloc((void *)hint, sz, + MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, prot); + if (!p && !hint) + lj_trace_err(J, LJ_TRERR_MCODEAL); + return p; +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + UNUSED(J); UNUSED(sz); + VirtualFree(p, 0, MEM_RELEASE); +} + +static int mcode_setprot(void *p, size_t sz, DWORD prot) +{ + DWORD oprot; + return !VirtualProtect(p, sz, prot, &oprot); +} + +#elif LJ_TARGET_POSIX + +#include + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +#define MCPROT_RW (PROT_READ|PROT_WRITE) +#define MCPROT_RX (PROT_READ|PROT_EXEC) +#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC) + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) +{ + void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) { + if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); + p = NULL; + } + return p; +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + UNUSED(J); + munmap(p, sz); +} + +static int mcode_setprot(void *p, size_t sz, int prot) +{ + return mprotect(p, sz, prot); +} + +#elif LJ_64 + +#error "Missing OS support for explicit placement of executable memory" + +#else + +/* Fallback allocator. This will fail if memory is not executable by default. */ +#define LUAJIT_UNPROTECT_MCODE +#define MCPROT_RW 0 +#define MCPROT_RX 0 +#define MCPROT_RWX 0 + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) +{ + UNUSED(hint); UNUSED(prot); + return lj_mem_new(J->L, sz); +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + lj_mem_free(J2G(J), p, sz); +} + +#endif + +/* -- MCode area protection ----------------------------------------------- */ + +/* Define this ONLY if the page protection twiddling becomes a bottleneck. */ +#ifdef LUAJIT_UNPROTECT_MCODE + +/* It's generally considered to be a potential security risk to have +** pages with simultaneous write *and* execute access in a process. +** +** Do not even think about using this mode for server processes or +** apps handling untrusted external data (such as a browser). +** +** The security risk is not in LuaJIT itself -- but if an adversary finds +** any *other* flaw in your C application logic, then any RWX memory page +** simplifies writing an exploit considerably. +*/ +#define MCPROT_GEN MCPROT_RWX +#define MCPROT_RUN MCPROT_RWX + +static void mcode_protect(jit_State *J, int prot) +{ + UNUSED(J); UNUSED(prot); +} + +#else + +/* This is the default behaviour and much safer: +** +** Most of the time the memory pages holding machine code are executable, +** but NONE of them is writable. +** +** The current memory area is marked read-write (but NOT executable) only +** during the short time window while the assembler generates machine code. +*/ +#define MCPROT_GEN MCPROT_RW +#define MCPROT_RUN MCPROT_RX + +/* Protection twiddling failed. Probably due to kernel security. */ +static LJ_NOINLINE void mcode_protfail(jit_State *J) +{ + lua_CFunction panic = J2G(J)->panic; + if (panic) { + lua_State *L = J->L; + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_JITPROT)); + panic(L); + } +} + +/* Change protection of MCode area. */ +static void mcode_protect(jit_State *J, int prot) +{ + if (J->mcprot != prot) { + if (LJ_UNLIKELY(mcode_setprot(J->mcarea, J->szmcarea, prot))) + mcode_protfail(J); + J->mcprot = prot; + } +} + +#endif + +/* -- MCode area allocation ----------------------------------------------- */ + +#if LJ_TARGET_X64 +#define mcode_validptr(p) ((p) && (uintptr_t)(p) < (uintptr_t)1<<47) +#else +#define mcode_validptr(p) ((p) && (uintptr_t)(p) < 0xffff0000) +#endif + +#ifdef LJ_TARGET_JUMPRANGE + +/* Get memory within relative jump distance of our code in 64 bit mode. */ +static void *mcode_alloc(jit_State *J, size_t sz) +{ + /* Target an address in the static assembler code (64K aligned). + ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB. + ** Use half the jump range so every address in the range can reach any other. + */ +#if LJ_TARGET_MIPS + /* Use the middle of the 256MB-aligned region. */ + uintptr_t target = ((uintptr_t)(void *)lj_vm_exit_handler & 0xf0000000u) + + 0x08000000u; +#else + uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; +#endif + const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21); + /* First try a contiguous area below the last one. */ + uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0; + int i; + for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */ + if (mcode_validptr(hint)) { + void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); + + if (mcode_validptr(p) && + ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)) + return p; + if (p) mcode_free(J, p, sz); /* Free badly placed area. */ + } + /* Next try probing pseudo-random addresses. */ + do { + hint = (0x78fb ^ LJ_PRNG_BITS(J, 15)) << 16; /* 64K aligned. */ + } while (!(hint + sz < range)); + hint = target + hint - (range>>1); + } + lj_trace_err(J, LJ_TRERR_MCODEAL); /* Give up. OS probably ignores hints? */ + return NULL; +} + +#else + +/* All memory addresses are reachable by relative jumps. */ +#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN) + +#endif + +/* -- MCode area management ----------------------------------------------- */ + +/* Linked list of MCode areas. */ +typedef struct MCLink { + MCode *next; /* Next area. */ + size_t size; /* Size of current area. */ +} MCLink; + +/* Allocate a new MCode area. */ +static void mcode_allocarea(jit_State *J) +{ + MCode *oldarea = J->mcarea; + size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10; + sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); + J->mcarea = (MCode *)mcode_alloc(J, sz); + J->szmcarea = sz; + J->mcprot = MCPROT_GEN; + J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea); + J->mcbot = (MCode *)((char *)J->mcarea + sizeof(MCLink)); + ((MCLink *)J->mcarea)->next = oldarea; + ((MCLink *)J->mcarea)->size = sz; + J->szallmcarea += sz; +} + +/* Free all MCode areas. */ +void lj_mcode_free(jit_State *J) +{ + MCode *mc = J->mcarea; + J->mcarea = NULL; + J->szallmcarea = 0; + while (mc) { + MCode *next = ((MCLink *)mc)->next; + mcode_free(J, mc, ((MCLink *)mc)->size); + mc = next; + } +} + +/* -- MCode transactions -------------------------------------------------- */ + +/* Reserve the remainder of the current MCode area. */ +MCode *lj_mcode_reserve(jit_State *J, MCode **lim) +{ + if (!J->mcarea) + mcode_allocarea(J); + else + mcode_protect(J, MCPROT_GEN); + *lim = J->mcbot; + return J->mctop; +} + +/* Commit the top part of the current MCode area. */ +void lj_mcode_commit(jit_State *J, MCode *top) +{ + J->mctop = top; + mcode_protect(J, MCPROT_RUN); +} + +/* Abort the reservation. */ +void lj_mcode_abort(jit_State *J) +{ + if (J->mcarea) + mcode_protect(J, MCPROT_RUN); +} + +/* Set/reset protection to allow patching of MCode areas. */ +MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish) +{ +#ifdef LUAJIT_UNPROTECT_MCODE + UNUSED(J); UNUSED(ptr); UNUSED(finish); + return NULL; +#else + if (finish) { + if (J->mcarea == ptr) + mcode_protect(J, MCPROT_RUN); + else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN))) + mcode_protfail(J); + return NULL; + } else { + MCode *mc = J->mcarea; + /* Try current area first to use the protection cache. */ + if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) { + mcode_protect(J, MCPROT_GEN); + return mc; + } + /* Otherwise search through the list of MCode areas. */ + for (;;) { + mc = ((MCLink *)mc)->next; + lua_assert(mc != NULL); + if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) { + if (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN))) + mcode_protfail(J); + return mc; + } + } + } +#endif +} + +/* Limit of MCode reservation reached. */ +void lj_mcode_limiterr(jit_State *J, size_t need) +{ + size_t sizemcode, maxmcode; + lj_mcode_abort(J); + sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10; + sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); + maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10; + if ((size_t)need > sizemcode) + lj_trace_err(J, LJ_TRERR_MCODEOV); /* Too long for any area. */ + if (J->szallmcarea + sizemcode > maxmcode) + lj_trace_err(J, LJ_TRERR_MCODEAL); + mcode_allocarea(J); + lj_trace_err(J, LJ_TRERR_MCODELM); /* Retry with new area. */ +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.h new file mode 100644 index 0000000..89344fc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_mcode.h @@ -0,0 +1,30 @@ +/* +** Machine code management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_MCODE_H +#define _LJ_MCODE_H + +#include "lj_obj.h" + +#if LJ_HASJIT || LJ_HASFFI +LJ_FUNC void lj_mcode_sync(void *start, void *end); +#endif + +#if LJ_HASJIT + +#include "lj_jit.h" + +LJ_FUNC void lj_mcode_free(jit_State *J); +LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim); +LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m); +LJ_FUNC void lj_mcode_abort(jit_State *J); +LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish); +LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need); + +#define lj_mcode_commitbot(J, m) (J->mcbot = (m)) + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.c new file mode 100644 index 0000000..0a52667 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.c @@ -0,0 +1,466 @@ +/* +** Metamethod handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_meta_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* -- Metamethod handling ------------------------------------------------- */ + +/* String interning of metamethod names for fast indexing. */ +void lj_meta_init(lua_State *L) +{ +#define MMNAME(name) "__" #name + const char *metanames = MMDEF(MMNAME); +#undef MMNAME + global_State *g = G(L); + const char *p, *q; + uint32_t mm; + for (mm = 0, p = metanames; *p; mm++, p = q) { + GCstr *s; + for (q = p+2; *q && *q != '_'; q++) ; + s = lj_str_new(L, p, (size_t)(q-p)); + /* NOBARRIER: g->gcroot[] is a GC root. */ + setgcref(g->gcroot[GCROOT_MMNAME+mm], obj2gco(s)); + } +} + +/* Negative caching of a few fast metamethods. See the lj_meta_fast() macro. */ +cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name) +{ + cTValue *mo = lj_tab_getstr(mt, name); + lua_assert(mm <= MM_FAST); + if (!mo || tvisnil(mo)) { /* No metamethod? */ + mt->nomm |= (uint8_t)(1u<metatable); + else if (tvisudata(o)) + mt = tabref(udataV(o)->metatable); + else + mt = tabref(basemt_obj(G(L), o)); + if (mt) { + cTValue *mo = lj_tab_getstr(mt, mmname_str(G(L), mm)); + if (mo) + return mo; + } + return niltv(L); +} + +#if LJ_HASFFI +/* Tailcall from C function. */ +int lj_meta_tailcall(lua_State *L, cTValue *tv) +{ + TValue *base = L->base; + TValue *top = L->top; + const BCIns *pc = frame_pc(base-1); /* Preserve old PC from frame. */ + copyTV(L, base-1, tv); /* Replace frame with new object. */ + top->u32.lo = LJ_CONT_TAILCALL; + setframe_pc(top, pc); + setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */ + setframe_ftsz(top+1, (int)((char *)(top+2) - (char *)base) + FRAME_CONT); + L->base = L->top = top+2; + /* + ** before: [old_mo|PC] [... ...] + ** ^base ^top + ** after: [new_mo|itype] [... ...] [NULL|PC] [dummy|delta] + ** ^base/top + ** tailcall: [new_mo|PC] [... ...] + ** ^base ^top + */ + return 0; +} +#endif + +/* Setup call to metamethod to be run by Assembler VM. */ +static TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo, + cTValue *a, cTValue *b) +{ + /* + ** |-- framesize -> top top+1 top+2 top+3 + ** before: [func slots ...] + ** mm setup: [func slots ...] [cont|?] [mo|tmtype] [a] [b] + ** in asm: [func slots ...] [cont|PC] [mo|delta] [a] [b] + ** ^-- func base ^-- mm base + ** after mm: [func slots ...] [result] + ** ^-- copy to base[PC_RA] --/ for lj_cont_ra + ** istruecond + branch for lj_cont_cond* + ** ignore for lj_cont_nop + ** next PC: [func slots ...] + */ + TValue *top = L->top; + if (curr_funcisL(L)) top = curr_topL(L); + setcont(top, cont); /* Assembler VM stores PC in upper word. */ + copyTV(L, top+1, mo); /* Store metamethod and two arguments. */ + copyTV(L, top+2, a); + copyTV(L, top+3, b); + return top+2; /* Return new base. */ +} + +/* -- C helpers for some instructions, called from assembler VM ----------- */ + +/* Helper for TGET*. __index chain and metamethod. */ +cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k) +{ + int loop; + for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) { + cTValue *mo; + if (LJ_LIKELY(tvistab(o))) { + GCtab *t = tabV(o); + cTValue *tv = lj_tab_get(L, t, k); + if (!tvisnil(tv) || + !(mo = lj_meta_fast(L, tabref(t->metatable), MM_index))) + return tv; + } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_index))) { + lj_err_optype(L, o, LJ_ERR_OPINDEX); + return NULL; /* unreachable */ + } + if (tvisfunc(mo)) { + L->top = mmcall(L, lj_cont_ra, mo, o, k); + return NULL; /* Trigger metamethod call. */ + } + o = mo; + } + lj_err_msg(L, LJ_ERR_GETLOOP); + return NULL; /* unreachable */ +} + +/* Helper for TSET*. __newindex chain and metamethod. */ +TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k) +{ + TValue tmp; + int loop; + for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) { + cTValue *mo; + if (LJ_LIKELY(tvistab(o))) { + GCtab *t = tabV(o); + cTValue *tv = lj_tab_get(L, t, k); + if (LJ_LIKELY(!tvisnil(tv))) { + t->nomm = 0; /* Invalidate negative metamethod cache. */ + lj_gc_anybarriert(L, t); + return (TValue *)tv; + } else if (!(mo = lj_meta_fast(L, tabref(t->metatable), MM_newindex))) { + t->nomm = 0; /* Invalidate negative metamethod cache. */ + lj_gc_anybarriert(L, t); + if (tv != niltv(L)) + return (TValue *)tv; + if (tvisnil(k)) lj_err_msg(L, LJ_ERR_NILIDX); + else if (tvisint(k)) { setnumV(&tmp, (lua_Number)intV(k)); k = &tmp; } + else if (tvisnum(k) && tvisnan(k)) lj_err_msg(L, LJ_ERR_NANIDX); + return lj_tab_newkey(L, t, k); + } + } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_newindex))) { + lj_err_optype(L, o, LJ_ERR_OPINDEX); + return NULL; /* unreachable */ + } + if (tvisfunc(mo)) { + L->top = mmcall(L, lj_cont_nop, mo, o, k); + /* L->top+2 = v filled in by caller. */ + return NULL; /* Trigger metamethod call. */ + } + copyTV(L, &tmp, mo); + o = &tmp; + } + lj_err_msg(L, LJ_ERR_SETLOOP); + return NULL; /* unreachable */ +} + +static cTValue *str2num(cTValue *o, TValue *n) +{ + if (tvisnum(o)) + return o; + else if (tvisint(o)) + return (setnumV(n, (lua_Number)intV(o)), n); + else if (tvisstr(o) && lj_strscan_num(strV(o), n)) + return n; + else + return NULL; +} + +/* Helper for arithmetic instructions. Coercion, metamethod. */ +TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, cTValue *rc, + BCReg op) +{ + MMS mm = bcmode_mm(op); + TValue tempb, tempc; + cTValue *b, *c; + if ((b = str2num(rb, &tempb)) != NULL && + (c = str2num(rc, &tempc)) != NULL) { /* Try coercion first. */ + setnumV(ra, lj_vm_foldarith(numV(b), numV(c), (int)mm-MM_add)); + return NULL; + } else { + cTValue *mo = lj_meta_lookup(L, rb, mm); + if (tvisnil(mo)) { + mo = lj_meta_lookup(L, rc, mm); + if (tvisnil(mo)) { + if (str2num(rb, &tempb) == NULL) rc = rb; + lj_err_optype(L, rc, LJ_ERR_OPARITH); + return NULL; /* unreachable */ + } + } + return mmcall(L, lj_cont_ra, mo, rb, rc); + } +} + +/* In-place coercion of a number to a string. */ +static LJ_AINLINE int tostring(lua_State *L, TValue *o) +{ + if (tvisstr(o)) { + return 1; + } else if (tvisnumber(o)) { + setstrV(L, o, lj_str_fromnumber(L, o)); + return 1; + } else { + return 0; + } +} + +/* Helper for CAT. Coercion, iterative concat, __concat metamethod. */ +TValue *lj_meta_cat(lua_State *L, TValue *top, int left) +{ + int fromc = 0; + if (left < 0) { left = -left; fromc = 1; } + do { + int n = 1; + if (!(tvisstr(top-1) || tvisnumber(top-1)) || !tostring(L, top)) { + cTValue *mo = lj_meta_lookup(L, top-1, MM_concat); + if (tvisnil(mo)) { + mo = lj_meta_lookup(L, top, MM_concat); + if (tvisnil(mo)) { + if (tvisstr(top-1) || tvisnumber(top-1)) top++; + lj_err_optype(L, top-1, LJ_ERR_OPCAT); + return NULL; /* unreachable */ + } + } + /* One of the top two elements is not a string, call __cat metamethod: + ** + ** before: [...][CAT stack .........................] + ** top-1 top top+1 top+2 + ** pick two: [...][CAT stack ...] [o1] [o2] + ** setup mm: [...][CAT stack ...] [cont|?] [mo|tmtype] [o1] [o2] + ** in asm: [...][CAT stack ...] [cont|PC] [mo|delta] [o1] [o2] + ** ^-- func base ^-- mm base + ** after mm: [...][CAT stack ...] <--push-- [result] + ** next step: [...][CAT stack .............] + */ + copyTV(L, top+2, top); /* Careful with the order of stack copies! */ + copyTV(L, top+1, top-1); + copyTV(L, top, mo); + setcont(top-1, lj_cont_cat); + return top+1; /* Trigger metamethod call. */ + } else if (strV(top)->len == 0) { /* Shortcut. */ + (void)tostring(L, top-1); + } else { + /* Pick as many strings as possible from the top and concatenate them: + ** + ** before: [...][CAT stack ...........................] + ** pick str: [...][CAT stack ...] [...... strings ......] + ** concat: [...][CAT stack ...] [result] + ** next step: [...][CAT stack ............] + */ + MSize tlen = strV(top)->len; + char *buffer; + int i; + for (n = 1; n <= left && tostring(L, top-n); n++) { + MSize len = strV(top-n)->len; + if (len >= LJ_MAX_STR - tlen) + lj_err_msg(L, LJ_ERR_STROV); + tlen += len; + } + buffer = lj_str_needbuf(L, &G(L)->tmpbuf, tlen); + n--; + tlen = 0; + for (i = n; i >= 0; i--) { + MSize len = strV(top-i)->len; + memcpy(buffer + tlen, strVdata(top-i), len); + tlen += len; + } + setstrV(L, top-n, lj_str_new(L, buffer, tlen)); + } + left -= n; + top -= n; + } while (left >= 1); + if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) { + if (!fromc) L->top = curr_topL(L); + lj_gc_step(L); + } + return NULL; +} + +/* Helper for LEN. __len metamethod. */ +TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o) +{ + cTValue *mo = lj_meta_lookup(L, o, MM_len); + if (tvisnil(mo)) { + if (LJ_52 && tvistab(o)) + tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<gch.metatable), MM_eq); + if (mo) { + TValue *top; + uint32_t it; + if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) { + cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq); + if (mo2 == NULL || !lj_obj_equal(mo, mo2)) + return (TValue *)(intptr_t)ne; + } + top = curr_top(L); + setcont(top, ne ? lj_cont_condf : lj_cont_condt); + copyTV(L, top+1, mo); + it = ~(uint32_t)o1->gch.gct; + setgcV(L, top+2, o1, it); + setgcV(L, top+3, o2, it); + return top+2; /* Trigger metamethod call. */ + } + return (TValue *)(intptr_t)ne; +} + +#if LJ_HASFFI +TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins) +{ + ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt; + int op = (int)bc_op(ins) & ~1; + TValue tv; + cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)]; + cTValue *o1mm = o1; + if (op == BC_ISEQV) { + o2 = &L->base[bc_d(ins)]; + if (!tviscdata(o1mm)) o1mm = o2; + } else if (op == BC_ISEQS) { + setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins)))); + o2 = &tv; + } else if (op == BC_ISEQN) { + o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)]; + } else { + lua_assert(op == BC_ISEQP); + setitype(&tv, ~bc_d(ins)); + o2 = &tv; + } + mo = lj_meta_lookup(L, o1mm, MM_eq); + if (LJ_LIKELY(!tvisnil(mo))) + return mmcall(L, cont, mo, o1, o2); + else + return (TValue *)(intptr_t)(bc_op(ins) & 1); +} +#endif + +/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */ +TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op) +{ + if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) { + ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt; + MMS mm = (op & 2) ? MM_le : MM_lt; + cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm); + if (LJ_UNLIKELY(tvisnil(mo))) goto err; + return mmcall(L, cont, mo, o1, o2); + } else if (LJ_52 || itype(o1) == itype(o2)) { + /* Never called with two numbers. */ + if (tvisstr(o1) && tvisstr(o2)) { + int32_t res = lj_str_cmp(strV(o1), strV(o2)); + return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1)); + } else { + trymt: + while (1) { + ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt; + MMS mm = (op & 2) ? MM_le : MM_lt; + cTValue *mo = lj_meta_lookup(L, o1, mm); +#if LJ_52 + if (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm)))) +#else + cTValue *mo2 = lj_meta_lookup(L, o2, mm); + if (tvisnil(mo) || !lj_obj_equal(mo, mo2)) +#endif + { + if (op & 2) { /* MM_le not found: retry with MM_lt. */ + cTValue *ot = o1; o1 = o2; o2 = ot; /* Swap operands. */ + op ^= 3; /* Use LT and flip condition. */ + continue; + } + goto err; + } + return mmcall(L, cont, mo, o1, o2); + } + } + } else if (tvisbool(o1) && tvisbool(o2)) { + goto trymt; + } else { + err: + lj_err_comp(L, o1, o2); + return NULL; + } +} + +/* Helper for calls. __call metamethod. */ +void lj_meta_call(lua_State *L, TValue *func, TValue *top) +{ + cTValue *mo = lj_meta_lookup(L, func, MM_call); + TValue *p; + if (!tvisfunc(mo)) + lj_err_optype_call(L, func); + for (p = top; p > func; p--) copyTV(L, p, p-1); + copyTV(L, func, mo); +} + +/* Helper for FORI. Coercion. */ +void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o) +{ + if (!lj_strscan_numberobj(o)) lj_err_msg(L, LJ_ERR_FORINIT); + if (!lj_strscan_numberobj(o+1)) lj_err_msg(L, LJ_ERR_FORLIM); + if (!lj_strscan_numberobj(o+2)) lj_err_msg(L, LJ_ERR_FORSTEP); + if (LJ_DUALNUM) { + /* Ensure all slots are integers or all slots are numbers. */ + int32_t k[3]; + int nint = 0; + ptrdiff_t i; + for (i = 0; i <= 2; i++) { + if (tvisint(o+i)) { + k[i] = intV(o+i); nint++; + } else { + k[i] = lj_num2int(numV(o+i)); nint += ((lua_Number)k[i] == numV(o+i)); + } + } + if (nint == 3) { /* Narrow to integers. */ + setintV(o, k[0]); + setintV(o+1, k[1]); + setintV(o+2, k[2]); + } else if (nint != 0) { /* Widen to numbers. */ + if (tvisint(o)) setnumV(o, (lua_Number)intV(o)); + if (tvisint(o+1)) setnumV(o+1, (lua_Number)intV(o+1)); + if (tvisint(o+2)) setnumV(o+2, (lua_Number)intV(o+2)); + } + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.h new file mode 100644 index 0000000..8d7c2cd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_meta.h @@ -0,0 +1,37 @@ +/* +** Metamethod handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_META_H +#define _LJ_META_H + +#include "lj_obj.h" + +/* Metamethod handling */ +LJ_FUNC void lj_meta_init(lua_State *L); +LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name); +LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm); +#if LJ_HASFFI +LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv); +#endif + +#define lj_meta_fastg(g, mt, mm) \ + ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \ + lj_meta_cache(mt, mm, mmname_str(g, mm))) +#define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm) + +/* C helpers for some instructions, called from assembler VM. */ +LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k); +LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k); +LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, + cTValue *rc, BCReg op); +LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left); +LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o); +LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne); +LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins); +LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op); +LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top); +LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.c new file mode 100644 index 0000000..c7f3bc1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.c @@ -0,0 +1,35 @@ +/* +** Miscellaneous object handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_obj_c +#define LUA_CORE + +#include "lj_obj.h" + +/* Object type names. */ +LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */ + "no value", "nil", "boolean", "userdata", "number", "string", + "table", "function", "userdata", "thread", "proto", "cdata" +}; + +LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */ + "nil", "boolean", "boolean", "userdata", "string", "upval", "thread", + "proto", "function", "trace", "cdata", "table", "userdata", "number" +}; + +/* Compare two objects without calling metamethods. */ +int lj_obj_equal(cTValue *o1, cTValue *o2) +{ + if (itype(o1) == itype(o2)) { + if (tvispri(o1)) + return 1; + if (!tvisnum(o1)) + return gcrefeq(o1->gcr, o2->gcr); + } else if (!tvisnumber(o1) || !tvisnumber(o2)) { + return 0; + } + return numberVnum(o1) == numberVnum(o2); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.h new file mode 100644 index 0000000..cc999aa --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_obj.h @@ -0,0 +1,856 @@ +/* +** LuaJIT VM tags, values and objects. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#ifndef _LJ_OBJ_H +#define _LJ_OBJ_H + +#include "lua.h" +#include "lj_def.h" +#include "lj_arch.h" + +/* -- Memory references (32 bit address space) ---------------------------- */ + +/* Memory size. */ +typedef uint32_t MSize; + +/* Memory reference */ +typedef struct MRef { + uint32_t ptr32; /* Pseudo 32 bit pointer. */ +} MRef; + +#define mref(r, t) ((t *)(void *)(uintptr_t)(r).ptr32) + +#define setmref(r, p) ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p)) +#define setmrefr(r, v) ((r).ptr32 = (v).ptr32) + +/* -- GC object references (32 bit address space) ------------------------- */ + +/* GCobj reference */ +typedef struct GCRef { + uint32_t gcptr32; /* Pseudo 32 bit pointer. */ +} GCRef; + +/* Common GC header for all collectable objects. */ +#define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct +/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */ + +#define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32) +#define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32) +#define gcrefu(r) ((r).gcptr32) +#define gcrefi(r) ((int32_t)(r).gcptr32) +#define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32) +#define gcnext(gc) (gcref((gc)->gch.nextgc)) + +#define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch) +#define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i)) +#define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p)) +#define setgcrefnull(r) ((r).gcptr32 = 0) +#define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32) + +/* IMPORTANT NOTE: +** +** All uses of the setgcref* macros MUST be accompanied with a write barrier. +** +** This is to ensure the integrity of the incremental GC. The invariant +** to preserve is that a black object never points to a white object. +** I.e. never store a white object into a field of a black object. +** +** It's ok to LEAVE OUT the write barrier ONLY in the following cases: +** - The source is not a GC object (NULL). +** - The target is a GC root. I.e. everything in global_State. +** - The target is a lua_State field (threads are never black). +** - The target is a stack slot, see setgcV et al. +** - The target is an open upvalue, i.e. pointing to a stack slot. +** - The target is a newly created object (i.e. marked white). But make +** sure nothing invokes the GC inbetween. +** - The target and the source are the same object (self-reference). +** - The target already contains the object (e.g. moving elements around). +** +** The most common case is a store to a stack slot. All other cases where +** a barrier has been omitted are annotated with a NOBARRIER comment. +** +** The same logic applies for stores to table slots (array part or hash +** part). ALL uses of lj_tab_set* require a barrier for the stored value +** *and* the stored key, based on the above rules. In practice this means +** a barrier is needed if *either* of the key or value are a GC object. +** +** It's ok to LEAVE OUT the write barrier in the following special cases: +** - The stored value is nil. The key doesn't matter because it's either +** not resurrected or lj_tab_newkey() will take care of the key barrier. +** - The key doesn't matter if the *previously* stored value is guaranteed +** to be non-nil (because the key is kept alive in the table). +** - The key doesn't matter if it's guaranteed not to be part of the table, +** since lj_tab_newkey() takes care of the key barrier. This applies +** trivially to new tables, but watch out for resurrected keys. Storing +** a nil value leaves the key in the table! +** +** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used +** by the interpreter for all table stores. +** +** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark +** dead keys in tables. The reference is left in, but it's guaranteed to +** be never dereferenced as long as the value is nil. It's ok if the key is +** freed or if any object subsequently gets the same address. +** +** Not destroying dead keys helps to keep key hash slots stable. This avoids +** specialization back-off for HREFK when a value flips between nil and +** non-nil and the GC gets in the way. It also allows safely hoisting +** HREF/HREFK across GC steps. Dead keys are only removed if a table is +** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize. +** +** The trade-off is that a write barrier for tables must take the key into +** account, too. Implicitly resurrecting the key by storing a non-nil value +** may invalidate the incremental GC invariant. +*/ + +/* -- Common type definitions --------------------------------------------- */ + +/* Types for handling bytecodes. Need this here, details in lj_bc.h. */ +typedef uint32_t BCIns; /* Bytecode instruction. */ +typedef uint32_t BCPos; /* Bytecode position. */ +typedef uint32_t BCReg; /* Bytecode register. */ +typedef int32_t BCLine; /* Bytecode line number. */ + +/* Internal assembler functions. Never call these directly from C. */ +typedef void (*ASMFunction)(void); + +/* Resizable string buffer. Need this here, details in lj_str.h. */ +typedef struct SBuf { + char *buf; /* String buffer base. */ + MSize n; /* String buffer length. */ + MSize sz; /* String buffer size. */ +} SBuf; + +/* -- Tags and values ----------------------------------------------------- */ + +/* Frame link. */ +typedef union { + int32_t ftsz; /* Frame type and size of previous frame. */ + MRef pcr; /* Overlaps PC for Lua frames. */ +} FrameLink; + +/* Tagged value. */ +typedef LJ_ALIGN(8) union TValue { + uint64_t u64; /* 64 bit pattern overlaps number. */ + lua_Number n; /* Number object overlaps split tag/value object. */ + struct { + LJ_ENDIAN_LOHI( + union { + GCRef gcr; /* GCobj reference (if any). */ + int32_t i; /* Integer value. */ + }; + , uint32_t it; /* Internal object tag. Must overlap MSW of number. */ + ) + }; + struct { + LJ_ENDIAN_LOHI( + GCRef func; /* Function for next frame (or dummy L). */ + , FrameLink tp; /* Link to previous frame. */ + ) + } fr; + struct { + LJ_ENDIAN_LOHI( + uint32_t lo; /* Lower 32 bits of number. */ + , uint32_t hi; /* Upper 32 bits of number. */ + ) + } u32; +} TValue; + +typedef const TValue cTValue; + +#define tvref(r) (mref(r, TValue)) + +/* More external and GCobj tags for internal objects. */ +#define LAST_TT LUA_TTHREAD +#define LUA_TPROTO (LAST_TT+1) +#define LUA_TCDATA (LAST_TT+2) + +/* Internal object tags. +** +** Internal tags overlap the MSW of a number object (must be a double). +** Interpreted as a double these are special NaNs. The FPU only generates +** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available +** for use as internal tags. Small negative numbers are used to shorten the +** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate). +** +** ---MSW---.---LSW--- +** primitive types | itype | | +** lightuserdata | itype | void * | (32 bit platforms) +** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers) +** GC objects | itype | GCRef | +** int (LJ_DUALNUM)| itype | int | +** number -------double------ +** +** ORDER LJ_T +** Primitive types nil/false/true must be first, lightuserdata next. +** GC objects are at the end, table/userdata must be lowest. +** Also check lj_ir.h for similar ordering constraints. +*/ +#define LJ_TNIL (~0u) +#define LJ_TFALSE (~1u) +#define LJ_TTRUE (~2u) +#define LJ_TLIGHTUD (~3u) +#define LJ_TSTR (~4u) +#define LJ_TUPVAL (~5u) +#define LJ_TTHREAD (~6u) +#define LJ_TPROTO (~7u) +#define LJ_TFUNC (~8u) +#define LJ_TTRACE (~9u) +#define LJ_TCDATA (~10u) +#define LJ_TTAB (~11u) +#define LJ_TUDATA (~12u) +/* This is just the canonical number type used in some places. */ +#define LJ_TNUMX (~13u) + +/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */ +#if LJ_64 +#define LJ_TISNUM 0xfffeffffu +#else +#define LJ_TISNUM LJ_TNUMX +#endif +#define LJ_TISTRUECOND LJ_TFALSE +#define LJ_TISPRI LJ_TTRUE +#define LJ_TISGCV (LJ_TSTR+1) +#define LJ_TISTABUD LJ_TTAB + +/* -- String object ------------------------------------------------------- */ + +/* String object header. String payload follows. */ +typedef struct GCstr { + GCHeader; + uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */ + uint8_t unused; + MSize hash; /* Hash of string. */ + MSize len; /* Size of string. */ +} GCstr; + +#define strref(r) (&gcref((r))->str) +#define strdata(s) ((const char *)((s)+1)) +#define strdatawr(s) ((char *)((s)+1)) +#define strVdata(o) strdata(strV(o)) +#define sizestring(s) (sizeof(struct GCstr)+(s)->len+1) + +/* -- Userdata object ----------------------------------------------------- */ + +/* Userdata object. Payload follows. */ +typedef struct GCudata { + GCHeader; + uint8_t udtype; /* Userdata type. */ + uint8_t unused2; + GCRef env; /* Should be at same offset in GCfunc. */ + MSize len; /* Size of payload. */ + GCRef metatable; /* Must be at same offset in GCtab. */ + uint32_t align1; /* To force 8 byte alignment of the payload. */ +} GCudata; + +/* Userdata types. */ +enum { + UDTYPE_USERDATA, /* Regular userdata. */ + UDTYPE_IO_FILE, /* I/O library FILE. */ + UDTYPE_FFI_CLIB, /* FFI C library namespace. */ + UDTYPE__MAX +}; + +#define uddata(u) ((void *)((u)+1)) +#define sizeudata(u) (sizeof(struct GCudata)+(u)->len) + +/* -- C data object ------------------------------------------------------- */ + +/* C data object. Payload follows. */ +typedef struct GCcdata { + GCHeader; + uint16_t ctypeid; /* C type ID. */ +} GCcdata; + +/* Prepended to variable-sized or realigned C data objects. */ +typedef struct GCcdataVar { + uint16_t offset; /* Offset to allocated memory (relative to GCcdata). */ + uint16_t extra; /* Extra space allocated (incl. GCcdata + GCcdatav). */ + MSize len; /* Size of payload. */ +} GCcdataVar; + +#define cdataptr(cd) ((void *)((cd)+1)) +#define cdataisv(cd) ((cd)->marked & 0x80) +#define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar))) +#define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len) +#define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra) +#define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset)) + +/* -- Prototype object ---------------------------------------------------- */ + +#define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef)) +#define round_nkgc(n) (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1)) + +typedef struct GCproto { + GCHeader; + uint8_t numparams; /* Number of parameters. */ + uint8_t framesize; /* Fixed frame size. */ + MSize sizebc; /* Number of bytecode instructions. */ + GCRef gclist; + MRef k; /* Split constant array (points to the middle). */ + MRef uv; /* Upvalue list. local slot|0x8000 or parent uv idx. */ + MSize sizekgc; /* Number of collectable constants. */ + MSize sizekn; /* Number of lua_Number constants. */ + MSize sizept; /* Total size including colocated arrays. */ + uint8_t sizeuv; /* Number of upvalues. */ + uint8_t flags; /* Miscellaneous flags (see below). */ + uint16_t trace; /* Anchor for chain of root traces. */ + /* ------ The following fields are for debugging/tracebacks only ------ */ + GCRef chunkname; /* Name of the chunk this function was defined in. */ + BCLine firstline; /* First line of the function definition. */ + BCLine numline; /* Number of lines for the function definition. */ + MRef lineinfo; /* Compressed map from bytecode ins. to source line. */ + MRef uvinfo; /* Upvalue names. */ + MRef varinfo; /* Names and compressed extents of local variables. */ +} GCproto; + +/* Flags for prototype. */ +#define PROTO_CHILD 0x01 /* Has child prototypes. */ +#define PROTO_VARARG 0x02 /* Vararg function. */ +#define PROTO_FFI 0x04 /* Uses BC_KCDATA for FFI datatypes. */ +#define PROTO_NOJIT 0x08 /* JIT disabled for this function. */ +#define PROTO_ILOOP 0x10 /* Patched bytecode with ILOOP etc. */ +/* Only used during parsing. */ +#define PROTO_HAS_RETURN 0x20 /* Already emitted a return. */ +#define PROTO_FIXUP_RETURN 0x40 /* Need to fixup emitted returns. */ +/* Top bits used for counting created closures. */ +#define PROTO_CLCOUNT 0x20 /* Base of saturating 3 bit counter. */ +#define PROTO_CLC_BITS 3 +#define PROTO_CLC_POLY (3*PROTO_CLCOUNT) /* Polymorphic threshold. */ + +#define PROTO_UV_LOCAL 0x8000 /* Upvalue for local slot. */ +#define PROTO_UV_IMMUTABLE 0x4000 /* Immutable upvalue. */ + +#define proto_kgc(pt, idx) \ + check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \ + gcref(mref((pt)->k, GCRef)[(idx)])) +#define proto_knumtv(pt, idx) \ + check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)]) +#define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto))) +#define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt))) +#define proto_uv(pt) (mref((pt)->uv, uint16_t)) + +#define proto_chunkname(pt) (strref((pt)->chunkname)) +#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt)))) +#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void)) +#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t)) +#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t)) + +/* -- Upvalue object ------------------------------------------------------ */ + +typedef struct GCupval { + GCHeader; + uint8_t closed; /* Set if closed (i.e. uv->v == &uv->u.value). */ + uint8_t immutable; /* Immutable value. */ + union { + TValue tv; /* If closed: the value itself. */ + struct { /* If open: double linked list, anchored at thread. */ + GCRef prev; + GCRef next; + }; + }; + MRef v; /* Points to stack slot (open) or above (closed). */ + uint32_t dhash; /* Disambiguation hash: dh1 != dh2 => cannot alias. */ +} GCupval; + +#define uvprev(uv_) (&gcref((uv_)->prev)->uv) +#define uvnext(uv_) (&gcref((uv_)->next)->uv) +#define uvval(uv_) (mref((uv_)->v, TValue)) + +/* -- Function object (closures) ------------------------------------------ */ + +/* Common header for functions. env should be at same offset in GCudata. */ +#define GCfuncHeader \ + GCHeader; uint8_t ffid; uint8_t nupvalues; \ + GCRef env; GCRef gclist; MRef pc + +typedef struct GCfuncC { + GCfuncHeader; + lua_CFunction f; /* C function to be called. */ + TValue upvalue[1]; /* Array of upvalues (TValue). */ +} GCfuncC; + +typedef struct GCfuncL { + GCfuncHeader; + GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */ +} GCfuncL; + +typedef union GCfunc { + GCfuncC c; + GCfuncL l; +} GCfunc; + +#define FF_LUA 0 +#define FF_C 1 +#define isluafunc(fn) ((fn)->c.ffid == FF_LUA) +#define iscfunc(fn) ((fn)->c.ffid == FF_C) +#define isffunc(fn) ((fn)->c.ffid > FF_C) +#define funcproto(fn) \ + check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto))) +#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n)) +#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n)) + +/* -- Table object -------------------------------------------------------- */ + +/* Hash node. */ +typedef struct Node { + TValue val; /* Value object. Must be first field. */ + TValue key; /* Key object. */ + MRef next; /* Hash chain. */ + MRef freetop; /* Top of free elements (stored in t->node[0]). */ +} Node; + +LJ_STATIC_ASSERT(offsetof(Node, val) == 0); + +typedef struct GCtab { + GCHeader; + uint8_t nomm; /* Negative cache for fast metamethods. */ + int8_t colo; /* Array colocation. */ + MRef array; /* Array part. */ + GCRef gclist; + GCRef metatable; /* Must be at same offset in GCudata. */ + MRef node; /* Hash part. */ + uint32_t asize; /* Size of array part (keys [0, asize-1]). */ + uint32_t hmask; /* Hash part mask (size of hash part - 1). */ +} GCtab; + +#define sizetabcolo(n) ((n)*sizeof(TValue) + sizeof(GCtab)) +#define tabref(r) (&gcref((r))->tab) +#define noderef(r) (mref((r), Node)) +#define nextnode(n) (mref((n)->next, Node)) + +/* -- State objects ------------------------------------------------------- */ + +/* VM states. */ +enum { + LJ_VMST_INTERP, /* Interpreter. */ + LJ_VMST_C, /* C function. */ + LJ_VMST_GC, /* Garbage collector. */ + LJ_VMST_EXIT, /* Trace exit handler. */ + LJ_VMST_RECORD, /* Trace recorder. */ + LJ_VMST_OPT, /* Optimizer. */ + LJ_VMST_ASM, /* Assembler. */ + LJ_VMST__MAX +}; + +#define setvmstate(g, st) ((g)->vmstate = ~LJ_VMST_##st) + +/* Metamethods. ORDER MM */ +#ifdef LJ_HASFFI +#define MMDEF_FFI(_) _(new) +#else +#define MMDEF_FFI(_) +#endif + +#if LJ_52 || LJ_HASFFI +#define MMDEF_PAIRS(_) _(pairs) _(ipairs) +#else +#define MMDEF_PAIRS(_) +#define MM_pairs 255 +#define MM_ipairs 255 +#endif + +#define MMDEF(_) \ + _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \ + /* Only the above (fast) metamethods are negative cached (max. 8). */ \ + _(lt) _(le) _(concat) _(call) \ + /* The following must be in ORDER ARITH. */ \ + _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \ + /* The following are used in the standard libraries. */ \ + _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_) + +typedef enum { +#define MMENUM(name) MM_##name, +MMDEF(MMENUM) +#undef MMENUM + MM__MAX, + MM____ = MM__MAX, + MM_FAST = MM_len +} MMS; + +/* GC root IDs. */ +typedef enum { + GCROOT_MMNAME, /* Metamethod names. */ + GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1, + GCROOT_BASEMT, /* Metatables for base types. */ + GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX, + GCROOT_IO_INPUT, /* Userdata for default I/O input file. */ + GCROOT_IO_OUTPUT, /* Userdata for default I/O output file. */ + GCROOT_MAX +} GCRootID; + +#define basemt_it(g, it) ((g)->gcroot[GCROOT_BASEMT+~(it)]) +#define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)]) +#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) + +typedef struct GCState { + MSize total; /* Memory currently allocated. */ + MSize threshold; /* Memory threshold. */ + uint8_t currentwhite; /* Current white color. */ + uint8_t state; /* GC state. */ + uint8_t nocdatafin; /* No cdata finalizer called. */ + uint8_t unused2; + MSize sweepstr; /* Sweep position in string table. */ + GCRef root; /* List of all collectable objects. */ + MRef sweep; /* Sweep position in root list. */ + GCRef gray; /* List of gray objects. */ + GCRef grayagain; /* List of objects for atomic traversal. */ + GCRef weak; /* List of weak tables (to be cleared). */ + GCRef mmudata; /* List of userdata (to be finalized). */ + MSize stepmul; /* Incremental GC step granularity. */ + MSize debt; /* Debt (how much GC is behind schedule). */ + MSize estimate; /* Estimate of memory actually in use. */ + MSize pause; /* Pause between successive GC cycles. */ +} GCState; + +/* Global state, shared by all threads of a Lua universe. */ +typedef struct global_State { + GCRef *strhash; /* String hash table (hash chain anchors). */ + MSize strmask; /* String hash mask (size of hash table - 1). */ + MSize strnum; /* Number of strings in hash table. */ + lua_Alloc allocf; /* Memory allocator. */ + void *allocd; /* Memory allocator data. */ + GCState gc; /* Garbage collector. */ + SBuf tmpbuf; /* Temporary buffer for string concatenation. */ + Node nilnode; /* Fallback 1-element hash part (nil key and value). */ + GCstr strempty; /* Empty string. */ + uint8_t stremptyz; /* Zero terminator of empty string. */ + uint8_t hookmask; /* Hook mask. */ + uint8_t dispatchmode; /* Dispatch mode. */ + uint8_t vmevmask; /* VM event mask. */ + GCRef mainthref; /* Link to main thread. */ + TValue registrytv; /* Anchor for registry. */ + TValue tmptv, tmptv2; /* Temporary TValues. */ + GCupval uvhead; /* Head of double-linked list of all open upvalues. */ + int32_t hookcount; /* Instruction hook countdown. */ + int32_t hookcstart; /* Start count for instruction hook counter. */ + lua_Hook hookf; /* Hook function. */ + lua_CFunction wrapf; /* Wrapper for C function calls. */ + lua_CFunction panic; /* Called as a last resort for errors. */ + volatile int32_t vmstate; /* VM state or current JIT code trace number. */ + BCIns bc_cfunc_int; /* Bytecode for internal C function calls. */ + BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */ + GCRef jit_L; /* Current JIT code lua_State or NULL. */ + MRef jit_base; /* Current JIT code L->base. */ + MRef ctype_state; /* Pointer to C type state. */ + GCRef gcroot[GCROOT_MAX]; /* GC roots. */ +} global_State; + +#define mainthread(g) (&gcref(g->mainthref)->th) +#define niltv(L) \ + check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val) +#define niltvg(g) \ + check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val) + +/* Hook management. Hook event masks are defined in lua.h. */ +#define HOOK_EVENTMASK 0x0f +#define HOOK_ACTIVE 0x10 +#define HOOK_ACTIVE_SHIFT 4 +#define HOOK_VMEVENT 0x20 +#define HOOK_GC 0x40 +#define hook_active(g) ((g)->hookmask & HOOK_ACTIVE) +#define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE) +#define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC)) +#define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT)) +#define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE) +#define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK) +#define hook_restore(g, h) \ + ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h)) + +/* Per-thread state object. */ +struct lua_State { + GCHeader; + uint8_t dummy_ffid; /* Fake FF_C for curr_funcisL() on dummy frames. */ + uint8_t status; /* Thread status. */ + MRef glref; /* Link to global state. */ + GCRef gclist; /* GC chain. */ + TValue *base; /* Base of currently executing function. */ + TValue *top; /* First free slot in the stack. */ + MRef maxstack; /* Last free slot in the stack. */ + MRef stack; /* Stack base. */ + GCRef openupval; /* List of open upvalues in the stack. */ + GCRef env; /* Thread environment (table of globals). */ + void *cframe; /* End of C stack frame chain. */ + MSize stacksize; /* True stack size (incl. LJ_STACK_EXTRA). */ +}; + +#define G(L) (mref(L->glref, global_State)) +#define registry(L) (&G(L)->registrytv) + +/* Macros to access the currently executing (Lua) function. */ +#define curr_func(L) (&gcref((L->base-1)->fr.func)->fn) +#define curr_funcisL(L) (isluafunc(curr_func(L))) +#define curr_proto(L) (funcproto(curr_func(L))) +#define curr_topL(L) (L->base + curr_proto(L)->framesize) +#define curr_top(L) (curr_funcisL(L) ? curr_topL(L) : L->top) + +/* -- GC object definition and conversions -------------------------------- */ + +/* GC header for generic access to common fields of GC objects. */ +typedef struct GChead { + GCHeader; + uint8_t unused1; + uint8_t unused2; + GCRef env; + GCRef gclist; + GCRef metatable; +} GChead; + +/* The env field SHOULD be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env)); +LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env)); + +/* The metatable field MUST be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable)); +LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable)); + +/* The gclist field MUST be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist)); + +typedef union GCobj { + GChead gch; + GCstr str; + GCupval uv; + lua_State th; + GCproto pt; + GCfunc fn; + GCcdata cd; + GCtab tab; + GCudata ud; +} GCobj; + +/* Macros to convert a GCobj pointer into a specific value. */ +#define gco2str(o) check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str) +#define gco2uv(o) check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv) +#define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th) +#define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt) +#define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn) +#define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd) +#define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab) +#define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud) + +/* Macro to convert any collectable object into a GCobj pointer. */ +#define obj2gco(v) ((GCobj *)(v)) + +/* -- TValue getters/setters ---------------------------------------------- */ + +#ifdef LUA_USE_ASSERT +#include "lj_gc.h" +#endif + +/* Macros to test types. */ +#define itype(o) ((o)->it) +#define tvisnil(o) (itype(o) == LJ_TNIL) +#define tvisfalse(o) (itype(o) == LJ_TFALSE) +#define tvistrue(o) (itype(o) == LJ_TTRUE) +#define tvisbool(o) (tvisfalse(o) || tvistrue(o)) +#if LJ_64 +#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2) +#else +#define tvislightud(o) (itype(o) == LJ_TLIGHTUD) +#endif +#define tvisstr(o) (itype(o) == LJ_TSTR) +#define tvisfunc(o) (itype(o) == LJ_TFUNC) +#define tvisthread(o) (itype(o) == LJ_TTHREAD) +#define tvisproto(o) (itype(o) == LJ_TPROTO) +#define tviscdata(o) (itype(o) == LJ_TCDATA) +#define tvistab(o) (itype(o) == LJ_TTAB) +#define tvisudata(o) (itype(o) == LJ_TUDATA) +#define tvisnumber(o) (itype(o) <= LJ_TISNUM) +#define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM) +#define tvisnum(o) (itype(o) < LJ_TISNUM) + +#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND) +#define tvispri(o) (itype(o) >= LJ_TISPRI) +#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */ +#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV)) + +/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */ +#define tvisnan(o) ((o)->n != (o)->n) +#if LJ_64 +#define tviszero(o) (((o)->u64 << 1) == 0) +#else +#define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0) +#endif +#define tvispzero(o) ((o)->u64 == 0) +#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000)) +#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000)) +#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64) + +/* Macros to convert type ids. */ +#if LJ_64 +#define itypemap(o) \ + (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o)) +#else +#define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o)) +#endif + +/* Macros to get tagged values. */ +#define gcval(o) (gcref((o)->gcr)) +#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it)) +#if LJ_64 +#define lightudV(o) \ + check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff))) +#else +#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void)) +#endif +#define gcV(o) check_exp(tvisgcv(o), gcval(o)) +#define strV(o) check_exp(tvisstr(o), &gcval(o)->str) +#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn) +#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th) +#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt) +#define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd) +#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) +#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) +#define numV(o) check_exp(tvisnum(o), (o)->n) +#define intV(o) check_exp(tvisint(o), (int32_t)(o)->i) + +/* Macros to set tagged values. */ +#define setitype(o, i) ((o)->it = (i)) +#define setnilV(o) ((o)->it = LJ_TNIL) +#define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x)) + +static LJ_AINLINE void setlightudV(TValue *o, void *p) +{ +#if LJ_64 + o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48); +#else + setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD); +#endif +} + +#if LJ_64 +#define checklightudptr(L, p) \ + (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p)) +#define setcont(o, f) \ + ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) +#else +#define checklightudptr(L, p) (p) +#define setcont(o, f) setlightudV((o), (void *)(f)) +#endif + +#define tvchecklive(L, o) \ + UNUSED(L), lua_assert(!tvisgcv(o) || \ + ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o)))) + +static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t itype) +{ + setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o); +} + +#define define_setV(name, type, tag) \ +static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \ +{ \ + setgcV(L, o, obj2gco(v), tag); \ +} +define_setV(setstrV, GCstr, LJ_TSTR) +define_setV(setthreadV, lua_State, LJ_TTHREAD) +define_setV(setprotoV, GCproto, LJ_TPROTO) +define_setV(setfuncV, GCfunc, LJ_TFUNC) +define_setV(setcdataV, GCcdata, LJ_TCDATA) +define_setV(settabV, GCtab, LJ_TTAB) +define_setV(setudataV, GCudata, LJ_TUDATA) + +#define setnumV(o, x) ((o)->n = (x)) +#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000)) +#define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000)) +#define setminfV(o) ((o)->u64 = U64x(fff00000,00000000)) + +static LJ_AINLINE void setintV(TValue *o, int32_t i) +{ +#if LJ_DUALNUM + o->i = (uint32_t)i; setitype(o, LJ_TISNUM); +#else + o->n = (lua_Number)i; +#endif +} + +static LJ_AINLINE void setint64V(TValue *o, int64_t i) +{ + if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i)) + setintV(o, (int32_t)i); + else + setnumV(o, (lua_Number)i); +} + +#if LJ_64 +#define setintptrV(o, i) setint64V((o), (i)) +#else +#define setintptrV(o, i) setintV((o), (i)) +#endif + +/* Copy tagged values. */ +static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2) +{ + *o1 = *o2; tvchecklive(L, o1); +} + +/* -- Number to integer conversion ---------------------------------------- */ + +#if LJ_SOFTFP +LJ_ASMF int32_t lj_vm_tobit(double x); +#endif + +static LJ_AINLINE int32_t lj_num2bit(lua_Number n) +{ +#if LJ_SOFTFP + return lj_vm_tobit(n); +#else + TValue o; + o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */ + return (int32_t)o.u32.lo; +#endif +} + +#if LJ_TARGET_X86 && !defined(__SSE2__) +#define lj_num2int(n) lj_num2bit((n)) +#else +#define lj_num2int(n) ((int32_t)(n)) +#endif + +static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) +{ +#ifdef _MSC_VER + if (n >= 9223372036854775808.0) /* They think it's a feature. */ + return (uint64_t)(int64_t)(n - 18446744073709551616.0); + else +#endif + return (uint64_t)n; +} + +static LJ_AINLINE int32_t numberVint(cTValue *o) +{ + if (LJ_LIKELY(tvisint(o))) + return intV(o); + else + return lj_num2int(numV(o)); +} + +static LJ_AINLINE lua_Number numberVnum(cTValue *o) +{ + if (LJ_UNLIKELY(tvisint(o))) + return (lua_Number)intV(o); + else + return numV(o); +} + +/* -- Miscellaneous object handling --------------------------------------- */ + +/* Names and maps for internal and external object tags. */ +LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1]; +LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1]; + +#define lj_typename(o) (lj_obj_itypename[itypemap(o)]) + +/* Compare two objects without calling metamethods. */ +LJ_FUNC int lj_obj_equal(cTValue *o1, cTValue *o2); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_dce.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_dce.c new file mode 100644 index 0000000..be80189 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_dce.c @@ -0,0 +1,77 @@ +/* +** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_dce_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Scan through all snapshots and mark all referenced instructions. */ +static void dce_marksnap(jit_State *J) +{ + SnapNo i, nsnap = J->cur.nsnap; + for (i = 0; i < nsnap; i++) { + SnapShot *snap = &J->cur.snap[i]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (ref >= REF_FIRST) + irt_setmark(IR(ref)->t); + } + } +} + +/* Backwards propagate marks. Replace unused instructions with NOPs. */ +static void dce_propagate(jit_State *J) +{ + IRRef1 *pchain[IR__MAX]; + IRRef ins; + uint32_t i; + for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i]; + for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) { + IRIns *ir = IR(ins); + if (irt_ismarked(ir->t)) { + irt_clearmark(ir->t); + pchain[ir->o] = &ir->prev; + } else if (!ir_sideeff(ir)) { + *pchain[ir->o] = ir->prev; /* Reroute original instruction chain. */ + ir->t.irt = IRT_NIL; + ir->o = IR_NOP; /* Replace instruction with NOP. */ + ir->op1 = ir->op2 = 0; + ir->prev = 0; + continue; + } + if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t); + if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t); + } +} + +/* Dead Code Elimination. +** +** First backpropagate marks for all used instructions. Then replace +** the unused ones with a NOP. Note that compressing the IR to eliminate +** the NOPs does not pay off. +*/ +void lj_opt_dce(jit_State *J) +{ + if ((J->flags & JIT_F_OPT_DCE)) { + dce_marksnap(J); + dce_propagate(J); + } +} + +#undef IR + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_fold.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_fold.c new file mode 100644 index 0000000..8a5b41c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_fold.c @@ -0,0 +1,2297 @@ +/* +** FOLD: Constant Folding, Algebraic Simplifications and Reassociation. +** ABCelim: Array Bounds Check Elimination. +** CSE: Common-Subexpression Elimination. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_fold_c +#define LUA_CORE + +#include + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_carith.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Here's a short description how the FOLD engine processes instructions: +** +** The FOLD engine receives a single instruction stored in fins (J->fold.ins). +** The instruction and its operands are used to select matching fold rules. +** These are applied iteratively until a fixed point is reached. +** +** The 8 bit opcode of the instruction itself plus the opcodes of the +** two instructions referenced by its operands form a 24 bit key +** 'ins left right' (unused operands -> 0, literals -> lowest 8 bits). +** +** This key is used for partial matching against the fold rules. The +** left/right operand fields of the key are successively masked with +** the 'any' wildcard, from most specific to least specific: +** +** ins left right +** ins any right +** ins left any +** ins any any +** +** The masked key is used to lookup a matching fold rule in a semi-perfect +** hash table. If a matching rule is found, the related fold function is run. +** Multiple rules can share the same fold function. A fold rule may return +** one of several special values: +** +** - NEXTFOLD means no folding was applied, because an additional test +** inside the fold function failed. Matching continues against less +** specific fold rules. Finally the instruction is passed on to CSE. +** +** - RETRYFOLD means the instruction was modified in-place. Folding is +** retried as if this instruction had just been received. +** +** All other return values are terminal actions -- no further folding is +** applied: +** +** - INTFOLD(i) returns a reference to the integer constant i. +** +** - LEFTFOLD and RIGHTFOLD return the left/right operand reference +** without emitting an instruction. +** +** - CSEFOLD and EMITFOLD pass the instruction directly to CSE or emit +** it without passing through any further optimizations. +** +** - FAILFOLD, DROPFOLD and CONDFOLD only apply to instructions which have +** no result (e.g. guarded assertions): FAILFOLD means the guard would +** always fail, i.e. the current trace is pointless. DROPFOLD means +** the guard is always true and has been eliminated. CONDFOLD is a +** shortcut for FAILFOLD + cond (i.e. drop if true, otherwise fail). +** +** - Any other return value is interpreted as an IRRef or TRef. This +** can be a reference to an existing or a newly created instruction. +** Only the least-significant 16 bits (IRRef1) are used to form a TRef +** which is finally returned to the caller. +** +** The FOLD engine receives instructions both from the trace recorder and +** substituted instructions from LOOP unrolling. This means all types +** of instructions may end up here, even though the recorder bypasses +** FOLD in some cases. Thus all loads, stores and allocations must have +** an any/any rule to avoid being passed on to CSE. +** +** Carefully read the following requirements before adding or modifying +** any fold rules: +** +** Requirement #1: All fold rules must preserve their destination type. +** +** Consistently use INTFOLD() (KINT result) or lj_ir_knum() (KNUM result). +** Never use lj_ir_knumint() which can have either a KINT or KNUM result. +** +** Requirement #2: Fold rules should not create *new* instructions which +** reference operands *across* PHIs. +** +** E.g. a RETRYFOLD with 'fins->op1 = fleft->op1' is invalid if the +** left operand is a PHI. Then fleft->op1 would point across the PHI +** frontier to an invariant instruction. Adding a PHI for this instruction +** would be counterproductive. The solution is to add a barrier which +** prevents folding across PHIs, i.e. 'PHIBARRIER(fleft)' in this case. +** The only exception is for recurrences with high latencies like +** repeated int->num->int conversions. +** +** One could relax this condition a bit if the referenced instruction is +** a PHI, too. But this often leads to worse code due to excessive +** register shuffling. +** +** Note: returning *existing* instructions (e.g. LEFTFOLD) is ok, though. +** Even returning fleft->op1 would be ok, because a new PHI will added, +** if needed. But again, this leads to excessive register shuffling and +** should be avoided. +** +** Requirement #3: The set of all fold rules must be monotonic to guarantee +** termination. +** +** The goal is optimization, so one primarily wants to add strength-reducing +** rules. This means eliminating an instruction or replacing an instruction +** with one or more simpler instructions. Don't add fold rules which point +** into the other direction. +** +** Some rules (like commutativity) do not directly reduce the strength of +** an instruction, but enable other fold rules (e.g. by moving constants +** to the right operand). These rules must be made unidirectional to avoid +** cycles. +** +** Rule of thumb: the trace recorder expands the IR and FOLD shrinks it. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) +#define fleft (&J->fold.left) +#define fright (&J->fold.right) +#define knumleft (ir_knum(fleft)->n) +#define knumright (ir_knum(fright)->n) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Fold function type. Fastcall on x86 significantly reduces their size. */ +typedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J); + +/* Macros for the fold specs, so buildvm can recognize them. */ +#define LJFOLD(x) +#define LJFOLDX(x) +#define LJFOLDF(name) static TRef LJ_FASTCALL fold_##name(jit_State *J) +/* Note: They must be at the start of a line or buildvm ignores them! */ + +/* Barrier to prevent using operands across PHIs. */ +#define PHIBARRIER(ir) if (irt_isphi((ir)->t)) return NEXTFOLD + +/* Barrier to prevent folding across a GC step. +** GC steps can only happen at the head of a trace and at LOOP. +** And the GC is only driven forward if there is at least one allocation. +*/ +#define gcstep_barrier(J, ref) \ + ((ref) < J->chain[IR_LOOP] && \ + (J->chain[IR_SNEW] || J->chain[IR_XSNEW] || \ + J->chain[IR_TNEW] || J->chain[IR_TDUP] || \ + J->chain[IR_CNEW] || J->chain[IR_CNEWI] || J->chain[IR_TOSTR])) + +/* -- Constant folding for FP numbers ------------------------------------- */ + +LJFOLD(ADD KNUM KNUM) +LJFOLD(SUB KNUM KNUM) +LJFOLD(MUL KNUM KNUM) +LJFOLD(DIV KNUM KNUM) +LJFOLD(NEG KNUM KNUM) +LJFOLD(ABS KNUM KNUM) +LJFOLD(ATAN2 KNUM KNUM) +LJFOLD(LDEXP KNUM KNUM) +LJFOLD(MIN KNUM KNUM) +LJFOLD(MAX KNUM KNUM) +LJFOLDF(kfold_numarith) +{ + lua_Number a = knumleft; + lua_Number b = knumright; + lua_Number y = lj_vm_foldarith(a, b, fins->o - IR_ADD); + return lj_ir_knum(J, y); +} + +LJFOLD(LDEXP KNUM KINT) +LJFOLDF(kfold_ldexp) +{ +#if LJ_TARGET_X86ORX64 + UNUSED(J); + return NEXTFOLD; +#else + return lj_ir_knum(J, ldexp(knumleft, fright->i)); +#endif +} + +LJFOLD(FPMATH KNUM any) +LJFOLDF(kfold_fpmath) +{ + lua_Number a = knumleft; + lua_Number y = lj_vm_foldfpm(a, fins->op2); + return lj_ir_knum(J, y); +} + +LJFOLD(POW KNUM KINT) +LJFOLDF(kfold_numpow) +{ + lua_Number a = knumleft; + lua_Number b = (lua_Number)fright->i; + lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD); + return lj_ir_knum(J, y); +} + +/* Must not use kfold_kref for numbers (could be NaN). */ +LJFOLD(EQ KNUM KNUM) +LJFOLD(NE KNUM KNUM) +LJFOLD(LT KNUM KNUM) +LJFOLD(GE KNUM KNUM) +LJFOLD(LE KNUM KNUM) +LJFOLD(GT KNUM KNUM) +LJFOLD(ULT KNUM KNUM) +LJFOLD(UGE KNUM KNUM) +LJFOLD(ULE KNUM KNUM) +LJFOLD(UGT KNUM KNUM) +LJFOLDF(kfold_numcomp) +{ + return CONDFOLD(lj_ir_numcmp(knumleft, knumright, (IROp)fins->o)); +} + +/* -- Constant folding for 32 bit integers -------------------------------- */ + +static int32_t kfold_intop(int32_t k1, int32_t k2, IROp op) +{ + switch (op) { + case IR_ADD: k1 += k2; break; + case IR_SUB: k1 -= k2; break; + case IR_MUL: k1 *= k2; break; + case IR_MOD: k1 = lj_vm_modi(k1, k2); break; + case IR_NEG: k1 = -k1; break; + case IR_BAND: k1 &= k2; break; + case IR_BOR: k1 |= k2; break; + case IR_BXOR: k1 ^= k2; break; + case IR_BSHL: k1 <<= (k2 & 31); break; + case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 31)); break; + case IR_BSAR: k1 >>= (k2 & 31); break; + case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 31)); break; + case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 31)); break; + case IR_MIN: k1 = k1 < k2 ? k1 : k2; break; + case IR_MAX: k1 = k1 > k2 ? k1 : k2; break; + default: lua_assert(0); break; + } + return k1; +} + +LJFOLD(ADD KINT KINT) +LJFOLD(SUB KINT KINT) +LJFOLD(MUL KINT KINT) +LJFOLD(MOD KINT KINT) +LJFOLD(NEG KINT KINT) +LJFOLD(BAND KINT KINT) +LJFOLD(BOR KINT KINT) +LJFOLD(BXOR KINT KINT) +LJFOLD(BSHL KINT KINT) +LJFOLD(BSHR KINT KINT) +LJFOLD(BSAR KINT KINT) +LJFOLD(BROL KINT KINT) +LJFOLD(BROR KINT KINT) +LJFOLD(MIN KINT KINT) +LJFOLD(MAX KINT KINT) +LJFOLDF(kfold_intarith) +{ + return INTFOLD(kfold_intop(fleft->i, fright->i, (IROp)fins->o)); +} + +LJFOLD(ADDOV KINT KINT) +LJFOLD(SUBOV KINT KINT) +LJFOLD(MULOV KINT KINT) +LJFOLDF(kfold_intovarith) +{ + lua_Number n = lj_vm_foldarith((lua_Number)fleft->i, (lua_Number)fright->i, + fins->o - IR_ADDOV); + int32_t k = lj_num2int(n); + if (n != (lua_Number)k) + return FAILFOLD; + return INTFOLD(k); +} + +LJFOLD(BNOT KINT) +LJFOLDF(kfold_bnot) +{ + return INTFOLD(~fleft->i); +} + +LJFOLD(BSWAP KINT) +LJFOLDF(kfold_bswap) +{ + return INTFOLD((int32_t)lj_bswap((uint32_t)fleft->i)); +} + +LJFOLD(LT KINT KINT) +LJFOLD(GE KINT KINT) +LJFOLD(LE KINT KINT) +LJFOLD(GT KINT KINT) +LJFOLD(ULT KINT KINT) +LJFOLD(UGE KINT KINT) +LJFOLD(ULE KINT KINT) +LJFOLD(UGT KINT KINT) +LJFOLD(ABC KINT KINT) +LJFOLDF(kfold_intcomp) +{ + int32_t a = fleft->i, b = fright->i; + switch ((IROp)fins->o) { + case IR_LT: return CONDFOLD(a < b); + case IR_GE: return CONDFOLD(a >= b); + case IR_LE: return CONDFOLD(a <= b); + case IR_GT: return CONDFOLD(a > b); + case IR_ULT: return CONDFOLD((uint32_t)a < (uint32_t)b); + case IR_UGE: return CONDFOLD((uint32_t)a >= (uint32_t)b); + case IR_ULE: return CONDFOLD((uint32_t)a <= (uint32_t)b); + case IR_ABC: + case IR_UGT: return CONDFOLD((uint32_t)a > (uint32_t)b); + default: lua_assert(0); return FAILFOLD; + } +} + +LJFOLD(UGE any KINT) +LJFOLDF(kfold_intcomp0) +{ + if (fright->i == 0) + return DROPFOLD; + return NEXTFOLD; +} + +/* -- Constant folding for 64 bit integers -------------------------------- */ + +static uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op) +{ + switch (op) { +#if LJ_64 || LJ_HASFFI + case IR_ADD: k1 += k2; break; + case IR_SUB: k1 -= k2; break; +#endif +#if LJ_HASFFI + case IR_MUL: k1 *= k2; break; + case IR_BAND: k1 &= k2; break; + case IR_BOR: k1 |= k2; break; + case IR_BXOR: k1 ^= k2; break; +#endif + default: UNUSED(k2); lua_assert(0); break; + } + return k1; +} + +LJFOLD(ADD KINT64 KINT64) +LJFOLD(SUB KINT64 KINT64) +LJFOLD(MUL KINT64 KINT64) +LJFOLD(BAND KINT64 KINT64) +LJFOLD(BOR KINT64 KINT64) +LJFOLD(BXOR KINT64 KINT64) +LJFOLDF(kfold_int64arith) +{ + return INT64FOLD(kfold_int64arith(ir_k64(fleft)->u64, + ir_k64(fright)->u64, (IROp)fins->o)); +} + +LJFOLD(DIV KINT64 KINT64) +LJFOLD(MOD KINT64 KINT64) +LJFOLD(POW KINT64 KINT64) +LJFOLDF(kfold_int64arith2) +{ +#if LJ_HASFFI + uint64_t k1 = ir_k64(fleft)->u64, k2 = ir_k64(fright)->u64; + if (irt_isi64(fins->t)) { + k1 = fins->o == IR_DIV ? lj_carith_divi64((int64_t)k1, (int64_t)k2) : + fins->o == IR_MOD ? lj_carith_modi64((int64_t)k1, (int64_t)k2) : + lj_carith_powi64((int64_t)k1, (int64_t)k2); + } else { + k1 = fins->o == IR_DIV ? lj_carith_divu64(k1, k2) : + fins->o == IR_MOD ? lj_carith_modu64(k1, k2) : + lj_carith_powu64(k1, k2); + } + return INT64FOLD(k1); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BSHL KINT64 KINT) +LJFOLD(BSHR KINT64 KINT) +LJFOLD(BSAR KINT64 KINT) +LJFOLD(BROL KINT64 KINT) +LJFOLD(BROR KINT64 KINT) +LJFOLDF(kfold_int64shift) +{ +#if LJ_HASFFI || LJ_64 + uint64_t k = ir_k64(fleft)->u64; + int32_t sh = (fright->i & 63); + switch ((IROp)fins->o) { + case IR_BSHL: k <<= sh; break; +#if LJ_HASFFI + case IR_BSHR: k >>= sh; break; + case IR_BSAR: k = (uint64_t)((int64_t)k >> sh); break; + case IR_BROL: k = lj_rol(k, sh); break; + case IR_BROR: k = lj_ror(k, sh); break; +#endif + default: lua_assert(0); break; + } + return INT64FOLD(k); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BNOT KINT64) +LJFOLDF(kfold_bnot64) +{ +#if LJ_HASFFI + return INT64FOLD(~ir_k64(fleft)->u64); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BSWAP KINT64) +LJFOLDF(kfold_bswap64) +{ +#if LJ_HASFFI + return INT64FOLD(lj_bswap64(ir_k64(fleft)->u64)); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(LT KINT64 KINT64) +LJFOLD(GE KINT64 KINT64) +LJFOLD(LE KINT64 KINT64) +LJFOLD(GT KINT64 KINT64) +LJFOLD(ULT KINT64 KINT64) +LJFOLD(UGE KINT64 KINT64) +LJFOLD(ULE KINT64 KINT64) +LJFOLD(UGT KINT64 KINT64) +LJFOLDF(kfold_int64comp) +{ +#if LJ_HASFFI + uint64_t a = ir_k64(fleft)->u64, b = ir_k64(fright)->u64; + switch ((IROp)fins->o) { + case IR_LT: return CONDFOLD(a < b); + case IR_GE: return CONDFOLD(a >= b); + case IR_LE: return CONDFOLD(a <= b); + case IR_GT: return CONDFOLD(a > b); + case IR_ULT: return CONDFOLD((uint64_t)a < (uint64_t)b); + case IR_UGE: return CONDFOLD((uint64_t)a >= (uint64_t)b); + case IR_ULE: return CONDFOLD((uint64_t)a <= (uint64_t)b); + case IR_UGT: return CONDFOLD((uint64_t)a > (uint64_t)b); + default: lua_assert(0); return FAILFOLD; + } +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(UGE any KINT64) +LJFOLDF(kfold_int64comp0) +{ +#if LJ_HASFFI + if (ir_k64(fright)->u64 == 0) + return DROPFOLD; + return NEXTFOLD; +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +/* -- Constant folding for strings ---------------------------------------- */ + +LJFOLD(SNEW KKPTR KINT) +LJFOLDF(kfold_snew_kptr) +{ + GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i); + return lj_ir_kstr(J, s); +} + +LJFOLD(SNEW any KINT) +LJFOLDF(kfold_snew_empty) +{ + if (fright->i == 0) + return lj_ir_kstr(J, &J2G(J)->strempty); + return NEXTFOLD; +} + +LJFOLD(STRREF KGC KINT) +LJFOLDF(kfold_strref) +{ + GCstr *str = ir_kstr(fleft); + lua_assert((MSize)fright->i <= str->len); + return lj_ir_kkptr(J, (char *)strdata(str) + fright->i); +} + +LJFOLD(STRREF SNEW any) +LJFOLDF(kfold_strref_snew) +{ + PHIBARRIER(fleft); + if (irref_isk(fins->op2) && fright->i == 0) { + return fleft->op1; /* strref(snew(ptr, len), 0) ==> ptr */ + } else { + /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */ + IRIns *ir = IR(fleft->op1); + IRRef1 str = ir->op1; /* IRIns * is not valid across emitir. */ + lua_assert(ir->o == IR_STRREF); + PHIBARRIER(ir); + fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */ + fins->op1 = str; + fins->ot = IRT(IR_STRREF, IRT_P32); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(CALLN CARG IRCALL_lj_str_cmp) +LJFOLDF(kfold_strcmp) +{ + if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) { + GCstr *a = ir_kstr(IR(fleft->op1)); + GCstr *b = ir_kstr(IR(fleft->op2)); + return INTFOLD(lj_str_cmp(a, b)); + } + return NEXTFOLD; +} + +/* -- Constant folding of pointer arithmetic ------------------------------ */ + +LJFOLD(ADD KGC KINT) +LJFOLD(ADD KGC KINT64) +LJFOLDF(kfold_add_kgc) +{ + GCobj *o = ir_kgc(fleft); +#if LJ_64 + ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64; +#else + ptrdiff_t ofs = fright->i; +#endif +#if LJ_HASFFI + if (irt_iscdata(fleft->t)) { + CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid); + if (ctype_isnum(ct->info) || ctype_isenum(ct->info) || + ctype_isptr(ct->info) || ctype_isfunc(ct->info) || + ctype_iscomplex(ct->info) || ctype_isvector(ct->info)) + return lj_ir_kkptr(J, (char *)o + ofs); + } +#endif + return lj_ir_kptr(J, (char *)o + ofs); +} + +LJFOLD(ADD KPTR KINT) +LJFOLD(ADD KPTR KINT64) +LJFOLD(ADD KKPTR KINT) +LJFOLD(ADD KKPTR KINT64) +LJFOLDF(kfold_add_kptr) +{ + void *p = ir_kptr(fleft); +#if LJ_64 + ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64; +#else + ptrdiff_t ofs = fright->i; +#endif + return lj_ir_kptr_(J, fleft->o, (char *)p + ofs); +} + +LJFOLD(ADD any KGC) +LJFOLD(ADD any KPTR) +LJFOLD(ADD any KKPTR) +LJFOLDF(kfold_add_kright) +{ + if (fleft->o == IR_KINT || fleft->o == IR_KINT64) { + IRRef1 tmp = fins->op1; fins->op1 = fins->op2; fins->op2 = tmp; + return RETRYFOLD; + } + return NEXTFOLD; +} + +/* -- Constant folding of conversions ------------------------------------- */ + +LJFOLD(TOBIT KNUM KNUM) +LJFOLDF(kfold_tobit) +{ + return INTFOLD(lj_num2bit(knumleft)); +} + +LJFOLD(CONV KINT IRCONV_NUM_INT) +LJFOLDF(kfold_conv_kint_num) +{ + return lj_ir_knum(J, (lua_Number)fleft->i); +} + +LJFOLD(CONV KINT IRCONV_NUM_U32) +LJFOLDF(kfold_conv_kintu32_num) +{ + return lj_ir_knum(J, (lua_Number)(uint32_t)fleft->i); +} + +LJFOLD(CONV KINT IRCONV_INT_I8) +LJFOLD(CONV KINT IRCONV_INT_U8) +LJFOLD(CONV KINT IRCONV_INT_I16) +LJFOLD(CONV KINT IRCONV_INT_U16) +LJFOLDF(kfold_conv_kint_ext) +{ + int32_t k = fleft->i; + if ((fins->op2 & IRCONV_SRCMASK) == IRT_I8) k = (int8_t)k; + else if ((fins->op2 & IRCONV_SRCMASK) == IRT_U8) k = (uint8_t)k; + else if ((fins->op2 & IRCONV_SRCMASK) == IRT_I16) k = (int16_t)k; + else k = (uint16_t)k; + return INTFOLD(k); +} + +LJFOLD(CONV KINT IRCONV_I64_INT) +LJFOLD(CONV KINT IRCONV_U64_INT) +LJFOLD(CONV KINT IRCONV_I64_U32) +LJFOLD(CONV KINT IRCONV_U64_U32) +LJFOLDF(kfold_conv_kint_i64) +{ + if ((fins->op2 & IRCONV_SEXT)) + return INT64FOLD((uint64_t)(int64_t)fleft->i); + else + return INT64FOLD((uint64_t)(int64_t)(uint32_t)fleft->i); +} + +LJFOLD(CONV KINT64 IRCONV_NUM_I64) +LJFOLDF(kfold_conv_kint64_num_i64) +{ + return lj_ir_knum(J, (lua_Number)(int64_t)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KINT64 IRCONV_NUM_U64) +LJFOLDF(kfold_conv_kint64_num_u64) +{ + return lj_ir_knum(J, (lua_Number)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KINT64 IRCONV_INT_I64) +LJFOLD(CONV KINT64 IRCONV_U32_I64) +LJFOLDF(kfold_conv_kint64_int_i64) +{ + return INTFOLD((int32_t)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KNUM IRCONV_INT_NUM) +LJFOLDF(kfold_conv_knum_int_num) +{ + lua_Number n = knumleft; + if (!(fins->op2 & IRCONV_TRUNC)) { + int32_t k = lj_num2int(n); + if (irt_isguard(fins->t) && n != (lua_Number)k) { + /* We're about to create a guard which always fails, like CONV +1.5. + ** Some pathological loops cause this during LICM, e.g.: + ** local x,k,t = 0,1.5,{1,[1.5]=2} + ** for i=1,200 do x = x+ t[k]; k = k == 1 and 1.5 or 1 end + ** assert(x == 300) + */ + return FAILFOLD; + } + return INTFOLD(k); + } else { + return INTFOLD((int32_t)n); + } +} + +LJFOLD(CONV KNUM IRCONV_U32_NUM) +LJFOLDF(kfold_conv_knum_u32_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); +#ifdef _MSC_VER + { /* Workaround for MSVC bug. */ + volatile uint32_t u = (uint32_t)knumleft; + return INTFOLD((int32_t)u); + } +#else + return INTFOLD((int32_t)(uint32_t)knumleft); +#endif +} + +LJFOLD(CONV KNUM IRCONV_I64_NUM) +LJFOLDF(kfold_conv_knum_i64_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); + return INT64FOLD((uint64_t)(int64_t)knumleft); +} + +LJFOLD(CONV KNUM IRCONV_U64_NUM) +LJFOLDF(kfold_conv_knum_u64_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); + return INT64FOLD(lj_num2u64(knumleft)); +} + +LJFOLD(TOSTR KNUM) +LJFOLDF(kfold_tostr_knum) +{ + return lj_ir_kstr(J, lj_str_fromnum(J->L, &knumleft)); +} + +LJFOLD(TOSTR KINT) +LJFOLDF(kfold_tostr_kint) +{ + return lj_ir_kstr(J, lj_str_fromint(J->L, fleft->i)); +} + +LJFOLD(STRTO KGC) +LJFOLDF(kfold_strto) +{ + TValue n; + if (lj_strscan_num(ir_kstr(fleft), &n)) + return lj_ir_knum(J, numV(&n)); + return FAILFOLD; +} + +/* -- Constant folding of equality checks --------------------------------- */ + +/* Don't constant-fold away FLOAD checks against KNULL. */ +LJFOLD(EQ FLOAD KNULL) +LJFOLD(NE FLOAD KNULL) +LJFOLDX(lj_opt_cse) + +/* But fold all other KNULL compares, since only KNULL is equal to KNULL. */ +LJFOLD(EQ any KNULL) +LJFOLD(NE any KNULL) +LJFOLD(EQ KNULL any) +LJFOLD(NE KNULL any) +LJFOLD(EQ KINT KINT) /* Constants are unique, so same refs <==> same value. */ +LJFOLD(NE KINT KINT) +LJFOLD(EQ KINT64 KINT64) +LJFOLD(NE KINT64 KINT64) +LJFOLD(EQ KGC KGC) +LJFOLD(NE KGC KGC) +LJFOLDF(kfold_kref) +{ + return CONDFOLD((fins->op1 == fins->op2) ^ (fins->o == IR_NE)); +} + +/* -- Algebraic shortcuts ------------------------------------------------- */ + +LJFOLD(FPMATH FPMATH IRFPM_FLOOR) +LJFOLD(FPMATH FPMATH IRFPM_CEIL) +LJFOLD(FPMATH FPMATH IRFPM_TRUNC) +LJFOLDF(shortcut_round) +{ + IRFPMathOp op = (IRFPMathOp)fleft->op2; + if (op == IRFPM_FLOOR || op == IRFPM_CEIL || op == IRFPM_TRUNC) + return LEFTFOLD; /* round(round_left(x)) = round_left(x) */ + return NEXTFOLD; +} + +LJFOLD(ABS ABS KNUM) +LJFOLDF(shortcut_left) +{ + return LEFTFOLD; /* f(g(x)) ==> g(x) */ +} + +LJFOLD(ABS NEG KNUM) +LJFOLDF(shortcut_dropleft) +{ + PHIBARRIER(fleft); + fins->op1 = fleft->op1; /* abs(neg(x)) ==> abs(x) */ + return RETRYFOLD; +} + +/* Note: no safe shortcuts with STRTO and TOSTR ("1e2" ==> +100 ==> "100"). */ +LJFOLD(NEG NEG any) +LJFOLD(BNOT BNOT) +LJFOLD(BSWAP BSWAP) +LJFOLDF(shortcut_leftleft) +{ + PHIBARRIER(fleft); /* See above. Fold would be ok, but not beneficial. */ + return fleft->op1; /* f(g(x)) ==> x */ +} + +/* -- FP algebraic simplifications ---------------------------------------- */ + +/* FP arithmetic is tricky -- there's not much to simplify. +** Please note the following common pitfalls before sending "improvements": +** x+0 ==> x is INVALID for x=-0 +** 0-x ==> -x is INVALID for x=+0 +** x*0 ==> 0 is INVALID for x=-0, x=+-Inf or x=NaN +*/ + +LJFOLD(ADD NEG any) +LJFOLDF(simplify_numadd_negx) +{ + PHIBARRIER(fleft); + fins->o = IR_SUB; /* (-a) + b ==> b - a */ + fins->op1 = fins->op2; + fins->op2 = fleft->op1; + return RETRYFOLD; +} + +LJFOLD(ADD any NEG) +LJFOLDF(simplify_numadd_xneg) +{ + PHIBARRIER(fright); + fins->o = IR_SUB; /* a + (-b) ==> a - b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(SUB any KNUM) +LJFOLDF(simplify_numsub_k) +{ + lua_Number n = knumright; + if (n == 0.0) /* x - (+-0) ==> x */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(SUB NEG KNUM) +LJFOLDF(simplify_numsub_negk) +{ + PHIBARRIER(fleft); + fins->op2 = fleft->op1; /* (-x) - k ==> (-k) - x */ + fins->op1 = (IRRef1)lj_ir_knum(J, -knumright); + return RETRYFOLD; +} + +LJFOLD(SUB any NEG) +LJFOLDF(simplify_numsub_xneg) +{ + PHIBARRIER(fright); + fins->o = IR_ADD; /* a - (-b) ==> a + b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(MUL any KNUM) +LJFOLD(DIV any KNUM) +LJFOLDF(simplify_nummuldiv_k) +{ + lua_Number n = knumright; + if (n == 1.0) { /* x o 1 ==> x */ + return LEFTFOLD; + } else if (n == -1.0) { /* x o -1 ==> -x */ + fins->o = IR_NEG; + fins->op2 = (IRRef1)lj_ir_knum_neg(J); + return RETRYFOLD; + } else if (fins->o == IR_MUL && n == 2.0) { /* x * 2 ==> x + x */ + fins->o = IR_ADD; + fins->op2 = fins->op1; + return RETRYFOLD; + } else if (fins->o == IR_DIV) { /* x / 2^k ==> x * 2^-k */ + uint64_t u = ir_knum(fright)->u64; + uint32_t ex = ((uint32_t)(u >> 52) & 0x7ff); + if ((u & U64x(000fffff,ffffffff)) == 0 && ex - 1 < 0x7fd) { + u = (u & ((uint64_t)1 << 63)) | ((uint64_t)(0x7fe - ex) << 52); + fins->o = IR_MUL; /* Multiply by exact reciprocal. */ + fins->op2 = lj_ir_knum_u64(J, u); + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(MUL NEG KNUM) +LJFOLD(DIV NEG KNUM) +LJFOLDF(simplify_nummuldiv_negk) +{ + PHIBARRIER(fleft); + fins->op1 = fleft->op1; /* (-a) o k ==> a o (-k) */ + fins->op2 = (IRRef1)lj_ir_knum(J, -knumright); + return RETRYFOLD; +} + +LJFOLD(MUL NEG NEG) +LJFOLD(DIV NEG NEG) +LJFOLDF(simplify_nummuldiv_negneg) +{ + PHIBARRIER(fleft); + PHIBARRIER(fright); + fins->op1 = fleft->op1; /* (-a) o (-b) ==> a o b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(POW any KINT) +LJFOLDF(simplify_numpow_xk) +{ + int32_t k = fright->i; + TRef ref = fins->op1; + if (k == 0) /* x ^ 0 ==> 1 */ + return lj_ir_knum_one(J); /* Result must be a number, not an int. */ + if (k == 1) /* x ^ 1 ==> x */ + return LEFTFOLD; + if ((uint32_t)(k+65536) > 2*65536u) /* Limit code explosion. */ + return NEXTFOLD; + if (k < 0) { /* x ^ (-k) ==> (1/x) ^ k. */ + ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref); + k = -k; + } + /* Unroll x^k for 1 <= k <= 65536. */ + for (; (k & 1) == 0; k >>= 1) /* Handle leading zeros. */ + ref = emitir(IRTN(IR_MUL), ref, ref); + if ((k >>= 1) != 0) { /* Handle trailing bits. */ + TRef tmp = emitir(IRTN(IR_MUL), ref, ref); + for (; k != 1; k >>= 1) { + if (k & 1) + ref = emitir(IRTN(IR_MUL), ref, tmp); + tmp = emitir(IRTN(IR_MUL), tmp, tmp); + } + ref = emitir(IRTN(IR_MUL), ref, tmp); + } + return ref; +} + +LJFOLD(POW KNUM any) +LJFOLDF(simplify_numpow_kx) +{ + lua_Number n = knumleft; + if (n == 2.0) { /* 2.0 ^ i ==> ldexp(1.0, tonum(i)) */ + fins->o = IR_CONV; +#if LJ_TARGET_X86ORX64 + fins->op1 = fins->op2; + fins->op2 = IRCONV_NUM_INT; + fins->op2 = (IRRef1)lj_opt_fold(J); +#endif + fins->op1 = (IRRef1)lj_ir_knum_one(J); + fins->o = IR_LDEXP; + return RETRYFOLD; + } + return NEXTFOLD; +} + +/* -- Simplify conversions ------------------------------------------------ */ + +LJFOLD(CONV CONV IRCONV_NUM_INT) /* _NUM */ +LJFOLDF(shortcut_conv_num_int) +{ + PHIBARRIER(fleft); + /* Only safe with a guarded conversion to int. */ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_NUM && irt_isguard(fleft->t)) + return fleft->op1; /* f(g(x)) ==> x */ + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_INT_NUM) /* _INT */ +LJFOLD(CONV CONV IRCONV_U32_NUM) /* _U32*/ +LJFOLDF(simplify_conv_int_num) +{ + /* Fold even across PHI to avoid expensive num->int conversions in loop. */ + if ((fleft->op2 & IRCONV_SRCMASK) == + ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) + return fleft->op1; + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_I64_NUM) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U64_NUM) /* _INT or _U32 */ +LJFOLDF(simplify_conv_i64_num) +{ + PHIBARRIER(fleft); + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) { + /* Reduce to a sign-extension. */ + fins->op1 = fleft->op1; + fins->op2 = ((IRT_I64<<5)|IRT_INT|IRCONV_SEXT); + return RETRYFOLD; + } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) { +#if LJ_TARGET_X64 + return fleft->op1; +#else + /* Reduce to a zero-extension. */ + fins->op1 = fleft->op1; + fins->op2 = (IRT_I64<<5)|IRT_U32; + return RETRYFOLD; +#endif + } + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_INT_I64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_INT_U64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U32_I64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U32_U64) /* _INT or _U32 */ +LJFOLDF(simplify_conv_int_i64) +{ + int src; + PHIBARRIER(fleft); + src = (fleft->op2 & IRCONV_SRCMASK); + if (src == IRT_INT || src == IRT_U32) { + if (src == ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) { + return fleft->op1; + } else { + fins->op2 = ((fins->op2 & IRCONV_DSTMASK) | src); + fins->op1 = fleft->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_FLOAT_NUM) /* _FLOAT */ +LJFOLDF(simplify_conv_flt_num) +{ + PHIBARRIER(fleft); + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_FLOAT) + return fleft->op1; + return NEXTFOLD; +} + +/* Shortcut TOBIT + IRT_NUM <- IRT_INT/IRT_U32 conversion. */ +LJFOLD(TOBIT CONV KNUM) +LJFOLDF(simplify_tobit_conv) +{ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT || + (fleft->op2 & IRCONV_SRCMASK) == IRT_U32) { + /* Fold even across PHI to avoid expensive num->int conversions in loop. */ + lua_assert(irt_isnum(fleft->t)); + return fleft->op1; + } + return NEXTFOLD; +} + +/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */ +LJFOLD(FPMATH CONV IRFPM_FLOOR) +LJFOLD(FPMATH CONV IRFPM_CEIL) +LJFOLD(FPMATH CONV IRFPM_TRUNC) +LJFOLDF(simplify_floor_conv) +{ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT || + (fleft->op2 & IRCONV_SRCMASK) == IRT_U32) + return LEFTFOLD; + return NEXTFOLD; +} + +/* Strength reduction of widening. */ +LJFOLD(CONV any IRCONV_I64_INT) +LJFOLD(CONV any IRCONV_U64_INT) +LJFOLDF(simplify_conv_sext) +{ + IRRef ref = fins->op1; + int64_t ofs = 0; + if (!(fins->op2 & IRCONV_SEXT)) + return NEXTFOLD; + PHIBARRIER(fleft); + if (fleft->o == IR_XLOAD && (irt_isu8(fleft->t) || irt_isu16(fleft->t))) + goto ok_reduce; + if (fleft->o == IR_ADD && irref_isk(fleft->op2)) { + ofs = (int64_t)IR(fleft->op2)->i; + ref = fleft->op1; + } + /* Use scalar evolution analysis results to strength-reduce sign-extension. */ + if (ref == J->scev.idx) { + IRRef lo = J->scev.dir ? J->scev.start : J->scev.stop; + lua_assert(irt_isint(J->scev.t)); + if (lo && IR(lo)->i + ofs >= 0) { + ok_reduce: +#if LJ_TARGET_X64 + /* Eliminate widening. All 32 bit ops do an implicit zero-extension. */ + return LEFTFOLD; +#else + /* Reduce to a (cheaper) zero-extension. */ + fins->op2 &= ~IRCONV_SEXT; + return RETRYFOLD; +#endif + } + } + return NEXTFOLD; +} + +/* Strength reduction of narrowing. */ +LJFOLD(CONV ADD IRCONV_INT_I64) +LJFOLD(CONV SUB IRCONV_INT_I64) +LJFOLD(CONV MUL IRCONV_INT_I64) +LJFOLD(CONV ADD IRCONV_INT_U64) +LJFOLD(CONV SUB IRCONV_INT_U64) +LJFOLD(CONV MUL IRCONV_INT_U64) +LJFOLD(CONV ADD IRCONV_U32_I64) +LJFOLD(CONV SUB IRCONV_U32_I64) +LJFOLD(CONV MUL IRCONV_U32_I64) +LJFOLD(CONV ADD IRCONV_U32_U64) +LJFOLD(CONV SUB IRCONV_U32_U64) +LJFOLD(CONV MUL IRCONV_U32_U64) +LJFOLDF(simplify_conv_narrow) +{ + IROp op = (IROp)fleft->o; + IRType t = irt_type(fins->t); + IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2; + PHIBARRIER(fleft); + op1 = emitir(IRTI(IR_CONV), op1, mode); + op2 = emitir(IRTI(IR_CONV), op2, mode); + fins->ot = IRT(op, t); + fins->op1 = op1; + fins->op2 = op2; + return RETRYFOLD; +} + +/* Special CSE rule for CONV. */ +LJFOLD(CONV any any) +LJFOLDF(cse_conv) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + IRRef op1 = fins->op1, op2 = (fins->op2 & IRCONV_MODEMASK); + uint8_t guard = irt_isguard(fins->t); + IRRef ref = J->chain[IR_CONV]; + while (ref > op1) { + IRIns *ir = IR(ref); + /* Commoning with stronger checks is ok. */ + if (ir->op1 == op1 && (ir->op2 & IRCONV_MODEMASK) == op2 && + irt_isguard(ir->t) >= guard) + return ref; + ref = ir->prev; + } + } + return EMITFOLD; /* No fallthrough to regular CSE. */ +} + +/* FP conversion narrowing. */ +LJFOLD(TOBIT ADD KNUM) +LJFOLD(TOBIT SUB KNUM) +LJFOLD(CONV ADD IRCONV_INT_NUM) +LJFOLD(CONV SUB IRCONV_INT_NUM) +LJFOLD(CONV ADD IRCONV_I64_NUM) +LJFOLD(CONV SUB IRCONV_I64_NUM) +LJFOLDF(narrow_convert) +{ + PHIBARRIER(fleft); + /* Narrowing ignores PHIs and repeating it inside the loop is not useful. */ + if (J->chain[IR_LOOP]) + return NEXTFOLD; + lua_assert(fins->o != IR_CONV || (fins->op2&IRCONV_CONVMASK) != IRCONV_TOBIT); + return lj_opt_narrow_convert(J); +} + +/* -- Integer algebraic simplifications ----------------------------------- */ + +LJFOLD(ADD any KINT) +LJFOLD(ADDOV any KINT) +LJFOLD(SUBOV any KINT) +LJFOLDF(simplify_intadd_k) +{ + if (fright->i == 0) /* i o 0 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(MULOV any KINT) +LJFOLDF(simplify_intmul_k) +{ + if (fright->i == 0) /* i * 0 ==> 0 */ + return RIGHTFOLD; + if (fright->i == 1) /* i * 1 ==> i */ + return LEFTFOLD; + if (fright->i == 2) { /* i * 2 ==> i + i */ + fins->o = IR_ADDOV; + fins->op2 = fins->op1; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(SUB any KINT) +LJFOLDF(simplify_intsub_k) +{ + if (fright->i == 0) /* i - 0 ==> i */ + return LEFTFOLD; + fins->o = IR_ADD; /* i - k ==> i + (-k) */ + fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i); /* Overflow for -2^31 ok. */ + return RETRYFOLD; +} + +LJFOLD(SUB KINT any) +LJFOLD(SUB KINT64 any) +LJFOLDF(simplify_intsub_kleft) +{ + if (fleft->o == IR_KINT ? (fleft->i == 0) : (ir_kint64(fleft)->u64 == 0)) { + fins->o = IR_NEG; /* 0 - i ==> -i */ + fins->op1 = fins->op2; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(ADD any KINT64) +LJFOLDF(simplify_intadd_k64) +{ + if (ir_kint64(fright)->u64 == 0) /* i + 0 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(SUB any KINT64) +LJFOLDF(simplify_intsub_k64) +{ + uint64_t k = ir_kint64(fright)->u64; + if (k == 0) /* i - 0 ==> i */ + return LEFTFOLD; + fins->o = IR_ADD; /* i - k ==> i + (-k) */ + fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k); + return RETRYFOLD; +} + +static TRef simplify_intmul_k(jit_State *J, int32_t k) +{ + /* Note: many more simplifications are possible, e.g. 2^k1 +- 2^k2. + ** But this is mainly intended for simple address arithmetic. + ** Also it's easier for the backend to optimize the original multiplies. + */ + if (k == 1) { /* i * 1 ==> i */ + return LEFTFOLD; + } else if ((k & (k-1)) == 0) { /* i * 2^k ==> i << k */ + fins->o = IR_BSHL; + fins->op2 = lj_ir_kint(J, lj_fls((uint32_t)k)); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MUL any KINT) +LJFOLDF(simplify_intmul_k32) +{ + if (fright->i == 0) /* i * 0 ==> 0 */ + return INTFOLD(0); + else if (fright->i > 0) + return simplify_intmul_k(J, fright->i); + return NEXTFOLD; +} + +LJFOLD(MUL any KINT64) +LJFOLDF(simplify_intmul_k64) +{ + if (ir_kint64(fright)->u64 == 0) /* i * 0 ==> 0 */ + return INT64FOLD(0); +#if LJ_64 + /* NYI: SPLIT for BSHL and 32 bit backend support. */ + else if (ir_kint64(fright)->u64 < 0x80000000u) + return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64); +#endif + return NEXTFOLD; +} + +LJFOLD(MOD any KINT) +LJFOLDF(simplify_intmod_k) +{ + int32_t k = fright->i; + lua_assert(k != 0); + if (k > 0 && (k & (k-1)) == 0) { /* i % (2^k) ==> i & (2^k-1) */ + fins->o = IR_BAND; + fins->op2 = lj_ir_kint(J, k-1); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MOD KINT any) +LJFOLDF(simplify_intmod_kleft) +{ + if (fleft->i == 0) + return INTFOLD(0); + return NEXTFOLD; +} + +LJFOLD(SUB any any) +LJFOLD(SUBOV any any) +LJFOLDF(simplify_intsub) +{ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) /* i - i ==> 0 */ + return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0); + return NEXTFOLD; +} + +LJFOLD(SUB ADD any) +LJFOLDF(simplify_intsubadd_leftcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) /* (i + j) - i ==> j */ + return fleft->op2; + if (fins->op2 == fleft->op2) /* (i + j) - j ==> i */ + return fleft->op1; + } + return NEXTFOLD; +} + +LJFOLD(SUB SUB any) +LJFOLDF(simplify_intsubsub_leftcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) { /* (i - j) - i ==> 0 - j */ + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + fins->op2 = fleft->op2; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(SUB any SUB) +LJFOLDF(simplify_intsubsub_rightcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fright); + if (fins->op1 == fright->op1) /* i - (i - j) ==> j */ + return fright->op2; + } + return NEXTFOLD; +} + +LJFOLD(SUB any ADD) +LJFOLDF(simplify_intsubadd_rightcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fright); + if (fins->op1 == fright->op1) { /* i - (i + j) ==> 0 - j */ + fins->op2 = fright->op2; + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + return RETRYFOLD; + } + if (fins->op1 == fright->op2) { /* i - (j + i) ==> 0 - j */ + fins->op2 = fright->op1; + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(SUB ADD ADD) +LJFOLDF(simplify_intsubaddadd_cancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + PHIBARRIER(fright); + if (fleft->op1 == fright->op1) { /* (i + j1) - (i + j2) ==> j1 - j2 */ + fins->op1 = fleft->op2; + fins->op2 = fright->op2; + return RETRYFOLD; + } + if (fleft->op1 == fright->op2) { /* (i + j1) - (j2 + i) ==> j1 - j2 */ + fins->op1 = fleft->op2; + fins->op2 = fright->op1; + return RETRYFOLD; + } + if (fleft->op2 == fright->op1) { /* (j1 + i) - (i + j2) ==> j1 - j2 */ + fins->op1 = fleft->op1; + fins->op2 = fright->op2; + return RETRYFOLD; + } + if (fleft->op2 == fright->op2) { /* (j1 + i) - (j2 + i) ==> j1 - j2 */ + fins->op1 = fleft->op1; + fins->op2 = fright->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(BAND any KINT) +LJFOLD(BAND any KINT64) +LJFOLDF(simplify_band_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i & 0 ==> 0 */ + return RIGHTFOLD; + if (k == -1) /* i & -1 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BOR any KINT) +LJFOLD(BOR any KINT64) +LJFOLDF(simplify_bor_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i | 0 ==> i */ + return LEFTFOLD; + if (k == -1) /* i | -1 ==> -1 */ + return RIGHTFOLD; + return NEXTFOLD; +} + +LJFOLD(BXOR any KINT) +LJFOLD(BXOR any KINT64) +LJFOLDF(simplify_bxor_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i xor 0 ==> i */ + return LEFTFOLD; + if (k == -1) { /* i xor -1 ==> ~i */ + fins->o = IR_BNOT; + fins->op2 = 0; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BSHL any KINT) +LJFOLD(BSHR any KINT) +LJFOLD(BSAR any KINT) +LJFOLD(BROL any KINT) +LJFOLD(BROR any KINT) +LJFOLDF(simplify_shift_ik) +{ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = (fright->i & mask); + if (k == 0) /* i o 0 ==> i */ + return LEFTFOLD; + if (k == 1 && fins->o == IR_BSHL) { /* i << 1 ==> i + i */ + fins->o = IR_ADD; + fins->op2 = fins->op1; + return RETRYFOLD; + } + if (k != fright->i) { /* i o k ==> i o (k & mask) */ + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; + } +#ifndef LJ_TARGET_UNIFYROT + if (fins->o == IR_BROR) { /* bror(i, k) ==> brol(i, (-k)&mask) */ + fins->o = IR_BROL; + fins->op2 = (IRRef1)lj_ir_kint(J, (-k)&mask); + return RETRYFOLD; + } +#endif + return NEXTFOLD; +} + +LJFOLD(BSHL any BAND) +LJFOLD(BSHR any BAND) +LJFOLD(BSAR any BAND) +LJFOLD(BROL any BAND) +LJFOLD(BROR any BAND) +LJFOLDF(simplify_shift_andk) +{ + IRIns *irk = IR(fright->op2); + PHIBARRIER(fright); + if ((fins->o < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && + irk->o == IR_KINT) { /* i o (j & mask) ==> i o j */ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = irk->i & mask; + if (k == mask) { + fins->op2 = fright->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(BSHL KINT any) +LJFOLD(BSHR KINT any) +LJFOLD(BSHL KINT64 any) +LJFOLD(BSHR KINT64 any) +LJFOLDF(simplify_shift1_ki) +{ + int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i : + (int64_t)ir_k64(fleft)->u64; + if (k == 0) /* 0 o i ==> 0 */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BSAR KINT any) +LJFOLD(BROL KINT any) +LJFOLD(BROR KINT any) +LJFOLD(BSAR KINT64 any) +LJFOLD(BROL KINT64 any) +LJFOLD(BROR KINT64 any) +LJFOLDF(simplify_shift2_ki) +{ + int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i : + (int64_t)ir_k64(fleft)->u64; + if (k == 0 || k == -1) /* 0 o i ==> 0; -1 o i ==> -1 */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BSHL BAND KINT) +LJFOLD(BSHR BAND KINT) +LJFOLD(BROL BAND KINT) +LJFOLD(BROR BAND KINT) +LJFOLDF(simplify_shiftk_andk) +{ + IRIns *irk = IR(fleft->op2); + PHIBARRIER(fleft); + if (irk->o == IR_KINT) { /* (i & k1) o k2 ==> (i o k2) & (k1 o k2) */ + int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o); + fins->op1 = fleft->op1; + fins->op1 = (IRRef1)lj_opt_fold(J); + fins->op2 = (IRRef1)lj_ir_kint(J, k); + fins->ot = IRTI(IR_BAND); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BAND BSHL KINT) +LJFOLD(BAND BSHR KINT) +LJFOLDF(simplify_andk_shiftk) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT && + kfold_intop(-1, irk->i, (IROp)fleft->o) == fright->i) + return LEFTFOLD; /* (i o k1) & k2 ==> i, if (-1 o k1) == k2 */ + return NEXTFOLD; +} + +/* -- Reassociation ------------------------------------------------------- */ + +LJFOLD(ADD ADD KINT) +LJFOLD(MUL MUL KINT) +LJFOLD(BAND BAND KINT) +LJFOLD(BOR BOR KINT) +LJFOLD(BXOR BXOR KINT) +LJFOLDF(reassoc_intarith_k) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT) { + int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o); + if (k == irk->i) /* (i o k1) o k2 ==> i o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */ + } + return NEXTFOLD; +} + +LJFOLD(ADD ADD KINT64) +LJFOLD(MUL MUL KINT64) +LJFOLD(BAND BAND KINT64) +LJFOLD(BOR BOR KINT64) +LJFOLD(BXOR BXOR KINT64) +LJFOLDF(reassoc_intarith_k64) +{ +#if LJ_HASFFI || LJ_64 + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT64) { + uint64_t k = kfold_int64arith(ir_k64(irk)->u64, + ir_k64(fright)->u64, (IROp)fins->o); + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint64(J, k); + return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */ + } + return NEXTFOLD; +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(MIN MIN any) +LJFOLD(MAX MAX any) +LJFOLD(BAND BAND any) +LJFOLD(BOR BOR any) +LJFOLDF(reassoc_dup) +{ + if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2) + return LEFTFOLD; /* (a o b) o a ==> a o b; (a o b) o b ==> a o b */ + return NEXTFOLD; +} + +LJFOLD(BXOR BXOR any) +LJFOLDF(reassoc_bxor) +{ + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) /* (a xor b) xor a ==> b */ + return fleft->op2; + if (fins->op2 == fleft->op2) /* (a xor b) xor b ==> a */ + return fleft->op1; + return NEXTFOLD; +} + +LJFOLD(BSHL BSHL KINT) +LJFOLD(BSHR BSHR KINT) +LJFOLD(BSAR BSAR KINT) +LJFOLD(BROL BROL KINT) +LJFOLD(BROR BROR KINT) +LJFOLDF(reassoc_shift) +{ + IRIns *irk = IR(fleft->op2); + PHIBARRIER(fleft); /* The (shift any KINT) rule covers k2 == 0 and more. */ + if (irk->o == IR_KINT) { /* (i o k1) o k2 ==> i o (k1 + k2) */ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = (irk->i & mask) + (fright->i & mask); + if (k > mask) { /* Combined shift too wide? */ + if (fins->o == IR_BSHL || fins->o == IR_BSHR) + return mask == 31 ? INTFOLD(0) : INT64FOLD(0); + else if (fins->o == IR_BSAR) + k = mask; + else + k &= mask; + } + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MIN MIN KNUM) +LJFOLD(MAX MAX KNUM) +LJFOLD(MIN MIN KINT) +LJFOLD(MAX MAX KINT) +LJFOLDF(reassoc_minmax_k) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KNUM) { + lua_Number a = ir_knum(irk)->n; + lua_Number y = lj_vm_foldarith(a, knumright, fins->o - IR_ADD); + if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_knum(J, y); + return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */ + } else if (irk->o == IR_KINT) { + int32_t a = irk->i; + int32_t y = kfold_intop(a, fright->i, fins->o); + if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, y); + return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */ + } + return NEXTFOLD; +} + +LJFOLD(MIN MAX any) +LJFOLD(MAX MIN any) +LJFOLDF(reassoc_minmax_left) +{ + if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2) + return RIGHTFOLD; /* (b o1 a) o2 b ==> b; (a o1 b) o2 b ==> b */ + return NEXTFOLD; +} + +LJFOLD(MIN any MAX) +LJFOLD(MAX any MIN) +LJFOLDF(reassoc_minmax_right) +{ + if (fins->op1 == fright->op1 || fins->op1 == fright->op2) + return LEFTFOLD; /* a o2 (a o1 b) ==> a; a o2 (b o1 a) ==> a */ + return NEXTFOLD; +} + +/* -- Array bounds check elimination -------------------------------------- */ + +/* Eliminate ABC across PHIs to handle t[i-1] forwarding case. +** ABC(asize, (i+k)+(-k)) ==> ABC(asize, i), but only if it already exists. +** Could be generalized to (i+k1)+k2 ==> i+(k1+k2), but needs better disambig. +*/ +LJFOLD(ABC any ADD) +LJFOLDF(abc_fwd) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { + if (irref_isk(fright->op2)) { + IRIns *add2 = IR(fright->op1); + if (add2->o == IR_ADD && irref_isk(add2->op2) && + IR(fright->op2)->i == -IR(add2->op2)->i) { + IRRef ref = J->chain[IR_ABC]; + IRRef lim = add2->op1; + if (fins->op1 > lim) lim = fins->op1; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == fins->op1 && ir->op2 == add2->op1) + return DROPFOLD; + ref = ir->prev; + } + } + } + } + return NEXTFOLD; +} + +/* Eliminate ABC for constants. +** ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2)) +** Drop second ABC if k2 is lower. Otherwise patch first ABC with k2. +*/ +LJFOLD(ABC any KINT) +LJFOLDF(abc_k) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { + IRRef ref = J->chain[IR_ABC]; + IRRef asize = fins->op1; + while (ref > asize) { + IRIns *ir = IR(ref); + if (ir->op1 == asize && irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (fright->i > k) + ir->op2 = fins->op2; + return DROPFOLD; + } + ref = ir->prev; + } + return EMITFOLD; /* Already performed CSE. */ + } + return NEXTFOLD; +} + +/* Eliminate invariant ABC inside loop. */ +LJFOLD(ABC any any) +LJFOLDF(abc_invar) +{ + /* Invariant ABC marked as PTR. Drop if op1 is invariant, too. */ + if (!irt_isint(fins->t) && fins->op1 < J->chain[IR_LOOP] && + !irt_isphi(IR(fins->op1)->t)) + return DROPFOLD; + return NEXTFOLD; +} + +/* -- Commutativity ------------------------------------------------------- */ + +/* The refs of commutative ops are canonicalized. Lower refs go to the right. +** Rationale behind this: +** - It (also) moves constants to the right. +** - It reduces the number of FOLD rules (e.g. (BOR any KINT) suffices). +** - It helps CSE to find more matches. +** - The assembler generates better code with constants at the right. +*/ + +LJFOLD(ADD any any) +LJFOLD(MUL any any) +LJFOLD(ADDOV any any) +LJFOLD(MULOV any any) +LJFOLDF(comm_swap) +{ + if (fins->op1 < fins->op2) { /* Move lower ref to the right. */ + IRRef1 tmp = fins->op1; + fins->op1 = fins->op2; + fins->op2 = tmp; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(EQ any any) +LJFOLD(NE any any) +LJFOLDF(comm_equal) +{ + /* For non-numbers only: x == x ==> drop; x ~= x ==> fail */ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) + return CONDFOLD(fins->o == IR_EQ); + return fold_comm_swap(J); +} + +LJFOLD(LT any any) +LJFOLD(GE any any) +LJFOLD(LE any any) +LJFOLD(GT any any) +LJFOLD(ULT any any) +LJFOLD(UGE any any) +LJFOLD(ULE any any) +LJFOLD(UGT any any) +LJFOLDF(comm_comp) +{ + /* For non-numbers only: x <=> x ==> drop; x <> x ==> fail */ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) + return CONDFOLD((fins->o ^ (fins->o >> 1)) & 1); + if (fins->op1 < fins->op2) { /* Move lower ref to the right. */ + IRRef1 tmp = fins->op1; + fins->op1 = fins->op2; + fins->op2 = tmp; + fins->o ^= 3; /* GT <-> LT, GE <-> LE, does not affect U */ + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BAND any any) +LJFOLD(BOR any any) +LJFOLD(MIN any any) +LJFOLD(MAX any any) +LJFOLDF(comm_dup) +{ + if (fins->op1 == fins->op2) /* x o x ==> x */ + return LEFTFOLD; + return fold_comm_swap(J); +} + +LJFOLD(BXOR any any) +LJFOLDF(comm_bxor) +{ + if (fins->op1 == fins->op2) /* i xor i ==> 0 */ + return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0); + return fold_comm_swap(J); +} + +/* -- Simplification of compound expressions ------------------------------ */ + +static TRef kfold_xload(jit_State *J, IRIns *ir, const void *p) +{ + int32_t k; + switch (irt_type(ir->t)) { + case IRT_NUM: return lj_ir_knum_u64(J, *(uint64_t *)p); + case IRT_I8: k = (int32_t)*(int8_t *)p; break; + case IRT_U8: k = (int32_t)*(uint8_t *)p; break; + case IRT_I16: k = (int32_t)(int16_t)lj_getu16(p); break; + case IRT_U16: k = (int32_t)(uint16_t)lj_getu16(p); break; + case IRT_INT: case IRT_U32: k = (int32_t)lj_getu32(p); break; + case IRT_I64: case IRT_U64: return lj_ir_kint64(J, *(uint64_t *)p); + default: return 0; + } + return lj_ir_kint(J, k); +} + +/* Turn: string.sub(str, a, b) == kstr +** into: string.byte(str, a) == string.byte(kstr, 1) etc. +** Note: this creates unaligned XLOADs on x86/x64. +*/ +LJFOLD(EQ SNEW KGC) +LJFOLD(NE SNEW KGC) +LJFOLDF(merge_eqne_snew_kgc) +{ + GCstr *kstr = ir_kstr(fright); + int32_t len = (int32_t)kstr->len; + lua_assert(irt_isstr(fins->t)); + +#if LJ_TARGET_UNALIGNED +#define FOLD_SNEW_MAX_LEN 4 /* Handle string lengths 0, 1, 2, 3, 4. */ +#define FOLD_SNEW_TYPE8 IRT_I8 /* Creates shorter immediates. */ +#else +#define FOLD_SNEW_MAX_LEN 1 /* Handle string lengths 0 or 1. */ +#define FOLD_SNEW_TYPE8 IRT_U8 /* Prefer unsigned loads. */ +#endif + + PHIBARRIER(fleft); + if (len <= FOLD_SNEW_MAX_LEN) { + IROp op = (IROp)fins->o; + IRRef strref = fleft->op1; + lua_assert(IR(strref)->o == IR_STRREF); + if (op == IR_EQ) { + emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len)); + /* Caveat: fins/fleft/fright is no longer valid after emitir. */ + } else { + /* NE is not expanded since this would need an OR of two conds. */ + if (!irref_isk(fleft->op2)) /* Only handle the constant length case. */ + return NEXTFOLD; + if (IR(fleft->op2)->i != len) + return DROPFOLD; + } + if (len > 0) { + /* A 4 byte load for length 3 is ok -- all strings have an extra NUL. */ + uint16_t ot = (uint16_t)(len == 1 ? IRT(IR_XLOAD, FOLD_SNEW_TYPE8) : + len == 2 ? IRT(IR_XLOAD, IRT_U16) : + IRTI(IR_XLOAD)); + TRef tmp = emitir(ot, strref, + IRXLOAD_READONLY | (len > 1 ? IRXLOAD_UNALIGNED : 0)); + TRef val = kfold_xload(J, IR(tref_ref(tmp)), strdata(kstr)); + if (len == 3) + tmp = emitir(IRTI(IR_BAND), tmp, + lj_ir_kint(J, LJ_ENDIAN_SELECT(0x00ffffff, 0xffffff00))); + fins->op1 = (IRRef1)tmp; + fins->op2 = (IRRef1)val; + fins->ot = (IROpT)IRTGI(op); + return RETRYFOLD; + } else { + return DROPFOLD; + } + } + return NEXTFOLD; +} + +/* -- Loads --------------------------------------------------------------- */ + +/* Loads cannot be folded or passed on to CSE in general. +** Alias analysis is needed to check for forwarding opportunities. +** +** Caveat: *all* loads must be listed here or they end up at CSE! +*/ + +LJFOLD(ALOAD any) +LJFOLDX(lj_opt_fwd_aload) + +/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */ +LJFOLD(HLOAD KKPTR) +LJFOLDF(kfold_hload_kkptr) +{ + UNUSED(J); + lua_assert(ir_kptr(fleft) == niltvg(J2G(J))); + return TREF_NIL; +} + +LJFOLD(HLOAD any) +LJFOLDX(lj_opt_fwd_hload) + +LJFOLD(ULOAD any) +LJFOLDX(lj_opt_fwd_uload) + +LJFOLD(CALLL any IRCALL_lj_tab_len) +LJFOLDX(lj_opt_fwd_tab_len) + +/* Upvalue refs are really loads, but there are no corresponding stores. +** So CSE is ok for them, except for UREFO across a GC step (see below). +** If the referenced function is const, its upvalue addresses are const, too. +** This can be used to improve CSE by looking for the same address, +** even if the upvalues originate from a different function. +*/ +LJFOLD(UREFO KGC any) +LJFOLD(UREFC KGC any) +LJFOLDF(cse_uref) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + IRRef ref = J->chain[fins->o]; + GCfunc *fn = ir_kfunc(fleft); + GCupval *uv = gco2uv(gcref(fn->l.uvptr[(fins->op2 >> 8)])); + while (ref > 0) { + IRIns *ir = IR(ref); + if (irref_isk(ir->op1)) { + GCfunc *fn2 = ir_kfunc(IR(ir->op1)); + if (gco2uv(gcref(fn2->l.uvptr[(ir->op2 >> 8)])) == uv) { + if (fins->o == IR_UREFO && gcstep_barrier(J, ref)) + break; + return ref; + } + } + ref = ir->prev; + } + } + return EMITFOLD; +} + +LJFOLD(HREFK any any) +LJFOLDX(lj_opt_fwd_hrefk) + +LJFOLD(HREF TNEW any) +LJFOLDF(fwd_href_tnew) +{ + if (lj_opt_fwd_href_nokey(J)) + return lj_ir_kkptr(J, niltvg(J2G(J))); + return NEXTFOLD; +} + +LJFOLD(HREF TDUP KPRI) +LJFOLD(HREF TDUP KGC) +LJFOLD(HREF TDUP KNUM) +LJFOLDF(fwd_href_tdup) +{ + TValue keyv; + lj_ir_kvalue(J->L, &keyv, fright); + if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) && + lj_opt_fwd_href_nokey(J)) + return lj_ir_kkptr(J, niltvg(J2G(J))); + return NEXTFOLD; +} + +/* We can safely FOLD/CSE array/hash refs and field loads, since there +** are no corresponding stores. But we need to check for any NEWREF with +** an aliased table, as it may invalidate all of the pointers and fields. +** Only HREF needs the NEWREF check -- AREF and HREFK already depend on +** FLOADs. And NEWREF itself is treated like a store (see below). +*/ +LJFOLD(FLOAD TNEW IRFL_TAB_ASIZE) +LJFOLDF(fload_tab_tnew_asize) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD(fleft->op1); + return NEXTFOLD; +} + +LJFOLD(FLOAD TNEW IRFL_TAB_HMASK) +LJFOLDF(fload_tab_tnew_hmask) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((1 << fleft->op2)-1); + return NEXTFOLD; +} + +LJFOLD(FLOAD TDUP IRFL_TAB_ASIZE) +LJFOLDF(fload_tab_tdup_asize) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->asize); + return NEXTFOLD; +} + +LJFOLD(FLOAD TDUP IRFL_TAB_HMASK) +LJFOLDF(fload_tab_tdup_hmask) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->hmask); + return NEXTFOLD; +} + +LJFOLD(HREF any any) +LJFOLD(FLOAD any IRFL_TAB_ARRAY) +LJFOLD(FLOAD any IRFL_TAB_NODE) +LJFOLD(FLOAD any IRFL_TAB_ASIZE) +LJFOLD(FLOAD any IRFL_TAB_HMASK) +LJFOLDF(fload_tab_ah) +{ + TRef tr = lj_opt_cse(J); + return lj_opt_fwd_tptr(J, tref_ref(tr)) ? tr : EMITFOLD; +} + +/* Strings are immutable, so we can safely FOLD/CSE the related FLOAD. */ +LJFOLD(FLOAD KGC IRFL_STR_LEN) +LJFOLDF(fload_str_len_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return INTFOLD((int32_t)ir_kstr(fleft)->len); + return NEXTFOLD; +} + +LJFOLD(FLOAD SNEW IRFL_STR_LEN) +LJFOLDF(fload_str_len_snew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { + PHIBARRIER(fleft); + return fleft->op2; + } + return NEXTFOLD; +} + +/* The C type ID of cdata objects is immutable. */ +LJFOLD(FLOAD KGC IRFL_CDATA_CTYPEID) +LJFOLDF(fload_cdata_typeid_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return INTFOLD((int32_t)ir_kcdata(fleft)->ctypeid); + return NEXTFOLD; +} + +/* Get the contents of immutable cdata objects. */ +LJFOLD(FLOAD KGC IRFL_CDATA_PTR) +LJFOLD(FLOAD KGC IRFL_CDATA_INT) +LJFOLD(FLOAD KGC IRFL_CDATA_INT64) +LJFOLDF(fload_cdata_int64_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { + void *p = cdataptr(ir_kcdata(fleft)); + if (irt_is64(fins->t)) + return INT64FOLD(*(uint64_t *)p); + else + return INTFOLD(*(int32_t *)p); + } + return NEXTFOLD; +} + +LJFOLD(FLOAD CNEW IRFL_CDATA_CTYPEID) +LJFOLD(FLOAD CNEWI IRFL_CDATA_CTYPEID) +LJFOLDF(fload_cdata_typeid_cnew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return fleft->op1; /* No PHI barrier needed. CNEW/CNEWI op1 is const. */ + return NEXTFOLD; +} + +/* Pointer, int and int64 cdata objects are immutable. */ +LJFOLD(FLOAD CNEWI IRFL_CDATA_PTR) +LJFOLD(FLOAD CNEWI IRFL_CDATA_INT) +LJFOLD(FLOAD CNEWI IRFL_CDATA_INT64) +LJFOLDF(fload_cdata_ptr_int64_cnew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return fleft->op2; /* Fold even across PHI to avoid allocations. */ + return NEXTFOLD; +} + +LJFOLD(FLOAD any IRFL_STR_LEN) +LJFOLD(FLOAD any IRFL_CDATA_CTYPEID) +LJFOLD(FLOAD any IRFL_CDATA_PTR) +LJFOLD(FLOAD any IRFL_CDATA_INT) +LJFOLD(FLOAD any IRFL_CDATA_INT64) +LJFOLD(VLOAD any any) /* Vararg loads have no corresponding stores. */ +LJFOLDX(lj_opt_cse) + +/* All other field loads need alias analysis. */ +LJFOLD(FLOAD any any) +LJFOLDX(lj_opt_fwd_fload) + +/* This is for LOOP only. Recording handles SLOADs internally. */ +LJFOLD(SLOAD any any) +LJFOLDF(fwd_sload) +{ + if ((fins->op2 & IRSLOAD_FRAME)) { + TRef tr = lj_opt_cse(J); + return tref_ref(tr) < J->chain[IR_RETF] ? EMITFOLD : tr; + } else { + lua_assert(J->slot[fins->op1] != 0); + return J->slot[fins->op1]; + } +} + +/* Only fold for KKPTR. The pointer _and_ the contents must be const. */ +LJFOLD(XLOAD KKPTR any) +LJFOLDF(xload_kptr) +{ + TRef tr = kfold_xload(J, fins, ir_kptr(fleft)); + return tr ? tr : NEXTFOLD; +} + +LJFOLD(XLOAD any any) +LJFOLDX(lj_opt_fwd_xload) + +/* -- Write barriers ------------------------------------------------------ */ + +/* Write barriers are amenable to CSE, but not across any incremental +** GC steps. +** +** The same logic applies to open upvalue references, because a stack +** may be resized during a GC step (not the current stack, but maybe that +** of a coroutine). +*/ +LJFOLD(TBAR any) +LJFOLD(OBAR any any) +LJFOLD(UREFO any any) +LJFOLDF(barrier_tab) +{ + TRef tr = lj_opt_cse(J); + if (gcstep_barrier(J, tref_ref(tr))) /* CSE across GC step? */ + return EMITFOLD; /* Raw emit. Assumes fins is left intact by CSE. */ + return tr; +} + +LJFOLD(TBAR TNEW) +LJFOLD(TBAR TDUP) +LJFOLDF(barrier_tnew_tdup) +{ + /* New tables are always white and never need a barrier. */ + if (fins->op1 < J->chain[IR_LOOP]) /* Except across a GC step. */ + return NEXTFOLD; + return DROPFOLD; +} + +/* -- Stores and allocations ---------------------------------------------- */ + +/* Stores and allocations cannot be folded or passed on to CSE in general. +** But some stores can be eliminated with dead-store elimination (DSE). +** +** Caveat: *all* stores and allocs must be listed here or they end up at CSE! +*/ + +LJFOLD(ASTORE any any) +LJFOLD(HSTORE any any) +LJFOLDX(lj_opt_dse_ahstore) + +LJFOLD(USTORE any any) +LJFOLDX(lj_opt_dse_ustore) + +LJFOLD(FSTORE any any) +LJFOLDX(lj_opt_dse_fstore) + +LJFOLD(XSTORE any any) +LJFOLDX(lj_opt_dse_xstore) + +LJFOLD(NEWREF any any) /* Treated like a store. */ +LJFOLD(CALLS any any) +LJFOLD(CALLL any any) /* Safeguard fallback. */ +LJFOLD(CALLXS any any) +LJFOLD(XBAR) +LJFOLD(RETF any any) /* Modifies BASE. */ +LJFOLD(TNEW any any) +LJFOLD(TDUP any) +LJFOLD(CNEW any any) +LJFOLD(XSNEW any any) +LJFOLDX(lj_ir_emit) + +/* ------------------------------------------------------------------------ */ + +/* Every entry in the generated hash table is a 32 bit pattern: +** +** xxxxxxxx iiiiiii lllllll rrrrrrrrrr +** +** xxxxxxxx = 8 bit index into fold function table +** iiiiiii = 7 bit folded instruction opcode +** lllllll = 7 bit left instruction opcode +** rrrrrrrrrr = 8 bit right instruction opcode or 10 bits from literal field +*/ + +#include "lj_folddef.h" + +/* ------------------------------------------------------------------------ */ + +/* Fold IR instruction. */ +TRef LJ_FASTCALL lj_opt_fold(jit_State *J) +{ + uint32_t key, any; + IRRef ref; + + if (LJ_UNLIKELY((J->flags & JIT_F_OPT_MASK) != JIT_F_OPT_DEFAULT)) { + lua_assert(((JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE|JIT_F_OPT_DSE) | + JIT_F_OPT_DEFAULT) == JIT_F_OPT_DEFAULT); + /* Folding disabled? Chain to CSE, but not for loads/stores/allocs. */ + if (!(J->flags & JIT_F_OPT_FOLD) && irm_kind(lj_ir_mode[fins->o]) == IRM_N) + return lj_opt_cse(J); + + /* No FOLD, forwarding or CSE? Emit raw IR for loads, except for SLOAD. */ + if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE)) != + (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE) && + irm_kind(lj_ir_mode[fins->o]) == IRM_L && fins->o != IR_SLOAD) + return lj_ir_emit(J); + + /* No FOLD or DSE? Emit raw IR for stores. */ + if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_DSE)) != + (JIT_F_OPT_FOLD|JIT_F_OPT_DSE) && + irm_kind(lj_ir_mode[fins->o]) == IRM_S) + return lj_ir_emit(J); + } + + /* Fold engine start/retry point. */ +retry: + /* Construct key from opcode and operand opcodes (unless literal/none). */ + key = ((uint32_t)fins->o << 17); + if (fins->op1 >= J->cur.nk) { + key += (uint32_t)IR(fins->op1)->o << 10; + *fleft = *IR(fins->op1); + } + if (fins->op2 >= J->cur.nk) { + key += (uint32_t)IR(fins->op2)->o; + *fright = *IR(fins->op2); + } else { + key += (fins->op2 & 0x3ffu); /* Literal mask. Must include IRCONV_*MASK. */ + } + + /* Check for a match in order from most specific to least specific. */ + any = 0; + for (;;) { + uint32_t k = key | (any & 0x1ffff); + uint32_t h = fold_hashkey(k); + uint32_t fh = fold_hash[h]; /* Lookup key in semi-perfect hash table. */ + if ((fh & 0xffffff) == k || (fh = fold_hash[h+1], (fh & 0xffffff) == k)) { + ref = (IRRef)tref_ref(fold_func[fh >> 24](J)); + if (ref != NEXTFOLD) + break; + } + if (any == 0xfffff) /* Exhausted folding. Pass on to CSE. */ + return lj_opt_cse(J); + any = (any | (any >> 10)) ^ 0xffc00; + } + + /* Return value processing, ordered by frequency. */ + if (LJ_LIKELY(ref >= MAX_FOLD)) + return TREF(ref, irt_t(IR(ref)->t)); + if (ref == RETRYFOLD) + goto retry; + if (ref == KINTFOLD) + return lj_ir_kint(J, fins->i); + if (ref == FAILFOLD) + lj_trace_err(J, LJ_TRERR_GFAIL); + lua_assert(ref == DROPFOLD); + return REF_DROP; +} + +/* -- Common-Subexpression Elimination ------------------------------------ */ + +/* CSE an IR instruction. This is very fast due to the skip-list chains. */ +TRef LJ_FASTCALL lj_opt_cse(jit_State *J) +{ + /* Avoid narrow to wide store-to-load forwarding stall */ + IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16); + IROp op = fins->o; + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + /* Limited search for same operands in per-opcode chain. */ + IRRef ref = J->chain[op]; + IRRef lim = fins->op1; + if (fins->op2 > lim) lim = fins->op2; /* Relies on lit < REF_BIAS. */ + while (ref > lim) { + if (IR(ref)->op12 == op12) + return TREF(ref, irt_t(IR(ref)->t)); /* Common subexpression found. */ + ref = IR(ref)->prev; + } + } + /* Otherwise emit IR (inlined for speed). */ + { + IRRef ref = lj_ir_nextins(J); + IRIns *ir = IR(ref); + ir->prev = J->chain[op]; + ir->op12 = op12; + J->chain[op] = (IRRef1)ref; + ir->o = fins->o; + J->guardemit.irt |= fins->t.irt; + return TREF(ref, irt_t((ir->t = fins->t))); + } +} + +/* CSE with explicit search limit. */ +TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim) +{ + IRRef ref = J->chain[fins->o]; + IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16); + while (ref > lim) { + if (IR(ref)->op12 == op12) + return ref; + ref = IR(ref)->prev; + } + return lj_ir_emit(J); +} + +/* ------------------------------------------------------------------------ */ + +#undef IR +#undef fins +#undef fleft +#undef fright +#undef knumleft +#undef knumright +#undef emitir + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_loop.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_loop.c new file mode 100644 index 0000000..fa00115 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_loop.c @@ -0,0 +1,436 @@ +/* +** LOOP: Loop Optimizations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_loop_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_vm.h" + +/* Loop optimization: +** +** Traditional Loop-Invariant Code Motion (LICM) splits the instructions +** of a loop into invariant and variant instructions. The invariant +** instructions are hoisted out of the loop and only the variant +** instructions remain inside the loop body. +** +** Unfortunately LICM is mostly useless for compiling dynamic languages. +** The IR has many guards and most of the subsequent instructions are +** control-dependent on them. The first non-hoistable guard would +** effectively prevent hoisting of all subsequent instructions. +** +** That's why we use a special form of unrolling using copy-substitution, +** combined with redundancy elimination: +** +** The recorded instruction stream is re-emitted to the compiler pipeline +** with substituted operands. The substitution table is filled with the +** refs returned by re-emitting each instruction. This can be done +** on-the-fly, because the IR is in strict SSA form, where every ref is +** defined before its use. +** +** This aproach generates two code sections, separated by the LOOP +** instruction: +** +** 1. The recorded instructions form a kind of pre-roll for the loop. It +** contains a mix of invariant and variant instructions and performs +** exactly one loop iteration (but not necessarily the 1st iteration). +** +** 2. The loop body contains only the variant instructions and performs +** all remaining loop iterations. +** +** On first sight that looks like a waste of space, because the variant +** instructions are present twice. But the key insight is that the +** pre-roll honors the control-dependencies for *both* the pre-roll itself +** *and* the loop body! +** +** It also means one doesn't have to explicitly model control-dependencies +** (which, BTW, wouldn't help LICM much). And it's much easier to +** integrate sparse snapshotting with this approach. +** +** One of the nicest aspects of this approach is that all of the +** optimizations of the compiler pipeline (FOLD, CSE, FWD, etc.) can be +** reused with only minor restrictions (e.g. one should not fold +** instructions across loop-carried dependencies). +** +** But in general all optimizations can be applied which only need to look +** backwards into the generated instruction stream. At any point in time +** during the copy-substitution process this contains both a static loop +** iteration (the pre-roll) and a dynamic one (from the to-be-copied +** instruction up to the end of the partial loop body). +** +** Since control-dependencies are implicitly kept, CSE also applies to all +** kinds of guards. The major advantage is that all invariant guards can +** be hoisted, too. +** +** Load/store forwarding works across loop iterations, too. This is +** important if loop-carried dependencies are kept in upvalues or tables. +** E.g. 'self.idx = self.idx + 1' deep down in some OO-style method may +** become a forwarded loop-recurrence after inlining. +** +** Since the IR is in SSA form, loop-carried dependencies have to be +** modeled with PHI instructions. The potential candidates for PHIs are +** collected on-the-fly during copy-substitution. After eliminating the +** redundant ones, PHI instructions are emitted *below* the loop body. +** +** Note that this departure from traditional SSA form doesn't change the +** semantics of the PHI instructions themselves. But it greatly simplifies +** on-the-fly generation of the IR and the machine code. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- PHI elimination ----------------------------------------------------- */ + +/* Emit or eliminate collected PHIs. */ +static void loop_emit_phi(jit_State *J, IRRef1 *subst, IRRef1 *phi, IRRef nphi, + SnapNo onsnap) +{ + int passx = 0; + IRRef i, j, nslots; + IRRef invar = J->chain[IR_LOOP]; + /* Pass #1: mark redundant and potentially redundant PHIs. */ + for (i = 0, j = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRRef rref = subst[lref]; + if (lref == rref || rref == REF_DROP) { /* Invariants are redundant. */ + irt_clearphi(IR(lref)->t); + } else { + phi[j++] = (IRRef1)lref; + if (!(IR(rref)->op1 == lref || IR(rref)->op2 == lref)) { + /* Quick check for simple recurrences failed, need pass2. */ + irt_setmark(IR(lref)->t); + passx = 1; + } + } + } + nphi = j; + /* Pass #2: traverse variant part and clear marks of non-redundant PHIs. */ + if (passx) { + SnapNo s; + for (i = J->cur.nins-1; i > invar; i--) { + IRIns *ir = IR(i); + if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t); + if (!irref_isk(ir->op1)) { + irt_clearmark(IR(ir->op1)->t); + if (ir->op1 < invar && + ir->o >= IR_CALLN && ir->o <= IR_CARG) { /* ORDER IR */ + ir = IR(ir->op1); + while (ir->o == IR_CARG) { + if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t); + if (irref_isk(ir->op1)) break; + ir = IR(ir->op1); + irt_clearmark(ir->t); + } + } + } + } + for (s = J->cur.nsnap-1; s >= onsnap; s--) { + SnapShot *snap = &J->cur.snap[s]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (!irref_isk(ref)) irt_clearmark(IR(ref)->t); + } + } + } + /* Pass #3: add PHIs for variant slots without a corresponding SLOAD. */ + nslots = J->baseslot+J->maxslot; + for (i = 1; i < nslots; i++) { + IRRef ref = tref_ref(J->slot[i]); + while (!irref_isk(ref) && ref != subst[ref]) { + IRIns *ir = IR(ref); + irt_clearmark(ir->t); /* Unmark potential uses, too. */ + if (irt_isphi(ir->t) || irt_ispri(ir->t)) + break; + irt_setphi(ir->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + ref = subst[ref]; + if (ref > invar) + break; + } + } + /* Pass #4: propagate non-redundant PHIs. */ + while (passx) { + passx = 0; + for (i = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRIns *ir = IR(lref); + if (!irt_ismarked(ir->t)) { /* Propagate only from unmarked PHIs. */ + IRIns *irr = IR(subst[lref]); + if (irt_ismarked(irr->t)) { /* Right ref points to other PHI? */ + irt_clearmark(irr->t); /* Mark that PHI as non-redundant. */ + passx = 1; /* Retry. */ + } + } + } + } + /* Pass #5: emit PHI instructions or eliminate PHIs. */ + for (i = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRIns *ir = IR(lref); + if (!irt_ismarked(ir->t)) { /* Emit PHI if not marked. */ + IRRef rref = subst[lref]; + if (rref > invar) + irt_setphi(IR(rref)->t); + emitir_raw(IRT(IR_PHI, irt_type(ir->t)), lref, rref); + } else { /* Otherwise eliminate PHI. */ + irt_clearmark(ir->t); + irt_clearphi(ir->t); + } + } +} + +/* -- Loop unrolling using copy-substitution ------------------------------ */ + +/* Copy-substitute snapshot. */ +static void loop_subst_snap(jit_State *J, SnapShot *osnap, + SnapEntry *loopmap, IRRef1 *subst) +{ + SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs]; + SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)]; + MSize nmapofs; + MSize on, ln, nn, onent = osnap->nent; + BCReg nslots = osnap->nslots; + SnapShot *snap = &J->cur.snap[J->cur.nsnap]; + if (irt_isguard(J->guardemit)) { /* Guard inbetween? */ + nmapofs = J->cur.nsnapmap; + J->cur.nsnap++; /* Add new snapshot. */ + } else { /* Otherwise overwrite previous snapshot. */ + snap--; + nmapofs = snap->mapofs; + } + J->guardemit.irt = 0; + /* Setup new snapshot. */ + snap->mapofs = (uint16_t)nmapofs; + snap->ref = (IRRef1)J->cur.nins; + snap->nslots = nslots; + snap->topslot = osnap->topslot; + snap->count = 0; + nmap = &J->cur.snapmap[nmapofs]; + /* Substitute snapshot slots. */ + on = ln = nn = 0; + while (on < onent) { + SnapEntry osn = omap[on], lsn = loopmap[ln]; + if (snap_slot(lsn) < snap_slot(osn)) { /* Copy slot from loop map. */ + nmap[nn++] = lsn; + ln++; + } else { /* Copy substituted slot from snapshot map. */ + if (snap_slot(lsn) == snap_slot(osn)) ln++; /* Shadowed loop slot. */ + if (!irref_isk(snap_ref(osn))) + osn = snap_setref(osn, subst[snap_ref(osn)]); + nmap[nn++] = osn; + on++; + } + } + while (snap_slot(loopmap[ln]) < nslots) /* Copy remaining loop slots. */ + nmap[nn++] = loopmap[ln++]; + snap->nent = (uint8_t)nn; + omap += onent; + nmap += nn; + while (omap < nextmap) /* Copy PC + frame links. */ + *nmap++ = *omap++; + J->cur.nsnapmap = (uint16_t)(nmap - J->cur.snapmap); +} + +/* Unroll loop. */ +static void loop_unroll(jit_State *J) +{ + IRRef1 phi[LJ_MAX_PHI]; + uint32_t nphi = 0; + IRRef1 *subst; + SnapNo onsnap; + SnapShot *osnap, *loopsnap; + SnapEntry *loopmap, *psentinel; + IRRef ins, invar; + + /* Use temp buffer for substitution table. + ** Only non-constant refs in [REF_BIAS,invar) are valid indexes. + ** Caveat: don't call into the VM or run the GC or the buffer may be gone. + */ + invar = J->cur.nins; + subst = (IRRef1 *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, + (invar-REF_BIAS)*sizeof(IRRef1)) - REF_BIAS; + subst[REF_BASE] = REF_BASE; + + /* LOOP separates the pre-roll from the loop body. */ + emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0); + + /* Grow snapshot buffer and map for copy-substituted snapshots. + ** Need up to twice the number of snapshots minus #0 and loop snapshot. + ** Need up to twice the number of entries plus fallback substitutions + ** from the loop snapshot entries for each new snapshot. + ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap! + */ + onsnap = J->cur.nsnap; + lj_snap_grow_buf(J, 2*onsnap-2); + lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent); + + /* The loop snapshot is used for fallback substitutions. */ + loopsnap = &J->cur.snap[onsnap-1]; + loopmap = &J->cur.snapmap[loopsnap->mapofs]; + /* The PC of snapshot #0 and the loop snapshot must match. */ + psentinel = &loopmap[loopsnap->nent]; + lua_assert(*psentinel == J->cur.snapmap[J->cur.snap[0].nent]); + *psentinel = SNAP(255, 0, 0); /* Replace PC with temporary sentinel. */ + + /* Start substitution with snapshot #1 (#0 is empty for root traces). */ + osnap = &J->cur.snap[1]; + + /* Copy and substitute all recorded instructions and snapshots. */ + for (ins = REF_FIRST; ins < invar; ins++) { + IRIns *ir; + IRRef op1, op2; + + if (ins >= osnap->ref) /* Instruction belongs to next snapshot? */ + loop_subst_snap(J, osnap++, loopmap, subst); /* Copy-substitute it. */ + + /* Substitute instruction operands. */ + ir = IR(ins); + op1 = ir->op1; + if (!irref_isk(op1)) op1 = subst[op1]; + op2 = ir->op2; + if (!irref_isk(op2)) op2 = subst[op2]; + if (irm_kind(lj_ir_mode[ir->o]) == IRM_N && + op1 == ir->op1 && op2 == ir->op2) { /* Regular invariant ins? */ + subst[ins] = (IRRef1)ins; /* Shortcut. */ + } else { + /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */ + IRType1 t = ir->t; /* Get this first, since emitir may invalidate ir. */ + IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2)); + subst[ins] = (IRRef1)ref; + if (ref != ins) { + IRIns *irr = IR(ref); + if (ref < invar) { /* Loop-carried dependency? */ + /* Potential PHI? */ + if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) { + irt_setphi(irr->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + } + /* Check all loop-carried dependencies for type instability. */ + if (!irt_sametype(t, irr->t)) { + if (irt_isinteger(t) && irt_isinteger(irr->t)) + continue; + else if (irt_isnum(t) && irt_isinteger(irr->t)) /* Fix int->num. */ + ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT)); + else if (irt_isnum(irr->t) && irt_isinteger(t)) /* Fix num->int. */ + ref = tref_ref(emitir(IRTGI(IR_CONV), ref, + IRCONV_INT_NUM|IRCONV_CHECK)); + else + lj_trace_err(J, LJ_TRERR_TYPEINS); + subst[ins] = (IRRef1)ref; + irr = IR(ref); + goto phiconv; + } + } else if (ref != REF_DROP && irr->o == IR_CONV && + ref > invar && irr->op1 < invar) { + /* May need an extra PHI for a CONV. */ + ref = irr->op1; + irr = IR(ref); + phiconv: + if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) { + irt_setphi(irr->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + } + } + } + } + } + if (!irt_isguard(J->guardemit)) /* Drop redundant snapshot. */ + J->cur.nsnapmap = (uint16_t)J->cur.snap[--J->cur.nsnap].mapofs; + lua_assert(J->cur.nsnapmap <= J->sizesnapmap); + *psentinel = J->cur.snapmap[J->cur.snap[0].nent]; /* Restore PC. */ + + loop_emit_phi(J, subst, phi, nphi, onsnap); +} + +/* Undo any partial changes made by the loop optimization. */ +static void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap) +{ + ptrdiff_t i; + SnapShot *snap = &J->cur.snap[nsnap-1]; + SnapEntry *map = J->cur.snapmap; + map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent]; /* Restore PC. */ + J->cur.nsnapmap = (uint16_t)nsnapmap; + J->cur.nsnap = nsnap; + J->guardemit.irt = 0; + lj_ir_rollback(J, ins); + for (i = 0; i < BPROP_SLOTS; i++) { /* Remove backprop. cache entries. */ + BPropEntry *bp = &J->bpropcache[i]; + if (bp->val >= ins) + bp->key = 0; + } + for (ins--; ins >= REF_FIRST; ins--) { /* Remove flags. */ + IRIns *ir = IR(ins); + irt_clearphi(ir->t); + irt_clearmark(ir->t); + } +} + +/* Protected callback for loop optimization. */ +static TValue *cploop_opt(lua_State *L, lua_CFunction dummy, void *ud) +{ + UNUSED(L); UNUSED(dummy); + loop_unroll((jit_State *)ud); + return NULL; +} + +/* Loop optimization. */ +int lj_opt_loop(jit_State *J) +{ + IRRef nins = J->cur.nins; + SnapNo nsnap = J->cur.nsnap; + MSize nsnapmap = J->cur.nsnapmap; + int errcode = lj_vm_cpcall(J->L, NULL, J, cploop_opt); + if (LJ_UNLIKELY(errcode)) { + lua_State *L = J->L; + if (errcode == LUA_ERRRUN && tvisnumber(L->top-1)) { /* Trace error? */ + int32_t e = numberVint(L->top-1); + switch ((TraceError)e) { + case LJ_TRERR_TYPEINS: /* Type instability. */ + case LJ_TRERR_GFAIL: /* Guard would always fail. */ + /* Unrolling via recording fixes many cases, e.g. a flipped boolean. */ + if (--J->instunroll < 0) /* But do not unroll forever. */ + break; + L->top--; /* Remove error object. */ + loop_undo(J, nins, nsnap, nsnapmap); + return 1; /* Loop optimization failed, continue recording. */ + default: + break; + } + } + lj_err_throw(L, errcode); /* Propagate all other errors. */ + } + return 0; /* Loop optimization is ok. */ +} + +#undef IR +#undef emitir +#undef emitir_raw + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_mem.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_mem.c new file mode 100644 index 0000000..c8cdc3e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_mem.c @@ -0,0 +1,917 @@ +/* +** Memory access optimizations. +** AA: Alias Analysis using high-level semantic disambiguation. +** FWD: Load Forwarding (L2L) + Store Forwarding (S2L). +** DSE: Dead-Store Elimination. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_mem_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) +#define fleft (&J->fold.left) +#define fright (&J->fold.right) + +/* +** Caveat #1: return value is not always a TRef -- only use with tref_ref(). +** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold(). +*/ + +/* Return values from alias analysis. */ +typedef enum { + ALIAS_NO, /* The two refs CANNOT alias (exact). */ + ALIAS_MAY, /* The two refs MAY alias (inexact). */ + ALIAS_MUST /* The two refs MUST alias (exact). */ +} AliasRet; + +/* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */ + +/* Simplified escape analysis: check for intervening stores. */ +static AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop) +{ + IRRef ref = (IRRef)(ir - J->cur.ir); /* The ref that might be stored. */ + for (ir++; ir < stop; ir++) + if (ir->op2 == ref && + (ir->o == IR_ASTORE || ir->o == IR_HSTORE || + ir->o == IR_USTORE || ir->o == IR_FSTORE)) + return ALIAS_MAY; /* Reference was stored and might alias. */ + return ALIAS_NO; /* Reference was not stored. */ +} + +/* Alias analysis for two different table references. */ +static AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb) +{ + IRIns *taba = IR(ta), *tabb = IR(tb); + int newa, newb; + lua_assert(ta != tb); + lua_assert(irt_istab(taba->t) && irt_istab(tabb->t)); + /* Disambiguate new allocations. */ + newa = (taba->o == IR_TNEW || taba->o == IR_TDUP); + newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP); + if (newa && newb) + return ALIAS_NO; /* Two different allocations never alias. */ + if (newb) { /* At least one allocation? */ + IRIns *tmp = taba; taba = tabb; tabb = tmp; + } else if (!newa) { + return ALIAS_MAY; /* Anything else: we just don't know. */ + } + return aa_escape(J, taba, tabb); +} + +/* Alias analysis for array and hash access using key-based disambiguation. */ +static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb) +{ + IRRef ka = refa->op2; + IRRef kb = refb->op2; + IRIns *keya, *keyb; + IRRef ta, tb; + if (refa == refb) + return ALIAS_MUST; /* Shortcut for same refs. */ + keya = IR(ka); + if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); } + keyb = IR(kb); + if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); } + ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1; + tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1; + if (ka == kb) { + /* Same key. Check for same table with different ref (NEWREF vs. HREF). */ + if (ta == tb) + return ALIAS_MUST; /* Same key, same table. */ + else + return aa_table(J, ta, tb); /* Same key, possibly different table. */ + } + if (irref_isk(ka) && irref_isk(kb)) + return ALIAS_NO; /* Different constant keys. */ + if (refa->o == IR_AREF) { + /* Disambiguate array references based on index arithmetic. */ + int32_t ofsa = 0, ofsb = 0; + IRRef basea = ka, baseb = kb; + lua_assert(refb->o == IR_AREF); + /* Gather base and offset from t[base] or t[base+-ofs]. */ + if (keya->o == IR_ADD && irref_isk(keya->op2)) { + basea = keya->op1; + ofsa = IR(keya->op2)->i; + if (basea == kb && ofsa != 0) + return ALIAS_NO; /* t[base+-ofs] vs. t[base]. */ + } + if (keyb->o == IR_ADD && irref_isk(keyb->op2)) { + baseb = keyb->op1; + ofsb = IR(keyb->op2)->i; + if (ka == baseb && ofsb != 0) + return ALIAS_NO; /* t[base] vs. t[base+-ofs]. */ + } + if (basea == baseb && ofsa != ofsb) + return ALIAS_NO; /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */ + } else { + /* Disambiguate hash references based on the type of their keys. */ + lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) && + (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF)); + if (!irt_sametype(keya->t, keyb->t)) + return ALIAS_NO; /* Different key types. */ + } + if (ta == tb) + return ALIAS_MAY; /* Same table, cannot disambiguate keys. */ + else + return aa_table(J, ta, tb); /* Try to disambiguate tables. */ +} + +/* Array and hash load forwarding. */ +static TRef fwd_ahload(jit_State *J, IRRef xref) +{ + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[fins->o+IRDELTA_L2S]; + while (ref > xref) { + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + + /* No conflicting store (yet): const-fold loads from allocations. */ + { + IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr; + IRRef tab = ir->op1; + ir = IR(tab); + if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) { + /* A NEWREF with a number key may end up pointing to the array part. + ** But it's referenced from HSTORE and not found in the ASTORE chain. + ** For now simply consider this a conflict without forwarding anything. + */ + if (xr->o == IR_AREF) { + IRRef ref2 = J->chain[IR_NEWREF]; + while (ref2 > tab) { + IRIns *newref = IR(ref2); + if (irt_isnum(IR(newref->op2)->t)) + goto cselim; + ref2 = newref->prev; + } + } + /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF. + ** But the above search for conflicting stores was limited by xref. + ** So continue searching, limited by the TNEW/TDUP. Store forwarding + ** is ok, too. A conflict does NOT limit the search for a matching load. + */ + while (ref > tab) { + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: goto cselim; /* Conflicting store. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + lua_assert(ir->o != IR_TNEW || irt_isnil(fins->t)); + if (irt_ispri(fins->t)) { + return TREF_PRI(irt_type(fins->t)); + } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) || + irt_isstr(fins->t)) { + TValue keyv; + cTValue *tv; + IRIns *key = IR(xr->op2); + if (key->o == IR_KSLOT) key = IR(key->op1); + lj_ir_kvalue(J->L, &keyv, key); + tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv); + lua_assert(itype2irt(tv) == irt_type(fins->t)); + if (irt_isnum(fins->t)) + return lj_ir_knum_u64(J, tv->u64); + else if (LJ_DUALNUM && irt_isint(fins->t)) + return lj_ir_kint(J, intV(tv)); + else + return lj_ir_kstr(J, strV(tv)); + } + /* Othwerwise: don't intern as a constant. */ + } + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + ref = J->chain[fins->o]; + while (ref > lim) { + IRIns *load = IR(ref); + if (load->op1 == xref) + return ref; /* Load forwarding. */ + ref = load->prev; + } + return 0; /* Conflict or no match. */ +} + +/* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */ +static TRef fwd_aload_reassoc(jit_State *J) +{ + IRIns *irx = IR(fins->op1); + IRIns *key = IR(irx->op2); + if (key->o == IR_ADD && irref_isk(key->op2)) { + IRIns *add2 = IR(key->op1); + if (add2->o == IR_ADD && irref_isk(add2->op2) && + IR(key->op2)->i == -IR(add2->op2)->i) { + IRRef ref = J->chain[IR_AREF]; + IRRef lim = add2->op1; + if (irx->op1 > lim) lim = irx->op1; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == irx->op1 && ir->op2 == add2->op1) + return fwd_ahload(J, ref); + ref = ir->prev; + } + } + } + return 0; +} + +/* ALOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J) +{ + IRRef ref; + if ((ref = fwd_ahload(J, fins->op1)) || + (ref = fwd_aload_reassoc(J))) + return ref; + return EMITFOLD; +} + +/* HLOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J) +{ + IRRef ref = fwd_ahload(J, fins->op1); + if (ref) + return ref; + return EMITFOLD; +} + +/* HREFK forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J) +{ + IRRef tab = fleft->op1; + IRRef ref = J->chain[IR_NEWREF]; + while (ref > tab) { + IRIns *newref = IR(ref); + if (tab == newref->op1) { + if (fright->op1 == newref->op2) + return ref; /* Forward from NEWREF. */ + else + goto docse; + } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) { + goto docse; + } + ref = newref->prev; + } + /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */ + if (IR(tab)->o == IR_TDUP) + fins->t.irt &= ~IRT_GUARD; /* Drop HREFK guard. */ +docse: + return CSEFOLD; +} + +/* Check whether HREF of TNEW/TDUP can be folded to niltv. */ +int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J) +{ + IRRef lim = fins->op1; /* Search limit. */ + IRRef ref; + + /* The key for an ASTORE may end up in the hash part after a NEWREF. */ + if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) { + ref = J->chain[IR_ASTORE]; + while (ref > lim) { + if (ref < J->chain[IR_NEWREF]) + return 0; /* Conflict. */ + ref = IR(ref)->prev; + } + } + + /* Search for conflicting stores. */ + ref = J->chain[IR_HSTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO) + return 0; /* Conflict. */ + ref = store->prev; + } + + return 1; /* No conflict. Can fold to niltv. */ +} + +/* Check whether there's no aliasing NEWREF for the left operand. */ +int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim) +{ + IRRef ta = fins->op1; + IRRef ref = J->chain[IR_NEWREF]; + while (ref > lim) { + IRIns *newref = IR(ref); + if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO) + return 0; /* Conflict. */ + ref = newref->prev; + } + return 1; /* No conflict. Can safely FOLD/CSE. */ +} + +/* ASTORE/HSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J) +{ + IRRef xref = fins->op1; /* xREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(xref); + IRRef1 *refp = &J->chain[fins->o]; + IRRef ref = *refp; + while (ref > xref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: /* Store to MAYBE the same location. */ + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: /* Store to the same location. */ + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards (includes conflicting loads). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || ir->o == IR_CALLL) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- ULOAD forwarding ---------------------------------------------------- */ + +/* The current alias analysis for upvalues is very simplistic. It only +** disambiguates between the unique upvalues of the same function. +** This is good enough for now, since most upvalues are read-only. +** +** A more precise analysis would be feasible with the help of the parser: +** generate a unique key for every upvalue, even across all prototypes. +** Lacking a realistic use-case, it's unclear whether this is beneficial. +*/ +static AliasRet aa_uref(IRIns *refa, IRIns *refb) +{ + if (refa->o != refb->o) + return ALIAS_NO; /* Different UREFx type. */ + if (refa->op1 == refb->op1) { /* Same function. */ + if (refa->op2 == refb->op2) + return ALIAS_MUST; /* Same function, same upvalue idx. */ + else + return ALIAS_NO; /* Same function, different upvalue idx. */ + } else { /* Different functions, check disambiguation hash values. */ + if (((refa->op2 ^ refb->op2) & 0xff)) + return ALIAS_NO; /* Upvalues with different hash values cannot alias. */ + else + return ALIAS_MAY; /* No conclusion can be drawn for same hash value. */ + } +} + +/* ULOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J) +{ + IRRef uref = fins->op1; + IRRef lim = REF_BASE; /* Search limit. */ + IRIns *xr = IR(uref); + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[IR_USTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + switch (aa_uref(xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + + ref = J->chain[IR_ULOAD]; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == uref || + (IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o)) + return ref; /* Match for identical or equal UREFx (non-CSEable UREFO). */ + ref = ir->prev; + } + return lj_ir_emit(J); +} + +/* USTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J) +{ + IRRef xref = fins->op1; /* xREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(xref); + IRRef1 *refp = &J->chain[IR_USTORE]; + IRRef ref = *refp; + while (ref > xref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_uref(xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: /* Store to MAYBE the same location. */ + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: /* Store to the same location. */ + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards (includes conflicting loads). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t)) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + if (ref+1 < J->cur.nins && + store[1].o == IR_OBAR && store[1].op1 == xref) { + IRRef1 *bp = &J->chain[IR_OBAR]; + IRIns *obar; + for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp)) + bp = &obar->prev; + /* Remove OBAR, too. */ + *bp = obar->prev; + obar->o = IR_NOP; + obar->t.irt = IRT_NIL; + obar->op1 = obar->op2 = 0; + obar->prev = 0; + } + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- FLOAD forwarding and FSTORE elimination ----------------------------- */ + +/* Alias analysis for field access. +** Field loads are cheap and field stores are rare. +** Simple disambiguation based on field types is good enough. +*/ +static AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb) +{ + if (refa->op2 != refb->op2) + return ALIAS_NO; /* Different fields. */ + if (refa->op1 == refb->op1) + return ALIAS_MUST; /* Same field, same object. */ + else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM) + return aa_table(J, refa->op1, refb->op1); /* Disambiguate tables. */ + else + return ALIAS_MAY; /* Same field, possibly different object. */ +} + +/* Only the loads for mutable fields end up here (see FOLD). */ +TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J) +{ + IRRef oref = fins->op1; /* Object reference. */ + IRRef fid = fins->op2; /* Field ID. */ + IRRef lim = oref; /* Search limit. */ + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[IR_FSTORE]; + while (ref > oref) { + IRIns *store = IR(ref); + switch (aa_fref(J, fins, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + + /* No conflicting store: const-fold field loads from allocations. */ + if (fid == IRFL_TAB_META) { + IRIns *ir = IR(oref); + if (ir->o == IR_TNEW || ir->o == IR_TDUP) + return lj_ir_knull(J, IRT_TAB); + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + return lj_opt_cselim(J, lim); +} + +/* FSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J) +{ + IRRef fref = fins->op1; /* FREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(fref); + IRRef1 *refp = &J->chain[IR_FSTORE]; + IRRef ref = *refp; + while (ref > fref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_fref(J, xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards or conflicting loads. */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2)) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- XLOAD forwarding and XSTORE elimination ----------------------------- */ + +/* Find cdata allocation for a reference (if any). */ +static IRIns *aa_findcnew(jit_State *J, IRIns *ir) +{ + while (ir->o == IR_ADD) { + if (!irref_isk(ir->op1)) { + IRIns *ir1 = aa_findcnew(J, IR(ir->op1)); /* Left-recursion. */ + if (ir1) return ir1; + } + if (irref_isk(ir->op2)) return NULL; + ir = IR(ir->op2); /* Flatten right-recursion. */ + } + return ir->o == IR_CNEW ? ir : NULL; +} + +/* Alias analysis for two cdata allocations. */ +static AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb) +{ + IRIns *cnewa = aa_findcnew(J, refa); + IRIns *cnewb = aa_findcnew(J, refb); + if (cnewa == cnewb) + return ALIAS_MAY; /* Same allocation or neither is an allocation. */ + if (cnewa && cnewb) + return ALIAS_NO; /* Two different allocations never alias. */ + if (cnewb) { cnewa = cnewb; refb = refa; } + return aa_escape(J, cnewa, refb); +} + +/* Alias analysis for XLOAD/XSTORE. */ +static AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb) +{ + ptrdiff_t ofsa = 0, ofsb = 0; + IRIns *refb = IR(xb->op1); + IRIns *basea = refa, *baseb = refb; + if (refa == refb && irt_sametype(xa->t, xb->t)) + return ALIAS_MUST; /* Shortcut for same refs with identical type. */ + /* Offset-based disambiguation. */ + if (refa->o == IR_ADD && irref_isk(refa->op2)) { + IRIns *irk = IR(refa->op2); + basea = IR(refa->op1); + ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + } + if (refb->o == IR_ADD && irref_isk(refb->op2)) { + IRIns *irk = IR(refb->op2); + baseb = IR(refb->op1); + ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + } + /* Treat constified pointers like base vs. base+offset. */ + if (basea->o == IR_KPTR && baseb->o == IR_KPTR) { + ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea); + baseb = basea; + } + /* This implements (very) strict aliasing rules. + ** Different types do NOT alias, except for differences in signedness. + ** Type punning through unions is allowed (but forces a reload). + */ + if (basea == baseb) { + ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t); + if (ofsa == ofsb) { + if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t)) + return ALIAS_MUST; /* Same-sized, same-kind. May need to convert. */ + } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) { + return ALIAS_NO; /* Non-overlapping base+-o1 vs. base+-o2. */ + } + /* NYI: extract, extend or reinterpret bits (int <-> fp). */ + return ALIAS_MAY; /* Overlapping or type punning: force reload. */ + } + if (!irt_sametype(xa->t, xb->t) && + !(irt_typerange(xa->t, IRT_I8, IRT_U64) && + ((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1)) + return ALIAS_NO; + /* NYI: structural disambiguation. */ + return aa_cnew(J, basea, baseb); /* Try to disambiguate allocations. */ +} + +/* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */ +static IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2) +{ + IRRef ref = J->chain[op]; + IRRef lim = op1; + if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; } + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == op1 && ir->op2 == op2) + return ref; + ref = ir->prev; + } + return 0; +} + +/* Reassociate index references. */ +static IRRef reassoc_xref(jit_State *J, IRIns *ir) +{ + ptrdiff_t ofs = 0; + if (ir->o == IR_ADD && irref_isk(ir->op2)) { /* Get constant offset. */ + IRIns *irk = IR(ir->op2); + ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + ir = IR(ir->op1); + } + if (ir->o == IR_ADD) { /* Add of base + index. */ + /* Index ref > base ref for loop-carried dependences. Only check op1. */ + IRIns *ir2, *ir1 = IR(ir->op1); + int32_t shift = 0; + IRRef idxref; + /* Determine index shifts. Don't bother with IR_MUL here. */ + if (ir1->o == IR_BSHL && irref_isk(ir1->op2)) + shift = IR(ir1->op2)->i; + else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2) + shift = 1; + else + ir1 = ir; + ir2 = IR(ir1->op1); + /* A non-reassociated add. Must be a loop-carried dependence. */ + if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2)) + ofs += (ptrdiff_t)IR(ir2->op2)->i << shift; + else + return 0; + idxref = ir2->op1; + /* Try to CSE the reassociated chain. Give up if not found. */ + if (ir1 != ir && + !(idxref = reassoc_trycse(J, ir1->o, idxref, + ir1->o == IR_BSHL ? ir1->op2 : idxref))) + return 0; + if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2))) + return 0; + if (ofs != 0) { + IRRef refk = tref_ref(lj_ir_kintp(J, ofs)); + if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk))) + return 0; + } + return idxref; /* Success, found a reassociated index reference. Phew. */ + } + return 0; /* Failure. */ +} + +/* XLOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J) +{ + IRRef xref = fins->op1; + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef ref; + + if ((fins->op2 & IRXLOAD_READONLY)) + goto cselim; + if ((fins->op2 & IRXLOAD_VOLATILE)) + goto doemit; + + /* Search for conflicting stores. */ + ref = J->chain[IR_XSTORE]; +retry: + if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS]; + if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR]; + while (ref > lim) { + IRIns *store = IR(ref); + switch (aa_xref(J, xr, fins, store)) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: + /* Emit conversion if the loaded type doesn't match the forwarded type. */ + if (!irt_sametype(fins->t, IR(store->op2)->t)) { + IRType st = irt_type(fins->t); + if (st == IRT_I8 || st == IRT_I16) { /* Trunc + sign-extend. */ + st |= IRCONV_SEXT; + } else if (st == IRT_U8 || st == IRT_U16) { /* Trunc + zero-extend. */ + } else if (st == IRT_INT) { + st = irt_type(IR(store->op2)->t); /* Needs dummy CONV.int.*. */ + } else { /* I64/U64 are boxed, U32 is hidden behind a CONV.num.u32. */ + goto store_fwd; + } + fins->ot = IRTI(IR_CONV); + fins->op1 = store->op2; + fins->op2 = (IRT_INT<<5)|st; + return RETRYFOLD; + } + store_fwd: + return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + ref = J->chain[IR_XLOAD]; + while (ref > lim) { + /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */ + if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t)) + return ref; + ref = IR(ref)->prev; + } + + /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */ + if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] && + xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) { + ref = J->chain[IR_XSTORE]; + while (ref > lim) /* Skip stores that have already been checked. */ + ref = IR(ref)->prev; + lim = xref; + xr = IR(xref); + goto retry; /* Retry with the reassociated reference. */ + } +doemit: + return EMITFOLD; +} + +/* XSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J) +{ + IRRef xref = fins->op1; + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRRef1 *refp = &J->chain[IR_XSTORE]; + IRRef ref = *refp; + if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS]; + if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR]; + while (ref > lim) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_xref(J, xr, fins, store)) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards or any XLOADs (no AA performed). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || ir->o == IR_XLOAD) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- Forwarding of lj_tab_len -------------------------------------------- */ + +/* This is rather simplistic right now, but better than nothing. */ +TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J) +{ + IRRef tab = fins->op1; /* Table reference. */ + IRRef lim = tab; /* Search limit. */ + IRRef ref; + + /* Any ASTORE is a conflict and limits the search. */ + if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE]; + + /* Search for conflicting HSTORE with numeric key. */ + ref = J->chain[IR_HSTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + IRIns *href = IR(store->op1); + IRIns *key = IR(href->op2); + if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) { + lim = ref; /* Conflicting store found, limits search for TLEN. */ + break; + } + ref = store->prev; + } + + /* Try to find a matching load. Below the conflicting store, if any. */ + return lj_opt_cselim(J, lim); +} + +/* -- ASTORE/HSTORE previous type analysis -------------------------------- */ + +/* Check whether the previous value for a table store is non-nil. +** This can be derived either from a previous store or from a previous +** load (because all loads from tables perform a type check). +** +** The result of the analysis can be used to avoid the metatable check +** and the guard against HREF returning niltv. Both of these are cheap, +** so let's not spend too much effort on the analysis. +** +** A result of 1 is exact: previous value CANNOT be nil. +** A result of 0 is inexact: previous value MAY be nil. +*/ +int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref) +{ + /* First check stores. */ + IRRef ref = J->chain[loadop+IRDELTA_L2S]; + while (ref > xref) { + IRIns *store = IR(ref); + if (store->op1 == xref) { /* Same xREF. */ + /* A nil store MAY alias, but a non-nil store MUST alias. */ + return !irt_isnil(store->t); + } else if (irt_isnil(store->t)) { /* Must check any nil store. */ + IRRef skref = IR(store->op1)->op2; + IRRef xkref = IR(xref)->op2; + /* Same key type MAY alias. Need ALOAD check due to multiple int types. */ + if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) { + if (skref == xkref || !irref_isk(skref) || !irref_isk(xkref)) + return 0; /* A nil store with same const key or var key MAY alias. */ + /* Different const keys CANNOT alias. */ + } /* Different key types CANNOT alias. */ + } /* Other non-nil stores MAY alias. */ + ref = store->prev; + } + + /* Check loads since nothing could be derived from stores. */ + ref = J->chain[loadop]; + while (ref > xref) { + IRIns *load = IR(ref); + if (load->op1 == xref) { /* Same xREF. */ + /* A nil load MAY alias, but a non-nil load MUST alias. */ + return !irt_isnil(load->t); + } /* Other non-nil loads MAY alias. */ + ref = load->prev; + } + return 0; /* Nothing derived at all, previous value MAY be nil. */ +} + +/* ------------------------------------------------------------------------ */ + +#undef IR +#undef fins +#undef fleft +#undef fright + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_narrow.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_narrow.c new file mode 100644 index 0000000..2cecf65 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_narrow.c @@ -0,0 +1,648 @@ +/* +** NARROW: Narrowing of numbers to integers (double to int32_t). +** STRIPOV: Stripping of overflow checks. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_narrow_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Rationale for narrowing optimizations: +** +** Lua has only a single number type and this is a FP double by default. +** Narrowing doubles to integers does not pay off for the interpreter on a +** current-generation x86/x64 machine. Most FP operations need the same +** amount of execution resources as their integer counterparts, except +** with slightly longer latencies. Longer latencies are a non-issue for +** the interpreter, since they are usually hidden by other overhead. +** +** The total CPU execution bandwidth is the sum of the bandwidth of the FP +** and the integer units, because they execute in parallel. The FP units +** have an equal or higher bandwidth than the integer units. Not using +** them means losing execution bandwidth. Moving work away from them to +** the already quite busy integer units is a losing proposition. +** +** The situation for JIT-compiled code is a bit different: the higher code +** density makes the extra latencies much more visible. Tight loops expose +** the latencies for updating the induction variables. Array indexing +** requires narrowing conversions with high latencies and additional +** guards (to check that the index is really an integer). And many common +** optimizations only work on integers. +** +** One solution would be speculative, eager narrowing of all number loads. +** This causes many problems, like losing -0 or the need to resolve type +** mismatches between traces. It also effectively forces the integer type +** to have overflow-checking semantics. This impedes many basic +** optimizations and requires adding overflow checks to all integer +** arithmetic operations (whereas FP arithmetics can do without). +** +** Always replacing an FP op with an integer op plus an overflow check is +** counter-productive on a current-generation super-scalar CPU. Although +** the overflow check branches are highly predictable, they will clog the +** execution port for the branch unit and tie up reorder buffers. This is +** turning a pure data-flow dependency into a different data-flow +** dependency (with slightly lower latency) *plus* a control dependency. +** In general, you don't want to do this since latencies due to data-flow +** dependencies can be well hidden by out-of-order execution. +** +** A better solution is to keep all numbers as FP values and only narrow +** when it's beneficial to do so. LuaJIT uses predictive narrowing for +** induction variables and demand-driven narrowing for index expressions, +** integer arguments and bit operations. Additionally it can eliminate or +** hoist most of the resulting overflow checks. Regular arithmetic +** computations are never narrowed to integers. +** +** The integer type in the IR has convenient wrap-around semantics and +** ignores overflow. Extra operations have been added for +** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type. +** Apart from reducing overall complexity of the compiler, this also +** nicely solves the problem where you want to apply algebraic +** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can +** use lea instead of an add for integer ADD, but not for ADDOV (lea does +** not affect the flags, but it helps to avoid register moves). +** +** +** All of the above has to be reconsidered for architectures with slow FP +** operations or without a hardware FPU. The dual-number mode of LuaJIT +** addresses this issue. Arithmetic operations are performed on integers +** as far as possible and overflow checks are added as needed. +** +** This implies that narrowing for integer arguments and bit operations +** should also strip overflow checks, e.g. replace ADDOV with ADD. The +** original overflow guards are weak and can be eliminated by DCE, if +** there's no other use. +** +** A slight twist is that it's usually beneficial to use overflow-checked +** integer arithmetics if all inputs are already integers. This is the only +** change that affects the single-number mode, too. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Elimination of narrowing type conversions --------------------------- */ + +/* Narrowing of index expressions and bit operations is demand-driven. The +** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT) +** in all of these cases (e.g. array indexing or string indexing). FOLD +** already takes care of eliminating simple redundant conversions like +** CONV.int.num(CONV.num.int(x)) ==> x. +** +** But the surrounding code is FP-heavy and arithmetic operations are +** performed on FP numbers (for the single-number mode). Consider a common +** example such as 'x=t[i+1]', with 'i' already an integer (due to induction +** variable narrowing). The index expression would be recorded as +** CONV.int.num(ADD(CONV.num.int(i), 1)) +** which is clearly suboptimal. +** +** One can do better by recursively backpropagating the narrowing type +** conversion across FP arithmetic operations. This turns FP ops into +** their corresponding integer counterparts. Depending on the semantics of +** the conversion they also need to check for overflow. Currently only ADD +** and SUB are supported. +** +** The above example can be rewritten as +** ADDOV(CONV.int.num(CONV.num.int(i)), 1) +** and then into ADDOV(i, 1) after folding of the conversions. The original +** FP ops remain in the IR and are eliminated by DCE since all references to +** them are gone. +** +** [In dual-number mode the trace recorder already emits ADDOV etc., but +** this can be further reduced. See below.] +** +** Special care has to be taken to avoid narrowing across an operation +** which is potentially operating on non-integral operands. One obvious +** case is when an expression contains a non-integral constant, but ends +** up as an integer index at runtime (like t[x+1.5] with x=0.5). +** +** Operations with two non-constant operands illustrate a similar problem +** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there, +** unless it can be proven that either operand is integral (e.g. by CSEing +** a previous conversion). As a not-so-obvious corollary this logic also +** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]). +** +** Correctness of the transformation is guaranteed by avoiding to expand +** the tree by adding more conversions than the one we would need to emit +** if not backpropagating. TOBIT employs a more optimistic rule, because +** the conversion has special semantics, designed to make the life of the +** compiler writer easier. ;-) +** +** Using on-the-fly backpropagation of an expression tree doesn't work +** because it's unknown whether the transform is correct until the end. +** This either requires IR rollback and cache invalidation for every +** subtree or a two-pass algorithm. The former didn't work out too well, +** so the code now combines a recursive collector with a stack-based +** emitter. +** +** [A recursive backpropagation algorithm with backtracking, employing +** skip-list lookup and round-robin caching, emitting stack operations +** on-the-fly for a stack-based interpreter -- and all of that in a meager +** kilobyte? Yep, compilers are a great treasure chest. Throw away your +** textbooks and read the codebase of a compiler today!] +** +** There's another optimization opportunity for array indexing: it's +** always accompanied by an array bounds-check. The outermost overflow +** check may be delegated to the ABC operation. This works because ABC is +** an unsigned comparison and wrap-around due to overflow creates negative +** numbers. +** +** But this optimization is only valid for constants that cannot overflow +** an int32_t into the range of valid array indexes [0..2^27+1). A check +** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30 +** wraps to -2^30-1. +** +** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are +** quite common. So the above example finally ends up as ADD(i, 1)! +** +** Later on, the assembler is able to fuse the whole array reference and +** the ADD into the memory operands of loads and other instructions. This +** is why LuaJIT is able to generate very pretty (and fast) machine code +** for array indexing. And that, my dear, concludes another story about +** one of the hidden secrets of LuaJIT ... +*/ + +/* Maximum backpropagation depth and maximum stack size. */ +#define NARROW_MAX_BACKPROP 100 +#define NARROW_MAX_STACK 256 + +/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1] +** The lower 16 bits hold a reference (or 0). The upper 16 bits hold +** the IR opcode + type or one of the following special opcodes: +*/ +enum { + NARROW_REF, /* Push ref. */ + NARROW_CONV, /* Push conversion of ref. */ + NARROW_SEXT, /* Push sign-extension of ref. */ + NARROW_INT /* Push KINT ref. The next code holds an int32_t. */ +}; + +typedef uint32_t NarrowIns; + +#define NARROWINS(op, ref) (((op) << 16) + (ref)) +#define narrow_op(ins) ((IROpT)((ins) >> 16)) +#define narrow_ref(ins) ((IRRef1)(ins)) + +/* Context used for narrowing of type conversions. */ +typedef struct NarrowConv { + jit_State *J; /* JIT compiler state. */ + NarrowIns *sp; /* Current stack pointer. */ + NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */ + int lim; /* Limit on the number of emitted conversions. */ + IRRef mode; /* Conversion mode (IRCONV_*). */ + IRType t; /* Destination type: IRT_INT or IRT_I64. */ + NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */ +} NarrowConv; + +/* Lookup a reference in the backpropagation cache. */ +static BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode) +{ + ptrdiff_t i; + for (i = 0; i < BPROP_SLOTS; i++) { + BPropEntry *bp = &J->bpropcache[i]; + /* Stronger checks are ok, too. */ + if (bp->key == key && bp->mode >= mode && + ((bp->mode ^ mode) & IRCONV_MODEMASK) == 0) + return bp; + } + return NULL; +} + +/* Add an entry to the backpropagation cache. */ +static void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode) +{ + uint32_t slot = J->bpropslot; + BPropEntry *bp = &J->bpropcache[slot]; + J->bpropslot = (slot + 1) & (BPROP_SLOTS-1); + bp->key = key; + bp->val = val; + bp->mode = mode; +} + +/* Backpropagate overflow stripping. */ +static void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth) +{ + jit_State *J = nc->J; + IRIns *ir = IR(ref); + if (ir->o == IR_ADDOV || ir->o == IR_SUBOV || + (ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) { + BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT); + if (bp) { + ref = bp->val; + } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { + narrow_stripov_backprop(nc, ir->op1, depth); + narrow_stripov_backprop(nc, ir->op2, depth); + *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref); + return; + } + } + *nc->sp++ = NARROWINS(NARROW_REF, ref); +} + +/* Backpropagate narrowing conversion. Return number of needed conversions. */ +static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth) +{ + jit_State *J = nc->J; + IRIns *ir = IR(ref); + IRRef cref; + + /* Check the easy cases first. */ + if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) { + if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY) + narrow_stripov_backprop(nc, ir->op1, depth+1); + else + *nc->sp++ = NARROWINS(NARROW_REF, ir->op1); /* Undo conversion. */ + if (nc->t == IRT_I64) + *nc->sp++ = NARROWINS(NARROW_SEXT, 0); /* Sign-extend integer. */ + return 0; + } else if (ir->o == IR_KNUM) { /* Narrow FP constant. */ + lua_Number n = ir_knum(ir)->n; + if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) { + /* Allows a wider range of constants. */ + int64_t k64 = (int64_t)n; + if (n == (lua_Number)k64) { /* Only if const doesn't lose precision. */ + *nc->sp++ = NARROWINS(NARROW_INT, 0); + *nc->sp++ = (NarrowIns)k64; /* But always truncate to 32 bits. */ + return 0; + } + } else { + int32_t k = lj_num2int(n); + /* Only if constant is a small integer. */ + if (checki16(k) && n == (lua_Number)k) { + *nc->sp++ = NARROWINS(NARROW_INT, 0); + *nc->sp++ = (NarrowIns)k; + return 0; + } + } + return 10; /* Never narrow other FP constants (this is rare). */ + } + + /* Try to CSE the conversion. Stronger checks are ok, too. */ + cref = J->chain[fins->o]; + while (cref > ref) { + IRIns *cr = IR(cref); + if (cr->op1 == ref && + (fins->o == IR_TOBIT || + ((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) && + irt_isguard(cr->t) >= irt_isguard(fins->t)))) { + *nc->sp++ = NARROWINS(NARROW_REF, cref); + return 0; /* Already there, no additional conversion needed. */ + } + cref = cr->prev; + } + + /* Backpropagate across ADD/SUB. */ + if (ir->o == IR_ADD || ir->o == IR_SUB) { + /* Try cache lookup first. */ + IRRef mode = nc->mode; + BPropEntry *bp; + /* Inner conversions need a stronger check. */ + if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0) + mode += IRCONV_CHECK-IRCONV_INDEX; + bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode); + if (bp) { + *nc->sp++ = NARROWINS(NARROW_REF, bp->val); + return 0; + } else if (nc->t == IRT_I64) { + /* Try sign-extending from an existing (checked) conversion to int. */ + mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX; + bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode); + if (bp) { + *nc->sp++ = NARROWINS(NARROW_REF, bp->val); + *nc->sp++ = NARROWINS(NARROW_SEXT, 0); + return 0; + } + } + if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { + NarrowIns *savesp = nc->sp; + int count = narrow_conv_backprop(nc, ir->op1, depth); + count += narrow_conv_backprop(nc, ir->op2, depth); + if (count <= nc->lim) { /* Limit total number of conversions. */ + *nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref); + return count; + } + nc->sp = savesp; /* Too many conversions, need to backtrack. */ + } + } + + /* Otherwise add a conversion. */ + *nc->sp++ = NARROWINS(NARROW_CONV, ref); + return 1; +} + +/* Emit the conversions collected during backpropagation. */ +static IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc) +{ + /* The fins fields must be saved now -- emitir() overwrites them. */ + IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0; + IROpT convot = fins->ot; + IRRef1 convop2 = fins->op2; + NarrowIns *next = nc->stack; /* List of instructions from backpropagation. */ + NarrowIns *last = nc->sp; + NarrowIns *sp = nc->stack; /* Recycle the stack to store operands. */ + while (next < last) { /* Simple stack machine to process the ins. list. */ + NarrowIns ref = *next++; + IROpT op = narrow_op(ref); + if (op == NARROW_REF) { + *sp++ = ref; + } else if (op == NARROW_CONV) { + *sp++ = emitir_raw(convot, ref, convop2); /* Raw emit avoids a loop. */ + } else if (op == NARROW_SEXT) { + lua_assert(sp >= nc->stack+1); + sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1], + (IRT_I64<<5)|IRT_INT|IRCONV_SEXT); + } else if (op == NARROW_INT) { + lua_assert(next < last); + *sp++ = nc->t == IRT_I64 ? + lj_ir_kint64(J, (int64_t)(int32_t)*next++) : + lj_ir_kint(J, *next++); + } else { /* Regular IROpT. Pops two operands and pushes one result. */ + IRRef mode = nc->mode; + lua_assert(sp >= nc->stack+2); + sp--; + /* Omit some overflow checks for array indexing. See comments above. */ + if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) { + if (next == last && irref_isk(narrow_ref(sp[0])) && + (uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u) + guardot = 0; + else /* Otherwise cache a stronger check. */ + mode += IRCONV_CHECK-IRCONV_INDEX; + } + sp[-1] = emitir(op+guardot, sp[-1], sp[0]); + /* Add to cache. */ + if (narrow_ref(ref)) + narrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode); + } + } + lua_assert(sp == nc->stack+1); + return nc->stack[0]; +} + +/* Narrow a type conversion of an arithmetic operation. */ +TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J) +{ + if ((J->flags & JIT_F_OPT_NARROW)) { + NarrowConv nc; + nc.J = J; + nc.sp = nc.stack; + nc.maxsp = &nc.stack[NARROW_MAX_STACK-4]; + nc.t = irt_type(fins->t); + if (fins->o == IR_TOBIT) { + nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */ + nc.lim = 2; /* TOBIT can use a more optimistic rule. */ + } else { + nc.mode = fins->op2; + nc.lim = 1; + } + if (narrow_conv_backprop(&nc, fins->op1, 0) <= nc.lim) + return narrow_conv_emit(J, &nc); + } + return NEXTFOLD; +} + +/* -- Narrowing of implicit conversions ----------------------------------- */ + +/* Recursively strip overflow checks. */ +static TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode) +{ + IRRef ref = tref_ref(tr); + IRIns *ir = IR(ref); + int op = ir->o; + if (op >= IR_ADDOV && op <= lastop) { + BPropEntry *bp = narrow_bpc_get(J, ref, mode); + if (bp) { + return TREF(bp->val, irt_t(IR(bp->val)->t)); + } else { + IRRef op1 = ir->op1, op2 = ir->op2; /* The IR may be reallocated. */ + op1 = narrow_stripov(J, op1, lastop, mode); + op2 = narrow_stripov(J, op2, lastop, mode); + tr = emitir(IRT(op - IR_ADDOV + IR_ADD, + ((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2); + narrow_bpc_set(J, ref, tref_ref(tr), mode); + } + } else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) { + tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode); + } + return tr; +} + +/* Narrow array index. */ +TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr) +{ + IRIns *ir; + lua_assert(tref_isnumber(tr)); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX); + /* Omit some overflow checks for array indexing. See comments above. */ + ir = IR(tref_ref(tr)); + if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) && + (uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u) + return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2); + return tr; +} + +/* Narrow conversion to integer operand (overflow undefined). */ +TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr) +{ + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY); + if (!tref_isinteger(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* + ** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. + ** Use IRCONV_TOBIT for the cache entries, since the semantics are the same. + */ + return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT); +} + +/* Narrow conversion to bitop operand (overflow wrapped). */ +TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr) +{ + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J)); + if (!tref_isinteger(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* + ** Wrapped overflow semantics allow stripping of ADDOV and SUBOV. + ** MULOV cannot be stripped due to precision widening. + */ + return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT); +} + +#if LJ_HASFFI +/* Narrow C array index (overflow undefined). */ +TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr) +{ + lua_assert(tref_isnumber(tr)); + if (tref_isnum(tr)) + return emitir(IRT(IR_CONV, IRT_INTP), tr, + (IRT_INTP<<5)|IRT_NUM|IRCONV_TRUNC|IRCONV_ANY); + /* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */ + return narrow_stripov(J, tr, IR_MULOV, + LJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) : + ((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT)); +} +#endif + +/* -- Narrowing of arithmetic operators ----------------------------------- */ + +/* Check whether a number fits into an int32_t (-0 is ok, too). */ +static int numisint(lua_Number n) +{ + return (n == (lua_Number)lj_num2int(n)); +} + +/* Narrowing of arithmetic operations. */ +TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc, + TValue *vb, TValue *vc, IROp op) +{ + if (tref_isstr(rb)) { + rb = emitir(IRTG(IR_STRTO, IRT_NUM), rb, 0); + lj_strscan_num(strV(vb), vb); + } + if (tref_isstr(rc)) { + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + lj_strscan_num(strV(vc), vc); + } + /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */ + if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) && + tref_isinteger(rb) && tref_isinteger(rc) && + numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc), + (int)op - (int)IR_ADD))) + return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc); + if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT); + if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + return emitir(IRTN(op), rb, rc); +} + +/* Narrowing of unary minus operator. */ +TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc) +{ + if (tref_isstr(rc)) { + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + lj_strscan_num(strV(vc), vc); + } + if (tref_isinteger(rc)) { + if ((uint32_t)numberVint(vc) != 0x80000000u) + return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc); + rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + } + return emitir(IRTN(IR_NEG), rc, lj_ir_knum_neg(J)); +} + +/* Narrowing of modulo operator. */ +TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc) +{ + TRef tmp; + if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) && + tref_isinteger(rb) && tref_isinteger(rc) && + (tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) { + emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0)); + return emitir(IRTI(IR_MOD), rb, rc); + } + /* b % c ==> b - floor(b/c)*c */ + rb = lj_ir_tonum(J, rb); + rc = lj_ir_tonum(J, rc); + tmp = emitir(IRTN(IR_DIV), rb, rc); + tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR); + tmp = emitir(IRTN(IR_MUL), tmp, rc); + return emitir(IRTN(IR_SUB), rb, tmp); +} + +/* Narrowing of power operator or math.pow. */ +TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc) +{ + if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* Narrowing must be unconditional to preserve (-x)^i semantics. */ + if (tvisint(vc) || numisint(numV(vc))) { + int checkrange = 0; + /* Split pow is faster for bigger exponents. But do this only for (+k)^i. */ + if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) { + int32_t k = numberVint(vc); + if (!(k >= -65536 && k <= 65536)) goto split_pow; + checkrange = 1; + } + if (!tref_isinteger(rc)) { + if (tref_isstr(rc)) + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + /* Guarded conversion to integer! */ + rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK); + } + if (checkrange && !tref_isk(rc)) { /* Range guard: -65536 <= i <= 65536 */ + TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536)); + emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536)); + } + return emitir(IRTN(IR_POW), rb, rc); + } +split_pow: + /* FOLD covers most cases, but some are easier to do here. */ + if (tref_isk(rb) && tvispone(ir_knum(IR(tref_ref(rb))))) + return rb; /* 1 ^ x ==> 1 */ + rc = lj_ir_tonum(J, rc); + if (tref_isk(rc) && ir_knum(IR(tref_ref(rc)))->n == 0.5) + return emitir(IRTN(IR_FPMATH), rb, IRFPM_SQRT); /* x ^ 0.5 ==> sqrt(x) */ + /* Split up b^c into exp2(c*log2(b)). Assembler may rejoin later. */ + rb = emitir(IRTN(IR_FPMATH), rb, IRFPM_LOG2); + rc = emitir(IRTN(IR_MUL), rb, rc); + return emitir(IRTN(IR_FPMATH), rc, IRFPM_EXP2); +} + +/* -- Predictive narrowing of induction variables ------------------------- */ + +/* Narrow a single runtime value. */ +static int narrow_forl(jit_State *J, cTValue *o) +{ + if (tvisint(o)) return 1; + if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o)); + return 0; +} + +/* Narrow the FORL index type by looking at the runtime values. */ +IRType lj_opt_narrow_forl(jit_State *J, cTValue *tv) +{ + lua_assert(tvisnumber(&tv[FORL_IDX]) && + tvisnumber(&tv[FORL_STOP]) && + tvisnumber(&tv[FORL_STEP])); + /* Narrow only if the runtime values of start/stop/step are all integers. */ + if (narrow_forl(J, &tv[FORL_IDX]) && + narrow_forl(J, &tv[FORL_STOP]) && + narrow_forl(J, &tv[FORL_STEP])) { + /* And if the loop index can't possibly overflow. */ + lua_Number step = numberVnum(&tv[FORL_STEP]); + lua_Number sum = numberVnum(&tv[FORL_STOP]) + step; + if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0)) + return IRT_INT; + } + return IRT_NUM; +} + +#undef IR +#undef fins +#undef emitir +#undef emitir_raw + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_sink.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_sink.c new file mode 100644 index 0000000..3a33346 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_sink.c @@ -0,0 +1,245 @@ +/* +** SINK: Allocation Sinking and Store Sinking. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_sink_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_target.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Check whether the store ref points to an eligible allocation. */ +static IRIns *sink_checkalloc(jit_State *J, IRIns *irs) +{ + IRIns *ir = IR(irs->op1); + if (!irref_isk(ir->op2)) + return NULL; /* Non-constant key. */ + if (ir->o == IR_HREFK || ir->o == IR_AREF) + ir = IR(ir->op1); + else if (!(ir->o == IR_HREF || ir->o == IR_NEWREF || + ir->o == IR_FREF || ir->o == IR_ADD)) + return NULL; /* Unhandled reference type (for XSTORE). */ + ir = IR(ir->op1); + if (!(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW)) + return NULL; /* Not an allocation. */ + return ir; /* Return allocation. */ +} + +/* Recursively check whether a value depends on a PHI. */ +static int sink_phidep(jit_State *J, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isphi(ir->t)) return 1; + if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1; + if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1; + return 0; +} + +/* Check whether a value is a sinkable PHI or loop-invariant. */ +static int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref) +{ + if (ref >= REF_FIRST) { + IRIns *ir = IR(ref); + if (irt_isphi(ir->t) || (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && + irt_isphi(IR(ir->op1)->t))) { + ira->prev++; + return 1; /* Sinkable PHI. */ + } + /* Otherwise the value must be loop-invariant. */ + return ref < J->loopref && !sink_phidep(J, ref); + } + return 1; /* Constant (non-PHI). */ +} + +/* Mark non-sinkable allocations using single-pass backward propagation. +** +** Roots for the marking process are: +** - Some PHIs or snapshots (see below). +** - Non-PHI, non-constant values stored to PHI allocations. +** - All guards. +** - Any remaining loads not eliminated by store-to-load forwarding. +** - Stores with non-constant keys. +** - All stored values. +*/ +static void sink_mark_ins(jit_State *J) +{ + IRIns *ir, *irlast = IR(J->cur.nins-1); + for (ir = irlast ; ; ir--) { + switch (ir->o) { + case IR_BASE: + return; /* Finished. */ + case IR_CALLL: /* IRCALL_lj_tab_len */ + case IR_ALOAD: case IR_HLOAD: case IR_XLOAD: case IR_TBAR: + irt_setmark(IR(ir->op1)->t); /* Mark ref for remaining loads. */ + break; + case IR_FLOAD: + if (irt_ismarked(ir->t) || ir->op2 == IRFL_TAB_META) + irt_setmark(IR(ir->op1)->t); /* Mark table for remaining loads. */ + break; + case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: { + IRIns *ira = sink_checkalloc(J, ir); + if (!ira || (irt_isphi(ira->t) && !sink_checkphi(J, ira, ir->op2))) + irt_setmark(IR(ir->op1)->t); /* Mark ineligible ref. */ + irt_setmark(IR(ir->op2)->t); /* Mark stored value. */ + break; + } +#if LJ_HASFFI + case IR_CNEWI: + if (irt_isphi(ir->t) && + (!sink_checkphi(J, ir, ir->op2) || + (LJ_32 && ir+1 < irlast && (ir+1)->o == IR_HIOP && + !sink_checkphi(J, ir, (ir+1)->op2)))) + irt_setmark(ir->t); /* Mark ineligible allocation. */ + /* fallthrough */ +#endif + case IR_USTORE: + irt_setmark(IR(ir->op2)->t); /* Mark stored value. */ + break; +#if LJ_HASFFI + case IR_CALLXS: +#endif + case IR_CALLS: + irt_setmark(IR(ir->op1)->t); /* Mark (potentially) stored values. */ + break; + case IR_PHI: { + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + irl->prev = irr->prev = 0; /* Clear PHI value counts. */ + if (irl->o == irr->o && + (irl->o == IR_TNEW || irl->o == IR_TDUP || + (LJ_HASFFI && (irl->o == IR_CNEW || irl->o == IR_CNEWI)))) + break; + irt_setmark(irl->t); + irt_setmark(irr->t); + break; + } + default: + if (irt_ismarked(ir->t) || irt_isguard(ir->t)) { /* Propagate mark. */ + if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t); + if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t); + } + break; + } + } +} + +/* Mark all instructions referenced by a snapshot. */ +static void sink_mark_snap(jit_State *J, SnapShot *snap) +{ + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (!irref_isk(ref)) + irt_setmark(IR(ref)->t); + } +} + +/* Iteratively remark PHI refs with differing marks or PHI value counts. */ +static void sink_remark_phi(jit_State *J) +{ + IRIns *ir; + int remark; + do { + remark = 0; + for (ir = IR(J->cur.nins-1); ir->o == IR_PHI; ir--) { + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + if (((irl->t.irt ^ irr->t.irt) & IRT_MARK)) + remark = 1; + else if (irl->prev == irr->prev) + continue; + irt_setmark(IR(ir->op1)->t); + irt_setmark(IR(ir->op2)->t); + } + } while (remark); +} + +/* Sweep instructions and tag sunken allocations and stores. */ +static void sink_sweep_ins(jit_State *J) +{ + IRIns *ir, *irfirst = IR(J->cur.nk); + for (ir = IR(J->cur.nins-1) ; ir >= irfirst; ir--) { + switch (ir->o) { + case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: { + IRIns *ira = sink_checkalloc(J, ir); + if (ira && !irt_ismarked(ira->t)) { + int delta = (int)(ir - ira); + ir->prev = REGSP(RID_SINK, delta > 255 ? 255 : delta); + } else { + ir->prev = REGSP_INIT; + } + break; + } + case IR_NEWREF: + if (!irt_ismarked(IR(ir->op1)->t)) { + ir->prev = REGSP(RID_SINK, 0); + } else { + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + } + break; +#if LJ_HASFFI + case IR_CNEW: case IR_CNEWI: +#endif + case IR_TNEW: case IR_TDUP: + if (!irt_ismarked(ir->t)) { + ir->t.irt &= ~IRT_GUARD; + ir->prev = REGSP(RID_SINK, 0); + J->cur.sinktags = 1; /* Signal present SINK tags to assembler. */ + } else { + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + } + break; + case IR_PHI: { + IRIns *ira = IR(ir->op2); + if (!irt_ismarked(ira->t) && + (ira->o == IR_TNEW || ira->o == IR_TDUP || + (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI)))) { + ir->prev = REGSP(RID_SINK, 0); + } else { + ir->prev = REGSP_INIT; + } + break; + } + default: + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + break; + } + } +} + +/* Allocation sinking and store sinking. +** +** 1. Mark all non-sinkable allocations. +** 2. Then sink all remaining allocations and the related stores. +*/ +void lj_opt_sink(jit_State *J) +{ + const uint32_t need = (JIT_F_OPT_SINK|JIT_F_OPT_FWD| + JIT_F_OPT_DCE|JIT_F_OPT_CSE|JIT_F_OPT_FOLD); + if ((J->flags & need) == need && + (J->chain[IR_TNEW] || J->chain[IR_TDUP] || + (LJ_HASFFI && (J->chain[IR_CNEW] || J->chain[IR_CNEWI])))) { + if (!J->loopref) + sink_mark_snap(J, &J->cur.snap[J->cur.nsnap-1]); + sink_mark_ins(J); + if (J->loopref) + sink_remark_phi(J); + sink_sweep_ins(J); + } +} + +#undef IR + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_split.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_split.c new file mode 100644 index 0000000..99d1058 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_opt_split.c @@ -0,0 +1,731 @@ +/* +** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_split_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT && (LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_vm.h" + +/* SPLIT pass: +** +** This pass splits up 64 bit IR instructions into multiple 32 bit IR +** instructions. It's only active for soft-float targets or for 32 bit CPUs +** which lack native 64 bit integer operations (the FFI is currently the +** only emitter for 64 bit integer instructions). +** +** Splitting the IR in a separate pass keeps each 32 bit IR assembler +** backend simple. Only a small amount of extra functionality needs to be +** implemented. This is much easier than adding support for allocating +** register pairs to each backend (believe me, I tried). A few simple, but +** important optimizations can be performed by the SPLIT pass, which would +** be tedious to do in the backend. +** +** The basic idea is to replace each 64 bit IR instruction with its 32 bit +** equivalent plus an extra HIOP instruction. The splitted IR is not passed +** through FOLD or any other optimizations, so each HIOP is guaranteed to +** immediately follow it's counterpart. The actual functionality of HIOP is +** inferred from the previous instruction. +** +** The operands of HIOP hold the hiword input references. The output of HIOP +** is the hiword output reference, which is also used to hold the hiword +** register or spill slot information. The register allocator treats this +** instruction independently of any other instruction, which improves code +** quality compared to using fixed register pairs. +** +** It's easier to split up some instructions into two regular 32 bit +** instructions. E.g. XLOAD is split up into two XLOADs with two different +** addresses. Obviously 64 bit constants need to be split up into two 32 bit +** constants, too. Some hiword instructions can be entirely omitted, e.g. +** when zero-extending a 32 bit value to 64 bits. 64 bit arguments for calls +** are split up into two 32 bit arguments each. +** +** On soft-float targets, floating-point instructions are directly converted +** to soft-float calls by the SPLIT pass (except for comparisons and MIN/MAX). +** HIOP for number results has the type IRT_SOFTFP ("sfp" in -jdump). +** +** Here's the IR and x64 machine code for 'x.b = x.a + 1' for a struct with +** two int64_t fields: +** +** 0100 p32 ADD base +8 +** 0101 i64 XLOAD 0100 +** 0102 i64 ADD 0101 +1 +** 0103 p32 ADD base +16 +** 0104 i64 XSTORE 0103 0102 +** +** mov rax, [esi+0x8] +** add rax, +0x01 +** mov [esi+0x10], rax +** +** Here's the transformed IR and the x86 machine code after the SPLIT pass: +** +** 0100 p32 ADD base +8 +** 0101 int XLOAD 0100 +** 0102 p32 ADD base +12 +** 0103 int XLOAD 0102 +** 0104 int ADD 0101 +1 +** 0105 int HIOP 0103 +0 +** 0106 p32 ADD base +16 +** 0107 int XSTORE 0106 0104 +** 0108 int HIOP 0106 0105 +** +** mov eax, [esi+0x8] +** mov ecx, [esi+0xc] +** add eax, +0x01 +** adc ecx, +0x00 +** mov [esi+0x10], eax +** mov [esi+0x14], ecx +** +** You may notice the reassociated hiword address computation, which is +** later fused into the mov operands by the assembler. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Directly emit the transformed IR without updating chains etc. */ +static IRRef split_emit(jit_State *J, uint16_t ot, IRRef1 op1, IRRef1 op2) +{ + IRRef nref = lj_ir_nextins(J); + IRIns *ir = IR(nref); + ir->ot = ot; + ir->op1 = op1; + ir->op2 = op2; + return nref; +} + +#if LJ_SOFTFP +/* Emit a (checked) number to integer conversion. */ +static IRRef split_num2int(jit_State *J, IRRef lo, IRRef hi, int check) +{ + IRRef tmp, res; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), lo, hi); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hi, lo); +#endif + res = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_softfp_d2i); + if (check) { + tmp = split_emit(J, IRTI(IR_CALLN), res, IRCALL_softfp_i2d); + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); + split_emit(J, IRTGI(IR_EQ), tmp, lo); + split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), tmp+1, hi); + } + return res; +} + +/* Emit a CALLN with one split 64 bit argument. */ +static IRRef split_call_l(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); +} + +/* Emit a CALLN with one split 64 bit argument and a 32 bit argument. */ +static IRRef split_call_li(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1, op2 = ir->op2; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); +} +#endif + +/* Emit a CALLN with two split 64 bit arguments. */ +static IRRef split_call_ll(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1, op2 = ir->op2; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); +#endif + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, + IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT), + tmp, tmp); +} + +/* Get a pointer to the other 32 bit word (LE: hiword, BE: loword). */ +static IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref) +{ + IRRef nref = oir[ref].prev; + IRIns *ir = IR(nref); + int32_t ofs = 4; + if (ir->o == IR_KPTR) + return lj_ir_kptr(J, (char *)ir_kptr(ir) + ofs); + if (ir->o == IR_ADD && irref_isk(ir->op2) && !irt_isphi(oir[ref].t)) { + /* Reassociate address. */ + ofs += IR(ir->op2)->i; + nref = ir->op1; + if (ofs == 0) return nref; + } + return split_emit(J, IRTI(IR_ADD), nref, lj_ir_kint(J, ofs)); +} + +/* Substitute references of a snapshot. */ +static void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir) +{ + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRIns *ir = &oir[snap_ref(sn)]; + if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn)))) + map[n] = ((sn & 0xffff0000) | ir->prev); + } +} + +/* Transform the old IR to the new IR. */ +static void split_ir(jit_State *J) +{ + IRRef nins = J->cur.nins, nk = J->cur.nk; + MSize irlen = nins - nk; + MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1)); + IRIns *oir = (IRIns *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, need); + IRRef1 *hisubst; + IRRef ref, snref; + SnapShot *snap; + + /* Copy old IR to buffer. */ + memcpy(oir, IR(nk), irlen*sizeof(IRIns)); + /* Bias hiword substitution table and old IR. Loword kept in field prev. */ + hisubst = (IRRef1 *)&oir[irlen] - nk; + oir -= nk; + + /* Remove all IR instructions, but retain IR constants. */ + J->cur.nins = REF_FIRST; + J->loopref = 0; + + /* Process constants and fixed references. */ + for (ref = nk; ref <= REF_BASE; ref++) { + IRIns *ir = &oir[ref]; + if ((LJ_SOFTFP && ir->o == IR_KNUM) || ir->o == IR_KINT64) { + /* Split up 64 bit constant. */ + TValue tv = *ir_k64(ir); + ir->prev = lj_ir_kint(J, (int32_t)tv.u32.lo); + hisubst[ref] = lj_ir_kint(J, (int32_t)tv.u32.hi); + } else { + ir->prev = ref; /* Identity substitution for loword. */ + hisubst[ref] = 0; + } + } + + /* Process old IR instructions. */ + snap = J->cur.snap; + snref = snap->ref; + for (ref = REF_FIRST; ref < nins; ref++) { + IRIns *ir = &oir[ref]; + IRRef nref = lj_ir_nextins(J); + IRIns *nir = IR(nref); + IRRef hi = 0; + + if (ref >= snref) { + snap->ref = nref; + split_subst_snap(J, snap++, oir); + snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0; + } + + /* Copy-substitute old instruction to new instruction. */ + nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev; + nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev; + ir->prev = nref; /* Loword substitution. */ + nir->o = ir->o; + nir->t.irt = ir->t.irt & ~(IRT_MARK|IRT_ISPHI); + hisubst[ref] = 0; + + /* Split 64 bit instructions. */ +#if LJ_SOFTFP + if (irt_isnum(ir->t)) { + nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */ + /* Note: hi ref = lo ref + 1! Required for SNAP_SOFTFPNUM logic. */ + switch (ir->o) { + case IR_ADD: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_add); + break; + case IR_SUB: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_sub); + break; + case IR_MUL: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_mul); + break; + case IR_DIV: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div); + break; + case IR_POW: + hi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi); + break; + case IR_FPMATH: + /* Try to rejoin pow from EXP2, MUL and LOG2. */ + if (nir->op2 == IRFPM_EXP2 && nir->op1 > J->loopref) { + IRIns *irp = IR(nir->op1); + if (irp->o == IR_CALLN && irp->op2 == IRCALL_softfp_mul) { + IRIns *irm4 = IR(irp->op1); + IRIns *irm3 = IR(irm4->op1); + IRIns *irm12 = IR(irm3->op1); + IRIns *irl1 = IR(irm12->op1); + if (irm12->op1 > J->loopref && irl1->o == IR_CALLN && + irl1->op2 == IRCALL_lj_vm_log2) { + IRRef tmp = irl1->op1; /* Recycle first two args from LOG2. */ + IRRef arg3 = irm3->op2, arg4 = irm4->op2; + J->cur.nins--; + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg3); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg4); + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_pow); + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); + break; + } + } + } + hi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2); + break; + case IR_ATAN2: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_atan2); + break; + case IR_LDEXP: + hi = split_call_li(J, hisubst, oir, ir, IRCALL_ldexp); + break; + case IR_NEG: case IR_ABS: + nir->o = IR_CONV; /* Pass through loword. */ + nir->op2 = (IRT_INT << 5) | IRT_INT; + hi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + case IR_SLOAD: + if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from int to number. */ + nir->op2 &= ~IRSLOAD_CONVERT; + ir->prev = nref = split_emit(J, IRTI(IR_CALLN), nref, + IRCALL_softfp_i2d); + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + } + /* fallthrough */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + case IR_STRTO: + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + case IR_XLOAD: { + IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */ + J->cur.nins--; + hi = split_ptr(J, oir, ir->op1); /* Insert the hiref ADD. */ + nref = lj_ir_nextins(J); + nir = IR(nref); + *nir = inslo; /* Re-emit lo XLOAD immediately before hi XLOAD. */ + hi = split_emit(J, IRT(IR_XLOAD, IRT_SOFTFP), hi, ir->op2); +#if LJ_LE + ir->prev = nref; +#else + ir->prev = hi; hi = nref; +#endif + break; + } + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_XSTORE: + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nir->op1, hisubst[ir->op2]); + break; + case IR_CONV: { /* Conversion to number. Others handled below. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + UNUSED(st); +#if LJ_32 && LJ_HASFFI + if (st == IRT_I64 || st == IRT_U64) { + hi = split_call_l(J, hisubst, oir, ir, + st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d); + break; + } +#endif + lua_assert(st == IRT_INT || + (LJ_32 && LJ_HASFFI && (st == IRT_U32 || st == IRT_FLOAT))); + nir->o = IR_CALLN; +#if LJ_32 && LJ_HASFFI + nir->op2 = st == IRT_INT ? IRCALL_softfp_i2d : + st == IRT_FLOAT ? IRCALL_softfp_f2d : + IRCALL_softfp_ui2d; +#else + nir->op2 = IRCALL_softfp_i2d; +#endif + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + } + case IR_CALLN: + case IR_CALLL: + case IR_CALLS: + case IR_CALLXS: + goto split_call; + case IR_PHI: + if (nir->op1 == nir->op2) + J->cur.nins--; /* Drop useless PHIs. */ + if (hisubst[ir->op1] != hisubst[ir->op2]) + split_emit(J, IRT(IR_PHI, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + case IR_HIOP: + J->cur.nins--; /* Drop joining HIOP. */ + ir->prev = nir->op1; + hi = nir->op2; + break; + default: + lua_assert(ir->o <= IR_NE || ir->o == IR_MIN || ir->o == IR_MAX); + hi = split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + } + } else +#endif +#if LJ_32 && LJ_HASFFI + if (irt_isint64(ir->t)) { + IRRef hiref = hisubst[ir->op1]; + nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */ + switch (ir->o) { + case IR_ADD: + case IR_SUB: + /* Use plain op for hiword if loword cannot produce a carry/borrow. */ + if (irref_isk(nir->op2) && IR(nir->op2)->i == 0) { + ir->prev = nir->op1; /* Pass through loword. */ + nir->op1 = hiref; nir->op2 = hisubst[ir->op2]; + hi = nref; + break; + } + /* fallthrough */ + case IR_NEG: + hi = split_emit(J, IRTI(IR_HIOP), hiref, hisubst[ir->op2]); + break; + case IR_MUL: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_lj_carith_mul64); + break; + case IR_DIV: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 : + IRCALL_lj_carith_divu64); + break; + case IR_MOD: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 : + IRCALL_lj_carith_modu64); + break; + case IR_POW: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 : + IRCALL_lj_carith_powu64); + break; + case IR_FLOAD: + lua_assert(ir->op2 == IRFL_CDATA_INT64); + hi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4); +#if LJ_BE + ir->prev = hi; hi = nref; +#endif + break; + case IR_XLOAD: + hi = split_emit(J, IRTI(IR_XLOAD), split_ptr(J, oir, ir->op1), ir->op2); +#if LJ_BE + ir->prev = hi; hi = nref; +#endif + break; + case IR_XSTORE: + split_emit(J, IRTI(IR_HIOP), nir->op1, hisubst[ir->op2]); + break; + case IR_CONV: { /* Conversion to 64 bit integer. Others handled below. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if LJ_SOFTFP + if (st == IRT_NUM) { /* NUM to 64 bit int conv. */ + hi = split_call_l(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul); + } else if (st == IRT_FLOAT) { /* FLOAT to 64 bit int conv. */ + nir->o = IR_CALLN; + nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul; + hi = split_emit(J, IRTI(IR_HIOP), nref, nref); + } +#else + if (st == IRT_NUM || st == IRT_FLOAT) { /* FP to 64 bit int conv. */ + hi = split_emit(J, IRTI(IR_HIOP), nir->op1, nref); + } +#endif + else if (st == IRT_I64 || st == IRT_U64) { /* 64/64 bit cast. */ + /* Drop cast, since assembler doesn't care. */ + goto fwdlo; + } else if ((ir->op2 & IRCONV_SEXT)) { /* Sign-extend to 64 bit. */ + IRRef k31 = lj_ir_kint(J, 31); + nir = IR(nref); /* May have been reallocated. */ + ir->prev = nir->op1; /* Pass through loword. */ + nir->o = IR_BSAR; /* hi = bsar(lo, 31). */ + nir->op2 = k31; + hi = nref; + } else { /* Zero-extend to 64 bit. */ + hi = lj_ir_kint(J, 0); + goto fwdlo; + } + break; + } + case IR_CALLXS: + goto split_call; + case IR_PHI: { + IRRef hiref2; + if ((irref_isk(nir->op1) && irref_isk(nir->op2)) || + nir->op1 == nir->op2) + J->cur.nins--; /* Drop useless PHIs. */ + hiref2 = hisubst[ir->op2]; + if (!((irref_isk(hiref) && irref_isk(hiref2)) || hiref == hiref2)) + split_emit(J, IRTI(IR_PHI), hiref, hiref2); + break; + } + case IR_HIOP: + J->cur.nins--; /* Drop joining HIOP. */ + ir->prev = nir->op1; + hi = nir->op2; + break; + default: + lua_assert(ir->o <= IR_NE); /* Comparisons. */ + split_emit(J, IRTGI(IR_HIOP), hiref, hisubst[ir->op2]); + break; + } + } else +#endif +#if LJ_SOFTFP + if (ir->o == IR_SLOAD) { + if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from number to int. */ + nir->op2 &= ~IRSLOAD_CONVERT; + if (!(nir->op2 & IRSLOAD_TYPECHECK)) + nir->t.irt = IRT_INT; /* Drop guard. */ + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + ir->prev = split_num2int(J, nref, nref+1, irt_isguard(ir->t)); + } + } else if (ir->o == IR_TOBIT) { + IRRef tmp, op1 = ir->op1; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + ir->prev = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_lj_vm_tobit); + } else if (ir->o == IR_TOSTR) { + if (hisubst[ir->op1]) { + if (irref_isk(ir->op1)) + nir->op1 = ir->op1; + else + split_emit(J, IRT(IR_HIOP, IRT_NIL), hisubst[ir->op1], nref); + } + } else if (ir->o == IR_HREF || ir->o == IR_NEWREF) { + if (irref_isk(ir->op2) && hisubst[ir->op2]) + nir->op2 = ir->op2; + } else +#endif + if (ir->o == IR_CONV) { /* See above, too. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if LJ_32 && LJ_HASFFI + if (st == IRT_I64 || st == IRT_U64) { /* Conversion from 64 bit int. */ +#if LJ_SOFTFP + if (irt_isfloat(ir->t)) { + split_call_l(J, hisubst, oir, ir, + st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f); + J->cur.nins--; /* Drop unused HIOP. */ + } +#else + if (irt_isfp(ir->t)) { /* 64 bit integer to FP conversion. */ + ir->prev = split_emit(J, IRT(IR_HIOP, irt_type(ir->t)), + hisubst[ir->op1], nref); + } +#endif + else { /* Truncate to lower 32 bits. */ + fwdlo: + ir->prev = nir->op1; /* Forward loword. */ + /* Replace with NOP to avoid messing up the snapshot logic. */ + nir->ot = IRT(IR_NOP, IRT_NIL); + nir->op1 = nir->op2 = 0; + } + } +#endif +#if LJ_SOFTFP && LJ_32 && LJ_HASFFI + else if (irt_isfloat(ir->t)) { + if (st == IRT_NUM) { + split_call_l(J, hisubst, oir, ir, IRCALL_softfp_d2f); + J->cur.nins--; /* Drop unused HIOP. */ + } else { + nir->o = IR_CALLN; + nir->op2 = st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f; + } + } else if (st == IRT_FLOAT) { + nir->o = IR_CALLN; + nir->op2 = irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui; + } else +#endif +#if LJ_SOFTFP + if (st == IRT_NUM || (LJ_32 && LJ_HASFFI && st == IRT_FLOAT)) { + if (irt_isguard(ir->t)) { + lua_assert(st == IRT_NUM && irt_isint(ir->t)); + J->cur.nins--; + ir->prev = split_num2int(J, nir->op1, hisubst[ir->op1], 1); + } else { + split_call_l(J, hisubst, oir, ir, +#if LJ_32 && LJ_HASFFI + st == IRT_NUM ? + (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) : + (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui) +#else + IRCALL_softfp_d2i +#endif + ); + J->cur.nins--; /* Drop unused HIOP. */ + } + } +#endif + } else if (ir->o == IR_CALLXS) { + IRRef hiref; + split_call: + hiref = hisubst[ir->op1]; + if (hiref) { + IROpT ot = nir->ot; + IRRef op2 = nir->op2; + nir->ot = IRT(IR_CARG, IRT_NIL); +#if LJ_LE + nir->op2 = hiref; +#else + nir->op2 = nir->op1; nir->op1 = hiref; +#endif + ir->prev = nref = split_emit(J, ot, nref, op2); + } + if (LJ_SOFTFP ? irt_is64(ir->t) : irt_isint64(ir->t)) + hi = split_emit(J, + IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT), + nref, nref); + } else if (ir->o == IR_CARG) { + IRRef hiref = hisubst[ir->op1]; + if (hiref) { + IRRef op2 = nir->op2; +#if LJ_LE + nir->op2 = hiref; +#else + nir->op2 = nir->op1; nir->op1 = hiref; +#endif + ir->prev = nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2); + nir = IR(nref); + } + hiref = hisubst[ir->op2]; + if (hiref) { +#if !LJ_TARGET_X86 + int carg = 0; + IRIns *cir; + for (cir = IR(nir->op1); cir->o == IR_CARG; cir = IR(cir->op1)) + carg++; + if ((carg & 1) == 0) { /* Align 64 bit arguments. */ + IRRef op2 = nir->op2; + nir->op2 = REF_NIL; + nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2); + nir = IR(nref); + } +#endif +#if LJ_BE + { IRRef tmp = nir->op2; nir->op2 = hiref; hiref = tmp; } +#endif + ir->prev = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, hiref); + } + } else if (ir->o == IR_CNEWI) { + if (hisubst[ir->op2]) + split_emit(J, IRT(IR_HIOP, IRT_NIL), nref, hisubst[ir->op2]); + } else if (ir->o == IR_LOOP) { + J->loopref = nref; /* Needed by assembler. */ + } + hisubst[ref] = hi; /* Store hiword substitution. */ + } + if (snref == nins) { /* Substitution for last snapshot. */ + snap->ref = J->cur.nins; + split_subst_snap(J, snap, oir); + } + + /* Add PHI marks. */ + for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) { + IRIns *ir = IR(ref); + if (ir->o != IR_PHI) break; + if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t); + if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t); + } +} + +/* Protected callback for split pass. */ +static TValue *cpsplit(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + split_ir(J); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +#if defined(LUA_USE_ASSERT) || LJ_SOFTFP +/* Slow, but sure way to check whether a SPLIT pass is needed. */ +static int split_needsplit(jit_State *J) +{ + IRIns *ir, *irend; + IRRef ref; + for (ir = IR(REF_FIRST), irend = IR(J->cur.nins); ir < irend; ir++) + if (LJ_SOFTFP ? irt_is64orfp(ir->t) : irt_isint64(ir->t)) + return 1; + if (LJ_SOFTFP) { + for (ref = J->chain[IR_SLOAD]; ref; ref = IR(ref)->prev) + if ((IR(ref)->op2 & IRSLOAD_CONVERT)) + return 1; + if (J->chain[IR_TOBIT]) + return 1; + } + for (ref = J->chain[IR_CONV]; ref; ref = IR(ref)->prev) { + IRType st = (IR(ref)->op2 & IRCONV_SRCMASK); + if ((LJ_SOFTFP && (st == IRT_NUM || st == IRT_FLOAT)) || + st == IRT_I64 || st == IRT_U64) + return 1; + } + return 0; /* Nope. */ +} +#endif + +/* SPLIT pass. */ +void lj_opt_split(jit_State *J) +{ +#if LJ_SOFTFP + if (!J->needsplit) + J->needsplit = split_needsplit(J); +#else + lua_assert(J->needsplit >= split_needsplit(J)); /* Verify flag. */ +#endif + if (J->needsplit) { + int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit); + if (errcode) { + /* Completely reset the trace to avoid inconsistent dump on abort. */ + J->cur.nins = J->cur.nk = REF_BASE; + J->cur.nsnap = 0; + lj_err_throw(J->L, errcode); /* Propagate errors. */ + } + } +} + +#undef IR + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.c new file mode 100644 index 0000000..e8aafba --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.c @@ -0,0 +1,2752 @@ +/* +** Lua parser (source code -> bytecode). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_parse_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_state.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_lex.h" +#include "lj_parse.h" +#include "lj_vm.h" +#include "lj_vmevent.h" + +/* -- Parser structures and definitions ----------------------------------- */ + +/* Expression kinds. */ +typedef enum { + /* Constant expressions must be first and in this order: */ + VKNIL, + VKFALSE, + VKTRUE, + VKSTR, /* sval = string value */ + VKNUM, /* nval = number value */ + VKLAST = VKNUM, + VKCDATA, /* nval = cdata value, not treated as a constant expression */ + /* Non-constant expressions follow: */ + VLOCAL, /* info = local register, aux = vstack index */ + VUPVAL, /* info = upvalue index, aux = vstack index */ + VGLOBAL, /* sval = string value */ + VINDEXED, /* info = table register, aux = index reg/byte/string const */ + VJMP, /* info = instruction PC */ + VRELOCABLE, /* info = instruction PC */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction PC, aux = base */ + VVOID +} ExpKind; + +/* Expression descriptor. */ +typedef struct ExpDesc { + union { + struct { + uint32_t info; /* Primary info. */ + uint32_t aux; /* Secondary info. */ + } s; + TValue nval; /* Number value. */ + GCstr *sval; /* String value. */ + } u; + ExpKind k; + BCPos t; /* True condition jump list. */ + BCPos f; /* False condition jump list. */ +} ExpDesc; + +/* Macros for expressions. */ +#define expr_hasjump(e) ((e)->t != (e)->f) + +#define expr_isk(e) ((e)->k <= VKLAST) +#define expr_isk_nojump(e) (expr_isk(e) && !expr_hasjump(e)) +#define expr_isnumk(e) ((e)->k == VKNUM) +#define expr_isnumk_nojump(e) (expr_isnumk(e) && !expr_hasjump(e)) +#define expr_isstrk(e) ((e)->k == VKSTR) + +#define expr_numtv(e) check_exp(expr_isnumk((e)), &(e)->u.nval) +#define expr_numberV(e) numberVnum(expr_numtv((e))) + +/* Initialize expression. */ +static LJ_AINLINE void expr_init(ExpDesc *e, ExpKind k, uint32_t info) +{ + e->k = k; + e->u.s.info = info; + e->f = e->t = NO_JMP; +} + +/* Check number constant for +-0. */ +static int expr_numiszero(ExpDesc *e) +{ + TValue *o = expr_numtv(e); + return tvisint(o) ? (intV(o) == 0) : tviszero(o); +} + +/* Per-function linked list of scope blocks. */ +typedef struct FuncScope { + struct FuncScope *prev; /* Link to outer scope. */ + MSize vstart; /* Start of block-local variables. */ + uint8_t nactvar; /* Number of active vars outside the scope. */ + uint8_t flags; /* Scope flags. */ +} FuncScope; + +#define FSCOPE_LOOP 0x01 /* Scope is a (breakable) loop. */ +#define FSCOPE_BREAK 0x02 /* Break used in scope. */ +#define FSCOPE_GOLA 0x04 /* Goto or label used in scope. */ +#define FSCOPE_UPVAL 0x08 /* Upvalue in scope. */ +#define FSCOPE_NOCLOSE 0x10 /* Do not close upvalues. */ + +#define NAME_BREAK ((GCstr *)(uintptr_t)1) + +/* Index into variable stack. */ +typedef uint16_t VarIndex; +#define LJ_MAX_VSTACK (65536 - LJ_MAX_UPVAL) + +/* Variable/goto/label info. */ +#define VSTACK_VAR_RW 0x01 /* R/W variable. */ +#define VSTACK_GOTO 0x02 /* Pending goto. */ +#define VSTACK_LABEL 0x04 /* Label. */ + +/* Per-function state. */ +typedef struct FuncState { + GCtab *kt; /* Hash table for constants. */ + LexState *ls; /* Lexer state. */ + lua_State *L; /* Lua state. */ + FuncScope *bl; /* Current scope. */ + struct FuncState *prev; /* Enclosing function. */ + BCPos pc; /* Next bytecode position. */ + BCPos lasttarget; /* Bytecode position of last jump target. */ + BCPos jpc; /* Pending jump list to next bytecode. */ + BCReg freereg; /* First free register. */ + BCReg nactvar; /* Number of active local variables. */ + BCReg nkn, nkgc; /* Number of lua_Number/GCobj constants */ + BCLine linedefined; /* First line of the function definition. */ + BCInsLine *bcbase; /* Base of bytecode stack. */ + BCPos bclim; /* Limit of bytecode stack. */ + MSize vbase; /* Base of variable stack for this function. */ + uint8_t flags; /* Prototype flags. */ + uint8_t numparams; /* Number of parameters. */ + uint8_t framesize; /* Fixed frame size. */ + uint8_t nuv; /* Number of upvalues */ + VarIndex varmap[LJ_MAX_LOCVAR]; /* Map from register to variable idx. */ + VarIndex uvmap[LJ_MAX_UPVAL]; /* Map from upvalue to variable idx. */ + VarIndex uvtmp[LJ_MAX_UPVAL]; /* Temporary upvalue map. */ +} FuncState; + +/* Binary and unary operators. ORDER OPR */ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, /* ORDER ARITH */ + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_GE, OPR_LE, OPR_GT, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + +LJ_STATIC_ASSERT((int)BC_ISGE-(int)BC_ISLT == (int)OPR_GE-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_ISLE-(int)BC_ISLT == (int)OPR_LE-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_ISGT-(int)BC_ISLT == (int)OPR_GT-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_SUBVV-(int)BC_ADDVV == (int)OPR_SUB-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_MULVV-(int)BC_ADDVV == (int)OPR_MUL-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_DIVVV-(int)BC_ADDVV == (int)OPR_DIV-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_MODVV-(int)BC_ADDVV == (int)OPR_MOD-(int)OPR_ADD); + +/* -- Error handling ------------------------------------------------------ */ + +LJ_NORET LJ_NOINLINE static void err_syntax(LexState *ls, ErrMsg em) +{ + lj_lex_error(ls, ls->token, em); +} + +LJ_NORET LJ_NOINLINE static void err_token(LexState *ls, LexToken token) +{ + lj_lex_error(ls, ls->token, LJ_ERR_XTOKEN, lj_lex_token2str(ls, token)); +} + +LJ_NORET static void err_limit(FuncState *fs, uint32_t limit, const char *what) +{ + if (fs->linedefined == 0) + lj_lex_error(fs->ls, 0, LJ_ERR_XLIMM, limit, what); + else + lj_lex_error(fs->ls, 0, LJ_ERR_XLIMF, fs->linedefined, limit, what); +} + +#define checklimit(fs, v, l, m) if ((v) >= (l)) err_limit(fs, l, m) +#define checklimitgt(fs, v, l, m) if ((v) > (l)) err_limit(fs, l, m) +#define checkcond(ls, c, em) { if (!(c)) err_syntax(ls, em); } + +/* -- Management of constants --------------------------------------------- */ + +/* Return bytecode encoding for primitive constant. */ +#define const_pri(e) check_exp((e)->k <= VKTRUE, (e)->k) + +#define tvhaskslot(o) ((o)->u32.hi == 0) +#define tvkslot(o) ((o)->u32.lo) + +/* Add a number constant. */ +static BCReg const_num(FuncState *fs, ExpDesc *e) +{ + lua_State *L = fs->L; + TValue *o; + lua_assert(expr_isnumk(e)); + o = lj_tab_set(L, fs->kt, &e->u.nval); + if (tvhaskslot(o)) + return tvkslot(o); + o->u64 = fs->nkn; + return fs->nkn++; +} + +/* Add a GC object constant. */ +static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype) +{ + lua_State *L = fs->L; + TValue key, *o; + setgcV(L, &key, gc, itype); + /* NOBARRIER: the key is new or kept alive. */ + o = lj_tab_set(L, fs->kt, &key); + if (tvhaskslot(o)) + return tvkslot(o); + o->u64 = fs->nkgc; + return fs->nkgc++; +} + +/* Add a string constant. */ +static BCReg const_str(FuncState *fs, ExpDesc *e) +{ + lua_assert(expr_isstrk(e) || e->k == VGLOBAL); + return const_gc(fs, obj2gco(e->u.sval), LJ_TSTR); +} + +/* Anchor string constant to avoid GC. */ +GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len) +{ + /* NOBARRIER: the key is new or kept alive. */ + lua_State *L = ls->L; + GCstr *s = lj_str_new(L, str, len); + TValue *tv = lj_tab_setstr(L, ls->fs->kt, s); + if (tvisnil(tv)) setboolV(tv, 1); + lj_gc_check(L); + return s; +} + +#if LJ_HASFFI +/* Anchor cdata to avoid GC. */ +void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd) +{ + /* NOBARRIER: the key is new or kept alive. */ + lua_State *L = ls->L; + setcdataV(L, tv, cd); + setboolV(lj_tab_set(L, ls->fs->kt, tv), 1); +} +#endif + +/* -- Jump list handling -------------------------------------------------- */ + +/* Get next element in jump list. */ +static BCPos jmp_next(FuncState *fs, BCPos pc) +{ + ptrdiff_t delta = bc_j(fs->bcbase[pc].ins); + if ((BCPos)delta == NO_JMP) + return NO_JMP; + else + return (BCPos)(((ptrdiff_t)pc+1)+delta); +} + +/* Check if any of the instructions on the jump list produce no value. */ +static int jmp_novalue(FuncState *fs, BCPos list) +{ + for (; list != NO_JMP; list = jmp_next(fs, list)) { + BCIns p = fs->bcbase[list >= 1 ? list-1 : list].ins; + if (!(bc_op(p) == BC_ISTC || bc_op(p) == BC_ISFC || bc_a(p) == NO_REG)) + return 1; + } + return 0; +} + +/* Patch register of test instructions. */ +static int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg) +{ + BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc]; + BCOp op = bc_op(ilp->ins); + if (op == BC_ISTC || op == BC_ISFC) { + if (reg != NO_REG && reg != bc_d(ilp->ins)) { + setbc_a(&ilp->ins, reg); + } else { /* Nothing to store or already in the right register. */ + setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC)); + setbc_a(&ilp->ins, 0); + } + } else if (bc_a(ilp->ins) == NO_REG) { + if (reg == NO_REG) { + ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0); + } else { + setbc_a(&ilp->ins, reg); + if (reg >= bc_a(ilp[1].ins)) + setbc_a(&ilp[1].ins, reg+1); + } + } else { + return 0; /* Cannot patch other instructions. */ + } + return 1; +} + +/* Drop values for all instructions on jump list. */ +static void jmp_dropval(FuncState *fs, BCPos list) +{ + for (; list != NO_JMP; list = jmp_next(fs, list)) + jmp_patchtestreg(fs, list, NO_REG); +} + +/* Patch jump instruction to target. */ +static void jmp_patchins(FuncState *fs, BCPos pc, BCPos dest) +{ + BCIns *jmp = &fs->bcbase[pc].ins; + BCPos offset = dest-(pc+1)+BCBIAS_J; + lua_assert(dest != NO_JMP); + if (offset > BCMAX_D) + err_syntax(fs->ls, LJ_ERR_XJUMP); + setbc_d(jmp, offset); +} + +/* Append to jump list. */ +static void jmp_append(FuncState *fs, BCPos *l1, BCPos l2) +{ + if (l2 == NO_JMP) { + return; + } else if (*l1 == NO_JMP) { + *l1 = l2; + } else { + BCPos list = *l1; + BCPos next; + while ((next = jmp_next(fs, list)) != NO_JMP) /* Find last element. */ + list = next; + jmp_patchins(fs, list, l2); + } +} + +/* Patch jump list and preserve produced values. */ +static void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget, + BCReg reg, BCPos dtarget) +{ + while (list != NO_JMP) { + BCPos next = jmp_next(fs, list); + if (jmp_patchtestreg(fs, list, reg)) + jmp_patchins(fs, list, vtarget); /* Jump to target with value. */ + else + jmp_patchins(fs, list, dtarget); /* Jump to default target. */ + list = next; + } +} + +/* Jump to following instruction. Append to list of pending jumps. */ +static void jmp_tohere(FuncState *fs, BCPos list) +{ + fs->lasttarget = fs->pc; + jmp_append(fs, &fs->jpc, list); +} + +/* Patch jump list to target. */ +static void jmp_patch(FuncState *fs, BCPos list, BCPos target) +{ + if (target == fs->pc) { + jmp_tohere(fs, list); + } else { + lua_assert(target < fs->pc); + jmp_patchval(fs, list, target, NO_REG, target); + } +} + +/* -- Bytecode register allocator ----------------------------------------- */ + +/* Bump frame size. */ +static void bcreg_bump(FuncState *fs, BCReg n) +{ + BCReg sz = fs->freereg + n; + if (sz > fs->framesize) { + if (sz >= LJ_MAX_SLOTS) + err_syntax(fs->ls, LJ_ERR_XSLOTS); + fs->framesize = (uint8_t)sz; + } +} + +/* Reserve registers. */ +static void bcreg_reserve(FuncState *fs, BCReg n) +{ + bcreg_bump(fs, n); + fs->freereg += n; +} + +/* Free register. */ +static void bcreg_free(FuncState *fs, BCReg reg) +{ + if (reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + +/* Free register for expression. */ +static void expr_free(FuncState *fs, ExpDesc *e) +{ + if (e->k == VNONRELOC) + bcreg_free(fs, e->u.s.info); +} + +/* -- Bytecode emitter ---------------------------------------------------- */ + +/* Emit bytecode instruction. */ +static BCPos bcemit_INS(FuncState *fs, BCIns ins) +{ + BCPos pc = fs->pc; + LexState *ls = fs->ls; + jmp_patchval(fs, fs->jpc, pc, NO_REG, pc); + fs->jpc = NO_JMP; + if (LJ_UNLIKELY(pc >= fs->bclim)) { + ptrdiff_t base = fs->bcbase - ls->bcstack; + checklimit(fs, ls->sizebcstack, LJ_MAX_BCINS, "bytecode instructions"); + lj_mem_growvec(fs->L, ls->bcstack, ls->sizebcstack, LJ_MAX_BCINS,BCInsLine); + fs->bclim = (BCPos)(ls->sizebcstack - base); + fs->bcbase = ls->bcstack + base; + } + fs->bcbase[pc].ins = ins; + fs->bcbase[pc].line = ls->lastline; + fs->pc = pc+1; + return pc; +} + +#define bcemit_ABC(fs, o, a, b, c) bcemit_INS(fs, BCINS_ABC(o, a, b, c)) +#define bcemit_AD(fs, o, a, d) bcemit_INS(fs, BCINS_AD(o, a, d)) +#define bcemit_AJ(fs, o, a, j) bcemit_INS(fs, BCINS_AJ(o, a, j)) + +#define bcptr(fs, e) (&(fs)->bcbase[(e)->u.s.info].ins) + +/* -- Bytecode emitter for expressions ------------------------------------ */ + +/* Discharge non-constant expression to any register. */ +static void expr_discharge(FuncState *fs, ExpDesc *e) +{ + BCIns ins; + if (e->k == VUPVAL) { + ins = BCINS_AD(BC_UGET, 0, e->u.s.info); + } else if (e->k == VGLOBAL) { + ins = BCINS_AD(BC_GGET, 0, const_str(fs, e)); + } else if (e->k == VINDEXED) { + BCReg rc = e->u.s.aux; + if ((int32_t)rc < 0) { + ins = BCINS_ABC(BC_TGETS, 0, e->u.s.info, ~rc); + } else if (rc > BCMAX_C) { + ins = BCINS_ABC(BC_TGETB, 0, e->u.s.info, rc-(BCMAX_C+1)); + } else { + bcreg_free(fs, rc); + ins = BCINS_ABC(BC_TGETV, 0, e->u.s.info, rc); + } + bcreg_free(fs, e->u.s.info); + } else if (e->k == VCALL) { + e->u.s.info = e->u.s.aux; + e->k = VNONRELOC; + return; + } else if (e->k == VLOCAL) { + e->k = VNONRELOC; + return; + } else { + return; + } + e->u.s.info = bcemit_INS(fs, ins); + e->k = VRELOCABLE; +} + +/* Emit bytecode to set a range of registers to nil. */ +static void bcemit_nil(FuncState *fs, BCReg from, BCReg n) +{ + if (fs->pc > fs->lasttarget) { /* No jumps to current position? */ + BCIns *ip = &fs->bcbase[fs->pc-1].ins; + BCReg pto, pfrom = bc_a(*ip); + switch (bc_op(*ip)) { /* Try to merge with the previous instruction. */ + case BC_KPRI: + if (bc_d(*ip) != ~LJ_TNIL) break; + if (from == pfrom) { + if (n == 1) return; + } else if (from == pfrom+1) { + from = pfrom; + n++; + } else { + break; + } + *ip = BCINS_AD(BC_KNIL, from, from+n-1); /* Replace KPRI. */ + return; + case BC_KNIL: + pto = bc_d(*ip); + if (pfrom <= from && from <= pto+1) { /* Can we connect both ranges? */ + if (from+n-1 > pto) + setbc_d(ip, from+n-1); /* Patch previous instruction range. */ + return; + } + break; + default: + break; + } + } + /* Emit new instruction or replace old instruction. */ + bcemit_INS(fs, n == 1 ? BCINS_AD(BC_KPRI, from, VKNIL) : + BCINS_AD(BC_KNIL, from, from+n-1)); +} + +/* Discharge an expression to a specific register. Ignore branches. */ +static void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg) +{ + BCIns ins; + expr_discharge(fs, e); + if (e->k == VKSTR) { + ins = BCINS_AD(BC_KSTR, reg, const_str(fs, e)); + } else if (e->k == VKNUM) { +#if LJ_DUALNUM + cTValue *tv = expr_numtv(e); + if (tvisint(tv) && checki16(intV(tv))) + ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv)); + else +#else + lua_Number n = expr_numberV(e); + int32_t k = lj_num2int(n); + if (checki16(k) && n == (lua_Number)k) + ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); + else +#endif + ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e)); +#if LJ_HASFFI + } else if (e->k == VKCDATA) { + fs->flags |= PROTO_FFI; + ins = BCINS_AD(BC_KCDATA, reg, + const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA)); +#endif + } else if (e->k == VRELOCABLE) { + setbc_a(bcptr(fs, e), reg); + goto noins; + } else if (e->k == VNONRELOC) { + if (reg == e->u.s.info) + goto noins; + ins = BCINS_AD(BC_MOV, reg, e->u.s.info); + } else if (e->k == VKNIL) { + bcemit_nil(fs, reg, 1); + goto noins; + } else if (e->k <= VKTRUE) { + ins = BCINS_AD(BC_KPRI, reg, const_pri(e)); + } else { + lua_assert(e->k == VVOID || e->k == VJMP); + return; + } + bcemit_INS(fs, ins); +noins: + e->u.s.info = reg; + e->k = VNONRELOC; +} + +/* Forward declaration. */ +static BCPos bcemit_jmp(FuncState *fs); + +/* Discharge an expression to a specific register. */ +static void expr_toreg(FuncState *fs, ExpDesc *e, BCReg reg) +{ + expr_toreg_nobranch(fs, e, reg); + if (e->k == VJMP) + jmp_append(fs, &e->t, e->u.s.info); /* Add it to the true jump list. */ + if (expr_hasjump(e)) { /* Discharge expression with branches. */ + BCPos jend, jfalse = NO_JMP, jtrue = NO_JMP; + if (jmp_novalue(fs, e->t) || jmp_novalue(fs, e->f)) { + BCPos jval = (e->k == VJMP) ? NO_JMP : bcemit_jmp(fs); + jfalse = bcemit_AD(fs, BC_KPRI, reg, VKFALSE); + bcemit_AJ(fs, BC_JMP, fs->freereg, 1); + jtrue = bcemit_AD(fs, BC_KPRI, reg, VKTRUE); + jmp_tohere(fs, jval); + } + jend = fs->pc; + fs->lasttarget = jend; + jmp_patchval(fs, e->f, jend, reg, jfalse); + jmp_patchval(fs, e->t, jend, reg, jtrue); + } + e->f = e->t = NO_JMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + +/* Discharge an expression to the next free register. */ +static void expr_tonextreg(FuncState *fs, ExpDesc *e) +{ + expr_discharge(fs, e); + expr_free(fs, e); + bcreg_reserve(fs, 1); + expr_toreg(fs, e, fs->freereg - 1); +} + +/* Discharge an expression to any register. */ +static BCReg expr_toanyreg(FuncState *fs, ExpDesc *e) +{ + expr_discharge(fs, e); + if (e->k == VNONRELOC) { + if (!expr_hasjump(e)) return e->u.s.info; /* Already in a register. */ + if (e->u.s.info >= fs->nactvar) { + expr_toreg(fs, e, e->u.s.info); /* Discharge to temp. register. */ + return e->u.s.info; + } + } + expr_tonextreg(fs, e); /* Discharge to next register. */ + return e->u.s.info; +} + +/* Partially discharge expression to a value. */ +static void expr_toval(FuncState *fs, ExpDesc *e) +{ + if (expr_hasjump(e)) + expr_toanyreg(fs, e); + else + expr_discharge(fs, e); +} + +/* Emit store for LHS expression. */ +static void bcemit_store(FuncState *fs, ExpDesc *var, ExpDesc *e) +{ + BCIns ins; + if (var->k == VLOCAL) { + fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW; + expr_free(fs, e); + expr_toreg(fs, e, var->u.s.info); + return; + } else if (var->k == VUPVAL) { + fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW; + expr_toval(fs, e); + if (e->k <= VKTRUE) + ins = BCINS_AD(BC_USETP, var->u.s.info, const_pri(e)); + else if (e->k == VKSTR) + ins = BCINS_AD(BC_USETS, var->u.s.info, const_str(fs, e)); + else if (e->k == VKNUM) + ins = BCINS_AD(BC_USETN, var->u.s.info, const_num(fs, e)); + else + ins = BCINS_AD(BC_USETV, var->u.s.info, expr_toanyreg(fs, e)); + } else if (var->k == VGLOBAL) { + BCReg ra = expr_toanyreg(fs, e); + ins = BCINS_AD(BC_GSET, ra, const_str(fs, var)); + } else { + BCReg ra, rc; + lua_assert(var->k == VINDEXED); + ra = expr_toanyreg(fs, e); + rc = var->u.s.aux; + if ((int32_t)rc < 0) { + ins = BCINS_ABC(BC_TSETS, ra, var->u.s.info, ~rc); + } else if (rc > BCMAX_C) { + ins = BCINS_ABC(BC_TSETB, ra, var->u.s.info, rc-(BCMAX_C+1)); + } else { + /* Free late alloced key reg to avoid assert on free of value reg. */ + /* This can only happen when called from expr_table(). */ + lua_assert(e->k != VNONRELOC || ra < fs->nactvar || + rc < ra || (bcreg_free(fs, rc),1)); + ins = BCINS_ABC(BC_TSETV, ra, var->u.s.info, rc); + } + } + bcemit_INS(fs, ins); + expr_free(fs, e); +} + +/* Emit method lookup expression. */ +static void bcemit_method(FuncState *fs, ExpDesc *e, ExpDesc *key) +{ + BCReg idx, func, obj = expr_toanyreg(fs, e); + expr_free(fs, e); + func = fs->freereg; + bcemit_AD(fs, BC_MOV, func+1, obj); /* Copy object to first argument. */ + lua_assert(expr_isstrk(key)); + idx = const_str(fs, key); + if (idx <= BCMAX_C) { + bcreg_reserve(fs, 2); + bcemit_ABC(fs, BC_TGETS, func, obj, idx); + } else { + bcreg_reserve(fs, 3); + bcemit_AD(fs, BC_KSTR, func+2, idx); + bcemit_ABC(fs, BC_TGETV, func, obj, func+2); + fs->freereg--; + } + e->u.s.info = func; + e->k = VNONRELOC; +} + +/* -- Bytecode emitter for branches --------------------------------------- */ + +/* Emit unconditional branch. */ +static BCPos bcemit_jmp(FuncState *fs) +{ + BCPos jpc = fs->jpc; + BCPos j = fs->pc - 1; + BCIns *ip = &fs->bcbase[j].ins; + fs->jpc = NO_JMP; + if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) + setbc_j(ip, NO_JMP); + else + j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP); + jmp_append(fs, &j, jpc); + return j; +} + +/* Invert branch condition of bytecode instruction. */ +static void invertcond(FuncState *fs, ExpDesc *e) +{ + BCIns *ip = &fs->bcbase[e->u.s.info - 1].ins; + setbc_op(ip, bc_op(*ip)^1); +} + +/* Emit conditional branch. */ +static BCPos bcemit_branch(FuncState *fs, ExpDesc *e, int cond) +{ + BCPos pc; + if (e->k == VRELOCABLE) { + BCIns *ip = bcptr(fs, e); + if (bc_op(*ip) == BC_NOT) { + *ip = BCINS_AD(cond ? BC_ISF : BC_IST, 0, bc_d(*ip)); + return bcemit_jmp(fs); + } + } + if (e->k != VNONRELOC) { + bcreg_reserve(fs, 1); + expr_toreg_nobranch(fs, e, fs->freereg-1); + } + bcemit_AD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->u.s.info); + pc = bcemit_jmp(fs); + expr_free(fs, e); + return pc; +} + +/* Emit branch on true condition. */ +static void bcemit_branch_t(FuncState *fs, ExpDesc *e) +{ + BCPos pc; + expr_discharge(fs, e); + if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE) + pc = NO_JMP; /* Never jump. */ + else if (e->k == VJMP) + invertcond(fs, e), pc = e->u.s.info; + else if (e->k == VKFALSE || e->k == VKNIL) + expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs); + else + pc = bcemit_branch(fs, e, 0); + jmp_append(fs, &e->f, pc); + jmp_tohere(fs, e->t); + e->t = NO_JMP; +} + +/* Emit branch on false condition. */ +static void bcemit_branch_f(FuncState *fs, ExpDesc *e) +{ + BCPos pc; + expr_discharge(fs, e); + if (e->k == VKNIL || e->k == VKFALSE) + pc = NO_JMP; /* Never jump. */ + else if (e->k == VJMP) + pc = e->u.s.info; + else if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE) + expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs); + else + pc = bcemit_branch(fs, e, 1); + jmp_append(fs, &e->t, pc); + jmp_tohere(fs, e->f); + e->f = NO_JMP; +} + +/* -- Bytecode emitter for operators -------------------------------------- */ + +/* Try constant-folding of arithmetic operators. */ +static int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + TValue o; + lua_Number n; + if (!expr_isnumk_nojump(e1) || !expr_isnumk_nojump(e2)) return 0; + n = lj_vm_foldarith(expr_numberV(e1), expr_numberV(e2), (int)opr-OPR_ADD); + setnumV(&o, n); + if (tvisnan(&o) || tvismzero(&o)) return 0; /* Avoid NaN and -0 as consts. */ + if (LJ_DUALNUM) { + int32_t k = lj_num2int(n); + if ((lua_Number)k == n) { + setintV(&e1->u.nval, k); + return 1; + } + } + setnumV(&e1->u.nval, n); + return 1; +} + +/* Emit arithmetic operator. */ +static void bcemit_arith(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + BCReg rb, rc, t; + uint32_t op; + if (foldarith(opr, e1, e2)) + return; + if (opr == OPR_POW) { + op = BC_POW; + rc = expr_toanyreg(fs, e2); + rb = expr_toanyreg(fs, e1); + } else { + op = opr-OPR_ADD+BC_ADDVV; + /* Must discharge 2nd operand first since VINDEXED might free regs. */ + expr_toval(fs, e2); + if (expr_isnumk(e2) && (rc = const_num(fs, e2)) <= BCMAX_C) + op -= BC_ADDVV-BC_ADDVN; + else + rc = expr_toanyreg(fs, e2); + /* 1st operand discharged by bcemit_binop_left, but need KNUM/KSHORT. */ + lua_assert(expr_isnumk(e1) || e1->k == VNONRELOC); + expr_toval(fs, e1); + /* Avoid two consts to satisfy bytecode constraints. */ + if (expr_isnumk(e1) && !expr_isnumk(e2) && + (t = const_num(fs, e1)) <= BCMAX_B) { + rb = rc; rc = t; op -= BC_ADDVV-BC_ADDNV; + } else { + rb = expr_toanyreg(fs, e1); + } + } + /* Using expr_free might cause asserts if the order is wrong. */ + if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--; + if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--; + e1->u.s.info = bcemit_ABC(fs, op, 0, rb, rc); + e1->k = VRELOCABLE; +} + +/* Emit comparison operator. */ +static void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + ExpDesc *eret = e1; + BCIns ins; + expr_toval(fs, e1); + if (opr == OPR_EQ || opr == OPR_NE) { + BCOp op = opr == OPR_EQ ? BC_ISEQV : BC_ISNEV; + BCReg ra; + if (expr_isk(e1)) { e1 = e2; e2 = eret; } /* Need constant in 2nd arg. */ + ra = expr_toanyreg(fs, e1); /* First arg must be in a reg. */ + expr_toval(fs, e2); + switch (e2->k) { + case VKNIL: case VKFALSE: case VKTRUE: + ins = BCINS_AD(op+(BC_ISEQP-BC_ISEQV), ra, const_pri(e2)); + break; + case VKSTR: + ins = BCINS_AD(op+(BC_ISEQS-BC_ISEQV), ra, const_str(fs, e2)); + break; + case VKNUM: + ins = BCINS_AD(op+(BC_ISEQN-BC_ISEQV), ra, const_num(fs, e2)); + break; + default: + ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2)); + break; + } + } else { + uint32_t op = opr-OPR_LT+BC_ISLT; + BCReg ra, rd; + if ((op-BC_ISLT) & 1) { /* GT -> LT, GE -> LE */ + e1 = e2; e2 = eret; /* Swap operands. */ + op = ((op-BC_ISLT)^3)+BC_ISLT; + expr_toval(fs, e1); + } + rd = expr_toanyreg(fs, e2); + ra = expr_toanyreg(fs, e1); + ins = BCINS_AD(op, ra, rd); + } + /* Using expr_free might cause asserts if the order is wrong. */ + if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--; + if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--; + bcemit_INS(fs, ins); + eret->u.s.info = bcemit_jmp(fs); + eret->k = VJMP; +} + +/* Fixup left side of binary operator. */ +static void bcemit_binop_left(FuncState *fs, BinOpr op, ExpDesc *e) +{ + if (op == OPR_AND) { + bcemit_branch_t(fs, e); + } else if (op == OPR_OR) { + bcemit_branch_f(fs, e); + } else if (op == OPR_CONCAT) { + expr_tonextreg(fs, e); + } else if (op == OPR_EQ || op == OPR_NE) { + if (!expr_isk_nojump(e)) expr_toanyreg(fs, e); + } else { + if (!expr_isnumk_nojump(e)) expr_toanyreg(fs, e); + } +} + +/* Emit binary operator. */ +static void bcemit_binop(FuncState *fs, BinOpr op, ExpDesc *e1, ExpDesc *e2) +{ + if (op <= OPR_POW) { + bcemit_arith(fs, op, e1, e2); + } else if (op == OPR_AND) { + lua_assert(e1->t == NO_JMP); /* List must be closed. */ + expr_discharge(fs, e2); + jmp_append(fs, &e2->f, e1->f); + *e1 = *e2; + } else if (op == OPR_OR) { + lua_assert(e1->f == NO_JMP); /* List must be closed. */ + expr_discharge(fs, e2); + jmp_append(fs, &e2->t, e1->t); + *e1 = *e2; + } else if (op == OPR_CONCAT) { + expr_toval(fs, e2); + if (e2->k == VRELOCABLE && bc_op(*bcptr(fs, e2)) == BC_CAT) { + lua_assert(e1->u.s.info == bc_b(*bcptr(fs, e2))-1); + expr_free(fs, e1); + setbc_b(bcptr(fs, e2), e1->u.s.info); + e1->u.s.info = e2->u.s.info; + } else { + expr_tonextreg(fs, e2); + expr_free(fs, e2); + expr_free(fs, e1); + e1->u.s.info = bcemit_ABC(fs, BC_CAT, 0, e1->u.s.info, e2->u.s.info); + } + e1->k = VRELOCABLE; + } else { + lua_assert(op == OPR_NE || op == OPR_EQ || + op == OPR_LT || op == OPR_GE || op == OPR_LE || op == OPR_GT); + bcemit_comp(fs, op, e1, e2); + } +} + +/* Emit unary operator. */ +static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e) +{ + if (op == BC_NOT) { + /* Swap true and false lists. */ + { BCPos temp = e->f; e->f = e->t; e->t = temp; } + jmp_dropval(fs, e->f); + jmp_dropval(fs, e->t); + expr_discharge(fs, e); + if (e->k == VKNIL || e->k == VKFALSE) { + e->k = VKTRUE; + return; + } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) { + e->k = VKFALSE; + return; + } else if (e->k == VJMP) { + invertcond(fs, e); + return; + } else if (e->k == VRELOCABLE) { + bcreg_reserve(fs, 1); + setbc_a(bcptr(fs, e), fs->freereg-1); + e->u.s.info = fs->freereg-1; + e->k = VNONRELOC; + } else { + lua_assert(e->k == VNONRELOC); + } + } else { + lua_assert(op == BC_UNM || op == BC_LEN); + if (op == BC_UNM && !expr_hasjump(e)) { /* Constant-fold negations. */ +#if LJ_HASFFI + if (e->k == VKCDATA) { /* Fold in-place since cdata is not interned. */ + GCcdata *cd = cdataV(&e->u.nval); + int64_t *p = (int64_t *)cdataptr(cd); + if (cd->ctypeid == CTID_COMPLEX_DOUBLE) + p[1] ^= (int64_t)U64x(80000000,00000000); + else + *p = -*p; + return; + } else +#endif + if (expr_isnumk(e) && !expr_numiszero(e)) { /* Avoid folding to -0. */ + TValue *o = expr_numtv(e); + if (tvisint(o)) { + int32_t k = intV(o); + if (k == -k) + setnumV(o, -(lua_Number)k); + else + setintV(o, -k); + return; + } else { + o->u64 ^= U64x(80000000,00000000); + return; + } + } + } + expr_toanyreg(fs, e); + } + expr_free(fs, e); + e->u.s.info = bcemit_AD(fs, op, 0, e->u.s.info); + e->k = VRELOCABLE; +} + +/* -- Lexer support ------------------------------------------------------- */ + +/* Check and consume optional token. */ +static int lex_opt(LexState *ls, LexToken tok) +{ + if (ls->token == tok) { + lj_lex_next(ls); + return 1; + } + return 0; +} + +/* Check and consume token. */ +static void lex_check(LexState *ls, LexToken tok) +{ + if (ls->token != tok) + err_token(ls, tok); + lj_lex_next(ls); +} + +/* Check for matching token. */ +static void lex_match(LexState *ls, LexToken what, LexToken who, BCLine line) +{ + if (!lex_opt(ls, what)) { + if (line == ls->linenumber) { + err_token(ls, what); + } else { + const char *swhat = lj_lex_token2str(ls, what); + const char *swho = lj_lex_token2str(ls, who); + lj_lex_error(ls, ls->token, LJ_ERR_XMATCH, swhat, swho, line); + } + } +} + +/* Check for string token. */ +static GCstr *lex_str(LexState *ls) +{ + GCstr *s; + if (ls->token != TK_name && (LJ_52 || ls->token != TK_goto)) + err_token(ls, TK_name); + s = strV(&ls->tokenval); + lj_lex_next(ls); + return s; +} + +/* -- Variable handling --------------------------------------------------- */ + +#define var_get(ls, fs, i) ((ls)->vstack[(fs)->varmap[(i)]]) + +/* Define a new local variable. */ +static void var_new(LexState *ls, BCReg n, GCstr *name) +{ + FuncState *fs = ls->fs; + MSize vtop = ls->vtop; + checklimit(fs, fs->nactvar+n, LJ_MAX_LOCVAR, "local variables"); + if (LJ_UNLIKELY(vtop >= ls->sizevstack)) { + if (ls->sizevstack >= LJ_MAX_VSTACK) + lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK); + lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo); + } + lua_assert((uintptr_t)name < VARNAME__MAX || + lj_tab_getstr(fs->kt, name) != NULL); + /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */ + setgcref(ls->vstack[vtop].name, obj2gco(name)); + fs->varmap[fs->nactvar+n] = (uint16_t)vtop; + ls->vtop = vtop+1; +} + +#define var_new_lit(ls, n, v) \ + var_new(ls, (n), lj_parse_keepstr(ls, "" v, sizeof(v)-1)) + +#define var_new_fixed(ls, n, vn) \ + var_new(ls, (n), (GCstr *)(uintptr_t)(vn)) + +/* Add local variables. */ +static void var_add(LexState *ls, BCReg nvars) +{ + FuncState *fs = ls->fs; + BCReg nactvar = fs->nactvar; + while (nvars--) { + VarInfo *v = &var_get(ls, fs, nactvar); + v->startpc = fs->pc; + v->slot = nactvar++; + v->info = 0; + } + fs->nactvar = nactvar; +} + +/* Remove local variables. */ +static void var_remove(LexState *ls, BCReg tolevel) +{ + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + var_get(ls, fs, --fs->nactvar).endpc = fs->pc; +} + +/* Lookup local variable name. */ +static BCReg var_lookup_local(FuncState *fs, GCstr *n) +{ + int i; + for (i = fs->nactvar-1; i >= 0; i--) { + if (n == strref(var_get(fs->ls, fs, i).name)) + return (BCReg)i; + } + return (BCReg)-1; /* Not found. */ +} + +/* Lookup or add upvalue index. */ +static MSize var_lookup_uv(FuncState *fs, MSize vidx, ExpDesc *e) +{ + MSize i, n = fs->nuv; + for (i = 0; i < n; i++) + if (fs->uvmap[i] == vidx) + return i; /* Already exists. */ + /* Otherwise create a new one. */ + checklimit(fs, fs->nuv, LJ_MAX_UPVAL, "upvalues"); + lua_assert(e->k == VLOCAL || e->k == VUPVAL); + fs->uvmap[n] = (uint16_t)vidx; + fs->uvtmp[n] = (uint16_t)(e->k == VLOCAL ? vidx : LJ_MAX_VSTACK+e->u.s.info); + fs->nuv = n+1; + return n; +} + +/* Forward declaration. */ +static void fscope_uvmark(FuncState *fs, BCReg level); + +/* Recursively lookup variables in enclosing functions. */ +static MSize var_lookup_(FuncState *fs, GCstr *name, ExpDesc *e, int first) +{ + if (fs) { + BCReg reg = var_lookup_local(fs, name); + if ((int32_t)reg >= 0) { /* Local in this function? */ + expr_init(e, VLOCAL, reg); + if (!first) + fscope_uvmark(fs, reg); /* Scope now has an upvalue. */ + return (MSize)(e->u.s.aux = (uint32_t)fs->varmap[reg]); + } else { + MSize vidx = var_lookup_(fs->prev, name, e, 0); /* Var in outer func? */ + if ((int32_t)vidx >= 0) { /* Yes, make it an upvalue here. */ + e->u.s.info = (uint8_t)var_lookup_uv(fs, vidx, e); + e->k = VUPVAL; + return vidx; + } + } + } else { /* Not found in any function, must be a global. */ + expr_init(e, VGLOBAL, 0); + e->u.sval = name; + } + return (MSize)-1; /* Global. */ +} + +/* Lookup variable name. */ +#define var_lookup(ls, e) \ + var_lookup_((ls)->fs, lex_str(ls), (e), 1) + +/* -- Goto an label handling ---------------------------------------------- */ + +/* Add a new goto or label. */ +static MSize gola_new(LexState *ls, GCstr *name, uint8_t info, BCPos pc) +{ + FuncState *fs = ls->fs; + MSize vtop = ls->vtop; + if (LJ_UNLIKELY(vtop >= ls->sizevstack)) { + if (ls->sizevstack >= LJ_MAX_VSTACK) + lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK); + lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo); + } + lua_assert(name == NAME_BREAK || lj_tab_getstr(fs->kt, name) != NULL); + /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */ + setgcref(ls->vstack[vtop].name, obj2gco(name)); + ls->vstack[vtop].startpc = pc; + ls->vstack[vtop].slot = (uint8_t)fs->nactvar; + ls->vstack[vtop].info = info; + ls->vtop = vtop+1; + return vtop; +} + +#define gola_isgoto(v) ((v)->info & VSTACK_GOTO) +#define gola_islabel(v) ((v)->info & VSTACK_LABEL) +#define gola_isgotolabel(v) ((v)->info & (VSTACK_GOTO|VSTACK_LABEL)) + +/* Patch goto to jump to label. */ +static void gola_patch(LexState *ls, VarInfo *vg, VarInfo *vl) +{ + FuncState *fs = ls->fs; + BCPos pc = vg->startpc; + setgcrefnull(vg->name); /* Invalidate pending goto. */ + setbc_a(&fs->bcbase[pc].ins, vl->slot); + jmp_patch(fs, pc, vl->startpc); +} + +/* Patch goto to close upvalues. */ +static void gola_close(LexState *ls, VarInfo *vg) +{ + FuncState *fs = ls->fs; + BCPos pc = vg->startpc; + BCIns *ip = &fs->bcbase[pc].ins; + lua_assert(gola_isgoto(vg)); + lua_assert(bc_op(*ip) == BC_JMP || bc_op(*ip) == BC_UCLO); + setbc_a(ip, vg->slot); + if (bc_op(*ip) == BC_JMP) { + BCPos next = jmp_next(fs, pc); + if (next != NO_JMP) jmp_patch(fs, next, pc); /* Jump to UCLO. */ + setbc_op(ip, BC_UCLO); /* Turn into UCLO. */ + setbc_j(ip, NO_JMP); + } +} + +/* Resolve pending forward gotos for label. */ +static void gola_resolve(LexState *ls, FuncScope *bl, MSize idx) +{ + VarInfo *vg = ls->vstack + bl->vstart; + VarInfo *vl = ls->vstack + idx; + for (; vg < vl; vg++) + if (gcrefeq(vg->name, vl->name) && gola_isgoto(vg)) { + if (vg->slot < vl->slot) { + GCstr *name = strref(var_get(ls, ls->fs, vg->slot).name); + lua_assert((uintptr_t)name >= VARNAME__MAX); + ls->linenumber = ls->fs->bcbase[vg->startpc].line; + lua_assert(strref(vg->name) != NAME_BREAK); + lj_lex_error(ls, 0, LJ_ERR_XGSCOPE, + strdata(strref(vg->name)), strdata(name)); + } + gola_patch(ls, vg, vl); + } +} + +/* Fixup remaining gotos and labels for scope. */ +static void gola_fixup(LexState *ls, FuncScope *bl) +{ + VarInfo *v = ls->vstack + bl->vstart; + VarInfo *ve = ls->vstack + ls->vtop; + for (; v < ve; v++) { + GCstr *name = strref(v->name); + if (name != NULL) { /* Only consider remaining valid gotos/labels. */ + if (gola_islabel(v)) { + VarInfo *vg; + setgcrefnull(v->name); /* Invalidate label that goes out of scope. */ + for (vg = v+1; vg < ve; vg++) /* Resolve pending backward gotos. */ + if (strref(vg->name) == name && gola_isgoto(vg)) { + if ((bl->flags&FSCOPE_UPVAL) && vg->slot > v->slot) + gola_close(ls, vg); + gola_patch(ls, vg, v); + } + } else if (gola_isgoto(v)) { + if (bl->prev) { /* Propagate goto or break to outer scope. */ + bl->prev->flags |= name == NAME_BREAK ? FSCOPE_BREAK : FSCOPE_GOLA; + v->slot = bl->nactvar; + if ((bl->flags & FSCOPE_UPVAL)) + gola_close(ls, v); + } else { /* No outer scope: undefined goto label or no loop. */ + ls->linenumber = ls->fs->bcbase[v->startpc].line; + if (name == NAME_BREAK) + lj_lex_error(ls, 0, LJ_ERR_XBREAK); + else + lj_lex_error(ls, 0, LJ_ERR_XLUNDEF, strdata(name)); + } + } + } + } +} + +/* Find existing label. */ +static VarInfo *gola_findlabel(LexState *ls, GCstr *name) +{ + VarInfo *v = ls->vstack + ls->fs->bl->vstart; + VarInfo *ve = ls->vstack + ls->vtop; + for (; v < ve; v++) + if (strref(v->name) == name && gola_islabel(v)) + return v; + return NULL; +} + +/* -- Scope handling ------------------------------------------------------ */ + +/* Begin a scope. */ +static void fscope_begin(FuncState *fs, FuncScope *bl, int flags) +{ + bl->nactvar = (uint8_t)fs->nactvar; + bl->flags = flags; + bl->vstart = fs->ls->vtop; + bl->prev = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + +/* End a scope. */ +static void fscope_end(FuncState *fs) +{ + FuncScope *bl = fs->bl; + LexState *ls = fs->ls; + fs->bl = bl->prev; + var_remove(ls, bl->nactvar); + fs->freereg = fs->nactvar; + lua_assert(bl->nactvar == fs->nactvar); + if ((bl->flags & (FSCOPE_UPVAL|FSCOPE_NOCLOSE)) == FSCOPE_UPVAL) + bcemit_AJ(fs, BC_UCLO, bl->nactvar, 0); + if ((bl->flags & FSCOPE_BREAK)) { + if ((bl->flags & FSCOPE_LOOP)) { + MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc); + ls->vtop = idx; /* Drop break label immediately. */ + gola_resolve(ls, bl, idx); + return; + } /* else: need the fixup step to propagate the breaks. */ + } else if (!(bl->flags & FSCOPE_GOLA)) { + return; + } + gola_fixup(ls, bl); +} + +/* Mark scope as having an upvalue. */ +static void fscope_uvmark(FuncState *fs, BCReg level) +{ + FuncScope *bl; + for (bl = fs->bl; bl && bl->nactvar > level; bl = bl->prev) + ; + if (bl) + bl->flags |= FSCOPE_UPVAL; +} + +/* -- Function state management ------------------------------------------- */ + +/* Fixup bytecode for prototype. */ +static void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, MSize n) +{ + BCInsLine *base = fs->bcbase; + MSize i; + pt->sizebc = n; + bc[0] = BCINS_AD((fs->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF, + fs->framesize, 0); + for (i = 1; i < n; i++) + bc[i] = base[i].ins; +} + +/* Fixup upvalues for child prototype, step #2. */ +static void fs_fixup_uv2(FuncState *fs, GCproto *pt) +{ + VarInfo *vstack = fs->ls->vstack; + uint16_t *uv = proto_uv(pt); + MSize i, n = pt->sizeuv; + for (i = 0; i < n; i++) { + VarIndex vidx = uv[i]; + if (vidx >= LJ_MAX_VSTACK) + uv[i] = vidx - LJ_MAX_VSTACK; + else if ((vstack[vidx].info & VSTACK_VAR_RW)) + uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL; + else + uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL | PROTO_UV_IMMUTABLE; + } +} + +/* Fixup constants for prototype. */ +static void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr) +{ + GCtab *kt; + TValue *array; + Node *node; + MSize i, hmask; + checklimitgt(fs, fs->nkn, BCMAX_D+1, "constants"); + checklimitgt(fs, fs->nkgc, BCMAX_D+1, "constants"); + setmref(pt->k, kptr); + pt->sizekn = fs->nkn; + pt->sizekgc = fs->nkgc; + kt = fs->kt; + array = tvref(kt->array); + for (i = 0; i < kt->asize; i++) + if (tvhaskslot(&array[i])) { + TValue *tv = &((TValue *)kptr)[tvkslot(&array[i])]; + if (LJ_DUALNUM) + setintV(tv, (int32_t)i); + else + setnumV(tv, (lua_Number)i); + } + node = noderef(kt->node); + hmask = kt->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (tvhaskslot(&n->val)) { + ptrdiff_t kidx = (ptrdiff_t)tvkslot(&n->val); + lua_assert(!tvisint(&n->key)); + if (tvisnum(&n->key)) { + TValue *tv = &((TValue *)kptr)[kidx]; + if (LJ_DUALNUM) { + lua_Number nn = numV(&n->key); + int32_t k = lj_num2int(nn); + lua_assert(!tvismzero(&n->key)); + if ((lua_Number)k == nn) + setintV(tv, k); + else + *tv = n->key; + } else { + *tv = n->key; + } + } else { + GCobj *o = gcV(&n->key); + setgcref(((GCRef *)kptr)[~kidx], o); + lj_gc_objbarrier(fs->L, pt, o); + if (tvisproto(&n->key)) + fs_fixup_uv2(fs, gco2pt(o)); + } + } + } +} + +/* Fixup upvalues for prototype, step #1. */ +static void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv) +{ + setmref(pt->uv, uv); + pt->sizeuv = fs->nuv; + memcpy(uv, fs->uvtmp, fs->nuv*sizeof(VarIndex)); +} + +#ifndef LUAJIT_DISABLE_DEBUGINFO +/* Prepare lineinfo for prototype. */ +static size_t fs_prep_line(FuncState *fs, BCLine numline) +{ + return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2); +} + +/* Fixup lineinfo for prototype. */ +static void fs_fixup_line(FuncState *fs, GCproto *pt, + void *lineinfo, BCLine numline) +{ + BCInsLine *base = fs->bcbase + 1; + BCLine first = fs->linedefined; + MSize i = 0, n = fs->pc-1; + pt->firstline = fs->linedefined; + pt->numline = numline; + setmref(pt->lineinfo, lineinfo); + if (LJ_LIKELY(numline < 256)) { + uint8_t *li = (uint8_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0 && delta < 256); + li[i] = (uint8_t)delta; + } while (++i < n); + } else if (LJ_LIKELY(numline < 65536)) { + uint16_t *li = (uint16_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0 && delta < 65536); + li[i] = (uint16_t)delta; + } while (++i < n); + } else { + uint32_t *li = (uint32_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0); + li[i] = (uint32_t)delta; + } while (++i < n); + } +} + +/* Resize buffer if needed. */ +static LJ_NOINLINE void fs_buf_resize(LexState *ls, MSize len) +{ + MSize sz = ls->sb.sz * 2; + while (ls->sb.n + len > sz) sz = sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, sz); +} + +static LJ_AINLINE void fs_buf_need(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->sb.n + len > ls->sb.sz)) + fs_buf_resize(ls, len); +} + +/* Add string to buffer. */ +static void fs_buf_str(LexState *ls, const char *str, MSize len) +{ + char *p = ls->sb.buf + ls->sb.n; + MSize i; + ls->sb.n += len; + for (i = 0; i < len; i++) p[i] = str[i]; +} + +/* Add ULEB128 value to buffer. */ +static void fs_buf_uleb128(LexState *ls, uint32_t v) +{ + MSize n = ls->sb.n; + uint8_t *p = (uint8_t *)ls->sb.buf; + for (; v >= 0x80; v >>= 7) + p[n++] = (uint8_t)((v & 0x7f) | 0x80); + p[n++] = (uint8_t)v; + ls->sb.n = n; +} + +/* Prepare variable info for prototype. */ +static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar) +{ + VarInfo *vs =ls->vstack, *ve; + MSize i, n; + BCPos lastpc; + lj_str_resetbuf(&ls->sb); /* Copy to temp. string buffer. */ + /* Store upvalue names. */ + for (i = 0, n = fs->nuv; i < n; i++) { + GCstr *s = strref(vs[fs->uvmap[i]].name); + MSize len = s->len+1; + fs_buf_need(ls, len); + fs_buf_str(ls, strdata(s), len); + } + *ofsvar = ls->sb.n; + lastpc = 0; + /* Store local variable names and compressed ranges. */ + for (ve = vs + ls->vtop, vs += fs->vbase; vs < ve; vs++) { + if (!gola_isgotolabel(vs)) { + GCstr *s = strref(vs->name); + BCPos startpc; + if ((uintptr_t)s < VARNAME__MAX) { + fs_buf_need(ls, 1 + 2*5); + ls->sb.buf[ls->sb.n++] = (uint8_t)(uintptr_t)s; + } else { + MSize len = s->len+1; + fs_buf_need(ls, len + 2*5); + fs_buf_str(ls, strdata(s), len); + } + startpc = vs->startpc; + fs_buf_uleb128(ls, startpc-lastpc); + fs_buf_uleb128(ls, vs->endpc-startpc); + lastpc = startpc; + } + } + fs_buf_need(ls, 1); + ls->sb.buf[ls->sb.n++] = '\0'; /* Terminator for varinfo. */ + return ls->sb.n; +} + +/* Fixup variable info for prototype. */ +static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar) +{ + setmref(pt->uvinfo, p); + setmref(pt->varinfo, (char *)p + ofsvar); + memcpy(p, ls->sb.buf, ls->sb.n); /* Copy from temp. string buffer. */ +} +#else + +/* Initialize with empty debug info, if disabled. */ +#define fs_prep_line(fs, numline) (UNUSED(numline), 0) +#define fs_fixup_line(fs, pt, li, numline) \ + pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL) +#define fs_prep_var(ls, fs, ofsvar) (UNUSED(ofsvar), 0) +#define fs_fixup_var(ls, pt, p, ofsvar) \ + setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL) + +#endif + +/* Check if bytecode op returns. */ +static int bcopisret(BCOp op) +{ + switch (op) { + case BC_CALLMT: case BC_CALLT: + case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1: + return 1; + default: + return 0; + } +} + +/* Fixup return instruction for prototype. */ +static void fs_fixup_ret(FuncState *fs) +{ + BCPos lastpc = fs->pc; + if (lastpc <= fs->lasttarget || !bcopisret(bc_op(fs->bcbase[lastpc-1].ins))) { + if ((fs->bl->flags & FSCOPE_UPVAL)) + bcemit_AJ(fs, BC_UCLO, 0, 0); + bcemit_AD(fs, BC_RET0, 0, 1); /* Need final return. */ + } + fs->bl->flags |= FSCOPE_NOCLOSE; /* Handled above. */ + fscope_end(fs); + lua_assert(fs->bl == NULL); + /* May need to fixup returns encoded before first function was created. */ + if (fs->flags & PROTO_FIXUP_RETURN) { + BCPos pc; + for (pc = 1; pc < lastpc; pc++) { + BCIns ins = fs->bcbase[pc].ins; + BCPos offset; + switch (bc_op(ins)) { + case BC_CALLMT: case BC_CALLT: + case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1: + offset = bcemit_INS(fs, ins); /* Copy original instruction. */ + fs->bcbase[offset].line = fs->bcbase[pc].line; + offset = offset-(pc+1)+BCBIAS_J; + if (offset > BCMAX_D) + err_syntax(fs->ls, LJ_ERR_XFIXUP); + /* Replace with UCLO plus branch. */ + fs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset); + break; + case BC_UCLO: + return; /* We're done. */ + default: + break; + } + } + } +} + +/* Finish a FuncState and return the new prototype. */ +static GCproto *fs_finish(LexState *ls, BCLine line) +{ + lua_State *L = ls->L; + FuncState *fs = ls->fs; + BCLine numline = line - fs->linedefined; + size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar; + GCproto *pt; + + /* Apply final fixups. */ + fs_fixup_ret(fs); + + /* Calculate total size of prototype including all colocated arrays. */ + sizept = sizeof(GCproto) + fs->pc*sizeof(BCIns) + fs->nkgc*sizeof(GCRef); + sizept = (sizept + sizeof(TValue)-1) & ~(sizeof(TValue)-1); + ofsk = sizept; sizept += fs->nkn*sizeof(TValue); + ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2; + ofsli = sizept; sizept += fs_prep_line(fs, numline); + ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar); + + /* Allocate prototype and initialize its fields. */ + pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept); + pt->gct = ~LJ_TPROTO; + pt->sizept = (MSize)sizept; + pt->trace = 0; + pt->flags = (uint8_t)(fs->flags & ~(PROTO_HAS_RETURN|PROTO_FIXUP_RETURN)); + pt->numparams = fs->numparams; + pt->framesize = fs->framesize; + setgcref(pt->chunkname, obj2gco(ls->chunkname)); + + /* Close potentially uninitialized gap between bc and kgc. */ + *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(fs->nkgc+1)) = 0; + fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), fs->pc); + fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk)); + fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv)); + fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline); + fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar); + + lj_vmevent_send(L, BC, + setprotoV(L, L->top++, pt); + ); + + L->top--; /* Pop table of constants. */ + ls->vtop = fs->vbase; /* Reset variable stack. */ + ls->fs = fs->prev; + lua_assert(ls->fs != NULL || ls->token == TK_eof); + return pt; +} + +/* Initialize a new FuncState. */ +static void fs_init(LexState *ls, FuncState *fs) +{ + lua_State *L = ls->L; + fs->prev = ls->fs; ls->fs = fs; /* Append to list. */ + fs->ls = ls; + fs->vbase = ls->vtop; + fs->L = L; + fs->pc = 0; + fs->lasttarget = 0; + fs->jpc = NO_JMP; + fs->freereg = 0; + fs->nkgc = 0; + fs->nkn = 0; + fs->nactvar = 0; + fs->nuv = 0; + fs->bl = NULL; + fs->flags = 0; + fs->framesize = 1; /* Minimum frame size. */ + fs->kt = lj_tab_new(L, 0, 0); + /* Anchor table of constants in stack to avoid being collected. */ + settabV(L, L->top, fs->kt); + incr_top(L); +} + +/* -- Expressions --------------------------------------------------------- */ + +/* Forward declaration. */ +static void expr(LexState *ls, ExpDesc *v); + +/* Return string expression. */ +static void expr_str(LexState *ls, ExpDesc *e) +{ + expr_init(e, VKSTR, 0); + e->u.sval = lex_str(ls); +} + +/* Return index expression. */ +static void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e) +{ + /* Already called: expr_toval(fs, e). */ + t->k = VINDEXED; + if (expr_isnumk(e)) { +#if LJ_DUALNUM + if (tvisint(expr_numtv(e))) { + int32_t k = intV(expr_numtv(e)); + if (checku8(k)) { + t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ + return; + } + } +#else + lua_Number n = expr_numberV(e); + int32_t k = lj_num2int(n); + if (checku8(k) && n == (lua_Number)k) { + t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ + return; + } +#endif + } else if (expr_isstrk(e)) { + BCReg idx = const_str(fs, e); + if (idx <= BCMAX_C) { + t->u.s.aux = ~idx; /* -256..-1: const string key */ + return; + } + } + t->u.s.aux = expr_toanyreg(fs, e); /* 0..255: register */ +} + +/* Parse index expression with named field. */ +static void expr_field(LexState *ls, ExpDesc *v) +{ + FuncState *fs = ls->fs; + ExpDesc key; + expr_toanyreg(fs, v); + lj_lex_next(ls); /* Skip dot or colon. */ + expr_str(ls, &key); + expr_index(fs, v, &key); +} + +/* Parse index expression with brackets. */ +static void expr_bracket(LexState *ls, ExpDesc *v) +{ + lj_lex_next(ls); /* Skip '['. */ + expr(ls, v); + expr_toval(ls->fs, v); + lex_check(ls, ']'); +} + +/* Get value of constant expression. */ +static void expr_kvalue(TValue *v, ExpDesc *e) +{ + if (e->k <= VKTRUE) { + setitype(v, ~(uint32_t)e->k); + } else if (e->k == VKSTR) { + setgcref(v->gcr, obj2gco(e->u.sval)); + setitype(v, LJ_TSTR); + } else { + lua_assert(tvisnumber(expr_numtv(e))); + *v = *expr_numtv(e); + } +} + +/* Parse table constructor expression. */ +static void expr_table(LexState *ls, ExpDesc *e) +{ + FuncState *fs = ls->fs; + BCLine line = ls->linenumber; + GCtab *t = NULL; + int vcall = 0, needarr = 0, fixt = 0; + uint32_t narr = 1; /* First array index. */ + uint32_t nhash = 0; /* Number of hash entries. */ + BCReg freg = fs->freereg; + BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0); + expr_init(e, VNONRELOC, freg); + bcreg_reserve(fs, 1); + freg++; + lex_check(ls, '{'); + while (ls->token != '}') { + ExpDesc key, val; + vcall = 0; + if (ls->token == '[') { + expr_bracket(ls, &key); /* Already calls expr_toval. */ + if (!expr_isk(&key)) expr_index(fs, e, &key); + if (expr_isnumk(&key) && expr_numiszero(&key)) needarr = 1; else nhash++; + lex_check(ls, '='); + } else if ((ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) && + lj_lex_lookahead(ls) == '=') { + expr_str(ls, &key); + lex_check(ls, '='); + nhash++; + } else { + expr_init(&key, VKNUM, 0); + setintV(&key.u.nval, (int)narr); + narr++; + needarr = vcall = 1; + } + expr(ls, &val); + if (expr_isk(&key) && key.k != VKNIL && + (key.k == VKSTR || expr_isk_nojump(&val))) { + TValue k, *v; + if (!t) { /* Create template table on demand. */ + BCReg kidx; + t = lj_tab_new(fs->L, needarr ? narr : 0, hsize2hbits(nhash)); + kidx = const_gc(fs, obj2gco(t), LJ_TTAB); + fs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx); + } + vcall = 0; + expr_kvalue(&k, &key); + v = lj_tab_set(fs->L, t, &k); + lj_gc_anybarriert(fs->L, t); + if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */ + expr_kvalue(v, &val); + } else { /* Otherwise create dummy string key (avoids lj_tab_newkey). */ + settabV(fs->L, v, t); /* Preserve key with table itself as value. */ + fixt = 1; /* Fix this later, after all resizes. */ + goto nonconst; + } + } else { + nonconst: + if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; } + if (expr_isk(&key)) expr_index(fs, e, &key); + bcemit_store(fs, e, &val); + } + fs->freereg = freg; + if (!lex_opt(ls, ',') && !lex_opt(ls, ';')) break; + } + lex_match(ls, '}', '{', line); + if (vcall) { + BCInsLine *ilp = &fs->bcbase[fs->pc-1]; + ExpDesc en; + lua_assert(bc_a(ilp->ins) == freg && + bc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB)); + expr_init(&en, VKNUM, 0); + en.u.nval.u32.lo = narr-1; + en.u.nval.u32.hi = 0x43300000; /* Biased integer to avoid denormals. */ + if (narr > 256) { fs->pc--; ilp--; } + ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en)); + setbc_b(&ilp[-1].ins, 0); + } + if (pc == fs->pc-1) { /* Make expr relocable if possible. */ + e->u.s.info = pc; + fs->freereg--; + e->k = VRELOCABLE; + } else { + e->k = VNONRELOC; /* May have been changed by expr_index. */ + } + if (!t) { /* Construct TNEW RD: hhhhhaaaaaaaaaaa. */ + BCIns *ip = &fs->bcbase[pc].ins; + if (!needarr) narr = 0; + else if (narr < 3) narr = 3; + else if (narr > 0x7ff) narr = 0x7ff; + setbc_d(ip, narr|(hsize2hbits(nhash)<<11)); + } else { + if (needarr && t->asize < narr) + lj_tab_reasize(fs->L, t, narr-1); + if (fixt) { /* Fix value for dummy keys in template table. */ + Node *node = noderef(t->node); + uint32_t i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (tvistab(&n->val)) { + lua_assert(tabV(&n->val) == t); + setnilV(&n->val); /* Turn value into nil. */ + } + } + } + lj_gc_check(fs->L); + } +} + +/* Parse function parameters. */ +static BCReg parse_params(LexState *ls, int needself) +{ + FuncState *fs = ls->fs; + BCReg nparams = 0; + lex_check(ls, '('); + if (needself) + var_new_lit(ls, nparams++, "self"); + if (ls->token != ')') { + do { + if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) { + var_new(ls, nparams++, lex_str(ls)); + } else if (ls->token == TK_dots) { + lj_lex_next(ls); + fs->flags |= PROTO_VARARG; + break; + } else { + err_syntax(ls, LJ_ERR_XPARAM); + } + } while (lex_opt(ls, ',')); + } + var_add(ls, nparams); + lua_assert(fs->nactvar == nparams); + bcreg_reserve(fs, nparams); + lex_check(ls, ')'); + return nparams; +} + +/* Forward declaration. */ +static void parse_chunk(LexState *ls); + +/* Parse body of a function. */ +static void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line) +{ + FuncState fs, *pfs = ls->fs; + FuncScope bl; + GCproto *pt; + ptrdiff_t oldbase = pfs->bcbase - ls->bcstack; + fs_init(ls, &fs); + fscope_begin(&fs, &bl, 0); + fs.linedefined = line; + fs.numparams = (uint8_t)parse_params(ls, needself); + fs.bcbase = pfs->bcbase + pfs->pc; + fs.bclim = pfs->bclim - pfs->pc; + bcemit_AD(&fs, BC_FUNCF, 0, 0); /* Placeholder. */ + parse_chunk(ls); + if (ls->token != TK_end) lex_match(ls, TK_end, TK_function, line); + pt = fs_finish(ls, (ls->lastline = ls->linenumber)); + pfs->bcbase = ls->bcstack + oldbase; /* May have been reallocated. */ + pfs->bclim = (BCPos)(ls->sizebcstack - oldbase); + /* Store new prototype in the constant array of the parent. */ + expr_init(e, VRELOCABLE, + bcemit_AD(pfs, BC_FNEW, 0, const_gc(pfs, obj2gco(pt), LJ_TPROTO))); +#if LJ_HASFFI + pfs->flags |= (fs.flags & PROTO_FFI); +#endif + if (!(pfs->flags & PROTO_CHILD)) { + if (pfs->flags & PROTO_HAS_RETURN) + pfs->flags |= PROTO_FIXUP_RETURN; + pfs->flags |= PROTO_CHILD; + } + lj_lex_next(ls); +} + +/* Parse expression list. Last expression is left open. */ +static BCReg expr_list(LexState *ls, ExpDesc *v) +{ + BCReg n = 1; + expr(ls, v); + while (lex_opt(ls, ',')) { + expr_tonextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + +/* Parse function argument list. */ +static void parse_args(LexState *ls, ExpDesc *e) +{ + FuncState *fs = ls->fs; + ExpDesc args; + BCIns ins; + BCReg base; + BCLine line = ls->linenumber; + if (ls->token == '(') { +#if !LJ_52 + if (line != ls->lastline) + err_syntax(ls, LJ_ERR_XAMBIG); +#endif + lj_lex_next(ls); + if (ls->token == ')') { /* f(). */ + args.k = VVOID; + } else { + expr_list(ls, &args); + if (args.k == VCALL) /* f(a, b, g()) or f(a, b, ...). */ + setbc_b(bcptr(fs, &args), 0); /* Pass on multiple results. */ + } + lex_match(ls, ')', '(', line); + } else if (ls->token == '{') { + expr_table(ls, &args); + } else if (ls->token == TK_string) { + expr_init(&args, VKSTR, 0); + args.u.sval = strV(&ls->tokenval); + lj_lex_next(ls); + } else { + err_syntax(ls, LJ_ERR_XFUNARG); + return; /* Silence compiler. */ + } + lua_assert(e->k == VNONRELOC); + base = e->u.s.info; /* Base register for call. */ + if (args.k == VCALL) { + ins = BCINS_ABC(BC_CALLM, base, 2, args.u.s.aux - base - 1); + } else { + if (args.k != VVOID) + expr_tonextreg(fs, &args); + ins = BCINS_ABC(BC_CALL, base, 2, fs->freereg - base); + } + expr_init(e, VCALL, bcemit_INS(fs, ins)); + e->u.s.aux = base; + fs->bcbase[fs->pc - 1].line = line; + fs->freereg = base+1; /* Leave one result by default. */ +} + +/* Parse primary expression. */ +static void expr_primary(LexState *ls, ExpDesc *v) +{ + FuncState *fs = ls->fs; + /* Parse prefix expression. */ + if (ls->token == '(') { + BCLine line = ls->linenumber; + lj_lex_next(ls); + expr(ls, v); + lex_match(ls, ')', '(', line); + expr_discharge(ls->fs, v); + } else if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) { + var_lookup(ls, v); + } else { + err_syntax(ls, LJ_ERR_XSYMBOL); + } + for (;;) { /* Parse multiple expression suffixes. */ + if (ls->token == '.') { + expr_field(ls, v); + } else if (ls->token == '[') { + ExpDesc key; + expr_toanyreg(fs, v); + expr_bracket(ls, &key); + expr_index(fs, v, &key); + } else if (ls->token == ':') { + ExpDesc key; + lj_lex_next(ls); + expr_str(ls, &key); + bcemit_method(fs, v, &key); + parse_args(ls, v); + } else if (ls->token == '(' || ls->token == TK_string || ls->token == '{') { + expr_tonextreg(fs, v); + parse_args(ls, v); + } else { + break; + } + } +} + +/* Parse simple expression. */ +static void expr_simple(LexState *ls, ExpDesc *v) +{ + switch (ls->token) { + case TK_number: + expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokenval)) ? VKCDATA : VKNUM, 0); + copyTV(ls->L, &v->u.nval, &ls->tokenval); + break; + case TK_string: + expr_init(v, VKSTR, 0); + v->u.sval = strV(&ls->tokenval); + break; + case TK_nil: + expr_init(v, VKNIL, 0); + break; + case TK_true: + expr_init(v, VKTRUE, 0); + break; + case TK_false: + expr_init(v, VKFALSE, 0); + break; + case TK_dots: { /* Vararg. */ + FuncState *fs = ls->fs; + BCReg base; + checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS); + bcreg_reserve(fs, 1); + base = fs->freereg-1; + expr_init(v, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams)); + v->u.s.aux = base; + break; + } + case '{': /* Table constructor. */ + expr_table(ls, v); + return; + case TK_function: + lj_lex_next(ls); + parse_body(ls, v, 0, ls->linenumber); + return; + default: + expr_primary(ls, v); + return; + } + lj_lex_next(ls); +} + +/* Manage syntactic levels to avoid blowing up the stack. */ +static void synlevel_begin(LexState *ls) +{ + if (++ls->level >= LJ_MAX_XLEVEL) + lj_lex_error(ls, 0, LJ_ERR_XLEVELS); +} + +#define synlevel_end(ls) ((ls)->level--) + +/* Convert token to binary operator. */ +static BinOpr token2binop(LexToken tok) +{ + switch (tok) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_concat: return OPR_CONCAT; + case TK_ne: return OPR_NE; + case TK_eq: return OPR_EQ; + case '<': return OPR_LT; + case TK_le: return OPR_LE; + case '>': return OPR_GT; + case TK_ge: return OPR_GE; + case TK_and: return OPR_AND; + case TK_or: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + +/* Priorities for each binary operator. ORDER OPR. */ +static const struct { + uint8_t left; /* Left priority. */ + uint8_t right; /* Right priority. */ +} priority[] = { + {6,6}, {6,6}, {7,7}, {7,7}, {7,7}, /* ADD SUB MUL DIV MOD */ + {10,9}, {5,4}, /* POW CONCAT (right associative) */ + {3,3}, {3,3}, /* EQ NE */ + {3,3}, {3,3}, {3,3}, {3,3}, /* LT GE GT LE */ + {2,2}, {1,1} /* AND OR */ +}; + +#define UNARY_PRIORITY 8 /* Priority for unary operators. */ + +/* Forward declaration. */ +static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit); + +/* Parse unary expression. */ +static void expr_unop(LexState *ls, ExpDesc *v) +{ + BCOp op; + if (ls->token == TK_not) { + op = BC_NOT; + } else if (ls->token == '-') { + op = BC_UNM; + } else if (ls->token == '#') { + op = BC_LEN; + } else { + expr_simple(ls, v); + return; + } + lj_lex_next(ls); + expr_binop(ls, v, UNARY_PRIORITY); + bcemit_unop(ls->fs, op, v); +} + +/* Parse binary expressions with priority higher than the limit. */ +static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit) +{ + BinOpr op; + synlevel_begin(ls); + expr_unop(ls, v); + op = token2binop(ls->token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + ExpDesc v2; + BinOpr nextop; + lj_lex_next(ls); + bcemit_binop_left(ls->fs, op, v); + /* Parse binary expression with higher priority. */ + nextop = expr_binop(ls, &v2, priority[op].right); + bcemit_binop(ls->fs, op, v, &v2); + op = nextop; + } + synlevel_end(ls); + return op; /* Return unconsumed binary operator (if any). */ +} + +/* Parse expression. */ +static void expr(LexState *ls, ExpDesc *v) +{ + expr_binop(ls, v, 0); /* Priority 0: parse whole expression. */ +} + +/* Assign expression to the next register. */ +static void expr_next(LexState *ls) +{ + ExpDesc e; + expr(ls, &e); + expr_tonextreg(ls->fs, &e); +} + +/* Parse conditional expression. */ +static BCPos expr_cond(LexState *ls) +{ + ExpDesc v; + expr(ls, &v); + if (v.k == VKNIL) v.k = VKFALSE; + bcemit_branch_t(ls->fs, &v); + return v.f; +} + +/* -- Assignments --------------------------------------------------------- */ + +/* List of LHS variables. */ +typedef struct LHSVarList { + ExpDesc v; /* LHS variable. */ + struct LHSVarList *prev; /* Link to previous LHS variable. */ +} LHSVarList; + +/* Eliminate write-after-read hazards for local variable assignment. */ +static void assign_hazard(LexState *ls, LHSVarList *lh, const ExpDesc *v) +{ + FuncState *fs = ls->fs; + BCReg reg = v->u.s.info; /* Check against this variable. */ + BCReg tmp = fs->freereg; /* Rename to this temp. register (if needed). */ + int hazard = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == reg) { /* t[i], t = 1, 2 */ + hazard = 1; + lh->v.u.s.info = tmp; + } + if (lh->v.u.s.aux == reg) { /* t[i], i = 1, 2 */ + hazard = 1; + lh->v.u.s.aux = tmp; + } + } + } + if (hazard) { + bcemit_AD(fs, BC_MOV, tmp, reg); /* Rename conflicting variable. */ + bcreg_reserve(fs, 1); + } +} + +/* Adjust LHS/RHS of an assignment. */ +static void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e) +{ + FuncState *fs = ls->fs; + int32_t extra = (int32_t)nvars - (int32_t)nexps; + if (e->k == VCALL) { + extra++; /* Compensate for the VCALL itself. */ + if (extra < 0) extra = 0; + setbc_b(bcptr(fs, e), extra+1); /* Fixup call results. */ + if (extra > 1) bcreg_reserve(fs, (BCReg)extra-1); + } else { + if (e->k != VVOID) + expr_tonextreg(fs, e); /* Close last expression. */ + if (extra > 0) { /* Leftover LHS are set to nil. */ + BCReg reg = fs->freereg; + bcreg_reserve(fs, (BCReg)extra); + bcemit_nil(fs, reg, (BCReg)extra); + } + } +} + +/* Recursively parse assignment statement. */ +static void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars) +{ + ExpDesc e; + checkcond(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, LJ_ERR_XSYNTAX); + if (lex_opt(ls, ',')) { /* Collect LHS list and recurse upwards. */ + LHSVarList vl; + vl.prev = lh; + expr_primary(ls, &vl.v); + if (vl.v.k == VLOCAL) + assign_hazard(ls, lh, &vl.v); + checklimit(ls->fs, ls->level + nvars, LJ_MAX_XLEVEL, "variable names"); + parse_assignment(ls, &vl, nvars+1); + } else { /* Parse RHS. */ + BCReg nexps; + lex_check(ls, '='); + nexps = expr_list(ls, &e); + if (nexps == nvars) { + if (e.k == VCALL) { + if (bc_op(*bcptr(ls->fs, &e)) == BC_VARG) { /* Vararg assignment. */ + ls->fs->freereg--; + e.k = VRELOCABLE; + } else { /* Multiple call results. */ + e.u.s.info = e.u.s.aux; /* Base of call is not relocatable. */ + e.k = VNONRELOC; + } + } + bcemit_store(ls->fs, &lh->v, &e); + return; + } + assign_adjust(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* Drop leftover regs. */ + } + /* Assign RHS to LHS and recurse downwards. */ + expr_init(&e, VNONRELOC, ls->fs->freereg-1); + bcemit_store(ls->fs, &lh->v, &e); +} + +/* Parse call statement or assignment. */ +static void parse_call_assign(LexState *ls) +{ + FuncState *fs = ls->fs; + LHSVarList vl; + expr_primary(ls, &vl.v); + if (vl.v.k == VCALL) { /* Function call statement. */ + setbc_b(bcptr(fs, &vl.v), 1); /* No results. */ + } else { /* Start of an assignment. */ + vl.prev = NULL; + parse_assignment(ls, &vl, 1); + } +} + +/* Parse 'local' statement. */ +static void parse_local(LexState *ls) +{ + if (lex_opt(ls, TK_function)) { /* Local function declaration. */ + ExpDesc v, b; + FuncState *fs = ls->fs; + var_new(ls, 0, lex_str(ls)); + expr_init(&v, VLOCAL, fs->freereg); + v.u.s.aux = fs->varmap[fs->freereg]; + bcreg_reserve(fs, 1); + var_add(ls, 1); + parse_body(ls, &b, 0, ls->linenumber); + /* bcemit_store(fs, &v, &b) without setting VSTACK_VAR_RW. */ + expr_free(fs, &b); + expr_toreg(fs, &b, v.u.s.info); + /* The upvalue is in scope, but the local is only valid after the store. */ + var_get(ls, fs, fs->nactvar - 1).startpc = fs->pc; + } else { /* Local variable declaration. */ + ExpDesc e; + BCReg nexps, nvars = 0; + do { /* Collect LHS. */ + var_new(ls, nvars++, lex_str(ls)); + } while (lex_opt(ls, ',')); + if (lex_opt(ls, '=')) { /* Optional RHS. */ + nexps = expr_list(ls, &e); + } else { /* Or implicitly set to nil. */ + e.k = VVOID; + nexps = 0; + } + assign_adjust(ls, nvars, nexps, &e); + var_add(ls, nvars); + } +} + +/* Parse 'function' statement. */ +static void parse_func(LexState *ls, BCLine line) +{ + FuncState *fs; + ExpDesc v, b; + int needself = 0; + lj_lex_next(ls); /* Skip 'function'. */ + /* Parse function name. */ + var_lookup(ls, &v); + while (ls->token == '.') /* Multiple dot-separated fields. */ + expr_field(ls, &v); + if (ls->token == ':') { /* Optional colon to signify method call. */ + needself = 1; + expr_field(ls, &v); + } + parse_body(ls, &b, needself, line); + fs = ls->fs; + bcemit_store(fs, &v, &b); + fs->bcbase[fs->pc - 1].line = line; /* Set line for the store. */ +} + +/* -- Control transfer statements ----------------------------------------- */ + +/* Check for end of block. */ +static int endofblock(LexToken token) +{ + switch (token) { + case TK_else: case TK_elseif: case TK_end: case TK_until: case TK_eof: + return 1; + default: + return 0; + } +} + +/* Parse 'return' statement. */ +static void parse_return(LexState *ls) +{ + BCIns ins; + FuncState *fs = ls->fs; + lj_lex_next(ls); /* Skip 'return'. */ + fs->flags |= PROTO_HAS_RETURN; + if (endofblock(ls->token) || ls->token == ';') { /* Bare return. */ + ins = BCINS_AD(BC_RET0, 0, 1); + } else { /* Return with one or more values. */ + ExpDesc e; /* Receives the _last_ expression in the list. */ + BCReg nret = expr_list(ls, &e); + if (nret == 1) { /* Return one result. */ + if (e.k == VCALL) { /* Check for tail call. */ + BCIns *ip = bcptr(fs, &e); + /* It doesn't pay off to add BC_VARGT just for 'return ...'. */ + if (bc_op(*ip) == BC_VARG) goto notailcall; + fs->pc--; + ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip)); + } else { /* Can return the result from any register. */ + ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2); + } + } else { + if (e.k == VCALL) { /* Append all results from a call. */ + notailcall: + setbc_b(bcptr(fs, &e), 0); + ins = BCINS_AD(BC_RETM, fs->nactvar, e.u.s.aux - fs->nactvar); + } else { + expr_tonextreg(fs, &e); /* Force contiguous registers. */ + ins = BCINS_AD(BC_RET, fs->nactvar, nret+1); + } + } + } + if (fs->flags & PROTO_CHILD) + bcemit_AJ(fs, BC_UCLO, 0, 0); /* May need to close upvalues first. */ + bcemit_INS(fs, ins); +} + +/* Parse 'break' statement. */ +static void parse_break(LexState *ls) +{ + ls->fs->bl->flags |= FSCOPE_BREAK; + gola_new(ls, NAME_BREAK, VSTACK_GOTO, bcemit_jmp(ls->fs)); +} + +/* Parse 'goto' statement. */ +static void parse_goto(LexState *ls) +{ + FuncState *fs = ls->fs; + GCstr *name = lex_str(ls); + VarInfo *vl = gola_findlabel(ls, name); + if (vl) /* Treat backwards goto within same scope like a loop. */ + bcemit_AJ(fs, BC_LOOP, vl->slot, -1); /* No BC range check. */ + fs->bl->flags |= FSCOPE_GOLA; + gola_new(ls, name, VSTACK_GOTO, bcemit_jmp(fs)); +} + +/* Parse label. */ +static void parse_label(LexState *ls) +{ + FuncState *fs = ls->fs; + GCstr *name; + MSize idx; + fs->lasttarget = fs->pc; + fs->bl->flags |= FSCOPE_GOLA; + lj_lex_next(ls); /* Skip '::'. */ + name = lex_str(ls); + if (gola_findlabel(ls, name)) + lj_lex_error(ls, 0, LJ_ERR_XLDUP, strdata(name)); + idx = gola_new(ls, name, VSTACK_LABEL, fs->pc); + lex_check(ls, TK_label); + /* Recursively parse trailing statements: labels and ';' (Lua 5.2 only). */ + for (;;) { + if (ls->token == TK_label) { + synlevel_begin(ls); + parse_label(ls); + synlevel_end(ls); + } else if (LJ_52 && ls->token == ';') { + lj_lex_next(ls); + } else { + break; + } + } + /* Trailing label is considered to be outside of scope. */ + if (endofblock(ls->token) && ls->token != TK_until) + ls->vstack[idx].slot = fs->bl->nactvar; + gola_resolve(ls, fs->bl, idx); +} + +/* -- Blocks, loops and conditional statements ---------------------------- */ + +/* Parse a block. */ +static void parse_block(LexState *ls) +{ + FuncState *fs = ls->fs; + FuncScope bl; + fscope_begin(fs, &bl, 0); + parse_chunk(ls); + fscope_end(fs); +} + +/* Parse 'while' statement. */ +static void parse_while(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos start, loop, condexit; + FuncScope bl; + lj_lex_next(ls); /* Skip 'while'. */ + start = fs->lasttarget = fs->pc; + condexit = expr_cond(ls); + fscope_begin(fs, &bl, FSCOPE_LOOP); + lex_check(ls, TK_do); + loop = bcemit_AD(fs, BC_LOOP, fs->nactvar, 0); + parse_block(ls); + jmp_patch(fs, bcemit_jmp(fs), start); + lex_match(ls, TK_end, TK_while, line); + fscope_end(fs); + jmp_tohere(fs, condexit); + jmp_patchins(fs, loop, fs->pc); +} + +/* Parse 'repeat' statement. */ +static void parse_repeat(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos loop = fs->lasttarget = fs->pc; + BCPos condexit; + FuncScope bl1, bl2; + fscope_begin(fs, &bl1, FSCOPE_LOOP); /* Breakable loop scope. */ + fscope_begin(fs, &bl2, 0); /* Inner scope. */ + lj_lex_next(ls); /* Skip 'repeat'. */ + bcemit_AD(fs, BC_LOOP, fs->nactvar, 0); + parse_chunk(ls); + lex_match(ls, TK_until, TK_repeat, line); + condexit = expr_cond(ls); /* Parse condition (still inside inner scope). */ + if (!(bl2.flags & FSCOPE_UPVAL)) { /* No upvalues? Just end inner scope. */ + fscope_end(fs); + } else { /* Otherwise generate: cond: UCLO+JMP out, !cond: UCLO+JMP loop. */ + parse_break(ls); /* Break from loop and close upvalues. */ + jmp_tohere(fs, condexit); + fscope_end(fs); /* End inner scope and close upvalues. */ + condexit = bcemit_jmp(fs); + } + jmp_patch(fs, condexit, loop); /* Jump backwards if !cond. */ + jmp_patchins(fs, loop, fs->pc); + fscope_end(fs); /* End loop scope. */ +} + +/* Parse numeric 'for'. */ +static void parse_for_num(LexState *ls, GCstr *varname, BCLine line) +{ + FuncState *fs = ls->fs; + BCReg base = fs->freereg; + FuncScope bl; + BCPos loop, loopend; + /* Hidden control variables. */ + var_new_fixed(ls, FORL_IDX, VARNAME_FOR_IDX); + var_new_fixed(ls, FORL_STOP, VARNAME_FOR_STOP); + var_new_fixed(ls, FORL_STEP, VARNAME_FOR_STEP); + /* Visible copy of index variable. */ + var_new(ls, FORL_EXT, varname); + lex_check(ls, '='); + expr_next(ls); + lex_check(ls, ','); + expr_next(ls); + if (lex_opt(ls, ',')) { + expr_next(ls); + } else { + bcemit_AD(fs, BC_KSHORT, fs->freereg, 1); /* Default step is 1. */ + bcreg_reserve(fs, 1); + } + var_add(ls, 3); /* Hidden control variables. */ + lex_check(ls, TK_do); + loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP); + fscope_begin(fs, &bl, 0); /* Scope for visible variables. */ + var_add(ls, 1); + bcreg_reserve(fs, 1); + parse_block(ls); + fscope_end(fs); + /* Perform loop inversion. Loop control instructions are at the end. */ + loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP); + fs->bcbase[loopend].line = line; /* Fix line for control ins. */ + jmp_patchins(fs, loopend, loop+1); + jmp_patchins(fs, loop, fs->pc); +} + +/* Try to predict whether the iterator is next() and specialize the bytecode. +** Detecting next() and pairs() by name is simplistic, but quite effective. +** The interpreter backs off if the check for the closure fails at runtime. +*/ +static int predict_next(LexState *ls, FuncState *fs, BCPos pc) +{ + BCIns ins = fs->bcbase[pc].ins; + GCstr *name; + cTValue *o; + switch (bc_op(ins)) { + case BC_MOV: + name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name)); + break; + case BC_UGET: + name = gco2str(gcref(ls->vstack[fs->uvmap[bc_d(ins)]].name)); + break; + case BC_GGET: + /* There's no inverse index (yet), so lookup the strings. */ + o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "pairs")); + if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins)) + return 1; + o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "next")); + if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins)) + return 1; + return 0; + default: + return 0; + } + return (name->len == 5 && !strcmp(strdata(name), "pairs")) || + (name->len == 4 && !strcmp(strdata(name), "next")); +} + +/* Parse 'for' iterator. */ +static void parse_for_iter(LexState *ls, GCstr *indexname) +{ + FuncState *fs = ls->fs; + ExpDesc e; + BCReg nvars = 0; + BCLine line; + BCReg base = fs->freereg + 3; + BCPos loop, loopend, exprpc = fs->pc; + FuncScope bl; + int isnext; + /* Hidden control variables. */ + var_new_fixed(ls, nvars++, VARNAME_FOR_GEN); + var_new_fixed(ls, nvars++, VARNAME_FOR_STATE); + var_new_fixed(ls, nvars++, VARNAME_FOR_CTL); + /* Visible variables returned from iterator. */ + var_new(ls, nvars++, indexname); + while (lex_opt(ls, ',')) + var_new(ls, nvars++, lex_str(ls)); + lex_check(ls, TK_in); + line = ls->linenumber; + assign_adjust(ls, 3, expr_list(ls, &e), &e); + bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */ + isnext = (nvars <= 5 && predict_next(ls, fs, exprpc)); + var_add(ls, 3); /* Hidden control variables. */ + lex_check(ls, TK_do); + loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP); + fscope_begin(fs, &bl, 0); /* Scope for visible variables. */ + var_add(ls, nvars-3); + bcreg_reserve(fs, nvars-3); + parse_block(ls); + fscope_end(fs); + /* Perform loop inversion. Loop control instructions are at the end. */ + jmp_patchins(fs, loop, fs->pc); + bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1); + loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP); + fs->bcbase[loopend-1].line = line; /* Fix line for control ins. */ + fs->bcbase[loopend].line = line; + jmp_patchins(fs, loopend, loop+1); +} + +/* Parse 'for' statement. */ +static void parse_for(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + GCstr *varname; + FuncScope bl; + fscope_begin(fs, &bl, FSCOPE_LOOP); + lj_lex_next(ls); /* Skip 'for'. */ + varname = lex_str(ls); /* Get first variable name. */ + if (ls->token == '=') + parse_for_num(ls, varname, line); + else if (ls->token == ',' || ls->token == TK_in) + parse_for_iter(ls, varname); + else + err_syntax(ls, LJ_ERR_XFOR); + lex_match(ls, TK_end, TK_for, line); + fscope_end(fs); /* Resolve break list. */ +} + +/* Parse condition and 'then' block. */ +static BCPos parse_then(LexState *ls) +{ + BCPos condexit; + lj_lex_next(ls); /* Skip 'if' or 'elseif'. */ + condexit = expr_cond(ls); + lex_check(ls, TK_then); + parse_block(ls); + return condexit; +} + +/* Parse 'if' statement. */ +static void parse_if(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos flist; + BCPos escapelist = NO_JMP; + flist = parse_then(ls); + while (ls->token == TK_elseif) { /* Parse multiple 'elseif' blocks. */ + jmp_append(fs, &escapelist, bcemit_jmp(fs)); + jmp_tohere(fs, flist); + flist = parse_then(ls); + } + if (ls->token == TK_else) { /* Parse optional 'else' block. */ + jmp_append(fs, &escapelist, bcemit_jmp(fs)); + jmp_tohere(fs, flist); + lj_lex_next(ls); /* Skip 'else'. */ + parse_block(ls); + } else { + jmp_append(fs, &escapelist, flist); + } + jmp_tohere(fs, escapelist); + lex_match(ls, TK_end, TK_if, line); +} + +/* -- Parse statements ---------------------------------------------------- */ + +/* Parse a statement. Returns 1 if it must be the last one in a chunk. */ +static int parse_stmt(LexState *ls) +{ + BCLine line = ls->linenumber; + switch (ls->token) { + case TK_if: + parse_if(ls, line); + break; + case TK_while: + parse_while(ls, line); + break; + case TK_do: + lj_lex_next(ls); + parse_block(ls); + lex_match(ls, TK_end, TK_do, line); + break; + case TK_for: + parse_for(ls, line); + break; + case TK_repeat: + parse_repeat(ls, line); + break; + case TK_function: + parse_func(ls, line); + break; + case TK_local: + lj_lex_next(ls); + parse_local(ls); + break; + case TK_return: + parse_return(ls); + return 1; /* Must be last. */ + case TK_break: + lj_lex_next(ls); + parse_break(ls); + return !LJ_52; /* Must be last in Lua 5.1. */ +#if LJ_52 + case ';': + lj_lex_next(ls); + break; +#endif + case TK_label: + parse_label(ls); + break; + case TK_goto: + if (LJ_52 || lj_lex_lookahead(ls) == TK_name) { + lj_lex_next(ls); + parse_goto(ls); + break; + } /* else: fallthrough */ + default: + parse_call_assign(ls); + break; + } + return 0; +} + +/* A chunk is a list of statements optionally separated by semicolons. */ +static void parse_chunk(LexState *ls) +{ + int islast = 0; + synlevel_begin(ls); + while (!islast && !endofblock(ls->token)) { + islast = parse_stmt(ls); + lex_opt(ls, ';'); + lua_assert(ls->fs->framesize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* Free registers after each stmt. */ + } + synlevel_end(ls); +} + +/* Entry point of bytecode parser. */ +GCproto *lj_parse(LexState *ls) +{ + FuncState fs; + FuncScope bl; + GCproto *pt; + lua_State *L = ls->L; +#ifdef LUAJIT_DISABLE_DEBUGINFO + ls->chunkname = lj_str_newlit(L, "="); +#else + ls->chunkname = lj_str_newz(L, ls->chunkarg); +#endif + setstrV(L, L->top, ls->chunkname); /* Anchor chunkname string. */ + incr_top(L); + ls->level = 0; + fs_init(ls, &fs); + fs.linedefined = 0; + fs.numparams = 0; + fs.bcbase = NULL; + fs.bclim = 0; + fs.flags |= PROTO_VARARG; /* Main chunk is always a vararg func. */ + fscope_begin(&fs, &bl, 0); + bcemit_AD(&fs, BC_FUNCV, 0, 0); /* Placeholder. */ + lj_lex_next(ls); /* Read-ahead first token. */ + parse_chunk(ls); + if (ls->token != TK_eof) + err_token(ls, TK_eof); + pt = fs_finish(ls, ls->linenumber); + L->top--; /* Drop chunkname. */ + lua_assert(fs.prev == NULL); + lua_assert(ls->fs == NULL); + lua_assert(pt->sizeuv == 0); + return pt; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.h new file mode 100644 index 0000000..532657a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_parse.h @@ -0,0 +1,18 @@ +/* +** Lua parser (source code -> bytecode). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_PARSE_H +#define _LJ_PARSE_H + +#include "lj_obj.h" +#include "lj_lex.h" + +LJ_FUNC GCproto *lj_parse(LexState *ls); +LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l); +#if LJ_HASFFI +LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_recdef.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_recdef.h new file mode 100644 index 0000000..d421265 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_recdef.h @@ -0,0 +1,263 @@ +/* This is a generated file. DO NOT EDIT! */ + +static const uint16_t recff_idmap[] = { +0, +0x0100, +0x0200, +0x0300, +0, +0, +0x0400, +0x0500, +0x0600, +0x0700, +0, +0, +0x0800, +0x0900, +0x0a00, +0, +0x0b00, +0x0c00, +0x0d00, +0, +0x0e00, +0x0f00, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0x1000, +0x1100+(IRFPM_FLOOR), +0x1100+(IRFPM_CEIL), +0x1200+(IRFPM_SQRT), +0x1200+(IRFPM_LOG10), +0x1200+(IRFPM_EXP), +0x1200+(IRFPM_SIN), +0x1200+(IRFPM_COS), +0x1200+(IRFPM_TAN), +0x1300+(FF_math_asin), +0x1300+(FF_math_acos), +0x1300+(FF_math_atan), +0x1400+(IRCALL_sinh), +0x1400+(IRCALL_cosh), +0x1400+(IRCALL_tanh), +0, +0x1500, +0x1600, +0x1600, +0x1700, +0x1800, +0x1900, +0, +0x1a00, +0x1b00+(IR_MIN), +0x1b00+(IR_MAX), +0x1c00, +0, +0x1d00+(IR_TOBIT), +0x1d00+(IR_BNOT), +0x1d00+(IR_BSWAP), +0x1e00+(IR_BSHL), +0x1e00+(IR_BSHR), +0x1e00+(IR_BSAR), +0x1e00+(IR_BROL), +0x1e00+(IR_BROR), +0x1f00+(IR_BAND), +0x1f00+(IR_BOR), +0x1f00+(IR_BXOR), +0, +0x2000, +0x2100+(0), +0, +0x2100+(1), +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0x2200, +0, +0x2300, +0x2400, +0, +0, +0, +0, +0x2500+(0), +0x2600+(0), +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0x2500+(GCROOT_IO_OUTPUT), +0x2600+(GCROOT_IO_OUTPUT), +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0x2700+(0), +0x2700+(1), +0x2800+(MM_eq), +0x2800+(MM_len), +0x2800+(MM_lt), +0x2800+(MM_le), +0x2800+(MM_concat), +0x2900, +0x2800+(MM_add), +0x2800+(MM_sub), +0x2800+(MM_mul), +0x2800+(MM_div), +0x2800+(MM_mod), +0x2800+(MM_pow), +0x2800+(MM_unm), +0, +0, +0, +0x2a00+(1), +0x2a00+(0), +0, +0, +0, +0, +0x2b00, +0x2b00, +0x2c00, +0x2d00, +0x2e00+(FF_ffi_sizeof), +0x2e00+(FF_ffi_alignof), +0x2e00+(FF_ffi_offsetof), +0x2f00, +0x3000, +0x3100, +0x3200, +0x3300, +0, +0x3400 +}; + +static const RecordFunc recff_func[] = { +recff_nyi, +recff_c, +recff_assert, +recff_type, +recff_ipairs_aux, +recff_ipairs, +recff_getmetatable, +recff_setmetatable, +recff_rawget, +recff_rawset, +recff_rawequal, +recff_select, +recff_tonumber, +recff_tostring, +recff_pcall, +recff_xpcall, +recff_math_abs, +recff_math_round, +recff_math_unary, +recff_math_atrig, +recff_math_htrig, +recff_math_modf, +recff_math_degrad, +recff_math_log, +recff_math_atan2, +recff_math_pow, +recff_math_ldexp, +recff_math_minmax, +recff_math_random, +recff_bit_unary, +recff_bit_shift, +recff_bit_nary, +recff_string_len, +recff_string_range, +recff_table_getn, +recff_table_insert, +recff_table_remove, +recff_io_write, +recff_io_flush, +recff_cdata_index, +recff_cdata_arith, +recff_cdata_call, +recff_clib_index, +recff_ffi_new, +recff_ffi_typeof, +recff_ffi_istype, +recff_ffi_xof, +recff_ffi_errno, +recff_ffi_string, +recff_ffi_copy, +recff_ffi_fill, +recff_ffi_abi, +recff_ffi_gc +}; + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.c new file mode 100644 index 0000000..c6848fc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.c @@ -0,0 +1,2248 @@ +/* +** Trace recorder (bytecode -> SSA IR). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_record_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_snap.h" +#include "lj_dispatch.h" +#include "lj_vm.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Sanity checks ------------------------------------------------------- */ + +#ifdef LUA_USE_ASSERT +/* Sanity check the whole IR -- sloooow. */ +static void rec_check_ir(jit_State *J) +{ + IRRef i, nins = J->cur.nins, nk = J->cur.nk; + lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536); + for (i = nins-1; i >= nk; i--) { + IRIns *ir = IR(i); + uint32_t mode = lj_ir_mode[ir->o]; + IRRef op1 = ir->op1; + IRRef op2 = ir->op2; + switch (irm_op1(mode)) { + case IRMnone: lua_assert(op1 == 0); break; + case IRMref: lua_assert(op1 >= nk); + lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break; + case IRMlit: break; + case IRMcst: lua_assert(i < REF_BIAS); continue; + } + switch (irm_op2(mode)) { + case IRMnone: lua_assert(op2 == 0); break; + case IRMref: lua_assert(op2 >= nk); + lua_assert(i >= REF_BIAS ? op2 < i : op2 > i); break; + case IRMlit: break; + case IRMcst: lua_assert(0); break; + } + if (ir->prev) { + lua_assert(ir->prev >= nk); + lua_assert(i >= REF_BIAS ? ir->prev < i : ir->prev > i); + lua_assert(ir->o == IR_NOP || IR(ir->prev)->o == ir->o); + } + } +} + +/* Compare stack slots and frames of the recorder and the VM. */ +static void rec_check_slots(jit_State *J) +{ + BCReg s, nslots = J->baseslot + J->maxslot; + int32_t depth = 0; + cTValue *base = J->L->base - J->baseslot; + lua_assert(J->baseslot >= 1 && J->baseslot < LJ_MAX_JSLOTS); + lua_assert(J->baseslot == 1 || (J->slot[J->baseslot-1] & TREF_FRAME)); + lua_assert(nslots < LJ_MAX_JSLOTS); + for (s = 0; s < nslots; s++) { + TRef tr = J->slot[s]; + if (tr) { + cTValue *tv = &base[s]; + IRRef ref = tref_ref(tr); + IRIns *ir; + lua_assert(ref >= J->cur.nk && ref < J->cur.nins); + ir = IR(ref); + lua_assert(irt_t(ir->t) == tref_t(tr)); + if (s == 0) { + lua_assert(tref_isfunc(tr)); + } else if ((tr & TREF_FRAME)) { + GCfunc *fn = gco2func(frame_gc(tv)); + BCReg delta = (BCReg)(tv - frame_prev(tv)); + lua_assert(tref_isfunc(tr)); + if (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir)); + lua_assert(s > delta ? (J->slot[s-delta] & TREF_FRAME) : (s == delta)); + depth++; + } else if ((tr & TREF_CONT)) { + lua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void)); + lua_assert((J->slot[s+1] & TREF_FRAME)); + depth++; + } else { + if (tvisnumber(tv)) + lua_assert(tref_isnumber(tr)); /* Could be IRT_INT etc., too. */ + else + lua_assert(itype2irt(tv) == tref_type(tr)); + if (tref_isk(tr)) { /* Compare constants. */ + TValue tvk; + lj_ir_kvalue(J->L, &tvk, ir); + if (!(tvisnum(&tvk) && tvisnan(&tvk))) + lua_assert(lj_obj_equal(tv, &tvk)); + else + lua_assert(tvisnum(tv) && tvisnan(tv)); + } + } + } + } + lua_assert(J->framedepth == depth); +} +#endif + +/* -- Type handling and specialization ------------------------------------ */ + +/* Note: these functions return tagged references (TRef). */ + +/* Specialize a slot to a specific type. Note: slot can be negative! */ +static TRef sloadt(jit_State *J, int32_t slot, IRType t, int mode) +{ + /* Caller may set IRT_GUARD in t. */ + TRef ref = emitir_raw(IRT(IR_SLOAD, t), (int32_t)J->baseslot+slot, mode); + J->base[slot] = ref; + return ref; +} + +/* Specialize a slot to the runtime type. Note: slot can be negative! */ +static TRef sload(jit_State *J, int32_t slot) +{ + IRType t = itype2irt(&J->L->base[slot]); + TRef ref = emitir_raw(IRTG(IR_SLOAD, t), (int32_t)J->baseslot+slot, + IRSLOAD_TYPECHECK); + if (irtype_ispri(t)) ref = TREF_PRI(t); /* Canonicalize primitive refs. */ + J->base[slot] = ref; + return ref; +} + +/* Get TRef from slot. Load slot and specialize if not done already. */ +#define getslot(J, s) (J->base[(s)] ? J->base[(s)] : sload(J, (int32_t)(s))) + +/* Get TRef for current function. */ +static TRef getcurrf(jit_State *J) +{ + if (J->base[-1]) + return J->base[-1]; + lua_assert(J->baseslot == 1); + return sloadt(J, -1, IRT_FUNC, IRSLOAD_READONLY); +} + +/* Compare for raw object equality. +** Returns 0 if the objects are the same. +** Returns 1 if they are different, but the same type. +** Returns 2 for two different types. +** Comparisons between primitives always return 1 -- no caller cares about it. +*/ +int lj_record_objcmp(jit_State *J, TRef a, TRef b, cTValue *av, cTValue *bv) +{ + int diff = !lj_obj_equal(av, bv); + if (!tref_isk2(a, b)) { /* Shortcut, also handles primitives. */ + IRType ta = tref_isinteger(a) ? IRT_INT : tref_type(a); + IRType tb = tref_isinteger(b) ? IRT_INT : tref_type(b); + if (ta != tb) { + /* Widen mixed number/int comparisons to number/number comparison. */ + if (ta == IRT_INT && tb == IRT_NUM) { + a = emitir(IRTN(IR_CONV), a, IRCONV_NUM_INT); + ta = IRT_NUM; + } else if (ta == IRT_NUM && tb == IRT_INT) { + b = emitir(IRTN(IR_CONV), b, IRCONV_NUM_INT); + } else { + return 2; /* Two different types are never equal. */ + } + } + emitir(IRTG(diff ? IR_NE : IR_EQ, ta), a, b); + } + return diff; +} + +/* Constify a value. Returns 0 for non-representable object types. */ +TRef lj_record_constify(jit_State *J, cTValue *o) +{ + if (tvisgcv(o)) + return lj_ir_kgc(J, gcV(o), itype2irt(o)); + else if (tvisint(o)) + return lj_ir_kint(J, intV(o)); + else if (tvisnum(o)) + return lj_ir_knumint(J, numV(o)); + else if (tvisbool(o)) + return TREF_PRI(itype2irt(o)); + else + return 0; /* Can't represent lightuserdata (pointless). */ +} + +/* -- Record loop ops ----------------------------------------------------- */ + +/* Loop event. */ +typedef enum { + LOOPEV_LEAVE, /* Loop is left or not entered. */ + LOOPEV_ENTERLO, /* Loop is entered with a low iteration count left. */ + LOOPEV_ENTER /* Loop is entered. */ +} LoopEvent; + +/* Canonicalize slots: convert integers to numbers. */ +static void canonicalize_slots(jit_State *J) +{ + BCReg s; + if (LJ_DUALNUM) return; + for (s = J->baseslot+J->maxslot-1; s >= 1; s--) { + TRef tr = J->slot[s]; + if (tref_isinteger(tr)) { + IRIns *ir = IR(tref_ref(tr)); + if (!(ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_READONLY))) + J->slot[s] = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + } + } +} + +/* Stop recording. */ +static void rec_stop(jit_State *J, TraceLink linktype, TraceNo lnk) +{ + lj_trace_end(J); + J->cur.linktype = (uint8_t)linktype; + J->cur.link = (uint16_t)lnk; + /* Looping back at the same stack level? */ + if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) { + if ((J->flags & JIT_F_OPT_LOOP)) /* Shall we try to create a loop? */ + goto nocanon; /* Do not canonicalize or we lose the narrowing. */ + if (J->cur.root) /* Otherwise ensure we always link to the root trace. */ + J->cur.link = J->cur.root; + } + canonicalize_slots(J); +nocanon: + /* Note: all loop ops must set J->pc to the following instruction! */ + lj_snap_add(J); /* Add loop snapshot. */ + J->needsnap = 0; + J->mergesnap = 1; /* In case recording continues. */ +} + +/* Search bytecode backwards for a int/num constant slot initializer. */ +static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t) +{ + /* This algorithm is rather simplistic and assumes quite a bit about + ** how the bytecode is generated. It works fine for FORI initializers, + ** but it won't necessarily work in other cases (e.g. iterator arguments). + ** It doesn't do anything fancy, either (like backpropagating MOVs). + */ + const BCIns *pc, *startpc = proto_bc(J->pt); + for (pc = endpc-1; pc > startpc; pc--) { + BCIns ins = *pc; + BCOp op = bc_op(ins); + /* First try to find the last instruction that stores to this slot. */ + if (bcmode_a(op) == BCMbase && bc_a(ins) <= slot) { + return 0; /* Multiple results, e.g. from a CALL or KNIL. */ + } else if (bcmode_a(op) == BCMdst && bc_a(ins) == slot) { + if (op == BC_KSHORT || op == BC_KNUM) { /* Found const. initializer. */ + /* Now try to verify there's no forward jump across it. */ + const BCIns *kpc = pc; + for (; pc > startpc; pc--) + if (bc_op(*pc) == BC_JMP) { + const BCIns *target = pc+bc_j(*pc)+1; + if (target > kpc && target <= endpc) + return 0; /* Conditional assignment. */ + } + if (op == BC_KSHORT) { + int32_t k = (int32_t)(int16_t)bc_d(ins); + return t == IRT_INT ? lj_ir_kint(J, k) : lj_ir_knum(J, (lua_Number)k); + } else { + cTValue *tv = proto_knumtv(J->pt, bc_d(ins)); + if (t == IRT_INT) { + int32_t k = numberVint(tv); + if (tvisint(tv) || numV(tv) == (lua_Number)k) /* -0 is ok here. */ + return lj_ir_kint(J, k); + return 0; /* Type mismatch. */ + } else { + return lj_ir_knum(J, numberVnum(tv)); + } + } + } + return 0; /* Non-constant initializer. */ + } + } + return 0; /* No assignment to this slot found? */ +} + +/* Load and optionally convert a FORI argument from a slot. */ +static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode) +{ + int conv = (tvisint(&J->L->base[slot]) != (t==IRT_INT)) ? IRSLOAD_CONVERT : 0; + return sloadt(J, (int32_t)slot, + t + (((mode & IRSLOAD_TYPECHECK) || + (conv && t == IRT_INT && !(mode >> 16))) ? + IRT_GUARD : 0), + mode + conv); +} + +/* Peek before FORI to find a const initializer. Otherwise load from slot. */ +static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, + IRType t, int mode) +{ + TRef tr = J->base[slot]; + if (!tr) { + tr = find_kinit(J, fori, slot, t); + if (!tr) + tr = fori_load(J, slot, t, mode); + } + return tr; +} + +/* Return the direction of the FOR loop iterator. +** It's important to exactly reproduce the semantics of the interpreter. +*/ +static int rec_for_direction(cTValue *o) +{ + return (tvisint(o) ? intV(o) : (int32_t)o->u32.hi) >= 0; +} + +/* Simulate the runtime behavior of the FOR loop iterator. */ +static LoopEvent rec_for_iter(IROp *op, cTValue *o, int isforl) +{ + lua_Number stopv = numberVnum(&o[FORL_STOP]); + lua_Number idxv = numberVnum(&o[FORL_IDX]); + lua_Number stepv = numberVnum(&o[FORL_STEP]); + if (isforl) + idxv += stepv; + if (rec_for_direction(&o[FORL_STEP])) { + if (idxv <= stopv) { + *op = IR_LE; + return idxv + 2*stepv > stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER; + } + *op = IR_GT; return LOOPEV_LEAVE; + } else { + if (stopv <= idxv) { + *op = IR_GE; + return idxv + 2*stepv < stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER; + } + *op = IR_LT; return LOOPEV_LEAVE; + } +} + +/* Record checks for FOR loop overflow and step direction. */ +static void rec_for_check(jit_State *J, IRType t, int dir, + TRef stop, TRef step, int init) +{ + if (!tref_isk(step)) { + /* Non-constant step: need a guard for the direction. */ + TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); + emitir(IRTG(dir ? IR_GE : IR_LT, t), step, zero); + /* Add hoistable overflow checks for a narrowed FORL index. */ + if (init && t == IRT_INT) { + if (tref_isk(stop)) { + /* Constant stop: optimize check away or to a range check for step. */ + int32_t k = IR(tref_ref(stop))->i; + if (dir) { + if (k > 0) + emitir(IRTGI(IR_LE), step, lj_ir_kint(J, (int32_t)0x7fffffff-k)); + } else { + if (k < 0) + emitir(IRTGI(IR_GE), step, lj_ir_kint(J, (int32_t)0x80000000-k)); + } + } else { + /* Stop+step variable: need full overflow check. */ + TRef tr = emitir(IRTGI(IR_ADDOV), step, stop); + emitir(IRTI(IR_USE), tr, 0); /* ADDOV is weak. Avoid dead result. */ + } + } + } else if (init && t == IRT_INT && !tref_isk(stop)) { + /* Constant step: optimize overflow check to a range check for stop. */ + int32_t k = IR(tref_ref(step))->i; + k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; + emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); + } +} + +/* Record a FORL instruction. */ +static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev, + int init) +{ + BCReg ra = bc_a(*fori); + cTValue *tv = &J->L->base[ra]; + TRef idx = J->base[ra+FORL_IDX]; + IRType t = idx ? tref_type(idx) : + (init || LJ_DUALNUM) ? lj_opt_narrow_forl(J, tv) : IRT_NUM; + int mode = IRSLOAD_INHERIT + + ((!LJ_DUALNUM || tvisint(tv) == (t == IRT_INT)) ? IRSLOAD_READONLY : 0); + TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode); + TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode); + int tc, dir = rec_for_direction(&tv[FORL_STEP]); + lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); + scev->t.irt = t; + scev->dir = dir; + scev->stop = tref_ref(stop); + scev->step = tref_ref(step); + rec_for_check(J, t, dir, stop, step, init); + scev->start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT)); + tc = (LJ_DUALNUM && + !(scev->start && irref_isk(scev->stop) && irref_isk(scev->step) && + tvisint(&tv[FORL_IDX]) == (t == IRT_INT))) ? + IRSLOAD_TYPECHECK : 0; + if (tc) { + J->base[ra+FORL_STOP] = stop; + J->base[ra+FORL_STEP] = step; + } + if (!idx) + idx = fori_load(J, ra+FORL_IDX, t, + IRSLOAD_INHERIT + tc + (J->scev.start << 16)); + if (!init) + J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); + J->base[ra+FORL_EXT] = idx; + scev->idx = tref_ref(idx); + J->maxslot = ra+FORL_EXT+1; +} + +/* Record FORL/JFORL or FORI/JFORI. */ +static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) +{ + BCReg ra = bc_a(*fori); + TValue *tv = &J->L->base[ra]; + TRef *tr = &J->base[ra]; + IROp op; + LoopEvent ev; + TRef stop; + IRType t; + if (isforl) { /* Handle FORL/JFORL opcodes. */ + TRef idx = tr[FORL_IDX]; + if (tref_ref(idx) == J->scev.idx) { + t = J->scev.t.irt; + stop = J->scev.stop; + idx = emitir(IRT(IR_ADD, t), idx, J->scev.step); + tr[FORL_EXT] = tr[FORL_IDX] = idx; + } else { + ScEvEntry scev; + rec_for_loop(J, fori, &scev, 0); + t = scev.t.irt; + stop = scev.stop; + } + } else { /* Handle FORI/JFORI opcodes. */ + BCReg i; + lj_meta_for(J->L, tv); + t = (LJ_DUALNUM || tref_isint(tr[FORL_IDX])) ? lj_opt_narrow_forl(J, tv) : + IRT_NUM; + for (i = FORL_IDX; i <= FORL_STEP; i++) { + if (!tr[i]) sload(J, ra+i); + lua_assert(tref_isnumber_str(tr[i])); + if (tref_isstr(tr[i])) + tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); + if (t == IRT_INT) { + if (!tref_isinteger(tr[i])) + tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK); + } else { + if (!tref_isnum(tr[i])) + tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT); + } + } + tr[FORL_EXT] = tr[FORL_IDX]; + stop = tr[FORL_STOP]; + rec_for_check(J, t, rec_for_direction(&tv[FORL_STEP]), + stop, tr[FORL_STEP], 1); + } + + ev = rec_for_iter(&op, tv, isforl); + if (ev == LOOPEV_LEAVE) { + J->maxslot = ra+FORL_EXT+1; + J->pc = fori+1; + } else { + J->maxslot = ra; + J->pc = fori+bc_j(*fori)+1; + } + lj_snap_add(J); + + emitir(IRTG(op, t), tr[FORL_IDX], stop); + + if (ev == LOOPEV_LEAVE) { + J->maxslot = ra; + J->pc = fori+bc_j(*fori)+1; + } else { + J->maxslot = ra+FORL_EXT+1; + J->pc = fori+1; + } + J->needsnap = 1; + return ev; +} + +/* Record ITERL/JITERL. */ +static LoopEvent rec_iterl(jit_State *J, const BCIns iterins) +{ + BCReg ra = bc_a(iterins); + lua_assert(J->base[ra] != 0); + if (!tref_isnil(J->base[ra])) { /* Looping back? */ + J->base[ra-1] = J->base[ra]; /* Copy result of ITERC to control var. */ + J->maxslot = ra-1+bc_b(J->pc[-1]); + J->pc += bc_j(iterins)+1; + return LOOPEV_ENTER; + } else { + J->maxslot = ra-3; + J->pc++; + return LOOPEV_LEAVE; + } +} + +/* Record LOOP/JLOOP. Now, that was easy. */ +static LoopEvent rec_loop(jit_State *J, BCReg ra) +{ + if (ra < J->maxslot) J->maxslot = ra; + J->pc++; + return LOOPEV_ENTER; +} + +/* Check if a loop repeatedly failed to trace because it didn't loop back. */ +static int innerloopleft(jit_State *J, const BCIns *pc) +{ + ptrdiff_t i; + for (i = 0; i < PENALTY_SLOTS; i++) + if (mref(J->penalty[i].pc, const BCIns) == pc) { + if ((J->penalty[i].reason == LJ_TRERR_LLEAVE || + J->penalty[i].reason == LJ_TRERR_LINNER) && + J->penalty[i].val >= 2*PENALTY_MIN) + return 1; + break; + } + return 0; +} + +/* Handle the case when an interpreted loop op is hit. */ +static void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev) +{ + if (J->parent == 0) { + if (pc == J->startpc && J->framedepth + J->retdepth == 0) { + /* Same loop? */ + if (ev == LOOPEV_LEAVE) /* Must loop back to form a root trace. */ + lj_trace_err(J, LJ_TRERR_LLEAVE); + rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Looping root trace. */ + } else if (ev != LOOPEV_LEAVE) { /* Entering inner loop? */ + /* It's usually better to abort here and wait until the inner loop + ** is traced. But if the inner loop repeatedly didn't loop back, + ** this indicates a low trip count. In this case try unrolling + ** an inner loop even in a root trace. But it's better to be a bit + ** more conservative here and only do it for very short loops. + */ + if (bc_j(*pc) != -1 && !innerloopleft(J, pc)) + lj_trace_err(J, LJ_TRERR_LINNER); /* Root trace hit an inner loop. */ + if ((ev != LOOPEV_ENTERLO && + J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0) + lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */ + J->loopref = J->cur.nins; + } + } else if (ev != LOOPEV_LEAVE) { /* Side trace enters an inner loop. */ + J->loopref = J->cur.nins; + if (--J->loopunroll < 0) + lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */ + } /* Side trace continues across a loop that's left or not entered. */ +} + +/* Handle the case when an already compiled loop op is hit. */ +static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev) +{ + if (J->parent == 0) { /* Root trace hit an inner loop. */ + /* Better let the inner loop spawn a side trace back here. */ + lj_trace_err(J, LJ_TRERR_LINNER); + } else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */ + J->instunroll = 0; /* Cannot continue across a compiled loop op. */ + if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Form an extra loop. */ + else + rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the loop. */ + } /* Side trace continues across a loop that's left or not entered. */ +} + +/* -- Record calls and returns -------------------------------------------- */ + +/* Specialize to the runtime value of the called function or its prototype. */ +static TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr) +{ + TRef kfunc; + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + /* Too many closures created? Probably not a monomorphic function. */ + if (pt->flags >= PROTO_CLC_POLY) { /* Specialize to prototype instead. */ + TRef trpt = emitir(IRT(IR_FLOAD, IRT_P32), tr, IRFL_FUNC_PC); + emitir(IRTG(IR_EQ, IRT_P32), trpt, lj_ir_kptr(J, proto_bc(pt))); + (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); /* Prevent GC of proto. */ + return tr; + } + } + /* Otherwise specialize to the function (closure) value itself. */ + kfunc = lj_ir_kfunc(J, fn); + emitir(IRTG(IR_EQ, IRT_FUNC), tr, kfunc); + return kfunc; +} + +/* Record call setup. */ +static void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + RecordIndex ix; + TValue *functv = &J->L->base[func]; + TRef *fbase = &J->base[func]; + ptrdiff_t i; + for (i = 0; i <= nargs; i++) + (void)getslot(J, func+i); /* Ensure func and all args have a reference. */ + if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */ + ix.tab = fbase[0]; + copyTV(J->L, &ix.tabv, functv); + if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj)) + lj_trace_err(J, LJ_TRERR_NOMM); + for (i = ++nargs; i > 0; i--) /* Shift arguments up. */ + fbase[i] = fbase[i-1]; + fbase[0] = ix.mobj; /* Replace function. */ + functv = &ix.mobjv; + } + fbase[0] = TREF_FRAME | rec_call_specialize(J, funcV(functv), fbase[0]); + J->maxslot = (BCReg)nargs; +} + +/* Record call. */ +void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + rec_call_setup(J, func, nargs); + /* Bump frame. */ + J->framedepth++; + J->base += func+1; + J->baseslot += func+1; +} + +/* Record tail call. */ +void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + rec_call_setup(J, func, nargs); + if (frame_isvarg(J->L->base - 1)) { + BCReg cbase = (BCReg)frame_delta(J->L->base - 1); + if (--J->framedepth < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + func += cbase; + } + /* Move func + args down. */ + memmove(&J->base[-1], &J->base[func], sizeof(TRef)*(J->maxslot+1)); + /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */ + /* Tailcalls can form a loop, so count towards the loop unroll limit. */ + if (++J->tailcalled > J->loopunroll) + lj_trace_err(J, LJ_TRERR_LUNROLL); +} + +/* Check unroll limits for down-recursion. */ +static int check_downrec_unroll(jit_State *J, GCproto *pt) +{ + IRRef ptref; + for (ptref = J->chain[IR_KGC]; ptref; ptref = IR(ptref)->prev) + if (ir_kgc(IR(ptref)) == obj2gco(pt)) { + int count = 0; + IRRef ref; + for (ref = J->chain[IR_RETF]; ref; ref = IR(ref)->prev) + if (IR(ref)->op1 == ptref) + count++; + if (count) { + if (J->pc == J->startpc) { + if (count + J->tailcalled > J->param[JIT_P_recunroll]) + return 1; + } else { + lj_trace_err(J, LJ_TRERR_DOWNREC); + } + } + } + return 0; +} + +/* Record return. */ +void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) +{ + TValue *frame = J->L->base - 1; + ptrdiff_t i; + for (i = 0; i < gotresults; i++) + (void)getslot(J, rbase+i); /* Ensure all results have a reference. */ + while (frame_ispcall(frame)) { /* Immediately resolve pcall() returns. */ + BCReg cbase = (BCReg)frame_delta(frame); + if (--J->framedepth < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + lua_assert(J->baseslot > 1); + gotresults++; + rbase += cbase; + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + J->base[--rbase] = TREF_TRUE; /* Prepend true to results. */ + frame = frame_prevd(frame); + } + /* Return to lower frame via interpreter for unhandled cases. */ + if (J->framedepth == 0 && J->pt && bc_isret(bc_op(*J->pc)) && + (!frame_islua(frame) || + (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))))) { + /* NYI: specialize to frame type and return directly, not via RET*. */ + for (i = 0; i < (ptrdiff_t)rbase; i++) + J->base[i] = 0; /* Purge dead slots. */ + J->maxslot = rbase + (BCReg)gotresults; + rec_stop(J, LJ_TRLINK_RETURN, 0); /* Return to interpreter. */ + return; + } + if (frame_isvarg(frame)) { + BCReg cbase = (BCReg)frame_delta(frame); + if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */ + lj_trace_err(J, LJ_TRERR_NYIRETL); + lua_assert(J->baseslot > 1); + rbase += cbase; + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + frame = frame_prevd(frame); + } + if (frame_islua(frame)) { /* Return to Lua frame. */ + BCIns callins = *(frame_pc(frame)-1); + ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults; + BCReg cbase = bc_a(callins); + GCproto *pt = funcproto(frame_func(frame - (cbase+1))); + if ((pt->flags & PROTO_NOJIT)) + lj_trace_err(J, LJ_TRERR_CJITOFF); + if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) { + if (check_downrec_unroll(J, pt)) { + J->maxslot = (BCReg)(rbase + gotresults); + lj_snap_purge(J); + rec_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno); /* Down-recursion. */ + return; + } + lj_snap_add(J); + } + for (i = 0; i < nresults; i++) /* Adjust results. */ + J->base[i-1] = i < gotresults ? J->base[rbase+i] : TREF_NIL; + J->maxslot = cbase+(BCReg)nresults; + if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */ + J->framedepth--; + lua_assert(J->baseslot > cbase+1); + J->baseslot -= cbase+1; + J->base -= cbase+1; + } else if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) { + /* Return to lower frame would leave the loop in a root trace. */ + lj_trace_err(J, LJ_TRERR_LLEAVE); + } else { /* Return to lower frame. Guard for the target we return to. */ + TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); + TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame)); + emitir(IRTG(IR_RETF, IRT_P32), trpt, trpc); + J->retdepth++; + J->needsnap = 1; + lua_assert(J->baseslot == 1); + /* Shift result slots up and clear the slots of the new frame below. */ + memmove(J->base + cbase, J->base-1, sizeof(TRef)*nresults); + memset(J->base-1, 0, sizeof(TRef)*(cbase+1)); + } + } else if (frame_iscont(frame)) { /* Return to continuation frame. */ + ASMFunction cont = frame_contf(frame); + BCReg cbase = (BCReg)frame_delta(frame); + if ((J->framedepth -= 2) < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + J->maxslot = cbase-2; + if (cont == lj_cont_ra) { + /* Copy result to destination slot. */ + BCReg dst = bc_a(*(frame_contpc(frame)-1)); + J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL; + if (dst >= J->maxslot) J->maxslot = dst+1; + } else if (cont == lj_cont_nop) { + /* Nothing to do here. */ + } else if (cont == lj_cont_cat) { + lua_assert(0); + } else { + /* Result type already specialized. */ + lua_assert(cont == lj_cont_condf || cont == lj_cont_condt); + } + } else { + lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */ + } + lua_assert(J->baseslot >= 1); +} + +/* -- Metamethod handling ------------------------------------------------- */ + +/* Prepare to record call to metamethod. */ +static BCReg rec_mm_prep(jit_State *J, ASMFunction cont) +{ + BCReg s, top = curr_proto(J->L)->framesize; + TRef trcont; + setcont(&J->L->base[top], cont); +#if LJ_64 + trcont = lj_ir_kptr(J, (void *)((int64_t)cont - (int64_t)lj_vm_asm_begin)); +#else + trcont = lj_ir_kptr(J, (void *)cont); +#endif + J->base[top] = trcont | TREF_CONT; + J->framedepth++; + for (s = J->maxslot; s < top; s++) + J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */ + return top+1; +} + +/* Record metamethod lookup. */ +int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) +{ + RecordIndex mix; + GCtab *mt; + if (tref_istab(ix->tab)) { + mt = tabref(tabV(&ix->tabv)->metatable); + mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META); + } else if (tref_isudata(ix->tab)) { + int udtype = udataV(&ix->tabv)->udtype; + mt = tabref(udataV(&ix->tabv)->metatable); + /* The metatables of special userdata objects are treated as immutable. */ + if (udtype != UDTYPE_USERDATA) { + cTValue *mo; + if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) { + /* Specialize to the C library namespace object. */ + emitir(IRTG(IR_EQ, IRT_P32), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv))); + } else { + /* Specialize to the type of userdata. */ + TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, udtype)); + } + immutable_mt: + mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm)); + if (!mo || tvisnil(mo)) + return 0; /* No metamethod. */ + /* Treat metamethod or index table as immutable, too. */ + if (!(tvisfunc(mo) || tvistab(mo))) + lj_trace_err(J, LJ_TRERR_BADTYPE); + copyTV(J->L, &ix->mobjv, mo); + ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB); + ix->mtv = mt; + ix->mt = TREF_NIL; /* Dummy value for comparison semantics. */ + return 1; /* Got metamethod or index table. */ + } + mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META); + } else { + /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */ + mt = tabref(basemt_obj(J2G(J), &ix->tabv)); + if (mt == NULL) { + ix->mt = TREF_NIL; + return 0; /* No metamethod. */ + } + /* The cdata metatable is treated as immutable. */ + if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt; + ix->mt = mix.tab = lj_ir_ktab(J, mt); + goto nocheck; + } + ix->mt = mt ? mix.tab : TREF_NIL; + emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mix.tab, lj_ir_knull(J, IRT_TAB)); +nocheck: + if (mt) { + GCstr *mmstr = mmname_str(J2G(J), mm); + cTValue *mo = lj_tab_getstr(mt, mmstr); + if (mo && !tvisnil(mo)) + copyTV(J->L, &ix->mobjv, mo); + ix->mtv = mt; + settabV(J->L, &mix.tabv, mt); + setstrV(J->L, &mix.keyv, mmstr); + mix.key = lj_ir_kstr(J, mmstr); + mix.val = 0; + mix.idxchain = 0; + ix->mobj = lj_record_idx(J, &mix); + return !tref_isnil(ix->mobj); /* 1 if metamethod found, 0 if not. */ + } + return 0; /* No metamethod. */ +} + +/* Record call to arithmetic metamethod. */ +static TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm) +{ + /* Set up metamethod call first to save ix->tab and ix->tabv. */ + BCReg func = rec_mm_prep(J, lj_cont_ra); + TRef *base = J->base + func; + TValue *basev = J->L->base + func; + base[1] = ix->tab; base[2] = ix->key; + copyTV(J->L, basev+1, &ix->tabv); + copyTV(J->L, basev+2, &ix->keyv); + if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + if (mm != MM_unm) { + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + if (lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */ + goto ok; + } + lj_trace_err(J, LJ_TRERR_NOMM); + } +ok: + base[0] = ix->mobj; + copyTV(J->L, basev+0, &ix->mobjv); + lj_record_call(J, func, 2); + return 0; /* No result yet. */ +} + +/* Record call to __len metamethod. */ +static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv) +{ + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, tv); + if (lj_record_mm_lookup(J, &ix, MM_len)) { + BCReg func = rec_mm_prep(J, lj_cont_ra); + TRef *base = J->base + func; + TValue *basev = J->L->base + func; + base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv); + base[1] = tr; copyTV(J->L, basev+1, tv); +#if LJ_52 + base[2] = tr; copyTV(J->L, basev+2, tv); +#else + base[2] = TREF_NIL; setnilV(basev+2); +#endif + lj_record_call(J, func, 2); + } else { + if (LJ_52 && tref_istab(tr)) + return lj_ir_call(J, IRCALL_lj_tab_len, tr); + lj_trace_err(J, LJ_TRERR_NOMM); + } + return 0; /* No result yet. */ +} + +/* Call a comparison metamethod. */ +static void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op) +{ + BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt); + TRef *base = J->base + func; + TValue *tv = J->L->base + func; + base[0] = ix->mobj; base[1] = ix->val; base[2] = ix->key; + copyTV(J->L, tv+0, &ix->mobjv); + copyTV(J->L, tv+1, &ix->valv); + copyTV(J->L, tv+2, &ix->keyv); + lj_record_call(J, func, 2); +} + +/* Record call to equality comparison metamethod (for tab and udata only). */ +static void rec_mm_equal(jit_State *J, RecordIndex *ix, int op) +{ + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + if (lj_record_mm_lookup(J, ix, MM_eq)) { /* Lookup mm on 1st operand. */ + cTValue *bv; + TRef mo1 = ix->mobj; + TValue mo1v; + copyTV(J->L, &mo1v, &ix->mobjv); + /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */ + bv = &ix->keyv; + if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else { /* Lookup metamethod on 2nd operand and compare both. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, bv); + if (!lj_record_mm_lookup(J, ix, MM_eq) || + lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv)) + return; + } + rec_mm_callcomp(J, ix, op); + } +} + +/* Record call to ordered comparison metamethods (for arbitrary objects). */ +static void rec_mm_comp(jit_State *J, RecordIndex *ix, int op) +{ + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + while (1) { + MMS mm = (op & 2) ? MM_le : MM_lt; /* Try __le + __lt or only __lt. */ +#if LJ_52 + if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + if (!lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */ + goto nomatch; + } + rec_mm_callcomp(J, ix, op); + return; +#else + if (lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + cTValue *bv; + TRef mo1 = ix->mobj; + TValue mo1v; + copyTV(J->L, &mo1v, &ix->mobjv); + /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */ + bv = &ix->keyv; + if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else { /* Lookup metamethod on 2nd operand and compare both. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, bv); + if (!lj_record_mm_lookup(J, ix, mm) || + lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv)) + goto nomatch; + } + rec_mm_callcomp(J, ix, op); + return; + } +#endif + nomatch: + /* Lookup failed. Retry with __lt and swapped operands. */ + if (!(op & 2)) break; /* Already at __lt. Interpreter will throw. */ + ix->tab = ix->key; ix->key = ix->val; ix->val = ix->tab; + copyTV(J->L, &ix->tabv, &ix->keyv); + copyTV(J->L, &ix->keyv, &ix->valv); + copyTV(J->L, &ix->valv, &ix->tabv); + op ^= 3; + } +} + +#if LJ_HASFFI +/* Setup call to cdata comparison metamethod. */ +static void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm) +{ + lj_snap_add(J); + if (tref_iscdata(ix->val)) { + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + } else { + lua_assert(tref_iscdata(ix->key)); + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + } + lj_record_mm_lookup(J, ix, mm); + rec_mm_callcomp(J, ix, op); +} +#endif + +/* -- Indexed access ------------------------------------------------------ */ + +/* Record bounds-check. */ +static void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize) +{ + /* Try to emit invariant bounds checks. */ + if ((J->flags & (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) == + (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) { + IRRef ref = tref_ref(ikey); + IRIns *ir = IR(ref); + int32_t ofs = 0; + IRRef ofsref = 0; + /* Handle constant offsets. */ + if (ir->o == IR_ADD && irref_isk(ir->op2)) { + ofsref = ir->op2; + ofs = IR(ofsref)->i; + ref = ir->op1; + ir = IR(ref); + } + /* Got scalar evolution analysis results for this reference? */ + if (ref == J->scev.idx) { + int32_t stop; + lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD); + stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]); + /* Runtime value for stop of loop is within bounds? */ + if ((int64_t)stop + ofs < (int64_t)asize) { + /* Emit invariant bounds check for stop. */ + emitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop : + emitir(IRTI(IR_ADD), J->scev.stop, ofsref)); + /* Emit invariant bounds check for start, if not const or negative. */ + if (!(J->scev.dir && J->scev.start && + (int64_t)IR(J->scev.start)->i + ofs >= 0)) + emitir(IRTG(IR_ABC, IRT_P32), asizeref, ikey); + return; + } + } + } + emitir(IRTGI(IR_ABC), asizeref, ikey); /* Emit regular bounds check. */ +} + +/* Record indexed key lookup. */ +static TRef rec_idx_key(jit_State *J, RecordIndex *ix) +{ + TRef key; + GCtab *t = tabV(&ix->tabv); + ix->oldv = lj_tab_get(J->L, t, &ix->keyv); /* Lookup previous value. */ + + /* Integer keys are looked up in the array part first. */ + key = ix->key; + if (tref_isnumber(key)) { + int32_t k = numberVint(&ix->keyv); + if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k) + k = LJ_MAX_ASIZE; + if ((MSize)k < LJ_MAX_ASIZE) { /* Potential array key? */ + TRef ikey = lj_opt_narrow_index(J, key); + TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); + if ((MSize)k < t->asize) { /* Currently an array key? */ + TRef arrayref; + rec_idx_abc(J, asizeref, ikey, t->asize); + arrayref = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_ARRAY); + return emitir(IRT(IR_AREF, IRT_P32), arrayref, ikey); + } else { /* Currently not in array (may be an array extension)? */ + emitir(IRTGI(IR_ULE), asizeref, ikey); /* Inv. bounds check. */ + if (k == 0 && tref_isk(key)) + key = lj_ir_knum_zero(J); /* Canonicalize 0 or +-0.0 to +0.0. */ + /* And continue with the hash lookup. */ + } + } else if (!tref_isk(key)) { + /* We can rule out const numbers which failed the integerness test + ** above. But all other numbers are potential array keys. + */ + if (t->asize == 0) { /* True sparse tables have an empty array part. */ + /* Guard that the array part stays empty. */ + TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); + emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0)); + } else { + lj_trace_err(J, LJ_TRERR_NYITMIX); + } + } + } + + /* Otherwise the key is located in the hash part. */ + if (t->hmask == 0) { /* Shortcut for empty hash part. */ + /* Guard that the hash part stays empty. */ + TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK); + emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0)); + return lj_ir_kkptr(J, niltvg(J2G(J))); + } + if (tref_isinteger(key)) /* Hash keys are based on numbers, not ints. */ + key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT); + if (tref_isk(key)) { + /* Optimize lookup of constant hash keys. */ + MSize hslot = (MSize)((char *)ix->oldv - (char *)&noderef(t->node)[0].val); + if (t->hmask > 0 && hslot <= t->hmask*(MSize)sizeof(Node) && + hslot <= 65535*(MSize)sizeof(Node)) { + TRef node, kslot; + TRef hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK); + emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask)); + node = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_NODE); + kslot = lj_ir_kslot(J, key, hslot / sizeof(Node)); + return emitir(IRTG(IR_HREFK, IRT_P32), node, kslot); + } + } + /* Fall back to a regular hash lookup. */ + return emitir(IRT(IR_HREF, IRT_P32), ix->tab, key); +} + +/* Determine whether a key is NOT one of the fast metamethod names. */ +static int nommstr(jit_State *J, TRef key) +{ + if (tref_isstr(key)) { + if (tref_isk(key)) { + GCstr *str = ir_kstr(IR(tref_ref(key))); + uint32_t mm; + for (mm = 0; mm <= MM_FAST; mm++) + if (mmname_str(J2G(J), mm) == str) + return 0; /* MUST be one the fast metamethod names. */ + } else { + return 0; /* Variable string key MAY be a metamethod name. */ + } + } + return 1; /* CANNOT be a metamethod name. */ +} + +/* Record indexed load/store. */ +TRef lj_record_idx(jit_State *J, RecordIndex *ix) +{ + TRef xref; + IROp xrefop, loadop; + cTValue *oldv; + + while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */ + /* Never call raw lj_record_idx() on non-table. */ + lua_assert(ix->idxchain != 0); + if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index)) + lj_trace_err(J, LJ_TRERR_NOMM); + handlemm: + if (tref_isfunc(ix->mobj)) { /* Handle metamethod call. */ + BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra); + TRef *base = J->base + func; + TValue *tv = J->L->base + func; + base[0] = ix->mobj; base[1] = ix->tab; base[2] = ix->key; + setfuncV(J->L, tv+0, funcV(&ix->mobjv)); + copyTV(J->L, tv+1, &ix->tabv); + copyTV(J->L, tv+2, &ix->keyv); + if (ix->val) { + base[3] = ix->val; + copyTV(J->L, tv+3, &ix->valv); + lj_record_call(J, func, 3); /* mobj(tab, key, val) */ + return 0; + } else { + lj_record_call(J, func, 2); /* res = mobj(tab, key) */ + return 0; /* No result yet. */ + } + } + /* Otherwise retry lookup with metaobject. */ + ix->tab = ix->mobj; + copyTV(J->L, &ix->tabv, &ix->mobjv); + if (--ix->idxchain == 0) + lj_trace_err(J, LJ_TRERR_IDXLOOP); + } + + /* First catch nil and NaN keys for tables. */ + if (tvisnil(&ix->keyv) || (tvisnum(&ix->keyv) && tvisnan(&ix->keyv))) { + if (ix->val) /* Better fail early. */ + lj_trace_err(J, LJ_TRERR_STORENN); + if (tref_isk(ix->key)) { + if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_index)) + goto handlemm; + return TREF_NIL; + } + } + + /* Record the key lookup. */ + xref = rec_idx_key(J, ix); + xrefop = IR(tref_ref(xref))->o; + loadop = xrefop == IR_AREF ? IR_ALOAD : IR_HLOAD; + /* The lj_meta_tset() inconsistency is gone, but better play safe. */ + oldv = xrefop == IR_KKPTR ? (cTValue *)ir_kptr(IR(tref_ref(xref))) : ix->oldv; + + if (ix->val == 0) { /* Indexed load */ + IRType t = itype2irt(oldv); + TRef res; + if (oldv == niltvg(J2G(J))) { + emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + res = TREF_NIL; + } else { + res = emitir(IRTG(loadop, t), xref, 0); + } + if (t == IRT_NIL && ix->idxchain && lj_record_mm_lookup(J, ix, MM_index)) + goto handlemm; + if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitives. */ + return res; + } else { /* Indexed store. */ + GCtab *mt = tabref(tabV(&ix->tabv)->metatable); + int keybarrier = tref_isgcv(ix->key) && !tref_isnil(ix->val); + if (tvisnil(oldv)) { /* Previous value was nil? */ + /* Need to duplicate the hasmm check for the early guards. */ + int hasmm = 0; + if (ix->idxchain && mt) { + cTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), MM_newindex)); + hasmm = mo && !tvisnil(mo); + } + if (hasmm) + emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */ + else if (xrefop == IR_HREF) + emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32), + xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) { + lua_assert(hasmm); + goto handlemm; + } + lua_assert(!hasmm); + if (oldv == niltvg(J2G(J))) { /* Need to insert a new key. */ + TRef key = ix->key; + if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */ + key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT); + xref = emitir(IRT(IR_NEWREF, IRT_P32), ix->tab, key); + keybarrier = 0; /* NEWREF already takes care of the key barrier. */ + } + } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) { + /* Cannot derive that the previous value was non-nil, must do checks. */ + if (xrefop == IR_HREF) /* Guard against store to niltv. */ + emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + if (ix->idxchain) { /* Metamethod lookup required? */ + /* A check for NULL metatable is cheaper (hoistable) than a load. */ + if (!mt) { + TRef mtref = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB)); + } else { + IRType t = itype2irt(oldv); + emitir(IRTG(loadop, t), xref, 0); /* Guard for non-nil value. */ + } + } + } else { + keybarrier = 0; /* Previous non-nil value kept the key alive. */ + } + /* Convert int to number before storing. */ + if (!LJ_DUALNUM && tref_isinteger(ix->val)) + ix->val = emitir(IRTN(IR_CONV), ix->val, IRCONV_NUM_INT); + emitir(IRT(loadop+IRDELTA_L2S, tref_type(ix->val)), xref, ix->val); + if (keybarrier || tref_isgcv(ix->val)) + emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0); + /* Invalidate neg. metamethod cache for stores with certain string keys. */ + if (!nommstr(J, ix->key)) { + TRef fref = emitir(IRT(IR_FREF, IRT_P32), ix->tab, IRFL_TAB_NOMM); + emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0)); + } + J->needsnap = 1; + return 0; + } +} + +/* -- Upvalue access ------------------------------------------------------ */ + +/* Check whether upvalue is immutable and ok to constify. */ +static int rec_upvalue_constify(jit_State *J, GCupval *uvp) +{ + if (uvp->immutable) { + cTValue *o = uvval(uvp); + /* Don't constify objects that may retain large amounts of memory. */ +#if LJ_HASFFI + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) { + CType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid); + if (!ctype_hassize(ct->info) || ct->size <= 16) + return 1; + } + return 0; + } +#else + UNUSED(J); +#endif + if (!(tvistab(o) || tvisudata(o) || tvisthread(o))) + return 1; + } + return 0; +} + +/* Record upvalue load/store. */ +static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val) +{ + GCupval *uvp = &gcref(J->fn->l.uvptr[uv])->uv; + TRef fn = getcurrf(J); + IRRef uref; + int needbarrier = 0; + if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */ + TRef tr, kfunc; + lua_assert(val == 0); + if (!tref_isk(fn)) { /* Late specialization of current function. */ + if (J->pt->flags >= PROTO_CLC_POLY) + goto noconstify; + kfunc = lj_ir_kfunc(J, J->fn); + emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc); + J->base[-1] = TREF_FRAME | kfunc; + fn = kfunc; + } + tr = lj_record_constify(J, uvval(uvp)); + if (tr) + return tr; + } +noconstify: + /* Note: this effectively limits LJ_MAX_UPVAL to 127. */ + uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff); + if (!uvp->closed) { + /* In current stack? */ + if (uvval(uvp) >= tvref(J->L->stack) && + uvval(uvp) < tvref(J->L->maxstack)) { + int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot)); + if (slot >= 0) { /* Aliases an SSA slot? */ + slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */ + /* NYI: add IR to guard that it's still aliasing the same slot. */ + if (val == 0) { + return getslot(J, slot); + } else { + J->base[slot] = val; + if (slot >= (int32_t)J->maxslot) J->maxslot = (BCReg)(slot+1); + return 0; + } + } + } + uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_P32), fn, uv)); + } else { + needbarrier = 1; + uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_P32), fn, uv)); + } + if (val == 0) { /* Upvalue load */ + IRType t = itype2irt(uvval(uvp)); + TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0); + if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */ + return res; + } else { /* Upvalue store. */ + /* Convert int to number before storing. */ + if (!LJ_DUALNUM && tref_isinteger(val)) + val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); + emitir(IRT(IR_USTORE, tref_type(val)), uref, val); + if (needbarrier && tref_isgcv(val)) + emitir(IRT(IR_OBAR, IRT_NIL), uref, val); + J->needsnap = 1; + return 0; + } +} + +/* -- Record calls to Lua functions --------------------------------------- */ + +/* Check unroll limits for calls. */ +static void check_call_unroll(jit_State *J, TraceNo lnk) +{ + cTValue *frame = J->L->base - 1; + void *pc = mref(frame_func(frame)->l.pc, void); + int32_t depth = J->framedepth; + int32_t count = 0; + if ((J->pt->flags & PROTO_VARARG)) depth--; /* Vararg frame still missing. */ + for (; depth > 0; depth--) { /* Count frames with same prototype. */ + if (frame_iscont(frame)) depth--; + frame = frame_prev(frame); + if (mref(frame_func(frame)->l.pc, void) == pc) + count++; + } + if (J->pc == J->startpc) { + if (count + J->tailcalled > J->param[JIT_P_recunroll]) { + J->pc++; + if (J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Tail-recursion. */ + else + rec_stop(J, LJ_TRLINK_UPREC, J->cur.traceno); /* Up-recursion. */ + } + } else { + if (count > J->param[JIT_P_callunroll]) { + if (lnk) { /* Possible tail- or up-recursion. */ + lj_trace_flush(J, lnk); /* Flush trace that only returns. */ + /* Set a small, pseudo-random hotcount for a quick retry of JFUNC*. */ + hotcount_set(J2GG(J), J->pc+1, LJ_PRNG_BITS(J, 4)); + } + lj_trace_err(J, LJ_TRERR_CUNROLL); + } + } +} + +/* Record Lua function setup. */ +static void rec_func_setup(jit_State *J) +{ + GCproto *pt = J->pt; + BCReg s, numparams = pt->numparams; + if ((pt->flags & PROTO_NOJIT)) + lj_trace_err(J, LJ_TRERR_CJITOFF); + if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + /* Fill up missing parameters with nil. */ + for (s = J->maxslot; s < numparams; s++) + J->base[s] = TREF_NIL; + /* The remaining slots should never be read before they are written. */ + J->maxslot = numparams; +} + +/* Record Lua vararg function setup. */ +static void rec_func_vararg(jit_State *J) +{ + GCproto *pt = J->pt; + BCReg s, fixargs, vframe = J->maxslot+1; + lua_assert((pt->flags & PROTO_VARARG)); + if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + J->base[vframe-1] = J->base[-1]; /* Copy function up. */ + /* Copy fixarg slots up and set their original slots to nil. */ + fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot; + for (s = 0; s < fixargs; s++) { + J->base[vframe+s] = J->base[s]; + J->base[s] = TREF_NIL; + } + J->maxslot = fixargs; + J->framedepth++; + J->base += vframe; + J->baseslot += vframe; +} + +/* Record entry to a Lua function. */ +static void rec_func_lua(jit_State *J) +{ + rec_func_setup(J); + check_call_unroll(J, 0); +} + +/* Record entry to an already compiled function. */ +static void rec_func_jit(jit_State *J, TraceNo lnk) +{ + GCtrace *T; + rec_func_setup(J); + T = traceref(J, lnk); + if (T->linktype == LJ_TRLINK_RETURN) { /* Trace returns to interpreter? */ + check_call_unroll(J, lnk); + /* Temporarily unpatch JFUNC* to continue recording across function. */ + J->patchins = *J->pc; + J->patchpc = (BCIns *)J->pc; + *J->patchpc = T->startins; + return; + } + J->instunroll = 0; /* Cannot continue across a compiled function. */ + if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Extra tail-recursion. */ + else + rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the function. */ +} + +/* -- Vararg handling ----------------------------------------------------- */ + +/* Detect y = select(x, ...) idiom. */ +static int select_detect(jit_State *J) +{ + BCIns ins = J->pc[1]; + if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) { + cTValue *func = &J->L->base[bc_a(ins)]; + if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) + return 1; + } + return 0; +} + +/* Record vararg instruction. */ +static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) +{ + int32_t numparams = J->pt->numparams; + ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1; + lua_assert(frame_isvarg(J->L->base-1)); + if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */ + ptrdiff_t i; + if (nvararg < 0) nvararg = 0; + if (nresults == -1) { + nresults = nvararg; + J->maxslot = dst + (BCReg)nvararg; + } else if (dst + nresults > J->maxslot) { + J->maxslot = dst + (BCReg)nresults; + } + for (i = 0; i < nresults; i++) + J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL; + } else { /* Unknown number of varargs passed to trace. */ + TRef fr = emitir(IRTI(IR_SLOAD), 0, IRSLOAD_READONLY|IRSLOAD_FRAME); + int32_t frofs = 8*(1+numparams)+FRAME_VARG; + if (nresults >= 0) { /* Known fixed number of results. */ + ptrdiff_t i; + if (nvararg > 0) { + ptrdiff_t nload = nvararg >= nresults ? nresults : nvararg; + TRef vbase; + if (nvararg >= nresults) + emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults)); + else + emitir(IRTGI(IR_EQ), fr, lj_ir_kint(J, frame_ftsz(J->L->base-1))); + vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); + vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); + for (i = 0; i < nload; i++) { + IRType t = itype2irt(&J->L->base[i-1-nvararg]); + TRef aref = emitir(IRT(IR_AREF, IRT_P32), + vbase, lj_ir_kint(J, (int32_t)i)); + TRef tr = emitir(IRTG(IR_VLOAD, t), aref, 0); + if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */ + J->base[dst+i] = tr; + } + } else { + emitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs)); + nvararg = 0; + } + for (i = nvararg; i < nresults; i++) + J->base[dst+i] = TREF_NIL; + if (dst + (BCReg)nresults > J->maxslot) + J->maxslot = dst + (BCReg)nresults; + } else if (select_detect(J)) { /* y = select(x, ...) */ + TRef tridx = J->base[dst-1]; + TRef tr = TREF_NIL; + ptrdiff_t idx = lj_ffrecord_select_mode(J, tridx, &J->L->base[dst-1]); + if (idx < 0) goto nyivarg; + if (idx != 0 && !tref_isinteger(tridx)) + tridx = emitir(IRTGI(IR_CONV), tridx, IRCONV_INT_NUM|IRCONV_INDEX); + if (idx != 0 && tref_isk(tridx)) { + emitir(IRTGI(idx <= nvararg ? IR_GE : IR_LT), + fr, lj_ir_kint(J, frofs+8*(int32_t)idx)); + frofs -= 8; /* Bias for 1-based index. */ + } else if (idx <= nvararg) { /* Compute size. */ + TRef tmp = emitir(IRTI(IR_ADD), fr, lj_ir_kint(J, -frofs)); + if (numparams) + emitir(IRTGI(IR_GE), tmp, lj_ir_kint(J, 0)); + tr = emitir(IRTI(IR_BSHR), tmp, lj_ir_kint(J, 3)); + if (idx != 0) { + tridx = emitir(IRTI(IR_ADD), tridx, lj_ir_kint(J, -1)); + rec_idx_abc(J, tr, tridx, (uint32_t)nvararg); + } + } else { + TRef tmp = lj_ir_kint(J, frofs); + if (idx != 0) { + TRef tmp2 = emitir(IRTI(IR_BSHL), tridx, lj_ir_kint(J, 3)); + tmp = emitir(IRTI(IR_ADD), tmp2, tmp); + } else { + tr = lj_ir_kint(J, 0); + } + emitir(IRTGI(IR_LT), fr, tmp); + } + if (idx != 0 && idx <= nvararg) { + IRType t; + TRef aref, vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); + vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); + t = itype2irt(&J->L->base[idx-2-nvararg]); + aref = emitir(IRT(IR_AREF, IRT_P32), vbase, tridx); + tr = emitir(IRTG(IR_VLOAD, t), aref, 0); + if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */ + } + J->base[dst-2] = tr; + J->maxslot = dst-1; + J->bcskip = 2; /* Skip CALLM + select. */ + } else { + nyivarg: + setintV(&J->errinfo, BC_VARG); + lj_trace_err_info(J, LJ_TRERR_NYIBC); + } + } +} + +/* -- Record allocations -------------------------------------------------- */ + +static TRef rec_tnew(jit_State *J, uint32_t ah) +{ + uint32_t asize = ah & 0x7ff; + uint32_t hbits = ah >> 11; + if (asize == 0x7ff) asize = 0x801; + return emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits); +} + +/* -- Record bytecode ops ------------------------------------------------- */ + +/* Prepare for comparison. */ +static void rec_comp_prep(jit_State *J) +{ + /* Prevent merging with snapshot #0 (GC exit) since we fixup the PC. */ + if (J->cur.nsnap == 1 && J->cur.snap[0].ref == J->cur.nins) + emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); + lj_snap_add(J); +} + +/* Fixup comparison. */ +static void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond) +{ + BCIns jmpins = pc[1]; + const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0); + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + /* Set PC to opposite target to avoid re-recording the comp. in side trace. */ + J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc); + J->needsnap = 1; + if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins); + lj_snap_shrink(J); /* Shrink last snapshot if possible. */ +} + +/* Record the next bytecode instruction (_before_ it's executed). */ +void lj_record_ins(jit_State *J) +{ + cTValue *lbase; + RecordIndex ix; + const BCIns *pc; + BCIns ins; + BCOp op; + TRef ra, rb, rc; + + /* Perform post-processing action before recording the next instruction. */ + if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) { + switch (J->postproc) { + case LJ_POST_FIXCOMP: /* Fixup comparison. */ + pc = frame_pc(&J2G(J)->tmptv); + rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1))); + /* fallthrough */ + case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */ + case LJ_POST_FIXGUARDSNAP: /* Fixup and emit pending guard and snapshot. */ + if (!tvistruecond(&J2G(J)->tmptv2)) { + J->fold.ins.o ^= 1; /* Flip guard to opposite. */ + if (J->postproc == LJ_POST_FIXGUARDSNAP) { + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + J->cur.snapmap[snap->mapofs+snap->nent-1]--; /* False -> true. */ + } + } + lj_opt_fold(J); /* Emit pending guard. */ + /* fallthrough */ + case LJ_POST_FIXBOOL: + if (!tvistruecond(&J2G(J)->tmptv2)) { + BCReg s; + TValue *tv = J->L->base; + for (s = 0; s < J->maxslot; s++) /* Fixup stack slot (if any). */ + if (J->base[s] == TREF_TRUE && tvisfalse(&tv[s])) { + J->base[s] = TREF_FALSE; + break; + } + } + break; + case LJ_POST_FIXCONST: + { + BCReg s; + TValue *tv = J->L->base; + for (s = 0; s < J->maxslot; s++) /* Constify stack slots (if any). */ + if (J->base[s] == TREF_NIL && !tvisnil(&tv[s])) + J->base[s] = lj_record_constify(J, &tv[s]); + } + break; + case LJ_POST_FFRETRY: /* Suppress recording of retried fast function. */ + if (bc_op(*J->pc) >= BC__MAX) + return; + break; + default: lua_assert(0); break; + } + J->postproc = LJ_POST_NONE; + } + + /* Need snapshot before recording next bytecode (e.g. after a store). */ + if (J->needsnap) { + J->needsnap = 0; + lj_snap_purge(J); + lj_snap_add(J); + J->mergesnap = 1; + } + + /* Skip some bytecodes. */ + if (LJ_UNLIKELY(J->bcskip > 0)) { + J->bcskip--; + return; + } + + /* Record only closed loops for root traces. */ + pc = J->pc; + if (J->framedepth == 0 && + (MSize)((char *)pc - (char *)J->bc_min) >= J->bc_extent) + lj_trace_err(J, LJ_TRERR_LLEAVE); + +#ifdef LUA_USE_ASSERT + rec_check_slots(J); + rec_check_ir(J); +#endif + + /* Keep a copy of the runtime values of var/num/str operands. */ +#define rav (&ix.valv) +#define rbv (&ix.tabv) +#define rcv (&ix.keyv) + + lbase = J->L->base; + ins = *pc; + op = bc_op(ins); + ra = bc_a(ins); + ix.val = 0; + switch (bcmode_a(op)) { + case BCMvar: + copyTV(J->L, rav, &lbase[ra]); ix.val = ra = getslot(J, ra); break; + default: break; /* Handled later. */ + } + rb = bc_b(ins); + rc = bc_c(ins); + switch (bcmode_b(op)) { + case BCMnone: rb = 0; rc = bc_d(ins); break; /* Upgrade rc to 'rd'. */ + case BCMvar: + copyTV(J->L, rbv, &lbase[rb]); ix.tab = rb = getslot(J, rb); break; + default: break; /* Handled later. */ + } + switch (bcmode_c(op)) { + case BCMvar: + copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break; + case BCMpri: setitype(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break; + case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc); + copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) : + lj_ir_knumint(J, numV(tv)); } break; + case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc)); + setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break; + default: break; /* Handled later. */ + } + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: +#if LJ_HASFFI + if (tref_iscdata(ra) || tref_iscdata(rc)) { + rec_mm_comp_cdata(J, &ix, op, ((int)op & 2) ? MM_le : MM_lt); + break; + } +#endif + /* Emit nothing for two numeric or string consts. */ + if (!(tref_isk2(ra,rc) && tref_isnumber_str(ra) && tref_isnumber_str(rc))) { + IRType ta = tref_isinteger(ra) ? IRT_INT : tref_type(ra); + IRType tc = tref_isinteger(rc) ? IRT_INT : tref_type(rc); + int irop; + if (ta != tc) { + /* Widen mixed number/int comparisons to number/number comparison. */ + if (ta == IRT_INT && tc == IRT_NUM) { + ra = emitir(IRTN(IR_CONV), ra, IRCONV_NUM_INT); + ta = IRT_NUM; + } else if (ta == IRT_NUM && tc == IRT_INT) { + rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + } else if (LJ_52) { + ta = IRT_NIL; /* Force metamethod for different types. */ + } else if (!((ta == IRT_FALSE || ta == IRT_TRUE) && + (tc == IRT_FALSE || tc == IRT_TRUE))) { + break; /* Interpreter will throw for two different types. */ + } + } + rec_comp_prep(J); + irop = (int)op - (int)BC_ISLT + (int)IR_LT; + if (ta == IRT_NUM) { + if ((irop & 1)) irop ^= 4; /* ISGE/ISGT are unordered. */ + if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop)) + irop ^= 5; + } else if (ta == IRT_INT) { + if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop)) + irop ^= 1; + } else if (ta == IRT_STR) { + if (!lj_ir_strcmp(strV(rav), strV(rcv), (IROp)irop)) irop ^= 1; + ra = lj_ir_call(J, IRCALL_lj_str_cmp, ra, rc); + rc = lj_ir_kint(J, 0); + ta = IRT_INT; + } else { + rec_mm_comp(J, &ix, (int)op); + break; + } + emitir(IRTG(irop, ta), ra, rc); + rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1); + } + break; + + case BC_ISEQV: case BC_ISNEV: + case BC_ISEQS: case BC_ISNES: + case BC_ISEQN: case BC_ISNEN: + case BC_ISEQP: case BC_ISNEP: +#if LJ_HASFFI + if (tref_iscdata(ra) || tref_iscdata(rc)) { + rec_mm_comp_cdata(J, &ix, op, MM_eq); + break; + } +#endif + /* Emit nothing for two non-table, non-udata consts. */ + if (!(tref_isk2(ra, rc) && !(tref_istab(ra) || tref_isudata(ra)))) { + int diff; + rec_comp_prep(J); + diff = lj_record_objcmp(J, ra, rc, rav, rcv); + if (diff == 2 || !(tref_istab(ra) || tref_isudata(ra))) + rec_comp_fixup(J, J->pc, ((int)op & 1) == !diff); + else if (diff == 1) /* Only check __eq if different, but same type. */ + rec_mm_equal(J, &ix, (int)op); + } + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: + if ((op & 1) == tref_istruecond(rc)) + rc = 0; /* Don't store if condition is not true. */ + /* fallthrough */ + case BC_IST: case BC_ISF: /* Type specialization suffices. */ + if (bc_a(pc[1]) < J->maxslot) + J->maxslot = bc_a(pc[1]); /* Shrink used slots. */ + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_NOT: + /* Type specialization already forces const result. */ + rc = tref_istruecond(rc) ? TREF_FALSE : TREF_TRUE; + break; + + case BC_LEN: + if (tref_isstr(rc)) + rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN); + else if (!LJ_52 && tref_istab(rc)) + rc = lj_ir_call(J, IRCALL_lj_tab_len, rc); + else + rc = rec_mm_len(J, rc, rcv); + break; + + /* -- Arithmetic ops ---------------------------------------------------- */ + + case BC_UNM: + if (tref_isnumber_str(rc)) { + rc = lj_opt_narrow_unm(J, rc, rcv); + } else { + ix.tab = rc; + copyTV(J->L, &ix.tabv, rcv); + rc = rec_mm_arith(J, &ix, MM_unm); + } + break; + + case BC_ADDNV: case BC_SUBNV: case BC_MULNV: case BC_DIVNV: case BC_MODNV: + /* Swap rb/rc and rbv/rcv. rav is temp. */ + ix.tab = rc; ix.key = rc = rb; rb = ix.tab; + copyTV(J->L, rav, rbv); + copyTV(J->L, rbv, rcv); + copyTV(J->L, rcv, rav); + if (op == BC_MODNV) + goto recmod; + /* fallthrough */ + case BC_ADDVN: case BC_SUBVN: case BC_MULVN: case BC_DIVVN: + case BC_ADDVV: case BC_SUBVV: case BC_MULVV: case BC_DIVVV: { + MMS mm = bcmode_mm(op); + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv, + (int)mm - (int)MM_add + (int)IR_ADD); + else + rc = rec_mm_arith(J, &ix, mm); + break; + } + + case BC_MODVN: case BC_MODVV: + recmod: + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_mod(J, rb, rc, rcv); + else + rc = rec_mm_arith(J, &ix, MM_mod); + break; + + case BC_POW: + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_pow(J, lj_ir_tonum(J, rb), rc, rcv); + else + rc = rec_mm_arith(J, &ix, MM_pow); + break; + + /* -- Constant and move ops --------------------------------------------- */ + + case BC_MOV: + /* Clear gap of method call to avoid resurrecting previous refs. */ + if (ra > J->maxslot) J->base[ra-1] = 0; + break; + case BC_KSTR: case BC_KNUM: case BC_KPRI: + break; + case BC_KSHORT: + rc = lj_ir_kint(J, (int32_t)(int16_t)rc); + break; + case BC_KNIL: + while (ra <= rc) + J->base[ra++] = TREF_NIL; + if (rc >= J->maxslot) J->maxslot = rc+1; + break; +#if LJ_HASFFI + case BC_KCDATA: + rc = lj_ir_kgc(J, proto_kgc(J->pt, ~(ptrdiff_t)rc), IRT_CDATA); + break; +#endif + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + rc = rec_upvalue(J, rc, 0); + break; + case BC_USETV: case BC_USETS: case BC_USETN: case BC_USETP: + rec_upvalue(J, ra, rc); + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_GGET: case BC_GSET: + settabV(J->L, &ix.tabv, tabref(J->fn->l.env)); + ix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), getcurrf(J), IRFL_FUNC_ENV); + ix.idxchain = LJ_MAX_IDXCHAIN; + rc = lj_record_idx(J, &ix); + break; + + case BC_TGETB: case BC_TSETB: + setintV(&ix.keyv, (int32_t)rc); + ix.key = lj_ir_kint(J, (int32_t)rc); + /* fallthrough */ + case BC_TGETV: case BC_TGETS: case BC_TSETV: case BC_TSETS: + ix.idxchain = LJ_MAX_IDXCHAIN; + rc = lj_record_idx(J, &ix); + break; + + case BC_TNEW: + rc = rec_tnew(J, rc); + break; + case BC_TDUP: + rc = emitir(IRTG(IR_TDUP, IRT_TAB), + lj_ir_ktab(J, gco2tab(proto_kgc(J->pt, ~(ptrdiff_t)rc))), 0); + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_ITERC: + J->base[ra] = getslot(J, ra-3); + J->base[ra+1] = getslot(J, ra-2); + J->base[ra+2] = getslot(J, ra-1); + { /* Do the actual copy now because lj_record_call needs the values. */ + TValue *b = &J->L->base[ra]; + copyTV(J->L, b, b-3); + copyTV(J->L, b+1, b-2); + copyTV(J->L, b+2, b-1); + } + lj_record_call(J, ra, (ptrdiff_t)rc-1); + break; + + /* L->top is set to L->base+ra+rc+NARGS-1+1. See lj_dispatch_ins(). */ + case BC_CALLM: + rc = (BCReg)(J->L->top - J->L->base) - ra; + /* fallthrough */ + case BC_CALL: + lj_record_call(J, ra, (ptrdiff_t)rc-1); + break; + + case BC_CALLMT: + rc = (BCReg)(J->L->top - J->L->base) - ra; + /* fallthrough */ + case BC_CALLT: + lj_record_tailcall(J, ra, (ptrdiff_t)rc-1); + break; + + case BC_VARG: + rec_varg(J, ra, (ptrdiff_t)rb-1); + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + /* L->top is set to L->base+ra+rc+NRESULTS-1, see lj_dispatch_ins(). */ + rc = (BCReg)(J->L->top - J->L->base) - ra + 1; + /* fallthrough */ + case BC_RET: case BC_RET0: case BC_RET1: + lj_record_ret(J, ra, (ptrdiff_t)rc-1); + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORI: + if (rec_for(J, pc, 0) != LOOPEV_LEAVE) + J->loopref = J->cur.nins; + break; + case BC_JFORI: + lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL); + if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */ + rec_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J])); + /* Continue tracing if the loop is not entered. */ + break; + + case BC_FORL: + rec_loop_interp(J, pc, rec_for(J, pc+((ptrdiff_t)rc-BCBIAS_J), 1)); + break; + case BC_ITERL: + rec_loop_interp(J, pc, rec_iterl(J, *pc)); + break; + case BC_LOOP: + rec_loop_interp(J, pc, rec_loop(J, ra)); + break; + + case BC_JFORL: + rec_loop_jit(J, rc, rec_for(J, pc+bc_j(traceref(J, rc)->startins), 1)); + break; + case BC_JITERL: + rec_loop_jit(J, rc, rec_iterl(J, traceref(J, rc)->startins)); + break; + case BC_JLOOP: + rec_loop_jit(J, rc, rec_loop(J, ra)); + break; + + case BC_IFORL: + case BC_IITERL: + case BC_ILOOP: + case BC_IFUNCF: + case BC_IFUNCV: + lj_trace_err(J, LJ_TRERR_BLACKL); + break; + + case BC_JMP: + if (ra < J->maxslot) + J->maxslot = ra; /* Shrink used slots. */ + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + rec_func_lua(J); + break; + case BC_JFUNCF: + rec_func_jit(J, rc); + break; + + case BC_FUNCV: + rec_func_vararg(J); + rec_func_lua(J); + break; + case BC_JFUNCV: + lua_assert(0); /* Cannot happen. No hotcall counting for varag funcs. */ + break; + + case BC_FUNCC: + case BC_FUNCCW: + lj_ffrecord_func(J); + break; + + default: + if (op >= BC__MAX) { + lj_ffrecord_func(J); + break; + } + /* fallthrough */ + case BC_ITERN: + case BC_ISNEXT: + case BC_CAT: + case BC_UCLO: + case BC_FNEW: + case BC_TSETM: + setintV(&J->errinfo, (int32_t)op); + lj_trace_err_info(J, LJ_TRERR_NYIBC); + break; + } + + /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */ + if (bcmode_a(op) == BCMdst && rc) { + J->base[ra] = rc; + if (ra >= J->maxslot) J->maxslot = ra+1; + } + +#undef rav +#undef rbv +#undef rcv + + /* Limit the number of recorded IR instructions. */ + if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord]) + lj_trace_err(J, LJ_TRERR_TRACEOV); +} + +/* -- Recording setup ----------------------------------------------------- */ + +/* Setup recording for a root trace started by a hot loop. */ +static const BCIns *rec_setup_root(jit_State *J) +{ + /* Determine the next PC and the bytecode range for the loop. */ + const BCIns *pcj, *pc = J->pc; + BCIns ins = *pc; + BCReg ra = bc_a(ins); + switch (bc_op(ins)) { + case BC_FORL: + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + pc += 1+bc_j(ins); + J->bc_min = pc; + break; + case BC_ITERL: + lua_assert(bc_op(pc[-1]) == BC_ITERC); + J->maxslot = ra + bc_b(pc[-1]) - 1; + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + pc += 1+bc_j(ins); + lua_assert(bc_op(pc[-1]) == BC_JMP); + J->bc_min = pc; + break; + case BC_LOOP: + /* Only check BC range for real loops, but not for "repeat until true". */ + pcj = pc + bc_j(ins); + ins = *pcj; + if (bc_op(ins) == BC_JMP && bc_j(ins) < 0) { + J->bc_min = pcj+1 + bc_j(ins); + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + } + J->maxslot = ra; + pc++; + break; + case BC_RET: + case BC_RET0: + case BC_RET1: + /* No bytecode range check for down-recursive root traces. */ + J->maxslot = ra + bc_d(ins) - 1; + break; + case BC_FUNCF: + /* No bytecode range check for root traces started by a hot call. */ + J->maxslot = J->pt->numparams; + pc++; + break; + default: + lua_assert(0); + break; + } + return pc; +} + +/* Setup for recording a new trace. */ +void lj_record_setup(jit_State *J) +{ + uint32_t i; + + /* Initialize state related to current trace. */ + memset(J->slot, 0, sizeof(J->slot)); + memset(J->chain, 0, sizeof(J->chain)); + memset(J->bpropcache, 0, sizeof(J->bpropcache)); + J->scev.idx = REF_NIL; + + J->baseslot = 1; /* Invoking function is at base[-1]. */ + J->base = J->slot + J->baseslot; + J->maxslot = 0; + J->framedepth = 0; + J->retdepth = 0; + + J->instunroll = J->param[JIT_P_instunroll]; + J->loopunroll = J->param[JIT_P_loopunroll]; + J->tailcalled = 0; + J->loopref = 0; + + J->bc_min = NULL; /* Means no limit. */ + J->bc_extent = ~(MSize)0; + + /* Emit instructions for fixed references. Also triggers initial IR alloc. */ + emitir_raw(IRT(IR_BASE, IRT_P32), J->parent, J->exitno); + for (i = 0; i <= 2; i++) { + IRIns *ir = IR(REF_NIL-i); + ir->i = 0; + ir->t.irt = (uint8_t)(IRT_NIL+i); + ir->o = IR_KPRI; + ir->prev = 0; + } + J->cur.nk = REF_TRUE; + + J->startpc = J->pc; + setmref(J->cur.startpc, J->pc); + if (J->parent) { /* Side trace. */ + GCtrace *T = traceref(J, J->parent); + TraceNo root = T->root ? T->root : J->parent; + J->cur.root = (uint16_t)root; + J->cur.startins = BCINS_AD(BC_JMP, 0, 0); + /* Check whether we could at least potentially form an extra loop. */ + if (J->exitno == 0 && T->snap[0].nent == 0) { + /* We can narrow a FORL for some side traces, too. */ + if (J->pc > proto_bc(J->pt) && bc_op(J->pc[-1]) == BC_JFORI && + bc_d(J->pc[bc_j(J->pc[-1])-1]) == root) { + lj_snap_add(J); + rec_for_loop(J, J->pc-1, &J->scev, 1); + goto sidecheck; + } + } else { + J->startpc = NULL; /* Prevent forming an extra loop. */ + } + lj_snap_replay(J, T); + sidecheck: + if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || + T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + + J->param[JIT_P_tryside]) { + rec_stop(J, LJ_TRLINK_INTERP, 0); + } + } else { /* Root trace. */ + J->cur.root = 0; + J->cur.startins = *J->pc; + J->pc = rec_setup_root(J); + /* Note: the loop instruction itself is recorded at the end and not + ** at the start! So snapshot #0 needs to point to the *next* instruction. + */ + lj_snap_add(J); + if (bc_op(J->cur.startins) == BC_FORL) + rec_for_loop(J, J->pc-1, &J->scev, 1); + if (1 + J->pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + } +#ifdef LUAJIT_ENABLE_CHECKHOOK + /* Regularly check for instruction/line hooks from compiled code and + ** exit to the interpreter if the hooks are set. + ** + ** This is a compile-time option and disabled by default, since the + ** hook checks may be quite expensive in tight loops. + ** + ** Note this is only useful if hooks are *not* set most of the time. + ** Use this only if you want to *asynchronously* interrupt the execution. + ** + ** You can set the instruction hook via lua_sethook() with a count of 1 + ** from a signal handler or another native thread. Please have a look + ** at the first few functions in luajit.c for an example (Ctrl-C handler). + */ + { + TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), + lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE); + tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT))); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); + } +#endif +} + +#undef IR +#undef emitir_raw +#undef emitir + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.h new file mode 100644 index 0000000..940e105 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_record.h @@ -0,0 +1,44 @@ +/* +** Trace recorder (bytecode -> SSA IR). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_RECORD_H +#define _LJ_RECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* Context for recording an indexed load/store. */ +typedef struct RecordIndex { + TValue tabv; /* Runtime value of table (or indexed object). */ + TValue keyv; /* Runtime value of key. */ + TValue valv; /* Runtime value of stored value. */ + TValue mobjv; /* Runtime value of metamethod object. */ + GCtab *mtv; /* Runtime value of metatable object. */ + cTValue *oldv; /* Runtime value of previously stored value. */ + TRef tab; /* Table (or indexed object) reference. */ + TRef key; /* Key reference. */ + TRef val; /* Value reference for a store or 0 for a load. */ + TRef mt; /* Metatable reference. */ + TRef mobj; /* Metamethod object reference. */ + int idxchain; /* Index indirections left or 0 for raw lookup. */ +} RecordIndex; + +LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b, + cTValue *av, cTValue *bv); +LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o); + +LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs); +LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs); +LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults); + +LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm); +LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix); + +LJ_FUNC void lj_record_ins(jit_State *J); +LJ_FUNC void lj_record_setup(jit_State *J); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.c new file mode 100644 index 0000000..1c978c2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.c @@ -0,0 +1,865 @@ +/* +** Snapshot handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_snap_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_target.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#endif + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Snapshot buffer allocation ------------------------------------------ */ + +/* Grow snapshot buffer. */ +void lj_snap_grow_buf_(jit_State *J, MSize need) +{ + MSize maxsnap = (MSize)J->param[JIT_P_maxsnap]; + if (need > maxsnap) + lj_trace_err(J, LJ_TRERR_SNAPOV); + lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot); + J->cur.snap = J->snapbuf; +} + +/* Grow snapshot map buffer. */ +void lj_snap_grow_map_(jit_State *J, MSize need) +{ + if (need < 2*J->sizesnapmap) + need = 2*J->sizesnapmap; + else if (need < 64) + need = 64; + J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf, + J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry)); + J->cur.snapmap = J->snapmapbuf; + J->sizesnapmap = need; +} + +/* -- Snapshot generation ------------------------------------------------- */ + +/* Add all modified slots to the snapshot. */ +static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) +{ + IRRef retf = J->chain[IR_RETF]; /* Limits SLOAD restore elimination. */ + BCReg s; + MSize n = 0; + for (s = 0; s < nslots; s++) { + TRef tr = J->slot[s]; + IRRef ref = tref_ref(tr); + if (ref) { + SnapEntry sn = SNAP_TR(s, tr); + IRIns *ir = IR(ref); + if (!(sn & (SNAP_CONT|SNAP_FRAME)) && + ir->o == IR_SLOAD && ir->op1 == s && ref > retf) { + /* No need to snapshot unmodified non-inherited slots. */ + if (!(ir->op2 & IRSLOAD_INHERIT)) + continue; + /* No need to restore readonly slots and unmodified non-parent slots. */ + if (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) && + (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT) + sn |= SNAP_NORESTORE; + } + if (LJ_SOFTFP && irt_isnum(ir->t)) + sn |= SNAP_SOFTFPNUM; + map[n++] = sn; + } + } + return n; +} + +/* Add frame links at the end of the snapshot. */ +static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map) +{ + cTValue *frame = J->L->base - 1; + cTValue *lim = J->L->base - J->baseslot; + cTValue *ftop = frame + funcproto(frame_func(frame))->framesize; + MSize f = 0; + map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */ + while (frame > lim) { /* Backwards traversal of all frames above base. */ + if (frame_islua(frame)) { + map[f++] = SNAP_MKPC(frame_pc(frame)); + frame = frame_prevl(frame); + if (frame + funcproto(frame_func(frame))->framesize > ftop) + ftop = frame + funcproto(frame_func(frame))->framesize; + } else if (frame_iscont(frame)) { + map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); + map[f++] = SNAP_MKPC(frame_contpc(frame)); + frame = frame_prevd(frame); + } else { + lua_assert(!frame_isc(frame)); + map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); + frame = frame_prevd(frame); + } + } + lua_assert(f == (MSize)(1 + J->framedepth)); + return (BCReg)(ftop - lim); +} + +/* Take a snapshot of the current stack. */ +static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap) +{ + BCReg nslots = J->baseslot + J->maxslot; + MSize nent; + SnapEntry *p; + /* Conservative estimate. */ + lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1); + p = &J->cur.snapmap[nsnapmap]; + nent = snapshot_slots(J, p, nslots); + snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent); + snap->mapofs = (uint16_t)nsnapmap; + snap->ref = (IRRef1)J->cur.nins; + snap->nent = (uint8_t)nent; + snap->nslots = (uint8_t)nslots; + snap->count = 0; + J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth); +} + +/* Add or merge a snapshot. */ +void lj_snap_add(jit_State *J) +{ + MSize nsnap = J->cur.nsnap; + MSize nsnapmap = J->cur.nsnapmap; + /* Merge if no ins. inbetween or if requested and no guard inbetween. */ + if (J->mergesnap ? !irt_isguard(J->guardemit) : + (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) { + if (nsnap == 1) { /* But preserve snap #0 PC. */ + emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); + goto nomerge; + } + nsnapmap = J->cur.snap[--nsnap].mapofs; + } else { + nomerge: + lj_snap_grow_buf(J, nsnap+1); + J->cur.nsnap = (uint16_t)(nsnap+1); + } + J->mergesnap = 0; + J->guardemit.irt = 0; + snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap); +} + +/* -- Snapshot modification ----------------------------------------------- */ + +#define SNAP_USEDEF_SLOTS (LJ_MAX_JSLOTS+LJ_STACK_EXTRA) + +/* Find unused slots with reaching-definitions bytecode data-flow analysis. */ +static BCReg snap_usedef(jit_State *J, uint8_t *udf, + const BCIns *pc, BCReg maxslot) +{ + BCReg s; + GCobj *o; + + if (maxslot == 0) return 0; +#ifdef LUAJIT_USE_VALGRIND + /* Avoid errors for harmless reads beyond maxslot. */ + memset(udf, 1, SNAP_USEDEF_SLOTS); +#else + memset(udf, 1, maxslot); +#endif + + /* Treat open upvalues as used. */ + o = gcref(J->L->openupval); + while (o) { + if (uvval(gco2uv(o)) < J->L->base) break; + udf[uvval(gco2uv(o)) - J->L->base] = 0; + o = gcref(o->gch.nextgc); + } + +#define USE_SLOT(s) udf[(s)] &= ~1 +#define DEF_SLOT(s) udf[(s)] *= 3 + + /* Scan through following bytecode and check for uses/defs. */ + lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc); + for (;;) { + BCIns ins = *pc++; + BCOp op = bc_op(ins); + switch (bcmode_b(op)) { + case BCMvar: USE_SLOT(bc_b(ins)); break; + default: break; + } + switch (bcmode_c(op)) { + case BCMvar: USE_SLOT(bc_c(ins)); break; + case BCMrbase: + lua_assert(op == BC_CAT); + for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + break; + case BCMjump: + handle_jump: { + BCReg minslot = bc_a(ins); + if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT; + else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1; + else if (op == BC_UCLO) { pc += bc_j(ins); break; } + for (s = minslot; s < maxslot; s++) DEF_SLOT(s); + return minslot < maxslot ? minslot : maxslot; + } + case BCMlit: + if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) { + goto handle_jump; + } else if (bc_isret(op)) { + BCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1); + for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s); + for (; s < top; s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + return 0; + } + break; + case BCMfunc: return maxslot; /* NYI: will abort, anyway. */ + default: break; + } + switch (bcmode_a(op)) { + case BCMvar: USE_SLOT(bc_a(ins)); break; + case BCMdst: + if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins)); + break; + case BCMbase: + if (op >= BC_CALLM && op <= BC_VARG) { + BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ? + maxslot : (bc_a(ins) + bc_c(ins)); + s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0); + for (; s < top; s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + if (op == BC_CALLT || op == BC_CALLMT) { + for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s); + return 0; + } + } else if (op == BC_KNIL) { + for (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s); + } else if (op == BC_TSETM) { + for (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s); + } + break; + default: break; + } + lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc); + } + +#undef USE_SLOT +#undef DEF_SLOT + + return 0; /* unreachable */ +} + +/* Purge dead slots before the next snapshot. */ +void lj_snap_purge(jit_State *J) +{ + uint8_t udf[SNAP_USEDEF_SLOTS]; + BCReg maxslot = J->maxslot; + BCReg s = snap_usedef(J, udf, J->pc, maxslot); + for (; s < maxslot; s++) + if (udf[s] != 0) + J->base[s] = 0; /* Purge dead slots. */ +} + +/* Shrink last snapshot. */ +void lj_snap_shrink(jit_State *J) +{ + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, m, nlim, nent = snap->nent; + uint8_t udf[SNAP_USEDEF_SLOTS]; + BCReg maxslot = J->maxslot; + BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot); + BCReg baseslot = J->baseslot; + maxslot += baseslot; + minslot += baseslot; + snap->nslots = (uint8_t)maxslot; + for (n = m = 0; n < nent; n++) { /* Remove unused slots from snapshot. */ + BCReg s = snap_slot(map[n]); + if (s < minslot || (s < maxslot && udf[s-baseslot] == 0)) + map[m++] = map[n]; /* Only copy used slots. */ + } + snap->nent = (uint8_t)m; + nlim = J->cur.nsnapmap - snap->mapofs - 1; + while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */ + J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */ +} + +/* -- Snapshot access ----------------------------------------------------- */ + +/* Initialize a Bloom Filter with all renamed refs. +** There are very few renames (often none), so the filter has +** very few bits set. This makes it suitable for negative filtering. +*/ +static BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim) +{ + BloomFilter rfilt = 0; + IRIns *ir; + for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--) + if (ir->op2 <= lim) + bloomset(rfilt, ir->op1); + return rfilt; +} + +/* Process matching renames to find the original RegSP. */ +static RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs) +{ + IRIns *ir; + for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--) + if (ir->op1 == ref && ir->op2 <= lim) + rs = ir->prev; + return rs; +} + +/* Copy RegSP from parent snapshot to the parent links of the IR. */ +IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir) +{ + SnapShot *snap = &T->snap[snapno]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + BloomFilter rfilt = snap_renamefilter(T, snapno); + MSize n = 0; + IRRef ref = 0; + for ( ; ; ir++) { + uint32_t rs; + if (ir->o == IR_SLOAD) { + if (!(ir->op2 & IRSLOAD_PARENT)) break; + for ( ; ; n++) { + lua_assert(n < snap->nent); + if (snap_slot(map[n]) == ir->op1) { + ref = snap_ref(map[n++]); + break; + } + } + } else if (LJ_SOFTFP && ir->o == IR_HIOP) { + ref++; + } else if (ir->o == IR_PVAL) { + ref = ir->op1 + REF_BIAS; + } else { + break; + } + rs = T->ir[ref].prev; + if (bloomtest(rfilt, ref)) + rs = snap_renameref(T, snapno, ref, rs); + ir->prev = (uint16_t)rs; + lua_assert(regsp_used(rs)); + } + return ir; +} + +/* -- Snapshot replay ----------------------------------------------------- */ + +/* Replay constant from parent trace. */ +static TRef snap_replay_const(jit_State *J, IRIns *ir) +{ + /* Only have to deal with constants that can occur in stack slots. */ + switch ((IROp)ir->o) { + case IR_KPRI: return TREF_PRI(irt_type(ir->t)); + case IR_KINT: return lj_ir_kint(J, ir->i); + case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); + case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir)); + case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir)); + case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ + default: lua_assert(0); return TREF_NIL; break; + } +} + +/* De-duplicate parent reference. */ +static TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref) +{ + MSize j; + for (j = 0; j < nmax; j++) + if (snap_ref(map[j]) == ref) + return J->slot[snap_slot(map[j])] & ~(SNAP_CONT|SNAP_FRAME); + return 0; +} + +/* Emit parent reference with de-duplication. */ +static TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax, + BloomFilter seen, IRRef ref) +{ + IRIns *ir = &T->ir[ref]; + TRef tr; + if (irref_isk(ref)) + tr = snap_replay_const(J, ir); + else if (!regsp_used(ir->prev)) + tr = 0; + else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0) + tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0); + return tr; +} + +/* Check whether a sunk store corresponds to an allocation. Slow path. */ +static int snap_sunk_store2(jit_State *J, IRIns *ira, IRIns *irs) +{ + if (irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE) { + IRIns *irk = IR(irs->op1); + if (irk->o == IR_AREF || irk->o == IR_HREFK) + irk = IR(irk->op1); + return (IR(irk->op1) == ira); + } + return 0; +} + +/* Check whether a sunk store corresponds to an allocation. Fast path. */ +static LJ_AINLINE int snap_sunk_store(jit_State *J, IRIns *ira, IRIns *irs) +{ + if (irs->s != 255) + return (ira + irs->s == irs); /* Fast check. */ + return snap_sunk_store2(J, ira, irs); +} + +/* Replay snapshot state to setup side trace. */ +void lj_snap_replay(jit_State *J, GCtrace *T) +{ + SnapShot *snap = &T->snap[J->exitno]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + BloomFilter seen = 0; + int pass23 = 0; + J->framedepth = 0; + /* Emit IR for slots inherited from parent snapshot. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + IRRef ref = snap_ref(sn); + IRIns *ir = &T->ir[ref]; + TRef tr; + /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */ + if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0) + goto setslot; + bloomset(seen, ref); + if (irref_isk(ref)) { + tr = snap_replay_const(J, ir); + } else if (!regsp_used(ir->prev)) { + pass23 = 1; + lua_assert(s != 0); + tr = s; + } else { + IRType t = irt_type(ir->t); + uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT; + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; + if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY); + tr = emitir_raw(IRT(IR_SLOAD, t), s, mode); + } + setslot: + J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ + J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); + if ((sn & SNAP_FRAME)) + J->baseslot = s+1; + } + if (pass23) { + IRIns *irlast = &T->ir[snap->ref]; + pass23 = 0; + /* Emit dependent PVALs. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef refp = snap_ref(sn); + IRIns *ir = &T->ir[refp]; + if (regsp_reg(ir->r) == RID_SUNK) { + if (J->slot[snap_slot(sn)] != snap_slot(sn)) continue; + pass23 = 1; + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || + ir->o == IR_CNEW || ir->o == IR_CNEWI); + if (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1); + if (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2); + if (LJ_HASFFI && ir->o == IR_CNEWI) { + if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) + snap_pref(J, T, map, nent, seen, (ir+1)->op2); + } else { + IRIns *irs; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (snap_pref(J, T, map, nent, seen, irs->op2) == 0) + snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1); + else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && + irs+1 < irlast && (irs+1)->o == IR_HIOP) + snap_pref(J, T, map, nent, seen, (irs+1)->op2); + } + } + } else if (!irref_isk(refp) && !regsp_used(ir->prev)) { + lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + J->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1); + } + } + /* Replay sunk instructions. */ + for (n = 0; pass23 && n < nent; n++) { + SnapEntry sn = map[n]; + IRRef refp = snap_ref(sn); + IRIns *ir = &T->ir[refp]; + if (regsp_reg(ir->r) == RID_SUNK) { + TRef op1, op2; + if (J->slot[snap_slot(sn)] != snap_slot(sn)) { /* De-dup allocs. */ + J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]]; + continue; + } + op1 = ir->op1; + if (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1); + op2 = ir->op2; + if (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2); + if (LJ_HASFFI && ir->o == IR_CNEWI) { + if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) { + lj_needsplit(J); /* Emit joining HIOP. */ + op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2, + snap_pref(J, T, map, nent, seen, (ir+1)->op2)); + } + J->slot[snap_slot(sn)] = emitir(ir->ot, op1, op2); + } else { + IRIns *irs; + TRef tr = emitir(ir->ot, op1, op2); + J->slot[snap_slot(sn)] = tr; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *irr = &T->ir[irs->op1]; + TRef val, key = irr->op2, tmp = tr; + if (irr->o != IR_FREF) { + IRIns *irk = &T->ir[key]; + if (irr->o == IR_HREFK) + key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]), + irk->op2); + else + key = snap_replay_const(J, irk); + if (irr->o == IR_HREFK || irr->o == IR_AREF) { + IRIns *irf = &T->ir[irr->op1]; + tmp = emitir(irf->ot, tmp, irf->op2); + } + } + tmp = emitir(irr->ot, tmp, key); + val = snap_pref(J, T, map, nent, seen, irs->op2); + if (val == 0) { + IRIns *irc = &T->ir[irs->op2]; + lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT); + val = snap_pref(J, T, map, nent, seen, irc->op1); + val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); + } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && + irs+1 < irlast && (irs+1)->o == IR_HIOP) { + IRType t = IRT_I64; + if (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP) + t = IRT_NUM; + lj_needsplit(J); + if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) { + uint64_t k = (uint32_t)T->ir[irs->op2].i + + ((uint64_t)T->ir[(irs+1)->op2].i << 32); + val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM, + lj_ir_k64_find(J, k)); + } else { + val = emitir_raw(IRT(IR_HIOP, t), val, + snap_pref(J, T, map, nent, seen, (irs+1)->op2)); + } + tmp = emitir(IRT(irs->o, t), tmp, val); + continue; + } + tmp = emitir(irs->ot, tmp, val); + } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) { + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); + } + } + } + } + } + J->base = J->slot + J->baseslot; + J->maxslot = snap->nslots - J->baseslot; + lj_snap_add(J); + if (pass23) /* Need explicit GC step _after_ initial snapshot. */ + emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0); +} + +/* -- Snapshot restore ---------------------------------------------------- */ + +static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRIns *ir, TValue *o); + +/* Restore a value from the trace exit state. */ +static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRRef ref, TValue *o) +{ + IRIns *ir = &T->ir[ref]; + IRType1 t = ir->t; + RegSP rs = ir->prev; + if (irref_isk(ref)) { /* Restore constant slot. */ + lj_ir_kvalue(J->L, o, ir); + return; + } + if (LJ_UNLIKELY(bloomtest(rfilt, ref))) + rs = snap_renameref(T, snapno, ref, rs); + if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */ + int32_t *sps = &ex->spill[regsp_spill(rs)]; + if (irt_isinteger(t)) { + setintV(o, *sps); +#if !LJ_SOFTFP + } else if (irt_isnum(t)) { + o->u64 = *(uint64_t *)sps; +#endif + } else if (LJ_64 && irt_islightud(t)) { + /* 64 bit lightuserdata which may escape already has the tag bits. */ + o->u64 = *(uint64_t *)sps; + } else { + lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */ + setgcrefi(o->gcr, *sps); + setitype(o, irt_toitype(t)); + } + } else { /* Restore from register. */ + Reg r = regsp_reg(rs); + if (ra_noreg(r)) { + lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o); + if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o)); + return; + } else if (irt_isinteger(t)) { + setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]); +#if !LJ_SOFTFP + } else if (irt_isnum(t)) { + setnumV(o, ex->fpr[r-RID_MIN_FPR]); +#endif + } else if (LJ_64 && irt_islightud(t)) { + /* 64 bit lightuserdata which may escape already has the tag bits. */ + o->u64 = ex->gpr[r-RID_MIN_GPR]; + } else { + if (!irt_ispri(t)) + setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]); + setitype(o, irt_toitype(t)); + } + } +} + +#if LJ_HASFFI +/* Restore raw data from the trace exit state. */ +static void snap_restoredata(GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRRef ref, void *dst, CTSize sz) +{ + IRIns *ir = &T->ir[ref]; + RegSP rs = ir->prev; + int32_t *src; + uint64_t tmp; + if (irref_isk(ref)) { + if (ir->o == IR_KNUM || ir->o == IR_KINT64) { + src = mref(ir->ptr, int32_t); + } else if (sz == 8) { + tmp = (uint64_t)(uint32_t)ir->i; + src = (int32_t *)&tmp; + } else { + src = &ir->i; + } + } else { + if (LJ_UNLIKELY(bloomtest(rfilt, ref))) + rs = snap_renameref(T, snapno, ref, rs); + if (ra_hasspill(regsp_spill(rs))) { + src = &ex->spill[regsp_spill(rs)]; + if (sz == 8 && !irt_is64(ir->t)) { + tmp = (uint64_t)(uint32_t)*src; + src = (int32_t *)&tmp; + } + } else { + Reg r = regsp_reg(rs); + if (ra_noreg(r)) { + /* Note: this assumes CNEWI is never used for SOFTFP split numbers. */ + lua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + snap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4); + *(lua_Number *)dst = (lua_Number)*(int32_t *)dst; + return; + } + src = (int32_t *)&ex->gpr[r-RID_MIN_GPR]; +#if !LJ_SOFTFP + if (r >= RID_MAX_GPR) { + src = (int32_t *)&ex->fpr[r-RID_MIN_FPR]; +#if LJ_TARGET_PPC + if (sz == 4) { /* PPC FPRs are always doubles. */ + *(float *)dst = (float)*(double *)src; + return; + } +#else + if (LJ_BE && sz == 4) src++; +#endif + } +#endif + } + } + lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8); + if (sz == 4) *(int32_t *)dst = *src; + else if (sz == 8) *(int64_t *)dst = *(int64_t *)src; + else if (sz == 1) *(int8_t *)dst = (int8_t)*src; + else *(int16_t *)dst = (int16_t)*src; +} +#endif + +/* Unsink allocation from the trace exit state. Unsink sunk stores. */ +static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRIns *ir, TValue *o) +{ + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || + ir->o == IR_CNEW || ir->o == IR_CNEWI); +#if LJ_HASFFI + if (ir->o == IR_CNEW || ir->o == IR_CNEWI) { + CTState *cts = ctype_cts(J->L); + CTypeID id = (CTypeID)T->ir[ir->op1].i; + CTSize sz = lj_ctype_size(cts, id); + GCcdata *cd = lj_cdata_new(cts, id, sz); + setcdataV(J->L, o, cd); + if (ir->o == IR_CNEWI) { + uint8_t *p = (uint8_t *)cdataptr(cd); + lua_assert(sz == 4 || sz == 8); + if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) { + snap_restoredata(T, ex, snapno, rfilt, (ir+1)->op2, LJ_LE?p+4:p, 4); + if (LJ_BE) p += 4; + sz = 4; + } + snap_restoredata(T, ex, snapno, rfilt, ir->op2, p, sz); + } else { + IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref]; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *iro = &T->ir[T->ir[irs->op1].op2]; + uint8_t *p = (uint8_t *)cd; + CTSize szs; + lua_assert(irs->o == IR_XSTORE && T->ir[irs->op1].o == IR_ADD); + lua_assert(iro->o == IR_KINT || iro->o == IR_KINT64); + if (irt_is64(irs->t)) szs = 8; + else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1; + else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2; + else szs = 4; + if (LJ_64 && iro->o == IR_KINT64) + p += (int64_t)ir_k64(iro)->u64; + else + p += iro->i; + lua_assert(p >= (uint8_t *)cdataptr(cd) && + p + szs <= (uint8_t *)cdataptr(cd) + sz); + if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { + lua_assert(szs == 4); + snap_restoredata(T, ex, snapno, rfilt, (irs+1)->op2, LJ_LE?p+4:p,4); + if (LJ_BE) p += 4; + } + snap_restoredata(T, ex, snapno, rfilt, irs->op2, p, szs); + } + } + } else +#endif + { + IRIns *irs, *irlast; + GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) : + lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1])); + settabV(J->L, o, t); + irlast = &T->ir[T->snap[snapno].ref]; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *irk = &T->ir[irs->op1]; + TValue tmp, *val; + lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE); + if (irk->o == IR_FREF) { + lua_assert(irk->op2 == IRFL_TAB_META); + snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp); + /* NOBARRIER: The table is new (marked white). */ + setgcref(t->metatable, obj2gco(tabV(&tmp))); + } else { + irk = &T->ir[irk->op2]; + if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1]; + lj_ir_kvalue(J->L, &tmp, irk); + val = lj_tab_set(J->L, t, &tmp); + /* NOBARRIER: The table is new (marked white). */ + snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val); + if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { + snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp); + val->u32.hi = tmp.u32.lo; + } + } + } + } +} + +/* Restore interpreter state from exit state with the help of a snapshot. */ +const BCIns *lj_snap_restore(jit_State *J, void *exptr) +{ + ExitState *ex = (ExitState *)exptr; + SnapNo snapno = J->exitno; /* For now, snapno == exitno. */ + GCtrace *T = traceref(J, J->parent); + SnapShot *snap = &T->snap[snapno]; + MSize n, nent = snap->nent; + SnapEntry *map = &T->snapmap[snap->mapofs]; + SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; + int32_t ftsz0; + TValue *frame; + BloomFilter rfilt = snap_renamefilter(T, snapno); + const BCIns *pc = snap_pc(map[nent]); + lua_State *L = J->L; + + /* Set interpreter PC to the next PC to get correct error messages. */ + setcframe_pc(cframe_raw(L->cframe), pc+1); + + /* Make sure the stack is big enough for the slots from the snapshot. */ + if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) { + L->top = curr_topL(L); + lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize); + } + + /* Fill stack slots with data from the registers and spill slots. */ + frame = L->base-1; + ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + if (!(sn & SNAP_NORESTORE)) { + TValue *o = &frame[snap_slot(sn)]; + IRRef ref = snap_ref(sn); + IRIns *ir = &T->ir[ref]; + if (ir->r == RID_SUNK) { + MSize j; + for (j = 0; j < n; j++) + if (snap_ref(map[j]) == ref) { /* De-duplicate sunk allocations. */ + copyTV(L, o, &frame[snap_slot(map[j])]); + goto dupslot; + } + snap_unsink(J, T, ex, snapno, rfilt, ir, o); + dupslot: + continue; + } + snap_restoreval(J, T, ex, snapno, rfilt, ref, o); + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) { + TValue tmp; + snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp); + o->u32.hi = tmp.u32.lo; + } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { + /* Overwrite tag with frame link. */ + o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0; + L->base = o+1; + } + } + } + lua_assert(map + nent == flinks); + + /* Compute current stack top. */ + switch (bc_op(*pc)) { + default: + if (bc_op(*pc) < BC_FUNCF) { + L->top = curr_topL(L); + break; + } + /* fallthrough */ + case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM: + L->top = frame + snap->nslots; + break; + } + return pc; +} + +#undef IR +#undef emitir_raw +#undef emitir + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.h new file mode 100644 index 0000000..1b2d74d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_snap.h @@ -0,0 +1,34 @@ +/* +** Snapshot handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_SNAP_H +#define _LJ_SNAP_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +LJ_FUNC void lj_snap_add(jit_State *J); +LJ_FUNC void lj_snap_purge(jit_State *J); +LJ_FUNC void lj_snap_shrink(jit_State *J); +LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir); +LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T); +LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr); +LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need); +LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need); + +static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need) +{ + if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need); +} + +static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need) +{ + if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need); +} + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.c new file mode 100644 index 0000000..f972fdc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.c @@ -0,0 +1,287 @@ +/* +** State and stack handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_state_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_trace.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_lex.h" +#include "lj_alloc.h" + +/* -- Stack handling ------------------------------------------------------ */ + +/* Stack sizes. */ +#define LJ_STACK_MIN LUA_MINSTACK /* Min. stack size. */ +#define LJ_STACK_MAX LUAI_MAXSTACK /* Max. stack size. */ +#define LJ_STACK_START (2*LJ_STACK_MIN) /* Starting stack size. */ +#define LJ_STACK_MAXEX (LJ_STACK_MAX + 1 + LJ_STACK_EXTRA) + +/* Explanation of LJ_STACK_EXTRA: +** +** Calls to metamethods store their arguments beyond the current top +** without checking for the stack limit. This avoids stack resizes which +** would invalidate passed TValue pointers. The stack check is performed +** later by the function header. This can safely resize the stack or raise +** an error. Thus we need some extra slots beyond the current stack limit. +** +** Most metamethods need 4 slots above top (cont, mobj, arg1, arg2) plus +** one extra slot if mobj is not a function. Only lj_meta_tset needs 5 +** slots above top, but then mobj is always a function. So we can get by +** with 5 extra slots. +*/ + +/* Resize stack slots and adjust pointers in state. */ +static void resizestack(lua_State *L, MSize n) +{ + TValue *st, *oldst = tvref(L->stack); + ptrdiff_t delta; + MSize oldsize = L->stacksize; + MSize realsize = n + 1 + LJ_STACK_EXTRA; + GCobj *up; + lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1); + st = (TValue *)lj_mem_realloc(L, tvref(L->stack), + (MSize)(L->stacksize*sizeof(TValue)), + (MSize)(realsize*sizeof(TValue))); + setmref(L->stack, st); + delta = (char *)st - (char *)oldst; + setmref(L->maxstack, st + n); + while (oldsize < realsize) /* Clear new slots. */ + setnilV(st + oldsize++); + L->stacksize = realsize; + L->base = (TValue *)((char *)L->base + delta); + L->top = (TValue *)((char *)L->top + delta); + for (up = gcref(L->openupval); up != NULL; up = gcnext(up)) + setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta)); + if (obj2gco(L) == gcref(G(L)->jit_L)) + setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta); +} + +/* Relimit stack after error, in case the limit was overdrawn. */ +void lj_state_relimitstack(lua_State *L) +{ + if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1) + resizestack(L, LJ_STACK_MAX); +} + +/* Try to shrink the stack (called from GC). */ +void lj_state_shrinkstack(lua_State *L, MSize used) +{ + if (L->stacksize > LJ_STACK_MAXEX) + return; /* Avoid stack shrinking while handling stack overflow. */ + if (4*used < L->stacksize && + 2*(LJ_STACK_START+LJ_STACK_EXTRA) < L->stacksize && + obj2gco(L) != gcref(G(L)->jit_L)) /* Don't shrink stack of live trace. */ + resizestack(L, L->stacksize >> 1); +} + +/* Try to grow stack. */ +void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) +{ + MSize n; + if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */ + lj_err_throw(L, LUA_ERRERR); + n = L->stacksize + need; + if (n > LJ_STACK_MAX) { + n += 2*LUA_MINSTACK; + } else if (n < 2*L->stacksize) { + n = 2*L->stacksize; + if (n >= LJ_STACK_MAX) + n = LJ_STACK_MAX; + } + resizestack(L, n); + if (L->stacksize > LJ_STACK_MAXEX) + lj_err_msg(L, LJ_ERR_STKOV); +} + +void LJ_FASTCALL lj_state_growstack1(lua_State *L) +{ + lj_state_growstack(L, 1); +} + +/* Allocate basic stack for new state. */ +static void stack_init(lua_State *L1, lua_State *L) +{ + TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue); + setmref(L1->stack, st); + L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA; + stend = st + L1->stacksize; + setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1); + L1->base = L1->top = st+1; + setthreadV(L1, st, L1); /* Needed for curr_funcisL() on empty stack. */ + while (st < stend) /* Clear new slots. */ + setnilV(st++); +} + +/* -- State handling ------------------------------------------------------ */ + +/* Open parts that may cause memory-allocation errors. */ +static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud) +{ + global_State *g = G(L); + UNUSED(dummy); + UNUSED(ud); + stack_init(L, L); + /* NOBARRIER: State initialization, all objects are white. */ + setgcref(L->env, obj2gco(lj_tab_new(L, 0, LJ_MIN_GLOBAL))); + settabV(L, registry(L), lj_tab_new(L, 0, LJ_MIN_REGISTRY)); + lj_str_resize(L, LJ_MIN_STRTAB-1); + lj_meta_init(L); + lj_lex_init(L); + fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */ + g->gc.threshold = 4*g->gc.total; + lj_trace_initstate(g); + return NULL; +} + +static void close_state(lua_State *L) +{ + global_State *g = G(L); + lj_func_closeuv(L, tvref(L->stack)); + lj_gc_freeall(g); + lua_assert(gcref(g->gc.root) == obj2gco(L)); + lua_assert(g->strnum == 0); + lj_trace_freestate(g); +#if LJ_HASFFI + lj_ctype_freestate(g); +#endif + lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); + lj_str_freebuf(g, &g->tmpbuf); + lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); + lua_assert(g->gc.total == sizeof(GG_State)); +#ifndef LUAJIT_USE_SYSMALLOC + if (g->allocf == lj_alloc_f) + lj_alloc_destroy(g->allocd); + else +#endif + g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); +} + +#if LJ_64 +lua_State *lj_state_newstate(lua_Alloc f, void *ud) +#else +LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) +#endif +{ + GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State)); + lua_State *L = &GG->L; + global_State *g = &GG->g; + if (GG == NULL || !checkptr32(GG)) return NULL; + memset(GG, 0, sizeof(GG_State)); + L->gct = ~LJ_TTHREAD; + L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */ + L->dummy_ffid = FF_C; + setmref(L->glref, g); + g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED; + g->strempty.marked = LJ_GC_WHITE0; + g->strempty.gct = ~LJ_TSTR; + g->allocf = f; + g->allocd = ud; + setgcref(g->mainthref, obj2gco(L)); + setgcref(g->uvhead.prev, obj2gco(&g->uvhead)); + setgcref(g->uvhead.next, obj2gco(&g->uvhead)); + g->strmask = ~(MSize)0; + setnilV(registry(L)); + setnilV(&g->nilnode.val); + setnilV(&g->nilnode.key); + setmref(g->nilnode.freetop, &g->nilnode); + lj_str_initbuf(&g->tmpbuf); + g->gc.state = GCSpause; + setgcref(g->gc.root, obj2gco(L)); + setmref(g->gc.sweep, &g->gc.root); + g->gc.total = sizeof(GG_State); + g->gc.pause = LUAI_GCPAUSE; + g->gc.stepmul = LUAI_GCMUL; + lj_dispatch_init((GG_State *)L); + L->status = LUA_ERRERR+1; /* Avoid touching the stack upon memory error. */ + if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) { + /* Memory allocation error: free partial state. */ + close_state(L); + return NULL; + } + L->status = 0; + return L; +} + +static TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud) +{ + UNUSED(dummy); + UNUSED(ud); + lj_gc_finalize_cdata(L); + lj_gc_finalize_udata(L); + /* Frame pop omitted. */ + return NULL; +} + +LUA_API void lua_close(lua_State *L) +{ + global_State *g = G(L); + int i; + L = mainthread(g); /* Only the main thread can be closed. */ + lj_func_closeuv(L, tvref(L->stack)); + lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */ +#if LJ_HASJIT + G2J(g)->flags &= ~JIT_F_ON; + G2J(g)->state = LJ_TRACE_IDLE; + lj_dispatch_update(g); +#endif + for (i = 0;;) { + hook_enter(g); + L->status = 0; + L->cframe = NULL; + L->base = L->top = tvref(L->stack) + 1; + if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == 0) { + if (++i >= 10) break; + lj_gc_separateudata(g, 1); /* Separate udata again. */ + if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */ + break; + } + } + close_state(L); +} + +lua_State *lj_state_new(lua_State *L) +{ + lua_State *L1 = lj_mem_newobj(L, lua_State); + L1->gct = ~LJ_TTHREAD; + L1->dummy_ffid = FF_C; + L1->status = 0; + L1->stacksize = 0; + setmref(L1->stack, NULL); + L1->cframe = NULL; + /* NOBARRIER: The lua_State is new (marked white). */ + setgcrefnull(L1->openupval); + setmrefr(L1->glref, L->glref); + setgcrefr(L1->env, L->env); + stack_init(L1, L); /* init stack */ + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + +void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L) +{ + lua_assert(L != mainthread(g)); + lj_func_closeuv(L, tvref(L->stack)); + lua_assert(gcref(L->openupval) == NULL); + lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); + lj_mem_freet(g, L); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.h new file mode 100644 index 0000000..74249d9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_state.h @@ -0,0 +1,35 @@ +/* +** State and stack handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STATE_H +#define _LJ_STATE_H + +#include "lj_obj.h" + +#define incr_top(L) \ + (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0)) + +#define savestack(L, p) ((char *)(p) - mref(L->stack, char)) +#define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n))) + +LJ_FUNC void lj_state_relimitstack(lua_State *L); +LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used); +LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need); +LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L); + +static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need) +{ + if ((mref(L->maxstack, char) - (char *)L->top) <= + (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue)) + lj_state_growstack(L, need); +} + +LJ_FUNC lua_State *lj_state_new(lua_State *L); +LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L); +#if LJ_64 +LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.c new file mode 100644 index 0000000..aead8b5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.c @@ -0,0 +1,339 @@ +/* +** String handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lj_str_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_state.h" +#include "lj_char.h" + +/* -- String interning ---------------------------------------------------- */ + +/* Ordered compare of strings. Assumes string data is 4-byte aligned. */ +int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) +{ + MSize i, n = a->len > b->len ? b->len : a->len; + for (i = 0; i < n; i += 4) { + /* Note: innocuous access up to end of string + 3. */ + uint32_t va = *(const uint32_t *)(strdata(a)+i); + uint32_t vb = *(const uint32_t *)(strdata(b)+i); + if (va != vb) { +#if LJ_LE + va = lj_bswap(va); vb = lj_bswap(vb); +#endif + i -= n; + if ((int32_t)i >= -3) { + va >>= 32+(i<<3); vb >>= 32+(i<<3); + if (va == vb) break; + } + return va < vb ? -1 : 1; + } + } + return (int32_t)(a->len - b->len); +} + +/* Fast string data comparison. Caveat: unaligned access to 1st string! */ +static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) +{ + MSize i = 0; + lua_assert(len > 0); + lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); + do { /* Note: innocuous access up to end of string + 3. */ + uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); + if (v) { + i -= len; +#if LJ_LE + return (int32_t)i >= -3 ? (v << (32+(i<<3))) : 1; +#else + return (int32_t)i >= -3 ? (v >> (32+(i<<3))) : 1; +#endif + } + i += 4; + } while (i < len); + return 0; +} + +/* Resize the string hash table (grow and shrink). */ +void lj_str_resize(lua_State *L, MSize newmask) +{ + global_State *g = G(L); + GCRef *newhash; + MSize i; + if (g->gc.state == GCSsweepstring || newmask >= LJ_MAX_STRTAB-1) + return; /* No resizing during GC traversal or if already too big. */ + newhash = lj_mem_newvec(L, newmask+1, GCRef); + memset(newhash, 0, (newmask+1)*sizeof(GCRef)); + for (i = g->strmask; i != ~(MSize)0; i--) { /* Rehash old table. */ + GCobj *p = gcref(g->strhash[i]); + while (p) { /* Follow each hash chain and reinsert all strings. */ + MSize h = gco2str(p)->hash & newmask; + GCobj *next = gcnext(p); + /* NOBARRIER: The string table is a GC root. */ + setgcrefr(p->gch.nextgc, newhash[h]); + setgcref(newhash[h], p); + p = next; + } + } + lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); + g->strmask = newmask; + g->strhash = newhash; +} + +/* Intern a string and return string object. */ +GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) +{ + global_State *g; + GCstr *s; + GCobj *o; + MSize len = (MSize)lenx; + MSize a, b, h = len; + if (lenx >= LJ_MAX_STR) + lj_err_msg(L, LJ_ERR_STROV); + g = G(L); + /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */ + if (len >= 4) { /* Caveat: unaligned access! */ + a = lj_getu32(str); + h ^= lj_getu32(str+len-4); + b = lj_getu32(str+(len>>1)-2); + h ^= b; h -= lj_rol(b, 14); + b += lj_getu32(str+(len>>2)-1); + } else if (len > 0) { + a = *(const uint8_t *)str; + h ^= *(const uint8_t *)(str+len-1); + b = *(const uint8_t *)(str+(len>>1)); + h ^= b; h -= lj_rol(b, 14); + } else { + return &g->strempty; + } + a ^= h; a -= lj_rol(h, 11); + b ^= a; b -= lj_rol(a, 25); + h ^= b; h -= lj_rol(b, 16); + /* Check if the string has already been interned. */ + o = gcref(g->strhash[h & g->strmask]); + if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { + while (o != NULL) { + GCstr *sx = gco2str(o); + if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) { + /* Resurrect if dead. Can only happen with fixstring() (keywords). */ + if (isdead(g, o)) flipwhite(o); + return sx; /* Return existing string. */ + } + o = gcnext(o); + } + } else { /* Slow path: end of string is too close to a page boundary. */ + while (o != NULL) { + GCstr *sx = gco2str(o); + if (sx->len == len && memcmp(str, strdata(sx), len) == 0) { + /* Resurrect if dead. Can only happen with fixstring() (keywords). */ + if (isdead(g, o)) flipwhite(o); + return sx; /* Return existing string. */ + } + o = gcnext(o); + } + } + /* Nope, create a new string. */ + s = lj_mem_newt(L, sizeof(GCstr)+len+1, GCstr); + newwhite(g, s); + s->gct = ~LJ_TSTR; + s->len = len; + s->hash = h; + s->reserved = 0; + memcpy(strdatawr(s), str, len); + strdatawr(s)[len] = '\0'; /* Zero-terminate string. */ + /* Add it to string hash table. */ + h &= g->strmask; + s->nextgc = g->strhash[h]; + /* NOBARRIER: The string table is a GC root. */ + setgcref(g->strhash[h], obj2gco(s)); + if (g->strnum++ > g->strmask) /* Allow a 100% load factor. */ + lj_str_resize(L, (g->strmask<<1)+1); /* Grow string table. */ + return s; /* Return newly interned string. */ +} + +void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) +{ + g->strnum--; + lj_mem_free(g, s, sizestring(s)); +} + +/* -- Type conversions ---------------------------------------------------- */ + +/* Print number to buffer. Canonicalizes non-finite values. */ +size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o) +{ + if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */ + lua_Number n = o->n; +#if __BIONIC__ + if (tvismzero(o)) { s[0] = '-'; s[1] = '0'; return 2; } +#endif + return (size_t)lua_number2str(s, n); + } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) { + s[0] = 'n'; s[1] = 'a'; s[2] = 'n'; return 3; + } else if ((o->u32.hi & 0x80000000) == 0) { + s[0] = 'i'; s[1] = 'n'; s[2] = 'f'; return 3; + } else { + s[0] = '-'; s[1] = 'i'; s[2] = 'n'; s[3] = 'f'; return 4; + } +} + +/* Print integer to buffer. Returns pointer to start. */ +char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k) +{ + uint32_t u = (uint32_t)(k < 0 ? -k : k); + p += 1+10; + do { *--p = (char)('0' + u % 10); } while (u /= 10); + if (k < 0) *--p = '-'; + return p; +} + +/* Convert number to string. */ +GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np) +{ + char buf[LJ_STR_NUMBUF]; + size_t len = lj_str_bufnum(buf, (TValue *)np); + return lj_str_new(L, buf, len); +} + +/* Convert integer to string. */ +GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k) +{ + char s[1+10]; + char *p = lj_str_bufint(s, k); + return lj_str_new(L, p, (size_t)(s+sizeof(s)-p)); +} + +GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o) +{ + return tvisint(o) ? lj_str_fromint(L, intV(o)) : lj_str_fromnum(L, &o->n); +} + +/* -- String formatting --------------------------------------------------- */ + +static void addstr(lua_State *L, SBuf *sb, const char *str, MSize len) +{ + char *p; + MSize i; + if (sb->n + len > sb->sz) { + MSize sz = sb->sz * 2; + while (sb->n + len > sz) sz = sz * 2; + lj_str_resizebuf(L, sb, sz); + } + p = sb->buf + sb->n; + sb->n += len; + for (i = 0; i < len; i++) p[i] = str[i]; +} + +static void addchar(lua_State *L, SBuf *sb, int c) +{ + if (sb->n + 1 > sb->sz) { + MSize sz = sb->sz * 2; + lj_str_resizebuf(L, sb, sz); + } + sb->buf[sb->n++] = (char)c; +} + +/* Push formatted message as a string object to Lua stack. va_list variant. */ +const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp) +{ + SBuf *sb = &G(L)->tmpbuf; + lj_str_needbuf(L, sb, (MSize)strlen(fmt)); + lj_str_resetbuf(sb); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + addstr(L, sb, fmt, (MSize)(e-fmt)); + /* This function only handles %s, %c, %d, %f and %p formats. */ + switch (e[1]) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + addstr(L, sb, s, (MSize)strlen(s)); + break; + } + case 'c': + addchar(L, sb, va_arg(argp, int)); + break; + case 'd': { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, va_arg(argp, int32_t)); + addstr(L, sb, p, (MSize)(buf+LJ_STR_INTBUF-p)); + break; + } + case 'f': { + char buf[LJ_STR_NUMBUF]; + TValue tv; + MSize len; + tv.n = (lua_Number)(va_arg(argp, LUAI_UACNUMBER)); + len = (MSize)lj_str_bufnum(buf, &tv); + addstr(L, sb, buf, len); + break; + } + case 'p': { +#define FMTP_CHARS (2*sizeof(ptrdiff_t)) + char buf[2+FMTP_CHARS]; + ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *)); + ptrdiff_t i, lasti = 2+FMTP_CHARS; + if (p == 0) { + addstr(L, sb, "NULL", 4); + break; + } +#if LJ_64 + /* Shorten output for 64 bit pointers. */ + lasti = 2+2*4+((p >> 32) ? 2+2*(lj_fls((uint32_t)(p >> 32))>>3) : 0); +#endif + buf[0] = '0'; + buf[1] = 'x'; + for (i = lasti-1; i >= 2; i--, p >>= 4) + buf[i] = "0123456789abcdef"[(p & 15)]; + addstr(L, sb, buf, (MSize)lasti); + break; + } + case '%': + addchar(L, sb, '%'); + break; + default: + addchar(L, sb, '%'); + addchar(L, sb, e[1]); + break; + } + fmt = e+2; + } + addstr(L, sb, fmt, (MSize)strlen(fmt)); + setstrV(L, L->top, lj_str_new(L, sb->buf, sb->n)); + incr_top(L); + return strVdata(L->top - 1); +} + +/* Push formatted message as a string object to Lua stack. Vararg variant. */ +const char *lj_str_pushf(lua_State *L, const char *fmt, ...) +{ + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = lj_str_pushvf(L, fmt, argp); + va_end(argp); + return msg; +} + +/* -- Buffer handling ----------------------------------------------------- */ + +char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz) +{ + if (sz > sb->sz) { + if (sz < LJ_MIN_SBUF) sz = LJ_MIN_SBUF; + lj_str_resizebuf(L, sb, sz); + } + return sb->buf; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.h new file mode 100644 index 0000000..1602c98 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_str.h @@ -0,0 +1,50 @@ +/* +** String handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STR_H +#define _LJ_STR_H + +#include + +#include "lj_obj.h" + +/* String interning. */ +LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b); +LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask); +LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len); +LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s); + +#define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s))) +#define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1)) + +/* Type conversions. */ +LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o); +LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k); +LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np); +LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k); +LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o); + +#define LJ_STR_INTBUF (1+10) +#define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR + +/* String formatting. */ +LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp); +LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...) +#if defined(__GNUC__) + __attribute__ ((format (printf, 2, 3))) +#endif + ; + +/* Resizable string buffers. Struct definition in lj_obj.h. */ +LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz); + +#define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0) +#define lj_str_resetbuf(sb) ((sb)->n = 0) +#define lj_str_resizebuf(L, sb, size) \ + ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \ + (sb)->sz = (size)) +#define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz) + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.c new file mode 100644 index 0000000..a21c414 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.c @@ -0,0 +1,497 @@ +/* +** String scanning. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lj_strscan_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* -- Scanning numbers ---------------------------------------------------- */ + +/* +** Rationale for the builtin string to number conversion library: +** +** It removes a dependency on libc's strtod(), which is a true portability +** nightmare. Mainly due to the plethora of supported OS and toolchain +** combinations. Sadly, the various implementations +** a) are often buggy, incomplete (no hex floats) and/or imprecise, +** b) sometimes crash or hang on certain inputs, +** c) return non-standard NaNs that need to be filtered out, and +** d) fail if the locale-specific decimal separator is not a dot, +** which can only be fixed with atrocious workarounds. +** +** Also, most of the strtod() implementations are hopelessly bloated, +** which is not just an I-cache hog, but a problem for static linkage +** on embedded systems, too. +** +** OTOH the builtin conversion function is very compact. Even though it +** does a lot more, like parsing long longs, octal or imaginary numbers +** and returning the result in different formats: +** a) It needs less than 3 KB (!) of machine code (on x64 with -Os), +** b) it doesn't perform any dynamic allocation and, +** c) it needs only around 600 bytes of stack space. +** +** The builtin function is faster than strtod() for typical inputs, e.g. +** "123", "1.5" or "1e6". Arguably, it's slower for very large exponents, +** which are not very common (this could be fixed, if needed). +** +** And most importantly, the builtin function is equally precise on all +** platforms. It correctly converts and rounds any input to a double. +** If this is not the case, please send a bug report -- but PLEASE verify +** that the implementation you're comparing to is not the culprit! +** +** The implementation quickly pre-scans the entire string first and +** handles simple integers on-the-fly. Otherwise, it dispatches to the +** base-specific parser. Hex and octal is straightforward. +** +** Decimal to binary conversion uses a fixed-length circular buffer in +** base 100. Some simple cases are handled directly. For other cases, the +** number in the buffer is up-scaled or down-scaled until the integer part +** is in the proper range. Then the integer part is rounded and converted +** to a double which is finally rescaled to the result. Denormals need +** special treatment to prevent incorrect 'double rounding'. +*/ + +/* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */ +#define STRSCAN_DIG 1024 +#define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ +#define STRSCAN_DDIG (STRSCAN_DIG/2) +#define STRSCAN_DMASK (STRSCAN_DDIG-1) + +/* Helpers for circular buffer. */ +#define DNEXT(a) (((a)+1) & STRSCAN_DMASK) +#define DPREV(a) (((a)-1) & STRSCAN_DMASK) +#define DLEN(lo, hi) ((int32_t)(((lo)-(hi)) & STRSCAN_DMASK)) + +#define casecmp(c, k) (((c) | 0x20) == k) + +/* Final conversion to double. */ +static void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg) +{ + double n; + + /* Avoid double rounding for denormals. */ + if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) { + /* NYI: all of this generates way too much code on 32 bit CPUs. */ +#if defined(__GNUC__) && LJ_64 + int32_t b = (int32_t)(__builtin_clzll(x)^63); +#else + int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) : + (int32_t)lj_fls((uint32_t)x); +#endif + if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) { + uint64_t rb = (uint64_t)1 << (-1075-ex2); + if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb; + x = (x & ~(rb+rb-1)); + } + } + + /* Convert to double using a signed int64_t conversion, then rescale. */ + lua_assert((int64_t)x >= 0); + n = (double)(int64_t)x; + if (neg) n = -n; + if (ex2) n = ldexp(n, ex2); + o->n = n; +} + +/* Parse hexadecimal number. */ +static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, + StrScanFmt fmt, uint32_t opt, + int32_t ex2, int32_t neg, uint32_t dig) +{ + uint64_t x = 0; + uint32_t i; + + /* Scan hex digits. */ + for (i = dig > 16 ? 16 : dig ; i; i--, p++) { + uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9; + x = (x << 4) + (d & 15); + } + + /* Summarize rounding-effect of excess digits. */ + for (i = 16; i < dig; i++, p++) + x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4; + + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_INT; /* Fast path for 32 bit integers. */ + } + if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } + /* fallthrough */ + case STRSCAN_U32: + if (dig > 8) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_U32; + case STRSCAN_I64: + case STRSCAN_U64: + if (dig > 16) return STRSCAN_ERROR; + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + return fmt; + default: + break; + } + + /* Reduce range then convert to double. */ + if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; } + strscan_double(x, o, ex2, neg); + return fmt; +} + +/* Parse octal number. */ +static StrScanFmt strscan_oct(const uint8_t *p, TValue *o, + StrScanFmt fmt, int32_t neg, uint32_t dig) +{ + uint64_t x = 0; + + /* Scan octal digits. */ + if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR; + while (dig-- > 0) { + if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR; + x = (x << 3) + (*p++ & 7); + } + + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (x >= 0x80000000u+neg) fmt = STRSCAN_U32; + /* fallthrough */ + case STRSCAN_U32: + if ((x >> 32)) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + break; + default: + case STRSCAN_I64: + case STRSCAN_U64: + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + break; + } + return fmt; +} + +/* Parse decimal number. */ +static StrScanFmt strscan_dec(const uint8_t *p, TValue *o, + StrScanFmt fmt, uint32_t opt, + int32_t ex10, int32_t neg, uint32_t dig) +{ + uint8_t xi[STRSCAN_DDIG], *xip = xi; + + if (dig) { + uint32_t i = dig; + if (i > STRSCAN_MAXDIG) { + ex10 += (int32_t)(i - STRSCAN_MAXDIG); + i = STRSCAN_MAXDIG; + } + /* Scan unaligned leading digit. */ + if (((ex10^i) & 1)) + *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++; + /* Scan aligned double-digits. */ + for ( ; i > 1; i -= 2) { + uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++; + *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++; + } + /* Scan and realign trailing digit. */ + if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, p++; + + /* Summarize rounding-effect of excess digits. */ + if (dig > STRSCAN_MAXDIG) { + do { + if ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; } + p++; + } while (--dig > STRSCAN_MAXDIG); + dig = STRSCAN_MAXDIG; + } else { /* Simplify exponent. */ + while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2; + } + } else { /* Only got zeros. */ + ex10 = 0; + xi[0] = 0; + } + + /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */ + if (dig <= 20 && ex10 == 0) { + uint8_t *xis; + uint64_t x = xi[0]; + double n; + for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis; + if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) { /* No overflow? */ + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_INT; /* Fast path for 32 bit integers. */ + } + if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; } + /* fallthrough */ + case STRSCAN_U32: + if ((x >> 32) != 0) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_U32; + case STRSCAN_I64: + case STRSCAN_U64: + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + return fmt; + default: + plainnumber: /* Fast path for plain numbers < 2^63. */ + if ((int64_t)x < 0) break; + n = (double)(int64_t)x; + if (neg) n = -n; + o->n = n; + return fmt; + } + } + } + + /* Slow non-integer path. */ + if (fmt == STRSCAN_INT) { + if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR; + fmt = STRSCAN_NUM; + } else if (fmt > STRSCAN_INT) { + return STRSCAN_ERROR; + } + { + uint32_t hi = 0, lo = (uint32_t)(xip-xi); + int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1); + + lua_assert(lo > 0 && (ex10 & 1) == 0); + + /* Handle simple overflow/underflow. */ + if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; } + else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; } + + /* Scale up until we have at least 17 or 18 integer part digits. */ + while (idig < 9 && idig < DLEN(lo, hi)) { + uint32_t i, cy = 0; + ex2 -= 6; + for (i = DPREV(lo); ; i = DPREV(i)) { + uint32_t d = (xi[i] << 6) + cy; + cy = (((d >> 2) * 5243) >> 17); d = d - cy * 100; /* Div/mod 100. */ + xi[i] = (uint8_t)d; + if (i == hi) break; + if (d == 0 && i == DPREV(lo)) lo = i; + } + if (cy) { + hi = DPREV(hi); + if (xi[DPREV(lo)] == 0) lo = DPREV(lo); + else if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; } + xi[hi] = (uint8_t)cy; idig++; + } + } + + /* Scale down until no more than 17 or 18 integer part digits remain. */ + while (idig > 9) { + uint32_t i, cy = 0; + ex2 += 6; + for (i = hi; i != lo; i = DNEXT(i)) { + cy += xi[i]; + xi[i] = (cy >> 6); + cy = 100 * (cy & 0x3f); + if (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--; + } + while (cy) { + if (hi == lo) { xi[DPREV(lo)] |= 1; break; } + xi[lo] = (cy >> 6); lo = DNEXT(lo); + cy = 100 * (cy & 0x3f); + } + } + + /* Collect integer part digits and convert to rescaled double. */ + { + uint64_t x = xi[hi]; + uint32_t i; + for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i)) + x = x * 100 + xi[i]; + if (i == lo) { + while (--idig >= 0) x = x * 100; + } else { /* Gather round bit from remaining digits. */ + x <<= 1; ex2--; + do { + if (xi[i]) { x |= 1; break; } + i = DNEXT(i); + } while (i != lo); + } + strscan_double(x, o, ex2, neg); + } + } + return fmt; +} + +/* Scan string containing a number. Returns format. Returns value in o. */ +StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) +{ + int32_t neg = 0; + + /* Remove leading space, parse sign and non-numbers. */ + if (LJ_UNLIKELY(!lj_char_isdigit(*p))) { + while (lj_char_isspace(*p)) p++; + if (*p == '+' || *p == '-') neg = (*p++ == '-'); + if (LJ_UNLIKELY(*p >= 'A')) { /* Parse "inf", "infinity" or "nan". */ + TValue tmp; + setnanV(&tmp); + if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) { + if (neg) setminfV(&tmp); else setpinfV(&tmp); + p += 3; + if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') && + casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5; + } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) { + p += 3; + } + while (lj_char_isspace(*p)) p++; + if (*p) return STRSCAN_ERROR; + o->u64 = tmp.u64; + return STRSCAN_NUM; + } + } + + /* Parse regular number. */ + { + StrScanFmt fmt = STRSCAN_INT; + int cmask = LJ_CHAR_DIGIT; + int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10; + const uint8_t *sp, *dp = NULL; + uint32_t dig = 0, hasdig = 0, x = 0; + int32_t ex = 0; + + /* Determine base and skip leading zeros. */ + if (LJ_UNLIKELY(*p <= '0')) { + if (*p == '0' && casecmp(p[1], 'x')) + base = 16, cmask = LJ_CHAR_XDIGIT, p += 2; + for ( ; ; p++) { + if (*p == '0') { + hasdig = 1; + } else if (*p == '.') { + if (dp) return STRSCAN_ERROR; + dp = p; + } else { + break; + } + } + } + + /* Preliminary digit and decimal point scan. */ + for (sp = p; ; p++) { + if (LJ_LIKELY(lj_char_isa(*p, cmask))) { + x = x * 10 + (*p & 15); /* For fast path below. */ + dig++; + } else if (*p == '.') { + if (dp) return STRSCAN_ERROR; + dp = p; + } else { + break; + } + } + if (!(hasdig | dig)) return STRSCAN_ERROR; + + /* Handle decimal point. */ + if (dp) { + fmt = STRSCAN_NUM; + if (dig) { + ex = (int32_t)(dp-(p-1)); dp = p-1; + while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ + if (base == 16) ex *= 4; + } + } + + /* Parse exponent. */ + if (casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) { + uint32_t xx; + int negx = 0; + fmt = STRSCAN_NUM; p++; + if (*p == '+' || *p == '-') negx = (*p++ == '-'); + if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; + xx = (*p++ & 15); + while (lj_char_isdigit(*p)) { + if (xx < 65536) xx = xx * 10 + (*p & 15); + p++; + } + ex += negx ? -(int32_t)xx : (int32_t)xx; + } + + /* Parse suffix. */ + if (*p) { + /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */ + /* NYI: f (float). Not needed until cp_number() handles non-integers. */ + if (casecmp(*p, 'i')) { + if (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR; + p++; fmt = STRSCAN_IMAG; + } else if (fmt == STRSCAN_INT) { + if (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32; + if (casecmp(*p, 'l')) { + p++; + if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT; + else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR; + else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT; + } + if (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64)) + p++, fmt += STRSCAN_U32 - STRSCAN_INT; + if ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) || + (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL))) + return STRSCAN_ERROR; + } + while (lj_char_isspace(*p)) p++; + if (*p) return STRSCAN_ERROR; + } + + /* Fast path for decimal 32 bit integers. */ + if (fmt == STRSCAN_INT && base == 10 && + (dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) { + int32_t y = neg ? -(int32_t)x : (int32_t)x; + if ((opt & STRSCAN_OPT_TONUM)) { + o->n = (double)y; + return STRSCAN_NUM; + } else { + o->i = y; + return STRSCAN_INT; + } + } + + /* Dispatch to base-specific parser. */ + if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG)) + return strscan_oct(sp, o, fmt, neg, dig); + if (base == 16) + fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig); + else + fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); + + /* Try to convert number to integer, if requested. */ + if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { + double n = o->n; + int32_t i = lj_num2int(n); + if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } + } + return fmt; + } +} + +int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o) +{ + StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, + STRSCAN_OPT_TONUM); + lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM); + return (fmt != STRSCAN_ERROR); +} + +#if LJ_DUALNUM +int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o) +{ + StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, + STRSCAN_OPT_TOINT); + lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT); + if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM); + return (fmt != STRSCAN_ERROR); +} +#endif + +#undef DNEXT +#undef DPREV +#undef DLEN + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.h new file mode 100644 index 0000000..15abd6a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_strscan.h @@ -0,0 +1,39 @@ +/* +** String scanning. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STRSCAN_H +#define _LJ_STRSCAN_H + +#include "lj_obj.h" + +/* Options for accepted/returned formats. */ +#define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */ +#define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */ +#define STRSCAN_OPT_IMAG 0x04 +#define STRSCAN_OPT_LL 0x08 +#define STRSCAN_OPT_C 0x10 + +/* Returned format. */ +typedef enum { + STRSCAN_ERROR, + STRSCAN_NUM, STRSCAN_IMAG, + STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64, +} StrScanFmt; + +LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt); +LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o); +#if LJ_DUALNUM +LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o); +#else +#define lj_strscan_number(s, o) lj_strscan_num((s), (o)) +#endif + +/* Check for number or convert string to number/int in-place (!). */ +static LJ_AINLINE int lj_strscan_numberobj(TValue *o) +{ + return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o)); +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.c new file mode 100644 index 0000000..fc7d0f1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.c @@ -0,0 +1,631 @@ +/* +** Table handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_tab_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" + +/* -- Object hashing ------------------------------------------------------ */ + +/* Hash values are masked with the table hash mask and used as an index. */ +static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) +{ + Node *n = noderef(t->node); + return &n[hash & t->hmask]; +} + +/* String hashes are precomputed when they are interned. */ +#define hashstr(t, s) hashmask(t, (s)->hash) + +#define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi))) +#define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1)) +#define hashptr(t, p) hashlohi((t), u32ptr(p), u32ptr(p) + HASH_BIAS) +#define hashgcref(t, r) hashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS) + +/* Hash an arbitrary key and return its anchor position in the hash table. */ +static Node *hashkey(const GCtab *t, cTValue *key) +{ + lua_assert(!tvisint(key)); + if (tvisstr(key)) + return hashstr(t, strV(key)); + else if (tvisnum(key)) + return hashnum(t, key); + else if (tvisbool(key)) + return hashmask(t, boolV(key)); + else + return hashgcref(t, key->gcr); + /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */ +} + +/* -- Table creation and destruction -------------------------------------- */ + +/* Create new hash part for table. */ +static LJ_AINLINE void newhpart(lua_State *L, GCtab *t, uint32_t hbits) +{ + uint32_t hsize; + Node *node; + lua_assert(hbits != 0); + if (hbits > LJ_MAX_HBITS) + lj_err_msg(L, LJ_ERR_TABOV); + hsize = 1u << hbits; + node = lj_mem_newvec(L, hsize, Node); + setmref(node->freetop, &node[hsize]); + setmref(t->node, node); + t->hmask = hsize-1; +} + +/* +** Q: Why all of these copies of t->hmask, t->node etc. to local variables? +** A: Because alias analysis for C is _really_ tough. +** Even state-of-the-art C compilers won't produce good code without this. +*/ + +/* Clear hash part of table. */ +static LJ_AINLINE void clearhpart(GCtab *t) +{ + uint32_t i, hmask = t->hmask; + Node *node = noderef(t->node); + lua_assert(t->hmask != 0); + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + setmref(n->next, NULL); + setnilV(&n->key); + setnilV(&n->val); + } +} + +/* Clear array part of table. */ +static LJ_AINLINE void clearapart(GCtab *t) +{ + uint32_t i, asize = t->asize; + TValue *array = tvref(t->array); + for (i = 0; i < asize; i++) + setnilV(&array[i]); +} + +/* Create a new table. Note: the slots are not initialized (yet). */ +static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits) +{ + GCtab *t; + /* First try to colocate the array part. */ + if (LJ_MAX_COLOSIZE != 0 && asize > 0 && asize <= LJ_MAX_COLOSIZE) { + lua_assert((sizeof(GCtab) & 7) == 0); + t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize)); + t->gct = ~LJ_TTAB; + t->nomm = (uint8_t)~0; + t->colo = (int8_t)asize; + setmref(t->array, (TValue *)((char *)t + sizeof(GCtab))); + setgcrefnull(t->metatable); + t->asize = asize; + t->hmask = 0; + setmref(t->node, &G(L)->nilnode); + } else { /* Otherwise separately allocate the array part. */ + t = lj_mem_newobj(L, GCtab); + t->gct = ~LJ_TTAB; + t->nomm = (uint8_t)~0; + t->colo = 0; + setmref(t->array, NULL); + setgcrefnull(t->metatable); + t->asize = 0; /* In case the array allocation fails. */ + t->hmask = 0; + setmref(t->node, &G(L)->nilnode); + if (asize > 0) { + if (asize > LJ_MAX_ASIZE) + lj_err_msg(L, LJ_ERR_TABOV); + setmref(t->array, lj_mem_newvec(L, asize, TValue)); + t->asize = asize; + } + } + if (hbits) + newhpart(L, t, hbits); + return t; +} + +/* Create a new table. +** +** IMPORTANT NOTE: The API differs from lua_createtable()! +** +** The array size is non-inclusive. E.g. asize=128 creates array slots +** for 0..127, but not for 128. If you need slots 1..128, pass asize=129 +** (slot 0 is wasted in this case). +** +** The hash size is given in hash bits. hbits=0 means no hash part. +** hbits=1 creates 2 hash slots, hbits=2 creates 4 hash slots and so on. +*/ +GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits) +{ + GCtab *t = newtab(L, asize, hbits); + clearapart(t); + if (t->hmask > 0) clearhpart(t); + return t; +} + +#if LJ_HASJIT +GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize) +{ + GCtab *t = newtab(L, ahsize & 0xffffff, ahsize >> 24); + clearapart(t); + if (t->hmask > 0) clearhpart(t); + return t; +} +#endif + +/* Duplicate a table. */ +GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt) +{ + GCtab *t; + uint32_t asize, hmask; + t = newtab(L, kt->asize, kt->hmask > 0 ? lj_fls(kt->hmask)+1 : 0); + lua_assert(kt->asize == t->asize && kt->hmask == t->hmask); + t->nomm = 0; /* Keys with metamethod names may be present. */ + asize = kt->asize; + if (asize > 0) { + TValue *array = tvref(t->array); + TValue *karray = tvref(kt->array); + if (asize < 64) { /* An inlined loop beats memcpy for < 512 bytes. */ + uint32_t i; + for (i = 0; i < asize; i++) + copyTV(L, &array[i], &karray[i]); + } else { + memcpy(array, karray, asize*sizeof(TValue)); + } + } + hmask = kt->hmask; + if (hmask > 0) { + uint32_t i; + Node *node = noderef(t->node); + Node *knode = noderef(kt->node); + ptrdiff_t d = (char *)node - (char *)knode; + setmref(node->freetop, (Node *)((char *)noderef(knode->freetop) + d)); + for (i = 0; i <= hmask; i++) { + Node *kn = &knode[i]; + Node *n = &node[i]; + Node *next = nextnode(kn); + /* Don't use copyTV here, since it asserts on a copy of a dead key. */ + n->val = kn->val; n->key = kn->key; + setmref(n->next, next == NULL? next : (Node *)((char *)next + d)); + } + } + return t; +} + +/* Free a table. */ +void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t) +{ + if (t->hmask > 0) + lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node); + if (t->asize > 0 && LJ_MAX_COLOSIZE != 0 && t->colo <= 0) + lj_mem_freevec(g, tvref(t->array), t->asize, TValue); + if (LJ_MAX_COLOSIZE != 0 && t->colo) + lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f)); + else + lj_mem_freet(g, t); +} + +/* -- Table resizing ------------------------------------------------------ */ + +/* Resize a table to fit the new array/hash part sizes. */ +static void resizetab(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits) +{ + Node *oldnode = noderef(t->node); + uint32_t oldasize = t->asize; + uint32_t oldhmask = t->hmask; + if (asize > oldasize) { /* Array part grows? */ + TValue *array; + uint32_t i; + if (asize > LJ_MAX_ASIZE) + lj_err_msg(L, LJ_ERR_TABOV); + if (LJ_MAX_COLOSIZE != 0 && t->colo > 0) { + /* A colocated array must be separated and copied. */ + TValue *oarray = tvref(t->array); + array = lj_mem_newvec(L, asize, TValue); + t->colo = (int8_t)(t->colo | 0x80); /* Mark as separated (colo < 0). */ + for (i = 0; i < oldasize; i++) + copyTV(L, &array[i], &oarray[i]); + } else { + array = (TValue *)lj_mem_realloc(L, tvref(t->array), + oldasize*sizeof(TValue), asize*sizeof(TValue)); + } + setmref(t->array, array); + t->asize = asize; + for (i = oldasize; i < asize; i++) /* Clear newly allocated slots. */ + setnilV(&array[i]); + } + /* Create new (empty) hash part. */ + if (hbits) { + newhpart(L, t, hbits); + clearhpart(t); + } else { + global_State *g = G(L); + setmref(t->node, &g->nilnode); + t->hmask = 0; + } + if (asize < oldasize) { /* Array part shrinks? */ + TValue *array = tvref(t->array); + uint32_t i; + t->asize = asize; /* Note: This 'shrinks' even colocated arrays. */ + for (i = asize; i < oldasize; i++) /* Reinsert old array values. */ + if (!tvisnil(&array[i])) + copyTV(L, lj_tab_setinth(L, t, (int32_t)i), &array[i]); + /* Physically shrink only separated arrays. */ + if (LJ_MAX_COLOSIZE != 0 && t->colo <= 0) + setmref(t->array, lj_mem_realloc(L, array, + oldasize*sizeof(TValue), asize*sizeof(TValue))); + } + if (oldhmask > 0) { /* Reinsert pairs from old hash part. */ + global_State *g; + uint32_t i; + for (i = 0; i <= oldhmask; i++) { + Node *n = &oldnode[i]; + if (!tvisnil(&n->val)) + copyTV(L, lj_tab_set(L, t, &n->key), &n->val); + } + g = G(L); + lj_mem_freevec(g, oldnode, oldhmask+1, Node); + } +} + +static uint32_t countint(cTValue *key, uint32_t *bins) +{ + lua_assert(!tvisint(key)); + if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if ((uint32_t)k < LJ_MAX_ASIZE && nk == (lua_Number)k) { + bins[(k > 2 ? lj_fls((uint32_t)(k-1)) : 0)]++; + return 1; + } + } + return 0; +} + +static uint32_t countarray(const GCtab *t, uint32_t *bins) +{ + uint32_t na, b, i; + if (t->asize == 0) return 0; + for (na = i = b = 0; b < LJ_MAX_ABITS; b++) { + uint32_t n, top = 2u << b; + TValue *array; + if (top >= t->asize) { + top = t->asize-1; + if (i > top) + break; + } + array = tvref(t->array); + for (n = 0; i <= top; i++) + if (!tvisnil(&array[i])) + n++; + bins[b] += n; + na += n; + } + return na; +} + +static uint32_t counthash(const GCtab *t, uint32_t *bins, uint32_t *narray) +{ + uint32_t total, na, i, hmask = t->hmask; + Node *node = noderef(t->node); + for (total = na = 0, i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (!tvisnil(&n->val)) { + na += countint(&n->key, bins); + total++; + } + } + *narray += na; + return total; +} + +static uint32_t bestasize(uint32_t bins[], uint32_t *narray) +{ + uint32_t b, sum, na = 0, sz = 0, nn = *narray; + for (b = 0, sum = 0; 2*nn > (1u< 0 && 2*(sum += bins[b]) > (1u<hmask > 0 ? lj_fls(t->hmask)+1 : 0); +} + +/* -- Table getters ------------------------------------------------------- */ + +cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key) +{ + TValue k; + Node *n; + k.n = (lua_Number)key; + n = hashnum(t, &k); + do { + if (tvisnum(&n->key) && n->key.n == k.n) + return &n->val; + } while ((n = nextnode(n))); + return NULL; +} + +cTValue *lj_tab_getstr(GCtab *t, GCstr *key) +{ + Node *n = hashstr(t, key); + do { + if (tvisstr(&n->key) && strV(&n->key) == key) + return &n->val; + } while ((n = nextnode(n))); + return NULL; +} + +cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key) +{ + if (tvisstr(key)) { + cTValue *tv = lj_tab_getstr(t, strV(key)); + if (tv) + return tv; + } else if (tvisint(key)) { + cTValue *tv = lj_tab_getint(t, intV(key)); + if (tv) + return tv; + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if (nk == (lua_Number)k) { + cTValue *tv = lj_tab_getint(t, k); + if (tv) + return tv; + } else { + goto genlookup; /* Else use the generic lookup. */ + } + } else if (!tvisnil(key)) { + Node *n; + genlookup: + n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return &n->val; + } while ((n = nextnode(n))); + } + return niltv(L); +} + +/* -- Table setters ------------------------------------------------------- */ + +/* Insert new key. Use Brent's variation to optimize the chain length. */ +TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key) +{ + Node *n = hashkey(t, key); + if (!tvisnil(&n->val) || t->hmask == 0) { + Node *nodebase = noderef(t->node); + Node *collide, *freenode = noderef(nodebase->freetop); + lua_assert(freenode >= nodebase && freenode <= nodebase+t->hmask+1); + do { + if (freenode == nodebase) { /* No free node found? */ + rehashtab(L, t, key); /* Rehash table. */ + return lj_tab_set(L, t, key); /* Retry key insertion. */ + } + } while (!tvisnil(&(--freenode)->key)); + setmref(nodebase->freetop, freenode); + lua_assert(freenode != &G(L)->nilnode); + collide = hashkey(t, &n->key); + if (collide != n) { /* Colliding node not the main node? */ + while (noderef(collide->next) != n) /* Find predecessor. */ + collide = nextnode(collide); + setmref(collide->next, freenode); /* Relink chain. */ + /* Copy colliding node into free node and free main node. */ + freenode->val = n->val; + freenode->key = n->key; + freenode->next = n->next; + setmref(n->next, NULL); + setnilV(&n->val); + /* Rechain pseudo-resurrected string keys with colliding hashes. */ + while (nextnode(freenode)) { + Node *nn = nextnode(freenode); + if (tvisstr(&nn->key) && !tvisnil(&nn->val) && + hashstr(t, strV(&nn->key)) == n) { + freenode->next = nn->next; + nn->next = n->next; + setmref(n->next, nn); + } else { + freenode = nn; + } + } + } else { /* Otherwise use free node. */ + setmrefr(freenode->next, n->next); /* Insert into chain. */ + setmref(n->next, freenode); + n = freenode; + } + } + n->key.u64 = key->u64; + if (LJ_UNLIKELY(tvismzero(&n->key))) + n->key.u64 = 0; + lj_gc_anybarriert(L, t); + lua_assert(tvisnil(&n->val)); + return &n->val; +} + +TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key) +{ + TValue k; + Node *n; + k.n = (lua_Number)key; + n = hashnum(t, &k); + do { + if (tvisnum(&n->key) && n->key.n == k.n) + return &n->val; + } while ((n = nextnode(n))); + return lj_tab_newkey(L, t, &k); +} + +TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key) +{ + TValue k; + Node *n = hashstr(t, key); + do { + if (tvisstr(&n->key) && strV(&n->key) == key) + return &n->val; + } while ((n = nextnode(n))); + setstrV(L, &k, key); + return lj_tab_newkey(L, t, &k); +} + +TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key) +{ + Node *n; + t->nomm = 0; /* Invalidate negative metamethod cache. */ + if (tvisstr(key)) { + return lj_tab_setstr(L, t, strV(key)); + } else if (tvisint(key)) { + return lj_tab_setint(L, t, intV(key)); + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if (nk == (lua_Number)k) + return lj_tab_setint(L, t, k); + if (tvisnan(key)) + lj_err_msg(L, LJ_ERR_NANIDX); + /* Else use the generic lookup. */ + } else if (tvisnil(key)) { + lj_err_msg(L, LJ_ERR_NILIDX); + } + n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return &n->val; + } while ((n = nextnode(n))); + return lj_tab_newkey(L, t, key); +} + +/* -- Table traversal ----------------------------------------------------- */ + +/* Get the traversal index of a key. */ +static uint32_t keyindex(lua_State *L, GCtab *t, cTValue *key) +{ + TValue tmp; + if (tvisint(key)) { + int32_t k = intV(key); + if ((uint32_t)k < t->asize) + return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */ + setnumV(&tmp, (lua_Number)k); + key = &tmp; + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if ((uint32_t)k < t->asize && nk == (lua_Number)k) + return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */ + } + if (!tvisnil(key)) { + Node *n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return t->asize + (uint32_t)(n - noderef(t->node)); + /* Hash key indexes: [t->asize..t->asize+t->nmask] */ + } while ((n = nextnode(n))); + if (key->u32.hi == 0xfffe7fff) /* ITERN was despecialized while running. */ + return key->u32.lo - 1; + lj_err_msg(L, LJ_ERR_NEXTIDX); + return 0; /* unreachable */ + } + return ~0u; /* A nil key starts the traversal. */ +} + +/* Advance to the next step in a table traversal. */ +int lj_tab_next(lua_State *L, GCtab *t, TValue *key) +{ + uint32_t i = keyindex(L, t, key); /* Find predecessor key index. */ + for (i++; i < t->asize; i++) /* First traverse the array keys. */ + if (!tvisnil(arrayslot(t, i))) { + setintV(key, i); + copyTV(L, key+1, arrayslot(t, i)); + return 1; + } + for (i -= t->asize; i <= t->hmask; i++) { /* Then traverse the hash keys. */ + Node *n = &noderef(t->node)[i]; + if (!tvisnil(&n->val)) { + copyTV(L, key, &n->key); + copyTV(L, key+1, &n->val); + return 1; + } + } + return 0; /* End of traversal. */ +} + +/* -- Table length calculation -------------------------------------------- */ + +static MSize unbound_search(GCtab *t, MSize j) +{ + cTValue *tv; + MSize i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while ((tv = lj_tab_getint(t, (int32_t)j)) && !tvisnil(tv)) { + i = j; + j *= 2; + if (j > (MSize)(INT_MAX-2)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while ((tv = lj_tab_getint(t, (int32_t)i)) && !tvisnil(tv)) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + MSize m = (i+j)/2; + cTValue *tvb = lj_tab_getint(t, (int32_t)m); + if (tvb && !tvisnil(tvb)) i = m; else j = m; + } + return i; +} + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +MSize LJ_FASTCALL lj_tab_len(GCtab *t) +{ + MSize j = (MSize)t->asize; + if (j > 1 && tvisnil(arrayslot(t, j-1))) { + MSize i = 1; + while (j - i > 1) { + MSize m = (i+j)/2; + if (tvisnil(arrayslot(t, m-1))) j = m; else i = m; + } + return i-1; + } + if (j) j--; + if (t->hmask <= 0) + return j; + return unbound_search(t, j); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.h new file mode 100644 index 0000000..44b1bbb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_tab.h @@ -0,0 +1,70 @@ +/* +** Table handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TAB_H +#define _LJ_TAB_H + +#include "lj_obj.h" + +/* Hash constants. Tuned using a brute force search. */ +#define HASH_BIAS (-0x04c11db7) +#define HASH_ROT1 14 +#define HASH_ROT2 5 +#define HASH_ROT3 13 + +/* Scramble the bits of numbers and pointers. */ +static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi) +{ +#if LJ_TARGET_X86ORX64 + /* Prefer variant that compiles well for a 2-operand CPU. */ + lo ^= hi; hi = lj_rol(hi, HASH_ROT1); + lo -= hi; hi = lj_rol(hi, HASH_ROT2); + hi ^= lo; hi -= lj_rol(lo, HASH_ROT3); +#else + lo ^= hi; + lo = lo - lj_rol(hi, HASH_ROT1); + hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2); + hi = hi - lj_rol(lo, HASH_ROT3); +#endif + return hi; +} + +#define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) + +LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits); +#if LJ_HASJIT +LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize); +#endif +LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt); +LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t); +#if LJ_HASFFI +LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t); +#endif +LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize); + +/* Caveat: all getters except lj_tab_get() can return NULL! */ + +LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key); +LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key); +LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key); + +/* Caveat: all setters require a write barrier for the stored value. */ + +LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key); +LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key); +LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key); +LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); + +#define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize) +#define arrayslot(t, i) (&tvref((t)->array)[(i)]) +#define lj_tab_getint(t, key) \ + (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key))) +#define lj_tab_setint(L, t, key) \ + (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key))) + +LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key); +LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target.h new file mode 100644 index 0000000..820a97a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target.h @@ -0,0 +1,162 @@ +/* +** Definitions for target CPU. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_H +#define _LJ_TARGET_H + +#include "lj_def.h" +#include "lj_arch.h" + +/* -- Registers and spill slots ------------------------------------------- */ + +/* Register type (uint8_t in ir->r). */ +typedef uint32_t Reg; + +/* The hi-bit is NOT set for an allocated register. This means the value +** can be directly used without masking. The hi-bit is set for a register +** allocation hint or for RID_INIT, RID_SINK or RID_SUNK. +*/ +#define RID_NONE 0x80 +#define RID_MASK 0x7f +#define RID_INIT (RID_NONE|RID_MASK) +#define RID_SINK (RID_INIT-1) +#define RID_SUNK (RID_INIT-2) + +#define ra_noreg(r) ((r) & RID_NONE) +#define ra_hasreg(r) (!((r) & RID_NONE)) + +/* The ra_hashint() macro assumes a previous test for ra_noreg(). */ +#define ra_hashint(r) ((r) < RID_SUNK) +#define ra_gethint(r) ((Reg)((r) & RID_MASK)) +#define ra_sethint(rr, r) rr = (uint8_t)((r)|RID_NONE) +#define ra_samehint(r1, r2) (ra_gethint((r1)^(r2)) == 0) + +/* Spill slot 0 means no spill slot has been allocated. */ +#define SPS_NONE 0 + +#define ra_hasspill(s) ((s) != SPS_NONE) + +/* Combined register and spill slot (uint16_t in ir->prev). */ +typedef uint32_t RegSP; + +#define REGSP(r, s) ((r) + ((s) << 8)) +#define REGSP_HINT(r) ((r)|RID_NONE) +#define REGSP_INIT REGSP(RID_INIT, 0) + +#define regsp_reg(rs) ((rs) & 255) +#define regsp_spill(rs) ((rs) >> 8) +#define regsp_used(rs) \ + (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0)) + +/* -- Register sets ------------------------------------------------------- */ + +/* Bitset for registers. 32 registers suffice for most architectures. +** Note that one set holds bits for both GPRs and FPRs. +*/ +#if LJ_TARGET_PPC || LJ_TARGET_MIPS +typedef uint64_t RegSet; +#else +typedef uint32_t RegSet; +#endif + +#define RID2RSET(r) (((RegSet)1) << (r)) +#define RSET_EMPTY ((RegSet)0) +#define RSET_RANGE(lo, hi) ((RID2RSET((hi)-(lo))-1) << (lo)) + +#define rset_test(rs, r) ((int)((rs) >> (r)) & 1) +#define rset_set(rs, r) (rs |= RID2RSET(r)) +#define rset_clear(rs, r) (rs &= ~RID2RSET(r)) +#define rset_exclude(rs, r) (rs & ~RID2RSET(r)) +#if LJ_TARGET_PPC || LJ_TARGET_MIPS +#define rset_picktop(rs) ((Reg)(__builtin_clzll(rs)^63)) +#define rset_pickbot(rs) ((Reg)__builtin_ctzll(rs)) +#else +#define rset_picktop(rs) ((Reg)lj_fls(rs)) +#define rset_pickbot(rs) ((Reg)lj_ffs(rs)) +#endif + +/* -- Register allocation cost -------------------------------------------- */ + +/* The register allocation heuristic keeps track of the cost for allocating +** a specific register: +** +** A free register (obviously) has a cost of 0 and a 1-bit in the free mask. +** +** An already allocated register has the (non-zero) IR reference in the lowest +** bits and the result of a blended cost-model in the higher bits. +** +** The allocator first checks the free mask for a hit. Otherwise an (unrolled) +** linear search for the minimum cost is used. The search doesn't need to +** keep track of the position of the minimum, which makes it very fast. +** The lowest bits of the minimum cost show the desired IR reference whose +** register is the one to evict. +** +** Without the cost-model this degenerates to the standard heuristics for +** (reverse) linear-scan register allocation. Since code generation is done +** in reverse, a live interval extends from the last use to the first def. +** For an SSA IR the IR reference is the first (and only) def and thus +** trivially marks the end of the interval. The LSRA heuristics says to pick +** the register whose live interval has the furthest extent, i.e. the lowest +** IR reference in our case. +** +** A cost-model should take into account other factors, like spill-cost and +** restore- or rematerialization-cost, which depend on the kind of instruction. +** E.g. constants have zero spill costs, variant instructions have higher +** costs than invariants and PHIs should preferably never be spilled. +** +** Here's a first cut at simple, but effective blended cost-model for R-LSRA: +** - Due to careful design of the IR, constants already have lower IR +** references than invariants and invariants have lower IR references +** than variants. +** - The cost in the upper 16 bits is the sum of the IR reference and a +** weighted score. The score currently only takes into account whether +** the IRT_ISPHI bit is set in the instruction type. +** - The PHI weight is the minimum distance (in IR instructions) a PHI +** reference has to be further apart from a non-PHI reference to be spilled. +** - It should be a power of two (for speed) and must be between 2 and 32768. +** Good values for the PHI weight seem to be between 40 and 150. +** - Further study is required. +*/ +#define REGCOST_PHI_WEIGHT 64 + +/* Cost for allocating a specific register. */ +typedef uint32_t RegCost; + +/* Note: assumes 16 bit IRRef1. */ +#define REGCOST(cost, ref) ((RegCost)(ref) + ((RegCost)(cost) << 16)) +#define regcost_ref(rc) ((IRRef1)(rc)) + +#define REGCOST_T(t) \ + ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI)) +#define REGCOST_REF_T(ref, t) (REGCOST((ref), (ref)) + REGCOST_T((t))) + +/* -- Target-specific definitions ----------------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_target_x86.h" +#elif LJ_TARGET_ARM +#include "lj_target_arm.h" +#elif LJ_TARGET_PPC +#include "lj_target_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_target_mips.h" +#else +#error "Missing include for target CPU" +#endif + +#ifdef EXITSTUBS_PER_GROUP +/* Return the address of an exit stub. */ +static LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno) +{ + lua_assert(group[exitno / EXITSTUBS_PER_GROUP] != NULL); + return (char *)group[exitno / EXITSTUBS_PER_GROUP] + + EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP); +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_addr(J, exitno) \ + ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno))) +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_arm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_arm.h new file mode 100644 index 0000000..63a0c92 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_arm.h @@ -0,0 +1,274 @@ +/* +** Definitions for ARM CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_ARM_H +#define _LJ_TARGET_ARM_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC) +#if LJ_SOFTFP +#define FPRDEF(_) +#else +#define FPRDEF(_) \ + _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \ + _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15) +#endif +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_TMP = RID_LR, + + /* Calling conventions. */ + RID_RET = RID_R0, + RID_RETLO = RID_R0, + RID_RETHI = RID_R1, +#if LJ_SOFTFP + RID_FPRET = RID_R0, +#else + RID_FPRET = RID_D0, +#endif + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R9, /* Interpreter BASE. */ + RID_LPC = RID_R6, /* Interpreter PC. */ + RID_DISPATCH = RID_R7, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R8, /* Interpreter L. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_PC+1, + RID_MIN_FPR = RID_MAX_GPR, +#if LJ_SOFTFP + RID_MAX_FPR = RID_MIN_FPR, +#else + RID_MAX_FPR = RID_D15+1, +#endif + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except sp, lr and pc. */ +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_R12+1)) +#define RSET_GPREVEN \ + (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \ + RID2RSET(RID_R8)|RID2RSET(RID_R10)) +#define RSET_GPRODD \ + (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \ + RID2RSET(RID_R9)|RID2RSET(RID_R11)) +#if LJ_SOFTFP +#define RSET_FPR 0 +#else +#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)) +#endif +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +/* ABI-specific register sets. lr is an implicit scratch register. */ +#define RSET_SCRATCH_GPR_ (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12)) +#ifdef __APPLE__ +#define RSET_SCRATCH_GPR (RSET_SCRATCH_GPR_|RID2RSET(RID_R9)) +#else +#define RSET_SCRATCH_GPR RSET_SCRATCH_GPR_ +#endif +#if LJ_SOFTFP +#define RSET_SCRATCH_FPR 0 +#else +#define RSET_SCRATCH_FPR (RSET_RANGE(RID_D0, RID_D7+1)) +#endif +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R0 +#define REGARG_LASTGPR RID_R3 +#define REGARG_NUMGPR 4 +#if LJ_ABI_SOFTFP +#define REGARG_FIRSTFPR 0 +#define REGARG_LASTFPR 0 +#define REGARG_NUMFPR 0 +#else +#define REGARG_FIRSTFPR RID_D0 +#define REGARG_LASTFPR RID_D7 +#define REGARG_NUMFPR 8 +#endif + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. +*/ +#define SPS_FIXED 2 +#define SPS_FIRST 2 + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { +#if !LJ_SOFTFP + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ +#endif + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* PC after instruction that caused an exit. Used to find the trace number. */ +#define EXITSTATE_PCREG RID_PC +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +#define EXITSTUB_SPACING 4 +#define EXITSTUBS_PER_GROUP 32 + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define ARMF_CC(ai, cc) (((ai) ^ ARMI_CCAL) | ((cc) << 28)) +#define ARMF_N(r) ((r) << 16) +#define ARMF_D(r) ((r) << 12) +#define ARMF_S(r) ((r) << 8) +#define ARMF_M(r) (r) +#define ARMF_SH(sh, n) (((sh) << 5) | ((n) << 7)) +#define ARMF_RSH(sh, r) (0x10 | ((sh) << 5) | ARMF_S(r)) + +typedef enum ARMIns { + ARMI_CCAL = 0xe0000000, + ARMI_S = 0x000100000, + ARMI_K12 = 0x02000000, + ARMI_KNEG = 0x00200000, + ARMI_LS_W = 0x00200000, + ARMI_LS_U = 0x00800000, + ARMI_LS_P = 0x01000000, + ARMI_LS_R = 0x02000000, + ARMI_LSX_I = 0x00400000, + + ARMI_AND = 0xe0000000, + ARMI_EOR = 0xe0200000, + ARMI_SUB = 0xe0400000, + ARMI_RSB = 0xe0600000, + ARMI_ADD = 0xe0800000, + ARMI_ADC = 0xe0a00000, + ARMI_SBC = 0xe0c00000, + ARMI_RSC = 0xe0e00000, + ARMI_TST = 0xe1100000, + ARMI_TEQ = 0xe1300000, + ARMI_CMP = 0xe1500000, + ARMI_CMN = 0xe1700000, + ARMI_ORR = 0xe1800000, + ARMI_MOV = 0xe1a00000, + ARMI_BIC = 0xe1c00000, + ARMI_MVN = 0xe1e00000, + + ARMI_NOP = 0xe1a00000, + + ARMI_MUL = 0xe0000090, + ARMI_SMULL = 0xe0c00090, + + ARMI_LDR = 0xe4100000, + ARMI_LDRB = 0xe4500000, + ARMI_LDRH = 0xe01000b0, + ARMI_LDRSB = 0xe01000d0, + ARMI_LDRSH = 0xe01000f0, + ARMI_LDRD = 0xe00000d0, + ARMI_STR = 0xe4000000, + ARMI_STRB = 0xe4400000, + ARMI_STRH = 0xe00000b0, + ARMI_STRD = 0xe00000f0, + ARMI_PUSH = 0xe92d0000, + + ARMI_B = 0xea000000, + ARMI_BL = 0xeb000000, + ARMI_BLX = 0xfa000000, + ARMI_BLXr = 0xe12fff30, + + /* ARMv6 */ + ARMI_REV = 0xe6bf0f30, + ARMI_SXTB = 0xe6af0070, + ARMI_SXTH = 0xe6bf0070, + ARMI_UXTB = 0xe6ef0070, + ARMI_UXTH = 0xe6ff0070, + + /* ARMv6T2 */ + ARMI_MOVW = 0xe3000000, + ARMI_MOVT = 0xe3400000, + + /* VFP */ + ARMI_VMOV_D = 0xeeb00b40, + ARMI_VMOV_S = 0xeeb00a40, + ARMI_VMOVI_D = 0xeeb00b00, + + ARMI_VMOV_R_S = 0xee100a10, + ARMI_VMOV_S_R = 0xee000a10, + ARMI_VMOV_RR_D = 0xec500b10, + ARMI_VMOV_D_RR = 0xec400b10, + + ARMI_VADD_D = 0xee300b00, + ARMI_VSUB_D = 0xee300b40, + ARMI_VMUL_D = 0xee200b00, + ARMI_VMLA_D = 0xee000b00, + ARMI_VMLS_D = 0xee000b40, + ARMI_VNMLS_D = 0xee100b00, + ARMI_VDIV_D = 0xee800b00, + + ARMI_VABS_D = 0xeeb00bc0, + ARMI_VNEG_D = 0xeeb10b40, + ARMI_VSQRT_D = 0xeeb10bc0, + + ARMI_VCMP_D = 0xeeb40b40, + ARMI_VCMPZ_D = 0xeeb50b40, + + ARMI_VMRS = 0xeef1fa10, + + ARMI_VCVT_S32_F32 = 0xeebd0ac0, + ARMI_VCVT_S32_F64 = 0xeebd0bc0, + ARMI_VCVT_U32_F32 = 0xeebc0ac0, + ARMI_VCVT_U32_F64 = 0xeebc0bc0, + ARMI_VCVTR_S32_F32 = 0xeebd0a40, + ARMI_VCVTR_S32_F64 = 0xeebd0b40, + ARMI_VCVTR_U32_F32 = 0xeebc0a40, + ARMI_VCVTR_U32_F64 = 0xeebc0b40, + ARMI_VCVT_F32_S32 = 0xeeb80ac0, + ARMI_VCVT_F64_S32 = 0xeeb80bc0, + ARMI_VCVT_F32_U32 = 0xeeb80a40, + ARMI_VCVT_F64_U32 = 0xeeb80b40, + ARMI_VCVT_F32_F64 = 0xeeb70bc0, + ARMI_VCVT_F64_F32 = 0xeeb70ac0, + + ARMI_VLDR_S = 0xed100a00, + ARMI_VLDR_D = 0xed100b00, + ARMI_VSTR_S = 0xed000a00, + ARMI_VSTR_D = 0xed000b00, +} ARMIns; + +typedef enum ARMShift { + ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR +} ARMShift; + +/* ARM condition codes. */ +typedef enum ARMCC { + CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC, + CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL, + CC_HS = CC_CS, CC_LO = CC_CC +} ARMCC; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_mips.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_mips.h new file mode 100644 index 0000000..e0fc152 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_mips.h @@ -0,0 +1,257 @@ +/* +** Definitions for MIPS CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_MIPS_H +#define _LJ_TARGET_MIPS_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \ + _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \ + _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA) +#define FPRDEF(_) \ + _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \ + _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \ + _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \ + _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31) +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_ZERO = RID_R0, + RID_TMP = RID_RA, + + /* Calling conventions. */ + RID_RET = RID_R2, +#if LJ_LE + RID_RETHI = RID_R3, + RID_RETLO = RID_R2, +#else + RID_RETHI = RID_R2, + RID_RETLO = RID_R3, +#endif + RID_FPRET = RID_F0, + RID_CFUNCADDR = RID_R25, + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R16, /* Interpreter BASE. */ + RID_LPC = RID_R18, /* Interpreter PC. */ + RID_DISPATCH = RID_R19, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R20, /* Interpreter L. */ + RID_JGL = RID_R30, /* On-trace: global_State + 32768. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_RA+1, + RID_MIN_FPR = RID_F0, + RID_MAX_FPR = RID_F31+1, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR /* Only even regs are used. */ +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2 and JGL. */ +#define RSET_FIXED \ + (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\ + RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)) +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED) +#define RSET_FPR \ + (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\ + RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\ + RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\ + RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30)) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#define RSET_SCRATCH_GPR \ + (RSET_RANGE(RID_R1, RID_R15+1)|\ + RID2RSET(RID_R24)|RID2RSET(RID_R25)|RID2RSET(RID_R28)) +#define RSET_SCRATCH_FPR \ + (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\ + RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\ + RID2RSET(RID_F16)|RID2RSET(RID_F18)) +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R4 +#define REGARG_LASTGPR RID_R7 +#define REGARG_NUMGPR 4 +#define REGARG_FIRSTFPR RID_F12 +#define REGARG_LASTFPR RID_F14 +#define REGARG_NUMFPR 2 + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. +*/ +#define SPS_FIXED 5 +#define SPS_FIRST 4 + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +/* Return the address of a per-trace exit stub. */ +static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p) +{ + while (*p == 0x00000000) p++; /* Skip MIPSI_NOP. */ + return p; +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_trace_addr(T, exitno) \ + exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode)) + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define MIPSF_S(r) ((r) << 21) +#define MIPSF_T(r) ((r) << 16) +#define MIPSF_D(r) ((r) << 11) +#define MIPSF_R(r) ((r) << 21) +#define MIPSF_H(r) ((r) << 16) +#define MIPSF_G(r) ((r) << 11) +#define MIPSF_F(r) ((r) << 6) +#define MIPSF_A(n) ((n) << 6) +#define MIPSF_M(n) ((n) << 11) + +typedef enum MIPSIns { + /* Integer instructions. */ + MIPSI_MOVE = 0x00000021, + MIPSI_NOP = 0x00000000, + + MIPSI_LI = 0x24000000, + MIPSI_LU = 0x34000000, + MIPSI_LUI = 0x3c000000, + + MIPSI_ADDIU = 0x24000000, + MIPSI_ANDI = 0x30000000, + MIPSI_ORI = 0x34000000, + MIPSI_XORI = 0x38000000, + MIPSI_SLTI = 0x28000000, + MIPSI_SLTIU = 0x2c000000, + + MIPSI_ADDU = 0x00000021, + MIPSI_SUBU = 0x00000023, + MIPSI_MUL = 0x70000002, + MIPSI_AND = 0x00000024, + MIPSI_OR = 0x00000025, + MIPSI_XOR = 0x00000026, + MIPSI_NOR = 0x00000027, + MIPSI_SLT = 0x0000002a, + MIPSI_SLTU = 0x0000002b, + MIPSI_MOVZ = 0x0000000a, + MIPSI_MOVN = 0x0000000b, + + MIPSI_SLL = 0x00000000, + MIPSI_SRL = 0x00000002, + MIPSI_SRA = 0x00000003, + MIPSI_ROTR = 0x00200002, /* MIPS32R2 */ + MIPSI_SLLV = 0x00000004, + MIPSI_SRLV = 0x00000006, + MIPSI_SRAV = 0x00000007, + MIPSI_ROTRV = 0x00000046, /* MIPS32R2 */ + + MIPSI_SEB = 0x7c000420, /* MIPS32R2 */ + MIPSI_SEH = 0x7c000620, /* MIPS32R2 */ + MIPSI_WSBH = 0x7c0000a0, /* MIPS32R2 */ + + MIPSI_B = 0x10000000, + MIPSI_J = 0x08000000, + MIPSI_JAL = 0x0c000000, + MIPSI_JR = 0x00000008, + MIPSI_JALR = 0x0000f809, + + MIPSI_BEQ = 0x10000000, + MIPSI_BNE = 0x14000000, + MIPSI_BLEZ = 0x18000000, + MIPSI_BGTZ = 0x1c000000, + MIPSI_BLTZ = 0x04000000, + MIPSI_BGEZ = 0x04010000, + + /* Load/store instructions. */ + MIPSI_LW = 0x8c000000, + MIPSI_SW = 0xac000000, + MIPSI_LB = 0x80000000, + MIPSI_SB = 0xa0000000, + MIPSI_LH = 0x84000000, + MIPSI_SH = 0xa4000000, + MIPSI_LBU = 0x90000000, + MIPSI_LHU = 0x94000000, + MIPSI_LWC1 = 0xc4000000, + MIPSI_SWC1 = 0xe4000000, + MIPSI_LDC1 = 0xd4000000, + MIPSI_SDC1 = 0xf4000000, + + /* FP instructions. */ + MIPSI_MOV_S = 0x46000006, + MIPSI_MOV_D = 0x46200006, + MIPSI_MOVT_D = 0x46210011, + MIPSI_MOVF_D = 0x46200011, + + MIPSI_ABS_D = 0x46200005, + MIPSI_NEG_D = 0x46200007, + + MIPSI_ADD_D = 0x46200000, + MIPSI_SUB_D = 0x46200001, + MIPSI_MUL_D = 0x46200002, + MIPSI_DIV_D = 0x46200003, + MIPSI_SQRT_D = 0x46200004, + + MIPSI_ADD_S = 0x46000000, + MIPSI_SUB_S = 0x46000001, + + MIPSI_CVT_D_S = 0x46000021, + MIPSI_CVT_W_S = 0x46000024, + MIPSI_CVT_S_D = 0x46200020, + MIPSI_CVT_W_D = 0x46200024, + MIPSI_CVT_S_W = 0x46800020, + MIPSI_CVT_D_W = 0x46800021, + + MIPSI_TRUNC_W_S = 0x4600000d, + MIPSI_TRUNC_W_D = 0x4620000d, + MIPSI_FLOOR_W_S = 0x4600000f, + MIPSI_FLOOR_W_D = 0x4620000f, + + MIPSI_MFC1 = 0x44000000, + MIPSI_MTC1 = 0x44800000, + + MIPSI_BC1F = 0x45000000, + MIPSI_BC1T = 0x45010000, + + MIPSI_C_EQ_D = 0x46200032, + MIPSI_C_OLT_D = 0x46200034, + MIPSI_C_ULT_D = 0x46200035, + MIPSI_C_OLE_D = 0x46200036, + MIPSI_C_ULE_D = 0x46200037, + +} MIPSIns; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_ppc.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_ppc.h new file mode 100644 index 0000000..475e046 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_ppc.h @@ -0,0 +1,280 @@ +/* +** Definitions for PPC CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_PPC_H +#define _LJ_TARGET_PPC_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \ + _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \ + _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31) +#define FPRDEF(_) \ + _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \ + _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \ + _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \ + _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31) +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_TMP = RID_R0, + + /* Calling conventions. */ + RID_RET = RID_R3, + RID_RETHI = RID_R3, + RID_RETLO = RID_R4, + RID_FPRET = RID_F1, + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R14, /* Interpreter BASE. */ + RID_LPC = RID_R16, /* Interpreter PC. */ + RID_DISPATCH = RID_R17, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R18, /* Interpreter L. */ + RID_JGL = RID_R31, /* On-trace: global_State + 32768. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_R31+1, + RID_MIN_FPR = RID_F0, + RID_MAX_FPR = RID_F31+1, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */ +#define RSET_FIXED \ + (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\ + RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)) +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED) +#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#define RSET_SCRATCH_GPR (RSET_RANGE(RID_R3, RID_R12+1)) +#define RSET_SCRATCH_FPR (RSET_RANGE(RID_F0, RID_F13+1)) +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R3 +#define REGARG_LASTGPR RID_R10 +#define REGARG_NUMGPR 8 +#define REGARG_FIRSTFPR RID_F1 +#define REGARG_LASTFPR RID_F8 +#define REGARG_NUMFPR 8 + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. +** [sp+12] tmplo word \ +** [sp+ 8] tmphi word / tmp dword, parameter area for callee +** [sp+ 4] tmpw, LR of callee +** [sp+ 0] stack chain +*/ +#define SPS_FIXED 7 +#define SPS_FIRST 4 + +/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */ +#define SPOFS_TMPW 4 +#define SPOFS_TMP 8 +#define SPOFS_TMPHI 8 +#define SPOFS_TMPLO 12 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +/* Return the address of a per-trace exit stub. */ +static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno) +{ + while (*p == 0x60000000) p++; /* Skip PPCI_NOP. */ + return p + 3 + exitno; +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_trace_addr(T, exitno) \ + exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno)) + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define PPCF_CC(cc) ((((cc) & 3) << 16) | (((cc) & 4) << 22)) +#define PPCF_T(r) ((r) << 21) +#define PPCF_A(r) ((r) << 16) +#define PPCF_B(r) ((r) << 11) +#define PPCF_C(r) ((r) << 6) +#define PPCF_MB(n) ((n) << 6) +#define PPCF_ME(n) ((n) << 1) +#define PPCF_Y 0x00200000 +#define PPCF_DOT 0x00000001 + +typedef enum PPCIns { + /* Integer instructions. */ + PPCI_MR = 0x7c000378, + PPCI_NOP = 0x60000000, + + PPCI_LI = 0x38000000, + PPCI_LIS = 0x3c000000, + + PPCI_ADD = 0x7c000214, + PPCI_ADDC = 0x7c000014, + PPCI_ADDO = 0x7c000614, + PPCI_ADDE = 0x7c000114, + PPCI_ADDZE = 0x7c000194, + PPCI_ADDME = 0x7c0001d4, + PPCI_ADDI = 0x38000000, + PPCI_ADDIS = 0x3c000000, + PPCI_ADDIC = 0x30000000, + PPCI_ADDICDOT = 0x34000000, + + PPCI_SUBF = 0x7c000050, + PPCI_SUBFC = 0x7c000010, + PPCI_SUBFO = 0x7c000450, + PPCI_SUBFE = 0x7c000110, + PPCI_SUBFZE = 0x7c000190, + PPCI_SUBFME = 0x7c0001d0, + PPCI_SUBFIC = 0x20000000, + + PPCI_NEG = 0x7c0000d0, + + PPCI_AND = 0x7c000038, + PPCI_ANDC = 0x7c000078, + PPCI_NAND = 0x7c0003b8, + PPCI_ANDIDOT = 0x70000000, + PPCI_ANDISDOT = 0x74000000, + + PPCI_OR = 0x7c000378, + PPCI_NOR = 0x7c0000f8, + PPCI_ORI = 0x60000000, + PPCI_ORIS = 0x64000000, + + PPCI_XOR = 0x7c000278, + PPCI_EQV = 0x7c000238, + PPCI_XORI = 0x68000000, + PPCI_XORIS = 0x6c000000, + + PPCI_CMPW = 0x7c000000, + PPCI_CMPLW = 0x7c000040, + PPCI_CMPWI = 0x2c000000, + PPCI_CMPLWI = 0x28000000, + + PPCI_MULLW = 0x7c0001d6, + PPCI_MULLI = 0x1c000000, + PPCI_MULLWO = 0x7c0005d6, + + PPCI_EXTSB = 0x7c000774, + PPCI_EXTSH = 0x7c000734, + + PPCI_SLW = 0x7c000030, + PPCI_SRW = 0x7c000430, + PPCI_SRAW = 0x7c000630, + PPCI_SRAWI = 0x7c000670, + + PPCI_RLWNM = 0x5c000000, + PPCI_RLWINM = 0x54000000, + PPCI_RLWIMI = 0x50000000, + + PPCI_B = 0x48000000, + PPCI_BL = 0x48000001, + PPCI_BC = 0x40800000, + PPCI_BCL = 0x40800001, + PPCI_BCTR = 0x4e800420, + PPCI_BCTRL = 0x4e800421, + + PPCI_CRANDC = 0x4c000102, + PPCI_CRXOR = 0x4c000182, + PPCI_CRAND = 0x4c000202, + PPCI_CREQV = 0x4c000242, + PPCI_CRORC = 0x4c000342, + PPCI_CROR = 0x4c000382, + + PPCI_MFLR = 0x7c0802a6, + PPCI_MTCTR = 0x7c0903a6, + + PPCI_MCRXR = 0x7c000400, + + /* Load/store instructions. */ + PPCI_LWZ = 0x80000000, + PPCI_LBZ = 0x88000000, + PPCI_STW = 0x90000000, + PPCI_STB = 0x98000000, + PPCI_LHZ = 0xa0000000, + PPCI_LHA = 0xa8000000, + PPCI_STH = 0xb0000000, + + PPCI_STWU = 0x94000000, + + PPCI_LFS = 0xc0000000, + PPCI_LFD = 0xc8000000, + PPCI_STFS = 0xd0000000, + PPCI_STFD = 0xd8000000, + + PPCI_LWZX = 0x7c00002e, + PPCI_LBZX = 0x7c0000ae, + PPCI_STWX = 0x7c00012e, + PPCI_STBX = 0x7c0001ae, + PPCI_LHZX = 0x7c00022e, + PPCI_LHAX = 0x7c0002ae, + PPCI_STHX = 0x7c00032e, + + PPCI_LWBRX = 0x7c00042c, + PPCI_STWBRX = 0x7c00052c, + + PPCI_LFSX = 0x7c00042e, + PPCI_LFDX = 0x7c0004ae, + PPCI_STFSX = 0x7c00052e, + PPCI_STFDX = 0x7c0005ae, + + /* FP instructions. */ + PPCI_FMR = 0xfc000090, + PPCI_FNEG = 0xfc000050, + PPCI_FABS = 0xfc000210, + + PPCI_FRSP = 0xfc000018, + PPCI_FCTIWZ = 0xfc00001e, + + PPCI_FADD = 0xfc00002a, + PPCI_FSUB = 0xfc000028, + PPCI_FMUL = 0xfc000032, + PPCI_FDIV = 0xfc000024, + PPCI_FSQRT = 0xfc00002c, + + PPCI_FMADD = 0xfc00003a, + PPCI_FMSUB = 0xfc000038, + PPCI_FNMSUB = 0xfc00003c, + + PPCI_FCMPU = 0xfc000000, + PPCI_FSEL = 0xfc00002e, +} PPCIns; + +typedef enum PPCCC { + CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO +} PPCCC; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_x86.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_x86.h new file mode 100644 index 0000000..41f401b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_target_x86.h @@ -0,0 +1,342 @@ +/* +** Definitions for x86 and x64 CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_X86_H +#define _LJ_TARGET_X86_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#if LJ_64 +#define GPRDEF(_) \ + _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \ + _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D) +#define FPRDEF(_) \ + _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \ + _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15) +#else +#define GPRDEF(_) \ + _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) +#define FPRDEF(_) \ + _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) +#endif +#define VRIDDEF(_) \ + _(MRM) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_MRM = RID_MAX, /* Pseudo-id for ModRM operand. */ + + /* Calling conventions. */ + RID_RET = RID_EAX, +#if LJ_64 + RID_FPRET = RID_XMM0, +#else + RID_RETLO = RID_EAX, + RID_RETHI = RID_EDX, +#endif + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_EDX, /* Interpreter BASE. */ +#if LJ_64 && !LJ_ABI_WIN + RID_LPC = RID_EBX, /* Interpreter PC. */ + RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */ +#else + RID_LPC = RID_ESI, /* Interpreter PC. */ + RID_DISPATCH = RID_EBX, /* Interpreter DISPATCH table. */ +#endif + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_EAX, + RID_MIN_FPR = RID_XMM0, + RID_MAX_GPR = RID_MIN_FPR, + RID_MAX_FPR = RID_MAX, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR, +}; + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except the stack pointer. */ +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP)) +#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#if LJ_64 +/* Note: this requires the use of FORCE_REX! */ +#define RSET_GPR8 RSET_GPR +#else +#define RSET_GPR8 (RSET_RANGE(RID_EAX, RID_EBX+1)) +#endif + +/* ABI-specific register sets. */ +#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX)) +#if LJ_64 +#if LJ_ABI_WIN +/* Windows x64 ABI. */ +#define RSET_SCRATCH \ + (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1)) +#define REGARG_GPRS \ + (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5)) +#define REGARG_NUMGPR 4 +#define REGARG_NUMFPR 4 +#define REGARG_FIRSTFPR RID_XMM0 +#define REGARG_LASTFPR RID_XMM3 +#define STACKARG_OFS (4*8) +#else +/* The rest of the civilized x64 world has a common ABI. */ +#define RSET_SCRATCH \ + (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR) +#define REGARG_GPRS \ + (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \ + <<5))<<5))<<5))<<5))<<5)) +#define REGARG_NUMGPR 6 +#define REGARG_NUMFPR 8 +#define REGARG_FIRSTFPR RID_XMM0 +#define REGARG_LASTFPR RID_XMM7 +#define STACKARG_OFS 0 +#endif +#else +/* Common x86 ABI. */ +#define RSET_SCRATCH (RSET_ACD|RSET_FPR) +#define REGARG_GPRS (RID_ECX|(RID_EDX<<5)) /* Fastcall only. */ +#define REGARG_NUMGPR 2 /* Fastcall only. */ +#define REGARG_NUMFPR 0 +#define STACKARG_OFS 0 +#endif + +#if LJ_64 +/* Prefer the low 8 regs of each type to reduce REX prefixes. */ +#undef rset_picktop +#define rset_picktop(rs) (lj_fls(lj_bswap(rs)) ^ 0x18) +#endif + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. +*/ +#if LJ_64 +#if LJ_ABI_WIN +#define SPS_FIXED (4*2) +#define SPS_FIRST (4*2) /* Don't use callee register save area. */ +#else +#define SPS_FIXED 4 +#define SPS_FIRST 2 +#endif +#else +#define SPS_FIXED 6 +#define SPS_FIRST 2 +#endif + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */ +#define EXITSTUB_SPACING (2+2) +#define EXITSTUBS_PER_GROUP 32 + +/* -- x86 ModRM operand encoding ------------------------------------------ */ + +typedef enum { + XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0, + XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0, + XM_MASK = 0xc0 +} x86Mode; + +/* Structure to hold variable ModRM operand. */ +typedef struct { + int32_t ofs; /* Offset. */ + uint8_t base; /* Base register or RID_NONE. */ + uint8_t idx; /* Index register or RID_NONE. */ + uint8_t scale; /* Index scale (XM_SCALE1 .. XM_SCALE8). */ +} x86ModRM; + +/* -- Opcodes ------------------------------------------------------------- */ + +/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */ +#define XO_(o) ((uint32_t)(0x0000fe + (0x##o<<24))) +#define XO_FPU(a,b) ((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24))) +#define XO_0f(o) ((uint32_t)(0x0f00fd + (0x##o<<24))) +#define XO_66(o) ((uint32_t)(0x6600fd + (0x##o<<24))) +#define XO_660f(o) ((uint32_t)(0x0f66fc + (0x##o<<24))) +#define XO_f20f(o) ((uint32_t)(0x0ff2fc + (0x##o<<24))) +#define XO_f30f(o) ((uint32_t)(0x0ff3fc + (0x##o<<24))) + +/* This list of x86 opcodes is not intended to be complete. Opcodes are only +** included when needed. Take a look at DynASM or jit.dis_x86 to see the +** whole mess. +*/ +typedef enum { + /* Fixed length opcodes. XI_* prefix. */ + XI_NOP = 0x90, + XI_XCHGa = 0x90, + XI_CALL = 0xe8, + XI_JMP = 0xe9, + XI_JMPs = 0xeb, + XI_PUSH = 0x50, /* Really 50+r. */ + XI_JCCs = 0x70, /* Really 7x. */ + XI_JCCn = 0x80, /* Really 0f8x. */ + XI_LEA = 0x8d, + XI_MOVrib = 0xb0, /* Really b0+r. */ + XI_MOVri = 0xb8, /* Really b8+r. */ + XI_ARITHib = 0x80, + XI_ARITHi = 0x81, + XI_ARITHi8 = 0x83, + XI_PUSHi8 = 0x6a, + XI_TESTb = 0x84, + XI_TEST = 0x85, + XI_MOVmi = 0xc7, + XI_GROUP5 = 0xff, + + /* Note: little-endian byte-order! */ + XI_FLDZ = 0xeed9, + XI_FLD1 = 0xe8d9, + XI_FLDLG2 = 0xecd9, + XI_FLDLN2 = 0xedd9, + XI_FDUP = 0xc0d9, /* Really fld st0. */ + XI_FPOP = 0xd8dd, /* Really fstp st0. */ + XI_FPOP1 = 0xd9dd, /* Really fstp st1. */ + XI_FRNDINT = 0xfcd9, + XI_FSIN = 0xfed9, + XI_FCOS = 0xffd9, + XI_FPTAN = 0xf2d9, + XI_FPATAN = 0xf3d9, + XI_FSCALE = 0xfdd9, + XI_FYL2X = 0xf1d9, + + /* Variable-length opcodes. XO_* prefix. */ + XO_MOV = XO_(8b), + XO_MOVto = XO_(89), + XO_MOVtow = XO_66(89), + XO_MOVtob = XO_(88), + XO_MOVmi = XO_(c7), + XO_MOVmib = XO_(c6), + XO_LEA = XO_(8d), + XO_ARITHib = XO_(80), + XO_ARITHi = XO_(81), + XO_ARITHi8 = XO_(83), + XO_ARITHiw8 = XO_66(83), + XO_SHIFTi = XO_(c1), + XO_SHIFT1 = XO_(d1), + XO_SHIFTcl = XO_(d3), + XO_IMUL = XO_0f(af), + XO_IMULi = XO_(69), + XO_IMULi8 = XO_(6b), + XO_CMP = XO_(3b), + XO_TESTb = XO_(84), + XO_TEST = XO_(85), + XO_GROUP3b = XO_(f6), + XO_GROUP3 = XO_(f7), + XO_GROUP5b = XO_(fe), + XO_GROUP5 = XO_(ff), + XO_MOVZXb = XO_0f(b6), + XO_MOVZXw = XO_0f(b7), + XO_MOVSXb = XO_0f(be), + XO_MOVSXw = XO_0f(bf), + XO_MOVSXd = XO_(63), + XO_BSWAP = XO_0f(c8), + XO_CMOV = XO_0f(40), + + XO_MOVSD = XO_f20f(10), + XO_MOVSDto = XO_f20f(11), + XO_MOVSS = XO_f30f(10), + XO_MOVSSto = XO_f30f(11), + XO_MOVLPD = XO_660f(12), + XO_MOVAPS = XO_0f(28), + XO_XORPS = XO_0f(57), + XO_ANDPS = XO_0f(54), + XO_ADDSD = XO_f20f(58), + XO_SUBSD = XO_f20f(5c), + XO_MULSD = XO_f20f(59), + XO_DIVSD = XO_f20f(5e), + XO_SQRTSD = XO_f20f(51), + XO_MINSD = XO_f20f(5d), + XO_MAXSD = XO_f20f(5f), + XO_ROUNDSD = 0x0b3a0ffc, /* Really 66 0f 3a 0b. See asm_fpmath. */ + XO_UCOMISD = XO_660f(2e), + XO_CVTSI2SD = XO_f20f(2a), + XO_CVTSD2SI = XO_f20f(2d), + XO_CVTTSD2SI= XO_f20f(2c), + XO_CVTSI2SS = XO_f30f(2a), + XO_CVTSS2SI = XO_f30f(2d), + XO_CVTTSS2SI= XO_f30f(2c), + XO_CVTSS2SD = XO_f30f(5a), + XO_CVTSD2SS = XO_f20f(5a), + XO_ADDSS = XO_f30f(58), + XO_MOVD = XO_660f(6e), + XO_MOVDto = XO_660f(7e), + + XO_FLDd = XO_(d9), XOg_FLDd = 0, + XO_FLDq = XO_(dd), XOg_FLDq = 0, + XO_FILDd = XO_(db), XOg_FILDd = 0, + XO_FILDq = XO_(df), XOg_FILDq = 5, + XO_FSTPd = XO_(d9), XOg_FSTPd = 3, + XO_FSTPq = XO_(dd), XOg_FSTPq = 3, + XO_FISTPq = XO_(df), XOg_FISTPq = 7, + XO_FISTTPq = XO_(dd), XOg_FISTTPq = 1, + XO_FADDq = XO_(dc), XOg_FADDq = 0, + XO_FLDCW = XO_(d9), XOg_FLDCW = 5, + XO_FNSTCW = XO_(d9), XOg_FNSTCW = 7 +} x86Op; + +/* x86 opcode groups. */ +typedef uint32_t x86Group; + +#define XG_(i8, i, g) ((x86Group)(((i8) << 16) + ((i) << 8) + (g))) +#define XG_ARITHi(g) XG_(XI_ARITHi8, XI_ARITHi, g) +#define XG_TOXOi(xg) ((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000))) +#define XG_TOXOi8(xg) ((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000))) + +#define XO_ARITH(a) ((x86Op)(0x030000fe + ((a)<<27))) +#define XO_ARITHw(a) ((x86Op)(0x036600fd + ((a)<<27))) + +typedef enum { + XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP, + XOg_X_IMUL +} x86Arith; + +typedef enum { + XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR +} x86Shift; + +typedef enum { + XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV +} x86Group3; + +typedef enum { + XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH +} x86Group5; + +/* x86 condition codes. */ +typedef enum { + CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE, + CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE, + CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB, + CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE, + CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL, + CC_NG = CC_LE, CC_G = CC_NLE +} x86CC; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.c new file mode 100644 index 0000000..9e5e400 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.c @@ -0,0 +1,815 @@ +/* +** Trace management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_trace_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_frame.h" +#include "lj_state.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_gdbjit.h" +#include "lj_record.h" +#include "lj_asm.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" +#include "lj_target.h" + +/* -- Error handling ------------------------------------------------------ */ + +/* Synchronous abort with error message. */ +void lj_trace_err(jit_State *J, TraceError e) +{ + setnilV(&J->errinfo); /* No error info. */ + setintV(J->L->top++, (int32_t)e); + lj_err_throw(J->L, LUA_ERRRUN); +} + +/* Synchronous abort with error message and error info. */ +void lj_trace_err_info(jit_State *J, TraceError e) +{ + setintV(J->L->top++, (int32_t)e); + lj_err_throw(J->L, LUA_ERRRUN); +} + +/* -- Trace management ---------------------------------------------------- */ + +/* The current trace is first assembled in J->cur. The variable length +** arrays point to shared, growable buffers (J->irbuf etc.). When trace +** recording ends successfully, the current trace and its data structures +** are copied to a new (compact) GCtrace object. +*/ + +/* Find a free trace number. */ +static TraceNo trace_findfree(jit_State *J) +{ + MSize osz, lim; + if (J->freetrace == 0) + J->freetrace = 1; + for (; J->freetrace < J->sizetrace; J->freetrace++) + if (traceref(J, J->freetrace) == NULL) + return J->freetrace++; + /* Need to grow trace array. */ + lim = (MSize)J->param[JIT_P_maxtrace] + 1; + if (lim < 2) lim = 2; else if (lim > 65535) lim = 65535; + osz = J->sizetrace; + if (osz >= lim) + return 0; /* Too many traces. */ + lj_mem_growvec(J->L, J->trace, J->sizetrace, lim, GCRef); + for (; osz < J->sizetrace; osz++) + setgcrefnull(J->trace[osz]); + return J->freetrace; +} + +#define TRACE_APPENDVEC(field, szfield, tp) \ + T->field = (tp *)p; \ + memcpy(p, J->cur.field, J->cur.szfield*sizeof(tp)); \ + p += J->cur.szfield*sizeof(tp); + +#ifdef LUAJIT_USE_PERFTOOLS +/* +** Create symbol table of JIT-compiled code. For use with Linux perf tools. +** Example usage: +** perf record -f -e cycles luajit test.lua +** perf report -s symbol +** rm perf.data /tmp/perf-*.map +*/ +#include +#include + +static void perftools_addtrace(GCtrace *T) +{ + static FILE *fp; + GCproto *pt = &gcref(T->startpt)->pt; + const BCIns *startpc = mref(T->startpc, const BCIns); + const char *name = proto_chunknamestr(pt); + BCLine lineno; + if (name[0] == '@' || name[0] == '=') + name++; + else + name = "(string)"; + lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc); + lineno = lj_debug_line(pt, proto_bcpos(pt, startpc)); + if (!fp) { + char fname[40]; + sprintf(fname, "/tmp/perf-%d.map", getpid()); + if (!(fp = fopen(fname, "w"))) return; + setlinebuf(fp); + } + fprintf(fp, "%lx %x TRACE_%d::%s:%u\n", + (long)T->mcode, T->szmcode, T->traceno, name, lineno); +} +#endif + +/* Save current trace by copying and compacting it. */ +static void trace_save(jit_State *J) +{ + size_t sztr = ((sizeof(GCtrace)+7)&~7); + size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns); + size_t sz = sztr + szins + + J->cur.nsnap*sizeof(SnapShot) + + J->cur.nsnapmap*sizeof(SnapEntry); + GCtrace *T = lj_mem_newt(J->L, (MSize)sz, GCtrace); + char *p = (char *)T + sztr; + memcpy(T, &J->cur, sizeof(GCtrace)); + setgcrefr(T->nextgc, J2G(J)->gc.root); + setgcrefp(J2G(J)->gc.root, T); + newwhite(J2G(J), T); + T->gct = ~LJ_TTRACE; + T->ir = (IRIns *)p - J->cur.nk; + memcpy(p, J->cur.ir+J->cur.nk, szins); + p += szins; + TRACE_APPENDVEC(snap, nsnap, SnapShot) + TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry) + J->cur.traceno = 0; + setgcrefp(J->trace[T->traceno], T); + lj_gc_barriertrace(J2G(J), T->traceno); + lj_gdbjit_addtrace(J, T); +#ifdef LUAJIT_USE_PERFTOOLS + perftools_addtrace(T); +#endif +} + +void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T) +{ + jit_State *J = G2J(g); + if (T->traceno) { + lj_gdbjit_deltrace(J, T); + if (T->traceno < J->freetrace) + J->freetrace = T->traceno; + setgcrefnull(J->trace[T->traceno]); + } + lj_mem_free(g, T, + ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) + + T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry)); +} + +/* Re-enable compiling a prototype by unpatching any modified bytecode. */ +void lj_trace_reenableproto(GCproto *pt) +{ + if ((pt->flags & PROTO_ILOOP)) { + BCIns *bc = proto_bc(pt); + BCPos i, sizebc = pt->sizebc;; + pt->flags &= ~PROTO_ILOOP; + if (bc_op(bc[0]) == BC_IFUNCF) + setbc_op(&bc[0], BC_FUNCF); + for (i = 1; i < sizebc; i++) { + BCOp op = bc_op(bc[i]); + if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP) + setbc_op(&bc[i], (int)op+(int)BC_LOOP-(int)BC_ILOOP); + } + } +} + +/* Unpatch the bytecode modified by a root trace. */ +static void trace_unpatch(jit_State *J, GCtrace *T) +{ + BCOp op = bc_op(T->startins); + BCIns *pc = mref(T->startpc, BCIns); + UNUSED(J); + if (op == BC_JMP) + return; /* No need to unpatch branches in parent traces (yet). */ + switch (bc_op(*pc)) { + case BC_JFORL: + lua_assert(traceref(J, bc_d(*pc)) == T); + *pc = T->startins; + pc += bc_j(T->startins); + lua_assert(bc_op(*pc) == BC_JFORI); + setbc_op(pc, BC_FORI); + break; + case BC_JITERL: + case BC_JLOOP: + lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op)); + *pc = T->startins; + break; + case BC_JMP: + lua_assert(op == BC_ITERL); + pc += bc_j(*pc)+2; + if (bc_op(*pc) == BC_JITERL) { + lua_assert(traceref(J, bc_d(*pc)) == T); + *pc = T->startins; + } + break; + case BC_JFUNCF: + lua_assert(op == BC_FUNCF); + *pc = T->startins; + break; + default: /* Already unpatched. */ + break; + } +} + +/* Flush a root trace. */ +static void trace_flushroot(jit_State *J, GCtrace *T) +{ + GCproto *pt = &gcref(T->startpt)->pt; + lua_assert(T->root == 0 && pt != NULL); + /* First unpatch any modified bytecode. */ + trace_unpatch(J, T); + /* Unlink root trace from chain anchored in prototype. */ + if (pt->trace == T->traceno) { /* Trace is first in chain. Easy. */ + pt->trace = T->nextroot; + } else if (pt->trace) { /* Otherwise search in chain of root traces. */ + GCtrace *T2 = traceref(J, pt->trace); + if (T2) { + for (; T2->nextroot; T2 = traceref(J, T2->nextroot)) + if (T2->nextroot == T->traceno) { + T2->nextroot = T->nextroot; /* Unlink from chain. */ + break; + } + } + } +} + +/* Flush a trace. Only root traces are considered. */ +void lj_trace_flush(jit_State *J, TraceNo traceno) +{ + if (traceno > 0 && traceno < J->sizetrace) { + GCtrace *T = traceref(J, traceno); + if (T && T->root == 0) + trace_flushroot(J, T); + } +} + +/* Flush all traces associated with a prototype. */ +void lj_trace_flushproto(global_State *g, GCproto *pt) +{ + while (pt->trace != 0) + trace_flushroot(G2J(g), traceref(G2J(g), pt->trace)); +} + +/* Flush all traces. */ +int lj_trace_flushall(lua_State *L) +{ + jit_State *J = L2J(L); + ptrdiff_t i; + if ((J2G(J)->hookmask & HOOK_GC)) + return 1; + for (i = (ptrdiff_t)J->sizetrace-1; i > 0; i--) { + GCtrace *T = traceref(J, i); + if (T) { + if (T->root == 0) + trace_flushroot(J, T); + lj_gdbjit_deltrace(J, T); + T->traceno = 0; + setgcrefnull(J->trace[i]); + } + } + J->cur.traceno = 0; + J->freetrace = 0; + /* Clear penalty cache. */ + memset(J->penalty, 0, sizeof(J->penalty)); + /* Free the whole machine code and invalidate all exit stub groups. */ + lj_mcode_free(J); + memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup)); + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "flush")); + ); + return 0; +} + +/* Initialize JIT compiler state. */ +void lj_trace_initstate(global_State *g) +{ + jit_State *J = G2J(g); + TValue *tv; + /* Initialize SIMD constants. */ + tv = LJ_KSIMD(J, LJ_KSIMD_ABS); + tv[0].u64 = U64x(7fffffff,ffffffff); + tv[1].u64 = U64x(7fffffff,ffffffff); + tv = LJ_KSIMD(J, LJ_KSIMD_NEG); + tv[0].u64 = U64x(80000000,00000000); + tv[1].u64 = U64x(80000000,00000000); +} + +/* Free everything associated with the JIT compiler state. */ +void lj_trace_freestate(global_State *g) +{ + jit_State *J = G2J(g); +#ifdef LUA_USE_ASSERT + { /* This assumes all traces have already been freed. */ + ptrdiff_t i; + for (i = 1; i < (ptrdiff_t)J->sizetrace; i++) + lua_assert(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL); + } +#endif + lj_mcode_free(J); + lj_ir_k64_freeall(J); + lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry); + lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot); + lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns); + lj_mem_freevec(g, J->trace, J->sizetrace, GCRef); +} + +/* -- Penalties and blacklisting ------------------------------------------ */ + +/* Blacklist a bytecode instruction. */ +static void blacklist_pc(GCproto *pt, BCIns *pc) +{ + setbc_op(pc, (int)bc_op(*pc)+(int)BC_ILOOP-(int)BC_LOOP); + pt->flags |= PROTO_ILOOP; +} + +/* Penalize a bytecode instruction. */ +static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e) +{ + uint32_t i, val = PENALTY_MIN; + for (i = 0; i < PENALTY_SLOTS; i++) + if (mref(J->penalty[i].pc, const BCIns) == pc) { /* Cache slot found? */ + /* First try to bump its hotcount several times. */ + val = ((uint32_t)J->penalty[i].val << 1) + + LJ_PRNG_BITS(J, PENALTY_RNDBITS); + if (val > PENALTY_MAX) { + blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */ + return; + } + goto setpenalty; + } + /* Assign a new penalty cache slot. */ + i = J->penaltyslot; + J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1); + setmref(J->penalty[i].pc, pc); +setpenalty: + J->penalty[i].val = (uint16_t)val; + J->penalty[i].reason = e; + hotcount_set(J2GG(J), pc+1, val); +} + +/* -- Trace compiler state machine ---------------------------------------- */ + +/* Start tracing. */ +static void trace_start(jit_State *J) +{ + lua_State *L; + TraceNo traceno; + + if ((J->pt->flags & PROTO_NOJIT)) { /* JIT disabled for this proto? */ + if (J->parent == 0) { + /* Lazy bytecode patching to disable hotcount events. */ + lua_assert(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL || + bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF); + setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP); + J->pt->flags |= PROTO_ILOOP; + } + J->state = LJ_TRACE_IDLE; /* Silently ignored. */ + return; + } + + /* Get a new trace number. */ + traceno = trace_findfree(J); + if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */ + lua_assert((J2G(J)->hookmask & HOOK_GC) == 0); + lj_trace_flushall(J->L); + J->state = LJ_TRACE_IDLE; /* Silently ignored. */ + return; + } + setgcrefp(J->trace[traceno], &J->cur); + + /* Setup enough of the current trace to be able to send the vmevent. */ + memset(&J->cur, 0, sizeof(GCtrace)); + J->cur.traceno = traceno; + J->cur.nins = J->cur.nk = REF_BASE; + J->cur.ir = J->irbuf; + J->cur.snap = J->snapbuf; + J->cur.snapmap = J->snapmapbuf; + J->mergesnap = 0; + J->needsnap = 0; + J->bcskip = 0; + J->guardemit.irt = 0; + J->postproc = LJ_POST_NONE; + lj_resetsplit(J); + setgcref(J->cur.startpt, obj2gco(J->pt)); + + L = J->L; + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "start")); + setintV(L->top++, traceno); + setfuncV(L, L->top++, J->fn); + setintV(L->top++, proto_bcpos(J->pt, J->pc)); + if (J->parent) { + setintV(L->top++, J->parent); + setintV(L->top++, J->exitno); + } + ); + lj_record_setup(J); +} + +/* Stop tracing. */ +static void trace_stop(jit_State *J) +{ + BCIns *pc = mref(J->cur.startpc, BCIns); + BCOp op = bc_op(J->cur.startins); + GCproto *pt = &gcref(J->cur.startpt)->pt; + TraceNo traceno = J->cur.traceno; + lua_State *L; + + switch (op) { + case BC_FORL: + setbc_op(pc+bc_j(J->cur.startins), BC_JFORI); /* Patch FORI, too. */ + /* fallthrough */ + case BC_LOOP: + case BC_ITERL: + case BC_FUNCF: + /* Patch bytecode of starting instruction in root trace. */ + setbc_op(pc, (int)op+(int)BC_JLOOP-(int)BC_LOOP); + setbc_d(pc, traceno); + addroot: + /* Add to root trace chain in prototype. */ + J->cur.nextroot = pt->trace; + pt->trace = (TraceNo1)traceno; + break; + case BC_RET: + case BC_RET0: + case BC_RET1: + *pc = BCINS_AD(BC_JLOOP, J->cur.snap[0].nslots, traceno); + goto addroot; + case BC_JMP: + /* Patch exit branch in parent to side trace entry. */ + lua_assert(J->parent != 0 && J->cur.root != 0); + lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode); + /* Avoid compiling a side trace twice (stack resizing uses parent exit). */ + traceref(J, J->parent)->snap[J->exitno].count = SNAPCOUNT_DONE; + /* Add to side trace chain in root trace. */ + { + GCtrace *root = traceref(J, J->cur.root); + root->nchild++; + J->cur.nextside = root->nextside; + root->nextside = (TraceNo1)traceno; + } + break; + default: + lua_assert(0); + break; + } + + /* Commit new mcode only after all patching is done. */ + lj_mcode_commit(J, J->cur.mcode); + J->postproc = LJ_POST_NONE; + trace_save(J); + + L = J->L; + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "stop")); + setintV(L->top++, traceno); + ); +} + +/* Start a new root trace for down-recursion. */ +static int trace_downrec(jit_State *J) +{ + /* Restart recording at the return instruction. */ + lua_assert(J->pt != NULL); + lua_assert(bc_isret(bc_op(*J->pc))); + if (bc_op(*J->pc) == BC_RETM) + return 0; /* NYI: down-recursion with RETM. */ + J->parent = 0; + J->exitno = 0; + J->state = LJ_TRACE_RECORD; + trace_start(J); + return 1; +} + +/* Abort tracing. */ +static int trace_abort(jit_State *J) +{ + lua_State *L = J->L; + TraceError e = LJ_TRERR_RECERR; + TraceNo traceno; + + J->postproc = LJ_POST_NONE; + lj_mcode_abort(J); + if (tvisnumber(L->top-1)) + e = (TraceError)numberVint(L->top-1); + if (e == LJ_TRERR_MCODELM) { + L->top--; /* Remove error object */ + J->state = LJ_TRACE_ASM; + return 1; /* Retry ASM with new MCode area. */ + } + /* Penalize or blacklist starting bytecode instruction. */ + if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) + penalty_pc(J, &gcref(J->cur.startpt)->pt, mref(J->cur.startpc, BCIns), e); + + /* Is there anything to abort? */ + traceno = J->cur.traceno; + if (traceno) { + ptrdiff_t errobj = savestack(L, L->top-1); /* Stack may be resized. */ + J->cur.link = 0; + J->cur.linktype = LJ_TRLINK_NONE; + lj_vmevent_send(L, TRACE, + TValue *frame; + const BCIns *pc; + GCfunc *fn; + setstrV(L, L->top++, lj_str_newlit(L, "abort")); + setintV(L->top++, traceno); + /* Find original Lua function call to generate a better error message. */ + frame = J->L->base-1; + pc = J->pc; + while (!isluafunc(frame_func(frame))) { + pc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1; + frame = frame_prev(frame); + } + fn = frame_func(frame); + setfuncV(L, L->top++, fn); + setintV(L->top++, proto_bcpos(funcproto(fn), pc)); + copyTV(L, L->top++, restorestack(L, errobj)); + copyTV(L, L->top++, &J->errinfo); + ); + /* Drop aborted trace after the vmevent (which may still access it). */ + setgcrefnull(J->trace[traceno]); + if (traceno < J->freetrace) + J->freetrace = traceno; + J->cur.traceno = 0; + } + L->top--; /* Remove error object */ + if (e == LJ_TRERR_DOWNREC) + return trace_downrec(J); + else if (e == LJ_TRERR_MCODEAL) + lj_trace_flushall(L); + return 0; +} + +/* Perform pending re-patch of a bytecode instruction. */ +static LJ_AINLINE void trace_pendpatch(jit_State *J, int force) +{ + if (LJ_UNLIKELY(J->patchpc)) { + if (force || J->bcskip == 0) { + *J->patchpc = J->patchins; + J->patchpc = NULL; + } else { + J->bcskip = 0; + } + } +} + +/* State machine for the trace compiler. Protected callback. */ +static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + UNUSED(dummy); + do { + retry: + switch (J->state) { + case LJ_TRACE_START: + J->state = LJ_TRACE_RECORD; /* trace_start() may change state. */ + trace_start(J); + lj_dispatch_update(J2G(J)); + break; + + case LJ_TRACE_RECORD: + trace_pendpatch(J, 0); + setvmstate(J2G(J), RECORD); + lj_vmevent_send_(L, RECORD, + /* Save/restore tmptv state for trace recorder. */ + TValue savetv = J2G(J)->tmptv; + TValue savetv2 = J2G(J)->tmptv2; + setintV(L->top++, J->cur.traceno); + setfuncV(L, L->top++, J->fn); + setintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1); + setintV(L->top++, J->framedepth); + , + J2G(J)->tmptv = savetv; + J2G(J)->tmptv2 = savetv2; + ); + lj_record_ins(J); + break; + + case LJ_TRACE_END: + trace_pendpatch(J, 1); + J->loopref = 0; + if ((J->flags & JIT_F_OPT_LOOP) && + J->cur.link == J->cur.traceno && J->framedepth + J->retdepth == 0) { + setvmstate(J2G(J), OPT); + lj_opt_dce(J); + if (lj_opt_loop(J)) { /* Loop optimization failed? */ + J->cur.link = 0; + J->cur.linktype = LJ_TRLINK_NONE; + J->loopref = J->cur.nins; + J->state = LJ_TRACE_RECORD; /* Try to continue recording. */ + break; + } + J->loopref = J->chain[IR_LOOP]; /* Needed by assembler. */ + } + lj_opt_split(J); + lj_opt_sink(J); + J->state = LJ_TRACE_ASM; + break; + + case LJ_TRACE_ASM: + setvmstate(J2G(J), ASM); + lj_asm_trace(J, &J->cur); + trace_stop(J); + setvmstate(J2G(J), INTERP); + J->state = LJ_TRACE_IDLE; + lj_dispatch_update(J2G(J)); + return NULL; + + default: /* Trace aborted asynchronously. */ + setintV(L->top++, (int32_t)LJ_TRERR_RECERR); + /* fallthrough */ + case LJ_TRACE_ERR: + trace_pendpatch(J, 1); + if (trace_abort(J)) + goto retry; + setvmstate(J2G(J), INTERP); + J->state = LJ_TRACE_IDLE; + lj_dispatch_update(J2G(J)); + return NULL; + } + } while (J->state > LJ_TRACE_RECORD); + return NULL; +} + +/* -- Event handling ------------------------------------------------------ */ + +/* A bytecode instruction is about to be executed. Record it. */ +void lj_trace_ins(jit_State *J, const BCIns *pc) +{ + /* Note: J->L must already be set. pc is the true bytecode PC here. */ + J->pc = pc; + J->fn = curr_func(J->L); + J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL; + while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0) + J->state = LJ_TRACE_ERR; +} + +/* A hotcount triggered. Start recording a root trace. */ +void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc) +{ + /* Note: pc is the interpreter bytecode PC here. It's offset by 1. */ + ERRNO_SAVE + /* Reset hotcount. */ + hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP); + /* Only start a new trace if not recording or inside __gc call or vmevent. */ + if (J->state == LJ_TRACE_IDLE && + !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) { + J->parent = 0; /* Root trace. */ + J->exitno = 0; + J->state = LJ_TRACE_START; + lj_trace_ins(J, pc-1); + } + ERRNO_RESTORE +} + +/* Check for a hot side exit. If yes, start recording a side trace. */ +static void trace_hotside(jit_State *J, const BCIns *pc) +{ + SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno]; + if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) && + snap->count != SNAPCOUNT_DONE && + ++snap->count >= J->param[JIT_P_hotexit]) { + lua_assert(J->state == LJ_TRACE_IDLE); + /* J->parent is non-zero for a side trace. */ + J->state = LJ_TRACE_START; + lj_trace_ins(J, pc); + } +} + +/* Tiny struct to pass data to protected call. */ +typedef struct ExitDataCP { + jit_State *J; + void *exptr; /* Pointer to exit state. */ + const BCIns *pc; /* Restart interpreter at this PC. */ +} ExitDataCP; + +/* Need to protect lj_snap_restore because it may throw. */ +static TValue *trace_exit_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + ExitDataCP *exd = (ExitDataCP *)ud; + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + exd->pc = lj_snap_restore(exd->J, exd->exptr); + UNUSED(dummy); + return NULL; +} + +#ifndef LUAJIT_DISABLE_VMEVENT +/* Push all registers from exit state. */ +static void trace_exit_regs(lua_State *L, ExitState *ex) +{ + int32_t i; + setintV(L->top++, RID_NUM_GPR); + setintV(L->top++, RID_NUM_FPR); + for (i = 0; i < RID_NUM_GPR; i++) { + if (sizeof(ex->gpr[i]) == sizeof(int32_t)) + setintV(L->top++, (int32_t)ex->gpr[i]); + else + setnumV(L->top++, (lua_Number)ex->gpr[i]); + } +#if !LJ_SOFTFP + for (i = 0; i < RID_NUM_FPR; i++) { + setnumV(L->top, ex->fpr[i]); + if (LJ_UNLIKELY(tvisnan(L->top))) + setnanV(L->top); + L->top++; + } +#endif +} +#endif + +#ifdef EXITSTATE_PCREG +/* Determine trace number from pc of exit instruction. */ +static TraceNo trace_exit_find(jit_State *J, MCode *pc) +{ + TraceNo traceno; + for (traceno = 1; traceno < J->sizetrace; traceno++) { + GCtrace *T = traceref(J, traceno); + if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode)) + return traceno; + } + lua_assert(0); + return 0; +} +#endif + +/* A trace exited. Restore interpreter state. */ +int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr) +{ + ERRNO_SAVE + lua_State *L = J->L; + ExitState *ex = (ExitState *)exptr; + ExitDataCP exd; + int errcode; + const BCIns *pc; + void *cf; + GCtrace *T; +#ifdef EXITSTATE_PCREG + J->parent = trace_exit_find(J, (MCode *)(intptr_t)ex->gpr[EXITSTATE_PCREG]); +#endif + T = traceref(J, J->parent); UNUSED(T); +#ifdef EXITSTATE_CHECKEXIT + if (J->exitno == T->nsnap) { /* Treat stack check like a parent exit. */ + lua_assert(T->root != 0); + J->exitno = T->ir[REF_BASE].op2; + J->parent = T->ir[REF_BASE].op1; + T = traceref(J, J->parent); + } +#endif + lua_assert(T != NULL && J->exitno < T->nsnap); + exd.J = J; + exd.exptr = exptr; + errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp); + if (errcode) + return -errcode; /* Return negated error code. */ + + lj_vmevent_send(L, TEXIT, + lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK); + setintV(L->top++, J->parent); + setintV(L->top++, J->exitno); + trace_exit_regs(L, ex); + ); + + pc = exd.pc; + cf = cframe_raw(L->cframe); + setcframe_pc(cf, pc); + if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) { + if (!(G(L)->hookmask & HOOK_GC)) + lj_gc_step(L); /* Exited because of GC: drive GC forward. */ + } else { + trace_hotside(J, pc); + } + if (bc_op(*pc) == BC_JLOOP) { + BCIns *retpc = &traceref(J, bc_d(*pc))->startins; + if (bc_isret(bc_op(*retpc))) { + if (J->state == LJ_TRACE_RECORD) { + J->patchins = *pc; + J->patchpc = (BCIns *)pc; + *J->patchpc = *retpc; + J->bcskip = 1; + } else { + pc = retpc; + setcframe_pc(cf, pc); + } + } + } + /* Return MULTRES or 0. */ + ERRNO_RESTORE + switch (bc_op(*pc)) { + case BC_CALLM: case BC_CALLMT: + return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc)); + case BC_RETM: + return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc)); + case BC_TSETM: + return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc)); + default: + if (bc_op(*pc) >= BC_FUNCF) + return (int)((BCReg)(L->top - L->base) + 1); + return 0; + } +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.h new file mode 100644 index 0000000..f310908 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_trace.h @@ -0,0 +1,53 @@ +/* +** Trace management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TRACE_H +#define _LJ_TRACE_H + +#include "lj_obj.h" + +#if LJ_HASJIT +#include "lj_jit.h" +#include "lj_dispatch.h" + +/* Trace errors. */ +typedef enum { +#define TREDEF(name, msg) LJ_TRERR_##name, +#include "lj_traceerr.h" + LJ_TRERR__MAX +} TraceError; + +LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e); +LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e); + +/* Trace management. */ +LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T); +LJ_FUNC void lj_trace_reenableproto(GCproto *pt); +LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt); +LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno); +LJ_FUNC int lj_trace_flushall(lua_State *L); +LJ_FUNC void lj_trace_initstate(global_State *g); +LJ_FUNC void lj_trace_freestate(global_State *g); + +/* Event handling. */ +LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc); +LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc); +LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr); + +/* Signal asynchronous abort of trace or end of trace. */ +#define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE) +#define lj_trace_end(J) (J->state = LJ_TRACE_END) + +#else + +#define lj_trace_flushall(L) (UNUSED(L), 0) +#define lj_trace_initstate(g) UNUSED(g) +#define lj_trace_freestate(g) UNUSED(g) +#define lj_trace_abort(g) UNUSED(g) +#define lj_trace_end(J) UNUSED(J) + +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_traceerr.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_traceerr.h new file mode 100644 index 0000000..521560a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_traceerr.h @@ -0,0 +1,61 @@ +/* +** Trace compiler error messages. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* This file may be included multiple times with different TREDEF macros. */ + +/* Recording. */ +TREDEF(RECERR, "error thrown or hook called during recording") +TREDEF(TRACEOV, "trace too long") +TREDEF(STACKOV, "trace too deep") +TREDEF(SNAPOV, "too many snapshots") +TREDEF(BLACKL, "blacklisted") +TREDEF(NYIBC, "NYI: bytecode %d") + +/* Recording loop ops. */ +TREDEF(LLEAVE, "leaving loop in root trace") +TREDEF(LINNER, "inner loop in root trace") +TREDEF(LUNROLL, "loop unroll limit reached") + +/* Recording calls/returns. */ +TREDEF(BADTYPE, "bad argument type") +TREDEF(CJITOFF, "JIT compilation disabled for function") +TREDEF(CUNROLL, "call unroll limit reached") +TREDEF(DOWNREC, "down-recursion, restarting") +TREDEF(NYICF, "NYI: C function %p") +TREDEF(NYIFF, "NYI: FastFunc %s") +TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s") +TREDEF(NYIRETL, "NYI: return to lower frame") + +/* Recording indexed load/store. */ +TREDEF(STORENN, "store with nil or NaN key") +TREDEF(NOMM, "missing metamethod") +TREDEF(IDXLOOP, "looping index lookup") +TREDEF(NYITMIX, "NYI: mixed sparse/dense table") + +/* Recording C data operations. */ +TREDEF(NOCACHE, "symbol not in cache") +TREDEF(NYICONV, "NYI: unsupported C type conversion") +TREDEF(NYICALL, "NYI: unsupported C function type") + +/* Optimizations. */ +TREDEF(GFAIL, "guard would always fail") +TREDEF(PHIOV, "too many PHIs") +TREDEF(TYPEINS, "persistent type instability") + +/* Assembler. */ +TREDEF(MCODEAL, "failed to allocate mcode memory") +TREDEF(MCODEOV, "machine code too long") +TREDEF(MCODELM, "hit mcode limit (retrying)") +TREDEF(SPILLOV, "too many spill slots") +TREDEF(BADRA, "inconsistent register allocation") +TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d") +TREDEF(NYIPHI, "NYI: PHI shuffling too complex") +TREDEF(NYICOAL, "NYI: register coalescing too complex") + +#undef TREDEF + +/* Detecting unused error messages: + awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh +*/ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.c new file mode 100644 index 0000000..6cd357e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.c @@ -0,0 +1,34 @@ +/* +** Userdata handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_udata_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_udata.h" + +GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env) +{ + GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata); + global_State *g = G(L); + newwhite(g, ud); /* Not finalized. */ + ud->gct = ~LJ_TUDATA; + ud->udtype = UDTYPE_USERDATA; + ud->len = sz; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcrefnull(ud->metatable); + setgcref(ud->env, obj2gco(env)); + /* Chain to userdata list (after main thread). */ + setgcrefr(ud->nextgc, mainthread(g)->nextgc); + setgcref(mainthread(g)->nextgc, obj2gco(ud)); + return ud; +} + +void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud) +{ + lj_mem_free(g, ud, sizeudata(ud)); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.h new file mode 100644 index 0000000..e03d9a3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_udata.h @@ -0,0 +1,14 @@ +/* +** Userdata handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_UDATA_H +#define _LJ_UDATA_H + +#include "lj_obj.h" + +LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env); +LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vm.h new file mode 100644 index 0000000..4a8f03f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vm.h @@ -0,0 +1,116 @@ +/* +** Assembler VM interface definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_VM_H +#define _LJ_VM_H + +#include "lj_obj.h" + +/* Entry points for ASM parts of VM. */ +LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1); +LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); +typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud); +LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud, + lua_CPFunction cp); +LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); +LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode); +LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe); +LJ_ASMF void lj_vm_unwind_c_eh(void); +LJ_ASMF void lj_vm_unwind_ff_eh(void); +#if LJ_TARGET_X86ORX64 +LJ_ASMF void lj_vm_unwind_rethrow(void); +#endif + +/* Miscellaneous functions. */ +#if LJ_TARGET_X86ORX64 +LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]); +#endif +#if LJ_TARGET_PPC +void lj_vm_cachesync(void *start, void *end); +#endif +LJ_ASMF double lj_vm_foldarith(double x, double y, int op); +#if LJ_HASJIT +LJ_ASMF double lj_vm_foldfpm(double x, int op); +#endif +#if !LJ_ARCH_HASFPU +/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */ +#endif + +/* Dispatch targets for recording and hooks. */ +LJ_ASMF void lj_vm_record(void); +LJ_ASMF void lj_vm_inshook(void); +LJ_ASMF void lj_vm_rethook(void); +LJ_ASMF void lj_vm_callhook(void); + +/* Trace exit handling. */ +LJ_ASMF void lj_vm_exit_handler(void); +LJ_ASMF void lj_vm_exit_interp(void); + +/* Internal math helper functions. */ +#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC +#define lj_vm_floor floor +#define lj_vm_ceil ceil +#else +LJ_ASMF double lj_vm_floor(double); +LJ_ASMF double lj_vm_ceil(double); +#if LJ_TARGET_ARM +LJ_ASMF double lj_vm_floor_sf(double); +LJ_ASMF double lj_vm_ceil_sf(double); +#endif +#endif +#if defined(LUAJIT_NO_LOG2) || LJ_TARGET_X86ORX64 +LJ_ASMF double lj_vm_log2(double); +#else +#define lj_vm_log2 log2 +#endif + +#if LJ_HASJIT +#if LJ_TARGET_X86ORX64 +LJ_ASMF void lj_vm_floor_sse(void); +LJ_ASMF void lj_vm_ceil_sse(void); +LJ_ASMF void lj_vm_trunc_sse(void); +LJ_ASMF void lj_vm_exp_x87(void); +LJ_ASMF void lj_vm_exp2_x87(void); +LJ_ASMF void lj_vm_pow_sse(void); +LJ_ASMF void lj_vm_powi_sse(void); +#else +#if LJ_TARGET_PPC +#define lj_vm_trunc trunc +#else +LJ_ASMF double lj_vm_trunc(double); +#if LJ_TARGET_ARM +LJ_ASMF double lj_vm_trunc_sf(double); +#endif +#endif +LJ_ASMF double lj_vm_powi(double, int32_t); +#ifdef LUAJIT_NO_EXP2 +LJ_ASMF double lj_vm_exp2(double); +#else +#define lj_vm_exp2 exp2 +#endif +#endif +LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t); +#if LJ_HASFFI +LJ_ASMF int lj_vm_errno(void); +#endif +#endif + +/* Continuations for metamethods. */ +LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */ +LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */ +LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */ +LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */ +LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */ +LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */ + +enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */ + +/* Start of the ASM code. */ +LJ_ASMF char lj_vm_asm_begin[]; + +/* Bytecode offsets are relative to lj_vm_asm_begin. */ +#define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs))) + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.c new file mode 100644 index 0000000..e14ad5b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.c @@ -0,0 +1,57 @@ +/* +** VM event handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lj_vmevent_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" + +ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev) +{ + global_State *g = G(L); + GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY); + cTValue *tv = lj_tab_getstr(tabV(registry(L)), s); + if (tvistab(tv)) { + int hash = VMEVENT_HASH(ev); + tv = lj_tab_getint(tabV(tv), hash); + if (tv && tvisfunc(tv)) { + lj_state_checkstack(L, LUA_MINSTACK); + setfuncV(L, L->top++, funcV(tv)); + return savestack(L, L->top); + } + } + g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */ + return 0; +} + +void lj_vmevent_call(lua_State *L, ptrdiff_t argbase) +{ + global_State *g = G(L); + uint8_t oldmask = g->vmevmask; + uint8_t oldh = hook_save(g); + int status; + g->vmevmask = 0; /* Disable all events. */ + hook_vmevent(g); + status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0); + if (LJ_UNLIKELY(status)) { + /* Really shouldn't use stderr here, but where else to complain? */ + L->top--; + fputs("VM handler failed: ", stderr); + fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr); + fputc('\n', stderr); + } + hook_restore(g, oldh); + if (g->vmevmask != VMEVENT_NOCACHE) + g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.h new file mode 100644 index 0000000..51bae01 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmevent.h @@ -0,0 +1,59 @@ +/* +** VM event handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_VMEVENT_H +#define _LJ_VMEVENT_H + +#include "lj_obj.h" + +/* Registry key for VM event handler table. */ +#define LJ_VMEVENTS_REGKEY "_VMEVENTS" +#define LJ_VMEVENTS_HSIZE 4 + +#define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7)) +#define VMEVENT_HASH(ev) ((int)(ev) & ~7) +#define VMEVENT_HASHIDX(h) ((int)(h) << 3) +#define VMEVENT_NOCACHE 255 + +#define VMEVENT_DEF(name, hash) \ + LJ_VMEVENT_##name##_, \ + LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3) + +/* VM event IDs. */ +typedef enum { + VMEVENT_DEF(BC, 0x00003883), + VMEVENT_DEF(TRACE, 0xb2d91467), + VMEVENT_DEF(RECORD, 0x9284bf4f), + VMEVENT_DEF(TEXIT, 0xb29df2b0), + LJ_VMEVENT__MAX +} VMEvent; + +#ifdef LUAJIT_DISABLE_VMEVENT +#define lj_vmevent_send(L, ev, args) UNUSED(L) +#define lj_vmevent_send_(L, ev, args, post) UNUSED(L) +#else +#define lj_vmevent_send(L, ev, args) \ + if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ + ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ + if (argbase) { \ + args \ + lj_vmevent_call(L, argbase); \ + } \ + } +#define lj_vmevent_send_(L, ev, args, post) \ + if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ + ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ + if (argbase) { \ + args \ + lj_vmevent_call(L, argbase); \ + post \ + } \ + } + +LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev); +LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmmath.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmmath.c new file mode 100644 index 0000000..63886aa --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lj_vmmath.c @@ -0,0 +1,140 @@ +/* +** Math helper functions for assembler VM. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_vmmath_c +#define LUA_CORE + +#include +#include + +#include "lj_obj.h" +#include "lj_ir.h" +#include "lj_vm.h" + +/* -- Helper functions for generated machine code ------------------------- */ + +#if LJ_TARGET_X86ORX64 +/* Wrapper functions to avoid linker issues on OSX. */ +LJ_FUNCA double lj_vm_sinh(double x) { return sinh(x); } +LJ_FUNCA double lj_vm_cosh(double x) { return cosh(x); } +LJ_FUNCA double lj_vm_tanh(double x) { return tanh(x); } +#endif + +#if !LJ_TARGET_X86ORX64 +double lj_vm_foldarith(double x, double y, int op) +{ + switch (op) { + case IR_ADD - IR_ADD: return x+y; break; + case IR_SUB - IR_ADD: return x-y; break; + case IR_MUL - IR_ADD: return x*y; break; + case IR_DIV - IR_ADD: return x/y; break; + case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break; + case IR_POW - IR_ADD: return pow(x, y); break; + case IR_NEG - IR_ADD: return -x; break; + case IR_ABS - IR_ADD: return fabs(x); break; +#if LJ_HASJIT + case IR_ATAN2 - IR_ADD: return atan2(x, y); break; + case IR_LDEXP - IR_ADD: return ldexp(x, (int)y); break; + case IR_MIN - IR_ADD: return x > y ? y : x; break; + case IR_MAX - IR_ADD: return x < y ? y : x; break; +#endif + default: return x; + } +} +#endif + +#if LJ_HASJIT + +#ifdef LUAJIT_NO_LOG2 +double lj_vm_log2(double a) +{ + return log(a) * 1.4426950408889634074; +} +#endif + +#ifdef LUAJIT_NO_EXP2 +double lj_vm_exp2(double a) +{ + return exp(a * 0.6931471805599453); +} +#endif + +#if !(LJ_TARGET_ARM || LJ_TARGET_PPC) +int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b) +{ + uint32_t y, ua, ub; + lua_assert(b != 0); /* This must be checked before using this function. */ + ua = a < 0 ? (uint32_t)-a : (uint32_t)a; + ub = b < 0 ? (uint32_t)-b : (uint32_t)b; + y = ua % ub; + if (y != 0 && (a^b) < 0) y = y - ub; + if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y; + return (int32_t)y; +} +#endif + +#if !LJ_TARGET_X86ORX64 +/* Unsigned x^k. */ +static double lj_vm_powui(double x, uint32_t k) +{ + double y; + lua_assert(k != 0); + for (; (k & 1) == 0; k >>= 1) x *= x; + y = x; + if ((k >>= 1) != 0) { + for (;;) { + x *= x; + if (k == 1) break; + if (k & 1) y *= x; + k >>= 1; + } + y *= x; + } + return y; +} + +/* Signed x^k. */ +double lj_vm_powi(double x, int32_t k) +{ + if (k > 1) + return lj_vm_powui(x, (uint32_t)k); + else if (k == 1) + return x; + else if (k == 0) + return 1.0; + else + return 1.0 / lj_vm_powui(x, (uint32_t)-k); +} + +/* Computes fpm(x) for extended math functions. */ +double lj_vm_foldfpm(double x, int fpm) +{ + switch (fpm) { + case IRFPM_FLOOR: return lj_vm_floor(x); + case IRFPM_CEIL: return lj_vm_ceil(x); + case IRFPM_TRUNC: return lj_vm_trunc(x); + case IRFPM_SQRT: return sqrt(x); + case IRFPM_EXP: return exp(x); + case IRFPM_EXP2: return lj_vm_exp2(x); + case IRFPM_LOG: return log(x); + case IRFPM_LOG2: return lj_vm_log2(x); + case IRFPM_LOG10: return log10(x); + case IRFPM_SIN: return sin(x); + case IRFPM_COS: return cos(x); + case IRFPM_TAN: return tan(x); + default: lua_assert(0); + } + return 0; +} +#endif + +#if LJ_HASFFI +int lj_vm_errno(void) +{ + return errno; +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ljamalg.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ljamalg.c new file mode 100644 index 0000000..52a8615 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ljamalg.c @@ -0,0 +1,93 @@ +/* +** LuaJIT core and libraries amalgamation. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* ++--------------------------------------------------------------------------+ +| WARNING: Compiling the amalgamation needs a lot of virtual memory | +| (around 300 MB with GCC 4.x)! If you don't have enough physical memory | +| your machine will start swapping to disk and the compile will not finish | +| within a reasonable amount of time. | +| So either compile on a bigger machine or use the non-amalgamated build. | ++--------------------------------------------------------------------------+ +*/ + +#define ljamalg_c +#define LUA_CORE + +/* To get the mremap prototype. Must be defined before any system includes. */ +#if defined(__linux__) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + +#ifndef WINVER +#define WINVER 0x0501 +#endif + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_gc.c" +#include "lj_err.c" +#include "lj_char.c" +#include "lj_bc.c" +#include "lj_obj.c" +#include "lj_str.c" +#include "lj_tab.c" +#include "lj_func.c" +#include "lj_udata.c" +#include "lj_meta.c" +#include "lj_debug.c" +#include "lj_state.c" +#include "lj_dispatch.c" +#include "lj_vmevent.c" +#include "lj_vmmath.c" +#include "lj_strscan.c" +#include "lj_api.c" +#include "lj_lex.c" +#include "lj_parse.c" +#include "lj_bcread.c" +#include "lj_bcwrite.c" +#include "lj_load.c" +#include "lj_ctype.c" +#include "lj_cdata.c" +#include "lj_cconv.c" +#include "lj_ccall.c" +#include "lj_ccallback.c" +#include "lj_carith.c" +#include "lj_clib.c" +#include "lj_cparse.c" +#include "lj_lib.c" +#include "lj_ir.c" +#include "lj_opt_mem.c" +#include "lj_opt_fold.c" +#include "lj_opt_narrow.c" +#include "lj_opt_dce.c" +#include "lj_opt_loop.c" +#include "lj_opt_split.c" +#include "lj_opt_sink.c" +#include "lj_mcode.c" +#include "lj_snap.c" +#include "lj_record.c" +#include "lj_crecord.c" +#include "lj_ffrecord.c" +#include "lj_asm.c" +#include "lj_trace.c" +#include "lj_gdbjit.c" +#include "lj_alloc.c" + +#include "lib_aux.c" +#include "lib_base.c" +#include "lib_math.c" +#include "lib_string.c" +#include "lib_table.c" +#include "lib_io.c" +#include "lib_os.c" +#include "lib_package.c" +#include "lib_debug.c" +#include "lib_bit.c" +#include "lib_jit.c" +#include "lib_ffi.c" +#include "lib_init.c" + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.c new file mode 100644 index 0000000..f3022df --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.c @@ -0,0 +1,460 @@ +/* +** $Id: llex.c,v 2.19 2006/02/06 18:28:16 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "lzio.h" + + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case EOZ: { + return TK_EOS; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.h new file mode 100644 index 0000000..d4ca7f2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llex.h @@ -0,0 +1,81 @@ +/* +** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llimits.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llimits.h new file mode 100644 index 0000000..b03221a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmathlib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmathlib.c new file mode 100644 index 0000000..d181a73 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmathlib.c @@ -0,0 +1,263 @@ +/* +** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $ +** Standard mathematical library +** See Copyright Notice in lua.h +*/ + + +#include +#include + +#define lmathlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#undef PI +#define PI (3.14159265358979323846) +#define RADIANS_PER_DEGREE (PI/180.0) + + + +static int math_abs (lua_State *L) { + lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sin (lua_State *L) { + lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sinh (lua_State *L) { + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cos (lua_State *L) { + lua_pushnumber(L, cos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cosh (lua_State *L) { + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tan (lua_State *L) { + lua_pushnumber(L, tan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tanh (lua_State *L) { + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_asin (lua_State *L) { + lua_pushnumber(L, asin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_acos (lua_State *L) { + lua_pushnumber(L, acos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan (lua_State *L) { + lua_pushnumber(L, atan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan2 (lua_State *L) { + lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_ceil (lua_State *L) { + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); + return 1; +} + +static int math_floor (lua_State *L) { + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); + return 1; +} + +static int math_fmod (lua_State *L) { + lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_modf (lua_State *L) { + double ip; + double fp = modf(luaL_checknumber(L, 1), &ip); + lua_pushnumber(L, ip); + lua_pushnumber(L, fp); + return 2; +} + +static int math_sqrt (lua_State *L) { + lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); + return 1; +} + +static int math_pow (lua_State *L) { + lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_log (lua_State *L) { + lua_pushnumber(L, log(luaL_checknumber(L, 1))); + return 1; +} + +static int math_log10 (lua_State *L) { + lua_pushnumber(L, log10(luaL_checknumber(L, 1))); + return 1; +} + +static int math_exp (lua_State *L) { + lua_pushnumber(L, exp(luaL_checknumber(L, 1))); + return 1; +} + +static int math_deg (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); + return 1; +} + +static int math_rad (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); + return 1; +} + +static int math_frexp (lua_State *L) { + int e; + lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); + lua_pushinteger(L, e); + return 2; +} + +static int math_ldexp (lua_State *L) { + lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); + return 1; +} + + + +static int math_min (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmin = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d < dmin) + dmin = d; + } + lua_pushnumber(L, dmin); + return 1; +} + + +static int math_max (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmax = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d > dmax) + dmax = d; + } + lua_pushnumber(L, dmax); + return 1; +} + + +static int math_random (lua_State *L) { + /* the `%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ + lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; + } + case 1: { /* only upper limit */ + int u = luaL_checkint(L, 1); + luaL_argcheck(L, 1<=u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ + break; + } + case 2: { /* lower and upper limits */ + int l = luaL_checkint(L, 1); + int u = luaL_checkint(L, 2); + luaL_argcheck(L, l<=u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ + break; + } + default: return luaL_error(L, "wrong number of arguments"); + } + return 1; +} + + +static int math_randomseed (lua_State *L) { + srand(luaL_checkint(L, 1)); + return 0; +} + + +static const luaL_Reg mathlib[] = { + {"abs", math_abs}, + {"acos", math_acos}, + {"asin", math_asin}, + {"atan2", math_atan2}, + {"atan", math_atan}, + {"ceil", math_ceil}, + {"cosh", math_cosh}, + {"cos", math_cos}, + {"deg", math_deg}, + {"exp", math_exp}, + {"floor", math_floor}, + {"fmod", math_fmod}, + {"frexp", math_frexp}, + {"ldexp", math_ldexp}, + {"log10", math_log10}, + {"log", math_log}, + {"max", math_max}, + {"min", math_min}, + {"modf", math_modf}, + {"pow", math_pow}, + {"rad", math_rad}, + {"random", math_random}, + {"randomseed", math_randomseed}, + {"sinh", math_sinh}, + {"sin", math_sin}, + {"sqrt", math_sqrt}, + {"tanh", math_tanh}, + {"tan", math_tan}, + {NULL, NULL} +}; + + +/* +** Open math library +*/ +LUALIB_API int luaopen_math (lua_State *L) { + luaL_register(L, LUA_MATHLIBNAME, mathlib); + lua_pushnumber(L, PI); + lua_setfield(L, -2, "pi"); + lua_pushnumber(L, HUGE_VAL); + lua_setfield(L, -2, "huge"); +#if defined(LUA_COMPAT_MOD) + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.c new file mode 100644 index 0000000..cef2bc5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.c @@ -0,0 +1,86 @@ +/* +** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.h new file mode 100644 index 0000000..19df1fb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lmem.h @@ -0,0 +1,49 @@ +/* +** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loadlib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loadlib.c new file mode 100644 index 0000000..19edaca --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loadlib.c @@ -0,0 +1,667 @@ +/* +** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +** +** This module contains an implementation of loadlib for Unix systems +** that have dlfcn, an implementation for Darwin (Mac OS X), an +** implementation for Windows, and a stub for other systems. +*/ + + +#include +#include + + +#define loadlib_c +#define LUA_LIB + +#include "lauxlib.h" +#include "lobject.h" +#include "lua.h" +#include "lualib.h" + + +/* environment variables that hold the search path for packages */ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" + +/* prefix for open functions in C libraries */ +#define LUA_POF "luaopen_" + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "_" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +/* error codes for ll_loadfunc */ +#define ERRLIB 1 +#define ERRFUNC 2 + +#define setprogdir(L) ((void)0) + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(LUA_DL_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include + + +#undef setprogdir + +static void setprogdir (lua_State *L) { + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff)/sizeof(char); + DWORD n = GetModuleFileName(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); + else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibrary(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include + + +/* Mac appends a `_' before C function names */ +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +#define DLMSG "dynamic libraries not enabled; check your Lua installation" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + return ERRLIB; /* unable to load library */ + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f == NULL) + return ERRFUNC; /* unable to find function */ + lua_pushcfunction(L, f); + return 0; /* return function */ + } +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int stat = ll_loadfunc(L, path, init); + if (stat == 0) /* no errors? */ + return 1; /* return the loaded function */ + else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + + + +/* +** {====================================================== +** 'require' function +** ======================================================= +*/ + + +static int readable (const char *filename) { + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + + +static const char *pushnexttemplate (lua_State *L, const char *path) { + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, l - path); /* template */ + return l; +} + + +static const char *findfile (lua_State *L, const char *name, + const char *pname) { + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + lua_pushstring(L, ""); /* error accumulator */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename; + filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pop(L, 2); /* remove path template and file name */ + luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_concat(L, 2); + } + return NULL; /* not found */ +} + + +static void loaderror (lua_State *L, const char *filename) { + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + + +static int loader_Lua (lua_State *L) { + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static const char *mkfuncname (lua_State *L, const char *modname) { + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, POF"%s", funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + + +static int loader_C (lua_State *L) { + const char *funcname; + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + funcname = mkfuncname(L, name); + if (ll_loadfunc(L, filename, funcname) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static int loader_Croot (lua_State *L) { + const char *funcname; + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int stat; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, p - name); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + funcname = mkfuncname(L, name); + if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { + if (stat != ERRFUNC) loaderror(L, filename); /* real error */ + luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + + +static int loader_preload (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) /* not found? */ + luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); + return 1; +} + + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushstring(L, ""); /* error message accumulator */ + for (i=1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + return 1; +} + +/* }====================================================== */ + + + +/* +** {====================================================== +** 'module' function +** ======================================================= +*/ + + +static void setfenv (lua_State *L) { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "f", &ar); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + + +static void dooptions (lua_State *L, int n) { + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + + +static void modinit (lua_State *L, const char *modname) { + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + return luaL_error(L, "name conflict for module " LUA_QS, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + + +static int ll_seeall (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + + +/* }====================================================== */ + + + +/* auxiliary mark (for internal use) */ +#define AUXMARK "\1" + +static void setpath (lua_State *L, const char *fieldname, const char *envname, + const char *def) { + const char *path = getenv(envname); + if (path == NULL) /* no environment variable? */ + lua_pushstring(L, def); /* use default */ + else { + /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + + +static const luaL_Reg pk_funcs[] = { + {"loadlib", ll_loadlib}, + {"seeall", ll_seeall}, + {NULL, NULL} +}; + + +static const luaL_Reg ll_funcs[] = { + {"module", ll_module}, + {"require", ll_require}, + {NULL, NULL} +}; + + +static const lua_CFunction loaders[] = + {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; + + +LUALIB_API int luaopen_package (lua_State *L) { + int i; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + luaL_register(L, LUA_LOADLIBNAME, pk_funcs); +#if defined(LUA_COMPAT_LOADLIB) + lua_getfield(L, -1, "loadlib"); + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); +#endif + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + /* create `loaders' table */ + lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + /* fill it with pre-defined loaders */ + for (i=0; loaders[i] != NULL; i++) { + lua_pushcfunction(L, loaders[i]); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ + /* store config information */ + lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); + lua_setfield(L, -2, "config"); + /* set field `loaded' */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_newtable(L); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, ll_funcs); /* open lib into global table */ + lua_pop(L, 1); + return 1; /* return 'package' table */ +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.c new file mode 100644 index 0000000..acde82c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.c @@ -0,0 +1,214 @@ +/* +** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + *result = lua_str2number(s, &endptr); + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.h new file mode 100644 index 0000000..8ce4405 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lobject.h @@ -0,0 +1,381 @@ +/* +** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(tsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA const TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.c new file mode 100644 index 0000000..bf9cd52 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.c @@ -0,0 +1,102 @@ +/* +** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.h new file mode 100644 index 0000000..2834b1d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lopcodes.h @@ -0,0 +1,268 @@ +/* +** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loslib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loslib.c new file mode 100644 index 0000000..509d7b7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/loslib.c @@ -0,0 +1,238 @@ +/* +** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 roberto Exp $ +** Standard Operating System library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define loslib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +static int os_pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static int os_execute (lua_State *L) { + lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + return 1; +} + + +static int os_remove (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return os_pushresult(L, remove(filename) == 0, filename); +} + + +static int os_rename (lua_State *L) { + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return os_pushresult(L, rename(fromname, toname) == 0, fromname); +} + + +static int os_tmpname (lua_State *L) { + char buff[LUA_TMPNAMBUFSIZE]; + int err; + lua_tmpnam(buff, err); + if (err) + return luaL_error(L, "unable to generate a unique filename"); + lua_pushstring(L, buff); + return 1; +} + + +static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + return 1; +} + + +static int os_clock (lua_State *L) { + lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + return 1; +} + + +/* +** {====================================================== +** Time/Date operations +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, +** wday=%w+1, yday=%j, isdst=? } +** ======================================================= +*/ + +static void setfield (lua_State *L, const char *key, int value) { + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield (lua_State *L, const char *key, int value) { + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield (lua_State *L, const char *key) { + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + + +static int getfield (lua_State *L, const char *key, int d) { + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) + res = (int)lua_tointeger(L, -1); + else { + if (d < 0) + return luaL_error(L, "field " LUA_QS " missing in date table", key); + res = d; + } + lua_pop(L, 1); + return res; +} + + +static int os_date (lua_State *L) { + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = lua_isnoneornil(L, 2) ? time(NULL) : + (time_t)luaL_checknumber(L, 2); + struct tm *stm; + if (*s == '!') { /* UTC? */ + stm = gmtime(&t); + s++; /* skip `!' */ + } + else + stm = localtime(&t); + if (stm == NULL) /* invalid date? */ + lua_pushnil(L); + else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } + else { + char b[256]; + if (strftime(b, sizeof(b), s, stm)) + lua_pushstring(L, b); + else + return luaL_error(L, LUA_QL("date") " format too long"); + } + return 1; +} + + +static int os_time (lua_State *L) { + time_t t; + if (lua_isnoneornil(L, 1)) /* called without args? */ + t = time(NULL); /* get current time */ + else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + + +static int os_difftime (lua_State *L) { + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, 0)))); + return 1; +} + +/* }====================================================== */ + + +static int os_setlocale (lua_State *L) { + static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, + LC_NUMERIC, LC_TIME}; + static const char *const catnames[] = {"all", "collate", "ctype", "monetary", + "numeric", "time", NULL}; + const char *l = lua_tostring(L, 1); + int op = luaL_checkoption(L, 2, "all", catnames); + luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); + lua_pushstring(L, setlocale(cat[op], l)); + return 1; +} + + +static int os_exit (lua_State *L) { + exit(luaL_optint(L, 1, EXIT_SUCCESS)); + return 0; /* to avoid warnings */ +} + +static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, + {"execute", os_execute}, + {"exit", os_exit}, + {"getenv", os_getenv}, + {"remove", os_remove}, + {"rename", os_rename}, + {"setlocale", os_setlocale}, + {"time", os_time}, + {"tmpname", os_tmpname}, + {NULL, NULL} +}; + +/* }====================================================== */ + + + +LUALIB_API int luaopen_os (lua_State *L) { + luaL_register(L, LUA_OSLIBNAME, syslib); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.c new file mode 100644 index 0000000..b40ee79 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.c @@ -0,0 +1,1336 @@ +/* +** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" + + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + lua_assert(!bl->isbreakable || !bl->upval); /* loops have no body */ + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key), + luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ +struct LHS_assign { + struct LHS_assign *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +}; + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} + + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + struct LHS_assign nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && !bl->isbreakable) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + checknext(ls, TK_DO); + block(ls); + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + checknext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + checknext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + struct LHS_assign v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + assignment(ls, &v, 1); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + breakstat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.h new file mode 100644 index 0000000..d5e6e81 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lparser.h @@ -0,0 +1,83 @@ +/* +** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "ltable.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.c new file mode 100644 index 0000000..77e93fb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.c @@ -0,0 +1,214 @@ +/* +** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + luai_userstateclose(L); + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + close_state(L); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.h new file mode 100644 index 0000000..d296a4c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstate.h @@ -0,0 +1,168 @@ +/* +** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.c new file mode 100644 index 0000000..4319930 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.c @@ -0,0 +1,111 @@ +/* +** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.h new file mode 100644 index 0000000..1d2e91e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstrlib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstrlib.c new file mode 100644 index 0000000..84478fd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lstrlib.c @@ -0,0 +1,863 @@ +/* +** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + return (pos>=0) ? pos : (ptrdiff_t)len+pos+1; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + default: { + luaL_argerror(L, 3, "string/function/table expected"); + return; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (strchr(FLAGS, *p)) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option to " LUA_QL("format")); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, + {"dump", str_dump}, + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.c new file mode 100644 index 0000000..bc91cac --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static const Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + n += 1; /* normalize number (avoid -0) */ + lua_assert(sizeof(a) <= sizeof(n)); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +const TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +const TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +const TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + const TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + const TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.h new file mode 100644 index 0000000..09193cd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltablib.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltablib.c new file mode 100644 index 0000000..453b23b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltablib.c @@ -0,0 +1,278 @@ +/* +** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (e == 0) return 0; /* table is `empty' */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + const TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltm.h new file mode 100644 index 0000000..866c796 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ltm.h @@ -0,0 +1,54 @@ +/* +** $Id: ltm.h,v 2.6 2005/06/06 13:30:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.h new file mode 100644 index 0000000..c83fd3b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.h @@ -0,0 +1,393 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + +/* From Lua 5.2. */ +LUA_API void *lua_upvalueid (lua_State *L, int idx, int n); +LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2); +LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname, const char *mode); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.hpp b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.hpp new file mode 100644 index 0000000..07e9002 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua.hpp @@ -0,0 +1,9 @@ +// C++ wrapper for LuaJIT header files. + +extern "C" { +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "luajit.h" +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.dll b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.dll new file mode 100644 index 0000000..63ff004 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.dll differ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.exp b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.exp new file mode 100644 index 0000000..e432ce0 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.exp differ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.lib b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.lib new file mode 100644 index 0000000..7ab4ce5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lua51.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luac.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luac.c new file mode 100644 index 0000000..2dd76b7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luac.c @@ -0,0 +1,196 @@ +/* +** $Id: luac.c,v 1.52 2005/11/11 14:03:13 lhf Exp $ +** Lua compiler (saves bytecodes to files; also list bytecodes) +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include + +#define luac_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstring.h" +#include "lundump.h" + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -l list\n" + " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n", + progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i))->l.p) + +static Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + int i,pc; + Proto* f=luaF_newproto(L); + setptvalue2s(L,L->top,f); incr_top(L); + f->source=luaS_newliteral(L,"=(" PROGNAME ")"); + f->maxstacksize=1; + pc=2*n+1; + f->code=luaM_newvector(L,pc,Instruction); + f->sizecode=pc; + f->p=luaM_newvector(L,n,Proto*); + f->sizep=n; + pc=0; + for (i=0; ip[i]=toproto(L,i-n-1); + f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); + f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); + } + f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +struct Smain { + int argc; + char** argv; +}; + +static int pmain(lua_State* L) +{ + struct Smain* s = (struct Smain*)lua_touserdata(L, 1); + int argc=s->argc; + char** argv=s->argv; + Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +int main(int argc, char* argv[]) +{ + lua_State* L; + struct Smain s; + int i=doargs(argc,argv); + argc-=i; argv+=i; + if (argc<=0) usage("no input files given"); + L=lua_open(); + if (L==NULL) fatal("not enough memory for state"); + s.argc=argc; + s.argv=argv; + if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); + lua_close(L); + return EXIT_SUCCESS; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luaconf.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luaconf.h new file mode 100644 index 0000000..affb7da --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luaconf.h @@ -0,0 +1,156 @@ +/* +** Configuration header. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef luaconf_h +#define luaconf_h + +#ifndef WINVER +#define WINVER 0x0501 +#endif +#include +#include + +/* Default path for loading Lua and C modules with require(). */ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" +#else +/* +** Note to distribution maintainers: do NOT patch the following lines! +** Please read ../doc/install.html#distro and pass PREFIX=/usr instead. +*/ +#ifndef LUA_MULTILIB +#define LUA_MULTILIB "lib" +#endif +#ifndef LUA_LMULTILIB +#define LUA_LMULTILIB "lib" +#endif +#define LUA_LROOT "/usr/local" +#define LUA_LUADIR "/lua/5.1/" +#define LUA_LJDIR "/luajit-2.0.3/" + +#ifdef LUA_ROOT +#define LUA_JROOT LUA_ROOT +#define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR +#define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR +#define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua" +#define LUA_RCPATH ";" LUA_RCDIR "?.so" +#else +#define LUA_JROOT LUA_LROOT +#define LUA_RLPATH +#define LUA_RCPATH +#endif + +#define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua" +#define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR +#define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR +#define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua" +#define LUA_LCPATH1 ";" LUA_LCDIR "?.so" +#define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so" + +#define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH +#define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2 +#endif + +/* Environment variable names for path overrides and initialization code. */ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + +/* Special file system characters. */ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" +#define LUA_PATH_CONFIG \ + LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \ + LUA_EXECDIR "\n" LUA_IGMARK + +/* Quoting in error messages. */ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + +/* Various tunables. */ +#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */ +#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */ +#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */ +#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */ +#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */ + +/* Compatibility with older library function names. */ +#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */ +#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */ + +/* Configuration for the frontend (the luajit executable). */ +#if defined(luajit_c) +#define LUA_PROGNAME "luajit" /* Fallback frontend name. */ +#define LUA_PROMPT "> " /* Interactive prompt. */ +#define LUA_PROMPT2 ">> " /* Continuation prompt. */ +#define LUA_MAXINPUT 512 /* Max. input line length. */ +#endif + +/* Note: changing the following defines breaks the Lua 5.1 ABI. */ +#define LUA_INTEGER ptrdiff_t +#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */ +/* +** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using +** unreasonable amounts of stack space, but still retain ABI compatibility. +** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it. +*/ +#define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ) + +/* The following defines are here only for compatibility with luaconf.h +** from the standard Lua distribution. They must not be changed for LuaJIT. +*/ +#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER double +#define LUAI_UACNUMBER double +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +/* Linkage of public API functions. */ +#if defined(LUA_BUILD_AS_DLL) +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif +#else +#define LUA_API extern +#endif + +#define LUALIB_API LUA_API + +/* Support for internal assertions. */ +#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK) +#include +#endif +#ifdef LUA_USE_ASSERT +#define lua_assert(x) assert(x) +#endif +#ifdef LUA_USE_APICHECK +#define luai_apicheck(L, o) { (void)L; assert(o); } +#else +#define luai_apicheck(L, o) { (void)L; } +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.c new file mode 100644 index 0000000..4cccf04 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.c @@ -0,0 +1,571 @@ +/* +** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define luajit_c + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "luajit.h" + +#include "lj_arch.h" + +#if LJ_TARGET_POSIX +#include +#define lua_stdin_is_tty() isatty(0) +#elif LJ_TARGET_WINDOWS +#include +#ifdef __BORLANDC__ +#define lua_stdin_is_tty() isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#endif +#else +#define lua_stdin_is_tty() 1 +#endif + +#if !LJ_TARGET_CONSOLE +#include +#endif + +static lua_State *globalL = NULL; +static const char *progname = LUA_PROGNAME; + +#if !LJ_TARGET_CONSOLE +static void lstop(lua_State *L, lua_Debug *ar) +{ + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + /* Avoid luaL_error -- a C hook doesn't add an extra frame. */ + luaL_where(L, 0); + lua_pushfstring(L, "%sinterrupted!", lua_tostring(L, -1)); + lua_error(L); +} + +static void laction(int i) +{ + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} +#endif + +static void print_usage(void) +{ + fprintf(stderr, + "usage: %s [options]... [script [args]...].\n" + "Available options are:\n" + " -e chunk Execute string " LUA_QL("chunk") ".\n" + " -l name Require library " LUA_QL("name") ".\n" + " -b ... Save or list bytecode.\n" + " -j cmd Perform LuaJIT control command.\n" + " -O[opt] Control LuaJIT optimizations.\n" + " -i Enter interactive mode after executing " LUA_QL("script") ".\n" + " -v Show version information.\n" + " -E Ignore environment variables.\n" + " -- Stop handling options.\n" + " - Execute stdin and stop handling options.\n" + , + progname); + fflush(stderr); +} + +static void l_message(const char *pname, const char *msg) +{ + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + +static int report(lua_State *L, int status) +{ + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + +static int traceback(lua_State *L) +{ + if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */ + if (lua_isnoneornil(L, 1) || + !luaL_callmeta(L, 1, "__tostring") || + !lua_isstring(L, -1)) + return 1; /* Return non-string error object. */ + lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */ + } + luaL_traceback(L, L, lua_tostring(L, 1), 1); + return 1; +} + +static int docall(lua_State *L, int narg, int clear) +{ + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ +#if !LJ_TARGET_CONSOLE + signal(SIGINT, laction); +#endif + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); +#if !LJ_TARGET_CONSOLE + signal(SIGINT, SIG_DFL); +#endif + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + +static void print_version(void) +{ + fputs(LUAJIT_VERSION " -- " LUAJIT_COPYRIGHT ". " LUAJIT_URL "\n", stdout); +} + +static void print_jit_status(lua_State *L) +{ + int n; + const char *s; + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit"); /* Get jit.* module table. */ + lua_remove(L, -2); + lua_getfield(L, -1, "status"); + lua_remove(L, -2); + n = lua_gettop(L); + lua_call(L, 0, LUA_MULTRET); + fputs(lua_toboolean(L, n) ? "JIT: ON" : "JIT: OFF", stdout); + for (n++; (s = lua_tostring(L, n)); n++) { + putc(' ', stdout); + fputs(s, stdout); + } + putc('\n', stdout); +} + +static int getargs(lua_State *L, char **argv, int n) +{ + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i = n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i = 0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + +static int dofile(lua_State *L, const char *name) +{ + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + +static int dostring(lua_State *L, const char *s, const char *name) +{ + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + +static int dolibrary(lua_State *L, const char *name) +{ + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + +static void write_prompt(lua_State *L, int firstline) +{ + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2; + fputs(p, stdout); + fflush(stdout); + lua_pop(L, 1); /* remove global */ +} + +static int incomplete(lua_State *L, int status) +{ + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + +static int pushline(lua_State *L, int firstline) +{ + char buf[LUA_MAXINPUT]; + write_prompt(L, firstline); + if (fgets(buf, LUA_MAXINPUT, stdin)) { + size_t len = strlen(buf); + if (len > 0 && buf[len-1] == '\n') + buf[len-1] = '\0'; + if (firstline && buf[0] == '=') + lua_pushfstring(L, "return %s", buf+1); + else + lua_pushstring(L, buf); + return 1; + } + return 0; +} + +static int loadline(lua_State *L) +{ + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_remove(L, 1); /* remove line */ + return status; +} + +static void dotty(lua_State *L) +{ + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, + lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + +static int handle_script(lua_State *L, char **argv, int n) +{ + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + +/* Load add-on module. */ +static int loadjitmodule(lua_State *L) +{ + lua_getglobal(L, "require"); + lua_pushliteral(L, "jit."); + lua_pushvalue(L, -3); + lua_concat(L, 2); + if (lua_pcall(L, 1, 1, 0)) { + const char *msg = lua_tostring(L, -1); + if (msg && !strncmp(msg, "module ", 7)) { + err: + l_message(progname, + "unknown luaJIT command or jit.* modules not installed"); + return 1; + } else { + return report(L, 1); + } + } + lua_getfield(L, -1, "start"); + if (lua_isnil(L, -1)) goto err; + lua_remove(L, -2); /* Drop module table. */ + return 0; +} + +/* Run command with options. */ +static int runcmdopt(lua_State *L, const char *opt) +{ + int narg = 0; + if (opt && *opt) { + for (;;) { /* Split arguments. */ + const char *p = strchr(opt, ','); + narg++; + if (!p) break; + if (p == opt) + lua_pushnil(L); + else + lua_pushlstring(L, opt, (size_t)(p - opt)); + opt = p + 1; + } + if (*opt) + lua_pushstring(L, opt); + else + lua_pushnil(L); + } + return report(L, lua_pcall(L, narg, 0, 0)); +} + +/* JIT engine control command: try jit library first or load add-on module. */ +static int dojitcmd(lua_State *L, const char *cmd) +{ + const char *opt = strchr(cmd, '='); + lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd)); + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit"); /* Get jit.* module table. */ + lua_remove(L, -2); + lua_pushvalue(L, -2); + lua_gettable(L, -2); /* Lookup library function. */ + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); /* Drop non-function and jit.* table, keep module name. */ + if (loadjitmodule(L)) + return 1; + } else { + lua_remove(L, -2); /* Drop jit.* table. */ + } + lua_remove(L, -2); /* Drop module name. */ + return runcmdopt(L, opt ? opt+1 : opt); +} + +/* Optimization flags. */ +static int dojitopt(lua_State *L, const char *opt) +{ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit.opt"); /* Get jit.opt.* module table. */ + lua_remove(L, -2); + lua_getfield(L, -1, "start"); + lua_remove(L, -2); + return runcmdopt(L, opt); +} + +/* Save or list bytecode. */ +static int dobytecode(lua_State *L, char **argv) +{ + int narg = 0; + lua_pushliteral(L, "bcsave"); + if (loadjitmodule(L)) + return 1; + if (argv[0][2]) { + narg++; + argv[0][1] = '-'; + lua_pushstring(L, argv[0]+1); + } + for (argv++; *argv != NULL; narg++, argv++) + lua_pushstring(L, *argv); + return report(L, lua_pcall(L, narg, 0, 0)); +} + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + +#define FLAGS_INTERACTIVE 1 +#define FLAGS_VERSION 2 +#define FLAGS_EXEC 4 +#define FLAGS_OPTION 8 +#define FLAGS_NOENV 16 + +static int collectargs(char **argv, int *flags) +{ + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* Not an option? */ + return i; + switch (argv[i][1]) { /* Check option. */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *flags |= FLAGS_INTERACTIVE; + /* fallthrough */ + case 'v': + notail(argv[i]); + *flags |= FLAGS_VERSION; + break; + case 'e': + *flags |= FLAGS_EXEC; + case 'j': /* LuaJIT extension */ + case 'l': + *flags |= FLAGS_OPTION; + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + case 'O': break; /* LuaJIT extension */ + case 'b': /* LuaJIT extension */ + if (*flags) return -1; + *flags |= FLAGS_EXEC; + return 0; + case 'E': + *flags |= FLAGS_NOENV; + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + +static int runargs(lua_State *L, char **argv, int n) +{ + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + case 'j': { /* LuaJIT extension */ + const char *cmd = argv[i] + 2; + if (*cmd == '\0') cmd = argv[++i]; + lua_assert(cmd != NULL); + if (dojitcmd(L, cmd)) + return 1; + break; + } + case 'O': /* LuaJIT extension */ + if (dojitopt(L, argv[i] + 2)) + return 1; + break; + case 'b': /* LuaJIT extension */ + return dobytecode(L, argv+i); + default: break; + } + } + return 0; +} + +static int handle_luainit(lua_State *L) +{ +#if LJ_TARGET_CONSOLE + const char *init = NULL; +#else + const char *init = getenv(LUA_INIT); +#endif + if (init == NULL) + return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + +static struct Smain { + char **argv; + int argc; + int status; +} smain; + +static int pmain(lua_State *L) +{ + struct Smain *s = &smain; + char **argv = s->argv; + int script; + int flags = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + LUAJIT_VERSION_SYM(); /* linker-enforced version check */ + script = collectargs(argv, &flags); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if ((flags & FLAGS_NOENV)) { + lua_pushboolean(L, 1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); + } + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, -1); + if (!(flags & FLAGS_NOENV)) { + s->status = handle_luainit(L); + if (s->status != 0) return 0; + } + if ((flags & FLAGS_VERSION)) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) { + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + } + if ((flags & FLAGS_INTERACTIVE)) { + print_jit_status(L); + dotty(L); + } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) { + if (lua_stdin_is_tty()) { + print_version(); + print_jit_status(L); + dotty(L); + } else { + dofile(L, NULL); /* executes stdin as a file */ + } + } + return 0; +} + +int main(int argc, char **argv) +{ + int status; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + smain.argc = argc; + smain.argv = argv; + status = lua_cpcall(L, pmain, NULL); + report(L, status); + lua_close(L); + return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.exe b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.exe new file mode 100644 index 0000000..9b721da Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.exe differ diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.h new file mode 100644 index 0000000..be721cf --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/luajit.h @@ -0,0 +1,70 @@ +/* +** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ +** +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] +*/ + +#ifndef _LUAJIT_H +#define _LUAJIT_H + +#include "lua.h" + +#define LUAJIT_VERSION "LuaJIT 2.0.3" +#define LUAJIT_VERSION_NUM 20003 /* Version 2.0.3 = 02.00.03. */ +#define LUAJIT_VERSION_SYM luaJIT_version_2_0_3 +#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2014 Mike Pall" +#define LUAJIT_URL "http://luajit.org/" + +/* Modes for luaJIT_setmode. */ +#define LUAJIT_MODE_MASK 0x00ff + +enum { + LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ + LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ + + LUAJIT_MODE_FUNC, /* Change mode for a function. */ + LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ + LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ + + LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ + + LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ + + LUAJIT_MODE_MAX +}; + +/* Flags or'ed in to the mode. */ +#define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ +#define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ +#define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ + +/* LuaJIT public C API. */ + +/* Control the JIT engine. */ +LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); + +/* Enforce (dynamic) linker error for version mismatches. Call from main. */ +LUA_API void LUAJIT_VERSION_SYM(void); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lualib.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lualib.h new file mode 100644 index 0000000..1c1e317 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lualib.h @@ -0,0 +1,43 @@ +/* +** Standard library header. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LUALIB_H +#define _LUALIB_H + +#include "lua.h" + +#define LUA_FILEHANDLE "FILE*" + +#define LUA_COLIBNAME "coroutine" +#define LUA_MATHLIBNAME "math" +#define LUA_STRLIBNAME "string" +#define LUA_TABLIBNAME "table" +#define LUA_IOLIBNAME "io" +#define LUA_OSLIBNAME "os" +#define LUA_LOADLIBNAME "package" +#define LUA_DBLIBNAME "debug" +#define LUA_BITLIBNAME "bit" +#define LUA_JITLIBNAME "jit" +#define LUA_FFILIBNAME "ffi" + +LUALIB_API int luaopen_base(lua_State *L); +LUALIB_API int luaopen_math(lua_State *L); +LUALIB_API int luaopen_string(lua_State *L); +LUALIB_API int luaopen_table(lua_State *L); +LUALIB_API int luaopen_io(lua_State *L); +LUALIB_API int luaopen_os(lua_State *L); +LUALIB_API int luaopen_package(lua_State *L); +LUALIB_API int luaopen_debug(lua_State *L); +LUALIB_API int luaopen_bit(lua_State *L); +LUALIB_API int luaopen_jit(lua_State *L); +LUALIB_API int luaopen_ffi(lua_State *L); + +LUALIB_API void luaL_openlibs(lua_State *L); + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.c new file mode 100644 index 0000000..7fc635e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.c @@ -0,0 +1,223 @@ +/* +** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + IF (1, "bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + return f; +} + +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.h new file mode 100644 index 0000000..58cca5d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lundump.h @@ -0,0 +1,36 @@ +/* +** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.c new file mode 100644 index 0000000..6f4c029 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.c @@ -0,0 +1,762 @@ +/* +** $Id: lvm.c,v 2.62 2006/01/23 19:51:43 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if (mask > LUA_MASKLINE) { /* instruction-hook set? */ + if (L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + if (!ttisnil(oldval) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (!ttisfunction(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!tostring(L, top-2) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, const TValue *rb, + const TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.h new file mode 100644 index 0000000..788423f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.c new file mode 100644 index 0000000..5121ada --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.c @@ -0,0 +1,82 @@ +/* +** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.h b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.h new file mode 100644 index 0000000..8f403b8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/msvcbuild.bat b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/msvcbuild.bat new file mode 100644 index 0000000..9160e0f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/msvcbuild.bat @@ -0,0 +1,113 @@ +@rem Script to build LuaJIT with MSVC. +@rem Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +@rem +@rem Either open a "Visual Studio .NET Command Prompt" +@rem (Note that the Express Edition does not contain an x64 compiler) +@rem -or- +@rem Open a "Windows SDK Command Shell" and set the compiler environment: +@rem setenv /release /x86 +@rem -or- +@rem setenv /release /x64 +@rem +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL + +@setlocal +@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set LJLIB=lib /nologo /nodefaultlib +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set LJDLLNAME=lua51.dll +@set LJLIBNAME=lua51.lib +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64 +@set LJARCH=x64 +@minilua +@if errorlevel 8 goto :X64 +@set DASMFLAGS=-D WIN -D JIT -D FFI +@set LJARCH=x86 +:X64 +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m peobj -o lj_vm.obj +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% /Zi +@set LJLINK=%LJLINK% /debug +:NODEBUG +@if "%1"=="amalg" goto :AMALGDLL +@if "%1"=="static" goto :STATIC +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :MTDLL +:STATIC +%LJCOMPILE% lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :MTDLL +:AMALGDLL +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c +@if errorlevel 1 goto :BAD +%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj +@if errorlevel 1 goto :BAD +:MTDLL +if exist %LJDLLNAME%.manifest^ + %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2 + +%LJCOMPILE% luajit.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME% +@if errorlevel 1 goto :BAD +if exist luajit.exe.manifest^ + %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe + +@del *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for Windows/%LJARCH% === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo You must open a "Visual Studio .NET Command Prompt" to run this script +:END diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/print.c b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/print.c new file mode 100644 index 0000000..1c3a445 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/print.c @@ -0,0 +1,224 @@ +/* +** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lundump.h" + +#define PrintFunction luaU_print + +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) + +static void PrintString(const Proto* f, int n) +{ + const char* s=svalue(&f->k[n]); + putchar('"'); + for (; *s; s++) + { + switch (*s) + { + case '"': printf("\\\""); break; + case '\a': printf("\\a"); break; + case '\b': printf("\\b"); break; + case '\f': printf("\\f"); break; + case '\n': printf("\\n"); break; + case '\r': printf("\\r"); break; + case '\t': printf("\\t"); break; + case '\v': printf("\\v"); break; + default: if (isprint((unsigned char)*s)) + printf("%c",*s); + else + printf("\\%03u",(unsigned char)*s); + } + } + putchar('"'); +} + +static void PrintConstant(const Proto* f, int i) +{ + const TValue* o=&f->k[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf(LUA_NUMBER_FMT,nvalue(o)); + break; + case LUA_TSTRING: + PrintString(f,i); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); + break; + case iABx: + if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); + break; + case iAsBx: + if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); + break; + case OP_GETGLOBAL: + case OP_SETGLOBAL: + printf("\t; %s",svalue(&f->k[bx])); + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_DIV: + case OP_POW: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); + else printf("\t; %d",c); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=getstr(f->source); + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintConstants(const Proto* f) +{ + int i,n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } +} + +static void PrintUpvalues(const Proto* f) +{ + int i,n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + if (f->upvalues==NULL) return; + for (i=0; iupvalues[i])); + } +} + +void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) + { + PrintConstants(f); + PrintLocals(f); + PrintUpvalues(f); + } + for (i=0; ip[i],full); +} diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ps4build.bat b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ps4build.bat new file mode 100644 index 0000000..42fc9a6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/ps4build.bat @@ -0,0 +1,103 @@ +@rem Script to build LuaJIT with the PS4 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler) +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL +@if not defined SCE_ORBIS_SDK_DIR goto :FAIL + +@setlocal +@rem ---- Host compiler ---- +@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@rem Check for 64 bit host compiler. +@minilua +@if not errorlevel 8 goto :FAIL + +@set DASMFLAGS=-D P64 +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m elfasm -o lj_vm.s +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@rem ---- Cross compiler ---- +@set LJCOMPILE="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-clang" -c -Wall -DLUAJIT_DISABLE_FFI +@set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus +@set INCLUDE="" + +orbis-as -o lj_vm.o lj_vm.s + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% -g -O0 +@set TARGETLIB=libluajitD.a +goto :BUILD +:NODEBUG +@set LJCOMPILE=%LJCOMPILE% -O2 +@set TARGETLIB=libluajit.a +:BUILD +del %TARGETLIB% +@if "%1"=="amalg" goto :AMALG +for %%f in (lj_*.c lib_*.c) do ( + %LJCOMPILE% %%f + @if errorlevel 1 goto :BAD +) + +%LJLIB% %TARGETLIB% lj_*.o lib_*.o +@if errorlevel 1 goto :BAD +@goto :NOAMALG +:AMALG +%LJCOMPILE% ljamalg.c +@if errorlevel 1 goto :BAD +%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o +@if errorlevel 1 goto :BAD +:NOAMALG + +@del *.o *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for PS4 === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo To run this script you must open a "Visual Studio .NET Command Prompt" +@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too. +:END diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_arm.dasc b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_arm.dasc new file mode 100644 index 0000000..82cba90 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_arm.dasc @@ -0,0 +1,4487 @@ +|// Low-level VM code for ARM CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch arm +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +| +|// The following must be C callee-save. +|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding. +|.define KBASE, r5 // Constants of current Lua function. +|.define PC, r6 // Next PC. +|.define DISPATCH, r7 // Opcode dispatch table. +|.define LREG, r8 // Register holding lua_State (also in SAVE_L). +| +|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+. +|.define BASE, r9 // Base of current Lua stack frame. +| +|// The following temporaries are not saved across C calls, except for RA/RC. +|.define RA, r10 // Callee-save. +|.define RC, r11 // Callee-save. +|.define RB, r12 +|.define OP, r12 // Overlaps RB, must not be lr. +|.define INS, lr +| +|// Calling conventions. Also used as temporaries. +|.define CARG1, r0 +|.define CARG2, r1 +|.define CARG3, r2 +|.define CARG4, r3 +|.define CARG12, r0 // For 1st soft-fp double. +|.define CARG34, r2 // For 2nd soft-fp double. +| +|.define CRET1, r0 +|.define CRET2, r1 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define SAVE_R4, [sp, #28] +|.define CFRAME_SPACE, #28 +|.define SAVE_ERRF, [sp, #24] +|.define SAVE_NRES, [sp, #20] +|.define SAVE_CFRAME, [sp, #16] +|.define SAVE_L, [sp, #12] +|.define SAVE_PC, [sp, #8] +|.define SAVE_MULTRES, [sp, #4] +|.define ARG5, [sp] +| +|.define TMPDhi, [sp, #4] +|.define TMPDlo, [sp] +|.define TMPD, [sp] +|.define TMPDp, sp +| +|.if FPU +|.macro saveregs +| push {r5, r6, r7, r8, r9, r10, r11, lr} +| vpush {d8-d15} +| sub sp, sp, CFRAME_SPACE+4 +| str r4, SAVE_R4 +|.endmacro +|.macro restoreregs_ret +| ldr r4, SAVE_R4 +| add sp, sp, CFRAME_SPACE+4 +| vpop {d8-d15} +| pop {r5, r6, r7, r8, r9, r10, r11, pc} +|.endmacro +|.else +|.macro saveregs +| push {r4, r5, r6, r7, r8, r9, r10, r11, lr} +| sub sp, sp, CFRAME_SPACE +|.endmacro +|.macro restoreregs_ret +| add sp, sp, CFRAME_SPACE +| pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} +|.endmacro +|.endif +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// Trap for not-yet-implemented parts. +|.macro NYI; ud; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_FUNC, #-8 +|.define FRAME_PC, #-4 +| +|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro +|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro +|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro +|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro +|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| ldrb OP, [PC] +|.endmacro +|.macro ins_NEXT2 +| ldr INS, [PC], #4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT3 +| ldr OP, [DISPATCH, OP, lsl #2] +| decode_RA8 RA, INS +| decode_RD RC, INS +| bx OP +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +| ins_NEXT3 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +| .define ins_next3, ins_NEXT3 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| .endmacro +| .macro ins_next3 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Avoid register name substitution for field name. +#define field_pc pc +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| ldr PC, LFUNC:CARG3->field_pc +| ldrb OP, [PC] // STALL: load PC. early PC. +| ldr INS, [PC], #4 +| ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP. +| decode_RA8 RA, INS +| add RA, RA, BASE +| bx OP +|.endmacro +| +|.macro ins_call +| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| str PC, [BASE, FRAME_PC] +| ins_callt // STALL: locked PC. +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro +|.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro +|.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro +|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro +|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro +|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotcheck, delta +| lsr CARG1, PC, #1 +| and CARG1, CARG1, #126 +| sub CARG1, CARG1, #-GG_DISP2HOT +| ldrh CARG2, [DISPATCH, CARG1] +| subs CARG2, CARG2, #delta +| strh CARG2, [DISPATCH, CARG1] +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP +| blo ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL +| blo ->vm_hotcall +|.endmacro +| +|// Set current VM state. +|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro +|.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)] +| bic mark, mark, #LJ_GC_BLACK // black2gray(tab) +| str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)] +| strb mark, tab->marked +| str tmp, tab->gclist +|.endmacro +| +|.macro .IOS, a, b +|.if IOS +| a, b +|.endif +|.endmacro +| +|//----------------------------------------------------------------------- + +#if !LJ_DUALNUM +#error "Only dual-number mode supported for ARM target" +#endif + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: RB = previous base. + | tst PC, #FRAME_P + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame. + | mvn CARG2, #~LJ_TTRUE + | mov BASE, RB + | // Prepending may overwrite the pcall frame, so do it at the end. + | str CARG2, [RA, FRAME_PC] // Prepend true to results. + | sub RA, RA, #8 + | + |->vm_returnc: + | adds RC, RC, #8 // RC = (nresults+1)*8. + | mov CRET1, #LUA_YIELD + | beq ->vm_unwind_c_eh + | str RC, SAVE_MULTRES + | ands CARG1, PC, #FRAME_TYPE + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return + | // CARG1 = PC & FRAME_TYPE + | bic RB, PC, #FRAME_TYPEP + | cmp CARG1, #FRAME_C + | sub RB, BASE, RB // RB = previous base. + | bne ->vm_returnp + | + | str RB, L->base + | ldr KBASE, SAVE_NRES + | mv_vmstate CARG4, C + | sub BASE, BASE, #8 + | subs CARG3, RC, #8 + | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8 + | st_vmstate CARG4 + | beq >2 + |1: + | subs CARG3, CARG3, #8 + | ldrd CARG12, [RA], #8 + | strd CARG12, [BASE], #8 + | bne <1 + |2: + | cmp KBASE, RC // More/less results wanted? + | bne >6 + |3: + | str BASE, L->top // Store new top. + | + |->vm_leave_cp: + | ldr RC, SAVE_CFRAME // Restore previous C frame. + | mov CRET1, #0 // Ok return status for vm_pcall. + | str RC, L->cframe + | + |->vm_leave_unw: + | restoreregs_ret + | + |6: + | blt >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | ldr CARG3, L->maxstack + | mvn CARG2, #~LJ_TNIL + | cmp BASE, CARG3 + | bhs >8 + | str CARG2, [BASE, #4] + | add RC, RC, #8 + | add BASE, BASE, #8 + | b <2 + | + |7: // Less results wanted. + | sub CARG1, RC, KBASE + | cmp KBASE, #0 // LUA_MULTRET+1 case? + | subne BASE, BASE, CARG1 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | str BASE, L->top // Save current top held in BASE (yes). + | mov CARG2, KBASE + | mov CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mov sp, CARG1 + | mov CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | ldr L, SAVE_L + | mv_vmstate CARG4, C + | ldr GL:CARG3, L->glref + | str CARG4, GL:CARG3->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. + | mov sp, CARG1 + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | ldr L, SAVE_L + | mov MASKR8, #255 + | mov RC, #16 // 2 results: false + error message. + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | ldr BASE, L->base + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | mvn CARG1, #~LJ_TFALSE + | sub RA, BASE, #8 // Results start at BASE-8. + | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame. + | add DISPATCH, DISPATCH, #GG_G2DISP + | mv_vmstate CARG2, INTERP + | str CARG1, [BASE, #-4] // Prepend false to error message. + | st_vmstate CARG2 + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | // CARG1 = L + | mov CARG2, #LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | mov CARG1, L + | str BASE, L->base + | add PC, PC, #4 // Must point after first instruction. + | str RC, L->top + | lsr CARG3, RA, #3 + |2: + | // L->base = new base, L->top = top + | str PC, SAVE_PC + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | ldr RC, L->top + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | sub NARGS8:RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mov L, CARG1 + | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table. + | mov BASE, CARG2 + | add DISPATCH, DISPATCH, #GG_G2DISP + | str L, SAVE_L + | mov PC, #FRAME_CP + | str CARG3, SAVE_NRES + | add CARG2, sp, #CFRAME_RESUME + | ldrb CARG1, L->status + | str CARG3, SAVE_ERRF + | str CARG2, L->cframe + | str CARG3, SAVE_CFRAME + | cmp CARG1, #0 + | str L, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mov RA, BASE + | ldr BASE, L->base + | ldr CARG1, L->top + | mov MASKR8, #255 + | strb CARG3, L->status + | sub RC, CARG1, BASE + | ldr PC, [BASE, FRAME_PC] + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | mv_vmstate CARG2, INTERP + | add RC, RC, #8 + | ands CARG1, PC, #FRAME_TYPE + | st_vmstate CARG2 + | str RC, SAVE_MULTRES + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | mov PC, #FRAME_CP + | str CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | mov PC, #FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | ldr RC, L:CARG1->cframe + | str CARG3, SAVE_NRES + | mov L, CARG1 + | str CARG1, SAVE_L + | mov BASE, CARG2 + | str sp, L->cframe // Add our C frame to cframe chain. + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | str CARG1, SAVE_PC // Any value outside of bytecode is ok. + | str RC, SAVE_CFRAME + | add DISPATCH, DISPATCH, #GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | ldr RB, L->base // RB = old base (for vmeta_call). + | ldr CARG1, L->top + | mov MASKR8, #255 + | add PC, PC, BASE + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | sub PC, PC, RB // PC = frame delta + frame type + | mv_vmstate CARG2, INTERP + | sub NARGS8:RC, CARG1, BASE + | st_vmstate CARG2 + | + |->vm_call_dispatch: + | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC + | ldrd CARG34, [BASE, FRAME_FUNC] + | checkfunc CARG4, ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mov L, CARG1 + | ldr RA, L:CARG1->stack + | str CARG1, SAVE_L + | ldr RB, L->top + | str CARG1, SAVE_PC // Any value outside of bytecode is ok. + | ldr RC, L->cframe + | sub RA, RA, RB // Compute -savestack(L, L->top). + | str sp, L->cframe // Add our C frame to cframe chain. + | mov RB, #0 + | str RA, SAVE_NRES // Neg. delta means cframe w/o frame. + | str RB, SAVE_ERRF // No error function. + | str RC, SAVE_CFRAME + | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud) + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | movs BASE, CRET1 + | mov PC, #FRAME_CP + | add DISPATCH, DISPATCH, #GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8 + | ldr LFUNC:CARG3, [RB, FRAME_FUNC] + | ldr CARG1, [BASE, #-16] // Get continuation. + | mov CARG4, BASE + | mov BASE, RB // Restore caller BASE. + |.if FFI + | cmp CARG1, #1 + |.endif + | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC]. + | ldr CARG3, LFUNC:CARG3->field_pc + | mvn INS, #~LJ_TNIL + | add CARG2, RA, RC + | str INS, [CARG2, #-4] // Ensure one valid arg. + |.if FFI + | bls >1 + |.endif + | ldr KBASE, [CARG3, #PC2PROTO(k)] + | // BASE = base, RA = resultptr, CARG4 = meta base + | bx CARG1 + | + |.if FFI + |1: + | beq ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + | ldr CARG3, [BASE, FRAME_FUNC] + | sub CARG4, CARG4, #16 + | sub RC, CARG4, BASE + | b ->vm_call_tail + |.endif + | + |->cont_cat: // RA = resultptr, CARG4 = meta base + | ldr INS, [PC, #-4] + | sub CARG2, CARG4, #16 + | ldrd CARG34, [RA] + | str BASE, L->base + | decode_RB8 RC, INS + | decode_RA8 RA, INS + | add CARG1, BASE, RC + | subs CARG1, CARG2, CARG1 + | strdne CARG34, [CARG2] + | movne CARG3, CARG1 + | bne ->BC_CAT_Z + | strd CARG34, [BASE, RA] + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | add CARG2, BASE, RB + | b >2 + | + |->vmeta_tgets: + | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) + | mvn CARG4, #~LJ_TTAB + | str TAB:RB, [CARG2] + | str CARG4, [CARG2, #4] + |2: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tgetb: // RC = index + | decode_RB8 RB, INS + | str RC, TMPDlo + | mvn CARG4, #~LJ_TISNUM + | add CARG2, BASE, RB + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tgetv: + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | beq >3 + | ldrd CARG34, [CRET1] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | rsb CARG1, BASE, #FRAME_CONT + | ldr BASE, L->top + | mov NARGS8:RC, #16 // 2 args for func(t, k). + | str PC, [BASE, #-12] // [cont|PC] + | add PC, CARG1, BASE + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | add CARG2, BASE, RB + | b >2 + | + |->vmeta_tsets: + | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) + | mvn CARG4, #~LJ_TTAB + | str TAB:RB, [CARG2] + | str CARG4, [CARG2, #4] + |2: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tsetb: // RC = index + | decode_RB8 RB, INS + | str RC, TMPDlo + | mvn CARG4, #~LJ_TISNUM + | add CARG2, BASE, RB + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tsetv: + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | ldrd CARG34, [BASE, RA] + | beq >3 + | ins_next1 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | strd CARG34, [CRET1] + | ins_next2 + | ins_next3 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | rsb CARG1, BASE, #FRAME_CONT + | ldr BASE, L->top + | mov NARGS8:RC, #24 // 3 args for func(t, k, v). + | strd CARG34, [BASE, #16] // Copy value to third argument. + | str PC, [BASE, #-12] // [cont|PC] + | add PC, CARG1, BASE + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mov CARG1, L + | sub PC, PC, #4 + | mov CARG2, RA + | str BASE, L->base + | mov CARG3, RC + | str PC, SAVE_PC + | decode_OP CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | .IOS ldr BASE, L->base + | cmp CRET1, #1 + | bhi ->vmeta_binop + |4: + | ldrh RB, [PC, #2] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | subhs PC, RB, #0x20000 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | ldr INS, [PC, #-4] + | ldrd CARG12, [RA] + | decode_RA8 CARG3, INS + | strd CARG12, [BASE, CARG3] + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | ldr CARG2, [RA, #4] + | mvn CARG1, #~LJ_TTRUE + | cmp CARG1, CARG2 // Branch if result is true. + | b <4 + | + |->cont_condf: // RA = resultptr + | ldr CARG2, [RA, #4] + | checktp CARG2, LJ_TFALSE // Branch if result is false. + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | sub PC, PC, #4 + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |->vmeta_equal_cd: + |.if FFI + | sub PC, PC, #4 + | str BASE, L->base + | mov CARG1, L + | mov CARG2, INS + | str PC, SAVE_PC + | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vn: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_nv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG4, BASE, RB + | add CARG3, KBASE, RC + | b >1 + | + |->vmeta_unm: + | ldr INS, [PC, #-8] + | sub PC, PC, #4 + | add CARG3, BASE, RC + | add CARG4, BASE, RC + | b >1 + | + |->vmeta_arith_vv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |1: + | decode_OP OP, INS + | add CARG2, BASE, RA + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | str OP, ARG5 + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub CARG2, CRET1, BASE + | str PC, [CRET1, #-12] // [cont|PC] + | add PC, CARG2, #FRAME_CONT + | mov BASE, CRET1 + | mov NARGS8:RC, #16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: + | add CARG2, BASE, RC + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). + | .IOS ldr BASE, L->base +#if LJ_52 + | cmp CRET1, #0 + | bne ->vmeta_binop // Binop call for compatibility. + | ldr TAB:CARG1, [BASE, RC] + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // RB = old base, BASE = new base, RC = nargs*8 + | mov CARG1, L + | str RB, L->base // This is the callers base! + | sub CARG2, BASE, #8 + | str PC, SAVE_PC + | add CARG3, BASE, NARGS8:RC + | .IOS mov RA, BASE + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | .IOS mov BASE, RA + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mov CARG1, L + | str BASE, L->base + | sub CARG2, RA, #8 + | str PC, SAVE_PC + | add CARG3, RA, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | .IOS ldr BASE, L->base + | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here. + | ldr PC, [BASE, FRAME_PC] + | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. + | b ->BC_CALLT2_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mov CARG1, L + | str BASE, L->base + | mov CARG2, RA + | str PC, SAVE_PC + | bl extern lj_meta_for // (lua_State *L, TValue *base) + | .IOS ldr BASE, L->base + |.if JIT + | ldrb OP, [PC, #-4] + |.endif + | ldr INS, [PC, #-4] + |.if JIT + | cmp OP, #BC_JFORI + |.endif + | decode_RA8 RA, INS + | decode_RD RC, INS + |.if JIT + | beq =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | checktp CARG2, LJ_TISNUM + | cmnlo CARG4, #-LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_d, name + | .ffunc name + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 + | vldr d0, [BASE] + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_dd, name + | .ffunc name + | ldr CARG2, [BASE, #4] + | ldr CARG4, [BASE, #12] + | cmp NARGS8:RC, #16 + | vldr d0, [BASE] + | vldr d1, [BASE, #8] + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | cmnlo CARG4, #-LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2. + |.macro ffgccheck + | ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)] + | cmp CARG1, CARG2 + | blge ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | checktp CARG2, LJ_TTRUE + | bhi ->fff_fallback + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + | mov RB, BASE + | subs RA, NARGS8:RC, #8 + | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8. + | beq ->fff_res // Done if exactly 1 argument. + |1: + | ldrd CARG12, [RB, #8] + | subs RA, RA, #8 + | strd CARG12, [RB], #8 + | bne <1 + | b ->fff_res + | + |.ffunc type + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | mvnlo CARG2, #~LJ_TISNUM + | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1 + | lsl CARG4, CARG4, #3 + | ldrd CARG12, [CFUNC:CARG3, CARG4] + | b ->fff_restv + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktp CARG2, LJ_TTAB + | cmnne CARG2, #-LJ_TUDATA + | bne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | ldr TAB:RB, TAB:CARG1->metatable + |2: + | mvn CARG2, #~LJ_TNIL + | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])] + | cmp TAB:RB, #0 + | beq ->fff_restv + | ldr CARG3, TAB:RB->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:RB->node + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + |3: // Rearranged logic, because we expect _not_ to find the key. + | ldrd CARG34, NODE:INS->key // STALL: early NODE:INS. + | ldrd CARG12, NODE:INS->val + | ldr NODE:INS, NODE:INS->next + | checktp CARG4, LJ_TSTR + | cmpeq CARG3, STR:RC + | beq >5 + | cmp NODE:INS, #0 + | bne <3 + |4: + | mov CARG1, RB // Use metatable as default result. + | mvn CARG2, #~LJ_TTAB + | b ->fff_restv + |5: + | checktp CARG2, LJ_TNIL + | bne ->fff_restv + | b <4 + | + |6: + | checktp CARG2, LJ_TISNUM + | mvnhs CARG2, CARG2 + | movlo CARG2, #~LJ_TISNUM + | add CARG4, DISPATCH, CARG2, lsl #2 + | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])] + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | checktp CARG2, LJ_TTAB + | ldreq TAB:RB, TAB:CARG1->metatable + | checktpeq CARG4, LJ_TTAB + | ldrbeq CARG4, TAB:CARG1->marked + | cmpeq TAB:RB, #0 + | bne ->fff_fallback + | tst CARG4, #LJ_GC_BLACK // isblack(table) + | str TAB:CARG3, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, CARG4, CARG3 + | b ->fff_restv + | + |.ffunc rawget + | ldrd CARG34, [BASE] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | mov CARG2, CARG3 + | checktab CARG4, ->fff_fallback + | mov CARG1, L + | add CARG3, BASE, #8 + | .IOS mov RA, BASE + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | .IOS mov BASE, RA + | ldrd CARG12, [CRET1] + | b ->fff_restv + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | bne ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bls ->fff_restv + | b ->fff_fallback + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checktp CARG2, LJ_TSTR + | // A __tostring method in the string base metatable is ignored. + | beq ->fff_restv + | // Handle numbers inline, unless a number base metatable is present. + | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])] + | str BASE, L->base + | checktp CARG2, LJ_TISNUM + | cmpls CARG4, #0 + | str PC, SAVE_PC // Redundant (but a defined value). + | bhi ->fff_fallback + | ffgccheck + | mov CARG1, L + | mov CARG2, BASE + | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) + | // Returns GCstr *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc_1 next + | mvn CARG4, #~LJ_TNIL + | checktab CARG2, ->fff_fallback + | strd CARG34, [BASE, NARGS8:RC] // Set missing 2nd arg to nil. + | ldr PC, [BASE, FRAME_PC] + | mov CARG2, CARG1 + | str BASE, L->base // Add frame since C call can throw. + | mov CARG1, L + | str BASE, L->top // Dummy frame length is ok. + | add CARG3, BASE, #8 + | str PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | mvneq CRET2, #~LJ_TNIL + | beq ->fff_restv // End of traversal: return nil. + | ldrd CARG12, [BASE, #8] // Copy key and value to results. + | ldrd CARG34, [BASE, #16] + | mov RC, #(2+1)*8 + | strd CARG12, [BASE, #-8] + | strd CARG34, [BASE] + | b ->fff_res + | + |.ffunc_1 pairs + | checktab CARG2, ->fff_fallback +#if LJ_52 + | ldr TAB:RB, TAB:CARG1->metatable +#endif + | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0] + | ldr PC, [BASE, FRAME_PC] +#if LJ_52 + | cmp TAB:RB, #0 + | bne ->fff_fallback +#endif + | mvn CARG2, #~LJ_TNIL + | mov RC, #(3+1)*8 + | strd CFUNC:CARG34, [BASE, #-8] + | str CARG2, [BASE, #12] + | b ->fff_res + | + |.ffunc_2 ipairs_aux + | checktp CARG2, LJ_TTAB + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | ldr RB, TAB:CARG1->asize + | ldr RC, TAB:CARG1->array + | add CARG3, CARG3, #1 + | ldr PC, [BASE, FRAME_PC] + | cmp CARG3, RB + | add RC, RC, CARG3, lsl #3 + | strd CARG34, [BASE, #-8] + | ldrdlo CARG12, [RC] + | mov RC, #(0+1)*8 + | bhs >2 // Not in array part? + |1: + | checktp CARG2, LJ_TNIL + | movne RC, #(2+1)*8 + | strdne CARG12, [BASE] + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | ldr RB, TAB:CARG1->hmask + | mov CARG2, CARG3 + | cmp RB, #0 + | beq ->fff_res + | .IOS mov RA, BASE + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | .IOS mov BASE, RA + | cmp CRET1, #0 + | beq ->fff_res + | ldrd CARG12, [CRET1] + | b <1 + | + |.ffunc_1 ipairs + | checktab CARG2, ->fff_fallback +#if LJ_52 + | ldr TAB:RB, TAB:CARG1->metatable +#endif + | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0] + | ldr PC, [BASE, FRAME_PC] +#if LJ_52 + | cmp TAB:RB, #0 + | bne ->fff_fallback +#endif + | mov CARG1, #0 + | mvn CARG2, #~LJ_TISNUM + | mov RC, #(3+1)*8 + | strd CFUNC:CARG34, [BASE, #-8] + | strd CARG12, [BASE, #8] + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. + | mov RB, BASE + | add BASE, BASE, #8 + | moveq PC, #8+FRAME_PCALL + | movne PC, #8+FRAME_PCALLH + | sub NARGS8:RC, NARGS8:RC, #8 + | b ->vm_call_dispatch + | + |.ffunc_2 xpcall + | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)] + | checkfunc CARG4, ->fff_fallback // Traceback must be a function. + | mov RB, BASE + | strd CARG12, [BASE, #8] // Swap function and traceback. + | strd CARG34, [BASE] + | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. + | add BASE, BASE, #16 + | moveq PC, #16+FRAME_PCALL + | movne PC, #16+FRAME_PCALLH + | sub NARGS8:RC, NARGS8:RC, #16 + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | checktp CARG2, LJ_TTHREAD + | bne ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr + |.endif + | ldr PC, [BASE, FRAME_PC] + | str BASE, L->base + | ldr CARG2, L:CARG1->top + | ldrb RA, L:CARG1->status + | ldr RB, L:CARG1->base + | add CARG3, CARG2, NARGS8:RC + | add CARG4, CARG2, RA + | str PC, SAVE_PC + | cmp CARG4, RB + | beq ->fff_fallback + | ldr CARG4, L:CARG1->maxstack + | ldr RB, L:CARG1->cframe + | cmp RA, #LUA_YIELD + | cmpls CARG3, CARG4 + | cmpls RB, #0 + | bhi ->fff_fallback + |1: + |.if resume + | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC. + | add BASE, BASE, #8 + | sub NARGS8:RC, NARGS8:RC, #8 + |.endif + | str CARG3, L:CARG1->top + | str BASE, L->top + |2: // Move args to coroutine. + | ldrd CARG34, [BASE, RB] + | cmp RB, NARGS8:RC + | strdne CARG34, [CARG2, RB] + | add RB, RB, #8 + | bne <2 + | + | mov CARG3, #0 + | mov L:RA, L:CARG1 + | mov CARG4, #0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | ldr CARG3, L:RA->base + | mv_vmstate CARG2, INTERP + | ldr CARG4, L:RA->top + | st_vmstate CARG2 + | cmp CRET1, #LUA_YIELD + | ldr BASE, L->base + | bhi >8 + | subs RC, CARG4, CARG3 + | ldr CARG1, L->maxstack + | add CARG2, BASE, RC + | beq >6 // No results? + | cmp CARG2, CARG1 + | mov RB, #0 + | bhi >9 // Need to grow stack? + | + | sub CARG4, RC, #8 + | str CARG3, L:RA->top // Clear coroutine stack. + |5: // Move results from coroutine. + | ldrd CARG12, [CARG3, RB] + | cmp RB, CARG4 + | strd CARG12, [BASE, RB] + | add RB, RB, #8 + | bne <5 + |6: + |.if resume + | mvn CARG3, #~LJ_TTRUE + | add RC, RC, #16 + |7: + | str CARG3, [BASE, #-4] // Prepend true/false to results. + | sub RA, BASE, #8 + |.else + | mov RA, BASE + | add RC, RC, #8 + |.endif + | ands CARG1, PC, #FRAME_TYPE + | str PC, SAVE_PC + | str RC, SAVE_MULTRES + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | ldrd CARG12, [CARG4, #-8]! + | mvn CARG3, #~LJ_TFALSE + | mov RC, #(2+1)*8 + | str CARG4, L:RA->top // Remove error from coroutine stack. + | strd CARG12, [BASE] // Copy error message. + | b <7 + |.else + | mov CARG1, L + | mov CARG2, L:RA + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + | // Never returns. + |.endif + | + |9: // Handle stack expansion on return from yield. + | mov CARG1, L + | lsr CARG2, RC, #3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | mov CRET1, #0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | ldr CARG1, L->cframe + | add CARG2, BASE, NARGS8:RC + | str BASE, L->base + | tst CARG1, #CFRAME_RESUME + | str CARG2, L->top + | mov CRET1, #LUA_YIELD + | mov CARG3, #0 + | beq ->fff_fallback + | str CARG3, L->cframe + | strb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.macro math_round, func + | .ffunc_1 math_ .. func + | checktp CARG2, LJ_TISNUM + | beq ->fff_restv + | bhi ->fff_fallback + | // Round FP value and normalize result. + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | bpl >2 // |x| < 1? + | mvn CARG4, #0x3e0 + | subs RB, CARG4, RB, asr #21 + | lsl CARG4, CARG2, #11 + | lsl CARG3, CARG1, #11 + | orr CARG4, CARG4, #0x80000000 + | rsb INS, RB, #32 + | orr CARG4, CARG4, CARG1, lsr #21 + | bls >3 // |x| >= 2^31? + | orr CARG3, CARG3, CARG4, lsl INS + | lsr CARG1, CARG4, RB + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 + | addne CARG1, CARG1, #1 + |.else + | bics CARG3, CARG3, CARG2, asr #31 + | addsne CARG1, CARG1, #1 + | ldrdvs CARG12, >9 + | bvs ->fff_restv + |.endif + | cmp CARG2, #0 + | rsblt CARG1, CARG1, #0 + |1: + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |2: // |x| < 1 + | bcs ->fff_restv // |x| is not finite. + | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1 + | moveq CARG1, #0 + | mvnne CARG1, #0 + |.else + | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1 + | moveq CARG1, #0 + | movne CARG1, #1 + |.endif + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |3: // |x| >= 2^31. Check for x == -(2^31). + | cmpeq CARG4, #0x80000000 + |.if "func" == "floor" + | cmpeq CARG3, #0 + |.endif + | bne >4 + | cmp CARG2, #0 + | movmi CARG1, #0x80000000 + | bmi <1 + |4: + | bl ->vm_..func.._sf + | b ->fff_restv + |.endmacro + | + | math_round floor + | math_round ceil + | + |.align 8 + |9: + | .long 0x00000000, 0x41e00000 // 2^31. + | + |.ffunc_1 math_abs + | checktp CARG2, LJ_TISNUM + | bhi ->fff_fallback + | bicne CARG2, CARG2, #0x80000000 + | bne ->fff_restv + | cmp CARG1, #0 + | rsbslt CARG1, CARG1, #0 + | ldrdvs CARG12, <9 + | // Fallthrough. + | + |->fff_restv: + | // CARG12 = TValue result. + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + |->fff_res1: + | // PC = return. + | mov RC, #(1+1)*8 + |->fff_res: + | // RC = (nresults+1)*8, PC = return. + | ands CARG1, PC, #FRAME_TYPE + | ldreq INS, [PC, #-4] + | str RC, SAVE_MULTRES + | sub RA, BASE, #8 + | bne ->vm_return + | decode_RB8 RB, INS + |5: + | cmp RB, RC // More results expected? + | bhi >6 + | decode_RA8 CARG1, INS + | ins_next1 + | ins_next2 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, CARG1 + | ins_next3 + | + |6: // Fill up results with nil. + | add CARG2, RA, RC + | mvn CARG1, #~LJ_TNIL + | add RC, RC, #8 + | str CARG1, [CARG2, #-4] + | b <5 + | + |.macro math_extern, func + |.if HFABI + | .ffunc_d math_ .. func + |.else + | .ffunc_n math_ .. func + |.endif + | .IOS mov RA, BASE + | bl extern func + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + |.endmacro + | + |.macro math_extern2, func + |.if HFABI + | .ffunc_dd math_ .. func + |.else + | .ffunc_nn math_ .. func + |.endif + | .IOS mov RA, BASE + | bl extern func + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + |.endmacro + | + |.if FPU + | .ffunc_d math_sqrt + | vsqrt.f64 d0, d0 + |->fff_resd: + | ldr PC, [BASE, FRAME_PC] + | vstr d0, [BASE, #-8] + | b ->fff_res1 + |.else + | math_extern sqrt + |.endif + | + |.ffunc math_log + |.if HFABI + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | vldr d0, [BASE] + | bne ->fff_fallback + |.else + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | bne ->fff_fallback + |.endif + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + | .IOS mov RA, BASE + | bl extern log + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.if FPU + | .ffunc_d math_rad + | vldr d1, CFUNC:CARG3->upvalue[0] + | vmul.f64 d0, d0, d1 + | b ->fff_resd + |.else + | .ffunc_n math_rad + | ldrd CARG34, CFUNC:CARG3->upvalue[0] + | bl extern __aeabi_dmul + | b ->fff_restv + |.endif + | + |.if HFABI + | .ffunc math_ldexp + | ldr CARG4, [BASE, #4] + | ldrd CARG12, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | vldr d0, [BASE] + | checktp CARG4, LJ_TISNUM + | bhs ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bne ->fff_fallback + | .IOS mov RA, BASE + | bl extern ldexp // (double x, int exp) + | .IOS mov BASE, RA + | b ->fff_resd + |.else + |.ffunc_2 math_ldexp + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + | checktp CARG4, LJ_TISNUM + | bne ->fff_fallback + | .IOS mov RA, BASE + | bl extern ldexp // (double x, int exp) + | .IOS mov BASE, RA + | b ->fff_restv + |.endif + | + |.if HFABI + |.ffunc_d math_frexp + | mov CARG1, sp + | .IOS mov RA, BASE + | bl extern frexp + | .IOS mov BASE, RA + | ldr CARG3, [sp] + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | vstr d0, [BASE, #-8] + | mov RC, #(2+1)*8 + | strd CARG34, [BASE] + | b ->fff_res + |.else + |.ffunc_n math_frexp + | mov CARG3, sp + | .IOS mov RA, BASE + | bl extern frexp + | .IOS mov BASE, RA + | ldr CARG3, [sp] + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + | mov RC, #(2+1)*8 + | strd CARG34, [BASE] + | b ->fff_res + |.endif + | + |.if HFABI + |.ffunc_d math_modf + | sub CARG1, BASE, #8 + | ldr PC, [BASE, FRAME_PC] + | .IOS mov RA, BASE + | bl extern modf + | .IOS mov BASE, RA + | mov RC, #(2+1)*8 + | vstr d0, [BASE] + | b ->fff_res + |.else + |.ffunc_n math_modf + | sub CARG3, BASE, #8 + | ldr PC, [BASE, FRAME_PC] + | .IOS mov RA, BASE + | bl extern modf + | .IOS mov BASE, RA + | mov RC, #(2+1)*8 + | strd CARG12, [BASE] + | b ->fff_res + |.endif + | + |.macro math_minmax, name, cond, fcond + |.if FPU + | .ffunc_1 name + | add RB, BASE, RC + | checktp CARG2, LJ_TISNUM + | add RA, BASE, #8 + | bne >4 + |1: // Handle integers. + | ldrd CARG34, [RA] + | cmp RA, RB + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bne >3 + | cmp CARG1, CARG3 + | add RA, RA, #8 + | mov..cond CARG1, CARG3 + | b <1 + |3: // Convert intermediate result to number and continue below. + | vmov s4, CARG1 + | bhi ->fff_fallback + | vldr d1, [RA] + | vcvt.f64.s32 d0, s4 + | b >6 + | + |4: + | vldr d0, [BASE] + | bhi ->fff_fallback + |5: // Handle numbers. + | ldrd CARG34, [RA] + | vldr d1, [RA] + | cmp RA, RB + | bhs ->fff_resd + | checktp CARG4, LJ_TISNUM + | bhs >7 + |6: + | vcmp.f64 d0, d1 + | vmrs + | add RA, RA, #8 + | vmov..fcond.f64 d0, d1 + | b <5 + |7: // Convert integer to number and continue above. + | vmov s4, CARG3 + | bhi ->fff_fallback + | vcvt.f64.s32 d1, s4 + | b <6 + | + |.else + | + | .ffunc_1 name + | checktp CARG2, LJ_TISNUM + | mov RA, #8 + | bne >4 + |1: // Handle integers. + | ldrd CARG34, [BASE, RA] + | cmp RA, RC + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bne >3 + | cmp CARG1, CARG3 + | add RA, RA, #8 + | mov..cond CARG1, CARG3 + | b <1 + |3: // Convert intermediate result to number and continue below. + | bhi ->fff_fallback + | bl extern __aeabi_i2d + | ldrd CARG34, [BASE, RA] + | b >6 + | + |4: + | bhi ->fff_fallback + |5: // Handle numbers. + | ldrd CARG34, [BASE, RA] + | cmp RA, RC + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bhs >7 + |6: + | bl extern __aeabi_cdcmple + | add RA, RA, #8 + | mov..fcond CARG1, CARG3 + | mov..fcond CARG2, CARG4 + | b <5 + |7: // Convert integer to number and continue above. + | bhi ->fff_fallback + | strd CARG12, TMPD + | mov CARG1, CARG3 + | bl extern __aeabi_i2d + | ldrd CARG34, TMPD + | b <6 + |.endif + |.endmacro + | + | math_minmax math_min, gt, hi + | math_minmax math_max, lt, lo + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr CARG2, ->fff_fallback + | ldr CARG1, STR:CARG1->len + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.ffunc string_byte // Only handle the 1-arg case here. + | ldrd CARG12, [BASE] + | ldr PC, [BASE, FRAME_PC] + | cmp NARGS8:RC, #8 + | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument. + | bne ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end). + | mvn CARG2, #~LJ_TISNUM + | cmp CARG3, #0 + | moveq RC, #(0+1)*8 + | movne RC, #(1+1)*8 + | strd CARG12, [BASE, #-8] + | b ->fff_res + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | ldrd CARG12, [BASE] + | ldr PC, [BASE, FRAME_PC] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | checktpeq CARG2, LJ_TISNUM + | bicseq CARG4, CARG1, #255 + | mov CARG3, #1 + | bne ->fff_fallback + | str CARG1, TMPD + | mov CARG2, TMPDp // Points to stack. Little-endian. + |->fff_newstr: + | // CARG2 = str, CARG3 = len. + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #16] + | cmp NARGS8:RC, #16 + | mvn RB, #0 + | beq >1 + | blo ->fff_fallback + | checktp CARG4, LJ_TISNUM + | mov RB, CARG3 + | bne ->fff_fallback + |1: + | ldrd CARG34, [BASE, #8] + | checktp CARG2, LJ_TSTR + | ldreq CARG2, STR:CARG1->len + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end + | add CARG4, CARG2, #1 + | cmp CARG3, #0 // if (start < 0) start += len+1 + | addlt CARG3, CARG3, CARG4 + | cmp CARG3, #1 // if (start < 1) start = 1 + | movlt CARG3, #1 + | cmp RB, #0 // if (end < 0) end += len+1 + | addlt RB, RB, CARG4 + | bic RB, RB, RB, asr #31 // if (end < 0) end = 0 + | cmp RB, CARG2 // if (end > len) end = len + | add CARG1, STR:CARG1, #sizeof(GCstr)-1 + | movgt RB, CARG2 + | add CARG2, CARG1, CARG3 + | subs CARG3, RB, CARG3 // len = end - start + | add CARG3, CARG3, #1 // len += 1 + | bge ->fff_newstr + |->fff_emptystr: + | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty) + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #8] + | cmp NARGS8:RC, #16 + | bne ->fff_fallback // Exactly 2 arguments + | checktp CARG2, LJ_TSTR + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | subs CARG4, CARG3, #1 + | ldr CARG2, STR:CARG1->len + | blt ->fff_emptystr // Count <= 0? + | cmp CARG2, #1 + | blo ->fff_emptystr // Zero-length string? + | bne ->fff_fallback // Fallback for > 1-char strings. + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | ldr CARG1, STR:CARG1[1] + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // Fill buffer with char. + | strb CARG1, [CARG2, CARG4] + | subs CARG4, CARG4, #1 + | bge <1 + | b ->fff_newstr + | + |.ffunc string_reverse + | ffgccheck + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checkstr CARG2, ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | mov CARG4, CARG3 + | add CARG1, STR:CARG1, #sizeof(GCstr) + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // Reverse string copy. + | ldrb RB, [CARG1], #1 + | subs CARG4, CARG4, #1 + | blt ->fff_newstr + | strb RB, [CARG2, CARG4] + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checkstr CARG2, ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | mov CARG4, #0 + | add CARG1, STR:CARG1, #sizeof(GCstr) + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // ASCII case conversion. + | ldrb RB, [CARG1, CARG4] + | cmp CARG4, CARG3 + | bhs ->fff_newstr + | sub RC, RB, #lo + | cmp RC, #26 + | eorlo RB, RB, #0x20 + | strb RB, [CARG2, CARG4] + | add CARG4, CARG4, #1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG2, ->fff_fallback + | .IOS mov RA, BASE + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | .IOS mov BASE, RA + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |//-- Bit library -------------------------------------------------------- + | + |// FP number to bit conversion for soft-float. Clobbers r0-r3. + |->vm_tobit_fb: + | bhi ->fff_fallback + |->vm_tobit: + | lsl RB, CARG2, #1 + | adds RB, RB, #0x00200000 + | movpl CARG1, #0 // |x| < 1? + | bxpl lr + | mvn CARG4, #0x3e0 + | subs RB, CARG4, RB, asr #21 + | bmi >1 // |x| >= 2^32? + | lsl CARG4, CARG2, #11 + | orr CARG4, CARG4, #0x80000000 + | orr CARG4, CARG4, CARG1, lsr #21 + | cmp CARG2, #0 + | lsr CARG1, CARG4, RB + | rsblt CARG1, CARG1, #0 + | bx lr + |1: + | add RB, RB, #21 + | lsr CARG4, CARG1, RB + | rsb RB, RB, #20 + | lsl CARG1, CARG2, #12 + | cmp CARG2, #0 + | orr CARG1, CARG4, CARG1, lsl RB + | rsblt CARG1, CARG1, #0 + | bx lr + | + |.macro .ffunc_bit, name + | .ffunc_1 bit_..name + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + |.endmacro + | + |.ffunc_bit tobit + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | mov CARG3, CARG1 + | mov RA, #8 + |1: + | ldrd CARG12, [BASE, RA] + | cmp RA, NARGS8:RC + | add RA, RA, #8 + | bge >2 + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + | ins CARG3, CARG3, CARG1 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, orr + |.ffunc_bit_op bxor, eor + | + |2: + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | strd CARG34, [BASE, #-8] + | b ->fff_res1 + | + |.ffunc_bit bswap + | eor CARG3, CARG1, CARG1, ror #16 + | bic CARG3, CARG3, #0x00ff0000 + | ror CARG1, CARG1, #8 + | mvn CARG2, #~LJ_TISNUM + | eor CARG1, CARG1, CARG3, lsr #8 + | b ->fff_restv + | + |.ffunc_bit bnot + | mvn CARG1, CARG1 + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc bit_..name + | ldrd CARG12, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + |.if shmod == 0 + | and RA, CARG1, #31 + |.else + | rsb RA, CARG1, #0 + |.endif + | ldrd CARG12, [BASE] + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + | ins CARG1, CARG1, RA + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + |.endmacro + | + |.ffunc_bit_sh lshift, lsl, 0 + |.ffunc_bit_sh rshift, lsr, 0 + |.ffunc_bit_sh arshift, asr, 0 + |.ffunc_bit_sh rol, ror, 1 + |.ffunc_bit_sh ror, ror, 0 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RC = nargs*8 + | ldr CARG3, [BASE, FRAME_FUNC] + | ldr CARG2, L->maxstack + | add CARG1, BASE, NARGS8:RC + | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC. + | str CARG1, L->top + | ldr CARG3, CFUNC:CARG3->f + | str BASE, L->base + | add CARG1, CARG1, #8*LUA_MINSTACK + | str PC, SAVE_PC // Redundant (but a defined value). + | cmp CARG1, CARG2 + | mov CARG1, L + | bhi >5 // Need to grow stack. + | blx CARG3 // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | ldr BASE, L->base + | cmp CRET1, #0 + | lsl RC, CRET1, #3 + | sub RA, BASE, #8 + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | ldr CARG1, L->top + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | sub NARGS8:RC, CARG1, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | ands CARG1, PC, #FRAME_TYPE + | bic CARG2, PC, #FRAME_TYPEP + | ldreq INS, [PC, #-4] + | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8. + | addeq CARG2, CARG2, #8 + | sub RB, BASE, CARG2 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | mov CARG2, #LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | cmp CARG1, CARG1 // Set zero-flag to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mov RA, lr + | str BASE, L->base + | add CARG2, BASE, NARGS8:RC + | str PC, SAVE_PC // Redundant (but a defined value). + | str CARG2, L->top + | mov CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | ldr BASE, L->base + | mov lr, RA // Help return address predictor. + | ldr CFUNC:CARG3, [BASE, FRAME_FUNC] + | bx lr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent. + | bne >5 + | // Decrement the hookcount for consistency, but always do the call. + | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | tst CARG1, #HOOK_ACTIVE + | bne >1 + | sub CARG2, CARG2, #1 + | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT + | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | b >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | tst CARG1, #HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | decode_OP OP, INS + | add OP, DISPATCH, OP, lsl #2 + | ldr pc, [OP, #GG_DISP2STATIC] + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | tst CARG1, #HOOK_ACTIVE // Hook already active? + | bne <5 + | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT + | beq <5 + | subs CARG2, CARG2, #1 + | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | beq >1 + | tst CARG1, #LUA_MASKLINE + | beq <5 + |1: + | mov CARG1, L + | str BASE, L->base + | mov CARG2, PC + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | ldr BASE, L->base + |4: // Re-dispatch to static ins. + | ldrb OP, [PC, #-4] + | ldr INS, [PC, #-4] + | add OP, DISPATCH, OP, lsl #2 + | ldr OP, [OP, #GG_DISP2STATIC] + | decode_RA8 RA, INS + | decode_RD RC, INS + | bx OP + | + |->cont_hook: // Continue from hook yield. + | ldr CARG1, [CARG4, #-24] + | add PC, PC, #4 + | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L). + | sub CARG1, DISPATCH, #-GG_DISP2J + | str PC, SAVE_PC + | ldr CARG3, LFUNC:CARG3->field_pc + | mov CARG2, PC + | str L, [DISPATCH, #DISPATCH_J(L)] + | ldrb CARG3, [CARG3, #PC2PROTO(framesize)] + | str BASE, L->base + | add CARG3, BASE, CARG3, lsl #3 + | str CARG3, L->top + | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) + | b <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mov CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | orr CARG2, PC, #1 + |1: + |.endif + | add CARG4, BASE, RC + | str PC, SAVE_PC + | mov CARG1, L + | str BASE, L->base + | sub RA, RA, BASE + | str CARG4, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | ldr BASE, L->base + | ldr CARG4, L->top + | mov CARG2, #0 + | add RA, BASE, RA + | sub NARGS8:RC, CARG4, BASE + | str CARG2, SAVE_PC // Invalidate for subsequent line hook. + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | ldr INS, [PC, #-4] + | bx CRET1 + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_exit_handler: + |.if JIT + | sub sp, sp, #12 + | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12} + | ldr CARG1, [sp, #64] // Load original value of lr. + | ldr DISPATCH, [lr] // Load DISPATCH. + | add CARG3, sp, #64 // Recompute original value of sp. + | mv_vmstate CARG4, EXIT + | str CARG3, [sp, #52] // Store sp in RID_SP + | st_vmstate CARG4 + | ldr CARG2, [CARG1, #-4]! // Get exit instruction. + | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC. + | str CARG1, [sp, #60] + |.if FPU + | vpush {d0-d15} + |.endif + | lsl CARG2, CARG2, #8 + | add CARG1, CARG1, CARG2, asr #6 + | ldr CARG2, [lr, #4] // Load exit stub group offset. + | sub CARG1, CARG1, lr + | ldr L, [DISPATCH, #DISPATCH_GL(jit_L)] + | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number. + | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)] + | str CARG1, [DISPATCH, #DISPATCH_J(exitno)] + | mov CARG4, #0 + | str L, [DISPATCH, #DISPATCH_J(L)] + | str BASE, L->base + | str CARG4, [DISPATCH, #DISPATCH_GL(jit_L)] + | sub CARG1, DISPATCH, #-GG_DISP2J + | mov CARG2, sp + | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) + | // Returns MULTRES (unscaled) or negated error code. + | ldr CARG2, L->cframe + | ldr BASE, L->base + | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. + | mov sp, CARG2 + | ldr PC, SAVE_PC // Get SAVE_PC. + | str L, SAVE_L // Set SAVE_L (on-trace resume/yield). + | b >1 + |.endif + |->vm_exit_interp: + | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set. + |.if JIT + | ldr L, SAVE_L + |1: + | cmp CARG1, #0 + | blt >3 // Check for error from exit. + | lsl RC, CARG1, #3 + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | str RC, SAVE_MULTRES + | mov CARG3, #0 + | ldr CARG2, LFUNC:CARG2->field_pc + | str CARG3, [DISPATCH, #DISPATCH_GL(jit_L)] + | mv_vmstate CARG4, INTERP + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | // Modified copy of ins_next which handles function header dispatch, too. + | ldrb OP, [PC] + | mov MASKR8, #255 + | ldr INS, [PC], #4 + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | st_vmstate CARG4 + | cmp OP, #BC_FUNCF // Function header? + | ldr OP, [DISPATCH, OP, lsl #2] + | decode_RA8 RA, INS + | lsrlo RC, INS, #16 // No: Decode operands A*8 and D. + | subhs RC, RC, #8 + | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8 + | bx OP + | + |3: // Rethrow error from the right C frame. + | rsb CARG2, CARG1, #0 + | mov CARG1, L + | bl extern lj_err_throw // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called from JIT code. + |// + |// double lj_vm_floor/ceil/trunc(double x); + |.macro vm_round, func, hf + |.if hf == 1 + | vmov CARG1, CARG2, d0 + |.endif + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | bpl >2 // |x| < 1? + | mvn CARG4, #0x3cc + | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. + | bxlo lr // |x| >= 2^52: done. + | mvn CARG4, #1 + | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask + | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask + | subs RB, RB, #32 + | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask + | orrpl CARG3, CARG3, CARG4 + | mvnpl CARG4, #1 + | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) + |.else + | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) + |.endif + |.if hf == 1 + | vmoveq d0, CARG1, CARG2 + |.endif + | bxeq lr // iszero: done. + | mvn CARG4, #1 + | cmp RB, #0 + | lslpl CARG3, CARG4, RB + | mvnmi CARG3, #0 + | add RB, RB, #32 + | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask + | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + | + |2: // |x| < 1: + | bxcs lr // |x| is not finite. + | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) + |.else + | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) + |.endif + | mov CARG1, #0 // lo = 0 + | and CARG2, CARG2, #0x80000000 + | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0) + | orrne CARG2, CARG2, CARG4 + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + |.endmacro + | + |9: + | .long 0x3ff00000 // hiword(+1.0) + | + |->vm_floor: + |.if HFABI + | vm_round floor, 1 + |.endif + |->vm_floor_sf: + | vm_round floor, 0 + | + |->vm_ceil: + |.if HFABI + | vm_round ceil, 1 + |.endif + |->vm_ceil_sf: + | vm_round ceil, 0 + | + |.macro vm_trunc, hf + |.if JIT + |.if hf == 1 + | vmov CARG1, CARG2, d0 + |.endif + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0. + | movpl CARG1, #0 + |.if hf == 1 + | vmovpl d0, CARG1, CARG2 + |.endif + | bxpl lr + | mvn CARG4, #0x3cc + | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. + | bxlo lr // |x| >= 2^52: already done. + | mvn CARG4, #1 + | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask + | subs RB, RB, #32 + | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + |.endif + |.endmacro + | + |->vm_trunc: + |.if HFABI + | vm_trunc 1 + |.endif + |->vm_trunc_sf: + | vm_trunc 0 + | + | // double lj_vm_mod(double dividend, double divisor); + |->vm_mod: + |.if FPU + | // Special calling convention. Also, RC (r11) is not preserved. + | vdiv.f64 d0, d6, d7 + | mov RC, lr + | vmov CARG1, CARG2, d0 + | bl ->vm_floor_sf + | vmov d0, CARG1, CARG2 + | vmul.f64 d0, d0, d7 + | mov lr, RC + | vsub.f64 d6, d6, d0 + | bx lr + |.else + | push {r0, r1, r2, r3, r4, lr} + | bl extern __aeabi_ddiv + | bl ->vm_floor_sf + | ldrd CARG34, [sp, #8] + | bl extern __aeabi_dmul + | ldrd CARG34, [sp] + | eor CARG2, CARG2, #0x80000000 + | bl extern __aeabi_dadd + | add sp, sp, #20 + | pop {pc} + |.endif + | + | // int lj_vm_modi(int dividend, int divisor); + |->vm_modi: + | ands RB, CARG1, #0x80000000 + | rsbmi CARG1, CARG1, #0 // a = |dividend| + | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor). + | cmp CARG2, #0 + | rsbmi CARG2, CARG2, #0 // b = |divisor| + | subs CARG4, CARG2, #1 + | cmpne CARG1, CARG2 + | moveq CARG1, #0 // if (b == 1 || a == b) a = 0 + | tsthi CARG2, CARG4 + | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1 + | bls >1 + | // Use repeated subtraction to get the remainder. + | clz CARG3, CARG1 + | clz CARG4, CARG2 + | sub CARG4, CARG4, CARG3 + | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8 + | addne pc, pc, CARG3, lsl #3 // Duff's device. + | nop + { + int i; + for (i = 31; i >= 0; i--) { + | cmp CARG1, CARG2, lsl #i + | subhs CARG1, CARG1, CARG2, lsl #i + } + } + |1: + | cmp CARG1, #0 + | cmpne RB, #0 + | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b + | eors CARG2, CARG1, RB, lsl #1 + | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y + | bx lr + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. + |// Saveregs already performed. Callback slot number in [sp], g in r12. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | ldr CTSTATE, GL:r12->ctype_state + | add DISPATCH, r12, #GG_G2DISP + |.if FPU + | str r4, SAVE_R4 + | add r4, sp, CFRAME_SPACE+4+8*8 + | vstmdb r4!, {d8-d15} + |.endif + |.if HFABI + | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8]) + |.endif + | strd CARG34, CTSTATE->cb.gpr[2] + | strd CARG12, CTSTATE->cb.gpr[0] + |.if HFABI + | vstmdb r12!, {d0-d7} + |.endif + | ldr CARG4, [sp] + | add CARG3, sp, #CFRAME_SIZE + | mov CARG1, CTSTATE + | lsr CARG4, CARG4, #3 + | str CARG3, CTSTATE->cb.stack + | mov CARG2, sp + | str CARG4, CTSTATE->cb.slot + | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok. + | bl extern lj_ccallback_enter // (CTState *cts, void *cf) + | // Returns lua_State *. + | ldr BASE, L:CRET1->base + | mv_vmstate CARG2, INTERP + | ldr RC, L:CRET1->top + | mov MASKR8, #255 + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | mov L, CRET1 + | sub RC, RC, BASE + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | st_vmstate CARG2 + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)] + | str BASE, L->base + | str CARG4, L->top + | str L, CTSTATE->L + | mov CARG1, CTSTATE + | mov CARG2, RA + | bl extern lj_ccallback_leave // (CTState *cts, TValue *o) + | ldrd CARG12, CTSTATE->cb.gpr[0] + |.if HFABI + | vldr d0, CTSTATE->cb.fpr[0] + |.endif + | b ->vm_leave_unw + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, r4 + | push {CCSTATE, r5, r11, lr} + | mov CCSTATE, CARG1 + | ldr CARG1, CCSTATE:CARG1->spadj + | ldrb CARG2, CCSTATE->nsp + | add CARG3, CCSTATE, #offsetof(CCallState, stack) + |.if HFABI + | add RB, CCSTATE, #offsetof(CCallState, fpr[0]) + |.endif + | mov r11, sp + | sub sp, sp, CARG1 // Readjust stack. + | subs CARG2, CARG2, #1 + |.if HFABI + | vldm RB, {d0-d7} + |.endif + | ldr RB, CCSTATE->func + | bmi >2 + |1: // Copy stack slots. + | ldr CARG4, [CARG3, CARG2, lsl #2] + | str CARG4, [sp, CARG2, lsl #2] + | subs CARG2, CARG2, #1 + | bpl <1 + |2: + | ldrd CARG12, CCSTATE->gpr[0] + | ldrd CARG34, CCSTATE->gpr[2] + | blx RB + | mov sp, r11 + |.if HFABI + | add r12, CCSTATE, #offsetof(CCallState, fpr[4]) + |.endif + | strd CRET1, CCSTATE->gpr[0] + |.if HFABI + | vstmdb r12!, {d0-d3} + |.endif + | pop {CCSTATE, r5, r11, pc} + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RC = src2, JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, BASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TISNUM + | bne >3 + | checktp CARG4, LJ_TISNUM + | bne >4 + | cmp CARG1, CARG3 + if (op == BC_ISLT) { + | sublt PC, RB, #0x20000 + } else if (op == BC_ISGE) { + | subge PC, RB, #0x20000 + } else if (op == BC_ISLE) { + | suble PC, RB, #0x20000 + } else { + | subgt PC, RB, #0x20000 + } + |1: + | ins_next + | + |3: // CARG12 is not an integer. + |.if FPU + | vldr d0, [RA] + | bhi ->vmeta_comp + | // d0 is a number. + | checktp CARG4, LJ_TISNUM + | vldr d1, [RC] + | blo >5 + | bhi ->vmeta_comp + | // d0 is a number, CARG3 is an integer. + | vmov s4, CARG3 + | vcvt.f64.s32 d1, s4 + | b >5 + |4: // CARG1 is an integer, CARG34 is not an integer. + | vldr d1, [RC] + | bhi ->vmeta_comp + | // CARG1 is an integer, d1 is a number. + | vmov s4, CARG1 + | vcvt.f64.s32 d0, s4 + |5: // d0 and d1 are numbers. + | vcmp.f64 d0, d1 + | vmrs + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + if (op == BC_ISLT) { + | sublo PC, RB, #0x20000 + } else if (op == BC_ISGE) { + | subhs PC, RB, #0x20000 + } else if (op == BC_ISLE) { + | subls PC, RB, #0x20000 + } else { + | subhi PC, RB, #0x20000 + } + | b <1 + |.else + | bhi ->vmeta_comp + | // CARG12 is a number. + | checktp CARG4, LJ_TISNUM + | movlo RA, RB // Save RB. + | blo >5 + | bhi ->vmeta_comp + | // CARG12 is a number, CARG3 is an integer. + | mov CARG1, CARG3 + | mov RC, RA + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | mov CARG3, CARG1 + | mov CARG4, CARG2 + | ldrd CARG12, [RC] // Restore first operand. + | b >5 + |4: // CARG1 is an integer, CARG34 is not an integer. + | bhi ->vmeta_comp + | // CARG1 is an integer, CARG34 is a number. + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | ldrd CARG34, [RC] // Restore second operand. + |5: // CARG12 and CARG34 are numbers. + | bl extern __aeabi_cdcmple + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + if (op == BC_ISLT) { + | sublo PC, RA, #0x20000 + } else if (op == BC_ISGE) { + | subhs PC, RA, #0x20000 + } else if (op == BC_ISLE) { + | subls PC, RA, #0x20000 + } else { + | subhi PC, RA, #0x20000 + } + | b <1 + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RC = src2, JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, BASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TISNUM + | cmnls CARG4, #-LJ_TISNUM + if (vk) { + | bls ->BC_ISEQN_Z + } else { + | bls ->BC_ISNEN_Z + } + | // Either or both types are not numbers. + |.if FFI + | checktp CARG2, LJ_TCDATA + | checktpne CARG4, LJ_TCDATA + | beq ->vmeta_equal_cd + |.endif + | cmp CARG2, CARG4 // Compare types. + | bne >2 // Not the same type? + | checktp CARG2, LJ_TISPRI + | bhs >1 // Same type and primitive type? + | + | // Same types and not a primitive type. Compare GCobj or pvalue. + | cmp CARG1, CARG3 + if (vk) { + | bne >3 // Different GCobjs or pvalues? + |1: // Branch if same. + | sub PC, RB, #0x20000 + |2: // Different. + | ins_next + |3: + | checktp CARG2, LJ_TISTABUD + | bhi <2 // Different objects and not table/ud? + } else { + | beq >1 // Same GCobjs or pvalues? + | checktp CARG2, LJ_TISTABUD + | bhi >2 // Different objects and not table/ud? + } + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + if (vk) { + | beq <2 // No metatable? + } else { + | beq >2 // No metatable? + } + | ldrb RA, TAB:RA->nomm + | mov CARG4, #1-vk // ne = 0 or 1. + | mov CARG2, CARG1 + | tst RA, #1<vmeta_equal // 'no __eq' flag not set? + if (vk) { + | b <2 + } else { + |2: // Branch if different. + | sub PC, RB, #0x20000 + |1: // Same. + | ins_next + } + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RC = str_const (~), JMP with RC = target + | mvn RC, RC + | ldrd CARG12, [BASE, RA] + | ldrh RB, [PC, #2] + | ldr STR:CARG3, [KBASE, RC, lsl #2] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TSTR + |.if FFI + | bne >7 + | cmp CARG1, CARG3 + |.else + | cmpeq CARG1, CARG3 + |.endif + if (vk) { + | subeq PC, RB, #0x20000 + |1: + } else { + |1: + | subne PC, RB, #0x20000 + } + | ins_next + | + |.if FFI + |7: + | checktp CARG2, LJ_TCDATA + | bne <1 + | b ->vmeta_equal_cd + |.endif + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RC = num_const (~), JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, KBASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + if (vk) { + |->BC_ISEQN_Z: + } else { + |->BC_ISNEN_Z: + } + | checktp CARG2, LJ_TISNUM + | bne >3 + | checktp CARG4, LJ_TISNUM + | bne >4 + | cmp CARG1, CARG3 + if (vk) { + | subeq PC, RB, #0x20000 + |1: + } else { + |1: + | subne PC, RB, #0x20000 + } + |2: + | ins_next + | + |3: // CARG12 is not an integer. + |.if FFI + | bhi >7 + |.else + if (!vk) { + | subhi PC, RB, #0x20000 + } + | bhi <2 + |.endif + |.if FPU + | checktp CARG4, LJ_TISNUM + | vmov s4, CARG3 + | vldr d0, [RA] + | vldrlo d1, [RC] + | vcvths.f64.s32 d1, s4 + | b >5 + |4: // CARG1 is an integer, d1 is a number. + | vmov s4, CARG1 + | vldr d1, [RC] + | vcvt.f64.s32 d0, s4 + |5: // d0 and d1 are numbers. + | vcmp.f64 d0, d1 + | vmrs + if (vk) { + | subeq PC, RB, #0x20000 + } else { + | subne PC, RB, #0x20000 + } + | b <2 + |.else + | // CARG12 is a number. + | checktp CARG4, LJ_TISNUM + | movlo RA, RB // Save RB. + | blo >5 + | // CARG12 is a number, CARG3 is an integer. + | mov CARG1, CARG3 + | mov RC, RA + |4: // CARG1 is an integer, CARG34 is a number. + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | ldrd CARG34, [RC] // Restore other operand. + |5: // CARG12 and CARG34 are numbers. + | bl extern __aeabi_cdcmpeq + if (vk) { + | subeq PC, RA, #0x20000 + } else { + | subne PC, RA, #0x20000 + } + | b <2 + |.endif + | + |.if FFI + |7: + | checktp CARG2, LJ_TCDATA + | bne <1 + | b ->vmeta_equal_cd + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RC = primitive_type (~), JMP with RC = target + | ldrd CARG12, [BASE, RA] + | ldrh RB, [PC, #2] + | add PC, PC, #4 + | mvn RC, RC + | add RB, PC, RB, lsl #2 + |.if FFI + | checktp CARG2, LJ_TCDATA + | beq ->vmeta_equal_cd + |.endif + | cmp CARG2, RC + if (vk) { + | subeq PC, RB, #0x20000 + } else { + | subne PC, RB, #0x20000 + } + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RC = src, JMP with RC = target + | add RC, BASE, RC, lsl #3 + | ldrh RB, [PC, #2] + | ldrd CARG12, [RC] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TTRUE + if (op == BC_ISTC || op == BC_IST) { + | subls PC, RB, #0x20000 + if (op == BC_ISTC) { + | strdls CARG12, [BASE, RA] + } + } else { + | subhi PC, RB, #0x20000 + if (op == BC_ISFC) { + | strdhi CARG12, [BASE, RA] + } + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ins_next1 + | ldrd CARG12, [BASE, RC] + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_NOT: + | // RA = dst*8, RC = src + | add RC, BASE, RC, lsl #3 + | ins_next1 + | ldr CARG1, [RC, #4] + | add RA, BASE, RA + | ins_next2 + | checktp CARG1, LJ_TTRUE + | mvnls CARG2, #~LJ_TFALSE + | mvnhi CARG2, #~LJ_TTRUE + | str CARG2, [RA, #4] + | ins_next3 + break; + case BC_UNM: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ldrd CARG12, [BASE, RC] + | ins_next1 + | ins_next2 + | checktp CARG2, LJ_TISNUM + | bhi ->vmeta_unm + | eorne CARG2, CARG2, #0x80000000 + | bne >5 + | rsbseq CARG1, CARG1, #0 + | ldrdvs CARG12, >9 + |5: + | strd CARG12, [BASE, RA] + | ins_next3 + | + |.align 8 + |9: + | .long 0x00000000, 0x41e00000 // 2^31. + break; + case BC_LEN: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ldrd CARG12, [BASE, RC] + | checkstr CARG2, >2 + | ldr CARG1, STR:CARG1->len + |1: + | mvn CARG2, #~LJ_TISNUM + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |2: + | checktab CARG2, ->vmeta_len +#if LJ_52 + | ldr TAB:CARG3, TAB:CARG1->metatable + | cmp TAB:CARG3, #0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | .IOS mov RC, BASE + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | .IOS mov BASE, RC + | b <1 +#if LJ_52 + |9: + | ldrb CARG4, TAB:CARG3->nomm + | tst CARG4, #1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithcheck, cond, ncond, target + ||if (vk == 1) { + | cmn CARG4, #-LJ_TISNUM + | cmn..cond CARG2, #-LJ_TISNUM + ||} else { + | cmn CARG2, #-LJ_TISNUM + | cmn..cond CARG4, #-LJ_TISNUM + ||} + | b..ncond target + |.endmacro + |.macro ins_arithcheck_int, target + | ins_arithcheck eq, ne, target + |.endmacro + |.macro ins_arithcheck_num, target + | ins_arithcheck lo, hs, target + |.endmacro + | + |.macro ins_arithpre + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | .if FPU + | ldrd CARG12, [RB, BASE]! + | ldrd CARG34, [RC, KBASE]! + | .else + | ldrd CARG12, [BASE, RB] + | ldrd CARG34, [KBASE, RC] + | .endif + || break; + ||case 1: + | .if FPU + | ldrd CARG34, [RB, BASE]! + | ldrd CARG12, [RC, KBASE]! + | .else + | ldrd CARG34, [BASE, RB] + | ldrd CARG12, [KBASE, RC] + | .endif + || break; + ||default: + | .if FPU + | ldrd CARG12, [RB, BASE]! + | ldrd CARG34, [RC, BASE]! + | .else + | ldrd CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | .endif + || break; + ||} + |.endmacro + | + |.macro ins_arithpre_fpu, reg1, reg2 + |.if FPU + ||if (vk == 1) { + | vldr reg2, [RB] + | vldr reg1, [RC] + ||} else { + | vldr reg1, [RB] + | vldr reg2, [RC] + ||} + |.endif + |.endmacro + | + |.macro ins_arithpost_fpu, reg + | ins_next1 + | add RA, BASE, RA + | ins_next2 + | vstr reg, [RA] + | ins_next3 + |.endmacro + | + |.macro ins_arithfallback, ins + ||switch (vk) { + ||case 0: + | ins ->vmeta_arith_vn + || break; + ||case 1: + | ins ->vmeta_arith_nv + || break; + ||default: + | ins ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arithdn, intins, fpins, fpcall + | ins_arithpre + |.if "intins" ~= "vm_modi" and not FPU + | ins_next1 + |.endif + | ins_arithcheck_int >5 + |.if "intins" == "smull" + | smull CARG1, RC, CARG3, CARG1 + | cmp RC, CARG1, asr #31 + | ins_arithfallback bne + |.elif "intins" == "vm_modi" + | movs CARG2, CARG3 + | ins_arithfallback beq + | bl ->vm_modi + | mvn CARG2, #~LJ_TISNUM + |.else + | intins CARG1, CARG1, CARG3 + | ins_arithfallback bvs + |.endif + |4: + |.if "intins" == "vm_modi" or FPU + | ins_next1 + |.endif + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |5: // FP variant. + | ins_arithpre_fpu d6, d7 + | ins_arithfallback ins_arithcheck_num + |.if FPU + |.if "intins" == "vm_modi" + | bl fpcall + |.else + | fpins d6, d6, d7 + |.endif + | ins_arithpost_fpu d6 + |.else + | bl fpcall + |.if "intins" ~= "vm_modi" + | ins_next1 + |.endif + | b <4 + |.endif + |.endmacro + | + |.macro ins_arithfp, fpins, fpcall + | ins_arithpre + |.if "fpins" ~= "extern" or HFABI + | ins_arithpre_fpu d0, d1 + |.endif + | ins_arithfallback ins_arithcheck_num + |.if "fpins" == "extern" + | .IOS mov RC, BASE + | bl fpcall + | .IOS mov BASE, RC + |.elif FPU + | fpins d0, d0, d1 + |.else + | bl fpcall + |.endif + |.if ("fpins" ~= "extern" or HFABI) and FPU + | ins_arithpost_fpu d0 + |.else + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arithdn adds, vadd.f64, extern __aeabi_dadd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arithdn subs, vsub.f64, extern __aeabi_dsub + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arithdn smull, vmul.f64, extern __aeabi_dmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arithfp vdiv.f64, extern __aeabi_ddiv + break; + case BC_MODVN: case BC_MODNV: case BC_MODVV: + | ins_arithdn vm_modi, vm_mod, ->vm_mod + break; + case BC_POW: + | // NYI: (partial) integer arithmetic. + | ins_arithfp extern, extern pow + break; + + case BC_CAT: + | decode_RB8 RC, INS + | decode_RC8 RB, INS + | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!) + | sub CARG3, RB, RC + | str BASE, L->base + | add CARG2, BASE, RB + |->BC_CAT_Z: + | // RA = dst*8, RC = src_start*8, CARG2 = top-1 + | mov CARG1, L + | str PC, SAVE_PC + | lsr CARG3, CARG3, #3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | ldr BASE, L->base + | cmp CRET1, #0 + | bne ->vmeta_binop + | ldrd CARG34, [BASE, RC] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] // Copy result to RA. + | ins_next3 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RC = str_const (~) + | mvn RC, RC + | ins_next1 + | ldr CARG1, [KBASE, RC, lsl #2] + | mvn CARG2, #~LJ_TSTR + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RC = cdata_const (~) + | mvn RC, RC + | ins_next1 + | ldr CARG1, [KBASE, RC, lsl #2] + | mvn CARG2, #~LJ_TCDATA + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, (RC = int16_literal) + | mov CARG1, INS, asr #16 // Refetch sign-extended reg. + | mvn CARG2, #~LJ_TISNUM + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KNUM: + | // RA = dst*8, RC = num_const + | lsl RC, RC, #3 + | ins_next1 + | ldrd CARG12, [KBASE, RC] + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KPRI: + | // RA = dst*8, RC = primitive_type (~) + | add RA, BASE, RA + | mvn RC, RC + | ins_next1 + | ins_next2 + | str RC, [RA, #4] + | ins_next3 + break; + case BC_KNIL: + | // RA = base*8, RC = end + | add RA, BASE, RA + | add RC, BASE, RC, lsl #3 + | mvn CARG1, #~LJ_TNIL + | str CARG1, [RA, #4] + | add RA, RA, #8 + |1: + | str CARG1, [RA, #4] + | cmp RA, RC + | add RA, RA, #8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RC = uvnum + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsl RC, RC, #2 + | add RC, RC, #offsetof(GCfuncL, uvptr) + | ldr UPVAL:CARG2, [LFUNC:CARG2, RC] + | ldr CARG2, UPVAL:CARG2->v + | ldrd CARG34, [CARG2] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + break; + case BC_USETV: + | // RA = uvnum*8, RC = src + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | lsl RC, RC, #3 + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldrd CARG34, [BASE, RC] + | ldrb RB, UPVAL:CARG2->marked + | ldrb RC, UPVAL:CARG2->closed + | ldr CARG2, UPVAL:CARG2->v + | tst RB, #LJ_GC_BLACK // isblack(uv) + | add RB, CARG4, #-LJ_TISGCV + | cmpne RC, #0 + | strd CARG34, [CARG2] + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmn RB, #-(LJ_TNUMX - LJ_TISGCV) + | ldrbhi RC, GCOBJ:CARG3->gch.marked + | bls <1 // tvisgcv(v) + | sub CARG1, DISPATCH, #-GG_DISP2G + | tst RC, #LJ_GC_WHITES + | // Crossed a write barrier. Move the barrier forward. + |.if IOS + | beq <1 + | mov RC, BASE + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | mov BASE, RC + |.else + | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) + |.endif + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RC = str_const (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | mvn RC, RC + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldr STR:CARG3, [KBASE, RC, lsl #2] + | mvn CARG4, #~LJ_TSTR + | ldrb RB, UPVAL:CARG2->marked + | ldr CARG2, UPVAL:CARG2->v + | ldrb RC, UPVAL:CARG2->closed + | tst RB, #LJ_GC_BLACK // isblack(uv) + | ldrb RB, STR:CARG3->marked + | strd CARG34, [CARG2] + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | tst RB, #LJ_GC_WHITES // iswhite(str) + | cmpne RC, #0 + | sub CARG1, DISPATCH, #-GG_DISP2G + | // Crossed a write barrier. Move the barrier forward. + |.if IOS + | beq <1 + | mov RC, BASE + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | mov BASE, RC + |.else + | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) + |.endif + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RC = num_const + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | lsl RC, RC, #3 + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldrd CARG34, [KBASE, RC] + | ldr CARG2, UPVAL:CARG2->v + | ins_next1 + | ins_next2 + | strd CARG34, [CARG2] + | ins_next3 + break; + case BC_USETP: + | // RA = uvnum*8, RC = primitive_type (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | mvn RC, RC + | ldr CARG2, UPVAL:CARG2->v + | ins_next1 + | ins_next2 + | str RC, [CARG2, #4] + | ins_next3 + break; + + case BC_UCLO: + | // RA = level*8, RC = target + | ldr CARG3, L->openupval + | add RC, PC, RC, lsl #2 + | str BASE, L->base + | cmp CARG3, #0 + | sub PC, RC, #0x20000 + | beq >1 + | mov CARG1, L + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | ldr BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RC = proto_const (~) (holding function prototype) + | mvn RC, RC + | str BASE, L->base + | ldr CARG2, [KBASE, RC, lsl #2] + | str PC, SAVE_PC + | ldr CARG3, [BASE, FRAME_FUNC] + | mov CARG1, L + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TFUNC + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RC = (hbits|asize) | tab_const (~) + if (op == BC_TDUP) { + | mvn RC, RC + } + | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)] + | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)] + | str BASE, L->base + | str PC, SAVE_PC + | cmp CARG3, CARG4 + | mov CARG1, L + | bhs >5 + |1: + if (op == BC_TNEW) { + | lsl CARG2, RC, #21 + | lsr CARG3, RC, #11 + | asr RC, CARG2, #21 + | lsr CARG2, CARG2, #21 + | cmn RC, #1 + | addeq CARG2, CARG2, #2 + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns GCtab *. + } else { + | ldr CARG2, [KBASE, RC, lsl #2] + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns GCtab *. + } + | ldr BASE, L->base + | mvn CARG2, #~LJ_TTAB + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |5: + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mov CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RC = str_const (~) + case BC_GSET: + | // RA = dst*8, RC = str_const (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | mvn RC, RC + | ldr TAB:CARG1, LFUNC:CARG2->env + | ldr STR:RC, [KBASE, RC, lsl #2] + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = dst*8, RB = table*8, RC = key*8 + | ldrd TAB:CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12. + | checktp CARG4, LJ_TISNUM // Integer key? + | ldreq CARG4, TAB:CARG1->array + | ldreq CARG2, TAB:CARG1->asize + | bne >9 + | + | add CARG4, CARG4, CARG3, lsl #3 + | cmp CARG3, CARG2 // In array part? + | ldrdlo CARG34, [CARG4] + | bhs ->vmeta_tgetv + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | beq >5 + |1: + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG2, TAB:CARG1->metatable + | cmp TAB:CARG2, #0 + | beq <1 // No metatable: done. + | ldrb CARG2, TAB:CARG2->nomm + | tst CARG2, #1<vmeta_tgetv + | + |9: + | checktp CARG4, LJ_TSTR // String key? + | moveq STR:RC, CARG3 + | beq ->BC_TGETS_Z + | b ->vmeta_tgetv + break; + case BC_TGETS: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = dst*8, RB = table*8, RC = str_const (~) + | ldrd CARG12, [BASE, RB] + | mvn RC, RC + | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. + | checktab CARG2, ->vmeta_tgets1 + |->BC_TGETS_Z: + | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 + | ldr CARG3, TAB:CARG1->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:CARG1->node + | mov TAB:RB, TAB:CARG1 + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + |1: + | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS. + | ldrd CARG34, NODE:INS->val + | ldr NODE:INS, NODE:INS->next + | checktp CARG2, LJ_TSTR + | cmpeq CARG1, STR:RC + | bne >4 + | checktp CARG4, LJ_TNIL + | beq >5 + |3: + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |4: // Follow hash chain. + | cmp NODE:INS, #0 + | bne <1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG1, TAB:RB->metatable + | mov CARG3, #0 // Optional clear of undef. value (during load stall). + | mvn CARG4, #~LJ_TNIL + | cmp TAB:CARG1, #0 + | beq <3 // No metatable: done. + | ldrb CARG2, TAB:CARG1->nomm + | tst CARG2, #1<vmeta_tgets + break; + case BC_TGETB: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = dst*8, RB = table*8, RC = index + | ldrd CARG12, [BASE, RB] + | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12. + | ldr CARG3, TAB:CARG1->asize + | ldr CARG4, TAB:CARG1->array + | lsl CARG2, RC, #3 + | cmp RC, CARG3 + | ldrdlo CARG34, [CARG4, CARG2] + | bhs ->vmeta_tgetb + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | beq >5 + |1: + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG2, TAB:CARG1->metatable + | cmp TAB:CARG2, #0 + | beq <1 // No metatable: done. + | ldrb CARG2, TAB:CARG2->nomm + | tst CARG2, #1<vmeta_tgetb + break; + + case BC_TSETV: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = src*8, RB = table*8, RC = key*8 + | ldrd TAB:CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12. + | checktp CARG4, LJ_TISNUM // Integer key? + | ldreq CARG2, TAB:CARG1->array + | ldreq CARG4, TAB:CARG1->asize + | bne >9 + | + | add CARG2, CARG2, CARG3, lsl #3 + | cmp CARG3, CARG4 // In array part? + | ldrlo INS, [CARG2, #4] + | bhs ->vmeta_tsetv + | ins_next1 // Overwrites RB! + | checktp INS, LJ_TNIL + | ldrb INS, TAB:CARG1->marked + | ldrd CARG34, [BASE, RA] + | beq >5 + |1: + | tst INS, #LJ_GC_BLACK // isblack(table) + | strd CARG34, [CARG2] + | bne >7 + |2: + | ins_next2 + | ins_next3 + | + |5: // Check for __newindex if previous value is nil. + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + | beq <1 // No metatable: done. + | ldrb RA, TAB:RA->nomm + | tst RA, #1<vmeta_tsetv + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:CARG1, INS, CARG3 + | b <2 + | + |9: + | checktp CARG4, LJ_TSTR // String key? + | moveq STR:RC, CARG3 + | beq ->BC_TSETS_Z + | b ->vmeta_tsetv + break; + case BC_TSETS: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = src*8, RB = table*8, RC = str_const (~) + | ldrd CARG12, [BASE, RB] + | mvn RC, RC + | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. + | checktab CARG2, ->vmeta_tsets1 + |->BC_TSETS_Z: + | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 + | ldr CARG3, TAB:CARG1->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:CARG1->node + | mov TAB:RB, TAB:CARG1 + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | mov CARG4, #0 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + | strb CARG4, TAB:RB->nomm // Clear metamethod cache. + |1: + | ldrd CARG12, NODE:INS->key + | ldr CARG4, NODE:INS->val.it + | ldr NODE:CARG3, NODE:INS->next + | checktp CARG2, LJ_TSTR + | cmpeq CARG1, STR:RC + | bne >5 + | ldrb CARG2, TAB:RB->marked + | checktp CARG4, LJ_TNIL // Key found, but nil value? + | ldrd CARG34, [BASE, RA] + | beq >4 + |2: + | tst CARG2, #LJ_GC_BLACK // isblack(table) + | strd CARG34, NODE:INS->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | ldr TAB:CARG1, TAB:RB->metatable + | cmp TAB:CARG1, #0 + | beq <2 // No metatable: done. + | ldrb CARG1, TAB:CARG1->nomm + | tst CARG1, #1<vmeta_tsets + | + |5: // Follow hash chain. + | movs NODE:INS, NODE:CARG3 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | ldr TAB:CARG1, TAB:RB->metatable + | mov CARG3, TMPDp + | str PC, SAVE_PC + | cmp TAB:CARG1, #0 // No metatable: continue. + | str BASE, L->base + | ldrbne CARG2, TAB:CARG1->nomm + | mov CARG1, L + | beq >6 + | tst CARG2, #1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | mov CARG2, TAB:RB + | str CARG4, TMPDhi + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | ldr BASE, L->base + | ldrd CARG34, [BASE, RA] + | strd CARG34, [CRET1] + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, CARG2, CARG3 + | b <3 + break; + case BC_TSETB: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = src*8, RB = table*8, RC = index + | ldrd CARG12, [BASE, RB] + | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12. + | ldr CARG3, TAB:CARG1->asize + | ldr RB, TAB:CARG1->array + | lsl CARG2, RC, #3 + | cmp RC, CARG3 + | ldrdlo CARG34, [CARG2, RB]! + | bhs ->vmeta_tsetb + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | ldrb INS, TAB:CARG1->marked + | ldrd CARG34, [BASE, RA] + | beq >5 + |1: + | tst INS, #LJ_GC_BLACK // isblack(table) + | strd CARG34, [CARG2] + | bne >7 + |2: + | ins_next2 + | ins_next3 + | + |5: // Check for __newindex if previous value is nil. + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + | beq <1 // No metatable: done. + | ldrb RA, TAB:RA->nomm + | tst RA, #1<vmeta_tsetb + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:CARG1, INS, CARG3 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RC = num_const (start index) + | add RA, BASE, RA + |1: + | ldr RB, SAVE_MULTRES + | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table. + | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word. + | subs RB, RB, #8 + | ldr CARG4, TAB:CARG2->asize + | beq >4 // Nothing to copy? + | add CARG3, CARG1, RB, lsr #3 + | cmp CARG3, CARG4 + | ldr CARG4, TAB:CARG2->array + | add RB, RA, RB + | bhi >5 + | add INS, CARG4, CARG1, lsl #3 + | ldrb CARG1, TAB:CARG2->marked + |3: // Copy result slots to table. + | ldrd CARG34, [RA], #8 + | strd CARG34, [INS], #8 + | cmp RA, RB + | blo <3 + | tst CARG1, #LJ_GC_BLACK // isblack(table) + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | .IOS ldr BASE, L->base + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, CARG1, CARG3 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = nresults+1,) RC = extra_nargs + | ldr CARG1, SAVE_MULTRES + | decode_RC8 NARGS8:RC, INS + | add NARGS8:RC, NARGS8:RC, CARG1 + | b ->BC_CALL_Z + break; + case BC_CALL: + | decode_RC8 NARGS8:RC, INS + | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8 + |->BC_CALL_Z: + | mov RB, BASE // Save old BASE for vmeta_call. + | ldrd CARG34, [BASE, RA]! + | sub NARGS8:RC, NARGS8:RC, #8 + | add BASE, BASE, #8 + | checkfunc CARG4, ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs + | ldr CARG1, SAVE_MULTRES + | add NARGS8:RC, CARG1, RC, lsl #3 + | b ->BC_CALLT1_Z + break; + case BC_CALLT: + | lsl NARGS8:RC, RC, #3 + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + |->BC_CALLT1_Z: + | ldrd LFUNC:CARG34, [RA, BASE]! + | sub NARGS8:RC, NARGS8:RC, #8 + | add RA, RA, #8 + | checkfunc CARG4, ->vmeta_callt + | ldr PC, [BASE, FRAME_PC] + |->BC_CALLT2_Z: + | mov RB, #0 + | ldrb CARG4, LFUNC:CARG3->ffid + | tst PC, #FRAME_TYPE + | bne >7 + |1: + | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC. + | cmp NARGS8:RC, #0 + | beq >3 + |2: + | ldrd CARG12, [RA, RB] + | add INS, RB, #8 + | cmp INS, NARGS8:RC + | strd CARG12, [BASE, RB] + | mov RB, INS + | bne <2 + |3: + | cmp CARG4, #1 // (> FF_C) Calling a fast function? + | bhi >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | ldr INS, [PC, #-4] + | decode_RA8 RA, INS + | sub CARG1, BASE, RA + | ldr LFUNC:CARG1, [CARG1, #-16] + | ldr CARG1, LFUNC:CARG1->field_pc + | ldr KBASE, [CARG1, #PC2PROTO(k)] + | b <4 + | + |7: // Tailcall from a vararg function. + | eor PC, PC, #FRAME_VARG + | tst PC, #FRAME_TYPEP // Vararg frame below? + | movne CARG4, #0 // Clear ffid if no Lua function below. + | bne <1 + | sub BASE, BASE, PC + | ldr PC, [BASE, FRAME_PC] + | tst PC, #FRAME_TYPE + | movne CARG4, #0 // Clear ffid if no Lua function below. + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) + | add RA, BASE, RA + | mov RB, BASE // Save old BASE for vmeta_call. + | ldrd CARG34, [RA, #-16] + | ldrd CARG12, [RA, #-8] + | add BASE, RA, #8 + | strd CARG34, [RA, #8] // Copy state. + | strd CARG12, [RA, #16] // Copy control var. + | // STALL: locked CARG34. + | ldrd LFUNC:CARG34, [RA, #-24] + | mov NARGS8:RC, #16 // Iterators get 2 arguments. + | // STALL: load CARG34. + | strd LFUNC:CARG34, [RA] // Copy callable. + | checkfunc CARG4, ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | ldr TAB:RB, [RA, #-16] + | ldr CARG1, [RA, #-8] // Get index from control var. + | ldr INS, TAB:RB->asize + | ldr CARG2, TAB:RB->array + | add PC, PC, #4 + |1: // Traverse array part. + | subs RC, CARG1, INS + | add CARG3, CARG2, CARG1, lsl #3 + | bhs >5 // Index points after array part? + | ldrd CARG34, [CARG3] + | checktp CARG4, LJ_TNIL + | addeq CARG1, CARG1, #1 // Skip holes in array part. + | beq <1 + | ldrh RC, [PC, #-2] + | mvn CARG2, #~LJ_TISNUM + | strd CARG34, [RA, #8] + | add RC, PC, RC, lsl #2 + | add RB, CARG1, #1 + | strd CARG12, [RA] + | sub PC, RC, #0x20000 + | str RB, [RA, #-8] // Update control var. + |3: + | ins_next + | + |5: // Traverse hash part. + | ldr CARG4, TAB:RB->hmask + | ldr NODE:RB, TAB:RB->node + |6: + | add CARG1, RC, RC, lsl #1 + | cmp RC, CARG4 // End of iteration? Branch to ITERL+1. + | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8 + | bhi <3 + | ldrd CARG12, NODE:CARG3->val + | checktp CARG2, LJ_TNIL + | add RC, RC, #1 + | beq <6 // Skip holes in hash part. + | ldrh RB, [PC, #-2] + | add RC, RC, INS + | ldrd CARG34, NODE:CARG3->key + | str RC, [RA, #-8] // Update control var. + | strd CARG12, [RA, #8] + | add RC, PC, RB, lsl #2 + | sub PC, RC, #0x20000 + | strd CARG34, [RA] + | b <3 + break; + + case BC_ISNEXT: + | // RA = base*8, RC = target (points to ITERN) + | add RA, BASE, RA + | add RC, PC, RC, lsl #2 + | ldrd CFUNC:CARG12, [RA, #-24] + | ldr CARG3, [RA, #-12] + | ldr CARG4, [RA, #-4] + | checktp CARG2, LJ_TFUNC + | ldrbeq CARG1, CFUNC:CARG1->ffid + | checktpeq CARG3, LJ_TTAB + | checktpeq CARG4, LJ_TNIL + | cmpeq CARG1, #FF_next_N + | subeq PC, RC, #0x20000 + | bne >5 + | ins_next1 + | ins_next2 + | mov CARG1, #0 + | mvn CARG2, #0x00018000 + | strd CARG1, [RA, #-8] // Initialize control var. + |1: + | ins_next3 + |5: // Despecialize bytecode if any of the checks fail. + | mov CARG1, #BC_JMP + | mov OP, #BC_ITERC + | strb CARG1, [PC, #-4] + | sub PC, RC, #0x20000 + | strb OP, [PC] // Subsumes ins_next1. + | ins_next2 + | b <1 + break; + + case BC_VARG: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | ldr CARG1, [BASE, FRAME_PC] + | add RC, BASE, RC + | add RA, BASE, RA + | add RC, RC, #FRAME_VARG + | add CARG4, RA, RB + | sub CARG3, BASE, #8 // CARG3 = vtop + | sub RC, RC, CARG1 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmp RB, #0 + | sub CARG1, CARG3, RC + | beq >5 // Copy all varargs? + | sub CARG4, CARG4, #16 + |1: // Copy vararg slots to destination slots. + | cmp RC, CARG3 + | ldrdlo CARG12, [RC], #8 + | mvnhs CARG2, #~LJ_TNIL + | cmp RA, CARG4 + | strd CARG12, [RA], #8 + | blo <1 + |2: + | ins_next + | + |5: // Copy all varargs. + | ldr CARG4, L->maxstack + | cmp CARG1, #0 + | movle RB, #8 // MULTRES = (0+1)*8 + | addgt RB, CARG1, #8 + | add CARG2, RA, CARG1 + | str RB, SAVE_MULTRES + | ble <2 + | cmp CARG2, CARG4 + | bhi >7 + |6: + | ldrd CARG12, [RC], #8 + | strd CARG12, [RA], #8 + | cmp RC, CARG3 + | blo <6 + | b <2 + | + |7: // Grow stack for varargs. + | lsr CARG2, CARG1, #3 + | str RA, L->top + | mov CARG1, L + | str BASE, L->base + | sub RC, RC, BASE // Need delta, because BASE may change. + | str PC, SAVE_PC + | sub RA, RA, BASE + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | add RA, BASE, RA + | add RC, BASE, RC + | sub CARG3, BASE, #8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RC = extra results + | ldr CARG1, SAVE_MULTRES + | ldr PC, [BASE, FRAME_PC] + | add RA, BASE, RA + | add RC, CARG1, RC, lsl #3 + | b ->BC_RETM_Z + break; + + case BC_RET: + | // RA = results*8, RC = nresults+1 + | ldr PC, [BASE, FRAME_PC] + | lsl RC, RC, #3 + | add RA, BASE, RA + |->BC_RETM_Z: + | str RC, SAVE_MULTRES + |1: + | ands CARG1, PC, #FRAME_TYPE + | eor CARG2, PC, #FRAME_VARG + | bne ->BC_RETV2_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return + | ldr INS, [PC, #-4] + | subs CARG4, RC, #8 + | sub CARG3, BASE, #8 + | beq >3 + |2: + | ldrd CARG12, [RA], #8 + | add BASE, BASE, #8 + | subs CARG4, CARG4, #8 + | strd CARG12, [BASE, #-16] + | bne <2 + |3: + | decode_RA8 RA, INS + | sub CARG4, CARG3, RA + | decode_RB8 RB, INS + | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC] + |5: + | cmp RB, RC // More results expected? + | bhi >6 + | mov BASE, CARG4 + | ldr CARG2, LFUNC:CARG1->field_pc + | ins_next1 + | ins_next2 + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | ins_next3 + | + |6: // Fill up results with nil. + | mvn CARG2, #~LJ_TNIL + | add BASE, BASE, #8 + | add RC, RC, #8 + | str CARG2, [BASE, #-12] + | b <5 + | + |->BC_RETV1_Z: // Non-standard return case. + | add RA, BASE, RA + |->BC_RETV2_Z: + | tst CARG2, #FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, CARG2 + | ldr PC, [BASE, FRAME_PC] + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RC = nresults+1 + | ldr PC, [BASE, FRAME_PC] + | lsl RC, RC, #3 + | str RC, SAVE_MULTRES + | ands CARG1, PC, #FRAME_TYPE + | eor CARG2, PC, #FRAME_VARG + | ldreq INS, [PC, #-4] + | bne ->BC_RETV1_Z + if (op == BC_RET1) { + | ldrd CARG12, [BASE, RA] + } + | sub CARG4, BASE, #8 + | decode_RA8 RA, INS + if (op == BC_RET1) { + | strd CARG12, [CARG4] + } + | sub BASE, CARG4, RA + | decode_RB8 RB, INS + | ldr LFUNC:CARG1, [BASE, FRAME_FUNC] + |5: + | cmp RB, RC + | bhi >6 + | ldr CARG2, LFUNC:CARG1->field_pc + | ins_next1 + | ins_next2 + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | ins_next3 + | + |6: // Fill up results with nil. + | sub CARG2, CARG4, #4 + | mvn CARG3, #~LJ_TNIL + | str CARG3, [CARG2, RC] + | add RC, RC, #8 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4] + |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12] + |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20] + |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28] + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RC = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | ldrd CARG12, [RA, BASE]! + if (op != BC_JFORL) { + | add RC, PC, RC, lsl #2 + } + if (!vk) { + | ldrd CARG34, FOR_STOP + | checktp CARG2, LJ_TISNUM + | ldr RB, FOR_TSTEP + | bne >5 + | checktp CARG4, LJ_TISNUM + | ldr CARG4, FOR_STEP + | checktpeq RB, LJ_TISNUM + | bne ->vmeta_for + | cmp CARG4, #0 + | blt >4 + | cmp CARG1, CARG3 + } else { + | ldrd CARG34, FOR_STEP + | checktp CARG2, LJ_TISNUM + | bne >5 + | adds CARG1, CARG1, CARG3 + | ldr CARG4, FOR_STOP + if (op == BC_IFORL) { + | addvs RC, PC, #0x20000 // Overflow: prevent branch. + } else { + | bvs >2 // Overflow: do not enter mcode. + } + | cmp CARG3, #0 + | blt >4 + | cmp CARG1, CARG4 + } + |1: + if (op == BC_FORI) { + | subgt PC, RC, #0x20000 + } else if (op == BC_JFORI) { + | sub PC, RC, #0x20000 + | ldrhle RC, [PC, #-2] + } else if (op == BC_IFORL) { + | suble PC, RC, #0x20000 + } + if (vk) { + | strd CARG12, FOR_IDX + } + |2: + | ins_next1 + | ins_next2 + | strd CARG12, FOR_EXT + if (op == BC_JFORI || op == BC_JFORL) { + | ble =>BC_JLOOP + } + |3: + | ins_next3 + | + |4: // Invert check for negative step. + if (!vk) { + | cmp CARG3, CARG1 + } else { + | cmp CARG4, CARG1 + } + | b <1 + | + |5: // FP loop. + if (!vk) { + | cmnlo CARG4, #-LJ_TISNUM + | cmnlo RB, #-LJ_TISNUM + | bhs ->vmeta_for + |.if FPU + | vldr d0, FOR_IDX + | vldr d1, FOR_STOP + | cmp RB, #0 + | vstr d0, FOR_EXT + |.else + | cmp RB, #0 + | strd CARG12, FOR_EXT + | blt >8 + |.endif + } else { + |.if FPU + | vldr d0, FOR_IDX + | vldr d2, FOR_STEP + | vldr d1, FOR_STOP + | cmp CARG4, #0 + | vadd.f64 d0, d0, d2 + |.else + | cmp CARG4, #0 + | blt >8 + | bl extern __aeabi_dadd + | strd CARG12, FOR_IDX + | ldrd CARG34, FOR_STOP + | strd CARG12, FOR_EXT + |.endif + } + |6: + |.if FPU + | vcmpge.f64 d0, d1 + | vcmplt.f64 d1, d0 + | vmrs + |.else + | bl extern __aeabi_cdcmple + |.endif + if (vk) { + |.if FPU + | vstr d0, FOR_IDX + | vstr d0, FOR_EXT + |.endif + } + if (op == BC_FORI) { + | subhi PC, RC, #0x20000 + } else if (op == BC_JFORI) { + | sub PC, RC, #0x20000 + | ldrhls RC, [PC, #-2] + | bls =>BC_JLOOP + } else if (op == BC_IFORL) { + | subls PC, RC, #0x20000 + } else { + | bls =>BC_JLOOP + } + | ins_next1 + | ins_next2 + | b <3 + | + |.if not FPU + |8: // Invert check for negative step. + if (vk) { + | bl extern __aeabi_dadd + | strd CARG12, FOR_IDX + | strd CARG12, FOR_EXT + } + | mov CARG3, CARG1 + | mov CARG4, CARG2 + | ldrd CARG12, FOR_STOP + | b <6 + |.endif + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RC = target + | ldrd CARG12, [RA, BASE]! + if (op == BC_JITERL) { + | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. + | strdne CARG12, [RA, #-8] + | bne =>BC_JLOOP + } else { + | add RC, PC, RC, lsl #2 + | // STALL: load CARG12. + | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. + | subne PC, RC, #0x20000 // Otherwise save control var + branch. + | strdne CARG12, [RA, #-8] + } + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RC = target (loop extent) + | // Note: RA/RC is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RC = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base (ignored), RC = traceno + | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)] + | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0. + | ldr TRACE:RC, [CARG1, RC, lsl #2] + | st_vmstate CARG2 + | ldr RA, TRACE:RC->mcode + | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)] + | str L, [DISPATCH, #DISPATCH_GL(jit_L)] + | bx RA + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RC = target + | add RC, PC, RC, lsl #2 + | sub PC, RC, #0x20000 + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 + | ldr CARG1, L->maxstack + | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)] + | ldr KBASE, [PC, #-4+PC2PROTO(k)] + | cmp RA, CARG1 + | bhi ->vm_growstack_l + if (op != BC_JFUNCF) { + | ins_next1 + | ins_next2 + } + |2: + | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters. + | mvn CARG4, #~LJ_TNIL + | blo >3 + if (op == BC_JFUNCF) { + | decode_RD RC, INS + | b =>BC_JLOOP + } else { + | ins_next3 + } + | + |3: // Clear missing parameters. + | strd CARG34, [BASE, NARGS8:RC] + | add NARGS8:RC, NARGS8:RC, #8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 + | ldr CARG1, L->maxstack + | add CARG4, BASE, RC + | add RA, RA, RC + | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC. + | add CARG2, RC, #8+FRAME_VARG + | ldr KBASE, [PC, #-4+PC2PROTO(k)] + | cmp RA, CARG1 + | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG. + | bhs ->vm_growstack_l + | ldrb RB, [PC, #-4+PC2PROTO(numparams)] + | mov RA, BASE + | mov RC, CARG4 + | cmp RB, #0 + | add BASE, CARG4, #8 + | beq >3 + | mvn CARG3, #~LJ_TNIL + |1: + | cmp RA, RC // Less args than parameters? + | ldrdlo CARG12, [RA], #8 + | movhs CARG2, CARG3 + | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC). + |2: + | subs RB, RB, #1 + | strd CARG12, [CARG4, #8]! + | bne <1 + |3: + | ins_next + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | ldr CARG4, CFUNC:CARG3->f + } else { + | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)] + } + | add CARG2, RA, NARGS8:RC + | ldr CARG1, L->maxstack + | add RC, BASE, NARGS8:RC + | str BASE, L->base + | cmp CARG2, CARG1 + | str RC, L->top + if (op == BC_FUNCCW) { + | ldr CARG2, CFUNC:CARG3->f + } + | mv_vmstate CARG3, C + | mov CARG1, L + | bhi ->vm_growstack_c // Need to grow stack. + | st_vmstate CARG3 + | blx CARG4 // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | ldr BASE, L->base + | mv_vmstate CARG3, INTERP + | ldr CRET2, L->top + | lsl RC, CRET1, #3 + | st_vmstate CARG3 + | ldr PC, [BASE, FRAME_PC] + | sub RA, CRET2, RC // RA = L->top - nresults*8 + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 0xe\n" /* Return address is in lr. */ + "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */ + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */ + fcofs, CFRAME_SIZE); + for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */ + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i)); +#if LJ_ARCH_HASFPU + for (i = 15; i >= 8; i--) /* offset d8-d15 */ + fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n", + 64+2*i, 10+2*(15-i)); + fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */ +#endif + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" + "\t.long lj_vm_ffi_call\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */ + "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */ + "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */ + "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */ + "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */ + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + default: + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_mips.dasc b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_mips.dasc new file mode 100644 index 0000000..0ec13e6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_mips.dasc @@ -0,0 +1,4241 @@ +|// Low-level VM code for MIPS CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch mips +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r16 // Base of current Lua stack frame. +|.define KBASE, r17 // Constants of current Lua function. +|.define PC, r18 // Next PC. +|.define DISPATCH, r19 // Opcode dispatch table. +|.define LREG, r20 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r21 // Size of multi-result: (nresults+1)*8. +|// NYI: r22 currently unused. +| +|.define JGL, r30 // On-trace: global_State + 32768. +| +|// Constants for type-comparisons, stores and conversions. C callee-save. +|.define TISNIL, r30 +|.define TOBIT, f30 // 2^52 + 2^51. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r23 // Callee-save. +|.define RB, r8 +|.define RC, r9 +|.define RD, r10 +|.define INS, r11 +| +|.define AT, r1 // Assembler temporary. +|.define TMP0, r12 +|.define TMP1, r13 +|.define TMP2, r14 +|.define TMP3, r15 +| +|// Calling conventions. +|.define CFUNCADDR, r25 +|.define CARG1, r4 +|.define CARG2, r5 +|.define CARG3, r6 +|.define CARG4, r7 +| +|.define CRET1, r2 +|.define CRET2, r3 +| +|.define FARG1, f12 +|.define FARG2, f14 +| +|.define FRET1, f0 +|.define FRET2, f2 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define CFRAME_SPACE, 112 // Delta for sp. +| +|.define SAVE_ERRF, 124(sp) // 32 bit C frame info. +|.define SAVE_NRES, 120(sp) +|.define SAVE_CFRAME, 116(sp) +|.define SAVE_L, 112(sp) +|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter. +|.define SAVE_GPR_, 72 // .. 72+10*4: 32 bit GPR saves. +|.define SAVE_FPR_, 24 // .. 24+6*8: 64 bit FPR saves. +|.define SAVE_PC, 20(sp) +|.define ARG5, 16(sp) +|.define CSAVE_4, 12(sp) +|.define CSAVE_3, 8(sp) +|.define CSAVE_2, 4(sp) +|.define CSAVE_1, 0(sp) +|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee. +| +|.define ARG5_OFS, 16 +|.define SAVE_MULTRES, ARG5 +| +|.macro saveregs +| addiu sp, sp, -CFRAME_SPACE +| sw ra, SAVE_GPR_+9*4(sp) +| sw r30, SAVE_GPR_+8*4(sp) +| sdc1 f30, SAVE_FPR_+5*8(sp) +| sw r23, SAVE_GPR_+7*4(sp) +| sw r22, SAVE_GPR_+6*4(sp) +| sdc1 f28, SAVE_FPR_+4*8(sp) +| sw r21, SAVE_GPR_+5*4(sp) +| sw r20, SAVE_GPR_+4*4(sp) +| sdc1 f26, SAVE_FPR_+3*8(sp) +| sw r19, SAVE_GPR_+3*4(sp) +| sw r18, SAVE_GPR_+2*4(sp) +| sdc1 f24, SAVE_FPR_+2*8(sp) +| sw r17, SAVE_GPR_+1*4(sp) +| sw r16, SAVE_GPR_+0*4(sp) +| sdc1 f22, SAVE_FPR_+1*8(sp) +| sdc1 f20, SAVE_FPR_+0*8(sp) +|.endmacro +| +|.macro restoreregs_ret +| lw ra, SAVE_GPR_+9*4(sp) +| lw r30, SAVE_GPR_+8*4(sp) +| ldc1 f30, SAVE_FPR_+5*8(sp) +| lw r23, SAVE_GPR_+7*4(sp) +| lw r22, SAVE_GPR_+6*4(sp) +| ldc1 f28, SAVE_FPR_+4*8(sp) +| lw r21, SAVE_GPR_+5*4(sp) +| lw r20, SAVE_GPR_+4*4(sp) +| ldc1 f26, SAVE_FPR_+3*8(sp) +| lw r19, SAVE_GPR_+3*4(sp) +| lw r18, SAVE_GPR_+2*4(sp) +| ldc1 f24, SAVE_FPR_+2*8(sp) +| lw r17, SAVE_GPR_+1*4(sp) +| lw r16, SAVE_GPR_+0*4(sp) +| ldc1 f22, SAVE_FPR_+1*8(sp) +| ldc1 f20, SAVE_FPR_+0*8(sp) +| jr ra +| addiu sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// Trap for not-yet-implemented parts. +|.macro NYI; .long 0xf0f0f0f0; .endmacro +| +|// Macros to mark delay slots. +|.macro ., a; a; .endmacro +|.macro ., a,b; a,b; .endmacro +|.macro ., a,b,c; a,b,c; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Endian-specific defines. +|.define FRAME_PC, LJ_ENDIAN_SELECT(-4,-8) +|.define FRAME_FUNC, LJ_ENDIAN_SELECT(-8,-4) +|.define HI, LJ_ENDIAN_SELECT(4,0) +|.define LO, LJ_ENDIAN_SELECT(0,4) +|.define OFS_RD, LJ_ENDIAN_SELECT(2,0) +|.define OFS_RA, LJ_ENDIAN_SELECT(1,2) +|.define OFS_OP, LJ_ENDIAN_SELECT(0,3) +| +|// Instruction decode. +|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro +|.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro +|.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro +|.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro +|.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro +|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro +|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro +|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro +|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro +|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro +|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro +|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro +|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lw INS, 0(PC) +| addiu PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT2 +| decode_OP4a TMP1, INS +| decode_OP4b TMP1 +| addu TMP0, DISPATCH, TMP1 +| decode_RD8a RD, INS +| lw AT, 0(TMP0) +| decode_RA8a RA, INS +| decode_RD8b RD +| jr AT +| decode_RA8b RA +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lw PC, LFUNC:RB->pc +| lw INS, 0(PC) +| addiu PC, PC, 4 +| decode_OP4a TMP1, INS +| decode_RA8a RA, INS +| decode_OP4b TMP1 +| decode_RA8b RA +| addu TMP0, DISPATCH, TMP1 +| lw TMP0, 0(TMP0) +| jr TMP0 +| addu RA, RA, BASE +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| sw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|.macro branch_RD +| srl TMP0, RD, 1 +| lui AT, (-(BCBIAS_J*4 >> 16) & 65535) +| addu TMP0, TMP0, AT +| addu PC, PC, TMP0 +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +#define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch)) +#define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro load_got, func +| lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH) +|.endmacro +|// Much faster. Sadly, there's no easy way to force the required code layout. +|// .macro call_intern, func; bal extern func; .endmacro +|.macro call_intern, func; jalr CFUNCADDR; .endmacro +|.macro call_extern; jalr CFUNCADDR; .endmacro +|.macro jmp_extern; jr CFUNCADDR; .endmacro +| +|.macro hotcheck, delta, target +| srl TMP1, PC, 1 +| andi TMP1, TMP1, 126 +| addu TMP1, TMP1, DISPATCH +| lhu TMP2, GG_DISP2HOT(TMP1) +| addiu TMP2, TMP2, -delta +| bltz TMP2, target +|. sh TMP2, GG_DISP2HOT(TMP1) +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP, ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL, ->vm_hotcall +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp, target +| lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| andi mark, mark, ~LJ_GC_BLACK & 255 // black2gray(tab) +| sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| sb mark, tab->marked +| b target +|. sw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andi AT, PC, FRAME_P + | beqz AT, ->cont_dispatch + |. li TMP1, LJ_TTRUE + | + | // Return from pcall or xpcall fast func. + | lw PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | move BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | sw TMP1, FRAME_PC(RA) // Prepend true to results. + | addiu RA, RA, -8 + | + |->vm_returnc: + | addiu RD, RD, 8 // RD = (nresults+1)*8. + | andi TMP0, PC, FRAME_TYPE + | beqz RD, ->vm_unwind_c_eh + |. li CRET1, LUA_YIELD + | beqz TMP0, ->BC_RET_Z // Handle regular return to Lua. + |. move MULTRES, RD + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | li TMP2, -8 + | xori AT, TMP0, FRAME_C + | and TMP2, PC, TMP2 + | bnez AT, ->vm_returnp + | subu TMP2, BASE, TMP2 // TMP2 = previous base. + | + | addiu TMP1, RD, -8 + | sw TMP2, L->base + | li_vmstate C + | lw TMP2, SAVE_NRES + | addiu BASE, BASE, -8 + | st_vmstate + | beqz TMP1, >2 + |. sll TMP2, TMP2, 3 + |1: + | addiu TMP1, TMP1, -8 + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | sdc1 f0, 0(BASE) + | bnez TMP1, <1 + |. addiu BASE, BASE, 8 + | + |2: + | bne TMP2, RD, >6 + |3: + |. sw BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lw TMP0, SAVE_CFRAME // Restore previous C frame. + | move CRET1, r0 // Ok return status for vm_pcall. + | sw TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs_ret + | + |6: + | lw TMP1, L->maxstack + | slt AT, TMP2, RD + | bnez AT, >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + |. slt AT, BASE, TMP1 + | beqz AT, >8 + |. nop + | sw TISNIL, HI(BASE) + | addiu RD, RD, 8 + | b <2 + |. addiu BASE, BASE, 8 + | + |7: // Less results wanted. + | subu TMP0, RD, TMP2 + | subu TMP0, BASE, TMP0 // Either keep top or shrink it. + | b <3 + |. movn BASE, TMP0, TMP2 // LUA_MULTRET+1 case? + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | load_got lj_state_growstack + | move MULTRES, RD + | move CARG2, TMP2 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw TMP2, SAVE_NRES + | lw BASE, L->top // Need the (realloced) L->top in BASE. + | move RD, MULTRES + | b <2 + |. sll TMP2, TMP2, 3 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | move sp, CARG1 + | move CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lw L, SAVE_L + | li TMP0, ~LJ_VMST_C + | lw GL:TMP1, L->glref + | b ->vm_leave_unw + |. sw TMP0, GL:TMP1->vmstate + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | li AT, -4 + | and sp, CARG1, AT + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lw L, SAVE_L + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | li TISNIL, LJ_TNIL + | lw BASE, L->base + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | mtc1 TMP3, TOBIT + | li TMP1, LJ_TFALSE + | li_vmstate INTERP + | lw PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | cvt.d.s TOBIT, TOBIT + | addiu RA, BASE, -8 // Results start at BASE-8. + | addiu DISPATCH, DISPATCH, GG_G2DISP + | sw TMP1, HI(RA) // Prepend false to error message. + | st_vmstate + | b ->vm_returnc + |. li RD, 16 // 2 results: false + error message. + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | b >2 + |. li CARG2, LUA_MINSTACK + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | addu RC, BASE, RC + | subu RA, RA, BASE + | sw BASE, L->base + | addiu PC, PC, 4 // Must point after first instruction. + | sw RC, L->top + | srl CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | load_got lj_state_growstack + | sw PC, SAVE_PC + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw BASE, L->base + | lw RC, L->top + | lw LFUNC:RB, FRAME_FUNC(BASE) + | subu RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | move L, CARG1 + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | move BASE, CARG2 + | lbu TMP1, L->status + | sw L, SAVE_L + | li PC, FRAME_CP + | addiu TMP0, sp, CFRAME_RESUME + | addiu DISPATCH, DISPATCH, GG_G2DISP + | sw r0, SAVE_NRES + | sw r0, SAVE_ERRF + | sw TMP0, L->cframe + | sw r0, SAVE_CFRAME + | beqz TMP1, >3 + |. sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | + | // Resume after yield (like a return). + | move RA, BASE + | lw BASE, L->base + | lw TMP1, L->top + | lw PC, FRAME_PC(BASE) + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | subu RD, TMP1, BASE + | mtc1 TMP3, TOBIT + | sb r0, L->status + | cvt.d.s TOBIT, TOBIT + | li_vmstate INTERP + | addiu RD, RD, 8 + | st_vmstate + | move MULTRES, RD + | andi TMP0, PC, FRAME_TYPE + | beqz TMP0, ->BC_RET_Z + |. li TISNIL, LJ_TNIL + | b ->vm_return + |. nop + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | sw CARG4, SAVE_ERRF + | b >1 + |. li PC, FRAME_CP + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lw TMP1, L:CARG1->cframe + | sw CARG3, SAVE_NRES + | move L, CARG1 + | sw CARG1, SAVE_L + | move BASE, CARG2 + | sw sp, L->cframe // Add our C frame to cframe chain. + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sw TMP1, SAVE_CFRAME + | addiu DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lw TMP2, L->base // TMP2 = old base (used in vmeta_call). + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lw TMP1, L->top + | mtc1 TMP3, TOBIT + | addu PC, PC, BASE + | subu NARGS8:RC, TMP1, BASE + | subu PC, PC, TMP2 // PC = frame delta + frame type + | cvt.d.s TOBIT, TOBIT + | li_vmstate INTERP + | li TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | lw TMP0, FRAME_PC(BASE) + | li AT, LJ_TFUNC + | bne TMP0, AT, ->vmeta_call + |. lw LFUNC:RB, FRAME_FUNC(BASE) + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | move L, CARG1 + | lw TMP0, L:CARG1->stack + | sw CARG1, SAVE_L + | lw TMP1, L->top + | sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | subu TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lw TMP1, L->cframe + | sw sp, L->cframe // Add our C frame to cframe chain. + | sw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | sw r0, SAVE_ERRF // No error function. + | move CFUNCADDR, CARG4 + | jalr CARG4 // (lua_State *L, lua_CFunction func, void *ud) + |. sw TMP1, SAVE_CFRAME + | move BASE, CRET1 + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | bnez CRET1, <3 // Else continue with the call. + |. addiu DISPATCH, DISPATCH, GG_G2DISP + | b ->vm_leave_cp // No base? Just remove C frame. + |. nop + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lw TMP0, -16+LO(BASE) // Continuation. + | move RB, BASE + | move BASE, TMP2 // Restore caller BASE. + | lw LFUNC:TMP1, FRAME_FUNC(TMP2) + |.if FFI + | sltiu AT, TMP0, 2 + |.endif + | lw PC, -16+HI(RB) // Restore PC from [cont|PC]. + | addu TMP2, RA, RD + | lw TMP1, LFUNC:TMP1->pc + |.if FFI + | bnez AT, >1 + |.endif + |. sw TISNIL, -8+HI(TMP2) // Ensure one valid arg. + | // BASE = base, RA = resultptr, RB = meta base + | jr TMP0 // Jump to continuation. + |. lw KBASE, PC2PROTO(k)(TMP1) + | + |.if FFI + |1: + | bnez TMP0, ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + |. addiu TMP1, RB, -16 + | b ->vm_call_tail + |. subu RC, TMP1, BASE + |.endif + | + |->cont_cat: // RA = resultptr, RB = meta base + | lw INS, -4(PC) + | addiu CARG2, RB, -16 + | ldc1 f0, 0(RA) + | decode_RB8a MULTRES, INS + | decode_RA8a RA, INS + | decode_RB8b MULTRES + | decode_RA8b RA + | addu TMP1, BASE, MULTRES + | sw BASE, L->base + | subu CARG3, CARG2, TMP1 + | bne TMP1, CARG2, ->BC_CAT_Z + |. sdc1 f0, 0(CARG2) + | addu RA, BASE, RA + | b ->cont_nop + |. sdc1 f0, 0(RA) + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP0, HI(CARG3) + | + |->vmeta_tgets: + | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TTAB + | sw TAB:RB, LO(CARG2) + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2) + | sw TMP0, HI(CARG2) + | li TMP1, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP1, HI(CARG3) + | + |->vmeta_tgetb: // TMP0 = index + | mtc1 TMP0, f0 + | cvt.d.w f0, f0 + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | sdc1 f0, 0(CARG3) + | + |->vmeta_tgetv: + |1: + | load_got lj_meta_tget + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + |. move CARG1, L + | // Returns TValue * (finished) or NULL (metamethod). + | beqz CRET1, >3 + |. addiu TMP1, BASE, -FRAME_CONT + | ldc1 f0, 0(CRET1) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | lw BASE, L->top + | sw PC, -16+HI(BASE) // [cont|PC] + | subu PC, BASE, TMP1 + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + |. li NARGS8:RC, 16 // 2 args for func(t, k). + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP0, HI(CARG3) + | + |->vmeta_tsets: + | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TTAB + | sw TAB:RB, LO(CARG2) + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2) + | sw TMP0, HI(CARG2) + | li TMP1, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP1, HI(CARG3) + | + |->vmeta_tsetb: // TMP0 = index + | mtc1 TMP0, f0 + | cvt.d.w f0, f0 + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | sdc1 f0, 0(CARG3) + | + |->vmeta_tsetv: + |1: + | load_got lj_meta_tset + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + |. move CARG1, L + | // Returns TValue * (finished) or NULL (metamethod). + | beqz CRET1, >3 + |. ldc1 f0, 0(RA) + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | ins_next1 + | sdc1 f0, 0(CRET1) + | ins_next2 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | addiu TMP1, BASE, -FRAME_CONT + | lw BASE, L->top + | sw PC, -16+HI(BASE) // [cont|PC] + | subu PC, BASE, TMP1 + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | sdc1 f0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + |. li NARGS8:RC, 24 // 3 args for func(t, k, v) + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | // CARG2, CARG3 are already set by BC_ISLT/BC_ISGE/BC_ISLE/BC_ISGT. + | load_got lj_meta_comp + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | decode_OP1 CARG4, INS + | call_intern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + |3: + | sltiu AT, CRET1, 2 + | beqz AT, ->vmeta_binop + | negu TMP2, CRET1 + |4: + | lhu RD, OFS_RD(PC) + | addiu PC, PC, 4 + | lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535) + | sll RD, RD, 2 + | addu RD, RD, TMP1 + | and RD, RD, TMP2 + | addu PC, PC, RD + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lbu TMP1, -4+OFS_RA(PC) + | ldc1 f0, 0(RA) + | sll TMP1, TMP1, 3 + | addu TMP1, BASE, TMP1 + | b ->cont_nop + |. sdc1 f0, 0(TMP1) + | + |->cont_condt: // RA = resultptr + | lw TMP0, HI(RA) + | sltiu AT, TMP0, LJ_TISTRUECOND + | b <4 + |. negu TMP2, AT // Branch if result is true. + | + |->cont_condf: // RA = resultptr + | lw TMP0, HI(RA) + | sltiu AT, TMP0, LJ_TISTRUECOND + | b <4 + |. addiu TMP2, AT, -1 // Branch if result is false. + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | load_got lj_meta_equal + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |. nop + | + |->vmeta_equal_cd: + |.if FFI + | load_got lj_meta_equal_cd + | move CARG2, INS + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_equal_cd // (lua_State *L, BCIns op) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |. nop + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_unm: + | move CARG4, CARG3 + | + |->vmeta_arith: + | load_got lj_meta_arith + | decode_OP1 TMP0, INS + | sw BASE, L->base + | sw PC, SAVE_PC + | move CARG2, RA + | sw TMP0, ARG5 + | call_intern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + |. move CARG1, L + | // Returns NULL (finished) or TValue * (metamethod). + | beqz CRET1, ->cont_nop + |. nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | subu TMP1, CRET1, BASE + | sw PC, -16+HI(CRET1) // [cont|PC] + | move TMP2, BASE + | addiu PC, TMP1, FRAME_CONT + | move BASE, CRET1 + | b ->vm_call_dispatch + |. li NARGS8:RC, 16 // 2 args for func(o1, o2). + | + |->vmeta_len: + | // CARG2 already set by BC_LEN. +#if LJ_52 + | move MULTRES, CARG1 +#endif + | load_got lj_meta_len + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_len // (lua_State *L, TValue *o) + |. move CARG1, L + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | bnez CRET1, ->vmeta_binop // Binop call for compatibility. + |. nop + | b ->BC_LEN_Z + |. move CARG1, MULTRES +#else + | b ->vmeta_binop // Binop call for compatibility. + |. nop +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | load_got lj_meta_call + | sw TMP2, L->base // This is the callers base! + | addiu CARG2, BASE, -8 + | sw PC, SAVE_PC + | addu CARG3, BASE, RC + | move MULTRES, NARGS8:RC + | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + |. move CARG1, L + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addiu NARGS8:RC, MULTRES, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | load_got lj_meta_call + | sw BASE, L->base + | addiu CARG2, RA, -8 + | sw PC, SAVE_PC + | addu CARG3, RA, RC + | move MULTRES, NARGS8:RC + | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + |. move CARG1, L + | lw TMP1, FRAME_PC(BASE) + | lw LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + |. addiu NARGS8:RC, MULTRES, 8 // Got one more argument now. + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | load_got lj_meta_for + | sw BASE, L->base + | move CARG2, RA + | sw PC, SAVE_PC + | move MULTRES, INS + | call_intern lj_meta_for // (lua_State *L, TValue *base) + |. move CARG1, L + |.if JIT + | decode_OP1 TMP0, MULTRES + | li AT, BC_JFORI + |.endif + | decode_RA8a RA, MULTRES + | decode_RD8a RD, MULTRES + | decode_RA8b RA + |.if JIT + | beq TMP0, AT, =>BC_JFORI + |. decode_RD8b RD + | b =>BC_FORI + |. nop + |.else + | b =>BC_FORI + |. decode_RD8b RD + |.endif + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | beqz NARGS8:RC, ->fff_fallback + |. lw CARG3, HI(BASE) + | lw CARG1, LO(BASE) + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | bnez AT, ->fff_fallback + |. lw CARG4, 8+HI(BASE) + | lw CARG1, LO(BASE) + | lw CARG2, 8+LO(BASE) + |.endmacro + | + |.macro .ffunc_n, name // Caveat: has delay slot! + |->ff_ .. name: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. ldc1 FARG1, 0(BASE) + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name // Caveat: has delay slot! + |->ff_ .. name: + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | bnez AT, ->fff_fallback + |. lw CARG4, 8+HI(BASE) + | ldc1 FARG1, 0(BASE) + | ldc1 FARG2, 8(BASE) + | sltiu TMP0, CARG3, LJ_TISNUM + | sltiu TMP1, CARG4, LJ_TISNUM + | and TMP0, TMP0, TMP1 + | beqz TMP0, ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot! + |.macro ffgccheck + | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | subu AT, TMP0, TMP1 + | bgezal AT, ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | sltiu AT, CARG3, LJ_TISTRUECOND + | beqz AT, ->fff_fallback + |. addiu RA, BASE, -8 + | lw PC, FRAME_PC(BASE) + | addiu RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | addu TMP2, RA, NARGS8:RC + | sw CARG3, HI(RA) + | addiu TMP1, BASE, 8 + | beq BASE, TMP2, ->fff_res // Done if exactly 1 argument. + |. sw CARG1, LO(RA) + |1: + | ldc1 f0, 0(TMP1) + | sdc1 f0, -8(TMP1) + | bne TMP1, TMP2, <1 + |. addiu TMP1, TMP1, 8 + | b ->fff_res + |. nop + | + |.ffunc type + | lw CARG3, HI(BASE) + | li TMP1, LJ_TISNUM + | beqz NARGS8:RC, ->fff_fallback + |. sltiu TMP0, CARG3, LJ_TISNUM + | movz TMP1, CARG3, TMP0 + | not TMP1, TMP1 + | sll TMP1, TMP1, 3 + | addu TMP1, CFUNC:RB, TMP1 + | b ->fff_resn + |. ldc1 FRET1, CFUNC:TMP1->upvalue + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | li AT, LJ_TTAB + | bne CARG3, AT, >6 + |. li AT, LJ_TUDATA + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lw TAB:CARG1, TAB:CARG1->metatable + |2: + | lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beqz TAB:CARG1, ->fff_restv + |. li CARG3, LJ_TNIL + | lw TMP0, TAB:CARG1->hmask + | li CARG3, LJ_TTAB // Use metatable as default result. + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:CARG1->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + | li AT, LJ_TSTR + |3: // Rearranged logic, because we expect _not_ to find the key. + | lw CARG4, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | lw NODE:TMP3, NODE:TMP2->next + | bne CARG4, AT, >4 + |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | beq TMP0, STR:RC, >5 + |. lw TMP1, offsetof(Node, val)+LO(NODE:TMP2) + |4: + | beqz NODE:TMP3, ->fff_restv // Not found, keep default result. + |. move NODE:TMP2, NODE:TMP3 + | b <3 + |. nop + |5: + | beq CARG2, TISNIL, ->fff_restv // Ditto for nil value. + |. nop + | move CARG3, CARG2 // Return value of mt.__metatable. + | b ->fff_restv + |. move CARG1, TMP1 + | + |6: + | beq CARG3, AT, <1 + |. sltiu TMP0, CARG3, LJ_TISNUM + | li TMP1, LJ_TISNUM + | movz TMP1, CARG3, TMP0 + | not TMP1, TMP1 + | sll TMP1, TMP1, 2 + | addu TMP1, DISPATCH, TMP1 + | b <2 + |. lw TAB:CARG1, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1) + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. addiu CARG4, CARG4, -LJ_TTAB + | lw TAB:TMP1, TAB:CARG1->metatable + | lbu TMP3, TAB:CARG1->marked + | or AT, CARG4, TAB:TMP1 + | bnez AT, ->fff_fallback + |. andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | beqz AT, ->fff_restv + |. sw TAB:CARG2, TAB:CARG1->metatable + | barrierback TAB:CARG1, TMP3, TMP0, ->fff_restv + | + |.ffunc rawget + | lw CARG4, HI(BASE) + | sltiu AT, NARGS8:RC, 16 + | lw TAB:CARG2, LO(BASE) + | load_got lj_tab_get + | addiu CARG4, CARG4, -LJ_TTAB + | or AT, AT, CARG4 + | bnez AT, ->fff_fallback + | addiu CARG3, BASE, 8 + | call_intern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + |. move CARG1, L + | // Returns cTValue *. + | b ->fff_resn + |. ldc1 FRET1, 0(CRET1) + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | lw CARG1, HI(BASE) + | xori AT, NARGS8:RC, 8 + | sltiu CARG1, CARG1, LJ_TISNUM + | movn CARG1, r0, AT + | beqz CARG1, ->fff_fallback // Exactly one number argument. + |. ldc1 FRET1, 0(BASE) + | b ->fff_resn + |. nop + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | li AT, LJ_TSTR + | // A __tostring method in the string base metatable is ignored. + | beq CARG3, AT, ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + |. lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | sltiu TMP0, CARG3, LJ_TISNUM + | sltiu TMP1, TMP1, 1 + | and TMP0, TMP0, TMP1 + | beqz TMP0, ->fff_fallback + |. sw BASE, L->base // Add frame since C call can throw. + | ffgccheck + |. sw PC, SAVE_PC // Redundant (but a defined value). + | load_got lj_str_fromnum + | move CARG1, L + | call_intern lj_str_fromnum // (lua_State *L, lua_Number *np) + |. move CARG2, BASE + | // Returns GCstr *. + | li CARG3, LJ_TSTR + | b ->fff_restv + |. move CARG1, CRET1 + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | lw CARG1, HI(BASE) + | lw TAB:CARG2, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. addu TMP2, BASE, NARGS8:RC + | li AT, LJ_TTAB + | sw TISNIL, HI(TMP2) // Set missing 2nd arg to nil. + | bne CARG1, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) + | load_got lj_tab_next + | sw BASE, L->base // Add frame since C call can throw. + | sw BASE, L->top // Dummy frame length is ok. + | addiu CARG3, BASE, 8 + | sw PC, SAVE_PC + | call_intern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + |. move CARG1, L + | // Returns 0 at end of traversal. + | beqz CRET1, ->fff_restv // End of traversal: return nil. + |. li CARG3, LJ_TNIL + | ldc1 f0, 8(BASE) // Copy key and value to results. + | addiu RA, BASE, -8 + | ldc1 f2, 16(BASE) + | li RD, (2+1)*8 + | sdc1 f0, 0(RA) + | b ->fff_res + |. sdc1 f2, 8(RA) + | + |.ffunc_1 pairs + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | ldc1 f0, CFUNC:RB->upvalue[0] + | bnez TAB:TMP2, ->fff_fallback +#else + | ldc1 f0, CFUNC:RB->upvalue[0] +#endif + |. addiu RA, BASE, -8 + | sw TISNIL, 8+HI(BASE) + | li RD, (3+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |.ffunc ipairs_aux + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | lw TAB:CARG1, LO(BASE) + | lw CARG4, 8+HI(BASE) + | bnez AT, ->fff_fallback + |. ldc1 FARG2, 8(BASE) + | addiu CARG3, CARG3, -LJ_TTAB + | sltiu AT, CARG4, LJ_TISNUM + | li TMP0, 1 + | movn AT, r0, CARG3 + | mtc1 TMP0, FARG1 + | beqz AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) + | cvt.w.d FRET1, FARG2 + | cvt.d.w FARG1, FARG1 + | lw TMP0, TAB:CARG1->asize + | lw TMP1, TAB:CARG1->array + | mfc1 TMP2, FRET1 + | addiu RA, BASE, -8 + | add.d FARG2, FARG2, FARG1 + | addiu TMP2, TMP2, 1 + | sltu AT, TMP2, TMP0 + | sll TMP3, TMP2, 3 + | addu TMP3, TMP1, TMP3 + | beqz AT, >2 // Not in array part? + |. sdc1 FARG2, 0(RA) + | lw TMP2, HI(TMP3) + | ldc1 f0, 0(TMP3) + |1: + | beq TMP2, TISNIL, ->fff_res // End of iteration, return 0 results. + |. li RD, (0+1)*8 + | li RD, (2+1)*8 + | b ->fff_res + |. sdc1 f0, 8(RA) + |2: // Check for empty hash part first. Otherwise call C function. + | lw TMP0, TAB:CARG1->hmask + | load_got lj_tab_getinth + | beqz TMP0, ->fff_res + |. li RD, (0+1)*8 + | call_intern lj_tab_getinth // (GCtab *t, int32_t key) + |. move CARG2, TMP2 + | // Returns cTValue * or NULL. + | beqz CRET1, ->fff_res + |. li RD, (0+1)*8 + | lw TMP2, HI(CRET1) + | b <1 + |. ldc1 f0, 0(CRET1) + | + |.ffunc_1 ipairs + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | ldc1 f0, CFUNC:RB->upvalue[0] + | bnez TAB:TMP2, ->fff_fallback +#else + | ldc1 f0, CFUNC:RB->upvalue[0] +#endif + |. addiu RA, BASE, -8 + | sw r0, 8+HI(BASE) + | sw r0, 8+LO(BASE) + | li RD, (3+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | beqz NARGS8:RC, ->fff_fallback + | move TMP2, BASE + | addiu BASE, BASE, 8 + | // Remember active hook before pcall. + | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT + | andi TMP3, TMP3, 1 + | addiu PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + |. addiu NARGS8:RC, NARGS8:RC, -8 + | + |.ffunc xpcall + | sltiu AT, NARGS8:RC, 16 + | lw CARG4, 8+HI(BASE) + | bnez AT, ->fff_fallback + |. ldc1 FARG2, 8(BASE) + | ldc1 FARG1, 0(BASE) + | lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH) + | li AT, LJ_TFUNC + | move TMP2, BASE + | bne CARG4, AT, ->fff_fallback // Traceback must be a function. + | addiu BASE, BASE, 16 + | // Remember active hook before pcall. + | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT + | sdc1 FARG2, 0(TMP2) // Swap function and traceback. + | andi TMP3, TMP3, 1 + | sdc1 FARG1, 8(TMP2) + | addiu PC, TMP3, 16+FRAME_PCALL + | b ->vm_call_dispatch + |. addiu NARGS8:RC, NARGS8:RC, -16 + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | li AT, LJ_TTHREAD + | bne CARG3, AT, ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | lw L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + | lbu TMP0, L:CARG1->status + | lw TMP1, L:CARG1->cframe + | lw CARG2, L:CARG1->top + | lw TMP2, L:CARG1->base + | addiu TMP3, TMP0, -LUA_YIELD + | bgtz TMP3, ->fff_fallback // st > LUA_YIELD? + |. xor TMP2, TMP2, CARG2 + | bnez TMP1, ->fff_fallback // cframe != 0? + |. or AT, TMP2, TMP0 + | lw TMP0, L:CARG1->maxstack + | beqz AT, ->fff_fallback // base == top && st == 0? + |. lw PC, FRAME_PC(BASE) + | addu TMP2, CARG2, NARGS8:RC + | sltu AT, TMP0, TMP2 + | bnez AT, ->fff_fallback // Stack overflow? + |. sw PC, SAVE_PC + | sw BASE, L->base + |1: + |.if resume + | addiu BASE, BASE, 8 // Keep resumed thread in stack for GC. + | addiu NARGS8:RC, NARGS8:RC, -8 + | addiu TMP2, TMP2, -8 + |.endif + | sw TMP2, L:CARG1->top + | addu TMP1, BASE, NARGS8:RC + | move CARG3, CARG2 + | sw BASE, L->top + |2: // Move args to coroutine. + | ldc1 f0, 0(BASE) + | sltu AT, BASE, TMP1 + | beqz AT, >3 + |. addiu BASE, BASE, 8 + | sdc1 f0, 0(CARG3) + | b <2 + |. addiu CARG3, CARG3, 8 + |3: + | bal ->vm_resume // (lua_State *L, TValue *base, 0, 0) + |. move L:RA, L:CARG1 + | // Returns thread status. + |4: + | lw TMP2, L:RA->base + | sltiu AT, CRET1, LUA_YIELD+1 + | lw TMP3, L:RA->top + | li_vmstate INTERP + | lw BASE, L->base + | st_vmstate + | beqz AT, >8 + |. subu RD, TMP3, TMP2 + | lw TMP0, L->maxstack + | beqz RD, >6 // No results? + |. addu TMP1, BASE, RD + | sltu AT, TMP0, TMP1 + | bnez AT, >9 // Need to grow stack? + |. addu TMP3, TMP2, RD + | sw TMP2, L:RA->top // Clear coroutine stack. + | move TMP1, BASE + |5: // Move results from coroutine. + | ldc1 f0, 0(TMP2) + | addiu TMP2, TMP2, 8 + | sltu AT, TMP2, TMP3 + | sdc1 f0, 0(TMP1) + | bnez AT, <5 + |. addiu TMP1, TMP1, 8 + |6: + | andi TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | addiu RA, BASE, -8 + | sw TMP1, -8+HI(BASE) // Prepend true to results. + | addiu RD, RD, 16 + |.else + | move RA, BASE + | addiu RD, RD, 8 + |.endif + |7: + | sw PC, SAVE_PC + | beqz TMP0, ->BC_RET_Z + |. move MULTRES, RD + | b ->vm_return + |. nop + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | addiu TMP3, TMP3, -8 + | li TMP1, LJ_TFALSE + | ldc1 f0, 0(TMP3) + | sw TMP3, L:RA->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | sw TMP1, -8+HI(BASE) // Prepend false to results. + | addiu RA, BASE, -8 + | sdc1 f0, 0(BASE) // Copy error message. + | b <7 + |. andi TMP0, PC, FRAME_TYPE + |.else + | load_got lj_ffh_coroutine_wrap_err + | move CARG2, L:RA + | call_intern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |. move CARG1, L + |.endif + | + |9: // Handle stack expansion on return from yield. + | load_got lj_state_growstack + | srl CARG2, RD, 3 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | b <4 + |. li CRET1, 0 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lw TMP0, L->cframe + | addu TMP1, BASE, NARGS8:RC + | sw BASE, L->base + | andi TMP0, TMP0, CFRAME_RESUME + | sw TMP1, L->top + | beqz TMP0, ->fff_fallback + |. li CRET1, LUA_YIELD + | sw r0, L->cframe + | b ->vm_leave_unw + |. sb CRET1, L->status + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_n math_abs + |. abs.d FRET1, FARG1 + |->fff_resn: + | lw PC, FRAME_PC(BASE) + | addiu RA, BASE, -8 + | b ->fff_res1 + |. sdc1 FRET1, -8(BASE) + | + |->fff_restv: + | // CARG3/CARG1 = TValue result. + | lw PC, FRAME_PC(BASE) + | sw CARG3, -8+HI(BASE) + | addiu RA, BASE, -8 + | sw CARG1, -8+LO(BASE) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->vm_return + |. move MULTRES, RD + | lw INS, -4(PC) + | decode_RB8a RB, INS + | decode_RB8b RB + |5: + | sltu AT, RD, RB + | bnez AT, >6 // More results expected? + |. decode_RA8a TMP0, INS + | decode_RA8b TMP0 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | subu BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | addu TMP1, RA, RD + | addiu RD, RD, 8 + | b <5 + |. sw TISNIL, -8+HI(TMP1) + | + |.macro math_extern, func + |->ff_math_ .. func: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. load_got func + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. nop + | call_extern + |. ldc1 FARG1, 0(BASE) + | b ->fff_resn + |. nop + |.endmacro + | + |.macro math_extern2, func + | .ffunc_nn math_ .. func + |. load_got func + | call_extern + |. nop + | b ->fff_resn + |. nop + |.endmacro + | + |.macro math_round, func + | .ffunc_n math_ .. func + |. nop + | bal ->vm_ .. func + |. nop + | b ->fff_resn + |. nop + |.endmacro + | + | math_round floor + | math_round ceil + | + |.ffunc math_log + | lw CARG3, HI(BASE) + | li AT, 8 + | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument. + |. load_got log + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. nop + | call_extern + |. ldc1 FARG1, 0(BASE) + | b ->fff_resn + |. nop + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |.ffunc_n math_sqrt + |. sqrt.d FRET1, FARG1 + | b ->fff_resn + |. nop + | + |->ff_math_deg: + |.ffunc_n math_rad + |. ldc1 FARG2, CFUNC:RB->upvalue[0] + | b ->fff_resn + |. mul.d FRET1, FARG1, FARG2 + | + |.ffunc_nn math_ldexp + | cvt.w.d FARG2, FARG2 + | load_got ldexp + | mfc1 CARG3, FARG2 + | call_extern + |. nop + | b ->fff_resn + |. nop + | + |.ffunc_n math_frexp + | load_got frexp + | lw PC, FRAME_PC(BASE) + | call_extern + |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | lw TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | addiu RA, BASE, -8 + | mtc1 TMP1, FARG2 + | sdc1 FRET1, 0(RA) + | cvt.d.w FARG2, FARG2 + | sdc1 FARG2, 8(RA) + | b ->fff_res + |. li RD, (2+1)*8 + | + |.ffunc_n math_modf + | load_got modf + | lw PC, FRAME_PC(BASE) + | call_extern + |. addiu CARG3, BASE, -8 + | addiu RA, BASE, -8 + | sdc1 FRET1, 0(BASE) + | b ->fff_res + |. li RD, (2+1)*8 + | + |.macro math_minmax, name, ismax + |->ff_ .. name: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. ldc1 FRET1, 0(BASE) + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. addu TMP2, BASE, NARGS8:RC + | addiu TMP1, BASE, 8 + | beq TMP1, TMP2, ->fff_resn + |1: + |. lw CARG3, HI(TMP1) + | ldc1 FARG1, 0(TMP1) + | addiu TMP1, TMP1, 8 + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |.if ismax + |. c.olt.d FARG1, FRET1 + |.else + |. c.olt.d FRET1, FARG1 + |.endif + | bne TMP1, TMP2, <1 + |. movf.d FRET1, FARG1 + | b ->fff_resn + |. nop + |.endmacro + | + | math_minmax math_min, 0 + | math_minmax math_max, 1 + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. nop + | b ->fff_resi + |. lw CRET1, STR:CARG1->len + | + |.ffunc string_byte // Only handle the 1-arg case here. + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | xori AT, NARGS8:RC, 8 + | addiu CARG3, CARG3, -LJ_TSTR + | or AT, AT, CARG3 + | bnez AT, ->fff_fallback // Need exactly 1 string argument. + |. nop + | lw TMP0, STR:CARG1->len + | lbu TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | addiu RA, BASE, -8 + | sltu RD, r0, TMP0 + | mtc1 TMP1, f0 + | addiu RD, RD, 1 + | cvt.d.w f0, f0 + | lw PC, FRAME_PC(BASE) + | sll RD, RD, 3 // RD = ((str->len != 0)+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | lw CARG3, HI(BASE) + | ldc1 FARG1, 0(BASE) + | li AT, 8 + | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument. + |. sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. li CARG3, 1 + | cvt.w.d FARG1, FARG1 + | addiu CARG2, sp, ARG5_OFS + | sltiu AT, TMP0, 256 + | mfc1 TMP0, FARG1 + | beqz AT, ->fff_fallback + |. sw TMP0, ARG5 + |->fff_newstr: + | load_got lj_str_new + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_str_new // (lua_State *L, char *str, size_t l) + |. move CARG1, L + | // Returns GCstr *. + | lw BASE, L->base + | move CARG1, CRET1 + | b ->fff_restv + |. li CARG3, LJ_TSTR + | + |.ffunc string_sub + | ffgccheck + | addiu AT, NARGS8:RC, -16 + | lw CARG3, 16+HI(BASE) + | ldc1 f0, 16(BASE) + | lw TMP0, HI(BASE) + | lw STR:CARG1, LO(BASE) + | bltz AT, ->fff_fallback + | lw CARG2, 8+HI(BASE) + | ldc1 f2, 8(BASE) + | beqz AT, >1 + |. li CARG4, -1 + | cvt.w.d f0, f0 + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. mfc1 CARG4, f0 + |1: + | sltiu AT, CARG2, LJ_TISNUM + | beqz AT, ->fff_fallback + |. li AT, LJ_TSTR + | cvt.w.d f2, f2 + | bne TMP0, AT, ->fff_fallback + |. lw CARG2, STR:CARG1->len + | mfc1 CARG3, f2 + | // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end + | slt AT, CARG4, r0 + | addiu TMP0, CARG2, 1 + | addu TMP1, CARG4, TMP0 + | slt TMP3, CARG3, r0 + | movn CARG4, TMP1, AT // if (end < 0) end += len+1 + | addu TMP1, CARG3, TMP0 + | movn CARG3, TMP1, TMP3 // if (start < 0) start += len+1 + | li TMP2, 1 + | slt AT, CARG4, r0 + | slt TMP3, r0, CARG3 + | movn CARG4, r0, AT // if (end < 0) end = 0 + | movz CARG3, TMP2, TMP3 // if (start < 1) start = 1 + | slt AT, CARG2, CARG4 + | movn CARG4, CARG2, AT // if (end > len) end = len + | addu CARG2, STR:CARG1, CARG3 + | subu CARG3, CARG4, CARG3 // len = end - start + | addiu CARG2, CARG2, sizeof(GCstr)-1 + | bgez CARG3, ->fff_newstr + |. addiu CARG3, CARG3, 1 // len++ + |->fff_emptystr: // Return empty string. + | addiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty) + | b ->fff_restv + |. li CARG3, LJ_TSTR + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | lw TMP0, HI(BASE) + | addiu AT, NARGS8:RC, -16 // Exactly 2 arguments. + | lw CARG4, 8+HI(BASE) + | lw STR:CARG1, LO(BASE) + | addiu TMP0, TMP0, -LJ_TSTR + | ldc1 f0, 8(BASE) + | or AT, AT, TMP0 + | bnez AT, ->fff_fallback + |. sltiu AT, CARG4, LJ_TISNUM + | cvt.w.d f0, f0 + | beqz AT, ->fff_fallback + |. lw TMP0, STR:CARG1->len + | mfc1 CARG3, f0 + | lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | li AT, 1 + | blez CARG3, ->fff_emptystr // Count <= 0? + |. sltu AT, AT, TMP0 + | beqz TMP0, ->fff_emptystr // Zero length string? + |. sltu TMP0, TMP1, CARG3 + | or AT, AT, TMP0 + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | bnez AT, ->fff_fallback // Fallback for > 1-char strings. + |. lbu TMP0, STR:CARG1[1] + | addu TMP2, CARG2, CARG3 + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | addiu TMP2, TMP2, -1 + | sltu AT, CARG2, TMP2 + | bnez AT, <1 + |. sb TMP0, 0(TMP2) + | b ->fff_newstr + |. nop + | + |.ffunc string_reverse + | ffgccheck + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | lw CARG3, STR:CARG1->len + | addiu CARG1, STR:CARG1, #STR + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | sltu AT, TMP1, CARG3 + | bnez AT, ->fff_fallback + |. addu TMP3, CARG1, CARG3 + | addu CARG4, CARG2, CARG3 + |1: // Reverse string copy. + | lbu TMP1, 0(CARG1) + | sltu AT, CARG1, TMP3 + | beqz AT, ->fff_newstr + |. addiu CARG1, CARG1, 1 + | addiu CARG4, CARG4, -1 + | b <1 + | sb TMP1, 0(CARG4) + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | lw CARG3, STR:CARG1->len + | addiu CARG1, STR:CARG1, #STR + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | sltu AT, TMP1, CARG3 + | bnez AT, ->fff_fallback + |. addu TMP3, CARG1, CARG3 + | move CARG4, CARG2 + |1: // ASCII case conversion. + | lbu TMP1, 0(CARG1) + | sltu AT, CARG1, TMP3 + | beqz AT, ->fff_newstr + |. addiu TMP0, TMP1, -lo + | xori TMP2, TMP1, 0x20 + | sltiu AT, TMP0, 26 + | movn TMP1, TMP2, AT + | addiu CARG1, CARG1, 1 + | sb TMP1, 0(CARG4) + | b <1 + |. addiu CARG4, CARG4, 1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. load_got lj_tab_len + | call_intern lj_tab_len // (GCtab *t) + |. nop + | // Returns uint32_t (but less than 2^31). + | b ->fff_resi + |. nop + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + | .ffunc_n bit_..name + |. add.d FARG1, FARG1, TOBIT + | mfc1 CRET1, FARG1 + |.endmacro + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | addiu TMP1, BASE, 8 + | addu TMP2, BASE, NARGS8:RC + |1: + | lw CARG4, HI(TMP1) + | beq TMP1, TMP2, ->fff_resi + |. ldc1 FARG1, 0(TMP1) + | sltiu AT, CARG4, LJ_TISNUM + | beqz AT, ->fff_fallback + | add.d FARG1, FARG1, TOBIT + | mfc1 CARG2, FARG1 + | ins CRET1, CRET1, CARG2 + | b <1 + |. addiu TMP1, TMP1, 8 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | srl TMP0, CRET1, 24 + | srl TMP2, CRET1, 8 + | sll TMP1, CRET1, 24 + | andi TMP2, TMP2, 0xff00 + | or TMP0, TMP0, TMP1 + | andi CRET1, CRET1, 0xff00 + | or TMP0, TMP0, TMP2 + | sll CRET1, CRET1, 8 + | b ->fff_resi + |. or CRET1, TMP0, CRET1 + | + |.ffunc_bit bnot + | b ->fff_resi + |. not CRET1, CRET1 + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc_nn bit_..name + |. add.d FARG1, FARG1, TOBIT + | add.d FARG2, FARG2, TOBIT + | mfc1 CARG1, FARG1 + | mfc1 CARG2, FARG2 + |.if shmod == 1 + | li AT, 32 + | subu TMP0, AT, CARG2 + | sllv CARG2, CARG1, CARG2 + | srlv CARG1, CARG1, TMP0 + |.elif shmod == 2 + | li AT, 32 + | subu TMP0, AT, CARG2 + | srlv CARG2, CARG1, CARG2 + | sllv CARG1, CARG1, TMP0 + |.endif + | b ->fff_resi + |. ins CRET1, CARG1, CARG2 + |.endmacro + | + |.ffunc_bit_sh lshift, sllv, 0 + |.ffunc_bit_sh rshift, srlv, 0 + |.ffunc_bit_sh arshift, srav, 0 + |// Can't use rotrv, since it's only in MIPS32R2. + |.ffunc_bit_sh rol, or, 1 + |.ffunc_bit_sh ror, or, 2 + | + |.ffunc_bit tobit + |->fff_resi: + | mtc1 CRET1, FRET1 + | b ->fff_resn + |. cvt.d.w FRET1, FRET1 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lw TMP3, CFUNC:RB->f + | addu TMP1, BASE, NARGS8:RC + | lw PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addiu TMP0, TMP1, 8*LUA_MINSTACK + | lw TMP2, L->maxstack + | sw PC, SAVE_PC // Redundant (but a defined value). + | sltu AT, TMP2, TMP0 + | sw BASE, L->base + | sw TMP1, L->top + | bnez AT, >5 // Need to grow stack. + |. move CFUNCADDR, TMP3 + | jalr TMP3 // (lua_State *L) + |. move CARG1, L + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lw BASE, L->base + | sll RD, CRET1, 3 + | bgtz CRET1, ->fff_res // Returned nresults+1? + |. addiu RA, BASE, -8 + |1: // Returned 0 or -1: retry fast path. + | lw TMP0, L->top + | lw LFUNC:RB, FRAME_FUNC(BASE) + | bnez CRET1, ->vm_call_tail // Returned -1? + |. subu NARGS8:RC, TMP0, BASE + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andi TMP0, PC, FRAME_TYPE + | li AT, -4 + | bnez TMP0, >3 + |. and TMP1, PC, AT + | lbu TMP1, OFS_RA(PC) + | sll TMP1, TMP1, 3 + | addiu TMP1, TMP1, 8 + |3: + | b ->vm_call_dispatch // Resolve again for tailcall. + |. subu TMP2, BASE, TMP1 + | + |5: // Grow stack for fallback handler. + | load_got lj_state_growstack + | li CARG2, LUA_MINSTACK + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw BASE, L->base + | b <1 + |. li CRET1, 0 // Force retry. + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | move MULTRES, ra + | load_got lj_gc_step + | sw BASE, L->base + | addu TMP0, BASE, NARGS8:RC + | sw PC, SAVE_PC // Redundant (but a defined value). + | sw TMP0, L->top + | call_intern lj_gc_step // (lua_State *L) + |. move CARG1, L + | lw BASE, L->base + | move ra, MULTRES + | lw TMP0, L->top + | lw CFUNC:RB, FRAME_FUNC(BASE) + | jr ra + |. subu NARGS8:RC, TMP0, BASE + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi AT, TMP3, HOOK_VMEVENT // No recording while in vmevent. + | bnez AT, >5 + | // Decrement the hookcount for consistency, but always do the call. + |. lw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE + | bnez AT, >1 + |. addiu TMP2, TMP2, -1 + | andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqz AT, >1 + |. nop + | b >1 + |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE // Hook already active? + | beqz AT, >1 + |5: // Re-dispatch to static ins. + |. lw AT, GG_DISP2STATIC(TMP0) // Assumes TMP0 holds DISPATCH+OP*4. + | jr AT + |. nop + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE // Hook already active? + | bnez AT, <5 + |. andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqz AT, <5 + |. addiu TMP2, TMP2, -1 + | beqz TMP2, >1 + |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, LUA_MASKLINE + | beqz AT, <5 + |1: + |. load_got lj_dispatch_ins + | sw MULTRES, SAVE_MULTRES + | move CARG2, PC + | sw BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | call_intern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |. move CARG1, L + |3: + | lw BASE, L->base + |4: // Re-dispatch to static ins. + | lw INS, -4(PC) + | decode_OP4a TMP1, INS + | decode_OP4b TMP1 + | addu TMP0, DISPATCH, TMP1 + | decode_RD8a RD, INS + | lw AT, GG_DISP2STATIC(TMP0) + | decode_RA8a RA, INS + | decode_RD8b RD + | jr AT + | decode_RA8b RA + | + |->cont_hook: // Continue from hook yield. + | addiu PC, PC, 4 + | b <4 + |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins. + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | lw LFUNC:TMP1, FRAME_FUNC(BASE) + | addiu CARG1, DISPATCH, GG_DISP2J + | sw PC, SAVE_PC + | lw TMP1, LFUNC:TMP1->pc + | move CARG2, PC + | sw L, DISPATCH_J(L)(DISPATCH) + | lbu TMP1, PC2PROTO(framesize)(TMP1) + | load_got lj_trace_hot + | sw BASE, L->base + | sll TMP1, TMP1, 3 + | addu TMP1, BASE, TMP1 + | call_intern lj_trace_hot // (jit_State *J, const BCIns *pc) + |. sw TMP1, L->top + | b <3 + |. nop + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + |.if JIT + | b >1 + |.endif + |. move CARG2, PC + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | load_got lj_dispatch_call + | addu TMP0, BASE, RC + | sw PC, SAVE_PC + | sw BASE, L->base + | subu RA, RA, BASE + | sw TMP0, L->top + | call_intern lj_dispatch_call // (lua_State *L, const BCIns *pc) + |. move CARG1, L + | // Returns ASMFunction. + | lw BASE, L->base + | lw TMP0, L->top + | sw r0, SAVE_PC // Invalidate for subsequent line hook. + | subu NARGS8:RC, TMP0, BASE + | addu RA, BASE, RA + | lw LFUNC:RB, FRAME_FUNC(BASE) + | jr CRET1 + |. lw INS, -4(PC) + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro savex_, a, b + | sdc1 f..a, 16+a*8(sp) + | sw r..a, 16+32*8+a*4(sp) + | sw r..b, 16+32*8+b*4(sp) + |.endmacro + | + |->vm_exit_handler: + |.if JIT + | addiu sp, sp, -(16+32*8+32*4) + | savex_ 0, 1 + | savex_ 2, 3 + | savex_ 4, 5 + | savex_ 6, 7 + | savex_ 8, 9 + | savex_ 10, 11 + | savex_ 12, 13 + | savex_ 14, 15 + | savex_ 16, 17 + | savex_ 18, 19 + | savex_ 20, 21 + | savex_ 22, 23 + | savex_ 24, 25 + | savex_ 26, 27 + | sdc1 f28, 16+28*8(sp) + | sw r28, 16+32*8+28*4(sp) + | sdc1 f30, 16+30*8(sp) + | sw r30, 16+32*8+30*4(sp) + | sw r0, 16+32*8+31*4(sp) // Clear RID_TMP. + | li_vmstate EXIT + | addiu TMP2, sp, 16+32*8+32*4 // Recompute original value of sp. + | addiu DISPATCH, JGL, -GG_DISP2G-32768 + | lw TMP1, 0(TMP2) // Load exit number. + | st_vmstate + | sw TMP2, 16+32*8+29*4(sp) // Store sp in RID_SP. + | lw L, DISPATCH_GL(jit_L)(DISPATCH) + | lw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | load_got lj_trace_exit + | sw L, DISPATCH_J(L)(DISPATCH) + | sw ra, DISPATCH_J(parent)(DISPATCH) // Store trace number. + | sw TMP1, DISPATCH_J(exitno)(DISPATCH) // Store exit number. + | addiu CARG1, DISPATCH, GG_DISP2J + | sw BASE, L->base + | call_intern lj_trace_exit // (jit_State *J, ExitState *ex) + |. addiu CARG2, sp, 16 + | // Returns MULTRES (unscaled) or negated error code. + | lw TMP1, L->cframe + | li AT, -4 + | lw BASE, L->base + | and sp, TMP1, AT + | lw PC, SAVE_PC // Get SAVE_PC. + | b >1 + |. sw L, SAVE_L // Set SAVE_L (on-trace resume/yield). + |.endif + |->vm_exit_interp: + |.if JIT + | // CRET1 = MULTRES or negated error code, BASE, PC and JGL set. + | lw L, SAVE_L + | addiu DISPATCH, JGL, -GG_DISP2G-32768 + |1: + | bltz CRET1, >3 // Check for error from exit. + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | sll MULTRES, CRET1, 3 + | li TISNIL, LJ_TNIL + | sw MULTRES, SAVE_MULTRES + | mtc1 TMP3, TOBIT + | lw TMP1, LFUNC:TMP1->pc + | sw r0, DISPATCH_GL(jit_L)(DISPATCH) + | lw KBASE, PC2PROTO(k)(TMP1) + | cvt.d.s TOBIT, TOBIT + | // Modified copy of ins_next which handles function header dispatch, too. + | lw INS, 0(PC) + | addiu PC, PC, 4 + | // Assumes TISNIL == ~LJ_VMST_INTERP == -1 + | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) + | decode_OP4a TMP1, INS + | decode_OP4b TMP1 + | sltiu TMP2, TMP1, BC_FUNCF*4 // Function header? + | addu TMP0, DISPATCH, TMP1 + | decode_RD8a RD, INS + | lw AT, 0(TMP0) + | decode_RA8a RA, INS + | beqz TMP2, >2 + |. decode_RA8b RA + | jr AT + |. decode_RD8b RD + |2: + | addiu RC, MULTRES, -8 + | jr AT + |. addu RA, RA, BASE + | + |3: // Rethrow error from the right C frame. + | load_got lj_err_throw + | negu CARG2, CRET1 + | call_intern lj_err_throw // (lua_State *L, int errcode) + |. move CARG1, L + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1. + |.macro vm_round, func + | lui TMP0, 0x4330 // Hiword of 2^52 (double). + | mtc1 r0, f4 + | mtc1 TMP0, f5 + | abs.d FRET2, FARG1 // |x| + | mfc1 AT, f13 + | c.olt.d 0, FRET2, f4 + | add.d FRET1, FRET2, f4 // (|x| + 2^52) - 2^52 + | bc1f 0, >1 // Truncate only if |x| < 2^52. + |. sub.d FRET1, FRET1, f4 + | slt AT, AT, r0 + |.if "func" == "ceil" + | lui TMP0, 0xbff0 // Hiword of -1 (double). Preserves -0. + |.else + | lui TMP0, 0x3ff0 // Hiword of +1 (double). + |.endif + |.if "func" == "trunc" + | mtc1 TMP0, f5 + | c.olt.d 0, FRET2, FRET1 // |x| < result? + | sub.d FRET2, FRET1, f4 + | movt.d FRET1, FRET2, 0 // If yes, subtract +1. + | neg.d FRET2, FRET1 + | jr ra + |. movn.d FRET1, FRET2, AT // Merge sign bit back in. + |.else + | neg.d FRET2, FRET1 + | mtc1 TMP0, f5 + | movn.d FRET1, FRET2, AT // Merge sign bit back in. + |.if "func" == "ceil" + | c.olt.d 0, FRET1, FARG1 // x > result? + |.else + | c.olt.d 0, FARG1, FRET1 // x < result? + |.endif + | sub.d FRET2, FRET1, f4 // If yes, subtract +-1. + | jr ra + |. movt.d FRET1, FRET2, 0 + |.endif + |1: + | jr ra + |. mov.d FRET1, FARG1 + |.endmacro + | + |->vm_floor: + | vm_round floor + |->vm_ceil: + | vm_round ceil + |->vm_trunc: + |.if JIT + | vm_round trunc + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in r1, g in r2. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | saveregs + | lw CTSTATE, GL:r2->ctype_state + | addiu DISPATCH, r2, GG_G2DISP + | load_got lj_ccallback_enter + | sw r1, CTSTATE->cb.slot + | sw CARG1, CTSTATE->cb.gpr[0] + | sw CARG2, CTSTATE->cb.gpr[1] + | sdc1 FARG1, CTSTATE->cb.fpr[0] + | sw CARG3, CTSTATE->cb.gpr[2] + | sw CARG4, CTSTATE->cb.gpr[3] + | sdc1 FARG2, CTSTATE->cb.fpr[1] + | addiu TMP0, sp, CFRAME_SPACE+16 + | sw TMP0, CTSTATE->cb.stack + | sw r0, SAVE_PC // Any value outside of bytecode is ok. + | move CARG2, sp + | call_intern lj_ccallback_enter // (CTState *cts, void *cf) + |. move CARG1, CTSTATE + | // Returns lua_State *. + | lw BASE, L:CRET1->base + | lw RC, L:CRET1->top + | move L, CRET1 + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lw LFUNC:RB, FRAME_FUNC(BASE) + | mtc1 TMP3, TOBIT + | li_vmstate INTERP + | li TISNIL, LJ_TNIL + | subu RC, RC, BASE + | st_vmstate + | cvt.d.s TOBIT, TOBIT + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | load_got lj_ccallback_leave + | lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH) + | sw BASE, L->base + | sw RB, L->top + | sw L, CTSTATE->L + | move CARG2, RA + | call_intern lj_ccallback_leave // (CTState *cts, TValue *o) + |. move CARG1, CTSTATE + | lw CRET1, CTSTATE->cb.gpr[0] + | ldc1 FRET1, CTSTATE->cb.fpr[0] + | lw CRET2, CTSTATE->cb.gpr[1] + | b ->vm_leave_unw + |. ldc1 FRET2, CTSTATE->cb.fpr[1] + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, CARG1 + | lw TMP1, CCSTATE->spadj + | lbu CARG2, CCSTATE->nsp + | move TMP2, sp + | subu sp, sp, TMP1 + | sw ra, -4(TMP2) + | sll CARG2, CARG2, 2 + | sw r16, -8(TMP2) + | sw CCSTATE, -12(TMP2) + | move r16, TMP2 + | addiu TMP1, CCSTATE, offsetof(CCallState, stack) + | addiu TMP2, sp, 16 + | beqz CARG2, >2 + |. addu TMP3, TMP1, CARG2 + |1: + | lw TMP0, 0(TMP1) + | addiu TMP1, TMP1, 4 + | sltu AT, TMP1, TMP3 + | sw TMP0, 0(TMP2) + | bnez AT, <1 + |. addiu TMP2, TMP2, 4 + |2: + | lw CFUNCADDR, CCSTATE->func + | lw CARG2, CCSTATE->gpr[1] + | lw CARG3, CCSTATE->gpr[2] + | lw CARG4, CCSTATE->gpr[3] + | ldc1 FARG1, CCSTATE->fpr[0] + | ldc1 FARG2, CCSTATE->fpr[1] + | jalr CFUNCADDR + |. lw CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1. + | lw CCSTATE:TMP1, -12(r16) + | lw TMP2, -8(r16) + | lw ra, -4(r16) + | sw CRET1, CCSTATE:TMP1->gpr[0] + | sw CRET2, CCSTATE:TMP1->gpr[1] + | sdc1 FRET1, CCSTATE:TMP1->fpr[0] + | sdc1 FRET2, CCSTATE:TMP1->fpr[1] + | move sp, r16 + | jr ra + |. move r16, TMP2 + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + | addu CARG2, BASE, RA + | addu CARG3, BASE, RD + | lw TMP0, HI(CARG2) + | lw TMP1, HI(CARG3) + | ldc1 f0, 0(CARG2) + | ldc1 f2, 0(CARG3) + | sltiu TMP0, TMP0, LJ_TISNUM + | sltiu TMP1, TMP1, LJ_TISNUM + | lhu TMP2, OFS_RD(PC) + | and TMP0, TMP0, TMP1 + | addiu PC, PC, 4 + | beqz TMP0, ->vmeta_comp + |. lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535) + | decode_RD4b TMP2 + | addu TMP2, TMP2, TMP1 + if (op == BC_ISLT || op == BC_ISGE) { + | c.olt.d f0, f2 + } else { + | c.ole.d f0, f2 + } + if (op == BC_ISLT || op == BC_ISLE) { + | movf TMP2, r0 + } else { + | movt TMP2, r0 + } + | addu PC, PC, TMP2 + |1: + | ins_next + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | ldc1 f0, 0(RA) + | addu RD, BASE, RD + | lhu TMP2, -4+OFS_RD(PC) + | lw TMP1, HI(RD) + | ldc1 f2, 0(RD) + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sltiu AT, TMP0, LJ_TISNUM + | sltiu CARG1, TMP1, LJ_TISNUM + | decode_RD4b TMP2 + | and AT, AT, CARG1 + | beqz AT, >5 + |. addu TMP2, TMP2, TMP3 + | c.eq.d f0, f2 + if (vk) { + | movf TMP2, r0 + } else { + | movt TMP2, r0 + } + |1: + | addu PC, PC, TMP2 + | ins_next + |5: // Either or both types are not numbers. + | lw CARG2, LO(RA) + | lw CARG3, LO(RD) + |.if FFI + | li TMP3, LJ_TCDATA + | beq TMP0, TMP3, ->vmeta_equal_cd + |.endif + |. sltiu AT, TMP0, LJ_TISPRI // Not a primitive? + |.if FFI + | beq TMP1, TMP3, ->vmeta_equal_cd + |.endif + |. xor TMP3, CARG2, CARG3 // Same tv? + | xor TMP1, TMP1, TMP0 // Same type? + | sltiu CARG1, TMP0, LJ_TISTABUD+1 // Table or userdata? + | movz TMP3, r0, AT // Ignore tv if primitive. + | movn CARG1, r0, TMP1 // Tab/ud and same type? + | or AT, TMP1, TMP3 // Same type && (pri||same tv). + | movz CARG1, r0, AT + | beqz CARG1, <1 // Done if not tab/ud or not same type or same tv. + if (vk) { + |. movn TMP2, r0, AT + } else { + |. movz TMP2, r0, AT + } + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lw TAB:TMP1, TAB:CARG2->metatable + | beqz TAB:TMP1, <1 // No metatable? + |. nop + | lbu TMP1, TAB:TMP1->nomm + | andi TMP1, TMP1, 1<vmeta_equal // Handle __eq metamethod. + |. li CARG4, 1-vk // ne = 0 or 1. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | srl RD, RD, 1 + | lw STR:TMP3, LO(RA) + | subu RD, KBASE, RD + | lhu TMP2, -4+OFS_RD(PC) + |.if FFI + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |.endif + |. lw STR:TMP1, -4(RD) // KBASE-4-str_const*4 + | addiu TMP0, TMP0, -LJ_TSTR + | decode_RD4b TMP2 + | xor TMP1, STR:TMP1, STR:TMP3 + | or TMP0, TMP0, TMP1 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (vk) { + | movn TMP2, r0, TMP0 + } else { + | movz TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | ldc1 f0, 0(RA) + | addu RD, KBASE, RD + | lhu TMP2, -4+OFS_RD(PC) + | ldc1 f2, 0(RD) + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sltiu AT, TMP0, LJ_TISNUM + | decode_RD4b TMP2 + |.if FFI + | beqz AT, >5 + |.else + | beqz AT, >1 + |.endif + |. addu TMP2, TMP2, TMP3 + | c.eq.d f0, f2 + if (vk) { + | movf TMP2, r0 + | addu PC, PC, TMP2 + |1: + } else { + | movt TMP2, r0 + |1: + | addu PC, PC, TMP2 + } + | ins_next + |.if FFI + |5: + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |. nop + | b <1 + |. nop + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | addu RA, BASE, RA + | srl TMP1, RD, 3 + | lw TMP0, HI(RA) + | lhu TMP2, OFS_RD(PC) + | not TMP1, TMP1 + | addiu PC, PC, 4 + |.if FFI + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |.endif + |. xor TMP0, TMP0, TMP1 + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (vk) { + | movn TMP2, r0, TMP0 + } else { + | movz TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | addu RD, BASE, RD + | lhu TMP2, OFS_RD(PC) + | lw TMP0, HI(RD) + | addiu PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (op == BC_IST) { + | movz TMP2, r0, TMP0 + } else { + | movn TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + } else { + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | ldc1 f0, 0(RD) + if (op == BC_ISTC) { + | beqz TMP0, >1 + } else { + | bnez TMP0, >1 + } + |. addu RA, BASE, RA + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + | sdc1 f0, 0(RA) + | addu PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | addu RD, BASE, RD + | addu RA, BASE, RA + | ldc1 f0, 0(RD) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | addu RD, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(RD) + | li TMP1, LJ_TFALSE + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | addiu TMP1, TMP0, LJ_TTRUE + | ins_next1 + | sw TMP1, HI(RA) + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | addu CARG3, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(CARG3) + | ldc1 f0, 0(CARG3) + | sltiu AT, TMP0, LJ_TISNUM + | beqz AT, ->vmeta_unm + |. neg.d f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | addu CARG2, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(CARG2) + | lw CARG1, LO(CARG2) + | li AT, LJ_TSTR + | bne TMP0, AT, >2 + |. li AT, LJ_TTAB + | lw CRET1, STR:CARG1->len + |1: + | mtc1 CRET1, f0 + | cvt.d.w f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + |2: + | bne TMP0, AT, ->vmeta_len + |. nop +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | bnez TAB:TMP2, >9 + |. nop + |3: +#endif + |->BC_LEN_Z: + | load_got lj_tab_len + | call_intern lj_tab_len // (GCtab *t) + |. nop + | // Returns uint32_t (but less than 2^31). + | b <1 + |. nop +#if LJ_52 + |9: + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_len + |. nop +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||switch (vk) { + ||case 0: + | addu CARG3, BASE, RB + | addu CARG4, KBASE, RC + | lw TMP1, HI(CARG3) + | ldc1 f20, 0(CARG3) + | ldc1 f22, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + || break; + ||case 1: + | addu CARG4, BASE, RB + | addu CARG3, KBASE, RC + | lw TMP1, HI(CARG4) + | ldc1 f22, 0(CARG4) + | ldc1 f20, 0(CARG3) + | sltiu AT, TMP1, LJ_TISNUM + || break; + ||default: + | addu CARG3, BASE, RB + | addu CARG4, BASE, RC + | lw TMP1, HI(CARG3) + | lw TMP2, HI(CARG4) + | ldc1 f20, 0(CARG3) + | ldc1 f22, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + | sltiu TMP0, TMP2, LJ_TISNUM + | and AT, AT, TMP0 + || break; + ||} + | beqz AT, ->vmeta_arith + |. addu RA, BASE, RA + |.endmacro + | + |.macro fpmod, a, b, c + |->BC_MODVN_Z: + | bal ->vm_floor // floor(b/c) + |. div.d FARG1, b, c + | mul.d a, FRET1, c + | sub.d a, b, a // b - floor(b/c)*c + |.endmacro + | + |.macro ins_arith, ins + | ins_arithpre + |.if "ins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |. nop + |.else + | ins f0, f20, f22 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith add.d + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith sub.d + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith mul.d + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith div.d + break; + case BC_MODVN: + | ins_arith fpmod + break; + case BC_MODNV: case BC_MODVV: + | ins_arith fpmod_ + break; + case BC_POW: + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG3, BASE, RB + | addu CARG4, BASE, RC + | lw TMP1, HI(CARG3) + | lw TMP2, HI(CARG4) + | ldc1 FARG1, 0(CARG3) + | ldc1 FARG2, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + | sltiu TMP0, TMP2, LJ_TISNUM + | and AT, AT, TMP0 + | load_got pow + | beqz AT, ->vmeta_arith + |. addu RA, BASE, RA + | call_extern + |. nop + | ins_next1 + | sdc1 FRET1, 0(RA) + | ins_next2 + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | subu CARG3, RC, RB + | sw BASE, L->base + | addu CARG2, BASE, RC + | move MULTRES, RB + |->BC_CAT_Z: + | load_got lj_meta_cat + | srl CARG3, CARG3, 3 + | sw PC, SAVE_PC + | call_intern lj_meta_cat // (lua_State *L, TValue *top, int left) + |. move CARG1, L + | // Returns NULL (finished) or TValue * (metamethod). + | bnez CRET1, ->vmeta_binop + |. lw BASE, L->base + | addu RB, BASE, MULTRES + | ldc1 f0, 0(RB) + | addu RA, BASE, RA + | ins_next1 + | sdc1 f0, 0(RA) // Copy result from RB to RA. + | ins_next2 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | ins_next1 + | lw TMP0, -4(TMP1) // KBASE-4-str_const*4 + | addu RA, BASE, RA + | li TMP2, LJ_TSTR + | sw TMP0, LO(RA) + | sw TMP2, HI(RA) + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | ins_next1 + | lw TMP0, -4(TMP1) // KBASE-4-cdata_const*4 + | addu RA, BASE, RA + | li TMP2, LJ_TCDATA + | sw TMP0, LO(RA) + | sw TMP2, HI(RA) + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + | sra RD, INS, 16 + | mtc1 RD, f0 + | addu RA, BASE, RA + | cvt.d.w f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | addu RD, KBASE, RD + | addu RA, BASE, RA + | ldc1 f0, 0(RD) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srl TMP1, RD, 3 + | addu RA, BASE, RA + | not TMP0, TMP1 + | ins_next1 + | sw TMP0, HI(RA) + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | addu RA, BASE, RA + | sw TISNIL, HI(RA) + | addiu RA, RA, 8 + | addu RD, BASE, RD + |1: + | sw TISNIL, HI(RA) + | slt AT, RA, RD + | bnez AT, <1 + |. addiu RA, RA, 8 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RD, RD, 1 + | addu RD, RD, LFUNC:RB + | lw UPVAL:RB, LFUNC:RD->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | ldc1 f0, 0(TMP1) + | addu RA, BASE, RA + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | addu RD, BASE, RD + | addu RA, RA, LFUNC:RB + | ldc1 f0, 0(RD) + | lw UPVAL:RB, LFUNC:RA->uvptr + | lbu TMP3, UPVAL:RB->marked + | lw CARG2, UPVAL:RB->v + | andi TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbu TMP0, UPVAL:RB->closed + | lw TMP2, HI(RD) + | sdc1 f0, 0(CARG2) + | li AT, LJ_GC_BLACK|1 + | or TMP3, TMP3, TMP0 + | beq TMP3, AT, >2 // Upvalue is closed and black? + |. addiu TMP2, TMP2, -(LJ_TNUMX+1) + |1: + | ins_next + | + |2: // Check if new value is collectable. + | sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1) + | beqz AT, <1 // tvisgcv(v) + |. lw TMP1, LO(RD) + | lbu TMP3, GCOBJ:TMP1->gch.marked + | andi TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | beqz TMP3, <1 + |. load_got lj_gc_barrieruv + | // Crossed a write barrier. Move the barrier forward. + | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv) + |. addiu CARG1, DISPATCH, GG_DISP2G + | b <1 + |. nop + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | srl TMP1, RD, 1 + | addu RA, RA, LFUNC:RB + | subu TMP1, KBASE, TMP1 + | lw UPVAL:RB, LFUNC:RA->uvptr + | lw STR:TMP1, -4(TMP1) // KBASE-4-str_const*4 + | lbu TMP2, UPVAL:RB->marked + | lw CARG2, UPVAL:RB->v + | lbu TMP3, STR:TMP1->marked + | andi AT, TMP2, LJ_GC_BLACK // isblack(uv) + | lbu TMP2, UPVAL:RB->closed + | li TMP0, LJ_TSTR + | sw STR:TMP1, LO(CARG2) + | bnez AT, >2 + |. sw TMP0, HI(CARG2) + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | beqz TMP2, <1 + |. andi AT, TMP3, LJ_GC_WHITES // iswhite(str) + | beqz AT, <1 + |. load_got lj_gc_barrieruv + | // Crossed a write barrier. Move the barrier forward. + | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv) + |. addiu CARG1, DISPATCH, GG_DISP2G + | b <1 + |. nop + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | addu RD, KBASE, RD + | addu RA, RA, LFUNC:RB + | ldc1 f0, 0(RD) + | lw UPVAL:RB, LFUNC:RA->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | sdc1 f0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | srl TMP0, RD, 3 + | addu RA, RA, LFUNC:RB + | not TMP0, TMP0 + | lw UPVAL:RB, LFUNC:RA->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | sw TMP0, HI(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lw TMP2, L->openupval + | branch_RD // Do this first since RD is not saved. + | load_got lj_func_closeuv + | sw BASE, L->base + | beqz TMP2, >1 + |. move CARG1, L + | call_intern lj_func_closeuv // (lua_State *L, TValue *level) + |. addu CARG2, BASE, RA + | lw BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srl TMP1, RD, 1 + | load_got lj_func_newL_gc + | subu TMP1, KBASE, TMP1 + | lw CARG3, FRAME_FUNC(BASE) + | lw CARG2, -4(TMP1) // KBASE-4-tab_const*4 + | sw BASE, L->base + | sw PC, SAVE_PC + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | call_intern lj_func_newL_gc + |. move CARG1, L + | // Returns GCfuncL *. + | lw BASE, L->base + | li TMP0, LJ_TFUNC + | ins_next1 + | addu RA, BASE, RA + | sw TMP0, HI(RA) + | sw LFUNC:CRET1, LO(RA) + | ins_next2 + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | sw BASE, L->base + | sw PC, SAVE_PC + | sltu AT, TMP0, TMP1 + | beqz AT, >5 + |1: + if (op == BC_TNEW) { + | load_got lj_tab_new + | srl CARG2, RD, 3 + | andi CARG2, CARG2, 0x7ff + | li TMP0, 0x801 + | addiu AT, CARG2, -0x7ff + | srl CARG3, RD, 14 + | movz CARG2, TMP0, AT + | // (lua_State *L, int32_t asize, uint32_t hbits) + | call_intern lj_tab_new + |. move CARG1, L + | // Returns Table *. + } else { + | load_got lj_tab_dup + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | move CARG1, L + | call_intern lj_tab_dup // (lua_State *L, Table *kt) + |. lw CARG2, -4(TMP1) // KBASE-4-str_const*4 + | // Returns Table *. + } + | lw BASE, L->base + | ins_next1 + | addu RA, BASE, RA + | li TMP0, LJ_TTAB + | sw TAB:CRET1, LO(RA) + | sw TMP0, HI(RA) + | ins_next2 + |5: + | load_got lj_gc_step_fixtop + | move MULTRES, RD + | call_intern lj_gc_step_fixtop // (lua_State *L) + |. move CARG1, L + | b <1 + |. move RD, MULTRES + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lw LFUNC:TMP2, FRAME_FUNC(BASE) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | lw TAB:RB, LFUNC:TMP2->env + | lw STR:RC, -4(TMP1) // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + |. addu RA, BASE, RA + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG2, BASE, RB + | addu CARG3, BASE, RC + | lw TMP1, HI(CARG2) + | lw TMP2, HI(CARG3) + | lw TAB:RB, LO(CARG2) + | li AT, LJ_TTAB + | ldc1 f0, 0(CARG3) + | bne TMP1, AT, ->vmeta_tgetv + |. addu RA, BASE, RA + | sltiu AT, TMP2, LJ_TISNUM + | beqz AT, >5 + |. li AT, LJ_TSTR + | + | // Convert number key to integer, check for integerness and range. + | cvt.w.d f2, f0 + | lw TMP0, TAB:RB->asize + | mfc1 TMP2, f2 + | cvt.d.w f4, f2 + | lw TMP1, TAB:RB->array + | c.eq.d f0, f4 + | sltu AT, TMP2, TMP0 + | movf AT, r0 + | sll TMP2, TMP2, 3 + | beqz AT, ->vmeta_tgetv // Integer key and in array part? + |. addu TMP2, TMP1, TMP2 + | lw TMP0, HI(TMP2) + | beq TMP0, TISNIL, >2 + |. ldc1 f0, 0(TMP2) + |1: + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |2: // Check for __index if table value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_tgetv + |. nop + | + |5: + | bne TMP2, AT, ->vmeta_tgetv + |. lw STR:RC, LO(CARG3) + | b ->BC_TGETS_Z // String key? + |. nop + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*4 (~) + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RC4a RC, INS + | lw TMP0, HI(CARG2) + | decode_RC4b RC + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | subu CARG3, KBASE, RC + | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4 + | bne TMP0, AT, ->vmeta_tgets1 + |. addu RA, BASE, RA + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lw TMP0, TAB:RB->hmask + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:RB->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | lw NODE:TMP1, NODE:TMP2->next + | lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | addiu CARG1, CARG1, -LJ_TSTR + | xor TMP0, TMP0, STR:RC + | or AT, CARG1, TMP0 + | bnez AT, >4 + |. lw TAB:TMP3, TAB:RB->metatable + | beq CARG2, TISNIL, >5 // Key found, but nil value? + |. lw CARG1, offsetof(Node, val)+LO(NODE:TMP2) + |3: + | ins_next1 + | sw CARG2, HI(RA) + | sw CARG1, LO(RA) + | ins_next2 + | + |4: // Follow hash chain. + | bnez NODE:TMP1, <1 + |. move NODE:TMP2, NODE:TMP1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | beqz TAB:TMP3, <3 // No metatable: done. + |. li CARG2, LJ_TNIL + | lbu TMP0, TAB:TMP3->nomm + | andi TMP0, TMP0, 1<vmeta_tgets + |. nop + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RDtoRC8 RC, RD + | lw CARG1, HI(CARG2) + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | addu RA, BASE, RA + | bne CARG1, AT, ->vmeta_tgetb + |. srl TMP0, RC, 3 + | lw TMP1, TAB:RB->asize + | lw TMP2, TAB:RB->array + | sltu AT, TMP0, TMP1 + | beqz AT, ->vmeta_tgetb + |. addu RC, TMP2, RC + | lw TMP1, HI(RC) + | beq TMP1, TISNIL, >5 + |. ldc1 f0, 0(RC) + |1: + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP1, TAB:TMP2->nomm + | andi TMP1, TMP1, 1<vmeta_tgetb // Caveat: preserve TMP0! + |. nop + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG2, BASE, RB + | addu CARG3, BASE, RC + | lw TMP1, HI(CARG2) + | lw TMP2, HI(CARG3) + | lw TAB:RB, LO(CARG2) + | li AT, LJ_TTAB + | ldc1 f0, 0(CARG3) + | bne TMP1, AT, ->vmeta_tsetv + |. addu RA, BASE, RA + | sltiu AT, TMP2, LJ_TISNUM + | beqz AT, >5 + |. li AT, LJ_TSTR + | + | // Convert number key to integer, check for integerness and range. + | cvt.w.d f2, f0 + | lw TMP0, TAB:RB->asize + | mfc1 TMP2, f2 + | cvt.d.w f4, f2 + | lw TMP1, TAB:RB->array + | c.eq.d f0, f4 + | sltu AT, TMP2, TMP0 + | movf AT, r0 + | sll TMP2, TMP2, 3 + | beqz AT, ->vmeta_tsetv // Integer key and in array part? + |. addu TMP1, TMP1, TMP2 + | lbu TMP3, TAB:RB->marked + | lw TMP0, HI(TMP1) + | beq TMP0, TISNIL, >3 + |. ldc1 f0, 0(RA) + |1: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f0, 0(TMP1) + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP2, TAB:TMP2->nomm + | andi TMP2, TMP2, 1<vmeta_tsetv + |. nop + | + |5: + | bne TMP2, AT, ->vmeta_tsetv + |. lw STR:RC, LO(CARG3) + | b ->BC_TSETS_Z // String key? + |. nop + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RC4a RC, INS + | lw TMP0, HI(CARG2) + | decode_RC4b RC + | li AT, LJ_TTAB + | subu CARG3, KBASE, RC + | lw TAB:RB, LO(CARG2) + | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4 + | bne TMP0, AT, ->vmeta_tsets1 + |. addu RA, BASE, RA + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8 + | lw TMP0, TAB:RB->hmask + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:RB->node + | sb r0, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + | ldc1 f20, 0(RA) + |1: + | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | li AT, LJ_TSTR + | lw NODE:TMP1, NODE:TMP2->next + | bne CARG1, AT, >5 + |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | bne TMP0, STR:RC, >5 + |. lbu TMP3, TAB:RB->marked + | beq CARG2, TISNIL, >4 // Key found, but nil value? + |. lw TAB:TMP0, TAB:RB->metatable + |2: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f20, NODE:TMP2->val + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | beqz TAB:TMP0, <2 // No metatable: done. + |. nop + | lbu TMP0, TAB:TMP0->nomm + | andi TMP0, TMP0, 1<vmeta_tsets + |. nop + | + |5: // Follow hash chain. + | bnez NODE:TMP1, <1 + |. move NODE:TMP2, NODE:TMP1 + | // End of hash chain: key not found, add a new one + | + | // But check for __newindex first. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, >6 // No metatable: continue. + |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |. li AT, LJ_TSTR + |6: + | load_got lj_tab_newkey + | sw STR:RC, LO(CARG3) + | sw AT, HI(CARG3) + | sw BASE, L->base + | move CARG2, TAB:RB + | sw PC, SAVE_PC + | call_intern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k + |. move CARG1, L + | // Returns TValue *. + | lw BASE, L->base + | b <3 // No 2nd write barrier needed. + |. sdc1 f20, 0(CRET1) + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RDtoRC8 RC, RD + | lw CARG1, HI(CARG2) + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | addu RA, BASE, RA + | bne CARG1, AT, ->vmeta_tsetb + |. srl TMP0, RC, 3 + | lw TMP1, TAB:RB->asize + | lw TMP2, TAB:RB->array + | sltu AT, TMP0, TMP1 + | beqz AT, ->vmeta_tsetb + |. addu RC, TMP2, RC + | lw TMP1, HI(RC) + | lbu TMP3, TAB:RB->marked + | beq TMP1, TISNIL, >5 + |. ldc1 f0, 0(RA) + |1: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f0, 0(RC) + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP1, TAB:TMP2->nomm + | andi TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + |. nop + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | addu RA, BASE, RA + |1: + | addu TMP3, KBASE, RD + | lw TAB:CARG2, -8+LO(RA) // Guaranteed to be a table. + | addiu TMP0, MULTRES, -8 + | lw TMP3, LO(TMP3) // Integer constant is in lo-word. + | beqz TMP0, >4 // Nothing to copy? + |. srl CARG3, TMP0, 3 + | addu CARG3, CARG3, TMP3 + | lw TMP2, TAB:CARG2->asize + | sll TMP1, TMP3, 3 + | lbu TMP3, TAB:CARG2->marked + | lw CARG1, TAB:CARG2->array + | sltu AT, TMP2, CARG3 + | bnez AT, >5 + |. addu TMP2, RA, TMP0 + | addu TMP1, TMP1, CARG1 + | andi TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | sltu AT, RA, TMP2 + | sdc1 f0, 0(TMP1) + | bnez AT, <3 + |. addiu TMP1, TMP1, 8 + | bnez TMP0, >7 + |. nop + |4: + | ins_next + | + |5: // Need to resize array part. + | load_got lj_tab_reasize + | sw BASE, L->base + | sw PC, SAVE_PC + | move BASE, RD + | call_intern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + |. move CARG1, L + | // Must not reallocate the stack. + | move RD, BASE + | b <1 + |. lw BASE, L->base // Reload BASE for lack of a saved register. + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0, <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | decode_RDtoRC8 NARGS8:RC, RD + | b ->BC_CALL_Z + |. addu NARGS8:RC, NARGS8:RC, MULTRES + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | decode_RDtoRC8 NARGS8:RC, RD + |->BC_CALL_Z: + | move TMP2, BASE + | addu BASE, BASE, RA + | li AT, LJ_TFUNC + | lw TMP0, HI(BASE) + | lw LFUNC:RB, LO(BASE) + | addiu BASE, BASE, 8 + | bne TMP0, AT, ->vmeta_call + |. addiu NARGS8:RC, NARGS8:RC, -8 + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | addu NARGS8:RD, NARGS8:RD, MULTRES // BC_CALLT gets RC from RD. + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | addu RA, BASE, RA + | li AT, LJ_TFUNC + | lw TMP0, HI(RA) + | lw LFUNC:RB, LO(RA) + | move NARGS8:RC, RD + | lw TMP1, FRAME_PC(BASE) + | addiu RA, RA, 8 + | bne TMP0, AT, ->vmeta_callt + |. addiu NARGS8:RC, NARGS8:RC, -8 + |->BC_CALLT_Z: + | andi TMP0, TMP1, FRAME_TYPE // Caveat: preserve TMP0 until the 'or'. + | lbu TMP3, LFUNC:RB->ffid + | bnez TMP0, >7 + |. xori TMP2, TMP1, FRAME_VARG + |1: + | sw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | sltiu AT, TMP3, 2 // (> FF_C) Calling a fast function? + | move TMP2, BASE + | beqz NARGS8:RC, >3 + |. move TMP3, NARGS8:RC + |2: + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | addiu TMP3, TMP3, -8 + | sdc1 f0, 0(TMP2) + | bnez TMP3, <2 + |. addiu TMP2, TMP2, 8 + |3: + | or TMP0, TMP0, AT + | beqz TMP0, >5 + |. nop + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lw INS, -4(TMP1) + | decode_RA8a RA, INS + | decode_RA8b RA + | subu TMP1, BASE, RA + | lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1) + | lw TMP1, LFUNC:TMP1->pc + | b <4 + |. lw KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | + |7: // Tailcall from a vararg function. + | andi AT, TMP2, FRAME_TYPEP + | bnez AT, <1 // Vararg frame below? + |. subu TMP2, BASE, TMP2 // Relocate BASE down. + | move BASE, TMP2 + | lw TMP1, FRAME_PC(TMP2) + | b <1 + |. andi TMP0, TMP1, FRAME_TYPE + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | move TMP2, BASE + | addu BASE, BASE, RA + | li AT, LJ_TFUNC + | lw TMP1, -24+HI(BASE) + | lw LFUNC:RB, -24+LO(BASE) + | ldc1 f2, -8(BASE) + | ldc1 f0, -16(BASE) + | sw TMP1, HI(BASE) // Copy callable. + | sw LFUNC:RB, LO(BASE) + | sdc1 f2, 16(BASE) // Copy control var. + | sdc1 f0, 8(BASE) // Copy state. + | addiu BASE, BASE, 8 + | bne TMP1, AT, ->vmeta_call + |. li NARGS8:RC, 16 // Iterators get 2 arguments. + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | addu RA, BASE, RA + | lw TAB:RB, -16+LO(RA) + | lw RC, -8+LO(RA) // Get index from control var. + | lw TMP0, TAB:RB->asize + | lw TMP1, TAB:RB->array + | addiu PC, PC, 4 + |1: // Traverse array part. + | sltu AT, RC, TMP0 + | beqz AT, >5 // Index points after array part? + |. sll TMP3, RC, 3 + | addu TMP3, TMP1, TMP3 + | lw TMP2, HI(TMP3) + | ldc1 f0, 0(TMP3) + | mtc1 RC, f2 + | lhu RD, -4+OFS_RD(PC) + | beq TMP2, TISNIL, <1 // Skip holes in array part. + |. addiu RC, RC, 1 + | cvt.d.w f2, f2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sdc1 f0, 8(RA) + | decode_RD4b RD + | addu RD, RD, TMP3 + | sw RC, -8+LO(RA) // Update control var. + | addu PC, PC, RD + | sdc1 f2, 0(RA) + |3: + | ins_next + | + |5: // Traverse hash part. + | lw TMP1, TAB:RB->hmask + | subu RC, RC, TMP0 + | lw TMP2, TAB:RB->node + |6: + | sltu AT, TMP1, RC // End of iteration? Branch to ITERL+1. + | bnez AT, <3 + |. sll TMP3, RC, 5 + | sll RB, RC, 3 + | subu TMP3, TMP3, RB + | addu NODE:TMP3, TMP3, TMP2 + | lw RB, HI(NODE:TMP3) + | ldc1 f0, 0(NODE:TMP3) + | lhu RD, -4+OFS_RD(PC) + | beq RB, TISNIL, <6 // Skip holes in hash part. + |. addiu RC, RC, 1 + | ldc1 f2, NODE:TMP3->key + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sdc1 f0, 8(RA) + | addu RC, RC, TMP0 + | decode_RD4b RD + | addu RD, RD, TMP3 + | sdc1 f2, 0(RA) + | addu PC, PC, RD + | b <3 + |. sw RC, -8+LO(RA) // Update control var. + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | addu RA, BASE, RA + | lw TMP0, -24+HI(RA) + | lw CFUNC:TMP1, -24+LO(RA) + | lw TMP2, -16+HI(RA) + | lw TMP3, -8+HI(RA) + | li AT, LJ_TFUNC + | bne TMP0, AT, >5 + |. addiu TMP2, TMP2, -LJ_TTAB + | lbu TMP1, CFUNC:TMP1->ffid + | addiu TMP3, TMP3, -LJ_TNIL + | srl TMP0, RD, 1 + | or TMP2, TMP2, TMP3 + | addiu TMP1, TMP1, -FF_next_N + | addu TMP0, PC, TMP0 + | or TMP1, TMP1, TMP2 + | bnez TMP1, >5 + |. lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535) + | addu PC, TMP0, TMP2 + | lui TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | sw r0, -8+LO(RA) // Initialize control var. + | sw TMP1, -8+HI(RA) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP3, BC_JMP + | li TMP1, BC_ITERC + | sb TMP3, -4+OFS_OP(PC) + | addu PC, TMP0, TMP2 + | b <1 + |. sb TMP1, OFS_OP(PC) + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lw TMP0, FRAME_PC(BASE) + | decode_RDtoRC8 RC, RD + | decode_RB8a RB, INS + | addu RC, BASE, RC + | decode_RB8b RB + | addu RA, BASE, RA + | addiu RC, RC, FRAME_VARG + | addu TMP2, RA, RB + | addiu TMP3, BASE, -8 // TMP3 = vtop + | subu RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | beqz RB, >5 // Copy all varargs? + |. subu TMP1, TMP3, RC + | addiu TMP2, TMP2, -16 + |1: // Copy vararg slots to destination slots. + | lw CARG1, HI(RC) + | sltu AT, RC, TMP3 + | lw CARG2, LO(RC) + | addiu RC, RC, 8 + | movz CARG1, TISNIL, AT + | sw CARG1, HI(RA) + | sw CARG2, LO(RA) + | sltu AT, RA, TMP2 + | bnez AT, <1 + |. addiu RA, RA, 8 + |3: + | ins_next + | + |5: // Copy all varargs. + | lw TMP0, L->maxstack + | blez TMP1, <3 // No vararg slots? + |. li MULTRES, 8 // MULTRES = (0+1)*8 + | addu TMP2, RA, TMP1 + | sltu AT, TMP0, TMP2 + | bnez AT, >7 + |. addiu MULTRES, TMP1, 8 + |6: + | ldc1 f0, 0(RC) + | addiu RC, RC, 8 + | sdc1 f0, 0(RA) + | sltu AT, RC, TMP3 + | bnez AT, <6 // More vararg slots? + |. addiu RA, RA, 8 + | b <3 + |. nop + | + |7: // Grow stack for varargs. + | load_got lj_state_growstack + | sw RA, L->top + | subu RA, RA, BASE + | sw BASE, L->base + | subu BASE, RC, BASE // Need delta, because BASE may change. + | sw PC, SAVE_PC + | srl CARG2, TMP1, 3 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | move RC, BASE + | lw BASE, L->base + | addu RA, BASE, RA + | addu RC, BASE, RC + | b <6 + |. addiu TMP3, BASE, -8 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | addu RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lw PC, FRAME_PC(BASE) + | addu RA, BASE, RA + | move MULTRES, RD + |1: + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->BC_RETV_Z + |. xori TMP1, PC, FRAME_VARG + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lw INS, -4(PC) + | addiu TMP2, BASE, -8 + | addiu RC, RD, -8 + | decode_RA8a TMP0, INS + | decode_RB8a RB, INS + | decode_RA8b TMP0 + | decode_RB8b RB + | addu TMP3, TMP2, RB + | beqz RC, >3 + |. subu BASE, TMP2, TMP0 + |2: + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | addiu RC, RC, -8 + | sdc1 f0, 0(TMP2) + | bnez RC, <2 + |. addiu TMP2, TMP2, 8 + |3: + | addiu TMP3, TMP3, -8 + |5: + | sltu AT, TMP2, TMP3 + | bnez AT, >6 + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lw TMP1, LFUNC:TMP1->pc + | lw KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | sw TISNIL, HI(TMP2) + | b <5 + |. addiu TMP2, TMP2, 8 + | + |->BC_RETV_Z: // Non-standard return case. + | andi TMP2, TMP1, FRAME_TYPEP + | bnez TMP2, ->vm_return + |. nop + | // Return from vararg function: relocate BASE down. + | subu BASE, BASE, TMP1 + | b <1 + |. lw PC, FRAME_PC(BASE) + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lw PC, FRAME_PC(BASE) + | addu RA, BASE, RA + | move MULTRES, RD + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->BC_RETV_Z + |. xori TMP1, PC, FRAME_VARG + | + | lw INS, -4(PC) + | addiu TMP2, BASE, -8 + if (op == BC_RET1) { + | ldc1 f0, 0(RA) + } + | decode_RB8a RB, INS + | decode_RA8a RA, INS + | decode_RB8b RB + | decode_RA8b RA + if (op == BC_RET1) { + | sdc1 f0, 0(TMP2) + } + | subu BASE, TMP2, RA + |5: + | sltu AT, RD, RB + | bnez AT, >6 + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lw TMP1, LFUNC:TMP1->pc + | lw KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | addiu TMP2, TMP2, 8 + | addiu RD, RD, 8 + | b <5 + if (op == BC_RET1) { + |. sw TISNIL, HI(TMP2) + } else { + |. sw TISNIL, -8+HI(TMP2) + } + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | addu RA, BASE, RA + if (vk) { + | ldc1 f0, FORL_IDX*8(RA) + | ldc1 f4, FORL_STEP*8(RA) + | ldc1 f2, FORL_STOP*8(RA) + | lw TMP3, FORL_STEP*8+HI(RA) + | add.d f0, f0, f4 + | sdc1 f0, FORL_IDX*8(RA) + } else { + | lw TMP1, FORL_IDX*8+HI(RA) + | lw TMP3, FORL_STEP*8+HI(RA) + | lw TMP2, FORL_STOP*8+HI(RA) + | sltiu TMP1, TMP1, LJ_TISNUM + | sltiu TMP0, TMP3, LJ_TISNUM + | sltiu TMP2, TMP2, LJ_TISNUM + | and TMP1, TMP1, TMP0 + | and TMP1, TMP1, TMP2 + | ldc1 f0, FORL_IDX*8(RA) + | beqz TMP1, ->vmeta_for + |. ldc1 f2, FORL_STOP*8(RA) + } + if (op != BC_JFORL) { + | srl RD, RD, 1 + | lui TMP0, (-(BCBIAS_J*4 >> 16) & 65535) + } + | c.le.d 0, f0, f2 + | c.le.d 1, f2, f0 + | sdc1 f0, FORL_EXT*8(RA) + if (op == BC_JFORI) { + | li TMP1, 1 + | li TMP2, 1 + | addu TMP0, RD, TMP0 + | slt TMP3, TMP3, r0 + | movf TMP1, r0, 0 + | addu PC, PC, TMP0 + | movf TMP2, r0, 1 + | lhu RD, -4+OFS_RD(PC) + | movn TMP1, TMP2, TMP3 + | bnez TMP1, =>BC_JLOOP + |. decode_RD8b RD + } else if (op == BC_JFORL) { + | li TMP1, 1 + | li TMP2, 1 + | slt TMP3, TMP3, r0 + | movf TMP1, r0, 0 + | movf TMP2, r0, 1 + | movn TMP1, TMP2, TMP3 + | bnez TMP1, =>BC_JLOOP + |. nop + } else { + | addu TMP1, RD, TMP0 + | slt TMP3, TMP3, r0 + | move TMP2, TMP1 + if (op == BC_FORI) { + | movt TMP1, r0, 0 + | movt TMP2, r0, 1 + } else { + | movf TMP1, r0, 0 + | movf TMP2, r0, 1 + } + | movn TMP1, TMP2, TMP3 + | addu PC, PC, TMP1 + } + | ins_next + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | addu RA, BASE, RA + | lw TMP1, HI(RA) + | beq TMP1, TISNIL, >1 // Stop if iterator returned nil. + |. lw TMP2, LO(RA) + if (op == BC_JITERL) { + | sw TMP1, -8+HI(RA) + | b =>BC_JLOOP + |. sw TMP2, -8+LO(RA) + } else { + | branch_RD // Otherwise save control var + branch. + | sw TMP1, -8+HI(RA) + | sw TMP2, -8+LO(RA) + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base*8 (ignored), RD = traceno*8 + | lw TMP1, DISPATCH_J(trace)(DISPATCH) + | srl RD, RD, 1 + | li AT, 0 + | addu TMP1, TMP1, RD + | // Traces on MIPS don't store the trace number, so use 0. + | sw AT, DISPATCH_GL(vmstate)(DISPATCH) + | lw TRACE:TMP2, 0(TMP1) + | sw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | sw L, DISPATCH_GL(jit_L)(DISPATCH) + | lw TMP2, TRACE:TMP2->mcode + | jr TMP2 + |. addiu JGL, DISPATCH, GG_DISP2G+32768 + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lw TMP2, L->maxstack + | lbu TMP1, -4+PC2PROTO(numparams)(PC) + | lw KBASE, -4+PC2PROTO(k)(PC) + | sltu AT, TMP2, RA + | bnez AT, ->vm_growstack_l + |. sll TMP1, TMP1, 3 + if (op != BC_JFUNCF) { + | ins_next1 + } + |2: + | sltu AT, NARGS8:RC, TMP1 // Check for missing parameters. + | bnez AT, >3 + |. addu AT, BASE, NARGS8:RC + if (op == BC_JFUNCF) { + | decode_RD8a RD, INS + | b =>BC_JLOOP + |. decode_RD8b RD + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | sw TISNIL, HI(AT) + | b <2 + |. addiu NARGS8:RC, NARGS8:RC, 8 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | addu TMP1, BASE, RC + | lw TMP2, L->maxstack + | addu TMP0, RA, RC + | sw LFUNC:RB, LO(TMP1) // Store copy of LFUNC. + | addiu TMP3, RC, 8+FRAME_VARG + | sltu AT, TMP0, TMP2 + | lw KBASE, -4+PC2PROTO(k)(PC) + | beqz AT, ->vm_growstack_l + |. sw TMP3, HI(TMP1) // Store delta + FRAME_VARG. + | lbu TMP2, -4+PC2PROTO(numparams)(PC) + | move RA, BASE + | move RC, TMP1 + | ins_next1 + | beqz TMP2, >3 + |. addiu BASE, TMP1, 8 + |1: + | lw TMP0, HI(RA) + | lw TMP3, LO(RA) + | sltu AT, RA, RC // Less args than parameters? + | move CARG1, TMP0 + | movz TMP0, TISNIL, AT // Clear missing parameters. + | movn CARG1, TISNIL, AT // Clear old fixarg slot (help the GC). + | sw TMP3, 8+LO(TMP1) + | addiu TMP2, TMP2, -1 + | sw TMP0, 8+HI(TMP1) + | addiu TMP1, TMP1, 8 + | sw CARG1, HI(RA) + | bnez TMP2, <1 + |. addiu RA, RA, 8 + |3: + | ins_next2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lw CFUNCADDR, CFUNC:RB->f + } else { + | lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH) + } + | addu TMP1, RA, NARGS8:RC + | lw TMP2, L->maxstack + | addu RC, BASE, NARGS8:RC + | sw BASE, L->base + | sltu AT, TMP2, TMP1 + | sw RC, L->top + | li_vmstate C + if (op == BC_FUNCCW) { + | lw CARG2, CFUNC:RB->f + } + | bnez AT, ->vm_growstack_c // Need to grow stack. + |. move CARG1, L + | jalr CFUNCADDR // (lua_State *L [, lua_CFunction f]) + |. st_vmstate + | // Returns nresults. + | lw BASE, L->base + | sll RD, CRET1, 3 + | lw TMP1, L->top + | li_vmstate INTERP + | lw PC, FRAME_PC(BASE) // Fetch PC of caller. + | subu RA, TMP1, RD // RA = L->top - nresults*8 + | b ->vm_returnc + |. st_vmstate + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.4byte .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.4byte 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.4byte .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.4byte .Lframe0\n" + "\t.4byte .Lbegin\n" + "\t.4byte %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x9f\n\t.sleb128 1\n" + "\t.byte 0x9e\n\t.sleb128 2\n", + fcofs, CFRAME_SIZE); + for (i = 23; i >= 16; i--) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i); + for (i = 30; i >= 20; i -= 2) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.4byte .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.4byte .Lframe0\n" + "\t.4byte lj_vm_ffi_call\n" + "\t.4byte %d\n" + "\t.byte 0x9f\n\t.uleb128 1\n" + "\t.byte 0x90\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0x10\n" + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif + fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); + fprintf(ctx->fp, + "\t.globl lj_err_unwind_dwarf\n" + ".Lframe1:\n" + "\t.4byte .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.4byte 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0\n" + "\t.4byte lj_err_unwind_dwarf\n" + "\t.byte 0\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.4byte .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.4byte .LASFDE2-.Lframe1\n" + "\t.4byte .Lbegin\n" + "\t.4byte %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x9f\n\t.sleb128 1\n" + "\t.byte 0x9e\n\t.sleb128 2\n", + fcofs, CFRAME_SIZE); + for (i = 23; i >= 16; i--) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i); + for (i = 30; i >= 20; i -= 2) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE2:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.4byte .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.4byte 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.4byte .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.4byte .LASFDE3-.Lframe2\n" + "\t.4byte lj_vm_ffi_call\n" + "\t.4byte %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0x9f\n\t.uleb128 1\n" + "\t.byte 0x90\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0x10\n" + "\t.align 2\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + default: + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppc.dasc b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppc.dasc new file mode 100644 index 0000000..da75f55 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppc.dasc @@ -0,0 +1,5137 @@ +|// Low-level VM code for PowerPC CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch ppc +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// DynASM defines used by the PPC port: +|// +|// P64 64 bit pointers (only for GPR64 testing). +|// Note: a full PPC64 _LP64 port is not planned. +|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3). +|// Affects reg saves, stack layout, carry/overflow/dot flags etc. +|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360). +|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3). +|// Function pointers are really a struct: code, TOC, env (optional). +|// TOCENV Function pointers have an environment pointer, too (not on PS3). +|// PPE Power Processor Element of Cell (PS3) or Xenon (Xbox 360). +|// Must avoid (slow) micro-coded instructions. +| +|.if P64 +|.define TOC, 1 +|.define TOCENV, 1 +|.macro lpx, a, b, c; ldx a, b, c; .endmacro +|.macro lp, a, b; ld a, b; .endmacro +|.macro stp, a, b; std a, b; .endmacro +|.define decode_OPP, decode_OP8 +|.if FFI +|// Missing: Calling conventions, 64 bit regs, TOC. +|.error lib_ffi not yet implemented for PPC64 +|.endif +|.else +|.macro lpx, a, b, c; lwzx a, b, c; .endmacro +|.macro lp, a, b; lwz a, b; .endmacro +|.macro stp, a, b; stw a, b; .endmacro +|.define decode_OPP, decode_OP4 +|.endif +| +|// Convenience macros for TOC handling. +|.if TOC +|// Linker needs a TOC patch area for every external call relocation. +|.macro blex, target; bl extern target@plt; nop; .endmacro +|.macro .toc, a, b; a, b; .endmacro +|.if P64 +|.define TOC_OFS, 8 +|.define ENV_OFS, 16 +|.else +|.define TOC_OFS, 4 +|.define ENV_OFS, 8 +|.endif +|.else // No TOC. +|.macro blex, target; bl extern target@plt; .endmacro +|.macro .toc, a, b; .endmacro +|.endif +|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro +| +|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro +| +|.macro andix., y, a, i +|.if PPE +| rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i) +| cmpwi y, 0 +|.else +| andi. y, a, i +|.endif +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA) +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r14 // Base of current Lua stack frame. +|.define KBASE, r15 // Constants of current Lua function. +|.define PC, r16 // Next PC. +|.define DISPATCH, r17 // Opcode dispatch table. +|.define LREG, r18 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. +|.define JGL, r31 // On-trace: global_State + 32768. +| +|// Constants for type-comparisons, stores and conversions. C callee-save. +|.define TISNUM, r22 +|.define TISNIL, r23 +|.define ZERO, r24 +|.define TOBIT, f30 // 2^52 + 2^51. +|.define TONUM, f31 // 2^52 + 2^51 + 2^31. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r20 // Callee-save. +|.define RB, r10 +|.define RC, r11 +|.define RD, r12 +|.define INS, r7 // Overlaps CARG5. +| +|.define TMP0, r0 +|.define TMP1, r8 +|.define TMP2, r9 +|.define TMP3, r6 // Overlaps CARG4. +| +|// Saved temporaries. +|.define SAVE0, r21 +| +|// Calling conventions. +|.define CARG1, r3 +|.define CARG2, r4 +|.define CARG3, r5 +|.define CARG4, r6 // Overlaps TMP3. +|.define CARG5, r7 // Overlaps INS. +| +|.define FARG1, f1 +|.define FARG2, f2 +| +|.define CRET1, r3 +|.define CRET2, r4 +| +|.define TOCREG, r2 // TOC register (only used by C code). +|.define ENVREG, r11 // Environment pointer (nested C functions). +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.if GPR64 +|.if FRAME32 +| +|// 456(sp) // \ 32/64 bit C frame info +|.define TONUM_LO, 452(sp) // | +|.define TONUM_HI, 448(sp) // | +|.define TMPD_LO, 444(sp) // | +|.define TMPD_HI, 440(sp) // | +|.define SAVE_CR, 432(sp) // | 64 bit CR save. +|.define SAVE_ERRF, 424(sp) // > Parameter save area. +|.define SAVE_NRES, 420(sp) // | +|.define SAVE_L, 416(sp) // | +|.define SAVE_PC, 412(sp) // | +|.define SAVE_MULTRES, 408(sp) // | +|.define SAVE_CFRAME, 400(sp) // / 64 bit C frame chain. +|// 392(sp) // Reserved. +|.define CFRAME_SPACE, 384 // Delta for sp. +|// Back chain for sp: 384(sp) <-- sp entering interpreter +|.define SAVE_LR, 376(sp) // 32 bit LR stored in hi-part. +|.define SAVE_GPR_, 232 // .. 232+18*8: 64 bit GPR saves. +|.define SAVE_FPR_, 88 // .. 88+18*8: 64 bit FPR saves. +|// 80(sp) // Needed for 16 byte stack frame alignment. +|// 16(sp) // Callee parameter save area (ABI mandated). +|// 8(sp) // Reserved +|// Back chain for sp: 0(sp) <-- sp while in interpreter +|// 32 bit sp stored in hi-part of 0(sp). +| +|.define TMPD_BLO, 447(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.else +| +|// 508(sp) // \ 32 bit C frame info. +|.define SAVE_ERRF, 472(sp) // | +|.define SAVE_NRES, 468(sp) // | +|.define SAVE_L, 464(sp) // > Parameter save area. +|.define SAVE_PC, 460(sp) // | +|.define SAVE_MULTRES, 456(sp) // | +|.define SAVE_CFRAME, 448(sp) // / 64 bit C frame chain. +|.define SAVE_LR, 416(sp) +|.define CFRAME_SPACE, 400 // Delta for sp. +|// Back chain for sp: 400(sp) <-- sp entering interpreter +|.define SAVE_FPR_, 256 // .. 256+18*8: 64 bit FPR saves. +|.define SAVE_GPR_, 112 // .. 112+18*8: 64 bit GPR saves. +|// 48(sp) // Callee parameter save area (ABI mandated). +|.define SAVE_TOC, 40(sp) // TOC save area. +|.define TMPD_LO, 36(sp) // \ Link editor temp (ABI mandated). +|.define TMPD_HI, 32(sp) // / +|.define TONUM_LO, 28(sp) // \ Compiler temp (ABI mandated). +|.define TONUM_HI, 24(sp) // / +|// Next frame lr: 16(sp) +|.define SAVE_CR, 8(sp) // 64 bit CR save. +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.define TMPD_BLO, 39(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.endif +|.else +| +|.define SAVE_LR, 276(sp) +|.define CFRAME_SPACE, 272 // Delta for sp. +|// Back chain for sp: 272(sp) <-- sp entering interpreter +|.define SAVE_FPR_, 128 // .. 128+18*8: 64 bit FPR saves. +|.define SAVE_GPR_, 56 // .. 56+18*4: 32 bit GPR saves. +|.define SAVE_CR, 52(sp) // 32 bit CR save. +|.define SAVE_ERRF, 48(sp) // 32 bit C frame info. +|.define SAVE_NRES, 44(sp) +|.define SAVE_CFRAME, 40(sp) +|.define SAVE_L, 36(sp) +|.define SAVE_PC, 32(sp) +|.define SAVE_MULTRES, 28(sp) +|.define UNUSED1, 24(sp) +|.define TMPD_LO, 20(sp) +|.define TMPD_HI, 16(sp) +|.define TONUM_LO, 12(sp) +|.define TONUM_HI, 8(sp) +|// Next frame lr: 4(sp) +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.define TMPD_BLO, 23(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.endif +| +|.macro save_, reg +|.if GPR64 +| std r..reg, SAVE_GPR_+(reg-14)*8(sp) +|.else +| stw r..reg, SAVE_GPR_+(reg-14)*4(sp) +|.endif +| stfd f..reg, SAVE_FPR_+(reg-14)*8(sp) +|.endmacro +|.macro rest_, reg +|.if GPR64 +| ld r..reg, SAVE_GPR_+(reg-14)*8(sp) +|.else +| lwz r..reg, SAVE_GPR_+(reg-14)*4(sp) +|.endif +| lfd f..reg, SAVE_FPR_+(reg-14)*8(sp) +|.endmacro +| +|.macro saveregs +|.if GPR64 and not FRAME32 +| stdu sp, -CFRAME_SPACE(sp) +|.else +| stwu sp, -CFRAME_SPACE(sp) +|.endif +| save_ 14; save_ 15; save_ 16 +| mflr r0 +| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22 +|.if GPR64 and not FRAME32 +| std r0, SAVE_LR +|.else +| stw r0, SAVE_LR +|.endif +| save_ 23; save_ 24; save_ 25 +| mfcr r0 +| save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31 +|.if GPR64 +| std r0, SAVE_CR +|.else +| stw r0, SAVE_CR +|.endif +| .toc std TOCREG, SAVE_TOC +|.endmacro +| +|.macro restoreregs +|.if GPR64 and not FRAME32 +| ld r0, SAVE_LR +|.else +| lwz r0, SAVE_LR +|.endif +|.if GPR64 +| ld r12, SAVE_CR +|.else +| lwz r12, SAVE_CR +|.endif +| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19 +| mtlr r0; +|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif +| rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25 +|.if PPE; mtocrf 0x10, r12; .endif +| rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31 +|.if PPE; mtocrf 0x08, r12; .endif +| addi sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// These basic macros should really be part of DynASM. +|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro +|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro +|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro +|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro +|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro +| +|// Trap for not-yet-implemented parts. +|.macro NYI; tw 4, sp, sp; .endmacro +| +|// int/FP conversions. +|.macro tonum_i, freg, reg +| xoris reg, reg, 0x8000 +| stw reg, TONUM_LO +| lfd freg, TONUM_D +| fsub freg, freg, TONUM +|.endmacro +| +|.macro tonum_u, freg, reg +| stw reg, TONUM_LO +| lfd freg, TONUM_D +| fsub freg, freg, TOBIT +|.endmacro +| +|.macro toint, reg, freg, tmpfreg +| fctiwz tmpfreg, freg +| stfd tmpfreg, TMPD +| lwz reg, TMPD_LO +|.endmacro +| +|.macro toint, reg, freg +| toint reg, freg, freg +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_PC, -8 +|.define FRAME_FUNC, -4 +| +|// Instruction decode. +|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro +|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro +|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro +|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro +|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro +|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro +| +|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro +|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lwz INS, 0(PC) +| addi PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. Note: optimized for e300! +|.macro ins_NEXT2 +| decode_OPP TMP1, INS +| lpx TMP0, DISPATCH, TMP1 +| mtctr TMP0 +| decode_RB8 RB, INS +| decode_RD8 RD, INS +| decode_RA8 RA, INS +| decode_RC8 RC, INS +| bctr +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lwz PC, LFUNC:RB->pc +| lwz INS, 0(PC) +| addi PC, PC, 4 +| decode_OPP TMP1, INS +| decode_RA8 RA, INS +| lpx TMP0, DISPATCH, TMP1 +| add RA, RA, BASE +| mtctr TMP0 +| bctr +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| stw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checknum, reg; cmplw reg, TISNUM; .endmacro +|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro +|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro +|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro +|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro +|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro +| +|.macro branch_RD +| srwi TMP0, RD, 1 +| addis PC, PC, -(BCBIAS_J*4 >> 16) +| add PC, PC, TMP0 +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotcheck, delta, target +| rlwinm TMP1, PC, 31, 25, 30 +| addi TMP1, TMP1, GG_DISP2HOT +| lhzx TMP2, DISPATCH, TMP1 +| addic. TMP2, TMP2, -delta +| sthx TMP2, DISPATCH, TMP1 +| blt target +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP, ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL, ->vm_hotcall +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| // Assumes LJ_GC_BLACK is 0x04. +| rlwinm mark, mark, 0, 30, 28 // black2gray(tab) +| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| stb mark, tab->marked +| stw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andix. TMP0, PC, FRAME_P + | li TMP1, LJ_TTRUE + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | mr BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | stwu TMP1, FRAME_PC(RA) // Prepend true to results. + | + |->vm_returnc: + | addi RD, RD, 8 // RD = (nresults+1)*8. + | andix. TMP0, PC, FRAME_TYPE + | cmpwi cr1, RD, 0 + | li CRET1, LUA_YIELD + | beq cr1, ->vm_unwind_c_eh + | mr MULTRES, RD + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | cmpwi TMP0, FRAME_C + | rlwinm TMP2, PC, 0, 0, 28 + | li_vmstate C + | sub TMP2, BASE, TMP2 // TMP2 = previous base. + | bney ->vm_returnp + | + | addic. TMP1, RD, -8 + | stp TMP2, L->base + | lwz TMP2, SAVE_NRES + | subi BASE, BASE, 8 + | st_vmstate + | slwi TMP2, TMP2, 3 + | beq >2 + |1: + | addic. TMP1, TMP1, -8 + | lfd f0, 0(RA) + | addi RA, RA, 8 + | stfd f0, 0(BASE) + | addi BASE, BASE, 8 + | bney <1 + | + |2: + | cmpw TMP2, RD // More/less results wanted? + | bne >6 + |3: + | stp BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lp TMP0, SAVE_CFRAME // Restore previous C frame. + | li CRET1, 0 // Ok return status for vm_pcall. + | stp TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs + | blr + | + |6: + | ble >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | lwz TMP1, L->maxstack + | cmplw BASE, TMP1 + | bge >8 + | stw TISNIL, 0(BASE) + | addi RD, RD, 8 + | addi BASE, BASE, 8 + | b <2 + | + |7: // Less results wanted. + | subfic TMP3, TMP2, 0 // LUA_MULTRET+1 case? + | sub TMP0, RD, TMP2 + | subfe TMP1, TMP1, TMP1 // TMP1 = TMP2 == 0 ? 0 : -1 + | and TMP0, TMP0, TMP1 + | sub BASE, BASE, TMP0 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | stp BASE, L->top // Save current top held in BASE (yes). + | mr SAVE0, RD + | mr CARG2, TMP2 + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz TMP2, SAVE_NRES + | mr RD, SAVE0 + | slwi TMP2, TMP2, 3 + | lp BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mr sp, CARG1 + | mr CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | .toc ld TOCREG, SAVE_TOC + | li TMP0, ~LJ_VMST_C + | lwz GL:TMP1, L->glref + | stw TMP0, GL:TMP1->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + |.if GPR64 + | rldicr sp, CARG1, 0, 61 + |.else + | rlwinm sp, CARG1, 0, 0, 29 + |.endif + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | .toc ld TOCREG, SAVE_TOC + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp BASE, L->base + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li ZERO, 0 + | stw TMP3, TMPD + | li TMP1, LJ_TFALSE + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | li TISNIL, LJ_TNIL + | li_vmstate INTERP + | lfs TOBIT, TMPD + | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | la RA, -8(BASE) // Results start at BASE-8. + | stw TMP3, TMPD + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw TMP1, 0(RA) // Prepend false to error message. + | li RD, 16 // 2 results: false + error message. + | st_vmstate + | lfs TONUM, TMPD + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | li CARG2, LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | stp BASE, L->base + | addi PC, PC, 4 // Must point after first instruction. + | stp RC, L->top + | srwi CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | stw PC, SAVE_PC + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | lp RC, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mr L, CARG1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | mr BASE, CARG2 + | lbz TMP1, L->status + | stw L, SAVE_L + | li PC, FRAME_CP + | addi TMP0, sp, CFRAME_RESUME + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw CARG3, SAVE_NRES + | cmplwi TMP1, 0 + | stw CARG3, SAVE_ERRF + | stp TMP0, L->cframe + | stp CARG3, SAVE_CFRAME + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mr RA, BASE + | lp BASE, L->base + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp TMP1, L->top + | lwz PC, FRAME_PC(BASE) + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | stb CARG3, L->status + | stw TMP3, TMPD + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | sub RD, TMP1, BASE + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | addi RD, RD, 8 + | stw TMP0, TONUM_HI + | li_vmstate INTERP + | li ZERO, 0 + | st_vmstate + | andix. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | lfs TONUM, TMPD + | li TISNIL, LJ_TNIL + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | li PC, FRAME_CP + | stw CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lp TMP1, L:CARG1->cframe + | stw CARG3, SAVE_NRES + | mr L, CARG1 + | stw CARG1, SAVE_L + | mr BASE, CARG2 + | stp sp, L->cframe // Add our C frame to cframe chain. + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | stp TMP1, SAVE_CFRAME + | addi DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lp TMP2, L->base // TMP2 = old base (used in vmeta_call). + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp TMP1, L->top + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | add PC, PC, BASE + | stw TMP3, TMPD + | li ZERO, 0 + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | sub PC, PC, TMP2 // PC = frame delta + frame type + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | sub NARGS8:RC, TMP1, BASE + | stw TMP0, TONUM_HI + | li_vmstate INTERP + | lfs TONUM, TMPD + | li TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | lwz TMP0, FRAME_PC(BASE) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | checkfunc TMP0; bne ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mr L, CARG1 + | lwz TMP0, L:CARG1->stack + | stw CARG1, SAVE_L + | lp TMP1, L->top + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lp TMP1, L->cframe + | stp sp, L->cframe // Add our C frame to cframe chain. + | .toc lp CARG4, 0(CARG4) + | li TMP2, 0 + | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | stw TMP2, SAVE_ERRF // No error function. + | stp TMP1, SAVE_CFRAME + | mtctr CARG4 + | bctrl // (lua_State *L, lua_CFunction func, void *ud) + |.if PPE + | mr BASE, CRET1 + | cmpwi CRET1, 0 + |.else + | mr. BASE, CRET1 + |.endif + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | addi DISPATCH, DISPATCH, GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lwz TMP0, -12(BASE) // Continuation. + | mr RB, BASE + | mr BASE, TMP2 // Restore caller BASE. + | lwz LFUNC:TMP1, FRAME_FUNC(TMP2) + |.if FFI + | cmplwi TMP0, 1 + |.endif + | lwz PC, -16(RB) // Restore PC from [cont|PC]. + | subi TMP2, RD, 8 + | lwz TMP1, LFUNC:TMP1->pc + | stwx TISNIL, RA, TMP2 // Ensure one valid arg. + |.if FFI + | ble >1 + |.endif + | lwz KBASE, PC2PROTO(k)(TMP1) + | // BASE = base, RA = resultptr, RB = meta base + | mtctr TMP0 + | bctr // Jump to continuation. + | + |.if FFI + |1: + | beq ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + | subi TMP1, RB, 16 + | sub RC, TMP1, BASE + | b ->vm_call_tail + |.endif + | + |->cont_cat: // RA = resultptr, RB = meta base + | lwz INS, -4(PC) + | subi CARG2, RB, 16 + | decode_RB8 SAVE0, INS + | lfd f0, 0(RA) + | add TMP1, BASE, SAVE0 + | stp BASE, L->base + | cmplw TMP1, CARG2 + | sub CARG3, CARG2, TMP1 + | decode_RA8 RA, INS + | stfd f0, 0(CARG2) + | bney ->BC_CAT_Z + | stfdx f0, BASE, RA + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TSTR + | decode_RB8 RB, INS + | stw STR:RC, 4(CARG3) + | add CARG2, BASE, RB + | stw TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tgets: + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TTAB + | stw TAB:RB, 4(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | stw TMP0, 0(CARG2) + | li TMP1, LJ_TSTR + | stw STR:RC, 4(CARG3) + | stw TMP1, 0(CARG3) + | b >1 + | + |->vmeta_tgetb: // TMP0 = index + |.if not DUALNUM + | tonum_u f0, TMP0 + |.endif + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + |.if DUALNUM + | stw TISNUM, 0(CARG3) + | stw TMP0, 4(CARG3) + |.else + | stfd f0, 0(CARG3) + |.endif + | b >1 + | + |->vmeta_tgetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | beq >3 + | lfd f0, 0(CRET1) + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | subfic TMP1, BASE, FRAME_CONT + | lp BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 16 // 2 args for func(t, k). + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TSTR + | decode_RB8 RB, INS + | stw STR:RC, 4(CARG3) + | add CARG2, BASE, RB + | stw TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tsets: + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TTAB + | stw TAB:RB, 4(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | stw TMP0, 0(CARG2) + | li TMP1, LJ_TSTR + | stw STR:RC, 4(CARG3) + | stw TMP1, 0(CARG3) + | b >1 + | + |->vmeta_tsetb: // TMP0 = index + |.if not DUALNUM + | tonum_u f0, TMP0 + |.endif + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + |.if DUALNUM + | stw TISNUM, 0(CARG3) + | stw TMP0, 4(CARG3) + |.else + | stfd f0, 0(CARG3) + |.endif + | b >1 + | + |->vmeta_tsetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | lfdx f0, BASE, RA + | beq >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | ins_next1 + | stfd f0, 0(CRET1) + | ins_next2 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | subfic TMP1, BASE, FRAME_CONT + | lp BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 24 // 3 args for func(t, k, v) + | stfd f0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mr CARG1, L + | subi PC, PC, 4 + |.if DUALNUM + | mr CARG2, RA + |.else + | add CARG2, BASE, RA + |.endif + | stw PC, SAVE_PC + |.if DUALNUM + | mr CARG3, RD + |.else + | add CARG3, BASE, RD + |.endif + | stp BASE, L->base + | decode_OP1 CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | cmplwi CRET1, 1 + | bgt ->vmeta_binop + | subfic CRET1, CRET1, 0 + |4: + | lwz INS, 0(PC) + | addi PC, PC, 4 + | decode_RD4 TMP2, INS + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | and TMP2, TMP2, CRET1 + | add PC, PC, TMP2 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lwz INS, -4(PC) + | lfd f0, 0(RA) + | decode_RA8 TMP1, INS + | stfdx f0, BASE, TMP1 + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | lwz TMP0, 0(RA) + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is true. + | subfe CRET1, CRET1, CRET1 + | not CRET1, CRET1 + | b <4 + | + |->cont_condf: // RA = resultptr + | lwz TMP0, 0(RA) + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is false. + | subfe CRET1, CRET1, CRET1 + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | subi PC, PC, 4 + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |->vmeta_equal_cd: + |.if FFI + | mr CARG2, INS + | subi PC, PC, 4 + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_nv: + | add CARG3, KBASE, RC + | add CARG4, BASE, RB + | b >1 + |->vmeta_arith_nv2: + |.if DUALNUM + | mr CARG3, RC + | mr CARG4, RB + | b >1 + |.endif + | + |->vmeta_unm: + | mr CARG3, RD + | mr CARG4, RD + | b >1 + | + |->vmeta_arith_vn: + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_vv: + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |.if DUALNUM + | b >1 + |.endif + |->vmeta_arith_vn2: + |->vmeta_arith_vv2: + |.if DUALNUM + | mr CARG3, RB + | mr CARG4, RC + |.endif + |1: + | add CARG2, BASE, RA + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS. + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub TMP1, CRET1, BASE + | stw PC, -16(CRET1) // [cont|PC] + | mr TMP2, BASE + | addi PC, TMP1, FRAME_CONT + | mr BASE, CRET1 + | li NARGS8:RC, 16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: +#if LJ_52 + | mr SAVE0, CARG1 +#endif + | mr CARG2, RD + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | cmplwi CRET1, 0 + | bne ->vmeta_binop // Binop call for compatibility. + | mr CARG1, SAVE0 + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | mr CARG1, L + | stp TMP2, L->base // This is the callers base! + | subi CARG2, BASE, 8 + | stw PC, SAVE_PC + | add CARG3, BASE, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mr CARG1, L + | stp BASE, L->base + | subi CARG2, RA, 8 + | stw PC, SAVE_PC + | add CARG3, RA, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz TMP1, FRAME_PC(BASE) + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mr CARG1, L + | stp BASE, L->base + | mr CARG2, RA + | stw PC, SAVE_PC + | mr SAVE0, INS + | bl extern lj_meta_for // (lua_State *L, TValue *base) + |.if JIT + | decode_OP1 TMP0, SAVE0 + |.endif + | decode_RA8 RA, SAVE0 + |.if JIT + | cmpwi TMP0, BC_JFORI + |.endif + | decode_RD8 RD, SAVE0 + |.if JIT + | beqy =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz CARG1, 4(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lwz CARG4, 8(BASE) + | lwz CARG1, 4(BASE) + | lwz CARG2, 12(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | lwz CARG4, 8(BASE) + | lfd FARG2, 8(BASE) + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + | checknum CARG4; bge ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1. + |.macro ffgccheck + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | cmplw TMP0, TMP1 + | bgel ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | li TMP1, LJ_TFALSE + | la RA, -8(BASE) + | cmplw cr1, CARG3, TMP1 + | lwz PC, FRAME_PC(BASE) + | bge cr1, ->fff_fallback + | stw CARG3, 0(RA) + | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | stw CARG1, 4(RA) + | beq ->fff_res // Done if exactly 1 argument. + | li TMP1, 8 + | subi RC, RC, 8 + |1: + | cmplw TMP1, RC + | lfdx f0, BASE, TMP1 + | stfdx f0, RA, TMP1 + | addi TMP1, TMP1, 8 + | bney <1 + | b ->fff_res + | + |.ffunc type + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | blt ->fff_fallback + | .gpr64 extsw CARG1, CARG1 + | subfc TMP0, TISNUM, CARG1 + | subfe TMP2, CARG1, CARG1 + | orc TMP1, TMP2, TMP0 + | addi TMP1, TMP1, ~LJ_TISNUM+1 + | slwi TMP1, TMP1, 3 + | la TMP2, CFUNC:RB->upvalue + | lfdx FARG1, TMP2, TMP1 + | b ->fff_resn + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktab CARG3; bne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:CARG1, TAB:CARG1->metatable + |2: + | li CARG3, LJ_TNIL + | cmplwi TAB:CARG1, 0 + | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beq ->fff_restv + | lwz TMP0, TAB:CARG1->hmask + | li CARG3, LJ_TTAB // Use metatable as default result. + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:CARG1->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |3: // Rearranged logic, because we expect _not_ to find the key. + | lwz CARG4, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2) + | checkstr CARG4; bne >4 + | cmpw TMP0, STR:RC; beq >5 + |4: + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | beq ->fff_restv // Not found, keep default result. + | b <3 + |5: + | checknil CARG2 + | beq ->fff_restv // Ditto for nil value. + | mr CARG3, CARG2 // Return value of mt.__metatable. + | mr CARG1, TMP1 + | b ->fff_restv + | + |6: + | cmpwi CARG3, LJ_TUDATA; beq <1 + | .gpr64 extsw CARG3, CARG3 + | subfc TMP0, TISNUM, CARG3 + | subfe TMP2, CARG3, CARG3 + | orc TMP1, TMP2, TMP0 + | addi TMP1, TMP1, ~LJ_TISNUM+1 + | slwi TMP1, TMP1, 2 + | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH) + | lwzx TAB:CARG1, TMP2, TMP1 + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | checktab CARG3; bne ->fff_fallback + | lwz TAB:TMP1, TAB:CARG1->metatable + | checktab CARG4; bne ->fff_fallback + | cmplwi TAB:TMP1, 0 + | lbz TMP3, TAB:CARG1->marked + | bne ->fff_fallback + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stw TAB:CARG2, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, TMP3, TMP0 + | b ->fff_restv + | + |.ffunc rawget + | cmplwi NARGS8:RC, 16 + | lwz CARG4, 0(BASE) + | lwz TAB:CARG2, 4(BASE) + | blt ->fff_fallback + | checktab CARG4; bne ->fff_fallback + | la CARG3, 8(BASE) + | mr CARG1, L + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | lfd FARG1, 0(CRET1) + | b ->fff_resn + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Exactly one argument. + | checknum CARG1; bgt ->fff_fallback + | b ->fff_resn + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checkstr CARG3 + | // A __tostring method in the string base metatable is ignored. + | beq ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | checknum CARG3 + | cmplwi cr1, TMP0, 0 + | stp BASE, L->base // Add frame since C call can throw. + | crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq + | stw PC, SAVE_PC // Redundant (but a defined value). + | beq ->fff_fallback + | ffgccheck + | mr CARG1, L + | mr CARG2, BASE + |.if DUALNUM + | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) + |.else + | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) + |.endif + | // Returns GCstr *. + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | lwz TAB:CARG2, 4(BASE) + | blt ->fff_fallback + | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + | checktab CARG1 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback + | stp BASE, L->base // Add frame since C call can throw. + | mr CARG1, L + | stp BASE, L->top // Dummy frame length is ok. + | la CARG3, 8(BASE) + | stw PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | cmplwi CRET1, 0 + | li CARG3, LJ_TNIL + | beq ->fff_restv // End of traversal: return nil. + | lfd f0, 8(BASE) // Copy key and value to results. + | la RA, -8(BASE) + | lfd f1, 16(BASE) + | stfd f0, 0(RA) + | li RD, (2+1)*8 + | stfd f1, 8(RA) + | b ->fff_res + | + |.ffunc_1 pairs + | checktab CARG3 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | lfd f0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | lfd f0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | stw TISNIL, 8(BASE) + | li RD, (3+1)*8 + | stfd f0, 0(RA) + | b ->fff_res + | + |.ffunc ipairs_aux + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lwz TAB:CARG1, 4(BASE) + | lwz CARG4, 8(BASE) + |.if DUALNUM + | lwz TMP2, 12(BASE) + |.else + | lfd FARG2, 8(BASE) + |.endif + | blt ->fff_fallback + | checktab CARG3 + | checknum cr1, CARG4 + | lwz PC, FRAME_PC(BASE) + |.if DUALNUM + | bne ->fff_fallback + | bne cr1, ->fff_fallback + |.else + | lus TMP0, 0x3ff0 + | stw ZERO, TMPD_LO + | bne ->fff_fallback + | stw TMP0, TMPD_HI + | bge cr1, ->fff_fallback + | lfd FARG1, TMPD + | toint TMP2, FARG2, f0 + |.endif + | lwz TMP0, TAB:CARG1->asize + | lwz TMP1, TAB:CARG1->array + |.if not DUALNUM + | fadd FARG2, FARG2, FARG1 + |.endif + | addi TMP2, TMP2, 1 + | la RA, -8(BASE) + | cmplw TMP0, TMP2 + |.if DUALNUM + | stw TISNUM, 0(RA) + | slwi TMP3, TMP2, 3 + | stw TMP2, 4(RA) + |.else + | slwi TMP3, TMP2, 3 + | stfd FARG2, 0(RA) + |.endif + | ble >2 // Not in array part? + | lwzx TMP2, TMP1, TMP3 + | lfdx f0, TMP1, TMP3 + |1: + | checknil TMP2 + | li RD, (0+1)*8 + | beq ->fff_res // End of iteration, return 0 results. + | li RD, (2+1)*8 + | stfd f0, 8(RA) + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | lwz TMP0, TAB:CARG1->hmask + | cmplwi TMP0, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | mr CARG2, TMP2 + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | cmplwi CRET1, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | lwz TMP2, 0(CRET1) + | lfd f0, 0(CRET1) + | b <1 + | + |.ffunc_1 ipairs + | checktab CARG3 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | lfd f0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | lfd f0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + |.if DUALNUM + | stw TISNUM, 8(BASE) + |.else + | stw ZERO, 8(BASE) + |.endif + | stw ZERO, 12(BASE) + | li RD, (3+1)*8 + | stfd f0, 0(RA) + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | cmplwi NARGS8:RC, 8 + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | blt ->fff_fallback + | mr TMP2, BASE + | la BASE, 8(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | subi NARGS8:RC, NARGS8:RC, 8 + | addi PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + | + |.ffunc xpcall + | cmplwi NARGS8:RC, 16 + | lwz CARG4, 8(BASE) + | lfd FARG2, 8(BASE) + | lfd FARG1, 0(BASE) + | blt ->fff_fallback + | lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH) + | mr TMP2, BASE + | checkfunc CARG4; bne ->fff_fallback // Traceback must be a function. + | la BASE, 16(BASE) + | // Remember active hook before pcall. + | rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | stfd FARG2, 0(TMP2) // Swap function and traceback. + | subi NARGS8:RC, NARGS8:RC, 16 + | stfd FARG1, 8(TMP2) + | addi PC, TMP1, 16+FRAME_PCALL + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + | lbz TMP0, L:CARG1->status + | lp TMP1, L:CARG1->cframe + | lp CARG2, L:CARG1->top + | cmplwi cr0, TMP0, LUA_YIELD + | lp TMP2, L:CARG1->base + | cmplwi cr1, TMP1, 0 + | lwz TMP0, L:CARG1->maxstack + | cmplw cr7, CARG2, TMP2 + | lwz PC, FRAME_PC(BASE) + | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0 + | add TMP2, CARG2, NARGS8:RC + | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD + | cmplw cr1, TMP2, TMP0 + | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt + | stw PC, SAVE_PC + | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov + | stp BASE, L->base + | blt cr6, ->fff_fallback + |1: + |.if resume + | addi BASE, BASE, 8 // Keep resumed thread in stack for GC. + | subi NARGS8:RC, NARGS8:RC, 8 + | subi TMP2, TMP2, 8 + |.endif + | stp TMP2, L:CARG1->top + | li TMP1, 0 + | stp BASE, L->top + |2: // Move args to coroutine. + | cmpw TMP1, NARGS8:RC + | lfdx f0, BASE, TMP1 + | beq >3 + | stfdx f0, CARG2, TMP1 + | addi TMP1, TMP1, 8 + | b <2 + |3: + | li CARG3, 0 + | mr L:SAVE0, L:CARG1 + | li CARG4, 0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | lp TMP2, L:SAVE0->base + | cmplwi CRET1, LUA_YIELD + | lp TMP3, L:SAVE0->top + | li_vmstate INTERP + | lp BASE, L->base + | st_vmstate + | bgt >8 + | sub RD, TMP3, TMP2 + | lwz TMP0, L->maxstack + | cmplwi RD, 0 + | add TMP1, BASE, RD + | beq >6 // No results? + | cmplw TMP1, TMP0 + | li TMP1, 0 + | bgt >9 // Need to grow stack? + | + | subi TMP3, RD, 8 + | stp TMP2, L:SAVE0->top // Clear coroutine stack. + |5: // Move results from coroutine. + | cmplw TMP1, TMP3 + | lfdx f0, TMP2, TMP1 + | stfdx f0, BASE, TMP1 + | addi TMP1, TMP1, 8 + | bne <5 + |6: + | andix. TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | la RA, -8(BASE) + | stw TMP1, -8(BASE) // Prepend true to results. + | addi RD, RD, 16 + |.else + | mr RA, BASE + | addi RD, RD, 8 + |.endif + |7: + | stw PC, SAVE_PC + | mr MULTRES, RD + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | andix. TMP0, PC, FRAME_TYPE + | la TMP3, -8(TMP3) + | li TMP1, LJ_TFALSE + | lfd f0, 0(TMP3) + | stp TMP3, L:SAVE0->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | stw TMP1, -8(BASE) // Prepend false to results. + | la RA, -8(BASE) + | stfd f0, 0(BASE) // Copy error message. + | b <7 + |.else + | mr CARG1, L + | mr CARG2, L:SAVE0 + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |.endif + | + |9: // Handle stack expansion on return from yield. + | mr CARG1, L + | srwi CARG2, RD, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | li CRET1, 0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lp TMP0, L->cframe + | add TMP1, BASE, NARGS8:RC + | stp BASE, L->base + | andix. TMP0, TMP0, CFRAME_RESUME + | stp TMP1, L->top + | li CRET1, LUA_YIELD + | beq ->fff_fallback + | stp ZERO, L->cframe + | stb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_1 math_abs + | checknum CARG3 + |.if DUALNUM + | bne >2 + | srawi TMP1, CARG1, 31 + | xor TMP2, TMP1, CARG1 + |.if GPR64 + | lus TMP0, 0x8000 + | sub CARG1, TMP2, TMP1 + | cmplw CARG1, TMP0 + | beq >1 + |.else + | sub. CARG1, TMP2, TMP1 + | blt >1 + |.endif + |->fff_resi: + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | stw TISNUM, -8(BASE) + | stw CRET1, -4(BASE) + | b ->fff_res1 + |1: + | lus CARG3, 0x41e0 // 2^31. + | li CARG1, 0 + | b ->fff_restv + |2: + |.endif + | bge ->fff_fallback + | rlwinm CARG3, CARG3, 0, 1, 31 + | // Fallthrough. + | + |->fff_restv: + | // CARG3/CARG1 = TValue result. + | lwz PC, FRAME_PC(BASE) + | stw CARG3, -8(BASE) + | la RA, -8(BASE) + | stw CARG1, -4(BASE) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andix. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | bney ->vm_return + | lwz INS, -4(PC) + | decode_RB8 RB, INS + |5: + | cmplw RB, RD // More results expected? + | decode_RA8 TMP0, INS + | bgt >6 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, RA, TMP1 + | b <5 + | + |.macro math_extern, func + | .ffunc_n math_ .. func + | blex func + | b ->fff_resn + |.endmacro + | + |.macro math_extern2, func + | .ffunc_nn math_ .. func + | blex func + | b ->fff_resn + |.endmacro + | + |.macro math_round, func + | .ffunc_1 math_ .. func + | checknum CARG3; beqy ->fff_restv + | rlwinm TMP2, CARG3, 12, 21, 31 + | bge ->fff_fallback + | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023 + | cmplwi cr1, TMP2, 31 // 0 <= exp < 31? + | subfic TMP0, TMP2, 31 + | blt >3 + | slwi TMP1, CARG3, 11 + | srwi TMP3, CARG1, 21 + | oris TMP1, TMP1, 0x8000 + | addi TMP2, TMP2, 1 + | or TMP1, TMP1, TMP3 + | slwi CARG2, CARG1, 11 + | bge cr1, >4 + | slw TMP3, TMP1, TMP2 + | srw RD, TMP1, TMP0 + | or TMP3, TMP3, CARG2 + | srawi TMP2, CARG3, 31 + |.if "func" == "floor" + | and TMP1, TMP3, TMP2 + | addic TMP0, TMP1, -1 + | subfe TMP1, TMP0, TMP1 + | add CARG1, RD, TMP1 + | xor CARG1, CARG1, TMP2 + | sub CARG1, CARG1, TMP2 + | b ->fff_resi + |.else + | andc TMP1, TMP3, TMP2 + | addic TMP0, TMP1, -1 + | subfe TMP1, TMP0, TMP1 + | add CARG1, RD, TMP1 + | cmpw CARG1, RD + | xor CARG1, CARG1, TMP2 + | sub CARG1, CARG1, TMP2 + | bge ->fff_resi + | // Overflow to 2^31. + | lus CARG3, 0x41e0 // 2^31. + | li CARG1, 0 + | b ->fff_restv + |.endif + |3: // |x| < 1 + | slwi TMP2, CARG3, 1 + | srawi TMP1, CARG3, 31 + | or TMP2, CARG1, TMP2 // ztest = (hi+hi) | lo + |.if "func" == "floor" + | and TMP1, TMP2, TMP1 // (ztest & sign) == 0 ? 0 : -1 + | subfic TMP2, TMP1, 0 + | subfe CARG1, CARG1, CARG1 + |.else + | andc TMP1, TMP2, TMP1 // (ztest & ~sign) == 0 ? 0 : 1 + | addic TMP2, TMP1, -1 + | subfe CARG1, TMP2, TMP1 + |.endif + | b ->fff_resi + |4: // exp >= 31. Check for -(2^31). + | xoris TMP1, TMP1, 0x8000 + | srawi TMP2, CARG3, 31 + |.if "func" == "floor" + | or TMP1, TMP1, CARG2 + |.endif + |.if PPE + | orc TMP1, TMP1, TMP2 + | cmpwi TMP1, 0 + |.else + | orc. TMP1, TMP1, TMP2 + |.endif + | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | lus CARG1, 0x8000 // -(2^31). + | beqy ->fff_resi + |5: + | lfd FARG1, 0(BASE) + | blex func + | b ->fff_resn + |.endmacro + | + |.if DUALNUM + | math_round floor + | math_round ceil + |.else + | // NYI: use internal implementation. + | math_extern floor + | math_extern ceil + |.endif + | + |.if SQRT + |.ffunc_n math_sqrt + | fsqrt FARG1, FARG1 + | b ->fff_resn + |.else + | math_extern sqrt + |.endif + | + |.ffunc math_log + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checknum CARG3; bge ->fff_fallback + | blex log + | b ->fff_resn + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.ffunc_n math_rad + | lfd FARG2, CFUNC:RB->upvalue[0] + | fmul FARG1, FARG1, FARG2 + | b ->fff_resn + | + |.if DUALNUM + |.ffunc math_ldexp + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | lwz CARG4, 8(BASE) + |.if GPR64 + | lwz CARG2, 12(BASE) + |.else + | lwz CARG1, 12(BASE) + |.endif + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + | checknum CARG4; bne ->fff_fallback + |.else + |.ffunc_nn math_ldexp + |.if GPR64 + | toint CARG2, FARG2 + |.else + | toint CARG1, FARG2 + |.endif + |.endif + | blex ldexp + | b ->fff_resn + | + |.ffunc_n math_frexp + |.if GPR64 + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + |.else + | la CARG1, DISPATCH_GL(tmptv)(DISPATCH) + |.endif + | lwz PC, FRAME_PC(BASE) + | blex frexp + | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | la RA, -8(BASE) + |.if not DUALNUM + | tonum_i FARG2, TMP1 + |.endif + | stfd FARG1, 0(RA) + | li RD, (2+1)*8 + |.if DUALNUM + | stw TISNUM, 8(RA) + | stw TMP1, 12(RA) + |.else + | stfd FARG2, 8(RA) + |.endif + | b ->fff_res + | + |.ffunc_n math_modf + |.if GPR64 + | la CARG2, -8(BASE) + |.else + | la CARG1, -8(BASE) + |.endif + | lwz PC, FRAME_PC(BASE) + | blex modf + | la RA, -8(BASE) + | stfd FARG1, 0(BASE) + | li RD, (2+1)*8 + | b ->fff_res + | + |.macro math_minmax, name, ismax + |.if DUALNUM + | .ffunc_1 name + | checknum CARG3 + | addi TMP1, BASE, 8 + | add TMP2, BASE, NARGS8:RC + | bne >4 + |1: // Handle integers. + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + | lwz CARG2, 4(TMP1) + | bge cr1, ->fff_resi + | checknum CARG4 + | xoris TMP0, CARG1, 0x8000 + | xoris TMP3, CARG2, 0x8000 + | bne >3 + | subfc TMP3, TMP3, TMP0 + | subfe TMP0, TMP0, TMP0 + |.if ismax + | andc TMP3, TMP3, TMP0 + |.else + | and TMP3, TMP3, TMP0 + |.endif + | add CARG1, TMP3, CARG2 + |.if GPR64 + | rldicl CARG1, CARG1, 0, 32 + |.endif + | addi TMP1, TMP1, 8 + | b <1 + |3: + | bge ->fff_fallback + | // Convert intermediate result to number and continue below. + | tonum_i FARG1, CARG1 + | lfd FARG2, 0(TMP1) + | b >6 + |4: + | lfd FARG1, 0(BASE) + | bge ->fff_fallback + |5: // Handle numbers. + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + | lfd FARG2, 0(TMP1) + | bge cr1, ->fff_resn + | checknum CARG4; bge >7 + |6: + | fsub f0, FARG1, FARG2 + | addi TMP1, TMP1, 8 + |.if ismax + | fsel FARG1, f0, FARG1, FARG2 + |.else + | fsel FARG1, f0, FARG2, FARG1 + |.endif + | b <5 + |7: // Convert integer to number and continue above. + | lwz CARG2, 4(TMP1) + | bne ->fff_fallback + | tonum_i FARG2, CARG2 + | b <6 + |.else + | .ffunc_n name + | li TMP1, 8 + |1: + | lwzx CARG2, BASE, TMP1 + | lfdx FARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_resn + | bge ->fff_fallback + | fsub f0, FARG1, FARG2 + | addi TMP1, TMP1, 8 + |.if ismax + | fsel FARG1, f0, FARG1, FARG2 + |.else + | fsel FARG1, f0, FARG2, FARG1 + |.endif + | b <1 + |.endif + |.endmacro + | + | math_minmax math_min, 0 + | math_minmax math_max, 1 + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr CARG3; bne ->fff_fallback + | lwz CRET1, STR:CARG1->len + | b ->fff_resi + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checkstr CARG3 + | bne ->fff_fallback + | lwz TMP0, STR:CARG1->len + |.if DUALNUM + | lbz CARG1, STR:CARG1[1] // Access is always ok (NUL at end). + | li RD, (0+1)*8 + | lwz PC, FRAME_PC(BASE) + | cmplwi TMP0, 0 + | la RA, -8(BASE) + | beqy ->fff_res + | b ->fff_resi + |.else + | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | addic TMP3, TMP0, -1 // RD = ((str->len != 0)+1)*8 + | subfe RD, TMP3, TMP0 + | stw TMP1, TONUM_LO // Inlined tonum_u f0, TMP1. + | addi RD, RD, 1 + | lfd f0, TONUM_D + | la RA, -8(BASE) + | lwz PC, FRAME_PC(BASE) + | fsub f0, f0, TOBIT + | slwi RD, RD, 3 + | stfd f0, 0(RA) + | b ->fff_res + |.endif + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + |.if DUALNUM + | lwz TMP0, 4(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG3; bne ->fff_fallback + | la CARG2, 7(BASE) + |.else + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG3; bge ->fff_fallback + | toint TMP0, FARG1 + | la CARG2, TMPD_BLO + |.endif + | li CARG3, 1 + | cmplwi TMP0, 255; bgt ->fff_fallback + |->fff_newstr: + | mr CARG1, L + | stp BASE, L->base + | stw PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | lp BASE, L->base + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 16(BASE) + |.if not DUALNUM + | lfd f0, 16(BASE) + |.endif + | lwz TMP0, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | lwz CARG2, 8(BASE) + |.if DUALNUM + | lwz TMP1, 12(BASE) + |.else + | lfd f1, 8(BASE) + |.endif + | li TMP2, -1 + | beq >1 + |.if DUALNUM + | checknum CARG3 + | lwz TMP2, 20(BASE) + | bne ->fff_fallback + |1: + | checknum CARG2; bne ->fff_fallback + |.else + | checknum CARG3; bge ->fff_fallback + | toint TMP2, f0 + |1: + | checknum CARG2; bge ->fff_fallback + |.endif + | checkstr TMP0; bne ->fff_fallback + |.if not DUALNUM + | toint TMP1, f1 + |.endif + | lwz TMP0, STR:CARG1->len + | cmplw TMP0, TMP2 // len < end? (unsigned compare) + | addi TMP3, TMP2, 1 + | blt >5 + |2: + | cmpwi TMP1, 0 // start <= 0? + | add TMP3, TMP1, TMP0 + | ble >7 + |3: + | sub CARG3, TMP2, TMP1 + | addi CARG2, STR:CARG1, #STR-1 + | srawi TMP0, CARG3, 31 + | addi CARG3, CARG3, 1 + | add CARG2, CARG2, TMP1 + | andc CARG3, CARG3, TMP0 + |.if GPR64 + | rldicl CARG2, CARG2, 0, 32 + | rldicl CARG3, CARG3, 0, 32 + |.endif + | b ->fff_newstr + | + |5: // Negative end or overflow. + | cmpw TMP0, TMP2 // len >= end? (signed compare) + | add TMP2, TMP0, TMP3 // Negative end: end = end+len+1. + | bge <2 + | mr TMP2, TMP0 // Overflow: end = len. + | b <2 + | + |7: // Negative start or underflow. + | .gpr64 extsw TMP1, TMP1 + | addic CARG3, TMP1, -1 + | subfe CARG3, CARG3, CARG3 + | srawi CARG2, TMP3, 31 // Note: modifies carry. + | andc TMP3, TMP3, CARG3 + | andc TMP1, TMP3, CARG2 + | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) + | b <3 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmplwi NARGS8:RC, 16 + | lwz TMP0, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | lwz CARG4, 8(BASE) + |.if DUALNUM + | lwz CARG3, 12(BASE) + |.else + | lfd FARG2, 8(BASE) + |.endif + | bne ->fff_fallback // Exactly 2 arguments. + | checkstr TMP0; bne ->fff_fallback + |.if DUALNUM + | checknum CARG4; bne ->fff_fallback + |.else + | checknum CARG4; bge ->fff_fallback + | toint CARG3, FARG2 + |.endif + | lwz TMP0, STR:CARG1->len + | cmpwi CARG3, 0 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | ble >2 // Count <= 0? (or non-int) + | cmplwi TMP0, 1 + | subi TMP2, CARG3, 1 + | blt >2 // Zero length string? + | cmplw cr1, TMP1, CARG3 + | bne ->fff_fallback // Fallback for > 1-char strings. + | lbz TMP0, STR:CARG1[1] + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | blt cr1, ->fff_fallback + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | cmplwi TMP2, 0 + | stbx TMP0, CARG2, TMP2 + | subi TMP2, TMP2, 1 + | bne <1 + | b ->fff_newstr + |2: // Return empty string. + | la STR:CARG1, DISPATCH_GL(strempty)(DISPATCH) + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |.ffunc string_reverse + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | checkstr CARG3 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | bne ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | li TMP2, 0 + | cmplw TMP1, CARG3 + | subi TMP3, CARG3, 1 + | blt ->fff_fallback + |1: // Reverse string copy. + | cmpwi TMP3, 0 + | lbzx TMP1, CARG1, TMP2 + | blty ->fff_newstr + | stbx TMP1, CARG2, TMP3 + | subi TMP3, TMP3, 1 + | addi TMP2, TMP2, 1 + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | checkstr CARG3 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | bne ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | cmplw TMP1, CARG3 + | li TMP2, 0 + | blt ->fff_fallback + |1: // ASCII case conversion. + | cmplw TMP2, CARG3 + | lbzx TMP1, CARG1, TMP2 + | bgey ->fff_newstr + | subi TMP0, TMP1, lo + | xori TMP3, TMP1, 0x20 + | addic TMP0, TMP0, -26 + | subfe TMP3, TMP3, TMP3 + | rlwinm TMP3, TMP3, 0, 26, 26 // x &= 0x20. + | xor TMP1, TMP1, TMP3 + | stbx TMP1, CARG2, TMP2 + | addi TMP2, TMP2, 1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG3; bne ->fff_fallback + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b ->fff_resi + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + |.if DUALNUM + | .ffunc_1 bit_..name + | checknum CARG3; bnel ->fff_tobit_fb + |.else + | .ffunc_n bit_..name + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + |.endif + |.endmacro + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | addi TMP1, BASE, 8 + | add TMP2, BASE, NARGS8:RC + |1: + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + |.if DUALNUM + | lwz CARG2, 4(TMP1) + |.else + | lfd FARG1, 0(TMP1) + |.endif + | bgey cr1, ->fff_resi + | checknum CARG4 + |.if DUALNUM + | bnel ->fff_bitop_fb + |.else + | fadd FARG1, FARG1, TOBIT + | bge ->fff_fallback + | stfd FARG1, TMPD + | lwz CARG2, TMPD_LO + |.endif + | ins CARG1, CARG1, CARG2 + | addi TMP1, TMP1, 8 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | rotlwi TMP0, CARG1, 8 + | rlwimi TMP0, CARG1, 24, 0, 7 + | rlwimi TMP0, CARG1, 24, 16, 23 + | mr CRET1, TMP0 + | b ->fff_resi + | + |.ffunc_bit bnot + | not CRET1, CARG1 + | b ->fff_resi + | + |.macro .ffunc_bit_sh, name, ins, shmod + |.if DUALNUM + | .ffunc_2 bit_..name + | checknum CARG3; bnel ->fff_tobit_fb + | // Note: no inline conversion from number for 2nd argument! + | checknum CARG4; bne ->fff_fallback + |.else + | .ffunc_nn bit_..name + | fadd FARG1, FARG1, TOBIT + | fadd FARG2, FARG2, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + | stfd FARG2, TMPD + | lwz CARG2, TMPD_LO + |.endif + |.if shmod == 1 + | rlwinm CARG2, CARG2, 0, 27, 31 + |.elif shmod == 2 + | neg CARG2, CARG2 + |.endif + | ins CRET1, CARG1, CARG2 + | b ->fff_resi + |.endmacro + | + |.ffunc_bit_sh lshift, slw, 1 + |.ffunc_bit_sh rshift, srw, 1 + |.ffunc_bit_sh arshift, sraw, 1 + |.ffunc_bit_sh rol, rotlw, 0 + |.ffunc_bit_sh ror, rotlw, 2 + | + |.ffunc_bit tobit + |.if DUALNUM + | b ->fff_resi + |.else + |->fff_resi: + | tonum_i FARG1, CRET1 + |.endif + |->fff_resn: + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | stfd FARG1, -8(BASE) + | b ->fff_res1 + | + |// Fallback FP number to bit conversion. + |->fff_tobit_fb: + |.if DUALNUM + | lfd FARG1, 0(BASE) + | bgt ->fff_fallback + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + | blr + |.endif + |->fff_bitop_fb: + |.if DUALNUM + | lfd FARG1, 0(TMP1) + | bgt ->fff_fallback + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG2, TMPD_LO + | blr + |.endif + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lp TMP3, CFUNC:RB->f + | add TMP1, BASE, NARGS8:RC + | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addi TMP0, TMP1, 8*LUA_MINSTACK + | lwz TMP2, L->maxstack + | stw PC, SAVE_PC // Redundant (but a defined value). + | .toc lp TMP3, 0(TMP3) + | cmplw TMP0, TMP2 + | stp BASE, L->base + | stp TMP1, L->top + | mr CARG1, L + | bgt >5 // Need to grow stack. + | mtctr TMP3 + | bctrl // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lp BASE, L->base + | cmpwi CRET1, 0 + | slwi RD, CRET1, 3 + | la RA, -8(BASE) + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | lp TMP0, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub NARGS8:RC, TMP0, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andix. TMP0, PC, FRAME_TYPE + | rlwinm TMP1, PC, 0, 0, 28 + | bne >3 + | lwz INS, -4(PC) + | decode_RA8 TMP1, INS + | addi TMP1, TMP1, 8 + |3: + | sub TMP2, BASE, TMP1 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | li CARG2, LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mflr SAVE0 + | stp BASE, L->base + | add TMP0, BASE, NARGS8:RC + | stw PC, SAVE_PC // Redundant (but a defined value). + | stp TMP0, L->top + | mr CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | lp BASE, L->base + | mtlr SAVE0 + | lp TMP0, L->top + | sub NARGS8:RC, TMP0, BASE + | lwz CFUNC:RB, FRAME_FUNC(BASE) + | blr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andix. TMP0, TMP3, HOOK_VMEVENT // No recording while in vmevent. + | bne >5 + | // Decrement the hookcount for consistency, but always do the call. + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE + | bne >1 + | subi TMP2, TMP2, 1 + | andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqy >1 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | b >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OPP TMP1, INS. + | lpx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | bctr + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0 + | bne <5 + | + | cmpwi cr1, TMP0, 0 + | addic. TMP2, TMP2, -1 + | beq cr1, <5 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | beq >1 + | bge cr1, <5 + |1: + | mr CARG1, L + | stw MULTRES, SAVE_MULTRES + | mr CARG2, PC + | stp BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | lp BASE, L->base + |4: // Re-dispatch to static ins. + | lwz INS, -4(PC) + | decode_OPP TMP1, INS + | decode_RB8 RB, INS + | addi TMP1, TMP1, GG_DISP2STATIC + | decode_RD8 RD, INS + | lpx TMP0, DISPATCH, TMP1 + | decode_RA8 RA, INS + | decode_RC8 RC, INS + | mtctr TMP0 + | bctr + | + |->cont_hook: // Continue from hook yield. + | addi PC, PC, 4 + | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | addi CARG1, DISPATCH, GG_DISP2J + | stw PC, SAVE_PC + | lwz TMP1, LFUNC:TMP1->pc + | mr CARG2, PC + | stw L, DISPATCH_J(L)(DISPATCH) + | lbz TMP1, PC2PROTO(framesize)(TMP1) + | stp BASE, L->base + | slwi TMP1, TMP1, 3 + | add TMP1, BASE, TMP1 + | stp TMP1, L->top + | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) + | b <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mr CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | add TMP0, BASE, RC + | stw PC, SAVE_PC + | mr CARG1, L + | stp BASE, L->base + | sub RA, RA, BASE + | stp TMP0, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | lp BASE, L->base + | lp TMP0, L->top + | stw ZERO, SAVE_PC // Invalidate for subsequent line hook. + | sub NARGS8:RC, TMP0, BASE + | add RA, BASE, RA + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | lwz INS, -4(PC) + | mtctr CRET1 + | bctr + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro savex_, a, b, c, d + | stfd f..a, 16+a*8(sp) + | stfd f..b, 16+b*8(sp) + | stfd f..c, 16+c*8(sp) + | stfd f..d, 16+d*8(sp) + |.endmacro + | + |->vm_exit_handler: + |.if JIT + | addi sp, sp, -(16+32*8+32*4) + | stmw r2, 16+32*8+2*4(sp) + | addi DISPATCH, JGL, -GG_DISP2G-32768 + | li CARG2, ~LJ_VMST_EXIT + | lwz CARG1, 16+32*8+32*4(sp) // Get stack chain. + | stw CARG2, DISPATCH_GL(vmstate)(DISPATCH) + | savex_ 0,1,2,3 + | stw CARG1, 0(sp) // Store extended stack chain. + | mcrxr cr0 // Clear SO flag. + | savex_ 4,5,6,7 + | addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp. + | savex_ 8,9,10,11 + | stw CARG2, 16+32*8+1*4(sp) // Store sp in RID_SP. + | savex_ 12,13,14,15 + | mflr CARG3 + | li TMP1, 0 + | savex_ 16,17,18,19 + | stw TMP1, 16+32*8+0*4(sp) // Clear RID_TMP. + | savex_ 20,21,22,23 + | lhz CARG4, 2(CARG3) // Load trace number. + | savex_ 24,25,26,27 + | lwz L, DISPATCH_GL(jit_L)(DISPATCH) + | savex_ 28,29,30,31 + | sub CARG3, TMP0, CARG3 // Compute exit number. + | lp BASE, DISPATCH_GL(jit_base)(DISPATCH) + | srwi CARG3, CARG3, 2 + | stw L, DISPATCH_J(L)(DISPATCH) + | subi CARG3, CARG3, 2 + | stw TMP1, DISPATCH_GL(jit_L)(DISPATCH) + | stw CARG4, DISPATCH_J(parent)(DISPATCH) + | stp BASE, L->base + | addi CARG1, DISPATCH, GG_DISP2J + | stw CARG3, DISPATCH_J(exitno)(DISPATCH) + | addi CARG2, sp, 16 + | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) + | // Returns MULTRES (unscaled) or negated error code. + | lp TMP1, L->cframe + | lwz TMP2, 0(sp) + | lp BASE, L->base + |.if GPR64 + | rldicr sp, TMP1, 0, 61 + |.else + | rlwinm sp, TMP1, 0, 0, 29 + |.endif + | lwz PC, SAVE_PC // Get SAVE_PC. + | stw TMP2, 0(sp) + | stw L, SAVE_L // Set SAVE_L (on-trace resume/yield). + | b >1 + |.endif + |->vm_exit_interp: + |.if JIT + | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set. + | lwz L, SAVE_L + | addi DISPATCH, JGL, -GG_DISP2G-32768 + |1: + | cmpwi CARG1, 0 + | blt >3 // Check for error from exit. + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | slwi MULTRES, CARG1, 3 + | li TMP2, 0 + | stw MULTRES, SAVE_MULTRES + | lwz TMP1, LFUNC:TMP1->pc + | stw TMP2, DISPATCH_GL(jit_L)(DISPATCH) + | lwz KBASE, PC2PROTO(k)(TMP1) + | // Setup type comparison constants. + | li TISNUM, LJ_TISNUM + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | stw TMP3, TMPD + | li ZERO, 0 + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | li TISNIL, LJ_TNIL + | stw TMP0, TONUM_HI + | lfs TONUM, TMPD + | // Modified copy of ins_next which handles function header dispatch, too. + | lwz INS, 0(PC) + | addi PC, PC, 4 + | // Assumes TISNIL == ~LJ_VMST_INTERP == -1. + | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) + | decode_OPP TMP1, INS + | decode_RA8 RA, INS + | lpx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | cmplwi TMP1, BC_FUNCF*4 // Function header? + | bge >2 + | decode_RB8 RB, INS + | decode_RD8 RD, INS + | decode_RC8 RC, INS + | bctr + |2: + | subi RC, MULTRES, 8 + | add RA, RA, BASE + | bctr + | + |3: // Rethrow error from the right C frame. + | neg CARG2, CARG1 + | mr CARG1, L + | bl extern lj_err_throw // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// NYI: Use internal implementations of floor, ceil, trunc. + | + |->vm_modi: + | divwo. TMP0, CARG1, CARG2 + | bso >1 + |.if GPR64 + | xor CARG3, CARG1, CARG2 + | cmpwi CARG3, 0 + |.else + | xor. CARG3, CARG1, CARG2 + |.endif + | mullw TMP0, TMP0, CARG2 + | sub CARG1, CARG1, TMP0 + | bgelr + | cmpwi CARG1, 0; beqlr + | add CARG1, CARG1, CARG2 + | blr + |1: + | cmpwi CARG2, 0 + | li CARG1, 0 + | beqlr + | mcrxr cr0 // Clear SO for -2147483648 % -1 and return 0. + | blr + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |// void lj_vm_cachesync(void *start, void *end) + |// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size. + |// This is a good lower bound, except for very ancient PPC models. + |->vm_cachesync: + |.if JIT or FFI + | // Compute start of first cache line and number of cache lines. + | rlwinm CARG1, CARG1, 0, 0, 26 + | sub CARG2, CARG2, CARG1 + | addi CARG2, CARG2, 31 + | rlwinm. CARG2, CARG2, 27, 5, 31 + | beqlr + | mtctr CARG2 + | mr CARG3, CARG1 + |1: // Flush D-Cache. + | dcbst r0, CARG1 + | addi CARG1, CARG1, 32 + | bdnz <1 + | sync + | mtctr CARG2 + |1: // Invalidate I-Cache. + | icbi r0, CARG3 + | addi CARG3, CARG3, 32 + | bdnz <1 + | isync + | blr + |.endif + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in r11, g in r12. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | saveregs + | lwz CTSTATE, GL:r12->ctype_state + | addi DISPATCH, r12, GG_G2DISP + | stw r11, CTSTATE->cb.slot + | stw r3, CTSTATE->cb.gpr[0] + | stfd f1, CTSTATE->cb.fpr[0] + | stw r4, CTSTATE->cb.gpr[1] + | stfd f2, CTSTATE->cb.fpr[1] + | stw r5, CTSTATE->cb.gpr[2] + | stfd f3, CTSTATE->cb.fpr[2] + | stw r6, CTSTATE->cb.gpr[3] + | stfd f4, CTSTATE->cb.fpr[3] + | stw r7, CTSTATE->cb.gpr[4] + | stfd f5, CTSTATE->cb.fpr[4] + | stw r8, CTSTATE->cb.gpr[5] + | stfd f6, CTSTATE->cb.fpr[5] + | stw r9, CTSTATE->cb.gpr[6] + | stfd f7, CTSTATE->cb.fpr[6] + | stw r10, CTSTATE->cb.gpr[7] + | stfd f8, CTSTATE->cb.fpr[7] + | addi TMP0, sp, CFRAME_SPACE+8 + | stw TMP0, CTSTATE->cb.stack + | mr CARG1, CTSTATE + | stw CTSTATE, SAVE_PC // Any value outside of bytecode is ok. + | mr CARG2, sp + | bl extern lj_ccallback_enter // (CTState *cts, void *cf) + | // Returns lua_State *. + | lp BASE, L:CRET1->base + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp RC, L:CRET1->top + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | li ZERO, 0 + | mr L, CRET1 + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | stw TMP0, TONUM_HI + | li TISNIL, LJ_TNIL + | li_vmstate INTERP + | lfs TOBIT, TMPD + | stw TMP3, TMPD + | sub RC, RC, BASE + | st_vmstate + | lfs TONUM, TMPD + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH) + | stp BASE, L->base + | stp RB, L->top + | stp L, CTSTATE->L + | mr CARG1, CTSTATE + | mr CARG2, RA + | bl extern lj_ccallback_leave // (CTState *cts, TValue *o) + | lwz CRET1, CTSTATE->cb.gpr[0] + | lfd FARG1, CTSTATE->cb.fpr[0] + | lwz CRET2, CTSTATE->cb.gpr[1] + | b ->vm_leave_unw + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, CARG1 + | lwz TMP1, CCSTATE->spadj + | mflr TMP0 + | lbz CARG2, CCSTATE->nsp + | lbz CARG3, CCSTATE->nfpr + | neg TMP1, TMP1 + | stw TMP0, 4(sp) + | cmpwi cr1, CARG3, 0 + | mr TMP2, sp + | addic. CARG2, CARG2, -1 + | stwux sp, sp, TMP1 + | crnot 4*cr1+eq, 4*cr1+eq // For vararg calls. + | stw r14, -4(TMP2) + | stw CCSTATE, -8(TMP2) + | mr r14, TMP2 + | la TMP1, CCSTATE->stack + | slwi CARG2, CARG2, 2 + | blty >2 + | la TMP2, 8(sp) + |1: + | lwzx TMP0, TMP1, CARG2 + | stwx TMP0, TMP2, CARG2 + | addic. CARG2, CARG2, -4 + | bge <1 + |2: + | bney cr1, >3 + | lfd f1, CCSTATE->fpr[0] + | lfd f2, CCSTATE->fpr[1] + | lfd f3, CCSTATE->fpr[2] + | lfd f4, CCSTATE->fpr[3] + | lfd f5, CCSTATE->fpr[4] + | lfd f6, CCSTATE->fpr[5] + | lfd f7, CCSTATE->fpr[6] + | lfd f8, CCSTATE->fpr[7] + |3: + | lp TMP0, CCSTATE->func + | lwz CARG2, CCSTATE->gpr[1] + | lwz CARG3, CCSTATE->gpr[2] + | lwz CARG4, CCSTATE->gpr[3] + | lwz CARG5, CCSTATE->gpr[4] + | mtctr TMP0 + | lwz r8, CCSTATE->gpr[5] + | lwz r9, CCSTATE->gpr[6] + | lwz r10, CCSTATE->gpr[7] + | lwz CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1. + | bctrl + | lwz CCSTATE:TMP1, -8(r14) + | lwz TMP2, -4(r14) + | lwz TMP0, 4(r14) + | stw CARG1, CCSTATE:TMP1->gpr[0] + | stfd FARG1, CCSTATE:TMP1->fpr[0] + | stw CARG2, CCSTATE:TMP1->gpr[1] + | mtlr TMP0 + | stw CARG3, CCSTATE:TMP1->gpr[2] + | mr sp, r14 + | stw CARG4, CCSTATE:TMP1->gpr[3] + | mr r14, TMP2 + | blr + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, BASE + | lwz TMP2, -4(PC) + | checknum cr0, TMP0 + | lwz CARG3, 4(RD) + | decode_RD4 TMP2, TMP2 + | checknum cr1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bne cr0, >7 + | bne cr1, >8 + | cmpw CARG2, CARG3 + if (op == BC_ISLT) { + | bge >2 + } else if (op == BC_ISGE) { + | blt >2 + } else if (op == BC_ISLE) { + | bgt >2 + } else { + | ble >2 + } + |1: + | add PC, PC, TMP2 + |2: + | ins_next + | + |7: // RA is not an integer. + | bgt cr0, ->vmeta_comp + | // RA is a number. + | lfd f0, 0(RA) + | bgt cr1, ->vmeta_comp + | blt cr1, >4 + | // RA is a number, RD is an integer. + | tonum_i f1, CARG3 + | b >5 + | + |8: // RA is an integer, RD is not an integer. + | bgt cr1, ->vmeta_comp + | // RA is an integer, RD is a number. + | tonum_i f0, CARG2 + |4: + | lfd f1, 0(RD) + |5: + | fcmpu cr0, f0, f1 + if (op == BC_ISLT) { + | bge <2 + } else if (op == BC_ISGE) { + | blt <2 + } else if (op == BC_ISLE) { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | bge <2 + } else { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | blt <2 + } + | b <1 + |.else + | lwzx TMP0, BASE, RA + | addi PC, PC, 4 + | lfdx f0, BASE, RA + | lwzx TMP1, BASE, RD + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | lfdx f1, BASE, RD + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | bge cr0, ->vmeta_comp + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge cr1, ->vmeta_comp + | fcmpu cr0, f0, f1 + if (op == BC_ISLT) { + | bge >1 + } else if (op == BC_ISGE) { + | blt >1 + } else if (op == BC_ISLE) { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | bge >1 + } else { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | blt >1 + } + | add PC, PC, TMP2 + |1: + | ins_next + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, BASE + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | lwz CARG3, 4(RD) + | cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (vk) { + | ble cr7, ->BC_ISEQN_Z + } else { + | ble cr7, ->BC_ISNEN_Z + } + |.else + | lwzux TMP0, RA, BASE + | lwz TMP2, 0(PC) + | lfd f0, 0(RA) + | addi PC, PC, 4 + | lwzux TMP1, RD, BASE + | checknum cr0, TMP0 + | decode_RD4 TMP2, TMP2 + | lfd f1, 0(RD) + | checknum cr1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge cr0, >5 + | bge cr1, >5 + | fcmpu cr0, f0, f1 + if (vk) { + | bne >1 + | add PC, PC, TMP2 + } else { + | beq >1 + | add PC, PC, TMP2 + } + |1: + | ins_next + |.endif + |5: // Either or both types are not numbers. + |.if not DUALNUM + | lwz CARG2, 4(RA) + | lwz CARG3, 4(RD) + |.endif + |.if FFI + | cmpwi cr7, TMP0, LJ_TCDATA + | cmpwi cr5, TMP1, LJ_TCDATA + |.endif + | not TMP3, TMP0 + | cmplw TMP0, TMP1 + | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive? + |.if FFI + | cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq + |.endif + | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata? + |.if FFI + | beq cr7, ->vmeta_equal_cd + |.endif + | cmplw cr5, CARG2, CARG3 + | crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt // 2: Same type and primitive. + | crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq // 1: Same tv or different type. + | crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq // 0: Same type and same tv. + | mr SAVE0, PC + | cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt // 0 or 2. + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt // 1 or 2. + if (vk) { + | bne cr0, >6 + | add PC, PC, TMP2 + |6: + } else { + | beq cr0, >6 + | add PC, PC, TMP2 + |6: + } + |.if DUALNUM + | bge cr0, >2 // Done if 1 or 2. + |1: + | ins_next + |2: + |.else + | blt cr0, <1 // Done if 1 or 2. + |.endif + | blt cr6, <1 // Done if not tab/ud. + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:TMP2, TAB:CARG2->metatable + | li CARG4, 1-vk // ne = 0 or 1. + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable? + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_equal // Handle __eq metamethod. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | lwzux TMP0, RA, BASE + | srwi RD, RD, 1 + | lwz STR:TMP3, 4(RA) + | lwz TMP2, 0(PC) + | subfic RD, RD, -4 + | addi PC, PC, 4 + |.if FFI + | cmpwi TMP0, LJ_TCDATA + |.endif + | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4 + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TSTR + |.if FFI + | beq ->vmeta_equal_cd + |.endif + | sub TMP1, STR:TMP1, STR:TMP3 + | or TMP0, TMP0, TMP1 + | decode_RD4 TMP2, TMP2 + | subfic TMP0, TMP0, 0 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | subfe TMP1, TMP1, TMP1 + if (vk) { + | andc TMP2, TMP2, TMP1 + } else { + | and TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, KBASE + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | lwz CARG3, 4(RD) + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (vk) { + |->BC_ISEQN_Z: + } else { + |->BC_ISNEN_Z: + } + | bne cr0, >7 + | bne cr1, >8 + | cmpw CARG2, CARG3 + |4: + |.else + if (vk) { + |->BC_ISEQN_Z: // Dummy label. + } else { + |->BC_ISNEN_Z: // Dummy label. + } + | lwzx TMP0, BASE, RA + | addi PC, PC, 4 + | lfdx f0, BASE, RA + | lwz TMP2, -4(PC) + | lfdx f1, KBASE, RD + | decode_RD4 TMP2, TMP2 + | checknum TMP0 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge >3 + | fcmpu cr0, f0, f1 + |.endif + if (vk) { + | bne >1 + | add PC, PC, TMP2 + |1: + |.if not FFI + |3: + |.endif + } else { + | beq >2 + |1: + |.if not FFI + |3: + |.endif + | add PC, PC, TMP2 + |2: + } + | ins_next + |.if FFI + |3: + | cmpwi TMP0, LJ_TCDATA + | beq ->vmeta_equal_cd + | b <1 + |.endif + |.if DUALNUM + |7: // RA is not an integer. + | bge cr0, <3 + | // RA is a number. + | lfd f0, 0(RA) + | blt cr1, >1 + | // RA is a number, RD is an integer. + | tonum_i f1, CARG3 + | b >2 + | + |8: // RA is an integer, RD is a number. + | tonum_i f0, CARG2 + |1: + | lfd f1, 0(RD) + |2: + | fcmpu cr0, f0, f1 + | b <4 + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | lwzx TMP0, BASE, RA + | srwi TMP1, RD, 3 + | lwz TMP2, 0(PC) + | not TMP1, TMP1 + | addi PC, PC, 4 + |.if FFI + | cmpwi TMP0, LJ_TCDATA + |.endif + | sub TMP0, TMP0, TMP1 + |.if FFI + | beq ->vmeta_equal_cd + |.endif + | decode_RD4 TMP2, TMP2 + | .gpr64 extsw TMP0, TMP0 + | addic TMP0, TMP0, -1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | subfe TMP1, TMP1, TMP1 + if (vk) { + | and TMP2, TMP2, TMP1 + } else { + | andc TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | lwzx TMP0, BASE, RD + | lwz INS, 0(PC) + | addi PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE + | decode_RD4 TMP2, INS + | subfe TMP1, TMP1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (op == BC_IST) { + | andc TMP2, TMP2, TMP1 + } else { + | and TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + } else { + | li TMP1, LJ_TFALSE + | lfdx f0, BASE, RD + | cmplw TMP0, TMP1 + if (op == BC_ISTC) { + | bge >1 + } else { + | blt >1 + } + | addis PC, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | stfdx f0, BASE, RA + | add PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lfdx f0, BASE, RD + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lwzx TMP0, BASE, RD + | .gpr64 extsw TMP0, TMP0 + | subfic TMP1, TMP0, LJ_TTRUE + | adde TMP0, TMP0, TMP1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | lwzux TMP1, RD, BASE + | lwz TMP0, 4(RD) + | checknum TMP1 + |.if DUALNUM + | bne >5 + |.if GPR64 + | lus TMP2, 0x8000 + | neg TMP0, TMP0 + | cmplw TMP0, TMP2 + | beq >4 + |.else + | nego. TMP0, TMP0 + | bso >4 + |1: + |.endif + | ins_next1 + | stwux TISNUM, RA, BASE + | stw TMP0, 4(RA) + |3: + | ins_next2 + |4: + |.if not GPR64 + | // Potential overflow. + | mcrxr cr0; bley <1 // Ignore unrelated overflow. + |.endif + | lus TMP1, 0x41e0 // 2^31. + | li TMP0, 0 + | b >7 + |.endif + |5: + | bge ->vmeta_unm + | xoris TMP1, TMP1, 0x8000 + |7: + | ins_next1 + | stwux TMP1, RA, BASE + | stw TMP0, 4(RA) + |.if DUALNUM + | b <3 + |.else + | ins_next2 + |.endif + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | lwzux TMP0, RD, BASE + | lwz CARG1, 4(RD) + | checkstr TMP0; bne >2 + | lwz CRET1, STR:CARG1->len + |1: + |.if DUALNUM + | ins_next1 + | stwux TISNUM, RA, BASE + | stw CRET1, 4(RA) + |.else + | tonum_u f0, CRET1 // Result is a non-negative integer. + | ins_next1 + | stfdx f0, BASE, RA + |.endif + | ins_next2 + |2: + | checktab TMP0; bne ->vmeta_len +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | cmplwi TAB:TMP2, 0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b <1 +#if LJ_52 + |9: + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | lwzx TMP1, BASE, RB + | .if DUALNUM + | lwzx TMP2, KBASE, RC + | .endif + | lfdx f14, BASE, RB + | lfdx f15, KBASE, RC + | .if DUALNUM + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vn + | .else + | checknum TMP1; bge ->vmeta_arith_vn + | .endif + || break; + ||case 1: + | lwzx TMP1, BASE, RB + | .if DUALNUM + | lwzx TMP2, KBASE, RC + | .endif + | lfdx f15, BASE, RB + | lfdx f14, KBASE, RC + | .if DUALNUM + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_nv + | .else + | checknum TMP1; bge ->vmeta_arith_nv + | .endif + || break; + ||default: + | lwzx TMP1, BASE, RB + | lwzx TMP2, BASE, RC + | lfdx f14, BASE, RB + | lfdx f15, BASE, RC + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arithfallback, ins + ||switch (vk) { + ||case 0: + | ins ->vmeta_arith_vn2 + || break; + ||case 1: + | ins ->vmeta_arith_nv2 + || break; + ||default: + | ins ->vmeta_arith_vv2 + || break; + ||} + |.endmacro + | + |.macro intmod, a, b, c + | bl ->vm_modi + |.endmacro + | + |.macro fpmod, a, b, c + |->BC_MODVN_Z: + | fdiv FARG1, b, c + | // NYI: Use internal implementation of floor. + | blex floor // floor(b/c) + | fmul a, FARG1, c + | fsub a, b, a // b - floor(b/c)*c + |.endmacro + | + |.macro ins_arithfp, fpins + | ins_arithpre + |.if "fpins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |.else + | fpins f0, f14, f15 + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + |.endif + |.endmacro + | + |.macro ins_arithdn, intins, fpins + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, KBASE + | lwz CARG1, 4(RB) + | checknum cr0, TMP1 + | lwz CARG2, 4(RC) + || break; + ||case 1: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, KBASE + | lwz CARG2, 4(RB) + | checknum cr0, TMP1 + | lwz CARG1, 4(RC) + || break; + ||default: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, BASE + | lwz CARG1, 4(RB) + | checknum cr0, TMP1 + | lwz CARG2, 4(RC) + || break; + ||} + | checknum cr1, TMP2 + | bne >5 + | bne cr1, >5 + | intins CARG1, CARG1, CARG2 + | bso >4 + |1: + | ins_next1 + | stwux TISNUM, RA, BASE + | stw CARG1, 4(RA) + |2: + | ins_next2 + |4: // Overflow. + | mcrxr cr0; bley <1 // Ignore unrelated overflow. + | ins_arithfallback b + |5: // FP variant. + ||if (vk == 1) { + | lfd f15, 0(RB) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f14, 0(RC) + ||} else { + | lfd f14, 0(RB) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f15, 0(RC) + ||} + | ins_arithfallback bge + |.if "fpins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |.else + | fpins f0, f14, f15 + | ins_next1 + | stfdx f0, BASE, RA + | b <2 + |.endif + |.endmacro + | + |.macro ins_arith, intins, fpins + |.if DUALNUM + | ins_arithdn intins, fpins + |.else + | ins_arithfp fpins + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + |.if GPR64 + |.macro addo32., y, a, b + | // Need to check overflow for (a<<32) + (b<<32). + | rldicr TMP0, a, 32, 31 + | rldicr TMP3, b, 32, 31 + | addo. TMP0, TMP0, TMP3 + | add y, a, b + |.endmacro + | ins_arith addo32., fadd + |.else + | ins_arith addo., fadd + |.endif + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + |.if GPR64 + |.macro subo32., y, a, b + | // Need to check overflow for (a<<32) - (b<<32). + | rldicr TMP0, a, 32, 31 + | rldicr TMP3, b, 32, 31 + | subo. TMP0, TMP0, TMP3 + | sub y, a, b + |.endmacro + | ins_arith subo32., fsub + |.else + | ins_arith subo., fsub + |.endif + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith mullwo., fmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arithfp fdiv + break; + case BC_MODVN: + | ins_arith intmod, fpmod + break; + case BC_MODNV: case BC_MODVV: + | ins_arith intmod, fpmod_ + break; + case BC_POW: + | // NYI: (partial) integer arithmetic. + | lwzx TMP1, BASE, RB + | lfdx FARG1, BASE, RB + | lwzx TMP2, BASE, RC + | lfdx FARG2, BASE, RC + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vv + | blex pow + | ins_next1 + | stfdx FARG1, BASE, RA + | ins_next2 + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | sub CARG3, RC, RB + | stp BASE, L->base + | add CARG2, BASE, RC + | mr SAVE0, RB + |->BC_CAT_Z: + | stw PC, SAVE_PC + | mr CARG1, L + | srwi CARG3, CARG3, 3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | lp BASE, L->base + | bne ->vmeta_binop + | ins_next1 + | lfdx f0, BASE, SAVE0 // Copy result from RB to RA. + | stfdx f0, BASE, RA + | ins_next2 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | ins_next1 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4 + | li TMP2, LJ_TSTR + | stwux TMP2, RA, BASE + | stw TMP0, 4(RA) + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | ins_next1 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4 + | li TMP2, LJ_TCDATA + | stwux TMP2, RA, BASE + | stw TMP0, 4(RA) + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + |.if DUALNUM + | slwi RD, RD, 13 + | srawi RD, RD, 16 + | ins_next1 + | stwux TISNUM, RA, BASE + | stw RD, 4(RA) + | ins_next2 + |.else + | // The soft-float approach is faster. + | slwi RD, RD, 13 + | srawi TMP1, RD, 31 + | xor TMP2, TMP1, RD + | sub TMP2, TMP2, TMP1 // TMP2 = abs(x) + | cntlzw TMP3, TMP2 + | subfic TMP1, TMP3, 0x40d // TMP1 = exponent-1 + | slw TMP2, TMP2, TMP3 // TMP2 = left aligned mantissa + | subfic TMP3, RD, 0 + | slwi TMP1, TMP1, 20 + | rlwimi RD, TMP2, 21, 1, 31 // hi = sign(x) | (mantissa>>11) + | subfe TMP0, TMP0, TMP0 + | add RD, RD, TMP1 // hi = hi + exponent-1 + | and RD, RD, TMP0 // hi = x == 0 ? 0 : hi + | ins_next1 + | stwux RD, RA, BASE + | stw ZERO, 4(RA) + | ins_next2 + |.endif + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | ins_next1 + | lfdx f0, KBASE, RD + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srwi TMP1, RD, 3 + | not TMP0, TMP1 + | ins_next1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | stwx TISNIL, BASE, RA + | addi RA, RA, 8 + |1: + | stwx TISNIL, BASE, RA + | cmpw RA, RD + | addi RA, RA, 8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RD, RD, 1 + | addi RD, RD, offsetof(GCfuncL, uvptr) + | lwzx UPVAL:RB, LFUNC:RB, RD + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | lfd f0, 0(TMP1) + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lfdux f0, RD, BASE + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP0, UPVAL:RB->closed + | lwz TMP2, 0(RD) + | stfd f0, 0(CARG2) + | cmplwi cr1, TMP0, 0 + | lwz TMP1, 4(RD) + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | subi TMP2, TMP2, (LJ_TNUMX+1) + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1) + | bge <1 // tvisgcv(v) + | lbz TMP3, GCOBJ:TMP1->gch.marked + | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | srwi RA, RA, 1 + | subfic TMP1, TMP1, -4 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4 + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP3, STR:TMP1->marked + | lbz TMP2, UPVAL:RB->closed + | li TMP0, LJ_TSTR + | stw STR:TMP1, 4(CARG2) + | stw TMP0, 0(CARG2) + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(str) + | cmplwi cr1, TMP2, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lfdx f0, KBASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | stfd f0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | srwi TMP0, RD, 3 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | not TMP0, TMP0 + | lwzx UPVAL:RB, LFUNC:RB, RA + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | stw TMP0, 0(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lwz TMP1, L->openupval + | branch_RD // Do this first since RD is not saved. + | stp BASE, L->base + | cmplwi TMP1, 0 + | mr CARG1, L + | beq >1 + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | lp BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srwi TMP1, RD, 1 + | stp BASE, L->base + | subfic TMP1, TMP1, -4 + | stw PC, SAVE_PC + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | mr CARG1, L + | lwz CARG3, FRAME_FUNC(BASE) + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | lp BASE, L->base + | li TMP0, LJ_TFUNC + | stwux TMP0, RA, BASE + | stw LFUNC:CRET1, 4(RA) + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | mr CARG1, L + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | stp BASE, L->base + | cmplw TMP0, TMP1 + | stw PC, SAVE_PC + | bge >5 + |1: + if (op == BC_TNEW) { + | rlwinm CARG2, RD, 29, 21, 31 + | rlwinm CARG3, RD, 18, 27, 31 + | cmpwi CARG2, 0x7ff; beq >3 + |2: + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns Table *. + } else { + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns Table *. + } + | lp BASE, L->base + | li TMP0, LJ_TTAB + | stwux TMP0, RA, BASE + | stw TAB:CRET1, 4(RA) + | ins_next + if (op == BC_TNEW) { + |3: + | li CARG2, 0x801 + | b <2 + } + |5: + | mr SAVE0, RD + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mr RD, SAVE0 + | mr CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lwz LFUNC:TMP2, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | lwz TAB:RB, LFUNC:TMP2->env + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | lwzux CARG1, RB, BASE + | lwzux CARG2, RC, BASE + | lwz TAB:RB, 4(RB) + |.if DUALNUM + | lwz RC, 4(RC) + |.else + | lfd f0, 0(RC) + |.endif + | checktab CARG1 + | checknum cr1, CARG2 + | bne ->vmeta_tgetv + |.if DUALNUM + | lwz TMP0, TAB:RB->asize + | bne cr1, >5 + | lwz TMP1, TAB:RB->array + | cmplw TMP0, RC + | slwi TMP2, RC, 3 + |.else + | bge cr1, >5 + | // Convert number key to integer, check for integerness and range. + | fctiwz f1, f0 + | fadd f2, f0, TOBIT + | stfd f1, TMPD + | lwz TMP0, TAB:RB->asize + | fsub f2, f2, TOBIT + | lwz TMP2, TMPD_LO + | lwz TMP1, TAB:RB->array + | fcmpu cr1, f0, f2 + | cmplw cr0, TMP0, TMP2 + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq + | slwi TMP2, TMP2, 3 + |.endif + | ble ->vmeta_tgetv // Integer key and in array part? + | lwzx TMP0, TMP1, TMP2 + | lfdx f14, TMP1, TMP2 + | checknil TMP0; beq >2 + |1: + | ins_next1 + | stfdx f14, BASE, RA + | ins_next2 + | + |2: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_tgetv + | + |5: + | checkstr CARG2; bne ->vmeta_tgetv + |.if not DUALNUM + | lwz STR:RC, 4(RC) + |.endif + | b ->BC_TGETS_Z // String key? + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*8 (~) + | lwzux CARG1, RB, BASE + | srwi TMP1, RC, 1 + | lwz TAB:RB, 4(RB) + | subfic TMP1, TMP1, -4 + | checktab CARG1 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | bne ->vmeta_tgets1 + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lwz CARG1, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2) + | checkstr CARG1; bne >4 + | cmpw TMP0, STR:RC; bne >4 + | checknil CARG2; beq >5 // Key found, but nil value? + |3: + | stwux CARG2, RA, BASE + | stw TMP1, 4(RA) + | ins_next + | + |4: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, nil result. + | li CARG2, LJ_TNIL + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <3 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_tgets + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | lwzux CARG1, RB, BASE + | srwi TMP0, RC, 3 + | lwz TAB:RB, 4(RB) + | checktab CARG1; bne ->vmeta_tgetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | cmplw TMP0, TMP1; bge ->vmeta_tgetb + | lwzx TMP1, TMP2, RC + | lfdx f0, TMP2, RC + | checknil TMP1; beq >5 + |1: + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_tgetb // Caveat: preserve TMP0! + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | lwzux CARG1, RB, BASE + | lwzux CARG2, RC, BASE + | lwz TAB:RB, 4(RB) + |.if DUALNUM + | lwz RC, 4(RC) + |.else + | lfd f0, 0(RC) + |.endif + | checktab CARG1 + | checknum cr1, CARG2 + | bne ->vmeta_tsetv + |.if DUALNUM + | lwz TMP0, TAB:RB->asize + | bne cr1, >5 + | lwz TMP1, TAB:RB->array + | cmplw TMP0, RC + | slwi TMP0, RC, 3 + |.else + | bge cr1, >5 + | // Convert number key to integer, check for integerness and range. + | fctiwz f1, f0 + | fadd f2, f0, TOBIT + | stfd f1, TMPD + | lwz TMP0, TAB:RB->asize + | fsub f2, f2, TOBIT + | lwz TMP2, TMPD_LO + | lwz TMP1, TAB:RB->array + | fcmpu cr1, f0, f2 + | cmplw cr0, TMP0, TMP2 + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq + | slwi TMP0, TMP2, 3 + |.endif + | ble ->vmeta_tsetv // Integer key and in array part? + | lwzx TMP2, TMP1, TMP0 + | lbz TMP3, TAB:RB->marked + | lfdx f14, BASE, RA + | checknil TMP2; beq >3 + |1: + | andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table) + | stfdx f14, TMP1, TMP0 + | bne >7 + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_tsetv + | + |5: + | checkstr CARG2; bne ->vmeta_tsetv + |.if not DUALNUM + | lwz STR:RC, 4(RC) + |.endif + | b ->BC_TSETS_Z // String key? + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | lwzux CARG1, RB, BASE + | srwi TMP1, RC, 1 + | lwz TAB:RB, 4(RB) + | subfic TMP1, TMP1, -4 + | checktab CARG1 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | bne ->vmeta_tsets1 + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | stb ZERO, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | lfdx f14, BASE, RA + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | lbz TMP3, TAB:RB->marked + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lwz CARG1, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz NODE:TMP1, NODE:TMP2->next + | checkstr CARG1; bne >5 + | cmpw TMP0, STR:RC; bne >5 + | checknil CARG2; beq >4 // Key found, but nil value? + |2: + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stfd f14, NODE:TMP2->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <2 // No metatable: done. + | lbz TMP0, TAB:TMP1->nomm + | andix. TMP0, TMP0, 1<vmeta_tsets + | + |5: // Follow hash chain. + | cmplwi NODE:TMP1, 0 + | mr NODE:TMP2, NODE:TMP1 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | lwz TAB:TMP1, TAB:RB->metatable + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | stw PC, SAVE_PC + | mr CARG1, L + | cmplwi TAB:TMP1, 0 + | stp BASE, L->base + | beq >6 // No metatable: continue. + | lbz TMP0, TAB:TMP1->nomm + | andix. TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | li TMP0, LJ_TSTR + | stw STR:RC, 4(CARG3) + | mr CARG2, TAB:RB + | stw TMP0, 0(CARG3) + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | lp BASE, L->base + | stfd f14, 0(CRET1) + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | lwzux CARG1, RB, BASE + | srwi TMP0, RC, 3 + | lwz TAB:RB, 4(RB) + | checktab CARG1; bne ->vmeta_tsetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | lbz TMP3, TAB:RB->marked + | cmplw TMP0, TMP1 + | lfdx f14, BASE, RA + | bge ->vmeta_tsetb + | lwzx TMP1, TMP2, RC + | checknil TMP1; beq >5 + |1: + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stfdx f14, TMP2, RC + | bne >7 + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <1 // No metatable: done. + | lbz TMP1, TAB:TMP1->nomm + | andix. TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | add RA, BASE, RA + |1: + | add TMP3, KBASE, RD + | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table. + | addic. TMP0, MULTRES, -8 + | lwz TMP3, 4(TMP3) // Integer constant is in lo-word. + | srwi CARG3, TMP0, 3 + | beq >4 // Nothing to copy? + | add CARG3, CARG3, TMP3 + | lwz TMP2, TAB:CARG2->asize + | slwi TMP1, TMP3, 3 + | lbz TMP3, TAB:CARG2->marked + | cmplw CARG3, TMP2 + | add TMP2, RA, TMP0 + | lwz TMP0, TAB:CARG2->array + | bgt >5 + | add TMP1, TMP1, TMP0 + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | lfd f0, 0(RA) + | addi RA, RA, 8 + | cmpw cr1, RA, TMP2 + | stfd f0, 0(TMP1) + | addi TMP1, TMP1, 8 + | blt cr1, <3 + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | mr SAVE0, RD + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | mr RD, SAVE0 + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALL follows. + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | mr TMP2, BASE + | lwzux TMP0, BASE, RA + | lwz LFUNC:RB, 4(BASE) + | subi NARGS8:RC, NARGS8:RC, 8 + | addi BASE, BASE, 8 + | checkfunc TMP0; bne ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | lwzux TMP0, RA, BASE + | lwz LFUNC:RB, 4(RA) + | subi NARGS8:RC, NARGS8:RC, 8 + | lwz TMP1, FRAME_PC(BASE) + | checkfunc TMP0 + | addi RA, RA, 8 + | bne ->vmeta_callt + |->BC_CALLT_Z: + | andix. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand. + | lbz TMP3, LFUNC:RB->ffid + | xori TMP2, TMP1, FRAME_VARG + | cmplwi cr1, NARGS8:RC, 0 + | bne >7 + |1: + | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | li TMP2, 0 + | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function? + | beq cr1, >3 + |2: + | addi TMP3, TMP2, 8 + | lfdx f0, RA, TMP2 + | cmplw cr1, TMP3, NARGS8:RC + | stfdx f0, BASE, TMP2 + | mr TMP2, TMP3 + | bne cr1, <2 + |3: + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt + | beq >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lwz INS, -4(TMP1) + | decode_RA8 RA, INS + | sub TMP1, BASE, RA + | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1) + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | b <4 + | + |7: // Tailcall from a vararg function. + | andix. TMP0, TMP2, FRAME_TYPEP + | bne <1 // Vararg frame below? + | sub BASE, BASE, TMP2 // Relocate BASE down. + | lwz TMP1, FRAME_PC(BASE) + | andix. TMP0, TMP1, FRAME_TYPE + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | mr TMP2, BASE + | add BASE, BASE, RA + | lwz TMP1, -24(BASE) + | lwz LFUNC:RB, -20(BASE) + | lfd f1, -8(BASE) + | lfd f0, -16(BASE) + | stw TMP1, 0(BASE) // Copy callable. + | stw LFUNC:RB, 4(BASE) + | checkfunc TMP1 + | stfd f1, 16(BASE) // Copy control var. + | li NARGS8:RC, 16 // Iterators get 2 arguments. + | stfdu f0, 8(BASE) // Copy state. + | bne ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | lwz TAB:RB, -12(RA) + | lwz RC, -4(RA) // Get index from control var. + | lwz TMP0, TAB:RB->asize + | lwz TMP1, TAB:RB->array + | addi PC, PC, 4 + |1: // Traverse array part. + | cmplw RC, TMP0 + | slwi TMP3, RC, 3 + | bge >5 // Index points after array part? + | lwzx TMP2, TMP1, TMP3 + | lfdx f0, TMP1, TMP3 + | checknil TMP2 + | lwz INS, -4(PC) + | beq >4 + |.if DUALNUM + | stw RC, 4(RA) + | stw TISNUM, 0(RA) + |.else + | tonum_u f1, RC + |.endif + | addi RC, RC, 1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | stfd f0, 8(RA) + | decode_RD4 TMP1, INS + | stw RC, -4(RA) // Update control var. + | add PC, TMP1, TMP3 + |.if not DUALNUM + | stfd f1, 0(RA) + |.endif + |3: + | ins_next + | + |4: // Skip holes in array part. + | addi RC, RC, 1 + | b <1 + | + |5: // Traverse hash part. + | lwz TMP1, TAB:RB->hmask + | sub RC, RC, TMP0 + | lwz TMP2, TAB:RB->node + |6: + | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1. + | slwi TMP3, RC, 5 + | bgty <3 + | slwi RB, RC, 3 + | sub TMP3, TMP3, RB + | lwzx RB, TMP2, TMP3 + | lfdx f0, TMP2, TMP3 + | add NODE:TMP3, TMP2, TMP3 + | checknil RB + | lwz INS, -4(PC) + | beq >7 + | lfd f1, NODE:TMP3->key + | addis TMP2, PC, -(BCBIAS_J*4 >> 16) + | stfd f0, 8(RA) + | add RC, RC, TMP0 + | decode_RD4 TMP1, INS + | stfd f1, 0(RA) + | addi RC, RC, 1 + | add PC, TMP1, TMP2 + | stw RC, -4(RA) // Update control var. + | b <3 + | + |7: // Skip holes in hash part. + | addi RC, RC, 1 + | b <6 + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | add RA, BASE, RA + | lwz TMP0, -24(RA) + | lwz CFUNC:TMP1, -20(RA) + | lwz TMP2, -16(RA) + | lwz TMP3, -8(RA) + | cmpwi cr0, TMP2, LJ_TTAB + | cmpwi cr1, TMP0, LJ_TFUNC + | cmpwi cr6, TMP3, LJ_TNIL + | bne cr1, >5 + | lbz TMP1, CFUNC:TMP1->ffid + | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq + | cmpwi cr7, TMP1, FF_next_N + | srwi TMP0, RD, 1 + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | add TMP3, PC, TMP0 + | bne cr0, >5 + | lus TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | stw ZERO, -4(RA) // Initialize control var. + | stw TMP1, -8(RA) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP0, BC_JMP + | li TMP1, BC_ITERC + | stb TMP0, -1(PC) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + | stb TMP1, 3(PC) + | b <1 + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lwz TMP0, FRAME_PC(BASE) + | add RC, BASE, RC + | add RA, BASE, RA + | addi RC, RC, FRAME_VARG + | add TMP2, RA, RB + | subi TMP3, BASE, 8 // TMP3 = vtop + | sub RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmplwi cr1, RB, 0 + |.if PPE + | sub TMP1, TMP3, RC + | cmpwi TMP1, 0 + |.else + | sub. TMP1, TMP3, RC + |.endif + | beq cr1, >5 // Copy all varargs? + | subi TMP2, TMP2, 16 + | ble >2 // No vararg slots? + |1: // Copy vararg slots to destination slots. + | lfd f0, 0(RC) + | addi RC, RC, 8 + | stfd f0, 0(RA) + | cmplw RA, TMP2 + | cmplw cr1, RC, TMP3 + | bge >3 // All destination slots filled? + | addi RA, RA, 8 + | blt cr1, <1 // More vararg slots? + |2: // Fill up remainder with nil. + | stw TISNIL, 0(RA) + | cmplw RA, TMP2 + | addi RA, RA, 8 + | blt <2 + |3: + | ins_next + | + |5: // Copy all varargs. + | lwz TMP0, L->maxstack + | li MULTRES, 8 // MULTRES = (0+1)*8 + | bley <3 // No vararg slots? + | add TMP2, RA, TMP1 + | cmplw TMP2, TMP0 + | addi MULTRES, TMP1, 8 + | bgt >7 + |6: + | lfd f0, 0(RC) + | addi RC, RC, 8 + | stfd f0, 0(RA) + | cmplw RC, TMP3 + | addi RA, RA, 8 + | blt <6 // More vararg slots? + | b <3 + | + |7: // Grow stack for varargs. + | mr CARG1, L + | stp RA, L->top + | sub SAVE0, RC, BASE // Need delta, because BASE may change. + | stp BASE, L->base + | sub RA, RA, BASE + | stw PC, SAVE_PC + | srwi CARG2, TMP1, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | add RA, BASE, RA + | add RC, BASE, SAVE0 + | subi TMP3, BASE, 8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + |1: + | andix. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lwz INS, -4(PC) + | cmpwi RD, 8 + | subi TMP2, BASE, 8 + | subi RC, RD, 8 + | decode_RB8 RB, INS + | beq >3 + | li TMP1, 0 + |2: + | addi TMP3, TMP1, 8 + | lfdx f0, RA, TMP1 + | cmpw TMP3, RC + | stfdx f0, TMP2, TMP1 + | beq >3 + | addi TMP1, TMP3, 8 + | lfdx f1, RA, TMP3 + | cmpw TMP1, RC + | stfdx f1, TMP2, TMP3 + | bne <2 + |3: + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, TMP2, TMP1 + | b <5 + | + |->BC_RETV_Z: // Non-standard return case. + | andix. TMP2, TMP1, FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, TMP1 + | lwz PC, FRAME_PC(BASE) + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + | andix. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bney ->BC_RETV_Z + | + | lwz INS, -4(PC) + | subi TMP2, BASE, 8 + | decode_RB8 RB, INS + if (op == BC_RET1) { + | lfd f0, 0(RA) + | stfd f0, 0(TMP2) + } + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, TMP2, TMP1 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + |.if DUALNUM + | // Integer loop. + | lwzux TMP1, RA, BASE + | lwz CARG1, FORL_IDX*8+4(RA) + | cmplw cr0, TMP1, TISNUM + if (vk) { + | lwz CARG3, FORL_STEP*8+4(RA) + | bne >9 + |.if GPR64 + | // Need to check overflow for (a<<32) + (b<<32). + | rldicr TMP0, CARG1, 32, 31 + | rldicr TMP2, CARG3, 32, 31 + | add CARG1, CARG1, CARG3 + | addo. TMP0, TMP0, TMP2 + |.else + | addo. CARG1, CARG1, CARG3 + |.endif + | cmpwi cr6, CARG3, 0 + | lwz CARG2, FORL_STOP*8+4(RA) + | bso >6 + |4: + | stw CARG1, FORL_IDX*8+4(RA) + } else { + | lwz TMP3, FORL_STEP*8(RA) + | lwz CARG3, FORL_STEP*8+4(RA) + | lwz TMP2, FORL_STOP*8(RA) + | lwz CARG2, FORL_STOP*8+4(RA) + | cmplw cr7, TMP3, TISNUM + | cmplw cr1, TMP2, TISNUM + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | cmpwi cr6, CARG3, 0 + | bne >9 + } + | blt cr6, >5 + | cmpw CARG1, CARG2 + |1: + | stw TISNUM, FORL_EXT*8(RA) + if (op != BC_JFORL) { + | srwi RD, RD, 1 + } + | stw CARG1, FORL_EXT*8+4(RA) + if (op != BC_JFORL) { + | add RD, PC, RD + } + if (op == BC_FORI) { + | bgt >3 // See FP loop below. + } else if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + | bley >7 + } else if (op == BC_IFORL) { + | bgt >2 + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else { + | bley =>BC_JLOOP + } + |2: + | ins_next + |5: // Invert check for negative step. + | cmpw CARG2, CARG1 + | b <1 + if (vk) { + |6: // Potential overflow. + | mcrxr cr0; bley <4 // Ignore unrelated overflow. + | b <2 + } + |.endif + if (vk) { + |.if DUALNUM + |9: // FP loop. + | lfd f1, FORL_IDX*8(RA) + |.else + | lfdux f1, RA, BASE + |.endif + | lfd f3, FORL_STEP*8(RA) + | lfd f2, FORL_STOP*8(RA) + | lwz TMP3, FORL_STEP*8(RA) + | fadd f1, f1, f3 + | stfd f1, FORL_IDX*8(RA) + } else { + |.if DUALNUM + |9: // FP loop. + |.else + | lwzux TMP1, RA, BASE + | lwz TMP3, FORL_STEP*8(RA) + | lwz TMP2, FORL_STOP*8(RA) + | cmplw cr0, TMP1, TISNUM + | cmplw cr7, TMP3, TISNUM + | cmplw cr1, TMP2, TISNUM + |.endif + | lfd f1, FORL_IDX*8(RA) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f2, FORL_STOP*8(RA) + | bge ->vmeta_for + } + | cmpwi cr6, TMP3, 0 + if (op != BC_JFORL) { + | srwi RD, RD, 1 + } + | stfd f1, FORL_EXT*8(RA) + if (op != BC_JFORL) { + | add RD, PC, RD + } + | fcmpu cr0, f1, f2 + if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } + | blt cr6, >5 + if (op == BC_FORI) { + | bgt >3 + } else if (op == BC_IFORL) { + |.if DUALNUM + | bgty <2 + |.else + | bgt >2 + |.endif + |1: + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else if (op == BC_JFORI) { + | bley >7 + } else { + | bley =>BC_JLOOP + } + |.if DUALNUM + | b <2 + |.else + |2: + | ins_next + |.endif + |5: // Negative step. + if (op == BC_FORI) { + | bge <2 + |3: // Used by integer loop, too. + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else if (op == BC_IFORL) { + | bgey <1 + } else if (op == BC_JFORI) { + | bgey >7 + } else { + | bgey =>BC_JLOOP + } + | b <2 + if (op == BC_JFORI) { + |7: + | lwz INS, -4(PC) + | decode_RD8 RD, INS + | b =>BC_JLOOP + } + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | lwzux TMP1, RA, BASE + | lwz TMP2, 4(RA) + | checknil TMP1; beq >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | stw TMP1, -8(RA) + | stw TMP2, -4(RA) + | b =>BC_JLOOP + } else { + | branch_RD // Otherwise save control var + branch. + | stw TMP1, -8(RA) + | stw TMP2, -4(RA) + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base*8 (ignored), RD = traceno*8 + | lwz TMP1, DISPATCH_J(trace)(DISPATCH) + | srwi RD, RD, 1 + | // Traces on PPC don't store the trace number, so use 0. + | stw ZERO, DISPATCH_GL(vmstate)(DISPATCH) + | lwzx TRACE:TMP2, TMP1, RD + | mcrxr cr0 // Clear SO flag. + | lp TMP2, TRACE:TMP2->mcode + | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | mtctr TMP2 + | stw L, DISPATCH_GL(jit_L)(DISPATCH) + | addi JGL, DISPATCH, GG_DISP2G+32768 + | bctr + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | lbz TMP1, -4+PC2PROTO(numparams)(PC) + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw RA, TMP2 + | slwi TMP1, TMP1, 3 + | bgt ->vm_growstack_l + if (op != BC_JFUNCF) { + | ins_next1 + } + |2: + | cmplw NARGS8:RC, TMP1 // Check for missing parameters. + | blt >3 + if (op == BC_JFUNCF) { + | decode_RD8 RD, INS + | b =>BC_JLOOP + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | stwx TISNIL, BASE, NARGS8:RC + | addi NARGS8:RC, NARGS8:RC, 8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | add TMP1, BASE, RC + | add TMP0, RA, RC + | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC. + | addi TMP3, RC, 8+FRAME_VARG + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw TMP0, TMP2 + | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG. + | bge ->vm_growstack_l + | lbz TMP2, -4+PC2PROTO(numparams)(PC) + | mr RA, BASE + | mr RC, TMP1 + | ins_next1 + | cmpwi TMP2, 0 + | addi BASE, TMP1, 8 + | beq >3 + |1: + | cmplw RA, RC // Less args than parameters? + | lwz TMP0, 0(RA) + | lwz TMP3, 4(RA) + | bge >4 + | stw TISNIL, 0(RA) // Clear old fixarg slot (help the GC). + | addi RA, RA, 8 + |2: + | addic. TMP2, TMP2, -1 + | stw TMP0, 8(TMP1) + | stw TMP3, 12(TMP1) + | addi TMP1, TMP1, 8 + | bne <1 + |3: + | ins_next2 + | + |4: // Clear missing parameters. + | li TMP0, LJ_TNIL + | b <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lp RD, CFUNC:RB->f + } else { + | lp RD, DISPATCH_GL(wrapf)(DISPATCH) + } + | add TMP1, RA, NARGS8:RC + | lwz TMP2, L->maxstack + | .toc lp TMP3, 0(RD) + | add RC, BASE, NARGS8:RC + | stp BASE, L->base + | cmplw TMP1, TMP2 + | stp RC, L->top + | li_vmstate C + |.if TOC + | mtctr TMP3 + |.else + | mtctr RD + |.endif + if (op == BC_FUNCCW) { + | lp CARG2, CFUNC:RB->f + } + | mr CARG1, L + | bgt ->vm_growstack_c // Need to grow stack. + | .toc lp TOCREG, TOC_OFS(RD) + | .tocenv lp ENVREG, ENV_OFS(RD) + | st_vmstate + | bctrl // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | lp BASE, L->base + | .toc ld TOCREG, SAVE_TOC + | slwi RD, CRET1, 3 + | lp TMP1, L->top + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. + | sub RA, TMP1, RD // RA = L->top - nresults*8 + | st_vmstate + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n", + fcofs, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte %d\n\t.uleb128 %d\n", + 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" +#if LJ_TARGET_PS3 + "\t.long .lj_vm_ffi_call\n" +#else + "\t.long lj_vm_ffi_call\n" +#endif + "\t.long %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x8e\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0xe\n" + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif +#if !LJ_NO_UNWIND + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.long .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.long .LASFDE2-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n", + fcofs, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte %d\n\t.uleb128 %d\n", + 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE2:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.long .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.long .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.long .LASFDE3-.Lframe2\n" + "\t.long lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x8e\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0xe\n" + "\t.align 2\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif +#endif + break; + default: + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppcspe.dasc b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppcspe.dasc new file mode 100644 index 0000000..adcec24 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_ppcspe.dasc @@ -0,0 +1,3691 @@ +|// Low-level VM code for PowerPC/e500 CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch ppc +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r1 = sp, r2 and r13 = reserved and/or small data area ptr +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r14 // Base of current Lua stack frame. +|.define KBASE, r15 // Constants of current Lua function. +|.define PC, r16 // Next PC. +|.define DISPATCH, r17 // Opcode dispatch table. +|.define LREG, r18 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. +| +|// Constants for vectorized type-comparisons (hi+low GPR). C callee-save. +|.define TISNUM, r22 +|.define TISSTR, r23 +|.define TISTAB, r24 +|.define TISFUNC, r25 +|.define TISNIL, r26 +|.define TOBIT, r27 +|.define ZERO, TOBIT // Zero in lo word. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r20 // Callee-save. +|.define RB, r10 +|.define RC, r11 +|.define RD, r12 +|.define INS, r7 // Overlaps CARG5. +| +|.define TMP0, r0 +|.define TMP1, r8 +|.define TMP2, r9 +|.define TMP3, r6 // Overlaps CARG4. +| +|// Saved temporaries. +|.define SAVE0, r21 +| +|// Calling conventions. +|.define CARG1, r3 +|.define CARG2, r4 +|.define CARG3, r5 +|.define CARG4, r6 // Overlaps TMP3. +|.define CARG5, r7 // Overlaps INS. +| +|.define CRET1, r3 +|.define CRET2, r4 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define SAVE_LR, 188(sp) +|.define CFRAME_SPACE, 184 // Delta for sp. +|// Back chain for sp: 184(sp) <-- sp entering interpreter +|.define SAVE_r31, 176(sp) // 64 bit register saves. +|.define SAVE_r30, 168(sp) +|.define SAVE_r29, 160(sp) +|.define SAVE_r28, 152(sp) +|.define SAVE_r27, 144(sp) +|.define SAVE_r26, 136(sp) +|.define SAVE_r25, 128(sp) +|.define SAVE_r24, 120(sp) +|.define SAVE_r23, 112(sp) +|.define SAVE_r22, 104(sp) +|.define SAVE_r21, 96(sp) +|.define SAVE_r20, 88(sp) +|.define SAVE_r19, 80(sp) +|.define SAVE_r18, 72(sp) +|.define SAVE_r17, 64(sp) +|.define SAVE_r16, 56(sp) +|.define SAVE_r15, 48(sp) +|.define SAVE_r14, 40(sp) +|.define SAVE_CR, 36(sp) +|.define UNUSED1, 32(sp) +|.define SAVE_ERRF, 28(sp) // 32 bit C frame info. +|.define SAVE_NRES, 24(sp) +|.define SAVE_CFRAME, 20(sp) +|.define SAVE_L, 16(sp) +|.define SAVE_PC, 12(sp) +|.define SAVE_MULTRES, 8(sp) +|// Next frame lr: 4(sp) +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.macro save_, reg; evstdd reg, SAVE_..reg; .endmacro +|.macro rest_, reg; evldd reg, SAVE_..reg; .endmacro +| +|.macro saveregs +| stwu sp, -CFRAME_SPACE(sp) +| save_ r14; save_ r15; save_ r16; save_ r17; save_ r18; save_ r19 +| mflr r0; mfcr r12 +| save_ r20; save_ r21; save_ r22; save_ r23; save_ r24; save_ r25 +| stw r0, SAVE_LR; stw r12, SAVE_CR +| save_ r26; save_ r27; save_ r28; save_ r29; save_ r30; save_ r31 +|.endmacro +| +|.macro restoreregs +| lwz r0, SAVE_LR; lwz r12, SAVE_CR +| rest_ r14; rest_ r15; rest_ r16; rest_ r17; rest_ r18; rest_ r19 +| mtlr r0; mtcrf 0x38, r12 +| rest_ r20; rest_ r21; rest_ r22; rest_ r23; rest_ r24; rest_ r25 +| rest_ r26; rest_ r27; rest_ r28; rest_ r29; rest_ r30; rest_ r31 +| addi sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// These basic macros should really be part of DynASM. +|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro +|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro +|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro +|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro +|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro +| +|// Trap for not-yet-implemented parts. +|.macro NYI; tw 4, sp, sp; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_PC, -8 +|.define FRAME_FUNC, -4 +| +|// Instruction decode. +|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro +|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro +|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro +|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro +|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro +| +|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro +|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lwz INS, 0(PC) +| addi PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT2 +| decode_OP4 TMP1, INS +| decode_RB8 RB, INS +| decode_RD8 RD, INS +| lwzx TMP0, DISPATCH, TMP1 +| decode_RA8 RA, INS +| decode_RC8 RC, INS +| mtctr TMP0 +| bctr +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lwz PC, LFUNC:RB->pc +| lwz INS, 0(PC) +| addi PC, PC, 4 +| decode_OP4 TMP1, INS +| decode_RA8 RA, INS +| lwzx TMP0, DISPATCH, TMP1 +| add RA, RA, BASE +| mtctr TMP0 +| bctr +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| stw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checknum, reg; evcmpltu reg, TISNUM; .endmacro +|.macro checkstr, reg; evcmpeq reg, TISSTR; .endmacro +|.macro checktab, reg; evcmpeq reg, TISTAB; .endmacro +|.macro checkfunc, reg; evcmpeq reg, TISFUNC; .endmacro +|.macro checknil, reg; evcmpeq reg, TISNIL; .endmacro +|.macro checkok, label; blt label; .endmacro +|.macro checkfail, label; bge label; .endmacro +|.macro checkanyfail, label; bns label; .endmacro +|.macro checkallok, label; bso label; .endmacro +| +|.macro branch_RD +| srwi TMP0, RD, 1 +| add PC, PC, TMP0 +| addis PC, PC, -(BCBIAS_J*4 >> 16) +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotloop +| NYI +|.endmacro +| +|.macro hotcall +| NYI +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| // Assumes LJ_GC_BLACK is 0x04. +| rlwinm mark, mark, 0, 30, 28 // black2gray(tab) +| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| stb mark, tab->marked +| stw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andi. TMP0, PC, FRAME_P + | evsplati TMP1, LJ_TTRUE + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | mr BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | stwu TMP1, FRAME_PC(RA) // Prepend true to results. + | + |->vm_returnc: + | addi RD, RD, 8 // RD = (nresults+1)*8. + | andi. TMP0, PC, FRAME_TYPE + | cmpwi cr1, RD, 0 + | li CRET1, LUA_YIELD + | beq cr1, ->vm_unwind_c_eh + | mr MULTRES, RD + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | cmpwi TMP0, FRAME_C + | rlwinm TMP2, PC, 0, 0, 28 + | li_vmstate C + | sub TMP2, BASE, TMP2 // TMP2 = previous base. + | bne ->vm_returnp + | + | addic. TMP1, RD, -8 + | stw TMP2, L->base + | lwz TMP2, SAVE_NRES + | subi BASE, BASE, 8 + | st_vmstate + | slwi TMP2, TMP2, 3 + | beq >2 + |1: + | addic. TMP1, TMP1, -8 + | evldd TMP0, 0(RA) + | addi RA, RA, 8 + | evstdd TMP0, 0(BASE) + | addi BASE, BASE, 8 + | bne <1 + | + |2: + | cmpw TMP2, RD // More/less results wanted? + | bne >6 + |3: + | stw BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lwz TMP0, SAVE_CFRAME // Restore previous C frame. + | li CRET1, 0 // Ok return status for vm_pcall. + | stw TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs + | blr + | + |6: + | ble >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | lwz TMP1, L->maxstack + | cmplw BASE, TMP1 + | bge >8 + | evstdd TISNIL, 0(BASE) + | addi RD, RD, 8 + | addi BASE, BASE, 8 + | b <2 + | + |7: // Less results wanted. + | sub TMP0, RD, TMP2 + | cmpwi TMP2, 0 // LUA_MULTRET+1 case? + | sub TMP0, BASE, TMP0 // Subtract the difference. + | iseleq BASE, BASE, TMP0 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | stw BASE, L->top // Save current top held in BASE (yes). + | mr SAVE0, RD + | mr CARG2, TMP2 + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz TMP2, SAVE_NRES + | mr RD, SAVE0 + | slwi TMP2, TMP2, 3 + | lwz BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mr sp, CARG1 + | mr CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | li TMP0, ~LJ_VMST_C + | lwz GL:TMP1, L->glref + | stw TMP0, GL:TMP1->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | rlwinm sp, CARG1, 0, 0, 29 + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | evsplati TISFUNC, LJ_TFUNC + | lus TOBIT, 0x4338 + | evsplati TISTAB, LJ_TTAB + | li TMP0, 0 + | lwz BASE, L->base + | evmergelo TOBIT, TOBIT, TMP0 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | evsplati TISSTR, LJ_TSTR + | li TMP1, LJ_TFALSE + | evsplati TISNIL, LJ_TNIL + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | la RA, -8(BASE) // Results start at BASE-8. + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw TMP1, 0(RA) // Prepend false to error message. + | li RD, 16 // 2 results: false + error message. + | st_vmstate + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | li CARG2, LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | stw BASE, L->base + | addi PC, PC, 4 // Must point after first instruction. + | stw RC, L->top + | srwi CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | stw PC, SAVE_PC + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | lwz RC, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mr L, CARG1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | mr BASE, CARG2 + | lbz TMP1, L->status + | stw L, SAVE_L + | li PC, FRAME_CP + | addi TMP0, sp, CFRAME_RESUME + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw CARG3, SAVE_NRES + | cmplwi TMP1, 0 + | stw CARG3, SAVE_ERRF + | stw TMP0, L->cframe + | stw CARG3, SAVE_CFRAME + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mr RA, BASE + | lwz BASE, L->base + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | lwz TMP1, L->top + | evsplati TISFUNC, LJ_TFUNC + | lus TOBIT, 0x4338 + | evsplati TISTAB, LJ_TTAB + | lwz PC, FRAME_PC(BASE) + | li TMP2, 0 + | evsplati TISSTR, LJ_TSTR + | sub RD, TMP1, BASE + | evmergelo TOBIT, TOBIT, TMP2 + | stb CARG3, L->status + | andi. TMP0, PC, FRAME_TYPE + | li_vmstate INTERP + | addi RD, RD, 8 + | evsplati TISNIL, LJ_TNIL + | mr MULTRES, RD + | st_vmstate + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | li PC, FRAME_CP + | stw CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lwz TMP1, L:CARG1->cframe + | stw CARG3, SAVE_NRES + | mr L, CARG1 + | stw CARG1, SAVE_L + | mr BASE, CARG2 + | stw sp, L->cframe // Add our C frame to cframe chain. + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | stw TMP1, SAVE_CFRAME + | addi DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lwz TMP2, L->base // TMP2 = old base (used in vmeta_call). + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | lwz TMP1, L->top + | evsplati TISFUNC, LJ_TFUNC + | add PC, PC, BASE + | evsplati TISTAB, LJ_TTAB + | lus TOBIT, 0x4338 + | li TMP0, 0 + | sub PC, PC, TMP2 // PC = frame delta + frame type + | evsplati TISSTR, LJ_TSTR + | sub NARGS8:RC, TMP1, BASE + | evmergelo TOBIT, TOBIT, TMP0 + | li_vmstate INTERP + | evsplati TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | li TMP0, -8 + | evlddx LFUNC:RB, BASE, TMP0 + | checkfunc LFUNC:RB + | checkfail ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mr L, CARG1 + | lwz TMP0, L:CARG1->stack + | stw CARG1, SAVE_L + | lwz TMP1, L->top + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lwz TMP1, L->cframe + | stw sp, L->cframe // Add our C frame to cframe chain. + | li TMP2, 0 + | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | stw TMP2, SAVE_ERRF // No error function. + | stw TMP1, SAVE_CFRAME + | mtctr CARG4 + | bctrl // (lua_State *L, lua_CFunction func, void *ud) + | mr. BASE, CRET1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | addi DISPATCH, DISPATCH, GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lwz TMP0, -12(BASE) // Continuation. + | mr RB, BASE + | mr BASE, TMP2 // Restore caller BASE. + | lwz LFUNC:TMP1, FRAME_FUNC(TMP2) + | cmplwi TMP0, 0 + | lwz PC, -16(RB) // Restore PC from [cont|PC]. + | beq >1 + | subi TMP2, RD, 8 + | lwz TMP1, LFUNC:TMP1->pc + | evstddx TISNIL, RA, TMP2 // Ensure one valid arg. + | lwz KBASE, PC2PROTO(k)(TMP1) + | // BASE = base, RA = resultptr, RB = meta base + | mtctr TMP0 + | bctr // Jump to continuation. + | + |1: // Tail call from C function. + | subi TMP1, RB, 16 + | sub RC, TMP1, BASE + | b ->vm_call_tail + | + |->cont_cat: // RA = resultptr, RB = meta base + | lwz INS, -4(PC) + | subi CARG2, RB, 16 + | decode_RB8 SAVE0, INS + | evldd TMP0, 0(RA) + | add TMP1, BASE, SAVE0 + | stw BASE, L->base + | cmplw TMP1, CARG2 + | sub CARG3, CARG2, TMP1 + | decode_RA8 RA, INS + | evstdd TMP0, 0(CARG2) + | bne ->BC_CAT_Z + | evstddx TMP0, BASE, RA + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | evmergelo STR:RC, TISSTR, STR:RC + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | decode_RB8 RB, INS + | evstdd STR:RC, 0(CARG3) + | add CARG2, BASE, RB + | b >1 + | + |->vmeta_tgets: + | evmergelo TAB:RB, TISTAB, TAB:RB + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo STR:RC, TISSTR, STR:RC + | evstdd TAB:RB, 0(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | evstdd STR:RC, 0(CARG3) + | b >1 + | + |->vmeta_tgetb: // TMP0 = index + | efdcfsi TMP0, TMP0 + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + | evstdd TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tgetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | beq >3 + | evldd TMP0, 0(CRET1) + | evstddx TMP0, BASE, RA + | ins_next + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | subfic TMP1, BASE, FRAME_CONT + | lwz BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 16 // 2 args for func(t, k). + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | evmergelo STR:RC, TISSTR, STR:RC + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | decode_RB8 RB, INS + | evstdd STR:RC, 0(CARG3) + | add CARG2, BASE, RB + | b >1 + | + |->vmeta_tsets: + | evmergelo TAB:RB, TISTAB, TAB:RB + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo STR:RC, TISSTR, STR:RC + | evstdd TAB:RB, 0(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | evstdd STR:RC, 0(CARG3) + | b >1 + | + |->vmeta_tsetb: // TMP0 = index + | efdcfsi TMP0, TMP0 + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + | evstdd TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tsetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | evlddx TMP0, BASE, RA + | beq >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | evstdd TMP0, 0(CRET1) + | ins_next + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | subfic TMP1, BASE, FRAME_CONT + | lwz BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 24 // 3 args for func(t, k, v) + | evstdd TMP0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mr CARG1, L + | subi PC, PC, 4 + | add CARG2, BASE, RA + | stw PC, SAVE_PC + | add CARG3, BASE, RD + | stw BASE, L->base + | decode_OP1 CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | cmplwi CRET1, 1 + | bgt ->vmeta_binop + |4: + | lwz INS, 0(PC) + | addi PC, PC, 4 + | decode_RD4 TMP2, INS + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | add TMP2, TMP2, TMP3 + | isellt PC, PC, TMP2 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lwz INS, -4(PC) + | evldd TMP0, 0(RA) + | decode_RA8 TMP1, INS + | evstddx TMP0, BASE, TMP1 + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | lwz TMP0, 0(RA) + | li TMP1, LJ_TTRUE + | cmplw TMP1, TMP0 // Branch if result is true. + | b <4 + | + |->cont_condf: // RA = resultptr + | lwz TMP0, 0(RA) + | li TMP1, LJ_TFALSE + | cmplw TMP0, TMP1 // Branch if result is false. + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | subi PC, PC, 4 + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vn: + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_nv: + | add CARG3, KBASE, RC + | add CARG4, BASE, RB + | b >1 + | + |->vmeta_unm: + | add CARG3, BASE, RD + | mr CARG4, CARG3 + | b >1 + | + |->vmeta_arith_vv: + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |1: + | add CARG2, BASE, RA + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS. + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub TMP1, CRET1, BASE + | stw PC, -16(CRET1) // [cont|PC] + | mr TMP2, BASE + | addi PC, TMP1, FRAME_CONT + | mr BASE, CRET1 + | li NARGS8:RC, 16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: +#if LJ_52 + | mr SAVE0, CARG1 +#endif + | add CARG2, BASE, RD + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | cmplwi CRET1, 0 + | bne ->vmeta_binop // Binop call for compatibility. + | mr CARG1, SAVE0 + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | mr CARG1, L + | stw TMP2, L->base // This is the callers base! + | subi CARG2, BASE, 8 + | stw PC, SAVE_PC + | add CARG3, BASE, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mr CARG1, L + | stw BASE, L->base + | subi CARG2, RA, 8 + | stw PC, SAVE_PC + | add CARG3, RA, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz TMP1, FRAME_PC(BASE) + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mr CARG1, L + | stw BASE, L->base + | mr CARG2, RA + | stw PC, SAVE_PC + | mr SAVE0, INS + | bl extern lj_meta_for // (lua_State *L, TValue *base) + |.if JIT + | decode_OP1 TMP0, SAVE0 + |.endif + | decode_RA8 RA, SAVE0 + |.if JIT + | cmpwi TMP0, BC_JFORI + |.endif + | decode_RD8 RD, SAVE0 + |.if JIT + | beq =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | evldd CARG1, 0(BASE) + | evldd CARG2, 8(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | checknum CARG1 + | checkfail ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | evmergehi TMP0, CARG1, CARG2 + | checknum TMP0 + | checkanyfail ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1. + |.macro ffgccheck + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | cmplw TMP0, TMP1 + | bgel ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc assert + | cmplwi NARGS8:RC, 8 + | evldd TMP0, 0(BASE) + | blt ->fff_fallback + | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE. + | la RA, -8(BASE) + | evcmpltu cr1, TMP0, TMP1 + | lwz PC, FRAME_PC(BASE) + | bge cr1, ->fff_fallback + | evstdd TMP0, 0(RA) + | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | beq ->fff_res // Done if exactly 1 argument. + | li TMP1, 8 + | subi RC, RC, 8 + |1: + | cmplw TMP1, RC + | evlddx TMP0, BASE, TMP1 + | evstddx TMP0, RA, TMP1 + | addi TMP1, TMP1, 8 + | bne <1 + | b ->fff_res + | + |.ffunc type + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | blt ->fff_fallback + | li TMP2, ~LJ_TNUMX + | cmplw CARG1, TISNUM + | not TMP1, CARG1 + | isellt TMP1, TMP2, TMP1 + | slwi TMP1, TMP1, 3 + | la TMP2, CFUNC:RB->upvalue + | evlddx STR:CRET1, TMP2, TMP1 + | b ->fff_restv + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktab CARG1 + | evmergehi TMP1, CARG1, CARG1 + | checkfail >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:RB, TAB:CARG1->metatable + |2: + | evmr CRET1, TISNIL + | cmplwi TAB:RB, 0 + | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beq ->fff_restv + | lwz TMP0, TAB:RB->hmask + | evmergelo CRET1, TISTAB, TAB:RB // Use metatable as default result. + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |3: // Rearranged logic, because we expect _not_ to find the key. + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | lwz NODE:TMP2, NODE:TMP2->next + | checkallok >5 + | cmplwi NODE:TMP2, 0 + | beq ->fff_restv // Not found, keep default result. + | b <3 + |5: + | checknil TMP1 + | checkok ->fff_restv // Ditto for nil value. + | evmr CRET1, TMP1 // Return value of mt.__metatable. + | b ->fff_restv + | + |6: + | cmpwi TMP1, LJ_TUDATA + | not TMP1, TMP1 + | beq <1 + | checknum CARG1 + | slwi TMP1, TMP1, 2 + | li TMP2, 4*~LJ_TNUMX + | isellt TMP1, TMP2, TMP1 + | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH) + | lwzx TAB:RB, TMP2, TMP1 + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | evmergehi TMP0, TAB:CARG1, TAB:CARG2 + | checktab TMP0 + | checkanyfail ->fff_fallback + | lwz TAB:TMP1, TAB:CARG1->metatable + | cmplwi TAB:TMP1, 0 + | lbz TMP3, TAB:CARG1->marked + | bne ->fff_fallback + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stw TAB:CARG2, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, TMP3, TMP0 + | b ->fff_restv + | + |.ffunc rawget + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checktab CARG2 + | la CARG3, 8(BASE) + | checkfail ->fff_fallback + | mr CARG1, L + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | evldd CRET1, 0(CRET1) + | b ->fff_restv + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | bne ->fff_fallback // Exactly one argument. + | checknum CARG1 + | checkok ->fff_restv + | b ->fff_fallback + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checkstr CARG1 + | // A __tostring method in the string base metatable is ignored. + | checkok ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | checknum CARG1 + | cmplwi cr1, TMP0, 0 + | stw BASE, L->base // Add frame since C call can throw. + | crand 4*cr0+eq, 4*cr0+lt, 4*cr1+eq + | stw PC, SAVE_PC // Redundant (but a defined value). + | bne ->fff_fallback + | ffgccheck + | mr CARG1, L + | mr CARG2, BASE + | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) + | // Returns GCstr *. + | evmergelo STR:CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | evstddx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + | checktab TAB:CARG2 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback + | stw BASE, L->base // Add frame since C call can throw. + | mr CARG1, L + | stw BASE, L->top // Dummy frame length is ok. + | la CARG3, 8(BASE) + | stw PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | cmplwi CRET1, 0 + | evmr CRET1, TISNIL + | beq ->fff_restv // End of traversal: return nil. + | evldd TMP0, 8(BASE) // Copy key and value to results. + | la RA, -8(BASE) + | evldd TMP1, 16(BASE) + | evstdd TMP0, 0(RA) + | li RD, (2+1)*8 + | evstdd TMP1, 8(RA) + | b ->fff_res + | + |.ffunc_1 pairs + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | evstdd TISNIL, 8(BASE) + | li RD, (3+1)*8 + | evstdd CFUNC:TMP0, 0(RA) + | b ->fff_res + | + |.ffunc_2 ipairs_aux + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback + | checknum CARG2 + | lus TMP3, 0x3ff0 + | checkfail ->fff_fallback + | efdctsi TMP2, CARG2 + | lwz TMP0, TAB:CARG1->asize + | evmergelo TMP3, TMP3, ZERO + | lwz TMP1, TAB:CARG1->array + | efdadd CARG2, CARG2, TMP3 + | addi TMP2, TMP2, 1 + | la RA, -8(BASE) + | cmplw TMP0, TMP2 + | slwi TMP3, TMP2, 3 + | evstdd CARG2, 0(RA) + | ble >2 // Not in array part? + | evlddx TMP1, TMP1, TMP3 + |1: + | checknil TMP1 + | li RD, (0+1)*8 + | checkok ->fff_res // End of iteration, return 0 results. + | li RD, (2+1)*8 + | evstdd TMP1, 8(RA) + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | lwz TMP0, TAB:CARG1->hmask + | cmplwi TMP0, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | mr CARG2, TMP2 + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | cmplwi CRET1, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | evldd TMP1, 0(CRET1) + | b <1 + | + |.ffunc_1 ipairs + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | evsplati TMP1, 0 + | li RD, (3+1)*8 + | evstdd TMP1, 8(BASE) + | evstdd CFUNC:TMP0, 0(RA) + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | cmplwi NARGS8:RC, 8 + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | blt ->fff_fallback + | mr TMP2, BASE + | la BASE, 8(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | subi NARGS8:RC, NARGS8:RC, 8 + | addi PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + | + |.ffunc_2 xpcall + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | mr TMP2, BASE + | checkfunc CARG2 // Traceback must be a function. + | checkfail ->fff_fallback + | la BASE, 16(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | evstdd CARG2, 0(TMP2) // Swap function and traceback. + | subi NARGS8:RC, NARGS8:RC, 16 + | evstdd CARG1, 8(TMP2) + | addi PC, TMP3, 16+FRAME_PCALL + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | evmergehi TMP0, L:CARG1, L:CARG1 + |.else + |.ffunc coroutine_wrap_aux + | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + |.if resume + | cmpwi TMP0, LJ_TTHREAD + | bne ->fff_fallback + |.endif + | lbz TMP0, L:CARG1->status + | lwz TMP1, L:CARG1->cframe + | lwz CARG2, L:CARG1->top + | cmplwi cr0, TMP0, LUA_YIELD + | lwz TMP2, L:CARG1->base + | cmplwi cr1, TMP1, 0 + | lwz TMP0, L:CARG1->maxstack + | cmplw cr7, CARG2, TMP2 + | lwz PC, FRAME_PC(BASE) + | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0 + | add TMP2, CARG2, NARGS8:RC + | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD + | cmplw cr1, TMP2, TMP0 + | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt + | stw PC, SAVE_PC + | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov + | stw BASE, L->base + | blt cr6, ->fff_fallback + |1: + |.if resume + | addi BASE, BASE, 8 // Keep resumed thread in stack for GC. + | subi NARGS8:RC, NARGS8:RC, 8 + | subi TMP2, TMP2, 8 + |.endif + | stw TMP2, L:CARG1->top + | li TMP1, 0 + | stw BASE, L->top + |2: // Move args to coroutine. + | cmpw TMP1, NARGS8:RC + | evlddx TMP0, BASE, TMP1 + | beq >3 + | evstddx TMP0, CARG2, TMP1 + | addi TMP1, TMP1, 8 + | b <2 + |3: + | li CARG3, 0 + | mr L:SAVE0, L:CARG1 + | li CARG4, 0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | lwz TMP2, L:SAVE0->base + | cmplwi CRET1, LUA_YIELD + | lwz TMP3, L:SAVE0->top + | li_vmstate INTERP + | lwz BASE, L->base + | st_vmstate + | bgt >8 + | sub RD, TMP3, TMP2 + | lwz TMP0, L->maxstack + | cmplwi RD, 0 + | add TMP1, BASE, RD + | beq >6 // No results? + | cmplw TMP1, TMP0 + | li TMP1, 0 + | bgt >9 // Need to grow stack? + | + | subi TMP3, RD, 8 + | stw TMP2, L:SAVE0->top // Clear coroutine stack. + |5: // Move results from coroutine. + | cmplw TMP1, TMP3 + | evlddx TMP0, TMP2, TMP1 + | evstddx TMP0, BASE, TMP1 + | addi TMP1, TMP1, 8 + | bne <5 + |6: + | andi. TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | la RA, -8(BASE) + | stw TMP1, -8(BASE) // Prepend true to results. + | addi RD, RD, 16 + |.else + | mr RA, BASE + | addi RD, RD, 8 + |.endif + |7: + | stw PC, SAVE_PC + | mr MULTRES, RD + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | andi. TMP0, PC, FRAME_TYPE + | la TMP3, -8(TMP3) + | li TMP1, LJ_TFALSE + | evldd TMP0, 0(TMP3) + | stw TMP3, L:SAVE0->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | stw TMP1, -8(BASE) // Prepend false to results. + | la RA, -8(BASE) + | evstdd TMP0, 0(BASE) // Copy error message. + | b <7 + |.else + | mr CARG1, L + | mr CARG2, L:SAVE0 + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |.endif + | + |9: // Handle stack expansion on return from yield. + | mr CARG1, L + | srwi CARG2, RD, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | li CRET1, 0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lwz TMP0, L->cframe + | add TMP1, BASE, NARGS8:RC + | stw BASE, L->base + | andi. TMP0, TMP0, CFRAME_RESUME + | stw TMP1, L->top + | li CRET1, LUA_YIELD + | beq ->fff_fallback + | stw ZERO, L->cframe + | stb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_n math_abs + | efdabs CRET1, CARG1 + | // Fallthrough. + | + |->fff_restv: + | // CRET1 = TValue result. + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | evstdd CRET1, 0(RA) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andi. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | bne ->vm_return + | lwz INS, -4(PC) + | decode_RB8 RB, INS + |5: + | cmplw RB, RD // More results expected? + | decode_RA8 TMP0, INS + | bgt >6 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, RA, TMP1 + | b <5 + | + |.macro math_extern, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | bl extern func@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + |.endmacro + | + |.macro math_extern2, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | evldd CARG4, 8(BASE) + | blt ->fff_fallback + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | evmergehi CARG3, CARG4, CARG4 + | checkanyfail ->fff_fallback + | bl extern func@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + |.endmacro + | + |.macro math_round, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | lwz PC, FRAME_PC(BASE) + | bl ->vm_..func.._hilo; + | la RA, -8(BASE) + | evstdd CRET2, 0(RA) + | b ->fff_res1 + |.endmacro + | + | math_round floor + | math_round ceil + | + | math_extern sqrt + | + |.ffunc math_log + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | bl extern log@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.ffunc_n math_rad + | evldd CARG2, CFUNC:RB->upvalue[0] + | efdmul CRET1, CARG1, CARG2 + | b ->fff_restv + | + |.ffunc math_ldexp + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | evldd CARG4, 8(BASE) + | blt ->fff_fallback + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | checkanyfail ->fff_fallback + | efdctsi CARG3, CARG4 + | bl extern ldexp@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + | + |.ffunc math_frexp + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | lwz PC, FRAME_PC(BASE) + | bl extern frexp@plt + | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo CRET1, CRET1, CRET2 + | efdcfsi CRET2, TMP1 + | la RA, -8(BASE) + | evstdd CRET1, 0(RA) + | li RD, (2+1)*8 + | evstdd CRET2, 8(RA) + | b ->fff_res + | + |.ffunc math_modf + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | la CARG3, -8(BASE) + | lwz PC, FRAME_PC(BASE) + | bl extern modf@plt + | evmergelo CRET1, CRET1, CRET2 + | la RA, -8(BASE) + | evstdd CRET1, 0(BASE) + | li RD, (2+1)*8 + | b ->fff_res + | + |.macro math_minmax, name, cmpop + | .ffunc_1 name + | checknum CARG1 + | li TMP1, 8 + | checkfail ->fff_fallback + |1: + | evlddx CARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_restv // Ok, since CRET1 = CARG1. + | checkfail ->fff_fallback + | cmpop CARG2, CARG1 + | addi TMP1, TMP1, 8 + | crmove 4*cr0+lt, 4*cr0+gt + | evsel CARG1, CARG2, CARG1 + | b <1 + |.endmacro + | + | math_minmax math_min, efdtstlt + | math_minmax math_max, efdtstgt + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr STR:CARG1 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmplwi NARGS8:RC, 8 + | evldd STR:CARG1, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checkstr STR:CARG1 + | la RA, -8(BASE) + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | li RD, (0+1)*8 + | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | li TMP2, (1+1)*8 + | cmplwi TMP0, 0 + | lwz PC, FRAME_PC(BASE) + | efdcfsi CRET1, TMP1 + | iseleq RD, RD, TMP2 + | evstdd CRET1, 0(RA) + | b ->fff_res + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG1 + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | checkfail ->fff_fallback + | efdctsiz TMP0, CARG1 + | li CARG3, 1 + | cmplwi TMP0, 255 + | stb TMP0, 0(CARG2) + | bgt ->fff_fallback + |->fff_newstr: + | mr CARG1, L + | stw BASE, L->base + | stw PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | lwz BASE, L->base + | evmergelo STR:CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | cmplwi NARGS8:RC, 16 + | evldd CARG3, 16(BASE) + | evldd STR:CARG1, 0(BASE) + | blt ->fff_fallback + | evldd CARG2, 8(BASE) + | li TMP2, -1 + | beq >1 + | checknum CARG3 + | checkfail ->fff_fallback + | efdctsiz TMP2, CARG3 + |1: + | checknum CARG2 + | checkfail ->fff_fallback + | checkstr STR:CARG1 + | efdctsiz TMP1, CARG2 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | cmplw TMP0, TMP2 // len < end? (unsigned compare) + | add TMP3, TMP2, TMP0 + | blt >5 + |2: + | cmpwi TMP1, 0 // start <= 0? + | add TMP3, TMP1, TMP0 + | ble >7 + |3: + | sub. CARG3, TMP2, TMP1 + | addi CARG2, STR:CARG1, #STR-1 + | addi CARG3, CARG3, 1 + | add CARG2, CARG2, TMP1 + | isellt CARG3, r0, CARG3 + | b ->fff_newstr + | + |5: // Negative end or overflow. + | cmpw TMP0, TMP2 + | addi TMP3, TMP3, 1 + | iselgt TMP2, TMP3, TMP0 // end = end > len ? len : end+len+1 + | b <2 + | + |7: // Negative start or underflow. + | cmpwi cr1, TMP3, 0 + | iseleq TMP1, r0, TMP3 + | isel TMP1, r0, TMP1, 4*cr1+lt + | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) + | b <3 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmplwi NARGS8:RC, 16 + | evldd CARG1, 0(BASE) + | evldd CARG2, 8(BASE) + | bne ->fff_fallback // Exactly 2 arguments. + | checknum CARG2 + | checkfail ->fff_fallback + | checkstr STR:CARG1 + | efdctsiz CARG3, CARG2 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | cmpwi CARG3, 0 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | ble >2 // Count <= 0? (or non-int) + | cmplwi TMP0, 1 + | subi TMP2, CARG3, 1 + | blt >2 // Zero length string? + | cmplw cr1, TMP1, CARG3 + | bne ->fff_fallback // Fallback for > 1-char strings. + | lbz TMP0, STR:CARG1[1] + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | blt cr1, ->fff_fallback + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | cmplwi TMP2, 0 + | stbx TMP0, CARG2, TMP2 + | subi TMP2, TMP2, 1 + | bne <1 + | b ->fff_newstr + |2: // Return empty string. + | la STR:CRET1, DISPATCH_GL(strempty)(DISPATCH) + | evmergelo CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |.ffunc string_reverse + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + | checkstr STR:CARG1 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | checkfail ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | li TMP2, 0 + | cmplw TMP1, CARG3 + | subi TMP3, CARG3, 1 + | blt ->fff_fallback + |1: // Reverse string copy. + | cmpwi TMP3, 0 + | lbzx TMP1, CARG1, TMP2 + | blt ->fff_newstr + | stbx TMP1, CARG2, TMP3 + | subi TMP3, TMP3, 1 + | addi TMP2, TMP2, 1 + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + | checkstr STR:CARG1 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | checkfail ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | cmplw TMP1, CARG3 + | li TMP2, 0 + | blt ->fff_fallback + |1: // ASCII case conversion. + | cmplw TMP2, CARG3 + | lbzx TMP1, CARG1, TMP2 + | bge ->fff_newstr + | subi TMP0, TMP1, lo + | xori TMP3, TMP1, 0x20 + | cmplwi TMP0, 26 + | isellt TMP1, TMP3, TMP1 + | stbx TMP1, CARG2, TMP2 + | addi TMP2, TMP2, 1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG1 + | checkfail ->fff_fallback + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | efdcfsi CRET1, CRET1 + | b ->fff_restv + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + | .ffunc_n bit_..name + | efdadd CARG1, CARG1, TOBIT + |.endmacro + | + |.ffunc_bit tobit + |->fff_resbit: + | efdcfsi CRET1, CARG1 + | b ->fff_restv + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | li TMP1, 8 + |1: + | evlddx CARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_resbit + | checkfail ->fff_fallback + | efdadd CARG2, CARG2, TOBIT + | ins CARG1, CARG1, CARG2 + | addi TMP1, TMP1, 8 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | rotlwi TMP0, CARG1, 8 + | rlwimi TMP0, CARG1, 24, 0, 7 + | rlwimi TMP0, CARG1, 24, 16, 23 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.ffunc_bit bnot + | not TMP0, CARG1 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc_nn bit_..name + | efdadd CARG2, CARG2, TOBIT + | efdadd CARG1, CARG1, TOBIT + |.if shmod == 1 + | rlwinm CARG2, CARG2, 0, 27, 31 + |.elif shmod == 2 + | neg CARG2, CARG2 + |.endif + | ins TMP0, CARG1, CARG2 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + |.endmacro + | + |.ffunc_bit_sh lshift, slw, 1 + |.ffunc_bit_sh rshift, srw, 1 + |.ffunc_bit_sh arshift, sraw, 1 + |.ffunc_bit_sh rol, rotlw, 0 + |.ffunc_bit_sh ror, rotlw, 2 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lwz TMP3, CFUNC:RB->f + | add TMP1, BASE, NARGS8:RC + | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addi TMP0, TMP1, 8*LUA_MINSTACK + | lwz TMP2, L->maxstack + | stw PC, SAVE_PC // Redundant (but a defined value). + | cmplw TMP0, TMP2 + | stw BASE, L->base + | stw TMP1, L->top + | mr CARG1, L + | bgt >5 // Need to grow stack. + | mtctr TMP3 + | bctrl // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lwz BASE, L->base + | cmpwi CRET1, 0 + | slwi RD, CRET1, 3 + | la RA, -8(BASE) + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | lwz TMP0, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub NARGS8:RC, TMP0, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andi. TMP0, PC, FRAME_TYPE + | rlwinm TMP1, PC, 0, 0, 28 + | bne >3 + | lwz INS, -4(PC) + | decode_RA8 TMP1, INS + | addi TMP1, TMP1, 8 + |3: + | sub TMP2, BASE, TMP1 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | li CARG2, LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mflr SAVE0 + | stw BASE, L->base + | add TMP0, BASE, NARGS8:RC + | stw PC, SAVE_PC // Redundant (but a defined value). + | stw TMP0, L->top + | mr CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | lwz BASE, L->base + | mtlr SAVE0 + | lwz TMP0, L->top + | sub NARGS8:RC, TMP0, BASE + | lwz CFUNC:RB, FRAME_FUNC(BASE) + | blr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | NYI + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OP4 TMP1, INS. + | lwzx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | bctr + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0 + | bne <5 + | + | cmpwi cr1, TMP0, 0 + | addic. TMP2, TMP2, -1 + | beq cr1, <5 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | beq >1 + | bge cr1, <5 + |1: + | mr CARG1, L + | stw MULTRES, SAVE_MULTRES + | mr CARG2, PC + | stw BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | lwz BASE, L->base + |4: // Re-dispatch to static ins. + | lwz INS, -4(PC) + | decode_OP4 TMP1, INS + | decode_RB8 RB, INS + | addi TMP1, TMP1, GG_DISP2STATIC + | decode_RD8 RD, INS + | lwzx TMP0, DISPATCH, TMP1 + | decode_RA8 RA, INS + | decode_RC8 RC, INS + | mtctr TMP0 + | bctr + | + |->cont_hook: // Continue from hook yield. + | addi PC, PC, 4 + | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | NYI + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mr CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | add TMP0, BASE, RC + | stw PC, SAVE_PC + | mr CARG1, L + | stw BASE, L->base + | sub RA, RA, BASE + | stw TMP0, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | lwz BASE, L->base + | lwz TMP0, L->top + | stw ZERO, SAVE_PC // Invalidate for subsequent line hook. + | sub NARGS8:RC, TMP0, BASE + | add RA, BASE, RA + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | mtctr CRET1 + | bctr + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_exit_handler: + |.if JIT + | NYI + |.endif + |->vm_exit_interp: + |.if JIT + | NYI + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called by math.floor/math.ceil fast functions + |// and from JIT code. + |// + |// This can be inlined if the CPU has the frin/friz/frip/frim instructions. + |// The alternative hard-float approaches have a deep dependency chain. + |// The resulting latency is at least 3x-7x the double-precision FP latency + |// (e500v2: 6cy, e600: 5cy, Cell: 10cy) or around 20-70 cycles. + |// + |// The soft-float approach is tedious, but much faster (e500v2: ~11cy/~6cy). + |// However it relies on a fast way to transfer the FP value to GPRs + |// (e500v2: 0cy for lo-word, 1cy for hi-word). + |// + |.macro vm_round, name, mode + | // Used temporaries: TMP0, TMP1, TMP2, TMP3. + |->name.._efd: // Input: CARG2, output: CRET2 + | evmergehi CARG1, CARG2, CARG2 + |->name.._hilo: + | // Input: CARG1 (hi), CARG2 (hi, lo), output: CRET2 + | rlwinm TMP2, CARG1, 12, 21, 31 + | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023 + | li TMP1, -1 + | cmplwi cr1, TMP2, 51 // 0 <= exp <= 51? + | subfic TMP0, TMP2, 52 + | bgt cr1, >1 + | lus TMP3, 0xfff0 + | slw TMP0, TMP1, TMP0 // lomask = -1 << (52-exp) + | sraw TMP1, TMP3, TMP2 // himask = (int32_t)0xfff00000 >> exp + |.if mode == 2 // trunc(x): + | evmergelo TMP0, TMP1, TMP0 + | evand CRET2, CARG2, TMP0 // hi &= himask, lo &= lomask + |.else + | andc TMP2, CARG2, TMP0 + | andc TMP3, CARG1, TMP1 + | or TMP2, TMP2, TMP3 // ztest = (hi&~himask) | (lo&~lomask) + | srawi TMP3, CARG1, 31 // signmask = (int32_t)hi >> 31 + |.if mode == 0 // floor(x): + | and. TMP2, TMP2, TMP3 // iszero = ((ztest & signmask) == 0) + |.else // ceil(x): + | andc. TMP2, TMP2, TMP3 // iszero = ((ztest & ~signmask) == 0) + |.endif + | and CARG2, CARG2, TMP0 // lo &= lomask + | and CARG1, CARG1, TMP1 // hi &= himask + | subc TMP0, CARG2, TMP0 + | iseleq TMP0, CARG2, TMP0 // lo = iszero ? lo : lo-lomask + | sube TMP1, CARG1, TMP1 + | iseleq TMP1, CARG1, TMP1 // hi = iszero ? hi : hi-himask+carry + | evmergelo CRET2, TMP1, TMP0 + |.endif + | blr + |1: + | bgtlr // Already done if >=2^52, +-inf or nan. + |.if mode == 2 // trunc(x): + | rlwinm TMP1, CARG1, 0, 0, 0 // hi = sign(x) + | li TMP0, 0 + | evmergelo CRET2, TMP1, TMP0 + |.else + | rlwinm TMP2, CARG1, 0, 1, 31 + | srawi TMP0, CARG1, 31 // signmask = (int32_t)hi >> 31 + | or TMP2, TMP2, CARG2 // ztest = abs(hi) | lo + | lus TMP1, 0x3ff0 + |.if mode == 0 // floor(x): + | and. TMP2, TMP2, TMP0 // iszero = ((ztest & signmask) == 0) + |.else // ceil(x): + | andc. TMP2, TMP2, TMP0 // iszero = ((ztest & ~signmask) == 0) + |.endif + | li TMP0, 0 + | iseleq TMP1, r0, TMP1 + | rlwimi CARG1, TMP1, 0, 1, 31 // hi = sign(x) | (iszero ? 0.0 : 1.0) + | evmergelo CRET2, CARG1, TMP0 + |.endif + | blr + |.endmacro + | + |->vm_floor: + | mflr CARG3 + | evmergelo CARG2, CARG1, CARG2 + | bl ->vm_floor_hilo + | mtlr CARG3 + | evmergehi CRET1, CRET2, CRET2 + | blr + | + | vm_round vm_floor, 0 + | vm_round vm_ceil, 1 + |.if JIT + | vm_round vm_trunc, 2 + |.else + |->vm_trunc_efd: + |->vm_trunc_hilo: + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_ffi_call: + |.if FFI + | NYI + |.endif + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + | evlddx TMP0, BASE, RA + | addi PC, PC, 4 + | evlddx TMP1, BASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz TMP2, -4(PC) + | evmergehi RB, TMP0, TMP1 + | decode_RD4 TMP2, TMP2 + | checknum RB + | add TMP2, TMP2, TMP3 + | checkanyfail ->vmeta_comp + | efdcmplt TMP0, TMP1 + if (op == BC_ISLE || op == BC_ISGT) { + | efdcmpeq cr1, TMP0, TMP1 + | cror 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + } + if (op == BC_ISLT || op == BC_ISLE) { + | iselgt PC, TMP2, PC + } else { + | iselgt PC, PC, TMP2 + } + | ins_next + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + | evlddx CARG2, BASE, RA + | addi PC, PC, 4 + | evlddx CARG3, BASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz TMP2, -4(PC) + | evmergehi RB, CARG2, CARG3 + | decode_RD4 TMP2, TMP2 + | checknum RB + | add TMP2, TMP2, TMP3 + | checkanyfail >5 + | efdcmpeq CARG2, CARG3 + if (vk) { + | iselgt PC, TMP2, PC + } else { + | iselgt PC, PC, TMP2 + } + |1: + | ins_next + | + |5: // Either or both types are not numbers. + | evcmpeq CARG2, CARG3 + | not TMP3, RB + | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive? + | crorc 4*cr7+lt, 4*cr0+so, 4*cr0+lt // 1: Same tv or different type. + | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata? + | crandc 4*cr7+gt, 4*cr0+lt, 4*cr1+gt // 2: Same type and primitive. + | mr SAVE0, PC + if (vk) { + | isel PC, TMP2, PC, 4*cr7+gt + } else { + | isel TMP2, PC, TMP2, 4*cr7+gt + } + | cror 4*cr7+lt, 4*cr7+lt, 4*cr7+gt // 1 or 2. + if (vk) { + | isel PC, TMP2, PC, 4*cr0+so + } else { + | isel PC, PC, TMP2, 4*cr0+so + } + | blt cr7, <1 // Done if 1 or 2. + | blt cr6, <1 // Done if not tab/ud. + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:TMP2, TAB:CARG2->metatable + | li CARG4, 1-vk // ne = 0 or 1. + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable? + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_equal // Handle __eq metamethod. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | evlddx TMP0, BASE, RA + | srwi RD, RD, 1 + | lwz INS, 0(PC) + | subfic RD, RD, -4 + | addi PC, PC, 4 + | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | evmergelo STR:TMP1, TISSTR, STR:TMP1 + | add TMP2, TMP2, TMP3 + | evcmpeq TMP0, STR:TMP1 + if (vk) { + | isel PC, TMP2, PC, 4*cr0+so + } else { + | isel PC, PC, TMP2, 4*cr0+so + } + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + | evlddx TMP0, BASE, RA + | addi PC, PC, 4 + | evlddx TMP1, KBASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz INS, -4(PC) + | checknum TMP0 + | checkfail >5 + | efdcmpeq TMP0, TMP1 + |1: + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (vk) { + | iselgt PC, TMP2, PC + |5: + } else { + | iselgt PC, PC, TMP2 + } + |3: + | ins_next + if (!vk) { + |5: + | decode_RD4 TMP2, INS + | add PC, TMP2, TMP3 + | b <3 + } + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | lwzx TMP0, BASE, RA + | srwi TMP1, RD, 3 + | lwz INS, 0(PC) + | addi PC, PC, 4 + | not TMP1, TMP1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | cmplw TMP0, TMP1 + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (vk) { + | iseleq PC, TMP2, PC + } else { + | iseleq PC, PC, TMP2 + } + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | evlddx TMP0, BASE, RD + | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE. + | lwz INS, 0(PC) + | evcmpltu TMP0, TMP1 + | addi PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (op == BC_IST) { + | isellt PC, TMP2, PC + } else { + | isellt PC, PC, TMP2 + } + } else { + if (op == BC_ISTC) { + | checkfail >1 + } else { + | checkok >1 + } + | addis PC, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | evstddx TMP0, BASE, RA + | add PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | ins_next1 + | evlddx TMP0, BASE, RD + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lwzx TMP0, BASE, RD + | subfic TMP1, TMP0, LJ_TTRUE + | adde TMP0, TMP0, TMP1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | evlddx TMP0, BASE, RD + | checknum TMP0 + | checkfail ->vmeta_unm + | efdneg TMP0, TMP0 + | ins_next1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | evlddx CARG1, BASE, RD + | checkstr CARG1 + | checkfail >2 + | lwz CRET1, STR:CARG1->len + |1: + | ins_next1 + | efdcfsi TMP0, CRET1 + | evstddx TMP0, BASE, RA + | ins_next2 + |2: + | checktab CARG1 + | checkfail ->vmeta_len +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | cmplwi TAB:TMP2, 0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b <1 +#if LJ_52 + |9: + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre, t0, t1 + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | evlddx t0, BASE, RB + | checknum t0 + | evlddx t1, KBASE, RC + | checkfail ->vmeta_arith_vn + || break; + ||case 1: + | evlddx t1, BASE, RB + | checknum t1 + | evlddx t0, KBASE, RC + | checkfail ->vmeta_arith_nv + || break; + ||default: + | evlddx t0, BASE, RB + | evlddx t1, BASE, RC + | evmergehi TMP2, t0, t1 + | checknum TMP2 + | checkanyfail ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arith, ins + | ins_arithpre TMP0, TMP1 + | ins_next1 + | ins TMP0, TMP0, TMP1 + | evstddx TMP0, BASE, RA + | ins_next2 + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith efdadd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith efdsub + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith efdmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith efddiv + break; + case BC_MODVN: + | ins_arithpre RD, SAVE0 + |->BC_MODVN_Z: + | efddiv CARG2, RD, SAVE0 + | bl ->vm_floor_efd // floor(b/c) + | efdmul TMP0, CRET2, SAVE0 + | ins_next1 + | efdsub TMP0, RD, TMP0 // b - floor(b/c)*c + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_MODNV: case BC_MODVV: + | ins_arithpre RD, SAVE0 + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + break; + case BC_POW: + | evlddx CARG2, BASE, RB + | evlddx CARG4, BASE, RC + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | evmergehi CARG3, CARG4, CARG4 + | checkanyfail ->vmeta_arith_vv + | bl extern pow@plt + | evmergelo CRET2, CRET1, CRET2 + | evstddx CRET2, BASE, RA + | ins_next + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | sub CARG3, RC, RB + | stw BASE, L->base + | add CARG2, BASE, RC + | mr SAVE0, RB + |->BC_CAT_Z: + | stw PC, SAVE_PC + | mr CARG1, L + | srwi CARG3, CARG3, 3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | lwz BASE, L->base + | bne ->vmeta_binop + | evlddx TMP0, BASE, SAVE0 // Copy result from RB to RA. + | evstddx TMP0, BASE, RA + | ins_next + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | ins_next1 + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4 + | evmergelo TMP0, TISSTR, TMP0 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | ins_next1 + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4 + | li TMP2, LJ_TCDATA + | evmergelo TMP0, TMP2, TMP0 + | evstddx TMP0, BASE, RA + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + | srwi TMP1, RD, 3 + | extsh TMP1, TMP1 + | ins_next1 + | efdcfsi TMP0, TMP1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | evlddx TMP0, KBASE, RD + | ins_next1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srwi TMP1, RD, 3 + | not TMP0, TMP1 + | ins_next1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | evstddx TISNIL, BASE, RA + | addi RA, RA, 8 + |1: + | evstddx TISNIL, BASE, RA + | cmpw RA, RD + | addi RA, RA, 8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RD, RD, 1 + | addi RD, RD, offsetof(GCfuncL, uvptr) + | lwzx UPVAL:RB, LFUNC:RB, RD + | lwz TMP1, UPVAL:RB->v + | evldd TMP0, 0(TMP1) + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | evlddx TMP1, BASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP0, UPVAL:RB->closed + | evmergehi TMP2, TMP1, TMP1 + | evstdd TMP1, 0(CARG2) + | cmplwi cr1, TMP0, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | subi TMP2, TMP2, (LJ_TISNUM+1) + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmplwi TMP2, LJ_TISGCV - (LJ_TISNUM+1) + | bge <1 // tvisgcv(v) + | lbz TMP3, GCOBJ:TMP1->gch.marked + | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | srwi RA, RA, 1 + | subfic TMP1, TMP1, -4 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4 + | lwzx UPVAL:RB, LFUNC:RB, RA + | evmergelo STR:TMP1, TISSTR, STR:TMP1 + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP3, STR:TMP1->marked + | lbz TMP2, UPVAL:RB->closed + | evstdd STR:TMP1, 0(CARG2) + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(str) + | cmplwi cr1, TMP2, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | evlddx TMP0, KBASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | lwz TMP1, UPVAL:RB->v + | evstdd TMP0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | srwi TMP0, RD, 3 + | lwzx UPVAL:RB, LFUNC:RB, RA + | not TMP0, TMP0 + | lwz TMP1, UPVAL:RB->v + | stw TMP0, 0(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lwz TMP1, L->openupval + | branch_RD // Do this first since RD is not saved. + | stw BASE, L->base + | cmplwi TMP1, 0 + | mr CARG1, L + | beq >1 + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | lwz BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srwi TMP1, RD, 1 + | stw BASE, L->base + | subfic TMP1, TMP1, -4 + | stw PC, SAVE_PC + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | mr CARG1, L + | lwz CARG3, FRAME_FUNC(BASE) + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | lwz BASE, L->base + | evmergelo LFUNC:CRET1, TISFUNC, LFUNC:CRET1 + | evstddx LFUNC:CRET1, BASE, RA + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | mr CARG1, L + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | stw BASE, L->base + | cmplw TMP0, TMP1 + | stw PC, SAVE_PC + | bge >5 + |1: + if (op == BC_TNEW) { + | rlwinm CARG2, RD, 29, 21, 31 + | rlwinm CARG3, RD, 18, 27, 31 + | cmpwi CARG2, 0x7ff + | li TMP1, 0x801 + | iseleq CARG2, TMP1, CARG2 + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns Table *. + } else { + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns Table *. + } + | lwz BASE, L->base + | evmergelo TAB:CRET1, TISTAB, TAB:CRET1 + | evstddx TAB:CRET1, BASE, RA + | ins_next + |5: + | mr SAVE0, RD + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mr RD, SAVE0 + | mr CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lwz LFUNC:TMP2, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | lwz TAB:RB, LFUNC:TMP2->env + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | evlddx TAB:RB, BASE, RB + | evlddx RC, BASE, RC + | checktab TAB:RB + | checkfail ->vmeta_tgetv + | checknum RC + | checkfail >5 + | // Convert number key to integer + | efdctsi TMP2, RC + | lwz TMP0, TAB:RB->asize + | efdcfsi TMP1, TMP2 + | cmplw cr0, TMP0, TMP2 + | efdcmpeq cr1, RC, TMP1 + | lwz TMP1, TAB:RB->array + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + | slwi TMP2, TMP2, 3 + | ble ->vmeta_tgetv // Integer key and in array part? + | evlddx TMP1, TMP1, TMP2 + | checknil TMP1 + | checkok >2 + |1: + | evstddx TMP1, BASE, RA + | ins_next + | + |2: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_tgetv + | + |5: + | checkstr STR:RC // String key? + | checkok ->BC_TGETS_Z + | b ->vmeta_tgetv + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*8 (~) + | evlddx TAB:RB, BASE, RB + | srwi TMP1, RC, 1 + | checktab TAB:RB + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | checkfail ->vmeta_tgets1 + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | checkanyfail >4 + | checknil TMP1 + | checkok >5 // Key found, but nil value? + |3: + | evstddx TMP1, BASE, RA + | ins_next + | + |4: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, nil result. + | evmr TMP1, TISNIL + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <3 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_tgets + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | evlddx TAB:RB, BASE, RB + | srwi TMP0, RC, 3 + | checktab TAB:RB + | checkfail ->vmeta_tgetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | cmplw TMP0, TMP1 + | bge ->vmeta_tgetb + | evlddx TMP1, TMP2, RC + | checknil TMP1 + | checkok >5 + |1: + | ins_next1 + | evstddx TMP1, BASE, RA + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_tgetb // Caveat: preserve TMP0! + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | evlddx TAB:RB, BASE, RB + | evlddx RC, BASE, RC + | checktab TAB:RB + | checkfail ->vmeta_tsetv + | checknum RC + | checkfail >5 + | // Convert number key to integer + | efdctsi TMP2, RC + | evlddx SAVE0, BASE, RA + | lwz TMP0, TAB:RB->asize + | efdcfsi TMP1, TMP2 + | cmplw cr0, TMP0, TMP2 + | efdcmpeq cr1, RC, TMP1 + | lwz TMP1, TAB:RB->array + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + | slwi TMP0, TMP2, 3 + | ble ->vmeta_tsetv // Integer key and in array part? + | lbz TMP3, TAB:RB->marked + | evlddx TMP2, TMP1, TMP0 + | checknil TMP2 + | checkok >3 + |1: + | andi. TMP2, TMP3, LJ_GC_BLACK // isblack(table) + | evstddx SAVE0, TMP1, TMP0 + | bne >7 + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_tsetv + | + |5: + | checkstr STR:RC // String key? + | checkok ->BC_TSETS_Z + | b ->vmeta_tsetv + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | evlddx TAB:RB, BASE, RB + | srwi TMP1, RC, 1 + | checktab TAB:RB + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | checkfail ->vmeta_tsets1 + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | stb ZERO, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | evlddx SAVE0, BASE, RA + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | lbz TMP3, TAB:RB->marked + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | checkanyfail >5 + | checknil TMP1 + | checkok >4 // Key found, but nil value? + |2: + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | evstdd SAVE0, NODE:TMP2->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <2 // No metatable: done. + | lbz TMP0, TAB:TMP1->nomm + | andi. TMP0, TMP0, 1<vmeta_tsets + | + |5: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | lwz TAB:TMP1, TAB:RB->metatable + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | stw PC, SAVE_PC + | mr CARG1, L + | cmplwi TAB:TMP1, 0 + | stw BASE, L->base + | beq >6 // No metatable: continue. + | lbz TMP0, TAB:TMP1->nomm + | andi. TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mr CARG2, TAB:RB + | evstdd STR:RC, 0(CARG3) + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | lwz BASE, L->base + | evstdd SAVE0, 0(CRET1) + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | evlddx TAB:RB, BASE, RB + | srwi TMP0, RC, 3 + | checktab TAB:RB + | checkfail ->vmeta_tsetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | lbz TMP3, TAB:RB->marked + | cmplw TMP0, TMP1 + | evlddx SAVE0, BASE, RA + | bge ->vmeta_tsetb + | evlddx TMP1, TMP2, RC + | checknil TMP1 + | checkok >5 + |1: + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | evstddx SAVE0, TMP2, RC + | bne >7 + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <1 // No metatable: done. + | lbz TMP1, TAB:TMP1->nomm + | andi. TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | add RA, BASE, RA + |1: + | add TMP3, KBASE, RD + | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table. + | addic. TMP0, MULTRES, -8 + | lwz TMP3, 4(TMP3) // Integer constant is in lo-word. + | srwi CARG3, TMP0, 3 + | beq >4 // Nothing to copy? + | add CARG3, CARG3, TMP3 + | lwz TMP2, TAB:CARG2->asize + | slwi TMP1, TMP3, 3 + | lbz TMP3, TAB:CARG2->marked + | cmplw CARG3, TMP2 + | add TMP2, RA, TMP0 + | lwz TMP0, TAB:CARG2->array + | bgt >5 + | add TMP1, TMP1, TMP0 + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | evldd TMP0, 0(RA) + | addi RA, RA, 8 + | cmpw cr1, RA, TMP2 + | evstdd TMP0, 0(TMP1) + | addi TMP1, TMP1, 8 + | blt cr1, <3 + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | mr SAVE0, RD + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | mr RD, SAVE0 + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALL follows. + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | evlddx LFUNC:RB, BASE, RA + | mr TMP2, BASE + | add BASE, BASE, RA + | subi NARGS8:RC, NARGS8:RC, 8 + | checkfunc LFUNC:RB + | addi BASE, BASE, 8 + | checkfail ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | evlddx LFUNC:RB, BASE, RA + | add RA, BASE, RA + | lwz TMP1, FRAME_PC(BASE) + | subi NARGS8:RC, NARGS8:RC, 8 + | checkfunc LFUNC:RB + | addi RA, RA, 8 + | checkfail ->vmeta_callt + |->BC_CALLT_Z: + | andi. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand. + | lbz TMP3, LFUNC:RB->ffid + | xori TMP2, TMP1, FRAME_VARG + | cmplwi cr1, NARGS8:RC, 0 + | bne >7 + |1: + | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | li TMP2, 0 + | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function? + | beq cr1, >3 + |2: + | addi TMP3, TMP2, 8 + | evlddx TMP0, RA, TMP2 + | cmplw cr1, TMP3, NARGS8:RC + | evstddx TMP0, BASE, TMP2 + | mr TMP2, TMP3 + | bne cr1, <2 + |3: + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt + | beq >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lwz INS, -4(TMP1) + | decode_RA8 RA, INS + | sub TMP1, BASE, RA + | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1) + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | b <4 + | + |7: // Tailcall from a vararg function. + | andi. TMP0, TMP2, FRAME_TYPEP + | bne <1 // Vararg frame below? + | sub BASE, BASE, TMP2 // Relocate BASE down. + | lwz TMP1, FRAME_PC(BASE) + | andi. TMP0, TMP1, FRAME_TYPE + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | subi RA, RA, 24 // evldd doesn't support neg. offsets. + | mr TMP2, BASE + | evlddx LFUNC:RB, BASE, RA + | add BASE, BASE, RA + | evldd TMP0, 8(BASE) + | evldd TMP1, 16(BASE) + | evstdd LFUNC:RB, 24(BASE) // Copy callable. + | checkfunc LFUNC:RB + | evstdd TMP0, 32(BASE) // Copy state. + | li NARGS8:RC, 16 // Iterators get 2 arguments. + | evstdd TMP1, 40(BASE) // Copy control var. + | addi BASE, BASE, 32 + | checkfail ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | lwz TAB:RB, -12(RA) + | lwz RC, -4(RA) // Get index from control var. + | lwz TMP0, TAB:RB->asize + | lwz TMP1, TAB:RB->array + | addi PC, PC, 4 + |1: // Traverse array part. + | cmplw RC, TMP0 + | slwi TMP3, RC, 3 + | bge >5 // Index points after array part? + | evlddx TMP2, TMP1, TMP3 + | checknil TMP2 + | lwz INS, -4(PC) + | checkok >4 + | efdcfsi TMP0, RC + | addi RC, RC, 1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | evstdd TMP2, 8(RA) + | decode_RD4 TMP1, INS + | stw RC, -4(RA) // Update control var. + | add PC, TMP1, TMP3 + | evstdd TMP0, 0(RA) + |3: + | ins_next + | + |4: // Skip holes in array part. + | addi RC, RC, 1 + | b <1 + | + |5: // Traverse hash part. + | lwz TMP1, TAB:RB->hmask + | sub RC, RC, TMP0 + | lwz TMP2, TAB:RB->node + |6: + | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1. + | slwi TMP3, RC, 5 + | bgt <3 + | slwi RB, RC, 3 + | sub TMP3, TMP3, RB + | evlddx RB, TMP2, TMP3 + | add NODE:TMP3, TMP2, TMP3 + | checknil RB + | lwz INS, -4(PC) + | checkok >7 + | evldd TMP3, NODE:TMP3->key + | addis TMP2, PC, -(BCBIAS_J*4 >> 16) + | evstdd RB, 8(RA) + | add RC, RC, TMP0 + | decode_RD4 TMP1, INS + | evstdd TMP3, 0(RA) + | addi RC, RC, 1 + | add PC, TMP1, TMP2 + | stw RC, -4(RA) // Update control var. + | b <3 + | + |7: // Skip holes in hash part. + | addi RC, RC, 1 + | b <6 + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | add RA, BASE, RA + | li TMP2, -24 + | evlddx CFUNC:TMP1, RA, TMP2 + | lwz TMP2, -16(RA) + | lwz TMP3, -8(RA) + | evmergehi TMP0, CFUNC:TMP1, CFUNC:TMP1 + | cmpwi cr0, TMP2, LJ_TTAB + | cmpwi cr1, TMP0, LJ_TFUNC + | cmpwi cr6, TMP3, LJ_TNIL + | bne cr1, >5 + | lbz TMP1, CFUNC:TMP1->ffid + | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq + | cmpwi cr7, TMP1, FF_next_N + | srwi TMP0, RD, 1 + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | add TMP3, PC, TMP0 + | bne cr0, >5 + | lus TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | stw ZERO, -4(RA) // Initialize control var. + | stw TMP1, -8(RA) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP0, BC_JMP + | li TMP1, BC_ITERC + | stb TMP0, -1(PC) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + | stb TMP1, 3(PC) + | b <1 + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lwz TMP0, FRAME_PC(BASE) + | add RC, BASE, RC + | add RA, BASE, RA + | addi RC, RC, FRAME_VARG + | add TMP2, RA, RB + | subi TMP3, BASE, 8 // TMP3 = vtop + | sub RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmplwi cr1, RB, 0 + | sub. TMP1, TMP3, RC + | beq cr1, >5 // Copy all varargs? + | subi TMP2, TMP2, 16 + | ble >2 // No vararg slots? + |1: // Copy vararg slots to destination slots. + | evldd TMP0, 0(RC) + | addi RC, RC, 8 + | evstdd TMP0, 0(RA) + | cmplw RA, TMP2 + | cmplw cr1, RC, TMP3 + | bge >3 // All destination slots filled? + | addi RA, RA, 8 + | blt cr1, <1 // More vararg slots? + |2: // Fill up remainder with nil. + | evstdd TISNIL, 0(RA) + | cmplw RA, TMP2 + | addi RA, RA, 8 + | blt <2 + |3: + | ins_next + | + |5: // Copy all varargs. + | lwz TMP0, L->maxstack + | li MULTRES, 8 // MULTRES = (0+1)*8 + | ble <3 // No vararg slots? + | add TMP2, RA, TMP1 + | cmplw TMP2, TMP0 + | addi MULTRES, TMP1, 8 + | bgt >7 + |6: + | evldd TMP0, 0(RC) + | addi RC, RC, 8 + | evstdd TMP0, 0(RA) + | cmplw RC, TMP3 + | addi RA, RA, 8 + | blt <6 // More vararg slots? + | b <3 + | + |7: // Grow stack for varargs. + | mr CARG1, L + | stw RA, L->top + | sub SAVE0, RC, BASE // Need delta, because BASE may change. + | stw BASE, L->base + | sub RA, RA, BASE + | stw PC, SAVE_PC + | srwi CARG2, TMP1, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | add RA, BASE, RA + | add RC, BASE, SAVE0 + | subi TMP3, BASE, 8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + |1: + | andi. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lwz INS, -4(PC) + | cmpwi RD, 8 + | subi TMP2, BASE, 8 + | subi RC, RD, 8 + | decode_RB8 RB, INS + | beq >3 + | li TMP1, 0 + |2: + | addi TMP3, TMP1, 8 + | evlddx TMP0, RA, TMP1 + | cmpw TMP3, RC + | evstddx TMP0, TMP2, TMP1 + | beq >3 + | addi TMP1, TMP3, 8 + | evlddx TMP0, RA, TMP3 + | cmpw TMP1, RC + | evstddx TMP0, TMP2, TMP3 + | bne <2 + |3: + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, TMP2, TMP1 + | b <5 + | + |->BC_RETV_Z: // Non-standard return case. + | andi. TMP2, TMP1, FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, TMP1 + | lwz PC, FRAME_PC(BASE) + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + | andi. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + | lwz INS, -4(PC) + | subi TMP2, BASE, 8 + | decode_RB8 RB, INS + if (op == BC_RET1) { + | evldd TMP0, 0(RA) + | evstdd TMP0, 0(TMP2) + } + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, TMP2, TMP1 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | add RA, BASE, RA + | evldd TMP1, FORL_IDX*8(RA) + | evldd TMP3, FORL_STEP*8(RA) + | evldd TMP2, FORL_STOP*8(RA) + if (!vk) { + | evcmpgtu cr0, TMP1, TISNUM + | evcmpgtu cr7, TMP3, TISNUM + | evcmpgtu cr1, TMP2, TISNUM + | cror 4*cr0+lt, 4*cr0+lt, 4*cr7+lt + | cror 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | blt ->vmeta_for + } + if (vk) { + | efdadd TMP1, TMP1, TMP3 + | evstdd TMP1, FORL_IDX*8(RA) + } + | evcmpgts TMP3, TISNIL + | evstdd TMP1, FORL_EXT*8(RA) + | bge >2 + | efdcmpgt TMP1, TMP2 + |1: + if (op != BC_JFORL) { + | srwi RD, RD, 1 + | add RD, PC, RD + if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else { + | addis RD, RD, -(BCBIAS_J*4 >> 16) + } + } + if (op == BC_FORI) { + | iselgt PC, RD, PC + } else if (op == BC_IFORL) { + | iselgt PC, PC, RD + } else { + | ble =>BC_JLOOP + } + | ins_next + |2: + | efdcmpgt TMP2, TMP1 + | b <1 + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | evlddx TMP1, BASE, RA + | subi RA, RA, 8 + | checknil TMP1 + | checkok >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | NYI + } else { + | branch_RD // Otherwise save control var + branch. + | evstddx TMP1, BASE, RA + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | NYI + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | lbz TMP1, -4+PC2PROTO(numparams)(PC) + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw RA, TMP2 + | slwi TMP1, TMP1, 3 + | bgt ->vm_growstack_l + | ins_next1 + |2: + | cmplw NARGS8:RC, TMP1 // Check for missing parameters. + | ble >3 + if (op == BC_JFUNCF) { + | NYI + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | evstddx TISNIL, BASE, NARGS8:RC + | addi NARGS8:RC, NARGS8:RC, 8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | add TMP1, BASE, RC + | add TMP0, RA, RC + | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC. + | addi TMP3, RC, 8+FRAME_VARG + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw TMP0, TMP2 + | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG. + | bge ->vm_growstack_l + | lbz TMP2, -4+PC2PROTO(numparams)(PC) + | mr RA, BASE + | mr RC, TMP1 + | ins_next1 + | cmpwi TMP2, 0 + | addi BASE, TMP1, 8 + | beq >3 + |1: + | cmplw RA, RC // Less args than parameters? + | evldd TMP0, 0(RA) + | bge >4 + | evstdd TISNIL, 0(RA) // Clear old fixarg slot (help the GC). + | addi RA, RA, 8 + |2: + | addic. TMP2, TMP2, -1 + | evstdd TMP0, 8(TMP1) + | addi TMP1, TMP1, 8 + | bne <1 + |3: + | ins_next2 + | + |4: // Clear missing parameters. + | evmr TMP0, TISNIL + | b <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lwz TMP3, CFUNC:RB->f + } else { + | lwz TMP3, DISPATCH_GL(wrapf)(DISPATCH) + } + | add TMP1, RA, NARGS8:RC + | lwz TMP2, L->maxstack + | add RC, BASE, NARGS8:RC + | stw BASE, L->base + | cmplw TMP1, TMP2 + | stw RC, L->top + | li_vmstate C + | mtctr TMP3 + if (op == BC_FUNCCW) { + | lwz CARG2, CFUNC:RB->f + } + | mr CARG1, L + | bgt ->vm_growstack_c // Need to grow stack. + | st_vmstate + | bctrl // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | lwz TMP1, L->top + | slwi RD, CRET1, 3 + | lwz BASE, L->base + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. + | sub RA, TMP1, RD // RA = L->top - nresults*8 + | st_vmstate + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n", + (int)ctx->codesz, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n", + 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .LASFDE1-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n", + (int)ctx->codesz, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n", + 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE1:\n\n"); + break; + default: + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_x86.dasc b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_x86.dasc new file mode 100644 index 0000000..8a9b536 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/vm_x86.dasc @@ -0,0 +1,6374 @@ +|// Low-level VM code for x86 CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.if P64 +|.arch x64 +|.else +|.arch x86 +|.endif +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|//----------------------------------------------------------------------- +| +|.if P64 +|.define X64, 1 +|.define SSE, 1 +|.if WIN +|.define X64WIN, 1 +|.endif +|.endif +| +|// Fixed register assignments for the interpreter. +|// This is very fragile and has many dependencies. Caveat emptor. +|.define BASE, edx // Not C callee-save, refetched anyway. +|.if not X64 +|.define KBASE, edi // Must be C callee-save. +|.define KBASEa, KBASE +|.define PC, esi // Must be C callee-save. +|.define PCa, PC +|.define DISPATCH, ebx // Must be C callee-save. +|.elif X64WIN +|.define KBASE, edi // Must be C callee-save. +|.define KBASEa, rdi +|.define PC, esi // Must be C callee-save. +|.define PCa, rsi +|.define DISPATCH, ebx // Must be C callee-save. +|.else +|.define KBASE, r15d // Must be C callee-save. +|.define KBASEa, r15 +|.define PC, ebx // Must be C callee-save. +|.define PCa, rbx +|.define DISPATCH, r14d // Must be C callee-save. +|.endif +| +|.define RA, ecx +|.define RAH, ch +|.define RAL, cl +|.define RB, ebp // Must be ebp (C callee-save). +|.define RC, eax // Must be eax. +|.define RCW, ax +|.define RCH, ah +|.define RCL, al +|.define OP, RB +|.define RD, RC +|.define RDW, RCW +|.define RDL, RCL +|.if X64 +|.define RAa, rcx +|.define RBa, rbp +|.define RCa, rax +|.define RDa, rax +|.else +|.define RAa, RA +|.define RBa, RB +|.define RCa, RC +|.define RDa, RD +|.endif +| +|.if not X64 +|.define FCARG1, ecx // x86 fastcall arguments. +|.define FCARG2, edx +|.elif X64WIN +|.define CARG1, rcx // x64/WIN64 C call arguments. +|.define CARG2, rdx +|.define CARG3, r8 +|.define CARG4, r9 +|.define CARG1d, ecx +|.define CARG2d, edx +|.define CARG3d, r8d +|.define CARG4d, r9d +|.define FCARG1, CARG1d // Upwards compatible to x86 fastcall. +|.define FCARG2, CARG2d +|.else +|.define CARG1, rdi // x64/POSIX C call arguments. +|.define CARG2, rsi +|.define CARG3, rdx +|.define CARG4, rcx +|.define CARG5, r8 +|.define CARG6, r9 +|.define CARG1d, edi +|.define CARG2d, esi +|.define CARG3d, edx +|.define CARG4d, ecx +|.define CARG5d, r8d +|.define CARG6d, r9d +|.define FCARG1, CARG1d // Simulate x86 fastcall. +|.define FCARG2, CARG2d +|.endif +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS, int +|.type TRACE, GCtrace +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|//----------------------------------------------------------------------- +|.if not X64 // x86 stack layout. +| +|.define CFRAME_SPACE, aword*7 // Delta for esp (see <--). +|.macro saveregs_ +| push edi; push esi; push ebx +| sub esp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push ebp; saveregs_ +|.endmacro +|.macro restoreregs +| add esp, CFRAME_SPACE +| pop ebx; pop esi; pop edi; pop ebp +|.endmacro +| +|.define SAVE_ERRF, aword [esp+aword*15] // vm_pcall/vm_cpcall only. +|.define SAVE_NRES, aword [esp+aword*14] +|.define SAVE_CFRAME, aword [esp+aword*13] +|.define SAVE_L, aword [esp+aword*12] +|//----- 16 byte aligned, ^^^ arguments from C caller +|.define SAVE_RET, aword [esp+aword*11] //<-- esp entering interpreter. +|.define SAVE_R4, aword [esp+aword*10] +|.define SAVE_R3, aword [esp+aword*9] +|.define SAVE_R2, aword [esp+aword*8] +|//----- 16 byte aligned +|.define SAVE_R1, aword [esp+aword*7] //<-- esp after register saves. +|.define SAVE_PC, aword [esp+aword*6] +|.define TMP2, aword [esp+aword*5] +|.define TMP1, aword [esp+aword*4] +|//----- 16 byte aligned +|.define ARG4, aword [esp+aword*3] +|.define ARG3, aword [esp+aword*2] +|.define ARG2, aword [esp+aword*1] +|.define ARG1, aword [esp] //<-- esp while in interpreter. +|//----- 16 byte aligned, ^^^ arguments for C callee +| +|// FPARGx overlaps ARGx and ARG(x+1) on x86. +|.define FPARG3, qword [esp+qword*1] +|.define FPARG1, qword [esp] +|// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ). +|.define TMPQ, qword [esp+aword*4] +|.define TMP3, ARG4 +|.define ARG5, TMP1 +|.define TMPa, TMP1 +|.define MULTRES, TMP2 +| +|// Arguments for vm_call and vm_pcall. +|.define INARG_BASE, SAVE_CFRAME // Overwritten by SAVE_CFRAME! +| +|// Arguments for vm_cpcall. +|.define INARG_CP_CALL, SAVE_ERRF +|.define INARG_CP_UD, SAVE_NRES +|.define INARG_CP_FUNC, SAVE_CFRAME +| +|//----------------------------------------------------------------------- +|.elif X64WIN // x64/Windows stack layout +| +|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). +|.macro saveregs_ +| push rdi; push rsi; push rbx +| sub rsp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push rbp; saveregs_ +|.endmacro +|.macro restoreregs +| add rsp, CFRAME_SPACE +| pop rbx; pop rsi; pop rdi; pop rbp +|.endmacro +| +|.define SAVE_CFRAME, aword [rsp+aword*13] +|.define SAVE_PC, dword [rsp+dword*25] +|.define SAVE_L, dword [rsp+dword*24] +|.define SAVE_ERRF, dword [rsp+dword*23] +|.define SAVE_NRES, dword [rsp+dword*22] +|.define TMP2, dword [rsp+dword*21] +|.define TMP1, dword [rsp+dword*20] +|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter +|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*8] +|.define SAVE_R3, aword [rsp+aword*7] +|.define SAVE_R2, aword [rsp+aword*6] +|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.define ARG5, aword [rsp+aword*4] +|.define CSAVE_4, aword [rsp+aword*3] +|.define CSAVE_3, aword [rsp+aword*2] +|.define CSAVE_2, aword [rsp+aword*1] +|.define CSAVE_1, aword [rsp] //<-- rsp while in interpreter. +|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee +| +|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ). +|.define TMPQ, qword [rsp+aword*10] +|.define MULTRES, TMP2 +|.define TMPa, ARG5 +|.define ARG5d, dword [rsp+aword*4] +|.define TMP3, ARG5d +| +|//----------------------------------------------------------------------- +|.else // x64/POSIX stack layout +| +|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). +|.macro saveregs_ +| push rbx; push r15; push r14 +| sub rsp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push rbp; saveregs_ +|.endmacro +|.macro restoreregs +| add rsp, CFRAME_SPACE +| pop r14; pop r15; pop rbx; pop rbp +|.endmacro +| +|//----- 16 byte aligned, +|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*8] +|.define SAVE_R3, aword [rsp+aword*7] +|.define SAVE_R2, aword [rsp+aword*6] +|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.define SAVE_CFRAME, aword [rsp+aword*4] +|.define SAVE_PC, dword [rsp+dword*7] +|.define SAVE_L, dword [rsp+dword*6] +|.define SAVE_ERRF, dword [rsp+dword*5] +|.define SAVE_NRES, dword [rsp+dword*4] +|.define TMPa, aword [rsp+aword*1] +|.define TMP2, dword [rsp+dword*1] +|.define TMP1, dword [rsp] //<-- rsp while in interpreter. +|//----- 16 byte aligned +| +|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ). +|.define TMPQ, qword [rsp] +|.define TMP3, dword [rsp+aword*1] +|.define MULTRES, TMP2 +| +|.endif +| +|//----------------------------------------------------------------------- +| +|// Instruction headers. +|.macro ins_A; .endmacro +|.macro ins_AD; .endmacro +|.macro ins_AJ; .endmacro +|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro +|.macro ins_AB_; movzx RB, RCH; .endmacro +|.macro ins_A_C; movzx RC, RCL; .endmacro +|.macro ins_AND; not RDa; .endmacro +| +|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster). +|.macro ins_NEXT +| mov RC, [PC] +| movzx RA, RCH +| movzx OP, RCL +| add PC, 4 +| shr RC, 16 +|.if X64 +| jmp aword [DISPATCH+OP*8] +|.else +| jmp aword [DISPATCH+OP*4] +|.endif +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| // Around 10%-30% slower on Core2, a lot more slower on P4. +| .macro ins_next +| jmp ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC +| mov PC, LFUNC:RB->pc +| mov RA, [PC] +| movzx OP, RAL +| movzx RA, RAH +| add PC, 4 +|.if X64 +| jmp aword [DISPATCH+OP*8] +|.else +| jmp aword [DISPATCH+OP*4] +|.endif +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC, RD = nargs+1 +| mov [BASE-4], PC +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checktp, reg, tp; cmp dword [BASE+reg*8+4], tp; .endmacro +|.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro +|.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro +|.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro +|.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro +| +|// These operands must be used with movzx. +|.define PC_OP, byte [PC-4] +|.define PC_RA, byte [PC-3] +|.define PC_RB, byte [PC-1] +|.define PC_RC, byte [PC-2] +|.define PC_RD, word [PC-2] +| +|.macro branchPC, reg +| lea PC, [PC+reg*4-BCBIAS_J*4] +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|// Decrement hashed hotcount and trigger trace recorder if zero. +|.macro hotloop, reg +| mov reg, PC +| shr reg, 1 +| and reg, HOTCOUNT_PCMASK +| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP +| jb ->vm_hotloop +|.endmacro +| +|.macro hotcall, reg +| mov reg, PC +| shr reg, 1 +| and reg, HOTCOUNT_PCMASK +| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL +| jb ->vm_hotcall +|.endmacro +| +|// Set current VM state. +|.macro set_vmstate, st +| mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st +|.endmacro +| +|// x87 compares. +|.macro fcomparepp // Compare and pop st0 >< st1. +| fucomip st1 +| fpop +|.endmacro +| +|.macro fdup; fld st0; .endmacro +|.macro fpop1; fstp st1; .endmacro +| +|// Synthesize SSE FP constants. +|.macro sseconst_abs, reg, tmp // Synthesize abs mask. +|.if X64 +| mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp +|.else +| pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1 +|.endif +|.endmacro +| +|.macro sseconst_hi, reg, tmp, val // Synthesize hi-32 bit const. +|.if X64 +| mov64 tmp, U64x(val,00000000); movd reg, tmp +|.else +| mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51 +|.endif +|.endmacro +| +|.macro sseconst_sign, reg, tmp // Synthesize sign mask. +| sseconst_hi reg, tmp, 80000000 +|.endmacro +|.macro sseconst_1, reg, tmp // Synthesize 1.0. +| sseconst_hi reg, tmp, 3ff00000 +|.endmacro +|.macro sseconst_m1, reg, tmp // Synthesize -1.0. +| sseconst_hi reg, tmp, bff00000 +|.endmacro +|.macro sseconst_2p52, reg, tmp // Synthesize 2^52. +| sseconst_hi reg, tmp, 43300000 +|.endmacro +|.macro sseconst_tobit, reg, tmp // Synthesize 2^52 + 2^51. +| sseconst_hi reg, tmp, 43380000 +|.endmacro +| +|// Move table write barrier back. Overwrites reg. +|.macro barrierback, tab, reg +| and byte tab->marked, (uint8_t)~LJ_GC_BLACK // black2gray(tab) +| mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)] +| mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab +| mov tab->gclist, reg +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | test PC, FRAME_P + | jz ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | and PC, -8 + | sub BASE, PC // Restore caller base. + | lea RAa, [RA+PC-8] // Rebase RA and prepend one result. + | mov PC, [BASE-4] // Fetch PC of previous frame. + | // Prepending may overwrite the pcall frame, so do it at the end. + | mov dword [BASE+RA+4], LJ_TTRUE // Prepend true to results. + | + |->vm_returnc: + | add RD, 1 // RD = nresults+1 + | jz ->vm_unwind_yield + | mov MULTRES, RD + | test PC, FRAME_TYPE + | jz ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return + | xor PC, FRAME_C + | test PC, FRAME_TYPE + | jnz ->vm_returnp + | + | // Return to C. + | set_vmstate C + | and PC, -8 + | sub PC, BASE + | neg PC // Previous base = BASE - delta. + | + | sub RD, 1 + | jz >2 + |1: // Move results down. + |.if X64 + | mov RBa, [BASE+RA] + | mov [BASE-8], RBa + |.else + | mov RB, [BASE+RA] + | mov [BASE-8], RB + | mov RB, [BASE+RA+4] + | mov [BASE-4], RB + |.endif + | add BASE, 8 + | sub RD, 1 + | jnz <1 + |2: + | mov L:RB, SAVE_L + | mov L:RB->base, PC + |3: + | mov RD, MULTRES + | mov RA, SAVE_NRES // RA = wanted nresults+1 + |4: + | cmp RA, RD + | jne >6 // More/less results wanted? + |5: + | sub BASE, 8 + | mov L:RB->top, BASE + | + |->vm_leave_cp: + | mov RAa, SAVE_CFRAME // Restore previous C frame. + | mov L:RB->cframe, RAa + | xor eax, eax // Ok return status for vm_pcall. + | + |->vm_leave_unw: + | restoreregs + | ret + | + |6: + | jb >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | cmp BASE, L:RB->maxstack + | ja >8 + | mov dword [BASE-4], LJ_TNIL + | add BASE, 8 + | add RD, 1 + | jmp <4 + | + |7: // Less results wanted. + | test RA, RA + | jz <5 // But check for LUA_MULTRET+1. + | sub RA, RD // Negative result! + | lea BASE, [BASE+RA*8] // Correct top. + | jmp <5 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | mov L:RB->top, BASE // Save current top held in BASE (yes). + | mov MULTRES, RD // Need to fill only remainder with nil. + | mov FCARG2, RA + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->top // Need the (realloced) L->top in BASE. + | jmp <3 + | + |->vm_unwind_yield: + | mov al, LUA_YIELD + | jmp ->vm_unwind_c_eh + | + |->vm_unwind_c@8: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + |.if X64 + | mov eax, CARG2d // Error return status for vm_pcall. + | mov rsp, CARG1 + |.else + | mov eax, FCARG2 // Error return status for vm_pcall. + | mov esp, FCARG1 + |.endif + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | mov L:RB, SAVE_L + | mov GL:RB, L:RB->glref + | mov dword GL:RB->vmstate, ~LJ_VMST_C + | jmp ->vm_leave_unw + | + |->vm_unwind_rethrow: + |.if X64 and not X64WIN + | mov FCARG1, SAVE_L + | mov FCARG2, eax + | restoreregs + | jmp extern lj_err_throw@8 // (lua_State *L, int errcode) + |.endif + | + |->vm_unwind_ff@4: // Unwind C stack, return from ff pcall. + | // (void *cframe) + |.if X64 + | and CARG1, CFRAME_RAWMASK + | mov rsp, CARG1 + |.else + | and FCARG1, CFRAME_RAWMASK + | mov esp, FCARG1 + |.endif + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | mov L:RB, SAVE_L + | mov RAa, -8 // Results start at BASE+RA = BASE-8. + | mov RD, 1+1 // Really 1+2 results, incr. later. + | mov BASE, L:RB->base + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | mov PC, [BASE-4] // Fetch PC of previous frame. + | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message. + | set_vmstate INTERP + | jmp ->vm_returnc // Increments RD/MULTRES and returns. + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | mov FCARG2, LUA_MINSTACK + | jmp >2 + | + |->vm_growstack_v: // Grow stack for vararg Lua function. + | sub RD, 8 + | jmp >1 + | + |->vm_growstack_f: // Grow stack for fixarg Lua function. + | // BASE = new base, RD = nargs+1, RB = L, PC = first PC + | lea RD, [BASE+NARGS:RD*8-8] + |1: + | movzx RA, byte [PC-4+PC2PROTO(framesize)] + | add PC, 4 // Must point after first instruction. + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov SAVE_PC, PC + | mov FCARG2, RA + |2: + | // RB = L, L->base = new base, L->top = top + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | mov RD, L:RB->top + | mov LFUNC:RB, [BASE-8] + | sub RD, BASE + | shr RD, 3 + | add NARGS:RD, 1 + | // BASE = new base, RB = LFUNC, RD = nargs+1 + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + |.if X64 + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + | mov RA, CARG2d + |.else + | mov L:RB, SAVE_L + | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! + |.endif + | mov PC, FRAME_CP + | xor RD, RD + | lea KBASEa, [esp+CFRAME_RESUME] + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | mov L:RB->cframe, KBASEa + | mov SAVE_PC, RD // Any value outside of bytecode is ok. + | mov SAVE_CFRAME, RDa + |.if X64 + | mov SAVE_NRES, RD + | mov SAVE_ERRF, RD + |.endif + | cmp byte L:RB->status, RDL + | je >3 // Initial resume (like a call). + | + | // Resume after yield (like a return). + | set_vmstate INTERP + | mov byte L:RB->status, RDL + | mov BASE, L:RB->base + | mov RD, L:RB->top + | sub RD, RA + | shr RD, 3 + | add RD, 1 // RD = nresults+1 + | sub RA, BASE // RA = resultofs + | mov PC, [BASE-4] + | mov MULTRES, RD + | test PC, FRAME_TYPE + | jz ->BC_RET_Z + | jmp ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | mov PC, FRAME_CP + |.if X64 + | mov SAVE_ERRF, CARG4d + |.endif + | jmp >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | mov PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + |.if X64 + | mov SAVE_NRES, CARG3d + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + | mov RA, CARG2d + |.else + | mov L:RB, SAVE_L + | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! + |.endif + | + | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASEa + | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. + |.if X64 + | mov L:RB->cframe, rsp + |.else + | mov L:RB->cframe, esp + |.endif + | + |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype). + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype). + | set_vmstate INTERP + | mov BASE, L:RB->base // BASE = old base (used in vmeta_call). + | add PC, RA + | sub PC, BASE // PC = frame delta + frame type + | + | mov RD, L:RB->top + | sub RD, RA + | shr NARGS:RD, 3 + | add NARGS:RD, 1 // RD = nargs+1 + | + |->vm_call_dispatch: + | mov LFUNC:RB, [RA-8] + | cmp dword [RA-4], LJ_TFUNC + | jne ->vmeta_call // Ensure KBASE defined and != BASE. + | + |->vm_call_dispatch_f: + | mov BASE, RA + | ins_call + | // BASE = new base, RB = func, RD = nargs+1, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + |.if X64 + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + |.else + | mov L:RB, SAVE_L + | // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap! + | mov RC, INARG_CP_UD // Get args before they are overwritten. + | mov RA, INARG_CP_FUNC + | mov BASE, INARG_CP_CALL + |.endif + | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. + | + | mov KBASE, L:RB->stack // Compute -savestack(L, L->top). + | sub KBASE, L:RB->top + | mov SAVE_ERRF, 0 // No error function. + | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame. + | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe). + | + |.if X64 + | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASEa + | mov L:RB->cframe, rsp + | + | call CARG4 // (lua_State *L, lua_CFunction func, void *ud) + |.else + | mov ARG3, RC // Have to copy args downwards. + | mov ARG2, RA + | mov ARG1, L:RB + | + | mov KBASE, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASE + | mov L:RB->cframe, esp + | + | call BASE // (lua_State *L, lua_CFunction func, void *ud) + |.endif + | // TValue * (new base) or NULL returned in eax (RC). + | test RC, RC + | jz ->vm_leave_cp // No base? Just remove C frame. + | mov RA, RC + | mov PC, FRAME_CP + | jmp <2 // Else continue with the call. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES) + | add RA, BASE + | and PC, -8 + | mov RB, BASE + | sub BASE, PC // Restore caller BASE. + | mov dword [RA+RD*8-4], LJ_TNIL // Ensure one valid arg. + | mov RC, RA // ... in [RC] + | mov PC, [RB-12] // Restore PC from [cont|PC]. + |.if X64 + | movsxd RAa, dword [RB-16] // May be negative on WIN64 with debug. + |.if FFI + | cmp RA, 1 + | jbe >1 + |.endif + | lea KBASEa, qword [=>0] + | add RAa, KBASEa + |.else + | mov RA, dword [RB-16] + |.if FFI + | cmp RA, 1 + | jbe >1 + |.endif + |.endif + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | // BASE = base, RC = result, RB = meta base + | jmp RAa // Jump to continuation. + | + |.if FFI + |1: + | je ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: Tail call from C function. + | sub RB, BASE + | shr RB, 3 + | lea RD, [RB-1] + | jmp ->vm_call_tail + |.endif + | + |->cont_cat: // BASE = base, RC = result, RB = mbase + | movzx RA, PC_RB + | sub RB, 16 + | lea RA, [BASE+RA*8] + | sub RA, RB + | je ->cont_ra + | neg RA + | shr RA, 3 + |.if X64WIN + | mov CARG3d, RA + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | mov RCa, [RC] + | mov [RB], RCa + | mov CARG2d, RB + |.elif X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | mov CARG3d, RA + | mov RAa, [RC] + | mov [RB], RAa + | mov CARG2d, RB + |.else + | mov ARG3, RA + | mov RA, [RC+4] + | mov RC, [RC] + | mov [RB+4], RA + | mov [RB], RC + | mov ARG2, RB + |.endif + | jmp ->BC_CAT_Z + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets: + | mov TMP1, RC // RC = GCstr * + | mov TMP2, LJ_TSTR + | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2. + | cmp PC_OP, BC_GGET + | jne >1 + | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. + | mov [RA], TAB:RB // RB = GCtab * + | mov dword [RA+4], LJ_TTAB + | mov RB, RA + | jmp >2 + | + |->vmeta_tgetb: + | movzx RC, PC_RC + |.if DUALNUM + | mov TMP2, LJ_TISNUM + | mov TMP1, RC + |.elif SSE + | cvtsi2sd xmm0, RC + | movsd TMPQ, xmm0 + |.else + | mov ARG4, RC + | fild ARG4 + | fstp TMPQ + |.endif + | lea RCa, TMPQ // Store temp. TValue in TMPQ. + | jmp >1 + | + |->vmeta_tgetv: + | movzx RC, PC_RC // Reload TValue *k from RC. + | lea RC, [BASE+RC*8] + |1: + | movzx RB, PC_RB // Reload TValue *t from RB. + | lea RB, [BASE+RB*8] + |2: + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RB + | mov CARG3, RCa // May be 64 bit ptr to stack. + | mov L:RB, L:CARG1d + |.else + | mov ARG2, RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // TValue * (finished) or NULL (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz >3 + |->cont_ra: // BASE = base, RC = result + | movzx RA, PC_RA + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC+4] + | mov RC, [RC] + | mov [BASE+RA*8+4], RB + | mov [BASE+RA*8], RC + |.endif + | ins_next + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | mov RA, L:RB->top + | mov [RA-12], PC // [cont|PC] + | lea PC, [RA+FRAME_CONT] + | sub PC, BASE + | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here. + | mov NARGS:RD, 2+1 // 2 args for func(t, k). + | jmp ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets: + | mov TMP1, RC // RC = GCstr * + | mov TMP2, LJ_TSTR + | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2. + | cmp PC_OP, BC_GSET + | jne >1 + | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. + | mov [RA], TAB:RB // RB = GCtab * + | mov dword [RA+4], LJ_TTAB + | mov RB, RA + | jmp >2 + | + |->vmeta_tsetb: + | movzx RC, PC_RC + |.if DUALNUM + | mov TMP2, LJ_TISNUM + | mov TMP1, RC + |.elif SSE + | cvtsi2sd xmm0, RC + | movsd TMPQ, xmm0 + |.else + | mov ARG4, RC + | fild ARG4 + | fstp TMPQ + |.endif + | lea RCa, TMPQ // Store temp. TValue in TMPQ. + | jmp >1 + | + |->vmeta_tsetv: + | movzx RC, PC_RC // Reload TValue *k from RC. + | lea RC, [BASE+RC*8] + |1: + | movzx RB, PC_RB // Reload TValue *t from RB. + | lea RB, [BASE+RB*8] + |2: + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RB + | mov CARG3, RCa // May be 64 bit ptr to stack. + | mov L:RB, L:CARG1d + |.else + | mov ARG2, RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // TValue * (finished) or NULL (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | movzx RA, PC_RA + |.if X64 + | mov RBa, [BASE+RA*8] + | mov [RC], RBa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + |->cont_nop: // BASE = base, (RC = result) + | ins_next + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | mov RA, L:RB->top + | mov [RA-12], PC // [cont|PC] + | movzx RC, PC_RA + | // Copy value to third argument. + |.if X64 + | mov RBa, [BASE+RC*8] + | mov [RA+16], RBa + |.else + | mov RB, [BASE+RC*8+4] + | mov RC, [BASE+RC*8] + | mov [RA+20], RB + | mov [RA+16], RC + |.endif + | lea PC, [RA+FRAME_CONT] + | sub PC, BASE + | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here. + | mov NARGS:RD, 3+1 // 3 args for func(t, k, v). + | jmp ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d == BASE. + |.if X64WIN + | lea CARG3d, [BASE+RD*8] + | lea CARG2d, [BASE+RA*8] + |.else + | lea CARG2d, [BASE+RA*8] + | lea CARG3d, [BASE+RD*8] + |.endif + | mov CARG1d, L:RB // Caveat: CARG1d/CARG4d == RA. + | movzx CARG4d, PC_OP + |.else + | movzx RB, PC_OP + | lea RD, [BASE+RD*8] + | lea RA, [BASE+RA*8] + | mov ARG4, RB + | mov L:RB, SAVE_L + | mov ARG3, RD + | mov ARG2, RA + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + |3: + | mov BASE, L:RB->base + | cmp RC, 1 + | ja ->vmeta_binop + |4: + | lea PC, [PC+4] + | jb >6 + |5: + | movzx RD, PC_RD + | branchPC RD + |6: + | ins_next + | + |->cont_condt: // BASE = base, RC = result + | add PC, 4 + | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is true. + | jb <5 + | jmp <6 + | + |->cont_condf: // BASE = base, RC = result + | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is false. + | jmp <4 + | + |->vmeta_equal: + | sub PC, 4 + |.if X64WIN + | mov CARG3d, RD + | mov CARG4d, RB + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d == BASE. + | mov CARG2d, RA + | mov CARG1d, L:RB // Caveat: CARG1d == RA. + |.elif X64 + | mov CARG2d, RA + | mov CARG4d, RB // Caveat: CARG4d == RA. + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG3d == BASE. + | mov CARG3d, RD + | mov CARG1d, L:RB + |.else + | mov ARG4, RB + | mov L:RB, SAVE_L + | mov ARG3, RD + | mov ARG2, RA + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + | jmp <3 + | + |->vmeta_equal_cd: + |.if FFI + | sub PC, 4 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG1, L:RB + | mov FCARG2, dword [PC-4] + | mov SAVE_PC, PC + | call extern lj_meta_equal_cd@8 // (lua_State *L, BCIns ins) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + | jmp <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vno: + |.if DUALNUM + | movzx RB, PC_RB + |.endif + |->vmeta_arith_vn: + | lea RC, [KBASE+RC*8] + | jmp >1 + | + |->vmeta_arith_nvo: + |.if DUALNUM + | movzx RC, PC_RC + |.endif + |->vmeta_arith_nv: + | lea RC, [KBASE+RC*8] + | lea RB, [BASE+RB*8] + | xchg RB, RC + | jmp >2 + | + |->vmeta_unm: + | lea RC, [BASE+RD*8] + | mov RB, RC + | jmp >2 + | + |->vmeta_arith_vvo: + |.if DUALNUM + | movzx RB, PC_RB + |.endif + |->vmeta_arith_vv: + | lea RC, [BASE+RC*8] + |1: + | lea RB, [BASE+RB*8] + |2: + | lea RA, [BASE+RA*8] + |.if X64WIN + | mov CARG3d, RB + | mov CARG4d, RC + | movzx RC, PC_OP + | mov ARG5d, RC + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d == BASE. + | mov CARG2d, RA + | mov CARG1d, L:RB // Caveat: CARG1d == RA. + |.elif X64 + | movzx CARG5d, PC_OP + | mov CARG2d, RA + | mov CARG4d, RC // Caveat: CARG4d == RA. + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG3d == BASE. + | mov CARG3d, RB + | mov L:RB, L:CARG1d + |.else + | mov ARG3, RB + | mov L:RB, SAVE_L + | mov ARG4, RC + | movzx RC, PC_OP + | mov ARG2, RA + | mov ARG5, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // NULL (finished) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = base, RC = new base, stack = cont/func/o1/o2 + | mov RA, RC + | sub RC, BASE + | mov [RA-12], PC // [cont|PC] + | lea PC, [RC+FRAME_CONT] + | mov NARGS:RD, 2+1 // 2 args for func(o1, o2). + | jmp ->vm_call_dispatch + | + |->vmeta_len: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | lea FCARG2, [BASE+RD*8] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB + | mov SAVE_PC, PC + | call extern lj_meta_len@8 // (lua_State *L, TValue *o) + | // NULL (retry) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base +#if LJ_52 + | test RC, RC + | jne ->vmeta_binop // Binop call for compatibility. + | movzx RD, PC_RD + | mov TAB:FCARG1, [BASE+RD*8] + | jmp ->BC_LEN_Z +#else + | jmp ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call_ra: + | lea RA, [BASE+RA*8+8] + |->vmeta_call: // Resolve and call __call metamethod. + | // BASE = old base, RA = new base, RC = nargs+1, PC = return + | mov TMP2, RA // Save RA, RC for us. + | mov TMP1, NARGS:RD + | sub RA, 8 + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RA + | lea CARG3d, [RA+NARGS:RD*8] + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | lea RC, [RA+NARGS:RD*8] + | mov L:RB, SAVE_L + | mov ARG2, RA + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE // This is the callers base! + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | mov BASE, L:RB->base + | mov RA, TMP2 + | mov NARGS:RD, TMP1 + | mov LFUNC:RB, [RA-8] + | add NARGS:RD, 1 + | // This is fragile. L->base must not move, KBASE must always be defined. + | cmp KBASE, BASE // Continue with CALLT if flag set. + | je ->BC_CALLT_Z + | mov BASE, RA + | ins_call // Otherwise call resolved metamethod. + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG2, RA // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | mov SAVE_PC, PC + | call extern lj_meta_for@8 // (lua_State *L, TValue *base) + | mov BASE, L:RB->base + | mov RC, [PC-4] + | movzx RA, RCH + | movzx OP, RCL + | shr RC, 16 + |.if X64 + | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Retry FORI or JFORI. + |.else + | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Retry FORI or JFORI. + |.endif + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmp NARGS:RD, 1+1; jb ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmp NARGS:RD, 2+1; jb ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE] + |.endmacro + | + |.macro .ffunc_n, name, op + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | op + | fld qword [BASE] + |.endmacro + | + |.macro .ffunc_nsse, name, op + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | op xmm0, qword [BASE] + |.endmacro + | + |.macro .ffunc_nsse, name + | .ffunc_nsse name, movsd + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE] + | fld qword [BASE+8] + |.endmacro + | + |.macro .ffunc_nnsse, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | movsd xmm0, qword [BASE] + | movsd xmm1, qword [BASE+8] + |.endmacro + | + |.macro .ffunc_nnr, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE+8] + | fld qword [BASE] + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses label 1. + |.macro ffgccheck + | mov RB, [DISPATCH+DISPATCH_GL(gc.total)] + | cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)] + | jb >1 + | call ->fff_gcstep + |1: + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | mov RB, [BASE+4] + | cmp RB, LJ_TISTRUECOND; jae ->fff_fallback + | mov PC, [BASE-4] + | mov MULTRES, RD + | mov [BASE-4], RB + | mov RB, [BASE] + | mov [BASE-8], RB + | sub RD, 2 + | jz >2 + | mov RA, BASE + |1: + | add RA, 8 + |.if X64 + | mov RBa, [RA] + | mov [RA-8], RBa + |.else + | mov RB, [RA+4] + | mov [RA-4], RB + | mov RB, [RA] + | mov [RA-8], RB + |.endif + | sub RD, 1 + | jnz <1 + |2: + | mov RD, MULTRES + | jmp ->fff_res_ + | + |.ffunc_1 type + | mov RB, [BASE+4] + |.if X64 + | mov RA, RB + | sar RA, 15 + | cmp RA, -2 + | je >3 + |.endif + | mov RC, ~LJ_TNUMX + | not RB + | cmp RC, RB + | cmova RC, RB + |2: + | mov CFUNC:RB, [BASE-8] + | mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RC + | jmp ->fff_res1 + |.if X64 + |3: + | mov RC, ~LJ_TLIGHTUD + | jmp <2 + |.endif + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | mov RB, [BASE+4] + | mov PC, [BASE-4] + | cmp RB, LJ_TTAB; jne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | mov TAB:RB, [BASE] + | mov TAB:RB, TAB:RB->metatable + |2: + | test TAB:RB, TAB:RB + | mov dword [BASE-4], LJ_TNIL + | jz ->fff_res1 + | mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)] + | mov dword [BASE-4], LJ_TTAB // Store metatable as default result. + | mov [BASE-8], TAB:RB + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | add NODE:RA, TAB:RB->node + |3: // Rearranged logic, because we expect _not_ to find the key. + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >4 + | cmp dword NODE:RA->key.gcr, STR:RC + | je >5 + |4: + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <3 + | jmp ->fff_res1 // Not found, keep default result. + |5: + | mov RB, [RA+4] + | cmp RB, LJ_TNIL; je ->fff_res1 // Ditto for nil value. + | mov RC, [RA] + | mov [BASE-4], RB // Return value of mt.__metatable. + | mov [BASE-8], RC + | jmp ->fff_res1 + | + |6: + | cmp RB, LJ_TUDATA; je <1 + |.if X64 + | cmp RB, LJ_TNUMX; ja >8 + | cmp RB, LJ_TISNUM; jbe >7 + | mov RB, LJ_TLIGHTUD + | jmp >8 + |7: + |.else + | cmp RB, LJ_TISNUM; ja >8 + |.endif + | mov RB, LJ_TNUMX + |8: + | not RB + | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])] + | jmp <2 + | + |.ffunc_2 setmetatable + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | // Fast path: no mt for table yet and not clearing the mt. + | mov TAB:RB, [BASE] + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TTAB; jne ->fff_fallback + | mov TAB:RC, [BASE+8] + | mov TAB:RB->metatable, TAB:RC + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TTAB // Return original table. + | mov [BASE-8], TAB:RB + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jz >1 + | // Possible write barrier. Table is black, but skip iswhite(mt) check. + | barrierback TAB:RB, RC + |1: + | jmp ->fff_res1 + | + |.ffunc_2 rawget + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + |.if X64WIN + | mov RB, BASE // Save BASE. + | lea CARG3d, [BASE+8] + | mov CARG2d, [BASE] // Caveat: CARG2d == BASE. + | mov CARG1d, SAVE_L + |.elif X64 + | mov RB, BASE // Save BASE. + | mov CARG2d, [BASE] + | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE. + | mov CARG1d, SAVE_L + |.else + | mov TAB:RD, [BASE] + | mov L:RB, SAVE_L + | mov ARG2, TAB:RD + | mov ARG1, L:RB + | mov RB, BASE // Save BASE. + | add BASE, 8 + | mov ARG3, BASE + |.endif + | call extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // cTValue * returned in eax (RD). + | mov BASE, RB // Restore BASE. + | // Copy table slot. + |.if X64 + | mov RBa, [RD] + | mov PC, [BASE-4] + | mov [BASE-8], RBa + |.else + | mov RB, [RD] + | mov RD, [RD+4] + | mov PC, [BASE-4] + | mov [BASE-8], RB + | mov [BASE-4], RD + |.endif + | jmp ->fff_res1 + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument. + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >1 + | mov RB, dword [BASE]; jmp ->fff_resi + |1: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE]; jmp ->fff_resxmm0 + |.else + | fld qword [BASE]; jmp ->fff_resn + |.endif + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | mov PC, [BASE-4] + | cmp dword [BASE+4], LJ_TSTR; jne >3 + | // A __tostring method in the string base metatable is ignored. + | mov STR:RD, [BASE] + |2: + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RD + | jmp ->fff_res1 + |3: // Handle numbers inline, unless a number base metatable is present. + | cmp dword [BASE+4], LJ_TISNUM; ja ->fff_fallback + | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0 + | jne ->fff_fallback + | ffgccheck // Caveat: uses label 1. + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Add frame since C call can throw. + | mov SAVE_PC, PC // Redundant (but a defined value). + |.if X64 and not X64WIN + | mov FCARG2, BASE // Otherwise: FCARG2 == BASE + |.endif + | mov L:FCARG1, L:RB + |.if DUALNUM + | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o) + |.else + | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np) + |.endif + | // GCstr returned in eax (RD). + | mov BASE, L:RB->base + | jmp <2 + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc_1 next + | je >2 // Missing 2nd arg? + |1: + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Add frame since C call can throw. + | mov L:RB->top, BASE // Dummy frame length is ok. + | mov PC, [BASE-4] + |.if X64WIN + | lea CARG3d, [BASE+8] + | mov CARG2d, [BASE] // Caveat: CARG2d == BASE. + | mov CARG1d, L:RB + |.elif X64 + | mov CARG2d, [BASE] + | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE. + | mov CARG1d, L:RB + |.else + | mov TAB:RD, [BASE] + | mov ARG2, TAB:RD + | mov ARG1, L:RB + | add BASE, 8 + | mov ARG3, BASE + |.endif + | mov SAVE_PC, PC // Needed for ITERN fallback. + | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Flag returned in eax (RD). + | mov BASE, L:RB->base + | test RD, RD; jz >3 // End of traversal? + | // Copy key and value to results. + |.if X64 + | mov RBa, [BASE+8] + | mov RDa, [BASE+16] + | mov [BASE-8], RBa + | mov [BASE], RDa + |.else + | mov RB, [BASE+8] + | mov RD, [BASE+12] + | mov [BASE-8], RB + | mov [BASE-4], RD + | mov RB, [BASE+16] + | mov RD, [BASE+20] + | mov [BASE], RB + | mov [BASE+4], RD + |.endif + |->fff_res2: + | mov RD, 1+2 + | jmp ->fff_res + |2: // Set missing 2nd arg to nil. + | mov dword [BASE+12], LJ_TNIL + | jmp <1 + |3: // End of traversal: return nil. + | mov dword [BASE-4], LJ_TNIL + | jmp ->fff_res1 + | + |.ffunc_1 pairs + | mov TAB:RB, [BASE] + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback +#if LJ_52 + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback +#endif + | mov CFUNC:RB, [BASE-8] + | mov CFUNC:RD, CFUNC:RB->upvalue[0] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TFUNC + | mov [BASE-8], CFUNC:RD + | mov dword [BASE+12], LJ_TNIL + | mov RD, 1+3 + | jmp ->fff_res + | + |.ffunc_1 ipairs_aux + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | mov PC, [BASE-4] + |.if DUALNUM + | mov RD, dword [BASE+8] + | add RD, 1 + | mov dword [BASE-4], LJ_TISNUM + | mov dword [BASE-8], RD + |.elif SSE + | movsd xmm0, qword [BASE+8] + | sseconst_1 xmm1, RBa + | addsd xmm0, xmm1 + | cvtsd2si RD, xmm0 + | movsd qword [BASE-8], xmm0 + |.else + | fld qword [BASE+8] + | fld1 + | faddp st1 + | fist ARG1 + | fstp qword [BASE-8] + | mov RD, ARG1 + |.endif + | mov TAB:RB, [BASE] + | cmp RD, TAB:RB->asize; jae >2 // Not in array part? + | shl RD, 3 + | add RD, TAB:RB->array + |1: + | cmp dword [RD+4], LJ_TNIL; je ->fff_res0 + | // Copy array slot. + |.if X64 + | mov RBa, [RD] + | mov [BASE], RBa + |.else + | mov RB, [RD] + | mov RD, [RD+4] + | mov [BASE], RB + | mov [BASE+4], RD + |.endif + | jmp ->fff_res2 + |2: // Check for empty hash part first. Otherwise call C function. + | cmp dword TAB:RB->hmask, 0; je ->fff_res0 + | mov FCARG1, TAB:RB + | mov RB, BASE // Save BASE. + | mov FCARG2, RD // Caveat: FCARG2 == BASE + | call extern lj_tab_getinth@8 // (GCtab *t, int32_t key) + | // cTValue * or NULL returned in eax (RD). + | mov BASE, RB + | test RD, RD + | jnz <1 + |->fff_res0: + | mov RD, 1+0 + | jmp ->fff_res + | + |.ffunc_1 ipairs + | mov TAB:RB, [BASE] + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback +#if LJ_52 + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback +#endif + | mov CFUNC:RB, [BASE-8] + | mov CFUNC:RD, CFUNC:RB->upvalue[0] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TFUNC + | mov [BASE-8], CFUNC:RD + |.if DUALNUM + | mov dword [BASE+12], LJ_TISNUM + | mov dword [BASE+8], 0 + |.elif SSE + | xorps xmm0, xmm0 + | movsd qword [BASE+8], xmm0 + |.else + | fldz + | fstp qword [BASE+8] + |.endif + | mov RD, 1+3 + | jmp ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc_1 pcall + | lea RA, [BASE+8] + | sub NARGS:RD, 1 + | mov PC, 8+FRAME_PCALL + |1: + | movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)] + | shr RB, HOOK_ACTIVE_SHIFT + | and RB, 1 + | add PC, RB // Remember active hook before pcall. + | jmp ->vm_call_dispatch + | + |.ffunc_2 xpcall + | cmp dword [BASE+12], LJ_TFUNC; jne ->fff_fallback + | mov RB, [BASE+4] // Swap function and traceback. + | mov [BASE+12], RB + | mov dword [BASE+4], LJ_TFUNC + | mov LFUNC:RB, [BASE] + | mov PC, [BASE+8] + | mov [BASE+8], LFUNC:RB + | mov [BASE], PC + | lea RA, [BASE+16] + | sub NARGS:RD, 2 + | mov PC, 16+FRAME_PCALL + | jmp <1 + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | mov L:RB, [BASE] + |.else + |.ffunc coroutine_wrap_aux + | mov CFUNC:RB, [BASE-8] + | mov L:RB, CFUNC:RB->upvalue[0].gcr + |.endif + | mov PC, [BASE-4] + | mov SAVE_PC, PC + |.if X64 + | mov TMP1, L:RB + |.else + | mov ARG1, L:RB + |.endif + |.if resume + | cmp dword [BASE+4], LJ_TTHREAD; jne ->fff_fallback + |.endif + | cmp aword L:RB->cframe, 0; jne ->fff_fallback + | cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback + | mov RA, L:RB->top + | je >1 // Status != LUA_YIELD (i.e. 0)? + | cmp RA, L:RB->base // Check for presence of initial func. + | je ->fff_fallback + |1: + |.if resume + | lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread). + |.else + | lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1). + |.endif + | cmp PC, L:RB->maxstack; ja ->fff_fallback + | mov L:RB->top, PC + | + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + |.if resume + | add BASE, 8 // Keep resumed thread in stack for GC. + |.endif + | mov L:RB->top, BASE + |.if resume + | lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move. + |.else + | lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move. + |.endif + | sub RBa, PCa // Relative to PC. + | + | cmp PC, RA + | je >3 + |2: // Move args to coroutine. + |.if X64 + | mov RCa, [PC+RB] + | mov [PC-8], RCa + |.else + | mov RC, [PC+RB+4] + | mov [PC-4], RC + | mov RC, [PC+RB] + | mov [PC-8], RC + |.endif + | sub PC, 8 + | cmp PC, RA + | jne <2 + |3: + |.if X64 + | mov CARG2d, RA + | mov CARG1d, TMP1 + |.else + | mov ARG2, RA + | xor RA, RA + | mov ARG4, RA + | mov ARG3, RA + |.endif + | call ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | set_vmstate INTERP + | + | mov L:RB, SAVE_L + |.if X64 + | mov L:PC, TMP1 + |.else + | mov L:PC, ARG1 // The callee doesn't modify SAVE_L. + |.endif + | mov BASE, L:RB->base + | cmp eax, LUA_YIELD + | ja >8 + |4: + | mov RA, L:PC->base + | mov KBASE, L:PC->top + | mov L:PC->top, RA // Clear coroutine stack. + | mov PC, KBASE + | sub PC, RA + | je >6 // No results? + | lea RD, [BASE+PC] + | shr PC, 3 + | cmp RD, L:RB->maxstack + | ja >9 // Need to grow stack? + | + | mov RB, BASE + | sub RBa, RAa + |5: // Move results from coroutine. + |.if X64 + | mov RDa, [RA] + | mov [RA+RB], RDa + |.else + | mov RD, [RA] + | mov [RA+RB], RD + | mov RD, [RA+4] + | mov [RA+RB+4], RD + |.endif + | add RA, 8 + | cmp RA, KBASE + | jne <5 + |6: + |.if resume + | lea RD, [PC+2] // nresults+1 = 1 + true + results. + | mov dword [BASE-4], LJ_TTRUE // Prepend true to results. + |.else + | lea RD, [PC+1] // nresults+1 = 1 + results. + |.endif + |7: + | mov PC, SAVE_PC + | mov MULTRES, RD + |.if resume + | mov RAa, -8 + |.else + | xor RA, RA + |.endif + | test PC, FRAME_TYPE + | jz ->BC_RET_Z + | jmp ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | mov dword [BASE-4], LJ_TFALSE // Prepend false to results. + | mov RA, L:PC->top + | sub RA, 8 + | mov L:PC->top, RA // Clear error from coroutine stack. + | // Copy error message. + |.if X64 + | mov RDa, [RA] + | mov [BASE], RDa + |.else + | mov RD, [RA] + | mov [BASE], RD + | mov RD, [RA+4] + | mov [BASE+4], RD + |.endif + | mov RD, 1+2 // nresults+1 = 1 + false + error. + | jmp <7 + |.else + | mov FCARG2, L:PC + | mov FCARG1, L:RB + | call extern lj_ffh_coroutine_wrap_err@8 // (lua_State *L, lua_State *co) + | // Error function does not return. + |.endif + | + |9: // Handle stack expansion on return from yield. + |.if X64 + | mov L:RA, TMP1 + |.else + | mov L:RA, ARG1 // The callee doesn't modify SAVE_L. + |.endif + | mov L:RA->top, KBASE // Undo coroutine stack clearing. + | mov FCARG2, PC + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + |.if X64 + | mov L:PC, TMP1 + |.else + | mov L:PC, ARG1 + |.endif + | mov BASE, L:RB->base + | jmp <4 // Retry the stack move. + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | mov L:RB, SAVE_L + | test aword L:RB->cframe, CFRAME_RESUME + | jz ->fff_fallback + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB->top, RD + | xor RD, RD + | mov aword L:RB->cframe, RDa + | mov al, LUA_YIELD + | mov byte L:RB->status, al + | jmp ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.if not DUALNUM + |->fff_resi: // Dummy. + |.endif + | + |.if SSE + |->fff_resn: + | mov PC, [BASE-4] + | fstp qword [BASE-8] + | jmp ->fff_res1 + |.endif + | + | .ffunc_1 math_abs + |.if DUALNUM + | cmp dword [BASE+4], LJ_TISNUM; jne >2 + | mov RB, dword [BASE] + | cmp RB, 0; jns ->fff_resi + | neg RB; js >1 + |->fff_resbit: + |->fff_resi: + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TISNUM + | mov dword [BASE-8], RB + | jmp ->fff_res1 + |1: + | mov PC, [BASE-4] + | mov dword [BASE-4], 0x41e00000 // 2^31. + | mov dword [BASE-8], 0 + | jmp ->fff_res1 + |2: + | ja ->fff_fallback + |.else + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + |.endif + | + |.if SSE + | movsd xmm0, qword [BASE] + | sseconst_abs xmm1, RDa + | andps xmm0, xmm1 + |->fff_resxmm0: + | mov PC, [BASE-4] + | movsd qword [BASE-8], xmm0 + | // fallthrough + |.else + | fld qword [BASE] + | fabs + | // fallthrough + |->fff_resxmm0: // Dummy. + |->fff_resn: + | mov PC, [BASE-4] + | fstp qword [BASE-8] + |.endif + | + |->fff_res1: + | mov RD, 1+1 + |->fff_res: + | mov MULTRES, RD + |->fff_res_: + | test PC, FRAME_TYPE + | jnz >7 + |5: + | cmp PC_RB, RDL // More results expected? + | ja >6 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | movzx RA, PC_RA + | not RAa // Note: ~RA = -(RA+1) + | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 + | ins_next + | + |6: // Fill up results with nil. + | mov dword [BASE+RD*8-12], LJ_TNIL + | add RD, 1 + | jmp <5 + | + |7: // Non-standard return case. + | mov RAa, -8 // Results start at BASE+RA = BASE-8. + | jmp ->vm_return + | + |.macro math_round, func + | .ffunc math_ .. func + |.if DUALNUM + | cmp dword [BASE+4], LJ_TISNUM; jne >1 + | mov RB, dword [BASE]; jmp ->fff_resi + |1: + | ja ->fff_fallback + |.else + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE] + | call ->vm_ .. func + | .if DUALNUM + | cvtsd2si RB, xmm0 + | cmp RB, 0x80000000 + | jne ->fff_resi + | cvtsi2sd xmm1, RB + | ucomisd xmm0, xmm1 + | jp ->fff_resxmm0 + | je ->fff_resi + | .endif + | jmp ->fff_resxmm0 + |.else + | fld qword [BASE] + | call ->vm_ .. func + | .if DUALNUM + | fist ARG1 + | mov RB, ARG1 + | cmp RB, 0x80000000; jne >2 + | fdup + | fild ARG1 + | fcomparepp + | jp ->fff_resn + | jne ->fff_resn + |2: + | fpop + | jmp ->fff_resi + | .else + | jmp ->fff_resn + | .endif + |.endif + |.endmacro + | + | math_round floor + | math_round ceil + | + |.if SSE + |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0 + |.else + |.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn + |.endif + | + |.ffunc math_log + | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument. + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn + | + |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn + |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn + | + |.ffunc_n math_sin; fsin; jmp ->fff_resn + |.ffunc_n math_cos; fcos; jmp ->fff_resn + |.ffunc_n math_tan; fptan; fpop; jmp ->fff_resn + | + |.ffunc_n math_asin + | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fpatan + | jmp ->fff_resn + |.ffunc_n math_acos + | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fxch; fpatan + | jmp ->fff_resn + |.ffunc_n math_atan; fld1; fpatan; jmp ->fff_resn + | + |.macro math_extern, func + |.if SSE + | .ffunc_nsse math_ .. func + | .if not X64 + | movsd FPARG1, xmm0 + | .endif + |.else + | .ffunc_n math_ .. func + | fstp FPARG1 + |.endif + | mov RB, BASE + | call extern lj_vm_ .. func + | mov BASE, RB + | .if X64 + | jmp ->fff_resxmm0 + | .else + | jmp ->fff_resn + | .endif + |.endmacro + | + | math_extern sinh + | math_extern cosh + | math_extern tanh + | + |->ff_math_deg: + |.if SSE + |.ffunc_nsse math_rad + | mov CFUNC:RB, [BASE-8] + | mulsd xmm0, qword CFUNC:RB->upvalue[0] + | jmp ->fff_resxmm0 + |.else + |.ffunc_n math_rad + | mov CFUNC:RB, [BASE-8] + | fmul qword CFUNC:RB->upvalue[0] + | jmp ->fff_resn + |.endif + | + |.ffunc_nn math_atan2; fpatan; jmp ->fff_resn + |.ffunc_nnr math_ldexp; fscale; fpop1; jmp ->fff_resn + | + |.ffunc_1 math_frexp + | mov RB, [BASE+4] + | cmp RB, LJ_TISNUM; jae ->fff_fallback + | mov PC, [BASE-4] + | mov RC, [BASE] + | mov [BASE-4], RB; mov [BASE-8], RC + | shl RB, 1; cmp RB, 0xffe00000; jae >3 + | or RC, RB; jz >3 + | mov RC, 1022 + | cmp RB, 0x00200000; jb >4 + |1: + | shr RB, 21; sub RB, RC // Extract and unbias exponent. + |.if SSE + | cvtsi2sd xmm0, RB + |.else + | mov TMP1, RB; fild TMP1 + |.endif + | mov RB, [BASE-4] + | and RB, 0x800fffff // Mask off exponent. + | or RB, 0x3fe00000 // Put mantissa in range [0.5,1) or 0. + | mov [BASE-4], RB + |2: + |.if SSE + | movsd qword [BASE], xmm0 + |.else + | fstp qword [BASE] + |.endif + | mov RD, 1+2 + | jmp ->fff_res + |3: // Return +-0, +-Inf, NaN unmodified and an exponent of 0. + |.if SSE + | xorps xmm0, xmm0; jmp <2 + |.else + | fldz; jmp <2 + |.endif + |4: // Handle denormals by multiplying with 2^54 and adjusting the bias. + |.if SSE + | movsd xmm0, qword [BASE] + | sseconst_hi xmm1, RBa, 43500000 // 2^54. + | mulsd xmm0, xmm1 + | movsd qword [BASE-8], xmm0 + |.else + | fld qword [BASE] + | mov TMP1, 0x5a800000; fmul TMP1 // x = x*2^54 + | fstp qword [BASE-8] + |.endif + | mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1 + | + |.if SSE + |.ffunc_nsse math_modf + |.else + |.ffunc_n math_modf + |.endif + | mov RB, [BASE+4] + | mov PC, [BASE-4] + | shl RB, 1; cmp RB, 0xffe00000; je >4 // +-Inf? + |.if SSE + | movaps xmm4, xmm0 + | call ->vm_trunc + | subsd xmm4, xmm0 + |1: + | movsd qword [BASE-8], xmm0 + | movsd qword [BASE], xmm4 + |.else + | fdup + | call ->vm_trunc + | fsub st1, st0 + |1: + | fstp qword [BASE-8] + | fstp qword [BASE] + |.endif + | mov RC, [BASE-4]; mov RB, [BASE+4] + | xor RC, RB; js >3 // Need to adjust sign? + |2: + | mov RD, 1+2 + | jmp ->fff_res + |3: + | xor RB, 0x80000000; mov [BASE+4], RB // Flip sign of fraction. + | jmp <2 + |4: + |.if SSE + | xorps xmm4, xmm4; jmp <1 // Return +-Inf and +-0. + |.else + | fldz; fxch; jmp <1 // Return +-Inf and +-0. + |.endif + | + |.ffunc_nnr math_fmod + |1: ; fprem; fnstsw ax; sahf; jp <1 + | fpop1 + | jmp ->fff_resn + | + |.if SSE + |.ffunc_nnsse math_pow; call ->vm_pow; jmp ->fff_resxmm0 + |.else + |.ffunc_nn math_pow; call ->vm_pow; jmp ->fff_resn + |.endif + | + |.macro math_minmax, name, cmovop, fcmovop, sseop + | .ffunc name + | mov RA, 2 + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >4 + | mov RB, dword [BASE] + |1: // Handle integers. + | cmp RA, RD; jae ->fff_resi + | cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3 + | cmp RB, dword [BASE+RA*8-8] + | cmovop RB, dword [BASE+RA*8-8] + | add RA, 1 + | jmp <1 + |3: + | ja ->fff_fallback + | // Convert intermediate result to number and continue below. + |.if SSE + | cvtsi2sd xmm0, RB + |.else + | mov TMP1, RB + | fild TMP1 + |.endif + | jmp >6 + |4: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | + |.if SSE + | movsd xmm0, qword [BASE] + |5: // Handle numbers or integers. + | cmp RA, RD; jae ->fff_resxmm0 + | cmp dword [BASE+RA*8-4], LJ_TISNUM + |.if DUALNUM + | jb >6 + | ja ->fff_fallback + | cvtsi2sd xmm1, dword [BASE+RA*8-8] + | jmp >7 + |.else + | jae ->fff_fallback + |.endif + |6: + | movsd xmm1, qword [BASE+RA*8-8] + |7: + | sseop xmm0, xmm1 + | add RA, 1 + | jmp <5 + |.else + | fld qword [BASE] + |5: // Handle numbers or integers. + | cmp RA, RD; jae ->fff_resn + | cmp dword [BASE+RA*8-4], LJ_TISNUM + |.if DUALNUM + | jb >6 + | ja >9 + | fild dword [BASE+RA*8-8] + | jmp >7 + |.else + | jae >9 + |.endif + |6: + | fld qword [BASE+RA*8-8] + |7: + | fucomi st1; fcmovop st1; fpop1 + | add RA, 1 + | jmp <5 + |.endif + |.endmacro + | + | math_minmax math_min, cmovg, fcmovnbe, minsd + | math_minmax math_max, cmovl, fcmovbe, maxsd + |.if not SSE + |9: + | fpop; jmp ->fff_fallback + |.endif + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + |.if DUALNUM + | mov RB, dword STR:RB->len; jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, dword STR:RB->len; jmp ->fff_resxmm0 + |.else + | fild dword STR:RB->len; jmp ->fff_resn + |.endif + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmp NARGS:RD, 1+1; jne ->fff_fallback + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov PC, [BASE-4] + | cmp dword STR:RB->len, 1 + | jb ->fff_res0 // Return no results for empty string. + | movzx RB, byte STR:RB[1] + |.if DUALNUM + | jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, RB; jmp ->fff_resxmm0 + |.else + | mov TMP1, RB; fild TMP1; jmp ->fff_resn + |.endif + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmp NARGS:RD, 1+1; jne ->fff_fallback // *Exactly* 1 arg. + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + | mov RB, dword [BASE] + | cmp RB, 255; ja ->fff_fallback + | mov TMP2, RB + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RB, qword [BASE] + | cmp RB, 255; ja ->fff_fallback + | mov TMP2, RB + |.else + | jae ->fff_fallback + | fld qword [BASE] + | fistp TMP2 + | cmp TMP2, 255; ja ->fff_fallback + |.endif + |.if X64 + | mov TMP3, 1 + |.else + | mov ARG3, 1 + |.endif + | lea RDa, TMP2 // Points to stack. Little-endian. + |->fff_newstr: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + |.if X64 + | mov CARG3d, TMP3 // Zero-extended to size_t. + | mov CARG2, RDa // May be 64 bit ptr to stack. + | mov CARG1d, L:RB + |.else + | mov ARG2, RD + | mov ARG1, L:RB + |.endif + | mov SAVE_PC, PC + | call extern lj_str_new // (lua_State *L, char *str, size_t l) + | // GCstr * returned in eax (RD). + | mov BASE, L:RB->base + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RD + | jmp ->fff_res1 + | + |.ffunc string_sub + | ffgccheck + | mov TMP2, -1 + | cmp NARGS:RD, 1+2; jb ->fff_fallback + | jna >1 + | cmp dword [BASE+20], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + | mov RB, dword [BASE+16] + | mov TMP2, RB + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RB, qword [BASE+16] + | mov TMP2, RB + |.else + | jae ->fff_fallback + | fld qword [BASE+16] + | fistp TMP2 + |.endif + |1: + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | mov STR:RB, [BASE] + | mov TMP3, STR:RB + | mov RB, STR:RB->len + |.if DUALNUM + | mov RA, dword [BASE+8] + |.elif SSE + | cvttsd2si RA, qword [BASE+8] + |.else + | fld qword [BASE+8] + | fistp ARG3 + | mov RA, ARG3 + |.endif + | mov RC, TMP2 + | cmp RB, RC // len < end? (unsigned compare) + | jb >5 + |2: + | test RA, RA // start <= 0? + | jle >7 + |3: + | mov STR:RB, TMP3 + | sub RC, RA // start > end? + | jl ->fff_emptystr + | lea RB, [STR:RB+RA+#STR-1] + | add RC, 1 + |4: + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov RD, RB + | jmp ->fff_newstr + | + |5: // Negative end or overflow. + | jl >6 + | lea RC, [RC+RB+1] // end = end+(len+1) + | jmp <2 + |6: // Overflow. + | mov RC, RB // end = len + | jmp <2 + | + |7: // Negative start or underflow. + | je >8 + | add RA, RB // start = start+(len+1) + | add RA, 1 + | jg <3 // start > 0? + |8: // Underflow. + | mov RA, 1 // start = 1 + | jmp <3 + | + |->fff_emptystr: // Range underflow. + | xor RC, RC // Zero length. Any ptr in RB is ok. + | jmp <4 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmp NARGS:RD, 2+1; jne ->fff_fallback // Exactly 2 arguments. + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + | mov STR:RB, [BASE] + |.if DUALNUM + | jne ->fff_fallback + | mov RC, dword [BASE+8] + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RC, qword [BASE+8] + |.else + | jae ->fff_fallback + | fld qword [BASE+8] + | fistp TMP2 + | mov RC, TMP2 + |.endif + | test RC, RC + | jle ->fff_emptystr // Count <= 0? (or non-int) + | cmp dword STR:RB->len, 1 + | jb ->fff_emptystr // Zero length string? + | jne ->fff_fallback_2 // Fallback for > 1-char strings. + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_2 + | movzx RA, byte STR:RB[1] + | mov RB, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | mov [RB], RAL + | add RB, 1 + | sub RC, 1 + | jnz <1 + | mov RD, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + | jmp ->fff_newstr + | + |.ffunc_1 string_reverse + | ffgccheck + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov RC, STR:RB->len + | test RC, RC + | jz ->fff_emptystr // Zero length string? + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1 + | add RB, #STR + | mov TMP2, PC // Need another temp register. + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + |1: + | movzx RA, byte [RB] + | add RB, 1 + | sub RC, 1 + | mov [PC+RC], RAL + | jnz <1 + | mov RD, PC + | mov PC, TMP2 + | jmp ->fff_newstr + | + |.macro ffstring_case, name, lo, hi + | .ffunc_1 name + | ffgccheck + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov RC, STR:RB->len + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1 + | add RB, #STR + | mov TMP2, PC // Need another temp register. + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + | jmp >3 + |1: // ASCII case conversion. Yes, this is suboptimal code (do you care?). + | movzx RA, byte [RB+RC] + | cmp RA, lo + | jb >2 + | cmp RA, hi + | ja >2 + | xor RA, 0x20 + |2: + | mov [PC+RC], RAL + |3: + | sub RC, 1 + | jns <1 + | mov RD, PC + | mov PC, TMP2 + | jmp ->fff_newstr + |.endmacro + | + |ffstring_case string_lower, 0x41, 0x5a + |ffstring_case string_upper, 0x61, 0x7a + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | mov RB, BASE // Save BASE. + | mov TAB:FCARG1, [BASE] + | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t) + | // Length of table returned in eax (RD). + | mov BASE, RB // Restore BASE. + |.if DUALNUM + | mov RB, RD; jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0 + |.else + | mov ARG1, RD; fild ARG1; jmp ->fff_resn + |.endif + | + |//-- Bit library -------------------------------------------------------- + | + |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!). + | + |.macro .ffunc_bit, name, kind + | .ffunc_1 name + |.if kind == 2 + |.if SSE + | sseconst_tobit xmm1, RBa + |.else + | mov TMP1, TOBIT_BIAS + |.endif + |.endif + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >1 + | mov RB, dword [BASE] + |.if kind > 0 + | jmp >2 + |.else + | jmp ->fff_resbit + |.endif + |1: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE] + |.if kind < 2 + | sseconst_tobit xmm1, RBa + |.endif + | addsd xmm0, xmm1 + | movd RB, xmm0 + |.else + | fld qword [BASE] + |.if kind < 2 + | mov TMP1, TOBIT_BIAS + |.endif + | fadd TMP1 + | fstp FPARG1 + |.if kind > 0 + | mov RB, ARG1 + |.endif + |.endif + |2: + |.endmacro + | + |.ffunc_bit bit_tobit, 0 + |.if DUALNUM or SSE + |.if not SSE + | mov RB, ARG1 + |.endif + | jmp ->fff_resbit + |.else + | fild ARG1 + | jmp ->fff_resn + |.endif + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name, 2 + | mov TMP2, NARGS:RD // Save for fallback. + | lea RD, [BASE+NARGS:RD*8-16] + |1: + | cmp RD, BASE + | jbe ->fff_resbit + | cmp dword [RD+4], LJ_TISNUM + |.if DUALNUM + | jne >2 + | ins RB, dword [RD] + | sub RD, 8 + | jmp <1 + |2: + | ja ->fff_fallback_bit_op + |.else + | jae ->fff_fallback_bit_op + |.endif + |.if SSE + | movsd xmm0, qword [RD] + | addsd xmm0, xmm1 + | movd RA, xmm0 + | ins RB, RA + |.else + | fld qword [RD] + | fadd TMP1 + | fstp FPARG1 + | ins RB, ARG1 + |.endif + | sub RD, 8 + | jmp <1 + |.endmacro + | + |.ffunc_bit_op bit_band, and + |.ffunc_bit_op bit_bor, or + |.ffunc_bit_op bit_bxor, xor + | + |.ffunc_bit bit_bswap, 1 + | bswap RB + | jmp ->fff_resbit + | + |.ffunc_bit bit_bnot, 1 + | not RB + |.if DUALNUM + | jmp ->fff_resbit + |.elif SSE + |->fff_resbit: + | cvtsi2sd xmm0, RB + | jmp ->fff_resxmm0 + |.else + |->fff_resbit: + | mov ARG1, RB + | fild ARG1 + | jmp ->fff_resn + |.endif + | + |->fff_fallback_bit_op: + | mov NARGS:RD, TMP2 // Restore for fallback + | jmp ->fff_fallback + | + |.macro .ffunc_bit_sh, name, ins + |.if DUALNUM + | .ffunc_bit name, 1 + | // Note: no inline conversion from number for 2nd argument! + | cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback + | mov RA, dword [BASE+8] + |.elif SSE + | .ffunc_nnsse name + | sseconst_tobit xmm2, RBa + | addsd xmm0, xmm2 + | addsd xmm1, xmm2 + | movd RB, xmm0 + | movd RA, xmm1 + |.else + | .ffunc_nn name + | mov TMP1, TOBIT_BIAS + | fadd TMP1 + | fstp FPARG3 + | fadd TMP1 + | fstp FPARG1 + | mov RA, ARG3 + | mov RB, ARG1 + |.endif + | ins RB, cl // Assumes RA is ecx. + | jmp ->fff_resbit + |.endmacro + | + |.ffunc_bit_sh bit_lshift, shl + |.ffunc_bit_sh bit_rshift, shr + |.ffunc_bit_sh bit_arshift, sar + |.ffunc_bit_sh bit_rol, rol + |.ffunc_bit_sh bit_ror, ror + | + |//----------------------------------------------------------------------- + | + |->fff_fallback_2: + | mov NARGS:RD, 1+2 // Other args are ignored, anyway. + | jmp ->fff_fallback + |->fff_fallback_1: + | mov NARGS:RD, 1+1 // Other args are ignored, anyway. + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RD = nargs+1 + | mov L:RB, SAVE_L + | mov PC, [BASE-4] // Fallback may overwrite PC. + | mov SAVE_PC, PC // Redundant (but a defined value). + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | lea RA, [RD+8*LUA_MINSTACK] // Ensure enough space for handler. + | mov L:RB->top, RD + | mov CFUNC:RD, [BASE-8] + | cmp RA, L:RB->maxstack + | ja >5 // Need to grow stack. + |.if X64 + | mov CARG1d, L:RB + |.else + | mov ARG1, L:RB + |.endif + | call aword CFUNC:RD->f // (lua_State *L) + | mov BASE, L:RB->base + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | test RD, RD; jg ->fff_res // Returned nresults+1? + |1: + | mov RA, L:RB->top + | sub RA, BASE + | shr RA, 3 + | test RD, RD + | lea NARGS:RD, [RA+1] + | mov LFUNC:RB, [BASE-8] + | jne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | mov RA, BASE + | test PC, FRAME_TYPE + | jnz >3 + | movzx RB, PC_RA + | not RBa // Note: ~RB = -(RB+1) + | lea BASE, [BASE+RB*8] // base = base - (RB+1)*8 + | jmp ->vm_call_dispatch // Resolve again for tailcall. + |3: + | mov RB, PC + | and RB, -8 + | sub BASE, RB + | jmp ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | mov FCARG2, LUA_MINSTACK + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | xor RD, RD // Simulate a return 0. + | jmp <1 // Dumb retry (goes through ff first). + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RD = nargs+1 + | pop RBa // Must keep stack at same level. + | mov TMPa, RBa // Save return address + | mov L:RB, SAVE_L + | mov SAVE_PC, PC // Redundant (but a defined value). + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | mov FCARG1, L:RB + | mov L:RB->top, RD + | call extern lj_gc_step@4 // (lua_State *L) + | mov BASE, L:RB->base + | mov RD, L:RB->top + | sub RD, BASE + | shr RD, 3 + | add NARGS:RD, 1 + | mov RBa, TMPa + | push RBa // Restore return address. + | ret + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_VMEVENT // No recording while in vmevent. + | jnz >5 + | // Decrement the hookcount for consistency, but always do the call. + | test RDL, HOOK_ACTIVE + | jnz >1 + | test RDL, LUA_MASKLINE|LUA_MASKCOUNT + | jz >1 + | dec dword [DISPATCH+DISPATCH_GL(hookcount)] + | jmp >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_ACTIVE // Hook already active? + | jnz >5 + | jmp >1 + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_ACTIVE // Hook already active? + | jnz >5 + | + | test RDL, LUA_MASKLINE|LUA_MASKCOUNT + | jz >5 + | dec dword [DISPATCH+DISPATCH_GL(hookcount)] + | jz >1 + | test RDL, LUA_MASKLINE + | jz >5 + |1: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG2, PC // Caveat: FCARG2 == BASE + | mov FCARG1, L:RB + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | call extern lj_dispatch_ins@8 // (lua_State *L, BCIns *pc) + |3: + | mov BASE, L:RB->base + |4: + | movzx RA, PC_RA + |5: + | movzx OP, PC_OP + | movzx RD, PC_RD + |.if X64 + | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins. + |.else + | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Re-dispatch to static ins. + |.endif + | + |->cont_hook: // Continue from hook yield. + | add PC, 4 + | mov RA, [RB-24] + | mov MULTRES, RA // Restore MULTRES for *M ins. + | jmp <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | mov LFUNC:RB, [BASE-8] // Same as curr_topL(L). + | mov RB, LFUNC:RB->pc + | movzx RD, byte [RB+PC2PROTO(framesize)] + | lea RD, [BASE+RD*8] + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov FCARG2, PC + | lea FCARG1, [DISPATCH+GG_DISP2J] + | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa + | mov SAVE_PC, PC + | call extern lj_trace_hot@8 // (jit_State *J, const BCIns *pc) + | jmp <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mov SAVE_PC, PC + |.if JIT + | jmp >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | mov SAVE_PC, PC + | or PC, 1 // Marker for hot call. + |1: + |.endif + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov FCARG2, PC + | mov FCARG1, L:RB + | call extern lj_dispatch_call@8 // (lua_State *L, const BCIns *pc) + | // ASMFunction returned in eax/rax (RDa). + | mov SAVE_PC, 0 // Invalidate for subsequent line hook. + |.if JIT + | and PC, -2 + |.endif + | mov BASE, L:RB->base + | mov RAa, RDa + | mov RD, L:RB->top + | sub RD, BASE + | mov RBa, RAa + | movzx RA, PC_RA + | shr RD, 3 + | add NARGS:RD, 1 + | jmp RBa + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Called from an exit stub with the exit number on the stack. + |// The 16 bit exit number is stored with two (sign-extended) push imm8. + |->vm_exit_handler: + |.if JIT + |.if X64 + | push r13; push r12 + | push r11; push r10; push r9; push r8 + | push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp + | push rbx; push rdx; push rcx; push rax + | movzx RC, byte [rbp-8] // Reconstruct exit number. + | mov RCH, byte [rbp-16] + | mov [rbp-8], r15; mov [rbp-16], r14 + |.else + | push ebp; lea ebp, [esp+12]; push ebp + | push ebx; push edx; push ecx; push eax + | movzx RC, byte [ebp-4] // Reconstruct exit number. + | mov RCH, byte [ebp-8] + | mov [ebp-4], edi; mov [ebp-8], esi + |.endif + | // Caveat: DISPATCH is ebx. + | mov DISPATCH, [ebp] + | mov RA, [DISPATCH+DISPATCH_GL(vmstate)] // Get trace number. + | set_vmstate EXIT + | mov [DISPATCH+DISPATCH_J(exitno)], RC + | mov [DISPATCH+DISPATCH_J(parent)], RA + |.if X64 + |.if X64WIN + | sub rsp, 16*8+4*8 // Room for SSE regs + save area. + |.else + | sub rsp, 16*8 // Room for SSE regs. + |.endif + | add rbp, -128 + | movsd qword [rbp-8], xmm15; movsd qword [rbp-16], xmm14 + | movsd qword [rbp-24], xmm13; movsd qword [rbp-32], xmm12 + | movsd qword [rbp-40], xmm11; movsd qword [rbp-48], xmm10 + | movsd qword [rbp-56], xmm9; movsd qword [rbp-64], xmm8 + | movsd qword [rbp-72], xmm7; movsd qword [rbp-80], xmm6 + | movsd qword [rbp-88], xmm5; movsd qword [rbp-96], xmm4 + | movsd qword [rbp-104], xmm3; movsd qword [rbp-112], xmm2 + | movsd qword [rbp-120], xmm1; movsd qword [rbp-128], xmm0 + |.else + | sub esp, 8*8+16 // Room for SSE regs + args. + | movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6 + | movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4 + | movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2 + | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0 + |.endif + | // Caveat: RB is ebp. + | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)] + | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)] + | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa + | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 + | mov L:RB->base, BASE + |.if X64WIN + | lea CARG2, [rsp+4*8] + |.elif X64 + | mov CARG2, rsp + |.else + | lea FCARG2, [esp+16] + |.endif + | lea FCARG1, [DISPATCH+GG_DISP2J] + | call extern lj_trace_exit@8 // (jit_State *J, ExitState *ex) + | // MULTRES or negated error code returned in eax (RD). + | mov RAa, L:RB->cframe + | and RAa, CFRAME_RAWMASK + |.if X64WIN + | // Reposition stack later. + |.elif X64 + | mov rsp, RAa // Reposition stack to C frame. + |.else + | mov esp, RAa // Reposition stack to C frame. + |.endif + | mov [RAa+CFRAME_OFS_L], L:RB // Set SAVE_L (on-trace resume/yield). + | mov BASE, L:RB->base + | mov PC, [RAa+CFRAME_OFS_PC] // Get SAVE_PC. + |.if X64 + | jmp >1 + |.endif + |.endif + |->vm_exit_interp: + | // RD = MULTRES or negated error code, BASE, PC and DISPATCH set. + |.if JIT + |.if X64 + | // Restore additional callee-save registers only used in compiled code. + |.if X64WIN + | lea RAa, [rsp+9*16+4*8] + |1: + | movdqa xmm15, [RAa-9*16] + | movdqa xmm14, [RAa-8*16] + | movdqa xmm13, [RAa-7*16] + | movdqa xmm12, [RAa-6*16] + | movdqa xmm11, [RAa-5*16] + | movdqa xmm10, [RAa-4*16] + | movdqa xmm9, [RAa-3*16] + | movdqa xmm8, [RAa-2*16] + | movdqa xmm7, [RAa-1*16] + | mov rsp, RAa // Reposition stack to C frame. + | movdqa xmm6, [RAa] + | mov r15, CSAVE_3 + | mov r14, CSAVE_4 + |.else + | add rsp, 16 // Reposition stack to C frame. + |1: + |.endif + | mov r13, TMPa + | mov r12, TMPQ + |.endif + | test RD, RD; js >3 // Check for error from exit. + | mov MULTRES, RD + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 + | set_vmstate INTERP + | // Modified copy of ins_next which handles function header dispatch, too. + | mov RC, [PC] + | movzx RA, RCH + | movzx OP, RCL + | add PC, 4 + | shr RC, 16 + | cmp OP, BC_FUNCF // Function header? + | jb >2 + | mov RC, MULTRES // RC/RD holds nres+1. + |2: + |.if X64 + | jmp aword [DISPATCH+OP*8] + |.else + | jmp aword [DISPATCH+OP*4] + |.endif + | + |3: // Rethrow error from the right C frame. + | neg RD + | mov FCARG1, L:RB + | mov FCARG2, RD + | call extern lj_err_throw@8 // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called by math.floor/math.ceil fast functions + |// and from JIT code. + | + |// x87 variant: Arg/ret on x87 stack. No int/xmm registers modified. + |.macro vm_round_x87, mode1, mode2 + | fnstcw word [esp+4] // Caveat: overwrites ARG1 and ARG2. + | mov [esp+8], eax + | mov ax, mode1 + | or ax, [esp+4] + |.if mode2 ~= 0xffff + | and ax, mode2 + |.endif + | mov [esp+6], ax + | fldcw word [esp+6] + | frndint + | fldcw word [esp+4] + | mov eax, [esp+8] + | ret + |.endmacro + | + |// SSE variant: arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified. + |.macro vm_round_sse, mode + | sseconst_abs xmm2, RDa + | sseconst_2p52 xmm3, RDa + | movaps xmm1, xmm0 + | andpd xmm1, xmm2 // |x| + | ucomisd xmm3, xmm1 // No truncation if 2^52 <= |x|. + | jbe >1 + | andnpd xmm2, xmm0 // Isolate sign bit. + |.if mode == 2 // trunc(x)? + | movaps xmm0, xmm1 + | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52 + | subsd xmm1, xmm3 + | sseconst_1 xmm3, RDa + | cmpsd xmm0, xmm1, 1 // |x| < result? + | andpd xmm0, xmm3 + | subsd xmm1, xmm0 // If yes, subtract -1. + | orpd xmm1, xmm2 // Merge sign bit back in. + |.else + | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52 + | subsd xmm1, xmm3 + | orpd xmm1, xmm2 // Merge sign bit back in. + | .if mode == 1 // ceil(x)? + | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0. + | cmpsd xmm0, xmm1, 6 // x > result? + | .else // floor(x)? + | sseconst_1 xmm2, RDa + | cmpsd xmm0, xmm1, 1 // x < result? + | .endif + | andpd xmm0, xmm2 + | subsd xmm1, xmm0 // If yes, subtract +-1. + |.endif + | movaps xmm0, xmm1 + |1: + | ret + |.endmacro + | + |.macro vm_round, name, ssemode, mode1, mode2 + |->name: + |.if not SSE + | vm_round_x87 mode1, mode2 + |.endif + |->name .. _sse: + | vm_round_sse ssemode + |.endmacro + | + | vm_round vm_floor, 0, 0x0400, 0xf7ff + | vm_round vm_ceil, 1, 0x0800, 0xfbff + | vm_round vm_trunc, 2, 0x0c00, 0xffff + | + |// FP modulo x%y. Called by BC_MOD* and vm_arith. + |->vm_mod: + |.if SSE + |// Args in xmm0/xmm1, return value in xmm0. + |// Caveat: xmm0-xmm5 and RC (eax) modified! + | movaps xmm5, xmm0 + | divsd xmm0, xmm1 + | sseconst_abs xmm2, RDa + | sseconst_2p52 xmm3, RDa + | movaps xmm4, xmm0 + | andpd xmm4, xmm2 // |x/y| + | ucomisd xmm3, xmm4 // No truncation if 2^52 <= |x/y|. + | jbe >1 + | andnpd xmm2, xmm0 // Isolate sign bit. + | addsd xmm4, xmm3 // (|x/y| + 2^52) - 2^52 + | subsd xmm4, xmm3 + | orpd xmm4, xmm2 // Merge sign bit back in. + | sseconst_1 xmm2, RDa + | cmpsd xmm0, xmm4, 1 // x/y < result? + | andpd xmm0, xmm2 + | subsd xmm4, xmm0 // If yes, subtract 1.0. + | movaps xmm0, xmm5 + | mulsd xmm1, xmm4 + | subsd xmm0, xmm1 + | ret + |1: + | mulsd xmm1, xmm0 + | movaps xmm0, xmm5 + | subsd xmm0, xmm1 + | ret + |.else + |// Args/ret on x87 stack (y on top). No xmm registers modified. + |// Caveat: needs 3 slots on x87 stack! RC (eax) modified! + | fld st1 + | fdiv st1 + | fnstcw word [esp+4] + | mov ax, 0x0400 + | or ax, [esp+4] + | and ax, 0xf7ff + | mov [esp+6], ax + | fldcw word [esp+6] + | frndint + | fldcw word [esp+4] + | fmulp st1 + | fsubp st1 + | ret + |.endif + | + |// FP log2(x). Called by math.log(x, base). + |->vm_log2: + |.if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | fld1 + | fld qword [rsp+8] + | fyl2x + | fstp qword [rsp+8] + | movsd xmm0, qword [rsp+8] + |.elif X64 + | movsd qword [rsp-8], xmm0 // Use red zone. + | fld1 + | fld qword [rsp-8] + | fyl2x + | fstp qword [rsp-8] + | movsd xmm0, qword [rsp-8] + |.else + | fld1 + | fld qword [esp+4] + | fyl2x + |.endif + | ret + | + |// FP exponentiation e^x and 2^x. Called by math.exp fast function and + |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified. + |// Caveat: needs 3 slots on x87 stack! + |->vm_exp_x87: + | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e)) + |->vm_exp2_x87: + | .if X64WIN + | .define expscratch, dword [rsp+8] // Use scratch area. + | .elif X64 + | .define expscratch, dword [rsp-8] // Use red zone. + | .else + | .define expscratch, dword [esp+4] // Needs 4 byte scratch area. + | .endif + | fst expscratch // Caveat: overwrites ARG1. + | cmp expscratch, 0x7f800000; je >1 // Special case: e^+Inf = +Inf + | cmp expscratch, 0xff800000; je >2 // Special case: e^-Inf = 0 + |->vm_exp2raw: // Entry point for vm_pow. Without +-Inf check. + | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part. + | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int + |1: + | ret + |2: + | fpop; fldz; ret + | + |// Generic power function x^y. Called by BC_POW, math.pow fast function, + |// and vm_arith. + |// Args/ret on x87 stack (y on top). RC (eax) modified. + |// Caveat: needs 3 slots on x87 stack! + |->vm_pow: + |.if not SSE + | fist dword [esp+4] // Store/reload int before comparison. + | fild dword [esp+4] // Integral exponent used in vm_powi. + | fucomip st1 + | jnz >8 // Branch for FP exponents. + | jp >9 // Branch for NaN exponent. + | fpop // Pop y and fallthrough to vm_powi. + | + |// FP/int power function x^i. Arg1/ret on x87 stack. + |// Arg2 (int) on C stack. RC (eax) modified. + |// Caveat: needs 2 slots on x87 stack! + | mov eax, [esp+4] + | cmp eax, 1; jle >6 // i<=1? + | // Now 1 < (unsigned)i <= 0x80000000. + |1: // Handle leading zeros. + | test eax, 1; jnz >2 + | fmul st0 + | shr eax, 1 + | jmp <1 + |2: + | shr eax, 1; jz >5 + | fdup + |3: // Handle trailing bits. + | fmul st0 + | shr eax, 1; jz >4 + | jnc <3 + | fmul st1, st0 + | jmp <3 + |4: + | fmulp st1 + |5: + | ret + |6: + | je <5 // x^1 ==> x + | jb >7 + | fld1; fdivrp st1 + | neg eax + | cmp eax, 1; je <5 // x^-1 ==> 1/x + | jmp <1 // x^-i ==> (1/x)^i + |7: + | fpop; fld1 // x^0 ==> 1 + | ret + | + |8: // FP/FP power function x^y. + | fst dword [esp+4] + | fxch + | fst dword [esp+8] + | mov eax, [esp+4]; shl eax, 1 + | cmp eax, 0xff000000; je >2 // x^+-Inf? + | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y? + | cmp eax, 0xff000000; je >4 // +-Inf^y? + | fyl2x + | jmp ->vm_exp2raw + | + |9: // Handle x^NaN. + | fld1 + | fucomip st2 + | je >1 // 1^NaN ==> 1 + | fxch // x^NaN ==> NaN + |1: + | fpop + | ret + | + |2: // Handle x^+-Inf. + | fabs + | fld1 + | fucomip st1 + | je >3 // +-1^+-Inf ==> 1 + | fpop; fabs; fldz; mov eax, 0; setc al + | ror eax, 1; xor eax, [esp+4]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0 + | fxch + |3: + | fpop1; fabs + | ret + | + |4: // Handle +-0^y or +-Inf^y. + | cmp dword [esp+4], 0; jge <3 // y >= 0, x^y ==> |x| + | fpop; fpop + | test eax, eax; jz >5 // y < 0, +-0^y ==> +Inf + | fldz // y < 0, +-Inf^y ==> 0 + | ret + |5: + | mov dword [esp+4], 0x7f800000 // Return +Inf. + | fld dword [esp+4] + | ret + |.endif + | + |// Args in xmm0/xmm1. Ret in xmm0. xmm0-xmm2 and RC (eax) modified. + |// Needs 16 byte scratch area for x86. Also called from JIT code. + |->vm_pow_sse: + | cvtsd2si eax, xmm1 + | cvtsi2sd xmm2, eax + | ucomisd xmm1, xmm2 + | jnz >8 // Branch for FP exponents. + | jp >9 // Branch for NaN exponent. + | // Fallthrough to vm_powi_sse. + | + |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified. + |->vm_powi_sse: + | cmp eax, 1; jle >6 // i<=1? + | // Now 1 < (unsigned)i <= 0x80000000. + |1: // Handle leading zeros. + | test eax, 1; jnz >2 + | mulsd xmm0, xmm0 + | shr eax, 1 + | jmp <1 + |2: + | shr eax, 1; jz >5 + | movaps xmm1, xmm0 + |3: // Handle trailing bits. + | mulsd xmm0, xmm0 + | shr eax, 1; jz >4 + | jnc <3 + | mulsd xmm1, xmm0 + | jmp <3 + |4: + | mulsd xmm0, xmm1 + |5: + | ret + |6: + | je <5 // x^1 ==> x + | jb >7 // x^0 ==> 1 + | neg eax + | call <1 + | sseconst_1 xmm1, RDa + | divsd xmm1, xmm0 + | movaps xmm0, xmm1 + | ret + |7: + | sseconst_1 xmm0, RDa + | ret + | + |8: // FP/FP power function x^y. + |.if X64 + | movd rax, xmm1; shl rax, 1 + | rol rax, 12; cmp rax, 0xffe; je >2 // x^+-Inf? + | movd rax, xmm0; shl rax, 1; je >4 // +-0^y? + | rol rax, 12; cmp rax, 0xffe; je >5 // +-Inf^y? + | .if X64WIN + | movsd qword [rsp+16], xmm1 // Use scratch area. + | movsd qword [rsp+8], xmm0 + | fld qword [rsp+16] + | fld qword [rsp+8] + | .else + | movsd qword [rsp-16], xmm1 // Use red zone. + | movsd qword [rsp-8], xmm0 + | fld qword [rsp-16] + | fld qword [rsp-8] + | .endif + |.else + | movsd qword [esp+12], xmm1 // Needs 16 byte scratch area. + | movsd qword [esp+4], xmm0 + | cmp dword [esp+12], 0; jne >1 + | mov eax, [esp+16]; shl eax, 1 + | cmp eax, 0xffe00000; je >2 // x^+-Inf? + |1: + | cmp dword [esp+4], 0; jne >1 + | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y? + | cmp eax, 0xffe00000; je >5 // +-Inf^y? + |1: + | fld qword [esp+12] + | fld qword [esp+4] + |.endif + | fyl2x // y*log2(x) + | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part. + | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int + |.if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + |.elif X64 + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + |.else + | fstp qword [esp+4] // Needs 8 byte scratch area. + | movsd xmm0, qword [esp+4] + |.endif + | ret + | + |9: // Handle x^NaN. + | sseconst_1 xmm2, RDa + | ucomisd xmm0, xmm2; je >1 // 1^NaN ==> 1 + | movaps xmm0, xmm1 // x^NaN ==> NaN + |1: + | ret + | + |2: // Handle x^+-Inf. + | sseconst_abs xmm2, RDa + | andpd xmm0, xmm2 // |x| + | sseconst_1 xmm2, RDa + | ucomisd xmm0, xmm2; je <1 // +-1^+-Inf ==> 1 + | movmskpd eax, xmm1 + | xorps xmm0, xmm0 + | mov ah, al; setc al; xor al, ah; jne <1 // |x|<>1, x^+-Inf ==> +Inf/0 + |3: + | sseconst_hi xmm0, RDa, 7ff00000 // +Inf + | ret + | + |4: // Handle +-0^y. + | movmskpd eax, xmm1; test eax, eax; jnz <3 // y < 0, +-0^y ==> +Inf + | xorps xmm0, xmm0 // y >= 0, +-0^y ==> 0 + | ret + | + |5: // Handle +-Inf^y. + | movmskpd eax, xmm1; test eax, eax; jz <3 // y >= 0, +-Inf^y ==> +Inf + | xorps xmm0, xmm0 // y < 0, +-Inf^y ==> 0 + | ret + | + |// Callable from C: double lj_vm_foldfpm(double x, int fpm) + |// Computes fpm(x) for extended math functions. ORDER FPM. + |->vm_foldfpm: + |.if JIT + |.if X64 + | .if X64WIN + | .define fpmop, CARG2d + | .else + | .define fpmop, CARG1d + | .endif + | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil + | cmp fpmop, 3; jb ->vm_trunc; ja >2 + | sqrtsd xmm0, xmm0; ret + |2: + | .if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | fld qword [rsp+8] + | .else + | movsd qword [rsp-8], xmm0 // Use red zone. + | fld qword [rsp-8] + | .endif + | cmp fpmop, 5; ja >2 + | .if X64WIN; pop rax; .endif + | je >1 + | call ->vm_exp_x87 + | .if X64WIN; push rax; .endif + | jmp >7 + |1: + | call ->vm_exp2_x87 + | .if X64WIN; push rax; .endif + | jmp >7 + |2: ; cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; jmp >7 + |1: ; fld1; fxch; fyl2x; jmp >7 + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; jmp >7 + |1: ; fsin; jmp >7 + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; jmp >7 + |1: ; fptan; fpop + |7: + | .if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + | .else + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + | .endif + | ret + |.else // x86 calling convention. + | .define fpmop, eax + |.if SSE + | mov fpmop, [esp+12] + | movsd xmm0, qword [esp+4] + | cmp fpmop, 1; je >1; ja >2 + | call ->vm_floor; jmp >7 + |1: ; call ->vm_ceil; jmp >7 + |2: ; cmp fpmop, 3; je >1; ja >2 + | call ->vm_trunc; jmp >7 + |1: + | sqrtsd xmm0, xmm0 + |7: + | movsd qword [esp+4], xmm0 // Overwrite callee-owned args. + | fld qword [esp+4] + | ret + |2: ; fld qword [esp+4] + | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 + |2: ; cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; ret + |1: ; fld1; fxch; fyl2x; ret + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; ret + |1: ; fsin; ret + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; ret + |1: ; fptan; fpop; ret + |.else + | mov fpmop, [esp+12] + | fld qword [esp+4] + | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil + | cmp fpmop, 3; jb ->vm_trunc; ja >2 + | fsqrt; ret + |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 + | cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; ret + |1: ; fld1; fxch; fyl2x; ret + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; ret + |1: ; fsin; ret + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; ret + |1: ; fptan; fpop; ret + |.endif + |.endif + |9: ; int3 // Bad fpm. + |.endif + | + |// Callable from C: double lj_vm_foldarith(double x, double y, int op) + |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -) + |// and basic math functions. ORDER ARITH + |->vm_foldarith: + |.if X64 + | + | .if X64WIN + | .define foldop, CARG3d + | .else + | .define foldop, CARG1d + | .endif + | cmp foldop, 1; je >1; ja >2 + | addsd xmm0, xmm1; ret + |1: ; subsd xmm0, xmm1; ret + |2: ; cmp foldop, 3; je >1; ja >2 + | mulsd xmm0, xmm1; ret + |1: ; divsd xmm0, xmm1; ret + |2: ; cmp foldop, 5; jb ->vm_mod; je ->vm_pow + | cmp foldop, 7; je >1; ja >2 + | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; ret + |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; ret + |2: ; cmp foldop, 9; ja >2 + |.if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | movsd qword [rsp+16], xmm1 + | fld qword [rsp+8] + | fld qword [rsp+16] + |.else + | movsd qword [rsp-8], xmm0 // Use red zone. + | movsd qword [rsp-16], xmm1 + | fld qword [rsp-8] + | fld qword [rsp-16] + |.endif + | je >1 + | fpatan + |7: + |.if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + |.else + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + |.endif + | ret + |1: ; fxch; fscale; fpop1; jmp <7 + |2: ; cmp foldop, 11; je >1; ja >9 + | minsd xmm0, xmm1; ret + |1: ; maxsd xmm0, xmm1; ret + |9: ; int3 // Bad op. + | + |.elif SSE // x86 calling convention with SSE ops. + | + | .define foldop, eax + | mov foldop, [esp+20] + | movsd xmm0, qword [esp+4] + | movsd xmm1, qword [esp+12] + | cmp foldop, 1; je >1; ja >2 + | addsd xmm0, xmm1 + |7: + | movsd qword [esp+4], xmm0 // Overwrite callee-owned args. + | fld qword [esp+4] + | ret + |1: ; subsd xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 3; je >1; ja >2 + | mulsd xmm0, xmm1; jmp <7 + |1: ; divsd xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 5 + | je >1; ja >2 + | call ->vm_mod; jmp <7 + |1: ; pop edx; call ->vm_pow; push edx; jmp <7 // Writes to scratch area. + |2: ; cmp foldop, 7; je >1; ja >2 + | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; jmp <7 + |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 9; ja >2 + | fld qword [esp+4] // Reload from stack + | fld qword [esp+12] + | je >1 + | fpatan; ret + |1: ; fxch; fscale; fpop1; ret + |2: ; cmp foldop, 11; je >1; ja >9 + | minsd xmm0, xmm1; jmp <7 + |1: ; maxsd xmm0, xmm1; jmp <7 + |9: ; int3 // Bad op. + | + |.else // x86 calling convention with x87 ops. + | + | mov eax, [esp+20] + | fld qword [esp+4] + | fld qword [esp+12] + | cmp eax, 1; je >1; ja >2 + | faddp st1; ret + |1: ; fsubp st1; ret + |2: ; cmp eax, 3; je >1; ja >2 + | fmulp st1; ret + |1: ; fdivp st1; ret + |2: ; cmp eax, 5; jb ->vm_mod; je ->vm_pow + | cmp eax, 7; je >1; ja >2 + | fpop; fchs; ret + |1: ; fpop; fabs; ret + |2: ; cmp eax, 9; je >1; ja >2 + | fpatan; ret + |1: ; fxch; fscale; fpop1; ret + |2: ; cmp eax, 11; je >1; ja >9 + | fucomi st1; fcmovnbe st1; fpop1; ret + |1: ; fucomi st1; fcmovbe st1; fpop1; ret + |9: ; int3 // Bad op. + | + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |// int lj_vm_cpuid(uint32_t f, uint32_t res[4]) + |->vm_cpuid: + |.if X64 + | mov eax, CARG1d + | .if X64WIN; push rsi; mov rsi, CARG2; .endif + | push rbx + | cpuid + | mov [rsi], eax + | mov [rsi+4], ebx + | mov [rsi+8], ecx + | mov [rsi+12], edx + | pop rbx + | .if X64WIN; pop rsi; .endif + | ret + |.else + | pushfd + | pop edx + | mov ecx, edx + | xor edx, 0x00200000 // Toggle ID bit in flags. + | push edx + | popfd + | pushfd + | pop edx + | xor eax, eax // Zero means no features supported. + | cmp ecx, edx + | jz >1 // No ID toggle means no CPUID support. + | mov eax, [esp+4] // Argument 1 is function number. + | push edi + | push ebx + | cpuid + | mov edi, [esp+16] // Argument 2 is result area. + | mov [edi], eax + | mov [edi+4], ebx + | mov [edi+8], ecx + | mov [edi+12], edx + | pop ebx + | pop edi + |1: + | ret + |.endif + | + |//----------------------------------------------------------------------- + |//-- Assertions --------------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->assert_bad_for_arg_type: +#ifdef LUA_USE_ASSERT + | int3 +#endif + | int3 + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in ah/al. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + |.if not X64 + | sub esp, 16 // Leave room for SAVE_ERRF etc. + |.endif + | saveregs_ // ebp/rbp already saved. ebp now holds global_State *. + | lea DISPATCH, [ebp+GG_G2DISP] + | mov CTSTATE, GL:ebp->ctype_state + | movzx eax, ax + | mov CTSTATE->cb.slot, eax + |.if X64 + | mov CTSTATE->cb.gpr[0], CARG1 + | mov CTSTATE->cb.gpr[1], CARG2 + | mov CTSTATE->cb.gpr[2], CARG3 + | mov CTSTATE->cb.gpr[3], CARG4 + | movsd qword CTSTATE->cb.fpr[0], xmm0 + | movsd qword CTSTATE->cb.fpr[1], xmm1 + | movsd qword CTSTATE->cb.fpr[2], xmm2 + | movsd qword CTSTATE->cb.fpr[3], xmm3 + |.if X64WIN + | lea rax, [rsp+CFRAME_SIZE+4*8] + |.else + | lea rax, [rsp+CFRAME_SIZE] + | mov CTSTATE->cb.gpr[4], CARG5 + | mov CTSTATE->cb.gpr[5], CARG6 + | movsd qword CTSTATE->cb.fpr[4], xmm4 + | movsd qword CTSTATE->cb.fpr[5], xmm5 + | movsd qword CTSTATE->cb.fpr[6], xmm6 + | movsd qword CTSTATE->cb.fpr[7], xmm7 + |.endif + | mov CTSTATE->cb.stack, rax + | mov CARG2, rsp + |.else + | lea eax, [esp+CFRAME_SIZE+16] + | mov CTSTATE->cb.gpr[0], FCARG1 + | mov CTSTATE->cb.gpr[1], FCARG2 + | mov CTSTATE->cb.stack, eax + | mov FCARG1, [esp+CFRAME_SIZE+12] // Move around misplaced retaddr/ebp. + | mov FCARG2, [esp+CFRAME_SIZE+8] + | mov SAVE_RET, FCARG1 + | mov SAVE_R4, FCARG2 + | mov FCARG2, esp + |.endif + | mov SAVE_PC, CTSTATE // Any value outside of bytecode is ok. + | mov FCARG1, CTSTATE + | call extern lj_ccallback_enter@8 // (CTState *cts, void *cf) + | // lua_State * returned in eax (RD). + | set_vmstate INTERP + | mov BASE, L:RD->base + | mov RD, L:RD->top + | sub RD, BASE + | mov LFUNC:RB, [BASE-8] + | shr RD, 3 + | add RD, 1 + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | mov L:RA, SAVE_L + | mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)] + | mov aword CTSTATE->L, L:RAa + | mov L:RA->base, BASE + | mov L:RA->top, RB + | mov FCARG1, CTSTATE + | mov FCARG2, RC + | call extern lj_ccallback_leave@8 // (CTState *cts, TValue *o) + |.if X64 + | mov rax, CTSTATE->cb.gpr[0] + | movsd xmm0, qword CTSTATE->cb.fpr[0] + | jmp ->vm_leave_unw + |.else + | mov L:RB, SAVE_L + | mov eax, CTSTATE->cb.gpr[0] + | mov edx, CTSTATE->cb.gpr[1] + | cmp dword CTSTATE->cb.gpr[2], 1 + | jb >7 + | je >6 + | fld qword CTSTATE->cb.fpr[0].d + | jmp >7 + |6: + | fld dword CTSTATE->cb.fpr[0].f + |7: + | mov ecx, L:RB->top + | movzx ecx, word [ecx+6] // Get stack adjustment and copy up. + | mov SAVE_L, ecx // Must be one slot above SAVE_RET + | restoreregs + | pop ecx // Move return addr from SAVE_RET. + | add esp, [esp] // Adjust stack. + | add esp, 16 + | push ecx + | ret + |.endif + |.endif + | + |->vm_ffi_call@4: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + |.if X64 + | .type CCSTATE, CCallState, rbx + | push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1 + |.else + | .type CCSTATE, CCallState, ebx + | push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1 + |.endif + | + | // Readjust stack. + |.if X64 + | mov eax, CCSTATE->spadj + | sub rsp, rax + |.else + | sub esp, CCSTATE->spadj + |.if WIN + | mov CCSTATE->spadj, esp + |.endif + |.endif + | + | // Copy stack slots. + | movzx ecx, byte CCSTATE->nsp + | sub ecx, 1 + | js >2 + |1: + |.if X64 + | mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)] + | mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax + |.else + | mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)] + | mov [esp+ecx*4], eax + |.endif + | sub ecx, 1 + | jns <1 + |2: + | + |.if X64 + | movzx eax, byte CCSTATE->nfpr + | mov CARG1, CCSTATE->gpr[0] + | mov CARG2, CCSTATE->gpr[1] + | mov CARG3, CCSTATE->gpr[2] + | mov CARG4, CCSTATE->gpr[3] + |.if not X64WIN + | mov CARG5, CCSTATE->gpr[4] + | mov CARG6, CCSTATE->gpr[5] + |.endif + | test eax, eax; jz >5 + | movaps xmm0, CCSTATE->fpr[0] + | movaps xmm1, CCSTATE->fpr[1] + | movaps xmm2, CCSTATE->fpr[2] + | movaps xmm3, CCSTATE->fpr[3] + |.if not X64WIN + | cmp eax, 4; jbe >5 + | movaps xmm4, CCSTATE->fpr[4] + | movaps xmm5, CCSTATE->fpr[5] + | movaps xmm6, CCSTATE->fpr[6] + | movaps xmm7, CCSTATE->fpr[7] + |.endif + |5: + |.else + | mov FCARG1, CCSTATE->gpr[0] + | mov FCARG2, CCSTATE->gpr[1] + |.endif + | + | call aword CCSTATE->func + | + |.if X64 + | mov CCSTATE->gpr[0], rax + | movaps CCSTATE->fpr[0], xmm0 + |.if not X64WIN + | mov CCSTATE->gpr[1], rdx + | movaps CCSTATE->fpr[1], xmm1 + |.endif + |.else + | mov CCSTATE->gpr[0], eax + | mov CCSTATE->gpr[1], edx + | cmp byte CCSTATE->resx87, 1 + | jb >7 + | je >6 + | fstp qword CCSTATE->fpr[0].d[0] + | jmp >7 + |6: + | fstp dword CCSTATE->fpr[0].f[0] + |7: + |.if WIN + | sub CCSTATE->spadj, esp + |.endif + |.endif + | + |.if X64 + | mov rbx, [rbp-8]; leave; ret + |.else + | mov ebx, [ebp-4]; leave; ret + |.endif + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |// Note: aligning all instructions does not pay off. + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + |.macro jmp_comp, lt, ge, le, gt, target + ||switch (op) { + ||case BC_ISLT: + | lt target + ||break; + ||case BC_ISGE: + | ge target + ||break; + ||case BC_ISLE: + | le target + ||break; + ||case BC_ISGT: + | gt target + ||break; + ||default: break; /* Shut up GCC. */ + ||} + |.endmacro + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1, RD = src2, JMP with RD = target + | ins_AD + |.if DUALNUM + | checkint RA, >7 + | checkint RD, >8 + | mov RB, dword [BASE+RA*8] + | add PC, 4 + | cmp RB, dword [BASE+RD*8] + | jmp_comp jge, jl, jg, jle, >9 + |6: + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RA is not an integer. + | ja ->vmeta_comp + | // RA is a number. + | cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp + | // RA is a number, RD is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RD*8] + | jmp >2 + |.else + | fld qword [BASE+RA*8] + | fild dword [BASE+RD*8] + | jmp >3 + |.endif + | + |8: // RA is an integer, RD is not an integer. + | ja ->vmeta_comp + | // RA is an integer, RD is a number. + |.if SSE + | cvtsi2sd xmm1, dword [BASE+RA*8] + | movsd xmm0, qword [BASE+RD*8] + | add PC, 4 + | ucomisd xmm0, xmm1 + | jmp_comp jbe, ja, jb, jae, <9 + | jmp <6 + |.else + | fild dword [BASE+RA*8] + | jmp >2 + |.endif + |.else + | checknum RA, ->vmeta_comp + | checknum RD, ->vmeta_comp + |.endif + |.if SSE + |1: + | movsd xmm0, qword [BASE+RD*8] + |2: + | add PC, 4 + | ucomisd xmm0, qword [BASE+RA*8] + |3: + |.else + |1: + | fld qword [BASE+RA*8] // Reverse order, i.e like cmp D, A. + |2: + | fld qword [BASE+RD*8] + |3: + | add PC, 4 + | fcomparepp + |.endif + | // Unordered: all of ZF CF PF set, ordered: PF clear. + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + |.if DUALNUM + | jmp_comp jbe, ja, jb, jae, <9 + | jmp <6 + |.else + | jmp_comp jbe, ja, jb, jae, >1 + | movzx RD, PC_RD + | branchPC RD + |1: + | ins_next + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | ins_AD // RA = src1, RD = src2, JMP with RD = target + | mov RB, [BASE+RD*8+4] + | add PC, 4 + |.if DUALNUM + | cmp RB, LJ_TISNUM; jne >7 + | checkint RA, >8 + | mov RB, dword [BASE+RD*8] + | cmp RB, dword [BASE+RA*8] + if (vk) { + | jne >9 + } else { + | je >9 + } + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RD is not an integer. + | ja >5 + | // RD is a number. + | cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5 + | // RD is a number, RA is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RA*8] + |.else + | fild dword [BASE+RA*8] + |.endif + | jmp >2 + | + |8: // RD is an integer, RA is not an integer. + | ja >5 + | // RD is an integer, RA is a number. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RD*8] + | ucomisd xmm0, qword [BASE+RA*8] + |.else + | fild dword [BASE+RD*8] + | fld qword [BASE+RA*8] + |.endif + | jmp >4 + | + |.else + | cmp RB, LJ_TISNUM; jae >5 + | checknum RA, >5 + |.endif + |.if SSE + |1: + | movsd xmm0, qword [BASE+RA*8] + |2: + | ucomisd xmm0, qword [BASE+RD*8] + |4: + |.else + |1: + | fld qword [BASE+RA*8] + |2: + | fld qword [BASE+RD*8] + |4: + | fcomparepp + |.endif + iseqne_fp: + if (vk) { + | jp >2 // Unordered means not equal. + | jne >2 + } else { + | jp >2 // Unordered means not equal. + | je >1 + } + iseqne_end: + if (vk) { + |1: // EQ: Branch to the target. + | movzx RD, PC_RD + | branchPC RD + |2: // NE: Fallthrough to next instruction. + |.if not FFI + |3: + |.endif + } else { + |.if not FFI + |3: + |.endif + |2: // NE: Branch to the target. + | movzx RD, PC_RD + | branchPC RD + |1: // EQ: Fallthrough to next instruction. + } + if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV || + op == BC_ISEQN || op == BC_ISNEN)) { + | jmp <9 + } else { + | ins_next + } + | + if (op == BC_ISEQV || op == BC_ISNEV) { + |5: // Either or both types are not numbers. + |.if FFI + | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd + | checktp RA, LJ_TCDATA; je ->vmeta_equal_cd + |.endif + | checktp RA, RB // Compare types. + | jne <2 // Not the same type? + | cmp RB, LJ_TISPRI + | jae <1 // Same type and primitive type? + | + | // Same types and not a primitive type. Compare GCobj or pvalue. + | mov RA, [BASE+RA*8] + | mov RD, [BASE+RD*8] + | cmp RA, RD + | je <1 // Same GCobjs or pvalues? + | cmp RB, LJ_TISTABUD + | ja <2 // Different objects and not table/ud? + |.if X64 + | cmp RB, LJ_TUDATA // And not 64 bit lightuserdata. + | jb <2 + |.endif + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | mov TAB:RB, TAB:RA->metatable + | test TAB:RB, TAB:RB + | jz <2 // No metatable? + | test byte TAB:RB->nomm, 1<vmeta_equal // Handle __eq metamethod. + } else { + |.if FFI + |3: + | cmp RB, LJ_TCDATA + if (LJ_DUALNUM && vk) { + | jne <9 + } else { + | jne <2 + } + | jmp ->vmeta_equal_cd + |.endif + } + break; + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | ins_AND // RA = src, RD = str const, JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + | cmp RB, LJ_TSTR; jne >3 + | mov RA, [BASE+RA*8] + | cmp RA, [KBASE+RD*4] + iseqne_test: + if (vk) { + | jne >2 + } else { + | je >1 + } + goto iseqne_end; + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | ins_AD // RA = src, RD = num const, JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + |.if DUALNUM + | cmp RB, LJ_TISNUM; jne >7 + | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8 + | mov RB, dword [KBASE+RD*8] + | cmp RB, dword [BASE+RA*8] + if (vk) { + | jne >9 + } else { + | je >9 + } + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RA is not an integer. + | ja >3 + | // RA is a number. + | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1 + | // RA is a number, RD is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [KBASE+RD*8] + |.else + | fild dword [KBASE+RD*8] + |.endif + | jmp >2 + | + |8: // RA is an integer, RD is a number. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RA*8] + | ucomisd xmm0, qword [KBASE+RD*8] + |.else + | fild dword [BASE+RA*8] + | fld qword [KBASE+RD*8] + |.endif + | jmp >4 + |.else + | cmp RB, LJ_TISNUM; jae >3 + |.endif + |.if SSE + |1: + | movsd xmm0, qword [KBASE+RD*8] + |2: + | ucomisd xmm0, qword [BASE+RA*8] + |4: + |.else + |1: + | fld qword [KBASE+RD*8] + |2: + | fld qword [BASE+RA*8] + |4: + | fcomparepp + |.endif + goto iseqne_fp; + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | ins_AND // RA = src, RD = primitive type (~), JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + | cmp RB, RD + if (!LJ_HASFFI) goto iseqne_test; + if (vk) { + | jne >3 + | movzx RD, PC_RD + | branchPC RD + |2: + | ins_next + |3: + | cmp RB, LJ_TCDATA; jne <2 + | jmp ->vmeta_equal_cd + } else { + | je >2 + | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd + | movzx RD, PC_RD + | branchPC RD + |2: + | ins_next + } + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | ins_AD // RA = dst or unused, RD = src, JMP with RD = target + | mov RB, [BASE+RD*8+4] + | add PC, 4 + | cmp RB, LJ_TISTRUECOND + if (op == BC_IST || op == BC_ISTC) { + | jae >1 + } else { + | jb >1 + } + if (op == BC_ISTC || op == BC_ISFC) { + | mov [BASE+RA*8+4], RB + | mov RB, [BASE+RD*8] + | mov [BASE+RA*8], RB + } + | movzx RD, PC_RD + | branchPC RD + |1: // Fallthrough to the next instruction. + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | ins_AD // RA = dst, RD = src + |.if X64 + | mov RBa, [BASE+RD*8] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [BASE+RD*8+4] + | mov RD, [BASE+RD*8] + | mov [BASE+RA*8+4], RB + | mov [BASE+RA*8], RD + |.endif + | ins_next_ + break; + case BC_NOT: + | ins_AD // RA = dst, RD = src + | xor RB, RB + | checktp RD, LJ_TISTRUECOND + | adc RB, LJ_TTRUE + | mov [BASE+RA*8+4], RB + | ins_next + break; + case BC_UNM: + | ins_AD // RA = dst, RD = src + |.if DUALNUM + | checkint RD, >5 + | mov RB, [BASE+RD*8] + | neg RB + | jo >4 + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RB + |9: + | ins_next + |4: + | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31. + | mov dword [BASE+RA*8], 0 + | jmp <9 + |5: + | ja ->vmeta_unm + |.else + | checknum RD, ->vmeta_unm + |.endif + |.if SSE + | movsd xmm0, qword [BASE+RD*8] + | sseconst_sign xmm1, RDa + | xorps xmm0, xmm1 + | movsd qword [BASE+RA*8], xmm0 + |.else + | fld qword [BASE+RD*8] + | fchs + | fstp qword [BASE+RA*8] + |.endif + |.if DUALNUM + | jmp <9 + |.else + | ins_next + |.endif + break; + case BC_LEN: + | ins_AD // RA = dst, RD = src + | checkstr RD, >2 + | mov STR:RD, [BASE+RD*8] + |.if DUALNUM + | mov RD, dword STR:RD->len + |1: + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RD + |.elif SSE + | xorps xmm0, xmm0 + | cvtsi2sd xmm0, dword STR:RD->len + |1: + | movsd qword [BASE+RA*8], xmm0 + |.else + | fild dword STR:RD->len + |1: + | fstp qword [BASE+RA*8] + |.endif + | ins_next + |2: + | checktab RD, ->vmeta_len + | mov TAB:FCARG1, [BASE+RD*8] +#if LJ_52 + | mov TAB:RB, TAB:FCARG1->metatable + | cmp TAB:RB, 0 + | jnz >9 + |3: +#endif + |->BC_LEN_Z: + | mov RB, BASE // Save BASE. + | call extern lj_tab_len@4 // (GCtab *t) + | // Length of table returned in eax (RD). + |.if DUALNUM + | // Nothing to do. + |.elif SSE + | cvtsi2sd xmm0, RD + |.else + | mov ARG1, RD + | fild ARG1 + |.endif + | mov BASE, RB // Restore BASE. + | movzx RA, PC_RA + | jmp <1 +#if LJ_52 + |9: // Check for __len. + | test byte TAB:RB->nomm, 1<vmeta_len // 'no __len' flag NOT set: check. +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre, x87ins, sseins, ssereg + | ins_ABC + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | checknum RB, ->vmeta_arith_vn + | .if DUALNUM + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn + | .endif + | .if SSE + | movsd xmm0, qword [BASE+RB*8] + | sseins ssereg, qword [KBASE+RC*8] + | .else + | fld qword [BASE+RB*8] + | x87ins qword [KBASE+RC*8] + | .endif + || break; + ||case 1: + | checknum RB, ->vmeta_arith_nv + | .if DUALNUM + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv + | .endif + | .if SSE + | movsd xmm0, qword [KBASE+RC*8] + | sseins ssereg, qword [BASE+RB*8] + | .else + | fld qword [KBASE+RC*8] + | x87ins qword [BASE+RB*8] + | .endif + || break; + ||default: + | checknum RB, ->vmeta_arith_vv + | checknum RC, ->vmeta_arith_vv + | .if SSE + | movsd xmm0, qword [BASE+RB*8] + | sseins ssereg, qword [BASE+RC*8] + | .else + | fld qword [BASE+RB*8] + | x87ins qword [BASE+RC*8] + | .endif + || break; + ||} + |.endmacro + | + |.macro ins_arithdn, intins + | ins_ABC + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | checkint RB, ->vmeta_arith_vn + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn + | mov RB, [BASE+RB*8] + | intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno + || break; + ||case 1: + | checkint RB, ->vmeta_arith_nv + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv + | mov RC, [KBASE+RC*8] + | intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo + || break; + ||default: + | checkint RB, ->vmeta_arith_vv + | checkint RC, ->vmeta_arith_vv + | mov RB, [BASE+RB*8] + | intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo + || break; + ||} + | mov dword [BASE+RA*8+4], LJ_TISNUM + ||if (vk == 1) { + | mov dword [BASE+RA*8], RC + ||} else { + | mov dword [BASE+RA*8], RB + ||} + | ins_next + |.endmacro + | + |.macro ins_arithpost + |.if SSE + | movsd qword [BASE+RA*8], xmm0 + |.else + | fstp qword [BASE+RA*8] + |.endif + |.endmacro + | + |.macro ins_arith, x87ins, sseins + | ins_arithpre x87ins, sseins, xmm0 + | ins_arithpost + | ins_next + |.endmacro + | + |.macro ins_arith, intins, x87ins, sseins + |.if DUALNUM + | ins_arithdn intins + |.else + | ins_arith, x87ins, sseins + |.endif + |.endmacro + + | // RA = dst, RB = src1 or num const, RC = src2 or num const + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith add, fadd, addsd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith sub, fsub, subsd + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith imul, fmul, mulsd + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith fdiv, divsd + break; + case BC_MODVN: + | ins_arithpre fld, movsd, xmm1 + |->BC_MODVN_Z: + | call ->vm_mod + | ins_arithpost + | ins_next + break; + case BC_MODNV: case BC_MODVV: + | ins_arithpre fld, movsd, xmm1 + | jmp ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + break; + case BC_POW: + | ins_arithpre fld, movsd, xmm1 + | call ->vm_pow + | ins_arithpost + | ins_next + break; + + case BC_CAT: + | ins_ABC // RA = dst, RB = src_start, RC = src_end + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | lea CARG2d, [BASE+RC*8] + | mov CARG3d, RC + | sub CARG3d, RB + |->BC_CAT_Z: + | mov L:RB, L:CARG1d + |.else + | lea RA, [BASE+RC*8] + | sub RC, RB + | mov ARG2, RA + | mov ARG3, RC + |->BC_CAT_Z: + | mov L:RB, SAVE_L + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // NULL (finished) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jnz ->vmeta_binop + | movzx RB, PC_RB // Copy result to Stk[RA] from Stk[RB]. + | movzx RA, PC_RA + |.if X64 + | mov RCa, [BASE+RB*8] + | mov [BASE+RA*8], RCa + |.else + | mov RC, [BASE+RB*8+4] + | mov RB, [BASE+RB*8] + | mov [BASE+RA*8+4], RC + | mov [BASE+RA*8], RB + |.endif + | ins_next + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | ins_AND // RA = dst, RD = str const (~) + | mov RD, [KBASE+RD*4] + | mov dword [BASE+RA*8+4], LJ_TSTR + | mov [BASE+RA*8], RD + | ins_next + break; + case BC_KCDATA: + |.if FFI + | ins_AND // RA = dst, RD = cdata const (~) + | mov RD, [KBASE+RD*4] + | mov dword [BASE+RA*8+4], LJ_TCDATA + | mov [BASE+RA*8], RD + | ins_next + |.endif + break; + case BC_KSHORT: + | ins_AD // RA = dst, RD = signed int16 literal + |.if DUALNUM + | movsx RD, RDW + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RD + |.elif SSE + | movsx RD, RDW // Sign-extend literal. + | cvtsi2sd xmm0, RD + | movsd qword [BASE+RA*8], xmm0 + |.else + | fild PC_RD // Refetch signed RD from instruction. + | fstp qword [BASE+RA*8] + |.endif + | ins_next + break; + case BC_KNUM: + | ins_AD // RA = dst, RD = num const + |.if SSE + | movsd xmm0, qword [KBASE+RD*8] + | movsd qword [BASE+RA*8], xmm0 + |.else + | fld qword [KBASE+RD*8] + | fstp qword [BASE+RA*8] + |.endif + | ins_next + break; + case BC_KPRI: + | ins_AND // RA = dst, RD = primitive type (~) + | mov [BASE+RA*8+4], RD + | ins_next + break; + case BC_KNIL: + | ins_AD // RA = dst_start, RD = dst_end + | lea RA, [BASE+RA*8+12] + | lea RD, [BASE+RD*8+4] + | mov RB, LJ_TNIL + | mov [RA-8], RB // Sets minimum 2 slots. + |1: + | mov [RA], RB + | add RA, 8 + | cmp RA, RD + | jbe <1 + | ins_next + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | ins_AD // RA = dst, RD = upvalue # + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)] + | mov RB, UPVAL:RB->v + |.if X64 + | mov RDa, [RB] + | mov [BASE+RA*8], RDa + |.else + | mov RD, [RB+4] + | mov RB, [RB] + | mov [BASE+RA*8+4], RD + | mov [BASE+RA*8], RB + |.endif + | ins_next + break; + case BC_USETV: +#define TV2MARKOFS \ + ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)) + | ins_AD // RA = upvalue #, RD = src + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | cmp byte UPVAL:RB->closed, 0 + | mov RB, UPVAL:RB->v + | mov RA, [BASE+RD*8] + | mov RD, [BASE+RD*8+4] + | mov [RB], RA + | mov [RB+4], RD + | jz >1 + | // Check barrier for closed upvalue. + | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv) + | jnz >2 + |1: + | ins_next + | + |2: // Upvalue is black. Check if new value is collectable and white. + | sub RD, LJ_TISGCV + | cmp RD, LJ_TNUMX - LJ_TISGCV // tvisgcv(v) + | jbe <1 + | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v) + | jz <1 + | // Crossed a write barrier. Move the barrier forward. + |.if X64 and not X64WIN + | mov FCARG2, RB + | mov RB, BASE // Save BASE. + |.else + | xchg FCARG2, RB // Save BASE (FCARG2 == BASE). + |.endif + | lea GL:FCARG1, [DISPATCH+GG_DISP2G] + | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv) + | mov BASE, RB // Restore BASE. + | jmp <1 + break; +#undef TV2MARKOFS + case BC_USETS: + | ins_AND // RA = upvalue #, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov GCOBJ:RA, [KBASE+RD*4] + | mov RD, UPVAL:RB->v + | mov [RD], GCOBJ:RA + | mov dword [RD+4], LJ_TSTR + | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv) + | jnz >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str) + | jz <1 + | cmp byte UPVAL:RB->closed, 0 + | jz <1 + | // Crossed a write barrier. Move the barrier forward. + | mov RB, BASE // Save BASE (FCARG2 == BASE). + | mov FCARG2, RD + | lea GL:FCARG1, [DISPATCH+GG_DISP2G] + | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv) + | mov BASE, RB // Restore BASE. + | jmp <1 + break; + case BC_USETN: + | ins_AD // RA = upvalue #, RD = num const + | mov LFUNC:RB, [BASE-8] + |.if SSE + | movsd xmm0, qword [KBASE+RD*8] + |.else + | fld qword [KBASE+RD*8] + |.endif + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov RA, UPVAL:RB->v + |.if SSE + | movsd qword [RA], xmm0 + |.else + | fstp qword [RA] + |.endif + | ins_next + break; + case BC_USETP: + | ins_AND // RA = upvalue #, RD = primitive type (~) + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov RA, UPVAL:RB->v + | mov [RA+4], RD + | ins_next + break; + case BC_UCLO: + | ins_AD // RA = level, RD = target + | branchPC RD // Do this first to free RD. + | mov L:RB, SAVE_L + | cmp dword L:RB->openupval, 0 + | je >1 + | mov L:RB->base, BASE + | lea FCARG2, [BASE+RA*8] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | call extern lj_func_closeuv@8 // (lua_State *L, TValue *level) + | mov BASE, L:RB->base + |1: + | ins_next + break; + + case BC_FNEW: + | ins_AND // RA = dst, RD = proto const (~) (holding function prototype) + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG3d, [BASE-8] + | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *. + | mov CARG1d, L:RB + |.else + | mov LFUNC:RA, [BASE-8] + | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *. + | mov L:RB, SAVE_L + | mov ARG3, LFUNC:RA + | mov ARG2, PROTO:RD + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | call extern lj_func_newL_gc + | // GCfuncL * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], LFUNC:RC + | mov dword [BASE+RA*8+4], LJ_TFUNC + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + | ins_AD // RA = dst, RD = hbits|asize + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] + | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] + | mov SAVE_PC, PC + | jae >5 + |1: + |.if X64 + | mov CARG3d, RD + | and RD, 0x7ff + | shr CARG3d, 11 + |.else + | mov RA, RD + | and RD, 0x7ff + | shr RA, 11 + | mov ARG3, RA + |.endif + | cmp RD, 0x7ff + | je >3 + |2: + |.if X64 + | mov L:CARG1d, L:RB + | mov CARG2d, RD + |.else + | mov ARG1, L:RB + | mov ARG2, RD + |.endif + | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Table * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], TAB:RC + | mov dword [BASE+RA*8+4], LJ_TTAB + | ins_next + |3: // Turn 0x7ff into 0x801. + | mov RD, 0x801 + | jmp <2 + |5: + | mov L:FCARG1, L:RB + | call extern lj_gc_step_fixtop@4 // (lua_State *L) + | movzx RD, PC_RD + | jmp <1 + break; + case BC_TDUP: + | ins_AND // RA = dst, RD = table const (~) (holding template table) + | mov L:RB, SAVE_L + | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] + | mov SAVE_PC, PC + | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] + | mov L:RB->base, BASE + | jae >3 + |2: + | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | call extern lj_tab_dup@8 // (lua_State *L, Table *kt) + | // Table * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], TAB:RC + | mov dword [BASE+RA*8+4], LJ_TTAB + | ins_next + |3: + | mov L:FCARG1, L:RB + | call extern lj_gc_step_fixtop@4 // (lua_State *L) + | movzx RD, PC_RD // Need to reload RD. + | not RDa + | jmp <2 + break; + + case BC_GGET: + | ins_AND // RA = dst, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov TAB:RB, LFUNC:RB->env + | mov STR:RC, [KBASE+RD*4] + | jmp ->BC_TGETS_Z + break; + case BC_GSET: + | ins_AND // RA = src, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov TAB:RB, LFUNC:RB->env + | mov STR:RC, [KBASE+RD*4] + | jmp ->BC_TSETS_Z + break; + + case BC_TGETV: + | ins_ABC // RA = dst, RB = table, RC = key + | checktab RB, ->vmeta_tgetv + | mov TAB:RB, [BASE+RB*8] + | + | // Integer key? + |.if DUALNUM + | checkint RC, >5 + | mov RC, dword [BASE+RC*8] + |.else + | // Convert number to int and back and compare. + | checknum RC, >5 + |.if SSE + | movsd xmm0, qword [BASE+RC*8] + | cvtsd2si RC, xmm0 + | cvtsi2sd xmm1, RC + | ucomisd xmm0, xmm1 + |.else + | fld qword [BASE+RC*8] + | fist ARG1 + | fild ARG1 + | fcomparepp + | mov RC, ARG1 + |.endif + | jne ->vmeta_tgetv // Generic numeric key? Use fallback. + |.endif + | cmp RC, TAB:RB->asize // Takes care of unordered, too. + | jae ->vmeta_tgetv // Not in array part? Use fallback. + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >2 + | // Get array slot. + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC] + | mov RC, [RC+4] + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + |.endif + |1: + | ins_next + | + |2: // Check for __index if table value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz >3 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tgetv // 'no __index' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + |3: + | mov dword [BASE+RA*8+4], LJ_TNIL + | jmp <1 + | + |5: // String key? + | checkstr RC, ->vmeta_tgetv + | mov STR:RC, [BASE+RC*8] + | jmp ->BC_TGETS_Z + break; + case BC_TGETS: + | ins_ABC // RA = dst, RB = table, RC = str const (~) + | not RCa + | mov STR:RC, [KBASE+RC*4] + | checktab RB, ->vmeta_tgets + | mov TAB:RB, [BASE+RB*8] + |->BC_TGETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA. + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | add NODE:RA, TAB:RB->node + |1: + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >4 + | cmp dword NODE:RA->key.gcr, STR:RC + | jne >4 + | // Ok, key found. Assumes: offsetof(Node, val) == 0 + | cmp dword [RA+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >5 // Key found, but nil value? + | movzx RC, PC_RA + | // Get node value. + |.if X64 + | mov RBa, [RA] + | mov [BASE+RC*8], RBa + |.else + | mov RB, [RA] + | mov RA, [RA+4] + | mov [BASE+RC*8], RB + | mov [BASE+RC*8+4], RA + |.endif + |2: + | ins_next + | + |3: + | movzx RC, PC_RA + | mov dword [BASE+RC*8+4], LJ_TNIL + | jmp <2 + | + |4: // Follow hash chain. + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | mov TAB:RA, TAB:RB->metatable + | test TAB:RA, TAB:RA + | jz <3 // No metatable: done. + | test byte TAB:RA->nomm, 1<vmeta_tgets // Caveat: preserve STR:RC. + break; + case BC_TGETB: + | ins_ABC // RA = dst, RB = table, RC = byte literal + | checktab RB, ->vmeta_tgetb + | mov TAB:RB, [BASE+RB*8] + | cmp RC, TAB:RB->asize + | jae ->vmeta_tgetb + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >2 + | // Get array slot. + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC] + | mov RC, [RC+4] + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + |.endif + |1: + | ins_next + | + |2: // Check for __index if table value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz >3 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tgetb // 'no __index' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + |3: + | mov dword [BASE+RA*8+4], LJ_TNIL + | jmp <1 + break; + + case BC_TSETV: + | ins_ABC // RA = src, RB = table, RC = key + | checktab RB, ->vmeta_tsetv + | mov TAB:RB, [BASE+RB*8] + | + | // Integer key? + |.if DUALNUM + | checkint RC, >5 + | mov RC, dword [BASE+RC*8] + |.else + | // Convert number to int and back and compare. + | checknum RC, >5 + |.if SSE + | movsd xmm0, qword [BASE+RC*8] + | cvtsd2si RC, xmm0 + | cvtsi2sd xmm1, RC + | ucomisd xmm0, xmm1 + |.else + | fld qword [BASE+RC*8] + | fist ARG1 + | fild ARG1 + | fcomparepp + | mov RC, ARG1 + |.endif + | jne ->vmeta_tsetv // Generic numeric key? Use fallback. + |.endif + | cmp RC, TAB:RB->asize // Takes care of unordered, too. + | jae ->vmeta_tsetv + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL + | je >3 // Previous value is nil? + |1: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: // Set array slot. + |.if X64 + | mov RBa, [BASE+RA*8] + | mov [RC], RBa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <1 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsetv // 'no __newindex' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + | jmp <1 + | + |5: // String key? + | checkstr RC, ->vmeta_tsetv + | mov STR:RC, [BASE+RC*8] + | jmp ->BC_TSETS_Z + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RA + | movzx RA, PC_RA // Restore RA. + | jmp <2 + break; + case BC_TSETS: + | ins_ABC // RA = src, RB = table, RC = str const (~) + | not RCa + | mov STR:RC, [KBASE+RC*4] + | checktab RB, ->vmeta_tsets + | mov TAB:RB, [BASE+RB*8] + |->BC_TSETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA. + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | mov byte TAB:RB->nomm, 0 // Clear metamethod cache. + | add NODE:RA, TAB:RB->node + |1: + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >5 + | cmp dword NODE:RA->key.gcr, STR:RC + | jne >5 + | // Ok, key found. Assumes: offsetof(Node, val) == 0 + | cmp dword [RA+4], LJ_TNIL + | je >4 // Previous value is nil? + |2: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |3: // Set node value. + | movzx RC, PC_RA + |.if X64 + | mov RBa, [BASE+RC*8] + | mov [RA], RBa + |.else + | mov RB, [BASE+RC*8+4] + | mov RC, [BASE+RC*8] + | mov [RA+4], RB + | mov [RA], RC + |.endif + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <2 + | mov TMP1, RA // Save RA. + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + | mov RA, TMP1 // Restore RA. + | jmp <2 + | + |5: // Follow hash chain. + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | mov TAB:RA, TAB:RB->metatable + | test TAB:RA, TAB:RA + | jz >6 // No metatable: continue. + | test byte TAB:RA->nomm, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mov TMP1, STR:RC + | mov TMP2, LJ_TSTR + | mov TMP3, TAB:RB // Save TAB:RB for us. + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | lea CARG3, TMP1 + | mov CARG2d, TAB:RB + | mov L:RB, L:CARG1d + |.else + | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. + | mov ARG2, TAB:RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Handles write barrier for the new key. TValue * returned in eax (RC). + | mov BASE, L:RB->base + | mov TAB:RB, TMP3 // Need TAB:RB for barrier. + | mov RA, eax + | jmp <2 // Must check write barrier for value. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RC // Destroys STR:RC. + | jmp <3 + break; + case BC_TSETB: + | ins_ABC // RA = src, RB = table, RC = byte literal + | checktab RB, ->vmeta_tsetb + | mov TAB:RB, [BASE+RB*8] + | cmp RC, TAB:RB->asize + | jae ->vmeta_tsetb + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL + | je >3 // Previous value is nil? + |1: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: // Set array slot. + |.if X64 + | mov RAa, [BASE+RA*8] + | mov [RC], RAa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <1 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsetb // 'no __newindex' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + | jmp <1 + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RA + | movzx RA, PC_RA // Restore RA. + | jmp <2 + break; + + case BC_TSETM: + | ins_AD // RA = base (table at base-1), RD = num const (start index) + | mov TMP1, KBASE // Need one more free register. + | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word. + |1: + | lea RA, [BASE+RA*8] + | mov TAB:RB, [RA-8] // Guaranteed to be a table. + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: + | mov RD, MULTRES + | sub RD, 1 + | jz >4 // Nothing to copy? + | add RD, KBASE // Compute needed size. + | cmp RD, TAB:RB->asize + | ja >5 // Doesn't fit into array part? + | sub RD, KBASE + | shl KBASE, 3 + | add KBASE, TAB:RB->array + |3: // Copy result slots to table. + |.if X64 + | mov RBa, [RA] + | add RA, 8 + | mov [KBASE], RBa + |.else + | mov RB, [RA] + | mov [KBASE], RB + | mov RB, [RA+4] + | add RA, 8 + | mov [KBASE+4], RB + |.endif + | add KBASE, 8 + | sub RD, 1 + | jnz <3 + |4: + | mov KBASE, TMP1 + | ins_next + | + |5: // Need to resize array part. + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, TAB:RB + | mov CARG3d, RD + | mov L:RB, L:CARG1d + |.else + | mov ARG2, TAB:RB + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov ARG3, RD + | mov ARG1, L:RB + |.endif + | mov SAVE_PC, PC + | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | mov BASE, L:RB->base + | movzx RA, PC_RA // Restore RA. + | jmp <1 // Retry. + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:RB, RD + | jmp <2 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALL: case BC_CALLM: + | ins_A_C // RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs + if (op == BC_CALLM) { + | add NARGS:RD, MULTRES + } + | cmp dword [BASE+RA*8+4], LJ_TFUNC + | mov LFUNC:RB, [BASE+RA*8] + | jne ->vmeta_call_ra + | lea BASE, [BASE+RA*8+8] + | ins_call + break; + + case BC_CALLMT: + | ins_AD // RA = base, RD = extra_nargs + | add NARGS:RD, MULTRES + | // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op. + break; + case BC_CALLT: + | ins_AD // RA = base, RD = nargs+1 + | lea RA, [BASE+RA*8+8] + | mov KBASE, BASE // Use KBASE for move + vmeta_call hint. + | mov LFUNC:RB, [RA-8] + | cmp dword [RA-4], LJ_TFUNC + | jne ->vmeta_call + |->BC_CALLT_Z: + | mov PC, [BASE-4] + | test PC, FRAME_TYPE + | jnz >7 + |1: + | mov [BASE-8], LFUNC:RB // Copy function down, reloaded below. + | mov MULTRES, NARGS:RD + | sub NARGS:RD, 1 + | jz >3 + |2: // Move args down. + |.if X64 + | mov RBa, [RA] + | add RA, 8 + | mov [KBASE], RBa + |.else + | mov RB, [RA] + | mov [KBASE], RB + | mov RB, [RA+4] + | add RA, 8 + | mov [KBASE+4], RB + |.endif + | add KBASE, 8 + | sub NARGS:RD, 1 + | jnz <2 + | + | mov LFUNC:RB, [BASE-8] + |3: + | mov NARGS:RD, MULTRES + | cmp byte LFUNC:RB->ffid, 1 // (> FF_C) Calling a fast function? + | ja >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function. + | test PC, FRAME_TYPE // Lua frame below? + | jnz <4 + | movzx RA, PC_RA + | not RAa + | lea RA, [BASE+RA*8] + | mov LFUNC:KBASE, [RA-8] // Need to prepare KBASE. + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | jmp <4 + | + |7: // Tailcall from a vararg function. + | sub PC, FRAME_VARG + | test PC, FRAME_TYPEP + | jnz >8 // Vararg frame below? + | sub BASE, PC // Need to relocate BASE/KBASE down. + | mov KBASE, BASE + | mov PC, [BASE-4] + | jmp <1 + |8: + | add PC, FRAME_VARG + | jmp <1 + break; + + case BC_ITERC: + | ins_A // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1) + | lea RA, [BASE+RA*8+8] // fb = base+1 + |.if X64 + | mov RBa, [RA-24] // Copy state. fb[0] = fb[-3]. + | mov RCa, [RA-16] // Copy control var. fb[1] = fb[-2]. + | mov [RA], RBa + | mov [RA+8], RCa + |.else + | mov RB, [RA-24] // Copy state. fb[0] = fb[-3]. + | mov RC, [RA-20] + | mov [RA], RB + | mov [RA+4], RC + | mov RB, [RA-16] // Copy control var. fb[1] = fb[-2]. + | mov RC, [RA-12] + | mov [RA+8], RB + | mov [RA+12], RC + |.endif + | mov LFUNC:RB, [RA-32] // Copy callable. fb[-1] = fb[-4] + | mov RC, [RA-28] + | mov [RA-8], LFUNC:RB + | mov [RA-4], RC + | cmp RC, LJ_TFUNC // Handle like a regular 2-arg call. + | mov NARGS:RD, 2+1 + | jne ->vmeta_call + | mov BASE, RA + | ins_call + break; + + case BC_ITERN: + | ins_A // RA = base, (RB = nresults+1, RC = nargs+1 (2+1)) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | mov TMP1, KBASE // Need two more free registers. + | mov TMP2, DISPATCH + | mov TAB:RB, [BASE+RA*8-16] + | mov RC, [BASE+RA*8-8] // Get index from control var. + | mov DISPATCH, TAB:RB->asize + | add PC, 4 + | mov KBASE, TAB:RB->array + |1: // Traverse array part. + | cmp RC, DISPATCH; jae >5 // Index points after array part? + | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4 + |.if DUALNUM + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RC + |.elif SSE + | cvtsi2sd xmm0, RC + |.else + | fild dword [BASE+RA*8-8] + |.endif + | // Copy array slot to returned value. + |.if X64 + | mov RBa, [KBASE+RC*8] + | mov [BASE+RA*8+8], RBa + |.else + | mov RB, [KBASE+RC*8+4] + | mov [BASE+RA*8+12], RB + | mov RB, [KBASE+RC*8] + | mov [BASE+RA*8+8], RB + |.endif + | add RC, 1 + | // Return array index as a numeric key. + |.if DUALNUM + | // See above. + |.elif SSE + | movsd qword [BASE+RA*8], xmm0 + |.else + | fstp qword [BASE+RA*8] + |.endif + | mov [BASE+RA*8-8], RC // Update control var. + |2: + | movzx RD, PC_RD // Get target from ITERL. + | branchPC RD + |3: + | mov DISPATCH, TMP2 + | mov KBASE, TMP1 + | ins_next + | + |4: // Skip holes in array part. + | add RC, 1 + |.if not (DUALNUM or SSE) + | mov [BASE+RA*8-8], RC + |.endif + | jmp <1 + | + |5: // Traverse hash part. + | sub RC, DISPATCH + |6: + | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1. + | imul KBASE, RC, #NODE + | add NODE:KBASE, TAB:RB->node + | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7 + | lea DISPATCH, [RC+DISPATCH+1] + | // Copy key and value from hash slot. + |.if X64 + | mov RBa, NODE:KBASE->key + | mov RCa, NODE:KBASE->val + | mov [BASE+RA*8], RBa + | mov [BASE+RA*8+8], RCa + |.else + | mov RB, NODE:KBASE->key.gcr + | mov RC, NODE:KBASE->key.it + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + | mov RB, NODE:KBASE->val.gcr + | mov RC, NODE:KBASE->val.it + | mov [BASE+RA*8+8], RB + | mov [BASE+RA*8+12], RC + |.endif + | mov [BASE+RA*8-8], DISPATCH + | jmp <2 + | + |7: // Skip holes in hash part. + | add RC, 1 + | jmp <6 + break; + + case BC_ISNEXT: + | ins_AD // RA = base, RD = target (points to ITERN) + | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5 + | mov CFUNC:RB, [BASE+RA*8-24] + | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5 + | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5 + | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 + | branchPC RD + | mov dword [BASE+RA*8-8], 0 // Initialize control var. + | mov dword [BASE+RA*8-4], 0xfffe7fff + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | mov PC_OP, BC_JMP + | branchPC RD + | mov byte [PC], BC_ITERC + | jmp <1 + break; + + case BC_VARG: + | ins_ABC // RA = base, RB = nresults+1, RC = numparams + | mov TMP1, KBASE // Need one more free register. + | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)] + | lea RA, [BASE+RA*8] + | sub KBASE, [BASE-4] + | // Note: KBASE may now be even _above_ BASE if nargs was < numparams. + | test RB, RB + | jz >5 // Copy all varargs? + | lea RB, [RA+RB*8-8] + | cmp KBASE, BASE // No vararg slots? + | jnb >2 + |1: // Copy vararg slots to destination slots. + |.if X64 + | mov RCa, [KBASE-8] + | add KBASE, 8 + | mov [RA], RCa + |.else + | mov RC, [KBASE-8] + | mov [RA], RC + | mov RC, [KBASE-4] + | add KBASE, 8 + | mov [RA+4], RC + |.endif + | add RA, 8 + | cmp RA, RB // All destination slots filled? + | jnb >3 + | cmp KBASE, BASE // No more vararg slots? + | jb <1 + |2: // Fill up remainder with nil. + | mov dword [RA+4], LJ_TNIL + | add RA, 8 + | cmp RA, RB + | jb <2 + |3: + | mov KBASE, TMP1 + | ins_next + | + |5: // Copy all varargs. + | mov MULTRES, 1 // MULTRES = 0+1 + | mov RC, BASE + | sub RC, KBASE + | jbe <3 // No vararg slots? + | mov RB, RC + | shr RB, 3 + | add RB, 1 + | mov MULTRES, RB // MULTRES = #varargs+1 + | mov L:RB, SAVE_L + | add RC, RA + | cmp RC, L:RB->maxstack + | ja >7 // Need to grow stack? + |6: // Copy all vararg slots. + |.if X64 + | mov RCa, [KBASE-8] + | add KBASE, 8 + | mov [RA], RCa + |.else + | mov RC, [KBASE-8] + | mov [RA], RC + | mov RC, [KBASE-4] + | add KBASE, 8 + | mov [RA+4], RC + |.endif + | add RA, 8 + | cmp KBASE, BASE // No more vararg slots? + | jb <6 + | jmp <3 + | + |7: // Grow stack for varargs. + | mov L:RB->base, BASE + | mov L:RB->top, RA + | mov SAVE_PC, PC + | sub KBASE, BASE // Need delta, because BASE may change. + | mov FCARG2, MULTRES + | sub FCARG2, 1 + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | mov RA, L:RB->top + | add KBASE, BASE + | jmp <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | ins_AD // RA = results, RD = extra_nresults + | add RD, MULTRES // MULTRES >=1, so RD >=1. + | // Fall through. Assumes BC_RET follows and ins_AD is a no-op. + break; + + case BC_RET: case BC_RET0: case BC_RET1: + | ins_AD // RA = results, RD = nresults+1 + if (op != BC_RET0) { + | shl RA, 3 + } + |1: + | mov PC, [BASE-4] + | mov MULTRES, RD // Save nresults+1. + | test PC, FRAME_TYPE // Check frame type marker. + | jnz >7 // Not returning to a fixarg Lua func? + switch (op) { + case BC_RET: + |->BC_RET_Z: + | mov KBASE, BASE // Use KBASE for result move. + | sub RD, 1 + | jz >3 + |2: // Move results down. + |.if X64 + | mov RBa, [KBASE+RA] + | mov [KBASE-8], RBa + |.else + | mov RB, [KBASE+RA] + | mov [KBASE-8], RB + | mov RB, [KBASE+RA+4] + | mov [KBASE-4], RB + |.endif + | add KBASE, 8 + | sub RD, 1 + | jnz <2 + |3: + | mov RD, MULTRES // Note: MULTRES may be >255. + | movzx RB, PC_RB // So cannot compare with RDL! + |5: + | cmp RB, RD // More results expected? + | ja >6 + break; + case BC_RET1: + |.if X64 + | mov RBa, [BASE+RA] + | mov [BASE-8], RBa + |.else + | mov RB, [BASE+RA+4] + | mov [BASE-4], RB + | mov RB, [BASE+RA] + | mov [BASE-8], RB + |.endif + /* fallthrough */ + case BC_RET0: + |5: + | cmp PC_RB, RDL // More results expected? + | ja >6 + default: + break; + } + | movzx RA, PC_RA + | not RAa // Note: ~RA = -(RA+1) + | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | ins_next + | + |6: // Fill up results with nil. + if (op == BC_RET) { + | mov dword [KBASE-4], LJ_TNIL // Note: relies on shifted base. + | add KBASE, 8 + } else { + | mov dword [BASE+RD*8-12], LJ_TNIL + } + | add RD, 1 + | jmp <5 + | + |7: // Non-standard return case. + | lea RB, [PC-FRAME_VARG] + | test RB, FRAME_TYPEP + | jnz ->vm_return + | // Return from vararg function: relocate BASE down and RA up. + | sub BASE, RB + if (op != BC_RET0) { + | add RA, RB + } + | jmp <1 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + |.define FOR_IDX, [RA]; .define FOR_TIDX, dword [RA+4] + |.define FOR_STOP, [RA+8]; .define FOR_TSTOP, dword [RA+12] + |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20] + |.define FOR_EXT, [RA+24]; .define FOR_TEXT, dword [RA+28] + + case BC_FORL: + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + vk = (op == BC_IFORL || op == BC_JFORL); + | ins_AJ // RA = base, RD = target (after end of loop or start of loop) + | lea RA, [BASE+RA*8] + if (LJ_DUALNUM) { + | cmp FOR_TIDX, LJ_TISNUM; jne >9 + if (!vk) { + | cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for + | cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for + | mov RB, dword FOR_IDX + | cmp dword FOR_STEP, 0; jl >5 + } else { +#ifdef LUA_USE_ASSERT + | cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type + | cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type +#endif + | mov RB, dword FOR_STEP + | test RB, RB; js >5 + | add RB, dword FOR_IDX; jo >1 + | mov dword FOR_IDX, RB + } + | cmp RB, dword FOR_STOP + | mov FOR_TEXT, LJ_TISNUM + | mov dword FOR_EXT, RB + if (op == BC_FORI) { + | jle >7 + |1: + |6: + | branchPC RD + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jle =>BC_JLOOP + |1: + |6: + } else if (op == BC_IFORL) { + | jg >7 + |6: + | branchPC RD + |1: + } else { + | jle =>BC_JLOOP + |1: + |6: + } + |7: + | ins_next + | + |5: // Invert check for negative step. + if (vk) { + | add RB, dword FOR_IDX; jo <1 + | mov dword FOR_IDX, RB + } + | cmp RB, dword FOR_STOP + | mov FOR_TEXT, LJ_TISNUM + | mov dword FOR_EXT, RB + if (op == BC_FORI) { + | jge <7 + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jge =>BC_JLOOP + } else if (op == BC_IFORL) { + | jl <7 + } else { + | jge =>BC_JLOOP + } + | jmp <6 + |9: // Fallback to FP variant. + } else if (!vk) { + | cmp FOR_TIDX, LJ_TISNUM + } + if (!vk) { + | jae ->vmeta_for + | cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for + } else { +#ifdef LUA_USE_ASSERT + | cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type + | cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type +#endif + } + | mov RB, FOR_TSTEP // Load type/hiword of for step. + if (!vk) { + | cmp RB, LJ_TISNUM; jae ->vmeta_for + } + |.if SSE + | movsd xmm0, qword FOR_IDX + | movsd xmm1, qword FOR_STOP + if (vk) { + | addsd xmm0, qword FOR_STEP + | movsd qword FOR_IDX, xmm0 + | test RB, RB; js >3 + } else { + | jl >3 + } + | ucomisd xmm1, xmm0 + |1: + | movsd qword FOR_EXT, xmm0 + |.else + | fld qword FOR_STOP + | fld qword FOR_IDX + if (vk) { + | fadd qword FOR_STEP // nidx = idx + step + | fst qword FOR_IDX + | fst qword FOR_EXT + | test RB, RB; js >1 + } else { + | fst qword FOR_EXT + | jl >1 + } + | fxch // Swap lim/(n)idx if step non-negative. + |1: + | fcomparepp + |.endif + if (op == BC_FORI) { + |.if DUALNUM + | jnb <7 + |.else + | jnb >2 + | branchPC RD + |.endif + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jnb =>BC_JLOOP + } else if (op == BC_IFORL) { + |.if DUALNUM + | jb <7 + |.else + | jb >2 + | branchPC RD + |.endif + } else { + | jnb =>BC_JLOOP + } + |.if DUALNUM + | jmp <6 + |.else + |2: + | ins_next + |.endif + |.if SSE + |3: // Invert comparison if step is negative. + | ucomisd xmm0, xmm1 + | jmp <1 + |.endif + break; + + case BC_ITERL: + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | ins_AJ // RA = base, RD = target + | lea RA, [BASE+RA*8] + | mov RB, [RA+4] + | cmp RB, LJ_TNIL; je >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | mov [RA-4], RB + | mov RB, [RA] + | mov [RA-8], RB + | jmp =>BC_JLOOP + } else { + | branchPC RD // Otherwise save control var + branch. + | mov RD, [RA] + | mov [RA-4], RB + | mov [RA-8], RD + } + |1: + | ins_next + break; + + case BC_LOOP: + | ins_A // RA = base, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op. + break; + + case BC_ILOOP: + | ins_A // RA = base, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | ins_AD // RA = base (ignored), RD = traceno + | mov RA, [DISPATCH+DISPATCH_J(trace)] + | mov TRACE:RD, [RA+RD*4] + | mov RDa, TRACE:RD->mcode + | mov L:RB, SAVE_L + | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE + | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB + | // Save additional callee-save registers only used in compiled code. + |.if X64WIN + | mov TMPQ, r12 + | mov TMPa, r13 + | mov CSAVE_4, r14 + | mov CSAVE_3, r15 + | mov RAa, rsp + | sub rsp, 9*16+4*8 + | movdqa [RAa], xmm6 + | movdqa [RAa-1*16], xmm7 + | movdqa [RAa-2*16], xmm8 + | movdqa [RAa-3*16], xmm9 + | movdqa [RAa-4*16], xmm10 + | movdqa [RAa-5*16], xmm11 + | movdqa [RAa-6*16], xmm12 + | movdqa [RAa-7*16], xmm13 + | movdqa [RAa-8*16], xmm14 + | movdqa [RAa-9*16], xmm15 + |.elif X64 + | mov TMPQ, r12 + | mov TMPa, r13 + | sub rsp, 16 + |.endif + | jmp RDa + |.endif + break; + + case BC_JMP: + | ins_AJ // RA = unused, RD = target + | branchPC RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + /* + ** Reminder: A function may be called with func/args above L->maxstack, + ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot, + ** too. This means all FUNC* ops (including fast functions) must check + ** for stack overflow _before_ adding more slots! + */ + + case BC_FUNCF: + |.if JIT + | hotcall RB + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | ins_AD // BASE = new base, RA = framesize, RD = nargs+1 + | mov KBASE, [PC-4+PC2PROTO(k)] + | mov L:RB, SAVE_L + | lea RA, [BASE+RA*8] // Top of frame. + | cmp RA, L:RB->maxstack + | ja ->vm_growstack_f + | movzx RA, byte [PC-4+PC2PROTO(numparams)] + | cmp NARGS:RD, RA // Check for missing parameters. + | jbe >3 + |2: + if (op == BC_JFUNCF) { + | movzx RD, PC_RD + | jmp =>BC_JLOOP + } else { + | ins_next + } + | + |3: // Clear missing parameters. + | mov dword [BASE+NARGS:RD*8-4], LJ_TNIL + | add NARGS:RD, 1 + | cmp NARGS:RD, RA + | jbe <3 + | jmp <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | int3 // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | ins_AD // BASE = new base, RA = framesize, RD = nargs+1 + | lea RB, [NARGS:RD*8+FRAME_VARG] + | lea RD, [BASE+NARGS:RD*8] + | mov LFUNC:KBASE, [BASE-8] + | mov [RD-4], RB // Store delta + FRAME_VARG. + | mov [RD-8], LFUNC:KBASE // Store copy of LFUNC. + | mov L:RB, SAVE_L + | lea RA, [RD+RA*8] + | cmp RA, L:RB->maxstack + | ja ->vm_growstack_v // Need to grow stack. + | mov RA, BASE + | mov BASE, RD + | movzx RB, byte [PC-4+PC2PROTO(numparams)] + | test RB, RB + | jz >2 + |1: // Copy fixarg slots up to new frame. + | add RA, 8 + | cmp RA, BASE + | jnb >3 // Less args than parameters? + | mov KBASE, [RA-8] + | mov [RD], KBASE + | mov KBASE, [RA-4] + | mov [RD+4], KBASE + | add RD, 8 + | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC). + | sub RB, 1 + | jnz <1 + |2: + if (op == BC_JFUNCV) { + | movzx RD, PC_RD + | jmp =>BC_JLOOP + } else { + | mov KBASE, [PC-4+PC2PROTO(k)] + | ins_next + } + | + |3: // Clear missing parameters. + | mov dword [RD+4], LJ_TNIL + | add RD, 8 + | sub RB, 1 + | jnz <3 + | jmp <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | ins_AD // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1 + | mov CFUNC:RB, [BASE-8] + | mov KBASEa, CFUNC:RB->f + | mov L:RB, SAVE_L + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB->base, BASE + | lea RA, [RD+8*LUA_MINSTACK] + | cmp RA, L:RB->maxstack + | mov L:RB->top, RD + if (op == BC_FUNCC) { + |.if X64 + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | mov ARG1, L:RB + |.endif + } else { + |.if X64 + | mov CARG2, KBASEa + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | mov ARG2, KBASEa + | mov ARG1, L:RB + |.endif + } + | ja ->vm_growstack_c // Need to grow stack. + | set_vmstate C + if (op == BC_FUNCC) { + | call KBASEa // (lua_State *L) + } else { + | // (lua_State *L, lua_CFunction f) + | call aword [DISPATCH+DISPATCH_GL(wrapf)] + } + | set_vmstate INTERP + | // nresults returned in eax (RD). + | mov BASE, L:RB->base + | lea RA, [BASE+RD*8] + | neg RA + | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8 + | mov PC, [BASE-4] // Fetch PC of caller. + | jmp ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + dasm_growpc(Dst, BC__MAX); + build_subroutines(ctx); + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); +#if LJ_64 +#define SZPTR "8" +#define BSZPTR "3" +#define REG_SP "0x7" +#define REG_RA "0x10" +#else +#define SZPTR "4" +#define BSZPTR "2" +#define REG_SP "0x4" +#define REG_RA "0x8" +#endif + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad .Lbegin\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE0:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad lj_vm_ffi_call\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.long lj_vm_ffi_call\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif +#if (defined(__sun__) && defined(__svr4__)) +#if LJ_64 + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n"); +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); +#endif +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); +#endif + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.long .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.long .LASFDE2-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE2:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.long .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.long .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.long .LASFDE3-.Lframe2\n" + "\t.long lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + /* Mental note: never let Apple design an assembler. + ** Or a linker. Or a plastic case. But I digress. + */ + case BUILD_machasm: { +#if LJ_HASFFI + int fcsize = 0; +#endif + int i; + fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n"); + fprintf(ctx->fp, + "EH_frame1:\n" + "\t.set L$set$x,LECIEX-LSCIEX\n" + "\t.long L$set$x\n" + "LSCIEX:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zPR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 6\n" /* augmentation length */ + "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */ +#if LJ_64 + "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEX:\n\n"); + for (i = 0; i < ctx->nsym; i++) { + const char *name = ctx->sym[i].name; + int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; + if (size == 0) continue; +#if LJ_HASFFI + if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; } +#endif + fprintf(ctx->fp, + "%s.eh:\n" + "LSFDE%d:\n" + "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" + "\t.long L$set$%d\n" + "LASFDE%d:\n" + "\t.long LASFDE%d-EH_frame1\n" + "\t.long %s-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ +#else + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDE%d:\n\n", + name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); + } +#if LJ_HASFFI + if (fcsize) { + fprintf(ctx->fp, + "EH_frame2:\n" + "\t.set L$set$y,LECIEY-LSCIEY\n" + "\t.long L$set$y\n" + "LSCIEY:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 1\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEY:\n\n"); + fprintf(ctx->fp, + "_lj_vm_ffi_call.eh:\n" + "LSFDEY:\n" + "\t.set L$set$yy,LEFDEY-LASFDEY\n" + "\t.long L$set$yy\n" + "LASFDEY:\n" + "\t.long LASFDEY-EH_frame2\n" + "\t.long _lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */ + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDEY:\n\n", fcsize); + } +#endif +#if LJ_64 + fprintf(ctx->fp, "\t.subsections_via_symbols\n"); +#else + fprintf(ctx->fp, + "\t.non_lazy_symbol_pointer\n" + "L_lj_err_unwind_dwarf$non_lazy_ptr:\n" + ".indirect_symbol _lj_err_unwind_dwarf\n" + ".long 0\n"); +#endif + } + break; + default: /* Difficult for other modes. */ + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/lua/xedkbuild.bat b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/xedkbuild.bat new file mode 100644 index 0000000..240ec87 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/lua/xedkbuild.bat @@ -0,0 +1,92 @@ +@rem Script to build LuaJIT with the Xbox 360 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler) +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL +@if not defined XEDK goto :FAIL + +@setlocal +@rem ---- Host compiler ---- +@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@rem Error out for 64 bit host compiler +@minilua +@if errorlevel 8 goto :FAIL + +@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_ppc.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m peobj -o lj_vm.obj +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@rem ---- Cross compiler ---- +@set LJCOMPILE="%XEDK%\bin\win32\cl" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC +@set LJLIB="%XEDK%\bin\win32\lib" /nologo +@set "INCLUDE=%XEDK%\include\xbox" + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set "LJCOMPILE=%LJCOMPILE% /Zi" +:NODEBUG +@if "%1"=="amalg" goto :AMALG +%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :NOAMALG +:AMALG +%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj +@if errorlevel 1 goto :BAD +:NOAMALG + +@del *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for Xbox 360 === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo To run this script you must open a "Visual Studio .NET Command Prompt" +@echo (32 bit host compiler). The Xbox 360 SDK must be installed, too. +:END diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/sa.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/sa.cpp new file mode 100644 index 0000000..9ec200e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/sa.cpp @@ -0,0 +1,413 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "winlua.h" +#include "../systeminc/menu.h" +#include "../systeminc/character.h" +#include +#include +#ifdef _AIDENGLU_ +#include "../systeminc/pc.h" +extern Landed PcLanded; +#endif +#include "../systeminc/field.h" +#ifdef _WIN_LUAJIT_ + +#define L_ESC '%' +#define FLAGS "-+ #0" +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) +#define MAX_ITEM 512 +#define uchar(c) ((unsigned char)(c)) +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; + if (isdigit(uchar(*p))) p++; + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; + if (isdigit(uchar(*p))) p++; + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +int SaLuaPrint(lua_State *L) +{ + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + memset(b.buffer,0,LUAL_BUFFERSIZE); + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); + else { + char form[MAX_FORMAT]; + char buff[MAX_ITEM]; + memset(form,0,MAX_FORMAT); + memset(buff,0,MAX_ITEM); + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; + } + else { + sprintf(buff, form, s); + break; + } + } + default: { + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + printf(b.buffer); + return 1; +} + +static int SaStockFontBuffer(lua_State *L) +{ + size_t l; + const int winX = luaL_checkint(L, 1); + const int winY = luaL_checkint(L, 2); + const int fontPrio = luaL_checkint(L, 3); + const int color = luaL_checkint(L, 4); + const char *data=luaL_checklstring(L, 5, &l); + const int hitFlag = luaL_checkint(L, 6); + lua_pushinteger(L, StockFontBuffer( winX, winY, fontPrio, color, (char *)data, hitFlag )); + return 1; +} + +static int SaMakeHitBox(lua_State *L) +{ + const int x1 = luaL_checkint(L, 1); + const int y1 = luaL_checkint(L, 2); + const int x2 = luaL_checkint(L, 3); + const int y2 = luaL_checkint(L, 4); + const int dispPrio = luaL_checkint(L, 5); + + lua_pushinteger(L, MakeHitBox( x1, y1 - 3, x2, y2 - 3, dispPrio )); + return 1; +} + +static int SaDeathAction(lua_State *L) +{ + const int addr = luaL_checkint(L, 1); + DeathAction((ACTION *)addr); + return 1; +} + +static int SaMakeWindowDisp(lua_State *L) +{ + const int x = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + const int sizeX = luaL_checkint(L, 3); + const int sizeY = luaL_checkint(L, 4); + const int titleNo = luaL_checkint(L, 5); + const int wndType = luaL_checkint(L, 6); + lua_pushinteger(L, (int)MakeWindowDisp(x,y,sizeX,sizeY,titleNo,wndType)); + return 1; +} + + +static int SaMakeAnimDisp(lua_State *L) +{ + const int x = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + const int sprNo = luaL_checkint(L, 3); + const int mode = luaL_checkint(L, 4); + lua_pushinteger(L, (int)MakeAnimDisp(x,y,sprNo,mode)); + return 1; +} + +static int SaStockDispBuffer(lua_State *L) +{ + const int x = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + const int dispPrio = luaL_checkint(L, 3); + const int bmpNo = luaL_checkint(L, 4); + const int hitFlag = luaL_checkint(L, 5); + lua_pushinteger(L, (int)StockDispBuffer(x,y,dispPrio,bmpNo, hitFlag)); + return 1; +} + +static int SaStockBoxDispBuffer(lua_State *L) +{ +#define STOCK_DISP_BUFFER_NO_BMP ( 1 << 31 ) // ??????? +#define STOCK_DISP_BUFFER_LINE ( 1 << 30 ) // ??? +#define STOCK_DISP_BUFFER_BOX ( 1 << 29 ) // ???? +#define STOCK_DISP_BUFFER_BOX_FILL ( 1 << 28 ) // ????D???? +#define STOCK_DISP_BUFFER_CIRCLE ( 1 << 27 ) // ? + const int x1 = luaL_checkint(L, 1); + const int y1 = luaL_checkint(L, 2); + const int x2 = luaL_checkint(L, 3); + const int y2 = luaL_checkint(L, 4); + const int dispPrio = luaL_checkint(L, 5); + const int color = luaL_checkint(L, 6); + const int fill = luaL_checkint(L, 7); + + int col; + int x = ( x1 << 16 ) | x2; + int y = ( y1 << 16 ) | y2; + + if( fill == 0 ) col = color | STOCK_DISP_BUFFER_BOX | STOCK_DISP_BUFFER_NO_BMP ; + else if( fill == 1 ) col = color | STOCK_DISP_BUFFER_BOX_FILL | STOCK_DISP_BUFFER_NO_BMP ; + else if( fill == 2 ) col = color | STOCK_DISP_BUFFER_LINE | STOCK_DISP_BUFFER_NO_BMP ; + + StockDispBuffer( x, y, dispPrio, col, 0 ); + return 1; +} + +static int SaPlaySe(lua_State *L) +{ + const int tone = luaL_checkint(L, 1); + const int x = luaL_checkint(L, 2); + const int y = luaL_checkint(L, 3); + extern int play_se(int tone, int x, int y); + play_se(tone, x, y); + return 1; +} + +static int SaLeftShift(lua_State *L) +{ + int mask = (int)luaL_checkint(L, 1); + const int id = luaL_checkint(L, 2); + + lua_pushinteger(L, mask <<= id); + return 1; +} + +static int SaRightShift(lua_State *L) +{ + int mask = (int)luaL_checkint(L, 1); + const int id = luaL_checkint(L, 2); + + lua_pushinteger(L, mask >>= id); + return 1; +} + +static int SaD1AndD2(lua_State *L) +{ + const int d1 = luaL_checkint(L, 1); + const int d2 = luaL_checkint(L, 2); + + lua_pushinteger(L, d1 & d2); + return 1; +} +extern SA_WINDOWS windows; +static int SaGetKeyInputFocus(lua_State *L) +{ + GetKeyInputFocus(&MyChatBuffer); + return 1; +} + +static int getTickCount(lua_State *L) +{ + lua_pushinteger(L, GetTickCount()); + + return 1; +} + +static int SaShellExecute(lua_State *L) +{ + size_t l; + const char *data=luaL_checklstring(L, 1, &l); + ShellExecute(NULL,"open",data,NULL,NULL,SW_SHOWNORMAL); + return 1; +} + +static int SaShowMessage(lua_State *L) +{ + size_t l; + const char *str=luaL_checklstring(L, 1, &l); + const int color=luaL_checkint(L, 2); + StockChatBufferLine( (char *)str, color); + return 1; +} +extern char szUser[], szPassword[]; +static int SaGetCdkey(lua_State *L) +{ + lua_pushstring(L, szUser); + return 1; +} + +static int SAtimeGetTime(lua_State *L) +{ + lua_pushinteger(L, timeGetTime()); + return 1; +} + +extern int getTextLength(char * str); +static int Lua_getTextLength(lua_State *L) +{ + size_t l; + const char *str=luaL_checklstring(L, 1, &l); + int ret = getTextLength((char *)str); + lua_pushinteger(L,ret); + return 1; +} + +static int Lua_TeaDecryption(lua_State *L) +{ + char temp[2024]; + memset(temp,0,2024); + size_t l; + const char *str=luaL_checklstring(L, 1, &l); + extern long TEA(long* v, long n, long* k); + extern int getfilesize(FILE* fp); + FILE *fp=NULL; + errno_t err = fopen_s(&fp,str,"rb"); + if(err==0){ + int len = getfilesize(fp); + fread(temp,1,len,fp); + fclose(fp); + TEA((long*)temp,len/4,(long*)_LUA_KEY_); + } + lua_pushstring(L, temp); + return 1; +} + +static int Lua_getStringFromIndexWithDelim_body(lua_State *L) +{ + extern BOOL getStringFromIndexWithDelim_body( char* src ,char* delim ,int index,char* buf , int buflen); + char temp[2048]; + memset(temp,0,2024); + size_t l; + const char *str=luaL_checklstring(L, 1, &l); + const int index=luaL_checkint(L, 2); + const char *delim=luaL_checklstring(L, 3, &l); + getStringFromIndexWithDelim_body((char *)str,(char *)delim,index,temp,2024); + lua_pushstring(L, temp); + return 1; +} + +static int Lua_strmemcpy(lua_State *L) +{ + char temp[2048]; + memset(temp,0,2024); + size_t l; + const char *str=luaL_checklstring(L, 1, &l); + const int index1=luaL_checkint(L, 2); + const int index2=luaL_checkint(L, 3); + memcpy(temp,str+index1-1,index2); + lua_pushstring(L, temp); + return 1; +} + + +static const luaL_Reg salib[] = { + + {"getStringFromIndexWithDelim", Lua_getStringFromIndexWithDelim_body}, + {"strmemcpy", Lua_strmemcpy}, + {"TeaDecryption", Lua_TeaDecryption}, + {"StockFontBuffer", SaStockFontBuffer}, + {"MakeHitBox", SaMakeHitBox}, + {"DeathAction", SaDeathAction}, + {"MakeWindowDisp", SaMakeWindowDisp}, + {"MakeAnimDisp", SaMakeAnimDisp}, + {"StockDispBuffer", SaStockDispBuffer}, + {"StockBoxDispBuffer", SaStockBoxDispBuffer}, + {"PlaySe", SaPlaySe}, + {"LeftShift", SaLeftShift}, + {"RightShift", SaRightShift}, + {"SaD1AndD2", SaD1AndD2}, + {"GetKeyInputFocus", SaGetKeyInputFocus}, + {"getTickCount", getTickCount}, + {"ShellExecute", SaShellExecute}, + {"ShowMessage", SaShowMessage}, + {"GetCdkey", SaGetCdkey}, + {"print", SaLuaPrint}, + {"timeGetTime", SAtimeGetTime}, + {"getTextLength", Lua_getTextLength}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Sa (lua_State *L) { + luaL_register(L, "sa", salib); + return 1; +} + +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/win.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/win.cpp new file mode 100644 index 0000000..2ef0215 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/win.cpp @@ -0,0 +1,236 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "winlua.h" +#include "../systeminc/character.h" +#include "../systeminc/tool.h" +#include "../systeminc/action.h" +#include "../systeminc/field.h" +#include "../systeminc/mouse.h" +#include "../systeminc/menu.h" +#include "../systeminc/netmain.h" +#include "../other/caryime.h" +#include "../oft/work.h" +#include +#include +#ifdef _WIN_LUAJIT_ +extern int cloasewindows; +extern SA_WINDOWS windows; + +static int InitWindow(lua_State *L) +{ + size_t l; + const int winW = luaL_checkint(L, 1); + const int winH = luaL_checkint(L, 2); + const int msgWNLen = luaL_checkint(L, 3); + const char *data = luaL_checklstring(L, 4, &l); + extern void getStrSplit( char *, char *, int, int, int ); + makeStringFromEscaped((char *)data); + getStrSplit(windows.message.data[0], (char *)data, 100, 25, msgWNLen); + return 1; +} + +static int NewPrint(lua_State *L) +{ + size_t l; + const char *data = luaL_checklstring(L, 1, &l); + printf(data); + return 1; +} + + + +static int getMessageData(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + lua_pushstring(L, windows.message.data[id]); + return 1; +} +static int getMouseLeftCrick(lua_State *L) +{ + lua_pushinteger(L, (mouse.onceState & MOUSE_LEFT_CRICK)); + return 1; +} + +extern int indexWN; +static int getIndexWN(lua_State *L) +{ + lua_pushinteger(L, indexWN); + return 1; +} +extern int idWN; +static int getIdWN(lua_State *L) +{ + lua_pushinteger(L, idWN); + return 1; +} +extern int buttonTypeWN; + +static int getButtonTypeWN(lua_State *L) +{ + lua_pushinteger(L, buttonTypeWN); + return 1; +} + + +static int getHitFontNo(lua_State *L) +{ + lua_pushinteger(L, HitFontNo); + return 1; +} + +static int getHitDispNo(lua_State *L) +{ + lua_pushinteger(L, HitDispNo); + return 1; +} +extern int windowTypeWN; +extern short wnCloseFlag; +static int CloseWindow(lua_State *L) +{ + windowTypeWN = -1; + wnCloseFlag = 1; + return 1; +} + +static int CloseFlg(lua_State *L) +{ + wnCloseFlag = 0; + return 1; +} + +static int DelWindow(lua_State *L) +{ + if( CheckMenuFlag() + || ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + || cloasewindows == 1) + { + wnCloseFlag = 0; + cloasewindows = 0; + lua_pushinteger(L, 1); + }else{ + lua_pushinteger(L, 0); + } + return 1; +} +void initStrBuffer( STR_BUFFER *, int, int, int, int, int ); +static int SaInitStrBuffer(lua_State *L) +{ + const int x = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + const int len = luaL_checkint(L, 3); + const int color = luaL_checkint(L, 4); + const int prio = luaL_checkint(L, 5); + //ʼϢ + windows.input.buffer[0] = '\0'; + windows.input.cnt = 0; + windows.input.cursor=0; + initStrBuffer( &windows.input, x, y, len, color, prio ); + return 1; +} + +static int SaInitNewStrBuffer(lua_State *L) +{ + size_t l; + const int x = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + const int len = luaL_checkint(L, 3); + const int color = luaL_checkint(L, 4); + const int prio = luaL_checkint(L, 5); + const char *str = luaL_checklstring(L, 6, &l); + //ʼϢ + int slen = strlen((char *)str); + if(slen > 0){ + strcpy(windows.input.buffer, str); + windows.input.cnt = slen; + windows.input.cursor=slen; + }else{ + windows.input.buffer[0] = '\0'; + windows.input.cnt = 0; + windows.input.cursor=0; + + } + initStrBuffer( &windows.input, x, y, len, color, prio ); + + return 1; +} + +static int SaWinGetKeyInputFocus(lua_State *L) +{ + GetKeyInputFocus( &windows.input ); + return 1; +} + +static int SaStockFontBuffer2(lua_State *L) +{ + StockFontBuffer2(&windows.input); + return 1; +} +static int SaSetInputMsgNum(lua_State *L) +{ + for(int i = 0; i < windows.input.cnt;i++) + { + if (windows.input.buffer[i] < '0' || windows.input.buffer[i] > '9') + { + if(i == 0){ + windows.input.buffer[i] = '1'; + }else{ + windows.input.buffer[i] = '0'; + } + } + } + return 1; +} + + +static int SaGetInputMsg(lua_State *L) +{ + lua_pushstring(L, windows.input.buffer); + return 1; +} +extern void ShowBottomLineString(int iColor,LPSTR lpstr); +static int SaShowBottomLineString(lua_State *L) +{ + size_t l; + const int color = luaL_checkint(L, 1); + const char *data = luaL_checklstring(L, 2, &l); + ShowBottomLineString(color,(char *)data); + return 1; +} + + + +static const luaL_Reg winlib[] = { + {"InitWindow", InitWindow}, + {"getMouseLeftCrick", getMouseLeftCrick}, + {"getIndexWN", getIndexWN}, + {"getIdWN", getIdWN}, + {"CloseWindow", CloseWindow}, + {"DelWindow", DelWindow}, + {"CloseFlg", CloseFlg}, + {"getButtonTypeWN", getButtonTypeWN}, + {"getHitFontNo", getHitFontNo}, + {"getHitDispNo", getHitDispNo}, + {"InitStrBuffer", SaInitStrBuffer}, + {"InitNewStrBuffer", SaInitNewStrBuffer}, + {"GetKeyInputFocus", SaWinGetKeyInputFocus}, + {"getMessageData", getMessageData}, + {"StockFontBuffer2", SaStockFontBuffer2}, + {"GetInputMsg", SaGetInputMsg}, + {"SetInputMsgNum", SaSetInputMsgNum}, + {"print", NewPrint}, + {"ShowBottomLineString", SaShowBottomLineString}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Win (lua_State *L) { + luaL_register(L, "win", winlib); + return 1; +} + +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.cpp b/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.cpp new file mode 100644 index 0000000..8c2e9f6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.cpp @@ -0,0 +1,439 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../wgs/tea.h" +#include "../systeminc/action.h" +#include "../newproto/autil.h" +#include "winlua.h" +#include +#include +#ifdef _WIN_LUAJIT_ +static const char *progname = "lua"; +MY_Lua MYLua; +lua_State* FindWinIntLua( int wintype, char *data ) +{ + lua_State *lua = NULL; + if (lua == NULL){ + char filename[256]; +#ifdef _RELUA_ + sprintf_s(filename, "%s//win//%d.lua", _LUA_PATCH_, wintype); +#else +#ifdef _SA_VERSION_25 + sprintf_s(filename, "%s//win//%d.es", _LUA_PATCH_, wintype); +#endif + +#endif + lua = FindLua(filename); + if (lua == NULL)return NULL; + } + lua_getglobal(lua, "WindowInit"); + if (!lua_isfunction(lua, -1)){ + lua_pop(lua, 1); + return NULL; + } + lua_pushstring(lua, data); + docall(lua, 1, 1); + return lua; +} + +ACTION * FreeCreateWinTypeLua( lua_State *lua ) +{ + if (lua == NULL){ + return NULL; + } + + lua_getglobal(lua, "CreateWinType"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return NULL; + } + + int TM_Ret = lua_pcall(lua, 0, 1, 0); + + if (TM_Ret != 0){ + printf("ڣFreeCreateWinTypeLua :%d(%s)\n", TM_Ret, lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + + if (!lua_isnumber(lua, -1)) + return NULL; + + int ret = (int)lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return (ACTION *)ret; +} + +ACTION * FreeServerWinTypeLua( lua_State *lua ) +{ + if (lua == NULL){ + return NULL; + } + lua_getglobal(lua, "ServerWindowType"); + int TM_Ret = lua_pcall(lua, 0, 1, 0); + + if (TM_Ret != 0){ + printf("ڣFreeServerWinTypeLua :%d(%s)\n", TM_Ret, lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + if (!lua_isnumber(lua, -1)) + return NULL; + int ret = (int)lua_tonumber(lua, -1); + lua_pop(lua, 1); + return (ACTION *)ret; +} + + +static const luaL_Reg lualibs[] = { + {"Win", luaopen_Win}, + {"lssproto", luaopen_Lssproto}, + {"sa", luaopen_Sa}, + {"ServerList", luaopen_ServerList}, + {"data", luaopen_Data}, + {NULL, NULL} +}; + +LUALIB_API void luaAB_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + +int getArrayInt(lua_State *L, int idx) { + int result = 0; + lua_pushnumber(L, idx + 1); + lua_gettable(L, -2); + result = (int)lua_tonumber(L, -1); + lua_pop(L, 1); + return result; +} + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + lua_remove(L, base); + if(status != 0){ + printf("ڣdocall :%d(%s)\n", status, lua_tostring(L, -1)); + int iTop = lua_gettop(L); + lua_pop(L,iTop); + lua_gc(L, LUA_GCCOLLECT, 0); + } + + return status; +} + +int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + +int decryptLUA(lua_State *L, char *filename){ + FILE *f; + char loadfilename[256]; + int luamaxlen = 0; + unsigned char *luabuff; + strcpy(loadfilename, filename); + fopen_s(&f,loadfilename,"rb");//򿪲1 + if (f!=NULL){ + fseek(f,0,SEEK_END); + luamaxlen = ftell(f); + luabuff = (unsigned char*)malloc(luamaxlen+1); + fseek(f,0,SEEK_SET); + fread(luabuff, 1, luamaxlen, f); + fclose(f); + luabuff[luamaxlen]=0; + }else{ + return -100; + } + TEA((long*)luabuff,(luamaxlen/4),(long *)_LUA_KEY_); + int status = luaL_dostring(L,(const char *)luabuff); + free(luabuff); + return status; +} + + +int myluaload (char *filename) +{ + MY_Lua *salua = &MYLua; + while(salua->next!=NULL){ + if(strcmp(salua->luapath, filename) == 0){ + return FALSE; + } + salua = salua->next; + } + salua->luapath = new char[strlen(filename)+1]; + memset( salua->luapath, 0 , strlen(filename)+1); + strcpy(salua->luapath, filename); + salua->next = (tagMYLua *)new MY_Lua; + memset( salua->next, 0 , sizeof(MY_Lua) ); + if(salua->next == NULL)return EXIT_FAILURE; + + salua->lua = lua_open(); + if (salua->lua == NULL) { + return FALSE; + } + lua_gc(salua->lua, LUA_GCSTOP, 0); + luaL_openlibs(salua->lua); + luaAB_openlibs(salua->lua); + lua_gc(salua->lua, LUA_GCRESTART, 0); +#ifdef _RELUA_ + int re = dofile(salua->lua, filename); + if(re!=0){ + printf("ļ%s ʾ%s %d\n",filename,(char *)lua_tostring(salua->lua, -1),re); + lua_gc(salua->lua, LUA_GCCOLLECT, 0); + return TRUE; + } +#else + int re = decryptLUA(salua->lua, filename); + if(re != 0){ + if(re==-100) return TRUE; + printf("ļ%s ʾ%s %d\n",filename,(char *)lua_tostring(salua->lua, -1),re); + lua_gc(salua->lua, LUA_GCCOLLECT, 0); + return TRUE; + } +#endif + lua_getglobal(salua->lua, "main"); + if (lua_isfunction(salua->lua, -1)) { + docall(salua->lua, 0, 1); + } + return TRUE; +} + +int remyluaload (char *filename) +{ + MY_Lua *salua = &MYLua; + + while(salua->next!=NULL){ + if(strlen(salua->luapath) > 0){ + if(strlen(filename)>0){ + if(strstr(salua->luapath, filename) == 0){ + salua = salua->next; + continue; + } + } + lua_gc(salua->lua, LUA_GCSTOP, 0); + luaL_openlibs(salua->lua); + luaAB_openlibs(salua->lua); + lua_gc(salua->lua, LUA_GCRESTART, 0); + dofile(salua->lua, salua->luapath); + lua_getglobal(salua->lua, "data"); + if (lua_isfunction(salua->lua, -1)) { + docall(salua->lua, 0, 1); + } + } + salua = salua->next; + } + return EXIT_SUCCESS; +} + + +int closemyluaload() +{ + MY_Lua *salua = &MYLua; + while(salua->next!=NULL){ + lua_pop(salua->lua, 1); + lua_close(salua->lua); + salua = salua->next; + } + + return EXIT_SUCCESS; +} + +void LoadStoneAgeLUA(char *path) +{ + char filename[256]; + + WIN32_FIND_DATA wfd; + HANDLE hFind; + lstrcpy(filename, path); + lstrcat(filename, "/"); + lstrcat(filename, "*.*"); // ļ + + hFind = FindFirstFile(filename, &wfd); + if (hFind == INVALID_HANDLE_VALUE) // ûҵʧ + return; + do{ + + if (wfd.cFileName[0] == '.') + continue; // Ŀ¼ + if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + sprintf_s(filename, "%s//%s", path, wfd.cFileName); + LoadStoneAgeLUA(filename); + }else{ +#ifdef _RELUA_ + if( strcmptail( wfd.cFileName, ".lua" ) == 0) +#else +#ifdef _SA_VERSION_25 + if( strcmptail( wfd.cFileName, "es" ) == 0) +#endif + +#endif + { + char filename[256]; + memset(filename, 0, 256); + sprintf_s(filename, "%s//%s", path, wfd.cFileName); + myluaload(filename); + } + } + }while (FindNextFile(hFind, &wfd)); + FindClose(hFind); // رղҾ +} + +void ReLoadStoneAgeLUA(char *filename) +{ + remyluaload(filename); +} + +void NewLoadStoneAgeLUA(char *filename) +{ + char token[256]; + if(strlen(filename)>0){ + sprintf_s(token, "%s//%s", _LUA_PATCH_,filename); + myluaload(token); + }else{ + LoadStoneAgeLUA(_LUA_PATCH_); + } +} + +lua_State *FindLua(char *filename) +{ + MY_Lua *salua = &MYLua; + char newfilename[256]; + sprintf_s(newfilename, "%s", filename); + while(salua->next != NULL){ + if(strcmp(newfilename, salua->luapath) == 0){ + return salua->lua; + } + salua = salua->next; + } + return NULL; +} + + + +int FreeGetBattleMap(int floor) +{ + lua_State *lua = NULL; + if (lua == NULL){ + char filename[256]; +#ifdef _RELUA_ + sprintf_s(filename, "%s//map//battlemap.lua",_LUA_PATCH_); +#else +#ifdef _SA_VERSION_25 + sprintf_s(filename, "%s//map//battlemap.es",_LUA_PATCH_); +#endif + +#endif + lua = FindLua(filename); + if (lua == NULL)return NULL; + } + lua_getglobal(lua, "FreeGetBattleMap"); + if (!lua_isfunction(lua, -1)) { + printf("FreeGetBattleMap (%s)\n", lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + lua_pushnumber(lua, floor); + int TM_Ret = lua_pcall(lua, 1, 1, 0); + + if (TM_Ret != 0){ + printf("ڣFreeGetBattleMap :%d(%s)\n", TM_Ret, lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + if (!lua_isnumber(lua, -1)) + return NULL; + int ret = (int)lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + + +#endif + + +#ifdef _CHARTITLE_STR_ +char* FreeGetTitleStr(int id) +{ + lua_State *lua = NULL; + if (lua == NULL){ + char filename[256]; +#ifdef _RELUA_ + sprintf_s(filename, "%s//title.lua",_LUA_PATCH_); +#else +#ifdef _SA_VERSION_25 + sprintf_s(filename, "%s//title.es",_LUA_PATCH_); +#endif + +#endif + lua = FindLua(filename); + if (lua == NULL)return NULL; + } + lua_getglobal(lua, "GetTitleStr"); + if (!lua_isfunction(lua, -1)) { + printf("GetTitleStr (%s)\n", lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + lua_pushnumber(lua, id); + int TM_Ret = lua_pcall(lua, 1, 1, 0); + + if (TM_Ret != 0){ + printf("ڣGetTitleStr :%d(%s)\n", TM_Ret, lua_tostring(lua, -1)); + lua_pop(lua, 1); + return NULL; + } + if (!lua_isstring(lua, -1)) + return NULL; + char *ret = (char *)lua_tostring(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.h b/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.h new file mode 100644 index 0000000..5a0eebe --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/mylua/winlua.h @@ -0,0 +1,45 @@ +#pragma comment(lib,"lua51.lib") +extern "C" { +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +} +#include +#include +#ifdef _WIN_LUAJIT_ +int myluaload (char *filename); +int remyluaload (char *filename); +void LoadStoneAgeLUA(char *path); +int closemyluaload(); +int dofile (lua_State *L, const char *name); +int docall (lua_State *L, int narg, int clear); +int getArrayInt(lua_State *L, int idx); +LUALIB_API void luaAB_openlibs (lua_State *L); +LUALIB_API int luaopen_Win(lua_State *L); +LUALIB_API int luaopen_Lssproto(lua_State *L); +LUALIB_API int luaopen_Sa (lua_State *L); +LUALIB_API int luaopen_ServerList (lua_State *L); +LUALIB_API int luaopen_Data (lua_State *L); +lua_State *FindLua(char *filename); +lua_State* FindWinIntLua( int wintype, char *data ); +ACTION * FreeCreateWinTypeLua( lua_State *lua ); +ACTION * FreeServerWinTypeLua( lua_State *lua ); +void ReLoadStoneAgeLUA(char *filename); +void LC_LUA_ITEM_DIRECTIONS(int x,int y,char *name,int iamge); + +typedef struct tagMYLua +{ + lua_State *lua; + char *luapath; + struct tagMYLua *next; +}MY_Lua; + +LUALIB_API int luaopen_Win (lua_State *L); +LUALIB_API int luaopen_ServerList (lua_State *L); +LUALIB_API int luaopen_Sa (lua_State *L); +LUALIB_API int luaopen_Lssproto (lua_State *L); +LUALIB_API int luaopen_Data (lua_State *L); +int FreeGetBattleMap(int floor); +int CheckPlayOnLine(int index,char * account,char *mac); +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/newproto/autil.cpp b/石器时代8.5客户端最新源代码/石器源码/newproto/autil.cpp new file mode 100644 index 0000000..bc82000 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/newproto/autil.cpp @@ -0,0 +1,971 @@ +// Arminius' protocol utilities ver 0.1 +// +// Any questions and bugs, mailto: arminius@mail.hwaei.com.tw + +// ------------------------------------------------------------------- +// The following definitions is to define game-dependent codes. +// Before compiling, remove the "//". +#define __STONEAGE +#include +#include +#include +#include "autil.h" +#include "../systeminc/chat.h" +#include "../systeminc/font.h" +#include "../systeminc/VMProtectSDK.h" +#ifdef __STONEAGE +#include "../systeminc/version.h" +#include "../systeminc/lssproto_util.h" +//#include "../systeminc/common.h" +#endif + +char **MesgSlice; +int SliceCount; + +char PersonalKey[32]; + +#ifdef _STONDEBUG_ +extern int g_iMallocCount; +#endif + +// ------------------------------------------------------------------- +// Initialize utilities +// +void util_Init(void) +{ + int i; + + MesgSlice = (char **) MALLOC(sizeof(char *) * SLICE_MAX); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + for (i=0; i=SliceCount) { + // discard all message + for (j=0; j0=bytes converted +int util_256to64(char *dst, char *src, int len, char *table) +{ + unsigned int dw,dwcounter; + int i; + + if (!dst || !src || !table) return 0; + dw=0; + dwcounter=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ dw & 0x3f ]; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ dw ]; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Convert 6-bit strings into 8-bit strings, buffers that store these strings +// must have enough space. +// +// arg: dst=6-bit string; src=8-bit string; table=mapping table +// ret: 0=failed >0=bytes converted +int util_64to256(char *dst, char *src, char *table) +{ + unsigned int dw,dwcounter; + unsigned int i, j; + char *ptr = NULL; + + dw=0; + dwcounter=0; + if (!dst || !src || !table) return 0; + char c; + for (i=0; i> 8; + } else { + dw = (unsigned int)(ptr-table) & 0x3f; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// This basically is a 256to64 encoder. But it shifts the result by key. +// +// arg: dst=6-bit string; src=8-bit string; len=src strlen; +// table=mapping table; key=rotate key; +// ret: 0=failed >0=bytes converted +int util_256to64_shr(char *dst, char *src, int len, char *table, char *key) +{ + unsigned int dw,dwcounter,j; + int i; + + if (!dst || !src || !table || !key) return 0; + if (strlen(key)<1) return 0; // key can't be empty. + dw=0; + dwcounter=0; + j=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ ((dw & 0x3f) + key[j]) % 64 ];// check! + j++; if (!key[j]) j=0; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ (dw + key[j]) % 64 ]; // check! + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Decoding function of util_256to64_shr. +// +// arg: dst=8-bit string; src=6-bit string; table=mapping table; +// key=rotate key; +// ret: 0=failed >0=bytes converted +int util_shl_64to256(char *dst, char *src, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j,k; + char *ptr = NULL; + + if (!key || (strlen(key)<1)) return 0; // must have key + + dw=0; + dwcounter=0; + j=0; + if (!dst || !src || !table) return 0; + char c; + for (i=0; i> 8; + } else { + // check! + dw = (((unsigned int)(ptr-table) & 0x3f) + 64 - key[j]) % 64; + j++; if (!key[j]) j=0; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// This basically is a 256to64 encoder. But it shifts the result by key. +// +// arg: dst=6-bit string; src=8-bit string; len=src strlen; +// table=mapping table; key=rotate key; +// ret: 0=failed >0=bytes converted +int util_256to64_shl(char *dst, char *src, int len, char *table, char *key) +{ + unsigned int dw,dwcounter; + int i, j; + + if (!dst || !src || !table || !key) return 0; + if (strlen(key)<1) return 0; // key can't be empty. + dw=0; + dwcounter=0; + j=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ ((dw & 0x3f) + 64 - key[j]) % 64 ]; // check! + j++; if (!key[j]) j=0; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ (dw + 64 - key[j]) % 64 ]; // check! + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Decoding function of util_256to64_shl. +// +// arg: dst=8-bit string; src=6-bit string; table=mapping table; +// key=rotate key; +// ret: 0=failed >0=bytes converted +int util_shr_64to256(char *dst, char *src, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j,k; + char *ptr = NULL; + if (!key || (strlen(key)<1)) return 0; // must have key + dw=0; + dwcounter=0; + j=0; + if (!dst || !src || !table) return 0; + char c; + for (i=0; i> 8; + } else { + // check! + dw = (((unsigned int)(ptr-table) & 0x3f) + key[j]) % 64; + j++; if (!key[j]) j=0; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Swap a integer (4 byte). +// The value "rule" indicates the swaping rule. It's a 4 byte string +// such as "1324" or "2431". +// +void util_swapint(int *dst, int *src, char *rule) +{ + char *ptr, *qtr; + int i; + + ptr = (char *) src; + qtr = (char *) dst; + for (i=0; i<4; i++) qtr[rule[i]-'1']=ptr[i]; +} + +// ------------------------------------------------------------------- +// Xor a string. Be careful that your string contains '0xff'. Your +// data may lose. +// +void util_xorstring(char *dst, char *src) +{ + unsigned int i; + + for (i=0; i 0 ){ + char* d = dest; + const char* s = src; + unsigned int i; + for( i=0; i=n ){ + *(d+i-1)='\0'; + break; + } + *(d+i) = *(s+i); + }else + *(d+i) = *(s+i); + } + } + return dest; +} + + +void strcpysafe( char* dest ,size_t n ,const char* src ) +{ + if (!src) { + *dest = '\0'; + return; + } + if( n <= 0 ) + return; + else if( n < strlen( src ) + 1 ){ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + }else + strcpy( dest , src ); +} + + +void strncpysafe( char* dest , const size_t n , + const char* src ,const int length ) +{ + unsigned int Short; + Short = min( strlen( src ) ,(unsigned int) length ); + if( n < Short + 1 ){ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + + }else if( n <= 0 ){ + return; + }else{ + strncpy2( dest , src , Short ); + dest[Short]= '\0'; + + } +} + + +BOOL getStringFromIndexWithDelim_body( char* src ,char* delim ,int index,char* buf , int buflen) +{ + int i; + int length =0; + int addlen=0; + int oneByteMode = 0; + + if( strlen( delim ) == 1 ){ + oneByteMode = 1; + } + for( i = 0 ; i < index ; i ++ ){ + char* last; + src += addlen; + + if( oneByteMode ){ + + last = ScanOneByte( src, delim[0] ); + }else{ + last = strstr( src , delim ); + } + if( last == NULL ){ + strcpysafe( buf , buflen, src ); + if( i == index - 1 ){ + if(buf[0]==0) return FALSE; + return TRUE; + } + buf[0]=0; + return FALSE; + } + length = last - src; + addlen= length + strlen( delim ); + } + strncpysafe( buf, buflen , src,length ); + if(buf[0]==0) return FALSE; + return TRUE; +} + +void ltrim(char *str){ + char *ptr; + for(ptr=str; *ptr == 32; ptr++) ; + +} + +void rtrim(char *str){ + int i; + for(i=(int)strlen(str)-1; str[i] == 32 && i>=0; str[i--]=0); +} +#ifdef _FONT_STYLE_ + +WM_STR wmstr[25]; +extern int getTextLength(char * str); +void getstrstyle(char *str,int index,int pos,int flg,WM_STR wm[]) +{ + char *stemp,*etemp; + if(flg) + stemp = str; + else + stemp = sunday(str, "[style "); + if(stemp){ + if(stemp!= str){ + wm[index].flg=TRUE; + wm[index].style[pos].size = FONT_SIZE1; + if(pos==0) + wm[index].style[pos].x = 0; + else + wm[index].style[pos].x = getTextLength(wm[index].style[pos-1].str)+wm[index].style[pos-1].x; + wm[index].style[pos].color = 0; + int len = stemp - str; + memcpy(wm[index].style[pos].str,str,len); + wm[index].style[pos].str[len]=NULL; + pos++; + getstrstyle(stemp,index,pos,TRUE,wm); + }else{ + wm[index].flg=TRUE; + stemp=stemp+7; + etemp = sunday(stemp, "]")+1; + char *scolor = sunday(stemp, "c="); + if(scolor){ + scolor=scolor+2; + char strnum[3]; + int i=0; + for(i;i<2 && scolor[i] !=' ' && scolor[i]!=']';i++){ + strnum[i] = scolor[i]; + } + strnum[i]=0; + wm[index].style[pos].color = atoi(strnum); + }else wm[index].style[pos].color =0; + + char *ssize = sunday(stemp, "s="); + if(ssize){ + ssize=ssize+2; + char strsize[3]; + int i=0; + for(i;i<2 && ssize[i] !=' ' && ssize[i]!=']';i++){ + strsize[i] = ssize[i]; + } + strsize[i]=0; + wm[index].style[pos].size = atoi(ssize); + }else wm[index].style[pos].size = FONT_SIZE1; + + stemp = sunday(str,"[/style]"); + + int len = stemp - etemp; + memcpy(wm[index].style[pos].str,etemp,len); + wm[index].style[pos].str[len]=NULL; + if(pos==0) + wm[index].style[pos].x = 0; + else + wm[index].style[pos].x = getTextLength(wm[index].style[pos-1].str)+wm[index].style[pos-1].x; + pos++; + stemp = stemp + 8; + getstrstyle(stemp,index,pos,FALSE,wm); + } + }else{ + sprintf(wm[index].style[pos].str,"%s",str); + if(!wm[index].flg){ + wm[index].flg=TRUE; + wm[index].style[pos].x = 0; + wm[index].style[pos].color = 0; + wm[index].style[pos].size = FONT_SIZE1; + }else{ + wm[index].style[pos].size = FONT_SIZE1; + wm[index].style[pos].x = getTextLength(wm[index].style[pos-1].str)+wm[index].style[pos-1].x; + wm[index].style[pos].color = 0; + } + } +} + +void PutWinText(int x,int y,char fontPrio,int color,char *str,BOOL hitFlag,int index ) +{ + int i=0; + for(;i<30;i++){ + if(*wmstr[index].style[i].str) + StockFontBufferExt(x+wmstr[index].style[i].x,y,fontPrio,wmstr[index].style[i].color, + wmstr[index].style[i].str,hitFlag,wmstr[index].style[i].size); + } +} +#ifdef _CHARTITLE_STR_ +void PutTitleText(int x,int y,char fontPrio,TITLE_STR str,BOOL hitFlag) +{ + int i=0; + for(;i<10;i++){ + if(*str.style[i].str) + StockFontBufferExt(x+str.style[i].x,y,fontPrio,str.style[i].color, + str.style[i].str,hitFlag,str.style[i].size); + } +} + +extern int getTextLength(char * str); +void getTitlestyle(char *str,int pos,int flg,TITLE_STR* wm) +{ + char *stemp,*etemp; + if(flg) + stemp = str; + else + stemp = sunday(str, "[style "); + if(stemp){ + if(stemp!= str){ + wm->flg=TRUE; + wm->style[pos].size = FONT_SIZE1; + if(pos==0) + wm->style[pos].x = 0; + else + wm->style[pos].x = getTextLength(wm->style[pos-1].str)+wm->style[pos-1].x; + wm->style[pos].color = 0; + int len = stemp - str; + memcpy(wm->style[pos].str,str,len); + wm->style[pos].str[len]=NULL; + pos++; + getTitlestyle(stemp,pos,TRUE,wm); + }else{ + wm->flg=TRUE; + stemp=stemp+7; + etemp = sunday(stemp, "]")+1; + char *scolor = sunday(stemp, "c="); + if(scolor){ + scolor=scolor+2; + char strnum[3]; + int i=0; + for(i;i<2 && scolor[i] !=' ' && scolor[i]!=']';i++){ + strnum[i] = scolor[i]; + } + strnum[i]=0; + wm->style[pos].color = atoi(strnum); + }else wm->style[pos].color =0; + + char *ssize = sunday(stemp, "s="); + if(ssize){ + ssize=ssize+2; + char strsize[3]; + int i=0; + for(i;i<2 && ssize[i] !=' ' && ssize[i]!=']';i++){ + strsize[i] = ssize[i]; + } + strsize[i]=0; + wm->style[pos].size = atoi(ssize); + }else wm->style[pos].size = FONT_SIZE1; + + stemp = sunday(str,"[/style]"); + + int len = stemp - etemp; + memcpy(wm->style[pos].str,etemp,len); + wm->style[pos].str[len]=NULL; + if(pos==0) + wm->style[pos].x = 0; + else + wm->style[pos].x = getTextLength(wm->style[pos-1].str)+wm->style[pos-1].x; + pos++; + stemp = stemp + 8; + getTitlestyle(stemp,pos,FALSE,wm); + } + }else{ + sprintf(wm->style[pos].str,"%s",str); + if(!wm->flg){ + wm->flg=TRUE; + wm->style[pos].x = 0; + wm->style[pos].color = 0; + wm->style[pos].size = FONT_SIZE1; + wm->len = getTextLength(wm->style[pos].str); + }else{ + wm->style[pos].size = FONT_SIZE1; + wm->style[pos].x = getTextLength(wm->style[pos-1].str)+wm->style[pos-1].x; + wm->style[pos].color = 0; + wm->len = getTextLength(wm->style[pos].str)+wm->style[pos].x; + } + } +} + +void getCharTitleSplit( char *str,TITLE_STR* title) +{ + memset(title,0,sizeof(TITLE_STR)); + if (str == NULL) return; + int i=0; + for(i;i<25;i++){ + if(*str){ + getTitlestyle(str,0,FALSE,title); + } + } +} +#endif + + +void getStrSplitNew( char str[][256]) +{ + memset(wmstr,0,sizeof(WM_STR)*25); + int i=0; + + for(i;i<25;i++){ + if(str[i][0]){ + getstrstyle(str[i],i,0,FALSE,wmstr); + } + } +} + + +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/newproto/autil.h b/石器时代8.5客户端最新源代码/石器源码/newproto/autil.h new file mode 100644 index 0000000..7bb5597 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/newproto/autil.h @@ -0,0 +1,93 @@ +// Arminius' protocol utilities ver 0.1 +// +// Any questions and bugs, mailto: arminius@mail.hwaei.com.tw + +#ifndef __UTIL_H_ +#define __UTIL_H_ +#include "../systeminc/version.h" +#define SLICE_MAX 20 +#define SLICE_SIZE 65500 +extern char **MesgSlice; // store message slices +extern int SliceCount; // count slices in MesgSlice + +extern char PersonalKey[]; + +#define DEFAULTTABLE \ + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}" +#define DEFAULTFUNCBEGIN "&" +#define DEFAULTFUNCEND "#" + +void util_Init(void); +void util_Release(void); +void util_SplitMessage(char *source, char *separator); +void util_EncodeMessage(char *dst, char *src); +void util_DecodeMessage(char *dst, char *src); +int util_GetFunctionFromSlice(int *func, int *fieldcount); +void util_DiscardMessage(void); +void util_SendMesg(int fd, int func, char *buffer); + +// ------------------------------------------------------------------- +// Encoding function units. Use in Encrypting functions. +int util_256to64(char *dst, char *src, int len, char *table); +int util_64to256(char *dst, char *src, char *table); +int util_256to64_shr(char *dst, char *src, int len, char *table, char *key); +int util_shl_64to256(char *dst, char *src, char *table, char *key); +int util_256to64_shl(char *dst, char *src, int len, char *table, char *key); +int util_shr_64to256(char *dst, char *src, char *table, char *key); + +void util_swapint(int *dst, int *src, char *rule); +void util_xorstring(char *dst, char *src); +void util_shrstring(char *dst, char *src, int offs); +void util_shlstring(char *dst, char *src, int offs); +// ------------------------------------------------------------------- +// Encrypting functions +int util_deint(int sliceno, int *value); +int util_mkint(char *buffer, int value); +int util_destring(int sliceno, char *value); +int util_mkstring(char *buffer, char *value); + +#endif + + +int strcmptail( char *s1 , char *s2 ); +#ifndef _AUTIL_H_ +#define _AUTIL_H_ +#ifdef _FONT_STYLE_ +typedef struct +{ + int x; + int size; + int color; + char str[128]; +}WM_STR_STYLE; + +typedef struct +{ + int flg; + WM_STR_STYLE style[30]; +}WM_STR; + + +typedef struct +{ + int x; + int size; + int color; + char str[32]; +}TITLE_STR_STYLE; + +typedef struct +{ + int flg; + int len; + TITLE_STR_STYLE style[10]; +}TITLE_STR; +void getCharTitleSplit( char *str,TITLE_STR* title); +extern WM_STR wmstr[25]; +void getStrSplitNew( char str[][256]); +extern char* sunday( char* str, char* subStr); +void PutWinText(int x,int y,char fontPrio,int color,char *str,BOOL hitFlag,int index ); +#endif +#endif +BOOL getStringFromIndexWithDelim_body( char* src ,char* delim ,int index,char* buf , int buflen); + diff --git a/石器时代8.5客户端最新源代码/石器源码/newproto/protocol.cpp b/石器时代8.5客户端最新源代码/石器源码/newproto/protocol.cpp new file mode 100644 index 0000000..17d20cb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/newproto/protocol.cpp @@ -0,0 +1,2752 @@ +//#ifdef __NEW_PROTOCOL + +#include +#include +#include "../systeminc/version.h" +#include "autil.h" +#include "protocol.h" +#include "../systeminc/pc.h" +#include "../Wgs/message.h" +// WON FIX +#include +#include "../systeminc/field.h" +#include "../systeminc/chat.h" +#ifdef _MACADDRESSD +#include "../GetMacAddress.h" +#endif +#include "../systeminc/VMProtectSDK.h" + +void LogToRecvdata(char *data) +{ + return; +} + +void LogToSenddata(char *data) +{ + return; +} + +void ־(int id,char *data) +{ + printf("շ=%d %s\n",id,data); + FILE *fp = fopen( "fengbao.txt", "a+" ); + if( fp ) fprintf( fp, "շ=%d %s\n",id,data); + if( fp ) fclose( fp ); +} + +void ־1(int id) +{ + FILE *fp = fopen( "fengbao1.txt", "a+" ); + if( fp ) fprintf( fp, "շ=%d \n",id); + if( fp ) fclose( fp ); +} + +int SaDispatchMessage(int fd, char *encoded) +{ + char datalog[16384]; + int func,fieldcount; + int iChecksum = 0, iChecksumrecv; + char raw[16384]; + util_DecodeMessage(raw,encoded); + +#ifdef _STONDEBUG_ + FILE *fp = fopen( "recvtime.txt", "a+" ); + if( fp ) fprintf( fp, "%u RECV %d %s\n", TimeGetTime(), strlen(raw), raw); + if( fp ) fclose( fp ); +#endif + util_SplitMessage(raw,SEPARATOR); + + if (util_GetFunctionFromSlice(&func, &fieldcount)){ + + //־1(func); + + + + if (func==LSSPROTO_XYD_RECV) { + int x; + int y; + int dir; + + iChecksum += util_deint(2, &x); + iChecksum += util_deint(3, &y); + iChecksum += util_deint(4, &dir); + util_deint(5, &iChecksumrecv); + if (iChecksum != iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"x=%d y=%d dir=%d",x,y,dir); + ־(func,datalog); +#endif + lssproto_XYD_recv(fd, x, y, dir); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_EV_RECV) + { + int seqno; + int result; + + iChecksum += util_deint(2, &seqno); + iChecksum += util_deint(3, &result); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"seqno=%d result=%d",seqno,result); + ־(func,datalog); +#endif + lssproto_EV_recv(fd, seqno, result); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_EN_RECV) + { + int result; + int field; + + iChecksum += util_deint(2, &result); + iChecksum += util_deint(3, &field); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%d field=%d",result,field); + ־(func,datalog); +#endif + lssproto_EN_recv(fd, result, field); + + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_RS_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%s",data); + ־(func,datalog); +#endif + lssproto_RS_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_RD_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%s",data); + ־(func,datalog); +#endif + lssproto_RD_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_B_RECV) + { + char command[16384]; + + iChecksum += util_destring(2, command); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + ־(func,command); +#endif + LogToRecvdata( command ); + + lssproto_B_recv(fd, command); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_I_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%s",data); + ־(func,datalog); +#endif + lssproto_I_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_SI_RECV) + { + int fromindex; + int toindex; + + iChecksum += util_deint(2, &fromindex); + iChecksum += util_deint(3, &toindex); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"fromindex=%d toindex=%d",fromindex,toindex); + ־(func,datalog); +#endif + lssproto_SI_recv(fd, fromindex, toindex); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_MSG_RECV) + { + int aindex; + char text[16384]; + int color; + + iChecksum += util_deint(2, &aindex); + iChecksum += util_destring(3, text); + iChecksum += util_deint(4, &color); + util_deint(5, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"aindex=%d text=%s color=%d",aindex,text,color); + ־(func,datalog); +#endif + lssproto_MSG_recv(fd, aindex, text, color); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_PME_RECV) + { + int objindex; + int graphicsno; + int x; + int y; + int dir; + int flg; + int no; + char cdata[16384]; + + iChecksum += util_deint(2, &objindex); + iChecksum += util_deint(3, &graphicsno); + iChecksum += util_deint(4, &x); + iChecksum += util_deint(5, &y); + iChecksum += util_deint(6, &dir); + iChecksum += util_deint(7, &flg); + iChecksum += util_deint(8, &no); + iChecksum += util_destring(9, cdata); + util_deint(10, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"objindex=%d graphicsno=%d x=%d y=%d dir=%d flg=%d no=%d cdata=%s",objindex,graphicsno,x,y,dir,flg,no,cdata); + ־(func,datalog); +#endif + lssproto_PME_recv(fd, objindex, graphicsno, x, y, dir, flg, no, cdata); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_AB_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_AB_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_ABI_RECV) + { + int num; + char data[16384]; + + iChecksum += util_deint(2, &num); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"num=%d data=%s",num,data); + ־(func,datalog); +#endif + lssproto_ABI_recv(fd, num, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_TK_RECV) + { + int index; + char message[16384]; + int color; + + iChecksum += util_deint(2, &index); + iChecksum += util_destring(3, message); + iChecksum += util_deint(4, &color); + util_deint(5, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"index=%d message=%s color=%d",index,message,color); + ־(func,datalog); +#endif + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_WORLD)){ + if(strstr(message,"[]")){ + SliceCount=0; + return 0; + } + } + if(!(pc.etcFlag & PC_ETCFLAG_ALL_SERV)){ + if(strstr(message,"[]")){ + SliceCount=0; + return 0; + } + } + lssproto_TK_recv(fd, index, message, color); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_MC_RECV) + { + int fl; + int x1; + int y1; + int x2; + int y2; + int tilesum; + int objsum; + int eventsum; + char data[16384]; + + iChecksum += util_deint(2, &fl); + iChecksum += util_deint(3, &x1); + iChecksum += util_deint(4, &y1); + iChecksum += util_deint(5, &x2); + iChecksum += util_deint(6, &y2); + iChecksum += util_deint(7, &tilesum); + iChecksum += util_deint(8, &objsum); + iChecksum += util_deint(9, &eventsum); + iChecksum += util_destring(10, data); + util_deint(11, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"fl=%d x1=%d y1=%d x2=%d y2=%d tilesum=%d objsum=%d eventsum=%d data=%s",fl,x1,y1,x2,y2,tilesum, + objsum,eventsum,data); + ־(func,datalog); +#endif +#ifdef __SKYISLAND + extern void SkyIslandSetNo( int fl); + SkyIslandSetNo( fl); +#endif + + LogToRecvdata(data); + + lssproto_MC_recv(fd, fl, x1, y1, x2, y2, tilesum, objsum, eventsum, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_M_RECV) + { + int fl; + int x1; + int y1; + int x2; + int y2; + char data[16384]; + + iChecksum += util_deint(2, &fl); + iChecksum += util_deint(3, &x1); + iChecksum += util_deint(4, &y1); + iChecksum += util_deint(5, &x2); + iChecksum += util_deint(6, &y2); + iChecksum += util_destring(7, data); + util_deint(8, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } + + LogToRecvdata(data); +#ifdef _STONDEBUG__PACKET_ + char datalog[26384]; + sprintf_s(datalog,"fl=%d x1=%d y1=%d x2=%d y2=%d data=%s",fl,x1,y1,x2,y2,data); + ־(func,datalog); +#endif + lssproto_M_recv(fd, fl, x1, y1, x2, y2, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_C_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_C_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CA_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_CA_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CD_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_CD_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_R_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_R_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_S_RECV) + { + char data[16384]; + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_S_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_D_RECV) + { + int category; + int dx; + int dy; + char data[16384]; + + iChecksum += util_deint(2, &category); + iChecksum += util_deint(3, &dx); + iChecksum += util_deint(4, &dy); + iChecksum += util_destring(5, data); + util_deint(6, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"category=%d dx=%d dy=%d data=%s",category,dx,dy,data); + ־(func,datalog); +#endif + lssproto_D_recv(fd, category, dx, dy, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_FS_RECV) + { + int flg; + + iChecksum += util_deint(2, &flg); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"flg=%d",flg); + ־(func,datalog); +#endif + lssproto_FS_recv(fd, flg); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_HL_RECV) + { + int flg; + + iChecksum += util_deint(2, &flg); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"flg=%d",flg); + ־(func,datalog); +#endif + lssproto_HL_recv(fd, flg); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_PR_RECV) + { + int request; + int result; + + iChecksum += util_deint(2, &request); + iChecksum += util_deint(3, &result); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"request=%d result=%d",request, result); + ־(func,datalog); +#endif + lssproto_PR_recv(fd, request, result); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_KS_RECV) + { + int petarray; + int result; + + iChecksum += util_deint(2, &petarray); + iChecksum += util_deint(3, &result); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"petarray=%d result=%d",petarray, result); + ־(func,datalog); +#endif + lssproto_KS_recv(fd, petarray, result); + SliceCount=0; + return 0; + } +#ifdef _STANDBYPET + else if (func==LSSPROTO_SPET_RECV) + { + int standbypet; + int result; + + iChecksum += util_deint(2, &standbypet); + iChecksum += util_deint(3, &result); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"standbypet=%d result=%d",standbypet, result); + ־(func,datalog); +#endif + lssproto_SPET_recv(fd, standbypet, result); + SliceCount=0; + return 0; + } +#endif + +#ifdef _PETS_SELECTCON + else if (func==LSSPROTO_PETST_RECV) + { + int petarray; + int result; + + iChecksum += util_deint(2, &petarray); + iChecksum += util_deint(3, &result); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"petarray=%d result=%d",petarray, result); + ־(func,datalog); +#endif + lssproto_PETST_recv(fd, petarray, result); + SliceCount=0; + return 0; + } +#endif + else if (func==LSSPROTO_PS_RECV) + { + int result; + int havepetindex; + int havepetskill; + int toindex; + + iChecksum += util_deint(2, &result); + iChecksum += util_deint(3, &havepetindex); + iChecksum += util_deint(4, &havepetskill); + iChecksum += util_deint(5, &toindex); + util_deint(6, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%d havepetindex=%d havepetskill=%d toindex=%d",result, havepetindex,havepetskill,toindex); + ־(func,datalog); +#endif + lssproto_PS_recv(fd, result, havepetindex, havepetskill, toindex); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_SKUP_RECV) + { + int point; + + iChecksum += util_deint(2, &point); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%d",point); + ־(func,datalog); +#endif + lssproto_SKUP_recv(fd, point); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_WN_RECV) + { + int windowtype; + int buttontype; + int seqno; + int objindex; + char data[16384]; + + iChecksum += util_deint(2, &windowtype); + iChecksum += util_deint(3, &buttontype); + iChecksum += util_deint(4, &seqno); + iChecksum += util_deint(5, &objindex); + iChecksum += util_destring(6, data); + util_deint(7, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + char datalog[10420]; + sprintf_s(datalog,"windowtype=%d buttontype=%d seqno=%d objindex=%d data=%s",windowtype, buttontype,seqno,objindex,data); + ־(func,datalog); +#endif + lssproto_WN_recv(fd, windowtype, buttontype, seqno, objindex, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_EF_RECV) + { + int effect; + int level; + char option[16384]; + + iChecksum += util_deint(2, &effect); + iChecksum += util_deint(3, &level); + iChecksum += util_destring(4, option); + util_deint(5, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"effect=%d level=%d option=%s",effect,level,option); + ־(func,datalog); +#endif + lssproto_EF_recv(fd, effect, level, option); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_SE_RECV) + { + int x; + int y; + int senumber; + int sw; + + iChecksum += util_deint(2, &x); + iChecksum += util_deint(3, &y); + iChecksum += util_deint(4, &senumber); + iChecksum += util_deint(5, &sw); + util_deint(6, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"x=%d y=%d senumber=%d sw=%d",x,y,senumber,sw); + ־(func,datalog); +#endif + lssproto_SE_recv(fd, x, y, senumber, sw); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CLIENTLOGIN_RECV) + { + char result[16384]; + + iChecksum += util_destring(2, result); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s",result); + ־(func,datalog); +#endif + lssproto_ClientLogin_recv(fd, result); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CREATENEWCHAR_RECV) + { + char result[16384]; + char data[16384]; + + iChecksum += util_destring(2, result); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s data=%s",result,data); + ־(func,datalog); +#endif + lssproto_CreateNewChar_recv(fd, result, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CHARDELETE_RECV) + { + char result[16384]; + char data[16384]; + + iChecksum += util_destring(2, result); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s data=%s",result,data); + ־(func,datalog); +#endif + lssproto_CharDelete_recv(fd, result, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CHARLOGIN_RECV) + { + char result[16384]; + char data[16384]; + + iChecksum += util_destring(2, result); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s data=%s",result,data); + ־(func,datalog); +#endif + lssproto_CharLogin_recv(fd, result, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CHARLIST_RECV) + { + char result[16384]; + char data[16384]; + + iChecksum += util_destring(2, result); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s data=%s",result,data); + ־(func,datalog); +#endif + lssproto_CharList_recv(fd, result, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_CHARLOGOUT_RECV) + { + char result[16384]; + char data[16384]; + + iChecksum += util_destring(2, result); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"result=%s data=%s",result,data); + ־(func,datalog); +#endif + lssproto_CharLogout_recv(fd, result, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_PROCGET_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_ProcGet_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_PLAYERNUMGET_RECV) + { + int logincount; + int player; + + iChecksum += util_deint(2, &logincount); + iChecksum += util_deint(3, &player); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"logincount=%d player=%d",logincount,player); + ־(func,datalog); +#endif + lssproto_PlayerNumGet_recv(fd, logincount, player); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_ECHO_RECV) + { + char test[16384]; + + iChecksum += util_destring(2, test); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"test=%d",test); + ־(func,datalog); +#endif + lssproto_Echo_recv(fd, test); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_NU_RECV) + { + int AddCount; + + iChecksum += util_deint(2, &AddCount); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%d",AddCount); + ־(func,datalog); +#endif + lssproto_NU_recv(fd, AddCount); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_TD_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_TD_recv(fd, data); + SliceCount=0; + return 0; + } + else if (func==LSSPROTO_FM_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + LogToRecvdata( data ); + + lssproto_FM_recv(fd, data); + SliceCount=0; + return 0; + } + +#ifdef _ITEM_CRACKER + else if(func==LSSPROTO_IC_RECV) + { + int x, y; + iChecksum += util_deint( 2, &x); + iChecksum += util_deint( 3, &y); + util_deint( 4, &iChecksumrecv); + if(iChecksum!=iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"x=%d y=%d",x,y); + ־(func,datalog); +#endif + lssproto_IC_recv(fd, x, y); + SliceCount=0; + return 0; + } +#endif +#ifdef _CHECK_GAMESPEED + else if ( func == LSSPROTO_CS_RECV ) + { + int deltimes=0; + iChecksum += util_deint(2, &deltimes); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"deltimes=%d",deltimes); + ־(func,datalog); +#endif + lssproto_CS_recv(fd, deltimes); + SliceCount=0; + return 0; + } +#endif + +#ifdef _MAGIC_NOCAST//Ĭ + else if (func==LSSPROTO_NC_RECV) + { + int flg; + + iChecksum += util_deint(2, &flg); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"%d",flg); + ־(func,datalog); +#endif + + lssproto_NC_recv(fd, flg); + SliceCount=0; + return 0; + } +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ + else if ( func == LSSPROTO_CHATROOM_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_CHATROOM_recv(fd, data); + SliceCount=0; + return 0; + } +#endif +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ + else if ( func == LSSPROTO_RESIST_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_RESIST_recv(fd, data); + SliceCount=0; + return 0; + } +#endif + +#ifdef _ALCHEPLUS + else if ( func == LSSPROTO_ALCHEPLUS_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } + +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_ALCHEPLUS_recv(fd, data); + SliceCount=0; + return 0; + } +#endif + else if ( func == LSSPROTO_CHAREFFECT_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } + +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_CHAREFFECT_recv(fd, data); + SliceCount=0; + return 0; + } + +#ifdef _RED_MEMOY_ + else if ( func == LSSPROTO_REDMEMOY_RECV ) + { + int type,time,vip,index; + char name[128]; + + iChecksum += util_deint(2, &type); + iChecksum += util_deint(3, &time); + iChecksum += util_deint(4, &vip); + iChecksum += util_destring(5, name); + iChecksum += util_deint(6, &index); + util_deint(7, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } + extern void RedMemoySetup(int type,int time,int vip,char *name,int index); + RedMemoySetup(type,time,vip,name,index); + SliceCount=0; + return 0; + } +#endif + +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + else if ( func == LSSPROTO_BATTLESKILL_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } + +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_BATTLESKILL_recv(fd, data); + SliceCount=0; + return 0; + } +#endif + else if( func==LSSPROTO_WO_RECV) + { + int effect; + + iChecksum += util_deint(2, &effect); + util_deint(3, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"effect=%d",effect); + ־(func,datalog); +#endif + lssproto_WO_recv( fd, effect ); + SliceCount=0; + return 0; + } +#ifdef _STREET_VENDOR + else if (func == LSSPROTO_STREET_VENDOR_RECV) + { + char data[16384]; + + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_STREET_VENDOR_recv(fd,data); + SliceCount=0; + return 0; + } +#endif +#ifdef _SECONDARY_WINDOW_DATA_ + else if (func == LSSPROTO_SECONDARY_WINDOW_RECV) + { + char data[16384]; + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + extern char [1024]; + memset(,0,1024); + sprintf(,"%s",data); + SliceCount=0; + return 0; + } +#endif +#ifdef _ICONBUTTONS_ + else if (func == LSSPROTO_TRUNTABLE_RECV) + { + char data[16384]; + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + if(data[0]=='A'){ + extern void ת(int ѡ); + ת(atoi(data+1)); + } +#ifdef _CHARSIGNDAY_ + if(data[0]=='C'){ + extern void ǩ״̬(int ״̬); + ǩ״̬(atoi(data+1)); + } +#endif + SliceCount=0; + return 0; + } +#endif + + +#ifdef _FAMILYBADGE_ + else if (func == LSSPROTO_FAMILYBADGE_RECV) + { + char data[16384]; + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_FamilyBadge_recv(data); + SliceCount=0; + return 0; + } +#endif +#ifdef _JOBDAILY + else if (func == LSSPROTO_JOBDAILY_RECV) + { + char data[16384]; + + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_JOBDAILY_recv(fd,data); + SliceCount=0; + return 0; + } +#endif +#ifdef _TEACHER_SYSTEM + else if (func == LSSPROTO_TEACHER_SYSTEM_RECV) + { + char data[16384]; + + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_TEACHER_SYSTEM_recv(fd,data); + SliceCount=0; + return 0; + } +#endif +#ifdef _ADD_STATUS_2 + else if (func == LSSPROTO_S2_RECV) + { + char data[16384]; + + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + LogToRecvdata(data); + lssproto_S2_recv(fd,data); + SliceCount = 0; + return 0; + } +#endif +#ifdef _ITEM_FIREWORK + else if (func == LSSPROTO_FIREWORK_RECV) + { + int iChecksum = 0, iChecksumrecv, iCharaindex, iType, iActionNum; + char szData[16384]; + + iChecksum += util_deint(2, &iCharaindex); + iChecksum += util_deint(3, &iType); + iChecksum += util_deint(4, &iActionNum); + util_deint(5, &iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount = 0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"iCharaindex=%d iType=%d iActionNum=%d",iCharaindex,iType,iActionNum); + ־(func,datalog); +#endif + LogToRecvdata(szData); + lssproto_Firework_recv(fd, iCharaindex, iType, iActionNum); + SliceCount = 0; + return 0; + } +#endif +#ifdef _MOVE_SCREEN + else if (func == LSSPROTO_MOVE_SCREEN_RECV) + { + int iXY; + BOOL bMoveScreenMode; + char szData[16384]; + + iChecksum += util_deint(2, &bMoveScreenMode); + iChecksum += util_deint(3, &iXY); + util_deint(4, &iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount = 0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"bMoveScreenMode=%d iXY=%d",bMoveScreenMode,iXY); + ־(func,datalog); +#endif + LogToRecvdata(szData); + lssproto_MoveScreen_recv(fd, bMoveScreenMode, iXY); + SliceCount = 0; + return 0; + } +#endif +#ifdef _THEATER + else if (func == LSSPROTO_THEATER_DATA_RECV) + { + char data[16384]; + + iChecksum += util_destring(2, data); + util_deint(3, &iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } + LogToRecvdata(data); +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_TheaterData_recv(fd, data); + SliceCount = 0; + return 0; + } +#endif +#ifdef _GET_HOSTNAME + else if( func == LSSPROTO_HOSTNAME_RECV ) + { + int hostnametamp; + + iChecksum += util_deint(2, &hostnametamp); + util_deint(3, &iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount = 0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"hostnametamp=%d",hostnametamp); + ־(func,datalog); +#endif + lssproto_HostName_send(fd); + SliceCount = 0; + return 0; + } +#endif +#ifdef _NPC_MAGICCARD + else if( func == LSSPROTO_MAGICCARD_ACTION_RECV ) + { + char data[16384]; + + iChecksum += util_destring(2,data); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"data=%s",data); + ־(func,datalog); +#endif + lssproto_MagiccardAction_recv(fd, data); + SliceCount = 0; + return 0; + } + else if( func == LSSPROTO_MAGICCARD_DAMAGE_RECV ) + { + //char data[16384]; + int position,damage,offsetx,offsety; + + iChecksum += util_deint(2,&position); + iChecksum += util_deint(3, &damage); + iChecksum += util_deint(4, &offsetx); + iChecksum += util_deint(5, &offsety); + + util_deint(6,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"position=%d damage=%d offsetx=%d offsety=%d",position,damage,offsetx,offsety); + ־(func,datalog); +#endif + lssproto_MagiccardDamage_recv(fd,position,damage,offsetx,offsety); + SliceCount = 0; + return 0; + } +#endif +#ifdef _NPC_DANCE + else if( func == LSSPROTO_DANCEMAN_OPTION_RECV ) + { + int option; + + iChecksum += util_deint(2, &option); + + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"option=%d",option); + ־(func,datalog); +#endif + lssproto_DancemanOption_recv(fd,option); + SliceCount = 0; + return 0; + } +#endif +#ifdef _HUNDRED_KILL + else if( func == LSSPROTO_HUNDREDKILL_RECV ) + { + int flag; + + iChecksum += util_deint(2, &flag); + + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"flag=%d",flag); + ־(func,datalog); +#endif + lssproto_hundredkill_recv(fd,flag); + SliceCount = 0; + return 0; + } +#endif +#ifdef _PK2007 + else if( func == LSSPROTO_PKLIST_RECV ) + { + int count; + char data[16384]; + iChecksum += util_deint(2, &count); + iChecksum += util_destring(3, data); + util_deint(4, &iChecksumrecv); + if (iChecksum!=iChecksumrecv) { + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"count=%d data=%s",count,data); + ־(func,datalog); +#endif + lssproto_pkList_recv(fd, count, data); + SliceCount=0; + return 0; + } +#endif +#ifdef _NEWSHOP_ + else if( func == LSSPROTO_SHOPOK_RECV ) + { + int a; + extern unsigned int sockfd; + iChecksum += util_deint(2,&a); + util_deint(3,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"a=%d",a); + ־(func,datalog); +#endif + int checksum=0; + char buf[1024*4*4]; + memset(buf,0,1024*4*4); + checksum +=util_mkint(buf, 0); + util_mkint(buf, checksum); + util_SendMesg(sockfd, LSSPROTO_SHOPOK_SEND, buf); + SliceCount = 0; + return 0; + } +#endif + else if( func == LSSPROTO_SAMENU_RECV ) + { + int count; + char data[16384]; + iChecksum += util_deint(2, &count); + iChecksum += util_destring(3, data); + util_deint(4,&iChecksumrecv); + if(iChecksum != iChecksumrecv){ + SliceCount=0; + return 1; + } +#ifdef _STONDEBUG__PACKET_ + + sprintf_s(datalog,"count=%d data=%s",count,data); + ־(func,datalog); +#endif + ShellExecute(NULL,"open",data,NULL,NULL,SW_SHOWNORMAL); + SliceCount = 0; + return 0; + } +#ifdef _ANNOUNCEMENT_ + else if( func == LSSPROTO_DENGON_RECV ) + { + char data[512]; + int coloer; + int num; + + util_destring(2, data); + util_deint(3, &coloer); + util_deint(4, &num); + lssproto_DENGON_recv(data, coloer, num); + SliceCount = 0; + return 0; + } +#endif +#ifdef _CHARTITLE_ + else if( func == LSSPROTO_CHARTITLE_RECV ) + { + int checksum=0, checksumrecv; + char token[10200]={0}; + checksum +=util_destring(2,token); + util_deint(3,&checksumrecv); + if(checksum != checksumrecv){ + SliceCount=0; + return 1; + } + extern void ƺݸ(char *); + ƺݸ(token); + SliceCount = 0; + return 0; + } +#endif +#ifdef _CHARTITLE_STR_ + else if( func == LSSPROTO_CHARTITLE_RECV ) + { + int checksum=0, checksumrecv; + char token[10200]={0}; + checksum +=util_destring(2,token); + util_deint(3,&checksumrecv); + if(checksum != checksumrecv){ + SliceCount=0; + return 1; + } + extern void ƺݸ(char *); + ƺݸ(token); + SliceCount = 0; + return 0; + } +#endif + + +#ifdef _PET_SKINS + else if (func == LSSPROTO_PETSKINS_RECV) + { + int checksum = 0, checksumrecv; + char token[10200] = { 0 }; + checksum += util_destring(2, token); + util_deint(3, &checksumrecv); + if (checksum != checksumrecv){ + SliceCount = 0; + return 1; + } + lssproto_PetSkins_recv(token); + SliceCount = 0; + return 0; + } +#endif + +#ifdef _PETBLESS_ + else if( func == LSSPROTO_VB_RECV ){ + int checksum=0, checksumrecv; + char token[10200]={0}; + checksum +=util_destring(2,token); + util_deint(3,&checksumrecv); + if(checksum != checksumrecv){ + SliceCount=0; + return 1; + } + extern char ף[128]; + sprintf(ף,"%s",token); + SliceCount = 0; + return 0; + } +#endif + SliceCount=0; + } + return 1; +} + +void lssproto_W_send(int fd,int x,int y,char* direction) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkstring(buffer, direction); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_W2_SEND, buffer); +} + +void lssproto_W2_send(int fd,int x,int y,char* direction) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkstring(buffer, direction); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_W2_SEND, buffer); +} + +void lssproto_EV_send(int fd,int event,int seqno,int x,int y,int dir) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, event); + iChecksum += util_mkint(buffer, seqno); + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, dir); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_EV_SEND, buffer); +} + +void lssproto_EN_send(int fd,int x,int y) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_EN_SEND, buffer); +} + +void lssproto_DU_send(int fd,int x,int y) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DU_SEND, buffer); +} + +void lssproto_EO_send(int fd,int dummy) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, dummy); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_EO_SEND, buffer); +} + +void lssproto_BU_send(int fd,int dummy) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, dummy); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_BU_SEND, buffer); +} + +void lssproto_JB_send(int fd,int x,int y) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_JB_SEND, buffer); +} + +void lssproto_LB_send(int fd,int x,int y) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_LB_SEND, buffer); +} + +void lssproto_B_send(int fd,char* command) +{ + char buffer[16384]; + int iChecksum=0; + + LogToSenddata( command ); + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, command); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_B_SEND, buffer); +} + +void lssproto_SKD_send(int fd,int dir,int index) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, dir); + iChecksum += util_mkint(buffer, index); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_SKD_SEND, buffer); +} + +void lssproto_ID_send(int fd,int x,int y,int haveitemindex,int toindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, haveitemindex); + iChecksum += util_mkint(buffer, toindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_ID_SEND, buffer); +} + +void lssproto_PI_send(int fd,int x,int y,int dir) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, dir); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PI_SEND, buffer); +} + +void lssproto_DI_send(int fd,int x,int y,int itemindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, itemindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DI_SEND, buffer); +} + +void lssproto_DG_send(int fd,int x,int y,int amount) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, amount); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DG_SEND, buffer); +} + +void lssproto_DP_send(int fd,int x,int y,int petindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, petindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DP_SEND, buffer); +} + +void lssproto_MI_send(int fd,int fromindex,int toindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, fromindex); + iChecksum += util_mkint(buffer, toindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_MI_SEND, buffer); +} + +void lssproto_MSG_send(int fd,int index,char* message,int color) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, index); + iChecksum += util_mkstring(buffer, message); + iChecksum += util_mkint(buffer, color); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_MSG_SEND, buffer); +} + +void lssproto_PMSG_send(int fd,int index,int petindex,int itemindex,char* message,int color) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, index); + iChecksum += util_mkint(buffer, petindex); + iChecksum += util_mkint(buffer, itemindex); + iChecksum += util_mkstring(buffer, message); + iChecksum += util_mkint(buffer, color); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PMSG_SEND, buffer); +} + +#ifdef _TEAM_KICKPARTY +void lssproto_KTEAM_send( int fd,int si) +{ + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, si); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_KTEAM_SEND, buffer); +} +#endif + +void lssproto_AB_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_AB_SEND, buffer); +} + +void lssproto_DAB_send(int fd,int index) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, index); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DAB_SEND, buffer); +} + +void lssproto_AAB_send(int fd,int x,int y) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_AAB_SEND, buffer); +} + +void lssproto_L_send(int fd,int dir) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, dir); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_L_SEND, buffer); +} + +void lssproto_TK_send(int fd,int x,int y,char* message,int color,int area) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkstring(buffer, message); + iChecksum += util_mkint(buffer, color); + iChecksum += util_mkint(buffer, area); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_TK_SEND, buffer); +} + +void lssproto_M_send(int fd,int fl,int x1,int y1,int x2,int y2) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, fl); + iChecksum += util_mkint(buffer, x1); + iChecksum += util_mkint(buffer, y1); + iChecksum += util_mkint(buffer, x2); + iChecksum += util_mkint(buffer, y2); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_M_SEND, buffer); +} + +void lssproto_C_send(int fd,int index) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, index); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_C_SEND, buffer); +} + +void lssproto_S_send(int fd,char* category) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, category); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_S_SEND, buffer); +} + +void lssproto_FS_send(int fd,int flg) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, flg); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_FS_SEND, buffer); +} + +void lssproto_HL_send(int fd,int flg) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, flg); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_HL_SEND, buffer); +} + +void lssproto_PR_send(int fd,int x,int y,int request) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, request); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PR_SEND, buffer); +} + +void lssproto_KS_send(int fd,int petarray) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, petarray); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_KS_SEND, buffer); +} + +#ifdef _STANDBYPET +void lssproto_SPET_send(int fd, int standbypet) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, standbypet); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_SPET_SEND, buffer); +} +#endif + +void lssproto_AC_send(int fd,int x,int y,int actionno) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, actionno); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_AC_SEND, buffer); +} + +void lssproto_MU_send(int fd,int x,int y,int array,int toindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, array); + iChecksum += util_mkint(buffer, toindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_MU_SEND, buffer); +} + +void lssproto_PS_send(int fd,int havepetindex,int havepetskill,int toindex,char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, havepetindex); + iChecksum += util_mkint(buffer, havepetskill); + iChecksum += util_mkint(buffer, toindex); + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PS_SEND, buffer); +} + +void lssproto_ST_send(int fd,int titleindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, titleindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_ST_SEND, buffer); +} + +void lssproto_DT_send(int fd,int titleindex) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, titleindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_DT_SEND, buffer); +} + +void lssproto_FT_send(int fd,char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_FT_SEND, buffer); +} + +void lssproto_SKUP_send(int fd,int skillid) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, skillid); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_SKUP_SEND, buffer); +} + +void lssproto_KN_send(int fd,int havepetindex,char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, havepetindex); + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_KN_SEND, buffer); +} + +void lssproto_WN_send(int fd,int x,int y,int seqno,int objindex,int select,char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, seqno); + iChecksum += util_mkint(buffer, objindex); + iChecksum += util_mkint(buffer, select); + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_WN_SEND, buffer); +} + +void lssproto_SP_send(int fd,int x,int y,int dir) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + iChecksum += util_mkint(buffer, dir); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_SP_SEND, buffer); +} +#ifdef _NEW_CLIENT_LOGIN +void lssproto_ClientLogin_send(int fd,char* cdkey,char* passwd,char* mac,int selectServerIndex, char *ip) +#else +void lssproto_ClientLogin_send(int fd,char* cdkey,char* passwd) +#endif +{ + char buffer[16384]; + int iChecksum=0; +#ifdef _CHARTITLE_ + extern void ʼƺŽṹ(); + ʼƺŽṹ(); +#endif +#ifdef _CHARTITLE_STR_ + extern void ʼƺŽṹ(); + ʼƺŽṹ(); +#endif +#ifdef _RED_MEMOY_ + extern void RedMemoyInit(); + RedMemoyInit(); +#endif + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, cdkey); + iChecksum += util_mkstring(buffer, passwd); +#ifdef _NEW_CLIENT_LOGIN + iChecksum += util_mkstring(buffer, mac); + iChecksum += util_mkint(buffer, selectServerIndex); + iChecksum += util_mkstring(buffer, ip); +#endif + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CLIENTLOGIN_SEND, buffer); + +} + +void lssproto_CreateNewChar_send(int fd,int dataplacenum,char* charname,int imgno,int faceimgno,int vital,int str,int tgh,int dex,int earth,int water,int fire,int wind,int hometown) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, dataplacenum); + iChecksum += util_mkstring(buffer, charname); + iChecksum += util_mkint(buffer, imgno); + iChecksum += util_mkint(buffer, faceimgno); + iChecksum += util_mkint(buffer, vital); + iChecksum += util_mkint(buffer, str); + iChecksum += util_mkint(buffer, tgh); + iChecksum += util_mkint(buffer, dex); + iChecksum += util_mkint(buffer, earth); + iChecksum += util_mkint(buffer, water); + iChecksum += util_mkint(buffer, fire); + iChecksum += util_mkint(buffer, wind); + iChecksum += util_mkint(buffer, hometown); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CREATENEWCHAR_SEND, buffer); +} +extern STR_BUFFER passwd; +void lssproto_CharDelete_send(int fd,char* charname) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, charname); + iChecksum += util_mkstring(buffer, passwd.buffer); + util_mkint(buffer, iChecksum); + passwd.cnt = 0; + passwd.cursor=0; + ZeroMemory(passwd.buffer,sizeof(passwd.buffer)); + util_SendMesg(fd, LSSPROTO_CHARDELETE_SEND, buffer); +} + +void lssproto_CharLogin_send(int fd,char* charname) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, charname); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CHARLOGIN_SEND, buffer); +} + +void lssproto_CharList_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CHARLIST_SEND, buffer); +} +#ifdef _PK2007 +void lssproto_pkList_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PKLIST_SEND, buffer); +} +#endif +void lssproto_CharLogout_send(int fd, int Flg) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; +#ifdef _CHAR_NEWLOGOUT + iChecksum += util_mkint( buffer, Flg); +#endif + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CHARLOGOUT_SEND, buffer); +} + +void lssproto_ProcGet_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PROCGET_SEND, buffer); +} + +void lssproto_PlayerNumGet_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PLAYERNUMGET_SEND, buffer); +} + +void lssproto_Echo_send(int fd,char* test) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, test); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_ECHO_SEND, buffer); +} + +void lssproto_Shutdown_send(int fd,char* passwd,int min) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, passwd); + iChecksum += util_mkint(buffer, min); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_SHUTDOWN_SEND, buffer); +} + +void lssproto_TD_send(int fd, char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_TD_SEND, buffer); +} +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +void lssproto_CHATROOM_send ( int fd , char* data ) +{ + char buffer[16384] = {0}; + int iChecksum=0; + + // WON FIX ֹ̫Ƶ + if( data[0] == 'B' ){ + unsigned int now_time = (unsigned int)time(NULL); + static unsigned int old_time = 0; + + if( now_time < old_time ){ + SelRoomBtn = 1; + return; + } + old_time = now_time + 2; // delay 2 + } + + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_CHATROOM_SEND, buffer); +} +#endif + +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +void lssproto_RESIST_send ( int fd , char* data ) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_RESIST_SEND, buffer); +} +#endif + +#ifdef _ALCHEPLUS +void lssproto_ALCHEPLUS_send ( int fd , char* data ) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_ALCHEPLUS_SEND, buffer); +} +#endif + +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +void lssproto_BATTLESKILL_send (int fd, int SkillNum ) +{ + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, SkillNum); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_BATTLESKILL_SEND, buffer); +} +#endif +// Robin 05/25 +void lssproto_FM_send(int fd, char* data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_FM_SEND, buffer); +} + +// shan 2002/01/10 +void lssproto_PETST_send(int fd, int nPet, int sPet)// sPet 0:Ϣ 1:ȴ 4:ʼ +{ + //cary + if( dwServer == GS){ + char buffer[16384]; + int iChecksum=0; + memset(buffer,0,16384); + iChecksum += util_mkint(buffer, nPet); + iChecksum += util_mkint(buffer, sPet); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PETST_SEND, buffer); + } +} +//#endif + +#ifdef _FIX_DEL_MAP // WON ADD ҳͼͼ +void lssproto_DM_send(int fd) +{ + char buffer[2]; + buffer[0] = '\0'; + util_SendMesg(fd, LSSPROTO_DM_SEND, buffer); +} +#endif + +#ifdef _CHECK_GAMESPEED +void lssproto_CS_send( int fd) +{ + char buffer[2]; + buffer[0] = '\0'; + util_SendMesg(fd, LSSPROTO_CS_SEND, buffer); +} +#endif + +void lssproto_BM_send(int fd, int iindex) +{ +#ifdef _BLACK_MARKET + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, iindex); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_BM_SEND, buffer); +#endif +} + +#ifdef _MIND_ICON +void lssproto_MA_send(int fd, int x, int y, int nMind) +{ + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, nMind); + iChecksum += util_mkint(buffer, x); + iChecksum += util_mkint(buffer, y); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_MA_SEND, buffer); +} +#endif + +#ifdef _STREET_VENDOR +void lssproto_STREET_VENDOR_send(int fd,char *data) +{ + char buffer[16384]; + int iChecksum = 0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer,iChecksum); + util_SendMesg(fd,LSSPROTO_STREET_VENDOR_SEND,buffer); +} +#endif + +#ifdef _JOBDAILY +void lssproto_JOBDAILY_send(int fd,char *data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer, data); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_JOBDAILY_SEND, buffer); +} +#endif +#ifdef _FAMILYBADGE_ +void lssproto_FamilyBadge_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkint(buffer, 1); + util_mkint(buffer, iChecksum); + util_SendMesg(fd, LSSPROTO_FAMILYBADGE_SEND, buffer); +} + +#endif +#ifdef _TEACHER_SYSTEM +void lssproto_TEACHER_SYSTEM_send(int fd,char *data) +{ + char buffer[16384]; + int iChecksum=0; + + buffer[0] = '\0'; + iChecksum += util_mkstring(buffer,data); + util_mkint(buffer,iChecksum); + util_SendMesg(fd,LSSPROTO_TEACHER_SYSTEM_SEND,buffer); +} +#endif +#ifdef _PET_ITEM +// װ +void lssproto_PetItemEquip_send(int fd, int iGx, int iGy, int iPetNo, int iItemNo, int iDestNO) +{ + char szBuffer[16384]; + int iChecksum=0; + + szBuffer[0] = '\0'; + iChecksum += util_mkint(szBuffer, iGx); + iChecksum += util_mkint(szBuffer, iGy); + iChecksum += util_mkint(szBuffer, iPetNo); + iChecksum += util_mkint(szBuffer, iItemNo); + iChecksum += util_mkint(szBuffer, iDestNO); + util_mkint(szBuffer, iChecksum); + util_SendMesg(fd, LSSPROTO_PET_ITEM_EQUIP_SEND, szBuffer); +} +#endif +#ifdef _GET_HOSTNAME +void lssproto_HostName_send(int fd) +{ + char buffer[16384]; + int iChecksum=0; + buffer[0] = '\0'; + char MyName[255]; + gethostname(MyName,255); +#ifdef _MACADDRESSD + MAC_ADDR addrlist[3]; + memset(&addrlist,0,sizeof(addrlist)); + int macnum=GetMACaddress(addrlist,3); + char MACNUM[16]=""; + sprintf_s(MACNUM,"%2X%2X%2X%2X%2X%2X",addrlist[0].addr[0],addrlist[0].addr[1],addrlist[0].addr[2],addrlist[0].addr[3],addrlist[0].addr[4],addrlist[0].addr[5]); + for(i=0;i<(int)strlen(MACNUM);i++){ + if( MACNUM[i] == ' ' ) + MACNUM[i] = '0'; + MACNUM[i] ^= 0xff;// + } + //for(i=0;i +#include "../systeminc/version.h" +extern int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); +extern BOOL g_bUseAlpha; + +// Robin 0804 ride Pet +extern BOOL bNewServer; + +void petfallChangeGraph(ACTION *a0); +#ifdef _PETSKILL_RIDE +void petrideChangeGraph(ACTION *a0,int ridebmp); +#endif +void LogToBattleError(char *data, int line); +void katino(ACTION *a0); +static int command_point; +extern ACTION *MakeAnimDisp(int x, int y, int sprNo, int mode); +#ifdef _SYUTEST +static ACTION *Light1; +#endif +#ifdef _PETSKILL_LER +extern BOOL g_bUseAlpha; +#endif + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 +//⴦ +int ShooterNum = -1; +/* +int nuty[20] = { 384 , 408 , 360 , 432 , 336 , 312 , 360 , 264 , 408 , 216 , 150 , 174 , +126 , 198 , 102 , 202 , 250 , 154 , 298 , 106 } ; +*/ +#endif + +#ifdef _MAGIC_NOCAST//Ĭ +extern BOOL NoCastFlag; +#endif +//ACTION *set_bg( void ); +ACTION *oft_test(void); +//ACTION *set_teki( void ); +//void teki( ACTION *pAct ); +void monster(ACTION *a0); +static int get_num(void); + +/* ??????? ****************************************************/ +#define HIT_STOP_TIM 8 +#define VCT_NO_DIE 250 +#define VCT_NO_APPEAR VCT_NO_DIE - 1 +#ifdef __NEW_BATTLE_EFFECT +//#define VCT_NO_PAUSE 254 +#define VCT_NO_EFFECT 255 +#endif +#define SCREEN_OUT 106 +#define ATTACK_MAGIC_CASE 200 +#define TOCALL_MAGIC_CASE 210 +//#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define PROSKILL 230 +int AttPreMagicNum = -1; +int AttNextMagicNum = -1; +short NoMiss = -1; //⴦˫ع +short StarLoop = 0; +//#endif +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ +#define FIRE_HUNTER_SKILL 240 +#endif +#ifdef _WAVETRACK // (ɿ) Syu ADD +int BeAttNum = -1 ; //ߵλñ +#endif + +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ +BOOL FireSkillEnd = FALSE; +BOOL bFireInit = FALSE; +int tempPosH = 0; +int tempPosV = 0; +int iBeAttNum = -1; //߱ +int counter; +int tarpos = -1; +int tarMgiDem = 0; +#endif + +/* ?????? ****************************************************/ +//???????? +char att_select_flg; + +/* ??????? ****************************************************/ +static ACTION *p_kanji; +static char kanji_buf[4][128]; +static ACTION *p_master; +static ACTION *p_attrib; +static ACTION *p_missile[BATTLKPKPLYAERNUM + 1]; +unsigned char crs_change_tbl[32] = { + 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4 }; +unsigned char crs_change_tbl2[8] = { + 16, 20, 24, 28, 0, 4, 8, 12 }; +unsigned char crs_bound_tbl[4][32] = { + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + { 16, 15, 14, 13, 12, 11, 10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 22, 21, 20, 19, 18, 17 }, + { 0, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29, 28, 27, 26, 25, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }, +}; +typedef struct{ + int v_pos; + ACTION *work; +} SORT_CHR_EQU; +static SORT_CHR_EQU sort_chr_buf[40]; +static char pet_nix_tbl[] = +{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-1, 0, 0, 0, 0, +-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +1, 0, 0, 0, 0, +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-1, 0, 0, 0, 0, +-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +1, 0, 0, 0, 0, +-2, +}; +static int monster_start_pos[BATTLKPKPLYAERNUM * 2]; +static int monster_place_pos[BATTLKPKPLYAERNUM * 2]; +#ifdef _BATTLE_PK_PLAYER_FOR_40 +static int monster_place_no[BATTLKPKPLYAERNUM] = { 2,1,3,0,4,7,6,8,5,9,12,11,13,10,14,17,16,18,15,19,22,21,23,20,24,27,26,28,25,29,32,31,33,30,34,37,36,38,35,39}; +#else +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 +static int monster_place_no[24] = { 2, 1, 3, 0, 4, 5, 8, 7, 9, 6, 10, 11, 14, 13, 15, 12, 16, 17, 20, 19, 21, 18, 22, 23}; +#else +static int monster_place_no[20] = { 2, 1, 3, 0, 4, 7, 6, 8, 5, 9, 12, 11, 13, 10, 14, 17, 16, 18, 15, 19 }; +#endif +#endif +#ifdef __ATTACK_MAGIC + +// Global vars +int g_iRunEarthQuake = 0; // ״: 0 --> û , 1 --> ʼ , 2 --> +int g_iCurRunEarthQuake = 0; // Ŀǰλ +int g_iNumRunEarthQuake; // ܴ + + + +#define ATTACK_MAGIC_ID 12345678 // ħʶ +#define MAX_NUM_ATTACKED 16 // 󱻹ߵĿ + + + +// λö +struct POS +{ + WORD x; // Xλ + WORD y; // Yλ +}; + + + +// BJ | ߵı | 12345678 | ʩʣMP | ǰöĶ | Ķ | +// öĶ | ķʽ | ʱ | ʾλõķʽ( Ի ) | +// λ( зʾλ÷ʽ ) | λ( ǰöλ÷ʽ ) | λ( öλ÷ʽ ) | +// ǰöʾǰ | ʾǰ | öʾǰ | +// 𶯻 | 𶯵ʼʱ | 𶯵Ľʱ | ĶX1 | ĶX2 | ...ĶXn|FF +// 12345678: ʾΪԵħΪ˯ +struct ATTACK_MAGIC +{ + DWORD dwCurFrame1; // ĿǰѲŹFramesδŹǰǰ + DWORD dwCurFrame2; // ĿǰѲŹFramesѾǰ + DWORD dwEQuake; // Ƿ𶯻 + DWORD dwEQuakeSTime; // Ŀʼʱ + DWORD dwEQuakeETime; // Ľʱ + DWORD dwEQuakeSFrame; // ŵĿʼFrame0XFFFFFFFFʾûеЧ + DWORD dwEQuakeEFrame; // ŵĽFrame0XFFFFFFFFʾûеЧ + int iPreMgcNum; // ǰöĶ + int iCurMgcNum; // Ķ + int iPostMgcNum; // öĶ + WORD wRunPreMgc; // ǷѾִǰ + WORD wAttackType; // ķʽ: ( )( )( ͬʱ )ȫ( )ȫ( ͬʱ ) + WORD wAttackTimeSlice; // ʱԺΪλ + WORD wShowType; // ʾλõķʽԼ + WORD wScreenX; // ʾλõXᣬھʾʽʱ + WORD wScreenY; // ʾλõYᣬھʾʽʱ + WORD wPreMgcX; // ǰöλ + WORD wPreMgcY; // ǰöλ + WORD wPostMgcX; // öλ + WORD wPostMgcY; // öλ + WORD wPreMgcOnChar; // ǰöʾڵذϣ + WORD wCurMgcOnChar; // ʾڵذϣ + WORD wPostMgcOnChar; // öʾڵذϣ + WORD wMgcFrameCount[MAX_NUM_ATTACKED]; // ŹڵʱFrame Count + WORD wAttackedIndex[MAX_NUM_ATTACKED]; // ߵУ0 - 19: һλ , 20: ǰ , 21: , 22: ȫз + POS posAttacked[MAX_NUM_ATTACKED]; // ߵıλ + WORD wNumAttacks; // ܴ + WORD wNumAttackeds; // ϵĴ + WORD wCurAttackNum; // Ŀǰ +}; + + + +static ATTACK_MAGIC AttMgc; // ı +static BOOL bRunAttMgc = FALSE; // Ƿѳʼһ +static int AttackedInfo[4 * 10]; // ʮ˵ıѶÿ˵λѶ( |ŵ|˿۵Ѫ|۵Ѫ ) +static int iAttackedNum; // Ŀ +static int iCurAttackedFinishNum; // ɵĵ + + + +static BOOL BuildAttackMagicData(ACTION *pMaster, ACTION *pAttacker); // Ͻ +static BOOL RunTimeMagic(); // ļغʽ + +#endif + + +#ifdef __TOCALL_MAGIC +// kjl 02/06/24 +#define TOCALL_MAGIC_ID 5711438 // ٻʶ + +struct TOCALL_MAGIC +{ + DWORD dwCurFrame1; // ĿǰѲŹFramesδŹǰǰ + DWORD dwCurFrame2; // ĿǰѲŹFramesѾǰ + DWORD dwEQuake; // Ƿ𶯻 + DWORD dwEQuakeSTime; // Ŀʼʱ + DWORD dwEQuakeETime; // Ľʱ + DWORD dwEQuakeSFrame; // ŵĿʼFrame0XFFFFFFFFʾûеЧ + DWORD dwEQuakeEFrame; // ŵĽFrame0XFFFFFFFFʾûеЧ + int iPreMgcNum; // ǰöĶ + int iCurMgcNum; // Ķ + int iPostMgcNum; // öĶ + WORD wRunPreMgc; // ǷѾִǰ + WORD wAttackType; // ķʽ: ( )( )( ͬʱ )ȫ( )ȫ( ͬʱ ) + WORD wAttackTimeSlice; // ʱԺΪλ + WORD wShowType; // ʾλõķʽԼ + WORD wScreenX; // ʾλõXᣬھʾʽʱ + WORD wScreenY; // ʾλõYᣬھʾʽʱ + WORD wPreMgcX; // ǰöλ + WORD wPreMgcY; // ǰöλ + WORD wPostMgcX; // öλ + WORD wPostMgcY; // öλ + WORD wPreMgcOnChar; // ǰöʾڵذϣ + WORD wCurMgcOnChar; // ʾڵذϣ + WORD wPostMgcOnChar; // öʾڵذϣ + WORD wMgcFrameCount[MAX_NUM_ATTACKED]; // ŹڵʱFrame Count + WORD wAttackedIndex[MAX_NUM_ATTACKED]; // ߵУ0 - 19: һλ , 20: ǰ , 21: , 22: ȫз + POS posAttacked[MAX_NUM_ATTACKED]; // ߵıλ + WORD wNumAttacks; // ܴ + WORD wNumAttackeds; // ϵĴ + WORD wCurAttackNum; // Ŀǰ + WORD wIsPostDisappear; // Ƿʧ + WORD wToCallMagicNo; // ٻ +}; + +static TOCALL_MAGIC ToCallMgc; // ı +static BOOL bRunToCallMgc = FALSE; // Ƿѳʼһ + +static BOOL BuildToCallMagicData(ACTION *pMaster, ACTION *pAttacker); // ٻϽ +//static BOOL RunTimeMagic(); // ļغʽ + +#endif + +#ifdef _PROFESSION_ADDSKILL +static int bRunBoundaryMgc_l = 0, bRunBoundaryMgc_r = 0; // Ч״̬ +ACTION *boundary_2,*boundary_mark[2]; +static BOOL BuildBoundaryMagicData( int state ); // ЧϽ +static void RunTimeMagicBoundary(int state); +#endif + +//˳ +enum { + T_PRIO_TOP, /* ??I */ + T_PRIO_JIKI = 20, /* ? */ + T_PRIO_JIKI_MISSILE, /* ?d */ + T_PRIO_MONSTER = 30, /* */ + T_PRIO_UFO = 60, /* ??? */ + T_PRIO_MONSTER_MISSILE = 70, /* d */ + T_PRIO_MISSILE, /* ???? */ + T_PRIO_MAGIC_EFFECT, /* ??? */ + T_PRIO_HIT_MARK, /* ?????? */ + T_PRIO_DAMAGE_NUM, /* ????k */ + T_PRIO_MASTER = 100, /* ???? */ + T_PRIO_BOW, /* ? */ + T_PRIO_BTM /* ?? */ +}; + +enum { + D_PRIO_MASTER = 80, /* ???? */ + D_PRIO_MONSTER_MISSILE, /* d */ + D_PRIO_UFO, /* ??? */ + D_PRIO_MONSTER, /* */ + D_PRIO_JIKI_MISSILE, /* ?d */ + D_PRIO_JIKI, /* ? */ + D_PRIO_MISSILE, /* ???? */ + D_PRIO_MAGIC_EFFECT, /* ??? */ + D_PRIO_HIT_MARK, /* ?????? */ + D_PRIO_DAMAGE_NUM, /* ????k */ +}; + +#ifdef _ATTACK_EFFECT +void DisplayAttackEffect(ACTION *a0) +{ + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + DeathAction(a0); +} + +void SetDisplayAttackEffect(ACTION *a0, int iEffectNumber) +{ + ACTION *a1, *a2; + + a2 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); // µ ACTION (ʱЧ) + if (a2 == NULL) + return; + ATR_NAME(a2) = DisplayAttackEffect; + ATR_CHR_NO(a2) = iEffectNumber; + a1 = ATR_BODY_WORK(0, a0); // ȡ + ATR_DISP_PRIO(a2) = ATR_DISP_PRIO(a1) + 1; // ʾڱͼϲ + ATR_H_POS(a2) = ATR_H_POS(a1); // ʾڱλ + ATR_V_POS(a2) = ATR_V_POS(a1); +} +#endif +/* ???????? *******************************************************************/ +void kakushi_command(void) +{ + //?????? + if (LowResoCmdFlag) // ??T???????? + return; + //V???? + if ((joy_con[0] & JOY_LEFT) && (joy_con[0] & JOY_RIGHT)) + { + LowResoCmdFlag = 1; // ??T?????????? + //??????? + play_se(211, 320, 240); + } +} + +#define DAMAGE_SPD 24 +//ʱʾ +void damage_num(ACTION *a0) +{ + int d0, d1, dx, d2 = 0; + char szMoji[256]; + char szMojiP[256]; + //andy_mp + char szMojMp[256]; + char szMojHp[256]; + + d0 = 0; dx = 0; + if (slow_flg) //slow״̬ + { + if (s_timer & 3) //ƶ + d0 = 1; + } + if (d0 == 0) //ƶ + { + switch (ATR_INT_WORK1(a0)) + { + case 0: + case 36: + case 37: + case 38: + case 39: + case 40: +#ifdef _SKILL_ADDBARRIER + case 43: +#endif +#ifdef _PETSKILL_PEEL + case 44: +#endif +#ifdef _PETSKILL_JUSTICE + case 45: +#endif +#ifdef _PETSKILL_ADDATTCRAZED + case 46: + case 47: +#endif +#ifdef _PETSKILL_PROVOKEFIGHT + case 48: +#endif +#ifdef _PRO3_ADDSKILL + case 49: + case 50: + case 51: +#endif + case 6: + case 14: + case 15: + case 16: + gemini(a0); + } + switch (ATR_VCT_NO(a0)) + { + case 0: + ATR_SPD(a0) -= 2; //??????? + if (ATR_SPD(a0)) //??????? + break; + ATR_CRS(a0) = 16; + ATR_VCT_NO(a0) = 1; + break; + + case 1: + ATR_SPD(a0) += 2; + if (ATR_SPD(a0) >= DAMAGE_SPD) //??? + { + ATR_STIMER(a0) = 60; + ATR_VCT_NO(a0) = 2; + } + break; + + case 2: + ATR_SPD(a0) = 0; //?h_ + if (--ATR_STIMER(a0)) //??? + break; + DeathAction(a0); //? + return; + } + } + + switch (ATR_INT_WORK1(a0)) + { + case 0: //Miss + sprintf_s(szMoji, "Miss"); + d1 = 0; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_MISS; + break; + case 1: // + sprintf_s(szMoji, "Counter"); + d1 = 1; //ˮɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_COUNTER; + break; + case 3: // + sprintf_s(szMoji, "Guard"); + d1 = 3; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_GUARD; + break; + case 5: //׽ + sprintf_s(szMoji, "Capture"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_CAPTURE; + break; + + case 6: //˴ + sprintf_s(szMoji, "%d", ATR_INT_WORK0(a0)); + sprintf_s(szMojiP, "%d", ATR_INT_WORKp(a0)); + //andy_mp + if (ATR_MPDFLG(a0) == 1) + sprintf_s(szMojMp, "%d", ATR_MPDAMAGE(a0)); + if (ATR_ADDHPFLG(a0) == 1) + sprintf_s(szMojHp, "%d", ATR_ADDHP(a0)); + d1 = 6; //ɫSet + break; + case 7: //׽ɹ + sprintf_s(szMoji, "Success"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_GET; + break; + case 8: //׽ʧܴ + sprintf_s(szMoji, "Fail"); + d1 = 6; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_FAIL; + break; + case 9: //ܴ + sprintf_s(szMoji, "Escape"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_ESCAPE; + break; + case 10: //ջسﴦ + sprintf_s(szMoji, "Come!"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_COME_ON; + break; + case 11: //ųﴦ + sprintf_s(szMoji, "Go!"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_GO; + break; + case 12: //Ƴ + sprintf_s(szMoji, "Guard break"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_GUARD_BREAK; + break; + case 13: //??? + sprintf_s(szMoji, "Danger"); + d1 = 6; //??? + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_DANGER; + break; + case 14: //ظ + sprintf_s(szMoji, "%d", ATR_INT_WORK0(a0)); + sprintf_s(szMojiP, "%d", ATR_INT_WORKp(a0)); + d1 = 5; //ɫSet + break; + case 15: //MPظ + sprintf_s(szMoji, "%d", ATR_INT_WORK0(a0)); + sprintf_s(szMojiP, "%d", ATR_INT_WORKp(a0)); + d1 = 4; //ɫSet + break; + case 16: //MP½ + sprintf_s(szMoji, "%d", ATR_INT_WORK0(a0)); + sprintf_s(szMojiP, "%d", ATR_INT_WORKp(a0)); + d1 = 3; //ɫSet + break; + case 17: // + sprintf_s(szMoji, "Leave"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_LEAVE; + break; + case 18: //NONO + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_NO; + break; + case 19: //CRUSH + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_CRUSH; + break; + case 20: //????????? + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_CAPTURE_UP; + break; + +#ifdef _SKILL_ROAR //輼:() + case 22: + sprintf_s(szMoji, "Roar"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_ROAR; + break; +#endif + +#ifdef _SKILL_SELFEXPLODE //Ա + case 23: + sprintf_s(szMoji, "SelfExplode"); + d1 = 5; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_selfexplod; // + break; +#endif + +#ifdef _ATTDOUBLE_ATTACK // andy_add + case 25: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_land_att; + break; + case 26: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_water_att; + break; + case 27: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_fire_att; + break; + case 28: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_wind_att; + break; +#endif + case 29: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_tooth; + break; + case 30: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_mic_def; + break; + case 31: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_ironwall; + break; + + case 32: //ת + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_ch_earth; + break; + case 33: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_ch_water; + break; + case 34: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_ch_fire; + break; + case 35: + sprintf_s(szMoji, "No"); + d1 = 2; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_ch_wind; + break; + case 36: //andy_add غϲѪ + memset(szMoji, 0, sizeof(szMoji)); + memset(szMojiP, 0, sizeof(szMojiP)); + if (ATR_INT_WORK0(a0) != 0) + { + sprintf_s(szMoji, "%4d", ATR_INT_WORK0(a0)); + sprintf_s(szMojiP, "%4d", ATR_INT_WORKp(a0)); + } + if (ATR_MPDAMAGE(a0) != 0) + sprintf_s(szMojMp, "%4d", ATR_MPDAMAGE(a0)); + d2 = FONT_PAL_YELLOW; + d1 = FONT_PAL_GREEN; + break; + case 37: + memset(szMoji, 0, sizeof(szMoji)); + sprintf_s(szMoji, "ر %s", (ATR_INT_WORK0(a0) > 0) ? "" : "½"); + d1 = FONT_PAL_GREEN; + break; + case 38: + memset(szMoji, 0, sizeof(szMoji)); + sprintf_s(szMoji, " %s%d", (ATR_INT_WORK0(a0) > 0) ? "" : "½", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + break; + case 39: + memset(szMoji, 0, sizeof(szMoji)); + sprintf_s(szMoji, " %s%d", (ATR_INT_WORK0(a0) > 0) ? "" : "½", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + break; + case 40: + memset(szMoji, 0, sizeof(szMoji)); + sprintf_s(szMoji, " %s%d", (ATR_INT_WORK0(a0) > 0) ? "" : "½", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + break; +#ifdef _SYUTEST + case 41: + sprintf_s(szMoji, "LightTake"); + d1 = 5; + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = SPR_lightget;// + break; +#endif + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + case 41: + sprintf_s(szMoji, "LightTake"); + d1 = 5; + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = AttNextMagicNum;// +#ifdef _WAVETRACK // (ɿ) Syu ADD + if (AttNextMagicNum == 101703 && BeAttNum >= 15 && BeAttNum <= 19) + { + if (BeAttNum == 15) + ATR_H_POS(a0) = ATR_H_POS(a0) - 1 ; + else if (BeAttNum == 17) + ATR_H_POS(a0) = ATR_H_POS(a0) - 2 ; + else if (BeAttNum == 19) + ATR_H_POS(a0) = ATR_H_POS(a0) - 3 ; + else if (BeAttNum == 18) + ATR_V_POS(a0) = ATR_V_POS(a0) - 1 ; + } + if (AttNextMagicNum == 101704 && BeAttNum >= 5 && BeAttNum <= 9) + { + if (BeAttNum == 5) + { + if (ATR_CHR_CNT(a0) == 0) + { + ATR_H_POS(a0) = 441; + ATR_V_POS(a0) = 322; + } + else + ATR_H_POS(a0) = ATR_H_POS(a0) + 1; + } + else if (BeAttNum == 6) + { + if (ATR_CHR_CNT(a0) == 0) + { + ATR_H_POS(a0) = 377; + ATR_V_POS(a0) = 370; + } + else + ATR_H_POS(a0) = ATR_H_POS(a0) + 2; + } + else if (BeAttNum == 7) + { + if (ATR_CHR_CNT(a0) == 0) + { + ATR_H_POS(a0) = 505; + ATR_V_POS(a0) = 274; + } + } + else if (BeAttNum == 8) + { + if (ATR_CHR_CNT(a0) == 0) + { + ATR_H_POS(a0) = 313; + ATR_V_POS(a0) = 418; + } + else + ATR_H_POS(a0) = ATR_H_POS(a0) + 3; + } + else if (BeAttNum == 9) + { + if (ATR_CHR_CNT(a0) == 0) + { + ATR_H_POS(a0) = 569; + ATR_V_POS(a0) = 226; + } + else + ATR_V_POS(a0) = ATR_V_POS(a0) + 1; + } + } +#endif + break; + //#endif + +#ifdef _EQUIT_ARRANGE + case 42: // + sprintf_s(szMoji, "Guard"); + d1 = 3; //ɫSet + ATR_ATTRIB(a0) = 0; + ATR_CHR_NO(a0) = CG_ICON_GUARD; + break; +#endif + +#ifdef _SKILL_ADDBARRIER // Change 輼:Ϊħ쳣Թ + case 43: + memset(szMoji, 0, sizeof(szMoji)); + if (ATR_INT_WORK0(a0) == 0) + sprintf_s(szMoji, "쳣Իظ"); + else + sprintf_s(szMoji, "쳣 %s%d", (ATR_INT_WORK0(a0) > 0) ? "":"½", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + break; +#endif +#ifdef _PETSKILL_PEEL + case 44: + { + char *tempstr[] = { "ͷ", "", "", "Ʒ", "Ʒ", "", "", "Ь", ""}; + memset(szMoji, 0, sizeof(szMoji)); + if (ATR_INT_WORK0(a0) > 8) + break; + sprintf_s(szMoji, "ж %s װ", tempstr[ATR_INT_WORK0(a0)]); + d1 = FONT_PAL_GREEN; + } + break; +#endif +#ifdef _PETSKILL_JUSTICE + case 45: + { + sprintf_s(szMoji, " %d غ", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + } + break; +#endif +#ifdef _PETSKILL_ADDATTCRAZED + case 46: + { + sprintf_s(szMoji, "ݻر½", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + } + break; + case 47: + { + sprintf_s(szMoji, "ݻرܻظ", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + } + break; +#endif +#ifdef _PETSKILL_PROVOKEFIGHT + case 48: + { + d1 = FONT_PAL_GREEN; + switch(ATR_INT_WORK0(a0)){ + case 0: + sprintf_s(szMoji, "!", ATR_INT_WORK0(a0)); + break; + case 1: + sprintf_s(szMoji, "ܵ!", ATR_INT_WORK0(a0)); + break; + case 2: + sprintf_s(szMoji, "Һס!", ATR_INT_WORK0(a0)); + break; + case 3: + sprintf_s(szMoji, "!", ATR_INT_WORK0(a0)); + break; + case 4: + sprintf_s(szMoji, "չ֮", ATR_INT_WORK0(a0)); + break; + case 5: + sprintf_s(szMoji, "վ֮", ATR_INT_WORK0(a0)); + break; + case 6: + sprintf_s(szMoji, "֮", ATR_INT_WORK0(a0)); + break; + case 7: + sprintf_s(szMoji, "֮ʧЧ", ATR_INT_WORK0(a0)); + break; + case 8: + sprintf_s(szMoji, "֮ʧЧ", ATR_INT_WORK0(a0)); + break; + case 9: + sprintf_s(szMoji, "֮ʧЧ", ATR_INT_WORK0(a0)); + break; + case 10: + sprintf_s(szMoji, "ҺЧ!", ATR_INT_WORK0(a0)); + break; +#ifdef _PRO3_ADDSKILL + case 11: + sprintf_s(szMoji, "ѹǶϽ!"); + break; + case 12: + sprintf_s(szMoji, "˶֮!"); + break; + case 13: + sprintf_s(szMoji, "֮!"); + break; + case 14: + sprintf_s(szMoji, "ο!"); + break; + case 15: + sprintf_s(szMoji, "ӡ鷨!"); + break; + case 16: + sprintf_s(szMoji, "ظ鷨!"); + break; + case 17: + sprintf_s(szMoji, "˶ħ!"); + break; + case 18: + sprintf_s(szMoji, "ħ!"); + break; + case 19: + sprintf_s(szMoji, "ܵ˾!"); + break; +#endif + } + break; + } +#endif +#ifdef _PRO3_ADDSKILL + case 49: //ο + { + sprintf_s(szMoji, "ҳ϶ %d ", ATR_INT_WORK0(a0)); + d1 = FONT_PAL_GREEN; + } + break; + case 50: //ӡ + { + char *tempstr[] = { "", "ɽȪ", "", "ĩ", "", "", "", "", "", "", + "Ѫ", "Ѫ", "", "ǹ", "", "", "׸", "", "", "", "", + "λλ", "", "", "˫ع", "ر", "ǹ", "", "", "", + "ͨ", "ͨͶʯ", "ͨͶ", "״̬ظ", "Ϊ", "", "ۼ", "רעս", + "ܻ", "ᴩ", "", "", "ҹ", "", "׷Ѱ", "رս", "", + "", "޵", "ʬӶ", "", "㹥", "", "", "﹥", "ӹ", "ѱ", "ŭ", + "Ը", "׿", "", "", "", "ǿ", "", "", "Ȼ", "Ȼ", + "ؽ", "ˮ", "", "", "Ƴ", "յ", "Ұ", + "ķ", "ѹǶϽ", "սŭ", "", + "ħӡ", "ħ", "֮", "ر", + "ر", "֮", "ο", + "ս", "ҩѧ" }; + memset(szMoji, 0, sizeof(szMoji)); + sprintf_s(szMoji, "%s ӡ", tempstr[ATR_INT_WORK0(a0)]); + d1 = FONT_PAL_GREEN; + } + break; + case 51: + { + sprintf_s(szMoji, "½%d", ATR_INT_WORK0(a0) ); + d1 = FONT_PAL_GREEN; + } + break; +#endif + } + + switch (ATR_INT_WORK1(a0)) + { + case 36: //andy_add غϲѪ + if (ATR_RIDE_FLAG(a0) == 1) + StockFontBuffer(ATR_H_POS(a0) - 20, ATR_V_POS(a0) + 32, FONT_PRIO_BACK, d1, szMojiP, 0); + case 37: + case 38: + case 39: + case 40: +#ifdef _SKILL_ADDBARRIER + case 43: +#endif +#ifdef _PETSKILL_PEEL + case 44: +#endif +#ifdef _PETSKILL_JUSTICE + case 45: +#endif +#ifdef _PETSKILL_ADDATTCRAZED + case 46: + case 47: +#endif +#ifdef _PETSKILL_PROVOKEFIGHT + case 48: +#endif +#ifdef _PRO3_ADDSKILL + case 49: + case 50: + case 51: +#endif + StockFontBuffer(ATR_H_POS(a0) - 20, ATR_V_POS(a0), FONT_PRIO_BACK, d1, szMoji, 0); + if (ATR_MPDAMAGE(a0) != 0) + StockFontBuffer(ATR_H_POS(a0) - 20, ATR_V_POS(a0) + 12, FONT_PRIO_BACK, d2, szMojMp, 0); + break; + case 6: + case 14: + case 15: + case 16: + //andy_mp + if (ATR_ADDHPFLG(a0) == 1)//Ѫ + { + StockFontBuffer(ATR_H_POS(a0) - d0, ATR_V_POS(a0), FONT_PRIO_BACK, FONT_PAL_GREEN, szMojHp, 0); + break; + } + d0 = GetStrWidth(szMoji) >> 1; + StockFontBuffer(ATR_H_POS(a0) - d0, ATR_V_POS(a0), FONT_PRIO_BACK, d1, szMoji, 0); + + if (ATR_MPDAMAGE(a0) != 0 || ATR_MPDFLG(a0) == 1)//˺ + StockFontBuffer(ATR_H_POS(a0) - d0, ATR_V_POS(a0) + 12, FONT_PRIO_BACK, FONT_PAL_YELLOW, szMojMp, 0); + if (ATR_RIDE_FLAG(a0) == 1) + { + dx = GetStrWidth(szMojiP) >> 1; + StockFontBuffer(ATR_H_POS(a0) - dx, ATR_V_POS(a0) + 60, FONT_PRIO_BACK, d1, szMojiP, 0); + } + break; + default: + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + } +} + +//˺ֵ趨 +void set_damage_num(ACTION *a0, int color, int v_pos) +{ + ACTION *a1; + a1 = GetAction(T_PRIO_DAMAGE_NUM, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ +#ifdef _WAVETRACK // (ɿ) Syu ADD + BeAttNum = a0->hitDispNo ; +#endif + ATR_NAME(a1) = damage_num; + //ʾȶ + ATR_DISP_PRIO(a1) = D_PRIO_DAMAGE_NUM; + /* ???t */ + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0) + v_pos; + ATR_SPD(a1) = DAMAGE_SPD; + ATR_ATTRIB(a1) = ACT_ATR_HIDE; + //Syu mark иɫûϵdamage_numĴ룬damage_numswitchŻɫ + ATR_INT_WORK1(a1) = color; //ɫ趨 + if (ATR_ADDHPFLG(a0) == 1) + { + ATR_ADDHP(a1) = ATR_ADDHP(a0); + ATR_ADDHPFLG(a1) = ATR_ADDHPFLG(a0); + } + int dddd = ATR_DAMAGE(a0); + ATR_INT_WORK0(a1) = ATR_DAMAGE(a0); //˺趨 + ATR_INT_WORKp(a1) = ATR_PET_DAMAGE(a0); //˺趨 + ATR_RIDE_FLAG(a1) = ATR_RIDE(a0); + //andy_mp + ATR_MPDAMAGE(a1) = ATR_MPDAMAGE(a0); + ATR_MPDFLG(a1) = ATR_MPDFLG(a0); + + switch (ATR_INT_WORK1(a1)) + { + case 0: + case 36: + case 37: + case 38: + case 40: +#ifdef _SKILL_ADDBARRIER + case 43: +#endif +#ifdef _PETSKILL_PEEL + case 44: +#endif +#ifdef _PETSKILL_JUSTICE + case 45: +#endif +#ifdef _PETSKILL_ADDATTCRAZED + case 46: + case 47: +#endif +#ifdef _PETSKILL_PROVOKEFIGHT + case 48: +#endif +#ifdef _PRO3_ADDSKILL + case 49: + case 50: + case 51: +#endif + case 6: + case 14: + case 15: + case 16: + case 19: + break; + default: +#ifdef _SKILL_SELFEXPLODE //Ա + if (ATR_SELFEXPLODE(a0) == 1) + ATR_V_POS(a1) = ATR_V_POS(a0) - SpriteInfo[a0->bmpNo].height / 2 + 20; + else +#endif +#ifdef _SYUTEST + if (color == 41) + ATR_V_POS(a1) = ATR_V_POS(a0) + v_pos; + else + ATR_V_POS(a1) = ATR_V_POS(a0) - 80; +#else + ATR_V_POS(a1) = ATR_V_POS(a0) - 80; +#endif + } +#ifdef _PETSKILL_LER + // ׶ʱķ + if (color == 3 && ATR_CHR_NO(a0) == 101815) + { + ACTION *a2; + a2 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a2 == NULL) + return; + ATR_NAME(a2) = katino; + ATR_BODY_WORK(0, a2) = a0; + ATR_JUJUTSU_WORK(a0) = a2; + ATR_DISP_PRIO(a2) = ATR_DISP_PRIO(a0) + 1; + ATR_H_POS(a2) = ATR_H_POS(a0) + 10; + ATR_V_POS(a2) = ATR_V_POS(a0) + 10; + if (g_bUseAlpha) + ATR_CHR_NO(a2) = 101805; + else + ATR_CHR_NO(a2) = 101858; + } +#endif +#ifdef _PETSKILL_RIDE + //petrideChangeGraph( a0 ); +#endif +} + +/* ???????? *******************************************************************/ +#if 0 +??? +????? +????? Y +????? ? +????? ?S +????? ? +????? ? +????? ?????? +????? + +????? +????? +????? Y +????? ? +????? ?S +????? ? +????? ? +????? ?????? +????? +#endif +void play_damage(int no, int x) +{ + //????????? + if (no >= 10100) + no -= 100; + //Ч + switch (no) + { + case 10000: // + no = 250; + break; + case 10001: //צ + no = 254; + break; + case 10002: // + no = 251; + break; + case 10003: // + no = 251; + break; + case 10004: //ǹ + no = 252; + break; + case 10005: // + no = -1; + break; + case 10006: //Ͷ + no = -1; + break; + case 10007: // + no = 254; + break; + default: + no = 250; + } + //??????? + if (no != -1) + play_se(no, x, 240); +} + +/* ???? *******************************************************************/ +void disp_kanji(ACTION *a0) +{ + int d1, d7; + + ACTION *a1; + a1 = ATR_BODY_WORK(0, a0); //????? + if (!--ATR_INT_WORK0(a0)) //????? + { + DeathAction(a1); //???? + DeathAction(a0); //? + p_kanji = NULL; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + else + { + if (ATR_LIFE(a1)) //???? + { + for (d1 = 4 + 13, d7 = 0; d7 < 4; d1 += 18, d7++) + { + if (kanji_buf[d7][0]) //?????? + StockFontBuffer(640 - 4 + -64 * 4 + 24, d1, FONT_PRIO_FRONT, FONT_PAL_WHITE, kanji_buf[d7], 0); + } + } + } +} + +/* ????? *******************************************************************/ +void magic_effect(ACTION *a0) +{ + ACTION *a1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) //?????? + { + ATR_VCT_NO(a0)++; + ATR_CHR_ACT(a0)++; + } + break; + case 1: + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) //?????? + { + ATR_VCT_NO(a0)++; + ATR_CHR_ACT(a0)++; + } + break; + case 2: + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) //?????? + { + DeathAction(a0); //? + return; + } + break; + } + a1 = ATR_BODY_WORK(0, a0); //? + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1); +} + +//HIT_MARK ( ɱ ) +void hit_mark_critical(ACTION *a0) +{ + if (ATR_STIMER(a0) == ATR_FIRST_FLG(a0) >> 1) //????? + ATR_CHR_NO(a0)--; + if (--ATR_STIMER(a0)) + { + gemini(a0); + pattern(a0, 0, 0); + } + else + { + DeathAction(a0); // + return; + } +} +//HIT_MARK +void hit_mark(ACTION *a0) +{ + //ATR_KAISHINΪTRUE + if (ATR_KAISHIN(a0)) + { + if (ATR_STIMER(a0) == ATR_FIRST_FLG(a0) * 1 / 3) //????? + ATR_CHR_NO(a0)--; + if (ATR_STIMER(a0) == ATR_FIRST_FLG(a0) * 2 / 3) //????? + ATR_CHR_NO(a0)--; + } + else + { + if (ATR_STIMER(a0) == ATR_FIRST_FLG(a0) * 1 / 3) //????? + ATR_CHR_NO(a0)--; + if (ATR_STIMER(a0) == ATR_FIRST_FLG(a0) * 2 / 3) //????? + ATR_CHR_NO(a0)--; + } + if (--ATR_STIMER(a0)) + pattern(a0, 0, 0); + else + { + DeathAction(a0); // + return; + } +} + +void set_hit_mark(ACTION *a0) +{ + ACTION *a1, *a2; + int d0; + + //ɱʱǣDzDZɱDzbreak + for (d0 = 5; d0 > 0; d0--) + { + //趨HIT_MARK + a1 = GetAction(T_PRIO_HIT_MARK, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ + ATR_NAME(a1) = hit_mark; + //ʾȶ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + //豻ɫͼ + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + //趨ͼ + ATR_CHR_NO(a1) = CG_HIT_MARK_12; //ɫ + else + //趨ͼ + ATR_CHR_NO(a1) = CG_HIT_MARK_22; //ɫ + //λ + a2 = ATR_BODY_WORK(0, a0); + ATR_H_POS(a1) = ATR_H_POS(a2); + ATR_V_POS(a1) = ATR_V_POS(a2) - 32; + ATR_SPD(a1) = Rnd(4, 7); + ATR_CRS(a1) = d0 * 6; + if (ATR_HIT_STOP(a0) == HIT_STOP_TIM) //?????????? + ATR_FIRST_FLG(a1) = ATR_STIMER(a1) = ATR_HIT_STOP(a0); //ʾʱ趨 + else + { + ATR_FIRST_FLG(a1) = ATR_STIMER(a1) = ATR_HIT_STOP(a0); //ʾʱ趨 + ATR_KAISHIN(a1) = 1; + } + //ɱʱһǣDZɱ + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + { + ATR_NAME(a1) = hit_mark_critical; + ATR_CHR_NO(a1) = CG_HIT_MARK_01; + + } + else + break; + } +} + +/* \?????? *******************************************************************/ +void disp_guard_mark(ACTION *a0) +{ + ACTION *a1; + a1 = ATR_BODY_WORK(0, a0); + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1) - 32; + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) //?????? + DeathAction(a0); //? +} + +void set_guard_mark(ACTION *a0) +{ + ACTION *a1; + + a1 = GetAction(T_PRIO_HIT_MARK, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + ATR_NAME(a1) = disp_guard_mark; + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) + ATR_CHR_NO(a1) = SPR_mirror; + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) + ATR_CHR_NO(a1) = SPR_barrior; +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + else if (ATR_ATTACK_KIND(0, a0) & ATT_TRAP) + { // + if ( a0->hitDispNo >= 10 && a0->hitDispNo <= 19 ) + ATR_CHR_NO(a1) = 101630; + else if ( a0->hitDispNo >= 0 && a0->hitDispNo <= 9 ) + ATR_CHR_NO(a1) = 101696; +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + { + if (ATR_GROUP_FLG(a0) == 0) ATR_CHR_NO(a1) = 101696; + else ATR_CHR_NO(a1) = 101630; + } +#endif + } +#endif +#ifdef _PETSKILL_ACUPUNCTURE + else if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + //ĿǰʾЧͼ +#ifdef _FIX_ACUPUNCTURE + ATR_DAMAGE(a0) = ATR_ATTACK_POW(1, a0); +#else + ATR_DAMAGE(a0) = ATR_ATTACK_POW(0, a0)*2;//趨˺ֵ +#endif +#endif +#ifdef _PET_ITEM + else if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + ATR_DAMAGE(a0) = ATR_ATTACK_POW(1, a0); +#endif + else + ATR_CHR_NO(a1) = SPR_kyusyu; + + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); +} + +void set_jujutsu_hit_mark(ACTION *a0) +{ + ACTION *a1; + + //????????? + a1 = GetAction(T_PRIO_HIT_MARK, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ + ATR_NAME(a1) = hit_mark; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + /* ?????k? */ + ATR_CHR_NO(a1) = CG_HIT_MARK_32; //? + /* ???t */ + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0) - 32; + ATR_FIRST_FLG(a1) = ATR_STIMER(a1) = HIT_STOP_TIM; //????? +} + +static int piyo_loop_v_tbl[] = { + 0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 9, 10, 9, + 9, 9, 9, 8, 8, 7, 6, 5, 5, 4, 3, 2, 1, 0, -1, -2, + -3, -4, -4, -5, -6, -7, -8, -8, -9, -9, -9, -9, -10, -9, -9, -9, + -9, -8, -8, -7, -6, -5, -5, -4, -3, -2, -1, +}; +static int piyo_loop_h_tbl[] = { + -24, -23, -23, -22, -21, -20, -19, -17, -16, -14, -11, -9, -7, -4, -2, 0, 2, + 4, 7, 9, 11, 14, 16, 17, 19, 20, 21, 22, 23, 23, 24, 23, 23, + 22, 21, 20, 19, 17, 16, 14, 12, 9, 7, 4, 2, 0, -2, -4, -7, + -9, -11, -14, -16, -17, -19, -20, -21, -22, -23, -23, +}; + +//?????????? ??????? ?????????? +void piyo_loop(ACTION *a0) +{ + ACTION *a1; + int d0; + + a1 = ATR_BODY_WORK(0, a0); //ol?????? + if (ATR_NAME(a1) == NULL || ATR_LIFE(a1) != 0) //??????? + { + DeathAction(a0); //? + return; + } + /* ?IT */ + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + d0 = piyo_loop_h_tbl[ATR_STIMER(a0)]; + ATR_H_POS(a0) = ATR_H_POS(a1) + d0 + ATR_INT_WORK0(a0); + d0 = piyo_loop_v_tbl[ATR_STIMER(a0)]; + ATR_V_POS(a0) = ATR_V_POS(a1) + d0 + ATR_INT_WORK1(a0); + ATR_STIMER(a0)++; + if (ATR_STIMER(a0) == 60) + ATR_STIMER(a0) = 0; + pattern(a0, 0, 0); +} + +//?????????? ????????? ?????????? +#define PIYOPIYO_CNT 3 +void set_piyo_loop(ACTION *a0) +{ + ACTION *a1; + int d7; + + for (d7 = 0; d7 < PIYOPIYO_CNT; d7++) + { + //????????? + a1 = GetAction(T_PRIO_HIT_MARK, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ + ATR_NAME(a1) = piyo_loop; + ATR_CHR_NO(a1) = SPR_star; + /* ???t */ + ATR_BODY_WORK(0, a1) = a0; + ATR_STIMER(a1) = d7 * (60 / PIYOPIYO_CNT); + //???h +#ifndef __CARYTEST + ATR_INT_WORK0(a1) = a0->anim_x + SpriteInfo[ATR_PAT_NO(a0)].width / 2; +#else + ATR_INT_WORK0(a1) = a0->anim_x + g_lpRealAdrn[ATR_PAT_NO(a0)].width / 2; +#endif + ATR_INT_WORK1(a1) = a0->anim_y; + } +} + +/* ??? *******************************************************************/ +void katino(ACTION *a0) +{ + ACTION *a1; + + a1 = ATR_BODY_WORK(0, a0); //?????????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) == VCT_NO_DIE + 2 || ATR_LIFE(a1) == 0) //??? + { + ATR_JUJUTSU_WORK(a1) = NULL; //? + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + ATR_H_POS(a0) = ATR_H_POS(a1); +#ifdef _FIXSTATUS // (ɿ) Syu ADD ս״̬ʾʽ + if (ATR_CHR_NO(a0) == SPR_shock) // + ATR_V_POS(a0) = ATR_V_POS(a1); + else if (ATR_CHR_NO(a0) == 35120) // + ATR_V_POS(a0) = ATR_V_POS(a1) - 34 ; + else if (ATR_CHR_NO(a0) == 101702) //Sars + ATR_V_POS(a0) = ATR_V_POS(a1) - 34 ; + else if (ATR_CHR_NO(a0) == 27692) // + ATR_V_POS(a0) = ATR_V_POS(a1) - 34 ; + else if (ATR_CHR_NO(a0) == 35110) //޵ + ATR_V_POS(a0) = ATR_V_POS(a1) - 34 ; + else if (ATR_CHR_NO(a0) == 26517) // + ATR_V_POS(a0) = ATR_V_POS(a1) - 34 ; + else if (ATR_CHR_NO(a0) == CG_HIT_MARK_00) + { //ѣ + StarLoop++; + if (StarLoop <= 20 && StarLoop > 0) + ATR_V_POS(a0) = ATR_V_POS(a1) - 46; + else if (StarLoop <= 40 && StarLoop > 20) + ATR_V_POS(a0) = ATR_V_POS(a1) - 56; + else if (StarLoop <= 60 && StarLoop > 40) + { + ATR_V_POS(a0) = ATR_V_POS(a1) - 56; + ATR_H_POS(a0) = ATR_H_POS(a0) + 16; + } + else if (StarLoop <= 80 && StarLoop > 60) + { + ATR_V_POS(a0) = ATR_V_POS(a1) - 46; + ATR_H_POS(a0) = ATR_H_POS(a0) + 16; + } + if (StarLoop >= 80) + StarLoop = 0 ; + } +#ifdef _PETSKILL_LER + // ׶ʱλò + else if (ATR_CHR_NO(a0) == 101810 || ATR_CHR_NO(a0) == 101811 || ATR_CHR_NO(a0) == 101863 || ATR_CHR_NO(a0) == 101864); + // ׶ʱķܶλҪ + else if (ATR_CHR_NO(a0) == 101805 || ATR_CHR_NO(a0) == 101858) + { + ATR_H_POS(a0) = ATR_H_POS(a1) + 10; + ATR_V_POS(a0) = ATR_V_POS(a1) + 10; + } +#endif + else + ATR_V_POS(a0) = ATR_V_POS(a1) - 64; +#else + if (ATR_CHR_NO(a0) == SPR_shock) //???? + ATR_V_POS(a0) = ATR_V_POS(a1); + else + ATR_V_POS(a0) = ATR_V_POS(a1) - 64; +#endif +#ifdef _PETSKILL_LER + // Ϊʱ + if (ATR_CHR_NO(a0) == 101810 || ATR_CHR_NO(a0) == 101811 || ATR_CHR_NO(a0) == 101805 || + ATR_CHR_NO(a0) == 101863 || ATR_CHR_NO(a0) == 101864 || ATR_CHR_NO(a0) == 101858) + { + // , + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + ATR_JUJUTSU_WORK(a1) = NULL; + DeathAction(a0); + if (ATR_CHR_ACT(a1) == ANIM_DEAD && ATR_CHR_NO(a1) == 101813) + ATR_CHR_NO(a1) = 101814; + else if (ATR_CHR_ACT(a1) == ANIM_DEAD && ATR_CHR_NO(a1) == 101814) + ATR_CHR_NO(a1) = 101815; + ATR_VCT_NO(a1) = 0; + int i; + for (i = 0; i < BATTLKPKPLYAERNUM; i++) + { + // ҳ׶һ + if (ATR_CHR_NO(p_party[i]) == ATR_CHR_NO(a1)) + break; + } + a1->dir = ATR_CHR_ANG(a1) = i < 10 ? 3:7; + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + } + } + else +#endif + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? +} + +//״̬ +void set_single_jujutsu(int d0, ACTION *a1) +{ + if (ATR_LIFE(a1) == 0) //?????? + return; + + ACTION *a2; + + a2 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a2 == NULL) + return; + /* ??? */ + ATR_NAME(a2) = katino; + ATR_BODY_WORK(0, a2) = a1; + ATR_JUJUTSU_WORK(a1) = a2; + /* ?IT */ + ATR_DISP_PRIO(a2) = ATR_DISP_PRIO(a1) + 1; + /* ???t */ + ATR_H_POS(a2) = ATR_H_POS(a1); + ATR_V_POS(a2) = ATR_V_POS(a1) - 64; + ATR_STIMER(a2) = d0; + /* ?????k? */ + switch (d0) + { + // "", + case 1: + ATR_CHR_NO(a2) = SPR_poison; + break; + // "??", + case 2: + ATR_CHR_NO(a2) = SPR_shock; + break; + + // "?", + case 3: + ATR_CHR_NO(a2) = SPR_sleep; + break; + // "?", + case 4: + ATR_CHR_NO(a2) = SPR_stone; + break; + // "?????", + case 5: + ATR_CHR_NO(a2) = SPR_drunk; + break; + // "??" + case 6: + ATR_CHR_NO(a2) = SPR_conf; + break; +#ifdef _MAGIC_WEAKEN // + case 7: + ATR_CHR_NO(a2) = SPR_weaken; + break; +#endif +#ifdef _MAGIC_DEEPPOISION //綾 + case 8: + ATR_CHR_NO(a2) = SPR_deeppoison; + break; +#endif +#ifdef _MAGIC_BARRIER + case 9: + ATR_CHR_NO(a2) = SPR_barrier; //ħ + break; +#endif +#ifdef _MAGIC_NOCAST + case 10: + ATR_CHR_NO(a2) = SPR_nocast; //Ĭ + break; +#endif + +#ifdef _SARS // WON ADD ɷ + case 11: + ATR_CHR_NO(a2) = 101702; //ɷ + break; +#endif + +#ifdef _CHAR_PROFESSION // WON ADD + case 12: + ATR_CHR_NO(a2) = CG_HIT_MARK_00; //ѣ + break; + case 13: + ATR_CHR_NO(a2) = 35120; // + break; + case 14: + ATR_CHR_NO(a2) = 35110; //޵ + break; + case 15: + ATR_CHR_NO(a2) = 27692; // + break; + case 16: + ATR_CHR_NO(a2) = 26517; // + break; + case 17: + ATR_CHR_NO(a2) = 27692; // + break; + case 18: + ATR_CHR_NO(a2) = 27012; //Ѫ + break; + case 19: + ATR_CHR_NO(a2) = 27012; //һѪ + break; + case 20: + ATR_CHR_NO(a2) = SPR_conf; // + break; + case 21: + ATR_CHR_NO(a2) = 0; // + break; + case 22: + ATR_CHR_NO(a2) = 0; // + break; + case 23: + ATR_CHR_NO(a2) = 100551; //׸ + break; +#ifdef _PROFESSION_ADDSKILL + case 32: + ATR_CHR_NO(a2) = SPR_barrier; // ˮ + break; + case 33: + ATR_CHR_NO(a2) = SPR_shock; //־ + //case 24: + // ATR_CHR_NO(a2) = 0; // ׸ + break; +#endif +#endif +#ifdef _PETSKILL_LER + case 34: + if (ATR_CHR_NO(a1) == 101814) + { + // һα + if (g_bUseAlpha) + ATR_CHR_NO(a2) = 101810; // 1 + else + ATR_CHR_NO(a2) = 101863; // 1 + ATR_V_POS(a2) = ATR_V_POS(a1); + if (ATR_CHR_ACT_OLD(a1) != ANIM_DEAD) + { + ATR_VCT_NO(a1) = VCT_NO_DIE; + ATR_CHR_NO(a1) = 101813; + } + } + else if (ATR_CHR_NO(a1) == 101815) + { + // ڶα + if (g_bUseAlpha) + ATR_CHR_NO(a2) = 101811; // 2 + else + ATR_CHR_NO(a2) = 101864; // 2 + ATR_V_POS(a2) = ATR_V_POS(a1); + if (ATR_CHR_ACT_OLD(a1) != ANIM_DEAD) + { + ATR_VCT_NO(a1) = VCT_NO_DIE; + ATR_CHR_NO(a1) = 101814; + } + } + break; +#endif +#ifdef _PRO_KILLME + case 35: + ATR_CHR_NO(a2) = 101292; // ŭ + break; +#endif +#ifdef _PRO_ABSOLUTE_DEFENSE + case 36: + ATR_CHR_NO(a2) = 102043; + break; +#endif +#ifdef _PRO3_ADDSKILL + case 37: + ATR_CHR_NO(a2) = 102044;//37 ħ + break; + case 38: + ATR_CHR_NO(a2) = 102046;//38 ֮ + break; + case 39: + ATR_CHR_NO(a2) = 101296;//39 ο + break; +#endif + } +} + +/* NͧT?? *******************************************************************/ +void attrib_reverse(ACTION *a0) +{ + ACTION *a1; + + a1 = ATR_BODY_WORK(0, a0); //T?????????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) == VCT_NO_DIE + 2) //??? + { + ATR_ATTRIB_WORK(a1) = NULL; //? + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1) - 64; + ATR_CHR_NO(a0) = SPR_zokusei; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? +} + +/* NͧT????? *******************************************************************/ +void set_attrib_reverse(ACTION *a1) +{ + ACTION *a2; + + a2 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a2 == NULL) + return; + /* ??? */ + ATR_NAME(a2) = attrib_reverse; + ATR_BODY_WORK(0, a2) = a1; + ATR_ATTRIB_WORK(a1) = a2; + /* ?IT */ + ATR_DISP_PRIO(a2) = ATR_DISP_PRIO(a1) + 1; + /* ?????k? */ + ATR_CHR_NO(a2) = CG_ATR_ICON_EARTH_BATTLE; + /* ???t */ + ATR_H_POS(a2) = ATR_H_POS(a1); + ATR_V_POS(a2) = ATR_V_POS(a1) - 64; +} + + +//int boomerang_pos_tbl[]= {0x320, 0x140, 0x2EE, 0xDC, 0x186, 0x6A, 0x214, 0xAA}; +//int boomerang_pos_tbl2[]={0x2EE, 0x118, 0x2BC, 0xB4, 0x154, 0x32, 0x1BE, 0x64}; +////O[v̌ +//int boomerang_pos_tbl3a[]={0x104, 0x1A4, 0x64, 0x14A, -0x60, 0xA0, -0x92, 0x104}; +//int boomerang_pos_tbl4a[]={0x154, 0x1C2, 0xB4, 0x190, -0x92, 0xC8, -0xC4, 0x12C}; +////O[v̑O +//int boomerang_pos_tbl3b[]={0xC4, 0x1A4, 0x44, 0x16A, -0x60, 0xA0, -0x92, 0x104}; +//int boomerang_pos_tbl4b[]={0x154, 0x1C2, 0xB4, 0x1D0, -0x92, 0xC8, -0xC4, 0x12C}; + + +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 +int boomerang_pos_tbl[] = { 0x320, 0x140, 0x2EE, 0xDC, 0x186, 0x6A, 0x214, 0xAA }; +int boomerang_pos_tbl2[] = { 0x2EE, 0x118, 0x2BC, 0xB4, 0x154, 0x32, 0x1BE, 0x64 }; +//ϽλС15ʱ xiezi +int boomerang_pos_tbl3a[] = { 0x104 + 160, 0x1A4 + 120, 0x64 + 160, 0x14A + 120, -0x60 + 160, 0xA0 + 120, -0x92 + 160, 0x104 + 120 }; +int boomerang_pos_tbl4a[] = { 0x154 + 160, 0x1C2 + 120, 0xB4 + 160, 0x190 + 120, -0x92 + 160, 0xC8 + 120, -0xC4 + 160, 0x12C + 120 }; +//Ͻλڵ15ʱ xiezi +int boomerang_pos_tbl3b[] = { 0xC4 + 160, 0x1A4 + 120, 0x44 + 160, 0x16A + 120, -0x60 + 160, 0xA0 + 120, -0x92 + 160, 0x104 + 120 }; +int boomerang_pos_tbl4b[] = { 0x154 + 160, 0x1C2 + 120, 0xB4 + 160, 0x1D0 + 120, -0x92 + 160, 0xC8 + 120, -0xC4 + 160, 0x12C + 120 }; +#else +int boomerang_pos_tbl[] = { 0x320, 0x140, 0x2EE, 0xDC, 0x186, 0x6A, 0x214, 0xAA }; +int boomerang_pos_tbl2[] = { 0x2EE, 0x118, 0x2BC, 0xB4, 0x154, 0x32, 0x1BE, 0x64 }; +//ϽλС15ʱ xiezi +int boomerang_pos_tbl3a[] = { 0x104 + 160, 0x1A4 + 120, 0x64 + 160, 0x14A + 120, -0x60 + 160, 0xA0 + 120, -0x92 + 160, 0x104 + 120 }; +int boomerang_pos_tbl4a[] = { 0x154 + 160, 0x1C2 + 120, 0xB4 + 160, 0x190 + 120, -0x92 + 160, 0xC8 + 120, -0xC4 + 160, 0x12C + 120 }; +//Ͻλڵ15ʱ xiezi +int boomerang_pos_tbl3b[] = { 0xC4 + 160, 0x1A4 + 120, 0x44 + 160, 0x16A + 120, -0x60 + 160, 0xA0 + 120, -0x92 + 160, 0x104 + 120 }; +int boomerang_pos_tbl4b[] = { 0x154 + 160, 0x1C2 + 120, 0xB4 + 160, 0x1D0 + 120, -0x92 + 160, 0xC8 + 120, -0xC4 + 160, 0x12C + 120 }; +#endif + + +void boomerang(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + float dx, dy; + + if (ATR_HIT_STOP(a0)) + { + if (--ATR_HIT_STOP(a0)) + return; + } + switch (ATR_VCT_NO(a0)) + { + case 0: + if (ATR_GROUP_FLG(a0) == 0) + { + d0 = boomerang_pos_tbl[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + else + { + if (ATR_PLACE_NO(a0) >= 15)//Ҳǣ + { + d0 = boomerang_pos_tbl3b[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl3b[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + else + { + d0 = boomerang_pos_tbl3a[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl3a[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + } + + if (ATR_FIRST_FLG(a0) == 0) + { + ATR_SPD(a0) = 40; + radar(a0, &d0, &d1); + ATR_CRS(a0) = d0; + ATR_FIRST_FLG(a0) = 1; + } + else + radar2(a0, d0, d1, ATR_LONG_WORK(1, a0)); + gemini(a0); + dx = (float)(d0 - ATR_H_POS(a0)); + dy = (float)(d1 - ATR_V_POS(a0)); + d0 = (int)sqrt((double)(dx * dx + dy * dy)); + if (d0 < 20) + ATR_VCT_NO(a0) = 1; + + break; + case 1: + if (ATR_SPD(a0) != 32) + ATR_SPD(a0)--; + if (ATR_GROUP_FLG(a0) == 0) + { + d0 = boomerang_pos_tbl2[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl2[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + else + { + if (ATR_PLACE_NO(a0) >= 15) + { + d0 = boomerang_pos_tbl4b[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl4b[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + else + { + d0 = boomerang_pos_tbl4a[ATR_LONG_WORK(0, a0) * 2]; + d1 = boomerang_pos_tbl4a[ATR_LONG_WORK(0, a0) * 2 + 1]; + } + } + radar2(a0, d0, d1, ATR_LONG_WORK(1, a0)); + gemini(a0); + dx = (float)(d0 - ATR_H_POS(a0)); + dy = (float)(d1 - ATR_V_POS(a0)); + d0 = (int)sqrt((double)(dx * dx + dy * dy)); + if (d0 < 40) + { + d0 = get_num(); + if (d0 == 255) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + DeathAction(a0); + p_missile[0] = NULL; + return; + } + else + { + ATR_BODY_WORK(0, a0) = p_party[d0]; + ATR_ATTACK_KIND(0, a0) = get_num(); + ATR_ATTACK_POW(0, a0) = get_num(); + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + + ATR_VCT_NO(a0) = 2; + } + } + break; + case 2: + + if (ATR_SPD(a0) != 40) + ATR_SPD(a0)++; + a1 = ATR_BODY_WORK(0, a0); + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar2(a0, d0, d1, ATR_LONG_WORK(1, a0)); + gemini(a0); + dx = (float)(d0 - ATR_H_POS(a0)); + dy = (float)(d1 - ATR_V_POS(a0)); + d0 = (int)sqrt((double)(dx * dx + dy * dy)); + + if (d0 > 1000) //ھ1000ʱֱӽ + { + ATR_COUNTER_FLG(a0) = 1; + ATR_LONG_WORK(2, a0) = 0; + + if (ATR_PLACE_NO(a1) == 17) + { + ATR_H_POS(a0) = ATR_H_POS(a1) + 128; + ATR_V_POS(a0) = ATR_V_POS(a1) - 96; + } + else if (ATR_PLACE_NO(a1) == 16) + { + ATR_H_POS(a0) = ATR_H_POS(a1) + 256; + ATR_V_POS(a0) = ATR_V_POS(a1) - 192; + } + else + { + ATR_H_POS(a0) = ATR_H_POS(a1) + 256; + ATR_V_POS(a0) = ATR_V_POS(a1) - 192; + } + return; + } + + if (ATR_COUNTER_FLG(a0) == 1) + { + if (BattleMapNo >= 148 && BattleMapNo <= 150) + d1 = 10 + 5; + else + d1 = 10; + } + else + { + if (BattleMapNo >= 148 && BattleMapNo <= 150) + d1 = 20 + 10; + else + d1 = 20; + } + if (d0 < 80) + { + if (ATR_COUNTER_FLG(a0) == 1 && ATR_LONG_WORK(2, a0) == 0) + { + ATR_LONG_WORK(2, a0) = 1; + a1 = ATR_BODY_WORK(1, a0); + ATR_VCT_NO(a1) = 72; + play_se(14, ATR_H_POS(a0), ATR_V_POS(a0)); + } + } + if (d0 < d1) + { + if (ATR_COUNTER_FLG(a0) == 1) + { + DeathAction(a0); + p_missile[0] = NULL; + return; + } + ATR_LONG_WORK(2, a0) = 0; + a2 = ATR_BODY_WORK(0, a0); + if (ATR_LIFE(a2) <= 0) + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; + goto boomerang_200; + } +#ifdef _PETSKILL_ACUPUNCTURE + //////////////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + //////////////////////////////////// +#else + //////////////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + //////////////////////////////////// +#endif + set_guard_mark(a0); + + ATR_COMBO(a1) = 0; + + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + { + ATR_VCT_NO(a1) = 16; + if (ATR_GROUP_FLG(a0) == 0) + ATR_CRS(a1) = crs_change_tbl2[3]; + else + ATR_CRS(a1) = crs_change_tbl2[7]; + ATR_DAMAGE_ANG(a1) = crs_change_tbl[ATR_CRS(a1)]; + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; + goto boomerang_200; + } + + if (!((ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) | (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION))) + { + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) + { + a2 = ATR_BODY_WORK(0, a0); + + set_damage_num(a2, 0, -64); + goto boomerang_200; + } + } + + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + set_damage_num(a1, 19, -112); + + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) + ATR_AKO_FLG(a1) = 2; + if (ATR_ATTACK_KIND(0, a0) & ATT_DEATH) + ATR_LIFE(a1) = 0; + if (ATR_GROUP_FLG(a0) == 0) + ATR_DAMAGE_ANG(a1) = 1; + else + ATR_DAMAGE_ANG(a1) = 5; + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) + { + if (!ATR_COMBO(a1)) + { + + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; + ATR_ATTACK_PET_POW(0, a0) = 0; + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) + { + ATR_ATTACK_POW(0, a0) = 0; + ATR_ATTACK_PET_POW(0, a0) = 0; + } + else + ATR_VCT_NO(a1) = 10; + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + ATR_KAISHIN(a1) = 1; + else + ATR_KAISHIN(a1) = 0; + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) + { + + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; + } + if (ATR_KAISHIN(a1)) + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; + + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) || (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION)) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) + { + if (ATR_COMBO(a1) == 0) + set_damage_num(a0, 1, -64 + 16); + } + + play_se(252, ATR_H_POS(a0), ATR_V_POS(a0)); + + set_hit_mark(a0); + } + boomerang_200: + ATR_HIT_STOP(a0) /= 4; + d0 = get_num(); + if (d0 == 255) + { + ATR_BODY_WORK(0, a0) = ATR_BODY_WORK(1, a0); + ATR_COUNTER_FLG(a0) = 1; + } + else + { + ATR_BODY_WORK(0, a0) = p_party[d0]; + ATR_ATTACK_KIND(0, a0) = get_num(); + ATR_ATTACK_POW(0, a0) = get_num(); + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + } + } + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} + + +static char stick_ang_tbl[] = { 8, 10, 12, 14, 0, 2, 4, 6 }; +/* ????? *******************************************************************/ +void stick_bow(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + a1 = ATR_BODY_WORK(0, a0); //ol?????? + if (ATR_NAME(a1) == NULL) //??? + { + DeathAction(a0); //? + ATR_STIMER(ATR_BODY_WORK(1, a0))++; //??? + return; + } + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + a2 = ATR_BODY_WORK(0, a0); //??????? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a1, &d0, &d1); //???? + ATR_STIMER(a0)++; + if (ATR_CRS(a0) == 0) //?? + { + if (ATR_SPD(a0) == 0) //????? + ATR_CRS(a0) = 16; + else + ATR_SPD(a0) -= 1; + } + else + ATR_SPD(a0) += 1; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 1: + case 2: + case 3: + a1 = ATR_BODY_WORK(0, a0); //??????? +#if 0 + if (ATR_VCT_NO(a0) == 2) //??h?? + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE + 1) //X????? + { + DeathAction(a0); //? + return; + } + } + else + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) //r??????? + { + if (ATR_VCT_NO(a1) == 0) //r??? + { + DeathAction(a0); //? + ATR_STIMER(ATR_BODY_WORK(1, a0))++; //??? + return; + } + else + { + ATR_VCT_NO(a0) = 2; + break; + } + } + } +#else + if (ATR_VCT_NO(a0) == 2) //??h?? + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE + 1) //X????? + { + DeathAction(a0); //? + return; + } + } + else if (ATR_VCT_NO(a0) == 3) + { + if (ATR_VCT_NO(ATR_BODY_WORK(1, a0)) == 0) //????? + { + DeathAction(a0); //? + return; + } + } + else + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) //r??????? + { + ATR_STIMER(ATR_BODY_WORK(1, a0))++; //??? + if (ATR_VCT_NO(a1) == 0) //r??? + { + ATR_VCT_NO(a0) = 3; + return; + } + else + { + ATR_VCT_NO(a0) = 2; + break; + } + } + } +#endif + ATR_H_POS(a0) = ATR_H_POS(a1) + ATR_INT_WORK0(a0); + ATR_V_POS(a0) = ATR_V_POS(a1) + ATR_INT_WORK1(a0); + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a1) + 4) & 7; //????? + ATR_CHR_NO(a0) = CG_ARROW_00 + stick_ang_tbl[ATR_CHR_ANG(a0)]; // + ATR_H_MINI(a0) = 0; //? + ATR_V_MINI(a0) = 0; + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + gemini(a0); + gemini(a0); + if (ATR_CHR_ANG(a1) == 3 || ATR_CHR_ANG(a1) == 4 || ATR_CHR_ANG(a1) == 5) //?????? + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1); //?I??? + else + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; //?I??? + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 +void shoot(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + a1 = ATR_BODY_WORK(0, a0); + if (ATR_NAME(a1) == NULL) + { + DeathAction(a0); + ATR_STIMER(ATR_BODY_WORK(1, a0))++; + return; + } + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(1, a0); + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + a2 = ATR_BODY_WORK(0, a0); + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a1, &d0, &d1); + ATR_STIMER(a0)++; + if (ATR_CRS(a0) == 0) + { + if (ATR_SPD(a0) == 0) + ATR_CRS(a0) = 16; + else + ATR_SPD(a0) -= 1; + } + else + ATR_SPD(a0) += 1; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 1: + case 2: + case 3: + a1 = ATR_BODY_WORK(0, a0); + if (ATR_VCT_NO(a0) == 2) + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE + 1) + { + DeathAction(a0); + return; + } + } + else if (ATR_VCT_NO(a0) == 3) + { + if (ATR_VCT_NO(ATR_BODY_WORK(1, a0)) == 0) + { + DeathAction(a0); + return; + } + } + else + { + if (ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) + { + ATR_STIMER(ATR_BODY_WORK(1, a0))++; + if (ATR_VCT_NO(a1) == 0) + { + DeathAction(a0); + ATR_VCT_NO(a0) = 3; + return; + } + else + { + ATR_VCT_NO(a0) = 2; + break; + } + } + } + ATR_H_POS(a0) = ATR_H_POS(a1) + ATR_INT_WORK0(a0); + ATR_V_POS(a0) = ATR_V_POS(a1) + ATR_INT_WORK1(a0) + 32 + (a0->anim_cnt * 4); + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a1) + 4) & 7; + if (a0->anim_cnt == 5) + ATR_CHR_NO(a0) = 0; + else if (ATR_CHR_NO(a0) != 0) + ATR_CHR_NO(a0) = 101611; + ATR_H_MINI(a0) = 0; + ATR_V_MINI(a0) = 0; + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + gemini(a0); + gemini(a0); + if (ATR_CHR_ANG(a1) == 3 || ATR_CHR_ANG(a1) == 4 || ATR_CHR_ANG(a1) == 5) + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1); + else + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} +#endif + +/* ??h?? *******************************************************************/ +void bow(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + //??????? + if (!--ATR_GROUP_FLG(a0)) + { + a2 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_LIFE(a2) <= 0) //?????? + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + } +#ifdef _PETSKILL_ACUPUNCTURE + /////////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + /////////////////////////////// +#else + /////////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + /////////////////////////////// +#endif + set_guard_mark(a0); + ATR_COMBO(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + { + ATR_HIT_STOP(a0) = 32; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 16; //???? + ATR_CRS(a1) = ATR_CRS(a0); //????????????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; //?????????? + break; + } + + if (!((ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) | (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION))) + { + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) //???? + { + a2 = ATR_BODY_WORK(0, a0); //???????? + set_damage_num(a2, 0, -64); //?? + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + } + } + //????????? + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + //????? + set_damage_num(a1, 19, -112); + //????????? + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) //?????? + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) //?????? + ATR_AKO_FLG(a1) = 2; + if (ATR_ATTACK_KIND(0, a0) & ATT_DEATH) //????? + ATR_LIFE(a1) = 0; //????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) //?????? + { + if (!ATR_COMBO(a1)) //???????? + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + ATR_VCT_NO(a1) = 10; //????? + //?????? + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + ATR_KAISHIN(a1) = 1; //??????? + else + ATR_KAISHIN(a1) = 0; //G????? + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + //????? + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) //????? + { + //???????? + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; //??????? + } + if (ATR_KAISHIN(a1)) //?????? + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; //?????????? + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + //????????????? + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) || (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION)) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + { + //???????? + if (ATR_COMBO(a1) == 0) + set_damage_num(a0, 1, -64 + 16); //????? + } + //??? + play_se(12, ATR_H_POS(a0), ATR_V_POS(a0)); + //????????? + set_hit_mark(a0); + } + ATR_STIMER(a0) = ATR_HIT_STOP(a0) + 64; //??????? + ATR_INT_WORK0(a0) = Rnd(0, 8) - 4; //??????? + ATR_INT_WORK1(a0) = Rnd(0, 8) - 4 - 28; //???????!!! +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if (ShooterNum == 101578) + ATR_NAME(a0) = shoot; //????? + else + ATR_NAME(a0) = stick_bow; //????? +#else + ATR_NAME(a0) = stick_bow; //????? +#endif + ATR_VCT_NO(a0) = 1; // + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + ATR_V_POS(a0) -= 28; //!!! + ATR_CHR_ACT(a0) = 0; + p_missile[0] = NULL; //??????? + ATR_SPD(a0) = 40; //? + //??? + } + else + { + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 1: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + ATR_STIMER(a0) = 32; + else + ATR_STIMER(a0) = 64; + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[0] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_STIMER(ATR_BODY_WORK(1, a0))++; //??? + DeathAction(a0); //? + break; + } +} + +/* ????? *******************************************************************/ +void axe(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + a2 = ATR_BODY_WORK(0, a0); //??????? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a1, &d0, &d1); //???? + ATR_STIMER(a0)++; + if (ATR_CRS(a0) == 0) //?? + { + if (ATR_SPD(a0) == 0) //????? + ATR_CRS(a0) = 16; + else + ATR_SPD(a0) -= 1; + } + else + ATR_SPD(a0) += 1; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 1: + break; + case 2: + ATR_VCT_NO(a0)++; + break; + case 3: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + if (ATR_CRS(a0) == 0) //?? + { + if (ATR_SPD(a0) == 0) //????? + ATR_CRS(a0) = 16; + else + ATR_SPD(a0) -= 2; + } + else + ATR_SPD(a0) += 2; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 4: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1); + ATR_CHR_ACT(a0) = 1; //????????? + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} + +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ +void fireHunter(ACTION *a0) +{ + ACTION *a1, *a2; + int i = 0; + int j = 0; + int d0, d1; + + a1 = ATR_BODY_WORK(0, a0); //˵λַ + + switch (ATR_VCT_NO(a0)) + { + case 0: // + if (bFireInit) + { + int EnemyPos[4][2] = {{403 , 422}, {223 , 388},{7 , 198},{19 , 318},}; + int refPos, difPosH, difPosV; + int interval = 0; + int difPos_v = 0; //ɱλַ + int difPos_h = 0; //ɱλַ + int j = 1; + + ATR_INT_WORK2(a0) = ATR_H_POS(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0); + for (i = 2; i < 8 ; i++) + { + p_missile[i] = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + ATR_INT_WORK2(p_missile[i]) = ATR_H_POS(a0); + ATR_INT_WORK3(p_missile[i]) = ATR_V_POS(a0); + ATR_CHR_NO(p_missile[i]) = 101734; //ͼ + ATR_CHR_ANG(p_missile[i]) = ATR_CHR_ANG(a0); + ATR_CRS(p_missile[i]) = ATR_CRS(a0); + ATR_SPD(p_missile[i]) = 60; + } + if (iBeAttNum < 5) + { + refPos = 0; + difPosH = 32; + difPosV = 24; + } + else if (iBeAttNum < 10) + { + refPos = 1; + difPosH = 64; + difPosV = 48; + } + else if (iBeAttNum < 15) + { + refPos = 2; + difPosH = 32; + difPosV = 24; + } + else if (iBeAttNum < 20) + { + refPos = 3; + difPosH = 64; + difPosV = 48; + } + for (i = 1; i < 9; i++) + { + p_missile[i + 7] = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + ATR_H_POS(p_missile[i + 7]) = EnemyPos[refPos][0] + difPosH * i; + ATR_V_POS(p_missile[i + 7]) = EnemyPos[refPos][1] - difPosV * i; + ATR_CHR_NO(p_missile[i + 7]) = 101735; //ͼ + } + ATR_STIMER(a0) = 80; + + if (iBeAttNum == 18 || iBeAttNum == 11 || iBeAttNum == 19) + interval = ATR_GROUP_FLG(a0) / 7; + else + interval = ATR_GROUP_FLG(a0) / 6; + for (i = 0; i < ATR_GROUP_FLG(a0); i++) + { + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //״(·) + ATR_CRS(a0) = d0; //· + gemini(a0); + if (i == interval * j) + { + switch (iBeAttNum) //ɱλַ + { + case 10: + case 12: + difPos_v += 7; // + difPos_h += 2; //Ƕ + break; + case 14: + difPos_v += 10; + difPos_h += 2; + break; + case 15: + difPos_v += 4; + break; + case 16: + difPos_v += 5; + difPos_h -= 5; + break; + case 17: + difPos_v += 3; + break; + case 18: + difPos_v += 5; + difPos_h -= 5; + break; + case 19: + difPos_v += 17; + difPos_h -= 2; + break; + case 11: + difPos_v += 5; + difPos_h -= 5; + break; + /* case 8: + difPos_v += 7; + difPos_h -= 5; + break; + case 5: + difPos_v +=7; + difPos_h -=10; + break;*/ + } + if (iBeAttNum < 10) + { + //difPos_h -= 10;//Ƕ + difPos_v += 10; // + } + ATR_V_POS(p_missile[j+1]) = ATR_V_POS(a0) - difPos_v; + ATR_H_POS(p_missile[j+1]) = ATR_H_POS(a0) + difPos_h; + if (j < 6) + j++; + } + } + ATR_V_POS(a0) -= difPos_v; + ATR_H_POS(a0) += difPos_h; + bFireInit = FALSE; + } + //׼ + if (!FireSkillEnd) + { +#ifdef _PETSKILL_ACUPUNCTURE + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + ///////////////////////////// +#else + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + ///////////////////////////// +#endif + set_guard_mark(a0); // + ATR_COMBO(a1) = 0; // + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) // + { + for (i = 0; i < ATR_BODY_CNT(a0); i++) //ȫ + { + if ((i + 2) != tarpos) + { + a2 = ATR_BODY_WORK(i + 2, a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(i + 2, a0); + j = ATR_DAMAGE(a2); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(i + 2, a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + } + } + ATR_HIT_STOP(a0) = 32; //ֹͣ + ATR_VCT_NO(a0) = 1; //ֹͣ + gemini(a0); + ATR_VCT_NO(a1) = 16; //ܶ + ATR_CRS(a1) = ATR_CRS(a0); //· + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; + break; + } + if (!((ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) | (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION))) + { + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) //???? + { + //˺ + set_damage_num(a1, 0, -64); + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //ֹͣ + ATR_VCT_NO(a0) = 1; //ֹͣ + for (i = 0; i < ATR_BODY_CNT(a0); i++) //ȫ + { + if ((i + 2) != tarpos) + { + a2 = ATR_BODY_WORK(i + 2, a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(i + 2, a0); + j = ATR_DAMAGE(a2); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(i + 2, a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + } + } + break; + } + } + //ѹ + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + //ѹ + set_damage_num(a1, 19, -112); + //趨KO + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) //KO1 + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) //KO2 + ATR_AKO_FLG(a1) = 2; + if (ATR_ATTACK_KIND(0, a0) & ATT_DEATH) // + ATR_LIFE(a1) = 0; //趨 + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); //趨˺Ƕ + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) // + { + if (!ATR_COMBO(a1)) // + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; + ATR_ATTACK_PET_POW(0, a0) = 0; + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + ATR_VCT_NO(a1) = 10; //ͳ˺ѶϢ + /* //һ + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY){ + ATR_KAISHIN(a1) = 1; //һ + } else { + ATR_KAISHIN(a1) = 0; //ͨ + }*/ + ATR_KAISHIN(a1) = 0; //ͨ + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + // + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) // + { + ATR_LONG_WORK(1, a0) = 1; //趨 + // + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; //趨һ + } + if (ATR_KAISHIN(a1)) //趨һ + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; //趨ֹͣʱ + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //趨ֹͣʱ + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) || (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION)) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + { + //Ƿ + if (ATR_COMBO(a1) == 0) + set_damage_num(a0, 1, -64 + 16); //˺ʾ + } + //??? + play_se(252, ATR_H_POS(a0), ATR_V_POS(a0)); + //ɱ + set_hit_mark(a0); + } + ATR_HIT_STOP(a0) /= 4; //?????????? + ATR_VCT_NO(a0) = 3; // + for (i = 0; i < ATR_BODY_CNT(a0); i++) //ȫ + { + if ((i + 2) != tarpos) + { + a2 = ATR_BODY_WORK(i + 2, a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(i + 2, a0); + j = ATR_DAMAGE(a2); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(i + 2, a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + } + } + } + else + { + if (ATR_STIMER(a0)) + ATR_STIMER(a0)--; + + if (p_missile[2] != NULL) + { + if (pattern(p_missile[2], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[2]); + p_missile[2] = NULL; + } + } + if (ATR_STIMER(a0) < 70 && p_missile[3] != NULL) + { + if (pattern(p_missile[3], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[3]); + p_missile[3] = NULL; + } + } + if (ATR_STIMER(a0) < 60 && p_missile[4] != NULL) + { + if (pattern(p_missile[4], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[4]); + p_missile[4] = NULL; + } + } + if (ATR_STIMER(a0) < 50 && p_missile[5] != NULL) + { + if (pattern(p_missile[5], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[5]); + p_missile[5] = NULL; + } + } + if (ATR_STIMER(a0) < 40 && p_missile[6] != NULL) + { + if (pattern(p_missile[6], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[6]); + p_missile[6] = NULL; + } + } + if (iBeAttNum > 9) + { + if (ATR_STIMER(a0) < 30 && p_missile[7] != NULL) + { + if (pattern(p_missile[7], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[7]); + p_missile[7] = NULL; + } + } + } + if (ATR_STIMER(a0) < 20) + { + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP) && p_missile[6] == NULL) + { + counter = 0; + ATR_VCT_NO(a0) = 8; + } + } + } + break; + case 1: + if (--ATR_HIT_STOP(a0)) //ֹͣ + break; + ATR_CHR_ACT(a0) = 0; //ƶ + // + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + ATR_STIMER(a0) = 32; + else + ATR_STIMER(a0) = 64; + if (tarpos != -1) + { + a2 = ATR_BODY_WORK(tarpos, a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(tarpos, a0); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(tarpos, a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + tarpos = -1; + } + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[0] = NULL; + p_missile[1] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; // + p_missile[0] = NULL; + DeathAction(a0); //? + break; + case 3: + if (--ATR_HIT_STOP(a0)) //ֹͣ + break; + /* if ( tarMgiDem ) + { + a2 = ATR_BODY_WORK(2 ,a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(2 ,a0); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(2 ,a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + int k = ATR_DAMAGE(a2); + set_damage_num(a2, 0, -64); + tarMgiDem = 0; + }*/ + if (tarpos != -1) + { + a2 = ATR_BODY_WORK(tarpos, a0); + ATR_DAMAGE(a2) = ATR_ATTACK_POW(tarpos, a0); + ATR_PET_DAMAGE(a2) = ATR_ATTACK_PET_POW(tarpos, a0); + ATR_VCT_NO(a2) = 10; //ͳ˺ѶϢ + ATR_STIMER(a2) = 0; + ATR_FIRST_FLG(a2) = 0; + tarpos = -1; + } + ATR_GROUP_FLG(a0) = 35; + ATR_SPD(a0) = 16; + ATR_VCT_NO(a0)++; + break; + case 4: + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + if (!--ATR_GROUP_FLG(a0)) //??? + { + if (ATR_LONG_WORK(1, a0)) //??????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + ATR_VCT_NO(a0)++; + } + break; + case 5: + play_se(251, ATR_H_POS(a0), ATR_V_POS(a0)); + ATR_VCT_NO(a0)++; + ATR_STIMER(a0) = 30; + break; + case 6: + if (ATR_STIMER(a0)) + { + ATR_STIMER(a0)--; + break; + } + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) //r??????? + { + if (!ATR_LONG_WORK(1, a0)) //?????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + p_missile[0] = NULL; // + p_missile[1] = NULL; // + } + break; + case 7: + ATR_VCT_NO(a0)++; + ATR_STIMER(a0) =60; + break; + case 8: + for (i = 8; i < 13; i++) + { + if (p_missile[i] != NULL) + { + if (pattern(p_missile[i], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(p_missile[i]); + p_missile[i] = NULL; + counter++; + } + } + } + if (counter == 5) + { + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + FireSkillEnd = FALSE; + ATR_VCT_NO(a0) = 0; + } + break; + } +} +#endif + +/* ?????? *******************************************************************/ +void axe_shadow(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + //??????? + if (!--ATR_GROUP_FLG(a0)) + { + a2 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_LIFE(a2) <= 0) //?????? + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + break; + } +#ifdef _PETSKILL_ACUPUNCTURE + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + ///////////////////////////// +#else + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + ///////////////////////////// +#endif + set_guard_mark(a0); //\?Ӥ? + //????????? + ATR_COMBO(a1) = 0; + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + { + ATR_HIT_STOP(a0) = 32; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + ATR_CHR_ACT(a0) = 1; //????????? + gemini(a0); + ATR_VCT_NO(a1) = 16; //???? + ATR_CRS(a1) = ATR_CRS(a0); //????????????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; //?????????? + break; + } + //???????????? + if (!((ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) | (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION))) + { + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) //???? + { + a2 = ATR_BODY_WORK(0, a0); //???????? + //?? + set_damage_num(a2, 0, -64); + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_ACT(a0) = 1; //????????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + break; + } + } + //????????? + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + set_damage_num(a1, 19, -112); //????? + //????????? + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) //?????? + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) //?????? + ATR_AKO_FLG(a1) = 2; + if (ATR_ATTACK_KIND(0, a0) & ATT_DEATH) //????? + ATR_LIFE(a1) = 0; //????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) //?????? + { + if (!ATR_COMBO(a1)) //???????? + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //pet????? + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + ATR_VCT_NO(a1) = 10; //????? + //?????? + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + ATR_KAISHIN(a1) = 1; //??????? + else + ATR_KAISHIN(a1) = 0; //G????? + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + //????? + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) //????? + { + ATR_LONG_WORK(1, a0) = 1; //??????? + //???????? + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; //??????? + } + if (ATR_KAISHIN(a1)) //?????? + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; //?????????? + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + //????????????? + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) || (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION)) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + { + //???????? + if (ATR_COMBO(a1) == 0) + set_damage_num(a0, 1, -64 + 16);//????? + } + //??? + play_se(252, ATR_H_POS(a0), ATR_V_POS(a0)); + //????????? + set_hit_mark(a0); + } + ATR_HIT_STOP(a0) /= 4; //?????????? + ATR_VCT_NO(a0) = 3; //???????? + a1 = ATR_BODY_WORK(2, a0); //??????? + ATR_VCT_NO(a1) = 1; //???????? + ATR_CHR_ACT(a1) = 1; //????????? + } + else + { + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + } + break; + case 1: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + ATR_CHR_ACT(a0) = 0; //?h??????? + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + ATR_STIMER(a0) = 32; + else + ATR_STIMER(a0) = 64; + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[0] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + break; + case 3: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + a1 = ATR_BODY_WORK(2, a0); //??????? + ATR_CHR_ACT(a1) = 0; //?h??????? + //?????????h?? + ATR_GROUP_FLG(a0) = 35; + ATR_SPD(a0) = 16; + a1 = ATR_BODY_WORK(2, a0); //??????? + ATR_VCT_NO(a1) = 2; //?h?? + ATR_SPD(a1) = 32; + ATR_CRS(a1) = 0; + ATR_VCT_NO(a0)++; + break; + case 4: + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + if (!--ATR_GROUP_FLG(a0)) //??? + { + if (ATR_LONG_WORK(1, a0)) //??????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + ATR_VCT_NO(a0)++; + } + break; + case 5: + a1 = ATR_BODY_WORK(2, a0); //??????? + ATR_VCT_NO(a1) = 4; + //??? + play_se(251, ATR_H_POS(a0), ATR_V_POS(a0)); + ATR_VCT_NO(a0)++; + ATR_STIMER(a0) = 30; + break; + case 6: + if (ATR_STIMER(a0)) + { + ATR_STIMER(a0)--; + break; + } + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + a1 = ATR_BODY_WORK(2, a0); //??????? + ATR_ATTRIB(a1) = ACT_ATR_HIDE; //?? + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) //r??????? + { + if (!ATR_LONG_WORK(1, a0)) //?????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + p_missile[0] = NULL; // + a1 = ATR_BODY_WORK(2, a0); //??????? + DeathAction(a1); //? + } + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} + +/* ???? *******************************************************************/ +void stone(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + a2 = ATR_BODY_WORK(0, a0); //??????? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a1, &d0, &d1); //???? + ATR_STIMER(a0)++; + if (ATR_CRS(a0) == 0) //?? + { + if (ATR_SPD(a0) == 0) //????? + ATR_CRS(a0) = 16; + else + ATR_SPD(a0) -= 1; + } + else + ATR_SPD(a0) += 1; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 1: + break; + case 2: + ATR_VCT_NO(a0)++; + break; + case 3: + a1 = ATR_BODY_WORK(1, a0); //?s??????? + if (ATR_VCT_NO(a1) == 1) + { + DeathAction(a0); //? + return; + } + ATR_DISP_PRIO(a0) = ATR_DISP_PRIO(a1) + 1; + ATR_LONG_WORK(0, a0)++; + if (ATR_LONG_WORK(0, a0) & 1) + ATR_SPD(a0) += 2; + gemini(a0); + ATR_H_POS(a0) += ATR_INT_WORK2(a1); + ATR_V_POS(a0) += ATR_INT_WORK3(a1); + break; + case 4: + if (ATR_LONG_WORK(1, a0)) + { + //???? + if (!--ATR_LONG_WORK(1, a0)) + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + } + a1 = ATR_BODY_WORK(1, a0); //?s??????? + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1); + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +} + +/* ????? *******************************************************************/ +void stone_shadow(ACTION *a0) +{ + ACTION *a1, *a2, *a3; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + //??????? + if (!--ATR_GROUP_FLG(a0)) + { + a2 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_LIFE(a2) <= 0) //?????? + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + } +#ifdef _PETSKILL_ACUPUNCTURE + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + ///////////////////////////// +#else + ///////////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + ///////////////////////////// +#endif + set_guard_mark(a0); //\?Ӥ? + //????????? + ATR_COMBO(a1) = 0; + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + { + ATR_HIT_STOP(a0) = 32; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + gemini(a0); + ATR_VCT_NO(a1) = 16; //???? + ATR_CRS(a1) = ATR_CRS(a0); //????????????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; //?????????? + break; + } + //???????????? + if (!((ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) | (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION))) + { + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) //???? + { + a2 = ATR_BODY_WORK(0, a0); //???????? + //?? + set_damage_num(a2, 0, -64); + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + ATR_CHR_NO(a0) = ATR_LONG_WORK(0, a0); //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + } + } + //????????? + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + set_damage_num(a1, 19, -112);//????? + //????????? + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) //?????? + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) //?????? + ATR_AKO_FLG(a1) = 2; + if (ATR_ATTACK_KIND(0, a0) & ATT_DEATH) //????? + ATR_LIFE(a1) = 0; //????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) //?????? + { + if (!ATR_COMBO(a1)) //???????? + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //pet????? + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + ATR_VCT_NO(a1) = 10; //????? + //?????? + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + ATR_KAISHIN(a1) = 1; //??????? + else + ATR_KAISHIN(a1) = 0; //G????? + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + //????? + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) //????? + { + ATR_LONG_WORK(1, a0) = 1; //??????? + //???????? + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; //??????? + } + if (ATR_KAISHIN(a1)) //?????? + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; //?????????? + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + //????????????? + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) || (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION)) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + { + //???????? + if (ATR_COMBO(a1) == 0) + set_damage_num(a0, 1, -64 + 16); //????? + } + //??? + play_se(252, ATR_H_POS(a0), ATR_V_POS(a0)); + //????????? + set_hit_mark(a0); + } + ATR_VCT_NO(a0) = 3; //???????? + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_VCT_NO(a1) = 1; //???????? + } + else + { + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 1: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + ATR_STIMER(a0) = 32; + else + ATR_STIMER(a0) = 64; + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[0] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + break; + case 3: + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_CHR_NO(a1) = SPR_isiware; //????? + if (pattern(a1, ANM_NOMAL_SPD, ANM_NO_LOOP)) //?????? + goto stone_shadow_100; + if (!pattern(a1, ANM_NOMAL_SPD, ANM_NO_LOOP)) //????????? + break; + stone_shadow_100: + //?????????h?? + ATR_GROUP_FLG(a0) = 10; + ATR_SPD(a0) = 6; + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + d0 = ATR_CRS(a0); + if (d0 >= 4 && d0 < BATTLKPKPLYAERNUM) + ATR_CHR_NO(a1) = 25784; //𦄨??? + else + ATR_CHR_NO(a1) = 25783; //𦄨??? + ATR_CRS(a0) -= 8; + ATR_CRS(a0) &= 31; + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_VCT_NO(a1) = 2; //?h?? + ATR_SPD(a1) = 0; + ATR_CRS(a1) = 16; + ATR_LONG_WORK(1, a1) = 30; + ATR_VCT_NO(a0)++; + //????? + a3 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + //????? + a2 = GetAction(T_PRIO_BOW - 1, sizeof(ATR_EQU)); + ATR_NAME(a2) = ATR_NAME(a0); + ATR_VCT_NO(a2) = ATR_VCT_NO(a0); + /* ?IT */ + ATR_DISP_PRIO(a2) = ATR_DISP_PRIO(a0); + /* ?????k? */ + ATR_CHR_NO(a2) = ATR_CHR_NO(a0); + /* ???t */ + ATR_CHR_ANG(a2) = ATR_CHR_ANG(a0); + ATR_BODY_WORK(0, a2) = ATR_BODY_WORK(0, a0); //???? + ATR_BODY_WORK(1, a2) = ATR_BODY_WORK(1, a0); //D????? + ATR_BODY_WORK(2, a2) = a3; //?????? + ATR_ATTACK_POW(0, a2) = ATR_ATTACK_POW(0, a0); //??? + ATR_ATTACK_PET_POW(0, a2) = ATR_ATTACK_PET_POW(0, a0); //??? + ATR_ATTACK_KIND(0, a2) = ATR_ATTACK_KIND(0, a0); //????? + ATR_H_POS(a2) = ATR_H_POS(a0); + ATR_V_POS(a2) = ATR_V_POS(a0); + ATR_CRS(a2) = (ATR_CRS(a0) + 15) & 31; + ATR_SPD(a2) = ATR_SPD(a0); + ATR_BODY_CNT(a2) = ATR_BODY_CNT(a0); + ATR_GROUP_FLG(a2) = ATR_GROUP_FLG(a0); + pattern(a2, ANM_NOMAL_SPD, ANM_LOOP); + p_missile[1] = a1; + p_missile[2] = NULL; + /* ?????k? */ + if (d0 >= 4 && d0 < BATTLKPKPLYAERNUM) + ATR_CHR_NO(a3) = 25783; //𦄨??? + else + ATR_CHR_NO(a3) = 25784; //𦄨??? + ATR_NAME(a3) = ATR_NAME(a1); + ATR_VCT_NO(a3) = ATR_VCT_NO(a1); + ATR_BODY_WORK(1, a3) = a2; //?s??????? + ATR_VCT_NO(a3) = ATR_VCT_NO(a1); + ATR_DISP_PRIO(a3) = ATR_DISP_PRIO(a1); + ATR_SPD(a3) = ATR_SPD(a1); + ATR_CRS(a3) = ATR_CRS(a1); + ATR_H_POS(a3) = ATR_H_POS(a1); + ATR_V_POS(a3) = ATR_V_POS(a1); + ATR_LONG_WORK(1, a3) = 30; + break; + case 4: + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + if (!--ATR_GROUP_FLG(a0)) //??? + { + //???? + ATR_LONG_WORK(2, a0) = 60; + ATR_LONG_WORK(3, a0) = 1; + ATR_VCT_NO(a0) = 7; + } + break; + case 5: + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_VCT_NO(a1) = 4; + //??? + ATR_VCT_NO(a0)++; + break; + case 6: + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) //r??????? + { + if (!ATR_LONG_WORK(1, a0)) //?????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + p_missile[0] = NULL; // + p_missile[1] = NULL; // + a1 = ATR_BODY_WORK(2, a0); //?????? + DeathAction(a1); //? + } + case 7: + if (ATR_LONG_WORK(3, a0)) + { + ATR_LONG_WORK(3, a0) = 0; + //??? + play_se(251, ATR_H_POS(a0), ATR_V_POS(a0)); + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_VCT_NO(a1) = 4; + } + if (!--ATR_LONG_WORK(2, a0)) //??? + { + if (ATR_LONG_WORK(1, a0)) //??????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + ATR_VCT_NO(a0) = 5; + } + } +} + +//Terry add 2001/12/31 +/* ӰӴ *******************************************************************/ +#ifdef _ITEM_FIRECREAKER +void firecracker_shadow(ACTION *a0) +{ + ACTION *a1; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(0, a0); //˵λַ + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //״(·) + ATR_CRS(a0) = d0; //· + //׼ + if (!--ATR_GROUP_FLG(a0)) + { + ATR_VCT_NO(a0) = 1; //???????? + a1 = ATR_BODY_WORK(2, a0); //?????? + ATR_VCT_NO(a1) = 1; //???????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 0; //??? + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //Ӱӽ + ATR_CHR_NO(a1) = 101121; //ը + ATR_H_POS(a1) += 50; + } + else + { + ATR_INT_WORK2(a0) = ATR_H_POS(a0); //?h?? + ATR_INT_WORK3(a0) = ATR_V_POS(a0); // + gemini(a0); //?h + ATR_INT_WORK2(a0) = ATR_H_POS(a0) - ATR_INT_WORK2(a0); + ATR_INT_WORK3(a0) = ATR_V_POS(a0) - ATR_INT_WORK3(a0); + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + } + break; + case 1: + a1 = ATR_BODY_WORK(2, a0); //λַ + if (!pattern(a1, 36, ANM_NO_LOOP)) //δ + break; + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_NAME(a1) == NULL || ATR_VCT_NO(a1) >= VCT_NO_DIE || ATR_VCT_NO(a1) == 0) + { //r??????? + if (!ATR_LONG_WORK(1, a0)) //?????? + ATR_STIMER(ATR_BODY_WORK(1, a0)) = 1; //??? + DeathAction(a0); //? + p_missile[0] = NULL; // + p_missile[1] = NULL; // + a1 = ATR_BODY_WORK(2, a0); //?????? + DeathAction(a1); //? + } + break; + } +} +#endif +//Terry end + +/* ?????? *******************************************************************/ +void missile(ACTION *a0) +{ + ACTION *a1, *a2; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + //??????? + if (d1 <= 32) + { + a2 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_LIFE(a2) <= 0) //?????? + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + break; + } + //???? + if ((ATR_ATTACK_POW(0, a0) == 0) && (ATR_ATTACK_PET_POW(0, a0) == 0)) + { + a2 = ATR_BODY_WORK(0, a0); //???????? + //?? + set_damage_num(a2, 0, -64); + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + break; + } + ATR_CRS(a1) = d0; //????????????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) //?????? + { + if (!ATR_COMBO(a1)) //???????? + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //pet????? + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + ATR_VCT_NO(a1) = 10; //????? + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); // + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); // + //????? + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0) //????? + { + ATR_KAISHIN(a1) = 1; //??????? + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; //?????????? + } + else + { + ATR_KAISHIN(a1) = 0; //G????? + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + } + ATR_VCT_NO(a0) = 1; //???????? + //??? + play_se(103, 320, 240); + //?????? + a1 = GetAction(T_PRIO_MAGIC_EFFECT, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ + ATR_NAME(a1) = magic_effect; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MAGIC_EFFECT; + ATR_CHR_NO(a1) = 36009; + /* ???t */ + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); + } + else + gemini(a0); //?h + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 1: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + ATR_STIMER(a0) = 64; + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[ATR_BODY_CNT(a0)] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_DAMAGE(p_master)++; //??? + DeathAction(a0); //? + break; + } +} + +/* ???? *******************************************************************/ +void amelioration(ACTION *a0) +{ + ACTION *a1; + int d0, d1; + + switch (ATR_VCT_NO(a0)) + { + case 0: + if (ATR_INT_WORK0(a0) == 0) //??q?? + { + d0 = 310; + d1 = 222; + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2)) //???? + ATR_INT_WORK0(a0) = 1; //????? + } + else + { + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar2(a0, d0, d1, 1); //???? + if (ATR_INT_WORK1(a0) == 0) //???????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + if (d0 == ATR_CRS(a0)) //?????? + ATR_INT_WORK1(a0) = 1; //???????? + //??????? + if (d1 <= 32) + { + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_LIFE(a1) <= 0) //?????? + { + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 1; //???????? + break; + } + ATR_COUNTER(a1) = NULL; //???????? + ATR_VCT_NO(a1) = 15; //??? + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_KAISHIN(a1) = 0; //??????? + ATR_VCT_NO(a0) = 1; //???????? + //??? + play_se(100, 320, 240); + //?????? + a1 = GetAction(T_PRIO_MAGIC_EFFECT, sizeof(ATR_EQU)); + if (a1 == NULL) + return; + /* ??? */ + ATR_NAME(a1) = magic_effect; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MAGIC_EFFECT; + /* ?????k? */ + ATR_CHR_NO(a1) = 36009; + /* ???t */ + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); + } + else + gemini(a0); //?h + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 1: + if (--ATR_HIT_STOP(a0)) //?????????? + break; + ATR_STIMER(a0) = 64; + ATR_VCT_NO(a0) = 2; + a0->atr = ACT_ATR_HIDE; + p_missile[ATR_BODY_CNT(a0)] = NULL; + break; + case 2: + if (--ATR_STIMER(a0)) + break; + ATR_DAMAGE(p_master)++; //??? + DeathAction(a0); //? + break; + } +} + +// ???{??? ////////////////////////////////////////////////////////////// +typedef int CMPFUNC(const void*, const void*); +int sort_chr(SORT_CHR_EQU *a0, SORT_CHR_EQU *a1) +{ + if (a0->v_pos > a1->v_pos) + return 1; + else + return -1; +} + +extern int piyo_tbl[]; +extern int piyo_point; +//static int command_point; + +/*------------------------------------------- + ?????????????? + --------------------------------------------*/ +void set_raster_pos(ACTION *a1) +{ + int d0; + +#ifdef __ATTACK_MAGIC + int value = 0; + + // ڵлĵͼʱ + if ((g_iRunEarthQuake < 2) && (BattleMapNo < 148 || BattleMapNo > 150)) + return; + if (2 == g_iRunEarthQuake) + value = g_iCurRunEarthQuake; + else if (3 == g_iRunEarthQuake) + { + ATR_INT_WORK3(a1) = 0; + return; + } + d0 = ATR_V_POS(a1) >> 3; + d0 += piyo_point + value; + d0 &= 63; + ATR_V_POS(a1) -= piyo_tbl[d0]; + ATR_INT_WORK1(a1) -= piyo_tbl[d0]; + ATR_INT_WORK3(a1) = piyo_tbl[d0]; +#else + //?????????????? + if (BattleMapNo < 148 || BattleMapNo > 150) + return; + d0 = ATR_V_POS(a1) >> 3; + d0 += piyo_point; + d0 &= 63; + ATR_V_POS(a1) -= piyo_tbl[d0]; + ATR_INT_WORK1(a1) -= piyo_tbl[d0]; + ATR_INT_WORK3(a1) = piyo_tbl[d0]; +#endif +} + +/*------------------------------------------- + ???k????? + --------------------------------------------*/ +static int get_num(void) +{ + int d0 = 0; + int d1 = 0; + + while (1) + { + d0 = BattleCmd[command_point++]; + if (d0 == NULL) + return -1; + if (d0 >= '0' && d0 <= '9') //??? + break; //?????? + if (d0 >= 'A' && d0 <= 'F') //????? + break; //?????? + } + if (d0 >= 'A') //????? + d1 = d0 - 'A' + 10; + else + d1 = d0 - '0'; + while (1) + { + d0 = BattleCmd[command_point++]; //??????? + if (d0 == NULL) //??? + { + command_point--; + break; + } + if (d0 < '0' || d0 > '9') //?????? + { + if (d0 < 'A' || d0 > 'F') //???????? + break; //? + } + d1 = d1 << 4; //??????? + if (d0 >= 'A') //????? + d1 += d0 - 'A' + 10; + else + d1 += d0 - '0'; + } + return d1; +} +//andy_add +static int get_mpnum(char code) +{ + int d0, d1, num = 0; + + while (1) + { + d0 = BattleCmd[num++]; + if (d0 == NULL) + return -1; + if (d0 == (int)code) + break; + } + + while (1) + { + d0 = BattleCmd[num++]; //???? + if (d0 == NULL) //??? + return -1; + if (d0 >= '0' && d0 <= '9') //??? + break; //?????? + if (d0 >= 'A' && d0 <= 'F') //????? + break; //?????? + } + if (d0 >= 'A') //????? + d1 = d0 - 'A' + 10; + else + d1 = d0 - '0'; + + while (1) + { + d0 = BattleCmd[num++]; //??????? + if (d0 == NULL) //??? + { + command_point--; + break; + } + if (d0 < '0' || d0 > '9') //?????? + { + if (d0 < 'A' || d0 > 'F') //???????? + break; //? + } + d1 = d1 << 4; //??????? + if (d0 >= 'A') //????? + d1 += d0 - 'A' + 10; + else + d1 += d0 - '0'; + } + return d1; +} +/*------------------------------------------- + ????????? + --------------------------------------------*/ +static char get_command(void) +{ + int now_point = 0; + char d0; + + while (1) + { + now_point = command_point; + d0 = BattleCmd[command_point++]; + if (d0 == NULL) + return -1; + if (d0 == 'B') + { + //andy_reEdit 2003/07/18 21:54 + if (BattleCmd[now_point + 2] == '|' && (BattleCmd[now_point - 1] == '|' || BattleCmd[now_point - 1] == NULL)) + break; + } + } + d0 = BattleCmd[command_point++]; + return d0; +} + +static char get_char() +{ + char d0; + + d0 = BattleCmd[command_point++]; //??? + if (d0 == NULL) //?????? + return -1; //? + return d0; +} + +/* q??? *******************************************************************/ +void get_name(ACTION *a1) +{ + char d0; + char *a2; + + a2 = ATR_HANDLE(a1); + while (1) + { + d0 = BattleCmd[command_point++]; //???? + if (d0 == NULL) //??? + break; + //???? + if (d0 == '|') + break; + if (IsDBCSLeadByte(d0)) + { + *a2++ = d0; + *a2++ = BattleCmd[command_point++]; + } + else + *a2++ = d0; + } + //???? + *a2 = 0; + makeStringFromEscaped(ATR_HANDLE(a1)); +} + +/*------------------------------------------- + ?????????? + --------------------------------------------*/ +static int get_next_flg(void) +{ + int d0, d1; + + d1 = command_point; //?????????~ + d0 = get_num(); //?? + if (d0 == -1) //??? + goto get_next_flg_500; + if (d0 == 255) //??? + goto get_next_flg_500; + d0 = get_num(); //????? + goto get_next_flg_700; +get_next_flg_500: + d0 = 0; +get_next_flg_700: + command_point = d1; //??????????? + + return d0; +} + +/*------------------------------------------- + ??????? + --------------------------------------------*/ +static int get_body_cnt(void) +{ + int d0, d1, d2 = 0; + + d1 = command_point; //?????????~ + while (1) + { + d0 = get_num(); //?? + if (d0 == -1) //??? + break; + if (d0 == 255) //??? + break; + get_num(); //??????? + get_num(); //???????? + if (BattleCmd[command_point] == 'p') + get_num(); //pet???????? + d2++; //?? + } + command_point = d1; //??????????? + + return d2; +} + +/*------------------------------------------- + ??????? + --------------------------------------------*/ +static ACTION *get_body_target(void) +{ + int d0, d1; + + d1 = command_point; //?????????~ + d0 = get_num(); //?? + command_point = d1; //??????????? + if (d0 == -1) + return 0; + else + return p_party[d0]; +} + +//ȫȷϴ +int check_all_dead(void) +{ + int d0, d7; + + d0 = 10; //趨 + for (d7 = 0; d7 < 5; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) //???????????? + { + if (ATR_PET_OK(p_party[d7])) + d0 = 5; //趨 + break; + } + } + for (d7 = 0; d7 < d0; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + if (ATR_LIFE(p_party[d7]) > 0) //һǻŵ + break; +#ifdef _PETSKILL_LER + // ׶һμڶʱȫ,Ϊ + else if (ATR_CHR_NO(p_party[d7]) == 101813 || ATR_CHR_NO(p_party[d7]) == 101814) + break; +#endif +#ifdef __NEW_BATTLE_EFFECT + if (1 == ATR_EFFECT_FLAG(p_party[d7])) + break; +#endif +#ifdef _HUNDRED_KILL + //npcû + if( BattleHundredFlag == TRUE ) + break; +#endif + } + } + if (d7 == d0) //ȫ + return 1; + d0 = 20; //趨 + + for (d7 = 10; d7 < 15; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) //???????????? + { + if (ATR_PET_OK(p_party[d7])) + d0 = 15; //趨 + break; + } + } + for (d7 = 10; d7 < d0; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + if (ATR_LIFE(p_party[d7]) > 0) //һǻŵ + break; +#ifdef _PETSKILL_LER + // ׶һμڶʱȫ,Ϊ + else if (ATR_CHR_NO(p_party[d7]) == 101813 || ATR_CHR_NO(p_party[d7]) == 101814) + break; +#endif +#ifdef __NEW_BATTLE_EFFECT + if (1 == ATR_EFFECT_FLAG(p_party[d7])) + break; +#endif +#ifdef _HUNDRED_KILL + //npcû + if( BattleHundredFlag == TRUE ) + break; +#endif + } + } + if (d7 == d0) //ȫ return 1 + return 1; + return 0; //˻ return 0 +} + +//Աʾ +void disp_attrib(ACTION *a0) +{ + ACTION *a1; + + a1 = p_attrib; + switch (ATR_ATTRIB(a0)) + { + // + case 0: + ATR_ATTRIB(a1) = ACT_ATR_HIDE; //ʾ + break; + // + case 1: + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; + ATR_CHR_NO(a1) = CG_ATR_ICON_EARTH_BATTLE; + break; + //ˮ + case 2: + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; + ATR_CHR_NO(a1) = CG_ATR_ICON_WATER_BATTLE; + break; + // + case 3: + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; + ATR_CHR_NO(a1) = CG_ATR_ICON_FIRE_BATTLE; + break; + // + case 4: + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; + ATR_CHR_NO(a1) = CG_ATR_ICON_WIND_BATTLE; + break; + } + pattern(a1, ANM_NOMAL_SPD, ANM_NO_LOOP); +} + +/* ???????? *******************************************************************/ +void get_command_asc(void) +{ + char d0, d1 = 0; + char *a2; + + kanji_buf[0][0] = kanji_buf[1][0] = kanji_buf[2][0] = kanji_buf[3][0] = 0; + a2 = kanji_buf[d1]; + while (1) + { + d0 = BattleCmd[command_point++]; //???? + if (d0 == NULL) //??? + { + command_point--; + break; + } + //???? + if (d0 == '\t') + { + //???? + *a2 = 0; + d1++; + if (d1 == 4) //????? + break; + a2 = kanji_buf[d1]; + continue; + } + //???? + if (d0 == '|') + break; + if (IsDBCSLeadByte(d0)) + { + *a2++ = d0; + *a2++ = BattleCmd[command_point++]; + } + else + *a2++ = d0; + } + //???? + *a2 = 0; +} + +#ifdef __TOCALL_MAGIC +// ٻϽ +BOOL BuildToCallMagicData(ACTION *pMaster, ACTION *pAttacker) +{ + int i, idx = 0, midx, midy, count = 0; + int charidx[MAX_NUM_ATTACKED]; + + memset(&ToCallMgc, 0, sizeof(ToCallMgc)); + memset(charidx, 0, sizeof(charidx)); + + iAttackedNum = 0; + iCurAttackedFinishNum = 0; + + // B$|Attacker's No( 0 - 19 )|5711438|Attacker's MP| + + ATR_VCT_NO(pAttacker) = TOCALL_MAGIC_CASE; + ATR_MP(pAttacker) = get_num(); + // ToCallMgc.iPreMgcNum = get_num(); + // ToCallMgc.iCurMgcNum = get_num(); + ToCallMgc.iPreMgcNum = get_num(); +#ifdef _PETSKILL_LER // ׶ + if (ToCallMgc.iPreMgcNum == 101808 || ToCallMgc.iPreMgcNum == 101809) + { + if (!g_bUseAlpha) + ToCallMgc.iPreMgcNum += 53; + } +#endif + ToCallMgc.iCurMgcNum = get_num(); +#ifdef _PROFESSION_ADDSKILL + if (ToCallMgc.iCurMgcNum >= 101770 && ToCallMgc.iCurMgcNum <= 101797) + { + if (!g_bUseAlpha) + ToCallMgc.iCurMgcNum += 55; + } +#endif +#ifdef _PETSKILL_LER // ׶ + if (ToCallMgc.iCurMgcNum == 101798) + { + if (!g_bUseAlpha) + ToCallMgc.iCurMgcNum = 101853; + } + if (ToCallMgc.iCurMgcNum == 101800) + { + if (!g_bUseAlpha) + ToCallMgc.iCurMgcNum = 101854; + } + if (ToCallMgc.iCurMgcNum == 101806 || ToCallMgc.iCurMgcNum == 101807) + { + if (!g_bUseAlpha) + ToCallMgc.iCurMgcNum += 53; + } +#endif + ToCallMgc.iPostMgcNum = get_num(); + ToCallMgc.wAttackType = (WORD)get_num(); + ToCallMgc.wAttackTimeSlice = (WORD)get_num(); + ToCallMgc.wShowType = (WORD)get_num(); + // ToCallMgc.wShowType =0; + ToCallMgc.wScreenX = (WORD)get_num(); + // ToCallMgc.wScreenX = 0;//-150; + ToCallMgc.wScreenY = (WORD)get_num(); + // ToCallMgc.wScreenY = 0;//-20; + ToCallMgc.wPreMgcX = (WORD)get_num(); + ToCallMgc.wPreMgcY = (WORD)get_num(); + ToCallMgc.wPostMgcX = (WORD)get_num(); + ToCallMgc.wPostMgcY = (WORD)get_num(); + ToCallMgc.wPreMgcOnChar = (WORD)get_num(); + ToCallMgc.wCurMgcOnChar = (WORD)get_num(); + ToCallMgc.wPostMgcOnChar = (WORD)get_num(); + ToCallMgc.dwEQuake = (DWORD)get_num(); + // ToCallMgc.dwEQuake = 1; + ToCallMgc.dwEQuakeSTime = (DWORD)get_num(); + // ToCallMgc.dwEQuakeSTime = 1000; + ToCallMgc.dwEQuakeETime = (DWORD)get_num(); + // ToCallMgc.dwEQuakeETime = 4000; + ToCallMgc.wIsPostDisappear = (WORD)get_num(); + ToCallMgc.wToCallMagicNo = (WORD)get_num(); + + do + { + charidx[idx] = get_num(); + } while (0XFF != charidx[idx] && ++idx); + + if (0 == idx) + return FALSE; + + while (0X5711438 != (AttackedInfo[iAttackedNum * 4] = get_num())) + { + AttackedInfo[iAttackedNum * 4 + 1] = get_num(); + AttackedInfo[iAttackedNum * 4 + 2] = get_num(); + AttackedInfo[iAttackedNum * 4 + 3] = get_num(); + iAttackedNum++; + } + ToCallMgc.dwCurFrame1 = 0; + ToCallMgc.dwCurFrame2 = 0; + ToCallMgc.dwEQuakeSFrame = ToCallMgc.dwEQuakeSTime >> 4; + ToCallMgc.dwEQuakeEFrame = ToCallMgc.dwEQuakeETime >> 4; + + // Ƿǰ + (0XFFFFFFFF == ToCallMgc.iPreMgcNum) ? ToCallMgc.wRunPreMgc = TRUE : ToCallMgc.wRunPreMgc = FALSE; + + // λʾ + if (1 == ToCallMgc.wShowType) + { + ToCallMgc.wNumAttacks = 1; + ToCallMgc.wCurAttackNum = 0; + ToCallMgc.posAttacked[0].x = ToCallMgc.wScreenX; + ToCallMgc.posAttacked[0].y = ToCallMgc.wScreenY; + ToCallMgc.wAttackedIndex[0] = 20; // ȫԱͬʱ״̬ + ToCallMgc.wMgcFrameCount[0] = 0; + + // ĵ + for (i = 0; i < idx; i++) + ToCallMgc.wAttackedIndex[i + 1] = charidx[i]; + + ToCallMgc.wAttackedIndex[i + 1] = 0XFF; + } + // λʾ + else + { + // ķʽΪȫͬʱ + if (2 == ToCallMgc.wAttackType || 4 == ToCallMgc.wAttackType) + { + midx = 0; + midy = 0; + + for (i = 0; i < idx; i++) + { + midx += p_party[charidx[i]]->x; + midy += p_party[charidx[i]]->y; + } + midx = int(midx / idx); + midy = int(midy / idx); + ToCallMgc.wNumAttacks = 1; + ToCallMgc.wCurAttackNum = 0; + ToCallMgc.posAttacked[0].x = midx + ToCallMgc.wScreenX; + ToCallMgc.posAttacked[0].y = midy + ToCallMgc.wScreenY; + ToCallMgc.wAttackedIndex[0] = 20; // ȫԱͬʱ״̬ + ToCallMgc.wMgcFrameCount[0] = 0; + + // ĵ + for (i = 0; i < idx; i++) + ToCallMgc.wAttackedIndex[i + 1] = charidx[i]; + ToCallMgc.wAttackedIndex[i + 1] = 0XFF; + } + // + else + { + // ĵ + for (i = 0; i < idx; i++) + { + ToCallMgc.wNumAttacks++; + ToCallMgc.posAttacked[i].x = ToCallMgc.wScreenX; + ToCallMgc.posAttacked[i].y = ToCallMgc.wScreenY; + ToCallMgc.wAttackedIndex[i] = charidx[i]; + ToCallMgc.wMgcFrameCount[i] = count; + count += ToCallMgc.wAttackTimeSlice >> 4; + } + } + } + ATR_VCT_NO(pAttacker) = TOCALL_MAGIC_CASE; + ATR_BODY_CNT(pMaster) = 1; + bRunToCallMgc = TRUE; + + return TRUE; +} + + +// ̬µħ +BOOL RunTimeMagicToCall() +{ + // ʼ + if (ToCallMgc.dwEQuakeSFrame == ToCallMgc.dwCurFrame1) + { + g_iRunEarthQuake = 1; + g_iNumRunEarthQuake = ToCallMgc.dwEQuakeEFrame - ToCallMgc.dwEQuakeSFrame; + } + + // + if (ToCallMgc.dwEQuakeEFrame == ToCallMgc.dwCurFrame1) + g_iRunEarthQuake = 3; + + ToCallMgc.dwCurFrame1++; + // ǰħǷѾ + if (FALSE == ToCallMgc.wRunPreMgc) + return TRUE; + + if (ToCallMgc.wToCallMagicNo != 2) + { + // Ƿδŵ + if (ToCallMgc.wCurAttackNum < ToCallMgc.wNumAttacks) + { + while (1) + { + if (ToCallMgc.dwCurFrame2 == ToCallMgc.wMgcFrameCount[ToCallMgc.wCurAttackNum]) + { + ACTION *a0; + + a0 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + ATR_NAME(a0) = monster; + ATR_VCT_NO(a0) = TOCALL_MAGIC_CASE + 2; // ִ + ATR_DISP_PRIO(a0) = (1 == ToCallMgc.wCurMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a0) = ToCallMgc.iCurMgcNum; + ATR_LONG_WORK(0, a0) = ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]; + ATR_H_POS(a0) = (20 == ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]) ? ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].x : ATR_H_POS(p_party[ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]]) + ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].x; + ATR_V_POS(a0) = (20 == ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]) ? ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].y : ATR_V_POS(p_party[ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]]) + ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].y; + + if (ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum] < 10) + ATR_CHR_ANG(a0) = (7); + else if (ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum] < 20) + ATR_CHR_ANG(a0) = (3); +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum] < 30) + ATR_CHR_ANG(a0) = (1); + else if (ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum] < 40) + ATR_CHR_ANG(a0) = (5); +#endif + ToCallMgc.wCurAttackNum++; + } + if (ToCallMgc.wCurAttackNum >= ToCallMgc.wNumAttacks || ToCallMgc.wMgcFrameCount[ToCallMgc.wCurAttackNum] > ToCallMgc.dwCurFrame2) + break; + } + } + } + else + { + // Ƿδŵ + if (ToCallMgc.wCurAttackNum < ToCallMgc.wNumAttacks) + { + while (1) + { + if (ToCallMgc.dwCurFrame2 == ToCallMgc.wMgcFrameCount[ToCallMgc.wCurAttackNum]) + { + ACTION *a0; + + a0 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + ATR_NAME(a0) = monster; + ATR_VCT_NO(a0) = TOCALL_MAGIC_CASE + 2; // ִ + ATR_DISP_PRIO(a0) = (1 == ToCallMgc.wCurMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a0) = ToCallMgc.iCurMgcNum; +#ifdef _PROFESSION_ADDSKILL + if (g_bUseAlpha) + { + if (ToCallMgc.iCurMgcNum == 101770 || ToCallMgc.iCurMgcNum == 101771)//ΪƳͼʾ֮ + ATR_DISP_PRIO(a0) = DISP_PRIO_TILE + ToCallMgc.wCurMgcOnChar; + } + else + { + if (ToCallMgc.iCurMgcNum == 101825 || ToCallMgc.iCurMgcNum == 101826)//ΪƳͼʾ֮ + ATR_DISP_PRIO(a0) = DISP_PRIO_TILE + ToCallMgc.wCurMgcOnChar; + } +#endif + ATR_LONG_WORK(0, a0) = ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]; + ATR_H_POS(a0) = (20 == ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]) ? ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].x : ATR_H_POS(p_party[ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]]) + ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].x; + ATR_V_POS(a0) = (20 == ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]) ? ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].y : ATR_V_POS(p_party[ToCallMgc.wAttackedIndex[ToCallMgc.wCurAttackNum]]) + ToCallMgc.posAttacked[ToCallMgc.wCurAttackNum].y; + ToCallMgc.wCurAttackNum++; + } + if (ToCallMgc.wCurAttackNum >= ToCallMgc.wNumAttacks || ToCallMgc.wMgcFrameCount[ToCallMgc.wCurAttackNum] > ToCallMgc.dwCurFrame2) + break; + } + } + } + ToCallMgc.dwCurFrame2++; + + return TRUE; +} +#endif + +#ifdef _PROFESSION_ADDSKILL +BOOL BuildBoundaryMagicData(int state) +{ + int stateno[] = {101789,101777,101783,101795,101786,101774,101780,101792}; + int mark=-1; + + if (!g_bUseAlpha) + { + if (state > 1) + state += 55; + stateno[0] = 101844, stateno[1] = 101832, stateno[2] = 101838, stateno[3] = 101850, + stateno[4] = 101841, stateno[5] = 101829, stateno[6] = 101835, stateno[7] = 101847; + } + if (state == 0)// + { + if (boundary_mark[0]) + { + DeathAction(boundary_mark[0]); + boundary_mark[0] = NULL; + } + bRunBoundaryMgc_l = 0; + } + if (state == 1)// + { + if (boundary_mark[1]) + { + DeathAction(boundary_mark[1]); + boundary_mark[1] = NULL; + } + bRunBoundaryMgc_r = 0; + } + if (state == stateno[0] // + || state == stateno[1] + || state == stateno[2] + || state == stateno[3]) + { + if (bRunBoundaryMgc_l != state) + { + if (boundary_mark[0]) + { + DeathAction(boundary_mark[0]); + boundary_mark[0] = NULL; + } + bRunBoundaryMgc_l = state; + if (boundary_mark[0] == NULL) + { + boundary_mark[0] = MakeAnimDisp(320, 240, state + 2, 0); + boundary_mark[0]->actNo = 0; + boundary_mark[0]->anim_ang = 3; + boundary_mark[0]->dispPrio = DISP_PRIO_TILE + 1;//ͼ + } + } + } + + if (state == stateno[4] //ҵ + || state == stateno[5] + || state == stateno[6] + || state == stateno[7]) + { + if (bRunBoundaryMgc_l != state) + { + if (boundary_mark[1]) + { + DeathAction(boundary_mark[1]); + boundary_mark[1] = NULL; + } + bRunBoundaryMgc_r = state; + if (boundary_mark[1] == NULL) + { + boundary_mark[1] = MakeAnimDisp(320, 240, state + 2, 0); + boundary_mark[1]->actNo = 0; + boundary_mark[1]->anim_ang = 3; + boundary_mark[1]->dispPrio = DISP_PRIO_TILE + 1;//ͼ + } + } + } + + return TRUE; +} + +void RunTimeMagicBoundary(int state) +{ + int stateno[] = { 101774, 101797}; + + if (!g_bUseAlpha) + { + stateno[0] = 101829; + stateno[1] = 101852; + } + if (boundary_2 == NULL && state >= stateno[0] && state <= stateno[1]) + { + int mark = state + 1; + + boundary_2 = MakeAnimDisp(320, 240, mark, 0); + boundary_2->actNo = 0; + boundary_2->anim_ang = 3; + boundary_2->dispPrio = DISP_PRIO_TILE + 1;//ͼ + } + + /*if ( boundary_r->anim_cnt == 10 ){//ŵһ + DeathAction(boundary_r); + boundary_r = NULL; + bRunBoundaryMgc = FALSE; + }*/ +} +#endif + +#ifdef __ATTACK_MAGIC +// ʾǰλ +static int SortIdx(const void *pElement1, const void *pElement2) +{ + int nth1 = *((int*)pElement1); + int nth2 = *((int*)pElement2); + + if (p_party[nth1]->y < p_party[nth2]->y) + return -1; + else if (p_party[nth1]->y > p_party[nth2]->y) + return 1; + + return 0; +} + +// Ͻ +BOOL BuildAttackMagicData(ACTION *pMaster, ACTION *pAttacker) +{ + int i, idx = 0, midx, midy, count = 0; + int charidx[MAX_NUM_ATTACKED]; + + memset(&AttMgc, 0, sizeof(AttMgc)); + memset(charidx, 0, sizeof(charidx)); + + iAttackedNum = 0; + iCurAttackedFinishNum = 0; + + // BJ|Attacker's No( 0 - 19 )|12345678|Attacker's MP| + + ATR_VCT_NO(pAttacker) = ATTACK_MAGIC_CASE; + ATR_MP(pAttacker) = get_num(); + AttMgc.iPreMgcNum = get_num(); + AttMgc.iCurMgcNum = get_num(); + AttMgc.iPostMgcNum = get_num(); + AttMgc.wAttackType = (WORD)get_num(); + AttMgc.wAttackTimeSlice = (WORD)get_num(); + AttMgc.wShowType = (WORD)get_num(); + AttMgc.wScreenX = (WORD)get_num(); + AttMgc.wScreenY = (WORD)get_num(); + AttMgc.wPreMgcX = (WORD)get_num(); + AttMgc.wPreMgcY = (WORD)get_num(); + AttMgc.wPostMgcX = (WORD)get_num(); + AttMgc.wPostMgcY = (WORD)get_num(); + AttMgc.wPreMgcOnChar = (WORD)get_num(); + AttMgc.wCurMgcOnChar = (WORD)get_num(); + AttMgc.wPostMgcOnChar = (WORD)get_num(); + AttMgc.dwEQuake = (DWORD)get_num(); + AttMgc.dwEQuakeSTime = (DWORD)get_num(); + AttMgc.dwEQuakeETime = (DWORD)get_num(); + + do + { + charidx[idx] = get_num(); + } while (0XFF != charidx[idx] && ++idx); + + if (0 == idx) + return FALSE; + + while (0X12345678 != (AttackedInfo[iAttackedNum * 4] = get_num())) + { + AttackedInfo[iAttackedNum * 4 + 1] = get_num(); + AttackedInfo[iAttackedNum * 4 + 2] = get_num(); + AttackedInfo[iAttackedNum * 4 + 3] = get_num(); + iAttackedNum++; + } + + AttMgc.dwCurFrame1 = 0; + AttMgc.dwCurFrame2 = 0; + AttMgc.dwEQuakeSFrame = AttMgc.dwEQuakeSTime >> 4; + AttMgc.dwEQuakeEFrame = AttMgc.dwEQuakeETime >> 4; + + // Ƿǰ + (0XFFFFFFFF == AttMgc.iPreMgcNum) ? AttMgc.wRunPreMgc = TRUE : AttMgc.wRunPreMgc = FALSE; + + // λʾ + if (1 == AttMgc.wShowType) + { + AttMgc.wNumAttacks = 1; + AttMgc.wCurAttackNum = 0; + AttMgc.posAttacked[0].x = AttMgc.wScreenX; + AttMgc.posAttacked[0].y = AttMgc.wScreenY; + AttMgc.wAttackedIndex[0] = 20; // ȫԱͬʱ״̬ + AttMgc.wMgcFrameCount[0] = 0; + + // ĵ + for (i = 0; i < idx; i++) + AttMgc.wAttackedIndex[i + 1] = charidx[i]; + + AttMgc.wAttackedIndex[i + 1] = 0XFF; + } + // λʾ + else + { + // ķʽΪȫͬʱ + if (2 == AttMgc.wAttackType || 4 == AttMgc.wAttackType) + { + midx = 0; + midy = 0; + for (i = 0; i < idx; i++) + { + midx += p_party[charidx[i]]->x; + midy += p_party[charidx[i]]->y; + } + midx = int(midx / idx); + midy = int(midy / idx); + AttMgc.wNumAttacks = 1; + AttMgc.wCurAttackNum = 0; + AttMgc.posAttacked[0].x = midx + AttMgc.wScreenX; + AttMgc.posAttacked[0].y = midy + AttMgc.wScreenY; + AttMgc.wAttackedIndex[0] = 20; // ȫԱͬʱ״̬ + AttMgc.wMgcFrameCount[0] = 0; + // ĵ + for (i = 0; i < idx; i++) + AttMgc.wAttackedIndex[i + 1] = charidx[i]; + + AttMgc.wAttackedIndex[i + 1] = 0XFF; + } + // + else + { + // ĵ + for (i = 0; i < idx; i++) + { + AttMgc.wNumAttacks++; + AttMgc.posAttacked[i].x = AttMgc.wScreenX; + AttMgc.posAttacked[i].y = AttMgc.wScreenY; + AttMgc.wAttackedIndex[i] = charidx[i]; + AttMgc.wMgcFrameCount[i] = count; + count += AttMgc.wAttackTimeSlice >> 4; + } + } + } + + ATR_VCT_NO(pAttacker) = ATTACK_MAGIC_CASE; + ATR_BODY_CNT(pMaster) = 1; + bRunAttMgc = TRUE; + + return TRUE; +} + +// ̬µħ +BOOL RunTimeMagic() +{ + // ʼ + if (AttMgc.dwEQuakeSFrame == AttMgc.dwCurFrame1) + { + g_iRunEarthQuake = 1; + g_iNumRunEarthQuake = AttMgc.dwEQuakeEFrame - AttMgc.dwEQuakeSFrame; + } + // + if (AttMgc.dwEQuakeEFrame == AttMgc.dwCurFrame1) + g_iRunEarthQuake = 3; + AttMgc.dwCurFrame1++; + // ǰħǷѾ + if (FALSE == AttMgc.wRunPreMgc) + return TRUE; + // Ƿδŵ + if (AttMgc.wCurAttackNum < AttMgc.wNumAttacks) + { + while (1) + { + if (AttMgc.dwCurFrame2 == AttMgc.wMgcFrameCount[AttMgc.wCurAttackNum]) + { + ACTION *a0; + + a0 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + ATR_NAME(a0) = monster; + ATR_VCT_NO(a0) = ATTACK_MAGIC_CASE + 2; // ִ + ATR_DISP_PRIO(a0) = (1 == AttMgc.wCurMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a0) = AttMgc.iCurMgcNum; + ATR_LONG_WORK(0, a0) = AttMgc.wAttackedIndex[AttMgc.wCurAttackNum]; + ATR_H_POS(a0) = (20 == AttMgc.wAttackedIndex[AttMgc.wCurAttackNum]) ? AttMgc.posAttacked[AttMgc.wCurAttackNum].x : ATR_H_POS(p_party[AttMgc.wAttackedIndex[AttMgc.wCurAttackNum]]) + AttMgc.posAttacked[AttMgc.wCurAttackNum].x; + ATR_V_POS(a0) = (20 == AttMgc.wAttackedIndex[AttMgc.wCurAttackNum]) ? AttMgc.posAttacked[AttMgc.wCurAttackNum].y : ATR_V_POS(p_party[AttMgc.wAttackedIndex[AttMgc.wCurAttackNum]]) + AttMgc.posAttacked[AttMgc.wCurAttackNum].y; + AttMgc.wCurAttackNum++; + } + if (AttMgc.wCurAttackNum >= AttMgc.wNumAttacks || AttMgc.wMgcFrameCount[AttMgc.wCurAttackNum] > AttMgc.dwCurFrame2) + break; + } + } + AttMgc.dwCurFrame2++; + + return TRUE; +} +#endif + +//ж +void master(ACTION *a0) +{ + ACTION *a1, *a2, *a3; + int d0, d1, d2, d3, d6, d7; + int z = 0; + int jjj = 0; + int command_no; + int sav_command_point, castflg = 0; + int petfall_flg = 0; + + //Աʾ + disp_attrib(a0); + if (ATR_VCT_NO(a0) == 0) // ȷ + { + if (BattleCmd[0] == NULL) //սȷ + goto master_500; + } + switch (ATR_VCT_NO(a0)) + { + case 0: //????D? + sav_command_point = command_point; //??????????~ + command_no = get_command(); //?????? + if (command_no == -1) //??? + { + ATR_VCT_NO(a0) = 4; //????r?? + command_point = 0; //????????????? + break; + } + if (command_no == ATT_KANJI) //???? + { + if (p_kanji != NULL) //??? + { + a1 = ATR_BODY_WORK(0, p_kanji); //?????? + DeathAction(a1); // + } + else + { + p_kanji = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (p_kanji == NULL) + return; + } + //BOX + a1 = MakeWindowDisp(640 - 4 - 64 * 4, 4, 4, 2, 0, 2); + //岻ʧ + if (a1 == NULL) + return; + ATR_BODY_WORK(0, p_kanji) = a1; //?????V + ATR_NAME(p_kanji) = disp_kanji; //?????? + ATR_ATTRIB(p_kanji) = ACT_ATR_HIDE; //?? + // ???????? + play_se(202, 320, 240); + command_point++; //?????????? + //????????? + get_command_asc(); + d0 = 60; //??? + for (d7 = 0; d7 < 4; d7++) + { + if (kanji_buf[d7][0]) //?????? + d0 += 60; //??? + } + ATR_INT_WORK0(p_kanji) = d0; + ATR_VCT_NO(a0) = 1; //????r? + ATR_BODY_CNT(a0) = 1; + ATR_DAMAGE(a0) = 0; + ATR_PET_DAMAGE(a0) = 0; + break; + } + if (command_no == ATT_EFFECT) + { +#ifdef __NEW_BATTLE_EFFECT + // Bj | target(who) | effect(effect no) | effect_anim | param | .... | FF + ACTION *target = NULL; + int who; + int effect; + int effect_anim; + int param; + + ATR_VCT_NO(a0) = 1; + while (1) + { + who = get_num(); + if (who == 255) + break; + effect = get_num(); //Чı + effect_anim = get_num(); //ЧĶ + param = get_num(); // + target = NULL; + if (who < BATTLKPKPLYAERNUM) + target = p_party[who]; + if (target) + { + ATR_EFFECT_FLAG(target) = effect; + ATR_EFFECT_ANIM(target) = effect_anim; + ATR_EFFECT_PARAM(target) = param; + ATR_BODY_CNT(a0)++; + } + } +#endif + break; + } +#ifdef _PETSKILL_BATTLE_MODEL + if (command_no == ATT_BATTLE_MODEL) // \սģ + { + ATR_VCT_NO(a0) = 1; + ATR_PET_DAMAGE(a0) = 0; + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + ATR_SYNC_FLG(p_party[d7]) = 0; + ATR_ATTACK_KIND(0, p_party[d7]) = 0; + ATR_ATTACK_KIND(1, p_party[d7]) = 0; + ATR_ATTACK_POW(0, p_party[d7]) = 0; + ATR_ATTACK_PET_POW(0, p_party[d7]) = 0; + ATR_MPDAMAGE(p_party[d7]) = 0; + ATR_MPDFLG(p_party[d7]) = 0; + ATR_ADDHP(p_party[d7]) = 0; + ATR_ADDHPFLG(p_party[d7])=0; + ATR_SHOWADDHP(p_party[d7])=0; + ATR_LONG_WORK(0, p_party[d7]) = 0; + ATR_BATTLE_MODEL(p_party[d7]) = 0; + memset(&ATR_BODY_WORK(0, p_party[d7]), 0, sizeof(ACTION*) * 20); + memset(p_missile, 0, sizeof(p_missile)); + } + d7 = 0; + // ȡij + d0 = get_num(); + a3 = p_party[d0]; + // жϹϻʼλ + if (ATR_GROUP_FLG(a3) == 0) + { + d2 = 3; // + d0 = 0; + } + else + { + d2 = 7; // + d0 = 10; + } + // ȡĿ깥 + a1 = NULL; + while ((d6 = get_num()) != 255) + { + a1 = p_party[d6]; + if (ATR_VCT_NO(a1) != 55) + ATR_FIRST_FLG(a1) = 0; + ATR_ATTACK_KIND(2, a1) = 0; + d3 = get_num(); // ȡ + // ж p_missile[d3] ûʹ + // ʹ,ʾҪĿ + if (p_missile[d3] != NULL) + { + a2 = p_missile[d3]; + ATR_BODY_WORK(ATR_INT_WORK1(a2), a2) = a1; // + ATR_BATTLE_MODEL(a1) = ATT_BATTLE_MODEL; // ĿDZ ATT_BATTLE_MODEL ̬ + ATR_ATTACK_KIND(ATR_INT_WORK1(a2), a2) = get_num(); // + ATR_ATTACK_POW(ATR_INT_WORK1(a2), a2) = get_num(); // + ATR_ATTACK_PET_POW(ATR_INT_WORK1(a2), a2) = get_num(); // pet + ATR_CHR_NO(a2) = get_num(); // ͼ + // ȮЧ,¼ʹȮĿ + if (BattleCmd[command_point] == 'g') + ATR_LONG_WORK(ATR_INT_WORK1(a2), a2) = get_num(); + ATR_INT_WORK1(a2)++; + // ¼Ŀб˹ + if (ATR_LONG_WORK(0, a1) == 0) + { + ATR_LONG_WORK(0, a1) = 1; // ATR_LONG_WORK λ : λַ 0 : 趨ĿǷ񱻹,Զ趨Ϊ1 + ATR_LONG_WORK(d3, a1) = d7 + 1; // λַ d3: d3 ǹı, d3 λַ + // ¼ڵ d7 + 1 ĻغϹĿ + } + else + ATR_LONG_WORK(d3, a1) = d7 + 1; // ATR_LONG_WORK λ 0 Ϊ 0 ʱ,ʾĿѱĹ, + // ֱ d3 λַ¼Ҫ d7 + 1 ĻغϹĿ + } + // ûʹù + else + { + p_missile[d3] = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (p_missile[d3] == NULL) + break; // ̫ + a2 = p_missile[d3]; + // ʼ + ATR_NAME(a2) = monster; + ATR_CHR_ANG(a2) = d2; + ATR_H_POS(a2) = monster_start_pos[monster_place_no[d3 + d0] * 2]; + ATR_V_POS(a2) = monster_start_pos[monster_place_no[d3 + d0] * 2 + 1]; + + ATR_CHR_ACT(a2) = ANIM_STAND; + ATR_GROUP_FLG(a2) = ATR_GROUP_FLG(a3); + a2->hitDispNo = a3->hitDispNo; + ATR_VCT_NO(a2) = 1; // ǰ + ATR_BODY_WORK(0, a2) = a1; // Ŀ + ATR_BATTLE_MODEL(a1) = ATT_BATTLE_MODEL; // ĿDZ ATT_BATTLE_MODEL ̬ + // ¼Ŀб˹ + if (ATR_LONG_WORK(0, a1) == 0) + { + ATR_LONG_WORK(0, a1) = 1; // ATR_LONG_WORK λ : λַ 0 : 趨ĿǷ񱻹,Զ趨Ϊ1 + ATR_LONG_WORK(d3, a1) = d7 + 1; // λַ d3: d3 ǹı, d3 λַ + // ¼ڵ d7 + 1 ĻغϹĿ + } + else + ATR_LONG_WORK(d3, a1) = d7 + 1; // ATR_LONG_WORK λ 0 Ϊ 0 ʱ,ʾĿѱĹ, + // ֱ d3 λַ¼Ҫ d7 + 1 ĻغϹĿ + ATR_ATTACK_KIND(0, a2) = get_num(); // + ATR_ATTACK_POW(0, a2) = get_num(); // + ATR_ATTACK_PET_POW(0, a2) = get_num(); // pet + ATR_CHR_NO(a2) = get_num(); // ͼ + ATR_PLACE_NO(a2) = d3; // ¼ + ATR_INT_WORK0(a2) = ATT_BATTLE_MODEL; // 趨 action ATT_BATTLE_MODEL ʹ,Է֮ıʶ,ʹ work0 ¼ + ATR_INT_WORK1(a2) = 1; // 趨˹ĿǰĿ,ʹ work1¼ + ATR_INT_WORK2(a2) = 0; // ΪǷһִ뿪 + ATR_INT_WORK3(a2) = 0; // ΪȮټȮ + // ȮЧ,¼ʹȮĿ + if (BattleCmd[command_point] == 'g') + ATR_LONG_WORK(0, a2) = get_num(); + ATR_SPD(a2) = 32; // ƶٶ + } + d7++; + } + ATR_COUNTER(a0) = a1; + ATR_DAMAGE(a0) = -d7; // Ϊ,ʱ ATR_DAMAGE(p_master) ATR_BODY_CNT(p_master) + ATR_INT_WORK1(a0) = 0; // ȷ p_missile Ƿ񶼱 + ATR_INT_WORK2(a0) = 1; // ʱ˳,ȴ ATR_LONG_WORK Ϊ 1 ִ + ATR_BODY_CNT(a0) = d7; // ܴ,ÿһζ ATR_DAMAGE(p_master) ,ֱ ATR_DAMAGE(p_master) == ATR_BODY_CNT(p_master) + // p_master Żȥһ BattleCmd ( a0 p_master) + break; + } +#endif + d0 = get_num(); //?????k? + if (d0 < 0 || d0 >= BATTLKPKPLYAERNUM) //????k??? + { + if (command_no == ATT_VARIABLE) //tNͨ??? + { + ATR_ATTRIB(p_master) = get_num(); //N?? + break; + } + else + { +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "command_no != ATT_VARIABLE", "Error", MB_OK); +#endif + break; + } + } + a1 = p_party[d0]; //??????? + if (ATR_NAME(a1) == NULL) //??????????????? + { +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ATR_NAME(a1) == NULL", "Error", MB_OK); +#endif + command_no = get_command(); //?????? + if (command_no == -1) //??? + { + ATR_VCT_NO(a0) = 4; //????r?? + command_point = 0; //????????????? + break; + } + command_point -= 2; //?????????? + break; + } + if (command_no != ATT_MALFUNCTION) //?????? + { + if (ATR_LIFE(a1) <= 0) //?????? + ATR_VCT_NO(a1) = 0; //`?? + } + if (command_no != ATT_MALFUNCTION) //?????? + { + if (ATR_VCT_NO(a1) != 0) //r?֢t? command_point = sav_command_point; //????r? + break; + } + ATR_VCT_NO(a0) = 1; //s?~r?? + ATR_DAMAGE(a0) = 0; + ATR_PET_DAMAGE(a0) = 0; + ATR_COUNTER(a0) = a1; //?????V + //????????????? + if (ATR_VCT_NO(a1) != 55) + ATR_FIRST_FLG(a1) = 0; //???????? + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) //?????? + { + ATR_SYNC_FLG(p_party[d7]) = 0; + ATR_ATTACK_KIND(0, p_party[d7]) = 0; + ATR_ATTACK_KIND(1, p_party[d7]) = 0; + ATR_ATTACK_POW(0, p_party[d7]) = 0; + ATR_ATTACK_PET_POW(0, p_party[d7]) = 0; + //andy_mp + ATR_MPDAMAGE(p_party[d7]) = 0; + ATR_MPDFLG(p_party[d7]) = 0; + ATR_ADDHP(p_party[d7]) = 0; + ATR_ADDHPFLG(p_party[d7]) = 0; + ATR_SHOWADDHP(p_party[d7]) = 0; +#ifdef _PETSKILL_BATTLE_MODEL + ATR_BATTLE_MODEL(p_party[d7]) = 0; + ATR_BODY_WORK(0, p_party[d7]) = NULL; +#endif + } + //?????? + ATR_ATTACK_KIND(2, a1) = 0; + switch (command_no) + { + // BI jibun_5 teki_F flg_2 damage_1 teki_9 flg_2 damage_1 FF + case ATT_IN: //?????????? ??? ?????????? + if (ATR_GROUP_FLG(a1) == 0) //???????? + { + ATR_V_POS(a1) = 8; + ATR_H_POS(a1) = -SCREEN_OUT; + } + else + { + ATR_V_POS(a1) = lpDraw->ySize - 8; + ATR_H_POS(a1) = lpDraw->xSize + SCREEN_OUT; + } + case ATT_HIT: //====================ֱӹ=============== + ATR_VCT_NO(a1) = 1; //ǰ + ATR_BODY_WORK(0, a1) = p_party[get_num()]; // + ATR_ATTACK_KIND(0, a1) = get_num(); // + ATR_ATTACK_POW(0, a1) = get_num(); // + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet +#ifdef _STONDEBUG_ + else + LogToBattleError( BattleCmd, __LINE__ ); +#endif + ATR_BODY_CNT(a0) = 1; +#ifdef _ATTDOUBLE_ATTACK + //andy_add + if (ATR_ATTACK_KIND(0, a1) & ATT_ATTDOUBLE || ATR_ATTACK_KIND(0, a1) & BCF_MODIFY) + ATR_BATTLEGRANO(a1) = get_num(); +#endif +#ifdef _ATTACK_EFFECT + //Ȯ xiezi + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + break; +#ifdef _MAGIC_DEEPPOISION + case ATT_DEEPPOISION: //綾 + ATR_VCT_NO(a1) = 1; // + ATR_BODY_WORK(0, a1) = p_party[get_num()];// //???? + ATR_ATTACK_KIND(0, a1) = get_num(); //ҷ?????? + ATR_ATTACK_POW(0, a1) = get_num(); //?????? + ATR_ATTACK_PET_POW(0, a1) = get_num();// + ATR_BODY_CNT(a0) = 1;// + ATR_DEEPPOISION(a1) = 1; + break; +#endif + //andy_mp + case ATT_MPDAMAGE://MP˺ + ATR_VCT_NO(a1) = 1; + ATR_BODY_WORK(0, a1) = p_party[get_num()]; + ATR_ATTACK_KIND(0, a1) = get_num(); + ATR_ATTACK_POW(0, a1) = get_num(); + ATR_ATTACK_PET_POW(0, a1) = get_num(); + ATR_MPDAMAGE(a1) = get_num(); + ATR_BODY_CNT(a0) = 1; + ATR_MPDFLG(a1) = 1; + break; //set_damage_num( a1, 16, -64 ) + + case ATT_DAMAGETOHP: + ATR_VCT_NO(a1) = 1; + ATR_BODY_WORK(0, a1) = p_party[get_num()]; + ATR_ATTACK_KIND(0, a1) = get_num(); + ATR_ATTACK_POW(0, a1) = get_num(); + ATR_ATTACK_PET_POW(0, a1) = get_num(); + ATR_ADDHP(a1) = get_num(); + ATR_BODY_CNT(a0) = 1; + ATR_SHOWADDHP(a1) = 1; + ATR_ADDHPFLG(a1) = 1; + break; + //BF jibun_5 + case ATT_FADE_OUT: //?????????? ??? ?????????? + ATR_VCT_NO(a1) = 80; //?~? + //?????? + ATR_ATTACK_KIND(2, a1) = 1; + ATR_BODY_CNT(a0) = 1; + break; + //BN|???k?|?????k?| + case ATT_NEXT_EQUIP: //?????????? ?? ?????????? + ATR_VCT_NO(a1) = 82; //?? + ATR_BODY_CNT(a0) = 1; + break; + //BJ|Attacker's No( 0 - 19 )|Attacker's MP|Attacker's animation index| + // Opposite's animation index|Opposite's index ... + //BJ|???k?|??|????????k?|??????????k?|?????|?????|FF + case ATT_JUJUTSU: //?????????? ?????????? + ATR_VCT_NO(a1) = 75; //??ӡua?? + ATR_MP(a1) = get_num(); //????? + ATR_BODY_CNT(a0) = 1; +#ifdef __ATTACK_MAGIC + if (ATTACK_MAGIC_ID == ATR_MP(a1)) + BuildAttackMagicData(a0, a1); +#endif + break; + case ATT_TOCALL: + ATR_VCT_NO(a1) = 2; //??ӡua?? + ATR_MP(a1) = get_num(); //????? + ATR_BODY_CNT(a0) = 1; +#ifdef __TOCALL_MAGIC + if (TOCALL_MAGIC_ID == ATR_MP(a1)) + BuildToCallMagicData(a0, a1); +#endif + break; + case ATT_MALFUNCTION: //?????????? Ol ?????????? + d0 = get_num(); //ӧk??? + ATR_STATUS(a1) = d0; //???????? + switch (d0) + { + //?? + case 0: + ATR_VCT_NO(a0) = 0; //???? + a2 = ATR_JUJUTSU_WORK(a1); + ATR_JUJUTSU_WORK(a1) = NULL; + DeathAction(a2); //? + break; + //?? + case 2: + //????? + if (ATR_LIFE(a1) > 0) + { + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 105; //??r?? + ATR_STIMER(a1) = 60; + set_single_jujutsu(d0, a1); //Ol??? + } + else + ATR_VCT_NO(a0) = 0; //???? + break; + //? + default: + ATR_VCT_NO(a0) = 0; //???? + set_single_jujutsu(d0, a1); //Ol??? + break; + } + break; + //ATR_ATTACK_KIND(a1); + /* + case ATT_MAGICSTATUS: //andy_add magicstatus + d0 = get_num(); + ATR_STATUS(a1) = d0; + switch (d0){ + case 0: + ATR_VCT_NO(a0) = 0; + a2 = ATR_MAGICSU_WORK(a1); + ATR_MAGICSU_WORK(a1) = NULL; + DeathAction( a2 ); + break; + + default: + ATR_VCT_NO(a0) = 0; + set_magic_status(d0, a1); + break; + } + break; + */ + + // ???????????????????k + case ATT_DAMAGE: + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 79; + ATR_LONG_WORK(0, a1) = 0; + d2 = d0 = get_num(); + d3 = d1 = get_num(); + att_damage_loop: + ATR_DAMAGE(a1) = get_num(); + if (BattleCmd[command_point] == 'p') + ATR_PET_DAMAGE(a1) = get_num(); //pet damage + + switch (d0) + { + case 0: //?? + switch (d1) + { + case 0: //? + set_damage_num(a1, 6, -64); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); //?????? + if (ATR_LIFE(a1) <= 0) //?????? + { + ATR_LIFE(a1) = 0; + slow_flg++; //???? + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + set_jujutsu_hit_mark(a1); // + //andy_log + if (ATR_PETFALL(a0) == 1) + { + if (ATR_LIFE(a0) > 0) + petfallChangeGraph(a0); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) //?????? + { + ATR_PET_LIFE(a1) = 0; + //slow_flg++; //???? + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + ATR_CHR_ACT(a1) = ANIM_DAMAGE; //??????????? + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; //??????? + break; + case 1: //? + //??k + set_damage_num(a1, 14, -64); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); + play_se(102, ATR_H_POS(a1), 240); + break; + //andy_add غϲѪ + case 2: + if (BattleCmd[command_point] == 'm') + ATR_MPDAMAGE(a1) = get_num(); + set_damage_num(a1, 36, -64); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + ATR_MP(a1) += ATR_MPDAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) >= ATR_PET_MAX_LIFE(a1)) + { + int k; + + k = ATR_PET_MAX_LIFE(a1); + k = ATR_PET_LIFE(a1); + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); + k = ATR_PET_LIFE(a1); + } + //ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 3: + set_damage_num(a1, 37, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 4:// + set_damage_num(a1, 38, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 5:// + set_damage_num(a1, 39, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 6:// + set_damage_num(a1, 40, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#ifdef _SKILL_ADDBARRIER + case 7:// + set_damage_num(a1, 43, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif +#ifdef _PETSKILL_PEEL + case 8://жװ + set_damage_num(a1, 44, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif +#ifdef _PETSKILL_JUSTICE + case 9: + set_damage_num(a1, 45, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif +#ifdef _PETSKILL_PROVOKEFIGHT + case 10: + set_damage_num(a1, 48, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif +#ifdef _PRO3_ADDSKILL + case 11: + set_damage_num(a1, 49, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 12: + set_damage_num(a1, 50, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 13: + set_damage_num(a1, 51, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif +#ifdef _PETSKILL_ADDATTCRAZED + /* case 10: + set_damage_num(a1, 46, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break;*/ +#endif + } + break; + + case 1: //?? + switch (d1) + { + case 0: //? + set_damage_num(a1, 16, -64); + ATR_MP(a1) -= ATR_DAMAGE(a1); //?????? + if (ATR_MP(a1) < 0) //?t??? + ATR_MP(a1) = 0; //???? + break; + case 1: //? + set_damage_num(a1, 15, -64); + ATR_MP(a1) += ATR_DAMAGE(a1); //????? + +#ifdef _FIXSHOWMPERR //Syu ADD ʱʾ + if (ATR_MP(a1) > pc.maxMp) + ATR_MP(a1) = pc.maxMp; +#else + if (ATR_MP(a1) > 100) //?????? + ATR_MP(a1) = 100; //?????? +#endif + //??? + play_se(102, ATR_H_POS(a1), 240); + break; +#ifdef _PETSKILL_ADDATTCRAZED + case 3: + set_damage_num(a1, 46, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; + case 4: + set_damage_num(a1, 47, -64); + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a1) = 78; + break; +#endif + } + break; +#ifdef _PETSKILL_LER + case 3: // + set_damage_num(a1, 0, -64); + break; +#endif + } + d6 = command_point; //????????~ + d0 = get_command(); //???????? + if (d0 == ATT_DAMAGE) //?????? + { + a1 = p_party[d0 = get_num()]; //??????? + d0 = get_num(); //??????? + if (d2 == d0) //????i??? + { + d1 = get_num(); //??????? + if (d3 == d1) //????i??? + goto att_damage_loop; + } + } + command_point = d6; //?????????? + break; + //BV|???k??????|Nͧk? + case ATT_VARIABLE: //?????????? ?????Nͨ? ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 85; //?????Nͨ?? + break; + //BR|????|???????? + case ATT_REVERSE: //?????????? NͧT ?????????? + ATR_VCT_NO(a0) = 0; //???? + d0 = get_num(); //??????????? + switch (d0) + { + //??? + case 0: + a2 = ATR_ATTRIB_WORK(a1); + ATR_ATTRIB_WORK(a1) = NULL; + DeathAction(a2); //? + break; + //?? + default: + set_attrib_reverse(a1); //NͧT??? + break; + } + break; + //BL|????|?? + case ATT_LIFE: //?????????? ?? ?????????? + ATR_VCT_NO(a0) = 0; //???? + ATR_DAMAGE(a1) = get_num(); //???? + //??k + ATR_LIFE(a1) = ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_VCT_NO(a1) = 0; //_? + ATR_CHR_ACT(a1) = ANIM_STAND; //_??????? + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + break; + //BQ|???? + case ATT_QUIT: //?????????? ???`?? ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 87; //???`??q? + break; + //BX|???? + case ATT_NIX: //?????????? ????r ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 90; //????r + break; + //B!|?????????????????? + case ATT_COMPANIONS: //?????????? s???? ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 95; //s?????? + break; + //B#|???????????? + case ATT_STEAL: //?????????? ???? ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 100; //?????? + break; + //B%|????????k? + case ATT_TALK: //?????????? ???? ?????????? + ATR_BODY_CNT(a0) = 1; + ATR_VCT_NO(a1) = 110; //????? + ATR_STIMER(a1) = 60; + d0 = get_num(); //???k??? + //????????? + set_damage_num(a1, 20, -64); + break; +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ + case ATT_FIRESKILL: + ATR_VCT_NO(a1) = FIRE_HUNTER_SKILL; //ɱ + ATR_FIRST_FLG(a1) = 0; + iBeAttNum = get_num(); + ATR_BODY_WORK(0, a1) = p_party[iBeAttNum]; //λַ + ATR_ATTACK_KIND(0, a1) = get_num(); // + ATR_ATTACK_POW(0, a1) = get_num(); // + // if ( BattleCmd[command_point] == 'p' ) { + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?? + // } + d0 = get_num(); // + ATR_BODY_CNT(a1) = d0; //˹ + for (d7 = 2; d7 < d0 + 2; d7++) + { + int x = get_num(); + + if (x == iBeAttNum) //Ŀħ˺ + { + tarMgiDem = 1; + tarpos = d7;//ATR_BODY_CNT(a1)--; + } + ATR_BODY_WORK(d7 ,a1) = p_party[x]; //λַ + ATR_ATTACK_KIND(d7 ,a1) = get_num(); // + ATR_ATTACK_POW(d7 ,a1) = get_num(); // + ATR_ATTACK_PET_POW(d7 ,a1) = get_num(); //pet + //} + } + break; +#endif +#ifdef _PROFESSION_ADDSKILL + case ATT_BOUNDARY: + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT(a0) = ANIM_STAND; + ATR_FIRST_FLG(a0) = 0; + ATR_VCT_NO(a1) = 0; //_? + ATR_CHR_ACT(a1) = ANIM_STAND; //_??????? + ATR_FIRST_FLG(a1) = 0; + d0 = get_num(); //??????????? + BuildBoundaryMagicData( d0 ); + d0 = get_num(); + break; +#endif +#ifdef _PETSKILL_RIDE + case ATT_RIDE: + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT(a0) = ANIM_STAND; + ATR_FIRST_FLG(a0) = 0; + ATR_VCT_NO(a1) = 0; //_? + ATR_CHR_ACT(a1) = ANIM_STAND; //_??????? + ATR_FIRST_FLG(a1) = 0; + d0 = get_num(); //ͼ + petrideChangeGraph(a1,d0); + d0 = get_num(); + break; +#endif + case ATT_BOW: //?????????? ??? ?????????? + ATR_VCT_NO(a1) = 30; //???? + ATR_LONG_WORK(0, a1) = get_num(); //ħk???? + if (ATR_LONG_WORK(0, a1) == 0) //??? + { + ATR_VCT_NO(a1) = 32; //???? + ATR_STIMER(a1) = 0; //???????? + ATR_DAMAGE(a1) = 1; // + ATR_PET_DAMAGE(a1) = 1; + } + ATR_FIRST_FLG(a1) = 0; // + ATR_BODY_WORK(0, a1) = p_party[get_num()]; //???? + ATR_ATTACK_KIND(0, a1) = get_num(); //?????? + ATR_ATTACK_POW(0, a1) = get_num(); //?????? + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?????? + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + + ATR_BODY_CNT(a0) = 1; +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + (ATR_CHR_NO(a1) == 101578) ? ShooterNum = 101578 : ShooterNum = -1; +#endif + break; + case ATT_BOOMERANG: //?????????? ??????? ?????????? + ATR_VCT_NO(a1) = 70; //???????? + ATR_FIRST_FLG(a1) = 0; // + ATR_BODY_CNT(a0) = 1; + break; + case ATT_FIRE: //?????????? ???? ?????????? + d0 = get_body_cnt(); //????? + if (d0 != 1) //]D???? + { + ATR_VCT_NO(a1) = 20; //???? + ATR_BODY_CNT(a0) = d0; //??D?? + ATR_BODY_CNT(a1) = d0; // + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + + } + else + { //?D???? + ATR_VCT_NO(a1) = 20; //???? + ATR_BODY_CNT(a0) = 1; //?D?? + ATR_BODY_CNT(a1) = 1; // + a2 = ATR_BODY_WORK(0, a1) = p_party[get_num()]; //? + } + break; + case ATT_SYNCHRONOUS: //?????????? i??? ?????????? + a3 = a2 = a1; //?~ + d1 = 0; //???????? + d2 = 0; + d7 = 0; //?????? + while (1) + { + d0 = get_num(); //??????? + if (d0 == 255) //??? + break; + a1 = p_party[d0]; //??????? + if (ATR_NAME(a1) == NULL) //???????? + { +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ûк幥ֽձ", "Error", MB_OK); +#endif + get_num(); //?????? + get_num(); //?????? + get_num(); //???? + if (BattleCmd[command_point] == 'p') + get_num(); //pet???? + + continue; + } + if (d7 == 0) //??????? + ATR_COUNTER(a0) = a1; //?????? + ATR_VCT_NO(a1) = 1; //q? + ATR_BODY_WORK(0, a1) = a3; //? + ATR_BODY_WORK(1, a2) = a1; //q???????????? + ATR_ATTACK_KIND(0, a1) = get_num(); +#ifdef _PETSKILL_ACUPUNCTURE + /////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a1) & ATT_REFLEX+ATT_ABSORPTION+ATT_BALLIA+ATT_TRAP+ATT_ACUPUNCTURE +#ifdef _PET_ITEM + + ATT_ATTACKBACK +#endif + ) +#else + if (ATR_ATTACK_KIND(0, a1) & ATT_REFLEX+ATT_ABSORPTION+ATT_BALLIA+ATT_ACUPUNCTURE +#ifdef _PET_ITEM + + ATT_ATTACKBACK +#endif + ) +#endif + /////////////////////// +#else + /////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a1) & ATT_REFLEX+ATT_ABSORPTION+ATT_BALLIA+ATT_TRAP) +#else + if (ATR_ATTACK_KIND(0, a1) & ATT_REFLEX + ATT_ABSORPTION + ATT_BALLIA) +#endif + /////////////////////// +#endif + { + ATR_ATTACK_POW(0, a1) = get_num(); //?????? + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?????? + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + } + else + { + d1 += ATR_ATTACK_POW(0, a1) = get_num(); //???? + if (BattleCmd[command_point] == 'p') + d2 += ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet???? + else + LogToBattleError(BattleCmd, __LINE__); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + } + ATR_FIRST_FLG(a1) = 0; //?????? + ATR_SYNC_FLG(a1) = 1; // + a2 = a1; //q???? + d7++; //???? + } + ATR_SYNC_FLG(a1) = 2; //????? + if (d1) //??????? + ATR_ATTACK_POW(0, a1) = d1; //???????? + if (d2) //??????? + ATR_ATTACK_PET_POW(0, a1) = d2; //???????? + ATR_LONG_WORK(0, a3) = d7; //?????? + ATR_BODY_CNT(a0) = d7; + break; + case 2: //?????????? ???? ?????????? + d0 = get_num(); //????? + if (d0 != 1) //??D???? + { + ATR_VCT_NO(a1) = 25; //???? + ATR_BODY_CNT(a0) = d0; //??D?? + ATR_BODY_CNT(a1) = d0; // + for (d7 = 0; d7 < d0; d7++) + { + ATR_BODY_WORK(d7, a1) = p_party[get_num()]; //? + ATR_ATTACK_KIND(d7, a1) = get_num(); //?????? + } + d0 = 320; + d1 = 240; + radar(a1, &d0, &d1); //???? + ATR_CRS(a1) = d0; /* ?????? */ + ATR_CHR_ANG(a1) = crs_change_tbl[d0]; /* ????? */ + } + else + { + ATR_VCT_NO(a1) = 25; //???? + ATR_BODY_CNT(a0) = 1; //?D?? + ATR_BODY_CNT(a1) = 1; // + ATR_BODY_WORK(0, a1) = p_party[get_num()]; //? + ATR_ATTACK_KIND(0, a1) = get_num(); //?????? + d0 = 320; + d1 = 240; + radar(a1, &d0, &d1); //???? + ATR_CRS(a1) = d0; /* ?????? */ + ATR_CHR_ANG(a1) = crs_change_tbl[d0]; /* ????? */ + } + break; + case 3: //?????????? ???? ?????????? + d0 = get_num(); //????? + ATR_VCT_NO(a1) = 30; //???? + ATR_BODY_CNT(a0) = d0; //?D?? + ATR_BODY_CNT(a1) = d0; // + for (d7 = 0; d7 < d0; d7++) + { + ATR_BODY_WORK(d7, a1) = p_party[get_num()]; //? + ATR_ATTACK_KIND(d7, a1) = get_num(); //?????? + } + break; + case ATT_TAKE: //?????????? ? ?????????? + ATR_VCT_NO(a1) = 35; //?? + ATR_BODY_WORK(0, a1) = p_party[get_num()]; //???? + ATR_ATTACK_KIND(0, a1) = get_num(); //???? + ATR_BODY_CNT(a0) = 1; + break; + case ATT_ESCAPE: //?????????? PfD ?????????? + ATR_BODY_CNT(a0) = 1; //D???? + d1 = ATR_ATTACK_KIND(0, a1) = get_num(); //???? + ATR_VCT_NO(a1) = 52; //D? + if (BattleMyNo == ATR_PLACE_NO(a1)) //?? + d0 = 1; + else + d0 = 0; + //ACTION_INF@e?????? + ATR_GUARD_FLG(a1) = 0; + //????V?ϣ?? + if (ATR_PET_OK(a1)) + { + a2 = p_party[ATR_PLACE_NO(a1) + 5]; //?????? + //?????????????????? + if (ATR_NAME(a2) != NULL && ATR_AKO_FLG(a2) == 0) + { + //????? + if (ATR_ATTACK_KIND(2, a2) == 1) + { + ATR_ATTRIB(a2) |= ACT_ATR_HIDE; //?? + //???? + ATR_NAME(a2) = NULL; + ATR_VCT_NO(a2) = VCT_NO_APPEAR; + } + else + { + //ACTION_INF@e?????? + ATR_GUARD_FLG(a2) = 0; + ATR_BODY_CNT(a0)++; //D?? + if (d0 == 1) //???D?? + d0 = 2; + } + } + } + //ACTION_INF@eԡ@e + switch (d0) + { + case 1: + ATR_GUARD_FLG(a1) = 1; + break; + case 2: + ATR_GUARD_FLG(a2) = 1; + ATR_GUARD_FLG(a1) = 1; + break; + } + break; + case ATT_SELECT: //?????????? ???k ?????????? + ATR_BODY_CNT(a0) = 1; + d0 = ATR_PLACE_NO(a1) + 5; //????????? + a2 = p_party[ATR_PLACE_NO(a1) + 5]; //????????? + ATR_BODY_WORK(0, a2) = a1; //???????? + ATR_FIRST_FLG(a2) = 0; //?????? + if (get_num() == 0) //???? + ATR_VCT_NO(a2) = 60; //????? + else + { //??? + ATR_NAME(a2) = monster; //???? + ATR_VCT_NO(a2) = 62; // + if (BattleMyNo == ATR_PLACE_NO(a1)) //?? + att_select_flg = TRUE; + } + break; + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + case ATT_PROSKILL: + ATR_VCT_NO(a1) = PROSKILL; //ʿְҵ + ATR_BODY_WORK(0, a1) = p_party[get_num()]; //ȡNo + ATR_ATTACK_KIND(0, a1) = get_num(); // + ATR_ATTACK_POW(0, a1) = get_num(); // + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + + ATR_WARRIOR_EFFECT(a1) = get_num(); + AttPreMagicNum = get_num(); + AttNextMagicNum = get_num(); + ATR_BODY_CNT(a0) = 1; +#ifdef _ATTDOUBLE_ATTACK + //andy_add + if (ATR_ATTACK_KIND(0, a1) & ATT_ATTDOUBLE || ATR_ATTACK_KIND(0, a1) & BCF_MODIFY) + ATR_BATTLEGRANO(a1) = get_num(); +#endif + break; + //#endif + default: //??????? + action_inf = -1; + //????????????? +#ifdef _STONDEBUG_ + { + char errbuf[256]; + + sprintf_s(errbuf, "errbuf:%c", command_no); + MessageBoxNew(hWnd, errbuf, "Error", MB_OK); + } +#endif + command_point = 0; + break; + } +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a1) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a1) = ATR_ATTACK_POW(0, a1) >> 16; + ATR_ATTACK_POW(0, a1) = ATR_ATTACK_POW(0, a1) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a1) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a1) = ATR_ATTACK_POW(0, a1) >> 16; + ATR_ATTACK_POW(0, a1) = ATR_ATTACK_POW(0, a1) & 0x0000ffff; + } +#endif + case 1: //s?~r? +#ifdef __ATTACK_MAGIC + if (TRUE == bRunAttMgc) + RunTimeMagic(); +#endif +#ifdef __TOCALL_MAGIC + if (TRUE == bRunToCallMgc) + RunTimeMagicToCall(); +#endif +#ifdef _PROFESSION_ADDSKILL + // RunTimeMagicBoundary(); +#endif + if (ATR_DAMAGE(a0) == ATR_BODY_CNT(a0)) + { //?~??? + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + //???r??????? + if (ATR_LIFE(p_party[d7]) > 0 && ATR_VCT_NO(p_party[d7]) != 0 && ATR_VCT_NO(p_party[d7]) < VCT_NO_DIE) + break; + } + } + if (d7 == BATTLKPKPLYAERNUM) //??? + ATR_VCT_NO(a0) = 0; //s?h? + } + break; + case 2: //u + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + //?????? + if (ATR_VCT_NO(p_party[d7]) != 0 && ATR_VCT_NO(p_party[d7]) != VCT_NO_DIE + 2) + break; + } + } + if (d7 == BATTLKPKPLYAERNUM) + { //??? + action_inf = 2; + command_point = 0; //????????????? + } + break; + case 3: //K͢r? + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + if (ATR_VCT_NO(p_party[d7]) != 0 && ATR_VCT_NO(p_party[d7]) != VCT_NO_DIE + 2) //???r??????? + break; + } + } + if (d7 == BATTLKPKPLYAERNUM) + { + ATR_VCT_NO(a0) = 0; + action_inf = 3; //K?? + if (BattleBpFlag & BATTLE_BP_JOIN)// ӡP?? + { + //u?? + if (check_all_dead()) + action_inf = 2; + } + } + break; + case 4: //????r? + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if (ATR_NAME(p_party[d7]) != NULL) + { + //u?? + if (check_all_dead()) + { + //???r??????? + if (ATR_VCT_NO(p_party[d7]) != 0 && ATR_VCT_NO(p_party[d7]) != VCT_NO_DIE + 2) + break; + } + else + { + //????????????? + if (BattleMyNo == d7) + { + if (ATR_VCT_NO(p_party[d7]) == 55) + break; + } + //???r??????? + if (ATR_LIFE(p_party[d7]) > 0 && ATR_VCT_NO(p_party[d7]) != 0 && ATR_VCT_NO(p_party[d7]) != VCT_NO_DIE + 2) + break; + } + } + } + if (d7 == BATTLKPKPLYAERNUM) + { + ATR_VCT_NO(a0) = 0; + //t@e?? + if (!action_inf) + action_inf = 1; //???? + //u?? + if (check_all_dead()) + action_inf = 2; + } + break; + } +master_500: + //??????????? +#ifdef __ATTACK_MAGIC + if ((BattleMapNo >= 148 && BattleMapNo <= 150) || g_iRunEarthQuake >= 2) +#else + if (BattleMapNo >= 148 && BattleMapNo <= 150) //??????????? +#endif + { + //???? + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + a1 = p_party[d7]; //??????? + if (ATR_NAME(a1) == NULL) //??? + continue; + ATR_V_POS(a1) += ATR_INT_WORK3(a1); + ATR_INT_WORK1(a1) += ATR_INT_WORK3(a1); + //???????????? + set_raster_pos(a1); + } + if (g_iRunEarthQuake == 3) + g_iRunEarthQuake = 0; + } + //????????? + d6 = 0; + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + a1 = p_party[d7]; //??????? + if (ATR_NAME(a1) == NULL) //??? + continue; + sort_chr_buf[d6].work = a1; //??????? + sort_chr_buf[d6++].v_pos = ATR_V_POS(a1); //????? + } + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if ((a1 = p_missile[d7]) == NULL) //??? + continue; + sort_chr_buf[d6].work = a1; //??????? + sort_chr_buf[d6++].v_pos = ATR_V_POS(a1); //????? + } + //??????? + qsort(sort_chr_buf, // ???? + d6, // {????? + sizeof(SORT_CHR_EQU), // ??? + (CMPFUNC*)sort_chr // {????????? + ); + d0 = 30; //?I??? + for (d7 = 0; d7 < d6; d7++) + ATR_DISP_PRIO(sort_chr_buf[d7].work) = d0++; +} + +//ж +void monster(ACTION *a0) +{ + int d0, d1, d6, d7, sav_command_point, idx; + ACTION *a1, *a2, *a3; + static ACTION *a0tmp[10]; + static int a0mark[10]; // 0:ѽaction release 1:δ + static int a0tmpcount; + + switch (ATR_VCT_NO(a0)) + { + case 0: // + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + if (ATR_VCT_NO(p_master) == 1) + { + a1 = ATR_COUNTER(p_master); //????????? + if (a1 != NULL && ATR_GROUP_FLG(a0) != ATR_GROUP_FLG(a1) && ATR_NAME(a1) != NULL) + { + //??? + if (ATR_H_POS(a1) < lpDraw->xSize && ATR_H_POS(a1) > 64 && ATR_V_POS(a1) < lpDraw->ySize && ATR_V_POS(a1) > 0 - 64) + { + if (ATR_STATUS(a1) <= JUJUTSU_1) //????????? + { + a1 = ATR_COUNTER(p_master); //???????? + d0 = ATR_H_POS(a1); //??? + d1 = ATR_V_POS(a1); + radar2(a0, d0, d1, 2); //???? + //???????? + d0 = ATR_CRS(a0) - ATR_CRS_OLD(a0); + if (d0 < 0) + d0 = 0 - d0; + if (d0 >= 2) + { + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CRS_OLD(a0) = ATR_CRS(a0); + } + } + } + } + } + //?????????? + d0 = ATR_STATUS(a0); + if (ATR_STATUS(a0) != 3 && ATR_STATUS(a0) != 4) + { + //?P??????e???? + if (BattleMyNo >= 20 || (ATR_ATTRIB(a0) & ACT_ATR_BTL_CMD_END) +#ifdef _PETSKILL_BATTLE_MODEL + || ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL +#endif + ){ + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + } + //ォͼƬ¼غȾ wxy + //pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + } +#ifdef _PETSKILL_BATTLE_MODEL + // 黻ҹû + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + { + a1 = ATR_BODY_WORK(0, a0); // ȡĿ + // Ⱥ˳ִ + if (ATR_LONG_WORK(ATR_PLACE_NO(a0), a1) == ATR_INT_WORK2(p_master)) + { + // Ŀصʱٹ + if (ATR_VCT_NO(a1) == 0) + ATR_VCT_NO(a0) = 2; // ʼ + // Ŀ뿪սʱ + if (ATR_VCT_NO(a1) == VCT_NO_APPEAR || ATR_LIFE(a1) <= 0) + { + ATR_VCT_NO(a0) = 3; // + ATR_BODY_WORK(0, a0) = NULL; // + } + } + } +#endif + break; + case 1: //ǰ + ATR_SPD(a0) = 32; //ƶٶ + a1 = ATR_BODY_WORK(0, a0); //зλ + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + //???????? + d0 = ATR_CRS(a0) - ATR_CRS_OLD(a0); + if (d0 < 0) + d0 = 0 - d0; + if (d0 >= 2) + { + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CRS_OLD(a0) = ATR_CRS(a0); + } + if (d1 <= 32 * 2) + { // +#ifdef _PIRATE_ANM + if (ATR_CHR_NO(a0) == 101491) + ATR_CHR_NO(a0) = 101490; +#endif + ATR_FIRST_FLG(a0) = 0; //???????? + ATR_HIT_STOP(a0) = 0; //?????????? +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + ATR_VCT_NO(a0) = 0; // ֮ȴ + else +#endif + { + if (ATR_ATTACK_KIND(0, a0) & ATT_VICARIOUS) + { //?????? + ATR_VCT_NO(a0) = 65; //??????r? + ATR_BODY_WORK(1, a0) = ATR_BODY_WORK(0, a0); //????~ + a1 = ATR_BODY_WORK(0, a0); //???????? + ATR_BODY_WORK(1, a1) = a0; // + a1 = p_party[get_num()]; //?????????? +#ifdef _ATTACK_EFFECT + //Ȯ xiezi + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + ATR_VCT_NO(a1) = 69; //??????? + ATR_FIRST_FLG(a1) = 0; // + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); //?hI?????? + } + else if (ATR_SYNC_FLG(a0)) //i????? + { + ATR_VCT_NO(a0) = 19; //i???r?? + a1 = ATR_BODY_WORK(0, a0); //???? + ATR_LONG_WORK(0, a1)--; //??? + } + else //andy_bug + ATR_VCT_NO(a0) = 2; //??? + } + } + else + { +#ifndef _PIRATE_ANM + gemini(a0); //?h +#else + if (ATR_CHR_NO(a0) != 101490) + gemini(a0); //?h +#endif + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? +#ifndef _PIRATE_ANM + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +#else + if (ATR_CHR_NO(a0) == 101490) + { + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + if (a0->bmpNo == 301137) + ATR_CHR_NO(a0) = 101491; + } + else + { + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + } +#endif + break; + case 2: // + if (ATR_HIT_STOP(a0)) //?????????? + { + if (--ATR_HIT_STOP(a0)) //?????????? + break; + } + a1 = ATR_BODY_WORK(0, a0); +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL && ATR_FIRST_FLG(a0) == 0 && ATR_INT_WORK3(a0) == 0) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_VICARIOUS) // Ȯ + { + ATR_VCT_NO(a0) = 65; // Ƚеȴ + ATR_BODY_WORK(1, a1) = a0; // ѹ¼,֮õ + a1 = p_party[ATR_LONG_WORK(0, a0)]; // ȡ action + ATR_VCT_NO(a1) = 69; // ʾ damage + ATR_FIRST_FLG(a1) = 0; + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); // ǰĿ + ATR_INT_WORK3(a0) = 1; + break; + } + ATR_SYNC_FLG(a1) = 1; + } +#endif + if (ATR_FIRST_FLG(a0) == 0) //??????? + { + ATR_HIT(a0) = 0; //????????? + ATR_HIT_TIMING(a0) = 0; //?????????? + + d0 = ATR_H_POS(a1); //??? + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = d0; //???V + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + //?????????? + if (ATR_ATTACK_KIND(0, a0) & ATT_G_CRASH) + //???????? + set_damage_num(a0, 12, -64 + 16); + else if (ATR_ATTACK_KIND(0, a0) & ATT_TOOEH) + set_damage_num(a0, 29, -64 + 16); +#ifdef _ATTDOUBLE_ATTACK + else if (ATR_ATTACK_KIND(0, a0) & ATT_ATTDOUBLE) + { + int skill = ATR_BATTLEGRANO(a0); + switch (skill) + { + case 70: + set_damage_num(a0, 25, -64 + 16); + break; + case 71: + set_damage_num(a0, 26, -64 + 16); + break; + case 72: + set_damage_num(a0, 27, -64 + 16); + break; + case 73: + set_damage_num(a0, 28, -64 + 16); + break; + } + } + else if (ATR_ATTACK_KIND(0, a0) & BCF_MODIFY) + { + int skill = ATR_BATTLEGRANO(a0); + + switch (skill) + { + case 74://74 + set_damage_num(a0, 32, -64 + 16); + break; + case 75://75 + set_damage_num(a0, 33, -64 + 16); + break; + case 76://76 + set_damage_num(a0, 34, -64 + 16); + break; + case 77://77 + set_damage_num(a0, 35, -64 + 16); + break; + } + } +#endif +#ifdef _SKILL_ROAR //輼:() + else if (ATR_ATTACK_KIND(0, a0) & ATT_ATTROAR) + { + set_damage_num(a0, 22, -64 + 16); + ATR_ROAR(a1) = 2; + } +#endif +#ifdef _SKILL_SELFEXPLODE //Ա + else if (ATR_ATTACK_KIND(0, a0) & ATT_ATTSELFEXPLODE) + { + ATR_SELFEXPLODE(a0) = 1; + set_damage_num(a0, 23, -64 + 16); + } +#endif +#ifdef _PETSKILL_EXPLODE // + else if (ATR_ATTACK_KIND(0, a0) & ATT_EXPLODE) + { + //ATR_SELFEXPLODE(a0) = 1; + ATR_LIFE(a0) = 1; + set_damage_num(a0, 23, -64 + 16); + } +#endif + else + { + //andy_fall + if (ATR_ATTACK_KIND(0, a0) & ATT_FALL) + { + if (ATR_RIDE(a1) == 1) + { + //set_damage_num(a0, 12, -64+16); //ݲͼ + ATR_PETFALL(a1) = 1; + } + } + } + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTPREPROSKILL) + set_damage_num(a1, 41, -64 + 25); + //#endif + //i???????? + if (ATR_SYNC_FLG(a0)) + d0 = 0; + else + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + d0 = 0; + else +#endif + d0 = get_next_flg(); //?????????? + } + if (d0 & ATT_COUNTER) //?????????? + { + ATR_COUNTER_FLG(a0) = 1; + ATR_COUNTER_FLG(a1) = 1; + ATR_STIMER(a0) = 255; + } + else + { + ATR_COUNTER_FLG(a0) = 0; + ATR_COUNTER_FLG(a1) = 0; + ATR_STIMER(a0) = 20; + } + ATR_FIRST_FLG(a0) = 1; //?????? + } + //ATT_AKO1 +#ifdef _PETSKILL_ANTINTER + if (ATR_VCT_NO(a1) >= VCT_NO_DIE && (ATR_ATTACK_KIND(0, a1) & (1 << 28))) //??? +#else + if (ATR_VCT_NO(a1) >= VCT_NO_DIE) //??? +#endif + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER && ATR_COUNTER(p_master) != a0) //??????? + ATR_VCT_NO(a0) = 0; //r?? + else + { + ATR_VCT_NO(a0) = 3; + ATR_STIMER(a0) = 20; +#ifdef _PETSKILL_BATTLE_MODEL + // + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + ATR_LONG_WORK(ATR_PLACE_NO(a0), a1) = 0; +#endif + } + break; + } +#ifdef _SKILL_SELFEXPLODE //Ա + if (ATR_SELFEXPLODE(a0) == 1) + { + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_CHR_ACT(a0) = ANIM_ATTACK; + } + else +#endif + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER && ATR_COUNTER(p_master) != a0) //??????? + ATR_VCT_NO(a0) = 0; //r?? + else + { + ATR_VCT_NO(a0) = 3; +#ifdef _PETSKILL_BATTLE_MODEL + // + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + ATR_LONG_WORK(ATR_PLACE_NO(a0), a1) = 0; +#endif + } + break; + } + //??????? + if (ATR_HIT(a0)) + { +#ifdef _ATTACK_EFFECT + if (ATR_LONG_WORK(0, a0) > 0) // Ч + { + SetDisplayAttackEffect(a0, ATR_LONG_WORK(0, a0)); + ATR_LONG_WORK(0, a0) = 0; + } +#endif + //andy_mp + if (ATR_SHOWADDHP(a0) == 1) + { + set_damage_num(a0, 6, -64); + ATR_SHOWADDHP(a0) = 0; + ATR_LIFE(a0) += ATR_ADDHP(a0); + } + ATR_ATTACK_KIND(1, a1) = ATR_ATTACK_KIND(0, a0) & ATT_DEATH; +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + ATR_ATTACK_KIND(1, a1) = 0; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + ////////////////////// +#else + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA | ATT_TRAP)) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ABSORPTION | ATT_BALLIA)) +#endif + ////////////////////// +#endif + { + set_guard_mark(a0); +#ifdef _PETSKILL_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & (ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_INT_WORK0(a0) != ATT_BATTLE_MODEL) +#endif + { + ATR_VCT_NO(a1) = 10; //趨Լ + ATR_DAMAGE(a1) = ATR_DAMAGE(a0);//ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0)*2; + //ATR_ATTACK_KIND(0, a1) &= ATT_AKO2; + if ((float)ATR_DAMAGE(a1) >= (float)(ATR_MAX_LIFE(a1) * 1.2 + 20.0)) + { + ATR_LIFE(a1) = 0; + ATR_AKO_FLG(a1) = 2; // + } + a1 = ATR_BODY_WORK(0, a0) = a0; + } + } +#endif + if (ATR_ATTACK_KIND(0, a0) & ATT_VICARIOUS) + { + a1 = ATR_BODY_WORK(0, a0); + ATR_VCT_NO(a1) = 6; + ATR_STIMER(a1) = 60; + } + } +#ifdef _PETSKILL_ACUPUNCTURE + /////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + /////////////////// +#else + /////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) ) +#else + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) +#endif + /////////////////// +#endif + { +#ifdef _PETSKILL_BATTLE_MODEL + // Dzǹ + if (ATR_INT_WORK0(a0) != ATT_BATTLE_MODEL) +#endif + a1 = ATR_BODY_WORK(0, a0) = a0; + } + else + a1 = ATR_BODY_WORK(0, a0); //????????xxx + //????????? + ATR_COMBO(a1) = 0; + //??????? + if (ATR_ATTACK_KIND(0, a0) & ATT_DODGE) + { + //??????????? + if (ATR_HIT_TIMING(a0) == 0) + { + ATR_HIT_TIMING(a0) = 1; //?????????? + ATR_VCT_NO(a1) = 16; //???? + ATR_CRS(a1) = ATR_CRS(a0); //????????????? + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 1; //????????? + ATR_BODY_WORK(0, a1) = a0; // + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + //????? + set_damage_num(a0, 1, -64 + 16); + } + ATR_HIT(a0) = 0; + play_se(8, ATR_H_POS(a0), ATR_V_POS(a0)); + break; + } + + //???????? + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + //????????? + if (ATR_ATTACK_KIND(0, a0) & ATT_CRUSH) + //????? + set_damage_num(a1, 19, -112); + } + //?????????//knock out + ATR_AKO_FLG(a1) = 0; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO1) //?????? + ATR_AKO_FLG(a1) = 1; + if (ATR_ATTACK_KIND(0, a0) & ATT_AKO2) //?????? + ATR_AKO_FLG(a1) = 2; + // ????? + if (ATR_HIT(a0) >= 10100) + { +#ifdef _PETSKILL_ACUPUNCTURE + /////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + /////////////////////// +#else + /////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) ) +#else + + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) +#endif + /////////////////////// +#endif + { + ATR_HIT(a0) -= 100; + if (ATR_SYNC_FLG(a0) == 1) + { + a2 = ATR_BODY_WORK(1, a0); + ATR_VCT_NO(a2) = 2; + ATR_COUNTER(p_master) = a2; + } + } + else + //????????? + ATR_COMBO(a1) = 1; + } + else if (ATR_SYNC_FLG(a0) == 1) + { +#ifdef _PETSKILL_ACUPUNCTURE + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (!(ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ))) +#else + if (!(ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ))) +#endif + ///////////////////// +#else + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (!(ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) )) +#else + if (!(ATR_ATTACK_KIND(0, a0) & ATT_REFLEX)) +#endif + ///////////////////// +#endif + ATR_COMBO(a1) = 1; + a2 = ATR_BODY_WORK(1, a0); //?????? + ATR_VCT_NO(a2) = 2; //??? + ATR_COUNTER(p_master) = a2; //?????? + } +#ifdef _PETSKILL_ACUPUNCTURE + ///////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + //////////////////// +#else + ///////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) ) +#else + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) +#endif + //////////////////// +#endif + { +#ifdef _PETSKILL_BATTLE_MODEL + // Dzǹ + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + { + ATR_ATTACK_POW(0, a0) = 0; // ˺ + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); + ATR_ATTACK_KIND(0, a0) |= ATT_NOMISS; + } + else +#endif + ATR_DAMAGE_ANG(a1) = (ATR_CHR_ANG(a0) + 4) & 7; + } + else + ATR_DAMAGE_ANG(a1) = ATR_CHR_ANG(a0); // + if (ATR_ATTACK_KIND(0, a0) & BCF_DEFMAGICATT) + set_damage_num(a1, 30, -64); + if (ATR_ATTACK_KIND(0, a0) & BCF_SUPERWALL) + set_damage_num(a1, 31, -64); + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTNEXTPROSKILL) + set_damage_num(a1, 41, -64 + 25); + //#endif + if (ATR_ATTACK_KIND(0, a0) & ATT_ABSORPTION) //?????? + { + if (ATR_SYNC_FLG(a0) == 0) //i???????? + { + if (!ATR_COMBO(a1)) //???????? + { + //??k +#ifdef _SYUTEST + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + if (Light1 == NULL) + Light1 = MakeAnimDisp(ATR_H_POS(a0), ATR_V_POS(a0), 101581, 0); + set_damage_num(a1, 41, -64 + 25); + // ɹԤ +#else + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? +#endif + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + } + else + { + //???????? + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + //??k + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); +#ifdef _SYUTEST + // ɹԤ +#endif + ATR_LIFE(a1) += ATR_DAMAGE(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + ATR_PET_LIFE(a1) += ATR_PET_DAMAGE(a1); + if (ATR_PET_LIFE(a1) > ATR_PET_MAX_LIFE(a1)) //???? + ATR_PET_LIFE(a1) = ATR_PET_MAX_LIFE(a1); //???? + set_damage_num(a1, 14, -64); + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + } + } + else if (ATR_ATTACK_KIND(0, a0) & ATT_BALLIA) //???????? + { + ATR_ATTACK_POW(0, a0) = 0; //????? + ATR_ATTACK_PET_POW(0, a0) = 0; //????? + } + else + { + ATR_VCT_NO(a1) = 10; //????? + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & ATT_NOMISS) + NoMiss = 1 ; + else + NoMiss = -1 ; +#endif + } + //?????? + if (ATR_ATTACK_KIND(0, a0) & ATT_SATISFACTORY) + ATR_KAISHIN(a1) = 1; //??????? + else + ATR_KAISHIN(a1) = 0; //G????? + ATR_DAMAGE(a1) = ATR_ATTACK_POW(0, a0); + ATR_PET_DAMAGE(a1) = ATR_ATTACK_PET_POW(0, a0); + //andy_mp + ATR_MPDAMAGE(a1) = ATR_MPDAMAGE(a0); + ATR_MPDFLG(a1) = ATR_MPDFLG(a0); + //????? + if (ATR_ATTACK_KIND(0, a0) & ATT_GUARD) + ATR_GUARD_FLG(a1) = 1; + else + ATR_GUARD_FLG(a1) = 0; +#ifdef _EQUIT_ARRANGE + if (ATR_ATTACK_KIND(0, a0) & ATT_ARRANGE) + { + set_damage_num(a1, 42, -64); + ATR_CHR_ACT(a1) = ANIM_GUARD; + } +#endif + if (ATR_LIFE(a1) - ATR_DAMAGE(a1) <= 0 || (ATR_ATTACK_KIND(0, a0) & ATT_DEATH)) + { + if (ATR_COMBO(a1) == 0) + ATR_KAISHIN(a1) = 1; + } + if (ATR_KAISHIN(a1)) + ATR_HIT_STOP(a0) = HIT_STOP_TIM * 4; + else + ATR_HIT_STOP(a0) = HIT_STOP_TIM; + if (ATR_DAMAGE(a1) || (ATR_ATTACK_KIND(0, a0) & (ATT_BALLIA | ATT_ABSORPTION))) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_COUNTER) //??????? + { + //???????? + if (ATR_COMBO(a1) == 0) + //????? + set_damage_num(a0, 1, -64 + 16); + } + //Ч + play_damage(ATR_HIT(a0), ATR_H_POS(a0)); + //ɱ + set_hit_mark(a0); + if (ATR_COMBO(a1)) //С + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //ֹͣ + } + ATR_HIT(a0) = 0; // + if (!(ATR_ATTACK_POW(0, a0) || ATR_ATTACK_PET_POW(0, a0))) //???? + { + ATR_HIT_STOP(a0) = 0; //ֹͣ + play_se(8, ATR_H_POS(a0), ATR_V_POS(a0)); + } + } + break; + + case 3: //ȴ +#ifdef _PETSKILL_BATTLE_MODEL + // Dzǹ + if (ATR_INT_WORK0(a0) == ATT_BATTLE_MODEL) + { + // ˹ûĿ + if (ATR_INT_WORK1(a0) > 1) + { + // ҳһĿ + for (d0 = 1; d0 < ATR_INT_WORK1(a0); d0++) + { + if (ATR_BODY_WORK(d0, a0) != NULL) // ҵĿ + { + a1 = ATR_BODY_WORK(d0, a0); // ȡĿ + ATR_BODY_WORK(d0, a0) = NULL; // + if (ATR_LIFE(a1) <= 0) // Ŀ + continue; + if (ATR_VCT_NO(a1) == VCT_NO_APPEAR) // Ŀ뿪ս + continue; + else + { + ATR_INT_WORK3(a0) = 0; + ATR_BODY_WORK(0, a0) = a1; // + ATR_ATTACK_KIND(0, a0) = ATR_ATTACK_KIND(d0, a0); // + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(d0, a0); // + ATR_ATTACK_PET_POW(0, a0) = ATR_ATTACK_PET_POW(d0, a0); // pet + ATR_LONG_WORK(0, a0) = ATR_LONG_WORK(d0, a0); // 趨ʹȮĿ + ATR_VCT_NO(a0) = 1; // ǰһĿ + ATR_INT_WORK2(p_master)++; // һ + ATR_INT_WORK1(a0)--; + break; + } + } + } + if (d0 == ATR_INT_WORK1(a0)) + ATR_INT_WORK1(a0) = 0; + } + // ûĿ,뿪 + else + { + // 趨뿪 + if (ATR_INT_WORK2(a0) == 0) // һִ + { + ATR_SPD(a0) = 16; + // 뿪 + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_INT_WORK2(a0) = 1; + ATR_INT_WORK2(p_master)++; // һ + } + gemini(a0); // ƶ + ATR_CHR_ACT(a0) = ANIM_WALK; + pattern(a0, 1, ANM_LOOP); + // ƶӫĻ + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { + DeathAction(a0); + p_missile[ATR_PLACE_NO(a0)] = NULL; + // Ƿе p_missile + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + if (p_missile[d7] != NULL) + break; + } + if (d7 >= BATTLKPKPLYAERNUM) + ATR_INT_WORK1(p_master) = 1; // еĹж + } + // еĹж + if (ATR_INT_WORK1(p_master)) + { + ATR_DAMAGE(p_master) = 0; + ATR_BODY_CNT(p_master) = 1; + if (ATR_BODY_WORK(0, a0) == NULL) // Ŀ겻ڳϻ + ATR_DAMAGE(p_master)++; + else // һĿ״̬Ǵ + if (ATR_VCT_NO(ATR_BODY_WORK(0, a0)) == 0 || ATR_LIFE(ATR_BODY_WORK(0, a0)) <= 0) + ATR_DAMAGE(p_master)++; + } + } + break; + } +#endif + if (--ATR_STIMER(a0)) //??r??? + break; + if (ATR_SYNC_FLG(a0)) + { //i????? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_VCT_NO(a0) = 4; //?~? + ATR_SPD(a0) = 32; + break; + } + d0 = get_num(); //???h?? + if (d0 == 255) + { //??? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; +#ifdef _SKILL_SELFEXPLODE //Ա + if (ATR_SELFEXPLODE(a0) == 1) + ATR_VCT_NO(a0) = 114; + else +#endif + ATR_VCT_NO(a0) = 4; //?~? + ATR_SPD(a0) = 32; + break; + } + if (ATR_ATTACK_KIND(0, a0) & ATT_VICARIOUS) //????????? + a2 = ATR_BODY_WORK(1, a0); + else + a2 = ATR_BODY_WORK(0, a0); //??V + a1 = ATR_BODY_WORK(0, a0) = p_party[d0]; //???? + + ATR_ATTACK_KIND(0, a0) = get_num(); //?????? + ATR_ATTACK_POW(0, a0) = get_num(); //?????? +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + + if (a1 == a2) //??i??? + ATR_VCT_NO(a0) = 5; //e?tr?? + else + ATR_VCT_NO(a0) = 1; //?h? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + break; + case 5: //e?tr?? + a1 = ATR_BODY_WORK(0, a0); + if (ATR_VCT_NO(a1) == 0) //?e?t?????? + ATR_VCT_NO(a0) = 1; //?h? + break; + case 4: // + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = d0; //?????? +#ifndef _PIRATE_ANM + gemini(a0); //?h +#else + if (ATR_CHR_NO(a0) != 101490) + gemini(a0); //?h +#endif + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + if (ATR_DAMAGE(p_master) != ATR_BODY_CNT(p_master)) //?????? + ATR_DAMAGE(p_master)++; //?????? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif// + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); +#ifdef _PIRATE_ANM + if (ATR_CHR_NO(a0) == 101492) + ATR_CHR_NO(a0) = 101490; +#endif + ATR_VCT_NO(a0) = 0; //r?? + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? +#ifndef _PIRATE_ANM + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); +#else + if (ATR_CHR_NO(a0) == 101490) + { + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + if (a0->bmpNo == 301026 || a0->bmpNo == 301138) + ATR_CHR_NO(a0) = 101492; + } + else + { + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + } +#endif + break; + case 6: //?\? + if (--ATR_STIMER(a0)) + break; + ATR_SPD(a0) = 10; + ATR_VCT_NO(a0) = 14; //???????~? + ATR_FIRST_FLG(a0) = 0; //?~? + break; + case 10: // + if (!ATR_DAMAGE(a0) && ATR_LIFE(a0) > 0 && !ATR_PET_DAMAGE(a0)) //???????? + { + //???????? + if (!ATR_COMBO(a0)) + { + //?? +#ifdef _SKILL_ROAR //輼:()//tuen "miss" off + if (ATR_ROAR(a0) == 2){ + // set_damage_num(a0, 18, -64); + } + else + { +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (NoMiss == 1);//set_damage_num(a0, 1, -64); + else if (NoMiss == -1) + set_damage_num(a0, 0, -64); +#else + set_damage_num(a0, 0, -64); +#endif + } +#else + set_damage_num(a0, 0, -64); +#endif + d0 = get_next_flg(); //?????????? + if (d0 & ATT_COUNTER) //??????? + ATR_VCT_NO(a0) = 11; //????? + else + { + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a0) = 0; //r?? + } + } + else + { + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a0) = 0; //r?? + } + break; + } + if (ATR_GUARD_FLG(a0)) + { //????? + //???????? + if (!ATR_COMBO(a0)) + //??? + set_damage_num(a0, 3, -64 + 16); + ATR_CHR_ACT(a0) = ANIM_GUARD; //??????????// + } + else + ATR_CHR_ACT(a0) = ANIM_DAMAGE; //???????????// + ATR_CHR_ANG(a0) = (ATR_DAMAGE_ANG(a0) + 4) & 7; + //?????????????????? + if (!ATR_COMBO(a0) || ATR_CHR_ACT_OLD(a0) != ANIM_DAMAGE) + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_DAMAGE_ANG(a0)]; + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + ATR_VCT_NO(a0) = 11; + //????? + if (ATR_COMBO(a0)) + ATR_STIMER(a0) = 255; + else + { + if (ATR_KAISHIN(a0)) //?????? + ATR_STIMER(a0) = HIT_STOP_TIM * 4; + else + ATR_STIMER(a0) = HIT_STOP_TIM; + } +#ifdef _PETSKILL_ACUPUNCTURE + ///////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ) && ATR_SYNC_FLG(a0) == 0) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ) && ATR_SYNC_FLG(a0) == 0) +#endif + ///////////////////////// +#else + ///////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) && ATR_SYNC_FLG(a0) == 0) +#else + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX && ATR_SYNC_FLG(a0) == 0) +#endif + ///////////////////////// +#endif + ATR_STIMER(a0) = HIT_STOP_TIM * 4;//817333333 + ATR_SPD(a0) = 16; +#ifdef _MAGIC_DEEPPOISION //綾 + if ((ATR_DEEPPOISION(a0) == 1)) + ATR_STIMER(a0) = 50; +#endif + //???????? + if (!ATR_COMBO(a0)) + { + //????k + set_damage_num(a0, 6, -64); + ATR_LIFE(a0) -= ATR_DAMAGE(a0); //????? + //andy_mp + ATR_MP(a0) -= ATR_MPDAMAGE(a0); + ATR_PET_LIFE(a0) -= ATR_PET_DAMAGE(a0); + //andy_fall + if (ATR_PETFALL(a0) == 1) + { + if (ATR_LIFE(a0) > 0) + petfallChangeGraph(a0); + } + if (ATR_PET_LIFE(a0) <= 0 && ATR_RIDE(a0)) + { //??????? + ATR_PET_LIFE(a0) = 0; + if (ATR_LIFE(a0) > 0) + petfallChangeGraph(a0); + } + if (ATR_LIFE(a0) <= 0 || (ATR_ATTACK_KIND(1, a0) & ATT_DEATH)) + { //??????? + ATR_LIFE(a0) = 0; + slow_flg++; //???? + flash_vct_no = 1; //????????? + } + } + break; + case 11: //????r? + if (ATR_DAMAGE(a0)) + { //??????? + gemini(a0); //?????? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31; + if (--ATR_STIMER(a0)) //??r??? + break; + } +#ifdef _PETSKILL_ACUPUNCTURE + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ) && ATR_SYNC_FLG(a0) == 0 ) +#else + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + ) && ATR_SYNC_FLG(a0) == 0) +#endif + ////////////////////// +#else + ////////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP) && ATR_SYNC_FLG(a0) == 0) +#else + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX && ATR_SYNC_FLG(a0) == 0) +#endif + ////////////////////// +#endif + { + sav_command_point = command_point; //??????????~ + d0 = get_num(); + command_point = sav_command_point; //???????????? + if (d0 != 255) + { //???? + a1 = ATR_BODY_WORK(0, a0) = p_party[get_num()]; //???? + ATR_ATTACK_KIND(0, a0) = get_num(); //?????? + ATR_ATTACK_POW(0, a0) = get_num(); //?????? +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //սЧ xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + + ATR_HIT_STOP(a0) = 0; //?????????? + ATR_VCT_NO(a0) = 2; //??? + ATR_FIRST_FLG(a0) = 0; //???????? + ATR_CHR_ACT_OLD(a0) = -1; + if (ATR_ATTACK_KIND(0, a0) & ATT_VICARIOUS) //?????? + ATR_VCT_NO(a0) = 1; //q? + break; + } + } + if (ATR_COUNTER_FLG(a0)) + { //???????//counter + a1 = ATR_BODY_WORK(0, a0) = p_party[get_num()]; //???? + ATR_ATTACK_KIND(0, a0) = get_num(); //?????? + ATR_ATTACK_POW(0, a0) = get_num(); //?????? +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + + ATR_CHR_ANG(a0) = (ATR_DAMAGE_ANG(a0) + 4) & 7; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_BODY_CNT(a0) = 1; // + ATR_BODY_WORK(0, a0) = a1; //? + ATR_HIT_STOP(a0) = HIT_STOP_TIM; //?????????? + ATR_VCT_NO(a0) = 2; //??? + ATR_FIRST_FLG(a0) = 0; //???????? + //????? + ATR_CHR_ACT_OLD(a0) = -1; + break; + } + if (ATR_LIFE(a0) <= 0) //??? + slow_flg--; //????? + // ????? + if (ATR_AKO_FLG(a0)) + { + //???? + ATR_FIRST_FLG(a0) = 0; + ATR_VCT_NO(a0) = 55; + //????V?ϣ?? + if (ATR_PET_OK(a0)) + { + a1 = p_party[ATR_PLACE_NO(a0) + 5]; //???????? + if (ATR_NAME(a1) != NULL) + { + ATR_BODY_WORK(0, a0) = a1; //????????? + if (ATR_LIFE(a1) > 0) //???????? + { + ATR_VCT_NO(a1) = 56; //???????? + ATR_BODY_WORK(0, a1) = a0; //???????? + } + } + else + ATR_BODY_WORK(0, a0) = NULL; //pet work clear????????? + } + else + ATR_BODY_WORK(0, a0) = NULL; //????????? + //?????? + if (BattleMyNo + 5 == ATR_PLACE_NO(a0)) + { + // ???????????? + if (att_select_flg == TRUE) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + { + // i????? + if (battlePetNoBak2 == pc.battlePetNo) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + //???? + pc.selectPetNo[battlePetNoBak2] = FALSE; + } + } + break; + } + if (ATR_KAISHIN(a0)) //?????? + ATR_SPD(a0) = 35;//˾ + else + ATR_SPD(a0) = 28; +#ifdef _MAGIC_DEEPPOISION //綾 + if (ATR_DEEPPOISION(a0) == 1) + { + ATR_SPD(a0) = 0; + ATR_LIFE(a0) = 0; + } +#endif + ATR_VCT_NO(a0) = 12; //??????? + break; + case 12: //?????? + //???? + if ((ATR_CHR_NO(a0) >= SPR_mwood1 && ATR_CHR_NO(a0) <= SPR_mstone3) || + (ATR_CHR_NO(a0) == 15323) || (ATR_CHR_NO(a0) == 10812) || (ATR_CHR_NO(a0) == 15527) || + (ATR_CHR_NO(a0) == 15543) || (ATR_CHR_NO(a0) == 15575) || (ATR_CHR_NO(a0) == 15607) + ) + ATR_SPD(a0) -= 2; + else + { + //˶ + if (ATR_CHR_ACT(a0) == ANIM_DAMAGE && ATR_CHR_NO(a0) >= SPR_pet061 && ATR_CHR_NO(a0) <= SPR_pet064 || ATR_CHR_NO(a0) == SPR_pet065) + { + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + gemini(a0); + ATR_SPD(a0) -= 1; + } + else + { + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + gemini(a0); //?h + ATR_SPD(a0) -= 2; + } + } + if (ATR_SPD(a0) < 0) //????????? + { + ATR_SPD(a0) = 10; + ATR_VCT_NO(a0) = 13; //??????r? + ATR_STIMER(a0) = 16; +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + a1 = ATR_COUNTER(p_master); + if (a1->anim_chr_no_bak == 101578) + ATR_STIMER(a0) = 26; +#endif + } + break; + case 13: //??????r? + if (--ATR_STIMER(a0)) //??r??? + break; +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + a1 = ATR_COUNTER(p_master); + if (a1->anim_chr_no_bak == 101578) + { + if ((abs(ATR_H_POS(a0) - ATR_INT_WORK0(a0)) + abs(ATR_V_POS(a0) - ATR_INT_WORK1(a0)) > 80)) + { + ATR_H_POS(a0) = ATR_INT_WORK0(a0); + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + } + } +#endif + if (ATR_LIFE(a0) > 0) //????? + { + if (ATR_COUNTER(p_master) == a0 || ATR_SYNC_FLG(a0) == 1) //????i?????? + { + d0 = ATR_INT_WORK0(a0); //??? + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_SPD(a0) = 32; + ATR_VCT_NO(a0) = 4; //?~? + } + else + { + ATR_VCT_NO(a0) = 14; //??? + ATR_FIRST_FLG(a0) = 0; //?????? + } + } + else + { +#ifdef _PETSKILL_ACUPUNCTURE + //////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_COUNTER(p_master) == a0 || ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) + { + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#else + if (ATR_COUNTER(p_master) == a0 || ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) + { + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_ACUPUNCTURE +#ifdef _PET_ITEM + | ATT_ATTACKBACK +#endif + )) +#endif + //////////////////// +#else + //////////////////// +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ATR_COUNTER(p_master) == a0 || ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP)) + { + if (ATR_ATTACK_KIND(0, a0) & (ATT_REFLEX | ATT_TRAP)) +#else + if (ATR_COUNTER(p_master) == a0 || ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) + { + if (ATR_ATTACK_KIND(0, a0) & ATT_REFLEX) +#endif + //////////////////// +#endif + ATR_DAMAGE(p_master)++; //??? + else + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_BATTLE_MODEL(a0) != ATT_BATTLE_MODEL) //DzDZ +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + } + d0 = ATR_INT_WORK0(a0); //??? + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + } +#ifdef _MAGIC_DEEPPOISION //綾 + if (ATR_DEEPPOISION(a0) == 1) + ATR_VCT_NO(a0) = VCT_NO_DIE + 1; + else +#endif + ATR_VCT_NO(a0) = VCT_NO_DIE; //?? + } + break; + case 14: //???????? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + if (ATR_FIRST_FLG(a0) == 0) + { + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_FIRST_FLG(a0) = 1; + } + ATR_CRS(a0) = d0; //?????? + //???? + if ((ATR_CHR_NO(a0) >= SPR_mwood1 && ATR_CHR_NO(a0) <= SPR_mstone3) || + (ATR_CHR_NO(a0) == 15323) || (ATR_CHR_NO(a0) == 10812) || (ATR_CHR_NO(a0) == 15527) || + (ATR_CHR_NO(a0) == 15543) || (ATR_CHR_NO(a0) == 15575) || (ATR_CHR_NO(a0) == 15607) + ) + d1 = ATR_SPD(a0) = 0; //???? + else + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + ATR_VCT_NO(a0) = 0; //r?? + ATR_SPD(a0) = 32; + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 15: //?? + ATR_VCT_NO(a0) = 0; //r?? + //??k + ATR_DAMAGE(a0) = Rnd(1, 500); + ATR_PET_DAMAGE(a0) = Rnd(1, 500); + set_damage_num(a0, 5, -64); + ATR_LIFE(a0) += ATR_DAMAGE(a0); //??? + ATR_PET_LIFE(a0) += ATR_PET_DAMAGE(a0); //??? + break; + case 16: //???? + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_SPD(a0) = 16; + ATR_CHR_ANG(a0) = (ATR_DAMAGE_ANG(a0) + 4) & 7; + gemini(a0); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_STIMER(a0)++; + if (ATR_STIMER(a0) == 20) + { + ATR_CRS_OLD(a0) = ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31; //?? + ATR_VCT_NO(a0)++; //????? + ATR_STIMER(a0) = 0; + } + break; + case 17: //???? + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_STIMER(a0)++; + d0 = 0; + if (ATR_FIRST_FLG(a0) == 0) + { //???????? + if (ATR_STIMER(a0) == 10) //???? + d0 = 1; + } + else + { + a1 = ATR_BODY_WORK(0, a0); //????? + if (ATR_VCT_NO(a1) != 2) //?????????? + d0 = 1; + } + if (d0) //?????? + { + if (ATR_COUNTER(p_master) == a0) + { //????? + sav_command_point = command_point; //??????????~ + d0 = get_num(); + command_point = sav_command_point; //???????????? + if (d0 == 255) //??? + { + ATR_STIMER(a0) = 1; //?L + ATR_VCT_NO(a0) = 3; //??r?? + break; + } + } + ATR_VCT_NO(a0)++; //????? + ATR_STIMER(a0) = 0; + } + break; + case 18: //???? + gemini(a0); + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_STIMER(a0)++; + if (ATR_STIMER(a0) == 20) + { +#ifdef _PETSKILL_BATTLE_MODEL + a1 = ATR_BODY_WORK(0, a0); + if (a1 && ATR_INT_WORK0(a1) == ATT_BATTLE_MODEL) + ATR_VCT_NO(a0) = 4; + else +#endif + if (ATR_COUNTER(p_master) == a0) + { //????? + ATR_STIMER(a0) = 1; //?L + ATR_VCT_NO(a0) = 3; //??r?? + } + else + { + if (ATR_COUNTER_FLG(a0)) + { //??????? + ATR_VCT_NO(a0) = 2; //??? + ATR_BODY_WORK(0, a0) = p_party[get_num()]; //???? + ATR_ATTACK_KIND(0, a0) = get_num(); //?????? + ATR_ATTACK_POW(0, a0) = get_num(); //?????? +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + ATR_FIRST_FLG(a0) = 0; //???????? + } + else + ATR_VCT_NO(a0) = 0; //r?? + } + } + break; + case 19: //i???r? + a1 = ATR_BODY_WORK(0, a0); //???? + if (!ATR_LONG_WORK(0, a1)) //????? + { + if (ATR_BODY_WORK(1, a1) == a0) //????k?? + { + ATR_VCT_NO(a0) = 2; //??? + break; + } + } + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 20: //?????? + if (ATR_BODY_CNT(a0) == 1 && ATR_FIRST_FLG(a0) == 0) //OD???????? + { + a2 = ATR_BODY_WORK(0, a0); //??? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + ATR_FIRST_FLG(a0) = 1; //?????? + } + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + ATR_CHR_ACT_OLD(a0) = -1; + ATR_VCT_NO(a0) = 0; //r?? + break; + } + //????D???? + if (ATR_CHR_CNT(a0) == ATR_HIT_TIMING(a0) && ATR_CHR_TIM(a0) == 0) + { + if (ATR_BODY_CNT(a0) == 1) //OD?? + { + //??????? + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = 1; //??? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + ATR_NAME(a1) = missile; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; + /* ?????k? */ + if (ATR_CHR_NO(a0) >= 31027) //?????? + ATR_CHR_NO(a1) = 32053; + else + ATR_CHR_NO(a1) = 32055; + ATR_ATTACK_KIND(0, a1) = get_num(); //?????? + ATR_ATTACK_POW(0, a1) = get_num(); //?????? + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //սЧ xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + + /* ???t */ + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_SPD(a1) = 32; + gemini(a1); + gemini(a1); + gemini(a1); + ATR_BODY_CNT(a1) = 0; + p_missile[0] = a1; + p_missile[1] = NULL; + } + else + { + for (d7 = 0; d7 < ATR_BODY_CNT(a0); d7++) + { + //??????? + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(a0); //??? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + ATR_NAME(a1) = missile; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; + /* ?????k? */ + if (ATR_CHR_NO(a0) >= 31027) //?????? + ATR_CHR_NO(a1) = 32053; + else + ATR_CHR_NO(a1) = 32055; + /* ???t */ + a2 = ATR_BODY_WORK(0, a1) = p_party[get_num()]; //? + ATR_ATTACK_KIND(0, a1) = get_num(); //?????? + ATR_ATTACK_POW(0, a1) = get_num(); //?????? + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a1) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //սЧ xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a1) = get_num(); // ¼Ч +#endif + + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a1, &d0, &d1); + ATR_CHR_ANG(a1) = crs_change_tbl[d0]; /* ????? */ + ATR_SPD(a1) = 32; //D?t??? + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + gemini(a1); + gemini(a1); + gemini(a1); + ATR_CRS(a1) = d0; + ATR_BODY_CNT(a1) = d7; + p_missile[d7] = a1; + } + p_missile[d7] = NULL; + } + } + break; + case 25: //??d + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + ATR_HIT(a0) = 0; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + ATR_CHR_ACT_OLD(a0) = -1; + ATR_VCT_NO(a0) = 0; //r?? + break; + } + //??????? + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + //????Ҥ + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = 26; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + /* ?????k? */ + ATR_CHR_NO(a1) = SPR_effect01; + /* ???t */ + LoadBmp(ATR_PAT_NO(a0)); +#ifndef __CARYTEST + ATR_V_POS(a1) = ATR_V_POS(a0) + a0->anim_y + SpriteInfo[ATR_PAT_NO(a0)].height / 2; +#else + ATR_V_POS(a1) = ATR_V_POS(a0) + a0->anim_y + g_lpRealAdrn[ATR_PAT_NO(a0)].height / 2; +#endif + ATR_H_POS(a1) = ATR_H_POS(a0); + } + break; + case 26: //????Ҥ + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //?????? + //?????? + while (1) + { + int dx; + + d0 = get_num(); //?????? + if (d0 == 255) //??? + break; + a2 = p_party[d0]; //???????????? + d0 = get_num(); //???????? + if (BattleCmd[command_point] == 'p') + dx = get_num(); //pet???????? + else + LogToBattleError(BattleCmd, __LINE__); + + //???????Ҥ + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + break; + } + /* ??? */ + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = 27; + ATR_BODY_WORK(0, a1) = a2; + ATR_INT_WORK0(a1) = d0; //????? + if (BattleCmd[command_point] == 'p') + ATR_INT_WORKp(a1) = dx; //pet????? + else + LogToBattleError(BattleCmd, __LINE__); + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + /* ?????k? */ + d0 = get_num(); + d0 = 0; + ATR_CHR_NO(a1) = SPR_heal + d0; + /* ???t */ + LoadBmp(ATR_PAT_NO(a2)); + ATR_H_POS(a1) = ATR_H_POS(a2); +#ifndef __CARYTEST + ATR_V_POS(a1) = ATR_V_POS(a2) + a2->anim_y + SpriteInfo[ATR_PAT_NO(a2)].height / 2; +#else + ATR_V_POS(a1) = ATR_V_POS(a2) + a2->anim_y + g_lpRealAdrn[ATR_PAT_NO(a2)].height / 2; +#endif + } + DeathAction(a0); //? + return; + } + break; + case 27: //?????? + if (ATR_HIT_STOP(a0)) + { + ATR_HIT_STOP(a0)--; + break; + } + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //?????? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + DeathAction(a0); //? + return; + } + if (ATR_CHR_CNT(a0) == 9 && ATR_CHR_TIM(a0) == 0) + { + a2 = ATR_BODY_WORK(0, a0); + ATR_DAMAGE(a2) = ATR_INT_WORK0(a0); //????? + ATR_LIFE(a2) += ATR_DAMAGE(a2); // + ATR_HIT_STOP(a0) = 40; + //??k + if (ATR_LIFE(a2) > ATR_MAX_LIFE(a2)) //???? + ATR_LIFE(a2) = ATR_MAX_LIFE(a2); //???? + ATR_PET_DAMAGE(a2) = ATR_INT_WORKp(a0); //????? + ATR_PET_LIFE(a2) += ATR_PET_DAMAGE(a2); // + //??k + if (ATR_PET_LIFE(a2) > ATR_PET_MAX_LIFE(a2)) //???? + ATR_PET_LIFE(a2) = ATR_PET_MAX_LIFE(a2); //???? + set_damage_num(a2, 14, -64); + } + break; +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ + case FIRE_HUNTER_SKILL: + if (ATR_FIRST_FLG(a0) == 0) + { //һغ + a2 = ATR_BODY_WORK(0, a0); //λַ + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a0, &d0, &d1); //״ + ATR_CRS(a0) = d0; //·ߴ + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; // + ATR_CHR_ACT(a0) = ANIM_ATTACK; // + } + ATR_HIT(a0) = 30; // + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { // + ATR_CHR_ACT_OLD(a0) = -1; + //Change fix ԭΪ 31 ij FIRE_HUNTER_SKILL+1 + ATR_VCT_NO(a0) = FIRE_HUNTER_SKILL+1; //˴ + ATR_FIRST_FLG(a0) = 0; //趨Ϊһغ + break; + } + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + a1 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); // + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //ѶϢ + ATR_VCT_NO(a0) = 0; // + return; + } + ATR_STIMER(a0) = 0; //???????? + ATR_NAME(a1) = fireHunter; //function + ATR_CHR_NO(a1) = 101734; //ͼ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; //ȶ + /*ʼλ*/ + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); //λַ + ATR_BODY_WORK(1, a1) = a0; //ij + for (int i = 2; i < ATR_BODY_CNT(a0) + 2; i++) + { + ATR_BODY_WORK(i, a1) = ATR_BODY_WORK(i, a0); //λַ + ATR_ATTACK_POW(i, a1) = ATR_ATTACK_POW(i, a0); // + ATR_ATTACK_PET_POW(i, a1) = ATR_ATTACK_PET_POW(i, a0); //﹥ + } + ATR_ATTACK_POW(0, a1) = ATR_ATTACK_POW(0, a0); // + ATR_ATTACK_PET_POW(0, a1) = ATR_ATTACK_PET_POW(0, a0); //﹥ + ATR_ATTACK_KIND(0, a1) = ATR_ATTACK_KIND(0, a0); // + ATR_SPD(a1) = 60; //ٶ + ATR_H_POS(a1) = ATR_H_POS(a0) ; + ATR_V_POS(a1) = ATR_V_POS(a0) - 50; + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; //· + ATR_COUNTER_FLG(a1) = ATR_CRS(a1); //˹·趨 + ATR_BODY_CNT(a1) = ATR_BODY_CNT(a0); // + bFireInit = TRUE; + FireSkillEnd = TRUE; + p_missile[0] = a1; + p_missile[1] = NULL; + d6 = 0; //㵽ʱ + while (1) + { + d0 = ATR_H_POS(ATR_BODY_WORK(0, a1)); + d1 = ATR_V_POS(ATR_BODY_WORK(0, a1)); + radar(a1, &d0, &d1); //״ + // + if (d1 <= 10) + break; + ATR_CRS(a1) = d0; + gemini(a1); + d6++; + } + if (!(ATR_GROUP_FLG(a1) = d6)) //ʱ䴢 + ATR_GROUP_FLG(a1) = 1; + ATR_H_POS(a1) = ATR_H_POS(a0) ; + ATR_V_POS(a1) = ATR_V_POS(a0) - 30; + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); // + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; //· + ATR_COUNTER_FLG(a1) = ATR_CRS(a1); //˹·趨 + } + break; + //Change fix з˯ߺٻ,ȥ 31 (ATR_VCT_NO(a0) = 31;),ȥ,Ϊ ATR_VCT_NO(a0) = FIRE_HUNTER_SKILL+1; ijһ + case FIRE_HUNTER_SKILL + 1: + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + if (!ATR_STIMER(a0)) //??????? + break; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + break; +#endif + case 30: //????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + a2 = ATR_BODY_WORK(0, a0); //??? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //???V + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + if (ATR_LONG_WORK(0, a0) == 0) //????? + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + else + ATR_CHR_ACT(a0) = ANIM_THROW; //????????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + ATR_HIT(a0) = 0; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + ATR_CHR_ACT_OLD(a0) = -1; + ATR_VCT_NO(a0) = 31; //????r?? + ATR_FIRST_FLG(a0) = 0; //???????? + break; + } + //??????? + //?D???? + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + //?????? + a1 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + ATR_STIMER(a0) = 0; //???????? + /* ??? */ + switch (ATR_LONG_WORK(0, a0)) + { + case 0: //? + ATR_NAME(a1) = bow; + ATR_CHR_NO(a1) = CG_ARROW_00 + ATR_CRS(a0) / 2 + 20; + break; + case 1: //??? + ATR_NAME(a1) = axe_shadow; + ATR_CHR_NO(a1) = SPR_onokage; + break; + case 2: //?? + ATR_NAME(a1) = stone_shadow; + ATR_CHR_NO(a1) = 25786; + break; + //Terry add 2001/12/28 +#ifdef _ITEM_FIRECREAKER + case 3: // + ATR_NAME(a1) = firecracker_shadow; + ATR_CHR_NO(a1) = 25786; + break; +#endif + //Terry end + default: + ATR_NAME(a1) = bow; + } + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; + /* ???t */ + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); //????? + ATR_BODY_WORK(1, a1) = a0; //D????? + ATR_ATTACK_POW(0, a1) = ATR_ATTACK_POW(0, a0); //??? + ATR_ATTACK_PET_POW(0, a1) = ATR_ATTACK_PET_POW(0, a0); //??? + ATR_ATTACK_KIND(0, a1) = ATR_ATTACK_KIND(0, a0); //????? + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_SPD(a1) = 32; + gemini(a1); + gemini(a1); + gemini(a1); + ATR_BODY_CNT(a1) = 0; + ATR_COUNTER_FLG(a1) = ATR_CRS(a0); //????????????? + p_missile[0] = a1; + p_missile[1] = NULL; + //???? + a2 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (a2 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + switch (ATR_LONG_WORK(0, a0)) + { + case 0: //? + ATR_NAME(a2) = stick_bow; + ATR_CHR_NO(a2) = CG_ARROW_00 + ATR_CRS(a0) / 2; + break; + case 1: //??? + ATR_NAME(a2) = axe; + ATR_CHR_NO(a2) = SPR_ono; + break; + case 2: //?? + ATR_NAME(a2) = stone; + ATR_CHR_NO(a2) = 25785; + break; + //Terry add 2001/12/28 +#ifdef _ITEM_FIRECREAKER + case 3: // + ATR_NAME(a2) = stone; + ATR_CHR_NO(a2) = 24350; + break; +#endif + //Terry end + default: + ATR_NAME(a2) = stick_bow; + } + /* ?IT */ + ATR_DISP_PRIO(a2) = D_PRIO_MISSILE; + //????????? + ATR_LONG_WORK(0, a1) = ATR_CHR_NO(a2); + ATR_BODY_WORK(2, a1) = a2; + /* ???t */ + ATR_CHR_ANG(a2) = ATR_CHR_ANG(a1); + a3 = ATR_BODY_WORK(0, a2) = ATR_BODY_WORK(0, a1); //????? + ATR_BODY_WORK(1, a2) = a1; //?s????? + ATR_H_POS(a2) = ATR_H_POS(a1); + ATR_V_POS(a2) = ATR_V_POS(a1); + + d6 = 0; //???? + ATR_SPD(a2) = 32; + while (1){ + d0 = ATR_H_POS(a3); + d1 = ATR_V_POS(a3); + radar(a2, &d0, &d1); //???? + //??????? + if (d1 <= 20){ + break; + } + ATR_CRS(a2) = d0; + gemini(a2); + d6++; + } + ATR_INT_WORK0(a2) = d1; //?????V + if (!(ATR_GROUP_FLG(a1) = d6)){ //???????V + ATR_GROUP_FLG(a1) = 1; + } + d6 = d6 >> 1; + ATR_SPD(a2) = d6; // + ATR_CRS(a2) = 0; // + ATR_H_MINI(a2) = 0; // + ATR_V_MINI(a2) = 0; // + ATR_H_POS(a2) = ATR_H_POS(a1); //? + ATR_V_POS(a2) = ATR_V_POS(a1) - 28; // + } + break; + + case 31: //??????r? + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + if (!ATR_STIMER(a0)){ //??????? + break; + } + d0 = get_num(); //???h?? + if (d0 == 255){ //??? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + } + else { + ATR_VCT_NO(a0) = 30; //???D + ATR_FIRST_FLG(a0) = 0; // + ATR_BODY_WORK(0, a0) = p_party[d0]; //???? + ATR_ATTACK_KIND(0, a0) = get_num(); //?????? + ATR_ATTACK_POW(0, a0) = get_num(); //?????? +#ifdef _PET_ITEM + if (ATR_ATTACK_KIND(0, a0) & ATT_ATTACKBACK) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif +#ifdef _FIX_ACUPUNCTURE + if (ATR_ATTACK_KIND(0, a0) & ATT_ACUPUNCTURE) + { + ATR_ATTACK_POW(1, a0) = ATR_ATTACK_POW(0, a0) >> 16; + ATR_ATTACK_POW(0, a0) = ATR_ATTACK_POW(0, a0) & 0x0000ffff; + } +#endif + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //pet?????? + else + LogToBattleError(BattleCmd, __LINE__); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + + } + break; + + case 32: // + // a2Ϊa1ΪӰ + if (ATR_FIRST_FLG(a0) == 0){ //??????? + a2 = ATR_BODY_WORK(0, a0); //??? + d0 = ATR_H_POS(a2); + d1 = ATR_V_POS(a2); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //???V + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + if (ATR_LONG_WORK(0, a0) == 0){ //????? + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + } + else { + ATR_CHR_ACT(a0) = ANIM_THROW; //????????? + } + ATR_FIRST_FLG(a0) = 1; //?????? + } + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + else if (ShooterNum == 101578) { + a2 = ATR_BODY_WORK(0, a0); //??? + // + //d0 = /*ATR_H_POS(a2) =*/ nutx[ a2->hitDispNo ] ; + //d1 = /*ATR_V_POS(a2) =*/ nuty[ a2->hitDispNo ] ; + // + d0 = ATR_H_POS(a2) = ATR_INT_WORK0(a2); + d1 = ATR_V_POS(a2) = ATR_INT_WORK1(a2); + + radar(a0, &d0, &d1); //???? + // ATR_CRS(a0) = d0; //???V + // ATR_CHR_ANG(a0) = crs_change_tbl[ d0 ]; /* ????? */ + } +#endif + + + ATR_HIT(a0) = 0; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)){ //???????? + ATR_VCT_NO(a0) = 33; //????r?? + break; + } + //??????? + //?D???? + if (ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100){ + //?????? + a1 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (a1 == NULL){ + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + switch (ATR_LONG_WORK(0, a0)){ + case 0: //? + ATR_NAME(a1) = bow; + break; + case 1: //??? + ATR_NAME(a1) = axe_shadow; + break; + case 2: //?? + ATR_NAME(a1) = stone_shadow; + break; + default: + ATR_NAME(a1) = bow; + } + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; + /* ?????k? */ +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if (ShooterNum == 101578) + ATR_CHR_NO(a1) = 27001; + else + ATR_CHR_NO(a1) = CG_ARROW_00 + ATR_CRS(a0) / 2 + 20; +#else + ATR_CHR_NO(a1) = CG_ARROW_00 + ATR_CRS(a0) / 2 + 20; +#endif + /* ???t */ + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); + ATR_BODY_WORK(0, a1) = ATR_BODY_WORK(0, a0); //????? + ATR_BODY_WORK(1, a1) = a0; //D????? + ATR_ATTACK_POW(0, a1) = ATR_ATTACK_POW(0, a0); //??? + ATR_ATTACK_PET_POW(0, a1) = ATR_ATTACK_PET_POW(0, a0); //??? + ATR_ATTACK_KIND(0, a1) = ATR_ATTACK_KIND(0, a0); //????? + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_SPD(a1) = 32; + gemini(a1); + gemini(a1); + gemini(a1); + ATR_BODY_CNT(a1) = 0; + ATR_COUNTER_FLG(a1) = ATR_CRS(a0); //????????????? + p_missile[0] = a1; + p_missile[1] = NULL; + + //???? + a2 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (a2 == NULL){ + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + switch (ATR_LONG_WORK(0, a0)){ + case 0: //? + ATR_NAME(a2) = stick_bow; + break; + case 1: //??? + ATR_NAME(a2) = axe; + break; + case 2: //?? + ATR_NAME(a2) = stone; + break; + default: + ATR_NAME(a2) = stick_bow; + } + /* ?IT */ + ATR_DISP_PRIO(a2) = D_PRIO_MISSILE; + /* ?????k? */ +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + //IJ + if (ShooterNum == 101578) + ATR_CHR_NO(a2) = 26995; + else + ATR_CHR_NO(a2) = CG_ARROW_00 + ATR_CRS(a0) / 2; +#else + ATR_CHR_NO(a2) = CG_ARROW_00 + ATR_CRS(a0) / 2; +#endif + //????????? + ATR_LONG_WORK(0, a1) = ATR_CHR_NO(a2); + ATR_BODY_WORK(2, a1) = a2; + /* ???t */ + ATR_CHR_ANG(a2) = ATR_CHR_ANG(a1); + a3 = ATR_BODY_WORK(0, a2) = ATR_BODY_WORK(0, a1); //????? + ATR_BODY_WORK(1, a2) = a1; //?s????? + ATR_H_POS(a2) = ATR_H_POS(a1); + ATR_V_POS(a2) = ATR_V_POS(a1); + + + d6 = 0; //???? + ATR_SPD(a2) = 32; + while (1) + { + d0 = ATR_H_POS(a3); + d1 = ATR_V_POS(a3); + radar(a2, &d0, &d1); //???? + //??????? + if (d1 <= 20) + break; + ATR_CRS(a2) = d0; + gemini(a2); + d6++; + } + ATR_INT_WORK0(a2) = d1; //?????V + if (!(ATR_GROUP_FLG(a1) = d6)) //???????V + ATR_GROUP_FLG(a1) = 1; + d6 = d6 >> 1; + ATR_SPD(a2) = d6; // + ATR_CRS(a2) = 0; // + ATR_H_MINI(a2) = 0; // + ATR_V_MINI(a2) = 0; // + ATR_H_POS(a2) = ATR_H_POS(a1); //? + ATR_V_POS(a2) = ATR_V_POS(a1) - 28; // + + d0 = get_num(); //???h?? + if (d0 != 255) + { //?????? + if (ATR_CHR_CNT(a0) >= 3) //???D + ATR_CHR_CNT(a0) -= 3; + else + ATR_CHR_ACT_OLD(a0) = -1; //???D + ATR_DAMAGE(a0)++; + ATR_FIRST_FLG(a0) = 0; + ATR_BODY_WORK(0, a0) = p_party[d0]; //趨 + ATR_ATTACK_KIND(0, a0) = get_num(); //趨 + ATR_ATTACK_POW(0, a0) = get_num(); //趨 + if (BattleCmd[command_point] == 'p') + ATR_ATTACK_PET_POW(0, a0) = get_num(); //﹥趨 + else + LogToBattleError(BattleCmd, __LINE__); + + //Ч xiezi +#ifdef _ATTACK_EFFECT + if (BattleCmd[command_point] == 's') + ATR_LONG_WORK(0, a0) = get_num(); // ¼Ч +#endif + } + } + break; + case 33: //ȴ + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + if (ATR_STIMER(a0) == ATR_DAMAGE(a0)) + { //????? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; // + } + break; + case 35: //ƶ + ATR_SPD(a0) = 32; //ٶ + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (d1 <= 32 * 2) + { //???? + ATR_VCT_NO(a0)++; //??? + ATR_FIRST_FLG(a0) = 0; //???????? + } + else + gemini(a0); //?h + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 36: //?? + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_HIT(a0) = 0; //????????? + d0 = ATR_H_POS(a1); //??? + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //???V + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; /* ????? */ + ATR_FIRST_FLG(a0) = 1; //?????? + } + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + ATR_VCT_NO(a0)++; //????r?? + ATR_FIRST_FLG(a0) = 0; //???????? + ATR_STIMER(a0) = 60; + break; + } + //??????? + if (ATR_HIT(a0) != 0 && ATR_HIT(a0) < 10100) + { + //????? + play_damage(ATR_HIT(a0), ATR_H_POS(a0)); + //? + set_damage_num(a0, 5, -64); + //??????? + ATR_VCT_NO(a1) = 45; + //????????? + ATR_BODY_WORK(0, a1) = a0; + //?hLT + ATR_SPD(a1) = ATR_SPD(a0) = 8; + //????????? + ATR_HIT(a0) = 0; + } + break; + case 37: //????r? + if (ATR_STIMER(a0)) + { + ATR_STIMER(a0)--; + break; + } + ATR_VCT_NO(a0)++; //????? + break; + case 38: //???? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_ATTACK_KIND(0, a0) == 0) + { //?? + if (ATR_VCT_NO(a1) == 45) + { //?????D?? + ATR_VCT_NO(a0) = 40; //???????? + ATR_DAMAGE(a0) = 0; //????? + } + else + ATR_VCT_NO(a0) = 42; //? + } + else + { + ATR_VCT_NO(a0) = 44; //?? + //? + set_damage_num(a0, 7, -64); + ATR_STIMER(a0) = 255; + ATR_DAMAGE(a0) = t_music_bgm_no; //???k?~ + play_bgm(0); //??????????? + } + } + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_ATTACK_KIND(0, a0) == 0 && ATR_VCT_NO(a1) == 45) + { //?? + if (!Rnd(0, 100)) + { //`?????? + ATR_VCT_NO(a0) = 40; //???????? + ATR_DAMAGE(a0) = 1; //????? + } + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + if (ATR_SPD(a0) == 32) //?????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 40: //??????? + a1 = ATR_BODY_WORK(0, a0); //???????? + ATR_VCT_NO(a1)++; //?????D + ATR_FIRST_FLG(a1) = 0; //???????? + // + set_damage_num(a0, 8, -64); + ATR_STIMER(a0) = 100; //???????? + if (ATR_DAMAGE(a0) == 1) //???? + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a0) + 4) & 7; //?? + ATR_VCT_NO(a0)++; //????? + break; + case 41: //???? + if (!--ATR_STIMER(a0)) + { + if (ATR_DAMAGE(a0) == 1) + { //???? + ATR_VCT_NO(a0) = 38; //???? + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a0) + 4) & 7; //?? + ATR_SPD(a0) = 32; //????? + } + else + ATR_VCT_NO(a0)++; //? + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + } + else + ATR_CHR_ACT(a0) = ANIM_ANGRY; //???????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 42: //ʧ + ATR_CHR_ACT(a0) = ANIM_STAND; //ֹͣ + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + a1 = ATR_BODY_WORK(0, a0); //ȡзָ + if (ATR_VCT_NO(a1) == 0) + { //?????`????? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + } + break; + case 44: //ɹ + if (!--ATR_STIMER(a0)) + { //ʱ䵽 + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; // + play_bgm(ATR_DAMAGE(a0)); //????? + } + ATR_CHR_ACT(a0) = ANIM_HAPPY; //??????????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 45: //?????? + a1 = ATR_BODY_WORK(0, a0); //?????????? + if (ATR_VCT_NO(a1) == 38) + { //??????? + d0 = ATR_H_POS(a1); //??? + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //???V + gemini(a0); + } + if (ATR_VCT_NO(a1) == 0) + { //??????? + ATR_ATTRIB(a0) = ACT_ATR_HIDE; //?? + ATR_NAME(a0) = NULL; + return; + } + ATR_CHR_ACT(a0) = ANIM_DAMAGE; //??????????? + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a0) + 1) & 7; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 46: //?????????? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_SPD(a0) = 16; + gemini(a0); //?h + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + a1 = ATR_BODY_WORK(0, a0); //?????????? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + ATR_VCT_NO(a0) = 0; //r?? + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 50: //PfD? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_SPD(a0) = 16; + if (ATR_LIFE(a0) <= 0) + { //?????? + if (ATR_GROUP_FLG(a0) == 0) //???????? + //???? + ATR_CRS(a0) = crs_change_tbl2[7]; + else + ATR_CRS(a0) = crs_change_tbl2[3]; + } + else + { + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + } + ATR_FIRST_FLG(a0) = 1; //?????? + } + gemini(a0); //?h + if (ATR_LIFE(a0) > 0) + { //????? + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, 1, ANM_LOOP); + } + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + ATR_DAMAGE(p_master)++; //D? + if (ATR_DAMAGE(p_master) == ATR_BODY_CNT(p_master) && ATR_GUARD_FLG(a0) == 1) + { //ACTION_INF@e?? + action_inf = 2; + command_point = 0; //????????????? + } + } + break; + case 52: //սʧ() + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + if (ATR_LIFE(a0) <= 0) + { //?????? + //????V?ϣ?? + if (ATR_PET_OK(a0)) + { + a2 = p_party[ATR_PLACE_NO(a0) + 5]; //???????? + if (ATR_NAME(a2) != NULL) + { + ATR_VCT_NO(a2) = 50; //????`?? + ATR_FIRST_FLG(a2) = 0; //???????? + } + } + ATR_VCT_NO(a0) = 50; //ܳɹ + break; + } + //ʾ + set_damage_num(a0, 9, -64); + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + ATR_STIMER(a0) = 12; //??????? + ATR_COUNTER_FLG(a0) = 0; // + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + pattern(a0, ATR_STIMER(a0), ANM_LOOP); + //???????LT??? + ATR_COUNTER_FLG(a0) = (ATR_COUNTER_FLG(a0) + 1) & 7; + if (!ATR_COUNTER_FLG(a0)) + { + ATR_STIMER(a0)--; + if (ATR_STIMER(a0) == 1) + { //????L?? + if (ATR_ATTACK_KIND(0, a0) == 0) //D?? + ATR_VCT_NO(a0)++; //D? + else + { + ATR_VCT_NO(a0) = 50; //D?? + ATR_FIRST_FLG(a0) = 0; //???????? + //????V?ϣ?? + if (ATR_PET_OK(a0)) + { + a2 = p_party[ATR_PLACE_NO(a0) + 5]; //???????? + if (ATR_NAME(a2) != NULL) + { + ATR_VCT_NO(a2) = 50; //????`?? + ATR_FIRST_FLG(a2) = 0; //???????? + } + } + } + } + } + break; + case 53: //սʧ() + pattern(a0, ATR_STIMER(a0), ANM_LOOP); + //???????LT??? + ATR_COUNTER_FLG(a0) = (ATR_COUNTER_FLG(a0) + 1) & 7; + if (!ATR_COUNTER_FLG(a0)) + { + ATR_STIMER(a0)++; + if (ATR_STIMER(a0) == 12) + { //???????? + ATR_STIMER(a0) = 60; + ATR_VCT_NO(a0)++; + //ʾʧ + set_damage_num(a0, 8, -64); + } + } + break; + case 54: //PfD?????? + ATR_CHR_ACT(a0) = ANIM_SAD; //??????????? + pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + if (!--ATR_STIMER(a0)) + { //?????? + ATR_DAMAGE(p_master)++; //D? + //????V?ϣ?? + if (ATR_PET_OK(a0)) + { + a2 = p_party[ATR_PLACE_NO(a0) + 5]; //???????? + if (ATR_NAME(a2) != NULL) // + ATR_DAMAGE(p_master)++; //???D? + } + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_VCT_NO(a0) = 0; //r?? + } + break; + case 55: // + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_SPD(a0) = 63; //?hLT??? + if (ATR_AKO_FLG(a0) == 2) //?????? + ATR_LONG_WORK(0, a0) = 0; //??????? + else + { + ATR_LONG_WORK(0, a0) = 3; //??????? + //ɵ + play_se(11, ATR_H_POS(a0), ATR_V_POS(a0)); + } + ATR_FIRST_FLG(a0) = 1; //?????? + } + gemini(a0); + if (ATR_LONG_WORK(0, a0) < 3) + { //???? + if (ATR_CRS(a0) < 8 || ATR_CRS(a0) > 24) + { + if (ATR_V_POS(a0) <= 0) + { //ƣZ? + d0 = 0; + goto monster_case55_100; //?????? + } + } + if (ATR_CRS(a0) < 16 && ATR_CRS(a0) > 0) + { + if (ATR_H_POS(a0) >= lpDraw->xSize) + { //?Z? + d0 = 1; + goto monster_case55_100; //?????? + } + } + if (ATR_CRS(a0) > 8 && ATR_CRS(a0) < 24) + { + if (ATR_V_POS(a0) >= lpDraw->ySize) + { //?Z? + d0 = 2; + goto monster_case55_100; //?????? + } + } + if (ATR_CRS(a0) > 16) + { + if (ATR_H_POS(a0) <= 0) + { //?Z? + d0 = 3; + goto monster_case55_100; //?????? + } + } + goto monster_case55_200; //?????? + + monster_case55_100: + d1 = ATR_CRS(a0); + d1 = ATR_CRS(a0) = crs_bound_tbl[d0][ATR_CRS(a0)]; //?? + ATR_LONG_WORK(0, a0)++; + //??? + play_se(66, ATR_H_POS(a0), ATR_V_POS(a0)); + + monster_case55_200: + ; + } + else + { + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT || ATR_V_POS(a0) > lpDraw->ySize + SCREEN_OUT || ATR_V_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + if (BattleMyNo == ATR_PLACE_NO(a0)) + { //?? + action_inf = 2; ////ACTION_INF@e + command_point = 0; //????????????? + break; + } + //???????? + a1 = ATR_BODY_WORK(0, a0); + if (a1 != NULL) + { + //????? + if (ATR_ATTACK_KIND(2, a1) == 1) + { + //???? + ATR_ATTRIB(a1) |= ACT_ATR_HIDE; //?? + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + if (ATR_COUNTER(p_master) == a0) //????? +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_BATTLE_MODEL(a0) != ATT_BATTLE_MODEL) +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + } + else + { + ATR_VCT_NO(a1) = 57; //???`?? + ATR_FIRST_FLG(a1) = 0; + } + } + else + { + if (ATR_COUNTER(p_master) == a0) //????? + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_BATTLE_MODEL(a0) != ATT_BATTLE_MODEL) +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + } + } + break; + } + } + if (ATR_AKO_FLG(a0) == 2) + { //?????? + if (ATR_LONG_WORK(0, a0) & 1) + ATR_CHR_ANG(a0)--; //?? + else + ATR_CHR_ANG(a0)++; //?? + ATR_CHR_ANG(a0) &= 7; //? + pattern(a0, 1, ANM_NO_LOOP); + } + break; + case 56: //????????? + a1 = ATR_BODY_WORK(0, a0); //???????? + //??? + if (ATR_H_POS(a1) < lpDraw->xSize && ATR_H_POS(a1) > 64 && ATR_V_POS(a1) < lpDraw->ySize && ATR_V_POS(a1) > 0 - 64) + { + d0 = ATR_H_POS(a1); //????? + d1 = ATR_V_POS(a1); + radar2(a0, d0, d1, 2); //???? + //???????? + d0 = ATR_CRS(a0) - ATR_CRS_OLD(a0); + if (d0 < 0) + d0 = 0 - d0; + if (d0 >= 2) + { + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CRS_OLD(a0) = ATR_CRS(a0); + } + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 57: //??????? + if (ATR_FIRST_FLG(a0) == 0) //??????? + { + ATR_SPD(a0) = 16; + if (ATR_LIFE(a0) <= 0) + { //?????? + if (ATR_GROUP_FLG(a0) == 0) //???????? + //???? + ATR_CRS(a0) = crs_change_tbl2[7]; + else + ATR_CRS(a0) = crs_change_tbl2[3]; + } + else + { + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + } + //????????????V?? + ATR_FIRST_FLG(a0) = 1; //?????? + } + gemini(a0); //?h + //????????????V?? + if (ATR_LIFE(a0) > 0) //????? + { + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, 1, ANM_LOOP); + } + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) //???? + { + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + //?????????????????????????????????????????????? + if (check_all_dead()) + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + if (ATR_COUNTER(p_master) == ATR_BODY_WORK(0, a0)) //???????? + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_BATTLE_MODEL(a0) != ATT_BATTLE_MODEL) +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + } + if (ATR_COUNTER(p_master) == a0) //????? + { +#ifdef _PETSKILL_BATTLE_MODEL + if (ATR_BATTLE_MODEL(a0) != ATT_BATTLE_MODEL) +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + } + } + break; + case 60: //????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + a1 = ATR_BODY_WORK(0, a0); //???????? + set_damage_num(a1, 10, -64); //?? + ATR_STIMER(a0) = 40; + play_se(216, ATR_H_POS(a0), 240); //?????? + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + ATR_CRS_OLD(a1) = ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_FIRST_FLG(a0) = 1; //?????? + } + //???? + if (!--ATR_STIMER(a0)) + { + ATR_FIRST_FLG(a0) = 0; //?????? + ATR_VCT_NO(a0)++; //?? + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + + case 61: //????? + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_SPD(a0) = 12; + if (ATR_LIFE(a0) > 0) + { //????? + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + } + ATR_FIRST_FLG(a0) = 1; //?????? + } + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + //???? + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_NAME(a0) = NULL; + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + break; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 62: //???? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + a1 = ATR_BODY_WORK(0, a0); //???????? + set_damage_num(a1, 11, -64); //?? + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + ATR_CRS_OLD(a1) = ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_STIMER(a0) = 40; + //???k???? + ATR_CHR_NO(a0) = get_num(); + //?????? + ATR_LEVEL(a0) = get_num(); + //????? + ATR_LIFE(a0) = get_num(); + //q??? + get_name(a0); + //?????? + ATR_MAX_LIFE(a0) = get_num(); + //???????? + a1 = ATR_BODY_WORK(0, a0); + //???? + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1) - 1; + //?? + ATR_ATTRIB(a0) &= ~ACT_ATR_HIDE; + ATR_SPD(a0) = 12; + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + ATR_CHR_ACT_OLD(a0) = -1; + ATR_AKO_FLG(a0) = 0; //????????? + ATR_ATTACK_KIND(2, a0) = 0; + ATR_STATUS(a0) = 0; //????????? + play_se(216, ATR_H_POS(a0), 240); //?????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + //???? + if (!--ATR_STIMER(a0)) + { + ATR_FIRST_FLG(a0) = 0; //?????? + ATR_VCT_NO(a0)++; //?? + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 63: //???? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + ATR_VCT_NO(a0) = 0; //r?? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 64: //?????r? + a1 = ATR_BODY_WORK(1, a0); //????? + //?????????? + if (ATR_VCT_NO(a1) != 2) + { + ATR_VCT_NO(a0) = 13; //??????r? + ATR_STIMER(a0) = 30; + } + break; + case 65: //???? + break; + case 66: //???h + a1 = ATR_BODY_WORK(0, a0); //???????? + if (ATR_FIRST_FLG(a0) == 0) //??????? + { + ATR_SPD(a0) = 28; + ATR_FIRST_FLG(a0) = 1; //?????? + } + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 1)) //???? + { + //??祆??? + ATR_VCT_NO(a1) = 67; + ATR_CRS(a1) = ATR_CRS(a0); //??????? + ATR_SPD(a1) = 40; + ATR_STIMER(a1) = 8; + //??Ԩ? +#ifdef _PETSKILL_BATTLE_MODEL + // DZ + if (ATR_BATTLE_MODEL(a1) == ATT_BATTLE_MODEL) + a1 = ATR_BODY_WORK(1, a1); // ATR_BODY_WORK(1,a1) ȡ action + else +#endif + a1 = ATR_COUNTER(p_master); + ATR_BODY_WORK(0, a1) = a0; //????? + //???????_ + ATR_VCT_NO(a0) = 65; + //???? + play_se(5, ATR_H_POS(a0), 240); + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 67: //?????? + gemini(a0); //?????? + ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31; + if (--ATR_STIMER(a0)) //??r??? + break; + ATR_VCT_NO(a0) = 68; + //???? +#ifdef _PETSKILL_BATTLE_MODEL + // DZ + if (ATR_BATTLE_MODEL(a0) == ATT_BATTLE_MODEL) + a1 = ATR_BODY_WORK(1, a0); // ATR_BODY_WORK(1, a0) ȡ action + else +#endif + a1 = ATR_COUNTER(p_master); //????????? + ATR_VCT_NO(a1) = 2; + break; + case 68: //?????? + gemini(a0); //?h + ATR_SPD(a0) -= 2; + if (ATR_SPD(a0) < 0) //????????? + { + ATR_SPD(a0) = 10; + ATR_VCT_NO(a0) = 64; //?????r?? + } + break; + case 69: //?????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + //?? + set_damage_num(a0, 13, -64); + ATR_STIMER(a0) = 35; + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (--ATR_STIMER(a0)) //??r??? + break; + ATR_VCT_NO(a0) = 66; //??h? + ATR_FIRST_FLG(a0) = 0; //?????? + break; + case 70: //??????? + if (ATR_FIRST_FLG(a0) == 0) //??????? + { + int d2; + + d1 = command_point; //?????????~ + d0 = get_num(); //?? + command_point = d1; //??????????? + d0 /= 5; + if (ATR_GROUP_FLG(a0) == 0) //???????? + { + d1 = boomerang_pos_tbl[d0 * 2]; + d2 = boomerang_pos_tbl[d0 * 2 + 1]; + } + else + { + //??????q??? + if (ATR_PLACE_NO(a0) >= 15) + { + d1 = boomerang_pos_tbl3b[d0 * 2]; + d2 = boomerang_pos_tbl3b[d0 * 2 + 1]; + } + else + { + d1 = boomerang_pos_tbl3a[d0 * 2]; + d2 = boomerang_pos_tbl3a[d0 * 2 + 1]; + } + } + radar(a0, &d1, &d2); //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = d1; + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ +#if 0 + ATR_CHR_ACT(a0) = ANIM_THROW; //????????? +#else + if (ATR_LONG_WORK(0, a0) == 0) //????? + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + else + ATR_CHR_ACT(a0) = ANIM_THROW; //????????? +#endif + + ATR_FIRST_FLG(a0) = 1; //?????? + } + ATR_HIT(a0) = 0; //????????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) //???????? + { + ATR_CHR_ACT_OLD(a0) = -1; + ATR_VCT_NO(a0) = 71; //????????? + break; + } + //??????? + //?????D???? + if(ATR_HIT(a0) >= 10000 && ATR_HIT(a0) < 10100) + { + //???????? + a1 = GetAction(T_PRIO_BOW, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + //????????? + ATR_BODY_WORK(0, a0) = a1; //????????? + /* ??? */ + ATR_NAME(a1) = boomerang; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MISSILE; + /* ?????k? */ + ATR_CHR_NO(a1) = SPR_boomerang;//SPR_ono;// + /* ???t */ + ATR_CHR_ANG(a1) = ATR_CHR_ANG(a0); + ATR_BODY_WORK(1, a1) = a0; //D????? + d1 = command_point; //?????????~ + d0 = get_num(); //?? + command_point = d1; //??????????? + //?k???? + ATR_LONG_WORK(0, a1) = d0 / 5; + //??T??? + if (ATR_GROUP_FLG(a0) == 0) + { + if (ATR_LONG_WORK(0, a1) <= 1) + ATR_LONG_WORK(1, a1) = 1; + else + ATR_LONG_WORK(1, a1) = 2; + } + else + { + if (ATR_LONG_WORK(0, a1) <= 1) + ATR_LONG_WORK(1, a1) = 2; + else + ATR_LONG_WORK(1, a1) = 1; + } + ATR_GROUP_FLG(a1) = ATR_GROUP_FLG(a0); + ATR_PLACE_NO(a1) = ATR_PLACE_NO(a0); + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_SPD(a1) = 32; + gemini(a1); + gemini(a1); + gemini(a1); + p_missile[0] = a1; + p_missile[1] = NULL; + } + break; + case 71: //???????? + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + a1 = ATR_BODY_WORK(0, a0); //???????????? + + //??? + d0 = ATR_H_POS(a1); //??? + d1 = ATR_V_POS(a1); + radar2(a0, d0, d1, 2); //???? + //???????? + d0 = ATR_CRS(a0) - ATR_CRS_OLD(a0); + if (d0 < 0) + d0 = 0 - d0; + if (d0 >= 2) + { + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CRS_OLD(a0) = ATR_CRS(a0); + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 72: //???????? + ATR_CHR_ACT(a0) = ANIM_HAND; //????????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_VCT_NO(a0) = 73; //?????????? + ATR_STIMER(a0) = 16; + break; + case 73: //????????? + if (!(--ATR_STIMER(a0))) //??? + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //_? + } + break; + case 75: //? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + //?????Ҥ + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = 76; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + /* ?????k? */ + ATR_CHR_NO(a1) = get_num(); //????????? +#ifdef _VARY_WOLF + if (ATR_CHR_NO(a1) == 101120) + ATR_DISP_PRIO(a1) = ATR_DISP_PRIO(a0) - 1; +#endif +#ifdef _PROFESSION_ADDSKILL + if ( !g_bUseAlpha ){ + if ( ATR_CHR_NO(a1) == 101769 || ATR_CHR_NO(a1) == 101772 || ATR_CHR_NO(a1) == 101773 ) + ATR_CHR_NO(a1) += 55; + if ( ATR_CHR_NO(a1) == 101802 || ATR_CHR_NO(a1) == 101803 || ATR_CHR_NO(a1) == 101804 ) + ATR_CHR_NO(a1) += 53; + } +#endif + /* ???t */ + LoadBmp(ATR_PAT_NO(a0)); + //??????? +#ifndef __CARYTEST + ATR_INT_WORK0(a1) = a0->anim_y + SpriteInfo[ATR_PAT_NO(a0)].height / 2; +#else + ATR_INT_WORK0(a1) = a0->anim_y + g_lpRealAdrn[ATR_PAT_NO(a0)].height / 2; +#endif + //??????????? + ATR_BODY_WORK(0, a1) = a0; + ATR_V_POS(a1) = ATR_V_POS(a0) + ATR_INT_WORK0(a1); + ATR_H_POS(a1) = ATR_H_POS(a0); + //r?? + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + break; + case 76: //??Ҥ + //?t + a1 = ATR_BODY_WORK(0, a0); + ATR_V_POS(a0) = ATR_V_POS(a1) + ATR_INT_WORK0(a0); + //????????? + if (ATR_CHR_NO(a0) == SPR_effect01) + d0 = pattern(a0, 5, ANM_NO_LOOP); + else + d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + if (d0) + { //?????? + DeathAction(a0); //? + d0 = get_num(); //????????? + d6 = 0; //????????? +#ifdef _VARY_WOLF + if (d0 >= 101429 && d0 <= 101436) + a1->anim_chr_no = 0; +#endif +#ifdef _PROFESSION_ADDSKILL + if (!g_bUseAlpha) + { + if (d0 == 101769 || d0 == 101772 || d0 == 101773) + d0 += 55; + if (d0 == 101802 || d0 == 101803 || d0 == 101804) + d0 += 53; + } +#endif + while (1) + { + d1 = get_num(); //ԧk??? + if (d1 == 255) + { //??? + if (d6 == 0) //??? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + break; + } + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + return; + } + //???????Ҥ + if (d1 < 0 || d1 >= BATTLKPKPLYAERNUM) + { + return; + } + a2 = p_party[d1]; //?????????? + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = 77; + ATR_CHR_NO(a1) = d0; //?????? + /* ???t */ + LoadBmp(ATR_PAT_NO(a2)); + //??????? +#ifndef __CARYTEST + ATR_INT_WORK0(a1) = a2->anim_y + SpriteInfo[ATR_PAT_NO(a2)].height / 2; +#else + ATR_INT_WORK0(a1) = a2->anim_y + g_lpRealAdrn[ATR_PAT_NO(a2)].height / 2; +#endif + //??????????? + ATR_BODY_WORK(0, a1) = a2; + ATR_V_POS(a1) = ATR_V_POS(a2) + ATR_INT_WORK0(a1); + ATR_H_POS(a1) = ATR_H_POS(a2); + d6++; //??????? + } + return; + } + break; + case 77: //??Ҥ + //?t + a1 = ATR_BODY_WORK(0, a0); + ATR_V_POS(a0) = ATR_V_POS(a1) + ATR_INT_WORK0(a0); + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //?????? + DeathAction(a0); //? +#ifdef _VARY_WOLF + if (a0->anim_chr_no_bak >= 101429 && a0->anim_chr_no_bak <= 101436) + a1->anim_chr_no = 101428; +#endif +#ifdef _PETSKILL_EVOLUTION + if ( a0->anim_chr_no_bak==101863 ){ //ͼֱӱ + if( a1->anim_chr_no == 102009 ) + a1->anim_chr_no = 102011; + else if( a1->anim_chr_no == 102010 ) + a1->anim_chr_no = 102012; + } +#endif + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + return; + } + break; + case 78: //??????? + ATR_FIRST_FLG(a0)++; + if (ATR_FIRST_FLG(a0) == 60) + { + ATR_FIRST_FLG(a0) = 0; + if (ATR_LIFE(a0) <= 0) + { //?????? + ATR_VCT_NO(a0) = VCT_NO_DIE + 1; //?? + slow_flg--; //????? + } + else + ATR_VCT_NO(a0) = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + break; + case 79: //?r? + ATR_LONG_WORK(0, a0)++; + if (ATR_LONG_WORK(0, a0) == 60) + { + ATR_VCT_NO(a0) = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + break; + case 80: //?? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_SPD(a0) = 32; + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + gemini(a0); //?h + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_VCT_NO(a0) = 0; //_? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + break; + case 82: //??? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_CHR_ACT(a0) = ANIM_SIT; //????????? + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + ATR_STIMER(a0) = 60; + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (!--ATR_STIMER(a0)) + { //??? + ATR_CHR_NO(a0) = get_num(); + ATR_CHR_ACT_OLD(a0) = -1; + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + ATR_CHR_ACT(a0) = ANIM_STAND; + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + ATR_VCT_NO(a0) = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + break; + case 85: //?????Nͨ? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + //?????Ҥ + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + ATR_VCT_NO(a0) = 0; //r?? + return; + } + /* ??? */ + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = 86; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + /* ?????k? */ + ATR_CHR_NO(a1) = SPR_effect01; + /* ???t */ + LoadBmp(ATR_PAT_NO(a0)); + //??????? +#ifndef __CARYTEST + ATR_INT_WORK0(a1) = a0->anim_y + SpriteInfo[ATR_PAT_NO(a0)].height / 2; +#else + ATR_INT_WORK0(a1) = a0->anim_y + g_lpRealAdrn[ATR_PAT_NO(a0)].height / 2; +#endif + //??????????? + ATR_BODY_WORK(0, a1) = a0; + ATR_V_POS(a1) = ATR_V_POS(a0) + ATR_INT_WORK0(a1); + ATR_H_POS(a1) = ATR_H_POS(a0); + //r?? + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); //??? + break; + case 86: //?????Nͨ??Ҥ + //????????? + if (ATR_CHR_NO(a0) == SPR_effect01) + d0 = pattern(a0, 5, ANM_NO_LOOP); + else + d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP); + if (d0) + { //?????? + //Nͨ? + ATR_ATTRIB(p_master) = get_num(); //N?? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + DeathAction(a0); //? + return; + } + break; + case 87: //???`??q + ATR_SPD(a0) = 32; //?hLTspeed + a1 = p_party[ATR_PLACE_NO(a0) - 5]; //????//з + d0 = ATR_H_POS(a1);//y + d1 = ATR_V_POS(a1);//x + radar(a0, &d0, &d1); //????//d0:course1 d1:distance + ATR_CRS(a0) = d0; //?????? + //???????? + d0 = ATR_CRS(a0) - ATR_CRS_OLD(a0); + if (d0 < 0) + d0 = 0 - d0; + if (d0 >= 2) + { +#ifdef _SKILL_ROAR //輼:()//ܷ +#else + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CRS_OLD(a0) = ATR_CRS(a0); +#endif + } + if (d1 <= 32 * 2) + { //???? + ATR_FIRST_FLG(a0) = 0; //???????? + ATR_VCT_NO(a0) = 88; //???`??? + } + else + gemini(a0); //?h + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 88: //???`?? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_STIMER(a0) = 40; +#ifdef _SKILL_ROAR //輼:()//ܷ + //?hLT??? + ATR_SPD(a0) = 60; + ATR_CHR_ACT(a0) = ANIM_DAMAGE; //_??????? +#else + //?hLT??? + ATR_SPD(a0) = 40; + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? +#endif + ATR_FIRST_FLG(a0) = 1; //?????? + } + //?h??? + if (!ATR_STIMER(a0)--) + { + ATR_VCT_NO(a0) = 89; //???`???? + ATR_STIMER(a0) = 40; + //???`? + set_damage_num(a0, 17, -64); +#ifdef _SKILL_ROAR //輼:()ܷ + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif +#else + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif +#endif + //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = (crs_change_tbl2[ATR_CHR_ANG(a0)]) & 31; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 89: //???`??? + if (ATR_STIMER(a0)) + { + ATR_STIMER(a0)--; + break; + } + gemini(a0); + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + ATR_DAMAGE(p_master)++; //D? + //?????? + if (BattleMyNo + 5 == ATR_PLACE_NO(a0)) + { + // ???????????? + if (att_select_flg == TRUE) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + { + // i????? + if (battlePetNoBak2 == pc.battlePetNo) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + //???? + pc.selectPetNo[battlePetNoBak2] = FALSE; + } + } + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, 1, ANM_LOOP); + break; + case 90: //????r + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + //????r + set_damage_num(a0, 18, -64); + ATR_STIMER(a0) = 0; //???????? + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + //??? + d0 = pet_nix_tbl[ATR_STIMER(a0)++]; + if (d0 == -2) + { //??? + ATR_VCT_NO(a0) = 0; //_? + ATR_DAMAGE(p_master)++; //D? + break; + } + ATR_CHR_ANG(a0) = (ATR_CHR_ANG(a0) + d0) & 7; //??? + pattern(a0, 1, ANM_LOOP); + break; + case 95: //s????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_LONG_WORK(0, a0) = get_num(); //???? + ATR_LONG_WORK(1, a0) = get_num(); //??????? + a1 = ATR_BODY_WORK(0, a0) = p_party[ATR_LONG_WORK(0, a0)]; //???? + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_SPD(a0) = 32; //?hLT + ATR_FIRST_FLG(a0) = 1; //?????? + } + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); + if (d1 <= 32 * 2) + { //???? + ATR_VCT_NO(a0) = 96; //s?????? + if (ATR_LONG_WORK(1, a0)) + { //??? + a1 = ATR_BODY_WORK(0, a0); //????????_ + ATR_VCT_NO(a1) = 98; // + ATR_SPD(a1) = ATR_SPD(a0); + ATR_CRS(a1) = ATR_CRS(a0); + } + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 96: //s????? + gemini(a0); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT //???? + || ATR_V_POS(a0) > lpDraw->ySize + SCREEN_OUT || ATR_V_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + //?????? + if (BattleMyNo + 5 == ATR_PLACE_NO(a0)) + { + // ???????????? + if (att_select_flg == TRUE) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + { + // i????? + if (battlePetNoBak2 == pc.battlePetNo) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + //???? + pc.selectPetNo[battlePetNoBak2] = FALSE; + } + } + if (ATR_LONG_WORK(1, a0)) + { //??? + a1 = ATR_BODY_WORK(0, a0); //????? + ATR_NAME(a1) = NULL; + ATR_ATTRIB(a1) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + //?????? + if (BattleMyNo + 5 == ATR_LONG_WORK(0, a0)) + { + // ???????????? + if (att_select_flg == TRUE) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + { + // i????? + if (battlePetNoBak2 == pc.battlePetNo) + { + //???? + pc.selectPetNo[pc.battlePetNo] = FALSE; + pc.battlePetNo = -1; + } + else + //???? + pc.selectPetNo[battlePetNoBak2] = FALSE; + } + } + } + } + break; + case 98: //s????????????_ + gemini(a0); + break; + case 100: //????? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_LONG_WORK(0, a0) = get_num(); //???? + ATR_LONG_WORK(1, a0) = get_num(); //??????? + a1 = ATR_BODY_WORK(0, a0) = p_party[ATR_LONG_WORK(0, a0)]; //???? + d0 = ATR_INT_WORK0(a1); + d1 = ATR_INT_WORK1(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + ATR_CHR_ANG(a0) = crs_change_tbl[ATR_CRS(a0)]; /* ????? */ + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_SPD(a0) = 32; //?hLT + ATR_FIRST_FLG(a0) = 1; //?????? + } + a1 = ATR_BODY_WORK(0, a0); //???????? + d0 = ATR_H_POS(a1); + d1 = ATR_V_POS(a1); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); + if (d1 <= 32 * 2) + { //???? + ATR_VCT_NO(a0) = 101; //????? + ATR_FIRST_FLG(a0) = 0; //??????? + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 101: //???? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_CHR_ACT(a0) = ANIM_ATTACK; //????????? + ATR_FIRST_FLG(a0) = 1; //?????? + } + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //???????? + ATR_CHR_ACT_OLD(a0) = -1; + ATR_VCT_NO(a0) = 102; //????r?? + ATR_FIRST_FLG(a0) = 0; //??????? + } + break; + case 102: //????r? + if (ATR_FIRST_FLG(a0) == 0) + { //??????? + ATR_STIMER(a0) = 30; //????? + if (ATR_LONG_WORK(1, a0)) //??? + //? + set_damage_num(a0, 7, -64); + else + // + set_damage_num(a0, 8, -64); + ATR_FIRST_FLG(a0) = 1; //?????? + } + ATR_STIMER(a0)--; + if (ATR_STIMER(a0) == 0) + { //??? + if (ATR_LONG_WORK(1, a0)) + { //??? + ATR_VCT_NO(a0) = 103; //`???? + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 7; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 3; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 1; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 5; +#endif + //???? + ATR_CRS_OLD(a0) = ATR_CRS(a0) = (crs_change_tbl2[ATR_CHR_ANG(a0)]) & 31; + a1 = ATR_BODY_WORK(0, a0); //????????? + ATR_VCT_NO(a1) = 104; + } + else + { + d0 = ATR_INT_WORK0(a0); //??? + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CHR_ANG(a0) = crs_change_tbl[d0]; + ATR_SPD(a0) = 32; + ATR_VCT_NO(a0) = 4; //?~? + } + } + break; + case 103: //`??? + gemini(a0); + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_NAME(a0) = NULL; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + ATR_VCT_NO(a0) = VCT_NO_APPEAR; + ATR_DAMAGE(p_master)++; //D? + a1 = ATR_BODY_WORK(0, a0); //?????_? + ATR_VCT_NO(a1) = 0; + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, 1, ANM_LOOP); + break; + case 104: //`????? + ATR_CHR_ACT(a0) = ANIM_ANGRY; //???????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case 105: //??r? + if (!--ATR_STIMER(a0)) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + ATR_VCT_NO(a0) = 0; //_? + } + break; + case 110: //???? + if (!--ATR_STIMER(a0)) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //??? + ATR_VCT_NO(a0) = 0; //_? + } + break; +#ifdef _SKILL_SELFEXPLODE //Ա + case 114: //Ա + ATR_SPD(a0) = 63; + ATR_ATTRIB(a0) |= ACT_ATR_HIDE; //?? + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + gemini(a0); //?h + if (ATR_H_POS(a0) > lpDraw->xSize + SCREEN_OUT || ATR_H_POS(a0) < 0 - SCREEN_OUT) + { //???? + ATR_VCT_NO(a0) = 0; //_? + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); //?????? + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; +#endif + //249: + case VCT_NO_APPEAR: //K + if (ATR_GROUP_FLG(a0) == 0) + ATR_CHR_ANG(a0) = 3; + else if (ATR_GROUP_FLG(a0) == 1) + ATR_CHR_ANG(a0) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a0) == 2) + ATR_CHR_ANG(a0) = 5; + else if (ATR_GROUP_FLG(a0) == 3) + ATR_CHR_ANG(a0) = 1; +#endif + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_SPD(a0) = 12; + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2) || ATR_CHR_NO(a0) == 101490) + { //???? + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + ATR_VCT_NO(a0) = 0; //r?? + ATR_CHR_ACT(a0) = ANIM_STAND; //_??????? + ATR_SPD(a0) = 32; + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + } + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case VCT_NO_DIE: //? + ATR_SPD(a0) = 4; + d0 = ATR_INT_WORK0(a0); + d1 = ATR_INT_WORK1(a0); + radar(a0, &d0, &d1); //???? + ATR_CRS(a0) = d0; //?????? + gemini(a0); //?h + if (d1 <= (ATR_SPD(a0) >> 2)) + { //???? + ATR_H_POS(a0) = ATR_INT_WORK0(a0); //? + ATR_V_POS(a0) = ATR_INT_WORK1(a0); + ATR_VCT_NO(a0) = VCT_NO_DIE + 1; //????? + } + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + if (s_timer & 1) + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case VCT_NO_DIE + 1: //? + ATR_CHR_ACT(a0) = ANIM_DEAD; //???????? + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //?????? +#ifdef __NEW_BATTLE_EFFECT + int effect = ATR_EFFECT_FLAG(a0); + int effect_anim = ATR_EFFECT_ANIM(a0); + + switch (effect) + { + case 1: // + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + if (a1 == NULL) + { + ATR_EFFECT_FLAG(a0) = 0; + ATR_EFFECT_ANIM(a0) = 0; + ATR_EFFECT_PARAM(a0) = 0; + return; + } + //???????Ҥ + ATR_DISP_PRIO(a1) = D_PRIO_HIT_MARK; + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = VCT_NO_EFFECT; + ATR_CHR_NO(a1) = effect_anim; //?????? + /* ???t */ + LoadBmp(ATR_PAT_NO(a0)); + //??????? +#ifndef __CARYTEST + ATR_INT_WORK0(a1) = a0->anim_y + SpriteInfo[ATR_PAT_NO(a0)].height / 2; +#else + ATR_INT_WORK0(a1) = a0->anim_y + g_lpRealAdrn[ATR_PAT_NO(a0)].height / 2; +#endif + //??????????? + ATR_BODY_WORK(0, a1) = a0; + ATR_V_POS(a1) = ATR_V_POS(a0) + ATR_INT_WORK0(a1); + ATR_H_POS(a1) = ATR_H_POS(a0); + break; + } +#endif + ATR_VCT_NO(a0) = VCT_NO_DIE + 2; //?? + //???? + set_piyo_loop(a0); + //????? + play_se(6, ATR_H_POS(a0), 240); + } + break; + case VCT_NO_DIE + 2: //? + break; +#ifdef __NEW_BATTLE_EFFECT + // case VCT_NO_PAUSE: + // break; + case VCT_NO_EFFECT: + { + a1 = ATR_BODY_WORK(0, a0); + int effect = ATR_EFFECT_FLAG(a1); + + switch (effect) + { + case 1: // + ATR_V_POS(a0) = ATR_V_POS(a1) + ATR_INT_WORK0(a0); + if (pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { //?????? + //??k + ATR_LIFE(a1) = ATR_EFFECT_PARAM(a1); + if (ATR_LIFE(a1) > ATR_MAX_LIFE(a1)) //???? + ATR_LIFE(a1) = ATR_MAX_LIFE(a1); //???? + ATR_VCT_NO(a1) = 0; //_? + ATR_CHR_ACT(a1) = ANIM_STAND; //_??????? + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + ATR_EFFECT_FLAG(a1) = 0; + ATR_EFFECT_ANIM(a1) = 0; + ATR_EFFECT_PARAM(a1) = 0; + DeathAction(a0); //? + ATR_DAMAGE(p_master)++; + } + return; + default: + ATR_EFFECT_FLAG(a1) = 0; + ATR_EFFECT_ANIM(a1) = 0; + ATR_EFFECT_PARAM(a1) = 0; + DeathAction(a0); //? + ATR_DAMAGE(p_master)++; + break; + } + } + break; +#endif +#ifdef __ATTACK_MAGIC + // ǰö + case ATTACK_MAGIC_CASE: + // Ƿ· + (0 == ATR_GROUP_FLG(a0)) ? ATR_CHR_ANG(a0) = 3 : ATR_CHR_ANG(a0) = 7; + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + if (0XFFFFFFFF != AttMgc.iPreMgcNum) + { + if (NULL == (a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)))) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + ATR_VCT_NO(a0) = 0; + return; + } + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 1; // ǰö +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (AttMgc.iPreMgcNum == 101120) + ATR_DISP_PRIO(a1) = (1 == AttMgc.wPreMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + else + ATR_DISP_PRIO(a1) = ATR_DISP_PRIO(a0) + 1; +#else + ATR_DISP_PRIO(a1) = (1 == AttMgc.wPreMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; +#endif + ATR_CHR_NO(a1) = AttMgc.iPreMgcNum; + ATR_BODY_WORK(0, a1) = a0; + ATR_H_POS(a1) = ATR_H_POS(a0) + AttMgc.wPreMgcX; + ATR_V_POS(a1) = ATR_V_POS(a0) + AttMgc.wPreMgcY; + } + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + // ִǰö + case ATTACK_MAGIC_CASE + 1: + a1 = ATR_BODY_WORK(0, a0); + ATR_H_POS(a0) = ATR_H_POS(a1) + AttMgc.wPreMgcX; + ATR_V_POS(a0) = ATR_V_POS(a1) + AttMgc.wPreMgcY; + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + AttMgc.wRunPreMgc = TRUE; + //ToCallMgc.wRunPreMgc = TRUE; + } + break; + // ִĿǰ + case ATTACK_MAGIC_CASE + 2: + { + idx = ATR_LONG_WORK(0, a0); + + // ŵλ + if (20 != idx) + { + a1 = p_party[idx]; + ATR_H_POS(a0) = ATR_H_POS(a1) + AttMgc.posAttacked[0].x; + ATR_V_POS(a0) = ATR_V_POS(a1) + AttMgc.posAttacked[0].y; + } + // ž + else + { + int value = 0; + + // Ŀǰڵ + if (2 == g_iRunEarthQuake) + value = piyo_tbl[(piyo_point + g_iCurRunEarthQuake) & 63] + 12; + + ATR_V_POS(a0) = AttMgc.posAttacked[0].y + value; + } + + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + // ûкö + if (0XFFFFFFFF == AttMgc.iPostMgcNum) + { + AttMgc.wNumAttackeds++; + if (20 == idx) + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0, j, charahurt, pethurt; + + while (++i && 0XFF != AttMgc.wAttackedIndex[i]) + { + for (j = 0; j < iAttackedNum; j++) + { + if (AttMgc.wAttackedIndex[i] == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + if (charahurt == 0) + { + set_damage_num(a1, 0, -64); + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 5; + } + else + { + set_damage_num(a1, 6, -64); + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 4; + } + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (charahurt == 0) + ATR_CHR_ACT(a1) = ANIM_STAND; + else + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + else + { + int j, charahurt, pethurt; + + for (j = 0; j < iAttackedNum; j++) + { + if (idx == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + if (charahurt == 0) + { + set_damage_num(a1, 0, -64); + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 5; + } + else + { + set_damage_num(a1, 6, -64); + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 4; + } + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (charahurt == 0) + ATR_CHR_ACT(a1) = ANIM_STAND; + else + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + // ӵкö + else + { + // еĵʩö + if (20 == idx) // idx = wAttackedIndex[0] + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0; + + while (++i && 0XFF != AttMgc.wAttackedIndex[i]) + { + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 3; // ö + ATR_DISP_PRIO(a1) = (1 == AttMgc.wPostMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a1) = AttMgc.iPostMgcNum; + ATR_LONG_WORK(0, a1) = AttMgc.wAttackedIndex[i]; + ATR_H_POS(a1) = ATR_H_POS(p_party[AttMgc.wAttackedIndex[i]]) + AttMgc.wPostMgcX; + ATR_V_POS(a1) = ATR_V_POS(p_party[AttMgc.wAttackedIndex[i]]) + AttMgc.wPostMgcY; + } + } + // ijһʩö + else + { + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 3; // ö + ATR_DISP_PRIO(a1) = (1 == AttMgc.wPostMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a1) = AttMgc.iPostMgcNum; + ATR_LONG_WORK(0, a1) = idx; + ATR_H_POS(a1) = ATR_H_POS(p_party[idx]) + AttMgc.wPostMgcX; + ATR_V_POS(a1) = ATR_V_POS(p_party[idx]) + AttMgc.wPostMgcY; + } + } + } + + // еĶ + if (AttMgc.wNumAttackeds == AttMgc.wNumAttacks && 0 == iAttackedNum) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunAttMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + } + // ִкö + case ATTACK_MAGIC_CASE + 3: + idx = ATR_LONG_WORK(0, a0); + a1 = p_party[idx]; + ATR_H_POS(a0) = ATR_H_POS(a1) + AttMgc.wPostMgcX; + ATR_V_POS(a0) = ATR_V_POS(a1) + AttMgc.wPostMgcY; + + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + AttMgc.wNumAttackeds++; + if (20 == idx) + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0, j, charahurt, pethurt; + + while (++i && 0XFF != AttMgc.wAttackedIndex[i]) + { + for (j = 0; j < iAttackedNum; j++) + { + if (AttMgc.wAttackedIndex[i] == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + set_damage_num(a1, 6, -64); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + else + { + int j, charahurt, pethurt; + + for (j = 0; j < iAttackedNum; j++) + { + if (idx == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + + ATR_VCT_NO(a1) = ATTACK_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + + ATR_PET_DAMAGE(a1) = pethurt; + set_damage_num(a1, 6, -64); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + // еĶ + if (AttMgc.wNumAttackeds == AttMgc.wNumAttacks && 0 == iAttackedNum) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunAttMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + // ˵ͼ + case ATTACK_MAGIC_CASE + 4: + if (ATR_FIRST_FLG(a0) > 40) + ATR_FIRST_FLG(a0) = 0; + ATR_FIRST_FLG(a0)++; + ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31; + gemini(a0); + if (40 == ATR_FIRST_FLG(a0)) + { + if (ATR_LIFE(a0) <= 0) + { + ATR_VCT_NO(a0) = VCT_NO_DIE + 1; + slow_flg--; + } + else + ATR_VCT_NO(a0) = 0; + + if (ATR_GROUP_FLG(a0) == 1) + ATR_CRS(a0) = crs_change_tbl2[7]; + else + ATR_CRS(a0) = crs_change_tbl2[3]; + gemini(a0); + ++iCurAttackedFinishNum; + } + // еĶ + if (iAttackedNum == iCurAttackedFinishNum) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunAttMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + case ATTACK_MAGIC_CASE + 5: + if (ATR_FIRST_FLG(a0) > 60) + ATR_FIRST_FLG(a0) = 0; + ATR_FIRST_FLG(a0)++; + if (ATR_FIRST_FLG(a0) == 60) + { + ATR_VCT_NO(a0) = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunAttMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; +#endif +#ifdef __TOCALL_MAGIC + // ǰö + case TOCALL_MAGIC_CASE: + // Ƿ· + (0 == ATR_GROUP_FLG(a0)) ? ATR_CHR_ANG(a0) = 3 : ATR_CHR_ANG(a0) = 7; + + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + + if (0XFFFFFFFF != ToCallMgc.iPreMgcNum) + { + if (NULL == (a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)))) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + ATR_VCT_NO(a0) = 0; + return; + } + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 1; // ǰö +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (ToCallMgc.iPreMgcNum == 101120) + ATR_DISP_PRIO(a1) = (1 == ToCallMgc.wPreMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + else + ATR_DISP_PRIO(a1) = ATR_DISP_PRIO(a0) + 1; +#else + ATR_DISP_PRIO(a1) = (1 == ToCallMgc.wPreMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; +#endif + ATR_CHR_NO(a1) = ToCallMgc.iPreMgcNum; + ATR_BODY_WORK(0, a1) = a0; + ATR_H_POS(a1) = ATR_H_POS(a0) + ToCallMgc.wPreMgcX; + ATR_V_POS(a1) = ATR_V_POS(a0) + ToCallMgc.wPreMgcY; + } + ATR_VCT_NO(a0) = 0; + ATR_CHR_ACT_OLD(a0) = -1; +#ifdef _PETSKILL_LER // ׶ + if (ATR_CHR_NO(a0) == 101815) + ATR_CHR_NO(a0) = ATR_CHR_NO(a0) * -1; +#endif + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + // ִǰö + case TOCALL_MAGIC_CASE + 1: + + a1 = ATR_BODY_WORK(0, a0); + ATR_H_POS(a0) = ATR_H_POS(a1) + ToCallMgc.wPreMgcX; + ATR_V_POS(a0) = ATR_V_POS(a1) + ToCallMgc.wPreMgcY; + + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + ToCallMgc.wRunPreMgc = TRUE; +#ifdef _PETSKILL_LER // ׶ + if (ATR_CHR_NO_OLD(a1) < 0) + { + int side; + + ATR_CHR_NO(a1) = ATR_CHR_NO(a1) * -1; + if (ToCallMgc.iCurMgcNum == 101798 || ToCallMgc.iCurMgcNum == 101800 || ToCallMgc.iCurMgcNum == 101853 || ToCallMgc.iCurMgcNum == 101854) + { + int i; + for (i = 0; i < BATTLKPKPLYAERNUM; i++) + { + // ҵ׶λ + if (ATR_CHR_NO(p_party[i]) == ATR_CHR_NO(a1)) + break; + } + side = i = (i < 10 ? 0:10); + // ׶ȫʧ + for (; i < side + 10; i++) + ATR_H_POS(p_party[i]) += -lpDraw->xSize; + } + } +#endif + } + break; + // ִĿǰ + case TOCALL_MAGIC_CASE + 2: + { + idx = ATR_LONG_WORK(0, a0); +#ifdef _PROFESSION_ADDSKILL + RunTimeMagicBoundary(ATR_CHR_NO(a0)); +#endif + // ŵλ + if (20 != idx) + { + a1 = p_party[idx]; + if (idx < 10) + { + ATR_H_POS(a0) = ATR_H_POS(a1) - ToCallMgc.posAttacked[0].x; + ATR_V_POS(a0) = ATR_V_POS(a1) - ToCallMgc.posAttacked[0].y; + } + else + { + ATR_H_POS(a0) = ATR_H_POS(a1) + ToCallMgc.posAttacked[0].x; + ATR_V_POS(a0) = ATR_V_POS(a1) + ToCallMgc.posAttacked[0].y; + } + } + // ž + else + { + int value = 0; + + // Ŀǰڵ + if (2 == g_iRunEarthQuake) + value = piyo_tbl[(piyo_point + g_iCurRunEarthQuake) & 63] + 12; + ATR_V_POS(a0) = ToCallMgc.posAttacked[0].y + value; + } + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { +#ifdef _PETSKILL_LER // ׶ + int side; + + if (ATR_CHR_NO(a0) == 101798 || ATR_CHR_NO(a0) == 101800 || ATR_CHR_NO(a0) == 101853 || ATR_CHR_NO(a0) == 101854) + { + int i; + for (i = 0; i < BATTLKPKPLYAERNUM; i++) + { + // ҵ׶λ + if (ATR_CHR_NO(p_party[i]) == 101815) + break; + } + side = i = (i < 10 ? 0:10); + // ׶˳ + for (; i < side + 10; i++) + ATR_H_POS(p_party[i]) += lpDraw->xSize; + } +#endif + // Terry add fix ׶ + if (ToCallMgc.wCurAttackNum == 101628) + DeathAction(a0); + else + // end + if (ToCallMgc.wIsPostDisappear) + { + a0tmp[a0tmpcount] = a0; + a0mark[a0tmpcount] = 1; + a0tmpcount++; + } + else + { + DeathAction(a0); +#ifdef _PROFESSION_ADDSKILL + if (boundary_2) + { + DeathAction(boundary_2); + boundary_2 = NULL; + } +#endif + } + // ûкö + if (0XFFFFFFFF == ToCallMgc.iPostMgcNum) + { + ToCallMgc.wNumAttackeds++; + if (20 == idx) + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0, j, charahurt, pethurt; + + while (++i && 0XFF != ToCallMgc.wAttackedIndex[i]) + { + for (j = 0; j < iAttackedNum; j++) + { + if (ToCallMgc.wAttackedIndex[i] == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + if (charahurt == 0)//˺ֵΪ0 + { +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if (a0->anim_chr_no == 101651 || a0->anim_chr_no == 101650) //һMiss + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; + else + { + set_damage_num(a1, 0, -64); + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; + if ( ToCallMgc.iCurMgcNum == 101676 //ᴩ˺Ϊ0,ҪܵĶ + || ToCallMgc.iCurMgcNum == 101675 + || ToCallMgc.iCurMgcNum == 101674 + || ToCallMgc.iCurMgcNum == 101673 + || ToCallMgc.iCurMgcNum == 101672 + || ToCallMgc.iCurMgcNum == 101665 + || ToCallMgc.iCurMgcNum == 101664 + || ToCallMgc.iCurMgcNum == 101663 + || ToCallMgc.iCurMgcNum == 101662 + || ToCallMgc.iCurMgcNum == 101661 + || ToCallMgc.iCurMgcNum == 101656) + { // + ATR_STIMER(a1) = 0; + ATR_FIRST_FLG(a1) = 0; //????????? + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 6; + } + } +#else + set_damage_num(a1, 0, -64); + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; +#endif + } + else + { + set_damage_num(a1, 6, -64); + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 4; + } + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (charahurt == 0) + ATR_CHR_ACT(a1) = ANIM_STAND; + else + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + else + { + int j, charahurt, pethurt; + + for (j = 0; j < iAttackedNum; j++) + { + if (idx == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + if (charahurt == 0) + { + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + // if ( a0->anim_chr_no == 101651 || a0->anim_chr_no == 101650 ) //һMiss + // ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; + // else { + // set_damage_num( a1 , 0 , -64 ); + // ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; + // } + //#else + set_damage_num(a1, 0, -64); + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 5; + //#endif + } + else + { + set_damage_num(a1, 6, -64); + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 4; + } + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (charahurt == 0) + ATR_CHR_ACT(a1) = ANIM_STAND; + else + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + // ӵкö + else + { + // еĵʩö + if (20 == idx) // idx = wAttackedIndex[0] + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0; + + while (++i && 0XFF != ToCallMgc.wAttackedIndex[i]) + { + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 3; // ö + ATR_DISP_PRIO(a1) = (1 == ToCallMgc.wPostMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a1) = ToCallMgc.iPostMgcNum; + ATR_LONG_WORK(0, a1) = ToCallMgc.wAttackedIndex[i]; + ATR_H_POS(a1) = ATR_H_POS(p_party[ToCallMgc.wAttackedIndex[i]]) + ToCallMgc.wPostMgcX; + ATR_V_POS(a1) = ATR_V_POS(p_party[ToCallMgc.wAttackedIndex[i]]) + ToCallMgc.wPostMgcY; + } + } + // ijһʩö + else + { + a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)); + + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 3; // ö + ATR_DISP_PRIO(a1) = (1 == ToCallMgc.wPostMgcOnChar) ? D_PRIO_HIT_MARK : DISP_PRIO_TILE + 1; + ATR_CHR_NO(a1) = ToCallMgc.iPostMgcNum; + ATR_LONG_WORK(0, a1) = idx; + ATR_H_POS(a1) = ATR_H_POS(p_party[idx]) + ToCallMgc.wPostMgcX; + ATR_V_POS(a1) = ATR_V_POS(p_party[idx]) + ToCallMgc.wPostMgcY; + } + } + } + + // еĶ + if (ToCallMgc.wNumAttackeds == ToCallMgc.wNumAttacks && 0 == iAttackedNum) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunToCallMgc = FALSE; + g_iRunEarthQuake = 0; + } + + break; + } + // ִкö + case TOCALL_MAGIC_CASE + 3: + + idx = ATR_LONG_WORK(0, a0); + a1 = p_party[idx]; + ATR_H_POS(a0) = ATR_H_POS(a1) + ToCallMgc.wPostMgcX; + ATR_V_POS(a0) = ATR_V_POS(a1) + ToCallMgc.wPostMgcY; + + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + ToCallMgc.wNumAttackeds++; + + if (20 == idx) + { + // wAttackedIndex[0] 20 -- ȫ幥 + // wAttackedIndex[n] 0XFF -- + int i = 0, j, charahurt, pethurt; + + while (++i && 0XFF != ToCallMgc.wAttackedIndex[i]) + { + for (j = 0; j < iAttackedNum; j++) + { + if (ToCallMgc.wAttackedIndex[i] == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + + + ATR_PET_DAMAGE(a1) = pethurt; + + set_damage_num(a1, 6, -64); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + + + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) { + if (ATR_LIFE(a1) > 0) { + petfallChangeGraph(a1); + } + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)){ + ATR_PET_LIFE(a1) = 0; + + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + } + else + { + int j, charahurt, pethurt; + + for (j = 0; j < iAttackedNum; j++) + { + if (idx == AttackedInfo[j * 4]) + { + a1 = p_party[AttackedInfo[j * 4 + 1]]; + charahurt = AttackedInfo[j * 4 + 2]; + pethurt = AttackedInfo[j * 4 + 3]; + ATR_VCT_NO(a1) = TOCALL_MAGIC_CASE + 4; + ATR_LONG_WORK(0, a1) = 0; + ATR_DAMAGE(a1) = charahurt; + ATR_PET_DAMAGE(a1) = pethurt; + set_damage_num(a1, 6, -64); + ATR_LIFE(a1) -= ATR_DAMAGE(a1); + set_jujutsu_hit_mark(a1); + if (ATR_LIFE(a1) <= 0) + { + ATR_LIFE(a1) = 0; + slow_flg++; + } + ATR_PET_LIFE(a1) -= ATR_PET_DAMAGE(a1); + //andy_fall + if (ATR_PETFALL(a1) == 1) + { + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + if (ATR_PET_LIFE(a1) <= 0 && ATR_RIDE(a1)) + { + ATR_PET_LIFE(a1) = 0; + if (ATR_LIFE(a1) > 0) + petfallChangeGraph(a1); + } + ATR_CHR_ACT(a1) = ANIM_DAMAGE; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + + } + + // еĶ + if (ToCallMgc.wNumAttackeds == ToCallMgc.wNumAttacks && 0 == iAttackedNum) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunToCallMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + // ˵ͼ + case TOCALL_MAGIC_CASE + 4: + if (ATR_FIRST_FLG(a0) > 40) + ATR_FIRST_FLG(a0) = 0; + ATR_FIRST_FLG(a0)++; + if (ATR_LIFE(a0) <= 0) + { + ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31; + gemini(a0); + } + if (40 == ATR_FIRST_FLG(a0)) // 40 + { + if (ATR_LIFE(a0) <= 0) + { + ATR_VCT_NO(a0) = VCT_NO_DIE + 1; + slow_flg--; + } + else + ATR_VCT_NO(a0) = 0; + + if (ATR_GROUP_FLG(a0) == 1) + ATR_CRS(a0) = crs_change_tbl2[7]; + else + ATR_CRS(a0) = crs_change_tbl2[3]; + gemini(a0); + ++iCurAttackedFinishNum; + } + // еĶ + if (iAttackedNum == iCurAttackedFinishNum) + { + for (int i = 0; i < 10; i++) + { + if (a0mark[i] != 0) + { + DeathAction(a0tmp[i]); + a0mark[i] = 0; + } + } + a0tmpcount = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunToCallMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + case TOCALL_MAGIC_CASE + 5: + if (ATR_FIRST_FLG(a0) > 60) + ATR_FIRST_FLG(a0) = 0; + ATR_FIRST_FLG(a0)++; + if (ATR_FIRST_FLG(a0) == 60) + { + if (ToCallMgc.wIsPostDisappear) + { + for (int i = 0; i < 10; i++) + { + if (a0mark[i] != 0) + { + DeathAction(a0tmp[i]); + a0mark[i] = 0; + } + } + } + a0tmpcount = 0; + ATR_VCT_NO(a0) = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunToCallMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; + // + case TOCALL_MAGIC_CASE + 6: + ATR_CHR_ACT(a0) = ANIM_WALK; //?h??????? + ATR_SPD(a0) = 16; + ATR_CHR_ANG(a0) = (ATR_DAMAGE_ANG(a0) + 4) & 7; + if (ATR_GROUP_FLG(a0) == 1) + ATR_CRS(a0) = crs_change_tbl2[3]; + else + ATR_CRS(a0) = crs_change_tbl2[7]; + gemini(a0); + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + ATR_STIMER(a0)++; + if (ATR_STIMER(a0) == 20) + { + ATR_CRS_OLD(a0) = ATR_CRS(a0) = (ATR_CRS(a0) + 16) & 31;//?? + ATR_VCT_NO(a0) = 17; //????? + ATR_STIMER(a0) = 0; + ++iCurAttackedFinishNum; + } + // еĶ + if (iAttackedNum == iCurAttackedFinishNum) + { + for (int i = 0; i < 10; i++) + { + if (a0mark[i] != 0) + { + DeathAction(a0tmp[i]); + a0mark[i] = 0; + } + } + a0tmpcount = 0; + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + bRunToCallMgc = FALSE; + g_iRunEarthQuake = 0; + } + break; +#endif + //#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + case PROSKILL: + // Ƿ· + (0 == ATR_GROUP_FLG(a0)) ? ATR_CHR_ANG(a0) = 3 : ATR_CHR_ANG(a0) = 7; + + ATR_CRS_OLD(a0) = ATR_CRS(a0) = crs_change_tbl2[ATR_CHR_ANG(a0)]; + + if (0XFFFFFFFF != AttMgc.iPreMgcNum) + { + if (NULL == (a1 = GetAction(T_PRIO_MISSILE, sizeof(ATR_EQU)))) + { + ATR_DAMAGE(p_master) = ATR_BODY_CNT(p_master); + ATR_VCT_NO(a0) = 0; + return; + } + if (AttPreMagicNum == 0) + { + ATR_VCT_NO(a0) = 1; + return; + } + ATR_NAME(a1) = monster; + ATR_VCT_NO(a1) = PROSKILL + 1; // ǰö + ATR_CHR_NO(a1) = AttPreMagicNum; + ATR_DISP_PRIO(a1) = ATR_DISP_PRIO(a0) + 1; + ATR_BODY_WORK(0, a1) = a0; + ATR_H_POS(a1) = ATR_H_POS(a0); + ATR_V_POS(a1) = ATR_V_POS(a0); + } + if (ATR_WARRIOR_EFFECT(a0) == 1) + ATR_VCT_NO(a0) = 0; + else if (ATR_WARRIOR_EFFECT(a0) == 2) + ATR_VCT_NO(a0) = 1; + ATR_CHR_ACT_OLD(a0) = -1; + pattern(a0, ANM_NOMAL_SPD, ANM_LOOP); + break; + case PROSKILL + 1: + a1 = ATR_BODY_WORK(0, a0); + ATR_H_POS(a0) = ATR_H_POS(a1); + ATR_V_POS(a0) = ATR_V_POS(a1) - 35; + if (ATR_CHR_NO(a0) == 101631 || ATR_CHR_NO(a0) == 101632) + ATR_V_POS(a0) = ATR_V_POS(a1) - 65; + if (d0 = pattern(a0, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(a0); + if (ATR_WARRIOR_EFFECT(a1) == 1) + ATR_VCT_NO(a1) = 1; + } + break; + //#endif + } +#ifdef _SYUTEST + if (Light1 != NULL) + { + if (Light1->anim_cnt == 5) + { //ŵһ + DeathAction(Light1); + Light1 = NULL; + } + } +#endif +} + +ACTION *oft_test(void) +{ + int d0, d1, d2, d7; + int id_no = 0; + ACTION *a1; + + p_kanji = NULL; + for (d7 = 0; d7 < BATTLKPKPLYAERNUM + 1; d7++) // + p_missile[d7] = NULL; + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) // + p_party[d7] = NULL; + + // master action list /* ?????????????K? */ + a1 = GetAction(T_PRIO_MASTER, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + //ҪִеFunc + ATR_NAME(a1) = master; + //ȸȴ + ATR_VCT_NO(a1) = 3; + //ʾ˳ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // sprite /* ?????k? */ + ATR_CHR_NO(a1) = 31027; + ATR_CHR_ANG(a1) = 3; // + //λ + ATR_H_POS(a1) = 320; + ATR_V_POS(a1) = 240; + // + ATR_CHR_ACT(a1) = ANIM_ATTACK; // ƶ + // ¼ a1 p_master/* ???????V */ + p_master = a1; + // field µ action list/* ?????N???????????K? */ + a1 = GetAction(T_PRIO_MASTER, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_ATTRIB(a1) = ACT_ATR_HIDE; // ʾ //?? + //ʾ˳ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + //λ + ATR_H_POS(a1) = lpDraw->xSize - 32; + ATR_V_POS(a1) = lpDraw->ySize - 64; + // ¼ a1 p_attrib/* ???????V */ + p_attrib = a1; + +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 + //X + d0 = 416 + 5 + DISPLACEMENT_X; + //Y + d1 = 408 + 24 + DISPLACEMENT_Y; +#else + //X + d0 = 416 + 32 + 5 + DISPLACEMENT_X; + //Y + d1 = 408 + 24 + DISPLACEMENT_Y; +#endif + // ԤΪͼΪ SPR_021em + d2 = SPR_021em; /*?????*/ + + //_BATTLE_PK_PLAYER_FOR_6VS6 XIEZI ޸ + for (d7 = 0; d7 < MAX_BATTLE_ROW_CHARS; d7++) + { //ҷ + // ҷ monster action list /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + //ҪִеFunc /* ??? */ + ATR_NAME(a1) = NULL; + // Ϊdz + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ʾѶϢ // ?????????? + a1->atr |= ACT_ATR_INFO; + // Աѡ // ???Re?? + a1->atr |= ACT_ATR_HIT; + // sprite /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 3; // + ATR_HIT_TIMING(a1) = 5; + // λ /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) += 300; + ATR_V_POS(a1) += 300; + // һʼڻλ + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //ƶٶ + ATR_GROUP_FLG(a1) = 0; // group set //????????? + ATR_PLACE_NO(a1) = d7; // ¼ʼλ //?k?V + // ¼ a1 б/* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 += 32; + d1 -= 24; + } + +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 + //X + d0 = 320 - 64 + 5 + DISPLACEMENT_X; + //Y + d1 = 432 - 24 + DISPLACEMENT_Y; +#else + d0 = 320 - 32 + 5 + DISPLACEMENT_X; //?? + d1 = 432 - 24 + DISPLACEMENT_Y; //?? +#endif + d2 = SPR_pet001; /*???*/ + + //_BATTLE_PK_PLAYER_FOR_6VS6 XIEZI ޸ + for (; d7 < 2 * MAX_BATTLE_ROW_CHARS; d7++) + { //ҷ + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 3; //? + ATR_HIT_TIMING(a1) = 3 + 2; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) += 300; + ATR_V_POS(a1) += 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 0; //????????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 += 32 * 2; + d1 -= 24 * 2; + } + /* ???? */ + p_party[d7] = NULL; +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 + //X + d0 = 64 - 32 + 5; + //Y + d1 = 192 + 30; +#else + d0 = 64 - 32 + 5; //?? + d1 = 192 - 24 + 30; //?? +#endif + d2 = SPR_021em; /*?????*/ + + //_BATTLE_PK_PLAYER_FOR_6VS6 XIEZI ޸ + for (; d7 < 3 * MAX_BATTLE_ROW_CHARS; d7++) + { //з + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 7; //?? + ATR_HIT_TIMING(a1) = 5; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) -= 300; + ATR_V_POS(a1) -= 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 1; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 += 32; + d1 -= 24; + } + +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 + //X + d0 = 32 + 32 + 5; + //Y + d1 = 264 + 48 + 10; +#else + d0 = 32 + 32 + 5; //?? + d1 = 264 + 24 + 10; //?? +#endif + d2 = SPR_pet001; /*???*/ + + //_BATTLE_PK_PLAYER_FOR_6VS6 XIEZI ޸ + for (; d7 < 4 * MAX_BATTLE_ROW_CHARS; d7++) + { //з + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 7; //?? + ATR_HIT_TIMING(a1) = 3 + 2; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) -= 300; + ATR_V_POS(a1) -= 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 1; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 += 32 * 2; + d1 -= 24 * 2; + } +#ifdef _BATTLE_PK_PLAYER_FOR_40 + p_party[d7] = NULL; + d0 = 128 + 32 + 5; + d1 = 408 + 24 + DISPLACEMENT_Y; + d2 = SPR_021em; /*?????*/ + for (d7 = 20; d7 < 25; d7++) + { //з + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 5; //?? + ATR_HIT_TIMING(a1) = 5; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) -= 300; + ATR_V_POS(a1) += 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 2; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 -= 32; + d1 -= 24; + } + d0 = 288 + 32 + 5; //?? + d1 = 432 - 24 + DISPLACEMENT_Y; //?? + d2 = SPR_pet001; /*???*/ + for (d7 = 25; d7 < 30; d7++) + { //з + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 5; //?? + ATR_HIT_TIMING(a1) = 3 + 2; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) -= 300; + ATR_V_POS(a1) += 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 2; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 -= 32 * 2; + d1 -= 24 * 2; + } + + //X + d0 = 608 - 32 + 5 + DISPLACEMENT_X; + //Y + d1 = 190 - 24 + 30; + d2 = SPR_021em; /*?????*/ + for (d7 = 30; d7 < 35; d7++) + { //Ͻǵз + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 1; //?? + ATR_HIT_TIMING(a1) = 5; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) += 300; + ATR_V_POS(a1) -= 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 3; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 -= 32; + d1 -= 24; + } + d0 = 608 - 32 + 5 + DISPLACEMENT_X; //?? + d1 = 236 + 24 + 30; //?? + d2 = SPR_pet001; /*???*/ + for (d7 = 35; d7 < 40; d7++) + { //Ͻǵз + /* ??????????????K? */ + a1 = GetAction(T_PRIO_JIKI, sizeof(ATR_EQU)); + if (a1 == NULL) + return NULL; + ATR_NAME(a1) = NULL; + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + /* ?IT */ + ATR_DISP_PRIO(a1) = D_PRIO_MASTER; + // ?????????? + a1->atr |= ACT_ATR_INFO; + // ???Re?? + a1->atr |= ACT_ATR_HIT; + /* ?????k? */ + ATR_CHR_NO(a1) = d2; + ATR_CHR_ANG(a1) = 1; //?? + ATR_HIT_TIMING(a1) = 3 + 2; + /* ???t */ + monster_place_pos[id_no] = ATR_H_POS(a1) = ATR_INT_WORK0(a1) = d0; + monster_place_pos[id_no + 1] = ATR_V_POS(a1) = ATR_INT_WORK1(a1) = d1; + ATR_H_POS(a1) += 300; + ATR_V_POS(a1) -= 300; + monster_start_pos[id_no++] = ATR_H_POS(a1); + monster_start_pos[id_no++] = ATR_V_POS(a1); + /* ???? */ + ATR_CHR_ACT(a1) = ANIM_STAND; //?h??????? + ATR_SPD(a1) = 32; //?hLT + ATR_GROUP_FLG(a1) = 3; //???????? + ATR_PLACE_NO(a1) = d7; //?k?V + /* ???????V */ + p_party[d7] = a1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + /* ?? */ + d0 -= 32 * 2; + d1 -= 24 * 2; + } + +#endif + // λ //???t?t + for (d7 = 0; d7 < BATTLKPKPLYAERNUM; d7++) + { + a1 = p_party[d7]; + ATR_H_POS(a1) = monster_start_pos[monster_place_no[d7] * 2]; + ATR_V_POS(a1) = monster_start_pos[monster_place_no[d7] * 2 + 1]; + ATR_INT_WORK0(a1) = monster_place_pos[monster_place_no[d7] * 2]; + ATR_INT_WORK1(a1) = monster_place_pos[monster_place_no[d7] * 2 + 1]; + } + command_point = 0; // clear command point //????????????? + return a1; +} + +static int bc_pointer; +/* ??????? *******************************************************************/ +int get_bc_num(void) +{ + int d0, d1; + + while (1) + { + d0 = BattleStatus[bc_pointer++]; //???? + if (d0 == NULL) + { //??? + bc_pointer--; + return -1; + } + if (d0 >= '0' && d0 <= '9') //??? + break; //?????? + if (d0 >= 'A' && d0 <= 'F') //????? + break; //?????? + } + if (d0 >= 'A') //????? + d1 = d0 - 'A' + 10; + else + d1 = d0 - '0'; + + while (1) + { + d0 = BattleStatus[bc_pointer++]; //??????? + if (d0 == NULL) + { //??? + bc_pointer--; + break; + } + if (d0 < '0' || d0 > '9') + { //?????? + if (d0 < 'A' || d0 > 'F') //???????? + break; //? + } + d1 = d1 << 4; //??????? + if (d0 >= 'A') //????? + d1 += d0 - 'A' + 10; + else + d1 += d0 - '0'; + } + return d1; +} + +/* ?????? *******************************************************************/ +void get_bc_asc(ACTION *a1, int flg) +{ + char d0; + char *a2; + + if (flg == 0) + a2 = ATR_HANDLE(a1); + else + a2 = ATR_TITLE(a1); + while (1) + { + d0 = BattleStatus[bc_pointer++]; //???? + if (d0 == NULL) + { //??? + bc_pointer--; + break; + } + //???? + if (d0 == '|') + break; + if (IsDBCSLeadByte(d0)) + { + *a2++ = d0; + *a2++ = BattleStatus[bc_pointer++]; + } + else + *a2++ = d0; + } + //???? + *a2 = 0; + if (flg == 0) + makeStringFromEscaped(ATR_HANDLE(a1)); + else + makeStringFromEscaped(ATR_TITLE(a1)); +} + +// Robin 0728 +/* ?????? for Ride Pet*******************************************************************/ +void get_bc_asc_ridepet(ACTION *a1) +{ + char d0; + char *a2; + + a2 = ATR_PETNAME(a1); + while (1) + { + d0 = BattleStatus[bc_pointer++]; //???? + if (d0 == NULL) + { //??? + bc_pointer--; + break; + } + //???? + if (d0 == '|') + break; + if (IsDBCSLeadByte(d0)) + { + *a2++ = d0; + *a2++ = BattleStatus[bc_pointer++]; + } + else + *a2++ = d0; + } + //???? + *a2 = 0; + makeStringFromEscaped(ATR_PETNAME(a1)); +} + +//Ƿ״̬ȷ +//p_partyеֵеijʼ +void set_bc(void) +{ + ACTION *a1; + int d0, d2, d3, d1 = 0; + + //???????? + bc_pointer = 3; + //?????N + ATR_ATTRIB(p_master) = get_bc_num(); + //Pf???????? + while (BattleStatus[bc_pointer] != NULL) + { + //??k???? + d2 = get_bc_num(); +#ifdef _STONDEBUG_ + if (d2 >= BATTLKPKPLYAERNUM) + MessageBoxNew(hWnd, "ʼʧ,趨", "Error", MB_OK); +#endif + //????????????? + a1 = p_party[d2]; + /* ??? */ + ATR_NAME(a1) = monster; + //q??? + get_bc_asc(a1, 0); + //???? + get_bc_asc(a1, 1); + //???k???? + ATR_CHR_NO(a1) = get_bc_num(); + //?????? + ATR_LEVEL(a1) = get_bc_num(); + //????? + ATR_LIFE(a1) = get_bc_num(); + +#ifdef _SFUMATO + ATR_SFUMATO(a1) = 0xff0000; +#endif + + //?????? + ATR_MAX_LIFE(a1) = get_bc_num(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + ATR_MAX_MANA(a1) = pc.maxMp ; +#endif + //?????? + d0 = get_bc_num(); + // Robin 0728 ridePet + if (bNewServer) + { + ATR_RIDE(a1) = get_bc_num(); + get_bc_asc_ridepet(a1); + ATR_PETLEVEL(a1) = get_bc_num(); + ATR_PET_LIFE(a1) = get_bc_num(); + int k = ATR_PET_LIFE(a1); + ATR_PET_MAX_LIFE(a1) = get_bc_num(); + int o = ATR_PET_MAX_LIFE(a1); + } + else + { + ATR_RIDE(a1) = 0; + ATR_PETNAME(a1)[0] = NULL; + ATR_PETLEVEL(a1) = 0; + ATR_PET_LIFE(a1) = 0; + ATR_PET_MAX_LIFE(a1) = 0; + } + //??? + if (d0 & BC_FRESH) + { + //???? + if ((ATR_CHR_NO(a1) >= SPR_mwood1 && ATR_CHR_NO(a1) <= SPR_mstone3) || + (ATR_CHR_NO(a1) == 15323) || (ATR_CHR_NO(a1) == 10812) || (ATR_CHR_NO(a1) == 15527) || + (ATR_CHR_NO(a1) == 15543) || (ATR_CHR_NO(a1) == 15575) || (ATR_CHR_NO(a1) == 15607)) + { + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; //?? + //r?? + ATR_VCT_NO(a1) = 0; + ATR_CHR_ACT(a1) = ANIM_STAND; + ATR_H_POS(a1) = ATR_INT_WORK0(a1) = monster_place_pos[monster_place_no[d2] * 2]; + ATR_V_POS(a1) = ATR_INT_WORK1(a1) = monster_place_pos[monster_place_no[d2] * 2 + 1]; + //??? + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + ATR_CRS_OLD(a1) = ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_CHR_ACT(a1) = ANIM_WALK; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + else + { + //K? + ATR_VCT_NO(a1) = VCT_NO_APPEAR; + ATR_ATTRIB(a1) &= ~ACT_ATR_HIDE; //?? + //K͢r? + ATR_VCT_NO(p_master) = 3; + /* ???? */ + ATR_H_POS(a1) = monster_start_pos[monster_place_no[d2] * 2]; + ATR_V_POS(a1) = monster_start_pos[monster_place_no[d2] * 2 + 1]; + ATR_INT_WORK0(a1) = monster_place_pos[monster_place_no[d2] * 2]; + ATR_INT_WORK1(a1) = monster_place_pos[monster_place_no[d2] * 2 + 1]; + } + //???????????? + set_raster_pos(a1); + //148 149 150 + } + else + { + if (ATR_LIFE(a1) > 0) + { //????? + if (d0 & BC_FADE_OUT) + { // ??s??? + ATR_ATTRIB(a1) |= ACT_ATR_TRAVEL; + //?????? + ATR_ATTACK_KIND(2, a1) = 1; + if (ATR_GROUP_FLG(a1) == 0) + { //???????? + ATR_V_POS(a1) = lpDraw->ySize + 16; + ATR_H_POS(a1) = lpDraw->xSize + SCREEN_OUT; + } + else + { + ATR_V_POS(a1) = -18; + ATR_H_POS(a1) = -SCREEN_OUT; + } + } + else + { + ATR_ATTRIB(a1) &= ~ACT_ATR_TRAVEL; + ATR_H_POS(a1) = ATR_INT_WORK0(a1) = monster_place_pos[monster_place_no[d2] * 2]; + ATR_V_POS(a1) = ATR_INT_WORK1(a1) = monster_place_pos[monster_place_no[d2] * 2 + 1]; + //???????????? + set_raster_pos(a1); + } + //r?? + ATR_VCT_NO(a1) = 0; + ATR_CHR_ACT(a1) = ANIM_STAND; + if (BattleBpFlag & BATTLE_BP_JOIN) + { // ӡP?? + //??? + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + ATR_CRS_OLD(a1) = ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_CHR_ACT(a1) = ANIM_WALK; + ATR_CHR_ACT_OLD(a1) = -1; + pattern(a1, ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + //??? + if (d0 & BC_DEATH) + { + if (ATR_VCT_NO(a1) == VCT_NO_APPEAR) + { //??????? + //???? + ATR_VCT_NO(a1) = VCT_NO_DIE + 2; + ATR_H_POS(a1) = ATR_INT_WORK0(a1) = monster_place_pos[monster_place_no[d2] * 2]; + ATR_V_POS(a1) = ATR_INT_WORK1(a1) = monster_place_pos[monster_place_no[d2] * 2 + 1]; + //???????????? + set_raster_pos(a1); + //???? + ATR_LIFE(a1) = 0; + //???????? + if (ATR_GROUP_FLG(a1) == 0) + ATR_CHR_ANG(a1) = 3; + else if (ATR_GROUP_FLG(a1) == 1) + ATR_CHR_ANG(a1) = 7; +#ifdef _BATTLE_PK_PLAYER_FOR_40 + else if (ATR_GROUP_FLG(a1) == 2) + ATR_CHR_ANG(a1) = 5; + else if (ATR_GROUP_FLG(a1) == 3) + ATR_CHR_ANG(a1) = 1; +#endif + ATR_CRS_OLD(a1) = ATR_CRS(a1) = crs_change_tbl2[ATR_CHR_ANG(a1)]; + ATR_CHR_ACT(a1) = ANIM_DEAD; //???????? + ATR_CHR_ACT_OLD(a1) = -1; + while (1) + { + if (pattern(a1, 1, ANM_NO_LOOP)) //?????? + break; + } + //???? + LoadBmp(ATR_PAT_NO(a1)); +#ifndef _PETSKILL_ANTINTER + set_piyo_loop(a1); +#endif + //?r?` + ATR_VCT_NO(p_master) = 3; + } + } + //????V?ϣ?? + if (d0 & BC_PET_OK) + ATR_PET_OK(a1) = 1; + //?????????????? + if (ATR_JUJUTSU_WORK(a1) == NULL) + { + d3 = 0; + if (d0 & BC_BIT3) // ""?? + d3 = 1; + else if (d0 & BC_BIT4) // "??"?? + d3 = 2; + else if (d0 & BC_BIT5) // "?"?? + d3 = 3; + else if (d0 & BC_BIT6) // "?"?? + d3 = 4; + else if (d0 & BC_BIT7) // "???"?? + d3 = 5; + else if (d0 & BC_BIT8) // "??"?? + d3 = 6; +#ifdef _MAGIC_WEAKEN + if (d0 & BC_WEAKEN) // + d3 = 7; +#endif +#ifdef _MAGIC_DEEPPOISION + if (d0 & BC_DEEPPOISON) //綾 + d3 = 8; +#endif +#ifdef _MAGIC_BARRIER + if (d0 & BC_BARRIER) //ħ + d3 = 9; +#endif +#ifdef _MAGIC_NOCAST + if (d0 & BC_NOCAST) //Ĭ + d3 = 10; +#endif +#ifdef _SARS // WON ADD ɷ + if (d0 & BC_SARS) // ɷ + d3 = 11; +#endif +#ifdef _CHAR_PROFESSION // WON ADD ѣ + if (d0 & BC_DIZZY) // ѣ + d3 = 12; + if (d0 & BC_ENTWINE) // + d3 = 13; + if (d0 & BC_DRAGNET) // ޵ + d3 = 14; + if (d0 & BC_ICECRACK) // + d3 = 15; + if (d0 & BC_OBLIVION) // + d3 = 16; + if (d0 & BC_ICEARROW) // + d3 = 17; + if (d0 & BC_BLOODWORMS)// Ѫ + d3 = 18; + if (d0 & BC_SIGN) // һѪ + d3 = 19; + if (d0 & BC_CRAZY) // + d3 = 20; + if (d0 & BC_F_ENCLOSE) // + d3 = 21; + if (d0 & BC_I_ENCLOSE) // + d3 = 22; + if (d0 & BC_T_ENCLOSE) // ׸ + d3 = 23; +#ifdef _PROFESSION_ADDSKILL + if (d0 & BC_WATER) + d3 = 32; // ˮ + if (d0 & BC_WATER) + d3 = 33; // ־ + //if (d0 & BC_F_I_T_ENCLOSE) // ׸ + // d3 = 24; +#endif +#ifdef _PETSKILL_LER + if (d0 & BC_CHANGE) + d3 = 34; // ׶ +#endif +#ifdef _PRO_KILLME + if (d0 & BC_ANGER) + d3 = 35; // ŭ +#endif + +#endif +#ifdef _PETSKILL_LER + if (d0 & BC_CHANGE) + d3 = 34; // ׶ +#endif + if (d3) + { //?????? + set_single_jujutsu(d3, a1); //Ol??? + ATR_STATUS(a1) = d3; //???????? + } + else + ATR_STATUS(a1) = 0; //????? + } + //NͧT???????? + if (ATR_ATTRIB_WORK(a1) == NULL) + { + if (d0 & BC_REVERSE) //T?? + set_attrib_reverse(a1); //NͧT??? + } + } + //K͢r?????? + if (ATR_VCT_NO(p_master) != 3) + action_inf = 3; //K?? +} + +// ???????? ????? ?************************************/ +void disp_shild(void) +{ + char box[] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, + 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + DDSURFACEDESC ddsd; // ??????Bl + char d6, d7; + char *psource; // ?I????? + + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + + // ?????????????????( i?? ddsd ?ѩ?V????? ) + if (lpDraw->lpBACKBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) + { + //MessageBoxNew( hWnd, "Surfacelockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } + + psource = box; // ??????? + _asm{ + // push eax + // push ebx + // push ecx + // push edx + // push esi + // push edi + + mov edx, [ddsd.lpSurface] //Id???? + add edx, 640 - 24 // + + mov ebx, [ddsd.lPitch] //????????? + sub ebx, 16 + + mov al, 10 - 9 //???????? + mov[d6], al // + + disp_shild_100 : + mov al, 30 //???????? + mov[d7], al // + mov edi, edx //????? + + disp_shild_200 : + mov cl, 16 //????????? + // mov esi,edx + mov esi, [psource] + + disp_shild_300 : + mov ch, 16 //????????? + + loop_x : + mov al, [esi] + or al, al + je skip + + mov[edi], al + + skip : + inc esi + inc edi + dec ch + jne loop_x + + add edi, ebx + dec cl + jne disp_shild_300 + + dec[d7] + jne disp_shild_200 + + add edx, 16 // + dec[d6] + jne disp_shild_100 + + // pop edi + // pop esi + // pop edx + // pop ecx + // pop ebx + // pop eax + } + + // ??????????????????? + if (lpDraw->lpBACKBUFFER->Unlock(NULL) != DD_OK) + { + extern int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); + MessageBoxNew(hWnd, "SurfaceUnlockʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return; + } + + return; +} + +void petfallChangeGraph(ACTION *a0) +{ + //andy_fall + if (ATR_PETFALL(a0) != 1) + return; + if (ATR_RIDE(a0) != 1) + return; + +#ifdef _PETSKILL_RIDE + a0->saveride = ATR_CHR_NO(a0); +#endif + + for (int j = 0; j < sizeof(ridePetTable) / sizeof(tagRidePetTable); j++) + { + if (ridePetTable[j].rideNo == ATR_CHR_NO(a0)) + { + ATR_CHR_NO(a0) = ridePetTable[j].charNo; + break; + } + } + ATR_PETFALL(a0) = 2; + //andy_fall + ATR_RIDE(a0) = 0; +} + +#ifdef _PETSKILL_RIDE +void petrideChangeGraph(ACTION *a0,int ridebmp) +{ + //andy_fall + //if (ATR_PETFALL(a0) != 2) + // return; + //if (ATR_RIDE(a0) != 0) + // return; + + //if( a0->saveride == -1 ) + // return; + + ATR_CHR_NO(a0) = ridebmp; + + ATR_PETFALL(a0) = 0; + //andy_fall + ATR_RIDE(a0) = 1; + ATR_RIDE_FLAG(a0) = 1; +} +#endif + +void LogToBattleError(char *data, int line) +{ +#ifdef _STONDEBUG_ + FILE *rfp; + rfp = fopen("battleerror.txt", "a+"); + if (rfp) + { + fprintf(rfp, "%d: %s\n", line, data); + fclose(rfp); + } +#endif +} diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/pat_dat.cpp b/石器时代8.5客户端最新源代码/石器源码/oft/pat_dat.cpp new file mode 100644 index 0000000..a99b936 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/pat_dat.cpp @@ -0,0 +1,2454 @@ +#include "../systeminc/version.h" +#include "pl01.h" +//#include "../systeminc/font.h" + + + +#define FONT_SIZE 14 + + +static int PAT0_000[] = //? +{ + 2,640,480, + 0,0,0,0, + 0,480,0,0 +}; + +static int PAT0_001[] = //? +{ + 1,32,32, + 0,0,0,0 +}; + +static int PAT0_002[] = //d +{ + 1,8,8, + 0,0,0,0 +}; + +//????? ? ? ? ? +static int PAT2_000[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 0, FONT_SIZE * 0 +}; +static int PAT2_001[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 1, FONT_SIZE * 0 +}; +static int PAT2_002[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 2, FONT_SIZE * 0 +}; +static int PAT2_003[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 3, FONT_SIZE * 0 +}; +static int PAT2_004[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 4, FONT_SIZE * 0 +}; +static int PAT2_005[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 5, FONT_SIZE * 0 +}; +static int PAT2_006[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 6, FONT_SIZE * 0 +}; +static int PAT2_007[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 7, FONT_SIZE * 0 +}; +static int PAT2_008[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 8, FONT_SIZE * 0 +}; +static int PAT2_009[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 9, FONT_SIZE * 0 +}; + +//????? ? ? ? ? +static int PAT2_010[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 0, FONT_SIZE * 1 +}; +static int PAT2_011[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 1, FONT_SIZE * 1 +}; +static int PAT2_012[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 2, FONT_SIZE * 1 +}; +static int PAT2_013[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 3, FONT_SIZE * 1 +}; +static int PAT2_014[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 4, FONT_SIZE * 1 +}; +static int PAT2_015[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 5, FONT_SIZE * 1 +}; +static int PAT2_016[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 6, FONT_SIZE * 1 +}; +static int PAT2_017[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 7, FONT_SIZE * 1 +}; +static int PAT2_018[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 8, FONT_SIZE * 1 +}; +static int PAT2_019[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 9, FONT_SIZE * 1 +}; +static int PAT2_020[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 10, FONT_SIZE * 1 +}; +static int PAT2_021[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 11, FONT_SIZE * 1 +}; +static int PAT2_022[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 12, FONT_SIZE * 1 +}; +static int PAT2_023[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 13, FONT_SIZE * 1 +}; +static int PAT2_024[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 14, FONT_SIZE * 1 +}; +static int PAT2_025[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 15, FONT_SIZE * 1 +}; +static int PAT2_026[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 16, FONT_SIZE * 1 +}; +static int PAT2_027[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 17, FONT_SIZE * 1 +}; +static int PAT2_028[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 18, FONT_SIZE * 1 +}; +static int PAT2_029[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 19, FONT_SIZE * 1 +}; +static int PAT2_030[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 20, FONT_SIZE * 1 +}; +static int PAT2_031[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 21, FONT_SIZE * 1 +}; +static int PAT2_032[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 22, FONT_SIZE * 1 +}; +static int PAT2_033[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 23, FONT_SIZE * 1 +}; +static int PAT2_034[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 24, FONT_SIZE * 1 +}; +static int PAT2_035[] = +{ + 1,FONT_SIZE,FONT_SIZE, + 0, 0, FONT_SIZE * 25, FONT_SIZE * 1 +}; + +//?????????????? ??? ????????????????? +#define XSIZE 8 +#define YSIZE 16 +#define OFFS 0 +#define YOFFS PL0100*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_000[] = +{ + 8,XSIZE,YSIZE, + XPOS- 4 , YPOS-48,0x0000,YOFFS+0x0000, + XPOS+ 4 , YPOS-48,0x0000,YOFFS+0x0010, + XPOS+ 4 , YPOS-32,0x0000,YOFFS+0x0020, + XPOS- 4 , YPOS-32,0x0000,YOFFS+0x0030, + XPOS-12 , YPOS-32,0x0000,YOFFS+0x0040, + XPOS-12 , YPOS-16,0x0000,YOFFS+0x0050, + XPOS- 4 , YPOS-16,0x0000,YOFFS+0x0060, + XPOS+ 4 , YPOS-16,0x0000,YOFFS+0x0070, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0101*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_001[] = +{ + 8,XSIZE,YSIZE, + XPOS- 4 , YPOS-48,0x0000,YOFFS+0x0000, + XPOS+ 4 , YPOS-48,0x0000,YOFFS+0x0010, + XPOS+ 4 , YPOS-32,0x0000,YOFFS+0x0020, + XPOS- 4 , YPOS-32,0x0000,YOFFS+0x0030, + XPOS-12 , YPOS-32,0x0000,YOFFS+0x0040, + XPOS-12 , YPOS-16,0x0000,YOFFS+0x0050, + XPOS- 4 , YPOS-16,0x0000,YOFFS+0x0060, + XPOS+ 4 , YPOS-16,0x0000,YOFFS+0x0070, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0102*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_002[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0010, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0020, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0030, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0040, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0050, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0060, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0070, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0080, +}; + +#undef YOFFS +#undef YPOS +#define YOFFS PL0103*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_003[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0010, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0020, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0030, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0040, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0050, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0060, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0070, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0080, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0104*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_004[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0105*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_005[] = +{ + 12,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0016*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0106*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_006[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0107*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_007[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0108*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_008[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0109*8 +#define XPOS 7 +#define YPOS 0 +static int PAT1_009[] = +{ + 10,XSIZE,YSIZE, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010A*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_00A[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010B*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_00B[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010C*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_00C[] = +{ + 12,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0016*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010D*8 +#define XPOS 6 +#define YPOS 0 +static int PAT1_00D[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010E*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_00E[] = +{ + 12,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0016*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL010F*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_00F[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0110*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_010[] = +{ + 11,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0111*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_011[] = +{ + 9,XSIZE,YSIZE, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0112*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_012[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0113*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_013[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0114*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_014[] = +{ + 7,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0115*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_015[] = +{ + 8,XSIZE,YSIZE, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0116*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_016[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0117*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_017[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0118*8 +#define XPOS 7 +#define YPOS 0 +static int PAT1_018[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0119*8 +#define XPOS 18 +#define YPOS 0 +static int PAT1_019[] = +{ + 9,XSIZE,YSIZE, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011A*8 +#define XPOS 14 +#define YPOS 0 +static int PAT1_01A[] = +{ + 7,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011B*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_01B[] = +{ + 5,XSIZE,YSIZE, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0008*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011C*8 +#define XPOS 5 +#define YPOS 0 +static int PAT1_01C[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011D*8 +#define XPOS 5 +#define YPOS 0 +static int PAT1_01D[] = +{ + 7,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011E*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_01E[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL011F*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_01F[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0120*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_020[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0121*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_021[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0122*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_022[] = +{ + 9,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0123*8 +#define XPOS 0 +#define YPOS -3 +static int PAT1_023[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0124*8 +#define XPOS 1 +#define YPOS -2 +static int PAT1_024[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0125*8 +#define XPOS 1 +#define YPOS -7 +static int PAT1_025[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0126*8 +#define XPOS 0 +#define YPOS -4 +static int PAT1_026[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0127*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_027[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0128*8 +#define XPOS 0 +#define YPOS -12 +static int PAT1_028[] = +{ + 7,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0129*8 +#define XPOS 0 +#define YPOS -12 +static int PAT1_029[] = +{ + 7,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012A*8 +#define XPOS 0 +#define YPOS -12 +static int PAT1_02A[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012B*8 +#define XPOS 0 +#define YPOS -12 +static int PAT1_02B[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012C*8 +#define XPOS 0 +#define YPOS -12 +static int PAT1_02C[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012D*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_02D[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012E*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_02E[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL012F*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_02F[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0130*8 +#define XPOS 1 +#define YPOS 0 +static int PAT1_030[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0131*8 +#define XPOS -1 +#define YPOS 0 +static int PAT1_031[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0132*8 +#define XPOS -3 +#define YPOS 0 +static int PAT1_032[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0133*8 +#define XPOS -4 +#define YPOS 0 +static int PAT1_033[] = +{ + 8,XSIZE,YSIZE, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0134*8 +#define XPOS -4 +#define YPOS 0 +static int PAT1_034[] = +{ + 6,XSIZE,YSIZE, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000A*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0135*8 +#define XPOS 1 +#define YPOS 0 +static int PAT1_035[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0136*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_036[] = +{ + 9,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0137*8 +#define XPOS 3 +#define YPOS 0 +static int PAT1_037[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x000A*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0138*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_038[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0139*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_039[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013A*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_03A[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013B*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_03B[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013C*8 +#define XPOS -4 +#define YPOS -8 +static int PAT1_03C[] = +{ + 11,XSIZE,YSIZE, + XPOS- 24,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS+ 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013D*8 +#define XPOS -4 +#define YPOS -8 +static int PAT1_03D[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 16,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 16,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 24,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013E*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_03E[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL013F*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_03F[] = +{ + 10,XSIZE,YSIZE, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0140*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_040[] = +{ + 8,XSIZE,YSIZE, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0002*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0141*8 +#define XPOS 2 +#define YPOS 0 +static int PAT1_041[] = +{ + 8,XSIZE,YSIZE, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0142*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_042[] = +{ + 8,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0143*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_043[] = +{ + 13,XSIZE,YSIZE, + XPOS- 20,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0008*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0012*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0016*8, + XPOS+ 12,YPOS- 16,0x0000,YOFFS+0x0018*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0144*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_044[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0145*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_045[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0146*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_046[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0147*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_047[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0148*8 +#define XPOS 1 +#define YPOS 0 +static int PAT1_048[] = +{ + 6,XSIZE,YSIZE, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000A*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0149*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_049[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014A*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_04A[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014B*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_04B[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014C*8 +#define XPOS 4 +#define YPOS 0 +static int PAT1_04C[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014D*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_04D[] = +{ + 11,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014E*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_04E[] = +{ + 9,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL014F*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_04F[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0150*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_050[] = +{ + 8,XSIZE,YSIZE, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0151*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_051[] = +{ + 7,XSIZE,YSIZE, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0152*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_052[] = +{ + 11,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0153*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_053[] = +{ + 11,XSIZE,YSIZE, + XPOS- 4,YPOS- 64,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 64,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0154*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_054[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 64,0x0000,YOFFS+0x0000*8, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0155*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_055[] = +{ + 8,XSIZE,YSIZE, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0156*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_056[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0157*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_057[] = +{ + 9,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0158*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_058[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0159*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_059[] = +{ + 10,XSIZE,YSIZE, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015A*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05A[] = +{ + 10,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015B*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05B[] = +{ + 11,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x0014*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015C*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05C[] = +{ + 10,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0012*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015D*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05D[] = +{ + 13,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0016*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0018*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015E*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05E[] = +{ + 13,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0016*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0018*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL015F*8 +#define XPOS 8 +#define YPOS 0 +static int PAT1_05F[] = +{ + 13,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x0010*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0016*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0018*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0160*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_060[] = +{ + 1,XSIZE,YSIZE, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0000*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0161*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_061[] = +{ + 2,XSIZE,YSIZE, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0002*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0162*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_062[] = +{ + 2,XSIZE,YSIZE, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0002*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0163*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_063[] = +{ + 1,XSIZE,YSIZE, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0000*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0164*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_064[] = +{ + 2,XSIZE,YSIZE, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0002*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0165*8 +#define XPOS 0 +#define YPOS 0 +static int PAT1_065[] = +{ + 1,XSIZE,YSIZE, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0000*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0166*8 +#define XPOS 4 +#define YPOS -1 +static int PAT1_066[] = +{ + 9,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x000E*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0010*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0167*8 +#define XPOS 4 +#define YPOS -1 +static int PAT1_067[] = +{ + 8,XSIZE,YSIZE, + XPOS- 12,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x000C*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x000E*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0168*8 +#define XPOS -1 +#define YPOS -1 +static int PAT1_068[] = +{ + 12,XSIZE,YSIZE, + XPOS- 16,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS- 8,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 0,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 8,YPOS- 48,0x0000,YOFFS+0x0006*8, + XPOS+ 8,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS+ 0,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 8,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 16,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 16,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 8,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS+ 0,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS+ 8,YPOS- 16,0x0000,YOFFS+0x0016*8, +}; + +#undef YOFFS +#undef XPOS +#undef YPOS +#define YOFFS PL0169*8 +#define XPOS 0 +#define YPOS -1 +static int PAT1_069[] = +{ + 12,XSIZE,YSIZE, + XPOS- 4,YPOS- 48,0x0000,YOFFS+0x0000*8, + XPOS+ 4,YPOS- 48,0x0000,YOFFS+0x0002*8, + XPOS+ 12,YPOS- 48,0x0000,YOFFS+0x0004*8, + XPOS+ 12,YPOS- 32,0x0000,YOFFS+0x0006*8, + XPOS+ 4,YPOS- 32,0x0000,YOFFS+0x0008*8, + XPOS- 4,YPOS- 32,0x0000,YOFFS+0x000A*8, + XPOS- 12,YPOS- 32,0x0000,YOFFS+0x000C*8, + XPOS- 20,YPOS- 32,0x0000,YOFFS+0x000E*8, + XPOS- 20,YPOS- 16,0x0000,YOFFS+0x0010*8, + XPOS- 12,YPOS- 16,0x0000,YOFFS+0x0012*8, + XPOS- 4,YPOS- 16,0x0000,YOFFS+0x0014*8, + XPOS+ 4,YPOS- 16,0x0000,YOFFS+0x0016*8, +}; + + + + + +int *pPatTbl00[] = { + PAT0_000, + PAT0_001, + PAT0_002 +}; + + + +int *pPatTbl01[] = { + PAT1_000,PAT1_001,PAT1_002,PAT1_003,PAT1_004,PAT1_005,PAT1_006,PAT1_007, + PAT1_008,PAT1_009,PAT1_00A,PAT1_00B,PAT1_00C,PAT1_00D,PAT1_00E,PAT1_00F, + PAT1_010,PAT1_011,PAT1_012,PAT1_013,PAT1_014,PAT1_015,PAT1_016,PAT1_017, + PAT1_018,PAT1_019,PAT1_01A,PAT1_01B,PAT1_01C,PAT1_01D,PAT1_01E,PAT1_01F, + PAT1_020,PAT1_021,PAT1_022,PAT1_023,PAT1_024,PAT1_025,PAT1_026,PAT1_027, + PAT1_028,PAT1_029,PAT1_02A,PAT1_02B,PAT1_02C,PAT1_02D,PAT1_02E,PAT1_02F, + PAT1_030,PAT1_031,PAT1_032,PAT1_033,PAT1_034,PAT1_035,PAT1_036,PAT1_037, + PAT1_038,PAT1_039,PAT1_03A,PAT1_03B,PAT1_03C,PAT1_03D,PAT1_03E,PAT1_03F, + PAT1_040,PAT1_041,PAT1_042,PAT1_043,PAT1_044,PAT1_045,PAT1_046,PAT1_047, + PAT1_048,PAT1_049,PAT1_04A,PAT1_04B,PAT1_04C,PAT1_04D,PAT1_04E,PAT1_04F, + PAT1_050,PAT1_051,PAT1_052,PAT1_053,PAT1_054,PAT1_055,PAT1_056,PAT1_057, + PAT1_058,PAT1_059,PAT1_05A,PAT1_05B,PAT1_05C,PAT1_05D,PAT1_05E,PAT1_05F, + PAT1_060,PAT1_061,PAT1_062,PAT1_063,PAT1_064,PAT1_065,PAT1_066,PAT1_067, + PAT1_068,PAT1_069 +}; + +int *pPatTbl02[] = { +// ?? + PAT2_000, // ? + PAT2_001, // ? + PAT2_002, // ? + PAT2_003, // ? + PAT2_004, // ? + PAT2_005, // ? + PAT2_006, // ? + PAT2_007, // ? + PAT2_008, // ? + PAT2_009, // ? +// ??????? + PAT2_010, // ? + PAT2_011, // ? + PAT2_012, // ? + PAT2_013, // ? + PAT2_014, // ? + PAT2_015, // ? + PAT2_016, // ? + PAT2_017, // ? + PAT2_018, // ? + PAT2_019, // ? + PAT2_020, // ? + PAT2_021, // ? + PAT2_022, // ? + PAT2_023, // ? + PAT2_024, // ? + PAT2_025, // ? + PAT2_026, // ? + PAT2_027, // ? + PAT2_028, // ? + PAT2_029, // ? + PAT2_030, // ? + PAT2_031, // ? + PAT2_032, // ? + PAT2_033, // ? + PAT2_034, // ? + PAT2_035, // ? +}; + +static int PAT3_000[] = // ?? +{ + 1,68,94, + 0,0,68 * 0,0 +}; + +static int PAT3_001[] = // +{ + 1,68,94, + 0,0,68 * 1,0 +}; + +static int PAT3_002[] = // +{ + 1,68,94, + 0,0,68 * 2,0 +}; + +static int PAT3_003[] = // +{ + 1,68,94, + 0,0,68 * 3,0 +}; + +static int PAT3_004[] = // ?~ +{ + 1,72,93, + 0,0,72 * 0,94 +}; + +static int PAT3_005[] = // +{ + 1,72,93, + 0,0,72 * 1,94 +}; + +static int PAT3_006[] = // +{ + 1,72,93, + 0,0,72 * 2,94 +}; + +static int PAT3_007[] = // +{ + 1,72,93, + 0,0,72 * 3,94 +}; + +// +int *pPatTbl03[] = { + PAT3_000, // ?? + PAT3_001, // + PAT3_002, // + PAT3_003, // + PAT3_004, // ?~ + PAT3_005, // + PAT3_006, // + PAT3_007, // +}; + + diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/pl01.h b/石器时代8.5客户端最新源代码/石器源码/oft/pl01.h new file mode 100644 index 0000000..eeb56fb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/pl01.h @@ -0,0 +1,106 @@ +#define PL0100 0 +#define PL0101 16 +#define PL0102 32 +#define PL0103 50 +#define PL0104 68 +#define PL0105 88 +#define PL0106 112 +#define PL0107 132 +#define PL0108 150 +#define PL0109 170 +#define PL010A 190 +#define PL010B 208 +#define PL010C 226 +#define PL010D 250 +#define PL010E 270 +#define PL010F 294 +#define PL0110 314 +#define PL0111 336 +#define PL0112 354 +#define PL0113 374 +#define PL0114 390 +#define PL0115 404 +#define PL0116 420 +#define PL0117 438 +#define PL0118 454 +#define PL0119 470 +#define PL011A 488 +#define PL011B 502 +#define PL011C 512 +#define PL011D 528 +#define PL011E 542 +#define PL011F 560 +#define PL0120 578 +#define PL0121 596 +#define PL0122 614 +#define PL0123 632 +#define PL0124 654 +#define PL0125 674 +#define PL0126 694 +#define PL0127 712 +#define PL0128 734 +#define PL0129 748 +#define PL012A 762 +#define PL012B 778 +#define PL012C 794 +#define PL012D 810 +#define PL012E 832 +#define PL012F 852 +#define PL0130 874 +#define PL0131 892 +#define PL0132 912 +#define PL0133 928 +#define PL0134 944 +#define PL0135 956 +#define PL0136 976 +#define PL0137 994 +#define PL0138 1024 +#define PL0139 1044 +#define PL013A 1064 +#define PL013B 1084 +#define PL013C 1104 +#define PL013D 1126 +#define PL013E 1148 +#define PL013F 1166 +#define PL0140 1186 +#define PL0141 1202 +#define PL0142 1218 +#define PL0143 1234 +#define PL0144 1260 +#define PL0145 1278 +#define PL0146 1296 +#define PL0147 1316 +#define PL0148 1334 +#define PL0149 1346 +#define PL014A 1362 +#define PL014B 1378 +#define PL014C 1394 +#define PL014D 1416 +#define PL014E 1438 +#define PL014F 1456 +#define PL0150 1472 +#define PL0151 1488 +#define PL0152 1502 +#define PL0153 1524 +#define PL0154 1546 +#define PL0155 1566 +#define PL0156 1582 +#define PL0157 1602 +#define PL0158 1620 +#define PL0159 1640 +#define PL015A 1660 +#define PL015B 1680 +#define PL015C 1702 +#define PL015D 1722 +#define PL015E 1748 +#define PL015F 1774 +#define PL0160 1800 +#define PL0161 1802 +#define PL0162 1806 +#define PL0163 1810 +#define PL0164 1812 +#define PL0165 1816 +#define PL0166 1818 +#define PL0167 1836 +#define PL0168 1852 +#define PL0169 1876 diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/sys2.cpp b/石器时代8.5客户端最新源代码/石器源码/oft/sys2.cpp new file mode 100644 index 0000000..e4c3015 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/sys2.cpp @@ -0,0 +1,681 @@ +/*----------------------------------------------------------------- + [??????? +-------------------------------------------------------------------*/ +#include + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "vg410.h" +#include "work.h" +#include "../other/caryIme.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/pc.h" +#include"../systeminc/netmain.h" +#include"../systeminc/lssproto_cli.h" +#include "../systeminc/character.h" +#include"../systeminc/map.h" +#include +#define RELEASE(x) if(x){x->Release();x=NULL;} + +/*------------------------------------------- + ??? +--------------------------------------------*/ + +extern HINSTANCE hInst; +#ifndef DI_2 +LPDIRECTINPUT8 pDInput; +LPDIRECTINPUT8 pDInput2; +#else +LPDIRECTINPUT pDInput; +LPDIRECTINPUT pDInput2; +#endif + +#ifdef _MIND_ICON +bool m_bt = false; +#endif + +/*?????????? ???????????? ??????????*/ +#define REPEAT_TIME 30 +#define REPEAT_SPEED 7 +Uint32 joy_auto_repeat(Uint8 d1) +{ + Uint32 d0=0; + if( (joy_con[d1] & JOY_UP+JOY_DOWN+JOY_RIGHT+JOY_LEFT+JOY_A+JOY_B+JOY_F5+JOY_F6+JOY_F7+JOY_F8)==0 ){ /*???????*/ + joy_timer[d1]=0; /*?????????????*/ + return 0; + } + if(joy_trg[d1] & JOY_UP){ /*?*/ + d0|=JOY_UP; /*???????*/ + } else { + if(joy_con[d1] & JOY_UP){ /*?*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_UP; + } + } + } + if(joy_trg[d1] & JOY_DOWN){ /*??*/ + d0|=JOY_DOWN; /*????????*/ + } else { + if(joy_con[d1] & JOY_DOWN){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_DOWN; + } + } + } + if(joy_trg[d1] & JOY_RIGHT){ /*??*/ + d0|=JOY_RIGHT; /*????????*/ + } else { + if(joy_con[d1] & JOY_RIGHT){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_RIGHT; + } + } + } + if(joy_trg[d1] & JOY_LEFT){ /*??*/ + d0|=JOY_LEFT; /*????????*/ + } else { + if(joy_con[d1] & JOY_LEFT){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_LEFT; + } + } + } + +#if 1 + if(joy_trg[d1] & JOY_A){ /*A?*/ + d0|=JOY_A; /*????????*/ + } else { + if(joy_con[d1] & JOY_A){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_A; + } + } + } + + if(joy_trg[d1] & JOY_B){ /*B?*/ + d0|=JOY_B; /*????????*/ + } else { + if(joy_con[d1] & JOY_B){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_B; + } + } + } +#endif + + if(joy_trg[d1] & JOY_F5){ /*F5?*/ + d0|=JOY_F5; /*????????*/ + } else { + if(joy_con[d1] & JOY_F5){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_F5; + } + } + } + if(joy_trg[d1] & JOY_F6){ /*F6?*/ + d0|=JOY_F6; /*????????*/ + } else { + if(joy_con[d1] & JOY_F6){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_F6; + } + } + } + if(joy_trg[d1] & JOY_F7){ /*F7?*/ + d0|=JOY_F7; /*????????*/ + } else { + if(joy_con[d1] & JOY_F7){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_F7; + } + } + } + if(joy_trg[d1] & JOY_F8){ /*F8?*/ + d0|=JOY_F8; /*????????*/ + } else { + if(joy_con[d1] & JOY_F8){ /*??*/ + joy_timer[d1]++; /*??*/ + if(joy_timer[d1]==REPEAT_TIME){ + joy_timer[d1]-=REPEAT_SPEED; + d0|=JOY_F8; + } + } + } + return d0; +} + +#if 0 +/*?????????? ??????????????\? ??????????*/ +void joy_read(void) +{ + Uint16 d0,d1; + Uint16 a,c; + d0=0; //??D??? + if(GetAsyncKeyState(VK_LEFT) & 0x8000) + d0|=JOY_LEFT; + if(GetAsyncKeyState(VK_UP) & 0x8000) + d0|=JOY_UP; + if(GetAsyncKeyState(VK_RIGHT) & 0x8000) + d0|=JOY_RIGHT; + if(GetAsyncKeyState(VK_DOWN) & 0x8000) + d0|=JOY_DOWN; + if(GetAsyncKeyState(VK_Z) & 0x8000) + d0|=JOY_A; + if(GetAsyncKeyState(VK_X) & 0x8000) + d0|=JOY_B; + if(GetAsyncKeyState(VK_G) & 0x8000) + d0|=JOY_A; + if(GetAsyncKeyState(VK_H) & 0x8000) + d0|=JOY_B; + joy_con[0] = d0; + + d0=0; //??D??? + if(GetAsyncKeyState(VK_NUMPAD4) & 0x8000) + d0|=JOY_LEFT; + if(GetAsyncKeyState(VK_NUMPAD8) & 0x8000) + d0|=JOY_UP; + if(GetAsyncKeyState(VK_NUMPAD6) & 0x8000) + d0|=JOY_RIGHT; + if(GetAsyncKeyState(VK_NUMPAD2) & 0x8000) + d0|=JOY_DOWN; + if(GetAsyncKeyState(VK_A) & 0x8000) + d0|=JOY_A; + if(GetAsyncKeyState(VK_S) & 0x8000) + d0|=JOY_B; + if(GetAsyncKeyState(VK_T) & 0x8000) + d0|=JOY_A; + if(GetAsyncKeyState(VK_Y) & 0x8000) + d0|=JOY_B; + joy_con[1] = d0; + + d1 = ~(joy_buf[0]); //??D??? + joy_trg[0] = d1 & joy_con[0]; + + d1 = ~(joy_buf[1]); //??D??? + joy_trg[1] = d1 & joy_con[1]; + + c = ~(joy_con[0]); //??D? + a = ~(joy_buf[0]); + a ^= c; + a &= c; + joy_pul[0] = a; + + c = ~(joy_con[1]); //??D? + a = ~(joy_buf[1]); + a ^= c; + a &= c; + joy_pul[1] = a; + + joy_buf[0] = joy_con[0]; + joy_buf[1] = joy_con[1]; + + joy_auto[0] = joy_auto_repeat(0); + joy_auto[1] = joy_auto_repeat(1); +} +#else +/*------------------------------------------- + ?????????x +---------------------------------------------*/ +BOOL CALLBACK GetJoystickCallback(LPDIDEVICEINSTANCE lpddi,LPVOID pvRef) +{ + HRESULT ret; + +#ifndef DI_2 + //?????????????????????? + ret = pDInput->CreateDevice(lpddi->guidInstance,&pDInputDevice2,NULL); + if(ret != DI_OK){ + return DIENUM_CONTINUE; + } +#else + LPDIRECTINPUTDEVICE pDev; + //?????????????????????? + ret = pDInput->CreateDevice(lpddi->guidInstance,&pDev,NULL); + if(ret != DI_OK){ + return DIENUM_CONTINUE; + } + pDev->QueryInterface(IID_IDirectInputDevice2,(LPVOID *)&pDInputDevice2); +#endif + return DIENUM_STOP; +} + +/*?????????? ??????????????????????\? ??????????*/ +void joy_read(void) +{ + Uint32 d0,d1; + Uint32 a,c; + HRESULT ret = DI_OK; + DIJOYSTATE dijs; + + if(keyboad_flg == FALSE){ //????????? + return; + } + + d0=0; + + //??D??? + + if( DInputActiveFlag == TRUE ){ + if(joy_flg == TRUE){ //????????ϣ?? + pDInputDevice2->Poll(); //??????????? + ret = pDInputDevice2->GetDeviceState(sizeof(DIJOYSTATE),&dijs); + if(ret == DI_OK){ + if(dijs.lX > 500) + d0|=JOY_RIGHT; + if(dijs.lX < -500) + d0|=JOY_LEFT; + if(dijs.lY > 500) + d0|=JOY_DOWN; + if(dijs.lY < -500) + d0|=JOY_UP; + if(dijs.rgbButtons[0] & 0x80) + d0|=JOY_A; + if(dijs.rgbButtons[1] & 0x80) + d0|=JOY_B; + } + else if(ret == DIERR_INPUTLOST){ + pDInputDevice2->Acquire(); + } + } + ret = pDInputDevice->GetDeviceState(256,di_key); //???????? + } + if(ret == DI_OK){ + if(di_key[DIK_LEFT] & 0x80) + d0|=JOY_LEFT; + if(di_key[DIK_UP] & 0x80) + d0|=JOY_UP; + if(di_key[DIK_RIGHT] & 0x80) + d0|=JOY_RIGHT; + if(di_key[DIK_DOWN] & 0x80) + d0|=JOY_DOWN; + //if(di_key[DIK_Z] & 0x80) + // d0|=JOY_A; + //if(di_key[DIK_X] & 0x80) + // d0|=JOY_B; + //if(di_key[DIK_G] & 0x80) + // d0|=JOY_A; + //if(di_key[DIK_H] & 0x80) + // d0|=JOY_B; + + // ???? ????????? + // ESC ?? + if(di_key[DIK_ESCAPE] & 0x80){ + // ????????????? + //if( ImeBufferBak2 == NULL ) + d0|=JOY_ESC; + } + + // ??????? Ctrl ??????????? + if( di_key[DIK_RCONTROL] & 0x80 || di_key[DIK_LCONTROL] & 0x80 ){ + // Ctrl + M + if( di_key[DIK_M] & 0x80 ) d0|=JOY_CTRL_M; + // Ctrl + S + if( di_key[DIK_S] & 0x80 ) d0|=JOY_CTRL_S; + // Ctrl + P + if( di_key[DIK_P] & 0x80 ) d0|=JOY_CTRL_P; + // Ctrl + I + if( di_key[DIK_I] & 0x80 ) d0|=JOY_CTRL_I; + // Ctrl + E + if( di_key[DIK_E] & 0x80 ) d0|=JOY_CTRL_E; + // Ctrl + A + if( di_key[DIK_A] & 0x80 ) d0|=JOY_CTRL_A; + // Ctrl + C + if( di_key[DIK_C] & 0x80 ) d0|=JOY_CTRL_C; + // Ctrl + V + if( di_key[DIK_V] & 0x80 ) d0|=JOY_CTRL_V; + // Ctrl + Z + if( di_key[DIK_Z] & 0x80 ) d0|=JOY_A; + // Ctrl + X + if( di_key[DIK_X] & 0x80 ) d0|=JOY_B; + // Ctrl + T + if( di_key[DIK_T] & 0x80 ) d0|=JOY_CTRL_T; + + + } + + // {?? + if( di_key[DIK_PRIOR] & 0x80) d0|=JOY_P_UP; + if( di_key[DIK_NEXT] & 0x80) d0|=JOY_P_DOWN; + if( di_key[DIK_HOME] & 0x80) d0|=JOY_HOME; + if( di_key[DIK_END] & 0x80) d0|=JOY_END; + if( di_key[DIK_INSERT] & 0x80) d0|=JOY_INS; + if( di_key[DIK_DELETE] & 0x80) d0|=JOY_DEL; + + + + joy_con[0] = d0; + + d0=0; + + //??D??? + // ???????? + if( GetImeString() == NULL ){ + + // ????????? + if(di_key[DIK_F1] & 0x80) d0|=JOY_F1; + if(di_key[DIK_F2] & 0x80) d0|=JOY_F2; + if(di_key[DIK_F3] & 0x80) d0|=JOY_F3; + if(di_key[DIK_F4] & 0x80) d0|=JOY_F4; + + if(di_key[DIK_F5] & 0x80) d0|=JOY_F5; + if(di_key[DIK_F6] & 0x80) d0|=JOY_F6; + if(di_key[DIK_F7] & 0x80) d0|=JOY_F7; + if(di_key[DIK_F8] & 0x80) d0|=JOY_F8; + + if(di_key[DIK_F9] & 0x80) d0|=JOY_F9; + if(di_key[DIK_F10] & 0x80) d0|=JOY_F10; + if(di_key[DIK_F11] & 0x80) d0|=JOY_F11; + if(di_key[DIK_F12] & 0x80) d0|=JOY_F12; + } + // ??????? Ctrl ??????????? + if( di_key[DIK_RCONTROL] & 0x80 || di_key[DIK_LCONTROL] & 0x80 ){ + // ?????????????? + if(di_key[DIK_1] & 0x80) d0|=JOY_CTRL_1; + if(di_key[DIK_2] & 0x80) d0|=JOY_CTRL_2; + if(di_key[DIK_3] & 0x80) d0|=JOY_CTRL_3; + if(di_key[DIK_4] & 0x80) d0|=JOY_CTRL_4; + if(di_key[DIK_5] & 0x80) d0|=JOY_CTRL_5; + if(di_key[DIK_6] & 0x80) d0|=JOY_CTRL_6; + if(di_key[DIK_7] & 0x80) d0|=JOY_CTRL_7; + if(di_key[DIK_8] & 0x80) d0|=JOY_CTRL_8; + if(di_key[DIK_9] & 0x80) d0|=JOY_CTRL_9; + if(di_key[DIK_0] & 0x80) d0|=JOY_CTRL_0; + if(di_key[DIK_MINUS] & 0x80) d0|=JOY_CTRL_MINUS; + //cary ʮ + if(di_key[DIK_EQUALS] & 0x80) d0|=JOY_CTRL_CIRCUMFLEX; + if(di_key[DIK_BACKSLASH] & 0x80) d0|=JOY_CTRL_YEN; + if(di_key[DIK_J] & 0x80) d0|=JOY_CTRL_J; + if(di_key[DIK_Q] & 0x80) d0|=JOY_CTRL_Q; + if(di_key[DIK_W] & 0x80) d0|=JOY_CTRL_W; + if(di_key[DIK_G] & 0x80) d0|=JOY_CTRL_G; + + // Robin 0607 channel + if(di_key[DIK_C] & 0x80) d0|=JOY_CTRL_C; + + #ifdef _TELLCHANNEL //ROG ADD Ƶ + if( di_key[DIK_R] & 0x80 ) d0|=JOY_CTRL_R; + #endif + + } + + // ????????? + //if(di_key[DIK_SYSRQ] & 0x80) d0|=JOY_PRINT_SCREEN; + // ???? + if(di_key[DIK_TAB] & 0x80) d0|=JOY_TAB; + // ????? + if(di_key[DIK_RSHIFT] & 0x80) d0|=JOY_RSHIFT; + if(di_key[DIK_LSHIFT] & 0x80) d0|=JOY_LSHIFT; + // ?????? + //if(di_key[DIK_RETURN] & 0x80) d0|=JOY_RETURN; + +#ifdef _MIND_ICON + if( (pc.ptAct) && ((di_key[DIK_LMENU] & 0x80) || (di_key[DIK_RMENU] & 0x80)) && pc.ptAct->pYobi ){ + CHAREXTRA *ext; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + if(!ext->ptMindIcon){ + if(!m_bt && (di_key[DIK_Q] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_heart); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_heart); + }else if(!m_bt && (di_key[DIK_W] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_broken); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_broken); + }else if(!m_bt && (di_key[DIK_E] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_m_clip); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_m_clip); + }else if(!m_bt && (di_key[DIK_R] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_m_stone); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_m_stone); + }else if(!m_bt && (di_key[DIK_T] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_m_burlap); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_m_burlap); + }else if(!m_bt && (di_key[DIK_Y] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_screamer); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_screamer); + }else if(!m_bt && (di_key[DIK_U] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_question_mark); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_question_mark); + }else if(!m_bt && (di_key[DIK_I] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_cramp); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_cramp); + }else if(!m_bt && (di_key[DIK_O] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_black_squall); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_black_squall); + }else if(!m_bt && (di_key[DIK_P] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_perspiration); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_perspiration); + }else if(!m_bt && (di_key[DIK_A] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_silence); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_silence); + }else if(!m_bt && (di_key[DIK_S] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_asleep); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_asleep); + }else if(!m_bt && (di_key[DIK_D] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_cafe); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_cafe); + }else if(!m_bt && (di_key[DIK_F] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_lightbulb); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_lightbulb); + }else if(!m_bt && (di_key[DIK_G] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_accent); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_accent); + }else if(!m_bt && (di_key[DIK_H] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_money); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_money); + }else if(!m_bt && (di_key[DIK_J] & 0x80)){ + m_bt = true; setCharMind( pc.ptAct, SPR_pk); + lssproto_MA_send( sockfd, nowGx, nowGy, SPR_pk); + } + if(!(di_key[0x10]&0x80) && !(di_key[0x11]&0x80) && !(di_key[0x12]&0x80) && + !(di_key[0x13]&0x80) && !(di_key[0x14]&0x80) && !(di_key[0x15]&0x80) && + !(di_key[0x16]&0x80) && !(di_key[0x17]&0x80) && !(di_key[0x18]&0x80) && + !(di_key[0x19]&0x80) && !(di_key[0x1E]&0x80) && !(di_key[0x1F]&0x80) && + !(di_key[0x20]&0x80) && !(di_key[0x21]&0x80) && !(di_key[0x22]&0x80) && + !(di_key[0x23]&0x80) && !(di_key[0x24]&0x80) + ) + m_bt = false; + } + } +#endif + +#if 0 + if(di_key[DIK_NUMPAD4] & 0x80) + d0|=JOY_LEFT; + if(di_key[DIK_NUMPAD8] & 0x80) + d0|=JOY_UP; + if(di_key[DIK_NUMPAD6] & 0x80) + d0|=JOY_RIGHT; + if(di_key[DIK_NUMPAD2] & 0x80) + d0|=JOY_DOWN; + if(di_key[DIK_A] & 0x80) + d0|=JOY_A; + if(di_key[DIK_S] & 0x80) + d0|=JOY_B; + if(di_key[DIK_T] & 0x80) + d0|=JOY_A; + if(di_key[DIK_Y] & 0x80) + d0|=JOY_B; +#endif + + + joy_con[1] = d0; + + d1 = ~(joy_buf[0]); //??D??? + joy_trg[0] = d1 & joy_con[0]; + + d1 = ~(joy_buf[1]); //??D??? + joy_trg[1] = d1 & joy_con[1]; + + c = ~(joy_con[0]); //??D? + a = ~(joy_buf[0]); + a ^= c; + a &= c; + joy_pul[0] = a; + + c = ~(joy_con[1]); //??D? + a = ~(joy_buf[1]); + a ^= c; + a &= c; + joy_pul[1] = a; + + joy_buf[0] = joy_con[0]; + joy_buf[1] = joy_con[1]; + + joy_auto[0] = joy_auto_repeat(0); + joy_auto[1] = joy_auto_repeat(1); + } + else if(ret == DIERR_INPUTLOST){ + pDInputDevice->Acquire(); + } +} +#endif +/*?????????? ?????????????????????? ??????????*/ +/*------------------------------------------- + Direct Input ??? +---------------------------------------------*/ +int InitDInput(void) +{ + HRESULT ret; + + if( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ){ //???????????? + return FALSE; + } +#ifndef DI_2 + ret = DirectInput8Create( hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&pDInput, NULL); + if(ret != DI_OK){ + return FALSE; + } +#else + ret = DirectInputCreate(hInst,DIRECTINPUT_VERSION,&pDInput,NULL); + if(ret != DI_OK){ + return FALSE; + } +#endif + //??????????????????? + ret = pDInput->CreateDevice(GUID_SysKeyboard,&pDInputDevice,NULL); + if(ret != DI_OK){ + RELEASE(pDInput); + return FALSE; + } + + //??????????@e + ret = pDInputDevice->SetDataFormat(&c_dfDIKeyboard); + if(ret != DI_OK){ + RELEASE(pDInputDevice); + RELEASE(pDInput); + return FALSE; + } + + //????@e + ret = pDInputDevice->SetCooperativeLevel(hWnd,DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); + if(ret != DI_OK){ + RELEASE(pDInputDevice); + RELEASE(pDInput); + return FALSE; + } + + pDInputDevice->Acquire(); + +#ifndef DI_2 + ret = DirectInput8Create( hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&pDInput, NULL); + if(ret != DI_OK){ + return FALSE; + } +#else + ret = DirectInputCreate(hInst,DIRECTINPUT_VERSION,&pDInput2,NULL); + if(ret != DI_OK){ + return FALSE; + } +#endif + keyboad_flg = TRUE; //?????ϣ + + joy_flg = FALSE; //????????t? + return TRUE; + + //?????????S? + pDInputDevice2 = NULL; + +#ifndef DI_2 + pDInput2->EnumDevices( DI8DEVCLASS_GAMECTRL, (LPDIENUMDEVICESCALLBACK)GetJoystickCallback, NULL, DIEDFL_ATTACHEDONLY); + if(pDInputDevice2 == NULL){ + RELEASE(pDInput2); + return FALSE; + } +#else + pDInput2->EnumDevices(DIDEVTYPE_JOYSTICK,(LPDIENUMDEVICESCALLBACK)GetJoystickCallback,NULL,DIEDFL_ATTACHEDONLY); + if(pDInputDevice2 == NULL){ + RELEASE(pDInput2); + return FALSE; + } +#endif + //??????????@e + ret = pDInputDevice2->SetDataFormat(&c_dfDIJoystick); + if(ret != DI_OK){ + RELEASE(pDInputDevice2); + RELEASE(pDInput2); + return FALSE; + } + + //????@e + ret = pDInputDevice2->SetCooperativeLevel(hWnd,DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); + if(ret != DI_OK){ + RELEASE(pDInputDevice2); + RELEASE(pDInput2); + return FALSE; + } + + DIPROPRANGE diprg; + + // ?k?d??@e + diprg.diph.dwSize = sizeof(diprg); + diprg.diph.dwHeaderSize = sizeof(diprg.diph); + diprg.diph.dwObj = DIJOFS_X; + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.lMin = -1000; + diprg.lMax = +1000; + pDInputDevice2->SetProperty(DIPROP_RANGE, &diprg.diph); + diprg.diph.dwObj = DIJOFS_Y; + pDInputDevice2->SetProperty(DIPROP_RANGE, &diprg.diph); + + pDInputDevice2->Acquire(); + + joy_flg = TRUE; //????????ϣ + return TRUE; +} +/*------------------------------------------- + Direct Input ?? +---------------------------------------------*/ +int EndDInput(void) +{ + //?????ϣ?? + if(keyboad_flg == TRUE){ + pDInputDevice->Unacquire(); + RELEASE(pDInputDevice); + RELEASE(pDInput); + } + //????????ϣ?? + if(joy_flg == TRUE){ + pDInputDevice2->Unacquire(); + RELEASE(pDInputDevice2); + RELEASE(pDInput2); + } + + return TRUE; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/sys2.h b/石器时代8.5客户端最新源代码/石器源码/oft/sys2.h new file mode 100644 index 0000000..aee7bbe --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/sys2.h @@ -0,0 +1,12 @@ +/************************/ +/* sys2.h */ +/************************/ +#ifndef _SYS2_H_ +#define _SYS2_H_ + +// ???V? +extern void joy_read(void); +extern int InitDInput(void); +extern int EndDInput(void); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/tekecess.cpp b/石器时代8.5客户端最新源代码/石器源码/oft/tekecess.cpp new file mode 100644 index 0000000..0dca5b1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/tekecess.cpp @@ -0,0 +1,310 @@ +/************************/ +/* takecess.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/map.h" +#include "../systeminc/menu.h" +#include "../systeminc/battlemap.h" + +#if 0 + +extern ACTION* oft_test(); +extern void damage_num( ACTION *a0 ); +extern int piyo_point; + +int flash_pal_cnt; +PALETTEENTRY Palette2[256]; // ?????Bl + +/* ?????? *********************************************************/ +void die_flash( void ) +{ + int d0 = 0; + int d1,d7; + switch(flash_vct_no){ + case 0: + break; + +//?????????? ? ?????????? + case 1: + flash_vct_no++; + break; + + case 2: + for( d7 = 0; d7 < 10; d7++ ){ + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = Palette[d7].peRed; + Palette2[d7].peFlags = Palette[d7].peFlags; + + Palette2[d7+246].peBlue = Palette[d7+246].peBlue; + Palette2[d7+246].peGreen = Palette[d7+246].peGreen; + Palette2[d7+246].peRed = Palette[d7+246].peRed; + Palette2[d7+246].peFlags = Palette[d7].peFlags; + } + for( d7 = 10; d7 < 246; d7++ ){ //?????????? + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = 0xff; + Palette2[d7].peFlags = Palette[d7].peFlags; + } + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + flash_pal_cnt = 20; + flash_vct_no++; + break; + + case 3: + if(--flash_pal_cnt){ + break; + } + flash_vct_no++; + break; + + case 4: + for(d7=10; d7<246; d7++){ + if(Palette2[d7].peRed == Palette[d7].peRed){ + continue; + } + d0 = 1; + d1 = Palette2[d7].peRed - Palette[d7].peRed; + if(d1 > 2) + d1 = 2; + if(d1 < -2) + d1 = -2; + Palette2[d7].peRed -= d1; + } + if(WindowMode){ //?????????? + flash_pal_cnt++; + if(flash_pal_cnt == 10){ //??u?? + flash_pal_cnt = 0; + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + } else { + d0 = 1; //???? + } + } else { + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + } + if(d0 == 0){ //??? + flash_vct_no = 0; + } + break; + +#if 0 +//?????????? ? ?????????? + case 4: + for( d7 = 0; d7 < 10; d7++ ){ + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = Palette[d7].peRed; + Palette2[d7].peFlags = Palette[d7].peFlags; + + Palette2[d7+246].peBlue = Palette[d7+246].peBlue; + Palette2[d7+246].peGreen = Palette[d7+246].peGreen; + Palette2[d7+246].peRed = Palette[d7+246].peRed; + Palette2[d7+246].peFlags = Palette[d7].peFlags; + } + for( d7 = 10; d7 < 246; d7++ ){ //?????????? + Palette2[d7].peBlue = 0xf0; + Palette2[d7].peGreen = 0xf0; + Palette2[d7].peRed = 0xf0; + Palette2[d7].peFlags = Palette[d7].peFlags; + } + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + flash_pal_cnt = 0; + flash_vct_no = 6; + break; + +//?????????? ????? ?????????? + case 5: + for( d7 = 0; d7 < 10; d7++ ){ + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = Palette[d7].peRed; + Palette2[d7].peFlags = Palette[d7].peFlags; + + Palette2[d7+246].peBlue = Palette[d7+246].peBlue; + Palette2[d7+246].peGreen = Palette[d7+246].peGreen; + Palette2[d7+246].peRed = Palette[d7+246].peRed; + Palette2[d7+246].peFlags = Palette[d7].peFlags; + } + for( d7 = 10; d7 < 246; d7++ ){ //?????????? + Palette2[d7].peBlue = 0xff; + Palette2[d7].peGreen = 0x80; + Palette2[d7].peRed = 0x80; + Palette2[d7].peFlags = Palette[d7].peFlags; + } + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + flash_pal_cnt = 0; + flash_vct_no = 6; + break; + +//?????????? ? ? ????? ?????????? + case 6: + for(d7=10; d7<246; d7++){ + if(Palette2[d7].peRed != Palette[d7].peRed){ + d0 = 1; + d1 = Palette2[d7].peRed - Palette[d7].peRed; + if(d1 > 4) + d1 = 4; + if(d1 < -4) + d1 = -4; + Palette2[d7].peRed -= d1; + } + if(Palette2[d7].peGreen != Palette[d7].peGreen){ + d0 = 1; + d1 = Palette2[d7].peGreen - Palette[d7].peGreen; + if(d1 > 4) + d1 = 4; + if(d1 < -4) + d1 = -4; + Palette2[d7].peGreen -= d1; + } + if(Palette2[d7].peBlue != Palette[d7].peBlue){ + d0 = 1; + d1 = Palette2[d7].peBlue - Palette[d7].peBlue; + if(d1 > 4) + d1 = 4; + if(d1 < -4) + d1 = -4; + Palette2[d7].peBlue -= d1; + } + } + if(WindowMode){ //?????????? + flash_pal_cnt++; + if(flash_pal_cnt == 10){ //??u?? + flash_pal_cnt = 0; + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + } else { + d0 = 1; //???? + } + } else { + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); + } + if(d0 == 0){ //??? + flash_vct_no = 0; + } + break; +#endif + } +} +/* ???????k *********************************************************/ +void damage_dispx( void ) +{ + ACTION *pActLoop = pActTop->pNext; /* Id????????x */ + ACTION *pActLoopBak; /* ????????? */ + int d0; + char szMoji[ 256 ]; + + // ????? + while(1){ + + /* ?????????? */ + if( pActLoop == pActBtm ) break; + + /* ????? */ + if( pActLoop->deathFlag == FALSE ){ + + /* Pd( pActLoop->prio ); */ + /* ?????????? */ + if( pActLoop->func == damage_num ){ + if(ATR_INT_WORK1(pActLoop) == 0){ //???? + sprintf_s( szMoji,"Miss" ); + } else if(ATR_INT_WORK1(pActLoop) == 1){ //??????? + sprintf_s( szMoji,"Counter" ); + } else if(ATR_INT_WORK1(pActLoop) == 3){ //????? + sprintf_s( szMoji,"Guard" ); + } else { + sprintf_s( szMoji,"%d", ATR_INT_WORK0(pActLoop) ); + } + d0 = GetStrWidth( szMoji ) >> 1; + StockFontBuffer( ATR_H_POS(pActLoop) - d0, ATR_V_POS(pActLoop), FONT_PRIO_BACK, ATR_INT_WORK1(pActLoop), szMoji, 0 ); + } + + /* ?????????? */ + pActLoop = pActLoop->pNext; + + }else{ /* ?????? */ + + /* q????? */ + pActLoop->pPrev->pNext = pActLoop->pNext; + pActLoop->pNext->pPrev = pActLoop->pPrev; + /* ?????? */ + pActLoopBak = pActLoop->pNext; + /* ?????? */ + ClearAction( pActLoop ); + /* ???????? */ + pActLoop = pActLoopBak; + } + } +} + +/* ?????? ********************************************************************/ +void TakeTestProc( void ) +{ + s_timer++; + switch( SubProcNo ){ + case 0: + slow_flg = 0; + oft_test(); + SubProcNo++; + InitChat(); + GetKeyInputFocus( &MyChatBuffer ); +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap( BattleMapNo ); +#else + ReadBattleMap( BattleMapNo ); +#endif + break; + + case 1: + if(joy_trg[0]&JOY_A){ + DeathAllAction(); + SubProcNo = 0; + break; + } + FlashKeyboardCursor(); + if(slow_flg){ + if(!(s_timer&7)){ + piyo_point++; + piyo_point &= 63; + } + if(s_timer&3){ + damage_dispx(); //???????k + goto TakeTestProc01_100; + } + } else { + if(!(s_timer&1)){ + piyo_point++; + piyo_point &= 63; + } + } + /* ????????? */ + RunAction(); + +TakeTestProc01_100: + if(flash_vct_no){ //???????? + die_flash(); //?????? + } + + // ??????????????? + StockTaskDispBuffer(); + + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + + break; + } +} +#endif + +/* ?????? ********************************************************************/ +void TakeTestProc( void ){} diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/vg410.h b/石器时代8.5客户端最新源代码/石器源码/oft/vg410.h new file mode 100644 index 0000000..edcfc52 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/vg410.h @@ -0,0 +1,505 @@ + +#ifndef _VG410_H_ +#define _VG410_H_ + +#include "windows.h" +#include "../systeminc/action.h" + +typedef unsigned char Uint8 ; /* ????????? */ +typedef signed char Sint8 ; /* ????????? */ +typedef unsigned short Uint16 ; /* ????????? */ +typedef signed short Sint16 ; /* ????????? */ +typedef unsigned long Uint32 ; /* ????????? */ +typedef signed long Sint32 ; /* ????????? */ +typedef float Float32 ; /* ????? */ +typedef double Float64 ; /* ????? */ + +/*---------- ???????????? ----------*/ +#define ATR_MAX 256 + +typedef void (*FUNC)(Uint16); +typedef void (*FUNC2)(); +typedef struct{ + Uint8 vct_no; + Uint8 stimer; + ACTION *body_work[20]; + Uint8 body_cnt; + int damage; + + Uint8 hit_stop; + Uint8 hit_timing; + Uint8 group_flg; + int attack_kind[20]; + int attack_pow[20]; + Uint8 combo; + Uint8 kaishin; + int life; + ACTION *counter; + Uint8 counter_flg; + ACTION *jujutsu_work; + ACTION *magicstatus_work; + ACTION *attrib_work; + Uint8 guard_flg; + Uint8 damage_ang; + Uint8 first_flg; + Uint8 place_no; + Uint8 pet_ok; + Uint8 ako_flg; + Uint8 crs_old; + Uint8 sync_flg; + int int_work0; + int int_work1; + int int_work2; + int int_work3; + int long_work[20]; + // Robin 0729 + int attack_pet_kind[20]; + int attack_pet_pow[20]; + int pet_damage; + int int_workp; + int onRide; + //andy_mp + int mpdamage; + int addhp; + int mpflg; + int addhpflg; + int showaddhp; + int graNo; +#ifdef __NEW_BATTLE_EFFECT + int effect_flg; + int effect_anim; + int effect_param; +#endif +#ifdef _SKILL_SELFEXPLODE //Ա + int petSelfExplode; //() +#endif +#ifdef _PETSKILL_BATTLE_MODEL + int battle_model; +#endif +} ATR_EQU; + +#define ATR_NAME(a) a->func +#define ATR_ATTRIB(a) a->atr +#define ATR_H_POS(a) a->x +#define ATR_V_POS(a) a->y +#define ATR_H_MINI(a) a->h_mini +#define ATR_V_MINI(a) a->v_mini +#define ATR_SPD(a) a->spd +#define ATR_CRS(a) a->crs +//#define ATR_SPD(a) ((ATR_EQU *)a->pReg)->spd +//#define ATR_CRS(a) ((ATR_EQU *)a->pReg)->crs +//#define ATR_H_MINI(a) ((ATR_EQU *)a->pReg)->h_mini +//#define ATR_V_MINI(a) ((ATR_EQU *)a->pReg)->v_mini +#define ATR_PAT_NO(a) a->bmpNo +#define ATR_PAT_BAK_NO(a) a->bmpNo_bak + + +#define ATR_CHR_NO(a) a->anim_chr_no +#define ATR_CHR_NO_OLD(a) a->anim_chr_no_bak +#define ATR_CHR_ACT(a) a->anim_no +#define ATR_CHR_ACT_OLD(a) a->anim_no_bak +#define ATR_CHR_ANG(a) a->anim_ang +#define ATR_CHR_ANG_OLD(a) a->anim_ang_bak +#define ATR_CHR_CNT(a) a->anim_cnt +#define ATR_CHR_TIM(a) a->anim_frame_cnt +#define ATR_CHR_H_POS(a) a->anim_x +#define ATR_CHR_V_POS(a) a->anim_y +#define ATR_TASK_PRIO(a) a->prio /* ????I?? */ +#define ATR_DISP_PRIO(a) a->dispPrio /* ??I?? */ +#define ATR_LIFE(a) a->hp +#ifdef _PET_ITEM +#define ATR_OLD_LIFE(a) a->iOldHp +#endif +#define ATR_MP(a) a->mp +#define ATR_MAX_LIFE(a) a->maxHp +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define ATR_MAX_MANA(a) a->maxMp +#endif +#define ATR_HANDLE(a) a->name +#define ATR_TITLE(a) a->freeName +#define ATR_LEVEL(a) a->level +#define ATR_HIT(a) a->anim_hit +#define ATR_STATUS(a) a->status /* ????? */ +// Robin 0728 ridePet +#define ATR_RIDE(a) a->onRide +#define ATR_PETNAME(a) a->petName +#define ATR_PETLEVEL(a) a->petLevel +#define ATR_PET_LIFE(a) a->petHp +#define ATR_PET_MAX_LIFE(a) a->petMaxHp +#define ATR_PETFALL(a) a->petFall +#ifdef _SKILL_ROAR +#define ATR_ROAR(a) a->petRoar //() +#endif +#ifdef _SKILL_SELFEXPLODE //Ա +#define ATR_SELFEXPLODE(a) a->petSelfExplode +#endif +#ifdef _MAGIC_DEEPPOISION //綾 +#define ATR_DEEPPOISION(a) a->petDeepPoision +#endif +//#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define ATR_WARRIOR_EFFECT(a) a->warrioreffect +//#endif + +#ifdef _SFUMATO +#define ATR_SFUMATO(a) a->sfumato // Ⱦͼɫ +#endif + +#define ATR_VCT_NO(a) ((ATR_EQU *)a->pYobi)->vct_no +#define ATR_STIMER(a) ((ATR_EQU *)a->pYobi)->stimer +#define ATR_BODY_WORK(b,a) ((ATR_EQU *)a->pYobi)->body_work[b] +#define ATR_BODY_CNT(a) ((ATR_EQU *)a->pYobi)->body_cnt +#define ATR_DAMAGE(a) ((ATR_EQU *)a->pYobi)->damage + + +//#define ATR_BODY_WORK(b,a) _ATR_BODY_WORK(b,a,__FILE__,__LINE__) + +ACTION * _ATR_BODY_WORK(int b ,ACTION * a,char *file,int line); + +//andy_mp +#define ATR_MPDAMAGE(a) ((ATR_EQU *)a->pYobi)->mpdamage +#define ATR_MPDFLG(a) ((ATR_EQU *)a->pYobi)->mpflg +#define ATR_ADDHP(a) ((ATR_EQU *)a->pYobi)->addhp +#define ATR_ADDHPFLG(a) ((ATR_EQU *)a->pYobi)->addhpflg +#define ATR_SHOWADDHP(a) ((ATR_EQU *)a->pYobi)->showaddhp +#define ATR_BATTLEGRANO(a) ((ATR_EQU *)a->pYobi)->graNo + +#define ATR_GROUP_FLG(a) ((ATR_EQU *)a->pYobi)->group_flg +#define ATR_ATTACK_KIND(b,a) ((ATR_EQU *)a->pYobi)->attack_kind[b] + +#define ATR_ATTACK_POW(b,a) ((ATR_EQU *)a->pYobi)->attack_pow[b] +#define ATR_HIT_STOP(a) ((ATR_EQU *)a->pYobi)->hit_stop +#define ATR_HIT_TIMING(a) ((ATR_EQU *)a->pYobi)->hit_timing +#define ATR_COMBO(a) ((ATR_EQU *)a->pYobi)->combo +#define ATR_KAISHIN(a) ((ATR_EQU *)a->pYobi)->kaishin +#define ATR_COUNTER(a) ((ATR_EQU *)a->pYobi)->counter +#define ATR_COUNTER_FLG(a) ((ATR_EQU *)a->pYobi)->counter_flg +#define ATR_JUJUTSU_WORK(a) ((ATR_EQU *)a->pYobi)->jujutsu_work +#define ATR_MAGICSU_WORK(a) ((ATR_EQU *)a->pYobi)->magicstatus_work +#define ATR_ATTRIB_WORK(a) ((ATR_EQU *)a->pYobi)->attrib_work +#define ATR_GUARD_FLG(a) ((ATR_EQU *)a->pYobi)->guard_flg +#define ATR_DAMAGE_ANG(a) ((ATR_EQU *)a->pYobi)->damage_ang +#define ATR_FIRST_FLG(a) ((ATR_EQU *)a->pYobi)->first_flg +#define ATR_PLACE_NO(a) ((ATR_EQU *)a->pYobi)->place_no +#define ATR_PET_OK(a) ((ATR_EQU *)a->pYobi)->pet_ok +#define ATR_AKO_FLG(a) ((ATR_EQU *)a->pYobi)->ako_flg +#define ATR_CRS_OLD(a) ((ATR_EQU *)a->pYobi)->crs_old +#define ATR_SYNC_FLG(a) ((ATR_EQU *)a->pYobi)->sync_flg +#define ATR_INT_WORK0(a) ((ATR_EQU *)a->pYobi)->int_work0 +#define ATR_INT_WORK1(a) ((ATR_EQU *)a->pYobi)->int_work1 +#define ATR_INT_WORK2(a) ((ATR_EQU *)a->pYobi)->int_work2 +#define ATR_INT_WORK3(a) ((ATR_EQU *)a->pYobi)->int_work3 +#define ATR_LONG_WORK(b,a) ((ATR_EQU *)a->pYobi)->long_work[b] +// Robin 0729 ride pet +#define ATR_ATTACK_PET_KIND(b,a) ((ATR_EQU *)a->pYobi)->attack_pet_kind[b] +#define ATR_ATTACK_PET_POW(b,a) ((ATR_EQU *)a->pYobi)->attack_pet_pow[b] +#define ATR_PET_DAMAGE(a) ((ATR_EQU *)a->pYobi)->pet_damage +#define ATR_INT_WORKp(a) ((ATR_EQU *)a->pYobi)->int_workp +#define ATR_RIDE_FLAG(a) ((ATR_EQU *)a->pYobi)->onRide + +#ifdef __NEW_BATTLE_EFFECT +#define ATR_EFFECT_FLAG(a) ((ATR_EQU *)a->pYobi)->effect_flg +#define ATR_EFFECT_ANIM(a) ((ATR_EQU *)a->pYobi)->effect_anim +#define ATR_EFFECT_PARAM(a) ((ATR_EQU *)a->pYobi)->effect_param +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +#define ATR_BATTLE_MODEL(a) ((ATR_EQU *)a->pYobi)->battle_model +#endif + +#ifdef _SKILL_SELFEXPLODE //Ա +//#define ATR_SELFEXPLODE(a) ((ATR_EQU *)a->pYobi)->petSelfExplode //Ա +#endif +/*---------- ??? ----------*/ +#define ATT_HIT 'H' //??? +#define ATT_FIRE 'Z' //?d +#define ATT_BOW 'B' //? +#define ATT_TAKE 'T' //? +#define ATT_ESCAPE 'E' //D +#define ATT_SELECT 'S' //???k +#define ATT_MONSTER 'W' //l +#define ATT_JUJUTSU 'J' // +#ifdef __NEW_BATTLE_EFFECT +#define ATT_EFFECT 'j' //սЧ +#endif +//#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define ATT_PROSKILL '+' +//#endif +#ifdef _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ +#define ATT_FIRESKILL 'f' +#endif +#ifdef _PROFESSION_ADDSKILL// +#define ATT_BOUNDARY 'a' +#endif +#ifdef _PETSKILL_BATTLE_MODEL +#define ATT_BATTLE_MODEL 'b' // \սģ +#endif +#ifdef _PETSKILL_RIDE +#define ATT_RIDE 'c' +#endif + +//andy_mp +#define ATT_MPDAMAGE 'p' //MP˺ +#define ATT_DAMAGETOHP 'h' +#define ATT_MAGICSTATUS 'm' //״̬ +#ifdef _MAGIC_DEEPPOISION +#define ATT_DEEPPOISION 'd' //綾 +#endif +#define ATT_BOOMERANG 'O' //????? +#define ATT_SYNCHRONOUS 'Y' //i??? +#define ATT_MALFUNCTION 'M' //Ol +#define ATT_DAMAGE 'D' //Ol???? +#define ATT_FADE_OUT 'F' //NͧT +#define ATT_LIFE 'L' //??? +#define ATT_IN 'I' //??? +#define ATT_VARIABLE 'V' //N?? +#define ATT_REVERSE 'R' //?? +#define ATT_QUIT 'Q' //???`?? +#define ATT_NIX 'X' //????r +#define ATT_KANJI 'K' //?? +#define ATT_NEXT_EQUIP 'N' //?? +#define ATT_COMPANIONS '!' //s?? +#define ATT_STEAL '#' //?? +#define ATT_TALK '%' //???? +#define ATT_TOCALL '$' // ٻ + +#define ATT_DEATH (1 << 0) // +#define ATT_NORMAL (1 << 1) //ͨ +#define ATT_SATISFACTORY (1 << 2) //һ +#define ATT_GUARD (1 << 3) // +#define ATT_COUNTER (1 << 4) // +#define ATT_DODGE (1 << 5) // +#define ATT_AKO1 (1 << 6) //1 +#define ATT_AKO2 (1 << 7) //2 +#define ATT_G_CRASH (1 << 8) //ײ +#define ATT_VICARIOUS (1 << 9) //Ȯ +#define ATT_REFLEX (1 << 10) // +#define ATT_ABSORPTION (1 << 11) // +#define ATT_BALLIA (1 << 12) // +#define ATT_CRUSH (1 << 13) //ײ +#define ATT_FALL (1 << 14) // +#define ATT_TOOEH (1 << 15) // +#define ATT_ATTDOUBLE (1 << 16) //ǿ +#ifdef _SKILL_ROAR +#define ATT_ATTROAR (1 << 17) //() +#endif +#ifdef _SKILL_SELFEXPLODE //Ա +#define ATT_ATTSELFEXPLODE (1 << 18) //Ա +#endif +#ifdef _PETSKILL_EXPLODE +#define ATT_EXPLODE (1 << 29) //(Աһ,ֻǽɫʧ) +#endif + +#define BCF_DEFMAGICATT (1 << 19) +#define BCF_SUPERWALL (1 << 20) +#define BCF_MODIFY (1 << 21) //ת + + +//#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define ATT_ATTPREPROSKILL (1 << 22) //ְҵ +#define ATT_ATTNEXTPROSKILL (1 << 23) //ְҵ +#define ATT_TRAP (1 << 25) // +#define ATT_NOMISS (1 << 26) //һ» +//#endif + +#ifdef _EQUIT_ARRANGE +#define ATT_ARRANGE (1 << 24) //ͼ#endif +#endif + +#ifdef _PETSKILL_ACUPUNCTURE +#define ATT_ACUPUNCTURE (1 << 27) +#endif + +#ifdef _PETSKILL_ANTINTER +#define ATT_ANTINTER (1 << 28) +#endif + +#ifdef _PET_ITEM +#define ATT_ATTACKBACK (1 << 30) +#endif + +#define JUJUTSU_1 (1) // "", +#define JUJUTSU_2 (2) // "??", +#define JUJUTSU_3 (3) // "?", +#define JUJUTSU_4 (4) // "?", +#define JUJUTSU_5 (5) // "?????", +#define JUJUTSU_6 (6) // "??" + +#define BC_FRESH (1 << 0) //?? +#define BC_DEATH (1 << 1) //? +#define BC_PET_OK (1 << 2) //????V?ϣ +#define BC_BIT3 (1 << 3) // "", +#define BC_BIT4 (1 << 4) // "??", +#define BC_BIT5 (1 << 5) // "?", +#define BC_BIT6 (1 << 6) // "?", +#define BC_BIT7 (1 << 7) // "?????", +#define BC_BIT8 (1 << 8) // "??" +#define BC_FADE_OUT (1 << 9) //??? +#define BC_REVERSE (1 << 10) //NͧT +#ifdef _MAGIC_WEAKEN +#define BC_WEAKEN (1 << 11) // +#endif +#ifdef _MAGIC_DEEPPOISION +#define BC_DEEPPOISON (1 << 12) //綾 +#endif +#ifdef _MAGIC_BARRIER +#define BC_BARRIER (1 << 13) //ħ +#endif +#ifdef _MAGIC_NOCAST +#define BC_NOCAST (1 << 14) //Ĭ +#endif + +#ifdef _SARS // WON ADD ɷ +#define BC_SARS (1 << 15) // ɷ +#endif +#ifdef _PETSKILL_LER +#define BC_CHANGE (1<<30) // ׶ +#endif +#ifdef _CHAR_PROFESSION // WON ADD +#define BC_DIZZY (1 << 16) // ѣ +#define BC_ENTWINE (1 << 17) // +#define BC_DRAGNET (1 << 18) // ޵ +#define BC_ICECRACK (1 << 19) // +#define BC_OBLIVION (1 << 20) // +#define BC_ICEARROW (1 << 21) // +#define BC_BLOODWORMS (1 << 22) // Ѫ +#define BC_SIGN (1 << 23) // һѪ +#define BC_CRAZY (1 << 24) // +#define BC_F_ENCLOSE (1 << 25) // +#define BC_I_ENCLOSE (1 << 26) // +#define BC_T_ENCLOSE (1 << 27) // ׸ + +#ifdef _PROFESSION_ADDSKILL +#define BC_WATER (1 << 28) // ˮ +#define BC_FEAR (1 << 29) // ־ +//#define BC_F_I_T_ENCLOSE (1 << 28) // ׸ +#endif +#ifdef _PETSKILL_LER +#define BC_CHANGE (1<<30) // ׶ +#endif +#ifdef _PRO_KILLME +#define BC_ANGER (1<<31) // ŭ +#endif + +#endif + + +/*---------- ???????? ----------*/ +// ?? +#define JOY_RIGHT (1 << 15) /* Right Key */ +#define JOY_LEFT (1 << 14) /* Left Key */ +#define JOY_DOWN (1 << 13) /* Down Key */ +#define JOY_UP (1 << 12) /* Up Key */ +#define JOY_START (1 << 11) /* Start */ +#define JOY_A (1 << 10) /* A Trigger */ +#define JOY_C (1 << 9) /* C Trigger */ +#define JOY_B (1 << 8) /* B Trigger */ +#define JOY_R (1 << 7) /* R Trigger */ +#define JOY_X (1 << 6) /* X Trigger */ +#define JOY_DEL (1 << 5) /* DELETE */ +#define JOY_INS (1 << 4) /* INSERT */ +#define JOY_END (1 << 3) /* END */ +#define JOY_HOME (1 << 2) /* HOME */ +#define JOY_P_DOWN (1 << 1) /* PAGE_UP */ +#define JOY_P_UP (1 << 0) /* PAGE_DOWN */ + +#define JOY_ESC (1 << 31) /* ESC Key */ +#define JOY_CTRL_M (1 << 30) /* Ctrl + M */ +#define JOY_CTRL_S (1 << 29) /* Ctrl + S */ +#define JOY_CTRL_P (1 << 28) /* Ctrl + P */ +#define JOY_CTRL_I (1 << 27) /* Ctrl + I */ +#define JOY_CTRL_E (1 << 26) /* Ctrl + E */ +#define JOY_CTRL_A (1 << 25) /* Ctrl + A */ + +#define JOY_CTRL_C (1 << 24) /* Ctrl + C */ +#define JOY_CTRL_V (1 << 23) /* Ctrl + V */ +#define JOY_CTRL_T (1 << 22) /* Ctrl + T */ + +#if 0 +#define JOY_X (1 << 22) /* X Trigger */ +#define JOY_Y (1 << 21) /* Y Trigger */ +#define JOY_Z (1 << 20) /* Z Trigger */ +#define JOY_L (1 << 19) /* L Trigger */ +#define JOY_G (1 << 18) /* L Trigger */ +#define JOY_H (1 << 17) /* L Trigger */ +#define JOY_H (1 << 16) /* L Trigger */ +#endif + +// ?? +//#define JOY_RIGHT (1 << 15) /* Right Key */ +//#define JOY_LEFT (1 << 14) /* Left Key */ +//#define JOY_DOWN (1 << 13) /* Down Key */ +//#define JOY_UP (1 << 12) /* Up Key */ +// ????????? +#define JOY_F1 (1 << 0) /* F1 */ +#define JOY_F2 (1 << 1) /* F2 */ +#define JOY_F3 (1 << 2) /* F3 */ +#define JOY_F4 (1 << 3) /* F4 */ +#define JOY_F5 (1 << 4) /* F5 */ +#define JOY_F6 (1 << 5) /* F6 */ +#define JOY_F7 (1 << 6) /* F7 */ +#define JOY_F8 (1 << 7) /* F8 */ +#define JOY_F9 (1 << 8) /* F9 */ +#define JOY_F10 (1 << 9) /* F10 */ +#define JOY_F11 (1 << 10) /* F11 */ +#define JOY_F12 (1 << 11) /* F12 */ +// ????????????? +#define JOY_CTRL_1 (1 << 12) /* Ctrl + 1 */ +#define JOY_CTRL_2 (1 << 13) /* Ctrl + 2 */ +#define JOY_CTRL_3 (1 << 14) /* Ctrl + 3 */ +#define JOY_CTRL_4 (1 << 15) /* Ctrl + 4 */ +#define JOY_CTRL_5 (1 << 16) /* Ctrl + 5 */ +#define JOY_CTRL_6 (1 << 17) /* Ctrl + 6 */ +#define JOY_CTRL_7 (1 << 18) /* Ctrl + 7 */ +#define JOY_CTRL_8 (1 << 19) /* Ctrl + 8 */ +#define JOY_CTRL_9 (1 << 20) /* Ctrl + 9 */ +#define JOY_CTRL_0 (1 << 21) /* Ctrl + 0 */ +#define JOY_CTRL_MINUS (1 << 22) /* Ctrl + MINUS */ +#define JOY_CTRL_CIRCUMFLEX (1 << 23) /* Ctrl + DIK_CIRCUMFLEX */ +#define JOY_CTRL_YEN (1 << 28) /* Ctrl + YEN */ +// ???? +#define JOY_TAB (1 << 25) /* Ctrl + TAB */ +// ????? +#define JOY_RSHIFT (1 << 26) /* Ctrl + RSHIFT */ +#define JOY_LSHIFT (1 << 27) /* Ctrl + LSHIFT */ +// ????? +#define JOY_CTRL_J (1 << 24) /* Ctrl + J */ +// ?v????? +#define JOY_CTRL_Q (1 << 29) /* Ctrl + Q */ +// ?????? +#define JOY_CTRL_W (1 << 30) /* Ctrl + W */ +// ????????? +#define JOY_CTRL_G (1 << 31) /* Ctrl + G */ + +#ifdef _TELLCHANNEL //ROG ADD Ƶ +#define JOY_CTRL_R (1 << 31) +#endif + +/*--------- ????? ------------------*/ +#define VK_A 0x41 +#define VK_B 0x42 +#define VK_C 0x43 +#define VK_D 0x44 +#define VK_E 0x45 +#define VK_F 0x46 +#define VK_G 0x47 +#define VK_H 0x48 +#define VK_I 0x49 +#define VK_J 0x4A +#define VK_K 0x4B +#define VK_L 0x4C +#define VK_M 0x4D +#define VK_N 0x4E +#define VK_O 0x4F +#define VK_P 0x50 +#define VK_Q 0x51 +#define VK_R 0x52 +#define VK_S 0x53 +#define VK_T 0x54 +#define VK_U 0x55 +#define VK_V 0x56 +#define VK_W 0x57 +#define VK_X 0x58 +#define VK_Y 0x59 +#define VK_Z 0x5A + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/work.cpp b/石器时代8.5客户端最新源代码/石器源码/oft/work.cpp new file mode 100644 index 0000000..9ed1adf --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/work.cpp @@ -0,0 +1,30 @@ +#include "../systeminc/version.h" +#include "vg410.h" +#include "work.h" + +/*---------- ??? ----------*/ +Uint32 joy_con[2]={0,0}; +Uint32 joy_trg[2]={0,0}; +Uint32 joy_pul[2]={0,0}; +Uint32 joy_buf[2]; +Uint32 joy_auto[2]={0,0}; +Uint16 joy_timer[2]; +Uint16 s_timer; +unsigned char di_key[256]; +#ifndef DI_2 +LPDIRECTINPUTDEVICE8 pDInputDevice; +LPDIRECTINPUTDEVICE8 pDInputDevice2; +#else +LPDIRECTINPUTDEVICE pDInputDevice; +LPDIRECTINPUTDEVICE2 pDInputDevice2; +#endif +char joy_flg = FALSE; +char keyboad_flg = FALSE; +int slow_flg = 0; +int flash_vct_no = 0; +int quake_flg = 0; +int quake_vct_no = 0; +ACTION *p_party[BATTLKPKPLYAERNUM]; +int action_inf; +// +BOOL DInputActiveFlag = TRUE; diff --git a/石器时代8.5客户端最新源代码/石器源码/oft/work.h b/石器时代8.5客户端最新源代码/石器源码/oft/work.h new file mode 100644 index 0000000..cfef578 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/oft/work.h @@ -0,0 +1,34 @@ +#ifndef _WORK_H_ +#define _WORK_H_ + +#include +#include "vg410.h" + +/*---------- ??? ----------*/ +extern Uint32 joy_con[2]; +extern Uint32 joy_trg[2]; +extern Uint32 joy_pul[2]; +extern Uint32 joy_buf[2]; +extern Uint32 joy_auto[2]; +extern Uint16 joy_timer[2]; +extern Uint16 s_timer; +extern unsigned char di_key[256]; +#ifndef DI_2 +extern LPDIRECTINPUTDEVICE8 pDInputDevice; +extern LPDIRECTINPUTDEVICE8 pDInputDevice2; +#else +extern LPDIRECTINPUTDEVICE pDInputDevice; +extern LPDIRECTINPUTDEVICE2 pDInputDevice2; +#endif +extern char joy_flg; +extern char keyboad_flg; +extern int slow_flg; +extern int flash_vct_no; +extern int quake_flg; +extern int quake_vct_no; +extern ACTION *p_party[]; +extern int action_inf; +// +extern BOOL DInputActiveFlag; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.cpp b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.cpp new file mode 100644 index 0000000..6328df1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.cpp @@ -0,0 +1,887 @@ +/************************/ +/* ohta.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "ohta.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/t_music.h" + +ACTION *MakeJiki( void ); +void Jiki( ACTION *pAct ); + +ACTION *MakeJikiTama( int x, int y, int dx, int dy, int bmpNo ); +void JikiTama( ACTION *pAct ); + +ACTION *MakeEnemy( void ); +void Enemy( ACTION *pAct ); + +ACTION *MakeEnemyTama( ACTION *pOya ); +void EnemyTama( ACTION *pAct ); + +ACTION *MakeBg( void ); +void Bg( ACTION *pAct ); + +ACTION *MakeKen( void ); +void Ken( ACTION *pAct ); + +ACTION *MakeGameOver( void ); +void GameOver( ACTION *pAct ); + +/* kǩ` */ +int bomData[] = { 21, 22, 23, 23, 22, 21 }; + +/* ԙCΥݥ */ +ACTION *pJiki; + + +/* ĤηN */ +enum{ + TAMA_NORMAL, /* Ω`ޥ */ + TAMA_TWIN, /* ĥ */ + TAMA_3WAY, /* */ + TAMA_DIR, /* ȫ */ + TAMA_END /* K */ +}; + +/********************************************/ +/* ԙC */ +/********************************************/ + +/* ԙC䘋 */ +typedef struct{ + int cnt,cnt2,cnt3; /* å */ + int tamaDir; /* η */ + int tamaDx; /* Σ؉ */ + int attackKind; /* ĤηN */ + STR_BUFFER strTestBuffer; /* ƥ */ +}JIKI; + +static int No = 36000; + +/* ԙC *******************************************************************/ +ACTION *MakeJiki( void ) +{ + ACTION *pAct; + JIKI *pYobi; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_JIKI, sizeof( JIKI ) ); + if( pAct == NULL ) return NULL; + + /* 䘋Υɥ쥹 */ + pYobi = ( JIKI *)pAct->pYobi; + + /* gv */ + pAct->func = Jiki; + /* ʾȶ */ + pAct->dispPrio = DISP_PRIO_JIKI; + // ж + ܥåʾ + pAct->atr |= ACT_ATR_HIT_BOX; + /* ץ饤ȷ */ + //pAct->bmpNo = 31; + //pAct->anim_chr_no = 20001; + // anim_tbl.h η + pAct->anim_chr_no = 31555; // Υ + //pAct->anim_chr_no = 5200; // ޥ` + //pAct->anim_chr_no = 9350; // SCORE + // + //pAct->anim_no = ANIM_ATTACK; + pAct->anim_no = ANIM_STAND; + pAct->anim_no = ANIM_STAND + 1; + // ˥`( )( ¤һؤ ) + pAct->anim_ang = 0; + /* ȣ */ + pAct->hp = 100; + /* λ */ + pAct->x = 304; + pAct->y = 400; + + /* */ +// MakeEnemy(); + /* £ */ + //MakeBg(); + + /* */ +// MakeKen(); + + /* ĤηN */ + //pYobi->attackKind = TAMA_DIR; + pYobi->attackKind = TAMA_3WAY; + /* */ + pYobi->tamaDir = 1; + pYobi->tamaDx = 1; + /* `Х˱ */ + pJiki = pAct; + + // ФL + pYobi->strTestBuffer.len = 10; + // Фɫ + pYobi->strTestBuffer.color = 1; + pYobi->strTestBuffer.x = 320; + pYobi->strTestBuffer.y = 260; + + return pAct; + +} + +/* ԙCI *******************************************************************/ +void Jiki( ACTION *pAct ) +{ + JIKI *pYobi = ( JIKI *)pAct->pYobi; + //int i; + + /* ܤr */ + if( pAct->damage > 0 ){ + pAct->hp -= pAct->damage; + if( pAct->hp <= 0 ){ + pAct->state = ACT_STATE_DEAD; + pYobi->cnt = 0; + pYobi->cnt2 = 0; + pYobi->cnt3 = 0; + } + pAct->damage = 0; + } + // ȡ +// rcX = Rnd( 0,608 ); +// rcY = Rnd( 0,400 ); +// SetRect( &Rc[ pAct->bmpNo ], rcX, rcY, rcX + 32, rcY + 32 ); + + // ޥƄ + //pAct->x = mouse.nowPoint.x; + //pAct->y = mouse.nowPoint.y; + + // ޥǏk + if( pYobi->cnt3 <= 0 ){ + // k + //if( mouse.state == MOUSE_LEFT_CRICK ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + // ե`ȡ + //GetKeyInputFocus( &pYobi->strTestBuffer ); + /* */ + //MakeJikiTama( pAct->x , pAct->y -16, 0, -8, Rnd( 0, BMP_FILE - 1 ) ); + //MakeJikiTama( pAct->x , pAct->y -16, 0, -8, 1034 ); + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 25 ); + + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 0, BMP_FILE - 2 ) ); + + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 31554, 31557 ) ); // ԣǣ + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 31000, 31069 ) ); // 󥹥` +// MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 30100, 30135 ) ); // У + //MakeJikiTama( pAct->x + 10, pAct->y -16, 0, -8, Rnd( 0, BMP_FILE - 1 ) ); + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 29 ); + //MakeJikiTama( pAct->x - 10, pAct->y -16, 0, -8, 29 ); + //MakeJikiTama( pAct->x + 10, pAct->y -16, 0, -8, 29 ); + pYobi->cnt3 = 5; +#if 0 + for( i = 0; i < (int)256; i++ ){ + // 뤯 + Palette[i].peRed *= 0.95; + Palette[i].peGreen *= 0.95; + Palette[i].peBlue *= 0.95; + } + // ѥåȤO + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); +#endif + } + // Хܥ + if( GetAsyncKeyState( VK_MBUTTON ) ){ + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 29 ); + //MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 0, BMP_FILE - 1 ) ); + // MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 32 ); + pYobi->cnt3 = 5; + + } + // k + //if( mouse.onceState & MOUSE_RIGHT_CRICK ){ + if( mouse.state & MOUSE_RIGHT_CRICK ){ + // ե`ȡ + //GetKeyInputFocus( &MyChatBuffer ); + //if( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 ){ + // MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 29 ); + // `եä + //if( lpSurface[ 0 ] != NULL ){ + // // ` + // lpSurface[ 0 ]->Release( ); + // lpSurface[ 0 ] = NULL; + //} + // MakeBg(); +#if 0 + MakeJikiTama( pAct->x - 10, pAct->y -16, -6, -8, Rnd( 0, BMP_FILE - 2 ) ); + MakeJikiTama( pAct->x - 5, pAct->y -16, -3, -8, Rnd( 0, BMP_FILE - 2 ) ); + MakeJikiTama( pAct->x, pAct->y -16, 0, -8, Rnd( 0, BMP_FILE - 2 ) ); + MakeJikiTama( pAct->x + 5, pAct->y -16, 3, -8, Rnd( 0, BMP_FILE - 2 ) ); + MakeJikiTama( pAct->x + 10, pAct->y -16, 6, -8, Rnd( 0, BMP_FILE - 2 ) ); +#else + // MakeJikiTama( pAct->x - 10, pAct->y -16, -6, -8, No ); + // MakeJikiTama( pAct->x - 5, pAct->y -16, -3, -8, No ); + // MakeJikiTama( pAct->x, pAct->y -16, 0, -8, No ); + // MakeJikiTama( pAct->x + 5, pAct->y -16, 3, -8, No ); + // MakeJikiTama( pAct->x + 10, pAct->y -16, 6, -8, No ); +#endif + pYobi->cnt3 = 5; +#if 0 + for( i = 0; i < (int)256; i++ ){ + // + Palette[i].peRed *= 1.05; + Palette[i].peGreen*= 1.05; + Palette[i].peBlue *= 1.05; + } + //ѥåȤO + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); +#endif + } + + }else pYobi->cnt3--; + + /* ״BǷ */ + switch( pAct->state ){ + /* ͨr */ + case ACT_STATE_ACT: + + /* Ȥεж */ + //Hit( pAct, PRIO_ENEMY_TAMA ); + /* Ȥεж */ + //Hit( pAct, PRIO_ENEMY ); + + /* Ƅ */ + if( joy_con[ 0 ] & JOY_UP ){ /* */ + pAct->y -= 2; + if( pAct->y < 0 ) pAct->y = 0; + } + if( joy_con[ 0 ] & JOY_DOWN ){ /* */ + pAct->y += 2; + if( pAct->y > 448 ) pAct->y = 448; + } + if( joy_con[ 0 ] & JOY_LEFT ){ /* */ + pAct->x -= 2; + if( pAct->x < 0 ) pAct->x = 0; + } + if( joy_con[ 0 ] & JOY_RIGHT ){ /* */ + pAct->x += 2; + if( pAct->x > 608 ) pAct->x = 608; + } + + // + //if( joy_con[ 0 ] & JOY_B ) MakeEnemy(); + + /* k */ + if( pYobi->cnt3 <= 0 ){ /* */ + if( joy_con[ 0 ] & JOY_A ){ + + /*DeathAllAction();*/ + /* ηNǷ */ + switch( pYobi->attackKind ){ + + case TAMA_NORMAL: + + /* */ + MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 28 ); + + break; + + case TAMA_TWIN: + + /* */ + MakeJikiTama( pAct->x - 10, pAct->y -16, 0, -8, 29 ); + MakeJikiTama( pAct->x + 10, pAct->y -16, 0, -8, 29 ); + + break; + + case TAMA_3WAY: + + MakeJikiTama( pAct->x - 10, pAct->y -16, -4, -8, 29 ); + MakeJikiTama( pAct->x, pAct->y -16, 0, -8, 29 ); + MakeJikiTama( pAct->x + 10, pAct->y -16, 4, -8, 29 ); + + break; + + case TAMA_DIR: + + MakeJikiTama( pAct->x, pAct->y -16, pYobi->tamaDx, -8, 29 ); + MakeJikiTama( pAct->x, pAct->y -16, -pYobi->tamaDx, -8, 29 ); + /* */ + pYobi->tamaDx += pYobi->tamaDir; + if( pYobi->tamaDx <= -10 || 10 <= pYobi->tamaDx ){ + pYobi->tamaDir *= -1; + } + break; + } + pYobi->cnt3 = 2; /* */ + //pYobi->cnt3 = 0; /* */ + } + }else{ + if( pYobi->cnt3 > 0 ) pYobi->cnt3--; + } + + /* */ +/* if( ( int )pAct->x % 2 ) pAct->atr |= ACT_ATR_HIDE; + else pAct->atr &= ~ACT_ATR_HIDE; +*/ + /* */ + pYobi->cnt++; + if( pYobi->cnt >= 1 ){ + //MakeEnemy(); + pYobi->cnt2++; + if( pYobi->cnt2 >= 5 ){ + pYobi->cnt2 = 0; + /* */ + //pYobi->attackKind++; + if( pYobi->attackKind >= TAMA_END ){ + pYobi->attackKind = 0; + } + } + pYobi->cnt = 0; + } + + break; + + /* r */ + case ACT_STATE_DEAD: + + if( pYobi->cnt == 0 ){ + pAct->bmpNo = bomData[ 0 ]; + pYobi->cnt = 1; + } + /* k˥` */ + pYobi->cnt2++; + if( pYobi->cnt2 >= 5 ){ + pAct->bmpNo = bomData[ pYobi->cnt ]; + pYobi->cnt++; + pYobi->cnt2 = 0; + /* Kä */ + if( pYobi->cnt == 6 ){ + DeathAction( pAct ); + MakeGameOver( ); + } + } + + break; + } + + // ʾǩ`Хåե + //StockDispBuffer( pAct->x + 32, pAct->y, pAct->dispPrio, pAct->anim_chr_no, 0 ); + //StockDispBuffer( pAct->x - 32, pAct->y, pAct->dispPrio, pAct->anim_chr_no, 0 ); + { + char szMoji[ 256 ]; + wsprintf( szMoji,"BmpNo = %d",No ); + // StockFontBuffer( pAct->x, pAct->y, FONT_PRIO_FRONT, 2, szMoji, 0 ); + } + + // ˥` + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); + // ƥбʾ + //StockFontBuffer( 320, 200, FONT_PRIO_FRONT, pYobi->strTestBuffer.color, pYobi->strTestBuffer.buffer, 0 ); + StockFontBuffer2( &pYobi->strTestBuffer ); +} + +/********************************************/ +/* ԙC */ +/********************************************/ + +/* ԙC *********************************************************************/ +ACTION *MakeJikiTama( int x, int y, int dx, int dy, int bmpNo ) +{ + ACTION *pAct; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_JIKI_TAMA, 0 ); + if( pAct == NULL ) return NULL; + + /* gv */ + pAct->func = JikiTama; + // anim_tbl.h η + pAct->anim_chr_no = bmpNo; // Υ + // + //pAct->anim_no = ANIM_ATTACK; + pAct->anim_no = Rnd( ANIM_ATTACK, ANIM_WALK ); + //pAct->anim_no = ANIM_WALK; + // ˥`( )( ¤һؤ ) + pAct->anim_ang = Rnd( 0, 7 ); + ///* ץ饤ȷ */ + //pAct->bmpNo = bmpNo; + /* ʾȶ */ + pAct->dispPrio = 2; + /* ȣ */ + pAct->hp = 10000; + /* λ */ + pAct->x = x - dx; + pAct->y = y - dy; + /* */ + pAct->dx = dx / 2; + pAct->dy = dy / 2; + + return pAct; +} + +/* ԙCI *********************************************************************/ +void JikiTama( ACTION *pAct ) +{ + + /* ܤr */ + if( pAct->damage > 0 ){ + pAct->hp -= pAct->damage; + if( pAct->hp <= 0 ){ + pAct->state = ACT_STATE_DEAD; + } + pAct->damage = 0; + } + + /* ״BǷ */ + switch( pAct->state ){ + /* ͨr */ + case ACT_STATE_ACT: + + /* Ȥεж */ + //Hit( pAct, PRIO_ENEMY ); + + /* Ƅ */ + pAct->x += pAct->dx; + pAct->y += pAct->dy; + + /* ߥå */ + if( pAct->y <= -32 ){ + pAct->y = -32; + MakeEnemyTama( pAct ); + DeathAction( pAct ); + }else + if( lpDraw->ySize <= pAct->y ){ + pAct->y = lpDraw->ySize; + DeathAction( pAct ); + } + + if( pAct->x <= -32 ){ + pAct->x = -32; + DeathAction( pAct ); + }else + if( lpDraw->xSize <= pAct->x ){ + pAct->x = lpDraw->xSize; + DeathAction( pAct ); + } + + break; + + /* r */ + case ACT_STATE_DEAD: + + DeathAction( pAct ); + + break; + } + + + // ˥` + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); +} + + +/********************************************/ +/* */ +/********************************************/ + +/* 䘋 */ +typedef struct{ + int cnt,cnt2,cnt3,animCnt; /* å */ +}ENEMY; + +/* *********************************************************************/ +ACTION *MakeEnemy( void ) +{ + ACTION *pAct; + ENEMY *pYobi; + short bmpTbl[] = { 1, 3, 5, 7, 9, 29 }; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_ENEMY, sizeof( ENEMY ) ); + if( pAct == NULL ) return NULL; + + /* 䘋Υɥ쥹 */ + pYobi = ( ENEMY *)pAct->pYobi; + + /* gv */ + pAct->func = Enemy; + /* ץ饤ȷ */ + pAct->bmpNo = bmpTbl[ ( int )Rnd( 0, 4 ) ]; + //pAct->bmpNo = Rnd( 1, 10 ); + /* ʾȶ */ + pAct->dispPrio = 1; + /* ȣ */ + pAct->hp = 10;//Rnd( 10, 50 ); + /* λå */ +// pAct->x = Rnd( 0, 608 ); + pAct->x = Rnd( 0, lpDraw->xSize ); + ATR_CRS(pAct) = 16; + ATR_SPD(pAct) = Rnd( 28, 36 ); + pAct->dx = 0; + + pAct->y = 0; + /* ֥ */ + pAct->dx = Rnd( -3, 3 ); + pAct->dy = Rnd( 1, 3 ); + + return pAct; +} + +/* I *********************************************************************/ +void enemy_missile( ACTION *a0 ) +{ + gemini(a0); //Ƅ + //ʤ + if(ATR_H_POS(a0)>=lpDraw->xSize || ATR_H_POS(a0)<-32 || ATR_V_POS(a0)>lpDraw->ySize || ATR_V_POS(a0)<-32) + DeathAction( a0 ); //K +} + +/* I *********************************************************************/ +void Enemy( ACTION *pAct ) +{ + ENEMY *pYobi = ( ENEMY *)pAct->pYobi; + + /* ܤr */ + if( pAct->damage > 0 ){ + pAct->hp -= pAct->damage; + if( pAct->hp <= 0 ){ + pAct->state = ACT_STATE_DEAD; + pYobi->cnt = 0; + pYobi->cnt2 = 0; + pYobi->cnt3 = 0; + } + pAct->damage = 0; + } + + /* ״BǷ */ + switch( pAct->state ){ + /* ͨr */ + case ACT_STATE_ACT: + + /* Ƅ */ +// pAct->x += pAct->dx; +// pAct->y += pAct->dy; + + /* ߥåȥå */ +// if( pAct->x < 0 ){ +// pAct->x = 0; +// pAct->dx *= -1; +// } +// else +// if( pAct->x > lpDraw->xSize ){ +// pAct->x = lpDraw->xSize; +// pAct->dx *= -1; +// } +// if( pAct->y > lpDraw->ySize ){ +// pAct->y = -32; +// } + + pAct->dx++; //zߤˣإԩ`ɉ + pAct->dx&=1; // + gemini(pAct); //Ƅ + if(ATR_CRS(pAct)==0){ //ƄФʤ + if( pAct->y < -32 ){ //϶ˤʤ + ATR_CRS(pAct)=16; //Ƅ_ʼ + ATR_SPD(pAct) = Rnd( 28, 36 ); + pAct->x = Rnd( 0, lpDraw->xSize ); // + } else { + if(pAct->dx) + ATR_SPD(pAct)++; //ԩ`ɥå + } + } else { + if(pAct->dx){ + ATR_SPD(pAct)--; //ԩ`ɥ + if(!ATR_SPD(pAct)){ //ֹͣʤ + ATR_CRS(pAct)=0; //Ƅ_ʼ + ACTION *a1; //ߥk + int d1,d2; + /* ꥹȤ˵h */ + a1 = GetAction( PRIO_ENEMY_TAMA, 0 ); + if( a1 == NULL ) break; + /* gv */ + a1->func = enemy_missile; + /* ץ饤ȷ */ + a1->bmpNo = No++; + /* ʾȶ */ + a1->dispPrio = 3; + /* λ */ + ATR_H_POS(a1) = ATR_H_POS(pAct)+16; + ATR_V_POS(a1) = ATR_V_POS(pAct)+16; + d1 = pJiki->x; //ԙCη򥻥å + d2 = pJiki->y; // + radar(a1, &d1, &d2); // + ATR_CRS(a1)=d1; // + ATR_SPD(a1)=16; //Ƅٶ + play_se( 2, ATR_H_POS(a1), ATR_V_POS(a1) ); //ߥk + } + } + } + // ˥` +/* pYobi->cnt3 += pAct->dy; + if( pYobi->cnt3 >= 20 ){ + pYobi->cnt3 = 0; + pYobi->animCnt = pYobi->animCnt * ( -2 ) + 1; + pAct->bmpNo += pYobi->animCnt; + } +*/ +/* + pAct->cnt++; + if( pAct->cnt >= 300 ){ + pAct->state = ACT_STATE_DEAD; + pAct->cnt = 0; + } +*/ + //if( Rnd( 0, 300 ) == 0 ) MakeEnemyTama( pAct ); + //MakeEnemyTama( pAct ); + + break; + + /* r */ + case ACT_STATE_DEAD: + + if( pYobi->cnt == 0 ){ + pAct->bmpNo = bomData[ 0 ]; + pYobi->cnt = 1; + } + /* k˥` */ + pYobi->cnt2++; + if( pYobi->cnt2 >= 5 ){ + pAct->bmpNo = bomData[ pYobi->cnt ]; + pYobi->cnt++; + pYobi->cnt2 = 0; + /* Kä */ + if( pYobi->cnt == 6 ){ + DeathAction( pAct ); + } + } + + break; + } + +} + +/********************************************/ +/* */ +/********************************************/ + +/* *********************************************************************/ +ACTION *MakeEnemyTama( ACTION *pOya ) +{ + ACTION *pAct; + //float dir; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_ENEMY_TAMA, 0 ); + if( pAct == NULL ) return NULL; + + /* gv */ + pAct->func = EnemyTama; + /* ץ饤ȷ */ + pAct->anim_chr_no = Rnd( 31554, 31556 ); //饤 + // ж + ܥåʾ + pAct->atr |= ACT_ATR_HIT_BOX; + //pAct->anim_no = Rnd( ANIM_ATTACK, ANIM_SATTACK ); + //pAct->anim_no = ANIM_ATTACK; + pAct->anim_no = ANIM_WALK; + /* ʾȶ */ + pAct->dispPrio = DISP_PRIO_JIKI; + /* ȣ */ + pAct->hp = 0; + /* λ */ + //pAct->x = pOya->x + 16; + //pAct->y = pOya->y + 32 ; + pAct->x = Rnd( 100, 500 ); + pAct->y = Rnd( 100, 400 ); + + // Ƅӷ + radar2( pAct, pJiki->x, pJiki->y, 1 ); + //Ƅٶ + pAct->spd = 16; + + // ˥` + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); + return pAct; +} + +/* I *********************************************************************/ +void EnemyTama( ACTION *pAct ) +{ + + /* ܤr */ + if( pAct->damage > 0 ){ + pAct->hp -= pAct->damage; + if( pAct->hp <= 0 ){ + pAct->state = ACT_STATE_DEAD; + } + pAct->damage = 0; + } + + /* ״BǷ */ + switch( pAct->state ){ + /* ͨr */ + case ACT_STATE_ACT: + + // ޥ`뤬ҥåȤƤ + if( pAct->hitDispNo == HitDispNo ){ + // 󥯥åѺƤr + if( mouse.state & MOUSE_LEFT_CRICK ){ + // ɥåƄ + pAct->x = mouse.nowPoint.x; + pAct->y = mouse.nowPoint.y; + } + // 󥯥åѺƤr + if( mouse.state & MOUSE_RIGHT_CRICK ){ + // ɥåƄ + DeathAction( pAct ); + } + + } + /* Ƅ */ + //pAct->x += pAct->dx; + //pAct->y += pAct->dy; + //gemini( pAct ); //Ƅ +#if 0 + /* ߥå */ + if( pAct->y <= 0 ){ + pAct->y = 0; + DeathAction( pAct ); + }else + if( pAct->y >= 481 ){ + DeathAction( pAct ); + } + if( pAct->x <= -8 ){ + DeathAction( pAct ); + }else + if( lpDraw->xSize <= pAct->x ){ + DeathAction( pAct ); + } +#endif + break; + + /* r */ + case ACT_STATE_DEAD: + DeathAction( pAct ); + break; + } + // Ƅӷ + radar2( pAct, pJiki->x, pJiki->y, Rnd( 0, 10 ) ); + // ˥` + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); +} + +/* `४`Щ` *******************************************************************/ +ACTION *MakeGameOver( void ) +{ + ACTION *pAct; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_GAME_OVER, 0 ); + if( pAct == NULL ) return NULL; + + /* gv */ + pAct->func = GameOver; + + // DZʾ + pAct->atr |= ACT_ATR_HIDE; + + /* ץ饤ȷ */ + pAct->bmpNo = 0; +// pAct->bmpNo = 30; + /* ȣ */ + pAct->hp = 100; + /* λ */ + pAct->x = 250; + pAct->y = 200; + + return pAct; + +} + +/* `४`Щ`I *******************************************************************/ +void GameOver( ACTION *pAct ) +{ + //char szMoji[128]; + + // GAME OVER ʾ + +} + +/* £ *********************************************************************/ +ACTION *MakeBg( void ) +{ + ACTION *pAct; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_BG, NULL ); + if( pAct == NULL ) return NULL; + + /* gv */ + pAct->func = Bg; + + /* ץ饤ȷ */ + //pAct->bmpNo = 30; +// pAct->bmpNo = 44; + pAct->anim_chr_no = 9376; + /* ʾȶ */ + pAct->dispPrio = 0; + /* λ */ + pAct->x = 320; + pAct->y = 240; + + // ȡ + //pYobi->rcX = 0; + //pYobi->rcY = lpDraw->ySize; + //SetRect( &Rc[ pAct->bmpNo ], pYobi->rcX, pYobi->rcY, pYobi->rcX + lpDraw->xSize, pYobi->rcY + lpDraw->ySize ); + + return pAct; +} + +/* £DŽI *********************************************************************/ +void Bg( ACTION *pAct ) +{ + // ȡ + // ȡ + //pAct->y++; + //if( pAct->y >= 240 ) pAct->y = -240; + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); //˥`I + //StockDispBuffer( pAct->x, pAct->y+lpDraw->ySize, 0, pAct->anim_chr_no, 0 ); + //StockDispBuffer( pAct->x, pAct->y, 0, pAct->anim_chr_no, 0 ); + //StockDispBuffer( pAct->x, pAct->y+lpDraw->ySize, 0, pAct->anim_chr_no, 0); +} + + +/* *********************************************************************/ +ACTION *MakeKen( void ) +{ + ACTION *pAct; + + /* ꥹȤ˵h */ + pAct = GetAction( PRIO_BG, NULL ); + if( pAct == NULL ) return NULL; + + /* gv */ + pAct->func = Ken; + + /* ץ饤ȷ */ + pAct->bmpNo = 33; + /* ʾȶ */ + pAct->dispPrio = 100; + /* λ */ + pAct->x = 100; + pAct->y = 100; + + // ȡ + //pYobi->rcX = 0; + //pYobi->rcY = lpDraw->ySize; + //SetRect( &Rc[ pAct->bmpNo ], pYobi->rcX, pYobi->rcY, pYobi->rcX + lpDraw->xSize, pYobi->rcY + lpDraw->ySize ); + + return pAct; +} + +/* I *********************************************************************/ +void Ken( ACTION *pAct ) +{ + int anim[] = { 0,0,0,0, + 1,1,1,1, + 2,2,2,2, + 3,3,3,3, + 2,2,2,2, + 1,1,1,1 + }; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.h b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.h new file mode 100644 index 0000000..74e724f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta.h @@ -0,0 +1,10 @@ +/************************/ +/* ohta.c */ +/************************/ +#ifndef _OHTA_H_ +#define _OHTA_H_ + +/* ԙC *******************************************************************/ +ACTION *MakeJiki( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/ohta/ohta_proc.cpp b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta_proc.cpp new file mode 100644 index 0000000..a59d6c5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/ohta/ohta_proc.cpp @@ -0,0 +1,40 @@ +/************************/ +/* ohta_proc.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "ohta.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/map.h" +#include "../systeminc/menu.h" + +void OhtaTestProc( void ) +{ + switch( SubProcNo ){ + case 0: + MakeJiki(); + SubProcNo++; + InitChat(); + GetKeyInputFocus( &MyChatBuffer ); + break; + + case 1: + FlashKeyboardCursor(); + if( mouse.level < DISP_PRIO_MENU && TaskBarFlag == FALSE ){ + drawGrid(); + moveProc(); + } + + RunAction(); + StockTaskDispBuffer(); + drawMap(); + ChatProc(); + ChatBufferToFontBuffer(); + MenuProc(); + ImeProc(); + PaletteProc(); + break; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/aes.h b/石器时代8.5客户端最新源代码/石器源码/openssl/aes.h new file mode 100644 index 0000000..450f2b4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/aes.h @@ -0,0 +1,148 @@ +/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */ +/* ==================================================================== + * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + */ + +#ifndef HEADER_AES_H +#define HEADER_AES_H + +#include + +#ifdef OPENSSL_NO_AES +#error AES is disabled. +#endif + +#define AES_ENCRYPT 1 +#define AES_DECRYPT 0 + +/* Because array size can't be a const in C, the following two are macros. + Both sizes are in bytes. */ +#define AES_MAXNR 14 +#define AES_BLOCK_SIZE 16 + +#ifdef OPENSSL_FIPS +#define FIPS_AES_SIZE_T int +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* This should be a hidden type, but EVP requires that the size be known */ +struct aes_key_st { +#ifdef AES_LONG + unsigned long rd_key[4 *(AES_MAXNR + 1)]; +#else + unsigned int rd_key[4 *(AES_MAXNR + 1)]; +#endif + int rounds; +}; +typedef struct aes_key_st AES_KEY; + +const char *AES_options(void); + +int AES_set_encrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); +int AES_set_decrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); + +void AES_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); +void AES_decrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); + +void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key, const int enc); +void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, const int enc); +void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, + const int nbits,const AES_KEY *key, + unsigned char *ivec,const int enc); +void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, int *num); +void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char ivec[AES_BLOCK_SIZE], + unsigned char ecount_buf[AES_BLOCK_SIZE], + unsigned int *num); + +/* For IGE, see also http://www.links.org/files/openssl-ige.pdf */ +/* NB: the IV is _two_ blocks long */ +void AES_ige_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, const int enc); +/* NB: the IV is _four_ blocks long */ +void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + const AES_KEY *key2, const unsigned char *ivec, + const int enc); + +int AES_wrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); +int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); + +#ifdef __cplusplus +} +#endif + +#endif /* !HEADER_AES_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/applink.c b/石器时代8.5客户端最新源代码/石器源码/openssl/applink.c new file mode 100644 index 0000000..54a0a64 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/applink.c @@ -0,0 +1,94 @@ +#define APPLINK_STDIN 1 +#define APPLINK_STDOUT 2 +#define APPLINK_STDERR 3 +#define APPLINK_FPRINTF 4 +#define APPLINK_FGETS 5 +#define APPLINK_FREAD 6 +#define APPLINK_FWRITE 7 +#define APPLINK_FSETMOD 8 +#define APPLINK_FEOF 9 +#define APPLINK_FCLOSE 10 /* should not be used */ + +#define APPLINK_FOPEN 11 /* solely for completeness */ +#define APPLINK_FSEEK 12 +#define APPLINK_FTELL 13 +#define APPLINK_FFLUSH 14 +#define APPLINK_FERROR 15 +#define APPLINK_CLEARERR 16 +#define APPLINK_FILENO 17 /* to be used with below */ + +#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */ +#define APPLINK_READ 19 +#define APPLINK_WRITE 20 +#define APPLINK_LSEEK 21 +#define APPLINK_CLOSE 22 +#define APPLINK_MAX 22 /* always same as last macro */ + +#ifndef APPMACROS_ONLY +#include +#include +#include + +static void *app_stdin(void) { return stdin; } +static void *app_stdout(void) { return stdout; } +static void *app_stderr(void) { return stderr; } +static int app_feof(FILE *fp) { return feof(fp); } +static int app_ferror(FILE *fp) { return ferror(fp); } +static void app_clearerr(FILE *fp) { clearerr(fp); } +static int app_fileno(FILE *fp) { return _fileno(fp); } +static int app_fsetmod(FILE *fp,char mod) +{ return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT); } + +#ifdef __cplusplus +extern "C" { +#endif + +__declspec(dllexport) +void ** +#if defined(__BORLANDC__) +__stdcall /* __stdcall appears to be the only way to get the name + * decoration right with Borland C. Otherwise it works + * purely incidentally, as we pass no parameters. */ +#else +__cdecl +#endif +OPENSSL_Applink(void) +{ static int once=1; + static void *OPENSSL_ApplinkTable[APPLINK_MAX+1]={(void *)APPLINK_MAX}; + + if (once) + { OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin; + OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout; + OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr; + OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf; + OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets; + OPENSSL_ApplinkTable[APPLINK_FREAD] = fread; + OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite; + OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod; + OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof; + OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose; + + OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen; + OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek; + OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell; + OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush; + OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror; + OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr; + OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno; + + OPENSSL_ApplinkTable[APPLINK_OPEN] = _open; + OPENSSL_ApplinkTable[APPLINK_READ] = _read; + OPENSSL_ApplinkTable[APPLINK_WRITE] = _write; + OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek; + OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close; + + once = 0; + } + + return OPENSSL_ApplinkTable; +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/asn1.h b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1.h new file mode 100644 index 0000000..e338522 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1.h @@ -0,0 +1,1329 @@ +/* crypto/asn1/asn1.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_ASN1_H +#define HEADER_ASN1_H + +#include +#include +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#include + +#include + +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define V_ASN1_UNIVERSAL 0x00 +#define V_ASN1_APPLICATION 0x40 +#define V_ASN1_CONTEXT_SPECIFIC 0x80 +#define V_ASN1_PRIVATE 0xc0 + +#define V_ASN1_CONSTRUCTED 0x20 +#define V_ASN1_PRIMITIVE_TAG 0x1f +#define V_ASN1_PRIMATIVE_TAG 0x1f + +#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */ +#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ +#define V_ASN1_ANY -4 /* used in ASN1 template code */ + +#define V_ASN1_NEG 0x100 /* negative flag */ + +#define V_ASN1_UNDEF -1 +#define V_ASN1_EOC 0 +#define V_ASN1_BOOLEAN 1 /**/ +#define V_ASN1_INTEGER 2 +#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) +#define V_ASN1_BIT_STRING 3 +#define V_ASN1_OCTET_STRING 4 +#define V_ASN1_NULL 5 +#define V_ASN1_OBJECT 6 +#define V_ASN1_OBJECT_DESCRIPTOR 7 +#define V_ASN1_EXTERNAL 8 +#define V_ASN1_REAL 9 +#define V_ASN1_ENUMERATED 10 +#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) +#define V_ASN1_UTF8STRING 12 +#define V_ASN1_SEQUENCE 16 +#define V_ASN1_SET 17 +#define V_ASN1_NUMERICSTRING 18 /**/ +#define V_ASN1_PRINTABLESTRING 19 +#define V_ASN1_T61STRING 20 +#define V_ASN1_TELETEXSTRING 20 /* alias */ +#define V_ASN1_VIDEOTEXSTRING 21 /**/ +#define V_ASN1_IA5STRING 22 +#define V_ASN1_UTCTIME 23 +#define V_ASN1_GENERALIZEDTIME 24 /**/ +#define V_ASN1_GRAPHICSTRING 25 /**/ +#define V_ASN1_ISO64STRING 26 /**/ +#define V_ASN1_VISIBLESTRING 26 /* alias */ +#define V_ASN1_GENERALSTRING 27 /**/ +#define V_ASN1_UNIVERSALSTRING 28 /**/ +#define V_ASN1_BMPSTRING 30 + +/* For use with d2i_ASN1_type_bytes() */ +#define B_ASN1_NUMERICSTRING 0x0001 +#define B_ASN1_PRINTABLESTRING 0x0002 +#define B_ASN1_T61STRING 0x0004 +#define B_ASN1_TELETEXSTRING 0x0004 +#define B_ASN1_VIDEOTEXSTRING 0x0008 +#define B_ASN1_IA5STRING 0x0010 +#define B_ASN1_GRAPHICSTRING 0x0020 +#define B_ASN1_ISO64STRING 0x0040 +#define B_ASN1_VISIBLESTRING 0x0040 +#define B_ASN1_GENERALSTRING 0x0080 +#define B_ASN1_UNIVERSALSTRING 0x0100 +#define B_ASN1_OCTET_STRING 0x0200 +#define B_ASN1_BIT_STRING 0x0400 +#define B_ASN1_BMPSTRING 0x0800 +#define B_ASN1_UNKNOWN 0x1000 +#define B_ASN1_UTF8STRING 0x2000 +#define B_ASN1_UTCTIME 0x4000 +#define B_ASN1_GENERALIZEDTIME 0x8000 +#define B_ASN1_SEQUENCE 0x10000 + +/* For use with ASN1_mbstring_copy() */ +#define MBSTRING_FLAG 0x1000 +#define MBSTRING_UTF8 (MBSTRING_FLAG) +#define MBSTRING_ASC (MBSTRING_FLAG|1) +#define MBSTRING_BMP (MBSTRING_FLAG|2) +#define MBSTRING_UNIV (MBSTRING_FLAG|4) + +#define SMIME_OLDMIME 0x400 +#define SMIME_CRLFEOL 0x800 +#define SMIME_STREAM 0x1000 + +struct X509_algor_st; +DECLARE_STACK_OF(X509_ALGOR) + +#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */ +#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */ + +/* We MUST make sure that, except for constness, asn1_ctx_st and + asn1_const_ctx are exactly the same. Fortunately, as soon as + the old ASN1 parsing macros are gone, we can throw this away + as well... */ +typedef struct asn1_ctx_st + { + unsigned char *p;/* work char pointer */ + int eos; /* end of sequence read for indefinite encoding */ + int error; /* error code to use when returning an error */ + int inf; /* constructed if 0x20, indefinite is 0x21 */ + int tag; /* tag from last 'get object' */ + int xclass; /* class from last 'get object' */ + long slen; /* length of last 'get object' */ + unsigned char *max; /* largest value of p allowed */ + unsigned char *q;/* temporary variable */ + unsigned char **pp;/* variable */ + int line; /* used in error processing */ + } ASN1_CTX; + +typedef struct asn1_const_ctx_st + { + const unsigned char *p;/* work char pointer */ + int eos; /* end of sequence read for indefinite encoding */ + int error; /* error code to use when returning an error */ + int inf; /* constructed if 0x20, indefinite is 0x21 */ + int tag; /* tag from last 'get object' */ + int xclass; /* class from last 'get object' */ + long slen; /* length of last 'get object' */ + const unsigned char *max; /* largest value of p allowed */ + const unsigned char *q;/* temporary variable */ + const unsigned char **pp;/* variable */ + int line; /* used in error processing */ + } ASN1_const_CTX; + +/* These are used internally in the ASN1_OBJECT to keep track of + * whether the names and data need to be free()ed */ +#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */ +#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */ +#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */ +#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ +typedef struct asn1_object_st + { + const char *sn,*ln; + int nid; + int length; + unsigned char *data; + int flags; /* Should we free this one */ + } ASN1_OBJECT; + +#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ +/* This indicates that the ASN1_STRING is not a real value but just a place + * holder for the location where indefinite length constructed data should + * be inserted in the memory buffer + */ +#define ASN1_STRING_FLAG_NDEF 0x010 + +/* This flag is used by the CMS code to indicate that a string is not + * complete and is a place holder for content when it had all been + * accessed. The flag will be reset when content has been written to it. + */ +#define ASN1_STRING_FLAG_CONT 0x020 + +/* This is the base type that holds just about everything :-) */ +typedef struct asn1_string_st + { + int length; + int type; + unsigned char *data; + /* The value of the following field depends on the type being + * held. It is mostly being used for BIT_STRING so if the + * input data has a non-zero 'unused bits' value, it will be + * handled correctly */ + long flags; + } ASN1_STRING; + +/* ASN1_ENCODING structure: this is used to save the received + * encoding of an ASN1 type. This is useful to get round + * problems with invalid encodings which can break signatures. + */ + +typedef struct ASN1_ENCODING_st + { + unsigned char *enc; /* DER encoding */ + long len; /* Length of encoding */ + int modified; /* set to 1 if 'enc' is invalid */ + } ASN1_ENCODING; + +/* Used with ASN1 LONG type: if a long is set to this it is omitted */ +#define ASN1_LONG_UNDEF 0x7fffffffL + +#define STABLE_FLAGS_MALLOC 0x01 +#define STABLE_NO_MASK 0x02 +#define DIRSTRING_TYPE \ + (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) +#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) + +typedef struct asn1_string_table_st { + int nid; + long minsize; + long maxsize; + unsigned long mask; + unsigned long flags; +} ASN1_STRING_TABLE; + +DECLARE_STACK_OF(ASN1_STRING_TABLE) + +/* size limits: this stuff is taken straight from RFC2459 */ + +#define ub_name 32768 +#define ub_common_name 64 +#define ub_locality_name 128 +#define ub_state_name 128 +#define ub_organization_name 64 +#define ub_organization_unit_name 64 +#define ub_title 64 +#define ub_email_address 128 + +/* Declarations for template structures: for full definitions + * see asn1t.h + */ +typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; +typedef struct ASN1_ITEM_st ASN1_ITEM; +typedef struct ASN1_TLC_st ASN1_TLC; +/* This is just an opaque pointer */ +typedef struct ASN1_VALUE_st ASN1_VALUE; + +/* Declare ASN1 functions: the implement macro in in asn1t.h */ + +#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) + +#define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type) + +#define DECLARE_ASN1_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) + +#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) + +#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(itname) + +#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(const type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(name) + +#define DECLARE_ASN1_NDEF_FUNCTION(name) \ + int i2d_##name##_NDEF(name *a, unsigned char **out); + +#define DECLARE_ASN1_FUNCTIONS_const(name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) + +#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + type *name##_new(void); \ + void name##_free(type *a); + +#define D2I_OF(type) type *(*)(type **,const unsigned char **,long) +#define I2D_OF(type) int (*)(type *,unsigned char **) +#define I2D_OF_const(type) int (*)(const type *,unsigned char **) + +#define CHECKED_D2I_OF(type, d2i) \ + ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0))) +#define CHECKED_I2D_OF(type, i2d) \ + ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0))) +#define CHECKED_NEW_OF(type, xnew) \ + ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0))) +#define CHECKED_PTR_OF(type, p) \ + ((void*) (1 ? p : (type*)0)) +#define CHECKED_PPTR_OF(type, p) \ + ((void**) (1 ? p : (type**)0)) + +#define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long) +#define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **) +#define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type) + +TYPEDEF_D2I2D_OF(void); + +/* The following macros and typedefs allow an ASN1_ITEM + * to be embedded in a structure and referenced. Since + * the ASN1_ITEM pointers need to be globally accessible + * (possibly from shared libraries) they may exist in + * different forms. On platforms that support it the + * ASN1_ITEM structure itself will be globally exported. + * Other platforms will export a function that returns + * an ASN1_ITEM pointer. + * + * To handle both cases transparently the macros below + * should be used instead of hard coding an ASN1_ITEM + * pointer in a structure. + * + * The structure will look like this: + * + * typedef struct SOMETHING_st { + * ... + * ASN1_ITEM_EXP *iptr; + * ... + * } SOMETHING; + * + * It would be initialised as e.g.: + * + * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; + * + * and the actual pointer extracted with: + * + * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); + * + * Finally an ASN1_ITEM pointer can be extracted from an + * appropriate reference with: ASN1_ITEM_rptr(X509). This + * would be used when a function takes an ASN1_ITEM * argument. + * + */ + +#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM ASN1_ITEM_EXP; + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +#define ASN1_ITEM_ptr(iptr) (iptr) + +/* Macro to include ASN1_ITEM pointer from base type */ +#define ASN1_ITEM_ref(iptr) (&(iptr##_it)) + +#define ASN1_ITEM_rptr(ref) (&(ref##_it)) + +#define DECLARE_ASN1_ITEM(name) \ + OPENSSL_EXTERN const ASN1_ITEM name##_it; + +#else + +/* Platforms that can't easily handle shared global variables are declared + * as functions returning ASN1_ITEM pointers. + */ + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM * ASN1_ITEM_EXP(void); + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +#define ASN1_ITEM_ptr(iptr) (iptr()) + +/* Macro to include ASN1_ITEM pointer from base type */ +#define ASN1_ITEM_ref(iptr) (iptr##_it) + +#define ASN1_ITEM_rptr(ref) (ref##_it()) + +#define DECLARE_ASN1_ITEM(name) \ + const ASN1_ITEM * name##_it(void); + +#endif + +/* Parameters used by ASN1_STRING_print_ex() */ + +/* These determine which characters to escape: + * RFC2253 special characters, control characters and + * MSB set characters + */ + +#define ASN1_STRFLGS_ESC_2253 1 +#define ASN1_STRFLGS_ESC_CTRL 2 +#define ASN1_STRFLGS_ESC_MSB 4 + + +/* This flag determines how we do escaping: normally + * RC2253 backslash only, set this to use backslash and + * quote. + */ + +#define ASN1_STRFLGS_ESC_QUOTE 8 + + +/* These three flags are internal use only. */ + +/* Character is a valid PrintableString character */ +#define CHARTYPE_PRINTABLESTRING 0x10 +/* Character needs escaping if it is the first character */ +#define CHARTYPE_FIRST_ESC_2253 0x20 +/* Character needs escaping if it is the last character */ +#define CHARTYPE_LAST_ESC_2253 0x40 + +/* NB the internal flags are safely reused below by flags + * handled at the top level. + */ + +/* If this is set we convert all character strings + * to UTF8 first + */ + +#define ASN1_STRFLGS_UTF8_CONVERT 0x10 + +/* If this is set we don't attempt to interpret content: + * just assume all strings are 1 byte per character. This + * will produce some pretty odd looking output! + */ + +#define ASN1_STRFLGS_IGNORE_TYPE 0x20 + +/* If this is set we include the string type in the output */ +#define ASN1_STRFLGS_SHOW_TYPE 0x40 + +/* This determines which strings to display and which to + * 'dump' (hex dump of content octets or DER encoding). We can + * only dump non character strings or everything. If we + * don't dump 'unknown' they are interpreted as character + * strings with 1 octet per character and are subject to + * the usual escaping options. + */ + +#define ASN1_STRFLGS_DUMP_ALL 0x80 +#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 + +/* These determine what 'dumping' does, we can dump the + * content octets or the DER encoding: both use the + * RFC2253 #XXXXX notation. + */ + +#define ASN1_STRFLGS_DUMP_DER 0x200 + +/* All the string flags consistent with RFC2253, + * escaping control characters isn't essential in + * RFC2253 but it is advisable anyway. + */ + +#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ + ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + ASN1_STRFLGS_UTF8_CONVERT | \ + ASN1_STRFLGS_DUMP_UNKNOWN | \ + ASN1_STRFLGS_DUMP_DER) + +DECLARE_STACK_OF(ASN1_INTEGER) +DECLARE_ASN1_SET_OF(ASN1_INTEGER) + +DECLARE_STACK_OF(ASN1_GENERALSTRING) + +typedef struct asn1_type_st + { + int type; + union { + char *ptr; + ASN1_BOOLEAN boolean; + ASN1_STRING * asn1_string; + ASN1_OBJECT * object; + ASN1_INTEGER * integer; + ASN1_ENUMERATED * enumerated; + ASN1_BIT_STRING * bit_string; + ASN1_OCTET_STRING * octet_string; + ASN1_PRINTABLESTRING * printablestring; + ASN1_T61STRING * t61string; + ASN1_IA5STRING * ia5string; + ASN1_GENERALSTRING * generalstring; + ASN1_BMPSTRING * bmpstring; + ASN1_UNIVERSALSTRING * universalstring; + ASN1_UTCTIME * utctime; + ASN1_GENERALIZEDTIME * generalizedtime; + ASN1_VISIBLESTRING * visiblestring; + ASN1_UTF8STRING * utf8string; + /* set and sequence are left complete and still + * contain the set or sequence bytes */ + ASN1_STRING * set; + ASN1_STRING * sequence; + ASN1_VALUE * asn1_value; + } value; + } ASN1_TYPE; + +DECLARE_STACK_OF(ASN1_TYPE) +DECLARE_ASN1_SET_OF(ASN1_TYPE) + +typedef struct asn1_method_st + { + i2d_of_void *i2d; + d2i_of_void *d2i; + void *(*create)(void); + void (*destroy)(void *); + } ASN1_METHOD; + +/* This is used when parsing some Netscape objects */ +typedef struct asn1_header_st + { + ASN1_OCTET_STRING *header; + void *data; + ASN1_METHOD *meth; + } ASN1_HEADER; + +/* This is used to contain a list of bit names */ +typedef struct BIT_STRING_BITNAME_st { + int bitnum; + const char *lname; + const char *sname; +} BIT_STRING_BITNAME; + + +#define M_ASN1_STRING_length(x) ((x)->length) +#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n)) +#define M_ASN1_STRING_type(x) ((x)->type) +#define M_ASN1_STRING_data(x) ((x)->data) + +/* Macros for string operations */ +#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\ + ASN1_STRING_type_new(V_ASN1_BIT_STRING) +#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\ + ASN1_STRING_dup((ASN1_STRING *)a) +#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) +#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) + +#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\ + ASN1_STRING_type_new(V_ASN1_INTEGER) +#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a) +#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) + +#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ + ASN1_STRING_type_new(V_ASN1_ENUMERATED) +#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) +#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) + +#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ + ASN1_STRING_type_new(V_ASN1_OCTET_STRING) +#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\ + ASN1_STRING_dup((ASN1_STRING *)a) +#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) +#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) +#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b) +#define M_i2d_ASN1_OCTET_STRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\ + V_ASN1_UNIVERSAL) + +#define B_ASN1_TIME \ + B_ASN1_UTCTIME | \ + B_ASN1_GENERALIZEDTIME + +#define B_ASN1_PRINTABLE \ + B_ASN1_NUMERICSTRING| \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_T61STRING| \ + B_ASN1_IA5STRING| \ + B_ASN1_BIT_STRING| \ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING|\ + B_ASN1_SEQUENCE|\ + B_ASN1_UNKNOWN + +#define B_ASN1_DIRECTORYSTRING \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_TELETEXSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_UTF8STRING + +#define B_ASN1_DISPLAYTEXT \ + B_ASN1_IA5STRING| \ + B_ASN1_VISIBLESTRING| \ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING + +#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING) +#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ + pp,a->type,V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_PRINTABLE(a,pp,l) \ + d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ + B_ASN1_PRINTABLE) + +#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) +#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ + pp,a->type,V_ASN1_UNIVERSAL) +#define M_d2i_DIRECTORYSTRING(a,pp,l) \ + d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ + B_ASN1_DIRECTORYSTRING) + +#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) +#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ + pp,a->type,V_ASN1_UNIVERSAL) +#define M_d2i_DISPLAYTEXT(a,pp,l) \ + d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ + B_ASN1_DISPLAYTEXT) + +#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\ + ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) +#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \ + (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING) + +#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\ + ASN1_STRING_type_new(V_ASN1_T61STRING) +#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_T61STRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_T61STRING(a,pp,l) \ + (ASN1_T61STRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING) + +#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ + ASN1_STRING_type_new(V_ASN1_IA5STRING) +#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_IA5STRING_dup(a) \ + (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a) +#define M_i2d_ASN1_IA5STRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_IA5STRING(a,pp,l) \ + (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\ + B_ASN1_IA5STRING) + +#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\ + ASN1_STRING_type_new(V_ASN1_UTCTIME) +#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a) + +#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ + ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) +#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\ + (ASN1_STRING *)a) + +#define M_ASN1_TIME_new() (ASN1_TIME *)\ + ASN1_STRING_type_new(V_ASN1_UTCTIME) +#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a) + +#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ + ASN1_STRING_type_new(V_ASN1_GENERALSTRING) +#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_GENERALSTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \ + (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING) + +#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\ + ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING) +#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \ + (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING) + +#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\ + ASN1_STRING_type_new(V_ASN1_BMPSTRING) +#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_BMPSTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_BMPSTRING(a,pp,l) \ + (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) + +#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\ + ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) +#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_VISIBLESTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \ + (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING) + +#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\ + ASN1_STRING_type_new(V_ASN1_UTF8STRING) +#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_UTF8STRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_UTF8STRING(a,pp,l) \ + (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) + + /* for the is_set parameter to i2d_ASN1_SET */ +#define IS_SEQUENCE 0 +#define IS_SET 1 + +DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) + +int ASN1_TYPE_get(ASN1_TYPE *a); +void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); +int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); + +ASN1_OBJECT * ASN1_OBJECT_new(void ); +void ASN1_OBJECT_free(ASN1_OBJECT *a); +int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); +ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, + long length); +ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, + long length); + +DECLARE_ASN1_ITEM(ASN1_OBJECT) + +DECLARE_STACK_OF(ASN1_OBJECT) +DECLARE_ASN1_SET_OF(ASN1_OBJECT) + +ASN1_STRING * ASN1_STRING_new(void); +void ASN1_STRING_free(ASN1_STRING *a); +ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); +ASN1_STRING * ASN1_STRING_type_new(int type ); +int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); + /* Since this is used to store all sorts of things, via macros, for now, make + its data void * */ +int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); +void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); +int ASN1_STRING_length(ASN1_STRING *x); +void ASN1_STRING_length_set(ASN1_STRING *x, int n); +int ASN1_STRING_type(ASN1_STRING *x); +unsigned char * ASN1_STRING_data(ASN1_STRING *x); + +DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) +int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); +ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp, + long length); +int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, + int length ); +int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); +int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n); + +#ifndef OPENSSL_NO_BIO +int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, + BIT_STRING_BITNAME *tbl, int indent); +#endif +int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl); +int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, + BIT_STRING_BITNAME *tbl); + +int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); +int d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length); + +DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) +int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); +ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp, + long length); +ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp, + long length); +ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x); +int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y); + +DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) + +int ASN1_UTCTIME_check(ASN1_UTCTIME *a); +ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); +int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); +int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); +#if 0 +time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s); +#endif + +int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); +int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); + +DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) +ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a); +int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b); +int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len); + +DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_NULL) +DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) + +int UTF8_getc(const unsigned char *str, int len, unsigned long *val); +int UTF8_putc(unsigned char *str, int len, unsigned long value); + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) +DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_TIME) + +DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF) + +ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); +int ASN1_TIME_check(ASN1_TIME *t); +ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); + +int i2d_ASN1_SET(STACK *a, unsigned char **pp, + i2d_of_void *i2d, int ex_tag, int ex_class, int is_set); +STACK * d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, + d2i_of_void *d2i, void (*free_func)(void *), + int ex_tag, int ex_class); + +#ifndef OPENSSL_NO_BIO +int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); +int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); +int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a); +int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size); +int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); +int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); +int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); +#endif +int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); + +int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num); +ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, + const char *sn, const char *ln); + +int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); +long ASN1_INTEGER_get(ASN1_INTEGER *a); +ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); +BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); + +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); +long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai); +BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn); + +/* General */ +/* given a string, return the correct type, max is the maximum length */ +int ASN1_PRINTABLE_type(const unsigned char *s, int max); + +int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass); +ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, + long length, int Ptag, int Pclass); +unsigned long ASN1_tag2bit(int tag); +/* type is one or more of the B_ASN1_ values. */ +ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,const unsigned char **pp, + long length,int type); + +/* PARSING */ +int asn1_Finish(ASN1_CTX *c); +int asn1_const_Finish(ASN1_const_CTX *c); + +/* SPECIALS */ +int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, + int *pclass, long omax); +int ASN1_check_infinite_end(unsigned char **p,long len); +int ASN1_const_check_infinite_end(const unsigned char **p,long len); +void ASN1_put_object(unsigned char **pp, int constructed, int length, + int tag, int xclass); +int ASN1_put_eoc(unsigned char **pp); +int ASN1_object_size(int constructed, int length, int tag); + +/* Used to implement other functions */ +void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x); + +#define ASN1_dup_of(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(type, x))) + +#define ASN1_dup_of_const(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(const type, x))) + +void *ASN1_item_dup(const ASN1_ITEM *it, void *x); + +/* ASN1 alloc/free macros for when a type is only used internally */ + +#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) +#define M_ASN1_free_of(x, type) \ + ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) + +#ifndef OPENSSL_NO_FP_API +void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); + +#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); +int ASN1_i2d_fp(i2d_of_void *i2d,FILE *out,void *x); + +#define ASN1_i2d_fp_of(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +#define ASN1_i2d_fp_of_const(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); +int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags); +#endif + +int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in); + +#ifndef OPENSSL_NO_BIO +void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x); + +#define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); +int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, unsigned char *x); + +#define ASN1_i2d_bio_of(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +#define ASN1_i2d_bio_of_const(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); +int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); +int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a); +int ASN1_TIME_print(BIO *fp,ASN1_TIME *a); +int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); +int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags); +int ASN1_parse(BIO *bp,const unsigned char *pp,long len,int indent); +int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long len,int indent,int dump); +#endif +const char *ASN1_tag2str(int tag); + +/* Used to load and write netscape format cert/key */ +int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); +ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,const unsigned char **pp, long length); +ASN1_HEADER *ASN1_HEADER_new(void ); +void ASN1_HEADER_free(ASN1_HEADER *a); + +int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); + +/* Not used that much at this point, except for the first two */ +ASN1_METHOD *X509_asn1_meth(void); +ASN1_METHOD *RSAPrivateKey_asn1_meth(void); +ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void); +ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void); + +int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, + unsigned char *data, int len); +int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, + unsigned char *data, int max_len); +int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, + unsigned char *data, int len); +int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, + unsigned char *data, int max_len); + +STACK *ASN1_seq_unpack(const unsigned char *buf, int len, + d2i_of_void *d2i, void (*free_func)(void *)); +unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, + unsigned char **buf, int *len ); +void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i); +void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); +ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, + ASN1_OCTET_STRING **oct); + +#define ASN1_pack_string_of(type,obj,i2d,oct) \ + (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \ + CHECKED_I2D_OF(type, i2d), \ + oct)) + +ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); + +void ASN1_STRING_set_default_mask(unsigned long mask); +int ASN1_STRING_set_default_mask_asc(char *p); +unsigned long ASN1_STRING_get_default_mask(void); +int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask); +int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask, + long minsize, long maxsize); + +ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, + const unsigned char *in, int inlen, int inform, int nid); +ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); +int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); +void ASN1_STRING_TABLE_cleanup(void); + +/* ASN1 template functions */ + +/* Old API compatible functions */ +ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); +void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); +ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it); +int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); +int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); + +void ASN1_add_oid_module(void); + +ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf); +ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf); + +typedef int asn1_output_data_fn(BIO *out, BIO *data, ASN1_VALUE *val, int flags, + const ASN1_ITEM *it); + +int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, + int ctype_nid, int econt_nid, + STACK_OF(X509_ALGOR) *mdalgs, + asn1_output_data_fn *data_fn, + const ASN1_ITEM *it); +ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_ASN1_strings(void); + +/* Error codes for the ASN1 functions. */ + +/* Function codes. */ +#define ASN1_F_A2D_ASN1_OBJECT 100 +#define ASN1_F_A2I_ASN1_ENUMERATED 101 +#define ASN1_F_A2I_ASN1_INTEGER 102 +#define ASN1_F_A2I_ASN1_STRING 103 +#define ASN1_F_APPEND_EXP 176 +#define ASN1_F_ASN1_BIT_STRING_SET_BIT 183 +#define ASN1_F_ASN1_CB 177 +#define ASN1_F_ASN1_CHECK_TLEN 104 +#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105 +#define ASN1_F_ASN1_COLLECT 106 +#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 +#define ASN1_F_ASN1_D2I_FP 109 +#define ASN1_F_ASN1_D2I_READ_BIO 107 +#define ASN1_F_ASN1_DIGEST 184 +#define ASN1_F_ASN1_DO_ADB 110 +#define ASN1_F_ASN1_DUP 111 +#define ASN1_F_ASN1_ENUMERATED_SET 112 +#define ASN1_F_ASN1_ENUMERATED_TO_BN 113 +#define ASN1_F_ASN1_EX_C2I 204 +#define ASN1_F_ASN1_FIND_END 190 +#define ASN1_F_ASN1_GENERALIZEDTIME_SET 185 +#define ASN1_F_ASN1_GENERATE_V3 178 +#define ASN1_F_ASN1_GET_OBJECT 114 +#define ASN1_F_ASN1_HEADER_NEW 115 +#define ASN1_F_ASN1_I2D_BIO 116 +#define ASN1_F_ASN1_I2D_FP 117 +#define ASN1_F_ASN1_INTEGER_SET 118 +#define ASN1_F_ASN1_INTEGER_TO_BN 119 +#define ASN1_F_ASN1_ITEM_D2I_FP 206 +#define ASN1_F_ASN1_ITEM_DUP 191 +#define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW 121 +#define ASN1_F_ASN1_ITEM_EX_D2I 120 +#define ASN1_F_ASN1_ITEM_I2D_BIO 192 +#define ASN1_F_ASN1_ITEM_I2D_FP 193 +#define ASN1_F_ASN1_ITEM_PACK 198 +#define ASN1_F_ASN1_ITEM_SIGN 195 +#define ASN1_F_ASN1_ITEM_UNPACK 199 +#define ASN1_F_ASN1_ITEM_VERIFY 197 +#define ASN1_F_ASN1_MBSTRING_NCOPY 122 +#define ASN1_F_ASN1_OBJECT_NEW 123 +#define ASN1_F_ASN1_OUTPUT_DATA 207 +#define ASN1_F_ASN1_PACK_STRING 124 +#define ASN1_F_ASN1_PCTX_NEW 205 +#define ASN1_F_ASN1_PKCS5_PBE_SET 125 +#define ASN1_F_ASN1_SEQ_PACK 126 +#define ASN1_F_ASN1_SEQ_UNPACK 127 +#define ASN1_F_ASN1_SIGN 128 +#define ASN1_F_ASN1_STR2TYPE 179 +#define ASN1_F_ASN1_STRING_SET 186 +#define ASN1_F_ASN1_STRING_TABLE_ADD 129 +#define ASN1_F_ASN1_STRING_TYPE_NEW 130 +#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 +#define ASN1_F_ASN1_TEMPLATE_NEW 133 +#define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I 131 +#define ASN1_F_ASN1_TIME_SET 175 +#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 +#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 +#define ASN1_F_ASN1_UNPACK_STRING 136 +#define ASN1_F_ASN1_UTCTIME_SET 187 +#define ASN1_F_ASN1_VERIFY 137 +#define ASN1_F_B64_READ_ASN1 208 +#define ASN1_F_B64_WRITE_ASN1 209 +#define ASN1_F_BITSTR_CB 180 +#define ASN1_F_BN_TO_ASN1_ENUMERATED 138 +#define ASN1_F_BN_TO_ASN1_INTEGER 139 +#define ASN1_F_C2I_ASN1_BIT_STRING 189 +#define ASN1_F_C2I_ASN1_INTEGER 194 +#define ASN1_F_C2I_ASN1_OBJECT 196 +#define ASN1_F_COLLECT_DATA 140 +#define ASN1_F_D2I_ASN1_BIT_STRING 141 +#define ASN1_F_D2I_ASN1_BOOLEAN 142 +#define ASN1_F_D2I_ASN1_BYTES 143 +#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144 +#define ASN1_F_D2I_ASN1_HEADER 145 +#define ASN1_F_D2I_ASN1_INTEGER 146 +#define ASN1_F_D2I_ASN1_OBJECT 147 +#define ASN1_F_D2I_ASN1_SET 148 +#define ASN1_F_D2I_ASN1_TYPE_BYTES 149 +#define ASN1_F_D2I_ASN1_UINTEGER 150 +#define ASN1_F_D2I_ASN1_UTCTIME 151 +#define ASN1_F_D2I_NETSCAPE_RSA 152 +#define ASN1_F_D2I_NETSCAPE_RSA_2 153 +#define ASN1_F_D2I_PRIVATEKEY 154 +#define ASN1_F_D2I_PUBLICKEY 155 +#define ASN1_F_D2I_RSA_NET 200 +#define ASN1_F_D2I_RSA_NET_2 201 +#define ASN1_F_D2I_X509 156 +#define ASN1_F_D2I_X509_CINF 157 +#define ASN1_F_D2I_X509_PKEY 159 +#define ASN1_F_I2D_ASN1_SET 188 +#define ASN1_F_I2D_ASN1_TIME 160 +#define ASN1_F_I2D_DSA_PUBKEY 161 +#define ASN1_F_I2D_EC_PUBKEY 181 +#define ASN1_F_I2D_PRIVATEKEY 163 +#define ASN1_F_I2D_PUBLICKEY 164 +#define ASN1_F_I2D_RSA_NET 162 +#define ASN1_F_I2D_RSA_PUBKEY 165 +#define ASN1_F_LONG_C2I 166 +#define ASN1_F_OID_MODULE_INIT 174 +#define ASN1_F_PARSE_TAGGING 182 +#define ASN1_F_PKCS5_PBE2_SET 167 +#define ASN1_F_PKCS5_PBE_SET 202 +#define ASN1_F_SMIME_READ_ASN1 210 +#define ASN1_F_SMIME_TEXT 211 +#define ASN1_F_X509_CINF_NEW 168 +#define ASN1_F_X509_CRL_ADD0_REVOKED 169 +#define ASN1_F_X509_INFO_NEW 170 +#define ASN1_F_X509_NAME_ENCODE 203 +#define ASN1_F_X509_NAME_EX_D2I 158 +#define ASN1_F_X509_NAME_EX_NEW 171 +#define ASN1_F_X509_NEW 172 +#define ASN1_F_X509_PKEY_NEW 173 + +/* Reason codes. */ +#define ASN1_R_ADDING_OBJECT 171 +#define ASN1_R_ASN1_PARSE_ERROR 198 +#define ASN1_R_ASN1_SIG_PARSE_ERROR 199 +#define ASN1_R_AUX_ERROR 100 +#define ASN1_R_BAD_CLASS 101 +#define ASN1_R_BAD_OBJECT_HEADER 102 +#define ASN1_R_BAD_PASSWORD_READ 103 +#define ASN1_R_BAD_TAG 104 +#define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 210 +#define ASN1_R_BN_LIB 105 +#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 +#define ASN1_R_BUFFER_TOO_SMALL 107 +#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108 +#define ASN1_R_DATA_IS_WRONG 109 +#define ASN1_R_DECODE_ERROR 110 +#define ASN1_R_DECODING_ERROR 111 +#define ASN1_R_DEPTH_EXCEEDED 174 +#define ASN1_R_ENCODE_ERROR 112 +#define ASN1_R_ERROR_GETTING_TIME 173 +#define ASN1_R_ERROR_LOADING_SECTION 172 +#define ASN1_R_ERROR_PARSING_SET_ELEMENT 113 +#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 +#define ASN1_R_EXPECTING_AN_INTEGER 115 +#define ASN1_R_EXPECTING_AN_OBJECT 116 +#define ASN1_R_EXPECTING_A_BOOLEAN 117 +#define ASN1_R_EXPECTING_A_TIME 118 +#define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 +#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 +#define ASN1_R_FIELD_MISSING 121 +#define ASN1_R_FIRST_NUM_TOO_LARGE 122 +#define ASN1_R_HEADER_TOO_LONG 123 +#define ASN1_R_ILLEGAL_BITSTRING_FORMAT 175 +#define ASN1_R_ILLEGAL_BOOLEAN 176 +#define ASN1_R_ILLEGAL_CHARACTERS 124 +#define ASN1_R_ILLEGAL_FORMAT 177 +#define ASN1_R_ILLEGAL_HEX 178 +#define ASN1_R_ILLEGAL_IMPLICIT_TAG 179 +#define ASN1_R_ILLEGAL_INTEGER 180 +#define ASN1_R_ILLEGAL_NESTED_TAGGING 181 +#define ASN1_R_ILLEGAL_NULL 125 +#define ASN1_R_ILLEGAL_NULL_VALUE 182 +#define ASN1_R_ILLEGAL_OBJECT 183 +#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 +#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 +#define ASN1_R_ILLEGAL_TAGGED_ANY 127 +#define ASN1_R_ILLEGAL_TIME_VALUE 184 +#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185 +#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 +#define ASN1_R_INVALID_BMPSTRING_LENGTH 129 +#define ASN1_R_INVALID_DIGIT 130 +#define ASN1_R_INVALID_MIME_TYPE 200 +#define ASN1_R_INVALID_MODIFIER 186 +#define ASN1_R_INVALID_NUMBER 187 +#define ASN1_R_INVALID_SEPARATOR 131 +#define ASN1_R_INVALID_TIME_FORMAT 132 +#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 +#define ASN1_R_INVALID_UTF8STRING 134 +#define ASN1_R_IV_TOO_LARGE 135 +#define ASN1_R_LENGTH_ERROR 136 +#define ASN1_R_LIST_ERROR 188 +#define ASN1_R_MIME_NO_CONTENT_TYPE 201 +#define ASN1_R_MIME_PARSE_ERROR 202 +#define ASN1_R_MIME_SIG_PARSE_ERROR 203 +#define ASN1_R_MISSING_EOC 137 +#define ASN1_R_MISSING_SECOND_NUMBER 138 +#define ASN1_R_MISSING_VALUE 189 +#define ASN1_R_MSTRING_NOT_UNIVERSAL 139 +#define ASN1_R_MSTRING_WRONG_TAG 140 +#define ASN1_R_NESTED_ASN1_STRING 197 +#define ASN1_R_NON_HEX_CHARACTERS 141 +#define ASN1_R_NOT_ASCII_FORMAT 190 +#define ASN1_R_NOT_ENOUGH_DATA 142 +#define ASN1_R_NO_CONTENT_TYPE 204 +#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 +#define ASN1_R_NO_MULTIPART_BODY_FAILURE 205 +#define ASN1_R_NO_MULTIPART_BOUNDARY 206 +#define ASN1_R_NO_SIG_CONTENT_TYPE 207 +#define ASN1_R_NULL_IS_WRONG_LENGTH 144 +#define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191 +#define ASN1_R_ODD_NUMBER_OF_CHARS 145 +#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146 +#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 +#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 +#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 +#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192 +#define ASN1_R_SHORT_LINE 150 +#define ASN1_R_SIG_INVALID_MIME_TYPE 208 +#define ASN1_R_STREAMING_NOT_SUPPORTED 209 +#define ASN1_R_STRING_TOO_LONG 151 +#define ASN1_R_STRING_TOO_SHORT 152 +#define ASN1_R_TAG_VALUE_TOO_HIGH 153 +#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 +#define ASN1_R_TIME_NOT_ASCII_FORMAT 193 +#define ASN1_R_TOO_LONG 155 +#define ASN1_R_TYPE_NOT_CONSTRUCTED 156 +#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157 +#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158 +#define ASN1_R_UNEXPECTED_EOC 159 +#define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH 211 +#define ASN1_R_UNKNOWN_FORMAT 160 +#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 +#define ASN1_R_UNKNOWN_OBJECT_TYPE 162 +#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 +#define ASN1_R_UNKNOWN_TAG 194 +#define ASN1_R_UNKOWN_FORMAT 195 +#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 +#define ASN1_R_UNSUPPORTED_CIPHER 165 +#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166 +#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 +#define ASN1_R_UNSUPPORTED_TYPE 196 +#define ASN1_R_WRONG_TAG 168 +#define ASN1_R_WRONG_TYPE 169 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/asn1_mac.h b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1_mac.h new file mode 100644 index 0000000..d958ca6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1_mac.h @@ -0,0 +1,571 @@ +/* crypto/asn1/asn1_mac.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_ASN1_MAC_H +#define HEADER_ASN1_MAC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ASN1_MAC_ERR_LIB +#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 +#endif + +#define ASN1_MAC_H_err(f,r,line) \ + ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) + +#define M_ASN1_D2I_vars(a,type,func) \ + ASN1_const_CTX c; \ + type ret=NULL; \ + \ + c.pp=(const unsigned char **)pp; \ + c.q= *(const unsigned char **)pp; \ + c.error=ERR_R_NESTED_ASN1_ERROR; \ + if ((a == NULL) || ((*a) == NULL)) \ + { if ((ret=(type)func()) == NULL) \ + { c.line=__LINE__; goto err; } } \ + else ret=(*a); + +#define M_ASN1_D2I_Init() \ + c.p= *(const unsigned char **)pp; \ + c.max=(length == 0)?0:(c.p+length); + +#define M_ASN1_D2I_Finish_2(a) \ + if (!asn1_const_Finish(&c)) \ + { c.line=__LINE__; goto err; } \ + *(const unsigned char **)pp=c.p; \ + if (a != NULL) (*a)=ret; \ + return(ret); + +#define M_ASN1_D2I_Finish(a,func,e) \ + M_ASN1_D2I_Finish_2(a); \ +err:\ + ASN1_MAC_H_err((e),c.error,c.line); \ + asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ + if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ + return(NULL) + +#define M_ASN1_D2I_start_sequence() \ + if (!asn1_GetSequence(&c,&length)) \ + { c.line=__LINE__; goto err; } +/* Begin reading ASN1 without a surrounding sequence */ +#define M_ASN1_D2I_begin() \ + c.slen = length; + +/* End reading ASN1 with no check on length */ +#define M_ASN1_D2I_Finish_nolen(a, func, e) \ + *pp=c.p; \ + if (a != NULL) (*a)=ret; \ + return(ret); \ +err:\ + ASN1_MAC_H_err((e),c.error,c.line); \ + asn1_add_error(*pp,(int)(c.q- *pp)); \ + if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ + return(NULL) + +#define M_ASN1_D2I_end_sequence() \ + (((c.inf&1) == 0)?(c.slen <= 0): \ + (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) + +/* Don't use this with d2i_ASN1_BOOLEAN() */ +#define M_ASN1_D2I_get(b, func) \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +/* Don't use this with d2i_ASN1_BOOLEAN() */ +#define M_ASN1_D2I_get_x(type,b,func) \ + c.q=c.p; \ + if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +/* use this instead () */ +#define M_ASN1_D2I_get_int(b,func) \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) < 0) \ + {c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +#define M_ASN1_D2I_get_opt(b,func,type) \ + if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ + == (V_ASN1_UNIVERSAL|(type)))) \ + { \ + M_ASN1_D2I_get(b,func); \ + } + +#define M_ASN1_D2I_get_imp(b,func, type) \ + M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ + c.slen-=(c.p-c.q);\ + M_ASN1_next_prev=_tmp; + +#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ + if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ + (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ + { \ + unsigned char _tmp = M_ASN1_next; \ + M_ASN1_D2I_get_imp(b,func, type);\ + } + +#define M_ASN1_D2I_get_set(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func, \ + V_ASN1_SET,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ + V_ASN1_SET,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_set_opt(r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ + { M_ASN1_D2I_get_set(r,func,free_func); } + +#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ + { M_ASN1_D2I_get_set_type(type,r,func,free_func); } + +#define M_ASN1_I2D_len_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_len_SET(a,f); + +#define M_ASN1_I2D_put_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SET(a,f); + +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE(a,f); + +#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE_type(type,a,f); + +#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ + if ((c.slen != 0) && \ + (M_ASN1_next == \ + (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ + { \ + M_ASN1_D2I_get_imp_set(b,func,free_func,\ + tag,V_ASN1_CONTEXT_SPECIFIC); \ + } + +#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ + if ((c.slen != 0) && \ + (M_ASN1_next == \ + (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ + { \ + M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ + tag,V_ASN1_CONTEXT_SPECIFIC); \ + } + +#define M_ASN1_D2I_get_seq(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ + V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) + +#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ + { M_ASN1_D2I_get_seq(r,func,free_func); } + +#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ + { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } + +#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); + +#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); + +#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ + c.q=c.p; \ + if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ + (void (*)())free_func,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ + c.q=c.p; \ + if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ + free_func,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +#define M_ASN1_D2I_get_set_strings(r,func,a,b) \ + c.q=c.p; \ + if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ + if ((c.slen != 0L) && (M_ASN1_next == \ + (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ + { \ + int Tinf,Ttag,Tclass; \ + long Tlen; \ + \ + c.q=c.p; \ + Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ + if (Tinf & 0x80) \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ + if (func(&(r),&c.p,Tlen) == NULL) \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ + c.slen-=(c.p-c.q); \ + } + +#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ + if ((c.slen != 0) && (M_ASN1_next == \ + (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ + { \ + int Tinf,Ttag,Tclass; \ + long Tlen; \ + \ + c.q=c.p; \ + Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ + if (Tinf & 0x80) \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ + if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ + (void (*)())free_func, \ + b,V_ASN1_UNIVERSAL) == NULL) \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ + c.slen-=(c.p-c.q); \ + } + +#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ + if ((c.slen != 0) && (M_ASN1_next == \ + (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ + { \ + int Tinf,Ttag,Tclass; \ + long Tlen; \ + \ + c.q=c.p; \ + Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ + if (Tinf & 0x80) \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ + if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ + free_func,b,V_ASN1_UNIVERSAL) == NULL) \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ + c.slen-=(c.p-c.q); \ + } + +/* New macros */ +#define M_ASN1_New_Malloc(ret,type) \ + if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ + { c.line=__LINE__; goto err2; } + +#define M_ASN1_New(arg,func) \ + if (((arg)=func()) == NULL) return(NULL) + +#define M_ASN1_New_Error(a) \ +/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ + return(NULL);*/ \ + err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ + return(NULL) + + +/* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, + some macros that use ASN1_const_CTX still insist on writing in the input + stream. ARGH! ARGH! ARGH! Let's get rid of this macro package. + Please? -- Richard Levitte */ +#define M_ASN1_next (*((unsigned char *)(c.p))) +#define M_ASN1_next_prev (*((unsigned char *)(c.q))) + +/*************************************************/ + +#define M_ASN1_I2D_vars(a) int r=0,ret=0; \ + unsigned char *p; \ + if (a == NULL) return(0) + +/* Length Macros */ +#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) +#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) + +#define M_ASN1_I2D_len_SET(a,f) \ + ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); + +#define M_ASN1_I2D_len_SET_type(type,a,f) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ + V_ASN1_UNIVERSAL,IS_SET); + +#define M_ASN1_I2D_len_SEQUENCE(a,f) \ + ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ + V_ASN1_UNIVERSAL,IS_SEQUENCE) + +#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_len_SEQUENCE(a,f); + +#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + M_ASN1_I2D_len_SEQUENCE_type(type,a,f); + +#define M_ASN1_I2D_len_IMP_SET(a,f,x) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); + +#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + +#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); + +#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + +#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ + if (a != NULL)\ + { \ + v=f(a,NULL); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0))\ + { \ + v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0))\ + { \ + v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_##type##_num(a) != 0))\ + { \ + v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ + V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +/* Put Macros */ +#define M_ASN1_I2D_put(a,f) f(a,&p) + +#define M_ASN1_I2D_put_IMP_opt(a,f,t) \ + if (a != NULL) \ + { \ + unsigned char *q=p; \ + f(a,&p); \ + *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ + } + +#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ + V_ASN1_UNIVERSAL,IS_SET) +#define M_ASN1_I2D_put_SET_type(type,a,f) \ + i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) +#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ + V_ASN1_CONTEXT_SPECIFIC,IS_SET) +#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ + i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) +#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ + V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ + V_ASN1_UNIVERSAL,IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ + i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE(a,f); + +#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); } + +#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); } + +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); } + +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); } + +#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ + if (a != NULL) \ + { \ + ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ + f(a,&p); \ + } + +#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + { \ + ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ + i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ + } + +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + { \ + ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ + i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ + } + +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { \ + ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ + i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ + } + +#define M_ASN1_I2D_seq_total() \ + r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ + if (pp == NULL) return(r); \ + p= *pp; \ + ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) + +#define M_ASN1_I2D_INF_seq_start(tag,ctx) \ + *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ + *(p++)=0x80 + +#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 + +#define M_ASN1_I2D_finish() *pp=p; \ + return(r); + +int asn1_GetSequence(ASN1_const_CTX *c, long *length); +void asn1_add_error(const unsigned char *address,int offset); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/asn1t.h b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1t.h new file mode 100644 index 0000000..ac14f94 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/asn1t.h @@ -0,0 +1,893 @@ +/* asn1t.h */ +/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL + * project 2000. + */ +/* ==================================================================== + * Copyright (c) 2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#ifndef HEADER_ASN1T_H +#define HEADER_ASN1T_H + +#include +#include +#include + +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +#endif + +/* ASN1 template defines, structures and functions */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) + + +/* Macros for start and end of ASN1_ITEM definition */ + +#define ASN1_ITEM_start(itname) \ + OPENSSL_GLOBAL const ASN1_ITEM itname##_it = { + +#define ASN1_ITEM_end(itname) \ + }; + +#else + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr())) + + +/* Macros for start and end of ASN1_ITEM definition */ + +#define ASN1_ITEM_start(itname) \ + const ASN1_ITEM * itname##_it(void) \ + { \ + static const ASN1_ITEM local_it = { + +#define ASN1_ITEM_end(itname) \ + }; \ + return &local_it; \ + } + +#endif + + +/* Macros to aid ASN1 template writing */ + +#define ASN1_ITEM_TEMPLATE(tname) \ + static const ASN1_TEMPLATE tname##_item_tt + +#define ASN1_ITEM_TEMPLATE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE,\ + -1,\ + &tname##_item_tt,\ + 0,\ + NULL,\ + 0,\ + #tname \ + ASN1_ITEM_end(tname) + + +/* This is a ASN1 type which just embeds a template */ + +/* This pair helps declare a SEQUENCE. We can do: + * + * ASN1_SEQUENCE(stname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END(stname) + * + * This will produce an ASN1_ITEM called stname_it + * for a structure called stname. + * + * If you want the same structure but a different + * name then use: + * + * ASN1_SEQUENCE(itname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END_name(stname, itname) + * + * This will create an item called itname_it using + * a structure called stname. + */ + +#define ASN1_SEQUENCE(tname) \ + static const ASN1_TEMPLATE tname##_seq_tt[] + +#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) + +#define ASN1_SEQUENCE_END_name(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +#define ASN1_NDEF_SEQUENCE(tname) \ + ASN1_SEQUENCE(tname) + +#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ + ASN1_SEQUENCE_cb(tname, cb) + +#define ASN1_SEQUENCE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_SEQUENCE(tname) + +#define ASN1_BROKEN_SEQUENCE(tname) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ + ASN1_SEQUENCE(tname) + +#define ASN1_SEQUENCE_ref(tname, cb, lck) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ + ASN1_SEQUENCE(tname) + +#define ASN1_SEQUENCE_enc(tname, enc, cb) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ + ASN1_SEQUENCE(tname) + +#define ASN1_NDEF_SEQUENCE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(tname),\ + #tname \ + ASN1_ITEM_end(tname) + +#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) + +#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) + +#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) + +#define ASN1_SEQUENCE_END_ref(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + + +/* This pair helps declare a CHOICE type. We can do: + * + * ASN1_CHOICE(chname) = { + * ... CHOICE options ... + * ASN1_CHOICE_END(chname) + * + * This will produce an ASN1_ITEM called chname_it + * for a structure called chname. The structure + * definition must look like this: + * typedef struct { + * int type; + * union { + * ASN1_SOMETHING *opt1; + * ASN1_SOMEOTHER *opt2; + * } value; + * } chname; + * + * the name of the selector must be 'type'. + * to use an alternative selector name use the + * ASN1_CHOICE_END_selector() version. + */ + +#define ASN1_CHOICE(tname) \ + static const ASN1_TEMPLATE tname##_ch_tt[] + +#define ASN1_CHOICE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_CHOICE(tname) + +#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) + +#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) + +#define ASN1_CHOICE_END_selector(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +#define ASN1_CHOICE_END_cb(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +/* This helps with the template wrapper form of ASN1_ITEM */ + +#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ + (flags), (tag), 0,\ + #name, ASN1_ITEM_ref(type) } + +/* These help with SEQUENCE or CHOICE components */ + +/* used to declare other types */ + +#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ + (flags), (tag), offsetof(stname, field),\ + #field, ASN1_ITEM_ref(type) } + +/* used when the structure is combined with the parent */ + +#define ASN1_EX_COMBINE(flags, tag, type) { \ + (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) } + +/* implicit and explicit helper macros */ + +#define ASN1_IMP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) + +#define ASN1_EXP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) + +/* Any defined by macros: the field used is in the table itself */ + +#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION +#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +#else +#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } +#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } +#endif +/* Plain simple type */ +#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) + +/* OPTIONAL simple type */ +#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* IMPLICIT tagged simple type */ +#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) + +/* IMPLICIT tagged OPTIONAL simple type */ +#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) + +/* Same as above but EXPLICIT */ + +#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) +#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) + +/* SEQUENCE OF type */ +#define ASN1_SEQUENCE_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) + +/* OPTIONAL SEQUENCE OF */ +#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Same as above but for SET OF */ + +#define ASN1_SET_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) + +#define ASN1_SET_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ + +#define ASN1_IMP_SET_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +#define ASN1_EXP_SET_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +/* EXPLICIT using indefinite length constructed form */ +#define ASN1_NDEF_EXP(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) + +/* EXPLICIT OPTIONAL using indefinite length constructed form */ +#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) + +/* Macros for the ASN1_ADB structure */ + +#define ASN1_ADB(name) \ + static const ASN1_ADB_TABLE name##_adbtbl[] + +#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ + ;\ + static const ASN1_ADB name##_adb = {\ + flags,\ + offsetof(name, field),\ + app_table,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + } + +#else + +#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ + ;\ + static const ASN1_ITEM *name##_adb(void) \ + { \ + static const ASN1_ADB internal_adb = \ + {\ + flags,\ + offsetof(name, field),\ + app_table,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + }; \ + return (const ASN1_ITEM *) &internal_adb; \ + } \ + void dummy_function(void) + +#endif + +#define ADB_ENTRY(val, template) {val, template} + +#define ASN1_ADB_TEMPLATE(name) \ + static const ASN1_TEMPLATE name##_tt + +/* This is the ASN1 template structure that defines + * a wrapper round the actual type. It determines the + * actual position of the field in the value structure, + * various flags such as OPTIONAL and the field name. + */ + +struct ASN1_TEMPLATE_st { +unsigned long flags; /* Various flags */ +long tag; /* tag, not used if no tagging */ +unsigned long offset; /* Offset of this field in structure */ +#ifndef NO_ASN1_FIELD_NAMES +const char *field_name; /* Field name */ +#endif +ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ +}; + +/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ + +#define ASN1_TEMPLATE_item(t) (t->item_ptr) +#define ASN1_TEMPLATE_adb(t) (t->item_ptr) + +typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; +typedef struct ASN1_ADB_st ASN1_ADB; + +struct ASN1_ADB_st { + unsigned long flags; /* Various flags */ + unsigned long offset; /* Offset of selector field */ + STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */ + const ASN1_ADB_TABLE *tbl; /* Table of possible types */ + long tblcount; /* Number of entries in tbl */ + const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ + const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ +}; + +struct ASN1_ADB_TABLE_st { + long value; /* NID for an object or value for an int */ + const ASN1_TEMPLATE tt; /* item for this value */ +}; + +/* template flags */ + +/* Field is optional */ +#define ASN1_TFLG_OPTIONAL (0x1) + +/* Field is a SET OF */ +#define ASN1_TFLG_SET_OF (0x1 << 1) + +/* Field is a SEQUENCE OF */ +#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) + +/* Special case: this refers to a SET OF that + * will be sorted into DER order when encoded *and* + * the corresponding STACK will be modified to match + * the new order. + */ +#define ASN1_TFLG_SET_ORDER (0x3 << 1) + +/* Mask for SET OF or SEQUENCE OF */ +#define ASN1_TFLG_SK_MASK (0x3 << 1) + +/* These flags mean the tag should be taken from the + * tag field. If EXPLICIT then the underlying type + * is used for the inner tag. + */ + +/* IMPLICIT tagging */ +#define ASN1_TFLG_IMPTAG (0x1 << 3) + + +/* EXPLICIT tagging, inner tag from underlying type */ +#define ASN1_TFLG_EXPTAG (0x2 << 3) + +#define ASN1_TFLG_TAG_MASK (0x3 << 3) + +/* context specific IMPLICIT */ +#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT + +/* context specific EXPLICIT */ +#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT + +/* If tagging is in force these determine the + * type of tag to use. Otherwise the tag is + * determined by the underlying type. These + * values reflect the actual octet format. + */ + +/* Universal tag */ +#define ASN1_TFLG_UNIVERSAL (0x0<<6) +/* Application tag */ +#define ASN1_TFLG_APPLICATION (0x1<<6) +/* Context specific tag */ +#define ASN1_TFLG_CONTEXT (0x2<<6) +/* Private tag */ +#define ASN1_TFLG_PRIVATE (0x3<<6) + +#define ASN1_TFLG_TAG_CLASS (0x3<<6) + +/* These are for ANY DEFINED BY type. In this case + * the 'item' field points to an ASN1_ADB structure + * which contains a table of values to decode the + * relevant type + */ + +#define ASN1_TFLG_ADB_MASK (0x3<<8) + +#define ASN1_TFLG_ADB_OID (0x1<<8) + +#define ASN1_TFLG_ADB_INT (0x1<<9) + +/* This flag means a parent structure is passed + * instead of the field: this is useful is a + * SEQUENCE is being combined with a CHOICE for + * example. Since this means the structure and + * item name will differ we need to use the + * ASN1_CHOICE_END_name() macro for example. + */ + +#define ASN1_TFLG_COMBINE (0x1<<10) + +/* This flag when present in a SEQUENCE OF, SET OF + * or EXPLICIT causes indefinite length constructed + * encoding to be used if required. + */ + +#define ASN1_TFLG_NDEF (0x1<<11) + +/* This is the actual ASN1 item itself */ + +struct ASN1_ITEM_st { +char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */ +long utype; /* underlying type */ +const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */ +long tcount; /* Number of templates if SEQUENCE or CHOICE */ +const void *funcs; /* functions that handle this type */ +long size; /* Structure size (usually)*/ +#ifndef NO_ASN1_FIELD_NAMES +const char *sname; /* Structure name */ +#endif +}; + +/* These are values for the itype field and + * determine how the type is interpreted. + * + * For PRIMITIVE types the underlying type + * determines the behaviour if items is NULL. + * + * Otherwise templates must contain a single + * template and the type is treated in the + * same way as the type specified in the template. + * + * For SEQUENCE types the templates field points + * to the members, the size field is the + * structure size. + * + * For CHOICE types the templates field points + * to each possible member (typically a union) + * and the 'size' field is the offset of the + * selector. + * + * The 'funcs' field is used for application + * specific functions. + * + * For COMPAT types the funcs field gives a + * set of functions that handle this type, this + * supports the old d2i, i2d convention. + * + * The EXTERN type uses a new style d2i/i2d. + * The new style should be used where possible + * because it avoids things like the d2i IMPLICIT + * hack. + * + * MSTRING is a multiple string type, it is used + * for a CHOICE of character strings where the + * actual strings all occupy an ASN1_STRING + * structure. In this case the 'utype' field + * has a special meaning, it is used as a mask + * of acceptable types using the B_ASN1 constants. + * + * NDEF_SEQUENCE is the same as SEQUENCE except + * that it will use indefinite length constructed + * encoding if requested. + * + */ + +#define ASN1_ITYPE_PRIMITIVE 0x0 + +#define ASN1_ITYPE_SEQUENCE 0x1 + +#define ASN1_ITYPE_CHOICE 0x2 + +#define ASN1_ITYPE_COMPAT 0x3 + +#define ASN1_ITYPE_EXTERN 0x4 + +#define ASN1_ITYPE_MSTRING 0x5 + +#define ASN1_ITYPE_NDEF_SEQUENCE 0x6 + +/* Cache for ASN1 tag and length, so we + * don't keep re-reading it for things + * like CHOICE + */ + +struct ASN1_TLC_st{ + char valid; /* Values below are valid */ + int ret; /* return value */ + long plen; /* length */ + int ptag; /* class value */ + int pclass; /* class value */ + int hdrlen; /* header length */ +}; + +/* Typedefs for ASN1 function pointers */ + +typedef ASN1_VALUE * ASN1_new_func(void); +typedef void ASN1_free_func(ASN1_VALUE *a); +typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length); +typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); + +typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, + int tag, int aclass, char opt, ASN1_TLC *ctx); + +typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); +typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); +typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); + +typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); +typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); + +typedef struct ASN1_COMPAT_FUNCS_st { + ASN1_new_func *asn1_new; + ASN1_free_func *asn1_free; + ASN1_d2i_func *asn1_d2i; + ASN1_i2d_func *asn1_i2d; +} ASN1_COMPAT_FUNCS; + +typedef struct ASN1_EXTERN_FUNCS_st { + void *app_data; + ASN1_ex_new_func *asn1_ex_new; + ASN1_ex_free_func *asn1_ex_free; + ASN1_ex_free_func *asn1_ex_clear; + ASN1_ex_d2i *asn1_ex_d2i; + ASN1_ex_i2d *asn1_ex_i2d; +} ASN1_EXTERN_FUNCS; + +typedef struct ASN1_PRIMITIVE_FUNCS_st { + void *app_data; + unsigned long flags; + ASN1_ex_new_func *prim_new; + ASN1_ex_free_func *prim_free; + ASN1_ex_free_func *prim_clear; + ASN1_primitive_c2i *prim_c2i; + ASN1_primitive_i2c *prim_i2c; +} ASN1_PRIMITIVE_FUNCS; + +/* This is the ASN1_AUX structure: it handles various + * miscellaneous requirements. For example the use of + * reference counts and an informational callback. + * + * The "informational callback" is called at various + * points during the ASN1 encoding and decoding. It can + * be used to provide minor customisation of the structures + * used. This is most useful where the supplied routines + * *almost* do the right thing but need some extra help + * at a few points. If the callback returns zero then + * it is assumed a fatal error has occurred and the + * main operation should be abandoned. + * + * If major changes in the default behaviour are required + * then an external type is more appropriate. + */ + +typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it); + +typedef struct ASN1_AUX_st { + void *app_data; + int flags; + int ref_offset; /* Offset of reference value */ + int ref_lock; /* Lock type to use */ + ASN1_aux_cb *asn1_cb; + int enc_offset; /* Offset of ASN1_ENCODING structure */ +} ASN1_AUX; + +/* Flags in ASN1_AUX */ + +/* Use a reference count */ +#define ASN1_AFLG_REFCOUNT 1 +/* Save the encoding of structure (useful for signatures) */ +#define ASN1_AFLG_ENCODING 2 +/* The Sequence length is invalid */ +#define ASN1_AFLG_BROKEN 4 + +/* operation values for asn1_cb */ + +#define ASN1_OP_NEW_PRE 0 +#define ASN1_OP_NEW_POST 1 +#define ASN1_OP_FREE_PRE 2 +#define ASN1_OP_FREE_POST 3 +#define ASN1_OP_D2I_PRE 4 +#define ASN1_OP_D2I_POST 5 +#define ASN1_OP_I2D_PRE 6 +#define ASN1_OP_I2D_POST 7 + +/* Macro to implement a primitive type */ +#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) +#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ + ASN1_ITEM_end(itname) + +/* Macro to implement a multi string type */ +#define IMPLEMENT_ASN1_MSTRING(itname, mask) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ + ASN1_ITEM_end(itname) + +/* Macro to implement an ASN1_ITEM in terms of old style funcs */ + +#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE) + +#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \ + static const ASN1_COMPAT_FUNCS sname##_ff = { \ + (ASN1_new_func *)sname##_new, \ + (ASN1_free_func *)sname##_free, \ + (ASN1_d2i_func *)d2i_##sname, \ + (ASN1_i2d_func *)i2d_##sname, \ + }; \ + ASN1_ITEM_start(sname) \ + ASN1_ITYPE_COMPAT, \ + tag, \ + NULL, \ + 0, \ + &sname##_ff, \ + 0, \ + #sname \ + ASN1_ITEM_end(sname) + +#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ + ASN1_ITEM_start(sname) \ + ASN1_ITYPE_EXTERN, \ + tag, \ + NULL, \ + 0, \ + &fptrs, \ + 0, \ + #sname \ + ASN1_ITEM_end(sname) + +/* Macro to implement standard functions in terms of ASN1_ITEM structures */ + +#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) + +#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) + +#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ + IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) + +#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) + +#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ + stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } + +#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ + int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ + { \ + return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ + } + +/* This includes evil casts to remove const: they will go away when full + * ASN1 constification is done. + */ +#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ + stname * stname##_dup(stname *x) \ + { \ + return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ + } + +#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ + IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) + +#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +/* external definitions for primitive types */ + +DECLARE_ASN1_ITEM(ASN1_BOOLEAN) +DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_SEQUENCE) +DECLARE_ASN1_ITEM(CBIGNUM) +DECLARE_ASN1_ITEM(BIGNUM) +DECLARE_ASN1_ITEM(LONG) +DECLARE_ASN1_ITEM(ZLONG) + +DECLARE_STACK_OF(ASN1_VALUE) + +/* Functions used internally by the ASN1 code */ + +int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); +void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); +int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); +int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); + +void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); +int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt); +int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, + int tag, int aclass, char opt, ASN1_TLC *ctx); + +int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); +int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt); +void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); + +int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); +int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); + +int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); +int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); + +ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); + +const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr); + +int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it); + +void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); +void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); +int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); +int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/bio.h b/石器时代8.5客户端最新源代码/石器源码/openssl/bio.h new file mode 100644 index 0000000..cecb6a7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/bio.h @@ -0,0 +1,776 @@ +/* crypto/bio/bio.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_BIO_H +#define HEADER_BIO_H + +#include + +#ifndef OPENSSL_NO_FP_API +# include +#endif +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* These are the 'types' of BIOs */ +#define BIO_TYPE_NONE 0 +#define BIO_TYPE_MEM (1|0x0400) +#define BIO_TYPE_FILE (2|0x0400) + +#define BIO_TYPE_FD (4|0x0400|0x0100) +#define BIO_TYPE_SOCKET (5|0x0400|0x0100) +#define BIO_TYPE_NULL (6|0x0400) +#define BIO_TYPE_SSL (7|0x0200) +#define BIO_TYPE_MD (8|0x0200) /* passive filter */ +#define BIO_TYPE_BUFFER (9|0x0200) /* filter */ +#define BIO_TYPE_CIPHER (10|0x0200) /* filter */ +#define BIO_TYPE_BASE64 (11|0x0200) /* filter */ +#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ +#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ +#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ +#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ +#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ +#define BIO_TYPE_NULL_FILTER (17|0x0200) +#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ +#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ +#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ +#define BIO_TYPE_DGRAM (21|0x0400|0x0100) +#define BIO_TYPE_COMP (23|0x0200) /* filter */ + +#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ +#define BIO_TYPE_FILTER 0x0200 +#define BIO_TYPE_SOURCE_SINK 0x0400 + +/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. + * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ +#define BIO_NOCLOSE 0x00 +#define BIO_CLOSE 0x01 + +/* These are used in the following macros and are passed to + * BIO_ctrl() */ +#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ +#define BIO_CTRL_EOF 2 /* opt - are we at the eof */ +#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ +#define BIO_CTRL_SET 4 /* man - set the 'IO' type */ +#define BIO_CTRL_GET 5 /* man - get the 'IO' type */ +#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ +#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ +#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ +#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ +#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ +#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ +#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ +#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ +/* callback is int cb(BIO *bio,state,ret); */ +#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ +#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ + +#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ + +/* dgram BIO stuff */ +#define BIO_CTRL_DGRAM_CONNECT 31 /* BIO dgram special */ +#define BIO_CTRL_DGRAM_SET_CONNECTED 32 /* allow for an externally + * connected socket to be + * passed in */ +#define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */ +#define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */ +#define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */ +#define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */ + +#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ +#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ + +/* #ifdef IP_MTU_DISCOVER */ +#define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ +/* #endif */ + +#define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ +#define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */ +#define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for + * MTU. want to use this + * if asking the kernel + * fails */ + +#define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU + * was exceed in the + * previous write + * operation */ + +#define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ + + +/* modifiers */ +#define BIO_FP_READ 0x02 +#define BIO_FP_WRITE 0x04 +#define BIO_FP_APPEND 0x08 +#define BIO_FP_TEXT 0x10 + +#define BIO_FLAGS_READ 0x01 +#define BIO_FLAGS_WRITE 0x02 +#define BIO_FLAGS_IO_SPECIAL 0x04 +#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) +#define BIO_FLAGS_SHOULD_RETRY 0x08 +#ifndef BIO_FLAGS_UPLINK +/* "UPLINK" flag denotes file descriptors provided by application. + It defaults to 0, as most platforms don't require UPLINK interface. */ +#define BIO_FLAGS_UPLINK 0 +#endif + +/* Used in BIO_gethostbyname() */ +#define BIO_GHBN_CTRL_HITS 1 +#define BIO_GHBN_CTRL_MISSES 2 +#define BIO_GHBN_CTRL_CACHE_SIZE 3 +#define BIO_GHBN_CTRL_GET_ENTRY 4 +#define BIO_GHBN_CTRL_FLUSH 5 + +/* Mostly used in the SSL BIO */ +/* Not used anymore + * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 + * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 + * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 + */ + +#define BIO_FLAGS_BASE64_NO_NL 0x100 + +/* This is used with memory BIOs: it means we shouldn't free up or change the + * data in any way. + */ +#define BIO_FLAGS_MEM_RDONLY 0x200 + +typedef struct bio_st BIO; + +void BIO_set_flags(BIO *b, int flags); +int BIO_test_flags(const BIO *b, int flags); +void BIO_clear_flags(BIO *b, int flags); + +#define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) +#define BIO_set_retry_special(b) \ + BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) +#define BIO_set_retry_read(b) \ + BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) +#define BIO_set_retry_write(b) \ + BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) + +/* These are normally used internally in BIOs */ +#define BIO_clear_retry_flags(b) \ + BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) +#define BIO_get_retry_flags(b) \ + BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) + +/* These should be used by the application to tell why we should retry */ +#define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) +#define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) +#define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) +#define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) +#define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) + +/* The next three are used in conjunction with the + * BIO_should_io_special() condition. After this returns true, + * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO + * stack and return the 'reason' for the special and the offending BIO. + * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ +/* Returned from the SSL bio when the certificate retrieval code had an error */ +#define BIO_RR_SSL_X509_LOOKUP 0x01 +/* Returned from the connect BIO when a connect would have blocked */ +#define BIO_RR_CONNECT 0x02 +/* Returned from the accept BIO when an accept would have blocked */ +#define BIO_RR_ACCEPT 0x03 + +/* These are passed by the BIO callback */ +#define BIO_CB_FREE 0x01 +#define BIO_CB_READ 0x02 +#define BIO_CB_WRITE 0x03 +#define BIO_CB_PUTS 0x04 +#define BIO_CB_GETS 0x05 +#define BIO_CB_CTRL 0x06 + +/* The callback is called before and after the underling operation, + * The BIO_CB_RETURN flag indicates if it is after the call */ +#define BIO_CB_RETURN 0x80 +#define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) +#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) +#define BIO_cb_post(a) ((a)&BIO_CB_RETURN) + +long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long); +void BIO_set_callback(BIO *b, + long (*callback)(struct bio_st *,int,const char *,int, long,long)); +char *BIO_get_callback_arg(const BIO *b); +void BIO_set_callback_arg(BIO *b, char *arg); + +const char * BIO_method_name(const BIO *b); +int BIO_method_type(const BIO *b); + +typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); + +#ifndef OPENSSL_SYS_WIN16 +typedef struct bio_method_st + { + int type; + const char *name; + int (*bwrite)(BIO *, const char *, int); + int (*bread)(BIO *, char *, int); + int (*bputs)(BIO *, const char *); + int (*bgets)(BIO *, char *, int); + long (*ctrl)(BIO *, int, long, void *); + int (*create)(BIO *); + int (*destroy)(BIO *); + long (*callback_ctrl)(BIO *, int, bio_info_cb *); + } BIO_METHOD; +#else +typedef struct bio_method_st + { + int type; + const char *name; + int (_far *bwrite)(); + int (_far *bread)(); + int (_far *bputs)(); + int (_far *bgets)(); + long (_far *ctrl)(); + int (_far *create)(); + int (_far *destroy)(); + long (_far *callback_ctrl)(); + } BIO_METHOD; +#endif + +struct bio_st + { + BIO_METHOD *method; + /* bio, mode, argp, argi, argl, ret */ + long (*callback)(struct bio_st *,int,const char *,int, long,long); + char *cb_arg; /* first argument for the callback */ + + int init; + int shutdown; + int flags; /* extra storage */ + int retry_reason; + int num; + void *ptr; + struct bio_st *next_bio; /* used by filter BIOs */ + struct bio_st *prev_bio; /* used by filter BIOs */ + int references; + unsigned long num_read; + unsigned long num_write; + + CRYPTO_EX_DATA ex_data; + }; + +DECLARE_STACK_OF(BIO) + +typedef struct bio_f_buffer_ctx_struct + { + /* BIO *bio; */ /* this is now in the BIO struct */ + int ibuf_size; /* how big is the input buffer */ + int obuf_size; /* how big is the output buffer */ + + char *ibuf; /* the char array */ + int ibuf_len; /* how many bytes are in it */ + int ibuf_off; /* write/read offset */ + + char *obuf; /* the char array */ + int obuf_len; /* how many bytes are in it */ + int obuf_off; /* write/read offset */ + } BIO_F_BUFFER_CTX; + +/* connect BIO stuff */ +#define BIO_CONN_S_BEFORE 1 +#define BIO_CONN_S_GET_IP 2 +#define BIO_CONN_S_GET_PORT 3 +#define BIO_CONN_S_CREATE_SOCKET 4 +#define BIO_CONN_S_CONNECT 5 +#define BIO_CONN_S_OK 6 +#define BIO_CONN_S_BLOCKED_CONNECT 7 +#define BIO_CONN_S_NBIO 8 +/*#define BIO_CONN_get_param_hostname BIO_ctrl */ + +#define BIO_C_SET_CONNECT 100 +#define BIO_C_DO_STATE_MACHINE 101 +#define BIO_C_SET_NBIO 102 +#define BIO_C_SET_PROXY_PARAM 103 +#define BIO_C_SET_FD 104 +#define BIO_C_GET_FD 105 +#define BIO_C_SET_FILE_PTR 106 +#define BIO_C_GET_FILE_PTR 107 +#define BIO_C_SET_FILENAME 108 +#define BIO_C_SET_SSL 109 +#define BIO_C_GET_SSL 110 +#define BIO_C_SET_MD 111 +#define BIO_C_GET_MD 112 +#define BIO_C_GET_CIPHER_STATUS 113 +#define BIO_C_SET_BUF_MEM 114 +#define BIO_C_GET_BUF_MEM_PTR 115 +#define BIO_C_GET_BUFF_NUM_LINES 116 +#define BIO_C_SET_BUFF_SIZE 117 +#define BIO_C_SET_ACCEPT 118 +#define BIO_C_SSL_MODE 119 +#define BIO_C_GET_MD_CTX 120 +#define BIO_C_GET_PROXY_PARAM 121 +#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ +#define BIO_C_GET_CONNECT 123 +#define BIO_C_GET_ACCEPT 124 +#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 +#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 +#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +#define BIO_C_FILE_SEEK 128 +#define BIO_C_GET_CIPHER_CTX 129 +#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ +#define BIO_C_SET_BIND_MODE 131 +#define BIO_C_GET_BIND_MODE 132 +#define BIO_C_FILE_TELL 133 +#define BIO_C_GET_SOCKS 134 +#define BIO_C_SET_SOCKS 135 + +#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ +#define BIO_C_GET_WRITE_BUF_SIZE 137 +#define BIO_C_MAKE_BIO_PAIR 138 +#define BIO_C_DESTROY_BIO_PAIR 139 +#define BIO_C_GET_WRITE_GUARANTEE 140 +#define BIO_C_GET_READ_REQUEST 141 +#define BIO_C_SHUTDOWN_WR 142 +#define BIO_C_NREAD0 143 +#define BIO_C_NREAD 144 +#define BIO_C_NWRITE0 145 +#define BIO_C_NWRITE 146 +#define BIO_C_RESET_READ_REQUEST 147 +#define BIO_C_SET_MD_CTX 148 + + +#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) +#define BIO_get_app_data(s) BIO_get_ex_data(s,0) + +/* BIO_s_connect() and BIO_s_socks4a_connect() */ +#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) +#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) +#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) +#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) +#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) +#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) +#define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2) +#define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3) + + +#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) + +/* BIO_s_accept_socket() */ +#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) +#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) +/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ +#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) +#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) + +#define BIO_BIND_NORMAL 0 +#define BIO_BIND_REUSEADDR_IF_UNUSED 1 +#define BIO_BIND_REUSEADDR 2 +#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + +#define BIO_do_connect(b) BIO_do_handshake(b) +#define BIO_do_accept(b) BIO_do_handshake(b) +#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) + +/* BIO_s_proxy_client() */ +#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) +#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) +/* BIO_set_nbio(b,n) */ +#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) +/* BIO *BIO_get_filter_bio(BIO *bio); */ +#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)())) +#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) +#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) + +#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) +#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) +#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) +#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) + +#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) +#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) + +#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) +#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) + +#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + +/* name is cast to lose const, but might be better to route through a function + so we can do it safely */ +#ifdef CONST_STRICT +/* If you are wondering why this isn't defined, its because CONST_STRICT is + * purely a compile-time kludge to allow const to be checked. + */ +int BIO_read_filename(BIO *b,const char *name); +#else +#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ,(char *)name) +#endif +#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_WRITE,name) +#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_APPEND,name) +#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) + +/* WARNING WARNING, this ups the reference count on the read bio of the + * SSL structure. This is because the ssl read BIO is now pointed to by + * the next_bio field in the bio. So when you free the BIO, make sure + * you are doing a BIO_free_all() to catch the underlying BIO. */ +#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) +#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) +#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) +#define BIO_set_ssl_renegotiate_bytes(b,num) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); +#define BIO_get_num_renegotiates(b) \ + BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL); +#define BIO_set_ssl_renegotiate_timeout(b,seconds) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); + +/* defined in evp.h */ +/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ + +#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) +#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) +#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) +#define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) + +/* For the BIO_f_buffer() type */ +#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) +#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) +#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) +#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) +#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) + +/* Don't use the next one unless you know what you are doing :-) */ +#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) + +#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) +#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) +#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) +#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) +#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) +#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +/* ...pending macros have inappropriate return type */ +size_t BIO_ctrl_pending(BIO *b); +size_t BIO_ctrl_wpending(BIO *b); +#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) +#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \ + cbp) +#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb) + +/* For the BIO_f_buffer() type */ +#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) + +/* For BIO_s_bio() */ +#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) +#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) +#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) +#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) +#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) +/* macros with inappropriate type -- but ...pending macros use int too: */ +#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) +#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +size_t BIO_ctrl_get_write_guarantee(BIO *b); +size_t BIO_ctrl_get_read_request(BIO *b); +int BIO_ctrl_reset_read_request(BIO *b); + +/* ctrl macros for dgram */ +#define BIO_ctrl_dgram_connect(b,peer) \ + (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer) +#define BIO_ctrl_set_connected(b, state, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, state, (char *)peer) +#define BIO_dgram_recv_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) +#define BIO_dgram_send_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) +#define BIO_dgram_set_peer(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer) + +/* These two aren't currently implemented */ +/* int BIO_get_ex_num(BIO *bio); */ +/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ +int BIO_set_ex_data(BIO *bio,int idx,void *data); +void *BIO_get_ex_data(BIO *bio,int idx); +int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +unsigned long BIO_number_read(BIO *bio); +unsigned long BIO_number_written(BIO *bio); + +# ifndef OPENSSL_NO_FP_API +# if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL) +BIO_METHOD *BIO_s_file_internal(void); +BIO *BIO_new_file_internal(char *filename, char *mode); +BIO *BIO_new_fp_internal(FILE *stream, int close_flag); +# define BIO_s_file BIO_s_file_internal +# define BIO_new_file BIO_new_file_internal +# define BIO_new_fp BIO_new_fp_internal +# else /* FP_API */ +BIO_METHOD *BIO_s_file(void ); +BIO *BIO_new_file(const char *filename, const char *mode); +BIO *BIO_new_fp(FILE *stream, int close_flag); +# define BIO_s_file_internal BIO_s_file +# define BIO_new_file_internal BIO_new_file +# define BIO_new_fp_internal BIO_s_file +# endif /* FP_API */ +# endif +BIO * BIO_new(BIO_METHOD *type); +int BIO_set(BIO *a,BIO_METHOD *type); +int BIO_free(BIO *a); +void BIO_vfree(BIO *a); +int BIO_read(BIO *b, void *data, int len); +int BIO_gets(BIO *bp,char *buf, int size); +int BIO_write(BIO *b, const void *data, int len); +int BIO_puts(BIO *bp,const char *buf); +int BIO_indent(BIO *b,int indent,int max); +long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); +long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); +char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); +long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); +BIO * BIO_push(BIO *b,BIO *append); +BIO * BIO_pop(BIO *b); +void BIO_free_all(BIO *a); +BIO * BIO_find_type(BIO *b,int bio_type); +BIO * BIO_next(BIO *b); +BIO * BIO_get_retry_BIO(BIO *bio, int *reason); +int BIO_get_retry_reason(BIO *bio); +BIO * BIO_dup_chain(BIO *in); + +int BIO_nread0(BIO *bio, char **buf); +int BIO_nread(BIO *bio, char **buf, int num); +int BIO_nwrite0(BIO *bio, char **buf); +int BIO_nwrite(BIO *bio, char **buf, int num); + +#ifndef OPENSSL_SYS_WIN16 +long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, + long argl,long ret); +#else +long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, + long argl,long ret); +#endif + +BIO_METHOD *BIO_s_mem(void); +BIO *BIO_new_mem_buf(void *buf, int len); +BIO_METHOD *BIO_s_socket(void); +BIO_METHOD *BIO_s_connect(void); +BIO_METHOD *BIO_s_accept(void); +BIO_METHOD *BIO_s_fd(void); +#ifndef OPENSSL_SYS_OS2 +BIO_METHOD *BIO_s_log(void); +#endif +BIO_METHOD *BIO_s_bio(void); +BIO_METHOD *BIO_s_null(void); +BIO_METHOD *BIO_f_null(void); +BIO_METHOD *BIO_f_buffer(void); +#ifdef OPENSSL_SYS_VMS +BIO_METHOD *BIO_f_linebuffer(void); +#endif +BIO_METHOD *BIO_f_nbio_test(void); +#ifndef OPENSSL_NO_DGRAM +BIO_METHOD *BIO_s_datagram(void); +#endif + +/* BIO_METHOD *BIO_f_ber(void); */ + +int BIO_sock_should_retry(int i); +int BIO_sock_non_fatal_error(int error); +int BIO_dgram_non_fatal_error(int error); + +int BIO_fd_should_retry(int i); +int BIO_fd_non_fatal_error(int error); +int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const char *s, int len); +int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const char *s, int len, int indent); +int BIO_dump(BIO *b,const char *bytes,int len); +int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent); +#ifndef OPENSSL_NO_FP_API +int BIO_dump_fp(FILE *fp, const char *s, int len); +int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); +#endif +struct hostent *BIO_gethostbyname(const char *name); +/* We might want a thread-safe interface too: + * struct hostent *BIO_gethostbyname_r(const char *name, + * struct hostent *result, void *buffer, size_t buflen); + * or something similar (caller allocates a struct hostent, + * pointed to by "result", and additional buffer space for the various + * substructures; if the buffer does not suffice, NULL is returned + * and an appropriate error code is set). + */ +int BIO_sock_error(int sock); +int BIO_socket_ioctl(int fd, long type, void *arg); +int BIO_socket_nbio(int fd,int mode); +int BIO_get_port(const char *str, unsigned short *port_ptr); +int BIO_get_host_ip(const char *str, unsigned char *ip); +int BIO_get_accept_socket(char *host_port,int mode); +int BIO_accept(int sock,char **ip_port); +int BIO_sock_init(void ); +void BIO_sock_cleanup(void); +int BIO_set_tcp_ndelay(int sock,int turn_on); + +BIO *BIO_new_socket(int sock, int close_flag); +BIO *BIO_new_dgram(int fd, int close_flag); +BIO *BIO_new_fd(int fd, int close_flag); +BIO *BIO_new_connect(char *host_port); +BIO *BIO_new_accept(char *host_port); + +int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, + BIO **bio2, size_t writebuf2); +/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. + * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. + * Size 0 uses default value. + */ + +void BIO_copy_next_retry(BIO *b); + +/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/ + +#ifdef __GNUC__ +# define __bio_h__attr__ __attribute__ +#else +# define __bio_h__attr__(x) +#endif +int BIO_printf(BIO *bio, const char *format, ...) + __bio_h__attr__((__format__(__printf__,2,3))); +int BIO_vprintf(BIO *bio, const char *format, va_list args) + __bio_h__attr__((__format__(__printf__,2,0))); +int BIO_snprintf(char *buf, size_t n, const char *format, ...) + __bio_h__attr__((__format__(__printf__,3,4))); +int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) + __bio_h__attr__((__format__(__printf__,3,0))); +#undef __bio_h__attr__ + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_BIO_strings(void); + +/* Error codes for the BIO functions. */ + +/* Function codes. */ +#define BIO_F_ACPT_STATE 100 +#define BIO_F_BIO_ACCEPT 101 +#define BIO_F_BIO_BER_GET_HEADER 102 +#define BIO_F_BIO_CALLBACK_CTRL 131 +#define BIO_F_BIO_CTRL 103 +#define BIO_F_BIO_GETHOSTBYNAME 120 +#define BIO_F_BIO_GETS 104 +#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 +#define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_PORT 107 +#define BIO_F_BIO_MAKE_PAIR 121 +#define BIO_F_BIO_NEW 108 +#define BIO_F_BIO_NEW_FILE 109 +#define BIO_F_BIO_NEW_MEM_BUF 126 +#define BIO_F_BIO_NREAD 123 +#define BIO_F_BIO_NREAD0 124 +#define BIO_F_BIO_NWRITE 125 +#define BIO_F_BIO_NWRITE0 122 +#define BIO_F_BIO_PUTS 110 +#define BIO_F_BIO_READ 111 +#define BIO_F_BIO_SOCK_INIT 112 +#define BIO_F_BIO_WRITE 113 +#define BIO_F_BUFFER_CTRL 114 +#define BIO_F_CONN_CTRL 127 +#define BIO_F_CONN_STATE 115 +#define BIO_F_FILE_CTRL 116 +#define BIO_F_FILE_READ 130 +#define BIO_F_LINEBUFFER_CTRL 129 +#define BIO_F_MEM_READ 128 +#define BIO_F_MEM_WRITE 117 +#define BIO_F_SSL_NEW 118 +#define BIO_F_WSASTARTUP 119 + +/* Reason codes. */ +#define BIO_R_ACCEPT_ERROR 100 +#define BIO_R_BAD_FOPEN_MODE 101 +#define BIO_R_BAD_HOSTNAME_LOOKUP 102 +#define BIO_R_BROKEN_PIPE 124 +#define BIO_R_CONNECT_ERROR 103 +#define BIO_R_EOF_ON_MEMORY_BIO 127 +#define BIO_R_ERROR_SETTING_NBIO 104 +#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 +#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 +#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 +#define BIO_R_INVALID_ARGUMENT 125 +#define BIO_R_INVALID_IP_ADDRESS 108 +#define BIO_R_IN_USE 123 +#define BIO_R_KEEPALIVE 109 +#define BIO_R_NBIO_CONNECT_ERROR 110 +#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 +#define BIO_R_NO_HOSTNAME_SPECIFIED 112 +#define BIO_R_NO_PORT_DEFINED 113 +#define BIO_R_NO_PORT_SPECIFIED 114 +#define BIO_R_NO_SUCH_FILE 128 +#define BIO_R_NULL_PARAMETER 115 +#define BIO_R_TAG_MISMATCH 116 +#define BIO_R_UNABLE_TO_BIND_SOCKET 117 +#define BIO_R_UNABLE_TO_CREATE_SOCKET 118 +#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 +#define BIO_R_UNINITIALIZED 120 +#define BIO_R_UNSUPPORTED_METHOD 121 +#define BIO_R_WRITE_TO_READ_ONLY_BIO 126 +#define BIO_R_WSASTARTUP 122 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/blowfish.h b/石器时代8.5客户端最新源代码/石器源码/openssl/blowfish.h new file mode 100644 index 0000000..d24ffcc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/blowfish.h @@ -0,0 +1,129 @@ +/* crypto/bf/blowfish.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_BLOWFISH_H +#define HEADER_BLOWFISH_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_NO_BF +#error BF is disabled. +#endif + +#define BF_ENCRYPT 1 +#define BF_DECRYPT 0 + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! BF_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! BF_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) +#define BF_LONG unsigned long +#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) +#define BF_LONG unsigned long +#define BF_LONG_LOG2 3 +/* + * _CRAY note. I could declare short, but I have no idea what impact + * does it have on performance on none-T3E machines. I could declare + * int, but at least on C90 sizeof(int) can be chosen at compile time. + * So I've chosen long... + * + */ +#else +#define BF_LONG unsigned int +#endif + +#define BF_ROUNDS 16 +#define BF_BLOCK 8 + +typedef struct bf_key_st + { + BF_LONG P[BF_ROUNDS+2]; + BF_LONG S[4*256]; + } BF_KEY; + +#ifdef OPENSSL_FIPS +void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data); +#endif +void BF_set_key(BF_KEY *key, int len, const unsigned char *data); + +void BF_encrypt(BF_LONG *data,const BF_KEY *key); +void BF_decrypt(BF_LONG *data,const BF_KEY *key); + +void BF_ecb_encrypt(const unsigned char *in, unsigned char *out, + const BF_KEY *key, int enc); +void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + const BF_KEY *schedule, unsigned char *ivec, int enc); +void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length, + const BF_KEY *schedule, unsigned char *ivec, int *num, int enc); +void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length, + const BF_KEY *schedule, unsigned char *ivec, int *num); +const char *BF_options(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/bn.h b/石器时代8.5客户端最新源代码/石器源码/openssl/bn.h new file mode 100644 index 0000000..f1719a5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/bn.h @@ -0,0 +1,855 @@ +/* crypto/bn/bn.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the Eric Young open source + * license provided above. + * + * The binary polynomial arithmetic software is originally written by + * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. + * + */ + +#ifndef HEADER_BN_H +#define HEADER_BN_H + +#include +#ifndef OPENSSL_NO_FP_API +#include /* FILE */ +#endif +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* These preprocessor symbols control various aspects of the bignum headers and + * library code. They're not defined by any "normal" configuration, as they are + * intended for development and testing purposes. NB: defining all three can be + * useful for debugging application code as well as openssl itself. + * + * BN_DEBUG - turn on various debugging alterations to the bignum code + * BN_DEBUG_RAND - uses random poisoning of unused words to trip up + * mismanagement of bignum internals. You must also define BN_DEBUG. + */ +/* #define BN_DEBUG */ +/* #define BN_DEBUG_RAND */ + +#define BN_MUL_COMBA +#define BN_SQR_COMBA +#define BN_RECURSION + +/* This next option uses the C libraries (2 word)/(1 word) function. + * If it is not defined, I use my C version (which is slower). + * The reason for this flag is that when the particular C compiler + * library routine is used, and the library is linked with a different + * compiler, the library is missing. This mostly happens when the + * library is built with gcc and then linked using normal cc. This would + * be a common occurrence because gcc normally produces code that is + * 2 times faster than system compilers for the big number stuff. + * For machines with only one compiler (or shared libraries), this should + * be on. Again this in only really a problem on machines + * using "long long's", are 32bit, and are not using my assembler code. */ +#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \ + defined(OPENSSL_SYS_WIN32) || defined(linux) +# ifndef BN_DIV2W +# define BN_DIV2W +# endif +#endif + +/* assuming long is 64bit - this is the DEC Alpha + * unsigned long long is only 64 bits :-(, don't define + * BN_LLONG for the DEC Alpha */ +#ifdef SIXTY_FOUR_BIT_LONG +#define BN_ULLONG unsigned long long +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK (0xffffffffffffffffffffffffffffffffLL) +#define BN_MASK2 (0xffffffffffffffffL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000L) +#define BN_MASK2h1 (0xffffffff80000000L) +#define BN_TBIT (0x8000000000000000L) +#define BN_DEC_CONV (10000000000000000000UL) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%019lu" +#define BN_DEC_NUM 19 +#endif + +/* This is where the long long data type is 64 bits, but long is 32. + * For machines where there are 64bit registers, this is the mode to use. + * IRIX, on R4000 and above should use this mode, along with the relevant + * assembler code :-). Do NOT define BN_LLONG. + */ +#ifdef SIXTY_FOUR_BIT +#undef BN_LLONG +#undef BN_ULLONG +#define BN_ULONG unsigned long long +#define BN_LONG long long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK2 (0xffffffffffffffffLL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000LL) +#define BN_MASK2h1 (0xffffffff80000000LL) +#define BN_TBIT (0x8000000000000000LL) +#define BN_DEC_CONV (10000000000000000000ULL) +#define BN_DEC_FMT1 "%llu" +#define BN_DEC_FMT2 "%019llu" +#define BN_DEC_NUM 19 +#endif + +#ifdef THIRTY_TWO_BIT +#ifdef BN_LLONG +# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__) +# define BN_ULLONG unsigned __int64 +# else +# define BN_ULLONG unsigned long long +# endif +#endif +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +#ifdef OPENSSL_SYS_WIN32 +/* VC++ doesn't like the LL suffix */ +#define BN_MASK (0xffffffffffffffffL) +#else +#define BN_MASK (0xffffffffffffffffLL) +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#endif + +#ifdef SIXTEEN_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned long +#define BN_ULONG unsigned short +#define BN_LONG short +#define BN_BITS 32 +#define BN_BYTES 2 +#define BN_BITS2 16 +#define BN_BITS4 8 +#define BN_MASK (0xffffffff) +#define BN_MASK2 (0xffff) +#define BN_MASK2l (0xff) +#define BN_MASK2h1 (0xff80) +#define BN_MASK2h (0xff00) +#define BN_TBIT (0x8000) +#define BN_DEC_CONV (100000) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%05u" +#define BN_DEC_NUM 5 +#endif + +#ifdef EIGHT_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned short +#define BN_ULONG unsigned char +#define BN_LONG char +#define BN_BITS 16 +#define BN_BYTES 1 +#define BN_BITS2 8 +#define BN_BITS4 4 +#define BN_MASK (0xffff) +#define BN_MASK2 (0xff) +#define BN_MASK2l (0xf) +#define BN_MASK2h1 (0xf8) +#define BN_MASK2h (0xf0) +#define BN_TBIT (0x80) +#define BN_DEC_CONV (100) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%02u" +#define BN_DEC_NUM 2 +#endif + +#define BN_DEFAULT_BITS 1280 + +#define BN_FLG_MALLOCED 0x01 +#define BN_FLG_STATIC_DATA 0x02 +#define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, + * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime, + * BN_div() will call BN_div_no_branch, + * BN_mod_inverse() will call BN_mod_inverse_no_branch. + */ + +#ifndef OPENSSL_NO_DEPRECATED +#define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME /* deprecated name for the flag */ + /* avoid leaking exponent information through timings + * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */ +#endif + +#ifndef OPENSSL_NO_DEPRECATED +#define BN_FLG_FREE 0x8000 /* used for debuging */ +#endif +#define BN_set_flags(b,n) ((b)->flags|=(n)) +#define BN_get_flags(b,n) ((b)->flags&(n)) + +/* get a clone of a BIGNUM with changed flags, for *temporary* use only + * (the two BIGNUMs cannot not be used in parallel!) */ +#define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \ + (dest)->top=(b)->top, \ + (dest)->dmax=(b)->dmax, \ + (dest)->neg=(b)->neg, \ + (dest)->flags=(((dest)->flags & BN_FLG_MALLOCED) \ + | ((b)->flags & ~BN_FLG_MALLOCED) \ + | BN_FLG_STATIC_DATA \ + | (n))) + +/* Already declared in ossl_typ.h */ +#if 0 +typedef struct bignum_st BIGNUM; +/* Used for temp variables (declaration hidden in bn_lcl.h) */ +typedef struct bignum_ctx BN_CTX; +typedef struct bn_blinding_st BN_BLINDING; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_gencb_st BN_GENCB; +#endif + +struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int dmax; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + +/* Used for montgomery multiplication */ +struct bn_mont_ctx_st + { + int ri; /* number of bits in R */ + BIGNUM RR; /* used to convert to montgomery form */ + BIGNUM N; /* The modulus */ + BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1 + * (Ni is only stored for bignum algorithm) */ +#if 0 + /* OpenSSL 0.9.9 preview: */ + BN_ULONG n0[2];/* least significant word(s) of Ni */ +#else + BN_ULONG n0; /* least significant word of Ni */ +#endif + int flags; + }; + +/* Used for reciprocal division/mod functions + * It cannot be shared between threads + */ +struct bn_recp_ctx_st + { + BIGNUM N; /* the divisor */ + BIGNUM Nr; /* the reciprocal */ + int num_bits; + int shift; + int flags; + }; + +/* Used for slow "generation" functions. */ +struct bn_gencb_st + { + unsigned int ver; /* To handle binary (in)compatibility */ + void *arg; /* callback-specific data */ + union + { + /* if(ver==1) - handles old style callbacks */ + void (*cb_1)(int, int, void *); + /* if(ver==2) - new callback style */ + int (*cb_2)(int, int, BN_GENCB *); + } cb; + }; +/* Wrapper function to make using BN_GENCB easier, */ +int BN_GENCB_call(BN_GENCB *cb, int a, int b); +/* Macro to populate a BN_GENCB structure with an "old"-style callback */ +#define BN_GENCB_set_old(gencb, callback, cb_arg) { \ + BN_GENCB *tmp_gencb = (gencb); \ + tmp_gencb->ver = 1; \ + tmp_gencb->arg = (cb_arg); \ + tmp_gencb->cb.cb_1 = (callback); } +/* Macro to populate a BN_GENCB structure with a "new"-style callback */ +#define BN_GENCB_set(gencb, callback, cb_arg) { \ + BN_GENCB *tmp_gencb = (gencb); \ + tmp_gencb->ver = 2; \ + tmp_gencb->arg = (cb_arg); \ + tmp_gencb->cb.cb_2 = (callback); } + +#define BN_prime_checks 0 /* default: select number of iterations + based on the size of the number */ + +/* number of Miller-Rabin iterations for an error rate of less than 2^-80 + * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook + * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996]; + * original paper: Damgaard, Landrock, Pomerance: Average case error estimates + * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */ +#define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \ + (b) >= 850 ? 3 : \ + (b) >= 650 ? 4 : \ + (b) >= 550 ? 5 : \ + (b) >= 450 ? 6 : \ + (b) >= 400 ? 7 : \ + (b) >= 350 ? 8 : \ + (b) >= 300 ? 9 : \ + (b) >= 250 ? 12 : \ + (b) >= 200 ? 15 : \ + (b) >= 150 ? 18 : \ + /* b >= 100 */ 27) + +#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) + +/* Note that BN_abs_is_word didn't work reliably for w == 0 until 0.9.8 */ +#define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \ + (((w) == 0) && ((a)->top == 0))) +#define BN_is_zero(a) ((a)->top == 0) +#define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg) +#define BN_is_word(a,w) (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg)) +#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) + +#define BN_one(a) (BN_set_word((a),1)) +#define BN_zero_ex(a) \ + do { \ + BIGNUM *_tmp_bn = (a); \ + _tmp_bn->top = 0; \ + _tmp_bn->neg = 0; \ + } while(0) +#ifdef OPENSSL_NO_DEPRECATED +#define BN_zero(a) BN_zero_ex(a) +#else +#define BN_zero(a) (BN_set_word((a),0)) +#endif + +const BIGNUM *BN_value_one(void); +char * BN_options(void); +BN_CTX *BN_CTX_new(void); +#ifndef OPENSSL_NO_DEPRECATED +void BN_CTX_init(BN_CTX *c); +#endif +void BN_CTX_free(BN_CTX *c); +void BN_CTX_start(BN_CTX *ctx); +BIGNUM *BN_CTX_get(BN_CTX *ctx); +void BN_CTX_end(BN_CTX *ctx); +int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); +int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom); +int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_num_bits(const BIGNUM *a); +int BN_num_bits_word(BN_ULONG); +BIGNUM *BN_new(void); +void BN_init(BIGNUM *); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); +void BN_swap(BIGNUM *a, BIGNUM *b); +BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); +int BN_bn2bin(const BIGNUM *a, unsigned char *to); +BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret); +int BN_bn2mpi(const BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); +int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx); +/** BN_set_negative sets sign of a BIGNUM + * \param b pointer to the BIGNUM object + * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise + */ +void BN_set_negative(BIGNUM *b, int n); +/** BN_is_negative returns 1 if the BIGNUM is negative + * \param a pointer to the BIGNUM object + * \return 1 if a < 0 and 0 otherwise + */ +#define BN_is_negative(a) ((a)->neg != 0) + +int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, + BN_CTX *ctx); +#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) +int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); +int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); +int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); +int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *m, BN_CTX *ctx); +int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); +int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m); + +BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(const BIGNUM *a); + +int BN_cmp(const BIGNUM *a, const BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(const BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, const BIGNUM *a); +int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx); + +int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m,BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); +int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1, + const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m, + BN_CTX *ctx,BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m,BN_CTX *ctx); + +int BN_mask_bits(BIGNUM *a,int n); +#ifndef OPENSSL_NO_FP_API +int BN_print_fp(FILE *fp, const BIGNUM *a); +#endif +#ifdef HEADER_BIO_H +int BN_print(BIO *fp, const BIGNUM *a); +#else +int BN_print(void *fp, const BIGNUM *a); +#endif +int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, const BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *BN_dup(const BIGNUM *a); +int BN_ucmp(const BIGNUM *a, const BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char * BN_bn2hex(const BIGNUM *a); +char * BN_bn2dec(const BIGNUM *a); +int BN_hex2bn(BIGNUM **a, const char *str); +int BN_dec2bn(BIGNUM **a, const char *str); +int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); +int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */ +BIGNUM *BN_mod_inverse(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); +BIGNUM *BN_mod_sqrt(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); + +/* Deprecated versions */ +#ifndef OPENSSL_NO_DEPRECATED +BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe, + const BIGNUM *add, const BIGNUM *rem, + void (*callback)(int,int,void *),void *cb_arg); +int BN_is_prime(const BIGNUM *p,int nchecks, + void (*callback)(int,int,void *), + BN_CTX *ctx,void *cb_arg); +int BN_is_prime_fasttest(const BIGNUM *p,int nchecks, + void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg, + int do_trial_division); +#endif /* !defined(OPENSSL_NO_DEPRECATED) */ + +/* Newer versions */ +int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add, + const BIGNUM *rem, BN_GENCB *cb); +int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb); +int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, + int do_trial_division, BN_GENCB *cb); + +int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx); + +int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, + const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, + const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb); +int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, + BIGNUM *Xp1, BIGNUM *Xp2, + const BIGNUM *Xp, + const BIGNUM *e, BN_CTX *ctx, + BN_GENCB *cb); + +BN_MONT_CTX *BN_MONT_CTX_new(void ); +void BN_MONT_CTX_init(BN_MONT_CTX *ctx); +int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b, + BN_MONT_CTX *mont, BN_CTX *ctx); +#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ + (r),(a),&((mont)->RR),(mont),(ctx)) +int BN_from_montgomery(BIGNUM *r,const BIGNUM *a, + BN_MONT_CTX *mont, BN_CTX *ctx); +void BN_MONT_CTX_free(BN_MONT_CTX *mont); +int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx); +BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); +BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, + const BIGNUM *mod, BN_CTX *ctx); + +/* BN_BLINDING flags */ +#define BN_BLINDING_NO_UPDATE 0x00000001 +#define BN_BLINDING_NO_RECREATE 0x00000002 + +BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod); +void BN_BLINDING_free(BN_BLINDING *b); +int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); +int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); +int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *); +unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *); +void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long); +unsigned long BN_BLINDING_get_flags(const BN_BLINDING *); +void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long); +BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, + const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx, + int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), + BN_MONT_CTX *m_ctx); + +#ifndef OPENSSL_NO_DEPRECATED +void BN_set_params(int mul,int high,int low,int mont); +int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */ +#endif + +void BN_RECP_CTX_init(BN_RECP_CTX *recp); +BN_RECP_CTX *BN_RECP_CTX_new(void); +void BN_RECP_CTX_free(BN_RECP_CTX *recp); +int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); +int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, + BN_RECP_CTX *recp,BN_CTX *ctx); +int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, + BN_RECP_CTX *recp, BN_CTX *ctx); + +/* Functions for arithmetic over binary polynomials represented by BIGNUMs. + * + * The BIGNUM::neg property of BIGNUMs representing binary polynomials is + * ignored. + * + * Note that input arguments are not const so that their bit arrays can + * be expanded to the appropriate size if needed. + */ + +int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/ +#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b) +int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/ +int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */ +int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); /* r = (a * a) mod p */ +int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p, + BN_CTX *ctx); /* r = (1 / b) mod p */ +int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */ +int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */ +int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); /* r = sqrt(a) mod p */ +int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); /* r^2 + r = a mod p */ +#define BN_GF2m_cmp(a, b) BN_ucmp((a), (b)) +/* Some functions allow for representation of the irreducible polynomials + * as an unsigned int[], say p. The irreducible f(t) is then of the form: + * t^p[0] + t^p[1] + ... + t^p[k] + * where m = p[0] > p[1] > ... > p[k] = 0. + */ +int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]); + /* r = a mod p */ +int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const unsigned int p[], BN_CTX *ctx); /* r = (a * b) mod p */ +int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], + BN_CTX *ctx); /* r = (a * a) mod p */ +int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const unsigned int p[], + BN_CTX *ctx); /* r = (1 / b) mod p */ +int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const unsigned int p[], BN_CTX *ctx); /* r = (a / b) mod p */ +int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const unsigned int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */ +int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, + const unsigned int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */ +int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a, + const unsigned int p[], BN_CTX *ctx); /* r^2 + r = a mod p */ +int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max); +int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a); + +/* faster mod functions for the 'NIST primes' + * 0 <= a < p^2 */ +int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); + +const BIGNUM *BN_get0_nist_prime_192(void); +const BIGNUM *BN_get0_nist_prime_224(void); +const BIGNUM *BN_get0_nist_prime_256(void); +const BIGNUM *BN_get0_nist_prime_384(void); +const BIGNUM *BN_get0_nist_prime_521(void); + +/* library internal functions */ + +#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\ + (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2)) +#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) +BIGNUM *bn_expand2(BIGNUM *a, int words); +#ifndef OPENSSL_NO_DEPRECATED +BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ +#endif + +/* Bignum consistency macros + * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from + * bignum data after direct manipulations on the data. There is also an + * "internal" macro, bn_check_top(), for verifying that there are no leading + * zeroes. Unfortunately, some auditing is required due to the fact that + * bn_fix_top() has become an overabused duct-tape because bignum data is + * occasionally passed around in an inconsistent state. So the following + * changes have been made to sort this out; + * - bn_fix_top()s implementation has been moved to bn_correct_top() + * - if BN_DEBUG isn't defined, bn_fix_top() maps to bn_correct_top(), and + * bn_check_top() is as before. + * - if BN_DEBUG *is* defined; + * - bn_check_top() tries to pollute unused words even if the bignum 'top' is + * consistent. (ed: only if BN_DEBUG_RAND is defined) + * - bn_fix_top() maps to bn_check_top() rather than "fixing" anything. + * The idea is to have debug builds flag up inconsistent bignums when they + * occur. If that occurs in a bn_fix_top(), we examine the code in question; if + * the use of bn_fix_top() was appropriate (ie. it follows directly after code + * that manipulates the bignum) it is converted to bn_correct_top(), and if it + * was not appropriate, we convert it permanently to bn_check_top() and track + * down the cause of the bug. Eventually, no internal code should be using the + * bn_fix_top() macro. External applications and libraries should try this with + * their own code too, both in terms of building against the openssl headers + * with BN_DEBUG defined *and* linking with a version of OpenSSL built with it + * defined. This not only improves external code, it provides more test + * coverage for openssl's own code. + */ + +#ifdef BN_DEBUG + +/* We only need assert() when debugging */ +#include + +#ifdef BN_DEBUG_RAND +/* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */ +#ifndef RAND_pseudo_bytes +int RAND_pseudo_bytes(unsigned char *buf,int num); +#define BN_DEBUG_TRIX +#endif +#define bn_pollute(a) \ + do { \ + const BIGNUM *_bnum1 = (a); \ + if(_bnum1->top < _bnum1->dmax) { \ + unsigned char _tmp_char; \ + /* We cast away const without the compiler knowing, any \ + * *genuinely* constant variables that aren't mutable \ + * wouldn't be constructed with top!=dmax. */ \ + BN_ULONG *_not_const; \ + memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \ + RAND_pseudo_bytes(&_tmp_char, 1); \ + memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \ + (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \ + } \ + } while(0) +#ifdef BN_DEBUG_TRIX +#undef RAND_pseudo_bytes +#endif +#else +#define bn_pollute(a) +#endif +#define bn_check_top(a) \ + do { \ + const BIGNUM *_bnum2 = (a); \ + if (_bnum2 != NULL) { \ + assert((_bnum2->top == 0) || \ + (_bnum2->d[_bnum2->top - 1] != 0)); \ + bn_pollute(_bnum2); \ + } \ + } while(0) + +#define bn_fix_top(a) bn_check_top(a) + +#else /* !BN_DEBUG */ + +#define bn_pollute(a) +#define bn_check_top(a) +#define bn_fix_top(a) bn_correct_top(a) + +#endif + +#define bn_correct_top(a) \ + { \ + BN_ULONG *ftl; \ + if ((a)->top > 0) \ + { \ + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ + if (*(ftl--)) break; \ + } \ + bn_pollute(a); \ + } + +BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); +BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); +void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); +BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); +BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); +BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); + +/* Primes from RFC 2409 */ +BIGNUM *get_rfc2409_prime_768(BIGNUM *bn); +BIGNUM *get_rfc2409_prime_1024(BIGNUM *bn); + +/* Primes from RFC 3526 */ +BIGNUM *get_rfc3526_prime_1536(BIGNUM *bn); +BIGNUM *get_rfc3526_prime_2048(BIGNUM *bn); +BIGNUM *get_rfc3526_prime_3072(BIGNUM *bn); +BIGNUM *get_rfc3526_prime_4096(BIGNUM *bn); +BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn); +BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn); + +int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_BN_strings(void); + +/* Error codes for the BN functions. */ + +/* Function codes. */ +#define BN_F_BNRAND 127 +#define BN_F_BN_BLINDING_CONVERT_EX 100 +#define BN_F_BN_BLINDING_CREATE_PARAM 128 +#define BN_F_BN_BLINDING_INVERT_EX 101 +#define BN_F_BN_BLINDING_NEW 102 +#define BN_F_BN_BLINDING_UPDATE 103 +#define BN_F_BN_BN2DEC 104 +#define BN_F_BN_BN2HEX 105 +#define BN_F_BN_CTX_GET 116 +#define BN_F_BN_CTX_NEW 106 +#define BN_F_BN_CTX_START 129 +#define BN_F_BN_DIV 107 +#define BN_F_BN_DIV_NO_BRANCH 138 +#define BN_F_BN_DIV_RECP 130 +#define BN_F_BN_EXP 123 +#define BN_F_BN_EXPAND2 108 +#define BN_F_BN_EXPAND_INTERNAL 120 +#define BN_F_BN_GF2M_MOD 131 +#define BN_F_BN_GF2M_MOD_EXP 132 +#define BN_F_BN_GF2M_MOD_MUL 133 +#define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134 +#define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135 +#define BN_F_BN_GF2M_MOD_SQR 136 +#define BN_F_BN_GF2M_MOD_SQRT 137 +#define BN_F_BN_MOD_EXP2_MONT 118 +#define BN_F_BN_MOD_EXP_MONT 109 +#define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124 +#define BN_F_BN_MOD_EXP_MONT_WORD 117 +#define BN_F_BN_MOD_EXP_RECP 125 +#define BN_F_BN_MOD_EXP_SIMPLE 126 +#define BN_F_BN_MOD_INVERSE 110 +#define BN_F_BN_MOD_INVERSE_NO_BRANCH 139 +#define BN_F_BN_MOD_LSHIFT_QUICK 119 +#define BN_F_BN_MOD_MUL_RECIPROCAL 111 +#define BN_F_BN_MOD_SQRT 121 +#define BN_F_BN_MPI2BN 112 +#define BN_F_BN_NEW 113 +#define BN_F_BN_RAND 114 +#define BN_F_BN_RAND_RANGE 122 +#define BN_F_BN_USUB 115 + +/* Reason codes. */ +#define BN_R_ARG2_LT_ARG3 100 +#define BN_R_BAD_RECIPROCAL 101 +#define BN_R_BIGNUM_TOO_LONG 114 +#define BN_R_CALLED_WITH_EVEN_MODULUS 102 +#define BN_R_DIV_BY_ZERO 103 +#define BN_R_ENCODING_ERROR 104 +#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 +#define BN_R_INPUT_NOT_REDUCED 110 +#define BN_R_INVALID_LENGTH 106 +#define BN_R_INVALID_RANGE 115 +#define BN_R_NOT_A_SQUARE 111 +#define BN_R_NOT_INITIALIZED 107 +#define BN_R_NO_INVERSE 108 +#define BN_R_NO_SOLUTION 116 +#define BN_R_P_IS_NOT_PRIME 112 +#define BN_R_TOO_MANY_ITERATIONS 113 +#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/buffer.h b/石器时代8.5客户端最新源代码/石器源码/openssl/buffer.h new file mode 100644 index 0000000..1db9607 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/buffer.h @@ -0,0 +1,118 @@ +/* crypto/buffer/buffer.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_BUFFER_H +#define HEADER_BUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if !defined(NO_SYS_TYPES_H) +#include +#endif + +/* Already declared in ossl_typ.h */ +/* typedef struct buf_mem_st BUF_MEM; */ + +struct buf_mem_st + { + int length; /* current number of bytes */ + char *data; + int max; /* size of buffer */ + }; + +BUF_MEM *BUF_MEM_new(void); +void BUF_MEM_free(BUF_MEM *a); +int BUF_MEM_grow(BUF_MEM *str, int len); +int BUF_MEM_grow_clean(BUF_MEM *str, int len); +char * BUF_strdup(const char *str); +char * BUF_strndup(const char *str, size_t siz); +void * BUF_memdup(const void *data, size_t siz); + +/* safe string functions */ +size_t BUF_strlcpy(char *dst,const char *src,size_t siz); +size_t BUF_strlcat(char *dst,const char *src,size_t siz); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_BUF_strings(void); + +/* Error codes for the BUF functions. */ + +/* Function codes. */ +#define BUF_F_BUF_MEMDUP 103 +#define BUF_F_BUF_MEM_GROW 100 +#define BUF_F_BUF_MEM_GROW_CLEAN 105 +#define BUF_F_BUF_MEM_NEW 101 +#define BUF_F_BUF_STRDUP 102 +#define BUF_F_BUF_STRNDUP 104 + +/* Reason codes. */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/cast.h b/石器时代8.5客户端最新源代码/石器源码/openssl/cast.h new file mode 100644 index 0000000..1faf580 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/cast.h @@ -0,0 +1,107 @@ +/* crypto/cast/cast.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_CAST_H +#define HEADER_CAST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifdef OPENSSL_NO_CAST +#error CAST is disabled. +#endif + +#define CAST_ENCRYPT 1 +#define CAST_DECRYPT 0 + +#define CAST_LONG unsigned long + +#define CAST_BLOCK 8 +#define CAST_KEY_LENGTH 16 + +typedef struct cast_key_st + { + CAST_LONG data[32]; + int short_key; /* Use reduced rounds for short key */ + } CAST_KEY; + +#ifdef OPENSSL_FIPS +void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); +#endif +void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); +void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key, + int enc); +void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); +void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + CAST_KEY *ks, unsigned char *iv, int enc); +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/comp.h b/石器时代8.5客户端最新源代码/石器源码/openssl/comp.h new file mode 100644 index 0000000..4b405c7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/comp.h @@ -0,0 +1,80 @@ + +#ifndef HEADER_COMP_H +#define HEADER_COMP_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct comp_ctx_st COMP_CTX; + +typedef struct comp_method_st + { + int type; /* NID for compression library */ + const char *name; /* A text string to identify the library */ + int (*init)(COMP_CTX *ctx); + void (*finish)(COMP_CTX *ctx); + int (*compress)(COMP_CTX *ctx, + unsigned char *out, unsigned int olen, + unsigned char *in, unsigned int ilen); + int (*expand)(COMP_CTX *ctx, + unsigned char *out, unsigned int olen, + unsigned char *in, unsigned int ilen); + /* The following two do NOTHING, but are kept for backward compatibility */ + long (*ctrl)(void); + long (*callback_ctrl)(void); + } COMP_METHOD; + +struct comp_ctx_st + { + COMP_METHOD *meth; + unsigned long compress_in; + unsigned long compress_out; + unsigned long expand_in; + unsigned long expand_out; + + CRYPTO_EX_DATA ex_data; + }; + + +COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); +void COMP_CTX_free(COMP_CTX *ctx); +int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +COMP_METHOD *COMP_rle(void ); +COMP_METHOD *COMP_zlib(void ); +void COMP_zlib_cleanup(void); + +#ifdef HEADER_BIO_H +#ifdef ZLIB +BIO_METHOD *BIO_f_zlib(void); +#endif +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_COMP_strings(void); + +/* Error codes for the COMP functions. */ + +/* Function codes. */ +#define COMP_F_BIO_ZLIB_FLUSH 99 +#define COMP_F_BIO_ZLIB_NEW 100 +#define COMP_F_BIO_ZLIB_READ 101 +#define COMP_F_BIO_ZLIB_WRITE 102 + +/* Reason codes. */ +#define COMP_R_ZLIB_DEFLATE_ERROR 99 +#define COMP_R_ZLIB_INFLATE_ERROR 100 +#define COMP_R_ZLIB_NOT_SUPPORTED 101 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/conf.h b/石器时代8.5客户端最新源代码/石器源码/openssl/conf.h new file mode 100644 index 0000000..8aa06bc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/conf.h @@ -0,0 +1,254 @@ +/* crypto/conf/conf.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_CONF_H +#define HEADER_CONF_H + +#include +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct + { + char *section; + char *name; + char *value; + } CONF_VALUE; + +DECLARE_STACK_OF(CONF_VALUE) +DECLARE_STACK_OF(CONF_MODULE) +DECLARE_STACK_OF(CONF_IMODULE) + +struct conf_st; +struct conf_method_st; +typedef struct conf_method_st CONF_METHOD; + +struct conf_method_st + { + const char *name; + CONF *(*create)(CONF_METHOD *meth); + int (*init)(CONF *conf); + int (*destroy)(CONF *conf); + int (*destroy_data)(CONF *conf); + int (*load_bio)(CONF *conf, BIO *bp, long *eline); + int (*dump)(const CONF *conf, BIO *bp); + int (*is_number)(const CONF *conf, char c); + int (*to_int)(const CONF *conf, char c); + int (*load)(CONF *conf, const char *name, long *eline); + }; + +/* Module definitions */ + +typedef struct conf_imodule_st CONF_IMODULE; +typedef struct conf_module_st CONF_MODULE; + +/* DSO module function typedefs */ +typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf); +typedef void conf_finish_func(CONF_IMODULE *md); + +#define CONF_MFLAGS_IGNORE_ERRORS 0x1 +#define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2 +#define CONF_MFLAGS_SILENT 0x4 +#define CONF_MFLAGS_NO_DSO 0x8 +#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 +#define CONF_MFLAGS_DEFAULT_SECTION 0x20 + +int CONF_set_default_method(CONF_METHOD *meth); +void CONF_set_nconf(CONF *conf,LHASH *hash); +LHASH *CONF_load(LHASH *conf,const char *file,long *eline); +#ifndef OPENSSL_NO_FP_API +LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); +#endif +LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline); +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section); +char *CONF_get_string(LHASH *conf,const char *group,const char *name); +long CONF_get_number(LHASH *conf,const char *group,const char *name); +void CONF_free(LHASH *conf); +int CONF_dump_fp(LHASH *conf, FILE *out); +int CONF_dump_bio(LHASH *conf, BIO *out); + +void OPENSSL_config(const char *config_name); +void OPENSSL_no_config(void); + +/* New conf code. The semantics are different from the functions above. + If that wasn't the case, the above functions would have been replaced */ + +struct conf_st + { + CONF_METHOD *meth; + void *meth_data; + LHASH *data; + }; + +CONF *NCONF_new(CONF_METHOD *meth); +CONF_METHOD *NCONF_default(void); +CONF_METHOD *NCONF_WIN32(void); +#if 0 /* Just to give you an idea of what I have in mind */ +CONF_METHOD *NCONF_XML(void); +#endif +void NCONF_free(CONF *conf); +void NCONF_free_data(CONF *conf); + +int NCONF_load(CONF *conf,const char *file,long *eline); +#ifndef OPENSSL_NO_FP_API +int NCONF_load_fp(CONF *conf, FILE *fp,long *eline); +#endif +int NCONF_load_bio(CONF *conf, BIO *bp,long *eline); +STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section); +char *NCONF_get_string(const CONF *conf,const char *group,const char *name); +int NCONF_get_number_e(const CONF *conf,const char *group,const char *name, + long *result); +int NCONF_dump_fp(const CONF *conf, FILE *out); +int NCONF_dump_bio(const CONF *conf, BIO *out); + +#if 0 /* The following function has no error checking, + and should therefore be avoided */ +long NCONF_get_number(CONF *conf,char *group,char *name); +#else +#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r) +#endif + +/* Module functions */ + +int CONF_modules_load(const CONF *cnf, const char *appname, + unsigned long flags); +int CONF_modules_load_file(const char *filename, const char *appname, + unsigned long flags); +void CONF_modules_unload(int all); +void CONF_modules_finish(void); +void CONF_modules_free(void); +int CONF_module_add(const char *name, conf_init_func *ifunc, + conf_finish_func *ffunc); + +const char *CONF_imodule_get_name(const CONF_IMODULE *md); +const char *CONF_imodule_get_value(const CONF_IMODULE *md); +void *CONF_imodule_get_usr_data(const CONF_IMODULE *md); +void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data); +CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md); +unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md); +void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags); +void *CONF_module_get_usr_data(CONF_MODULE *pmod); +void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data); + +char *CONF_get1_default_config_file(void); + +int CONF_parse_list(const char *list, int sep, int nospc, + int (*list_cb)(const char *elem, int len, void *usr), void *arg); + +void OPENSSL_load_builtin_modules(void); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_CONF_strings(void); + +/* Error codes for the CONF functions. */ + +/* Function codes. */ +#define CONF_F_CONF_DUMP_FP 104 +#define CONF_F_CONF_LOAD 100 +#define CONF_F_CONF_LOAD_BIO 102 +#define CONF_F_CONF_LOAD_FP 103 +#define CONF_F_CONF_MODULES_LOAD 116 +#define CONF_F_DEF_LOAD 120 +#define CONF_F_DEF_LOAD_BIO 121 +#define CONF_F_MODULE_INIT 115 +#define CONF_F_MODULE_LOAD_DSO 117 +#define CONF_F_MODULE_RUN 118 +#define CONF_F_NCONF_DUMP_BIO 105 +#define CONF_F_NCONF_DUMP_FP 106 +#define CONF_F_NCONF_GET_NUMBER 107 +#define CONF_F_NCONF_GET_NUMBER_E 112 +#define CONF_F_NCONF_GET_SECTION 108 +#define CONF_F_NCONF_GET_STRING 109 +#define CONF_F_NCONF_LOAD 113 +#define CONF_F_NCONF_LOAD_BIO 110 +#define CONF_F_NCONF_LOAD_FP 114 +#define CONF_F_NCONF_NEW 111 +#define CONF_F_STR_COPY 101 + +/* Reason codes. */ +#define CONF_R_ERROR_LOADING_DSO 110 +#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 +#define CONF_R_MISSING_EQUAL_SIGN 101 +#define CONF_R_MISSING_FINISH_FUNCTION 111 +#define CONF_R_MISSING_INIT_FUNCTION 112 +#define CONF_R_MODULE_INITIALIZATION_ERROR 109 +#define CONF_R_NO_CLOSE_BRACE 102 +#define CONF_R_NO_CONF 105 +#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106 +#define CONF_R_NO_SECTION 107 +#define CONF_R_NO_SUCH_FILE 114 +#define CONF_R_NO_VALUE 108 +#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 +#define CONF_R_UNKNOWN_MODULE_NAME 113 +#define CONF_R_VARIABLE_HAS_NO_VALUE 104 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/conf_api.h b/石器时代8.5客户端最新源代码/石器源码/openssl/conf_api.h new file mode 100644 index 0000000..87a954a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/conf_api.h @@ -0,0 +1,89 @@ +/* conf_api.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_CONF_API_H +#define HEADER_CONF_API_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Up until OpenSSL 0.9.5a, this was new_section */ +CONF_VALUE *_CONF_new_section(CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was get_section */ +CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ +STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, + const char *section); + +int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); +char *_CONF_get_string(const CONF *conf, const char *section, + const char *name); +long _CONF_get_number(const CONF *conf, const char *section, const char *name); + +int _CONF_new_data(CONF *conf); +void _CONF_free_data(CONF *conf); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/crypto.h b/石器时代8.5客户端最新源代码/石器源码/openssl/crypto.h new file mode 100644 index 0000000..0e4fb07 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/crypto.h @@ -0,0 +1,619 @@ +/* crypto/crypto.h */ +/* ==================================================================== + * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_CRYPTO_H +#define HEADER_CRYPTO_H + +#include + +#include + +#ifndef OPENSSL_NO_FP_API +#include +#endif + +#include +#include +#include +#include + +#ifdef CHARSET_EBCDIC +#include +#endif + +/* Resolve problems on some operating systems with symbol names that clash + one way or another */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Backward compatibility to SSLeay */ +/* This is more to be used to check the correct DLL is being used + * in the MS world. */ +#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER +#define SSLEAY_VERSION 0 +/* #define SSLEAY_OPTIONS 1 no longer supported */ +#define SSLEAY_CFLAGS 2 +#define SSLEAY_BUILT_ON 3 +#define SSLEAY_PLATFORM 4 +#define SSLEAY_DIR 5 + +/* Already declared in ossl_typ.h */ +#if 0 +typedef struct crypto_ex_data_st CRYPTO_EX_DATA; +/* Called when a new object is created */ +typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +/* Called when an object is free()ed */ +typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +/* Called when we need to dup an object */ +typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, + int idx, long argl, void *argp); +#endif + +/* A generic structure to pass assorted data in a expandable way */ +typedef struct openssl_item_st + { + int code; + void *value; /* Not used for flag attributes */ + size_t value_size; /* Max size of value for output, length for input */ + size_t *value_length; /* Returned length of value for output */ + } OPENSSL_ITEM; + + +/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock + * names in cryptlib.c + */ + +#define CRYPTO_LOCK_ERR 1 +#define CRYPTO_LOCK_EX_DATA 2 +#define CRYPTO_LOCK_X509 3 +#define CRYPTO_LOCK_X509_INFO 4 +#define CRYPTO_LOCK_X509_PKEY 5 +#define CRYPTO_LOCK_X509_CRL 6 +#define CRYPTO_LOCK_X509_REQ 7 +#define CRYPTO_LOCK_DSA 8 +#define CRYPTO_LOCK_RSA 9 +#define CRYPTO_LOCK_EVP_PKEY 10 +#define CRYPTO_LOCK_X509_STORE 11 +#define CRYPTO_LOCK_SSL_CTX 12 +#define CRYPTO_LOCK_SSL_CERT 13 +#define CRYPTO_LOCK_SSL_SESSION 14 +#define CRYPTO_LOCK_SSL_SESS_CERT 15 +#define CRYPTO_LOCK_SSL 16 +#define CRYPTO_LOCK_SSL_METHOD 17 +#define CRYPTO_LOCK_RAND 18 +#define CRYPTO_LOCK_RAND2 19 +#define CRYPTO_LOCK_MALLOC 20 +#define CRYPTO_LOCK_BIO 21 +#define CRYPTO_LOCK_GETHOSTBYNAME 22 +#define CRYPTO_LOCK_GETSERVBYNAME 23 +#define CRYPTO_LOCK_READDIR 24 +#define CRYPTO_LOCK_RSA_BLINDING 25 +#define CRYPTO_LOCK_DH 26 +#define CRYPTO_LOCK_MALLOC2 27 +#define CRYPTO_LOCK_DSO 28 +#define CRYPTO_LOCK_DYNLOCK 29 +#define CRYPTO_LOCK_ENGINE 30 +#define CRYPTO_LOCK_UI 31 +#define CRYPTO_LOCK_ECDSA 32 +#define CRYPTO_LOCK_EC 33 +#define CRYPTO_LOCK_ECDH 34 +#define CRYPTO_LOCK_BN 35 +#define CRYPTO_LOCK_EC_PRE_COMP 36 +#define CRYPTO_LOCK_STORE 37 +#define CRYPTO_LOCK_COMP 38 +#ifndef OPENSSL_FIPS +#define CRYPTO_NUM_LOCKS 39 +#else +#define CRYPTO_LOCK_FIPS 39 +#define CRYPTO_LOCK_FIPS2 40 +#define CRYPTO_NUM_LOCKS 41 +#endif + +#define CRYPTO_LOCK 1 +#define CRYPTO_UNLOCK 2 +#define CRYPTO_READ 4 +#define CRYPTO_WRITE 8 + +#ifndef OPENSSL_NO_LOCKING +#ifndef CRYPTO_w_lock +#define CRYPTO_w_lock(type) \ + CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) +#define CRYPTO_w_unlock(type) \ + CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) +#define CRYPTO_r_lock(type) \ + CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__) +#define CRYPTO_r_unlock(type) \ + CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__) +#define CRYPTO_add(addr,amount,type) \ + CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) +#endif +#else +#define CRYPTO_w_lock(a) +#define CRYPTO_w_unlock(a) +#define CRYPTO_r_lock(a) +#define CRYPTO_r_unlock(a) +#define CRYPTO_add(a,b,c) ((*(a))+=(b)) +#endif + +/* Some applications as well as some parts of OpenSSL need to allocate + and deallocate locks in a dynamic fashion. The following typedef + makes this possible in a type-safe manner. */ +/* struct CRYPTO_dynlock_value has to be defined by the application. */ +typedef struct + { + int references; + struct CRYPTO_dynlock_value *data; + } CRYPTO_dynlock; + + +/* The following can be used to detect memory leaks in the SSLeay library. + * It used, it turns on malloc checking */ + +#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */ +#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */ +#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */ +#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */ + +/* The following are bit values to turn on or off options connected to the + * malloc checking functionality */ + +/* Adds time to the memory checking information */ +#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */ +/* Adds thread number to the memory checking information */ +#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */ + +#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD) + + +/* predec of the BIO type */ +typedef struct bio_st BIO_dummy; + +struct crypto_ex_data_st + { + STACK *sk; + int dummy; /* gcc is screwing up this data structure :-( */ + }; + +/* This stuff is basically class callback functions + * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */ + +typedef struct crypto_ex_data_func_st + { + long argl; /* Arbitary long */ + void *argp; /* Arbitary void * */ + CRYPTO_EX_new *new_func; + CRYPTO_EX_free *free_func; + CRYPTO_EX_dup *dup_func; + } CRYPTO_EX_DATA_FUNCS; + +DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS) + +/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA + * entry. + */ + +#define CRYPTO_EX_INDEX_BIO 0 +#define CRYPTO_EX_INDEX_SSL 1 +#define CRYPTO_EX_INDEX_SSL_CTX 2 +#define CRYPTO_EX_INDEX_SSL_SESSION 3 +#define CRYPTO_EX_INDEX_X509_STORE 4 +#define CRYPTO_EX_INDEX_X509_STORE_CTX 5 +#define CRYPTO_EX_INDEX_RSA 6 +#define CRYPTO_EX_INDEX_DSA 7 +#define CRYPTO_EX_INDEX_DH 8 +#define CRYPTO_EX_INDEX_ENGINE 9 +#define CRYPTO_EX_INDEX_X509 10 +#define CRYPTO_EX_INDEX_UI 11 +#define CRYPTO_EX_INDEX_ECDSA 12 +#define CRYPTO_EX_INDEX_ECDH 13 +#define CRYPTO_EX_INDEX_COMP 14 +#define CRYPTO_EX_INDEX_STORE 15 + +/* Dynamically assigned indexes start from this value (don't use directly, use + * via CRYPTO_ex_data_new_class). */ +#define CRYPTO_EX_INDEX_USER 100 + + +/* This is the default callbacks, but we can have others as well: + * this is needed in Win32 where the application malloc and the + * library malloc may not be the same. + */ +#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\ + malloc, realloc, free) + +#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD +# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ +# define CRYPTO_MDEBUG +# endif +#endif + +/* Set standard debugging functions (not done by default + * unless CRYPTO_MDEBUG is defined) */ +void CRYPTO_malloc_debug_init(void); + +int CRYPTO_mem_ctrl(int mode); +int CRYPTO_is_mem_check_on(void); + +/* for applications */ +#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) +#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) + +/* for library-internal use */ +#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) +#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) +#define is_MemCheck_on() CRYPTO_is_mem_check_on() + +#define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) +#define OPENSSL_strdup(str) CRYPTO_strdup((str),__FILE__,__LINE__) +#define OPENSSL_realloc(addr,num) \ + CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__) +#define OPENSSL_realloc_clean(addr,old_num,num) \ + CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__) +#define OPENSSL_remalloc(addr,num) \ + CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__) +#define OPENSSL_freeFunc CRYPTO_free +#define OPENSSL_free(addr) CRYPTO_free(addr) + +#define OPENSSL_malloc_locked(num) \ + CRYPTO_malloc_locked((int)num,__FILE__,__LINE__) +#define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr) + + +const char *SSLeay_version(int type); +unsigned long SSLeay(void); + +int OPENSSL_issetugid(void); + +/* An opaque type representing an implementation of "ex_data" support */ +typedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL; +/* Return an opaque pointer to the current "ex_data" implementation */ +const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void); +/* Sets the "ex_data" implementation to be used (if it's not too late) */ +int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i); +/* Get a new "ex_data" class, and return the corresponding "class_index" */ +int CRYPTO_ex_data_new_class(void); +/* Within a given class, get/register a new index */ +int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, + CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, + CRYPTO_EX_free *free_func); +/* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given + * class (invokes whatever per-class callbacks are applicable) */ +int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); +int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, + CRYPTO_EX_DATA *from); +void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); +/* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index + * (relative to the class type involved) */ +int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); +void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad,int idx); +/* This function cleans up all "ex_data" state. It mustn't be called under + * potential race-conditions. */ +void CRYPTO_cleanup_all_ex_data(void); + +int CRYPTO_get_new_lockid(char *name); + +int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */ +void CRYPTO_lock(int mode, int type,const char *file,int line); +void CRYPTO_set_locking_callback(void (*func)(int mode,int type, + const char *file,int line)); +void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file, + int line); +void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type, + const char *file, int line)); +int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type, + const char *file,int line); +void CRYPTO_set_id_callback(unsigned long (*func)(void)); +unsigned long (*CRYPTO_get_id_callback(void))(void); +unsigned long CRYPTO_thread_id(void); +const char *CRYPTO_get_lock_name(int type); +int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file, + int line); + +void int_CRYPTO_set_do_dynlock_callback( + void (*do_dynlock_cb)(int mode, int type, const char *file, int line)); + +int CRYPTO_get_new_dynlockid(void); +void CRYPTO_destroy_dynlockid(int i); +struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i); +void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, int line)); +void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)); +void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, const char *file, int line)); +struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file,int line); +void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file,int line); +void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file,int line); + +/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- + * call the latter last if you need different functions */ +int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *)); +int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *)); +int CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int), + void *(*r)(void *,size_t,const char *,int), + void (*f)(void *)); +int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int), + void (*free_func)(void *)); +int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int), + void (*r)(void *,void *,int,const char *,int,int), + void (*f)(void *,int), + void (*so)(long), + long (*go)(void)); +void CRYPTO_set_mem_info_functions( + int (*push_info_fn)(const char *info, const char *file, int line), + int (*pop_info_fn)(void), + int (*remove_all_info_fn)(void)); +void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *)); +void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *)); +void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int), + void *(**r)(void *, size_t,const char *,int), + void (**f)(void *)); +void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int), + void (**f)(void *)); +void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int), + void (**r)(void *,void *,int,const char *,int,int), + void (**f)(void *,int), + void (**so)(long), + long (**go)(void)); + +void *CRYPTO_malloc_locked(int num, const char *file, int line); +void CRYPTO_free_locked(void *); +void *CRYPTO_malloc(int num, const char *file, int line); +char *CRYPTO_strdup(const char *str, const char *file, int line); +void CRYPTO_free(void *); +void *CRYPTO_realloc(void *addr,int num, const char *file, int line); +void *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file, + int line); +void *CRYPTO_remalloc(void *addr,int num, const char *file, int line); + +void OPENSSL_cleanse(void *ptr, size_t len); + +void CRYPTO_set_mem_debug_options(long bits); +long CRYPTO_get_mem_debug_options(void); + +#define CRYPTO_push_info(info) \ + CRYPTO_push_info_(info, __FILE__, __LINE__); +int CRYPTO_push_info_(const char *info, const char *file, int line); +int CRYPTO_pop_info(void); +int CRYPTO_remove_all_info(void); + + +/* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro; + * used as default in CRYPTO_MDEBUG compilations): */ +/* The last argument has the following significance: + * + * 0: called before the actual memory allocation has taken place + * 1: called after the actual memory allocation has taken place + */ +void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p); +void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p); +void CRYPTO_dbg_free(void *addr,int before_p); +/* Tell the debugging code about options. By default, the following values + * apply: + * + * 0: Clear all options. + * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option. + * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option. + * V_CRYPTO_MDEBUG_ALL (3): 1 + 2 + */ +void CRYPTO_dbg_set_options(long bits); +long CRYPTO_dbg_get_options(void); + +int CRYPTO_dbg_push_info(const char *info, const char *file, int line); +int CRYPTO_dbg_pop_info(void); +int CRYPTO_dbg_remove_all_info(void); + +#ifndef OPENSSL_NO_FP_API +void CRYPTO_mem_leaks_fp(FILE *); +#endif +void CRYPTO_mem_leaks(struct bio_st *bio); +/* unsigned long order, char *file, int line, int num_bytes, char *addr */ +typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *); +void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb); + +/* die if we have to */ +void OpenSSLDie(const char *file,int line,const char *assertion); +#define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1)) + +unsigned long *OPENSSL_ia32cap_loc(void); +#define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc())) +int OPENSSL_isservice(void); + +#ifdef OPENSSL_FIPS +#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \ + alg " previous FIPS forbidden algorithm error ignored"); + +#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \ + #alg " Algorithm forbidden in FIPS mode"); + +#ifdef OPENSSL_FIPS_STRICT +#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg) +#else +#define FIPS_BAD_ALGORITHM(alg) \ + { \ + FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \ + ERR_add_error_data(2, "Algorithm=", #alg); \ + return 0; \ + } +#endif + +/* Low level digest API blocking macro */ + +#define FIPS_NON_FIPS_MD_Init(alg) \ + int alg##_Init(alg##_CTX *c) \ + { \ + if (FIPS_mode()) \ + FIPS_BAD_ALGORITHM(alg) \ + return private_##alg##_Init(c); \ + } \ + int private_##alg##_Init(alg##_CTX *c) + +/* For ciphers the API often varies from cipher to cipher and each needs to + * be treated as a special case. Variable key length ciphers (Blowfish, RC4, + * CAST) however are very similar and can use a blocking macro. + */ + +#define FIPS_NON_FIPS_VCIPHER_Init(alg) \ + void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \ + { \ + if (FIPS_mode()) \ + FIPS_BAD_ABORT(alg) \ + private_##alg##_set_key(key, len, data); \ + } \ + void private_##alg##_set_key(alg##_KEY *key, int len, \ + const unsigned char *data) + +#else + +#define FIPS_NON_FIPS_VCIPHER_Init(alg) \ + void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) + +#define FIPS_NON_FIPS_MD_Init(alg) \ + int alg##_Init(alg##_CTX *c) + +#endif /* def OPENSSL_FIPS */ + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_CRYPTO_strings(void); + +#define OPENSSL_HAVE_INIT 1 +void OPENSSL_init(void); + +/* Error codes for the CRYPTO functions. */ + +/* Function codes. */ +#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 +#define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103 +#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101 +#define CRYPTO_F_CRYPTO_SET_EX_DATA 102 +#define CRYPTO_F_DEF_ADD_INDEX 104 +#define CRYPTO_F_DEF_GET_CLASS 105 +#define CRYPTO_F_INT_DUP_EX_DATA 106 +#define CRYPTO_F_INT_FREE_EX_DATA 107 +#define CRYPTO_F_INT_NEW_EX_DATA 108 + +/* Reason codes. */ +#define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/des.h b/石器时代8.5客户端最新源代码/石器源码/openssl/des.h new file mode 100644 index 0000000..92b6663 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/des.h @@ -0,0 +1,245 @@ +/* crypto/des/des.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_NEW_DES_H +#define HEADER_NEW_DES_H + +#include /* OPENSSL_EXTERN, OPENSSL_NO_DES, + DES_LONG (via openssl/opensslconf.h */ + +#ifdef OPENSSL_NO_DES +#error DES is disabled. +#endif + +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char DES_cblock[8]; +typedef /* const */ unsigned char const_DES_cblock[8]; +/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * + * and const_DES_cblock * are incompatible pointer types. */ + +typedef struct DES_ks + { + union + { + DES_cblock cblock; + /* make sure things are correct size on machines with + * 8 byte longs */ + DES_LONG deslong[2]; + } ks[16]; + } DES_key_schedule; + +#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT +# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT +# define OPENSSL_ENABLE_OLD_DES_SUPPORT +# endif +#endif + +#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT +# include +#endif + +#define DES_KEY_SZ (sizeof(DES_cblock)) +#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) + +#define DES_ENCRYPT 1 +#define DES_DECRYPT 0 + +#define DES_CBC_MODE 0 +#define DES_PCBC_MODE 1 + +#define DES_ecb2_encrypt(i,o,k1,k2,e) \ + DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */ +#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) +OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */ +#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) + +const char *DES_options(void); +void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, + DES_key_schedule *ks1,DES_key_schedule *ks2, + DES_key_schedule *ks3, int enc); +DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, + long length,DES_key_schedule *schedule, + const_DES_cblock *ivec); +/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ +void DES_cbc_encrypt(const unsigned char *input,unsigned char *output, + long length,DES_key_schedule *schedule,DES_cblock *ivec, + int enc); +void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output, + long length,DES_key_schedule *schedule,DES_cblock *ivec, + int enc); +void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output, + long length,DES_key_schedule *schedule,DES_cblock *ivec, + const_DES_cblock *inw,const_DES_cblock *outw,int enc); +void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, + long length,DES_key_schedule *schedule,DES_cblock *ivec, + int enc); +void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, + DES_key_schedule *ks,int enc); + +/* This is the DES encryption function that gets called by just about + every other DES routine in the library. You should not use this + function except to implement 'modes' of DES. I say this because the + functions that call this routine do the conversion from 'char *' to + long, and this needs to be done to make sure 'non-aligned' memory + access do not occur. The characters are loaded 'little endian'. + Data is a pointer to 2 unsigned long's and ks is the + DES_key_schedule to use. enc, is non zero specifies encryption, + zero if decryption. */ +void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc); + +/* This functions is the same as DES_encrypt1() except that the DES + initial permutation (IP) and final permutation (FP) have been left + out. As for DES_encrypt1(), you should not use this function. + It is used by the routines in the library that implement triple DES. + IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same + as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */ +void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc); + +void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, + long length, + DES_key_schedule *ks1,DES_key_schedule *ks2, + DES_key_schedule *ks3,DES_cblock *ivec,int enc); +void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, + long length, + DES_key_schedule *ks1,DES_key_schedule *ks2, + DES_key_schedule *ks3, + DES_cblock *ivec1,DES_cblock *ivec2, + int enc); +void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, + long length,DES_key_schedule *ks1, + DES_key_schedule *ks2,DES_key_schedule *ks3, + DES_cblock *ivec,int *num,int enc); +void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, + int numbits,long length,DES_key_schedule *ks1, + DES_key_schedule *ks2,DES_key_schedule *ks3, + DES_cblock *ivec,int enc); +void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, + long length,DES_key_schedule *ks1, + DES_key_schedule *ks2,DES_key_schedule *ks3, + DES_cblock *ivec,int *num); +#if 0 +void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white, + DES_cblock *out_white); +#endif + +int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, + DES_cblock *iv); +int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched, + DES_cblock *iv); +char *DES_fcrypt(const char *buf,const char *salt, char *ret); +char *DES_crypt(const char *buf,const char *salt); +void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, + long length,DES_key_schedule *schedule,DES_cblock *ivec); +void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output, + long length,DES_key_schedule *schedule,DES_cblock *ivec, + int enc); +DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[], + long length,int out_count,DES_cblock *seed); +int DES_random_key(DES_cblock *ret); +void DES_set_odd_parity(DES_cblock *key); +int DES_check_key_parity(const_DES_cblock *key); +int DES_is_weak_key(const_DES_cblock *key); +/* DES_set_key (= set_key = DES_key_sched = key_sched) calls + * DES_set_key_checked if global variable DES_check_key is set, + * DES_set_key_unchecked otherwise. */ +int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); +int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule); +int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule); +void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); +void DES_string_to_key(const char *str,DES_cblock *key); +void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2); +void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, + DES_key_schedule *schedule,DES_cblock *ivec,int *num, + int enc); +void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, + DES_key_schedule *schedule,DES_cblock *ivec,int *num); + +int DES_read_password(DES_cblock *key, const char *prompt, int verify); +int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt, + int verify); + +#define DES_fixup_key_parity DES_set_odd_parity + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/des_old.h b/石器时代8.5客户端最新源代码/石器源码/openssl/des_old.h new file mode 100644 index 0000000..2b2c372 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/des_old.h @@ -0,0 +1,446 @@ +/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */ + +/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + * + * The function names in here are deprecated and are only present to + * provide an interface compatible with openssl 0.9.6 and older as + * well as libdes. OpenSSL now provides functions where "des_" has + * been replaced with "DES_" in the names, to make it possible to + * make incompatible changes that are needed for C type security and + * other stuff. + * + * This include files has two compatibility modes: + * + * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API + * that is compatible with libdes and SSLeay. + * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an + * API that is compatible with OpenSSL 0.9.5x to 0.9.6x. + * + * Note that these modes break earlier snapshots of OpenSSL, where + * libdes compatibility was the only available mode or (later on) the + * prefered compatibility mode. However, after much consideration + * (and more or less violent discussions with external parties), it + * was concluded that OpenSSL should be compatible with earlier versions + * of itself before anything else. Also, in all honesty, libdes is + * an old beast that shouldn't really be used any more. + * + * Please consider starting to use the DES_ functions rather than the + * des_ ones. The des_ functions will disappear completely before + * OpenSSL 1.0! + * + * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + */ + +/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL + * project 2001. + */ +/* ==================================================================== + * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_DES_H +#define HEADER_DES_H + +#include /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ + +#ifdef OPENSSL_NO_DES +#error DES is disabled. +#endif + +#ifndef HEADER_NEW_DES_H +#error You must include des.h, not des_old.h directly. +#endif + +#ifdef _KERBEROS_DES_H +#error replaces . +#endif + +#include + +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _ +#undef _ +#endif + +typedef unsigned char _ossl_old_des_cblock[8]; +typedef struct _ossl_old_des_ks_struct + { + union { + _ossl_old_des_cblock _; + /* make sure things are correct size on machines with + * 8 byte longs */ + DES_LONG pad[2]; + } ks; + } _ossl_old_des_key_schedule[16]; + +#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY +#define des_cblock DES_cblock +#define const_des_cblock const_DES_cblock +#define des_key_schedule DES_key_schedule +#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\ + DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e)) +#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\ + DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e)) +#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\ + DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e)) +#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\ + DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e)) +#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\ + DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n)) +#define des_options()\ + DES_options() +#define des_cbc_cksum(i,o,l,k,iv)\ + DES_cbc_cksum((i),(o),(l),&(k),(iv)) +#define des_cbc_encrypt(i,o,l,k,iv,e)\ + DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e)) +#define des_ncbc_encrypt(i,o,l,k,iv,e)\ + DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e)) +#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\ + DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e)) +#define des_cfb_encrypt(i,o,n,l,k,iv,e)\ + DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e)) +#define des_ecb_encrypt(i,o,k,e)\ + DES_ecb_encrypt((i),(o),&(k),(e)) +#define des_encrypt1(d,k,e)\ + DES_encrypt1((d),&(k),(e)) +#define des_encrypt2(d,k,e)\ + DES_encrypt2((d),&(k),(e)) +#define des_encrypt3(d,k1,k2,k3)\ + DES_encrypt3((d),&(k1),&(k2),&(k3)) +#define des_decrypt3(d,k1,k2,k3)\ + DES_decrypt3((d),&(k1),&(k2),&(k3)) +#define des_xwhite_in2out(k,i,o)\ + DES_xwhite_in2out((k),(i),(o)) +#define des_enc_read(f,b,l,k,iv)\ + DES_enc_read((f),(b),(l),&(k),(iv)) +#define des_enc_write(f,b,l,k,iv)\ + DES_enc_write((f),(b),(l),&(k),(iv)) +#define des_fcrypt(b,s,r)\ + DES_fcrypt((b),(s),(r)) +#if 0 +#define des_crypt(b,s)\ + DES_crypt((b),(s)) +#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__) +#define crypt(b,s)\ + DES_crypt((b),(s)) +#endif +#endif +#define des_ofb_encrypt(i,o,n,l,k,iv)\ + DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv)) +#define des_pcbc_encrypt(i,o,l,k,iv,e)\ + DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e)) +#define des_quad_cksum(i,o,l,c,s)\ + DES_quad_cksum((i),(o),(l),(c),(s)) +#define des_random_seed(k)\ + _ossl_096_des_random_seed((k)) +#define des_random_key(r)\ + DES_random_key((r)) +#define des_read_password(k,p,v) \ + DES_read_password((k),(p),(v)) +#define des_read_2passwords(k1,k2,p,v) \ + DES_read_2passwords((k1),(k2),(p),(v)) +#define des_set_odd_parity(k)\ + DES_set_odd_parity((k)) +#define des_check_key_parity(k)\ + DES_check_key_parity((k)) +#define des_is_weak_key(k)\ + DES_is_weak_key((k)) +#define des_set_key(k,ks)\ + DES_set_key((k),&(ks)) +#define des_key_sched(k,ks)\ + DES_key_sched((k),&(ks)) +#define des_set_key_checked(k,ks)\ + DES_set_key_checked((k),&(ks)) +#define des_set_key_unchecked(k,ks)\ + DES_set_key_unchecked((k),&(ks)) +#define des_string_to_key(s,k)\ + DES_string_to_key((s),(k)) +#define des_string_to_2keys(s,k1,k2)\ + DES_string_to_2keys((s),(k1),(k2)) +#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\ + DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e)) +#define des_ofb64_encrypt(i,o,l,ks,iv,n)\ + DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n)) + + +#define des_ecb2_encrypt(i,o,k1,k2,e) \ + des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +#define des_check_key DES_check_key +#define des_rw_mode DES_rw_mode +#else /* libdes compatibility */ +/* Map all symbol names to _ossl_old_des_* form, so we avoid all + clashes with libdes */ +#define des_cblock _ossl_old_des_cblock +#define des_key_schedule _ossl_old_des_key_schedule +#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\ + _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e)) +#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\ + _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e)) +#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\ + _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e)) +#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\ + _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n)) +#define des_options()\ + _ossl_old_des_options() +#define des_cbc_cksum(i,o,l,k,iv)\ + _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv)) +#define des_cbc_encrypt(i,o,l,k,iv,e)\ + _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e)) +#define des_ncbc_encrypt(i,o,l,k,iv,e)\ + _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e)) +#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\ + _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e)) +#define des_cfb_encrypt(i,o,n,l,k,iv,e)\ + _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e)) +#define des_ecb_encrypt(i,o,k,e)\ + _ossl_old_des_ecb_encrypt((i),(o),(k),(e)) +#define des_encrypt(d,k,e)\ + _ossl_old_des_encrypt((d),(k),(e)) +#define des_encrypt2(d,k,e)\ + _ossl_old_des_encrypt2((d),(k),(e)) +#define des_encrypt3(d,k1,k2,k3)\ + _ossl_old_des_encrypt3((d),(k1),(k2),(k3)) +#define des_decrypt3(d,k1,k2,k3)\ + _ossl_old_des_decrypt3((d),(k1),(k2),(k3)) +#define des_xwhite_in2out(k,i,o)\ + _ossl_old_des_xwhite_in2out((k),(i),(o)) +#define des_enc_read(f,b,l,k,iv)\ + _ossl_old_des_enc_read((f),(b),(l),(k),(iv)) +#define des_enc_write(f,b,l,k,iv)\ + _ossl_old_des_enc_write((f),(b),(l),(k),(iv)) +#define des_fcrypt(b,s,r)\ + _ossl_old_des_fcrypt((b),(s),(r)) +#define des_crypt(b,s)\ + _ossl_old_des_crypt((b),(s)) +#if 0 +#define crypt(b,s)\ + _ossl_old_crypt((b),(s)) +#endif +#define des_ofb_encrypt(i,o,n,l,k,iv)\ + _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv)) +#define des_pcbc_encrypt(i,o,l,k,iv,e)\ + _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e)) +#define des_quad_cksum(i,o,l,c,s)\ + _ossl_old_des_quad_cksum((i),(o),(l),(c),(s)) +#define des_random_seed(k)\ + _ossl_old_des_random_seed((k)) +#define des_random_key(r)\ + _ossl_old_des_random_key((r)) +#define des_read_password(k,p,v) \ + _ossl_old_des_read_password((k),(p),(v)) +#define des_read_2passwords(k1,k2,p,v) \ + _ossl_old_des_read_2passwords((k1),(k2),(p),(v)) +#define des_set_odd_parity(k)\ + _ossl_old_des_set_odd_parity((k)) +#define des_is_weak_key(k)\ + _ossl_old_des_is_weak_key((k)) +#define des_set_key(k,ks)\ + _ossl_old_des_set_key((k),(ks)) +#define des_key_sched(k,ks)\ + _ossl_old_des_key_sched((k),(ks)) +#define des_string_to_key(s,k)\ + _ossl_old_des_string_to_key((s),(k)) +#define des_string_to_2keys(s,k1,k2)\ + _ossl_old_des_string_to_2keys((s),(k1),(k2)) +#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\ + _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e)) +#define des_ofb64_encrypt(i,o,l,ks,iv,n)\ + _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n)) + + +#define des_ecb2_encrypt(i,o,k1,k2,e) \ + des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +#define des_check_key DES_check_key +#define des_rw_mode DES_rw_mode +#endif + +const char *_ossl_old_des_options(void); +void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, + _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2, + _ossl_old_des_key_schedule ks3, int enc); +DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, + long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec); +void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, + _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); +void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, + _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); +void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, + _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec, + _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc); +void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits, + long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); +void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, + _ossl_old_des_key_schedule ks,int enc); +void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc); +void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc); +void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1, + _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3); +void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1, + _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3); +void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output, + long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, + _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc); +void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out, + long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, + _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc); +void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out, + long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, + _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num); +#if 0 +void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white), + _ossl_old_des_cblock (*out_white)); +#endif + +int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched, + _ossl_old_des_cblock *iv); +int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched, + _ossl_old_des_cblock *iv); +char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret); +char *_ossl_old_des_crypt(const char *buf,const char *salt); +#if !defined(PERL5) && !defined(NeXT) +char *_ossl_old_crypt(const char *buf,const char *salt); +#endif +void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out, + int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec); +void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, + _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); +DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, + long length,int out_count,_ossl_old_des_cblock *seed); +void _ossl_old_des_random_seed(_ossl_old_des_cblock key); +void _ossl_old_des_random_key(_ossl_old_des_cblock ret); +int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify); +int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2, + const char *prompt,int verify); +void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key); +int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key); +int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule); +int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule); +void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key); +void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2); +void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, + _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc); +void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, + _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num); + +void _ossl_096_des_random_seed(des_cblock *key); + +/* The following definitions provide compatibility with the MIT Kerberos + * library. The _ossl_old_des_key_schedule structure is not binary compatible. */ + +#define _KERBEROS_DES_H + +#define KRBDES_ENCRYPT DES_ENCRYPT +#define KRBDES_DECRYPT DES_DECRYPT + +#ifdef KERBEROS +# define ENCRYPT DES_ENCRYPT +# define DECRYPT DES_DECRYPT +#endif + +#ifndef NCOMPAT +# define C_Block des_cblock +# define Key_schedule des_key_schedule +# define KEY_SZ DES_KEY_SZ +# define string_to_key des_string_to_key +# define read_pw_string des_read_pw_string +# define random_key des_random_key +# define pcbc_encrypt des_pcbc_encrypt +# define set_key des_set_key +# define key_sched des_key_sched +# define ecb_encrypt des_ecb_encrypt +# define cbc_encrypt des_cbc_encrypt +# define ncbc_encrypt des_ncbc_encrypt +# define xcbc_encrypt des_xcbc_encrypt +# define cbc_cksum des_cbc_cksum +# define quad_cksum des_quad_cksum +# define check_parity des_check_key_parity +#endif + +#define des_fixup_key_parity DES_fixup_key_parity + +#ifdef __cplusplus +} +#endif + +/* for DES_read_pw_string et al */ +#include + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/dh.h b/石器时代8.5客户端最新源代码/石器源码/openssl/dh.h new file mode 100644 index 0000000..10475ac --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/dh.h @@ -0,0 +1,245 @@ +/* crypto/dh/dh.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_DH_H +#define HEADER_DH_H + +#include + +#ifdef OPENSSL_NO_DH +#error DH is disabled. +#endif + +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifndef OPENSSL_DH_MAX_MODULUS_BITS +# define OPENSSL_DH_MAX_MODULUS_BITS 10000 +#endif + +#define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024 + +#define DH_FLAG_CACHE_MONT_P 0x01 +#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH + * implementation now uses constant time + * modular exponentiation for secret exponents + * by default. This flag causes the + * faster variable sliding window method to + * be used for all exponents. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct dh_st DH; */ +/* typedef struct dh_method DH_METHOD; */ + +struct dh_method + { + const char *name; + /* Methods here */ + int (*generate_key)(DH *dh); + int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh); + int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a, + const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *m_ctx); /* Can be null */ + + int (*init)(DH *dh); + int (*finish)(DH *dh); + int flags; + char *app_data; + /* If this is non-NULL, it will be used to generate parameters */ + int (*generate_params)(DH *dh, int prime_len, int generator, BN_GENCB *cb); + }; + +struct dh_st + { + /* This first argument is used to pick up errors when + * a DH is passed instead of a EVP_PKEY */ + int pad; + int version; + BIGNUM *p; + BIGNUM *g; + long length; /* optional */ + BIGNUM *pub_key; /* g^x */ + BIGNUM *priv_key; /* x */ + + int flags; + BN_MONT_CTX *method_mont_p; + /* Place holders if we want to do X9.42 DH */ + BIGNUM *q; + BIGNUM *j; + unsigned char *seed; + int seedlen; + BIGNUM *counter; + + int references; + CRYPTO_EX_DATA ex_data; + const DH_METHOD *meth; + ENGINE *engine; + }; + +#define DH_GENERATOR_2 2 +/* #define DH_GENERATOR_3 3 */ +#define DH_GENERATOR_5 5 + +/* DH_check error codes */ +#define DH_CHECK_P_NOT_PRIME 0x01 +#define DH_CHECK_P_NOT_SAFE_PRIME 0x02 +#define DH_UNABLE_TO_CHECK_GENERATOR 0x04 +#define DH_NOT_SUITABLE_GENERATOR 0x08 + +/* DH_check_pub_key error codes */ +#define DH_CHECK_PUBKEY_TOO_SMALL 0x01 +#define DH_CHECK_PUBKEY_TOO_LARGE 0x02 + +/* primes p where (p-1)/2 is prime too are called "safe"; we define + this for backward compatibility: */ +#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME + +#define DHparams_dup(x) ASN1_dup_of_const(DH,i2d_DHparams,d2i_DHparams,x) +#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ + (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x)) +#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \ + (unsigned char *)(x)) +#define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x) +#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x) + +const DH_METHOD *DH_OpenSSL(void); + +#ifdef OPENSSL_FIPS +DH * FIPS_dh_new(void); +void FIPS_dh_free(DH *dh); +#endif + +void DH_set_default_method(const DH_METHOD *meth); +const DH_METHOD *DH_get_default_method(void); +int DH_set_method(DH *dh, const DH_METHOD *meth); +DH *DH_new_method(ENGINE *engine); + +DH * DH_new(void); +void DH_free(DH *dh); +int DH_up_ref(DH *dh); +int DH_size(const DH *dh); +int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int DH_set_ex_data(DH *d, int idx, void *arg); +void *DH_get_ex_data(DH *d, int idx); + +/* Deprecated version */ +#ifndef OPENSSL_NO_DEPRECATED +DH * DH_generate_parameters(int prime_len,int generator, + void (*callback)(int,int,void *),void *cb_arg); +#endif /* !defined(OPENSSL_NO_DEPRECATED) */ + +/* New version */ +int DH_generate_parameters_ex(DH *dh, int prime_len,int generator, BN_GENCB *cb); + +int DH_check(const DH *dh,int *codes); +int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes); +int DH_generate_key(DH *dh); +int DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh); +DH * d2i_DHparams(DH **a,const unsigned char **pp, long length); +int i2d_DHparams(const DH *a,unsigned char **pp); +#ifndef OPENSSL_NO_FP_API +int DHparams_print_fp(FILE *fp, const DH *x); +#endif +#ifndef OPENSSL_NO_BIO +int DHparams_print(BIO *bp, const DH *x); +#else +int DHparams_print(char *bp, const DH *x); +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_DH_strings(void); + +/* Error codes for the DH functions. */ + +/* Function codes. */ +#define DH_F_COMPUTE_KEY 102 +#define DH_F_DHPARAMS_PRINT 100 +#define DH_F_DHPARAMS_PRINT_FP 101 +#define DH_F_DH_BUILTIN_GENPARAMS 106 +#define DH_F_DH_COMPUTE_KEY 107 +#define DH_F_DH_GENERATE_KEY 108 +#define DH_F_DH_GENERATE_PARAMETERS 109 +#define DH_F_DH_NEW_METHOD 105 +#define DH_F_GENERATE_KEY 103 +#define DH_F_GENERATE_PARAMETERS 104 + +/* Reason codes. */ +#define DH_R_BAD_GENERATOR 101 +#define DH_R_INVALID_PUBKEY 102 +#define DH_R_KEY_SIZE_TOO_SMALL 104 +#define DH_R_MODULUS_TOO_LARGE 103 +#define DH_R_NO_PRIVATE_VALUE 100 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/dsa.h b/石器时代8.5客户端最新源代码/石器源码/openssl/dsa.h new file mode 100644 index 0000000..702c50d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/dsa.h @@ -0,0 +1,324 @@ +/* crypto/dsa/dsa.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* + * The DSS routines are based on patches supplied by + * Steven Schoch . He basically did the + * work and I have just tweaked them a little to fit into my + * stylistic vision for SSLeay :-) */ + +#ifndef HEADER_DSA_H +#define HEADER_DSA_H + +#include + +#ifdef OPENSSL_NO_DSA +#error DSA is disabled. +#endif + +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#include + +#ifndef OPENSSL_NO_DEPRECATED +#include +#ifndef OPENSSL_NO_DH +# include +#endif +#endif + +#ifndef OPENSSL_DSA_MAX_MODULUS_BITS +# define OPENSSL_DSA_MAX_MODULUS_BITS 10000 +#endif + +#define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024 + +#define DSA_FLAG_CACHE_MONT_P 0x01 +#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA + * implementation now uses constant time + * modular exponentiation for secret exponents + * by default. This flag causes the + * faster variable sliding window method to + * be used for all exponents. + */ + +/* If this flag is set the DSA method is FIPS compliant and can be used + * in FIPS mode. This is set in the validated module method. If an + * application sets this flag in its own methods it is its reposibility + * to ensure the result is compliant. + */ + +#define DSA_FLAG_FIPS_METHOD 0x0400 + +/* If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +#define DSA_FLAG_NON_FIPS_ALLOW 0x0400 + +#ifdef OPENSSL_FIPS +#define FIPS_DSA_SIZE_T int +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct dsa_st DSA; */ +/* typedef struct dsa_method DSA_METHOD; */ + +typedef struct DSA_SIG_st + { + BIGNUM *r; + BIGNUM *s; + } DSA_SIG; + +struct dsa_method + { + const char *name; + DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); + int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, + BIGNUM **rp); + int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len, + DSA_SIG *sig, DSA *dsa); + int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, + BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *in_mont); + int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *m_ctx); /* Can be null */ + int (*init)(DSA *dsa); + int (*finish)(DSA *dsa); + int flags; + char *app_data; + /* If this is non-NULL, it is used to generate DSA parameters */ + int (*dsa_paramgen)(DSA *dsa, int bits, + unsigned char *seed, int seed_len, + int *counter_ret, unsigned long *h_ret, + BN_GENCB *cb); + /* If this is non-NULL, it is used to generate DSA keys */ + int (*dsa_keygen)(DSA *dsa); + }; + +struct dsa_st + { + /* This first variable is used to pick up errors where + * a DSA is passed instead of of a EVP_PKEY */ + int pad; + long version; + int write_params; + BIGNUM *p; + BIGNUM *q; /* == 20 */ + BIGNUM *g; + + BIGNUM *pub_key; /* y public key */ + BIGNUM *priv_key; /* x private key */ + + BIGNUM *kinv; /* Signing pre-calc */ + BIGNUM *r; /* Signing pre-calc */ + + int flags; + /* Normally used to cache montgomery values */ + BN_MONT_CTX *method_mont_p; + int references; + CRYPTO_EX_DATA ex_data; + const DSA_METHOD *meth; + /* functional reference if 'meth' is ENGINE-provided */ + ENGINE *engine; + }; + +#define DSAparams_dup(x) ASN1_dup_of_const(DSA,i2d_DSAparams,d2i_DSAparams,x) +#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ + (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) +#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ + (unsigned char *)(x)) +#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) +#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) + + +DSA_SIG * DSA_SIG_new(void); +void DSA_SIG_free(DSA_SIG *a); +int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); +DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length); + +DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); +int DSA_do_verify(const unsigned char *dgst,int dgst_len, + DSA_SIG *sig,DSA *dsa); + +const DSA_METHOD *DSA_OpenSSL(void); + +void DSA_set_default_method(const DSA_METHOD *); +const DSA_METHOD *DSA_get_default_method(void); +int DSA_set_method(DSA *dsa, const DSA_METHOD *); + +#ifdef OPENSSL_FIPS +DSA * FIPS_dsa_new(void); +void FIPS_dsa_free (DSA *r); +#endif + +DSA * DSA_new(void); +DSA * DSA_new_method(ENGINE *engine); +void DSA_free (DSA *r); +/* "up" the DSA object's reference count */ +int DSA_up_ref(DSA *r); +int DSA_size(const DSA *); + /* next 4 return -1 on error */ +int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); +int DSA_sign(int type,const unsigned char *dgst,int dlen, + unsigned char *sig, unsigned int *siglen, DSA *dsa); +int DSA_verify(int type,const unsigned char *dgst,int dgst_len, + const unsigned char *sigbuf, int siglen, DSA *dsa); +int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int DSA_set_ex_data(DSA *d, int idx, void *arg); +void *DSA_get_ex_data(DSA *d, int idx); + +DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); +DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); +DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length); + +/* Deprecated version */ +#ifndef OPENSSL_NO_DEPRECATED +DSA * DSA_generate_parameters(int bits, + unsigned char *seed,int seed_len, + int *counter_ret, unsigned long *h_ret,void + (*callback)(int, int, void *),void *cb_arg); +#endif /* !defined(OPENSSL_NO_DEPRECATED) */ + +/* New version */ +int DSA_generate_parameters_ex(DSA *dsa, int bits, + unsigned char *seed,int seed_len, + int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); + +int DSA_generate_key(DSA *a); +int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); +int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); +int i2d_DSAparams(const DSA *a,unsigned char **pp); + +#ifndef OPENSSL_NO_BIO +int DSAparams_print(BIO *bp, const DSA *x); +int DSA_print(BIO *bp, const DSA *x, int off); +#endif +#ifndef OPENSSL_NO_FP_API +int DSAparams_print_fp(FILE *fp, const DSA *x); +int DSA_print_fp(FILE *bp, const DSA *x, int off); +#endif + +#define DSS_prime_checks 50 +/* Primality test according to FIPS PUB 186[-1], Appendix 2.1: + * 50 rounds of Rabin-Miller */ +#define DSA_is_prime(n, callback, cb_arg) \ + BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) + +#ifndef OPENSSL_NO_DH +/* Convert DSA structure (key or just parameters) into DH structure + * (be careful to avoid small subgroup attacks when using this!) */ +DH *DSA_dup_DH(const DSA *r); +#endif + +#ifdef OPENSSL_FIPS +int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig); +int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen); +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_DSA_strings(void); + +/* Error codes for the DSA functions. */ + +/* Function codes. */ +#define DSA_F_D2I_DSA_SIG 110 +#define DSA_F_DSAPARAMS_PRINT 100 +#define DSA_F_DSAPARAMS_PRINT_FP 101 +#define DSA_F_DSA_BUILTIN_KEYGEN 119 +#define DSA_F_DSA_BUILTIN_PARAMGEN 118 +#define DSA_F_DSA_DO_SIGN 112 +#define DSA_F_DSA_DO_VERIFY 113 +#define DSA_F_DSA_GENERATE_PARAMETERS 117 +#define DSA_F_DSA_NEW_METHOD 103 +#define DSA_F_DSA_PRINT 104 +#define DSA_F_DSA_PRINT_FP 105 +#define DSA_F_DSA_SET_DEFAULT_METHOD 115 +#define DSA_F_DSA_SET_METHOD 116 +#define DSA_F_DSA_SIGN 106 +#define DSA_F_DSA_SIGN_SETUP 107 +#define DSA_F_DSA_SIG_NEW 109 +#define DSA_F_DSA_VERIFY 108 +#define DSA_F_I2D_DSA_SIG 111 +#define DSA_F_SIG_CB 114 + +/* Reason codes. */ +#define DSA_R_BAD_Q_VALUE 102 +#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 +#define DSA_R_KEY_SIZE_TOO_SMALL 106 +#define DSA_R_MISSING_PARAMETERS 101 +#define DSA_R_MODULUS_TOO_LARGE 103 +#define DSA_R_NON_FIPS_METHOD 104 +#define DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 105 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/dso.h b/石器时代8.5客户端最新源代码/石器源码/openssl/dso.h new file mode 100644 index 0000000..3e51913 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/dso.h @@ -0,0 +1,368 @@ +/* dso.h -*- mode:C; c-file-style: "eay" -*- */ +/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL + * project 2000. + */ +/* ==================================================================== + * Copyright (c) 2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_DSO_H +#define HEADER_DSO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* These values are used as commands to DSO_ctrl() */ +#define DSO_CTRL_GET_FLAGS 1 +#define DSO_CTRL_SET_FLAGS 2 +#define DSO_CTRL_OR_FLAGS 3 + +/* By default, DSO_load() will translate the provided filename into a form + * typical for the platform (more specifically the DSO_METHOD) using the + * dso_name_converter function of the method. Eg. win32 will transform "blah" + * into "blah.dll", and dlfcn will transform it into "libblah.so". The + * behaviour can be overriden by setting the name_converter callback in the DSO + * object (using DSO_set_name_converter()). This callback could even utilise + * the DSO_METHOD's converter too if it only wants to override behaviour for + * one or two possible DSO methods. However, the following flag can be set in a + * DSO to prevent *any* native name-translation at all - eg. if the caller has + * prompted the user for a path to a driver library so the filename should be + * interpreted as-is. */ +#define DSO_FLAG_NO_NAME_TRANSLATION 0x01 +/* An extra flag to give if only the extension should be added as + * translation. This is obviously only of importance on Unix and + * other operating systems where the translation also may prefix + * the name with something, like 'lib', and ignored everywhere else. + * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used + * at the same time. */ +#define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02 + +/* The following flag controls the translation of symbol names to upper + * case. This is currently only being implemented for OpenVMS. + */ +#define DSO_FLAG_UPCASE_SYMBOL 0x10 + +/* This flag loads the library with public symbols. + * Meaning: The exported symbols of this library are public + * to all libraries loaded after this library. + * At the moment only implemented in unix. + */ +#define DSO_FLAG_GLOBAL_SYMBOLS 0x20 + + +typedef void (*DSO_FUNC_TYPE)(void); + +typedef struct dso_st DSO; + +/* The function prototype used for method functions (or caller-provided + * callbacks) that transform filenames. They are passed a DSO structure pointer + * (or NULL if they are to be used independantly of a DSO object) and a + * filename to transform. They should either return NULL (if there is an error + * condition) or a newly allocated string containing the transformed form that + * the caller will need to free with OPENSSL_free() when done. */ +typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *); +/* The function prototype used for method functions (or caller-provided + * callbacks) that merge two file specifications. They are passed a + * DSO structure pointer (or NULL if they are to be used independantly of + * a DSO object) and two file specifications to merge. They should + * either return NULL (if there is an error condition) or a newly allocated + * string containing the result of merging that the caller will need + * to free with OPENSSL_free() when done. + * Here, merging means that bits and pieces are taken from each of the + * file specifications and added together in whatever fashion that is + * sensible for the DSO method in question. The only rule that really + * applies is that if the two specification contain pieces of the same + * type, the copy from the first string takes priority. One could see + * it as the first specification is the one given by the user and the + * second being a bunch of defaults to add on if they're missing in the + * first. */ +typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *); + +typedef struct dso_meth_st + { + const char *name; + /* Loads a shared library, NB: new DSO_METHODs must ensure that a + * successful load populates the loaded_filename field, and likewise a + * successful unload OPENSSL_frees and NULLs it out. */ + int (*dso_load)(DSO *dso); + /* Unloads a shared library */ + int (*dso_unload)(DSO *dso); + /* Binds a variable */ + void *(*dso_bind_var)(DSO *dso, const char *symname); + /* Binds a function - assumes a return type of DSO_FUNC_TYPE. + * This should be cast to the real function prototype by the + * caller. Platforms that don't have compatible representations + * for different prototypes (this is possible within ANSI C) + * are highly unlikely to have shared libraries at all, let + * alone a DSO_METHOD implemented for them. */ + DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname); + +/* I don't think this would actually be used in any circumstances. */ +#if 0 + /* Unbinds a variable */ + int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr); + /* Unbinds a function */ + int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); +#endif + /* The generic (yuck) "ctrl()" function. NB: Negative return + * values (rather than zero) indicate errors. */ + long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg); + /* The default DSO_METHOD-specific function for converting filenames to + * a canonical native form. */ + DSO_NAME_CONVERTER_FUNC dso_name_converter; + /* The default DSO_METHOD-specific function for converting filenames to + * a canonical native form. */ + DSO_MERGER_FUNC dso_merger; + + /* [De]Initialisation handlers. */ + int (*init)(DSO *dso); + int (*finish)(DSO *dso); + } DSO_METHOD; + +/**********************************************************************/ +/* The low-level handle type used to refer to a loaded shared library */ + +struct dso_st + { + DSO_METHOD *meth; + /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS + * doesn't use anything but will need to cache the filename + * for use in the dso_bind handler. All in all, let each + * method control its own destiny. "Handles" and such go in + * a STACK. */ + STACK *meth_data; + int references; + int flags; + /* For use by applications etc ... use this for your bits'n'pieces, + * don't touch meth_data! */ + CRYPTO_EX_DATA ex_data; + /* If this callback function pointer is set to non-NULL, then it will + * be used in DSO_load() in place of meth->dso_name_converter. NB: This + * should normally set using DSO_set_name_converter(). */ + DSO_NAME_CONVERTER_FUNC name_converter; + /* If this callback function pointer is set to non-NULL, then it will + * be used in DSO_load() in place of meth->dso_merger. NB: This + * should normally set using DSO_set_merger(). */ + DSO_MERGER_FUNC merger; + /* This is populated with (a copy of) the platform-independant + * filename used for this DSO. */ + char *filename; + /* This is populated with (a copy of) the translated filename by which + * the DSO was actually loaded. It is NULL iff the DSO is not currently + * loaded. NB: This is here because the filename translation process + * may involve a callback being invoked more than once not only to + * convert to a platform-specific form, but also to try different + * filenames in the process of trying to perform a load. As such, this + * variable can be used to indicate (a) whether this DSO structure + * corresponds to a loaded library or not, and (b) the filename with + * which it was actually loaded. */ + char *loaded_filename; + }; + + +DSO * DSO_new(void); +DSO * DSO_new_method(DSO_METHOD *method); +int DSO_free(DSO *dso); +int DSO_flags(DSO *dso); +int DSO_up_ref(DSO *dso); +long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); + +/* This function sets the DSO's name_converter callback. If it is non-NULL, + * then it will be used instead of the associated DSO_METHOD's function. If + * oldcb is non-NULL then it is set to the function pointer value being + * replaced. Return value is non-zero for success. */ +int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, + DSO_NAME_CONVERTER_FUNC *oldcb); +/* These functions can be used to get/set the platform-independant filename + * used for a DSO. NB: set will fail if the DSO is already loaded. */ +const char *DSO_get_filename(DSO *dso); +int DSO_set_filename(DSO *dso, const char *filename); +/* This function will invoke the DSO's name_converter callback to translate a + * filename, or if the callback isn't set it will instead use the DSO_METHOD's + * converter. If "filename" is NULL, the "filename" in the DSO itself will be + * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is + * simply duplicated. NB: This function is usually called from within a + * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that + * caller-created DSO_METHODs can do the same thing. A non-NULL return value + * will need to be OPENSSL_free()'d. */ +char *DSO_convert_filename(DSO *dso, const char *filename); +/* This function will invoke the DSO's merger callback to merge two file + * specifications, or if the callback isn't set it will instead use the + * DSO_METHOD's merger. A non-NULL return value will need to be + * OPENSSL_free()'d. */ +char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2); +/* If the DSO is currently loaded, this returns the filename that it was loaded + * under, otherwise it returns NULL. So it is also useful as a test as to + * whether the DSO is currently loaded. NB: This will not necessarily return + * the same value as DSO_convert_filename(dso, dso->filename), because the + * DSO_METHOD's load function may have tried a variety of filenames (with + * and/or without the aid of the converters) before settling on the one it + * actually loaded. */ +const char *DSO_get_loaded_filename(DSO *dso); + +void DSO_set_default_method(DSO_METHOD *meth); +DSO_METHOD *DSO_get_default_method(void); +DSO_METHOD *DSO_get_method(DSO *dso); +DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); + +/* The all-singing all-dancing load function, you normally pass NULL + * for the first and third parameters. Use DSO_up and DSO_free for + * subsequent reference count handling. Any flags passed in will be set + * in the constructed DSO after its init() function but before the + * load operation. If 'dso' is non-NULL, 'flags' is ignored. */ +DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags); + +/* This function binds to a variable inside a shared library. */ +void *DSO_bind_var(DSO *dso, const char *symname); + +/* This function binds to a function inside a shared library. */ +DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname); + +/* This method is the default, but will beg, borrow, or steal whatever + * method should be the default on any particular platform (including + * DSO_METH_null() if necessary). */ +DSO_METHOD *DSO_METHOD_openssl(void); + +/* This method is defined for all platforms - if a platform has no + * DSO support then this will be the only method! */ +DSO_METHOD *DSO_METHOD_null(void); + +/* If DSO_DLFCN is defined, the standard dlfcn.h-style functions + * (dlopen, dlclose, dlsym, etc) will be used and incorporated into + * this method. If not, this method will return NULL. */ +DSO_METHOD *DSO_METHOD_dlfcn(void); + +/* If DSO_DL is defined, the standard dl.h-style functions (shl_load, + * shl_unload, shl_findsym, etc) will be used and incorporated into + * this method. If not, this method will return NULL. */ +DSO_METHOD *DSO_METHOD_dl(void); + +/* If WIN32 is defined, use DLLs. If not, return NULL. */ +DSO_METHOD *DSO_METHOD_win32(void); + +/* If VMS is defined, use shared images. If not, return NULL. */ +DSO_METHOD *DSO_METHOD_vms(void); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_DSO_strings(void); + +/* Error codes for the DSO functions. */ + +/* Function codes. */ +#define DSO_F_DLFCN_BIND_FUNC 100 +#define DSO_F_DLFCN_BIND_VAR 101 +#define DSO_F_DLFCN_LOAD 102 +#define DSO_F_DLFCN_MERGER 130 +#define DSO_F_DLFCN_NAME_CONVERTER 123 +#define DSO_F_DLFCN_UNLOAD 103 +#define DSO_F_DL_BIND_FUNC 104 +#define DSO_F_DL_BIND_VAR 105 +#define DSO_F_DL_LOAD 106 +#define DSO_F_DL_MERGER 131 +#define DSO_F_DL_NAME_CONVERTER 124 +#define DSO_F_DL_UNLOAD 107 +#define DSO_F_DSO_BIND_FUNC 108 +#define DSO_F_DSO_BIND_VAR 109 +#define DSO_F_DSO_CONVERT_FILENAME 126 +#define DSO_F_DSO_CTRL 110 +#define DSO_F_DSO_FREE 111 +#define DSO_F_DSO_GET_FILENAME 127 +#define DSO_F_DSO_GET_LOADED_FILENAME 128 +#define DSO_F_DSO_LOAD 112 +#define DSO_F_DSO_MERGE 132 +#define DSO_F_DSO_NEW_METHOD 113 +#define DSO_F_DSO_SET_FILENAME 129 +#define DSO_F_DSO_SET_NAME_CONVERTER 122 +#define DSO_F_DSO_UP_REF 114 +#define DSO_F_VMS_BIND_SYM 115 +#define DSO_F_VMS_LOAD 116 +#define DSO_F_VMS_MERGER 133 +#define DSO_F_VMS_UNLOAD 117 +#define DSO_F_WIN32_BIND_FUNC 118 +#define DSO_F_WIN32_BIND_VAR 119 +#define DSO_F_WIN32_JOINER 135 +#define DSO_F_WIN32_LOAD 120 +#define DSO_F_WIN32_MERGER 134 +#define DSO_F_WIN32_NAME_CONVERTER 125 +#define DSO_F_WIN32_SPLITTER 136 +#define DSO_F_WIN32_UNLOAD 121 + +/* Reason codes. */ +#define DSO_R_CTRL_FAILED 100 +#define DSO_R_DSO_ALREADY_LOADED 110 +#define DSO_R_EMPTY_FILE_STRUCTURE 113 +#define DSO_R_FAILURE 114 +#define DSO_R_FILENAME_TOO_BIG 101 +#define DSO_R_FINISH_FAILED 102 +#define DSO_R_INCORRECT_FILE_SYNTAX 115 +#define DSO_R_LOAD_FAILED 103 +#define DSO_R_NAME_TRANSLATION_FAILED 109 +#define DSO_R_NO_FILENAME 111 +#define DSO_R_NO_FILE_SPECIFICATION 116 +#define DSO_R_NULL_HANDLE 104 +#define DSO_R_SET_FILENAME_FAILED 112 +#define DSO_R_STACK_ERROR 105 +#define DSO_R_SYM_FAILURE 106 +#define DSO_R_UNLOAD_FAILED 107 +#define DSO_R_UNSUPPORTED 108 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/dtls1.h b/石器时代8.5客户端最新源代码/石器源码/openssl/dtls1.h new file mode 100644 index 0000000..f159d37 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/dtls1.h @@ -0,0 +1,218 @@ +/* ssl/dtls1.h */ +/* + * DTLS implementation written by Nagendra Modadugu + * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. + */ +/* ==================================================================== + * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_DTLS1_H +#define HEADER_DTLS1_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define DTLS1_VERSION 0xFEFF +#define DTLS1_BAD_VER 0x0100 + +#if 0 +/* this alert description is not specified anywhere... */ +#define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE 110 +#endif + +/* lengths of messages */ +#define DTLS1_COOKIE_LENGTH 32 + +#define DTLS1_RT_HEADER_LENGTH 13 + +#define DTLS1_HM_HEADER_LENGTH 12 + +#define DTLS1_HM_BAD_FRAGMENT -2 +#define DTLS1_HM_FRAGMENT_RETRY -3 + +#define DTLS1_CCS_HEADER_LENGTH 1 + +#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE +#define DTLS1_AL_HEADER_LENGTH 7 +#else +#define DTLS1_AL_HEADER_LENGTH 2 +#endif + + +typedef struct dtls1_bitmap_st + { + PQ_64BIT map; + unsigned long length; /* sizeof the bitmap in bits */ + PQ_64BIT max_seq_num; /* max record number seen so far */ + } DTLS1_BITMAP; + +struct hm_header_st + { + unsigned char type; + unsigned long msg_len; + unsigned short seq; + unsigned long frag_off; + unsigned long frag_len; + unsigned int is_ccs; + }; + +struct ccs_header_st + { + unsigned char type; + unsigned short seq; + }; + +struct dtls1_timeout_st + { + /* Number of read timeouts so far */ + unsigned int read_timeouts; + + /* Number of write timeouts so far */ + unsigned int write_timeouts; + + /* Number of alerts received so far */ + unsigned int num_alerts; + }; + +typedef struct record_pqueue_st + { + unsigned short epoch; + pqueue q; + } record_pqueue; + +typedef struct hm_fragment_st + { + struct hm_header_st msg_header; + unsigned char *fragment; + } hm_fragment; + +typedef struct dtls1_state_st + { + unsigned int send_cookie; + unsigned char cookie[DTLS1_COOKIE_LENGTH]; + unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH]; + unsigned int cookie_len; + + /* + * The current data and handshake epoch. This is initially + * undefined, and starts at zero once the initial handshake is + * completed + */ + unsigned short r_epoch; + unsigned short w_epoch; + + /* records being received in the current epoch */ + DTLS1_BITMAP bitmap; + + /* renegotiation starts a new set of sequence numbers */ + DTLS1_BITMAP next_bitmap; + + /* handshake message numbers */ + unsigned short handshake_write_seq; + unsigned short next_handshake_write_seq; + + unsigned short handshake_read_seq; + + /* Received handshake records (processed and unprocessed) */ + record_pqueue unprocessed_rcds; + record_pqueue processed_rcds; + + /* Buffered handshake messages */ + pqueue buffered_messages; + + /* Buffered (sent) handshake records */ + pqueue sent_messages; + + unsigned int mtu; /* max wire packet size */ + + struct hm_header_st w_msg_hdr; + struct hm_header_st r_msg_hdr; + + struct dtls1_timeout_st timeout; + + /* storage for Alert/Handshake protocol data received but not + * yet processed by ssl3_read_bytes: */ + unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH]; + unsigned int alert_fragment_len; + unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH]; + unsigned int handshake_fragment_len; + + unsigned int retransmitting; + + } DTLS1_STATE; + +typedef struct dtls1_record_data_st + { + unsigned char *packet; + unsigned int packet_length; + SSL3_BUFFER rbuf; + SSL3_RECORD rrec; + } DTLS1_RECORD_DATA; + + +/* Timeout multipliers (timeout slice is defined in apps/timeouts.h */ +#define DTLS1_TMO_READ_COUNT 2 +#define DTLS1_TMO_WRITE_COUNT 2 + +#define DTLS1_TMO_ALERT_COUNT 12 + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/e_os2.h b/石器时代8.5客户端最新源代码/石器源码/openssl/e_os2.h new file mode 100644 index 0000000..9da0b65 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/e_os2.h @@ -0,0 +1,279 @@ +/* e_os2.h */ +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include + +#ifndef HEADER_E_OS2_H +#define HEADER_E_OS2_H + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Detect operating systems. This probably needs completing. + * The result is that at least one OPENSSL_SYS_os macro should be defined. + * However, if none is defined, Unix is assumed. + **/ + +#define OPENSSL_SYS_UNIX + +/* ----------------------- Macintosh, before MacOS X ----------------------- */ +#if defined(__MWERKS__) && defined(macintosh) || defined(OPENSSL_SYSNAME_MAC) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_MACINTOSH_CLASSIC +#endif + +/* ----------------------- NetWare ----------------------------------------- */ +#if defined(NETWARE) || defined(OPENSSL_SYSNAME_NETWARE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_NETWARE +#endif + +/* ---------------------- Microsoft operating systems ---------------------- */ + +/* Note that MSDOS actually denotes 32-bit environments running on top of + MS-DOS, such as DJGPP one. */ +#if defined(OPENSSL_SYSNAME_MSDOS) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_MSDOS +#endif + +/* For 32 bit environment, there seems to be the CygWin environment and then + all the others that try to do the same thing Microsoft does... */ +#if defined(OPENSSL_SYSNAME_UWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_UWIN +#else +# if defined(__CYGWIN32__) || defined(OPENSSL_SYSNAME_CYGWIN32) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_CYGWIN +# else +# if defined(_WIN32) || defined(OPENSSL_SYSNAME_WIN32) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32 +# endif +# if defined(OPENSSL_SYSNAME_WINNT) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINNT +# endif +# if defined(OPENSSL_SYSNAME_WINCE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINCE +# endif +# endif +#endif + +/* Anything that tries to look like Microsoft is "Windows" */ +#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_SYS_MSDOS +# define OPENSSL_SYS_MSDOS +# endif +#endif + +/* DLL settings. This part is a bit tough, because it's up to the application + implementor how he or she will link the application, so it requires some + macro to be used. */ +#ifdef OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_OPT_WINDLL +# if defined(_WINDLL) /* This is used when building OpenSSL to indicate that + DLL linkage should be used */ +# define OPENSSL_OPT_WINDLL +# endif +# endif +#endif + +/* -------------------------------- OpenVMS -------------------------------- */ +#if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYSNAME_VMS) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_VMS +# if defined(__DECC) +# define OPENSSL_SYS_VMS_DECC +# elif defined(__DECCXX) +# define OPENSSL_SYS_VMS_DECC +# define OPENSSL_SYS_VMS_DECCXX +# else +# define OPENSSL_SYS_VMS_NODECC +# endif +#endif + +/* --------------------------------- OS/2 ---------------------------------- */ +#if defined(__EMX__) || defined(__OS2__) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_OS2 +#endif + +/* --------------------------------- Unix ---------------------------------- */ +#ifdef OPENSSL_SYS_UNIX +# if defined(linux) || defined(__linux__) || defined(OPENSSL_SYSNAME_LINUX) +# define OPENSSL_SYS_LINUX +# endif +# ifdef OPENSSL_SYSNAME_MPE +# define OPENSSL_SYS_MPE +# endif +# ifdef OPENSSL_SYSNAME_SNI +# define OPENSSL_SYS_SNI +# endif +# ifdef OPENSSL_SYSNAME_ULTRASPARC +# define OPENSSL_SYS_ULTRASPARC +# endif +# ifdef OPENSSL_SYSNAME_NEWS4 +# define OPENSSL_SYS_NEWS4 +# endif +# ifdef OPENSSL_SYSNAME_MACOSX +# define OPENSSL_SYS_MACOSX +# endif +# ifdef OPENSSL_SYSNAME_MACOSX_RHAPSODY +# define OPENSSL_SYS_MACOSX_RHAPSODY +# define OPENSSL_SYS_MACOSX +# endif +# ifdef OPENSSL_SYSNAME_SUNOS +# define OPENSSL_SYS_SUNOS +#endif +# if defined(_CRAY) || defined(OPENSSL_SYSNAME_CRAY) +# define OPENSSL_SYS_CRAY +# endif +# if defined(_AIX) || defined(OPENSSL_SYSNAME_AIX) +# define OPENSSL_SYS_AIX +# endif +#endif + +/* --------------------------------- VOS ----------------------------------- */ +#ifdef OPENSSL_SYSNAME_VOS +# define OPENSSL_SYS_VOS +#endif + +/* ------------------------------- VxWorks --------------------------------- */ +#ifdef OPENSSL_SYSNAME_VXWORKS +# define OPENSSL_SYS_VXWORKS +#endif + +/** + * That's it for OS-specific stuff + *****************************************************************************/ + + +/* Specials for I/O an exit */ +#ifdef OPENSSL_SYS_MSDOS +# define OPENSSL_UNISTD_IO +# define OPENSSL_DECLARE_EXIT extern void exit(int); +#else +# define OPENSSL_UNISTD_IO OPENSSL_UNISTD +# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */ +#endif + +/* Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare + certain global symbols that, with some compilers under VMS, have to be + defined and declared explicitely with globaldef and globalref. + Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare + DLL exports and imports for compilers under Win32. These are a little + more complicated to use. Basically, for any library that exports some + global variables, the following code must be present in the header file + that declares them, before OPENSSL_EXTERN is used: + + #ifdef SOME_BUILD_FLAG_MACRO + # undef OPENSSL_EXTERN + # define OPENSSL_EXTERN OPENSSL_EXPORT + #endif + + The default is to have OPENSSL_EXPORT, OPENSSL_IMPORT and OPENSSL_GLOBAL + have some generally sensible values, and for OPENSSL_EXTERN to have the + value OPENSSL_IMPORT. +*/ + +#if defined(OPENSSL_SYS_VMS_NODECC) +# define OPENSSL_EXPORT globalref +# define OPENSSL_IMPORT globalref +# define OPENSSL_GLOBAL globaldef +#elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL) +# define OPENSSL_EXPORT extern __declspec(dllexport) +# define OPENSSL_IMPORT extern __declspec(dllimport) +# define OPENSSL_GLOBAL +#else +# define OPENSSL_EXPORT extern +# define OPENSSL_IMPORT extern +# define OPENSSL_GLOBAL +#endif +#define OPENSSL_EXTERN OPENSSL_IMPORT + +/* Macros to allow global variables to be reached through function calls when + required (if a shared library version requvres it, for example. + The way it's done allows definitions like this: + + // in foobar.c + OPENSSL_IMPLEMENT_GLOBAL(int,foobar) = 0; + // in foobar.h + OPENSSL_DECLARE_GLOBAL(int,foobar); + #define foobar OPENSSL_GLOBAL_REF(foobar) +*/ +#ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define OPENSSL_IMPLEMENT_GLOBAL(type,name) \ + extern type _hide_##name; \ + type *_shadow_##name(void) { return &_hide_##name; } \ + static type _hide_##name +# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void) +# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name())) +#else +# define OPENSSL_IMPLEMENT_GLOBAL(type,name) OPENSSL_GLOBAL type _shadow_##name +# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name +# define OPENSSL_GLOBAL_REF(name) _shadow_##name +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ebcdic.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ebcdic.h new file mode 100644 index 0000000..6d65afc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ebcdic.h @@ -0,0 +1,19 @@ +/* crypto/ebcdic.h */ + +#ifndef HEADER_EBCDIC_H +#define HEADER_EBCDIC_H + +#include + +/* Avoid name clashes with other applications */ +#define os_toascii _openssl_os_toascii +#define os_toebcdic _openssl_os_toebcdic +#define ebcdic2ascii _openssl_ebcdic2ascii +#define ascii2ebcdic _openssl_ascii2ebcdic + +extern const unsigned char os_toascii[256]; +extern const unsigned char os_toebcdic[256]; +void *ebcdic2ascii(void *dest, const void *srce, size_t count); +void *ascii2ebcdic(void *dest, const void *srce, size_t count); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ec.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ec.h new file mode 100644 index 0000000..8bc2a23 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ec.h @@ -0,0 +1,526 @@ +/* crypto/ec/ec.h */ +/* + * Originally written by Bodo Moeller for the OpenSSL project. + */ +/* ==================================================================== + * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the OpenSSL open source + * license provided above. + * + * The elliptic curve binary polynomial software is originally written by + * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. + * + */ + +#ifndef HEADER_EC_H +#define HEADER_EC_H + +#include + +#ifdef OPENSSL_NO_EC +#error EC is disabled. +#endif + +#include +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifdef __cplusplus +extern "C" { +#elif defined(__SUNPRO_C) +# if __SUNPRO_C >= 0x520 +# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) +# endif +#endif + + +#ifndef OPENSSL_ECC_MAX_FIELD_BITS +# define OPENSSL_ECC_MAX_FIELD_BITS 661 +#endif + +typedef enum { + /* values as defined in X9.62 (ECDSA) and elsewhere */ + POINT_CONVERSION_COMPRESSED = 2, + POINT_CONVERSION_UNCOMPRESSED = 4, + POINT_CONVERSION_HYBRID = 6 +} point_conversion_form_t; + + +typedef struct ec_method_st EC_METHOD; + +typedef struct ec_group_st + /* + EC_METHOD *meth; + -- field definition + -- curve coefficients + -- optional generator with associated information (order, cofactor) + -- optional extra data (precomputed table for fast computation of multiples of generator) + -- ASN1 stuff + */ + EC_GROUP; + +typedef struct ec_point_st EC_POINT; + + +/* EC_METHODs for curves over GF(p). + * EC_GFp_simple_method provides the basis for the optimized methods. + */ +const EC_METHOD *EC_GFp_simple_method(void); +const EC_METHOD *EC_GFp_mont_method(void); +const EC_METHOD *EC_GFp_nist_method(void); + +/* EC_METHOD for curves over GF(2^m). + */ +const EC_METHOD *EC_GF2m_simple_method(void); + + +EC_GROUP *EC_GROUP_new(const EC_METHOD *); +void EC_GROUP_free(EC_GROUP *); +void EC_GROUP_clear_free(EC_GROUP *); +int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *); +EC_GROUP *EC_GROUP_dup(const EC_GROUP *); + +const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); +int EC_METHOD_get_field_type(const EC_METHOD *); + +int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor); +const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *); +int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *); +int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *); + +void EC_GROUP_set_curve_name(EC_GROUP *, int nid); +int EC_GROUP_get_curve_name(const EC_GROUP *); + +void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag); +int EC_GROUP_get_asn1_flag(const EC_GROUP *); + +void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t); +point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); + +unsigned char *EC_GROUP_get0_seed(const EC_GROUP *); +size_t EC_GROUP_get_seed_len(const EC_GROUP *); +size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); + +int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); +int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); +int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); +int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); + +/* returns the number of bits needed to represent a field element */ +int EC_GROUP_get_degree(const EC_GROUP *); + +/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */ +int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); +/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the + * elliptic curve is not zero, 0 otherwise */ +int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *); + +/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */ +int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *); + +/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() + * after choosing an appropriate EC_METHOD */ +EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); +EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); + +/* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure + * specified by a curve name (in form of a NID) */ +EC_GROUP *EC_GROUP_new_by_curve_name(int nid); +/* handling of internal curves */ +typedef struct { + int nid; + const char *comment; + } EC_builtin_curve; +/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number + * of all available curves or zero if a error occurred. + * In case r ist not zero nitems EC_builtin_curve structures + * are filled with the data of the first nitems internal groups */ +size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); + + +/* EC_POINT functions */ + +EC_POINT *EC_POINT_new(const EC_GROUP *); +void EC_POINT_free(EC_POINT *); +void EC_POINT_clear_free(EC_POINT *); +int EC_POINT_copy(EC_POINT *, const EC_POINT *); +EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *); + +const EC_METHOD *EC_POINT_method_of(const EC_POINT *); + +int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *); +int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *, + const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); +int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *, + BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); +int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *, + const BIGNUM *x, const BIGNUM *y, BN_CTX *); +int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *, + BIGNUM *x, BIGNUM *y, BN_CTX *); +int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *, + const BIGNUM *x, int y_bit, BN_CTX *); + +int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *, + const BIGNUM *x, const BIGNUM *y, BN_CTX *); +int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *, + BIGNUM *x, BIGNUM *y, BN_CTX *); +int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *, + const BIGNUM *x, int y_bit, BN_CTX *); + +size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, + unsigned char *buf, size_t len, BN_CTX *); +int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *, + const unsigned char *buf, size_t len, BN_CTX *); + +/* other interfaces to point2oct/oct2point: */ +BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BIGNUM *, BN_CTX *); +EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, + EC_POINT *, BN_CTX *); +char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BN_CTX *); +EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, + EC_POINT *, BN_CTX *); + +int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); +int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); +int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); + +int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *); +int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); +int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); + +int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); +int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); + + +int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *); +int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *); + +/* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */ +int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *); +/* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */ +int EC_GROUP_have_precompute_mult(const EC_GROUP *); + + + +/* ASN1 stuff */ + +/* EC_GROUP_get_basis_type() returns the NID of the basis type + * used to represent the field elements */ +int EC_GROUP_get_basis_type(const EC_GROUP *); +int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); +int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, + unsigned int *k2, unsigned int *k3); + +#define OPENSSL_EC_NAMED_CURVE 0x001 + +typedef struct ecpk_parameters_st ECPKPARAMETERS; + +EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); +int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); + +#define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x) +#define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x) +#define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \ + (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x)) +#define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \ + (unsigned char *)(x)) + +#ifndef OPENSSL_NO_BIO +int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); +#endif +#ifndef OPENSSL_NO_FP_API +int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); +#endif + +/* the EC_KEY stuff */ +typedef struct ec_key_st EC_KEY; + +/* some values for the encoding_flag */ +#define EC_PKEY_NO_PARAMETERS 0x001 +#define EC_PKEY_NO_PUBKEY 0x002 + +EC_KEY *EC_KEY_new(void); +EC_KEY *EC_KEY_new_by_curve_name(int nid); +void EC_KEY_free(EC_KEY *); +EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *); +EC_KEY *EC_KEY_dup(const EC_KEY *); + +int EC_KEY_up_ref(EC_KEY *); + +const EC_GROUP *EC_KEY_get0_group(const EC_KEY *); +int EC_KEY_set_group(EC_KEY *, const EC_GROUP *); +const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *); +int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *); +const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *); +int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *); +unsigned EC_KEY_get_enc_flags(const EC_KEY *); +void EC_KEY_set_enc_flags(EC_KEY *, unsigned int); +point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *); +void EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t); +/* functions to set/get method specific data */ +void *EC_KEY_get_key_method_data(EC_KEY *, + void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); +void EC_KEY_insert_key_method_data(EC_KEY *, void *data, + void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); +/* wrapper functions for the underlying EC_GROUP object */ +void EC_KEY_set_asn1_flag(EC_KEY *, int); +int EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx); + +/* EC_KEY_generate_key() creates a ec private (public) key */ +int EC_KEY_generate_key(EC_KEY *); +/* EC_KEY_check_key() */ +int EC_KEY_check_key(const EC_KEY *); + +/* de- and encoding functions for SEC1 ECPrivateKey */ +EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len); +int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out); +/* de- and encoding functions for EC parameters */ +EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len); +int i2d_ECParameters(EC_KEY *a, unsigned char **out); +/* de- and encoding functions for EC public key + * (octet string, not DER -- hence 'o2i' and 'i2o') */ +EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len); +int i2o_ECPublicKey(EC_KEY *a, unsigned char **out); + +#ifndef OPENSSL_NO_BIO +int ECParameters_print(BIO *bp, const EC_KEY *x); +int EC_KEY_print(BIO *bp, const EC_KEY *x, int off); +#endif +#ifndef OPENSSL_NO_FP_API +int ECParameters_print_fp(FILE *fp, const EC_KEY *x); +int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off); +#endif + +#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) + +#ifndef __cplusplus +#if defined(__SUNPRO_C) +# if __SUNPRO_C >= 0x520 +# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) +# endif +# endif +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_EC_strings(void); + +/* Error codes for the EC functions. */ + +/* Function codes. */ +#define EC_F_COMPUTE_WNAF 143 +#define EC_F_D2I_ECPARAMETERS 144 +#define EC_F_D2I_ECPKPARAMETERS 145 +#define EC_F_D2I_ECPRIVATEKEY 146 +#define EC_F_ECPARAMETERS_PRINT 147 +#define EC_F_ECPARAMETERS_PRINT_FP 148 +#define EC_F_ECPKPARAMETERS_PRINT 149 +#define EC_F_ECPKPARAMETERS_PRINT_FP 150 +#define EC_F_ECP_NIST_MOD_192 203 +#define EC_F_ECP_NIST_MOD_224 204 +#define EC_F_ECP_NIST_MOD_256 205 +#define EC_F_ECP_NIST_MOD_521 206 +#define EC_F_EC_ASN1_GROUP2CURVE 153 +#define EC_F_EC_ASN1_GROUP2FIELDID 154 +#define EC_F_EC_ASN1_GROUP2PARAMETERS 155 +#define EC_F_EC_ASN1_GROUP2PKPARAMETERS 156 +#define EC_F_EC_ASN1_PARAMETERS2GROUP 157 +#define EC_F_EC_ASN1_PKPARAMETERS2GROUP 158 +#define EC_F_EC_EX_DATA_SET_DATA 211 +#define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208 +#define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159 +#define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195 +#define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160 +#define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161 +#define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162 +#define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163 +#define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164 +#define EC_F_EC_GFP_MONT_FIELD_DECODE 133 +#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134 +#define EC_F_EC_GFP_MONT_FIELD_MUL 131 +#define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209 +#define EC_F_EC_GFP_MONT_FIELD_SQR 132 +#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189 +#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP 135 +#define EC_F_EC_GFP_NIST_FIELD_MUL 200 +#define EC_F_EC_GFP_NIST_FIELD_SQR 201 +#define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202 +#define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165 +#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166 +#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100 +#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101 +#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102 +#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103 +#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104 +#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137 +#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167 +#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105 +#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168 +#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128 +#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169 +#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129 +#define EC_F_EC_GROUP_CHECK 170 +#define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171 +#define EC_F_EC_GROUP_COPY 106 +#define EC_F_EC_GROUP_GET0_GENERATOR 139 +#define EC_F_EC_GROUP_GET_COFACTOR 140 +#define EC_F_EC_GROUP_GET_CURVE_GF2M 172 +#define EC_F_EC_GROUP_GET_CURVE_GFP 130 +#define EC_F_EC_GROUP_GET_DEGREE 173 +#define EC_F_EC_GROUP_GET_ORDER 141 +#define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193 +#define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194 +#define EC_F_EC_GROUP_NEW 108 +#define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174 +#define EC_F_EC_GROUP_NEW_FROM_DATA 175 +#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142 +#define EC_F_EC_GROUP_SET_CURVE_GF2M 176 +#define EC_F_EC_GROUP_SET_CURVE_GFP 109 +#define EC_F_EC_GROUP_SET_EXTRA_DATA 110 +#define EC_F_EC_GROUP_SET_GENERATOR 111 +#define EC_F_EC_KEY_CHECK_KEY 177 +#define EC_F_EC_KEY_COPY 178 +#define EC_F_EC_KEY_GENERATE_KEY 179 +#define EC_F_EC_KEY_NEW 182 +#define EC_F_EC_KEY_PRINT 180 +#define EC_F_EC_KEY_PRINT_FP 181 +#define EC_F_EC_POINTS_MAKE_AFFINE 136 +#define EC_F_EC_POINTS_MUL 138 +#define EC_F_EC_POINT_ADD 112 +#define EC_F_EC_POINT_CMP 113 +#define EC_F_EC_POINT_COPY 114 +#define EC_F_EC_POINT_DBL 115 +#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183 +#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116 +#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117 +#define EC_F_EC_POINT_INVERT 210 +#define EC_F_EC_POINT_IS_AT_INFINITY 118 +#define EC_F_EC_POINT_IS_ON_CURVE 119 +#define EC_F_EC_POINT_MAKE_AFFINE 120 +#define EC_F_EC_POINT_MUL 184 +#define EC_F_EC_POINT_NEW 121 +#define EC_F_EC_POINT_OCT2POINT 122 +#define EC_F_EC_POINT_POINT2OCT 123 +#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185 +#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124 +#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186 +#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125 +#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126 +#define EC_F_EC_POINT_SET_TO_INFINITY 127 +#define EC_F_EC_PRE_COMP_DUP 207 +#define EC_F_EC_PRE_COMP_NEW 196 +#define EC_F_EC_WNAF_MUL 187 +#define EC_F_EC_WNAF_PRECOMPUTE_MULT 188 +#define EC_F_I2D_ECPARAMETERS 190 +#define EC_F_I2D_ECPKPARAMETERS 191 +#define EC_F_I2D_ECPRIVATEKEY 192 +#define EC_F_I2O_ECPUBLICKEY 151 +#define EC_F_O2I_ECPUBLICKEY 152 + +/* Reason codes. */ +#define EC_R_ASN1_ERROR 115 +#define EC_R_ASN1_UNKNOWN_FIELD 116 +#define EC_R_BUFFER_TOO_SMALL 100 +#define EC_R_D2I_ECPKPARAMETERS_FAILURE 117 +#define EC_R_DISCRIMINANT_IS_ZERO 118 +#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119 +#define EC_R_FIELD_TOO_LARGE 138 +#define EC_R_GROUP2PKPARAMETERS_FAILURE 120 +#define EC_R_I2D_ECPKPARAMETERS_FAILURE 121 +#define EC_R_INCOMPATIBLE_OBJECTS 101 +#define EC_R_INVALID_ARGUMENT 112 +#define EC_R_INVALID_COMPRESSED_POINT 110 +#define EC_R_INVALID_COMPRESSION_BIT 109 +#define EC_R_INVALID_ENCODING 102 +#define EC_R_INVALID_FIELD 103 +#define EC_R_INVALID_FORM 104 +#define EC_R_INVALID_GROUP_ORDER 122 +#define EC_R_INVALID_PENTANOMIAL_BASIS 132 +#define EC_R_INVALID_PRIVATE_KEY 123 +#define EC_R_INVALID_TRINOMIAL_BASIS 137 +#define EC_R_MISSING_PARAMETERS 124 +#define EC_R_MISSING_PRIVATE_KEY 125 +#define EC_R_NOT_A_NIST_PRIME 135 +#define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136 +#define EC_R_NOT_IMPLEMENTED 126 +#define EC_R_NOT_INITIALIZED 111 +#define EC_R_NO_FIELD_MOD 133 +#define EC_R_PASSED_NULL_PARAMETER 134 +#define EC_R_PKPARAMETERS2GROUP_FAILURE 127 +#define EC_R_POINT_AT_INFINITY 106 +#define EC_R_POINT_IS_NOT_ON_CURVE 107 +#define EC_R_SLOT_FULL 108 +#define EC_R_UNDEFINED_GENERATOR 113 +#define EC_R_UNDEFINED_ORDER 128 +#define EC_R_UNKNOWN_GROUP 129 +#define EC_R_UNKNOWN_ORDER 114 +#define EC_R_UNSUPPORTED_FIELD 131 +#define EC_R_WRONG_ORDER 130 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ecdh.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ecdh.h new file mode 100644 index 0000000..b4b58ee --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ecdh.h @@ -0,0 +1,123 @@ +/* crypto/ecdh/ecdh.h */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * The Elliptic Curve Public-Key Crypto Library (ECC Code) included + * herein is developed by SUN MICROSYSTEMS, INC., and is contributed + * to the OpenSSL project. + * + * The ECC Code is licensed pursuant to the OpenSSL open source + * license provided below. + * + * The ECDH software is originally written by Douglas Stebila of + * Sun Microsystems Laboratories. + * + */ +/* ==================================================================== + * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#ifndef HEADER_ECDH_H +#define HEADER_ECDH_H + +#include + +#ifdef OPENSSL_NO_ECDH +#error ECDH is disabled. +#endif + +#include +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +const ECDH_METHOD *ECDH_OpenSSL(void); + +void ECDH_set_default_method(const ECDH_METHOD *); +const ECDH_METHOD *ECDH_get_default_method(void); +int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); + +int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, + void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); + +int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new + *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); +void *ECDH_get_ex_data(EC_KEY *d, int idx); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_ECDH_strings(void); + +/* Error codes for the ECDH functions. */ + +/* Function codes. */ +#define ECDH_F_ECDH_COMPUTE_KEY 100 +#define ECDH_F_ECDH_DATA_NEW_METHOD 101 + +/* Reason codes. */ +#define ECDH_R_KDF_FAILED 102 +#define ECDH_R_NO_PRIVATE_VALUE 100 +#define ECDH_R_POINT_ARITHMETIC_FAILURE 101 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ecdsa.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ecdsa.h new file mode 100644 index 0000000..f20c8ee --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ecdsa.h @@ -0,0 +1,271 @@ +/* crypto/ecdsa/ecdsa.h */ +/** + * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions + * \author Written by Nils Larsch for the OpenSSL project + */ +/* ==================================================================== + * Copyright (c) 2000-2003 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#ifndef HEADER_ECDSA_H +#define HEADER_ECDSA_H + +#include + +#ifdef OPENSSL_NO_ECDSA +#error ECDSA is disabled. +#endif + +#include +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ECDSA_SIG_st + { + BIGNUM *r; + BIGNUM *s; + } ECDSA_SIG; + +/** ECDSA_SIG *ECDSA_SIG_new(void) + * allocates and initialize a ECDSA_SIG structure + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_SIG_new(void); + +/** ECDSA_SIG_free + * frees a ECDSA_SIG structure + * \param a pointer to the ECDSA_SIG structure + */ +void ECDSA_SIG_free(ECDSA_SIG *a); + +/** i2d_ECDSA_SIG + * DER encode content of ECDSA_SIG object (note: this function modifies *pp + * (*pp += length of the DER encoded signature)). + * \param a pointer to the ECDSA_SIG object + * \param pp pointer to a unsigned char pointer for the output or NULL + * \return the length of the DER encoded ECDSA_SIG object or 0 + */ +int i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **pp); + +/** d2i_ECDSA_SIG + * decodes a DER encoded ECDSA signature (note: this function changes *pp + * (*pp += len)). + * \param v pointer to ECDSA_SIG pointer (may be NULL) + * \param pp buffer with the DER encoded signature + * \param len bufferlength + * \return pointer to the decoded ECDSA_SIG structure (or NULL) + */ +ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **v, const unsigned char **pp, long len); + +/** ECDSA_do_sign + * computes the ECDSA signature of the given hash value using + * the supplied private key and returns the created signature. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param eckey pointer to the EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL + */ +ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey); + +/** ECDSA_do_sign_ex + * computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param kinv optional pointer to a pre-computed inverse k + * \param rp optional pointer to the pre-computed rp value (see + * ECDSA_sign_setup + * \param eckey pointer to the EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL + */ +ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, + const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); + +/** ECDSA_do_verify + * verifies that the supplied signature is a valid ECDSA + * signature of the supplied hash value using the supplied public key. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param sig pointer to the ECDSA_SIG structure + * \param eckey pointer to the EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error + */ +int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, + const ECDSA_SIG *sig, EC_KEY* eckey); + +const ECDSA_METHOD *ECDSA_OpenSSL(void); + +/** ECDSA_set_default_method + * sets the default ECDSA method + * \param meth the new default ECDSA_METHOD + */ +void ECDSA_set_default_method(const ECDSA_METHOD *meth); + +/** ECDSA_get_default_method + * returns the default ECDSA method + * \return pointer to ECDSA_METHOD structure containing the default method + */ +const ECDSA_METHOD *ECDSA_get_default_method(void); + +/** ECDSA_set_method + * sets method to be used for the ECDSA operations + * \param eckey pointer to the EC_KEY object + * \param meth pointer to the new method + * \return 1 on success and 0 otherwise + */ +int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); + +/** ECDSA_size + * returns the maximum length of the DER encoded signature + * \param eckey pointer to a EC_KEY object + * \return numbers of bytes required for the DER encoded signature + */ +int ECDSA_size(const EC_KEY *eckey); + +/** ECDSA_sign_setup + * precompute parts of the signing operation. + * \param eckey pointer to the EC_KEY object containing a private EC key + * \param ctx pointer to a BN_CTX object (may be NULL) + * \param kinv pointer to a BIGNUM pointer for the inverse of k + * \param rp pointer to a BIGNUM pointer for x coordinate of k * generator + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, + BIGNUM **rp); + +/** ECDSA_sign + * computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig buffer to hold the DER encoded signature + * \param siglen pointer to the length of the returned signature + * \param eckey pointer to the EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); + + +/** ECDSA_sign_ex + * computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig buffer to hold the DER encoded signature + * \param siglen pointer to the length of the returned signature + * \param kinv optional pointer to a pre-computed inverse k + * \param rp optional pointer to the pre-computed rp value (see + * ECDSA_sign_setup + * \param eckey pointer to the EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, + const BIGNUM *rp, EC_KEY *eckey); + +/** ECDSA_verify + * verifies that the given signature is valid ECDSA signature + * of the supplied hash value using the specified public key. + * \param type this parameter is ignored + * \param dgst pointer to the hash value + * \param dgstlen length of the hash value + * \param sig pointer to the DER encoded signature + * \param siglen length of the DER encoded signature + * \param eckey pointer to the EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error + */ +int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, + const unsigned char *sig, int siglen, EC_KEY *eckey); + +/* the standard ex_data functions */ +int ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new + *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg); +void *ECDSA_get_ex_data(EC_KEY *d, int idx); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_ECDSA_strings(void); + +/* Error codes for the ECDSA functions. */ + +/* Function codes. */ +#define ECDSA_F_ECDSA_DATA_NEW_METHOD 100 +#define ECDSA_F_ECDSA_DO_SIGN 101 +#define ECDSA_F_ECDSA_DO_VERIFY 102 +#define ECDSA_F_ECDSA_SIGN_SETUP 103 + +/* Reason codes. */ +#define ECDSA_R_BAD_SIGNATURE 100 +#define ECDSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 101 +#define ECDSA_R_ERR_EC_LIB 102 +#define ECDSA_R_MISSING_PARAMETERS 103 +#define ECDSA_R_NEED_NEW_SETUP_VALUES 106 +#define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED 104 +#define ECDSA_R_SIGNATURE_MALLOC_FAILED 105 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/engine.h b/石器时代8.5客户端最新源代码/石器源码/openssl/engine.h new file mode 100644 index 0000000..f503595 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/engine.h @@ -0,0 +1,801 @@ +/* openssl/engine.h */ +/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL + * project 2000. + */ +/* ==================================================================== + * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_ENGINE_H +#define HEADER_ENGINE_H + +#include + +#ifdef OPENSSL_NO_ENGINE +#error ENGINE is disabled. +#endif + +#ifndef OPENSSL_NO_DEPRECATED +#include +#ifndef OPENSSL_NO_RSA +#include +#endif +#ifndef OPENSSL_NO_DSA +#include +#endif +#ifndef OPENSSL_NO_DH +#include +#endif +#ifndef OPENSSL_NO_ECDH +#include +#endif +#ifndef OPENSSL_NO_ECDSA +#include +#endif +#include +#include +#include +#include +#endif + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* These flags are used to control combinations of algorithm (methods) + * by bitwise "OR"ing. */ +#define ENGINE_METHOD_RSA (unsigned int)0x0001 +#define ENGINE_METHOD_DSA (unsigned int)0x0002 +#define ENGINE_METHOD_DH (unsigned int)0x0004 +#define ENGINE_METHOD_RAND (unsigned int)0x0008 +#define ENGINE_METHOD_ECDH (unsigned int)0x0010 +#define ENGINE_METHOD_ECDSA (unsigned int)0x0020 +#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 +#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 +#define ENGINE_METHOD_STORE (unsigned int)0x0100 +/* Obvious all-or-nothing cases. */ +#define ENGINE_METHOD_ALL (unsigned int)0xFFFF +#define ENGINE_METHOD_NONE (unsigned int)0x0000 + +/* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used + * internally to control registration of ENGINE implementations, and can be set + * by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to + * initialise registered ENGINEs if they are not already initialised. */ +#define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001 + +/* ENGINE flags that can be set by ENGINE_set_flags(). */ +/* #define ENGINE_FLAGS_MALLOCED 0x0001 */ /* Not used */ + +/* This flag is for ENGINEs that wish to handle the various 'CMD'-related + * control commands on their own. Without this flag, ENGINE_ctrl() handles these + * control commands on behalf of the ENGINE using their "cmd_defns" data. */ +#define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002 + +/* This flag is for ENGINEs who return new duplicate structures when found via + * "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl() + * commands are called in sequence as part of some stateful process like + * key-generation setup and execution), it can set this flag - then each attempt + * to obtain the ENGINE will result in it being copied into a new structure. + * Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments + * the existing ENGINE's structural reference count. */ +#define ENGINE_FLAGS_BY_ID_COPY (int)0x0004 + +/* ENGINEs can support their own command types, and these flags are used in + * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each + * command expects. Currently only numeric and string input is supported. If a + * control command supports none of the _NUMERIC, _STRING, or _NO_INPUT options, + * then it is regarded as an "internal" control command - and not for use in + * config setting situations. As such, they're not available to the + * ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() access. Changes to + * this list of 'command types' should be reflected carefully in + * ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). */ + +/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */ +#define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001 +/* accepts string input (cast from 'void*' to 'const char *', 4th parameter to + * ENGINE_ctrl) */ +#define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002 +/* Indicates that the control command takes *no* input. Ie. the control command + * is unparameterised. */ +#define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004 +/* Indicates that the control command is internal. This control command won't + * be shown in any output, and is only usable through the ENGINE_ctrl_cmd() + * function. */ +#define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008 + +/* NB: These 3 control commands are deprecated and should not be used. ENGINEs + * relying on these commands should compile conditional support for + * compatibility (eg. if these symbols are defined) but should also migrate the + * same functionality to their own ENGINE-specific control functions that can be + * "discovered" by calling applications. The fact these control commands + * wouldn't be "executable" (ie. usable by text-based config) doesn't change the + * fact that application code can find and use them without requiring per-ENGINE + * hacking. */ + +/* These flags are used to tell the ctrl function what should be done. + * All command numbers are shared between all engines, even if some don't + * make sense to some engines. In such a case, they do nothing but return + * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */ +#define ENGINE_CTRL_SET_LOGSTREAM 1 +#define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2 +#define ENGINE_CTRL_HUP 3 /* Close and reinitialise any + handles/connections etc. */ +#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */ +#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used + when calling the password + callback and the user + interface */ +#define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration, given + a string that represents a + file name or so */ +#define ENGINE_CTRL_LOAD_SECTION 7 /* Load data from a given + section in the already loaded + configuration */ + +/* These control commands allow an application to deal with an arbitrary engine + * in a dynamic way. Warn: Negative return values indicate errors FOR THESE + * COMMANDS because zero is used to indicate 'end-of-list'. Other commands, + * including ENGINE-specific command types, return zero for an error. + * + * An ENGINE can choose to implement these ctrl functions, and can internally + * manage things however it chooses - it does so by setting the + * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise the + * ENGINE_ctrl() code handles this on the ENGINE's behalf using the cmd_defns + * data (set using ENGINE_set_cmd_defns()). This means an ENGINE's ctrl() + * handler need only implement its own commands - the above "meta" commands will + * be taken care of. */ + +/* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", then + * all the remaining control commands will return failure, so it is worth + * checking this first if the caller is trying to "discover" the engine's + * capabilities and doesn't want errors generated unnecessarily. */ +#define ENGINE_CTRL_HAS_CTRL_FUNCTION 10 +/* Returns a positive command number for the first command supported by the + * engine. Returns zero if no ctrl commands are supported. */ +#define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11 +/* The 'long' argument specifies a command implemented by the engine, and the + * return value is the next command supported, or zero if there are no more. */ +#define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12 +/* The 'void*' argument is a command name (cast from 'const char *'), and the + * return value is the command that corresponds to it. */ +#define ENGINE_CTRL_GET_CMD_FROM_NAME 13 +/* The next two allow a command to be converted into its corresponding string + * form. In each case, the 'long' argument supplies the command. In the NAME_LEN + * case, the return value is the length of the command name (not counting a + * trailing EOL). In the NAME case, the 'void*' argument must be a string buffer + * large enough, and it will be populated with the name of the command (WITH a + * trailing EOL). */ +#define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14 +#define ENGINE_CTRL_GET_NAME_FROM_CMD 15 +/* The next two are similar but give a "short description" of a command. */ +#define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16 +#define ENGINE_CTRL_GET_DESC_FROM_CMD 17 +/* With this command, the return value is the OR'd combination of + * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given + * engine-specific ctrl command expects. */ +#define ENGINE_CTRL_GET_CMD_FLAGS 18 + +/* ENGINE implementations should start the numbering of their own control + * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */ +#define ENGINE_CMD_BASE 200 + +/* NB: These 2 nCipher "chil" control commands are deprecated, and their + * functionality is now available through ENGINE-specific control commands + * (exposed through the above-mentioned 'CMD'-handling). Code using these 2 + * commands should be migrated to the more general command handling before these + * are removed. */ + +/* Flags specific to the nCipher "chil" engine */ +#define ENGINE_CTRL_CHIL_SET_FORKCHECK 100 + /* Depending on the value of the (long)i argument, this sets or + * unsets the SimpleForkCheck flag in the CHIL API to enable or + * disable checking and workarounds for applications that fork(). + */ +#define ENGINE_CTRL_CHIL_NO_LOCKING 101 + /* This prevents the initialisation function from providing mutex + * callbacks to the nCipher library. */ + +/* If an ENGINE supports its own specific control commands and wishes the + * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on its + * behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN entries + * to ENGINE_set_cmd_defns(). It should also implement a ctrl() handler that + * supports the stated commands (ie. the "cmd_num" entries as described by the + * array). NB: The array must be ordered in increasing order of cmd_num. + * "null-terminated" means that the last ENGINE_CMD_DEFN element has cmd_num set + * to zero and/or cmd_name set to NULL. */ +typedef struct ENGINE_CMD_DEFN_st + { + unsigned int cmd_num; /* The command number */ + const char *cmd_name; /* The command name itself */ + const char *cmd_desc; /* A short description of the command */ + unsigned int cmd_flags; /* The input the command expects */ + } ENGINE_CMD_DEFN; + +/* Generic function pointer */ +typedef int (*ENGINE_GEN_FUNC_PTR)(void); +/* Generic function pointer taking no arguments */ +typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *); +/* Specific control function pointer */ +typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void)); +/* Generic load_key function pointer */ +typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, + UI_METHOD *ui_method, void *callback_data); +typedef int (*ENGINE_SSL_CLIENT_CERT_PTR)(ENGINE *, SSL *ssl, + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **pkey, + STACK_OF(X509) **pother, UI_METHOD *ui_method, void *callback_data); +/* These callback types are for an ENGINE's handler for cipher and digest logic. + * These handlers have these prototypes; + * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid); + * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid); + * Looking at how to implement these handlers in the case of cipher support, if + * the framework wants the EVP_CIPHER for 'nid', it will call; + * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure) + * If the framework wants a list of supported 'nid's, it will call; + * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error) + */ +/* Returns to a pointer to the array of supported cipher 'nid's. If the second + * parameter is non-NULL it is set to the size of the returned array. */ +typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int); +typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int); + +/* STRUCTURE functions ... all of these functions deal with pointers to ENGINE + * structures where the pointers have a "structural reference". This means that + * their reference is to allowed access to the structure but it does not imply + * that the structure is functional. To simply increment or decrement the + * structural reference count, use ENGINE_by_id and ENGINE_free. NB: This is not + * required when iterating using ENGINE_get_next as it will automatically + * decrement the structural reference count of the "current" ENGINE and + * increment the structural reference count of the ENGINE it returns (unless it + * is NULL). */ + +/* Get the first/last "ENGINE" type available. */ +ENGINE *ENGINE_get_first(void); +ENGINE *ENGINE_get_last(void); +/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ +ENGINE *ENGINE_get_next(ENGINE *e); +ENGINE *ENGINE_get_prev(ENGINE *e); +/* Add another "ENGINE" type into the array. */ +int ENGINE_add(ENGINE *e); +/* Remove an existing "ENGINE" type from the array. */ +int ENGINE_remove(ENGINE *e); +/* Retrieve an engine from the list by its unique "id" value. */ +ENGINE *ENGINE_by_id(const char *id); +/* Add all the built-in engines. */ +void ENGINE_load_openssl(void); +void ENGINE_load_dynamic(void); +#ifndef OPENSSL_NO_STATIC_ENGINE +void ENGINE_load_4758cca(void); +void ENGINE_load_aep(void); +void ENGINE_load_atalla(void); +void ENGINE_load_chil(void); +void ENGINE_load_cswift(void); +#ifndef OPENSSL_NO_GMP +void ENGINE_load_gmp(void); +#endif +void ENGINE_load_nuron(void); +void ENGINE_load_sureware(void); +void ENGINE_load_ubsec(void); +#endif +void ENGINE_load_cryptodev(void); +void ENGINE_load_padlock(void); +void ENGINE_load_builtin_engines(void); +#ifndef OPENSSL_NO_CAPIENG +void ENGINE_load_capi(void); +#endif + +/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation + * "registry" handling. */ +unsigned int ENGINE_get_table_flags(void); +void ENGINE_set_table_flags(unsigned int flags); + +/* Manage registration of ENGINEs per "table". For each type, there are 3 + * functions; + * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one) + * ENGINE_unregister_***(e) - unregister the implementation from 'e' + * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list + * Cleanup is automatically registered from each table when required, so + * ENGINE_cleanup() will reverse any "register" operations. */ + +int ENGINE_register_RSA(ENGINE *e); +void ENGINE_unregister_RSA(ENGINE *e); +void ENGINE_register_all_RSA(void); + +int ENGINE_register_DSA(ENGINE *e); +void ENGINE_unregister_DSA(ENGINE *e); +void ENGINE_register_all_DSA(void); + +int ENGINE_register_ECDH(ENGINE *e); +void ENGINE_unregister_ECDH(ENGINE *e); +void ENGINE_register_all_ECDH(void); + +int ENGINE_register_ECDSA(ENGINE *e); +void ENGINE_unregister_ECDSA(ENGINE *e); +void ENGINE_register_all_ECDSA(void); + +int ENGINE_register_DH(ENGINE *e); +void ENGINE_unregister_DH(ENGINE *e); +void ENGINE_register_all_DH(void); + +int ENGINE_register_RAND(ENGINE *e); +void ENGINE_unregister_RAND(ENGINE *e); +void ENGINE_register_all_RAND(void); + +int ENGINE_register_STORE(ENGINE *e); +void ENGINE_unregister_STORE(ENGINE *e); +void ENGINE_register_all_STORE(void); + +int ENGINE_register_ciphers(ENGINE *e); +void ENGINE_unregister_ciphers(ENGINE *e); +void ENGINE_register_all_ciphers(void); + +int ENGINE_register_digests(ENGINE *e); +void ENGINE_unregister_digests(ENGINE *e); +void ENGINE_register_all_digests(void); + +/* These functions register all support from the above categories. Note, use of + * these functions can result in static linkage of code your application may not + * need. If you only need a subset of functionality, consider using more + * selective initialisation. */ +int ENGINE_register_complete(ENGINE *e); +int ENGINE_register_all_complete(void); + +/* Send parametrised control commands to the engine. The possibilities to send + * down an integer, a pointer to data or a function pointer are provided. Any of + * the parameters may or may not be NULL, depending on the command number. In + * actuality, this function only requires a structural (rather than functional) + * reference to an engine, but many control commands may require the engine be + * functional. The caller should be aware of trying commands that require an + * operational ENGINE, and only use functional references in such situations. */ +int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); + +/* This function tests if an ENGINE-specific command is usable as a "setting". + * Eg. in an application's config file that gets processed through + * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to + * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). */ +int ENGINE_cmd_is_executable(ENGINE *e, int cmd); + +/* This function works like ENGINE_ctrl() with the exception of taking a + * command name instead of a command number, and can handle optional commands. + * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to + * use the cmd_name and cmd_optional. */ +int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, + long i, void *p, void (*f)(void), int cmd_optional); + +/* This function passes a command-name and argument to an ENGINE. The cmd_name + * is converted to a command number and the control command is called using + * 'arg' as an argument (unless the ENGINE doesn't support such a command, in + * which case no control command is called). The command is checked for input + * flags, and if necessary the argument will be converted to a numeric value. If + * cmd_optional is non-zero, then if the ENGINE doesn't support the given + * cmd_name the return value will be success anyway. This function is intended + * for applications to use so that users (or config files) can supply + * engine-specific config data to the ENGINE at run-time to control behaviour of + * specific engines. As such, it shouldn't be used for calling ENGINE_ctrl() + * functions that return data, deal with binary data, or that are otherwise + * supposed to be used directly through ENGINE_ctrl() in application code. Any + * "return" data from an ENGINE_ctrl() operation in this function will be lost - + * the return value is interpreted as failure if the return value is zero, + * success otherwise, and this function returns a boolean value as a result. In + * other words, vendors of 'ENGINE'-enabled devices should write ENGINE + * implementations with parameterisations that work in this scheme, so that + * compliant ENGINE-based applications can work consistently with the same + * configuration for the same ENGINE-enabled devices, across applications. */ +int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, + int cmd_optional); + +/* These functions are useful for manufacturing new ENGINE structures. They + * don't address reference counting at all - one uses them to populate an ENGINE + * structure with personalised implementations of things prior to using it + * directly or adding it to the builtin ENGINE list in OpenSSL. These are also + * here so that the ENGINE structure doesn't have to be exposed and break binary + * compatibility! */ +ENGINE *ENGINE_new(void); +int ENGINE_free(ENGINE *e); +int ENGINE_up_ref(ENGINE *e); +int ENGINE_set_id(ENGINE *e, const char *id); +int ENGINE_set_name(ENGINE *e, const char *name); +int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); +int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); +int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth); +int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth); +int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); +int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); +int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); +int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); +int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); +int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); +int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); +int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f); +int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); +int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, + ENGINE_SSL_CLIENT_CERT_PTR loadssl_f); +int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); +int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); +int ENGINE_set_flags(ENGINE *e, int flags); +int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); +/* These functions allow control over any per-structure ENGINE data. */ +int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); +void *ENGINE_get_ex_data(const ENGINE *e, int idx); + +/* This function cleans up anything that needs it. Eg. the ENGINE_add() function + * automatically ensures the list cleanup function is registered to be called + * from ENGINE_cleanup(). Similarly, all ENGINE_register_*** functions ensure + * ENGINE_cleanup() will clean up after them. */ +void ENGINE_cleanup(void); + +/* These return values from within the ENGINE structure. These can be useful + * with functional references as well as structural references - it depends + * which you obtained. Using the result for functional purposes if you only + * obtained a structural reference may be problematic! */ +const char *ENGINE_get_id(const ENGINE *e); +const char *ENGINE_get_name(const ENGINE *e); +const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); +const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); +const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); +const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); +const DH_METHOD *ENGINE_get_DH(const ENGINE *e); +const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); +const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); +ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); +ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e); +ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); +ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); +const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); +const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); +const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); +int ENGINE_get_flags(const ENGINE *e); + +/* FUNCTIONAL functions. These functions deal with ENGINE structures + * that have (or will) be initialised for use. Broadly speaking, the + * structural functions are useful for iterating the list of available + * engine types, creating new engine types, and other "list" operations. + * These functions actually deal with ENGINEs that are to be used. As + * such these functions can fail (if applicable) when particular + * engines are unavailable - eg. if a hardware accelerator is not + * attached or not functioning correctly. Each ENGINE has 2 reference + * counts; structural and functional. Every time a functional reference + * is obtained or released, a corresponding structural reference is + * automatically obtained or released too. */ + +/* Initialise a engine type for use (or up its reference count if it's + * already in use). This will fail if the engine is not currently + * operational and cannot initialise. */ +int ENGINE_init(ENGINE *e); +/* Free a functional reference to a engine type. This does not require + * a corresponding call to ENGINE_free as it also releases a structural + * reference. */ +int ENGINE_finish(ENGINE *e); + +/* The following functions handle keys that are stored in some secondary + * location, handled by the engine. The storage may be on a card or + * whatever. */ +EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **ppkey, + STACK_OF(X509) **pother, + UI_METHOD *ui_method, void *callback_data); + +/* This returns a pointer for the current ENGINE structure that + * is (by default) performing any RSA operations. The value returned + * is an incremented reference, so it should be free'd (ENGINE_finish) + * before it is discarded. */ +ENGINE *ENGINE_get_default_RSA(void); +/* Same for the other "methods" */ +ENGINE *ENGINE_get_default_DSA(void); +ENGINE *ENGINE_get_default_ECDH(void); +ENGINE *ENGINE_get_default_ECDSA(void); +ENGINE *ENGINE_get_default_DH(void); +ENGINE *ENGINE_get_default_RAND(void); +/* These functions can be used to get a functional reference to perform + * ciphering or digesting corresponding to "nid". */ +ENGINE *ENGINE_get_cipher_engine(int nid); +ENGINE *ENGINE_get_digest_engine(int nid); + +/* This sets a new default ENGINE structure for performing RSA + * operations. If the result is non-zero (success) then the ENGINE + * structure will have had its reference count up'd so the caller + * should still free their own reference 'e'. */ +int ENGINE_set_default_RSA(ENGINE *e); +int ENGINE_set_default_string(ENGINE *e, const char *def_list); +/* Same for the other "methods" */ +int ENGINE_set_default_DSA(ENGINE *e); +int ENGINE_set_default_ECDH(ENGINE *e); +int ENGINE_set_default_ECDSA(ENGINE *e); +int ENGINE_set_default_DH(ENGINE *e); +int ENGINE_set_default_RAND(ENGINE *e); +int ENGINE_set_default_ciphers(ENGINE *e); +int ENGINE_set_default_digests(ENGINE *e); + +/* The combination "set" - the flags are bitwise "OR"d from the + * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()" + * function, this function can result in unnecessary static linkage. If your + * application requires only specific functionality, consider using more + * selective functions. */ +int ENGINE_set_default(ENGINE *e, unsigned int flags); + +void ENGINE_add_conf_module(void); + +/* Deprecated functions ... */ +/* int ENGINE_clear_defaults(void); */ + +/**************************/ +/* DYNAMIC ENGINE SUPPORT */ +/**************************/ + +/* Binary/behaviour compatibility levels */ +#define OSSL_DYNAMIC_VERSION (unsigned long)0x00020000 +/* Binary versions older than this are too old for us (whether we're a loader or + * a loadee) */ +#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00020000 + +/* When compiling an ENGINE entirely as an external shared library, loadable by + * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure + * type provides the calling application's (or library's) error functionality + * and memory management function pointers to the loaded library. These should + * be used/set in the loaded library code so that the loading application's + * 'state' will be used/changed in all operations. The 'static_state' pointer + * allows the loaded library to know if it shares the same static data as the + * calling application (or library), and thus whether these callbacks need to be + * set or not. */ +typedef void *(*dyn_MEM_malloc_cb)(size_t); +typedef void *(*dyn_MEM_realloc_cb)(void *, size_t); +typedef void (*dyn_MEM_free_cb)(void *); +typedef struct st_dynamic_MEM_fns { + dyn_MEM_malloc_cb malloc_cb; + dyn_MEM_realloc_cb realloc_cb; + dyn_MEM_free_cb free_cb; + } dynamic_MEM_fns; +/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use + * these types so we (and any other dependant code) can simplify a bit?? */ +typedef void (*dyn_lock_locking_cb)(int,int,const char *,int); +typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int); +typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)( + const char *,int); +typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *, + const char *,int); +typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *, + const char *,int); +typedef struct st_dynamic_LOCK_fns { + dyn_lock_locking_cb lock_locking_cb; + dyn_lock_add_lock_cb lock_add_lock_cb; + dyn_dynlock_create_cb dynlock_create_cb; + dyn_dynlock_lock_cb dynlock_lock_cb; + dyn_dynlock_destroy_cb dynlock_destroy_cb; + } dynamic_LOCK_fns; +/* The top-level structure */ +typedef struct st_dynamic_fns { + void *static_state; + const ERR_FNS *err_fns; + const CRYPTO_EX_DATA_IMPL *ex_data_fns; + dynamic_MEM_fns mem_fns; + dynamic_LOCK_fns lock_fns; + } dynamic_fns; + +/* The version checking function should be of this prototype. NB: The + * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading code. + * If this function returns zero, it indicates a (potential) version + * incompatibility and the loaded library doesn't believe it can proceed. + * Otherwise, the returned value is the (latest) version supported by the + * loading library. The loader may still decide that the loaded code's version + * is unsatisfactory and could veto the load. The function is expected to + * be implemented with the symbol name "v_check", and a default implementation + * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */ +typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version); +#define IMPLEMENT_DYNAMIC_CHECK_FN() \ + OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \ + if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ + return 0; } + +/* This function is passed the ENGINE structure to initialise with its own + * function and command settings. It should not adjust the structural or + * functional reference counts. If this function returns zero, (a) the load will + * be aborted, (b) the previous ENGINE state will be memcpy'd back onto the + * structure, and (c) the shared library will be unloaded. So implementations + * should do their own internal cleanup in failure circumstances otherwise they + * could leak. The 'id' parameter, if non-NULL, represents the ENGINE id that + * the loader is looking for. If this is NULL, the shared library can choose to + * return failure or to initialise a 'default' ENGINE. If non-NULL, the shared + * library must initialise only an ENGINE matching the passed 'id'. The function + * is expected to be implemented with the symbol name "bind_engine". A standard + * implementation can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where + * the parameter 'fn' is a callback function that populates the ENGINE structure + * and returns an int value (zero for failure). 'fn' should have prototype; + * [static] int fn(ENGINE *e, const char *id); */ +typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, + const dynamic_fns *fns); +#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ + OPENSSL_EXPORT \ + int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ + if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \ + if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \ + fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \ + return 0; \ + CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \ + CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \ + CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \ + CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \ + CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \ + if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \ + return 0; \ + if(!ERR_set_implementation(fns->err_fns)) return 0; \ + skip_cbs: \ + if(!fn(e,id)) return 0; \ + return 1; } + +/* If the loading application (or library) and the loaded ENGINE library share + * the same static data (eg. they're both dynamically linked to the same + * libcrypto.so) we need a way to avoid trying to set system callbacks - this + * would fail, and for the same reason that it's unnecessary to try. If the + * loaded ENGINE has (or gets from through the loader) its own copy of the + * libcrypto static data, we will need to set the callbacks. The easiest way to + * detect this is to have a function that returns a pointer to some static data + * and let the loading application and loaded ENGINE compare their respective + * values. */ +void *ENGINE_get_static_state(void); + +#if defined(__OpenBSD__) || defined(__FreeBSD__) +void ENGINE_setup_bsd_cryptodev(void); +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_ENGINE_strings(void); + +/* Error codes for the ENGINE functions. */ + +/* Function codes. */ +#define ENGINE_F_DYNAMIC_CTRL 180 +#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 +#define ENGINE_F_DYNAMIC_LOAD 182 +#define ENGINE_F_DYNAMIC_SET_DATA_CTX 183 +#define ENGINE_F_ENGINE_ADD 105 +#define ENGINE_F_ENGINE_BY_ID 106 +#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 +#define ENGINE_F_ENGINE_CTRL 142 +#define ENGINE_F_ENGINE_CTRL_CMD 178 +#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 +#define ENGINE_F_ENGINE_FINISH 107 +#define ENGINE_F_ENGINE_FREE_UTIL 108 +#define ENGINE_F_ENGINE_GET_CIPHER 185 +#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177 +#define ENGINE_F_ENGINE_GET_DIGEST 186 +#define ENGINE_F_ENGINE_GET_NEXT 115 +#define ENGINE_F_ENGINE_GET_PREV 116 +#define ENGINE_F_ENGINE_INIT 119 +#define ENGINE_F_ENGINE_LIST_ADD 120 +#define ENGINE_F_ENGINE_LIST_REMOVE 121 +#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 +#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 +#define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 192 +#define ENGINE_F_ENGINE_NEW 122 +#define ENGINE_F_ENGINE_REMOVE 123 +#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 +#define ENGINE_F_ENGINE_SET_DEFAULT_TYPE 126 +#define ENGINE_F_ENGINE_SET_ID 129 +#define ENGINE_F_ENGINE_SET_NAME 130 +#define ENGINE_F_ENGINE_TABLE_REGISTER 184 +#define ENGINE_F_ENGINE_UNLOAD_KEY 152 +#define ENGINE_F_ENGINE_UNLOCKED_FINISH 191 +#define ENGINE_F_ENGINE_UP_REF 190 +#define ENGINE_F_INT_CTRL_HELPER 172 +#define ENGINE_F_INT_ENGINE_CONFIGURE 188 +#define ENGINE_F_INT_ENGINE_MODULE_INIT 187 +#define ENGINE_F_LOG_MESSAGE 141 + +/* Reason codes. */ +#define ENGINE_R_ALREADY_LOADED 100 +#define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133 +#define ENGINE_R_CMD_NOT_EXECUTABLE 134 +#define ENGINE_R_COMMAND_TAKES_INPUT 135 +#define ENGINE_R_COMMAND_TAKES_NO_INPUT 136 +#define ENGINE_R_CONFLICTING_ENGINE_ID 103 +#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119 +#define ENGINE_R_DH_NOT_IMPLEMENTED 139 +#define ENGINE_R_DSA_NOT_IMPLEMENTED 140 +#define ENGINE_R_DSO_FAILURE 104 +#define ENGINE_R_DSO_NOT_FOUND 132 +#define ENGINE_R_ENGINES_SECTION_ERROR 148 +#define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105 +#define ENGINE_R_ENGINE_SECTION_ERROR 149 +#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128 +#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129 +#define ENGINE_R_FINISH_FAILED 106 +#define ENGINE_R_GET_HANDLE_FAILED 107 +#define ENGINE_R_ID_OR_NAME_MISSING 108 +#define ENGINE_R_INIT_FAILED 109 +#define ENGINE_R_INTERNAL_LIST_ERROR 110 +#define ENGINE_R_INVALID_ARGUMENT 143 +#define ENGINE_R_INVALID_CMD_NAME 137 +#define ENGINE_R_INVALID_CMD_NUMBER 138 +#define ENGINE_R_INVALID_INIT_VALUE 151 +#define ENGINE_R_INVALID_STRING 150 +#define ENGINE_R_NOT_INITIALISED 117 +#define ENGINE_R_NOT_LOADED 112 +#define ENGINE_R_NO_CONTROL_FUNCTION 120 +#define ENGINE_R_NO_INDEX 144 +#define ENGINE_R_NO_LOAD_FUNCTION 125 +#define ENGINE_R_NO_REFERENCE 130 +#define ENGINE_R_NO_SUCH_ENGINE 116 +#define ENGINE_R_NO_UNLOAD_FUNCTION 126 +#define ENGINE_R_PROVIDE_PARAMETERS 113 +#define ENGINE_R_RSA_NOT_IMPLEMENTED 141 +#define ENGINE_R_UNIMPLEMENTED_CIPHER 146 +#define ENGINE_R_UNIMPLEMENTED_DIGEST 147 +#define ENGINE_R_VERSION_INCOMPATIBILITY 145 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/err.h b/石器时代8.5客户端最新源代码/石器源码/openssl/err.h new file mode 100644 index 0000000..dcac415 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/err.h @@ -0,0 +1,330 @@ +/* crypto/err/err.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_ERR_H +#define HEADER_ERR_H + +#include + +#ifndef OPENSSL_NO_FP_API +#include +#include +#endif + +#include +#ifndef OPENSSL_NO_BIO +#include +#endif +#ifndef OPENSSL_NO_LHASH +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef OPENSSL_NO_ERR +#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) +#else +#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) +#endif + +#include + +#define ERR_TXT_MALLOCED 0x01 +#define ERR_TXT_STRING 0x02 + +#define ERR_FLAG_MARK 0x01 + +#define ERR_NUM_ERRORS 16 +typedef struct err_state_st + { + unsigned long pid; + int err_flags[ERR_NUM_ERRORS]; + unsigned long err_buffer[ERR_NUM_ERRORS]; + char *err_data[ERR_NUM_ERRORS]; + int err_data_flags[ERR_NUM_ERRORS]; + const char *err_file[ERR_NUM_ERRORS]; + int err_line[ERR_NUM_ERRORS]; + int top,bottom; + } ERR_STATE; + +/* library */ +#define ERR_LIB_NONE 1 +#define ERR_LIB_SYS 2 +#define ERR_LIB_BN 3 +#define ERR_LIB_RSA 4 +#define ERR_LIB_DH 5 +#define ERR_LIB_EVP 6 +#define ERR_LIB_BUF 7 +#define ERR_LIB_OBJ 8 +#define ERR_LIB_PEM 9 +#define ERR_LIB_DSA 10 +#define ERR_LIB_X509 11 +/* #define ERR_LIB_METH 12 */ +#define ERR_LIB_ASN1 13 +#define ERR_LIB_CONF 14 +#define ERR_LIB_CRYPTO 15 +#define ERR_LIB_EC 16 +#define ERR_LIB_SSL 20 +/* #define ERR_LIB_SSL23 21 */ +/* #define ERR_LIB_SSL2 22 */ +/* #define ERR_LIB_SSL3 23 */ +/* #define ERR_LIB_RSAREF 30 */ +/* #define ERR_LIB_PROXY 31 */ +#define ERR_LIB_BIO 32 +#define ERR_LIB_PKCS7 33 +#define ERR_LIB_X509V3 34 +#define ERR_LIB_PKCS12 35 +#define ERR_LIB_RAND 36 +#define ERR_LIB_DSO 37 +#define ERR_LIB_ENGINE 38 +#define ERR_LIB_OCSP 39 +#define ERR_LIB_UI 40 +#define ERR_LIB_COMP 41 +#define ERR_LIB_ECDSA 42 +#define ERR_LIB_ECDH 43 +#define ERR_LIB_STORE 44 +#define ERR_LIB_FIPS 45 +#define ERR_LIB_CMS 46 +#define ERR_LIB_JPAKE 47 + +#define ERR_LIB_USER 128 + +#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__) +#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__) +#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__) +#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),__FILE__,__LINE__) +#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),__FILE__,__LINE__) +#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),__FILE__,__LINE__) +#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),__FILE__,__LINE__) +#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),__FILE__,__LINE__) +#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),__FILE__,__LINE__) +#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),__FILE__,__LINE__) +#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),__FILE__,__LINE__) +#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),__FILE__,__LINE__) +#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),__FILE__,__LINE__) +#define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),__FILE__,__LINE__) +#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__) +#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),__FILE__,__LINE__) +#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),__FILE__,__LINE__) +#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),__FILE__,__LINE__) +#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),__FILE__,__LINE__) +#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),__FILE__,__LINE__) +#define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),__FILE__,__LINE__) +#define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),__FILE__,__LINE__) +#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__) +#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__) +#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__) +#define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),__FILE__,__LINE__) +#define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),__FILE__,__LINE__) +#define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),__FILE__,__LINE__) +#define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__) +#define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),__FILE__,__LINE__) +#define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) + +/* Borland C seems too stupid to be able to shift and do longs in + * the pre-processor :-( */ +#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \ + ((((unsigned long)f)&0xfffL)*0x1000)| \ + ((((unsigned long)r)&0xfffL))) +#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL) +#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL) +#define ERR_GET_REASON(l) (int)((l)&0xfffL) +#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL) + + +/* OS functions */ +#define SYS_F_FOPEN 1 +#define SYS_F_CONNECT 2 +#define SYS_F_GETSERVBYNAME 3 +#define SYS_F_SOCKET 4 +#define SYS_F_IOCTLSOCKET 5 +#define SYS_F_BIND 6 +#define SYS_F_LISTEN 7 +#define SYS_F_ACCEPT 8 +#define SYS_F_WSASTARTUP 9 /* Winsock stuff */ +#define SYS_F_OPENDIR 10 +#define SYS_F_FREAD 11 + + +/* reasons */ +#define ERR_R_SYS_LIB ERR_LIB_SYS /* 2 */ +#define ERR_R_BN_LIB ERR_LIB_BN /* 3 */ +#define ERR_R_RSA_LIB ERR_LIB_RSA /* 4 */ +#define ERR_R_DH_LIB ERR_LIB_DH /* 5 */ +#define ERR_R_EVP_LIB ERR_LIB_EVP /* 6 */ +#define ERR_R_BUF_LIB ERR_LIB_BUF /* 7 */ +#define ERR_R_OBJ_LIB ERR_LIB_OBJ /* 8 */ +#define ERR_R_PEM_LIB ERR_LIB_PEM /* 9 */ +#define ERR_R_DSA_LIB ERR_LIB_DSA /* 10 */ +#define ERR_R_X509_LIB ERR_LIB_X509 /* 11 */ +#define ERR_R_ASN1_LIB ERR_LIB_ASN1 /* 13 */ +#define ERR_R_CONF_LIB ERR_LIB_CONF /* 14 */ +#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO /* 15 */ +#define ERR_R_EC_LIB ERR_LIB_EC /* 16 */ +#define ERR_R_SSL_LIB ERR_LIB_SSL /* 20 */ +#define ERR_R_BIO_LIB ERR_LIB_BIO /* 32 */ +#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 /* 33 */ +#define ERR_R_X509V3_LIB ERR_LIB_X509V3 /* 34 */ +#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 /* 35 */ +#define ERR_R_RAND_LIB ERR_LIB_RAND /* 36 */ +#define ERR_R_DSO_LIB ERR_LIB_DSO /* 37 */ +#define ERR_R_ENGINE_LIB ERR_LIB_ENGINE /* 38 */ +#define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */ +#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */ +#define ERR_R_COMP_LIB ERR_LIB_COMP /* 41 */ +#define ERR_R_ECDSA_LIB ERR_LIB_ECDSA /* 42 */ +#define ERR_R_ECDH_LIB ERR_LIB_ECDH /* 43 */ +#define ERR_R_STORE_LIB ERR_LIB_STORE /* 44 */ + +#define ERR_R_NESTED_ASN1_ERROR 58 +#define ERR_R_BAD_ASN1_OBJECT_HEADER 59 +#define ERR_R_BAD_GET_ASN1_OBJECT_CALL 60 +#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE 61 +#define ERR_R_ASN1_LENGTH_MISMATCH 62 +#define ERR_R_MISSING_ASN1_EOS 63 + +/* fatal error */ +#define ERR_R_FATAL 64 +#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) +#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) +#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) +#define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL) +#define ERR_R_DISABLED (5|ERR_R_FATAL) + +/* 99 is the maximum possible ERR_R_... code, higher values + * are reserved for the individual libraries */ + + +typedef struct ERR_string_data_st + { + unsigned long error; + const char *string; + } ERR_STRING_DATA; + +void ERR_put_error(int lib, int func,int reason,const char *file,int line); +void ERR_set_error_data(char *data,int flags); + +unsigned long ERR_get_error(void); +unsigned long ERR_get_error_line(const char **file,int *line); +unsigned long ERR_get_error_line_data(const char **file,int *line, + const char **data, int *flags); +unsigned long ERR_peek_error(void); +unsigned long ERR_peek_error_line(const char **file,int *line); +unsigned long ERR_peek_error_line_data(const char **file,int *line, + const char **data,int *flags); +unsigned long ERR_peek_last_error(void); +unsigned long ERR_peek_last_error_line(const char **file,int *line); +unsigned long ERR_peek_last_error_line_data(const char **file,int *line, + const char **data,int *flags); +void ERR_clear_error(void ); +char *ERR_error_string(unsigned long e,char *buf); +void ERR_error_string_n(unsigned long e, char *buf, size_t len); +const char *ERR_lib_error_string(unsigned long e); +const char *ERR_func_error_string(unsigned long e); +const char *ERR_reason_error_string(unsigned long e); +void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), + void *u); +#ifndef OPENSSL_NO_FP_API +void ERR_print_errors_fp(FILE *fp); +#endif +#ifndef OPENSSL_NO_BIO +void ERR_print_errors(BIO *bp); +void ERR_add_error_data(int num, ...); +#endif +void ERR_load_strings(int lib,ERR_STRING_DATA str[]); +void ERR_unload_strings(int lib,ERR_STRING_DATA str[]); +void ERR_load_ERR_strings(void); +void ERR_load_crypto_strings(void); +void ERR_free_strings(void); + +void ERR_remove_state(unsigned long pid); /* if zero we look it up */ +ERR_STATE *ERR_get_state(void); + +#ifndef OPENSSL_NO_LHASH +LHASH *ERR_get_string_table(void); +LHASH *ERR_get_err_state_table(void); +void ERR_release_err_state_table(LHASH **hash); +#endif + +int ERR_get_next_error_library(void); + +int ERR_set_mark(void); +int ERR_pop_to_mark(void); + +#ifdef OPENSSL_FIPS +void int_ERR_set_state_func(ERR_STATE *(*get_func)(void), + void (*remove_func)(unsigned long pid)); +void int_ERR_lib_init(void); +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct st_ERR_FNS ERR_FNS; */ +/* An application can use this function and provide the return value to loaded + * modules that should use the application's ERR state/functionality */ +const ERR_FNS *ERR_get_implementation(void); +/* A loaded module should call this function prior to any ERR operations using + * the application's "ERR_FNS". */ +int ERR_set_implementation(const ERR_FNS *fns); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/evp.h b/石器时代8.5客户端最新源代码/石器源码/openssl/evp.h new file mode 100644 index 0000000..79c0971 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/evp.h @@ -0,0 +1,1059 @@ +/* crypto/evp/evp.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_ENVELOPE_H +#define HEADER_ENVELOPE_H + +#ifdef OPENSSL_ALGORITHM_DEFINES +# include +#else +# define OPENSSL_ALGORITHM_DEFINES +# include +# undef OPENSSL_ALGORITHM_DEFINES +#endif + +#include + +#include + +#ifndef OPENSSL_NO_BIO +#include +#endif + +#ifdef OPENSSL_FIPS +#include +#endif + +/* +#define EVP_RC2_KEY_SIZE 16 +#define EVP_RC4_KEY_SIZE 16 +#define EVP_BLOWFISH_KEY_SIZE 16 +#define EVP_CAST5_KEY_SIZE 16 +#define EVP_RC5_32_12_16_KEY_SIZE 16 +*/ +#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ +#define EVP_MAX_KEY_LENGTH 32 +#define EVP_MAX_IV_LENGTH 16 +#define EVP_MAX_BLOCK_LENGTH 32 + +#define PKCS5_SALT_LEN 8 +/* Default PKCS#5 iteration count */ +#define PKCS5_DEFAULT_ITER 2048 + +#include + +#define EVP_PK_RSA 0x0001 +#define EVP_PK_DSA 0x0002 +#define EVP_PK_DH 0x0004 +#define EVP_PK_EC 0x0008 +#define EVP_PKT_SIGN 0x0010 +#define EVP_PKT_ENC 0x0020 +#define EVP_PKT_EXCH 0x0040 +#define EVP_PKS_RSA 0x0100 +#define EVP_PKS_DSA 0x0200 +#define EVP_PKS_EC 0x0400 +#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ + +#define EVP_PKEY_NONE NID_undef +#define EVP_PKEY_RSA NID_rsaEncryption +#define EVP_PKEY_RSA2 NID_rsa +#define EVP_PKEY_DSA NID_dsa +#define EVP_PKEY_DSA1 NID_dsa_2 +#define EVP_PKEY_DSA2 NID_dsaWithSHA +#define EVP_PKEY_DSA3 NID_dsaWithSHA1 +#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 +#define EVP_PKEY_DH NID_dhKeyAgreement +#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey + +#ifdef __cplusplus +extern "C" { +#endif + +/* Type needs to be a bit field + * Sub-type needs to be for variations on the method, as in, can it do + * arbitrary encryption.... */ +struct evp_pkey_st + { + int type; + int save_type; + int references; + union { + char *ptr; +#ifndef OPENSSL_NO_RSA + struct rsa_st *rsa; /* RSA */ +#endif +#ifndef OPENSSL_NO_DSA + struct dsa_st *dsa; /* DSA */ +#endif +#ifndef OPENSSL_NO_DH + struct dh_st *dh; /* DH */ +#endif +#ifndef OPENSSL_NO_EC + struct ec_key_st *ec; /* ECC */ +#endif + } pkey; + int save_parameters; + STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ + } /* EVP_PKEY */; + +#define EVP_PKEY_MO_SIGN 0x0001 +#define EVP_PKEY_MO_VERIFY 0x0002 +#define EVP_PKEY_MO_ENCRYPT 0x0004 +#define EVP_PKEY_MO_DECRYPT 0x0008 + +#if 0 +/* This structure is required to tie the message digest and signing together. + * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or + * oid, md and pkey. + * This is required because for various smart-card perform the digest and + * signing/verification on-board. To handle this case, the specific + * EVP_MD and EVP_PKEY_METHODs need to be closely associated. + * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it. + * This can either be software or a token to provide the required low level + * routines. + */ +typedef struct evp_pkey_md_st + { + int oid; + EVP_MD *md; + EVP_PKEY_METHOD *pkey; + } EVP_PKEY_MD; + +#define EVP_rsa_md2() \ + EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ + EVP_rsa_pkcs1(),EVP_md2()) +#define EVP_rsa_md5() \ + EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ + EVP_rsa_pkcs1(),EVP_md5()) +#define EVP_rsa_sha0() \ + EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ + EVP_rsa_pkcs1(),EVP_sha()) +#define EVP_rsa_sha1() \ + EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ + EVP_rsa_pkcs1(),EVP_sha1()) +#define EVP_rsa_ripemd160() \ + EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ + EVP_rsa_pkcs1(),EVP_ripemd160()) +#define EVP_rsa_mdc2() \ + EVP_PKEY_MD_add(NID_mdc2WithRSA,\ + EVP_rsa_octet_string(),EVP_mdc2()) +#define EVP_dsa_sha() \ + EVP_PKEY_MD_add(NID_dsaWithSHA,\ + EVP_dsa(),EVP_sha()) +#define EVP_dsa_sha1() \ + EVP_PKEY_MD_add(NID_dsaWithSHA1,\ + EVP_dsa(),EVP_sha1()) + +typedef struct evp_pkey_method_st + { + char *name; + int flags; + int type; /* RSA, DSA, an SSLeay specific constant */ + int oid; /* For the pub-key type */ + int encrypt_oid; /* pub/priv key encryption */ + + int (*sign)(); + int (*verify)(); + struct { + int (*set)(); /* get and/or set the underlying type */ + int (*get)(); + int (*encrypt)(); + int (*decrypt)(); + int (*i2d)(); + int (*d2i)(); + int (*dup)(); + } pub,priv; + int (*set_asn1_parameters)(); + int (*get_asn1_parameters)(); + } EVP_PKEY_METHOD; +#endif + +#ifndef EVP_MD +struct env_md_st + { + int type; + int pkey_type; + int md_size; + unsigned long flags; + int (*init)(EVP_MD_CTX *ctx); + int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count); + int (*final)(EVP_MD_CTX *ctx,unsigned char *md); + int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from); + int (*cleanup)(EVP_MD_CTX *ctx); + + /* FIXME: prototype these some day */ + int (*sign)(int type, const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, void *key); + int (*verify)(int type, const unsigned char *m, unsigned int m_length, + const unsigned char *sigbuf, unsigned int siglen, + void *key); + int required_pkey_type[5]; /*EVP_PKEY_xxx */ + int block_size; + int ctx_size; /* how big does the ctx->md_data need to be */ + } /* EVP_MD */; + +typedef int evp_sign_method(int type,const unsigned char *m, + unsigned int m_length,unsigned char *sigret, + unsigned int *siglen, void *key); +typedef int evp_verify_method(int type,const unsigned char *m, + unsigned int m_length,const unsigned char *sigbuf, + unsigned int siglen, void *key); + +typedef struct + { + EVP_MD_CTX *mctx; + void *key; + } EVP_MD_SVCTX; + +#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single + * block */ + +#define EVP_MD_FLAG_FIPS 0x0400 /* Note if suitable for use in FIPS mode */ + +#define EVP_MD_FLAG_SVCTX 0x0800 /* pass EVP_MD_SVCTX to sign/verify */ + +#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} + +#ifndef OPENSSL_NO_DSA +#define EVP_PKEY_DSA_method (evp_sign_method *)DSA_sign, \ + (evp_verify_method *)DSA_verify, \ + {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ + EVP_PKEY_DSA4,0} +#else +#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method +#endif + +#ifndef OPENSSL_NO_ECDSA +#define EVP_PKEY_ECDSA_method (evp_sign_method *)ECDSA_sign, \ + (evp_verify_method *)ECDSA_verify, \ + {EVP_PKEY_EC,0,0,0} +#else +#define EVP_PKEY_ECDSA_method EVP_PKEY_NULL_method +#endif + +#ifndef OPENSSL_NO_RSA +#define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \ + (evp_verify_method *)RSA_verify, \ + {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} +#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ + (evp_sign_method *)RSA_sign_ASN1_OCTET_STRING, \ + (evp_verify_method *)RSA_verify_ASN1_OCTET_STRING, \ + {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} +#else +#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method +#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method +#endif + +#endif /* !EVP_MD */ + +struct env_md_ctx_st + { + const EVP_MD *digest; + ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */ + unsigned long flags; + void *md_data; + } /* EVP_MD_CTX */; + +/* values for EVP_MD_CTX flags */ + +#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called + * once only */ +#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been + * cleaned */ +#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data + * in EVP_MD_CTX_cleanup */ +#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest + * in FIPS mode */ + +#define EVP_MD_CTX_FLAG_PAD_MASK 0xF0 /* RSA mode to use */ +#define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00 /* PKCS#1 v1.5 mode */ +#define EVP_MD_CTX_FLAG_PAD_X931 0x10 /* X9.31 mode */ +#define EVP_MD_CTX_FLAG_PAD_PSS 0x20 /* PSS mode */ +#define M_EVP_MD_CTX_FLAG_PSS_SALT(ctx) \ + ((ctx->flags>>16) &0xFFFF) /* seed length */ +#define EVP_MD_CTX_FLAG_PSS_MDLEN 0xFFFF /* salt len same as digest */ +#define EVP_MD_CTX_FLAG_PSS_MREC 0xFFFE /* salt max or auto recovered */ + +struct evp_cipher_st + { + int nid; + int block_size; + int key_len; /* Default value for variable length ciphers */ + int iv_len; + unsigned long flags; /* Various flags */ + int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv, int enc); /* init key */ + int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out, + const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */ + int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */ + int ctx_size; /* how big ctx->cipher_data needs to be */ + int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */ + int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */ + int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */ + void *app_data; /* Application data */ + } /* EVP_CIPHER */; + +/* Values for cipher flags */ + +/* Modes for ciphers */ + +#define EVP_CIPH_STREAM_CIPHER 0x0 +#define EVP_CIPH_ECB_MODE 0x1 +#define EVP_CIPH_CBC_MODE 0x2 +#define EVP_CIPH_CFB_MODE 0x3 +#define EVP_CIPH_OFB_MODE 0x4 +#define EVP_CIPH_MODE 0x7 +/* Set if variable length cipher */ +#define EVP_CIPH_VARIABLE_LENGTH 0x8 +/* Set if the iv handling should be done by the cipher itself */ +#define EVP_CIPH_CUSTOM_IV 0x10 +/* Set if the cipher's init() function should be called if key is NULL */ +#define EVP_CIPH_ALWAYS_CALL_INIT 0x20 +/* Call ctrl() to init cipher parameters */ +#define EVP_CIPH_CTRL_INIT 0x40 +/* Don't use standard key length function */ +#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 +/* Don't use standard block padding */ +#define EVP_CIPH_NO_PADDING 0x100 +/* cipher handles random key generation */ +#define EVP_CIPH_RAND_KEY 0x200 +/* Note if suitable for use in FIPS mode */ +#define EVP_CIPH_FLAG_FIPS 0x400 +/* Allow non FIPS cipher in FIPS mode */ +#define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800 +/* Allow use default ASN1 get/set iv */ +#define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000 +/* Buffer length in bits not bytes: CFB1 mode only */ +#define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 + +/* ctrl() values */ + +#define EVP_CTRL_INIT 0x0 +#define EVP_CTRL_SET_KEY_LENGTH 0x1 +#define EVP_CTRL_GET_RC2_KEY_BITS 0x2 +#define EVP_CTRL_SET_RC2_KEY_BITS 0x3 +#define EVP_CTRL_GET_RC5_ROUNDS 0x4 +#define EVP_CTRL_SET_RC5_ROUNDS 0x5 +#define EVP_CTRL_RAND_KEY 0x6 + +typedef struct evp_cipher_info_st + { + const EVP_CIPHER *cipher; + unsigned char iv[EVP_MAX_IV_LENGTH]; + } EVP_CIPHER_INFO; + +struct evp_cipher_ctx_st + { + const EVP_CIPHER *cipher; + ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */ + int encrypt; /* encrypt or decrypt */ + int buf_len; /* number we have left */ + + unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ + unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ + unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */ + int num; /* used by cfb/ofb mode */ + + void *app_data; /* application stuff */ + int key_len; /* May change for variable length cipher */ + unsigned long flags; /* Various flags */ + void *cipher_data; /* per EVP data */ + int final_used; + int block_mask; + unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */ + } /* EVP_CIPHER_CTX */; + +typedef struct evp_Encode_Ctx_st + { + int num; /* number saved in a partial encode/decode */ + int length; /* The length is either the output line length + * (in input bytes) or the shortest input line + * length that is ok. Once decoding begins, + * the length is adjusted up each time a longer + * line is decoded */ + unsigned char enc_data[80]; /* data to encode */ + int line_num; /* number read on current line */ + int expect_nl; + } EVP_ENCODE_CTX; + +/* Password based encryption function */ +typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md, int en_de); + +#ifndef OPENSSL_NO_RSA +#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ + (char *)(rsa)) +#endif + +#ifndef OPENSSL_NO_DSA +#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ + (char *)(dsa)) +#endif + +#ifndef OPENSSL_NO_DH +#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ + (char *)(dh)) +#endif + +#ifndef OPENSSL_NO_EC +#define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\ + (char *)(eckey)) +#endif + +/* Add some extra combinations */ +#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) +#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) +#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) +#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) + +/* Macros to reduce FIPS dependencies: do NOT use in applications */ +#define M_EVP_MD_size(e) ((e)->md_size) +#define M_EVP_MD_block_size(e) ((e)->block_size) +#define M_EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs)) +#define M_EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs)) +#define M_EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs)) +#define M_EVP_MD_type(e) ((e)->type) +#define M_EVP_MD_CTX_type(e) M_EVP_MD_type(M_EVP_MD_CTX_md(e)) +#define M_EVP_MD_CTX_md(e) ((e)->digest) + +#define M_EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs)) + +int EVP_MD_type(const EVP_MD *md); +#define EVP_MD_nid(e) EVP_MD_type(e) +#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) +int EVP_MD_pkey_type(const EVP_MD *md); +int EVP_MD_size(const EVP_MD *md); +int EVP_MD_block_size(const EVP_MD *md); + +const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx); +#define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) +#define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) +#define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) + +int EVP_CIPHER_nid(const EVP_CIPHER *cipher); +#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) +int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); +int EVP_CIPHER_key_length(const EVP_CIPHER *cipher); +int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher); +unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher); +#define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE) + +const EVP_CIPHER * EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); +void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); +void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); +#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) +unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx); +#define EVP_CIPHER_CTX_mode(e) (EVP_CIPHER_CTX_flags(e) & EVP_CIPH_MODE) + +#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) +#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) + +#define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +#define EVP_SignInit(a,b) EVP_DigestInit(a,b) +#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +#define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) +#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) +#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) + +#ifdef CONST_STRICT +void BIO_set_md(BIO *,const EVP_MD *md); +#else +# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) +#endif +#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) +#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) +#define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp) +#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) +#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) + +int EVP_Cipher(EVP_CIPHER_CTX *c, + unsigned char *out, + const unsigned char *in, + unsigned int inl); + +#define EVP_add_cipher_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) +#define EVP_add_digest_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) +#define EVP_delete_cipher_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); +#define EVP_delete_digest_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); + +void EVP_MD_CTX_init(EVP_MD_CTX *ctx); +int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); +EVP_MD_CTX *EVP_MD_CTX_create(void); +void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); +int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in); +void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); +void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); +int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx,int flags); +int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); +int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, + size_t cnt); +int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); +int EVP_Digest(const void *data, size_t count, + unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl); + +int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in); +int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); +int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); + +int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify); +void EVP_set_pw_prompt(const char *prompt); +char * EVP_get_pw_prompt(void); + +int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md, + const unsigned char *salt, const unsigned char *data, + int datal, int count, unsigned char *key,unsigned char *iv); + +void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags); +void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags); +int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx,int flags); + +int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, const unsigned char *iv); +int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); +int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, const unsigned char *iv); +int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); +int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); + +int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, + const unsigned char *key,const unsigned char *iv, + int enc); +int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key,const unsigned char *iv, + int enc); +int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); +int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); + +int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s, + EVP_PKEY *pkey); + +int EVP_VerifyFinal(EVP_MD_CTX *ctx,const unsigned char *sigbuf, + unsigned int siglen,EVP_PKEY *pkey); + +int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, + const unsigned char *ek, int ekl, const unsigned char *iv, + EVP_PKEY *priv); +int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, + unsigned char **ek, int *ekl, unsigned char *iv, + EVP_PKEY **pubk, int npubk); +int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl); + +void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); +void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, + const unsigned char *in,int inl); +void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); +int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); + +void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); +int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, + const unsigned char *in, int inl); +int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned + char *out, int *outl); +int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); + +void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); +int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); +EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); +void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a); +int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); +int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); +int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); +int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key); + +#ifndef OPENSSL_NO_BIO +BIO_METHOD *BIO_f_md(void); +BIO_METHOD *BIO_f_base64(void); +BIO_METHOD *BIO_f_cipher(void); +BIO_METHOD *BIO_f_reliable(void); +void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,const unsigned char *k, + const unsigned char *i, int enc); +#endif + +const EVP_MD *EVP_md_null(void); +#ifndef OPENSSL_NO_MD2 +const EVP_MD *EVP_md2(void); +#endif +#ifndef OPENSSL_NO_MD4 +const EVP_MD *EVP_md4(void); +#endif +#ifndef OPENSSL_NO_MD5 +const EVP_MD *EVP_md5(void); +#endif +#ifndef OPENSSL_NO_SHA +const EVP_MD *EVP_sha(void); +const EVP_MD *EVP_sha1(void); +const EVP_MD *EVP_dss(void); +const EVP_MD *EVP_dss1(void); +const EVP_MD *EVP_ecdsa(void); +#endif +#ifndef OPENSSL_NO_SHA256 +const EVP_MD *EVP_sha224(void); +const EVP_MD *EVP_sha256(void); +#endif +#ifndef OPENSSL_NO_SHA512 +const EVP_MD *EVP_sha384(void); +const EVP_MD *EVP_sha512(void); +#endif +#ifndef OPENSSL_NO_MDC2 +const EVP_MD *EVP_mdc2(void); +#endif +#ifndef OPENSSL_NO_RIPEMD +const EVP_MD *EVP_ripemd160(void); +#endif +const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ +#ifndef OPENSSL_NO_DES +const EVP_CIPHER *EVP_des_ecb(void); +const EVP_CIPHER *EVP_des_ede(void); +const EVP_CIPHER *EVP_des_ede3(void); +const EVP_CIPHER *EVP_des_ede_ecb(void); +const EVP_CIPHER *EVP_des_ede3_ecb(void); +const EVP_CIPHER *EVP_des_cfb64(void); +# define EVP_des_cfb EVP_des_cfb64 +const EVP_CIPHER *EVP_des_cfb1(void); +const EVP_CIPHER *EVP_des_cfb8(void); +const EVP_CIPHER *EVP_des_ede_cfb64(void); +# define EVP_des_ede_cfb EVP_des_ede_cfb64 +#if 0 +const EVP_CIPHER *EVP_des_ede_cfb1(void); +const EVP_CIPHER *EVP_des_ede_cfb8(void); +#endif +const EVP_CIPHER *EVP_des_ede3_cfb64(void); +# define EVP_des_ede3_cfb EVP_des_ede3_cfb64 +const EVP_CIPHER *EVP_des_ede3_cfb1(void); +const EVP_CIPHER *EVP_des_ede3_cfb8(void); +const EVP_CIPHER *EVP_des_ofb(void); +const EVP_CIPHER *EVP_des_ede_ofb(void); +const EVP_CIPHER *EVP_des_ede3_ofb(void); +const EVP_CIPHER *EVP_des_cbc(void); +const EVP_CIPHER *EVP_des_ede_cbc(void); +const EVP_CIPHER *EVP_des_ede3_cbc(void); +const EVP_CIPHER *EVP_desx_cbc(void); +/* This should now be supported through the dev_crypto ENGINE. But also, why are + * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */ +#if 0 +# ifdef OPENSSL_OPENBSD_DEV_CRYPTO +const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void); +const EVP_CIPHER *EVP_dev_crypto_rc4(void); +const EVP_MD *EVP_dev_crypto_md5(void); +# endif +#endif +#endif +#ifndef OPENSSL_NO_RC4 +const EVP_CIPHER *EVP_rc4(void); +const EVP_CIPHER *EVP_rc4_40(void); +#endif +#ifndef OPENSSL_NO_IDEA +const EVP_CIPHER *EVP_idea_ecb(void); +const EVP_CIPHER *EVP_idea_cfb64(void); +# define EVP_idea_cfb EVP_idea_cfb64 +const EVP_CIPHER *EVP_idea_ofb(void); +const EVP_CIPHER *EVP_idea_cbc(void); +#endif +#ifndef OPENSSL_NO_RC2 +const EVP_CIPHER *EVP_rc2_ecb(void); +const EVP_CIPHER *EVP_rc2_cbc(void); +const EVP_CIPHER *EVP_rc2_40_cbc(void); +const EVP_CIPHER *EVP_rc2_64_cbc(void); +const EVP_CIPHER *EVP_rc2_cfb64(void); +# define EVP_rc2_cfb EVP_rc2_cfb64 +const EVP_CIPHER *EVP_rc2_ofb(void); +#endif +#ifndef OPENSSL_NO_BF +const EVP_CIPHER *EVP_bf_ecb(void); +const EVP_CIPHER *EVP_bf_cbc(void); +const EVP_CIPHER *EVP_bf_cfb64(void); +# define EVP_bf_cfb EVP_bf_cfb64 +const EVP_CIPHER *EVP_bf_ofb(void); +#endif +#ifndef OPENSSL_NO_CAST +const EVP_CIPHER *EVP_cast5_ecb(void); +const EVP_CIPHER *EVP_cast5_cbc(void); +const EVP_CIPHER *EVP_cast5_cfb64(void); +# define EVP_cast5_cfb EVP_cast5_cfb64 +const EVP_CIPHER *EVP_cast5_ofb(void); +#endif +#ifndef OPENSSL_NO_RC5 +const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); +const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); +const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); +# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64 +const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); +#endif +#ifndef OPENSSL_NO_AES +const EVP_CIPHER *EVP_aes_128_ecb(void); +const EVP_CIPHER *EVP_aes_128_cbc(void); +const EVP_CIPHER *EVP_aes_128_cfb1(void); +const EVP_CIPHER *EVP_aes_128_cfb8(void); +const EVP_CIPHER *EVP_aes_128_cfb128(void); +# define EVP_aes_128_cfb EVP_aes_128_cfb128 +const EVP_CIPHER *EVP_aes_128_ofb(void); +#if 0 +const EVP_CIPHER *EVP_aes_128_ctr(void); +#endif +const EVP_CIPHER *EVP_aes_192_ecb(void); +const EVP_CIPHER *EVP_aes_192_cbc(void); +const EVP_CIPHER *EVP_aes_192_cfb1(void); +const EVP_CIPHER *EVP_aes_192_cfb8(void); +const EVP_CIPHER *EVP_aes_192_cfb128(void); +# define EVP_aes_192_cfb EVP_aes_192_cfb128 +const EVP_CIPHER *EVP_aes_192_ofb(void); +#if 0 +const EVP_CIPHER *EVP_aes_192_ctr(void); +#endif +const EVP_CIPHER *EVP_aes_256_ecb(void); +const EVP_CIPHER *EVP_aes_256_cbc(void); +const EVP_CIPHER *EVP_aes_256_cfb1(void); +const EVP_CIPHER *EVP_aes_256_cfb8(void); +const EVP_CIPHER *EVP_aes_256_cfb128(void); +# define EVP_aes_256_cfb EVP_aes_256_cfb128 +const EVP_CIPHER *EVP_aes_256_ofb(void); +#if 0 +const EVP_CIPHER *EVP_aes_256_ctr(void); +#endif +#endif +#ifndef OPENSSL_NO_CAMELLIA +const EVP_CIPHER *EVP_camellia_128_ecb(void); +const EVP_CIPHER *EVP_camellia_128_cbc(void); +const EVP_CIPHER *EVP_camellia_128_cfb1(void); +const EVP_CIPHER *EVP_camellia_128_cfb8(void); +const EVP_CIPHER *EVP_camellia_128_cfb128(void); +# define EVP_camellia_128_cfb EVP_camellia_128_cfb128 +const EVP_CIPHER *EVP_camellia_128_ofb(void); +const EVP_CIPHER *EVP_camellia_192_ecb(void); +const EVP_CIPHER *EVP_camellia_192_cbc(void); +const EVP_CIPHER *EVP_camellia_192_cfb1(void); +const EVP_CIPHER *EVP_camellia_192_cfb8(void); +const EVP_CIPHER *EVP_camellia_192_cfb128(void); +# define EVP_camellia_192_cfb EVP_camellia_192_cfb128 +const EVP_CIPHER *EVP_camellia_192_ofb(void); +const EVP_CIPHER *EVP_camellia_256_ecb(void); +const EVP_CIPHER *EVP_camellia_256_cbc(void); +const EVP_CIPHER *EVP_camellia_256_cfb1(void); +const EVP_CIPHER *EVP_camellia_256_cfb8(void); +const EVP_CIPHER *EVP_camellia_256_cfb128(void); +# define EVP_camellia_256_cfb EVP_camellia_256_cfb128 +const EVP_CIPHER *EVP_camellia_256_ofb(void); +#endif + +#ifndef OPENSSL_NO_SEED +const EVP_CIPHER *EVP_seed_ecb(void); +const EVP_CIPHER *EVP_seed_cbc(void); +const EVP_CIPHER *EVP_seed_cfb128(void); +# define EVP_seed_cfb EVP_seed_cfb128 +const EVP_CIPHER *EVP_seed_ofb(void); +#endif + +void OPENSSL_add_all_algorithms_noconf(void); +void OPENSSL_add_all_algorithms_conf(void); + +#ifdef OPENSSL_LOAD_CONF +#define OpenSSL_add_all_algorithms() \ + OPENSSL_add_all_algorithms_conf() +#else +#define OpenSSL_add_all_algorithms() \ + OPENSSL_add_all_algorithms_noconf() +#endif + +void OpenSSL_add_all_ciphers(void); +void OpenSSL_add_all_digests(void); +#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms() +#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers() +#define SSLeay_add_all_digests() OpenSSL_add_all_digests() + +int EVP_add_cipher(const EVP_CIPHER *cipher); +int EVP_add_digest(const EVP_MD *digest); + +const EVP_CIPHER *EVP_get_cipherbyname(const char *name); +const EVP_MD *EVP_get_digestbyname(const char *name); +void EVP_cleanup(void); + +int EVP_PKEY_decrypt(unsigned char *dec_key, + const unsigned char *enc_key,int enc_key_len, + EVP_PKEY *private_key); +int EVP_PKEY_encrypt(unsigned char *enc_key, + const unsigned char *key,int key_len, + EVP_PKEY *pub_key); +int EVP_PKEY_type(int type); +int EVP_PKEY_bits(EVP_PKEY *pkey); +int EVP_PKEY_size(EVP_PKEY *pkey); +int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key); + +#ifndef OPENSSL_NO_RSA +struct rsa_st; +int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key); +struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); +#endif +#ifndef OPENSSL_NO_DSA +struct dsa_st; +int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key); +struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); +#endif +#ifndef OPENSSL_NO_DH +struct dh_st; +int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key); +struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); +#endif +#ifndef OPENSSL_NO_EC +struct ec_key_st; +int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,struct ec_key_st *key); +struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); +#endif + +EVP_PKEY * EVP_PKEY_new(void); +void EVP_PKEY_free(EVP_PKEY *pkey); + +EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); + +EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, const unsigned char **pp, + long length); +EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); + +int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); +int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); +int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); +int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_CIPHER_type(const EVP_CIPHER *ctx); + +/* calls methods */ +int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +/* These are used by EVP_CIPHER methods */ +int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); +int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); + +/* PKCS5 password based encryption */ +int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, + int en_de); +int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, + const unsigned char *salt, int saltlen, int iter, + int keylen, unsigned char *out); +int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, + int en_de); + +void PKCS5_PBE_add(void); + +int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); +int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, + EVP_PBE_KEYGEN *keygen); +void EVP_PBE_cleanup(void); + +#ifdef OPENSSL_FIPS +#ifndef OPENSSL_NO_ENGINE +void int_EVP_MD_set_engine_callbacks( + int (*eng_md_init)(ENGINE *impl), + int (*eng_md_fin)(ENGINE *impl), + int (*eng_md_evp) + (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)); +void int_EVP_MD_init_engine_callbacks(void); +void int_EVP_CIPHER_set_engine_callbacks( + int (*eng_ciph_fin)(ENGINE *impl), + int (*eng_ciph_evp) + (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl)); +void int_EVP_CIPHER_init_engine_callbacks(void); +#endif +#endif + +void EVP_add_alg_module(void); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_EVP_strings(void); + +/* Error codes for the EVP functions. */ + +/* Function codes. */ +#define EVP_F_AES_INIT_KEY 133 +#define EVP_F_ALG_MODULE_INIT 138 +#define EVP_F_CAMELLIA_INIT_KEY 159 +#define EVP_F_D2I_PKEY 100 +#define EVP_F_DO_EVP_ENC_ENGINE 140 +#define EVP_F_DO_EVP_ENC_ENGINE_FULL 141 +#define EVP_F_DO_EVP_MD_ENGINE 139 +#define EVP_F_DO_EVP_MD_ENGINE_FULL 142 +#define EVP_F_DSAPKEY2PKCS8 134 +#define EVP_F_DSA_PKEY2PKCS8 135 +#define EVP_F_ECDSA_PKEY2PKCS8 129 +#define EVP_F_ECKEY_PKEY2PKCS8 132 +#define EVP_F_EVP_CIPHERINIT 137 +#define EVP_F_EVP_CIPHERINIT_EX 123 +#define EVP_F_EVP_CIPHER_CTX_CTRL 124 +#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 +#define EVP_F_EVP_DECRYPTFINAL_EX 101 +#define EVP_F_EVP_DIGESTINIT 136 +#define EVP_F_EVP_DIGESTINIT_EX 128 +#define EVP_F_EVP_ENCRYPTFINAL_EX 127 +#define EVP_F_EVP_MD_CTX_COPY_EX 110 +#define EVP_F_EVP_OPENINIT 102 +#define EVP_F_EVP_PBE_ALG_ADD 115 +#define EVP_F_EVP_PBE_CIPHERINIT 116 +#define EVP_F_EVP_PKCS82PKEY 111 +#define EVP_F_EVP_PKEY2PKCS8_BROKEN 113 +#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 +#define EVP_F_EVP_PKEY_DECRYPT 104 +#define EVP_F_EVP_PKEY_ENCRYPT 105 +#define EVP_F_EVP_PKEY_GET1_DH 119 +#define EVP_F_EVP_PKEY_GET1_DSA 120 +#define EVP_F_EVP_PKEY_GET1_ECDSA 130 +#define EVP_F_EVP_PKEY_GET1_EC_KEY 131 +#define EVP_F_EVP_PKEY_GET1_RSA 121 +#define EVP_F_EVP_PKEY_NEW 106 +#define EVP_F_EVP_RIJNDAEL 126 +#define EVP_F_EVP_SIGNFINAL 107 +#define EVP_F_EVP_VERIFYFINAL 108 +#define EVP_F_PKCS5_PBE_KEYIVGEN 117 +#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 +#define EVP_F_PKCS8_SET_BROKEN 112 +#define EVP_F_RC2_MAGIC_TO_METH 109 +#define EVP_F_RC5_CTRL 125 + +/* Reason codes. */ +#define EVP_R_AES_KEY_SETUP_FAILED 143 +#define EVP_R_ASN1_LIB 140 +#define EVP_R_BAD_BLOCK_LENGTH 136 +#define EVP_R_BAD_DECRYPT 100 +#define EVP_R_BAD_KEY_LENGTH 137 +#define EVP_R_BN_DECODE_ERROR 112 +#define EVP_R_BN_PUBKEY_ERROR 113 +#define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157 +#define EVP_R_CIPHER_PARAMETER_ERROR 122 +#define EVP_R_CTRL_NOT_IMPLEMENTED 132 +#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 +#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138 +#define EVP_R_DECODE_ERROR 114 +#define EVP_R_DIFFERENT_KEY_TYPES 101 +#define EVP_R_DISABLED_FOR_FIPS 144 +#define EVP_R_ENCODE_ERROR 115 +#define EVP_R_ERROR_LOADING_SECTION 145 +#define EVP_R_ERROR_SETTING_FIPS_MODE 146 +#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 +#define EVP_R_EXPECTING_AN_RSA_KEY 127 +#define EVP_R_EXPECTING_A_DH_KEY 128 +#define EVP_R_EXPECTING_A_DSA_KEY 129 +#define EVP_R_EXPECTING_A_ECDSA_KEY 141 +#define EVP_R_EXPECTING_A_EC_KEY 142 +#define EVP_R_FIPS_MODE_NOT_SUPPORTED 147 +#define EVP_R_INITIALIZATION_ERROR 134 +#define EVP_R_INPUT_NOT_INITIALIZED 111 +#define EVP_R_INVALID_FIPS_MODE 148 +#define EVP_R_INVALID_KEY_LENGTH 130 +#define EVP_R_IV_TOO_LARGE 102 +#define EVP_R_KEYGEN_FAILURE 120 +#define EVP_R_MISSING_PARAMETERS 103 +#define EVP_R_NO_CIPHER_SET 131 +#define EVP_R_NO_DIGEST_SET 139 +#define EVP_R_NO_DSA_PARAMETERS 116 +#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 +#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 +#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117 +#define EVP_R_PUBLIC_KEY_NOT_RSA 106 +#define EVP_R_UNKNOWN_OPTION 149 +#define EVP_R_UNKNOWN_PBE_ALGORITHM 121 +#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135 +#define EVP_R_UNSUPPORTED_CIPHER 107 +#define EVP_R_UNSUPPORTED_KEYLENGTH 123 +#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 +#define EVP_R_UNSUPPORTED_KEY_SIZE 108 +#define EVP_R_UNSUPPORTED_PRF 125 +#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 +#define EVP_R_UNSUPPORTED_SALT_TYPE 126 +#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 +#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 +#define EVP_R_SEED_KEY_SETUP_FAILED 162 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/hmac.h b/石器时代8.5客户端最新源代码/石器源码/openssl/hmac.h new file mode 100644 index 0000000..fc38ffb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/hmac.h @@ -0,0 +1,109 @@ +/* crypto/hmac/hmac.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +#ifndef HEADER_HMAC_H +#define HEADER_HMAC_H + +#include + +#ifdef OPENSSL_NO_HMAC +#error HMAC is disabled. +#endif + +#include + +#define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct hmac_ctx_st + { + const EVP_MD *md; + EVP_MD_CTX md_ctx; + EVP_MD_CTX i_ctx; + EVP_MD_CTX o_ctx; + unsigned int key_length; + unsigned char key[HMAC_MAX_MD_CBLOCK]; + } HMAC_CTX; + +#define HMAC_size(e) (EVP_MD_size((e)->md)) + + +void HMAC_CTX_init(HMAC_CTX *ctx); +void HMAC_CTX_cleanup(HMAC_CTX *ctx); + +#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ + +void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md); /* deprecated */ +void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md, ENGINE *impl); +void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); +void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); +unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, + const unsigned char *d, size_t n, unsigned char *md, + unsigned int *md_len); + +void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/idea.h b/石器时代8.5客户端最新源代码/石器源码/openssl/idea.h new file mode 100644 index 0000000..a137d4c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/idea.h @@ -0,0 +1,103 @@ +/* crypto/idea/idea.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_IDEA_H +#define HEADER_IDEA_H + +#include /* IDEA_INT, OPENSSL_NO_IDEA */ + +#ifdef OPENSSL_NO_IDEA +#error IDEA is disabled. +#endif + +#define IDEA_ENCRYPT 1 +#define IDEA_DECRYPT 0 + +#define IDEA_BLOCK 8 +#define IDEA_KEY_LENGTH 16 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct idea_key_st + { + IDEA_INT data[9][6]; + } IDEA_KEY_SCHEDULE; + +const char *idea_options(void); +void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, + IDEA_KEY_SCHEDULE *ks); +#ifdef OPENSSL_FIPS +void private_idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); +#endif +void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); +void idea_set_decrypt_key(const IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); +void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); +void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num,int enc); +void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num); +void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/krb5_asn.h b/石器时代8.5客户端最新源代码/石器源码/openssl/krb5_asn.h new file mode 100644 index 0000000..41725d0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/krb5_asn.h @@ -0,0 +1,256 @@ +/* krb5_asn.h */ +/* Written by Vern Staats for the OpenSSL project, +** using ocsp/{*.h,*asn*.c} as a starting point +*/ + +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_KRB5_ASN_H +#define HEADER_KRB5_ASN_H + +/* +#include +*/ +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ASN.1 from Kerberos RFC 1510 +*/ + +/* EncryptedData ::= SEQUENCE { +** etype[0] INTEGER, -- EncryptionType +** kvno[1] INTEGER OPTIONAL, +** cipher[2] OCTET STRING -- ciphertext +** } +*/ +typedef struct krb5_encdata_st + { + ASN1_INTEGER *etype; + ASN1_INTEGER *kvno; + ASN1_OCTET_STRING *cipher; + } KRB5_ENCDATA; + +DECLARE_STACK_OF(KRB5_ENCDATA) + +/* PrincipalName ::= SEQUENCE { +** name-type[0] INTEGER, +** name-string[1] SEQUENCE OF GeneralString +** } +*/ +typedef struct krb5_princname_st + { + ASN1_INTEGER *nametype; + STACK_OF(ASN1_GENERALSTRING) *namestring; + } KRB5_PRINCNAME; + +DECLARE_STACK_OF(KRB5_PRINCNAME) + + +/* Ticket ::= [APPLICATION 1] SEQUENCE { +** tkt-vno[0] INTEGER, +** realm[1] Realm, +** sname[2] PrincipalName, +** enc-part[3] EncryptedData +** } +*/ +typedef struct krb5_tktbody_st + { + ASN1_INTEGER *tktvno; + ASN1_GENERALSTRING *realm; + KRB5_PRINCNAME *sname; + KRB5_ENCDATA *encdata; + } KRB5_TKTBODY; + +typedef STACK_OF(KRB5_TKTBODY) KRB5_TICKET; +DECLARE_STACK_OF(KRB5_TKTBODY) + + +/* AP-REQ ::= [APPLICATION 14] SEQUENCE { +** pvno[0] INTEGER, +** msg-type[1] INTEGER, +** ap-options[2] APOptions, +** ticket[3] Ticket, +** authenticator[4] EncryptedData +** } +** +** APOptions ::= BIT STRING { +** reserved(0), use-session-key(1), mutual-required(2) } +*/ +typedef struct krb5_ap_req_st + { + ASN1_INTEGER *pvno; + ASN1_INTEGER *msgtype; + ASN1_BIT_STRING *apoptions; + KRB5_TICKET *ticket; + KRB5_ENCDATA *authenticator; + } KRB5_APREQBODY; + +typedef STACK_OF(KRB5_APREQBODY) KRB5_APREQ; +DECLARE_STACK_OF(KRB5_APREQBODY) + + +/* Authenticator Stuff */ + + +/* Checksum ::= SEQUENCE { +** cksumtype[0] INTEGER, +** checksum[1] OCTET STRING +** } +*/ +typedef struct krb5_checksum_st + { + ASN1_INTEGER *ctype; + ASN1_OCTET_STRING *checksum; + } KRB5_CHECKSUM; + +DECLARE_STACK_OF(KRB5_CHECKSUM) + + +/* EncryptionKey ::= SEQUENCE { +** keytype[0] INTEGER, +** keyvalue[1] OCTET STRING +** } +*/ +typedef struct krb5_encryptionkey_st + { + ASN1_INTEGER *ktype; + ASN1_OCTET_STRING *keyvalue; + } KRB5_ENCKEY; + +DECLARE_STACK_OF(KRB5_ENCKEY) + + +/* AuthorizationData ::= SEQUENCE OF SEQUENCE { +** ad-type[0] INTEGER, +** ad-data[1] OCTET STRING +** } +*/ +typedef struct krb5_authorization_st + { + ASN1_INTEGER *adtype; + ASN1_OCTET_STRING *addata; + } KRB5_AUTHDATA; + +DECLARE_STACK_OF(KRB5_AUTHDATA) + + +/* -- Unencrypted authenticator +** Authenticator ::= [APPLICATION 2] SEQUENCE { +** authenticator-vno[0] INTEGER, +** crealm[1] Realm, +** cname[2] PrincipalName, +** cksum[3] Checksum OPTIONAL, +** cusec[4] INTEGER, +** ctime[5] KerberosTime, +** subkey[6] EncryptionKey OPTIONAL, +** seq-number[7] INTEGER OPTIONAL, +** authorization-data[8] AuthorizationData OPTIONAL +** } +*/ +typedef struct krb5_authenticator_st + { + ASN1_INTEGER *avno; + ASN1_GENERALSTRING *crealm; + KRB5_PRINCNAME *cname; + KRB5_CHECKSUM *cksum; + ASN1_INTEGER *cusec; + ASN1_GENERALIZEDTIME *ctime; + KRB5_ENCKEY *subkey; + ASN1_INTEGER *seqnum; + KRB5_AUTHDATA *authorization; + } KRB5_AUTHENTBODY; + +typedef STACK_OF(KRB5_AUTHENTBODY) KRB5_AUTHENT; +DECLARE_STACK_OF(KRB5_AUTHENTBODY) + + +/* DECLARE_ASN1_FUNCTIONS(type) = DECLARE_ASN1_FUNCTIONS_name(type, type) = +** type *name##_new(void); +** void name##_free(type *a); +** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) = +** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) = +** type *d2i_##name(type **a, const unsigned char **in, long len); +** int i2d_##name(type *a, unsigned char **out); +** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it +*/ + +DECLARE_ASN1_FUNCTIONS(KRB5_ENCDATA) +DECLARE_ASN1_FUNCTIONS(KRB5_PRINCNAME) +DECLARE_ASN1_FUNCTIONS(KRB5_TKTBODY) +DECLARE_ASN1_FUNCTIONS(KRB5_APREQBODY) +DECLARE_ASN1_FUNCTIONS(KRB5_TICKET) +DECLARE_ASN1_FUNCTIONS(KRB5_APREQ) + +DECLARE_ASN1_FUNCTIONS(KRB5_CHECKSUM) +DECLARE_ASN1_FUNCTIONS(KRB5_ENCKEY) +DECLARE_ASN1_FUNCTIONS(KRB5_AUTHDATA) +DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENTBODY) +DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENT) + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/kssl.h b/石器时代8.5客户端最新源代码/石器源码/openssl/kssl.h new file mode 100644 index 0000000..a3d20e1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/kssl.h @@ -0,0 +1,179 @@ +/* ssl/kssl.h -*- mode: C; c-file-style: "eay" -*- */ +/* Written by Vern Staats for the OpenSSL project 2000. + * project 2000. + */ +/* ==================================================================== + * Copyright (c) 2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* +** 19990701 VRS Started. +*/ + +#ifndef KSSL_H +#define KSSL_H + +#include + +#ifndef OPENSSL_NO_KRB5 + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Depending on which KRB5 implementation used, some types from +** the other may be missing. Resolve that here and now +*/ +#ifdef KRB5_HEIMDAL +typedef unsigned char krb5_octet; +#define FAR +#else + +#ifndef FAR +#define FAR +#endif + +#endif + +/* Uncomment this to debug kssl problems or +** to trace usage of the Kerberos session key +** +** #define KSSL_DEBUG +*/ + +#ifndef KRB5SVC +#define KRB5SVC "host" +#endif + +#ifndef KRB5KEYTAB +#define KRB5KEYTAB "/etc/krb5.keytab" +#endif + +#ifndef KRB5SENDAUTH +#define KRB5SENDAUTH 1 +#endif + +#ifndef KRB5CHECKAUTH +#define KRB5CHECKAUTH 1 +#endif + +#ifndef KSSL_CLOCKSKEW +#define KSSL_CLOCKSKEW 300; +#endif + +#define KSSL_ERR_MAX 255 +typedef struct kssl_err_st { + int reason; + char text[KSSL_ERR_MAX+1]; + } KSSL_ERR; + + +/* Context for passing +** (1) Kerberos session key to SSL, and +** (2) Config data between application and SSL lib +*/ +typedef struct kssl_ctx_st + { + /* used by: disposition: */ + char *service_name; /* C,S default ok (kssl) */ + char *service_host; /* C input, REQUIRED */ + char *client_princ; /* S output from krb5 ticket */ + char *keytab_file; /* S NULL (/etc/krb5.keytab) */ + char *cred_cache; /* C NULL (default) */ + krb5_enctype enctype; + int length; + krb5_octet FAR *key; + } KSSL_CTX; + +#define KSSL_CLIENT 1 +#define KSSL_SERVER 2 +#define KSSL_SERVICE 3 +#define KSSL_KEYTAB 4 + +#define KSSL_CTX_OK 0 +#define KSSL_CTX_ERR 1 +#define KSSL_NOMEM 2 + +/* Public (for use by applications that use OpenSSL with Kerberos 5 support */ +krb5_error_code kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text); +KSSL_CTX *kssl_ctx_new(void); +KSSL_CTX *kssl_ctx_free(KSSL_CTX *kssl_ctx); +void kssl_ctx_show(KSSL_CTX *kssl_ctx); +krb5_error_code kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which, + krb5_data *realm, krb5_data *entity, int nentities); +krb5_error_code kssl_cget_tkt(KSSL_CTX *kssl_ctx, krb5_data **enc_tktp, + krb5_data *authenp, KSSL_ERR *kssl_err); +krb5_error_code kssl_sget_tkt(KSSL_CTX *kssl_ctx, krb5_data *indata, + krb5_ticket_times *ttimes, KSSL_ERR *kssl_err); +krb5_error_code kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session); +void kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text); +void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data); +krb5_error_code kssl_build_principal_2(krb5_context context, + krb5_principal *princ, int rlen, const char *realm, + int slen, const char *svc, int hlen, const char *host); +krb5_error_code kssl_validate_times(krb5_timestamp atime, + krb5_ticket_times *ttimes); +krb5_error_code kssl_check_authent(KSSL_CTX *kssl_ctx, krb5_data *authentp, + krb5_timestamp *atimep, KSSL_ERR *kssl_err); +unsigned char *kssl_skip_confound(krb5_enctype enctype, unsigned char *authn); + +#ifdef __cplusplus +} +#endif +#endif /* OPENSSL_NO_KRB5 */ +#endif /* KSSL_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/lhash.h b/石器时代8.5客户端最新源代码/石器源码/openssl/lhash.h new file mode 100644 index 0000000..d392d0c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/lhash.h @@ -0,0 +1,200 @@ +/* crypto/lhash/lhash.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* Header for dynamic hash table routines + * Author - Eric Young + */ + +#ifndef HEADER_LHASH_H +#define HEADER_LHASH_H + +#include +#ifndef OPENSSL_NO_FP_API +#include +#endif + +#ifndef OPENSSL_NO_BIO +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct lhash_node_st + { + void *data; + struct lhash_node_st *next; +#ifndef OPENSSL_NO_HASH_COMP + unsigned long hash; +#endif + } LHASH_NODE; + +typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); +typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); +typedef void (*LHASH_DOALL_FN_TYPE)(void *); +typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *); + +/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks. + * This way, callbacks can be provided to LHASH structures without function + * pointer casting and the macro-defined callbacks provide per-variable casting + * before deferring to the underlying type-specific callbacks. NB: It is + * possible to place a "static" in front of both the DECLARE and IMPLEMENT + * macros if the functions are strictly internal. */ + +/* First: "hash" functions */ +#define DECLARE_LHASH_HASH_FN(f_name,o_type) \ + unsigned long f_name##_LHASH_HASH(const void *); +#define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \ + unsigned long f_name##_LHASH_HASH(const void *arg) { \ + o_type a = (o_type)arg; \ + return f_name(a); } +#define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH + +/* Second: "compare" functions */ +#define DECLARE_LHASH_COMP_FN(f_name,o_type) \ + int f_name##_LHASH_COMP(const void *, const void *); +#define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \ + int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \ + o_type a = (o_type)arg1; \ + o_type b = (o_type)arg2; \ + return f_name(a,b); } +#define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP + +/* Third: "doall" functions */ +#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \ + void f_name##_LHASH_DOALL(void *); +#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \ + void f_name##_LHASH_DOALL(void *arg) { \ + o_type a = (o_type)arg; \ + f_name(a); } +#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL + +/* Fourth: "doall_arg" functions */ +#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ + void f_name##_LHASH_DOALL_ARG(void *, void *); +#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ + void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ + o_type a = (o_type)arg1; \ + a_type b = (a_type)arg2; \ + f_name(a,b); } +#define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG + +typedef struct lhash_st + { + LHASH_NODE **b; + LHASH_COMP_FN_TYPE comp; + LHASH_HASH_FN_TYPE hash; + unsigned int num_nodes; + unsigned int num_alloc_nodes; + unsigned int p; + unsigned int pmax; + unsigned long up_load; /* load times 256 */ + unsigned long down_load; /* load times 256 */ + unsigned long num_items; + + unsigned long num_expands; + unsigned long num_expand_reallocs; + unsigned long num_contracts; + unsigned long num_contract_reallocs; + unsigned long num_hash_calls; + unsigned long num_comp_calls; + unsigned long num_insert; + unsigned long num_replace; + unsigned long num_delete; + unsigned long num_no_delete; + unsigned long num_retrieve; + unsigned long num_retrieve_miss; + unsigned long num_hash_comps; + + int error; + } LHASH; + +#define LH_LOAD_MULT 256 + +/* Indicates a malloc() error in the last call, this is only bad + * in lh_insert(). */ +#define lh_error(lh) ((lh)->error) + +LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c); +void lh_free(LHASH *lh); +void *lh_insert(LHASH *lh, void *data); +void *lh_delete(LHASH *lh, const void *data); +void *lh_retrieve(LHASH *lh, const void *data); +void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func); +void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg); +unsigned long lh_strhash(const char *c); +unsigned long lh_num_items(const LHASH *lh); + +#ifndef OPENSSL_NO_FP_API +void lh_stats(const LHASH *lh, FILE *out); +void lh_node_stats(const LHASH *lh, FILE *out); +void lh_node_usage_stats(const LHASH *lh, FILE *out); +#endif + +#ifndef OPENSSL_NO_BIO +void lh_stats_bio(const LHASH *lh, BIO *out); +void lh_node_stats_bio(const LHASH *lh, BIO *out); +void lh_node_usage_stats_bio(const LHASH *lh, BIO *out); +#endif +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/md2.h b/石器时代8.5客户端最新源代码/石器源码/openssl/md2.h new file mode 100644 index 0000000..d59c9f2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/md2.h @@ -0,0 +1,95 @@ +/* crypto/md/md2.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_MD2_H +#define HEADER_MD2_H + +#include /* OPENSSL_NO_MD2, MD2_INT */ +#ifdef OPENSSL_NO_MD2 +#error MD2 is disabled. +#endif +#include + +#define MD2_DIGEST_LENGTH 16 +#define MD2_BLOCK 16 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct MD2state_st + { + unsigned int num; + unsigned char data[MD2_BLOCK]; + MD2_INT cksm[MD2_BLOCK]; + MD2_INT state[MD2_BLOCK]; + } MD2_CTX; + +const char *MD2_options(void); +#ifdef OPENSSL_FIPS +int private_MD2_Init(MD2_CTX *c); +#endif +int MD2_Init(MD2_CTX *c); +int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len); +int MD2_Final(unsigned char *md, MD2_CTX *c); +unsigned char *MD2(const unsigned char *d, size_t n,unsigned char *md); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/md4.h b/石器时代8.5客户端最新源代码/石器源码/openssl/md4.h new file mode 100644 index 0000000..ba1fe4a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/md4.h @@ -0,0 +1,120 @@ +/* crypto/md4/md4.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_MD4_H +#define HEADER_MD4_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_NO_MD4 +#error MD4 is disabled. +#endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! MD4_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) +#define MD4_LONG unsigned long +#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) +#define MD4_LONG unsigned long +#define MD4_LONG_LOG2 3 +/* + * _CRAY note. I could declare short, but I have no idea what impact + * does it have on performance on none-T3E machines. I could declare + * int, but at least on C90 sizeof(int) can be chosen at compile time. + * So I've chosen long... + * + */ +#else +#define MD4_LONG unsigned int +#endif + +#define MD4_CBLOCK 64 +#define MD4_LBLOCK (MD4_CBLOCK/4) +#define MD4_DIGEST_LENGTH 16 + +typedef struct MD4state_st + { + MD4_LONG A,B,C,D; + MD4_LONG Nl,Nh; + MD4_LONG data[MD4_LBLOCK]; + unsigned int num; + } MD4_CTX; + +#ifdef OPENSSL_FIPS +int private_MD4_Init(MD4_CTX *c); +#endif +int MD4_Init(MD4_CTX *c); +int MD4_Update(MD4_CTX *c, const void *data, size_t len); +int MD4_Final(unsigned char *md, MD4_CTX *c); +unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); +void MD4_Transform(MD4_CTX *c, const unsigned char *b); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/md5.h b/石器时代8.5客户端最新源代码/石器源码/openssl/md5.h new file mode 100644 index 0000000..612dc1c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/md5.h @@ -0,0 +1,120 @@ +/* crypto/md5/md5.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_MD5_H +#define HEADER_MD5_H + +#include"../openssl/md5.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_NO_MD5 +#error MD5 is disabled. +#endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! MD5_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) +#define MD5_LONG unsigned long +#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) +#define MD5_LONG unsigned long +#define MD5_LONG_LOG2 3 +/* + * _CRAY note. I could declare short, but I have no idea what impact + * does it have on performance on none-T3E machines. I could declare + * int, but at least on C90 sizeof(int) can be chosen at compile time. + * So I've chosen long... + * + */ +#else +#define MD5_LONG unsigned int +#endif + +#define MD5_CBLOCK 64 +#define MD5_LBLOCK (MD5_CBLOCK/4) +#define MD5_DIGEST_LENGTH 16 + +typedef struct MD5state_st + { + MD5_LONG A,B,C,D; + MD5_LONG Nl,Nh; + MD5_LONG data[MD5_LBLOCK]; + unsigned int num; + } MD5_CTX; + +#ifdef OPENSSL_FIPS +int private_MD5_Init(MD5_CTX *c); +#endif +int MD5_Init(MD5_CTX *c); +int MD5_Update(MD5_CTX *c, const void *data, size_t len); +int MD5_Final(unsigned char *md, MD5_CTX *c); +unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); +void MD5_Transform(MD5_CTX *c, const unsigned char *b); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/obj_mac.h b/石器时代8.5客户端最新源代码/石器源码/openssl/obj_mac.h new file mode 100644 index 0000000..ad5f7cf --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/obj_mac.h @@ -0,0 +1,3775 @@ +/* crypto/objects/obj_mac.h */ + +/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the + * following command: + * perl objects.pl objects.txt obj_mac.num obj_mac.h + */ + +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#define SN_undef "UNDEF" +#define LN_undef "undefined" +#define NID_undef 0 +#define OBJ_undef 0L + +#define SN_itu_t "ITU-T" +#define LN_itu_t "itu-t" +#define NID_itu_t 645 +#define OBJ_itu_t 0L + +#define NID_ccitt 404 +#define OBJ_ccitt OBJ_itu_t + +#define SN_iso "ISO" +#define LN_iso "iso" +#define NID_iso 181 +#define OBJ_iso 1L + +#define SN_joint_iso_itu_t "JOINT-ISO-ITU-T" +#define LN_joint_iso_itu_t "joint-iso-itu-t" +#define NID_joint_iso_itu_t 646 +#define OBJ_joint_iso_itu_t 2L + +#define NID_joint_iso_ccitt 393 +#define OBJ_joint_iso_ccitt OBJ_joint_iso_itu_t + +#define SN_member_body "member-body" +#define LN_member_body "ISO Member Body" +#define NID_member_body 182 +#define OBJ_member_body OBJ_iso,2L + +#define SN_identified_organization "identified-organization" +#define NID_identified_organization 676 +#define OBJ_identified_organization OBJ_iso,3L + +#define SN_hmac_md5 "HMAC-MD5" +#define LN_hmac_md5 "hmac-md5" +#define NID_hmac_md5 780 +#define OBJ_hmac_md5 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,1L + +#define SN_hmac_sha1 "HMAC-SHA1" +#define LN_hmac_sha1 "hmac-sha1" +#define NID_hmac_sha1 781 +#define OBJ_hmac_sha1 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,2L + +#define SN_certicom_arc "certicom-arc" +#define NID_certicom_arc 677 +#define OBJ_certicom_arc OBJ_identified_organization,132L + +#define SN_international_organizations "international-organizations" +#define LN_international_organizations "International Organizations" +#define NID_international_organizations 647 +#define OBJ_international_organizations OBJ_joint_iso_itu_t,23L + +#define SN_wap "wap" +#define NID_wap 678 +#define OBJ_wap OBJ_international_organizations,43L + +#define SN_wap_wsg "wap-wsg" +#define NID_wap_wsg 679 +#define OBJ_wap_wsg OBJ_wap,13L + +#define SN_selected_attribute_types "selected-attribute-types" +#define LN_selected_attribute_types "Selected Attribute Types" +#define NID_selected_attribute_types 394 +#define OBJ_selected_attribute_types OBJ_joint_iso_itu_t,5L,1L,5L + +#define SN_clearance "clearance" +#define NID_clearance 395 +#define OBJ_clearance OBJ_selected_attribute_types,55L + +#define SN_ISO_US "ISO-US" +#define LN_ISO_US "ISO US Member Body" +#define NID_ISO_US 183 +#define OBJ_ISO_US OBJ_member_body,840L + +#define SN_X9_57 "X9-57" +#define LN_X9_57 "X9.57" +#define NID_X9_57 184 +#define OBJ_X9_57 OBJ_ISO_US,10040L + +#define SN_X9cm "X9cm" +#define LN_X9cm "X9.57 CM ?" +#define NID_X9cm 185 +#define OBJ_X9cm OBJ_X9_57,4L + +#define SN_dsa "DSA" +#define LN_dsa "dsaEncryption" +#define NID_dsa 116 +#define OBJ_dsa OBJ_X9cm,1L + +#define SN_dsaWithSHA1 "DSA-SHA1" +#define LN_dsaWithSHA1 "dsaWithSHA1" +#define NID_dsaWithSHA1 113 +#define OBJ_dsaWithSHA1 OBJ_X9cm,3L + +#define SN_ansi_X9_62 "ansi-X9-62" +#define LN_ansi_X9_62 "ANSI X9.62" +#define NID_ansi_X9_62 405 +#define OBJ_ansi_X9_62 OBJ_ISO_US,10045L + +#define OBJ_X9_62_id_fieldType OBJ_ansi_X9_62,1L + +#define SN_X9_62_prime_field "prime-field" +#define NID_X9_62_prime_field 406 +#define OBJ_X9_62_prime_field OBJ_X9_62_id_fieldType,1L + +#define SN_X9_62_characteristic_two_field "characteristic-two-field" +#define NID_X9_62_characteristic_two_field 407 +#define OBJ_X9_62_characteristic_two_field OBJ_X9_62_id_fieldType,2L + +#define SN_X9_62_id_characteristic_two_basis "id-characteristic-two-basis" +#define NID_X9_62_id_characteristic_two_basis 680 +#define OBJ_X9_62_id_characteristic_two_basis OBJ_X9_62_characteristic_two_field,3L + +#define SN_X9_62_onBasis "onBasis" +#define NID_X9_62_onBasis 681 +#define OBJ_X9_62_onBasis OBJ_X9_62_id_characteristic_two_basis,1L + +#define SN_X9_62_tpBasis "tpBasis" +#define NID_X9_62_tpBasis 682 +#define OBJ_X9_62_tpBasis OBJ_X9_62_id_characteristic_two_basis,2L + +#define SN_X9_62_ppBasis "ppBasis" +#define NID_X9_62_ppBasis 683 +#define OBJ_X9_62_ppBasis OBJ_X9_62_id_characteristic_two_basis,3L + +#define OBJ_X9_62_id_publicKeyType OBJ_ansi_X9_62,2L + +#define SN_X9_62_id_ecPublicKey "id-ecPublicKey" +#define NID_X9_62_id_ecPublicKey 408 +#define OBJ_X9_62_id_ecPublicKey OBJ_X9_62_id_publicKeyType,1L + +#define OBJ_X9_62_ellipticCurve OBJ_ansi_X9_62,3L + +#define OBJ_X9_62_c_TwoCurve OBJ_X9_62_ellipticCurve,0L + +#define SN_X9_62_c2pnb163v1 "c2pnb163v1" +#define NID_X9_62_c2pnb163v1 684 +#define OBJ_X9_62_c2pnb163v1 OBJ_X9_62_c_TwoCurve,1L + +#define SN_X9_62_c2pnb163v2 "c2pnb163v2" +#define NID_X9_62_c2pnb163v2 685 +#define OBJ_X9_62_c2pnb163v2 OBJ_X9_62_c_TwoCurve,2L + +#define SN_X9_62_c2pnb163v3 "c2pnb163v3" +#define NID_X9_62_c2pnb163v3 686 +#define OBJ_X9_62_c2pnb163v3 OBJ_X9_62_c_TwoCurve,3L + +#define SN_X9_62_c2pnb176v1 "c2pnb176v1" +#define NID_X9_62_c2pnb176v1 687 +#define OBJ_X9_62_c2pnb176v1 OBJ_X9_62_c_TwoCurve,4L + +#define SN_X9_62_c2tnb191v1 "c2tnb191v1" +#define NID_X9_62_c2tnb191v1 688 +#define OBJ_X9_62_c2tnb191v1 OBJ_X9_62_c_TwoCurve,5L + +#define SN_X9_62_c2tnb191v2 "c2tnb191v2" +#define NID_X9_62_c2tnb191v2 689 +#define OBJ_X9_62_c2tnb191v2 OBJ_X9_62_c_TwoCurve,6L + +#define SN_X9_62_c2tnb191v3 "c2tnb191v3" +#define NID_X9_62_c2tnb191v3 690 +#define OBJ_X9_62_c2tnb191v3 OBJ_X9_62_c_TwoCurve,7L + +#define SN_X9_62_c2onb191v4 "c2onb191v4" +#define NID_X9_62_c2onb191v4 691 +#define OBJ_X9_62_c2onb191v4 OBJ_X9_62_c_TwoCurve,8L + +#define SN_X9_62_c2onb191v5 "c2onb191v5" +#define NID_X9_62_c2onb191v5 692 +#define OBJ_X9_62_c2onb191v5 OBJ_X9_62_c_TwoCurve,9L + +#define SN_X9_62_c2pnb208w1 "c2pnb208w1" +#define NID_X9_62_c2pnb208w1 693 +#define OBJ_X9_62_c2pnb208w1 OBJ_X9_62_c_TwoCurve,10L + +#define SN_X9_62_c2tnb239v1 "c2tnb239v1" +#define NID_X9_62_c2tnb239v1 694 +#define OBJ_X9_62_c2tnb239v1 OBJ_X9_62_c_TwoCurve,11L + +#define SN_X9_62_c2tnb239v2 "c2tnb239v2" +#define NID_X9_62_c2tnb239v2 695 +#define OBJ_X9_62_c2tnb239v2 OBJ_X9_62_c_TwoCurve,12L + +#define SN_X9_62_c2tnb239v3 "c2tnb239v3" +#define NID_X9_62_c2tnb239v3 696 +#define OBJ_X9_62_c2tnb239v3 OBJ_X9_62_c_TwoCurve,13L + +#define SN_X9_62_c2onb239v4 "c2onb239v4" +#define NID_X9_62_c2onb239v4 697 +#define OBJ_X9_62_c2onb239v4 OBJ_X9_62_c_TwoCurve,14L + +#define SN_X9_62_c2onb239v5 "c2onb239v5" +#define NID_X9_62_c2onb239v5 698 +#define OBJ_X9_62_c2onb239v5 OBJ_X9_62_c_TwoCurve,15L + +#define SN_X9_62_c2pnb272w1 "c2pnb272w1" +#define NID_X9_62_c2pnb272w1 699 +#define OBJ_X9_62_c2pnb272w1 OBJ_X9_62_c_TwoCurve,16L + +#define SN_X9_62_c2pnb304w1 "c2pnb304w1" +#define NID_X9_62_c2pnb304w1 700 +#define OBJ_X9_62_c2pnb304w1 OBJ_X9_62_c_TwoCurve,17L + +#define SN_X9_62_c2tnb359v1 "c2tnb359v1" +#define NID_X9_62_c2tnb359v1 701 +#define OBJ_X9_62_c2tnb359v1 OBJ_X9_62_c_TwoCurve,18L + +#define SN_X9_62_c2pnb368w1 "c2pnb368w1" +#define NID_X9_62_c2pnb368w1 702 +#define OBJ_X9_62_c2pnb368w1 OBJ_X9_62_c_TwoCurve,19L + +#define SN_X9_62_c2tnb431r1 "c2tnb431r1" +#define NID_X9_62_c2tnb431r1 703 +#define OBJ_X9_62_c2tnb431r1 OBJ_X9_62_c_TwoCurve,20L + +#define OBJ_X9_62_primeCurve OBJ_X9_62_ellipticCurve,1L + +#define SN_X9_62_prime192v1 "prime192v1" +#define NID_X9_62_prime192v1 409 +#define OBJ_X9_62_prime192v1 OBJ_X9_62_primeCurve,1L + +#define SN_X9_62_prime192v2 "prime192v2" +#define NID_X9_62_prime192v2 410 +#define OBJ_X9_62_prime192v2 OBJ_X9_62_primeCurve,2L + +#define SN_X9_62_prime192v3 "prime192v3" +#define NID_X9_62_prime192v3 411 +#define OBJ_X9_62_prime192v3 OBJ_X9_62_primeCurve,3L + +#define SN_X9_62_prime239v1 "prime239v1" +#define NID_X9_62_prime239v1 412 +#define OBJ_X9_62_prime239v1 OBJ_X9_62_primeCurve,4L + +#define SN_X9_62_prime239v2 "prime239v2" +#define NID_X9_62_prime239v2 413 +#define OBJ_X9_62_prime239v2 OBJ_X9_62_primeCurve,5L + +#define SN_X9_62_prime239v3 "prime239v3" +#define NID_X9_62_prime239v3 414 +#define OBJ_X9_62_prime239v3 OBJ_X9_62_primeCurve,6L + +#define SN_X9_62_prime256v1 "prime256v1" +#define NID_X9_62_prime256v1 415 +#define OBJ_X9_62_prime256v1 OBJ_X9_62_primeCurve,7L + +#define OBJ_X9_62_id_ecSigType OBJ_ansi_X9_62,4L + +#define SN_ecdsa_with_SHA1 "ecdsa-with-SHA1" +#define NID_ecdsa_with_SHA1 416 +#define OBJ_ecdsa_with_SHA1 OBJ_X9_62_id_ecSigType,1L + +#define SN_ecdsa_with_Recommended "ecdsa-with-Recommended" +#define NID_ecdsa_with_Recommended 791 +#define OBJ_ecdsa_with_Recommended OBJ_X9_62_id_ecSigType,2L + +#define SN_ecdsa_with_Specified "ecdsa-with-Specified" +#define NID_ecdsa_with_Specified 792 +#define OBJ_ecdsa_with_Specified OBJ_X9_62_id_ecSigType,3L + +#define SN_ecdsa_with_SHA224 "ecdsa-with-SHA224" +#define NID_ecdsa_with_SHA224 793 +#define OBJ_ecdsa_with_SHA224 OBJ_ecdsa_with_Specified,1L + +#define SN_ecdsa_with_SHA256 "ecdsa-with-SHA256" +#define NID_ecdsa_with_SHA256 794 +#define OBJ_ecdsa_with_SHA256 OBJ_ecdsa_with_Specified,2L + +#define SN_ecdsa_with_SHA384 "ecdsa-with-SHA384" +#define NID_ecdsa_with_SHA384 795 +#define OBJ_ecdsa_with_SHA384 OBJ_ecdsa_with_Specified,3L + +#define SN_ecdsa_with_SHA512 "ecdsa-with-SHA512" +#define NID_ecdsa_with_SHA512 796 +#define OBJ_ecdsa_with_SHA512 OBJ_ecdsa_with_Specified,4L + +#define OBJ_secg_ellipticCurve OBJ_certicom_arc,0L + +#define SN_secp112r1 "secp112r1" +#define NID_secp112r1 704 +#define OBJ_secp112r1 OBJ_secg_ellipticCurve,6L + +#define SN_secp112r2 "secp112r2" +#define NID_secp112r2 705 +#define OBJ_secp112r2 OBJ_secg_ellipticCurve,7L + +#define SN_secp128r1 "secp128r1" +#define NID_secp128r1 706 +#define OBJ_secp128r1 OBJ_secg_ellipticCurve,28L + +#define SN_secp128r2 "secp128r2" +#define NID_secp128r2 707 +#define OBJ_secp128r2 OBJ_secg_ellipticCurve,29L + +#define SN_secp160k1 "secp160k1" +#define NID_secp160k1 708 +#define OBJ_secp160k1 OBJ_secg_ellipticCurve,9L + +#define SN_secp160r1 "secp160r1" +#define NID_secp160r1 709 +#define OBJ_secp160r1 OBJ_secg_ellipticCurve,8L + +#define SN_secp160r2 "secp160r2" +#define NID_secp160r2 710 +#define OBJ_secp160r2 OBJ_secg_ellipticCurve,30L + +#define SN_secp192k1 "secp192k1" +#define NID_secp192k1 711 +#define OBJ_secp192k1 OBJ_secg_ellipticCurve,31L + +#define SN_secp224k1 "secp224k1" +#define NID_secp224k1 712 +#define OBJ_secp224k1 OBJ_secg_ellipticCurve,32L + +#define SN_secp224r1 "secp224r1" +#define NID_secp224r1 713 +#define OBJ_secp224r1 OBJ_secg_ellipticCurve,33L + +#define SN_secp256k1 "secp256k1" +#define NID_secp256k1 714 +#define OBJ_secp256k1 OBJ_secg_ellipticCurve,10L + +#define SN_secp384r1 "secp384r1" +#define NID_secp384r1 715 +#define OBJ_secp384r1 OBJ_secg_ellipticCurve,34L + +#define SN_secp521r1 "secp521r1" +#define NID_secp521r1 716 +#define OBJ_secp521r1 OBJ_secg_ellipticCurve,35L + +#define SN_sect113r1 "sect113r1" +#define NID_sect113r1 717 +#define OBJ_sect113r1 OBJ_secg_ellipticCurve,4L + +#define SN_sect113r2 "sect113r2" +#define NID_sect113r2 718 +#define OBJ_sect113r2 OBJ_secg_ellipticCurve,5L + +#define SN_sect131r1 "sect131r1" +#define NID_sect131r1 719 +#define OBJ_sect131r1 OBJ_secg_ellipticCurve,22L + +#define SN_sect131r2 "sect131r2" +#define NID_sect131r2 720 +#define OBJ_sect131r2 OBJ_secg_ellipticCurve,23L + +#define SN_sect163k1 "sect163k1" +#define NID_sect163k1 721 +#define OBJ_sect163k1 OBJ_secg_ellipticCurve,1L + +#define SN_sect163r1 "sect163r1" +#define NID_sect163r1 722 +#define OBJ_sect163r1 OBJ_secg_ellipticCurve,2L + +#define SN_sect163r2 "sect163r2" +#define NID_sect163r2 723 +#define OBJ_sect163r2 OBJ_secg_ellipticCurve,15L + +#define SN_sect193r1 "sect193r1" +#define NID_sect193r1 724 +#define OBJ_sect193r1 OBJ_secg_ellipticCurve,24L + +#define SN_sect193r2 "sect193r2" +#define NID_sect193r2 725 +#define OBJ_sect193r2 OBJ_secg_ellipticCurve,25L + +#define SN_sect233k1 "sect233k1" +#define NID_sect233k1 726 +#define OBJ_sect233k1 OBJ_secg_ellipticCurve,26L + +#define SN_sect233r1 "sect233r1" +#define NID_sect233r1 727 +#define OBJ_sect233r1 OBJ_secg_ellipticCurve,27L + +#define SN_sect239k1 "sect239k1" +#define NID_sect239k1 728 +#define OBJ_sect239k1 OBJ_secg_ellipticCurve,3L + +#define SN_sect283k1 "sect283k1" +#define NID_sect283k1 729 +#define OBJ_sect283k1 OBJ_secg_ellipticCurve,16L + +#define SN_sect283r1 "sect283r1" +#define NID_sect283r1 730 +#define OBJ_sect283r1 OBJ_secg_ellipticCurve,17L + +#define SN_sect409k1 "sect409k1" +#define NID_sect409k1 731 +#define OBJ_sect409k1 OBJ_secg_ellipticCurve,36L + +#define SN_sect409r1 "sect409r1" +#define NID_sect409r1 732 +#define OBJ_sect409r1 OBJ_secg_ellipticCurve,37L + +#define SN_sect571k1 "sect571k1" +#define NID_sect571k1 733 +#define OBJ_sect571k1 OBJ_secg_ellipticCurve,38L + +#define SN_sect571r1 "sect571r1" +#define NID_sect571r1 734 +#define OBJ_sect571r1 OBJ_secg_ellipticCurve,39L + +#define OBJ_wap_wsg_idm_ecid OBJ_wap_wsg,4L + +#define SN_wap_wsg_idm_ecid_wtls1 "wap-wsg-idm-ecid-wtls1" +#define NID_wap_wsg_idm_ecid_wtls1 735 +#define OBJ_wap_wsg_idm_ecid_wtls1 OBJ_wap_wsg_idm_ecid,1L + +#define SN_wap_wsg_idm_ecid_wtls3 "wap-wsg-idm-ecid-wtls3" +#define NID_wap_wsg_idm_ecid_wtls3 736 +#define OBJ_wap_wsg_idm_ecid_wtls3 OBJ_wap_wsg_idm_ecid,3L + +#define SN_wap_wsg_idm_ecid_wtls4 "wap-wsg-idm-ecid-wtls4" +#define NID_wap_wsg_idm_ecid_wtls4 737 +#define OBJ_wap_wsg_idm_ecid_wtls4 OBJ_wap_wsg_idm_ecid,4L + +#define SN_wap_wsg_idm_ecid_wtls5 "wap-wsg-idm-ecid-wtls5" +#define NID_wap_wsg_idm_ecid_wtls5 738 +#define OBJ_wap_wsg_idm_ecid_wtls5 OBJ_wap_wsg_idm_ecid,5L + +#define SN_wap_wsg_idm_ecid_wtls6 "wap-wsg-idm-ecid-wtls6" +#define NID_wap_wsg_idm_ecid_wtls6 739 +#define OBJ_wap_wsg_idm_ecid_wtls6 OBJ_wap_wsg_idm_ecid,6L + +#define SN_wap_wsg_idm_ecid_wtls7 "wap-wsg-idm-ecid-wtls7" +#define NID_wap_wsg_idm_ecid_wtls7 740 +#define OBJ_wap_wsg_idm_ecid_wtls7 OBJ_wap_wsg_idm_ecid,7L + +#define SN_wap_wsg_idm_ecid_wtls8 "wap-wsg-idm-ecid-wtls8" +#define NID_wap_wsg_idm_ecid_wtls8 741 +#define OBJ_wap_wsg_idm_ecid_wtls8 OBJ_wap_wsg_idm_ecid,8L + +#define SN_wap_wsg_idm_ecid_wtls9 "wap-wsg-idm-ecid-wtls9" +#define NID_wap_wsg_idm_ecid_wtls9 742 +#define OBJ_wap_wsg_idm_ecid_wtls9 OBJ_wap_wsg_idm_ecid,9L + +#define SN_wap_wsg_idm_ecid_wtls10 "wap-wsg-idm-ecid-wtls10" +#define NID_wap_wsg_idm_ecid_wtls10 743 +#define OBJ_wap_wsg_idm_ecid_wtls10 OBJ_wap_wsg_idm_ecid,10L + +#define SN_wap_wsg_idm_ecid_wtls11 "wap-wsg-idm-ecid-wtls11" +#define NID_wap_wsg_idm_ecid_wtls11 744 +#define OBJ_wap_wsg_idm_ecid_wtls11 OBJ_wap_wsg_idm_ecid,11L + +#define SN_wap_wsg_idm_ecid_wtls12 "wap-wsg-idm-ecid-wtls12" +#define NID_wap_wsg_idm_ecid_wtls12 745 +#define OBJ_wap_wsg_idm_ecid_wtls12 OBJ_wap_wsg_idm_ecid,12L + +#define SN_cast5_cbc "CAST5-CBC" +#define LN_cast5_cbc "cast5-cbc" +#define NID_cast5_cbc 108 +#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L + +#define SN_cast5_ecb "CAST5-ECB" +#define LN_cast5_ecb "cast5-ecb" +#define NID_cast5_ecb 109 + +#define SN_cast5_cfb64 "CAST5-CFB" +#define LN_cast5_cfb64 "cast5-cfb" +#define NID_cast5_cfb64 110 + +#define SN_cast5_ofb64 "CAST5-OFB" +#define LN_cast5_ofb64 "cast5-ofb" +#define NID_cast5_ofb64 111 + +#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" +#define NID_pbeWithMD5AndCast5_CBC 112 +#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L + +#define SN_id_PasswordBasedMAC "id-PasswordBasedMAC" +#define LN_id_PasswordBasedMAC "password based MAC" +#define NID_id_PasswordBasedMAC 782 +#define OBJ_id_PasswordBasedMAC OBJ_ISO_US,113533L,7L,66L,13L + +#define SN_id_DHBasedMac "id-DHBasedMac" +#define LN_id_DHBasedMac "Diffie-Hellman based MAC" +#define NID_id_DHBasedMac 783 +#define OBJ_id_DHBasedMac OBJ_ISO_US,113533L,7L,66L,30L + +#define SN_rsadsi "rsadsi" +#define LN_rsadsi "RSA Data Security, Inc." +#define NID_rsadsi 1 +#define OBJ_rsadsi OBJ_ISO_US,113549L + +#define SN_pkcs "pkcs" +#define LN_pkcs "RSA Data Security, Inc. PKCS" +#define NID_pkcs 2 +#define OBJ_pkcs OBJ_rsadsi,1L + +#define SN_pkcs1 "pkcs1" +#define NID_pkcs1 186 +#define OBJ_pkcs1 OBJ_pkcs,1L + +#define LN_rsaEncryption "rsaEncryption" +#define NID_rsaEncryption 6 +#define OBJ_rsaEncryption OBJ_pkcs1,1L + +#define SN_md2WithRSAEncryption "RSA-MD2" +#define LN_md2WithRSAEncryption "md2WithRSAEncryption" +#define NID_md2WithRSAEncryption 7 +#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L + +#define SN_md4WithRSAEncryption "RSA-MD4" +#define LN_md4WithRSAEncryption "md4WithRSAEncryption" +#define NID_md4WithRSAEncryption 396 +#define OBJ_md4WithRSAEncryption OBJ_pkcs1,3L + +#define SN_md5WithRSAEncryption "RSA-MD5" +#define LN_md5WithRSAEncryption "md5WithRSAEncryption" +#define NID_md5WithRSAEncryption 8 +#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L + +#define SN_sha1WithRSAEncryption "RSA-SHA1" +#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" +#define NID_sha1WithRSAEncryption 65 +#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L + +#define SN_sha256WithRSAEncryption "RSA-SHA256" +#define LN_sha256WithRSAEncryption "sha256WithRSAEncryption" +#define NID_sha256WithRSAEncryption 668 +#define OBJ_sha256WithRSAEncryption OBJ_pkcs1,11L + +#define SN_sha384WithRSAEncryption "RSA-SHA384" +#define LN_sha384WithRSAEncryption "sha384WithRSAEncryption" +#define NID_sha384WithRSAEncryption 669 +#define OBJ_sha384WithRSAEncryption OBJ_pkcs1,12L + +#define SN_sha512WithRSAEncryption "RSA-SHA512" +#define LN_sha512WithRSAEncryption "sha512WithRSAEncryption" +#define NID_sha512WithRSAEncryption 670 +#define OBJ_sha512WithRSAEncryption OBJ_pkcs1,13L + +#define SN_sha224WithRSAEncryption "RSA-SHA224" +#define LN_sha224WithRSAEncryption "sha224WithRSAEncryption" +#define NID_sha224WithRSAEncryption 671 +#define OBJ_sha224WithRSAEncryption OBJ_pkcs1,14L + +#define SN_pkcs3 "pkcs3" +#define NID_pkcs3 27 +#define OBJ_pkcs3 OBJ_pkcs,3L + +#define LN_dhKeyAgreement "dhKeyAgreement" +#define NID_dhKeyAgreement 28 +#define OBJ_dhKeyAgreement OBJ_pkcs3,1L + +#define SN_pkcs5 "pkcs5" +#define NID_pkcs5 187 +#define OBJ_pkcs5 OBJ_pkcs,5L + +#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES" +#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" +#define NID_pbeWithMD2AndDES_CBC 9 +#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L + +#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES" +#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" +#define NID_pbeWithMD5AndDES_CBC 10 +#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L + +#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64" +#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +#define NID_pbeWithMD2AndRC2_CBC 168 +#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L + +#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64" +#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +#define NID_pbeWithMD5AndRC2_CBC 169 +#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L + +#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES" +#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +#define NID_pbeWithSHA1AndDES_CBC 170 +#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L + +#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" +#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" +#define NID_pbeWithSHA1AndRC2_CBC 68 +#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L + +#define LN_id_pbkdf2 "PBKDF2" +#define NID_id_pbkdf2 69 +#define OBJ_id_pbkdf2 OBJ_pkcs5,12L + +#define LN_pbes2 "PBES2" +#define NID_pbes2 161 +#define OBJ_pbes2 OBJ_pkcs5,13L + +#define LN_pbmac1 "PBMAC1" +#define NID_pbmac1 162 +#define OBJ_pbmac1 OBJ_pkcs5,14L + +#define SN_pkcs7 "pkcs7" +#define NID_pkcs7 20 +#define OBJ_pkcs7 OBJ_pkcs,7L + +#define LN_pkcs7_data "pkcs7-data" +#define NID_pkcs7_data 21 +#define OBJ_pkcs7_data OBJ_pkcs7,1L + +#define LN_pkcs7_signed "pkcs7-signedData" +#define NID_pkcs7_signed 22 +#define OBJ_pkcs7_signed OBJ_pkcs7,2L + +#define LN_pkcs7_enveloped "pkcs7-envelopedData" +#define NID_pkcs7_enveloped 23 +#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L + +#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" +#define NID_pkcs7_signedAndEnveloped 24 +#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L + +#define LN_pkcs7_digest "pkcs7-digestData" +#define NID_pkcs7_digest 25 +#define OBJ_pkcs7_digest OBJ_pkcs7,5L + +#define LN_pkcs7_encrypted "pkcs7-encryptedData" +#define NID_pkcs7_encrypted 26 +#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L + +#define SN_pkcs9 "pkcs9" +#define NID_pkcs9 47 +#define OBJ_pkcs9 OBJ_pkcs,9L + +#define LN_pkcs9_emailAddress "emailAddress" +#define NID_pkcs9_emailAddress 48 +#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L + +#define LN_pkcs9_unstructuredName "unstructuredName" +#define NID_pkcs9_unstructuredName 49 +#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L + +#define LN_pkcs9_contentType "contentType" +#define NID_pkcs9_contentType 50 +#define OBJ_pkcs9_contentType OBJ_pkcs9,3L + +#define LN_pkcs9_messageDigest "messageDigest" +#define NID_pkcs9_messageDigest 51 +#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L + +#define LN_pkcs9_signingTime "signingTime" +#define NID_pkcs9_signingTime 52 +#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L + +#define LN_pkcs9_countersignature "countersignature" +#define NID_pkcs9_countersignature 53 +#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L + +#define LN_pkcs9_challengePassword "challengePassword" +#define NID_pkcs9_challengePassword 54 +#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L + +#define LN_pkcs9_unstructuredAddress "unstructuredAddress" +#define NID_pkcs9_unstructuredAddress 55 +#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L + +#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" +#define NID_pkcs9_extCertAttributes 56 +#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L + +#define SN_ext_req "extReq" +#define LN_ext_req "Extension Request" +#define NID_ext_req 172 +#define OBJ_ext_req OBJ_pkcs9,14L + +#define SN_SMIMECapabilities "SMIME-CAPS" +#define LN_SMIMECapabilities "S/MIME Capabilities" +#define NID_SMIMECapabilities 167 +#define OBJ_SMIMECapabilities OBJ_pkcs9,15L + +#define SN_SMIME "SMIME" +#define LN_SMIME "S/MIME" +#define NID_SMIME 188 +#define OBJ_SMIME OBJ_pkcs9,16L + +#define SN_id_smime_mod "id-smime-mod" +#define NID_id_smime_mod 189 +#define OBJ_id_smime_mod OBJ_SMIME,0L + +#define SN_id_smime_ct "id-smime-ct" +#define NID_id_smime_ct 190 +#define OBJ_id_smime_ct OBJ_SMIME,1L + +#define SN_id_smime_aa "id-smime-aa" +#define NID_id_smime_aa 191 +#define OBJ_id_smime_aa OBJ_SMIME,2L + +#define SN_id_smime_alg "id-smime-alg" +#define NID_id_smime_alg 192 +#define OBJ_id_smime_alg OBJ_SMIME,3L + +#define SN_id_smime_cd "id-smime-cd" +#define NID_id_smime_cd 193 +#define OBJ_id_smime_cd OBJ_SMIME,4L + +#define SN_id_smime_spq "id-smime-spq" +#define NID_id_smime_spq 194 +#define OBJ_id_smime_spq OBJ_SMIME,5L + +#define SN_id_smime_cti "id-smime-cti" +#define NID_id_smime_cti 195 +#define OBJ_id_smime_cti OBJ_SMIME,6L + +#define SN_id_smime_mod_cms "id-smime-mod-cms" +#define NID_id_smime_mod_cms 196 +#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L + +#define SN_id_smime_mod_ess "id-smime-mod-ess" +#define NID_id_smime_mod_ess 197 +#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L + +#define SN_id_smime_mod_oid "id-smime-mod-oid" +#define NID_id_smime_mod_oid 198 +#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L + +#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3" +#define NID_id_smime_mod_msg_v3 199 +#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L + +#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88" +#define NID_id_smime_mod_ets_eSignature_88 200 +#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L + +#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97" +#define NID_id_smime_mod_ets_eSignature_97 201 +#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L + +#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88" +#define NID_id_smime_mod_ets_eSigPolicy_88 202 +#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L + +#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97" +#define NID_id_smime_mod_ets_eSigPolicy_97 203 +#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L + +#define SN_id_smime_ct_receipt "id-smime-ct-receipt" +#define NID_id_smime_ct_receipt 204 +#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L + +#define SN_id_smime_ct_authData "id-smime-ct-authData" +#define NID_id_smime_ct_authData 205 +#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L + +#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert" +#define NID_id_smime_ct_publishCert 206 +#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L + +#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo" +#define NID_id_smime_ct_TSTInfo 207 +#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L + +#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo" +#define NID_id_smime_ct_TDTInfo 208 +#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L + +#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo" +#define NID_id_smime_ct_contentInfo 209 +#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L + +#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData" +#define NID_id_smime_ct_DVCSRequestData 210 +#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L + +#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData" +#define NID_id_smime_ct_DVCSResponseData 211 +#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L + +#define SN_id_smime_ct_compressedData "id-smime-ct-compressedData" +#define NID_id_smime_ct_compressedData 786 +#define OBJ_id_smime_ct_compressedData OBJ_id_smime_ct,9L + +#define SN_id_ct_asciiTextWithCRLF "id-ct-asciiTextWithCRLF" +#define NID_id_ct_asciiTextWithCRLF 787 +#define OBJ_id_ct_asciiTextWithCRLF OBJ_id_smime_ct,27L + +#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest" +#define NID_id_smime_aa_receiptRequest 212 +#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L + +#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel" +#define NID_id_smime_aa_securityLabel 213 +#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L + +#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory" +#define NID_id_smime_aa_mlExpandHistory 214 +#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L + +#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint" +#define NID_id_smime_aa_contentHint 215 +#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L + +#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest" +#define NID_id_smime_aa_msgSigDigest 216 +#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L + +#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType" +#define NID_id_smime_aa_encapContentType 217 +#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L + +#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier" +#define NID_id_smime_aa_contentIdentifier 218 +#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L + +#define SN_id_smime_aa_macValue "id-smime-aa-macValue" +#define NID_id_smime_aa_macValue 219 +#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L + +#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels" +#define NID_id_smime_aa_equivalentLabels 220 +#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L + +#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference" +#define NID_id_smime_aa_contentReference 221 +#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L + +#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref" +#define NID_id_smime_aa_encrypKeyPref 222 +#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L + +#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate" +#define NID_id_smime_aa_signingCertificate 223 +#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L + +#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts" +#define NID_id_smime_aa_smimeEncryptCerts 224 +#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L + +#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken" +#define NID_id_smime_aa_timeStampToken 225 +#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L + +#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId" +#define NID_id_smime_aa_ets_sigPolicyId 226 +#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L + +#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType" +#define NID_id_smime_aa_ets_commitmentType 227 +#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L + +#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation" +#define NID_id_smime_aa_ets_signerLocation 228 +#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L + +#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr" +#define NID_id_smime_aa_ets_signerAttr 229 +#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L + +#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert" +#define NID_id_smime_aa_ets_otherSigCert 230 +#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L + +#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp" +#define NID_id_smime_aa_ets_contentTimestamp 231 +#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L + +#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs" +#define NID_id_smime_aa_ets_CertificateRefs 232 +#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L + +#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs" +#define NID_id_smime_aa_ets_RevocationRefs 233 +#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L + +#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues" +#define NID_id_smime_aa_ets_certValues 234 +#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L + +#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues" +#define NID_id_smime_aa_ets_revocationValues 235 +#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L + +#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp" +#define NID_id_smime_aa_ets_escTimeStamp 236 +#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L + +#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp" +#define NID_id_smime_aa_ets_certCRLTimestamp 237 +#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L + +#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp" +#define NID_id_smime_aa_ets_archiveTimeStamp 238 +#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L + +#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType" +#define NID_id_smime_aa_signatureType 239 +#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L + +#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc" +#define NID_id_smime_aa_dvcs_dvc 240 +#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L + +#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES" +#define NID_id_smime_alg_ESDHwith3DES 241 +#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L + +#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2" +#define NID_id_smime_alg_ESDHwithRC2 242 +#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L + +#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap" +#define NID_id_smime_alg_3DESwrap 243 +#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L + +#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap" +#define NID_id_smime_alg_RC2wrap 244 +#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L + +#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH" +#define NID_id_smime_alg_ESDH 245 +#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L + +#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap" +#define NID_id_smime_alg_CMS3DESwrap 246 +#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L + +#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap" +#define NID_id_smime_alg_CMSRC2wrap 247 +#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L + +#define SN_id_smime_cd_ldap "id-smime-cd-ldap" +#define NID_id_smime_cd_ldap 248 +#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L + +#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri" +#define NID_id_smime_spq_ets_sqt_uri 249 +#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L + +#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice" +#define NID_id_smime_spq_ets_sqt_unotice 250 +#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L + +#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin" +#define NID_id_smime_cti_ets_proofOfOrigin 251 +#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L + +#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt" +#define NID_id_smime_cti_ets_proofOfReceipt 252 +#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L + +#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery" +#define NID_id_smime_cti_ets_proofOfDelivery 253 +#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L + +#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender" +#define NID_id_smime_cti_ets_proofOfSender 254 +#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L + +#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval" +#define NID_id_smime_cti_ets_proofOfApproval 255 +#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L + +#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation" +#define NID_id_smime_cti_ets_proofOfCreation 256 +#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L + +#define LN_friendlyName "friendlyName" +#define NID_friendlyName 156 +#define OBJ_friendlyName OBJ_pkcs9,20L + +#define LN_localKeyID "localKeyID" +#define NID_localKeyID 157 +#define OBJ_localKeyID OBJ_pkcs9,21L + +#define SN_ms_csp_name "CSPName" +#define LN_ms_csp_name "Microsoft CSP Name" +#define NID_ms_csp_name 417 +#define OBJ_ms_csp_name 1L,3L,6L,1L,4L,1L,311L,17L,1L + +#define SN_LocalKeySet "LocalKeySet" +#define LN_LocalKeySet "Microsoft Local Key set" +#define NID_LocalKeySet 856 +#define OBJ_LocalKeySet 1L,3L,6L,1L,4L,1L,311L,17L,2L + +#define OBJ_certTypes OBJ_pkcs9,22L + +#define LN_x509Certificate "x509Certificate" +#define NID_x509Certificate 158 +#define OBJ_x509Certificate OBJ_certTypes,1L + +#define LN_sdsiCertificate "sdsiCertificate" +#define NID_sdsiCertificate 159 +#define OBJ_sdsiCertificate OBJ_certTypes,2L + +#define OBJ_crlTypes OBJ_pkcs9,23L + +#define LN_x509Crl "x509Crl" +#define NID_x509Crl 160 +#define OBJ_x509Crl OBJ_crlTypes,1L + +#define OBJ_pkcs12 OBJ_pkcs,12L + +#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L + +#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128" +#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +#define NID_pbe_WithSHA1And128BitRC4 144 +#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L + +#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40" +#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +#define NID_pbe_WithSHA1And40BitRC4 145 +#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L + +#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES" +#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L + +#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES" +#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L + +#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128" +#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +#define NID_pbe_WithSHA1And128BitRC2_CBC 148 +#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L + +#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40" +#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +#define NID_pbe_WithSHA1And40BitRC2_CBC 149 +#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L + +#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L + +#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L + +#define LN_keyBag "keyBag" +#define NID_keyBag 150 +#define OBJ_keyBag OBJ_pkcs12_BagIds,1L + +#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +#define NID_pkcs8ShroudedKeyBag 151 +#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L + +#define LN_certBag "certBag" +#define NID_certBag 152 +#define OBJ_certBag OBJ_pkcs12_BagIds,3L + +#define LN_crlBag "crlBag" +#define NID_crlBag 153 +#define OBJ_crlBag OBJ_pkcs12_BagIds,4L + +#define LN_secretBag "secretBag" +#define NID_secretBag 154 +#define OBJ_secretBag OBJ_pkcs12_BagIds,5L + +#define LN_safeContentsBag "safeContentsBag" +#define NID_safeContentsBag 155 +#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L + +#define SN_md2 "MD2" +#define LN_md2 "md2" +#define NID_md2 3 +#define OBJ_md2 OBJ_rsadsi,2L,2L + +#define SN_md4 "MD4" +#define LN_md4 "md4" +#define NID_md4 257 +#define OBJ_md4 OBJ_rsadsi,2L,4L + +#define SN_md5 "MD5" +#define LN_md5 "md5" +#define NID_md5 4 +#define OBJ_md5 OBJ_rsadsi,2L,5L + +#define SN_md5_sha1 "MD5-SHA1" +#define LN_md5_sha1 "md5-sha1" +#define NID_md5_sha1 114 + +#define LN_hmacWithMD5 "hmacWithMD5" +#define NID_hmacWithMD5 797 +#define OBJ_hmacWithMD5 OBJ_rsadsi,2L,6L + +#define LN_hmacWithSHA1 "hmacWithSHA1" +#define NID_hmacWithSHA1 163 +#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +#define LN_hmacWithSHA224 "hmacWithSHA224" +#define NID_hmacWithSHA224 798 +#define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L + +#define LN_hmacWithSHA256 "hmacWithSHA256" +#define NID_hmacWithSHA256 799 +#define OBJ_hmacWithSHA256 OBJ_rsadsi,2L,9L + +#define LN_hmacWithSHA384 "hmacWithSHA384" +#define NID_hmacWithSHA384 800 +#define OBJ_hmacWithSHA384 OBJ_rsadsi,2L,10L + +#define LN_hmacWithSHA512 "hmacWithSHA512" +#define NID_hmacWithSHA512 801 +#define OBJ_hmacWithSHA512 OBJ_rsadsi,2L,11L + +#define SN_rc2_cbc "RC2-CBC" +#define LN_rc2_cbc "rc2-cbc" +#define NID_rc2_cbc 37 +#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L + +#define SN_rc2_ecb "RC2-ECB" +#define LN_rc2_ecb "rc2-ecb" +#define NID_rc2_ecb 38 + +#define SN_rc2_cfb64 "RC2-CFB" +#define LN_rc2_cfb64 "rc2-cfb" +#define NID_rc2_cfb64 39 + +#define SN_rc2_ofb64 "RC2-OFB" +#define LN_rc2_ofb64 "rc2-ofb" +#define NID_rc2_ofb64 40 + +#define SN_rc2_40_cbc "RC2-40-CBC" +#define LN_rc2_40_cbc "rc2-40-cbc" +#define NID_rc2_40_cbc 98 + +#define SN_rc2_64_cbc "RC2-64-CBC" +#define LN_rc2_64_cbc "rc2-64-cbc" +#define NID_rc2_64_cbc 166 + +#define SN_rc4 "RC4" +#define LN_rc4 "rc4" +#define NID_rc4 5 +#define OBJ_rc4 OBJ_rsadsi,3L,4L + +#define SN_rc4_40 "RC4-40" +#define LN_rc4_40 "rc4-40" +#define NID_rc4_40 97 + +#define SN_des_ede3_cbc "DES-EDE3-CBC" +#define LN_des_ede3_cbc "des-ede3-cbc" +#define NID_des_ede3_cbc 44 +#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L + +#define SN_rc5_cbc "RC5-CBC" +#define LN_rc5_cbc "rc5-cbc" +#define NID_rc5_cbc 120 +#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L + +#define SN_rc5_ecb "RC5-ECB" +#define LN_rc5_ecb "rc5-ecb" +#define NID_rc5_ecb 121 + +#define SN_rc5_cfb64 "RC5-CFB" +#define LN_rc5_cfb64 "rc5-cfb" +#define NID_rc5_cfb64 122 + +#define SN_rc5_ofb64 "RC5-OFB" +#define LN_rc5_ofb64 "rc5-ofb" +#define NID_rc5_ofb64 123 + +#define SN_ms_ext_req "msExtReq" +#define LN_ms_ext_req "Microsoft Extension Request" +#define NID_ms_ext_req 171 +#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L + +#define SN_ms_code_ind "msCodeInd" +#define LN_ms_code_ind "Microsoft Individual Code Signing" +#define NID_ms_code_ind 134 +#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +#define SN_ms_code_com "msCodeCom" +#define LN_ms_code_com "Microsoft Commercial Code Signing" +#define NID_ms_code_com 135 +#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +#define SN_ms_ctl_sign "msCTLSign" +#define LN_ms_ctl_sign "Microsoft Trust List Signing" +#define NID_ms_ctl_sign 136 +#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +#define SN_ms_sgc "msSGC" +#define LN_ms_sgc "Microsoft Server Gated Crypto" +#define NID_ms_sgc 137 +#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +#define SN_ms_efs "msEFS" +#define LN_ms_efs "Microsoft Encrypted File System" +#define NID_ms_efs 138 +#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +#define SN_ms_smartcard_login "msSmartcardLogin" +#define LN_ms_smartcard_login "Microsoft Smartcardlogin" +#define NID_ms_smartcard_login 648 +#define OBJ_ms_smartcard_login 1L,3L,6L,1L,4L,1L,311L,20L,2L,2L + +#define SN_ms_upn "msUPN" +#define LN_ms_upn "Microsoft Universal Principal Name" +#define NID_ms_upn 649 +#define OBJ_ms_upn 1L,3L,6L,1L,4L,1L,311L,20L,2L,3L + +#define SN_idea_cbc "IDEA-CBC" +#define LN_idea_cbc "idea-cbc" +#define NID_idea_cbc 34 +#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L + +#define SN_idea_ecb "IDEA-ECB" +#define LN_idea_ecb "idea-ecb" +#define NID_idea_ecb 36 + +#define SN_idea_cfb64 "IDEA-CFB" +#define LN_idea_cfb64 "idea-cfb" +#define NID_idea_cfb64 35 + +#define SN_idea_ofb64 "IDEA-OFB" +#define LN_idea_ofb64 "idea-ofb" +#define NID_idea_ofb64 46 + +#define SN_bf_cbc "BF-CBC" +#define LN_bf_cbc "bf-cbc" +#define NID_bf_cbc 91 +#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L + +#define SN_bf_ecb "BF-ECB" +#define LN_bf_ecb "bf-ecb" +#define NID_bf_ecb 92 + +#define SN_bf_cfb64 "BF-CFB" +#define LN_bf_cfb64 "bf-cfb" +#define NID_bf_cfb64 93 + +#define SN_bf_ofb64 "BF-OFB" +#define LN_bf_ofb64 "bf-ofb" +#define NID_bf_ofb64 94 + +#define SN_id_pkix "PKIX" +#define NID_id_pkix 127 +#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +#define SN_id_pkix_mod "id-pkix-mod" +#define NID_id_pkix_mod 258 +#define OBJ_id_pkix_mod OBJ_id_pkix,0L + +#define SN_id_pe "id-pe" +#define NID_id_pe 175 +#define OBJ_id_pe OBJ_id_pkix,1L + +#define SN_id_qt "id-qt" +#define NID_id_qt 259 +#define OBJ_id_qt OBJ_id_pkix,2L + +#define SN_id_kp "id-kp" +#define NID_id_kp 128 +#define OBJ_id_kp OBJ_id_pkix,3L + +#define SN_id_it "id-it" +#define NID_id_it 260 +#define OBJ_id_it OBJ_id_pkix,4L + +#define SN_id_pkip "id-pkip" +#define NID_id_pkip 261 +#define OBJ_id_pkip OBJ_id_pkix,5L + +#define SN_id_alg "id-alg" +#define NID_id_alg 262 +#define OBJ_id_alg OBJ_id_pkix,6L + +#define SN_id_cmc "id-cmc" +#define NID_id_cmc 263 +#define OBJ_id_cmc OBJ_id_pkix,7L + +#define SN_id_on "id-on" +#define NID_id_on 264 +#define OBJ_id_on OBJ_id_pkix,8L + +#define SN_id_pda "id-pda" +#define NID_id_pda 265 +#define OBJ_id_pda OBJ_id_pkix,9L + +#define SN_id_aca "id-aca" +#define NID_id_aca 266 +#define OBJ_id_aca OBJ_id_pkix,10L + +#define SN_id_qcs "id-qcs" +#define NID_id_qcs 267 +#define OBJ_id_qcs OBJ_id_pkix,11L + +#define SN_id_cct "id-cct" +#define NID_id_cct 268 +#define OBJ_id_cct OBJ_id_pkix,12L + +#define SN_id_ppl "id-ppl" +#define NID_id_ppl 662 +#define OBJ_id_ppl OBJ_id_pkix,21L + +#define SN_id_ad "id-ad" +#define NID_id_ad 176 +#define OBJ_id_ad OBJ_id_pkix,48L + +#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88" +#define NID_id_pkix1_explicit_88 269 +#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L + +#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88" +#define NID_id_pkix1_implicit_88 270 +#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L + +#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93" +#define NID_id_pkix1_explicit_93 271 +#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L + +#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93" +#define NID_id_pkix1_implicit_93 272 +#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L + +#define SN_id_mod_crmf "id-mod-crmf" +#define NID_id_mod_crmf 273 +#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L + +#define SN_id_mod_cmc "id-mod-cmc" +#define NID_id_mod_cmc 274 +#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L + +#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88" +#define NID_id_mod_kea_profile_88 275 +#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L + +#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93" +#define NID_id_mod_kea_profile_93 276 +#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L + +#define SN_id_mod_cmp "id-mod-cmp" +#define NID_id_mod_cmp 277 +#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L + +#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88" +#define NID_id_mod_qualified_cert_88 278 +#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L + +#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93" +#define NID_id_mod_qualified_cert_93 279 +#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L + +#define SN_id_mod_attribute_cert "id-mod-attribute-cert" +#define NID_id_mod_attribute_cert 280 +#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L + +#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol" +#define NID_id_mod_timestamp_protocol 281 +#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L + +#define SN_id_mod_ocsp "id-mod-ocsp" +#define NID_id_mod_ocsp 282 +#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L + +#define SN_id_mod_dvcs "id-mod-dvcs" +#define NID_id_mod_dvcs 283 +#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L + +#define SN_id_mod_cmp2000 "id-mod-cmp2000" +#define NID_id_mod_cmp2000 284 +#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L + +#define SN_info_access "authorityInfoAccess" +#define LN_info_access "Authority Information Access" +#define NID_info_access 177 +#define OBJ_info_access OBJ_id_pe,1L + +#define SN_biometricInfo "biometricInfo" +#define LN_biometricInfo "Biometric Info" +#define NID_biometricInfo 285 +#define OBJ_biometricInfo OBJ_id_pe,2L + +#define SN_qcStatements "qcStatements" +#define NID_qcStatements 286 +#define OBJ_qcStatements OBJ_id_pe,3L + +#define SN_ac_auditEntity "ac-auditEntity" +#define NID_ac_auditEntity 287 +#define OBJ_ac_auditEntity OBJ_id_pe,4L + +#define SN_ac_targeting "ac-targeting" +#define NID_ac_targeting 288 +#define OBJ_ac_targeting OBJ_id_pe,5L + +#define SN_aaControls "aaControls" +#define NID_aaControls 289 +#define OBJ_aaControls OBJ_id_pe,6L + +#define SN_sbgp_ipAddrBlock "sbgp-ipAddrBlock" +#define NID_sbgp_ipAddrBlock 290 +#define OBJ_sbgp_ipAddrBlock OBJ_id_pe,7L + +#define SN_sbgp_autonomousSysNum "sbgp-autonomousSysNum" +#define NID_sbgp_autonomousSysNum 291 +#define OBJ_sbgp_autonomousSysNum OBJ_id_pe,8L + +#define SN_sbgp_routerIdentifier "sbgp-routerIdentifier" +#define NID_sbgp_routerIdentifier 292 +#define OBJ_sbgp_routerIdentifier OBJ_id_pe,9L + +#define SN_ac_proxying "ac-proxying" +#define NID_ac_proxying 397 +#define OBJ_ac_proxying OBJ_id_pe,10L + +#define SN_sinfo_access "subjectInfoAccess" +#define LN_sinfo_access "Subject Information Access" +#define NID_sinfo_access 398 +#define OBJ_sinfo_access OBJ_id_pe,11L + +#define SN_proxyCertInfo "proxyCertInfo" +#define LN_proxyCertInfo "Proxy Certificate Information" +#define NID_proxyCertInfo 663 +#define OBJ_proxyCertInfo OBJ_id_pe,14L + +#define SN_id_qt_cps "id-qt-cps" +#define LN_id_qt_cps "Policy Qualifier CPS" +#define NID_id_qt_cps 164 +#define OBJ_id_qt_cps OBJ_id_qt,1L + +#define SN_id_qt_unotice "id-qt-unotice" +#define LN_id_qt_unotice "Policy Qualifier User Notice" +#define NID_id_qt_unotice 165 +#define OBJ_id_qt_unotice OBJ_id_qt,2L + +#define SN_textNotice "textNotice" +#define NID_textNotice 293 +#define OBJ_textNotice OBJ_id_qt,3L + +#define SN_server_auth "serverAuth" +#define LN_server_auth "TLS Web Server Authentication" +#define NID_server_auth 129 +#define OBJ_server_auth OBJ_id_kp,1L + +#define SN_client_auth "clientAuth" +#define LN_client_auth "TLS Web Client Authentication" +#define NID_client_auth 130 +#define OBJ_client_auth OBJ_id_kp,2L + +#define SN_code_sign "codeSigning" +#define LN_code_sign "Code Signing" +#define NID_code_sign 131 +#define OBJ_code_sign OBJ_id_kp,3L + +#define SN_email_protect "emailProtection" +#define LN_email_protect "E-mail Protection" +#define NID_email_protect 132 +#define OBJ_email_protect OBJ_id_kp,4L + +#define SN_ipsecEndSystem "ipsecEndSystem" +#define LN_ipsecEndSystem "IPSec End System" +#define NID_ipsecEndSystem 294 +#define OBJ_ipsecEndSystem OBJ_id_kp,5L + +#define SN_ipsecTunnel "ipsecTunnel" +#define LN_ipsecTunnel "IPSec Tunnel" +#define NID_ipsecTunnel 295 +#define OBJ_ipsecTunnel OBJ_id_kp,6L + +#define SN_ipsecUser "ipsecUser" +#define LN_ipsecUser "IPSec User" +#define NID_ipsecUser 296 +#define OBJ_ipsecUser OBJ_id_kp,7L + +#define SN_time_stamp "timeStamping" +#define LN_time_stamp "Time Stamping" +#define NID_time_stamp 133 +#define OBJ_time_stamp OBJ_id_kp,8L + +#define SN_OCSP_sign "OCSPSigning" +#define LN_OCSP_sign "OCSP Signing" +#define NID_OCSP_sign 180 +#define OBJ_OCSP_sign OBJ_id_kp,9L + +#define SN_dvcs "DVCS" +#define LN_dvcs "dvcs" +#define NID_dvcs 297 +#define OBJ_dvcs OBJ_id_kp,10L + +#define SN_id_it_caProtEncCert "id-it-caProtEncCert" +#define NID_id_it_caProtEncCert 298 +#define OBJ_id_it_caProtEncCert OBJ_id_it,1L + +#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes" +#define NID_id_it_signKeyPairTypes 299 +#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L + +#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes" +#define NID_id_it_encKeyPairTypes 300 +#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L + +#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg" +#define NID_id_it_preferredSymmAlg 301 +#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L + +#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo" +#define NID_id_it_caKeyUpdateInfo 302 +#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L + +#define SN_id_it_currentCRL "id-it-currentCRL" +#define NID_id_it_currentCRL 303 +#define OBJ_id_it_currentCRL OBJ_id_it,6L + +#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs" +#define NID_id_it_unsupportedOIDs 304 +#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L + +#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest" +#define NID_id_it_subscriptionRequest 305 +#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L + +#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse" +#define NID_id_it_subscriptionResponse 306 +#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L + +#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq" +#define NID_id_it_keyPairParamReq 307 +#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L + +#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep" +#define NID_id_it_keyPairParamRep 308 +#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L + +#define SN_id_it_revPassphrase "id-it-revPassphrase" +#define NID_id_it_revPassphrase 309 +#define OBJ_id_it_revPassphrase OBJ_id_it,12L + +#define SN_id_it_implicitConfirm "id-it-implicitConfirm" +#define NID_id_it_implicitConfirm 310 +#define OBJ_id_it_implicitConfirm OBJ_id_it,13L + +#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime" +#define NID_id_it_confirmWaitTime 311 +#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L + +#define SN_id_it_origPKIMessage "id-it-origPKIMessage" +#define NID_id_it_origPKIMessage 312 +#define OBJ_id_it_origPKIMessage OBJ_id_it,15L + +#define SN_id_it_suppLangTags "id-it-suppLangTags" +#define NID_id_it_suppLangTags 784 +#define OBJ_id_it_suppLangTags OBJ_id_it,16L + +#define SN_id_regCtrl "id-regCtrl" +#define NID_id_regCtrl 313 +#define OBJ_id_regCtrl OBJ_id_pkip,1L + +#define SN_id_regInfo "id-regInfo" +#define NID_id_regInfo 314 +#define OBJ_id_regInfo OBJ_id_pkip,2L + +#define SN_id_regCtrl_regToken "id-regCtrl-regToken" +#define NID_id_regCtrl_regToken 315 +#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L + +#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator" +#define NID_id_regCtrl_authenticator 316 +#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L + +#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo" +#define NID_id_regCtrl_pkiPublicationInfo 317 +#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L + +#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions" +#define NID_id_regCtrl_pkiArchiveOptions 318 +#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L + +#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID" +#define NID_id_regCtrl_oldCertID 319 +#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L + +#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey" +#define NID_id_regCtrl_protocolEncrKey 320 +#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L + +#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs" +#define NID_id_regInfo_utf8Pairs 321 +#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L + +#define SN_id_regInfo_certReq "id-regInfo-certReq" +#define NID_id_regInfo_certReq 322 +#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L + +#define SN_id_alg_des40 "id-alg-des40" +#define NID_id_alg_des40 323 +#define OBJ_id_alg_des40 OBJ_id_alg,1L + +#define SN_id_alg_noSignature "id-alg-noSignature" +#define NID_id_alg_noSignature 324 +#define OBJ_id_alg_noSignature OBJ_id_alg,2L + +#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1" +#define NID_id_alg_dh_sig_hmac_sha1 325 +#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L + +#define SN_id_alg_dh_pop "id-alg-dh-pop" +#define NID_id_alg_dh_pop 326 +#define OBJ_id_alg_dh_pop OBJ_id_alg,4L + +#define SN_id_cmc_statusInfo "id-cmc-statusInfo" +#define NID_id_cmc_statusInfo 327 +#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L + +#define SN_id_cmc_identification "id-cmc-identification" +#define NID_id_cmc_identification 328 +#define OBJ_id_cmc_identification OBJ_id_cmc,2L + +#define SN_id_cmc_identityProof "id-cmc-identityProof" +#define NID_id_cmc_identityProof 329 +#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L + +#define SN_id_cmc_dataReturn "id-cmc-dataReturn" +#define NID_id_cmc_dataReturn 330 +#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L + +#define SN_id_cmc_transactionId "id-cmc-transactionId" +#define NID_id_cmc_transactionId 331 +#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L + +#define SN_id_cmc_senderNonce "id-cmc-senderNonce" +#define NID_id_cmc_senderNonce 332 +#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L + +#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce" +#define NID_id_cmc_recipientNonce 333 +#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L + +#define SN_id_cmc_addExtensions "id-cmc-addExtensions" +#define NID_id_cmc_addExtensions 334 +#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L + +#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP" +#define NID_id_cmc_encryptedPOP 335 +#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L + +#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP" +#define NID_id_cmc_decryptedPOP 336 +#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L + +#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness" +#define NID_id_cmc_lraPOPWitness 337 +#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L + +#define SN_id_cmc_getCert "id-cmc-getCert" +#define NID_id_cmc_getCert 338 +#define OBJ_id_cmc_getCert OBJ_id_cmc,15L + +#define SN_id_cmc_getCRL "id-cmc-getCRL" +#define NID_id_cmc_getCRL 339 +#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L + +#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest" +#define NID_id_cmc_revokeRequest 340 +#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L + +#define SN_id_cmc_regInfo "id-cmc-regInfo" +#define NID_id_cmc_regInfo 341 +#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L + +#define SN_id_cmc_responseInfo "id-cmc-responseInfo" +#define NID_id_cmc_responseInfo 342 +#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L + +#define SN_id_cmc_queryPending "id-cmc-queryPending" +#define NID_id_cmc_queryPending 343 +#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L + +#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom" +#define NID_id_cmc_popLinkRandom 344 +#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L + +#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness" +#define NID_id_cmc_popLinkWitness 345 +#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L + +#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance" +#define NID_id_cmc_confirmCertAcceptance 346 +#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L + +#define SN_id_on_personalData "id-on-personalData" +#define NID_id_on_personalData 347 +#define OBJ_id_on_personalData OBJ_id_on,1L + +#define SN_id_on_permanentIdentifier "id-on-permanentIdentifier" +#define LN_id_on_permanentIdentifier "Permanent Identifier" +#define NID_id_on_permanentIdentifier 858 +#define OBJ_id_on_permanentIdentifier OBJ_id_on,3L + +#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth" +#define NID_id_pda_dateOfBirth 348 +#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L + +#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth" +#define NID_id_pda_placeOfBirth 349 +#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L + +#define SN_id_pda_gender "id-pda-gender" +#define NID_id_pda_gender 351 +#define OBJ_id_pda_gender OBJ_id_pda,3L + +#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship" +#define NID_id_pda_countryOfCitizenship 352 +#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,4L + +#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence" +#define NID_id_pda_countryOfResidence 353 +#define OBJ_id_pda_countryOfResidence OBJ_id_pda,5L + +#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo" +#define NID_id_aca_authenticationInfo 354 +#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L + +#define SN_id_aca_accessIdentity "id-aca-accessIdentity" +#define NID_id_aca_accessIdentity 355 +#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L + +#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity" +#define NID_id_aca_chargingIdentity 356 +#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L + +#define SN_id_aca_group "id-aca-group" +#define NID_id_aca_group 357 +#define OBJ_id_aca_group OBJ_id_aca,4L + +#define SN_id_aca_role "id-aca-role" +#define NID_id_aca_role 358 +#define OBJ_id_aca_role OBJ_id_aca,5L + +#define SN_id_aca_encAttrs "id-aca-encAttrs" +#define NID_id_aca_encAttrs 399 +#define OBJ_id_aca_encAttrs OBJ_id_aca,6L + +#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1" +#define NID_id_qcs_pkixQCSyntax_v1 359 +#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L + +#define SN_id_cct_crs "id-cct-crs" +#define NID_id_cct_crs 360 +#define OBJ_id_cct_crs OBJ_id_cct,1L + +#define SN_id_cct_PKIData "id-cct-PKIData" +#define NID_id_cct_PKIData 361 +#define OBJ_id_cct_PKIData OBJ_id_cct,2L + +#define SN_id_cct_PKIResponse "id-cct-PKIResponse" +#define NID_id_cct_PKIResponse 362 +#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L + +#define SN_id_ppl_anyLanguage "id-ppl-anyLanguage" +#define LN_id_ppl_anyLanguage "Any language" +#define NID_id_ppl_anyLanguage 664 +#define OBJ_id_ppl_anyLanguage OBJ_id_ppl,0L + +#define SN_id_ppl_inheritAll "id-ppl-inheritAll" +#define LN_id_ppl_inheritAll "Inherit all" +#define NID_id_ppl_inheritAll 665 +#define OBJ_id_ppl_inheritAll OBJ_id_ppl,1L + +#define SN_Independent "id-ppl-independent" +#define LN_Independent "Independent" +#define NID_Independent 667 +#define OBJ_Independent OBJ_id_ppl,2L + +#define SN_ad_OCSP "OCSP" +#define LN_ad_OCSP "OCSP" +#define NID_ad_OCSP 178 +#define OBJ_ad_OCSP OBJ_id_ad,1L + +#define SN_ad_ca_issuers "caIssuers" +#define LN_ad_ca_issuers "CA Issuers" +#define NID_ad_ca_issuers 179 +#define OBJ_ad_ca_issuers OBJ_id_ad,2L + +#define SN_ad_timeStamping "ad_timestamping" +#define LN_ad_timeStamping "AD Time Stamping" +#define NID_ad_timeStamping 363 +#define OBJ_ad_timeStamping OBJ_id_ad,3L + +#define SN_ad_dvcs "AD_DVCS" +#define LN_ad_dvcs "ad dvcs" +#define NID_ad_dvcs 364 +#define OBJ_ad_dvcs OBJ_id_ad,4L + +#define SN_caRepository "caRepository" +#define LN_caRepository "CA Repository" +#define NID_caRepository 785 +#define OBJ_caRepository OBJ_id_ad,5L + +#define OBJ_id_pkix_OCSP OBJ_ad_OCSP + +#define SN_id_pkix_OCSP_basic "basicOCSPResponse" +#define LN_id_pkix_OCSP_basic "Basic OCSP Response" +#define NID_id_pkix_OCSP_basic 365 +#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L + +#define SN_id_pkix_OCSP_Nonce "Nonce" +#define LN_id_pkix_OCSP_Nonce "OCSP Nonce" +#define NID_id_pkix_OCSP_Nonce 366 +#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L + +#define SN_id_pkix_OCSP_CrlID "CrlID" +#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID" +#define NID_id_pkix_OCSP_CrlID 367 +#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L + +#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses" +#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses" +#define NID_id_pkix_OCSP_acceptableResponses 368 +#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L + +#define SN_id_pkix_OCSP_noCheck "noCheck" +#define LN_id_pkix_OCSP_noCheck "OCSP No Check" +#define NID_id_pkix_OCSP_noCheck 369 +#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L + +#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff" +#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff" +#define NID_id_pkix_OCSP_archiveCutoff 370 +#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L + +#define SN_id_pkix_OCSP_serviceLocator "serviceLocator" +#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator" +#define NID_id_pkix_OCSP_serviceLocator 371 +#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L + +#define SN_id_pkix_OCSP_extendedStatus "extendedStatus" +#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status" +#define NID_id_pkix_OCSP_extendedStatus 372 +#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L + +#define SN_id_pkix_OCSP_valid "valid" +#define NID_id_pkix_OCSP_valid 373 +#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L + +#define SN_id_pkix_OCSP_path "path" +#define NID_id_pkix_OCSP_path 374 +#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L + +#define SN_id_pkix_OCSP_trustRoot "trustRoot" +#define LN_id_pkix_OCSP_trustRoot "Trust Root" +#define NID_id_pkix_OCSP_trustRoot 375 +#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L + +#define SN_algorithm "algorithm" +#define LN_algorithm "algorithm" +#define NID_algorithm 376 +#define OBJ_algorithm 1L,3L,14L,3L,2L + +#define SN_md5WithRSA "RSA-NP-MD5" +#define LN_md5WithRSA "md5WithRSA" +#define NID_md5WithRSA 104 +#define OBJ_md5WithRSA OBJ_algorithm,3L + +#define SN_des_ecb "DES-ECB" +#define LN_des_ecb "des-ecb" +#define NID_des_ecb 29 +#define OBJ_des_ecb OBJ_algorithm,6L + +#define SN_des_cbc "DES-CBC" +#define LN_des_cbc "des-cbc" +#define NID_des_cbc 31 +#define OBJ_des_cbc OBJ_algorithm,7L + +#define SN_des_ofb64 "DES-OFB" +#define LN_des_ofb64 "des-ofb" +#define NID_des_ofb64 45 +#define OBJ_des_ofb64 OBJ_algorithm,8L + +#define SN_des_cfb64 "DES-CFB" +#define LN_des_cfb64 "des-cfb" +#define NID_des_cfb64 30 +#define OBJ_des_cfb64 OBJ_algorithm,9L + +#define SN_rsaSignature "rsaSignature" +#define NID_rsaSignature 377 +#define OBJ_rsaSignature OBJ_algorithm,11L + +#define SN_dsa_2 "DSA-old" +#define LN_dsa_2 "dsaEncryption-old" +#define NID_dsa_2 67 +#define OBJ_dsa_2 OBJ_algorithm,12L + +#define SN_dsaWithSHA "DSA-SHA" +#define LN_dsaWithSHA "dsaWithSHA" +#define NID_dsaWithSHA 66 +#define OBJ_dsaWithSHA OBJ_algorithm,13L + +#define SN_shaWithRSAEncryption "RSA-SHA" +#define LN_shaWithRSAEncryption "shaWithRSAEncryption" +#define NID_shaWithRSAEncryption 42 +#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L + +#define SN_des_ede_ecb "DES-EDE" +#define LN_des_ede_ecb "des-ede" +#define NID_des_ede_ecb 32 +#define OBJ_des_ede_ecb OBJ_algorithm,17L + +#define SN_des_ede3_ecb "DES-EDE3" +#define LN_des_ede3_ecb "des-ede3" +#define NID_des_ede3_ecb 33 + +#define SN_des_ede_cbc "DES-EDE-CBC" +#define LN_des_ede_cbc "des-ede-cbc" +#define NID_des_ede_cbc 43 + +#define SN_des_ede_cfb64 "DES-EDE-CFB" +#define LN_des_ede_cfb64 "des-ede-cfb" +#define NID_des_ede_cfb64 60 + +#define SN_des_ede3_cfb64 "DES-EDE3-CFB" +#define LN_des_ede3_cfb64 "des-ede3-cfb" +#define NID_des_ede3_cfb64 61 + +#define SN_des_ede_ofb64 "DES-EDE-OFB" +#define LN_des_ede_ofb64 "des-ede-ofb" +#define NID_des_ede_ofb64 62 + +#define SN_des_ede3_ofb64 "DES-EDE3-OFB" +#define LN_des_ede3_ofb64 "des-ede3-ofb" +#define NID_des_ede3_ofb64 63 + +#define SN_desx_cbc "DESX-CBC" +#define LN_desx_cbc "desx-cbc" +#define NID_desx_cbc 80 + +#define SN_sha "SHA" +#define LN_sha "sha" +#define NID_sha 41 +#define OBJ_sha OBJ_algorithm,18L + +#define SN_sha1 "SHA1" +#define LN_sha1 "sha1" +#define NID_sha1 64 +#define OBJ_sha1 OBJ_algorithm,26L + +#define SN_dsaWithSHA1_2 "DSA-SHA1-old" +#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" +#define NID_dsaWithSHA1_2 70 +#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L + +#define SN_sha1WithRSA "RSA-SHA1-2" +#define LN_sha1WithRSA "sha1WithRSA" +#define NID_sha1WithRSA 115 +#define OBJ_sha1WithRSA OBJ_algorithm,29L + +#define SN_ripemd160 "RIPEMD160" +#define LN_ripemd160 "ripemd160" +#define NID_ripemd160 117 +#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L + +#define SN_ripemd160WithRSA "RSA-RIPEMD160" +#define LN_ripemd160WithRSA "ripemd160WithRSA" +#define NID_ripemd160WithRSA 119 +#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L + +#define SN_sxnet "SXNetID" +#define LN_sxnet "Strong Extranet ID" +#define NID_sxnet 143 +#define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +#define SN_X500 "X500" +#define LN_X500 "directory services (X.500)" +#define NID_X500 11 +#define OBJ_X500 2L,5L + +#define SN_X509 "X509" +#define NID_X509 12 +#define OBJ_X509 OBJ_X500,4L + +#define SN_commonName "CN" +#define LN_commonName "commonName" +#define NID_commonName 13 +#define OBJ_commonName OBJ_X509,3L + +#define SN_surname "SN" +#define LN_surname "surname" +#define NID_surname 100 +#define OBJ_surname OBJ_X509,4L + +#define LN_serialNumber "serialNumber" +#define NID_serialNumber 105 +#define OBJ_serialNumber OBJ_X509,5L + +#define SN_countryName "C" +#define LN_countryName "countryName" +#define NID_countryName 14 +#define OBJ_countryName OBJ_X509,6L + +#define SN_localityName "L" +#define LN_localityName "localityName" +#define NID_localityName 15 +#define OBJ_localityName OBJ_X509,7L + +#define SN_stateOrProvinceName "ST" +#define LN_stateOrProvinceName "stateOrProvinceName" +#define NID_stateOrProvinceName 16 +#define OBJ_stateOrProvinceName OBJ_X509,8L + +#define LN_streetAddress "streetAddress" +#define NID_streetAddress 660 +#define OBJ_streetAddress OBJ_X509,9L + +#define SN_organizationName "O" +#define LN_organizationName "organizationName" +#define NID_organizationName 17 +#define OBJ_organizationName OBJ_X509,10L + +#define SN_organizationalUnitName "OU" +#define LN_organizationalUnitName "organizationalUnitName" +#define NID_organizationalUnitName 18 +#define OBJ_organizationalUnitName OBJ_X509,11L + +#define LN_title "title" +#define NID_title 106 +#define OBJ_title OBJ_X509,12L + +#define LN_description "description" +#define NID_description 107 +#define OBJ_description OBJ_X509,13L + +#define LN_postalCode "postalCode" +#define NID_postalCode 661 +#define OBJ_postalCode OBJ_X509,17L + +#define SN_name "name" +#define LN_name "name" +#define NID_name 173 +#define OBJ_name OBJ_X509,41L + +#define SN_givenName "GN" +#define LN_givenName "givenName" +#define NID_givenName 99 +#define OBJ_givenName OBJ_X509,42L + +#define LN_initials "initials" +#define NID_initials 101 +#define OBJ_initials OBJ_X509,43L + +#define LN_generationQualifier "generationQualifier" +#define NID_generationQualifier 509 +#define OBJ_generationQualifier OBJ_X509,44L + +#define LN_x500UniqueIdentifier "x500UniqueIdentifier" +#define NID_x500UniqueIdentifier 503 +#define OBJ_x500UniqueIdentifier OBJ_X509,45L + +#define SN_dnQualifier "dnQualifier" +#define LN_dnQualifier "dnQualifier" +#define NID_dnQualifier 174 +#define OBJ_dnQualifier OBJ_X509,46L + +#define LN_pseudonym "pseudonym" +#define NID_pseudonym 510 +#define OBJ_pseudonym OBJ_X509,65L + +#define SN_role "role" +#define LN_role "role" +#define NID_role 400 +#define OBJ_role OBJ_X509,72L + +#define SN_X500algorithms "X500algorithms" +#define LN_X500algorithms "directory services - algorithms" +#define NID_X500algorithms 378 +#define OBJ_X500algorithms OBJ_X500,8L + +#define SN_rsa "RSA" +#define LN_rsa "rsa" +#define NID_rsa 19 +#define OBJ_rsa OBJ_X500algorithms,1L,1L + +#define SN_mdc2WithRSA "RSA-MDC2" +#define LN_mdc2WithRSA "mdc2WithRSA" +#define NID_mdc2WithRSA 96 +#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L + +#define SN_mdc2 "MDC2" +#define LN_mdc2 "mdc2" +#define NID_mdc2 95 +#define OBJ_mdc2 OBJ_X500algorithms,3L,101L + +#define SN_id_ce "id-ce" +#define NID_id_ce 81 +#define OBJ_id_ce OBJ_X500,29L + +#define SN_subject_directory_attributes "subjectDirectoryAttributes" +#define LN_subject_directory_attributes "X509v3 Subject Directory Attributes" +#define NID_subject_directory_attributes 769 +#define OBJ_subject_directory_attributes OBJ_id_ce,9L + +#define SN_subject_key_identifier "subjectKeyIdentifier" +#define LN_subject_key_identifier "X509v3 Subject Key Identifier" +#define NID_subject_key_identifier 82 +#define OBJ_subject_key_identifier OBJ_id_ce,14L + +#define SN_key_usage "keyUsage" +#define LN_key_usage "X509v3 Key Usage" +#define NID_key_usage 83 +#define OBJ_key_usage OBJ_id_ce,15L + +#define SN_private_key_usage_period "privateKeyUsagePeriod" +#define LN_private_key_usage_period "X509v3 Private Key Usage Period" +#define NID_private_key_usage_period 84 +#define OBJ_private_key_usage_period OBJ_id_ce,16L + +#define SN_subject_alt_name "subjectAltName" +#define LN_subject_alt_name "X509v3 Subject Alternative Name" +#define NID_subject_alt_name 85 +#define OBJ_subject_alt_name OBJ_id_ce,17L + +#define SN_issuer_alt_name "issuerAltName" +#define LN_issuer_alt_name "X509v3 Issuer Alternative Name" +#define NID_issuer_alt_name 86 +#define OBJ_issuer_alt_name OBJ_id_ce,18L + +#define SN_basic_constraints "basicConstraints" +#define LN_basic_constraints "X509v3 Basic Constraints" +#define NID_basic_constraints 87 +#define OBJ_basic_constraints OBJ_id_ce,19L + +#define SN_crl_number "crlNumber" +#define LN_crl_number "X509v3 CRL Number" +#define NID_crl_number 88 +#define OBJ_crl_number OBJ_id_ce,20L + +#define SN_crl_reason "CRLReason" +#define LN_crl_reason "X509v3 CRL Reason Code" +#define NID_crl_reason 141 +#define OBJ_crl_reason OBJ_id_ce,21L + +#define SN_invalidity_date "invalidityDate" +#define LN_invalidity_date "Invalidity Date" +#define NID_invalidity_date 142 +#define OBJ_invalidity_date OBJ_id_ce,24L + +#define SN_delta_crl "deltaCRL" +#define LN_delta_crl "X509v3 Delta CRL Indicator" +#define NID_delta_crl 140 +#define OBJ_delta_crl OBJ_id_ce,27L + +#define SN_issuing_distribution_point "issuingDistributionPoint" +#define LN_issuing_distribution_point "X509v3 Issuing Distrubution Point" +#define NID_issuing_distribution_point 770 +#define OBJ_issuing_distribution_point OBJ_id_ce,28L + +#define SN_certificate_issuer "certificateIssuer" +#define LN_certificate_issuer "X509v3 Certificate Issuer" +#define NID_certificate_issuer 771 +#define OBJ_certificate_issuer OBJ_id_ce,29L + +#define SN_name_constraints "nameConstraints" +#define LN_name_constraints "X509v3 Name Constraints" +#define NID_name_constraints 666 +#define OBJ_name_constraints OBJ_id_ce,30L + +#define SN_crl_distribution_points "crlDistributionPoints" +#define LN_crl_distribution_points "X509v3 CRL Distribution Points" +#define NID_crl_distribution_points 103 +#define OBJ_crl_distribution_points OBJ_id_ce,31L + +#define SN_certificate_policies "certificatePolicies" +#define LN_certificate_policies "X509v3 Certificate Policies" +#define NID_certificate_policies 89 +#define OBJ_certificate_policies OBJ_id_ce,32L + +#define SN_any_policy "anyPolicy" +#define LN_any_policy "X509v3 Any Policy" +#define NID_any_policy 746 +#define OBJ_any_policy OBJ_certificate_policies,0L + +#define SN_policy_mappings "policyMappings" +#define LN_policy_mappings "X509v3 Policy Mappings" +#define NID_policy_mappings 747 +#define OBJ_policy_mappings OBJ_id_ce,33L + +#define SN_authority_key_identifier "authorityKeyIdentifier" +#define LN_authority_key_identifier "X509v3 Authority Key Identifier" +#define NID_authority_key_identifier 90 +#define OBJ_authority_key_identifier OBJ_id_ce,35L + +#define SN_policy_constraints "policyConstraints" +#define LN_policy_constraints "X509v3 Policy Constraints" +#define NID_policy_constraints 401 +#define OBJ_policy_constraints OBJ_id_ce,36L + +#define SN_ext_key_usage "extendedKeyUsage" +#define LN_ext_key_usage "X509v3 Extended Key Usage" +#define NID_ext_key_usage 126 +#define OBJ_ext_key_usage OBJ_id_ce,37L + +#define SN_freshest_crl "freshestCRL" +#define LN_freshest_crl "X509v3 Freshest CRL" +#define NID_freshest_crl 857 +#define OBJ_freshest_crl OBJ_id_ce,46L + +#define SN_inhibit_any_policy "inhibitAnyPolicy" +#define LN_inhibit_any_policy "X509v3 Inhibit Any Policy" +#define NID_inhibit_any_policy 748 +#define OBJ_inhibit_any_policy OBJ_id_ce,54L + +#define SN_target_information "targetInformation" +#define LN_target_information "X509v3 AC Targeting" +#define NID_target_information 402 +#define OBJ_target_information OBJ_id_ce,55L + +#define SN_no_rev_avail "noRevAvail" +#define LN_no_rev_avail "X509v3 No Revocation Available" +#define NID_no_rev_avail 403 +#define OBJ_no_rev_avail OBJ_id_ce,56L + +#define SN_netscape "Netscape" +#define LN_netscape "Netscape Communications Corp." +#define NID_netscape 57 +#define OBJ_netscape 2L,16L,840L,1L,113730L + +#define SN_netscape_cert_extension "nsCertExt" +#define LN_netscape_cert_extension "Netscape Certificate Extension" +#define NID_netscape_cert_extension 58 +#define OBJ_netscape_cert_extension OBJ_netscape,1L + +#define SN_netscape_data_type "nsDataType" +#define LN_netscape_data_type "Netscape Data Type" +#define NID_netscape_data_type 59 +#define OBJ_netscape_data_type OBJ_netscape,2L + +#define SN_netscape_cert_type "nsCertType" +#define LN_netscape_cert_type "Netscape Cert Type" +#define NID_netscape_cert_type 71 +#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L + +#define SN_netscape_base_url "nsBaseUrl" +#define LN_netscape_base_url "Netscape Base Url" +#define NID_netscape_base_url 72 +#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L + +#define SN_netscape_revocation_url "nsRevocationUrl" +#define LN_netscape_revocation_url "Netscape Revocation Url" +#define NID_netscape_revocation_url 73 +#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L + +#define SN_netscape_ca_revocation_url "nsCaRevocationUrl" +#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" +#define NID_netscape_ca_revocation_url 74 +#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L + +#define SN_netscape_renewal_url "nsRenewalUrl" +#define LN_netscape_renewal_url "Netscape Renewal Url" +#define NID_netscape_renewal_url 75 +#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L + +#define SN_netscape_ca_policy_url "nsCaPolicyUrl" +#define LN_netscape_ca_policy_url "Netscape CA Policy Url" +#define NID_netscape_ca_policy_url 76 +#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L + +#define SN_netscape_ssl_server_name "nsSslServerName" +#define LN_netscape_ssl_server_name "Netscape SSL Server Name" +#define NID_netscape_ssl_server_name 77 +#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L + +#define SN_netscape_comment "nsComment" +#define LN_netscape_comment "Netscape Comment" +#define NID_netscape_comment 78 +#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L + +#define SN_netscape_cert_sequence "nsCertSequence" +#define LN_netscape_cert_sequence "Netscape Certificate Sequence" +#define NID_netscape_cert_sequence 79 +#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L + +#define SN_ns_sgc "nsSGC" +#define LN_ns_sgc "Netscape Server Gated Crypto" +#define NID_ns_sgc 139 +#define OBJ_ns_sgc OBJ_netscape,4L,1L + +#define SN_org "ORG" +#define LN_org "org" +#define NID_org 379 +#define OBJ_org OBJ_iso,3L + +#define SN_dod "DOD" +#define LN_dod "dod" +#define NID_dod 380 +#define OBJ_dod OBJ_org,6L + +#define SN_iana "IANA" +#define LN_iana "iana" +#define NID_iana 381 +#define OBJ_iana OBJ_dod,1L + +#define OBJ_internet OBJ_iana + +#define SN_Directory "directory" +#define LN_Directory "Directory" +#define NID_Directory 382 +#define OBJ_Directory OBJ_internet,1L + +#define SN_Management "mgmt" +#define LN_Management "Management" +#define NID_Management 383 +#define OBJ_Management OBJ_internet,2L + +#define SN_Experimental "experimental" +#define LN_Experimental "Experimental" +#define NID_Experimental 384 +#define OBJ_Experimental OBJ_internet,3L + +#define SN_Private "private" +#define LN_Private "Private" +#define NID_Private 385 +#define OBJ_Private OBJ_internet,4L + +#define SN_Security "security" +#define LN_Security "Security" +#define NID_Security 386 +#define OBJ_Security OBJ_internet,5L + +#define SN_SNMPv2 "snmpv2" +#define LN_SNMPv2 "SNMPv2" +#define NID_SNMPv2 387 +#define OBJ_SNMPv2 OBJ_internet,6L + +#define LN_Mail "Mail" +#define NID_Mail 388 +#define OBJ_Mail OBJ_internet,7L + +#define SN_Enterprises "enterprises" +#define LN_Enterprises "Enterprises" +#define NID_Enterprises 389 +#define OBJ_Enterprises OBJ_Private,1L + +#define SN_dcObject "dcobject" +#define LN_dcObject "dcObject" +#define NID_dcObject 390 +#define OBJ_dcObject OBJ_Enterprises,1466L,344L + +#define SN_mime_mhs "mime-mhs" +#define LN_mime_mhs "MIME MHS" +#define NID_mime_mhs 504 +#define OBJ_mime_mhs OBJ_Mail,1L + +#define SN_mime_mhs_headings "mime-mhs-headings" +#define LN_mime_mhs_headings "mime-mhs-headings" +#define NID_mime_mhs_headings 505 +#define OBJ_mime_mhs_headings OBJ_mime_mhs,1L + +#define SN_mime_mhs_bodies "mime-mhs-bodies" +#define LN_mime_mhs_bodies "mime-mhs-bodies" +#define NID_mime_mhs_bodies 506 +#define OBJ_mime_mhs_bodies OBJ_mime_mhs,2L + +#define SN_id_hex_partial_message "id-hex-partial-message" +#define LN_id_hex_partial_message "id-hex-partial-message" +#define NID_id_hex_partial_message 507 +#define OBJ_id_hex_partial_message OBJ_mime_mhs_headings,1L + +#define SN_id_hex_multipart_message "id-hex-multipart-message" +#define LN_id_hex_multipart_message "id-hex-multipart-message" +#define NID_id_hex_multipart_message 508 +#define OBJ_id_hex_multipart_message OBJ_mime_mhs_headings,2L + +#define SN_rle_compression "RLE" +#define LN_rle_compression "run length compression" +#define NID_rle_compression 124 +#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L + +#define SN_zlib_compression "ZLIB" +#define LN_zlib_compression "zlib compression" +#define NID_zlib_compression 125 +#define OBJ_zlib_compression OBJ_id_smime_alg,8L + +#define OBJ_csor 2L,16L,840L,1L,101L,3L + +#define OBJ_nistAlgorithms OBJ_csor,4L + +#define OBJ_aes OBJ_nistAlgorithms,1L + +#define SN_aes_128_ecb "AES-128-ECB" +#define LN_aes_128_ecb "aes-128-ecb" +#define NID_aes_128_ecb 418 +#define OBJ_aes_128_ecb OBJ_aes,1L + +#define SN_aes_128_cbc "AES-128-CBC" +#define LN_aes_128_cbc "aes-128-cbc" +#define NID_aes_128_cbc 419 +#define OBJ_aes_128_cbc OBJ_aes,2L + +#define SN_aes_128_ofb128 "AES-128-OFB" +#define LN_aes_128_ofb128 "aes-128-ofb" +#define NID_aes_128_ofb128 420 +#define OBJ_aes_128_ofb128 OBJ_aes,3L + +#define SN_aes_128_cfb128 "AES-128-CFB" +#define LN_aes_128_cfb128 "aes-128-cfb" +#define NID_aes_128_cfb128 421 +#define OBJ_aes_128_cfb128 OBJ_aes,4L + +#define SN_aes_192_ecb "AES-192-ECB" +#define LN_aes_192_ecb "aes-192-ecb" +#define NID_aes_192_ecb 422 +#define OBJ_aes_192_ecb OBJ_aes,21L + +#define SN_aes_192_cbc "AES-192-CBC" +#define LN_aes_192_cbc "aes-192-cbc" +#define NID_aes_192_cbc 423 +#define OBJ_aes_192_cbc OBJ_aes,22L + +#define SN_aes_192_ofb128 "AES-192-OFB" +#define LN_aes_192_ofb128 "aes-192-ofb" +#define NID_aes_192_ofb128 424 +#define OBJ_aes_192_ofb128 OBJ_aes,23L + +#define SN_aes_192_cfb128 "AES-192-CFB" +#define LN_aes_192_cfb128 "aes-192-cfb" +#define NID_aes_192_cfb128 425 +#define OBJ_aes_192_cfb128 OBJ_aes,24L + +#define SN_aes_256_ecb "AES-256-ECB" +#define LN_aes_256_ecb "aes-256-ecb" +#define NID_aes_256_ecb 426 +#define OBJ_aes_256_ecb OBJ_aes,41L + +#define SN_aes_256_cbc "AES-256-CBC" +#define LN_aes_256_cbc "aes-256-cbc" +#define NID_aes_256_cbc 427 +#define OBJ_aes_256_cbc OBJ_aes,42L + +#define SN_aes_256_ofb128 "AES-256-OFB" +#define LN_aes_256_ofb128 "aes-256-ofb" +#define NID_aes_256_ofb128 428 +#define OBJ_aes_256_ofb128 OBJ_aes,43L + +#define SN_aes_256_cfb128 "AES-256-CFB" +#define LN_aes_256_cfb128 "aes-256-cfb" +#define NID_aes_256_cfb128 429 +#define OBJ_aes_256_cfb128 OBJ_aes,44L + +#define SN_aes_128_cfb1 "AES-128-CFB1" +#define LN_aes_128_cfb1 "aes-128-cfb1" +#define NID_aes_128_cfb1 650 + +#define SN_aes_192_cfb1 "AES-192-CFB1" +#define LN_aes_192_cfb1 "aes-192-cfb1" +#define NID_aes_192_cfb1 651 + +#define SN_aes_256_cfb1 "AES-256-CFB1" +#define LN_aes_256_cfb1 "aes-256-cfb1" +#define NID_aes_256_cfb1 652 + +#define SN_aes_128_cfb8 "AES-128-CFB8" +#define LN_aes_128_cfb8 "aes-128-cfb8" +#define NID_aes_128_cfb8 653 + +#define SN_aes_192_cfb8 "AES-192-CFB8" +#define LN_aes_192_cfb8 "aes-192-cfb8" +#define NID_aes_192_cfb8 654 + +#define SN_aes_256_cfb8 "AES-256-CFB8" +#define LN_aes_256_cfb8 "aes-256-cfb8" +#define NID_aes_256_cfb8 655 + +#define SN_des_cfb1 "DES-CFB1" +#define LN_des_cfb1 "des-cfb1" +#define NID_des_cfb1 656 + +#define SN_des_cfb8 "DES-CFB8" +#define LN_des_cfb8 "des-cfb8" +#define NID_des_cfb8 657 + +#define SN_des_ede3_cfb1 "DES-EDE3-CFB1" +#define LN_des_ede3_cfb1 "des-ede3-cfb1" +#define NID_des_ede3_cfb1 658 + +#define SN_des_ede3_cfb8 "DES-EDE3-CFB8" +#define LN_des_ede3_cfb8 "des-ede3-cfb8" +#define NID_des_ede3_cfb8 659 + +#define SN_id_aes128_wrap "id-aes128-wrap" +#define NID_id_aes128_wrap 788 +#define OBJ_id_aes128_wrap OBJ_aes,5L + +#define SN_id_aes192_wrap "id-aes192-wrap" +#define NID_id_aes192_wrap 789 +#define OBJ_id_aes192_wrap OBJ_aes,25L + +#define SN_id_aes256_wrap "id-aes256-wrap" +#define NID_id_aes256_wrap 790 +#define OBJ_id_aes256_wrap OBJ_aes,45L + +#define OBJ_nist_hashalgs OBJ_nistAlgorithms,2L + +#define SN_sha256 "SHA256" +#define LN_sha256 "sha256" +#define NID_sha256 672 +#define OBJ_sha256 OBJ_nist_hashalgs,1L + +#define SN_sha384 "SHA384" +#define LN_sha384 "sha384" +#define NID_sha384 673 +#define OBJ_sha384 OBJ_nist_hashalgs,2L + +#define SN_sha512 "SHA512" +#define LN_sha512 "sha512" +#define NID_sha512 674 +#define OBJ_sha512 OBJ_nist_hashalgs,3L + +#define SN_sha224 "SHA224" +#define LN_sha224 "sha224" +#define NID_sha224 675 +#define OBJ_sha224 OBJ_nist_hashalgs,4L + +#define OBJ_dsa_with_sha2 OBJ_nistAlgorithms,3L + +#define SN_dsa_with_SHA224 "dsa_with_SHA224" +#define NID_dsa_with_SHA224 802 +#define OBJ_dsa_with_SHA224 OBJ_dsa_with_sha2,1L + +#define SN_dsa_with_SHA256 "dsa_with_SHA256" +#define NID_dsa_with_SHA256 803 +#define OBJ_dsa_with_SHA256 OBJ_dsa_with_sha2,2L + +#define SN_hold_instruction_code "holdInstructionCode" +#define LN_hold_instruction_code "Hold Instruction Code" +#define NID_hold_instruction_code 430 +#define OBJ_hold_instruction_code OBJ_id_ce,23L + +#define OBJ_holdInstruction OBJ_X9_57,2L + +#define SN_hold_instruction_none "holdInstructionNone" +#define LN_hold_instruction_none "Hold Instruction None" +#define NID_hold_instruction_none 431 +#define OBJ_hold_instruction_none OBJ_holdInstruction,1L + +#define SN_hold_instruction_call_issuer "holdInstructionCallIssuer" +#define LN_hold_instruction_call_issuer "Hold Instruction Call Issuer" +#define NID_hold_instruction_call_issuer 432 +#define OBJ_hold_instruction_call_issuer OBJ_holdInstruction,2L + +#define SN_hold_instruction_reject "holdInstructionReject" +#define LN_hold_instruction_reject "Hold Instruction Reject" +#define NID_hold_instruction_reject 433 +#define OBJ_hold_instruction_reject OBJ_holdInstruction,3L + +#define SN_data "data" +#define NID_data 434 +#define OBJ_data OBJ_itu_t,9L + +#define SN_pss "pss" +#define NID_pss 435 +#define OBJ_pss OBJ_data,2342L + +#define SN_ucl "ucl" +#define NID_ucl 436 +#define OBJ_ucl OBJ_pss,19200300L + +#define SN_pilot "pilot" +#define NID_pilot 437 +#define OBJ_pilot OBJ_ucl,100L + +#define LN_pilotAttributeType "pilotAttributeType" +#define NID_pilotAttributeType 438 +#define OBJ_pilotAttributeType OBJ_pilot,1L + +#define LN_pilotAttributeSyntax "pilotAttributeSyntax" +#define NID_pilotAttributeSyntax 439 +#define OBJ_pilotAttributeSyntax OBJ_pilot,3L + +#define LN_pilotObjectClass "pilotObjectClass" +#define NID_pilotObjectClass 440 +#define OBJ_pilotObjectClass OBJ_pilot,4L + +#define LN_pilotGroups "pilotGroups" +#define NID_pilotGroups 441 +#define OBJ_pilotGroups OBJ_pilot,10L + +#define LN_iA5StringSyntax "iA5StringSyntax" +#define NID_iA5StringSyntax 442 +#define OBJ_iA5StringSyntax OBJ_pilotAttributeSyntax,4L + +#define LN_caseIgnoreIA5StringSyntax "caseIgnoreIA5StringSyntax" +#define NID_caseIgnoreIA5StringSyntax 443 +#define OBJ_caseIgnoreIA5StringSyntax OBJ_pilotAttributeSyntax,5L + +#define LN_pilotObject "pilotObject" +#define NID_pilotObject 444 +#define OBJ_pilotObject OBJ_pilotObjectClass,3L + +#define LN_pilotPerson "pilotPerson" +#define NID_pilotPerson 445 +#define OBJ_pilotPerson OBJ_pilotObjectClass,4L + +#define SN_account "account" +#define NID_account 446 +#define OBJ_account OBJ_pilotObjectClass,5L + +#define SN_document "document" +#define NID_document 447 +#define OBJ_document OBJ_pilotObjectClass,6L + +#define SN_room "room" +#define NID_room 448 +#define OBJ_room OBJ_pilotObjectClass,7L + +#define LN_documentSeries "documentSeries" +#define NID_documentSeries 449 +#define OBJ_documentSeries OBJ_pilotObjectClass,9L + +#define SN_Domain "domain" +#define LN_Domain "Domain" +#define NID_Domain 392 +#define OBJ_Domain OBJ_pilotObjectClass,13L + +#define LN_rFC822localPart "rFC822localPart" +#define NID_rFC822localPart 450 +#define OBJ_rFC822localPart OBJ_pilotObjectClass,14L + +#define LN_dNSDomain "dNSDomain" +#define NID_dNSDomain 451 +#define OBJ_dNSDomain OBJ_pilotObjectClass,15L + +#define LN_domainRelatedObject "domainRelatedObject" +#define NID_domainRelatedObject 452 +#define OBJ_domainRelatedObject OBJ_pilotObjectClass,17L + +#define LN_friendlyCountry "friendlyCountry" +#define NID_friendlyCountry 453 +#define OBJ_friendlyCountry OBJ_pilotObjectClass,18L + +#define LN_simpleSecurityObject "simpleSecurityObject" +#define NID_simpleSecurityObject 454 +#define OBJ_simpleSecurityObject OBJ_pilotObjectClass,19L + +#define LN_pilotOrganization "pilotOrganization" +#define NID_pilotOrganization 455 +#define OBJ_pilotOrganization OBJ_pilotObjectClass,20L + +#define LN_pilotDSA "pilotDSA" +#define NID_pilotDSA 456 +#define OBJ_pilotDSA OBJ_pilotObjectClass,21L + +#define LN_qualityLabelledData "qualityLabelledData" +#define NID_qualityLabelledData 457 +#define OBJ_qualityLabelledData OBJ_pilotObjectClass,22L + +#define SN_userId "UID" +#define LN_userId "userId" +#define NID_userId 458 +#define OBJ_userId OBJ_pilotAttributeType,1L + +#define LN_textEncodedORAddress "textEncodedORAddress" +#define NID_textEncodedORAddress 459 +#define OBJ_textEncodedORAddress OBJ_pilotAttributeType,2L + +#define SN_rfc822Mailbox "mail" +#define LN_rfc822Mailbox "rfc822Mailbox" +#define NID_rfc822Mailbox 460 +#define OBJ_rfc822Mailbox OBJ_pilotAttributeType,3L + +#define SN_info "info" +#define NID_info 461 +#define OBJ_info OBJ_pilotAttributeType,4L + +#define LN_favouriteDrink "favouriteDrink" +#define NID_favouriteDrink 462 +#define OBJ_favouriteDrink OBJ_pilotAttributeType,5L + +#define LN_roomNumber "roomNumber" +#define NID_roomNumber 463 +#define OBJ_roomNumber OBJ_pilotAttributeType,6L + +#define SN_photo "photo" +#define NID_photo 464 +#define OBJ_photo OBJ_pilotAttributeType,7L + +#define LN_userClass "userClass" +#define NID_userClass 465 +#define OBJ_userClass OBJ_pilotAttributeType,8L + +#define SN_host "host" +#define NID_host 466 +#define OBJ_host OBJ_pilotAttributeType,9L + +#define SN_manager "manager" +#define NID_manager 467 +#define OBJ_manager OBJ_pilotAttributeType,10L + +#define LN_documentIdentifier "documentIdentifier" +#define NID_documentIdentifier 468 +#define OBJ_documentIdentifier OBJ_pilotAttributeType,11L + +#define LN_documentTitle "documentTitle" +#define NID_documentTitle 469 +#define OBJ_documentTitle OBJ_pilotAttributeType,12L + +#define LN_documentVersion "documentVersion" +#define NID_documentVersion 470 +#define OBJ_documentVersion OBJ_pilotAttributeType,13L + +#define LN_documentAuthor "documentAuthor" +#define NID_documentAuthor 471 +#define OBJ_documentAuthor OBJ_pilotAttributeType,14L + +#define LN_documentLocation "documentLocation" +#define NID_documentLocation 472 +#define OBJ_documentLocation OBJ_pilotAttributeType,15L + +#define LN_homeTelephoneNumber "homeTelephoneNumber" +#define NID_homeTelephoneNumber 473 +#define OBJ_homeTelephoneNumber OBJ_pilotAttributeType,20L + +#define SN_secretary "secretary" +#define NID_secretary 474 +#define OBJ_secretary OBJ_pilotAttributeType,21L + +#define LN_otherMailbox "otherMailbox" +#define NID_otherMailbox 475 +#define OBJ_otherMailbox OBJ_pilotAttributeType,22L + +#define LN_lastModifiedTime "lastModifiedTime" +#define NID_lastModifiedTime 476 +#define OBJ_lastModifiedTime OBJ_pilotAttributeType,23L + +#define LN_lastModifiedBy "lastModifiedBy" +#define NID_lastModifiedBy 477 +#define OBJ_lastModifiedBy OBJ_pilotAttributeType,24L + +#define SN_domainComponent "DC" +#define LN_domainComponent "domainComponent" +#define NID_domainComponent 391 +#define OBJ_domainComponent OBJ_pilotAttributeType,25L + +#define LN_aRecord "aRecord" +#define NID_aRecord 478 +#define OBJ_aRecord OBJ_pilotAttributeType,26L + +#define LN_pilotAttributeType27 "pilotAttributeType27" +#define NID_pilotAttributeType27 479 +#define OBJ_pilotAttributeType27 OBJ_pilotAttributeType,27L + +#define LN_mXRecord "mXRecord" +#define NID_mXRecord 480 +#define OBJ_mXRecord OBJ_pilotAttributeType,28L + +#define LN_nSRecord "nSRecord" +#define NID_nSRecord 481 +#define OBJ_nSRecord OBJ_pilotAttributeType,29L + +#define LN_sOARecord "sOARecord" +#define NID_sOARecord 482 +#define OBJ_sOARecord OBJ_pilotAttributeType,30L + +#define LN_cNAMERecord "cNAMERecord" +#define NID_cNAMERecord 483 +#define OBJ_cNAMERecord OBJ_pilotAttributeType,31L + +#define LN_associatedDomain "associatedDomain" +#define NID_associatedDomain 484 +#define OBJ_associatedDomain OBJ_pilotAttributeType,37L + +#define LN_associatedName "associatedName" +#define NID_associatedName 485 +#define OBJ_associatedName OBJ_pilotAttributeType,38L + +#define LN_homePostalAddress "homePostalAddress" +#define NID_homePostalAddress 486 +#define OBJ_homePostalAddress OBJ_pilotAttributeType,39L + +#define LN_personalTitle "personalTitle" +#define NID_personalTitle 487 +#define OBJ_personalTitle OBJ_pilotAttributeType,40L + +#define LN_mobileTelephoneNumber "mobileTelephoneNumber" +#define NID_mobileTelephoneNumber 488 +#define OBJ_mobileTelephoneNumber OBJ_pilotAttributeType,41L + +#define LN_pagerTelephoneNumber "pagerTelephoneNumber" +#define NID_pagerTelephoneNumber 489 +#define OBJ_pagerTelephoneNumber OBJ_pilotAttributeType,42L + +#define LN_friendlyCountryName "friendlyCountryName" +#define NID_friendlyCountryName 490 +#define OBJ_friendlyCountryName OBJ_pilotAttributeType,43L + +#define LN_organizationalStatus "organizationalStatus" +#define NID_organizationalStatus 491 +#define OBJ_organizationalStatus OBJ_pilotAttributeType,45L + +#define LN_janetMailbox "janetMailbox" +#define NID_janetMailbox 492 +#define OBJ_janetMailbox OBJ_pilotAttributeType,46L + +#define LN_mailPreferenceOption "mailPreferenceOption" +#define NID_mailPreferenceOption 493 +#define OBJ_mailPreferenceOption OBJ_pilotAttributeType,47L + +#define LN_buildingName "buildingName" +#define NID_buildingName 494 +#define OBJ_buildingName OBJ_pilotAttributeType,48L + +#define LN_dSAQuality "dSAQuality" +#define NID_dSAQuality 495 +#define OBJ_dSAQuality OBJ_pilotAttributeType,49L + +#define LN_singleLevelQuality "singleLevelQuality" +#define NID_singleLevelQuality 496 +#define OBJ_singleLevelQuality OBJ_pilotAttributeType,50L + +#define LN_subtreeMinimumQuality "subtreeMinimumQuality" +#define NID_subtreeMinimumQuality 497 +#define OBJ_subtreeMinimumQuality OBJ_pilotAttributeType,51L + +#define LN_subtreeMaximumQuality "subtreeMaximumQuality" +#define NID_subtreeMaximumQuality 498 +#define OBJ_subtreeMaximumQuality OBJ_pilotAttributeType,52L + +#define LN_personalSignature "personalSignature" +#define NID_personalSignature 499 +#define OBJ_personalSignature OBJ_pilotAttributeType,53L + +#define LN_dITRedirect "dITRedirect" +#define NID_dITRedirect 500 +#define OBJ_dITRedirect OBJ_pilotAttributeType,54L + +#define SN_audio "audio" +#define NID_audio 501 +#define OBJ_audio OBJ_pilotAttributeType,55L + +#define LN_documentPublisher "documentPublisher" +#define NID_documentPublisher 502 +#define OBJ_documentPublisher OBJ_pilotAttributeType,56L + +#define SN_id_set "id-set" +#define LN_id_set "Secure Electronic Transactions" +#define NID_id_set 512 +#define OBJ_id_set OBJ_international_organizations,42L + +#define SN_set_ctype "set-ctype" +#define LN_set_ctype "content types" +#define NID_set_ctype 513 +#define OBJ_set_ctype OBJ_id_set,0L + +#define SN_set_msgExt "set-msgExt" +#define LN_set_msgExt "message extensions" +#define NID_set_msgExt 514 +#define OBJ_set_msgExt OBJ_id_set,1L + +#define SN_set_attr "set-attr" +#define NID_set_attr 515 +#define OBJ_set_attr OBJ_id_set,3L + +#define SN_set_policy "set-policy" +#define NID_set_policy 516 +#define OBJ_set_policy OBJ_id_set,5L + +#define SN_set_certExt "set-certExt" +#define LN_set_certExt "certificate extensions" +#define NID_set_certExt 517 +#define OBJ_set_certExt OBJ_id_set,7L + +#define SN_set_brand "set-brand" +#define NID_set_brand 518 +#define OBJ_set_brand OBJ_id_set,8L + +#define SN_setct_PANData "setct-PANData" +#define NID_setct_PANData 519 +#define OBJ_setct_PANData OBJ_set_ctype,0L + +#define SN_setct_PANToken "setct-PANToken" +#define NID_setct_PANToken 520 +#define OBJ_setct_PANToken OBJ_set_ctype,1L + +#define SN_setct_PANOnly "setct-PANOnly" +#define NID_setct_PANOnly 521 +#define OBJ_setct_PANOnly OBJ_set_ctype,2L + +#define SN_setct_OIData "setct-OIData" +#define NID_setct_OIData 522 +#define OBJ_setct_OIData OBJ_set_ctype,3L + +#define SN_setct_PI "setct-PI" +#define NID_setct_PI 523 +#define OBJ_setct_PI OBJ_set_ctype,4L + +#define SN_setct_PIData "setct-PIData" +#define NID_setct_PIData 524 +#define OBJ_setct_PIData OBJ_set_ctype,5L + +#define SN_setct_PIDataUnsigned "setct-PIDataUnsigned" +#define NID_setct_PIDataUnsigned 525 +#define OBJ_setct_PIDataUnsigned OBJ_set_ctype,6L + +#define SN_setct_HODInput "setct-HODInput" +#define NID_setct_HODInput 526 +#define OBJ_setct_HODInput OBJ_set_ctype,7L + +#define SN_setct_AuthResBaggage "setct-AuthResBaggage" +#define NID_setct_AuthResBaggage 527 +#define OBJ_setct_AuthResBaggage OBJ_set_ctype,8L + +#define SN_setct_AuthRevReqBaggage "setct-AuthRevReqBaggage" +#define NID_setct_AuthRevReqBaggage 528 +#define OBJ_setct_AuthRevReqBaggage OBJ_set_ctype,9L + +#define SN_setct_AuthRevResBaggage "setct-AuthRevResBaggage" +#define NID_setct_AuthRevResBaggage 529 +#define OBJ_setct_AuthRevResBaggage OBJ_set_ctype,10L + +#define SN_setct_CapTokenSeq "setct-CapTokenSeq" +#define NID_setct_CapTokenSeq 530 +#define OBJ_setct_CapTokenSeq OBJ_set_ctype,11L + +#define SN_setct_PInitResData "setct-PInitResData" +#define NID_setct_PInitResData 531 +#define OBJ_setct_PInitResData OBJ_set_ctype,12L + +#define SN_setct_PI_TBS "setct-PI-TBS" +#define NID_setct_PI_TBS 532 +#define OBJ_setct_PI_TBS OBJ_set_ctype,13L + +#define SN_setct_PResData "setct-PResData" +#define NID_setct_PResData 533 +#define OBJ_setct_PResData OBJ_set_ctype,14L + +#define SN_setct_AuthReqTBS "setct-AuthReqTBS" +#define NID_setct_AuthReqTBS 534 +#define OBJ_setct_AuthReqTBS OBJ_set_ctype,16L + +#define SN_setct_AuthResTBS "setct-AuthResTBS" +#define NID_setct_AuthResTBS 535 +#define OBJ_setct_AuthResTBS OBJ_set_ctype,17L + +#define SN_setct_AuthResTBSX "setct-AuthResTBSX" +#define NID_setct_AuthResTBSX 536 +#define OBJ_setct_AuthResTBSX OBJ_set_ctype,18L + +#define SN_setct_AuthTokenTBS "setct-AuthTokenTBS" +#define NID_setct_AuthTokenTBS 537 +#define OBJ_setct_AuthTokenTBS OBJ_set_ctype,19L + +#define SN_setct_CapTokenData "setct-CapTokenData" +#define NID_setct_CapTokenData 538 +#define OBJ_setct_CapTokenData OBJ_set_ctype,20L + +#define SN_setct_CapTokenTBS "setct-CapTokenTBS" +#define NID_setct_CapTokenTBS 539 +#define OBJ_setct_CapTokenTBS OBJ_set_ctype,21L + +#define SN_setct_AcqCardCodeMsg "setct-AcqCardCodeMsg" +#define NID_setct_AcqCardCodeMsg 540 +#define OBJ_setct_AcqCardCodeMsg OBJ_set_ctype,22L + +#define SN_setct_AuthRevReqTBS "setct-AuthRevReqTBS" +#define NID_setct_AuthRevReqTBS 541 +#define OBJ_setct_AuthRevReqTBS OBJ_set_ctype,23L + +#define SN_setct_AuthRevResData "setct-AuthRevResData" +#define NID_setct_AuthRevResData 542 +#define OBJ_setct_AuthRevResData OBJ_set_ctype,24L + +#define SN_setct_AuthRevResTBS "setct-AuthRevResTBS" +#define NID_setct_AuthRevResTBS 543 +#define OBJ_setct_AuthRevResTBS OBJ_set_ctype,25L + +#define SN_setct_CapReqTBS "setct-CapReqTBS" +#define NID_setct_CapReqTBS 544 +#define OBJ_setct_CapReqTBS OBJ_set_ctype,26L + +#define SN_setct_CapReqTBSX "setct-CapReqTBSX" +#define NID_setct_CapReqTBSX 545 +#define OBJ_setct_CapReqTBSX OBJ_set_ctype,27L + +#define SN_setct_CapResData "setct-CapResData" +#define NID_setct_CapResData 546 +#define OBJ_setct_CapResData OBJ_set_ctype,28L + +#define SN_setct_CapRevReqTBS "setct-CapRevReqTBS" +#define NID_setct_CapRevReqTBS 547 +#define OBJ_setct_CapRevReqTBS OBJ_set_ctype,29L + +#define SN_setct_CapRevReqTBSX "setct-CapRevReqTBSX" +#define NID_setct_CapRevReqTBSX 548 +#define OBJ_setct_CapRevReqTBSX OBJ_set_ctype,30L + +#define SN_setct_CapRevResData "setct-CapRevResData" +#define NID_setct_CapRevResData 549 +#define OBJ_setct_CapRevResData OBJ_set_ctype,31L + +#define SN_setct_CredReqTBS "setct-CredReqTBS" +#define NID_setct_CredReqTBS 550 +#define OBJ_setct_CredReqTBS OBJ_set_ctype,32L + +#define SN_setct_CredReqTBSX "setct-CredReqTBSX" +#define NID_setct_CredReqTBSX 551 +#define OBJ_setct_CredReqTBSX OBJ_set_ctype,33L + +#define SN_setct_CredResData "setct-CredResData" +#define NID_setct_CredResData 552 +#define OBJ_setct_CredResData OBJ_set_ctype,34L + +#define SN_setct_CredRevReqTBS "setct-CredRevReqTBS" +#define NID_setct_CredRevReqTBS 553 +#define OBJ_setct_CredRevReqTBS OBJ_set_ctype,35L + +#define SN_setct_CredRevReqTBSX "setct-CredRevReqTBSX" +#define NID_setct_CredRevReqTBSX 554 +#define OBJ_setct_CredRevReqTBSX OBJ_set_ctype,36L + +#define SN_setct_CredRevResData "setct-CredRevResData" +#define NID_setct_CredRevResData 555 +#define OBJ_setct_CredRevResData OBJ_set_ctype,37L + +#define SN_setct_PCertReqData "setct-PCertReqData" +#define NID_setct_PCertReqData 556 +#define OBJ_setct_PCertReqData OBJ_set_ctype,38L + +#define SN_setct_PCertResTBS "setct-PCertResTBS" +#define NID_setct_PCertResTBS 557 +#define OBJ_setct_PCertResTBS OBJ_set_ctype,39L + +#define SN_setct_BatchAdminReqData "setct-BatchAdminReqData" +#define NID_setct_BatchAdminReqData 558 +#define OBJ_setct_BatchAdminReqData OBJ_set_ctype,40L + +#define SN_setct_BatchAdminResData "setct-BatchAdminResData" +#define NID_setct_BatchAdminResData 559 +#define OBJ_setct_BatchAdminResData OBJ_set_ctype,41L + +#define SN_setct_CardCInitResTBS "setct-CardCInitResTBS" +#define NID_setct_CardCInitResTBS 560 +#define OBJ_setct_CardCInitResTBS OBJ_set_ctype,42L + +#define SN_setct_MeAqCInitResTBS "setct-MeAqCInitResTBS" +#define NID_setct_MeAqCInitResTBS 561 +#define OBJ_setct_MeAqCInitResTBS OBJ_set_ctype,43L + +#define SN_setct_RegFormResTBS "setct-RegFormResTBS" +#define NID_setct_RegFormResTBS 562 +#define OBJ_setct_RegFormResTBS OBJ_set_ctype,44L + +#define SN_setct_CertReqData "setct-CertReqData" +#define NID_setct_CertReqData 563 +#define OBJ_setct_CertReqData OBJ_set_ctype,45L + +#define SN_setct_CertReqTBS "setct-CertReqTBS" +#define NID_setct_CertReqTBS 564 +#define OBJ_setct_CertReqTBS OBJ_set_ctype,46L + +#define SN_setct_CertResData "setct-CertResData" +#define NID_setct_CertResData 565 +#define OBJ_setct_CertResData OBJ_set_ctype,47L + +#define SN_setct_CertInqReqTBS "setct-CertInqReqTBS" +#define NID_setct_CertInqReqTBS 566 +#define OBJ_setct_CertInqReqTBS OBJ_set_ctype,48L + +#define SN_setct_ErrorTBS "setct-ErrorTBS" +#define NID_setct_ErrorTBS 567 +#define OBJ_setct_ErrorTBS OBJ_set_ctype,49L + +#define SN_setct_PIDualSignedTBE "setct-PIDualSignedTBE" +#define NID_setct_PIDualSignedTBE 568 +#define OBJ_setct_PIDualSignedTBE OBJ_set_ctype,50L + +#define SN_setct_PIUnsignedTBE "setct-PIUnsignedTBE" +#define NID_setct_PIUnsignedTBE 569 +#define OBJ_setct_PIUnsignedTBE OBJ_set_ctype,51L + +#define SN_setct_AuthReqTBE "setct-AuthReqTBE" +#define NID_setct_AuthReqTBE 570 +#define OBJ_setct_AuthReqTBE OBJ_set_ctype,52L + +#define SN_setct_AuthResTBE "setct-AuthResTBE" +#define NID_setct_AuthResTBE 571 +#define OBJ_setct_AuthResTBE OBJ_set_ctype,53L + +#define SN_setct_AuthResTBEX "setct-AuthResTBEX" +#define NID_setct_AuthResTBEX 572 +#define OBJ_setct_AuthResTBEX OBJ_set_ctype,54L + +#define SN_setct_AuthTokenTBE "setct-AuthTokenTBE" +#define NID_setct_AuthTokenTBE 573 +#define OBJ_setct_AuthTokenTBE OBJ_set_ctype,55L + +#define SN_setct_CapTokenTBE "setct-CapTokenTBE" +#define NID_setct_CapTokenTBE 574 +#define OBJ_setct_CapTokenTBE OBJ_set_ctype,56L + +#define SN_setct_CapTokenTBEX "setct-CapTokenTBEX" +#define NID_setct_CapTokenTBEX 575 +#define OBJ_setct_CapTokenTBEX OBJ_set_ctype,57L + +#define SN_setct_AcqCardCodeMsgTBE "setct-AcqCardCodeMsgTBE" +#define NID_setct_AcqCardCodeMsgTBE 576 +#define OBJ_setct_AcqCardCodeMsgTBE OBJ_set_ctype,58L + +#define SN_setct_AuthRevReqTBE "setct-AuthRevReqTBE" +#define NID_setct_AuthRevReqTBE 577 +#define OBJ_setct_AuthRevReqTBE OBJ_set_ctype,59L + +#define SN_setct_AuthRevResTBE "setct-AuthRevResTBE" +#define NID_setct_AuthRevResTBE 578 +#define OBJ_setct_AuthRevResTBE OBJ_set_ctype,60L + +#define SN_setct_AuthRevResTBEB "setct-AuthRevResTBEB" +#define NID_setct_AuthRevResTBEB 579 +#define OBJ_setct_AuthRevResTBEB OBJ_set_ctype,61L + +#define SN_setct_CapReqTBE "setct-CapReqTBE" +#define NID_setct_CapReqTBE 580 +#define OBJ_setct_CapReqTBE OBJ_set_ctype,62L + +#define SN_setct_CapReqTBEX "setct-CapReqTBEX" +#define NID_setct_CapReqTBEX 581 +#define OBJ_setct_CapReqTBEX OBJ_set_ctype,63L + +#define SN_setct_CapResTBE "setct-CapResTBE" +#define NID_setct_CapResTBE 582 +#define OBJ_setct_CapResTBE OBJ_set_ctype,64L + +#define SN_setct_CapRevReqTBE "setct-CapRevReqTBE" +#define NID_setct_CapRevReqTBE 583 +#define OBJ_setct_CapRevReqTBE OBJ_set_ctype,65L + +#define SN_setct_CapRevReqTBEX "setct-CapRevReqTBEX" +#define NID_setct_CapRevReqTBEX 584 +#define OBJ_setct_CapRevReqTBEX OBJ_set_ctype,66L + +#define SN_setct_CapRevResTBE "setct-CapRevResTBE" +#define NID_setct_CapRevResTBE 585 +#define OBJ_setct_CapRevResTBE OBJ_set_ctype,67L + +#define SN_setct_CredReqTBE "setct-CredReqTBE" +#define NID_setct_CredReqTBE 586 +#define OBJ_setct_CredReqTBE OBJ_set_ctype,68L + +#define SN_setct_CredReqTBEX "setct-CredReqTBEX" +#define NID_setct_CredReqTBEX 587 +#define OBJ_setct_CredReqTBEX OBJ_set_ctype,69L + +#define SN_setct_CredResTBE "setct-CredResTBE" +#define NID_setct_CredResTBE 588 +#define OBJ_setct_CredResTBE OBJ_set_ctype,70L + +#define SN_setct_CredRevReqTBE "setct-CredRevReqTBE" +#define NID_setct_CredRevReqTBE 589 +#define OBJ_setct_CredRevReqTBE OBJ_set_ctype,71L + +#define SN_setct_CredRevReqTBEX "setct-CredRevReqTBEX" +#define NID_setct_CredRevReqTBEX 590 +#define OBJ_setct_CredRevReqTBEX OBJ_set_ctype,72L + +#define SN_setct_CredRevResTBE "setct-CredRevResTBE" +#define NID_setct_CredRevResTBE 591 +#define OBJ_setct_CredRevResTBE OBJ_set_ctype,73L + +#define SN_setct_BatchAdminReqTBE "setct-BatchAdminReqTBE" +#define NID_setct_BatchAdminReqTBE 592 +#define OBJ_setct_BatchAdminReqTBE OBJ_set_ctype,74L + +#define SN_setct_BatchAdminResTBE "setct-BatchAdminResTBE" +#define NID_setct_BatchAdminResTBE 593 +#define OBJ_setct_BatchAdminResTBE OBJ_set_ctype,75L + +#define SN_setct_RegFormReqTBE "setct-RegFormReqTBE" +#define NID_setct_RegFormReqTBE 594 +#define OBJ_setct_RegFormReqTBE OBJ_set_ctype,76L + +#define SN_setct_CertReqTBE "setct-CertReqTBE" +#define NID_setct_CertReqTBE 595 +#define OBJ_setct_CertReqTBE OBJ_set_ctype,77L + +#define SN_setct_CertReqTBEX "setct-CertReqTBEX" +#define NID_setct_CertReqTBEX 596 +#define OBJ_setct_CertReqTBEX OBJ_set_ctype,78L + +#define SN_setct_CertResTBE "setct-CertResTBE" +#define NID_setct_CertResTBE 597 +#define OBJ_setct_CertResTBE OBJ_set_ctype,79L + +#define SN_setct_CRLNotificationTBS "setct-CRLNotificationTBS" +#define NID_setct_CRLNotificationTBS 598 +#define OBJ_setct_CRLNotificationTBS OBJ_set_ctype,80L + +#define SN_setct_CRLNotificationResTBS "setct-CRLNotificationResTBS" +#define NID_setct_CRLNotificationResTBS 599 +#define OBJ_setct_CRLNotificationResTBS OBJ_set_ctype,81L + +#define SN_setct_BCIDistributionTBS "setct-BCIDistributionTBS" +#define NID_setct_BCIDistributionTBS 600 +#define OBJ_setct_BCIDistributionTBS OBJ_set_ctype,82L + +#define SN_setext_genCrypt "setext-genCrypt" +#define LN_setext_genCrypt "generic cryptogram" +#define NID_setext_genCrypt 601 +#define OBJ_setext_genCrypt OBJ_set_msgExt,1L + +#define SN_setext_miAuth "setext-miAuth" +#define LN_setext_miAuth "merchant initiated auth" +#define NID_setext_miAuth 602 +#define OBJ_setext_miAuth OBJ_set_msgExt,3L + +#define SN_setext_pinSecure "setext-pinSecure" +#define NID_setext_pinSecure 603 +#define OBJ_setext_pinSecure OBJ_set_msgExt,4L + +#define SN_setext_pinAny "setext-pinAny" +#define NID_setext_pinAny 604 +#define OBJ_setext_pinAny OBJ_set_msgExt,5L + +#define SN_setext_track2 "setext-track2" +#define NID_setext_track2 605 +#define OBJ_setext_track2 OBJ_set_msgExt,7L + +#define SN_setext_cv "setext-cv" +#define LN_setext_cv "additional verification" +#define NID_setext_cv 606 +#define OBJ_setext_cv OBJ_set_msgExt,8L + +#define SN_set_policy_root "set-policy-root" +#define NID_set_policy_root 607 +#define OBJ_set_policy_root OBJ_set_policy,0L + +#define SN_setCext_hashedRoot "setCext-hashedRoot" +#define NID_setCext_hashedRoot 608 +#define OBJ_setCext_hashedRoot OBJ_set_certExt,0L + +#define SN_setCext_certType "setCext-certType" +#define NID_setCext_certType 609 +#define OBJ_setCext_certType OBJ_set_certExt,1L + +#define SN_setCext_merchData "setCext-merchData" +#define NID_setCext_merchData 610 +#define OBJ_setCext_merchData OBJ_set_certExt,2L + +#define SN_setCext_cCertRequired "setCext-cCertRequired" +#define NID_setCext_cCertRequired 611 +#define OBJ_setCext_cCertRequired OBJ_set_certExt,3L + +#define SN_setCext_tunneling "setCext-tunneling" +#define NID_setCext_tunneling 612 +#define OBJ_setCext_tunneling OBJ_set_certExt,4L + +#define SN_setCext_setExt "setCext-setExt" +#define NID_setCext_setExt 613 +#define OBJ_setCext_setExt OBJ_set_certExt,5L + +#define SN_setCext_setQualf "setCext-setQualf" +#define NID_setCext_setQualf 614 +#define OBJ_setCext_setQualf OBJ_set_certExt,6L + +#define SN_setCext_PGWYcapabilities "setCext-PGWYcapabilities" +#define NID_setCext_PGWYcapabilities 615 +#define OBJ_setCext_PGWYcapabilities OBJ_set_certExt,7L + +#define SN_setCext_TokenIdentifier "setCext-TokenIdentifier" +#define NID_setCext_TokenIdentifier 616 +#define OBJ_setCext_TokenIdentifier OBJ_set_certExt,8L + +#define SN_setCext_Track2Data "setCext-Track2Data" +#define NID_setCext_Track2Data 617 +#define OBJ_setCext_Track2Data OBJ_set_certExt,9L + +#define SN_setCext_TokenType "setCext-TokenType" +#define NID_setCext_TokenType 618 +#define OBJ_setCext_TokenType OBJ_set_certExt,10L + +#define SN_setCext_IssuerCapabilities "setCext-IssuerCapabilities" +#define NID_setCext_IssuerCapabilities 619 +#define OBJ_setCext_IssuerCapabilities OBJ_set_certExt,11L + +#define SN_setAttr_Cert "setAttr-Cert" +#define NID_setAttr_Cert 620 +#define OBJ_setAttr_Cert OBJ_set_attr,0L + +#define SN_setAttr_PGWYcap "setAttr-PGWYcap" +#define LN_setAttr_PGWYcap "payment gateway capabilities" +#define NID_setAttr_PGWYcap 621 +#define OBJ_setAttr_PGWYcap OBJ_set_attr,1L + +#define SN_setAttr_TokenType "setAttr-TokenType" +#define NID_setAttr_TokenType 622 +#define OBJ_setAttr_TokenType OBJ_set_attr,2L + +#define SN_setAttr_IssCap "setAttr-IssCap" +#define LN_setAttr_IssCap "issuer capabilities" +#define NID_setAttr_IssCap 623 +#define OBJ_setAttr_IssCap OBJ_set_attr,3L + +#define SN_set_rootKeyThumb "set-rootKeyThumb" +#define NID_set_rootKeyThumb 624 +#define OBJ_set_rootKeyThumb OBJ_setAttr_Cert,0L + +#define SN_set_addPolicy "set-addPolicy" +#define NID_set_addPolicy 625 +#define OBJ_set_addPolicy OBJ_setAttr_Cert,1L + +#define SN_setAttr_Token_EMV "setAttr-Token-EMV" +#define NID_setAttr_Token_EMV 626 +#define OBJ_setAttr_Token_EMV OBJ_setAttr_TokenType,1L + +#define SN_setAttr_Token_B0Prime "setAttr-Token-B0Prime" +#define NID_setAttr_Token_B0Prime 627 +#define OBJ_setAttr_Token_B0Prime OBJ_setAttr_TokenType,2L + +#define SN_setAttr_IssCap_CVM "setAttr-IssCap-CVM" +#define NID_setAttr_IssCap_CVM 628 +#define OBJ_setAttr_IssCap_CVM OBJ_setAttr_IssCap,3L + +#define SN_setAttr_IssCap_T2 "setAttr-IssCap-T2" +#define NID_setAttr_IssCap_T2 629 +#define OBJ_setAttr_IssCap_T2 OBJ_setAttr_IssCap,4L + +#define SN_setAttr_IssCap_Sig "setAttr-IssCap-Sig" +#define NID_setAttr_IssCap_Sig 630 +#define OBJ_setAttr_IssCap_Sig OBJ_setAttr_IssCap,5L + +#define SN_setAttr_GenCryptgrm "setAttr-GenCryptgrm" +#define LN_setAttr_GenCryptgrm "generate cryptogram" +#define NID_setAttr_GenCryptgrm 631 +#define OBJ_setAttr_GenCryptgrm OBJ_setAttr_IssCap_CVM,1L + +#define SN_setAttr_T2Enc "setAttr-T2Enc" +#define LN_setAttr_T2Enc "encrypted track 2" +#define NID_setAttr_T2Enc 632 +#define OBJ_setAttr_T2Enc OBJ_setAttr_IssCap_T2,1L + +#define SN_setAttr_T2cleartxt "setAttr-T2cleartxt" +#define LN_setAttr_T2cleartxt "cleartext track 2" +#define NID_setAttr_T2cleartxt 633 +#define OBJ_setAttr_T2cleartxt OBJ_setAttr_IssCap_T2,2L + +#define SN_setAttr_TokICCsig "setAttr-TokICCsig" +#define LN_setAttr_TokICCsig "ICC or token signature" +#define NID_setAttr_TokICCsig 634 +#define OBJ_setAttr_TokICCsig OBJ_setAttr_IssCap_Sig,1L + +#define SN_setAttr_SecDevSig "setAttr-SecDevSig" +#define LN_setAttr_SecDevSig "secure device signature" +#define NID_setAttr_SecDevSig 635 +#define OBJ_setAttr_SecDevSig OBJ_setAttr_IssCap_Sig,2L + +#define SN_set_brand_IATA_ATA "set-brand-IATA-ATA" +#define NID_set_brand_IATA_ATA 636 +#define OBJ_set_brand_IATA_ATA OBJ_set_brand,1L + +#define SN_set_brand_Diners "set-brand-Diners" +#define NID_set_brand_Diners 637 +#define OBJ_set_brand_Diners OBJ_set_brand,30L + +#define SN_set_brand_AmericanExpress "set-brand-AmericanExpress" +#define NID_set_brand_AmericanExpress 638 +#define OBJ_set_brand_AmericanExpress OBJ_set_brand,34L + +#define SN_set_brand_JCB "set-brand-JCB" +#define NID_set_brand_JCB 639 +#define OBJ_set_brand_JCB OBJ_set_brand,35L + +#define SN_set_brand_Visa "set-brand-Visa" +#define NID_set_brand_Visa 640 +#define OBJ_set_brand_Visa OBJ_set_brand,4L + +#define SN_set_brand_MasterCard "set-brand-MasterCard" +#define NID_set_brand_MasterCard 641 +#define OBJ_set_brand_MasterCard OBJ_set_brand,5L + +#define SN_set_brand_Novus "set-brand-Novus" +#define NID_set_brand_Novus 642 +#define OBJ_set_brand_Novus OBJ_set_brand,6011L + +#define SN_des_cdmf "DES-CDMF" +#define LN_des_cdmf "des-cdmf" +#define NID_des_cdmf 643 +#define OBJ_des_cdmf OBJ_rsadsi,3L,10L + +#define SN_rsaOAEPEncryptionSET "rsaOAEPEncryptionSET" +#define NID_rsaOAEPEncryptionSET 644 +#define OBJ_rsaOAEPEncryptionSET OBJ_rsadsi,1L,1L,6L + +#define SN_ipsec3 "Oakley-EC2N-3" +#define LN_ipsec3 "ipsec3" +#define NID_ipsec3 749 + +#define SN_ipsec4 "Oakley-EC2N-4" +#define LN_ipsec4 "ipsec4" +#define NID_ipsec4 750 + +#define SN_whirlpool "whirlpool" +#define NID_whirlpool 804 +#define OBJ_whirlpool OBJ_iso,0L,10118L,3L,0L,55L + +#define SN_cryptopro "cryptopro" +#define NID_cryptopro 805 +#define OBJ_cryptopro OBJ_member_body,643L,2L,2L + +#define SN_cryptocom "cryptocom" +#define NID_cryptocom 806 +#define OBJ_cryptocom OBJ_member_body,643L,2L,9L + +#define SN_id_GostR3411_94_with_GostR3410_2001 "id-GostR3411-94-with-GostR3410-2001" +#define LN_id_GostR3411_94_with_GostR3410_2001 "GOST R 34.11-94 with GOST R 34.10-2001" +#define NID_id_GostR3411_94_with_GostR3410_2001 807 +#define OBJ_id_GostR3411_94_with_GostR3410_2001 OBJ_cryptopro,3L + +#define SN_id_GostR3411_94_with_GostR3410_94 "id-GostR3411-94-with-GostR3410-94" +#define LN_id_GostR3411_94_with_GostR3410_94 "GOST R 34.11-94 with GOST R 34.10-94" +#define NID_id_GostR3411_94_with_GostR3410_94 808 +#define OBJ_id_GostR3411_94_with_GostR3410_94 OBJ_cryptopro,4L + +#define SN_id_GostR3411_94 "md_gost94" +#define LN_id_GostR3411_94 "GOST R 34.11-94" +#define NID_id_GostR3411_94 809 +#define OBJ_id_GostR3411_94 OBJ_cryptopro,9L + +#define SN_id_HMACGostR3411_94 "id-HMACGostR3411-94" +#define LN_id_HMACGostR3411_94 "HMAC GOST 34.11-94" +#define NID_id_HMACGostR3411_94 810 +#define OBJ_id_HMACGostR3411_94 OBJ_cryptopro,10L + +#define SN_id_GostR3410_2001 "gost2001" +#define LN_id_GostR3410_2001 "GOST R 34.10-2001" +#define NID_id_GostR3410_2001 811 +#define OBJ_id_GostR3410_2001 OBJ_cryptopro,19L + +#define SN_id_GostR3410_94 "gost94" +#define LN_id_GostR3410_94 "GOST R 34.10-94" +#define NID_id_GostR3410_94 812 +#define OBJ_id_GostR3410_94 OBJ_cryptopro,20L + +#define SN_id_Gost28147_89 "gost89" +#define LN_id_Gost28147_89 "GOST 28147-89" +#define NID_id_Gost28147_89 813 +#define OBJ_id_Gost28147_89 OBJ_cryptopro,21L + +#define SN_gost89_cnt "gost89-cnt" +#define NID_gost89_cnt 814 + +#define SN_id_Gost28147_89_MAC "gost-mac" +#define LN_id_Gost28147_89_MAC "GOST 28147-89 MAC" +#define NID_id_Gost28147_89_MAC 815 +#define OBJ_id_Gost28147_89_MAC OBJ_cryptopro,22L + +#define SN_id_GostR3411_94_prf "prf-gostr3411-94" +#define LN_id_GostR3411_94_prf "GOST R 34.11-94 PRF" +#define NID_id_GostR3411_94_prf 816 +#define OBJ_id_GostR3411_94_prf OBJ_cryptopro,23L + +#define SN_id_GostR3410_2001DH "id-GostR3410-2001DH" +#define LN_id_GostR3410_2001DH "GOST R 34.10-2001 DH" +#define NID_id_GostR3410_2001DH 817 +#define OBJ_id_GostR3410_2001DH OBJ_cryptopro,98L + +#define SN_id_GostR3410_94DH "id-GostR3410-94DH" +#define LN_id_GostR3410_94DH "GOST R 34.10-94 DH" +#define NID_id_GostR3410_94DH 818 +#define OBJ_id_GostR3410_94DH OBJ_cryptopro,99L + +#define SN_id_Gost28147_89_CryptoPro_KeyMeshing "id-Gost28147-89-CryptoPro-KeyMeshing" +#define NID_id_Gost28147_89_CryptoPro_KeyMeshing 819 +#define OBJ_id_Gost28147_89_CryptoPro_KeyMeshing OBJ_cryptopro,14L,1L + +#define SN_id_Gost28147_89_None_KeyMeshing "id-Gost28147-89-None-KeyMeshing" +#define NID_id_Gost28147_89_None_KeyMeshing 820 +#define OBJ_id_Gost28147_89_None_KeyMeshing OBJ_cryptopro,14L,0L + +#define SN_id_GostR3411_94_TestParamSet "id-GostR3411-94-TestParamSet" +#define NID_id_GostR3411_94_TestParamSet 821 +#define OBJ_id_GostR3411_94_TestParamSet OBJ_cryptopro,30L,0L + +#define SN_id_GostR3411_94_CryptoProParamSet "id-GostR3411-94-CryptoProParamSet" +#define NID_id_GostR3411_94_CryptoProParamSet 822 +#define OBJ_id_GostR3411_94_CryptoProParamSet OBJ_cryptopro,30L,1L + +#define SN_id_Gost28147_89_TestParamSet "id-Gost28147-89-TestParamSet" +#define NID_id_Gost28147_89_TestParamSet 823 +#define OBJ_id_Gost28147_89_TestParamSet OBJ_cryptopro,31L,0L + +#define SN_id_Gost28147_89_CryptoPro_A_ParamSet "id-Gost28147-89-CryptoPro-A-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_A_ParamSet 824 +#define OBJ_id_Gost28147_89_CryptoPro_A_ParamSet OBJ_cryptopro,31L,1L + +#define SN_id_Gost28147_89_CryptoPro_B_ParamSet "id-Gost28147-89-CryptoPro-B-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_B_ParamSet 825 +#define OBJ_id_Gost28147_89_CryptoPro_B_ParamSet OBJ_cryptopro,31L,2L + +#define SN_id_Gost28147_89_CryptoPro_C_ParamSet "id-Gost28147-89-CryptoPro-C-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_C_ParamSet 826 +#define OBJ_id_Gost28147_89_CryptoPro_C_ParamSet OBJ_cryptopro,31L,3L + +#define SN_id_Gost28147_89_CryptoPro_D_ParamSet "id-Gost28147-89-CryptoPro-D-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_D_ParamSet 827 +#define OBJ_id_Gost28147_89_CryptoPro_D_ParamSet OBJ_cryptopro,31L,4L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet 828 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet OBJ_cryptopro,31L,5L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet 829 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet OBJ_cryptopro,31L,6L + +#define SN_id_Gost28147_89_CryptoPro_RIC_1_ParamSet "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet 830 +#define OBJ_id_Gost28147_89_CryptoPro_RIC_1_ParamSet OBJ_cryptopro,31L,7L + +#define SN_id_GostR3410_94_TestParamSet "id-GostR3410-94-TestParamSet" +#define NID_id_GostR3410_94_TestParamSet 831 +#define OBJ_id_GostR3410_94_TestParamSet OBJ_cryptopro,32L,0L + +#define SN_id_GostR3410_94_CryptoPro_A_ParamSet "id-GostR3410-94-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_A_ParamSet 832 +#define OBJ_id_GostR3410_94_CryptoPro_A_ParamSet OBJ_cryptopro,32L,2L + +#define SN_id_GostR3410_94_CryptoPro_B_ParamSet "id-GostR3410-94-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_B_ParamSet 833 +#define OBJ_id_GostR3410_94_CryptoPro_B_ParamSet OBJ_cryptopro,32L,3L + +#define SN_id_GostR3410_94_CryptoPro_C_ParamSet "id-GostR3410-94-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_C_ParamSet 834 +#define OBJ_id_GostR3410_94_CryptoPro_C_ParamSet OBJ_cryptopro,32L,4L + +#define SN_id_GostR3410_94_CryptoPro_D_ParamSet "id-GostR3410-94-CryptoPro-D-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_D_ParamSet 835 +#define OBJ_id_GostR3410_94_CryptoPro_D_ParamSet OBJ_cryptopro,32L,5L + +#define SN_id_GostR3410_94_CryptoPro_XchA_ParamSet "id-GostR3410-94-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchA_ParamSet 836 +#define OBJ_id_GostR3410_94_CryptoPro_XchA_ParamSet OBJ_cryptopro,33L,1L + +#define SN_id_GostR3410_94_CryptoPro_XchB_ParamSet "id-GostR3410-94-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchB_ParamSet 837 +#define OBJ_id_GostR3410_94_CryptoPro_XchB_ParamSet OBJ_cryptopro,33L,2L + +#define SN_id_GostR3410_94_CryptoPro_XchC_ParamSet "id-GostR3410-94-CryptoPro-XchC-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchC_ParamSet 838 +#define OBJ_id_GostR3410_94_CryptoPro_XchC_ParamSet OBJ_cryptopro,33L,3L + +#define SN_id_GostR3410_2001_TestParamSet "id-GostR3410-2001-TestParamSet" +#define NID_id_GostR3410_2001_TestParamSet 839 +#define OBJ_id_GostR3410_2001_TestParamSet OBJ_cryptopro,35L,0L + +#define SN_id_GostR3410_2001_CryptoPro_A_ParamSet "id-GostR3410-2001-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_A_ParamSet 840 +#define OBJ_id_GostR3410_2001_CryptoPro_A_ParamSet OBJ_cryptopro,35L,1L + +#define SN_id_GostR3410_2001_CryptoPro_B_ParamSet "id-GostR3410-2001-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_B_ParamSet 841 +#define OBJ_id_GostR3410_2001_CryptoPro_B_ParamSet OBJ_cryptopro,35L,2L + +#define SN_id_GostR3410_2001_CryptoPro_C_ParamSet "id-GostR3410-2001-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_C_ParamSet 842 +#define OBJ_id_GostR3410_2001_CryptoPro_C_ParamSet OBJ_cryptopro,35L,3L + +#define SN_id_GostR3410_2001_CryptoPro_XchA_ParamSet "id-GostR3410-2001-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet 843 +#define OBJ_id_GostR3410_2001_CryptoPro_XchA_ParamSet OBJ_cryptopro,36L,0L + +#define SN_id_GostR3410_2001_CryptoPro_XchB_ParamSet "id-GostR3410-2001-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet 844 +#define OBJ_id_GostR3410_2001_CryptoPro_XchB_ParamSet OBJ_cryptopro,36L,1L + +#define SN_id_GostR3410_94_a "id-GostR3410-94-a" +#define NID_id_GostR3410_94_a 845 +#define OBJ_id_GostR3410_94_a OBJ_id_GostR3410_94,1L + +#define SN_id_GostR3410_94_aBis "id-GostR3410-94-aBis" +#define NID_id_GostR3410_94_aBis 846 +#define OBJ_id_GostR3410_94_aBis OBJ_id_GostR3410_94,2L + +#define SN_id_GostR3410_94_b "id-GostR3410-94-b" +#define NID_id_GostR3410_94_b 847 +#define OBJ_id_GostR3410_94_b OBJ_id_GostR3410_94,3L + +#define SN_id_GostR3410_94_bBis "id-GostR3410-94-bBis" +#define NID_id_GostR3410_94_bBis 848 +#define OBJ_id_GostR3410_94_bBis OBJ_id_GostR3410_94,4L + +#define SN_id_Gost28147_89_cc "id-Gost28147-89-cc" +#define LN_id_Gost28147_89_cc "GOST 28147-89 Cryptocom ParamSet" +#define NID_id_Gost28147_89_cc 849 +#define OBJ_id_Gost28147_89_cc OBJ_cryptocom,1L,6L,1L + +#define SN_id_GostR3410_94_cc "gost94cc" +#define LN_id_GostR3410_94_cc "GOST 34.10-94 Cryptocom" +#define NID_id_GostR3410_94_cc 850 +#define OBJ_id_GostR3410_94_cc OBJ_cryptocom,1L,5L,3L + +#define SN_id_GostR3410_2001_cc "gost2001cc" +#define LN_id_GostR3410_2001_cc "GOST 34.10-2001 Cryptocom" +#define NID_id_GostR3410_2001_cc 851 +#define OBJ_id_GostR3410_2001_cc OBJ_cryptocom,1L,5L,4L + +#define SN_id_GostR3411_94_with_GostR3410_94_cc "id-GostR3411-94-with-GostR3410-94-cc" +#define LN_id_GostR3411_94_with_GostR3410_94_cc "GOST R 34.11-94 with GOST R 34.10-94 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_94_cc 852 +#define OBJ_id_GostR3411_94_with_GostR3410_94_cc OBJ_cryptocom,1L,3L,3L + +#define SN_id_GostR3411_94_with_GostR3410_2001_cc "id-GostR3411-94-with-GostR3410-2001-cc" +#define LN_id_GostR3411_94_with_GostR3410_2001_cc "GOST R 34.11-94 with GOST R 34.10-2001 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_2001_cc 853 +#define OBJ_id_GostR3411_94_with_GostR3410_2001_cc OBJ_cryptocom,1L,3L,4L + +#define SN_id_GostR3410_2001_ParamSet_cc "id-GostR3410-2001-ParamSet-cc" +#define LN_id_GostR3410_2001_ParamSet_cc "GOST R 3410-2001 Parameter Set Cryptocom" +#define NID_id_GostR3410_2001_ParamSet_cc 854 +#define OBJ_id_GostR3410_2001_ParamSet_cc OBJ_cryptocom,1L,8L,1L + +#define SN_camellia_128_cbc "CAMELLIA-128-CBC" +#define LN_camellia_128_cbc "camellia-128-cbc" +#define NID_camellia_128_cbc 751 +#define OBJ_camellia_128_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,2L + +#define SN_camellia_192_cbc "CAMELLIA-192-CBC" +#define LN_camellia_192_cbc "camellia-192-cbc" +#define NID_camellia_192_cbc 752 +#define OBJ_camellia_192_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,3L + +#define SN_camellia_256_cbc "CAMELLIA-256-CBC" +#define LN_camellia_256_cbc "camellia-256-cbc" +#define NID_camellia_256_cbc 753 +#define OBJ_camellia_256_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,4L + +#define OBJ_ntt_ds 0L,3L,4401L,5L + +#define OBJ_camellia OBJ_ntt_ds,3L,1L,9L + +#define SN_camellia_128_ecb "CAMELLIA-128-ECB" +#define LN_camellia_128_ecb "camellia-128-ecb" +#define NID_camellia_128_ecb 754 +#define OBJ_camellia_128_ecb OBJ_camellia,1L + +#define SN_camellia_128_ofb128 "CAMELLIA-128-OFB" +#define LN_camellia_128_ofb128 "camellia-128-ofb" +#define NID_camellia_128_ofb128 766 +#define OBJ_camellia_128_ofb128 OBJ_camellia,3L + +#define SN_camellia_128_cfb128 "CAMELLIA-128-CFB" +#define LN_camellia_128_cfb128 "camellia-128-cfb" +#define NID_camellia_128_cfb128 757 +#define OBJ_camellia_128_cfb128 OBJ_camellia,4L + +#define SN_camellia_192_ecb "CAMELLIA-192-ECB" +#define LN_camellia_192_ecb "camellia-192-ecb" +#define NID_camellia_192_ecb 755 +#define OBJ_camellia_192_ecb OBJ_camellia,21L + +#define SN_camellia_192_ofb128 "CAMELLIA-192-OFB" +#define LN_camellia_192_ofb128 "camellia-192-ofb" +#define NID_camellia_192_ofb128 767 +#define OBJ_camellia_192_ofb128 OBJ_camellia,23L + +#define SN_camellia_192_cfb128 "CAMELLIA-192-CFB" +#define LN_camellia_192_cfb128 "camellia-192-cfb" +#define NID_camellia_192_cfb128 758 +#define OBJ_camellia_192_cfb128 OBJ_camellia,24L + +#define SN_camellia_256_ecb "CAMELLIA-256-ECB" +#define LN_camellia_256_ecb "camellia-256-ecb" +#define NID_camellia_256_ecb 756 +#define OBJ_camellia_256_ecb OBJ_camellia,41L + +#define SN_camellia_256_ofb128 "CAMELLIA-256-OFB" +#define LN_camellia_256_ofb128 "camellia-256-ofb" +#define NID_camellia_256_ofb128 768 +#define OBJ_camellia_256_ofb128 OBJ_camellia,43L + +#define SN_camellia_256_cfb128 "CAMELLIA-256-CFB" +#define LN_camellia_256_cfb128 "camellia-256-cfb" +#define NID_camellia_256_cfb128 759 +#define OBJ_camellia_256_cfb128 OBJ_camellia,44L + +#define SN_camellia_128_cfb1 "CAMELLIA-128-CFB1" +#define LN_camellia_128_cfb1 "camellia-128-cfb1" +#define NID_camellia_128_cfb1 760 + +#define SN_camellia_192_cfb1 "CAMELLIA-192-CFB1" +#define LN_camellia_192_cfb1 "camellia-192-cfb1" +#define NID_camellia_192_cfb1 761 + +#define SN_camellia_256_cfb1 "CAMELLIA-256-CFB1" +#define LN_camellia_256_cfb1 "camellia-256-cfb1" +#define NID_camellia_256_cfb1 762 + +#define SN_camellia_128_cfb8 "CAMELLIA-128-CFB8" +#define LN_camellia_128_cfb8 "camellia-128-cfb8" +#define NID_camellia_128_cfb8 763 + +#define SN_camellia_192_cfb8 "CAMELLIA-192-CFB8" +#define LN_camellia_192_cfb8 "camellia-192-cfb8" +#define NID_camellia_192_cfb8 764 + +#define SN_camellia_256_cfb8 "CAMELLIA-256-CFB8" +#define LN_camellia_256_cfb8 "camellia-256-cfb8" +#define NID_camellia_256_cfb8 765 + +#define SN_kisa "KISA" +#define LN_kisa "kisa" +#define NID_kisa 773 +#define OBJ_kisa OBJ_member_body,410L,200004L + +#define SN_seed_ecb "SEED-ECB" +#define LN_seed_ecb "seed-ecb" +#define NID_seed_ecb 776 +#define OBJ_seed_ecb OBJ_kisa,1L,3L + +#define SN_seed_cbc "SEED-CBC" +#define LN_seed_cbc "seed-cbc" +#define NID_seed_cbc 777 +#define OBJ_seed_cbc OBJ_kisa,1L,4L + +#define SN_seed_cfb128 "SEED-CFB" +#define LN_seed_cfb128 "seed-cfb" +#define NID_seed_cfb128 779 +#define OBJ_seed_cfb128 OBJ_kisa,1L,5L + +#define SN_seed_ofb128 "SEED-OFB" +#define LN_seed_ofb128 "seed-ofb" +#define NID_seed_ofb128 778 +#define OBJ_seed_ofb128 OBJ_kisa,1L,6L + +#define SN_hmac "HMAC" +#define LN_hmac "hmac" +#define NID_hmac 855 + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/objects.h b/石器时代8.5客户端最新源代码/石器源码/openssl/objects.h new file mode 100644 index 0000000..7242f76 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/objects.h @@ -0,0 +1,1049 @@ +/* crypto/objects/objects.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_OBJECTS_H +#define HEADER_OBJECTS_H + +#define USE_OBJ_MAC + +#ifdef USE_OBJ_MAC +#include +#else +#define SN_undef "UNDEF" +#define LN_undef "undefined" +#define NID_undef 0 +#define OBJ_undef 0L + +#define SN_Algorithm "Algorithm" +#define LN_algorithm "algorithm" +#define NID_algorithm 38 +#define OBJ_algorithm 1L,3L,14L,3L,2L + +#define LN_rsadsi "rsadsi" +#define NID_rsadsi 1 +#define OBJ_rsadsi 1L,2L,840L,113549L + +#define LN_pkcs "pkcs" +#define NID_pkcs 2 +#define OBJ_pkcs OBJ_rsadsi,1L + +#define SN_md2 "MD2" +#define LN_md2 "md2" +#define NID_md2 3 +#define OBJ_md2 OBJ_rsadsi,2L,2L + +#define SN_md5 "MD5" +#define LN_md5 "md5" +#define NID_md5 4 +#define OBJ_md5 OBJ_rsadsi,2L,5L + +#define SN_rc4 "RC4" +#define LN_rc4 "rc4" +#define NID_rc4 5 +#define OBJ_rc4 OBJ_rsadsi,3L,4L + +#define LN_rsaEncryption "rsaEncryption" +#define NID_rsaEncryption 6 +#define OBJ_rsaEncryption OBJ_pkcs,1L,1L + +#define SN_md2WithRSAEncryption "RSA-MD2" +#define LN_md2WithRSAEncryption "md2WithRSAEncryption" +#define NID_md2WithRSAEncryption 7 +#define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L + +#define SN_md5WithRSAEncryption "RSA-MD5" +#define LN_md5WithRSAEncryption "md5WithRSAEncryption" +#define NID_md5WithRSAEncryption 8 +#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L + +#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES" +#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" +#define NID_pbeWithMD2AndDES_CBC 9 +#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L + +#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES" +#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" +#define NID_pbeWithMD5AndDES_CBC 10 +#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L + +#define LN_X500 "X500" +#define NID_X500 11 +#define OBJ_X500 2L,5L + +#define LN_X509 "X509" +#define NID_X509 12 +#define OBJ_X509 OBJ_X500,4L + +#define SN_commonName "CN" +#define LN_commonName "commonName" +#define NID_commonName 13 +#define OBJ_commonName OBJ_X509,3L + +#define SN_countryName "C" +#define LN_countryName "countryName" +#define NID_countryName 14 +#define OBJ_countryName OBJ_X509,6L + +#define SN_localityName "L" +#define LN_localityName "localityName" +#define NID_localityName 15 +#define OBJ_localityName OBJ_X509,7L + +/* Postal Address? PA */ + +/* should be "ST" (rfc1327) but MS uses 'S' */ +#define SN_stateOrProvinceName "ST" +#define LN_stateOrProvinceName "stateOrProvinceName" +#define NID_stateOrProvinceName 16 +#define OBJ_stateOrProvinceName OBJ_X509,8L + +#define SN_organizationName "O" +#define LN_organizationName "organizationName" +#define NID_organizationName 17 +#define OBJ_organizationName OBJ_X509,10L + +#define SN_organizationalUnitName "OU" +#define LN_organizationalUnitName "organizationalUnitName" +#define NID_organizationalUnitName 18 +#define OBJ_organizationalUnitName OBJ_X509,11L + +#define SN_rsa "RSA" +#define LN_rsa "rsa" +#define NID_rsa 19 +#define OBJ_rsa OBJ_X500,8L,1L,1L + +#define LN_pkcs7 "pkcs7" +#define NID_pkcs7 20 +#define OBJ_pkcs7 OBJ_pkcs,7L + +#define LN_pkcs7_data "pkcs7-data" +#define NID_pkcs7_data 21 +#define OBJ_pkcs7_data OBJ_pkcs7,1L + +#define LN_pkcs7_signed "pkcs7-signedData" +#define NID_pkcs7_signed 22 +#define OBJ_pkcs7_signed OBJ_pkcs7,2L + +#define LN_pkcs7_enveloped "pkcs7-envelopedData" +#define NID_pkcs7_enveloped 23 +#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L + +#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" +#define NID_pkcs7_signedAndEnveloped 24 +#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L + +#define LN_pkcs7_digest "pkcs7-digestData" +#define NID_pkcs7_digest 25 +#define OBJ_pkcs7_digest OBJ_pkcs7,5L + +#define LN_pkcs7_encrypted "pkcs7-encryptedData" +#define NID_pkcs7_encrypted 26 +#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L + +#define LN_pkcs3 "pkcs3" +#define NID_pkcs3 27 +#define OBJ_pkcs3 OBJ_pkcs,3L + +#define LN_dhKeyAgreement "dhKeyAgreement" +#define NID_dhKeyAgreement 28 +#define OBJ_dhKeyAgreement OBJ_pkcs3,1L + +#define SN_des_ecb "DES-ECB" +#define LN_des_ecb "des-ecb" +#define NID_des_ecb 29 +#define OBJ_des_ecb OBJ_algorithm,6L + +#define SN_des_cfb64 "DES-CFB" +#define LN_des_cfb64 "des-cfb" +#define NID_des_cfb64 30 +/* IV + num */ +#define OBJ_des_cfb64 OBJ_algorithm,9L + +#define SN_des_cbc "DES-CBC" +#define LN_des_cbc "des-cbc" +#define NID_des_cbc 31 +/* IV */ +#define OBJ_des_cbc OBJ_algorithm,7L + +#define SN_des_ede "DES-EDE" +#define LN_des_ede "des-ede" +#define NID_des_ede 32 +/* ?? */ +#define OBJ_des_ede OBJ_algorithm,17L + +#define SN_des_ede3 "DES-EDE3" +#define LN_des_ede3 "des-ede3" +#define NID_des_ede3 33 + +#define SN_idea_cbc "IDEA-CBC" +#define LN_idea_cbc "idea-cbc" +#define NID_idea_cbc 34 +#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L + +#define SN_idea_cfb64 "IDEA-CFB" +#define LN_idea_cfb64 "idea-cfb" +#define NID_idea_cfb64 35 + +#define SN_idea_ecb "IDEA-ECB" +#define LN_idea_ecb "idea-ecb" +#define NID_idea_ecb 36 + +#define SN_rc2_cbc "RC2-CBC" +#define LN_rc2_cbc "rc2-cbc" +#define NID_rc2_cbc 37 +#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L + +#define SN_rc2_ecb "RC2-ECB" +#define LN_rc2_ecb "rc2-ecb" +#define NID_rc2_ecb 38 + +#define SN_rc2_cfb64 "RC2-CFB" +#define LN_rc2_cfb64 "rc2-cfb" +#define NID_rc2_cfb64 39 + +#define SN_rc2_ofb64 "RC2-OFB" +#define LN_rc2_ofb64 "rc2-ofb" +#define NID_rc2_ofb64 40 + +#define SN_sha "SHA" +#define LN_sha "sha" +#define NID_sha 41 +#define OBJ_sha OBJ_algorithm,18L + +#define SN_shaWithRSAEncryption "RSA-SHA" +#define LN_shaWithRSAEncryption "shaWithRSAEncryption" +#define NID_shaWithRSAEncryption 42 +#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L + +#define SN_des_ede_cbc "DES-EDE-CBC" +#define LN_des_ede_cbc "des-ede-cbc" +#define NID_des_ede_cbc 43 + +#define SN_des_ede3_cbc "DES-EDE3-CBC" +#define LN_des_ede3_cbc "des-ede3-cbc" +#define NID_des_ede3_cbc 44 +#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L + +#define SN_des_ofb64 "DES-OFB" +#define LN_des_ofb64 "des-ofb" +#define NID_des_ofb64 45 +#define OBJ_des_ofb64 OBJ_algorithm,8L + +#define SN_idea_ofb64 "IDEA-OFB" +#define LN_idea_ofb64 "idea-ofb" +#define NID_idea_ofb64 46 + +#define LN_pkcs9 "pkcs9" +#define NID_pkcs9 47 +#define OBJ_pkcs9 OBJ_pkcs,9L + +#define SN_pkcs9_emailAddress "Email" +#define LN_pkcs9_emailAddress "emailAddress" +#define NID_pkcs9_emailAddress 48 +#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L + +#define LN_pkcs9_unstructuredName "unstructuredName" +#define NID_pkcs9_unstructuredName 49 +#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L + +#define LN_pkcs9_contentType "contentType" +#define NID_pkcs9_contentType 50 +#define OBJ_pkcs9_contentType OBJ_pkcs9,3L + +#define LN_pkcs9_messageDigest "messageDigest" +#define NID_pkcs9_messageDigest 51 +#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L + +#define LN_pkcs9_signingTime "signingTime" +#define NID_pkcs9_signingTime 52 +#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L + +#define LN_pkcs9_countersignature "countersignature" +#define NID_pkcs9_countersignature 53 +#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L + +#define LN_pkcs9_challengePassword "challengePassword" +#define NID_pkcs9_challengePassword 54 +#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L + +#define LN_pkcs9_unstructuredAddress "unstructuredAddress" +#define NID_pkcs9_unstructuredAddress 55 +#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L + +#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" +#define NID_pkcs9_extCertAttributes 56 +#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L + +#define SN_netscape "Netscape" +#define LN_netscape "Netscape Communications Corp." +#define NID_netscape 57 +#define OBJ_netscape 2L,16L,840L,1L,113730L + +#define SN_netscape_cert_extension "nsCertExt" +#define LN_netscape_cert_extension "Netscape Certificate Extension" +#define NID_netscape_cert_extension 58 +#define OBJ_netscape_cert_extension OBJ_netscape,1L + +#define SN_netscape_data_type "nsDataType" +#define LN_netscape_data_type "Netscape Data Type" +#define NID_netscape_data_type 59 +#define OBJ_netscape_data_type OBJ_netscape,2L + +#define SN_des_ede_cfb64 "DES-EDE-CFB" +#define LN_des_ede_cfb64 "des-ede-cfb" +#define NID_des_ede_cfb64 60 + +#define SN_des_ede3_cfb64 "DES-EDE3-CFB" +#define LN_des_ede3_cfb64 "des-ede3-cfb" +#define NID_des_ede3_cfb64 61 + +#define SN_des_ede_ofb64 "DES-EDE-OFB" +#define LN_des_ede_ofb64 "des-ede-ofb" +#define NID_des_ede_ofb64 62 + +#define SN_des_ede3_ofb64 "DES-EDE3-OFB" +#define LN_des_ede3_ofb64 "des-ede3-ofb" +#define NID_des_ede3_ofb64 63 + +/* I'm not sure about the object ID */ +#define SN_sha1 "SHA1" +#define LN_sha1 "sha1" +#define NID_sha1 64 +#define OBJ_sha1 OBJ_algorithm,26L +/* 28 Jun 1996 - eay */ +/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */ + +#define SN_sha1WithRSAEncryption "RSA-SHA1" +#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" +#define NID_sha1WithRSAEncryption 65 +#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L + +#define SN_dsaWithSHA "DSA-SHA" +#define LN_dsaWithSHA "dsaWithSHA" +#define NID_dsaWithSHA 66 +#define OBJ_dsaWithSHA OBJ_algorithm,13L + +#define SN_dsa_2 "DSA-old" +#define LN_dsa_2 "dsaEncryption-old" +#define NID_dsa_2 67 +#define OBJ_dsa_2 OBJ_algorithm,12L + +/* proposed by microsoft to RSA */ +#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" +#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" +#define NID_pbeWithSHA1AndRC2_CBC 68 +#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L + +/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now + * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something + * completely different. + */ +#define LN_id_pbkdf2 "PBKDF2" +#define NID_id_pbkdf2 69 +#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L + +#define SN_dsaWithSHA1_2 "DSA-SHA1-old" +#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" +#define NID_dsaWithSHA1_2 70 +/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */ +#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L + +#define SN_netscape_cert_type "nsCertType" +#define LN_netscape_cert_type "Netscape Cert Type" +#define NID_netscape_cert_type 71 +#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L + +#define SN_netscape_base_url "nsBaseUrl" +#define LN_netscape_base_url "Netscape Base Url" +#define NID_netscape_base_url 72 +#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L + +#define SN_netscape_revocation_url "nsRevocationUrl" +#define LN_netscape_revocation_url "Netscape Revocation Url" +#define NID_netscape_revocation_url 73 +#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L + +#define SN_netscape_ca_revocation_url "nsCaRevocationUrl" +#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" +#define NID_netscape_ca_revocation_url 74 +#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L + +#define SN_netscape_renewal_url "nsRenewalUrl" +#define LN_netscape_renewal_url "Netscape Renewal Url" +#define NID_netscape_renewal_url 75 +#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L + +#define SN_netscape_ca_policy_url "nsCaPolicyUrl" +#define LN_netscape_ca_policy_url "Netscape CA Policy Url" +#define NID_netscape_ca_policy_url 76 +#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L + +#define SN_netscape_ssl_server_name "nsSslServerName" +#define LN_netscape_ssl_server_name "Netscape SSL Server Name" +#define NID_netscape_ssl_server_name 77 +#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L + +#define SN_netscape_comment "nsComment" +#define LN_netscape_comment "Netscape Comment" +#define NID_netscape_comment 78 +#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L + +#define SN_netscape_cert_sequence "nsCertSequence" +#define LN_netscape_cert_sequence "Netscape Certificate Sequence" +#define NID_netscape_cert_sequence 79 +#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L + +#define SN_desx_cbc "DESX-CBC" +#define LN_desx_cbc "desx-cbc" +#define NID_desx_cbc 80 + +#define SN_id_ce "id-ce" +#define NID_id_ce 81 +#define OBJ_id_ce 2L,5L,29L + +#define SN_subject_key_identifier "subjectKeyIdentifier" +#define LN_subject_key_identifier "X509v3 Subject Key Identifier" +#define NID_subject_key_identifier 82 +#define OBJ_subject_key_identifier OBJ_id_ce,14L + +#define SN_key_usage "keyUsage" +#define LN_key_usage "X509v3 Key Usage" +#define NID_key_usage 83 +#define OBJ_key_usage OBJ_id_ce,15L + +#define SN_private_key_usage_period "privateKeyUsagePeriod" +#define LN_private_key_usage_period "X509v3 Private Key Usage Period" +#define NID_private_key_usage_period 84 +#define OBJ_private_key_usage_period OBJ_id_ce,16L + +#define SN_subject_alt_name "subjectAltName" +#define LN_subject_alt_name "X509v3 Subject Alternative Name" +#define NID_subject_alt_name 85 +#define OBJ_subject_alt_name OBJ_id_ce,17L + +#define SN_issuer_alt_name "issuerAltName" +#define LN_issuer_alt_name "X509v3 Issuer Alternative Name" +#define NID_issuer_alt_name 86 +#define OBJ_issuer_alt_name OBJ_id_ce,18L + +#define SN_basic_constraints "basicConstraints" +#define LN_basic_constraints "X509v3 Basic Constraints" +#define NID_basic_constraints 87 +#define OBJ_basic_constraints OBJ_id_ce,19L + +#define SN_crl_number "crlNumber" +#define LN_crl_number "X509v3 CRL Number" +#define NID_crl_number 88 +#define OBJ_crl_number OBJ_id_ce,20L + +#define SN_certificate_policies "certificatePolicies" +#define LN_certificate_policies "X509v3 Certificate Policies" +#define NID_certificate_policies 89 +#define OBJ_certificate_policies OBJ_id_ce,32L + +#define SN_authority_key_identifier "authorityKeyIdentifier" +#define LN_authority_key_identifier "X509v3 Authority Key Identifier" +#define NID_authority_key_identifier 90 +#define OBJ_authority_key_identifier OBJ_id_ce,35L + +#define SN_bf_cbc "BF-CBC" +#define LN_bf_cbc "bf-cbc" +#define NID_bf_cbc 91 +#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L + +#define SN_bf_ecb "BF-ECB" +#define LN_bf_ecb "bf-ecb" +#define NID_bf_ecb 92 + +#define SN_bf_cfb64 "BF-CFB" +#define LN_bf_cfb64 "bf-cfb" +#define NID_bf_cfb64 93 + +#define SN_bf_ofb64 "BF-OFB" +#define LN_bf_ofb64 "bf-ofb" +#define NID_bf_ofb64 94 + +#define SN_mdc2 "MDC2" +#define LN_mdc2 "mdc2" +#define NID_mdc2 95 +#define OBJ_mdc2 2L,5L,8L,3L,101L +/* An alternative? 1L,3L,14L,3L,2L,19L */ + +#define SN_mdc2WithRSA "RSA-MDC2" +#define LN_mdc2WithRSA "mdc2withRSA" +#define NID_mdc2WithRSA 96 +#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L + +#define SN_rc4_40 "RC4-40" +#define LN_rc4_40 "rc4-40" +#define NID_rc4_40 97 + +#define SN_rc2_40_cbc "RC2-40-CBC" +#define LN_rc2_40_cbc "rc2-40-cbc" +#define NID_rc2_40_cbc 98 + +#define SN_givenName "G" +#define LN_givenName "givenName" +#define NID_givenName 99 +#define OBJ_givenName OBJ_X509,42L + +#define SN_surname "S" +#define LN_surname "surname" +#define NID_surname 100 +#define OBJ_surname OBJ_X509,4L + +#define SN_initials "I" +#define LN_initials "initials" +#define NID_initials 101 +#define OBJ_initials OBJ_X509,43L + +#define SN_uniqueIdentifier "UID" +#define LN_uniqueIdentifier "uniqueIdentifier" +#define NID_uniqueIdentifier 102 +#define OBJ_uniqueIdentifier OBJ_X509,45L + +#define SN_crl_distribution_points "crlDistributionPoints" +#define LN_crl_distribution_points "X509v3 CRL Distribution Points" +#define NID_crl_distribution_points 103 +#define OBJ_crl_distribution_points OBJ_id_ce,31L + +#define SN_md5WithRSA "RSA-NP-MD5" +#define LN_md5WithRSA "md5WithRSA" +#define NID_md5WithRSA 104 +#define OBJ_md5WithRSA OBJ_algorithm,3L + +#define SN_serialNumber "SN" +#define LN_serialNumber "serialNumber" +#define NID_serialNumber 105 +#define OBJ_serialNumber OBJ_X509,5L + +#define SN_title "T" +#define LN_title "title" +#define NID_title 106 +#define OBJ_title OBJ_X509,12L + +#define SN_description "D" +#define LN_description "description" +#define NID_description 107 +#define OBJ_description OBJ_X509,13L + +/* CAST5 is CAST-128, I'm just sticking with the documentation */ +#define SN_cast5_cbc "CAST5-CBC" +#define LN_cast5_cbc "cast5-cbc" +#define NID_cast5_cbc 108 +#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L + +#define SN_cast5_ecb "CAST5-ECB" +#define LN_cast5_ecb "cast5-ecb" +#define NID_cast5_ecb 109 + +#define SN_cast5_cfb64 "CAST5-CFB" +#define LN_cast5_cfb64 "cast5-cfb" +#define NID_cast5_cfb64 110 + +#define SN_cast5_ofb64 "CAST5-OFB" +#define LN_cast5_ofb64 "cast5-ofb" +#define NID_cast5_ofb64 111 + +#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" +#define NID_pbeWithMD5AndCast5_CBC 112 +#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L + +/* This is one sun will soon be using :-( + * id-dsa-with-sha1 ID ::= { + * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 } + */ +#define SN_dsaWithSHA1 "DSA-SHA1" +#define LN_dsaWithSHA1 "dsaWithSHA1" +#define NID_dsaWithSHA1 113 +#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L + +#define NID_md5_sha1 114 +#define SN_md5_sha1 "MD5-SHA1" +#define LN_md5_sha1 "md5-sha1" + +#define SN_sha1WithRSA "RSA-SHA1-2" +#define LN_sha1WithRSA "sha1WithRSA" +#define NID_sha1WithRSA 115 +#define OBJ_sha1WithRSA OBJ_algorithm,29L + +#define SN_dsa "DSA" +#define LN_dsa "dsaEncryption" +#define NID_dsa 116 +#define OBJ_dsa 1L,2L,840L,10040L,4L,1L + +#define SN_ripemd160 "RIPEMD160" +#define LN_ripemd160 "ripemd160" +#define NID_ripemd160 117 +#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L + +/* The name should actually be rsaSignatureWithripemd160, but I'm going + * to continue using the convention I'm using with the other ciphers */ +#define SN_ripemd160WithRSA "RSA-RIPEMD160" +#define LN_ripemd160WithRSA "ripemd160WithRSA" +#define NID_ripemd160WithRSA 119 +#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L + +/* Taken from rfc2040 + * RC5_CBC_Parameters ::= SEQUENCE { + * version INTEGER (v1_0(16)), + * rounds INTEGER (8..127), + * blockSizeInBits INTEGER (64, 128), + * iv OCTET STRING OPTIONAL + * } + */ +#define SN_rc5_cbc "RC5-CBC" +#define LN_rc5_cbc "rc5-cbc" +#define NID_rc5_cbc 120 +#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L + +#define SN_rc5_ecb "RC5-ECB" +#define LN_rc5_ecb "rc5-ecb" +#define NID_rc5_ecb 121 + +#define SN_rc5_cfb64 "RC5-CFB" +#define LN_rc5_cfb64 "rc5-cfb" +#define NID_rc5_cfb64 122 + +#define SN_rc5_ofb64 "RC5-OFB" +#define LN_rc5_ofb64 "rc5-ofb" +#define NID_rc5_ofb64 123 + +#define SN_rle_compression "RLE" +#define LN_rle_compression "run length compression" +#define NID_rle_compression 124 +#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L + +#define SN_zlib_compression "ZLIB" +#define LN_zlib_compression "zlib compression" +#define NID_zlib_compression 125 +#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L + +#define SN_ext_key_usage "extendedKeyUsage" +#define LN_ext_key_usage "X509v3 Extended Key Usage" +#define NID_ext_key_usage 126 +#define OBJ_ext_key_usage OBJ_id_ce,37 + +#define SN_id_pkix "PKIX" +#define NID_id_pkix 127 +#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +#define SN_id_kp "id-kp" +#define NID_id_kp 128 +#define OBJ_id_kp OBJ_id_pkix,3L + +/* PKIX extended key usage OIDs */ + +#define SN_server_auth "serverAuth" +#define LN_server_auth "TLS Web Server Authentication" +#define NID_server_auth 129 +#define OBJ_server_auth OBJ_id_kp,1L + +#define SN_client_auth "clientAuth" +#define LN_client_auth "TLS Web Client Authentication" +#define NID_client_auth 130 +#define OBJ_client_auth OBJ_id_kp,2L + +#define SN_code_sign "codeSigning" +#define LN_code_sign "Code Signing" +#define NID_code_sign 131 +#define OBJ_code_sign OBJ_id_kp,3L + +#define SN_email_protect "emailProtection" +#define LN_email_protect "E-mail Protection" +#define NID_email_protect 132 +#define OBJ_email_protect OBJ_id_kp,4L + +#define SN_time_stamp "timeStamping" +#define LN_time_stamp "Time Stamping" +#define NID_time_stamp 133 +#define OBJ_time_stamp OBJ_id_kp,8L + +/* Additional extended key usage OIDs: Microsoft */ + +#define SN_ms_code_ind "msCodeInd" +#define LN_ms_code_ind "Microsoft Individual Code Signing" +#define NID_ms_code_ind 134 +#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +#define SN_ms_code_com "msCodeCom" +#define LN_ms_code_com "Microsoft Commercial Code Signing" +#define NID_ms_code_com 135 +#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +#define SN_ms_ctl_sign "msCTLSign" +#define LN_ms_ctl_sign "Microsoft Trust List Signing" +#define NID_ms_ctl_sign 136 +#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +#define SN_ms_sgc "msSGC" +#define LN_ms_sgc "Microsoft Server Gated Crypto" +#define NID_ms_sgc 137 +#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +#define SN_ms_efs "msEFS" +#define LN_ms_efs "Microsoft Encrypted File System" +#define NID_ms_efs 138 +#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +/* Additional usage: Netscape */ + +#define SN_ns_sgc "nsSGC" +#define LN_ns_sgc "Netscape Server Gated Crypto" +#define NID_ns_sgc 139 +#define OBJ_ns_sgc OBJ_netscape,4L,1L + +#define SN_delta_crl "deltaCRL" +#define LN_delta_crl "X509v3 Delta CRL Indicator" +#define NID_delta_crl 140 +#define OBJ_delta_crl OBJ_id_ce,27L + +#define SN_crl_reason "CRLReason" +#define LN_crl_reason "CRL Reason Code" +#define NID_crl_reason 141 +#define OBJ_crl_reason OBJ_id_ce,21L + +#define SN_invalidity_date "invalidityDate" +#define LN_invalidity_date "Invalidity Date" +#define NID_invalidity_date 142 +#define OBJ_invalidity_date OBJ_id_ce,24L + +#define SN_sxnet "SXNetID" +#define LN_sxnet "Strong Extranet ID" +#define NID_sxnet 143 +#define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +/* PKCS12 and related OBJECT IDENTIFIERS */ + +#define OBJ_pkcs12 OBJ_pkcs,12L +#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1 + +#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128" +#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +#define NID_pbe_WithSHA1And128BitRC4 144 +#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L + +#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40" +#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +#define NID_pbe_WithSHA1And40BitRC4 145 +#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L + +#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES" +#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L + +#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES" +#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L + +#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128" +#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +#define NID_pbe_WithSHA1And128BitRC2_CBC 148 +#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L + +#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40" +#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +#define NID_pbe_WithSHA1And40BitRC2_CBC 149 +#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L + +#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L + +#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L + +#define LN_keyBag "keyBag" +#define NID_keyBag 150 +#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L + +#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +#define NID_pkcs8ShroudedKeyBag 151 +#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L + +#define LN_certBag "certBag" +#define NID_certBag 152 +#define OBJ_certBag OBJ_pkcs12_BagIds, 3L + +#define LN_crlBag "crlBag" +#define NID_crlBag 153 +#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L + +#define LN_secretBag "secretBag" +#define NID_secretBag 154 +#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L + +#define LN_safeContentsBag "safeContentsBag" +#define NID_safeContentsBag 155 +#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L + +#define LN_friendlyName "friendlyName" +#define NID_friendlyName 156 +#define OBJ_friendlyName OBJ_pkcs9, 20L + +#define LN_localKeyID "localKeyID" +#define NID_localKeyID 157 +#define OBJ_localKeyID OBJ_pkcs9, 21L + +#define OBJ_certTypes OBJ_pkcs9, 22L + +#define LN_x509Certificate "x509Certificate" +#define NID_x509Certificate 158 +#define OBJ_x509Certificate OBJ_certTypes, 1L + +#define LN_sdsiCertificate "sdsiCertificate" +#define NID_sdsiCertificate 159 +#define OBJ_sdsiCertificate OBJ_certTypes, 2L + +#define OBJ_crlTypes OBJ_pkcs9, 23L + +#define LN_x509Crl "x509Crl" +#define NID_x509Crl 160 +#define OBJ_x509Crl OBJ_crlTypes, 1L + +/* PKCS#5 v2 OIDs */ + +#define LN_pbes2 "PBES2" +#define NID_pbes2 161 +#define OBJ_pbes2 OBJ_pkcs,5L,13L + +#define LN_pbmac1 "PBMAC1" +#define NID_pbmac1 162 +#define OBJ_pbmac1 OBJ_pkcs,5L,14L + +#define LN_hmacWithSHA1 "hmacWithSHA1" +#define NID_hmacWithSHA1 163 +#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +/* Policy Qualifier Ids */ + +#define LN_id_qt_cps "Policy Qualifier CPS" +#define SN_id_qt_cps "id-qt-cps" +#define NID_id_qt_cps 164 +#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L + +#define LN_id_qt_unotice "Policy Qualifier User Notice" +#define SN_id_qt_unotice "id-qt-unotice" +#define NID_id_qt_unotice 165 +#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L + +#define SN_rc2_64_cbc "RC2-64-CBC" +#define LN_rc2_64_cbc "rc2-64-cbc" +#define NID_rc2_64_cbc 166 + +#define SN_SMIMECapabilities "SMIME-CAPS" +#define LN_SMIMECapabilities "S/MIME Capabilities" +#define NID_SMIMECapabilities 167 +#define OBJ_SMIMECapabilities OBJ_pkcs9,15L + +#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64" +#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +#define NID_pbeWithMD2AndRC2_CBC 168 +#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L + +#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64" +#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +#define NID_pbeWithMD5AndRC2_CBC 169 +#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L + +#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES" +#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +#define NID_pbeWithSHA1AndDES_CBC 170 +#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L + +/* Extension request OIDs */ + +#define LN_ms_ext_req "Microsoft Extension Request" +#define SN_ms_ext_req "msExtReq" +#define NID_ms_ext_req 171 +#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L + +#define LN_ext_req "Extension Request" +#define SN_ext_req "extReq" +#define NID_ext_req 172 +#define OBJ_ext_req OBJ_pkcs9,14L + +#define SN_name "name" +#define LN_name "name" +#define NID_name 173 +#define OBJ_name OBJ_X509,41L + +#define SN_dnQualifier "dnQualifier" +#define LN_dnQualifier "dnQualifier" +#define NID_dnQualifier 174 +#define OBJ_dnQualifier OBJ_X509,46L + +#define SN_id_pe "id-pe" +#define NID_id_pe 175 +#define OBJ_id_pe OBJ_id_pkix,1L + +#define SN_id_ad "id-ad" +#define NID_id_ad 176 +#define OBJ_id_ad OBJ_id_pkix,48L + +#define SN_info_access "authorityInfoAccess" +#define LN_info_access "Authority Information Access" +#define NID_info_access 177 +#define OBJ_info_access OBJ_id_pe,1L + +#define SN_ad_OCSP "OCSP" +#define LN_ad_OCSP "OCSP" +#define NID_ad_OCSP 178 +#define OBJ_ad_OCSP OBJ_id_ad,1L + +#define SN_ad_ca_issuers "caIssuers" +#define LN_ad_ca_issuers "CA Issuers" +#define NID_ad_ca_issuers 179 +#define OBJ_ad_ca_issuers OBJ_id_ad,2L + +#define SN_OCSP_sign "OCSPSigning" +#define LN_OCSP_sign "OCSP Signing" +#define NID_OCSP_sign 180 +#define OBJ_OCSP_sign OBJ_id_kp,9L +#endif /* USE_OBJ_MAC */ + +#include +#include + +#define OBJ_NAME_TYPE_UNDEF 0x00 +#define OBJ_NAME_TYPE_MD_METH 0x01 +#define OBJ_NAME_TYPE_CIPHER_METH 0x02 +#define OBJ_NAME_TYPE_PKEY_METH 0x03 +#define OBJ_NAME_TYPE_COMP_METH 0x04 +#define OBJ_NAME_TYPE_NUM 0x05 + +#define OBJ_NAME_ALIAS 0x8000 + +#define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 +#define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct obj_name_st + { + int type; + int alias; + const char *name; + const char *data; + } OBJ_NAME; + +#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) + + +int OBJ_NAME_init(void); +int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *), + int (*cmp_func)(const char *, const char *), + void (*free_func)(const char *, int, const char *)); +const char *OBJ_NAME_get(const char *name,int type); +int OBJ_NAME_add(const char *name,int type,const char *data); +int OBJ_NAME_remove(const char *name,int type); +void OBJ_NAME_cleanup(int type); /* -1 for everything */ +void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg), + void *arg); +void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), + void *arg); + +ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o); +ASN1_OBJECT * OBJ_nid2obj(int n); +const char * OBJ_nid2ln(int n); +const char * OBJ_nid2sn(int n); +int OBJ_obj2nid(const ASN1_OBJECT *o); +ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name); +int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); +int OBJ_txt2nid(const char *s); +int OBJ_ln2nid(const char *s); +int OBJ_sn2nid(const char *s); +int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); +const char * OBJ_bsearch(const char *key,const char *base,int num,int size, + int (*cmp)(const void *, const void *)); +const char * OBJ_bsearch_ex(const char *key,const char *base,int num, + int size, int (*cmp)(const void *, const void *), int flags); + +int OBJ_new_nid(int num); +int OBJ_add_object(const ASN1_OBJECT *obj); +int OBJ_create(const char *oid,const char *sn,const char *ln); +void OBJ_cleanup(void ); +int OBJ_create_objects(BIO *in); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_OBJ_strings(void); + +/* Error codes for the OBJ functions. */ + +/* Function codes. */ +#define OBJ_F_OBJ_ADD_OBJECT 105 +#define OBJ_F_OBJ_CREATE 100 +#define OBJ_F_OBJ_DUP 101 +#define OBJ_F_OBJ_NAME_NEW_INDEX 106 +#define OBJ_F_OBJ_NID2LN 102 +#define OBJ_F_OBJ_NID2OBJ 103 +#define OBJ_F_OBJ_NID2SN 104 + +/* Reason codes. */ +#define OBJ_R_MALLOC_FAILURE 100 +#define OBJ_R_UNKNOWN_NID 101 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ocsp.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ocsp.h new file mode 100644 index 0000000..a0577a7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ocsp.h @@ -0,0 +1,623 @@ +/* ocsp.h */ +/* Written by Tom Titchener for the OpenSSL + * project. */ + +/* History: + This file was transfered to Richard Levitte from CertCo by Kathy + Weinhold in mid-spring 2000 to be included in OpenSSL or released + as a patch kit. */ + +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_OCSP_H +#define HEADER_OCSP_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Various flags and values */ + +#define OCSP_DEFAULT_NONCE_LENGTH 16 + +#define OCSP_NOCERTS 0x1 +#define OCSP_NOINTERN 0x2 +#define OCSP_NOSIGS 0x4 +#define OCSP_NOCHAIN 0x8 +#define OCSP_NOVERIFY 0x10 +#define OCSP_NOEXPLICIT 0x20 +#define OCSP_NOCASIGN 0x40 +#define OCSP_NODELEGATED 0x80 +#define OCSP_NOCHECKS 0x100 +#define OCSP_TRUSTOTHER 0x200 +#define OCSP_RESPID_KEY 0x400 +#define OCSP_NOTIME 0x800 + +/* CertID ::= SEQUENCE { + * hashAlgorithm AlgorithmIdentifier, + * issuerNameHash OCTET STRING, -- Hash of Issuer's DN + * issuerKeyHash OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields) + * serialNumber CertificateSerialNumber } + */ +typedef struct ocsp_cert_id_st + { + X509_ALGOR *hashAlgorithm; + ASN1_OCTET_STRING *issuerNameHash; + ASN1_OCTET_STRING *issuerKeyHash; + ASN1_INTEGER *serialNumber; + } OCSP_CERTID; + +DECLARE_STACK_OF(OCSP_CERTID) + +/* Request ::= SEQUENCE { + * reqCert CertID, + * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_one_request_st + { + OCSP_CERTID *reqCert; + STACK_OF(X509_EXTENSION) *singleRequestExtensions; + } OCSP_ONEREQ; + +DECLARE_STACK_OF(OCSP_ONEREQ) +DECLARE_ASN1_SET_OF(OCSP_ONEREQ) + + +/* TBSRequest ::= SEQUENCE { + * version [0] EXPLICIT Version DEFAULT v1, + * requestorName [1] EXPLICIT GeneralName OPTIONAL, + * requestList SEQUENCE OF Request, + * requestExtensions [2] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_req_info_st + { + ASN1_INTEGER *version; + GENERAL_NAME *requestorName; + STACK_OF(OCSP_ONEREQ) *requestList; + STACK_OF(X509_EXTENSION) *requestExtensions; + } OCSP_REQINFO; + +/* Signature ::= SEQUENCE { + * signatureAlgorithm AlgorithmIdentifier, + * signature BIT STRING, + * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } + */ +typedef struct ocsp_signature_st + { + X509_ALGOR *signatureAlgorithm; + ASN1_BIT_STRING *signature; + STACK_OF(X509) *certs; + } OCSP_SIGNATURE; + +/* OCSPRequest ::= SEQUENCE { + * tbsRequest TBSRequest, + * optionalSignature [0] EXPLICIT Signature OPTIONAL } + */ +typedef struct ocsp_request_st + { + OCSP_REQINFO *tbsRequest; + OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */ + } OCSP_REQUEST; + +/* OCSPResponseStatus ::= ENUMERATED { + * successful (0), --Response has valid confirmations + * malformedRequest (1), --Illegal confirmation request + * internalError (2), --Internal error in issuer + * tryLater (3), --Try again later + * --(4) is not used + * sigRequired (5), --Must sign the request + * unauthorized (6) --Request unauthorized + * } + */ +#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 +#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 +#define OCSP_RESPONSE_STATUS_INTERNALERROR 2 +#define OCSP_RESPONSE_STATUS_TRYLATER 3 +#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 +#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 + +/* ResponseBytes ::= SEQUENCE { + * responseType OBJECT IDENTIFIER, + * response OCTET STRING } + */ +typedef struct ocsp_resp_bytes_st + { + ASN1_OBJECT *responseType; + ASN1_OCTET_STRING *response; + } OCSP_RESPBYTES; + +/* OCSPResponse ::= SEQUENCE { + * responseStatus OCSPResponseStatus, + * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } + */ +struct ocsp_response_st + { + ASN1_ENUMERATED *responseStatus; + OCSP_RESPBYTES *responseBytes; + }; + +/* ResponderID ::= CHOICE { + * byName [1] Name, + * byKey [2] KeyHash } + */ +#define V_OCSP_RESPID_NAME 0 +#define V_OCSP_RESPID_KEY 1 +struct ocsp_responder_id_st + { + int type; + union { + X509_NAME* byName; + ASN1_OCTET_STRING *byKey; + } value; + }; + +DECLARE_STACK_OF(OCSP_RESPID) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPID) + +/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key + * --(excluding the tag and length fields) + */ + +/* RevokedInfo ::= SEQUENCE { + * revocationTime GeneralizedTime, + * revocationReason [0] EXPLICIT CRLReason OPTIONAL } + */ +typedef struct ocsp_revoked_info_st + { + ASN1_GENERALIZEDTIME *revocationTime; + ASN1_ENUMERATED *revocationReason; + } OCSP_REVOKEDINFO; + +/* CertStatus ::= CHOICE { + * good [0] IMPLICIT NULL, + * revoked [1] IMPLICIT RevokedInfo, + * unknown [2] IMPLICIT UnknownInfo } + */ +#define V_OCSP_CERTSTATUS_GOOD 0 +#define V_OCSP_CERTSTATUS_REVOKED 1 +#define V_OCSP_CERTSTATUS_UNKNOWN 2 +typedef struct ocsp_cert_status_st + { + int type; + union { + ASN1_NULL *good; + OCSP_REVOKEDINFO *revoked; + ASN1_NULL *unknown; + } value; + } OCSP_CERTSTATUS; + +/* SingleResponse ::= SEQUENCE { + * certID CertID, + * certStatus CertStatus, + * thisUpdate GeneralizedTime, + * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, + * singleExtensions [1] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_single_response_st + { + OCSP_CERTID *certId; + OCSP_CERTSTATUS *certStatus; + ASN1_GENERALIZEDTIME *thisUpdate; + ASN1_GENERALIZEDTIME *nextUpdate; + STACK_OF(X509_EXTENSION) *singleExtensions; + } OCSP_SINGLERESP; + +DECLARE_STACK_OF(OCSP_SINGLERESP) +DECLARE_ASN1_SET_OF(OCSP_SINGLERESP) + +/* ResponseData ::= SEQUENCE { + * version [0] EXPLICIT Version DEFAULT v1, + * responderID ResponderID, + * producedAt GeneralizedTime, + * responses SEQUENCE OF SingleResponse, + * responseExtensions [1] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_response_data_st + { + ASN1_INTEGER *version; + OCSP_RESPID *responderId; + ASN1_GENERALIZEDTIME *producedAt; + STACK_OF(OCSP_SINGLERESP) *responses; + STACK_OF(X509_EXTENSION) *responseExtensions; + } OCSP_RESPDATA; + +/* BasicOCSPResponse ::= SEQUENCE { + * tbsResponseData ResponseData, + * signatureAlgorithm AlgorithmIdentifier, + * signature BIT STRING, + * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } + */ + /* Note 1: + The value for "signature" is specified in the OCSP rfc2560 as follows: + "The value for the signature SHALL be computed on the hash of the DER + encoding ResponseData." This means that you must hash the DER-encoded + tbsResponseData, and then run it through a crypto-signing function, which + will (at least w/RSA) do a hash-'n'-private-encrypt operation. This seems + a bit odd, but that's the spec. Also note that the data structures do not + leave anywhere to independently specify the algorithm used for the initial + hash. So, we look at the signature-specification algorithm, and try to do + something intelligent. -- Kathy Weinhold, CertCo */ + /* Note 2: + It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open + for interpretation. I've done tests against another responder, and found + that it doesn't do the double hashing that the RFC seems to say one + should. Therefore, all relevant functions take a flag saying which + variant should be used. -- Richard Levitte, OpenSSL team and CeloCom */ +typedef struct ocsp_basic_response_st + { + OCSP_RESPDATA *tbsResponseData; + X509_ALGOR *signatureAlgorithm; + ASN1_BIT_STRING *signature; + STACK_OF(X509) *certs; + } OCSP_BASICRESP; + +/* + * CRLReason ::= ENUMERATED { + * unspecified (0), + * keyCompromise (1), + * cACompromise (2), + * affiliationChanged (3), + * superseded (4), + * cessationOfOperation (5), + * certificateHold (6), + * removeFromCRL (8) } + */ +#define OCSP_REVOKED_STATUS_NOSTATUS -1 +#define OCSP_REVOKED_STATUS_UNSPECIFIED 0 +#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 +#define OCSP_REVOKED_STATUS_CACOMPROMISE 2 +#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 +#define OCSP_REVOKED_STATUS_SUPERSEDED 4 +#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 +#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 +#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 + +/* CrlID ::= SEQUENCE { + * crlUrl [0] EXPLICIT IA5String OPTIONAL, + * crlNum [1] EXPLICIT INTEGER OPTIONAL, + * crlTime [2] EXPLICIT GeneralizedTime OPTIONAL } + */ +typedef struct ocsp_crl_id_st + { + ASN1_IA5STRING *crlUrl; + ASN1_INTEGER *crlNum; + ASN1_GENERALIZEDTIME *crlTime; + } OCSP_CRLID; + +/* ServiceLocator ::= SEQUENCE { + * issuer Name, + * locator AuthorityInfoAccessSyntax OPTIONAL } + */ +typedef struct ocsp_service_locator_st + { + X509_NAME* issuer; + STACK_OF(ACCESS_DESCRIPTION) *locator; + } OCSP_SERVICELOC; + +#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" +#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" + +#define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) + +#define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) + +#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL) + +#define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\ + (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL) + +#define PEM_write_bio_OCSP_REQUEST(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +#define PEM_write_bio_OCSP_RESPONSE(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) + +#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) + +#define OCSP_REQUEST_sign(o,pkey,md) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\ + o->optionalSignature->signatureAlgorithm,NULL,\ + o->optionalSignature->signature,o->tbsRequest,pkey,md) + +#define OCSP_BASICRESP_sign(o,pkey,md,d) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),o->signatureAlgorithm,NULL,\ + o->signature,o->tbsResponseData,pkey,md) + +#define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\ + a->optionalSignature->signatureAlgorithm,\ + a->optionalSignature->signature,a->tbsRequest,r) + +#define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\ + a->signatureAlgorithm,a->signature,a->tbsResponseData,r) + +#define ASN1_BIT_STRING_digest(data,type,md,len) \ + ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len) + +#define OCSP_CERTID_dup(cid) ASN1_dup_of(OCSP_CERTID,i2d_OCSP_CERTID,d2i_OCSP_CERTID,cid) + +#define OCSP_CERTSTATUS_dup(cs)\ + (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\ + (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs)) + +OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req); +OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, + int maxline); +int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx); +void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx); + +OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer); + +OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, + X509_NAME *issuerName, + ASN1_BIT_STRING* issuerKey, + ASN1_INTEGER *serialNumber); + +OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid); + +int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len); +int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len); +int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs); +int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req); + +int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm); +int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert); + +int OCSP_request_sign(OCSP_REQUEST *req, + X509 *signer, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs, + unsigned long flags); + +int OCSP_response_status(OCSP_RESPONSE *resp); +OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp); + +int OCSP_resp_count(OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx); +int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last); +int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status, + int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, + ASN1_GENERALIZEDTIME *nextupd, + long sec, long maxsec); + +int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags); + +int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl); + +int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b); +int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b); + +int OCSP_request_onereq_count(OCSP_REQUEST *req); +OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); +OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one); +int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd, + ASN1_OCTET_STRING **pikeyHash, + ASN1_INTEGER **pserial, OCSP_CERTID *cid); +int OCSP_request_is_signed(OCSP_REQUEST *req); +OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, + OCSP_CERTID *cid, + int status, int reason, + ASN1_TIME *revtime, + ASN1_TIME *thisupd, ASN1_TIME *nextupd); +int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert); +int OCSP_basic_sign(OCSP_BASICRESP *brsp, + X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); + +ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d, + void *data, STACK_OF(ASN1_OBJECT) *sk); +#define ASN1_STRING_encode_of(type,s,i2d,data,sk) \ + ASN1_STRING_encode(s, CHECKED_I2D_OF(type, i2d), data, sk) + +X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim); + +X509_EXTENSION *OCSP_accept_responses_new(char **oids); + +X509_EXTENSION *OCSP_archive_cutoff_new(char* tim); + +X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls); + +int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x); +int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos); +int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos); +int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos); +X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc); +X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc); +void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx); +int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc); + +int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x); +int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos); +int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos); +int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos); +X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc); +X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc); +void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx); +int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc); + +int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x); +int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos); +int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos); +int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos); +X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc); +X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc); +void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx); +int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc); + +int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x); +int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos); +int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos); +int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos); +X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc); +X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc); +void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx); +int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc); + +DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS) +DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPID) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES) +DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTID) +DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST) +DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE) +DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_CRLID) +DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC) + +char *OCSP_response_status_str(long s); +char *OCSP_cert_status_str(long s); +char *OCSP_crl_reason_str(long s); + +int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags); +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags); + +int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, + X509_STORE *st, unsigned long flags); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_OCSP_strings(void); + +/* Error codes for the OCSP functions. */ + +/* Function codes. */ +#define OCSP_F_ASN1_STRING_ENCODE 100 +#define OCSP_F_D2I_OCSP_NONCE 102 +#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103 +#define OCSP_F_OCSP_BASIC_SIGN 104 +#define OCSP_F_OCSP_BASIC_VERIFY 105 +#define OCSP_F_OCSP_CERT_ID_NEW 101 +#define OCSP_F_OCSP_CHECK_DELEGATED 106 +#define OCSP_F_OCSP_CHECK_IDS 107 +#define OCSP_F_OCSP_CHECK_ISSUER 108 +#define OCSP_F_OCSP_CHECK_VALIDITY 115 +#define OCSP_F_OCSP_MATCH_ISSUERID 109 +#define OCSP_F_OCSP_PARSE_URL 114 +#define OCSP_F_OCSP_REQUEST_SIGN 110 +#define OCSP_F_OCSP_REQUEST_VERIFY 116 +#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111 +#define OCSP_F_OCSP_SENDREQ_BIO 112 +#define OCSP_F_PARSE_HTTP_LINE1 117 +#define OCSP_F_REQUEST_VERIFY 113 + +/* Reason codes. */ +#define OCSP_R_BAD_DATA 100 +#define OCSP_R_CERTIFICATE_VERIFY_ERROR 101 +#define OCSP_R_DIGEST_ERR 102 +#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122 +#define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123 +#define OCSP_R_ERROR_PARSING_URL 121 +#define OCSP_R_MISSING_OCSPSIGNING_USAGE 103 +#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124 +#define OCSP_R_NOT_BASIC_RESPONSE 104 +#define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105 +#define OCSP_R_NO_CONTENT 106 +#define OCSP_R_NO_PUBLIC_KEY 107 +#define OCSP_R_NO_RESPONSE_DATA 108 +#define OCSP_R_NO_REVOKED_TIME 109 +#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110 +#define OCSP_R_REQUEST_NOT_SIGNED 128 +#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111 +#define OCSP_R_ROOT_CA_NOT_TRUSTED 112 +#define OCSP_R_SERVER_READ_ERROR 113 +#define OCSP_R_SERVER_RESPONSE_ERROR 114 +#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115 +#define OCSP_R_SERVER_WRITE_ERROR 116 +#define OCSP_R_SIGNATURE_FAILURE 117 +#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118 +#define OCSP_R_STATUS_EXPIRED 125 +#define OCSP_R_STATUS_NOT_YET_VALID 126 +#define OCSP_R_STATUS_TOO_OLD 127 +#define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119 +#define OCSP_R_UNKNOWN_NID 120 +#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/opensslconf.h b/石器时代8.5客户端最新源代码/石器源码/openssl/opensslconf.h new file mode 100644 index 0000000..1f4f4b0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/opensslconf.h @@ -0,0 +1,259 @@ +/* opensslconf.h */ +/* WARNING: Generated automatically from opensslconf.h.in by Configure. */ + +/* OpenSSL was configured with the following options: */ +#ifndef OPENSSL_SYSNAME_WIN32 +# define OPENSSL_SYSNAME_WIN32 +#endif +#ifndef OPENSSL_DOING_MAKEDEPEND + + +#ifndef OPENSSL_NO_CAMELLIA +# define OPENSSL_NO_CAMELLIA +#endif +#ifndef OPENSSL_NO_CAPIENG +# define OPENSSL_NO_CAPIENG +#endif +#ifndef OPENSSL_NO_CMS +# define OPENSSL_NO_CMS +#endif +#ifndef OPENSSL_NO_GMP +# define OPENSSL_NO_GMP +#endif +#ifndef OPENSSL_NO_JPAKE +# define OPENSSL_NO_JPAKE +#endif +#ifndef OPENSSL_NO_KRB5 +# define OPENSSL_NO_KRB5 +#endif +#ifndef OPENSSL_NO_MDC2 +# define OPENSSL_NO_MDC2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_NO_RFC3779 +# define OPENSSL_NO_RFC3779 +#endif +#ifndef OPENSSL_NO_SEED +# define OPENSSL_NO_SEED +#endif + +#endif /* OPENSSL_DOING_MAKEDEPEND */ + +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif + +/* The OPENSSL_NO_* macros are also defined as NO_* if the application + asks for it. This is a transient feature that is provided for those + who haven't had the time to do the appropriate changes in their + applications. */ +#ifdef OPENSSL_ALGORITHM_DEFINES +# if defined(OPENSSL_NO_CAMELLIA) && !defined(NO_CAMELLIA) +# define NO_CAMELLIA +# endif +# if defined(OPENSSL_NO_CAPIENG) && !defined(NO_CAPIENG) +# define NO_CAPIENG +# endif +# if defined(OPENSSL_NO_CMS) && !defined(NO_CMS) +# define NO_CMS +# endif +# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP) +# define NO_GMP +# endif +# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE) +# define NO_JPAKE +# endif +# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5) +# define NO_KRB5 +# endif +# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2) +# define NO_MDC2 +# endif +# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5) +# define NO_RC5 +# endif +# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779) +# define NO_RFC3779 +# endif +# if defined(OPENSSL_NO_SEED) && !defined(NO_SEED) +# define NO_SEED +# endif +#endif + +/* crypto/opensslconf.h.in */ + +#ifdef OPENSSL_DOING_MAKEDEPEND + +/* Include any symbols here that have to be explicitly set to enable a feature + * that should be visible to makedepend. + * + * [Our "make depend" doesn't actually look at this, we use actual build settings + * instead; we want to make it easy to remove subdirectories with disabled algorithms.] + */ + +#ifndef OPENSSL_FIPS +#define OPENSSL_FIPS +#endif + +#endif + +/* Generate 80386 code? */ +#undef I386_ONLY + +#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */ +#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR) +#define ENGINESDIR "/usr/local/ssl/lib/engines" +#define OPENSSLDIR "/usr/local/ssl" +#endif +#endif + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD + +#undef OPENSSL_EXPORT_VAR_AS_FUNCTION +#define OPENSSL_EXPORT_VAR_AS_FUNCTION + +#if defined(HEADER_IDEA_H) && !defined(IDEA_INT) +#define IDEA_INT unsigned int +#endif + +#if defined(HEADER_MD2_H) && !defined(MD2_INT) +#define MD2_INT unsigned int +#endif + +#if defined(HEADER_RC2_H) && !defined(RC2_INT) +/* I need to put in a mod for the alpha - eay */ +#define RC2_INT unsigned int +#endif + +#if defined(HEADER_RC4_H) +#if !defined(RC4_INT) +/* using int types make the structure larger but make the code faster + * on most boxes I have tested - up to %20 faster. */ +/* + * I don't know what does "most" mean, but declaring "int" is a must on: + * - Intel P6 because partial register stalls are very expensive; + * - elder Alpha because it lacks byte load/store instructions; + */ +#define RC4_INT unsigned int +#endif +#if !defined(RC4_CHUNK) +/* + * This enables code handling data aligned at natural CPU word + * boundary. See crypto/rc4/rc4_enc.c for further details. + */ +#undef RC4_CHUNK +#endif +#endif + +#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG) +/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a + * %20 speed up (longs are 8 bytes, int's are 4). */ +#ifndef DES_LONG +#define DES_LONG unsigned long +#endif +#endif + +#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H) +#define CONFIG_HEADER_BN_H +#define BN_LLONG + +/* Should we define BN_DIV2W here? */ + +/* Only one for the following should be defined */ +/* The prime number generation stuff may not work when + * EIGHT_BIT but I don't care since I've only used this mode + * for debuging the bignum libraries */ +#undef SIXTY_FOUR_BIT_LONG +#undef SIXTY_FOUR_BIT +#define THIRTY_TWO_BIT +#undef SIXTEEN_BIT +#undef EIGHT_BIT +#endif + +#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) +#define CONFIG_HEADER_RC4_LOCL_H +/* if this is defined data[i] is used instead of *data, this is a %20 + * speedup on x86 */ +#define RC4_INDEX +#endif + +#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) +#define CONFIG_HEADER_BF_LOCL_H +#undef BF_PTR +#endif /* HEADER_BF_LOCL_H */ + +#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H) +#define CONFIG_HEADER_DES_LOCL_H +#ifndef DES_DEFAULT_OPTIONS +/* the following is tweaked from a config script, that is why it is a + * protected undef/define */ +#ifndef DES_PTR +#undef DES_PTR +#endif + +/* This helps C compiler generate the correct code for multiple functional + * units. It reduces register dependancies at the expense of 2 more + * registers */ +#ifndef DES_RISC1 +#undef DES_RISC1 +#endif + +#ifndef DES_RISC2 +#undef DES_RISC2 +#endif + +#if defined(DES_RISC1) && defined(DES_RISC2) +YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!! +#endif + +/* Unroll the inner loop, this sometimes helps, sometimes hinders. + * Very mucy CPU dependant */ +#ifndef DES_UNROLL +#undef DES_UNROLL +#endif + +/* These default values were supplied by + * Peter Gutman + * They are only used if nothing else has been defined */ +#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL) +/* Special defines which change the way the code is built depending on the + CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find + even newer MIPS CPU's, but at the moment one size fits all for + optimization options. Older Sparc's work better with only UNROLL, but + there's no way to tell at compile time what it is you're running on */ + +#if defined( sun ) /* Newer Sparc's */ +# define DES_PTR +# define DES_RISC1 +# define DES_UNROLL +#elif defined( __ultrix ) /* Older MIPS */ +# define DES_PTR +# define DES_RISC2 +# define DES_UNROLL +#elif defined( __osf1__ ) /* Alpha */ +# define DES_PTR +# define DES_RISC2 +#elif defined ( _AIX ) /* RS6000 */ + /* Unknown */ +#elif defined( __hpux ) /* HP-PA */ + /* Unknown */ +#elif defined( __aux ) /* 68K */ + /* Unknown */ +#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ +# define DES_UNROLL +#elif defined( __sgi ) /* Newer MIPS */ +# define DES_PTR +# define DES_RISC2 +# define DES_UNROLL +#elif defined(i386) || defined(__i386__) /* x86 boxes, should be gcc */ +# define DES_PTR +# define DES_RISC1 +# define DES_UNROLL +#endif /* Systems-specific speed defines */ +#endif + +#endif /* DES_DEFAULT_OPTIONS */ +#endif /* HEADER_DES_LOCL_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/opensslv.h b/石器时代8.5客户端最新源代码/石器源码/openssl/opensslv.h new file mode 100644 index 0000000..c6207f7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/opensslv.h @@ -0,0 +1,89 @@ +#ifndef HEADER_OPENSSLV_H +#define HEADER_OPENSSLV_H + +/* Numeric release version identifier: + * MNNFFPPS: major minor fix patch status + * The status nibble has one of the values 0 for development, 1 to e for betas + * 1 to 14, and f for release. The patch level is exactly that. + * For example: + * 0.9.3-dev 0x00903000 + * 0.9.3-beta1 0x00903001 + * 0.9.3-beta2-dev 0x00903002 + * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) + * 0.9.3 0x0090300f + * 0.9.3a 0x0090301f + * 0.9.4 0x0090400f + * 1.2.3z 0x102031af + * + * For continuity reasons (because 0.9.5 is already out, and is coded + * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level + * part is slightly different, by setting the highest bit. This means + * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start + * with 0x0090600S... + * + * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) + * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for + * major minor fix final patch/beta) + */ +#define OPENSSL_VERSION_NUMBER 0x009080bfL +#ifdef OPENSSL_FIPS +#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.8k-fips 25 Mar 2009" +#else +#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.8k 25 Mar 2009" +#endif +#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT + + +/* The macros below are to be used for shared library (.so, .dll, ...) + * versioning. That kind of versioning works a bit differently between + * operating systems. The most usual scheme is to set a major and a minor + * number, and have the runtime loader check that the major number is equal + * to what it was at application link time, while the minor number has to + * be greater or equal to what it was at application link time. With this + * scheme, the version number is usually part of the file name, like this: + * + * libcrypto.so.0.9 + * + * Some unixen also make a softlink with the major verson number only: + * + * libcrypto.so.0 + * + * On Tru64 and IRIX 6.x it works a little bit differently. There, the + * shared library version is stored in the file, and is actually a series + * of versions, separated by colons. The rightmost version present in the + * library when linking an application is stored in the application to be + * matched at run time. When the application is run, a check is done to + * see if the library version stored in the application matches any of the + * versions in the version string of the library itself. + * This version string can be constructed in any way, depending on what + * kind of matching is desired. However, to implement the same scheme as + * the one used in the other unixen, all compatible versions, from lowest + * to highest, should be part of the string. Consecutive builds would + * give the following versions strings: + * + * 3.0 + * 3.0:3.1 + * 3.0:3.1:3.2 + * 4.0 + * 4.0:4.1 + * + * Notice how version 4 is completely incompatible with version, and + * therefore give the breach you can see. + * + * There may be other schemes as well that I haven't yet discovered. + * + * So, here's the way it works here: first of all, the library version + * number doesn't need at all to match the overall OpenSSL version. + * However, it's nice and more understandable if it actually does. + * The current library version is stored in the macro SHLIB_VERSION_NUMBER, + * which is just a piece of text in the format "M.m.e" (Major, minor, edit). + * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, + * we need to keep a history of version numbers, which is done in the + * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and + * should only keep the versions that are binary compatible with the current. + */ +#define SHLIB_VERSION_HISTORY "" +#define SHLIB_VERSION_NUMBER "0.9.8" + + +#endif /* HEADER_OPENSSLV_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ossl_typ.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ossl_typ.h new file mode 100644 index 0000000..0e7a380 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ossl_typ.h @@ -0,0 +1,183 @@ +/* ==================================================================== + * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_OPENSSL_TYPES_H +#define HEADER_OPENSSL_TYPES_H + +#include + +#ifdef NO_ASN1_TYPEDEFS +#define ASN1_INTEGER ASN1_STRING +#define ASN1_ENUMERATED ASN1_STRING +#define ASN1_BIT_STRING ASN1_STRING +#define ASN1_OCTET_STRING ASN1_STRING +#define ASN1_PRINTABLESTRING ASN1_STRING +#define ASN1_T61STRING ASN1_STRING +#define ASN1_IA5STRING ASN1_STRING +#define ASN1_UTCTIME ASN1_STRING +#define ASN1_GENERALIZEDTIME ASN1_STRING +#define ASN1_TIME ASN1_STRING +#define ASN1_GENERALSTRING ASN1_STRING +#define ASN1_UNIVERSALSTRING ASN1_STRING +#define ASN1_BMPSTRING ASN1_STRING +#define ASN1_VISIBLESTRING ASN1_STRING +#define ASN1_UTF8STRING ASN1_STRING +#define ASN1_BOOLEAN int +#define ASN1_NULL int +#else +typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_ENUMERATED; +typedef struct asn1_string_st ASN1_BIT_STRING; +typedef struct asn1_string_st ASN1_OCTET_STRING; +typedef struct asn1_string_st ASN1_PRINTABLESTRING; +typedef struct asn1_string_st ASN1_T61STRING; +typedef struct asn1_string_st ASN1_IA5STRING; +typedef struct asn1_string_st ASN1_GENERALSTRING; +typedef struct asn1_string_st ASN1_UNIVERSALSTRING; +typedef struct asn1_string_st ASN1_BMPSTRING; +typedef struct asn1_string_st ASN1_UTCTIME; +typedef struct asn1_string_st ASN1_TIME; +typedef struct asn1_string_st ASN1_GENERALIZEDTIME; +typedef struct asn1_string_st ASN1_VISIBLESTRING; +typedef struct asn1_string_st ASN1_UTF8STRING; +typedef int ASN1_BOOLEAN; +typedef int ASN1_NULL; +#endif + +#ifdef OPENSSL_SYS_WIN32 +#undef X509_NAME +#undef X509_EXTENSIONS +#undef X509_CERT_PAIR +#undef PKCS7_ISSUER_AND_SERIAL +#undef OCSP_REQUEST +#undef OCSP_RESPONSE +#endif + +#ifdef BIGNUM +#undef BIGNUM +#endif +typedef struct bignum_st BIGNUM; +typedef struct bignum_ctx BN_CTX; +typedef struct bn_blinding_st BN_BLINDING; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_gencb_st BN_GENCB; + +typedef struct buf_mem_st BUF_MEM; + +typedef struct evp_cipher_st EVP_CIPHER; +typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; +typedef struct env_md_st EVP_MD; +typedef struct env_md_ctx_st EVP_MD_CTX; +typedef struct evp_pkey_st EVP_PKEY; + +typedef struct dh_st DH; +typedef struct dh_method DH_METHOD; + +typedef struct dsa_st DSA; +typedef struct dsa_method DSA_METHOD; + +typedef struct rsa_st RSA; +typedef struct rsa_meth_st RSA_METHOD; + +typedef struct rand_meth_st RAND_METHOD; + +typedef struct ecdh_method ECDH_METHOD; +typedef struct ecdsa_method ECDSA_METHOD; + +typedef struct x509_st X509; +typedef struct X509_algor_st X509_ALGOR; +typedef struct X509_crl_st X509_CRL; +typedef struct X509_name_st X509_NAME; +typedef struct x509_store_st X509_STORE; +typedef struct x509_store_ctx_st X509_STORE_CTX; +typedef struct ssl_st SSL; +typedef struct ssl_ctx_st SSL_CTX; + +typedef struct v3_ext_ctx X509V3_CTX; +typedef struct conf_st CONF; + +typedef struct store_st STORE; +typedef struct store_method_st STORE_METHOD; + +typedef struct ui_st UI; +typedef struct ui_method_st UI_METHOD; + +typedef struct st_ERR_FNS ERR_FNS; + +typedef struct engine_st ENGINE; + +typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; +typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; +typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; +typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; + + /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */ +#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */ +#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */ + +typedef struct crypto_ex_data_st CRYPTO_EX_DATA; +/* Callback types for crypto.h */ +typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, + int idx, long argl, void *argp); + +typedef struct ocsp_req_ctx_st OCSP_REQ_CTX; +typedef struct ocsp_response_st OCSP_RESPONSE; +typedef struct ocsp_responder_id_st OCSP_RESPID; + +#endif /* def HEADER_OPENSSL_TYPES_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pem.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pem.h new file mode 100644 index 0000000..6c193f1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pem.h @@ -0,0 +1,782 @@ +/* crypto/pem/pem.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_PEM_H +#define HEADER_PEM_H + +#include +#ifndef OPENSSL_NO_BIO +#include +#endif +#ifndef OPENSSL_NO_STACK +#include +#endif +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PEM_BUFSIZE 1024 + +#define PEM_OBJ_UNDEF 0 +#define PEM_OBJ_X509 1 +#define PEM_OBJ_X509_REQ 2 +#define PEM_OBJ_CRL 3 +#define PEM_OBJ_SSL_SESSION 4 +#define PEM_OBJ_PRIV_KEY 10 +#define PEM_OBJ_PRIV_RSA 11 +#define PEM_OBJ_PRIV_DSA 12 +#define PEM_OBJ_PRIV_DH 13 +#define PEM_OBJ_PUB_RSA 14 +#define PEM_OBJ_PUB_DSA 15 +#define PEM_OBJ_PUB_DH 16 +#define PEM_OBJ_DHPARAMS 17 +#define PEM_OBJ_DSAPARAMS 18 +#define PEM_OBJ_PRIV_RSA_PUBLIC 19 +#define PEM_OBJ_PRIV_ECDSA 20 +#define PEM_OBJ_PUB_ECDSA 21 +#define PEM_OBJ_ECPARAMETERS 22 + +#define PEM_ERROR 30 +#define PEM_DEK_DES_CBC 40 +#define PEM_DEK_IDEA_CBC 45 +#define PEM_DEK_DES_EDE 50 +#define PEM_DEK_DES_ECB 60 +#define PEM_DEK_RSA 70 +#define PEM_DEK_RSA_MD2 80 +#define PEM_DEK_RSA_MD5 90 + +#define PEM_MD_MD2 NID_md2 +#define PEM_MD_MD5 NID_md5 +#define PEM_MD_SHA NID_sha +#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption +#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption +#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption + +#define PEM_STRING_X509_OLD "X509 CERTIFICATE" +#define PEM_STRING_X509 "CERTIFICATE" +#define PEM_STRING_X509_PAIR "CERTIFICATE PAIR" +#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" +#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" +#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" +#define PEM_STRING_X509_CRL "X509 CRL" +#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" +#define PEM_STRING_PUBLIC "PUBLIC KEY" +#define PEM_STRING_RSA "RSA PRIVATE KEY" +#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" +#define PEM_STRING_DSA "DSA PRIVATE KEY" +#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" +#define PEM_STRING_PKCS7 "PKCS7" +#define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" +#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" +#define PEM_STRING_PKCS8INF "PRIVATE KEY" +#define PEM_STRING_DHPARAMS "DH PARAMETERS" +#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" +#define PEM_STRING_DSAPARAMS "DSA PARAMETERS" +#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" +#define PEM_STRING_ECPARAMETERS "EC PARAMETERS" +#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" +#define PEM_STRING_CMS "CMS" + + /* Note that this structure is initialised by PEM_SealInit and cleaned up + by PEM_SealFinal (at least for now) */ +typedef struct PEM_Encode_Seal_st + { + EVP_ENCODE_CTX encode; + EVP_MD_CTX md; + EVP_CIPHER_CTX cipher; + } PEM_ENCODE_SEAL_CTX; + +/* enc_type is one off */ +#define PEM_TYPE_ENCRYPTED 10 +#define PEM_TYPE_MIC_ONLY 20 +#define PEM_TYPE_MIC_CLEAR 30 +#define PEM_TYPE_CLEAR 40 + +typedef struct pem_recip_st + { + char *name; + X509_NAME *dn; + + int cipher; + int key_enc; + /* char iv[8]; unused and wrong size */ + } PEM_USER; + +typedef struct pem_ctx_st + { + int type; /* what type of object */ + + struct { + int version; + int mode; + } proc_type; + + char *domain; + + struct { + int cipher; + /* unused, and wrong size + unsigned char iv[8]; */ + } DEK_info; + + PEM_USER *originator; + + int num_recipient; + PEM_USER **recipient; + +#ifndef OPENSSL_NO_STACK + STACK *x509_chain; /* certificate chain */ +#else + char *x509_chain; /* certificate chain */ +#endif + EVP_MD *md; /* signature type */ + + int md_enc; /* is the md encrypted or not? */ + int md_len; /* length of md_data */ + char *md_data; /* message digest, could be pkey encrypted */ + + EVP_CIPHER *dec; /* date encryption cipher */ + int key_len; /* key length */ + unsigned char *key; /* key */ + /* unused, and wrong size + unsigned char iv[8]; */ + + + int data_enc; /* is the data encrypted */ + int data_len; + unsigned char *data; + } PEM_CTX; + +/* These macros make the PEM_read/PEM_write functions easier to maintain and + * write. Now they are all implemented with either: + * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) + */ + +#ifdef OPENSSL_NO_FP_API + +#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ + +#else + +#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ +type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ +{ \ + return (type*)PEM_ASN1_read(CHECKED_D2I_OF(type, d2i_##asn1), \ + str, fp, \ + CHECKED_PPTR_OF(type, x), \ + cb, u); \ +} + +#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x) \ +{ \ + return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ + str, fp, \ + CHECKED_PTR_OF(type, x), \ + NULL, NULL, 0, NULL, NULL); \ +} + +#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, const type *x) \ +{ \ + return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ + str, fp, \ + CHECKED_PTR_OF(const type, x), \ + NULL, NULL, 0, NULL, NULL); \ +} + +#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ + str, fp, \ + CHECKED_PTR_OF(type, x), \ + enc, kstr, klen, cb, u); \ + } + +#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ + str, fp, \ + CHECKED_PTR_OF(const type, x), \ + enc, kstr, klen, cb, u); \ + } + +#endif + +#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ +type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ +{ \ + return (type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i_##asn1), \ + str, bp, \ + CHECKED_PPTR_OF(type, x), \ + cb, u); \ +} + +#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x) \ +{ \ + return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ + str, bp, \ + CHECKED_PTR_OF(type, x), \ + NULL, NULL, 0, NULL, NULL); \ +} + +#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, const type *x) \ +{ \ + return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ + str, bp, \ + CHECKED_PTR_OF(const type, x), \ + NULL, NULL, 0, NULL, NULL); \ +} + +#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ + str, bp, \ + CHECKED_PTR_OF(type, x), \ + enc, kstr, klen, cb, u); \ + } + +#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ + str, bp, \ + CHECKED_PTR_OF(const type, x), \ + enc, kstr, klen, cb, u); \ + } + +#define IMPLEMENT_PEM_write(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) + +#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) + +#define IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_read_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_rw(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write(name, type, str, asn1) + +#define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_const(name, type, str, asn1) + +#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb(name, type, str, asn1) + +/* These are the same except they are for the declarations */ + +#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API) + +#define DECLARE_PEM_read_fp(name, type) /**/ +#define DECLARE_PEM_write_fp(name, type) /**/ +#define DECLARE_PEM_write_fp_const(name, type) /**/ +#define DECLARE_PEM_write_cb_fp(name, type) /**/ + +#else + +#define DECLARE_PEM_read_fp(name, type) \ + type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); + +#define DECLARE_PEM_write_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x); + +#define DECLARE_PEM_write_fp_const(name, type) \ + int PEM_write_##name(FILE *fp, const type *x); + +#define DECLARE_PEM_write_cb_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +#endif + +#ifndef OPENSSL_NO_BIO +#define DECLARE_PEM_read_bio(name, type) \ + type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); + +#define DECLARE_PEM_write_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x); + +#define DECLARE_PEM_write_bio_const(name, type) \ + int PEM_write_bio_##name(BIO *bp, const type *x); + +#define DECLARE_PEM_write_cb_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +#else + +#define DECLARE_PEM_read_bio(name, type) /**/ +#define DECLARE_PEM_write_bio(name, type) /**/ +#define DECLARE_PEM_write_bio_const(name, type) /**/ +#define DECLARE_PEM_write_cb_bio(name, type) /**/ + +#endif + +#define DECLARE_PEM_write(name, type) \ + DECLARE_PEM_write_bio(name, type) \ + DECLARE_PEM_write_fp(name, type) + +#define DECLARE_PEM_write_const(name, type) \ + DECLARE_PEM_write_bio_const(name, type) \ + DECLARE_PEM_write_fp_const(name, type) + +#define DECLARE_PEM_write_cb(name, type) \ + DECLARE_PEM_write_cb_bio(name, type) \ + DECLARE_PEM_write_cb_fp(name, type) + +#define DECLARE_PEM_read(name, type) \ + DECLARE_PEM_read_bio(name, type) \ + DECLARE_PEM_read_fp(name, type) + +#define DECLARE_PEM_rw(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write(name, type) + +#define DECLARE_PEM_rw_const(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_const(name, type) + +#define DECLARE_PEM_rw_cb(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_cb(name, type) + +#ifdef SSLEAY_MACROS + +#define PEM_write_SSL_SESSION(fp,x) \ + PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ + PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_X509(fp,x) \ + PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ + (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ + (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ + NULL,NULL,0,NULL,NULL) +#define PEM_write_X509_CRL(fp,x) \ + PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ + fp,(char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ + (char *)x,enc,kstr,klen,cb,u) +#define PEM_write_RSAPublicKey(fp,x) \ + PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ + PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL) +#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ + (char *)x,enc,kstr,klen,cb,u) +#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write((int (*)())i2d_PrivateKey,\ + (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ + bp,(char *)x,enc,kstr,klen,cb,u) +#define PEM_write_PKCS7(fp,x) \ + PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ + (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_DHparams(fp,x) \ + PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ + (char *)x,NULL,NULL,0,NULL,NULL) + +#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \ + PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ + PEM_STRING_X509,fp, \ + (char *)x, NULL,NULL,0,NULL,NULL) + +#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ + (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) +#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \ + (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u) +#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \ + (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u) +#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \ + (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u) +#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ + (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u) +#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ + (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u) +#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \ + (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u) +#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \ + (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u) +#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \ + (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u) +#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \ + (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u) + +#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \ + (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \ + (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ + (char **)x,cb,u) + +#define PEM_write_bio_X509(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ + (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ + (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ + NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_X509_CRL(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ + bp,(char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ + bp,(char *)x,enc,kstr,klen,cb,u) +#define PEM_write_bio_RSAPublicKey(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ + PEM_STRING_RSA_PUBLIC,\ + bp,(char *)x,NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ + bp,(char *)x,enc,kstr,klen,cb,u) +#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ + PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ + (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ + bp,(char *)x,enc,kstr,klen,cb,u) +#define PEM_write_bio_PKCS7(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ + (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_DHparams(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ + bp,(char *)x,NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_DSAparams(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ + PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL) + +#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ + PEM_STRING_X509,bp, \ + (char *)x, NULL,NULL,0,NULL,NULL) + +#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) +#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u) +#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u) +#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u) +#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u) +#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u) +#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u) + +#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u) +#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u) +#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u) + +#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \ + (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\ + (char **)x,cb,u) + +#endif + +#if 1 +/* "userdata": new with OpenSSL 0.9.4 */ +typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); +#else +/* OpenSSL 0.9.3, 0.9.3a */ +typedef int pem_password_cb(char *buf, int size, int rwflag); +#endif + +int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); +int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, + pem_password_cb *callback,void *u); + +#ifndef OPENSSL_NO_BIO +int PEM_read_bio(BIO *bp, char **name, char **header, + unsigned char **data,long *len); +int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data, + long len); +int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, + pem_password_cb *cb, void *u); +void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, + void **x, pem_password_cb *cb, void *u); + +#define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \ + ((type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i), \ + name, bp, \ + CHECKED_PPTR_OF(type, x), \ + cb, u)) + +int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x, + const EVP_CIPHER *enc,unsigned char *kstr,int klen, + pem_password_cb *cb, void *u); + +#define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \ + (PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d), \ + name, bp, \ + CHECKED_PTR_OF(type, x), \ + enc, kstr, klen, cb, u)) + +STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); +int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, + unsigned char *kstr, int klen, pem_password_cb *cd, void *u); +#endif + +#ifndef OPENSSL_SYS_WIN16 +int PEM_read(FILE *fp, char **name, char **header, + unsigned char **data,long *len); +int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); +void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, + char *x,const EVP_CIPHER *enc,unsigned char *kstr, + int klen,pem_password_cb *callback, void *u); +STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); +#endif + +int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, + EVP_MD *md_type, unsigned char **ek, int *ekl, + unsigned char *iv, EVP_PKEY **pubk, int npubk); +void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl); +int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, + unsigned char *out, int *outl, EVP_PKEY *priv); + +void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); +void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); +int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, + unsigned int *siglen, EVP_PKEY *pkey); + +int PEM_def_callback(char *buf, int num, int w, void *key); +void PEM_proc_type(char *buf, int type); +void PEM_dek_info(char *buf, const char *type, int len, char *str); + +#ifndef SSLEAY_MACROS + +#include + +DECLARE_PEM_rw(X509, X509) + +DECLARE_PEM_rw(X509_AUX, X509) + +DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR) + +DECLARE_PEM_rw(X509_REQ, X509_REQ) +DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) + +DECLARE_PEM_rw(X509_CRL, X509_CRL) + +DECLARE_PEM_rw(PKCS7, PKCS7) + +DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) + +DECLARE_PEM_rw(PKCS8, X509_SIG) + +DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) + +#ifndef OPENSSL_NO_RSA + +DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) + +DECLARE_PEM_rw_const(RSAPublicKey, RSA) +DECLARE_PEM_rw(RSA_PUBKEY, RSA) + +#endif + +#ifndef OPENSSL_NO_DSA + +DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) + +DECLARE_PEM_rw(DSA_PUBKEY, DSA) + +DECLARE_PEM_rw_const(DSAparams, DSA) + +#endif + +#ifndef OPENSSL_NO_EC +DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) +DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) +DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) +#endif + +#ifndef OPENSSL_NO_DH + +DECLARE_PEM_rw_const(DHparams, DH) + +#endif + +DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) + +DECLARE_PEM_rw(PUBKEY, EVP_PKEY) + +int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, + char *, int, pem_password_cb *, void *); +int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); + +int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); + +EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); + +int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, + char *kstr,int klen, pem_password_cb *cd, void *u); + +#endif /* SSLEAY_MACROS */ + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_PEM_strings(void); + +/* Error codes for the PEM functions. */ + +/* Function codes. */ +#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 +#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 +#define PEM_F_DO_PK8PKEY 126 +#define PEM_F_DO_PK8PKEY_FP 125 +#define PEM_F_LOAD_IV 101 +#define PEM_F_PEM_ASN1_READ 102 +#define PEM_F_PEM_ASN1_READ_BIO 103 +#define PEM_F_PEM_ASN1_WRITE 104 +#define PEM_F_PEM_ASN1_WRITE_BIO 105 +#define PEM_F_PEM_DEF_CALLBACK 100 +#define PEM_F_PEM_DO_HEADER 106 +#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 +#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 +#define PEM_F_PEM_PK8PKEY 119 +#define PEM_F_PEM_READ 108 +#define PEM_F_PEM_READ_BIO 109 +#define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 +#define PEM_F_PEM_READ_PRIVATEKEY 124 +#define PEM_F_PEM_SEALFINAL 110 +#define PEM_F_PEM_SEALINIT 111 +#define PEM_F_PEM_SIGNFINAL 112 +#define PEM_F_PEM_WRITE 113 +#define PEM_F_PEM_WRITE_BIO 114 +#define PEM_F_PEM_X509_INFO_READ 115 +#define PEM_F_PEM_X509_INFO_READ_BIO 116 +#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 + +/* Reason codes. */ +#define PEM_R_BAD_BASE64_DECODE 100 +#define PEM_R_BAD_DECRYPT 101 +#define PEM_R_BAD_END_LINE 102 +#define PEM_R_BAD_IV_CHARS 103 +#define PEM_R_BAD_PASSWORD_READ 104 +#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 +#define PEM_R_NOT_DEK_INFO 105 +#define PEM_R_NOT_ENCRYPTED 106 +#define PEM_R_NOT_PROC_TYPE 107 +#define PEM_R_NO_START_LINE 108 +#define PEM_R_PROBLEMS_GETTING_PASSWORD 109 +#define PEM_R_PUBLIC_KEY_NO_RSA 110 +#define PEM_R_READ_KEY 111 +#define PEM_R_SHORT_HEADER 112 +#define PEM_R_UNSUPPORTED_CIPHER 113 +#define PEM_R_UNSUPPORTED_ENCRYPTION 114 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pem2.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pem2.h new file mode 100644 index 0000000..f31790d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pem2.h @@ -0,0 +1,70 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * This header only exists to break a circular dependency between pem and err + * Ben 30 Jan 1999. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HEADER_PEM_H +void ERR_load_PEM_strings(void); +#endif + +#ifdef __cplusplus +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs12.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs12.h new file mode 100644 index 0000000..4bee605 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs12.h @@ -0,0 +1,333 @@ +/* pkcs12.h */ +/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_PKCS12_H +#define HEADER_PKCS12_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PKCS12_KEY_ID 1 +#define PKCS12_IV_ID 2 +#define PKCS12_MAC_ID 3 + +/* Default iteration count */ +#ifndef PKCS12_DEFAULT_ITER +#define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER +#endif + +#define PKCS12_MAC_KEY_LENGTH 20 + +#define PKCS12_SALT_LEN 8 + +/* Uncomment out next line for unicode password and names, otherwise ASCII */ + +/*#define PBE_UNICODE*/ + +#ifdef PBE_UNICODE +#define PKCS12_key_gen PKCS12_key_gen_uni +#define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni +#else +#define PKCS12_key_gen PKCS12_key_gen_asc +#define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc +#endif + +/* MS key usage constants */ + +#define KEY_EX 0x10 +#define KEY_SIG 0x80 + +typedef struct { +X509_SIG *dinfo; +ASN1_OCTET_STRING *salt; +ASN1_INTEGER *iter; /* defaults to 1 */ +} PKCS12_MAC_DATA; + +typedef struct { +ASN1_INTEGER *version; +PKCS12_MAC_DATA *mac; +PKCS7 *authsafes; +} PKCS12; + +PREDECLARE_STACK_OF(PKCS12_SAFEBAG) + +typedef struct { +ASN1_OBJECT *type; +union { + struct pkcs12_bag_st *bag; /* secret, crl and certbag */ + struct pkcs8_priv_key_info_st *keybag; /* keybag */ + X509_SIG *shkeybag; /* shrouded key bag */ + STACK_OF(PKCS12_SAFEBAG) *safes; + ASN1_TYPE *other; +}value; +STACK_OF(X509_ATTRIBUTE) *attrib; +} PKCS12_SAFEBAG; + +DECLARE_STACK_OF(PKCS12_SAFEBAG) +DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG) +DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG) + +typedef struct pkcs12_bag_st { +ASN1_OBJECT *type; +union { + ASN1_OCTET_STRING *x509cert; + ASN1_OCTET_STRING *x509crl; + ASN1_OCTET_STRING *octet; + ASN1_IA5STRING *sdsicert; + ASN1_TYPE *other; /* Secret or other bag */ +}value; +} PKCS12_BAGS; + +#define PKCS12_ERROR 0 +#define PKCS12_OK 1 + +/* Compatibility macros */ + +#define M_PKCS12_x5092certbag PKCS12_x5092certbag +#define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag + +#define M_PKCS12_certbag2x509 PKCS12_certbag2x509 +#define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl + +#define M_PKCS12_unpack_p7data PKCS12_unpack_p7data +#define M_PKCS12_pack_authsafes PKCS12_pack_authsafes +#define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes +#define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata + +#define M_PKCS12_decrypt_skey PKCS12_decrypt_skey +#define M_PKCS8_decrypt PKCS8_decrypt + +#define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type) +#define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type) +#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type + +#define PKCS12_get_attr(bag, attr_nid) \ + PKCS12_get_attr_gen(bag->attrib, attr_nid) + +#define PKCS8_get_attr(p8, attr_nid) \ + PKCS12_get_attr_gen(p8->attributes, attr_nid) + +#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0) + + +PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509); +PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl); +X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag); +X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag); + +PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1, + int nid2); +PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8); +PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen); +PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass, + int passlen); +X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, + const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8); +PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, + int passlen, unsigned char *salt, + int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8); +PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); +PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + STACK_OF(PKCS12_SAFEBAG) *bags); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen); + +int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); +STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12); + +int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen); +int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name, + int namelen); +int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); +ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid); +char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); +unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, + int passlen, unsigned char *in, int inlen, + unsigned char **data, int *datalen, int en_de); +void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, + const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf); +ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it, + const char *pass, int passlen, + void *obj, int zbuf); +PKCS12 *PKCS12_init(int mode); +int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type); +int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type, + int en_de); +int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *mac, unsigned int *maclen); +int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); +int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + const EVP_MD *md_type); +int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, + int saltlen, const EVP_MD *md_type); +unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen); +char *uni2asc(unsigned char *uni, int unilen); + +DECLARE_ASN1_FUNCTIONS(PKCS12) +DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA) +DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG) +DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS) + +DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS) +DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) + +void PKCS12_PBE_add(void); +int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, + STACK_OF(X509) **ca); +PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, + STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, + int mac_iter, int keytype); + +PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert); +PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key, + int key_usage, int iter, + int key_nid, char *pass); +int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, + int safe_nid, int iter, char *pass); +PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid); + +int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); +int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); +PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); +PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); +int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_PKCS12_strings(void); + +/* Error codes for the PKCS12 functions. */ + +/* Function codes. */ +#define PKCS12_F_PARSE_BAG 129 +#define PKCS12_F_PARSE_BAGS 103 +#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100 +#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127 +#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102 +#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104 +#define PKCS12_F_PKCS12_CREATE 105 +#define PKCS12_F_PKCS12_GEN_MAC 107 +#define PKCS12_F_PKCS12_INIT 109 +#define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106 +#define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108 +#define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117 +#define PKCS12_F_PKCS12_KEY_GEN_ASC 110 +#define PKCS12_F_PKCS12_KEY_GEN_UNI 111 +#define PKCS12_F_PKCS12_MAKE_KEYBAG 112 +#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113 +#define PKCS12_F_PKCS12_NEWPASS 128 +#define PKCS12_F_PKCS12_PACK_P7DATA 114 +#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 +#define PKCS12_F_PKCS12_PARSE 118 +#define PKCS12_F_PKCS12_PBE_CRYPT 119 +#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 +#define PKCS12_F_PKCS12_SETUP_MAC 122 +#define PKCS12_F_PKCS12_SET_MAC 123 +#define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130 +#define PKCS12_F_PKCS12_UNPACK_P7DATA 131 +#define PKCS12_F_PKCS12_VERIFY_MAC 126 +#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124 +#define PKCS12_F_PKCS8_ENCRYPT 125 + +/* Reason codes. */ +#define PKCS12_R_CANT_PACK_STRUCTURE 100 +#define PKCS12_R_CONTENT_TYPE_NOT_DATA 121 +#define PKCS12_R_DECODE_ERROR 101 +#define PKCS12_R_ENCODE_ERROR 102 +#define PKCS12_R_ENCRYPT_ERROR 103 +#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120 +#define PKCS12_R_INVALID_NULL_ARGUMENT 104 +#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 +#define PKCS12_R_IV_GEN_ERROR 106 +#define PKCS12_R_KEY_GEN_ERROR 107 +#define PKCS12_R_MAC_ABSENT 108 +#define PKCS12_R_MAC_GENERATION_ERROR 109 +#define PKCS12_R_MAC_SETUP_ERROR 110 +#define PKCS12_R_MAC_STRING_SET_ERROR 111 +#define PKCS12_R_MAC_VERIFY_ERROR 112 +#define PKCS12_R_MAC_VERIFY_FAILURE 113 +#define PKCS12_R_PARSE_ERROR 114 +#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115 +#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116 +#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117 +#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118 +#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs7.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs7.h new file mode 100644 index 0000000..cc092d2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pkcs7.h @@ -0,0 +1,464 @@ +/* crypto/pkcs7/pkcs7.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_PKCS7_H +#define HEADER_PKCS7_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_SYS_WIN32 +/* Under Win32 thes are defined in wincrypt.h */ +#undef PKCS7_ISSUER_AND_SERIAL +#undef PKCS7_SIGNER_INFO +#endif + +/* +Encryption_ID DES-CBC +Digest_ID MD5 +Digest_Encryption_ID rsaEncryption +Key_Encryption_ID rsaEncryption +*/ + +typedef struct pkcs7_issuer_and_serial_st + { + X509_NAME *issuer; + ASN1_INTEGER *serial; + } PKCS7_ISSUER_AND_SERIAL; + +typedef struct pkcs7_signer_info_st + { + ASN1_INTEGER *version; /* version 1 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *digest_alg; + STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ + X509_ALGOR *digest_enc_alg; + ASN1_OCTET_STRING *enc_digest; + STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ + + /* The private key to sign with */ + EVP_PKEY *pkey; + } PKCS7_SIGNER_INFO; + +DECLARE_STACK_OF(PKCS7_SIGNER_INFO) +DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) + +typedef struct pkcs7_recip_info_st + { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *key_enc_algor; + ASN1_OCTET_STRING *enc_key; + X509 *cert; /* get the pub-key from this */ + } PKCS7_RECIP_INFO; + +DECLARE_STACK_OF(PKCS7_RECIP_INFO) +DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) + +typedef struct pkcs7_signed_st + { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + + struct pkcs7_st *contents; + } PKCS7_SIGNED; +/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE. + * How about merging the two */ + +typedef struct pkcs7_enc_content_st + { + ASN1_OBJECT *content_type; + X509_ALGOR *algorithm; + ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ + const EVP_CIPHER *cipher; + } PKCS7_ENC_CONTENT; + +typedef struct pkcs7_enveloped_st + { + ASN1_INTEGER *version; /* version 0 */ + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; + PKCS7_ENC_CONTENT *enc_data; + } PKCS7_ENVELOPE; + +typedef struct pkcs7_signedandenveloped_st + { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + + PKCS7_ENC_CONTENT *enc_data; + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; + } PKCS7_SIGN_ENVELOPE; + +typedef struct pkcs7_digest_st + { + ASN1_INTEGER *version; /* version 0 */ + X509_ALGOR *md; /* md used */ + struct pkcs7_st *contents; + ASN1_OCTET_STRING *digest; + } PKCS7_DIGEST; + +typedef struct pkcs7_encrypted_st + { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ENC_CONTENT *enc_data; + } PKCS7_ENCRYPT; + +typedef struct pkcs7_st + { + /* The following is non NULL if it contains ASN1 encoding of + * this structure */ + unsigned char *asn1; + long length; + +#define PKCS7_S_HEADER 0 +#define PKCS7_S_BODY 1 +#define PKCS7_S_TAIL 2 + int state; /* used during processing */ + + int detached; + + ASN1_OBJECT *type; + /* content as defined by the type */ + /* all encryption/message digests are applied to the 'contents', + * leaving out the 'type' field. */ + union { + char *ptr; + + /* NID_pkcs7_data */ + ASN1_OCTET_STRING *data; + + /* NID_pkcs7_signed */ + PKCS7_SIGNED *sign; + + /* NID_pkcs7_enveloped */ + PKCS7_ENVELOPE *enveloped; + + /* NID_pkcs7_signedAndEnveloped */ + PKCS7_SIGN_ENVELOPE *signed_and_enveloped; + + /* NID_pkcs7_digest */ + PKCS7_DIGEST *digest; + + /* NID_pkcs7_encrypted */ + PKCS7_ENCRYPT *encrypted; + + /* Anything else */ + ASN1_TYPE *other; + } d; + } PKCS7; + +DECLARE_STACK_OF(PKCS7) +DECLARE_ASN1_SET_OF(PKCS7) +DECLARE_PKCS12_STACK_OF(PKCS7) + +#define PKCS7_OP_SET_DETACHED_SIGNATURE 1 +#define PKCS7_OP_GET_DETACHED_SIGNATURE 2 + +#define PKCS7_get_signed_attributes(si) ((si)->auth_attr) +#define PKCS7_get_attributes(si) ((si)->unauth_attr) + +#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) +#define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) +#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) +#define PKCS7_type_is_signedAndEnveloped(a) \ + (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) +#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) + +#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) + +#define PKCS7_set_detached(p,v) \ + PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) +#define PKCS7_get_detached(p) \ + PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) + +#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) + +#ifdef SSLEAY_MACROS +#ifndef PKCS7_ISSUER_AND_SERIAL_digest +#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ + ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ + (char *)data,md,len) +#endif +#endif + +/* S/MIME related flags */ + +#define PKCS7_TEXT 0x1 +#define PKCS7_NOCERTS 0x2 +#define PKCS7_NOSIGS 0x4 +#define PKCS7_NOCHAIN 0x8 +#define PKCS7_NOINTERN 0x10 +#define PKCS7_NOVERIFY 0x20 +#define PKCS7_DETACHED 0x40 +#define PKCS7_BINARY 0x80 +#define PKCS7_NOATTR 0x100 +#define PKCS7_NOSMIMECAP 0x200 +#define PKCS7_NOOLDMIMETYPE 0x400 +#define PKCS7_CRLFEOL 0x800 +#define PKCS7_STREAM 0x1000 +#define PKCS7_NOCRL 0x2000 + +/* Flags: for compatibility with older code */ + +#define SMIME_TEXT PKCS7_TEXT +#define SMIME_NOCERTS PKCS7_NOCERTS +#define SMIME_NOSIGS PKCS7_NOSIGS +#define SMIME_NOCHAIN PKCS7_NOCHAIN +#define SMIME_NOINTERN PKCS7_NOINTERN +#define SMIME_NOVERIFY PKCS7_NOVERIFY +#define SMIME_DETACHED PKCS7_DETACHED +#define SMIME_BINARY PKCS7_BINARY +#define SMIME_NOATTR PKCS7_NOATTR + +DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) + +#ifndef SSLEAY_MACROS +int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type, + unsigned char *md,unsigned int *len); +#ifndef OPENSSL_NO_FP_API +PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7); +int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7); +#endif +PKCS7 *PKCS7_dup(PKCS7 *p7); +PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7); +int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7); +#endif + +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT) +DECLARE_ASN1_FUNCTIONS(PKCS7) + +DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN) +DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY) + +DECLARE_ASN1_NDEF_FUNCTION(PKCS7) + +long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); + +int PKCS7_set_type(PKCS7 *p7, int type); +int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other); +int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); +int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, + const EVP_MD *dgst); +int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); +int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); +int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); +int PKCS7_content_new(PKCS7 *p7, int nid); +int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, + BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, + X509 *x509); + +BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); +int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); +BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); + + +PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, + EVP_PKEY *pkey, const EVP_MD *dgst); +X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md); +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); + +PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); +int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); +int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); + +PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); +ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type, + void *data); +int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value); +ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid); +ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid); +int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk); + + +PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, + BIO *data, int flags); +int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, + BIO *indata, BIO *out, int flags); +STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags); +PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, + int flags); +int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags); + +int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, + STACK_OF(X509_ALGOR) *cap); +STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); +int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); + +int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); +PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); +int SMIME_crlf_copy(BIO *in, BIO *out, int flags); +int SMIME_text(BIO *in, BIO *out); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_PKCS7_strings(void); + +/* Error codes for the PKCS7 functions. */ + +/* Function codes. */ +#define PKCS7_F_B64_READ_PKCS7 120 +#define PKCS7_F_B64_WRITE_PKCS7 121 +#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118 +#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 +#define PKCS7_F_PKCS7_ADD_CRL 101 +#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 +#define PKCS7_F_PKCS7_ADD_SIGNER 103 +#define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125 +#define PKCS7_F_PKCS7_CTRL 104 +#define PKCS7_F_PKCS7_DATADECODE 112 +#define PKCS7_F_PKCS7_DATAFINAL 128 +#define PKCS7_F_PKCS7_DATAINIT 105 +#define PKCS7_F_PKCS7_DATASIGN 106 +#define PKCS7_F_PKCS7_DATAVERIFY 107 +#define PKCS7_F_PKCS7_DECRYPT 114 +#define PKCS7_F_PKCS7_ENCRYPT 115 +#define PKCS7_F_PKCS7_FIND_DIGEST 127 +#define PKCS7_F_PKCS7_GET0_SIGNERS 124 +#define PKCS7_F_PKCS7_SET_CIPHER 108 +#define PKCS7_F_PKCS7_SET_CONTENT 109 +#define PKCS7_F_PKCS7_SET_DIGEST 126 +#define PKCS7_F_PKCS7_SET_TYPE 110 +#define PKCS7_F_PKCS7_SIGN 116 +#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 +#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119 +#define PKCS7_F_PKCS7_VERIFY 117 +#define PKCS7_F_SMIME_READ_PKCS7 122 +#define PKCS7_F_SMIME_TEXT 123 + +/* Reason codes. */ +#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117 +#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144 +#define PKCS7_R_CIPHER_NOT_INITIALIZED 116 +#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118 +#define PKCS7_R_DECODE_ERROR 130 +#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100 +#define PKCS7_R_DECRYPT_ERROR 119 +#define PKCS7_R_DIGEST_FAILURE 101 +#define PKCS7_R_ERROR_ADDING_RECIPIENT 120 +#define PKCS7_R_ERROR_SETTING_CIPHER 121 +#define PKCS7_R_INVALID_MIME_TYPE 131 +#define PKCS7_R_INVALID_NULL_POINTER 143 +#define PKCS7_R_MIME_NO_CONTENT_TYPE 132 +#define PKCS7_R_MIME_PARSE_ERROR 133 +#define PKCS7_R_MIME_SIG_PARSE_ERROR 134 +#define PKCS7_R_MISSING_CERIPEND_INFO 103 +#define PKCS7_R_NO_CONTENT 122 +#define PKCS7_R_NO_CONTENT_TYPE 135 +#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136 +#define PKCS7_R_NO_MULTIPART_BOUNDARY 137 +#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 +#define PKCS7_R_NO_RECIPIENT_MATCHES_KEY 146 +#define PKCS7_R_NO_SIGNATURES_ON_DATA 123 +#define PKCS7_R_NO_SIGNERS 142 +#define PKCS7_R_NO_SIG_CONTENT_TYPE 138 +#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 +#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124 +#define PKCS7_R_PKCS7_DATAFINAL 126 +#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125 +#define PKCS7_R_PKCS7_DATASIGN 145 +#define PKCS7_R_PKCS7_PARSE_ERROR 139 +#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140 +#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127 +#define PKCS7_R_SIGNATURE_FAILURE 105 +#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128 +#define PKCS7_R_SIG_INVALID_MIME_TYPE 141 +#define PKCS7_R_SMIME_TEXT_ERROR 129 +#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 +#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 +#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 +#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109 +#define PKCS7_R_UNKNOWN_OPERATION 110 +#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111 +#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112 +#define PKCS7_R_WRONG_CONTENT_TYPE 113 +#define PKCS7_R_WRONG_PKCS7_TYPE 114 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pq_compat.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pq_compat.h new file mode 100644 index 0000000..7b2c327 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pq_compat.h @@ -0,0 +1,152 @@ +/* crypto/pqueue/pqueue_compat.h */ +/* + * DTLS implementation written by Nagendra Modadugu + * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. + */ +/* ==================================================================== + * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_PQ_COMPAT_H +#define HEADER_PQ_COMPAT_H + +#include +#include + +/* + * The purpose of this header file is for supporting 64-bit integer + * manipulation on 32-bit (and lower) machines. Currently the only + * such environment is VMS, Utrix and those with smaller default integer + * sizes than 32 bits. For all such environment, we fall back to using + * BIGNUM. We may need to fine tune the conditions for systems that + * are incorrectly configured. + * + * The only clients of this code are (1) pqueue for priority, and + * (2) DTLS, for sequence number manipulation. + */ + +#if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT) + +#define PQ_64BIT_IS_INTEGER 0 +#define PQ_64BIT_IS_BIGNUM 1 + +#define PQ_64BIT BIGNUM +#define PQ_64BIT_CTX BN_CTX + +#define pq_64bit_init(x) BN_init(x) +#define pq_64bit_free(x) BN_free(x) + +#define pq_64bit_ctx_new(ctx) BN_CTX_new() +#define pq_64bit_ctx_free(x) BN_CTX_free(x) + +#define pq_64bit_assign(x, y) BN_copy(x, y) +#define pq_64bit_assign_word(x, y) BN_set_word(x, y) +#define pq_64bit_gt(x, y) BN_ucmp(x, y) >= 1 ? 1 : 0 +#define pq_64bit_eq(x, y) BN_ucmp(x, y) == 0 ? 1 : 0 +#define pq_64bit_add_word(x, w) BN_add_word(x, w) +#define pq_64bit_sub(r, x, y) BN_sub(r, x, y) +#define pq_64bit_sub_word(x, w) BN_sub_word(x, w) +#define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx) + +#define pq_64bit_bin2num(bn, bytes, len) BN_bin2bn(bytes, len, bn) +#define pq_64bit_num2bin(bn, bytes) BN_bn2bin(bn, bytes) +#define pq_64bit_get_word(x) BN_get_word(x) +#define pq_64bit_is_bit_set(x, offset) BN_is_bit_set(x, offset) +#define pq_64bit_lshift(r, x, shift) BN_lshift(r, x, shift) +#define pq_64bit_set_bit(x, num) BN_set_bit(x, num) +#define pq_64bit_get_length(x) BN_num_bits((x)) + +#else + +#define PQ_64BIT_IS_INTEGER 1 +#define PQ_64BIT_IS_BIGNUM 0 + +#if defined(SIXTY_FOUR_BIT) +#define PQ_64BIT BN_ULONG +#define PQ_64BIT_PRINT "%lld" +#elif defined(SIXTY_FOUR_BIT_LONG) +#define PQ_64BIT BN_ULONG +#define PQ_64BIT_PRINT "%ld" +#elif defined(THIRTY_TWO_BIT) +#define PQ_64BIT BN_ULLONG +#define PQ_64BIT_PRINT "%lld" +#endif + +#define PQ_64BIT_CTX void + +#define pq_64bit_init(x) +#define pq_64bit_free(x) +#define pq_64bit_ctx_new(ctx) (ctx) +#define pq_64bit_ctx_free(x) + +#define pq_64bit_assign(x, y) (*(x) = *(y)) +#define pq_64bit_assign_word(x, y) (*(x) = y) +#define pq_64bit_gt(x, y) (*(x) > *(y)) +#define pq_64bit_eq(x, y) (*(x) == *(y)) +#define pq_64bit_add_word(x, w) (*(x) = (*(x) + (w))) +#define pq_64bit_sub(r, x, y) (*(r) = (*(x) - *(y))) +#define pq_64bit_sub_word(x, w) (*(x) = (*(x) - (w))) +#define pq_64bit_mod(r, x, n, ctx) + +#define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num) +#define pq_64bit_num2bin(num, bytes) long_long_to_bytes(num, bytes) +#define pq_64bit_get_word(x) *(x) +#define pq_64bit_lshift(r, x, shift) (*(r) = (*(x) << (shift))) +#define pq_64bit_set_bit(x, num) do { \ + PQ_64BIT mask = 1; \ + mask = mask << (num); \ + *(x) |= mask; \ + } while(0) +#endif /* OPENSSL_SYS_VMS */ + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/pqueue.h b/石器时代8.5客户端最新源代码/石器源码/openssl/pqueue.h new file mode 100644 index 0000000..02386d1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/pqueue.h @@ -0,0 +1,95 @@ +/* crypto/pqueue/pqueue.h */ +/* + * DTLS implementation written by Nagendra Modadugu + * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. + */ +/* ==================================================================== + * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_PQUEUE_H +#define HEADER_PQUEUE_H + +#include +#include +#include + +#include + +typedef struct _pqueue *pqueue; + +typedef struct _pitem + { + PQ_64BIT priority; + void *data; + struct _pitem *next; + } pitem; + +typedef struct _pitem *piterator; + +pitem *pitem_new(PQ_64BIT priority, void *data); +void pitem_free(pitem *item); + +pqueue pqueue_new(void); +void pqueue_free(pqueue pq); + +pitem *pqueue_insert(pqueue pq, pitem *item); +pitem *pqueue_peek(pqueue pq); +pitem *pqueue_pop(pqueue pq); +pitem *pqueue_find(pqueue pq, PQ_64BIT priority); +pitem *pqueue_iterator(pqueue pq); +pitem *pqueue_next(piterator *iter); + +void pqueue_print(pqueue pq); + +#endif /* ! HEADER_PQUEUE_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/rand.h b/石器时代8.5客户端最新源代码/石器源码/openssl/rand.h new file mode 100644 index 0000000..ea89153 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/rand.h @@ -0,0 +1,167 @@ +/* crypto/rand/rand.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RAND_H +#define HEADER_RAND_H + +#include +#include +#include + +#if defined(OPENSSL_SYS_WINDOWS) +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(OPENSSL_FIPS) +#define FIPS_RAND_SIZE_T int +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct rand_meth_st RAND_METHOD; */ + +struct rand_meth_st + { + void (*seed)(const void *buf, int num); + int (*bytes)(unsigned char *buf, int num); + void (*cleanup)(void); + void (*add)(const void *buf, int num, double entropy); + int (*pseudorand)(unsigned char *buf, int num); + int (*status)(void); + }; + +#ifdef BN_DEBUG +extern int rand_predictable; +#endif + +int RAND_set_rand_method(const RAND_METHOD *meth); +const RAND_METHOD *RAND_get_rand_method(void); +#ifndef OPENSSL_NO_ENGINE +int RAND_set_rand_engine(ENGINE *engine); +#endif +RAND_METHOD *RAND_SSLeay(void); +void RAND_cleanup(void ); +int RAND_bytes(unsigned char *buf,int num); +int RAND_pseudo_bytes(unsigned char *buf,int num); +void RAND_seed(const void *buf,int num); +void RAND_add(const void *buf,int num,double entropy); +int RAND_load_file(const char *file,long max_bytes); +int RAND_write_file(const char *file); +const char *RAND_file_name(char *file,size_t num); +int RAND_status(void); +int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); +int RAND_egd(const char *path); +int RAND_egd_bytes(const char *path,int bytes); +int RAND_poll(void); +#ifndef OPENSSL_NO_ENGINE +#ifdef OPENSSL_FIPS +void int_RAND_init_engine_callbacks(void); +void int_RAND_set_callbacks( + int (*set_rand_func)(const RAND_METHOD *meth, + const RAND_METHOD **pmeth), + const RAND_METHOD *(*get_rand_func)(const RAND_METHOD **pmeth)); +#endif +#endif + +#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) + +void RAND_screen(void); +int RAND_event(UINT, WPARAM, LPARAM); + +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_RAND_strings(void); + +/* Error codes for the RAND functions. */ + +/* Function codes. */ +#define RAND_F_ENG_RAND_GET_RAND_METHOD 108 +#define RAND_F_FIPS_RAND 103 +#define RAND_F_FIPS_RAND_BYTES 102 +#define RAND_F_FIPS_RAND_GET_RAND_METHOD 109 +#define RAND_F_FIPS_RAND_SET_DT 106 +#define RAND_F_FIPS_SET_DT 104 +#define RAND_F_FIPS_SET_PRNG_SEED 107 +#define RAND_F_FIPS_SET_TEST_MODE 105 +#define RAND_F_RAND_GET_RAND_METHOD 101 +#define RAND_F_SSLEAY_RAND_BYTES 100 + +/* Reason codes. */ +#define RAND_R_NON_FIPS_METHOD 105 +#define RAND_R_NOT_IN_TEST_MODE 106 +#define RAND_R_NO_KEY_SET 107 +#define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 101 +#define RAND_R_PRNG_ERROR 108 +#define RAND_R_PRNG_KEYED 109 +#define RAND_R_PRNG_NOT_REKEYED 102 +#define RAND_R_PRNG_NOT_RESEEDED 103 +#define RAND_R_PRNG_NOT_SEEDED 100 +#define RAND_R_PRNG_SEED_MUST_NOT_MATCH_KEY 110 +#define RAND_R_PRNG_STUCK 104 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/rc2.h b/石器时代8.5客户端最新源代码/石器源码/openssl/rc2.h new file mode 100644 index 0000000..e542ec9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/rc2.h @@ -0,0 +1,103 @@ +/* crypto/rc2/rc2.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RC2_H +#define HEADER_RC2_H + +#include /* OPENSSL_NO_RC2, RC2_INT */ +#ifdef OPENSSL_NO_RC2 +#error RC2 is disabled. +#endif + +#define RC2_ENCRYPT 1 +#define RC2_DECRYPT 0 + +#define RC2_BLOCK 8 +#define RC2_KEY_LENGTH 16 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rc2_key_st + { + RC2_INT data[64]; + } RC2_KEY; + +#ifdef OPENSSL_FIPS +void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits); +#endif +void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits); +void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key, + int enc); +void RC2_encrypt(unsigned long *data,RC2_KEY *key); +void RC2_decrypt(unsigned long *data,RC2_KEY *key); +void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + RC2_KEY *ks, unsigned char *iv, int enc); +void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/rc4.h b/石器时代8.5客户端最新源代码/石器源码/openssl/rc4.h new file mode 100644 index 0000000..2d8620d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/rc4.h @@ -0,0 +1,90 @@ +/* crypto/rc4/rc4.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RC4_H +#define HEADER_RC4_H + +#include /* OPENSSL_NO_RC4, RC4_INT */ +#ifdef OPENSSL_NO_RC4 +#error RC4 is disabled. +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rc4_key_st + { + RC4_INT x,y; + RC4_INT data[256]; + } RC4_KEY; + + +const char *RC4_options(void); +#ifdef OPENSSL_FIPS +void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); +#endif +void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); +void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, + unsigned char *outdata); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ripemd.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ripemd.h new file mode 100644 index 0000000..3b6d043 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ripemd.h @@ -0,0 +1,106 @@ +/* crypto/ripemd/ripemd.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RIPEMD_H +#define HEADER_RIPEMD_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_NO_RIPEMD +#error RIPEMD is disabled. +#endif + +#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) +#define RIPEMD160_LONG unsigned long +#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) +#define RIPEMD160_LONG unsigned long +#define RIPEMD160_LONG_LOG2 3 +#else +#define RIPEMD160_LONG unsigned int +#endif + +#define RIPEMD160_CBLOCK 64 +#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4) +#define RIPEMD160_DIGEST_LENGTH 20 + +typedef struct RIPEMD160state_st + { + RIPEMD160_LONG A,B,C,D,E; + RIPEMD160_LONG Nl,Nh; + RIPEMD160_LONG data[RIPEMD160_LBLOCK]; + unsigned int num; + } RIPEMD160_CTX; +#ifdef OPENSSL_FIPS +int private_RIPEMD160_Init(RIPEMD160_CTX *c); +#endif +int RIPEMD160_Init(RIPEMD160_CTX *c); +int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); +int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); +unsigned char *RIPEMD160(const unsigned char *d, size_t n, + unsigned char *md); +void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/rsa.h b/石器时代8.5客户端最新源代码/石器源码/openssl/rsa.h new file mode 100644 index 0000000..5bb932a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/rsa.h @@ -0,0 +1,496 @@ +/* crypto/rsa/rsa.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RSA_H +#define HEADER_RSA_H + +#include + +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif + +#ifdef OPENSSL_NO_RSA +#error RSA is disabled. +#endif + +/* If this flag is set the RSA method is FIPS compliant and can be used + * in FIPS mode. This is set in the validated module method. If an + * application sets this flag in its own methods it is its reposibility + * to ensure the result is compliant. + */ + +#define RSA_FLAG_FIPS_METHOD 0x0400 + +/* If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +#define RSA_FLAG_NON_FIPS_ALLOW 0x0400 + +#ifdef OPENSSL_FIPS +#define FIPS_RSA_SIZE_T int +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Declared already in ossl_typ.h */ +/* typedef struct rsa_st RSA; */ +/* typedef struct rsa_meth_st RSA_METHOD; */ + +struct rsa_meth_st + { + const char *name; + int (*rsa_pub_enc)(int flen,const unsigned char *from, + unsigned char *to, + RSA *rsa,int padding); + int (*rsa_pub_dec)(int flen,const unsigned char *from, + unsigned char *to, + RSA *rsa,int padding); + int (*rsa_priv_enc)(int flen,const unsigned char *from, + unsigned char *to, + RSA *rsa,int padding); + int (*rsa_priv_dec)(int flen,const unsigned char *from, + unsigned char *to, + RSA *rsa,int padding); + int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa,BN_CTX *ctx); /* Can be null */ + int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *m_ctx); /* Can be null */ + int (*init)(RSA *rsa); /* called at new */ + int (*finish)(RSA *rsa); /* called at free */ + int flags; /* RSA_METHOD_FLAG_* things */ + char *app_data; /* may be needed! */ +/* New sign and verify functions: some libraries don't allow arbitrary data + * to be signed/verified: this allows them to be used. Note: for this to work + * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used + * RSA_sign(), RSA_verify() should be used instead. Note: for backwards + * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER + * option is set in 'flags'. + */ + int (*rsa_sign)(int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, const RSA *rsa); + int (*rsa_verify)(int dtype, + const unsigned char *m, unsigned int m_length, + unsigned char *sigbuf, unsigned int siglen, const RSA *rsa); +/* If this callback is NULL, the builtin software RSA key-gen will be used. This + * is for behavioural compatibility whilst the code gets rewired, but one day + * it would be nice to assume there are no such things as "builtin software" + * implementations. */ + int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); + }; + +struct rsa_st + { + /* The first parameter is used to pickup errors where + * this is passed instead of aEVP_PKEY, it is set to 0 */ + int pad; + long version; + const RSA_METHOD *meth; + /* functional reference if 'meth' is ENGINE-provided */ + ENGINE *engine; + BIGNUM *n; + BIGNUM *e; + BIGNUM *d; + BIGNUM *p; + BIGNUM *q; + BIGNUM *dmp1; + BIGNUM *dmq1; + BIGNUM *iqmp; + /* be careful using this if the RSA structure is shared */ + CRYPTO_EX_DATA ex_data; + int references; + int flags; + + /* Used to cache montgomery values */ + BN_MONT_CTX *_method_mod_n; + BN_MONT_CTX *_method_mod_p; + BN_MONT_CTX *_method_mod_q; + + /* all BIGNUM values are actually in the following data, if it is not + * NULL */ + char *bignum_data; + BN_BLINDING *blinding; + BN_BLINDING *mt_blinding; + }; + +#ifndef OPENSSL_RSA_MAX_MODULUS_BITS +# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 +#endif + +#define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024 + +#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS +# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 +#endif +#ifndef OPENSSL_RSA_MAX_PUBEXP_BITS +# define OPENSSL_RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "large" modulus only */ +#endif + +#define RSA_3 0x3L +#define RSA_F4 0x10001L + +#define RSA_METHOD_FLAG_NO_CHECK 0x0001 /* don't check pub/private match */ + +#define RSA_FLAG_CACHE_PUBLIC 0x0002 +#define RSA_FLAG_CACHE_PRIVATE 0x0004 +#define RSA_FLAG_BLINDING 0x0008 +#define RSA_FLAG_THREAD_SAFE 0x0010 +/* This flag means the private key operations will be handled by rsa_mod_exp + * and that they do not depend on the private key components being present: + * for example a key stored in external hardware. Without this flag bn_mod_exp + * gets called when private key components are absent. + */ +#define RSA_FLAG_EXT_PKEY 0x0020 + +/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions. + */ +#define RSA_FLAG_SIGN_VER 0x0040 + +#define RSA_FLAG_NO_BLINDING 0x0080 /* new with 0.9.6j and 0.9.7b; the built-in + * RSA implementation now uses blinding by + * default (ignoring RSA_FLAG_BLINDING), + * but other engines might not need it + */ +#define RSA_FLAG_NO_CONSTTIME 0x0100 /* new with 0.9.8f; the built-in RSA + * implementation now uses constant time + * operations by default in private key operations, + * e.g., constant time modular exponentiation, + * modular inverse without leaking branches, + * division without leaking branches. This + * flag disables these constant time + * operations and results in faster RSA + * private key operations. + */ +#ifndef OPENSSL_NO_DEPRECATED +#define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME /* deprecated name for the flag*/ + /* new with 0.9.7h; the built-in RSA + * implementation now uses constant time + * modular exponentiation for secret exponents + * by default. This flag causes the + * faster variable sliding window method to + * be used for all exponents. + */ +#endif + + +#define RSA_PKCS1_PADDING 1 +#define RSA_SSLV23_PADDING 2 +#define RSA_NO_PADDING 3 +#define RSA_PKCS1_OAEP_PADDING 4 +#define RSA_X931_PADDING 5 + +#define RSA_PKCS1_PADDING_SIZE 11 + +#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) +#define RSA_get_app_data(s) RSA_get_ex_data(s,0) + +RSA * RSA_new(void); +RSA * RSA_new_method(ENGINE *engine); +int RSA_size(const RSA *); + +/* Deprecated version */ +#ifndef OPENSSL_NO_DEPRECATED +RSA * RSA_generate_key(int bits, unsigned long e,void + (*callback)(int,int,void *),void *cb_arg); +#endif /* !defined(OPENSSL_NO_DEPRECATED) */ + +/* New version */ +int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); +int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2, + const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp, + const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq, + const BIGNUM *e, BN_GENCB *cb); +int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb); + +int RSA_check_key(const RSA *); + /* next 4 return -1 on error */ +int RSA_public_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa,int padding); +int RSA_private_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa,int padding); +int RSA_public_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa,int padding); +int RSA_private_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa,int padding); +void RSA_free (RSA *r); +/* "up" the RSA object's reference count */ +int RSA_up_ref(RSA *r); + +int RSA_flags(const RSA *r); + +#ifdef OPENSSL_FIPS +RSA *FIPS_rsa_new(void); +void FIPS_rsa_free(RSA *r); +#endif + +void RSA_set_default_method(const RSA_METHOD *meth); +const RSA_METHOD *RSA_get_default_method(void); +const RSA_METHOD *RSA_get_method(const RSA *rsa); +int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); + +/* This function needs the memory locking malloc callbacks to be installed */ +int RSA_memory_lock(RSA *r); + +/* these are the actual SSLeay RSA functions */ +const RSA_METHOD *RSA_PKCS1_SSLeay(void); + +const RSA_METHOD *RSA_null_method(void); + +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) + +#ifndef OPENSSL_NO_FP_API +int RSA_print_fp(FILE *fp, const RSA *r,int offset); +#endif + +#ifndef OPENSSL_NO_BIO +int RSA_print(BIO *bp, const RSA *r,int offset); +#endif + +#ifndef OPENSSL_NO_RC4 +int i2d_RSA_NET(const RSA *a, unsigned char **pp, + int (*cb)(char *buf, int len, const char *prompt, int verify), + int sgckey); +RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, + int (*cb)(char *buf, int len, const char *prompt, int verify), + int sgckey); + +int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, + int (*cb)(char *buf, int len, const char *prompt, + int verify)); +RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, + int (*cb)(char *buf, int len, const char *prompt, + int verify)); +#endif + +/* The following 2 functions sign and verify a X509_SIG ASN1 object + * inside PKCS#1 padded RSA encryption */ +int RSA_sign(int type, const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, RSA *rsa); +int RSA_verify(int type, const unsigned char *m, unsigned int m_length, + unsigned char *sigbuf, unsigned int siglen, RSA *rsa); + +/* The following 2 function sign and verify a ASN1_OCTET_STRING + * object inside PKCS#1 padded RSA encryption */ +int RSA_sign_ASN1_OCTET_STRING(int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, RSA *rsa); +int RSA_verify_ASN1_OCTET_STRING(int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigbuf, unsigned int siglen, RSA *rsa); + +int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); +void RSA_blinding_off(RSA *rsa); +BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); + +int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, + const unsigned char *f,int fl); +int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len); +int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, + const unsigned char *f,int fl); +int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len); +int PKCS1_MGF1(unsigned char *mask, long len, + const unsigned char *seed, long seedlen, const EVP_MD *dgst); +int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, + const unsigned char *f,int fl, + const unsigned char *p,int pl); +int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len, + const unsigned char *p,int pl); +int RSA_padding_add_SSLv23(unsigned char *to,int tlen, + const unsigned char *f,int fl); +int RSA_padding_check_SSLv23(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len); +int RSA_padding_add_none(unsigned char *to,int tlen, + const unsigned char *f,int fl); +int RSA_padding_check_none(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len); +int RSA_padding_add_X931(unsigned char *to,int tlen, + const unsigned char *f,int fl); +int RSA_padding_check_X931(unsigned char *to,int tlen, + const unsigned char *f,int fl,int rsa_len); +int RSA_X931_hash_id(int nid); + +int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, + const EVP_MD *Hash, const unsigned char *EM, int sLen); +int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, + const unsigned char *mHash, + const EVP_MD *Hash, int sLen); + +int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int RSA_set_ex_data(RSA *r,int idx,void *arg); +void *RSA_get_ex_data(const RSA *r, int idx); + +RSA *RSAPublicKey_dup(RSA *rsa); +RSA *RSAPrivateKey_dup(RSA *rsa); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_RSA_strings(void); + +/* Error codes for the RSA functions. */ + +/* Function codes. */ +#define RSA_F_FIPS_RSA_SIGN 140 +#define RSA_F_FIPS_RSA_VERIFY 141 +#define RSA_F_MEMORY_LOCK 100 +#define RSA_F_RSA_BUILTIN_KEYGEN 129 +#define RSA_F_RSA_CHECK_KEY 123 +#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 +#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 +#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 +#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 +#define RSA_F_RSA_GENERATE_KEY 105 +#define RSA_F_RSA_MEMORY_LOCK 130 +#define RSA_F_RSA_NEW_METHOD 106 +#define RSA_F_RSA_NULL 124 +#define RSA_F_RSA_NULL_MOD_EXP 131 +#define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132 +#define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133 +#define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134 +#define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135 +#define RSA_F_RSA_PADDING_ADD_NONE 107 +#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 +#define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 +#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 +#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 +#define RSA_F_RSA_PADDING_ADD_SSLV23 110 +#define RSA_F_RSA_PADDING_ADD_X931 127 +#define RSA_F_RSA_PADDING_CHECK_NONE 111 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 +#define RSA_F_RSA_PADDING_CHECK_SSLV23 114 +#define RSA_F_RSA_PADDING_CHECK_X931 128 +#define RSA_F_RSA_PRINT 115 +#define RSA_F_RSA_PRINT_FP 116 +#define RSA_F_RSA_PRIVATE_ENCRYPT 137 +#define RSA_F_RSA_PUBLIC_DECRYPT 138 +#define RSA_F_RSA_SETUP_BLINDING 136 +#define RSA_F_RSA_SET_DEFAULT_METHOD 139 +#define RSA_F_RSA_SET_METHOD 142 +#define RSA_F_RSA_SIGN 117 +#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 +#define RSA_F_RSA_VERIFY 119 +#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 +#define RSA_F_RSA_VERIFY_PKCS1_PSS 126 + +/* Reason codes. */ +#define RSA_R_ALGORITHM_MISMATCH 100 +#define RSA_R_BAD_E_VALUE 101 +#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 +#define RSA_R_BAD_PAD_BYTE_COUNT 103 +#define RSA_R_BAD_SIGNATURE 104 +#define RSA_R_BLOCK_TYPE_IS_NOT_01 106 +#define RSA_R_BLOCK_TYPE_IS_NOT_02 107 +#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 +#define RSA_R_DATA_TOO_LARGE 109 +#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 +#define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132 +#define RSA_R_DATA_TOO_SMALL 111 +#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 +#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 +#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 +#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 +#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 +#define RSA_R_FIRST_OCTET_INVALID 133 +#define RSA_R_INVALID_HEADER 137 +#define RSA_R_INVALID_MESSAGE_LENGTH 131 +#define RSA_R_INVALID_PADDING 138 +#define RSA_R_INVALID_TRAILER 139 +#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 +#define RSA_R_KEY_SIZE_TOO_SMALL 120 +#define RSA_R_LAST_OCTET_INVALID 134 +#define RSA_R_MODULUS_TOO_LARGE 105 +#define RSA_R_NON_FIPS_METHOD 141 +#define RSA_R_NO_PUBLIC_EXPONENT 140 +#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 +#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 +#define RSA_R_OAEP_DECODING_ERROR 121 +#define RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 142 +#define RSA_R_PADDING_CHECK_FAILED 114 +#define RSA_R_P_NOT_PRIME 128 +#define RSA_R_Q_NOT_PRIME 129 +#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 +#define RSA_R_SLEN_CHECK_FAILED 136 +#define RSA_R_SLEN_RECOVERY_FAILED 135 +#define RSA_R_SSLV3_ROLLBACK_ATTACK 115 +#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 +#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 +#define RSA_R_UNKNOWN_PADDING_TYPE 118 +#define RSA_R_WRONG_SIGNATURE_LENGTH 119 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/safestack.h b/石器时代8.5客户端最新源代码/石器源码/openssl/safestack.h new file mode 100644 index 0000000..40b1790 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/safestack.h @@ -0,0 +1,2030 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_SAFESTACK_H +#define HEADER_SAFESTACK_H + +#include + +#ifdef DEBUG_SAFESTACK + +#ifndef CHECKED_PTR_OF +#define CHECKED_PTR_OF(type, p) \ + ((void*) (1 ? p : (type*)0)) +#endif + +#define CHECKED_SK_FREE_FUNC(type, p) \ + ((void (*)(void *)) ((1 ? p : (void (*)(type *))0))) + +#define CHECKED_SK_CMP_FUNC(type, p) \ + ((int (*)(const char * const *, const char * const *)) \ + ((1 ? p : (int (*)(const type * const *, const type * const *))0))) + +#define STACK_OF(type) struct stack_st_##type +#define PREDECLARE_STACK_OF(type) STACK_OF(type); + +#define DECLARE_STACK_OF(type) \ +STACK_OF(type) \ + { \ + STACK stack; \ + }; + +#define IMPLEMENT_STACK_OF(type) /* nada (obsolete in new safestack approach)*/ + +/* SKM_sk_... stack macros are internal to safestack.h: + * never use them directly, use sk__... instead */ +#define SKM_sk_new(type, cmp) \ + ((STACK_OF(type) *)sk_new(CHECKED_SK_CMP_FUNC(type, cmp))) +#define SKM_sk_new_null(type) \ + ((STACK_OF(type) *)sk_new_null()) +#define SKM_sk_free(type, st) \ + sk_free(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_num(type, st) \ + sk_num(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_value(type, st,i) \ + ((type *)sk_value(CHECKED_PTR_OF(STACK_OF(type), st), i)) +#define SKM_sk_set(type, st,i,val) \ + sk_set(CHECKED_PTR_OF(STACK_OF(type), st), i, CHECKED_PTR_OF(type, val)) +#define SKM_sk_zero(type, st) \ + sk_zero(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_push(type, st,val) \ + sk_push(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) +#define SKM_sk_unshift(type, st,val) \ + sk_unshift(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) +#define SKM_sk_find(type, st,val) \ + sk_find(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) +#define SKM_sk_delete(type, st,i) \ + (type *)sk_delete(CHECKED_PTR_OF(STACK_OF(type), st), i) +#define SKM_sk_delete_ptr(type, st,ptr) \ + (type *)sk_delete_ptr(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, ptr)) +#define SKM_sk_insert(type, st,val,i) \ + sk_insert(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val), i) +#define SKM_sk_set_cmp_func(type, st,cmp) \ + ((int (*)(const type * const *,const type * const *)) \ + sk_set_cmp_func(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_CMP_FUNC(type, cmp))) +#define SKM_sk_dup(type, st) \ + (STACK_OF(type) *)sk_dup(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_pop_free(type, st,free_func) \ + sk_pop_free(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_FREE_FUNC(type, free_func)) +#define SKM_sk_shift(type, st) \ + (type *)sk_shift(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_pop(type, st) \ + (type *)sk_pop(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_sort(type, st) \ + sk_sort(CHECKED_PTR_OF(STACK_OF(type), st)) +#define SKM_sk_is_sorted(type, st) \ + sk_is_sorted(CHECKED_PTR_OF(STACK_OF(type), st)) + +#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + (STACK_OF(type) *)d2i_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type), st), \ + pp, length, \ + CHECKED_D2I_OF(type, d2i_func), \ + CHECKED_SK_FREE_FUNC(type, free_func), \ + ex_tag, ex_class) + +#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \ + i2d_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type), st), pp, \ + CHECKED_I2D_OF(type, i2d_func), \ + ex_tag, ex_class, is_set) + +#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \ + ASN1_seq_pack(CHECKED_PTR_OF(STACK_OF(type), st), \ + CHECKED_I2D_OF(type, i2d_func), buf, len) + +#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \ + (STACK_OF(type) *)ASN1_seq_unpack(buf, len, CHECKED_D2I_OF(type, d2i_func), CHECKED_SK_FREE_FUNC(type, free_func)) + +#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \ + (STACK_OF(type) *)PKCS12_decrypt_d2i(algor, \ + CHECKED_D2I_OF(type, d2i_func), \ + CHECKED_SK_FREE_FUNC(type, free_func), \ + pass, passlen, oct, seq) + +#else + +#define STACK_OF(type) STACK +#define PREDECLARE_STACK_OF(type) /* nada */ +#define DECLARE_STACK_OF(type) /* nada */ +#define IMPLEMENT_STACK_OF(type) /* nada */ + +#define SKM_sk_new(type, cmp) \ + sk_new((int (*)(const char * const *, const char * const *))(cmp)) +#define SKM_sk_new_null(type) \ + sk_new_null() +#define SKM_sk_free(type, st) \ + sk_free(st) +#define SKM_sk_num(type, st) \ + sk_num(st) +#define SKM_sk_value(type, st,i) \ + ((type *)sk_value(st, i)) +#define SKM_sk_set(type, st,i,val) \ + ((type *)sk_set(st, i,(char *)val)) +#define SKM_sk_zero(type, st) \ + sk_zero(st) +#define SKM_sk_push(type, st,val) \ + sk_push(st, (char *)val) +#define SKM_sk_unshift(type, st,val) \ + sk_unshift(st, (char *)val) +#define SKM_sk_find(type, st,val) \ + sk_find(st, (char *)val) +#define SKM_sk_delete(type, st,i) \ + ((type *)sk_delete(st, i)) +#define SKM_sk_delete_ptr(type, st,ptr) \ + ((type *)sk_delete_ptr(st,(char *)ptr)) +#define SKM_sk_insert(type, st,val,i) \ + sk_insert(st, (char *)val, i) +#define SKM_sk_set_cmp_func(type, st,cmp) \ + ((int (*)(const type * const *,const type * const *)) \ + sk_set_cmp_func(st, (int (*)(const char * const *, const char * const *))(cmp))) +#define SKM_sk_dup(type, st) \ + sk_dup(st) +#define SKM_sk_pop_free(type, st,free_func) \ + sk_pop_free(st, (void (*)(void *))free_func) +#define SKM_sk_shift(type, st) \ + ((type *)sk_shift(st)) +#define SKM_sk_pop(type, st) \ + ((type *)sk_pop(st)) +#define SKM_sk_sort(type, st) \ + sk_sort(st) +#define SKM_sk_is_sorted(type, st) \ + sk_is_sorted(st) + +#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + d2i_ASN1_SET(st,pp,length, (void *(*)(void ** ,const unsigned char ** ,long))d2i_func, (void (*)(void *))free_func, ex_tag,ex_class) +#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \ + i2d_ASN1_SET(st,pp,(int (*)(void *, unsigned char **))i2d_func,ex_tag,ex_class,is_set) + +#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \ + ASN1_seq_pack(st, (int (*)(void *, unsigned char **))i2d_func, buf, len) +#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \ + ASN1_seq_unpack(buf,len,(void *(*)(void **,const unsigned char **,long))d2i_func, (void(*)(void *))free_func) + +#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \ + ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq)) + +#endif + +/* This block of defines is updated by util/mkstack.pl, please do not touch! */ +#define sk_ACCESS_DESCRIPTION_new(st) SKM_sk_new(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION) +#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_num(st) SKM_sk_num(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_value(st, i) SKM_sk_value(ACCESS_DESCRIPTION, (st), (i)) +#define sk_ACCESS_DESCRIPTION_set(st, i, val) SKM_sk_set(ACCESS_DESCRIPTION, (st), (i), (val)) +#define sk_ACCESS_DESCRIPTION_zero(st) SKM_sk_zero(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val)) +#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val)) +#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val)) +#define sk_ACCESS_DESCRIPTION_find_ex(st, val) SKM_sk_find_ex(ACCESS_DESCRIPTION, (st), (val)) +#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i)) +#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr)) +#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i)) +#define sk_ACCESS_DESCRIPTION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ACCESS_DESCRIPTION, (st), (cmp)) +#define sk_ACCESS_DESCRIPTION_dup(st) SKM_sk_dup(ACCESS_DESCRIPTION, st) +#define sk_ACCESS_DESCRIPTION_pop_free(st, free_func) SKM_sk_pop_free(ACCESS_DESCRIPTION, (st), (free_func)) +#define sk_ACCESS_DESCRIPTION_shift(st) SKM_sk_shift(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_pop(st) SKM_sk_pop(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st)) +#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st)) + +#define sk_ASIdOrRange_new(st) SKM_sk_new(ASIdOrRange, (st)) +#define sk_ASIdOrRange_new_null() SKM_sk_new_null(ASIdOrRange) +#define sk_ASIdOrRange_free(st) SKM_sk_free(ASIdOrRange, (st)) +#define sk_ASIdOrRange_num(st) SKM_sk_num(ASIdOrRange, (st)) +#define sk_ASIdOrRange_value(st, i) SKM_sk_value(ASIdOrRange, (st), (i)) +#define sk_ASIdOrRange_set(st, i, val) SKM_sk_set(ASIdOrRange, (st), (i), (val)) +#define sk_ASIdOrRange_zero(st) SKM_sk_zero(ASIdOrRange, (st)) +#define sk_ASIdOrRange_push(st, val) SKM_sk_push(ASIdOrRange, (st), (val)) +#define sk_ASIdOrRange_unshift(st, val) SKM_sk_unshift(ASIdOrRange, (st), (val)) +#define sk_ASIdOrRange_find(st, val) SKM_sk_find(ASIdOrRange, (st), (val)) +#define sk_ASIdOrRange_find_ex(st, val) SKM_sk_find_ex(ASIdOrRange, (st), (val)) +#define sk_ASIdOrRange_delete(st, i) SKM_sk_delete(ASIdOrRange, (st), (i)) +#define sk_ASIdOrRange_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASIdOrRange, (st), (ptr)) +#define sk_ASIdOrRange_insert(st, val, i) SKM_sk_insert(ASIdOrRange, (st), (val), (i)) +#define sk_ASIdOrRange_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASIdOrRange, (st), (cmp)) +#define sk_ASIdOrRange_dup(st) SKM_sk_dup(ASIdOrRange, st) +#define sk_ASIdOrRange_pop_free(st, free_func) SKM_sk_pop_free(ASIdOrRange, (st), (free_func)) +#define sk_ASIdOrRange_shift(st) SKM_sk_shift(ASIdOrRange, (st)) +#define sk_ASIdOrRange_pop(st) SKM_sk_pop(ASIdOrRange, (st)) +#define sk_ASIdOrRange_sort(st) SKM_sk_sort(ASIdOrRange, (st)) +#define sk_ASIdOrRange_is_sorted(st) SKM_sk_is_sorted(ASIdOrRange, (st)) + +#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING) +#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_num(st) SKM_sk_num(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_value(st, i) SKM_sk_value(ASN1_GENERALSTRING, (st), (i)) +#define sk_ASN1_GENERALSTRING_set(st, i, val) SKM_sk_set(ASN1_GENERALSTRING, (st), (i), (val)) +#define sk_ASN1_GENERALSTRING_zero(st) SKM_sk_zero(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val)) +#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val)) +#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val)) +#define sk_ASN1_GENERALSTRING_find_ex(st, val) SKM_sk_find_ex(ASN1_GENERALSTRING, (st), (val)) +#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i)) +#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr)) +#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i)) +#define sk_ASN1_GENERALSTRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_GENERALSTRING, (st), (cmp)) +#define sk_ASN1_GENERALSTRING_dup(st) SKM_sk_dup(ASN1_GENERALSTRING, st) +#define sk_ASN1_GENERALSTRING_pop_free(st, free_func) SKM_sk_pop_free(ASN1_GENERALSTRING, (st), (free_func)) +#define sk_ASN1_GENERALSTRING_shift(st) SKM_sk_shift(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_pop(st) SKM_sk_pop(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_sort(st) SKM_sk_sort(ASN1_GENERALSTRING, (st)) +#define sk_ASN1_GENERALSTRING_is_sorted(st) SKM_sk_is_sorted(ASN1_GENERALSTRING, (st)) + +#define sk_ASN1_INTEGER_new(st) SKM_sk_new(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_new_null() SKM_sk_new_null(ASN1_INTEGER) +#define sk_ASN1_INTEGER_free(st) SKM_sk_free(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_num(st) SKM_sk_num(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_value(st, i) SKM_sk_value(ASN1_INTEGER, (st), (i)) +#define sk_ASN1_INTEGER_set(st, i, val) SKM_sk_set(ASN1_INTEGER, (st), (i), (val)) +#define sk_ASN1_INTEGER_zero(st) SKM_sk_zero(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val)) +#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val)) +#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val)) +#define sk_ASN1_INTEGER_find_ex(st, val) SKM_sk_find_ex(ASN1_INTEGER, (st), (val)) +#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i)) +#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr)) +#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i)) +#define sk_ASN1_INTEGER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_INTEGER, (st), (cmp)) +#define sk_ASN1_INTEGER_dup(st) SKM_sk_dup(ASN1_INTEGER, st) +#define sk_ASN1_INTEGER_pop_free(st, free_func) SKM_sk_pop_free(ASN1_INTEGER, (st), (free_func)) +#define sk_ASN1_INTEGER_shift(st) SKM_sk_shift(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_pop(st) SKM_sk_pop(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_sort(st) SKM_sk_sort(ASN1_INTEGER, (st)) +#define sk_ASN1_INTEGER_is_sorted(st) SKM_sk_is_sorted(ASN1_INTEGER, (st)) + +#define sk_ASN1_OBJECT_new(st) SKM_sk_new(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_new_null() SKM_sk_new_null(ASN1_OBJECT) +#define sk_ASN1_OBJECT_free(st) SKM_sk_free(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_num(st) SKM_sk_num(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_value(st, i) SKM_sk_value(ASN1_OBJECT, (st), (i)) +#define sk_ASN1_OBJECT_set(st, i, val) SKM_sk_set(ASN1_OBJECT, (st), (i), (val)) +#define sk_ASN1_OBJECT_zero(st) SKM_sk_zero(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val)) +#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val)) +#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val)) +#define sk_ASN1_OBJECT_find_ex(st, val) SKM_sk_find_ex(ASN1_OBJECT, (st), (val)) +#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i)) +#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr)) +#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i)) +#define sk_ASN1_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_OBJECT, (st), (cmp)) +#define sk_ASN1_OBJECT_dup(st) SKM_sk_dup(ASN1_OBJECT, st) +#define sk_ASN1_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(ASN1_OBJECT, (st), (free_func)) +#define sk_ASN1_OBJECT_shift(st) SKM_sk_shift(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_pop(st) SKM_sk_pop(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_sort(st) SKM_sk_sort(ASN1_OBJECT, (st)) +#define sk_ASN1_OBJECT_is_sorted(st) SKM_sk_is_sorted(ASN1_OBJECT, (st)) + +#define sk_ASN1_STRING_TABLE_new(st) SKM_sk_new(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_new_null() SKM_sk_new_null(ASN1_STRING_TABLE) +#define sk_ASN1_STRING_TABLE_free(st) SKM_sk_free(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_num(st) SKM_sk_num(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_value(st, i) SKM_sk_value(ASN1_STRING_TABLE, (st), (i)) +#define sk_ASN1_STRING_TABLE_set(st, i, val) SKM_sk_set(ASN1_STRING_TABLE, (st), (i), (val)) +#define sk_ASN1_STRING_TABLE_zero(st) SKM_sk_zero(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val)) +#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val)) +#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val)) +#define sk_ASN1_STRING_TABLE_find_ex(st, val) SKM_sk_find_ex(ASN1_STRING_TABLE, (st), (val)) +#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i)) +#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr)) +#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i)) +#define sk_ASN1_STRING_TABLE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_STRING_TABLE, (st), (cmp)) +#define sk_ASN1_STRING_TABLE_dup(st) SKM_sk_dup(ASN1_STRING_TABLE, st) +#define sk_ASN1_STRING_TABLE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_STRING_TABLE, (st), (free_func)) +#define sk_ASN1_STRING_TABLE_shift(st) SKM_sk_shift(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_pop(st) SKM_sk_pop(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_sort(st) SKM_sk_sort(ASN1_STRING_TABLE, (st)) +#define sk_ASN1_STRING_TABLE_is_sorted(st) SKM_sk_is_sorted(ASN1_STRING_TABLE, (st)) + +#define sk_ASN1_TYPE_new(st) SKM_sk_new(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_new_null() SKM_sk_new_null(ASN1_TYPE) +#define sk_ASN1_TYPE_free(st) SKM_sk_free(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_num(st) SKM_sk_num(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_value(st, i) SKM_sk_value(ASN1_TYPE, (st), (i)) +#define sk_ASN1_TYPE_set(st, i, val) SKM_sk_set(ASN1_TYPE, (st), (i), (val)) +#define sk_ASN1_TYPE_zero(st) SKM_sk_zero(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val)) +#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val)) +#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val)) +#define sk_ASN1_TYPE_find_ex(st, val) SKM_sk_find_ex(ASN1_TYPE, (st), (val)) +#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i)) +#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr)) +#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i)) +#define sk_ASN1_TYPE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_TYPE, (st), (cmp)) +#define sk_ASN1_TYPE_dup(st) SKM_sk_dup(ASN1_TYPE, st) +#define sk_ASN1_TYPE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_TYPE, (st), (free_func)) +#define sk_ASN1_TYPE_shift(st) SKM_sk_shift(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_pop(st) SKM_sk_pop(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_sort(st) SKM_sk_sort(ASN1_TYPE, (st)) +#define sk_ASN1_TYPE_is_sorted(st) SKM_sk_is_sorted(ASN1_TYPE, (st)) + +#define sk_ASN1_VALUE_new(st) SKM_sk_new(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_new_null() SKM_sk_new_null(ASN1_VALUE) +#define sk_ASN1_VALUE_free(st) SKM_sk_free(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_num(st) SKM_sk_num(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_value(st, i) SKM_sk_value(ASN1_VALUE, (st), (i)) +#define sk_ASN1_VALUE_set(st, i, val) SKM_sk_set(ASN1_VALUE, (st), (i), (val)) +#define sk_ASN1_VALUE_zero(st) SKM_sk_zero(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val)) +#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val)) +#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val)) +#define sk_ASN1_VALUE_find_ex(st, val) SKM_sk_find_ex(ASN1_VALUE, (st), (val)) +#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i)) +#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr)) +#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i)) +#define sk_ASN1_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_VALUE, (st), (cmp)) +#define sk_ASN1_VALUE_dup(st) SKM_sk_dup(ASN1_VALUE, st) +#define sk_ASN1_VALUE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_VALUE, (st), (free_func)) +#define sk_ASN1_VALUE_shift(st) SKM_sk_shift(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_pop(st) SKM_sk_pop(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_sort(st) SKM_sk_sort(ASN1_VALUE, (st)) +#define sk_ASN1_VALUE_is_sorted(st) SKM_sk_is_sorted(ASN1_VALUE, (st)) + +#define sk_BIO_new(st) SKM_sk_new(BIO, (st)) +#define sk_BIO_new_null() SKM_sk_new_null(BIO) +#define sk_BIO_free(st) SKM_sk_free(BIO, (st)) +#define sk_BIO_num(st) SKM_sk_num(BIO, (st)) +#define sk_BIO_value(st, i) SKM_sk_value(BIO, (st), (i)) +#define sk_BIO_set(st, i, val) SKM_sk_set(BIO, (st), (i), (val)) +#define sk_BIO_zero(st) SKM_sk_zero(BIO, (st)) +#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val)) +#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val)) +#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val)) +#define sk_BIO_find_ex(st, val) SKM_sk_find_ex(BIO, (st), (val)) +#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i)) +#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr)) +#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i)) +#define sk_BIO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BIO, (st), (cmp)) +#define sk_BIO_dup(st) SKM_sk_dup(BIO, st) +#define sk_BIO_pop_free(st, free_func) SKM_sk_pop_free(BIO, (st), (free_func)) +#define sk_BIO_shift(st) SKM_sk_shift(BIO, (st)) +#define sk_BIO_pop(st) SKM_sk_pop(BIO, (st)) +#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st)) +#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st)) + +#define sk_CMS_CertificateChoices_new(st) SKM_sk_new(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_new_null() SKM_sk_new_null(CMS_CertificateChoices) +#define sk_CMS_CertificateChoices_free(st) SKM_sk_free(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_num(st) SKM_sk_num(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_value(st, i) SKM_sk_value(CMS_CertificateChoices, (st), (i)) +#define sk_CMS_CertificateChoices_set(st, i, val) SKM_sk_set(CMS_CertificateChoices, (st), (i), (val)) +#define sk_CMS_CertificateChoices_zero(st) SKM_sk_zero(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_push(st, val) SKM_sk_push(CMS_CertificateChoices, (st), (val)) +#define sk_CMS_CertificateChoices_unshift(st, val) SKM_sk_unshift(CMS_CertificateChoices, (st), (val)) +#define sk_CMS_CertificateChoices_find(st, val) SKM_sk_find(CMS_CertificateChoices, (st), (val)) +#define sk_CMS_CertificateChoices_find_ex(st, val) SKM_sk_find_ex(CMS_CertificateChoices, (st), (val)) +#define sk_CMS_CertificateChoices_delete(st, i) SKM_sk_delete(CMS_CertificateChoices, (st), (i)) +#define sk_CMS_CertificateChoices_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_CertificateChoices, (st), (ptr)) +#define sk_CMS_CertificateChoices_insert(st, val, i) SKM_sk_insert(CMS_CertificateChoices, (st), (val), (i)) +#define sk_CMS_CertificateChoices_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_CertificateChoices, (st), (cmp)) +#define sk_CMS_CertificateChoices_dup(st) SKM_sk_dup(CMS_CertificateChoices, st) +#define sk_CMS_CertificateChoices_pop_free(st, free_func) SKM_sk_pop_free(CMS_CertificateChoices, (st), (free_func)) +#define sk_CMS_CertificateChoices_shift(st) SKM_sk_shift(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_pop(st) SKM_sk_pop(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_sort(st) SKM_sk_sort(CMS_CertificateChoices, (st)) +#define sk_CMS_CertificateChoices_is_sorted(st) SKM_sk_is_sorted(CMS_CertificateChoices, (st)) + +#define sk_CMS_RecipientInfo_new(st) SKM_sk_new(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_new_null() SKM_sk_new_null(CMS_RecipientInfo) +#define sk_CMS_RecipientInfo_free(st) SKM_sk_free(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_num(st) SKM_sk_num(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_value(st, i) SKM_sk_value(CMS_RecipientInfo, (st), (i)) +#define sk_CMS_RecipientInfo_set(st, i, val) SKM_sk_set(CMS_RecipientInfo, (st), (i), (val)) +#define sk_CMS_RecipientInfo_zero(st) SKM_sk_zero(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_push(st, val) SKM_sk_push(CMS_RecipientInfo, (st), (val)) +#define sk_CMS_RecipientInfo_unshift(st, val) SKM_sk_unshift(CMS_RecipientInfo, (st), (val)) +#define sk_CMS_RecipientInfo_find(st, val) SKM_sk_find(CMS_RecipientInfo, (st), (val)) +#define sk_CMS_RecipientInfo_find_ex(st, val) SKM_sk_find_ex(CMS_RecipientInfo, (st), (val)) +#define sk_CMS_RecipientInfo_delete(st, i) SKM_sk_delete(CMS_RecipientInfo, (st), (i)) +#define sk_CMS_RecipientInfo_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_RecipientInfo, (st), (ptr)) +#define sk_CMS_RecipientInfo_insert(st, val, i) SKM_sk_insert(CMS_RecipientInfo, (st), (val), (i)) +#define sk_CMS_RecipientInfo_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_RecipientInfo, (st), (cmp)) +#define sk_CMS_RecipientInfo_dup(st) SKM_sk_dup(CMS_RecipientInfo, st) +#define sk_CMS_RecipientInfo_pop_free(st, free_func) SKM_sk_pop_free(CMS_RecipientInfo, (st), (free_func)) +#define sk_CMS_RecipientInfo_shift(st) SKM_sk_shift(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_pop(st) SKM_sk_pop(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_sort(st) SKM_sk_sort(CMS_RecipientInfo, (st)) +#define sk_CMS_RecipientInfo_is_sorted(st) SKM_sk_is_sorted(CMS_RecipientInfo, (st)) + +#define sk_CMS_RevocationInfoChoice_new(st) SKM_sk_new(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_new_null() SKM_sk_new_null(CMS_RevocationInfoChoice) +#define sk_CMS_RevocationInfoChoice_free(st) SKM_sk_free(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_num(st) SKM_sk_num(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_value(st, i) SKM_sk_value(CMS_RevocationInfoChoice, (st), (i)) +#define sk_CMS_RevocationInfoChoice_set(st, i, val) SKM_sk_set(CMS_RevocationInfoChoice, (st), (i), (val)) +#define sk_CMS_RevocationInfoChoice_zero(st) SKM_sk_zero(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_push(st, val) SKM_sk_push(CMS_RevocationInfoChoice, (st), (val)) +#define sk_CMS_RevocationInfoChoice_unshift(st, val) SKM_sk_unshift(CMS_RevocationInfoChoice, (st), (val)) +#define sk_CMS_RevocationInfoChoice_find(st, val) SKM_sk_find(CMS_RevocationInfoChoice, (st), (val)) +#define sk_CMS_RevocationInfoChoice_find_ex(st, val) SKM_sk_find_ex(CMS_RevocationInfoChoice, (st), (val)) +#define sk_CMS_RevocationInfoChoice_delete(st, i) SKM_sk_delete(CMS_RevocationInfoChoice, (st), (i)) +#define sk_CMS_RevocationInfoChoice_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_RevocationInfoChoice, (st), (ptr)) +#define sk_CMS_RevocationInfoChoice_insert(st, val, i) SKM_sk_insert(CMS_RevocationInfoChoice, (st), (val), (i)) +#define sk_CMS_RevocationInfoChoice_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_RevocationInfoChoice, (st), (cmp)) +#define sk_CMS_RevocationInfoChoice_dup(st) SKM_sk_dup(CMS_RevocationInfoChoice, st) +#define sk_CMS_RevocationInfoChoice_pop_free(st, free_func) SKM_sk_pop_free(CMS_RevocationInfoChoice, (st), (free_func)) +#define sk_CMS_RevocationInfoChoice_shift(st) SKM_sk_shift(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_pop(st) SKM_sk_pop(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_sort(st) SKM_sk_sort(CMS_RevocationInfoChoice, (st)) +#define sk_CMS_RevocationInfoChoice_is_sorted(st) SKM_sk_is_sorted(CMS_RevocationInfoChoice, (st)) + +#define sk_CMS_SignerInfo_new(st) SKM_sk_new(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_new_null() SKM_sk_new_null(CMS_SignerInfo) +#define sk_CMS_SignerInfo_free(st) SKM_sk_free(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_num(st) SKM_sk_num(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_value(st, i) SKM_sk_value(CMS_SignerInfo, (st), (i)) +#define sk_CMS_SignerInfo_set(st, i, val) SKM_sk_set(CMS_SignerInfo, (st), (i), (val)) +#define sk_CMS_SignerInfo_zero(st) SKM_sk_zero(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_push(st, val) SKM_sk_push(CMS_SignerInfo, (st), (val)) +#define sk_CMS_SignerInfo_unshift(st, val) SKM_sk_unshift(CMS_SignerInfo, (st), (val)) +#define sk_CMS_SignerInfo_find(st, val) SKM_sk_find(CMS_SignerInfo, (st), (val)) +#define sk_CMS_SignerInfo_find_ex(st, val) SKM_sk_find_ex(CMS_SignerInfo, (st), (val)) +#define sk_CMS_SignerInfo_delete(st, i) SKM_sk_delete(CMS_SignerInfo, (st), (i)) +#define sk_CMS_SignerInfo_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_SignerInfo, (st), (ptr)) +#define sk_CMS_SignerInfo_insert(st, val, i) SKM_sk_insert(CMS_SignerInfo, (st), (val), (i)) +#define sk_CMS_SignerInfo_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_SignerInfo, (st), (cmp)) +#define sk_CMS_SignerInfo_dup(st) SKM_sk_dup(CMS_SignerInfo, st) +#define sk_CMS_SignerInfo_pop_free(st, free_func) SKM_sk_pop_free(CMS_SignerInfo, (st), (free_func)) +#define sk_CMS_SignerInfo_shift(st) SKM_sk_shift(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_pop(st) SKM_sk_pop(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_sort(st) SKM_sk_sort(CMS_SignerInfo, (st)) +#define sk_CMS_SignerInfo_is_sorted(st) SKM_sk_is_sorted(CMS_SignerInfo, (st)) + +#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE) +#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_num(st) SKM_sk_num(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_value(st, i) SKM_sk_value(CONF_IMODULE, (st), (i)) +#define sk_CONF_IMODULE_set(st, i, val) SKM_sk_set(CONF_IMODULE, (st), (i), (val)) +#define sk_CONF_IMODULE_zero(st) SKM_sk_zero(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val)) +#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val)) +#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val)) +#define sk_CONF_IMODULE_find_ex(st, val) SKM_sk_find_ex(CONF_IMODULE, (st), (val)) +#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i)) +#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr)) +#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i)) +#define sk_CONF_IMODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_IMODULE, (st), (cmp)) +#define sk_CONF_IMODULE_dup(st) SKM_sk_dup(CONF_IMODULE, st) +#define sk_CONF_IMODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_IMODULE, (st), (free_func)) +#define sk_CONF_IMODULE_shift(st) SKM_sk_shift(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_pop(st) SKM_sk_pop(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_sort(st) SKM_sk_sort(CONF_IMODULE, (st)) +#define sk_CONF_IMODULE_is_sorted(st) SKM_sk_is_sorted(CONF_IMODULE, (st)) + +#define sk_CONF_MODULE_new(st) SKM_sk_new(CONF_MODULE, (st)) +#define sk_CONF_MODULE_new_null() SKM_sk_new_null(CONF_MODULE) +#define sk_CONF_MODULE_free(st) SKM_sk_free(CONF_MODULE, (st)) +#define sk_CONF_MODULE_num(st) SKM_sk_num(CONF_MODULE, (st)) +#define sk_CONF_MODULE_value(st, i) SKM_sk_value(CONF_MODULE, (st), (i)) +#define sk_CONF_MODULE_set(st, i, val) SKM_sk_set(CONF_MODULE, (st), (i), (val)) +#define sk_CONF_MODULE_zero(st) SKM_sk_zero(CONF_MODULE, (st)) +#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val)) +#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val)) +#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val)) +#define sk_CONF_MODULE_find_ex(st, val) SKM_sk_find_ex(CONF_MODULE, (st), (val)) +#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i)) +#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr)) +#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i)) +#define sk_CONF_MODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_MODULE, (st), (cmp)) +#define sk_CONF_MODULE_dup(st) SKM_sk_dup(CONF_MODULE, st) +#define sk_CONF_MODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_MODULE, (st), (free_func)) +#define sk_CONF_MODULE_shift(st) SKM_sk_shift(CONF_MODULE, (st)) +#define sk_CONF_MODULE_pop(st) SKM_sk_pop(CONF_MODULE, (st)) +#define sk_CONF_MODULE_sort(st) SKM_sk_sort(CONF_MODULE, (st)) +#define sk_CONF_MODULE_is_sorted(st) SKM_sk_is_sorted(CONF_MODULE, (st)) + +#define sk_CONF_VALUE_new(st) SKM_sk_new(CONF_VALUE, (st)) +#define sk_CONF_VALUE_new_null() SKM_sk_new_null(CONF_VALUE) +#define sk_CONF_VALUE_free(st) SKM_sk_free(CONF_VALUE, (st)) +#define sk_CONF_VALUE_num(st) SKM_sk_num(CONF_VALUE, (st)) +#define sk_CONF_VALUE_value(st, i) SKM_sk_value(CONF_VALUE, (st), (i)) +#define sk_CONF_VALUE_set(st, i, val) SKM_sk_set(CONF_VALUE, (st), (i), (val)) +#define sk_CONF_VALUE_zero(st) SKM_sk_zero(CONF_VALUE, (st)) +#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val)) +#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val)) +#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val)) +#define sk_CONF_VALUE_find_ex(st, val) SKM_sk_find_ex(CONF_VALUE, (st), (val)) +#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i)) +#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr)) +#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i)) +#define sk_CONF_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_VALUE, (st), (cmp)) +#define sk_CONF_VALUE_dup(st) SKM_sk_dup(CONF_VALUE, st) +#define sk_CONF_VALUE_pop_free(st, free_func) SKM_sk_pop_free(CONF_VALUE, (st), (free_func)) +#define sk_CONF_VALUE_shift(st) SKM_sk_shift(CONF_VALUE, (st)) +#define sk_CONF_VALUE_pop(st) SKM_sk_pop(CONF_VALUE, (st)) +#define sk_CONF_VALUE_sort(st) SKM_sk_sort(CONF_VALUE, (st)) +#define sk_CONF_VALUE_is_sorted(st) SKM_sk_is_sorted(CONF_VALUE, (st)) + +#define sk_CRYPTO_EX_DATA_FUNCS_new(st) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS) +#define sk_CRYPTO_EX_DATA_FUNCS_free(st) SKM_sk_free(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_value(st, i) SKM_sk_value(CRYPTO_EX_DATA_FUNCS, (st), (i)) +#define sk_CRYPTO_EX_DATA_FUNCS_set(st, i, val) SKM_sk_set(CRYPTO_EX_DATA_FUNCS, (st), (i), (val)) +#define sk_CRYPTO_EX_DATA_FUNCS_zero(st) SKM_sk_zero(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val)) +#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val)) +#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val)) +#define sk_CRYPTO_EX_DATA_FUNCS_find_ex(st, val) SKM_sk_find_ex(CRYPTO_EX_DATA_FUNCS, (st), (val)) +#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i)) +#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr)) +#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i)) +#define sk_CRYPTO_EX_DATA_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_EX_DATA_FUNCS, (st), (cmp)) +#define sk_CRYPTO_EX_DATA_FUNCS_dup(st) SKM_sk_dup(CRYPTO_EX_DATA_FUNCS, st) +#define sk_CRYPTO_EX_DATA_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_EX_DATA_FUNCS, (st), (free_func)) +#define sk_CRYPTO_EX_DATA_FUNCS_shift(st) SKM_sk_shift(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_pop(st) SKM_sk_pop(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_sort(st) SKM_sk_sort(CRYPTO_EX_DATA_FUNCS, (st)) +#define sk_CRYPTO_EX_DATA_FUNCS_is_sorted(st) SKM_sk_is_sorted(CRYPTO_EX_DATA_FUNCS, (st)) + +#define sk_CRYPTO_dynlock_new(st) SKM_sk_new(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_new_null() SKM_sk_new_null(CRYPTO_dynlock) +#define sk_CRYPTO_dynlock_free(st) SKM_sk_free(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_num(st) SKM_sk_num(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_value(st, i) SKM_sk_value(CRYPTO_dynlock, (st), (i)) +#define sk_CRYPTO_dynlock_set(st, i, val) SKM_sk_set(CRYPTO_dynlock, (st), (i), (val)) +#define sk_CRYPTO_dynlock_zero(st) SKM_sk_zero(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val)) +#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val)) +#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val)) +#define sk_CRYPTO_dynlock_find_ex(st, val) SKM_sk_find_ex(CRYPTO_dynlock, (st), (val)) +#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i)) +#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr)) +#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i)) +#define sk_CRYPTO_dynlock_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_dynlock, (st), (cmp)) +#define sk_CRYPTO_dynlock_dup(st) SKM_sk_dup(CRYPTO_dynlock, st) +#define sk_CRYPTO_dynlock_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_dynlock, (st), (free_func)) +#define sk_CRYPTO_dynlock_shift(st) SKM_sk_shift(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_pop(st) SKM_sk_pop(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_sort(st) SKM_sk_sort(CRYPTO_dynlock, (st)) +#define sk_CRYPTO_dynlock_is_sorted(st) SKM_sk_is_sorted(CRYPTO_dynlock, (st)) + +#define sk_DIST_POINT_new(st) SKM_sk_new(DIST_POINT, (st)) +#define sk_DIST_POINT_new_null() SKM_sk_new_null(DIST_POINT) +#define sk_DIST_POINT_free(st) SKM_sk_free(DIST_POINT, (st)) +#define sk_DIST_POINT_num(st) SKM_sk_num(DIST_POINT, (st)) +#define sk_DIST_POINT_value(st, i) SKM_sk_value(DIST_POINT, (st), (i)) +#define sk_DIST_POINT_set(st, i, val) SKM_sk_set(DIST_POINT, (st), (i), (val)) +#define sk_DIST_POINT_zero(st) SKM_sk_zero(DIST_POINT, (st)) +#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val)) +#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val)) +#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val)) +#define sk_DIST_POINT_find_ex(st, val) SKM_sk_find_ex(DIST_POINT, (st), (val)) +#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i)) +#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr)) +#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i)) +#define sk_DIST_POINT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(DIST_POINT, (st), (cmp)) +#define sk_DIST_POINT_dup(st) SKM_sk_dup(DIST_POINT, st) +#define sk_DIST_POINT_pop_free(st, free_func) SKM_sk_pop_free(DIST_POINT, (st), (free_func)) +#define sk_DIST_POINT_shift(st) SKM_sk_shift(DIST_POINT, (st)) +#define sk_DIST_POINT_pop(st) SKM_sk_pop(DIST_POINT, (st)) +#define sk_DIST_POINT_sort(st) SKM_sk_sort(DIST_POINT, (st)) +#define sk_DIST_POINT_is_sorted(st) SKM_sk_is_sorted(DIST_POINT, (st)) + +#define sk_ENGINE_new(st) SKM_sk_new(ENGINE, (st)) +#define sk_ENGINE_new_null() SKM_sk_new_null(ENGINE) +#define sk_ENGINE_free(st) SKM_sk_free(ENGINE, (st)) +#define sk_ENGINE_num(st) SKM_sk_num(ENGINE, (st)) +#define sk_ENGINE_value(st, i) SKM_sk_value(ENGINE, (st), (i)) +#define sk_ENGINE_set(st, i, val) SKM_sk_set(ENGINE, (st), (i), (val)) +#define sk_ENGINE_zero(st) SKM_sk_zero(ENGINE, (st)) +#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val)) +#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val)) +#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val)) +#define sk_ENGINE_find_ex(st, val) SKM_sk_find_ex(ENGINE, (st), (val)) +#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i)) +#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr)) +#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i)) +#define sk_ENGINE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE, (st), (cmp)) +#define sk_ENGINE_dup(st) SKM_sk_dup(ENGINE, st) +#define sk_ENGINE_pop_free(st, free_func) SKM_sk_pop_free(ENGINE, (st), (free_func)) +#define sk_ENGINE_shift(st) SKM_sk_shift(ENGINE, (st)) +#define sk_ENGINE_pop(st) SKM_sk_pop(ENGINE, (st)) +#define sk_ENGINE_sort(st) SKM_sk_sort(ENGINE, (st)) +#define sk_ENGINE_is_sorted(st) SKM_sk_is_sorted(ENGINE, (st)) + +#define sk_ENGINE_CLEANUP_ITEM_new(st) SKM_sk_new(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_new_null() SKM_sk_new_null(ENGINE_CLEANUP_ITEM) +#define sk_ENGINE_CLEANUP_ITEM_free(st) SKM_sk_free(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_num(st) SKM_sk_num(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_value(st, i) SKM_sk_value(ENGINE_CLEANUP_ITEM, (st), (i)) +#define sk_ENGINE_CLEANUP_ITEM_set(st, i, val) SKM_sk_set(ENGINE_CLEANUP_ITEM, (st), (i), (val)) +#define sk_ENGINE_CLEANUP_ITEM_zero(st) SKM_sk_zero(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val)) +#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val)) +#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val)) +#define sk_ENGINE_CLEANUP_ITEM_find_ex(st, val) SKM_sk_find_ex(ENGINE_CLEANUP_ITEM, (st), (val)) +#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i)) +#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr)) +#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i)) +#define sk_ENGINE_CLEANUP_ITEM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE_CLEANUP_ITEM, (st), (cmp)) +#define sk_ENGINE_CLEANUP_ITEM_dup(st) SKM_sk_dup(ENGINE_CLEANUP_ITEM, st) +#define sk_ENGINE_CLEANUP_ITEM_pop_free(st, free_func) SKM_sk_pop_free(ENGINE_CLEANUP_ITEM, (st), (free_func)) +#define sk_ENGINE_CLEANUP_ITEM_shift(st) SKM_sk_shift(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_pop(st) SKM_sk_pop(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_sort(st) SKM_sk_sort(ENGINE_CLEANUP_ITEM, (st)) +#define sk_ENGINE_CLEANUP_ITEM_is_sorted(st) SKM_sk_is_sorted(ENGINE_CLEANUP_ITEM, (st)) + +#define sk_GENERAL_NAME_new(st) SKM_sk_new(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_new_null() SKM_sk_new_null(GENERAL_NAME) +#define sk_GENERAL_NAME_free(st) SKM_sk_free(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_num(st) SKM_sk_num(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_value(st, i) SKM_sk_value(GENERAL_NAME, (st), (i)) +#define sk_GENERAL_NAME_set(st, i, val) SKM_sk_set(GENERAL_NAME, (st), (i), (val)) +#define sk_GENERAL_NAME_zero(st) SKM_sk_zero(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val)) +#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val)) +#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val)) +#define sk_GENERAL_NAME_find_ex(st, val) SKM_sk_find_ex(GENERAL_NAME, (st), (val)) +#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i)) +#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr)) +#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i)) +#define sk_GENERAL_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAME, (st), (cmp)) +#define sk_GENERAL_NAME_dup(st) SKM_sk_dup(GENERAL_NAME, st) +#define sk_GENERAL_NAME_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAME, (st), (free_func)) +#define sk_GENERAL_NAME_shift(st) SKM_sk_shift(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_pop(st) SKM_sk_pop(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st)) +#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st)) + +#define sk_GENERAL_NAMES_new(st) SKM_sk_new(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_new_null() SKM_sk_new_null(GENERAL_NAMES) +#define sk_GENERAL_NAMES_free(st) SKM_sk_free(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_num(st) SKM_sk_num(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_value(st, i) SKM_sk_value(GENERAL_NAMES, (st), (i)) +#define sk_GENERAL_NAMES_set(st, i, val) SKM_sk_set(GENERAL_NAMES, (st), (i), (val)) +#define sk_GENERAL_NAMES_zero(st) SKM_sk_zero(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_push(st, val) SKM_sk_push(GENERAL_NAMES, (st), (val)) +#define sk_GENERAL_NAMES_unshift(st, val) SKM_sk_unshift(GENERAL_NAMES, (st), (val)) +#define sk_GENERAL_NAMES_find(st, val) SKM_sk_find(GENERAL_NAMES, (st), (val)) +#define sk_GENERAL_NAMES_find_ex(st, val) SKM_sk_find_ex(GENERAL_NAMES, (st), (val)) +#define sk_GENERAL_NAMES_delete(st, i) SKM_sk_delete(GENERAL_NAMES, (st), (i)) +#define sk_GENERAL_NAMES_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAMES, (st), (ptr)) +#define sk_GENERAL_NAMES_insert(st, val, i) SKM_sk_insert(GENERAL_NAMES, (st), (val), (i)) +#define sk_GENERAL_NAMES_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAMES, (st), (cmp)) +#define sk_GENERAL_NAMES_dup(st) SKM_sk_dup(GENERAL_NAMES, st) +#define sk_GENERAL_NAMES_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAMES, (st), (free_func)) +#define sk_GENERAL_NAMES_shift(st) SKM_sk_shift(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_pop(st) SKM_sk_pop(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_sort(st) SKM_sk_sort(GENERAL_NAMES, (st)) +#define sk_GENERAL_NAMES_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAMES, (st)) + +#define sk_GENERAL_SUBTREE_new(st) SKM_sk_new(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_new_null() SKM_sk_new_null(GENERAL_SUBTREE) +#define sk_GENERAL_SUBTREE_free(st) SKM_sk_free(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_num(st) SKM_sk_num(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_value(st, i) SKM_sk_value(GENERAL_SUBTREE, (st), (i)) +#define sk_GENERAL_SUBTREE_set(st, i, val) SKM_sk_set(GENERAL_SUBTREE, (st), (i), (val)) +#define sk_GENERAL_SUBTREE_zero(st) SKM_sk_zero(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_push(st, val) SKM_sk_push(GENERAL_SUBTREE, (st), (val)) +#define sk_GENERAL_SUBTREE_unshift(st, val) SKM_sk_unshift(GENERAL_SUBTREE, (st), (val)) +#define sk_GENERAL_SUBTREE_find(st, val) SKM_sk_find(GENERAL_SUBTREE, (st), (val)) +#define sk_GENERAL_SUBTREE_find_ex(st, val) SKM_sk_find_ex(GENERAL_SUBTREE, (st), (val)) +#define sk_GENERAL_SUBTREE_delete(st, i) SKM_sk_delete(GENERAL_SUBTREE, (st), (i)) +#define sk_GENERAL_SUBTREE_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_SUBTREE, (st), (ptr)) +#define sk_GENERAL_SUBTREE_insert(st, val, i) SKM_sk_insert(GENERAL_SUBTREE, (st), (val), (i)) +#define sk_GENERAL_SUBTREE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_SUBTREE, (st), (cmp)) +#define sk_GENERAL_SUBTREE_dup(st) SKM_sk_dup(GENERAL_SUBTREE, st) +#define sk_GENERAL_SUBTREE_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_SUBTREE, (st), (free_func)) +#define sk_GENERAL_SUBTREE_shift(st) SKM_sk_shift(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_pop(st) SKM_sk_pop(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_sort(st) SKM_sk_sort(GENERAL_SUBTREE, (st)) +#define sk_GENERAL_SUBTREE_is_sorted(st) SKM_sk_is_sorted(GENERAL_SUBTREE, (st)) + +#define sk_IPAddressFamily_new(st) SKM_sk_new(IPAddressFamily, (st)) +#define sk_IPAddressFamily_new_null() SKM_sk_new_null(IPAddressFamily) +#define sk_IPAddressFamily_free(st) SKM_sk_free(IPAddressFamily, (st)) +#define sk_IPAddressFamily_num(st) SKM_sk_num(IPAddressFamily, (st)) +#define sk_IPAddressFamily_value(st, i) SKM_sk_value(IPAddressFamily, (st), (i)) +#define sk_IPAddressFamily_set(st, i, val) SKM_sk_set(IPAddressFamily, (st), (i), (val)) +#define sk_IPAddressFamily_zero(st) SKM_sk_zero(IPAddressFamily, (st)) +#define sk_IPAddressFamily_push(st, val) SKM_sk_push(IPAddressFamily, (st), (val)) +#define sk_IPAddressFamily_unshift(st, val) SKM_sk_unshift(IPAddressFamily, (st), (val)) +#define sk_IPAddressFamily_find(st, val) SKM_sk_find(IPAddressFamily, (st), (val)) +#define sk_IPAddressFamily_find_ex(st, val) SKM_sk_find_ex(IPAddressFamily, (st), (val)) +#define sk_IPAddressFamily_delete(st, i) SKM_sk_delete(IPAddressFamily, (st), (i)) +#define sk_IPAddressFamily_delete_ptr(st, ptr) SKM_sk_delete_ptr(IPAddressFamily, (st), (ptr)) +#define sk_IPAddressFamily_insert(st, val, i) SKM_sk_insert(IPAddressFamily, (st), (val), (i)) +#define sk_IPAddressFamily_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(IPAddressFamily, (st), (cmp)) +#define sk_IPAddressFamily_dup(st) SKM_sk_dup(IPAddressFamily, st) +#define sk_IPAddressFamily_pop_free(st, free_func) SKM_sk_pop_free(IPAddressFamily, (st), (free_func)) +#define sk_IPAddressFamily_shift(st) SKM_sk_shift(IPAddressFamily, (st)) +#define sk_IPAddressFamily_pop(st) SKM_sk_pop(IPAddressFamily, (st)) +#define sk_IPAddressFamily_sort(st) SKM_sk_sort(IPAddressFamily, (st)) +#define sk_IPAddressFamily_is_sorted(st) SKM_sk_is_sorted(IPAddressFamily, (st)) + +#define sk_IPAddressOrRange_new(st) SKM_sk_new(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_new_null() SKM_sk_new_null(IPAddressOrRange) +#define sk_IPAddressOrRange_free(st) SKM_sk_free(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_num(st) SKM_sk_num(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_value(st, i) SKM_sk_value(IPAddressOrRange, (st), (i)) +#define sk_IPAddressOrRange_set(st, i, val) SKM_sk_set(IPAddressOrRange, (st), (i), (val)) +#define sk_IPAddressOrRange_zero(st) SKM_sk_zero(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_push(st, val) SKM_sk_push(IPAddressOrRange, (st), (val)) +#define sk_IPAddressOrRange_unshift(st, val) SKM_sk_unshift(IPAddressOrRange, (st), (val)) +#define sk_IPAddressOrRange_find(st, val) SKM_sk_find(IPAddressOrRange, (st), (val)) +#define sk_IPAddressOrRange_find_ex(st, val) SKM_sk_find_ex(IPAddressOrRange, (st), (val)) +#define sk_IPAddressOrRange_delete(st, i) SKM_sk_delete(IPAddressOrRange, (st), (i)) +#define sk_IPAddressOrRange_delete_ptr(st, ptr) SKM_sk_delete_ptr(IPAddressOrRange, (st), (ptr)) +#define sk_IPAddressOrRange_insert(st, val, i) SKM_sk_insert(IPAddressOrRange, (st), (val), (i)) +#define sk_IPAddressOrRange_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(IPAddressOrRange, (st), (cmp)) +#define sk_IPAddressOrRange_dup(st) SKM_sk_dup(IPAddressOrRange, st) +#define sk_IPAddressOrRange_pop_free(st, free_func) SKM_sk_pop_free(IPAddressOrRange, (st), (free_func)) +#define sk_IPAddressOrRange_shift(st) SKM_sk_shift(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_pop(st) SKM_sk_pop(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_sort(st) SKM_sk_sort(IPAddressOrRange, (st)) +#define sk_IPAddressOrRange_is_sorted(st) SKM_sk_is_sorted(IPAddressOrRange, (st)) + +#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY) +#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_num(st) SKM_sk_num(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_value(st, i) SKM_sk_value(KRB5_APREQBODY, (st), (i)) +#define sk_KRB5_APREQBODY_set(st, i, val) SKM_sk_set(KRB5_APREQBODY, (st), (i), (val)) +#define sk_KRB5_APREQBODY_zero(st) SKM_sk_zero(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val)) +#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val)) +#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val)) +#define sk_KRB5_APREQBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_APREQBODY, (st), (val)) +#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i)) +#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr)) +#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i)) +#define sk_KRB5_APREQBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_APREQBODY, (st), (cmp)) +#define sk_KRB5_APREQBODY_dup(st) SKM_sk_dup(KRB5_APREQBODY, st) +#define sk_KRB5_APREQBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_APREQBODY, (st), (free_func)) +#define sk_KRB5_APREQBODY_shift(st) SKM_sk_shift(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_pop(st) SKM_sk_pop(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_sort(st) SKM_sk_sort(KRB5_APREQBODY, (st)) +#define sk_KRB5_APREQBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_APREQBODY, (st)) + +#define sk_KRB5_AUTHDATA_new(st) SKM_sk_new(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_new_null() SKM_sk_new_null(KRB5_AUTHDATA) +#define sk_KRB5_AUTHDATA_free(st) SKM_sk_free(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_num(st) SKM_sk_num(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_value(st, i) SKM_sk_value(KRB5_AUTHDATA, (st), (i)) +#define sk_KRB5_AUTHDATA_set(st, i, val) SKM_sk_set(KRB5_AUTHDATA, (st), (i), (val)) +#define sk_KRB5_AUTHDATA_zero(st) SKM_sk_zero(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val)) +#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val)) +#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val)) +#define sk_KRB5_AUTHDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHDATA, (st), (val)) +#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i)) +#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr)) +#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i)) +#define sk_KRB5_AUTHDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHDATA, (st), (cmp)) +#define sk_KRB5_AUTHDATA_dup(st) SKM_sk_dup(KRB5_AUTHDATA, st) +#define sk_KRB5_AUTHDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHDATA, (st), (free_func)) +#define sk_KRB5_AUTHDATA_shift(st) SKM_sk_shift(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_pop(st) SKM_sk_pop(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_sort(st) SKM_sk_sort(KRB5_AUTHDATA, (st)) +#define sk_KRB5_AUTHDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHDATA, (st)) + +#define sk_KRB5_AUTHENTBODY_new(st) SKM_sk_new(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_new_null() SKM_sk_new_null(KRB5_AUTHENTBODY) +#define sk_KRB5_AUTHENTBODY_free(st) SKM_sk_free(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_num(st) SKM_sk_num(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_value(st, i) SKM_sk_value(KRB5_AUTHENTBODY, (st), (i)) +#define sk_KRB5_AUTHENTBODY_set(st, i, val) SKM_sk_set(KRB5_AUTHENTBODY, (st), (i), (val)) +#define sk_KRB5_AUTHENTBODY_zero(st) SKM_sk_zero(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val)) +#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val)) +#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val)) +#define sk_KRB5_AUTHENTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHENTBODY, (st), (val)) +#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i)) +#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr)) +#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i)) +#define sk_KRB5_AUTHENTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHENTBODY, (st), (cmp)) +#define sk_KRB5_AUTHENTBODY_dup(st) SKM_sk_dup(KRB5_AUTHENTBODY, st) +#define sk_KRB5_AUTHENTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHENTBODY, (st), (free_func)) +#define sk_KRB5_AUTHENTBODY_shift(st) SKM_sk_shift(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_pop(st) SKM_sk_pop(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_sort(st) SKM_sk_sort(KRB5_AUTHENTBODY, (st)) +#define sk_KRB5_AUTHENTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHENTBODY, (st)) + +#define sk_KRB5_CHECKSUM_new(st) SKM_sk_new(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_new_null() SKM_sk_new_null(KRB5_CHECKSUM) +#define sk_KRB5_CHECKSUM_free(st) SKM_sk_free(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_num(st) SKM_sk_num(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_value(st, i) SKM_sk_value(KRB5_CHECKSUM, (st), (i)) +#define sk_KRB5_CHECKSUM_set(st, i, val) SKM_sk_set(KRB5_CHECKSUM, (st), (i), (val)) +#define sk_KRB5_CHECKSUM_zero(st) SKM_sk_zero(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val)) +#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val)) +#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val)) +#define sk_KRB5_CHECKSUM_find_ex(st, val) SKM_sk_find_ex(KRB5_CHECKSUM, (st), (val)) +#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i)) +#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr)) +#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i)) +#define sk_KRB5_CHECKSUM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_CHECKSUM, (st), (cmp)) +#define sk_KRB5_CHECKSUM_dup(st) SKM_sk_dup(KRB5_CHECKSUM, st) +#define sk_KRB5_CHECKSUM_pop_free(st, free_func) SKM_sk_pop_free(KRB5_CHECKSUM, (st), (free_func)) +#define sk_KRB5_CHECKSUM_shift(st) SKM_sk_shift(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_pop(st) SKM_sk_pop(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_sort(st) SKM_sk_sort(KRB5_CHECKSUM, (st)) +#define sk_KRB5_CHECKSUM_is_sorted(st) SKM_sk_is_sorted(KRB5_CHECKSUM, (st)) + +#define sk_KRB5_ENCDATA_new(st) SKM_sk_new(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_new_null() SKM_sk_new_null(KRB5_ENCDATA) +#define sk_KRB5_ENCDATA_free(st) SKM_sk_free(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_num(st) SKM_sk_num(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_value(st, i) SKM_sk_value(KRB5_ENCDATA, (st), (i)) +#define sk_KRB5_ENCDATA_set(st, i, val) SKM_sk_set(KRB5_ENCDATA, (st), (i), (val)) +#define sk_KRB5_ENCDATA_zero(st) SKM_sk_zero(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val)) +#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val)) +#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val)) +#define sk_KRB5_ENCDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCDATA, (st), (val)) +#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i)) +#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr)) +#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i)) +#define sk_KRB5_ENCDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCDATA, (st), (cmp)) +#define sk_KRB5_ENCDATA_dup(st) SKM_sk_dup(KRB5_ENCDATA, st) +#define sk_KRB5_ENCDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCDATA, (st), (free_func)) +#define sk_KRB5_ENCDATA_shift(st) SKM_sk_shift(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_pop(st) SKM_sk_pop(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_sort(st) SKM_sk_sort(KRB5_ENCDATA, (st)) +#define sk_KRB5_ENCDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCDATA, (st)) + +#define sk_KRB5_ENCKEY_new(st) SKM_sk_new(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_new_null() SKM_sk_new_null(KRB5_ENCKEY) +#define sk_KRB5_ENCKEY_free(st) SKM_sk_free(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_num(st) SKM_sk_num(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_value(st, i) SKM_sk_value(KRB5_ENCKEY, (st), (i)) +#define sk_KRB5_ENCKEY_set(st, i, val) SKM_sk_set(KRB5_ENCKEY, (st), (i), (val)) +#define sk_KRB5_ENCKEY_zero(st) SKM_sk_zero(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val)) +#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val)) +#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val)) +#define sk_KRB5_ENCKEY_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCKEY, (st), (val)) +#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i)) +#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr)) +#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i)) +#define sk_KRB5_ENCKEY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCKEY, (st), (cmp)) +#define sk_KRB5_ENCKEY_dup(st) SKM_sk_dup(KRB5_ENCKEY, st) +#define sk_KRB5_ENCKEY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCKEY, (st), (free_func)) +#define sk_KRB5_ENCKEY_shift(st) SKM_sk_shift(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_pop(st) SKM_sk_pop(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_sort(st) SKM_sk_sort(KRB5_ENCKEY, (st)) +#define sk_KRB5_ENCKEY_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCKEY, (st)) + +#define sk_KRB5_PRINCNAME_new(st) SKM_sk_new(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_new_null() SKM_sk_new_null(KRB5_PRINCNAME) +#define sk_KRB5_PRINCNAME_free(st) SKM_sk_free(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_num(st) SKM_sk_num(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_value(st, i) SKM_sk_value(KRB5_PRINCNAME, (st), (i)) +#define sk_KRB5_PRINCNAME_set(st, i, val) SKM_sk_set(KRB5_PRINCNAME, (st), (i), (val)) +#define sk_KRB5_PRINCNAME_zero(st) SKM_sk_zero(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val)) +#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val)) +#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val)) +#define sk_KRB5_PRINCNAME_find_ex(st, val) SKM_sk_find_ex(KRB5_PRINCNAME, (st), (val)) +#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i)) +#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr)) +#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i)) +#define sk_KRB5_PRINCNAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_PRINCNAME, (st), (cmp)) +#define sk_KRB5_PRINCNAME_dup(st) SKM_sk_dup(KRB5_PRINCNAME, st) +#define sk_KRB5_PRINCNAME_pop_free(st, free_func) SKM_sk_pop_free(KRB5_PRINCNAME, (st), (free_func)) +#define sk_KRB5_PRINCNAME_shift(st) SKM_sk_shift(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_pop(st) SKM_sk_pop(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_sort(st) SKM_sk_sort(KRB5_PRINCNAME, (st)) +#define sk_KRB5_PRINCNAME_is_sorted(st) SKM_sk_is_sorted(KRB5_PRINCNAME, (st)) + +#define sk_KRB5_TKTBODY_new(st) SKM_sk_new(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_new_null() SKM_sk_new_null(KRB5_TKTBODY) +#define sk_KRB5_TKTBODY_free(st) SKM_sk_free(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_num(st) SKM_sk_num(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_value(st, i) SKM_sk_value(KRB5_TKTBODY, (st), (i)) +#define sk_KRB5_TKTBODY_set(st, i, val) SKM_sk_set(KRB5_TKTBODY, (st), (i), (val)) +#define sk_KRB5_TKTBODY_zero(st) SKM_sk_zero(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val)) +#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val)) +#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val)) +#define sk_KRB5_TKTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_TKTBODY, (st), (val)) +#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i)) +#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr)) +#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i)) +#define sk_KRB5_TKTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_TKTBODY, (st), (cmp)) +#define sk_KRB5_TKTBODY_dup(st) SKM_sk_dup(KRB5_TKTBODY, st) +#define sk_KRB5_TKTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_TKTBODY, (st), (free_func)) +#define sk_KRB5_TKTBODY_shift(st) SKM_sk_shift(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_pop(st) SKM_sk_pop(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_sort(st) SKM_sk_sort(KRB5_TKTBODY, (st)) +#define sk_KRB5_TKTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_TKTBODY, (st)) + +#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st)) +#define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER) +#define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st)) +#define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st)) +#define sk_MIME_HEADER_value(st, i) SKM_sk_value(MIME_HEADER, (st), (i)) +#define sk_MIME_HEADER_set(st, i, val) SKM_sk_set(MIME_HEADER, (st), (i), (val)) +#define sk_MIME_HEADER_zero(st) SKM_sk_zero(MIME_HEADER, (st)) +#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_find_ex(st, val) SKM_sk_find_ex(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i)) +#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr)) +#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i)) +#define sk_MIME_HEADER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_HEADER, (st), (cmp)) +#define sk_MIME_HEADER_dup(st) SKM_sk_dup(MIME_HEADER, st) +#define sk_MIME_HEADER_pop_free(st, free_func) SKM_sk_pop_free(MIME_HEADER, (st), (free_func)) +#define sk_MIME_HEADER_shift(st) SKM_sk_shift(MIME_HEADER, (st)) +#define sk_MIME_HEADER_pop(st) SKM_sk_pop(MIME_HEADER, (st)) +#define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st)) +#define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st)) + +#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st)) +#define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER) +#define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st)) +#define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st)) +#define sk_MIME_HEADER_value(st, i) SKM_sk_value(MIME_HEADER, (st), (i)) +#define sk_MIME_HEADER_set(st, i, val) SKM_sk_set(MIME_HEADER, (st), (i), (val)) +#define sk_MIME_HEADER_zero(st) SKM_sk_zero(MIME_HEADER, (st)) +#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_find_ex(st, val) SKM_sk_find_ex(MIME_HEADER, (st), (val)) +#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i)) +#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr)) +#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i)) +#define sk_MIME_HEADER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_HEADER, (st), (cmp)) +#define sk_MIME_HEADER_dup(st) SKM_sk_dup(MIME_HEADER, st) +#define sk_MIME_HEADER_pop_free(st, free_func) SKM_sk_pop_free(MIME_HEADER, (st), (free_func)) +#define sk_MIME_HEADER_shift(st) SKM_sk_shift(MIME_HEADER, (st)) +#define sk_MIME_HEADER_pop(st) SKM_sk_pop(MIME_HEADER, (st)) +#define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st)) +#define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st)) + +#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st)) +#define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM) +#define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st)) +#define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st)) +#define sk_MIME_PARAM_value(st, i) SKM_sk_value(MIME_PARAM, (st), (i)) +#define sk_MIME_PARAM_set(st, i, val) SKM_sk_set(MIME_PARAM, (st), (i), (val)) +#define sk_MIME_PARAM_zero(st) SKM_sk_zero(MIME_PARAM, (st)) +#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_find_ex(st, val) SKM_sk_find_ex(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i)) +#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr)) +#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i)) +#define sk_MIME_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_PARAM, (st), (cmp)) +#define sk_MIME_PARAM_dup(st) SKM_sk_dup(MIME_PARAM, st) +#define sk_MIME_PARAM_pop_free(st, free_func) SKM_sk_pop_free(MIME_PARAM, (st), (free_func)) +#define sk_MIME_PARAM_shift(st) SKM_sk_shift(MIME_PARAM, (st)) +#define sk_MIME_PARAM_pop(st) SKM_sk_pop(MIME_PARAM, (st)) +#define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st)) +#define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st)) + +#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st)) +#define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM) +#define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st)) +#define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st)) +#define sk_MIME_PARAM_value(st, i) SKM_sk_value(MIME_PARAM, (st), (i)) +#define sk_MIME_PARAM_set(st, i, val) SKM_sk_set(MIME_PARAM, (st), (i), (val)) +#define sk_MIME_PARAM_zero(st) SKM_sk_zero(MIME_PARAM, (st)) +#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_find_ex(st, val) SKM_sk_find_ex(MIME_PARAM, (st), (val)) +#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i)) +#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr)) +#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i)) +#define sk_MIME_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_PARAM, (st), (cmp)) +#define sk_MIME_PARAM_dup(st) SKM_sk_dup(MIME_PARAM, st) +#define sk_MIME_PARAM_pop_free(st, free_func) SKM_sk_pop_free(MIME_PARAM, (st), (free_func)) +#define sk_MIME_PARAM_shift(st) SKM_sk_shift(MIME_PARAM, (st)) +#define sk_MIME_PARAM_pop(st) SKM_sk_pop(MIME_PARAM, (st)) +#define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st)) +#define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st)) + +#define sk_NAME_FUNCS_new(st) SKM_sk_new(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_new_null() SKM_sk_new_null(NAME_FUNCS) +#define sk_NAME_FUNCS_free(st) SKM_sk_free(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_num(st) SKM_sk_num(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_value(st, i) SKM_sk_value(NAME_FUNCS, (st), (i)) +#define sk_NAME_FUNCS_set(st, i, val) SKM_sk_set(NAME_FUNCS, (st), (i), (val)) +#define sk_NAME_FUNCS_zero(st) SKM_sk_zero(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val)) +#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val)) +#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val)) +#define sk_NAME_FUNCS_find_ex(st, val) SKM_sk_find_ex(NAME_FUNCS, (st), (val)) +#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i)) +#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr)) +#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i)) +#define sk_NAME_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(NAME_FUNCS, (st), (cmp)) +#define sk_NAME_FUNCS_dup(st) SKM_sk_dup(NAME_FUNCS, st) +#define sk_NAME_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(NAME_FUNCS, (st), (free_func)) +#define sk_NAME_FUNCS_shift(st) SKM_sk_shift(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_pop(st) SKM_sk_pop(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_sort(st) SKM_sk_sort(NAME_FUNCS, (st)) +#define sk_NAME_FUNCS_is_sorted(st) SKM_sk_is_sorted(NAME_FUNCS, (st)) + +#define sk_OCSP_CERTID_new(st) SKM_sk_new(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_new_null() SKM_sk_new_null(OCSP_CERTID) +#define sk_OCSP_CERTID_free(st) SKM_sk_free(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_num(st) SKM_sk_num(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_value(st, i) SKM_sk_value(OCSP_CERTID, (st), (i)) +#define sk_OCSP_CERTID_set(st, i, val) SKM_sk_set(OCSP_CERTID, (st), (i), (val)) +#define sk_OCSP_CERTID_zero(st) SKM_sk_zero(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val)) +#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val)) +#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val)) +#define sk_OCSP_CERTID_find_ex(st, val) SKM_sk_find_ex(OCSP_CERTID, (st), (val)) +#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i)) +#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr)) +#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i)) +#define sk_OCSP_CERTID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_CERTID, (st), (cmp)) +#define sk_OCSP_CERTID_dup(st) SKM_sk_dup(OCSP_CERTID, st) +#define sk_OCSP_CERTID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_CERTID, (st), (free_func)) +#define sk_OCSP_CERTID_shift(st) SKM_sk_shift(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_pop(st) SKM_sk_pop(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_sort(st) SKM_sk_sort(OCSP_CERTID, (st)) +#define sk_OCSP_CERTID_is_sorted(st) SKM_sk_is_sorted(OCSP_CERTID, (st)) + +#define sk_OCSP_ONEREQ_new(st) SKM_sk_new(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_new_null() SKM_sk_new_null(OCSP_ONEREQ) +#define sk_OCSP_ONEREQ_free(st) SKM_sk_free(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_num(st) SKM_sk_num(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_value(st, i) SKM_sk_value(OCSP_ONEREQ, (st), (i)) +#define sk_OCSP_ONEREQ_set(st, i, val) SKM_sk_set(OCSP_ONEREQ, (st), (i), (val)) +#define sk_OCSP_ONEREQ_zero(st) SKM_sk_zero(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val)) +#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val)) +#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val)) +#define sk_OCSP_ONEREQ_find_ex(st, val) SKM_sk_find_ex(OCSP_ONEREQ, (st), (val)) +#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i)) +#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr)) +#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i)) +#define sk_OCSP_ONEREQ_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_ONEREQ, (st), (cmp)) +#define sk_OCSP_ONEREQ_dup(st) SKM_sk_dup(OCSP_ONEREQ, st) +#define sk_OCSP_ONEREQ_pop_free(st, free_func) SKM_sk_pop_free(OCSP_ONEREQ, (st), (free_func)) +#define sk_OCSP_ONEREQ_shift(st) SKM_sk_shift(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_pop(st) SKM_sk_pop(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st)) +#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st)) + +#define sk_OCSP_RESPID_new(st) SKM_sk_new(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_new_null() SKM_sk_new_null(OCSP_RESPID) +#define sk_OCSP_RESPID_free(st) SKM_sk_free(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_num(st) SKM_sk_num(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_value(st, i) SKM_sk_value(OCSP_RESPID, (st), (i)) +#define sk_OCSP_RESPID_set(st, i, val) SKM_sk_set(OCSP_RESPID, (st), (i), (val)) +#define sk_OCSP_RESPID_zero(st) SKM_sk_zero(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_push(st, val) SKM_sk_push(OCSP_RESPID, (st), (val)) +#define sk_OCSP_RESPID_unshift(st, val) SKM_sk_unshift(OCSP_RESPID, (st), (val)) +#define sk_OCSP_RESPID_find(st, val) SKM_sk_find(OCSP_RESPID, (st), (val)) +#define sk_OCSP_RESPID_find_ex(st, val) SKM_sk_find_ex(OCSP_RESPID, (st), (val)) +#define sk_OCSP_RESPID_delete(st, i) SKM_sk_delete(OCSP_RESPID, (st), (i)) +#define sk_OCSP_RESPID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_RESPID, (st), (ptr)) +#define sk_OCSP_RESPID_insert(st, val, i) SKM_sk_insert(OCSP_RESPID, (st), (val), (i)) +#define sk_OCSP_RESPID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_RESPID, (st), (cmp)) +#define sk_OCSP_RESPID_dup(st) SKM_sk_dup(OCSP_RESPID, st) +#define sk_OCSP_RESPID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_RESPID, (st), (free_func)) +#define sk_OCSP_RESPID_shift(st) SKM_sk_shift(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_pop(st) SKM_sk_pop(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_sort(st) SKM_sk_sort(OCSP_RESPID, (st)) +#define sk_OCSP_RESPID_is_sorted(st) SKM_sk_is_sorted(OCSP_RESPID, (st)) + +#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP) +#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_num(st) SKM_sk_num(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_value(st, i) SKM_sk_value(OCSP_SINGLERESP, (st), (i)) +#define sk_OCSP_SINGLERESP_set(st, i, val) SKM_sk_set(OCSP_SINGLERESP, (st), (i), (val)) +#define sk_OCSP_SINGLERESP_zero(st) SKM_sk_zero(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val)) +#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val)) +#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val)) +#define sk_OCSP_SINGLERESP_find_ex(st, val) SKM_sk_find_ex(OCSP_SINGLERESP, (st), (val)) +#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i)) +#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr)) +#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i)) +#define sk_OCSP_SINGLERESP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_SINGLERESP, (st), (cmp)) +#define sk_OCSP_SINGLERESP_dup(st) SKM_sk_dup(OCSP_SINGLERESP, st) +#define sk_OCSP_SINGLERESP_pop_free(st, free_func) SKM_sk_pop_free(OCSP_SINGLERESP, (st), (free_func)) +#define sk_OCSP_SINGLERESP_shift(st) SKM_sk_shift(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_pop(st) SKM_sk_pop(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_sort(st) SKM_sk_sort(OCSP_SINGLERESP, (st)) +#define sk_OCSP_SINGLERESP_is_sorted(st) SKM_sk_is_sorted(OCSP_SINGLERESP, (st)) + +#define sk_PKCS12_SAFEBAG_new(st) SKM_sk_new(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_new_null() SKM_sk_new_null(PKCS12_SAFEBAG) +#define sk_PKCS12_SAFEBAG_free(st) SKM_sk_free(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_num(st) SKM_sk_num(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_value(st, i) SKM_sk_value(PKCS12_SAFEBAG, (st), (i)) +#define sk_PKCS12_SAFEBAG_set(st, i, val) SKM_sk_set(PKCS12_SAFEBAG, (st), (i), (val)) +#define sk_PKCS12_SAFEBAG_zero(st) SKM_sk_zero(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val)) +#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val)) +#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val)) +#define sk_PKCS12_SAFEBAG_find_ex(st, val) SKM_sk_find_ex(PKCS12_SAFEBAG, (st), (val)) +#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i)) +#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr)) +#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i)) +#define sk_PKCS12_SAFEBAG_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS12_SAFEBAG, (st), (cmp)) +#define sk_PKCS12_SAFEBAG_dup(st) SKM_sk_dup(PKCS12_SAFEBAG, st) +#define sk_PKCS12_SAFEBAG_pop_free(st, free_func) SKM_sk_pop_free(PKCS12_SAFEBAG, (st), (free_func)) +#define sk_PKCS12_SAFEBAG_shift(st) SKM_sk_shift(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_pop(st) SKM_sk_pop(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_sort(st) SKM_sk_sort(PKCS12_SAFEBAG, (st)) +#define sk_PKCS12_SAFEBAG_is_sorted(st) SKM_sk_is_sorted(PKCS12_SAFEBAG, (st)) + +#define sk_PKCS7_new(st) SKM_sk_new(PKCS7, (st)) +#define sk_PKCS7_new_null() SKM_sk_new_null(PKCS7) +#define sk_PKCS7_free(st) SKM_sk_free(PKCS7, (st)) +#define sk_PKCS7_num(st) SKM_sk_num(PKCS7, (st)) +#define sk_PKCS7_value(st, i) SKM_sk_value(PKCS7, (st), (i)) +#define sk_PKCS7_set(st, i, val) SKM_sk_set(PKCS7, (st), (i), (val)) +#define sk_PKCS7_zero(st) SKM_sk_zero(PKCS7, (st)) +#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val)) +#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val)) +#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val)) +#define sk_PKCS7_find_ex(st, val) SKM_sk_find_ex(PKCS7, (st), (val)) +#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i)) +#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr)) +#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i)) +#define sk_PKCS7_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7, (st), (cmp)) +#define sk_PKCS7_dup(st) SKM_sk_dup(PKCS7, st) +#define sk_PKCS7_pop_free(st, free_func) SKM_sk_pop_free(PKCS7, (st), (free_func)) +#define sk_PKCS7_shift(st) SKM_sk_shift(PKCS7, (st)) +#define sk_PKCS7_pop(st) SKM_sk_pop(PKCS7, (st)) +#define sk_PKCS7_sort(st) SKM_sk_sort(PKCS7, (st)) +#define sk_PKCS7_is_sorted(st) SKM_sk_is_sorted(PKCS7, (st)) + +#define sk_PKCS7_RECIP_INFO_new(st) SKM_sk_new(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_new_null() SKM_sk_new_null(PKCS7_RECIP_INFO) +#define sk_PKCS7_RECIP_INFO_free(st) SKM_sk_free(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_num(st) SKM_sk_num(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_value(st, i) SKM_sk_value(PKCS7_RECIP_INFO, (st), (i)) +#define sk_PKCS7_RECIP_INFO_set(st, i, val) SKM_sk_set(PKCS7_RECIP_INFO, (st), (i), (val)) +#define sk_PKCS7_RECIP_INFO_zero(st) SKM_sk_zero(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val)) +#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val)) +#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val)) +#define sk_PKCS7_RECIP_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_RECIP_INFO, (st), (val)) +#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i)) +#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr)) +#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i)) +#define sk_PKCS7_RECIP_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_RECIP_INFO, (st), (cmp)) +#define sk_PKCS7_RECIP_INFO_dup(st) SKM_sk_dup(PKCS7_RECIP_INFO, st) +#define sk_PKCS7_RECIP_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_RECIP_INFO, (st), (free_func)) +#define sk_PKCS7_RECIP_INFO_shift(st) SKM_sk_shift(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_pop(st) SKM_sk_pop(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_sort(st) SKM_sk_sort(PKCS7_RECIP_INFO, (st)) +#define sk_PKCS7_RECIP_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_RECIP_INFO, (st)) + +#define sk_PKCS7_SIGNER_INFO_new(st) SKM_sk_new(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_new_null() SKM_sk_new_null(PKCS7_SIGNER_INFO) +#define sk_PKCS7_SIGNER_INFO_free(st) SKM_sk_free(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_num(st) SKM_sk_num(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_value(st, i) SKM_sk_value(PKCS7_SIGNER_INFO, (st), (i)) +#define sk_PKCS7_SIGNER_INFO_set(st, i, val) SKM_sk_set(PKCS7_SIGNER_INFO, (st), (i), (val)) +#define sk_PKCS7_SIGNER_INFO_zero(st) SKM_sk_zero(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val)) +#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val)) +#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val)) +#define sk_PKCS7_SIGNER_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_SIGNER_INFO, (st), (val)) +#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i)) +#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr)) +#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i)) +#define sk_PKCS7_SIGNER_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_SIGNER_INFO, (st), (cmp)) +#define sk_PKCS7_SIGNER_INFO_dup(st) SKM_sk_dup(PKCS7_SIGNER_INFO, st) +#define sk_PKCS7_SIGNER_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_SIGNER_INFO, (st), (free_func)) +#define sk_PKCS7_SIGNER_INFO_shift(st) SKM_sk_shift(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_pop(st) SKM_sk_pop(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_sort(st) SKM_sk_sort(PKCS7_SIGNER_INFO, (st)) +#define sk_PKCS7_SIGNER_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_SIGNER_INFO, (st)) + +#define sk_POLICYINFO_new(st) SKM_sk_new(POLICYINFO, (st)) +#define sk_POLICYINFO_new_null() SKM_sk_new_null(POLICYINFO) +#define sk_POLICYINFO_free(st) SKM_sk_free(POLICYINFO, (st)) +#define sk_POLICYINFO_num(st) SKM_sk_num(POLICYINFO, (st)) +#define sk_POLICYINFO_value(st, i) SKM_sk_value(POLICYINFO, (st), (i)) +#define sk_POLICYINFO_set(st, i, val) SKM_sk_set(POLICYINFO, (st), (i), (val)) +#define sk_POLICYINFO_zero(st) SKM_sk_zero(POLICYINFO, (st)) +#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val)) +#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val)) +#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val)) +#define sk_POLICYINFO_find_ex(st, val) SKM_sk_find_ex(POLICYINFO, (st), (val)) +#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i)) +#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr)) +#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i)) +#define sk_POLICYINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYINFO, (st), (cmp)) +#define sk_POLICYINFO_dup(st) SKM_sk_dup(POLICYINFO, st) +#define sk_POLICYINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYINFO, (st), (free_func)) +#define sk_POLICYINFO_shift(st) SKM_sk_shift(POLICYINFO, (st)) +#define sk_POLICYINFO_pop(st) SKM_sk_pop(POLICYINFO, (st)) +#define sk_POLICYINFO_sort(st) SKM_sk_sort(POLICYINFO, (st)) +#define sk_POLICYINFO_is_sorted(st) SKM_sk_is_sorted(POLICYINFO, (st)) + +#define sk_POLICYQUALINFO_new(st) SKM_sk_new(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_new_null() SKM_sk_new_null(POLICYQUALINFO) +#define sk_POLICYQUALINFO_free(st) SKM_sk_free(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_num(st) SKM_sk_num(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_value(st, i) SKM_sk_value(POLICYQUALINFO, (st), (i)) +#define sk_POLICYQUALINFO_set(st, i, val) SKM_sk_set(POLICYQUALINFO, (st), (i), (val)) +#define sk_POLICYQUALINFO_zero(st) SKM_sk_zero(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val)) +#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val)) +#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val)) +#define sk_POLICYQUALINFO_find_ex(st, val) SKM_sk_find_ex(POLICYQUALINFO, (st), (val)) +#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i)) +#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr)) +#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i)) +#define sk_POLICYQUALINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYQUALINFO, (st), (cmp)) +#define sk_POLICYQUALINFO_dup(st) SKM_sk_dup(POLICYQUALINFO, st) +#define sk_POLICYQUALINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYQUALINFO, (st), (free_func)) +#define sk_POLICYQUALINFO_shift(st) SKM_sk_shift(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_pop(st) SKM_sk_pop(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st)) +#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st)) + +#define sk_POLICY_MAPPING_new(st) SKM_sk_new(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_new_null() SKM_sk_new_null(POLICY_MAPPING) +#define sk_POLICY_MAPPING_free(st) SKM_sk_free(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_num(st) SKM_sk_num(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_value(st, i) SKM_sk_value(POLICY_MAPPING, (st), (i)) +#define sk_POLICY_MAPPING_set(st, i, val) SKM_sk_set(POLICY_MAPPING, (st), (i), (val)) +#define sk_POLICY_MAPPING_zero(st) SKM_sk_zero(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_push(st, val) SKM_sk_push(POLICY_MAPPING, (st), (val)) +#define sk_POLICY_MAPPING_unshift(st, val) SKM_sk_unshift(POLICY_MAPPING, (st), (val)) +#define sk_POLICY_MAPPING_find(st, val) SKM_sk_find(POLICY_MAPPING, (st), (val)) +#define sk_POLICY_MAPPING_find_ex(st, val) SKM_sk_find_ex(POLICY_MAPPING, (st), (val)) +#define sk_POLICY_MAPPING_delete(st, i) SKM_sk_delete(POLICY_MAPPING, (st), (i)) +#define sk_POLICY_MAPPING_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICY_MAPPING, (st), (ptr)) +#define sk_POLICY_MAPPING_insert(st, val, i) SKM_sk_insert(POLICY_MAPPING, (st), (val), (i)) +#define sk_POLICY_MAPPING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICY_MAPPING, (st), (cmp)) +#define sk_POLICY_MAPPING_dup(st) SKM_sk_dup(POLICY_MAPPING, st) +#define sk_POLICY_MAPPING_pop_free(st, free_func) SKM_sk_pop_free(POLICY_MAPPING, (st), (free_func)) +#define sk_POLICY_MAPPING_shift(st) SKM_sk_shift(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_pop(st) SKM_sk_pop(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_sort(st) SKM_sk_sort(POLICY_MAPPING, (st)) +#define sk_POLICY_MAPPING_is_sorted(st) SKM_sk_is_sorted(POLICY_MAPPING, (st)) + +#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER) +#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_num(st) SKM_sk_num(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_value(st, i) SKM_sk_value(SSL_CIPHER, (st), (i)) +#define sk_SSL_CIPHER_set(st, i, val) SKM_sk_set(SSL_CIPHER, (st), (i), (val)) +#define sk_SSL_CIPHER_zero(st) SKM_sk_zero(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val)) +#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val)) +#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val)) +#define sk_SSL_CIPHER_find_ex(st, val) SKM_sk_find_ex(SSL_CIPHER, (st), (val)) +#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i)) +#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr)) +#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i)) +#define sk_SSL_CIPHER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_CIPHER, (st), (cmp)) +#define sk_SSL_CIPHER_dup(st) SKM_sk_dup(SSL_CIPHER, st) +#define sk_SSL_CIPHER_pop_free(st, free_func) SKM_sk_pop_free(SSL_CIPHER, (st), (free_func)) +#define sk_SSL_CIPHER_shift(st) SKM_sk_shift(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_pop(st) SKM_sk_pop(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_sort(st) SKM_sk_sort(SSL_CIPHER, (st)) +#define sk_SSL_CIPHER_is_sorted(st) SKM_sk_is_sorted(SSL_CIPHER, (st)) + +#define sk_SSL_COMP_new(st) SKM_sk_new(SSL_COMP, (st)) +#define sk_SSL_COMP_new_null() SKM_sk_new_null(SSL_COMP) +#define sk_SSL_COMP_free(st) SKM_sk_free(SSL_COMP, (st)) +#define sk_SSL_COMP_num(st) SKM_sk_num(SSL_COMP, (st)) +#define sk_SSL_COMP_value(st, i) SKM_sk_value(SSL_COMP, (st), (i)) +#define sk_SSL_COMP_set(st, i, val) SKM_sk_set(SSL_COMP, (st), (i), (val)) +#define sk_SSL_COMP_zero(st) SKM_sk_zero(SSL_COMP, (st)) +#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val)) +#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val)) +#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val)) +#define sk_SSL_COMP_find_ex(st, val) SKM_sk_find_ex(SSL_COMP, (st), (val)) +#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i)) +#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr)) +#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i)) +#define sk_SSL_COMP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_COMP, (st), (cmp)) +#define sk_SSL_COMP_dup(st) SKM_sk_dup(SSL_COMP, st) +#define sk_SSL_COMP_pop_free(st, free_func) SKM_sk_pop_free(SSL_COMP, (st), (free_func)) +#define sk_SSL_COMP_shift(st) SKM_sk_shift(SSL_COMP, (st)) +#define sk_SSL_COMP_pop(st) SKM_sk_pop(SSL_COMP, (st)) +#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st)) +#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st)) + +#define sk_STORE_OBJECT_new(st) SKM_sk_new(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_new_null() SKM_sk_new_null(STORE_OBJECT) +#define sk_STORE_OBJECT_free(st) SKM_sk_free(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_num(st) SKM_sk_num(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_value(st, i) SKM_sk_value(STORE_OBJECT, (st), (i)) +#define sk_STORE_OBJECT_set(st, i, val) SKM_sk_set(STORE_OBJECT, (st), (i), (val)) +#define sk_STORE_OBJECT_zero(st) SKM_sk_zero(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_push(st, val) SKM_sk_push(STORE_OBJECT, (st), (val)) +#define sk_STORE_OBJECT_unshift(st, val) SKM_sk_unshift(STORE_OBJECT, (st), (val)) +#define sk_STORE_OBJECT_find(st, val) SKM_sk_find(STORE_OBJECT, (st), (val)) +#define sk_STORE_OBJECT_find_ex(st, val) SKM_sk_find_ex(STORE_OBJECT, (st), (val)) +#define sk_STORE_OBJECT_delete(st, i) SKM_sk_delete(STORE_OBJECT, (st), (i)) +#define sk_STORE_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(STORE_OBJECT, (st), (ptr)) +#define sk_STORE_OBJECT_insert(st, val, i) SKM_sk_insert(STORE_OBJECT, (st), (val), (i)) +#define sk_STORE_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(STORE_OBJECT, (st), (cmp)) +#define sk_STORE_OBJECT_dup(st) SKM_sk_dup(STORE_OBJECT, st) +#define sk_STORE_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(STORE_OBJECT, (st), (free_func)) +#define sk_STORE_OBJECT_shift(st) SKM_sk_shift(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_pop(st) SKM_sk_pop(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_sort(st) SKM_sk_sort(STORE_OBJECT, (st)) +#define sk_STORE_OBJECT_is_sorted(st) SKM_sk_is_sorted(STORE_OBJECT, (st)) + +#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st)) +#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID) +#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st)) +#define sk_SXNETID_num(st) SKM_sk_num(SXNETID, (st)) +#define sk_SXNETID_value(st, i) SKM_sk_value(SXNETID, (st), (i)) +#define sk_SXNETID_set(st, i, val) SKM_sk_set(SXNETID, (st), (i), (val)) +#define sk_SXNETID_zero(st) SKM_sk_zero(SXNETID, (st)) +#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val)) +#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val)) +#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val)) +#define sk_SXNETID_find_ex(st, val) SKM_sk_find_ex(SXNETID, (st), (val)) +#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i)) +#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr)) +#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i)) +#define sk_SXNETID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SXNETID, (st), (cmp)) +#define sk_SXNETID_dup(st) SKM_sk_dup(SXNETID, st) +#define sk_SXNETID_pop_free(st, free_func) SKM_sk_pop_free(SXNETID, (st), (free_func)) +#define sk_SXNETID_shift(st) SKM_sk_shift(SXNETID, (st)) +#define sk_SXNETID_pop(st) SKM_sk_pop(SXNETID, (st)) +#define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st)) +#define sk_SXNETID_is_sorted(st) SKM_sk_is_sorted(SXNETID, (st)) + +#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st)) +#define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING) +#define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st)) +#define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st)) +#define sk_UI_STRING_value(st, i) SKM_sk_value(UI_STRING, (st), (i)) +#define sk_UI_STRING_set(st, i, val) SKM_sk_set(UI_STRING, (st), (i), (val)) +#define sk_UI_STRING_zero(st) SKM_sk_zero(UI_STRING, (st)) +#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val)) +#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val)) +#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val)) +#define sk_UI_STRING_find_ex(st, val) SKM_sk_find_ex(UI_STRING, (st), (val)) +#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i)) +#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr)) +#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i)) +#define sk_UI_STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(UI_STRING, (st), (cmp)) +#define sk_UI_STRING_dup(st) SKM_sk_dup(UI_STRING, st) +#define sk_UI_STRING_pop_free(st, free_func) SKM_sk_pop_free(UI_STRING, (st), (free_func)) +#define sk_UI_STRING_shift(st) SKM_sk_shift(UI_STRING, (st)) +#define sk_UI_STRING_pop(st) SKM_sk_pop(UI_STRING, (st)) +#define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st)) +#define sk_UI_STRING_is_sorted(st) SKM_sk_is_sorted(UI_STRING, (st)) + +#define sk_X509_new(st) SKM_sk_new(X509, (st)) +#define sk_X509_new_null() SKM_sk_new_null(X509) +#define sk_X509_free(st) SKM_sk_free(X509, (st)) +#define sk_X509_num(st) SKM_sk_num(X509, (st)) +#define sk_X509_value(st, i) SKM_sk_value(X509, (st), (i)) +#define sk_X509_set(st, i, val) SKM_sk_set(X509, (st), (i), (val)) +#define sk_X509_zero(st) SKM_sk_zero(X509, (st)) +#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val)) +#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val)) +#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val)) +#define sk_X509_find_ex(st, val) SKM_sk_find_ex(X509, (st), (val)) +#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i)) +#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr)) +#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i)) +#define sk_X509_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509, (st), (cmp)) +#define sk_X509_dup(st) SKM_sk_dup(X509, st) +#define sk_X509_pop_free(st, free_func) SKM_sk_pop_free(X509, (st), (free_func)) +#define sk_X509_shift(st) SKM_sk_shift(X509, (st)) +#define sk_X509_pop(st) SKM_sk_pop(X509, (st)) +#define sk_X509_sort(st) SKM_sk_sort(X509, (st)) +#define sk_X509_is_sorted(st) SKM_sk_is_sorted(X509, (st)) + +#define sk_X509V3_EXT_METHOD_new(st) SKM_sk_new(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_new_null() SKM_sk_new_null(X509V3_EXT_METHOD) +#define sk_X509V3_EXT_METHOD_free(st) SKM_sk_free(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_num(st) SKM_sk_num(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_value(st, i) SKM_sk_value(X509V3_EXT_METHOD, (st), (i)) +#define sk_X509V3_EXT_METHOD_set(st, i, val) SKM_sk_set(X509V3_EXT_METHOD, (st), (i), (val)) +#define sk_X509V3_EXT_METHOD_zero(st) SKM_sk_zero(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val)) +#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val)) +#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val)) +#define sk_X509V3_EXT_METHOD_find_ex(st, val) SKM_sk_find_ex(X509V3_EXT_METHOD, (st), (val)) +#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i)) +#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr)) +#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i)) +#define sk_X509V3_EXT_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509V3_EXT_METHOD, (st), (cmp)) +#define sk_X509V3_EXT_METHOD_dup(st) SKM_sk_dup(X509V3_EXT_METHOD, st) +#define sk_X509V3_EXT_METHOD_pop_free(st, free_func) SKM_sk_pop_free(X509V3_EXT_METHOD, (st), (free_func)) +#define sk_X509V3_EXT_METHOD_shift(st) SKM_sk_shift(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_pop(st) SKM_sk_pop(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_sort(st) SKM_sk_sort(X509V3_EXT_METHOD, (st)) +#define sk_X509V3_EXT_METHOD_is_sorted(st) SKM_sk_is_sorted(X509V3_EXT_METHOD, (st)) + +#define sk_X509_ALGOR_new(st) SKM_sk_new(X509_ALGOR, (st)) +#define sk_X509_ALGOR_new_null() SKM_sk_new_null(X509_ALGOR) +#define sk_X509_ALGOR_free(st) SKM_sk_free(X509_ALGOR, (st)) +#define sk_X509_ALGOR_num(st) SKM_sk_num(X509_ALGOR, (st)) +#define sk_X509_ALGOR_value(st, i) SKM_sk_value(X509_ALGOR, (st), (i)) +#define sk_X509_ALGOR_set(st, i, val) SKM_sk_set(X509_ALGOR, (st), (i), (val)) +#define sk_X509_ALGOR_zero(st) SKM_sk_zero(X509_ALGOR, (st)) +#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val)) +#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val)) +#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val)) +#define sk_X509_ALGOR_find_ex(st, val) SKM_sk_find_ex(X509_ALGOR, (st), (val)) +#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i)) +#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr)) +#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i)) +#define sk_X509_ALGOR_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ALGOR, (st), (cmp)) +#define sk_X509_ALGOR_dup(st) SKM_sk_dup(X509_ALGOR, st) +#define sk_X509_ALGOR_pop_free(st, free_func) SKM_sk_pop_free(X509_ALGOR, (st), (free_func)) +#define sk_X509_ALGOR_shift(st) SKM_sk_shift(X509_ALGOR, (st)) +#define sk_X509_ALGOR_pop(st) SKM_sk_pop(X509_ALGOR, (st)) +#define sk_X509_ALGOR_sort(st) SKM_sk_sort(X509_ALGOR, (st)) +#define sk_X509_ALGOR_is_sorted(st) SKM_sk_is_sorted(X509_ALGOR, (st)) + +#define sk_X509_ATTRIBUTE_new(st) SKM_sk_new(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_new_null() SKM_sk_new_null(X509_ATTRIBUTE) +#define sk_X509_ATTRIBUTE_free(st) SKM_sk_free(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_num(st) SKM_sk_num(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_value(st, i) SKM_sk_value(X509_ATTRIBUTE, (st), (i)) +#define sk_X509_ATTRIBUTE_set(st, i, val) SKM_sk_set(X509_ATTRIBUTE, (st), (i), (val)) +#define sk_X509_ATTRIBUTE_zero(st) SKM_sk_zero(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val)) +#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val)) +#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val)) +#define sk_X509_ATTRIBUTE_find_ex(st, val) SKM_sk_find_ex(X509_ATTRIBUTE, (st), (val)) +#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i)) +#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr)) +#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i)) +#define sk_X509_ATTRIBUTE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ATTRIBUTE, (st), (cmp)) +#define sk_X509_ATTRIBUTE_dup(st) SKM_sk_dup(X509_ATTRIBUTE, st) +#define sk_X509_ATTRIBUTE_pop_free(st, free_func) SKM_sk_pop_free(X509_ATTRIBUTE, (st), (free_func)) +#define sk_X509_ATTRIBUTE_shift(st) SKM_sk_shift(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_pop(st) SKM_sk_pop(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_sort(st) SKM_sk_sort(X509_ATTRIBUTE, (st)) +#define sk_X509_ATTRIBUTE_is_sorted(st) SKM_sk_is_sorted(X509_ATTRIBUTE, (st)) + +#define sk_X509_CRL_new(st) SKM_sk_new(X509_CRL, (st)) +#define sk_X509_CRL_new_null() SKM_sk_new_null(X509_CRL) +#define sk_X509_CRL_free(st) SKM_sk_free(X509_CRL, (st)) +#define sk_X509_CRL_num(st) SKM_sk_num(X509_CRL, (st)) +#define sk_X509_CRL_value(st, i) SKM_sk_value(X509_CRL, (st), (i)) +#define sk_X509_CRL_set(st, i, val) SKM_sk_set(X509_CRL, (st), (i), (val)) +#define sk_X509_CRL_zero(st) SKM_sk_zero(X509_CRL, (st)) +#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val)) +#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val)) +#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val)) +#define sk_X509_CRL_find_ex(st, val) SKM_sk_find_ex(X509_CRL, (st), (val)) +#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i)) +#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr)) +#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i)) +#define sk_X509_CRL_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_CRL, (st), (cmp)) +#define sk_X509_CRL_dup(st) SKM_sk_dup(X509_CRL, st) +#define sk_X509_CRL_pop_free(st, free_func) SKM_sk_pop_free(X509_CRL, (st), (free_func)) +#define sk_X509_CRL_shift(st) SKM_sk_shift(X509_CRL, (st)) +#define sk_X509_CRL_pop(st) SKM_sk_pop(X509_CRL, (st)) +#define sk_X509_CRL_sort(st) SKM_sk_sort(X509_CRL, (st)) +#define sk_X509_CRL_is_sorted(st) SKM_sk_is_sorted(X509_CRL, (st)) + +#define sk_X509_EXTENSION_new(st) SKM_sk_new(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_new_null() SKM_sk_new_null(X509_EXTENSION) +#define sk_X509_EXTENSION_free(st) SKM_sk_free(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_num(st) SKM_sk_num(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_value(st, i) SKM_sk_value(X509_EXTENSION, (st), (i)) +#define sk_X509_EXTENSION_set(st, i, val) SKM_sk_set(X509_EXTENSION, (st), (i), (val)) +#define sk_X509_EXTENSION_zero(st) SKM_sk_zero(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val)) +#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val)) +#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val)) +#define sk_X509_EXTENSION_find_ex(st, val) SKM_sk_find_ex(X509_EXTENSION, (st), (val)) +#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i)) +#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr)) +#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i)) +#define sk_X509_EXTENSION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_EXTENSION, (st), (cmp)) +#define sk_X509_EXTENSION_dup(st) SKM_sk_dup(X509_EXTENSION, st) +#define sk_X509_EXTENSION_pop_free(st, free_func) SKM_sk_pop_free(X509_EXTENSION, (st), (free_func)) +#define sk_X509_EXTENSION_shift(st) SKM_sk_shift(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_pop(st) SKM_sk_pop(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_sort(st) SKM_sk_sort(X509_EXTENSION, (st)) +#define sk_X509_EXTENSION_is_sorted(st) SKM_sk_is_sorted(X509_EXTENSION, (st)) + +#define sk_X509_INFO_new(st) SKM_sk_new(X509_INFO, (st)) +#define sk_X509_INFO_new_null() SKM_sk_new_null(X509_INFO) +#define sk_X509_INFO_free(st) SKM_sk_free(X509_INFO, (st)) +#define sk_X509_INFO_num(st) SKM_sk_num(X509_INFO, (st)) +#define sk_X509_INFO_value(st, i) SKM_sk_value(X509_INFO, (st), (i)) +#define sk_X509_INFO_set(st, i, val) SKM_sk_set(X509_INFO, (st), (i), (val)) +#define sk_X509_INFO_zero(st) SKM_sk_zero(X509_INFO, (st)) +#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val)) +#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val)) +#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val)) +#define sk_X509_INFO_find_ex(st, val) SKM_sk_find_ex(X509_INFO, (st), (val)) +#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i)) +#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr)) +#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i)) +#define sk_X509_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_INFO, (st), (cmp)) +#define sk_X509_INFO_dup(st) SKM_sk_dup(X509_INFO, st) +#define sk_X509_INFO_pop_free(st, free_func) SKM_sk_pop_free(X509_INFO, (st), (free_func)) +#define sk_X509_INFO_shift(st) SKM_sk_shift(X509_INFO, (st)) +#define sk_X509_INFO_pop(st) SKM_sk_pop(X509_INFO, (st)) +#define sk_X509_INFO_sort(st) SKM_sk_sort(X509_INFO, (st)) +#define sk_X509_INFO_is_sorted(st) SKM_sk_is_sorted(X509_INFO, (st)) + +#define sk_X509_LOOKUP_new(st) SKM_sk_new(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_new_null() SKM_sk_new_null(X509_LOOKUP) +#define sk_X509_LOOKUP_free(st) SKM_sk_free(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_num(st) SKM_sk_num(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_value(st, i) SKM_sk_value(X509_LOOKUP, (st), (i)) +#define sk_X509_LOOKUP_set(st, i, val) SKM_sk_set(X509_LOOKUP, (st), (i), (val)) +#define sk_X509_LOOKUP_zero(st) SKM_sk_zero(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val)) +#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val)) +#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val)) +#define sk_X509_LOOKUP_find_ex(st, val) SKM_sk_find_ex(X509_LOOKUP, (st), (val)) +#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i)) +#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr)) +#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i)) +#define sk_X509_LOOKUP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_LOOKUP, (st), (cmp)) +#define sk_X509_LOOKUP_dup(st) SKM_sk_dup(X509_LOOKUP, st) +#define sk_X509_LOOKUP_pop_free(st, free_func) SKM_sk_pop_free(X509_LOOKUP, (st), (free_func)) +#define sk_X509_LOOKUP_shift(st) SKM_sk_shift(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_pop(st) SKM_sk_pop(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_sort(st) SKM_sk_sort(X509_LOOKUP, (st)) +#define sk_X509_LOOKUP_is_sorted(st) SKM_sk_is_sorted(X509_LOOKUP, (st)) + +#define sk_X509_NAME_new(st) SKM_sk_new(X509_NAME, (st)) +#define sk_X509_NAME_new_null() SKM_sk_new_null(X509_NAME) +#define sk_X509_NAME_free(st) SKM_sk_free(X509_NAME, (st)) +#define sk_X509_NAME_num(st) SKM_sk_num(X509_NAME, (st)) +#define sk_X509_NAME_value(st, i) SKM_sk_value(X509_NAME, (st), (i)) +#define sk_X509_NAME_set(st, i, val) SKM_sk_set(X509_NAME, (st), (i), (val)) +#define sk_X509_NAME_zero(st) SKM_sk_zero(X509_NAME, (st)) +#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val)) +#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val)) +#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val)) +#define sk_X509_NAME_find_ex(st, val) SKM_sk_find_ex(X509_NAME, (st), (val)) +#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i)) +#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr)) +#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i)) +#define sk_X509_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME, (st), (cmp)) +#define sk_X509_NAME_dup(st) SKM_sk_dup(X509_NAME, st) +#define sk_X509_NAME_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME, (st), (free_func)) +#define sk_X509_NAME_shift(st) SKM_sk_shift(X509_NAME, (st)) +#define sk_X509_NAME_pop(st) SKM_sk_pop(X509_NAME, (st)) +#define sk_X509_NAME_sort(st) SKM_sk_sort(X509_NAME, (st)) +#define sk_X509_NAME_is_sorted(st) SKM_sk_is_sorted(X509_NAME, (st)) + +#define sk_X509_NAME_ENTRY_new(st) SKM_sk_new(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_new_null() SKM_sk_new_null(X509_NAME_ENTRY) +#define sk_X509_NAME_ENTRY_free(st) SKM_sk_free(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_num(st) SKM_sk_num(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_value(st, i) SKM_sk_value(X509_NAME_ENTRY, (st), (i)) +#define sk_X509_NAME_ENTRY_set(st, i, val) SKM_sk_set(X509_NAME_ENTRY, (st), (i), (val)) +#define sk_X509_NAME_ENTRY_zero(st) SKM_sk_zero(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val)) +#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val)) +#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val)) +#define sk_X509_NAME_ENTRY_find_ex(st, val) SKM_sk_find_ex(X509_NAME_ENTRY, (st), (val)) +#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i)) +#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr)) +#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i)) +#define sk_X509_NAME_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME_ENTRY, (st), (cmp)) +#define sk_X509_NAME_ENTRY_dup(st) SKM_sk_dup(X509_NAME_ENTRY, st) +#define sk_X509_NAME_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME_ENTRY, (st), (free_func)) +#define sk_X509_NAME_ENTRY_shift(st) SKM_sk_shift(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_pop(st) SKM_sk_pop(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_sort(st) SKM_sk_sort(X509_NAME_ENTRY, (st)) +#define sk_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(X509_NAME_ENTRY, (st)) + +#define sk_X509_OBJECT_new(st) SKM_sk_new(X509_OBJECT, (st)) +#define sk_X509_OBJECT_new_null() SKM_sk_new_null(X509_OBJECT) +#define sk_X509_OBJECT_free(st) SKM_sk_free(X509_OBJECT, (st)) +#define sk_X509_OBJECT_num(st) SKM_sk_num(X509_OBJECT, (st)) +#define sk_X509_OBJECT_value(st, i) SKM_sk_value(X509_OBJECT, (st), (i)) +#define sk_X509_OBJECT_set(st, i, val) SKM_sk_set(X509_OBJECT, (st), (i), (val)) +#define sk_X509_OBJECT_zero(st) SKM_sk_zero(X509_OBJECT, (st)) +#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val)) +#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val)) +#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val)) +#define sk_X509_OBJECT_find_ex(st, val) SKM_sk_find_ex(X509_OBJECT, (st), (val)) +#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i)) +#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr)) +#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i)) +#define sk_X509_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_OBJECT, (st), (cmp)) +#define sk_X509_OBJECT_dup(st) SKM_sk_dup(X509_OBJECT, st) +#define sk_X509_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(X509_OBJECT, (st), (free_func)) +#define sk_X509_OBJECT_shift(st) SKM_sk_shift(X509_OBJECT, (st)) +#define sk_X509_OBJECT_pop(st) SKM_sk_pop(X509_OBJECT, (st)) +#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st)) +#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st)) + +#define sk_X509_POLICY_DATA_new(st) SKM_sk_new(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_new_null() SKM_sk_new_null(X509_POLICY_DATA) +#define sk_X509_POLICY_DATA_free(st) SKM_sk_free(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_num(st) SKM_sk_num(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_value(st, i) SKM_sk_value(X509_POLICY_DATA, (st), (i)) +#define sk_X509_POLICY_DATA_set(st, i, val) SKM_sk_set(X509_POLICY_DATA, (st), (i), (val)) +#define sk_X509_POLICY_DATA_zero(st) SKM_sk_zero(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_push(st, val) SKM_sk_push(X509_POLICY_DATA, (st), (val)) +#define sk_X509_POLICY_DATA_unshift(st, val) SKM_sk_unshift(X509_POLICY_DATA, (st), (val)) +#define sk_X509_POLICY_DATA_find(st, val) SKM_sk_find(X509_POLICY_DATA, (st), (val)) +#define sk_X509_POLICY_DATA_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_DATA, (st), (val)) +#define sk_X509_POLICY_DATA_delete(st, i) SKM_sk_delete(X509_POLICY_DATA, (st), (i)) +#define sk_X509_POLICY_DATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_DATA, (st), (ptr)) +#define sk_X509_POLICY_DATA_insert(st, val, i) SKM_sk_insert(X509_POLICY_DATA, (st), (val), (i)) +#define sk_X509_POLICY_DATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_DATA, (st), (cmp)) +#define sk_X509_POLICY_DATA_dup(st) SKM_sk_dup(X509_POLICY_DATA, st) +#define sk_X509_POLICY_DATA_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_DATA, (st), (free_func)) +#define sk_X509_POLICY_DATA_shift(st) SKM_sk_shift(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_pop(st) SKM_sk_pop(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_sort(st) SKM_sk_sort(X509_POLICY_DATA, (st)) +#define sk_X509_POLICY_DATA_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_DATA, (st)) + +#define sk_X509_POLICY_NODE_new(st) SKM_sk_new(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_new_null() SKM_sk_new_null(X509_POLICY_NODE) +#define sk_X509_POLICY_NODE_free(st) SKM_sk_free(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_num(st) SKM_sk_num(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_value(st, i) SKM_sk_value(X509_POLICY_NODE, (st), (i)) +#define sk_X509_POLICY_NODE_set(st, i, val) SKM_sk_set(X509_POLICY_NODE, (st), (i), (val)) +#define sk_X509_POLICY_NODE_zero(st) SKM_sk_zero(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_push(st, val) SKM_sk_push(X509_POLICY_NODE, (st), (val)) +#define sk_X509_POLICY_NODE_unshift(st, val) SKM_sk_unshift(X509_POLICY_NODE, (st), (val)) +#define sk_X509_POLICY_NODE_find(st, val) SKM_sk_find(X509_POLICY_NODE, (st), (val)) +#define sk_X509_POLICY_NODE_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_NODE, (st), (val)) +#define sk_X509_POLICY_NODE_delete(st, i) SKM_sk_delete(X509_POLICY_NODE, (st), (i)) +#define sk_X509_POLICY_NODE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_NODE, (st), (ptr)) +#define sk_X509_POLICY_NODE_insert(st, val, i) SKM_sk_insert(X509_POLICY_NODE, (st), (val), (i)) +#define sk_X509_POLICY_NODE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_NODE, (st), (cmp)) +#define sk_X509_POLICY_NODE_dup(st) SKM_sk_dup(X509_POLICY_NODE, st) +#define sk_X509_POLICY_NODE_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_NODE, (st), (free_func)) +#define sk_X509_POLICY_NODE_shift(st) SKM_sk_shift(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_pop(st) SKM_sk_pop(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_sort(st) SKM_sk_sort(X509_POLICY_NODE, (st)) +#define sk_X509_POLICY_NODE_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_NODE, (st)) + +#define sk_X509_POLICY_REF_new(st) SKM_sk_new(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_new_null() SKM_sk_new_null(X509_POLICY_REF) +#define sk_X509_POLICY_REF_free(st) SKM_sk_free(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_num(st) SKM_sk_num(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_value(st, i) SKM_sk_value(X509_POLICY_REF, (st), (i)) +#define sk_X509_POLICY_REF_set(st, i, val) SKM_sk_set(X509_POLICY_REF, (st), (i), (val)) +#define sk_X509_POLICY_REF_zero(st) SKM_sk_zero(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_push(st, val) SKM_sk_push(X509_POLICY_REF, (st), (val)) +#define sk_X509_POLICY_REF_unshift(st, val) SKM_sk_unshift(X509_POLICY_REF, (st), (val)) +#define sk_X509_POLICY_REF_find(st, val) SKM_sk_find(X509_POLICY_REF, (st), (val)) +#define sk_X509_POLICY_REF_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_REF, (st), (val)) +#define sk_X509_POLICY_REF_delete(st, i) SKM_sk_delete(X509_POLICY_REF, (st), (i)) +#define sk_X509_POLICY_REF_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_REF, (st), (ptr)) +#define sk_X509_POLICY_REF_insert(st, val, i) SKM_sk_insert(X509_POLICY_REF, (st), (val), (i)) +#define sk_X509_POLICY_REF_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_REF, (st), (cmp)) +#define sk_X509_POLICY_REF_dup(st) SKM_sk_dup(X509_POLICY_REF, st) +#define sk_X509_POLICY_REF_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_REF, (st), (free_func)) +#define sk_X509_POLICY_REF_shift(st) SKM_sk_shift(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_pop(st) SKM_sk_pop(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_sort(st) SKM_sk_sort(X509_POLICY_REF, (st)) +#define sk_X509_POLICY_REF_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_REF, (st)) + +#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE) +#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_num(st) SKM_sk_num(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_value(st, i) SKM_sk_value(X509_PURPOSE, (st), (i)) +#define sk_X509_PURPOSE_set(st, i, val) SKM_sk_set(X509_PURPOSE, (st), (i), (val)) +#define sk_X509_PURPOSE_zero(st) SKM_sk_zero(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val)) +#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val)) +#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val)) +#define sk_X509_PURPOSE_find_ex(st, val) SKM_sk_find_ex(X509_PURPOSE, (st), (val)) +#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i)) +#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr)) +#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i)) +#define sk_X509_PURPOSE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_PURPOSE, (st), (cmp)) +#define sk_X509_PURPOSE_dup(st) SKM_sk_dup(X509_PURPOSE, st) +#define sk_X509_PURPOSE_pop_free(st, free_func) SKM_sk_pop_free(X509_PURPOSE, (st), (free_func)) +#define sk_X509_PURPOSE_shift(st) SKM_sk_shift(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_pop(st) SKM_sk_pop(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_sort(st) SKM_sk_sort(X509_PURPOSE, (st)) +#define sk_X509_PURPOSE_is_sorted(st) SKM_sk_is_sorted(X509_PURPOSE, (st)) + +#define sk_X509_REVOKED_new(st) SKM_sk_new(X509_REVOKED, (st)) +#define sk_X509_REVOKED_new_null() SKM_sk_new_null(X509_REVOKED) +#define sk_X509_REVOKED_free(st) SKM_sk_free(X509_REVOKED, (st)) +#define sk_X509_REVOKED_num(st) SKM_sk_num(X509_REVOKED, (st)) +#define sk_X509_REVOKED_value(st, i) SKM_sk_value(X509_REVOKED, (st), (i)) +#define sk_X509_REVOKED_set(st, i, val) SKM_sk_set(X509_REVOKED, (st), (i), (val)) +#define sk_X509_REVOKED_zero(st) SKM_sk_zero(X509_REVOKED, (st)) +#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val)) +#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val)) +#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val)) +#define sk_X509_REVOKED_find_ex(st, val) SKM_sk_find_ex(X509_REVOKED, (st), (val)) +#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i)) +#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr)) +#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i)) +#define sk_X509_REVOKED_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_REVOKED, (st), (cmp)) +#define sk_X509_REVOKED_dup(st) SKM_sk_dup(X509_REVOKED, st) +#define sk_X509_REVOKED_pop_free(st, free_func) SKM_sk_pop_free(X509_REVOKED, (st), (free_func)) +#define sk_X509_REVOKED_shift(st) SKM_sk_shift(X509_REVOKED, (st)) +#define sk_X509_REVOKED_pop(st) SKM_sk_pop(X509_REVOKED, (st)) +#define sk_X509_REVOKED_sort(st) SKM_sk_sort(X509_REVOKED, (st)) +#define sk_X509_REVOKED_is_sorted(st) SKM_sk_is_sorted(X509_REVOKED, (st)) + +#define sk_X509_TRUST_new(st) SKM_sk_new(X509_TRUST, (st)) +#define sk_X509_TRUST_new_null() SKM_sk_new_null(X509_TRUST) +#define sk_X509_TRUST_free(st) SKM_sk_free(X509_TRUST, (st)) +#define sk_X509_TRUST_num(st) SKM_sk_num(X509_TRUST, (st)) +#define sk_X509_TRUST_value(st, i) SKM_sk_value(X509_TRUST, (st), (i)) +#define sk_X509_TRUST_set(st, i, val) SKM_sk_set(X509_TRUST, (st), (i), (val)) +#define sk_X509_TRUST_zero(st) SKM_sk_zero(X509_TRUST, (st)) +#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val)) +#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val)) +#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val)) +#define sk_X509_TRUST_find_ex(st, val) SKM_sk_find_ex(X509_TRUST, (st), (val)) +#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i)) +#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr)) +#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i)) +#define sk_X509_TRUST_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_TRUST, (st), (cmp)) +#define sk_X509_TRUST_dup(st) SKM_sk_dup(X509_TRUST, st) +#define sk_X509_TRUST_pop_free(st, free_func) SKM_sk_pop_free(X509_TRUST, (st), (free_func)) +#define sk_X509_TRUST_shift(st) SKM_sk_shift(X509_TRUST, (st)) +#define sk_X509_TRUST_pop(st) SKM_sk_pop(X509_TRUST, (st)) +#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st)) +#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st)) + +#define sk_X509_VERIFY_PARAM_new(st) SKM_sk_new(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_new_null() SKM_sk_new_null(X509_VERIFY_PARAM) +#define sk_X509_VERIFY_PARAM_free(st) SKM_sk_free(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_num(st) SKM_sk_num(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_value(st, i) SKM_sk_value(X509_VERIFY_PARAM, (st), (i)) +#define sk_X509_VERIFY_PARAM_set(st, i, val) SKM_sk_set(X509_VERIFY_PARAM, (st), (i), (val)) +#define sk_X509_VERIFY_PARAM_zero(st) SKM_sk_zero(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_push(st, val) SKM_sk_push(X509_VERIFY_PARAM, (st), (val)) +#define sk_X509_VERIFY_PARAM_unshift(st, val) SKM_sk_unshift(X509_VERIFY_PARAM, (st), (val)) +#define sk_X509_VERIFY_PARAM_find(st, val) SKM_sk_find(X509_VERIFY_PARAM, (st), (val)) +#define sk_X509_VERIFY_PARAM_find_ex(st, val) SKM_sk_find_ex(X509_VERIFY_PARAM, (st), (val)) +#define sk_X509_VERIFY_PARAM_delete(st, i) SKM_sk_delete(X509_VERIFY_PARAM, (st), (i)) +#define sk_X509_VERIFY_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_VERIFY_PARAM, (st), (ptr)) +#define sk_X509_VERIFY_PARAM_insert(st, val, i) SKM_sk_insert(X509_VERIFY_PARAM, (st), (val), (i)) +#define sk_X509_VERIFY_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_VERIFY_PARAM, (st), (cmp)) +#define sk_X509_VERIFY_PARAM_dup(st) SKM_sk_dup(X509_VERIFY_PARAM, st) +#define sk_X509_VERIFY_PARAM_pop_free(st, free_func) SKM_sk_pop_free(X509_VERIFY_PARAM, (st), (free_func)) +#define sk_X509_VERIFY_PARAM_shift(st) SKM_sk_shift(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_pop(st) SKM_sk_pop(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_sort(st) SKM_sk_sort(X509_VERIFY_PARAM, (st)) +#define sk_X509_VERIFY_PARAM_is_sorted(st) SKM_sk_is_sorted(X509_VERIFY_PARAM, (st)) + +#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(ACCESS_DESCRIPTION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_ACCESS_DESCRIPTION(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(ACCESS_DESCRIPTION, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_ACCESS_DESCRIPTION(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(ACCESS_DESCRIPTION, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_ASN1_INTEGER(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(ASN1_INTEGER, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_ASN1_INTEGER(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(ASN1_INTEGER, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_ASN1_INTEGER(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(ASN1_INTEGER, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_ASN1_INTEGER(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(ASN1_INTEGER, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_ASN1_OBJECT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(ASN1_OBJECT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_ASN1_OBJECT(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(ASN1_OBJECT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_ASN1_OBJECT(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(ASN1_OBJECT, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_ASN1_OBJECT(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(ASN1_OBJECT, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_ASN1_TYPE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(ASN1_TYPE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_ASN1_TYPE(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(ASN1_TYPE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_ASN1_TYPE(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(ASN1_TYPE, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(DIST_POINT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_DIST_POINT(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(DIST_POINT, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(GENERAL_NAME, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_GENERAL_NAME(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(GENERAL_NAME, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_GENERAL_NAME(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(GENERAL_NAME, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_OCSP_ONEREQ(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(OCSP_ONEREQ, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_OCSP_ONEREQ(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(OCSP_ONEREQ, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_OCSP_ONEREQ(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(OCSP_ONEREQ, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_OCSP_ONEREQ(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(OCSP_ONEREQ, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(OCSP_SINGLERESP, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(OCSP_SINGLERESP, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_OCSP_SINGLERESP(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(OCSP_SINGLERESP, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_OCSP_SINGLERESP(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(OCSP_SINGLERESP, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(PKCS12_SAFEBAG, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(PKCS12_SAFEBAG, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_PKCS12_SAFEBAG(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(PKCS12_SAFEBAG, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_PKCS12_SAFEBAG(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(PKCS12_SAFEBAG, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_PKCS7(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(PKCS7, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_PKCS7(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(PKCS7, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_PKCS7(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(PKCS7, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_PKCS7(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(PKCS7, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(PKCS7_RECIP_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(PKCS7_RECIP_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_PKCS7_RECIP_INFO(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(PKCS7_RECIP_INFO, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_PKCS7_RECIP_INFO(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(PKCS7_RECIP_INFO, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(PKCS7_SIGNER_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(PKCS7_SIGNER_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_PKCS7_SIGNER_INFO(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(PKCS7_SIGNER_INFO, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_PKCS7_SIGNER_INFO(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(PKCS7_SIGNER_INFO, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_POLICYINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(POLICYINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_POLICYINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(POLICYINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_POLICYINFO(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(POLICYINFO, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_POLICYINFO(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(POLICYINFO, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_POLICYQUALINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(POLICYQUALINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_POLICYQUALINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(POLICYQUALINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_POLICYQUALINFO(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(POLICYQUALINFO, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_POLICYQUALINFO(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(POLICYQUALINFO, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_SXNETID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(SXNETID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_SXNETID(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(SXNETID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_SXNETID(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(SXNETID, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_SXNETID(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(SXNETID, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_ALGOR(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_ALGOR, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_ALGOR(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_ALGOR, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_ALGOR(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_ALGOR, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_ALGOR(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_ALGOR, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_ATTRIBUTE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_ATTRIBUTE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_ATTRIBUTE(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_ATTRIBUTE, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_ATTRIBUTE(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_ATTRIBUTE, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_CRL(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_CRL, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_CRL(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_CRL, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_CRL(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_CRL, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_CRL(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_CRL, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_EXTENSION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_EXTENSION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_EXTENSION(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_EXTENSION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_EXTENSION(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_EXTENSION, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_EXTENSION(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_EXTENSION, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_NAME_ENTRY, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_NAME_ENTRY, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_NAME_ENTRY(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_NAME_ENTRY, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_NAME_ENTRY(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_NAME_ENTRY, (buf), (len), (d2i_func), (free_func)) + +#define d2i_ASN1_SET_OF_X509_REVOKED(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ + SKM_ASN1_SET_OF_d2i(X509_REVOKED, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) +#define i2d_ASN1_SET_OF_X509_REVOKED(st, pp, i2d_func, ex_tag, ex_class, is_set) \ + SKM_ASN1_SET_OF_i2d(X509_REVOKED, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set)) +#define ASN1_seq_pack_X509_REVOKED(st, i2d_func, buf, len) \ + SKM_ASN1_seq_pack(X509_REVOKED, (st), (i2d_func), (buf), (len)) +#define ASN1_seq_unpack_X509_REVOKED(buf, len, d2i_func, free_func) \ + SKM_ASN1_seq_unpack(X509_REVOKED, (buf), (len), (d2i_func), (free_func)) + +#define PKCS12_decrypt_d2i_PKCS12_SAFEBAG(algor, d2i_func, free_func, pass, passlen, oct, seq) \ + SKM_PKCS12_decrypt_d2i(PKCS12_SAFEBAG, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq)) + +#define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \ + SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq)) +/* End of util/mkstack.pl block, you may now edit :-) */ + +#endif /* !defined HEADER_SAFESTACK_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/sha.h b/石器时代8.5客户端最新源代码/石器源码/openssl/sha.h new file mode 100644 index 0000000..47a2c29 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/sha.h @@ -0,0 +1,203 @@ +/* crypto/sha/sha.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_SHA_H +#define HEADER_SHA_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) +#error SHA is disabled. +#endif + +#if defined(OPENSSL_FIPS) +#define FIPS_SHA_SIZE_T size_t +#endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! SHA_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) +#define SHA_LONG unsigned long +#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) +#define SHA_LONG unsigned long +#define SHA_LONG_LOG2 3 +#else +#define SHA_LONG unsigned int +#endif + +#define SHA_LBLOCK 16 +#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a + * contiguous array of 32 bit + * wide big-endian values. */ +#define SHA_LAST_BLOCK (SHA_CBLOCK-8) +#define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st + { + SHA_LONG h0,h1,h2,h3,h4; + SHA_LONG Nl,Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num; + } SHA_CTX; + +#ifndef OPENSSL_NO_SHA0 +#ifdef OPENSSL_FIPS +int private_SHA_Init(SHA_CTX *c); +#endif +int SHA_Init(SHA_CTX *c); +int SHA_Update(SHA_CTX *c, const void *data, size_t len); +int SHA_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); +void SHA_Transform(SHA_CTX *c, const unsigned char *data); +#endif +#ifndef OPENSSL_NO_SHA1 +int SHA1_Init(SHA_CTX *c); +int SHA1_Update(SHA_CTX *c, const void *data, size_t len); +int SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); +#endif + +#define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a + * contiguous array of 32 bit + * wide big-endian values. */ +#define SHA224_DIGEST_LENGTH 28 +#define SHA256_DIGEST_LENGTH 32 + +typedef struct SHA256state_st + { + SHA_LONG h[8]; + SHA_LONG Nl,Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num,md_len; + } SHA256_CTX; + +#ifndef OPENSSL_NO_SHA256 +int SHA224_Init(SHA256_CTX *c); +int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA224_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md); +int SHA256_Init(SHA256_CTX *c); +int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA256_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); +void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); +#endif + +#define SHA384_DIGEST_LENGTH 48 +#define SHA512_DIGEST_LENGTH 64 + +#ifndef OPENSSL_NO_SHA512 +/* + * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 + * being exactly 64-bit wide. See Implementation Notes in sha512.c + * for further details. + */ +#define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a + * contiguous array of 64 bit + * wide big-endian values. */ +#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) +#define SHA_LONG64 unsigned __int64 +#define U64(C) C##UI64 +#elif defined(__arch64__) +#define SHA_LONG64 unsigned long +#define U64(C) C##UL +#else +#define SHA_LONG64 unsigned long long +#define U64(C) C##ULL +#endif + +typedef struct SHA512state_st + { + SHA_LONG64 h[8]; + SHA_LONG64 Nl,Nh; + union { + SHA_LONG64 d[SHA_LBLOCK]; + unsigned char p[SHA512_CBLOCK]; + } u; + unsigned int num,md_len; + } SHA512_CTX; +#endif + +#ifndef OPENSSL_NO_SHA512 +int SHA384_Init(SHA512_CTX *c); +int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA384_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md); +int SHA512_Init(SHA512_CTX *c); +int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA512_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md); +void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ssl.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl.h new file mode 100644 index 0000000..ff8a128 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl.h @@ -0,0 +1,2075 @@ +/* ssl/ssl.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* ==================================================================== + * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECC cipher suite support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_SSL_H +#define HEADER_SSL_H + +#include + +#ifndef OPENSSL_NO_COMP +#include +#endif +#ifndef OPENSSL_NO_BIO +#include +#endif +#ifndef OPENSSL_NO_DEPRECATED +#ifndef OPENSSL_NO_X509 +#include +#endif +#include +#include +#include +#endif +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* SSLeay version number for ASN.1 encoding of the session information */ +/* Version 0 - initial version + * Version 1 - added the optional peer certificate + */ +#define SSL_SESSION_ASN1_VERSION 0x0001 + +/* text strings for the ciphers */ +#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5 +#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5 +#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 +#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5 +#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 +#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5 +#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5 +#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA +#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 +#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA + +/* VRS Additional Kerberos5 entries + */ +#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA +#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA +#define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA +#define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA +#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5 +#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5 +#define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5 +#define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5 + +#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA +#define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA +#define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA +#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 +#define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5 +#define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5 + +#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA +#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 +#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA +#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5 +#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA +#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5 +#define SSL_MAX_KRB5_PRINCIPAL_LENGTH 256 + +#define SSL_MAX_SSL_SESSION_ID_LENGTH 32 +#define SSL_MAX_SID_CTX_LENGTH 32 + +#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) +#define SSL_MAX_KEY_ARG_LENGTH 8 +#define SSL_MAX_MASTER_KEY_LENGTH 48 + +/* These are used to specify which ciphers to use and not to use */ +#define SSL_TXT_LOW "LOW" +#define SSL_TXT_MEDIUM "MEDIUM" +#define SSL_TXT_HIGH "HIGH" +#define SSL_TXT_FIPS "FIPS" +#define SSL_TXT_kFZA "kFZA" +#define SSL_TXT_aFZA "aFZA" +#define SSL_TXT_eFZA "eFZA" +#define SSL_TXT_FZA "FZA" + +#define SSL_TXT_aNULL "aNULL" +#define SSL_TXT_eNULL "eNULL" +#define SSL_TXT_NULL "NULL" + +#define SSL_TXT_kKRB5 "kKRB5" +#define SSL_TXT_aKRB5 "aKRB5" +#define SSL_TXT_KRB5 "KRB5" + +#define SSL_TXT_kRSA "kRSA" +#define SSL_TXT_kDHr "kDHr" +#define SSL_TXT_kDHd "kDHd" +#define SSL_TXT_kEDH "kEDH" +#define SSL_TXT_aRSA "aRSA" +#define SSL_TXT_aDSS "aDSS" +#define SSL_TXT_aDH "aDH" +#define SSL_TXT_DSS "DSS" +#define SSL_TXT_DH "DH" +#define SSL_TXT_EDH "EDH" +#define SSL_TXT_ADH "ADH" +#define SSL_TXT_RSA "RSA" +#define SSL_TXT_DES "DES" +#define SSL_TXT_3DES "3DES" +#define SSL_TXT_RC4 "RC4" +#define SSL_TXT_RC2 "RC2" +#define SSL_TXT_IDEA "IDEA" +#define SSL_TXT_SEED "SEED" +#define SSL_TXT_AES "AES" +#define SSL_TXT_CAMELLIA "CAMELLIA" +#define SSL_TXT_MD5 "MD5" +#define SSL_TXT_SHA1 "SHA1" +#define SSL_TXT_SHA "SHA" +#define SSL_TXT_EXP "EXP" +#define SSL_TXT_EXPORT "EXPORT" +#define SSL_TXT_EXP40 "EXPORT40" +#define SSL_TXT_EXP56 "EXPORT56" +#define SSL_TXT_SSLV2 "SSLv2" +#define SSL_TXT_SSLV3 "SSLv3" +#define SSL_TXT_TLSV1 "TLSv1" +#define SSL_TXT_ALL "ALL" +#define SSL_TXT_ECC "ECCdraft" /* ECC ciphersuites are not yet official */ + +/* + * COMPLEMENTOF* definitions. These identifiers are used to (de-select) + * ciphers normally not being used. + * Example: "RC4" will activate all ciphers using RC4 including ciphers + * without authentication, which would normally disabled by DEFAULT (due + * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT" + * will make sure that it is also disabled in the specific selection. + * COMPLEMENTOF* identifiers are portable between version, as adjustments + * to the default cipher setup will also be included here. + * + * COMPLEMENTOFDEFAULT does not experience the same special treatment that + * DEFAULT gets, as only selection is being done and no sorting as needed + * for DEFAULT. + */ +#define SSL_TXT_CMPALL "COMPLEMENTOFALL" +#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" + +/* The following cipher list is used by default. + * It also is substituted when an application-defined cipher list string + * starts with 'DEFAULT'. */ +#define SSL_DEFAULT_CIPHER_LIST "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" /* low priority for RC4 */ + +/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ +#define SSL_SENT_SHUTDOWN 1 +#define SSL_RECEIVED_SHUTDOWN 2 + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if (defined(OPENSSL_NO_RSA) || defined(OPENSSL_NO_MD5)) && !defined(OPENSSL_NO_SSL2) +#define OPENSSL_NO_SSL2 +#endif + +#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 +#define SSL_FILETYPE_PEM X509_FILETYPE_PEM + +/* This is needed to stop compilers complaining about the + * 'struct ssl_st *' function parameters used to prototype callbacks + * in SSL_CTX. */ +typedef struct ssl_st *ssl_crock_st; + +/* used to hold info on the particular ciphers used */ +typedef struct ssl_cipher_st + { + int valid; + const char *name; /* text name */ + unsigned long id; /* id, 4 bytes, first is version */ + unsigned long algorithms; /* what ciphers are used */ + unsigned long algo_strength; /* strength and export flags */ + unsigned long algorithm2; /* Extra flags */ + int strength_bits; /* Number of bits really used */ + int alg_bits; /* Number of bits for algorithm */ + unsigned long mask; /* used for matching */ + unsigned long mask_strength; /* also used for matching */ + } SSL_CIPHER; + +DECLARE_STACK_OF(SSL_CIPHER) + +/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */ +typedef struct ssl_method_st + { + int version; + int (*ssl_new)(SSL *s); + void (*ssl_clear)(SSL *s); + void (*ssl_free)(SSL *s); + int (*ssl_accept)(SSL *s); + int (*ssl_connect)(SSL *s); + int (*ssl_read)(SSL *s,void *buf,int len); + int (*ssl_peek)(SSL *s,void *buf,int len); + int (*ssl_write)(SSL *s,const void *buf,int len); + int (*ssl_shutdown)(SSL *s); + int (*ssl_renegotiate)(SSL *s); + int (*ssl_renegotiate_check)(SSL *s); + long (*ssl_get_message)(SSL *s, int st1, int stn, int mt, long + max, int *ok); + int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len, + int peek); + int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len); + int (*ssl_dispatch_alert)(SSL *s); + long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg); + long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg); + SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); + int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr); + int (*ssl_pending)(const SSL *s); + int (*num_ciphers)(void); + SSL_CIPHER *(*get_cipher)(unsigned ncipher); + struct ssl_method_st *(*get_ssl_method)(int version); + long (*get_timeout)(void); + struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ + int (*ssl_version)(void); + long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void)); + long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void)); + } SSL_METHOD; + +/* Lets make this into an ASN.1 type structure as follows + * SSL_SESSION_ID ::= SEQUENCE { + * version INTEGER, -- structure version number + * SSLversion INTEGER, -- SSL version number + * Cipher OCTET_STRING, -- the 3 byte cipher ID + * Session_ID OCTET_STRING, -- the Session ID + * Master_key OCTET_STRING, -- the master key + * KRB5_principal OCTET_STRING -- optional Kerberos principal + * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument + * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time + * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds + * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate + * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context + * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer' + * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX + * } + * Look in ssl/ssl_asn1.c for more details + * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-). + */ +typedef struct ssl_session_st + { + int ssl_version; /* what ssl version session info is + * being kept in here? */ + + /* only really used in SSLv2 */ + unsigned int key_arg_length; + unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH]; + int master_key_length; + unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH]; + /* session_id - valid? */ + unsigned int session_id_length; + unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH]; + /* this is used to determine whether the session is being reused in + * the appropriate context. It is up to the application to set this, + * via SSL_new */ + unsigned int sid_ctx_length; + unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; + +#ifndef OPENSSL_NO_KRB5 + unsigned int krb5_client_princ_len; + unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH]; +#endif /* OPENSSL_NO_KRB5 */ + + int not_resumable; + + /* The cert is the certificate used to establish this connection */ + struct sess_cert_st /* SESS_CERT */ *sess_cert; + + /* This is the cert for the other end. + * On clients, it will be the same as sess_cert->peer_key->x509 + * (the latter is not enough as sess_cert is not retained + * in the external representation of sessions, see ssl_asn1.c). */ + X509 *peer; + /* when app_verify_callback accepts a session where the peer's certificate + * is not ok, we must remember the error for session reuse: */ + long verify_result; /* only for servers */ + + int references; + long timeout; + long time; + + int compress_meth; /* Need to lookup the method */ + + SSL_CIPHER *cipher; + unsigned long cipher_id; /* when ASN.1 loaded, this + * needs to be used to load + * the 'cipher' structure */ + + STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */ + + CRYPTO_EX_DATA ex_data; /* application specific data */ + + /* These are used to make removal of session-ids more + * efficient and to implement a maximum cache size. */ + struct ssl_session_st *prev,*next; +#ifndef OPENSSL_NO_TLSEXT + char *tlsext_hostname; + /* RFC4507 info */ + unsigned char *tlsext_tick; /* Session ticket */ + size_t tlsext_ticklen; /* Session ticket length */ + long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */ +#endif + } SSL_SESSION; + + +#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L +#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L +#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L +#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L +#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L +#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L /* no effect since 0.9.7h and 0.9.8b */ +#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L +#define SSL_OP_TLS_D5_BUG 0x00000100L +#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L + +/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added + * in OpenSSL 0.9.6d. Usually (depending on the application protocol) + * the workaround is not needed. Unfortunately some broken SSL/TLS + * implementations cannot handle it at all, which is why we include + * it in SSL_OP_ALL. */ +#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L /* added in 0.9.6e */ + +/* SSL_OP_ALL: various bug workarounds that should be rather harmless. + * This used to be 0x000FFFFFL before 0.9.7. */ +#define SSL_OP_ALL 0x00000FFFL + +/* DTLS options */ +#define SSL_OP_NO_QUERY_MTU 0x00001000L +/* Turn on Cookie Exchange (on relevant for servers) */ +#define SSL_OP_COOKIE_EXCHANGE 0x00002000L +/* Don't use RFC4507 ticket extension */ +#define SSL_OP_NO_TICKET 0x00004000L + +/* As server, disallow session resumption on renegotiation */ +#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L +/* If set, always create a new key when using tmp_ecdh parameters */ +#define SSL_OP_SINGLE_ECDH_USE 0x00080000L +/* If set, always create a new key when using tmp_dh parameters */ +#define SSL_OP_SINGLE_DH_USE 0x00100000L +/* Set to always use the tmp_rsa key when doing RSA operations, + * even when this violates protocol specs */ +#define SSL_OP_EPHEMERAL_RSA 0x00200000L +/* Set on servers to choose the cipher according to the server's + * preferences */ +#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L +/* If set, a server will allow a client to issue a SSLv3.0 version number + * as latest version supported in the premaster secret, even when TLSv1.0 + * (version 3.1) was announced in the client hello. Normally this is + * forbidden to prevent version rollback attacks. */ +#define SSL_OP_TLS_ROLLBACK_BUG 0x00800000L + +#define SSL_OP_NO_SSLv2 0x01000000L +#define SSL_OP_NO_SSLv3 0x02000000L +#define SSL_OP_NO_TLSv1 0x04000000L + +/* The next flag deliberately changes the ciphertest, this is a check + * for the PKCS#1 attack */ +#define SSL_OP_PKCS1_CHECK_1 0x08000000L +#define SSL_OP_PKCS1_CHECK_2 0x10000000L +#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L +#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x40000000L + + +/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success + * when just a single record has been written): */ +#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L +/* Make it possible to retry SSL_write() with changed buffer location + * (buffer contents must stay the same!); this is not the default to avoid + * the misconception that non-blocking SSL_write() behaves like + * non-blocking write(): */ +#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L +/* Never bother the application with retries if the transport + * is blocking: */ +#define SSL_MODE_AUTO_RETRY 0x00000004L +/* Don't attempt to automatically build certificate chain */ +#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L + + +/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, + * they cannot be used to clear bits. */ + +#define SSL_CTX_set_options(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL) +#define SSL_CTX_get_options(ctx) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL) +#define SSL_set_options(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL) +#define SSL_get_options(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL) + +#define SSL_CTX_set_mode(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) +#define SSL_CTX_get_mode(ctx) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL) +#define SSL_set_mode(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) +#define SSL_get_mode(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) +#define SSL_set_mtu(ssl, mtu) \ + SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL) + + +void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); +void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); +#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) +#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) + + + +#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) +#define SSL_MAX_CERT_LIST_DEFAULT 1024*30 /* 30k max cert list :-) */ +#else +#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */ +#endif + +#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) + +/* This callback type is used inside SSL_CTX, SSL, and in the functions that set + * them. It is used to override the generation of SSL/TLS session IDs in a + * server. Return value should be zero on an error, non-zero to proceed. Also, + * callbacks should themselves check if the id they generate is unique otherwise + * the SSL handshake will fail with an error - callbacks can do this using the + * 'ssl' value they're passed by; + * SSL_has_matching_session_id(ssl, id, *id_len) + * The length value passed in is set at the maximum size the session ID can be. + * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback + * can alter this length to be less if desired, but under SSLv2 session IDs are + * supposed to be fixed at 16 bytes so the id will be padded after the callback + * returns in this case. It is also an error for the callback to set the size to + * zero. */ +typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id, + unsigned int *id_len); + +typedef struct ssl_comp_st + { + int id; + const char *name; +#ifndef OPENSSL_NO_COMP + COMP_METHOD *method; +#else + char *method; +#endif + } SSL_COMP; + +DECLARE_STACK_OF(SSL_COMP) + +struct ssl_ctx_st + { + SSL_METHOD *method; + + STACK_OF(SSL_CIPHER) *cipher_list; + /* same as above but sorted for lookup */ + STACK_OF(SSL_CIPHER) *cipher_list_by_id; + + struct x509_store_st /* X509_STORE */ *cert_store; + struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */ + /* Most session-ids that will be cached, default is + * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */ + unsigned long session_cache_size; + struct ssl_session_st *session_cache_head; + struct ssl_session_st *session_cache_tail; + + /* This can have one of 2 values, ored together, + * SSL_SESS_CACHE_CLIENT, + * SSL_SESS_CACHE_SERVER, + * Default is SSL_SESSION_CACHE_SERVER, which means only + * SSL_accept which cache SSL_SESSIONS. */ + int session_cache_mode; + + /* If timeout is not 0, it is the default timeout value set + * when SSL_new() is called. This has been put in to make + * life easier to set things up */ + long session_timeout; + + /* If this callback is not null, it will be called each + * time a session id is added to the cache. If this function + * returns 1, it means that the callback will do a + * SSL_SESSION_free() when it has finished using it. Otherwise, + * on 0, it means the callback has finished with it. + * If remove_session_cb is not null, it will be called when + * a session-id is removed from the cache. After the call, + * OpenSSL will SSL_SESSION_free() it. */ + int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess); + void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess); + SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, + unsigned char *data,int len,int *copy); + + struct + { + int sess_connect; /* SSL new conn - started */ + int sess_connect_renegotiate;/* SSL reneg - requested */ + int sess_connect_good; /* SSL new conne/reneg - finished */ + int sess_accept; /* SSL new accept - started */ + int sess_accept_renegotiate;/* SSL reneg - requested */ + int sess_accept_good; /* SSL accept/reneg - finished */ + int sess_miss; /* session lookup misses */ + int sess_timeout; /* reuse attempt on timeouted session */ + int sess_cache_full; /* session removed due to full cache */ + int sess_hit; /* session reuse actually done */ + int sess_cb_hit; /* session-id that was not + * in the cache was + * passed back via the callback. This + * indicates that the application is + * supplying session-id's from other + * processes - spooky :-) */ + } stats; + + int references; + + /* if defined, these override the X509_verify_cert() calls */ + int (*app_verify_callback)(X509_STORE_CTX *, void *); + void *app_verify_arg; + /* before OpenSSL 0.9.7, 'app_verify_arg' was ignored + * ('app_verify_callback' was called with just one argument) */ + + /* Default password callback. */ + pem_password_cb *default_passwd_callback; + + /* Default password callback user data. */ + void *default_passwd_callback_userdata; + + /* get client cert callback */ + int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey); + + /* cookie generate callback */ + int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, + unsigned int *cookie_len); + + /* verify cookie callback */ + int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, + unsigned int cookie_len); + + CRYPTO_EX_DATA ex_data; + + const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ + const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */ + const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */ + + STACK_OF(X509) *extra_certs; + STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */ + + + /* Default values used when no per-SSL value is defined follow */ + + void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */ + + /* what we put in client cert requests */ + STACK_OF(X509_NAME) *client_CA; + + + /* Default values to use in SSL structures follow (these are copied by SSL_new) */ + + unsigned long options; + unsigned long mode; + long max_cert_list; + + struct cert_st /* CERT */ *cert; + int read_ahead; + + /* callback that allows applications to peek at protocol messages */ + void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg); + void *msg_callback_arg; + + int verify_mode; + unsigned int sid_ctx_length; + unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; + int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ + + /* Default generate session ID callback. */ + GEN_SESSION_CB generate_session_id; + + X509_VERIFY_PARAM *param; + +#if 0 + int purpose; /* Purpose setting */ + int trust; /* Trust setting */ +#endif + + int quiet_shutdown; + +#ifndef OPENSSL_ENGINE + /* Engine to pass requests for client certs to + */ + ENGINE *client_cert_engine; +#endif + +#ifndef OPENSSL_NO_TLSEXT + /* TLS extensions servername callback */ + int (*tlsext_servername_callback)(SSL*, int *, void *); + void *tlsext_servername_arg; + /* RFC 4507 session ticket keys */ + unsigned char tlsext_tick_key_name[16]; + unsigned char tlsext_tick_hmac_key[16]; + unsigned char tlsext_tick_aes_key[16]; + /* Callback to support customisation of ticket key setting */ + int (*tlsext_ticket_key_cb)(SSL *ssl, + unsigned char *name, unsigned char *iv, + EVP_CIPHER_CTX *ectx, + HMAC_CTX *hctx, int enc); + + /* certificate status request info */ + /* Callback for status request */ + int (*tlsext_status_cb)(SSL *ssl, void *arg); + void *tlsext_status_arg; +#endif + + }; + +#define SSL_SESS_CACHE_OFF 0x0000 +#define SSL_SESS_CACHE_CLIENT 0x0001 +#define SSL_SESS_CACHE_SERVER 0x0002 +#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) +#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 +/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ +#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 +#define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 +#define SSL_SESS_CACHE_NO_INTERNAL \ + (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) + + struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx); +#define SSL_CTX_sess_number(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) +#define SSL_CTX_sess_connect(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) +#define SSL_CTX_sess_connect_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) +#define SSL_CTX_sess_connect_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) +#define SSL_CTX_sess_accept(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) +#define SSL_CTX_sess_accept_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) +#define SSL_CTX_sess_accept_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) +#define SSL_CTX_sess_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) +#define SSL_CTX_sess_cb_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) +#define SSL_CTX_sess_misses(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) +#define SSL_CTX_sess_timeouts(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) +#define SSL_CTX_sess_cache_full(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) + +void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess)); +int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, SSL_SESSION *sess); +void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess)); +void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, SSL_SESSION *sess); +void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,int len,int *copy)); +SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, unsigned char *Data, int len, int *copy); +void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*cb)(const SSL *ssl,int type,int val)); +void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl,int type,int val); +void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey)); +int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey); +#ifndef OPENSSL_NO_ENGINE +int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e); +#endif +void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)); +void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len)); + +#define SSL_NOTHING 1 +#define SSL_WRITING 2 +#define SSL_READING 3 +#define SSL_X509_LOOKUP 4 + +/* These will only be used when doing non-blocking IO */ +#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) +#define SSL_want_read(s) (SSL_want(s) == SSL_READING) +#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) +#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) + +struct ssl_st + { + /* protocol version + * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION) + */ + int version; + int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ + + SSL_METHOD *method; /* SSLv3 */ + + /* There are 2 BIO's even though they are normally both the + * same. This is so data can be read and written to different + * handlers */ + +#ifndef OPENSSL_NO_BIO + BIO *rbio; /* used by SSL_read */ + BIO *wbio; /* used by SSL_write */ + BIO *bbio; /* used during session-id reuse to concatenate + * messages */ +#else + char *rbio; /* used by SSL_read */ + char *wbio; /* used by SSL_write */ + char *bbio; +#endif + /* This holds a variable that indicates what we were doing + * when a 0 or -1 is returned. This is needed for + * non-blocking IO so we know what request needs re-doing when + * in SSL_accept or SSL_connect */ + int rwstate; + + /* true when we are actually in SSL_accept() or SSL_connect() */ + int in_handshake; + int (*handshake_func)(SSL *); + + /* Imagine that here's a boolean member "init" that is + * switched as soon as SSL_set_{accept/connect}_state + * is called for the first time, so that "state" and + * "handshake_func" are properly initialized. But as + * handshake_func is == 0 until then, we use this + * test instead of an "init" member. + */ + + int server; /* are we the server side? - mostly used by SSL_clear*/ + + int new_session;/* 1 if we are to use a new session. + * 2 if we are a server and are inside a handshake + * (i.e. not just sending a HelloRequest) + * NB: For servers, the 'new' session may actually be a previously + * cached session or even the previous session unless + * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */ + int quiet_shutdown;/* don't send shutdown packets */ + int shutdown; /* we have shut things down, 0x01 sent, 0x02 + * for received */ + int state; /* where we are */ + int rstate; /* where we are when reading */ + + BUF_MEM *init_buf; /* buffer used during init */ + void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */ + int init_num; /* amount read/written */ + int init_off; /* amount read/written */ + + /* used internally to point at a raw packet */ + unsigned char *packet; + unsigned int packet_length; + + struct ssl2_state_st *s2; /* SSLv2 variables */ + struct ssl3_state_st *s3; /* SSLv3 variables */ + struct dtls1_state_st *d1; /* DTLSv1 variables */ + + int read_ahead; /* Read as many input bytes as possible + * (for non-blocking reads) */ + + /* callback that allows applications to peek at protocol messages */ + void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg); + void *msg_callback_arg; + + int hit; /* reusing a previous session */ + + X509_VERIFY_PARAM *param; + +#if 0 + int purpose; /* Purpose setting */ + int trust; /* Trust setting */ +#endif + + /* crypto */ + STACK_OF(SSL_CIPHER) *cipher_list; + STACK_OF(SSL_CIPHER) *cipher_list_by_id; + + /* These are the ones being used, the ones in SSL_SESSION are + * the ones to be 'copied' into these ones */ + + EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */ + const EVP_MD *read_hash; /* used for mac generation */ +#ifndef OPENSSL_NO_COMP + COMP_CTX *expand; /* uncompress */ +#else + char *expand; +#endif + + EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */ + const EVP_MD *write_hash; /* used for mac generation */ +#ifndef OPENSSL_NO_COMP + COMP_CTX *compress; /* compression */ +#else + char *compress; +#endif + + /* session info */ + + /* client cert? */ + /* This is used to hold the server certificate used */ + struct cert_st /* CERT */ *cert; + + /* the session_id_context is used to ensure sessions are only reused + * in the appropriate context */ + unsigned int sid_ctx_length; + unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; + + /* This can also be in the session once a session is established */ + SSL_SESSION *session; + + /* Default generate session ID callback. */ + GEN_SESSION_CB generate_session_id; + + /* Used in SSL2 and SSL3 */ + int verify_mode; /* 0 don't care about verify failure. + * 1 fail if verify fails */ + int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ + + void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */ + + int error; /* error bytes to be written */ + int error_code; /* actual code */ + +#ifndef OPENSSL_NO_KRB5 + KSSL_CTX *kssl_ctx; /* Kerberos 5 context */ +#endif /* OPENSSL_NO_KRB5 */ + + SSL_CTX *ctx; + /* set this flag to 1 and a sleep(1) is put into all SSL_read() + * and SSL_write() calls, good for nbio debuging :-) */ + int debug; + + /* extra application data */ + long verify_result; + CRYPTO_EX_DATA ex_data; + + /* for server side, keep the list of CA_dn we can use */ + STACK_OF(X509_NAME) *client_CA; + + int references; + unsigned long options; /* protocol behaviour */ + unsigned long mode; /* API behaviour */ + long max_cert_list; + int first_packet; + int client_version; /* what was passed, used for + * SSLv3/TLS rollback check */ +#ifndef OPENSSL_NO_TLSEXT + /* TLS extension debug callback */ + void (*tlsext_debug_cb)(SSL *s, int client_server, int type, + unsigned char *data, int len, + void *arg); + void *tlsext_debug_arg; + char *tlsext_hostname; + int servername_done; /* no further mod of servername + 0 : call the servername extension callback. + 1 : prepare 2, allow last ack just after in server callback. + 2 : don't call servername callback, no ack in server hello + */ + /* certificate status request info */ + /* Status type or -1 if no status type */ + int tlsext_status_type; + /* Expect OCSP CertificateStatus message */ + int tlsext_status_expected; + /* OCSP status request only */ + STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids; + X509_EXTENSIONS *tlsext_ocsp_exts; + /* OCSP response received or to be sent */ + unsigned char *tlsext_ocsp_resp; + int tlsext_ocsp_resplen; + + /* RFC4507 session ticket expected to be received or sent */ + int tlsext_ticket_expected; + SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */ +#define session_ctx initial_ctx +#else +#define session_ctx ctx +#endif + }; + +#ifdef __cplusplus +} +#endif + +#include +#include +#include /* This is mostly sslv3 with a few tweaks */ +#include /* Datagram TLS */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* compatibility */ +#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg)) +#define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) +#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a)) +#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) +#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) +#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg)) + +/* The following are the possible values for ssl->state are are + * used to indicate where we are up to in the SSL connection establishment. + * The macros that follow are about the only things you should need to use + * and even then, only when using non-blocking IO. + * It can also be useful to work out where you were when the connection + * failed */ + +#define SSL_ST_CONNECT 0x1000 +#define SSL_ST_ACCEPT 0x2000 +#define SSL_ST_MASK 0x0FFF +#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT) +#define SSL_ST_BEFORE 0x4000 +#define SSL_ST_OK 0x03 +#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT) + +#define SSL_CB_LOOP 0x01 +#define SSL_CB_EXIT 0x02 +#define SSL_CB_READ 0x04 +#define SSL_CB_WRITE 0x08 +#define SSL_CB_ALERT 0x4000 /* used in callback */ +#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) +#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) +#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) +#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) +#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) +#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) +#define SSL_CB_HANDSHAKE_START 0x10 +#define SSL_CB_HANDSHAKE_DONE 0x20 + +/* Is the SSL_connection established? */ +#define SSL_get_state(a) SSL_state(a) +#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK) +#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT) +#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE) +#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT) +#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT) + +/* The following 2 states are kept in ssl->rstate when reads fail, + * you should not need these */ +#define SSL_ST_READ_HEADER 0xF0 +#define SSL_ST_READ_BODY 0xF1 +#define SSL_ST_READ_DONE 0xF2 + +/* Obtain latest Finished message + * -- that we sent (SSL_get_finished) + * -- that we expected from peer (SSL_get_peer_finished). + * Returns length (0 == no Finished so far), copies up to 'count' bytes. */ +size_t SSL_get_finished(const SSL *s, void *buf, size_t count); +size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); + +/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options + * are 'ored' with SSL_VERIFY_PEER if they are desired */ +#define SSL_VERIFY_NONE 0x00 +#define SSL_VERIFY_PEER 0x01 +#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 +#define SSL_VERIFY_CLIENT_ONCE 0x04 + +#define OpenSSL_add_ssl_algorithms() SSL_library_init() +#define SSLeay_add_ssl_algorithms() SSL_library_init() + +/* this is for backward compatibility */ +#if 0 /* NEW_SSLEAY */ +#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c) +#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n) +#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b)) +#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b)) +#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b)) +#endif +/* More backward compatibility */ +#define SSL_get_cipher(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +#define SSL_get_cipher_bits(s,np) \ + SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) +#define SSL_get_cipher_version(s) \ + SSL_CIPHER_get_version(SSL_get_current_cipher(s)) +#define SSL_get_cipher_name(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +#define SSL_get_time(a) SSL_SESSION_get_time(a) +#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) +#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) +#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) + +#if 1 /*SSLEAY_MACROS*/ +#define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id) +#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id) +#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ + (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) +#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) PEM_ASN1_read_bio_of(SSL_SESSION,d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,cb,u) +#define PEM_write_SSL_SESSION(fp,x) \ + PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ + PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_SSL_SESSION(bp,x) \ + PEM_ASN1_write_bio_of(SSL_SESSION,i2d_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,NULL,NULL,0,NULL,NULL) +#endif + +#define SSL_AD_REASON_OFFSET 1000 +/* These alert types are for SSLv3 and TLSv1 */ +#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY +#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */ +#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */ +#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED +#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW +#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */ +#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */ +#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */ +#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE +#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE +#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED +#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED +#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN +#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */ +#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */ +#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */ +#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */ +#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR +#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */ +#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */ +#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */ +#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ +#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED +#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION +#define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION +#define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE +#define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME +#define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE + +#define SSL_ERROR_NONE 0 +#define SSL_ERROR_SSL 1 +#define SSL_ERROR_WANT_READ 2 +#define SSL_ERROR_WANT_WRITE 3 +#define SSL_ERROR_WANT_X509_LOOKUP 4 +#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */ +#define SSL_ERROR_ZERO_RETURN 6 +#define SSL_ERROR_WANT_CONNECT 7 +#define SSL_ERROR_WANT_ACCEPT 8 + +#define SSL_CTRL_NEED_TMP_RSA 1 +#define SSL_CTRL_SET_TMP_RSA 2 +#define SSL_CTRL_SET_TMP_DH 3 +#define SSL_CTRL_SET_TMP_ECDH 4 +#define SSL_CTRL_SET_TMP_RSA_CB 5 +#define SSL_CTRL_SET_TMP_DH_CB 6 +#define SSL_CTRL_SET_TMP_ECDH_CB 7 + +#define SSL_CTRL_GET_SESSION_REUSED 8 +#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 +#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 +#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 +#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 +#define SSL_CTRL_GET_FLAGS 13 +#define SSL_CTRL_EXTRA_CHAIN_CERT 14 + +#define SSL_CTRL_SET_MSG_CALLBACK 15 +#define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 + +/* only applies to datagram connections */ +#define SSL_CTRL_SET_MTU 17 +/* Stats */ +#define SSL_CTRL_SESS_NUMBER 20 +#define SSL_CTRL_SESS_CONNECT 21 +#define SSL_CTRL_SESS_CONNECT_GOOD 22 +#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 +#define SSL_CTRL_SESS_ACCEPT 24 +#define SSL_CTRL_SESS_ACCEPT_GOOD 25 +#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 +#define SSL_CTRL_SESS_HIT 27 +#define SSL_CTRL_SESS_CB_HIT 28 +#define SSL_CTRL_SESS_MISSES 29 +#define SSL_CTRL_SESS_TIMEOUTS 30 +#define SSL_CTRL_SESS_CACHE_FULL 31 +#define SSL_CTRL_OPTIONS 32 +#define SSL_CTRL_MODE 33 + +#define SSL_CTRL_GET_READ_AHEAD 40 +#define SSL_CTRL_SET_READ_AHEAD 41 +#define SSL_CTRL_SET_SESS_CACHE_SIZE 42 +#define SSL_CTRL_GET_SESS_CACHE_SIZE 43 +#define SSL_CTRL_SET_SESS_CACHE_MODE 44 +#define SSL_CTRL_GET_SESS_CACHE_MODE 45 + +#define SSL_CTRL_GET_MAX_CERT_LIST 50 +#define SSL_CTRL_SET_MAX_CERT_LIST 51 + +/* see tls1.h for macros based on these */ +#ifndef OPENSSL_NO_TLSEXT +#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 +#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 +#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 +#define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 +#define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 +#define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 +#define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 + +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 + +#define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 +#endif + +#define SSL_session_reused(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) +#define SSL_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) +#define SSL_clear_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) +#define SSL_total_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) + +#define SSL_CTX_need_tmp_RSA(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL) +#define SSL_CTX_set_tmp_rsa(ctx,rsa) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) +#define SSL_CTX_set_tmp_dh(ctx,dh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) +#define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) + +#define SSL_need_tmp_RSA(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL) +#define SSL_set_tmp_rsa(ssl,rsa) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) +#define SSL_set_tmp_dh(ssl,dh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) +#define SSL_set_tmp_ecdh(ssl,ecdh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) + +#define SSL_CTX_add_extra_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) + +#ifndef OPENSSL_NO_BIO +BIO_METHOD *BIO_f_ssl(void); +BIO *BIO_new_ssl(SSL_CTX *ctx,int client); +BIO *BIO_new_ssl_connect(SSL_CTX *ctx); +BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); +int BIO_ssl_copy_session_id(BIO *to,BIO *from); +void BIO_ssl_shutdown(BIO *ssl_bio); + +#endif + +int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str); +SSL_CTX *SSL_CTX_new(SSL_METHOD *meth); +void SSL_CTX_free(SSL_CTX *); +long SSL_CTX_set_timeout(SSL_CTX *ctx,long t); +long SSL_CTX_get_timeout(const SSL_CTX *ctx); +X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *); +void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *); +int SSL_want(const SSL *s); +int SSL_clear(SSL *s); + +void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm); + +SSL_CIPHER *SSL_get_current_cipher(const SSL *s); +int SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits); +char * SSL_CIPHER_get_version(const SSL_CIPHER *c); +const char * SSL_CIPHER_get_name(const SSL_CIPHER *c); + +int SSL_get_fd(const SSL *s); +int SSL_get_rfd(const SSL *s); +int SSL_get_wfd(const SSL *s); +const char * SSL_get_cipher_list(const SSL *s,int n); +char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len); +int SSL_get_read_ahead(const SSL * s); +int SSL_pending(const SSL *s); +#ifndef OPENSSL_NO_SOCK +int SSL_set_fd(SSL *s, int fd); +int SSL_set_rfd(SSL *s, int fd); +int SSL_set_wfd(SSL *s, int fd); +#endif +#ifndef OPENSSL_NO_BIO +void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio); +BIO * SSL_get_rbio(const SSL *s); +BIO * SSL_get_wbio(const SSL *s); +#endif +int SSL_set_cipher_list(SSL *s, const char *str); +void SSL_set_read_ahead(SSL *s, int yes); +int SSL_get_verify_mode(const SSL *s); +int SSL_get_verify_depth(const SSL *s); +int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *); +void SSL_set_verify(SSL *s, int mode, + int (*callback)(int ok,X509_STORE_CTX *ctx)); +void SSL_set_verify_depth(SSL *s, int depth); +#ifndef OPENSSL_NO_RSA +int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); +#endif +int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); +int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); +int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, const unsigned char *d, long len); +int SSL_use_certificate(SSL *ssl, X509 *x); +int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); + +#ifndef OPENSSL_NO_STDIO +int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); +int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); +int SSL_use_certificate_file(SSL *ssl, const char *file, int type); +int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); +int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); +int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); +int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */ +STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); +int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *file); +#ifndef OPENSSL_SYS_VMS +#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */ +int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *dir); +#endif +#endif + +#endif + +void SSL_load_error_strings(void ); +const char *SSL_state_string(const SSL *s); +const char *SSL_rstate_string(const SSL *s); +const char *SSL_state_string_long(const SSL *s); +const char *SSL_rstate_string_long(const SSL *s); +long SSL_SESSION_get_time(const SSL_SESSION *s); +long SSL_SESSION_set_time(SSL_SESSION *s, long t); +long SSL_SESSION_get_timeout(const SSL_SESSION *s); +long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); +void SSL_copy_session_id(SSL *to,const SSL *from); + +SSL_SESSION *SSL_SESSION_new(void); +unsigned long SSL_SESSION_hash(const SSL_SESSION *a); +int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b); +const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len); +#ifndef OPENSSL_NO_FP_API +int SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses); +#endif +#ifndef OPENSSL_NO_BIO +int SSL_SESSION_print(BIO *fp,const SSL_SESSION *ses); +#endif +void SSL_SESSION_free(SSL_SESSION *ses); +int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp); +int SSL_set_session(SSL *to, SSL_SESSION *session); +int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c); +int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c); +int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB); +int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB); +int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, + unsigned int id_len); +SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char **pp, + long length); + +#ifdef HEADER_X509_H +X509 * SSL_get_peer_certificate(const SSL *s); +#endif + +STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s); + +int SSL_CTX_get_verify_mode(const SSL_CTX *ctx); +int SSL_CTX_get_verify_depth(const SSL_CTX *ctx); +int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *); +void SSL_CTX_set_verify(SSL_CTX *ctx,int mode, + int (*callback)(int, X509_STORE_CTX *)); +void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth); +void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg); +#ifndef OPENSSL_NO_RSA +int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); +#endif +int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len); +int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); +int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, + const unsigned char *d, long len); +int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); +int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d); + +void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); +void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); + +int SSL_CTX_check_private_key(const SSL_CTX *ctx); +int SSL_check_private_key(const SSL *ctx); + +int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +SSL * SSL_new(SSL_CTX *ctx); +int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +int SSL_CTX_set_purpose(SSL_CTX *s, int purpose); +int SSL_set_purpose(SSL *s, int purpose); +int SSL_CTX_set_trust(SSL_CTX *s, int trust); +int SSL_set_trust(SSL *s, int trust); + +void SSL_free(SSL *ssl); +int SSL_accept(SSL *ssl); +int SSL_connect(SSL *ssl); +int SSL_read(SSL *ssl,void *buf,int num); +int SSL_peek(SSL *ssl,void *buf,int num); +int SSL_write(SSL *ssl,const void *buf,int num); +long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg); +long SSL_callback_ctrl(SSL *, int, void (*)(void)); +long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg); +long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void)); + +int SSL_get_error(const SSL *s,int ret_code); +const char *SSL_get_version(const SSL *s); + +/* This sets the 'default' SSL version that SSL_new() will create */ +int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth); + +SSL_METHOD *SSLv2_method(void); /* SSLv2 */ +SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */ +SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */ + +SSL_METHOD *SSLv3_method(void); /* SSLv3 */ +SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */ +SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */ + +SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */ +SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */ +SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */ + +SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ +SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ +SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ + +SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */ +SSL_METHOD *DTLSv1_server_method(void); /* DTLSv1.0 */ +SSL_METHOD *DTLSv1_client_method(void); /* DTLSv1.0 */ + +STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); + +int SSL_do_handshake(SSL *s); +int SSL_renegotiate(SSL *s); +int SSL_renegotiate_pending(SSL *s); +int SSL_shutdown(SSL *s); + +SSL_METHOD *SSL_get_ssl_method(SSL *s); +int SSL_set_ssl_method(SSL *s,SSL_METHOD *method); +const char *SSL_alert_type_string_long(int value); +const char *SSL_alert_type_string(int value); +const char *SSL_alert_desc_string_long(int value); +const char *SSL_alert_desc_string(int value); + +void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list); +void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list); +STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s); +STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s); +int SSL_add_client_CA(SSL *ssl,X509 *x); +int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x); + +void SSL_set_connect_state(SSL *s); +void SSL_set_accept_state(SSL *s); + +long SSL_get_default_timeout(const SSL *s); + +int SSL_library_init(void ); + +char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size); +STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk); + +SSL *SSL_dup(SSL *ssl); + +X509 *SSL_get_certificate(const SSL *ssl); +/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl); + +void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode); +int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx); +void SSL_set_quiet_shutdown(SSL *ssl,int mode); +int SSL_get_quiet_shutdown(const SSL *ssl); +void SSL_set_shutdown(SSL *ssl,int mode); +int SSL_get_shutdown(const SSL *ssl); +int SSL_version(const SSL *ssl); +int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); +int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, + const char *CApath); +#define SSL_get0_session SSL_get_session /* just peek at pointer */ +SSL_SESSION *SSL_get_session(const SSL *ssl); +SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ +SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); +SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx); +void SSL_set_info_callback(SSL *ssl, + void (*cb)(const SSL *ssl,int type,int val)); +void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val); +int SSL_state(const SSL *ssl); + +void SSL_set_verify_result(SSL *ssl,long v); +long SSL_get_verify_result(const SSL *ssl); + +int SSL_set_ex_data(SSL *ssl,int idx,void *data); +void *SSL_get_ex_data(const SSL *ssl,int idx); +int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); + +int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data); +void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss,int idx); +int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); + +int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data); +void *SSL_CTX_get_ex_data(const SSL_CTX *ssl,int idx); +int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); + +int SSL_get_ex_data_X509_STORE_CTX_idx(void ); + +#define SSL_CTX_sess_set_cache_size(ctx,t) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) +#define SSL_CTX_sess_get_cache_size(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) +#define SSL_CTX_set_session_cache_mode(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) +#define SSL_CTX_get_session_cache_mode(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) + +#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) +#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) +#define SSL_CTX_get_read_ahead(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) +#define SSL_CTX_set_read_ahead(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL) +#define SSL_CTX_get_max_cert_list(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +#define SSL_CTX_set_max_cert_list(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) +#define SSL_get_max_cert_list(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +#define SSL_set_max_cert_list(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) + + /* NB: the keylength is only applicable when is_export is true */ +#ifndef OPENSSL_NO_RSA +void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, + RSA *(*cb)(SSL *ssl,int is_export, + int keylength)); + +void SSL_set_tmp_rsa_callback(SSL *ssl, + RSA *(*cb)(SSL *ssl,int is_export, + int keylength)); +#endif +#ifndef OPENSSL_NO_DH +void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, + DH *(*dh)(SSL *ssl,int is_export, + int keylength)); +void SSL_set_tmp_dh_callback(SSL *ssl, + DH *(*dh)(SSL *ssl,int is_export, + int keylength)); +#endif +#ifndef OPENSSL_NO_ECDH +void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx, + EC_KEY *(*ecdh)(SSL *ssl,int is_export, + int keylength)); +void SSL_set_tmp_ecdh_callback(SSL *ssl, + EC_KEY *(*ecdh)(SSL *ssl,int is_export, + int keylength)); +#endif + +#ifndef OPENSSL_NO_COMP +const COMP_METHOD *SSL_get_current_compression(SSL *s); +const COMP_METHOD *SSL_get_current_expansion(SSL *s); +const char *SSL_COMP_get_name(const COMP_METHOD *comp); +STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); +int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm); +#else +const void *SSL_get_current_compression(SSL *s); +const void *SSL_get_current_expansion(SSL *s); +const char *SSL_COMP_get_name(const void *comp); +void *SSL_COMP_get_compression_methods(void); +int SSL_COMP_add_compression_method(int id,void *cm); +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_SSL_strings(void); + +/* Error codes for the SSL functions. */ + +/* Function codes. */ +#define SSL_F_CLIENT_CERTIFICATE 100 +#define SSL_F_CLIENT_FINISHED 167 +#define SSL_F_CLIENT_HELLO 101 +#define SSL_F_CLIENT_MASTER_KEY 102 +#define SSL_F_D2I_SSL_SESSION 103 +#define SSL_F_DO_DTLS1_WRITE 245 +#define SSL_F_DO_SSL3_WRITE 104 +#define SSL_F_DTLS1_ACCEPT 246 +#define SSL_F_DTLS1_BUFFER_RECORD 247 +#define SSL_F_DTLS1_CLIENT_HELLO 248 +#define SSL_F_DTLS1_CONNECT 249 +#define SSL_F_DTLS1_ENC 250 +#define SSL_F_DTLS1_GET_HELLO_VERIFY 251 +#define SSL_F_DTLS1_GET_MESSAGE 252 +#define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT 253 +#define SSL_F_DTLS1_GET_RECORD 254 +#define SSL_F_DTLS1_OUTPUT_CERT_CHAIN 255 +#define SSL_F_DTLS1_PREPROCESS_FRAGMENT 277 +#define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE 256 +#define SSL_F_DTLS1_PROCESS_RECORD 257 +#define SSL_F_DTLS1_READ_BYTES 258 +#define SSL_F_DTLS1_READ_FAILED 259 +#define SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST 260 +#define SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE 261 +#define SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE 262 +#define SSL_F_DTLS1_SEND_CLIENT_VERIFY 263 +#define SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST 264 +#define SSL_F_DTLS1_SEND_SERVER_CERTIFICATE 265 +#define SSL_F_DTLS1_SEND_SERVER_HELLO 266 +#define SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE 267 +#define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268 +#define SSL_F_GET_CLIENT_FINISHED 105 +#define SSL_F_GET_CLIENT_HELLO 106 +#define SSL_F_GET_CLIENT_MASTER_KEY 107 +#define SSL_F_GET_SERVER_FINISHED 108 +#define SSL_F_GET_SERVER_HELLO 109 +#define SSL_F_GET_SERVER_VERIFY 110 +#define SSL_F_I2D_SSL_SESSION 111 +#define SSL_F_READ_N 112 +#define SSL_F_REQUEST_CERTIFICATE 113 +#define SSL_F_SERVER_FINISH 239 +#define SSL_F_SERVER_HELLO 114 +#define SSL_F_SERVER_VERIFY 240 +#define SSL_F_SSL23_ACCEPT 115 +#define SSL_F_SSL23_CLIENT_HELLO 116 +#define SSL_F_SSL23_CONNECT 117 +#define SSL_F_SSL23_GET_CLIENT_HELLO 118 +#define SSL_F_SSL23_GET_SERVER_HELLO 119 +#define SSL_F_SSL23_PEEK 237 +#define SSL_F_SSL23_READ 120 +#define SSL_F_SSL23_WRITE 121 +#define SSL_F_SSL2_ACCEPT 122 +#define SSL_F_SSL2_CONNECT 123 +#define SSL_F_SSL2_ENC_INIT 124 +#define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241 +#define SSL_F_SSL2_PEEK 234 +#define SSL_F_SSL2_READ 125 +#define SSL_F_SSL2_READ_INTERNAL 236 +#define SSL_F_SSL2_SET_CERTIFICATE 126 +#define SSL_F_SSL2_WRITE 127 +#define SSL_F_SSL3_ACCEPT 128 +#define SSL_F_SSL3_CALLBACK_CTRL 233 +#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 +#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 +#define SSL_F_SSL3_CLIENT_HELLO 131 +#define SSL_F_SSL3_CONNECT 132 +#define SSL_F_SSL3_CTRL 213 +#define SSL_F_SSL3_CTX_CTRL 133 +#define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC 279 +#define SSL_F_SSL3_ENC 134 +#define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 +#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 +#define SSL_F_SSL3_GET_CERT_STATUS 288 +#define SSL_F_SSL3_GET_CERT_VERIFY 136 +#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 +#define SSL_F_SSL3_GET_CLIENT_HELLO 138 +#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139 +#define SSL_F_SSL3_GET_FINISHED 140 +#define SSL_F_SSL3_GET_KEY_EXCHANGE 141 +#define SSL_F_SSL3_GET_MESSAGE 142 +#define SSL_F_SSL3_GET_NEW_SESSION_TICKET 283 +#define SSL_F_SSL3_GET_RECORD 143 +#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 +#define SSL_F_SSL3_GET_SERVER_DONE 145 +#define SSL_F_SSL3_GET_SERVER_HELLO 146 +#define SSL_F_SSL3_NEW_SESSION_TICKET 284 +#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 +#define SSL_F_SSL3_PEEK 235 +#define SSL_F_SSL3_READ_BYTES 148 +#define SSL_F_SSL3_READ_N 149 +#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150 +#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151 +#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 +#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 +#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 +#define SSL_F_SSL3_SEND_SERVER_HELLO 242 +#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 +#define SSL_F_SSL3_SETUP_BUFFERS 156 +#define SSL_F_SSL3_SETUP_KEY_BLOCK 157 +#define SSL_F_SSL3_WRITE_BYTES 158 +#define SSL_F_SSL3_WRITE_PENDING 159 +#define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 272 +#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 +#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 +#define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 273 +#define SSL_F_SSL_BAD_METHOD 160 +#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 +#define SSL_F_SSL_CERT_DUP 221 +#define SSL_F_SSL_CERT_INST 222 +#define SSL_F_SSL_CERT_INSTANTIATE 214 +#define SSL_F_SSL_CERT_NEW 162 +#define SSL_F_SSL_CHECK_PRIVATE_KEY 163 +#define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 274 +#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 +#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 +#define SSL_F_SSL_CLEAR 164 +#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165 +#define SSL_F_SSL_CREATE_CIPHER_LIST 166 +#define SSL_F_SSL_CTRL 232 +#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168 +#define SSL_F_SSL_CTX_NEW 169 +#define SSL_F_SSL_CTX_SET_CIPHER_LIST 269 +#define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE 278 +#define SSL_F_SSL_CTX_SET_PURPOSE 226 +#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219 +#define SSL_F_SSL_CTX_SET_SSL_VERSION 170 +#define SSL_F_SSL_CTX_SET_TRUST 229 +#define SSL_F_SSL_CTX_USE_CERTIFICATE 171 +#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172 +#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220 +#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173 +#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174 +#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175 +#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176 +#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177 +#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178 +#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179 +#define SSL_F_SSL_DO_HANDSHAKE 180 +#define SSL_F_SSL_GET_NEW_SESSION 181 +#define SSL_F_SSL_GET_PREV_SESSION 217 +#define SSL_F_SSL_GET_SERVER_SEND_CERT 182 +#define SSL_F_SSL_GET_SIGN_PKEY 183 +#define SSL_F_SSL_INIT_WBIO_BUFFER 184 +#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 +#define SSL_F_SSL_NEW 186 +#define SSL_F_SSL_PEEK 270 +#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT 275 +#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT 276 +#define SSL_F_SSL_READ 223 +#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187 +#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188 +#define SSL_F_SSL_SESSION_NEW 189 +#define SSL_F_SSL_SESSION_PRINT_FP 190 +#define SSL_F_SSL_SESS_CERT_NEW 225 +#define SSL_F_SSL_SET_CERT 191 +#define SSL_F_SSL_SET_CIPHER_LIST 271 +#define SSL_F_SSL_SET_FD 192 +#define SSL_F_SSL_SET_PKEY 193 +#define SSL_F_SSL_SET_PURPOSE 227 +#define SSL_F_SSL_SET_RFD 194 +#define SSL_F_SSL_SET_SESSION 195 +#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218 +#define SSL_F_SSL_SET_TRUST 228 +#define SSL_F_SSL_SET_WFD 196 +#define SSL_F_SSL_SHUTDOWN 224 +#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243 +#define SSL_F_SSL_UNDEFINED_FUNCTION 197 +#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244 +#define SSL_F_SSL_USE_CERTIFICATE 198 +#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 +#define SSL_F_SSL_USE_CERTIFICATE_FILE 200 +#define SSL_F_SSL_USE_PRIVATEKEY 201 +#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202 +#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203 +#define SSL_F_SSL_USE_RSAPRIVATEKEY 204 +#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205 +#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206 +#define SSL_F_SSL_VERIFY_CERT_CHAIN 207 +#define SSL_F_SSL_WRITE 208 +#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209 +#define SSL_F_TLS1_ENC 210 +#define SSL_F_TLS1_SETUP_KEY_BLOCK 211 +#define SSL_F_WRITE_PENDING 212 + +/* Reason codes. */ +#define SSL_R_APP_DATA_IN_HANDSHAKE 100 +#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272 +#define SSL_R_BAD_ALERT_RECORD 101 +#define SSL_R_BAD_AUTHENTICATION_TYPE 102 +#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 +#define SSL_R_BAD_CHECKSUM 104 +#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 +#define SSL_R_BAD_DECOMPRESSION 107 +#define SSL_R_BAD_DH_G_LENGTH 108 +#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109 +#define SSL_R_BAD_DH_P_LENGTH 110 +#define SSL_R_BAD_DIGEST_LENGTH 111 +#define SSL_R_BAD_DSA_SIGNATURE 112 +#define SSL_R_BAD_ECC_CERT 304 +#define SSL_R_BAD_ECDSA_SIGNATURE 305 +#define SSL_R_BAD_ECPOINT 306 +#define SSL_R_BAD_HELLO_REQUEST 105 +#define SSL_R_BAD_LENGTH 271 +#define SSL_R_BAD_MAC_DECODE 113 +#define SSL_R_BAD_MESSAGE_TYPE 114 +#define SSL_R_BAD_PACKET_LENGTH 115 +#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 +#define SSL_R_BAD_RESPONSE_ARGUMENT 117 +#define SSL_R_BAD_RSA_DECRYPT 118 +#define SSL_R_BAD_RSA_ENCRYPT 119 +#define SSL_R_BAD_RSA_E_LENGTH 120 +#define SSL_R_BAD_RSA_MODULUS_LENGTH 121 +#define SSL_R_BAD_RSA_SIGNATURE 122 +#define SSL_R_BAD_SIGNATURE 123 +#define SSL_R_BAD_SSL_FILETYPE 124 +#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125 +#define SSL_R_BAD_STATE 126 +#define SSL_R_BAD_WRITE_RETRY 127 +#define SSL_R_BIO_NOT_SET 128 +#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 +#define SSL_R_BN_LIB 130 +#define SSL_R_CA_DN_LENGTH_MISMATCH 131 +#define SSL_R_CA_DN_TOO_LONG 132 +#define SSL_R_CCS_RECEIVED_EARLY 133 +#define SSL_R_CERTIFICATE_VERIFY_FAILED 134 +#define SSL_R_CERT_LENGTH_MISMATCH 135 +#define SSL_R_CHALLENGE_IS_DIFFERENT 136 +#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 +#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 +#define SSL_R_CIPHER_TABLE_SRC_ERROR 139 +#define SSL_R_CLIENTHELLO_TLSEXT 157 +#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 +#define SSL_R_COMPRESSION_FAILURE 141 +#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307 +#define SSL_R_COMPRESSION_LIBRARY_ERROR 142 +#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143 +#define SSL_R_CONNECTION_TYPE_NOT_SET 144 +#define SSL_R_COOKIE_MISMATCH 308 +#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 +#define SSL_R_DATA_LENGTH_TOO_LONG 146 +#define SSL_R_DECRYPTION_FAILED 147 +#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 +#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 +#define SSL_R_DIGEST_CHECK_FAILED 149 +#define SSL_R_DUPLICATE_COMPRESSION_ID 309 +#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER 310 +#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 +#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282 +#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 +#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152 +#define SSL_R_EXTRA_DATA_IN_MESSAGE 153 +#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154 +#define SSL_R_HTTPS_PROXY_REQUEST 155 +#define SSL_R_HTTP_REQUEST 156 +#define SSL_R_ILLEGAL_PADDING 283 +#define SSL_R_INVALID_CHALLENGE_LENGTH 158 +#define SSL_R_INVALID_COMMAND 280 +#define SSL_R_INVALID_PURPOSE 278 +#define SSL_R_INVALID_STATUS_RESPONSE 316 +#define SSL_R_INVALID_TICKET_KEYS_LENGTH 275 +#define SSL_R_INVALID_TRUST 279 +#define SSL_R_KEY_ARG_TOO_LONG 284 +#define SSL_R_KRB5 285 +#define SSL_R_KRB5_C_CC_PRINC 286 +#define SSL_R_KRB5_C_GET_CRED 287 +#define SSL_R_KRB5_C_INIT 288 +#define SSL_R_KRB5_C_MK_REQ 289 +#define SSL_R_KRB5_S_BAD_TICKET 290 +#define SSL_R_KRB5_S_INIT 291 +#define SSL_R_KRB5_S_RD_REQ 292 +#define SSL_R_KRB5_S_TKT_EXPIRED 293 +#define SSL_R_KRB5_S_TKT_NYV 294 +#define SSL_R_KRB5_S_TKT_SKEW 295 +#define SSL_R_LENGTH_MISMATCH 159 +#define SSL_R_LENGTH_TOO_SHORT 160 +#define SSL_R_LIBRARY_BUG 274 +#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 +#define SSL_R_MESSAGE_TOO_LONG 296 +#define SSL_R_MISSING_DH_DSA_CERT 162 +#define SSL_R_MISSING_DH_KEY 163 +#define SSL_R_MISSING_DH_RSA_CERT 164 +#define SSL_R_MISSING_DSA_SIGNING_CERT 165 +#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166 +#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167 +#define SSL_R_MISSING_RSA_CERTIFICATE 168 +#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 +#define SSL_R_MISSING_RSA_SIGNING_CERT 170 +#define SSL_R_MISSING_TMP_DH_KEY 171 +#define SSL_R_MISSING_TMP_ECDH_KEY 311 +#define SSL_R_MISSING_TMP_RSA_KEY 172 +#define SSL_R_MISSING_TMP_RSA_PKEY 173 +#define SSL_R_MISSING_VERIFY_MESSAGE 174 +#define SSL_R_NON_SSLV2_INITIAL_PACKET 175 +#define SSL_R_NO_CERTIFICATES_RETURNED 176 +#define SSL_R_NO_CERTIFICATE_ASSIGNED 177 +#define SSL_R_NO_CERTIFICATE_RETURNED 178 +#define SSL_R_NO_CERTIFICATE_SET 179 +#define SSL_R_NO_CERTIFICATE_SPECIFIED 180 +#define SSL_R_NO_CIPHERS_AVAILABLE 181 +#define SSL_R_NO_CIPHERS_PASSED 182 +#define SSL_R_NO_CIPHERS_SPECIFIED 183 +#define SSL_R_NO_CIPHER_LIST 184 +#define SSL_R_NO_CIPHER_MATCH 185 +#define SSL_R_NO_CLIENT_CERT_METHOD 317 +#define SSL_R_NO_CLIENT_CERT_RECEIVED 186 +#define SSL_R_NO_COMPRESSION_SPECIFIED 187 +#define SSL_R_NO_METHOD_SPECIFIED 188 +#define SSL_R_NO_PRIVATEKEY 189 +#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 +#define SSL_R_NO_PROTOCOLS_AVAILABLE 191 +#define SSL_R_NO_PUBLICKEY 192 +#define SSL_R_NO_SHARED_CIPHER 193 +#define SSL_R_NO_VERIFY_CALLBACK 194 +#define SSL_R_NULL_SSL_CTX 195 +#define SSL_R_NULL_SSL_METHOD_PASSED 196 +#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 +#define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297 +#define SSL_R_PACKET_LENGTH_TOO_LONG 198 +#define SSL_R_PARSE_TLSEXT 223 +#define SSL_R_PATH_TOO_LONG 270 +#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 +#define SSL_R_PEER_ERROR 200 +#define SSL_R_PEER_ERROR_CERTIFICATE 201 +#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202 +#define SSL_R_PEER_ERROR_NO_CIPHER 203 +#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204 +#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205 +#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206 +#define SSL_R_PROTOCOL_IS_SHUTDOWN 207 +#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208 +#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209 +#define SSL_R_PUBLIC_KEY_NOT_RSA 210 +#define SSL_R_READ_BIO_NOT_SET 211 +#define SSL_R_READ_TIMEOUT_EXPIRED 312 +#define SSL_R_READ_WRONG_PACKET_TYPE 212 +#define SSL_R_RECORD_LENGTH_MISMATCH 213 +#define SSL_R_RECORD_TOO_LARGE 214 +#define SSL_R_RECORD_TOO_SMALL 298 +#define SSL_R_REQUIRED_CIPHER_MISSING 215 +#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216 +#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217 +#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218 +#define SSL_R_SERVERHELLO_TLSEXT 224 +#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 +#define SSL_R_SHORT_READ 219 +#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 +#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 +#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299 +#define SSL_R_SSL3_EXT_INVALID_SERVERNAME 225 +#define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 226 +#define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 +#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 +#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 +#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 +#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 +#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 +#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 +#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 +#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 +#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 +#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 +#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 +#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 +#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228 +#define SSL_R_SSL_HANDSHAKE_FAILURE 229 +#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230 +#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301 +#define SSL_R_SSL_SESSION_ID_CONFLICT 302 +#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273 +#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303 +#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231 +#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 +#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 +#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 +#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 +#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060 +#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 +#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 +#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 +#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 +#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 +#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 +#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 +#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232 +#define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 227 +#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233 +#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234 +#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235 +#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236 +#define SSL_R_UNABLE_TO_DECODE_ECDH_CERTS 313 +#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237 +#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238 +#define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314 +#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 +#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240 +#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241 +#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242 +#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243 +#define SSL_R_UNEXPECTED_MESSAGE 244 +#define SSL_R_UNEXPECTED_RECORD 245 +#define SSL_R_UNINITIALIZED 276 +#define SSL_R_UNKNOWN_ALERT_TYPE 246 +#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247 +#define SSL_R_UNKNOWN_CIPHER_RETURNED 248 +#define SSL_R_UNKNOWN_CIPHER_TYPE 249 +#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250 +#define SSL_R_UNKNOWN_PKEY_TYPE 251 +#define SSL_R_UNKNOWN_PROTOCOL 252 +#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253 +#define SSL_R_UNKNOWN_SSL_VERSION 254 +#define SSL_R_UNKNOWN_STATE 255 +#define SSL_R_UNSUPPORTED_CIPHER 256 +#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 +#define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315 +#define SSL_R_UNSUPPORTED_PROTOCOL 258 +#define SSL_R_UNSUPPORTED_SSL_VERSION 259 +#define SSL_R_UNSUPPORTED_STATUS_TYPE 329 +#define SSL_R_WRITE_BIO_NOT_SET 260 +#define SSL_R_WRONG_CIPHER_RETURNED 261 +#define SSL_R_WRONG_MESSAGE_TYPE 262 +#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263 +#define SSL_R_WRONG_SIGNATURE_LENGTH 264 +#define SSL_R_WRONG_SIGNATURE_SIZE 265 +#define SSL_R_WRONG_SSL_VERSION 266 +#define SSL_R_WRONG_VERSION_NUMBER 267 +#define SSL_R_X509_LIB 268 +#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ssl2.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl2.h new file mode 100644 index 0000000..99a52ea --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl2.h @@ -0,0 +1,268 @@ +/* ssl/ssl2.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_SSL2_H +#define HEADER_SSL2_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Protocol Version Codes */ +#define SSL2_VERSION 0x0002 +#define SSL2_VERSION_MAJOR 0x00 +#define SSL2_VERSION_MINOR 0x02 +/* #define SSL2_CLIENT_VERSION 0x0002 */ +/* #define SSL2_SERVER_VERSION 0x0002 */ + +/* Protocol Message Codes */ +#define SSL2_MT_ERROR 0 +#define SSL2_MT_CLIENT_HELLO 1 +#define SSL2_MT_CLIENT_MASTER_KEY 2 +#define SSL2_MT_CLIENT_FINISHED 3 +#define SSL2_MT_SERVER_HELLO 4 +#define SSL2_MT_SERVER_VERIFY 5 +#define SSL2_MT_SERVER_FINISHED 6 +#define SSL2_MT_REQUEST_CERTIFICATE 7 +#define SSL2_MT_CLIENT_CERTIFICATE 8 + +/* Error Message Codes */ +#define SSL2_PE_UNDEFINED_ERROR 0x0000 +#define SSL2_PE_NO_CIPHER 0x0001 +#define SSL2_PE_NO_CERTIFICATE 0x0002 +#define SSL2_PE_BAD_CERTIFICATE 0x0004 +#define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006 + +/* Cipher Kind Values */ +#define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */ +#define SSL2_CK_RC4_128_WITH_MD5 0x02010080 +#define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080 +#define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080 +#define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080 +#define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080 +#define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040 +#define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */ +#define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0 +#define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */ +#define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */ + +#define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */ +#define SSL2_CK_NULL 0x02ff0810 /* SSLeay */ + +#define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1" +#define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5" +#define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5" +#define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5" +#define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5" +#define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5" +#define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5" +#define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5" +#define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA" +#define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5" +#define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA" +#define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5" + +#define SSL2_TXT_NULL "NULL" + +/* Flags for the SSL_CIPHER.algorithm2 field */ +#define SSL2_CF_5_BYTE_ENC 0x01 +#define SSL2_CF_8_BYTE_ENC 0x02 + +/* Certificate Type Codes */ +#define SSL2_CT_X509_CERTIFICATE 0x01 + +/* Authentication Type Code */ +#define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01 + +#define SSL2_MAX_SSL_SESSION_ID_LENGTH 32 + +/* Upper/Lower Bounds */ +#define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256 +#ifdef OPENSSL_SYS_MPE +#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u +#else +#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */ +#endif +#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */ + +#define SSL2_CHALLENGE_LENGTH 16 +/*#define SSL2_CHALLENGE_LENGTH 32 */ +#define SSL2_MIN_CHALLENGE_LENGTH 16 +#define SSL2_MAX_CHALLENGE_LENGTH 32 +#define SSL2_CONNECTION_ID_LENGTH 16 +#define SSL2_MAX_CONNECTION_ID_LENGTH 16 +#define SSL2_SSL_SESSION_ID_LENGTH 16 +#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32 +#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16 +#define SSL2_MAX_KEY_MATERIAL_LENGTH 24 + +#ifndef HEADER_SSL_LOCL_H +#define CERT char +#endif + +typedef struct ssl2_state_st + { + int three_byte_header; + int clear_text; /* clear text */ + int escape; /* not used in SSLv2 */ + int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */ + + /* non-blocking io info, used to make sure the same + * args were passwd */ + unsigned int wnum; /* number of bytes sent so far */ + int wpend_tot; + const unsigned char *wpend_buf; + + int wpend_off; /* offset to data to write */ + int wpend_len; /* number of bytes passwd to write */ + int wpend_ret; /* number of bytes to return to caller */ + + /* buffer raw data */ + int rbuf_left; + int rbuf_offs; + unsigned char *rbuf; + unsigned char *wbuf; + + unsigned char *write_ptr;/* used to point to the start due to + * 2/3 byte header. */ + + unsigned int padding; + unsigned int rlength; /* passed to ssl2_enc */ + int ract_data_length; /* Set when things are encrypted. */ + unsigned int wlength; /* passed to ssl2_enc */ + int wact_data_length; /* Set when things are decrypted. */ + unsigned char *ract_data; + unsigned char *wact_data; + unsigned char *mac_data; + + unsigned char *read_key; + unsigned char *write_key; + + /* Stuff specifically to do with this SSL session */ + unsigned int challenge_length; + unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH]; + unsigned int conn_id_length; + unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH]; + unsigned int key_material_length; + unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2]; + + unsigned long read_sequence; + unsigned long write_sequence; + + struct { + unsigned int conn_id_length; + unsigned int cert_type; + unsigned int cert_length; + unsigned int csl; + unsigned int clear; + unsigned int enc; + unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH]; + unsigned int cipher_spec_length; + unsigned int session_id_length; + unsigned int clen; + unsigned int rlen; + } tmp; + } SSL2_STATE; + +/* SSLv2 */ +/* client */ +#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT) +#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT) +#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT) +#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT) +#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT) +/* server */ +#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT) +#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT) +#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT) +#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT) +#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT) + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ssl23.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl23.h new file mode 100644 index 0000000..d322898 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl23.h @@ -0,0 +1,83 @@ +/* ssl/ssl23.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_SSL23_H +#define HEADER_SSL23_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*client */ +/* write to server */ +#define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT) +#define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT) +/* read from server */ +#define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT) +#define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT) + +/* server */ +/* read from client */ +#define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT) +#define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT) + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ssl3.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl3.h new file mode 100644 index 0000000..4b1e2e9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ssl3.h @@ -0,0 +1,565 @@ +/* ssl/ssl3.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECC cipher suite support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_SSL3_H +#define HEADER_SSL3_H + +#ifndef OPENSSL_NO_COMP +#include +#endif +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SSL3_CK_RSA_NULL_MD5 0x03000001 +#define SSL3_CK_RSA_NULL_SHA 0x03000002 +#define SSL3_CK_RSA_RC4_40_MD5 0x03000003 +#define SSL3_CK_RSA_RC4_128_MD5 0x03000004 +#define SSL3_CK_RSA_RC4_128_SHA 0x03000005 +#define SSL3_CK_RSA_RC2_40_MD5 0x03000006 +#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 +#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 +#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 +#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A + +#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B +#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C +#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D +#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E +#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F +#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 + +#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011 +#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012 +#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013 +#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014 +#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015 +#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016 + +#define SSL3_CK_ADH_RC4_40_MD5 0x03000017 +#define SSL3_CK_ADH_RC4_128_MD5 0x03000018 +#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 +#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A +#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B + +#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C +#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D +#if 0 /* Because it clashes with KRB5, is never used any more, and is safe + to remove according to David Hopwood + of the ietf-tls list */ +#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E +#endif + +/* VRS Additional Kerberos5 entries + */ +#define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E +#define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F +#define SSL3_CK_KRB5_RC4_128_SHA 0x03000020 +#define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021 +#define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022 +#define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023 +#define SSL3_CK_KRB5_RC4_128_MD5 0x03000024 +#define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025 + +#define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026 +#define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027 +#define SSL3_CK_KRB5_RC4_40_SHA 0x03000028 +#define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029 +#define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A +#define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B + +#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" +#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" +#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" +#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" +#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" +#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" +#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" +#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" +#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" +#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" + +#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" +#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" +#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" +#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" +#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" +#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" + +#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" +#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" +#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" +#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" +#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" +#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" + +#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" +#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" +#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" +#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" +#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" + +#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA" +#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" +#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" + +#define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA" +#define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA" +#define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA" +#define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA" +#define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5" +#define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5" +#define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5" +#define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5" + +#define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA" +#define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA" +#define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA" +#define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5" +#define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5" +#define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5" + +#define SSL3_SSL_SESSION_ID_LENGTH 32 +#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 + +#define SSL3_MASTER_SECRET_SIZE 48 +#define SSL3_RANDOM_SIZE 32 +#define SSL3_SESSION_ID_SIZE 32 +#define SSL3_RT_HEADER_LENGTH 5 + +/* Due to MS stuffing up, this can change.... */ +#if defined(OPENSSL_SYS_WIN16) || \ + (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32)) +#define SSL3_RT_MAX_EXTRA (14000) +#else +#define SSL3_RT_MAX_EXTRA (16384) +#endif + +#define SSL3_RT_MAX_PLAIN_LENGTH 16384 +#ifdef OPENSSL_NO_COMP +#define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH +#else +#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) +#endif +#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) +#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) +#define SSL3_RT_MAX_DATA_SIZE (1024*1024) + +#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54" +#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52" + +#define SSL3_VERSION 0x0300 +#define SSL3_VERSION_MAJOR 0x03 +#define SSL3_VERSION_MINOR 0x00 + +#define SSL3_RT_CHANGE_CIPHER_SPEC 20 +#define SSL3_RT_ALERT 21 +#define SSL3_RT_HANDSHAKE 22 +#define SSL3_RT_APPLICATION_DATA 23 + +#define SSL3_AL_WARNING 1 +#define SSL3_AL_FATAL 2 + +#define SSL3_AD_CLOSE_NOTIFY 0 +#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */ +#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */ +#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */ +#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */ +#define SSL3_AD_NO_CERTIFICATE 41 +#define SSL3_AD_BAD_CERTIFICATE 42 +#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 +#define SSL3_AD_CERTIFICATE_REVOKED 44 +#define SSL3_AD_CERTIFICATE_EXPIRED 45 +#define SSL3_AD_CERTIFICATE_UNKNOWN 46 +#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */ + +typedef struct ssl3_record_st + { +/*r */ int type; /* type of record */ +/*rw*/ unsigned int length; /* How many bytes available */ +/*r */ unsigned int off; /* read/write offset into 'buf' */ +/*rw*/ unsigned char *data; /* pointer to the record data */ +/*rw*/ unsigned char *input; /* where the decode bytes are */ +/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */ +/*r */ unsigned long epoch; /* epoch number, needed by DTLS1 */ +/*r */ PQ_64BIT seq_num; /* sequence number, needed by DTLS1 */ + } SSL3_RECORD; + +typedef struct ssl3_buffer_st + { + unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes, + * see ssl3_setup_buffers() */ + size_t len; /* buffer size */ + int offset; /* where to 'copy from' */ + int left; /* how many bytes left */ + } SSL3_BUFFER; + +#define SSL3_CT_RSA_SIGN 1 +#define SSL3_CT_DSS_SIGN 2 +#define SSL3_CT_RSA_FIXED_DH 3 +#define SSL3_CT_DSS_FIXED_DH 4 +#define SSL3_CT_RSA_EPHEMERAL_DH 5 +#define SSL3_CT_DSS_EPHEMERAL_DH 6 +#define SSL3_CT_FORTEZZA_DMS 20 +/* SSL3_CT_NUMBER is used to size arrays and it must be large + * enough to contain all of the cert types defined either for + * SSLv3 and TLSv1. + */ +#define SSL3_CT_NUMBER 7 + + +#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 +#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 +#define SSL3_FLAGS_POP_BUFFER 0x0004 +#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008 + +typedef struct ssl3_state_st + { + long flags; + int delay_buf_pop_ret; + + unsigned char read_sequence[8]; + unsigned char read_mac_secret[EVP_MAX_MD_SIZE]; + unsigned char write_sequence[8]; + unsigned char write_mac_secret[EVP_MAX_MD_SIZE]; + + unsigned char server_random[SSL3_RANDOM_SIZE]; + unsigned char client_random[SSL3_RANDOM_SIZE]; + + /* flags for countermeasure against known-IV weakness */ + int need_empty_fragments; + int empty_fragment_done; + + SSL3_BUFFER rbuf; /* read IO goes into here */ + SSL3_BUFFER wbuf; /* write IO goes into here */ + + SSL3_RECORD rrec; /* each decoded record goes in here */ + SSL3_RECORD wrec; /* goes out from here */ + + /* storage for Alert/Handshake protocol data received but not + * yet processed by ssl3_read_bytes: */ + unsigned char alert_fragment[2]; + unsigned int alert_fragment_len; + unsigned char handshake_fragment[4]; + unsigned int handshake_fragment_len; + + /* partial write - check the numbers match */ + unsigned int wnum; /* number of bytes sent so far */ + int wpend_tot; /* number bytes written */ + int wpend_type; + int wpend_ret; /* number of bytes submitted */ + const unsigned char *wpend_buf; + + /* used during startup, digest all incoming/outgoing packets */ + EVP_MD_CTX finish_dgst1; + EVP_MD_CTX finish_dgst2; + + /* this is set whenerver we see a change_cipher_spec message + * come in when we are not looking for one */ + int change_cipher_spec; + + int warn_alert; + int fatal_alert; + /* we allow one fatal and one warning alert to be outstanding, + * send close alert via the warning alert */ + int alert_dispatch; + unsigned char send_alert[2]; + + /* This flag is set when we should renegotiate ASAP, basically when + * there is no more data in the read or write buffers */ + int renegotiate; + int total_renegotiations; + int num_renegotiations; + + int in_read_app_data; + + struct { + /* actually only needs to be 16+20 */ + unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2]; + + /* actually only need to be 16+20 for SSLv3 and 12 for TLS */ + unsigned char finish_md[EVP_MAX_MD_SIZE*2]; + int finish_md_len; + unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2]; + int peer_finish_md_len; + + unsigned long message_size; + int message_type; + + /* used to hold the new cipher we are going to use */ + SSL_CIPHER *new_cipher; +#ifndef OPENSSL_NO_DH + DH *dh; +#endif + +#ifndef OPENSSL_NO_ECDH + EC_KEY *ecdh; /* holds short lived ECDH key */ +#endif + + /* used when SSL_ST_FLUSH_DATA is entered */ + int next_state; + + int reuse_message; + + /* used for certificate requests */ + int cert_req; + int ctype_num; + char ctype[SSL3_CT_NUMBER]; + STACK_OF(X509_NAME) *ca_names; + + int use_rsa_tmp; + + int key_block_length; + unsigned char *key_block; + + const EVP_CIPHER *new_sym_enc; + const EVP_MD *new_hash; +#ifndef OPENSSL_NO_COMP + const SSL_COMP *new_compression; +#else + char *new_compression; +#endif + int cert_request; + } tmp; + + } SSL3_STATE; + + +/* SSLv3 */ +/*client */ +/* extra state */ +#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT) +/* write to server */ +#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT) +#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT) +/* read from server */ +#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) +#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) +#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A (0x126|SSL_ST_CONNECT) +#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B (0x127|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) +#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) +#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT) +#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT) +#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT) +/* write to server */ +#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT) +#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT) +#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT) +#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT) +#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT) +#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT) +#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT) +#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT) +#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT) +#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT) +#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT) +#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT) +/* read from server */ +#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT) +#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) +#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) +#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) +#define SSL3_ST_CR_SESSION_TICKET_A (0x1E0|SSL_ST_CONNECT) +#define SSL3_ST_CR_SESSION_TICKET_B (0x1E1|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_STATUS_A (0x1F0|SSL_ST_CONNECT) +#define SSL3_ST_CR_CERT_STATUS_B (0x1F1|SSL_ST_CONNECT) + +/* server */ +/* extra state */ +#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT) +/* read from client */ +/* Do not change the number values, they do matter */ +#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) +/* write to client */ +#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A (0x113|SSL_ST_ACCEPT) +#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B (0x114|SSL_ST_ACCEPT) +#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) +#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) +#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT) +#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT) +#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT) +/* read from client */ +#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT) +#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT) +#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT) +#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT) +#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT) +#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT) +/* write to client */ +#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) +#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) +#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SESSION_TICKET_A (0x1F0|SSL_ST_ACCEPT) +#define SSL3_ST_SW_SESSION_TICKET_B (0x1F1|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_STATUS_A (0x200|SSL_ST_ACCEPT) +#define SSL3_ST_SW_CERT_STATUS_B (0x201|SSL_ST_ACCEPT) + +#define SSL3_MT_HELLO_REQUEST 0 +#define SSL3_MT_CLIENT_HELLO 1 +#define SSL3_MT_SERVER_HELLO 2 +#define SSL3_MT_NEWSESSION_TICKET 4 +#define SSL3_MT_CERTIFICATE 11 +#define SSL3_MT_SERVER_KEY_EXCHANGE 12 +#define SSL3_MT_CERTIFICATE_REQUEST 13 +#define SSL3_MT_SERVER_DONE 14 +#define SSL3_MT_CERTIFICATE_VERIFY 15 +#define SSL3_MT_CLIENT_KEY_EXCHANGE 16 +#define SSL3_MT_FINISHED 20 +#define SSL3_MT_CERTIFICATE_STATUS 22 +#define DTLS1_MT_HELLO_VERIFY_REQUEST 3 + + +#define SSL3_MT_CCS 1 + +/* These are used when changing over to a new cipher */ +#define SSL3_CC_READ 0x01 +#define SSL3_CC_WRITE 0x02 +#define SSL3_CC_CLIENT 0x10 +#define SSL3_CC_SERVER 0x20 +#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) +#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) +#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) +#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/stack.h b/石器时代8.5客户端最新源代码/石器源码/openssl/stack.h new file mode 100644 index 0000000..5cbb116 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/stack.h @@ -0,0 +1,109 @@ +/* crypto/stack/stack.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_STACK_H +#define HEADER_STACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct stack_st + { + int num; + char **data; + int sorted; + + int num_alloc; + int (*comp)(const char * const *, const char * const *); + } STACK; + +#define M_sk_num(sk) ((sk) ? (sk)->num:-1) +#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) + +int sk_num(const STACK *); +char *sk_value(const STACK *, int); + +char *sk_set(STACK *, int, char *); + +STACK *sk_new(int (*cmp)(const char * const *, const char * const *)); +STACK *sk_new_null(void); +void sk_free(STACK *); +void sk_pop_free(STACK *st, void (*func)(void *)); +int sk_insert(STACK *sk,char *data,int where); +char *sk_delete(STACK *st,int loc); +char *sk_delete_ptr(STACK *st, char *p); +int sk_find(STACK *st,char *data); +int sk_find_ex(STACK *st,char *data); +int sk_push(STACK *st,char *data); +int sk_unshift(STACK *st,char *data); +char *sk_shift(STACK *st); +char *sk_pop(STACK *st); +void sk_zero(STACK *st); +int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *, + const char * const *))) + (const char * const *, const char * const *); +STACK *sk_dup(STACK *st); +void sk_sort(STACK *st); +int sk_is_sorted(const STACK *st); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/store.h b/石器时代8.5客户端最新源代码/石器源码/openssl/store.h new file mode 100644 index 0000000..6458337 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/store.h @@ -0,0 +1,554 @@ +/* crypto/store/store.h -*- mode:C; c-file-style: "eay" -*- */ +/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL + * project 2003. + */ +/* ==================================================================== + * Copyright (c) 2003 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_STORE_H +#define HEADER_STORE_H + +#include +#ifndef OPENSSL_NO_DEPRECATED +#include +#include +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct store_st STORE; */ +/* typedef struct store_method_st STORE_METHOD; */ + + +/* All the following functions return 0, a negative number or NULL on error. + When everything is fine, they return a positive value or a non-NULL + pointer, all depending on their purpose. */ + +/* Creators and destructor. */ +STORE *STORE_new_method(const STORE_METHOD *method); +STORE *STORE_new_engine(ENGINE *engine); +void STORE_free(STORE *ui); + + +/* Give a user interface parametrised control commands. This can be used to + send down an integer, a data pointer or a function pointer, as well as + be used to get information from a STORE. */ +int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void)); + +/* A control to set the directory with keys and certificates. Used by the + built-in directory level method. */ +#define STORE_CTRL_SET_DIRECTORY 0x0001 +/* A control to set a file to load. Used by the built-in file level method. */ +#define STORE_CTRL_SET_FILE 0x0002 +/* A control to set a configuration file to load. Can be used by any method + that wishes to load a configuration file. */ +#define STORE_CTRL_SET_CONF_FILE 0x0003 +/* A control to set a the section of the loaded configuration file. Can be + used by any method that wishes to load a configuration file. */ +#define STORE_CTRL_SET_CONF_SECTION 0x0004 + + +/* Some methods may use extra data */ +#define STORE_set_app_data(s,arg) STORE_set_ex_data(s,0,arg) +#define STORE_get_app_data(s) STORE_get_ex_data(s,0) +int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int STORE_set_ex_data(STORE *r,int idx,void *arg); +void *STORE_get_ex_data(STORE *r, int idx); + +/* Use specific methods instead of the built-in one */ +const STORE_METHOD *STORE_get_method(STORE *store); +const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth); + +/* The standard OpenSSL methods. */ +/* This is the in-memory method. It does everything except revoking and updating, + and is of course volatile. It's used by other methods that have an in-memory + cache. */ +const STORE_METHOD *STORE_Memory(void); +#if 0 /* Not yet implemented */ +/* This is the directory store. It does everything except revoking and updating, + and uses STORE_Memory() to cache things in memory. */ +const STORE_METHOD *STORE_Directory(void); +/* This is the file store. It does everything except revoking and updating, + and uses STORE_Memory() to cache things in memory. Certificates are added + to it with the store operation, and it will only get cached certificates. */ +const STORE_METHOD *STORE_File(void); +#endif + +/* Store functions take a type code for the type of data they should store + or fetch */ +typedef enum STORE_object_types + { + STORE_OBJECT_TYPE_X509_CERTIFICATE= 0x01, /* X509 * */ + STORE_OBJECT_TYPE_X509_CRL= 0x02, /* X509_CRL * */ + STORE_OBJECT_TYPE_PRIVATE_KEY= 0x03, /* EVP_PKEY * */ + STORE_OBJECT_TYPE_PUBLIC_KEY= 0x04, /* EVP_PKEY * */ + STORE_OBJECT_TYPE_NUMBER= 0x05, /* BIGNUM * */ + STORE_OBJECT_TYPE_ARBITRARY= 0x06, /* BUF_MEM * */ + STORE_OBJECT_TYPE_NUM= 0x06 /* The amount of known + object types */ + } STORE_OBJECT_TYPES; +/* List of text strings corresponding to the object types. */ +extern const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1]; + +/* Some store functions take a parameter list. Those parameters come with + one of the following codes. The comments following the codes below indicate + what type the value should be a pointer to. */ +typedef enum STORE_params + { + STORE_PARAM_EVP_TYPE= 0x01, /* int */ + STORE_PARAM_BITS= 0x02, /* size_t */ + STORE_PARAM_KEY_PARAMETERS= 0x03, /* ??? */ + STORE_PARAM_KEY_NO_PARAMETERS= 0x04, /* N/A */ + STORE_PARAM_AUTH_PASSPHRASE= 0x05, /* char * */ + STORE_PARAM_AUTH_KRB5_TICKET= 0x06, /* void * */ + STORE_PARAM_TYPE_NUM= 0x06 /* The amount of known + parameter types */ + } STORE_PARAM_TYPES; +/* Parameter value sizes. -1 means unknown, anything else is the required size. */ +extern const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1]; + +/* Store functions take attribute lists. Those attributes come with codes. + The comments following the codes below indicate what type the value should + be a pointer to. */ +typedef enum STORE_attribs + { + STORE_ATTR_END= 0x00, + STORE_ATTR_FRIENDLYNAME= 0x01, /* C string */ + STORE_ATTR_KEYID= 0x02, /* 160 bit string (SHA1) */ + STORE_ATTR_ISSUERKEYID= 0x03, /* 160 bit string (SHA1) */ + STORE_ATTR_SUBJECTKEYID= 0x04, /* 160 bit string (SHA1) */ + STORE_ATTR_ISSUERSERIALHASH= 0x05, /* 160 bit string (SHA1) */ + STORE_ATTR_ISSUER= 0x06, /* X509_NAME * */ + STORE_ATTR_SERIAL= 0x07, /* BIGNUM * */ + STORE_ATTR_SUBJECT= 0x08, /* X509_NAME * */ + STORE_ATTR_CERTHASH= 0x09, /* 160 bit string (SHA1) */ + STORE_ATTR_EMAIL= 0x0a, /* C string */ + STORE_ATTR_FILENAME= 0x0b, /* C string */ + STORE_ATTR_TYPE_NUM= 0x0b, /* The amount of known + attribute types */ + STORE_ATTR_OR= 0xff /* This is a special + separator, which + expresses the OR + operation. */ + } STORE_ATTR_TYPES; +/* Attribute value sizes. -1 means unknown, anything else is the required size. */ +extern const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1]; + +typedef enum STORE_certificate_status + { + STORE_X509_VALID= 0x00, + STORE_X509_EXPIRED= 0x01, + STORE_X509_SUSPENDED= 0x02, + STORE_X509_REVOKED= 0x03 + } STORE_CERTIFICATE_STATUS; + +/* Engine store functions will return a structure that contains all the necessary + * information, including revokation status for certificates. This is really not + * needed for application authors, as the ENGINE framework functions will extract + * the OpenSSL-specific information when at all possible. However, for engine + * authors, it's crucial to know this structure. */ +typedef struct STORE_OBJECT_st + { + STORE_OBJECT_TYPES type; + union + { + struct + { + STORE_CERTIFICATE_STATUS status; + X509 *certificate; + } x509; + X509_CRL *crl; + EVP_PKEY *key; + BIGNUM *number; + BUF_MEM *arbitrary; + } data; + } STORE_OBJECT; +DECLARE_STACK_OF(STORE_OBJECT) +STORE_OBJECT *STORE_OBJECT_new(void); +void STORE_OBJECT_free(STORE_OBJECT *data); + + + +/* The following functions handle the storage. They return 0, a negative number + or NULL on error, anything else on success. */ +X509 *STORE_get_certificate(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_store_certificate(STORE *e, X509 *data, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_modify_certificate(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +int STORE_revoke_certificate(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_delete_certificate(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +void *STORE_list_certificate_start(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +X509 *STORE_list_certificate_next(STORE *e, void *handle); +int STORE_list_certificate_end(STORE *e, void *handle); +int STORE_list_certificate_endp(STORE *e, void *handle); +EVP_PKEY *STORE_generate_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +EVP_PKEY *STORE_get_private_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_store_private_key(STORE *e, EVP_PKEY *data, + OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +int STORE_modify_private_key(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +int STORE_revoke_private_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_delete_private_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +void *STORE_list_private_key_start(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +EVP_PKEY *STORE_list_private_key_next(STORE *e, void *handle); +int STORE_list_private_key_end(STORE *e, void *handle); +int STORE_list_private_key_endp(STORE *e, void *handle); +EVP_PKEY *STORE_get_public_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_store_public_key(STORE *e, EVP_PKEY *data, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_modify_public_key(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +int STORE_revoke_public_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_delete_public_key(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +void *STORE_list_public_key_start(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +EVP_PKEY *STORE_list_public_key_next(STORE *e, void *handle); +int STORE_list_public_key_end(STORE *e, void *handle); +int STORE_list_public_key_endp(STORE *e, void *handle); +X509_CRL *STORE_generate_crl(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +X509_CRL *STORE_get_crl(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_store_crl(STORE *e, X509_CRL *data, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_modify_crl(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +int STORE_delete_crl(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +void *STORE_list_crl_start(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +X509_CRL *STORE_list_crl_next(STORE *e, void *handle); +int STORE_list_crl_end(STORE *e, void *handle); +int STORE_list_crl_endp(STORE *e, void *handle); +int STORE_store_number(STORE *e, BIGNUM *data, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_modify_number(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +BIGNUM *STORE_get_number(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_delete_number(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_store_arbitrary(STORE *e, BUF_MEM *data, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_modify_arbitrary(STORE *e, OPENSSL_ITEM search_attributes[], + OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], + OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +BUF_MEM *STORE_get_arbitrary(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); +int STORE_delete_arbitrary(STORE *e, OPENSSL_ITEM attributes[], + OPENSSL_ITEM parameters[]); + + +/* Create and manipulate methods */ +STORE_METHOD *STORE_create_method(char *name); +void STORE_destroy_method(STORE_METHOD *store_method); + +/* These callback types are use for store handlers */ +typedef int (*STORE_INITIALISE_FUNC_PTR)(STORE *); +typedef void (*STORE_CLEANUP_FUNC_PTR)(STORE *); +typedef STORE_OBJECT *(*STORE_GENERATE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef STORE_OBJECT *(*STORE_GET_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef void *(*STORE_START_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef STORE_OBJECT *(*STORE_NEXT_OBJECT_FUNC_PTR)(STORE *, void *handle); +typedef int (*STORE_END_OBJECT_FUNC_PTR)(STORE *, void *handle); +typedef int (*STORE_HANDLE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef int (*STORE_STORE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, STORE_OBJECT *data, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef int (*STORE_MODIFY_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); +typedef int (*STORE_GENERIC_FUNC_PTR)(STORE *, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); +typedef int (*STORE_CTRL_FUNC_PTR)(STORE *, int cmd, long l, void *p, void (*f)(void)); + +int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f); +int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f); +int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f); +int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f); +int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f); +int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR store_f); +int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f); +int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f); +int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f); +int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f); +int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f); +int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); +int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); +int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); +int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f); + +STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm); +STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm); +STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm); +STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm); +STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm); +STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm); +STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm); +STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm); +STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm); +STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm); +STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm); +STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm); +STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm); +STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm); +STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm); + +/* Method helper structures and functions. */ + +/* This structure is the result of parsing through the information in a list + of OPENSSL_ITEMs. It stores all the necessary information in a structured + way.*/ +typedef struct STORE_attr_info_st STORE_ATTR_INFO; + +/* Parse a list of OPENSSL_ITEMs and return a pointer to a STORE_ATTR_INFO. + Note that we do this in the list form, since the list of OPENSSL_ITEMs can + come in blocks separated with STORE_ATTR_OR. Note that the value returned + by STORE_parse_attrs_next() must be freed with STORE_ATTR_INFO_free(). */ +void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes); +STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle); +int STORE_parse_attrs_end(void *handle); +int STORE_parse_attrs_endp(void *handle); + +/* Creator and destructor */ +STORE_ATTR_INFO *STORE_ATTR_INFO_new(void); +int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs); + +/* Manipulators */ +char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); +unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs, + STORE_ATTR_TYPES code); +X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); +BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); +int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + char *cstr, size_t cstr_size); +int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + unsigned char *sha1str, size_t sha1str_size); +int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + X509_NAME *dn); +int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + BIGNUM *number); +int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + char *cstr, size_t cstr_size); +int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + unsigned char *sha1str, size_t sha1str_size); +int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + X509_NAME *dn); +int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, + BIGNUM *number); + +/* Compare on basis of a bit pattern formed by the STORE_ATTR_TYPES values + in each contained attribute. */ +int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); +/* Check if the set of attributes in a is within the range of attributes + set in b. */ +int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); +/* Check if the set of attributes in a are also set in b. */ +int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); +/* Same as STORE_ATTR_INFO_in(), but also checks the attribute values. */ +int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_STORE_strings(void); + +/* Error codes for the STORE functions. */ + +/* Function codes. */ +#define STORE_F_MEM_DELETE 134 +#define STORE_F_MEM_GENERATE 135 +#define STORE_F_MEM_LIST_END 168 +#define STORE_F_MEM_LIST_NEXT 136 +#define STORE_F_MEM_LIST_START 137 +#define STORE_F_MEM_MODIFY 169 +#define STORE_F_MEM_STORE 138 +#define STORE_F_STORE_ATTR_INFO_GET0_CSTR 139 +#define STORE_F_STORE_ATTR_INFO_GET0_DN 140 +#define STORE_F_STORE_ATTR_INFO_GET0_NUMBER 141 +#define STORE_F_STORE_ATTR_INFO_GET0_SHA1STR 142 +#define STORE_F_STORE_ATTR_INFO_MODIFY_CSTR 143 +#define STORE_F_STORE_ATTR_INFO_MODIFY_DN 144 +#define STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER 145 +#define STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR 146 +#define STORE_F_STORE_ATTR_INFO_SET_CSTR 147 +#define STORE_F_STORE_ATTR_INFO_SET_DN 148 +#define STORE_F_STORE_ATTR_INFO_SET_NUMBER 149 +#define STORE_F_STORE_ATTR_INFO_SET_SHA1STR 150 +#define STORE_F_STORE_CERTIFICATE 170 +#define STORE_F_STORE_CTRL 161 +#define STORE_F_STORE_DELETE_ARBITRARY 158 +#define STORE_F_STORE_DELETE_CERTIFICATE 102 +#define STORE_F_STORE_DELETE_CRL 103 +#define STORE_F_STORE_DELETE_NUMBER 104 +#define STORE_F_STORE_DELETE_PRIVATE_KEY 105 +#define STORE_F_STORE_DELETE_PUBLIC_KEY 106 +#define STORE_F_STORE_GENERATE_CRL 107 +#define STORE_F_STORE_GENERATE_KEY 108 +#define STORE_F_STORE_GET_ARBITRARY 159 +#define STORE_F_STORE_GET_CERTIFICATE 109 +#define STORE_F_STORE_GET_CRL 110 +#define STORE_F_STORE_GET_NUMBER 111 +#define STORE_F_STORE_GET_PRIVATE_KEY 112 +#define STORE_F_STORE_GET_PUBLIC_KEY 113 +#define STORE_F_STORE_LIST_CERTIFICATE_END 114 +#define STORE_F_STORE_LIST_CERTIFICATE_ENDP 153 +#define STORE_F_STORE_LIST_CERTIFICATE_NEXT 115 +#define STORE_F_STORE_LIST_CERTIFICATE_START 116 +#define STORE_F_STORE_LIST_CRL_END 117 +#define STORE_F_STORE_LIST_CRL_ENDP 154 +#define STORE_F_STORE_LIST_CRL_NEXT 118 +#define STORE_F_STORE_LIST_CRL_START 119 +#define STORE_F_STORE_LIST_PRIVATE_KEY_END 120 +#define STORE_F_STORE_LIST_PRIVATE_KEY_ENDP 155 +#define STORE_F_STORE_LIST_PRIVATE_KEY_NEXT 121 +#define STORE_F_STORE_LIST_PRIVATE_KEY_START 122 +#define STORE_F_STORE_LIST_PUBLIC_KEY_END 123 +#define STORE_F_STORE_LIST_PUBLIC_KEY_ENDP 156 +#define STORE_F_STORE_LIST_PUBLIC_KEY_NEXT 124 +#define STORE_F_STORE_LIST_PUBLIC_KEY_START 125 +#define STORE_F_STORE_MODIFY_ARBITRARY 162 +#define STORE_F_STORE_MODIFY_CERTIFICATE 163 +#define STORE_F_STORE_MODIFY_CRL 164 +#define STORE_F_STORE_MODIFY_NUMBER 165 +#define STORE_F_STORE_MODIFY_PRIVATE_KEY 166 +#define STORE_F_STORE_MODIFY_PUBLIC_KEY 167 +#define STORE_F_STORE_NEW_ENGINE 133 +#define STORE_F_STORE_NEW_METHOD 132 +#define STORE_F_STORE_PARSE_ATTRS_END 151 +#define STORE_F_STORE_PARSE_ATTRS_ENDP 172 +#define STORE_F_STORE_PARSE_ATTRS_NEXT 152 +#define STORE_F_STORE_PARSE_ATTRS_START 171 +#define STORE_F_STORE_REVOKE_CERTIFICATE 129 +#define STORE_F_STORE_REVOKE_PRIVATE_KEY 130 +#define STORE_F_STORE_REVOKE_PUBLIC_KEY 131 +#define STORE_F_STORE_STORE_ARBITRARY 157 +#define STORE_F_STORE_STORE_CERTIFICATE 100 +#define STORE_F_STORE_STORE_CRL 101 +#define STORE_F_STORE_STORE_NUMBER 126 +#define STORE_F_STORE_STORE_PRIVATE_KEY 127 +#define STORE_F_STORE_STORE_PUBLIC_KEY 128 + +/* Reason codes. */ +#define STORE_R_ALREADY_HAS_A_VALUE 127 +#define STORE_R_FAILED_DELETING_ARBITRARY 132 +#define STORE_R_FAILED_DELETING_CERTIFICATE 100 +#define STORE_R_FAILED_DELETING_KEY 101 +#define STORE_R_FAILED_DELETING_NUMBER 102 +#define STORE_R_FAILED_GENERATING_CRL 103 +#define STORE_R_FAILED_GENERATING_KEY 104 +#define STORE_R_FAILED_GETTING_ARBITRARY 133 +#define STORE_R_FAILED_GETTING_CERTIFICATE 105 +#define STORE_R_FAILED_GETTING_KEY 106 +#define STORE_R_FAILED_GETTING_NUMBER 107 +#define STORE_R_FAILED_LISTING_CERTIFICATES 108 +#define STORE_R_FAILED_LISTING_KEYS 109 +#define STORE_R_FAILED_MODIFYING_ARBITRARY 138 +#define STORE_R_FAILED_MODIFYING_CERTIFICATE 139 +#define STORE_R_FAILED_MODIFYING_CRL 140 +#define STORE_R_FAILED_MODIFYING_NUMBER 141 +#define STORE_R_FAILED_MODIFYING_PRIVATE_KEY 142 +#define STORE_R_FAILED_MODIFYING_PUBLIC_KEY 143 +#define STORE_R_FAILED_REVOKING_CERTIFICATE 110 +#define STORE_R_FAILED_REVOKING_KEY 111 +#define STORE_R_FAILED_STORING_ARBITRARY 134 +#define STORE_R_FAILED_STORING_CERTIFICATE 112 +#define STORE_R_FAILED_STORING_KEY 113 +#define STORE_R_FAILED_STORING_NUMBER 114 +#define STORE_R_NOT_IMPLEMENTED 128 +#define STORE_R_NO_CONTROL_FUNCTION 144 +#define STORE_R_NO_DELETE_ARBITRARY_FUNCTION 135 +#define STORE_R_NO_DELETE_NUMBER_FUNCTION 115 +#define STORE_R_NO_DELETE_OBJECT_FUNCTION 116 +#define STORE_R_NO_GENERATE_CRL_FUNCTION 117 +#define STORE_R_NO_GENERATE_OBJECT_FUNCTION 118 +#define STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION 136 +#define STORE_R_NO_GET_OBJECT_FUNCTION 119 +#define STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION 120 +#define STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION 131 +#define STORE_R_NO_LIST_OBJECT_END_FUNCTION 121 +#define STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION 122 +#define STORE_R_NO_LIST_OBJECT_START_FUNCTION 123 +#define STORE_R_NO_MODIFY_OBJECT_FUNCTION 145 +#define STORE_R_NO_REVOKE_OBJECT_FUNCTION 124 +#define STORE_R_NO_STORE 129 +#define STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION 137 +#define STORE_R_NO_STORE_OBJECT_FUNCTION 125 +#define STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION 126 +#define STORE_R_NO_VALUE 130 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/symhacks.h b/石器时代8.5客户端最新源代码/石器源码/openssl/symhacks.h new file mode 100644 index 0000000..8728e61 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/symhacks.h @@ -0,0 +1,409 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_SYMHACKS_H +#define HEADER_SYMHACKS_H + +#include + +/* Hacks to solve the problem with linkers incapable of handling very long + symbol names. In the case of VMS, the limit is 31 characters on VMS for + VAX. */ +#ifdef OPENSSL_SYS_VMS + +/* Hack a long name in crypto/cryptlib.c */ +#undef int_CRYPTO_set_do_dynlock_callback +#define int_CRYPTO_set_do_dynlock_callback int_CRYPTO_set_do_dynlock_cb + +/* Hack a long name in crypto/ex_data.c */ +#undef CRYPTO_get_ex_data_implementation +#define CRYPTO_get_ex_data_implementation CRYPTO_get_ex_data_impl +#undef CRYPTO_set_ex_data_implementation +#define CRYPTO_set_ex_data_implementation CRYPTO_set_ex_data_impl + +/* Hack a long name in crypto/asn1/a_mbstr.c */ +#undef ASN1_STRING_set_default_mask_asc +#define ASN1_STRING_set_default_mask_asc ASN1_STRING_set_def_mask_asc + +#if 0 /* No longer needed, since safestack macro magic does the job */ +/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */ +#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO +#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF +#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO +#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF +#endif + +#if 0 /* No longer needed, since safestack macro magic does the job */ +/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */ +#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO +#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECINF +#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO +#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECINF +#endif + +#if 0 /* No longer needed, since safestack macro magic does the job */ +/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */ +#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION +#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION i2d_ASN1_SET_OF_ACC_DESC +#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION +#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION d2i_ASN1_SET_OF_ACC_DESC +#endif + +/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */ +#undef PEM_read_NETSCAPE_CERT_SEQUENCE +#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQ +#undef PEM_write_NETSCAPE_CERT_SEQUENCE +#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQ +#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE +#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQ +#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE +#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQ +#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE +#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQ + +/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */ +#undef PEM_read_PKCS8_PRIV_KEY_INFO +#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO +#undef PEM_write_PKCS8_PRIV_KEY_INFO +#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO +#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO +#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO +#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO +#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO +#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO +#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_wrt_cb_bio_P8_PRIV_KEY_INFO + +/* Hack other PEM names */ +#undef PEM_write_bio_PKCS8PrivateKey_nid +#define PEM_write_bio_PKCS8PrivateKey_nid PEM_write_bio_PKCS8PrivKey_nid + +/* Hack some long X509 names */ +#undef X509_REVOKED_get_ext_by_critical +#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic +#undef X509_policy_tree_get0_user_policies +#define X509_policy_tree_get0_user_policies X509_pcy_tree_get0_usr_policies +#undef X509_policy_node_get0_qualifiers +#define X509_policy_node_get0_qualifiers X509_pcy_node_get0_qualifiers +#undef X509_STORE_CTX_get_explicit_policy +#define X509_STORE_CTX_get_explicit_policy X509_STORE_CTX_get_expl_policy + +/* Hack some long CRYPTO names */ +#undef CRYPTO_set_dynlock_destroy_callback +#define CRYPTO_set_dynlock_destroy_callback CRYPTO_set_dynlock_destroy_cb +#undef CRYPTO_set_dynlock_create_callback +#define CRYPTO_set_dynlock_create_callback CRYPTO_set_dynlock_create_cb +#undef CRYPTO_set_dynlock_lock_callback +#define CRYPTO_set_dynlock_lock_callback CRYPTO_set_dynlock_lock_cb +#undef CRYPTO_get_dynlock_lock_callback +#define CRYPTO_get_dynlock_lock_callback CRYPTO_get_dynlock_lock_cb +#undef CRYPTO_get_dynlock_destroy_callback +#define CRYPTO_get_dynlock_destroy_callback CRYPTO_get_dynlock_destroy_cb +#undef CRYPTO_get_dynlock_create_callback +#define CRYPTO_get_dynlock_create_callback CRYPTO_get_dynlock_create_cb +#undef CRYPTO_set_locked_mem_ex_functions +#define CRYPTO_set_locked_mem_ex_functions CRYPTO_set_locked_mem_ex_funcs +#undef CRYPTO_get_locked_mem_ex_functions +#define CRYPTO_get_locked_mem_ex_functions CRYPTO_get_locked_mem_ex_funcs + +/* Hack some long SSL names */ +#undef SSL_CTX_set_default_verify_paths +#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths +#undef SSL_get_ex_data_X509_STORE_CTX_idx +#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_d_X509_STORE_CTX_idx +#undef SSL_add_file_cert_subjects_to_stack +#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_subjs_to_stk +#undef SSL_add_dir_cert_subjects_to_stack +#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_subjs_to_stk +#undef SSL_CTX_use_certificate_chain_file +#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file +#undef SSL_CTX_set_cert_verify_callback +#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb +#undef SSL_CTX_set_default_passwd_cb_userdata +#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud +#undef SSL_COMP_get_compression_methods +#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods + +/* Hack some long ENGINE names */ +#undef ENGINE_get_default_BN_mod_exp_crt +#define ENGINE_get_default_BN_mod_exp_crt ENGINE_get_def_BN_mod_exp_crt +#undef ENGINE_set_default_BN_mod_exp_crt +#define ENGINE_set_default_BN_mod_exp_crt ENGINE_set_def_BN_mod_exp_crt +#undef ENGINE_set_load_privkey_function +#define ENGINE_set_load_privkey_function ENGINE_set_load_privkey_fn +#undef ENGINE_get_load_privkey_function +#define ENGINE_get_load_privkey_function ENGINE_get_load_privkey_fn +#undef ENGINE_set_load_ssl_client_cert_function +#define ENGINE_set_load_ssl_client_cert_function \ + ENGINE_set_ld_ssl_clnt_cert_fn +#undef ENGINE_get_ssl_client_cert_function +#define ENGINE_get_ssl_client_cert_function ENGINE_get_ssl_client_cert_fn + +/* Hack some long OCSP names */ +#undef OCSP_REQUEST_get_ext_by_critical +#define OCSP_REQUEST_get_ext_by_critical OCSP_REQUEST_get_ext_by_crit +#undef OCSP_BASICRESP_get_ext_by_critical +#define OCSP_BASICRESP_get_ext_by_critical OCSP_BASICRESP_get_ext_by_crit +#undef OCSP_SINGLERESP_get_ext_by_critical +#define OCSP_SINGLERESP_get_ext_by_critical OCSP_SINGLERESP_get_ext_by_crit + +/* Hack some long DES names */ +#undef _ossl_old_des_ede3_cfb64_encrypt +#define _ossl_old_des_ede3_cfb64_encrypt _ossl_odes_ede3_cfb64_encrypt +#undef _ossl_old_des_ede3_ofb64_encrypt +#define _ossl_old_des_ede3_ofb64_encrypt _ossl_odes_ede3_ofb64_encrypt + +/* Hack some long EVP names */ +#undef OPENSSL_add_all_algorithms_noconf +#define OPENSSL_add_all_algorithms_noconf OPENSSL_add_all_algo_noconf +#undef OPENSSL_add_all_algorithms_conf +#define OPENSSL_add_all_algorithms_conf OPENSSL_add_all_algo_conf + +/* Hack some long EC names */ +#undef EC_GROUP_set_point_conversion_form +#define EC_GROUP_set_point_conversion_form EC_GROUP_set_point_conv_form +#undef EC_GROUP_get_point_conversion_form +#define EC_GROUP_get_point_conversion_form EC_GROUP_get_point_conv_form +#undef EC_GROUP_clear_free_all_extra_data +#define EC_GROUP_clear_free_all_extra_data EC_GROUP_clr_free_all_xtra_data +#undef EC_POINT_set_Jprojective_coordinates_GFp +#define EC_POINT_set_Jprojective_coordinates_GFp \ + EC_POINT_set_Jproj_coords_GFp +#undef EC_POINT_get_Jprojective_coordinates_GFp +#define EC_POINT_get_Jprojective_coordinates_GFp \ + EC_POINT_get_Jproj_coords_GFp +#undef EC_POINT_set_affine_coordinates_GFp +#define EC_POINT_set_affine_coordinates_GFp EC_POINT_set_affine_coords_GFp +#undef EC_POINT_get_affine_coordinates_GFp +#define EC_POINT_get_affine_coordinates_GFp EC_POINT_get_affine_coords_GFp +#undef EC_POINT_set_compressed_coordinates_GFp +#define EC_POINT_set_compressed_coordinates_GFp EC_POINT_set_compr_coords_GFp +#undef EC_POINT_set_affine_coordinates_GF2m +#define EC_POINT_set_affine_coordinates_GF2m EC_POINT_set_affine_coords_GF2m +#undef EC_POINT_get_affine_coordinates_GF2m +#define EC_POINT_get_affine_coordinates_GF2m EC_POINT_get_affine_coords_GF2m +#undef EC_POINT_set_compressed_coordinates_GF2m +#define EC_POINT_set_compressed_coordinates_GF2m \ + EC_POINT_set_compr_coords_GF2m +#undef ec_GF2m_simple_group_clear_finish +#define ec_GF2m_simple_group_clear_finish ec_GF2m_simple_grp_clr_finish +#undef ec_GF2m_simple_group_check_discriminant +#define ec_GF2m_simple_group_check_discriminant ec_GF2m_simple_grp_chk_discrim +#undef ec_GF2m_simple_point_clear_finish +#define ec_GF2m_simple_point_clear_finish ec_GF2m_simple_pt_clr_finish +#undef ec_GF2m_simple_point_set_to_infinity +#define ec_GF2m_simple_point_set_to_infinity ec_GF2m_simple_pt_set_to_inf +#undef ec_GF2m_simple_points_make_affine +#define ec_GF2m_simple_points_make_affine ec_GF2m_simple_pts_make_affine +#undef ec_GF2m_simple_point_set_affine_coordinates +#define ec_GF2m_simple_point_set_affine_coordinates \ + ec_GF2m_smp_pt_set_af_coords +#undef ec_GF2m_simple_point_get_affine_coordinates +#define ec_GF2m_simple_point_get_affine_coordinates \ + ec_GF2m_smp_pt_get_af_coords +#undef ec_GF2m_simple_set_compressed_coordinates +#define ec_GF2m_simple_set_compressed_coordinates \ + ec_GF2m_smp_set_compr_coords +#undef ec_GFp_simple_group_set_curve_GFp +#define ec_GFp_simple_group_set_curve_GFp ec_GFp_simple_grp_set_curve_GFp +#undef ec_GFp_simple_group_get_curve_GFp +#define ec_GFp_simple_group_get_curve_GFp ec_GFp_simple_grp_get_curve_GFp +#undef ec_GFp_simple_group_clear_finish +#define ec_GFp_simple_group_clear_finish ec_GFp_simple_grp_clear_finish +#undef ec_GFp_simple_group_set_generator +#define ec_GFp_simple_group_set_generator ec_GFp_simple_grp_set_generator +#undef ec_GFp_simple_group_get0_generator +#define ec_GFp_simple_group_get0_generator ec_GFp_simple_grp_gt0_generator +#undef ec_GFp_simple_group_get_cofactor +#define ec_GFp_simple_group_get_cofactor ec_GFp_simple_grp_get_cofactor +#undef ec_GFp_simple_point_clear_finish +#define ec_GFp_simple_point_clear_finish ec_GFp_simple_pt_clear_finish +#undef ec_GFp_simple_point_set_to_infinity +#define ec_GFp_simple_point_set_to_infinity ec_GFp_simple_pt_set_to_inf +#undef ec_GFp_simple_points_make_affine +#define ec_GFp_simple_points_make_affine ec_GFp_simple_pts_make_affine +#undef ec_GFp_simple_group_get_curve_GFp +#define ec_GFp_simple_group_get_curve_GFp ec_GFp_simple_grp_get_curve_GFp +#undef ec_GFp_simple_set_Jprojective_coordinates_GFp +#define ec_GFp_simple_set_Jprojective_coordinates_GFp \ + ec_GFp_smp_set_Jproj_coords_GFp +#undef ec_GFp_simple_get_Jprojective_coordinates_GFp +#define ec_GFp_simple_get_Jprojective_coordinates_GFp \ + ec_GFp_smp_get_Jproj_coords_GFp +#undef ec_GFp_simple_point_set_affine_coordinates_GFp +#define ec_GFp_simple_point_set_affine_coordinates_GFp \ + ec_GFp_smp_pt_set_af_coords_GFp +#undef ec_GFp_simple_point_get_affine_coordinates_GFp +#define ec_GFp_simple_point_get_affine_coordinates_GFp \ + ec_GFp_smp_pt_get_af_coords_GFp +#undef ec_GFp_simple_set_compressed_coordinates_GFp +#define ec_GFp_simple_set_compressed_coordinates_GFp \ + ec_GFp_smp_set_compr_coords_GFp +#undef ec_GFp_simple_point_set_affine_coordinates +#define ec_GFp_simple_point_set_affine_coordinates \ + ec_GFp_smp_pt_set_af_coords +#undef ec_GFp_simple_point_get_affine_coordinates +#define ec_GFp_simple_point_get_affine_coordinates \ + ec_GFp_smp_pt_get_af_coords +#undef ec_GFp_simple_set_compressed_coordinates +#define ec_GFp_simple_set_compressed_coordinates \ + ec_GFp_smp_set_compr_coords +#undef ec_GFp_simple_group_check_discriminant +#define ec_GFp_simple_group_check_discriminant ec_GFp_simple_grp_chk_discrim + +/* Hack som long STORE names */ +#undef STORE_method_set_initialise_function +#define STORE_method_set_initialise_function STORE_meth_set_initialise_fn +#undef STORE_method_set_cleanup_function +#define STORE_method_set_cleanup_function STORE_meth_set_cleanup_fn +#undef STORE_method_set_generate_function +#define STORE_method_set_generate_function STORE_meth_set_generate_fn +#undef STORE_method_set_modify_function +#define STORE_method_set_modify_function STORE_meth_set_modify_fn +#undef STORE_method_set_revoke_function +#define STORE_method_set_revoke_function STORE_meth_set_revoke_fn +#undef STORE_method_set_delete_function +#define STORE_method_set_delete_function STORE_meth_set_delete_fn +#undef STORE_method_set_list_start_function +#define STORE_method_set_list_start_function STORE_meth_set_list_start_fn +#undef STORE_method_set_list_next_function +#define STORE_method_set_list_next_function STORE_meth_set_list_next_fn +#undef STORE_method_set_list_end_function +#define STORE_method_set_list_end_function STORE_meth_set_list_end_fn +#undef STORE_method_set_update_store_function +#define STORE_method_set_update_store_function STORE_meth_set_update_store_fn +#undef STORE_method_set_lock_store_function +#define STORE_method_set_lock_store_function STORE_meth_set_lock_store_fn +#undef STORE_method_set_unlock_store_function +#define STORE_method_set_unlock_store_function STORE_meth_set_unlock_store_fn +#undef STORE_method_get_initialise_function +#define STORE_method_get_initialise_function STORE_meth_get_initialise_fn +#undef STORE_method_get_cleanup_function +#define STORE_method_get_cleanup_function STORE_meth_get_cleanup_fn +#undef STORE_method_get_generate_function +#define STORE_method_get_generate_function STORE_meth_get_generate_fn +#undef STORE_method_get_modify_function +#define STORE_method_get_modify_function STORE_meth_get_modify_fn +#undef STORE_method_get_revoke_function +#define STORE_method_get_revoke_function STORE_meth_get_revoke_fn +#undef STORE_method_get_delete_function +#define STORE_method_get_delete_function STORE_meth_get_delete_fn +#undef STORE_method_get_list_start_function +#define STORE_method_get_list_start_function STORE_meth_get_list_start_fn +#undef STORE_method_get_list_next_function +#define STORE_method_get_list_next_function STORE_meth_get_list_next_fn +#undef STORE_method_get_list_end_function +#define STORE_method_get_list_end_function STORE_meth_get_list_end_fn +#undef STORE_method_get_update_store_function +#define STORE_method_get_update_store_function STORE_meth_get_update_store_fn +#undef STORE_method_get_lock_store_function +#define STORE_method_get_lock_store_function STORE_meth_get_lock_store_fn +#undef STORE_method_get_unlock_store_function +#define STORE_method_get_unlock_store_function STORE_meth_get_unlock_store_fn + +/* Hack some long CMS names */ +#undef CMS_RecipientInfo_ktri_get0_algs +#define CMS_RecipientInfo_ktri_get0_algs CMS_RecipInfo_ktri_get0_algs +#undef CMS_RecipientInfo_ktri_get0_signer_id +#define CMS_RecipientInfo_ktri_get0_signer_id CMS_RecipInfo_ktri_get0_sigr_id +#undef CMS_OtherRevocationInfoFormat_it +#define CMS_OtherRevocationInfoFormat_it CMS_OtherRevocInfoFormat_it +#undef CMS_KeyAgreeRecipientIdentifier_it +#define CMS_KeyAgreeRecipientIdentifier_it CMS_KeyAgreeRecipIdentifier_it +#undef CMS_OriginatorIdentifierOrKey_it +#define CMS_OriginatorIdentifierOrKey_it CMS_OriginatorIdOrKey_it +#undef cms_SignerIdentifier_get0_signer_id +#define cms_SignerIdentifier_get0_signer_id cms_SignerId_get0_signer_id + +#endif /* defined OPENSSL_SYS_VMS */ + + +/* Case insensiteve linking causes problems.... */ +#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2) +#undef ERR_load_CRYPTO_strings +#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings +#undef OCSP_crlID_new +#define OCSP_crlID_new OCSP_crlID2_new + +#undef d2i_ECPARAMETERS +#define d2i_ECPARAMETERS d2i_UC_ECPARAMETERS +#undef i2d_ECPARAMETERS +#define i2d_ECPARAMETERS i2d_UC_ECPARAMETERS +#undef d2i_ECPKPARAMETERS +#define d2i_ECPKPARAMETERS d2i_UC_ECPKPARAMETERS +#undef i2d_ECPKPARAMETERS +#define i2d_ECPKPARAMETERS i2d_UC_ECPKPARAMETERS + +/* These functions do not seem to exist! However, I'm paranoid... + Original command in x509v3.h: + These functions are being redefined in another directory, + and clash when the linker is case-insensitive, so let's + hide them a little, by giving them an extra 'o' at the + beginning of the name... */ +#undef X509v3_cleanup_extensions +#define X509v3_cleanup_extensions oX509v3_cleanup_extensions +#undef X509v3_add_extension +#define X509v3_add_extension oX509v3_add_extension +#undef X509v3_add_netscape_extensions +#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions +#undef X509v3_add_standard_extensions +#define X509v3_add_standard_extensions oX509v3_add_standard_extensions + + +#endif + + +#endif /* ! defined HEADER_VMS_IDHACKS_H */ +/* This one clashes with CMS_data_create */ +#undef cms_Data_create +#define cms_Data_create priv_cms_Data_create diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/tls1.h b/石器时代8.5客户端最新源代码/石器源码/openssl/tls1.h new file mode 100644 index 0000000..2d1d293 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/tls1.h @@ -0,0 +1,407 @@ +/* ssl/tls1.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the OpenSSL open source + * license provided above. + * + * ECC cipher suite support in OpenSSL originally written by + * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. + * + */ + +#ifndef HEADER_TLS1_H +#define HEADER_TLS1_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 0 + +#define TLS1_VERSION 0x0301 +#define TLS1_VERSION_MAJOR 0x03 +#define TLS1_VERSION_MINOR 0x01 + +#define TLS1_AD_DECRYPTION_FAILED 21 +#define TLS1_AD_RECORD_OVERFLOW 22 +#define TLS1_AD_UNKNOWN_CA 48 /* fatal */ +#define TLS1_AD_ACCESS_DENIED 49 /* fatal */ +#define TLS1_AD_DECODE_ERROR 50 /* fatal */ +#define TLS1_AD_DECRYPT_ERROR 51 +#define TLS1_AD_EXPORT_RESTRICTION 60 /* fatal */ +#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */ +#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */ +#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ +#define TLS1_AD_USER_CANCELLED 90 +#define TLS1_AD_NO_RENEGOTIATION 100 +/* codes 110-114 are from RFC3546 */ +#define TLS1_AD_UNSUPPORTED_EXTENSION 110 +#define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111 +#define TLS1_AD_UNRECOGNIZED_NAME 112 +#define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113 +#define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114 +#define TLS1_AD_UNKNOWN_PSK_IDENTITY 115 /* fatal */ + +/* ExtensionType values from RFC 3546 */ +#define TLSEXT_TYPE_server_name 0 +#define TLSEXT_TYPE_max_fragment_length 1 +#define TLSEXT_TYPE_client_certificate_url 2 +#define TLSEXT_TYPE_trusted_ca_keys 3 +#define TLSEXT_TYPE_truncated_hmac 4 +#define TLSEXT_TYPE_status_request 5 +#define TLSEXT_TYPE_elliptic_curves 10 +#define TLSEXT_TYPE_ec_point_formats 11 +#define TLSEXT_TYPE_session_ticket 35 + +/* NameType value from RFC 3546 */ +#define TLSEXT_NAMETYPE_host_name 0 +/* status request value from RFC 3546 */ +#define TLSEXT_STATUSTYPE_ocsp 1 + +#ifndef OPENSSL_NO_TLSEXT + +#define TLSEXT_MAXLEN_host_name 255 + +const char *SSL_get_servername(const SSL *s, const int type) ; +int SSL_get_servername_type(const SSL *s) ; + +#define SSL_set_tlsext_host_name(s,name) \ +SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name) + +#define SSL_set_tlsext_debug_callback(ssl, cb) \ +SSL_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_CB,(void (*)(void))cb) + +#define SSL_set_tlsext_debug_arg(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_ARG,0, (void *)arg) + +#define SSL_set_tlsext_status_type(ssl, type) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type, NULL) + +#define SSL_get_tlsext_status_exts(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) + +#define SSL_set_tlsext_status_exts(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) + +#define SSL_get_tlsext_status_ids(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) + +#define SSL_set_tlsext_status_ids(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) + +#define SSL_get_tlsext_status_ocsp_resp(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,0, (void *)arg) + +#define SSL_set_tlsext_status_ocsp_resp(ssl, arg, arglen) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,arglen, (void *)arg) + +#define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ +SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,(void (*)(void))cb) + +#define SSL_TLSEXT_ERR_OK 0 +#define SSL_TLSEXT_ERR_ALERT_WARNING 1 +#define SSL_TLSEXT_ERR_ALERT_FATAL 2 +#define SSL_TLSEXT_ERR_NOACK 3 + +#define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ +SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG,0, (void *)arg) + +#define SSL_CTX_get_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_GET_TLXEXT_TICKET_KEYS,(keylen),(keys)) +#define SSL_CTX_set_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_SET_TLXEXT_TICKET_KEYS,(keylen),(keys)) + +#define SSL_CTX_set_tlsext_status_cb(ssl, cb) \ +SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb) + +#define SSL_CTX_set_tlsext_status_arg(ssl, arg) \ +SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0, (void *)arg) + +#define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \ +SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb) + +#endif + +/* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt + * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see + * s3_lib.c). We actually treat them like SSL 3.0 ciphers, which we probably + * shouldn't. */ +#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060 +#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061 +#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062 +#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063 +#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064 +#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065 +#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066 + +/* AES ciphersuites from RFC3268 */ + +#define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F +#define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030 +#define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031 +#define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032 +#define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033 +#define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034 + +#define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035 +#define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036 +#define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037 +#define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038 +#define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 +#define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A + +/* Camellia ciphersuites from RFC4132 */ +#define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000041 +#define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000042 +#define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000043 +#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000044 +#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000045 +#define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA 0x03000046 + +#define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000084 +#define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000085 +#define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000086 +#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000087 +#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000088 +#define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA 0x03000089 + +/* SEED ciphersuites from RFC4162 */ +#define TLS1_CK_RSA_WITH_SEED_SHA 0x03000096 +#define TLS1_CK_DH_DSS_WITH_SEED_SHA 0x03000097 +#define TLS1_CK_DH_RSA_WITH_SEED_SHA 0x03000098 +#define TLS1_CK_DHE_DSS_WITH_SEED_SHA 0x03000099 +#define TLS1_CK_DHE_RSA_WITH_SEED_SHA 0x0300009A +#define TLS1_CK_ADH_WITH_SEED_SHA 0x0300009B + +/* ECC ciphersuites from draft-ietf-tls-ecc-12.txt with changes soon to be in draft 13 */ +#define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA 0x0300C001 +#define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA 0x0300C002 +#define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C003 +#define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0x0300C004 +#define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0x0300C005 + +#define TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA 0x0300C006 +#define TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA 0x0300C007 +#define TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C008 +#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0x0300C009 +#define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0x0300C00A + +#define TLS1_CK_ECDH_RSA_WITH_NULL_SHA 0x0300C00B +#define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA 0x0300C00C +#define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA 0x0300C00D +#define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA 0x0300C00E +#define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA 0x0300C00F + +#define TLS1_CK_ECDHE_RSA_WITH_NULL_SHA 0x0300C010 +#define TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA 0x0300C011 +#define TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA 0x0300C012 +#define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA 0x0300C013 +#define TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA 0x0300C014 + +#define TLS1_CK_ECDH_anon_WITH_NULL_SHA 0x0300C015 +#define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA 0x0300C016 +#define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA 0x0300C017 +#define TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA 0x0300C018 +#define TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA 0x0300C019 + +/* XXX + * Inconsistency alert: + * The OpenSSL names of ciphers with ephemeral DH here include the string + * "DHE", while elsewhere it has always been "EDH". + * (The alias for the list of all such ciphers also is "EDH".) + * The specifications speak of "EDH"; maybe we should allow both forms + * for everything. */ +#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5" +#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5" +#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA" +#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA" +#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA" +#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA" +#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA" + +/* AES ciphersuites from RFC3268 */ +#define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA" +#define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA" +#define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA" +#define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA" +#define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA" +#define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA" + +#define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA" +#define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA" +#define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA" +#define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA" +#define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" +#define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" + +/* ECC ciphersuites from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) */ +#define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA "ECDH-ECDSA-NULL-SHA" +#define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA" +#define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA "ECDH-ECDSA-DES-CBC3-SHA" +#define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA" +#define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA" + +#define TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA "ECDHE-ECDSA-NULL-SHA" +#define TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA" +#define TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "ECDHE-ECDSA-DES-CBC3-SHA" +#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA" +#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA" + +#define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA "ECDH-RSA-NULL-SHA" +#define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA" +#define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA "ECDH-RSA-DES-CBC3-SHA" +#define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA" +#define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA" + +#define TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA "ECDHE-RSA-NULL-SHA" +#define TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA" +#define TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA "ECDHE-RSA-DES-CBC3-SHA" +#define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA" +#define TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA" + +#define TLS1_TXT_ECDH_anon_WITH_NULL_SHA "AECDH-NULL-SHA" +#define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA "AECDH-RC4-SHA" +#define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA "AECDH-DES-CBC3-SHA" +#define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA "AECDH-AES128-SHA" +#define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA "AECDH-AES256-SHA" + +/* Camellia ciphersuites from RFC4132 */ +#define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA" +#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA "DH-DSS-CAMELLIA128-SHA" +#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA "DH-RSA-CAMELLIA128-SHA" +#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "DHE-DSS-CAMELLIA128-SHA" +#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA" +#define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA "ADH-CAMELLIA128-SHA" + +#define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA" +#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA "DH-DSS-CAMELLIA256-SHA" +#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA "DH-RSA-CAMELLIA256-SHA" +#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "DHE-DSS-CAMELLIA256-SHA" +#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA" +#define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA "ADH-CAMELLIA256-SHA" + +/* SEED ciphersuites from RFC4162 */ +#define TLS1_TXT_RSA_WITH_SEED_SHA "SEED-SHA" +#define TLS1_TXT_DH_DSS_WITH_SEED_SHA "DH-DSS-SEED-SHA" +#define TLS1_TXT_DH_RSA_WITH_SEED_SHA "DH-RSA-SEED-SHA" +#define TLS1_TXT_DHE_DSS_WITH_SEED_SHA "DHE-DSS-SEED-SHA" +#define TLS1_TXT_DHE_RSA_WITH_SEED_SHA "DHE-RSA-SEED-SHA" +#define TLS1_TXT_ADH_WITH_SEED_SHA "ADH-SEED-SHA" + +#define TLS_CT_RSA_SIGN 1 +#define TLS_CT_DSS_SIGN 2 +#define TLS_CT_RSA_FIXED_DH 3 +#define TLS_CT_DSS_FIXED_DH 4 +#define TLS_CT_ECDSA_SIGN 64 +#define TLS_CT_RSA_FIXED_ECDH 65 +#define TLS_CT_ECDSA_FIXED_ECDH 66 +#define TLS_CT_NUMBER 7 + +#define TLS1_FINISH_MAC_LENGTH 12 + +#define TLS_MD_MAX_CONST_SIZE 20 +#define TLS_MD_CLIENT_FINISH_CONST "client finished" +#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 +#define TLS_MD_SERVER_FINISH_CONST "server finished" +#define TLS_MD_SERVER_FINISH_CONST_SIZE 15 +#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" +#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 +#define TLS_MD_KEY_EXPANSION_CONST "key expansion" +#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 +#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" +#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 +#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" +#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 +#define TLS_MD_IV_BLOCK_CONST "IV block" +#define TLS_MD_IV_BLOCK_CONST_SIZE 8 +#define TLS_MD_MASTER_SECRET_CONST "master secret" +#define TLS_MD_MASTER_SECRET_CONST_SIZE 13 + +#ifdef CHARSET_EBCDIC +#undef TLS_MD_CLIENT_FINISH_CONST +#define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/ +#undef TLS_MD_SERVER_FINISH_CONST +#define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/ +#undef TLS_MD_SERVER_WRITE_KEY_CONST +#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/ +#undef TLS_MD_KEY_EXPANSION_CONST +#define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/ +#undef TLS_MD_CLIENT_WRITE_KEY_CONST +#define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*client write key*/ +#undef TLS_MD_SERVER_WRITE_KEY_CONST +#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/ +#undef TLS_MD_IV_BLOCK_CONST +#define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/ +#undef TLS_MD_MASTER_SECRET_CONST +#define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/ +#endif + +#ifdef __cplusplus +} +#endif +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/tmdiff.h b/石器时代8.5客户端最新源代码/石器源码/openssl/tmdiff.h new file mode 100644 index 0000000..af5c41c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/tmdiff.h @@ -0,0 +1,93 @@ +/* crypto/tmdiff.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* Header for dynamic hash table routines + * Author - Eric Young + */ +/* ... erm yeah, "dynamic hash tables" you say? + * + * And what would dynamic hash tables have to do with any of this code *now*? + * AFAICS, this code is only referenced by crypto/bn/exp.c which is an unused + * file that I doubt compiles any more. speed.c is the only thing that could + * use this (and it has nothing to do with hash tables), yet it instead has its + * own duplication of all this stuff and looks, if anything, more complete. See + * the corresponding note in apps/speed.c. + * The Bemused - Geoff + */ + +#ifndef HEADER_TMDIFF_H +#define HEADER_TMDIFF_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ms_tm MS_TM; + +MS_TM *ms_time_new(void ); +void ms_time_free(MS_TM *a); +void ms_time_get(MS_TM *a); +double ms_time_diff(MS_TM *start, MS_TM *end); +int ms_time_cmp(const MS_TM *ap, const MS_TM *bp); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/txt_db.h b/石器时代8.5客户端最新源代码/石器源码/openssl/txt_db.h new file mode 100644 index 0000000..307e1ba --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/txt_db.h @@ -0,0 +1,109 @@ +/* crypto/txt_db/txt_db.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_TXT_DB_H +#define HEADER_TXT_DB_H + +#include +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#include + +#define DB_ERROR_OK 0 +#define DB_ERROR_MALLOC 1 +#define DB_ERROR_INDEX_CLASH 2 +#define DB_ERROR_INDEX_OUT_OF_RANGE 3 +#define DB_ERROR_NO_INDEX 4 +#define DB_ERROR_INSERT_INDEX_CLASH 5 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct txt_db_st + { + int num_fields; + STACK /* char ** */ *data; + LHASH **index; + int (**qual)(char **); + long error; + long arg1; + long arg2; + char **arg_row; + } TXT_DB; + +#ifndef OPENSSL_NO_BIO +TXT_DB *TXT_DB_read(BIO *in, int num); +long TXT_DB_write(BIO *out, TXT_DB *db); +#else +TXT_DB *TXT_DB_read(char *in, int num); +long TXT_DB_write(char *out, TXT_DB *db); +#endif +int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(char **), + LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); +void TXT_DB_free(TXT_DB *db); +char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value); +int TXT_DB_insert(TXT_DB *db,char **value); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ui.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ui.h new file mode 100644 index 0000000..0182964 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ui.h @@ -0,0 +1,381 @@ +/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ +/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL + * project 2001. + */ +/* ==================================================================== + * Copyright (c) 2001 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_UI_H +#define HEADER_UI_H + +#ifndef OPENSSL_NO_DEPRECATED +#include +#endif +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Declared already in ossl_typ.h */ +/* typedef struct ui_st UI; */ +/* typedef struct ui_method_st UI_METHOD; */ + + +/* All the following functions return -1 or NULL on error and in some cases + (UI_process()) -2 if interrupted or in some other way cancelled. + When everything is fine, they return 0, a positive value or a non-NULL + pointer, all depending on their purpose. */ + +/* Creators and destructor. */ +UI *UI_new(void); +UI *UI_new_method(const UI_METHOD *method); +void UI_free(UI *ui); + +/* The following functions are used to add strings to be printed and prompt + strings to prompt for data. The names are UI_{add,dup}__string + and UI_{add,dup}_input_boolean. + + UI_{add,dup}__string have the following meanings: + add add a text or prompt string. The pointers given to these + functions are used verbatim, no copying is done. + dup make a copy of the text or prompt string, then add the copy + to the collection of strings in the user interface. + + The function is a name for the functionality that the given + string shall be used for. It can be one of: + input use the string as data prompt. + verify use the string as verification prompt. This + is used to verify a previous input. + info use the string for informational output. + error use the string for error output. + Honestly, there's currently no difference between info and error for the + moment. + + UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", + and are typically used when one wants to prompt for a yes/no response. + + + All of the functions in this group take a UI and a prompt string. + The string input and verify addition functions also take a flag argument, + a buffer for the result to end up with, a minimum input size and a maximum + input size (the result buffer MUST be large enough to be able to contain + the maximum number of characters). Additionally, the verify addition + functions takes another buffer to compare the result against. + The boolean input functions take an action description string (which should + be safe to ignore if the expected user action is obvious, for example with + a dialog box with an OK button and a Cancel button), a string of acceptable + characters to mean OK and to mean Cancel. The two last strings are checked + to make sure they don't have common characters. Additionally, the same + flag argument as for the string input is taken, as well as a result buffer. + The result buffer is required to be at least one byte long. Depending on + the answer, the first character from the OK or the Cancel character strings + will be stored in the first byte of the result buffer. No NUL will be + added, so the result is *not* a string. + + On success, the all return an index of the added information. That index + is usefull when retrieving results with UI_get0_result(). */ +int UI_add_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_dup_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_add_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, const char *test_buf); +int UI_dup_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, const char *test_buf); +int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_add_info_string(UI *ui, const char *text); +int UI_dup_info_string(UI *ui, const char *text); +int UI_add_error_string(UI *ui, const char *text); +int UI_dup_error_string(UI *ui, const char *text); + +/* These are the possible flags. They can be or'ed together. */ +/* Use to have echoing of input */ +#define UI_INPUT_FLAG_ECHO 0x01 +/* Use a default password. Where that password is found is completely + up to the application, it might for example be in the user data set + with UI_add_user_data(). It is not recommended to have more than + one input in each UI being marked with this flag, or the application + might get confused. */ +#define UI_INPUT_FLAG_DEFAULT_PWD 0x02 + +/* The user of these routines may want to define flags of their own. The core + UI won't look at those, but will pass them on to the method routines. They + must use higher bits so they don't get confused with the UI bits above. + UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good + example of use is this: + + #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) + +*/ +#define UI_INPUT_FLAG_USER_BASE 16 + + +/* The following function helps construct a prompt. object_desc is a + textual short description of the object, for example "pass phrase", + and object_name is the name of the object (might be a card name or + a file name. + The returned string shall always be allocated on the heap with + OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). + + If the ui_method doesn't contain a pointer to a user-defined prompt + constructor, a default string is built, looking like this: + + "Enter {object_desc} for {object_name}:" + + So, if object_desc has the value "pass phrase" and object_name has + the value "foo.key", the resulting string is: + + "Enter pass phrase for foo.key:" +*/ +char *UI_construct_prompt(UI *ui_method, + const char *object_desc, const char *object_name); + + +/* The following function is used to store a pointer to user-specific data. + Any previous such pointer will be returned and replaced. + + For callback purposes, this function makes a lot more sense than using + ex_data, since the latter requires that different parts of OpenSSL or + applications share the same ex_data index. + + Note that the UI_OpenSSL() method completely ignores the user data. + Other methods may not, however. */ +void *UI_add_user_data(UI *ui, void *user_data); +/* We need a user data retrieving function as well. */ +void *UI_get0_user_data(UI *ui); + +/* Return the result associated with a prompt given with the index i. */ +const char *UI_get0_result(UI *ui, int i); + +/* When all strings have been added, process the whole thing. */ +int UI_process(UI *ui); + +/* Give a user interface parametrised control commands. This can be used to + send down an integer, a data pointer or a function pointer, as well as + be used to get information from a UI. */ +int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); + +/* The commands */ +/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the + OpenSSL error stack before printing any info or added error messages and + before any prompting. */ +#define UI_CTRL_PRINT_ERRORS 1 +/* Check if a UI_process() is possible to do again with the same instance of + a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 + if not. */ +#define UI_CTRL_IS_REDOABLE 2 + + +/* Some methods may use extra data */ +#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) +#define UI_get_app_data(s) UI_get_ex_data(s,0) +int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int UI_set_ex_data(UI *r,int idx,void *arg); +void *UI_get_ex_data(UI *r, int idx); + +/* Use specific methods instead of the built-in one */ +void UI_set_default_method(const UI_METHOD *meth); +const UI_METHOD *UI_get_default_method(void); +const UI_METHOD *UI_get_method(UI *ui); +const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); + +/* The method with all the built-in thingies */ +UI_METHOD *UI_OpenSSL(void); + + +/* ---------- For method writers ---------- */ +/* A method contains a number of functions that implement the low level + of the User Interface. The functions are: + + an opener This function starts a session, maybe by opening + a channel to a tty, or by opening a window. + a writer This function is called to write a given string, + maybe to the tty, maybe as a field label in a + window. + a flusher This function is called to flush everything that + has been output so far. It can be used to actually + display a dialog box after it has been built. + a reader This function is called to read a given prompt, + maybe from the tty, maybe from a field in a + window. Note that it's called wth all string + structures, not only the prompt ones, so it must + check such things itself. + a closer This function closes the session, maybe by closing + the channel to the tty, or closing the window. + + All these functions are expected to return: + + 0 on error. + 1 on success. + -1 on out-of-band events, for example if some prompting has + been canceled (by pressing Ctrl-C, for example). This is + only checked when returned by the flusher or the reader. + + The way this is used, the opener is first called, then the writer for all + strings, then the flusher, then the reader for all strings and finally the + closer. Note that if you want to prompt from a terminal or other command + line interface, the best is to have the reader also write the prompts + instead of having the writer do it. If you want to prompt from a dialog + box, the writer can be used to build up the contents of the box, and the + flusher to actually display the box and run the event loop until all data + has been given, after which the reader only grabs the given data and puts + them back into the UI strings. + + All method functions take a UI as argument. Additionally, the writer and + the reader take a UI_STRING. +*/ + +/* The UI_STRING type is the data structure that contains all the needed info + about a string or a prompt, including test data for a verification prompt. +*/ +DECLARE_STACK_OF(UI_STRING) +typedef struct ui_string_st UI_STRING; + +/* The different types of strings that are currently supported. + This is only needed by method authors. */ +enum UI_string_types + { + UIT_NONE=0, + UIT_PROMPT, /* Prompt for a string */ + UIT_VERIFY, /* Prompt for a string and verify */ + UIT_BOOLEAN, /* Prompt for a yes/no response */ + UIT_INFO, /* Send info to the user */ + UIT_ERROR /* Send an error message to the user */ + }; + +/* Create and manipulate methods */ +UI_METHOD *UI_create_method(char *name); +void UI_destroy_method(UI_METHOD *ui_method); +int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); +int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)); +int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)); +int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)); +int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); +int (*UI_method_get_opener(UI_METHOD *method))(UI*); +int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*); +int (*UI_method_get_flusher(UI_METHOD *method))(UI*); +int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*); +int (*UI_method_get_closer(UI_METHOD *method))(UI*); + +/* The following functions are helpers for method writers to access relevant + data from a UI_STRING. */ + +/* Return type of the UI_STRING */ +enum UI_string_types UI_get_string_type(UI_STRING *uis); +/* Return input flags of the UI_STRING */ +int UI_get_input_flags(UI_STRING *uis); +/* Return the actual string to output (the prompt, info or error) */ +const char *UI_get0_output_string(UI_STRING *uis); +/* Return the optional action string to output (the boolean promtp instruction) */ +const char *UI_get0_action_string(UI_STRING *uis); +/* Return the result of a prompt */ +const char *UI_get0_result_string(UI_STRING *uis); +/* Return the string to test the result against. Only useful with verifies. */ +const char *UI_get0_test_string(UI_STRING *uis); +/* Return the required minimum size of the result */ +int UI_get_result_minsize(UI_STRING *uis); +/* Return the required maximum size of the result */ +int UI_get_result_maxsize(UI_STRING *uis); +/* Set the result of a UI_STRING. */ +int UI_set_result(UI *ui, UI_STRING *uis, const char *result); + + +/* A couple of popular utility functions */ +int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify); +int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_UI_strings(void); + +/* Error codes for the UI functions. */ + +/* Function codes. */ +#define UI_F_GENERAL_ALLOCATE_BOOLEAN 108 +#define UI_F_GENERAL_ALLOCATE_PROMPT 109 +#define UI_F_GENERAL_ALLOCATE_STRING 100 +#define UI_F_UI_CTRL 111 +#define UI_F_UI_DUP_ERROR_STRING 101 +#define UI_F_UI_DUP_INFO_STRING 102 +#define UI_F_UI_DUP_INPUT_BOOLEAN 110 +#define UI_F_UI_DUP_INPUT_STRING 103 +#define UI_F_UI_DUP_VERIFY_STRING 106 +#define UI_F_UI_GET0_RESULT 107 +#define UI_F_UI_NEW_METHOD 104 +#define UI_F_UI_SET_RESULT 105 + +/* Reason codes. */ +#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104 +#define UI_R_INDEX_TOO_LARGE 102 +#define UI_R_INDEX_TOO_SMALL 103 +#define UI_R_NO_RESULT_BUFFER 105 +#define UI_R_RESULT_TOO_LARGE 100 +#define UI_R_RESULT_TOO_SMALL 101 +#define UI_R_UNKNOWN_CONTROL_COMMAND 106 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/ui_compat.h b/石器时代8.5客户端最新源代码/石器源码/openssl/ui_compat.h new file mode 100644 index 0000000..b35c9bb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/ui_compat.h @@ -0,0 +1,83 @@ +/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ +/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL + * project 2001. + */ +/* ==================================================================== + * Copyright (c) 2001 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_UI_COMPAT_H +#define HEADER_UI_COMPAT_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The following functions were previously part of the DES section, + and are provided here for backward compatibility reasons. */ + +#define des_read_pw_string(b,l,p,v) \ + _ossl_old_des_read_pw_string((b),(l),(p),(v)) +#define des_read_pw(b,bf,s,p,v) \ + _ossl_old_des_read_pw((b),(bf),(s),(p),(v)) + +int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify); +int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/x509.h b/石器时代8.5客户端最新源代码/石器源码/openssl/x509.h new file mode 100644 index 0000000..e71b525 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/x509.h @@ -0,0 +1,1355 @@ +/* crypto/x509/x509.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_X509_H +#define HEADER_X509_H + +#include +#include +#ifndef OPENSSL_NO_BUFFER +#include +#endif +#ifndef OPENSSL_NO_EVP +#include +#endif +#ifndef OPENSSL_NO_BIO +#include +#endif +#include +#include +#include + +#ifndef OPENSSL_NO_EC +#include +#endif + +#ifndef OPENSSL_NO_ECDSA +#include +#endif + +#ifndef OPENSSL_NO_ECDH +#include +#endif + +#ifndef OPENSSL_NO_DEPRECATED +#ifndef OPENSSL_NO_RSA +#include +#endif +#ifndef OPENSSL_NO_DSA +#include +#endif +#ifndef OPENSSL_NO_DH +#include +#endif +#endif + +#ifndef OPENSSL_NO_SHA +#include +#endif +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_SYS_WIN32 +/* Under Win32 these are defined in wincrypt.h */ +#undef X509_NAME +#undef X509_CERT_PAIR +#endif + +#define X509_FILETYPE_PEM 1 +#define X509_FILETYPE_ASN1 2 +#define X509_FILETYPE_DEFAULT 3 + +#define X509v3_KU_DIGITAL_SIGNATURE 0x0080 +#define X509v3_KU_NON_REPUDIATION 0x0040 +#define X509v3_KU_KEY_ENCIPHERMENT 0x0020 +#define X509v3_KU_DATA_ENCIPHERMENT 0x0010 +#define X509v3_KU_KEY_AGREEMENT 0x0008 +#define X509v3_KU_KEY_CERT_SIGN 0x0004 +#define X509v3_KU_CRL_SIGN 0x0002 +#define X509v3_KU_ENCIPHER_ONLY 0x0001 +#define X509v3_KU_DECIPHER_ONLY 0x8000 +#define X509v3_KU_UNDEF 0xffff + +typedef struct X509_objects_st + { + int nid; + int (*a2i)(void); + int (*i2a)(void); + } X509_OBJECTS; + +struct X509_algor_st + { + ASN1_OBJECT *algorithm; + ASN1_TYPE *parameter; + } /* X509_ALGOR */; + +DECLARE_ASN1_SET_OF(X509_ALGOR) + +typedef STACK_OF(X509_ALGOR) X509_ALGORS; + +typedef struct X509_val_st + { + ASN1_TIME *notBefore; + ASN1_TIME *notAfter; + } X509_VAL; + +typedef struct X509_pubkey_st + { + X509_ALGOR *algor; + ASN1_BIT_STRING *public_key; + EVP_PKEY *pkey; + } X509_PUBKEY; + +typedef struct X509_sig_st + { + X509_ALGOR *algor; + ASN1_OCTET_STRING *digest; + } X509_SIG; + +typedef struct X509_name_entry_st + { + ASN1_OBJECT *object; + ASN1_STRING *value; + int set; + int size; /* temp variable */ + } X509_NAME_ENTRY; + +DECLARE_STACK_OF(X509_NAME_ENTRY) +DECLARE_ASN1_SET_OF(X509_NAME_ENTRY) + +/* we always keep X509_NAMEs in 2 forms. */ +struct X509_name_st + { + STACK_OF(X509_NAME_ENTRY) *entries; + int modified; /* true if 'bytes' needs to be built */ +#ifndef OPENSSL_NO_BUFFER + BUF_MEM *bytes; +#else + char *bytes; +#endif + unsigned long hash; /* Keep the hash around for lookups */ + } /* X509_NAME */; + +DECLARE_STACK_OF(X509_NAME) + +#define X509_EX_V_NETSCAPE_HACK 0x8000 +#define X509_EX_V_INIT 0x0001 +typedef struct X509_extension_st + { + ASN1_OBJECT *object; + ASN1_BOOLEAN critical; + ASN1_OCTET_STRING *value; + } X509_EXTENSION; + +typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; + +DECLARE_STACK_OF(X509_EXTENSION) +DECLARE_ASN1_SET_OF(X509_EXTENSION) + +/* a sequence of these are used */ +typedef struct x509_attributes_st + { + ASN1_OBJECT *object; + int single; /* 0 for a set, 1 for a single item (which is wrong) */ + union { + char *ptr; +/* 0 */ STACK_OF(ASN1_TYPE) *set; +/* 1 */ ASN1_TYPE *single; + } value; + } X509_ATTRIBUTE; + +DECLARE_STACK_OF(X509_ATTRIBUTE) +DECLARE_ASN1_SET_OF(X509_ATTRIBUTE) + + +typedef struct X509_req_info_st + { + ASN1_ENCODING enc; + ASN1_INTEGER *version; + X509_NAME *subject; + X509_PUBKEY *pubkey; + /* d=2 hl=2 l= 0 cons: cont: 00 */ + STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ + } X509_REQ_INFO; + +typedef struct X509_req_st + { + X509_REQ_INFO *req_info; + X509_ALGOR *sig_alg; + ASN1_BIT_STRING *signature; + int references; + } X509_REQ; + +typedef struct x509_cinf_st + { + ASN1_INTEGER *version; /* [ 0 ] default of v1 */ + ASN1_INTEGER *serialNumber; + X509_ALGOR *signature; + X509_NAME *issuer; + X509_VAL *validity; + X509_NAME *subject; + X509_PUBKEY *key; + ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ + ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ + STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */ + } X509_CINF; + +/* This stuff is certificate "auxiliary info" + * it contains details which are useful in certificate + * stores and databases. When used this is tagged onto + * the end of the certificate itself + */ + +typedef struct x509_cert_aux_st + { + STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */ + STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */ + ASN1_UTF8STRING *alias; /* "friendly name" */ + ASN1_OCTET_STRING *keyid; /* key id of private key */ + STACK_OF(X509_ALGOR) *other; /* other unspecified info */ + } X509_CERT_AUX; + +struct x509_st + { + X509_CINF *cert_info; + X509_ALGOR *sig_alg; + ASN1_BIT_STRING *signature; + int valid; + int references; + char *name; + CRYPTO_EX_DATA ex_data; + /* These contain copies of various extension values */ + long ex_pathlen; + long ex_pcpathlen; + unsigned long ex_flags; + unsigned long ex_kusage; + unsigned long ex_xkusage; + unsigned long ex_nscert; + ASN1_OCTET_STRING *skid; + struct AUTHORITY_KEYID_st *akid; + X509_POLICY_CACHE *policy_cache; +#ifndef OPENSSL_NO_RFC3779 + STACK_OF(IPAddressFamily) *rfc3779_addr; + struct ASIdentifiers_st *rfc3779_asid; +#endif +#ifndef OPENSSL_NO_SHA + unsigned char sha1_hash[SHA_DIGEST_LENGTH]; +#endif + X509_CERT_AUX *aux; + } /* X509 */; + +DECLARE_STACK_OF(X509) +DECLARE_ASN1_SET_OF(X509) + +/* This is used for a table of trust checking functions */ + +typedef struct x509_trust_st { + int trust; + int flags; + int (*check_trust)(struct x509_trust_st *, X509 *, int); + char *name; + int arg1; + void *arg2; +} X509_TRUST; + +DECLARE_STACK_OF(X509_TRUST) + +typedef struct x509_cert_pair_st { + X509 *forward; + X509 *reverse; +} X509_CERT_PAIR; + +/* standard trust ids */ + +#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */ + +#define X509_TRUST_COMPAT 1 +#define X509_TRUST_SSL_CLIENT 2 +#define X509_TRUST_SSL_SERVER 3 +#define X509_TRUST_EMAIL 4 +#define X509_TRUST_OBJECT_SIGN 5 +#define X509_TRUST_OCSP_SIGN 6 +#define X509_TRUST_OCSP_REQUEST 7 + +/* Keep these up to date! */ +#define X509_TRUST_MIN 1 +#define X509_TRUST_MAX 7 + + +/* trust_flags values */ +#define X509_TRUST_DYNAMIC 1 +#define X509_TRUST_DYNAMIC_NAME 2 + +/* check_trust return codes */ + +#define X509_TRUST_TRUSTED 1 +#define X509_TRUST_REJECTED 2 +#define X509_TRUST_UNTRUSTED 3 + +/* Flags for X509_print_ex() */ + +#define X509_FLAG_COMPAT 0 +#define X509_FLAG_NO_HEADER 1L +#define X509_FLAG_NO_VERSION (1L << 1) +#define X509_FLAG_NO_SERIAL (1L << 2) +#define X509_FLAG_NO_SIGNAME (1L << 3) +#define X509_FLAG_NO_ISSUER (1L << 4) +#define X509_FLAG_NO_VALIDITY (1L << 5) +#define X509_FLAG_NO_SUBJECT (1L << 6) +#define X509_FLAG_NO_PUBKEY (1L << 7) +#define X509_FLAG_NO_EXTENSIONS (1L << 8) +#define X509_FLAG_NO_SIGDUMP (1L << 9) +#define X509_FLAG_NO_AUX (1L << 10) +#define X509_FLAG_NO_ATTRIBUTES (1L << 11) + +/* Flags specific to X509_NAME_print_ex() */ + +/* The field separator information */ + +#define XN_FLAG_SEP_MASK (0xf << 16) + +#define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */ +#define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */ +#define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */ +#define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */ +#define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */ + +#define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */ + +/* How the field name is shown */ + +#define XN_FLAG_FN_MASK (0x3 << 21) + +#define XN_FLAG_FN_SN 0 /* Object short name */ +#define XN_FLAG_FN_LN (1 << 21) /* Object long name */ +#define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */ +#define XN_FLAG_FN_NONE (3 << 21) /* No field names */ + +#define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */ + +/* This determines if we dump fields we don't recognise: + * RFC2253 requires this. + */ + +#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) + +#define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */ + +/* Complete set of RFC2253 flags */ + +#define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ + XN_FLAG_SEP_COMMA_PLUS | \ + XN_FLAG_DN_REV | \ + XN_FLAG_FN_SN | \ + XN_FLAG_DUMP_UNKNOWN_FIELDS) + +/* readable oneline form */ + +#define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ + ASN1_STRFLGS_ESC_QUOTE | \ + XN_FLAG_SEP_CPLUS_SPC | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_SN) + +/* readable multiline form */ + +#define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + XN_FLAG_SEP_MULTILINE | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_LN | \ + XN_FLAG_FN_ALIGN) + +typedef struct X509_revoked_st + { + ASN1_INTEGER *serialNumber; + ASN1_TIME *revocationDate; + STACK_OF(X509_EXTENSION) /* optional */ *extensions; + int sequence; /* load sequence */ + } X509_REVOKED; + +DECLARE_STACK_OF(X509_REVOKED) +DECLARE_ASN1_SET_OF(X509_REVOKED) + +typedef struct X509_crl_info_st + { + ASN1_INTEGER *version; + X509_ALGOR *sig_alg; + X509_NAME *issuer; + ASN1_TIME *lastUpdate; + ASN1_TIME *nextUpdate; + STACK_OF(X509_REVOKED) *revoked; + STACK_OF(X509_EXTENSION) /* [0] */ *extensions; + ASN1_ENCODING enc; + } X509_CRL_INFO; + +struct X509_crl_st + { + /* actual signature */ + X509_CRL_INFO *crl; + X509_ALGOR *sig_alg; + ASN1_BIT_STRING *signature; + int references; + } /* X509_CRL */; + +DECLARE_STACK_OF(X509_CRL) +DECLARE_ASN1_SET_OF(X509_CRL) + +typedef struct private_key_st + { + int version; + /* The PKCS#8 data types */ + X509_ALGOR *enc_algor; + ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ + + /* When decrypted, the following will not be NULL */ + EVP_PKEY *dec_pkey; + + /* used to encrypt and decrypt */ + int key_length; + char *key_data; + int key_free; /* true if we should auto free key_data */ + + /* expanded version of 'enc_algor' */ + EVP_CIPHER_INFO cipher; + + int references; + } X509_PKEY; + +#ifndef OPENSSL_NO_EVP +typedef struct X509_info_st + { + X509 *x509; + X509_CRL *crl; + X509_PKEY *x_pkey; + + EVP_CIPHER_INFO enc_cipher; + int enc_len; + char *enc_data; + + int references; + } X509_INFO; + +DECLARE_STACK_OF(X509_INFO) +#endif + +/* The next 2 structures and their 8 routines were sent to me by + * Pat Richard and are used to manipulate + * Netscapes spki structures - useful if you are writing a CA web page + */ +typedef struct Netscape_spkac_st + { + X509_PUBKEY *pubkey; + ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ + } NETSCAPE_SPKAC; + +typedef struct Netscape_spki_st + { + NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ + X509_ALGOR *sig_algor; + ASN1_BIT_STRING *signature; + } NETSCAPE_SPKI; + +/* Netscape certificate sequence structure */ +typedef struct Netscape_certificate_sequence + { + ASN1_OBJECT *type; + STACK_OF(X509) *certs; + } NETSCAPE_CERT_SEQUENCE; + +/* Unused (and iv length is wrong) +typedef struct CBCParameter_st + { + unsigned char iv[8]; + } CBC_PARAM; +*/ + +/* Password based encryption structure */ + +typedef struct PBEPARAM_st { +ASN1_OCTET_STRING *salt; +ASN1_INTEGER *iter; +} PBEPARAM; + +/* Password based encryption V2 structures */ + +typedef struct PBE2PARAM_st { +X509_ALGOR *keyfunc; +X509_ALGOR *encryption; +} PBE2PARAM; + +typedef struct PBKDF2PARAM_st { +ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */ +ASN1_INTEGER *iter; +ASN1_INTEGER *keylength; +X509_ALGOR *prf; +} PBKDF2PARAM; + + +/* PKCS#8 private key info structure */ + +typedef struct pkcs8_priv_key_info_st + { + int broken; /* Flag for various broken formats */ +#define PKCS8_OK 0 +#define PKCS8_NO_OCTET 1 +#define PKCS8_EMBEDDED_PARAM 2 +#define PKCS8_NS_DB 3 + ASN1_INTEGER *version; + X509_ALGOR *pkeyalg; + ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */ + STACK_OF(X509_ATTRIBUTE) *attributes; + } PKCS8_PRIV_KEY_INFO; + +#ifdef __cplusplus +} +#endif + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SSLEAY_MACROS +#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\ + a->signature,(char *)a->cert_info,r) +#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \ + a->sig_alg,a->signature,(char *)a->req_info,r) +#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \ + a->sig_alg, a->signature,(char *)a->crl,r) + +#define X509_sign(x,pkey,md) \ + ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \ + x->sig_alg, x->signature, (char *)x->cert_info,pkey,md) +#define X509_REQ_sign(x,pkey,md) \ + ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \ + x->signature, (char *)x->req_info,pkey,md) +#define X509_CRL_sign(x,pkey,md) \ + ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \ + x->signature, (char *)x->crl,pkey,md) +#define NETSCAPE_SPKI_sign(x,pkey,md) \ + ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \ + x->signature, (char *)x->spkac,pkey,md) + +#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \ + (char *(*)())d2i_X509,(char *)x509) +#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\ + (int (*)())i2d_X509_ATTRIBUTE, \ + (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa) +#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \ + (int (*)())i2d_X509_EXTENSION, \ + (char *(*)())d2i_X509_EXTENSION,(char *)ex) +#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \ + (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)) +#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509) +#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \ + (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)) +#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509) + +#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \ + (char *(*)())d2i_X509_CRL,(char *)crl) +#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \ + X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\ + (unsigned char **)(crl)) +#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\ + (unsigned char *)crl) +#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \ + X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\ + (unsigned char **)(crl)) +#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\ + (unsigned char *)crl) + +#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \ + (char *(*)())d2i_PKCS7,(char *)p7) +#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \ + PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\ + (unsigned char **)(p7)) +#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\ + (unsigned char *)p7) +#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \ + PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\ + (unsigned char **)(p7)) +#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\ + (unsigned char *)p7) + +#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \ + (char *(*)())d2i_X509_REQ,(char *)req) +#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\ + X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\ + (unsigned char **)(req)) +#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\ + (unsigned char *)req) +#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\ + X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\ + (unsigned char **)(req)) +#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\ + (unsigned char *)req) + +#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \ + (char *(*)())d2i_RSAPublicKey,(char *)rsa) +#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \ + (char *(*)())d2i_RSAPrivateKey,(char *)rsa) + +#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\ + RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \ + (unsigned char **)(rsa)) +#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \ + (unsigned char *)rsa) +#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\ + RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \ + (unsigned char **)(rsa)) +#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \ + (unsigned char *)rsa) + +#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\ + RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \ + (unsigned char **)(rsa)) +#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \ + (unsigned char *)rsa) +#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\ + RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \ + (unsigned char **)(rsa)) +#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \ + (unsigned char *)rsa) + +#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\ + DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \ + (unsigned char **)(dsa)) +#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \ + (unsigned char *)dsa) +#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\ + DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \ + (unsigned char **)(dsa)) +#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \ + (unsigned char *)dsa) + +#define d2i_ECPrivateKey_fp(fp,ecdsa) (EC_KEY *)ASN1_d2i_fp((char *(*)())\ + EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (fp), \ + (unsigned char **)(ecdsa)) +#define i2d_ECPrivateKey_fp(fp,ecdsa) ASN1_i2d_fp(i2d_ECPrivateKey,fp, \ + (unsigned char *)ecdsa) +#define d2i_ECPrivateKey_bio(bp,ecdsa) (EC_KEY *)ASN1_d2i_bio((char *(*)())\ + EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (bp), \ + (unsigned char **)(ecdsa)) +#define i2d_ECPrivateKey_bio(bp,ecdsa) ASN1_i2d_bio(i2d_ECPrivateKey,bp, \ + (unsigned char *)ecdsa) + +#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\ + (char *(*)())d2i_X509_ALGOR,(char *)xn) + +#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \ + (char *(*)())d2i_X509_NAME,(char *)xn) +#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \ + (int (*)())i2d_X509_NAME_ENTRY, \ + (char *(*)())d2i_X509_NAME_ENTRY,\ + (char *)ne) + +#define X509_digest(data,type,md,len) \ + ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len) +#define X509_NAME_digest(data,type,md,len) \ + ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len) +#ifndef PKCS7_ISSUER_AND_SERIAL_digest +#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ + ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ + (char *)data,md,len) +#endif +#endif + +#define X509_EXT_PACK_UNKNOWN 1 +#define X509_EXT_PACK_STRING 2 + +#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version) +/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */ +#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore) +#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter) +#define X509_extract_key(x) X509_get_pubkey(x) /*****/ +#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version) +#define X509_REQ_get_subject_name(x) ((x)->req_info->subject) +#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) +#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) +#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm)) + +#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version) +#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate) +#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate) +#define X509_CRL_get_issuer(x) ((x)->crl->issuer) +#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked) + +/* This one is only used so that a binary form can output, as in + * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */ +#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key) + + +const char *X509_verify_cert_error_string(long n); + +#ifndef SSLEAY_MACROS +#ifndef OPENSSL_NO_EVP +int X509_verify(X509 *a, EVP_PKEY *r); + +int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); +int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); +int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); + +NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len); +char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); +EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); +int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); + +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); + +int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig); + +int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); +int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); + +int X509_pubkey_digest(const X509 *data,const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_digest(const X509 *data,const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type, + unsigned char *md, unsigned int *len); +#endif + +#ifndef OPENSSL_NO_FP_API +X509 *d2i_X509_fp(FILE *fp, X509 **x509); +int i2d_X509_fp(FILE *fp,X509 *x509); +X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl); +int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); +X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req); +int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); +#ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa); +int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); +RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa); +int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); +RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa); +int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa); +#endif +#ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); +int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); +DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); +int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +#endif +#ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); +int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); +int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); +#endif +X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); +int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); +int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); +#endif + +#ifndef OPENSSL_NO_BIO +X509 *d2i_X509_bio(BIO *bp,X509 **x509); +int i2d_X509_bio(BIO *bp,X509 *x509); +X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl); +int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); +X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req); +int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); +#ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa); +int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); +RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa); +int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); +RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa); +int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa); +#endif +#ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); +int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); +DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); +int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); +#endif +#ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); +int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); +int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); +#endif +X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8); +int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); +int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); +#endif + +X509 *X509_dup(X509 *x509); +X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); +X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); +X509_CRL *X509_CRL_dup(X509_CRL *crl); +X509_REQ *X509_REQ_dup(X509_REQ *req); +X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); +int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval); +void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, + X509_ALGOR *algor); + +X509_NAME *X509_NAME_dup(X509_NAME *xn); +X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); + +#endif /* !SSLEAY_MACROS */ + +int X509_cmp_time(ASN1_TIME *s, time_t *t); +int X509_cmp_current_time(ASN1_TIME *s); +ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t); +ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj); + +const char * X509_get_default_cert_area(void ); +const char * X509_get_default_cert_dir(void ); +const char * X509_get_default_cert_file(void ); +const char * X509_get_default_cert_dir_env(void ); +const char * X509_get_default_cert_file_env(void ); +const char * X509_get_default_private_dir(void ); + +X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); + +DECLARE_ASN1_FUNCTIONS(X509_ALGOR) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) +DECLARE_ASN1_FUNCTIONS(X509_VAL) + +DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) + +int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); +EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); +int X509_get_pubkey_parameters(EVP_PKEY *pkey, + STACK_OF(X509) *chain); +int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); +EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp, + long length); +#ifndef OPENSSL_NO_RSA +int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp); +RSA * d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp, + long length); +#endif +#ifndef OPENSSL_NO_DSA +int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp); +DSA * d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp, + long length); +#endif +#ifndef OPENSSL_NO_EC +int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp); +EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, + long length); +#endif + +DECLARE_ASN1_FUNCTIONS(X509_SIG) +DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) +DECLARE_ASN1_FUNCTIONS(X509_REQ) + +DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) +X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); + +DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) + +DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) + +DECLARE_ASN1_FUNCTIONS(X509_NAME) + +int X509_NAME_set(X509_NAME **xn, X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(X509_CINF) + +DECLARE_ASN1_FUNCTIONS(X509) +DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) + +DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR) + +int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int X509_set_ex_data(X509 *r, int idx, void *arg); +void *X509_get_ex_data(X509 *r, int idx); +int i2d_X509_AUX(X509 *a,unsigned char **pp); +X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length); + +int X509_alias_set1(X509 *x, unsigned char *name, int len); +int X509_keyid_set1(X509 *x, unsigned char *id, int len); +unsigned char * X509_alias_get0(X509 *x, int *len); +unsigned char * X509_keyid_get0(X509 *x, int *len); +int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int); +int X509_TRUST_set(int *t, int trust); +int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj); +int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj); +void X509_trust_clear(X509 *x); +void X509_reject_clear(X509 *x); + +DECLARE_ASN1_FUNCTIONS(X509_REVOKED) +DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) +DECLARE_ASN1_FUNCTIONS(X509_CRL) + +int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); + +X509_PKEY * X509_PKEY_new(void ); +void X509_PKEY_free(X509_PKEY *a); +int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp); +X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,const unsigned char **pp,long length); + +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) + +#ifndef OPENSSL_NO_EVP +X509_INFO * X509_INFO_new(void); +void X509_INFO_free(X509_INFO *a); +char * X509_NAME_oneline(X509_NAME *a,char *buf,int size); + +int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey); + +int ASN1_digest(i2d_of_void *i2d,const EVP_MD *type,char *data, + unsigned char *md,unsigned int *len); + +int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + char *data,EVP_PKEY *pkey, const EVP_MD *type); + +int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data, + unsigned char *md,unsigned int *len); + +int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey); + +int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, + ASN1_BIT_STRING *signature, + void *data, EVP_PKEY *pkey, const EVP_MD *type); +#endif + +int X509_set_version(X509 *x,long version); +int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); +ASN1_INTEGER * X509_get_serialNumber(X509 *x); +int X509_set_issuer_name(X509 *x, X509_NAME *name); +X509_NAME * X509_get_issuer_name(X509 *a); +int X509_set_subject_name(X509 *x, X509_NAME *name); +X509_NAME * X509_get_subject_name(X509 *a); +int X509_set_notBefore(X509 *x, ASN1_TIME *tm); +int X509_set_notAfter(X509 *x, ASN1_TIME *tm); +int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); +EVP_PKEY * X509_get_pubkey(X509 *x); +ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x); +int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */); + +int X509_REQ_set_version(X509_REQ *x,long version); +int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name); +int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); +EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req); +int X509_REQ_extension_nid(int nid); +int * X509_REQ_get_extension_nids(void); +void X509_REQ_set_extension_nids(int *nids); +STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req); +int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, + int nid); +int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); +int X509_REQ_get_attr_count(const X509_REQ *req); +int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, + int lastpos); +int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); +X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); +int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); +int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_NID(X509_REQ *req, + int nid, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_txt(X509_REQ *req, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_CRL_set_version(X509_CRL *x, long version); +int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name); +int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm); +int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm); +int X509_CRL_sort(X509_CRL *crl); + +int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); +int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); + +int X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey); + +int X509_check_private_key(X509 *x509,EVP_PKEY *pkey); + +int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_and_serial_hash(X509 *a); + +int X509_issuer_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_name_hash(X509 *a); + +int X509_subject_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_subject_name_hash(X509 *x); + +int X509_cmp(const X509 *a, const X509 *b); +int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); +unsigned long X509_NAME_hash(X509_NAME *x); + +int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); +#ifndef OPENSSL_NO_FP_API +int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag); +int X509_print_fp(FILE *bp,X509 *x); +int X509_CRL_print_fp(FILE *bp,X509_CRL *x); +int X509_REQ_print_fp(FILE *bp,X509_REQ *req); +int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags); +#endif + +#ifndef OPENSSL_NO_BIO +int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); +int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags); +int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag); +int X509_print(BIO *bp,X509 *x); +int X509_ocspid_print(BIO *bp,X509 *x); +int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent); +int X509_CRL_print(BIO *bp,X509_CRL *x); +int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag); +int X509_REQ_print(BIO *bp,X509_REQ *req); +#endif + +int X509_NAME_entry_count(X509_NAME *name); +int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, + char *buf,int len); +int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, + char *buf,int len); + +/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use + * lastpos, search after that position on. */ +int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos); +int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, + int lastpos); +X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc); +X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); +int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, + int loc, int set); +int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, + unsigned char *bytes, int len, int loc, int set); +int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, + unsigned char *bytes, int len, int loc, int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, + const char *field, int type, const unsigned char *bytes, int len); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, + int type,unsigned char *bytes, int len); +int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, + const unsigned char *bytes, int len, int loc, int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, + ASN1_OBJECT *obj, int type,const unsigned char *bytes, + int len); +int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, + ASN1_OBJECT *obj); +int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, + const unsigned char *bytes, int len); +ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); +ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); + +int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); +int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, + int nid, int lastpos); +int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, + ASN1_OBJECT *obj,int lastpos); +int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, + int crit, int lastpos); +X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); +X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); +STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, + X509_EXTENSION *ex, int loc); + +int X509_get_ext_count(X509 *x); +int X509_get_ext_by_NID(X509 *x, int nid, int lastpos); +int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos); +int X509_get_ext_by_critical(X509 *x, int crit, int lastpos); +X509_EXTENSION *X509_get_ext(X509 *x, int loc); +X509_EXTENSION *X509_delete_ext(X509 *x, int loc); +int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); +void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx); +int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_CRL_get_ext_count(X509_CRL *x); +int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos); +int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos); +int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos); +X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc); +X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); +int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); +void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx); +int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_REVOKED_get_ext_count(X509_REVOKED *x); +int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos); +int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos); +int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos); +X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc); +X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); +int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); +void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx); +int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, + unsigned long flags); + +X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, + int nid, int crit, ASN1_OCTET_STRING *data); +X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, + ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data); +int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj); +int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); +int X509_EXTENSION_set_data(X509_EXTENSION *ex, + ASN1_OCTET_STRING *data); +ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); +ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); +int X509_EXTENSION_get_critical(X509_EXTENSION *ex); + +int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); +int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, + int lastpos); +int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); +X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, + X509_ATTRIBUTE *attr); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x, + int nid, int type, + const unsigned char *bytes, int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, + const char *attrname, int type, + const unsigned char *bytes, int len); +void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, + ASN1_OBJECT *obj, int lastpos, int type); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, + int atrtype, const void *data, int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, + const ASN1_OBJECT *obj, int atrtype, const void *data, int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, + const char *atrname, int type, const unsigned char *bytes, int len); +int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); +int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len); +void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, + int atrtype, void *data); +int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr); +ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); +ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); + +int EVP_PKEY_get_attr_count(const EVP_PKEY *key); +int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, + int lastpos); +int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); +X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); +int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); +int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, + int nid, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_verify_cert(X509_STORE_CTX *ctx); + +/* lookup a cert from a X509 STACK */ +X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name, + ASN1_INTEGER *serial); +X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(PBEPARAM) +DECLARE_ASN1_FUNCTIONS(PBE2PARAM) +DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM) + +X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen); + +/* PKCS#8 utilities */ + +DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) + +EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken); +PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); + +int X509_check_trust(X509 *x, int id, int flags); +int X509_TRUST_get_count(void); +X509_TRUST * X509_TRUST_get0(int idx); +int X509_TRUST_get_by_id(int id); +int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), + char *name, int arg1, void *arg2); +void X509_TRUST_cleanup(void); +int X509_TRUST_get_flags(X509_TRUST *xp); +char *X509_TRUST_get0_name(X509_TRUST *xp); +int X509_TRUST_get_trust(X509_TRUST *xp); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_X509_strings(void); + +/* Error codes for the X509 functions. */ + +/* Function codes. */ +#define X509_F_ADD_CERT_DIR 100 +#define X509_F_BY_FILE_CTRL 101 +#define X509_F_CHECK_POLICY 145 +#define X509_F_DIR_CTRL 102 +#define X509_F_GET_CERT_BY_SUBJECT 103 +#define X509_F_NETSCAPE_SPKI_B64_DECODE 129 +#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 +#define X509_F_X509AT_ADD1_ATTR 135 +#define X509_F_X509V3_ADD_EXT 104 +#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 +#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 +#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 +#define X509_F_X509_ATTRIBUTE_GET0_DATA 139 +#define X509_F_X509_ATTRIBUTE_SET1_DATA 138 +#define X509_F_X509_CHECK_PRIVATE_KEY 128 +#define X509_F_X509_CRL_PRINT_FP 147 +#define X509_F_X509_EXTENSION_CREATE_BY_NID 108 +#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 +#define X509_F_X509_GET_PUBKEY_PARAMETERS 110 +#define X509_F_X509_LOAD_CERT_CRL_FILE 132 +#define X509_F_X509_LOAD_CERT_FILE 111 +#define X509_F_X509_LOAD_CRL_FILE 112 +#define X509_F_X509_NAME_ADD_ENTRY 113 +#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 +#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131 +#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 +#define X509_F_X509_NAME_ONELINE 116 +#define X509_F_X509_NAME_PRINT 117 +#define X509_F_X509_PRINT_EX_FP 118 +#define X509_F_X509_PUBKEY_GET 119 +#define X509_F_X509_PUBKEY_SET 120 +#define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 +#define X509_F_X509_REQ_PRINT_EX 121 +#define X509_F_X509_REQ_PRINT_FP 122 +#define X509_F_X509_REQ_TO_X509 123 +#define X509_F_X509_STORE_ADD_CERT 124 +#define X509_F_X509_STORE_ADD_CRL 125 +#define X509_F_X509_STORE_CTX_GET1_ISSUER 146 +#define X509_F_X509_STORE_CTX_INIT 143 +#define X509_F_X509_STORE_CTX_NEW 142 +#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 +#define X509_F_X509_TO_X509_REQ 126 +#define X509_F_X509_TRUST_ADD 133 +#define X509_F_X509_TRUST_SET 141 +#define X509_F_X509_VERIFY_CERT 127 + +/* Reason codes. */ +#define X509_R_BAD_X509_FILETYPE 100 +#define X509_R_BASE64_DECODE_ERROR 118 +#define X509_R_CANT_CHECK_DH_KEY 114 +#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 +#define X509_R_ERR_ASN1_LIB 102 +#define X509_R_INVALID_DIRECTORY 113 +#define X509_R_INVALID_FIELD_NAME 119 +#define X509_R_INVALID_TRUST 123 +#define X509_R_KEY_TYPE_MISMATCH 115 +#define X509_R_KEY_VALUES_MISMATCH 116 +#define X509_R_LOADING_CERT_DIR 103 +#define X509_R_LOADING_DEFAULTS 104 +#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 +#define X509_R_SHOULD_RETRY 106 +#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 +#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 +#define X509_R_UNKNOWN_KEY_TYPE 117 +#define X509_R_UNKNOWN_NID 109 +#define X509_R_UNKNOWN_PURPOSE_ID 121 +#define X509_R_UNKNOWN_TRUST_ID 120 +#define X509_R_UNSUPPORTED_ALGORITHM 111 +#define X509_R_WRONG_LOOKUP_TYPE 112 +#define X509_R_WRONG_TYPE 122 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/x509_vfy.h b/石器时代8.5客户端最新源代码/石器源码/openssl/x509_vfy.h new file mode 100644 index 0000000..76c76e1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/x509_vfy.h @@ -0,0 +1,531 @@ +/* crypto/x509/x509_vfy.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_X509_H +#include +/* openssl/x509.h ends up #include-ing this file at about the only + * appropriate moment. */ +#endif + +#ifndef HEADER_X509_VFY_H +#define HEADER_X509_VFY_H + +#include +#ifndef OPENSSL_NO_LHASH +#include +#endif +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Outer object */ +typedef struct x509_hash_dir_st + { + int num_dirs; + char **dirs; + int *dirs_type; + int num_dirs_alloced; + } X509_HASH_DIR_CTX; + +typedef struct x509_file_st + { + int num_paths; /* number of paths to files or directories */ + int num_alloced; + char **paths; /* the list of paths or directories */ + int *path_type; + } X509_CERT_FILE_CTX; + +/*******************************/ +/* +SSL_CTX -> X509_STORE + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + +SSL -> X509_STORE_CTX + ->X509_STORE + +The X509_STORE holds the tables etc for verification stuff. +A X509_STORE_CTX is used while validating a single certificate. +The X509_STORE has X509_LOOKUPs for looking up certs. +The X509_STORE then calls a function to actually verify the +certificate chain. +*/ + +#define X509_LU_RETRY -1 +#define X509_LU_FAIL 0 +#define X509_LU_X509 1 +#define X509_LU_CRL 2 +#define X509_LU_PKEY 3 + +typedef struct x509_object_st + { + /* one of the above types */ + int type; + union { + char *ptr; + X509 *x509; + X509_CRL *crl; + EVP_PKEY *pkey; + } data; + } X509_OBJECT; + +typedef struct x509_lookup_st X509_LOOKUP; + +DECLARE_STACK_OF(X509_LOOKUP) +DECLARE_STACK_OF(X509_OBJECT) + +/* This is a static that defines the function interface */ +typedef struct x509_lookup_method_st + { + const char *name; + int (*new_item)(X509_LOOKUP *ctx); + void (*free)(X509_LOOKUP *ctx); + int (*init)(X509_LOOKUP *ctx); + int (*shutdown)(X509_LOOKUP *ctx); + int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl, + char **ret); + int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name, + X509_OBJECT *ret); + int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name, + ASN1_INTEGER *serial,X509_OBJECT *ret); + int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type, + unsigned char *bytes,int len, + X509_OBJECT *ret); + int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len, + X509_OBJECT *ret); + } X509_LOOKUP_METHOD; + +/* This structure hold all parameters associated with a verify operation + * by including an X509_VERIFY_PARAM structure in related structures the + * parameters used can be customized + */ + +typedef struct X509_VERIFY_PARAM_st + { + char *name; + time_t check_time; /* Time to use */ + unsigned long inh_flags; /* Inheritance flags */ + unsigned long flags; /* Various verify flags */ + int purpose; /* purpose to check untrusted certificates */ + int trust; /* trust setting to check */ + int depth; /* Verify depth */ + STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */ + } X509_VERIFY_PARAM; + +DECLARE_STACK_OF(X509_VERIFY_PARAM) + +/* This is used to hold everything. It is used for all certificate + * validation. Once we have a certificate chain, the 'verify' + * function is then called to actually check the cert chain. */ +struct x509_store_st + { + /* The following is a cache of trusted certs */ + int cache; /* if true, stash any hits */ + STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */ + + /* These are external lookup methods */ + STACK_OF(X509_LOOKUP) *get_cert_methods; + + X509_VERIFY_PARAM *param; + + /* Callbacks for various operations */ + int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ + int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ + int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */ + int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */ + int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */ + int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */ + int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */ + int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */ + int (*cleanup)(X509_STORE_CTX *ctx); + + CRYPTO_EX_DATA ex_data; + int references; + } /* X509_STORE */; + +int X509_STORE_set_depth(X509_STORE *store, int depth); + +#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func)) +#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) + +/* This is the functions plus an instance of the local variables. */ +struct x509_lookup_st + { + int init; /* have we been started */ + int skip; /* don't use us. */ + X509_LOOKUP_METHOD *method; /* the functions */ + char *method_data; /* method data */ + + X509_STORE *store_ctx; /* who owns us */ + } /* X509_LOOKUP */; + +/* This is a used when verifying cert chains. Since the + * gathering of the cert chain can take some time (and have to be + * 'retried', this needs to be kept and passed around. */ +struct x509_store_ctx_st /* X509_STORE_CTX */ + { + X509_STORE *ctx; + int current_method; /* used when looking up certs */ + + /* The following are set by the caller */ + X509 *cert; /* The cert to check */ + STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */ + STACK_OF(X509_CRL) *crls; /* set of CRLs passed in */ + + X509_VERIFY_PARAM *param; + void *other_ctx; /* Other info for use with get_issuer() */ + + /* Callbacks for various operations */ + int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ + int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ + int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */ + int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */ + int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */ + int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */ + int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */ + int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */ + int (*check_policy)(X509_STORE_CTX *ctx); + int (*cleanup)(X509_STORE_CTX *ctx); + + /* The following is built up */ + int valid; /* if 0, rebuild chain */ + int last_untrusted; /* index of last untrusted cert */ + STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */ + X509_POLICY_TREE *tree; /* Valid policy tree */ + + int explicit_policy; /* Require explicit policy value */ + + /* When something goes wrong, this is why */ + int error_depth; + int error; + X509 *current_cert; + X509 *current_issuer; /* cert currently being tested as valid issuer */ + X509_CRL *current_crl; /* current CRL */ + + CRYPTO_EX_DATA ex_data; + } /* X509_STORE_CTX */; + +void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); + +#define X509_STORE_CTX_set_app_data(ctx,data) \ + X509_STORE_CTX_set_ex_data(ctx,0,data) +#define X509_STORE_CTX_get_app_data(ctx) \ + X509_STORE_CTX_get_ex_data(ctx,0) + +#define X509_L_FILE_LOAD 1 +#define X509_L_ADD_DIR 2 + +#define X509_LOOKUP_load_file(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) + +#define X509_LOOKUP_add_dir(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) + +#define X509_V_OK 0 +/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ + +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +#define X509_V_ERR_UNABLE_TO_GET_CRL 3 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +#define X509_V_ERR_CERT_NOT_YET_VALID 9 +#define X509_V_ERR_CERT_HAS_EXPIRED 10 +#define X509_V_ERR_CRL_NOT_YET_VALID 11 +#define X509_V_ERR_CRL_HAS_EXPIRED 12 +#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +#define X509_V_ERR_OUT_OF_MEM 17 +#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +#define X509_V_ERR_CERT_REVOKED 23 +#define X509_V_ERR_INVALID_CA 24 +#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +#define X509_V_ERR_INVALID_PURPOSE 26 +#define X509_V_ERR_CERT_UNTRUSTED 27 +#define X509_V_ERR_CERT_REJECTED 28 +/* These are 'informational' when looking for issuer cert */ +#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +#define X509_V_ERR_AKID_SKID_MISMATCH 30 +#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 + +#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +#define X509_V_ERR_INVALID_NON_CA 37 +#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 + +#define X509_V_ERR_INVALID_EXTENSION 41 +#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +#define X509_V_ERR_NO_EXPLICIT_POLICY 43 + +#define X509_V_ERR_UNNESTED_RESOURCE 44 + +/* The application is not happy */ +#define X509_V_ERR_APPLICATION_VERIFICATION 50 + +/* Certificate verify flags */ + +/* Send issuer+subject checks to verify_cb */ +#define X509_V_FLAG_CB_ISSUER_CHECK 0x1 +/* Use check time instead of current time */ +#define X509_V_FLAG_USE_CHECK_TIME 0x2 +/* Lookup CRLs */ +#define X509_V_FLAG_CRL_CHECK 0x4 +/* Lookup CRLs for whole chain */ +#define X509_V_FLAG_CRL_CHECK_ALL 0x8 +/* Ignore unhandled critical extensions */ +#define X509_V_FLAG_IGNORE_CRITICAL 0x10 +/* Disable workarounds for broken certificates */ +#define X509_V_FLAG_X509_STRICT 0x20 +/* Enable proxy certificate validation */ +#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +/* Enable policy checking */ +#define X509_V_FLAG_POLICY_CHECK 0x80 +/* Policy variable require-explicit-policy */ +#define X509_V_FLAG_EXPLICIT_POLICY 0x100 +/* Policy variable inhibit-any-policy */ +#define X509_V_FLAG_INHIBIT_ANY 0x200 +/* Policy variable inhibit-policy-mapping */ +#define X509_V_FLAG_INHIBIT_MAP 0x400 +/* Notify callback that policy is OK */ +#define X509_V_FLAG_NOTIFY_POLICY 0x800 + +#define X509_VP_FLAG_DEFAULT 0x1 +#define X509_VP_FLAG_OVERWRITE 0x2 +#define X509_VP_FLAG_RESET_FLAGS 0x4 +#define X509_VP_FLAG_LOCKED 0x8 +#define X509_VP_FLAG_ONCE 0x10 + +/* Internal use: mask of policy related options */ +#define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ + | X509_V_FLAG_EXPLICIT_POLICY \ + | X509_V_FLAG_INHIBIT_ANY \ + | X509_V_FLAG_INHIBIT_MAP) + +int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, + X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x); +void X509_OBJECT_up_ref_count(X509_OBJECT *a); +void X509_OBJECT_free_contents(X509_OBJECT *a); +X509_STORE *X509_STORE_new(void ); +void X509_STORE_free(X509_STORE *v); + +int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); +int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); +int X509_STORE_set_trust(X509_STORE *ctx, int trust); +int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm); + +X509_STORE_CTX *X509_STORE_CTX_new(void); + +int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); + +void X509_STORE_CTX_free(X509_STORE_CTX *ctx); +int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, + X509 *x509, STACK_OF(X509) *chain); +void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); +void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); + +X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); + +X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); +X509_LOOKUP_METHOD *X509_LOOKUP_file(void); + +int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); +int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); + +int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name, + X509_OBJECT *ret); + +int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); + +#ifndef OPENSSL_NO_STDIO +int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type); +#endif + + +X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); +void X509_LOOKUP_free(X509_LOOKUP *ctx); +int X509_LOOKUP_init(X509_LOOKUP *ctx); +int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, + X509_OBJECT *ret); +int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, + ASN1_INTEGER *serial, X509_OBJECT *ret); +int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, + unsigned char *bytes, int len, X509_OBJECT *ret); +int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, + int len, X509_OBJECT *ret); +int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); + +#ifndef OPENSSL_NO_STDIO +int X509_STORE_load_locations (X509_STORE *ctx, + const char *file, const char *dir); +int X509_STORE_set_default_paths(X509_STORE *ctx); +#endif + +int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data); +void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); +int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s); +int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); +X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); +void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk); +void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,STACK_OF(X509_CRL) *sk); +int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); +int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); +int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, + int purpose, int trust); +void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); +void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, + time_t t); +void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, + int (*verify_cb)(int, X509_STORE_CTX *)); + +X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx); +int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); + +X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param); +int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name); + +/* X509_VERIFY_PARAM functions */ + +X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); +void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name); +int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags); +int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose); +int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust); +void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth); +void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t); +int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, + ASN1_OBJECT *policy); +int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, + STACK_OF(ASN1_OBJECT) *policies); +int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); + +int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); +const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); +void X509_VERIFY_PARAM_table_cleanup(void); + +int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, + STACK_OF(X509) *certs, + STACK_OF(ASN1_OBJECT) *policy_oids, + unsigned int flags); + +void X509_policy_tree_free(X509_POLICY_TREE *tree); + +int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); +X509_POLICY_LEVEL * + X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, int i); + +STACK_OF(X509_POLICY_NODE) * + X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree); + +STACK_OF(X509_POLICY_NODE) * + X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree); + +int X509_policy_level_node_count(X509_POLICY_LEVEL *level); + +X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i); + +const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node); + +STACK_OF(POLICYQUALINFO) * + X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node); +const X509_POLICY_NODE * + X509_policy_node_get0_parent(const X509_POLICY_NODE *node); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/openssl/x509v3.h b/石器时代8.5客户端最新源代码/石器源码/openssl/x509v3.h new file mode 100644 index 0000000..9ef83da --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/openssl/x509v3.h @@ -0,0 +1,922 @@ +/* x509v3.h */ +/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#ifndef HEADER_X509V3_H +#define HEADER_X509V3_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward reference */ +struct v3_ext_method; +struct v3_ext_ctx; + +/* Useful typedefs */ + +typedef void * (*X509V3_EXT_NEW)(void); +typedef void (*X509V3_EXT_FREE)(void *); +typedef void * (*X509V3_EXT_D2I)(void *, const unsigned char ** , long); +typedef int (*X509V3_EXT_I2D)(void *, unsigned char **); +typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist); +typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values); +typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext); +typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str); +typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent); +typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str); + +/* V3 extension structure */ + +struct v3_ext_method { +int ext_nid; +int ext_flags; +/* If this is set the following four fields are ignored */ +ASN1_ITEM_EXP *it; +/* Old style ASN1 calls */ +X509V3_EXT_NEW ext_new; +X509V3_EXT_FREE ext_free; +X509V3_EXT_D2I d2i; +X509V3_EXT_I2D i2d; + +/* The following pair is used for string extensions */ +X509V3_EXT_I2S i2s; +X509V3_EXT_S2I s2i; + +/* The following pair is used for multi-valued extensions */ +X509V3_EXT_I2V i2v; +X509V3_EXT_V2I v2i; + +/* The following are used for raw extensions */ +X509V3_EXT_I2R i2r; +X509V3_EXT_R2I r2i; + +void *usr_data; /* Any extension specific data */ +}; + +typedef struct X509V3_CONF_METHOD_st { +char * (*get_string)(void *db, char *section, char *value); +STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section); +void (*free_string)(void *db, char * string); +void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section); +} X509V3_CONF_METHOD; + +/* Context specific info */ +struct v3_ext_ctx { +#define CTX_TEST 0x1 +int flags; +X509 *issuer_cert; +X509 *subject_cert; +X509_REQ *subject_req; +X509_CRL *crl; +X509V3_CONF_METHOD *db_meth; +void *db; +/* Maybe more here */ +}; + +typedef struct v3_ext_method X509V3_EXT_METHOD; + +DECLARE_STACK_OF(X509V3_EXT_METHOD) + +/* ext_flags values */ +#define X509V3_EXT_DYNAMIC 0x1 +#define X509V3_EXT_CTX_DEP 0x2 +#define X509V3_EXT_MULTILINE 0x4 + +typedef BIT_STRING_BITNAME ENUMERATED_NAMES; + +typedef struct BASIC_CONSTRAINTS_st { +int ca; +ASN1_INTEGER *pathlen; +} BASIC_CONSTRAINTS; + + +typedef struct PKEY_USAGE_PERIOD_st { +ASN1_GENERALIZEDTIME *notBefore; +ASN1_GENERALIZEDTIME *notAfter; +} PKEY_USAGE_PERIOD; + +typedef struct otherName_st { +ASN1_OBJECT *type_id; +ASN1_TYPE *value; +} OTHERNAME; + +typedef struct EDIPartyName_st { + ASN1_STRING *nameAssigner; + ASN1_STRING *partyName; +} EDIPARTYNAME; + +typedef struct GENERAL_NAME_st { + +#define GEN_OTHERNAME 0 +#define GEN_EMAIL 1 +#define GEN_DNS 2 +#define GEN_X400 3 +#define GEN_DIRNAME 4 +#define GEN_EDIPARTY 5 +#define GEN_URI 6 +#define GEN_IPADD 7 +#define GEN_RID 8 + +int type; +union { + char *ptr; + OTHERNAME *otherName; /* otherName */ + ASN1_IA5STRING *rfc822Name; + ASN1_IA5STRING *dNSName; + ASN1_TYPE *x400Address; + X509_NAME *directoryName; + EDIPARTYNAME *ediPartyName; + ASN1_IA5STRING *uniformResourceIdentifier; + ASN1_OCTET_STRING *iPAddress; + ASN1_OBJECT *registeredID; + + /* Old names */ + ASN1_OCTET_STRING *ip; /* iPAddress */ + X509_NAME *dirn; /* dirn */ + ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */ + ASN1_OBJECT *rid; /* registeredID */ + ASN1_TYPE *other; /* x400Address */ +} d; +} GENERAL_NAME; + +typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; + +typedef struct ACCESS_DESCRIPTION_st { + ASN1_OBJECT *method; + GENERAL_NAME *location; +} ACCESS_DESCRIPTION; + +typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; + +typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; + +DECLARE_STACK_OF(GENERAL_NAME) +DECLARE_ASN1_SET_OF(GENERAL_NAME) + +DECLARE_STACK_OF(ACCESS_DESCRIPTION) +DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) + +typedef struct DIST_POINT_NAME_st { +int type; +union { + GENERAL_NAMES *fullname; + STACK_OF(X509_NAME_ENTRY) *relativename; +} name; +} DIST_POINT_NAME; + +typedef struct DIST_POINT_st { +DIST_POINT_NAME *distpoint; +ASN1_BIT_STRING *reasons; +GENERAL_NAMES *CRLissuer; +} DIST_POINT; + +typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; + +DECLARE_STACK_OF(DIST_POINT) +DECLARE_ASN1_SET_OF(DIST_POINT) + +typedef struct AUTHORITY_KEYID_st { +ASN1_OCTET_STRING *keyid; +GENERAL_NAMES *issuer; +ASN1_INTEGER *serial; +} AUTHORITY_KEYID; + +/* Strong extranet structures */ + +typedef struct SXNET_ID_st { + ASN1_INTEGER *zone; + ASN1_OCTET_STRING *user; +} SXNETID; + +DECLARE_STACK_OF(SXNETID) +DECLARE_ASN1_SET_OF(SXNETID) + +typedef struct SXNET_st { + ASN1_INTEGER *version; + STACK_OF(SXNETID) *ids; +} SXNET; + +typedef struct NOTICEREF_st { + ASN1_STRING *organization; + STACK_OF(ASN1_INTEGER) *noticenos; +} NOTICEREF; + +typedef struct USERNOTICE_st { + NOTICEREF *noticeref; + ASN1_STRING *exptext; +} USERNOTICE; + +typedef struct POLICYQUALINFO_st { + ASN1_OBJECT *pqualid; + union { + ASN1_IA5STRING *cpsuri; + USERNOTICE *usernotice; + ASN1_TYPE *other; + } d; +} POLICYQUALINFO; + +DECLARE_STACK_OF(POLICYQUALINFO) +DECLARE_ASN1_SET_OF(POLICYQUALINFO) + +typedef struct POLICYINFO_st { + ASN1_OBJECT *policyid; + STACK_OF(POLICYQUALINFO) *qualifiers; +} POLICYINFO; + +typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; + +DECLARE_STACK_OF(POLICYINFO) +DECLARE_ASN1_SET_OF(POLICYINFO) + +typedef struct POLICY_MAPPING_st { + ASN1_OBJECT *issuerDomainPolicy; + ASN1_OBJECT *subjectDomainPolicy; +} POLICY_MAPPING; + +DECLARE_STACK_OF(POLICY_MAPPING) + +typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; + +typedef struct GENERAL_SUBTREE_st { + GENERAL_NAME *base; + ASN1_INTEGER *minimum; + ASN1_INTEGER *maximum; +} GENERAL_SUBTREE; + +DECLARE_STACK_OF(GENERAL_SUBTREE) + +typedef struct NAME_CONSTRAINTS_st { + STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; + STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; +} NAME_CONSTRAINTS; + +typedef struct POLICY_CONSTRAINTS_st { + ASN1_INTEGER *requireExplicitPolicy; + ASN1_INTEGER *inhibitPolicyMapping; +} POLICY_CONSTRAINTS; + +/* Proxy certificate structures, see RFC 3820 */ +typedef struct PROXY_POLICY_st + { + ASN1_OBJECT *policyLanguage; + ASN1_OCTET_STRING *policy; + } PROXY_POLICY; + +typedef struct PROXY_CERT_INFO_EXTENSION_st + { + ASN1_INTEGER *pcPathLengthConstraint; + PROXY_POLICY *proxyPolicy; + } PROXY_CERT_INFO_EXTENSION; + +DECLARE_ASN1_FUNCTIONS(PROXY_POLICY) +DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) + + +#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \ +",name:", val->name, ",value:", val->value); + +#define X509V3_set_ctx_test(ctx) \ + X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST) +#define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; + +#define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ + 0,0,0,0, \ + 0,0, \ + (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ + (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ + NULL, NULL, \ + table} + +#define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ + 0,0,0,0, \ + (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ + 0,0,0,0, \ + NULL} + +#define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + + +/* X509_PURPOSE stuff */ + +#define EXFLAG_BCONS 0x1 +#define EXFLAG_KUSAGE 0x2 +#define EXFLAG_XKUSAGE 0x4 +#define EXFLAG_NSCERT 0x8 + +#define EXFLAG_CA 0x10 +/* Really self issued not necessarily self signed */ +#define EXFLAG_SI 0x20 +#define EXFLAG_SS 0x20 +#define EXFLAG_V1 0x40 +#define EXFLAG_INVALID 0x80 +#define EXFLAG_SET 0x100 +#define EXFLAG_CRITICAL 0x200 +#define EXFLAG_PROXY 0x400 + +#define EXFLAG_INVALID_POLICY 0x800 + +#define KU_DIGITAL_SIGNATURE 0x0080 +#define KU_NON_REPUDIATION 0x0040 +#define KU_KEY_ENCIPHERMENT 0x0020 +#define KU_DATA_ENCIPHERMENT 0x0010 +#define KU_KEY_AGREEMENT 0x0008 +#define KU_KEY_CERT_SIGN 0x0004 +#define KU_CRL_SIGN 0x0002 +#define KU_ENCIPHER_ONLY 0x0001 +#define KU_DECIPHER_ONLY 0x8000 + +#define NS_SSL_CLIENT 0x80 +#define NS_SSL_SERVER 0x40 +#define NS_SMIME 0x20 +#define NS_OBJSIGN 0x10 +#define NS_SSL_CA 0x04 +#define NS_SMIME_CA 0x02 +#define NS_OBJSIGN_CA 0x01 +#define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA) + +#define XKU_SSL_SERVER 0x1 +#define XKU_SSL_CLIENT 0x2 +#define XKU_SMIME 0x4 +#define XKU_CODE_SIGN 0x8 +#define XKU_SGC 0x10 +#define XKU_OCSP_SIGN 0x20 +#define XKU_TIMESTAMP 0x40 +#define XKU_DVCS 0x80 + +#define X509_PURPOSE_DYNAMIC 0x1 +#define X509_PURPOSE_DYNAMIC_NAME 0x2 + +typedef struct x509_purpose_st { + int purpose; + int trust; /* Default trust ID */ + int flags; + int (*check_purpose)(const struct x509_purpose_st *, + const X509 *, int); + char *name; + char *sname; + void *usr_data; +} X509_PURPOSE; + +#define X509_PURPOSE_SSL_CLIENT 1 +#define X509_PURPOSE_SSL_SERVER 2 +#define X509_PURPOSE_NS_SSL_SERVER 3 +#define X509_PURPOSE_SMIME_SIGN 4 +#define X509_PURPOSE_SMIME_ENCRYPT 5 +#define X509_PURPOSE_CRL_SIGN 6 +#define X509_PURPOSE_ANY 7 +#define X509_PURPOSE_OCSP_HELPER 8 + +#define X509_PURPOSE_MIN 1 +#define X509_PURPOSE_MAX 8 + +/* Flags for X509V3_EXT_print() */ + +#define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) +/* Return error for unknown extensions */ +#define X509V3_EXT_DEFAULT 0 +/* Print error for unknown extensions */ +#define X509V3_EXT_ERROR_UNKNOWN (1L << 16) +/* ASN1 parse unknown extensions */ +#define X509V3_EXT_PARSE_UNKNOWN (2L << 16) +/* BIO_dump unknown extensions */ +#define X509V3_EXT_DUMP_UNKNOWN (3L << 16) + +/* Flags for X509V3_add1_i2d */ + +#define X509V3_ADD_OP_MASK 0xfL +#define X509V3_ADD_DEFAULT 0L +#define X509V3_ADD_APPEND 1L +#define X509V3_ADD_REPLACE 2L +#define X509V3_ADD_REPLACE_EXISTING 3L +#define X509V3_ADD_KEEP_EXISTING 4L +#define X509V3_ADD_DELETE 5L +#define X509V3_ADD_SILENT 0x10 + +DECLARE_STACK_OF(X509_PURPOSE) + +DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) + +DECLARE_ASN1_FUNCTIONS(SXNET) +DECLARE_ASN1_FUNCTIONS(SXNETID) + +int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen); +int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen); +int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen); + +ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone); +ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); +ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone); + +DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID) + +DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD) + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) + + +ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); +STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + ASN1_BIT_STRING *bits, + STACK_OF(CONF_VALUE) *extlist); + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret); +int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, + GENERAL_NAMES *gen, STACK_OF(CONF_VALUE) *extlist); +GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + +DECLARE_ASN1_FUNCTIONS(OTHERNAME) +DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) + +char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5); +ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); + +DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) +int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a); + +DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) +DECLARE_ASN1_FUNCTIONS(POLICYINFO) +DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO) +DECLARE_ASN1_FUNCTIONS(USERNOTICE) +DECLARE_ASN1_FUNCTIONS(NOTICEREF) + +DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS) +DECLARE_ASN1_FUNCTIONS(DIST_POINT) +DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME) + +DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) +DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) + +DECLARE_ASN1_ITEM(POLICY_MAPPING) +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) +DECLARE_ASN1_ITEM(POLICY_MAPPINGS) + +DECLARE_ASN1_ITEM(GENERAL_SUBTREE) +DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) + +DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) +DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) + +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) +DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) + +#ifdef HEADER_CONF_H +GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, + CONF_VALUE *cnf); +GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc); +void X509V3_conf_free(CONF_VALUE *val); + +X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value); +X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name, char *value); +int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section, STACK_OF(X509_EXTENSION) **sk); +int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509 *cert); +int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_REQ *req); +int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl); + +X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value); +X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value); +int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert); +int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req); +int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl); + +int X509V3_add_value_bool_nf(char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool); +int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint); +void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf); +void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash); +#endif + +char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section); +STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section); +void X509V3_string_free(X509V3_CTX *ctx, char *str); +void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); +void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, + X509_REQ *req, X509_CRL *crl, int flags); + +int X509V3_add_value(const char *name, const char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_uchar(const char *name, const unsigned char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_bool(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, + STACK_OF(CONF_VALUE) **extlist); +char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint); +ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value); +char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); +char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); +int X509V3_EXT_add(X509V3_EXT_METHOD *ext); +int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); +int X509V3_EXT_add_alias(int nid_to, int nid_from); +void X509V3_EXT_cleanup(void); + +X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext); +X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); +int X509V3_add_standard_extensions(void); +STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); +void *X509V3_EXT_d2i(X509_EXTENSION *ext); +void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx); + + +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); +int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags); + +char *hex_to_string(unsigned char *buffer, long len); +unsigned char *string_to_hex(char *str, long *len); +int name_cmp(const char *name, const char *cmp); + +void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, + int ml); +int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent); +int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); + +int X509V3_extensions_print(BIO *out, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent); + +int X509_check_ca(X509 *x); +int X509_check_purpose(X509 *x, int id, int ca); +int X509_supported_extension(X509_EXTENSION *ex); +int X509_PURPOSE_set(int *p, int purpose); +int X509_check_issued(X509 *issuer, X509 *subject); +int X509_PURPOSE_get_count(void); +X509_PURPOSE * X509_PURPOSE_get0(int idx); +int X509_PURPOSE_get_by_sname(char *sname); +int X509_PURPOSE_get_by_id(int id); +int X509_PURPOSE_add(int id, int trust, int flags, + int (*ck)(const X509_PURPOSE *, const X509 *, int), + char *name, char *sname, void *arg); +char *X509_PURPOSE_get0_name(X509_PURPOSE *xp); +char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp); +int X509_PURPOSE_get_trust(X509_PURPOSE *xp); +void X509_PURPOSE_cleanup(void); +int X509_PURPOSE_get_id(X509_PURPOSE *); + +STACK *X509_get1_email(X509 *x); +STACK *X509_REQ_get1_email(X509_REQ *x); +void X509_email_free(STACK *sk); +STACK *X509_get1_ocsp(X509 *x); + +ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); +ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); +int a2i_ipadd(unsigned char *ipout, const char *ipasc); +int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk, + unsigned long chtype); + +void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); + +#ifndef OPENSSL_NO_RFC3779 + +typedef struct ASRange_st { + ASN1_INTEGER *min, *max; +} ASRange; + +#define ASIdOrRange_id 0 +#define ASIdOrRange_range 1 + +typedef struct ASIdOrRange_st { + int type; + union { + ASN1_INTEGER *id; + ASRange *range; + } u; +} ASIdOrRange; + +typedef STACK_OF(ASIdOrRange) ASIdOrRanges; +DECLARE_STACK_OF(ASIdOrRange) + +#define ASIdentifierChoice_inherit 0 +#define ASIdentifierChoice_asIdsOrRanges 1 + +typedef struct ASIdentifierChoice_st { + int type; + union { + ASN1_NULL *inherit; + ASIdOrRanges *asIdsOrRanges; + } u; +} ASIdentifierChoice; + +typedef struct ASIdentifiers_st { + ASIdentifierChoice *asnum, *rdi; +} ASIdentifiers; + +DECLARE_ASN1_FUNCTIONS(ASRange) +DECLARE_ASN1_FUNCTIONS(ASIdOrRange) +DECLARE_ASN1_FUNCTIONS(ASIdentifierChoice) +DECLARE_ASN1_FUNCTIONS(ASIdentifiers) + + +typedef struct IPAddressRange_st { + ASN1_BIT_STRING *min, *max; +} IPAddressRange; + +#define IPAddressOrRange_addressPrefix 0 +#define IPAddressOrRange_addressRange 1 + +typedef struct IPAddressOrRange_st { + int type; + union { + ASN1_BIT_STRING *addressPrefix; + IPAddressRange *addressRange; + } u; +} IPAddressOrRange; + +typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; +DECLARE_STACK_OF(IPAddressOrRange) + +#define IPAddressChoice_inherit 0 +#define IPAddressChoice_addressesOrRanges 1 + +typedef struct IPAddressChoice_st { + int type; + union { + ASN1_NULL *inherit; + IPAddressOrRanges *addressesOrRanges; + } u; +} IPAddressChoice; + +typedef struct IPAddressFamily_st { + ASN1_OCTET_STRING *addressFamily; + IPAddressChoice *ipAddressChoice; +} IPAddressFamily; + +typedef STACK_OF(IPAddressFamily) IPAddrBlocks; +DECLARE_STACK_OF(IPAddressFamily) + +DECLARE_ASN1_FUNCTIONS(IPAddressRange) +DECLARE_ASN1_FUNCTIONS(IPAddressOrRange) +DECLARE_ASN1_FUNCTIONS(IPAddressChoice) +DECLARE_ASN1_FUNCTIONS(IPAddressFamily) + +/* + * API tag for elements of the ASIdentifer SEQUENCE. + */ +#define V3_ASID_ASNUM 0 +#define V3_ASID_RDI 1 + +/* + * AFI values, assigned by IANA. It'd be nice to make the AFI + * handling code totally generic, but there are too many little things + * that would need to be defined for other address families for it to + * be worth the trouble. + */ +#define IANA_AFI_IPV4 1 +#define IANA_AFI_IPV6 2 + +/* + * Utilities to construct and extract values from RFC3779 extensions, + * since some of the encodings (particularly for IP address prefixes + * and ranges) are a bit tedious to work with directly. + */ +int v3_asid_add_inherit(ASIdentifiers *asid, int which); +int v3_asid_add_id_or_range(ASIdentifiers *asid, int which, + ASN1_INTEGER *min, ASN1_INTEGER *max); +int v3_addr_add_inherit(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi); +int v3_addr_add_prefix(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *a, const int prefixlen); +int v3_addr_add_range(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *min, unsigned char *max); +unsigned v3_addr_get_afi(const IPAddressFamily *f); +int v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, + unsigned char *min, unsigned char *max, + const int length); + +/* + * Canonical forms. + */ +int v3_asid_is_canonical(ASIdentifiers *asid); +int v3_addr_is_canonical(IPAddrBlocks *addr); +int v3_asid_canonize(ASIdentifiers *asid); +int v3_addr_canonize(IPAddrBlocks *addr); + +/* + * Tests for inheritance and containment. + */ +int v3_asid_inherits(ASIdentifiers *asid); +int v3_addr_inherits(IPAddrBlocks *addr); +int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b); +int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b); + +/* + * Check whether RFC 3779 extensions nest properly in chains. + */ +int v3_asid_validate_path(X509_STORE_CTX *); +int v3_addr_validate_path(X509_STORE_CTX *); +int v3_asid_validate_resource_set(STACK_OF(X509) *chain, + ASIdentifiers *ext, + int allow_inheritance); +int v3_addr_validate_resource_set(STACK_OF(X509) *chain, + IPAddrBlocks *ext, + int allow_inheritance); + +#endif /* OPENSSL_NO_RFC3779 */ + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_X509V3_strings(void); + +/* Error codes for the X509V3 functions. */ + +/* Function codes. */ +#define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE 156 +#define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL 157 +#define X509V3_F_COPY_EMAIL 122 +#define X509V3_F_COPY_ISSUER 123 +#define X509V3_F_DO_DIRNAME 144 +#define X509V3_F_DO_EXT_CONF 124 +#define X509V3_F_DO_EXT_I2D 135 +#define X509V3_F_DO_EXT_NCONF 151 +#define X509V3_F_DO_I2V_NAME_CONSTRAINTS 148 +#define X509V3_F_HEX_TO_STRING 111 +#define X509V3_F_I2S_ASN1_ENUMERATED 121 +#define X509V3_F_I2S_ASN1_IA5STRING 149 +#define X509V3_F_I2S_ASN1_INTEGER 120 +#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138 +#define X509V3_F_NOTICE_SECTION 132 +#define X509V3_F_NREF_NOS 133 +#define X509V3_F_POLICY_SECTION 131 +#define X509V3_F_PROCESS_PCI_VALUE 150 +#define X509V3_F_R2I_CERTPOL 130 +#define X509V3_F_R2I_PCI 155 +#define X509V3_F_S2I_ASN1_IA5STRING 100 +#define X509V3_F_S2I_ASN1_INTEGER 108 +#define X509V3_F_S2I_ASN1_OCTET_STRING 112 +#define X509V3_F_S2I_ASN1_SKEY_ID 114 +#define X509V3_F_S2I_SKEY_ID 115 +#define X509V3_F_STRING_TO_HEX 113 +#define X509V3_F_SXNET_ADD_ID_ASC 125 +#define X509V3_F_SXNET_ADD_ID_INTEGER 126 +#define X509V3_F_SXNET_ADD_ID_ULONG 127 +#define X509V3_F_SXNET_GET_ID_ASC 128 +#define X509V3_F_SXNET_GET_ID_ULONG 129 +#define X509V3_F_V2I_ASIDENTIFIERS 158 +#define X509V3_F_V2I_ASN1_BIT_STRING 101 +#define X509V3_F_V2I_AUTHORITY_INFO_ACCESS 139 +#define X509V3_F_V2I_AUTHORITY_KEYID 119 +#define X509V3_F_V2I_BASIC_CONSTRAINTS 102 +#define X509V3_F_V2I_CRLD 134 +#define X509V3_F_V2I_EXTENDED_KEY_USAGE 103 +#define X509V3_F_V2I_GENERAL_NAMES 118 +#define X509V3_F_V2I_GENERAL_NAME_EX 117 +#define X509V3_F_V2I_IPADDRBLOCKS 159 +#define X509V3_F_V2I_ISSUER_ALT 153 +#define X509V3_F_V2I_NAME_CONSTRAINTS 147 +#define X509V3_F_V2I_POLICY_CONSTRAINTS 146 +#define X509V3_F_V2I_POLICY_MAPPINGS 145 +#define X509V3_F_V2I_SUBJECT_ALT 154 +#define X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL 160 +#define X509V3_F_V3_GENERIC_EXTENSION 116 +#define X509V3_F_X509V3_ADD1_I2D 140 +#define X509V3_F_X509V3_ADD_VALUE 105 +#define X509V3_F_X509V3_EXT_ADD 104 +#define X509V3_F_X509V3_EXT_ADD_ALIAS 106 +#define X509V3_F_X509V3_EXT_CONF 107 +#define X509V3_F_X509V3_EXT_I2D 136 +#define X509V3_F_X509V3_EXT_NCONF 152 +#define X509V3_F_X509V3_GET_SECTION 142 +#define X509V3_F_X509V3_GET_STRING 143 +#define X509V3_F_X509V3_GET_VALUE_BOOL 110 +#define X509V3_F_X509V3_PARSE_LIST 109 +#define X509V3_F_X509_PURPOSE_ADD 137 +#define X509V3_F_X509_PURPOSE_SET 141 + +/* Reason codes. */ +#define X509V3_R_BAD_IP_ADDRESS 118 +#define X509V3_R_BAD_OBJECT 119 +#define X509V3_R_BN_DEC2BN_ERROR 100 +#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101 +#define X509V3_R_DIRNAME_ERROR 149 +#define X509V3_R_DUPLICATE_ZONE_ID 133 +#define X509V3_R_ERROR_CONVERTING_ZONE 131 +#define X509V3_R_ERROR_CREATING_EXTENSION 144 +#define X509V3_R_ERROR_IN_EXTENSION 128 +#define X509V3_R_EXPECTED_A_SECTION_NAME 137 +#define X509V3_R_EXTENSION_EXISTS 145 +#define X509V3_R_EXTENSION_NAME_ERROR 115 +#define X509V3_R_EXTENSION_NOT_FOUND 102 +#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103 +#define X509V3_R_EXTENSION_VALUE_ERROR 116 +#define X509V3_R_ILLEGAL_EMPTY_EXTENSION 151 +#define X509V3_R_ILLEGAL_HEX_DIGIT 113 +#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 152 +#define X509V3_R_INVALID_ASNUMBER 160 +#define X509V3_R_INVALID_ASRANGE 161 +#define X509V3_R_INVALID_BOOLEAN_STRING 104 +#define X509V3_R_INVALID_EXTENSION_STRING 105 +#define X509V3_R_INVALID_INHERITANCE 162 +#define X509V3_R_INVALID_IPADDRESS 163 +#define X509V3_R_INVALID_NAME 106 +#define X509V3_R_INVALID_NULL_ARGUMENT 107 +#define X509V3_R_INVALID_NULL_NAME 108 +#define X509V3_R_INVALID_NULL_VALUE 109 +#define X509V3_R_INVALID_NUMBER 140 +#define X509V3_R_INVALID_NUMBERS 141 +#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110 +#define X509V3_R_INVALID_OPTION 138 +#define X509V3_R_INVALID_POLICY_IDENTIFIER 134 +#define X509V3_R_INVALID_PROXY_POLICY_SETTING 153 +#define X509V3_R_INVALID_PURPOSE 146 +#define X509V3_R_INVALID_SAFI 164 +#define X509V3_R_INVALID_SECTION 135 +#define X509V3_R_INVALID_SYNTAX 143 +#define X509V3_R_ISSUER_DECODE_ERROR 126 +#define X509V3_R_MISSING_VALUE 124 +#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142 +#define X509V3_R_NO_CONFIG_DATABASE 136 +#define X509V3_R_NO_ISSUER_CERTIFICATE 121 +#define X509V3_R_NO_ISSUER_DETAILS 127 +#define X509V3_R_NO_POLICY_IDENTIFIER 139 +#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 154 +#define X509V3_R_NO_PUBLIC_KEY 114 +#define X509V3_R_NO_SUBJECT_DETAILS 125 +#define X509V3_R_ODD_NUMBER_OF_DIGITS 112 +#define X509V3_R_OPERATION_NOT_DEFINED 148 +#define X509V3_R_OTHERNAME_ERROR 147 +#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED 155 +#define X509V3_R_POLICY_PATH_LENGTH 156 +#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED 157 +#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED 158 +#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159 +#define X509V3_R_SECTION_NOT_FOUND 150 +#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122 +#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123 +#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111 +#define X509V3_R_UNKNOWN_EXTENSION 129 +#define X509V3_R_UNKNOWN_EXTENSION_NAME 130 +#define X509V3_R_UNKNOWN_OPTION 120 +#define X509V3_R_UNSUPPORTED_OPTION 117 +#define X509V3_R_USER_TOO_LONG 132 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/other/GetMacAddress.h b/石器时代8.5客户端最新源代码/石器源码/other/GetMacAddress.h new file mode 100644 index 0000000..0488fe6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/GetMacAddress.h @@ -0,0 +1,12 @@ +#ifndef _GETMACADDRESS +#define _GETMACADDRESS + +typedef struct MAC_ADDR_t +{ + unsigned char addr[6]; +}MAC_ADDR; + +extern int GetMACaddress(MAC_ADDR *MacAddr,int MaxGetCount); +extern void PrintMACaddress(unsigned char MACData[]); + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.cpp b/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.cpp new file mode 100644 index 0000000..b7f56ca --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.cpp @@ -0,0 +1,298 @@ +#include ".\itemsmall.h" +#include "..\systeminc\tool.h" +#include + +//int ItemsMall::m_nAllLatestNum = 0; +//int ItemsMall::m_nAllItemsNum = 0; +//int ItemsMall::m_nAllPetsNum = 0; +//int ItemsMall::m_nAllOthersNum = 0; + +ItemsMall* ItemsMall::instance = NULL; +std::map ItemsMall::g_mapItemsMall; + +ItemsMall& ItemsMall::MakeInstance() +{ + if (instance == NULL) + { + instance = new ItemsMall; + } + + return *instance; +} + +void ItemsMall::Destroy() +{ + if (instance != NULL) + { + delete instance; + instance = NULL; + } +} + +void ItemsMall::SetItemDatas(char* pszData) +{ + if (pszData[0] == '#') //ע + { + return ; + } + + for (int i = 0; i < (int)strlen(pszData); i++) + { + if (pszData[i] == '#') + { + pszData[i] = '\0'; + break; + } + } + + ITEMSMALL item; + char szToken[64]; + + item.id = getIntegerToken(pszData, ',', 1); + item.itemId = getIntegerToken(pszData, ',', 2); + + int debug; + if (item.id == 200) + { + debug = 0; + } + + memset(szToken, 0, sizeof(szToken)); + getStringToken(pszData, ',', 3, sizeof(szToken) - 1, szToken); + strcpy(item.itemName, szToken); + + item.itemFlag = getIntegerToken(pszData, ',', 4); + item.bmpNo = getIntegerToken(pszData, ',', 5); + + item.currencyType = getIntegerToken(pszData, ',', 6); + + item.currencyNum = getIntegerToken(pszData, ',', 7); + item.recordType = getIntegerToken(pszData, ',', 8); + + char szLine1[128]; + char szLine2[128]; + char szLine3[128]; + memset(szLine1, 0, sizeof(szLine1)); + memset(szLine2, 0, sizeof(szLine2)); + memset(szLine3, 0, sizeof(szLine3)); + + memset(szToken, 0, sizeof(szToken)); + getStringToken(pszData, ',', 9, sizeof(szToken) - 1, szToken); + + getStringToken(szToken, '|', 1, sizeof(szLine1) - 1, szLine1); + strcpy(item.szLine1, szLine1); + + getStringToken(szToken, '|', 2, sizeof(szLine2) - 1, szLine2); + strcpy(item.szLine2, szLine2); + + getStringToken(szToken, '|', 3, sizeof(szLine3) - 1, szLine3); + strcpy(item.szLine3, szLine3); + + g_mapItemsMall.insert(std::make_pair(item.id, item)); + //OutputDebugStr(pszData); + //if (item.recordType == 1) + //{ + // ++m_nAllLatestNum; //ϼ + //} + // + //if (item.itemFlag == 1) + //{ + // ++m_nAllItemsNum; //װƷ + //} + // + //if (item.itemFlag == 2) + //{ + // ++m_nAllPetsNum; //Ʒ + //} + // + //if (item.recordType == 4) + //{ + // ++m_nAllOthersNum; //Ʒ + //} +} + +int ItemsMall::GetItemsNums() +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (iter->second.itemFlag == 1) //װ + { + ++nNums; + } + } + + return nNums; +} + +int ItemsMall::GetPetsNums() +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (iter->second.itemFlag == 2) // + { + ++nNums; + } + } + + return nNums; +} + +ITEMSMALL* ItemsMall::GetItemByIndex(int nIndex) +{ + if (nIndex >= 0 && nIndex <= GetAllItemSize()) + { + return &g_mapItemsMall[nIndex]; + } + + return NULL; +} + +ITEMSMALL* ItemsMall::GetItemByType(int nIndex, int nType, int recordType) +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (nType == iter->second.currencyType && recordType == iter->second.recordType) + { + if (nNums == nIndex) + { + return &(iter->second); + } + + ++nNums; + } + } + + return NULL; +} + +ITEMSMALL* ItemsMall::GetAllItemsByIndex(int nIndex, int nType) +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (nType == iter->second.currencyType && 1 == iter->second.itemFlag) //ITEM + { + if (nNums == nIndex) + { + return &(iter->second); + } + + ++nNums; + } + } + + return NULL; +} + +ITEMSMALL* ItemsMall::GetAllPetsByIndex(int nIndex, int nType) +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (nType == iter->second.currencyType && 2 == iter->second.itemFlag) //PET + { + if (nNums == nIndex) + { + return &(iter->second); + } + + ++nNums; + } + } + + return NULL; +} + +ITEMSMALL* ItemsMall::GetAllOtherItemsByIndex(int nIndex, int nType) +{ + int nNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + for (; iter != g_mapItemsMall.end(); iter++) + { + if (nType == iter->second.currencyType && 3 == iter->second.itemFlag) //Ʒ + { + if (nNums == nIndex) + { + return &(iter->second); + } + + ++nNums; + } + } + + return NULL; +} + +int ItemsMall::GetCurrentItemNum(int nCurrencyType, int nType) +{ + int nItemNums = 0; + std::map::iterator iter = g_mapItemsMall.begin(); + if (nType == 1) //ϼܻƷ + { + for (; iter != g_mapItemsMall.end(); iter++) + { + if (iter->second.currencyType == nCurrencyType && iter->second.recordType == nType) + { + ++nItemNums; + } + } + } + else/* if (nType == 2 || nType == 3) */ //װƷ߳ƷƷ + { + int nFlag = -1; + if (nType == 2) + { + nFlag = 1; //װ + } + else if (nType == 3) + { + nFlag = 2; // + } + else if (nType == 4) //Ʒ + { + nFlag = 3; + } + + for (; iter != g_mapItemsMall.end(); iter++) + { + if (iter->second.currencyType == nCurrencyType && iter->second.itemFlag == nFlag) + { + //char szTest[256]; + //memset(szTest, 0, sizeof(szTest)); + //sprintf_s(szTest, "\nname = %s", iter->second.itemName); + //OutputDebugStr(szTest); + ++nItemNums; + } + } + } + + return nItemNums; +} + +//int ItemsMall::GetAllLatestNum() //ϼۻƷ +//{ +// return m_nAllLatestNum; +//} +// +//int ItemsMall::GetAllItemsNum() //װƷ +//{ +// return m_nAllItemsNum; +//} +// +//int ItemsMall::GetAllPetsNum() //Ʒ +//{ +// return m_nAllPetsNum; +//} +// +//int ItemsMall::GetAllOthersNum() //Ʒ +//{ +// return m_nAllOthersNum; +//} diff --git a/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.h b/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.h new file mode 100644 index 0000000..37a2188 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/ItemsMall.h @@ -0,0 +1,66 @@ +#ifndef _ITEMS_MALL_H__ +#define _ITEMS_MALL_H__ + +#include + + +#define ITEMS_MALL_FILE_NAME "shopsellitems.bin" + + +typedef struct ITEMSMALL +{ + int id; //id + int itemId; //Ʒ/ID + char itemName[128]; //Ʒ/ + int itemFlag; //ƷdzƷΪ1Ϊ2 + int bmpNo; ///ƷͼƬ + int currencyType; //ЩƷĻ + int currencyNum; //ƷĽô˻ҹֶΪ-1 + int recordType; //Ʒࣺ1ʾϼۣ4ʾƷ + char szLine1[128]; + char szLine2[128]; + char szLine3[128]; +}*LP_ITEMSMALL; + +//̳زʾ +class ItemsMall +{ +public: + static ItemsMall& MakeInstance(); + static void Destroy(); + + void SetItemDatas(char* pszData); + + int GetItemsNums(); + int GetPetsNums(); + int GetAllItemSize() { return g_mapItemsMall.size(); } + + ITEMSMALL* GetItemByIndex(int nIndex); + ITEMSMALL* GetItemByType(int nIndex, int nType, int recordType = 1); //recodTypeĬֵΪ1ʾϼƷ4ΪƷ + ITEMSMALL* GetAllItemsByIndex(int nIndex, int nType); + ITEMSMALL* GetAllPetsByIndex(int nIndex, int nType); + ITEMSMALL* GetAllOtherItemsByIndex(int nIndex, int nType); + + int GetCurrentItemNum(int nCurrencyType, int nType); + + //int GetAllLatestNum(); //ϼۻƷ + //int GetAllItemsNum(); //װƷ + //int GetAllPetsNum(); //Ʒ + //int GetAllOthersNum(); //Ʒ + +protected: + ItemsMall(void){} + ItemsMall(ItemsMall&); + + ~ItemsMall(void){} + + static ItemsMall* instance; + static std::map g_mapItemsMall; + + //static int m_nAllLatestNum; + //static int m_nAllItemsNum; + //static int m_nAllPetsNum; + //static int m_nAllOthersNum; +}; + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.cpp b/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.cpp new file mode 100644 index 0000000..71feeb4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.cpp @@ -0,0 +1,131 @@ +#include "../systeminc/version.h" +#ifdef _PTTERN_SEPARATION_BIN +#include +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/unpack.h" +#include "../systeminc/sprmgr.h" +#include "../systeminc/anim_tbl.h" +#include "PtternSeparationBin.h" +#include "../wgs\tea.h" +#include "../systeminc\VMProtectSDK.h" +extern ADRNBIN adrnbuff[MAX_GRAPHICS]; +extern unsigned long bitmapnumbertable[MAX_GRAPHICS]; +extern SPRITEDATA SpriteData[mxSPRITE]; + +//cary 2001 07 10 +extern FILE *Realbinfp[MAX_GRAPHICS]; +int MaxAdrnID = 0; +void InitPteernSeparationBin(LPCTSTR lpszPath) +{ + + TCHAR szFind[MAX_PATH]; + lstrcpy(szFind, lpszPath); + lstrcat(szFind, "\\"); + lstrcat(szFind, "*.*"); // ļ + WIN32_FIND_DATA wfd; + HANDLE hFind = FindFirstFile(szFind, &wfd); + if (hFind == INVALID_HANDLE_VALUE) // ûҵʧ + return; + int index = 2; + do + { + if (wfd.cFileName[0] == '.') + continue; // Ŀ¼ + if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + TCHAR szFile[MAX_PATH]; + TCHAR szFindAdrnName[MAX_PATH]; + TCHAR szFindRealName[MAX_PATH]; + TCHAR szFindSprAdrnName[MAX_PATH]; + TCHAR szFindSprName[MAX_PATH]; + + + char FilePath[200]; + GetCurrentDirectory(200,FilePath); + wsprintf(szFile, "%s//%s", FilePath, lpszPath); + wsprintf(szFile, "%s//%s", lpszPath, wfd.cFileName); +#ifdef _SA_VERSION_25 + wsprintf(szFindAdrnName, "%s//adrn.es", szFile); + wsprintf(szFindRealName, "%s//real.es", szFile); +#endif + + if(AdrnInit(szFindAdrnName, szFindRealName, index)==TRUE){ +#ifdef _SA_VERSION_25 + wsprintf(szFindSprAdrnName, "%s//spradrn.es", szFile); + wsprintf(szFindSprName, "%s//spr.es", szFile); +#endif + + extern BOOL InitSprBinFileOpen( char *SPR_BIN, char *SPRADRN_BIN ); + InitSprBinFileOpen(szFindSprName,szFindSprAdrnName); + index++; + if(index>100)break; + } + InitPteernSeparationBin(szFile); // ҵĿ¼Ŀ¼еݹ + } + else + { + + } + } while (FindNextFile(hFind, &wfd)); + FindClose(hFind); // رղҾ + +} +int nextMaxAdrnID=0; +BOOL AdrnInit(LPCTSTR strAdrnFileName, LPCTSTR strRealFileName, int index) +{ + + ADRNBIN tmpadrnbuff; + FILE *Realfp, *Addrbinfp; + nextMaxAdrnID = MaxAdrnID; + int maxid = MaxAdrnID; + if (fopen_s(&Addrbinfp,strAdrnFileName, "rb")){ + return FALSE; + } + if(fopen_s(&Realfp, strRealFileName, "rb")){ + return FALSE; + } +#ifdef _BUDING_ + extern int getfilesize(FILE* fp); + int size = getfilesize(Addrbinfp); + char * sadrnbin = (char*)malloc(size); + fread(sadrnbin,1,size,Addrbinfp); + TEA((long*)sadrnbin,(size/4),(long *)_BUDING_); + int i=0; + for(i;i 1500 +#endif + ){ + bitmapnumbertable[tmpadrnbuff.attr.bmpnumber] = tmpadrnbuff.bitmapno + maxid; + } + } + fclose(Addrbinfp); + free(sadrnbin); +#else + while(!feof(Addrbinfp)){ + fread(&tmpadrnbuff, sizeof(tmpadrnbuff), 1, Addrbinfp); + adrnbuff[tmpadrnbuff.bitmapno + maxid] = tmpadrnbuff; + Realbinfp[tmpadrnbuff.bitmapno + maxid] = Realfp; + if((ULONG)MaxAdrnID < tmpadrnbuff.bitmapno + maxid){ + MaxAdrnID = tmpadrnbuff.bitmapno + maxid; + } + if( tmpadrnbuff.attr.bmpnumber != 0 ){ + bitmapnumbertable[tmpadrnbuff.attr.bmpnumber] = tmpadrnbuff.bitmapno + maxid; + } + } + fclose(Addrbinfp); +#endif + return TRUE; +} + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.h b/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.h new file mode 100644 index 0000000..5b8cffd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/PtternSeparationBin.h @@ -0,0 +1,6 @@ +#ifndef _PTTERN_SEPARATION_BIN_H_ +#define _PTTERN_SEPARATION_BIN_H_ +BOOL AdrnInit(LPCTSTR strAdrnFileName, LPCTSTR strRealFileName, int index); +BOOL SprInit(LPCTSTR strSprAdrnFileName, LPCTSTR strSprFileName, int index); +void InitPteernSeparationBin(LPCTSTR lpszPath) ; +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/anim_tbl_set.h b/石器时代8.5客户端最新源代码/石器源码/other/anim_tbl_set.h new file mode 100644 index 0000000..3699a8a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/anim_tbl_set.h @@ -0,0 +1,78 @@ +#ifndef _ANIM_TBL_SET_H_ +#define _ANIM_TBL_SET_H_ + +extern int CG_PKSERVER_PANEL; +extern int CG_BATTTLE_SKILLCHOICE; +extern int CG_FIELD_SKILL_PANEL; +extern int CG_FIELD_CHATROOM_PANEL; +extern int CG_FIELD_SV_SELL_PANEL; +extern int CG_FIELD_SV_SELL_PRICE_PANEL; +extern int CG_NEW_STATUS_WND; +extern int CG_NEWITEM_WND; +extern int CG_TRADE_WND; +extern int CG_TRADE_VIEWWND; +// ėpEBhE +extern int CG_WND_G_0; +extern int CG_WND_G_1; +extern int CG_WND_G_2; +extern int CG_WND_G_3; +extern int CG_WND_G_4; +extern int CG_WND_G_5; +extern int CG_WND_G_6; +extern int CG_WND_G_7; +extern int CG_WND_G_8; +// ėpEBhEQ +extern int CG_WND2_G_0; +extern int CG_WND2_G_1; +extern int CG_WND2_G_2; +extern int CG_WND2_G_3; +extern int CG_WND2_G_4; +extern int CG_WND2_G_5; +extern int CG_WND2_G_6; +extern int CG_WND2_G_7; +extern int CG_WND2_G_8; +// ėpEBhER +extern int CG_WND3_G_7; +extern int CG_WND3_G_8; +extern int CG_WND3_G_9; +// {EBhE +extern int CG_BTL_PET_CHANGE_WND; +// ybgEBhE +extern int CG_PET_WND_VIEW; +extern int CG_PET_WND_DETAIL; +extern int CG_NAME_CHANGE_WND; +// ACeEBhE +extern int CG_ITEM_WND_1; +extern int CG_JUJUTU_WND; +extern int CG_ITEM_WND_SELECT_WND; +extern int CG_STATUS_WND_GROUP_WND; +// }bvEBhE +extern int CG_MAP_WND; +// Xe[^XEBhE +extern int CG_STATUS_WND; +// [EBhE +extern int CG_MAIL_WND; +extern int CG_MAIL_WND_SEND_WND; +extern int CG_MAIL_WND_PET_SEND_WND; +extern int CG_MAIL_WND_HISTORY_WND; +// AoEBhE +extern int CG_ALBUM_WND; +// `bg̕o^EBhE +extern int CG_CHAT_REGISTY_WND; +// ėpEBhE +extern int CG_COMMON_WIN_YORO; +extern int CG_FIELD_HELP_WND; +// ybg̋ZEBhE +extern int CG_MSG_WND; +extern int CG_PET_WAZA_WND; +// ACeVbvEBhE +extern int CG_ITEMSHOP_WIN; +// ZVbvEBhE +extern int CG_SKILLSHOP_WIN; +// ܂ƂߔEBhE +extern int CG_ITEMSHOP_KOSU_WIN; +extern int CG_FAMILY_DETAIL_WIN; +extern int CG_FAMILY_BANK_WIN; +extern int CG_BM_WND; + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/caryime.h b/石器时代8.5客户端最新源代码/石器源码/other/caryime.h new file mode 100644 index 0000000..272cdbb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/caryime.h @@ -0,0 +1,55 @@ +/****************************************************************************** + caryIme.h: cary's ImeDllMainC + (c) \ʳCary Hsu, 2000.7.10 +******************************************************************************/ +#ifndef __CARYIME +#define __CARYIME + +typedef void(*RESULTCALLBACK)(LPSTR); + +/* IMEl +parameter: hwnd: ҨϥΪHWND + ResultCallback: JkG^ +return: TRUE: Y~Aе{A_hLkϥΤJk*/ +BOOL InitIme(HWND hwnd,RESULTCALLBACK ResultCallback); + +/* IME*/ +void EndIme(); + +/* ܪҦAwindow modefullscreen mode +parameter: bWindowMode: ϥΪҦ */ +void ChangeMode(BOOL bWindowMode); + +/* BzIMEmessage +parameter: Message: T + wParam,lParam:TѼ +return: TRUE: wgBzIMEmessage + FALSE: ٦]messageݭnBz */ +BOOL ImeMessage(UINT Message,WPARAM wParam,LPARAM lParam); + +/* clear IME buffer */ +void ClearIme(); + +/* IMEON,OFFAT{ +return: ON: TRUE + OFF:FALSE */ +BOOL ImeOpenState(); + +/* oJkrAicandiatecompsition +return: NULL: SrAЦۦBz + DNULL: Jkr */ +LPSTR GetImeString(); + +/* oJkyzr +return: Jkyzr */ +LPSTR GetImeDescString(); + +/////////////////////////////////////////////////////////////////////////////// + +/* olpstrW@Ӧr} +parameter: lpstrHead: rꪺY + lpstr: n^W@Ӧrr +return: W@Ӧr} */ +char *GetCharPrev(char *lpstrHead,char *lpstr); + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/getip.cpp b/石器时代8.5客户端最新源代码/石器源码/other/getip.cpp new file mode 100644 index 0000000..b6d96ab --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/getip.cpp @@ -0,0 +1,67 @@ +#include "../systeminc/version.h" + +#ifdef _LOGIP_ +#include +int SendData(SOCKET s, char * data) +{ + return send(s, data, strlen(data), 0); +} + +BOOL ȡIP(char *IP) +{ + WSAData wsaDat; + short int Port = 80; + if(WSAStartup(MAKEWORD(1,1),&wsaDat)) return FALSE; + + SOCKET sd = socket(AF_INET, SOCK_STREAM, 0); + if(sd ==INVALID_SOCKET) return FALSE; + SOCKADDR_IN sockAddr; + memset((void*)&sockAddr,0,sizeof(sockAddr)); + sockAddr.sin_family=AF_INET; + sockAddr.sin_port=htons(Port); + sockAddr.sin_addr.s_addr=inet_addr("115.238.240.61"); + if(connect(sd,(LPSOCKADDR)&sockAddr,sizeof(sockAddr))){ + closesocket(sd); + WSACleanup(); + return FALSE; + } + + SendData(sd, "GET /getip.php HTTP/1.1\r\n"); + SendData(sd, "Host:www.shiqi.hk\r\n"); + SendData(sd, "Accept: */*\r\n"); + SendData(sd, "User-Agent: Mozilla/4.0(compatible; MSIE 5.00; Windows NT)\r\n"); + SendData(sd, "\r\n"); + SendData(sd, "\r\n"); + + char recvstr[1024]; + memset(recvstr,0,1024); + char *p = recvstr; + char* iIndex_Head ; + int iLen = 1024; + while (iLen){ + int iRet = recv(sd,p,iLen,0); + if (iRet <= 0) { + closesocket(sd); + WSACleanup(); + return FALSE; + } + p += iRet; + iLen -= iRet; + if ((iIndex_Head = strstr(recvstr,""))){ + char* iIndex = strstr(recvstr,""); + if (!iIndex) { + continue; + } + char *p1 = iIndex_Head+2; + char *p2 = iIndex; + memcpy(IP,p1,p2-p1); + break; + } + } + closesocket(sd); + WSACleanup(); + return TRUE; +} + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/other/md5_encrypt.cpp b/石器时代8.5客户端最新源代码/石器源码/other/md5_encrypt.cpp new file mode 100644 index 0000000..7cc05b0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/md5_encrypt.cpp @@ -0,0 +1,389 @@ + // Md5A.cpp: implementation of the CMd5 class. +// +////////////////////////////////////////////////////////////////////// + +//#include "stdafx.h" +//#include "Afxwin.h" +#include "md5_encrypt.h" + +#ifdef _STONDEBUG_ +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +void MD5Init (MD5_CTX_ENCRYPT *context) /* context */ +{ + context->count[0] = context->count[1] = 0; + context->state[0] = 0x67452301; /* Load magic initialization constants.*/ + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* ----------------------------------------------------------------------------------- + MD5 block update operation. Continues an MD5 message-digest + operation, processing another message block, and updating the context. +-------------------------------------------------------------------------------------*/ + /* context */ /* input block */ /* length of input block */ +void MD5Update (MD5_CTX_ENCRYPT *context, unsigned char *input,unsigned int inputLen ) +{ + unsigned int i, index, partLen; + index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Compute number of bytes mod 64 */ + + if ( (context->count[0] += ( (UINT4)inputLen << 3) ) < ( (UINT4)inputLen << 3 ) ) + context->count[1]++; + + context->count[1] += ((UINT4)inputLen >> 29); + partLen = 64 - index; + + /* Transform as many times as possible.*/ + if (inputLen >= partLen) + { + MD5_memcpy( (POINTER)&context->buffer[index], (POINTER)input, partLen); + MD5Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + /* Buffer remaining input */ + MD5_memcpy( (POINTER)&context->buffer[index], (POINTER)&input[i],inputLen-i ); +} + +/* + MD5 finalization. Ends an MD5 message-digest operation, writing the + the message digest and zeroizing the context. +*/ +void MD5Final (unsigned char digest[16], MD5_CTX_ENCRYPT *context) + /* message digest */ /* context */ +{ + unsigned char bits[8]; + unsigned int index, padLen; + + Encode (bits, context->count, 8); /* Save number of bits */ + + /* Pad out to 56 mod 64.*/ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD5Update (context,(unsigned char*) PADDING, padLen); + + MD5Update (context, bits, 8); /* Append length (before padding) */ + Encode (digest, context->state, 16); /* Store state in digest */ + + /* Zeroize sensitive information.*/ + MD5_memset ((POINTER)context, 0, sizeof (*context)); +} + +/* MD5 basic transformation. Transforms state based on block. + */ +void MD5Transform (UINT4 state[4],unsigned char block[64]) +{ + int i=0; + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode (x, block, 64); + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + /* Round 2 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + /* Round 3 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + /* Round 4 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information.*/ + MD5_memset ((POINTER)x, 0, sizeof (x)); +} + +/* Encodes input (UINT4) into output (unsigned char). Assumes len is + a multiple of 4. + */ +void Encode (unsigned char *output,UINT4 *input,unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (UINT4). Assumes len is + a multiple of 4. + */ +void Decode (UINT4 *output,unsigned char *input,unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); +} + +/* Note: Replace "for loop" with standard memcpy if possible. */ +void MD5_memcpy (POINTER output,POINTER input,unsigned int len) +{ + unsigned int i; + + for (i = 0; i < len; i++) + output[i] = input[i]; +} + +/* Note: Replace "for loop" with standard memset if possible. */ +void MD5_memset (POINTER output,int value,unsigned int len) +{ + unsigned int i; + + for (i = 0; i < len; i++) + ((char *)output)[i] = (char)value; +} + +/* Digests a string and prints the result. */ +char* MDString (char *string) +{ + MD5_CTX_ENCRYPT context; + unsigned char digest[16]; + char output1[34]; + static char output[35]={"\0"}; + unsigned int len = ( unsigned int )strlen (string); + int i; + MD5Init (&context); + MD5Update (&context, (unsigned char*)string, len); + MD5Final (digest, &context); + + for (i = 0; i < 16; i++) + { + sprintf_s(&(output1[2*i]),34-2*i,"%02x",(unsigned char)digest[i]); + //sprintf_s(&(output1[2*i+1]),"%02x",(unsigned char)(digest[i]<<4)); + } + for(i=0;i<32;i++) + output[i]=output1[i]; + return output; +} + + +/* Digests a file and prints the result. */ +//char* MDFile (CString filename) +//CString MDFile (CString filename) +//{ +// static char output[33]={"\0"}; +// CFile file; +// CString result; +// MD5_CTX_ENCRYPT context; +// int len; +// unsigned char buffer[1024], digest[16]; +// int i; +// char output1[33]; +// //UINT aaa; +// if (file.Open(filename,CFile::modeRead)==0) +// { +// //printf ("%s can't be opened\n", filename); +// AfxMessageBoxNew("open file error"); +// return ""; +// } +// else +// { +// MD5Init (&context); +// while (len = file.Read (buffer, 1024))//, 1024, file)) +// MD5Update (&context, buffer, len); +// MD5Final (digest, &context); +// file.Close(); +// for (i = 0; i < 16; i++) +// { +// sprintf_s(&(output1[2*i]),"%02x",(unsigned char)digest[i]); +// // sprintf_s(&(output1[2*i+1]),"%02x",(unsigned char)(digest[i]<<4)); +// } +// for(i=0;i<32;i++) +// output[i]=output1[i]; +// result = output; +// return result; +// } +//} + +char* hmac_md5(char* text,char* key) +{ + char digest[16]; + char output1[34]; + static char output[35]={"\0"}; + MD5_CTX_ENCRYPT context; + unsigned char k_ipad[65]; /* inner padding - + * key XORd with ipad + */ + unsigned char k_opad[65]; /* outer padding - + * key XORd with opad + */ + unsigned char tk[16]; + int i; + int text_len = strlen (text); + int key_len=strlen(key); + /* if key is longer than 64 bytes reset it to key=MD5(key) */ + if (key_len > 64) + { + MD5_CTX_ENCRYPT tctx; + + MD5Init(&tctx); + MD5Update(&tctx,(unsigned char*) key, key_len); + MD5Final(tk, &tctx); + + key = (char*)tk; + key_len = 16; + } + + /* + * the HMAC_MD5 transform looks like: + * + * MD5(K XOR opad, MD5(K XOR ipad, text)) + * + * where K is an n byte key + * ipad is the byte 0x36 repeated 64 times + * opad is the byte 0x5c repeated 64 times + * and text is the data being protected + */ + + /* start out by storing key in pads */ + + /*bzero( k_ipad, sizeof k_ipad); + bzero( k_opad, sizeof k_opad); + */ + + for(i=0;i<65;i++) + k_ipad[i]=(unsigned char)0; + for(i=0;i<65;i++) + k_opad[i]=(unsigned char)0; + + /*bcopy( key, k_ipad, key_len); + bcopy( key, k_opad, key_len); + */ + for(i=0;i 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include +#include +#include +//#include + +#define MD 5 + +#ifndef PROTOTYPES +#define PROTOTYPES 0 +#endif + +typedef unsigned char *POINTER; /* POINTER defines a generic pointer type */ +typedef unsigned short int UINT2; /* UINT2 defines a two byte word */ +typedef unsigned long int UINT4; /* UINT4 defines a four byte word */ + +/* + PROTO_LIST is defined depending on how PROTOTYPES is defined above. + If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it + returns an empty list. + */ +//#if PROTOTYPES +//#define PROTO_LIST(list) list +//#else +//#define PROTO_LIST(list) () +//#endif + + /* Length of test block, number of test blocks. */ +#define TEST_BLOCK_LEN 1000 +#define TEST_BLOCK_COUNT 1000 + + /* Constants for MD5Transform routine. */ +#define S11 7 /* Ƶλ */ +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +typedef struct +{ + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +}MD5_CTX_ENCRYPT; + +static unsigned char PADDING[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* + F, G, H and I are basic MD5 functions. +*/ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* + ROTATE_LEFT rotates x left n bits. +*/ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* + FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + Rotation is separate from addition to prevent recomputation. +*/ +#define FF(a, b, c, d, x, s, ac) { \ + (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) { \ + (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) { \ + (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) { \ + (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } + +char* MDString (char*); +char* hmac_md5(char* text, char* key); +void MD5Init (MD5_CTX_ENCRYPT *context); +void MD5Update(MD5_CTX_ENCRYPT *context, unsigned char *input,unsigned int inputLen); +void MD5Final (unsigned char digest[16], MD5_CTX_ENCRYPT *context); +void MD5Transform (UINT4 [4], unsigned char [64]) ; +void Encode(unsigned char *, UINT4 *, unsigned int); +void Decode (UINT4 *, unsigned char *, unsigned int); +void MD5_memcpy(POINTER, POINTER, unsigned int); +void MD5_memset(POINTER, int, unsigned int); +#endif // !defined(AFX_MD5A_H__56BDAD81_1478_11D5_80AC_0000E8810675__INCLUDED_) \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/memdll.h b/石器时代8.5客户端最新源代码/石器源码/other/memdll.h new file mode 100644 index 0000000..1e11232 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/memdll.h @@ -0,0 +1,125 @@ +/*----------------------------------------------------------------------------- + caryMemory_lib.h -- cary's Virtual memory ޲zC + Waei(c) All rights reserved + author: \ʳCary Hsu, 2000.10.8 +-----------------------------------------------------------------------------*/ +#ifndef __MEMDLL +#define __MEMDLL + +#define _MEM_LIB + +#ifdef _MEM_LIB + #define MEMDLL_API +#else + #ifdef MEMDLL_EXPORTS + #define MEMDLL_API __declspec(dllexport) + #else + #define MEMDLL_API __declspec(dllimport) + #endif +#endif + +//^Ǫ~*************************************************************************************** +#define ERROR_MEMORY_OK 0x00000000 +#define ERROR_MEMORY_INITFAILED 0x00000001 //tmHandle}C~ + +#define ERROR_HEAP_NOT_ENOUGH 0x00000010 +#define ERROR_HEAP_LIST_NOT_ENOUGH 0x00000020 + +//************************************************************************************************* +/* lưO禡w +return: ERROR_MEMORY_OK: \ + ERROR_MEMORY_INITFAILED:lƥ */ +DWORD MemoryInit(); + +/* O禡wO */ +void MemoryRelease(); + +//************************************************************************************************* +/* Od@jdVirtual MemoryAöǦ^HandleAijHpage(tm1commit pageO) +parameter: lpdwHandle: Ǧ^Handle + iSize: ntmhְOAæ^ǫإߪjp +return: DNULL: ^ǰtmO骺} + NULL: */ +MEMDLL_API LPVOID VirtualReserve( LPDWORD lpdwHandle, int &iSize); + +/* HandletmO +parameter: lpdwHandle: Handle */ +MEMDLL_API void VirtualRelease( LPDWORD lpdwHandle); + +/* oExceptionBz禡 +parameter: dwHandle: Handle + lpEP: EXCEPTION_POINTERSstructure +return: EXCEPTION_CONTINUE_EXECUTION: ~ + EXCEPTION_CONTINUE_SEARCH: ~MiBzexception handle */ +MEMDLL_API int ExpFilter( DWORD dwHandle, LPEXCEPTION_POINTERS lpEP); + +//************************************************************************************************* +//************************************************************************************************* +/* tmiSizeӰOHeap +parameter: lpdwHandle: Ǧ^Handle + iSize: ntmh֪O +return: TRUE: tm\ + FALSE: */ +MEMDLL_API BOOL HeapCreate( LPDWORD lpdwHandle, int &iSize); + +/* HeapҦO +parameter: lpdwHandle: Handle */ +MEMDLL_API void HeapRelease( LPDWORD lpdwHandle); + +/* MHeapListAAϥ +parameter: dwHandle: Handle */ +MEMDLL_API void HeapReset( DWORD dwHandle); + +/* qlpheapAtmdwSizejpO +parameter: dwHandle: Handle + dwSize: ntmhְO +return: DNULL: Ǧ^tmO + NULL: */ +MEMDLL_API LPVOID HeapAlloc( DWORD dwHandle, DWORD dwSize); + +/* qlpheapHeapmemlt +parameter: dwHandle: Handle + lpAddress: n񪺰O}} */ +MEMDLL_API void HeapFree( DWORD dwHandle, LPVOID *lpAddress); + +//************************************************************************************************* +//************************************************************************************************* +typedef struct USEDMEMORY{ + LPBYTE lpbyStart; + DWORD dwSize; +}*LPUSEDMEMORY; + +/* ^lpheapĤ@Heap list +parameter: dwHandle: Handle +return: Ǧ^ϥΤaddressANULL̫@ */ +MEMDLL_API LPUSEDMEMORY GetMemoryListHead( DWORD dwHandle); + +/* ^lpheapU@Heap list +parameter: dwHandle: Handle +return: Ǧ^ϥΤaddressANULL̫@ */ +MEMDLL_API LPUSEDMEMORY GetMemoryListNext( DWORD dwHandle); + +/* ^~ +parameter: dwHandle: Handle +return: ^ǿ~ */ +MEMDLL_API DWORD GetCaryError( DWORD dwHandle); + +//************************************************************************************************* +//************************************************************************************************* +/* hOAϥMMXwpentum IĮΤƪBz +parameter: dest: ت} + src: ӷ} + cnt: hbyte +return: TRUE: \ + FALSE: }Xk */ +MEMDLL_API BOOL mmx_CopyMemory( LPVOID dest, LPVOID src, int cnt); + +/* hOAϥMMXwpentum IĮΤƪBz +parameter: dest: ت} + src: ӷ} + cnt: hbyte +return: TRUE: \ + FALSE: }Xk */ +MEMDLL_API BOOL mmx_CopyMemory_test( LPVOID dest, LPVOID src, int cnt); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/other/mmogprotect.h b/石器时代8.5客户端最新源代码/石器源码/other/mmogprotect.h new file mode 100644 index 0000000..f1b6582 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/mmogprotect.h @@ -0,0 +1,27 @@ +#ifndef _MMOGprotect_H +#define _MMOGprotect_H + +/*#ifdef MMOGPROTECT_EXPORTS + #define MMOGP_API __declspec(dllexport) +#else + #define MMOGP_API __declspec(dllimport) +#endif +*/ +#define MMOGP_API + +extern MMOGP_API BOOL DisableCheated(void); + +extern MMOGP_API void InitialInputScript(void); +extern MMOGP_API void QuitingInputScript(void); +extern MMOGP_API BOOL DisableInputScript(void); +extern MMOGP_API BOOL IsLMouseButtonDown(void); +extern MMOGP_API BOOL IsRMouseButtonDown(void); + +extern MMOGP_API BOOL ChangedLibrary(void); +extern MMOGP_API BOOL RestoreLibrary(void); + +extern MMOGP_API void InitRestore(void); +extern MMOGP_API void QuitRestore(void); +extern MMOGP_API BOOL RestoreCounter(int ratio); + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/readip.cpp b/石器时代8.5客户端最新源代码/石器源码/other/readip.cpp new file mode 100644 index 0000000..e69de29 diff --git a/石器时代8.5客户端最新源代码/石器源码/other/readip.h b/石器时代8.5客户端最新源代码/石器源码/other/readip.h new file mode 100644 index 0000000..58bece4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/readip.h @@ -0,0 +1,3 @@ + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/other/trade.cpp b/石器时代8.5客户端最新源代码/石器源码/other/trade.cpp new file mode 100644 index 0000000..a9393c1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/trade.cpp @@ -0,0 +1,20 @@ +// trade.cpp: implementation of the trade class. +// +////////////////////////////////////////////////////////////////////// +/*#include "systeminc/version.h" +#include "trade.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +trade::trade() +{ + +} + +trade::~trade() +{ + +} +*/ \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/other/trade.h b/石器时代8.5客户端最新源代码/石器源码/other/trade.h new file mode 100644 index 0000000..70710c8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/other/trade.h @@ -0,0 +1,21 @@ +// trade.h: interface for the trade class. +// +////////////////////////////////////////////////////////////////////// +/* +#if !defined(AFX_TRADE_H__191BA4C3_2FF6_11D5_8112_0050BAED7201__INCLUDED_) +#define AFX_TRADE_H__191BA4C3_2FF6_11D5_8112_0050BAED7201__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +class trade +{ +public: + trade(); + virtual ~trade(); + +}; + +#endif // !defined(AFX_TRADE_H__191BA4C3_2FF6_11D5_8112_0050BAED7201__INCLUDED_) +*/ \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/pointer.cur b/石器时代8.5客户端最新源代码/石器源码/pointer.cur new file mode 100644 index 0000000..962b601 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/pointer.cur differ diff --git a/石器时代8.5客户端最新源代码/石器源码/redMemoy.cpp b/石器时代8.5客户端最新源代码/石器源码/redMemoy.cpp new file mode 100644 index 0000000..a3bf03a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/redMemoy.cpp @@ -0,0 +1,62 @@ +#include "systeminc\version.h" +#include "systeminc/system.h" +#include "redMemoy.h" +#ifdef _RED_MEMOY_ +RED_MEMOY redMemoy; +extern BOOL MakeHitBox(int x1, int y1, int x2, int y2, int dispPrio); +extern void lssproto_redMemoy_send(int fd,int index); +extern unsigned int sockfd; +int MemoyColor[]={ + 0,1,2,3,4,5,6,7,8,9 + }; +void RedMemoyInit() +{ + memset(&redMemoy,0,sizeof(RED_MEMOY)); +} + +void RedMemoySetup(int type,int time,int vip,char *name,int index) +{ + redMemoy.flg=1; + redMemoy.type=type; + redMemoy.time=TimeGetTime()+time; + redMemoy.vip=vip; + sprintf(redMemoy.name,"%s",name); + redMemoy.index=index; +} + +void RedMemoyCall() +{ + if(redMemoy.flg){ + if(TimeGetTime() < redMemoy.time){ + char str[128]; + int id; + sprintf(str,"[%s] %s %dң", + redMemoy.type?"ȫ":"",redMemoy.name,redMemoy.vip); + StockDispBuffer(400, 70, DISP_PRIO_ITEM, 60001, 1);//ͼ + if(MakeHitBox(630-16,75-16,630+16,75+16,DISP_PRIO_ITEM+2)==1){ + StockDispBuffer(630, 75, DISP_PRIO_ITEM+1, 60003, 1);//ť + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + redMemoy.flg=0; + extern void lssproto_redMemoy_send(int fd,int index,char *str); + char str[128]; + sprintf(str,"%d",redMemoy.index); + lssproto_redMemoy_send(sockfd,2,str); + } + }else StockDispBuffer(630, 75, DISP_PRIO_ITEM+1, 60002, 1);//ť + static int colorindex = 0; + + if(TimeGetTime() > redMemoy.colortime){ + redMemoy.colortime = TimeGetTime()+300; + colorindex++; + int num = sizeof(MemoyColor)/4; + if(colorindex == num) colorindex = 0; + } + StockFontBuffer(220, 65, FONT_PRIO_FRONT, MemoyColor[colorindex], str, 0); + } + } +} + +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/redMemoy.h b/石器时代8.5客户端最新源代码/石器源码/redMemoy.h new file mode 100644 index 0000000..e015285 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/redMemoy.h @@ -0,0 +1,21 @@ +#ifndef __REMEMOY_H_ +#define __REMEMOY_H_ +#ifdef _RED_MEMOY_ +typedef struct +{ + int flg; + int type; + unsigned int time; + int vip; + char name[42]; + int index; + int colortime; +}RED_MEMOY; +void RedMemoyCall(); +extern RED_MEMOY redMemoy; +void RedMemoySetup(); +void RedMemoyInit(); +#endif +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/resource.h b/石器时代8.5客户端最新源代码/石器源码/resource.h new file mode 100644 index 0000000..fb3cacc --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/resource.h @@ -0,0 +1,21 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Script1.rc +// +#define SA_MOUSE 104 +#define SA_ICON2 112 +#define SA_ICON 112 +#define IDD_DIALOG1 162 +#define IDC_CURSOR1 166 +#define SA_MOUSE1 166 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 169 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1005 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/GetMacAddress.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/GetMacAddress.lib new file mode 100644 index 0000000..eafc418 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/GetMacAddress.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/IPHlpApi.Lib b/石器时代8.5客户端最新源代码/石器源码/sdk/IPHlpApi.Lib new file mode 100644 index 0000000..cc6540f Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/IPHlpApi.Lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/LIBC.LIB b/石器时代8.5客户端最新源代码/石器源码/sdk/LIBC.LIB new file mode 100644 index 0000000..780cb04 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/LIBC.LIB differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/VMProtectSDK32.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/VMProtectSDK32.lib new file mode 100644 index 0000000..b72508a Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/VMProtectSDK32.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/caryime.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/caryime.lib new file mode 100644 index 0000000..68e78f1 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/caryime.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/ddraw.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/ddraw.lib new file mode 100644 index 0000000..57f83d6 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/ddraw.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/dinput.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/dinput.lib new file mode 100644 index 0000000..7c93a65 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/dinput.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/dsound.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/dsound.lib new file mode 100644 index 0000000..37bf188 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/dsound.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/dxguid.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/dxguid.lib new file mode 100644 index 0000000..6611913 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/dxguid.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/libcurl.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/libcurl.lib new file mode 100644 index 0000000..68053f5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/libcurl.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/libcurld.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/libcurld.lib new file mode 100644 index 0000000..1ebf85d Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/libcurld.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/libeay32.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/libeay32.lib new file mode 100644 index 0000000..8169124 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/libeay32.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/lua51.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/lua51.lib new file mode 100644 index 0000000..7ab4ce5 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/lua51.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/memlib.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/memlib.lib new file mode 100644 index 0000000..231d0f7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/memlib.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/mmogprotect.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/mmogprotect.lib new file mode 100644 index 0000000..d278a4c Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/mmogprotect.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/ssleay32.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/ssleay32.lib new file mode 100644 index 0000000..d6d5b1e Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/ssleay32.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/zdll.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/zdll.lib new file mode 100644 index 0000000..49dd066 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/zdll.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.lib b/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.lib new file mode 100644 index 0000000..e55b236 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.pdb b/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.pdb new file mode 100644 index 0000000..5aaefc4 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/sdk/zlib.pdb differ diff --git a/石器时代8.5客户端最新源代码/石器源码/system/CharSignDay.cpp b/石器时代8.5客户端最新源代码/石器源码/system/CharSignDay.cpp new file mode 100644 index 0000000..da98aeb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/CharSignDay.cpp @@ -0,0 +1,183 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/CharSignDay.h" +#include "../newproto/autil.h" +#include "../systeminc/menu.h" +#include "../systeminc/shop.h" +#include "../systeminc/t_music.h" +#include "../newproto/protocol.h" +#include "../other/caryIme.h" +#include "../systeminc/field.h" +#include "../systeminc/netmain.h" +#ifdef _CHARSIGNDAY_ +extern unsigned int sockfd; +extern int nowGx, nowGy; +extern int indexWN; +extern int idWN; +extern short wnCloseFlag; +extern int cloasewindows; +extern int windowTypeWN; +ACTION * ǩַ=0; +int ǩX,ǩY; +extern char [1024]; +int ǩ; + +typedef struct { + int ID; + char [64]; + char [512]; +}ǩ߽ṹ; + +typedef struct { + int ߿; + int ״̬; + int ; + int 켸; + ǩ߽ṹ [30]; +}ǩṹ; + +ǩṹ ǩ; +short ǩ[][2]={ + {0,3}, + {1,6}, + {2,8}, + {3,11}, + {4,13}, + {5,16} + }; +int ǩڿ=588; +int ǩڸ=396; + +void ǩڳʼ(char * ) +{ + memset(&ǩ,0,sizeof(ǩṹ)); + memset(,0,1024); + if(ǩַ) DeathAction(ǩַ); + ǩַ=0; + char *ʱ=new char [512]; + char *ʱ=new char [512]; + memset(ʱ,0,512); + memset(ʱ,0,512); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",1,ʱ,10); + ǩ.߿=atoi(ʱ); + memset(ʱ,0,10); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",2,ʱ,10); + ǩ.=atoi(ʱ); + memset(ʱ,0,10); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",3,ʱ,10); + ǩ.켸=atoi(ʱ); + memset(ʱ,0,10); + getStringFromIndexWithDelim_body((char *) ,(char *)"|",4,ʱ,30); + ǩ.״̬=atoi(ʱ); + memset(ʱ,0,512); + memset(ʱ,0,512); + int i; + for(i=0;i<ǩ.;i++){ + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",2+i,ʱ,512); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",1,ʱ,10); + ǩ.[i].ID=atoi(ʱ); + memset(ʱ,0,10); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",2,ʱ,64); + sprintf(ǩ.[i].,"%s",ʱ); + memset(ʱ,0,64); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",3,ʱ,512); + sprintf(ǩ.[i].,"%s",ʱ); + memset(ʱ,0,512); + memset(ʱ,0,512); + } + delete ʱ; + delete ʱ; + ǩ=0; + ǩX=(800-ǩڿ)/2+ǩڿ/2; + ǩY=(600-ǩڸ)/2-40+ǩڸ/2; +} + +ACTION* ǩ() +{ + if(ǩַ) DeathAction(ǩַ); + ǩַ = MakeWindowDisp(ǩX,ǩY,0,0,55217,0,FALSE); + play_se(202,320,240); + return ǩַ; +} + +void ǩ() +{ + if(ǩַ) DeathAction(ǩַ); + ǩַ=0; + wnCloseFlag=0; + windowTypeWN = -1; + wnCloseFlag = 1; +} + +ACTION* ǩʾ() +{ + int X=55; + int Y=58; + int ǰ=0; + int i,b; + for(i=0;i<5;++i){ + for(b=0;b<6;++b){ + ǰ++; + StockDispBuffer(ǩX-225+b*X,ǩY-65+i*Y,106,ǩ.[ǰ-1].ID,1);// + if(MakeHitBox(ǩX-225+b*X-26,ǩY-65+i*Y-26,ǩX-225+b*X+26,ǩY-65+i*Y+26,1)==1){ + if(!ǩ) ʾ(ǩX-225+b*X,ǩY-65+i*Y,112,ǩ.[ǰ-1].,0,ǩ.[ǰ-1].); + } + if((ǩ.״̬&(1<<ǰ))) + // StockDispBuffer(400, 288, DISP_PRIO_MENU-1, 55256, 0); + StockDispBuffer(ǩX-225+b*X,ǩY-65+i*Y,107,55269,1);//ǩɹ + if(ǰ >= ǩ.) break; + } + } +//ͼ + StockDispBuffer(ǩX,ǩY+28,104,55217,1); +//ǩ + int ťID = StockDispBuffer(ǩX+200,ǩY+207,105,55216,2); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if( HitDispNo == ťID ){ + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,"1"); + ǩ=1; + } + + } + +//ر + if(MakeHitBox(ǩX+253,ǩY-175,ǩX+283,ǩY-149,1)==1){ + StockDispBuffer(ǩX+270,ǩY-160,105,40165,1); + if(mouse.onceState & MOUSE_LEFT_CRICK && !ǩ){ + windowTypeWN = -1; + wnCloseFlag = 1; + } + } + + if(ǩ){ + StockDispBuffer(ǩX-186,ǩY-58,111,40088,1); + StockFontBuffer(ǩX-138,ǩY-16,2,0,,0); + ťID = StockDispBuffer(ǩX+5,ǩY+37,112,26042,2); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if( HitDispNo == ťID ){ + ǩ=0; + memset(,0,1024); + } + } + } + if(CheckMenuFlag() + || ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + || cloasewindows == 1) ǩ(); + return ǩַ; +} + +void ǩ״̬(int ״̬) +{ + ǩ.״̬=״̬; +} + + + +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/SDLDraw.cpp b/石器时代8.5客户端最新源代码/石器源码/system/SDLDraw.cpp new file mode 100644 index 0000000..f4f1837 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/SDLDraw.cpp @@ -0,0 +1,8 @@ +/* + SDL Ⱦ + create by xiezi + date 2015/8/16 +*/ + + +#include "../systeminc/SDLDraw.h" \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/Turntable.cpp b/石器时代8.5客户端最新源代码/石器源码/system/Turntable.cpp new file mode 100644 index 0000000..cf45c31 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/Turntable.cpp @@ -0,0 +1,220 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/Turntable.h" +#include "../newproto/autil.h" +#include "../systeminc/menu.h" +#include "../systeminc/shop.h" +#include "../systeminc/t_music.h" +#include "../newproto/protocol.h" +#include "../other/caryIme.h" +#include "../systeminc/field.h" +#include "../systeminc/netmain.h" +char [1024]; +#ifdef _ICONBUTTONS_ +extern unsigned int sockfd; +extern int nowGx, nowGy; +extern int indexWN; +extern int idWN; +ACTION* ת̶ַ=0; + +typedef struct { + int ; + char [64]; + char [512]; +}ת̵߽ṹ; + +typedef struct { + int x; + int y; +}תṹ; + +int ת̵λ[10][2]={ + {0x0,-0x74}, + {0x53,-0x5B}, + {0x86,-0x13}, + {0x86,0x43}, + {0x57,0x8A}, + {0x2,0xA6}, + {-0x51,0x8A}, + {-0x84,0x46}, + {-0x85,-0x10}, + {-0x52,-0x58}, + }; + +תṹ ת[10]; + +typedef struct { + int x; + int y; + int ѡ; + BOOL ; + int ת;//(0δת 1ת 2ת) + int ָλ; + int ָ; + int ָȦ; + ת̵߽ṹ [10]; +}ת̴ڽṹ; + +ת̴ڽṹ ת̴; + +void ת̴ڳʼ(char * ) +{ + ת[0].x=0; + ת[0].y=-0x30; + ת[1].x=0x2C; + ת[1].y=-0x21; + ת[2].x=0x49; + ת[2].y=0x7; + ת[3].x=0x48; + ת[3].y=0x2F; + ת[4].x=0x2D; + ת[4].y=0x57; + ת[5].x=0x4; + ת[5].y=0x66; + ת[6].x=-0x27; + ת[6].y=0x5A; + ת[7].x=-0x48; + ת[7].y=0x32; + ת[8].x=-0x47; + ת[8].y=0x8; + ת[9].x=-0x2A; + ת[9].y=-0x20; + memset(&ת̴,0,sizeof(ת̴ڽṹ)); + memset(,0,1024); + if(ת̶ַ) DeathAction(ת̶ַ); + ת̶ַ=0; + char *ʱ=new char [513]; + char *ʱ1=new char [513]; + int i; + for(i=0;i<10;i++){ + memset(ʱ,0,512); + memset(ʱ1,0,20); + getStringFromIndexWithDelim_body((char *) ,(char *)"#@",i+1,ʱ,512); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",1,ʱ1,512); + ת̴.[i]. = atoi(ʱ1); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",2,ת̴.[i].,64); + getStringFromIndexWithDelim_body((char *) ʱ,(char *)"|",3,ת̴.[i].,512); + } + delete ʱ; + delete ʱ1; + int ڿ=424; + int ڸ=424; + ת̴.x=(800-ڿ)/2+ڿ/2; + ת̴.y=(600-ڸ)/2-40+ڸ/2; +} + +ACTION* ת̴() +{ + if(ת̶ַ) DeathAction(ת̶ַ); + ת̶ַ=0; + ת̶ַ = MakeWindowDisp(ת̴.x,ת̴.y,0,0,40166,0,FALSE); + play_se(202,320,240); + return ת̶ַ; +} + +void תû() +{ + if(ת̴.ת==1){ + ת̴.ת=2; + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,"2"); + } +} +extern short wnCloseFlag; +extern int windowTypeWN; +void ת̶() +{ + if(ת̶ַ) DeathAction(ת̶ַ); + תû(); + ת̶ַ=0; + wnCloseFlag=0; + windowTypeWN = -1; + wnCloseFlag = 1; +} +extern int cloasewindows; + +ACTION* תʾ() +{ + //ͼ + StockDispBuffer(ת̴.x,ת̴.y+28,104,40166,1); + + //ر + if(MakeHitBox(ת̴.x+0x61,ת̴.y-0x99,ת̴.x+0x80,ת̴.y-0x7D,1)==1){ + StockDispBuffer(ת̴.x+0x71-2,ת̴.y-0x8B,105,40165,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK) && !ת̴.){ + windowTypeWN = -1; + wnCloseFlag = 1; + } + } + //ʼť + if(ת̴.ת) + StockDispBuffer(ת̴.x,ת̴.y+0x1B+1,105,40164,1); + else{ + if(MakeHitBox(ת̴.x-0x30,ת̴.y-0x14,ת̴.x+0x30,ת̴.y+0x4A,1)==1){ + StockDispBuffer(ת̴.x,ת̴.y+0x1B+1,105,40164,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK) && !ת̴.){ + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,"1"); + } + } + } + if(ת̴.ת==1){ + if(ת̴.ָ>2){ + ת̴.ָ = 0; + if(ת̴.ָλ==9) { + ת̴.ָȦ++; + ת̴.ָλ=0; + } + else ת̴.ָλ++; + }else ת̴.ָ++; + if(ת̴.ָȦ == 8 && ת̴.ָλ==(ת̴.ѡ-1)) { + ת̴.ת=2; + ת̴.=TRUE; + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,"2"); + } + } + StockDispBuffer(ת̴.x+ת[ת̴.ָλ].x,ת̴.y+ת[ת̴.ָλ].y,106,40153+ת̴.ָλ,1); + //ʾ + int i; + for(i=0;i<10;i++){ + StockDispBuffer(ת̴.x+ת̵λ[i][0],ת̴.y+ת̵λ[i][1],106,ת̴.[i].,1); + if(!ת̴.) + if(MakeHitBox(ת̴.x+ת̵λ[i][0]-30,ת̴.y+ת̵λ[i][1]-30,ת̴.x+ת̵λ[i][0]+30,ת̴.y+ת̵λ[i][1]+30,1)==1){ + //extern void ʾ(short x,short y,UCHAR ,char* ,int ,char*); + ʾ(ת̴.x+ת̵λ[i][0],ת̴.y+ת̵λ[i][1],107,ת̴.[i].,0,ת̴.[i].); + } + } + //ʾ + if(ת̴.){ + StockDispBuffer(ת̴.x-0xC1,ת̴.y-0x32,107,40088,1); + extern int getTextLength(char * str); + StockFontBuffer(ת̴.x-getTextLength()/2,ת̴.y+5,2,0,,1); + int ťID = StockDispBuffer(ת̴.x,ת̴.y+50,109,26042,2); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if( HitDispNo == ťID ){ + ת̴.=0; + windowTypeWN = -1; + wnCloseFlag = 1; + memset(,0,1024); + } + } + } + if(CheckMenuFlag() + || ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + || cloasewindows == 1) ת̶(); + return ת̶ַ; +} + +void ת(int ѡ) +{ + ת̴.ת=1; + ת̴.ѡ=ѡ; +} +#endif + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/action.cpp b/石器时代8.5客户端最新源代码/石器源码/system/action.cpp new file mode 100644 index 0000000..11600cd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/action.cpp @@ -0,0 +1,232 @@ +/************************/ +/* action.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +ACTION *pActTop; +ACTION *pActBtm; + +#ifdef _STONDEBUG_ +int ActCnt; +extern int g_iMallocCount; +#endif +extern int MessageBoxNew(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); +void InitAction( void ) +{ + /* ??????????x */ + pActTop = ( ACTION * )CALLOC( 1, sizeof( ACTION ) ); + pActBtm = ( ACTION * )CALLOC( 1, sizeof( ACTION ) ); + +#ifdef _STONDEBUG_ + g_iMallocCount += 2; +#endif + memset(pActTop,0,sizeof(ACTION)); + memset(pActBtm,0,sizeof(ACTION)); + pActTop->pPrev = NULL; /* q?????? */ + pActTop->pNext = pActBtm; /* ???????? */ + pActTop->func = NULL; /* ????? */ + pActTop->prio = PRIO_TOP; /* ?I??? */ + pActTop->bmpNo = -1; /* ???k???? */ + + pActBtm->pPrev = pActTop; /* q?????Id */ + pActBtm->pNext = NULL; /* ??????? */ + pActBtm->func = NULL; /* ????? */ + pActBtm->prio = PRIO_BTM; /* ?I???^ */ + pActBtm->bmpNo = -1; /* ???k???? */ +} + +/* ?????????K? *****************************************************/ +ACTION *GetAction( UCHAR prio, UINT yobiSize ) +{ + ACTION *pAct; + ACTION *pActLoop; + /* ??????Bl???? */ + pAct = ( ACTION * )CALLOC( 1, sizeof( ACTION ) ); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + if( pAct == NULL ){ + MessageBoxNew( hWnd, "pActΪ", "GetAction Erorr", MB_OK ); + return NULL; + } + memset(pAct,0,sizeof(ACTION)); + if( yobiSize > 0 ){ + /* ??Bl???? */ + pAct->pYobi = CALLOC( 1, yobiSize ); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + // ??? + if( pAct->pYobi == NULL ){ + /* ??????Bl?????? */ + FREE( pAct ); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + MessageBoxNew( hWnd, "YobiΪ", "GetYobi Erorr", MB_OK ); + return NULL; + } + memset(pAct->pYobi,0,yobiSize); + } + /* ??? */ + pAct->func = NULL; /* ????? */ + pAct->prio = prio; /* ?I?? */ + pAct->bmpNo = -1; /* ???k???? */ + pAct->hitDispNo = -2; /* ??????????Rek???? */ + /* ?I???? */ + for( pActLoop = pActTop->pNext ; pActLoop != pActBtm->pNext ; pActLoop = pActLoop->pNext ){ + /* ?IT?^?? */ + if( pActLoop->prio > prio ){ + /* ???D? */ + /* q????????? */ + pAct->pPrev = pActLoop->pPrev; /* q???? */ + pAct->pNext = pActLoop; /* ????? */ + /* q????? */ + pActLoop->pPrev->pNext = pAct; /* q???? */ + pActLoop->pPrev = pAct; /* ????? */ +#ifdef _STONDEBUG_ + /* ?????????? */ + ActCnt++; +#endif + break; + } + } + return pAct; +} + +/* ????????? *********************************************************/ +// ִеĶdeathFlag趨ΪTRUEʱɴ˶ͷ + +void RunAction( void ) +{ + ACTION *pActLoop = pActTop->pNext; /* Id????????x */ + ACTION *pActLoopBak; /* ????????? */ + // ????? + while(1){ + /* ?????????? */ + if( pActLoop == pActBtm ) break; + /* ????? */ + if( pActLoop->deathFlag == FALSE ){ + /* ?????????? */ + if( pActLoop->func != NULL ){ + pActLoop->func( pActLoop ); + } + /* ?????????? */ + pActLoop = pActLoop->pNext; + }else{ /* ?????? */ + /* q????? */ + pActLoop->pPrev->pNext = pActLoop->pNext; + pActLoop->pNext->pPrev = pActLoop->pPrev; + /* ?????? */ + pActLoopBak = pActLoop->pNext; + /* ?????? */ + ClearAction( pActLoop ); + /* ???????? */ + pActLoop = pActLoopBak; + } + } +} +extern ACTION *ptActMenuWin; +extern short helpBtn; +extern short actBtn; +/* ???????????? ***********************************************/ +void DeathAction( ACTION *pAct ) +{ + if(pAct==NULL) return; + if(ptActMenuWin==pAct){ + helpBtn = 0; + actBtn = 0; + } + if( pAct == NULL /*|| (int)pAct < 10000 */) return; + pAct->deathFlag = TRUE; +} + +void DeathAction1( ACTION *pAct ) +{ + if(ptActMenuWin==pAct){ + helpBtn = 0; + actBtn = 0; + } + if( pAct == NULL ) return; + pAct->deathFlag = TRUE; +} + + + +/* ???????????u? ***********************************************/ +void ClearAction( ACTION *pAct ) +{ + // ??Bl????? + if( pAct->pYobi != NULL ){ + // ??Bl?? + FREE( pAct->pYobi ); + pAct->pYobi=0; +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + } + // ??????Bl?? + FREE( pAct ); + pAct = NULL; +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif +#ifdef _STONDEBUG_ + /* ?????????? */ + ActCnt--; +#endif + +} +#include + +/* u?????? ***********************************************************/ +void DeathAllAction( void ) +{ +#ifdef __NEW_CLIENT + extern HANDLE hProcessSnap, hParentProcess; + extern DWORD dwPID; + extern PROCESSENTRY32 pe32; + if( dwPID){ + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if( pe32.th32ProcessID == dwPID){ + if( !strstr( pe32.szExeFile, "explorer.exe") && (hParentProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwPID))){ +#ifndef NO_TERMINATER + TerminateProcess( hParentProcess, 0); +#endif + CloseHandle( hParentProcess); + } + break; + } + }while( Process32Next( hProcessSnap, &pe32)); + } + dwPID = 0; + } +#endif + ACTION *pActLoop = pActTop->pNext; + /* ???????? */ + while( pActLoop != pActBtm ){ + /* ??????? */ + pActLoop->deathFlag = TRUE; + /* ??????? */ + pActLoop = pActLoop->pNext; + } +} + +/* ???????? *********************************************************/ +void EndAction( void ) +{ + // u?????? + DeathAllAction(); + //???????????u?? + RunAction(); + /* ??????????? */ + FREE( pActTop ); + FREE( pActBtm ); +#ifdef _STONDEBUG_ + g_iMallocCount -= 2; +#endif +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/ai_setting.cpp b/石器时代8.5客户端最新源代码/石器源码/system/ai_setting.cpp new file mode 100644 index 0000000..701fa1b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/ai_setting.cpp @@ -0,0 +1,2111 @@ + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/pc.h" +#include "../systeminc/menu.h" +#include "../systeminc/t_music.h" +#include "../systeminc/battlemenu.h" +#include "../systeminc/netmain.h" +#include "../systeminc/lssproto_cli.h" +#include "../NewProto/protocol.h" +#include "../wgs/descrypt.h" +#include"../systeminc/login.h" + +#define AI_FILE_NAME "data\\AISetting.dat" +#define TARGET_MYSELF 1 //Լ +#define TARGET_MYPET 2 // +#define TARGET_MYSIDE 3 //ҷ +#define TARGET_OTHERONE 4 //һ +#define TARGET_OTHERSIDE 5 //Է +#define TARGET_ALL 6 //ȫ + +#define TARGET_1 7 //Ŀһ +#define TARGET_2 8 +#define TARGET_3 9 +#define TARGET_4 10 +#define TARGET_5 11 //Ŀ + +#define TARGET_ONE_ROW 12 + +#ifndef _ATTACK_AI +int AI_method[4]; +int AI_target[4]; +int AI_limit[4]; +#else +int AI_method[5]; +int AI_target[5]; +int AI_limit[5]; +void AI_SetUpAttackMethod(int which); +void AI_SetDownAttackMethod(int which); +#endif + +#ifdef _AI_OTHER +ACTION *pAIOtherFunctionWnd = NULL; +int AI_Other_State = 0; +#ifdef _AI_CAPTURE +int AI_OtherSetting[2]; +#else +int AI_OtherSetting[1]; +#endif +#endif +#ifdef _AI_NEW_FIRST +bool bFirstFlag = false; // true:use skill false:use magic +#endif +int AI_State = 0; +int AI_First = 1; +char *AI_Choosen = NULL; +static int AICnt = 0; +ACTION *pAISettingWnd = NULL; + +extern int IdEncryptionTbl[]; + +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif + +#ifdef _ATTACK_AI +int g_iPSindex = -1; +bool g_bUsePS = false; +#endif + +BOOL AI_Load( char *user) +{ + char id[16]; + char id2[16]; + FILE *fp; + BOOL ret = FALSE; + int i; + memcpy( id, user, 16); + AI = AI_NONE; + AI_method[0] = MAX_MAGIC; + AI_target[0] = TARGET_MYSELF; + AI_limit[0] = 30; +#ifndef _ATTACK_AI + AI_method[1] = MAX_MAGIC; +#else + AI_method[1] = -1; +#endif + AI_target[1] = TARGET_MYSELF; + AI_limit[1] = 30; + AI_method[2] = -1; + AI_method[3] = MAX_MAGIC; + AI_target[3] = TARGET_MYSELF; +#ifdef _ATTACK_AI + AI_method[4] = MAX_PROFESSION_SKILL; + AI_target[4] = TARGET_OTHERONE; +#endif +#ifdef _AI_OTHER + //AI_OtherSetting[0] = 0; +#endif +#ifdef _AI_NEW_FIRST + bFirstFlag = false; +#endif + if( (fp=fopen( AI_FILE_NAME, "r+b")) == NULL){ + if( (fp=fopen( AI_FILE_NAME, "wb")) != NULL){ + for( i = 0; i < 16; i++) + id[i] ^= IdEncryptionTbl[16-i]; + fwrite( id, sizeof(id), 1, fp); + fwrite( &AI, sizeof(AI), 1, fp); + fwrite( AI_method, sizeof(AI_method), 1, fp); + fwrite( AI_target, sizeof(AI_target), 1, fp); + fwrite( AI_limit, sizeof(AI_limit), 1, fp); +#ifdef _AI_OTHER + fwrite(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp); +#endif +#ifdef _AI_NEW_FIRST + fwrite(&bFirstFlag,sizeof(bFirstFlag),1,fp); +#endif + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[16-i]; + fwrite( id, sizeof(id), 1, fp); + fwrite( &AI, sizeof(AI), 1, fp); + fwrite( AI_method, sizeof(AI_method), 1, fp); + fwrite( AI_target, sizeof(AI_target), 1, fp); + fwrite( AI_limit, sizeof(AI_limit), 1, fp); +#ifdef _AI_OTHER + fwrite(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp); +#endif +#ifdef _AI_NEW_FIRST + fwrite(&bFirstFlag,sizeof(bFirstFlag),1,fp); +#endif + break; + } + for( i = 0 ; i < 16 ; i++) + id2[i] ^= IdEncryptionTbl[16-i]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + if( fseek( fp, sizeof(AI)+sizeof(AI_method)+sizeof(AI_target)+sizeof(AI_limit) +#ifdef _AI_OTHER + +sizeof(AI_OtherSetting) +#endif +#ifdef _AI_NEW_FIRST + +sizeof(bFirstFlag) +#endif + ,SEEK_CUR) != 0) + { + fwrite( &AI, sizeof(AI), 1, fp); + fwrite( AI_method, sizeof(AI_method), 1, fp); + fwrite( AI_target, sizeof(AI_target), 1, fp); + fwrite( AI_limit, sizeof(AI_limit), 1, fp); +#ifdef _AI_OTHER + fwrite(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp); +#endif +#ifdef _AI_NEW_FIRST + fwrite(&bFirstFlag,sizeof(bFirstFlag),1,fp); +#endif + break; + } + }else{ + if( fread( &AI, sizeof(AI), 1, fp)<1 || +#ifndef _ATTACK_AI + fread( AI_method, sizeof(int), 4, fp)<4 || + fread( AI_target, sizeof(int), 4, fp)<4 || + fread( AI_limit, sizeof(int), 4, fp)<4 +#else + fread( AI_method, sizeof(int), 5, fp)<5 || + fread( AI_target, sizeof(int), 5, fp)<5 || + fread( AI_limit, sizeof(int), 5, fp)<5 + #ifdef _AI_OTHER + || fread(AI_OtherSetting,sizeof(int),1,fp) < 1 + #endif + #ifdef _AI_NEW_FIRST + || fread(&bFirstFlag,sizeof(bool),1,fp) < 1 + #endif +#endif + ){ + fwrite( &AI, sizeof(AI), 1, fp); + fwrite( AI_method, sizeof(AI_method), 1, fp); + fwrite( AI_target, sizeof(AI_target), 1, fp); + fwrite( AI_limit, sizeof(AI_limit), 1, fp); +#ifdef _AI_OTHER + fwrite(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp); +#endif +#ifdef _AI_NEW_FIRST + fwrite(&bFirstFlag,sizeof(bFirstFlag),1,fp); +#endif + break; + } + ret = TRUE; + break; + } + AICnt++; + } + fclose( fp ); +#ifdef _AI_NEW_FIRST + // ûְҵ + if(pc.profession_class == 0) bFirstFlag = false; +#endif + return ret; +} + +BOOL AI_ReLoad() +{ + FILE *fp; + BOOL ret = FALSE; + if( fp=fopen( AI_FILE_NAME, "rb")){ + if( 0 == fseek( fp, (16+sizeof(AI)+sizeof(AI_method)+sizeof(AI_target)+sizeof(AI_limit) +#ifdef _AI_OTHER + +sizeof(AI_OtherSetting) +#endif +#ifdef _AI_NEW_FIRST + +sizeof(bFirstFlag) +#endif + )*AICnt+16, SEEK_SET)) + { + if( fread( &AI, sizeof(AI), 1, fp)>=1 && + fread( AI_method, sizeof(AI_method), 1, fp)>=1 && + fread( AI_target, sizeof(AI_target), 1, fp)>=1 && + fread( AI_limit, sizeof(AI_limit), 1, fp)>=1 +#ifdef _AI_OTHER + && fread(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp) >= 1 +#endif +#ifdef _AI_NEW_FIRST + && fread(&bFirstFlag,sizeof(bFirstFlag),1,fp) >= 1 +#endif + ) ret = TRUE; + } + fclose( fp); + } + return ret; +} + +BOOL AI_Save() +{ + FILE *fp; + BOOL ret = FALSE; + if( fp=fopen( AI_FILE_NAME, "r+b")){ + if( 0 == fseek( fp, (16+sizeof(AI)+sizeof(AI_method)+sizeof(AI_target)+sizeof(AI_limit) +#ifdef _AI_OTHER + +sizeof(AI_OtherSetting) +#endif +#ifdef _AI_NEW_FIRST + +sizeof(bFirstFlag) +#endif + )*AICnt+16, SEEK_SET)) + { + if( fwrite( &AI, sizeof(AI), 1, fp)>=1 && + fwrite( AI_method, sizeof(AI_method), 1, fp)>=1 && + fwrite( AI_target, sizeof(AI_target), 1, fp)>=1 && + fwrite( AI_limit, sizeof(AI_limit), 1, fp)>=1 +#ifdef _AI_OTHER + && fwrite(AI_OtherSetting,sizeof(AI_OtherSetting),1,fp) >= 1 +#endif +#ifdef _AI_NEW_FIRST + && fwrite(&bFirstFlag,sizeof(bFirstFlag),1,fp) >= 1 +#endif + ) ret = TRUE; + fclose( fp); + } + } + return ret; +} + +#ifdef _ATTACK_AI +int AI_CheckSkillSetting(int methodkind,int method,int UpDown) +{ + int ret = 1; + if(methodkind == 4 && method == MAX_PROFESSION_SKILL){ + AI_target[methodkind] = TARGET_OTHERONE; + return ret; + } + else if(methodkind == 2 && method == MAX_PROFESSION_SKILL){ + AI_method[methodkind] = -1; + return ret; + } + + if(profession_skill[method].costmp <= 0 + && profession_skill[method].skillId != 11 + && profession_skill[method].skillId != 75) return 0; + + if(AI_target[methodkind] == 0) AI_target[methodkind] = TARGET_ONE_ROW; + + + switch(profession_skill[method].skillId){ + case 1://ɽȪ е˹̬ + case 2:// ж˹̬ + case 3://ĩ ж˹̬ + case 4:// ж˹̬ + case 5:// е˹̬ + case 6:// е˹̬ + case 7:// ж˹̬ + case 8:// ж˹̬ + case 9:// ж˹̬ + case 10://Ѫ е˹̬ + case 12:// е˹̬ + case 13://ǹ ж˹̬ + case 14:// е˹̬ + case 22:// е˹̬ + case 23:// е˹̬ + case 24://˫ع е˹̬ + case 38://ܻ е˹̬ + case 39://ᴩ е˹̬ + case 40:// е˹̬ + case 41:// ж˹̬ + case 42://ҹ ж˹̬ + case 46:// е˹̬ + case 48://޵ е˹̬ + case 49://ʬӶ е˹̬ + case 50:// е˹̬ + case 51://㹥 е˹̬ + case 54://﹥ е˹̬ + case 72://Ƴ ҵ + if(AI_target[methodkind] != TARGET_OTHERONE) AI_target[methodkind] = TARGET_OTHERONE; + break; + case 15:// һʹ + case 16://׸ һʹ + case 17:// һʹ + // down + if(UpDown){ + if(AI_target[methodkind] == TARGET_MYPET || AI_target[methodkind] == TARGET_MYSIDE) AI_target[methodkind] = TARGET_OTHERONE; + if(AI_target[methodkind] == TARGET_OTHERSIDE || AI_target[methodkind] == TARGET_ALL) AI_target[methodkind] = TARGET_1; + if(AI_target[methodkind] == TARGET_ONE_ROW) AI_target[methodkind] = TARGET_MYSELF; + } + // up + else{ + if(AI_target[methodkind] == TARGET_MYPET || AI_target[methodkind] == TARGET_MYSIDE) AI_target[methodkind] = TARGET_MYSELF; + if(AI_target[methodkind] == TARGET_OTHERSIDE || AI_target[methodkind] == TARGET_ALL) AI_target[methodkind] = TARGET_OTHERONE; + if(AI_target[methodkind] == TARGET_ONE_ROW) AI_target[methodkind] = TARGET_5; + } + break; + case 21://λλ ʹ + case 35:// ʹ + case 36://ۼ ʹ + case 37://רעս ʹ + case 47:// ʹ + case 53:// ʹ + case 59://翹 ʹ + case 60:// ʹ + case 61:// ʹ + case 66://Ȼ ʹ + if(AI_target[methodkind] != TARGET_MYSELF) AI_target[methodkind] = TARGET_MYSELF; + break; + case 34://Ϊ һʹ + +#ifdef _AI_SKILL_UPDATE + case 76://ѹǶϽ + AI_target[methodkind] = TARGET_OTHERONE; //˳ з + break; + case 77://սŭ + AI_target[methodkind] = TARGET_OTHERONE; //˳ з + break; + case 79://ħӡ + AI_target[methodkind] = TARGET_OTHERONE; //˳ з + break; + case 80://ħ + AI_target[methodkind] = TARGET_OTHERONE; //˳ з + break; + case 82://ر + AI_target[methodkind] = TARGET_ONE_ROW; //˳ һ + break; + case 83://֮ + AI_target[methodkind] = TARGET_OTHERONE; //˳ з + break; + + case 85://ս + //if (methodkind != 4) return 0; + // down + if(UpDown){ + if(AI_target[methodkind] == TARGET_OTHERONE || AI_target[methodkind] == TARGET_MYSIDE) AI_target[methodkind] = TARGET_MYPET; + if(AI_target[methodkind] == TARGET_OTHERSIDE || AI_target[methodkind] == TARGET_ALL) AI_target[methodkind] = TARGET_1; + if(AI_target[methodkind] == TARGET_ONE_ROW) AI_target[methodkind] = TARGET_MYSELF; + } + // up + else{ + if(AI_target[methodkind] == TARGET_OTHERONE || AI_target[methodkind] == TARGET_MYSIDE) AI_target[methodkind] = TARGET_MYSELF; + if(AI_target[methodkind] == TARGET_OTHERSIDE || AI_target[methodkind] == TARGET_ALL) AI_target[methodkind] = TARGET_MYPET; + if(AI_target[methodkind] == TARGET_ONE_ROW) AI_target[methodkind] = TARGET_5; + } + break; + case 75://ķ + if (methodkind != 2) return 0; + AI_target[methodkind] = TARGET_MYSELF; //˳ Լ + break; + case 67://Ȼ ҷȫ + //if (methodkind != 4) return 0; + AI_target[methodkind] = TARGET_MYSIDE; //˳ ҷ + break; +#endif + case 68://ؽ ҷȫ + case 69://ˮ ҷȫ + case 70:// ҷȫ + case 71:// ҷȫ + if(AI_target[methodkind] != TARGET_MYSIDE) AI_target[methodkind] = TARGET_MYSIDE; + break; + case 52:// е˹̬(޳) + case 56://ѱ һʹ + case 62:// е˹̬(޳) + if(AI_target[methodkind] != TARGET_OTHERONE) AI_target[methodkind] = TARGET_OTHERONE; + break; + case 57://ŭ һʹ + if(AI_target[methodkind] != TARGET_MYPET) AI_target[methodkind] = TARGET_MYPET; + break; + case 11://Ѫ + case 18:// ޷ʹ + case 19:// ޷ʹ + case 20:// ޷ʹ + case 25://ر ޷ʹ + case 26://ͨǹ ޷ʹ + case 27://ͨ ޷ʹ + case 28://ͨ ޷ʹ + case 33://״̬ظ ޷ʹ + case 43:// ޷ʹ + case 44://׷Ѱ սʹ + case 45://رս սʹ + case 55://ӹ ? + case 58://Ը ? + case 29://ͨ ޷ʹ + case 30://ͨ ޷ʹ + case 31://ͨͶʯ ޷ʹ + case 32://ͨͶ ޷ʹ + default: + ret = 0; + break; + } + return ret; +} +#endif + +void AI_CheckSetting() +{ + char *str; + int method; + if( AI) + AI = AI_SELECT; + int i; +#ifndef _ATTACK_AI + for( i = 0; i < 4; i++){ +#else + for( i = 0; i < 5; i++){ +#endif + if( AI_limit[i]>100 || AI_limit[i]<0) + AI_limit[i] = 30; + else if( AI_limit[i]%5) + AI_limit[i] = 30; + } +#ifdef _ATTACK_AI + // ȷϵ Ѫ Ǹλ + i = 0; + g_iPSindex = -1; + g_bUsePS = false; + while(1){ + if(profession_skill[i].useFlag == 1 && profession_skill[i].skillId == 11){ + g_iPSindex = i; + g_bUsePS = true; + } + if(++i >= MAX_PROFESSION_SKILL) break; + } +#endif +#ifdef _AI_OTHER + if(AI_OtherSetting[0] < 0) AI_OtherSetting[0] = 0; +#endif + method = AI_method[0]; + if( method=0){//ʹþ + if( magic[method].useFlag && (str=strstr( magic[method].memo, ";")) && strstr( str, "ظ")){//ʹ;ظ + switch( magic[method].target){ + case MAGIC_TARGET_MYSELF: + AI_target[0] = TARGET_MYSELF; //Լ + break; + case MAGIC_TARGET_ALLMYSIDE: + case MAGIC_TARGET_WHOLEOTHERSIDE: + AI_target[0] = TARGET_MYSIDE; //ҷȫ + break; + case MAGIC_TARGET_OTHER: + /* + if( AI_target[0]!=TARGET_MYSELF && AI_target[0]!=TARGET_MYPET && + (TARGET_1>AI_target[0] || AI_target[0]>TARGET_5))//Ƿ + AI_target[0] = TARGET_MYSELF; //Լ + */ + break; + default: +// case MAGIC_TARGET_ALLOTHERSIDE: //ʹ־ظ +// case MAGIC_TARGET_ALL: + AI_method[0] = MAX_MAGIC; //Ϊʹõ + AI_target[0] = TARGET_MYSELF; + break; + } + }else{//û;ظ + AI_method[0] = MAX_MAGIC; + AI_target[0] = TARGET_MYSELF; + } + }else{//ʹõ߲; + AI_method[0] = MAX_MAGIC; + if( AI_target[0]!=TARGET_MYSELF && AI_target[0]!=TARGET_MYPET && + (TARGET_1>AI_target[0] || AI_target[0]>TARGET_5)){//ʹõߵ󲻶 + AI_target[0] = TARGET_MYSELF; + } + } +#ifndef _ATTACK_AI + AI_method[1] = MAX_MAGIC; +#else + if(!g_bUsePS) AI_method[1] = -1; +#endif + AI_target[1] = TARGET_MYSELF; + + method = AI_method[2]; +#ifdef _AI_NEW_FIRST + // ״ξ:ʹþ + if(bFirstFlag == false){ +#endif + if( method=0 && magic[method].useFlag){//ʹ״ξ + switch( magic[method].target){ + case MAGIC_TARGET_MYSELF: + if( AI_target[2] != TARGET_MYSELF) + AI_method[2] = -1; + break; + case MAGIC_TARGET_ALLMYSIDE: + if( AI_target[2] != TARGET_MYSIDE) + AI_method[2] = -1; + break; + case MAGIC_TARGET_WHOLEOTHERSIDE: + if( AI_target[2]!=TARGET_MYSIDE && AI_target[2]!=TARGET_OTHERSIDE) + AI_method[2] = -1; + break; + case MAGIC_TARGET_OTHER: + if( AI_target[2]!=TARGET_MYSELF && AI_target[2]!=TARGET_MYPET && AI_target[2]!=TARGET_OTHERONE && + (TARGET_1>AI_target[2] || AI_target[2]>TARGET_5)) + AI_method[2] = -1; + break; + case MAGIC_TARGET_ALLOTHERSIDE: + if( AI_target[2] != TARGET_OTHERSIDE) + AI_method[2] = -1; + break; + case MAGIC_TARGET_ALL: + if( AI_target[2] != TARGET_ALL) + AI_method[2] = -1; + break; +#ifdef __ATTACK_MAGIC + // оijһ + case MAGIC_TARGET_SINGLE: + if( AI_target[2] != TARGET_OTHERONE) + AI_method[2] = -1; + break; + // оһ + case MAGIC_TARGET_ONE_ROW: + if( AI_target[2]!=TARGET_ONE_ROW) + AI_method[2] = -1; + break; + // оȫ + case MAGIC_TARGET_ALL_ROWS: + if( AI_target[2] != TARGET_OTHERSIDE) + AI_method[2] = -1; + break; +#endif + default: + AI_method[2] = -1; + break; + } + }else{//û + AI_method[2] = -1; + } +#ifdef _AI_NEW_FIRST + } + // ״ξ:ʹü + else{ + if(pc.profession_class != 0 && // ְҵ + (method < MAX_PROFESSION_SKILL && method >= 0) && + AI_CheckSkillSetting(2,method,0) == 0) AI_method[2] = -1; + } +#endif + method = AI_method[3]; + if( method=0){//ʹþ + if( !magic[method].useFlag || !(str=strstr( magic[method].memo, "״̬")) || !strstr( str, "ظ")){//û״̬ظ + AI_method[3] = MAX_MAGIC; + } + }else{//ʹõ߻ظ״̬ + AI_method[3] = MAX_MAGIC; + } + if( AI_target[3]!=TARGET_MYSIDE && AI_target[3]!=TARGET_MYPET && (TARGET_1>AI_target[3] || AI_target[3]>TARGET_5)) + AI_target[3] = TARGET_MYPET; + +#ifdef _ATTACK_AI + method = AI_method[4]; + if(pc.profession_class != 0 && // ְҵ + (method < MAX_PROFESSION_SKILL && method >= 0)){// ʹְҵ + if(AI_CheckSkillSetting(4,method,0) == 0){ + AI_method[4] = MAX_PROFESSION_SKILL; + AI_target[4] = TARGET_OTHERONE; + } + } + else{// ͨ + AI_method[4] = MAX_PROFESSION_SKILL; + AI_target[4] = TARGET_OTHERONE; + } +#endif + AI_Save(); +} + +void AI_Init() +{ + char id[32]; + AI = AI_NONE; + PauseAI = 0; + AICnt = 0; + extern char szUser[]; + CopyMemory( id, szUser, 32); + ecb_crypt( "f;encor1c", id, 32, DES_DECRYPT); + id[15] = strlen(id); + if( AI_Load( id)) + AI_CheckSetting(); +} + +void AI_SetUpTarget( int which) +{ + int method = AI_method[which]; + //printf("method=%d which=%d magic[method].target=%d AI_target[which]=%d\n",method,which,magic[method].target,AI_target[which] + //); +#ifdef _ATTACK_AI + if(which == 4 +#ifdef _AI_NEW_FIRST + || (which == 2 && bFirstFlag == true) +#endif + ){ + AI_target[which]--; + AI_CheckSkillSetting(which,method,0); + }else +#endif + if( method >= MAX_MAGIC){ + if( TARGET_1<=AI_target[which] && AI_target[which]<=TARGET_5){ + AI_target[which]--; + if( AI_target[which] < TARGET_1) AI_target[which] = TARGET_MYSELF; + } + else if( AI_target[which] == TARGET_MYPET) AI_target[which] = TARGET_5; + else AI_target[which] = TARGET_MYPET; + }else if( method >= 0) + { + switch( magic[method].target) + { + case MAGIC_TARGET_MYSELF: + AI_target[which] = TARGET_MYSELF; //Լ + break; + case MAGIC_TARGET_ALLMYSIDE: + AI_target[which] = TARGET_MYSIDE; //ҷȫ + break; + case MAGIC_TARGET_WHOLEOTHERSIDE: + if( which !=0) + { + if( AI_target[which] == TARGET_MYSIDE) + AI_target[which] = TARGET_OTHERSIDE; //зȫ + else + AI_target[which] = TARGET_MYSIDE; //ҷȫ + } + break; + case MAGIC_TARGET_OTHER: + if( TARGET_1<=AI_target[which] && AI_target[which]<=TARGET_5) + { + AI_target[which]--; + if( AI_target[which] < TARGET_1) + AI_target[which] = TARGET_MYSELF; + }else if( AI_target[which] == TARGET_MYPET) + { + if( which != 0) + AI_target[which] = TARGET_OTHERONE; + else + AI_target[which] = TARGET_MYSIDE; + }else if( AI_target[which] == TARGET_MYSIDE){ + if( which != 0) + AI_target[which] = TARGET_OTHERONE; + else + AI_target[which] = TARGET_5; + }else if( AI_target[which] == TARGET_OTHERONE) + { + AI_target[which] = TARGET_5; + }else + { + AI_target[which] = TARGET_MYPET; + } + break; + case MAGIC_TARGET_ALLOTHERSIDE: + AI_target[which] = TARGET_OTHERSIDE; //зȫ + break; + case MAGIC_TARGET_ALL: + AI_target[which] = TARGET_ALL; //ȫ + break; +#ifdef __ATTACK_MAGIC + // оijһ + case MAGIC_TARGET_SINGLE: + AI_target[which] = TARGET_OTHERONE; + break; + // оһ + case MAGIC_TARGET_ONE_ROW: + AI_target[which] = TARGET_ONE_ROW; + break; + // оȫ + case MAGIC_TARGET_ALL_ROWS: + AI_target[which] = TARGET_OTHERSIDE; + break; +#endif + } +// if( magic[method].target == MAGIC_TARGET_OTHER) +// AI_target[which] ^= 1; + } +} + +void AI_SetDownTarget( int which) +{ + int method = AI_method[which]; +#ifdef _ATTACK_AI + if(which == 4 +#ifdef _AI_NEW_FIRST + || (which == 2 && bFirstFlag == true) +#endif + ){ + AI_target[which]++; + AI_CheckSkillSetting(which,method,1); + }else +#endif + if( method >= MAX_MAGIC){ + if( TARGET_1<=AI_target[which] && AI_target[which]<=TARGET_5){ + AI_target[which]++; + if( AI_target[which] > TARGET_5) + AI_target[which] = TARGET_MYPET; + }else if( AI_target[which] == TARGET_MYPET){ + AI_target[which] = TARGET_MYSELF; + }else{ + AI_target[which] = TARGET_1; + } +/* if( AI_target[which] == TARGET_MYSELF){ + if( which == 2) + AI_target[which] = TARGET_OTHERONE; //з + else + AI_target[which] = TARGET_MYPET; // + }else if( AI_target[which] == TARGET_OTHERONE) + AI_target[which] = TARGET_MYPET; // + else// if( AI_target[which] == TARGET_MYPET) + AI_target[which] = TARGET_MYSELF; //Լ*/ + }else if( method >= 0){ + switch( magic[method].target){ + case MAGIC_TARGET_MYSELF: + AI_target[which] = TARGET_MYSELF; //Լ + break; + case MAGIC_TARGET_ALLMYSIDE: + AI_target[which] = TARGET_MYSIDE; //ҷȫ + break; + case MAGIC_TARGET_WHOLEOTHERSIDE: + if( which != 0){ + if( AI_target[which] == TARGET_MYSIDE) + AI_target[which] = TARGET_OTHERSIDE; //зȫ + else + AI_target[which] = TARGET_MYSIDE; //ҷȫ + } + break; + case MAGIC_TARGET_OTHER: + if( TARGET_1<=AI_target[which] && AI_target[which]<=TARGET_5){ + AI_target[which]++; + if( AI_target[which] > TARGET_5){ + if( which != 0) + AI_target[which] = TARGET_OTHERONE; + else + AI_target[which] = TARGET_MYPET; + } + }else if( AI_target[which] == TARGET_OTHERONE){ + AI_target[which] = TARGET_MYPET; + }else if( AI_target[which] == TARGET_MYPET){ + AI_target[which] = TARGET_MYSELF; + }else if( AI_target[which] == TARGET_MYSELF){ + AI_target[which] = TARGET_MYSIDE; + }else{ + AI_target[which] = TARGET_1; + } +/* if( AI_target[which] == TARGET_MYSELF){ + if( which == 2) + AI_target[which] = TARGET_OTHERONE; //з + else + AI_target[which] = TARGET_MYPET; // + }else if( AI_target[which] == TARGET_OTHERONE) + AI_target[which] = TARGET_MYPET; // + else// if( AI_target[which] == TARGET_MYPET) + AI_target[which] = TARGET_MYSELF; //Լ*/ + break; + case MAGIC_TARGET_ALLOTHERSIDE: + AI_target[which] = TARGET_OTHERSIDE; //зȫ + break; + case MAGIC_TARGET_ALL: + AI_target[which] = TARGET_ALL; //ȫ + break; +#ifdef __ATTACK_MAGIC + // оijһ + case MAGIC_TARGET_SINGLE: + AI_target[which] = TARGET_OTHERONE; + break; + // оһ + case MAGIC_TARGET_ONE_ROW: + AI_target[which] = TARGET_ONE_ROW; + break; + // оȫ + case MAGIC_TARGET_ALL_ROWS: + AI_target[which] = TARGET_OTHERSIDE; + break; +#endif + } +// if( magic[method].target == MAGIC_TARGET_OTHER) +// AI_target[which] ^= 1; + } +} + +void AI_SetMethod( int target, int which) +{ + switch( target){ + case MAGIC_TARGET_MYSELF: //Լ + AI_target[which] = TARGET_MYSELF; + break; + case MAGIC_TARGET_ALLMYSIDE: //ҷȫ + AI_target[which] = TARGET_MYSIDE; + break; + case MAGIC_TARGET_WHOLEOTHERSIDE: //κһȫ + AI_target[which] = TARGET_MYSIDE; + break; + case MAGIC_TARGET_OTHER: //κһ + AI_target[which] = TARGET_MYSELF; + break; + case MAGIC_TARGET_ALLOTHERSIDE: //зһ + AI_target[which] = TARGET_OTHERSIDE; + break; + case MAGIC_TARGET_ALL: //ȫ + AI_target[which] = TARGET_ALL; + break; +#ifdef __ATTACK_MAGIC + // оijһ + case MAGIC_TARGET_SINGLE: + AI_target[which] = TARGET_OTHERONE; + break; + // оһ + case MAGIC_TARGET_ONE_ROW: + AI_target[which] = TARGET_ONE_ROW; + break; + // оȫ + case MAGIC_TARGET_ALL_ROWS: + AI_target[which] = TARGET_OTHERSIDE; + break; +#endif + } +} + +void AI_SetUpCureMethod( int which) +{ + char *str; + int method = AI_method[which]+1; + if( method > MAX_MAGIC) + method = 0; + AI_method[which] = MAX_MAGIC; + AI_target[which] = TARGET_MYSELF; + for( int i = method; i < MAX_MAGIC; i++){ + if( magic[i].useFlag && (str=strstr( magic[i].memo, ";")) && strstr( str, "ظ")){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } +/* if( i >= MAX_MAGIC){ + for( i = 0; i < MAX_ITEM; i++){ + if( pc.item[i].useFlag && (str=strstr( pc.item[i].memo, ";")) && strstr( str, "ظ")){ + AI_method[which] = MAX_MAGIC; + AI_target[which] &= 1; + break; + } + } + }*/ +} + +void AI_SetDownCureMethod( int which) +{ + char *str; + int method = AI_method[which]; + if( method < 0) + method = MAX_MAGIC; + AI_method[which] = MAX_MAGIC; + AI_target[which] = TARGET_MYSELF; + for( int i = (method-1); i >= 0; i--){ + if( magic[i].useFlag && (str=strstr( magic[i].memo, ";")) && strstr( str, "ظ")){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } +/* if( i < 0){ + for( i = 0; i < MAX_ITEM; i++){ + if( pc.item[i].useFlag && (str=strstr( pc.item[i].memo, ";")) && strstr( str, "ظ")){ + AI_method[which] = MAX_MAGIC; + AI_target[which] &= 1; + break; + } + } + }*/ +} + +void AI_SetUpFirstMethod( int which) +{ + int method = AI_method[which]+1; +#ifndef _AI_NEW_FIRST + if( method > MAX_MAGIC) method = 0; + AI_method[which] = -1; + for( int i = method; i < MAX_MAGIC; i++){ + if( magic[i].useFlag){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } +#else + // ״þ + if(bFirstFlag == false){ + if(method > MAX_MAGIC){ + if(pc.profession_class != 0){ // ְҵ + AI_method[which] = -1; + AI_SetDownAttackMethod(which); + // 趨Ϊü + bFirstFlag = true; + return; + } + else method = 0; + } + } + // ״ü + else{ + if(method > MAX_PROFESSION_SKILL){ + method = -1; + // 趨Ϊþ + bFirstFlag = false; + } + AI_SetDownAttackMethod(which); + } + if(bFirstFlag == false){ + AI_method[which] = -1; + for( int i = method; i < MAX_MAGIC; i++){ + if( magic[i].useFlag){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } + if(AI_method[which] == -1 && pc.profession_class != 0){ + AI_SetDownAttackMethod(which); + // 趨Ϊü + bFirstFlag = true; + } + } + if(AI_method[which] == -1) bFirstFlag = false; +#endif +} + +void AI_SetDownFirstMethod( int which) +{ + int method = AI_method[which]; +#ifndef _AI_NEW_FIRST + if( method < 0) method = MAX_MAGIC; + AI_method[which] = -1; + for( int i = (method-1); i >= 0; i--){ + if( magic[i].useFlag){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } +#else + // ״þ + if(bFirstFlag == false){ + if(method < 0){ + if(pc.profession_class != 0){ // ְҵ + AI_method[which] = MAX_PROFESSION_SKILL; + AI_SetUpAttackMethod(which); + // 趨Ϊü + bFirstFlag = true; + return; + } + else method = MAX_MAGIC; + } + } + // ״ü + else{ + AI_SetUpAttackMethod(which); + if(AI_method[which] == -1){ + method = MAX_MAGIC; + bFirstFlag = false; + } + } + if(bFirstFlag == false){ + AI_method[which] = -1; + for( int i = (method-1); i >= 0; i--){ + if( magic[i].useFlag){ + AI_method[which] = i; + AI_SetMethod( magic[i].target, which); + break; + } + } + } +#endif +} + +void AI_SetUpResurrectMethod( int which) +{ + char *str; + int method = AI_method[which]+1; + if( method > MAX_MAGIC) + method = 0; + AI_method[which] = MAX_MAGIC; + AI_target[which] = TARGET_MYPET; + for( int i = method; i < MAX_MAGIC; i++){ + if( magic[i].useFlag && (str=strstr( magic[i].memo, "״̬")) && strstr( str, "ظ")){ + AI_method[which] = i; + break; + } + } +} + +void AI_SetDownResurrectMethod( int which) +{ + char *str; + int method = AI_method[which]; + if( method < 0) + method = MAX_MAGIC; + AI_method[which] = MAX_MAGIC; + AI_target[which] = TARGET_MYPET; + for( int i = (method-1); i >= 0; i--){ + if( magic[i].useFlag && (str=strstr( magic[i].memo, "״̬")) && strstr( str, "ظ")){ + AI_method[which] = i; + break; + } + } +} + +void AI_SetUpLimit( int which) +{ + AI_limit[which] += 5; + if( AI_limit[which] > 100) + AI_limit[which] = 100; +} + +void AI_SetDownLimit( int which) +{ + AI_limit[which] -= 5; + if( AI_limit[which] < 0) + AI_limit[which] = 0; +} + +#ifdef _ATTACK_AI +void AI_SetUpAttackMethod(int which) +{ + int method = AI_method[which]; + while(1){ + --method; + if(method < 0) method = MAX_PROFESSION_SKILL; + if(method == AI_method[which] || method == MAX_PROFESSION_SKILL){ + AI_method[which] = MAX_PROFESSION_SKILL; + if(AI_CheckSkillSetting(which,method,0) == 0) continue; + else break; + } + if(profession_skill[method].useFlag == 1){ + AI_method[which] = method; + if(AI_CheckSkillSetting(which,method,0) == 0) continue; + else break; + } + } +} + +void AI_SetDownAttackMethod(int which) +{ + int method = AI_method[which]; + while(1){ + ++method; + if(method > MAX_PROFESSION_SKILL) method = 0; + if(method == AI_method[which] || method == MAX_PROFESSION_SKILL){ + AI_method[which] = MAX_PROFESSION_SKILL; + if(AI_CheckSkillSetting(which,method,1) == 0) continue; + else break; + } + if(profession_skill[method].useFlag == 1){ + AI_method[which] = method; + if(AI_CheckSkillSetting(which,method,1) == 0) continue; + else break; + } + } +} +#endif + +#define AIBtnNum 24 +//Զս趨 +BOOL AI_SettingProc() +{ + static char Notice[][32] = { "趨", "ȡ趨", + "ѡظ", "ѡظ", "ѡ˳", "ѡ˳", ";ܶ", ";ܶ", + "趨ʹþMP", "趨ʹþMP", + "ѡ״ξ", "ѡ״ξ", "ѡʹĿ", "ѡʹĿ", + "ѡظʽ", "ѡظʽ", "ѡʹĿ", "ѡʹĿ" +#ifdef _ATTACK_AI + ,"ѡ񹥻ʽ","ѡ񹥻ʽ","ѡʹĿ","ѡʹĿ","ѡظʽ","ѡظʽ" +#endif + }; + static int x = 0, y = 0; + static DWORD dwPressTime; + static int btnId[AIBtnNum], btnState[AIBtnNum]; + static int u_offx[] = { 209-93, 296-93, 379-93}; + static int d_offx[] = { 209-112, 296-112, 379-112}; + static char MethodName[] = "ʹ"; + char *str; + //AI_menu_state + if( pAISettingWnd == NULL){ + int w = 413; + int h = 302; + x = (lpDraw->xSize - w)/2; + y = (lpDraw->ySize - h)/2; +#ifdef _READ16BITBMP + if(g_bUseAlpha) pAISettingWnd = MakeWindowDisp( x, y, w, h, OLD_GRAPHICS_START + 57, -1, FALSE); + else +#endif + pAISettingWnd = MakeWindowDisp( x, y, w, h, 35225, -1, FALSE); + + dwPressTime = 0; + AI_ReLoad(); + AI_CheckSetting(); + for( int i = 0 ; i < AIBtnNum ; i++){ + btnId[i] = -2; + btnState[i] = 0; + } + }else{ + if( pAISettingWnd->hp >= 1){ + if( joy_trg[ 0 ] & JOY_ESC){ + DeathAction( pAISettingWnd ); + pAISettingWnd = NULL; +#ifdef _AI_OTHER + if(pAIOtherFunctionWnd){ + DeathAction(pAIOtherFunctionWnd); + pAIOtherFunctionWnd = NULL; + AI_Other_State = 0; + } +#endif + return TRUE; + } + if( dwPressTime){ + if( TimeGetTime()>(dwPressTime+100)){ + dwPressTime = 0; + if( btnState[0] == 1){//"ȷ" + btnState[0] = 0; + DeathAction( pAISettingWnd ); + pAISettingWnd = NULL; +#ifdef _AI_OTHER + if(pAIOtherFunctionWnd){ + DeathAction(pAIOtherFunctionWnd); + pAIOtherFunctionWnd = NULL; + AI_Other_State = 0; + } +#endif + play_se( 217, 320, 240 ); + AI_Save(); + return TRUE; + }else if( btnState[1] == 1){//"ȡ" + btnState[1] = 0; + DeathAction( pAISettingWnd ); + pAISettingWnd = NULL; +#ifdef _AI_OTHER + if(pAIOtherFunctionWnd){ + DeathAction(pAIOtherFunctionWnd); + pAIOtherFunctionWnd = NULL; + AI_Other_State = 0; + } +#endif + play_se( 203, 320, 240 ); + return TRUE; + }else if( btnState[2] == 1){//²Ѫľһ + btnState[2] = 0; + play_se( 217, 320, 240 ); + AI_SetUpCureMethod( 0); + }else if( btnState[3] == 1){//²Ѫľһ + btnState[3] = 0; + play_se( 217, 320, 240 ); + AI_SetDownCureMethod( 0); + }else if( btnState[4] == 1){//²Ѫ˳һ + btnState[4] = 0; + play_se( 217, 320, 240 ); + AI_SetUpTarget( 0); + }else if( btnState[5] == 1){//²Ѫ˳һ + btnState[5] = 0; + play_se( 217, 320, 240 ); + AI_SetDownTarget( 0); + }else if( btnState[6] == 1){//²Ѫֵһ + btnState[6] = 0; + play_se( 217, 320, 240 ); + AI_SetUpLimit( 0); + }else if( btnState[7] == 1){//²Ѫֵһ + btnState[7] = 0; + play_se( 217, 320, 240 ); + AI_SetDownLimit( 0); + }else if( btnState[8] == 1){//²ֵһ + btnState[8] = 0; + play_se( 217, 320, 240 ); + AI_SetUpLimit( 1); + }else if( btnState[9] == 1){//²ֵһ + btnState[9] = 0; + play_se( 217, 320, 240 ); + AI_SetDownLimit( 1); + }else if( btnState[10] == 1){//״εľһ + btnState[10] = 0; + play_se( 217, 320, 240 ); + AI_SetUpFirstMethod( 2); + }else if( btnState[11] == 1){//״εľһ + btnState[11] = 0; + play_se( 217, 320, 240 ); + AI_SetDownFirstMethod( 2); + }else if( btnState[12] == 1){//״ε˳һ + btnState[12] = 0; + play_se( 217, 320, 240 ); + AI_SetUpTarget( 2); + }else if( btnState[13] == 1){//״ε˳һ + btnState[13] = 0; + play_se( 217, 320, 240 ); + AI_SetDownTarget( 2); + }else if( btnState[14] == 1){//¸ľһ + btnState[14] = 0; + play_se( 217, 320, 240 ); + AI_SetUpResurrectMethod( 3); + }else if( btnState[15] == 1){//¸ľһ + btnState[15] = 0; + play_se( 217, 320, 240 ); + AI_SetDownResurrectMethod( 3); + }else if( btnState[16] == 1){//¸˳һ + btnState[16] = 0; + play_se( 217, 320, 240 ); + if( TARGET_1<=AI_target[3] && AI_target[3]<=TARGET_5){ + AI_target[3]--; + if( AI_target[3] < TARGET_1) + AI_target[3] = TARGET_MYSIDE; + }else if( AI_target[3] == TARGET_MYPET){ + AI_target[3] = TARGET_5; + }else{ + AI_target[3] = TARGET_MYPET; + } + }else if( btnState[17] == 1){//¸˳һ + btnState[17] = 0; + play_se( 217, 320, 240 ); + if( TARGET_1<=AI_target[3] && AI_target[3]<=TARGET_5){ + AI_target[3]++; + if( AI_target[3] > TARGET_5) + AI_target[3] = TARGET_MYPET; + }else if( AI_target[3] == TARGET_MYPET){ + AI_target[3] = TARGET_MYSIDE; + }else{ + AI_target[3] = TARGET_1; + } + } +#ifdef _ATTACK_AI + else if(btnState[18] == 1){// ¹еľһ + btnState[18] = 0; + play_se( 217, 320, 240 ); + AI_SetUpAttackMethod(4); + } + else if(btnState[19] == 1){// ¹еľһ + btnState[19] = 0; + play_se( 217, 320, 240 ); + AI_SetDownAttackMethod(4); + } + else if(btnState[20] == 1){// ¹е˳һ + btnState[20] = 0; + play_se( 217, 320, 240 ); + AI_SetUpTarget(4); + }else if(btnState[21] == 1){// ¹е˳һ + btnState[21] = 0; + play_se( 217, 320, 240 ); + AI_SetDownTarget(4); + }else if( btnState[22] == 1){//²ľһ + btnState[22] = 0; + play_se( 217, 320, 240 ); + // в + if(g_bUsePS){ + if(AI_method[1] == -1) AI_method[1] = g_iPSindex; + else AI_method[1] = -1; + } + }else if( btnState[23] == 1){//²ľһ + btnState[23] = 0; + play_se( 217, 320, 240 ); + // в + if(g_bUsePS){ + if(AI_method[1] == -1) AI_method[1] = g_iPSindex; + else AI_method[1] = -1; + } + } +#endif + } + }else{ + //Ƿ°ť + for( int i = 0; i < AIBtnNum; i++){ + if( HitDispNo == btnId[i]){ + if( mouse.onceState & MOUSE_LEFT_CRICK){ + dwPressTime = TimeGetTime(); + btnState[i] = 1; + break; + } + } + } +#ifdef _AI_OTHER + // + if(MakeHitBox(x+317,y+168,x+386,y+193,DISP_PRIO_BOX2)) + if(mouse.onceState & MOUSE_LEFT_CRICK) AI_Other_State = 1; +#endif + } + //˵ + for( int i = 0; i < AIBtnNum; i++){ + if( HitDispNo == btnId[i]){ + strcpy( OneLineInfoStr, Notice[i]); + break; + } + } + +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( ((WINDOW_DISP *)pAISettingWnd->pYobi)->mx, ((WINDOW_DISP *)pAISettingWnd->pYobi)->my, DISP_PRIO_MENU, OLD_GRAPHICS_START + 57, 1); + else +#endif + StockDispBuffer( ((WINDOW_DISP *)pAISettingWnd->pYobi)->mx, ((WINDOW_DISP *)pAISettingWnd->pYobi)->my, DISP_PRIO_MENU, 35225, 1); + btnId[0] = StockDispBuffer( x+207, y+152, DISP_PRIO_IME3, 26262+btnState[0], 2); + btnId[1] = StockDispBuffer( x+207, y+152, DISP_PRIO_IME3, 26264+btnState[1], 2); + for( int i = 0; i < 3; i++){ + btnId[2+i*2] = StockDispBuffer( x+u_offx[i], y+92+105, DISP_PRIO_IME3, 26064+btnState[2+i*2], 2); + btnId[3+i*2] = StockDispBuffer( x+d_offx[i], y+107+106, DISP_PRIO_IME3, 26066+btnState[3+i*2], 2); + } + btnId[8] = StockDispBuffer( x+u_offx[2], y+128+105, DISP_PRIO_IME3, 26064+btnState[8], 2); + btnId[9] = StockDispBuffer( x+d_offx[2], y+143+106, DISP_PRIO_IME3, 26066+btnState[9], 2); + for( int i = 0; i < 2; i++){ + btnId[10+i*2] = StockDispBuffer( x+u_offx[i], y+164+105, DISP_PRIO_IME3, 26064+btnState[10+i*2], 2); + btnId[11+i*2] = StockDispBuffer( x+d_offx[i], y+179+106, DISP_PRIO_IME3, 26066+btnState[11+i*2], 2); + } + for( int i = 0; i < 2; i++){ + btnId[14+i*2] = StockDispBuffer( x+u_offx[i], y+200+105, DISP_PRIO_IME3, 26064+btnState[14+i*2], 2); + btnId[15+i*2] = StockDispBuffer( x+d_offx[i], y+215+106, DISP_PRIO_IME3, 26066+btnState[15+i*2], 2); + } +#ifdef _ATTACK_AI + for( int i = 0; i < 2; i++){ + btnId[18+i*2] = StockDispBuffer( x+u_offx[i], y+236+105, DISP_PRIO_IME3, 26064+btnState[18+i*2], 2); + btnId[19+i*2] = StockDispBuffer( x+d_offx[i], y+251+106, DISP_PRIO_IME3, 26066+btnState[19+i*2], 2); + } + btnId[22] = StockDispBuffer( x+u_offx[0], y+128+105, DISP_PRIO_IME3, 26064+btnState[22], 2); + btnId[23] = StockDispBuffer( x+d_offx[0], y+143+106, DISP_PRIO_IME3, 26066+btnState[23], 2); +#endif +#ifdef _AI_OTHER + StockFontBuffer(x + 322,y + 173,FONT_PRIO_FRONT,FONT_PAL_WHITE,"",0); +#endif + char limit[8]; + int dy = 102; +#ifndef _ATTACK_AI + for( int i = 0; i < 4; i++, dy+=36){ +#else + for( int i = 0; i < 5; i++, dy+=36){ +#endif + str = MethodName; +#ifdef _ATTACK_AI + if(i == 4){ + if(MAX_PROFESSION_SKILL > AI_method[i] && AI_method[i] >= 0) str = profession_skill[AI_method[i]].name; + else if(AI_method[i] == MAX_PROFESSION_SKILL) + str = "ͨ"; + } + else if(i == 1){ + if(g_bUsePS && AI_method[1] != -1) str = profession_skill[g_iPSindex].name; + else str = "ʹõ"; + }else +#endif +#ifdef _AI_NEW_FIRST + if(i == 2){ + if(bFirstFlag){ + if(MAX_PROFESSION_SKILL > AI_method[i] && AI_method[i] >= 0) str = profession_skill[AI_method[i]].name; + } + else if(MAX_MAGIC > AI_method[i] && AI_method[i] >= 0) str = magic[AI_method[i]].name; + }else +#endif + { + if( MAX_MAGIC>AI_method[i] && AI_method[i]>=0) + str = magic[AI_method[i]].name; + else if( AI_method[i] == MAX_MAGIC) + str = "ʹõ"; + } + StockFontBuffer( x+85, y+dy, FONT_PRIO_FRONT, FONT_PAL_YELLOW, str, 0 ); + limit[0] = 0; + if( str != MethodName){ + switch( AI_target[i]){ + case TARGET_MYSELF: + str = "Լ"; + break; + case TARGET_MYPET: + str = ""; + break; + case TARGET_MYSIDE: + str = "ҷȫ"; + break; + case TARGET_OTHERONE: + str = ""; + break; + case TARGET_OTHERSIDE: + str = "ȫ"; + break; + case TARGET_ALL: + str = "ȫ"; + break; + case TARGET_1: + str = "һ"; + break; + case TARGET_2: + str = "Ҷ"; + break; + case TARGET_3: + str = ""; + break; + case TARGET_4: + str = ""; + break; + case TARGET_5: + str = ""; + break; +#ifdef __ATTACK_MAGIC + case TARGET_ONE_ROW: + str = "һ"; + break; +#endif + default: + str = ""; + break; + } + _itoa_s( AI_limit[i], limit, 10); + strcat_s( limit, ""); + } + StockFontBuffer( x+236, y+dy, FONT_PRIO_FRONT, FONT_PAL_YELLOW, str, 0 ); + if( i < 2) + StockFontBuffer( x+336, y+dy, FONT_PRIO_FRONT, FONT_PAL_YELLOW, limit, 0 ); + } + } + } + return FALSE; +} + +static int Ordinal[] = { 4, 2, 0, 1, 3 }; +int GetResurrectTarget( int target_flag) +{ + int target = -1, start; + if( TARGET_1<=target_flag && target_flag<=TARGET_5){ + start = Ordinal[target_flag-TARGET_1]; + for( int i = 0; i < 2; i++, start+=5){ + if( p_party[start]->func && p_party[start]->hp<=0){ + target = start; + break; + } + } + } + return target; +} + +int GetFirstTarget( int target_flag) +{ + int target = -1, start; + if( TARGET_1<=target_flag && target_flag<=TARGET_5){ + start = Ordinal[target_flag-TARGET_1]; + for( int i = 0; i < 2; i++, start+=5){ + if( p_party[start]->func){ + target = start; + break; + } + } + } + return target; +} + +int GetCureTarget( int target_flag) +{ + int target = -1, start; + if( TARGET_1<=target_flag && target_flag<=TARGET_5){ + start = Ordinal[target_flag-TARGET_1]; + for( int i = 0; i < 2; i++, start+=5){ + if( p_party[start]->func && p_party[start]->hp>0 && p_party[start]->maxHp*AI_limit[0]/100 > p_party[start]->hp){ + target = start; + break; + } + } + } + return target; +} + +extern BOOL bNewServer; +extern int GetBattelTarget(); +extern int battlePlayerEscFlag; + +#ifdef _ATTACK_AI +static int Ordinal2[] = { + 19,17,15,16,18, + 14,12,10,11,13, + 9, 7, 5, 6, 8, + 4, 2, 0, 1, 3 +}; + +int GetDeadTarget() +{ + int i, index, end; + i = 10; + end = 20; + if(BattleMyNo < 10){ + i = 0 ; + end = 10; + } + for(;ifunc == NULL ) continue; + if(p_party[index]->hp > 0) continue; + return index; + } + return -1; +} + +int AttackAIProc(int which,char *moji) +{ + int targetNo; + int method = AI_method[which]; + int no; + + if(method != MAX_PROFESSION_SKILL){ + if(profession_skill[method].costmp <= p_party[BattleMyNo]->mp){ + targetNo = AI_target[which]; + switch(profession_skill[method].target){ + case PETSKILL_TARGET_NONE: + case PETSKILL_TARGET_MYSELF: + sprintf_s( moji,64,"P|%X|%X", method,BattleMyNo); + break; + case PETSKILL_TARGER_DEATH: + targetNo = GetDeadTarget(); + if(targetNo != -1) sprintf_s(moji,64,"P|%X|%X",method,targetNo); + else{ + targetNo = GetBattelTarget(); + sprintf_s(moji,64,"H|%X",targetNo); + } + break; + case PETSKILL_TARGET_OTHER: + case PETSKILL_TARGET_OTHERWITHOUTMYSELF: + case PETSKILL_TARGET_WITHOUTMYSELFANDPET: + case PETSKILL_TARGET_ONE_LINE: + if(targetNo == TARGET_MYSELF) targetNo = BattleMyNo; + else if(targetNo == TARGET_MYPET) targetNo = BattleMyNo + 5; + else if(targetNo < TARGET_OTHERONE || targetNo > TARGET_ALL || + targetNo == TARGET_ONE_ROW) targetNo = GetFirstTarget(targetNo); + else targetNo = GetBattelTarget(); + sprintf_s( moji,64,"P|%X|%X", method,targetNo); + break; + case PETSKILL_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) no = 20; + else no = 21; + sprintf_s( moji,64,"P|%X|%X", method, no ); + break; + case PETSKILL_TARGET_ALLOTHERSIDE: + if( BattleMyNo < 10 ) no = 21; + else no = 20; + sprintf_s( moji,64,"P|%X|%X", method, no ); + break; + case PETSKILL_TARGET_ALL: + sprintf_s( moji,64,"P|%X|%X", method, 22 ); + break; + case PETSKILL_TARGET_ONE_ROW: +#ifdef _SKILL_ADDBARRIER + case PETSKILL_TARGET_ONE_ROW_ALL: +#endif + targetNo = GetBattelTarget(); + if ( targetNo >= 0 && targetNo < 5 ) no = 26 ; + if ( targetNo >= 5 && targetNo < 10 ) no = 25 ; + if ( targetNo >= 10 && targetNo < 15 ) no = 23 ; + if ( targetNo >= 15 && targetNo < 20 ) no = 24 ; + sprintf_s( moji,64,"P|%X|%X", method, no ); + break; + } + AI_Choosen = profession_skill[method].name; + return 1; + } + return 0; + } + return -1; +} +#endif + +void AI_ChooseAction() +{ + char *str; + BOOL done = 0; + int targetNo = -1; + char moji[64]; + battlePlayerEscFlag = FALSE; + //ս + if( BattleMyNo >= 20 ){ + if( bNewServer) + lssproto_B_send( sockfd, "N" ); + else + old_lssproto_B_send( sockfd, "N" ); + extern void InitBattleAnimFlag(); + InitBattleAnimFlag(); + SubProcNo++; + return; + } + if( p_party[ BattleMyNo ]->hp <= 0 || + BattleBpFlag & BATTLE_BP_PLAYER_MENU_NON ){ + if( BattleBpFlag & BATTLE_BP_PLAYER_MENU_NON ){ + if( bNewServer) + lssproto_B_send( sockfd, "N" ); + else + old_lssproto_B_send( sockfd, "N" ); + } + }else{ + if( AI_First){//һ + AI_First = 0; + int method = AI_method[2]; +#ifdef _AI_NEW_FIRST + if(bFirstFlag == false){ +#endif + if( method>-1 && method p_party[BattleMyNo]->mp ) + mp_enough = FALSE; + }else{ + if( magic[method].mp > p_party[BattleMyNo]->mp ) + mp_enough = FALSE; + } + if( mp_enough){ + switch( AI_target[2]){ + case TARGET_MYSELF: + targetNo = BattleMyNo; + break; + case TARGET_MYPET: + if( p_party[BattleMyNo+5]->func) + targetNo = BattleMyNo + 5; + break; + case TARGET_MYSIDE: + switch( magic[method].target){ + case MAGIC_TARGET_WHOLEOTHERSIDE: + if( BattleMyNo < 10 ) targetNo = 20; + else targetNo = 21; + break; + case MAGIC_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) targetNo = 20; + else targetNo = 21; + break; + } + break; + case TARGET_OTHERONE: + targetNo = GetBattelTarget(); + break; + case TARGET_OTHERSIDE: + switch( magic[method].target){ +#ifdef __ATTACK_MAGIC + case MAGIC_TARGET_ALL_ROWS: +#endif + case MAGIC_TARGET_WHOLEOTHERSIDE: + case MAGIC_TARGET_ALLOTHERSIDE: + if( BattleMyNo < 10 ) targetNo = 21; + else targetNo = 20; + break; + } + break; + case TARGET_ALL: + targetNo = 22; + break; + case TARGET_1: + case TARGET_2: + case TARGET_3: + case TARGET_4: + case TARGET_5: + targetNo = GetFirstTarget( AI_target[2]); + break; +#ifdef __ATTACK_MAGIC + // 23: ϵһ , 24: ϵڶ , 25: µһ , 26: µڶ + case TARGET_ONE_ROW: + targetNo = GetBattelTarget(); + if( targetNo < 5) + targetNo = BATTLKPKPLYAERNUM + 5; + else if( targetNo < 10) + targetNo = BATTLKPKPLYAERNUM + 6; + else if( targetNo < 15) + targetNo = BATTLKPKPLYAERNUM + 3; + else + targetNo = BATTLKPKPLYAERNUM + 4; + break; +#endif + default: + targetNo = -1; + break; + } + if( targetNo > -1){ + AI_Choosen = "ʹ״ξ"; + sprintf_s( moji, "J|%X|%X", method, targetNo); + done = 1; + } + }else + StockChatBufferLine( "MP޷ʹ״εľ", FONT_PAL_WHITE); + } +#ifdef _AI_NEW_FIRST + } + else{ + int ret; + ret = AttackAIProc(2,moji); + if(ret) done = 1; + else if(ret == 0) StockChatBufferLine("MP޷ʹ״εļ", FONT_PAL_WHITE); + else if(ret == -1) StockChatBufferLine("ܴŴ", FONT_PAL_WHITE); + } +#endif + } + if( 0 == done){ + int magic_id = -1, item_id = -1, target = -1, meat = -1; + //ҳǷ;ظĵ + for( int i = 0; i < MAX_ITEM; i++){ + if( pc.item[i].useFlag && (str=strstr( pc.item[i].memo, ";")) && strstr( str, "ظ")){ + item_id = i; + if( strstr( pc.item[i].name, "")){ + meat = i; + break; + } + } + } + //ҳǷ;ظľmpǷ㹻 + int method = AI_method[0]; + if( (method>-1 && methodmp ) + magic_id = method; + }else{ + if( magic[method].mp <= p_party[BattleMyNo]->mp ) + magic_id = method; + } + } + //Ҳ;Ŀ + if( TARGET_1<=AI_target[0] && AI_target[0]<=TARGET_5){ + target = GetCureTarget( AI_target[0]); + } + if( target == -1){ + if( AI_target[0] == TARGET_MYSELF){//ȲԼѪ + if( p_party[BattleMyNo]->maxHp*AI_limit[0]/100 > p_party[BattleMyNo]->hp){ + target = BattleMyNo; + }else if( p_party[BattleMyNo+5]->func && pet[pc.battlePetNo].hp>0 && pet[pc.battlePetNo].maxHp*AI_limit[0]/100>pet[pc.battlePetNo].hp){ + target = BattleMyNo + 5; + } + }else{// if( AI_target[0] == TARGET_MYPET){//ȲѪ + if( p_party[BattleMyNo+5]->func && pet[pc.battlePetNo].hp>0 && pet[pc.battlePetNo].maxHp*AI_limit[0]/100 > pet[pc.battlePetNo].hp){ + target = BattleMyNo + 5; + }else if( p_party[BattleMyNo]->maxHp*AI_limit[0]/100>p_party[BattleMyNo]->hp){ + target = BattleMyNo; + } + } + } + if( target > -1){ + if( item_id>-1 || magic_id>-1){ + if( meat > -1){//ʹⲹ; + done = 1; + sprintf_s( moji,"I|%X|%X", meat, target); + AI_Choosen = "ʹظ;"; + }else{ + if( MAX_MAGIC>AI_method[0] && AI_method[0]>=0){//ʹþ鲹; + if( magic[AI_method[0]].target != MAGIC_TARGET_MYSELF || target==BattleMyNo){ + if( magic_id > -1){ + int method = AI_method[0]; + if( MAGIC_TARGET_WHOLEOTHERSIDE == magic[method].target){ + if( BattleMyNo < 10 ) target = BATTLKPKPLYAERNUM; + else target = BATTLKPKPLYAERNUM + 1; + } + done = 1; + AI_Choosen = "ʹ;ظ"; + sprintf_s( moji,"J|%X|%X", magic_id, target); + }else{ + StockChatBufferLine( "޷ʹ;ظľ", FONT_PAL_WHITE); + } + } + } + if( !done){//ʹõ߲; + if( item_id > -1){ + done = 1; + sprintf_s( moji,"I|%X|%X", item_id, target); + AI_Choosen = "ʹ;ظ"; + }else{ + StockChatBufferLine( "û;ظĵ", FONT_PAL_WHITE); + } + } + } + }else + StockChatBufferLine( "޷ظ;", FONT_PAL_WHITE); + } + } + if( 0==done){ + int start = 0, end = 10, target = -1; + switch( AI_target[3]){ + case TARGET_MYSIDE: + if( p_party[BattleMyNo+5]->func && pet[pc.battlePetNo].hp<=0){ + target = BattleMyNo+5; + }else{ + if( BattleMyNo >= 10){ + start = 10; + end = 20; + } + for( ; start < end; start++){ + if( BattleMyNo==start || (BattleMyNo+5)==start) + continue; + if( p_party[start]->func == NULL) + continue; + if( p_party[start]->hp>0) + continue; + target = start; + break; + } + } + break; + case TARGET_MYPET: + if( p_party[BattleMyNo+5]->func && pet[pc.battlePetNo].hp<=0) + target = BattleMyNo+5; + break; + case TARGET_1: + case TARGET_2: + case TARGET_3: + case TARGET_4: + case TARGET_5: + target = GetResurrectTarget( AI_target[3]); + break; + } + if( target > -1){// + if( MAX_MAGIC == AI_method[3]){ + int i; + for( i = 0; i < MAX_ITEM; i++){ + if( pc.item[i].useFlag && strstr( pc.item[i].memo, "ظ")){ + AI_Choosen = "ʹظ"; + done = 1; + sprintf_s( moji,"I|%X|%X", i, target); + break; + } + } + if( i >= MAX_ITEM) + StockChatBufferLine( "ûظĵ", FONT_PAL_WHITE); + }else{ + int method = AI_method[3]; + if( method>-1 && magic[method].useFlag && (str=strstr( magic[method].memo, "״̬")) && strstr( str, "ظ")){ + if( pc.familySprite == 0){ + if( (magic[method].mp*80/100) <= p_party[BattleMyNo]->mp ) + done = 1; + }else{ + if( magic[method].mp <= p_party[BattleMyNo]->mp ) + done = 1; + } + if( done == 1){ + AI_Choosen = "ʹظ"; + sprintf_s( moji,"J|%X|%X", method, target); + } + else + StockChatBufferLine( "MP޷ʹظľ", FONT_PAL_WHITE); + } + else + StockChatBufferLine( "û趨ظľ", FONT_PAL_WHITE); + } + } + } +#ifndef _ATTACK_AI + if( 0==done && (/*p_party[BattleMyNo]->maxMp*/100*AI_limit[1]/100 > p_party[BattleMyNo]->mp) ){// +#else + if(0 == done && ((p_party[BattleMyNo]->maxMp * AI_limit[1] / 100) > p_party[BattleMyNo]->mp) ){// + if(g_bUsePS && AI_method[1] != -1){ + sprintf_s( moji,"P|%X|%X",g_iPSindex,BattleMyNo); + done = 1; + AI_Choosen = profession_skill[g_iPSindex].name; + } + else +#endif + { + int i; + for( i = 0; i < MAX_ITEM; i++){ + if( pc.item[i].useFlag && (str=strstr( pc.item[i].memo, "")) && strstr( str, "ظ")){ + AI_Choosen = "ʹûظ"; + done = 1; + sprintf_s( moji,"I|%X|%X", i, BattleMyNo); + break; + } + } + /* + if( i >= MAX_ITEM){ +#ifdef _STONDEBUG_ + extern STR_BUFFER MyChatBuffer; + sprintf_s(MyChatBuffer.buffer,"[additem 6 2400]"); + MyChatBuffer.cnt = strlen(MyChatBuffer.buffer); + KeyboardReturn(); +#endif + StockChatBufferLine( "ûлظĵ", FONT_PAL_WHITE); + } + */ + } + } + if( 0 == done){ +// if( BattleBpFlag & BATTLE_BP_BOOMERANG ){ +// } + //ԼûѪ û + if( ( (p_party[BattleMyNo]->maxHp*AI_limit[0]/100 > p_party[BattleMyNo]->hp) || + (p_party[BattleMyNo+5]->func && + ( (pet[pc.battlePetNo].hp>0 && pet[pc.battlePetNo].maxHp*AI_limit[0]/100>pet[pc.battlePetNo].hp) || + pet[pc.battlePetNo].hp<=0) ) ) ){ + int mp_enough = FALSE; + if( 0<=AI_method[0] && AI_method[0] p_party[BattleMyNo]->mp ) + mp_enough = FALSE; + }else{ + if( magic[AI_method[0]].mp > p_party[BattleMyNo]->mp ) + mp_enough = FALSE; + } + } + if( mp_enough == FALSE){//û趨ʹòѪ MP + battlePlayerEscFlag = TRUE; + strcpy( moji, "E"); + done = 1; + } + } + if( !done){ + int targetNo; +#ifdef _ATTACK_AI + if(AttackAIProc(4,moji) <= 0) +#endif + { +#ifdef _AI_CAPTURE + extern int nowFloor; + extern int nowGx, nowGy; + if (AI_OtherSetting[1] && (nowFloor!=500||nowGx>=250&&nowGy>=360)){ + targetNo = GetBattelTarget(); + if (p_party[targetNo]->level==1){ + sprintf_s( moji, "T|%X", targetNo ); + AI_Choosen = "Զץ"; + }else{ + AI_Choosen = "ץ"; + battlePlayerEscFlag = TRUE; + strcpy( moji, "E"); + done = 1; + } + }else{ +#endif + targetNo = GetBattelTarget(); + sprintf_s( moji, "H|%X", targetNo ); + AI_Choosen = "Զ"; +#ifdef _AI_CAPTURE + } +#endif + } + + } + } + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + } + done = 0; + strcpy( moji, "W|FF|FF"); + if( pc.battlePetNo>-1 && p_party[BattleMyNo+5]->hp>0 ){ + if( BattleBpFlag & BATTLE_BP_PET_MENU_NON || p_party[ BattleMyNo ]->hp <= 0 || battlePlayerEscFlag == TRUE){ + }else{ + int skill_id = -1; + for( int i = 0; i < pet[pc.battlePetNo].maxSkill; i++){ + if( petSkill[pc.battlePetNo][i].useFlag == TRUE && + petSkill[pc.battlePetNo][i].field != PETSKILL_FIELD_MAP){ + if( skill_id == -1) + skill_id = i; + if( petSkill[pc.battlePetNo][i].skillId!=2 && petSkill[pc.battlePetNo][i].skillId!=0) + skill_id = i; + if( petSkill[pc.battlePetNo][i].skillId == 1){ + skill_id = i; + break; + } + } + } + if( skill_id > -1){ + switch( petSkill[pc.battlePetNo][skill_id].target){ + case PETSKILL_TARGET_MYSELF: + targetNo = BattleMyNo + 5; + break; + case PETSKILL_TARGET_OTHER: + case PETSKILL_TARGET_OTHERWITHOUTMYSELF: + targetNo = GetBattelTarget(); + break; + case PETSKILL_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) targetNo = 20; + else targetNo = 21; + break; + case PETSKILL_TARGET_ALLOTHERSIDE: + if( BattleMyNo < 10 ) targetNo = 21; + else targetNo = 20; + break; + case PETSKILL_TARGET_ALL: + targetNo = 22; + break; + } + sprintf_s( moji, "W|%X|%X", skill_id, targetNo); + } + } + } + if( bNewServer) + lssproto_B_send( sockfd, moji); + else + old_lssproto_B_send( sockfd, moji); + for( int i = 0; i < BATTLKPKPLYAERNUM; i++){ + if( 0 == (p_party[i]->atr & p_party[i]->atr) ) + p_party[i]->atr = ACT_ATR_INFO | ACT_ATR_HIT; + } + p_party[ BattleMyNo ]->atr |= ACT_ATR_BTL_CMD_END; + p_party[ BattleMyNo + 5 ]->atr |= ACT_ATR_BTL_CMD_END; + SubProcNo++; +} + +void AI_CloseWnd() +{ +#ifdef _AIDENGLU_ + extern BOOL Զ½; + extern ACTION *pԶ½; + extern ACTION *; + extern ACTION *ﶯ; + Զ½=0; + if(pԶ½){ + DeathAction(pԶ½); + pԶ½=NULL; + } + if((int)){ + if((int)>1000) + DeathAction(); + =NULL; + if((int)ﶯ>1000) + DeathAction(ﶯ); + ﶯ=NULL; + } +#endif + AI_State = 0; + if( pAISettingWnd){ + DeathAction( pAISettingWnd ); + pAISettingWnd = NULL; + } +#ifdef _AI_OTHER + if(pAIOtherFunctionWnd){ + DeathAction(pAIOtherFunctionWnd); + pAIOtherFunctionWnd = NULL; + AI_Other_State = 0; + } +#endif +} + +#ifdef _AI_OTHER +#ifdef _AI_CAPTURE +#define AI_OTHER_BTN 3 +#else +#define AI_OTHER_BTN 2 +#endif +void AI_OtherProc(){ + static int btnId[AI_OTHER_BTN]; + int x,y,i; +#ifdef _AI_CAPTURE + static char szFunctionName[AI_OTHER_BTN][30] = {"","Զ","Զץ"}; + +#else + static char szFunctionName[AI_OTHER_BTN][30] = {"","Զ"}; +#endif + static char szFunctionSwitch[2][12] = {" "," ٣ţ "}; + if(pAIOtherFunctionWnd == NULL){ + // ս + pAIOtherFunctionWnd = MakeWindowDisp(413,lpDraw->ySize / 2 + 150,3,2,NULL,1, FALSE); + //if(ProcNo == PROC_BATTLE) pAIOtherFunctionWnd = MakeWindowDisp(413,150,3,2,NULL,1, FALSE); + //else pAIOtherFunctionWnd = MakeWindowDisp(413,0,3,2,NULL,1, FALSE); + } + else{ + if(pAIOtherFunctionWnd->hp >= 1 ){ + if(joy_trg[0] & JOY_ESC){ + DeathAction(pAIOtherFunctionWnd); + pAIOtherFunctionWnd = NULL; + AI_Other_State = 0; + return; + } + x = pAIOtherFunctionWnd->x; + y = pAIOtherFunctionWnd->y; + for(i=1;i û , 1 --> ʼ , 2 --> +extern int g_iCurRunEarthQuake; // Ŀǰλ +extern int g_iNumRunEarthQuake; // ܴ + +#endif + +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif +int MessageBoxNew(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); +// ?????????k? +int BattleMapNo = 0; + +#ifdef _NEWDRAWBATTLEMAP_FIX // (ɿ)ROG ADD սͼ޸ +int BattleMapAdvance = 0; // սͼЧܸĽ +#endif +// ?????? ???? +char *BattleMapFile[] = { + #include "../systeminc/battleMapName.h" +}; + +// ?????????????????????? ***************************/ +// ˮرսͼ +static int iCrystalBattleMap[4][3] = +{ // // // // + {29060,29061,29062},{29058,29059,29066},{29063,29064,29065},{29057,29067,29068} +}; + +BOOL ReadBattleMap( int no ) +{ +#ifdef _NEWDRAWBATTLEMAP_FIX // (ɿ)ROG ADD սͼ޸ + extern void ddrawBattleMap(); + ddrawBattleMap(); +#else + char msg[ 256 ]; + FILE *fp; + char header[ 5 ]; + unsigned short tile[ 1089 ]; + int cnt = 0; + int i, j, x = 0, y = 0, posX, posY; + unsigned short c1, c2; + // ???????? + if( no >= BATTLE_MAP_FILES ) + no = 0; + // ??????k??? + BattleMapNo = no; + // ?????????????? + if( ( fp = fopen( BattleMapFile[ no ], "rb" ) ) == NULL ){ + sprintf_s( msg, "%sȡʧܡ", BattleMapFile[ no ] ); + MessageBoxNew( hWnd, msg, "սͼ", MB_OK | MB_ICONSTOP ); + return FALSE; + } + // ???????? + fread( header, sizeof( char ), 4, fp ); + header[ 4 ] = '\0'; + // ???????? + if( !( strstr( header, "SAB" )) ) + MessageBoxNew( hWnd, "SAB ", "սͼ", MB_OK | MB_ICONSTOP ); + // ?????? + for( i = 0 ; i < 1089 ; i++ ){ + // ?????????? ????B????? ? + c1 = fgetc( fp ); + c2 = fgetc( fp ); + // ??????? + tile[ i ] = ( c1 << 8 ) | c2; + } + // ?????? + fclose( fp ); + //ROG FIX սͼͼλַ + //posX = 32 * ( -9 ) + (400 >> 1); + //posY = 24 * 10 + (300 >> 1); + posX = -416; + posY=272; +#ifdef _NEWDRAWBATTLEMAP // Syu ADD ԶBattleMap + extern int nowFloor ; + + if(((nowFloor == 817) || (nowFloor == 8007) || (nowFloor == 8101) || (nowFloor == 8100) || + (nowFloor == 8027) || (nowFloor == 8028) || (nowFloor == 8029) || (nowFloor == 8015) || + (nowFloor == 151) || (nowFloor == 160) || (nowFloor == 161) || (nowFloor >= 30022 && nowFloor <= 30025) || nowFloor == 8113 || nowFloor == 8114 +#ifdef _8BATTLEMAP + || (nowFloor >= 78 && nowFloor <= 99) || nowFloor == 8107 || (nowFloor >= 8108 && nowFloor <= 8112) || (nowFloor >= 8116 && nowFloor <= 8120) || (nowFloor >= 8124 && nowFloor <= 8126) || nowFloor == 7500 || nowFloor == 7530 || nowFloor == 7600 +#endif + ) + && ( RandBattleBg == 0 ) ) + { + RandBattleBg = RAND ( 0 , 4 ); + if ( RandBattleBg == 0 ) RandBattleBg = 29001 ; + else if ( RandBattleBg == 1 ) RandBattleBg = 29020 ; + else if ( RandBattleBg == 2 ) RandBattleBg = 29019 ; + else if ( RandBattleBg == 3 ) RandBattleBg = 29024 ; + else if ( RandBattleBg == 4 ) RandBattleBg = 29025 ; + + RandBattleBg = RAND ( 29047 , 29049 ); + // ˮرսͼ + if(nowFloor == 30022) RandBattleBg = iCrystalBattleMap[0][RAND(0,2)]; + else if(nowFloor == 30023) RandBattleBg = iCrystalBattleMap[1][RAND(0,2)]; + else if(nowFloor == 30024) RandBattleBg = iCrystalBattleMap[2][RAND(0,2)]; + else if(nowFloor == 30025) RandBattleBg = iCrystalBattleMap[3][RAND(0,2)]; +#ifdef _8BATTLEMAP + else if((nowFloor >= 78 && nowFloor <= 99) || nowFloor == 8107 ) RandBattleBg = 29074+RAND(0,2); + else if((nowFloor >= 8108 && nowFloor <= 8112) || (nowFloor >= 8116 && nowFloor <= 8120) || (nowFloor >= 8124 && nowFloor <= 8126) || nowFloor == 7500 || nowFloor == 7530 || nowFloor == 7600 ) RandBattleBg = 29070+RAND(0,3); +#endif + StockDispBuffer ( 400 , 300 , DISP_PRIO_TILE , RandBattleBg , 0 ) ; + } + else if ( ((nowFloor == 817) || (nowFloor == 8007) || (nowFloor == 8101) || (nowFloor == 8100) + || (nowFloor == 8027) || (nowFloor == 8028) || (nowFloor == 8029) || (nowFloor == 8015) || ( nowFloor == 151 ) + || (nowFloor == 160) || (nowFloor == 161) || (nowFloor >= 30022 && nowFloor <= 30025) || nowFloor == 8113 || nowFloor == 8114 +#ifdef _8BATTLEMAP + || (nowFloor >= 78 && nowFloor <= 99) || nowFloor == 8107 || (nowFloor >= 8108 && nowFloor <= 8112) || (nowFloor >= 8116 && nowFloor <= 8120) || (nowFloor >= 8124 && nowFloor <= 8126) || nowFloor == 7500 || nowFloor == 7530 || nowFloor == 7600 +#endif + ) + && (RandBattleBg != 0) ) + StockDispBuffer (400 , 300 , DISP_PRIO_TILE , RandBattleBg , 0 ) ; +#ifdef _SYUTEST2 + else { + RandBattleBg = 29050; + StockDispBuffer ( 320 , 240 , DISP_PRIO_TILE , RandBattleBg , 0 ) ; + } +#else + else if(nowFloor == 8519){ + RandBattleBg = 29069; + StockDispBuffer ( 400 , 300 , DISP_PRIO_TILE , RandBattleBg , 0 ) ; + }else + { + if((RandBattleBg = FreeGetBattleMap(nowFloor))){ + StockDispBuffer ( 400 , 300 , DISP_PRIO_TILE , RandBattleBg , 0 ) ; + }else{ + for( i = 0 ; i < 33 ; i++ ) + { + x = 0; + y = 0; + for( j = 0 ; j < 33 ; j++ ) + { + StockDispBuffer( posX + x, posY + y, DISP_PRIO_TILE, tile[ cnt++ ], 0 ); + x += 32; + y -= 24; + } + posX += 32; + posY += 24; + } + } + } +#endif + +// extern void ddrawBattleMap(); +// ddrawBattleMap(); + +#else + // ?????? + + for( i = 0 ; i < 20 ; i++ ){ + x = 0; + y = 0; + for( j = 0 ; j < 20 ; j++ ){ + // ??????????? + StockDispBuffer( posX + x, posY + y, DISP_PRIO_TILE, tile[ cnt++ ], 0 ); + x += 32; + y -= 24; + } + posX += 32; + posY += 24; + } +#endif +#endif + return TRUE; +} + +// ??????? ***********************************************************/ +#ifdef _NEWDRAWBATTLEMAP_FIX // (ɿ)ROG ADD սͼ޸ +#define RASTER_CLEARANCE 24 //Ч +#else +#define RASTER_CLEARANCE 8 +#endif +int piyo_tbl[]={ + 0,1,2,3,4,5,6,7,8,9,10,10,11,11,11,12, + 12,12,11,11,11,10,9,9,8,7,6,5,4,3,2,1, + 0,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-10,-11,-11,-11,-12, + -12,-12,-11,-11,-11,-10,-9,-9,-8,-7,-6,-5,-4,-3,-2,-1, +}; +int piyo_point = 0; + +void DrawBattleMap( void ) +{ + +#ifdef D3D_ENGINE + RECT destrect = { 0 }; +#else + RECT rect = { 0, 0, DEF_APPSIZEX, DEF_APPSIZEY }; +#endif + + int d0,d1,d6,d7,value; + short bx , by; +#ifdef __ATTACK_MAGIC + + // ͼŻ + +#ifdef _NEWDRAWBATTLEMAP // Syu ADD ԶBattleMap + extern int nowFloor; + if( ( BattleMapNo >= 148 && BattleMapNo <= 150 ) || 2 == g_iRunEarthQuake || + nowFloor == 817 || nowFloor == 8007 || nowFloor == 8101 || nowFloor == 8100 || + nowFloor == 8027 || nowFloor == 8028 || nowFloor == 8029 || nowFloor == 8015 || nowFloor == 8113 || nowFloor == 8114 ){ +#else + if( ( BattleMapNo >= 148 && BattleMapNo <= 150 ) || 2 == g_iRunEarthQuake ){ +#endif +#else + if(BattleMapNo >= 148 && BattleMapNo <= 150){ //??????????? +#endif + d1 = 1; + } else { + d1 = 0; + } + switch( d1 ){ + case 0: + bx = 0; + by = 0; + short x0, y0; + long w, h; + // ??????? + x0 = bx; + y0 = by; + w = rect.right - rect.left; + h = rect.bottom - rect.top; + if( bx >= lpDraw->xSize || bx + w <= 0 || by >= lpDraw->ySize || by + h <= 0 ){ + return; + } + if( bx < 0 ){ + rect.left -= bx; + x0 = 0; + } + if( bx + w > lpDraw->xSize ){ + rect.right -= bx + w - lpDraw->xSize; + } + if( by < 0 ){ + rect.top -= by; + y0 = 0; + } + if( by + h > lpDraw->ySize ){ + rect.bottom -= by + h - lpDraw->ySize; + } +#ifdef _STONDEBUG_ + SurfaceDispCnt++; +#endif +#ifdef D3D_ENGINE + destrect.left = x0; + destrect.top = y0; + destrect.right = x0 + rect.right - rect.left; + destrect.bottom = y0 + rect.bottom - rect.top; + lpDraw->lpd3dDevice->StretchRect(lpBattleSurface, &rect, lpDraw->lpOffScrSurface, &destrect, D3DTEXF_NONE); +#else + lpDraw->lpBACKBUFFER->BltFast( x0, y0, lpBattleSurface, &rect, DDBLTFAST_WAIT ); +#endif +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast(x0,y0,lpBattleSurfaceSys,&rect,DDBLTFAST_WAIT); +#endif + break; + case 1: + + value = piyo_point; + d6 = 0; + + #ifdef __ATTACK_MAGIC + + value += g_iCurRunEarthQuake; + + #endif + + rect.left = 0; //?Z + rect.right = 640 + DISPLACEMENT_X; //?Z + /* if(BattleMapAdvance < 10){ + BattleMapAdvance ++; + return; + } + else + BattleMapAdvance =0;*/ + + for(d7=0; d7 < 480 + DISPLACEMENT_Y; d7+=RASTER_CLEARANCE){ + rect.top = d7 + piyo_tbl[(d6+value) & 63] + 12; //ƣZ + rect.bottom = rect.top + RASTER_CLEARANCE; //?Z + + +#ifdef D3D_ENGINE + destrect.left = 0; + destrect.top = d7; + destrect.right = rect.right - rect.left; + destrect.bottom = d7 + rect.bottom - rect.top; + lpDraw->lpd3dDevice->StretchRect(lpBattleSurface, &rect, lpDraw->lpOffScrSurface, &destrect, D3DTEXF_NONE); +#else + lpDraw->lpBACKBUFFER->BltFast( 0, d7, lpBattleSurface, &rect, DDBLTFAST_WAIT ); +#endif +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast(0,d7,lpBattleSurfaceSys,&rect,DDBLTFAST_WAIT); +#endif + d6++; + } + break; + case 2: + d6 = 0; + for(d7=0; d7<480 + DISPLACEMENT_Y; d7+=RASTER_CLEARANCE/2){ + + rect.top = d7; //ƣZ + rect.bottom = rect.top + RASTER_CLEARANCE; //?Z + + d0 = piyo_tbl[(d6+piyo_point) & 63] / 2; //?Z + if(d0 < 0){ //?????? + rect.left = 0 - d0; + rect.right = 640 + DISPLACEMENT_X+ d0; //?Z + d0 = 0; + } else { + rect.left = 0; + rect.right = 640 + DISPLACEMENT_X- d0; //?Z + } +#ifdef D3D_ENGINE + destrect.left = d0; + destrect.top = d7; + destrect.right = d0 + rect.right - rect.left; + destrect.bottom = d7 + rect.bottom - rect.top; + lpDraw->lpd3dDevice->StretchRect(lpBattleSurface, &rect, lpDraw->lpOffScrSurface, &destrect, D3DTEXF_NONE); +#else + lpDraw->lpBACKBUFFER->BltFast( d0, d7, lpBattleSurface, &rect, DDBLTFAST_WAIT ); +#endif +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast(d0,d7,lpBattleSurfaceSys,&rect,DDBLTFAST_WAIT); +#endif + d6++; + } + break; + } +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/battlemenu.cpp b/石器时代8.5客户端最新源代码/石器源码/system/battlemenu.cpp new file mode 100644 index 0000000..45c7c00 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/battlemenu.cpp @@ -0,0 +1,3908 @@ +/************************/ +/* battleMenu.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/font.h" +#include "../other/caryIme.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/pc.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/t_music.h" +#include "../systeminc/menu.h" +#include "../systeminc/map.h" +#include "../systeminc/field.h" +#include "../systeminc/character.h" + +// ??? +enum{ + BATTLE_ATTACK, + BATTLE_JUJUTU, + BATTLE_CAPTURE, + BATTLE_ITEM, + BATTLE_WAZA, +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BATTLE_PROWAZA, +#endif +}; + +// ??? +#define BATTLE_MENU ( 1 << 0 ) +#define BATTLE_MENU_PET ( 1 << 1 ) + +// ?????? +#define BATTLE_MENU_SUU 9 +#define BATTLE_MENU_FONTS 9 +#define BATTLE_MENU_JUJUTSU_FONTS 6 +#define BATTLE_MENU_ITEM_FONTS 6 +#define BATTLE_MENU_PET_FONTS 7 +#define BATTLE_MENU_WAZA_FONTS 9 + +// ???????? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +#define BATTLE_BUTTON_SUU 10 +#else +#define BATTLE_BUTTON_SUU 9 +#endif + +#ifndef PK_SYSTEM_TIMER_BY_ZHU +#define BATTLE_CNT_DOWN_TIME _BATTLE_TIME_ //ÿսʱ +#endif + +char BattleCmd[ BATTLE_COMMAND_SIZE ]; +// ????????????? +char BattleCmdBak[ BATTLE_BUF_SIZE ][ BATTLE_COMMAND_SIZE ]; +// ?????????????? +int BattleCmdReadPointer; +int BattleCmdWritePointer; + +// ???֢t?? +char BattleStatus[ BATTLE_COMMAND_SIZE ]; +// ???֢t???????? +char BattleStatusBak[ BATTLE_BUF_SIZE ][ BATTLE_COMMAND_SIZE ]; +// ???֢t??????? +int BattleStatusReadPointer; +int BattleStatusWritePointer; +// ??k? +int BattleMyNo = 0; +// Pf????? +int BattleMyMp; +// Pf????? +int BattleEscFlag = FALSE; + +// ???????????? +int BattlePetStMenCnt; + +// ????? +int BattleBpFlag = FALSE; +// ????k? +int BattleCmdNo = -1; +// ӧk? +int BattleJujutuNo; +// ?k? +int BattleWazaNo; +// ӡP???k??????? +int battlePetNoBak = -2; +// ӡP???k???????? +int battlePetNoBak2 = -2; +// ????k? +int BattleItemNo; + +// ?????`????? +int battlePlayerEscFlag = FALSE; + +// ????V?????? +int BattleAnimFlag; +// ?????? +BOOL BattleTurnReceiveFlag; +#ifdef PK_SYSTEM_TIMER_BY_ZHU +BOOL BattleCntDownRest; +BOOL SendToServer; +#endif +int BattleCliTurnNo; +// ??????????k? +int BattleSvTurnNo; + +#ifdef _HUNDRED_KILL +BOOL BattleHundredFlag = FALSE; +#endif + +// Pf?????????? +BOOL BattleResultWndFlag = FALSE; + +// ??????? +DWORD BattleCntDown; +DWORD BattleIntervalCnt; +int AI; +DWORD PauseAI; +// ?????????????? +BOOL BattleCntDownFlag = FALSE; + +// ??????? +static BOOL battleButtonFlag[ BATTLE_BUTTON_SUU ]; +static int battleButtonDispNo[ BATTLE_BUTTON_SUU ]; +static int battleMenuJujutsuFontNo[ BATTLE_MENU_JUJUTSU_FONTS ]; +static int battleMenuItemFontNo[ BATTLE_MENU_ITEM_FONTS ]; +static int battleMenuPetFontNo[ BATTLE_MENU_PET_FONTS ]; +static int battleMenuWazaFontNo[ BATTLE_MENU_WAZA_FONTS ]; +int battleMenuFlag = FALSE; // ?????????????????? +static int battleMenuReturn = FALSE; // ???????????? +static int battlePetMenuFlag = FALSE; // ??????????? +int battlePetButtonFlag = FALSE; // ?????????????? +static int battleTimeUpFlag = FALSE; +static int battleTargetSelectFlag = FALSE; +int battleMenuFlag2 = FALSE; // ????????v?? +int battleButtonBak = -1; // q??????? +static int battleButtonBak2 = -1; // q???????? +int battleWazaTargetBak = -1; // q???k? + +// ?????????????? +static ACTION *pActInfoWnd; +static ACTION *pActWnd = NULL; + +// ???????? +static int buttonX, buttonY, buttonA; + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +int wonflag = 0 ; +int prouseskill = -1 ; +int SkillWnd2 = 0 ; +static int AdvanceSkillBtn[ 26 ] ; +static int AssitSkillBtn[ 26 ]; +static int BattleSkillBtn[ 26 ]; +#endif + +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif +// ?????????? ********************************************************/ +void InitBattleMenu( void ) +{ + int i; + // ??? + for( i = 0 ; i < BATTLE_BUTTON_SUU ; i++ ) battleButtonDispNo[ i ] = -2; + // + for( i = 0 ; i < BATTLE_MENU_JUJUTSU_FONTS ; i++ ) battleMenuJujutsuFontNo[ i ] = -2; + // ???? + for( i = 0 ; i < BATTLE_MENU_ITEM_FONTS ; i++ ) battleMenuItemFontNo[ i ] = -2; + // ??? + for( i = 0 ; i < BATTLE_MENU_PET_FONTS ; i++ ) battleMenuPetFontNo[ i ] = -2; + // ? + for( i = 0 ; i < BATTLE_MENU_WAZA_FONTS ; i++ ) battleMenuWazaFontNo[ i ] = -2; + + battleMenuFlag = FALSE; // ?????????? + battleMenuReturn = TRUE; // ???????????? +// battleButtonBak = -1; // q??????? + battleButtonBak2 = -1; // q???????? + BattleEscFlag = FALSE; // Pf???????? + // Pf?????????? + BattleResultWndFlag = FALSE; + // ??????u??? + ClearBattleButton(); + // ????????????? + battleButtonBak = 0; +#ifdef __AI + extern int AI_First; + AI_First = 1; +#else + if( AI != AI_NONE) + battleButtonBak = -1; +#endif + pActWnd = NULL; // ???????????? + pActInfoWnd = NULL; + // ????V?v???????? + if( battlePetNoBak != -2 ){ + battlePetButtonFlag = FALSE; // ???????? + }else{ + battlePetButtonFlag = TRUE; // ???????? + } + +} + +// ???K?????? ********************************************/ +int CheckBattle1P2P( void ) +{ + int i, cnt = 0; + // ????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ??????? + if( ( (ATR_EQU *)p_party[ i ]->pYobi )->pet_ok == TRUE ) cnt++; + } + if( cnt >= 2 ) return 2; + else return 1; +} + +// ????V??????????? ********************************************/ +void CheckBattleAnimFlag( void ) +{ + int i; + // ??????????????????i???u??????? + if( BattleCliTurnNo != BattleSvTurnNo ){ + // ????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ???????Re + p_party[ i ]->atr |= ACT_ATR_BTL_CMD_END; + } + return; + } + // ????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ???????Re + if( ( BattleAnimFlag >> i ) & 0x00000001 ) + p_party[ i ]->atr |= ACT_ATR_BTL_CMD_END; + } +} + +// ????V?????????? ********************************************/ +void InitBattleAnimFlag( void ) +{ + int i; + // ????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ???????Re + p_party[ i ]->atr &= ~ACT_ATR_BTL_CMD_END; + } +} + +// ????????? *******************************************************/ +int CheckPetSuu( void ) +{ + int i,cnt = 0; + for( i = 0 ; i < 5 ; i++ ){ + if( pet[ i ].useFlag == TRUE ) cnt++; + } + return cnt; +} + +// ???Re????? *****************************************************/ +void ClearBoxFlag( void ) +{ + int i; + // ???Re????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ???Re?????????? + + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL1; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL2; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL3; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL4; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL5; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL6; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL7; + p_party[i]->atr &= ~ACT_ATR_HIT_BOX_COL8; + + + p_party[ i ]->atr &= ~ACT_ATR_HIT_BOX; + p_party[ i ]->atr &= ~ACT_ATR_HIT_BOX_ALL1; + p_party[ i ]->atr &= ~ACT_ATR_HIT_BOX_ALL2; + p_party[ i ]->atr &= ~ACT_ATR_HIT_BOX_ALL3; + p_party[ i ]->atr &= ~ACT_ATR_HIT_BOX_ALL4; + p_party[ i ]->atr |= ACT_ATR_HIT; + // ???Rek???? + p_party[ i ]->hitDispNo = -2; + } +} + +// ??????????Re ***************************************************/ +int CheckBattelTarget( void ) +{ + int i; + // ????????????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // k?????? + + + if( !( p_party[i]->atr & ACT_ATR_HIT_BOX ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_ALL1 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_ALL2 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_ALL3 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_ALL4 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL1 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL2 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL3 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL4 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL5 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL6 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL7 ) && + !( p_party[i]->atr & ACT_ATR_HIT_BOX_COL8 )) continue; + +#ifdef _CANT_ATK + if( !((pc.sideNo*10) <= i && ((pc.sideNo+1)*10) > i) ) +#endif + // ??????? + if( p_party[ i ]->hitDispNo == HitDispNo ) + return i; + } + // ???????? + return -1; +} + +// ??????u??? *****************************************************/ +void ClearBattleButton( void ) +{ + // ???? + memset( battleButtonFlag, 0, sizeof( battleButtonFlag ) ); +} + +// ???????????????? *******************************************/ +void BattleButtonOff( void ) +{ + play_se( 217, 320, 240 ); + // ??????????? + DeathAction( pActWnd ); + pActWnd = NULL; // ???????????? + // ??????????????? + battleTargetSelectFlag = FALSE; + // ????k? + BattleCmdNo = -1; + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + wonflag = 0 ; +#endif + + // ??????u??? + ClearBattleButton(); + // ???Re????? + ClearBoxFlag(); +} + +// ?????????? *******************************************************/ +void InitItem2( int x, int y ) +{ + int i, j = 0, k = 0; + // ???????? + for( i = MAX_ITEMSTART ; i < MAX_ITEM ; i++ ){ + ItemBuffer[ i ].defX = x + 32 + j; + ItemBuffer[ i ].defY = y + 56 + 48 + 48 + 48 -160 + k; + ItemBuffer[ i ].x = ItemBuffer[ i ].defX; + ItemBuffer[ i ].y = ItemBuffer[ i ].defY; + ItemBuffer[ i ].bmpNo = 20000 + j / 48; + ItemBuffer[ i ].dispPrio = DISP_PRIO_ITEM; + j += 51; + if( j >= 48 * 5 ){ + j = 0; +#ifdef _NEW_ITEM_ + if(k>=48*2){ + k=0; + }else k += 48; +#else + k += 48; +#endif + + } + } +} + +// o?????? ***********************************************************/ +void HpMeterDisp( int no ) +{ + int meterX = p_party[ no ]->x; + int meterY = p_party[ no ]->y - 80; + int graNo; + // V?????????????? + if( p_party[ no ]->func == NULL || p_party[ no ]->hp <= 0 ) return; + // ????? + if( p_party[ no ]->atr & ACT_ATR_TRAVEL ) return; + // ?? + if( no == BattleMyNo ){ + // ? + StockDispBuffer( meterX, meterY, DISP_PRIO_IME1, CG_BATTLE_BAR_PLAYER_2, 0 ); + // o?? + StockBoxDispBuffer( meterX - 21, + meterY - 3, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->hp / (double)p_party[ BattleMyNo ]->maxHp ) * 40.0 ), + meterY - 3, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + StockBoxDispBuffer( meterX - 21, + meterY - 2, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->hp / (double)p_party[ BattleMyNo ]->maxHp ) * 40.0 ), + meterY - 2, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + // ?? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + StockBoxDispBuffer( meterX - 21, + meterY + 1, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->mp / (double)p_party[ BattleMyNo ]->maxMp ) * 40.0 ), + meterY + 1, + DISP_PRIO_IME2, SYSTEM_PAL_YELLOW, 2 ); + StockBoxDispBuffer( meterX - 21, + meterY + 2, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->mp / (double)p_party[ BattleMyNo ]->maxMp ) * 40.0 ), + meterY + 2, + DISP_PRIO_IME2, SYSTEM_PAL_YELLOW, 2 ); +#else + StockBoxDispBuffer( meterX - 21, + meterY + 1, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->mp / pc.maxMp ) * 40.0 ), + meterY + 1, + DISP_PRIO_IME2, SYSTEM_PAL_YELLOW, 2 ); + StockBoxDispBuffer( meterX - 21, + meterY + 2, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->mp / pc.maxMp ) * 40.0 ), + meterY + 2, + DISP_PRIO_IME2, SYSTEM_PAL_YELLOW, 2 ); +#endif + //cary ijѪ + if( p_party[ BattleMyNo ]->onRide > 0 ){ + meterY += 25; + meterX += 20; + // ? + StockDispBuffer( meterX , meterY, DISP_PRIO_IME1, CG_BATTLE_BAR_PET_2, 0 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY - 1, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->petHp / (double)p_party[ BattleMyNo ]->petMaxHp ) * 40.0 ), + meterY - 1, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY + 0, + meterX - 21 + (int)( ( (double)p_party[ BattleMyNo ]->petHp / (double)p_party[ BattleMyNo ]->petMaxHp ) * 40.0 ), + meterY + 0, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + } + }else{ // ???? + if( no == BattleMyNo + 5 ) graNo = CG_BATTLE_BAR_PET_2; + else graNo = CG_BATTLE_BAR_PET; + // ? + StockDispBuffer( meterX , meterY, DISP_PRIO_IME1, graNo, 0 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY - 1, + meterX - 21 + (int)( ( (double)p_party[ no ]->hp / (double)p_party[ no ]->maxHp ) * 40.0 ), + meterY - 1, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY + 0, + meterX - 21 + (int)( ( (double)p_party[ no ]->hp / (double)p_party[ no ]->maxHp ) * 40.0 ), + meterY + 0, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + //cary ijѪ + if( p_party[ no ]->onRide > 0 ){ + meterY += 25; + meterX += 20; + // ? + StockDispBuffer( meterX , meterY, DISP_PRIO_IME1, CG_BATTLE_BAR_PET, 0 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY - 1, + meterX - 21 + (int)( ( (double)p_party[ no ]->petHp / (double)p_party[ no ]->petMaxHp ) * 40.0 ), + meterY - 1, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + // o????????? + StockBoxDispBuffer( meterX - 21, + meterY + 0, + meterX - 21 + (int)( ( (double)p_party[ no ]->petHp / (double)p_party[ no ]->petMaxHp ) * 40.0 ), + meterY + 0, + DISP_PRIO_IME2, SYSTEM_PAL_GREEN, 2 ); + } + } +} + +// q? ************************************************************************/ +void BattleNameDisp( void ) +{ + + + int i; + int color = FONT_PAL_WHITE; + // q???????? + if( nameOverTheHeadFlag != TRUE ) return; + // ????????????? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?? + if( i == BattleMyNo || i == ( BattleMyNo + 5 ) ) + color = FONT_PAL_YELLOW; + else + color = FONT_PAL_WHITE; + char token[256]; + sprintf_s(token,"%s LV%d",p_party[ i ]->name,p_party[ i ]->level); + StockFontBuffer( p_party[ i ]->x - GetStrWidth( token )/2, p_party[ i ]->y - 10, FONT_PRIO_BACK, color, token, 0 ); + } +} + +/* +void BattleButtonAttack( void ) +{ + int i, j, bak; + if( HitDispNo == battleButtonDispNo[ 0 ] || battleButtonBak2 == 0 ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 0 ){ + bak = battleButtonFlag[ 0 ]; + BattleButtonOff(); + + if( bak == FALSE ){ + + battleTargetSelectFlag = TRUE; + + BattleCmdNo = BATTLE_ATTACK; + + battleButtonFlag[ 0 ] = TRUE; + + battleButtonBak = 0; + + battleButtonBak2 = -1; + int hitBoxAll; + int k; + if( BattleBpFlag & BATTLE_BP_BOOMERANG ){ + + hitBoxAll = ACT_ATR_HIT_BOX_ALL1; + j = 0; + + for( i = 0 ; i < BATTLESIDENUM * 2 ; i++ ){ + + if( !( j <= BattleMyNo && BattleMyNo < j + 5 ) ){ + + for( k = j ; k < j + 5 ; k++ ){ + + if( p_party[ k ]->func == NULL ) continue; + + if( p_party[ k ]->hp <= 0 ) continue; + + if( p_party[ k ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ k ]->atr |= hitBoxAll; + } + + hitBoxAll <<= 1; + } + j += 5; + } + for( i = 0 ; i < BATTLESIDENUM * 2 ; i++ ){ + for(j = i * 5; j < (i + 1) * 5; j ++){ + if( p_party[ j ]->func == NULL ) continue; + + if( p_party[ j ]->hp <= 0 ) continue; + + if( p_party[ j ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ j ]->atr |= (ACT_ATR_HIT_BOX_COL1 << i); + } + } + }else{ + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( i == BattleMyNo ) continue; + + if( p_party[ i ]->func == NULL ) continue; + + if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + } + } + } + strcpy( OneLineInfoStr,""); + } +} +*/ +void BattleButtonAttack( void ) +{ + int i, j, k, bak, hitBoxAll; + if( HitDispNo == battleButtonDispNo[ 0 ] || battleButtonBak2 == 0 ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 0 ){ + bak = battleButtonFlag[ 0 ]; + BattleButtonOff(); + + if( bak == FALSE ){ + + battleTargetSelectFlag = TRUE; + + BattleCmdNo = BATTLE_ATTACK; + + battleButtonFlag[ 0 ] = TRUE; + + battleButtonBak = 0; + + battleButtonBak2 = -1; + + if( BattleBpFlag & BATTLE_BP_BOOMERANG ){ + + hitBoxAll = ACT_ATR_HIT_BOX_ALL1; + j = 0; + + for( i = 0 ; i < 4 ; i++ ){ + + if( !( j <= BattleMyNo && BattleMyNo < j + 5 ) ){ + + for( k = j ; k < j + 5 ; k++ ){ + + if( p_party[ k ]->func == NULL ) continue; + + if( p_party[ k ]->hp <= 0 ) continue; + + if( p_party[ k ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ k ]->atr |= hitBoxAll; + } + + hitBoxAll <<= 1; + } + j += 5; + } + }else{ + + for( i = 0 ; i < 20 ; i++ ){ + + if( i == BattleMyNo ) continue; + + if( p_party[ i ]->func == NULL ) continue; + + if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + } + } + } + strcpy( OneLineInfoStr,""); + } +} + + + + +void BattleButtonJujutsu( void ) +{ + int i, x, y, bak; + char moji[ 256 ]; + if( HitDispNo == battleButtonDispNo[ 1 ] || battleButtonBak2 == 1 ){ +#ifdef _MAGIC_NOCAST + if( NoCastFlag == FALSE ) + { +#endif + + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 1 ){ + bak = battleButtonFlag[ 1 ]; + BattleButtonOff(); + + if( bak == FALSE ){ + + battleButtonFlag[ 1 ] = TRUE; + + BattleCmdNo = BATTLE_JUJUTU; + + for( i = 0 ; i < BATTLE_MENU_JUJUTSU_FONTS ; i++ ) battleMenuJujutsuFontNo[ i ] = -2; +#ifdef _NEW_WIN_POS_ + pActWnd = MakeWindowDisp( 520, 140, 271, 281, 0, -1 , FALSE ); +#else + pActWnd = MakeWindowDisp( 380, 140, 271, 281, 0, -1 , FALSE ); +#endif + battleButtonBak = 1; + + battleButtonBak2 = -1; + } + } + + strcpy( OneLineInfoStr, ""); +#ifdef _MAGIC_NOCAST + } + else + { + strcpy( OneLineInfoStr, "Ĭ޷"); + } +#endif + } +#ifdef _MAGIC_NOCAST + if(!( NoCastFlag == FALSE )){ + battleButtonFlag[ 1 ] = FALSE; + } +#endif + + if( battleButtonFlag[ 1 ] == TRUE ){ + + if( pActWnd != NULL ){ + + if( pActWnd->hp > 0 ){ + x = pActWnd->x + 74; + y = pActWnd->y + 208; + +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my + 7, DISP_PRIO_MENU, CG_JUJUTU_WND, 1 ); + else +#endif + StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my + 4, DISP_PRIO_MENU, CG_JUJUTU_WND, 1 ); + + for( i = 0 ; i < 5 ; i++ ){ + + if( HitFontNo == battleMenuJujutsuFontNo[ i ] && magic[ i ].useFlag == TRUE ){ + + char *splitPoint = magic[ i ].memo; + + sprintf_s( moji,"%2d/%2d", magic[ i ].mp, p_party[ BattleMyNo ]->mp ); + StockFontBuffer( pActWnd->x + 74 + 81, pActWnd->y + 183, FONT_PRIO_FRONT, 0, moji, 0 ); + + while( 1 ){ + + if( strlen( splitPoint ) > 22 ){ + strncpy_s( moji, splitPoint, 22 ); + moji[ 22 ] = NULL; + + if( GetStrLastByte( moji ) == 3 ){ + moji[ 21 ] = NULL; + splitPoint += 21; + }else{ + moji[ 22 ] = NULL; + splitPoint += 22; + } + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); y += 24; + }else{ + strcpy( moji, splitPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); + break; + } + } + + StockDispBuffer( pActWnd->x + 37, pActWnd->y + 220, DISP_PRIO_ITEM, pc.item[ i ].graNo, 0 ); + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + + if( magic[ i ].field == MAGIC_FIELD_MAP || magic[ i ].mp > p_party[ BattleMyNo ]->mp ){ + play_se( 220, 320, 240 ); + }else{ + BattleJujutuNo = i; + + battleTargetSelectFlag = TRUE; + + switch( magic[ i ].target ){ + case MAGIC_TARGET_MYSELF: + + p_party[ BattleMyNo ]->atr |= ACT_ATR_HIT_BOX; + + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_OTHER: + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) + if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + + #ifdef __ATTACK_MAGIC + + case MAGIC_TARGET_SINGLE: + + if( BattleMyNo < 10 ) + { + for( i = 10 ; i < 20 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[ BattleJujutuNo ].deadTargetFlag ) + if( p_party[ i ]->hp <= 0 ) + continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + } + else + { + for( i = 0 ; i < 10 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[ BattleJujutuNo ].deadTargetFlag ) + if( p_party[ i ]->hp <= 0 ) + continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + } + + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); + BattleCmdNo = BATTLE_JUJUTU; + play_se( 217 , 320 , 240 ); + + break; + + case MAGIC_TARGET_ONE_ROW: + + for( i = 0 ; i < 5 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) + continue; + + if( p_party[i]->atr & ACT_ATR_TRAVEL ) + continue; + + // µڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL4; + } + + for( i = 5 ; i < 10 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) + continue; + + if( p_party[i]->atr & ACT_ATR_TRAVEL ) + continue; + + // µһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL3; + } + + for( i = 10 ; i < 15 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) + continue; + + if( p_party[i]->atr & ACT_ATR_TRAVEL ) + continue; + + // ϵһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL1; + } + + for( i = 15 ; i < 20 ; i++ ) + { + if( p_party[i]->func == NULL ) + continue; + + if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) + continue; + + if( p_party[i]->atr & ACT_ATR_TRAVEL ) + continue; + + // ϵڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL2; + } + + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); + BattleCmdNo = BATTLE_JUJUTU; + play_se( 217 , 320 , 240 ); + + break; + + case MAGIC_TARGET_ALL_ROWS: + + if( BattleMyNo >= 10 ) + { + for( i = 0 ; i < 10 ; i++ ) + { + if( p_party[ i ]->func == NULL ) + continue; + + if( FALSE == magic[ BattleJujutuNo ].deadTargetFlag ) + if( p_party[ i ]->hp <= 0 ) + continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) + continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + } + else + { + for( i = 10 ; i < 20 ; i++ ) + { + if( p_party[ i ]->func == NULL ) + continue; + + if( FALSE == magic[ BattleJujutuNo ].deadTargetFlag ) + if( p_party[ i ]->hp <= 0 ) + continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) + continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } + + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); + BattleCmdNo = BATTLE_JUJUTU; + play_se( 217 , 320 , 240 ); + + break; + + #endif + + case MAGIC_TARGET_ALLMYSIDE: + + if( BattleMyNo < 10 ){ + + for( i = 0 ; i < 10 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + }else{ + + for( i = 10 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_ALLOTHERSIDE: + + if( BattleMyNo >= 10 ){ + + for( i = 0 ; i < 10 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + }else{ + + for( i = 10 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_ALL: + + for( i = 0 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_WHOLEOTHERSIDE: + + for( i = 0 ; i < 10 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + + for( i = 10 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( magic[ BattleJujutuNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + if( p_party[ i ]->atr & ACT_ATR_TRAVEL ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_JUJUTU; + + play_se( 217, 320, 240 ); + break; + } + } + } + } + } + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + + if( HitDispNo == battleMenuJujutsuFontNo[ 5 ] ){ + BattleButtonOff(); + } + } + + if( pActWnd != NULL ){ + int flag = FALSE; + int col; + + x = pActWnd->x + 30; + y = pActWnd->y + 35; + + for( i = 0 ; i < 5 ; i++ ){ + + if( magic[ i ].useFlag == TRUE ){ + col = FONT_PAL_WHITE; + if( magic[ i ].mp > p_party[ BattleMyNo ]->mp ) col = FONT_PAL_RED; // ??ۢK?? + if( magic[ i ].field == MAGIC_FIELD_MAP ) col = FONT_PAL_GRAY; // ????? + + CenteringStr( magic[ i ].name, moji, MAGIC_NAME_LEN ); + battleMenuJujutsuFontNo[ i ] = StockFontBuffer( x, y, FONT_PRIO_FRONT, col, moji, 2 ); y += 28; + flag = TRUE; + } + } + if( flag == FALSE ) StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, "û", 0 ); + + battleMenuJujutsuFontNo[ 5 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, pActWnd->y + 262 + 10, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + } + } + } + } +} + +// ????? *****************************************************************/ +void BattleButtonCapture( void )//׽ +{ + int i, bak; + if( HitDispNo == battleButtonDispNo[ 2 ] || battleButtonBak2 == 2 ){ + // ????????? + if( CheckPetSuu() >= 5 ){ + // ?????? + strcpy( OneLineInfoStr,"ٲijˡ"); + // ????????? + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + // ??? + play_se( 220, 320, 240 ); + } + // q???????? + battleButtonBak2 = -1; + }else{ + // ?????? + strcpy( OneLineInfoStr,"׽"); + // ????????? + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 2 ){ + bak = battleButtonFlag[ 2 ]; // ?????? + BattleButtonOff(); // ?????u??????? + // ????????? + if( bak == FALSE ){ + // ?????????????? + battleTargetSelectFlag = TRUE; + // ????k? + BattleCmdNo = BATTLE_CAPTURE; + // ????????? + battleButtonFlag[ 2 ] = TRUE; + // ???????? + battleButtonBak = 2; + // q???????? + battleButtonBak2 = -1; + // ???Re???? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // s???? + if( ( (ATR_EQU *)p_party[ i ]->pYobi )->group_flg == ( (ATR_EQU *)p_party[ BattleMyNo ]->pYobi )->group_flg ) continue; + // ???? + if( i == BattleMyNo ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ???Re????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + } + } + } + } +} + + +void BattleButtonHelp( void ) +{ + if( HitDispNo == battleButtonDispNo[ 3 ] && battleButtonFlag[ 3 ] == FALSE ){ + + strcpy( OneLineInfoStr, "ȡ"); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + + if( NoHelpFlag == TRUE ){ + + play_se( 220, 320, 240 ); + }else{ + + if( helpFlag == TRUE ){ + helpFlag = FALSE; + }else{ + helpFlag = TRUE; + } + + if( bNewServer) + lssproto_HL_send( sockfd, helpFlag ); + else + old_lssproto_HL_send( sockfd, helpFlag ); + + play_se( 217, 320, 240 ); + } + } + } +} + + +void BattleButtonGuard( void ) +{ + if( HitDispNo == battleButtonDispNo[ 4 ] && battleButtonFlag[ 4 ] == FALSE ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + BattleButtonOff(); + + battleButtonFlag[ 4 ] = TRUE; + + if( bNewServer) + lssproto_B_send( sockfd, "G" ); + else + old_lssproto_B_send( sockfd, "G" ); + + battleMenuReturn = TRUE; + + battleButtonBak = -1; + + battleButtonBak2 = -1; + + play_se( 203, 320, 240 ); + } + + strcpy( OneLineInfoStr, ""); + } +} +#ifdef _NEW_ITEM_ +extern int ҳ; +#endif + +void BattleButtonItem( void ) +{ + int i, bak; + char moji[ 256 ]; + int x, y; + if( HitDispNo == battleButtonDispNo[ 5 ] || battleButtonBak2 == 5 ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 5 ){ + bak = battleButtonFlag[ 5 ]; + BattleButtonOff(); + + if( bak == FALSE ){ + + battleButtonFlag[ 5 ] = TRUE; + + BattleCmdNo = BATTLE_ITEM; + + for( i = 0 ; i < BATTLE_MENU_ITEM_FONTS ; i++ ) battleMenuItemFontNo[ i ] = -2; + +#ifdef _NEW_WIN_POS_ + pActWnd = MakeWindowDisp( 520, 160, 271, 281, 0, -1 , FALSE ); +#ifdef _NEW_ITEM_ + ҳ=0; +#endif +#else + pActWnd = MakeWindowDisp( 380, 160, 271, 281, 0, -1 , FALSE ); +#endif + InitItem2( pActWnd->x, pActWnd->y ); + + battleButtonBak = 5; + + battleButtonBak2 = -1; + } + } + + strcpy( OneLineInfoStr, "ʹõߡ"); + } + + if( battleButtonFlag[ 5 ] == TRUE ){ + + if( pActWnd != NULL ){ + + if( pActWnd->hp > 0 ){ +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my, DISP_PRIO_MENU, CG_ITEM_WND_1, 1 ); + else +#endif + StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my - 0, DISP_PRIO_MENU, CG_ITEM_WND_1, 1 ); + + StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my - 80, DISP_PRIO_MENU, CG_BTL_ITEM_WND_TITLE, 1 ); + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + + if( HitDispNo == battleMenuItemFontNo[ 0 ] ){ + BattleButtonOff(); + } + } + + if( pActWnd != NULL ){ +#ifdef _MAPITEMNO_ + extern int nowFloor; +#endif + x = pActWnd->x + 16; + y = pActWnd->y + 191 + 7; +#ifdef _NEW_ITEM_ + for(i=0;i<3;i++){ + if(i==ҳ){ + StockDispBuffer(513,182+i*56, DISP_PRIO_IME3,55113+i, 1); + }else{ + BOOL flg=FALSE; + if(i){ + if(pc.״̬&1<= MAX_ITEMSTART ; i-- ){ +#ifdef _NEW_ITEM_ + int ʼ = MAX_ITEMSTART+MAX_MAXHAVEITEM*ҳ; + int ߽ = ʼ+MAX_MAXHAVEITEM; + if(i>=MAX_ITEMSTART){ + if(i<ʼ||i>=߽) continue; + } +#endif + if( MakeHitBox( ItemBuffer[ i ].defX - 24, ItemBuffer[ i ].defY - 24, + ItemBuffer[ i ].defX + 25, ItemBuffer[ i ].defY + 23, DISP_PRIO_IME3 ) == TRUE ){ + + if( pc.item[ i ].useFlag == TRUE ){ + int color = FONT_PAL_WHITE; + + char *splitPoint = pc.item[ i ].memo; + + if( pc.transmigration == 0 && pc.level < pc.item[ i ].level ) color = FONT_PAL_RED; + + StockFontBuffer( pActWnd->x + 16, pActWnd->y + 332 - 160, FONT_PRIO_FRONT, color, pc.item[ i ].name, 0 ); + + while( 1 ){ + + if( strlen( splitPoint ) > 28 ){ + strncpy_s( moji, splitPoint, 28 ); + moji[ 28 ] = NULL; + + if( GetStrLastByte( moji ) == 3 ){ + moji[ 27 ] = NULL; + splitPoint += 27; + }else{ + moji[ 28 ] = NULL; + splitPoint += 28; + } + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); y += 24; + }else{ + strcpy( moji, splitPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); + break; + } + } + } + + if( mouse.onceState & MOUSE_LEFT_DBL_CRICK ){ + + if( pc.item[ i ].useFlag == TRUE ){ + + if( pc.item[ i ].useFlag != TRUE || pc.item[ i ].field == ITEM_FIELD_MAP || pc.transmigration == 0 && pc.level < pc.item[ i ].level ){ + + play_se( 220, 320, 240 ); + }else{ + BattleItemNo = i; + + switch( pc.item[ i ].target ){ + case ITEM_TARGET_MYSELF: + + p_party[ BattleMyNo ]->atr |= ACT_ATR_HIT_BOX; + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_OTHER: + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALLMYSIDE: + + if( BattleMyNo < 10 ){ + + for( i = 0 ; i < 10 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + } + + else{ + + for( i = 10 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALLOTHERSIDE: + + if( BattleMyNo >= 10 ){ + + for( i = 0 ; i < 10 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + }else{ + + for( i = 10 ; i < 20 ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALL: + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_NONE: + + BattleButtonOff(); + battleMenuReturn = TRUE; + + if( bNewServer) + lssproto_ID_send( sockfd, nowGx, nowGy, i, 0 ); + else + old_lssproto_ID_send( sockfd, nowGx, nowGy, i, 0 ); + + play_se( 203, 320, 240 ); + + battleTargetSelectFlag = FALSE; + break; + + case ITEM_TARGET_OTHERWITHOUTMYSELF: + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( i == BattleMyNo ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_WITHOUTMYSELFANDPET: + + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + + if( p_party[ i ]->func == NULL ) continue; + + if( i == BattleMyNo + 5 ) continue; + + if( i == BattleMyNo ) continue; + + if( pc.item[ BattleItemNo ].deadTargetFlag == FALSE ) if( p_party[ i ]->hp <= 0 ) continue; + + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } + + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + BattleCmdNo = BATTLE_ITEM; + + play_se( 217, 320, 240 ); + break; +#ifdef _PET_ITEM + case ITEM_TARGET_PET: // սвɸװ + StockChatBufferLine("սвɸװ",FONT_PAL_RED); + break; +#endif + } + break; + } + } + } + } + if( pc.item[ i ].useFlag == TRUE ){ + StockDispBuffer( ItemBuffer[ i ].defX, ItemBuffer[ i ].defY, ItemBuffer[ i ].dispPrio, pc.item[ i ].graNo, 0 ); + } + } + + if( pActWnd != NULL ){ + battleMenuItemFontNo[ 0 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, pActWnd->y + 262, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + } + } + } + } + } +} + + +void BattleButtonPet( void ) +{ + int i, bak; + char moji[ 256 ]; + int x, y; + int flag = FALSE; + int atrFlag = FALSE; + int atrGraNo[ 4 ]; + int color; + if( HitDispNo == battleButtonDispNo[ 6 ] || battleButtonBak2 == 6 ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK || battleButtonBak2 == 6 ){ + bak = battleButtonFlag[ 6 ]; + BattleButtonOff(); + + if( bak == FALSE ){ + + battleButtonFlag[ 6 ] = TRUE; + + for( i = 0 ; i < BATTLE_MENU_PET_FONTS ; i++ ) battleMenuPetFontNo[ i ] = -2; +#ifdef _NEW_WIN_POS_ + pActWnd = MakeWindowDisp( 520 , 160, 271, 281, 0, -1 , FALSE ); +#else + pActWnd = MakeWindowDisp( 380, 160, 271, 281, 0, -1 , FALSE ); +#endif + battleButtonBak = 6; + + battleButtonBak2 = -1; + } + } + + strcpy( OneLineInfoStr, ""); + } + + if( battleButtonFlag[ 6 ] == TRUE ){ + if( pActWnd != NULL ){ + if( pActWnd->hp > 0 ){ + + StockDispBuffer(((WINDOW_DISP*)pActWnd->pYobi)->mx,((WINDOW_DISP*)pActWnd->pYobi)->my,DISP_PRIO_MENU,CG_BTL_PET_CHANGE_WND,1); + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + for( i = 0 ; i < 5 ; i++ ){ + if( pet[ i ].useFlag == TRUE && pc.selectPetNo[ i ] == TRUE ){ + if( HitFontNo == battleMenuPetFontNo[ i ] ){ + if( pet[ i ].hp > 0 && i != pc.battlePetNo ){ + sprintf_s( moji, "S|%d", i ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 203, 320, 240 ); + + DeathAction( pActWnd ); + + pActWnd = NULL; + + battleMenuReturn = TRUE; + + battleButtonBak = -1; + + battleButtonBak2 = -1; + }else{ + play_se( 220, 320, 240 ); + } + } + } + } + + if( HitDispNo == battleMenuPetFontNo[ 5 ] && pc.battlePetNo != -1 ){ + + if( bNewServer) + lssproto_B_send( sockfd, "S|-1" ); + else + old_lssproto_B_send( sockfd, "S|-1" ); + + play_se( 203, 320, 240 ); + + DeathAction( pActWnd ); + + pActWnd = NULL; + + battleMenuReturn = TRUE; + + battleButtonBak = -1; + + battleButtonBak2 = -1; + } + + if( HitDispNo == battleMenuPetFontNo[ 6 ] ){ + BattleButtonOff(); + } + } + + if( pActWnd != NULL ){ + x = pActWnd->x + 17, y = pActWnd->y + 10; + + for( i = 0 ; i < 5 ; i++ ){ + + if( pet[ i ].useFlag == TRUE && pc.selectPetNo[ i ] == TRUE ){ + atrFlag = FALSE; + color = FONT_PAL_AQUA; + if( pet[ i ].hp <= 0 ) color = FONT_PAL_RED; + if( i == pc.battlePetNo ) color = FONT_PAL_YELLOW; + + if( pet[ i ].freeName[ 0 ] != NULL ) + CenteringStr( pet[ i ].freeName, moji, PET_NAME_LEN ); + else + CenteringStr( pet[ i ].name, moji, PET_NAME_LEN ); + battleMenuPetFontNo[ i ] = StockFontBuffer( x, y, FONT_PRIO_FRONT, color, moji, 2 ); + + if( pet[ i ].earth > 0 ){ + if( pet[ i ].earth > 50 ) atrGraNo[ atrFlag ] = CG_ATR_ICON_EARTH_BIG; + else atrGraNo[ atrFlag ] = CG_ATR_ICON_EARTH_SML; + atrFlag++; + } + if( pet[ i ].water > 0 ){ + if( pet[ i ].water > 50 ) atrGraNo[ atrFlag ] = CG_ATR_ICON_WATER_BIG; + else atrGraNo[ atrFlag ] = CG_ATR_ICON_WATER_SML; + atrFlag++; + } + if( pet[ i ].fire > 0 ){ + if( pet[ i ].fire > 50 ) atrGraNo[ atrFlag ] = CG_ATR_ICON_FIRE_BIG; + else atrGraNo[ atrFlag ] = CG_ATR_ICON_FIRE_SML; + atrFlag++; + } + if( pet[ i ].wind > 0 ){ + if( pet[ i ].wind > 50 ) atrGraNo[ atrFlag ] = CG_ATR_ICON_WIND_BIG; + else atrGraNo[ atrFlag ] = CG_ATR_ICON_WIND_SML; + atrFlag++; + } + + if( atrFlag > 0 ) StockDispBuffer( pActWnd->x + 214, y + 8, DISP_PRIO_IME3, atrGraNo[ 0 ], 0 ); + + if( atrFlag > 1 ) StockDispBuffer( pActWnd->x + 214 + 16 , y + 8, DISP_PRIO_IME3, atrGraNo[ 1 ], 0 ); + y += 26; +#ifdef _NEWFONT_ + sprintf_s( moji, "%3d", pet[ i ].level); + StockFontBuffer( x + 27, y, FONT_PRIO_FRONT, color, moji, 0 ); + sprintf_s( moji, "%4d", pet[ i ].hp); + StockFontBuffer( x + 110, y, FONT_PRIO_FRONT, color, moji, 0 ); + sprintf_s( moji, "%4d", pet[ i ].maxHp); + StockFontBuffer( x + 160, y, FONT_PRIO_FRONT, color, moji, 0 ); +#else + sprintf_s( moji, "%3d %4d %4d", pet[ i ].level, pet[ i ].hp, pet[ i ].maxHp ); + StockFontBuffer( x + 27, y, FONT_PRIO_FRONT, color, moji, 0 ); +#endif + y += 25; + sprintf_s( moji, "%3d", pet[ i ].ai ); + StockFontBuffer( x + 60, y, FONT_PRIO_FRONT, color, moji, 0 ); y += 36; + flag = TRUE; + } + } + + if( flag == TRUE ){ + if( pc.battlePetNo != -1 ){ + battleMenuPetFontNo[ 5 ] = StockDispBuffer( pActWnd->x + 70, pActWnd->y + 367, DISP_PRIO_IME3, CG_BTL_PET_RETURN_BTN, 2 ); + battleMenuPetFontNo[ 6 ] = StockDispBuffer( pActWnd->x + 187, pActWnd->y + 367, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + }else{ + battleMenuPetFontNo[ 6 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, pActWnd->y + 367, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + } + }else{ + StockFontBuffer( x + 11, y, FONT_PRIO_FRONT, 0, "ûвսij", 0 ); + battleMenuPetFontNo[ 6 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, pActWnd->y + 367, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + } + } + } + } + } +} +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +void BattleButtonPPLSKILL( void ) +{ + if ( MenuToggleFlag & JOY_ESC || MenuToggleFlag & JOY_CTRL_E || MenuToggleFlag & JOY_CTRL_A) { + //play_se( 220, 320, 240 ); + return; + } + char msg[256] = ""; + char buf[256]; + char msg2[256]; + if( HitDispNo == battleButtonDispNo[ 9 ] ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + play_se( 217, 320, 240 ); + DeathAction( pActWnd ); + pActWnd = NULL; + battleTargetSelectFlag = FALSE; + BattleCmdNo = -1; + ClearBattleButton(); + ClearBoxFlag(); + //MenuToggleFlag &= ~JOY_CTRL_E; + //MenuToggleFlag &= ~JOY_CTRL_A; + ( wonflag == 0 ) ? wonflag = 1 : wonflag = 0 ; + } + strcpy( OneLineInfoStr, "ְҵ"); + } + if ( wonflag == 1 ) { + for ( int i = 0 ; i < 3 ; i ++ ) { +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if( MakeHitBox( 278 , 11 + i * 78, 308 , 89 + i * 78 , DISP_PRIO_IME3 ) == TRUE ) { + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + SkillWnd2 = i ; + play_se( 217, 320, 240 ); + break; + } + } + } + else +#endif + if( MakeHitBox( 270 , 14 + i * 79, 300 , 92 + i * 79 , DISP_PRIO_IME3 ) == TRUE ) { + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + SkillWnd2 = i ; + play_se( 217, 320, 240 ); + break; + } + } + } + StockDispBuffer( 159, 225 , DISP_PRIO_MENU, CG_BATTTLE_SKILLCHOICE, 1 ); + extern int BattleSkill[20]; + extern int AssitSkill[20]; + extern int AdvanceSkill[20]; + int x = 26 , y = 5 ; + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { +// StockDispBuffer( x + 138 + j * 60 , y + 228 + i * 72 , DISP_PRIO_IME3, CG_FIELD_SKILL_TILE , 2 ); + } + } + + switch ( SkillWnd2 ) { + case 0 : +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( 168, 223, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT , 0 ); + else +#endif + StockDispBuffer( 159, 226, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + if ( AssitSkill [ j + i * 4 ] == -1 ) + break; + if ( profession_skill[ AssitSkill [ j + i * 4 ] ].useFlag == 0 ) + StockDispBuffer ( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , CG_BTL_BUTTON_CROSS , 0 ) ; + //StockDispBuffer( x + 138 + j * 48 , y + 228 + i * 52 , DISP_PRIO_IME3, CG_FIELD_SKILL_TILE , 0 ); + AssitSkillBtn [ j + i * 4 ] = StockDispBuffer( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ AssitSkill [ j + i * 4 ] ].icon , 2 ); + sprintf_s( msg2 , "%8s" , profession_skill[AssitSkill [ j + i * 4 ]].name ); + StockFontBuffer( x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, FONT_PAL_WHITE, msg2, 0 ); + if ( HitDispNo == AssitSkillBtn [ j + i * 4 ] ){ + int use_color=0; + if( p_party[ BattleMyNo ]->mp >= profession_skill[AssitSkill [ j + i * 4 ]].costmp && profession_skill[AssitSkill [ j + i * 4 ]].costmp != 0 ){ + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } + if ( profession_skill[ AssitSkill [ j + i * 4 ] ].skillId == 11 ) + use_color = FONT_PAL_WHITE; //ѪԲmp + sprintf_s( msg2 , "%s" , profession_skill[AssitSkill [ j + i * 4 ]].name ); + StockFontBuffer( 20, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , " %d", profession_skill[AssitSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 85, 310, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg2 , "(ķMP:%d)" , profession_skill[AssitSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 170, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , "%s" , profession_skill[AssitSkill [ j + i * 4 ]].memo ) ; + } + if( mouse.onceState & MOUSE_LEFT_CRICK_UP ) { + if ( HitDispNo == AssitSkillBtn [ j + i * 4 ] && profession_skill[ AssitSkill [ j + i * 4 ] ].useFlag != 0) { + if( p_party[ BattleMyNo ]->mp >= profession_skill[AssitSkill [ j + i * 4 ]].costmp && profession_skill[AssitSkill [ j + i * 4 ]].costmp != 0 ) { + wonflag = 0 ; + prouseskill = AssitSkill [ j + i * 4 ] ; + BattleSetWazaHitBox( profession_skill[AssitSkill [ j + i * 4 ] ].target , 1) ; + } + else if ( profession_skill[ AssitSkill [ j + i * 4 ] ].skillId == 11 && profession_skill[AssitSkill [ j + i * 4 ]].costmp == 0 ) { //ѪԲmp + wonflag = 0 ; + prouseskill = AssitSkill [ j + i * 4 ] ; + BattleSetWazaHitBox( profession_skill[AssitSkill [ j + i * 4 ] ].target , 1) ; + } + } + } + } + } + break; + case 1 : +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( 168, 223, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE , 0 ); + else +#endif + StockDispBuffer( 159, 226, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + if ( BattleSkill [ j + i * 4 ] == -1 ) + break; + if ( profession_skill[ BattleSkill [ j + i * 4 ] ].useFlag == 0 ) + StockDispBuffer ( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , CG_BTL_BUTTON_CROSS , 0 ) ; + if ( profession_skill[ BattleSkill [ j + i * 4 ] ].skillId == 40 && p_party[ BattleMyNo ]->hp <= 10 ) + StockDispBuffer ( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , CG_BTL_BUTTON_CROSS , 0 ) ; + //StockDispBuffer( x + 138 + j * 48 , y + 228 + i * 52 , DISP_PRIO_IME3, CG_FIELD_SKILL_TILE , 0 ); + BattleSkillBtn [ j + i * 4 ] = StockDispBuffer( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ BattleSkill [ j + i * 4 ] ].icon , 2 ); + sprintf_s( msg2 , "%8s" , profession_skill[BattleSkill [ j + i * 4 ]].name ); + StockFontBuffer( x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, FONT_PAL_WHITE, msg2, 0 ); + if ( HitDispNo == BattleSkillBtn [ j + i * 4 ] ){ + + int use_color=0; + if( p_party[ BattleMyNo ]->mp >= profession_skill[BattleSkill [ j + i * 4 ]].costmp && profession_skill[BattleSkill [ j + i * 4 ]].costmp != 0 ) { + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } + + sprintf_s( msg2 , "%s" , profession_skill[BattleSkill [ j + i * 4 ]].name ); + StockFontBuffer( 20, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , " %d", profession_skill[BattleSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 85, 310, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg2 , "(ķMP:%d)" , profession_skill[BattleSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 170, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , "%s" , profession_skill[BattleSkill [ j + i * 4 ]].memo ) ; + } + if( mouse.onceState & MOUSE_LEFT_CRICK_UP ) { + if ( HitDispNo == BattleSkillBtn [ j + i * 4 ] && profession_skill[ BattleSkill [ j + i * 4 ] ].useFlag != 0) { + if( p_party[ BattleMyNo ]->mp >= profession_skill[BattleSkill [ j + i * 4 ]].costmp && profession_skill[BattleSkill [ j + i * 4 ]].costmp != 0 ) { + if ( !(profession_skill[ BattleSkill [ j + i * 4 ] ].skillId == 40 && p_party[ BattleMyNo ]->hp <= 10) ) { // + wonflag = 0 ; + prouseskill = BattleSkill [ j + i * 4 ] ; + BattleSetWazaHitBox( profession_skill[BattleSkill [ j + i * 4 ] ].target , 1) ; + } + } + } + } + } + } + break; + case 2: +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( 168, 223, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK , 0 ); + else +#endif + StockDispBuffer( 159, 226, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + if ( AdvanceSkill [ j + i * 4 ] == -1 ) + break; + if ( profession_skill[ AdvanceSkill [ j + i * 4 ] ].useFlag == 0 ) + StockDispBuffer ( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , CG_BTL_BUTTON_CROSS , 0 ) ; + //StockDispBuffer( x + 138 + j * 48 , y + 228 + i * 52 , DISP_PRIO_IME3, CG_FIELD_SKILL_TILE , 0 ); + AdvanceSkillBtn [ j + i * 4 ] = StockDispBuffer( x + 24 + j * 60 , y + 98 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ AdvanceSkill [ j + i * 4 ] ].icon , 2 ); + sprintf_s( msg2 , "%8s" , profession_skill[AdvanceSkill [ j + i * 4 ]].name ); + StockFontBuffer( x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, FONT_PAL_WHITE, msg2, 0 ); + if ( HitDispNo == AdvanceSkillBtn [ j + i * 4 ] ){ + + int use_color = 0; + if( p_party[ BattleMyNo ]->mp >= profession_skill[AdvanceSkill [ j + i * 4 ]].costmp && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp != 0 +#ifdef _PRO3_ADDSKILL + && profession_skill[AdvanceSkill [ j + i * 4 ]].cooltime == 0 +#endif + ){ + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } +#ifdef _PROFESSION_ADDSKILL + // if ( profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 2 ) + // use_color = FONT_PAL_WHITE; //Բmp +#endif +#ifdef _PRO_ABSOLUTE_DEFENSE + if ( ( profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 75 + || profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 76 + || profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 77 ) +#ifdef _PRO3_ADDSKILL + && profession_skill[AdvanceSkill [ j + i * 4 ]].cooltime == 0 +#endif + ) + use_color = FONT_PAL_WHITE; +#endif + sprintf_s( msg2 , "%s" , profession_skill[AdvanceSkill [ j + i * 4 ]].name ); + StockFontBuffer( 20, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , " %d", profession_skill[AdvanceSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 85, 310, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg2 , "(ķMP:%d)" , profession_skill[AdvanceSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 170, 312, FONT_PRIO_FRONT, use_color, msg2, 0 ); + + sprintf_s( msg , "%s" , profession_skill[AdvanceSkill [ j + i * 4 ]].memo ) ; + } + if( mouse.onceState & MOUSE_LEFT_CRICK_UP ) { + if ( HitDispNo == AdvanceSkillBtn [ j + i * 4 ] && profession_skill[ AdvanceSkill [ j + i * 4 ] ].useFlag != 0 ) { + if( p_party[ BattleMyNo ]->mp >= profession_skill[AdvanceSkill [ j + i * 4 ]].costmp && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp != 0 +#ifdef _PRO3_ADDSKILL + && profession_skill[AdvanceSkill [ j + i * 4 ]].cooltime == 0 +#endif + ){ + wonflag = 0 ; + prouseskill = AdvanceSkill [ j + i * 4 ]; + BattleSetWazaHitBox( profession_skill[AdvanceSkill [ j + i * 4 ] ].target , 1) ; + } +#ifdef _PRO_ABSOLUTE_DEFENSE + else if ( ( profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 75 + || profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 76 + || profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 77 ) + && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp == 0 +#ifdef _PRO3_ADDSKILL + && profession_skill[AdvanceSkill [ j + i * 4 ]].cooltime == 0 +#endif + ){ + wonflag = 0 ; + prouseskill = AdvanceSkill [ j + i * 4 ]; + BattleSetWazaHitBox( profession_skill[AdvanceSkill [ j + i * 4 ] ].target , 1) ; + } +#endif +#ifdef _PROFESSION_ADDSKILL + // else if ( profession_skill[ AdvanceSkill [ j + i * 4 ] ].skillId == 2 && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp == 0 ) { //Բmp + // wonflag = 0 ; + // BattleSetWazaHitBox( profession_skill[AdvanceSkill [ j + i * 4 ] ].target , 1) ; + // prouseskill = AdvanceSkill [ j + i * 4 ]; + // } +#endif + } + } + } + } + break; + default: + break; + } + char *splitPoint = msg ; + sprintf_s( buf , "%s" , msg ) ; + x = 18 ; + y = 340 ; + while( 1 ){ + if( strlen( splitPoint ) > 34 ) { + strncpy_s( msg, splitPoint, 34 ); + buf[ 34 ] = NULL; + if( GetStrLastByte( buf ) == 3 ){ + buf[ 33 ] = NULL; + splitPoint += 33; + }else{ + buf[ 34 ] = NULL; + splitPoint += 34; + } + StockFontBuffer( x, y , FONT_PRIO_FRONT, 0, buf, 0 ); y += 24; + }else{ + strcpy( buf, splitPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, buf, 0 ); + break; + } + } +// StockFontBuffer ( 300 , 400 , FONT_PRIO_FRONT , FONT_PAL_WHITE , msg , 0 ) ; + } +} +#endif + + +void BattleButtonEscape( void ) +{ + if( HitDispNo == battleButtonDispNo[ 7 ] && battleButtonFlag[ 7 ] == FALSE ){ + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + BattleButtonOff(); + battleButtonFlag[ 7 ] = TRUE; + // `?? + if( bNewServer) + lssproto_B_send( sockfd, "E" ); + else + old_lssproto_B_send( sockfd, "E" ); + // ?????`????? + battlePlayerEscFlag = TRUE; + // ?????? + battleMenuReturn = TRUE; + // ???????? + battleButtonBak = -1; + // q???????? + battleButtonBak2 = -1; + // ???????? + play_se( 203, 320, 240 ); + } + // ?????? + strcpy( OneLineInfoStr, "ѡ"); + } +} + +// ?????????????? **************************************************/ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +void BattleSetWazaHitBox( int no , int typeflag ) +#else +void BattleSetWazaHitBox( int no ) +#endif +{ + char moji[ 256 ]; + int i; + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + int switchnum = 0 ; + + if ( typeflag == 0 ){ + BattleWazaNo = no; + switchnum = petSkill[ battlePetNoBak ][ no ].target; + }else{ + switchnum = no ; + } + battleTargetSelectFlag = TRUE; + switch( switchnum ) { +#else + BattleWazaNo = no; + battleTargetSelectFlag = TRUE; + switch( petSkill[ battlePetNoBak ][ no ].target ) { +#endif + + case PETSKILL_TARGET_MYSELF: // ????? + // ???Re????????? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + p_party[ BattleMyNo ]->atr |= ACT_ATR_HIT_BOX; + else + p_party[ BattleMyNo + 5 ]->atr |= ACT_ATR_HIT_BOX; +#else + p_party[ BattleMyNo + 5 ]->atr |= ACT_ATR_HIT_BOX; +#endif +// if( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + BattleCmdNo = BATTLE_WAZA; + // ????? + play_se( 217, 320, 240 ); + // ?k??????? + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_OTHER: // \????) + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + if( p_party[ i ]->func == NULL ) continue; + if( p_party[ i ]->hp <= 0 ) continue; + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } +/// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + BattleCmdNo = BATTLE_WAZA; + play_se( 217, 320, 240 ); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag != 1 ) +#endif + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_ALLMYSIDE: // sul + // ???????? + if( BattleMyNo < 10 ){ + // ???Re???? + for( i = 0 ; i < 10 ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + } + // ???????? + else{ + // ???Re???? + for( i = 10 ; i < 20 ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + BattleCmdNo = BATTLE_WAZA; + play_se( 217, 320, 240 ); + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_ALLOTHERSIDE: // ?Dul + // ???????? + if( BattleMyNo >= 10 ){ + // ???Re???? + for( i = 0 ; i < 10 ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } + } + // ???????? + else{ + // ???Re???? + for( i = 10 ; i < 20 ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL2; + } + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + // ??????????? + DeathAction( pActWnd ); + pActWnd = NULL; + // ??????u??? + ClearBattleButton(); + // ????k? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + + BattleCmdNo = BATTLE_WAZA; + // ????? + play_se( 217, 320, 240 ); + // ?k??????? + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_ALL: // u? + // ???Re???? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX_ALL1; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + // ??????u??? + ClearBattleButton(); + // ????k? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + + BattleCmdNo = BATTLE_WAZA; + // ????? + play_se( 217, 320, 240 ); + // ?k??????? + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_NONE: // M?k????\???? + BattleButtonOff(); // ?????u??????? + battleMenuReturn = TRUE; + // ??? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + sprintf_s( moji,"P|%X|%X", prouseskill, BattleMyNo ); + else +#endif + sprintf_s( moji,"W|%X|%X", BattleWazaNo, BattleMyNo + 5 ); + // ?? + lssproto_B_send( sockfd, moji ); + + // ???????? + play_se( 203, 320, 240 ); + //andy_add +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 0 ){ + battleWazaTargetBak = -1; + battleTargetSelectFlag = FALSE; + } +#endif + break; + + case PETSKILL_TARGET_OTHERWITHOUTMYSELF: // \??????) + // ???Re???? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ???????? + if( i == BattleMyNo + 5 ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + + BattleCmdNo = BATTLE_WAZA; + // ????? + play_se( 217, 320, 240 ); + // ?k??????? + battleWazaTargetBak = no; + break; + + case PETSKILL_TARGET_WITHOUTMYSELFANDPET: // ?????? + // ???Re???? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // ?????????? + if( p_party[ i ]->func == NULL ) continue; + // ???????? + if( i == BattleMyNo + 5 ) continue; + // ???? + if( i == BattleMyNo ) continue; + // ?????? + if( p_party[ i ]->hp <= 0 ) continue; + // ????????? + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + // ??????????? + DeathAction( pActWnd ); + pActWnd = NULL; + // ??????u??? + ClearBattleButton(); + // ????k? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else +#endif + BattleCmdNo = BATTLE_WAZA; + // ????? + play_se( 217, 320, 240 ); + // ?k??????? + battleWazaTargetBak = no; + break; +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + case PETSKILL_TARGET_ONE_ROW: + for( i = 0 ; i < 5 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL4; + } + for( i = 5 ; i < 10 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL3; + } + for( i = 10 ; i < 15 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL1; + } + for( i = 15 ; i < 20 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL2; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else + BattleCmdNo = BATTLE_WAZA; + + play_se( 217, 320, 240 ); + + if ( typeflag != 1 ) + battleWazaTargetBak = no; + + break; +#ifdef _SKILL_ADDBARRIER + case PETSKILL_TARGET_ONE_ROW_ALL: + for( i = 0 ; i < 5 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL8; + } + for( i = 5 ; i < 10 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL7; + } + for( i = 10 ; i < 15 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵһ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL5; + } + for( i = 15 ; i < 20 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX_COL6; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else + BattleCmdNo = BATTLE_WAZA; + play_se( 217, 320, 240 ); + if ( typeflag != 1 ) + battleWazaTargetBak = no; + break; +#endif + case PETSKILL_TARGET_ONE_LINE: + for( i = 0 ; i < 5 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µڶ + p_party[i]->atr |= ACT_ATR_HIT_BOX; + p_party[i+5]->atr |= ACT_ATR_HIT_BOX; + } + for( i = 5 ; i < 10 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // µһ + p_party[i]->atr |= ACT_ATR_HIT_BOX; + p_party[i-5]->atr |= ACT_ATR_HIT_BOX; + + } + for( i = 10 ; i < 15 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵһ + p_party[i]->atr |= ACT_ATR_HIT_BOX; + p_party[i+5]->atr |= ACT_ATR_HIT_BOX; + + } + for( i = 15 ; i < 20 ; i++ ) { + if( p_party[i]->func == NULL ) continue; + //if( FALSE == magic[BattleJujutuNo].deadTargetFlag ) + if( p_party[i]->hp <= 0 ) continue; + if( p_party[i]->atr & ACT_ATR_TRAVEL ) continue; + // ϵڶ + p_party[i]->atr = ACT_ATR_HIT_BOX; + p_party[i-5]->atr = ACT_ATR_HIT_BOX; + + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + DeathAction( pActWnd ); + pActWnd = NULL; + ClearBattleButton(); + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else + BattleCmdNo = BATTLE_WAZA; + play_se( 217, 320, 240 ); + battleWazaTargetBak = no; + break; + case PETSKILL_TARGER_DEATH: + for( i = 0 ; i < 20 ; i++ ){ + if( p_party[ i ]->func == NULL ) continue; + if( p_party[ i ]->hp > 0 ) continue; + p_party[ i ]->atr |= ACT_ATR_HIT_BOX; + } +// if ( typeflag == 0 ) + battleTargetSelectFlag = TRUE; + + DeathAction( pActWnd ); + pActWnd = NULL; + + ClearBattleButton(); + + if ( typeflag == 1 ) + BattleCmdNo = BATTLE_PROWAZA; + else + BattleCmdNo = BATTLE_WAZA; + + play_se( 217, 320, 240 ); + + if ( typeflag != 1 ) + battleWazaTargetBak = no; + + break; +#endif + } +} + +// ????? *****************************************************************/ +void BattleButtonWaza( void ) +{ + int i, bak; + int x, y; + char moji[ 256 ]; + if( HitDispNo == battleButtonDispNo[ 8 ] || battlePetButtonFlag == TRUE ){ + // ????????? + if( mouse.onceState & MOUSE_LEFT_CRICK || battlePetButtonFlag == TRUE ){ + bak = battleButtonFlag[ 8 ]; // ?????? + BattleButtonOff(); // ?????u??????? + // ????????? + if( bak == FALSE ){ + // ????????? + battleButtonFlag[ 8 ] = TRUE; //򿪼ѡ + // ????????? + battleWazaTargetBak = -1; + // ????k? + //BattleCmdNo = BATTLE_WAZA; + // ?????Re??? + for( i = 0 ; i < BATTLE_MENU_WAZA_FONTS ; i++ ) battleMenuWazaFontNo[ i ] = -2; + // ????????? + pActWnd = MakeWindowDisp( 364, 41, 272, 348, 0, -1 ); + } + } + // ????????? + battlePetButtonFlag = FALSE; + // ?????? + strcpy( OneLineInfoStr, "ʹüܡ"); + } + // ???????? + if( battleButtonFlag[ 8 ] == TRUE ){ + // ????????? + if( pActWnd != NULL ){ + // ?????????????? + if( pActWnd->hp > 0 ){ + // ????????? + StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my, DISP_PRIO_MENU, CG_PET_WAZA_WND, 1 ); + // ????????? + for( i = 0 ; i < pet[ battlePetNoBak ].maxSkill ; i++ ){ + // ????? + StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActWnd->pYobi )->my, DISP_PRIO_IME3, CG_PET_WAZA_BAR_1 + i, 1 ); + } + // ???????? + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + // ???????? + if( HitDispNo == battleMenuWazaFontNo[ 7 ] ){ + // ?????u??????? + BattleButtonOff(); + } + } + // ???????? + if( pActWnd != NULL ){ + // ?@e + x = pActWnd->x + 32; + y = pActWnd->y + 252; + // C? + for( i = 0 ; i < pet[ battlePetNoBak ].maxSkill ; i++ ){ + // ???????? + if( petSkill[ battlePetNoBak ][ i ].useFlag == TRUE ){ + if( HitFontNo == battleMenuWazaFontNo[ i ] ){ + // ?????? + char *splitPoint = petSkill[ battlePetNoBak ][ i ].memo; + // ????? + while( 1 ){ + // ????????? + if( strlen( splitPoint ) > 24 ){ + strncpy_s( moji, splitPoint, 24 ); + moji[ 24 ] = NULL; // Z?????? + // u??S???? + if( GetStrLastByte( moji ) == 3 ){ + moji[ 23 ] = NULL; + splitPoint += 23; + }else{ + moji[ 24 ] = NULL; + splitPoint += 24; + } + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); y += 20; + }else{ + strcpy( moji, splitPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); + break; + } + } + // ???????? + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + // Pf???? + if( petSkill[ battlePetNoBak ][ i ].field != PETSKILL_FIELD_MAP ){ +#ifdef _VARY_WOLF + if(!((pet[battlePetNoBak].graNo==101428)&&(petSkill[battlePetNoBak][i].skillId==600)) +#ifdef _PETSKILL_EVOLUTION + && !((pet[battlePetNoBak].graNo==102011 || pet[battlePetNoBak].graNo==102012)&&(petSkill[battlePetNoBak][i].skillId==672)) +#endif + ) +#endif + // ?????????????? +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BattleSetWazaHitBox( i , 0 ) ; +#else + BattleSetWazaHitBox( i ); +#endif + }else{ + int flag = 0; + int j; + // Pf????????????????? + for( j = 0 ; j < pet[ battlePetNoBak ].maxSkill ; j++ ){ + // ???????? + if( petSkill[ battlePetNoBak ][ j ].useFlag == TRUE ){ + // Pf???? + if( petSkill[ battlePetNoBak ][ j ].field != PETSKILL_FIELD_MAP ) flag++; + } + } + // Pf?????????? + if( flag > 0 ){ + // ??? + play_se( 220, 320, 240 ); + } + // ?????? + else{ + BattleButtonOff(); // ?????u??????? + //battleMenuReturn = TRUE; + ClearBoxFlag(); + // ??????????? + if( bNewServer) + lssproto_B_send( sockfd, "W|FF|FF" ); + else + old_lssproto_B_send( sockfd, "W|FF|FF" ); + // ???????? + play_se( 203, 320, 240 ); + // ?k??????? + battleWazaTargetBak = -1; + // ?????????????? + battleTargetSelectFlag = FALSE; + } + } + } + } + } + } +/* +#ifndef __AI + //cary Զս + if( !PauseAI && AI!=AI_NONE && FALSE==battleTargetSelectFlag){ + if( (BattleIntervalCnt==0 && (BattleCntDown-TimeGetTime())<=29000) || BattleIntervalCnt pet[ battlePetNoBak ].hp) + ai = AI_GUARD; + else + ai = AI_ATTACK; + } + for( i = 0 ; i < pet[ battlePetNoBak ].maxSkill ; i++ ){ + if( petSkill[ battlePetNoBak ][ i ].useFlag == TRUE && + petSkill[ battlePetNoBak ][ i ].field != PETSKILL_FIELD_MAP ){ + if( first == -1) + first = i; + if( ai == AI_ATTACK){ + if( petSkill[ battlePetNoBak ][ i ].skillId!=2 && firstattack==-1) + firstattack = i; + if( petSkill[ battlePetNoBak ][ i ].skillId == 1){ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BattleSetWazaHitBox( i , 0 ); + +#else + BattleSetWazaHitBox( i ); +#endif + break; + } + }else if( ai == AI_GUARD){ + if( petSkill[ battlePetNoBak ][ i ].skillId == 2){ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BattleSetWazaHitBox( i , 0 ); +#else + BattleSetWazaHitBox( i ); +#endif + break; + } + } + } + } + if( i==pet[ battlePetNoBak ].maxSkill){ + if( ai==AI_ATTACK && firstattack!=-1) + first = firstattack; + if( first == -1){ + // ?????????????? + battleTargetSelectFlag = TRUE; + // ??????????? + DeathAction( pActWnd ); + pActWnd = NULL; + // ??????u??? + ClearBattleButton(); + // ????? + //play_se( 217, 320, 240 ); + }else +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BattleSetWazaHitBox( first , 0 ); +#else + BattleSetWazaHitBox( first ); +#endif + } + } + } +#endif +*/ + // ????????? + if( pActWnd != NULL ){ + // ?@e + x = pActWnd->x + 40; + y = pActWnd->y + 32; + // ?????? + if( pet[ battlePetNoBak ].freeName[ 0 ] != NULL ) + CenteringStr( pet[ battlePetNoBak ].freeName, moji, PET_NAME_LEN ); + else + CenteringStr( pet[ battlePetNoBak ].name, moji, PET_NAME_LEN ); + StockFontBuffer( x - 28, y, FONT_PRIO_FRONT, 0, moji, 0 ); y += 26; x += 18; + // ? + for( i = 0 ; i < pet[ battlePetNoBak ].maxSkill ; i++ ){ + // ???????? + if( petSkill[ battlePetNoBak ][ i ].useFlag == TRUE ){ + int color = FONT_PAL_GRAY; +#ifdef _NEWFONT_ + sprintf_s( moji," %s",petSkill[ battlePetNoBak ][ i ].name ); +#else + sprintf_s( moji," %-22s",petSkill[ battlePetNoBak ][ i ].name ); +#endif + // Pf???? + if( petSkill[ battlePetNoBak ][ i ].field != PETSKILL_FIELD_MAP ){ +#ifdef _VARY_WOLF + if(!((pet[battlePetNoBak].graNo==101428)&&(petSkill[battlePetNoBak][i].skillId==600)) +#ifdef _PETSKILL_EVOLUTION + && !((pet[battlePetNoBak].graNo==102011 || pet[battlePetNoBak].graNo==102012)&&(petSkill[battlePetNoBak][i].skillId==672)) +#endif + ) +#endif + color = FONT_PAL_WHITE; + } +#ifdef _NEWFONT_ + StockFontBuffer( x - 43, y, FONT_PRIO_FRONT, color, moji, 0 ); + char* str=" "; + battleMenuWazaFontNo[ i ] = StockFontBuffer( x - 43, y, FONT_PRIO_FRONT, color, str, 2 ); +#else + battleMenuWazaFontNo[ i ] = StockFontBuffer( x - 43, y, FONT_PRIO_FRONT, color, moji, 2 ); +#endif + } + y += 25; + } + // ?@e + y = pActWnd->y + 330; + // ????????? + battleMenuWazaFontNo[ 7 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActWnd->pYobi )->mx, y, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + } + } + } + } + } +} + +void BattleTargetSelect( void ) +{ + char moji[ 256 ]; + int targetNo; + int no; + + if( !( MenuToggleFlag & JOY_ESC ) && !( MenuToggleFlag & JOY_CTRL_E ) && !( MenuToggleFlag & JOY_CTRL_A ) && !( menuBtn == 1 ) ){ + + if( pActInfoWnd == NULL ){ + pActInfoWnd = MakeWindowDisp( 210, 356, 3, 2, 0, 1 ); + }else{ + if( pActInfoWnd->hp > 0 ){ + StockFontBuffer( pActInfoWnd->x + 38, pActInfoWnd->y + 28, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ѡ", 0 ); + StockFontBuffer( pActInfoWnd->x + 38, pActInfoWnd->y + 52, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "Ŀ", 0 ); + } +#ifdef _NEW_WIN_POS_ + if( mouse.nowPoint.y > 400 ) pActInfoWnd->y = 4; + if( mouse.nowPoint.y < 200 ) pActInfoWnd->y = 430; +#endif + + } + }else{ + DeathAction( pActInfoWnd ); + pActInfoWnd = NULL; + } + + //cary Զ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + + if( ( targetNo = CheckBattelTarget() ) != -1 ){ + + switch( BattleCmdNo ){ + case BATTLE_ATTACK: + sprintf_s( moji, "H|%X", targetNo ); + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + break; + + case BATTLE_CAPTURE: + sprintf_s( moji, "T|%X", targetNo ); + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + break; + + case BATTLE_JUJUTU: + //cary* + switch( magic[ BattleJujutuNo ].target ){ + + #ifdef __ATTACK_MAGIC + + // оijһ + case MAGIC_TARGET_SINGLE: + + sprintf_s( moji , "J|%X|%X" , BattleJujutuNo , targetNo ); + if( bNewServer) + lssproto_B_send( sockfd , moji ); + else + old_lssproto_B_send( sockfd , moji ); + play_se( 217 , 320 , 240 ); + + break; + + // оһ + case MAGIC_TARGET_ONE_ROW: + + // 23: ϵһ , 24: ϵڶ , 25: µһ , 26: µڶ + if( targetNo >= 0 && targetNo < 5 ) + no = BATTLKPKPLYAERNUM + 6; + else if( targetNo >= 5 && targetNo < 10 ) + no = BATTLKPKPLYAERNUM + 5; + else if( targetNo >= 10 && targetNo < 15 ) + no = BATTLKPKPLYAERNUM + 3; + else if( targetNo >= 15 && targetNo < 20 ) + no = BATTLKPKPLYAERNUM + 4; + + sprintf_s( moji , "J|%X|%X" , BattleJujutuNo , no ); + if( bNewServer) + lssproto_B_send( sockfd , moji ); + else + old_lssproto_B_send( sockfd , moji ); + play_se( 217 , 320 , 240 ); + + break; + + // оȫ + case MAGIC_TARGET_ALL_ROWS: + + ( BattleMyNo < 10 )? no = BATTLKPKPLYAERNUM + 1 : no = BATTLKPKPLYAERNUM; + sprintf_s( moji , "J|%X|%X" , BattleJujutuNo , no ); + if( bNewServer) + lssproto_B_send( sockfd , moji ); + else + old_lssproto_B_send( sockfd , moji ); + play_se( 217 , 320 , 240 ); + + break; + + #endif + + case MAGIC_TARGET_MYSELF: + case MAGIC_TARGET_OTHER: + sprintf_s( moji,"J|%X|%X", BattleJujutuNo, targetNo ); + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) no = 20; + else no = 21; + + sprintf_s( moji,"J|%X|%X", BattleJujutuNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_ALLOTHERSIDE: + if( BattleMyNo < 10 ) no = 21; + else no = 20; + + sprintf_s( moji,"J|%X|%X", BattleJujutuNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_ALL: + + sprintf_s( moji,"J|%X|%X", BattleJujutuNo, 22 ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case MAGIC_TARGET_WHOLEOTHERSIDE: + if( targetNo < 10 ) no = 20; + else no = 21; + + sprintf_s( moji,"J|%X|%X", BattleJujutuNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + } + break; + + //Change note ѡͳ + case BATTLE_ITEM: + //cary* + switch( pc.item[ BattleItemNo ].target ){ + case ITEM_TARGET_MYSELF: + case ITEM_TARGET_OTHER: + case ITEM_TARGET_OTHERWITHOUTMYSELF: + case ITEM_TARGET_WITHOUTMYSELFANDPET: + sprintf_s( moji,"I|%X|%X", BattleItemNo, targetNo ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) no = 20; + else no = 21; + + sprintf_s( moji,"I|%X|%X", BattleItemNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALLOTHERSIDE: + + if( BattleMyNo < 10 ) no = 21; + else no = 20; + + sprintf_s( moji,"I|%X|%X", BattleItemNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case ITEM_TARGET_ALL: + + sprintf_s( moji,"I|%X|%X", BattleItemNo, 22 ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + } + break; + + //Change note 輼ѡͳ + case BATTLE_WAZA: + switch( petSkill[ battlePetNoBak ][ BattleWazaNo ].target ){ + case PETSKILL_TARGET_MYSELF: + case PETSKILL_TARGET_OTHER: + case PETSKILL_TARGET_OTHERWITHOUTMYSELF: + case PETSKILL_TARGET_WITHOUTMYSELFANDPET: +#ifdef _BATTLESKILL + case PETSKILL_TARGER_DEATH: +#endif + sprintf_s( moji,"W|%X|%X", BattleWazaNo, targetNo ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case PETSKILL_TARGET_ALLMYSIDE: + + if( BattleMyNo < 10 ) no = 20; + else no = 21; + + sprintf_s( moji,"W|%X|%X", BattleWazaNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case PETSKILL_TARGET_ALLOTHERSIDE: + + if( BattleMyNo < 10 ) no = 21; + else no = 20; + + sprintf_s( moji,"W|%X|%X", BattleWazaNo, no ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; + + case PETSKILL_TARGET_ALL: + + sprintf_s( moji,"W|%X|%X", BattleWazaNo, 22 ); + + if( bNewServer) + lssproto_B_send( sockfd, moji ); + else + old_lssproto_B_send( sockfd, moji ); + + play_se( 217, 320, 240 ); + break; +#ifdef _BATTLESKILL + case PETSKILL_TARGET_ONE_ROW: +#endif +#ifdef _SKILL_ADDBARRIER + case PETSKILL_TARGET_ONE_ROW_ALL: +#endif + if ( targetNo >= 0 && targetNo < 5 ) no = BATTLKPKPLYAERNUM + 6 ; + if ( targetNo >= 5 && targetNo < 10 ) no = BATTLKPKPLYAERNUM + 5 ; + if ( targetNo >= 10 && targetNo < 15 ) no = BATTLKPKPLYAERNUM + 3 ; + if ( targetNo >= 15 && targetNo < 20 ) no = BATTLKPKPLYAERNUM + 4 ; + sprintf_s( moji,"W|%X|%X", BattleWazaNo, no ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + } + break; + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + //Change note ְҵѡͳ + case BATTLE_PROWAZA: + switch( profession_skill[prouseskill].target ){ + case PETSKILL_TARGET_MYSELF: + case PETSKILL_TARGET_OTHER: + case PETSKILL_TARGET_OTHERWITHOUTMYSELF: + case PETSKILL_TARGET_WITHOUTMYSELFANDPET: + case PETSKILL_TARGET_ONE_LINE: +#ifdef _BATTLESKILL + case PETSKILL_TARGER_DEATH: +#endif + sprintf_s( moji,"P|%X|%X", prouseskill, targetNo ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + case PETSKILL_TARGET_ALLMYSIDE: + if( BattleMyNo < 10 ) no = 20; + else no = 21; + sprintf_s( moji,"P|%X|%X", prouseskill, no ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + case PETSKILL_TARGET_ALLOTHERSIDE: + if( BattleMyNo < 10 ) no = 21; + else no = 20; + sprintf_s( moji,"P|%X|%X", prouseskill, no ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + case PETSKILL_TARGET_ALL: + sprintf_s( moji,"P|%X|%X", prouseskill, 22 ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + case PETSKILL_TARGET_ONE_ROW: +#ifdef _SKILL_ADDBARRIER + case PETSKILL_TARGET_ONE_ROW_ALL: +#endif + if ( targetNo >= 0 && targetNo < 5 ) no = BATTLKPKPLYAERNUM + 6 ; + if ( targetNo >= 5 && targetNo < 10 ) no = BATTLKPKPLYAERNUM + 5 ; + if ( targetNo >= 10 && targetNo < 15 ) no = BATTLKPKPLYAERNUM + 3 ; + if ( targetNo >= 15 && targetNo < 20 ) no = BATTLKPKPLYAERNUM + 4 ; + sprintf_s( moji,"P|%X|%X", prouseskill, no ); + lssproto_B_send( sockfd, moji ); + play_se( 217, 320, 240 ); + break; + } + break; +#endif + } + + play_se( 203, 320, 240 ); + + battleTargetSelectFlag = FALSE; + + battleMenuReturn = TRUE; + + DeathAction( pActInfoWnd ); + pActInfoWnd = NULL; + } + } +} + +static int Ordinal[] = { 4+15, 2+15, 0+15, 1+15, 3+15, + 4+10, 2+10, 0+10, 1+10, 3+10, + 4+5, 2+5, 0+5, 1+5, 3+5, + 4, 2, 0, 1, 3 }; +// ??????????Re ***************************************************/ +#ifdef _AI_OTHER +#ifdef _AI_CAPTURE +extern int AI_OtherSetting[2]; +#else +extern int AI_OtherSetting[1]; +#endif +#endif +int GetBattelTarget() +{ + int i, index, end; + i = 10; + end = 20; + if( BattleMyNo < 10){ + i = 0 ; + end = 10; + } +#ifdef __AI +#ifdef _AI_CAPTURE + for( ; i < end ; i++ ){ + index = Ordinal[i]; + if( p_party[index]->func == NULL ) continue; + if( p_party[index]->hp<=0 || index==BattleMyNo || index==5+BattleMyNo) + continue; + if(AI_OtherSetting[1]&&p_party[index]->level==1){ + return index;; + } + } +#endif + i = 10; + end = 20; + if( BattleMyNo < 10){ + i = 0 ; + end = 10; + } + for( ; i < end ; i++ ){ + index = Ordinal[i]; + if( p_party[index]->func == NULL ) continue; + if( p_party[index]->hp<=0 || index==BattleMyNo || index==5+BattleMyNo) + continue; + + return index; + } +#else + for( ; i < end ; i++ ){ + index = Ordinal[i]; + if( p_party[ index ]->func == NULL ) continue; + if( index==BattleMyNo || index==5+BattleMyNo) + continue; + + if( ( p_party[ index ]->atr & ACT_ATR_HIT_BOX ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL1 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL2 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL3 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL4 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_ALL1 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_ALL2 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_ALL3 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_ALL4 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL5 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL6 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL7 ) + ||( p_party[ index ]->atr & ACT_ATR_HIT_BOX_COL8 ) + ) + return index; + + } +#endif + return -1; +} + +// ????????? **********************************************************/ +void BattleCntDownDisp( void ) +{ + char moji[ 16 ]; + char *work = moji; + int x = 320 - 16 + DISPLACEMENT_X / 2; + int y = 240 + DISPLACEMENT_Y / 2; + int i; + // ??? + +#ifndef PK_SYSTEM_TIMER_BY_ZHU + int BattleCntDownRest = BattleCntDown - TimeGetTime(); + // ??????? + if( BattleCntDownFlag == FALSE ) return; +#else + if( BattleCntDownFlag == FALSE || BattleCliTurnNo < 0 ) return; +#endif + + // ????????? +/*//ai +#ifndef __AI + //cary Զս + if( AI!=AI_NONE && !PauseAI){ + if( battleMenuFlag&BATTLE_MENU && battleTargetSelectFlag){ + if( (BattleIntervalCnt==0 && BattleCntDownRest<=28000) || (BattleIntervalCnt!=0 && BattleIntervalCnthp <= 0 ){ + // ?????? + }else{ + // ?????????? + if( bNewServer) + lssproto_B_send( sockfd, "W|FF|FF" ); + else + old_lssproto_B_send( sockfd, "W|FF|FF" ); + } + }else{ + // ?????hk??? + if( ( battleMenuFlag & BATTLE_MENU && battleMenuReturn == TRUE ) || + ( battleMenuFlag & BATTLE_MENU_PET && battleMenuReturn == FALSE ) ){ + // ӡP????????????????? + if( battlePetNoBak == -1 || + p_party[ BattleMyNo + 5 ]->hp <= 0 ){ + // ?????? + }else{ + // ?????????? + if( bNewServer) + lssproto_B_send( sockfd, "W|FF|FF" ); + else + old_lssproto_B_send( sockfd, "W|FF|FF" ); + } + } + } + // ?????? + battleTargetSelectFlag = FALSE; + battleMenuReturn = TRUE; + // ???????? + play_se( 203, 320, 240 ); + // ???????? + battleButtonBak = battleButtonBak2; + // ??????????????? + DeathAction( pActInfoWnd ); + pActInfoWnd = NULL; + } + // ?????K?? + +#ifndef PK_SYSTEM_TIMER_BY_ZHU + sprintf_s( moji, "%2d", BattleCntDownRest / 1000 ); +#else + if ( ( BattleCntDown - TimeGetTime() ) / 1000 >= BATTLE_CNT_DOWN_TIME ) + { + return; + } + sprintf( moji, "%2d", ( BattleCntDown - TimeGetTime() ) / 1000 ); +#endif + + // ???????? + for( i = 0 ; i < 2 ; i++ ){ + // ?????? + if( *work != 0x20 ){ + // + StockDispBuffer( x, y, DISP_PRIO_IME1, *work - '0' + CG_CNT_DOWN_0, 0 ); + } + // ???h + x += 32; + // ?????? + work++; + } + //?????? + if( DuelFlag == TRUE + ){ + // ?????K?? + sprintf_s( moji, " %02d غ", BattleCliTurnNo + 1 ); + // + if(ResoMode == 0 || ResoMode == 2){ + StockFontBuffer( 290, 180, FONT_PRIO_BACK, FONT_PAL_YELLOW, moji, 0 ); + }else if(ResoMode == 3){ + StockFontBuffer( 370, 245, FONT_PRIO_BACK, FONT_PAL_YELLOW, moji, 0 ); + }else if(ResoMode == 4){ + StockFontBuffer( 480, 320, FONT_PRIO_BACK, FONT_PAL_YELLOW, moji, 0 ); + } + + } +} + +#ifdef PK_SYSTEM_TIMER_BY_ZHU +void BattleDown( void ) +{ + BattleCntDownFlag = FALSE; + ClearBoxFlag(); + // ??????????? + DeathAction( pActWnd ); + // ???????????? + pActWnd = NULL; + // ??????u??? + ClearBattleButton(); + // ???????hk?????????? + // ?????hk??? + if( ( battleMenuFlag & BATTLE_MENU && battleMenuReturn == TRUE ) || + ( battleMenuFlag & BATTLE_MENU_PET && battleMenuReturn == FALSE ) ){ + // ӡP????????????????? + if( battlePetNoBak == -1 || + p_party[ BattleMyNo + 5 ]->hp <= 0 ){ + // ?????? + }else{ + // ?????????? + if( bNewServer) + lssproto_B_send( sockfd, "W|FF|FF" ); + else + old_lssproto_B_send( sockfd, "W|FF|FF" ); + } + } + // ?????? + battleTargetSelectFlag = FALSE; + battleMenuReturn = TRUE; + // ???????? + play_se( 203, 320, 240 ); + // ???????? + battleButtonBak = battleButtonBak2; + // ??????????????? + DeathAction( pActInfoWnd ); + pActInfoWnd = NULL; +} +#endif + +// ޸սAIתBUG +#ifdef _FIX_BATTLE_AI +void battleMenuFix(void) +{ + //battlePetMenuFlag = FALSE; + battleMenuFlag &= ~BATTLE_MENU_PET; +} +#endif + +void BattleMenuProc( void ) +{ + char moji[ 256 ]; + int i; + + if( BattleMyNo >= BATTLKPKPLYAERNUM ){ + + if( bNewServer) + lssproto_B_send( sockfd, "N" ); + else + old_lssproto_B_send( sockfd, "N" ); + + InitBattleAnimFlag(); + + SubProcNo++; + return; + } + + for( i = 0 ; i < 20 ; i++ ) HpMeterDisp( i ); // o?????? + if( p_party[ BattleMyNo ]->hp > 0 && + !( BattleBpFlag & BATTLE_BP_PLAYER_MENU_NON && BattleBpFlag & BATTLE_BP_PET_MENU_NON ) ){ + + if( battleTargetSelectFlag ){ + BattleTargetSelect(); + }else{ + + DeathAction( pActInfoWnd ); + pActInfoWnd = NULL; + } + } + + if( battleMenuFlag2 == TRUE ){ +#ifdef _NEW_WIN_POS_ + buttonX = 820 + DISPLACEMENT_X; + buttonY = 65; +#endif + buttonA = 25; + + InitBattleAnimFlag(); + + battlePlayerEscFlag = FALSE; + + BattleCntDownFlag = TRUE; + +#ifndef PK_SYSTEM_TIMER_BY_ZHU + BattleCntDown = TimeGetTime() + BATTLE_CNT_DOWN_TIME; +#endif + + BattleIntervalCnt = 0; + + if( pc.battlePetNo == battlePetNoBak ){ + + if( battleWazaTargetBak != -1 ){ + battlePetButtonFlag = FALSE; + }else{ + battlePetButtonFlag = TRUE; + } + }else{ + battlePetButtonFlag = TRUE; + battleWazaTargetBak = -1; + } + + if( p_party[ BattleMyNo ]->hp <= 0 || + + BattleBpFlag & BATTLE_BP_PLAYER_MENU_NON ){ + + if( BattleBpFlag & BATTLE_BP_PLAYER_MENU_NON ){ + if( bNewServer) + lssproto_B_send( sockfd, "N" ); + else + old_lssproto_B_send( sockfd, "N" ); + } + + p_party[ BattleMyNo ]->atr |= ACT_ATR_BTL_CMD_END; + + battlePetMenuFlag = TRUE; + }else{ + + battleMenuFlag |= BATTLE_MENU; + + battleMenuReturn = FALSE; + + battleTimeUpFlag = FALSE; + + play_se( 202, 320, 240 ); + + for( i = 0 ; i < BATTLE_BUTTON_SUU ; i++ ) battleButtonDispNo[ i ] = -2; + + ClearBoxFlag(); + + battleButtonBak2 = battleButtonBak; + } + + battlePetNoBak = pc.battlePetNo; + battlePetNoBak2 = pc.battlePetNo; + + battleMenuFlag2 = FALSE; + + BattleBpFlag &= ~BATTLE_BP_PLAYER_MENU_NON; + } + + if( battleMenuFlag & BATTLE_MENU ){ + + if( battleMenuReturn == FALSE ){ + if( buttonA > 0 ){ + buttonA--; + buttonX -= buttonA; + } +/* +#ifndef __AI + if( !PauseAI && AI!=AI_NONE && battleButtonBak==-1 && (BattleCntDown-TimeGetTime())<=29500){ + DWORD ai = AI; + if( ai == AI_SELECT){ + if( p_party[ BattleMyNo ]->maxHp*3/10 < p_party[ BattleMyNo ]->hp) + ai = AI_ATTACK; + else if( p_party[ BattleMyNo ]->maxHp*15/100 < p_party[ BattleMyNo ]->hp) + ai = AI_GUARD; + else + ai = AI_ESCAPE; + } + BattleIntervalCnt = TimeGetTime() + 500; + if( ai==AI_ATTACK && battleButtonDispNo[ 0 ]!=-2){ + mouse.onceState = MOUSE_LEFT_CRICK; + HitDispNo = battleButtonDispNo[ 0 ]; + }else if( ai==AI_GUARD && battleButtonDispNo[ 4 ]!=-2){ + mouse.onceState = MOUSE_LEFT_CRICK; + HitDispNo = battleButtonDispNo[ 4 ]; + }else if( ai==AI_ESCAPE && battleButtonDispNo[ 7 ]!=-2){ + mouse.onceState = MOUSE_LEFT_CRICK; + HitDispNo = battleButtonDispNo[ 7 ]; + } + } +#endif +*/ + + BattleButtonAttack(); + BattleButtonJujutsu(); + BattleButtonCapture(); + BattleButtonHelp(); + BattleButtonGuard(); + BattleButtonItem(); + BattleButtonPet(); + BattleButtonEscape(); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + BattleButtonPPLSKILL(); +#endif + + if( mouse.onceState & MOUSE_RIGHT_CRICK ) BattleButtonOff(); + }else{ + if( buttonA <= 25 ){ + buttonA++; + buttonX += buttonA; + }else{ + + ClearBoxFlag(); + + battleTargetSelectFlag = FALSE; + battleMenuFlag = FALSE; + + if( BattleCntDownFlag == TRUE ){ + battlePetMenuFlag = TRUE; + }else{ + SubProcNo++; + } + + BattleCmdNo = -1; + + ClearBattleButton(); + } + } +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + battleButtonDispNo[ 0 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_ATT_UP - battleButtonFlag[ 0 ], 2 ); + battleButtonDispNo[ 1 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_JUJUTSU_UP - battleButtonFlag[ 1 ], 2 ); + battleButtonDispNo[ 2 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_CAPTURE_UP - battleButtonFlag[ 2 ], 2 ); + battleButtonDispNo[ 3 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_HELP_UP - helpFlag, 2 ); + battleButtonDispNo[ 4 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_DEF_UP - battleButtonFlag[ 4 ], 2 ); + battleButtonDispNo[ 5 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_ITEM_UP - battleButtonFlag[ 5 ], 2 ); + battleButtonDispNo[ 6 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_PET_UP - battleButtonFlag[ 6 ], 2 ); + battleButtonDispNo[ 7 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_ESCAPE_UP - battleButtonFlag[ 7 ], 2 ); + battleButtonDispNo[ 9 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BATTLE_PROSKL_UP - wonflag , 2 ); + StockDispBuffer( buttonX, buttonY, DISP_PRIO_MENU, CG_BATTLE_PANEL, 0 ); +#else + battleButtonDispNo[ 0 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_ATTACK_UP + battleButtonFlag[ 0 ], 2 ); + battleButtonDispNo[ 1 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_JUJUTU_UP + battleButtonFlag[ 1 ], 2 ); + battleButtonDispNo[ 2 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_CAPTURE_UP + battleButtonFlag[ 2 ], 2 ); + battleButtonDispNo[ 3 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_HELP_UP + helpFlag, 2 ); + battleButtonDispNo[ 4 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_GUARD_UP + battleButtonFlag[ 4 ], 2 ); + battleButtonDispNo[ 5 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_ITEM_UP + battleButtonFlag[ 5 ], 2 ); + battleButtonDispNo[ 6 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_PET_UP + battleButtonFlag[ 6 ], 2 ); + battleButtonDispNo[ 7 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_BTL_BUTTON_ESCAPE_UP + battleButtonFlag[ 7 ], 2 ); + StockDispBuffer( buttonX, buttonY, DISP_PRIO_MENU, CG_BTL_BUTTON_BASE, 0 ); +#endif + + if( CheckPetSuu() >= 5 ){ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + StockDispBuffer( buttonX + 44, buttonY - 14, DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#else + StockDispBuffer( buttonX + 28, buttonY - 18, DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#endif + } +#ifdef _LOCKHELP_OK // (ɿ) Syu ADD ɼս + extern int nowFloor; + if((nowFloor <= 8213 && nowFloor >= 8200) || + (nowFloor >= 30017 && nowFloor <= 30021) + ) NoHelpFlag = TRUE ; +#endif + if( NoHelpFlag == TRUE ){ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + StockDispBuffer( buttonX + 28 + 54 + 4 , buttonY - 18 + 4 , DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#else + StockDispBuffer( buttonX + 28 + 54, buttonY - 18, DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#endif + } +#ifdef _MAGIC_NOCAST + if( NoCastFlag == TRUE ){ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + StockDispBuffer( buttonX + 28 -54 - 14, buttonY - 18 + 4, DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#else + StockDispBuffer( buttonX + 28 -54, buttonY - 18, DISP_PRIO_IME4, CG_BTL_BUTTON_CROSS, 0 ); +#endif + } +#endif + } + + if( battlePetMenuFlag == TRUE ){ + buttonX = 815 + DISPLACEMENT_X; + buttonY = 48; + buttonA = 25; + + if( battlePetNoBak <= -1 || p_party[ BattleMyNo + 5 ]->hp <= 0 ){ + BattleCntDownFlag = FALSE; + SubProcNo++; + }else if( BattleBpFlag & BATTLE_BP_PET_MENU_NON || p_party[ BattleMyNo ]->hp <= 0 || battlePlayerEscFlag == TRUE ){ + if( bNewServer) + lssproto_B_send( sockfd, "W|FF|FF" ); + else + old_lssproto_B_send( sockfd, "W|FF|FF" ); + + BattleCntDownFlag = FALSE; + SubProcNo++; + }else{ + battleMenuFlag |= BATTLE_MENU_PET; + + battleMenuReturn = FALSE; + + play_se( 202, 320, 240 ); + + ClearBoxFlag(); + +#ifdef _PETSKILL_DAMAGETOHP // 輼:ԡѪ(Ѫı) + if( battleWazaTargetBak != -1 ){//һغϵļܱ + //Ϊ˱⵱ܲʹʱ,ȴѡ,ʹѡһ + if( petSkill[battlePetNoBak][battleWazaTargetBak].field == 2 //ʾΪѡ + || petSkill[battlePetNoBak][battleWazaTargetBak].skillId == 0 //Change fix ʹԻ򱩷ʱ,ѡػ,ѡ,ǿѡ + || petSkill[battlePetNoBak][battleWazaTargetBak].skillId == 2 ){ + //if( petSkill[battlePetNoBak][battleWazaTargetBak].skillId == 623 ){ //623:petskill2.txtڵļܱ + battleWazaTargetBak = -1; + battlePetButtonFlag = TRUE; + } + else{ + +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +// BattleWazaNo = battlePetNoBak; + BattleSetWazaHitBox( BattleWazaNo , 0 ); +#else + BattleSetWazaHitBox( BattleWazaNo ); +#endif + } + } +#else + if( battleWazaTargetBak != -1 ){ //һغϵļܱ +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +// BattleWazaNo = battlePetNoBak; + BattleSetWazaHitBox( BattleWazaNo , 0 ); +#else + BattleSetWazaHitBox( BattleWazaNo ); +#endif + } +#endif + + } + BattleBpFlag &= ~BATTLE_BP_PET_MENU_NON; + battlePetMenuFlag = FALSE; + } + + if( battleMenuFlag & BATTLE_MENU_PET ){ + + if( battleMenuReturn == FALSE ){ + + if( buttonA > 0 ){ + buttonA--; + buttonX -= buttonA; + } + + BattleButtonWaza(); + + if( mouse.onceState & MOUSE_RIGHT_CRICK ){ + battlePetButtonFlag = TRUE; + battleWazaTargetBak = -1; + } + }else{ + if( buttonA <= 25 ){ + buttonA++; + buttonX += buttonA; + }else{ + ClearBoxFlag(); + battleTargetSelectFlag = FALSE; + battleMenuFlag = FALSE; + p_party[ BattleMyNo + 5 ]->atr |= ACT_ATR_BTL_CMD_END; + SubProcNo++; + } + } + + if( battleWazaTargetBak != -1 ){ + sprintf_s( moji,"%-24s",petSkill[ battlePetNoBak ][ BattleWazaNo ].name ); + StockFontBuffer( buttonX - 100, buttonY - 7, FONT_PRIO_FRONT, 0, moji, 0 ); + battleButtonDispNo[ 8 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_PET_BTL_BUTTON_CANCEL_UP, 2 ); + + }else{ + battleButtonDispNo[ 8 ] = StockDispBuffer( buttonX, buttonY, DISP_PRIO_IME3, CG_PET_BTL_BUTTON_WAZA_UP + battleButtonFlag[ 8 ], 2 ); + } + StockDispBuffer( buttonX, buttonY, DISP_PRIO_MENU, CG_PET_BTL_BUTTON_BASE, 0 ); + } + + BattleCntDownDisp(); +} + +void CloseInfoWnd() +{ + if( pActInfoWnd){ + DeathAction( pActInfoWnd); + pActInfoWnd = NULL; + } +} \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/battleproc.cpp b/石器时代8.5客户端最新源代码/石器源码/system/battleproc.cpp new file mode 100644 index 0000000..0208e39 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/battleproc.cpp @@ -0,0 +1,1172 @@ +/************************/ +/* battleProc.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/map.h" +#include "../systeminc/menu.h" +#include "../systeminc/battlemap.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/battleMap.h" +#include "../systeminc/produce.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/t_music.h" +#include "../systeminc/pc.h" +#include "../systeminc/character.h" +#include "../systeminc/handletime.h" +#include "../systeminc/savedata.h" +#include "../systeminc/field.h" + +extern ACTION* oft_test(); +extern void damage_num( ACTION *a0 ); +extern void WindowDisp( ACTION *a0 ); +extern int piyo_point; +extern void set_bc( void ); +extern void disp_kanji(ACTION *a0); +extern BOOL bNewServer; + +#ifdef _PROFESSION_ADDSKILL +extern ACTION *boundary_2,*boundary_mark[2]; +#endif + +#ifdef __ATTACK_MAGIC + +// Global vars +extern int g_iRunEarthQuake; // ״: 0 --> û , 1 --> ʼ , 2 --> +extern int g_iCurRunEarthQuake; // Ŀǰλ +extern int g_iNumRunEarthQuake; // ܴ + +#endif + +extern BOOL BattlingFlag; + +int flash_pal_cnt; +PALETTEENTRY Palette2[256]; // ?????Bl + +// ????????? +BOOL EncountFlag = FALSE; +// ??????? +BOOL DuelFlag = FALSE; +// ?????? +BOOL NoHelpFlag = FALSE; +#ifdef _MAGIC_NOCAST//Ĭ +BOOL NoCastFlag = FALSE; +#endif +// ??????????? +BOOL EncountOffFlag = FALSE; + +// ???K????? +BOOL Battle1P2PFlag; + +// ?e?????? +ACTION* pActSurprisalWnd; +ACTION* pActAudienceExitWnd; + +#ifdef _NEWDRAWBATTLEMAP // (ɿ) Syu ADD ԶBattleMap +static ACTION *BattleWaterAct[8]; // +#endif + +// u?????? +extern int check_all_dead( void ); + +// ???????? +extern char att_select_flg; + + +// ??? + +// ?????????? +int BattleDebTurnNo = 0; +// ????????? +char *BattleBcDeb[] = +{ +#include "../systeminc/BattleBcDeb.h" +}; +// ?????????? +char *BattleCmdDeb[] = +{ +#include "../systeminc/BattleMvDeb.h" +}; + + + + + + extern +/* Pf *********************************************************/ +void battle_quake( void ) +{ + switch(quake_vct_no){ + case 0: //??? + break; + case 1: //? + quake_flg = 60; + quake_vct_no = 2; + break; + case 2: //? + if(quake_flg >= 16){ + piyo_point += 16; + } else { + piyo_point += quake_flg; + } + piyo_point &= 63; + if(!--quake_flg){ //??? + quake_vct_no = 0; + } + break; + } + + #ifdef __ATTACK_MAGIC + + switch( g_iRunEarthQuake ) + { + // û + case 0: + + break; + + // ʼ + case 1: + + g_iRunEarthQuake = 2; + break; + + // + case 2: + + if( g_iNumRunEarthQuake >= 16 ) + g_iCurRunEarthQuake += 16; + else + g_iCurRunEarthQuake += g_iNumRunEarthQuake; + + g_iCurRunEarthQuake &= 63; + + if( 0 == --g_iNumRunEarthQuake ) + g_iRunEarthQuake = 0; + + break; + + } + + #endif +} + +/* ?????? *********************************************************/ +void die_flash( void ) +{ + int d0 = 0; + int d1,d7; + return; + switch(flash_vct_no){ + case 0: + break; +//?????????? ? ?????????? + case 1: + flash_vct_no++; + break; + + case 2: + for( d7 = 0; d7 < 10; d7++ ){ + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = Palette[d7].peRed; + Palette2[d7].peFlags = Palette[d7].peFlags; + + Palette2[d7+246].peBlue = Palette[d7+246].peBlue; + Palette2[d7+246].peGreen = Palette[d7+246].peGreen; + Palette2[d7+246].peRed = Palette[d7+246].peRed; + Palette2[d7+246].peFlags = Palette[d7].peFlags; + } + for( d7 = 10; d7 < 246; d7++ ){ //?????????? + Palette2[d7].peBlue = Palette[d7].peBlue; + Palette2[d7].peGreen = Palette[d7].peGreen; + Palette2[d7].peRed = 0xff; + Palette2[d7].peFlags = Palette[d7].peFlags; + } +#ifndef D3D_ENGINE + lpDraw->lpPALETTE->SetEntries(0, 0, 256, Palette2); +#endif + flash_pal_cnt = 20; + flash_vct_no++; + break; + + case 3: + if(--flash_pal_cnt){ + break; + } + flash_vct_no++; + break; + + case 4: + for(d7=10; d7<246; d7++){ + if(Palette2[d7].peRed == Palette[d7].peRed){ + continue; + } + d0 = 1; + d1 = Palette2[d7].peRed - Palette[d7].peRed; + if(d1 > 3) + d1 = 3; + if(d1 < -3) + d1 = -3; + Palette2[d7].peRed -= d1; + } + if(WindowMode){ //?????????? + flash_pal_cnt++; + if(flash_pal_cnt == 10){ //??u?? + flash_pal_cnt = 0; +#ifndef D3D_ENGINE + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); +#endif + } else { + d0 = 1; //???? + } + } else { +#ifndef D3D_ENGINE + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette2 ); +#endif + } + if(d0 == 0){ //??? + flash_vct_no = 0; + } + break; + } +} + +/* ???????k *********************************************************/ +void damage_dispx( void ) +{ + ACTION *pActLoop = pActTop->pNext; /* Id????????x */ + ACTION *pActLoopBak; /* ????????? */ + // ????? + while(1){ + /* ?????????? */ + if( pActLoop == pActBtm ) break; + /* ????? */ + if( pActLoop->deathFlag == FALSE ){ + /* Pd( pActLoop->prio ); */ + /* ?????????? */ + if( pActLoop->func == damage_num ){ + damage_num(pActLoop); + } + if( pActLoop->func == WindowDisp ){ + WindowDisp(pActLoop); + } + if( pActLoop->func == disp_kanji ){ + disp_kanji(pActLoop); + } + /* ?????????? */ + pActLoop = pActLoop->pNext; + }else{ /* ?????? */ + /* q????? */ + pActLoop->pPrev->pNext = pActLoop->pNext; + pActLoop->pNext->pPrev = pActLoop->pPrev; + /* ?????? */ + pActLoopBak = pActLoop->pNext; + /* ?????? */ + ClearAction( pActLoop ); + /* ???????? */ + pActLoop = pActLoopBak; + } + } +} + +// ?e??? **************************************************************/ +void SurprisalDisp( void ) +{ + // ??????????? + if( BattleBpFlag & BATTLE_BP_ENEMY_SURPRISAL || BattleBpFlag & BATTLE_BP_PLAYER_SURPRISAL ){ + // ????????? + if( pActSurprisalWnd == NULL ){ + // ????????? + pActSurprisalWnd = MakeWindowDisp( 320 - 96, 240 - 48, 3, 2, NULL, 1 ); + // ???????? + play_se( 202, 320, 240 ); + } + // ????????????? + if( pActSurprisalWnd->hp > 0 ){ + // ???????????? + if( MenuToggleFlag & JOY_CTRL_E || MenuToggleFlag & JOY_CTRL_A ){ + if( pActSurprisalWnd->x < 320 - 96 + 56 ) pActSurprisalWnd->x += 6; + }else{ + if( pActSurprisalWnd->x > 320 - 96 ) pActSurprisalWnd->x -= 6; + } + // ??????????????? + if( BattleBpFlag & BATTLE_BP_ENEMY_SURPRISAL ){ + StockFontBuffer( pActSurprisalWnd->x + 38, pActSurprisalWnd->y + 40, FONT_PRIO_FRONT, 0, " ͵Ϯ ", 0 ); + } + // ???????????? + if( BattleBpFlag & BATTLE_BP_PLAYER_SURPRISAL ){ + StockFontBuffer( pActSurprisalWnd->x + 38, pActSurprisalWnd->y + 40, FONT_PRIO_FRONT, 0, "䲻Ĺ", 0 ); + } + } + } +} + +int xxx; + +/*Battle Process******************************************************************/ +#ifdef _AI_OTHER +#ifdef _AI_CAPTURE +extern int AI_OtherSetting[2]; +#else +extern int AI_OtherSetting[1]; +#endif +#endif + +void BattleProc( void ) +{ + int i; + int z; + s_timer++; + xxx = 0; +#ifndef _STREET_VENDOR + #ifdef _TABLEOFSKILL + extern short skillBtn ; + skillBtn = 0 ; + #endif +#endif +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + extern short chatRoomBtn ; + chatRoomBtn = 0; + SelRoomBtn = 0; +#endif + + switch( SubProcNo ){ + case BATTLE_SUBPROC_INIT: //ڻ +#ifdef __AI + extern char *AI_Choosen; + AI_Choosen = NULL; +#endif + BattlingFlag = TRUE; + +#ifdef _PROFESSION_ADDSKILL + if( boundary_2 != NULL ){ + DeathAction( boundary_2 ); + boundary_2 = NULL; + } + if( boundary_mark[0] ){ + DeathAction( boundary_mark[0] ); + boundary_mark[0] = NULL; + } + if( boundary_mark[1] ){ + DeathAction( boundary_mark[1] ); + boundary_mark[1] = NULL; + } +#endif + //Action + DeathAllAction(); + + // սʼʱͷŵˮеĶ +#ifdef _AniRandom // Syu ADD + extern void AniRandomRelease(); + AniRandomRelease(); +#endif + +#ifdef _AniCrossFrame // Syu ADD ι + extern void crossAniRelease(); + crossAniRelease(); +#endif +#ifdef _AniCharBubble // Syu ADD ³ + extern void CharbubbleRelease(); + CharbubbleRelease(); +#endif +#ifdef _AniImmobile // Syu ADD ض + extern void ImmobileAniRelease(); + ImmobileAniRelease(); +#endif +#ifdef _SPECIALSPACEANIM // Syu ADD ⳡ + extern void ReleaseSpecAnim(); + ReleaseSpecAnim(); +#endif +#ifdef _NEWDRAWBATTLEMAP // Syu ADD ԶBattleMap + if ( nowFloor == 817 || nowFloor == 8007 || nowFloor == 8101 || nowFloor == 8100 || + nowFloor == 8027 || nowFloor == 8028 || nowFloor == 8029 || nowFloor == 8015 || nowFloor == 8113 || nowFloor == 8114 ) + { + for ( z = 0 ; z < 8 ; z ++ ) + { + if ( BattleWaterAct [ z ] == NULL ) + { + BattleWaterAct[ z ] = MakeAnimDisp ( + ( 80 * (z + 1) ), + Rnd ( 5 , 450 ) , + Rnd( 101502 , 101509) , + 0); + BattleWaterAct[ z ]->dispPrio = 30 ; + } + } + } +#endif + slow_flg = 0; + action_inf = 0; + oft_test(); + // Menuʼ + InitMenu(); + // BattleMenuʼ + InitBattleMenu(); + pActSurprisalWnd = NULL; + pActAudienceExitWnd = NULL; + // Produceʼ + ProduceInitFlag = TRUE; + // focusȡ + GetKeyInputFocus( &MyChatBuffer ); + // ????? + // Bufferʼ + DispBuffer.DispCnt = 0; + FontCnt = 0; + // BattleMapȡ +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap( BattleMapNo ); +#else + ReadBattleMap( BattleMapNo ); +#endif + ChatProc(); // Chat + ChatBufferToFontBuffer(); // ?????????????????????? + // ??????????????? + ClearBackSurface(); + // ???????????????? +#ifdef __SKYISLAND + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#else + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + //?e??????? + if(DuelFlag == TRUE || eventEnemyFlag == 1 || vsLookFlag == 1) + { +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + if ( nowFloor != 817 && nowFloor != 8007 && nowFloor != 8101 && nowFloor != 8100 && + nowFloor != 8027 && nowFloor != 8028 && nowFloor != 8029 && nowFloor != 8015 && nowFloor != 8113 && nowFloor != 8114 ) + { +#endif + //BossսBGM + if( map_bgm_no>=15 && map_bgm_no<=21) + play_bgm( 13 ); + else + play_bgm( 6 ); + if(nowFloor == 8519) play_bgm(14); +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + } + else play_bgm ( 24 ) ; +#endif + } + else + { +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + if ( nowFloor != 817 && nowFloor != 8007 && nowFloor != 8101 && nowFloor != 8100 && + nowFloor != 8027 && nowFloor != 8028 && nowFloor != 8029 && nowFloor != 8015 && nowFloor != 8113 && nowFloor != 8114 ) + { +#endif + //ͨսBGM + if( map_bgm_no>=15 && map_bgm_no<=21) + play_bgm( 12 ); + else + play_bgm( 5 ); +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + } + else + play_bgm ( 24 ) ; +#endif + } + // ???????? + NowTime = TimeGetTime(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + // ?? + DrawProduce( PRODUCE_HAGARE_OCHI_IN ); + // ???? + MenuProc(); // ?????? + ImeProc(); // ??????? + // field menu ??????????? + fieldProc2(); + // menu flag on ????????? + battleMenuFlag2 = TRUE; + // ?????????? + for( i = 0 ; i < 5 ; i++ ){ + // ???????????? + if( pet[ i ].useFlag == FALSE ){ + // ?????? + if( i == pc.battlePetNo ) pc.battlePetNo = -1; + // ????? + if( i == pc.mailPetNo ) pc.mailPetNo = -1; + // ?????????? + pc.selectPetNo[ i ] = FALSE; + } + } + // ???????? + saveUserSetting(); + // ????k???? + SubProcNo++; + break; + + case BATTLE_SUBPROC_IN_PRODUCE: // ?????? + // ת ?? + if( DrawProduce( PRODUCE_HAGARE_OCHI_IN ) == TRUE ){ + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ?????????????????????? */ +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap( BattleMapNo ); +#else + ReadBattleMap( BattleMapNo ); +#endif + // ??????????????? + ClearBackSurface(); + // ???????????????? +#ifdef __SKYISLAND + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#else + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ???????? + NowTime = TimeGetTime(); + // ?????????? + BackBufferDrawType = DRAW_BACK_BATTLE; + // ?????????? + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + SubProcNo++; + }else{ + MenuProc(); // ?????? + ImeProc(); // ??????? + // ??????????? + fieldProc2(); + } + break; + + case BATTLE_SUBPROC_RECEIVE_BC: //ÿغʼ״̬ʾ +#ifdef _DEBUG__ + if(offlineFlag == TRUE){ + +#ifdef _BATTLE_PK_PLAYER_FOR_40 + strcpy(BattleStatus,"BC|3|" + "0|ishikawa|title|18768|1|20|20|0|" + "1|ishikawa|title|18768|1|20|20|0|" + "2|ishikawa|title|18768|1|20|20|0|" + "3|ishikawa|title|18768|1|20|20|0|" + "4|ishikawa|title|18768|1|20|20|0|" + "5|beron|title|18813|1|20|20|0|" + "6|beron|title|18813|1|20|20|0|" + "7|beron|title|18813|1|20|20|0|" + "8|beron|title|18813|1|20|20|0|" + "9|beron|title|18813|1|20|20|0|" + "A|ishikawa|title|18813|1|20|20|0|" + "B|ishikawa|title|18813|1|20|20|0|" + "C|ishikawa|title|18813|1|20|20|0|" + "D|ishikawa|title|18813|1|20|20|0|" + "E|ishikawa|title|18813|1|20|20|0|" + "F|beron|title|187BA|1|20|20|0|" + "10|beron|title|187BA|1|20|20|0|" + "11|beron|title|187BA|1|20|20|0|" + "12|beron|title|187BA|1|20|20|0|" + "13|beron|title|187BA|1|20|20|0|" + "14|beron|title|187BA|1|20|20|0|" + "15|beron|title|187BA|1|20|20|0|" + "16|beron|title|187BA|1|20|20|0|" + "17|beron|title|187BA|1|20|20|0|" + "18|beron|title|187BA|1|20|20|0|" + "19|beron|title|187BA|1|20|20|0|" + "1A|beron|title|187BA|1|20|20|0|" + "1B|beron|title|187BA|1|20|20|0|" + "1C|beron|title|187BA|1|20|20|0|" + "1D|beron|title|187BA|1|20|20|0|" + "1E|beron|title|187BA|1|20|20|0|" + "1F|beron|title|187BA|1|20|20|0|" + "20|beron|title|187BA|1|20|20|0|" + "21|beron|title|187BA|1|20|20|0|" + "22|beron|title|187BA|1|20|20|0|" + "23|beron|title|187BA|1|20|20|0|" + "24|beron|title|187BA|1|20|20|0|" + "25|beron|title|187BA|1|20|20|0|" + "26|beron|title|187BA|1|20|20|0|" + "27|beron|title|187BA|1|20|20|0|" + ); +#endif +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 + strcpy(BattleStatus, "BC|3|" + "0|friend1|title|18A97|1|20|20|1|" + "1|friend2|title|18A97|1|20|20|1|" + "2|friend3|title|18A97|1|20|20|1|" + "3|friend4|title|18A97|1|20|20|1|" + "4|friend5|title|18A97|1|20|20|1|" + "5|friend6|title|18A97|1|20|20|1|" + "6|mypet1|title|18813|1|20|20|1|" + "7|mypet2|title|18813|1|20|20|1|" + "8|mypet3|title|18813|1|20|20|1|" + "9|mypet4|title|18813|1|20|20|1|" + "A|mypet5|title|18813|1|20|20|1|" + "B|mypet6|title|18813|1|20|20|1|" + "C|enemy|title|18A97|2|20|20|1|" + "D|enemy|title|18A97|2|20|20|1|" + "E|enemy|title|18A97|2|20|20|1|" + "F|enemy|title|18A97|2|20|20|1|" + "10|enemy|title|18A97|2|20|20|1|" + "11|enemy|title|18A97|2|20|20|1|" + "12|enemy|title|18813|2|20|20|1|" + "13|enemy|title|18813|2|20|20|1|" + "14|enemy|title|18813|2|20|20|1|" + "15|enemy|title|18813|2|20|20|1|" + "16|enemy|title|18813|2|20|20|1|" + "17|enemy|title|18813|2|20|20|1|" + ); +#endif + //strcpy( BattleStatus, BattleBcDeb[ BattleDebTurnNo ] ); + //BC + set_bc(); + SubProcNo++; + break; + } +#endif + + /* ?????? */ + ChatProc(); +/* +#ifndef __AI + //cary ͣԶ + if( PauseAI == 2) + PauseAI = 0; + if( PauseAI == 1) + PauseAI = 2; + extern int battleButtonBak; + if( AI == AI_SELECT) + battleButtonBak = -1; +#endif +*/ + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + // ??q????????????? + TimeZoneProc(); + // ӡP?? + if( BattleBpFlag & BATTLE_BP_JOIN ){ + // ?????? + strcpy( OneLineInfoStr,"ȴغϽ"); + } + // ????????????????? + if( EncountFlag == FALSE ){ + // ?????????? + if( !( s_timer & 7 ) ){ + piyo_point++; + piyo_point &= 63; + } + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + } + if( BattleStatusReadPointer != BattleStatusWritePointer ){ + strcpy( BattleStatus, BattleStatusBak[ BattleStatusReadPointer ] ); + BattleStatusReadPointer = ( BattleStatusReadPointer + 1 ) & ( BATTLE_BUF_SIZE-1 ); + EncountFlag = FALSE; + set_bc(); + if( BattleMyNo < BATTLKPKPLYAERNUM ) { + if( p_party[ BattleMyNo ]->petFall == 2 ) { + lssproto_TK_recv( sockfd, 0, "P|˳ս", FONT_PAL_YELLOW); + p_party[ BattleMyNo ]->petFall = 0; + }else if( p_party[ BattleMyNo ]->onRide == -1 ) { + lssproto_TK_recv( sockfd, 0, "P|˹أ˳ս", FONT_PAL_YELLOW); + } +#ifdef _PETSKILL_BECOMEFOX + else if( p_party[ BattleMyNo ]->onRide == -2 ) { + lssproto_TK_recv( sockfd, 0, "P|Ļ˳ս", FONT_PAL_YELLOW); + } +#endif +#ifdef _PETSKILL_BECOMEPIG + else if( p_party[ BattleMyNo ]->onRide == -3 ) { + lssproto_TK_recv( sockfd, 0, "P|㴦˳ս", FONT_PAL_YELLOW); + } +#endif +#ifdef _PETSKILL_EXPLODE + else if( p_party[ BattleMyNo ]->onRide == -4 ) { + lssproto_TK_recv( sockfd, 0, "P|˱ѹ˳ս", FONT_PAL_YELLOW); + } +#endif + } + + + // Pf?????????? + CheckBattleNewPet(); + // ?P??????? + if( BattleMyNo < BATTLKPKPLYAERNUM ){ + // ???@e + p_party[ BattleMyNo ]->mp = BattleMyMp; + } + // ???K?????? + Battle1P2PFlag = CheckBattle1P2P(); + SubProcNo++; + } + // ?P????????? + if( BattleMyNo >= 20 ){ + // ????????? + if( pActAudienceExitWnd == NULL ){ + // ????????? + pActAudienceExitWnd = MakeWindowDisp( 444, 4, 3, 2, NULL, 1 ); + // ???????? + play_se( 202, 320, 240 ); + } + } + break; + + case BATTLE_SUBPROC_CHAR_IN: // K? + // ??????????l + if( !( s_timer & 7 ) ){ + piyo_point++; + piyo_point &= 63; + } + // ?e??? + SurprisalDisp(); + // ????V??????????? + CheckBattleAnimFlag(); + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + // ??q????????????? + TimeZoneProc(); + // q? + BattleNameDisp(); + // K??? + if( action_inf == 3 ){ + action_inf = 0; + // PfӡP?????? + BattleBpFlag &= ~BATTLE_BP_JOIN; + // u?????? + if( check_all_dead() == 1 ){ + SubProcNo = BATTLE_SUBPROC_OUT_PRODUCE_INIT; + break; + } + // ?e?????????? + if( pActSurprisalWnd != NULL ){ + // ?????? + DeathAction( pActSurprisalWnd ); + pActSurprisalWnd = NULL; + // ?e??????? + BattleBpFlag &= ~BATTLE_BP_ENEMY_SURPRISAL; + BattleBpFlag &= ~BATTLE_BP_PLAYER_SURPRISAL; + + } + // ??????? + SubProcNo++; + } + //PfD?? + if( action_inf == 2 ){ + SubProcNo = BATTLE_SUBPROC_OUT_PRODUCE_INIT; //Pf??? + action_inf = 0; + // ?????????? + BattleCmd[ 0 ] = NULL; + } + break; + + case BATTLE_SUBPROC_CMD_INPUT: // ????V? +#ifdef _DEBUG__ + if(offlineFlag == TRUE){ + SubProcNo++; + break; + } +#endif + // ?????????? + if( !( s_timer & 7 ) ){ + piyo_point++; + piyo_point &= 63; + } + + + { +#ifndef __AI + if( mouse.onceState == MOUSE_RIGHT_CRICK) + PauseAI = 2; + // ????????? + BattleMenuProc(); +#else + extern void AI_ChooseAction(); + if( AI == AI_SELECT){ + void CloseInfoWnd(); + CloseInfoWnd(); + AI_ChooseAction(); + }else + BattleMenuProc(); +#endif + } + + + // ????V??????????? + CheckBattleAnimFlag(); + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + // ??q????????????? + TimeZoneProc(); + // q? + BattleNameDisp(); + + break; + + case BATTLE_SUBPROC_RECEIVE_MOVIE: // ????r? +#ifdef _DEBUG__ + if(offlineFlag == TRUE){ + strcpy( BattleCmd,"BY teki_A jibun_0 flg_0 damage_0 jibun_1 flg_0 damage_0 jibun_2 flg_0 damage_0" + " jibun_3 flg_0 damage_0 jibun_4 flg_0 damage_0 jibun_5 flg_0 damage_0" + " jibun_6 flg_0 damage_0 jibun_7 flg_0 damage_0 jibun_8 flg_0 damage_0" + " jibun_9 flg_0 damage_1 FF"); + strcpy( BattleCmd, BattleCmdDeb[ BattleDebTurnNo ] ); + BattleMyNo = 0; + //???????? + att_select_flg = FALSE; + SubProcNo++; + break; + } +#endif +#ifndef __AI + if( mouse.onceState == MOUSE_RIGHT_CRICK) + PauseAI = 1; +#else + extern char *AI_Choosen; +#endif + // ?????????? + if( !( s_timer & 7 ) ){ + piyo_point++; + piyo_point &= 63; + } + // ????V??????????? + CheckBattleAnimFlag(); + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + // ??q????????????? + TimeZoneProc(); + // q? + BattleNameDisp(); + // ???????r? + if( BattleCmdReadPointer != BattleCmdWritePointer ){ + strcpy( BattleCmd, BattleCmdBak[ BattleCmdReadPointer ] ); + BattleCmdReadPointer = ( BattleCmdReadPointer + 1 ) & ( BATTLE_BUF_SIZE-1 ); + action_inf = 0; + //????????? + att_select_flg = FALSE; + SubProcNo++; + } + // K??? + if( Battle1P2PFlag == 2 ){ + // ?????? + strcpy( OneLineInfoStr,"ȴҡ"); + } + // ?P?? + if( BattleMyNo >= BATTLKPKPLYAERNUM ){ + // ???? + for( i = 0 ; i < BATTLKPKPLYAERNUM ; i++ ){ + // o?????? + HpMeterDisp( i ); + } + }else{ + // ???????? + if( BattleMyNo < 10 ){ + for( i = 0 ; i < 10 ; i++ ) HpMeterDisp( i ); // o?????? + }else + // ???????? + if( BattleMyNo >= 10 ){ + for( i = 10 ; i < 20 ; i++ ) HpMeterDisp( i ); // o?????? + } +#ifdef _BATTLE_PK_PLAYER_FOR_40 + if( BattleMyNo < 30 ){ + for( i = 20 ; i < 30 ; i++ ) HpMeterDisp( i ); // o?????? + }else + // ???????? + if( BattleMyNo >= 40 ){ + for( i = 30 ; i < 40 ; i++ ) HpMeterDisp( i ); // o?????? + } +#endif + } + break; + + case BATTLE_SUBPROC_MOVIE: // ?????? +#ifdef _DEBUG__ + if(offlineFlag == TRUE){ + if(joy_trg[0]&JOY_A){ //?????? + DeathAllAction(); + SubProcNo = 0; + BattleCmd[0] = NULL; + break; + } + } +#endif + //??????????? +#ifndef __AI + if( mouse.onceState == MOUSE_RIGHT_CRICK) + PauseAI = 1; +#else + if( AI_Choosen){ + + StockFontBuffer( 640-strlen(AI_Choosen)*7-4 + DISPLACEMENT_X, 440 + DISPLACEMENT_Y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, AI_Choosen, 0 ); + } +#endif + if( slow_flg ){ + if( !( s_timer & 31 ) ){ // ???????? + piyo_point++; // ???????????? + piyo_point &= 63; // ???????? + } + if( s_timer & 3 ){ // ???????????????????? + damage_dispx(); // ?????????k + }else{ + RunAction(); /* ????????? */ + battle_quake(); //Pf + } + } else { // ??????? + if( !( s_timer & 7 ) ){ + piyo_point++; + piyo_point &= 63; + } + RunAction(); /* ????????? */ + battle_quake(); //Pf + } + //???????? + if( flash_vct_no ) die_flash(); //?????? + // ??????????????? + StockTaskDispBuffer(); + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + // ??????????? + fieldProc2(); + // ??q????????????? + TimeZoneProc(); + // q? + //BattleNameDisp(); + //?????? + if( action_inf == 1 ){ + SubProcNo = BATTLE_SUBPROC_RECEIVE_BC; //????? +#ifndef PK_SYSTEM_TIMER_BY_ZHU + BattleCliTurnNo++; // ??????????? +#endif +#ifdef _DEBUG__ + if(offlineFlag == TRUE){ + SubProcNo = BATTLE_SUBPROC_RECEIVE_BC; //????????? + BattleDebTurnNo++; + // ???????? + if( BattleDebTurnNo >= sizeof( BattleCmdDeb )/sizeof(int) ) BattleDebTurnNo = 0; + } +#endif + action_inf = 0; + // ?????????? + BattleCmd[ 0 ] = NULL; + // ????????? + battleMenuFlag2 = TRUE; + } + //PfD?? + if( action_inf == 2 ){ + SubProcNo = BATTLE_SUBPROC_OUT_PRODUCE_INIT; //Pf??? + action_inf = 0; + // ?????????? + BattleCmd[ 0 ] = NULL; + } + break; + + case BATTLE_SUBPROC_OUT_PRODUCE_INIT: // ????? + //?????????? + fade_out_bgm(); + // ???????????? + CopyBackBuffer(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + SubProcNo++; +#ifdef _NEWDRAWBATTLEMAP // (ɿ) Syu ADD ԶBattleMap + extern int RandBattleBg ; + RandBattleBg = 0 ; + for ( z = 0 ; z < 8 ; z ++ ) + { + if ( BattleWaterAct[ z ] != NULL ) + { + DeathAction(BattleWaterAct[ z ]); + BattleWaterAct[ z ] = NULL; + } + } +#endif + break; + + case BATTLE_SUBPROC_OUT_PRODUCE: // ?? + // ?? + if( DrawProduce( PRODUCE_4WAY_OUT ) == TRUE ){ +#ifdef _HUNDRED_KILL + BattleHundredFlag = FALSE; +#endif + // ???????? + ChangeProc( PROC_GAME, 1 ); + // ?????u? + DeathAllAction(); + // ????????????????? + + BattlingFlag = FALSE; + + clearPtActCharObj(); + // ??????????????????? + encountNowFlag = 0; + // ????????????????????????? + if( bNewServer) + lssproto_EO_send( sockfd, 0 ); + else + old_lssproto_EO_send( sockfd, 0 ); + //?????????? + // Pf??????????`??????????????? + if( battleResultMsg.useFlag >= 1 ){ + BattleResultWndFlag = battleResultMsg.useFlag; // ????????? + battleResultMsg.useFlag = FALSE; // ?Bl??????? + } + +#ifdef _AI_OTHER + if(AI_OtherSetting[0]){ + ITEM *pItem = pc.item; +#ifdef _NEW_ITEM_ + for(int i=0;i= 24000 && pItem[i+9].graNo <= 24044)){ + // + if(bNewServer) lssproto_DI_send(sockfd,nowGx,nowGy,i+9); + else old_lssproto_DI_send(sockfd,nowGx,nowGy,i+9); + } + } + } +#endif + return; + } + break; + + case 12: // ? + break; + } + +#ifndef _CHANNEL_MODIFY + // Robin 0805 channel + if( bNewServer && joy_trg[1] & JOY_CTRL_C ) + { + char buf[64]; + if( pc.channel == -1 ) { + if( (pc.quickChannel != -1) && (pc.familyName[0] != NULL) ) { + sprintf( buf, "C|J|%d", pc.quickChannel); + if( bNewServer) + lssproto_FM_send( sockfd, buf ); + else + old_lssproto_FM_send( sockfd, buf ); + } + } + else{ + if( bNewServer) + lssproto_FM_send( sockfd, "C|J|-1" ); + else + old_lssproto_FM_send( sockfd, "C|J|-1" ); + } + } +#endif + // ???????????? + if( BackBufferDrawType != DRAW_BACK_PRODUCE ){ + // Pf???? + if( BattleEscFlag == TRUE ){ + // ?????? + SubProcNo = BATTLE_SUBPROC_OUT_PRODUCE_INIT; + // ?????? + BattleEscFlag = FALSE; + } + // ?P??????????? + if( mouse.onceState & MOUSE_RIGHT_CRICK && BattleMyNo >= 20 ){ + DeathAction(pActAudienceExitWnd); + pActAudienceExitWnd=NULL; + if( bNewServer) + lssproto_B_send( sockfd, "U" ); + else + old_lssproto_B_send( sockfd, "U" ); + } + // ???????? + if( pActAudienceExitWnd != NULL ){ + // ?P???????????????? + if( pActAudienceExitWnd->hp > 0 ){ + // ?? + StockFontBuffer( pActAudienceExitWnd->x + 30, pActAudienceExitWnd->y + 28, FONT_PRIO_FRONT, 0, "Ҽ", 0 ); + StockFontBuffer( pActAudienceExitWnd->x + 30, pActAudienceExitWnd->y + 52, FONT_PRIO_FRONT, 0, "ս", 0 ); + } + } + } + +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/character.cpp b/石器时代8.5客户端最新源代码/石器源码/system/character.cpp new file mode 100644 index 0000000..0968c04 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/character.cpp @@ -0,0 +1,4051 @@ +#include +#include + +/* WIN32_LEAN_AND_MEAN?define???WINDOWS.H??? +??????????????????????? +????????????????? */ +#define WIN32_LEAN_AND_MEAN +#include +#include +#include + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/action.h" +#include "../systeminc/map.h" +#include "../systeminc/pattern.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/sprdisp.h" +#include "../systeminc/math2.h" + +#include "../systeminc/character.h" +#include "../systeminc/pc.h" +#include "../systeminc/menu.h" +#include "../systeminc/main.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/chat.h" + +extern BOOL g_bUseAlpha; + +// ????????? +enum +{ + CHAROBJ_USE_FREE, + CHAROBJ_USE_STAY, + CHAROBJ_USE_VIEW +}; +// Robin +//#define MAX_CHAROBJ 1000 +#define MAX_CHAROBJ 1500 +CHAROBJ charObj[MAX_CHAROBJ]; +int maxCharObj; // K?? +int tailCharObj; // ????????t +int freeCharObj; // ???????t +int searchCharObj; // ???t + +#ifdef _AniCharBubble // Syu ADD ³ +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +bool popflag = false; // +bool waittimeflag = false; //ݽȴʱ +int waittime = 0 ; //ݽȴʱ +static ACTION *popAct; //ݶ +#endif + +// ??????????????? +int charIconOffsetY[12] = +{ + -71, -88, -84, -88, -96, -102, -88, -88, -88, -85, -85, -88 +}; + + +// ??????? +int battleIconTbl[][2] = +{ + { CG_VS_MARK_1A, CG_VS_MARK_1B }, + { CG_VS_MARK_2A, CG_VS_MARK_2B }, + { CG_VS_MARK_3A, CG_VS_MARK_3B }, + { CG_VS_MARK_4A, CG_VS_MARK_4B }, + { CG_VS_MARK_5A, CG_VS_MARK_5B }, + { CG_VS_MARK_6A, CG_VS_MARK_6B }, + { CG_VS_MARK_7A, CG_VS_MARK_7B }, + { CG_VS_MARK_8A, CG_VS_MARK_8B }, + { CG_VS_MARK_9A, CG_VS_MARK_9B }, + { CG_VS_MARK_10A, CG_VS_MARK_10B } +}; + +#ifdef _NPC_MAGICCARD +struct Posstruct Positiontable[]= +{ + {19,12,17,12,18,11}, //0 + {18,17,16,15,17,14}, //1 + {13,18,13,16,14,15}, //2 + { 9,14,11,14,12,13}, //3 + {10, 9,12,11,13,10}, //4 + {15, 8,15,10,16, 9}, //5 + {15,12,14,13,15,12}, //6 ׯ +/* + {23, 9,21, 9,22, 8}, //0 + {22,14,20,12,21,11}, //1 + {17,15,17,13,18,12}, //2 + {13,11,15,11,16,10}, //3 + {14, 6,16, 8,17, 7}, //4 + {19, 5,19, 7,20, 6}, //5 + {18,10,18,10,19, 9}, //6 ׯ +*/ +}; + +int offsetYtbl[60]={ + 20,38,54,68,80,104,104,104,104,104,104,104,104,104,104,104, + 104,104,104,104,104, 104,104,104,104,104, + 104,104,104,104,104, 104,104,104,104,104, + 104,104,104,104,104, 104,104,104,104,104, + 104,104,104,104,104, 104,104,104,104,104,104,104,104,104, +}; + +int fonttbl[60]={ + 0,0,0,0,0,0,0,0,0,0, + 1,2,3,4,5,6,7,8,9,10, + 11,12,13,14,15,16,17,18,19,20, + 21,22,23,24,25,26,27,28,29,30, + 31,32,33,34,35,36,37,38,39,40, + 40,40,40,40,40,40,40,40,40,40, + +}; +#endif +/* + {23, 9,21, 9,22, 8, 5,-1}, //0 + {22,14,20,12,21,11, 4, 4},//1 + {17,15,17,13,18,12,-1, 5}, //2 + {13,11,15,11,16,10,-5, 1}, //3 + {18,10,16, 8,17, 7,-4,-4}, //4 + {19, 5,19, 7,20, 6, 1,-5}, //5 + {18,18,18,10,19, 9, 0, 0}, //6 ׯ +*/ + +short nameOverTheHeadFlag = 1; + +void charProc( ACTION * ); + +// ???????????????? +void charProc( ACTION *ptAct ) +{ + float mx, my; + int animLoop; + int no; + CHAREXTRA *ext; + int pFlag = 0; + // ?h?? + // PC???????q??h?? + // PC?????h????V???????h?? + if( pc.ptAct != ptAct ){ + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + // ?????V?????????????? + if( (charObj[no].status & CHR_STATUS_PARTY) == 0 ){ + charMove( ptAct ); + pFlag = 0; + }else + pFlag = 1; + if( ptAct->vx == 0 && ptAct->vy == 0 && charObj[no].stockDir != -1 + && charObj[no].stockDirX == ptAct->gx && charObj[no].stockDirY == ptAct->gy ){ + ptAct->anim_ang = charObj[no].stockDir; + charObj[no].stockDir = -1; + charObj[no].stockDirX = 0; + charObj[no].stockDirY = 0; + } + } + // ??t +#ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + camMapToGamen(ptAct->mx - iScreenMoveX * GRID_SIZE, ptAct->my - iScreenMoveY * GRID_SIZE, &mx, &my); + else +#endif + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + // ?????????? +#ifdef _NPC_PICTURE +#endif + drawCharStatus( ptAct ); + // ????????? + if( ptAct->anim_no == ANIM_HAND + || ptAct->anim_no == ANIM_HAPPY + || ptAct->anim_no == ANIM_ANGRY + || ptAct->anim_no == ANIM_SAD + || ptAct->anim_no == ANIM_WALK + || ptAct->anim_no == ANIM_STAND + || ptAct->anim_no == ANIM_NOD ) + animLoop = ANM_LOOP; + else + animLoop = ANM_NO_LOOP; + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( pFlag ){ + if( nowSpdRate >= 1.2F ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( nowSpdRate >= 1.6F ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + }else{ + if( ptAct->bufCount >= 2 ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( ptAct->bufCount >= 4 ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + } + if( pc.ptAct != ptAct ){ + if( charObj[no].newFoundFlag ){ + S2 xx, yy, ww, hh; + // ??????? + realGetPos( ptAct->bmpNo, &xx, &yy ); + realGetWH( ptAct->bmpNo, &ww, &hh ); + xx += ptAct->x; + yy += ptAct->y; + if( 0 <= xx && xx+ww <= DEF_APPSIZEX + && 0 <= yy && yy+hh <= DEF_APPSIZEY ){ + CheckNewPet( ptAct->anim_chr_no ); + charObj[no].newFoundFlag = 0; + } + } + } + if( 20000 <= ptAct->anim_chr_no && ptAct->anim_chr_no <= 24999 ){ + // ???? + if( pc.ptAct != ptAct ){ + // d?????????? + if( ptAct->gx < nowGx-16 || nowGx+16 < ptAct->gx + || ptAct->gy < nowGy-16 || nowGy+16 < ptAct->gy ){ + delCharObj( charObj[no].id ); + return; + } + } + // i??t???????? + if( !itemOverlapCheck( ptAct->bmpNo, ptAct->gx, ptAct->gy ) ){ + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + ptAct->atr &= (~ACT_ATR_HIDE); + }else + ptAct->atr |= ACT_ATR_HIDE; + }else{ + // ???????? + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + } +} +//ˮActionCharAction޸ +#ifdef _WATERANIMATION //Syu ADD ֮ +void waterAniProc( ACTION *ptAct ) +{ + float mx, my; + int animLoop; + int no; + CHAREXTRA *ext; + int pFlag; + // ?h?? + // PC???????q??h?? + // PC?????h????V???????h?? + if( pc.ptAct != ptAct ){ + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + // ?????V?????????????? + if( (charObj[no].status & CHR_STATUS_PARTY) == 0 ){ + charMove( ptAct ); + pFlag = 0; + }else + pFlag = 1; + if( ptAct->vx == 0 && ptAct->vy == 0 && charObj[no].stockDir != -1 + && charObj[no].stockDirX == ptAct->gx && charObj[no].stockDirY == ptAct->gy ){ + ptAct->anim_ang = charObj[no].stockDir; + charObj[no].stockDir = -1; + charObj[no].stockDirX = 0; + charObj[no].stockDirY = 0; + } + } + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + // ?????????? + // ȡ״̬ᱻƵACTION + // drawCharStatus( ptAct ); + // ????????? + if( ptAct->anim_no == ANIM_HAND + || ptAct->anim_no == ANIM_HAPPY + || ptAct->anim_no == ANIM_ANGRY + || ptAct->anim_no == ANIM_SAD + || ptAct->anim_no == ANIM_WALK + || ptAct->anim_no == ANIM_STAND + || ptAct->anim_no == ANIM_NOD ) + animLoop = ANM_LOOP; + else + animLoop = ANM_NO_LOOP; + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( pFlag ){ + if( nowSpdRate >= 1.2F ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( nowSpdRate >= 1.6F ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + }else{ + if( ptAct->bufCount >= 2 ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + if( ptAct->bufCount >= 4 ) + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + } + if( pc.ptAct != ptAct ){ + if( charObj[no].newFoundFlag ){ + S2 xx, yy, ww, hh; + // ??????? + realGetPos( ptAct->bmpNo, &xx, &yy ); + realGetWH( ptAct->bmpNo, &ww, &hh ); + xx += ptAct->x; + yy += ptAct->y; + if( 0 <= xx && xx+ww <= DEF_APPSIZEX + && 0 <= yy && yy+hh <= DEF_APPSIZEY ){ + CheckNewPet( ptAct->anim_chr_no ); + charObj[no].newFoundFlag = 0; + } + } + } + if( 20000 <= ptAct->anim_chr_no && ptAct->anim_chr_no <= 24999 ){ + // ???? + if( pc.ptAct != ptAct ){ + // d?????????? + if( ptAct->gx < nowGx-16 || nowGx+16 < ptAct->gx + || ptAct->gy < nowGy-16 || nowGy+16 < ptAct->gy ){ + delCharObj( charObj[no].id ); + return; + } + } + // i??t???????? + if( !itemOverlapCheck( ptAct->bmpNo, ptAct->gx, ptAct->gy ) ){ + // ?????????????? +#ifdef _SPECIALSPACEANIM_FIX //ROG ADD ޸ͼ + setPartsPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my,ptAct->dispPrio); +#else + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); +#endif + ptAct->atr &= (~ACT_ATR_HIDE); + }else + ptAct->atr |= ACT_ATR_HIDE; + }else{ + // ???????? + // ?????????????? +#ifdef _SPECIALSPACEANIM_FIX //ROG ADD ޸ͼ + setPartsPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my,ptAct->dispPrio); +#else + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); +#endif + } +} +/* graNo Sprͼ + gx x + gy y + dispprio ͼĸ˳ +*/ + +ACTION *createWaterAnimation( int graNo, int gx, int gy, int dispprio ) +{ + + ACTION *ptAct; + float mx, my; + ptAct = GetAction( DISP_PRIO_BOX3, sizeof( CHAREXTRA ) ); +// ptAct = GetAction( PRIO_JIKI, NULL ); + if( ptAct == NULL ) return NULL; + ptAct->func = waterAniProc; + ptAct->anim_chr_no = graNo; + ptAct->anim_no = ANIM_STAND; + ptAct->anim_ang = 1; + ptAct->dispPrio = dispprio; + ptAct->atr |= ACT_ATR_HIT; + ptAct->nextGx = gx; + ptAct->nextGy = gy; + ptAct->bufCount = 0; + ptAct->gx = gx; + ptAct->gy = gy; + ptAct->mx = (float)gx * GRID_SIZE; + ptAct->my = (float)gy * GRID_SIZE; + ptAct->vx = 0; + ptAct->vy = 0; + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + pattern( ptAct, ANM_NOMAL_SPD, ANM_NO_LOOP ); + return ptAct; +} + +#endif +// ???????????? +ACTION *createCharAction( int graNo, int gx, int gy, int dir ) +{ + ACTION *ptAct; + float mx, my; + /* ?????????K? */ + ptAct = GetAction( PRIO_CHR, sizeof( CHAREXTRA ) ); + if( ptAct == NULL ) + return NULL; + // ??? + ptAct->func = charProc; + // ???????k? + ptAct->anim_chr_no = graNo; + // h?k? + ptAct->anim_no = ANIM_STAND; + // ?????????( ??? )( ??????? ) + ptAct->anim_ang = dir; + // ?IT +// ptAct->dispPrio = DISP_PRIO_BOX3; + ptAct->dispPrio = DISP_PRIO_CHAR; + // 1???????? + ptAct->atr = ACT_ATR_INFO | ACT_ATR_HIT | ACT_ATR_HIDE2; + // ???t + ptAct->nextGx = gx; // ??????????hI? + ptAct->nextGy = gy; + ptAct->bufCount = 0; + ptAct->gx = gx; // ???????????? + ptAct->gy = gy; + ptAct->mx = (float)gx * GRID_SIZE; // ???? + ptAct->my = (float)gy * GRID_SIZE; + ptAct->vx = 0; // ?h? + ptAct->vy = 0; + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + return ptAct; +} + +// ?????hI????????? +void stockCharMovePoint( ACTION *ptAct, int nextGx, int nextGy ) +{ + if( ptAct == NULL ) + return; + // ?????????????? + if( ptAct->bufCount < sizeof( ptAct->bufGx )/sizeof( int ) ){ + ptAct->bufGx[ptAct->bufCount] = nextGx; + ptAct->bufGy[ptAct->bufCount] = nextGy; + ptAct->bufCount++; + }else{ + // ??????????????? + ptAct->bufCount = 0; + setCharWarpPoint( ptAct, nextGx, nextGy ); + } +} + +// ?????hI????????????????? +//?????????????????k???????? +void correctCharMovePoint( ACTION *ptAct, int nextGx, int nextGy ) +{ + int dx, dy; + int nGx[2], nGy[2], nCnt = 0; + int i; + int preCnt; + int nextGx2, nextGy2; + if( ptAct == NULL ) + return; + // ??????? + // ??????????????next?{??? + if( ptAct->bufCount <= 0 ){ + nextGx2 = ptAct->nextGx; + nextGy2 = ptAct->nextGy; + }else{ + preCnt = ptAct->bufCount - 1; + nextGx2 = ptAct->bufGx[preCnt]; + nextGy2 = ptAct->bufGy[preCnt]; + } + dx = nextGx - nextGx2; + dy = nextGy - nextGy2; + if( ABS( dx ) == 2 && ABS( dy ) == 2 ){ + nGx[nCnt] = nextGx2+dx/2; + nGy[nCnt] = nextGy2+dy/2; + nCnt++; + }else if( ABS( dx ) == 2 ){ + nGx[nCnt] = nextGx2+dx/2; + nGy[nCnt] = nextGy; + nCnt++; + }else if( ABS( dy ) == 2 ){ + nGx[nCnt] = nextGx; + nGy[nCnt] = nextGy2+dy/2; + nCnt++; + } + nGx[nCnt] = nextGx; + nGy[nCnt] = nextGy; + nCnt++; + // ?????????????? + if( ptAct->bufCount+nCnt <= sizeof( ptAct->bufGx )/sizeof( int ) ){ + for( i = 0; i < nCnt; i++ ){ + ptAct->bufGx[ptAct->bufCount] = nGx[i]; + ptAct->bufGy[ptAct->bufCount] = nGy[i]; + ptAct->bufCount++; + } + }else{ + // ??????????????? + ptAct->bufCount = 0; + nCnt--; + setCharWarpPoint( ptAct, nGx[nCnt], nGy[nCnt] ); + } +} + +// ?????hI@e +void setCharMovePoint( ACTION *ptAct, int nextGx, int nextGy ) +{ + float dir1; + int dir; + float dx, dy; + float len; + float rate = 1.0F; + if( ptAct == NULL ) + return; + if( ptAct->bufCount > 5 ) + rate = 2.0F; + else if( ptAct->bufCount >= 4 ) + rate = 1.6F; + else if( ptAct->bufCount >= 2 ) + rate = 1.2F; + dx = nextGx*GRID_SIZE-ptAct->mx; + dy = nextGy*GRID_SIZE-ptAct->my; + len = (float)sqrt( (double)(dx*dx+dy*dy) ); + if( len > 0 ){ + dx /= len; + dy /= len; + }else{ + dx = 0; + dy = 0; + } + ptAct->vx = dx * MOVE_SPEED * rate; + ptAct->vy = dy * MOVE_SPEED * rate; + ptAct->nextGx = nextGx; + ptAct->nextGy = nextGy; + if( dx != 0 || dy != 0 ){ + dir1 = Atan( dx, dy ) + 22.5F; + AdjustDir( &dir1 ); + dir = (int)(dir1/45); + ptAct->anim_ang = dir; + ptAct->walkFlag = 1; + } +} + +void _setCharMovePoint( ACTION *ptAct, int nextGx, int nextGy ) +{ + float dir1; + int dir; + float dx, dy; + float len; + if( ptAct == NULL ) + return; + dx = nextGx*GRID_SIZE-ptAct->mx; + dy = nextGy*GRID_SIZE-ptAct->my; + len = (float)sqrt( (double)(dx*dx+dy*dy) ); + if( len > 0 ){ + dx /= len; + dy /= len; + }else{ + dx = 0; + dy = 0; + } + ptAct->vx = dx * MOVE_SPEED; + ptAct->vy = dy * MOVE_SPEED; + ptAct->nextGx = nextGx; + ptAct->nextGy = nextGy; + if( dx != 0 || dy != 0 ){ + dir1 = Atan( dx, dy ) + 22.5F; + AdjustDir( &dir1 ); + dir = (int)(dir1/45); + ptAct->anim_ang = dir; + ptAct->walkFlag = 1; + } +} + +// ????????????? +void shiftBufCount( ACTION *ptAct ) +{ + int i; + if( ptAct == NULL ) + return; + if( ptAct->bufCount > 0 ) + ptAct->bufCount--; + for( i = 0; i < ptAct->bufCount; i++ ){ + ptAct->bufGx[i] = ptAct->bufGx[i+1]; + ptAct->bufGy[i] = ptAct->bufGy[i+1]; + } +} + +// ????h?? +void charMove( ACTION *ptAct ) +{ + float mx, my; + if( ptAct == NULL ) + return; + mx = (float)ptAct->nextGx*GRID_SIZE; + my = (float)ptAct->nextGy*GRID_SIZE; + // ?????????????hI?@e?? + if( mx == ptAct->mx && my == ptAct->my ){ + // ?????????????@e + if( ptAct->bufCount > 0 ){ + setCharMovePoint( ptAct, ptAct->bufGx[0], ptAct->bufGy[0] ); + shiftBufCount( ptAct ); + } + } + mx = (float)ptAct->nextGx*GRID_SIZE; + my = (float)ptAct->nextGy*GRID_SIZE; + // ?h??? + if( ptAct->vx != 0 || ptAct->vy != 0 ){ + // ?????????????? + if( pointLen2( ptAct->mx, ptAct->my, mx, my ) + <= ptAct->vx*ptAct->vx+ptAct->vy*ptAct->vy ){ + ptAct->mx = mx; + ptAct->my = my; + ptAct->vx = 0; + ptAct->vy = 0; + }else{ + // ?h + ptAct->mx += ptAct->vx; + ptAct->my += ptAct->vy; + } + // ?h??? + ptAct->anim_no = ANIM_WALK; + }else{ + // ?h????֢t? + if( ptAct->walkFlag != 0 ) + ptAct->anim_no = ANIM_STAND; + ptAct->walkFlag = 0; + } + ptAct->gx = (int)(ptAct->mx/GRID_SIZE); + ptAct->gy = (int)(ptAct->my/GRID_SIZE); +} + +// ????h????h????? +void charMove2( ACTION *ptAct ) +{ + float mx, my; + if( ptAct == NULL ) + return; + mx = (float)ptAct->nextGx*GRID_SIZE; + my = (float)ptAct->nextGy*GRID_SIZE; + // ?h??? + if( ptAct->vx != 0 || ptAct->vy != 0 ){ + // ?????????????? + if( pointLen2( ptAct->mx, ptAct->my, mx, my ) + <= ptAct->vx*ptAct->vx+ptAct->vy*ptAct->vy ){ + ptAct->mx = mx; + ptAct->my = my; + ptAct->vx = 0; + ptAct->vy = 0; + }else{ + // ?h + ptAct->mx += ptAct->vx; + ptAct->my += ptAct->vy; + } + // ?h??? + ptAct->anim_no = ANIM_WALK; + }else{ + // ?h????֢t? + if( ptAct->walkFlag != 0 ) + ptAct->anim_no = ANIM_STAND; + ptAct->walkFlag = 0; + } + ptAct->gx = (int)(ptAct->mx/GRID_SIZE); + ptAct->gy = (int)(ptAct->my/GRID_SIZE); +} + +// ????h????h????? +void _charMove( ACTION *ptAct ) +{ + float mx, my; + float vx, vy; + if( ptAct == NULL ) + return; + mx = (float)ptAct->nextGx*GRID_SIZE; + my = (float)ptAct->nextGy*GRID_SIZE; + // ?h??? + if( ptAct->vx != 0 || ptAct->vy != 0 ){ + vx = ptAct->vx * nowSpdRate; + vy = ptAct->vy * nowSpdRate; + // ?????????????? + if( pointLen2( ptAct->mx, ptAct->my, mx, my ) + <= vx*vx+vy*vy ){ + ptAct->mx = mx; + ptAct->my = my; + ptAct->vx = 0; + ptAct->vy = 0; + }else{ + // ?h + ptAct->mx += vx; + ptAct->my += vy; + } + // ?h??? + ptAct->anim_no = ANIM_WALK; + }else{ + // ?h????֢t? + if( ptAct->walkFlag != 0 ) + ptAct->anim_no = ANIM_STAND; + ptAct->walkFlag = 0; + } + ptAct->gx = (int)(ptAct->mx/GRID_SIZE); + ptAct->gy = (int)(ptAct->my/GRID_SIZE); +} + +// ???????I@e +void setCharWarpPoint( ACTION *ptAct, int gx, int gy ) +{ + if( ptAct == NULL ) + return; + ptAct->gx = gx; + ptAct->gy = gy; + ptAct->nextGx = gx; + ptAct->nextGy = gy; + ptAct->mx = (float)gx*GRID_SIZE; + ptAct->my = (float)gy*GRID_SIZE; + ptAct->vx = 0; + ptAct->vy = 0; +} + +// ?????????@e +// +// status : ????????????? +// smsg : ?????ѩ?? +// +// smsg???status?@e?? +// +void setCharStatus( unsigned short *status, char *smsg ) +{ + // + if( strstr( smsg, "P" ) ) + *status |= CHR_STATUS_P; + else + *status &= (~CHR_STATUS_P); + // ?? + if( strstr( smsg, "N" ) ) + *status |= CHR_STATUS_N; + else + *status &= (~CHR_STATUS_N); + // ? + if( strstr( smsg, "Q" ) ) + *status |= CHR_STATUS_Q; + else + *status &= (~CHR_STATUS_Q); + // ? + if( strstr( smsg, "S" ) ) + *status |= CHR_STATUS_S; + else + *status &= (~CHR_STATUS_S); + // ?? + if( strstr( smsg, "D" ) ) + *status |= CHR_STATUS_D; + else + *status &= (~CHR_STATUS_D); + // ?? + if( strstr( smsg, "C" ) ) + *status |= CHR_STATUS_C; + else + *status &= (~CHR_STATUS_C); +} + +// ??????????? +void setCharLeader( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_LEADER; +} + + +int getCharType(ACTION *ptAct) +{ + extern int ο; + if(ProcNo!=PROC_GAME) return 0; + if(!ο ) return 0; + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return 0; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext){ + no = ext->charObjTblId; + if(no >=1500) return 0; + if(strcmp(ptAct->name,charObj[no].name)==0) + if(charObj[no].charType == 256){ + return 1; + } + } + return 0; +} + + + + +void delCharLeader( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~CHR_STATUS_LEADER); +} + +// ??????????????? +void setCharParty( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_PARTY; +} + +// ????????????????? +void delCharParty( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~CHR_STATUS_PARTY); +} + +// ?????P֢t??? +void setCharWatch( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_WATCH; +} + +// ?????P֢t??????? +void delCharWatch( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~CHR_STATUS_WATCH); +} +#ifdef _MIND_ICON +void setCharMind( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(MindNo < SPR_001em ) { + realGetNo( CG_ICON_FUKIDASI, (U4*)&MindNo ); + } + ptAct->sMindIcon = MindNo; + if(ext->ptMindIcon){ + DeathAction( ext->ptMindIcon); + ext->ptMindIcon = NULL; + } + ext->ptMindIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} +void delCharMind( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; +} +#endif + +#ifdef _SHOWFAMILYBADGE_ +void setCharFamily( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + ptAct->sFamilyIcon = MindNo; + if(ext->ptFamilyIcon){ + DeathAction( ext->ptFamilyIcon); + ext->ptFamilyIcon = NULL; + } + ext->ptFamilyIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} +void delCharFamily( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext->ptFamilyIcon){ + DeathAction( ext->ptFamilyIcon); + ext->ptFamilyIcon = NULL; + } +} +#endif + + +#ifdef _CHARTITLE_ +void setCharmTitle( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + ptAct->TitleIcon = MindNo; + if(ext->ptTitleIcon){ + DeathAction( ext->ptTitleIcon); + ext->ptTitleIcon = NULL; + } + ext->ptTitleIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} + +void delCharmTitle( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext->ptTitleIcon){ + DeathAction( ext->ptTitleIcon); + ext->ptTitleIcon = NULL; + } +} +#endif + + + +#ifdef FAMILY_MANOR_ +void setCharmFamily( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + ptAct->mFamilyIcon = MindNo; + if(ext->ptmFamilyIcon){ + DeathAction( ext->ptmFamilyIcon); + ext->ptmFamilyIcon = NULL; + } + ext->ptmFamilyIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} +void delCharmFamily( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext->ptmFamilyIcon){ + DeathAction( ext->ptmFamilyIcon); + ext->ptmFamilyIcon = NULL; + } +} +#endif +#ifdef _CHAR_MANOR_ +void setCharmManor( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + ptAct->mManorIcon = MindNo; + if(ext->ptmManorIcon){ + DeathAction( ext->ptmManorIcon); + ext->ptmManorIcon = NULL; + } + ext->ptmManorIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR-1); +} +void delCharmManor( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext->ptmManorIcon){ + DeathAction( ext->ptmManorIcon); + ext->ptmManorIcon = NULL; + } +} +#endif + +#ifdef _NPC_EVENT_NOTICE +void setNpcNotice( ACTION *ptAct, int MindNo) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + ptAct->noticeNo = MindNo; + if(ext->ptNoticeIcon){ + DeathAction( ext->ptNoticeIcon); + ext->ptNoticeIcon = NULL; + } + ext->ptNoticeIcon = createCommmonEffectAction( MindNo, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} +void delNpcNotice( ACTION *ptAct) +{ + CHAREXTRA *ext; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + if(ext->ptNoticeIcon){ + DeathAction( ext->ptNoticeIcon); + ext->ptNoticeIcon = NULL; + } +} +#endif + +// ????Pf? +void setCharBattle( ACTION *ptAct, int battleNo, short sideNo, short helpMode ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_BATTLE; + charObj[no].battleNo = battleNo; + charObj[no].sideNo = sideNo; + charObj[no].helpMode = helpMode; + if( helpMode ) + charObj[no].status |= CHR_STATUS_HELP; + else + charObj[no].status &= ~CHR_STATUS_HELP; +} + +// ????Pf? +void delCharBattle( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~(CHR_STATUS_BATTLE | CHR_STATUS_HELP)); +} + +// +//void setCharBattle( ACTION *ptAct, int battleNo, short sideNo, short helpMode ) +void setCharTrade( ACTION *ptAct, int battleNo ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_TRADE; + //charObj[no].battleNo = battleNo; +} + +// ????Pf? +void delCharTrade( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~CHR_STATUS_TRADE|CHR_STATUS_LEADER); +} + +#ifdef _ANGEL_SUMMON +void setCharAngel( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_ANGEL; +} + +void delCharAngel( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= ~CHR_STATUS_ANGEL; +} +#endif + +// ??????????? +void setCharUseMagic( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_USE_MAGIC; +} + +// ??????????????????? +// ??????? +extern int ο; + +void delCharUseMagic( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status &= (~CHR_STATUS_USE_MAGIC); +} + +// ????????? +void setCharFukidashi( ACTION *ptAct, unsigned int offTime ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + charObj[no].status |= CHR_STATUS_FUKIDASHI; + ext->drawFukidashiTime = offTime + TimeGetTime(); +} + +// ?????? +void drawCharStatus( ACTION *ptAct ) +{ + CHAREXTRA *ext; + int no; +#ifdef _ANGEL_SUMMON + unsigned status; +#else + unsigned short status; +#endif + int battleNo; + int sideNo; + int helpMode; + char msg[256]; +#ifdef _AniCharBubble // Syu ADD ³ + int RandAnimate; +#endif + + + + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + + if( pc.ptAct != NULL && pc.ptAct == ptAct ){ + // ??????? + status = pc.status; + battleNo = 0; + sideNo = 0; + helpMode = 0; + }else{ + status = charObj[no].status; + battleNo = charObj[no].battleNo; + sideNo = charObj[no].sideNo; + helpMode = charObj[no].helpMode; + } + + +#ifdef _CHAR_MANOR_ + if( ext->ptmManorIcon ){ + { + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + if(ATR_PAT_NO(ext->ptmManorIcon)){ + ATR_PAT_BAK_NO(ext->ptmManorIcon) = ATR_PAT_NO(ext->ptmManorIcon); + ATR_PAT_NO(ext->ptmManorIcon) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptmManorIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptmManorIcon)){ + ATR_PAT_NO(ext->ptmManorIcon) = ATR_PAT_BAK_NO(ext->ptmManorIcon); + } + } + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptmManorIcon->x = ptAct->x; + ext->ptmManorIcon->y = ptAct->y; + ext->ptmManorIcon->mx = ptAct->mx; + ext->ptmManorIcon->my = ptAct->my; + pattern( ext->ptmManorIcon, ANM_NOMAL_SPD, ANM_LOOP ); + StockDispBuffer2(ext->ptmManorIcon->x, ext->ptmManorIcon->y, ext->ptmManorIcon->dispPrio, ext->ptmManorIcon->bmpNo, 0); + } + } + } + } +#endif + + + + + if( (status & CHR_STATUS_BATTLE) != 0 ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + ;//ATR_PAT_NO(ptAct) = 0; + }else{ + int no; + U4 bmpNo; + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + realGetNo( battleIconTbl[(battleNo%10)][(sideNo%1)], &bmpNo ); + // ?????????????? + setCharPrio( bmpNo, ptAct->x, ptAct->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + + + } + + // Trade Mark + if( (status & CHR_STATUS_TRADE) != 0 ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + ;//ATR_PAT_NO(ptAct) = 0; + }else{ + + U4 bmpNo; + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + realGetNo( CG_TRADE_MARK, &bmpNo ); + setCharPrio( bmpNo, ptAct->x, ptAct->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + } + +#ifdef _ANGEL_SUMMON + if( (status & CHR_STATUS_ANGEL) != 0 && ext->ptActAngelMark == NULL ) { + if( g_bUseAlpha ) + ext->ptActAngelMark =createCommmonEffectAction( 101812, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR ); + else + ext->ptActAngelMark =createCommmonEffectAction( 101865, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR ); + + }else if( (status & CHR_STATUS_ANGEL) == 0 && ext->ptActAngelMark != NULL ) { + // ?????????????? + DeathAction( ext->ptActAngelMark ); + ext->ptActAngelMark = NULL; + }else if( (status & CHR_STATUS_ANGEL) != 0 && ext->ptActAngelMark != NULL ) { + //int no; + //no = (ptAct->anim_chr_no - SPR_001em) / 20; + //no %= 12; // P??????h??? + // ??????????????? + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptActAngelMark->x = ptAct->x; + ext->ptActAngelMark->y = ptAct->y + ptAct->anim_y + 140; + ext->ptActAngelMark->mx = ptAct->mx; + ext->ptActAngelMark->my = ptAct->my; + // ????????? + pattern( ext->ptActAngelMark, ANM_NOMAL_SPD, ANM_LOOP ); + // ?????????????? + setCharPrio( ext->ptActAngelMark->bmpNo, + ext->ptActAngelMark->x, ext->ptActAngelMark->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), + ext->ptActAngelMark->mx, ext->ptActAngelMark->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + + } + } +#endif + + // ?P??? + if( (status & CHR_STATUS_WATCH) != 0 ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + ;//ATR_PAT_NO(ptAct) = 0; + }else{ + int no; + U4 bmpNo; + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + realGetNo( CG_ICON_WATCHING, &bmpNo ); + // ?????????????? + setCharPrio( bmpNo, ptAct->x, ptAct->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + + } + } + } + // ?????? + if( (status & CHR_STATUS_HELP) != 0 ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + ;//ATR_PAT_NO(ptAct) = 0; + }else{ + int no; + U4 bmpNo; + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + realGetNo( CG_SPEECH_HELP, &bmpNo ); + // ?????????????? + setCharPrio( bmpNo, ptAct->x, ptAct->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_-20):-(y1/2+_FANILYTEXIAOY_-20), ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + } + // ??????? + //???????????? + //??P???????? + if( (status & CHR_STATUS_LEADER) != 0 + && ext->ptActLeaderMark == NULL + && ((status & CHR_STATUS_BATTLE) == 0 || (status & CHR_STATUS_WATCH) == 0) ){ + // ?????????????? + ext->ptActLeaderMark = + createCommmonEffectAction( SPR_leader, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR ); + }else if( ((status & CHR_STATUS_LEADER) == 0 || (status & CHR_STATUS_BATTLE) != 0) + && ext->ptActLeaderMark != NULL ){ + // ?????????????? + DeathAction( ext->ptActLeaderMark ); + ext->ptActLeaderMark = NULL; + }else if( (status & CHR_STATUS_LEADER) != 0 && ext->ptActLeaderMark != NULL ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct){ + if(ATR_PAT_NO(ext->ptActLeaderMark)){ + ATR_PAT_BAK_NO(ext->ptActLeaderMark) = ATR_PAT_NO(ext->ptActLeaderMark); + ATR_PAT_NO(ext->ptActLeaderMark) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptActLeaderMark) ){ + if(ATR_PAT_BAK_NO(ext->ptActLeaderMark)){ + ATR_PAT_NO(ext->ptActLeaderMark) = ATR_PAT_BAK_NO(ext->ptActLeaderMark); + } + } + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptActLeaderMark->x = ptAct->x; + ext->ptActLeaderMark->y = ptAct->y; + ext->ptActLeaderMark->mx = ptAct->mx; + ext->ptActLeaderMark->my = ptAct->my; + // ????????? + pattern( ext->ptActLeaderMark, ANM_NOMAL_SPD, ANM_LOOP ); + // ?????????????? + setCharPrio( ext->ptActLeaderMark->bmpNo, + ext->ptActLeaderMark->x, ext->ptActLeaderMark->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), + ext->ptActLeaderMark->mx, ext->ptActLeaderMark->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + + + } + } + } + // ????? + if( (status & CHR_STATUS_USE_MAGIC) != 0 && ext->ptActMagicEffect == NULL ){ + // ???????????? + ext->ptActMagicEffect = + createCommmonEffectAction( SPR_effect01, ptAct->gx, ptAct->gy+1, 0, 0, DISP_PRIO_CHAR ); + if( pc.ptAct != NULL && pc.ptAct == ptAct ) + delPcUseMagic(); + else + delCharUseMagic( ptAct ); + }else if( ext->ptActMagicEffect != NULL ){ + // ????????????? + ext->ptActMagicEffect->x = ptAct->x; + ext->ptActMagicEffect->y = ptAct->y; + ext->ptActMagicEffect->mx = ptAct->mx; + ext->ptActMagicEffect->my = ptAct->my; + // ????????? + if( pattern( ext->ptActMagicEffect, ANM_NOMAL_SPD, ANM_NO_LOOP ) == 0 ){ + // ?????????????? + setCharPrio( ext->ptActMagicEffect->bmpNo, + ext->ptActMagicEffect->x, ext->ptActMagicEffect->y+1, 0, 0, + ext->ptActMagicEffect->mx, ext->ptActMagicEffect->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + }else{ + // ???????????? + DeathAction( ext->ptActMagicEffect ); + ext->ptActMagicEffect = NULL; + } + } + // ?????? + if( (status & CHR_STATUS_FUKIDASHI) != 0 ){ + if( ext->drawFukidashiTime > TimeGetTime() ){ + int no; + U4 bmpNo; + realGetNo( CG_ICON_FUKIDASI, &bmpNo ); + if( SPR_001em <= ptAct->anim_chr_no && ptAct->anim_chr_no <= SPR_114bw ){ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct){ + ;//ATR_PAT_NO(ptAct) = 0; + }else{ + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + setCharPrio( bmpNo, ptAct->x, ptAct->y, 20,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + + } + } + }else{ + // ?????????????? + setCharPrio( bmpNo, ptAct->x, ptAct->y, 20, -84, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + } + }else + status &= (~CHR_STATUS_FUKIDASHI); + } +#ifdef _CHARTITLE_STR_ + extern void PutTitleText(int x,int y,char fontPrio,TITLE_STR str,BOOL hitFlag); + CHAREXTRA *ext1 = (CHAREXTRA *)ptAct->pYobi; + if(ext1){ + if(!ext1->ptStreetVendor){ + if(ptAct->TitleText.flg==1){ + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + PutTitleText(ptAct->x-ptAct->TitleText.len/2,ptAct->y-(y1/2+45)-12,0,ptAct->TitleText,0); + } + } + } + } +#endif + if( nameOverTheHeadFlag + && ptAct != pc.ptAct + && (ptAct->atr & (ACT_ATR_TYPE_PC | ACT_ATR_TYPE_OTHER_PC | ACT_ATR_TYPE_PET |ACT_ATR_TYPE_OTHER)) + && ptAct->anim_chr_no != 999 && ptAct->anim_chr_no != 0 ){ + if( (ptAct->atr & ACT_ATR_TYPE_PET) && strlen( ptAct->freeName ) > 0 ) + sprintf_s( msg, "%s", ptAct->freeName ); + else{ + sprintf_s( msg, "%s", ptAct->fmname); + StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-23, FONT_PRIO_BACK, ptAct->charNameColor, msg, 0 ); + sprintf_s( msg, "%s", ptAct->name ); + } + StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-10, FONT_PRIO_BACK, ptAct->charNameColor, msg, 0 ); + } + +#ifdef _GM_MARK // WON ADD GM ʶ + { + int graNo = ptAct->anim_chr_no ; + + //֣ǣ + if( (graNo == 100420) || (graNo == 100425) || (graNo == 100445) ){ + static count1=1, count2=0; + char msg[256]; + + if(count1 >10 ) count1=1; + if(count2 >15 ){ + count1++; + count2=0; + } + + count2++; + sprintf_s( msg , "ǣ"); + StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-110, FONT_PRIO_BACK, count1, msg, 1); + } + } +#endif + +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + int i; + sprintf_s( msg , ptAct->gm_name); + for(i=2;i>0;i--) + StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-110-i, FONT_PRIO_BACK, i , msg, 1); +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + +// if( ptAct->profession_class != 0 ){ + { + char msg[10]; + + switch(pc.profession_class){ + case 0: sprintf_s( msg , ""); break; + case 1: sprintf_s( msg , "ʿ"); break; + case 2: sprintf_s( msg , "ʦ"); break; + case 3: sprintf_s( msg , "׷"); break; + } + sprintf_s( pc.profession_class_name , "%s" , msg ) ; + //StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-110, FONT_PRIO_BACK, FONT_PAL_YELLOW, msg, 1); + //StockFontBuffer( ptAct->x-GetStrWidth( msg )/2, ptAct->y-110, FONT_PRIO_BACK, FONT_PAL_YELLOW, msg, 1); + //StockDispBuffer( ptAct->x-GetStrWidth( msg )/2 + 30, ptAct->y-90 , DISP_PRIO_IME3, CG_WAR_ICON_SMALL + pc.profession_class - 1, 0 ); + + } + +#endif + +#ifdef _AniCharBubble // Syu ADD ³ + if ( ( (nowFloor == 817) || (nowFloor == 8007) || (nowFloor == 8101) || (nowFloor == 8100) || + (nowFloor == 8027) || (nowFloor == 8028) || (nowFloor == 8029) || nowFloor == 8113 || nowFloor == 8114 || + (nowFloor == 8015) ) && (popflag == false) && (waittimeflag == false)) + { + RandAnimate = RAND ( 101508 , 101509 ); //ѡȡݻ + if ( popAct == NULL ) + { + //ݲʱҪƫֵ + if( RandAnimate == 101508 ) + popAct = createWaterAnimation( RandAnimate , nowGx + 2 , nowGy - 1 , 30 ); + if( RandAnimate == 101509 ) + popAct = createWaterAnimation( RandAnimate , nowGx + 1 , nowGy - 2 , 30 ); + popflag = true; + } + } + if ( waittimeflag == false && popAct != NULL) + if ( popAct->anim_cnt == 6 ) //ŵһ + { + if ( popAct != NULL) + { + DeathAction( popAct ); + popAct = NULL; + } + popflag = false; + waittimeflag = true; + } + if ( waittimeflag == true ) //ʱȴһβʱ + { + waittime ++ ; + if (waittime > 350 ) + { + waittime = 0; + waittimeflag = false; + } + } + if ( ( (nowFloor != 817) && (nowFloor != 8007) && (nowFloor != 8101) && (nowFloor != 8100) && (nowFloor != 8113) && (nowFloor != 8114) && + (nowFloor != 8027) && (nowFloor != 8028) && (nowFloor != 8029) && (nowFloor != 8015)) && (popflag == true)) + { + popflag = false; + waittimeflag = false; + if ( popAct != NULL) + { + DeathAction ( popAct ) ; + popAct = NULL; + } + } + +#endif +#ifdef __EMOTION + if( ext->ptActEmotion){ + if( ext->ptActEmotion->mx != ptAct->mx || + ext->ptActEmotion->my != ptAct->my || + ext->ptActEmotion->x != ptAct->x || + ext->ptActEmotion->y != ptAct->y ){ + DeathAction( ext->ptActEmotion); + ext->ptActEmotion = NULL; + //pattern( ext->ptActEmotion, ANM_NOMAL_SPD, ANM_LOOP ); + }else{ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct){ + if(ATR_PAT_NO(ext->ptActEmotion)){ + ATR_PAT_BAK_NO(ext->ptActEmotion) = ATR_PAT_NO(ext->ptActEmotion); + ATR_PAT_NO(ext->ptActEmotion) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptActEmotion) ){ + if(ATR_PAT_BAK_NO(ext->ptActEmotion)){ + ATR_PAT_NO(ext->ptActEmotion) = ATR_PAT_BAK_NO(ext->ptActEmotion); + } + } + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + pattern( ext->ptActEmotion, ANM_NOMAL_SPD, ANM_LOOP ); + setCharPrio( ext->ptActEmotion->bmpNo, + ext->ptActEmotion->x, ext->ptActEmotion->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), + ext->ptActEmotion->mx, ext->ptActEmotion->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + } + } +#endif +#ifdef _STREET_VENDOR + extern int ο; + if(ext->ptStreetVendor){ + BOOL pand = FALSE; + + if(ο){ + if(pc.ptAct == ptAct) pand = TRUE; + }else pand = TRUE; + if(pand){ + ext->ptStreetVendor->x = ptAct->x; + ext->ptStreetVendor->y = ptAct->y; + ext->ptStreetVendor->mx = ptAct->mx; + ext->ptStreetVendor->my = ptAct->my; + #ifdef _STREET_VENDOR_CHANGE_ICON + StockDispBuffer(ext->ptStreetVendor->x,ext->ptStreetVendor->y + 35,DISP_PRIO_TILE+1,35343,0); + StockDispBuffer(ext->ptStreetVendor->x - 10,ext->ptStreetVendor->y + 10,DISP_PRIO_CHAR-1,35344,0); + StockDispBuffer(ext->ptStreetVendor->x,ext->ptStreetVendor->y - 15,DISP_PRIO_CHAR+1,35345,0); + #else + #ifdef _READ16BITBMP + StockDispBuffer(ext->ptStreetVendor->x,ext->ptStreetVendor->y - 80,DISP_PRIO_CHAR,OLD_GRAPHICS_START+58,10); + #endif + #endif + StockFontBuffer(ext->ptStreetVendor->x - 65,ext->ptStreetVendor->y - 92, + FONT_PRIO_BACK,MyChatBuffer.color,ptAct->szStreetVendorTitle,0); + + } + } +#endif +#ifdef _MIND_ICON + if( ext->ptMindIcon){ + + //ɾͿ߶ʾ + if( ((ptAct->sMindIcon != SPR_asleep) && + (ptAct->sMindIcon != SPR_cafe) && + (ptAct->sMindIcon != SPR_accent) ) && + pattern( ext->ptMindIcon, ANM_NOMAL_SPD, ANM_NO_LOOP) + ){ + DeathAction( ext->ptMindIcon); + ext->ptMindIcon = NULL; + } + else{ + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct){ + if(ATR_PAT_NO(ext->ptMindIcon)){ + ATR_PAT_BAK_NO(ext->ptMindIcon) = ATR_PAT_NO(ext->ptMindIcon); + ATR_PAT_NO(ext->ptMindIcon) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptMindIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptMindIcon)){ + ATR_PAT_NO(ext->ptMindIcon) = ATR_PAT_BAK_NO(ext->ptMindIcon); + } + } + short x1,y1; + if(ȡߴ( ptAct,&x1,&y1)){ + ext->ptMindIcon->x = ptAct->x; + ext->ptMindIcon->y = ptAct->y; + ext->ptMindIcon->mx = ptAct->mx; + ext->ptMindIcon->my = ptAct->my; + pattern( ext->ptMindIcon, ANM_NOMAL_SPD, ANM_LOOP ); + setCharPrio( ext->ptMindIcon->bmpNo, + ext->ptMindIcon->x, ext->ptMindIcon->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), + ext->ptMindIcon->mx, ext->ptMindIcon->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + } + } +#endif + +#ifdef _NPC_EVENT_NOTICE + if( ext->ptNoticeIcon){//ɾͿ߶ʾ + { +{ + if(!ATR_PAT_NO(ext->ptNoticeIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptNoticeIcon)){ + ATR_PAT_NO(ext->ptNoticeIcon) = ATR_PAT_BAK_NO(ext->ptNoticeIcon); + } + } + short x1,y1,x2,y2; + y2=x2=0; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptNoticeIcon->x = ptAct->x; + ext->ptNoticeIcon->y = ptAct->y; + ext->ptNoticeIcon->mx = ptAct->mx; + ext->ptNoticeIcon->my = ptAct->my; + pattern( ext->ptNoticeIcon, ANM_NOMAL_SPD, ANM_LOOP ); + + setCharPrio( ext->ptNoticeIcon->bmpNo, + ext->ptNoticeIcon->x-x2, ext->ptNoticeIcon->y, 0,-(y1/2+_FANILYTEXIAOY_+10), + ext->ptNoticeIcon->mx, ext->ptNoticeIcon->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + + } + } + } + } +#endif + +#ifdef _SHOWFAMILYBADGE_ + if( ext->ptFamilyIcon){//ɾͿ߶ʾ + { + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + if(ATR_PAT_NO(ext->ptFamilyIcon)){ + ATR_PAT_BAK_NO(ext->ptFamilyIcon) = ATR_PAT_NO(ext->ptFamilyIcon); + ATR_PAT_NO(ext->ptFamilyIcon) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptFamilyIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptFamilyIcon)){ + ATR_PAT_NO(ext->ptFamilyIcon) = ATR_PAT_BAK_NO(ext->ptFamilyIcon); + } + } + short x1,y1,x2,y2; + y2=x2=0; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptFamilyIcon->x = ptAct->x; + ext->ptFamilyIcon->y = ptAct->y; + ext->ptFamilyIcon->mx = ptAct->mx; + ext->ptFamilyIcon->my = ptAct->my; + pattern( ext->ptFamilyIcon, ANM_NOMAL_SPD, ANM_LOOP ); +#ifdef _CHARTITLE_ + if(ext->ptTitleIcon){ + ȡߴ(ext->ptTitleIcon,&x2,&y2); + x2=x2/2; + } +#endif + +#ifdef _CHARTITLE_STR_ + if(ptAct->TitleText.flg){ + x2 = ptAct->TitleText.len/2+15; + } + setCharPrio( ext->ptFamilyIcon->bmpNo, + ext->ptFamilyIcon->x-x2, ext->ptFamilyIcon->y, 0,-(y1/2+_FANILYTEXIAOY_)-2, + ext->ptFamilyIcon->mx, ext->ptFamilyIcon->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); +#else + setCharPrio( ext->ptFamilyIcon->bmpNo, + ext->ptFamilyIcon->x-x2, ext->ptFamilyIcon->y, 0,-(y1/2+_FANILYTEXIAOY_), + ext->ptFamilyIcon->mx, ext->ptFamilyIcon->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); +#endif + + + } + } + } + } +#endif + +#ifdef FAMILY_MANOR_ + if( ext->ptmFamilyIcon ){//ɾͿ߶ʾ + { + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + if(ATR_PAT_NO(ext->ptmFamilyIcon)){ + ATR_PAT_BAK_NO(ext->ptmFamilyIcon) = ATR_PAT_NO(ext->ptmFamilyIcon); + ATR_PAT_NO(ext->ptmFamilyIcon) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptmFamilyIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptmFamilyIcon)){ + ATR_PAT_NO(ext->ptmFamilyIcon) = ATR_PAT_BAK_NO(ext->ptmFamilyIcon); + } + } + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptmFamilyIcon->x = ptAct->x; + ext->ptmFamilyIcon->y = ptAct->y; + ext->ptmFamilyIcon->mx = ptAct->mx; + ext->ptmFamilyIcon->my = ptAct->my; + pattern( ext->ptmFamilyIcon, ANM_NOMAL_SPD, ANM_LOOP ); + setCharPrio( ext->ptmFamilyIcon->bmpNo, + ext->ptmFamilyIcon->x, ext->ptmFamilyIcon->y, 0,-(y1/2+_FANILYTEXIAOY_)+100, + ext->ptmFamilyIcon->mx, ext->ptmFamilyIcon->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + + } + } + } + } +#endif + +#ifdef _CHARTITLE_ + if( ext->ptTitleIcon ){//ɾͿ߶ʾ + { + if(ο && ProcNo==PROC_GAME && pc.ptAct != ptAct ){ + if(ATR_PAT_NO(ext->ptTitleIcon)){ + ATR_PAT_BAK_NO(ext->ptTitleIcon) = ATR_PAT_NO(ext->ptTitleIcon); + ATR_PAT_NO(ext->ptTitleIcon) = 0; + } + }else{ + if(!ATR_PAT_NO(ext->ptTitleIcon) ){ + if(ATR_PAT_BAK_NO(ext->ptTitleIcon)){ + ATR_PAT_NO(ext->ptTitleIcon) = ATR_PAT_BAK_NO(ext->ptTitleIcon); + } + } + short x1,y1,x2,y2; + y2=x2=0; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptTitleIcon->x = ptAct->x; + ext->ptTitleIcon->y = ptAct->y; + ext->ptTitleIcon->mx = ptAct->mx; + ext->ptTitleIcon->my = ptAct->my; + pattern( ext->ptTitleIcon, ANM_NOMAL_SPD, ANM_LOOP ); + if(ext->ptFamilyIcon){ + x2=10; + } + setCharPrio( ext->ptTitleIcon->bmpNo, + ext->ptTitleIcon->x+x2, ext->ptTitleIcon->y, 0,-(y1/2+_FANILYTEXIAOY_), + ext->ptTitleIcon->mx, ext->ptTitleIcon->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + + } + } + } + } +#endif + + +#ifdef _ITEM_FIREWORK + if (ext->pActFirework[0]) // Ҫ̻ + { + float fX, fY; + + camMapToGamen((float)ext->pActFirework[0]->gx * GRID_SIZE, (float)ext->pActFirework[0]->gy * GRID_SIZE, &fX, &fY); + ext->pActFirework[0]->x = (int)fX; + ext->pActFirework[0]->y = (int)fY; + // һ̻,typeҪô + if (pattern(ext->pActFirework[0], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + if (ext->pActFirework[0]->damage == 0) // һм + { + int nGX, nGY; + + nGX = ext->pActFirework[0]->gx; + nGY = ext->pActFirework[0]->gy; + ext->pActFirework[1] = GetAction(PRIO_CHR, 0); + ext->pActFirework[1]->damage = 1; + ext->pActFirework[1]->anim_chr_no = ext->pActFirework[0]->anim_chr_no; + ext->pActFirework[1]->anim_no = ANIM_STAND; + ext->pActFirework[1]->anim_ang = 1; + ext->pActFirework[1]->actNo = 0; + ext->pActFirework[1]->dispPrio = DISP_PRIO_RESERVE; + ext->pActFirework[0]->gx = nGX - 2; + ext->pActFirework[0]->gy = nGY - 2; + ext->pActFirework[0]->anim_frame_cnt = 0; + ext->pActFirework[0]->anim_cnt = 0; + ext->pActFirework[1]->gx = nGX + 2; + ext->pActFirework[1]->gy = nGY + 2; + ext->pActFirework[0]->damage = -1; + } + else if (ext->pActFirework[0]->damage == 1) // м + { + ext->pActFirework[1] = GetAction(PRIO_CHR, 0); + ext->pActFirework[1]->anim_chr_no = ext->pActFirework[0]->anim_chr_no; + ext->pActFirework[1]->anim_no = ANIM_STAND; + ext->pActFirework[1]->anim_ang = 1; + ext->pActFirework[1]->actNo = 0; + ext->pActFirework[1]->dispPrio = DISP_PRIO_RESERVE; + ext->pActFirework[1]->level = 1; // level + ext->pActFirework[1]->gx = ext->pActFirework[0]->gx; + ext->pActFirework[1]->gy = ext->pActFirework[0]->gy; + ext->pActFirework[0]->damage = -2; + } + else if (ext->pActFirework[0]->damage == 2 || ext->pActFirework[0]->damage == -1) + ext->pActFirework[0]->damage = -2; + else if (ext->pActFirework[0]->damage == 3) // һȦ, + { + ext->pActFirework[1] = GetAction(PRIO_CHR, 0); + ext->pActFirework[1]->anim_chr_no = ext->pActFirework[0]->anim_chr_no; + ext->pActFirework[1]->anim_no = ANIM_STAND; + ext->pActFirework[1]->anim_ang = 1; + ext->pActFirework[1]->actNo = 0; + ext->pActFirework[1]->dispPrio = DISP_PRIO_RESERVE; + ext->pActFirework[1]->level = 10; // level + ext->pActFirework[1]->damage = ext->pActFirework[0]->damage; + ext->pActFirework[1]->gx = ext->pActFirework[0]->bufGx[0] - 2; + ext->pActFirework[1]->gy = ext->pActFirework[0]->bufGy[0] - 2; + ext->pActFirework[1]->bufGx[0] = ext->pActFirework[0]->bufGx[0]; + ext->pActFirework[1]->bufGy[0] = ext->pActFirework[0]->bufGy[0]; + ext->pActFirework[0]->damage = -2; + } + } + if (ext->pActFirework[0]->damage == -2 || warpEffectStart) + { + DeathAction(ext->pActFirework[0]); + ext->pActFirework[0] = NULL; + } + } + if (ext->pActFirework[1]) + { + float fX, fY; + + camMapToGamen((float)ext->pActFirework[1]->gx * GRID_SIZE, (float)ext->pActFirework[1]->gy * GRID_SIZE, &fX, &fY); + ext->pActFirework[1]->x = (int)fX; + ext->pActFirework[1]->y = (int)fY; + if (pattern(ext->pActFirework[1], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + if (--ext->pActFirework[1]->level >= 0) // 㻹Ҫܼ + { + ext->pActFirework[1]->anim_frame_cnt = 0; + ext->pActFirework[1]->anim_cnt = 0; + if (ext->pActFirework[1]->damage == 3) + { + int nXY[4][2] = { {3,-3}, {2,2}, {-3,3}, {-2,-2}}; + int nDir = ext->pActFirework[1]->level % 4; + + ext->pActFirework[1]->gx = ext->pActFirework[1]->bufGx[0] + nXY[nDir][0]; + ext->pActFirework[1]->gy = ext->pActFirework[1]->bufGy[0] + nXY[nDir][1]; + } + } + else + { + DeathAction(ext->pActFirework[1]); + ext->pActFirework[1] = NULL; + } + } + if (warpEffectStart) + { + DeathAction(ext->pActFirework[1]); + ext->pActFirework[1] = NULL; + } + } +#endif +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000004) + { + int iScore = pc.iTheaterMode >> 16, iDisplayNum; + + if (iScore == 100) + { + StockDispBuffer(280, 240, DISP_PRIO_MENU, CG_CNT_DOWN_1, 0); + StockDispBuffer(310, 240, DISP_PRIO_MENU, CG_CNT_DOWN_0, 0); + StockDispBuffer(340, 240, DISP_PRIO_MENU, CG_CNT_DOWN_0, 0); + } + else + { + iDisplayNum = iScore / 10 + CG_CNT_DOWN_0; + StockDispBuffer(300, 240, DISP_PRIO_MENU, iDisplayNum, 0); + iDisplayNum = iScore % 10 + CG_CNT_DOWN_0; + StockDispBuffer(330, 240, DISP_PRIO_MENU, iDisplayNum, 0); + } + } +#endif +#ifdef _NPC_MAGICCARD + { + float fX, fY; + char buf[32]; + int i,color; + + if( TimeGetTime() > inextexet ){ + inextexet = TimeGetTime() + 35; + for( i=0;i<20;i++){ + if( bShowflag[i] == FALSE ) continue; + iOffsetY[i]+=1; + if( iOffsetY[i] >= 60 ){ + iOffsetY[i] = 0; + iPosition[i] = 0; + bShowflag[i] = FALSE; + } + } + } + //sprintf_s(buf,"%d",MAX_PAL);//iTotalRunCount); + //PaletteChange(0,10); + //StockFontBufferExt( 400 , 240 , FONT_PRIO_FRONT, 5 , buf , 0 ,16); + //StockDispBuffer( 320 , 228 , DISP_PRIO_MENU , 26274 , 1); + //StockBoxDispBuffer( 400, 350 , 450, 400, DISP_PRIO_BOX, 249, 0 ); + +/* + if( iTotalRunCount % 20 == 0 ){ + iPosition[0] +=1; + if( iPosition[0] > 44 ){ + iPosition[0] = 0; + } + } +*/ + //StockFontBufferExt( 400 , 240-offsetYtbl[iPosition[0]] , FONT_PRIO_FRONT, 6 , "-1" , 0 , 18+iPosition[0] ); + //StockFontBufferExt( 10 , 240 , FONT_PRIO_FRONT, 2 , "-8" , 0 , 18 ); + + + for( i=0;i<20;i++){ + if( bShowflag[i] == TRUE ){ + //if( iShowdamage[i] == 0) continue; + if( iShowdamage[i] > 0 ){ + if( iShowdamage[i] == 1111){ + sprintf_s( buf,"ɹ"); + color = FONT_PAL_BLUE; + }else if( iShowdamage[i] == 2222 ){ + sprintf_s( buf,"ʧ"); + color = FONT_PAL_PURPLE; + }else{ + sprintf_s( buf,"-%d",iShowdamage[i]); + color = FONT_PAL_PURPLE ; + } + }else{ + sprintf_s( buf,"+%d",ABS(iShowdamage[i])); + color = FONT_PAL_GREEN; + } +#ifdef _MOVE_SCREEN + if(pc.bMoveScreenMode) + camMapToGamen((float)(Positiontable[iPosition[i]].humanX-iScreenMoveX + ioffsetsx) * GRID_SIZE, (float)(Positiontable[iPosition[i]].humanY-iScreenMoveY + ioffsetsy) * GRID_SIZE, &fX, &fY); + else + //camMapToGamen((float)Positiontable[iPosition[i]].humanX * GRID_SIZE, (float)Positiontable[iPosition[i]].humanY * GRID_SIZE, &fX, &fY); +#endif + camMapToGamen((float)(Positiontable[iPosition[i]].humanX + ioffsetsx ) * GRID_SIZE, (float)(Positiontable[iPosition[i]].humanY + ioffsetsy ) * GRID_SIZE, &fX, &fY); + //StockFontBuffer( (int)fX+30 , (int)fY-20-offsetYtbl[iOffsetY[i]] , FONT_PRIO_FRONT, color , buf , 0 ); + //StockFontBufferExt( (int)fX-20 , (int)fY , FONT_PRIO_FRONT, color , buf , 0 , 36); + //StockFontBufferExt( (int)fX-10 , (int)fY-20-offsetYtbl[iOffsetY[i]] , FONT_PRIO_FRONT, color , buf , 0 , 36); + //StockFontBufferExt( (int)fX-10 , (int)fY-20 , FONT_PRIO_FRONT, color , buf , 0 , 18+iOffsetY[i]); + //StockFontBufferExt( (int)fX-80+offsetYtbl[iOffsetY[i]] , (int)fY-50 , FONT_PRIO_FRONT, color , buf , 0 , 18+fonttbl[iOffsetY[i]]); + //StockFontBufferExt( (int)fX+4 , (int)fY-iOffsetY[i] , FONT_PRIO_FRONT, color , buf , 0 , 18+fonttbl[iOffsetY[i]]); + StockFontBuffer((int)fX+4 , (int)fY-iOffsetY[i] , FONT_PRIO_FRONT, color , buf , 0); + } + } + + if( ext->pActMagiccard[0] ) + { + camMapToGamen((float)ext->pActMagiccard[0]->gx * GRID_SIZE, (float)ext->pActMagiccard[0]->gy * GRID_SIZE, &fX, &fY); + ext->pActMagiccard[0]->x = (int)fX; + ext->pActMagiccard[0]->y = (int)fY; + if(pattern( ext->pActMagiccard[0], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(ext->pActMagiccard[0]); + ext->pActMagiccard[0] = NULL; + }/* + if( warpEffectStart ){ + DeathAction(ext->pActMagiccard[0]); + ext->pActMagiccard[0] = NULL; + }*/ + } + if( ext->pActMagiccard[1] && ext->pActMagiccard[0] == NULL ) + { + camMapToGamen((float)ext->pActMagiccard[1]->gx * GRID_SIZE, (float)ext->pActMagiccard[1]->gy * GRID_SIZE, &fX, &fY); + ext->pActMagiccard[1]->x = (int)fX; + ext->pActMagiccard[1]->y = (int)fY; + if(pattern( ext->pActMagiccard[1], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(ext->pActMagiccard[1]); + ext->pActMagiccard[1] = NULL; + }/* + if( warpEffectStart ){ + DeathAction(ext->pActMagiccard[1]); + ext->pActMagiccard[1] = NULL; + }*/ + } + if( ext->pActMagiccard[2] && ext->pActMagiccard[0] == NULL && ext->pActMagiccard[1] == NULL ) + { + camMapToGamen((float)ext->pActMagiccard[2]->gx * GRID_SIZE, (float)ext->pActMagiccard[2]->gy * GRID_SIZE, &fX, &fY); + ext->pActMagiccard[2]->x = (int)fX; + ext->pActMagiccard[2]->y = (int)fY; + if(pattern( ext->pActMagiccard[2], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(ext->pActMagiccard[2]); + ext->pActMagiccard[2] = NULL; + }/* + if( warpEffectStart ){ + DeathAction(ext->pActMagiccard[2]); + ext->pActMagiccard[2] = NULL; + }*/ + } + if( ext->pActMagiccard[3] && ext->pActMagiccard[0] == NULL && ext->pActMagiccard[1] == NULL && ext->pActMagiccard[2] == NULL ) + { + camMapToGamen((float)ext->pActMagiccard[3]->gx * GRID_SIZE, (float)ext->pActMagiccard[3]->gy * GRID_SIZE, &fX, &fY); + ext->pActMagiccard[3]->x = (int)fX; + ext->pActMagiccard[3]->y = (int)fY; + if(pattern( ext->pActMagiccard[3], ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + DeathAction(ext->pActMagiccard[3]); + ext->pActMagiccard[3] = NULL; + } + /* + if( warpEffectStart ){ + DeathAction(ext->pActMagiccard[3]); + ext->pActMagiccard[3] = NULL; + }*/ + } + if( warpEffectStart ){ + for( i=0;i<4;i++){ + DeathAction(ext->pActMagiccard[i]); + ext->pActMagiccard[i] = NULL; + } + } + } +#endif +#ifdef _NPC_PICTURE + if( ((ptAct->picture>>24) & 0x000000ff) == 2 && ext->ptActPicture == NULL ) { + if( g_bUseAlpha ) + ext->ptActPicture = + createCommmonEffectAction( 101812, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR ); + else + ext->ptActPicture = + createCommmonEffectAction( 101865, ptAct->gx, ptAct->gy, 0, 0, DISP_PRIO_CHAR ); + } + else if( ((ptAct->picture>>24) & 0x000000ff) != 2 && ext->ptActPicture != NULL ) { + // ?????????????? + DeathAction( ext->ptActAngelMark ); + ext->ptActAngelMark = NULL; + } + else if( ((ptAct->picture>>24) & 0x000000ff) == 2 && ext->ptActPicture != NULL ) { + int pictable[9]={100388,100841,101178,100854,101570,100353,101759,101424,101489}; + if( ptAct->anim_chr_no == pictable[((ptAct->picture&0x00ff0000)>>16)&0x000000ff] ){ + //int no; + //no = (ptAct->anim_chr_no - SPR_001em) / 20; + //no %= 12; // P??????h??? + // ??????????????? + + + short x1,y1; + if(ȡߴ(ptAct,&x1,&y1)){ + ext->ptActPicture->x = ptAct->x; + ext->ptActPicture->y = ptAct->y + ptAct->anim_y + 140; + ext->ptActPicture->mx = ptAct->mx; + ext->ptActPicture->my = ptAct->my; + // ????????? + pattern( ext->ptActPicture, ANM_NOMAL_SPD, ANM_LOOP ); + // ?????????????? + setCharPrio( ext->ptActPicture->bmpNo, ext->ptActPicture->x, ext->ptActPicture->y, 0,ptAct->sFamilyIcon?-(y1/2+_OTHERTEXIAOY_):-(y1/2+_FANILYTEXIAOY_), ext->ptActPicture->mx, ext->ptActPicture->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + + } + } + } + /*if( ((ptAct->picture>>24) & 0x000000ff) == 2 ){ + int pictable[9]={100388,100841,101178,100854,101570,100353,101759,101424,101489}; + if( ptAct->anim_chr_no == pictable[((ptAct->picture&0x00ff0000)>>16)&0x000000ff] ){ + int no; + U4 bmpNo; + no = (ptAct->anim_chr_no - SPR_001em) / 20; + no %= 12; // P??????h??? + realGetNo( CG_TRADE_MARK, &bmpNo ); + // ?????????????? + setCharPrio( bmpNo, ptAct->x, ptAct->y, 0, charIconOffsetY[no], ptAct->mx, ptAct->my + #ifdef _SFUMATO + , ptAct->sfumato + #endif + ); + } + } + */ +#endif + +} +#ifdef _AniCharBubble // Syu ADD ³ +void CharbubbleRelease() +{ + if ( popAct != NULL ) + { + DeathAction(popAct); + popAct = NULL; + } + popflag = false; + waittimeflag = false; +} +#endif +// ????????????q? +void setCharNameColor( ACTION *ptAct, int color ) +{ + CHAREXTRA *ext; + int no; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + ptAct->charNameColor = color; + charObj[no].charNameColor = color; +} + +// ?o??????? ///////////////////////////////////////////////// +ACTION *createCommmonEffectAction( int graNo, int gx, int gy, int anim, int dir, int prio ) +{ + ACTION *ptAct; + float mx, my; + /* ?????????K? */ + ptAct = GetAction( PRIO_CHR, 0 ); + if( ptAct == NULL ) + return NULL; + // ???????k? + ptAct->anim_chr_no = graNo; + // h?k? + ptAct->anim_no = anim; + // ?????????( ??? )( ??????? ) + ptAct->anim_ang = dir; + // ?IT + ptAct->dispPrio = prio; + // 1???????? + ptAct->atr = ACT_ATR_HIDE2; + // ???t + ptAct->nextGx = gx; // ??????????hI? + ptAct->nextGy = gy; + ptAct->gx = gx; // ???????????? + ptAct->gy = gy; + ptAct->mx = (float)gx * GRID_SIZE; // ???? + ptAct->my = (float)gy * GRID_SIZE; + ptAct->vx = 0; // ?h? + ptAct->vy = 0; + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + return ptAct; +} + +// ?o??????????????? ///////////////////////////////// +// ???????????????????????? +void commmonEffectNoLoop( ACTION *ptAct ) +{ + float mx, my; + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + // ????????? + if( pattern( ptAct, ANM_NOMAL_SPD, ANM_NO_LOOP ) == 0 ) + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y+1, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + else{ + // ??????????????????? + DeathAction( ptAct ); + ptAct = NULL; + } +} + +ACTION *createCommmonEffectNoLoop( int graNo, int gx, int gy, int anim, int dir, int prio ) +{ + ACTION *ptAct; + float mx, my; + /* ?????????K? */ + ptAct = GetAction( PRIO_CHR, 0 ); + if( ptAct == NULL ) + return NULL; + // ??? + ptAct->func = commmonEffectNoLoop; + // ???????k? + ptAct->anim_chr_no = graNo; + // h?k? + ptAct->anim_no = anim; + // ?????????( ??? )( ??????? ) + ptAct->anim_ang = dir; + // ?IT + ptAct->dispPrio = prio; + // 1???????? + ptAct->atr = ACT_ATR_HIDE2; + // ???t + ptAct->nextGx = gx; // ??????????hI? + ptAct->nextGy = gy; + ptAct->gx = gx; // ???????????? + ptAct->gy = gy; + ptAct->mx = (float)gx * GRID_SIZE; // ???? + ptAct->my = (float)gy * GRID_SIZE; + ptAct->vx = 0; // ?h? + ptAct->vy = 0; + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + return ptAct; +} + +// ???h?? ///////////////////////////////////////////////////////// +void changeCharAct( ACTION *ptAct, int x, int y, int dir, int action, + int effectno, int effectparam1, int effectparam2 ) +{ + CHAREXTRA *ext; + int no; + int i; + if( ptAct == NULL ) + return; + ext = (CHAREXTRA *)ptAct->pYobi; + no = ext->charObjTblId; + switch( action ){ + // ??֢t + case 0: + ptAct->bufCount = 0; + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ??? + case 31: + // ??֢t???G?{?????????? + // ????????? + setCharWarpPoint( ptAct, x, y ); + ptAct->bufCount = 0; + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + charObj[no].stockDir = -1; + break; + + // ?? + case 30: + // ???????????? + charObj[no].stockDir = dir; + charObj[no].stockDirX = x; + charObj[no].stockDirY = y; + if( (x == ptAct->nextGx && y == ptAct->nextGy) || ABS( ABS( x - ptAct->nextGx ) - ABS( y - ptAct->nextGy ) ) > 1 ) + break; + + // ? + case 1: + // NPC????????h???????V?????? + if( (charObj[no].status & CHR_STATUS_PARTY) != 0 && (charObj[no].status & CHR_STATUS_LEADER) != 0 ){ + // ?????????????? + if( ptAct->bufCount < sizeof( ptAct->bufGx )/sizeof( int ) ) + correctCharMovePoint( ptAct, x, y ); + else{ + // ???????????????????????? + stockCharMovePoint( ptAct, x, y ); + charObj[no].stockDir = -1; + // ????????? + for( i = 1; i < MAX_PARTY; i++ ){ + if( party[i].useFlag != 0 ){ + if( party[i].id != pc.id ){ + // ????? + party[i].ptAct->bufCount = 0; + setCharWarpPoint( party[i].ptAct, x, y ); + }else{ + // ???? + if( pc.ptAct != NULL ) + pc.ptAct->bufCount = 0; + setPcWarpPoint( x, y ); + } + } + } + } + }else + stockCharMovePoint( ptAct, x, y ); + ptAct->anim_no = ANIM_WALK; + break; + + // ?? + case 2: + ptAct->anim_no = ANIM_ATTACK; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ??? + case 3: + ptAct->anim_no = ANIM_THROW; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ???? + case 4: + ptAct->anim_no = ANIM_DAMAGE; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ? + case 5: + ptAct->anim_no = ANIM_DEAD; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ?? + case 6: + break; + + // ????? + case 7: + break; + + // ????? + case 8: /* UsedMagic */ + break; + + // X?? + case 10: + ptAct->anim_no = ANIM_DEAD; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ?? + case 11: + ptAct->anim_no = ANIM_SIT; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ?? + case 12: + ptAct->anim_no = ANIM_HAND; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ?? + case 13: + ptAct->anim_no = ANIM_HAPPY; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // W? + case 14: + ptAct->anim_no = ANIM_ANGRY; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // v?? + case 15: + ptAct->anim_no = ANIM_SAD; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ??? + case 16: + ptAct->anim_no = ANIM_GUARD; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ??h???? + case 17: + ptAct->anim_no = ANIM_WALK; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ???? + case 18: + ptAct->anim_no = ANIM_NOD; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // ??֢t??????? + case 19: + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + ptAct->anim_ang = dir; + break; + + // Pfѩ + case 20: + if( effectno >= 0 ){ + setCharBattle( ptAct, effectno, effectparam1, effectparam2 ); + // ????????? + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + }else + delCharBattle( ptAct ); + setCharWarpPoint( ptAct, x, y ); + ptAct->anim_ang = dir; + break; + + // ????ѩ + case 21: + if( effectno == 1 ) + setCharLeader( ptAct ); + else + delCharLeader( ptAct ); + ptAct->anim_ang = dir; + break; + + // ?Pѩ + case 22: + if( effectno == 1 ) + setCharWatch( ptAct ); + else + delCharWatch( ptAct ); + setCharWarpPoint( ptAct, x, y ); + ptAct->anim_ang = dir; + break; + + // ???????????q? + case 23: + setCharNameColor( ptAct, effectno ); + break; + + // + case 32: + if( effectno >= 0 ){ + setCharTrade( ptAct, effectno ); + // ????????? + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + }else + delCharTrade( ptAct ); + //setCharWarpPoint( ptAct, x, y ); + ptAct->anim_ang = dir; + break; + +#ifdef _ANGEL_SUMMON + case 34: + if( effectno > 0 ){ + setCharAngel( ptAct ); + // ????????? + ptAct->anim_no = ANIM_STAND; + ptAct->anim_no_bak = -1; + }else + delCharAngel( ptAct ); + //setCharWarpPoint( ptAct, x, y ); + ptAct->anim_ang = dir; + break; +#endif + +#ifdef _STREET_VENDOR + case 41: + if(ext->ptStreetVendor){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } + ext->ptStreetVendor = GetAction(PRIO_CHR,0); + break; + case 42: + if(ext->ptStreetVendor){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } + break; +#endif +#ifdef _MIND_ICON + case 40: + if(effectno >= 0) + setCharMind( ptAct, effectno); + else + delCharMind( ptAct); + break; +#endif +#ifdef _SHOWFAMILYBADGE_ + case 43: + if(effectno >= 0){ + setCharFamily( ptAct, effectno); + }else + delCharFamily( ptAct); + break; +#endif +#ifdef FAMILY_MANOR_ + case 44: + if(effectno >= 0) + setCharmFamily( ptAct, effectno); + else + delCharmFamily( ptAct); + break; +#endif +#ifdef _CHARTITLE_ + case 45: + if(effectno >= 0) + setCharmTitle( ptAct, effectno); + else + delCharmTitle( ptAct); + break; +#endif +#ifdef _CHAR_MANOR_ + case 46: + if(effectno >= 0) + setCharmManor( ptAct, effectno); + else + delCharmManor( ptAct); + break; +#endif + + +#ifdef _ITEM_CRACKER + case 50: + if(effectno >= 0) + setCharMind( ptAct, effectno); + else + delCharMind( ptAct); + break; +#endif +#ifdef _ITEM_FIREWORK + case 51: + if (ext->pActFirework[0]) + { + DeathAction(ext->pActFirework[0]); + ext->pActFirework[0] = NULL; + } + if (ext->pActFirework[1]) + { + DeathAction(ext->pActFirework[1]); + ext->pActFirework[1] = NULL; + } + ext->pActFirework[0] = GetAction(PRIO_CHR, 0); + ext->pActFirework[0]->damage = effectno; // damage type (effectno = type) + ext->pActFirework[0]->anim_chr_no = effectparam1; + ext->pActFirework[0]->anim_no = ANIM_STAND; + ext->pActFirework[0]->anim_ang = 1; + ext->pActFirework[0]->dispPrio = DISP_PRIO_RESERVE; + if (effectno == 3) + { + ext->pActFirework[0]->gx = ptAct->gx + 3; + ext->pActFirework[0]->gy = ptAct->gy - 3; + ext->pActFirework[0]->bufGx[0] = pc.ptAct->gx; + ext->pActFirework[0]->bufGy[0] = pc.ptAct->gy; + } + else + { + ext->pActFirework[0]->gx = ptAct->gx; + ext->pActFirework[0]->gy = ptAct->gy; + } + ext->pActFirework[0]->actNo = 0; + #ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + { + ext->pActFirework[0]->gx -= iScreenMoveX; + ext->pActFirework[0]->gy -= iScreenMoveY; + } + #endif + break; +#endif +#ifdef _NPC_MAGICCARD + case 60: + { + int i; + + for( i=0;i<4;i++){ + if(ext->pActMagiccard[i]){ + DeathAction(ext->pActMagiccard[i]); + ext->pActMagiccard[i] = NULL; + } + } + //changePcAct(x, y, dir, 60 , giver , actionNum , petaction) + //changePcAct( card , damage , dir, 60 , player , actionNum , action); + //effectno ֵʩߵλñ + if( effectparam2 == 3 ){ //ħ + ext->pActMagiccard[0] = GetAction(PRIO_CHR,0); + ext->pActMagiccard[0]->anim_chr_no = effectparam1; + ext->pActMagiccard[0]->dispPrio = DISP_PRIO_RESERVE; + if( effectparam1 == 101120 || effectparam1 == 101628){ + ext->pActMagiccard[0]->gx = Positiontable[effectno].humanX+1 + x; //.magic1X; + ext->pActMagiccard[0]->gy = Positiontable[effectno].humanY-1 + y; //.magic1Y; + }else{ + ext->pActMagiccard[0]->gx = Positiontable[effectno].petX+1 + x; + ext->pActMagiccard[0]->gy = Positiontable[effectno].petY-1 + y; + } + }else if( effectparam2 == 0 ){ //ӡǷ + ext->pActMagiccard[0] = GetAction(PRIO_CHR,0); + ext->pActMagiccard[0]->anim_chr_no = 101290; + ext->pActMagiccard[0]->dispPrio = DISP_PRIO_RESERVE; + ext->pActMagiccard[0]->gx = Positiontable[effectno].humanX+1 + x; + ext->pActMagiccard[0]->gy = Positiontable[effectno].humanY-1 + y; + }else{ + for( i=0;i<4;i++){ + ext->pActMagiccard[i] = GetAction(PRIO_CHR,0); + if( i == 0 ){ + ext->pActMagiccard[i]->anim_chr_no = 101942; + }else if( i == 3 ){ + ext->pActMagiccard[i]->anim_chr_no = 101943; + }else{ + ext->pActMagiccard[i]->anim_chr_no = effectparam1; + } + ext->pActMagiccard[i]->gx = Positiontable[effectno].petX + x; + ext->pActMagiccard[i]->gy = Positiontable[effectno].petY + y; + ext->pActMagiccard[i]->dispPrio = DISP_PRIO_RESERVE; + ext->pActMagiccard[i]->anim_ang = dir;//1; // + } + + ext->pActMagiccard[1]->anim_no = ANIM_STAND; + + if( effectparam2 == 1 ) //ƹ + ext->pActMagiccard[2]->anim_no = ANIM_ATTACK; + else if( effectparam2 == 2 ) //Ʒ + ext->pActMagiccard[2]->anim_no = ANIM_GUARD; + } +#ifdef _MOVE_SCREEN + if(pc.bMoveScreenMode) + { + for( i=0;i<4;i++){ + if(ext->pActMagiccard[i]){ + ext->pActMagiccard[i]->gx -= iScreenMoveX; + ext->pActMagiccard[i]->gy -= iScreenMoveY; + } + } + } +#endif + } + break; +#endif + + } +} + +// ID?? +// ??k 0? ... ID????t / -1 ... ??? +int searchCharObjId( int id ) +{ + int i; + int no = -1; + for( i = searchCharObj; i < tailCharObj; i++ ){ + if( charObj[i].use != CHAROBJ_USE_FREE && charObj[i].id == id ){ + no = i; + searchCharObj = i; + break; + } + } + if( no < 0 && searchCharObj > 0 ){ + for( i = 0; i < searchCharObj; i++ ){ + if( charObj[i].use != CHAROBJ_USE_FREE && charObj[i].id == id ){ + no = i; + searchCharObj = i; + break; + } + } + } + return no; +} + +// ??? +// ??kTRUE ... ??????? +BOOL checkCharObjPoint( int gx, int gy, short type ) +{ + int i; + int no = -1; + for( i = 0; i < tailCharObj; i++ ){ + if( charObj[i].use != CHAROBJ_USE_FREE && charObj[i].ptAct != NULL ){ + if( charObj[i].ptAct->gx == gx && charObj[i].ptAct->gy == gy && (charObj[i].type & type) != 0 ) + return TRUE; + } + } + return FALSE; +} + +// ????????? +// ??k1 ... ?????????????? +// 0 ... ???? +#ifdef _ANGEL_SUMMON +int checkCharObjPointStatus( int gx, int gy, short type, unsigned status ) +#else +int checkCharObjPointStatus( int gx, int gy, short type, unsigned short status ) +#endif +{ + int i; + int no = -1; + for( i = 0; i < tailCharObj; i++ ){ + if( charObj[i].use != CHAROBJ_USE_FREE && charObj[i].ptAct != NULL ){ + if( charObj[i].ptAct->gx == gx && charObj[i].ptAct->gy == gy && (charObj[i].type & type) != 0 ){ + if( (charObj[i].status & status ) != 0 ) + return 1; + } + } + } + return 0; +} + +// ????????? +// ??k1 ... ???????????????? +// 0 ... ???? +#ifdef _ANGEL_SUMMON +int checkCharObjPointNotStatus( int gx, int gy, short type, unsigned status ) +#else +int checkCharObjPointNotStatus( int gx, int gy, short type, unsigned short status ) +#endif +{ + int i; + int no = -1; + for( i = 0; i < tailCharObj; i++ ){ + if( charObj[i].use != CHAROBJ_USE_FREE && charObj[i].ptAct != NULL ){ + if( charObj[i].ptAct->gx == gx && charObj[i].ptAct->gy == gy && (charObj[i].type & type) != 0 ){ + if( (charObj[i].status & status ) == 0 ) + return 1; + } + } + } + return 0; +} + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _GM_IDENTIFY // Rog ADD GMʶ +void setNpcCharObj( int id, int graNo, int gx, int gy, int dir, char *fmname, + char *name, char *freeName, int level, char *petname, int petlevel, + int nameColor, int walk, int height, int charType, int profession_class, char *gm_name ) +#else +#ifdef _NPC_PICTURE +void setNpcCharObj( int id, int graNo, int gx, int gy, int dir, char *fmname, + char *name, char *freeName, int level, char *petname, int petlevel, + int nameColor, int walk, int height, int charType, int profession_class, int picture ) +#else +void setNpcCharObj( int id, int graNo, int gx, int gy, int dir, char *fmname, + char *name, char *freeName, int level, char *petname, int petlevel, + int nameColor, int walk, int height, int charType, int profession_class ) +#endif +#endif +#else +#ifdef _NPC_EVENT_NOTICE +void setNpcCharObj( int id, int graNo, int gx, int gy, int dir, char *fmname, + char *name, char *freeName, int level, char *petname, int petlevel, + int nameColor, int walk, int height, int charType, int noticeNo +#ifdef _CHARTITLE_STR_ + ,char *title +#endif + ) +#else +void setNpcCharObj( int id, int graNo, int gx, int gy, int dir, char *fmname, + char *name, char *freeName, int level, char *petname, int petlevel, + int nameColor, int walk, int height, int charType) +#endif +#endif +{ + int no; + BOOL existFlag = FALSE; + CHAREXTRA *ext; +#ifdef _ANGEL_SUMMON + unsigned angelMode =0; +#endif + + if( (no = searchCharObjId( id )) >= 0 ) { +#ifdef _ANGEL_SUMMON + angelMode = charObj[no].status & CHR_STATUS_ANGEL; +#endif + delCharObj( id); + } + if( !existFlag ){ + no = getCharObjBuf(); + if( no < 0 ) + return; + charObj[no].ptAct = createCharAction( graNo, gx, gy, dir ); + if( charObj[no].ptAct == NULL ) + return; + + charObj[no].use = CHAROBJ_USE_VIEW; + ext = (CHAREXTRA *)charObj[no].ptAct->pYobi; + ext->charObjTblId = no; + charObj[no].type = getAtrCharObjType( charType ); + charObj[no].id = id; + charObj[no].stockDir = -1; + } +#ifdef _CHARTITLE_STR_ + getCharTitleSplit(title,&charObj[no].ptAct->TitleText); +#endif + charObj[no].graNo = graNo; + charObj[no].nameColor = nameColor; + charObj[no].level = level; + charObj[no].gx = gx; + charObj[no].gy = gy; + charObj[no].dir = dir; + if( walk != 0 ) + charObj[no].status |= CHR_STATUS_W; + if( height != 0 ) + charObj[no].status |= CHR_STATUS_H; + if( strlen( name ) <= CHAR_NAME_LEN ) + strcpy( charObj[no].name, name ); + // shan add code + if( strlen( fmname ) <= CHAR_FMNAME_LEN ) + strcpy( charObj[no].fmname, fmname ); + if( charType != CHAR_TYPEPET ){ + if( strlen( freeName ) <= CHAR_FREENAME_LEN ) + strcpy( charObj[no].freeName, freeName ); + }else{ + if( strlen( freeName ) <= PET_FREENAME_LEN ) + strcpy( charObj[no].freeName, freeName ); + } + // Robin 0730 + if( strlen( petname ) <= CHAR_FREENAME_LEN ) + strcpy( charObj[no].petName, petname ); + charObj[no].petLevel = petlevel; + + charObj[no].charType = getAtrCharType( charType ); + charObj[no].newFoundFlag = 1; + +#ifdef _ANGEL_SUMMON + charObj[no].status |= angelMode; +#endif + + if( charObj[no].ptAct == NULL ) + return; + + charObj[no].ptAct->anim_chr_no = graNo; + charObj[no].ptAct->level = level; + charObj[no].ptAct->atr |= charObj[no].charType; + if( strlen( name ) <= CHAR_NAME_LEN ) + strcpy( charObj[no].ptAct->name, name ); + // shan add + if( charType == CHAR_TYPEPLAYER){ + if( strlen( fmname) <= CHAR_FMNAME_LEN ) + strcpy( charObj[no].ptAct->fmname, fmname ); + } + else{ + strcpy( charObj[no].ptAct->fmname, " " ); + } + + if( charType != CHAR_TYPEPET ){ + if( strlen( freeName ) <= CHAR_FREENAME_LEN ) + strcpy( charObj[no].ptAct->freeName, freeName ); + }else{ + if( strlen( freeName ) <= PET_FREENAME_LEN ) + strcpy( charObj[no].ptAct->freeName, freeName ); + } + // Robin 0730 + if( strlen( petname ) <= CHAR_FREENAME_LEN ) + strcpy( charObj[no].ptAct->petName, petname ); + charObj[no].ptAct->petLevel = petlevel; + + charObj[no].ptAct->itemNameColor = nameColor; + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + charObj[no].ptAct->profession_class = profession_class; +#endif +#ifdef _NPC_PICTURE + charObj[no].ptAct->picture = picture; + charObj[no].ptAct->picturetemp = ((((picture)&0x00ff0000)>>16)&0x000000ff);//(picture&0x0000ffff); + //charObj[no].ptAct->anim_no = ((((picture)&0x0000ff00)>>8 )&0x000000ff); +#endif +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + if( strlen( gm_name ) <= GM_NAME_LEN ) + strcpy( charObj[no].ptAct->gm_name, gm_name ); +#endif +#ifdef _NPC_EVENT_NOTICE + charObj[no].ptAct->noticeNo = noticeNo; +#endif +} + + + +BOOL setReturnPetObj( int id, int graNo, int gx, int gy, int dir, +char *name, char *freeName, int level, int nameColor, int walk, int height, int charType ) +{ + int no; + // K??????????? + if( (no = searchCharObjId( id )) >= 0 ) + // ????? + return FALSE; + // ??K?????????K? + no = getCharObjBuf(); + if( no < 0 ) + return FALSE; // ???????????? + charObj[no].ptAct = NULL; + charObj[no].use = CHAROBJ_USE_VIEW; + charObj[no].type = getAtrCharObjType( charType ); + charObj[no].id = id; + charObj[no].graNo = graNo; + charObj[no].nameColor = nameColor; + charObj[no].level = level; + charObj[no].gx = gx; + charObj[no].gy = gy; + charObj[no].dir = dir; + if( walk != 0 ) + charObj[no].status |= CHR_STATUS_W; + if( height != 0 ) + charObj[no].status |= CHR_STATUS_H; + if( strlen( name ) <= CHAR_NAME_LEN ) + strcpy( charObj[no].name, name ); + if( strlen( freeName ) <= PET_FREENAME_LEN ) + strcpy( charObj[no].freeName, freeName ); + charObj[no].charType = getAtrCharType( charType ); + return TRUE; +} + +// +// ????? +// +void setItemCharObj( int id, int graNo, int gx, int gy, int dir, int classNo, char *info ) +{ + int no; + BOOL existFlag = FALSE; + CHAREXTRA *ext; + // K??????????? + if( (no = searchCharObjId( id )) >= 0 ) + existFlag = TRUE; + // ??K?????????K? + if( !existFlag ){ + no = getCharObjBuf(); + if( no < 0 ) + return; // ???????????? + charObj[no].ptAct = createCharAction( graNo, gx, gy, dir ); + if( charObj[no].ptAct == NULL ) + // K??????????o??????????? + return; + charObj[no].use = CHAROBJ_USE_VIEW; + ext = (CHAREXTRA *)charObj[no].ptAct->pYobi; + ext->charObjTblId = no; + charObj[no].type = CHAROBJ_TYPE_ITEM; + charObj[no].id = id; + charObj[no].stockDir = -1; + } + charObj[no].graNo = graNo; + charObj[no].classNo = classNo; + charObj[no].gx = gx; + charObj[no].gy = gy; + charObj[no].dir = dir; + if( strlen( info ) <= 60 ) + strcpy( charObj[no].info, info ); + charObj[no].charType = ACT_ATR_TYPE_ITEM; + charObj[no].newFoundFlag = 0; // D????????? + // ???????????k?V?? + if( charObj[no].ptAct == NULL ) + return; + charObj[no].ptAct->anim_chr_no = graNo; + // 1??????????name?V?? + if( strlen( info ) <= ITEM_NAME_LEN ) + strcpy( charObj[no].ptAct->name, info ); + else + strcpy( charObj[no].ptAct->name, "???" ); + charObj[no].ptAct->atr |= ACT_ATR_TYPE_ITEM; + charObj[no].ptAct->itemNameColor = classNo; +} + +// +// ??? +// +void setMoneyCharObj( int id, int graNo, int gx, int gy, int dir, int money, char *info ) +{ + int no; + BOOL existFlag = FALSE; + CHAREXTRA *ext; + // K??????????? + if( (no = searchCharObjId( id )) >= 0 ) + existFlag = TRUE; + // ??K?????????K? + if( !existFlag ){ + no = getCharObjBuf(); + if( no < 0 ) + return; // ???????????? + charObj[no].ptAct = createCharAction( graNo, gx, gy, dir ); + if( charObj[no].ptAct == NULL ) + // K??????????o??????????? + return; + charObj[no].use = CHAROBJ_USE_VIEW; + ext = (CHAREXTRA *)charObj[no].ptAct->pYobi; + ext->charObjTblId = no; + charObj[no].type = CHAROBJ_TYPE_MONEY; + charObj[no].id = id; + charObj[no].stockDir = -1; + } + charObj[no].graNo = graNo; + charObj[no].money = money; + charObj[no].gx = gx; + charObj[no].gy = gy; + charObj[no].dir = dir; + if( strlen( info ) <= 60 ) + strcpy( charObj[no].info, info ); + charObj[no].charType = ACT_ATR_TYPE_GOLD; + charObj[no].newFoundFlag = 0; // D????????? + // ???????????k?V?? + if( charObj[no].ptAct == NULL ) + return; + charObj[no].ptAct->anim_chr_no = graNo; + // 1??????????name?V?? + if( strlen( info ) <= CHAR_NAME_LEN ) + strcpy( charObj[no].ptAct->name, info ); + else + strcpy( charObj[no].ptAct->name, "???" ); + charObj[no].ptAct->atr |= ACT_ATR_TYPE_GOLD; +} + +// ??????????x +// ??kcharObj???? +// -1 ... ??????? +int getCharObjBuf( void ) +{ + int i; + int ret; + // ???????????? + if( maxCharObj >= MAX_CHAROBJ ) + return -1; + ret = freeCharObj; + // D?????k? + maxCharObj++; + // ???K??t + if( freeCharObj+1 > tailCharObj ) + tailCharObj = freeCharObj+1; + // ??????????? + for( i = freeCharObj+1; i < MAX_CHAROBJ; i++ ){ + if( charObj[i].use == CHAROBJ_USE_FREE ){ + freeCharObj = i; + break; + } + } + if( freeCharObj > 0 && i >= MAX_CHAROBJ ){ + for( i = 0; i < freeCharObj; i++ ){ + if( charObj[i].use == CHAROBJ_USE_FREE ){ + freeCharObj = i; + break; + } + } + } + return ret; +} + +// ???????N?????????? +// ? ?type ... ????????????k? +// ??k??????atr?@e??Nͣk +int getAtrCharType( int type ) +{ + switch( type ){ + // ??? + case CHAR_TYPEPLAYER: + case CHAR_TYPEBUS: + return ACT_ATR_TYPE_OTHER_PC; + // ??? + case CHAR_TYPEPET: + return ACT_ATR_TYPE_PET; + // ??\ + default: + return ACT_ATR_TYPE_OTHER; + } + return 0; +} + +// ?????????????????? +// ? ?type ... ????????????k? +// ??kcharObj?type?@e??Nͣk +int getAtrCharObjType( int type ) +{ + int ret; + switch( type ){ + case CHAR_TYPEPLAYER: + ret = CHAROBJ_TYPE_USER_NPC; + break; + case CHAR_TYPEDENGON: + case CHAR_TYPEDUELRANKING: + case CHAR_TYPEMSG: + ret = CHAROBJ_TYPE_NPC | CHAROBJ_TYPE_LOOKAT; + break; + case CHAR_TYPEBUS: + ret = CHAROBJ_TYPE_NPC | CHAROBJ_TYPE_PARTY_OK; + break; + default: + ret = CHAROBJ_TYPE_NPC; + break; + } + return ret; +} + +// ID?????????????? +// ?????NULL +ACTION *getCharObjAct( int id ) +{ + int no; + if( (no = searchCharObjId( id )) < 0 ) + return NULL; + if( charObj[no].ptAct == NULL ) + return NULL; + return charObj[no].ptAct; +} + + +// ???????????? +void delCharObj( int id ) +{ + int i; + int no; + CHAREXTRA *ext; + + if( pc.id == id ){ + resetPc(); + return; + } + no = searchCharObjId( id ); + // ID??????? + if( no >= 0 ){ + if( charObj[no].ptAct != NULL ){ + ext = (CHAREXTRA *)charObj[no].ptAct->pYobi; + if( ext != NULL ){ + if( ext->ptActLeaderMark != NULL ){ + DeathAction( ext->ptActLeaderMark ); + ext->ptActLeaderMark = NULL; + } + if( ext->ptActMagicEffect != NULL ){ + DeathAction( ext->ptActMagicEffect ); + ext->ptActMagicEffect = NULL; + } +#ifdef __EMOTION + if( ext->ptActEmotion != NULL ){ + DeathAction( ext->ptActEmotion ); + ext->ptActEmotion = NULL; + } +#endif +#ifdef _STREET_VENDOR + if(ext->ptStreetVendor != NULL){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } +#endif +#ifdef _MIND_ICON + if( ext->ptMindIcon != NULL ){ + DeathAction( ext->ptMindIcon ); + ext->ptMindIcon = NULL; + } +#endif +#ifdef _SHOWFAMILYBADGE_ + if( ext->ptFamilyIcon != NULL ){ + DeathAction( ext->ptFamilyIcon ); + ext->ptFamilyIcon = NULL; + } +#endif +#ifdef _CHARTITLE_ + if( ext->ptTitleIcon != NULL ){ + DeathAction( ext->ptTitleIcon ); + ext->ptTitleIcon = NULL; + } +#endif +#ifdef FAMILY_MANOR_ + if( ext->ptmFamilyIcon != NULL ){ + DeathAction( ext->ptmFamilyIcon ); + ext->ptmFamilyIcon = NULL; + } +#endif +#ifdef _CHAR_MANOR_ + if( ext->ptmManorIcon != NULL ){ + DeathAction( ext->ptmManorIcon ); + ext->ptmManorIcon = NULL; + } +#endif +#ifdef _ITEM_FIREWORK + if (ext->pActFirework[0] != NULL) + DeathAction(ext->pActFirework[0]); + if (ext->pActFirework[1] != NULL) + DeathAction(ext->pActFirework[1]); + ext->pActFirework[0] = NULL; + ext->pActFirework[1] = NULL; +#endif +#ifdef _NPC_MAGICCARD + for( i=0;i<4;i++) { + if( ext->pActMagiccard[i] != NULL ){ + DeathAction( ext->pActMagiccard[i] ); + ext->pActMagiccard[i] = NULL; + } + } +#endif + } + DeathAction( charObj[no].ptAct ); + charObj[no].ptAct = NULL; + } + charObj[no].use = CHAROBJ_USE_FREE; + charObj[no].status = 0; + charObj[no].stockDir = -1; + // K??? + if( maxCharObj > 0 ) + maxCharObj--; + // ?????t??q??????????t??? + if( freeCharObj > no ) + freeCharObj = no; + // K?????????S? + for( i = tailCharObj; i > 0; i-- ){ + if( charObj[i-1].use != CHAROBJ_USE_FREE ){ + tailCharObj = i; + break; + } + } + } +} + + +// ???????????? +void initCharObj( void ) +{ + int i; + + maxCharObj = 0; + tailCharObj = 0; + freeCharObj = 0; + for( i = 0; i < MAX_CHAROBJ; i++ ) + { + charObj[i].use = CHAROBJ_USE_FREE; + charObj[i].ptAct = NULL; + charObj[i].status = 0; + charObj[i].id = 0; + charObj[i].stockDir = -1; + charObj[i].name[0] = '\0'; + } + + searchCharObj = 0; +} + + +// ????????????? +void resetCharObj( void ) +{ + int i; + CHAREXTRA *ext; + + maxCharObj = 0; + tailCharObj = 0; + freeCharObj = 0; + for( i = 0; i < MAX_CHAROBJ; i++ ) + { + if( charObj[i].use != CHAROBJ_USE_FREE ) + { + if( charObj[i].ptAct != NULL ) + { + ext = (CHAREXTRA *)charObj[i].ptAct->pYobi; + if( ext != NULL ) + { + if( ext->ptActLeaderMark != NULL ) + { + DeathAction( ext->ptActLeaderMark ); + ext->ptActLeaderMark = NULL; + } + if( ext->ptActMagicEffect != NULL ) + { + DeathAction( ext->ptActMagicEffect ); + ext->ptActMagicEffect = NULL; + } +#ifdef __EMOTION + if( ext->ptActEmotion != NULL ){ + DeathAction( ext->ptActEmotion ); + ext->ptActEmotion = NULL; + } +#endif +#ifdef _STREET_VENDOR + if(ext->ptStreetVendor != NULL){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } +#endif +#ifdef _MIND_ICON + if( ext->ptMindIcon != NULL ){ + DeathAction( ext->ptMindIcon ); + ext->ptMindIcon = NULL; + } +#endif +#ifdef _SHOWFAMILYBADGE_ + if( ext->ptFamilyIcon != NULL ){ + DeathAction( ext->ptFamilyIcon ); + ext->ptFamilyIcon = NULL; + } +#endif +#ifdef _CHARTITLE_ + if( ext->ptTitleIcon != NULL ){ + DeathAction( ext->ptTitleIcon ); + ext->ptTitleIcon = NULL; + } +#endif +#ifdef FAMILY_MANOR_ + if( ext->ptmFamilyIcon != NULL ){ + DeathAction( ext->ptmFamilyIcon ); + ext->ptmFamilyIcon = NULL; + } +#endif +#ifdef _CHAR_MANOR_ + if( ext->ptmManorIcon != NULL ){ + DeathAction( ext->ptmManorIcon ); + ext->ptmManorIcon = NULL; + } +#endif +#ifdef _NPC_EVENT_NOTICE + if( ext->ptNoticeIcon != NULL ){ + DeathAction( ext->ptNoticeIcon ); + ext->ptNoticeIcon = NULL; + } +#endif +#ifdef _ITEM_FIREWORK + if (ext->pActFirework[0] != NULL) + DeathAction(ext->pActFirework[0]); + if (ext->pActFirework[1] != NULL) + DeathAction(ext->pActFirework[1]); + ext->pActFirework[0] = NULL; + ext->pActFirework[1] = NULL; +#endif +#ifdef _NPC_MAGICCARD + if (ext->pActMagiccard[0] != NULL) + DeathAction(ext->pActMagiccard[0]); + if (ext->pActMagiccard[1] != NULL) + DeathAction(ext->pActMagiccard[1]); + if (ext->pActMagiccard[2] != NULL) + DeathAction(ext->pActMagiccard[2]); + if (ext->pActMagiccard[3] != NULL) + DeathAction(ext->pActMagiccard[3]); + ext->pActMagiccard[0] = NULL; + ext->pActMagiccard[1] = NULL; + ext->pActMagiccard[2] = NULL; + ext->pActMagiccard[3] = NULL; +#endif + } + DeathAction( charObj[i].ptAct ); + charObj[i].ptAct = NULL; + } + charObj[i].use = CHAROBJ_USE_FREE; + charObj[i].status = 0; + charObj[i].id = 0; + charObj[i].stockDir = -1; + } + } + + searchCharObj = 0; +} + + +// ??????????????????????? +void clearPtActCharObj( void ) +{ + int i; + + for( i = 0; i < MAX_CHAROBJ; i++ ) + { + if( charObj[i].use != CHAROBJ_USE_FREE ) + { + charObj[i].ptAct = NULL; + charObj[i].stockDir = -1; + } + } +} + + +// ????????????????????u?????? +void restorePtActCharObjAll( void ) +{ + int i; + CHAREXTRA *ext; + + for( i = 0; i < MAX_CHAROBJ; i++ ) + { + if( charObj[i].use != CHAROBJ_USE_FREE + && charObj[i].ptAct == NULL ) + { + charObj[i].ptAct = + createCharAction( charObj[i].graNo, charObj[i].gx, charObj[i].gy, charObj[i].dir ); + if( charObj[i].ptAct == NULL ) + { + continue; + } + + charObj[i].use = CHAROBJ_USE_VIEW; + + ext = (CHAREXTRA *)charObj[i].ptAct->pYobi; + ext->charObjTblId = i; + + // NPC???????? + // \?PC???????? + // ?Y + if( charObj[i].type == CHAROBJ_TYPE_NPC + || charObj[i].type == CHAROBJ_TYPE_USER_NPC ) + { + charObj[i].ptAct->level = charObj[i].level; + strcpy( charObj[i].ptAct->name, charObj[i].name ); + charObj[i].ptAct->atr |= charObj[i].charType; + } + else + // Item???????? + if( charObj[i].type == CHAROBJ_TYPE_ITEM ) + { + // 1??????????name?V?? + if( strlen( charObj[i].info ) <= ITEM_NAME_LEN ) + { + strcpy( charObj[i].ptAct->name, charObj[i].info ); + } + else + { + strcpy( charObj[i].ptAct->name, "???" ); + } + charObj[i].ptAct->atr |= charObj[i].charType; + } + else + // ?????????? + if( charObj[i].type == CHAROBJ_TYPE_MONEY ) + { + // 1??????????name?V?? + if( strlen( charObj[i].info ) <= CHAR_NAME_LEN ) + { + strcpy( charObj[i].ptAct->name, charObj[i].info ); + } + else + { + strcpy( charObj[i].ptAct->name, "???" ); + } + charObj[i].ptAct->atr |= charObj[i].charType; + } + } + } +} + + +// ????????????????????????? +void restorePtActCharObj( int id ) +{ + int no; + CHAREXTRA *ext; + + if( id < 0 ) + return; + + // K??????????? + if( (no = searchCharObjId( id )) < 0 ) + { + // ?????? + return; + } + + if( charObj[no].use != CHAROBJ_USE_FREE + && charObj[no].ptAct == NULL ) + { + charObj[no].ptAct = + createCharAction( charObj[no].graNo, charObj[no].gx, charObj[no].gy, charObj[no].dir ); + if( charObj[no].ptAct == NULL ) + { + // ??????????????? + return; + } + + charObj[no].use = CHAROBJ_USE_VIEW; + + ext = (CHAREXTRA *)charObj[no].ptAct->pYobi; + ext->charObjTblId = no; + + charObj[no].ptAct->level = charObj[no].level; + strcpy( charObj[no].ptAct->name, charObj[no].name ); + charObj[no].ptAct->atr |= charObj[no].charType; + } +} + + +// ????t? +void setMovePointCharObj( int id, int nextGx, int nextGy ) +{ + int no; + + no = searchCharObjId( id ); + if( no >= 0 ) + { + stockCharMovePoint( charObj[no].ptAct, nextGx, nextGy ); + } +} + + + + +/////////////////////////////////////////////////////////////////////////// +// i??????i????????????????????? + +typedef struct +{ + unsigned int bmpNo; + int gx; + int gy; +} ITEM_OVERLAP_CHECK; + +#define MAX_ITEM_OVERLAP 100 +ITEM_OVERLAP_CHECK itemOverlapTbl[MAX_ITEM_OVERLAP]; +int itemOverlapCheckCnt; + +void initItemOverlapCheck( void ) +{ + itemOverlapCheckCnt = 0; +} + + +// ??k TRUE ... i???? +// FALSE ... ?? +BOOL itemOverlapCheck( unsigned int bmpNo, int gx, int gy ) +{ + int i; + BOOL flag = FALSE; + for( i = 0; i < itemOverlapCheckCnt; i++ ){ + if( itemOverlapTbl[i].bmpNo == bmpNo + && itemOverlapTbl[i].gx == gx + && itemOverlapTbl[i].gy == gy ){ + flag = TRUE; + break; + } + } + if( !flag ){ + if( itemOverlapCheckCnt < MAX_ITEM_OVERLAP ){ + itemOverlapTbl[itemOverlapCheckCnt].bmpNo = bmpNo; + itemOverlapTbl[itemOverlapCheckCnt].gx = gx; + itemOverlapTbl[itemOverlapCheckCnt].gy = gy; + itemOverlapCheckCnt++; + } + } + return flag; +} + + + + + + +/////////////////////////////////////////////////////////////////////////// +// ???????? + + +// ?????????????? +void limitCantClientDir( short *dir ) +{ + // dir?????????????? + if( ((*dir) % 2) == 0 ) + { + (*dir)++; + } +} + +// dirk? 0 ?? 7 ??????? +void ajustClientDir( short *dir ) +{ + if( *dir < 0 ) + { + do + { + (*dir) += 8; + } while( *dir < 0 ); + } + else + if( *dir > 7 ) + { + do + { + (*dir) -= 8; + } while( *dir > 7 ); + } +} + + +void getPetRoute( ACTION *ptAct ) +{ + short dir; + int i; + int dx, dy; + int gx, gy; + PETEXTRA *pe; + + if( ptAct->bufCount > 0 ) + return; + + // ???Re????????? + if( nowGx != oldGx || nowGy != oldGy ) + return; + + pe = (PETEXTRA *)ptAct->pYobi; + + dir = pe->moveDir; + + for( i = 0; i < 4; i++ ) + { + getRouteData( dir, &dx, &dy ); + gx = ptAct->gx+dx; + gy = ptAct->gy+dy; + if( (gx != pe->preGx || gy != pe->preGy) + && checkHitMap( gx, gy ) == FALSE ) + { + break; + } + dir += (2*(i+1)); + ajustClientDir( &dir ); + } + + if( i >= 4 ) + { + pe->preGx = -1; + pe->preGy = -1; + pe->moveDir -= 2; + ajustClientDir( &pe->moveDir ); + return; + } + + if( pe->dirCnt >= 2 ) + { + pe->dirCnt = 0; + pe->moveDir -= 6; + ajustClientDir( &pe->moveDir ); + } + + if( dir != pe->preDir ) + { + pe->dirCnt++; + } + else + { + pe->dirCnt = 0; + } + + pe->preDir = dir; + + ptAct->bufGx[ptAct->bufCount] = gx; + ptAct->bufGy[ptAct->bufCount] = gy; + ptAct->bufCount++; + + pe->preGx = ptAct->gx; + pe->preGy = ptAct->gy; + + return; +} + + +// ?h?? +BOOL petMoveProc( ACTION *ptAct ) +{ + PETEXTRA *pe = (PETEXTRA *)ptAct->pYobi; + + // d?????????? + // ???8?????? + if( ABS( ptAct->gx - nowGx ) >= 13 + || ABS( ptAct->gy - nowGy ) >= 13 + || (pe->createTime+8000 < TimeGetTime() && ptAct->vx == 0 && ptAct->vy == 0) ) + { + restorePtActCharObj( pe->id ); + DeathAction( ptAct ); + ptAct = NULL; + return FALSE; + } + + if( pe->ptAct == NULL && pe->createTime+7200 < TimeGetTime() ) + { + pe->ptAct = createCommmonEffectNoLoop( SPR_difence, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + if( pe->ptAct2 == NULL && pe->createTime+7500 < TimeGetTime() ) + { + pe->ptAct2 = createCommmonEffectNoLoop( SPR_difence, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + + + if( ptAct->vx == 0 && ptAct->vy == 0 ) + { + // ?h????????t??? + getPetRoute( ptAct ); + } + charMove( ptAct ); + + if( pe->ptAct != NULL ) + { + pe->ptAct->mx = ptAct->mx; + pe->ptAct->my = ptAct->my; + } + if( pe->ptAct2 != NULL ) + { + pe->ptAct2->mx = ptAct->mx; + pe->ptAct2->my = ptAct->my; + } + + return TRUE; +} + + +// ???? +BOOL uprisePetProc( ACTION *ptAct ) +{ + PETEXTRA *pe = (PETEXTRA *)ptAct->pYobi; + + if( pe->ptAct == NULL && pe->createTime < TimeGetTime() ) + { + pe->ptAct = createCommmonEffectNoLoop( SPR_difence, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + if( pe->ptAct2 == NULL && pe->createTime+500 < TimeGetTime() ) + { + pe->ptAct2 = createCommmonEffectNoLoop( SPR_difence, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + + // ??????????? + if( pe->createTime+1200 < TimeGetTime() ) + { + restorePtActCharObj( pe->id ); + DeathAction( ptAct ); + ptAct = NULL; + } + + return FALSE; +} + + +// ?????????? +BOOL petCircleOutProc( ACTION *ptAct ) +{ + PETEXTRA *pe = (PETEXTRA *)ptAct->pYobi; + float mx, my; + float dx, dy; + float angle; + int i; + + if( pe->ptAct == NULL ) + { + pe->ptAct = (ACTION *)1; + pe->angle = 0.0F; + pe->r = 0; + createCommmonEffectNoLoop( SPR_hoshi, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + + if( pe->r > 800 ) + { + restorePtActCharObj( pe->id ); + DeathAction( ptAct ); + ptAct = NULL; + return FALSE; + } + + if( pe->ptAct != NULL && pe->createTime+1000 < TimeGetTime() ) + { + pe->r += 4; + pe->angle += 6.0F; + } + + angle = pe->angle; + for( i = 0; i < 3; i++ ) + { + dx = (float)pe->r * CosT( angle ); + dy = (float)pe->r * SinT( angle ); + + // ??t + camMapToGamen( ptAct->mx+dx, ptAct->my+dy, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + + // ????????? + pattern( ptAct, ANM_NOMAL_SPD, ANM_LOOP ); + + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx+dx, ptAct->my+dy +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + angle += 120; + AdjustDir( &angle ); + } + + return FALSE; +} + + +// ????????? +BOOL petCircleInProc( ACTION *ptAct ) +{ + PETEXTRA *pe = (PETEXTRA *)ptAct->pYobi; + float mx, my; + float dx, dy; + float angle; + int i; + + if( pe->ptAct == NULL ) + { + pe->ptAct = (ACTION *)1; + pe->ptAct2 = (ACTION *)NULL; + pe->angle = 0.0F; + pe->r = 800; + } + else + { + if( pe->r <= 0 ) + { + restorePtActCharObj( pe->id ); + DeathAction( ptAct ); + ptAct = NULL; + return TRUE; + } + } + + if( pe->ptAct != NULL ) + { + if( pe->ptAct2 == NULL && pe->createTime+2300 < TimeGetTime() ) + { + pe->ptAct2 = createCommmonEffectNoLoop( SPR_hoshi, ptAct->gx, ptAct->gy, + 0, 0, ptAct->dispPrio ); + } + + pe->r -= 4; + pe->angle += 6.0F; + + angle = pe->angle; + for( i = 0; i < 3; i++ ) + { + dx = (float)pe->r * CosT( angle ); + dy = (float)pe->r * SinT( angle ); + + // ??t + camMapToGamen( ptAct->mx+dx, ptAct->my+dy, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + + // ????????? + pattern( ptAct, ANM_NOMAL_SPD, ANM_LOOP ); + + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx+dx, ptAct->my+dy +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); + angle += 120; + AdjustDir( &angle ); + } + } + + return FALSE; +} + + +// ?????????????? +void petProc( ACTION *ptAct ) +{ + float mx, my; + int animLoop; + PETEXTRA *pe = (PETEXTRA *)ptAct->pYobi; + + switch( pe->mode ) + { + // ?????????? + case 0: + if( !petMoveProc( ptAct ) ) + { + return; + } + break; + + // ????? + // ???????????? + case 1: + if( !uprisePetProc( ptAct ) ) + { + return; + } + break; + + // ?????????? + case 2: + if( !petCircleOutProc( ptAct ) ) + { + return; + } + break; + + // ?????????? + case 3: + if( !petCircleInProc( ptAct ) ) + { + return; + } + break; + } + + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + + // ????????? + if( ptAct->anim_no == ANIM_HAND + || ptAct->anim_no == ANIM_HAPPY + || ptAct->anim_no == ANIM_ANGRY + || ptAct->anim_no == ANIM_SAD + || ptAct->anim_no == ANIM_WALK + || ptAct->anim_no == ANIM_STAND + || ptAct->anim_no == ANIM_NOD ) + { + animLoop = ANM_LOOP; + } + else + { + animLoop = ANM_NO_LOOP; + } + pattern( ptAct, ANM_NOMAL_SPD, animLoop ); + + // ?????????????? + setCharPrio( ptAct->bmpNo, ptAct->x, ptAct->y, 0, 0, ptAct->mx, ptAct->my +#ifdef _SFUMATO + , ptAct->sfumato +#endif + ); +} + + + +// ?????????? +ACTION *createPetAction( int graNo, int gx, int gy, int dir, int mode, int moveDir, int id ) +{ + ACTION *ptAct; + float mx, my; + PETEXTRA *pe; + + /* ?????????K? */ + ptAct = GetAction( PRIO_CHR, sizeof( PETEXTRA ) ); + if( ptAct == NULL ) + return NULL; + + // ??? + ptAct->func = petProc; + // ???????k? + ptAct->anim_chr_no = graNo; + // h?k? + ptAct->anim_no = ANIM_STAND; + // ?????????( ??? )( ??????? ) + ptAct->anim_ang = dir; + // ?IT + ptAct->dispPrio = DISP_PRIO_CHAR; + // 1???????? + ptAct->atr = ACT_ATR_INFO | ACT_ATR_HIT | ACT_ATR_HIDE2; + // ???t + ptAct->nextGx = gx; // ??????????hI? + ptAct->nextGy = gy; + ptAct->bufCount = 0; + ptAct->gx = gx; // ???????????? + ptAct->gy = gy; + ptAct->mx = (float)gx * GRID_SIZE; // ???? + ptAct->my = (float)gy * GRID_SIZE; + ptAct->vx = 0; // ?h? + ptAct->vy = 0; + + // ??t + camMapToGamen( ptAct->mx, ptAct->my, &mx, &my ); + ptAct->x = (int)(mx+.5); + ptAct->y = (int)(my+.5); + + pe = (PETEXTRA *)ptAct->pYobi; + pe->mode = mode; + pe->moveDir = moveDir; + limitCantClientDir( &pe->moveDir ); + pe->preDir = pe->moveDir; + pe->dirCnt = 0; + pe->preGx = gx; + pe->preGy = gy; + pe->walkCnt = 0; + pe->createTime = TimeGetTime(); + pe->ptAct = NULL; + pe->ptAct2 = NULL; + pe->angle = 0.0F; + pe->r = 0; + + pe->id = id; + + return ptAct; +} + + + +void þֹĶΪվ( void ) +{ + int i=0; + for(i;ianim_no == 5 || + charObj[i].ptAct->anim_no==2|| + charObj[i].ptAct->anim_no==0|| + charObj[i].ptAct->anim_no==1|| + charObj[i].ptAct->anim_no==12) + charObj[i].ptAct->anim_no = 3; + } + } + } +} + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/chat.cpp b/石器时代8.5客户端最新源代码/石器源码/system/chat.cpp new file mode 100644 index 0000000..86dbe36 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/chat.cpp @@ -0,0 +1,1567 @@ +/************************/ +/* chat.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/font.h" +#include "../other/caryIme.h" +#include "../systeminc/netproc.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/savedata.h" +#include "time.h" +#include "../systeminc/menu.h" +#include "../systeminc/t_music.h" +#include "../systeminc/t_music.h" +#include "../systeminc/tool.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/chat.h" +#include "../NewProto/protocol.h" +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif +#include "../systeminc/EncryptClient.h" +#include +extern INPUT_HISTORY InputHistory ; +extern STR_BUFFER SubBuffer; + +#ifdef __ONLINEGM +extern BOOL OnlineGmFlag; +#endif + +// ????????? +CHAT_BUFFER ChatBuffer[ MAX_CHAT_LINE ]; + +// ?V???????? +STR_BUFFER MyChatBuffer; + +// ???V???????????????? +STR_BUFFER *pNowStrBuffer = NULL; + +// ?????????? +int NowChatLine = 0; +// ???? +int NowMaxChatLine = DEF_CHAT_LINE; +#ifdef _SA_LIAOTIAN_ +int NowChatLine_Bak = 0; +#endif +// ????? +int NowMaxVoice = DEF_VOICE; +// ???????? +int CursorFlashCnt = 0; +// ?????????? +int ChatLineSmoothY = 0 ; + +#define CAHT_HISTORY_STR_FILE_NAME "data\\chathis.dat" // ?????????????? +// ???????????Bl +CHAT_HISTORY ChatHistory; + +#define MAX_SHIELD_SIZE 5000 +//typedef CEncryptClient<0x55, 0x168, 0xC9, 0x3C, 0x6B, 0x49, 0x81, 0x65> ENCRYPTCONF; +char SayShieldList[MAX_SHIELD_SIZE][24]; +char NameShieldList[MAX_SHIELD_SIZE][24]; + +// ??????? +void KeyboardTab( void ); + +// ?????? +FILE *chatLogFile = NULL; +char chatLogFileName[256]; +void openChatLogFile( void ); + +/* +#ifdef _TELLCHANNEL // (ɿ) ROG ADD Ƶ +char ReTellName[] = ""; +#endif +*/ + +void InitChat( void ) +{ + memset( ChatBuffer, 0, sizeof( CHAT_BUFFER ) * MAX_CHAT_LINE ); + memset( &MyChatBuffer, 0, sizeof( STR_BUFFER ) ); + MyChatBuffer.len = _FONTDATALEN_-10; +#ifndef _CHANNEL_MODIFY + MyChatBuffer.fontPrio = FONT_PRIO_BACK; +#else + MyChatBuffer.fontPrio = FONT_PRIO_CHATBUFFER; +#endif +#ifdef _MO_CHAT_EXPRESSION + MyChatBuffer.x = 8+20; +#else + MyChatBuffer.x = 8; +#endif + MyChatBuffer.y = 432 + DISPLACEMENT_Y; + getUserChatOption(); + openChatLogFile(); +#ifdef _CHANNEL_MODIFY + FILE *pf; + char buf[5]; + + if ((pf = fopen("data\\channel.dat","r")) == NULL) + { + pc.etcFlag |= PC_ETCFLAG_CHAT_TELL; + if ((pf = fopen("data\\channel.dat", "w+")) == NULL) + return; + else + { + buf[0] = (pc.etcFlag & PC_ETCFLAG_CHAT_TELL) ? 1:0; + buf[1] = (pc.etcFlag & PC_ETCFLAG_CHAT_SAVE) ? 1:0; +#ifdef _CHAR_PROFESSION + buf[2] = (pc.etcFlag & PC_ETCFLAG_CHAT_OCC) ? 1:0; +#endif +#ifdef _CHANNEL_WORLD + buf[3] = (pc.etcFlag & PC_ETCFLAG_CHAT_WORLD) ? 1:0; +#endif +#ifdef _CHANNEL_ALL_SERV + buf[4] = (pc.etcFlag & PC_ETCFLAG_ALL_SERV) ? 1:0; +#endif + fwrite(buf, 1, sizeof(buf), pf); + fclose(pf); + } + } + else + { + fread(&buf,1,sizeof(char),pf); + if (buf) + pc.etcFlag |= PC_ETCFLAG_CHAT_TELL; + fread(&buf,1,sizeof(char),pf); + if (buf) + pc.etcFlag |= PC_ETCFLAG_CHAT_SAVE; + fread(&buf,1,sizeof(char),pf); +#ifdef _CHAR_PROFESSION + if (buf) + pc.etcFlag |= PC_ETCFLAG_CHAT_OCC; +#endif +#ifdef _CHANNEL_WORLD + if (buf) + pc.etcFlag |= PC_ETCFLAG_CHAT_WORLD; +#endif +#ifdef _CHANNEL_ALL_SERV + if (buf) + pc.etcFlag |= PC_ETCFLAG_ALL_SERV; +#endif + fclose(pf); + } + + if (pc.familyleader <= 0) pc.etcFlag &= ~PC_ETCFLAG_CHAT_FM; + else pc.etcFlag |= PC_ETCFLAG_CHAT_FM; +#ifdef _CHAR_PROFESSION + if (pc.profession_class == 0) pc.etcFlag &= ~PC_ETCFLAG_CHAT_OCC; + else pc.etcFlag |= PC_ETCFLAG_CHAT_OCC; +#endif + if(!pc.etcFlag &PC_ETCFLAG_PARTY){ + pc.etcFlag |= PC_ETCFLAG_PARTY; + } + //޸ + pc.etcFlag |= PC_ETCFLAG_PARTY; + if (bNewServer) lssproto_FS_send(sockfd,pc.etcFlag); + else old_lssproto_FS_send(sockfd,pc.etcFlag); +#endif +} + +void openChatLogFile( void ) +{ + if( chatLogFile == NULL ){ +#ifdef _STONDEBUG_ + chatLogFile = fopen( chatLogFileName, "wt" ); +#else + static struct tm nowTime; + time_t longTime; + time( &longTime ); + localtime_s(&nowTime, &longTime ); + sprintf_s( chatLogFileName, ".\\chat\\CHAT_%02d%02d%02d.TXT", + (nowTime.tm_year % 100), nowTime.tm_mon+1, nowTime.tm_mday ); + chatLogFile = fopen( chatLogFileName, "a" ); + if( chatLogFile ){ + fprintf( chatLogFile, "----- Login: %02d/%02d/%02d %02d:%02d:%02d -----\n", + (nowTime.tm_year % 100), nowTime.tm_mon+1, nowTime.tm_mday, + nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec ); + } +#endif + } +} + +BOOL SaveChatHistoryStr( int no ) +{ + FILE *fp; + + if( ( fp = fopen( CAHT_HISTORY_STR_FILE_NAME, "r+b" ) ) == NULL ) + return FALSE; + // ????????????????????? + fseek( fp, sizeof( ChatHistory.str[ 0 ] ) * no, SEEK_SET ); + // ????????? + if( fwrite( &ChatHistory.str[ no ], sizeof( ChatHistory.str[ 0 ] ), 1, fp ) < 1 ){ + + fclose( fp );// ???????? + return FALSE; + } + + // ????k???????????????? + fseek( fp, sizeof( ChatHistory.str[ 0 ] ) * MAX_CHAT_HISTORY, SEEK_SET ); + // ????k??V + if( fwrite( &no, sizeof( int ), 1, fp ) < 1 ){ + + fclose( fp );// ???????? + return FALSE; + } + + // ???????? + fclose( fp ); + + return TRUE; +} + +// ???????????? ****************************************************************/ +BOOL LoadChatHistoryStr( void ) +{ + FILE *fp; + + // ?????????k????? + ChatHistory.nowNo = -1; + + // ??????????? + if( ( fp = fopen( CAHT_HISTORY_STR_FILE_NAME, "rb" ) ) == NULL ){ + // ?????ɤ?? + if( ( fp = fopen( CAHT_HISTORY_STR_FILE_NAME, "wb" ) ) != NULL ){ + // ??????? + fwrite( &ChatHistory, sizeof( CHAT_HISTORY ) - sizeof( int ), 1, fp ); + fclose( fp ); // ???????? + } + + // ????????k????? + ChatHistory.nowNo = MAX_CHAT_HISTORY - 1; + + return FALSE; + } + + // ?????? + if( fread( &ChatHistory, sizeof( CHAT_HISTORY ) - sizeof( int ), 1, fp ) < 1 ){ + + fclose( fp ); // ???????? + return FALSE; + } + // ???????? + fclose( fp ); + + return TRUE; +} + +/* ??????V?????? ****************************************************/ +// +void* EncryptFileName( LPCTSTR pszResFile,unsigned int &nSize ) +{ + //ENCRYPTCONF myConfFileCncryp; + //if( NULL != pszResFile ) ; // [Chancy2008-4-16 21:51] + + char szFile[MAX_PATH] = ""; + char szResFileTemp[MAX_PATH] = "" ; + lstrcpyn( szResFileTemp , pszResFile , sizeof( szResFileTemp ) ) ; + char* pszReadName; + _strlwr_s(pszReadName=_strdup(szResFileTemp),256); // [Chancy2008-4-16 21:52] + + if ( !pszReadName ) + return NULL; + + sprintf_s(szFile,"data/%s.bin",pszReadName); + + FILE* fp = fopen(szFile, "rb"); + if ( !fp ) + { + return false; + } + + //(myConfFileCncryp).Init(); + + fseek(fp,0,SEEK_END);//move file pointer to file end + unsigned int unFileSize = ftell( fp ); + nSize = ftell( fp ); + fseek( fp,0,SEEK_SET );// RESTORE + + void* pBuffer = new char[ unFileSize + 1 ]; // apply 1 char memory for '\0' because char pointer + + if( !pBuffer ) + return false; + memset( pBuffer,0,sizeof( char ) * ( unFileSize + 1 ) ); + fread( pBuffer,unFileSize,1,fp ); + //(myConfFileCncryp).Encrypt((unsigned char *)pBuffer,unFileSize); + fclose(fp); + + return pBuffer; +} + +BOOL MoveFilePointInt( const char * pBuffer ,unsigned int nSize , unsigned int &nRead, BOOL &bRead ,int nResult) // ƶļָ [11/27/2007] +{ + unsigned int nReadCount = nRead; // ¼ϴָλ [11/28/2007] + const char* pFind = strstr( pBuffer + nRead,"\n");//find \n + if( pFind ) + { + nRead = ( pFind - pBuffer + 1 ); // õǰָλ [11/28/2007] //õļʼλõƫλ// ȵעͲ׼ȷ [ĸ 2007-12-14] + } + if ((2 == nRead - nReadCount && nResult !=0)|| nResult == 0) // / ж϶ʵݣ2ֽڱʾ\r\n [11/28/2007] + { + bRead = FALSE; + } + else + { + bRead = TRUE; + } + if( nRead > nSize ) + return false; + return true; +} + +BOOL LoadReadSayShield( void ) +{ + char szName[]="ShieldWorld"; + unsigned int nSize; + char* pBuffer = (char*)EncryptFileName((char*)szName,nSize); + if( !pBuffer ) + return FALSE; + + unsigned int nRead = 0; //Ѿ˵ + BOOL bRead = FALSE; + int i = 0; + static char szWord[20] = ""; + while(nRead < nSize) + { + int nResult = sscanf_s(pBuffer + nRead , "%s", &szWord); + if ( !MoveFilePointInt(pBuffer,nSize,nRead,bRead,nResult)) + break; + if ( bRead == FALSE ) + continue; + if ( 1 == nResult ) + { + if(i >= MAX_SHIELD_SIZE) + { + break; + } + strcpy(SayShieldList[i], szWord ); + i++; + } + else + break; + } + delete[] pBuffer; + pBuffer = NULL; + return TRUE; +} + +BOOL LoadReadNameShield( void ) +{ + char szName[]="ShieldName"; + unsigned int nSize; + char* pBuffer = (char*)EncryptFileName((char*)szName,nSize); + if( !pBuffer ) + return FALSE; + + unsigned int nRead = 0; //Ѿ˵ + BOOL bRead = FALSE; + int i = 0; + static char szName_[20] = ""; + + while(nRead < nSize) + { + + int nResult = sscanf_s(pBuffer + nRead , "%s", &szName_); + if ( !MoveFilePointInt(pBuffer,nSize,nRead,bRead,nResult)) + break; + if ( bRead == FALSE ) + continue; + if ( 1 == nResult ) + { + if(i >= MAX_SHIELD_SIZE) + { + break; + } + strcpy(NameShieldList[i], szName_ ); + i++; + } + else + break; + } + delete[] pBuffer; + pBuffer = NULL; + return TRUE; + +} +bool CheckSay( const char* strSay, const char szReplace ) +{ + if ( NULL==strSay ) return true; + if ( strlen(strSay)==0 ) return true; + + for ( size_t i=0;i86) + strLen=86; + for(i=0;i86) + strLen=86; + for(i=0;i86) + strLen=86; + for(i=0;i86) + strLen=86; + for(i=0;i70){ + if(IsDBCSLeadByte(str[68])) + strLen = 69; + else + strLen = 70; + } + for(i=0;ibuffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer1(secretName); + TalkMode = 1; + } +#else +#ifdef _FRIENDCHANNEL + StrToNowStrBuffer1( secretName ); +#endif +#endif + + // V?????????????????? + if( pNowStrBuffer == &MyChatBuffer || pNowStrBuffer == &MailStr ){ + if( joy_trg[ 1 ] & JOY_F1 ) StrToNowStrBuffer1( chatRegistryStr[ 0 ].buffer ); + if( joy_trg[ 1 ] & JOY_F2 ) StrToNowStrBuffer1( chatRegistryStr[ 1 ].buffer ); + if( joy_trg[ 1 ] & JOY_F3 ) StrToNowStrBuffer1( chatRegistryStr[ 2 ].buffer ); + if( joy_trg[ 1 ] & JOY_F4 ) StrToNowStrBuffer1( chatRegistryStr[ 3 ].buffer ); + + if( joy_trg[ 1 ] & JOY_F5 ) StrToNowStrBuffer1( chatRegistryStr[ 4 ].buffer ); + if( joy_trg[ 1 ] & JOY_F6 ) StrToNowStrBuffer1( chatRegistryStr[ 5 ].buffer ); + if( joy_trg[ 1 ] & JOY_F7 ) StrToNowStrBuffer1( chatRegistryStr[ 6 ].buffer ); + if( joy_trg[ 1 ] & JOY_F8 ) StrToNowStrBuffer1( chatRegistryStr[ 7 ].buffer ); + } + if( pNowStrBuffer == &MyChatBuffer && GetImeString() == NULL ){ + // ??????? + if( joy_auto[ 0 ] & JOY_UP ){ + static UINT oldtime = 0; + if(oldtime < TimeGetTime()){ + oldtime = TimeGetTime() + 100; + int bak = ChatHistory.nowNo; + if( ChatHistory.nowNo == -1 ) ChatHistory.nowNo = ChatHistory.newNo; + else ChatHistory.nowNo--; + if( ChatHistory.nowNo < 0 ) ChatHistory.nowNo = MAX_CHAT_HISTORY - 1; + if( ChatHistory.str[ ChatHistory.nowNo ][ 0 ] != 0 && ( ChatHistory.nowNo != ChatHistory.newNo || bak == -1 ) ){ + pNowStrBuffer->cnt = 0; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + StrToNowStrBuffer1( ChatHistory.str[ ChatHistory.nowNo ] ); + }else{ + ChatHistory.nowNo = bak; + } +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + } + }else + // ???????? + if( joy_auto[ 0 ] & JOY_DOWN ){ + static UINT oldtime = 0; + if(oldtime < TimeGetTime()){ + + + oldtime = TimeGetTime() + 100; + + // ?????????V????? + if( ChatHistory.nowNo != -1 ){ + // ?????????I??? + if( ChatHistory.nowNo == ChatHistory.newNo ){ + ChatHistory.nowNo = -1; + // V?????????? + pNowStrBuffer->cnt = 0; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + }else{ + ChatHistory.nowNo++; + // ???????? + if( ChatHistory.nowNo >= MAX_CHAT_HISTORY ) ChatHistory.nowNo = 0; + // V?????????? + pNowStrBuffer->cnt = 0; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + // ????????V???????? + StrToNowStrBuffer1( ChatHistory.str[ ChatHistory.nowNo ] ); + } +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + } + } + } + } +} + +// ??????????? **************************************************/ +void FlashKeyboardCursor( void ) +{ + if(pNowStrBuffer==NULL) return; + if(CursorFlashCnt >= 20){ + StockFontBuffer(pNowStrBuffer->imeX, pNowStrBuffer->imeY , pNowStrBuffer->fontPrio, pNowStrBuffer->color, "_" , 0 ); + } + CursorFlashCnt++; + if( CursorFlashCnt >= 40 ) CursorFlashCnt = 0; +} + +// ?????? ***************************************************************/ +void KeyboardBackSpace( void ) +{ + int byte,cursor; + if(pNowStrBuffer==NULL) return; +#ifdef __ONLINEGM + if (pNowStrBuffer==&SubBuffer ){ + if (pNowStrBuffer->cursor==0 && InputHistory.newNo>0 && (InputHistory.newNo-1)>InputHistory.lockNo){ + InputHistory.str[InputHistory.newNo][0] = '\0'; + StrToNowStrBuffer1( InputHistory.str[ InputHistory.newNo-1 ] ); + byte = lstrlen(InputHistory.str[ InputHistory.newNo-1 ]); + pNowStrBuffer->cnt = byte; + pNowStrBuffer->cursor = byte; + InputHistory.newNo--; + InputHistory.addNo--; + if (InputHistory.newNo < 3+1 ){ + InputHistory.nowNo = 0; + pNowStrBuffer->y -= pNowStrBuffer->lineDist; + if(pNowStrBuffer->y<325-5) + pNowStrBuffer->y = 325-5 ; + } + else + InputHistory.nowNo = InputHistory.newNo-3-1; + } + } +#endif + if((cursor=pNowStrBuffer->cursor) > 0){ + char *lpstr=pNowStrBuffer->buffer; + char *lpstr1=lpstr+cursor; + byte=lpstr1-GetCharPrev(lpstr,lpstr1); + for(;cursor<=pNowStrBuffer->cnt;cursor++){ + lpstr[cursor-byte]=lpstr[cursor]; + } + pNowStrBuffer->cnt-=byte; + pNowStrBuffer->cursor-=byte; + CursorFlashCnt=20; + } +} + +// ??????? ***************************************************************/ +void KeyboardTab( void ) +{ + int i,flag = 0; + + // V???????? + if( pNowStrBuffer == NULL ) return; + + // ?K????? ******************************* + for( i = 0 ; i < MAX_CHAT_REGISTY_STR ; i++ ){ + if( pNowStrBuffer == &chatRegistryStr[ i ] ){ + flag = TRUE; + break; + } + } + // ?K??? ******************************* + if( flag == TRUE ){ + // ??????????? + if( joy_con[ 1 ] & JOY_RSHIFT || joy_con[ 1 ] & JOY_LSHIFT ){ + i--; + // ???????? + if( i < 0 ) i = MAX_CHAT_REGISTY_STR - 1; + }else{ + i++; + // ???????? + if( i >= MAX_CHAT_REGISTY_STR ) i = 0; + } + // V???????h + GetKeyInputFocus( &chatRegistryStr[ i ] ); + } + + // ??????????????? + CursorFlashCnt = 20; +#ifdef _CHANNEL_MODIFY + static DWORD dwChannelChangeTime = TimeGetTime(); + if(dwChannelChangeTime + 250 < TimeGetTime()){ + dwChannelChangeTime = TimeGetTime(); + + TalkMode = (TalkMode + 1) % PC_ETCFLAG_CHAT_WORLD_NUM; + + switch(TalkMode){ + case PC_ETCFLAG_CHAT_MODE_ID: + strcpy(secretName,""); + // ڶƵлһƵ + if(pc.etcFlag & PC_ETCFLAG_CHAT_MODE){ + pc.etcFlag &= ~PC_ETCFLAG_CHAT_MODE; + if(bNewServer) lssproto_FS_send(sockfd,pc.etcFlag); + else old_lssproto_FS_send(sockfd,pc.etcFlag); + } + break; + case PC_ETCFLAG_CHAT_TELL_ID: + // Ƶر,һƵ + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_TELL)) TalkMode++; + else break; + case PC_ETCFLAG_CHAT_PARTY_ID: + // ޶һƵ + if(partyModeFlag == 0) TalkMode++; + else{ + pc.etcFlag |= PC_ETCFLAG_CHAT_MODE; + if(bNewServer) lssproto_FS_send(sockfd,pc.etcFlag); + else old_lssproto_FS_send(sockfd,pc.etcFlag); + break; + } + case PC_ETCFLAG_CHAT_FM_ID: + // Ƶп,صƵ + if(pc.etcFlag & PC_ETCFLAG_CHAT_MODE){ + pc.etcFlag &= ~PC_ETCFLAG_CHAT_MODE; + if(bNewServer) lssproto_FS_send(sockfd,pc.etcFlag); + else old_lssproto_FS_send(sockfd,pc.etcFlag); + } + // Ƶر,һƵ + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_FM)) TalkMode++; + else break; +#ifdef _CHAR_PROFESSION + case PC_ETCFLAG_CHAT_OCC_ID: + // ְҵƵر,һƵ + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_OCC)) + TalkMode++; + break; +#endif +#ifdef _CHATROOMPROTOCOL + case PC_ETCFLAG_CHAT_CHAT_ID: + // Ƶ + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_CHAT)){ + secretFlag = FALSE; + selChar = -1; + strcpy(secretName,""); + } + break; +#endif +#ifdef _CHANNEL_WORLD + case PC_ETCFLAG_CHAT_WORLD_ID: + // Ƶ + if(!(pc.etcFlag & PC_ETCFLAG_CHAT_WORLD)){ + if((pc.etcFlag & PC_ETCFLAG_ALL_SERV)){ + TalkMode++; + }else{ + TalkMode = 0; + } + } + break; +#endif +#ifdef _CHANNEL_ALL_SERV + case PC_ETCFLAG_ALL_SERV_ID: + // Ƶ + if(!(pc.etcFlag & PC_ETCFLAG_ALL_SERV)){ + TalkMode = 0; + } + + break; +#endif + default: + TalkMode++; + break; + } +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + } +#else + #ifdef _FRIENDCHANNEL + TalkMode = (TalkMode + 1) % 3; + if(TalkMode == 2 ){ + secretFlag = FALSE; + selChar = -1; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer(""); + if(strcmp(pc.chatRoomNum, "") == 0) TalkMode = 0; + }else strcpy(secretName,""); + #else + #ifdef _TELLCHANNEL + TalkMode = (TalkMode + 1) % 2; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer(""); + #endif + #endif +#endif +} + +void KeyboardLeft() +{ + int byte,cursor; + if(pNowStrBuffer==NULL) return; + if((cursor=pNowStrBuffer->cursor) > 0){ + char *lpstr=pNowStrBuffer->buffer; + char *lpstr1=lpstr+cursor; + byte=lpstr1-GetCharPrev(lpstr,lpstr1); + pNowStrBuffer->cursor-=byte; + CursorFlashCnt=20; + } +} + +void KeyboardRight() +{ + int byte=1,cursor; + if(pNowStrBuffer==NULL) return; + if((cursor=pNowStrBuffer->cursor) < (pNowStrBuffer->cnt)){ + char *lpstr=pNowStrBuffer->buffer; + lpstr+=cursor; + if(*lpstr && IsDBCSLeadByte(*lpstr)) + byte=2; + pNowStrBuffer->cursor+=byte; + } + CursorFlashCnt=20; +} + +#include +/* ???????? ************************************************************/ +void KeyboardReturn( void ) +{ + //ttom + static bool first_keydown=true; + if(!first_keydown) { + //cary ʮ + static DWORD PreTime=TimeGetTime(),CurTime; + if(((CurTime=TimeGetTime())-PreTime)<500) + return; + PreTime=CurTime; + } +#ifdef __NEW_CLIENT + extern HANDLE hProcessSnap, hParentProcess; + extern DWORD dwPID; + extern PROCESSENTRY32 pe32; + if( dwPID){ + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if( pe32.th32ProcessID == dwPID){ + if( !strstr( pe32.szExeFile, "explorer.exe") && (hParentProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwPID))){ + #ifndef NO_TERMINATER + TerminateProcess( hParentProcess, 0); + #endif + CloseHandle( hParentProcess); + } + break; + } + }while( Process32Next( hProcessSnap, &pe32)); + } + dwPID = 0; + } +#endif + first_keydown=false; + //end + //ttom + char bakNo; + // ????????????????? + if( GetImeString() != NULL ) + return; + // ????V??? ******************************* + if( pNowStrBuffer == &MyChatBuffer ){ + if( pNowStrBuffer->cnt == 0 ) + return; + pNowStrBuffer->buffer[ pNowStrBuffer->cnt ] = '\0'; +#ifdef _STONDEBUG_ + // ???????? + if( strstr( pNowStrBuffer->buffer, "[battlein]" ) ) + EncountFlag = TRUE; + if( strstr( pNowStrBuffer->buffer, "[battleout]" ) ){ + ChangeProc( PROC_GAME, 1 ); + DeathAllAction(); // ???????? + } + #ifdef _THEATER + if (strstr(pNowStrBuffer->buffer, "scenery")) + { + char szData[128]; + + getStringToken(pNowStrBuffer->buffer, ' ', 2, sizeof(szData) - 1, szData); + sprintf_s(szData, "%d|%d", E_DATA_TYPE_SCENERY, atoi(szData)); + lssproto_TheaterData_recv(0, szData); + } + if (strstr(pNowStrBuffer->buffer, "movescreen")) + { + int iXY = 0; + char szData[128]; + + if (pc.bMoveScreenMode) + lssproto_MoveScreen_recv(0, FALSE, iXY); + else + { + getStringToken(pNowStrBuffer->buffer, ' ', 2, sizeof(szData) - 1, szData); + iXY = atoi(szData); + getStringToken(pNowStrBuffer->buffer, ' ', 3, sizeof(szData) - 1, szData); + iXY = (iXY << 16) | atoi(szData); + lssproto_MoveScreen_recv(0, TRUE, iXY); + } + } + if (strstr(pNowStrBuffer->buffer, "playnpc")) + { + char szData[128], szData1[128]; + + getStringToken(pNowStrBuffer->buffer, ' ', 2, sizeof(szData1) - 1, szData1); + sprintf_s(szData, "12|%s", szData1); + lssproto_TheaterData_recv(0, szData); + } + #endif + if( strstr( pNowStrBuffer->buffer, "[cary encountoff]" ) ){ + EncountOffFlag = TRUE; + pNowStrBuffer->cnt = 0; + pNowStrBuffer->cursor=0; + *( pNowStrBuffer->buffer )= '\0'; + return; + } + if( strstr( pNowStrBuffer->buffer, "[cary encounton]" ) ){ + EncountOffFlag = FALSE; + pNowStrBuffer->cnt = 0; + pNowStrBuffer->cursor=0; + *( pNowStrBuffer->buffer )= '\0'; + return; + } +#endif + // ?????? + bakNo = ChatHistory.newNo; + // ??????k?? + ChatHistory.newNo++; + // ???????? + if( ChatHistory.newNo >= MAX_CHAT_HISTORY ) + ChatHistory.newNo = 0; +//cary + BOOL bSave=TRUE; + /* + BOOL bH=FALSE; + for(int i=0;icnt;i++){ + if(!bH){ + if('['==pNowStrBuffer->buffer[i]) + bH=TRUE; + }else{ + } + } + */ + /* + for(int i=0;icnt;i++){ + if('['==pNowStrBuffer->buffer[i]){ + if(strstr( pNowStrBuffer->buffer+i, "debug on]" ) != 0){ + bSave=FALSE; + break; + } + } + } + */ + if(('['==pNowStrBuffer->buffer[0])&&(']'==pNowStrBuffer->buffer[pNowStrBuffer->cnt-1])) + bSave=FALSE; + if(!bSave){ + ChatHistory.newNo = bakNo; + }else{ +//end + // q???????? + if( strcmp( pNowStrBuffer->buffer, ChatHistory.str[ bakNo ] ) != 0 ){ + // ????????? + strcpy( ChatHistory.str[ ChatHistory.newNo ], pNowStrBuffer->buffer ); + // ?????????V + SaveChatHistoryStr( ChatHistory.newNo ); + }else{ + // ?????????? + ChatHistory.newNo = bakNo; + } + } + ChatHistory.nowNo = -1; + if( offlineFlag == FALSE ) + chatStrSendForServer( pNowStrBuffer->buffer, MyChatBuffer.color ); + pNowStrBuffer->cnt = 0; + pNowStrBuffer->cursor=0; + *( pNowStrBuffer->buffer )= '\0'; + }else + + // ???? ********************************** + if( pNowStrBuffer == &shougouChange ){ + // ?????? + DeathAction( pActMenuWnd3 ); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus( &MyChatBuffer ); + // ???????? + play_se( 203, 320, 240 ); + // q?? + if( bNewServer) + lssproto_FT_send( sockfd, shougouChange.buffer ) ; /* ../doc/lssproto.html line 1792 */ + else + old_lssproto_FT_send( sockfd, shougouChange.buffer ) ; /* ../doc/lssproto.html line 1792 */ + }else + + // q??? ********************************** + if( pNowStrBuffer == &petNameChange ){ + // ?????? + DeathAction( pActMenuWnd3 ); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus( &MyChatBuffer ); + // ???????? + play_se( 203, 320, 240 ); + // q?? + if( bNewServer) + lssproto_KN_send( sockfd, petStatusNo, petNameChange.buffer ) ; /* ../doc/lssproto.html line 1792 */ + else + old_lssproto_KN_send( sockfd, petStatusNo, petNameChange.buffer ) ; /* ../doc/lssproto.html line 1792 */ + }else + + // ????? ********************************** + if( pNowStrBuffer == &MailStr +#ifdef __EDEN_AUCTION + || pNowStrBuffer == &AuctionStr){ +#else + ){ +#endif + + char *buffer=pNowStrBuffer->buffer; + //пɷʱ + if(pNowStrBuffer->cnt < pNowStrBuffer->len-pNowStrBuffer->lineLen){ + //һȫΪspace + if((pNowStrBuffer->cursor)%pNowStrBuffer->lineLen == 0) + StockStrBufferChar(' '); + while((pNowStrBuffer->cursor)%pNowStrBuffer->lineLen) + StockStrBufferChar(' '); + } + }else + + // ????? ********************************** + if( pNowStrBuffer == &MailStr ){ + // ???????????? + if( MailStr.cnt < MailStr.len - MailStr.lineLen ){ + // ?Z?? + if( MailStr.cnt % MailStr.lineLen == 0 ) + StockStrBufferChar( ' ' ); + // ??Z???????V?? + while( MailStr.cnt % MailStr.lineLen ) + StockStrBufferChar( ' ' ); + } + } + + // ????V??? **************************** +#ifdef _FRIENDCHANNEL // + char temp[STR_BUFFER_SIZE]; + if( pNowStrBuffer == &chatRoomName ){ + GetKeyInputFocus( &MyChatBuffer ); + play_se( 203, 320, 240 ); + sprintf_s(temp,"C|%s",chatRoomName.buffer); + lssproto_CHATROOM_send ( sockfd , temp ) ; + DeathAction(pSetRoomWnd); + pSetRoomWnd = NULL; + setRoomFlag = FALSE; + } +#endif + +#ifdef _TELLCHANNEL + if(TalkMode == 1){ //ʾ + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer1(secretName); + } +#endif + + extern STR_BUFFER *idPasswordStr; + extern short idKeyReturn; + if( pNowStrBuffer == idPasswordStr ) + { + idKeyReturn = 1; + } + + // ??????????????? + CursorFlashCnt = 20; + +} +extern STR_BUFFER idKey; +extern STR_BUFFER passwd; +extern STR_BUFFER selCharName; +/* һԪĿǰString buffer +parameter: c: Ԫ */ +void StockStrBufferChar(char c) +{ + if(BYTE(c)>0x1f){ + int cnt,cursor; + if(pNowStrBuffer==NULL || (cnt=pNowStrBuffer->cnt) >= pNowStrBuffer->len) + return; + char *buffer=pNowStrBuffer->buffer; + if(pNowStrBuffer==&idKey || pNowStrBuffer==&passwd){ + /*if(!(('0'<=c && c<='9') || ('A'<=c && c<='Z') || ('a'<=c && c<='z'))) + return;*/ + }else if(pNowStrBuffer==&selCharName){ + if(' '==c || ''==c|| ','==c || '|'==c || '\\'==c) + return; + }else if(pNowStrBuffer==&SubBuffer){ + if('&'==c || '|'==c ) + return; + } + for(cursor=pNowStrBuffer->cursor++;cursor<=cnt;cnt--) + buffer[cnt+1]=buffer[cnt]; + buffer[cursor++]=c; + pNowStrBuffer->cnt++; + CursorFlashCnt=20; +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + } +} + +/* ˫λԪԪĿǰString buffer +parameter: lpc: ˫λԪԪ */ +void StockStrBufferDBChar(char *lpc) +{ + int cnt,cursor; + if(pNowStrBuffer==NULL || (cnt=pNowStrBuffer->cnt) >= pNowStrBuffer->len-1) + return; + char *buffer=pNowStrBuffer->buffer; + if(pNowStrBuffer==&idKey || pNowStrBuffer==&passwd) + return; + else{ + for(cursor=pNowStrBuffer->cursor;cursor<=cnt;cnt--) + buffer[cnt+2]=buffer[cnt]; + buffer[cursor++]=*lpc++; + buffer[cursor++]=*lpc; + pNowStrBuffer->cnt+=2; + pNowStrBuffer->cursor+=2; + CursorFlashCnt=20; + } +} + + + + + +#ifdef _FONT_SIZE +void StockChatBufferLine( char *str, unsigned char color ) +{ + StockChatBufferLineExt( str, color, 0 ); +} +void StockChatBufferLineExt( char *str_, unsigned char color, int fontsize ) +#else +void StockChatBufferLine( char *str_, unsigned char color ) +#endif +{ + char *str=str_; + extern int ; + extern int 忪; + if(忪){ + char [1024]={0}; + LCMapString (0x804,0x4000000,str_, strlen(str_),,1024); + str = ; + }else{ + str = str_; + } +#ifdef _SA_LIAOTIAN_ + if(NowChatLine_Bak != NowChatLine) NowChatLine = NowChatLine_Bak; +#endif +#ifdef _MO_CHAT_EXPRESSION + char strtemp[1024]; + delFontBuffer(&ChatBuffer[ NowChatLine ]); + int splitPoint = 0; + char splitStr[ STR_BUFFER_SIZE + 1 ]; + unsigned int MyChatBufferLen = _FONTDATALEN_; + if( strlen( str ) > MyChatBufferLen ){ + strncpy_s( splitStr, str, MyChatBufferLen ); + *( splitStr + MyChatBufferLen ) = NULL; + if( GetStrLastByte( splitStr ) == 3 ){ + splitPoint = MyChatBufferLen - 1; + *( splitStr + MyChatBufferLen - 1 ) = NULL; + }else + splitPoint = MyChatBufferLen; + strncpy_s( strtemp, str, splitPoint ); + strtemp[splitPoint]=0; + NewStockFontBuffer(&ChatBuffer[ NowChatLine ],0,color,strtemp,fontsize); + }else NewStockFontBuffer(&ChatBuffer[ NowChatLine ],0,color,str,fontsize); +#ifdef _SA_LIAOTIAN_ + NowChatLine_Bak++; +#endif + NowChatLine++; + if( NowChatLine >= MAX_CHAT_LINE ){ + NowChatLine = 0; +#ifdef _SA_LIAOTIAN_ + NowChatLine_Bak=0; +#endif + } + if( chatLogFile ){ + fprintf( chatLogFile, "%s\n", str ); + } + ChatLineSmoothY = 20; + if( splitPoint != 0 ){ +#ifdef _FONT_SIZE + StockChatBufferLineExt( str + splitPoint, color, fontsize ); +#else + StockChatBufferLine( str + splitPoint, color ); +#endif + } +#else + int splitPoint = 0; + char splitStr[ STR_BUFFER_SIZE + 1 ]; +#ifdef _NEWFONT_ + unsigned int MyChatBufferLen = 87; +#else + unsigned int MyChatBufferLen = 112; +#endif +#ifdef _FONT_SIZE + if( fontsize > 0 ) { + MyChatBufferLen = (int)(MyChatBufferLen*((float)FONT_SIZE/(float)fontsize)); + } +#endif + + if( strlen( str ) > MyChatBufferLen ){ + strncpy_s( splitStr, str, MyChatBufferLen ); + *( splitStr + MyChatBufferLen ) = NULL; + if( GetStrLastByte( splitStr ) == 3 ){ + splitPoint = MyChatBufferLen - 1; + *( splitStr + MyChatBufferLen - 1 ) = NULL; + }else + splitPoint = MyChatBufferLen; + strncpy_s( ChatBuffer[ NowChatLine ].buffer, str, splitPoint ); + + *( ChatBuffer[ NowChatLine ].buffer + splitPoint ) = NULL; +#ifdef _TALK_WINDOW + TalkWindow.AddString(ChatBuffer[NowChatLine].buffer,color); +#endif + }else{ + strcpy( ChatBuffer[ NowChatLine ].buffer, str ); +#ifdef _TALK_WINDOW + TalkWindow.AddString(str,color); +#endif + } + if( chatLogFile ){ + fprintf( chatLogFile, "%s\n", ChatBuffer[ NowChatLine ].buffer ); + } + ChatBuffer[ NowChatLine ].color = color; +#ifdef _FONT_SIZE + ChatBuffer[ NowChatLine ].fontsize = fontsize; +#endif + NowChatLine++; + if( NowChatLine >= MAX_CHAT_LINE ) NowChatLine = 0; + if( splitPoint != 0 ){ +#ifdef _FONT_SIZE + StockChatBufferLineExt( str + splitPoint, color, fontsize ); +#else + StockChatBufferLine( str + splitPoint, color ); +#endif + } + + ChatLineSmoothY = 20; + //ChatLineSmoothY = 20 - ChatBuffer[ NowChatLine-1 ].fontsize; + +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif +#endif +} + +void ClearChatBuffer( void ) +{ + int i; + for( i = 0 ; i < MAX_CHAT_LINE ; i++ ){ + ChatBuffer[ i ].buffer[ 0 ] = '\0'; + } + NowChatLine = 0; +#ifdef _SA_LIAOTIAN_ + NowChatLine_Bak=0; +#endif +} + + + +void ChatBufferToFontBuffer( void ) +{ +#ifdef _TALK_WINDOW + if(g_bTalkWindow) return; +#endif + int i, j, k = 0; + int x = 8, y = 400; // ? + + + + j = NowChatLine - 1; + // ???????? + if( j < 0 ) + j = MAX_CHAT_LINE - 1; + + // ??????????? + if( ChatLineSmoothY > 0 ) + k = NowMaxChatLine + 1; + else + k = NowMaxChatLine; + + // ???????? + if( k > MAX_CHAT_LINE ) + k = MAX_CHAT_LINE; + + // ?????????? + for( i = 0 ; i < k; i++ ){ + // ????????? + if( *ChatBuffer[ j ].buffer != NULL + ){ +#ifdef _FONT_SIZE +#ifdef _MO_CHAT_EXPRESSION + CHAT_BUFFER * temp = &ChatBuffer[j]; + while(temp){ + if(temp->x>760) break; + if(temp->BmpNo){ + StockDispBuffer(temp->x+x+14, y + ChatLineSmoothY + DISPLACEMENT_Y+7, DISP_PRIO_IME1,temp->BmpNo, 0); + }else{ + StockFontBufferExt(temp->x+x, y + ChatLineSmoothY + DISPLACEMENT_Y, FONT_PRIO_BACK, temp->color, ( char *)temp->buffer, 0,temp->fontsize ); + } + temp = temp->NextChatBuffer; + } +#else + StockFontBufferExt( x, y + ChatLineSmoothY + DISPLACEMENT_Y - (int)((ChatBuffer[j].fontsize/2)*1.4), FONT_PRIO_BACK, ChatBuffer[ j ].color, ( char *)ChatBuffer[ j ].buffer, 0, ChatBuffer[ j ].fontsize ); +#endif + //StockFontBufferExt( temp->x+x, y + ChatLineSmoothY + DISPLACEMENT_Y, FONT_PRIO_BACK, temp->color, ( char *)temp->buffer, 0, 0); +#else +#ifdef _MO_CHAT_EXPRESSION + CHAT_BUFFER * temp = &ChatBuffer[j]; + while(temp){ + if(temp->x>760) break; + if(temp->BmpNo){ + StockDispBuffer(temp->x+x+14, y + ChatLineSmoothY + DISPLACEMENT_Y+7, DISP_PRIO_IME1,temp->BmpNo, 0); + }else{ + StockFontBuffer(temp->x+x, y + ChatLineSmoothY + DISPLACEMENT_Y, FONT_PRIO_BACK, temp->color, ( char *)temp->buffer, 0 ); + } + temp = temp->NextChatBuffer; + } +#else + StockFontBuffer( x, y + ChatLineSmoothY + DISPLACEMENT_Y, FONT_PRIO_BACK, ChatBuffer[ j ].color, ( char *)ChatBuffer[ j ].buffer, 0 ); +#endif +#endif + } + y -= _CHAT_SPACING; // ??h +#ifdef _FONT_SIZE + y -= (int)((ChatBuffer[j].fontsize/2)*1.4); +#endif + // ?????? + j--; + // ???????? + if( j < 0 ) + j = MAX_CHAT_LINE - 1; + } + // ??????????? + if( ChatLineSmoothY > 0 ) + ChatLineSmoothY--; + +#ifdef LABEL_STR_ + extern char g_szChannelTitle[][13]; + StockFontBuffer( 2 ,430 + DISPLACEMENT_Y, FONT_PRIO_BACK, MyChatBuffer.color ,g_szChannelTitle[TalkMode] , 0 ); +#endif +#ifdef _MO_CHAT_EXPRESSION + extern void ShowBottomLineString(int iColor,LPSTR lpstr); + extern int focusGraId( int *id, int cnt ); + extern int pushGraId( int *id, int cnt ); + extern int selGraId( int *id, int cnt ); + int 鰴ťID = -1; + static int ͼƬ = 0; + static int 鴰״̬=FALSE; + static int 鵱ǰҳ=0; + static int ҳ = (EXPRESSION_NOID_NUM)%48?(EXPRESSION_NOID_NUM)/48+1:(EXPRESSION_NOID_NUM)/48; + int chatBtnGraNo[] = + { + CG_FIELD_CHAT_BTN_OFF, + CG_FIELD_CHAT_BTN_ON + }; + StockDispBuffer(40, 559, DISP_PRIO_IME3, chatBtnGraNo[ͼƬ], 1); + + if( MakeHitBox(40-10, 559-10,40+10,559+10, DISP_PRIO_IME4 ) == TRUE ) + { + ShowBottomLineString(FONT_PAL_WHITE, "顣"); + if(mouse.onceState & MOUSE_LEFT_CRICK){ + 鵱ǰҳ=1; + ͼƬ=1; + if(鴰״̬) 鴰״̬=FALSE; + else 鴰״̬=TRUE; + play_se(203, 320, 240); + }else ͼƬ=0; + } + if(鴰״̬){ + if( joy_trg[ 0 ] & JOY_ESC ) { + MenuToggleFlag|=JOY_ESC; + play_se(203, 320, 240); + 鴰״̬=FALSE; + } + int ťID[2]; + StockDispBuffer(120, 447, DISP_PRIO_IME3, 55103, 1); + ťID[0]=StockDispBuffer(89, 535, DISP_PRIO_IME4, 55104, 2); + ťID[1]=StockDispBuffer(152, 535, DISP_PRIO_IME4, 55105, 2); + int ID= selGraId(ťID,2); + if(ID==0){// + if(鵱ǰҳ>1) 鵱ǰҳ--; + }else if(ID==1){// + if(鵱ǰҳ < ҳ) 鵱ǰҳ++; + } + int start=(鵱ǰҳ-1)*48; + int end = (鵱ǰҳ*48 < EXPRESSION_NOID_NUM ?鵱ǰҳ*48:EXPRESSION_NOID_NUM); + int x,y; + for(y=0;y<6;y++){ + for(x=0;x<8;x++){ + 鰴ťID=StockDispBuffer(19+x*29, 362+y*29, DISP_PRIO_IME4, EXPRESSION_NOID_START+start, 2); + if(selGraId(&鰴ťID,1)!=-1){ + 鴰״̬=FALSE; + play_se(203, 320, 240); + char [128]; + sprintf_s(,"#%d",start+1); + strcat_s(MyChatBuffer.buffer,); + MyChatBuffer.cursor=strlen(MyChatBuffer.buffer); + MyChatBuffer.cnt=strlen(MyChatBuffer.buffer); + } + start++; + if(EXPRESSION_NOID_NUM < start) break; + } + if(EXPRESSION_NOID_NUM < start) break; + } + } +#endif + StockFontBuffer2( &MyChatBuffer ); +} + +/*******************************************************************************/ +/* ??????S??u????? +/* ??k S?? +/* u?? +/* ??? +/*******************************************************************************/ +int GetStrLastByte( char *str ) +{ + int byte = 0; + + // ?????????? + while( !( *str == '\0' ) ){ + // ( *str == ( char )0x81 && *( str + 1 ) == ( char )0x51 ) ) ){ + + // u???? + if(IsDBCSLeadByte(*str)){ + + // u??????????? + if( *( str + 1 ) == NULL ) return 3; // ?? + + str += 2; // ?????? + byte = 2; // u??? + + }else{ // S???? + + str ++; // ?????? + byte = 1; // S??? + } + } + return byte; +} + +/*******************************************************************************/ +/* ?????????????? +/* ??k ???? +/*******************************************************************************/ +#ifndef _NEWFONT_ +int GetStrWidth( char *str ) +{ + int width = 0; + // ?????????? + while(!( *str == '\0' ) ){ + if(IsDBCSLeadByte(*str)){ + str += 2; + width += FONT_SIZE; // ȫεsize + }else{ + str ++; + width += FONT_SIZE>>1; // εsize + } + } + return width; +} +#else +extern int getTextLength(char * str); +int GetStrWidth( char *str ) +{ + return getTextLength(str); +} +#endif + +/*******************************************************************************/ +/* V??????x +/*******************************************************************************/ +void GetKeyInputFocus( STR_BUFFER *pStrBuffer ) +{ + pNowStrBuffer = pStrBuffer; +} + +// ?????????V????????? ********************************************/ +void GetClipboad( void ) +{ + HGLOBAL hMem; + LPTSTR lpMem; + + /* ???????????? */ + OpenClipboard( hWnd ); + /* ?????????????????????x */ + hMem = GetClipboardData( CF_TEXT ); + /* ?????????? */ + if( hMem == NULL ){ + CloseClipboard(); + return; + } + /* ????????????? */ + lpMem = (LPTSTR)GlobalLock( hMem ); + /* ?????????????????@e */ +// SetWindowText( hwStrE, lpMem ); +// lstrcpy( chat_input_buf, lpMem ); + + StrToNowStrBuffer( lpMem ); + + GlobalUnlock( hMem ); + CloseClipboard(); +} + + +void SetClipboad( void ) +{ + HGLOBAL hMem; + LPTSTR lpMem; + + // V???????? + if( pNowStrBuffer == NULL ) return; + // ??????? + if( pNowStrBuffer->buffer[ 0 ] == NULL ) return; + + /* ?????????? */ + hMem = GlobalAlloc( GHND, 512 ); + /* ????????????????????x */ + lpMem = ( LPTSTR )GlobalLock( hMem ); +// lstrcpy( lpMem, chat_input_buf ); + /* ????????????????? */ + lstrcpy( lpMem, pNowStrBuffer->buffer ); + /* ??????????????? */ + GlobalUnlock( hMem ); + /* ???????????? */ + OpenClipboard( hWnd ); + /* ??????????? */ + EmptyClipboard(); + /* ???????????????????????? */ + SetClipboardData( CF_TEXT, hMem ); + /* ???????????? */ + CloseClipboard(); + /* ?????????? */ + //GlobalFree( hMem ); +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/directdraw.cpp b/石器时代8.5客户端最新源代码/石器源码/system/directdraw.cpp new file mode 100644 index 0000000..4c97534 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/directdraw.cpp @@ -0,0 +1,4019 @@ +/**** SYSTEM INCLUDE ****/ +#include +#include +#include +#include +#include + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/map.h" +#include "../systeminc/anim_tbl.h" + +#define PAL_CHANGE_INTERVAL_WIN 120 // ?????????????????? +#define PAL_CHANGE_INTERVAL_FULL 60 // ???????????????????? +int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); +#ifdef _NEW_COLOR_ +extern int NewColor16Flg; +#endif +//---------------------------------------------------------------------------// +// ??????e? // +//---------------------------------------------------------------------------// +DIRECT_DRAW *lpDraw; // DirectDraw?????????? +BOOL DDinitFlag = FALSE; // DirectDraw?????? + +HFONT hFont; // ???????? + +int displayBpp; // ?? + +int rBitLShift; // ?????????k +int gBitLShift; // ?????????k +int bBitLShift; // ?????????k + +int rBitRShift; // ?????????k +int gBitRShift; // ?????????k +int bBitRShift; // ?????????k + +PALETTEENTRY Palette[256]; // ?????Bl +PALETTE_STATE PalState; // ????֢t?Bl +BOOL PalChangeFlag; // ??????????? +#ifdef _HI_COLOR_32 +unsigned int highColor32Palette[256]; +#endif +unsigned short highColorPalette[256]; + +#ifdef _READ16BITBMP +extern RGBQUAD g_rgbPal[256]; +BOOL g_bUseAlpha = FALSE; +#endif +#ifdef _NEW_COLOR_ +extern BOOL g_bUseAlpha = FALSE; +#endif + +#ifdef _READ16BITBMPVARIABLES // _READ16BITBMP ҪIJ +BOOL g_bUseAlpha = FALSE; +#endif + +#ifdef _TALK_WINDOW +BOOL g_bTalkWindow = FALSE; +#endif + +#ifdef _STONDEBUG_ +extern int g_iMallocCount; +#endif + +void SetAnimTbl(); + +// ??????????? +char *palFileName[] = { +#include "../systeminc/palName.h" +}; + +const int MAX_PAL = sizeof(palFileName) / sizeof(palFileName[0]); +// ??k?????????????? +int getBitCount(int bit) +{ + int i, j, k; + j = 1; + k = 0; + for (i = 0; i < sizeof(int)* 8; i++){ + if ((bit & j)) + k++; + j <<= 1; + } + return k; +} + +#ifdef SWITCH_MODE +DEVMODE g_OriginalMode; +#endif + +BOOL InitDirectDraw(void) +{ + DWORD dwWriteByte; + HANDLE hErrorLogFile; + HRESULT hResult; + char szErrMsg[256]; + DDSCAPS ddscaps; // ??????????e???Bl + if ((hResult = DirectDrawCreate(NULL, &lpDraw->lpDD, NULL)) != DD_OK){ + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "DirectDrawCreate error(1):error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + if ((hResult = DirectDrawCreate((GUID *)DDCREATE_EMULATIONONLY, &lpDraw->lpDD, NULL)) != DD_OK){ + MessageBoxNew(hWnd, "DirectDrawCreate Error", "ȷ", MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "DirectDrawCreate error(2):error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } + } + if ((hResult = lpDraw->lpDD->QueryInterface(IID_IDirectDraw2, (LPVOID *)&lpDraw->lpDD2)) != DD_OK){ + MessageBoxNew(hWnd, "QueryInterface Error", "ȷ", MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "QueryInterface error:error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } +#ifdef _BACK_WINDOW +#undef _BACK_VERSION +#endif +#ifndef _BACK_VERSION + if (WindowMode){ +#ifdef SWITCH_MODE + if( g_OriginalMode.dmSize == 0){ + g_OriginalMode.dmSize = sizeof(DEVMODE); + EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &g_OriginalMode); + } + if( displayBpp!=(int)g_OriginalMode.dmBitsPerPel || lpDraw->xSize!=(int)g_OriginalMode.dmPelsWidth || lpDraw->ySize!=(int)g_OriginalMode.dmPelsHeight){ + DEVMODE DevMode; + int done = 0, iMode = 0; + DevMode.dmSize = sizeof(DEVMODE); + while( EnumDisplaySettings( NULL, iMode, &DevMode)){ + if( (int)DevMode.dmBitsPerPel==displayBpp && DevMode.dmPelsWidth==g_OriginalMode.dmPelsWidth && DevMode.dmPelsHeight==g_OriginalMode.dmPelsHeight){ + ChangeDisplaySettingsEx( NULL, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); + done = 1; + break; + } + iMode++; + DevMode.dmSize = sizeof(DEVMODE); + } + if( done == 0){ + iMode = 0; + DevMode.dmSize = sizeof(DEVMODE); + while( EnumDisplaySettings( NULL, iMode, &DevMode)){ + if( (int)DevMode.dmBitsPerPel==displayBpp && (int)DevMode.dmPelsWidth>=lpDraw->xSize && (int)DevMode.dmPelsHeight>=lpDraw->ySize){ + DevMode.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; + ChangeDisplaySettingsEx( NULL, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); + break; + } + iMode++; + DevMode.dmSize = sizeof(DEVMODE); + } + if( done == 0) return FALSE; + } + } +#endif + if (lpDraw->lpDD2->SetCooperativeLevel(hWnd, DDSCL_NORMAL) != DD_OK){ + MessageBoxNew(hWnd, "SetCooperativeLevel Error", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + + ZeroMemory(&lpDraw->ddsd, sizeof(lpDraw->ddsd)); + lpDraw->ddsd.dwSize = sizeof(lpDraw->ddsd); + lpDraw->ddsd.dwFlags = DDSD_CAPS; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + if ((hResult = lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd, &lpDraw->lpFRONTBUFFER, NULL)) != DD_OK){ + MessageBoxNew(hWnd, "洦ʧܡ", "ȷ", MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "Create frontbuffer error(1):error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } + if (lpDraw->lpDD2->CreateClipper(0, &lpDraw->lpCLIPPER, NULL) != DD_OK){ + MessageBoxNew(hWnd, "clipperʧܡ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + lpDraw->lpCLIPPER->SetHWnd(0, hWnd); + lpDraw->lpFRONTBUFFER->SetClipper(lpDraw->lpCLIPPER); + ZeroMemory(&lpDraw->ddsd, sizeof(lpDraw->ddsd)); + lpDraw->ddsd.dwSize = sizeof(lpDraw->ddsd); + lpDraw->ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + lpDraw->ddsd.dwWidth = lpDraw->xSize; + lpDraw->ddsd.dwHeight = lpDraw->ySize; + if ((hResult = lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd, &lpDraw->lpBACKBUFFER, NULL)) != DD_OK){ + MessageBoxNew(hWnd, "ݴʧ", "ȷ", MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "Create backbuffer error:error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + if((hResult = lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd,&lpDraw->lpBACKBUFFERSYS,NULL)) != DD_OK){ + MessageBoxNew(hWnd,"ݴʧ(sys)","ȷ",MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); + sprintf_s(szErrMsg,"Create backbuffer error:error result (%x)",hResult); + WriteFile(hErrorLogFile,szErrMsg,sizeof(szErrMsg),&dwWriteByte,NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } + } +#endif + } + else +#endif +#ifdef _BACK_WINDOW +#define _BACK_VERSION +#endif + { + if (lpDraw->lpDD2->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX) != DD_OK){ + MessageBoxNew(hWnd, "SetCooperativeLevel Error", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + lpDraw->lpDD2->SetDisplayMode(lpDraw->xSize, lpDraw->ySize, displayBpp, 0, 0); + ZeroMemory(&lpDraw->ddsd, sizeof(lpDraw->ddsd)); + lpDraw->ddsd.dwSize = sizeof(lpDraw->ddsd); + lpDraw->ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; + lpDraw->ddsd.dwBackBufferCount = 1; + if ((hResult = lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd, &lpDraw->lpFRONTBUFFER, NULL)) != DD_OK){ + MessageBoxNew(hWnd, "洦ʧܶ", "ȷ", MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + sprintf_s(szErrMsg, "Create frontbuffer error(2):error result (%x)", hResult); + WriteFile(hErrorLogFile, szErrMsg, sizeof(szErrMsg), &dwWriteByte, NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } + ddscaps.dwCaps = DDSCAPS_BACKBUFFER; + lpDraw->lpFRONTBUFFER->GetAttachedSurface(&ddscaps, &lpDraw->lpBACKBUFFER); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + ZeroMemory( &lpDraw->ddsd, sizeof( lpDraw->ddsd ) ); + lpDraw->ddsd.dwSize = sizeof( lpDraw->ddsd ); + lpDraw->ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + lpDraw->ddsd.dwWidth = lpDraw->xSize; + lpDraw->ddsd.dwHeight = lpDraw->ySize; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + if((hResult = lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd,&lpDraw->lpBACKBUFFERSYS,NULL)) != DD_OK){ + MessageBoxNew(hWnd,"ݴʧܶ(sys)","ȷ",MB_OK | MB_ICONSTOP); + hErrorLogFile = CreateFile("ErrorLog.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); + sprintf_s(szErrMsg,"Create backbuffer error:error result (%x)",hResult); + WriteFile(hErrorLogFile,szErrMsg,sizeof(szErrMsg),&dwWriteByte,NULL); + CloseHandle(hErrorLogFile); + return FALSE; + } + } +#endif + } + // WON REM +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + if (lpDraw->lpBACKBUFFER == NULL) + return FALSE; + + DDPIXELFORMAT ddPixelFormat; + ZeroMemory(&ddPixelFormat, sizeof(DDPIXELFORMAT)); + ddPixelFormat.dwSize = sizeof(DDPIXELFORMAT); + + if (lpDraw->lpBACKBUFFER->GetPixelFormat(&ddPixelFormat) != DD_OK) + return FALSE; + + rBitRShift = 8 - getBitCount(ddPixelFormat.dwRBitMask); // ?????????k + gBitRShift = 8 - getBitCount(ddPixelFormat.dwGBitMask); // ?????????k + bBitRShift = 8 - getBitCount(ddPixelFormat.dwBBitMask); // ?????????k + + rBitLShift = getBitCount(ddPixelFormat.dwBBitMask) + getBitCount(ddPixelFormat.dwGBitMask); // ?????????k + gBitLShift = getBitCount(ddPixelFormat.dwBBitMask); // ?????????k + bBitLShift = 0; // ?????????k + } + else + +#endif +#ifdef _HI_COLOR_16 + // ???????????????ѩ?x?? + if (displayBpp == 16){ + // ??????????NULL???? + if (lpDraw->lpBACKBUFFER == NULL) + return FALSE; + + DDPIXELFORMAT ddPixelFormat; // ????ѩ?Bl + // ?Bl???? + ZeroMemory(&ddPixelFormat, sizeof(DDPIXELFORMAT)); + ddPixelFormat.dwSize = sizeof(DDPIXELFORMAT); + + if (lpDraw->lpBACKBUFFER->GetPixelFormat(&ddPixelFormat) != DD_OK) + return FALSE; + + rBitRShift = 8 - getBitCount(ddPixelFormat.dwRBitMask); // ?????????k + gBitRShift = 8 - getBitCount(ddPixelFormat.dwGBitMask); // ?????????k + bBitRShift = 8 - getBitCount(ddPixelFormat.dwBBitMask); // ?????????k + + rBitLShift = getBitCount(ddPixelFormat.dwBBitMask) + getBitCount(ddPixelFormat.dwGBitMask); // ?????????k + gBitLShift = getBitCount(ddPixelFormat.dwBBitMask); // ?????????k + bBitLShift = 0; // ?????????k + } + +#endif + // ?????????? + if ((lpBattleSurface = CreateSurface(DEF_APPSIZEX, DEF_APPSIZEY, DEF_COLORKEY, DDSCAPS_VIDEOMEMORY)) == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd ,"VideoRam BattleSurfaceʧܣ" ,"ȷ",MB_OK | MB_ICONSTOP ); +#endif + if ((lpBattleSurface = CreateSurface(DEF_APPSIZEX, DEF_APPSIZEY, DEF_COLORKEY, DDSCAPS_SYSTEMMEMORY)) == NULL){ + MessageBoxNew(hWnd, "BattleSurfaceʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if((lpBattleSurfaceSys = CreateSurface(DEF_APPSIZEX,DEF_APPSIZEY,DEF_COLORKEY,DDSCAPS_SYSTEMMEMORY)) == NULL){ + MessageBoxNew(hWnd,"BattleSurface(sys)ʧܣ","ȷ",MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#endif +#ifdef __SKYISLAND + ClearSurface(lpBattleSurface); +#ifdef _READ16BITBMP + if(g_bUseAlpha) ClearSurface(lpBattleSurfaceSys); +#endif + extern void SkyIslandLoadBmp(); + SkyIslandLoadBmp(); +#endif + DDinitFlag = TRUE; + SetAnimTbl(); + return TRUE; +} + +BOOL InitPalette(void) +{ + int i; + FILE *fp; + + PALETTEENTRY pal[32] = { + // ????? + { 0x00, 0x00, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 0:? + { 0x80, 0x00, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 1:?? + { 0x00, 0x80, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 2:??? + { 0x80, 0x80, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 3:??? + { 0x00, 0x00, 0x80, PC_NOCOLLAPSE | PC_RESERVED }, // 4:?? + { 0x80, 0x00, 0x80, PC_NOCOLLAPSE | PC_RESERVED }, // 5:??? + { 0x00, 0x80, 0x80, PC_NOCOLLAPSE | PC_RESERVED }, // 6:??? + { 0xc0, 0xc0, 0xc0, PC_NOCOLLAPSE | PC_RESERVED }, // 7:??? + { 0xc0, 0xdc, 0xc0, PC_NOCOLLAPSE | PC_RESERVED }, // 8:? + { 0xa6, 0xca, 0xf0, PC_NOCOLLAPSE | PC_RESERVED }, // 9:? + + //ϵͳɫ// ???????? + { 0xde, 0x00, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, + { 0xff, 0x5f, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, + { 0xff, 0xff, 0xa0, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x00, 0x5f, 0xd2, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x50, 0xd2, 0xff, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x28, 0xe1, 0x28, PC_NOCOLLAPSE | PC_RESERVED }, + + //ϵͳɫ// ???????? + { 0xf5, 0xc3, 0x96, PC_NOCOLLAPSE | PC_RESERVED }, + { 0xe1, 0xa0, 0x5f, PC_NOCOLLAPSE | PC_RESERVED }, + { 0xc3, 0x7d, 0x46, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x9b, 0x55, 0x1e, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x46, 0x41, 0x37, PC_NOCOLLAPSE | PC_RESERVED }, + { 0x28, 0x23, 0x1e, PC_NOCOLLAPSE | PC_RESERVED }, + + // ????? + { 0xff, 0xfb, 0xf0, PC_NOCOLLAPSE | PC_RESERVED }, // 246:? + { 0xa0, 0xa0, 0xa4, PC_NOCOLLAPSE | PC_RESERVED }, // 247:? + { 0x80, 0x80, 0x80, PC_NOCOLLAPSE | PC_RESERVED }, // 248:? + { 0xff, 0x00, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 249: + { 0x00, 0xff, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 250:? + { 0xff, 0xff, 0x00, PC_NOCOLLAPSE | PC_RESERVED }, // 251:? + { 0x00, 0x00, 0xff, PC_NOCOLLAPSE | PC_RESERVED }, // 252: + { 0xff, 0x00, 0xff, PC_NOCOLLAPSE | PC_RESERVED }, // 253:? + { 0x00, 0xff, 0xff, PC_NOCOLLAPSE | PC_RESERVED }, // 254:? + { 0xff, 0xff, 0xff, PC_NOCOLLAPSE | PC_RESERVED } // 255:? + }; + + + // ?????????@e + for (i = 0; i < 10; i++){ + Palette[i].peBlue = pal[i].peBlue; + Palette[i].peGreen = pal[i].peGreen; + Palette[i].peRed = pal[i].peRed; + Palette[i].peFlags = PC_EXPLICIT; + + Palette[i + 246].peBlue = pal[i + 22].peBlue; + Palette[i + 246].peGreen = pal[i + 22].peGreen; + Palette[i + 246].peRed = pal[i + 22].peRed; + Palette[i + 246].peFlags = PC_EXPLICIT; + } + + // ?????????@e + for (i = 0; i < 6; i++){ + Palette[i + 10].peBlue = pal[i + 10].peBlue; + Palette[i + 10].peGreen = pal[i + 10].peGreen; + Palette[i + 10].peRed = pal[i + 10].peRed; + Palette[i + 10].peFlags = PC_NOCOLLAPSE | PC_RESERVED; + + Palette[i + 240].peBlue = pal[i + 16].peBlue; + Palette[i + 240].peGreen = pal[i + 16].peGreen; + Palette[i + 240].peRed = pal[i + 16].peRed; + Palette[i + 240].peFlags = PC_NOCOLLAPSE | PC_RESERVED; + } + + //ֻеһβ(ûгʼʱ)// ???????????k????? + if (PalState.flag == FALSE){ + fp = fopen(palFileName[0], "rb"); + if (fp == NULL){ + MessageBoxNew(hWnd, "ɫ̵ȡʧ", "Error", MB_OK | MB_ICONSTOP); + return FALSE; + } + else{ + //ʹõĵɫ趨// ?????????@e + for (i = 16; i < 240; i++){ + //// ???????? + Palette[i].peBlue = fgetc(fp); + Palette[i].peGreen = fgetc(fp); + Palette[i].peRed = fgetc(fp); + Palette[i].peFlags = PC_NOCOLLAPSE | PC_RESERVED; + } + fclose(fp); + } + } + if (!transmigrationEffectFlag) + { + Palette[168].peBlue = 0; + Palette[168].peGreen = 0; + Palette[168].peRed = 0; + //Palette[168].peFlags = PC_EXPLICIT; + } + +#if 0 + else{ + // ?????????@e + for( i = 16; i < 240; i++ ){ + // ?????????? + if( WindowMode ){ + Palette[i].peFlags = PC_NOCOLLAPSE | PC_RESERVED; + }else{ + Palette[i].peFlags = PC_EXPLICIT; + } + } + } +#endif + lpDraw->lpDD2->CreatePalette(DDPCAPS_8BIT, Palette, &lpDraw->lpPALETTE, NULL); + if (lpDraw->lpPALETTE == NULL){ + MessageBoxNew(hWnd, "ɫ̴ʧ", "Error", MB_OK | MB_ICONSTOP); + return FALSE; + } + // WON REM +#ifdef _HI_COLOR_16 + //#ifdef _STONDEBUG_ + if (displayBpp == 8){ + if (lpDraw->lpFRONTBUFFER->SetPalette(lpDraw->lpPALETTE) != DD_OK){ + MessageBoxNew(hWnd, "ɫ̴ʧ", "Error", MB_OK); + MessageBoxNew(hWnd, "ʹãλԪ߲ɫ򣳣λԪ߲ɫģʾ", "Error", MB_OK); + return FALSE; + } + } +#else + // Robin 05/02 +#ifdef SWITCH_MODE + if( lpDraw->lpFRONTBUFFER->SetPalette( lpDraw->lpPALETTE ) != DD_OK ){ + if( MessageBoxNew(hWnd, "ʹãɫʾģʾ", "ȷ", MB_RETRYCANCEL | MB_ICONEXCLAMATION ) == IDCANCEL) + return FALSE; + return FALSE; + } +#else + while( lpDraw->lpFRONTBUFFER->SetPalette( lpDraw->lpPALETTE ) != DD_OK ){ + if( MessageBoxNew(hWnd, "ʹãɫʾģʾ", "ȷ", MB_RETRYCANCEL | MB_ICONEXCLAMATION ) == IDCANCEL) + return FALSE; + } +#endif + +#endif + +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + highColor32Palette[0] = 0; + for (i = 1; i < 256; i++){ + highColor32Palette[i] = + ((Palette[i].peBlue >> bBitRShift) << bBitLShift) + + ((Palette[i].peGreen >> gBitRShift) << gBitLShift) + + ((Palette[i].peRed >> rBitRShift) << rBitLShift); + } + } + else +#endif + if (displayBpp == 16){ + // ?????????????? + highColorPalette[0] = 0; + for (i = 1; i < 256; i++){ + highColorPalette[i] = + ((Palette[i].peBlue >> bBitRShift) << bBitLShift) + //cary 2001 10 16 + + (((Palette[i].peGreen >> gBitRShift) | 1) << gBitLShift) + + ((Palette[i].peRed >> rBitRShift) << rBitLShift); + } + } + + PalState.flag = TRUE; + return TRUE; +} + +// ???????? ***********************************************************/ +void PaletteChange(int palNo, int time) +{ + // ???????? + if (palNo >= MAX_PAL) + return; + // ????k? + PalState.palNo = palNo; + // ??????? + PalState.time = time; + // ???????? + if (PalState.time <= 0) + PalState.time = 1; +} + +#ifdef _CACHE_SURFACE_ + +BOOL IsSurfaceExpired(SURFACE_INFO *surface) +{ + return (surface->palNo != PalState.palNo); +} + +#endif + +// ɫ̴ ***************************************************************/ +void PaletteProc(void) +{ + FILE *fp; // ???????? + static PALETTEENTRY pal[256]; // ?????Bl + static float dRed[256]; // ????? + static float dGreen[256]; // ????? + static float dBlue[256]; // ????? + static float dRedBak[256]; // ????? + static float dGreenBak[256]; // ????? + static float dBlueBak[256]; // ????? + static int timeCnt; // ???????? + static int changeCnt; // ????????? + static int palNoBak = 0; // ????? + static int openFlag = FALSE; // ??????????? + int i; + // ???????????? + if (palNoBak == PalState.palNo && openFlag == FALSE) + return; + // ??????????? + if (palNoBak != PalState.palNo){ + // ???????????? + fp = fopen(palFileName[PalState.palNo], "rb"); + // ?????????@e + for (i = 16; i < 240; i++){ + pal[i].peBlue = fgetc(fp); + pal[i].peGreen = fgetc(fp); + pal[i].peRed = fgetc(fp); + // 168??( 0, 0, 0 )?? + if (i == 168){ + pal[168].peBlue = 0; + pal[168].peGreen = 0; + pal[168].peRed = 0; + } + // ????? + dBlueBak[i] = Palette[i].peBlue; + dGreenBak[i] = Palette[i].peGreen; + dRedBak[i] = Palette[i].peRed; + // ?? + dBlue[i] = (float)(pal[i].peBlue - Palette[i].peBlue) / (float)PalState.time; + dGreen[i] = (float)(pal[i].peGreen - Palette[i].peGreen) / (float)PalState.time; + dRed[i] = (float)(pal[i].peRed - Palette[i].peRed) / (float)PalState.time; +#if 0 + // ?????????? + if( WindowMode ){ + Palette[i].peFlags = PC_NOCOLLAPSE | PC_RESERVED; + }else{ + Palette[i].peFlags = PC_EXPLICIT; + } +#endif + } + fclose(fp); // ?????? + timeCnt = 0; // ???????????????????? + changeCnt = 0; // ????????????????????; + palNoBak = PalState.palNo; // ?????? + openFlag = TRUE; // ????? + } + // ????? + timeCnt++; + // ???? + if (timeCnt <= PalState.time){ + // ?????????@e + for (i = 16; i < 240; i++){ + // ????? + dBlueBak[i] += dBlue[i]; + dGreenBak[i] += dGreen[i]; + dRedBak[i] += dRed[i]; + // ????? + Palette[i].peBlue = (BYTE)dBlueBak[i]; + Palette[i].peGreen = (BYTE)dGreenBak[i]; + Palette[i].peRed = (BYTE)dRedBak[i]; + } + } + else{ + // ??????????u??????k???? + // ?????????@e + for (i = 16; i < 240; i++){ + Palette[i].peBlue = pal[i].peBlue; + Palette[i].peGreen = pal[i].peGreen; + Palette[i].peRed = pal[i].peRed; + } + openFlag = FALSE; // ?????? + transEffectPaletteStatus = 2; + } + // ?????????????????? + if (changeCnt == 0 || openFlag == FALSE){ + // ????????????? + PalChangeFlag = TRUE; + // ???????@e + //lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); + } + // ???????? + changeCnt++; + // ?????????? + if (transmigrationEffectFlag) + { + // ?????? + if (changeCnt >= 10) changeCnt = 0; + } + if (WindowMode){ + if (changeCnt >= PAL_CHANGE_INTERVAL_WIN) + changeCnt = 0; + } + else{ + if (changeCnt >= PAL_CHANGE_INTERVAL_FULL) + changeCnt = 0; + } +} + +//---------------------------------------------------------------------------// +// ?? ?i?_????????????????????????? // +// ?? ?? // +// ?k ?? // +//---------------------------------------------------------------------------// + +extern RECT g_clientRect; +extern POINT g_clientPoint; +extern RECT g_moveRect; +#ifdef _MO_SHOW_FPS +int framesToShow; +int skipFramesToShow; +extern int NoDrawCnt; +void CalculateFrameRate() +{ + static int framesSkipPerSecond = 0; + static float framesPerSecond = 0.0f; // This will store our fps + static float lastTime = 0.0f; // This will hold the time from the last frame + float currentTime = TimeGetTime() * 0.001f; + ++framesPerSecond; + framesSkipPerSecond += NoDrawCnt - 1; + + if (currentTime - lastTime > 1.0f) + { + lastTime = currentTime; + framesToShow= int(framesPerSecond); + framesPerSecond = 0; + skipFramesToShow = framesSkipPerSecond; + framesSkipPerSecond = 0; + } +} +#endif + + +void Flip(void) +{ +#ifdef _MO_SHOW_FPS + CalculateFrameRate(); +#endif + + if (WindowMode == TRUE){ + lpDraw->lpFRONTBUFFER->Blt(&g_clientRect, lpDraw->lpBACKBUFFER, &g_moveRect, DDBLT_WAIT, NULL); + } + else + { + lpDraw->lpDD2->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL); + lpDraw->lpFRONTBUFFER->Flip(NULL, DDFLIP_WAIT); + } + return; +} + +//---------------------------------------------------------------------------// +// ?? ????????????? // +// ?? DIRECT_DRAW *lpDraw : DirectDraw???Bl // +// ?k ?? // +//---------------------------------------------------------------------------// +void ClearBackSurface(void) +{ + DDBLTFX ddbltfx; + + ZeroMemory(&ddbltfx, sizeof(DDBLTFX)); + ddbltfx.dwSize = sizeof(DDBLTFX); +#ifdef _STONDEBUG_ + QueryPerformanceCounter(&tf); + iTotalProcTime = (int)tf.QuadPart; +#endif + HRESULT hr = lpDraw->lpBACKBUFFER->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + lpDraw->lpBACKBUFFERSYS->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&ddbltfx); + } +#endif +#ifdef _STONDEBUG_ + QueryPerformanceCounter(&tf); + iTotalUseTime += (((int)tf.QuadPart - iTotalProcTime)) /100; + iTotalRunCount++; +#endif +} + +//---------------------------------------------------------------------------// +// ?? ?????????? // +// ?? DIRECT_DRAW *lpDraw : DirectDraw???Bl // +// ?k ?? // +//---------------------------------------------------------------------------// +void ClearSurface(LPDIRECTDRAWSURFACE lpSurface) +{ + DDBLTFX ddbltfx; + + ZeroMemory(&ddbltfx, sizeof(DDBLTFX)); + ddbltfx.dwSize = sizeof(DDBLTFX); + ddbltfx.dwFillColor = DEF_COLORKEY; // a?@e + + lpSurface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); + + return; +} + +// ??????????????????? +int BmpOffBits; +//---------------------------------------------------------------------------// +// ?? ????????????????????? // +// ?? char * pFile : ?????????? // +// ??kLPBITMAPINFO : NULL .????Or???? // +// NULL??.LPBITMAPINFO???? // +//---------------------------------------------------------------------------// +LPBITMAPINFO LoadDirectDrawBitmap(char *pFile) +{ + HFILE hFile; + OFSTRUCT ofSt; + BITMAPFILEHEADER BmpFileHeader; + LPBITMAPINFO lpBmpInfo; + + //??????? + if ((hFile = OpenFile(pFile, &ofSt, OF_READ)) == HFILE_ERROR) + return (LPBITMAPINFO)NULL; // File Open Error + + //????????????????? + _hread(hFile, &BmpFileHeader, sizeof(BITMAPFILEHEADER)); + + //?????????? + if ((lpBmpInfo = (LPBITMAPINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, BmpFileHeader.bfSize)) == NULL){ + MessageBoxNew(hWnd, "Heapüʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return (LPBITMAPINFO)NULL; //Memory Error + } + + //???????? + _hread(hFile, (void *)lpBmpInfo, BmpFileHeader.bfSize); + + //???????? + _lclose(hFile); + + // ??????????????????? + BmpOffBits = BmpFileHeader.bfOffBits - sizeof(BITMAPFILEHEADER); + + return lpBmpInfo; +} + +//---------------------------------------------------------------------------// +// ?? ???????????? // +// ?? short bxsize : ?θϐD???Ρ) // +// short bysize : ?θϐD?c?(Ρ) // +// DWORD ColorKey : a???k?(0?255) // +// ??k? ... ?????????? / ... NULL // +//---------------------------------------------------------------------------// +LPDIRECTDRAWSURFACE CreateSurface(short bxsize, short bysize, DWORD ColorKey, unsigned int VramOrSysram) +{ + DDCOLORKEY ddck; + LPDIRECTDRAWSURFACE lpSurface; +#ifdef _NEW_ALPHA_ + VramOrSysram = DDSCAPS_SYSTEMMEMORY; +#endif + lpDraw->ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + lpDraw->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | VramOrSysram; + lpDraw->ddsd.dwWidth = bxsize; + lpDraw->ddsd.dwHeight = bysize; + if (lpDraw->lpDD2->CreateSurface(&lpDraw->ddsd, &lpSurface, NULL) != DD_OK) + return (LPDIRECTDRAWSURFACE)NULL; + + ddck.dwColorSpaceLowValue = ColorKey; + ddck.dwColorSpaceHighValue = ColorKey; + lpSurface->SetColorKey(DDCKEY_SRCBLT, &ddck); + + return lpSurface; +} + + +//---------------------------------------------------------------------------// +// ?? ???????e??????? // +// ?? LPDIRECTDRAWSURFACE lpSurface : ?????? // +// short Xpoint : ???????t // +// short Ypoint : ??????t // +// LPBITMAPINFO pInfo : ??????????Bl // +// ?k ?? // +//---------------------------------------------------------------------------// +// ????????????? ? StretchDIBits ?? ? +void DrawBitmapToSurface(LPDIRECTDRAWSURFACE lpSurface, int offsetX, int offsetY, LPBITMAPINFO pBmpInfo) +{ + HDC hDcDest; + // e?????k????????????? + lpSurface->GetDC(&hDcDest); + StretchDIBits(hDcDest, + 0, 0, + //cary + pBmpInfo->bmiHeader.biWidth, pBmpInfo->bmiHeader.biHeight, + //SurfaceSizeX, SurfaceSizeY, + offsetX, offsetY, + pBmpInfo->bmiHeader.biWidth, pBmpInfo->bmiHeader.biHeight, + //SurfaceSizeX, SurfaceSizeY, + //end + (void *)((BYTE *)pBmpInfo + (sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)* 256)), + pBmpInfo, + + //DIB_PAL_COLORS, + DIB_RGB_COLORS, + //DIB_PAL_INDICES, + + SRCCOPY); + //NOTSRCCOPY ); + //DSTINVERT ); + //BLACKNESS ); + lpSurface->ReleaseDC(hDcDest); + + return; +} + +// ????????????? ? memcpy ?? ?****************************/ +#ifdef _READ16BITBMP +void DrawBitmapToSurface2(SURFACE_INFO *surface_info,LPDIRECTDRAWSURFACE lpSurfaceSys,int offsetX,int offsetY,int sizeX,int sizeY,LPBITMAPINFO pBmpInfo) +{ + + + LPDIRECTDRAWSURFACE lpSurface = surface_info->lpSurface; + DDSURFACEDESC ddsd; // ??????Bl + char *pDest; //Ŀĵָ// ?I????? + char *pSource; //Դָ// ??????? + short *pDest2; //Ŀĵָ(WORD type)// ?I??????????? + int surfacePitch; //source face // ?????????? + int bmpWidth; //bmpͼĿ// ???????? + int i; +#ifdef _READ16BITBMP + DDSURFACEDESC ddsdsys; + short *pDestSys; //Ŀĵָ systemmemory + int surfacePitchSys; //source face +#endif +#ifdef _HI_COLOR_32 + int *pDest32; + int *pDestSys32; + int surfacePitchSys32; +#endif + + // ??????????NULL???? + if( lpSurface == NULL ) return; +#ifdef _READ16BITBMP + if(lpSurfaceSys == NULL ) return; +#endif + // ?Bl???? + ZeroMemory( &ddsd, sizeof( DDSURFACEDESC ) ); + ddsd.dwSize = sizeof( DDSURFACEDESC ); +#ifdef _READ16BITBMP + ZeroMemory(&ddsdsys,sizeof(DDSURFACEDESC)); + ddsdsys.dwSize = sizeof(DDSURFACEDESC); +#endif + if( lpSurface->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ){ + return; + } +#ifdef _READ16BITBMP + if(lpSurfaceSys->Lock(NULL,&ddsdsys,DDLOCK_WAIT,NULL) != DD_OK){ + lpSurface->Unlock(NULL); + return; + } +#endif + pDest = ( char *)( ddsd.lpSurface ); +#ifdef _READ16BITBMP + pDestSys = (short*)(ddsdsys.lpSurface); +#endif +#ifdef _HI_COLOR_32 + pDestSys32 = (int*)(ddsdsys.lpSurface); +#endif + +#if 0 + pSource = ( char *)pBmpInfo + BmpOffBits + + offsetY * pBmpInfo->bmiHeader.biWidth + offsetX; + +#else + pSource = pRealBinBits + + offsetY * RealBinWidth + offsetX; +#endif + surfacePitch = ddsd.lPitch; +#ifdef _READ16BITBMP + surfacePitchSys = ddsdsys.lPitch >> 1; +#ifdef _HI_COLOR_32 + surfacePitchSys32 = ddsdsys.lPitch >> 2; +#endif + +#endif +#if 0 + bmpWidth = pBmpInfo->bmiHeader.biWidth; + +#else + bmpWidth = RealBinWidth; +#endif + if(ResoMode == 1){ + pSource -= bmpWidth; + sizeY >>= 1; + } + for( i = 0 ; i < sizeY ; i++ ){ + if(ResoMode == 1){ + _asm{ + mov edi,[pDest] //?I???? + mov esi,[pSource] //?????? + mov eax,[sizeX] //???????? + // mov ah,al // + shr ax,1 + mov cx,ax + inc esi //?????????????? + + loop_100: + mov al,[esi] //??????? + // cmp al,240 //????a? + // jne loop_200 //????????? + + // xor al,al //??a?? + + //loop_200: + mov [edi],al //???????? + inc esi //??????? + inc esi //??????? + inc edi //?I????? + // dec ah //?? + dec cx //?? + jne loop_100 //?????????? + } + // ???????????????? ?????????? ? + pSource -= bmpWidth*2; + } else { +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ) + { + int j; + int pixel; +#ifdef _HI_COLOR_32 + pDest32 = (int *)pDest; +#endif + for( j = 0; j < sizeX; j++ ){ +#ifdef _NEW_COLOR_ + if(NewColor16Flg==1){ + short *pDest3 = (short *)((pSource-pRealBinBits)*2+pRealBinBits); + if(pDest3[j]==DEF_COLORKEY){ + pDest32[j] = 0; +#ifdef _READ16BITBMP + pDestSys32[j] =0; +#endif + }else{ + pDest32[j] = (((pDest3[j]&0x001F)<<3)|((pDest3[j]&0x07E0 )<<5)|((pDest3[j]&0xF800 )<<8 )|0xFF000000 ); +#ifdef _READ16BITBMP + pDestSys32[j] = (((pDest3[j]&0x001F)<<3)|((pDest3[j]&0x07E0 )<<5)|((pDest3[j]&0xF800 )<<8 )|0xFF000000 ); +#endif + } + }else if(NewColor16Flg==2){ + + int *pDest3 = (int *)((pSource-pRealBinBits)*4+pRealBinBits); + if ((pDest3[j] & 0xff000000) == DEF_COLORKEY || ((pDest3[j] & 0xff) < 3 && ((pDest3[j] >> 16) & 0xff) < 3 && ((pDest3[j]>> 8) & 0xff) < 3 )){ + pDest32[j] = 0; + +#ifdef _READ16BITBMP + pDestSys32[j] =0; +#endif + }else{ + pDest32[j] = pDest3[j]; +#ifdef _READ16BITBMP + pDestSys32[j] = pDest3[j]; +#endif + } + }else{ +#endif + if( pSource[j] == DEF_COLORKEY ){ + pDest32[j] = 0; +#ifdef _READ16BITBMP + pDestSys32[j] = 0; +#endif + }else{ + pixel = highColor32Palette[(unsigned char)pSource[j]]; + if( pixel == 0 ){ + pDest32[j] = 1; +#ifdef _READ16BITBMP + pDestSys32[j] = 1; +#endif + }else{ + pDest32[j] = pixel; +#ifdef _READ16BITBMP + pDestSys32[j] = pixel; +#endif + } + } +#ifdef _NEW_COLOR_ + } +#endif + } + }else +#endif + if( displayBpp == 16 ) + { + int j; + short pixel; + + pDest2 = (short *)pDest; + + for( j = 0; j < sizeX; j++ ) + { +#ifdef _NEW_COLOR_ + if(NewColor16Flg==1){ + short *pDest3 = (short *)((pSource-pRealBinBits)*2+pRealBinBits); + if(pDest3[j]==DEF_COLORKEY){ + pDest2[j] = 0; +#ifdef _READ16BITBMP + pDestSys[j] = 0; +#endif + }else{ + pDest2[j] = pDest3[j]; +#ifdef _READ16BITBMP + pDestSys[j] = pDest3[j]; +#endif + } + }else if(NewColor16Flg==2){ + int *pDest3 = (int *)((pSource-pRealBinBits)*4+pRealBinBits); + if((pDest3[j] & 0xff000000) == DEF_COLORKEY || ((pDest3[j] & 0xff) < 3 && ((pDest3[j] >> 16) & 0xff) < 3 && ((pDest3[j]>> 8) & 0xff) < 3 )){ + pDest2[j] = 0; +#ifdef _READ16BITBMP + pDestSys[j] = 0; +#endif + }else{ + pDest2[j] = ((pDest3[j] >> 8) & 0xF8) | ((pDest3[j]>>5) & 0x7E) | ((pDest3[j]>>3) & 0x1F); +#ifdef _READ16BITBMP + pDestSys[j] = ((pDest3[j] >> 8) & 0xF8) | ((pDest3[j]>>5) & 0x7E) | ((pDest3[j]>>3) & 0x1F); +#endif + } + }else{ +#endif + if( pSource[j] == DEF_COLORKEY ) + { + pDest2[j] = 0; +#ifdef _READ16BITBMP + pDestSys[j] = 0; +#endif + } + else + { + pixel = highColorPalette[(unsigned char)pSource[j]]; + if( pixel == 0 ) + { + pDest2[j] = 1; +#ifdef _READ16BITBMP + pDestSys[j] = 1; +#endif + } + else + { + pDest2[j] = pixel; +#ifdef _READ16BITBMP + pDestSys[j] = pixel; +#endif + } + } +#ifdef _NEW_COLOR_ + } +#endif + } + }else{ + memcpy( pDest, pSource, sizeX ); + } + //HiO???????? + + // ???????????????? ?????????? ? + pSource -= bmpWidth; + } + // ??????????????? + pDest += surfacePitch; +#ifdef _READ16BITBMP + pDestSys += surfacePitchSys; +#endif +#ifdef _HI_COLOR_32 + pDestSys32 += surfacePitchSys32; +#endif + } + + // ??????????????????? + if( lpSurface->Unlock( NULL ) != DD_OK ){ + //MessageBoxNew( hWnd, "SurfaceUnlockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } +#ifdef _READ16BITBMP + lpSurfaceSys->Unlock(NULL); +#endif + return; +} +#endif + +#ifdef _CACHE_SURFACE_ +void DrawSurfaceFromPalette(SURFACE_INFO* surface_info) +{ + int sizeX, sizeY; + DDSURFACEDESC ddsd; + BYTE *pSource; //Դָ// + LPDIRECTDRAWSURFACE lpSurface = surface_info->lpSurface; + if (lpSurface == NULL) return; + //Ϊ256ɫ + if (surface_info->colordepth > 0) return; + //԰δı䲢Ҳлɫ̣ôͷأʹûе + if (surface_info->palNo == PalState.palNo && PalState.time == 1) return; + sizeX = surface_info->sizeX; + sizeY = surface_info->sizeY; + surface_info->palNo = PalState.palNo; + pSource = (BYTE *)surface_info->lpCacheData; + + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + if (lpSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK){ + return; + } + + if (displayBpp == 32) + { + DWORD *pDest = (DWORD *)(ddsd.lpSurface); + for (int i = 0; i < sizeY; i++) + { + for (int j = 0; j < sizeX; j++) + { + BYTE v = *(pSource + i * SurfaceSizeX + j); + *(pDest + i * SurfaceSizeX + j) = (v == DEF_COLORKEY ? 0 : ((highColor32Palette[v] == 0 ? 1 : highColor32Palette[v]))); + } + } + } + else + { + WORD *pDest = (WORD *)(ddsd.lpSurface); + for (int i = 0; i < sizeY; i++) + { + for (int j = 0; j < sizeX; j++) + { + BYTE v = *(pSource + i * SurfaceSizeX + j); + *(pDest + i * SurfaceSizeX + j) = (v == DEF_COLORKEY ? 0 : (highColorPalette[v] == 0 ? 1 : highColorPalette[v])); + } + } + } + if (lpSurface->Unlock(NULL) != DD_OK){ + return; + } + +} +#endif + +void DrawBitmapToSurface2(SURFACE_INFO *surface_info, int offsetX, int offsetY, int sizeX, int sizeY, LPBITMAPINFO pBmpInfo) +{ +#ifdef _CACHE_SURFACE_ + LPDIRECTDRAWSURFACE lpSurface = surface_info->lpSurface; + DDSURFACEDESC ddsd; + char *pDest; //Ŀĵָ// + char *pCache; // + char *pSource; //Դָ// + BYTE *alphatemp; + int surfacePitch; //source face // + int bmpWidth; //bmpͼĿ// + int i; + + if (lpSurface == NULL) return; + + surface_info->sizeX = sizeX; + surface_info->sizeY = sizeY; + surface_info->palNo = -1; + surface_info->colordepth = NewColor16Flg; + + if (surface_info->lpCacheData == NULL) + { + surface_info->lpCacheData = (char *)MALLOC(SurfaceSizeX*SurfaceSizeY); + if (surface_info->lpCacheData == NULL) return; + } + memset(surface_info->lpCacheData, 0, SurfaceSizeX*SurfaceSizeY); + pCache = surface_info->lpCacheData; + + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + if (lpSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK){ + return; + } + pDest = (char *)(ddsd.lpSurface); + + + +#if 0 + pSource = ( char *)pBmpInfo + BmpOffBits + + offsetY * pBmpInfo->bmiHeader.biWidth + offsetX; +#else + pSource = pRealBinBits + + offsetY * RealBinWidth + offsetX; + if (NewColor16Flg == 2 && displayBpp == 16){ + surface_info->lpAlphaData = (BYTE*)MALLOC(SurfaceSizeX*SurfaceSizeY); + memset(surface_info->lpAlphaData, 0, SurfaceSizeX*SurfaceSizeY); + alphatemp = surface_info->lpAlphaData; + } +#endif + surfacePitch = ddsd.lPitch; +#if 0 + bmpWidth = pBmpInfo->bmiHeader.biWidth; +#else + bmpWidth = RealBinWidth; +#endif + if (ResoMode == 1){ + pSource -= bmpWidth; + sizeY >>= 1; + } + for (i = 0; i < sizeY; i++){ + if (ResoMode == 1){ + _asm{ + mov edi, [pDest] + mov esi, [pSource] + mov eax, [sizeX] + shr ax, 1 + mov cx, ax + inc esi + loop_100 : + mov al, [esi] + mov[edi], al + inc esi + inc esi + inc edi + dec cx + jne loop_100 + } + pSource -= bmpWidth * 2; + } + else { +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + if (NewColor16Flg) + { + int j; + int pixel; + int * pDest2; + pDest2 = (int *)pDest; + for (j = 0; j < sizeX; j++){ +#ifdef _NEW_COLOR_ + if (NewColor16Flg == 1){ //rgb565 + short *pDest3 = (short *)((pSource - pRealBinBits) * 2 + pRealBinBits); + if (pDest3[j] == DEF_COLORKEY) + pDest2[j] = 0; + else{ + pDest2[j] = (((pDest3[j] & 0x001F) << 3) | ((pDest3[j] & 0x07E0) << 5) | ((pDest3[j] & 0xF800) << 8) | 0xFF000000); + } + } + else if (NewColor16Flg == 2){ //rgba8888 + int *pDest3 = (int *)((pSource - pRealBinBits) * 4 + pRealBinBits); + if ((pDest3[j] & 0xFF000000) >> 24 == DEF_COLORKEY) + pDest2[j] = 0; + else{ + pDest2[j] = pDest3[j]; + } + } +#endif + } + } + else //256ɫ + { + memcpy(pCache, pSource, sizeX); + } + } + else +#endif + if (displayBpp == 16){ + if (NewColor16Flg) + { + + int j; + short pixel; + short *pDest2 = (short *)pDest; + for (j = 0; j < sizeX; j++){ +#ifdef _NEW_COLOR_ + if (NewColor16Flg == 1){ //rgb565 + short *pDest3 = (short *)((pSource - pRealBinBits) * 2 + pRealBinBits); + if (pDest3[j] == DEF_COLORKEY) + pDest2[j] = 0; + else pDest2[j] = pDest3[j]; + } + else if (NewColor16Flg == 2){ //rgba8888 +#define COLOR_TO_MTK_COLOR_SIMUL(color) ((((color) >> 19) & 0x1f) << 11) \ + | ((((color) >> 10) & 0x3f) << 5)\ + | (((color) >> 3) & 0x1f) + int *pDest3 = (int *)((pSource - pRealBinBits) * 4 + pRealBinBits); + if ((pDest3[j] & 0xFF000000) >> 24 == DEF_COLORKEY){ + pDest2[j] = 0; + alphatemp[i * 64 + j] = 0; + } + else{ + alphatemp[i * 64 + j] = (pDest3[j] & 0xFF000000) >> 24; + pDest2[j] = COLOR_TO_MTK_COLOR_SIMUL(pDest3[j]); + } + } +#endif + } + } + else //256ɫ + { + memcpy(pCache, pSource, sizeX); + } + } + else{ + memcpy(pDest, pSource, sizeX); + } + pSource -= bmpWidth; + + } + pDest += surfacePitch; + pCache += SurfaceSizeX; + } + if (lpSurface->Unlock(NULL) != DD_OK){ + return; + } +#else + LPDIRECTDRAWSURFACE lpSurface = surface_info->lpSurface; + DDSURFACEDESC ddsd; + char *pDest; //Ŀĵָ// + char *pSource; //Դָ// + BYTE *alphatemp; + int surfacePitch; //source face // + int bmpWidth; //bmpͼĿ// + int i; + + if( lpSurface == NULL ) return; + ZeroMemory( &ddsd, sizeof( DDSURFACEDESC ) ); + ddsd.dwSize = sizeof( DDSURFACEDESC ); + if( lpSurface->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ){ + return; + } + pDest = ( char *)( ddsd.lpSurface ); +#if 0 + pSource = ( char *)pBmpInfo + BmpOffBits + + offsetY * pBmpInfo->bmiHeader.biWidth + offsetX; +#else + pSource = pRealBinBits + + offsetY * RealBinWidth + offsetX; + if(NewColor16Flg==2 && displayBpp == 16){ + surface_info->lpAlphaData = (BYTE*)MALLOC(SurfaceSizeX*SurfaceSizeY); + memset(surface_info->lpAlphaData,0,SurfaceSizeX*SurfaceSizeY); + alphatemp = surface_info->lpAlphaData; + } +#endif + surfacePitch = ddsd.lPitch; +#if 0 + bmpWidth = pBmpInfo->bmiHeader.biWidth; +#else + bmpWidth = RealBinWidth; +#endif + if(ResoMode == 1){ + pSource -= bmpWidth; + sizeY >>= 1; + } + for( i = 0 ; i < sizeY ; i++ ){ + if(ResoMode == 1){ + _asm{ + mov edi,[pDest] + mov esi,[pSource] + mov eax,[sizeX] + shr ax,1 + mov cx,ax + inc esi + loop_100: + mov al,[esi] + mov [edi],al + inc esi + inc esi + inc edi + dec cx + jne loop_100 + } + pSource -= bmpWidth*2; + } else { +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + int j; + int pixel; + int * pDest2; + pDest2 = (int *)pDest; + for( j = 0; j < sizeX; j++ ){ +#ifdef _NEW_COLOR_ + if(NewColor16Flg==1){ + short *pDest3 = (short *)((pSource-pRealBinBits)*2+pRealBinBits); + if(pDest3[j]==DEF_COLORKEY) + pDest2[j] = 0; + else{ + pDest2[j] = (((pDest3[j]&0x001F)<<3)|((pDest3[j]&0x07E0 )<<5)|((pDest3[j]&0xF800 )<<8 )|0xFF000000 ); + } + }else if(NewColor16Flg==2){ + int *pDest3 = (int *)((pSource-pRealBinBits)*4+pRealBinBits); + if((pDest3[j] & 0xFF000000)>>24==DEF_COLORKEY) + pDest2[j] = 0; + else{ + pDest2[j] = pDest3[j]; + } + }else{ +#endif + if( pSource[j] == DEF_COLORKEY ){ + pDest2[j] = 0; + }else{ + pixel = highColor32Palette[(unsigned char)pSource[j]]; + if( pixel == 0 ){ + pDest2[j] = 1; + }else{ + pDest2[j] = pixel; + } + } +#ifdef _NEW_COLOR_ + } +#endif + } + }else +#endif + if( displayBpp == 16 ){ + int j; + short pixel; + short *pDest2 = (short *)pDest; + for( j = 0; j < sizeX; j++ ){ +#ifdef _NEW_COLOR_ + if(NewColor16Flg==1){ + short *pDest3 = (short *)((pSource-pRealBinBits)*2+pRealBinBits); + if(pDest3[j]==DEF_COLORKEY) + pDest2[j] = 0; + else pDest2[j] = pDest3[j]; + }else if(NewColor16Flg==2){ +#define COLOR_TO_MTK_COLOR_SIMUL(color) ((((color) >> 19) & 0x1f) << 11) \ + |((((color) >> 10) & 0x3f) << 5)\ + |(((color) >> 3) & 0x1f) + int *pDest3 = (int *)((pSource-pRealBinBits)*4+pRealBinBits); + if((pDest3[j] & 0xFF000000)>>24==DEF_COLORKEY){ + pDest2[j] = 0; + alphatemp[i*64+j]=0; + }else{ + alphatemp[i*64+j]=(pDest3[j] &0xFF000000)>>24; + pDest2[j] = COLOR_TO_MTK_COLOR_SIMUL(pDest3[j]); + } + }else{ +#endif + if( pSource[j] == DEF_COLORKEY ){ + pDest2[j] = 0; + }else{ + pixel = highColorPalette[(unsigned char)pSource[j]]; + if( pixel == 0 ){ + pDest2[j] = 1; + }else{ + pDest2[j] = pixel; + } + } +#ifdef _NEW_COLOR_ + } +#endif + } + + + + + + }else{ + memcpy( pDest, pSource, sizeX ); + } + pSource -= bmpWidth; + + } + pDest += surfacePitch; + } + if( lpSurface->Unlock( NULL ) != DD_OK ){ + return; + } + return; +#endif +} + +// ?????? **************************************************************/ +void DrawBox(RECT *rect, unsigned char color, BOOL fill) +{ + DDSURFACEDESC ddsd; // ??????Bl +#ifdef _READ16BITBMP + DDSURFACEDESC ddsdsys; + int surfacePitchsys,bottomSys; + surfacePitchsys = bottomSys = 0; + short *pDestSys; +#endif +#ifdef _HI_COLOR_32 + int *pDest32; +#ifdef _READ16BITBMP + int *pDestSys32; +#endif +#endif + char *pDest; // ?I????? + short *pDest2; // ?I??????????? + int surfacePitch; // ?????????? + int i, j; // ??????? + int bottom; // ?_???????? + int w; // ?? + int h; // ? + short pixel; // 16BitColor????ѩ + + //??????????????? + if (ResoMode == 1){ + rect->top = (rect->top >> 1) - 1; + rect->left = (rect->left >> 1) - 1; + rect->right = (rect->right >> 1) + 1; + rect->bottom = (rect->bottom >> 1) + 1; + } + + // ???????? + if (rect->left < 0) rect->left = 0; + if (rect->right >= lpDraw->xSize) rect->right = lpDraw->xSize; + if (rect->top < 0) rect->top = 0; + if (rect->bottom >= lpDraw->ySize) rect->bottom = lpDraw->ySize; + + w = rect->right - rect->left; + h = rect->bottom - rect->top; + + if (fill != 2 && (w <= 2 || h <= 2)) return; + if (fill == 2 && w == 0) return; + + // ?Bl???? + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + ZeroMemory(&ddsdsys,sizeof(DDSURFACEDESC)); + ddsdsys.dwSize = sizeof(DDSURFACEDESC); + } +#endif + + // ?????????????????( i?? ddsd ?ѩ?V????? ) + if (lpDraw->lpBACKBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK){ + //MessageBoxNew( hWnd, "Surfacelockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdsys,DDLOCK_WAIT,NULL) != DD_OK ){ + lpDraw->lpBACKBUFFER->Unlock(NULL); + return; + } + surfacePitchsys = ddsdsys.lPitch; + } +#endif + + // ?????????? + surfacePitch = ddsd.lPitch; + // D????????????? +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // 32 Bit Color + surfacePitch = surfacePitch >> 1; + pDest32 = (int *)ddsd.lpSurface + rect->top * surfacePitch + rect->left + 1; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + surfacePitchsys = surfacePitchsys >> 2; + pDestSys32 = (int *)ddsdsys.lpSurface + rect->top * surfacePitchsys + rect->left + 1; + } +#endif + } + else +#endif + if (displayBpp == 16){ + // 16 Bit Color + surfacePitch = surfacePitch >> 1; + pDest2 = (short *)ddsd.lpSurface + rect->top * surfacePitch + rect->left + 1; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + surfacePitchsys = surfacePitchsys >> 1; + pDestSys = (short*)ddsdsys.lpSurface + rect->top * surfacePitchsys + rect->left + 1; + } +#endif + } + else{ + // 8 Bit Color + pDest = (char *)(ddsd.lpSurface) + rect->top * surfacePitch + rect->left + 1; + } + // ??????? + if (fill == FALSE){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // 32 Bit Color + int pixel; + surfacePitch = surfacePitch >> 1; + pDest32 = (int *)ddsd.lpSurface + rect->top * surfacePitch + rect->left + 1; + // ?_????????գk + bottom = (h - 1) * surfacePitch; +#ifdef _READ16BITBMP + bottomSys = ( h - 1 ) * surfacePitchsys; +#endif + + pixel = highColor32Palette[color]; + + // ???? + for (i = 0; i < w - 2; i++){ + // ?_?? + *(pDest32 + i) = pixel; + *(pDest32 + surfacePitch + i) = pixel; + // ??_?? + *(pDest32 + bottom - surfacePitch + i) = pixel; + *(pDest32 + bottom + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys32 + i) = pixel; + *(pDestSys32 + surfacePitchsys + i) = pixel; + *(pDestSys32 + bottomSys - surfacePitchsys + i) = pixel; + *(pDestSys32 + bottomSys + i) = pixel; + } +#endif + } + + // D??? + *(pDest32 + surfacePitch + surfacePitch + 1) = pixel; // ? + *(pDest32 + surfacePitch + surfacePitch + w - 4) = pixel; // ? + *(pDest32 + bottom - (surfacePitch + surfacePitch) + 1) = pixel; // ?? + *(pDest32 + bottom - (surfacePitch + surfacePitch) + w - 4) = pixel; // ?? + + // ??????????????? + pDest32 += surfacePitch - 1; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys32 + surfacePitchsys + surfacePitchsys + 1) = pixel; + *(pDestSys32 + surfacePitchsys + surfacePitchsys + w - 4) = pixel; + *(pDestSys32 + bottomSys - ( surfacePitchsys + surfacePitchsys ) + 1) = pixel; + *(pDestSys32 + bottomSys - ( surfacePitchsys + surfacePitchsys ) + w - 4) = pixel; + pDestSys32 += surfacePitchsys - 1; + } +#endif + + // ??? + for (i = 0; i < h - 2; i++){ + // ??_?? + *pDest32 = pixel; + *(pDest32 + 1) = pixel; + // ??_?? + *(pDest32 + w - 1) = pixel; + *(pDest32 + w - 2) = pixel; + // ??????????????? + pDest32 += surfacePitch; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *pDestSys32 = pixel; + *(pDestSys32 + 1) = pixel; + *(pDestSys32 + w - 1) = pixel; + *(pDestSys32 + w - 2) = pixel; + pDestSys32 += surfacePitchsys; + } +#endif + } + } + else +#endif + if (displayBpp == 16){ + // 16 Bit Color + + // ?_????????գk + bottom = (h - 1) * surfacePitch; +#ifdef _READ16BITBMP + bottomSys = ( h - 1 ) * surfacePitchsys; +#endif + + pixel = highColorPalette[color]; + + // ???? + for (i = 0; i < w - 2; i++){ + // ?_?? + *(pDest2 + i) = pixel; + *(pDest2 + surfacePitch + i) = pixel; + // ??_?? + *(pDest2 + bottom - surfacePitch + i) = pixel; + *(pDest2 + bottom + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys + i) = pixel; + *(pDestSys + surfacePitchsys + i) = pixel; + *(pDestSys + bottomSys - surfacePitchsys + i) = pixel; + *(pDestSys + bottomSys + i) = pixel; + } +#endif + } + + // D??? + *(pDest2 + surfacePitch + surfacePitch + 1) = pixel; // ? + *(pDest2 + surfacePitch + surfacePitch + w - 4) = pixel; // ? + *(pDest2 + bottom - (surfacePitch + surfacePitch) + 1) = pixel; // ?? + *(pDest2 + bottom - (surfacePitch + surfacePitch) + w - 4) = pixel; // ?? + + // ??????????????? + pDest2 += surfacePitch - 1; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys + surfacePitchsys + surfacePitchsys + 1) = pixel; + *(pDestSys + surfacePitchsys + surfacePitchsys + w - 4) = pixel; + *(pDestSys + bottomSys - ( surfacePitchsys + surfacePitchsys ) + 1) = pixel; + *(pDestSys + bottomSys - ( surfacePitchsys + surfacePitchsys ) + w - 4) = pixel; + pDestSys += surfacePitchsys - 1; + } +#endif + + // ??? + for (i = 0; i < h - 2; i++){ + // ??_?? + *pDest2 = pixel; + *(pDest2 + 1) = pixel; + // ??_?? + *(pDest2 + w - 1) = pixel; + *(pDest2 + w - 2) = pixel; + // ??????????????? + pDest2 += surfacePitch; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *pDestSys = pixel; + *(pDestSys + 1) = pixel; + *(pDestSys + w - 1) = pixel; + *(pDestSys + w - 2) = pixel; + pDestSys += surfacePitchsys; + } +#endif + } + } + else{ + // 8 Bit Color + + // ?_??????? + bottom = (h - 1) * surfacePitch; + + // ???? + for (i = 0; i < w - 2; i++){ + // ?_?? + *(pDest + i) = color; + *(pDest + i + surfacePitch) = color; + // ??_?? + *(pDest + i + bottom) = color; + *(pDest + i + bottom - surfacePitch) = color; + } + + // D??? + *(pDest + surfacePitch + surfacePitch + 1) = color; // ? + *(pDest + surfacePitch + surfacePitch + w - 4) = color; // ? + *(pDest + bottom - (surfacePitch + surfacePitch) + 1) = color; // ?? + *(pDest + bottom - (surfacePitch + surfacePitch) + w - 4) = color; // ?? + + // ??????????????? + pDest += surfacePitch - 1; + + // ??? + for (i = 0; i < h - 2; i++){ + // ??_?? + *pDest = color; + *(pDest + 1) = color; + // ??_?? + *(pDest + w - 1) = color; + *(pDest + w - 2) = color; + // ??????????????? + pDest += surfacePitch; + } + } + } + else if (fill == 1){ // D?????? +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + int pixel; + surfacePitch = surfacePitch >> 1; + // 32 Bit Color + pDest32 = (int *)ddsd.lpSurface + rect->top * surfacePitch + rect->left + 1; + pixel = highColor32Palette[color]; + + // ??????? + for (i = 0; i < w - 2; i++){ + *(pDest32 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys32 + i) = pixel; + } +#endif + } + pDest32 += surfacePitch; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + pDestSys32 += surfacePitchsys; + } +#endif + for (i = 0; i < h - 2; i++){ + for (j = 0; j < w; j++){ + *(pDest32 + j) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys32+j) = pixel; +#endif + } + pDest32 += surfacePitch; +#ifdef _READ16BITBMP + if(g_bUseAlpha) pDestSys32 += surfacePitchsys; +#endif + } + pDest32++; +#ifdef _READ16BITBMP + if(g_bUseAlpha) pDestSys32++; +#endif + for (i = 0; i < w - 2; i++){ + *(pDest32 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys32 + i) = pixel; +#endif + } + } + else +#endif + if (displayBpp == 16){ + pixel = highColorPalette[color]; + for (i = 0; i < w - 2; i++){ + *(pDest2 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + *(pDestSys + i) = pixel; + } +#endif + } + pDest2 += surfacePitch - 1; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + pDestSys += surfacePitchsys - 1; + } +#endif + for (i = 0; i < h - 2; i++){ + for (j = 0; j < w; j++){ + *(pDest2 + j) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys+j) = pixel; +#endif + } + pDest2 += surfacePitch; +#ifdef _READ16BITBMP + if(g_bUseAlpha) pDestSys += surfacePitchsys; +#endif + } + pDest2++; +#ifdef _READ16BITBMP + if(g_bUseAlpha) pDestSys++; +#endif + for (i = 0; i < w - 2; i++){ + *(pDest2 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys + i) = pixel; +#endif + } + } + else{ + pDest++; + memset(pDest, color, w - 2); + pDest += surfacePitch - 1; + for (i = 0; i < h - 2; i++){ + memset(pDest, color, w); + pDest += surfacePitch; + } + memset(pDest + 1, color, w - 2); + } + } + else if (fill == 2){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + int pixel; + surfacePitch = surfacePitch >> 1; + pixel = highColor32Palette[color]; + pDest32 = (int *)ddsd.lpSurface + rect->top * surfacePitch + rect->left + 1; + for (i = 0; i < w; i++){ + *(pDest32 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys32 + i) = pixel; +#endif + } + } + else +#endif + if (displayBpp == 16){ + pixel = highColorPalette[color]; + for (i = 0; i < w; i++){ + *(pDest2 + i) = pixel; +#ifdef _READ16BITBMP + if(g_bUseAlpha) *(pDestSys + i) = pixel; +#endif + } + } + else{ + memset(pDest, color, w); + } + } + if (lpDraw->lpBACKBUFFER->Unlock(NULL) != DD_OK){ + return; + } +#ifdef _READ16BITBMP + if(g_bUseAlpha) if(lpDraw->lpBACKBUFFERSYS->Unlock(NULL) != DD_OK ) return; +#endif + + return; +} + +void DrawAutoMapping(int x, int y, unsigned char *autoMap, int w, int h) +{ + DDSURFACEDESC ddsd; // ??????Bl + char *ptDest; // ?I????? + char *tmpPtDest; // ??? + char *tmpPtDest2; // ???? + int surfacePitch; // ?????????? + int i, j; // ??????? + int color, pc_color; + static short pcFlush = 0; + static unsigned int pcFlushTime = 0; + int xx, yy; + int ww, hh; + int mul; + + xx = 18; + yy = 118; + ww = w; + hh = h; + mul = 1; + + //??????????????? + if (ResoMode == 1) + { + x = x / 2; + y = y / 2; + xx = xx / 2 + 1; + yy = yy / 2 - 1; + ww = ww / 2; + hh = hh / 2; + mul = 2; + } + + if (pcFlushTime + 1000 <= TimeGetTime()) + { + pcFlushTime = TimeGetTime(); + pcFlush++; + pcFlush &= 1; + } + if (pcFlush){ + pc_color = 255; + } + else{ + pc_color = 0; + } + // ?Bl???? + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + + // ?????????????????( i?? ddsd ?ѩ?V????? ) + if (lpDraw->lpBACKBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) + { + //MessageBoxNew( hWnd, "Surfacelockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } + // ?????????? + surfacePitch = ddsd.lPitch; + // D????????????? + ptDest = (char *)(ddsd.lpSurface) + (y + yy) * surfacePitch; + if (displayBpp == 8){ + ptDest += (x + xx); + tmpPtDest = ptDest; + tmpPtDest2 = ptDest; + for (i = 0; i < hh; i++){ + ptDest = tmpPtDest; + for (j = 0; j < ww; j++){ + color = autoMap[(i*mul)*w + (j*mul)]; + *(ptDest - 1) = color; + *(ptDest) = color; + *(ptDest + 1) = color; + *(ptDest - surfacePitch) = color; + ptDest -= (surfacePitch - 2); + } + tmpPtDest += (surfacePitch + 2); + } + ptDest = tmpPtDest2 + (surfacePitch + 2)*hh / 2 - (surfacePitch - 2)*ww / 2; + // ???????????????? + *(ptDest - 1) = pc_color; + *(ptDest) = pc_color; + *(ptDest + 1) = pc_color; + *(ptDest - surfacePitch) = pc_color; + } + else +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + ptDest += ((x + xx) << 2); + tmpPtDest = ptDest; + tmpPtDest2 = ptDest; + for (i = 0; i < hh; i++){ + ptDest = tmpPtDest; + for (j = 0; j < ww; j++){ + color = highColor32Palette[autoMap[(i*mul)*w + (j*mul)]]; + *(int *)(ptDest - 4) = color; + *(int *)(ptDest) = color; + *(int *)(ptDest + 4) = color; + *(int *)(ptDest - surfacePitch) = color; + ptDest -= (surfacePitch - 8); + } + tmpPtDest += (surfacePitch + 8); + } + ptDest = tmpPtDest2 + (surfacePitch + 4)*hh - (surfacePitch - 4)*ww; + color = highColor32Palette[pc_color]; + // ???????????????? + *(int *)(ptDest - 4) = color; + *(int *)(ptDest) = color; + *(int *)(ptDest + 4) = color; + *(int *)(ptDest - surfacePitch) = color; + } + else +#endif + if (displayBpp == 16){ + ptDest += ((x + xx) << 1); + tmpPtDest = ptDest; + tmpPtDest2 = ptDest; + for (i = 0; i < hh; i++){ + ptDest = tmpPtDest; + for (j = 0; j < ww; j++){ + color = highColorPalette[autoMap[(i*mul)*w + (j*mul)]]; + *(short*)(ptDest - 2) = color; + *(short*)(ptDest) = color; + *(short*)(ptDest + 2) = color; + *(short*)(ptDest - surfacePitch) = color; + ptDest -= (surfacePitch - 4); + } + tmpPtDest += (surfacePitch + 4); + } + ptDest = tmpPtDest2 + (surfacePitch + 4)*hh / 2 - (surfacePitch - 4)*ww / 2; + color = highColorPalette[pc_color]; + // ???????????????? + *(short*)(ptDest - 2) = color; + *(short*)(ptDest) = color; + *(short*)(ptDest + 2) = color; + *(short*)(ptDest - surfacePitch) = color; + } + + // ??????????????????? + if (lpDraw->lpBACKBUFFER->Unlock(NULL) != DD_OK) + { + //MessageBoxNew( hWnd, "SurfaceUnlockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } + + return; +} + + +// ????????????????? +int getAutoMapColor(unsigned int GraphicNo) +{ + int index = 0; + static int width, height; + static unsigned char *graBuf; + unsigned int red = 0, green = 0, blue = 0; + unsigned int cnt = 0; + int color; + + int i, j; + // real.bin?G?k?????????????? + if (realGetImage(GraphicNo, (unsigned char **)&graBuf, &width, &height) == FALSE) return 0; + // ??????Χ???? + for (i = 0; i < height; i++){ + for (j = 0; j < width; j++){ + index = graBuf[i*width + j]; + if (index != DEF_COLORKEY){ // a??????? + red += Palette[index].peRed; + green += Palette[index].peGreen; + blue += Palette[index].peBlue; + cnt++; + } + } + } + + if (cnt == 0) return 0; + // ???k??????????????S? + color = getNearestColorIndex(RGB(red / cnt, green / cnt, blue / cnt), Palette, 256); + + return color; +} + +//---------------------------------------------------------------------------// +// ?entry?????palette?????color??k?????index??? +//---------------------------------------------------------------------------// +//ref Ѱɫӽɫ +int getNearestColorIndex(COLORREF color, PALETTEENTRY *palette, int entry) +{ + double distance, mindist; + int min_index; + int i; + mindist = (palette[0].peRed - GetRValue(color))*(palette[0].peRed - GetRValue(color)) + + (palette[0].peGreen - GetGValue(color))*(palette[0].peGreen - GetGValue(color)) + + (palette[0].peBlue - GetBValue(color))*(palette[0].peBlue - GetBValue(color)); + min_index = 0; + for (i = 16; i < entry - 16; i++){ + distance = (palette[i].peRed - GetRValue(color))*(palette[i].peRed - GetRValue(color)) + + (palette[i].peGreen - GetGValue(color))*(palette[i].peGreen - GetGValue(color)) + + (palette[i].peBlue - GetBValue(color))*(palette[i].peBlue - GetBValue(color)); + if (distance < mindist){ + min_index = i; + mindist = distance; + } + } + return min_index; +} + + + +//---------------------------------------------------------------------------// +// ?????????? // +//---------------------------------------------------------------------------// +//ref ͼЧ +void DrawMapEffect(void) +{ + DDSURFACEDESC ddsd; + char *ptDest; + short *ptDest2; +#ifdef _HI_COLOR_32 + int *ptDest32; +#endif + int surfacePitch; + int ww, hh; + MAP_EFFECT *buf; + char color; + int i, j; + + ww = DEF_APPSIZEX; + hh = DEF_APPSIZEY; + //??????????????? + if (ResoMode == 1){ + ww >>= 1; + hh >>= 1; + } + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + if (lpDraw->lpBACKBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) + return; +#ifdef _HI_COLOR_32 + if (displayBpp == 32) + surfacePitch = ddsd.lPitch >> 2; +#endif + if (displayBpp == 16) + surfacePitch = ddsd.lPitch >> 1; + buf = useBufMapEffect; + while (buf != (MAP_EFFECT *)NULL){ + if (0 < buf->x && buf->x < ww - 4 && 0 < buf->y && buf->y < hh - 12){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + ptDest32 = (int *)(ddsd.lpSurface) + buf->y * surfacePitch + buf->x; + } + else +#endif + if (displayBpp == 16) + ptDest2 = (short *)(ddsd.lpSurface) + buf->y * surfacePitch + buf->x; + else + ptDest = (char *)(ddsd.lpSurface) + buf->y * surfacePitch + buf->x; + if (buf->type == MAP_EFFECT_TYPE_RAIN){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + *(ptDest32) = highColor32Palette[143]; + *(ptDest32 + surfacePitch) = highColor32Palette[143]; + *(ptDest32 + surfacePitch * 2 + 1) = highColor32Palette[143]; + *(ptDest32 + surfacePitch * 3 + 1) = highColor32Palette[143]; + } + else +#endif + if (displayBpp == 16){ + *(ptDest2) = highColorPalette[143]; + *(ptDest2 + surfacePitch) = highColorPalette[143]; + *(ptDest2 + surfacePitch * 2 + 1) = highColorPalette[143]; + *(ptDest2 + surfacePitch * 3 + 1) = highColorPalette[143]; + } + else{ + *(ptDest) = (char)143; + *(ptDest + surfacePitch) = (char)143; + *(ptDest + surfacePitch * 2 + 1) = (char)143; + *(ptDest + surfacePitch * 3 + 1) = (char)143; + } + } + else if (buf->type == MAP_EFFECT_TYPE_SNOW){ + if (buf->mode == 0){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + *(ptDest32) = highColor32Palette[161]; + *(ptDest32 + 1) = highColor32Palette[159]; + *(ptDest32 + 2) = highColor32Palette[161]; + *(ptDest32 + surfacePitch) = highColor32Palette[159]; + *(ptDest32 + surfacePitch + 1) = highColor32Palette[159]; + *(ptDest32 + surfacePitch + 2) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2) = highColor32Palette[161]; + *(ptDest32 + surfacePitch * 2 + 1) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2 + 2) = highColor32Palette[161]; + } + else +#endif + if (displayBpp == 16){ + *(ptDest2) = highColorPalette[161]; + *(ptDest2 + 1) = highColorPalette[159]; + *(ptDest2 + 2) = highColorPalette[161]; + *(ptDest2 + surfacePitch) = highColorPalette[159]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[159]; + *(ptDest2 + surfacePitch + 2) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2) = highColorPalette[161]; + *(ptDest2 + surfacePitch * 2 + 1) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2 + 2) = highColorPalette[161]; + } + else{ + *(ptDest) = (char)161; + *(ptDest + 1) = (char)159; + *(ptDest + 2) = (char)161; + *(ptDest + surfacePitch) = (char)159; + *(ptDest + surfacePitch + 1) = (char)159; + *(ptDest + surfacePitch + 2) = (char)159; + *(ptDest + surfacePitch * 2) = (char)161; + *(ptDest + surfacePitch * 2 + 1) = (char)159; + *(ptDest + surfacePitch * 2 + 2) = (char)161; + } + } + else if (buf->mode == 1){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + *(ptDest32) = highColor32Palette[162]; + *(ptDest32 + 1) = highColor32Palette[159]; + *(ptDest32 + 2) = highColor32Palette[159]; + *(ptDest32 + 3) = highColor32Palette[162]; + *(ptDest32 + surfacePitch) = highColor32Palette[159]; + *(ptDest32 + surfacePitch + 1) = highColor32Palette[159]; + *(ptDest32 + surfacePitch + 2) = highColor32Palette[159]; + *(ptDest32 + surfacePitch + 3) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2 + 1) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2 + 2) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 2 + 3) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 3) = highColor32Palette[162]; + *(ptDest32 + surfacePitch * 3 + 1) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 3 + 2) = highColor32Palette[159]; + *(ptDest32 + surfacePitch * 3 + 3) = highColor32Palette[162]; + } + else +#endif + if (displayBpp == 16){ + *(ptDest2) = highColorPalette[162]; + *(ptDest2 + 1) = highColorPalette[159]; + *(ptDest2 + 2) = highColorPalette[159]; + *(ptDest2 + 3) = highColorPalette[162]; + *(ptDest2 + surfacePitch) = highColorPalette[159]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[159]; + *(ptDest2 + surfacePitch + 2) = highColorPalette[159]; + *(ptDest2 + surfacePitch + 3) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2 + 1) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2 + 2) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 2 + 3) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 3) = highColorPalette[162]; + *(ptDest2 + surfacePitch * 3 + 1) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 3 + 2) = highColorPalette[159]; + *(ptDest2 + surfacePitch * 3 + 3) = highColorPalette[162]; + } + else{ + *(ptDest) = (char)162; + *(ptDest + 1) = (char)159; + *(ptDest + 2) = (char)159; + *(ptDest + 3) = (char)162; + *(ptDest + surfacePitch) = (char)159; + *(ptDest + surfacePitch + 1) = (char)159; + *(ptDest + surfacePitch + 2) = (char)159; + *(ptDest + surfacePitch + 3) = (char)159; + *(ptDest + surfacePitch * 2) = (char)159; + *(ptDest + surfacePitch * 2 + 1) = (char)159; + *(ptDest + surfacePitch * 2 + 2) = (char)159; + *(ptDest + surfacePitch * 2 + 3) = (char)159; + *(ptDest + surfacePitch * 3) = (char)162; + *(ptDest + surfacePitch * 3 + 1) = (char)159; + *(ptDest + surfacePitch * 3 + 2) = (char)159; + *(ptDest + surfacePitch * 3 + 3) = (char)162; + } + } + } + else if (buf->type == MAP_EFFECT_TYPE_STAR){ + if (buf->mode == 0){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ????? + *(ptDest32 - surfacePitch - 1) = highColor32Palette[8]; + *(ptDest32 - surfacePitch) = highColor32Palette[255]; + *(ptDest32 - surfacePitch + 1) = highColor32Palette[8]; + *(ptDest32 - 1) = highColor32Palette[255]; + *(ptDest32) = highColor32Palette[255]; + *(ptDest32 + 1) = highColorPalette[255]; + *(ptDest32 + surfacePitch - 2) = highColor32Palette[8]; + *(ptDest32 + surfacePitch) = highColor32Palette[255]; + *(ptDest32 + surfacePitch + 2) = highColor32Palette[8]; + } + else +#endif + if (displayBpp == 16){ + // ????? + *(ptDest2 - surfacePitch - 1) = highColorPalette[8]; + *(ptDest2 - surfacePitch) = highColorPalette[255]; + *(ptDest2 - surfacePitch + 1) = highColorPalette[8]; + *(ptDest2 - 1) = highColorPalette[255]; + *(ptDest2) = highColorPalette[255]; + *(ptDest2 + 1) = highColorPalette[255]; + *(ptDest2 + surfacePitch - 1) = highColorPalette[8]; + *(ptDest2 + surfacePitch) = highColorPalette[255]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[8]; + } + else{ + // ????? + *(ptDest - surfacePitch - 1) = (char)8; + *(ptDest - surfacePitch) = (char)255; + *(ptDest - surfacePitch + 1) = (char)8; + *(ptDest - 1) = (char)255; + *(ptDest) = (char)255; + *(ptDest + 1) = (char)255; + *(ptDest + surfacePitch - 1) = (char)8; + *(ptDest + surfacePitch) = (char)255; + *(ptDest + surfacePitch + 1) = (char)8; + } + } + else if (buf->mode == 1){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ????? + *(ptDest32 - surfacePitch) = highColor32Palette[251]; + *(ptDest32 - 1) = highColor32Palette[251]; + *(ptDest32) = highColor32Palette[251]; + *(ptDest32 + 1) = highColor32Palette[251]; + *(ptDest32 + surfacePitch) = highColor32Palette[251]; + } + else +#endif + if (displayBpp == 16){ + // ????? + *(ptDest2 - surfacePitch) = highColorPalette[251]; + *(ptDest2 - 1) = highColorPalette[251]; + *(ptDest2) = highColorPalette[251]; + *(ptDest2 + 1) = highColorPalette[251]; + *(ptDest2 + surfacePitch) = highColorPalette[251]; + } + else{ + // ????? + *(ptDest - surfacePitch) = (char)251; + *(ptDest - 1) = (char)251; + *(ptDest) = (char)251; + *(ptDest + 1) = (char)251; + *(ptDest + surfacePitch) = (char)251; + } + } + else if (buf->mode == 2){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ??????? + *(ptDest32) = highColor32Palette[251]; + *(ptDest32 + 1) = highColor32Palette[255]; + *(ptDest32 + surfacePitch) = highColor32Palette[255]; + *(ptDest32 + surfacePitch + 1) = highColor32Palette[251]; + } + else +#endif + if (displayBpp == 16){ + // ??????? + *(ptDest2) = highColorPalette[251]; + *(ptDest2 + 1) = highColorPalette[255]; + *(ptDest2 + surfacePitch) = highColorPalette[255]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[251]; + } + else{ + // ??????? + *(ptDest) = (char)251; + *(ptDest + 1) = (char)255; + *(ptDest + surfacePitch) = (char)255; + *(ptDest + surfacePitch + 1) = (char)251; + } + } + else if (buf->mode == 3){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ??????? + *(ptDest32) = highColor32Palette[255]; + *(ptDest32 + 1) = highColor32Palette[251]; + *(ptDest32 + surfacePitch) = highColor32Palette[251]; + *(ptDest32 + surfacePitch + 1) = highColor32Palette[255]; + } + else +#endif + if (displayBpp == 16){ + // ??????? + *(ptDest2) = highColorPalette[255]; + *(ptDest2 + 1) = highColorPalette[251]; + *(ptDest2 + surfacePitch) = highColorPalette[251]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[255]; + } + else{ + // ??????? + *(ptDest) = (char)255; + *(ptDest + 1) = (char)251; + *(ptDest + surfacePitch) = (char)251; + *(ptDest + surfacePitch + 1) = (char)255; + } + } + else if (buf->mode == 4){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ??????? + *(ptDest32) = highColor32Palette[251]; + *(ptDest32 + 1) = highColor32Palette[193]; + *(ptDest32 + surfacePitch) = highColor32Palette[193]; + *(ptDest32 + surfacePitch + 1) = highColor32Palette[193]; + } + else +#endif + if (displayBpp == 16){ + // ??????? + *(ptDest2) = highColorPalette[251]; + *(ptDest2 + 1) = highColorPalette[193]; + *(ptDest2 + surfacePitch) = highColorPalette[193]; + *(ptDest2 + surfacePitch + 1) = highColorPalette[193]; + } + else{ + // ??????? + *(ptDest) = (char)251; + *(ptDest + 1) = (char)193; + *(ptDest + surfacePitch) = (char)193; + *(ptDest + surfacePitch + 1) = (char)193; + } + } + else if (buf->mode == 5){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ????? + *(ptDest32) = highColor32Palette[198]; + } + else +#endif + if (displayBpp == 16){ + // ????? + *(ptDest2) = highColorPalette[198]; + } + else{ + // ????? + *(ptDest) = (char)198; + } + } + else if (buf->mode == 6){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ????? + *(ptDest32) = highColor32Palette[193]; + } + else +#endif + if (displayBpp == 16){ + // ????? + *(ptDest2) = highColorPalette[193]; + } + else{ + // ????? + *(ptDest) = (char)193; + } + } + else if (buf->mode == 7){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ????? + *(ptDest32) = highColor32Palette[208]; + } + else +#endif + if (displayBpp == 16){ + // ????? + *(ptDest2) = highColorPalette[208]; + } + else{ + // ????? + *(ptDest) = (char)208; + } + } + else if (buf->mode == 8){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + // ??? + *(ptDest32) = highColor32Palette[251]; + } + else +#endif + if (displayBpp == 16){ + // ??? + *(ptDest2) = highColorPalette[251]; + } + else{ + // ??? + *(ptDest) = (char)251; + } + } + } + else if (buf->type == MAP_EFFECT_TYPE_KAMIFUBUKI){ + // ???? + if (buf->mode == 0){ + if (buf->type2 == 0) + color = (char)223; + else if (buf->type2 == 1) + color = (char)217; + else + color = (char)159; + } + else if (buf->mode == 1){ + if (buf->type2 == 0) + color = (char)212; + else if (buf->type2 == 1) + color = (char)208; + else + color = (char)159; + } + else if (buf->mode == 2){ + if (buf->type2 == 0) + color = (char)130; + else if (buf->type2 == 1) + color = (char)147; + else + color = (char)159; + } + else{ + if (buf->type2 == 0) + color = (char)116; + else if (buf->type2 == 1) + color = (char)99; + else + color = (char)159; + } + for (i = 0; i < buf->h; i++){ + for (j = 0; j < buf->w; j++){ + if (0 <= (buf->ex + j) && (buf->ex + j) < ww && 0 <= (buf->ey + i) && (buf->ey + i) < hh){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + *(ptDest32 + surfacePitch*(i + buf->ey) + j + buf->ex) = highColor32Palette[(unsigned char)color]; + } + else +#endif + if (displayBpp == 16) + *(ptDest2 + surfacePitch*(i + buf->ey) + j + buf->ex) = highColorPalette[(unsigned char)color]; + else + *(ptDest + surfacePitch*(i + buf->ey) + j + buf->ex) = color; + } + } + } + } + else if (buf->type == MAP_EFFECT_TYPE_HOTARU){ + } + } + buf = buf->next; + } + if (lpDraw->lpBACKBUFFER->Unlock(NULL) != DD_OK) + return; + return; +} + + + + + + +// ???????????? ????? ?************************************/ +void DrawDebugLine(unsigned char color) +{ + DDSURFACEDESC ddsd; // ??????Bl + char *pDest; // ?I????? + short *pDest2; // ?I??????????? + int surfacePitch; // ?????????? + int i, j, k, l, m; + short pixel; + + // ???????????? + if (WindowMode) return; + + // ?Bl???? + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + + // ?????????????????( i?? ddsd ?ѩ?V????? ) + if (lpDraw->lpFRONTBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK){ + //MessageBoxNew( hWnd, "Surfacelockʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); + return; + } + //?? + j = lpDraw->xSize; + k = lpDraw->ySize; + l = 8; + //??????????????? + if (ResoMode == 1){ + j >>= 1; + k >>= 1; + l >>= 1; + } +#ifdef _HI_COLOR_32 + if (displayBpp == 32) + { + int pixel; + int *pDest32; + pixel = highColor32Palette[color]; + // D????????????? + pDest32 = (int *)ddsd.lpSurface + j; + // ?????????? + surfacePitch = ddsd.lPitch >> 1; + // ??? + for (i = 0; i < k; i++) + { + // ?????? + for (m = 0; m < l; m++) + { + *(pDest32 + m) = pixel; + } + // ??????????????? + pDest32 += surfacePitch; + } + } + else +#endif + if (displayBpp == 16) + { + pixel = highColorPalette[color]; + // D????????????? + pDest2 = (short *)ddsd.lpSurface + j; + // ?????????? + surfacePitch = ddsd.lPitch >> 1; + // ??? + for (i = 0; i < k; i++) + { + // ?????? + for (m = 0; m < l; m++) + { + *(pDest2 + m) = pixel; + } + // ??????????????? + pDest2 += surfacePitch; + } + } + else + { + // D????????????? + pDest = (char *)(ddsd.lpSurface) + j; + + // ?????????? + surfacePitch = ddsd.lPitch; + + // ??? + for (i = 0; i < k; i++) + { + // ?????? + memset(pDest, color, l); + // ??????????????? + pDest += surfacePitch; + } + } + + // ??????????????????? + if (lpDraw->lpFRONTBUFFER->Unlock(NULL) != DD_OK){ + MessageBoxNew(hWnd, "SurfaceUnlockʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return; + } + + return; +} +//---------------------------------------------------------------------------// +// ?? RECT???qֱ??վϐD????]? // +// ?? DIRECT_DRAW *lpDraw : DirectDraw???Bl // +// short bx : ?I??t // +// short by : ?I?t // +// LPDIRECTDRAWSURFACE lpSurface : ??????? // +// ?k DD_OK:? // +//---------------------------------------------------------------------------// +#ifdef _READ16BITBMP +HRESULT DrawSurfaceFast( long bx, long by, LPDIRECTDRAWSURFACE lpSurface,LPDIRECTDRAWSURFACE lpSurfaceSys) +{ + long x0, y0; + long w, h; + + RECT rect = { 0, 0, SurfaceSizeX, SurfaceSizeY }; + x0 = bx; + y0 = by; + w = rect.right - rect.left; + h = rect.bottom - rect.top; + + if( bx >= lpDraw->xSize || bx + w <= 0 || by >= lpDraw->ySize || by + h <= 0 ){ + return DD_OK; + } + + // ?Z????? + if( bx < 0 ){ + rect.left -= bx; + x0 = 0; + } + // ?Z????? + if( bx + w > lpDraw->xSize ){ + rect.right -= bx + w - lpDraw->xSize; + } + // ƣZ????? + if( by < 0 ){ + rect.top -= by; + y0 = 0; + } + // ?Z????? + if( by + h > lpDraw->ySize ){ + rect.bottom -= by + h - lpDraw->ySize; + } + +#ifdef _STONDEBUG_ + // ????????????????? + SurfaceDispCnt++; +#endif + RECT rectD; + + rectD.left = x0; + rectD.top = y0; + rectD.right = x0 + (rect.right - rect.left); + rectD.bottom = y0 + (rect.bottom - rect.top); + lpDraw->lpBACKBUFFERSYS->Blt(&rectD,lpSurfaceSys,&rect,DDBLT_KEYSRC | DDBLT_WAIT,NULL); + return lpDraw->lpBACKBUFFER->Blt(&rectD,lpSurface,&rect,DDBLT_KEYSRC | DDBLT_WAIT,NULL); +} +#endif + +HRESULT DrawSurfaceFast(short bx, short by, LPDIRECTDRAWSURFACE lpSurface) +{ + short x0, y0; + long w, h; + RECT rect = { 0, 0, SurfaceSizeX, SurfaceSizeY }; + x0 = bx; + y0 = by; + w = rect.right - rect.left; + h = rect.bottom - rect.top; + if (bx >= lpDraw->xSize || bx + w <= 0 || by >= lpDraw->ySize || by + h <= 0){ + return DD_OK; + } + if (bx < 0){ + rect.left -= bx; + x0 = 0; + } + if (bx + w > lpDraw->xSize){ + rect.right -= bx + w - lpDraw->xSize; + } + if (by < 0){ + rect.top -= by; + y0 = 0; + } + if (by + h > lpDraw->ySize){ + rect.bottom -= by + h - lpDraw->ySize; + } + +#ifdef _STONDEBUG_ + SurfaceDispCnt++; +#endif + RECT rectD; + + rectD.left = x0; + rectD.top = y0; + rectD.right = x0 + (rect.right - rect.left); + rectD.bottom = y0 + (rect.bottom - rect.top); + return lpDraw->lpBACKBUFFER->Blt(&rectD, lpSurface, &rect, DDBLT_KEYSRC | DDBLT_WAIT, NULL); +} + +//---------------------------------------------------------------------------// +// ?? RECT???qֱ??վϐD????]? // +// ?? DIRECT_DRAW *lpDraw : DirectDraw???Bl // +// short bx : ?I??t // +// short by : ?I?t // +// RECT * rect : ?????Bl // +// LPDIRECTDRAWSURFACE lpSurface : ??????? // +// ?k DD_OK:? // +//---------------------------------------------------------------------------// +HRESULT DrawSurfaceFast2(short bx, short by, RECT *rect, LPDIRECTDRAWSURFACE lpSurface) +{ + short x0, y0; + long w, h; + + x0 = bx; + y0 = by; + w = rect->right - rect->left; + h = rect->bottom - rect->top; + + // ???????? + // ????? RECT ?????????????? + + // u?????????? + if (bx >= lpDraw->xSize || bx + w <= 0 || by >= lpDraw->ySize || by + h <= 0){ + return DD_OK; + } + + // ?Z????? + if (bx < 0){ + rect->left -= bx; + x0 = 0; + } + // ?Z????? + if (bx + w > lpDraw->xSize){ + rect->right -= bx + w - lpDraw->xSize; + } + // ƣZ????? + if (by < 0){ + rect->top -= by; + y0 = 0; + } + // ?Z????? + if (by + h > lpDraw->ySize){ + rect->bottom -= by + h - lpDraw->ySize; + } + +#ifdef _STONDEBUG_ + // ????????????????? + SurfaceDispCnt++; +#endif + + // ??????????L? + //return lpDraw->lpBACKBUFFER->BltFast( x0, y0, lpSurface, rect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); + return lpDraw->lpBACKBUFFER->BltFast(x0, y0, lpSurface, rect, DDBLTFAST_WAIT); +} + + +/* ?????????? ****************************************************/ +void ReleaseDirectDraw(void) +{ + int i; + // u???????????????? + for (i = 0; i < SurfaceCnt; i++){ + if (SurfaceInfo[i].lpSurface != NULL){ + if (SurfaceInfo[i].lpAlphaData != NULL){ + FREE(SurfaceInfo[i].lpAlphaData); + SurfaceInfo[i].lpAlphaData = NULL; + } + SurfaceInfo[i].lpSurface->Release(); + SurfaceInfo[i].lpSurface = NULL; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + SurfaceInfoSys[i].lpSurface->Release(); + SurfaceInfoSys[i].lpSurface = NULL; + } +#endif + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if(SurfaceInfo[i].lpAlphaData != NULL){ + FREE(SurfaceInfo[i].lpAlphaData); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + SurfaceInfo[i].lpAlphaData = NULL; + } + } +#endif + } +#ifdef __SKYISLAND + extern void SkyIslandRelease(); + SkyIslandRelease(); +#endif + // ?????????? + if (lpBattleSurface != NULL){ + // ???? + lpBattleSurface->Release(); + lpBattleSurface = NULL; + } + if (lpDraw){ + // ????? + if (lpDraw->lpPALETTE != NULL){ + lpDraw->lpPALETTE->Release(); + lpDraw->lpPALETTE = NULL; + } + // ?????? + if (lpDraw->lpCLIPPER != NULL){ + lpDraw->lpCLIPPER->Release(); + lpDraw->lpCLIPPER = NULL; + } + // ????????? + if (lpDraw->lpBACKBUFFER != NULL){ + lpDraw->lpBACKBUFFER->Release(); + lpDraw->lpBACKBUFFER = NULL; + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if(lpDraw->lpBACKBUFFERSYS != NULL){ + lpDraw->lpBACKBUFFERSYS->Release(); + lpDraw->lpBACKBUFFERSYS = NULL; + } + if(lpBattleSurfaceSys != NULL){ + lpBattleSurfaceSys->Release(); + lpBattleSurfaceSys = NULL; + } + } +#endif + // ??????????? + if (lpDraw->lpFRONTBUFFER != NULL){ + lpDraw->lpFRONTBUFFER->Release(); + lpDraw->lpFRONTBUFFER = NULL; + } + // DirectDraw?? + if (lpDraw->lpDD2 != NULL){ + lpDraw->lpDD2->Release(); + lpDraw->lpDD2 = NULL; + } + + // DIRECT_DRAW ?Bl? + HeapFree(GetProcessHeap(), NULL, lpDraw); + lpDraw = NULL; + } + // DirectDraw ??????? FALSE ??? + DDinitFlag = FALSE; +} + +// ??????????????? //////////////////////////////////////////// +BOOL CheckSurfaceLost(void) +{ + BOOL SurfaceLostFlag = FALSE; + int i; + // u????????????????? + for (i = 0; i < SurfaceCnt; i++){ + // ?????????? + if (SurfaceInfo[i].lpSurface != NULL){ + // ???????????????? +#ifdef _READ16BITBMP + if(g_bUseAlpha) + if(SurfaceInfoSys[i].lpSurface->IsLost()) SurfaceLostFlag = TRUE; +#endif + if (SurfaceInfo[i].lpSurface->IsLost()) SurfaceLostFlag = TRUE; + } + } + // ??????????? + if (lpBattleSurface != NULL){ + // ???? + if (lpBattleSurface->IsLost()){ + SurfaceLostFlag = TRUE; + } + } +#ifdef __SKYISLAND +#ifndef __CARYTEST + extern BOOL SkyIslandCheckSurface(); + if (SkyIslandCheckSurface()) + SurfaceLostFlag = TRUE; +#endif +#endif + // ?????????? + if (lpDraw->lpBACKBUFFER != NULL){ + // ???????????????? + if (lpDraw->lpBACKBUFFER->IsLost()){ + SurfaceLostFlag = TRUE; + } + } + // ???????????? + if (lpDraw->lpFRONTBUFFER != NULL){ + // ???????????????? + if (lpDraw->lpFRONTBUFFER->IsLost()){ + SurfaceLostFlag = TRUE; + } + } + + return SurfaceLostFlag; +} + +// ???????????? *************************************************/ +void InitFont(int fontNo) +{ + // + //char *fontName[] = { "Microsoft JhengHei","_GB2312" }; +#ifdef _NEWFONT_ + extern int ; + char fontName[2][128]; + if(==950){ + sprintf(fontName[0],"Microsoft JhengHei"); + sprintf(fontName[1],"Microsoft JhengHei"); + }else{ + sprintf(fontName[0],"Microsoft JhengHei"); + sprintf(fontName[1],"Microsoft JhengHei"); + } +#else + extern int ; + char fontName[2][128]; + if(==950){ + sprintf(fontName[0],"Microsoft JhengHei"); + sprintf(fontName[1],"Microsoft JhengHei"); + }else{ + sprintf(fontName[0],""); + sprintf(fontName[1],"_GB2312"); + } + + //char *fontName[] = { "", "_GB2312" }; +#endif + // ????????? + if (hFont != NULL){ + // ???????????? + DeleteObject(hFont); + } + + //??????????????? + if (ResoMode == 1){ + // MS??????e???????????????? + hFont = CreateFont( +#ifdef _NEWFONT_ + FONT_SIZE1, /* ???????? */ +#else + FONT_SIZE1, +#endif + 0, /* ?????? */ + 0, /* ???????T */ + 0, /* ??? ????x??T */ + /* ?????^? */ + FW_NORMAL, // 0 + /* ?????lN???? */ + FALSE, + /* ?_?N???? */ + FALSE, + /* e??_?N???? */ + FALSE, + /* ???? */ + GB2312_CHARSET/*CHINESEBIG5_CHARSET*/, // ?G?? GB2312_CHARSET + /* ?ڥT */ + OUT_DEFAULT_PRECIS, + /* ??????ڥT */ + CLIP_DEFAULT_PRECIS, + /* ? */ + DEFAULT_QUALITY, // ???????????????? + /* ??? */ + FIXED_PITCH | + /* ???? */ + FF_ROMAN, // ???????????????????????MS(R) Serif???????? + fontName[fontNo]); + } + else { +#ifdef _NEWFONT_ + char strfame[128]; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + }else{ + sprintf(strfame,"Microsoft JhengHei"); + } + hFont = CreateFont(FONT_SIZE1,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame + ); +#else + + char strfame[128]; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + hFont = CreateFont(FONT_SIZE2,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame + ); + }else{ + hFont = CreateFont( + FONT_SIZE1, + 0, + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + GB2312_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FIXED_PITCH | + FF_ROMAN, + fontName[fontNo]); + } +#endif + } +} + +#ifdef _CHANNEL_MODIFY +char g_szChannelTitle[][13] = { "[]", "[]", "[]", "[]" +#ifdef _CHAR_PROFESSION +,"[ְ]" +#endif +#ifdef _CHATROOMPROTOCOL +,"[]" +#endif +#ifdef _CHANNEL_WORLD +, "[]" +#endif +#ifdef _CHANNEL_ALL_SERV +, "[]" +#endif +}; +extern int TalkMode; +#endif +// ????????????????? //////////////////////////////////////// +void PutText(char fontPrio) +{ + HDC hDc; +#ifdef _READ16BITBMP + HDC hDcSys; +#endif + int i; + BOOL colorFlag = FALSE; + int color; + if (FontCnt == 0) return; + lpDraw->lpBACKBUFFER->GetDC(&hDc); +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->GetDC(&hDcSys); +#endif + SetBkMode(hDc, TRANSPARENT); +#ifdef _READ16BITBMP + if(g_bUseAlpha) SetBkMode(hDcSys,TRANSPARENT); +#endif + HFONT hOldFont = (HFONT)SelectObject(hDc, hFont); +#ifdef _READ16BITBMP + if(g_bUseAlpha) SelectObject(hDcSys,hFont); +#endif + SetTextColor(hDc, 0); +#ifdef _READ16BITBMP + if(g_bUseAlpha) SetTextColor(hDcSys,0); +#endif + for (i = 0; i < FontCnt; i++){ + if (FontBuffer[i].fontPrio == fontPrio){ + if (ResoMode == 1){ + TextOut(hDc, FontBuffer[i].x / 2 + 1, FontBuffer[i].y / 2 + 1, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); + } + else { +#ifdef _FONT_SIZE + static HFONT newFont = NULL; + static HFONT oldFont = NULL; + if (newFont != NULL) { + DeleteObject(newFont); + } + if (FontBuffer[i].size <= 0) + SelectObject(hDc, hFont); + else { + newFont = CreateNewFont(FontBuffer[i].size); + if (newFont != NULL) + oldFont = (HFONT)SelectObject(hDc, newFont); + } +#endif +#ifndef _CHANNEL_MODIFY + TextOut( hDc, FontBuffer[ i ].x + 1, FontBuffer[ i ].y + 1, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1, FontBuffer[ i ].y + 1, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif +#else + if (FontBuffer[i].fontPrio != FONT_PRIO_CHATBUFFER){ +#ifdef _FONT_PARAGRAPH_COLOR + char *s = FontBuffer[ i ].str; + int x = 0; + int len = 0; + while(char *ss = strstr(s, "/")){ + ss ++; + len = ss - s - 1; + if(ss[0] >= 'a' && ss[0] <= 'z'){ + ss++; + }else{ + len++; + } + TextOut( hDc, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, len); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y + 1, s, len); + } +#endif + s = ss; + x += len; + } + TextOut( hDc, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#endif +#else + TextOut(hDc, FontBuffer[i].x + 1, FontBuffer[i].y + 1, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1, FontBuffer[ i ].y + 1, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif +#endif + } + else{ +#ifdef _TALK_WINDOW + if(g_bTalkWindow) { + break; + } +#endif + +#ifdef _FONT_PARAGRAPH_COLOR + char *s = FontBuffer[ i ].str; + int x = 0; + int len = 0; + while(char *ss = strstr(s, "/")){ + ss ++; + len = ss - s - 1; + + if(ss[0] < 'a' || ss[0] > 'z'){ + len--; + } + if(false){ + TextOut( hDc, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, len + 2); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, len + 2); +#endif + } + else{ + TextOut( hDc, FontBuffer[ i ].x + 1 + 22 + x * 7, FontBuffer[ i ].y + 1, s, len + 2); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1 + 22 + x * 7, FontBuffer[ i ].y + 1, s, len + 2); +#endif + } + if(ss[0] >= 'a' && ss[0] <= 'z'){ + ss++; + } + s = ss; + x += len + 2; + } + + if(false){ + TextOut( hDc, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1 + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#endif + } + else{ + TextOut( hDc, FontBuffer[ i ].x + 1 + 22 + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1 + 22 + x * 7, FontBuffer[ i ].y + 1, s, strlen(s)); +#endif + } +#else + + if (false){ + TextOut(hDc, FontBuffer[i].x + 1, FontBuffer[i].y + 1, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1, FontBuffer[ i ].y + 1, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif + } + else{ + TextOut(hDc, FontBuffer[i].x + 1 + 22, FontBuffer[i].y + 1, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 1 + 22, FontBuffer[ i ].y + 1, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif + } +#endif +#ifndef LABEL_STR_ + TextOut(hDc, 1 + 1, 432 + DISPLACEMENT_Y + 1, g_szChannelTitle[TalkMode], (int)strlen(g_szChannelTitle[TalkMode])); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut(hDcSys,2 + 1,432 + DISPLACEMENT_Y + 1,g_szChannelTitle[TalkMode],(int)strlen(g_szChannelTitle[TalkMode])); +#endif +#endif + } +#endif +#ifdef _FONT_SIZE + if (newFont != NULL) { + DeleteObject(newFont); + SelectObject(hDc, oldFont); + } +#endif + } + } + } + // 訞????? SetTextColor?????????????L? ? + for (color = 0; color < FONT_PAL_NUM; color++){ + for (i = 0; i < FontCnt; i++){ + if (FontBuffer[i].fontPrio == fontPrio){ + if (FontBuffer[i].color == color){ + // ????????????????? + if (colorFlag == FALSE){ + SetTextColor(hDc, FontPal[color]); +#ifdef _READ16BITBMP + if(g_bUseAlpha) SetTextColor( hDcSys, FontPal[ color ] ); +#endif + colorFlag = TRUE; + } + //??????????????? + if (ResoMode == 1){ + // ????e????? + TextOut(hDc, FontBuffer[i].x >> 1, FontBuffer[i].y >> 1, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); + } + else { + // ????e????? +#ifdef _FONT_SIZE + static HFONT newFont = NULL; + static HFONT oldFont = NULL; + + if (newFont != NULL) { + DeleteObject(newFont); + //SelectObject( hDc, oldFont ); + } + if (FontBuffer[i].size <= 0) + SelectObject(hDc, hFont); + else { + newFont = CreateNewFont(FontBuffer[i].size); + if (newFont != NULL) + oldFont = (HFONT)SelectObject(hDc, newFont); + } +#endif + +#ifndef _CHANNEL_MODIFY + TextOut( hDc, FontBuffer[ i ].x, FontBuffer[ i ].y, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x, FontBuffer[ i ].y, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif +#else + if (FontBuffer[i].fontPrio != FONT_PRIO_CHATBUFFER){ +#ifdef _FONT_PARAGRAPH_COLOR + char *s = FontBuffer[ i ].str; + int x = 0; + int len = 0; + while(char *ss = strstr(s, "/")){ + ss ++; + len = ss - s - 1; + if(ss[0] < 'a' || ss[0] > 'z'){ + len++; + } + TextOut( hDc, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, len); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, len); + } +#endif + + if(ss[0] >= 'a' && ss[0] <= 'z'){ + SetTextColor( hDc, FontPal[ ss[0] - 'a' ] ); + ss++; + } + + s = ss; + x += len; + } + TextOut( hDc, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#endif + SetTextColor( hDc, FontPal[ color ] ); +#else + TextOut(hDc, FontBuffer[i].x, FontBuffer[i].y, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x, FontBuffer[ i ].y, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif +#endif + } + else{ +#ifdef _TALK_WINDOW + if(g_bTalkWindow) break; +#endif + +#ifdef _FONT_PARAGRAPH_COLOR + char *s = FontBuffer[ i ].str; + int x = 0; + int len = 0; + while(char *ss = strstr(s, "/")){ + ss ++; + len = ss - s - 1; + + if(ss[0] < 'a' || ss[0] > 'z'){ + len--; + } + if(false){ + TextOut( hDc, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, len + 2); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, len + 2); +#endif + } + else{ + TextOut( hDc, FontBuffer[ i ].x + 22 + x * 7, FontBuffer[ i ].y, s, len + 2); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 22 + x * 7, FontBuffer[ i ].y, s, len + 2); +#endif + } + + if(ss[0] >= 'a' && ss[0] <= 'z'){ + SetTextColor( hDc, FontPal[ ss[0] - 'a' ] ); + ss++; + } + + s = ss; + x += len + 2; + } + + if(false){ + TextOut( hDc, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#endif + } + else{ + TextOut( hDc, FontBuffer[ i ].x + 22 + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 22 + x * 7, FontBuffer[ i ].y, s, strlen(s)); +#endif + } + SetTextColor( hDc, FontPal[ color ] ); +#else + + if (false){ + TextOut(hDc, FontBuffer[i].x, FontBuffer[i].y, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x, FontBuffer[ i ].y, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif + } + else{ + TextOut(hDc, FontBuffer[i].x + 22, FontBuffer[i].y, FontBuffer[i].str, (int)strlen(FontBuffer[i].str)); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut( hDcSys, FontBuffer[ i ].x + 22, FontBuffer[ i ].y, FontBuffer[ i ].str, ( int )strlen( FontBuffer[ i ].str ) ); +#endif + } +#endif +#ifndef LABEL_STR_ + TextOut(hDc, 1, 432 + DISPLACEMENT_Y, g_szChannelTitle[TalkMode], (int)strlen(g_szChannelTitle[TalkMode])); +#ifdef _READ16BITBMP + if(g_bUseAlpha) TextOut(hDcSys,2,432 + DISPLACEMENT_Y,g_szChannelTitle[TalkMode],(int)strlen(g_szChannelTitle[TalkMode])); +#endif +#endif + } +#endif +#ifdef _FONT_SIZE + if (newFont != NULL) { + DeleteObject(newFont); + SelectObject(hDc, oldFont); + } +#endif + } + } + } + } + colorFlag = FALSE; + } + SelectObject(hDc, hOldFont); + lpDraw->lpBACKBUFFER->ReleaseDC(hDc); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + SelectObject(hDcSys,hOldFont); + lpDraw->lpBACKBUFFERSYS->ReleaseDC(hDcSys); + } +#endif +} + +//---------------------------------------------------------------------------// +// ?????????V +//---------------------------------------------------------------------------// +void snapShot(void) +{ + DDSURFACEDESC ddsdDesc; + RGBQUAD rgbpal[256]; + char fileName[256]; + int i; + static struct tm nowTime; + time_t longTime; + FILE *fp; + int w, h; + POINT clientPoint; // ??????????????????t??t + + // ?????Bl???? + clientPoint.x = 0; + clientPoint.y = 0; + // ??????????????????x + ClientToScreen(hWnd, &clientPoint); + + // V?????? + if (_mkdir("screenshot") != 0) + { + if (errno != EEXIST) + return; + } + + // V?????? + time(&longTime); // ???T??x + localtime_s(&nowTime, &longTime); + + for (i = 0; i < 1000; i++) + { + sprintf_s(fileName, "screenshot\\sa%02d%02d%02d_%03d.bmp", + (nowTime.tm_year % 100), nowTime.tm_mon + 1, nowTime.tm_mday, i); + + if ((fp = fopen(fileName, "r")) != NULL) + { + fclose(fp); + continue; + } + else + { + break; + } + } + + if (displayBpp != 16){ + for (i = 0; i < 256; i++){ + rgbpal[i].rgbRed = Palette[i].peRed; + rgbpal[i].rgbGreen = Palette[i].peGreen; + rgbpal[i].rgbBlue = Palette[i].peBlue; + rgbpal[i].rgbReserved = 0; + } + } + memset(&ddsdDesc, 0, sizeof(DDSURFACEDESC)); + ddsdDesc.dwSize = sizeof(DDSURFACEDESC); + if (lpDraw->lpFRONTBUFFER->Lock(NULL, &ddsdDesc, 0, NULL) != DD_OK){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd,"ǰʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + return; + } + + if (ResoMode == 1) + { + w = 320; + h = 240; + } + else + { + w = lpDraw->xSize; + h = lpDraw->ySize; + } + if (displayBpp == 16){ + BYTE *mem = new BYTE[w * h * 3], *pmem, pR, pG, pB; + if (mem == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd,"ʧʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + return; + } + WORD *work = (WORD*)ddsdDesc.lpSurface; + pmem = mem; + pmem += w * h * 3; + + // source face һƶbyte + ddsdDesc.lPitch >>= 1; + // work ӫĻλ,Ҫƫ + work += ddsdDesc.lPitch * g_clientPoint.y + g_clientPoint.x; + for (int y = 0; y < h; y++){ + pmem -= w * 3; + for (int x = 0; x < w; x++){ + // 565 ʾģʽ + if (gBitRShift == 2){ + pR = (BYTE)((((work[x] & 0xf800)) >> 11) << 3); + pG = (BYTE)((((work[x] & 0x07e0)) >> 5) << 2); + pB = (BYTE)((work[x] & 0x001f) << 3); + } + // 555 ʾģʽ + else{ + pR = (BYTE)((work[x] >> 10) << 3); + pG = (BYTE)(((work[x] & 0x03e0) >> 5) << 3); + pB = (BYTE)((work[x] & 0x001f) << 3); + } + *pmem++ = pB; + *pmem++ = pG; + *pmem++ = pR; + } + // + work += ddsdDesc.lPitch; + pmem -= w * 3; + } + + saveBmpFile16(fileName, mem, w, h); + delete[] mem; + } + else + saveBmpFile(fileName, (BYTE*)ddsdDesc.lpSurface, + clientPoint.x, clientPoint.y, w, h, ddsdDesc.lPitch, rgbpal, 256); + + if (lpDraw->lpFRONTBUFFER->Unlock(NULL) != DD_OK) + return; +} + + +// ???????????V +BOOL saveBmpFile(const char *filename, BYTE *buf, + int x, int y, int width, int height, int srcpitch, + RGBQUAD *rgbpal, int colorCnt) +{ + HANDLE fh; + BITMAPFILEHEADER fileheader; + BITMAPINFOHEADER infoheader; + + int linesize = (width + 3) / 4; + DWORD writtensize; + BYTE zero = 0; + int i; + + fh = CreateFile(filename, GENERIC_WRITE, (DWORD)NULL, + (LPSECURITY_ATTRIBUTES)NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL); + + if (fh == INVALID_HANDLE_VALUE) + { + return FALSE; + } + + + fileheader.bfType = 0x4D42; + fileheader.bfSize = sizeof(BITMAPFILEHEADER) + +sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*(colorCnt)+linesize*height; + fileheader.bfReserved1 = 0; + fileheader.bfReserved2 = 0; + fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + +sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*(colorCnt); + + WriteFile(fh, (void*)(&fileheader), sizeof(fileheader), &writtensize, NULL); + + + infoheader.biSize = sizeof(BITMAPINFOHEADER); + infoheader.biWidth = width; + infoheader.biHeight = height; + infoheader.biPlanes = 1; + infoheader.biBitCount = 8; + infoheader.biCompression = NULL; + infoheader.biSizeImage = sizeof(BITMAPINFOHEADER) + +sizeof(RGBQUAD)*(colorCnt)+linesize*height; + infoheader.biXPelsPerMeter = 0; + infoheader.biYPelsPerMeter = 0; + infoheader.biClrUsed = colorCnt; + infoheader.biClrImportant = 0; + + WriteFile(fh, (void*)(&infoheader), sizeof(BITMAPINFOHEADER), &writtensize, NULL); + WriteFile(fh, (void*)rgbpal, sizeof(RGBQUAD)*(colorCnt), &writtensize, NULL); + + for (i = 0; i < height; i++) + { + WriteFile(fh, (void*)(buf + srcpitch*(height + y - 1 - i) + x), width, &writtensize, NULL); + WriteFile(fh, (void*)(&zero), linesize - width, &writtensize, NULL); + } + + CloseHandle(fh); + + return TRUE; +} + +BOOL saveBmpFile16(const char *filename, BYTE *buf, int width, int height) +{ + HANDLE fh; + BITMAPFILEHEADER fileheader; + BITMAPINFOHEADER infoheader; + + DWORD writtensize; + BYTE zero = 0; + + fh = CreateFile(filename, GENERIC_WRITE, (DWORD)NULL, + (LPSECURITY_ATTRIBUTES)NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL); + + if (fh == INVALID_HANDLE_VALUE) return FALSE; + + fileheader.bfType = 0x4D42; + fileheader.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+width * height * 3; + fileheader.bfReserved1 = 0; + fileheader.bfReserved2 = 0; + fileheader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); + + infoheader.biSize = sizeof(BITMAPINFOHEADER); + infoheader.biWidth = width; + infoheader.biHeight = height; + infoheader.biPlanes = 1; + infoheader.biBitCount = 24; + infoheader.biCompression = 0; + infoheader.biSizeImage = width * height * 3; + infoheader.biXPelsPerMeter = 0; + infoheader.biYPelsPerMeter = 0; + infoheader.biClrUsed = 0; + infoheader.biClrImportant = 0; + + WriteFile(fh, (void*)(&fileheader), sizeof(fileheader), &writtensize, NULL); + WriteFile(fh, (void*)(&infoheader), sizeof(BITMAPINFOHEADER), &writtensize, NULL); + WriteFile(fh, (void*)buf, width * height * 3, &writtensize, NULL); + + CloseHandle(fh); + + return TRUE; +} + +#ifdef _READ16BITBMP +void Draw16BitmapToSurface2(SURFACE_INFO *surface_info,LPDIRECTDRAWSURFACE lpSurfaceSys,int offsetX,int offsetY,int sizeX,int sizeY,LPBITMAPINFO pBmpInfo) +{ + DDSURFACEDESC ddsd; + WORD *pDest; + BYTE R,G,B; + char *pSource; + int surfacePitch,i,j; + DDSURFACEDESC ddsdsys; + WORD *pDestSys; + int surfacePitchSys; +#ifdef _HI_COLOR_32 + int *pDest32; + int *pDestSys32; + int surfacePitch32; + int surfacePitchSys32; +#endif + + if(surface_info->lpSurface == NULL) return; + if(g_bUseAlpha && lpSurfaceSys == NULL) return; + + ZeroMemory(&ddsd,sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdsys,sizeof(DDSURFACEDESC)); + ddsdsys.dwSize = sizeof(DDSURFACEDESC); + + if(FAILED(surface_info->lpSurface->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL))) return; + if(g_bUseAlpha){ + if(FAILED(lpSurfaceSys->Lock(NULL,&ddsdsys,DDLOCK_WAIT,NULL))){ + surface_info->lpSurface->Unlock(NULL); + return; + } + } +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + pDest32 = (int*)(ddsd.lpSurface); + if(g_bUseAlpha) pDestSys32 = (int*)(ddsdsys.lpSurface); + pSource = pRealBinBits + offsetY * RealBinWidth + offsetX; + surfacePitch32 = ddsd.lPitch >> 2; + if(g_bUseAlpha) surfacePitchSys32 = ddsdsys.lPitch >> 2; + + for(i=0;i> 1; + if(g_bUseAlpha) surfacePitchSys = ddsdsys.lPitch >> 1; + + for(i=0;i> 3; + G = g_rgbPal[(BYTE)*pSource].rgbGreen >> 2; + B = g_rgbPal[(BYTE)*pSource].rgbBlue >> 3; + *pDest = (WORD)((R << 11) | (G << 5) | B); + pDest++; + pSource++; + if(g_bUseAlpha){ + *pDestSys = (WORD)((R << 11) | (G << 5) | B); + pDestSys++; + } + } + // һ + pDest += surfacePitch - sizeX; + pSource += RealBinWidth - sizeX; + if(g_bUseAlpha) pDestSys += surfacePitchSys - sizeX; + } + } + + surface_info->lpSurface->Unlock(NULL); + if(g_bUseAlpha) lpSurfaceSys->Unlock(NULL); + // дalpha channel + static UCHAR a[1]; + + if(g_bUseAlpha){ + if(surface_info->useAlpha == TRUE){ + BYTE *pAlphaSource = pRealBinAlpha + offsetY * RealBinWidth + offsetX; + BYTE *pAlphaDest = surface_info->lpAlphaData; + memset(pAlphaDest,0,SurfaceSizeX*SurfaceSizeY); + for(i=0;i> 3; + pAlphaDest++; + pAlphaSource++; + } + // һ + pAlphaDest += SurfaceSizeX - sizeX; + pAlphaSource += RealBinWidth - sizeX; + } + } + } + return; +} +#endif + +int CG_PKSERVER_PANEL; +int CG_BATTTLE_SKILLCHOICE; +int CG_FIELD_SKILL_PANEL; +int CG_FIELD_CHATROOM_PANEL; +int CG_FIELD_SV_SELL_PANEL; +int CG_FIELD_SV_SELL_PRICE_PANEL; +int CG_NEW_STATUS_WND; +int CG_NEWITEM_WND; +int CG_TRADE_WND; +int CG_TRADE_VIEWWND; +// [?????? +int CG_WND_G_0; +int CG_WND_G_1; +int CG_WND_G_2; +int CG_WND_G_3; +int CG_WND_G_4; +int CG_WND_G_5; +int CG_WND_G_6; +int CG_WND_G_7; +int CG_WND_G_8; +// [??????? +int CG_WND2_G_0; +int CG_WND2_G_1; +int CG_WND2_G_2; +int CG_WND2_G_3; +int CG_WND2_G_4; +int CG_WND2_G_5; +int CG_WND2_G_6; +int CG_WND2_G_7; +int CG_WND2_G_8; +// [??????? +int CG_WND3_G_7; +int CG_WND3_G_8; +int CG_WND3_G_9; +// o????? +int CG_BTL_PET_CHANGE_WND; +// ???????? +int CG_PET_WND_VIEW; +int CG_PET_WND_DETAIL; +int CG_NAME_CHANGE_WND; +// ????????? +int CG_ITEM_WND_1; +int CG_JUJUTU_WND; +int CG_ITEM_WND_SELECT_WND; +int CG_STATUS_WND_GROUP_WND; +// ???????? +int CG_MAP_WND; +// ?????????? +int CG_STATUS_WND; +// ???????? +int CG_MAIL_WND; +int CG_MAIL_WND_SEND_WND; +int CG_MAIL_WND_PET_SEND_WND; +int CG_MAIL_WND_HISTORY_WND; +// ????????? +int CG_ALBUM_WND; +// ??????K?????? +int CG_CHAT_REGISTY_WND; +// ?V?[?????? +int CG_COMMON_WIN_YORO; +int CG_FIELD_HELP_WND; +// ?????????? +int CG_MSG_WND; +int CG_PET_WAZA_WND; +// ????????????? +int CG_ITEMSHOP_WIN; +// ?????????? +int CG_SKILLSHOP_WIN; +// ?????????? +int CG_ITEMSHOP_KOSU_WIN; +int CG_FAMILY_DETAIL_WIN; +int CG_FAMILY_BANK_WIN; +int CG_BM_WND; + +void SetAnimTbl() +{ +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + CG_PKSERVER_PANEL = OLD_GRAPHICS_START+37; + CG_BATTTLE_SKILLCHOICE = OLD_GRAPHICS_START+53; + CG_FIELD_SKILL_PANEL = OLD_GRAPHICS_START+50; + CG_FIELD_CHATROOM_PANEL = OLD_GRAPHICS_START+54; + CG_FIELD_SV_SELL_PANEL = OLD_GRAPHICS_START+55; + CG_FIELD_SV_SELL_PRICE_PANEL = OLD_GRAPHICS_START+56; + CG_NEW_STATUS_WND = OLD_GRAPHICS_START+51; + CG_NEWITEM_WND = OLD_GRAPHICS_START+52; + CG_TRADE_WND = OLD_GRAPHICS_START+48; + CG_TRADE_VIEWWND = OLD_GRAPHICS_START+49; + CG_WND_G_0 = OLD_GRAPHICS_START; + CG_WND_G_1 = OLD_GRAPHICS_START+1; + CG_WND_G_2 = OLD_GRAPHICS_START+2; + CG_WND_G_3 = OLD_GRAPHICS_START+3; + CG_WND_G_4 = OLD_GRAPHICS_START+4; + CG_WND_G_5 = OLD_GRAPHICS_START+5; + CG_WND_G_6 = OLD_GRAPHICS_START+6; + CG_WND_G_7 = OLD_GRAPHICS_START+7; + CG_WND_G_8 = OLD_GRAPHICS_START+8; + CG_WND2_G_0 = OLD_GRAPHICS_START+9; + CG_WND2_G_1 = OLD_GRAPHICS_START+10; + CG_WND2_G_2 = OLD_GRAPHICS_START+11; + CG_WND2_G_3 = OLD_GRAPHICS_START+12; + CG_WND2_G_4 = OLD_GRAPHICS_START+13; + CG_WND2_G_5 = OLD_GRAPHICS_START+14; + CG_WND2_G_6 = OLD_GRAPHICS_START+15; + CG_WND2_G_7 = OLD_GRAPHICS_START+16; + CG_WND2_G_8 = OLD_GRAPHICS_START+17; + CG_WND3_G_7 = OLD_GRAPHICS_START+18; + CG_WND3_G_8 = OLD_GRAPHICS_START+19; + CG_WND3_G_9 = OLD_GRAPHICS_START+20; + CG_BTL_PET_CHANGE_WND = OLD_GRAPHICS_START+21; + CG_PET_WND_VIEW = OLD_GRAPHICS_START+22; + CG_PET_WND_DETAIL = OLD_GRAPHICS_START+23; + CG_NAME_CHANGE_WND = OLD_GRAPHICS_START+24; + CG_ITEM_WND_1 = OLD_GRAPHICS_START+25; + CG_JUJUTU_WND = OLD_GRAPHICS_START+26; + CG_ITEM_WND_SELECT_WND = OLD_GRAPHICS_START+27; + CG_STATUS_WND_GROUP_WND = OLD_GRAPHICS_START+28; + CG_MAP_WND = OLD_GRAPHICS_START+29; + CG_STATUS_WND = OLD_GRAPHICS_START+452; + CG_MAIL_WND = OLD_GRAPHICS_START+30; + CG_MAIL_WND_SEND_WND = OLD_GRAPHICS_START+38; + CG_MAIL_WND_PET_SEND_WND = OLD_GRAPHICS_START+39; + CG_MAIL_WND_HISTORY_WND = OLD_GRAPHICS_START+40; + CG_ALBUM_WND = OLD_GRAPHICS_START+41; + CG_CHAT_REGISTY_WND = OLD_GRAPHICS_START+42; + CG_COMMON_WIN_YORO = OLD_GRAPHICS_START+31; + CG_FIELD_HELP_WND = OLD_GRAPHICS_START+45; + CG_MSG_WND = OLD_GRAPHICS_START+47; + CG_PET_WAZA_WND = OLD_GRAPHICS_START+32; + CG_ITEMSHOP_WIN = OLD_GRAPHICS_START+33; + CG_SKILLSHOP_WIN = OLD_GRAPHICS_START+34; + CG_ITEMSHOP_KOSU_WIN = OLD_GRAPHICS_START+35; + CG_FAMILY_DETAIL_WIN = OLD_GRAPHICS_START+43; + CG_FAMILY_BANK_WIN = OLD_GRAPHICS_START+44; + CG_BM_WND = OLD_GRAPHICS_START+36; + } + else +#endif + { + CG_PKSERVER_PANEL = 26192; // ѡȡϵ + CG_BATTTLE_SKILLCHOICE = 26389; // սѡ + CG_FIELD_SKILL_PANEL = 26352; // ְҵܽ + CG_FIELD_CHATROOM_PANEL = 26427; // ҽ + CG_FIELD_SV_SELL_PANEL = 35221; // ̯() + CG_FIELD_SV_SELL_PRICE_PANEL = 35223; // ۼӴ + CG_NEW_STATUS_WND = 26386; +#ifdef _PET_ITEM + CG_NEWITEM_WND = 26455; // װλӴ(бǩ) +#else + CG_NEWITEM_WND = 26388; // װλӴ(֡š) +#endif + + CG_TRADE_WND = 26328; // Ӵ + + //end modified by lsh + CG_TRADE_VIEWWND = 26329; // ׼Ӵ + CG_WND_G_0 = 26001; + CG_WND_G_1 = 26002; + CG_WND_G_2 = 26003; + CG_WND_G_3 = 26004; + CG_WND_G_4 = 26005; + CG_WND_G_5 = 26006; + CG_WND_G_6 = 26007; + CG_WND_G_7 = 26008; + CG_WND_G_8 = 26009; + CG_WND2_G_0 = 26021; + CG_WND2_G_1 = 26022; + CG_WND2_G_2 = 26023; + CG_WND2_G_3 = 26024; + CG_WND2_G_4 = 26025; + CG_WND2_G_5 = 26026; + CG_WND2_G_6 = 26027; + CG_WND2_G_7 = 26028; + CG_WND2_G_8 = 26029; + CG_WND3_G_7 = 26037; + CG_WND3_G_8 = 26038; + CG_WND3_G_9 = 26039; + CG_BTL_PET_CHANGE_WND = 26040; // Pf?????V?v?????? + CG_PET_WND_VIEW = 26044; // ??????????????? + CG_PET_WND_DETAIL = 26045; // ?????????? + CG_NAME_CHANGE_WND = 26049; // q?????? + CG_ITEM_WND_1 = 26061; // ?????????? + CG_JUJUTU_WND = 26068; // ????? + CG_ITEM_WND_SELECT_WND = 26070; // k????? + CG_STATUS_WND_GROUP_WND = 26071; // ???????????? + CG_MAP_WND = 26081; // ???????? + CG_STATUS_WND = 26073; // ??????????????? + CG_MAIL_WND = 26082; // ???????? + CG_MAIL_WND_SEND_WND = 26200; // ????????? + CG_MAIL_WND_PET_SEND_WND = 26201; // ????????????? + CG_MAIL_WND_HISTORY_WND = 26203; // ?????????? + CG_ALBUM_WND = 26230; // ????????? + CG_CHAT_REGISTY_WND = 26232; + CG_COMMON_WIN_YORO = 26090; // "???????"?????????? + CG_FIELD_HELP_WND = 26258; + CG_MSG_WND = 26296; // Message's Main Window ,added by LeiBoy + CG_PET_WAZA_WND = 26130; + CG_ITEMSHOP_WIN = 26138; + CG_SKILLSHOP_WIN = 26139; + CG_ITEMSHOP_KOSU_WIN = 26140; + CG_FAMILY_DETAIL_WIN = 26239; + CG_FAMILY_BANK_WIN = 26240; + CG_BM_WND = 26141; + } +} +#ifdef _FONT_SIZE +HFONT CreateNewFont(int size) { + + +#ifdef _NEWFONT_ + char strfame[128]; + extern int ; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + }else{ + sprintf(strfame,"Microsoft JhengHei"); + } + + return CreateFont(size,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame); +#else + char strfame[128]; + extern int ; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + return CreateFont(size,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame); + }else{ + return CreateFont(size,0,0,0,400,FALSE,FALSE,FALSE,134, + OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_ROMAN,(LPCTSTR)""); + } + +#endif +} +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/field.cpp b/石器时代8.5客户端最新源代码/石器源码/system/field.cpp new file mode 100644 index 0000000..6dfd0c5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/field.cpp @@ -0,0 +1,6456 @@ +#include +#include +#include +#include +#include + +#include "../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/loadrealbin.h" +#include"../systeminc/loadsprbin.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/login.h" +#include"../systeminc/menu.h" +#include"../systeminc/map.h" +#include"../systeminc/lssproto_cli.h" +#include"../systeminc/pc.h" +#include"../systeminc/netmain.h" +#include"../systeminc/handletime.h" +#include"../systeminc/character.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/t_music.h" +#include "../systeminc/netproc.h" +#include "../systeminc/tool.h" +#include "../systeminc/onlinegm.h" + +extern int ProcNo2; +#ifdef _PET_ITEM +extern int nPetItemEquipBmpNumber[PET_EQUIPNUM][2]; +#endif + +#if 0 + +#include"netproc.h" +#include"character.h" +#include "battleProc.h" + +#endif + +#include "../systeminc/field.h" + +// ???????ul +short drawFieldButtonFlag = 1; +int fieldBtnHitId[FIELD_FUNC_END]; // ????????Re? +short drawTimeAnimeFlag = 0; + +extern BOOL bNewServer; +extern BOOL g_bUseAlpha; +// лͼBUG +ACTION *ptActMenuWin1 = NULL;//鶯 + +#ifdef _WATERANIMATION //Syu ADD ֮ +#define RAND(x,y) ((x - 1) + 1 + (int)((double)(y - (x - 1)) * rand() / (RAND_MAX + 1.0))) +bool in817flag = false; +#endif + +#ifdef _TEACHER_SYSTEM +void TeacherSystemWndfunc(int flag,char *data); +#endif + +BOOL BattlingFlag = FALSE; //for߻ϵͳ־ʹ + +#ifdef __ONLINEGM +BOOL OnlineGmFlag = FALSE; +#endif + +#ifdef _JOBDAILY +//BOOL JobDailyFlag = FALSE; +JOBDAILY jobdaily[MAXMISSION]; +int JobdailyGetMax = FALSE; +//int MaxPage = 0; +//int PageIndex = 0; +#endif + +#ifdef _CLOUD_EFFECT // (ɿ) ROG ADDƲЧ +void CloudDraw(); +#endif + +#ifdef _SURFACE_ANIM //ROG ADD ̬ʾ + int ani_num = 0; + BOOL breadAniFlag = FALSE; + ACTION *SPACT[MAX_ANIM]; + int ProduceXY[MAX_ANIM][7] = { -1 }; //0: spr, 1: x, 2: y, 3: ʱ 4:Ȩ 5:Ƿ 6:ACTION +#else + #ifdef _SPECIALSPACEANIM // Syu ADD ⳡ + static ACTION *SPACT[MAX_ANIM]; + #ifdef _SPECIALSPACEANIM_FIX + #ifdef _MOON_FAIRYLAND // ROG ADD ֮ɾ + // 0:ͼx 1:ͼy 2:ͼ 3:grano 4:ProduceXYûʹ 5:ProduceXYSPACTλ 6:ʾ˳ + int ProduceXY[TOTAL_ANIM][7] = { + { 48 , 27 , 1200 , 101290 , 0 , -1 , 30}, + { 36 , 28 , 8255 , 101730 , 0 , -1 , 0 }, + { 33 , 30 , 8255 , 101739 , 0 , -1 , 0 }, + { 25 , 38 , 8255 , 101733 , 0 , -1 , 0 }, + { 34 , 31 , 8255 , 101731 , 0 , -1 , 20} + }; + #else + int ProduceXY[TOTAL_ANIM][7] = { + { 48 , 27 , 1200 , 101290 , 0 , -1 , 30} + }; + #endif + #else + int ProduceXY[TOTAL_ANIM][6] = { + { 48 , 27 , 1200 , 101290 , 0 , -1 } + }; + #endif + #endif +#endif + +#ifdef _AniCrossFrame // Syu ADD ι +static ACTION *WaterAct2; //ι涯 +bool delFlag = false; //ι涯ɾ +bool flag22 = true; //ι涯ʲô +bool Timeflag2 = false; //ι涯ʱ +int TimeTick2 = 0; //ι涯ʱ +int TimeTickMax2 = 0; //ι涯ʱ +#endif + +#ifdef _AniRandom // Syu ADD +static ACTION *WaterAct[50]; // +bool Timeflag[50] = {false}; // +int TimeTick[50] = {0}; //ʱ +int TimeTickMax[50] = {0}; //ʱ +bool AniFlag = false; // +#endif + + + +#ifdef _AniImmobile // Syu ADD ض +static ACTION *WaterAct3[30]; //㶯 +bool Updownflag = false; //㶯Ư +int XYposition[560][7] = //㶯 + //{ X, Y, ͼ, , õAction, + // Ư(1ᶯ,2ᶯ), Ưʱ} +{ + { 252 , 255 , 101511 , 0 , -1 , 1 , 0}, + { 233 , 268 , 101510 , 0 , -1 , 1 , 0}, + { 227 , 257 , 101516 , 0 , -1 , 1 , 0}, + { 209 , 254 , 101511 , 0 , -1 , 1 , 0}, + { 308 , 133 , 101511 , 0 , -1 , 1 , 0}, + { 305 , 101 , 101518 , 0 , -1 , 1 , 0}, + { 316 , 121 , 101510 , 0 , -1 , 1 , 0}, + { 303 , 104 , 101511 , 0 , -1 , 1 , 0}, + { 287 , 122 , 101510 , 0 , -1 , 1 , 0}, + { 253 , 53 , 101510 , 0 , -1 , 1 , 0}, + { 109 , 98 , 101516 , 0 , -1 , 1 , 0}, + { 144 , 89 , 101511 , 0 , -1 , 1 , 0}, + { 114 , 86 , 101510 , 0 , -1 , 1 , 0}, + { 101 , 84 , 101517 , 0 , -1 , 1 , 0}, + { 94 , 93 , 101510 , 0 , -1 , 1 , 0}, + { 371 , 108 , 101511 , 0 , -1 , 1 , 0}, + { 183 , 120 , 101510 , 0 , -1 , 1 , 0}, + { 210 , 187 , 101510 , 0 , -1 , 1 , 0}, + { 382 , 187 , 101519 , 0 , -1 , 1 , 0}, + { 225 , 178 , 101510 , 0 , -1 , 1 , 0}, + { 355 , 206 , 101511 , 0 , -1 , 1 , 0}, + { 364 , 217 , 101517 , 0 , -1 , 1 , 0}, + { 239 , 150 , 101510 , 0 , -1 , 1 , 0}, + { 343 , 217 , 101511 , 0 , -1 , 1 , 0}, + { 245 , 139 , 101510 , 0 , -1 , 1 , 0}, + { 334 , 242 , 101516 , 0 , -1 , 1 , 0}, + { 324 , 218 , 101517 , 0 , -1 , 1 , 0}, + { 260 , 124 , 101518 , 0 , -1 , 1 , 0}, + { 301 , 246 , 101510 , 0 , -1 , 1 , 0}, + { 288 , 265 , 101510 , 0 , -1 , 1 , 0}, + { 278 , 267 , 101511 , 0 , -1 , 1 , 0}, + { 226 , 23 , 101510 , 0 , -1 , 1 , 0}, + { 344 , 43 , 101511 , 0 , -1 , 1 , 0}, + { 368 , 110 , 101516 , 0 , -1 , 1 , 0}, + { 360 , 145 , 101510 , 0 , -1 , 1 , 0}, + { 347 , 232 , 101510 , 0 , -1 , 1 , 0}, + { 327 , 230 , 101519 , 0 , -1 , 1 , 0}, + { 147 , 23 , 101518 , 0 , -1 , 1 , 0}, + { 147 , 42 , 101517 , 0 , -1 , 1 , 0}, + { 280 , 38 , 101510 , 0 , -1 , 1 , 0}, + { 158 , 44 , 101510 , 0 , -1 , 1 , 0}, + { 145 , 68 , 101510 , 0 , -1 , 1 , 0}, + { 189 , 66 , 101510 , 0 , -1 , 1 , 0}, + { 204 , 55 , 101511 , 0 , -1 , 1 , 0}, + { 199 , 55 , 101510 , 0 , -1 , 1 , 0}, + { 235 , 52 , 101511 , 0 , -1 , 1 , 0}, + { 253 , 34 , 101510 , 0 , -1 , 1 , 0}, + { 288 , 51 , 101510 , 0 , -1 , 1 , 0}, + { 298 , 62 , 101511 , 0 , -1 , 1 , 0}, + { 299 , 72 , 101510 , 0 , -1 , 1 , 0}, + { 256 , 94 , 101511 , 0 , -1 , 1 , 0}, + { 284 , 106 , 101516 , 0 , -1 , 1 , 0}, + { 344 , 42 , 101518 , 0 , -1 , 1 , 0}, + { 329 , 72 , 101519 , 0 , -1 , 1 , 0}, + { 351 , 82 , 101516 , 0 , -1 , 1 , 0}, + { 379 , 82 , 101517 , 0 , -1 , 1 , 0}, + { 164 , 264 , 101519 , 0 , -1 , 1 , 0}, + { 155 , 263 , 101510 , 0 , -1 , 1 , 0}, + { 124 , 267 , 101511 , 0 , -1 , 1 , 0}, + { 125 , 266 , 101510 , 0 , -1 , 1 , 0}, + { 112 , 290 , 101511 , 0 , -1 , 1 , 0}, + { 102 , 287 , 101510 , 0 , -1 , 1 , 0}, + { 95 , 308 , 101511 , 0 , -1 , 1 , 0}, + { 65 , 335 , 101511 , 0 , -1 , 1 , 0}, + { 50 , 335 , 101516 , 0 , -1 , 1 , 0}, + { 48 , 366 , 101510 , 0 , -1 , 1 , 0}, + { 72 , 354 , 101517 , 0 , -1 , 1 , 0}, + { 79 , 376 , 101511 , 0 , -1 , 1 , 0}, + { 112 , 372 , 101518 , 0 , -1 , 1 , 0}, + { 129 , 411 , 101510 , 0 , -1 , 1 , 0}, + { 134 , 421 , 101519 , 0 , -1 , 1 , 0}, + { 169 , 416 , 101510 , 0 , -1 , 1 , 0}, + { 201 , 418 , 101511 , 0 , -1 , 1 , 0}, + { 196 , 376 , 101516 , 0 , -1 , 1 , 0}, + { 206 , 366 , 101510 , 0 , -1 , 1 , 0}, + { 202 , 342 , 101517 , 0 , -1 , 1 , 0}, + { 172 , 334 , 101511 , 0 , -1 , 1 , 0}, + { 192 , 323 , 101510 , 0 , -1 , 1 , 0}, + { 155 , 337 , 101510 , 0 , -1 , 1 , 0}, + { 132 , 45 , 101511 , 0 , -1 , 1 , 0}, + { 99 , 489 , 101510 , 0 , -1 , 1 , 0}, + { 99 , 466 , 101511 , 0 , -1 , 1 , 0}, + { 114 , 435 , 101510 , 0 , -1 , 1 , 0}, + { 119 , 465 , 101516 , 0 , -1 , 1 , 0}, + { 142 , 435 , 101510 , 0 , -1 , 1 , 0}, + { 166 , 427 , 101517 , 0 , -1 , 1 , 0}, + { 159 , 383 , 101518 , 0 , -1 , 1 , 0}, + { 47 , 156 , 101510 , 0 , -1 , 1 , 0}, + { 47 , 132 , 101519 , 0 , -1 , 1 , 0}, + { 36 , 123 , 101510 , 0 , -1 , 1 , 0}, + { 61 , 162 , 101517 , 0 , -1 , 1 , 0}, + { 79 , 145 , 101510 , 0 , -1 , 1 , 0}, + { 93 , 157 , 101510 , 0 , -1 , 1 , 0}, + { 107 , 154 , 101511 , 0 , -1 , 1 , 0}, + { 118 , 165 , 101510 , 0 , -1 , 1 , 0}, + { 133 , 164 , 101519 , 0 , -1 , 1 , 0}, + { 138 , 176 , 101510 , 0 , -1 , 1 , 0}, + { 146 , 205 , 101510 , 0 , -1 , 1 , 0}, + { 162 , 211 , 101516 , 0 , -1 , 1 , 0}, + { 170 , 202 , 101510 , 0 , -1 , 1 , 0}, + + //캣 101595 캣 101597 + {130,181, 101595 , 0 , -1 , 2 , 0},{275,255, 101597 , 0 , -1 , 2 , 0}, + {124,161, 101595 , 0 , -1 , 2 , 0},{261,265, 101597 , 0 , -1 , 2 , 0}, + {243,90 , 101595 , 0 , -1 , 2 , 0},{226,250, 101597 , 0 , -1 , 2 , 0}, + {269,73 , 101595 , 0 , -1 , 2 , 0},{212,249, 101597 , 0 , -1 , 2 , 0}, + {292,55 , 101595 , 0 , -1 , 2 , 0},{182,250, 101597 , 0 , -1 , 2 , 0}, + {307,108, 101595 , 0 , -1 , 2 , 0},{169,260, 101597 , 0 , -1 , 2 , 0}, + {307,102, 101595 , 0 , -1 , 2 , 0},{147,262, 101597 , 0 , -1 , 2 , 0}, + {183,95 , 101595 , 0 , -1 , 2 , 0},{121,281, 101597 , 0 , -1 , 2 , 0}, + {156,56 , 101595 , 0 , -1 , 2 , 0},{109,289, 101597 , 0 , -1 , 2 , 0}, + {137,183, 101595 , 0 , -1 , 2 , 0},{103,297, 101597 , 0 , -1 , 2 , 0}, + {133,167, 101595 , 0 , -1 , 2 , 0},{46,320 , 101597 , 0 , -1 , 2 , 0}, + {130,163, 101595 , 0 , -1 , 2 , 0},{63,338 , 101597 , 0 , -1 , 2 , 0}, + {112,164, 101595 , 0 , -1 , 2 , 0},{50,360 , 101597 , 0 , -1 , 2 , 0}, + {82,151 , 101595 , 0 , -1 , 2 , 0},{92,365 , 101597 , 0 , -1 , 2 , 0}, + {66,154 , 101595 , 0 , -1 , 2 , 0},{122,380, 101597 , 0 , -1 , 2 , 0}, + {47,132 , 101595 , 0 , -1 , 2 , 0},{151,409, 101597 , 0 , -1 , 2 , 0}, + {43,130 , 101595 , 0 , -1 , 2 , 0},{162,416, 101597 , 0 , -1 , 2 , 0}, + {52,140 , 101595 , 0 , -1 , 2 , 0},{209,369, 101597 , 0 , -1 , 2 , 0}, + {76,155 , 101595 , 0 , -1 , 2 , 0},{192,338, 101597 , 0 , -1 , 2 , 0}, + {120,169, 101595 , 0 , -1 , 2 , 0},{165,315, 101597 , 0 , -1 , 2 , 0}, + {148,220, 101595 , 0 , -1 , 2 , 0},{166,343, 101597 , 0 , -1 , 2 , 0}, + {225,175, 101595 , 0 , -1 , 2 , 0},{199,403, 101597 , 0 , -1 , 2 , 0}, + {244,144, 101595 , 0 , -1 , 2 , 0},{171,408, 101597 , 0 , -1 , 2 , 0}, + {229,103, 101595 , 0 , -1 , 2 , 0},{145,406, 101597 , 0 , -1 , 2 , 0}, + {238,110, 101595 , 0 , -1 , 2 , 0},{164,461, 101597 , 0 , -1 , 2 , 0}, + {99,88 , 101595 , 0 , -1 , 2 , 0},{188,508, 101597 , 0 , -1 , 2 , 0}, + {134,80 , 101595 , 0 , -1 , 2 , 0},{158,457, 101597 , 0 , -1 , 2 , 0}, + {207,46 , 101595 , 0 , -1 , 2 , 0},{148,487, 101597 , 0 , -1 , 2 , 0}, + {315,43 , 101595 , 0 , -1 , 2 , 0},{103,460, 101597 , 0 , -1 , 2 , 0}, + {337,36 , 101595 , 0 , -1 , 2 , 0},{111,446, 101597 , 0 , -1 , 2 , 0}, + {353,75 , 101595 , 0 , -1 , 2 , 0},{126,443, 101597 , 0 , -1 , 2 , 0}, + {359,90 , 101595 , 0 , -1 , 2 , 0},{132,409, 101597 , 0 , -1 , 2 , 0}, + {359,100, 101595 , 0 , -1 , 2 , 0},{110,382, 101597 , 0 , -1 , 2 , 0}, + {355,100, 101595 , 0 , -1 , 2 , 0},{378,186, 101597 , 0 , -1 , 2 , 0}, + {351,152, 101595 , 0 , -1 , 2 , 0},{370,209, 101597 , 0 , -1 , 2 , 0}, + {360,157, 101595 , 0 , -1 , 2 , 0},{349,225, 101597 , 0 , -1 , 2 , 0}, + {370,170, 101595 , 0 , -1 , 2 , 0},{341,234, 101597 , 0 , -1 , 2 , 0}, + {300,254, 101595 , 0 , -1 , 2 , 0},{311,239, 101597 , 0 , -1 , 2 , 0}, + //̺ 101594 ̺ 101596 + {129,185, 101594 , 0 , -1 , 2 , 0},{367,204, 101596 , 0 , -1 , 2 , 0}, + {133,160, 101594 , 0 , -1 , 2 , 0},{340,221, 101596 , 0 , -1 , 2 , 0}, + {248,87 , 101594 , 0 , -1 , 2 , 0},{330,227, 101596 , 0 , -1 , 2 , 0}, + {262,36 , 101594 , 0 , -1 , 2 , 0},{316,250, 101596 , 0 , -1 , 2 , 0}, + {256,83 , 101594 , 0 , -1 , 2 , 0},{291,250, 101596 , 0 , -1 , 2 , 0}, + {313,115, 101594 , 0 , -1 , 2 , 0},{276,261, 101596 , 0 , -1 , 2 , 0}, + {303,110, 101594 , 0 , -1 , 2 , 0},{252,261, 101596 , 0 , -1 , 2 , 0}, + {173,83 , 101594 , 0 , -1 , 2 , 0},{222,249, 101596 , 0 , -1 , 2 , 0}, + {142,87 , 101594 , 0 , -1 , 2 , 0},{209,249, 101596 , 0 , -1 , 2 , 0}, + {252,126, 101594 , 0 , -1 , 2 , 0},{179,248, 101596 , 0 , -1 , 2 , 0}, + {221,179, 101594 , 0 , -1 , 2 , 0},{167,256, 101596 , 0 , -1 , 2 , 0}, + {199,182, 101594 , 0 , -1 , 2 , 0},{142,261, 101596 , 0 , -1 , 2 , 0}, + {96,149 , 101594 , 0 , -1 , 2 , 0},{113,278, 101596 , 0 , -1 , 2 , 0}, + {85,141 , 101594 , 0 , -1 , 2 , 0},{103,288, 101596 , 0 , -1 , 2 , 0}, + {61,157 , 101594 , 0 , -1 , 2 , 0},{84,307 , 101596 , 0 , -1 , 2 , 0}, + {39,135 , 101594 , 0 , -1 , 2 , 0},{46,324 , 101596 , 0 , -1 , 2 , 0}, + {40,131 , 101594 , 0 , -1 , 2 , 0},{63,343 , 101596 , 0 , -1 , 2 , 0}, + {55,148 , 101594 , 0 , -1 , 2 , 0},{53,363 , 101596 , 0 , -1 , 2 , 0}, + {92,147 , 101594 , 0 , -1 , 2 , 0},{100,369, 101596 , 0 , -1 , 2 , 0}, + {129,176, 101594 , 0 , -1 , 2 , 0},{135,390, 101596 , 0 , -1 , 2 , 0}, + {151,208, 101594 , 0 , -1 , 2 , 0},{153,407, 101596 , 0 , -1 , 2 , 0}, + {229,166, 101594 , 0 , -1 , 2 , 0},{169,419, 101596 , 0 , -1 , 2 , 0}, + {254,132, 101594 , 0 , -1 , 2 , 0},{212,370, 101596 , 0 , -1 , 2 , 0}, + {309,109, 101594 , 0 , -1 , 2 , 0},{196,338, 101596 , 0 , -1 , 2 , 0}, + {236,76 , 101594 , 0 , -1 , 2 , 0},{161,321, 101596 , 0 , -1 , 2 , 0}, + {111,89 , 101594 , 0 , -1 , 2 , 0},{184,335, 101596 , 0 , -1 , 2 , 0}, + {137,76 , 101594 , 0 , -1 , 2 , 0},{182,410, 101596 , 0 , -1 , 2 , 0}, + {269,57 , 101594 , 0 , -1 , 2 , 0},{179,425, 101596 , 0 , -1 , 2 , 0}, + {308,40 , 101594 , 0 , -1 , 2 , 0},{151,399, 101596 , 0 , -1 , 2 , 0}, + {345,60 , 101594 , 0 , -1 , 2 , 0},{167,487, 101596 , 0 , -1 , 2 , 0}, + {346,79 , 101594 , 0 , -1 , 2 , 0},{187,516, 101596 , 0 , -1 , 2 , 0}, + {359,98 , 101594 , 0 , -1 , 2 , 0},{106,488, 101596 , 0 , -1 , 2 , 0}, + {373,110, 101594 , 0 , -1 , 2 , 0},{143,487, 101596 , 0 , -1 , 2 , 0}, + {373,106, 101594 , 0 , -1 , 2 , 0},{106,455, 101596 , 0 , -1 , 2 , 0}, + {356,152, 101594 , 0 , -1 , 2 , 0},{104,458, 101596 , 0 , -1 , 2 , 0}, + {365,154, 101594 , 0 , -1 , 2 , 0},{146,428, 101596 , 0 , -1 , 2 , 0}, + {360,169, 101594 , 0 , -1 , 2 , 0},{128,405, 101596 , 0 , -1 , 2 , 0}, + {373,186, 101594 , 0 , -1 , 2 , 0},{92,381 , 101596 , 0 , -1 , 2 , 0}, + // ̺ 101598 ̺ 101600 + {148,199, 101598 , 0 , -1 , 2 , 0},{356,218, 101600 , 0 , -1 , 2 , 0}, + {120,158, 101598 , 0 , -1 , 2 , 0},{337,222, 101600 , 0 , -1 , 2 , 0}, + {235,78 , 101598 , 0 , -1 , 2 , 0},{319,233, 101600 , 0 , -1 , 2 , 0}, + {286,49 , 101598 , 0 , -1 , 2 , 0},{305,242, 101600 , 0 , -1 , 2 , 0}, + {372,121, 101598 , 0 , -1 , 2 , 0},{281,260, 101600 , 0 , -1 , 2 , 0}, + {346,62 , 101598 , 0 , -1 , 2 , 0},{271,262, 101600 , 0 , -1 , 2 , 0}, + {325,80 , 101598 , 0 , -1 , 2 , 0},{243,246, 101600 , 0 , -1 , 2 , 0}, + {156,52 , 101598 , 0 , -1 , 2 , 0},{223,250, 101600 , 0 , -1 , 2 , 0}, + {159,74 , 101598 , 0 , -1 , 2 , 0},{202,247, 101600 , 0 , -1 , 2 , 0}, + {240,153, 101598 , 0 , -1 , 2 , 0},{175,257, 101600 , 0 , -1 , 2 , 0}, + {204,176, 101598 , 0 , -1 , 2 , 0},{163,256, 101600 , 0 , -1 , 2 , 0}, + {189,189, 101598 , 0 , -1 , 2 , 0},{135,263, 101600 , 0 , -1 , 2 , 0}, + {88,142 , 101598 , 0 , -1 , 2 , 0},{113,288, 101600 , 0 , -1 , 2 , 0}, + {76,147 , 101598 , 0 , -1 , 2 , 0},{99,291 , 101600 , 0 , -1 , 2 , 0}, + {58,140 , 101598 , 0 , -1 , 2 , 0},{76,318 , 101600 , 0 , -1 , 2 , 0}, + {39,119 , 101598 , 0 , -1 , 2 , 0},{69,325 , 101600 , 0 , -1 , 2 , 0}, + {27,125 , 101598 , 0 , -1 , 2 , 0},{74,354 , 101600 , 0 , -1 , 2 , 0}, + {60,158 , 101598 , 0 , -1 , 2 , 0},{77,357 , 101600 , 0 , -1 , 2 , 0}, + {100,157, 101598 , 0 , -1 , 2 , 0},{100,375, 101600 , 0 , -1 , 2 , 0}, + {141,192, 101598 , 0 , -1 , 2 , 0},{126,403, 101600 , 0 , -1 , 2 , 0}, + {189,196, 101598 , 0 , -1 , 2 , 0},{160,399, 101600 , 0 , -1 , 2 , 0}, + {244,160, 101598 , 0 , -1 , 2 , 0},{176,433, 101600 , 0 , -1 , 2 , 0}, + {258,116, 101598 , 0 , -1 , 2 , 0},{205,364, 101600 , 0 , -1 , 2 , 0}, + {305,113, 101598 , 0 , -1 , 2 , 0},{191,330, 101600 , 0 , -1 , 2 , 0}, + {169,103, 101598 , 0 , -1 , 2 , 0},{150,329, 101600 , 0 , -1 , 2 , 0}, + {131,84 , 101598 , 0 , -1 , 2 , 0},{186,344, 101600 , 0 , -1 , 2 , 0}, + {196,97 , 101598 , 0 , -1 , 2 , 0},{183,413, 101600 , 0 , -1 , 2 , 0}, + {285,49 , 101598 , 0 , -1 , 2 , 0},{175,434, 101600 , 0 , -1 , 2 , 0}, + {330,24 , 101598 , 0 , -1 , 2 , 0},{162,462, 101600 , 0 , -1 , 2 , 0}, + {355,70 , 101598 , 0 , -1 , 2 , 0},{165,500, 101600 , 0 , -1 , 2 , 0}, + {328,60 , 101598 , 0 , -1 , 2 , 0},{180,510, 101600 , 0 , -1 , 2 , 0}, + {368,104, 101598 , 0 , -1 , 2 , 0},{137,489, 101600 , 0 , -1 , 2 , 0}, + {371,118, 101598 , 0 , -1 , 2 , 0},{130,491, 101600 , 0 , -1 , 2 , 0}, + {359,138, 101598 , 0 , -1 , 2 , 0},{114,443, 101600 , 0 , -1 , 2 , 0}, + {359,170, 101598 , 0 , -1 , 2 , 0},{99,470 , 101600 , 0 , -1 , 2 , 0}, + {349,131, 101598 , 0 , -1 , 2 , 0},{132,414, 101600 , 0 , -1 , 2 , 0}, + {372,177, 101598 , 0 , -1 , 2 , 0},{137,392, 101600 , 0 , -1 , 2 , 0}, + {381,203, 101598 , 0 , -1 , 2 , 0},{79,374 , 101600 , 0 , -1 , 2 , 0}, + // 101599 101601 + {141,202, 101599 , 0 , -1 , 2 , 0},{358,210, 101601 , 0 , -1 , 2 , 0}, + {125,162, 101599 , 0 , -1 , 2 , 0},{344,230, 101601 , 0 , -1 , 2 , 0}, + {243,94 , 101599 , 0 , -1 , 2 , 0},{326,229, 101601 , 0 , -1 , 2 , 0}, + {284,46 , 101599 , 0 , -1 , 2 , 0},{318,248, 101601 , 0 , -1 , 2 , 0}, + {317,126, 101599 , 0 , -1 , 2 , 0},{288,252, 101601 , 0 , -1 , 2 , 0}, + {354,75 , 101599 , 0 , -1 , 2 , 0},{274,255, 101601 , 0 , -1 , 2 , 0}, + {315,116, 101599 , 0 , -1 , 2 , 0},{243,263, 101601 , 0 , -1 , 2 , 0}, + {155,73 , 101599 , 0 , -1 , 2 , 0},{224,253, 101601 , 0 , -1 , 2 , 0}, + {161,78 , 101599 , 0 , -1 , 2 , 0},{208,252, 101601 , 0 , -1 , 2 , 0}, + {250,139, 101599 , 0 , -1 , 2 , 0},{178,254, 101601 , 0 , -1 , 2 , 0}, + {206,197, 101599 , 0 , -1 , 2 , 0},{160,260, 101601 , 0 , -1 , 2 , 0}, + {195,192, 101599 , 0 , -1 , 2 , 0},{135,264, 101601 , 0 , -1 , 2 , 0}, + {94,155 , 101599 , 0 , -1 , 2 , 0},{112,281, 101601 , 0 , -1 , 2 , 0}, + {77,153 , 101599 , 0 , -1 , 2 , 0},{103,296, 101601 , 0 , -1 , 2 , 0}, + {55,146 , 101599 , 0 , -1 , 2 , 0},{79,310 , 101601 , 0 , -1 , 2 , 0}, + {45,122 , 101599 , 0 , -1 , 2 , 0},{66,328 , 101601 , 0 , -1 , 2 , 0}, + {39,120 , 101599 , 0 , -1 , 2 , 0},{68,351 , 101601 , 0 , -1 , 2 , 0}, + {48,157 , 101599 , 0 , -1 , 2 , 0},{74,353 , 101601 , 0 , -1 , 2 , 0}, + {99,151 , 101599 , 0 , -1 , 2 , 0},{107,374, 101601 , 0 , -1 , 2 , 0}, + {136,182, 101599 , 0 , -1 , 2 , 0},{138,393, 101601 , 0 , -1 , 2 , 0}, + {173,203, 101599 , 0 , -1 , 2 , 0},{163,399, 101601 , 0 , -1 , 2 , 0}, + {223,160, 101599 , 0 , -1 , 2 , 0},{171,411, 101601 , 0 , -1 , 2 , 0}, + {254,121, 101599 , 0 , -1 , 2 , 0},{214,383, 101601 , 0 , -1 , 2 , 0}, + {315,118, 101599 , 0 , -1 , 2 , 0},{192,330, 101601 , 0 , -1 , 2 , 0}, + {234,69 , 101599 , 0 , -1 , 2 , 0},{155,322, 101601 , 0 , -1 , 2 , 0}, + {123,88 , 101599 , 0 , -1 , 2 , 0},{183,336, 101601 , 0 , -1 , 2 , 0}, + {164,80 , 101599 , 0 , -1 , 2 , 0},{182,421, 101601 , 0 , -1 , 2 , 0}, + {284,45 , 101599 , 0 , -1 , 2 , 0},{175,430, 101601 , 0 , -1 , 2 , 0}, + {333,30 , 101599 , 0 , -1 , 2 , 0},{150,415, 101601 , 0 , -1 , 2 , 0}, + {352,62 , 101599 , 0 , -1 , 2 , 0},{169,498, 101601 , 0 , -1 , 2 , 0}, + {335,83 , 101599 , 0 , -1 , 2 , 0},{188,517, 101601 , 0 , -1 , 2 , 0}, + {363,100, 101599 , 0 , -1 , 2 , 0},{118,492, 101601 , 0 , -1 , 2 , 0}, + {370,103, 101599 , 0 , -1 , 2 , 0},{136,490, 101601 , 0 , -1 , 2 , 0}, + {338,91 , 101599 , 0 , -1 , 2 , 0},{113,446, 101601 , 0 , -1 , 2 , 0}, + {359,153, 101599 , 0 , -1 , 2 , 0},{110,464, 101601 , 0 , -1 , 2 , 0}, + {363,162, 101599 , 0 , -1 , 2 , 0},{134,424, 101601 , 0 , -1 , 2 , 0}, + {373,171, 101599 , 0 , -1 , 2 , 0},{127,403, 101601 , 0 , -1 , 2 , 0}, + {385,192, 101599 , 0 , -1 , 2 , 0},{85,377 , 101601 , 0 , -1 , 2 , 0}, + // С̺ 101603 С̺ 101605 + {136,173, 101603 , 0 , -1 , 2 , 0},{349,213, 101605 , 0 , -1 , 2 , 0}, + {118,158, 101603 , 0 , -1 , 2 , 0},{339,225, 101605 , 0 , -1 , 2 , 0}, + {227,75 , 101603 , 0 , -1 , 2 , 0},{322,244, 101605 , 0 , -1 , 2 , 0}, + {286,57 , 101603 , 0 , -1 , 2 , 0},{299,247, 101605 , 0 , -1 , 2 , 0}, + {353,90 , 101603 , 0 , -1 , 2 , 0},{281,258, 101605 , 0 , -1 , 2 , 0}, + {322,70 , 101603 , 0 , -1 , 2 , 0},{272,256, 101605 , 0 , -1 , 2 , 0}, + {352,40 , 101603 , 0 , -1 , 2 , 0},{230,249, 101605 , 0 , -1 , 2 , 0}, + {155,52 , 101603 , 0 , -1 , 2 , 0},{216,248, 101605 , 0 , -1 , 2 , 0}, + {152,71 , 101603 , 0 , -1 , 2 , 0},{190,243, 101605 , 0 , -1 , 2 , 0}, + {234,168, 101603 , 0 , -1 , 2 , 0},{172,255, 101605 , 0 , -1 , 2 , 0}, + {199,190, 101603 , 0 , -1 , 2 , 0},{150,258, 101605 , 0 , -1 , 2 , 0}, + {175,203, 101603 , 0 , -1 , 2 , 0},{117,271, 101605 , 0 , -1 , 2 , 0}, + {85,141 , 101603 , 0 , -1 , 2 , 0},{109,284, 101605 , 0 , -1 , 2 , 0}, + {72,151 , 101603 , 0 , -1 , 2 , 0},{100,301, 101605 , 0 , -1 , 2 , 0}, + {44,139 , 101603 , 0 , -1 , 2 , 0},{75,315 , 101605 , 0 , -1 , 2 , 0}, + {45,122 , 101603 , 0 , -1 , 2 , 0},{74,311 , 101605 , 0 , -1 , 2 , 0}, + {29,116 , 101603 , 0 , -1 , 2 , 0},{61,367 , 101605 , 0 , -1 , 2 , 0}, + {72,151 , 101603 , 0 , -1 , 2 , 0},{48,346 , 101605 , 0 , -1 , 2 , 0}, + {115,157, 101603 , 0 , -1 , 2 , 0},{111,376, 101605 , 0 , -1 , 2 , 0}, + {154,202, 101603 , 0 , -1 , 2 , 0},{142,397, 101605 , 0 , -1 , 2 , 0}, + {212,183, 101603 , 0 , -1 , 2 , 0},{162,398, 101605 , 0 , -1 , 2 , 0}, + {244,157, 101603 , 0 , -1 , 2 , 0},{188,385, 101605 , 0 , -1 , 2 , 0}, + {256,105, 101603 , 0 , -1 , 2 , 0},{199,363, 101605 , 0 , -1 , 2 , 0}, + {281,113, 101603 , 0 , -1 , 2 , 0},{188,322, 101605 , 0 , -1 , 2 , 0}, + {154,73 , 101603 , 0 , -1 , 2 , 0},{161,330, 101605 , 0 , -1 , 2 , 0}, + {148,73 , 101603 , 0 , -1 , 2 , 0},{185,389, 101605 , 0 , -1 , 2 , 0}, + {252,41 , 101603 , 0 , -1 , 2 , 0},{173,430, 101605 , 0 , -1 , 2 , 0}, + {296,59 , 101603 , 0 , -1 , 2 , 0},{134,436, 101605 , 0 , -1 , 2 , 0}, + {312,67 , 101603 , 0 , -1 , 2 , 0},{189,470, 101605 , 0 , -1 , 2 , 0}, + {352,62 , 101603 , 0 , -1 , 2 , 0},{184,506, 101605 , 0 , -1 , 2 , 0}, + {333,86 , 101603 , 0 , -1 , 2 , 0},{164,499, 101605 , 0 , -1 , 2 , 0}, + {371,113, 101603 , 0 , -1 , 2 , 0},{156,486, 101605 , 0 , -1 , 2 , 0}, + {397,131, 101603 , 0 , -1 , 2 , 0},{110,491, 101605 , 0 , -1 , 2 , 0}, + {353,132, 101603 , 0 , -1 , 2 , 0},{117,438, 101605 , 0 , -1 , 2 , 0}, + {363,164, 101603 , 0 , -1 , 2 , 0},{99,480 , 101605 , 0 , -1 , 2 , 0}, + {365,165, 101603 , 0 , -1 , 2 , 0},{142,398, 101605 , 0 , -1 , 2 , 0}, + {373,184, 101603 , 0 , -1 , 2 , 0},{105,385, 101605 , 0 , -1 , 2 , 0}, + {372,185, 101603 , 0 , -1 , 2 , 0},{71,371 , 101605 , 0 , -1 , 2 , 0}, + //С캣 101602 С캣 101604 + + {154,200, 101602 , 0 , -1 , 2 , 0},{349,211, 101604 , 0 , -1 , 2 , 0}, + {119,157, 101602 , 0 , -1 , 2 , 0},{345,231, 101604 , 0 , -1 , 2 , 0}, + {239,82 , 101602 , 0 , -1 , 2 , 0},{326,243, 101604 , 0 , -1 , 2 , 0}, + {290,59 , 101602 , 0 , -1 , 2 , 0},{312,248, 101604 , 0 , -1 , 2 , 0}, + {358,99 , 101602 , 0 , -1 , 2 , 0},{281,253, 101604 , 0 , -1 , 2 , 0}, + {328,69 , 101602 , 0 , -1 , 2 , 0},{265,257, 101604 , 0 , -1 , 2 , 0}, + {258,37 , 101602 , 0 , -1 , 2 , 0},{235,247, 101604 , 0 , -1 , 2 , 0}, + {153,51 , 101602 , 0 , -1 , 2 , 0},{219,248, 101604 , 0 , -1 , 2 , 0}, + {153,72 , 101602 , 0 , -1 , 2 , 0},{197,244, 101604 , 0 , -1 , 2 , 0}, + {132,187, 101602 , 0 , -1 , 2 , 0},{174,252, 101604 , 0 , -1 , 2 , 0}, + {131,179, 101602 , 0 , -1 , 2 , 0},{161,257, 101604 , 0 , -1 , 2 , 0}, + {120,169, 101602 , 0 , -1 , 2 , 0},{131,271, 101604 , 0 , -1 , 2 , 0}, + {101,151, 101602 , 0 , -1 , 2 , 0},{108,285, 101604 , 0 , -1 , 2 , 0}, + {71,158 , 101602 , 0 , -1 , 2 , 0},{97,294 , 101604 , 0 , -1 , 2 , 0}, + {58,139 , 101602 , 0 , -1 , 2 , 0},{75,311 , 101604 , 0 , -1 , 2 , 0}, + {29,128 , 101602 , 0 , -1 , 2 , 0},{71,311 , 101604 , 0 , -1 , 2 , 0}, + {20,119 , 101602 , 0 , -1 , 2 , 0},{77,356 , 101604 , 0 , -1 , 2 , 0}, + {67,156 , 101602 , 0 , -1 , 2 , 0},{47,349 , 101604 , 0 , -1 , 2 , 0}, + {108,157, 101602 , 0 , -1 , 2 , 0},{87,372 , 101604 , 0 , -1 , 2 , 0}, + {149,200, 101602 , 0 , -1 , 2 , 0},{128,406, 101604 , 0 , -1 , 2 , 0}, + {187,190, 101602 , 0 , -1 , 2 , 0},{141,396, 101604 , 0 , -1 , 2 , 0}, + {238,157, 101602 , 0 , -1 , 2 , 0},{176,434, 101604 , 0 , -1 , 2 , 0}, + {270,120, 101602 , 0 , -1 , 2 , 0},{200,358, 101604 , 0 , -1 , 2 , 0}, + {271,120, 101602 , 0 , -1 , 2 , 0},{187,326, 101604 , 0 , -1 , 2 , 0}, + {155,57 , 101602 , 0 , -1 , 2 , 0},{151,334, 101604 , 0 , -1 , 2 , 0}, + {140,88 , 101602 , 0 , -1 , 2 , 0},{182,404, 101604 , 0 , -1 , 2 , 0}, + {240,70 , 101602 , 0 , -1 , 2 , 0},{165,419, 101604 , 0 , -1 , 2 , 0}, + {287,51 , 101602 , 0 , -1 , 2 , 0},{134,438, 101604 , 0 , -1 , 2 , 0}, + {302,57 , 101602 , 0 , -1 , 2 , 0},{182,471, 101604 , 0 , -1 , 2 , 0}, + {355,64 , 101602 , 0 , -1 , 2 , 0},{174,503, 101604 , 0 , -1 , 2 , 0}, + {342,93 , 101602 , 0 , -1 , 2 , 0},{186,505, 101604 , 0 , -1 , 2 , 0}, + {369,107, 101602 , 0 , -1 , 2 , 0},{148,487, 101604 , 0 , -1 , 2 , 0}, + {372,123, 101602 , 0 , -1 , 2 , 0},{120,491, 101604 , 0 , -1 , 2 , 0}, + {355,138, 101602 , 0 , -1 , 2 , 0},{117,438, 101604 , 0 , -1 , 2 , 0}, + {366,161, 101602 , 0 , -1 , 2 , 0},{98,475 , 101604 , 0 , -1 , 2 , 0}, + {363,163, 101602 , 0 , -1 , 2 , 0},{132,411, 101604 , 0 , -1 , 2 , 0}, + {369,181, 101602 , 0 , -1 , 2 , 0},{110,391, 101604 , 0 , -1 , 2 , 0}, + {374,189, 101602 , 0 , -1 , 2 , 0},{81,373 , 101604 , 0 , -1 , 2 , 0}, +}; +#endif + +#ifdef _STREET_VENDOR +int iOldGX,iOldGY; +extern ITEM_BUFFER ItemBuffer[MAX_ITEM]; +ACTION *pActStreetVendorWnd = NULL; +ACTION *pActStreetVendorBuyWnd = NULL; +short sStreetVendorBtn = 0; +short sStreetVendorBuyBtn = 0; +short sStreetVendorBtnFocus = 0; +int sStreetVendorBtnGraNo[] = +{ + CG_FIELD_SV_BTN_OFF, + CG_FIELD_SV_BTN_ON +}; + +// ۼӴ +extern void CheckNumber(char *buf,int num); +static ACTION *pActSellPriceWnd = NULL; +int SellPriceWndfunc() +{ + static STR_BUFFER str_bufferMoney; // ۼ,һǧ + int x,y,iConfirm; + + if (pActSellPriceWnd == NULL) + { + int winW = 106; + int winH = 80; + int winX = (lpDraw->xSize-winW)/2; + int winY = (lpDraw->ySize-winH)/2; + + pActSellPriceWnd = MakeWindowDisp(winX, winY, + winW, winH, CG_FIELD_SV_SELL_PRICE_PANEL, -1, FALSE); + // ۼֳʼ + ZeroMemory(str_bufferMoney.buffer, sizeof(str_bufferMoney.buffer)); + str_bufferMoney.cnt = 0; + str_bufferMoney.cursor = 0; + str_bufferMoney.color = 0; + str_bufferMoney.len = 8; + str_bufferMoney.lineLen = 8; + str_bufferMoney.lineDist = 0; + str_bufferMoney.x = pActSellPriceWnd->x + 10; + str_bufferMoney.y = pActSellPriceWnd->y + 28; + str_bufferMoney.fontPrio = FONT_PRIO_FRONT; + GetKeyInputFocus(&str_bufferMoney); + } + else + { + if (pActSellPriceWnd->hp > 0) + { + x = pActSellPriceWnd->x; + y = pActSellPriceWnd->y; + StockDispBuffer(((WINDOW_DISP *)pActSellPriceWnd->pYobi)->mx, + ((WINDOW_DISP *)pActSellPriceWnd->pYobi)->my, + DISP_PRIO_MENU, CG_FIELD_SV_SELL_PRICE_PANEL, 1); + iConfirm = StockDispBuffer(x + 55,y + 67, DISP_PRIO_IME3, 26289, 2); + + // ȷ + if ((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == iConfirm) + { + DeathAction(pActSellPriceWnd); + pActSellPriceWnd = NULL; + GetKeyInputFocus(&MyChatBuffer); + return atoi(str_bufferMoney.buffer); + } + // ۼ + if (MakeHitBox(str_bufferMoney.x, str_bufferMoney.y, str_bufferMoney.x + 88, str_bufferMoney.y + 22, DISP_PRIO_BOX2) == TRUE) + GetKeyInputFocus(&str_bufferMoney); + CheckNumber(str_bufferMoney.buffer, 10000000); + // ʾ۸ + StockFontBuffer2(&str_bufferMoney); + } + } + + return -1; +} + +// ̯Ӵ + +extern void CheckSpace(char *buf); +ACTION *pShowPet = NULL; +Show_Sell_Item ShowSellItem[MAX_SELL_ITEM]; +STR_BUFFER str_bufferVendorName; // + +Show_Sell_Item *GetEmptyShowSellItem(Show_Sell_Item *ShowSellItem) +{ + for (int i = 0; i < MAX_SELL_ITEM; i++) + { + if (ShowSellItem[i].usage == false) + return ShowSellItem + i; + } + return NULL; +} + +void StreetVendorWndfunc(bool bReset,char *data) +{ + int i,j,x,y,itemx,itemy,selId = 0; + char temp[8],szMsg[128]; + static int iBtn[7],iSellItemBtn[MAX_SELL_ITEM],iShowPet,iPetOnSell[MAX_PET],iGetSellPrice,iListStart; + static ITEM *pItem = NULL; + static bool bChangePet = true,bRunSellPrice = false; + static Show_Sell_Item *pShowSellItem = NULL; +#ifdef _NEW_ITEM_ + extern int ҳ; + static int iItemOnSell[MAX_MAXHAVEITEM*3]; +#else + static int iItemOnSell[MAX_MAXHAVEITEM]; +#endif + if (pActStreetVendorWnd == NULL) + { + int winW = 622; + int winH = 413; + int winX = (lpDraw->xSize-winW)/2; + int winY = (lpDraw->ySize-winH)/2; +#ifdef _NEW_ITEM_ + ҳ=0; +#endif + +#ifdef _NEW_RESOMODE + pActStreetVendorWnd = MakeWindowDisp(winX, winY, winW, winH, CG_FIELD_SV_SELL_PANEL, -1, FALSE); +#else + pActStreetVendorWnd = MakeWindowDisp((DEF_APPSIZEX >> 1) - (622 >> 1), 0, 622, 413, CG_FIELD_SV_SELL_PANEL, -1); +#endif + memset(iBtn, -1, sizeof(iBtn)); + memset(iItemOnSell, -1, sizeof(iItemOnSell)); + memset(iPetOnSell, -1, sizeof(iPetOnSell)); + for (i = 0; i < MAX_SELL_ITEM; i++) + { + ShowSellItem[i].name[0] = '\0'; + ShowSellItem[i].freeName[0] = '\0'; + ShowSellItem[i].needGetPrice = false; + ShowSellItem[i].pile = 0; + ShowSellItem[i].price = 0; + ShowSellItem[i].usage = false; + ShowSellItem[i].kind = -1; + ShowSellItem[i].index = -1; + } + if (bReset) + { + // ֳʼ + ZeroMemory(str_bufferVendorName.buffer, sizeof(str_bufferVendorName.buffer)); + str_bufferVendorName.cnt = 0; + str_bufferVendorName.cursor = 0; + str_bufferVendorName.color = 0; + str_bufferVendorName.len = 16; + str_bufferVendorName.lineLen = 16; + str_bufferVendorName.lineDist = 0; + str_bufferVendorName.x = pActStreetVendorWnd->x + 25; + str_bufferVendorName.y = pActStreetVendorWnd->y + 346; + str_bufferVendorName.fontPrio = FONT_PRIO_FRONT; + } + pItem = pc.item; + iShowPet = 0; + iListStart = 0; + bChangePet = true; + bRunSellPrice = false; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + pShowSellItem = NULL; + if (data != NULL) + { + int count = 0, kind, index, price; + + getStringToken(data, '|', 2, sizeof(szMsg) - 1, szMsg); + count = atoi(szMsg); + for (i = 0; i < count; i++) + { + getStringToken(data, '|', 3 + i * 3, sizeof(szMsg) - 1, szMsg); + kind = atoi(szMsg); + getStringToken(data, '|', 4 + i * 3, sizeof(szMsg) - 1, szMsg); + index = atoi(szMsg); + getStringToken(data, '|', 5 + i * 3, sizeof(szMsg) - 1, szMsg); + price = atoi(szMsg); + pShowSellItem = GetEmptyShowSellItem(ShowSellItem); + if (pShowSellItem != NULL) + { + // + if (kind == 0 && pItem[index].useFlag) + { + pShowSellItem->kind = kind; + pShowSellItem->index = index; + pShowSellItem->price = price; + sprintf_s(pShowSellItem->name, "%s", pItem[index].name); + pShowSellItem->pile = pItem[index].pile; + pShowSellItem->usage = true; + iItemOnSell[index - 9] = index; + } + // + else if(kind == 1 && pet[index].useFlag) + { + pShowSellItem->kind = kind; + pShowSellItem->index = index; + pShowSellItem->price = price; + sprintf_s(pShowSellItem->name, "%s", pet[index].name); + sprintf_s(pShowSellItem->freeName, "%s", pet[index].freeName); + pShowSellItem->pile = 1; + pShowSellItem->usage = true; + iPetOnSell[index] = index; + } + } + } + } + } + else + { + if (pActStreetVendorWnd->hp > 0) + { + if (bRunSellPrice) + { + iGetSellPrice = SellPriceWndfunc(); + if (iGetSellPrice != -1) + { + for(i = 0; i x; + y = pActStreetVendorWnd->y; + selId = focusFontId(iSellItemBtn, sizeof(iSellItemBtn) / sizeof(int)); + + // ʾ趨buttonֵλ + // ȷ + iBtn[0] = StockDispBuffer(x + 80, y + 388, DISP_PRIO_IME3, 26289, 2); + // ȡ + iBtn[1] = StockDispBuffer(x + 230, y + 388, DISP_PRIO_IME3, 26291, 2); + // Ͼͷ + iBtn[2] = StockDispBuffer(x + 305, y + 44, DISP_PRIO_IME3, 26331, 2); + // ¾ͷ + iBtn[3] = StockDispBuffer(x + 305, y + 304, DISP_PRIO_IME3, 26332, 2); + // ðť + iBtn[4] = StockDispBuffer(x + 335, y + 300, DISP_PRIO_IME3, 26062, 2); + // ͷ + iBtn[5] = StockDispBuffer(x + 520, y + 60, DISP_PRIO_IME3, 26047, 2); + // Ҽͷ + iBtn[6] = StockDispBuffer(x + 570, y + 60, DISP_PRIO_IME3, 26048, 2); + + // ʾ󷽵Ʒб + for (i = iListStart, j = 0; i < iListStart + 10; i++, j++) + { + if (ShowSellItem[i].usage) + { +#ifdef _NEWFONT_ + extern int getTextLength(char * str); + char tempstr[128]; + if (ShowSellItem[i].kind == 0){ + if (ShowSellItem[i].price == 0){ + StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].name, 0); + sprintf(tempstr,"x%d",ShowSellItem[i].pile); + StockFontBuffer(x + 180-getTextLength(tempstr)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + StockFontBuffer(x + 250-getTextLength("")/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + }else{ + StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].name, 0); + sprintf(tempstr,"x%d",ShowSellItem[i].pile); + StockFontBuffer(x + 180-getTextLength(tempstr)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + sprintf(tempstr,"%d",ShowSellItem[i].price); + StockFontBuffer(x + 250-getTextLength(tempstr)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + } + }else{ + if (ShowSellItem[i].price == 0){ + StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].name, 0); + StockFontBuffer(x + 175- getTextLength(ShowSellItem[i].freeName)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].freeName, 0); + StockFontBuffer(x + 250-getTextLength("")/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + }else{ + StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].name, 0); + StockFontBuffer(x + 175 - getTextLength(ShowSellItem[i].freeName)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowSellItem[i].freeName, 0); + sprintf(tempstr,"%d",ShowSellItem[i].price); + StockFontBuffer(x + 250-getTextLength(tempstr)/2, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + } + } + iSellItemBtn[j] = StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, + " ", 2); +#else + if (ShowSellItem[i].kind == 0) + { + if (ShowSellItem[i].price == 0) + sprintf_s(szMsg, "%-20sx%3d%13s", ShowSellItem[i].name, ShowSellItem[i].pile, ""); + else + sprintf_s(szMsg, "%-20sx%3d%13d", ShowSellItem[i].name, ShowSellItem[i].pile, ShowSellItem[i].price); + } + else + { + if (ShowSellItem[i].price == 0) + sprintf_s(szMsg, "%-17s%-12s%8s", ShowSellItem[i].name, ShowSellItem[i].freeName, ""); + else + sprintf_s(szMsg, "%-17s%-12s%8d", ShowSellItem[i].name, ShowSellItem[i].freeName, ShowSellItem[i].price); + } + iSellItemBtn[j] = StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 2); +#endif + } + else + iSellItemBtn[j] = StockFontBuffer(x + 20, y + 32 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + } + + for (i = 0; i < 7; i++) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (HitDispNo == iBtn[i]) + { + play_se(217, 320, 240); + switch (i) + { + // ȷ + case 0: + if (!bRunSellPrice) + { + int count = 0; + char szMsg[512], szTemp[512], szTemp1[16]; + + memset(szMsg, 0, sizeof(szMsg)); + memset(szTemp, 0, sizeof(szTemp)); + // ҪĶserver + for (j = 0; j < MAX_SELL_ITEM; j++) + { + if (ShowSellItem[j].usage) + { + sprintf_s(szTemp1, "%d|%d|%d|", ShowSellItem[j].kind, ShowSellItem[j].index, ShowSellItem[j].price); + strcat_s(szTemp, szTemp1); + count++; // ͳ + } + } + if (count != 0) + { + if (str_bufferVendorName.cnt == 0 || str_bufferVendorName.cnt>16) + { + sprintf_s(str_bufferVendorName.buffer, "ӭ!!"); + str_bufferVendorName.cnt = 10; + } + sprintf_s(szMsg, "S|%d|%s%s", count, szTemp, str_bufferVendorName.buffer); + lssproto_STREET_VENDOR_send(sockfd, szMsg); + // ̯,Ҫ + if (pc.ridePetNo > -1) + { + char buf[64]; + + sprintf_s(buf, "R|P|-1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + lssproto_FM_send(sockfd, buf); + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, pc.ridePetNo, 0); + } + } + else + { + lssproto_STREET_VENDOR_send(sockfd, "E|"); + pc.iOnStreetVendor = 0; + } + } + else + break; + // ȡ + case 1: + if (i == 1) + { + lssproto_STREET_VENDOR_send(sockfd, "E|"); + pc.iOnStreetVendor = 0; + } + sStreetVendorBtn = 0; + actBtn = 0; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + if (pActSellPriceWnd != NULL) + DeathAction(pActSellPriceWnd); + pActSellPriceWnd = NULL; + GetKeyInputFocus(&MyChatBuffer); + break; + // Ͼ + case 2: + iListStart--; + if (iListStart < 0) + iListStart = 0; + break; + // ¾ + case 3: + iListStart++; + if (iListStart > 10) + iListStart = 10; + break; + // + case 4: + if (!bRunSellPrice) + { + pShowSellItem = GetEmptyShowSellItem(ShowSellItem); + // пռ + if (pShowSellItem != NULL && iPetOnSell[iShowPet] == -1 && pShowPet != NULL) + { + iPetOnSell[iShowPet] = iShowPet; + bRunSellPrice = true; + pShowSellItem->usage = true; + pShowSellItem->needGetPrice = true; + sprintf_s(pShowSellItem->name, "%s", pet[iShowPet].name); + sprintf_s(pShowSellItem->freeName, "%s", pet[iShowPet].freeName); + pShowSellItem->pile = 1; + pShowSellItem->kind = 1; + pShowSellItem->index = iShowPet; + } + } + break; + // ͷ + case 5: + if (!bRunSellPrice) + { + iShowPet = (iShowPet + 1 > 4 ? 0:iShowPet + 1); + bChangePet = true; + } + break; + // Ҽͷ + case 6: + if (!bRunSellPrice) + { + iShowPet = (iShowPet - 1 < 0 ? 4:iShowPet - 1); + bChangePet = true; + } + break; + } + break; + } + } + } + if (!bRunSellPrice) + { + for (i = 0; i < 10; i++) + { + // ޸ļ۸ + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (selId == iSellItemBtn[i]) + { + ShowSellItem[i + iListStart].needGetPrice = true; + bRunSellPrice = true; + break; + } + } + // ȡ + else if (mouse.onceState & MOUSE_RIGHT_CRICK) + { + if (selId == iSellItemBtn[i]) + { + if (ShowSellItem[i + iListStart].kind == 0) + iItemOnSell[ShowSellItem[i + iListStart].index - 9] = -1; + else + iPetOnSell[ShowSellItem[i + iListStart].index] = -1; + ShowSellItem[i+iListStart].name[0] = '\0'; + ShowSellItem[i+iListStart].freeName[0] = '\0'; + ShowSellItem[i+iListStart].needGetPrice = false; + ShowSellItem[i+iListStart].pile = 0; + ShowSellItem[i+iListStart].price = 0; + ShowSellItem[i+iListStart].usage = false; + ShowSellItem[i+iListStart].kind = -1; + ShowSellItem[i+iListStart].index = -1; + break; + } + } + } + } + + + +#ifdef _NEW_ITEM_ + for(i=0;i<3;i++){ + if(i==ҳ){ + StockDispBuffer(722,350+i*56, DISP_PRIO_IME3,55223+i, 1); + }else{ + BOOL flg=FALSE; + if(i){ + if(pc.״̬&1<usage = true; + pShowSellItem->needGetPrice = true; + sprintf_s(pShowSellItem->name, "%s", pItem[].name); + pShowSellItem->pile = pItem[].pile; + pShowSellItem->kind = 0; + pShowSellItem->index = ; + } + } + } + } +#else + if (pItem[j * 5 + i + 9].useFlag) + { + if (!bRunSellPrice) + StockDispBuffer(itemx + 25, itemy + 25, DISP_PRIO_ITEM, pItem[j * 5 + i + 9].graNo, 0); + // ۸Ӵ,disp_prio 趨menuŲڼ۸Ӵ + else + StockDispBuffer(itemx + 25, itemy + 25, DISP_PRIO_MENU, pItem[j * 5 + i + 9].graNo, 0); + } + if (iItemOnSell[j * 5 + i] != -1) + { + // ۸Ӵ,ʾsell + if (!bRunSellPrice) + StockFontBuffer(itemx + 25, itemy + 25, FONT_PRIO_FRONT, FONT_PAL_RED, "SELL", 0); + } + if (!bRunSellPrice) + { + if (MakeHitBox(itemx, itemy, itemx + 50, itemy + 47, DISP_PRIO_IME3) == TRUE) + { +#ifdef _NPC_ITEMUP + if( pItem[j * 5 + i + 9].useFlag ) + ShowItemup(pItem[j * 5 + i + 9].itemup,mouse.nowPoint.x,mouse.nowPoint.y); +#endif + // + if (pItem[j * 5 + i + 9].useFlag && + // жϵǷѡ + (mouse.onceState & MOUSE_LEFT_DBL_CRICK) && + // û + (iItemOnSell[j * 5 + i] == -1) + ) + { + pShowSellItem = GetEmptyShowSellItem(ShowSellItem); + // пռ + if (pShowSellItem != NULL) + { + iItemOnSell[j * 5 + i] = j * 5 + i + 9; // ¼ǸҪ + play_se(217,320,240); + bRunSellPrice = true; + pShowSellItem->usage = true; + pShowSellItem->needGetPrice = true; + sprintf_s(pShowSellItem->name, "%s", pItem[j * 5 + i + 9].name); + pShowSellItem->pile = pItem[j * 5 + i + 9].pile; + pShowSellItem->kind = 0; + pShowSellItem->index = j * 5 + i + 9; + } + } + } + } +#endif + } + } + // + for (i = 0; i < MAX_PET; i++) + { + if (bChangePet && !bRunSellPrice) + { + // ֻҲ˼趨ɳʵij + if (pet[iShowPet].useFlag == 1 && (pc.ridePetNo != iShowPet) && (pc.mailPetNo != iShowPet)) + { + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + pShowPet = MakeAnimDisp(x + 396, y + 170, pet[iShowPet].graNo, 0); + bChangePet = false; + break; + } + else + { + if (HitDispNo == iBtn[5]) + iShowPet = (iShowPet + 1 > 4 ? 0:iShowPet + 1); + else if (HitDispNo == iBtn[6]) + iShowPet = (iShowPet - 1 < 0 ? 4:iShowPet - 1); + else + iShowPet = (iShowPet + 1 > 4 ? 0:iShowPet + 1); + } + } + if (pShowPet != NULL) + { + // ʾ + if (iPetOnSell[iShowPet] != -1) + StockFontBuffer(x + 440, y + 195, FONT_PRIO_FRONT, FONT_PAL_RED, "SELL", 0); + // ʾ + if (strlen(pet[iShowPet].freeName) > 0) + StockFontBuffer(x + 336, y + 28, FONT_PRIO_FRONT, 0, pet[iShowPet].freeName, 0); + else + StockFontBuffer(x + 336, y + 28, FONT_PRIO_FRONT, 0, pet[iShowPet].name, 0); + // ʾ + _itoa_s(pet[iShowPet].level, temp, 10); + StockFontBuffer(x + 542, y + 92 , FONT_PRIO_FRONT, FONT_PAL_WHITE, temp, 0); + _itoa_s(pet[iShowPet].atk, temp, 10); + StockFontBuffer(x + 542, y + 92 + 25, FONT_PRIO_FRONT, FONT_PAL_WHITE, temp, 0); + _itoa_s(pet[iShowPet].def, temp, 10); + StockFontBuffer(x + 542, y + 92 + 50, FONT_PRIO_FRONT, FONT_PAL_WHITE, temp, 0); + _itoa_s(pet[iShowPet].quick, temp, 10); + StockFontBuffer(x + 542, y + 92 + 73, FONT_PRIO_FRONT, FONT_PAL_WHITE, temp, 0); + _itoa_s(pet[iShowPet].maxHp, temp, 10); + StockFontBuffer(x + 542, y + 92 + 97, FONT_PRIO_FRONT, FONT_PAL_WHITE, temp, 0); + } + } + // û + if (i == MAX_PET && bChangePet) + { + bChangePet = false; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + } + // ڵ + if (MakeHitBox(str_bufferVendorName.x, str_bufferVendorName.y, str_bufferVendorName.x + 250, + str_bufferVendorName.y + 24, DISP_PRIO_BOX2) == TRUE) + GetKeyInputFocus(&str_bufferVendorName); + CheckSpace(str_bufferVendorName.buffer); + // ʾ + StockFontBuffer2(&str_bufferVendorName); + StockDispBuffer(((WINDOW_DISP *)pActStreetVendorWnd->pYobi)->mx, + ((WINDOW_DISP *)pActStreetVendorWnd->pYobi)->my, + DISP_PRIO_MENU, CG_FIELD_SV_SELL_PANEL, 1); + } + } +} + +// ̯ +Show_Vendor_Item ShowVendorItem[MAX_SELL_ITEM]; + +void StreetVendorBuyWndfunc(char *data) +{ + int i,j,x,y,selId = 0; + const int iMaxBtnNum = 5; + static int iBtn[iMaxBtnNum],iBuyItemBtn[MAX_SELL_ITEM],iListStart,iTotalBuy[2]; //iTotalBuy[0]: iTotalBuy[1]: + static int iEmptyNum[2],iCurrentShow,iTotalBuyMoney; // iEmptyNum[0]:ϵλ iEmptyNum[1]:λ + static int iMakePetAni = -1; +#ifdef _PET_ITEM + static BOOL bViewPetItem = FALSE; +#endif + char szMsg[1024]; + + if (pActStreetVendorBuyWnd == NULL) + { + int winW = 617; + int winH = 405; + int winX = (lpDraw->xSize-winW)/2; + int winY = (lpDraw->ySize-winH)/2; + +#ifdef _NEW_RESOMODE + pActStreetVendorBuyWnd = MakeWindowDisp(winX, winY, winW, winH, CG_FIELD_SV_BUY_PANEL, -1, FALSE); +#else + pActStreetVendorBuyWnd = MakeWindowDisp((DEF_APPSIZEX >> 1) - (617 >> 1), 0, 617, 405, CG_FIELD_SV_BUY_PANEL, -1); +#endif + + memset(ShowVendorItem, 0, sizeof(ShowVendorItem)); + memset(iBuyItemBtn, 0, sizeof(iBuyItemBtn)); + iTotalBuy[0] = iTotalBuy[1] = iListStart = iEmptyNum[0] = iEmptyNum[1] = iCurrentShow = iTotalBuyMoney = 0; + iMakePetAni = -1; + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++) + { + if (pc.item[i].useFlag == FALSE) + iEmptyNum[0]++; + } + for (i = 0; i < MAX_PET; i++) + { + if (pet[i].useFlag == 0) + iEmptyNum[1]++; + } + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } +#ifdef _PET_ITEM + InitItem(pActStreetVendorBuyWnd->x + 310, pActStreetVendorBuyWnd->y + 20, TRUE); +#endif + } + else + { + if (pActStreetVendorBuyWnd->hp > 0) + { + x = pActStreetVendorBuyWnd->x; + y = pActStreetVendorBuyWnd->y; + selId = focusFontId(iBuyItemBtn, sizeof(iBuyItemBtn) / sizeof(int)); + // ʾ趨buttonֵλ + // ȷ + iBtn[0] = StockDispBuffer(x + 410, y + 378, DISP_PRIO_IME3, 26289, 2); + // ȡ + iBtn[1] = StockDispBuffer(x + 535, y + 378, DISP_PRIO_IME3, 26291, 2); + // Ͼͷ + iBtn[2] = StockDispBuffer(x + 300, y + 34, DISP_PRIO_IME3, 26331, 2); + // ¾ͷ + iBtn[3] = StockDispBuffer(x + 300, y + 374, DISP_PRIO_IME3, 26332, 2); +#ifdef _PET_ITEM + if (bViewPetItem) + iBtn[4] = StockDispBuffer(x + 560, y + 318, DISP_PRIO_IME3, 26472, 2); + else + iBtn[4] = StockDispBuffer(x + 560, y + 318, DISP_PRIO_IME3, 26471, 2); +#endif + for (i = 0; i < iMaxBtnNum; i++) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (HitDispNo == iBtn[i]) + { + play_se(217, 320, 240); + switch (i) + { + // ȷ + case 0: + { + int count = 0; + char szMsg[128], szTemp[128], szTemp1[8]; + + memset(szMsg, 0, sizeof(szMsg)); + memset(szTemp, 0, sizeof(szTemp)); + // ҪĶserver + for(j = 0; j < MAX_SELL_ITEM; j++) + { + if (ShowVendorItem[j].bBuy) + { + sprintf_s(szTemp1, "%d|", ShowVendorItem[j].index); + strcat_s(szTemp, szTemp1); + count++; // ͳ + } + } + if (count != 0) + { + sprintf_s(szMsg, "B|%d|%s", count, szTemp); + lssproto_STREET_VENDOR_send(sockfd, szMsg); + } + else + lssproto_STREET_VENDOR_send(sockfd, "N|"); + } + // ȡ + case 1: + if (i == 1) + lssproto_STREET_VENDOR_send(sockfd, "N|"); + sStreetVendorBuyBtn = 0; + actBtn = 0; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + if (pActSellPriceWnd != NULL) + DeathAction(pActSellPriceWnd); + pActSellPriceWnd = NULL; + break; + // Ͼ + case 2: + iListStart--; + if (iListStart < 0) + iListStart = 0; + break; + // ¾ + case 3: + iListStart++; + if (iListStart > 13) + iListStart = 13; + break; +#ifdef _PET_ITEM + case 4: + bViewPetItem = !bViewPetItem; + break; +#endif + } + break; + } + } + } + + // ʾ󷽵Ʒб + for (i = iListStart, j = 0; i < iListStart + 13; i++, j++) + { + iBuyItemBtn[j]=-2; + if (ShowVendorItem[i].usage) + { + if (ShowVendorItem[i].kind == 0) + { +#ifdef _NEWFONT_ + extern int getTextLength(char * str); + char tempstr[128]; + if (ShowVendorItem[i].price == 0){ + StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].name, 0); + sprintf(tempstr,"x%d",ShowVendorItem[i].pile); + StockFontBuffer(x + 180-getTextLength(tempstr)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + StockFontBuffer(x + 250-getTextLength("")/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + }else{ + StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].name, 0); + sprintf(tempstr,"x%d",ShowVendorItem[i].pile); + StockFontBuffer(x + 180-getTextLength(tempstr)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + sprintf(tempstr,"%d",ShowVendorItem[i].price); + StockFontBuffer(x + 250-getTextLength(tempstr)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + } +#else + if (ShowVendorItem[i].price == 0) + sprintf_s(szMsg, "%-20sx%3d%13s", ShowVendorItem[i].name, ShowVendorItem[i].pile, ""); + else + sprintf_s(szMsg, "%-20sx%3d%13d", ShowVendorItem[i].name, ShowVendorItem[i].pile, ShowVendorItem[i].price); +#endif + } + else + { +#ifdef _NEWFONT_ + extern int getTextLength(char * str); + char tempstr[128]; + if (ShowVendorItem[i].price == 0){ + StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].name, 0); + StockFontBuffer(x + 175- getTextLength(ShowVendorItem[i].freeName)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].freeName, 0); + StockFontBuffer(x + 250-getTextLength("")/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + }else{ + StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].name, 0); + StockFontBuffer(x + 175 - getTextLength(ShowVendorItem[i].freeName)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[i].freeName, 0); + sprintf(tempstr,"%d",ShowVendorItem[i].price); + StockFontBuffer(x + 250-getTextLength(tempstr)/2, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, tempstr, 0); + } +#else + if (ShowVendorItem[i].price == 0) + sprintf_s(szMsg, "%-17s%-12s%8s", ShowVendorItem[i].name, ShowVendorItem[i].freeName, ""); + else + sprintf_s(szMsg, "%-17s%-12s%8d", ShowVendorItem[i].name, ShowVendorItem[i].freeName, ShowVendorItem[i].price); +#endif + } +#ifdef _NEWFONT_ + iBuyItemBtn[j] = StockFontBuffer(x + 20, y + 21 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, + " ", 2); +#else + iBuyItemBtn[j] = StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 2); +#endif + if (ShowVendorItem[i].bBuy) + StockBoxDispBuffer(x + 18, y + 19 + 28 * j, x + 280, y + 39 + 28 * j, DISP_PRIO_BOX2, SYSTEM_PAL_RED, 0); + } + //else + //iBuyItemBtn[j] = StockFontBuffer(x + 20, y + 22 + 28 * j, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + } + + // ʾĿϸ + if (ShowVendorItem[iCurrentShow].bGetData) + { + // ʾϸ + if (ShowVendorItem[iCurrentShow].kind == 0) + { + int iy = y + 198, color = ShowVendorItem[iCurrentShow].color; + char *splitPoint = ShowVendorItem[iCurrentShow].memo; + + // ͼ + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + // ʾ + StockDispBuffer(x + 415, y + 100, DISP_PRIO_ITEM, ShowVendorItem[iCurrentShow].bmpNo, 0); + // ʾߵµʯ + StockDispBuffer(x + 415, y + 100, DISP_PRIO_IME3, 26269, 0); + // ʾ + StockFontBuffer(x + 325, y + 150, FONT_PRIO_FRONT, color, ShowVendorItem[iCurrentShow].name, 0); + + // ʾ;ö + sprintf_s(szMsg, ";ö(%s)", ShowVendorItem[iCurrentShow].damage); + StockFontBuffer(x + 325, y + 174, FONT_PRIO_FRONT, color, szMsg, 0); + +#ifdef _NPC_ITEMUP + ShowItemup(ShowVendorItem[iCurrentShow].itemup,x+325+250,y+194); +#endif + // ʾ + while (1) + { + if (strlen(splitPoint) > 28) + { + sprintf_s(szMsg, "%s", splitPoint); + szMsg[28] = NULL; + if (GetStrLastByte(szMsg) == 3) + { + szMsg[27] = NULL; + splitPoint += 27; + } + else + { + szMsg[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x + 325, iy, FONT_PRIO_FRONT, 0, szMsg, 0); + iy += 24; + } + else + { + strcpy(szMsg, splitPoint); + StockFontBuffer(x + 325, iy, FONT_PRIO_FRONT, 0, szMsg, 0); + break; + } + } + } + // ʾϸ + else + { + if (pShowPet != NULL) + { +#ifdef _PET_ITEM + // ʾϵ + if (bViewPetItem) + { + int nY = 251, nColor; + char *splitPoint; + + // ʾװĵͼװ + for (i = 0; i < PET_EQUIPNUM; i++) + { + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, DISP_PRIO_IME3, nPetItemEquipBmpNumber[i][0], 0); + if (ShowVendorItem[iCurrentShow].oPetItemInfo[i].bmpNo > 0) + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, DISP_PRIO_ITEM, ShowVendorItem[iCurrentShow].oPetItemInfo[i].bmpNo, 0); + } + for (i = 0; i < PET_EQUIPNUM; i++) + { + // ʾװ + if (MakeHitBox( ItemBuffer[i].defX - 26, ItemBuffer[i].defY - 26, + ItemBuffer[i].defX + 26, ItemBuffer[i].defY + 23, DISP_PRIO_IME3) == TRUE) + { + if (ShowVendorItem[iCurrentShow].oPetItemInfo[i].bmpNo > 0) + { + nColor = ShowVendorItem[iCurrentShow].oPetItemInfo[i].color; + splitPoint = ShowVendorItem[iCurrentShow].oPetItemInfo[i].memo; + // װ + StockFontBuffer(x + 325, y + 195, FONT_PRIO_FRONT, nColor, ShowVendorItem[iCurrentShow].oPetItemInfo[i].name,0); + + // ;ö + sprintf_s(szMsg, ";ö(%s)", ShowVendorItem[iCurrentShow].oPetItemInfo[i].damage); + StockFontBuffer(x + 325, y + 215, FONT_PRIO_FRONT, nColor, szMsg, 0); + +#ifdef _NPC_ITEMUP + ShowItemup(ShowVendorItem[iCurrentShow].itemup,x+325+250,y+235); +#endif + // ʾ + while (1) + { + if (strlen(splitPoint) > 28) + { + sprintf_s(szMsg, 28, "%s", splitPoint); + szMsg[28] = NULL; + if (GetStrLastByte(szMsg) == 3) + { + szMsg[27] = NULL; + splitPoint += 27; + } + else + { + szMsg[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x + 325, nY, FONT_PRIO_FRONT, 0, szMsg, 0); + nY += 24; + } + else + { + strcpy(szMsg, splitPoint); + StockFontBuffer(x + 325, nY, FONT_PRIO_FRONT, 0, szMsg, 0); + break; + } + } + } + } + } + } + else +#endif + { + // ʾ + StockFontBuffer(x + 325, y + 35, FONT_PRIO_FRONT, FONT_PAL_WHITE, ShowVendorItem[iCurrentShow].name, 0); + // ʾת + sprintf_s(szMsg, "%d ת", ShowVendorItem[iCurrentShow].trans); + StockFontBuffer(x + 570, y + 35, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + // ʾﱻĺ + //StockFontBuffer(x + 325, y + 55, FONT_PRIO_FRONT, FONT_PAL_RED, ShowVendorItem[iCurrentShow].freeName, 0); + // ʾȼ,,Ѫ,,,, +#ifdef _NEWFONT_ + sprintf_s(szMsg, " ǰ ԭʼ Ԥ ɳ "); +#else + sprintf_s(szMsg, " ǰ ԭʼ Ԥ ɳ "); +#endif + StockFontBuffer(x + 325, y + 60, FONT_PRIO_FRONT, FONT_PAL_GREEN, szMsg, 0); + sprintf_s(szMsg, "Lv%d", ShowVendorItem[iCurrentShow].level); + StockFontBuffer(x + 325, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); +#ifdef _PETBLESS_ + if(ShowVendorItem[iCurrentShow].maxhp < 0 ){ + sprintf_s(szMsg, "Ѫ%d", abs(ShowVendorItem[iCurrentShow].maxhp)); + StockFontBuffer(x + 325, y + 100, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + } + else{ + sprintf_s(szMsg, "Ѫ%d", ShowVendorItem[iCurrentShow].maxhp); + StockFontBuffer(x + 325, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + } + + if(ShowVendorItem[iCurrentShow].attack < 0 ){ + sprintf_s(szMsg, "%d", abs(ShowVendorItem[iCurrentShow].attack)); + StockFontBuffer(x + 325, y + 120, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + } + else + { + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].attack); + StockFontBuffer(x + 325, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + + } + if(ShowVendorItem[iCurrentShow].defence < 0 ){ + sprintf_s(szMsg, "%d", abs(ShowVendorItem[iCurrentShow].defence)); + StockFontBuffer(x + 325, y + 140, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + } + else{ + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].defence); + StockFontBuffer(x + 325, y + 140, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + } + if(ShowVendorItem[iCurrentShow].dex < 0 ){ + sprintf_s(szMsg, "%d", abs(ShowVendorItem[iCurrentShow].dex)); + StockFontBuffer(x + 325, y + 160, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + } + else{ + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].dex); + StockFontBuffer(x + 325, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + } +#else + sprintf_s(szMsg, "Lv%d", ShowVendorItem[iCurrentShow].level); + StockFontBuffer(x + 325, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "Ѫ%d", ShowVendorItem[iCurrentShow].maxhp); + StockFontBuffer(x + 325, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].attack); + StockFontBuffer(x + 325, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].defence); + StockFontBuffer(x + 325, y + 140, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].dex); + StockFontBuffer(x + 325, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); +#endif + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].ylv); + StockFontBuffer(x + 395, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].yhp); + StockFontBuffer(x + 392, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].yack); + StockFontBuffer(x + 392, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].ydef); + StockFontBuffer(x + 392, y + 140, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].ydex); + StockFontBuffer(x + 392, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + + + float a,b,c,d,e,f; + float a1,b1,c1,d1,e1; + + if(ShowVendorItem[iCurrentShow].level != ShowVendorItem[iCurrentShow].ylv && ShowVendorItem[iCurrentShow].ylv){ + f = (float)(ShowVendorItem[iCurrentShow].level-ShowVendorItem[iCurrentShow].ylv); + a = (abs(ShowVendorItem[iCurrentShow].maxhp)- ShowVendorItem[iCurrentShow].yhp)/f; + b = (abs(ShowVendorItem[iCurrentShow].attack)-ShowVendorItem[iCurrentShow].yack)/f; + c = (abs(ShowVendorItem[iCurrentShow].defence)-ShowVendorItem[iCurrentShow].ydef)/f; + d = (abs(ShowVendorItem[iCurrentShow].dex)-ShowVendorItem[iCurrentShow].ydex)/f; + + f = 140.00 - ShowVendorItem[iCurrentShow].ylv; + + a1 = f*a+ShowVendorItem[iCurrentShow].yhp; + b1 = f*b+ShowVendorItem[iCurrentShow].yack; + c1 = f*c+ShowVendorItem[iCurrentShow].ydef; + d1 = f*d+ShowVendorItem[iCurrentShow].ydex; + }else{ + a=b=c=d=1.0000; + a1=b1=c1=d1=0; + } + e=b+c+d; + e1 = abs(ShowVendorItem[iCurrentShow].maxhp)*0.25 + abs(ShowVendorItem[iCurrentShow].attack)+abs(ShowVendorItem[iCurrentShow].defence)+abs(ShowVendorItem[iCurrentShow].dex); + + sprintf_s(szMsg, "%3d", 140); + + StockFontBuffer(x + 445, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.2f", a1); + StockFontBuffer(x + 435, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.2f", b1); + StockFontBuffer(x + 435, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.2f", c1); + StockFontBuffer(x + 435, y + 140, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.2f", d1); + StockFontBuffer(x + 435, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + + + sprintf_s(szMsg, "%3.4f", b+c+d); + StockFontBuffer(x + 500, y + 80, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + sprintf_s(szMsg, "%3.4f", a); + StockFontBuffer(x + 500, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.4f", b); + StockFontBuffer(x + 500, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.4f", c); + StockFontBuffer(x + 500, y + 140, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "%3.4f", d); + StockFontBuffer(x + 500, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + + + + sprintf_s(szMsg, "أ%d", ShowVendorItem[iCurrentShow].earth/10); + StockFontBuffer(x + 560, y + 80, FONT_PRIO_FRONT, FONT_PAL_GREEN, szMsg, 0); + sprintf_s(szMsg, "ˮ%d", ShowVendorItem[iCurrentShow].water/10); + StockFontBuffer(x + 560, y + 100, FONT_PRIO_FRONT, FONT_PAL_BLUE, szMsg, 0); + sprintf_s(szMsg, "%d", ShowVendorItem[iCurrentShow].fire/10); + StockFontBuffer(x + 560, y + 120, FONT_PRIO_FRONT, FONT_PAL_RED, szMsg, 0); + sprintf_s(szMsg, "磺%d", ShowVendorItem[iCurrentShow].wind/10); + StockFontBuffer(x + 560, y + 140, FONT_PRIO_FRONT, FONT_PAL_YELLOW, szMsg, 0); + sprintf_s(szMsg, "ң%d", ShowVendorItem[iCurrentShow].fidelity); + StockFontBuffer(x + 560, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + + + + + // ʾ輼 + for (i = 0; i < ShowVendorItem[iCurrentShow].maxSkill; i++) + { + sprintf_s(szMsg, " %d%s", i + 1, ShowVendorItem[iCurrentShow].skillname[i]); + StockFontBuffer(x + 325, y + 190 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + } + } + } + } + } + + // Ŀ + int kind; + + for (i = 0; i < 13; i++) + { + // ѡҪ + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + //selId = focusFontId(iBuyItemBtn, sizeof(iBuyItemBtn) / sizeof(int)); + if (HitFontNo == iBuyItemBtn[i]) + { + kind = ShowVendorItem[i + iListStart].kind; + + // ѵѡȡ + if (ShowVendorItem[i + iListStart].bBuy) + { + ShowVendorItem[i + iListStart].bBuy = false; + iTotalBuy[kind]--; + iTotalBuyMoney -= ShowVendorItem[i + iListStart].price; + } + // ǷƷ + else if (ShowVendorItem[i + iListStart].price > 0) + { + // ϻпλ + if (iEmptyNum[kind] > iTotalBuy[kind]) + { + // ϵǮ㹻 + if ((iTotalBuyMoney + ShowVendorItem[i + iListStart].price) <= pc.gold) + { + ShowVendorItem[i + iListStart].bBuy = true; + iTotalBuy[kind]++; + iTotalBuyMoney += ShowVendorItem[i + iListStart].price; + } + else + StockChatBufferLine("ʯҲ㣡", FONT_PAL_RED); + } + else + { + if (kind == 0) + StockChatBufferLine("ϵλ㣡", FONT_PAL_RED); + else if (kind == 1) + StockChatBufferLine("ϳλ㣡", FONT_PAL_RED); + } + } + else + StockChatBufferLine("Ʒɵѡ", FONT_PAL_RED); + break; + } + } + // Ŀ + else if (mouse.onceState & MOUSE_RIGHT_CRICK) + { + if (HitFontNo == iBuyItemBtn[i]) + { + if (!ShowVendorItem[i+iListStart].bGetData) + { + sprintf_s(szMsg, "D|%d|", ShowVendorItem[i + iListStart].index); + lssproto_STREET_VENDOR_send(sockfd, szMsg); + } + else if (ShowVendorItem[i + iListStart].kind == 1) + { + if (iCurrentShow != i + iListStart) + { + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + iMakePetAni = i + iListStart; + } + } + iCurrentShow = i + iListStart; +#ifdef _PET_ITEM + bViewPetItem = FALSE; +#endif + break; + } + } + } + + // ʾϵǮ + sprintf_s(szMsg, "%d", pc.gold); + StockFontBuffer(x + 380, y + 336, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + // ʾѡƷܼ + sprintf_s(szMsg, "%d", iTotalBuyMoney); + StockFontBuffer(x + 525, y + 336, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + if (iMakePetAni > -1) + { + pShowPet = MakeAnimDisp(x + 520, y + 300, ShowVendorItem[iMakePetAni].bmpNo, 0); + iMakePetAni = -1; + } + StockDispBuffer(((WINDOW_DISP *)pActStreetVendorBuyWnd->pYobi)->mx, + ((WINDOW_DISP *)pActStreetVendorBuyWnd->pYobi)->my, + DISP_PRIO_MENU, CG_FIELD_SV_BUY_PANEL, 1); + } + } + if (data != NULL) + { + int count, index; +#ifdef _PET_ITEM + int nPetItemPlace; +#endif + getStringToken(data, '|', 1, sizeof(szMsg) - 1, szMsg); + // + if (szMsg[0] == 'B') + { + getStringToken(data, '|', 2, sizeof(szMsg) - 1, szMsg); + count = atoi(szMsg); + for (i = 0; i < count; i++) + { + getStringToken(data, '|', 3 + i * 5, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[i].kind = atoi(szMsg); + getStringToken(data, '|', 4 + i * 5, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[i].price = atoi(szMsg); + getStringToken(data, '|', 5 + i * 5, sizeof(szMsg) - 1, szMsg); + strncpy_s(ShowVendorItem[i].name, szMsg, sizeof(ShowVendorItem[i].name)); + getStringToken(data, '|', 6 + i * 5, sizeof(szMsg) - 1, szMsg); + if (ShowVendorItem[i].kind == 0) + ShowVendorItem[i].pile = atoi(szMsg); + else + strncpy_s(ShowVendorItem[i].freeName, szMsg, sizeof(ShowVendorItem[i].freeName)); + getStringToken(data, '|', 7 + i * 5, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[i].index = atoi(szMsg); + ShowVendorItem[i].usage = true; + } + } + // ϸ + else if (szMsg[0] == 'D') + { + getStringToken(data, '|', 2, sizeof(szMsg) - 1, szMsg); + index = atoi(szMsg); + for (i = 0; i < MAX_SELL_ITEM; i++) + { + if (ShowVendorItem[i].usage && ShowVendorItem[i].index == index) + { + index = i; + break; + } + } + if (index >= 0 && index < MAX_SELL_ITEM) + { + if (ShowVendorItem[index].kind == 0) + { + getStringToken(data, '|', 3, sizeof(szMsg) - 1, szMsg); + strncpy_s(ShowVendorItem[index].memo, szMsg, sizeof(ShowVendorItem[index].memo)-1); + getStringToken(data, '|', 4, sizeof(szMsg) - 1, szMsg); + strncpy_s(ShowVendorItem[index].damage, szMsg, sizeof(ShowVendorItem[index].damage)-1); + getStringToken(data, '|', 5, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].color = atoi(szMsg); + getStringToken(data, '|', 6, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].bmpNo = atoi(szMsg); +#ifdef _NPC_ITEMUP + getStringToken(data, '|', 7, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].itemup = atoi(szMsg); +#endif + } + else + { + int size = sizeof(ShowVendorItem[index].skillname[0]); + + getStringToken(data, '|', 3, sizeof(szMsg) - 1, szMsg); + count = atoi(szMsg); + for (i = 0; i < count; i++) + { + getStringToken(data, '|', 4 + i, sizeof(szMsg) - 1, szMsg); + strncpy_s(ShowVendorItem[index].skillname[i], szMsg, size); + } + ShowVendorItem[index].maxSkill = count; + getStringToken(data, '|', 4 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].level = atoi(szMsg); + getStringToken(data, '|', 5 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].maxhp = atoi(szMsg); + getStringToken(data, '|', 6 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].attack = atoi(szMsg); + getStringToken(data, '|', 7 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].defence = atoi(szMsg); + getStringToken(data, '|', 8 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].dex = atoi(szMsg); + getStringToken(data, '|', 9 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].earth = atoi(szMsg); + getStringToken(data, '|', 10 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].water = atoi(szMsg); + getStringToken(data, '|', 11 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].fire = atoi(szMsg); + getStringToken(data, '|', 12 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].wind = atoi(szMsg); + getStringToken(data, '|', 13 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].fidelity = atoi(szMsg); + getStringToken(data, '|', 14 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].trans = atoi(szMsg); + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].bmpNo = atoi(szMsg); +#ifdef _PETCOM_ + i++; + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].ylv = atoi(szMsg); + i++; + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].yhp = atoi(szMsg); + i++; + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].yack = atoi(szMsg); + i++; + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].ydef = atoi(szMsg); + i++; + getStringToken(data, '|', 15 + i, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].ydex = atoi(szMsg); +#endif + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + iMakePetAni = index; +#ifdef _PET_ITEM + for (int j = 0; j < MAX_PET_ITEM; j++) + { + // װλ + if (getStringToken(data, '|', 16 + i + j * 6, sizeof(szMsg) - 1, szMsg)) + continue; + nPetItemPlace = atoi(szMsg); + // + getStringToken(data, '|', 17 + i + j * 6, + sizeof(ShowVendorItem[index].oPetItemInfo[nPetItemPlace].name) - 1, + ShowVendorItem[index].oPetItemInfo[nPetItemPlace].name); + // ˵ + getStringToken(data, '|', 18 + i + j * 6, + sizeof(ShowVendorItem[index].oPetItemInfo[nPetItemPlace].memo) - 1, + ShowVendorItem[index].oPetItemInfo[nPetItemPlace].memo); + // ;ö + getStringToken(data, '|', 19 + i + j * 6, + sizeof(ShowVendorItem[index].oPetItemInfo[nPetItemPlace].damage) - 1, + ShowVendorItem[index].oPetItemInfo[nPetItemPlace].damage); + // ɫ + getStringToken(data, '|', 20 + i + j * 6, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].oPetItemInfo[nPetItemPlace].color = atoi(szMsg); + // ͼ + getStringToken(data, '|', 21 + i + j * 6, sizeof(szMsg) - 1, szMsg); + ShowVendorItem[index].oPetItemInfo[nPetItemPlace].bmpNo = atoi(szMsg); + } +#endif + } + ShowVendorItem[index].bGetData = true; + } + } + } +} + +#else +#ifdef _TABLEOFSKILL // (ɿ) Syu ADD 7.0 \ܱ +int SkillWnd = 0 ; +ACTION *pActSkillWnd; +short skillBtn = 0; +short skillBtnFocus = 0; +int skillBtnGraNo[] = +{d + CG_FIELD_SKILL_BTN_OFF, + CG_FIELD_SKILL_BTN_ON +}; +// ְҵӴ +void SkillWndfunc() +{ + int x , y , j ; + char msg[256]; + char buf[256]; + char msg2[256]; + if (pActSkillWnd == NULL) + { + pActSkillWnd = MakeWindowDisp(354, 0, 300, 456, 0, -1); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = pActSkillWnd->x; + y = pActSkillWnd->y; +#endif + } + else + { + if (pActSkillWnd->hp > 0) + { + StockDispBuffer(((WINDOW_DISP*)pActSkillWnd->pYobi)->mx - 10, ((WINDOW_DISP*)pActSkillWnd->pYobi )->my - 5 , DISP_PRIO_MENU, CG_FIELD_SKILL_PANEL, 1); + x = pActSkillWnd->x + 2; + y = pActSkillWnd->y - 5; + fieldBtnHitId[14] = StockDispBuffer(x + 201, y + 442, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + StockFontBuffer(x + 58, y + 40, FONT_PRIO_FRONT, 1, pc.profession_class_name, 2); + sprintf_s(msg, "%d", pc.profession_skill_point); + StockFontBuffer(x + 228, y + 40, FONT_PRIO_FRONT, 1, msg, 0); + memset(msg, -1, sizeof(msg)); + } + } + for (int i = 0; i < 3; i++) + { +#ifdef _READ16BITBMP + if (g_bUseAlpha) + { + if (MakeHitBox(x + 258, y + 15 + i * 78, x + 288, y + 93 + i * 78, DISP_PRIO_IME3) == TRUE) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + SkillWnd = i ; + play_se(217, 320, 240); + break; + } + } + } + else +#endif + if (MakeHitBox(x + 250, y + 18 + i * 79, x + 280, y + 96 + i * 79, DISP_PRIO_IME3) == TRUE) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + SkillWnd = i ; + play_se(217, 320, 240); + break; + } + } + } + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (HitDispNo == fieldBtnHitId[14]) + { + actBtn = 0 ; + skillBtn = 0 ; + play_se(217, 320, 240); + } + } + extern int BattleSkill[20]; + extern int AssitSkill[20]; + extern int AdvanceSkill[20]; + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + StockDispBuffer(x + 143 + j * 60, y + 210 + i * 57, DISP_PRIO_IME3, CG_FIELD_SKILL_TILE, 0); + } + switch (SkillWnd) + { + case 0 : +#ifdef _READ16BITBMP + if (g_bUseAlpha) + StockDispBuffer(x + 147, y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT, 0); + else +#endif + StockDispBuffer(x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT, 0); + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + if (AssitSkill[j + i * 4] == -1) + break; + if (HitDispNo == StockDispBuffer(x + 29 + j * 60, y + 102 + i * 57, DISP_PRIO_IME3 + 1, profession_skill[AssitSkill[j + i * 4]].icon, 2)) + { + int use_color = 0; + + if (pc.mp >= profession_skill[AssitSkill[j + i * 4]].costmp && profession_skill[AssitSkill[j + i * 4]].costmp != 0) + use_color = FONT_PAL_WHITE; + else + use_color = FONT_PAL_GRAY; + sprintf_s(msg, "%s", profession_skill[AssitSkill[j + i * 4]].name); + StockFontBuffer(355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%d", profession_skill[AssitSkill[j + i * 4]].skill_level); + StockFontBuffer(440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "(ķMP:%d)", profession_skill[AssitSkill[j + i * 4]].costmp); + StockFontBuffer(500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%s", profession_skill[AssitSkill[j + i * 4]].memo); +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if (mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[AssitSkill[j + i * 4]].useFlag == 0) + { + if (pc.mp >= profession_skill[AssitSkill[j + i * 4]].costmp && profession_skill[AssitSkill[j + i * 4]].costmp != 0) + { + lssproto_BATTLESKILL_send(sockfd, AssitSkill[j + i * 4]); + play_se(217, 320, 240); + } + } +#endif + } + sprintf_s(msg2, "%8s", profession_skill[AssitSkill[j + i * 4]].name); + StockFontBuffer(x + j * 60, y + 110 + i * 57, FONT_PRIO_FRONT, profession_skill[AssitSkill[j + i * 4]].useFlag + 1, msg2, 0); + } + } + break; + case 1 : +#ifdef _READ16BITBMP + if (g_bUseAlpha) + StockDispBuffer(x + 147,y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE, 0); + else +#endif + StockDispBuffer(x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE, 0); + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + if (BattleSkill[j + i * 4] == -1) + break; + if (HitDispNo == StockDispBuffer(x + 29 + j * 60, y + 102 + i * 57, DISP_PRIO_IME3 + 1, profession_skill[BattleSkill[j + i * 4]].icon, 2)) + { + int use_color = 0; + + if (pc.mp >= profession_skill[BattleSkill[j + i * 4]].costmp && profession_skill[BattleSkill[j + i * 4]].costmp != 0) + use_color = FONT_PAL_WHITE; + else + use_color = FONT_PAL_GRAY; + + sprintf_s(msg, "%s", profession_skill[BattleSkill[j + i * 4]].name); + StockFontBuffer(355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%d", profession_skill[BattleSkill[j + i * 4]].skill_level); + StockFontBuffer(440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "(ķMP:%d)", profession_skill[BattleSkill[j + i * 4]].costmp); + StockFontBuffer(500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%s", profession_skill[BattleSkill[j + i * 4]].memo); +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if (mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[BattleSkill[j + i * 4]].useFlag == 0) + { + if (pc.mp >= profession_skill[BattleSkill[j + i * 4]].costmp && profession_skill[BattleSkill[j + i * 4]].costmp != 0) + { + lssproto_BATTLESKILL_send(sockfd , BattleSkill[j + i * 4]); + play_se(217, 320, 240); + } + } +#endif + } + sprintf_s(msg2, "%8s", profession_skill[BattleSkill[j + i * 4]].name); + StockFontBuffer(x + j * 60, y + 110 + i * 57, FONT_PRIO_FRONT, profession_skill[BattleSkill[j + i * 4]].useFlag + 1, msg2, 0); + } + } + break; + case 2: +#ifdef _READ16BITBMP + if (g_bUseAlpha) + StockDispBuffer(x + 147, y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK, 0); + else +#endif + StockDispBuffer(x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK, 0); + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + if (AdvanceSkill[j + i * 4] == -1) + break; + if (HitDispNo == StockDispBuffer(x + 29 + j * 60, y + 102 + i * 57, DISP_PRIO_IME3 + 1, profession_skill[AdvanceSkill[j + i * 4]].icon, 2)) + { + int use_color = 0; + + if (pc.mp >= profession_skill[AdvanceSkill[j + i * 4]].costmp && profession_skill[AdvanceSkill[j + i * 4]].costmp != 0) + use_color = FONT_PAL_WHITE; + else + use_color = FONT_PAL_GRAY; + + sprintf_s(msg, "%s", profession_skill[AdvanceSkill[j + i * 4]].name); + StockFontBuffer(355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%d", profession_skill[AdvanceSkill[j + i * 4]].skill_level); + StockFontBuffer(440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "(ķMP:%d)" , profession_skill[AdvanceSkill[j + i * 4]].costmp); + StockFontBuffer(500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0); + sprintf_s(msg, "%s", profession_skill[AdvanceSkill[j + i * 4]].memo); +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if (mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[AdvanceSkill[j + i * 4]].useFlag == 0) + { + if (pc.mp >= profession_skill[AdvanceSkill[j + i * 4]].costmp && profession_skill[AdvanceSkill[j + i * 4]].costmp != 0) + { + lssproto_BATTLESKILL_send(sockfd , AdvanceSkill[j + i * 4]); + play_se(217, 320, 240); + } + } +#endif + } + sprintf_s(msg2 , "%8s", profession_skill[AdvanceSkill[j + i * 4]].name); + StockFontBuffer(x + j * 60, y + 110 + i * 57, FONT_PRIO_FRONT, profession_skill[AdvanceSkill[j + i * 4]].useFlag + 1, msg2, 0); + } + } + break; + } + char *splitPoint = msg; + + sprintf_s(buf, "%s", msg); + x = 355; + y = 340; + while (1) + { + if (strlen(splitPoint) > 34) + { + strncpy_s(msg, splitPoint, 34); + buf[34] = NULL; + if (GetStrLastByte(buf) == 3) + { + buf[33] = NULL; + splitPoint += 33; + } + else + { + buf[34] = NULL; + splitPoint += 34; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, buf, 0); + y += 24; + } + else + { + strcpy(buf, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, buf, 0); + break; + } + } +} + #endif +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ +ACTION *pChatRoomWnd; +short chatRoomBtn = 0; +short SelRoomBtn = 0; +short chatRoomBtnFocus = 0; +int chatRoomBtnGraNo[] = +{ + CG_FIELD_CHATROOM_BTN_OFF, + CG_FIELD_CHATROOM_BTN_ON +}; +#endif + +// ??????? +short menuBtn = 0; +short menuBtnFocus = 0; +int menuBtnGraNo[] = +{ + CG_FIELD_MENU_BTN_OFF, + CG_FIELD_MENU_BTN_ON +}; + +// ??? +short cardBtn = 0; +short cardBtnFocus = 0; +int cardBtnGraNo[] = +{ + CG_FIELD_CARD_BTN_OFF, + CG_FIELD_CARD_BTN_ON +}; + +// Robin 04/12 Trade Button +short tradeBtn = 0; +short tradeBtnFocus = 0; +//short tradeBtnEnableFlag = 1; +int tradeBtnGraNo[] = +{ + CG_FIELD_TRADE_BTN_OFF, + CG_FIELD_TRADE_BTN_ON +}; + +#ifdef _MO_SIGN_IN +short signInBtn = 0; +short signInBtnFocus = 0; +int signInBtnGraNo[] = +{ + CG_FIELD_SIGNIN_BTN_OFF, + CG_FIELD_SIGNIN_BTN_ON +}; +#endif + +#ifdef _CHANGETEAM_ +short changeteamBtn = 0; +short changeteamBtnFocus = 0; +int schangeteamBtnGraNo[] = +{ + CG_FIELD_CHANGETEAM_BTN_OFF, + CG_FIELD_CHANGETEAM_BTN_ON +}; +#endif + +#ifdef _NEWSHOP_ +short marketBtn = 0; +short marketBtnFocus = 0; +int marketBtnGraNo[] = +{ + CG_FIELD_MARKET_BTN_OFF, + CG_FIELD_MARKET_BTN_ON +}; +#endif + +#ifdef _ANGEL_SUMMON +extern short HelpProcNo; +extern short jumpHelpPage; +extern short jumpHelpSeg; + +int angelFlag = FALSE; +int angelRecvType; +int angelRecvButton; +char angelMsg[1024*10] = ""; + +short angelLampDrawFlag = 0; +unsigned int angelLampFlashTime = 0; + +short angelBtn = 0; +short angelBtnFocus = 0; +int angelBtnGraNo[] = +{ + 35273, // CG_FIELD_ANGEL_BTN_OFF + 35272 // CG_FIELD_ANGEL_BTN_ON +}; +#endif + +// Robin 06/01 Channel Button +short channelBtn = 0; +short channelBtnFocus = 0; +short channelWNFlag = 1; +int channelBtnGraNo[] = +{ + CG_FIELD_CHANNEL_BTN_OFF, + CG_FIELD_CHANNEL_BTN_ON +}; + +// ????? +short partyBtn = 0; +short partyBtnFocus = 0; +short partyBtnEnableFlag = 1; +int partyBtnGraNo[] = +{ + CG_FIELD_GROUP_BTN_OFF, + CG_FIELD_GROUP_BTN_ON +}; + +// ?????? +short mailLamp = 0; +short mailLampDrawFlag = 0; + +#ifdef __PHONEMESSAGE +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- BEGIN +short msgBtn = 0; +short msgBtnFocus = 0; +int msgBtnGraNo[] = +{ + CG_FIELD_MSG_BTN_OFF, + CG_FIELD_MSG_BTN_ON +}; +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- END +#endif +#ifdef _NEW_MATCH +int helpBtnGraNo[] = +{ + CG_FIELD_HELP_BTN_ON, + CG_FIELD_HELP_BTN_OFF +}; +#else +int helpBtnGraNo[] = +{ + CG_FIELD_HELP_BTN_ON, + CG_FIELD_HELP_BTN_OFF +}; +#endif +short helpBtn = 0; +short helpBtnFocus = 0; +#ifdef _RED_MEMOY_ +short redmemoyBtn = 0; +short redmemoyBtnFocus = 0; +int redmemoyGraNo[] = +{ + 60005,60006 +}; +#endif +unsigned int mailLampFlashTime = 0; +// ӡP??? +short joinBattleBtn = 0; +short joinBattleBtnFocus = 0; +short joinBattleBtnEnableFlag = 1; +short joinBattleHelpMsgFlag = 1; +int joinBattleBtnGraNo[] = +{ + CG_FIELD_JOIN_BTL_BTN_OFF, + CG_FIELD_JOIN_BTL_BTN_ON +}; +// nP??? +short duelBtn = 0; +short duelBtnFocus = 0; +int duelBtnGraNo[] = +{ + CG_FIELD_DUEL_BTN_OFF, + CG_FIELD_DUEL_BTN_ON +}; + +// ???????? +short actBtn = 0; +short actBtnForcus = 0; +int actBtnUpTime; +int nowActMode; +int actBtnGraNo[] = +{ + CG_FIELD_ACT_BTN_OFF, + CG_FIELD_ACT_BTN_ON +}; +short charActionAnimeChangeProcNo; +short charActionAnimeChangeWindowFlag; +// ???ӡP?nPϣ??????? +short etcSwitchProcNo; +short etcSwitchChangeFlag = 0; +// ????? +int amPmAnimeTime; +int amPmAnimeX; +int amPmAnimeGraNoIndex0, amPmAnimeGraNoIndex1; +int amPmAnimeGraNo[] = +{ + CG_FIELD_AM_PM_01, + CG_FIELD_AM_PM_02, + CG_FIELD_AM_PM_03, + CG_FIELD_AM_PM_00 +}; + +#ifdef _TEACHER_SYSTEM +short sTeacherSystemBtn = 0; +short sTeacherSystemBtnFocus = 0; +int iTeacherSystemBtnGraNo[] = { + CG_FIELD_TS_BTN_OFF, + CG_FIELD_TS_BTN_ON +}; +#endif + +// ???????????????? +short etcSendFlag = 0; +// ?????? +short nowFieldMenuOpenFlag = 0; // ?????????????????? +// ??????????????????????? +unsigned int fieldBtnPushTime = 0; +// ?????????t? +unsigned int fieldInfoTime = 0; +// ?????? +void initCharActionAnimeChange( void ); +int charActionAnimeChange( void ); +void initEtcSwitch( void ); +int etcSwitch( void ); +// Robin 06/02 +void initJoinChannelWN( void ); +void closeJoinChannelWN( void ); +void joinChannelWN( void ); +void initJoinChannel2WN( char *data ); +void closeJoinChannel2WN( void ); +void joinChannel2WN( void ); +void leaderFuncWN( void ); +//static short joinChannelProc = 0; +static short joinChannel2Proc = 0; +struct tm serverAliveTime; +time_t serverAliveLongTime; + +// ????????????? +void initFieldProc( void ) +{ + int i; + + drawFieldButtonFlag = 1; + menuBtn = 0; + cardBtn = 0; + partyBtn = 0; + tradeBtn = 0; +// initPcAll()?s???@e?????????????? +// mailLamp = 0; +#ifdef __PHONEMESSAGE + msgBtn = 0; //LeiBoy 2002 Jan.26 +#endif +#ifdef _STREET_VENDOR + sStreetVendorBtn = 0; + sStreetVendorBuyBtn = 0; +#else + #ifdef _TABLEOFSKILL // (ɿ) Syu ADD 7.0 \ܱ + skillBtn = 0 ; + #endif +#endif +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + chatRoomBtn = 0; + SelRoomBtn = 0; + TalkMode = 0; +#endif + mailLampDrawFlag = 0; + mailLampFlashTime = 0; + joinBattleBtn = 0; + duelBtn = 0; + actBtn = 0; + actBtnForcus = 0; + nowActMode = 0; + drawTimeAnimeFlag = 1; + + for (i = 0; i < FIELD_FUNC_END; i++) + fieldBtnHitId[i] = -2; + + etcSendFlag = 0; + etcSwitchChangeFlag = 0; + fieldInfoTime = 0; + partyBtnEnableFlag = 1; + joinBattleBtnEnableFlag = 1; + joinBattleHelpMsgFlag = 1; + //tradeBtnEnableFlag = 1; +} + +// ???????????? +void resetFieldProc(void) +{ + actBtn = 0; + menuBtn = 0; + fieldInfoTime = 0; +#ifdef __PHONEMESSAGE + msgBtn = 0; +#endif + channelWNFlag = 0; +#ifdef _STREET_VENDOR + sStreetVendorBtn = 0; + sStreetVendorBuyBtn = 0; +#else + #ifdef _TABLEOFSKILL + skillBtn = 0 ; + #endif +#endif + helpBtn = 0; +} + +// ????????? +void fieldProc( void ) +{ + int selId; + int pushId; + int focusId; + BOOL walkFlag = FALSE; + + // ?????? + rand2(); + + // ??????????????????? + actionShortCutKeyProc(); + + // ?????????????????????????? + // r??????????? + if (etcSwitchChangeFlag && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime+FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + lssproto_FS_send(sockfd, pc.etcFlag); + else + old_lssproto_FS_send(sockfd, pc.etcFlag); + fieldBtnPushTime = TimeGetTime(); + etcSwitchChangeFlag = 0; + } + } + + // \?????????????? + if (CheckMenuFlag() || windowTypeWN > -1 || actBtn == 1 || menuBtn == 1 || channelWNFlag == 1) + drawFieldButtonFlag = 0; + else + drawFieldButtonFlag = 1; + + // ?????????????????????????? + nowFieldMenuOpenFlag = 0; + // ????????[??????????? + if (windowTypeWN != -1) + nowFieldMenuOpenFlag = 1; + // ???????????????? + if (actBtn == 1) + nowFieldMenuOpenFlag = 1; + // ???ӡP?nPϣ?????????????? + if (menuBtn == 1) + nowFieldMenuOpenFlag = 1; + + // ?????????????????????????1T?1024? + amPmAnimeTime = (SaTime.hour + 832) % 1024; + amPmAnimeGraNoIndex0 = amPmAnimeTime / 256; + amPmAnimeGraNoIndex1 = (amPmAnimeGraNoIndex0 + 1) % 4; + amPmAnimeX = (amPmAnimeTime % 256) / 4; + + // ????h????????? + if (nowVx != 0 || nowVy != 0) + walkFlag = TRUE; + + // ???????????????????????????? + if (etcSendFlag) + { + if (prSendFlag == 0 && jbSendFlag == 0 && duelSendFlag == 0) + etcSendFlag = 0; + else + etcSendFlag = 1; + } + + // ????????????????????? + // \??u???????? + // ?????? +#if 1 + // ?????????????? + selId = selGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + pushId = pushGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + focusId = focusGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + if (etcSendFlag != 0 || (walkFlag != FALSE && selId != FIELD_FUNC_PARTY)) + selId = -1; +#else + if (etcSendFlag == 0 && walkFlag == FALSE) + { + // ?????????????? + selId = selGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + pushId = pushGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + focusId = focusGraId(fieldBtnHitId, sizeof(fieldBtnHitId) / sizeof(int)); + } + else + selId = -1; +#endif + + // {e??????????????????? + if (/* nowFloor == 32021 + || */nowFloor == 31706 || nowFloor == 10204 || (10601 <= nowFloor && nowFloor <= 10605) + || nowFloor == 10919 || nowFloor == 10920 || nowFloor == 20711 || nowFloor == 20712 + || nowFloor == 1008 || nowFloor == 1021 || nowFloor == 3008 || nowFloor == 3021 +#ifdef _LOCKPARTYFLOOR // (ɿ) Syu ADD Ӳӵĵͼ + || ( nowFloor <= 8213 && nowFloor >= 8200 ) +#endif + || ( nowFloor >= 30017 && nowFloor <= 30021 ) || ( nowFloor == 7025 ) // ɭ׽ +#ifdef _THEATER + || nowFloor == 17001 // 糡 +#endif +#ifdef _NPC_MAGICCARD + || nowFloor == 17003 || nowFloor == 17005 +#endif +#ifdef _NPC_DANCE + || nowFloor == 7027 +#endif + ) + partyBtnEnableFlag = 0; + else + partyBtnEnableFlag = 1; + + // {e??????ӡP?????P????????????C???? + if (nowFloor < 10000 && (nowFloor / 1000 > 0) && (nowFloor % 1000 == 7) || nowFloor == 130) + { + joinBattleHelpMsgFlag = 0; // ?PC + joinBattleBtnEnableFlag = 1; + } + else + if (nowFloor == 1008 || nowFloor == 1021 || nowFloor == 3008 || nowFloor == 3021 + || nowFloor == 10919 || nowFloor == 10920 || nowFloor == 20711 || nowFloor == 20712 + || nowFloor == 10204) + { + joinBattleHelpMsgFlag = 2; // ӡP????C? + joinBattleBtnEnableFlag = 0; + } + else + { + joinBattleHelpMsgFlag = 1; // ӡPC + joinBattleBtnEnableFlag = 1; + } + + if (selId == FIELD_FUNC_MENU || (joy_trg[1] & JOY_CTRL_Q) +#ifdef __PHONEMESSAGE + && msgBtn == 0 +#endif +#ifdef _STREET_VENDOR + && sStreetVendorBtn == 0 + && sStreetVendorBuyBtn == 0 +#endif +#ifdef __ONLINEGM + && OnlineGmFlag == FALSE +#endif +/*#ifdef _JOBDAILY + && JobDailyFlag == FALSE +#endif*/ + && helpBtn == 0 + + ) + { + if (menuBtn == 0) + { + // ??????????????????????????? + // ????????????? + closeCharActionAnimeChange(); + closeJoinChannelWN(); + + // \??????????? + if (CheckMenuFlag()) + InitMenu2(); + + initEtcSwitch(); + menuBtn = 1; + play_se(202, 320, 240); // ???????? + } + else + closeEtcSwitch(); + } + if (menuBtn == 1 && etcSwitch()) + menuBtn = 0; + if (focusId == FIELD_FUNC_MENU) + menuBtnFocus = 1; // ??????????????? + else + menuBtnFocus = 0; +#ifdef _STREET_VENDOR + if (pushId == FIELD_FUNC_STREET_VENDOR) + { + if (selId == FIELD_FUNC_STREET_VENDOR) + { +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000002) + StockChatBufferLine("רı", FONT_PAL_RED); + else +#endif //_THEATER + { +#ifdef _MOVE_SCREEN + if(pc.bMoveScreenMode) + StockChatBufferLine("״̬޷̯",FONT_PAL_RED); + else +#endif + { + play_se( 202, 320, 240 ); + lssproto_STREET_VENDOR_send(sockfd, "O|"); + sStreetVendorBtn = 0; + } + } + } + } + if (sStreetVendorBtn == 1 || sStreetVendorBtn == 3) + { + actBtn = 1; + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + sStreetVendorBtn = 2; + iOldGX = nowGx; + iOldGY = nowGy; + // ׼ӼPKѡر + pc.etcFlag &= ~PC_ETCFLAG_TRADE; + pc.etcFlag &= ~PC_ETCFLAG_PARTY; + pc.etcFlag &= ~PC_ETCFLAG_DUEL; + if (bNewServer) + lssproto_FS_send(sockfd, pc.etcFlag); + else + old_lssproto_FS_send(sockfd, pc.etcFlag); + } + else + if (sStreetVendorBtn == 2) + { + StreetVendorWndfunc(true, NULL); + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) || CheckMenuFlag()) + { + play_se(203, 320, 240); + sStreetVendorBtn = 0; + actBtn = 0; + } + } + else + { + if (pActStreetVendorWnd) + { + DeathAction(pActStreetVendorWnd); + pActStreetVendorWnd = NULL; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + } + if (pActSellPriceWnd) + { + DeathAction(pActSellPriceWnd); + pActSellPriceWnd = NULL; + } + + } + if (sStreetVendorBuyBtn == 1) + { + actBtn = 1; + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + sStreetVendorBuyBtn = 2; + iOldGX = nowGx; + iOldGY = nowGy; + } + else + if (sStreetVendorBuyBtn == 2) + { + StreetVendorBuyWndfunc(NULL); + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) || CheckMenuFlag()) + { + play_se(203, 320, 240); + sStreetVendorBuyBtn = 0; + actBtn = 0; + } + } + else + { + if (pActStreetVendorBuyWnd) + { + DeathAction(pActStreetVendorBuyWnd); + pActStreetVendorBuyWnd = NULL; + actBtn = 0; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + lssproto_STREET_VENDOR_send(sockfd, "N|"); + } + } + // ڰ̯̯˹ʱ߶ȡ + if ((pc.iOnStreetVendor == 1 || sStreetVendorBuyBtn == 2) && (iOldGX != nowGx || iOldGY != nowGy)) + { + if (pc.iOnStreetVendor == 1) + lssproto_STREET_VENDOR_send(sockfd, "E|"); + if (sStreetVendorBuyBtn == 2) + lssproto_STREET_VENDOR_send(sockfd, "N|"); + pc.iOnStreetVendor = 0; + sStreetVendorBtn = 0; + sStreetVendorBuyBtn = 0; + actBtn = 0; + closeCharActionAnimeChange(); + } + + if (focusId == FIELD_FUNC_STREET_VENDOR) + sStreetVendorBtnFocus = 1; + else + sStreetVendorBtnFocus = 0; +#else +#ifndef _BACK_VERSION +#ifdef _TABLEOFSKILL + if (pushId == FIELD_FUNC_SKILL) + { + if (selId == FIELD_FUNC_SKILL) + { + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + play_se(202, 320, 240); + actBtn = 1; + skillBtn = 1 ; + } + } + if (skillBtn == 1) + { + //ҪӴʽ + SkillWndfunc(); + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) || CheckMenuFlag()) + { + play_se(203, 320, 240); + skillBtn = 0 ; + actBtn = 0 ; + } + } + else + { + if (pActSkillWnd) + { + DeathAction(pActSkillWnd); + pActSkillWnd = NULL; + } + } + if (focusId == FIELD_FUNC_SKILL) + skillBtnFocus = 1; + else + skillBtnFocus = 0; +#endif //_TABLEOFSKILL +#endif //_BACK_VERSION +#endif //_STREET_VENDOR + // ????? + if (pushId == FIELD_FUNC_CARD) + { + cardBtn = 1; + + if (selId == FIELD_FUNC_CARD) + { + int dx, dy; + int flag; + + // ??????????? + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPoint(nowGx+dx, nowGy+dy, CHAROBJ_TYPE_USER_NPC); + // ?????V????????????? + if (partyModeFlag == 0 && flag == TRUE && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0 +#ifdef _THEATER + && pc.iTheaterMode == 0 +#endif + ) + { + if (fieldBtnPushTime+FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + // ?? + if (bNewServer) + lssproto_AAB_send(sockfd, nowGx, nowGy); + else + old_lssproto_AAB_send(sockfd, nowGx, nowGy); + fieldBtnPushTime = TimeGetTime(); + } + } +#ifdef _THEATER + if (pc.iTheaterMode > 0) + StockChatBufferLine("רı", FONT_PAL_RED); +#endif + play_se(217, 320, 240); // ????? + } + } + else + cardBtn = 0; + if (focusId == FIELD_FUNC_CARD) + cardBtnFocus = 1; // ??????????????? + else + cardBtnFocus = 0; + + +#ifdef _MO_SIGN_IN + if (pushId == FIELD_FUNC_SIGNIN) + { + signInBtn = 1; + + if (selId == FIELD_FUNC_SIGNIN) + { +#ifdef _RIDEQUERY_ + lssproto_RideQuery_send(sockfd);// + fieldBtnPushTime = TimeGetTime(); + play_se(217, 320, 240); +#endif +#ifdef _CHARSIGNDAY_ + + lssproto_SignDay_send(sockfd);// + fieldBtnPushTime = TimeGetTime(); + play_se(217, 320, 240); +#endif + } + } + else + signInBtn = 0; + if (focusId == FIELD_FUNC_SIGNIN) + signInBtnFocus = 1; // ??????????????? + else + signInBtnFocus = 0; + +#endif + +#ifdef _CHANGETEAM_ + if (pushId == FIELD_FUNC_CHANGETEAM){ + changeteamBtn = 1; + if (selId == FIELD_FUNC_CHANGETEAM) + { + lssproto_SaMenu_send(sockfd, 30); + play_se(217, 320, 240); + } + }else + changeteamBtn = 0; + if (focusId == FIELD_FUNC_CHANGETEAM) + changeteamBtnFocus = 1; + else + changeteamBtnFocus = 0; +#endif +#ifdef _NEWSHOP_ + if (pushId == FIELD_FUNC_MARKET){ + marketBtn = 1; + if (selId == FIELD_FUNC_MARKET){ +#ifdef __AI + extern void AI_CloseWnd(); + AI_CloseWnd(); +#endif + extern ACTION* ̳Ƕַ; + if(̳Ƕַ){ + DeathAction(̳Ƕַ); + windowTypeWN = -1; + wnCloseFlag = 1; + ̳Ƕַ = 0; + }else{ + extern ̳ļ_ ̳ļ[5]; + extern int util_mkint(char *buffer, int value); + extern void util_SendMesg(int fd, int func, char *buffer); + extern int util_mkstring(char *buffer, char *value); + int checksum=0; + char buf[1024*4*4]; + memset(buf,0,1024*4*4); + checksum += util_mkstring(buf,̳ļ[0].MD5); + checksum += util_mkstring(buf,̳ļ[1].MD5); + checksum += util_mkstring(buf,̳ļ[2].MD5); + checksum += util_mkstring(buf,̳ļ[3].MD5); + checksum += util_mkstring(buf,̳ļ[4].MD5); + util_mkint(buf, checksum); + util_SendMesg(sockfd, 203, buf); + } + play_se(217, 320, 240); + } + }else + marketBtn = 0; + if (focusId == FIELD_FUNC_MARKET) + marketBtnFocus = 1; // ??????????????? + else + marketBtnFocus = 0; +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + if (pushId == FIELD_FUNC_CHATROOM) + { + if( selId == FIELD_FUNC_CHATROOM) + { + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + + if (strcmp(pc.chatRoomNum, "") == 0) + { + if (SelRoomBtn == 1 || pSelChanlWnd != NULL) + SelRoomBtn = 0; + else + { + /* + // WON ADD ֹ̫Ƶ + { + unsigned int now_time = (unsigned int)time(NULL); + static unsigned int old_time = 0; + + chatRoomBtn = 1; + + if( now_time > old_time ){ + + old_time = now_time + 10; + + lssproto_CHATROOM_send( sockfd,"B|"); + } + } + + old_time = now_time + 10; + */ +#ifdef _CHATROOMPROTOCOL + lssproto_CHATROOM_send(sockfd, "B|"); +#endif + } + } + else + { + if (chatRoomBtn == 1 || pChtChanlWnd != NULL) + chatRoomBtn = 0; + else + chatRoomBtn = 1; + } + if ((joy_trg[0] & JOY_ESC) || CheckMenuFlag()) + { + play_se(203, 320, 240); + chatRoomBtn = 0 ; + } + } + } + + if(SelRoomBtn == 1) + { + SelectChatRoom(); + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) || CheckMenuFlag()) + { + play_se(203, 320, 240); + SelRoomBtn = 0 ; + } + } + else if(chatRoomBtn == 1) + { + ChatRoomWnd(); + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) || CheckMenuFlag()) + { + play_se(203, 320, 240); + chatRoomBtn = 0 ; + } + } + else + { + if (pChtChanlWnd) + { + DeathAction(pChtChanlWnd); + pChtChanlWnd = NULL; + } + if( pSelChanlWnd) + { + DeathAction(pSelChanlWnd); + pSelChanlWnd = NULL; + } + } + + if (focusId == FIELD_FUNC_CHATROOM) + chatRoomBtnFocus = 1; + else + chatRoomBtnFocus = 0; +#endif + + // Robin 04/11 Trade + if (pushId == FIELD_FUNC_TRADE) + { + tradeBtn = 1; + + if (selId == FIELD_FUNC_TRADE) + { + int dx, dy; + int flag; + + // ??????????? + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPoint(nowGx+dx, nowGy+dy, CHAROBJ_TYPE_USER_NPC); + // ?????V????????????? + if (partyModeFlag == 0 && flag == TRUE && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 + && sendEnFlag == 0 && tradeFlag == 0 +#ifdef _STREET_VENDOR + && (pc.iOnStreetVendor == 0 || sStreetVendorBuyBtn == 2) +#endif +#ifdef _THEATER + && pc.iTheaterMode == 0 +#endif + ) + { + if (fieldBtnPushTime+FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + //if (bNewServer) + // lssproto_TD_send(sockfd, "D|D"); + //else + // old_lssproto_TD_send(sockfd, "D|D"); + + joy_trg[0] |= JOY_CTRL_T; + fieldBtnPushTime = TimeGetTime(); + } + } +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1) + StockChatBufferLine("̯вýн", FONT_PAL_RED); +#endif +#ifdef _THEATER + if (pc.iTheaterMode > 0) + StockChatBufferLine("רı", FONT_PAL_RED); +#endif + //play_se(217, 320, 240); // ????? + } + } + else + tradeBtn = 0; + if (focusId == FIELD_FUNC_TRADE) + tradeBtnFocus = 1; // ??????????????? + else + tradeBtnFocus = 0; +#ifdef _ANGEL_SUMMON + if (pushId == FIELD_FUNC_ANGEL) + { + angelBtn = 1; + + if (selId == FIELD_FUNC_ANGEL) + { + if (fieldBtnPushTime+FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + //lssproto_WN_send( sockfd, nowGx, nowGy, WINDOW_MESSAGETYPE_ANGELMESSAGE, , WINDOW_BUTTONTYPE_YES, msg ) ; + if (angelFlag) + openServerWindow(WINDOW_MESSAGETYPE_MESSAGE, angelRecvButton, angelRecvType, -1, angelMsg); + else + { + if (helpBtn == 0) + { + // ???ӡP?nPϣ??????????????????????? + // ????????????? + closeEtcSwitch(); + closeJoinChannelWN(); + // \??????????? + if (CheckMenuFlag()) + InitMenu2(); + HelpProcNo = 0; + helpBtn = 1; + actBtn = 1; + jumpHelpPage = 52; + jumpHelpSeg = 29; + play_se( 202, 320, 240 ); // ???????? + } + else + HelpProcNo = 1000; + } + fieldBtnPushTime = TimeGetTime(); + } + play_se(217, 320, 240); // ????? + } + } + else + angelBtn = 0; + if (focusId == FIELD_FUNC_ANGEL) + angelBtnFocus = 1; // ??????????????? + else + angelBtnFocus = 0; + + if (angelFlag) + { + // ??? + if (angelLampFlashTime == 0 ) + { + angelLampDrawFlag = 1; + angelLampFlashTime = TimeGetTime(); + } + else if (angelLampFlashTime+FIELD_MAIL_LAMP_FLASH_TIME < TimeGetTime()) + { + angelLampDrawFlag++; + angelLampDrawFlag &= 1; + angelLampFlashTime = TimeGetTime(); + } + } + else + { + angelLampDrawFlag = 0; + angelLampFlashTime = 0; + } +#endif +#ifdef _TEACHER_SYSTEM + if (pushId == FIELD_FUNC_TEACHER && selId == FIELD_FUNC_TEACHER) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + play_se(202, 320, 240); + lssproto_TEACHER_SYSTEM_send(sockfd, "P|"); + fieldBtnPushTime = TimeGetTime(); + sTeacherSystemBtn = 0; + } + } + if (sTeacherSystemBtn == 1) + { + if (helpBtn == 0) + { + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + HelpProcNo = 0; + helpBtn = 1; + actBtn = 1; + jumpHelpPage = 54+1; + jumpHelpSeg = 30; + play_se(202,320,240); + } + else + HelpProcNo = 1000; + sTeacherSystemBtn = 0; + } + else if (sTeacherSystemBtn == 2) + TeacherSystemWndfunc(0,NULL); + else if (sTeacherSystemBtn == 3) + TeacherSystemWndfunc(1,NULL); + else if (sTeacherSystemBtn == 4) + TeacherSystemWndfunc(2,NULL); + else if (sTeacherSystemBtn == 5) + TeacherSystemWndfunc(3,NULL); +#ifdef _TEACHER_SYSTEM_2 + else if (sTeacherSystemBtn == 6) + TeacherSystemWndfunc(4,NULL); + else if (sTeacherSystemBtn == 7) + TeacherSystemWndfunc(5,NULL); +#endif + + if (focusId == FIELD_FUNC_TEACHER) + sTeacherSystemBtnFocus = 1; + else + sTeacherSystemBtnFocus = 0; +#endif + // Robin 06/01 Channel + if (selId == FIELD_FUNC_CHANNEL) + { +#ifdef _FRIENDCHANNEL + closeJoinChannelWN(); +#endif + if (pc.familyName[0] == NULL) + { + char buf[64]; + + lssproto_TK_recv(sockfd, 0, "P|ȼ塣", 0); + sprintf_s(buf, "S|P", selId); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + return; + } + if (channelWNFlag == 0) + { + if (CheckMenuFlag()) + InitMenu2(); + channelWNFlag = 1; + initJoinChannelWN(); + play_se(202, 320, 240); // ???????? + } + else + closeJoinChannelWN(); + } + if (focusId == FIELD_FUNC_CHANNEL) + channelBtnFocus = 1; + else + channelBtnFocus = 0; + + if (channelWNFlag == 1) + joinChannelWN(); + +#ifndef _CHANNEL_MODIFY + if (bNewServer && joy_trg[1] & JOY_CTRL_C) + { + char buf[64]; + + if (pc.channel == -1) + { + if ((pc.quickChannel != -1) && (pc.familyName[0] != NULL)) + { + sprintf_s(buf, "C|J|%d", pc.quickChannel); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + } + else + { + if (bNewServer) + lssproto_FM_send(sockfd, "C|J|-1"); + else + old_lssproto_FM_send(sockfd, "C|J|-1"); + } + } +#endif + + // ??????? + if (pushId == FIELD_FUNC_PARTY) + { + partyBtn = 1; + if (partyBtnEnableFlag == 0) + { + // {e????????????? + partyBtn = 0; + play_se(220, 320, 240); // ??? + } + else if (selId == FIELD_FUNC_PARTY) + { + // ?????V??????h? + if (partyModeFlag == 0) + { + int dx, dy; + int flag; + + // ?Pf????????????????? + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPointNotStatus(nowGx+dx, nowGy+dy, (CHAROBJ_TYPE_USER_NPC | CHAROBJ_TYPE_PARTY_OK), CHR_STATUS_BATTLE); + // ????????????? + if (flag == 1 && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0 +#ifdef _STREET_VENDOR + && (pc.iOnStreetVendor == 0 || sStreetVendorBuyBtn == 2) +#endif +#ifdef _THEATER + && pc.iTheaterMode == 0 +#endif + ) + { + if (fieldBtnPushTime+FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + // M????????????????????????? + if (bNewServer) + lssproto_PR_send(sockfd, nowGx, nowGy, 1); + else + old_lssproto_PR_send(sockfd, nowGx, nowGy, 1); + prSendMode = 1; + prSendFlag = 1; + etcSendFlag = 1; + fieldBtnPushTime = TimeGetTime(); + } + } +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1) + StockChatBufferLine("̯в", FONT_PAL_RED); +#endif +#ifdef _THEATER + if (pc.iTheaterMode > 0) + StockChatBufferLine("רı", FONT_PAL_RED); +#endif + } + else + // ???????h? + { + if (eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + // M???????? + if (bNewServer) + lssproto_PR_send(sockfd, nowGx, nowGy, 0); + else + old_lssproto_PR_send(sockfd, nowGx, nowGy, 0); + prSendMode = 0; + prSendFlag = 1; + etcSendFlag = 1; + fieldBtnPushTime = TimeGetTime(); +#ifdef _CHANNEL_MODIFY + TalkMode = 0; +#endif + } + } + } + play_se(217, 320, 240); // ????? + } + } + else + partyBtn = 0; + + if (focusId == FIELD_FUNC_PARTY) + partyBtnFocus = 1; // ??????????????? + else + partyBtnFocus = 0; +#ifdef __PHONEMESSAGE + // LeiBoy 2002 Feb. 2 --- Cell Phone's Messages Button -- BEGIN + if (focusId == FIELD_FUNC_MSG) + msgBtnFocus = 1; + else + msgBtnFocus = 0; + if (pushId == FIELD_FUNC_MSG) + { + extern int MsgID; + + if (selId == FIELD_FUNC_MSG) + { + if (msgBtn==0) + { + /*closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + MsgID = 0; + msgBtn = 1; + play_se(202, 320, 240); + actBtn = 1;*/ + + //::ShellExecute(hWnd, NULL, "http://www.longzoro.com/", NULL, NULL, SW_SHOW ); + + } + else + { + } + } + } + //if (msgBtn == 1) + //{ + // extern int MsgProc(); + + // int msgret = MsgProc(); + + // if (msgret) + // { + // msgBtn = 0; + // actBtn = 0; + // GetKeyInputFocus(&MyChatBuffer); + // } + //} + // LeiBoy 2002 Feb. 2 --- Cell Phone's Messages Button -- END +#endif +#ifdef _RENWU_ + extern BOOL ѯ; + extern int HelpProc(); + + if(ѯ) + if (HelpProc()==1) + { + actBtn = 0; + ѯ=FALSE; + + } +#endif + + + +#ifdef _NEW_MATCH + if (pushId == FIELD_FUNC_HELP){ + helpBtn = 1; + if (selId == FIELD_FUNC_HELP) + { + lssproto_LB_send(sockfd, nowGx, nowGy); + play_se(217, 320, 240); + } + }else + helpBtn = 0; + if (focusId == FIELD_FUNC_HELP) + helpBtnFocus = 1; + else + helpBtnFocus = 0; +#else + helpBtnFocus = 0; + if (focusId == FIELD_FUNC_HELP) + helpBtnFocus = 1; + if (selId == FIELD_FUNC_HELP) + { + extern short HelpProcNo; + + if (helpBtn == 0) + { + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + HelpProcNo = 0; + helpBtn = 1; + //actBtn = 1; + play_se( 202, 320, 240 ); + }else HelpProcNo = 1000; + } + if (helpBtn == 1) + { + extern int HelpProc(); + +#ifdef _TRADE_BUG_LOG + extern bool __writeFirstTime; + + if (__writeFirstTime) + { + FILE *logf; + logf = fopen(".\\debug.txt", "w+"); + if (logf != NULL) + { + fseek(logf, 0, SEEK_END); + struct tm nowTime; + time_t longTime; + time(&longTime); + localtime_s(&nowTime, &longTime); + fprintf(logf, "[%02d-%02d-%02d %02d:%02d:%02d] ״̬=%d; =%d; ֵ=%d\r\n", + (nowTime.tm_year % 100), nowTime.tm_mon + 1, nowTime.tm_mday, + nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, + tradeStatus, MenuToggleFlag, MenuToggleFlag & JOY_CTRL_T); + fclose(logf); + } + tradeStatus = 0; + tradeFlag = 0; + MenuToggleFlag = 0; + __writeFirstTime = false; + } + +#endif + + if (HelpProc()) + { + helpBtn = 0; + actBtn = 0; + } + } + +#endif + +#ifdef _RED_MEMOY_ + if (pushId == FIELD_FUNC_RED_MEMOY){ + redmemoyBtn = 1; + if (selId == FIELD_FUNC_RED_MEMOY) + { + extern void lssproto_redMemoy_send(int fd,int index,char *str); + lssproto_redMemoy_send(sockfd, 1, ""); + play_se(217, 320, 240); + } + }else + redmemoyBtn = 0; + if (focusId == FIELD_FUNC_RED_MEMOY) + redmemoyBtnFocus = 1; + else + redmemoyBtnFocus = 0; +#endif + + if (pushId == FIELD_FUNC_JOIN_BATTLE) + { + joinBattleBtn = 1; + if (joinBattleBtnEnableFlag == 0) + { + joinBattleBtn = 0; + play_se(220, 320, 240); + } + else if (selId == FIELD_FUNC_JOIN_BATTLE) + { + int dx, dy; + int flag; + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPointStatus(nowGx+dx, nowGy+dy, CHAROBJ_TYPE_USER_NPC, CHR_STATUS_BATTLE | CHR_STATUS_WATCH); + if ((partyModeFlag == 0 || (partyModeFlag == 1 && (pc.status & CHR_STATUS_LEADER) != 0)) + && flag == 1 && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + { + if (nowFloor == 9000) + lssproto_LB_send(sockfd, nowGx, nowGy); + else + lssproto_JB_send(sockfd, nowGx, nowGy); + } + else + old_lssproto_JB_send(sockfd, nowGx, nowGy); + jbSendFlag = 1; + etcSendFlag = 1; + fieldBtnPushTime = TimeGetTime(); + } + } + play_se(217, 320, 240); + } + } + else + joinBattleBtn = 0; + if (focusId == FIELD_FUNC_JOIN_BATTLE) + joinBattleBtnFocus = 1; + else + joinBattleBtnFocus = 0; + + if (pushId == FIELD_FUNC_DUEL) + { + duelBtn = 1; + + if (selId == FIELD_FUNC_DUEL) + { + int dx, dy; + int flag; + + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPoint(nowGx+dx, nowGy+dy, CHAROBJ_TYPE_USER_NPC); + + if ((partyModeFlag == 0 || (partyModeFlag == 1 && (pc.status & CHR_STATUS_LEADER) != 0)) + && flag == TRUE && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + lssproto_DU_send(sockfd, nowGx, nowGy); + else + old_lssproto_DU_send(sockfd, nowGx, nowGy); + duelSendFlag = 1; + etcSendFlag = 1; + fieldBtnPushTime = TimeGetTime(); + } + } + play_se(217, 320, 240); + } + } + else + duelBtn = 0; + if (focusId == FIELD_FUNC_DUEL) + duelBtnFocus = 1; + else + duelBtnFocus = 0; + + // ?????????? + if (selId == FIELD_FUNC_ACT || (joy_trg[1] & JOY_CTRL_W) +#ifdef __ONLINEGM + && OnlineGmFlag == FALSE +#endif +/*#ifdef _JOBDAILY + && JobDailyFlag == FALSE +#endif*/ + + ) + { +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000001) + { + StockChatBufferLine("רĿ", FONT_PAL_RED); + actBtn = 0; + } + else +#endif + if (actBtn == 0) + { + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + initCharActionAnimeChange(); + actBtn = 1; + play_se(202, 320, 240); + } + else + closeCharActionAnimeChange(); + } + if (actBtn == 1 && charActionAnimeChange()) + actBtn = 0; + if (focusId == FIELD_FUNC_ACT) + actBtnForcus = 1; + else + actBtnForcus = 0; + + if (mailLamp) + { + if (mailLampFlashTime == 0) + { + mailLampDrawFlag = 1; + mailLampFlashTime = TimeGetTime(); + } + else if (mailLampFlashTime + FIELD_MAIL_LAMP_FLASH_TIME < TimeGetTime()) + { + mailLampDrawFlag++; + mailLampDrawFlag &= 1; + mailLampFlashTime = TimeGetTime(); + } + } + else + { + mailLampDrawFlag = 0; + mailLampFlashTime = 0; + } +} + +void fieldProc2(void) +{ + // ?????????(CTRL+Q) + if ((joy_trg[1] & JOY_CTRL_Q)) + { + if (menuBtn == 0) + { + closeCharActionAnimeChange(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + initEtcSwitch(); + menuBtn = 1; + play_se(202, 320, 240); + } + else + closeEtcSwitch(); + } + if (menuBtn == 1 && etcSwitch()) + menuBtn = 0; +} + +#ifdef _AniCrossFrame // Syu ADD ι +void crossAniRelease() +{ + if (WaterAct2 != NULL) + { + DeathAction(WaterAct2); + WaterAct2 = NULL; + Timeflag2 = false; + } +} +#endif + +#ifdef _AniImmobile // Syu ADD ض +void ImmobileAniRelease() +{ + Updownflag = false; + for (int i = 0; i < 560; i++) + { + if (XYposition[i][3] == 1) + { + if (WaterAct3[XYposition[i][4]] != NULL) + { + DeathAction(WaterAct3[XYposition[i][4]]); + WaterAct3[XYposition[i][4]] = NULL; + XYposition[i][3] = 0 ; + XYposition[i][4] = -1 ; +// XYposition[i][5] = 1 ; //Ư2ʲ + XYposition[i][6] = 0 ; + } + } + } +} +#endif + +#ifdef _AniRandom // Syu ADD +void AniRandomRelease() +{ + for (int i = 0; i < 50; i ++) + { + if (WaterAct[i] != NULL) + { + DeathAction(WaterAct[i]); + WaterAct[i] = NULL; + } + } +} +#endif + + +// ??????????T???? +void drawField(void) +{ + int leftUpPanelX = 0; // ???????? + int leftUpPanelY = 0; + int rightUpPanelX = 504 + DISPLACEMENT_X ; // ???????? + int rightUpPanelY = 0; + int i; +#ifdef _WATERANIMATION //Syu ADD ֮ + int Createflag = 0; + int RandAnimate = 0 ; +#endif +#ifdef _AniRandom // Syu ADD + int x1 , y1; +#endif +#ifdef _AniCrossFrame // Syu ADD ι + int x2 , y2; +#endif + +#if 0 +#ifdef _STONDEBUG__MSG + + char msg[256]; + // ?????Echo?????????? + // G??????????????????????? + sprintf_s(msg, "%s Server Alive -> %02d/%02d/%02d %02d:%02d:%02d", + selectServerName2[selectServerIndex], + (serverAliveTime.tm_year % 100), serverAliveTime.tm_mon+1, serverAliveTime.tm_mday, + serverAliveTime.tm_hour, serverAliveTime.tm_min, serverAliveTime.tm_sec); + StockFontBuffer( 108, 8, FONT_PRIO_FRONT, 0, msg, 0 ); + +#endif +#endif + +#ifdef _SPECIALSPACEANIM // Syu ADD ⳡ + SpecAnim(nowFloor); +#endif +#ifdef _AniCrossFrame // Syu ADD ι + if ((nowFloor == 817) || (nowFloor == 8007) || (nowFloor == 8101) || (nowFloor == 8100) || + (nowFloor == 8027) || (nowFloor == 8028) || (nowFloor == 8029) || (nowFloor == 8015) || (nowFloor == 8113) || (nowFloor == 8114) ) + { + //ι涯 Start + if (flag22 == false) + { + if (WaterAct2 != NULL && Timeflag2 == false) + { + DeathAction(WaterAct2); + WaterAct2 = NULL; + Timeflag2 = true; + //һγֵĵȴʱ + TimeTickMax2 = RAND(500, 1500); + } + } + if (Timeflag2 == true) + { + TimeTick2 ++; + if (TimeTick2 > TimeTickMax2) + { + Timeflag2 = false; + TimeTick2 = 0 ; + } + } + if (WaterAct2 == NULL || delFlag == false) + { + delFlag = true; + flag22 = true; + x2 = RAND(0, 1); + RandAnimate = RAND(0, 2); + if (RandAnimate > 1) + RandAnimate = RAND(101512, 101515); + //¡¡ϡĸ + else + { + RandAnimate = RAND(0, 4); + if (RandAnimate > 2) + RandAnimate = RAND(101582, 101593); + else + RandAnimate = RAND(101516, 101523); + if (RandAnimate == 101516 || RandAnimate == 101518) + x2 = RAND(2, 3); + else if (RandAnimate == 101521 || RandAnimate == 101523 || + (RandAnimate <= 101587 && RandAnimate >= 101582)) + x2 = RAND(4, 5); // + else if (RandAnimate == 101522 || RandAnimate == 101520 || + (RandAnimate <= 101593 && RandAnimate >= 101588)) + x2 = RAND(6, 7); // + } + //뻭λ + if (x2 == 0) // + { + x2 = RAND(50, lpDraw->xSize); + y2 = 0 ; + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 1) + { + x2 = 640 ; + y2 = RAND(50, lpDraw->ySize); + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 2) // + { + x2 = RAND(0, lpDraw->xSize); + y2 = 0 ; + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 3) + { + x2 = 0 ; + y2 = RAND(50, lpDraw->ySize); + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 4) // + { + x2 = RAND(50, lpDraw->xSize); + y2 = lpDraw->ySize ; + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 5) + { + x2 = lpDraw->xSize ; + y2 = RAND(50, lpDraw->ySize); + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 6) // + { + x2 = 0 ; + y2 = RAND(50, lpDraw->ySize); + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + else if (x2 == 7) + { + x2 = RAND(0, lpDraw->xSize); + y2 = lpDraw->ySize ; + WaterAct2 = MakeAnimDisp(x2, y2, RandAnimate, 18); + } + } + } + if ((nowFloor != 817 ) && (nowFloor != 8007) && (nowFloor != 8100) && (nowFloor != 8101) && + (nowFloor != 8027) && (nowFloor != 8028) && (nowFloor != 8029) && (nowFloor != 8015) && (nowFloor != 8113) && (nowFloor != 8114) ) + { + delFlag = false; + flag22 = true; + Timeflag2 = false; + } +#endif + +#ifdef _AniImmobile // Syu ADD ض + if (nowFloor == 817) + { + in817flag = true ; + for (i = 0; i < 560; i++) + { + //ж϶㶯Ƿ 32 * 32Χ + if ((nowGx > XYposition[i][0] - 16) && (nowGx < XYposition[i][0] + 16) && + (nowGy > XYposition[i][1] - 16) && (nowGy < XYposition[i][1] + 16)) + { + //жǷѲ + if (XYposition[i][3] == 0) + { + //ACTION + for (int j = 0; j < 30; j++) + { + if (WaterAct3[j] == NULL) + { + if (XYposition[i][5] == 2) + WaterAct3[j] = createWaterAnimation(XYposition[i][2], XYposition[i][0], XYposition[i][1], 0); + else + WaterAct3[j] = createWaterAnimation(XYposition[i][2], XYposition[i][0], XYposition[i][1], 30); + XYposition[i][3] = 1; + XYposition[i][4] = j; + break; + } + } + } + else + { + //㶯Ư + XYposition[i][6]++; + //ʱ̶ + if (XYposition[i][6] > 65) + { + XYposition[i][6] = 0; + //(XYposition[i][5]== 1 ) ? 0 : 1; + if (XYposition[i][5] == 1) + XYposition[i][5] = 0; + else if (XYposition[i][5] == 0) + XYposition[i][5] = 1; + } + if (XYposition[i][5] == 1) + { + WaterAct3[XYposition[i][4]]->mx = WaterAct3[XYposition[i][4]]->mx + float(0.5); + WaterAct3[XYposition[i][4]]->my = WaterAct3[XYposition[i][4]]->my - float(0.5); + } + else if (XYposition[i][5] == 0) + { + WaterAct3[XYposition[i][4]]->mx = WaterAct3[XYposition[i][4]]->mx - float(0.5); + WaterAct3[XYposition[i][4]]->my = WaterAct3[XYposition[i][4]]->my + float(0.5); + } + } + } +// ϲ + if (XYposition[i][3] == 1) + { + if ((nowGx < XYposition[i][0] - 16) || (nowGx > XYposition[i][0] + 16 ) || + (nowGy < XYposition[i][1] - 16) || (nowGy > XYposition[i][1] + 16)) + { + if (WaterAct3[XYposition[i][4]] != NULL) + { + DeathAction(WaterAct3[XYposition[i][4]]); + WaterAct3[XYposition[i][4]] = NULL; + XYposition[i][3] = 0; + } + } + } + } + } + else + { + if (in817flag == true) + { + for (i = 0; i < 560; i++) + { + if (XYposition[i][3] == 1) + { + if (WaterAct3[XYposition[i][4]] != NULL) + { + DeathAction(WaterAct3[XYposition[i][4]]); + WaterAct3[XYposition[i][4]] = NULL; + XYposition[i][3] = 0; + } + } + } + in817flag = false ; + } + } +#endif + +#ifdef _AniRandom // Syu ADD + if ((nowFloor == 817) || (nowFloor == 8007) || (nowFloor == 8100) || (nowFloor == 8101) || + (nowFloor == 8029) || (nowFloor == 8028) || (nowFloor == 8027) || (nowFloor == 8015) || (nowFloor == 8113) || (nowFloor == 8114) ) //жϵͼ + { + AniFlag = true; + for (i = 0; i < 50; i++) + { + if (Timeflag[i] == false) + { + //񣬲񶼲ȴʱ + Createflag = RAND(0, 3); + if (Createflag > 0) + { + if (WaterAct[i] == NULL) + { + //Χ 30 * 30 Χ + x1 = RAND(nowGx - 15, nowGx + 15); + y1 = RAND(nowGy - 15, nowGy + 15); + RandAnimate = RAND(0, 6); + if (RandAnimate > 2) + RandAnimate = RAND(101502, 101509); + else + RandAnimate = RAND(101524, 101529); + WaterAct[i]=createWaterAnimation(RandAnimate, x1, y1, 103); + Timeflag[i] = true; + TimeTickMax[i] = RAND(100, 400); + } + } + else + { + Timeflag[i] = true; + TimeTickMax[i] = RAND(300, 600); + } + } + } + //ŵĻʱ + for (i = 0; i < 50; i++) + { + if (Timeflag[i] == true) + TimeTick[i]++; + if (TimeTick[i] > TimeTickMax[i]) + { + TimeTick[i] = -100; + Timeflag[i] = false; + DeathAction(WaterAct[i]); + WaterAct[i] = NULL; + } + } + } + //𶯻 + else if (((nowFloor != 817) && (nowFloor != 8007) && (nowFloor != 8100) && (nowFloor != 8101) && (nowFloor != 8113) && (nowFloor != 8114) && + (nowFloor != 8027) && (nowFloor != 8028) && (nowFloor != 8029) && (nowFloor != 8015)) && (AniFlag == true)) + { + AniFlag = false; + for (i = 0; i < 50; i++) + { + if (WaterAct[i] != NULL) + { + DeathAction(WaterAct[i]); + WaterAct[i] = NULL; + } + } + } +#endif + + if (drawFieldButtonFlag) + { +#ifdef __PHONEMESSAGE +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- BEGIN +#ifdef _TABLEOFSKILL +#ifdef _ANGEL_SUMMON +#ifdef _TEACHER_SYSTEM + StockDispBuffer(leftUpPanelX + 163, leftUpPanelY + 27, DISP_PRIO_MENU, CG_FIELD_TS_LEFT_MENU, 0); +#else + StockDispBuffer(leftUpPanelX + 150, leftUpPanelY + 29, DISP_PRIO_MENU, CG_FIELD_MENU_LEFT_75, 0); +#endif + if (angelLampDrawFlag) + StockDispBuffer(leftUpPanelX + 64, leftUpPanelY + 42, DISP_PRIO_IME3, CG_FIELD_ANGEL_LAMP, 0); +#else +#ifdef _FRIENDCHANNEL + StockDispBuffer(leftUpPanelX + 141, leftUpPanelY + 29, DISP_PRIO_MENU, CG_FIELD_CHANNEL_MENU, 0); +#else + StockDispBuffer(leftUpPanelX + 141, leftUpPanelY + 29, DISP_PRIO_MENU, CG_FIELD_SKILL_MENU, 0); +#endif +#endif +#else + StockDispBuffer(leftUpPanelX + 100, leftUpPanelY + 28, DISP_PRIO_MENU, CG_FIELD_MENU_LEFT, 0); +#endif +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- END +#else + +//#ifdef __FAMILY_UI_ + if (bNewServer) + // ?????? +#ifdef _SPECIAL_LOGO +#ifdef _SA_VERSION_25 + StockDispBuffer(leftUpPanelX + 148, leftUpPanelY + 27, DISP_PRIO_MENU, CG_FIELD_MENU_LEFT_NEW, 0); +#endif + +#else + StockDispBuffer(leftUpPanelX + 26 + 58, leftUpPanelY + 28, DISP_PRIO_MENU, CG_FIELD_MENU_LEFT_NEW, 0); +#endif + else + + StockDispBuffer(leftUpPanelX + 26 + 52, leftUpPanelY + 28, DISP_PRIO_MENU, CG_FIELD_MENU_LEFT, 0); +#endif + + +#ifdef _MO_SIGN_IN + static int ʱ; +#ifdef _CHARSIGNADY_NO_ + extern PC pc; + static DWORD ʱ¼ = TimeGetTime() + 300; + if(!pc.ǩ){ + if(ʱ¼ < TimeGetTime()){ + ʱ¼ = TimeGetTime() + 300; + if(ʱ) ʱ =0; + else ʱ=1; + } + }else ʱ = signInBtn; +#else + ʱ = signInBtn; +#endif + fieldBtnHitId[FIELD_FUNC_SIGNIN] = StockDispBuffer(leftUpPanelX + 207, leftUpPanelY + 19, DISP_PRIO_IME3, signInBtnGraNo[ʱ], 2); + if (signInBtnFocus) +#ifdef _SA_VERSION_25 + ShowBottomLineString(FONT_PAL_WHITE, "ѯ"); +#endif +#endif + +#ifdef _CHANGETEAM_ +#ifdef _SA_VERSION_25 + fieldBtnHitId[FIELD_FUNC_CHANGETEAM] = StockDispBuffer(leftUpPanelX + 241, leftUpPanelY + 19, DISP_PRIO_IME3, schangeteamBtnGraNo[changeteamBtn], 2); +#endif + if (changeteamBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "ӳл"); + +#endif + +#ifdef _NEWSHOP_ +#ifdef _SA_VERSION_25 + fieldBtnHitId[FIELD_FUNC_MARKET] = StockDispBuffer(leftUpPanelX + 271, leftUpPanelY + 19, DISP_PRIO_IME3, marketBtnGraNo[marketBtn], 2); + if (marketBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "̳ǹܡ"); +#endif +#endif + +#ifdef _STREET_VENDOR + fieldBtnHitId[FIELD_FUNC_STREET_VENDOR] = StockDispBuffer(leftUpPanelX + 176, leftUpPanelY + 19, DISP_PRIO_IME3, sStreetVendorBtnGraNo[pc.iOnStreetVendor], 2); + if (sStreetVendorBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "̯ܡ"); +#else + #ifdef _TABLEOFSKILL + fieldBtnHitId[FIELD_FUNC_SKILL] = StockDispBuffer(leftUpPanelX + 108, leftUpPanelY + 28, DISP_PRIO_IME3, skillBtnGraNo[skillBtn], 2); + if (skillBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "ְҵܡ"); + #endif +#endif + // ???????? + fieldBtnHitId[FIELD_FUNC_MENU] = StockDispBuffer(leftUpPanelX + 52, leftUpPanelY + 28, DISP_PRIO_IME3, menuBtnGraNo[menuBtn], 2); + if (menuBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "Ϸ趨"); + // ???? + fieldBtnHitId[FIELD_FUNC_CARD] = StockDispBuffer(leftUpPanelX + 52, leftUpPanelY + 28, DISP_PRIO_IME3, cardBtnGraNo[cardBtn], 2); + if (cardBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "Ƭ"); + // Robin 04/12 Trade + fieldBtnHitId[FIELD_FUNC_TRADE] = StockDispBuffer(leftUpPanelX + 104 + 10, leftUpPanelY + 28 - 10, DISP_PRIO_IME3, tradeBtnGraNo[tradeBtn], 2); + if (tradeBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "нס"); + +#ifdef __PHONEMESSAGE +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- BEGIN +#ifdef _TABLEOFSKILL + fieldBtnHitId[FIELD_FUNC_MSG] = StockDispBuffer(leftUpPanelX + 132, leftUpPanelY + 28, DISP_PRIO_IME3, msgBtnGraNo[msgBtn], 2); +#else + fieldBtnHitId[FIELD_FUNC_MSG] = StockDispBuffer(leftUpPanelX + 101, leftUpPanelY + 28, DISP_PRIO_IME3, msgBtnGraNo[msgBtn], 2); +#endif + + if (msgBtnFocus) + + ShowBottomLineString(FONT_PAL_WHITE, "ѣ̳ǡ"); + +// LeiBoy 2002 Jan.26 --- Cell Phone's Messages Button -- END +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + if (SelRoomBtn == 1 || chatRoomBtn == 1) + fieldBtnHitId[FIELD_FUNC_CHATROOM] = StockDispBuffer(leftUpPanelX + 141, leftUpPanelY + 29, DISP_PRIO_IME3, chatRoomBtnGraNo[1], 2); + else + fieldBtnHitId[FIELD_FUNC_CHATROOM] = StockDispBuffer(leftUpPanelX + 141, leftUpPanelY + 29, DISP_PRIO_IME3, chatRoomBtnGraNo[0], 2); + if (chatRoomBtnFocus) + { + if(strcmp(pc.chatRoomNum, "") == 0) + ShowBottomLineString(FONT_PAL_WHITE, "ѡƵ"); + else + ShowBottomLineString(FONT_PAL_WHITE, "Ƶ"); + } +#endif +//#ifdef __FAMILY_UI_ + if (bNewServer) + { + // Robin 06/01 Channel +#ifndef _CHANNEL_MODIFY + if (pc.channel != -1) + channelBtn = 1; + else + channelBtn = 0; +#else + if (pc.channel == 5) + channelBtn = 1; + else + channelBtn = 0; +#endif + fieldBtnHitId[FIELD_FUNC_CHANNEL] = StockDispBuffer(leftUpPanelX + 115, leftUpPanelY + 28, DISP_PRIO_IME3, channelBtnGraNo[channelBtn], 2); + if (channelBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "幦ܡ"); + } +//#endif + // ?????? + fieldBtnHitId[FIELD_FUNC_PARTY] = StockDispBuffer(leftUpPanelX + 52, leftUpPanelY + 28, DISP_PRIO_IME3, partyBtnGraNo[partyBtn], 2); + if (partyBtnFocus) + { + // ?????C + // {e??????????????????? + if (partyBtnEnableFlag == 0) + ShowBottomLineString(FONT_PAL_WHITE, "ܼ顣"); + else + ShowBottomLineString(FONT_PAL_WHITE, "顣"); + } + + // ??????? + if (mailLampDrawFlag) + StockDispBuffer(leftUpPanelX + 52, leftUpPanelY + 28, DISP_PRIO_IME3, CG_FIELD_MAIL_LAMP, 0); + +#ifdef _RED_MEMOY_ + StockDispBuffer(rightUpPanelX + 40, rightUpPanelY + 31, DISP_PRIO_MENU, CG_FIELD_MENU_RIGHT, 0); + fieldBtnHitId[FIELD_FUNC_RED_MEMOY] = StockDispBuffer(rightUpPanelX - 34, rightUpPanelY + 19, DISP_PRIO_IME3, redmemoyGraNo[redmemoyBtn], 2); + if (redmemoyBtnFocus) ShowBottomLineString(FONT_PAL_WHITE, ""); +#else + StockDispBuffer(rightUpPanelX + 54, rightUpPanelY + 33, DISP_PRIO_MENU, CG_FIELD_MENU_RIGHT, 0); +#endif + fieldBtnHitId[FIELD_FUNC_JOIN_BATTLE] = StockDispBuffer(rightUpPanelX + 38, rightUpPanelY + 32, DISP_PRIO_IME3, joinBattleBtnGraNo[joinBattleBtn], 2); + if (joinBattleBtnFocus) + { +#ifdef _NEW_MATCH + ShowBottomLineString(FONT_PAL_WHITE, "ս"); +#else + if (joinBattleHelpMsgFlag == 1) + ShowBottomLineString(FONT_PAL_WHITE, "ս"); + else if (joinBattleHelpMsgFlag == 2) + ShowBottomLineString(FONT_PAL_WHITE, "ܼս"); + else + ShowBottomLineString(FONT_PAL_WHITE,"ս"); +#endif + } + + // ?ƢnP??? + fieldBtnHitId[FIELD_FUNC_DUEL] = StockDispBuffer(rightUpPanelX + 38, rightUpPanelY + 32, DISP_PRIO_IME3, duelBtnGraNo[duelBtn], 2); + if (duelBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "Ҿ"); + if (helpBtnFocus) +#ifdef _NEW_MATCH + ShowBottomLineString(FONT_PAL_WHITE, "ս"); +#else + ShowBottomLineString(FONT_PAL_WHITE, "ѯ"); +#endif + fieldBtnHitId[FIELD_FUNC_HELP] = StockDispBuffer(rightUpPanelX + 115, rightUpPanelY + 33, DISP_PRIO_IME3, helpBtnGraNo[helpBtn], 2); + fieldBtnHitId[FIELD_FUNC_ACT] = StockDispBuffer(rightUpPanelX + 68, rightUpPanelY + 32, DISP_PRIO_IME3, actBtnGraNo[actBtn], 2); + if (actBtnForcus) + ShowBottomLineString(FONT_PAL_WHITE, "ĸֶ"); + + // ????? + if (drawTimeAnimeFlag) + { + StockDispBuffer(rightUpPanelX + 104 - amPmAnimeX, rightUpPanelY + 21, DISP_PRIO_MENU, amPmAnimeGraNo[amPmAnimeGraNoIndex0], 0); + StockDispBuffer(rightUpPanelX + 104 + 64 - amPmAnimeX, rightUpPanelY + 21, DISP_PRIO_MENU, amPmAnimeGraNo[amPmAnimeGraNoIndex1], 0); + } + else + // ??????????????????????????? + StockDispBuffer(rightUpPanelX + 68, rightUpPanelY + 32, DISP_PRIO_MENU, CG_FIELD_MENU_RIGHT_BACK, 0); + +#ifdef _ANGEL_SUMMON + fieldBtnHitId[FIELD_FUNC_ANGEL] = StockDispBuffer(leftUpPanelX + 104 + 10 + 158, leftUpPanelY + 20, DISP_PRIO_IME3, angelBtnGraNo[angelBtn], 2); + if (angelBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "ٻ"); +#endif +#ifdef _TEACHER_SYSTEM + fieldBtnHitId[FIELD_FUNC_TEACHER] = StockDispBuffer(leftUpPanelX + 305, leftUpPanelY + 20, DISP_PRIO_IME3, iTeacherSystemBtnGraNo[sTeacherSystemBtn > 0 ? 1:0], 2); + if (sTeacherSystemBtnFocus) + ShowBottomLineString(FONT_PAL_WHITE, "ʦϵͳ"); +#endif + } + else + { + for (i = 0; i < FIELD_FUNC_END; i++) + fieldBtnHitId[i] = -2; + } +} + +// ???????????? +BOOL checkFieldMenuFlag(void) +{ + return nowFieldMenuOpenFlag; +} + +// ?????????????? +// ??? +void initCharActionAnimeChange(void) +{ + charActionAnimeChangeProcNo = 0; +} + +// ??????? +void closeCharActionAnimeChange(void) +{ + charActionAnimeChangeProcNo = 1000; +} + +int charActionAnimeChange(void) +{ + static int x, y, w, h; + static int btnId[13]; + int id = 0; + int focusId = 0; + char *msg[] = + { + " ", + " վ ", + " ", + " ", + " ͷ ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " Ͷ " +#ifdef __EMOTION + ," " + ," " +#endif + }; + char *msg2[] = + { + "µĶ (Ctrl+1)", + "վĶ (Ctrl+7)", + "ֵĶ (Ctrl+2)", + "߶Ķ (Ctrl+8)", + "ͷĶ (Ctrl+3)", + "εĶ (Ctrl+9)", + "˵Ķ (Ctrl+4)", + "Ķ (Ctrl+0)", + "Ķ (Ctrl+5)", + "Ķ (Ctrl+-)", + "˵Ķ (Ctrl+6)", + "˵Ķ (Ctrl+=)", + "ͶĶ (Ctrl+\\)" +#ifdef __EMOTION + ,"˯Ķ" + ,"䳡Ķ" +#endif + }; + int i, j; + int x1, y1, x2, y2; + int chgTbl[] = + { + 5, // ? ? + 3, // ? ? + 6, // ?? + 4, // ? + 11, // ???? + 2, // X?? + 7, // ? ? + 0, // ? ? + 8, // W ? + 10, // ??? + 9, // v?? + 1, // ???? + 12 // ??? + }; +#ifdef __EMOTION + int emotion[] = { SPR_sleep, SPR_stone}; +#endif + + if (charActionAnimeChangeProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + btnId[i] = -2; + + // ?????? + w = 3; + h = 6; + x = 440; + y = 16; + // лͼBUG + ptActMenuWin1 = MakeWindowDisp(x, y, w, h, NULL, 1); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActMenuWin1->x; + y = ptActMenuWin1->y; +#endif + charActionAnimeChangeProcNo++; + } + // лͼBUG + if (ptActMenuWin1 != NULL) + { + id = -1; + focusId = -1; + // лͼBUG + if (ptActMenuWin1->hp >= 1) + { + // ????kRe + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + focusId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + +#ifdef __EMOTION + for (i = 0; i < 7; i++) +#else + for (i = 0; i < 6; i++) +#endif + { + for (j = 0; j < 2; j++) + { + x1 = x + 84 * j + 18; + y1 = y + i * 30 + 21; + x2 = x1 + 73; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + id = i * 2 + j + 1; + focusId = i * 2 + j + 1; + } + } + } + +#ifdef __EMOTION + i = 7; +#else + i = 6; +#endif + j = 0; + x1 = x + 42 + 18; + y1 = y + i * 30 + 21; + x2 = x1 + 73; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + id = i * 2 + j + 1; + focusId = i * 2 + j + 1; + } + } + + // \????????????????????? + if (CheckMenuFlag()) + id = 100; + else if ((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) // ESC???????? + { + id = 100; + play_se(203, 320, 240); // ???????? + } + else if (charActionAnimeChangeProcNo == 1000) // ??????????? + id = 100; + + // ????? + if (id == 0) + play_se(203, 320, 240); // ???????? + else if (1 <= id && id <= 13) + { + id--; + if (eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + lssproto_AC_send(sockfd, nowGx, nowGy, chgTbl[id]); + else + old_lssproto_AC_send(sockfd, nowGx, nowGy, chgTbl[id]); + setPcAction(chgTbl[id]); + fieldBtnPushTime = TimeGetTime(); + } + } + // ????????k????????????????? + id = -1; + play_se(217, 320, 240); // ????? + } +#ifdef __EMOTION + if (14 <= id && id <= 15) + { + id -= 14; + setPcEmotion(emotion[id]); + id = -1; + play_se(217, 320, 240); // ????? + } +#endif + if (id >= 0) + { + // лͼBUG + DeathAction(ptActMenuWin1); + ptActMenuWin1 = NULL; + return 1; + } + // лͼBUG + if (ptActMenuWin1->hp >= 1) + { + btnId[0] = StockDispBuffer(x + 96, y + 258, DISP_PRIO_MENU, CG_CLOSE_BTN, 2); + if (focusId == 0) + ShowBottomLineString(FONT_PAL_WHITE, "رնӴ"); +#ifdef __EMOTION + for (i = 0; i < 7; i++) +#else + for (i = 0; i < 6; i++) +#endif + { + for (j = 0; j < 2; j++) + { + StockFontBuffer(x + 84 * j + 20, y + i * 30 + 24, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg[i * 2 + j], 0); + if ((i * 2 + j) == (focusId - 1)) + ShowBottomLineString(FONT_PAL_WHITE, msg2[i * 2 + j]); + } + } +#ifdef __EMOTION + i = 7; +#else + i = 6; +#endif + j = 0; + StockFontBuffer(x + 42 + 20, y + i * 30 + 24, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg[i * 2 + j], 0); + if ((i * 2 + j) == (focusId - 1)) + ShowBottomLineString(FONT_PAL_WHITE, msg2[i * 2 + j]); + } + } + + return 0; +} + +// ???ӡP?nPϣ????????? +// ??? +void initEtcSwitch(void) +{ + etcSwitchProcNo = 0; +} + +// ??????? +void closeEtcSwitch(void) +{ + etcSwitchProcNo = 1000; +} + +// ???ӡP?nPϣ?????? +// ??k: 0 ... ??? +// !0 ... ???? +#ifdef _CHANNEL_MODIFY +void SaveChatData(char *msg,char KindOfChannel,bool bCloseFile); +#endif + +short onlinegmProcNo; + +int etcSwitch(void) +{ + static ACTION *ptActMenuWin = NULL; +#ifdef _CHANNEL_MODIFY + static ACTION *pActChannelWin = NULL; + static int iChannelbtnId[6]; + FILE *pf = NULL; +#endif + static int x, y, w, h; + + static int btnId[8]; + + int id = 0; + int focusId = 0; + char *msg[] = + { + " ӣ", + " ", + "Ƭ", +#ifndef _CHANNEL_MODIFY + " 죺", +#else +#ifdef _NEWFONT_ + "Ƶ ", +#else + "Ƶ ", +#endif +#endif + " ף", +#ifdef __ONLINEGM + " ", +#endif +//#ifdef _JOBDAILY +// " ־", +//#endif + }; + + char *msg2[] = + { + " ", + " ٣ţ", + //" Other" + }; +#ifndef _CHANNEL_MODIFY + char *msg3[] = + { + " ȫ Ա", + " " + }; +#endif + char *msg4[] = + { + "趨Ƿ˼Ķ顣", + "趨Ƿ˵ս", + "趨ǷƬ", +#ifndef _CHANNEL_MODIFY + "趨ݿԱķΧ", +#else + "趨ƵĿرա", +#endif + "趨Ƿܽס" +#ifdef __ONLINEGM + , + "ϻرϵͳ", +#endif +//#ifdef _JOBDAILY +// "鿴־", +//#endif + }; + + unsigned int mask[] = + { + PC_ETCFLAG_PARTY, + PC_ETCFLAG_DUEL, + PC_ETCFLAG_MAIL, +#ifndef _CHANNEL_MODIFY + PC_ETCFLAG_CHAT_MODE, +#else + 0, +#endif + PC_ETCFLAG_TRADE +#ifdef __ONLINEGM + ,0 +#endif + }; +#ifdef _CHANNEL_MODIFY + char *pszChannel[] = { + "Ƶ", + "Ƶ", +#ifdef _CHAR_PROFESSION + "ְҵƵ", +#endif + "Ի" +#ifdef _CHANNEL_WORLD + ,"Ƶ" +#endif +#ifdef _CHANNEL_ALL_SERV + ,"Ƶ" +#endif + }; + int iChannelSwitch[] = { + PC_ETCFLAG_CHAT_TELL + ,PC_ETCFLAG_CHAT_FM +#ifdef _CHAR_PROFESSION + ,PC_ETCFLAG_CHAT_OCC +#endif + ,PC_ETCFLAG_CHAT_SAVE +#ifdef _CHANNEL_WORLD + ,PC_ETCFLAG_CHAT_WORLD +#endif +#ifdef _CHANNEL_ALL_SERV + ,PC_ETCFLAG_ALL_SERV +#endif + }; +#endif + +/*#ifdef _JOBDAILY + char *msg5[] = { + " ", + "һҳ", + "һҳ" + }; +#endif*/ + + int i; + int x1, y1, x2, y2; + + if (etcSwitchProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + btnId[i] = -2; + + // ?????? + w = 3; + h = 5; + x = 16; + //x = 440; + //y = 72; + y = 16; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1); //ptActMenuWin = MakeWindowDisp(x, y, w, h+1, NULL, 1); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + etcSwitchProcNo++; + } +#ifdef _CHANNEL_MODIFY + // ƵӴ + if (etcSwitchProcNo == 100) + { + w = 3; + + h = 5; + + x = 16; + y = 16; + pActChannelWin = MakeWindowDisp(x, y, w, h, NULL, 1); + etcSwitchProcNo++; + } + + if (pActChannelWin != NULL) + { + id = -1; + focusId = -1; + if (pActChannelWin->hp >= 1) + { + id = selGraId(iChannelbtnId, sizeof(iChannelbtnId) / sizeof(int)); + focusId = focusGraId(iChannelbtnId, sizeof(iChannelbtnId) / sizeof(int)); + for (i = 0; i < sizeof(pszChannel) / sizeof(char*); i++) + { + x1 = x + 18; + y1 = y + i * 30 + 23; + x2 = x1 + 157; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + id = i + 1; + focusId = i + 1; + } + } + + if (CheckMenuFlag()) + id = 100; + else if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL)) + { + id = 100; + play_se(203, 320, 240); + } + else if (etcSwitchProcNo == 1000) + id = 100; + + if (id == 0) + play_se(203, 320, 240); + else if (1 <= id && id <= sizeof(msg) / sizeof(char*)) + { + id--; + if (pc.etcFlag & iChannelSwitch[id]) + { + pc.etcFlag &= ~iChannelSwitch[id]; + TalkMode = 0; + } + else + pc.etcFlag |= iChannelSwitch[id]; + switch (id) + { + case 1: + if (pc.familyleader <= 0) + { + StockChatBufferLine("δ", FONT_PAL_RED); + pc.etcFlag &= ~iChannelSwitch[id]; + } + break; +#ifdef _CHAR_PROFESSION + case 2: + if (pc.profession_class == 0) + { + StockChatBufferLine("δְ", FONT_PAL_RED); + pc.etcFlag &= ~iChannelSwitch[id]; + } + break; +#else + case 2: + if (!(pc.etcFlag & iChannelSwitch[id])) + SaveChatData(NULL, 0, true); + break; +#endif +#ifdef _CHANNEL_WORLD + case 3: + if ( pc.etcFlag & iChannelSwitch[id] ) + { + SaveChatData(NULL, 0, true); + } + break; +#endif +#ifdef _CHANNEL_ALL_SERV + case 4: + if ( pc.etcFlag & iChannelSwitch[id] ) + { + SaveChatData(NULL, 0, true); + } + break; +#endif + } + if (eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + if (bNewServer) + lssproto_FS_send(sockfd, pc.etcFlag); + else + old_lssproto_FS_send(sockfd, pc.etcFlag); + + fieldBtnPushTime = TimeGetTime(); + } + else + etcSwitchChangeFlag = 1; + } + id = -1; + play_se(217, 320, 240); + } + if (id >= 0) + { + DeathAction(pActChannelWin); + pActChannelWin = NULL; + if ((pf = fopen("data\\channel.dat","w+")) == NULL) + StockChatBufferLine("Ƶ趨ȡʧ", FONT_PAL_RED); + else + { + char buf[5]; + + buf[0] = (pc.etcFlag & PC_ETCFLAG_CHAT_TELL) ? 1:0; + buf[1] = (pc.etcFlag & PC_ETCFLAG_CHAT_SAVE) ? 1:0; +#ifdef _CHAR_PROFESSION + buf[2] = (pc.etcFlag & PC_ETCFLAG_CHAT_OCC) ? 1:0; +#endif +#ifdef _CHANNEL_WORLD + buf[3] = (pc.etcFlag & PC_ETCFLAG_CHAT_WORLD) ? 1:0; +#endif +#ifdef _CHANNEL_ALL_SERV + buf[4] = (pc.etcFlag & PC_ETCFLAG_ALL_SERV) ? 1:0; +#endif + fwrite(buf, 1, sizeof(buf), pf); + fclose(pf); + } + return 1; + } + + + iChannelbtnId[0] = StockDispBuffer(x + 96, h * 48 - 24, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + + if (focusId == 0) + ShowBottomLineString(FONT_PAL_WHITE, "رѡӴ"); + + for (i = 0; i < sizeof(pszChannel) / sizeof(char*); i++) + { + StockFontBuffer(x + 20, y + i * 30 + 26, FONT_PRIO_FRONT, FONT_PAL_WHITE, pszChannel[i], 0); + StockFontBuffer(x + 105, y + i * 30 + 26, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg2[((pc.etcFlag & iChannelSwitch[i]) ? 1:0)], 0); + } + } + } +#endif +#ifdef __ONLINEGM + if (etcSwitchProcNo == 200) + { + int ret = iOnlineGmProc(); + + if (ret) + { // ر + GetKeyInputFocus(&MyChatBuffer); + OnlineGmFlag = FALSE; + return 1; + } + else + OnlineGmFlag = TRUE; + } +#endif +/*#ifdef _JOBDAILY + + if(etcSwitchProcNo==201){ + w = 8; + h = 7; + x = 63; + y = 70; + pActJobdailyWin = MakeWindowDisp( x, y, w, h, NULL, 1 ); + for(i=0;ihp >= 1){ + StockFontBuffer(274,94,FONT_PRIO_FRONT,FONT_PAL_YELLOW," ־",0); + StockFontBuffer(x+30,118,FONT_PRIO_FRONT,FONT_PAL_GREEN," --------------------˵--------------------",0); + StockFontBuffer(x+440,118,FONT_PRIO_FRONT,FONT_PAL_GREEN,"״̬",0); + + if(JobdailyGetFlag){ //ѽյ + char buf[20]; + for(i=0;i<10;i++){ + sprintf_s(buf,"%d",jobdaily[i+PageIndex*10].JobId); + if(!atoi(buf)) buf[0] = '\0'; + if(jobdaily[i+PageIndex*10].explain[0]==NULL) MaxPage = PageIndex+1; + StockFontBuffer(x+30,145+i*20,FONT_PRIO_FRONT,FONT_PAL_WHITE,buf,0); + StockFontBuffer(x+72,145+i*20,FONT_PRIO_FRONT,FONT_PAL_WHITE,jobdaily[i+PageIndex*10].explain,0); + StockFontBuffer(x+432 ,145+i*20,FONT_PRIO_FRONT,FONT_PAL_WHITE,jobdaily[i+PageIndex*10].state,0); + } + + } + + id = selGraId(iJobdailybtnId,sizeof(iJobdailybtnId)/sizeof(int)); + focusId = focusGraId(iJobdailybtnId,sizeof(iJobdailybtnId)/sizeof(int)); + + for(i = 0;i < sizeof(msg5)/sizeof(char*);i++){ + x1 = x+78+i*150; + y1 = y+30+23+196+45; + x2 = x1 + 48; + y2 = y1 + 22; + if(i==1) if(PageIndex==0) continue; //һҳ + if(i==2) if(PageIndex==MaxPage-1) continue; //һҳ + if(MakeHitBox(x1,y1,x2,y2,DISP_PRIO_BOX2)){ + if(mouse.onceState & MOUSE_LEFT_CRICK) id = i+1; + focusId = i+1; + } + } + + if(CheckMenuFlag()) id = 100; + else if(((joy_trg[0] & JOY_ESC) && GetImeString() == NULL)){ + id = 100; + play_se(203,320,240); + } + else if(etcSwitchProcNo == 1000) id = 100; + + if(id == 1){ + play_se(203,320,240); + DeathAction(pActJobdailyWin); + pActJobdailyWin = NULL; + return 1; + }else if(id == 2){ + PageIndex --; + if(PageIndex<=0) PageIndex=0; + }else if(id == 3){ + PageIndex ++; + if(PageIndex==MaxPage) PageIndex--; + } + + if(focusId == 1) ShowBottomLineString(FONT_PAL_WHITE,"ر־Ӵ"); + + for(i = 0;i < sizeof(msg5)/sizeof(char*);i++){ + StockFontBuffer(x+80+i*150,y+30+26+196+45,FONT_PRIO_FRONT,FONT_PAL_YELLOW,msg5[i],0); + //StockFontBuffer(x+105,y+i*30+26,FONT_PRIO_FRONT, FONT_PAL_WHITE,msg2[((pc.etcFlag & iChannelSwitch[i]) ? 1:0)],0); + } + //char buf[10]; + //sprintf_s(buf,"PageIndex:%d", PageIndex); + //StockFontBuffer( 400 , 230 , FONT_PRIO_FRONT, 1 , buf , 0 ); + //sprintf_s(buf,"MaxPage:%d",MaxPage); + //StockFontBuffer( 400 , 250 , FONT_PRIO_FRONT, 1 , buf , 0 ); + + } + } + +#endif*/ + + if (ptActMenuWin != NULL) + { + id = -1; + focusId = -1; + if (ptActMenuWin->hp >= 1) + { + // ????kRe + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + focusId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + + for (i = 0; i < sizeof(msg) / sizeof(char*); i++) + { + x1 = x+18; + y1 = y+i*30+23; + x2 = x1 + 157; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + id = i + 1; + focusId = i + 1; + } + } + } + + // \????????????????????? + if (CheckMenuFlag()) + id = 100; + else if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL)) // ESC???????? + { + id = 100; + play_se(203, 320, 240); // ???????? + } + else if (etcSwitchProcNo == 1000) // ??????????? + id = 100; + // ????? + if (id == 0) + play_se( 203, 320, 240 ); // ???????? + else +#ifdef _CHANNEL_MODIFY + if (id == 4) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + etcSwitchProcNo = 100; + return 0; + } + else +#endif +#ifdef __ONLINEGM + if (id == 6) + { + if (BattlingFlag == FALSE) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + onlinegmProcNo = 0 ; + etcSwitchProcNo = 200; + return 0; + } + else + { + StockChatBufferLine("ս޷ϻرϵͳ...", FONT_PAL_RED); + return 0; + } + } +#endif + +/*#ifdef _JOBDAILY + if(id == 7){ + if(BattlingFlag == FALSE){ + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + //onlinegmProcNo = 0 ; + etcSwitchProcNo = 201; + return 0; + }else{ + StockChatBufferLine("ս޷־...",FONT_PAL_RED); + return 0; + } + } +#endif*/ + + if (1 <= id && id <= sizeof(msg) / sizeof(char*)) + { + id--; + // ???????????? + if (pc.etcFlag & mask[id]) + pc.etcFlag &= ~mask[id]; + else + // ???????? + { +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1 || sStreetVendorBuyBtn == 2) + { + if (mask[id] == PC_ETCFLAG_TRADE || mask[id] == PC_ETCFLAG_PARTY || mask[id] == PC_ETCFLAG_DUEL) + StockChatBufferLine("̯вɿסӼս", FONT_PAL_RED); + else + pc.etcFlag |= mask[id]; + } + else + pc.etcFlag |= mask[id]; +#else + pc.etcFlag |= mask[id]; +#endif + } + if (eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + lssproto_FS_send(sockfd, pc.etcFlag); + else + old_lssproto_FS_send(sockfd, pc.etcFlag); + fieldBtnPushTime = TimeGetTime(); + } + else // ?????????????????????? ???? + etcSwitchChangeFlag = 1; + } + // ????????k????????????????? + id = -1; + play_se(217, 320, 240); //????? + } + + if (id >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return 1; + } + + if (ptActMenuWin->hp >= 1) + { + btnId[0] = StockDispBuffer(x + 96, h * 48 - 24 , DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + if (focusId == 0) + ShowBottomLineString(FONT_PAL_WHITE, "رѡӴ"); + for (i = 0; i < sizeof(msg) / sizeof(char*); i++) + { + StockFontBuffer(x + 20, y + i * 30 + 26, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg[i], 0); + + if (i != 3 && i != 5) //޸ѡע + StockFontBuffer(x + 105, y + i * 30 + 26, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg2[((pc.etcFlag & mask[i]) ? 1:0)], 0); +#ifndef _CHANNEL_MODIFY + else + StockFontBuffer(x + 105, y + i * 30 + 26, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg3[((pc.etcFlag & mask[i]) ? 1:0)], 0); +#endif + if (i == focusId - 1) + ShowBottomLineString(FONT_PAL_WHITE, msg4[i]); + } + } + } + + return 0; +} + +// ?????Q?N?? +// ??k 0 ... ??? +// 1 ... "??"???????? +int disconnectServer( void ) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + static int btnId[1]; + int id = 0; + char *msg[] = + { + "ж", + "صͷ" + }; + int i; + int ret = 0; + int xx, yy; + + + if (ptActMenuWin == NULL) + { + // \??????????? + if (CheckMenuFlag()) + InitMenu2(); + closeEtcSwitch(); + closeCharActionAnimeChange(); + closeJoinChannelWN(); + + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + btnId[i] = -2; + + // ?????? + w = 5; + h = 3; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } +#ifdef _AIDENGLU_ + extern int Զ½Ƿ; +#endif + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + if ( + id >= 0 +#ifdef _AIDENGLU_ + || Զ½Ƿ +#endif + ) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + ret = 1; + } + + yy = (h * 48) / 4; + for (i = 0; i < sizeof(msg) / sizeof(char*); i++) + { + xx = (w * 64 - strlen(msg[i]) / 2 * 17) / 2; + StockFontBuffer(x+ xx, y + (i + 1) * yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg[i], 0); + } + + xx = (w * 64 - strlen("ȷ") / 2 * 17) / 2; + btnId[0] = StockFontBuffer(x + xx, y + 3 * yy, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȷ", 2); + } + } + + return ret; +} + +// ????????q? +void drawFieldInfoWin(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int xx, yy; + + if (fieldInfoTime == 0) + { + if (ptActMenuWin != NULL) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + return; + } + + if (MapWmdFlagBak) + return; + + if (ptActMenuWin == NULL) + { + // \??????????? + if (CheckMenuFlag()) + { + // ????????????????? + if (MenuToggleFlag & JOY_CTRL_M) + MapWmdFlagBak = TRUE; + InitMenu2(); + } + closeEtcSwitch(); + closeCharActionAnimeChange(); + closeJoinChannelWN(); + + // ?????? + w = 4; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - 24 - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 3, FALSE); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + play_se(202, 320, 240); // ???????? + } + + if (ptActMenuWin != NULL) + { + if (fieldInfoTime + 2000 <= TimeGetTime() || CheckMenuFlag() || windowTypeWN > -1 || actBtn == 1 || menuBtn == 1) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + fieldInfoTime = 0; + return; + } + if (ptActMenuWin->hp >= 1) + { + xx = (w * 64 - strlen(nowFloorName) / 2 * 17) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, nowFloorName, 0); + } + } +} + +// ??????????????????? +void actionShortCutKeyProc(void) +{ + unsigned int key[] = + { + JOY_CTRL_0, // 0 + JOY_CTRL_CIRCUMFLEX, // 1 + JOY_CTRL_9, // 2 + JOY_CTRL_7, // 3 + JOY_CTRL_8, // 4 + JOY_CTRL_1, // 5 + JOY_CTRL_2, // 6 + JOY_CTRL_4, // 7 + JOY_CTRL_5, // 8 + JOY_CTRL_6, // 9 + JOY_CTRL_MINUS, // 10 + JOY_CTRL_3, // 11 + JOY_CTRL_YEN // 12 + }; + int i; + BOOL pushFlag = FALSE; + + // ????h?????????? + if (moveRouteCnt != 0 || nowVx != 0 || nowVy != 0) + return; + + for (i = 0; i < sizeof(key) / sizeof(unsigned int); i++) + { + if (joy_trg[1] & key[i]) + { + pushFlag = TRUE; + break; + } + } + + if (!pushFlag) + return; + + if (eventWarpSendFlag == 0 && eventEnemySendFlag == 0 && sendEnFlag == 0) + { +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000001) + StockChatBufferLine("רĿ", FONT_PAL_RED); + else +#endif + if (fieldBtnPushTime + FIELD_BTN_PUSH_WAIT < TimeGetTime())// ?? + { + if (bNewServer) + lssproto_AC_send(sockfd, nowGx, nowGy, i); + else + old_lssproto_AC_send(sockfd, nowGx, nowGy, i); + setPcAction(i); + fieldBtnPushTime = TimeGetTime(); + } + } +} + +static ACTION *ptActChannelWin = NULL; +static ACTION *ptActChannel2Win = NULL; +static ACTION *ptActLeaderFuncWin = NULL; + +#ifndef _FM_MODIFY +char channelName[9][20] = +{ + " ", + "Ƶ ", + "Ƶ ", + "Ƶ ", + "Ƶ ", + " 峤㲥 ", + " 뿪Ƶ ", + " 峤 ", + " " +}; +#else +char channelName[5][20] = +{ + " ", + " 峤 ", + "岼", + " رչ㲥 ", + " " +}; +#endif + +void initJoinChannelWN(void) +{ + channelWNFlag = 1; + //joinChannelProc = 1000; +} + +void closeJoinChannelWN(void) +{ + channelWNFlag = 0; + //joinChannelProc = 0; + DeathAction(ptActChannelWin); + ptActChannelWin = NULL; + joinChannel2Proc = 0; + DeathAction(ptActChannel2Win); + ptActChannel2Win = NULL; + DeathAction(ptActLeaderFuncWin); + ptActLeaderFuncWin = NULL; +#ifdef _FRIENDCHANNEL + chatRoomBtn = 0; + SelRoomBtn = 0; + #ifdef _STREET_VENDOR + if (sStreetVendorBtn != 3) + { + DeathAction(pActStreetVendorWnd); + pActStreetVendorWnd = NULL; + } + #else + #ifdef _TABLEOFSKILL + DeathAction(pActSkillWnd); + pActSkillWnd = NULL; + #endif + #endif +#endif +} + +void joinChannelWN(void) +{ + //static ACTION *ptActMenuWin = NULL; + int x, y, w, h, i; +#ifndef _FM_MODIFY + static int btnId[9]; +#else + static int btnId[5]; +#endif + static int graId[1]; + char buf[1024], buf2[64]; + int selId = 0; + int selgraId; + + x = 20; + y = 30; + w = 2; +#ifndef _FM_MODIFY + h = 8; +#else + h = 5; +#endif + + + if (ptActChannelWin == NULL) + { + ptActChannelWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActChannelWin->x; + y = ptActChannelWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + btnId[i] = -2; + } + else + { + if (ptActChannelWin->hp >= 1) + { + // ESC???????? + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL)) + { + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + } + if (CheckMenuFlag()) + closeJoinChannelWN(); + + selId = focusFontId(btnId, sizeof(btnId) / sizeof(int)); + selgraId = focusGraId(graId, sizeof(graId) / sizeof(int)); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (selgraId == 0) + { + closeJoinChannelWN(); + play_se(203, 320, 240); + return; + } +#ifndef _FM_MODIFY + switch (selId) + { + case 0: + sprintf_s(buf, "S|D2", selId); + break; + case 1: + case 2: + case 3: + sprintf_s(buf, "C|L|%d", selId); + break; + case 5: + #ifdef _FMVER21 + if (pc.familyleader != FMMEMBER_LEADER) + return; + #else + if (pc.familyleader != 1) + return; + #endif + sprintf_s(buf, "C|J|5"); + closeJoinChannelWN(); + play_se(203, 320, 240); + break; + case 6: + sprintf_s(buf, "C|J|-1"); + closeJoinChannelWN(); + play_se(203, 320, 240); + break; + case 7: + DeathAction(ptActChannel2Win); + ptActChannel2Win = NULL; + joinChannel2Proc = 2000; + play_se(203, 320, 240); + return; + case 8: + sprintf_s(buf, "S|SELF"); + closeJoinChannelWN(); + play_se(203, 320, 240); + break; + } +#else + switch (selId) + { + case 0: + sprintf_s(buf, "S|D2", selId); + break; + case 1: + DeathAction(ptActChannel2Win); + ptActChannel2Win = NULL; + joinChannel2Proc = 2000; + play_se(203, 320, 240); + return; + case 2: + sprintf_s(buf, "D"); + closeJoinChannelWN(); + play_se(203, 320, 240); + break; + case 3: + sprintf_s(buf, "C|J|-1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + sprintf_s(buf, "S|SELF"); + closeJoinChannelWN(); + play_se(203, 320, 240); + break; + } +#endif + if (selId != -1) + { + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + return; + } + } + + strcpy(buf2, ""); + for (i= 0; i < (int)(16 - strlen(pc.familyName)) / 2; i++) + strcat_s(buf2, " "); + strcat_s(buf2, pc.familyName); + +#ifndef _FM_MODIFY + btnId[8] = StockFontBuffer(x + 7, y + 30, FONT_PRIO_FRONT, FONT_PAL_GREEN, buf2, 0); +#else + btnId[4] = StockFontBuffer(x + 7, y + 30, FONT_PRIO_FRONT, FONT_PAL_GREEN, buf2, 0); + btnId[2] = StockFontBuffer(x + 25, y + 65 + 36 * 2, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[2], 2); +#endif + btnId[0] = StockFontBuffer(x + 25, y + 65, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[0], 2); + +#ifndef _FM_MODIFY + for (i = 1; i < 4; i++) + { + if (pc.channel == i) + btnId[i] = StockFontBuffer(x + 25, y + 65 + 36 * i, FONT_PRIO_FRONT, FONT_PAL_YELLOW, channelName[i], 2); + else + btnId[i] = StockFontBuffer(x + 25, y + 65 + 36 * i, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[i], 2); + } + btnId[6] = StockFontBuffer(x + 25, y + 65 + 36 * 4, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[6], 2); +#endif +#ifdef _FMVER21 + // shan add + if (pc.familyleader == FMMEMBER_LEADER || pc.familyleader == FMMEMBER_ELDER) +#else + if (pc.familyleader == 1) +#endif +#ifndef _FM_MODIFY + btnId[7] = StockFontBuffer(x + 25, y + 65 + 36 * 5, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[7], 2); + else + btnId[7] = StockFontBuffer(x + 25, y + 65 + 36 * 5, FONT_PRIO_FRONT, FONT_PAL_GRAY, channelName[7], 0); + graId[0] = StockDispBuffer(x + 65, y + 13 + 320, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); +#else + { + btnId[1] = StockFontBuffer(x + 25, y + 65 + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[1], 2); + btnId[3] = StockFontBuffer(x + 25, y + 65 + 36 * 3, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[3], 2); + } + else + { + btnId[1] = StockFontBuffer(x + 25, y + 65 + 36, FONT_PRIO_FRONT, FONT_PAL_GRAY, channelName[1], 0); + btnId[3] = StockFontBuffer(x + 25, y + 65 + 36 * 3, FONT_PRIO_FRONT, FONT_PAL_GRAY, channelName[3], 0); + } + graId[0] = StockDispBuffer(x + 65, y + 13 + 200, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); +#endif + +#ifndef _FM_MODIFY + switch (selId) + { + case 0: + ShowBottomLineString(FONT_PAL_WHITE, "鿴ϸϡ"); + break; + case 1: + case 2: + case 3: + if (pc.channel == selId) + sprintf_s(buf, "ĿǰƵ"); + else + sprintf_s(buf, "鿴Ƶ"); + ShowBottomLineString(FONT_PAL_WHITE, buf); + break; + case 5: + ShowBottomLineString(FONT_PAL_WHITE, "峤ȫϵԱ㲥"); + break; + case 6: + ShowBottomLineString(FONT_PAL_WHITE, "˳ĿǰƵ"); + break; + case 7: + ShowBottomLineString(FONT_PAL_WHITE, "峤רùܡ"); + break; + default: + if (selgraId == 0) + ShowBottomLineString(FONT_PAL_WHITE, "뿪Ƶѡ"); + break; + } +#else + switch (selId) + { + case 0: + ShowBottomLineString(FONT_PAL_WHITE, "鿴ϸϡ"); + break; + case 1: + ShowBottomLineString(FONT_PAL_WHITE, "峤רùܡ"); + break; + case 2: + ShowBottomLineString(FONT_PAL_WHITE, "ʹü岼ܡ"); + break; + case 3: + ShowBottomLineString(FONT_PAL_WHITE, "ر峤㲥ܡ"); + break; + default: + if (selgraId == 0) + ShowBottomLineString(FONT_PAL_WHITE, "뿪Ƶѡ"); + break; + } +#endif + if (joinChannel2Proc == 1000) + joinChannel2WN(); + else if (joinChannel2Proc == 2000) + leaderFuncWN(); + } + } +} + +struct TchannelData{ + int index; + int num; + int join[FAMILY_MAXMEMBER]; + int joinNum; + char name[FAMILY_MAXMEMBER][20]; +}; +static TchannelData channelData; + +char pageStr[2][10] = +{ + "һҳ", + "һҳ", +}; +static int pageNum; + +void initJoinChannel2WN(char *data) +{ + int i; + char buf[256]; + + channelData.joinNum = 0; + getStringToken(data, '|', 3, sizeof(buf) - 1, buf); + channelData.index = atoi(buf); + getStringToken(data, '|', 4, sizeof(buf) - 1, buf); + channelData.num = atoi(buf); + + if (channelData.num > 0) + { + for (i = 0; i < channelData.num && i < FAMILY_MAXMEMBER; i++) + { + getStringToken(data, '|', 4 + (i * 2) + 1, sizeof(buf) - 1, buf); + channelData.join[i] = atoi(buf); + if (channelData.join[i] == 1) + channelData.joinNum++; + getStringToken(data, '|', 4 + (i * 2) + 2, sizeof(buf) - 1, buf); + makeStringFromEscaped(buf); + strcpy(channelData.name[i], buf); + } + } + pageNum = 0; + play_se(202, 320, 240); // ???????? + joinChannel2Proc = 1000; + +} + +void closeJoinChannel2WN(void) +{ + joinChannel2Proc = 0; + DeathAction(ptActChannel2Win); + ptActChannel2Win = NULL; +} + +void joinChannel2WN(void) +{ + //static ACTION *ptActMenuWin = NULL; + int x, y, w, h, i; + static int fontBtnId[4]; + char buf[1024]; + int selId; + + x = 160; + y = 30; + w = 7; + h = 8; + + if (ptActChannel2Win == NULL) + { + DeathAction(ptActLeaderFuncWin); + ptActLeaderFuncWin = NULL; + ptActChannel2Win = MakeWindowDisp(x, y, w, h, NULL, 1); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActChannel2Win->x; + y = ptActChannel2Win->y; +#endif + } + else if (ptActChannel2Win->hp >= 1) + { + selId = focusFontId(fontBtnId, sizeof(fontBtnId) / sizeof(int)); + + switch (selId) + { + case 0: + ShowBottomLineString(FONT_PAL_WHITE, "뱾Ƶ"); + break; + case 1: + ShowBottomLineString(FONT_PAL_WHITE, "رӴ"); + break; + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + switch (selId) + { + case 0: + sprintf_s(buf, "C|J|%d", channelData.index); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + break; + case 1: + if (pc.channel == channelData.index) + { + sprintf_s(buf, "C|J|-1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + closeJoinChannel2WN(); + play_se(203, 320, 240); // ???????? + break; + case 2: + if (pageNum > 0) + pageNum--; + break; + case 3: + if (pageNum < 2) + pageNum++; + break; + } + } + + fontBtnId[0] = StockFontBuffer(x + 240, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ", 2); + fontBtnId[1] = StockFontBuffer(x + 340, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ", 2); + + switch (pageNum) + { + case 0: + if (channelData.num > 30) + fontBtnId[3] = StockFontBuffer(x + 120, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, pageStr[1], 2); + break; + case 1: + if (channelData.num > 60) + fontBtnId[3] = StockFontBuffer(x + 120, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, pageStr[1], 2); + fontBtnId[2] = StockFontBuffer(x + 50, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, pageStr[0], 2); + break; + case 2: + fontBtnId[2] = StockFontBuffer(x + 50, y + 340, FONT_PRIO_FRONT, FONT_PAL_YELLOW, pageStr[0], 2); + break; + } + StockFontBuffer(x + 25, y + 25, FONT_PRIO_FRONT, FONT_PAL_WHITE, channelName[channelData.index], 0); + + StockFontBuffer(x + 25, y + 50, FONT_PRIO_FRONT, FONT_PAL_WHITE, "[ Ƶ Ա ]", 0); + + sprintf_s(buf, "Ŀǰ %d λԱڱ", channelData.num); + StockFontBuffer(x + 200, y + 25, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, " %d ڱƵ", channelData.joinNum); + StockFontBuffer(x + 280, y + 50, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + + for (i = 0 ; i < channelData.num; i++) + { + int color; + + if (channelData.join[i] == 1) + color = FONT_PAL_WHITE; + else + color = FONT_PAL_GRAY; + + if (pageNum == 0 && i < 30) + { + if (i < 10) + StockFontBuffer(x + 25, y + 80 + i * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if(i < 20) + StockFontBuffer(x + 25 + 140, y + 80 + (i - 10) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if(i < 30) + StockFontBuffer(x + 25 + 280, y + 80 + (i - 20) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + } + else if (pageNum == 1 && i >= 30 && i < 60) + { + if (i < 40) + StockFontBuffer(x + 25, y + 80 + (i - 30) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if (i < 50) + StockFontBuffer(x + 25 + 140, y + 80 + (i - 40) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if (i < 60) + StockFontBuffer(x + 25 + 280, y + 80 + (i - 50) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + } + else if (pageNum == 2 && i >= 60) + { + if (i < 70) + StockFontBuffer(x + 25, y + 80 + (i - 60) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if (i < 80) + StockFontBuffer(x + 25 + 140, y + 80 + (i - 70) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + else if (i < 90) + StockFontBuffer(x + 25 + 280, y + 80 + (i - 80) * 25, FONT_PRIO_FRONT, color, channelData.name[i], 0); + } + } + } +} + +void leaderFuncWN(void) +{ + //static ACTION *ptActMenuWin = NULL; + int x, y, w, h; + static int btnId[9]; + static int graId[1]; + char buf[1024]; + int selId; + int selgraId; + + x = 160; + y = 30; + w = 2; + h = 5; + + if (ptActLeaderFuncWin == NULL) + { + ptActLeaderFuncWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600ģʽ + x = ptActLeaderFuncWin->x; + y = ptActLeaderFuncWin->y; +#endif + } + else if (ptActLeaderFuncWin->hp >= 1) + { + // ESC???????? + if (((joy_trg[0] & JOY_ESC) && GetImeString() == NULL)) + { + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + } + if (CheckMenuFlag()) + closeJoinChannelWN(); + + selId = focusFontId(btnId, sizeof(btnId) / sizeof(int)); + selgraId = focusGraId(graId, sizeof(graId) / sizeof(int)); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (selId == 1) + { +#ifdef _FMVER21 + if (pc.familyleader != FMMEMBER_LEADER) +#else + if (pc.familyleader != 1) +#endif + return; + sprintf_s(buf, "C|J|5"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } + if (selId == 2) + { + sprintf_s(buf, "L|F|1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } + + if (selId == 3) + { + sprintf_s(buf, "L|L|1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } + if (selId == 4) + { + sprintf_s(buf, "L|L|2"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } + + if (selId == 5) + { + sprintf_s(buf, "L|CHANGE|L"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } +#ifdef _ADD_FAMILY_TAX // WON ADD ׯ԰˰ + if (selId == 6) + { + sprintf_s(buf, "L|FMTAX|W"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeJoinChannelWN(); + play_se(203, 320, 240); // ???????? + return; + } +#endif + } + +#ifdef _FMVER21 + if (pc.familyleader == FMMEMBER_LEADER) +#else + if (pc.familyleader == 1) +#endif + { + if (pc.channel == 5) + btnId[1] = StockFontBuffer(x + 22, y + 65 + 36 * 0, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 峤㲥 ", 2); + else + btnId[1] = StockFontBuffer(x + 22, y + 65 + 36 * 0, FONT_PRIO_FRONT, FONT_PAL_WHITE, " 峤㲥 ", 2); + + btnId[2] = StockFontBuffer(x + 22, y + 65 + 36 * 1, FONT_PRIO_FRONT, FONT_PAL_WHITE, "Ա", 2); + + btnId[3] = StockFontBuffer(x + 22, y + 65 + 36 * 2, FONT_PRIO_FRONT, FONT_PAL_WHITE, " 뺯 ", 2); + //btnId[4] = StockFontBuffer(x + 22, y + 65 + 36 * 3, FONT_PRIO_FRONT, FONT_PAL_WHITE, " ѧϰͬ ", 2); + //btnId[5] = StockFontBuffer(x + 22, y + 65 + 36 * 4, FONT_PRIO_FRONT, FONT_PAL_WHITE, " 峤λ ", 2); + btnId[5] = StockFontBuffer(x + 22, y + 65 + 36 * 3, FONT_PRIO_FRONT, FONT_PAL_WHITE, " 峤λ ", 2); + + +#ifdef _ADD_FAMILY_TAX // WON ADD ׯ԰˰ + btnId[6] = StockFontBuffer(x + 22, y + 65 + 36 * 5, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ׯ԰˰", 2); +#endif + } +// shan begin +#ifdef _FMVER21 + if (pc.familyleader == FMMEMBER_ELDER) + { + btnId[1] = StockFontBuffer(x + 22, y + 65 + 36 * 0, FONT_PRIO_FRONT, FONT_PAL_GRAY, " 峤㲥 ", 0); + btnId[2] = StockFontBuffer(x + 22, y + 65 + 36 * 1, FONT_PRIO_FRONT, FONT_PAL_WHITE, "Ա", 2); + + btnId[3] = StockFontBuffer(x + 22, y + 65 + 36 * 2, FONT_PRIO_FRONT, FONT_PAL_WHITE, " 뺯 ", 2); + btnId[4] = StockFontBuffer(x + 22, y + 65 + 36 * 3, FONT_PRIO_FRONT, FONT_PAL_WHITE, " ѧϰͬ ", 2); + btnId[5] = StockFontBuffer(x + 22, y + 65 + 36 * 4, FONT_PRIO_FRONT, FONT_PAL_GRAY, " 峤λ ", 0); + +#ifdef _ADD_FAMILY_TAX // WON ADD ׯ԰˰ + btnId[6] = StockFontBuffer(x + 22, y + 65 + 36 * 5, FONT_PRIO_FRONT, FONT_PAL_GRAY, " ׯ԰˰ ", 0); +#endif + } +#endif +// shan end + if (selId == 1) + ShowBottomLineString(FONT_PAL_WHITE, "峤ȫϵԱ㲥"); + else if (selId == 2) + ShowBottomLineString(FONT_PAL_WHITE, "Աб"); + else if (selId == 3) + ShowBottomLineString(FONT_PAL_WHITE, "ι뺯"); + else if (selId == 4) + ShowBottomLineString(FONT_PAL_WHITE, "ѧϰͬ顣"); +#ifdef _ADD_FAMILY_TAX // WON ADD ׯ԰˰ + else if (selId == 6) + ShowBottomLineString(FONT_PAL_WHITE, "ׯ԰Ʒ˰ա"); +#endif + } + +} + +#ifdef _SURFACE_ANIM //ROG ADD ̬ʾ +int ReadAniFile(int floor) +{ + HANDLE hFile; + DWORD readbyte; + char fileName[32]; + ani_num = 0; + int col = 0, row = 0; + breadAniFlag = TRUE; //ȡ + sprintf_s(fileName, "map\\%d.ani", floor); + for (int i = 0; i < MAX_ANIM; i++) + { + ProduceXY[i][5] = -2 ; + ProduceXY[i][6] = -1 ; + } + hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, NULL, NULL); + if (hFile == INVALID_HANDLE_VALUE) + return -1; + while (ReadFile(hFile, &ProduceXY[row], sizeof(int) * 5, &readbyte, NULL) && readbyte) + { + ProduceXY[row][5] = 0 ; + row++; + } + ani_num = row; //õͼܶ + CloseHandle(hFile); + + return 1; +} +void SpecAnim(int floor) +{ + int j = 0; + + if (breadAniFlag && ProduceXY[0][5] == -2) + return; + else if (breadAniFlag == FALSE && ReadAniFile(floor) == -1) + return; + + for (int i = 0; i < ani_num; i ++) + { + switch (SaTimeZoneNo) + { + case LS_NIGHT: + if (ProduceXY[i][3] == 1 && ProduceXY[i][5] == 1) + { + if (SPACT[ProduceXY[i][6]] != NULL) + { + DeathAction(SPACT[ProduceXY[i][6]]); + SPACT[ProduceXY[i][6]] = NULL ; + ProduceXY[i][6] = -1 ; + } + ProduceXY[i][5] = -1; + } + else if (ProduceXY[i][3] == 2 && ProduceXY[i][5] == -1) + ProduceXY[i][5] = 0; + break; + case LS_MORNING: + case LS_NOON: + case LS_EVENING: + if (ProduceXY[i][3] == 2 && ProduceXY[i][5] == 1) + { + if (SPACT[ProduceXY[i][6]] != NULL) + { + DeathAction(SPACT[ProduceXY[i][6]]); + SPACT[ProduceXY[i][6]] = NULL ; + ProduceXY[i][6] = -1 ; + } + ProduceXY[i][5] = -1; + } + else if(ProduceXY[i][3] == 1 && ProduceXY[i][5] == -1) + ProduceXY[i][5] = 0; + break; + } + + if (ProduceXY[i][5] == 0) + { + for (j = 0; j < MAX_ANIM; j ++) + { + if (SPACT[j] == NULL) + { + float mx, my; + SPACT[j] = GetAction(DISP_PRIO_BOX3,sizeof(CHAREXTRA)); + if (SPACT[j] == NULL) + break; + SPACT[j]->anim_chr_no = ProduceXY[i][0]; + SPACT[j]->anim_no = ANIM_STAND; + SPACT[j]->anim_ang = 1; + SPACT[j]->dispPrio = ProduceXY[i][4]; + SPACT[j]->atr |= ACT_ATR_HIT; + SPACT[j]->nextGx = ProduceXY[i][1]; + SPACT[j]->nextGy = ProduceXY[i][2]; + SPACT[j]->bufCount = 0; + SPACT[j]->gx = ProduceXY[i][1]; + SPACT[j]->gy = ProduceXY[i][2]; + SPACT[j]->mx = (float)ProduceXY[i][1] * GRID_SIZE; + SPACT[j]->my = (float)ProduceXY[i][2] * GRID_SIZE; + SPACT[j]->vx = 0; + SPACT[j]->vy = 0; + camMapToGamen(SPACT[j]->mx, SPACT[j]->my, &mx, &my); + SPACT[j]->x = (int)(mx+.5); + SPACT[j]->y = (int)(my+.5); + pattern(SPACT[j],ANM_NOMAL_SPD,ANM_LOOP); + ProduceXY[i][5] = 1; + ProduceXY[i][6] = j; + break; + } + } + } + } +} + +void ReleaseSpecAnim () +{ + breadAniFlag = FALSE; + for (int i = 0; i < ani_num; i++) + { + if (ProduceXY[i][5] == 1) + { + if (SPACT[ProduceXY[i][6]] != NULL) + { + DeathAction(SPACT[ProduceXY[i][6]]); + SPACT[ProduceXY[i][6]] = NULL ; + ProduceXY[i][6] = -1 ; + ProduceXY[i][5] = 0 ; + } + } + } +} + +#else + +#ifdef _SPECIALSPACEANIM // Syu ADD ⳡ +void SpecAnim (int floor) +{ + int j = 0; + for (int i = 0; i < TOTAL_ANIM; i++) + { + if (floor == ProduceXY[i][2] && ProduceXY[i][4] == 0) + { + for (j = 0; j < MAX_ANIM; j++) + { + if (SPACT[j] == NULL) + { +#ifdef _SPECIALSPACEANIM_FIX + SPACT[j] = createWaterAnimation(ProduceXY[i][3] , ProduceXY[i][0] , ProduceXY[i][1] , ProduceXY[i][6]); +#else + SPACT[j] = createWaterAnimation(ProduceXY[i][3] , ProduceXY[i][0] , ProduceXY[i][1] , 30); +#endif + ProduceXY[i][4] = 1; + ProduceXY[i][5] = j; + break; + } + } + } + else if (floor != ProduceXY[i][2] && ProduceXY[i][4] == 1) + { + if (SPACT[ProduceXY[i][5]] != NULL) + { + DeathAction(SPACT[ProduceXY[i][5]]); + SPACT[ProduceXY[i][5]] = NULL ; + ProduceXY[i][5] = -1 ; + ProduceXY[i][4] = 0 ; + } + } + } +} + +void ReleaseSpecAnim() +{ + for (int i = 0; i < TOTAL_ANIM; i++) + { + if (ProduceXY[i][4] == 1) + { + if (SPACT[ProduceXY[i][5]] != NULL) + { + DeathAction(SPACT[ProduceXY[i][5]]); + SPACT[ProduceXY[i][5]] = NULL ; + ProduceXY[i][5] = -1 ; + ProduceXY[i][4] = 0 ; + } + } + } +} +#endif +#endif + +#ifdef _CLOUD_EFFECT // (ɿ) ROG ADDƲЧ +void CloudDraw() +{ + static DWORD SlowDraw; + static int dif, dif1; + DWORD now; + + if ((now = TimeGetTime()) > SlowDraw) + { + SlowDraw = now + 10; + dif ++; + if (dif > 1000) + dif = 0; + dif1 += 2; + if (dif1 > 1000) + dif1 =0; + } + StockDispBuffer(0 + dif - 200, 0 + dif, 20, 40500, 1); + StockDispBuffer(0 + dif1 - 360, 20 + dif1, 20, 40501, 1); + StockDispBuffer(0 + dif - 50, 10 + dif - 480, 20, 40502, 1); + StockDispBuffer(0 + dif1 - 100, 50 + dif - 400, 20, 40503, 1); +} +#endif + +#ifdef _TEACHER_SYSTEM +void TeacherSystemWndfunc(int flag, char *data) +{ + int i; + static int winX, winY, winW, winH, iOnline = 0, iGetNum = 0; + static int iFontId[7], iIndex[5]; + static ACTION *pActTeacherSystemWnd = NULL; + static char szBuf[6][32]; + static BOOL bOpen = FALSE; + char szMsg[128]; + + if (pActTeacherSystemWnd == NULL) + { + memset(iFontId, -1, sizeof(iFontId)); + memset(iIndex, -1, sizeof(iIndex)); + memset(szBuf, 0, sizeof(szBuf)); + switch (flag) + { + // ֻһ + case 0: + winW = 5; + winH = 2; + // get name + getStringToken(data, '|', 2, sizeof(szBuf[0]) - 1, szBuf[0]); // 浼ʦ + getStringToken(data, '|', 3, sizeof(szBuf[6]) - 1, szBuf[6]); // ȡʦ index + iIndex[0] = atoi(szBuf[6]); + break; + // һͬһ + case 1: + winW = 5; + winH = 5; + getStringToken(data, '|', 2, sizeof(szBuf[6]) - 1, szBuf[6]); + iGetNum = atoi(szBuf[6]); + // get name + for (i = 0; i < iGetNum; i++) + { + getStringToken(data, '|', 3 + i * 2, sizeof(szBuf[i]) - 1, szBuf[i]); // 浼ʦ + getStringToken(data, '|', 4 + i * 2, sizeof(szBuf[6]) - 1, szBuf[6]); // ȡʦ index + iIndex[i] = atoi(szBuf[6]); + } + break; + // ʾʦ + case 2: + winW = 5; + winH = 3; + getStringToken(data, '|', 2, sizeof(szBuf[0]) - 1, szBuf[0]); // 浼ʦ + getStringToken(data, '|', 3, sizeof(szBuf[6]) - 1, szBuf[6]); // ȡڲ״̬ + iOnline = atoi(szBuf[6]); + getStringToken(data, '|', 4, sizeof(szBuf[1]) - 1, szBuf[1]); // ϵ ip + break; + case 3: + winW = 5; + winH = 2; + break; +#ifdef _TEACHER_SYSTEM_2 + case 4: + winW = 5; + winH = 3; + getStringToken(data, '|', 2, sizeof(szBuf[0]) - 1, szBuf[0]); // ѧ + getStringToken(data, '|', 3, sizeof(szBuf[6]) - 1, szBuf[6]); // ȡڲ״̬ + iOnline = atoi(szBuf[6]); + getStringToken(data, '|', 4, sizeof(szBuf[1]) - 1, szBuf[1]); // ϵ ip + break; + case 5: + winW = 5; + winH = 2; + break; +#endif + } + iOldGX = nowGx; + iOldGY = nowGy; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + pActTeacherSystemWnd = MakeWindowDisp(winX, winY, winW, winH, NULL, 1); + } + else + { + // close window + if (CheckMenuFlag() || (joy_trg[0] & JOY_ESC) || actBtn == 1 || menuBtn == 1 || + disconnectServerFlag == TRUE || (iOldGX != nowGx || iOldGY != nowGy)) + { + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + bOpen = FALSE; + return; + } + if (pActTeacherSystemWnd->hp >= 1) + { + if (!bOpen) + bOpen = TRUE; + // ֻһѯǷҪԷĵʦ + if (flag == 0) + { + sprintf_s(szMsg, "Ƿ϶ %s", szBuf[0]); + StockFontBuffer(winX + 20, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + StockFontBuffer(winX + 20, winY + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, "Ϊĵʦ", 0); + iFontId[0] = StockFontBuffer(winX + 64, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȷ ", 2); + iFontId[1] = StockFontBuffer(winX + (winW + 1) * 32, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡ ", 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217, 320, 240); + // ȷ + if (i == 0) + { + sprintf_s(szMsg, "O|%d", iIndex[0]); + lssproto_TEACHER_SYSTEM_send(sockfd, szMsg); + } + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + bOpen = FALSE; + return; + } + } + } + } + // һͬһѯǷҪԷĵʦ + else if (flag == 1) + { + sprintf_s(szMsg, "ѡ˭Ϊĵʦأ"); + StockFontBuffer(winX + 20, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + iFontId[0] = StockFontBuffer(winX + winW / 2 * 64, winY + (winH - 1)* 48, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡ ", 2); + for (i = 0; i < iGetNum; i++) + iFontId[i+1] = StockFontBuffer(winX + 20, winY + 46 + i * 24, FONT_PRIO_FRONT, FONT_PAL_WHITE, szBuf[i], 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 7; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217,320,240); + // ѡ˵ʦ + if (i != 0) + { + sprintf_s(szMsg, "O|%d", iIndex[i-1]); + lssproto_TEACHER_SYSTEM_send(sockfd, szMsg); + } + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + bOpen = FALSE; + return; + } + } + } + } + // ʾʦ + else if (flag == 2) + { + sprintf_s(szMsg, "ʦ״̬"); + StockFontBuffer(winX + 130, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "ʦ%s", szBuf[0]); + StockFontBuffer(winX + 20, winY + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + StockFontBuffer(winX + 20, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "״̬", 0); + StockFontBuffer(winX + 66, winY + 52, FONT_PRIO_FRONT, + iOnline == 1 ? FONT_PAL_YELLOW : FONT_PAL_RED, iOnline == 1 ? "Online" : "Offline", 0); + StockFontBuffer(winX + 148, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ϵ", 0); + if (iOnline == 1) + { + for (i = 0; i < MAX_GMSV; i++) + { + if (gmsv[i].used == '1') + { + if (strcmp(szBuf[1], gmsv[i].ipaddr) == 0) + { + StockFontBuffer(winX + 190, winY + 52, FONT_PRIO_FRONT, FONT_PAL_GREEN, gmsv[i].name, 0); + break; + } + } + } + } + else + StockFontBuffer(winX + 190, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + iFontId[0] = StockFontBuffer(winX + 64, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ", 2); + iFontId[1] = StockFontBuffer(winX + (winW + 1) * 32, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡʦʸ", 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217,320,240); + sTeacherSystemBtn = 0; + // ȡʦʸ + if (i != 0) + sTeacherSystemBtn = 5; + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + bOpen = FALSE; + return; + } + } + } + } + // ȷǷҪȡʦ + else if (flag == 3) + { + StockFontBuffer(winX + 20, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ȡʦֵ", 0); + StockFontBuffer(winX + 20, winY + 40, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ȷҪȡʦ", 0); + iFontId[0] = StockFontBuffer(winX + 64, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȷ ", 2); + iFontId[1] = StockFontBuffer(winX + (winW + 1) * 32, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡ ", 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217,320,240); + // ȡʦʸ + if (i == 0) + lssproto_TEACHER_SYSTEM_send(sockfd, "C|"); + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + bOpen = FALSE; + return; + } + } + } + } +#ifdef _TEACHER_SYSTEM_2 + // ʾѧ + else if (flag == 4) + { + sprintf_s(szMsg, "ѧ״̬"); + StockFontBuffer(winX + 130, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + sprintf_s(szMsg, "ѧ%s", szBuf[0]); + StockFontBuffer(winX + 20, winY + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, szMsg, 0); + StockFontBuffer(winX + 20, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "״̬", 0); + StockFontBuffer(winX + 66, winY + 52, FONT_PRIO_FRONT, + iOnline == 1 ? FONT_PAL_YELLOW : FONT_PAL_RED, iOnline == 1 ? "Online" : "Offline", 0); + StockFontBuffer(winX + 148, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ϵ", 0); + if (iOnline == 1) + { + for (i = 0; i < MAX_GMSV; i++) + { + if (gmsv[i].used == '1') + { + if (strcmp(szBuf[1], gmsv[i].ipaddr) == 0) + { + StockFontBuffer(winX + 190, winY + 52, FONT_PRIO_FRONT, FONT_PAL_GREEN, gmsv[i].name, 0); + break; + } + } + } + } + else + StockFontBuffer(winX + 190, winY + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + iFontId[0] = StockFontBuffer(winX + 64, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ", 2); + iFontId[1] = StockFontBuffer(winX + (winW + 1) * 32, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡѧʸ", 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217,320,240); + sTeacherSystemBtn = 0; + // ȡѧʸ + if (i != 0) + sTeacherSystemBtn = 7; + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + bOpen = FALSE; + return; + } + } + } + } + // ȷǷҪȡѧ + else if (flag == 5) + { + StockFontBuffer(winX + 20, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "ȷҪȡѧ", 0); + iFontId[0] = StockFontBuffer(winX + 64, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȷ ", 2); + iFontId[1] = StockFontBuffer(winX + (winW + 1) * 32, winY + winH * 30, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ȡ ", 2); + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) + { + if (HitFontNo == iFontId[i]) + { + play_se(217,320,240); + // ȡѧʸ + if (i == 0) + lssproto_TEACHER_SYSTEM_send(sockfd, "D|"); + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + bOpen = FALSE; + return; + } + } + } + } +#endif + } + else + { + if (bOpen) + { + bOpen = FALSE; + DeathAction(pActTeacherSystemWnd); + pActTeacherSystemWnd = NULL; + sTeacherSystemBtn = 0; + } + } + } +} +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/font.cpp b/石器时代8.5客户端最新源代码/石器源码/system/font.cpp new file mode 100644 index 0000000..b0455d7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/font.cpp @@ -0,0 +1,456 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +#define ASCII(a) a-'A'+10 +#define ASCII_DEC(a) a-'0'+ 35 + +#define FONT_BUFFER_SIZE 1024 // ??????????? + +// ????????? +FONT_BUFFER FontBuffer[ FONT_BUFFER_SIZE ]; + +int FontCnt = 0; + +int FontZenkauWidth; + +int FontHankakuWidth; +int MessageBoxNew(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); +#ifdef _SUNDAY_STR_SEARCH +char* sunday( char* str, char* subStr) +{ + const int maxSize=256; + int next[maxSize]; + int strLen = strlen(str); + int subLen = strlen(subStr); + int i,j,pos; + for(i=0;i= FONT_BUFFER_SIZE ) return -2; + FontBuffer[ FontCnt ].x = x; + FontBuffer[ FontCnt ].y = y; + FontBuffer[ FontCnt ].fontPrio = fontPrio; + FontBuffer[ FontCnt ].color = color; + FontBuffer[ FontCnt ].hitFlag = hitFlag; + extern int ; + extern int 忪; + if(忪){ + char [1024]={0}; + LCMapString (0x804,0x4000000,str, strlen(str),,1024); + if(==950){ + extern char* GB2312ToBIG5(const char* szBIG5String); + strcpy( FontBuffer[ FontCnt ].str, GB2312ToBIG5((const char *)) ); + }else + strcpy( FontBuffer[ FontCnt ].str, ); + }else{ + if(==950){ + extern char* GB2312ToBIG5(const char* szBIG5String); + strcpy( FontBuffer[ FontCnt ].str, GB2312ToBIG5((const char *)str) ); + }else + strcpy( FontBuffer[ FontCnt ].str, str ); + } + FontBuffer[ FontCnt ].size = size; + return FontCnt++; +} +int StockFontBuffer( int x, int y, char fontPrio, int color, char *str, BOOL hitFlag ) +{ + return StockFontBufferExt( x, y, fontPrio, color, str, hitFlag, 0 ); +} +#else + +int StockFontBuffer( int x, int y, char fontPrio, int color, char *str, BOOL hitFlag ) +{ + if( FontCnt >= FONT_BUFFER_SIZE ) return -2; + FontBuffer[ FontCnt ].x = x; + FontBuffer[ FontCnt ].y = y; + FontBuffer[ FontCnt ].fontPrio = fontPrio; + FontBuffer[ FontCnt ].color = color; + FontBuffer[ FontCnt ].hitFlag = hitFlag; + extern int ; + extern int 忪; + if(忪){ + char [1024]={0}; + LCMapString (0x804,0x4000000,str, strlen(str),,1024); + strcpy( FontBuffer[ FontCnt ].str, ); + }else{ + strcpy( FontBuffer[ FontCnt ].str, str ); + } + return FontCnt++; +} +#endif +HDC FontSizeHdc=NULL; +HDC hScrDC=NULL; +void CreatFontHdc() +{ + hScrDC = CreateDC("FontHdc", NULL, NULL, NULL); + FontSizeHdc = CreateCompatibleDC(hScrDC); + if(FontSizeHdc){ +#ifdef _NEWFONT_ + extern int ; + char strfame[128]; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + }else{ + sprintf(strfame,"Microsoft JhengHei"); + } + HFONT font=CreateFont(FONT_SIZE1,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame); +#else + extern int ; + char strfame[128]; + HFONT font; + if(==950){ + sprintf(strfame,"Microsoft JhengHei"); + font=CreateFont(FONT_SIZE2,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,1, + 0,0,0,17,(LPCTSTR)strfame); + }else{ + font=CreateFont(FONT_SIZE1,0,0,0,400,FALSE,FALSE,FALSE,134, + OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_ROMAN,(LPCTSTR)""); + } + + +#endif + SelectObject(FontSizeHdc, font); + }else{ + MessageBoxNew(NULL,"HDC","ӣ",NULL); + exit(0); + } +} +int getTextLength(char * str) +{ + SIZE fontsize; + GetTextExtentPoint32(FontSizeHdc,(LPCSTR)str,strlen(str),(LPSIZE)&fontsize); + return fontsize.cx; +} + + +#ifdef _MO_CHAT_EXPRESSION +void delFontBuffer(CHAT_BUFFER *chatbuffer) +{ + + CHAT_BUFFER *pHAIH = chatbuffer->NextChatBuffer; + while(pHAIH) //лڽ + { + CHAT_BUFFER* pTemp; + pTemp = pHAIH; + pHAIH = pHAIH->NextChatBuffer; + free(pTemp); + } + chatbuffer->NextChatBuffer=NULL; +} + + + +void NewStockFontBuffer(CHAT_BUFFER *chatbuffer,int x,unsigned char color,char *str,int size) +{ + if(!str[0]){ + return; + } + memset(chatbuffer,0,sizeof(CHAT_BUFFER)); + chatbuffer->fontsize = size; + char outText[512]; + char *temp = sunday(str, "#"); + if (temp){ + if(temp!=str){ + int strl = temp-str; + memcpy(outText,str,strl); + outText[strl]=0x0; + SIZE fontsize; + GetTextExtentPoint32(FontSizeHdc,(LPCSTR)outText,strl,(LPSIZE)&fontsize); + chatbuffer->color = color; + chatbuffer->x = x; + strcpy(chatbuffer->buffer,outText); + chatbuffer->NextChatBuffer = (CHAT_BUFFER *)calloc(1,sizeof(CHAT_BUFFER)); + NewStockFontBuffer(chatbuffer->NextChatBuffer,x+fontsize.cx,color,temp,size); + }else{ + int cnt_int = 0; + int i=1; + for(i;i<4;i++){ + if(temp[i]>='0'&& temp[i]<='9'){ + cnt_int*=10; + cnt_int+=temp[i]-'0'; + }else{ + break; + } + } + if(cnt_int>0&&cnt_int<=EXPRESSION_NOID_NUM+1){ + chatbuffer->x = x; + chatbuffer->BmpNo = EXPRESSION_NOID_START+cnt_int-1; + temp+=i; + x+=26; + }else{ + memcpy(outText,temp,i); + outText[i]=0x0; + SIZE fontsize; + GetTextExtentPoint32(FontSizeHdc,(LPCSTR)outText,i,(LPSIZE)&fontsize); + chatbuffer->color = color; + chatbuffer->x = x; + strcpy(chatbuffer->buffer,outText); + x+=fontsize.cx; + temp+=i; + } + chatbuffer->NextChatBuffer = (CHAT_BUFFER *)calloc(1,sizeof(CHAT_BUFFER)); + NewStockFontBuffer(chatbuffer->NextChatBuffer,x,color,temp,size); + } + }else{ + chatbuffer->color = color; + chatbuffer->x = x; + strcpy(chatbuffer->buffer,str); + } +} +#endif + +void StockFontBuffer2( STR_BUFFER *strBuffer ) +{ + int lineDist = 0; //о + int splitPoint = 0; + int bakSplitPoint,cursor; + BOOL SetCursor=FALSE; + char splitStr[ 256 ]; + if( FontCnt >= FONT_BUFFER_SIZE ){ + strBuffer->hitFontNo = -2; + return; + } + //Ҫʱ + if( strBuffer->lineLen != 0 ){ + cursor=strBuffer->cursor; + while( strlen( strBuffer->buffer + splitPoint ) >= strBuffer->lineLen ){ + bakSplitPoint=splitPoint; + //copyһеִ + strncpy_s( splitStr, strBuffer->buffer + splitPoint, strBuffer->lineLen ); + *( splitStr + strBuffer->lineLen ) = NULL; + if( GetStrLastByte( splitStr ) == 3 ){ + //ָDBCSʱ˻һbyte + splitPoint = strBuffer->lineLen - 1 + splitPoint; + *( splitStr + strBuffer->lineLen - 1 ) = NULL; + }else + splitPoint = strBuffer->lineLen + splitPoint; + StockFontBuffer( strBuffer->x, strBuffer->y + lineDist, strBuffer->fontPrio, 0, splitStr, 0 ); + if(cursor>=bakSplitPoint && cursorimeX = strBuffer->x + (cursor-bakSplitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + SetCursor=TRUE; + } + lineDist += strBuffer->lineDist; + } + if(!SetCursor){ + strBuffer->imeX = strBuffer->x + (strBuffer->cursor-splitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + } + StockFontBuffer( strBuffer->x, strBuffer->y + lineDist, strBuffer->fontPrio, 0, strBuffer->buffer + splitPoint, 0 ); + }else{ + FontBuffer[ FontCnt ].x = strBuffer->x; + FontBuffer[ FontCnt ].y = strBuffer->y; + FontBuffer[ FontCnt ].fontPrio = strBuffer->fontPrio; + FontBuffer[ FontCnt ].color = strBuffer->color; + FontBuffer[ FontCnt ].hitFlag = 0; +#ifdef _FONT_SIZE + FontBuffer[ FontCnt ].size = 0; +#endif +//Hook_typeǺŲ +#ifdef _SAHOOK //Syu ADD Hookʽ + if( strBuffer->filterFlag == HOOK_TYPE){ + extern int HOOK_PASSWD_NUM; + for(int i = 0 ; i < HOOK_PASSWD_NUM ; i++) + FontBuffer[ FontCnt ].str[ i ] = '*'; + FontBuffer[ FontCnt].str[i]=NULL; + strBuffer->cursor = HOOK_PASSWD_NUM; + } + else if( strBuffer->filterFlag == BLIND_TYPE ){ +#else + if( strBuffer->filterFlag == BLIND_TYPE ){ +#endif + int i; + for(i = 0 ; i < strBuffer->cnt ; i++ ) + FontBuffer[ FontCnt ].str[ i ] = '*'; + FontBuffer[ FontCnt ].str[ i ] = NULL; + }else{ + extern int ; + if(==950){ + extern char* GB2312ToBIG5(const char* szBIG5String); + strcpy( FontBuffer[ FontCnt ].str, GB2312ToBIG5((const char *)strBuffer->buffer)); + }else + strcpy( FontBuffer[ FontCnt ].str, strBuffer->buffer); + } +#ifdef _NEWFONT_ + char strtemp[512]; + char *ptempstr; + if( strBuffer->filterFlag == BLIND_TYPE ){ + ptempstr = FontBuffer[ FontCnt ].str; + }else{ + ptempstr = strBuffer->buffer; + } + if(strBuffer->cursor==0){ + strBuffer->imeX = strBuffer->x; + }else{ + memcpy(strtemp,ptempstr,strBuffer->cursor); + strtemp[strBuffer->cursor]=0; + strBuffer->imeX = strBuffer->x + GetStrWidth(strtemp); + + } +#else + strBuffer->imeX = strBuffer->x + strBuffer->cursor*(FONT_SIZE>>1); +#endif + strBuffer->imeY = strBuffer->y; + strBuffer->hitFontNo = FontCnt++; + } +} +//ONLINEGM USE +int StockFontBuffer3( STR_BUFFER *strBuffer ) +{ + int lineDist = 0; //о + int splitPoint = 0; + int bakSplitPoint,cursor; + BOOL SetCursor=FALSE; + char splitStr[ 256 ]; + + cursor=strBuffer->cursor; + //Ҫʱ + while( strlen( strBuffer->buffer + splitPoint ) >= (unsigned)strBuffer->lineLen-1 ){ + bakSplitPoint=splitPoint; + strcpy( splitStr , strBuffer->buffer + splitPoint ); //һ + *( splitStr + strBuffer->lineLen ) = NULL; //ָ + splitPoint = strBuffer->lineLen + splitPoint; + StockFontBuffer( strBuffer->x, strBuffer->y , strBuffer->fontPrio, 0 , splitStr, 0 ); + + if(cursor>=bakSplitPoint && cursorimeX = strBuffer->x + (cursor-bakSplitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + SetCursor=TRUE; + } + lineDist += strBuffer->lineDist; + return 1; + } + if(!SetCursor){ // α겻軻 + strBuffer->imeX = strBuffer->x + (strBuffer->cursor-splitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + } + StockFontBuffer( strBuffer->x, strBuffer->y + lineDist, strBuffer->fontPrio, 0 , strBuffer->buffer + splitPoint, 0 ); + return 0; +} + + +void StockFontBufferFamily( STR_BUFFER *strBuffer ) +{ + int lineDist = 0; //о + int splitPoint = 0; + int bakSplitPoint,cursor; + BOOL SetCursor=FALSE; + char splitStr[ 256 ]; + if( FontCnt >= FONT_BUFFER_SIZE ){ + strBuffer->hitFontNo = -2; + return; + } + int ; + if( strBuffer->lineLen != 0 ){ + cursor=strBuffer->cursor; + if(lineDist) = strBuffer->lineLen; + else = 38; + while( strlen( strBuffer->buffer + splitPoint ) >= ){ + bakSplitPoint=splitPoint; + //copyһеִ + strncpy_s( splitStr, strBuffer->buffer + splitPoint, ); + *( splitStr + ) = NULL; + if( GetStrLastByte( splitStr ) == 3 ){ + //ָDBCSʱ˻һbyte + splitPoint = - 1 + splitPoint; + *( splitStr + - 1 ) = NULL; + }else + splitPoint = + splitPoint; + if(lineDist) + StockFontBuffer( strBuffer->x-60, strBuffer->y + lineDist, strBuffer->fontPrio, 0, splitStr, 0 ); + else + StockFontBuffer( strBuffer->x, strBuffer->y + lineDist, strBuffer->fontPrio, 0, splitStr, 0 ); + if(cursor>=bakSplitPoint && cursorimeX = strBuffer->x-60 + (cursor-bakSplitPoint)*(FONT_SIZE>>1); + else + strBuffer->imeX = strBuffer->x +(cursor-bakSplitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + SetCursor=TRUE; + } + lineDist += strBuffer->lineDist; + if(lineDist) = strBuffer->lineLen; + else = 38; + } + if(!SetCursor){ + if(lineDist) + strBuffer->imeX = strBuffer->x -60+ (strBuffer->cursor-splitPoint)*(FONT_SIZE>>1); + else + strBuffer->imeX = strBuffer->x + (strBuffer->cursor-splitPoint)*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y + lineDist; + } + if(lineDist) + StockFontBuffer( strBuffer->x-60, strBuffer->y + lineDist, strBuffer->fontPrio, 0, strBuffer->buffer + splitPoint, 0 ); + else + StockFontBuffer( strBuffer->x, strBuffer->y + lineDist, strBuffer->fontPrio, 0, strBuffer->buffer + splitPoint, 0 ); + }else{ + FontBuffer[ FontCnt ].x = strBuffer->x; + FontBuffer[ FontCnt ].y = strBuffer->y; + FontBuffer[ FontCnt ].fontPrio = strBuffer->fontPrio; + FontBuffer[ FontCnt ].color = strBuffer->color; + FontBuffer[ FontCnt ].hitFlag = 0; +#ifdef _FONT_SIZE + FontBuffer[ FontCnt ].size = 0; +#endif + //Hook_typeǺŲ +#ifdef _SAHOOK //Syu ADD Hookʽ + if( strBuffer->filterFlag == HOOK_TYPE){ + extern int HOOK_PASSWD_NUM; + for(int i = 0 ; i < HOOK_PASSWD_NUM ; i++) + FontBuffer[ FontCnt ].str[ i ] = '*'; + FontBuffer[ FontCnt].str[i]=NULL; + strBuffer->cursor = HOOK_PASSWD_NUM; + } + else if( strBuffer->filterFlag == BLIND_TYPE ){ +#else + if( strBuffer->filterFlag == BLIND_TYPE ){ +#endif + int i; + for(i = 0 ; i < strBuffer->cnt ; i++ ) + FontBuffer[ FontCnt ].str[ i ] = '*'; + FontBuffer[ FontCnt ].str[ i ] = NULL; + }else { + extern int ; + if(==950){ + extern char* GB2312ToBIG5(const char* szBIG5String); + strcpy( FontBuffer[ FontCnt ].str, GB2312ToBIG5((const char *)strBuffer->buffer) ); + }else + strcpy( FontBuffer[ FontCnt ].str, strBuffer->buffer ); + } + strBuffer->imeX = strBuffer->x - 60+strBuffer->cursor*(FONT_SIZE>>1); + strBuffer->imeY = strBuffer->y; + strBuffer->hitFontNo = FontCnt++; + } +} \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/gamemain.cpp b/石器时代8.5客户端最新源代码/石器源码/system/gamemain.cpp new file mode 100644 index 0000000..167f027 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/gamemain.cpp @@ -0,0 +1,1480 @@ +/************************/ +/* gamemain.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include +#include +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +#include "../oft/sys2.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/battleMap.h" +#include "../systeminc/netmain.h" +#include "../systeminc/savedata.h" +#include "../systeminc/produce.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/t_music.h" +#include "../systeminc/menu.h" +#include "../systeminc/handletime.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/character.h" +#include "../systeminc/login.h" +#include "../systeminc/pc.h" +#include "../systeminc/map.h" +#include "../NewProto/autil.h" +#include "../NewProto/protocol.h" +#include "../systeminc/field.h" +#include "../systeminc/VMProtectSDK.h" +#include +#ifdef _OPTIMIZATIONFLIP_ +#include +#include +#endif +#ifdef _CMD_MODE +#include +#include +#endif +#ifdef _REMAKE_20 +#include "../MMOGprotect.h" +#endif +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif +#ifdef _PTTERN_SEPARATION_BIN +#include "../other/PtternSeparationBin.h" +#endif +#ifdef _AIDENGLU_ +#include "../systeminc/pc.h" +extern Landed PcLanded; +#endif + +int Ƿؿ_1; +int ; +int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); + +#ifdef _OPTIMIZATIONFLIP_ +#define NO_DRAW_MAX_CNT 5 // ?????????? +#else +#define NO_DRAW_MAX_CNT 6 // ?????????? +//#define FRAME_SKIP 1 // ???????? ??? ???? +#endif + +// ?????????v???L? +void ChangeWindowMode(void); +// ??T???@e?? +void SetResoMode(int Mode); +void StrToNowStrBuffer(char *str); +void StrToNowStrBuffer1(char *str); + +//#ifndef _STONDEBUG_ +// #define _STONDEBUG_ // ???????????? +//#endif +#define _BATTLESLEPP_ 0 +int testCnt; +static char no_wait_cnt = 0; +int debug_info_flag = 0; + +//---------------------------------------------------------------------------// +// ??????e? // +//---------------------------------------------------------------------------// + +// ????????? +int FrameRate; +int DrawFrameCnt; +DWORD DrawFrameTime; +#ifdef _STONDEBUG_ +static int palNo = 0; +static int fontNo = 0; +#endif + +int GameState; + +#ifdef _OPTIMIZATIONFLIP_ +//ʱ +DWORD ProcTime = 8; +//ѭʱ +DWORD SystemTime = 16; +#else +//ʱ +DWORD ProcTime = 14; +//ѭʱ +#ifdef _SYSTEM_SLEEP_ +DWORD SystemTime = _SYSTEM_SLEEP_; +#else +DWORD SystemTime = 6; +#endif +#endif + + +#ifdef _NEW_SPEED_ +BOOL GameSpeedFlag = FALSE; +#endif +DWORD NowTime; +int NoDrawCnt = 1; +int BackBufferDrawType; +#ifdef _READ16BITBMP +bool g_bMMXMode; // CPU ǷMMXָ +#endif +#ifdef _REMAKE_20 +static DWORD dwDisableInputScriptTime = 0; // ÿִһDisableInputScriptTime() +#endif + +//DWORD WINAPI CheckTickCount(LPVOID lpParam); +#ifdef _CMD_MODE +void InitConsoleWindow(void); +void ConsoleThread(void); +#endif + +#ifdef _CHECK_GAMESPEED +void HighSpeedCheck( void ) +{ +#define HIGH_SPEED_CHECK_INTERVAL 60*60 + static int SpeedCnt=0; + static float delays=0; + if( init_net == FALSE ) return; + SpeedCnt++; + if( SpeedCnt >= HIGH_SPEED_CHECK_INTERVAL ){ + int delaytimes = lssproto_getdelaytimes(); + if( delaytimes > 0 ){ + lssproto_setdelaytimes( 0); + delays += delaytimes*10; + }else{ + if( delays > 0 ) delays--; + } + SpeedCnt = 0; + lssproto_CS_send( sockfd); //̽server + } + if( (int)delays > 0 ){ + for( int i=0; i<((int)delays+1000); i++){} + } +} +#endif + +DWORD WINAPI TestThreadProc(PVOID pParam) +{ + DWORD dwStart = GetTickCount(); + Sleep(3000); + DWORD endstart = GetTickCount() - dwStart; + if (endstart >= 3500){ + ExitProcess(0); + } + return 0; +} + +DWORD WINAPI TestThreadProc1(PVOID pParam) +{ + if (VMProtectIsDebuggerPresent(true)) ExitProcess(NULL); + if (VMProtectIsVirtualMachinePresent()) ExitProcess(NULL); + extern BOOL IsContainsProcess(char* strProName, BOOL ж = 1); + if (IsContainsProcess("ര", 0) || IsContainsProcess("ͬ", 0) || + IsContainsProcess("SbieSvc.exe")||IsContainsProcess("SbieCtrl.exe")) ExitProcess(NULL); + extern void (); + (); + return 0; +} + +HANDLE hThread = NULL; +HANDLE hThread1 = NULL; +void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime) +{ + if (hThread) CloseHandle(hThread); + hThread = CreateThread(NULL, 0, TestThreadProc, 0, 0, NULL); +} +void CALLBACK TimerProc1(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime) +{ + if (hThread1) CloseHandle(hThread1); + hThread1 = CreateThread(NULL, 0, TestThreadProc1, 0, 0, NULL); +} + + + +#ifdef _ANNOUNCEMENT_ +int = 0; +char [512]; +int ɫ = -1; +int ʱ = 0; + +void announce() +{ + if ( == 0) return; + int showcolor; + ʱ += 4; + int left = ((ʱ / 25) % (800 + (strlen() * 8))); + if (left == 0){ + --; + if (ɫ == -1){ + showcolor = rand() % 10; + } + else{ + showcolor = ɫ; + } + } + StockFontBuffer(800 - left, 60, 1, showcolor, , 0); +} +#endif + + +BOOL GameMain(void) +{ + if (InitGame() == FALSE){ + MessageBoxNew(hWnd, "Ϸ趨ʼʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + char sz[32]; + DWORD nowtime; + DWORD nowttime1 = TimeGetTime(); + DWORD nowttime3 = TimeGetTime(); + //_itoa_s( nowttime1^0xffffbcde, sz, 10); + +#ifdef _OPTIMIZATIONFLIP_ + BOOL finishLoop = TRUE; + unsigned int startloopTime = TimeGetTime(); + unsigned int endloopTime; + unsigned int endProcTime; + + unsigned int loopAmend = 0; + unsigned int skipAmend = 0; + extern BOOL isXP(); + BOOL isXPSystem = isXP(); +#endif + + + CreatFontHdc(); + +#ifdef _NODEBUG_ + SetTimer(0, 0, 6000, &TimerProc); + SetTimer(0, 0, 60000, &TimerProc1); +#endif + while (1){ + + if (SystemTask() == FALSE){ + EndGame(); + return FALSE; + } + +#ifdef _OPTIMIZATIONFLIP_ + if (finishLoop) + { + startloopTime = TimeGetTime(); + endloopTime = startloopTime + SystemTime; + endProcTime = startloopTime + ProcTime; + finishLoop = FALSE; + } +#endif + + +#ifdef _CHECK_GAMESPEED + HighSpeedCheck(); +#endif +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + if(dwDisableInputScriptTime + 300000 < TimeGetTime()){ + DisableInputScript(); + dwDisableInputScriptTime = TimeGetTime(); + } +#endif +#endif + + RealTimeToSATime(&SaTime); + DispBuffer.DispCnt = 0; + FontCnt = 0; + + if (!offlineFlag) + networkLoop(); + + cdda_play(cdda_no); + joy_read(); +#if 1 + if (joy_trg[1] & JOY_F12){ + static unsigned int prePushTime = 0; + if (prePushTime + 500 <= TimeGetTime()){ + snapShot(); + prePushTime = TimeGetTime(); + } + } +#endif + if (joy_trg[1] & JOY_F11) + nameOverTheHeadFlag = !nameOverTheHeadFlag; + + Process(); + + MouseProc(); +#ifdef _SURFACE_ANIM + AniProc(); +#endif +#ifdef _ANNOUNCEMENT_ + if (ProcNo == PROC_GAME){ + if (!actBtn){ + announce(); + } + } +#endif + SortDispBuffer(); + HitMouseCursor(); + PaletteProc(); +#ifdef _AIDENGLU_ + static int µ½ԭؿʼʱ = 0; + static int µ½AIʼʱ = 0; + static int µ½ʼʱ = 0; + static int µ½ӿʼʱ = 0; + static int µ½ʼʱ = 0; + extern int Ƿصս; + extern int Ƿص﷽; + extern int ǷصAIģʽ; + extern int Ƿص; + extern int ǷصǺ; + static int ӿʼʱ = 0; + + if (ProcNo == PROC_GAME){ + if (PcLanded.ģ == 0){ + if (ǷصAIģʽ){ + if (Ƿؿ_1){ + Ƿؿ_1 = FALSE; + ӿʼʱ = TimeGetTime(); + } + } + if (partyModeFlag){//һ˵ʱ½ + if (Ƿصս){ + Ƿصս = FALSE; + µ½ԭؿʼʱ = TimeGetTime(); + } + } + } + else{ + if (Ƿصս){ + Ƿصս = FALSE; + µ½ԭؿʼʱ = TimeGetTime(); + } + } + if (ӿʼʱ){ + if (TimeGetTime() > ӿʼʱ + 500){ + extern unsigned int sockfd; + if(!pc.etcFlag &PC_ETCFLAG_PARTY){ + pc.etcFlag |= PC_ETCFLAG_PARTY; + lssproto_FS_send(sockfd, pc.etcFlag); + } + } + } + if (µ½ԭؿʼʱ){ + if (TimeGetTime() > µ½ԭؿʼʱ + 2000){ + µ½ԭؿʼʱ = 0; + extern unsigned int sockfd; + lssproto_SaMenu_send(sockfd, 11); + } + } + if (ǷصAIģʽ){ + µ½AIʼʱ = TimeGetTime(); + ǷصAIģʽ = FALSE; + } + if (µ½AIʼʱ){ + if (TimeGetTime() > µ½AIʼʱ + 500){ + µ½AIʼʱ = 0; + AI = AI_SELECT; + StockChatBufferLine("ģʽ", FONT_PAL_RED); + pc.etcFlag |= PC_AI_MOD; + lssproto_FS_send(sockfd, pc.etcFlag); + } + } + if (Ƿص﷽){ + Ƿص﷽ = FALSE; + µ½ʼʱ = TimeGetTime(); + } + if (µ½ʼʱ){ + if (TimeGetTime() > µ½ʼʱ + 500){ + µ½ʼʱ = 0; + char dir2[2]; + setPcDir(PcLanded.﷽); + dir2[0] = cnvServDir(PcLanded.﷽, 1); + dir2[1] = '\0'; + walkSendForServer(nowGx, nowGy, dir2); + } + } + extern int Զ½Ƿ; + if (Ƿص&&!Ƿص﷽&&!µ½ʼʱ&&!partyModeFlag){ + if (!µ½ӿʼʱ){ + µ½ӿʼʱ = TimeGetTime(); + } + else{ + if (TimeGetTime() > µ½ӿʼʱ + FIELD_BTN_PUSH_WAIT){ + µ½ӿʼʱ = 0; + lssproto_PR_send(sockfd, nowGx, nowGy, 1); + } + } + if (ǷصǺ){ + if (!µ½ʼʱ){ + µ½ʼʱ = TimeGetTime(); + } + else{ + if (TimeGetTime() > µ½ʼʱ + 1000 * 60){ + µ½ʼʱ = 0; + char m[1024]; + sprintf_s(m, "P|λܴӴյµ½վǰλ(%d,%d)", nowGx, nowGy); + lssproto_TK_send(sockfd, nowGx, nowGy, m, 0, NowMaxVoice); + } + } + } + } + else{ + µ½ӿʼʱ = 0; + µ½ʼʱ = 0; + } + } + extern int Զ½Ƿ; + if (ProcNo >= 1 && ProcNo <= 3){ + if (PcLanded. != -1 && PcLanded.С != -1 && PcLanded. != -1){ + if (Զ½Ƿ) + StockFontBuffer(10, 550, FONT_PRIO_FRONT, FONT_PAL_RED, "Զ½,F9ֹͣԶ½", 0); + else + StockFontBuffer(10, 550, FONT_PRIO_FRONT, FONT_PAL_RED, "F9Զ½Ϸ", 0); + } + } + if (joy_trg[1] & JOY_F9&&ProcNo >= 1 && ProcNo <= 3) + { + if (Զ½Ƿ) Զ½Ƿ = !Զ½Ƿ; + else{ + if (PcLanded. != -1 && PcLanded.С != -1 && PcLanded. != -1) + Զ½Ƿ = TRUE; + } + } +#endif +#ifdef _STONDEBUG_ + if (joy_trg[1] & JOY_F9 && WindowMode){ +#else + if (joy_trg[1] & JOY_F9 && WindowMode && LowResoCmdFlag){ +#endif + + if (BackBufferDrawType != DRAW_BACK_PRODUCE){ + if (lpDraw != NULL){ + // DirectDraw ? + ReleaseDirectDraw(); + DeleteObject(hFont); + SetResoMode(((ResoMode + 1) % 5)); + InitDirectDraw(); + InitOffScreenSurface(); + InitFont(0); + ChangeWindowMode(); + if (InitPalette() == FALSE){ + PostMessage(hWnd, WM_CLOSE, 0, 0L); + } + if (ProcNo == PROC_BATTLE){ + DispBuffer.DispCnt = 0; + FontCnt = 0; + ReadBattleMap(BattleMapNo); + ClearBackSurface(); +#ifdef __SKYISLAND + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#else + PutBmp(); + lpBattleSurface->BltFast(0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT); +#endif + DispBuffer.DispCnt = 0; + FontCnt = 0; + NowTime = TimeGetTime(); + } + else + if (fastDrawTile && ProcNo == PROC_GAME){ + repairMap(); + } + } + } + } + + +#ifdef _STONDEBUG_ + if( joy_trg[ 0 ] & JOY_HOME ){ + strcpy( MyChatBuffer.buffer + MyChatBuffer.cnt, DebugKey0 ); + MyChatBuffer.cnt += strlen( DebugKey0 ); + } + if( joy_trg[ 0 ] & JOY_END ){ + strcpy( MyChatBuffer.buffer + MyChatBuffer.cnt, DebugKey1 ); + MyChatBuffer.cnt += strlen( DebugKey1 ); + } + if( joy_trg[ 0 ] & JOY_INS ){ + strcpy( MyChatBuffer.buffer + MyChatBuffer.cnt, DebugKey2 ); + MyChatBuffer.cnt += strlen( DebugKey2 ); + } + DisplayFrameRate(); + { + if( di_key[ DIK_PRIOR ] & 0x80 ){ + if( debug_info_flag == 0 ) debug_info_flag = 1; + if( debug_info_flag == 2 ) debug_info_flag = 3; + }else{ + if( debug_info_flag == 1 ) debug_info_flag = 2; + if( debug_info_flag == 3 ) debug_info_flag = 0; + } + if (debug_info_flag == 1 || debug_info_flag == 2) InfoDisp(); + } +#endif + +#ifdef __NEW_CLIENT_MEM +#ifndef __NEW_CLIENT_ONLY_WRITE + static DWORD reset = TimeGetTime() + 120000; + static DWORD flip = 1; + DWORD oldprotect; + if (reset < TimeGetTime()){ + char *newread, *newwrite; + reset += 120000; + flip = (flip + 1) & 1; + if (flip == 1){ + if ((newread = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + if (net_readbuflen){ + VirtualProtect(net_readbuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); + CopyMemory(newread, net_readbuf, net_readbuflen); + } + VirtualFree(net_readbuf, NULL, MEM_RELEASE); + net_readbuf = newread; + VirtualProtect(net_readbuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); + } + } + else{ + if ((newwrite = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + if (net_writebuflen){ + VirtualProtect(net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); + CopyMemory(newwrite, net_writebuf, net_writebuflen); + } + VirtualFree(net_writebuf, NULL, MEM_RELEASE); + net_writebuf = newwrite; + VirtualProtect(net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); + } + } + } +#else + static DWORD reset = TimeGetTime() + 120000; + DWORD oldprotect; + if( reset < TimeGetTime()){ + char *newwrite; + reset += 120000; + if( (newwrite=(char*)VirtualAlloc( NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); + CopyMemory( newwrite, net_writebuf, net_writebuflen); + VirtualFree( net_writebuf, NULL, MEM_RELEASE); + net_writebuf = newwrite; + VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); + newwrite = NULL; + } + } +#endif +#endif + +#ifdef _STONEAGE_NG + +#else + +#ifdef _OPTIMIZATIONFLIP_ + if (endProcTime > TimeGetTime()) + { + //֡ + if (NoDrawCnt < NO_DRAW_MAX_CNT + skipAmend) + { + NoDrawCnt++; + continue; + } + else + { + while (endProcTime > TimeGetTime()) + { + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } + } + } +#ifdef _MO_SHOW_FPS + sprintf(sz, "skip frames: %d", skipAmend); + StockFontBuffer(380, 10, 1, 1, sz, false); +#endif + +#else + NowTime = TimeGetTime();//ȡǰʱ + nowtime = nowttime1; + //nowtime ^= 0xffffbcde; + static DWORD OldTime = nowttime1; + if (NowTime > (nowtime + ProcTime)){ + //OldTime^= 0x855ff55f; + if (OldTime != nowtime){ + OldTime = nowtime; + if (NoDrawCnt < NO_DRAW_MAX_CNT){ + if (NowTime>nowttime3 + 2000){ + nowttime3 = NowTime; + nowtime = NowTime + SystemTime; + } + else + nowtime += (SystemTime); + nowttime1 = nowtime; + //_itoa_s( nowtime^0xffffbcde, sz, 10); + nowtime = 0; + NoDrawCnt++; + Sleep(0); + continue; + } + }//else + //OldTime^= 0x855ff55f; + } +#endif +#endif + nowtime = 0; + //cary AIл + if (di_key[DIK_NEXT] & 0x80){ + di_key[DIK_NEXT] &= ~0x80; + static DWORD switchmodetime = TimeGetTime(); + if ((switchmodetime + 500) < NowTime){ + switchmodetime = NowTime; +#ifdef __AI + if (AI == AI_SELECT){ + AI = AI_NONE; + pc.etcFlag &= (~PC_AI_MOD); + lssproto_FS_send(sockfd, pc.etcFlag); + // ޸սAIתBUG AI-> +#ifdef _FIX_BATTLE_AI + battleMenuFix(); +#endif + } + else{ + AI = AI_SELECT; + pc.etcFlag |= PC_AI_MOD; + lssproto_FS_send(sockfd, pc.etcFlag); + } + extern BOOL AI_Save(); + AI_Save(); +#else + extern int battleWazaTargetBak; + if (PROC_BATTLE != ProcNo || BATTLE_SUBPROC_CMD_INPUT != SubProcNo){ + battleWazaTargetBak = -1; + AI++; + if (AI > AI_SELECT) + AI = AI_NONE; + } + else{ + if (AI == AI_NONE){ + battleWazaTargetBak = -1; + AI = AI_ATTACK; + } + } +#endif + } + } + else if (di_key[DIK_PRIOR] & 0x80){ + di_key[DIK_PRIOR] &= ~0x80; + static DWORD switchmodetime = TimeGetTime(); + if ((switchmodetime + 500) < NowTime){ + switchmodetime = NowTime; +#ifdef __AI + if (AI == AI_SELECT){ + AI = AI_NONE; + // ޸սAIתBUG ->AI +#ifdef _FIX_BATTLE_AI + battleMenuFix(); +#endif + pc.etcFlag &= (~PC_AI_MOD); + lssproto_FS_send(sockfd, pc.etcFlag); + } + else{ + AI = AI_SELECT; + pc.etcFlag |= PC_AI_MOD; + lssproto_FS_send(sockfd, pc.etcFlag); + } + extern BOOL AI_Save(); + AI_Save(); +#else + extern int battleWazaTargetBak; + if (PROC_BATTLE != ProcNo || BATTLE_SUBPROC_CMD_INPUT != SubProcNo){ + battleWazaTargetBak = -1; + AI--; + if( AI < AI_NONE) + AI = AI_SELECT; + }else{ + if( AI == AI_NONE){ + battleWazaTargetBak = -1; + AI = AI_SELECT; + } + } +#endif + } + } + +#ifdef _STONDEBUG_ + SurfaceDispCnt = 0; + // DrawDebugLine( 250 ); +#endif +#ifndef __SKYISLAND + switch( BackBufferDrawType ){ + + case DRAW_BACK_NON: + break; + + case DRAW_BACK_NORMAL: + ClearBackSurface(); + break; + + case DRAW_BACK_PRODUCE: + break; + + case DRAW_BACK_BATTLE: // ??????? + + DrawBattleMap(); + break; + + } +#else + if (BackBufferDrawType != DRAW_BACK_PRODUCE){ +#endif +#ifdef _STONDEBUG_ + no_wait_cnt++; + if( GetAsyncKeyState( 0x10 ) & 0x8000 ) + no_wait_cnt &= 7; + else + no_wait_cnt &= 3; + if( GetAsyncKeyState( 0x10 ) & 0x8000 ){ //??????????? + if(!no_wait_cnt){ + PutBmp(); // ???????????????? + // dwaf ??????L??? + baseXFastDraw = nowXFastDraw; + baseYFastDraw = nowYFastDraw; + baseXFastDraw2 = nowXFastDraw2; + baseYFastDraw2 = nowYFastDraw2; + } + } + else { + PutBmp(); // ???????????????? + baseXFastDraw = nowXFastDraw; + baseYFastDraw = nowYFastDraw; + baseXFastDraw2 = nowXFastDraw2; + baseYFastDraw2 = nowYFastDraw2; + } +#else +#ifdef _NEW_SPEED_ + no_wait_cnt++; + no_wait_cnt &= 3; +#ifdef _OPTIMIZATIONFLIP_ + loopAmend = TimeGetTime(); +#endif + PutBmp(); +#ifdef _OPTIMIZATIONFLIP_ + loopAmend = TimeGetTime() - loopAmend; + if (loopAmend < 8) + { + skipAmend = 0; + } + else if (loopAmend >=8) + { + skipAmend = 1; + } +#endif + baseXFastDraw = nowXFastDraw; + baseYFastDraw = nowYFastDraw; + baseXFastDraw2 = nowXFastDraw2; + baseYFastDraw2 = nowYFastDraw2; + +#else + PutBmp(); + baseXFastDraw = nowXFastDraw; + baseYFastDraw = nowYFastDraw; + baseXFastDraw2 = nowXFastDraw2; + baseYFastDraw2 = nowYFastDraw2; + +#endif //_SPEED +#endif +#ifdef __SKYISLAND + } +#endif + +#ifdef _STONDEBUG_ + DrawDebugLine(0); +#endif + +#ifdef _STONDEBUG_ + if (GetAsyncKeyState(0x10) & 0x8000){ //??????????? + if (!no_wait_cnt){ + Flip(); // ?i?_???v??? + } + } + else { + Flip(); // ?i?_???v??? + } +#else + Flip(); // ?i?_???v??? +#endif + +#ifdef _STONDEBUG_ + DrawDebugLine(249); +#endif + +#ifdef _STONDEBUG_ + if (GetAsyncKeyState(0x10) & 0x8000){ //??????????? + nowtime = TimeGetTime(); + _itoa_s(nowtime ^ 0xffffbcde, sz, 10); + } else { + nowtime = atoi( sz); + nowtime ^= 0xffffbcde; + while( nowtime >= TimeGetTime() ){ + if( WindowMode ){ + Sleep(1); + } + } + } +#else +#ifdef _NEW_SPEED_ + //nowtime = atoi( sz); + //nowtime ^= 0xffffbcde; +#ifndef _OPTIMIZATIONFLIP_ + nowtime = nowttime1; + while (nowtime >= TimeGetTime()){ + Sleep(1); + } + nowtime = 0; +#endif +#else + nowtime = atoi( sz); + nowtime ^= 0xffffbcde; + while( nowtime >= TimeGetTime() ){ + Sleep(1); + } + nowtime = 0; + +#endif +#endif + + if (PalChangeFlag == TRUE){ + +#ifdef __NEW_CLIENT + extern HANDLE hProcessSnap, hParentProcess; + extern DWORD dwPID; + extern PROCESSENTRY32 pe32; + if( dwPID){ + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if (pe32.th32ProcessID == dwPID){ + if (!strstr(pe32.szExeFile, "explorer.exe") && (hParentProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID))){ +#ifndef NO_TERMINATER + TerminateProcess(hParentProcess, 0); +#endif + CloseHandle(hParentProcess); + } + break; + } + }while (Process32Next(hProcessSnap, &pe32)); + } + dwPID = 0; + } +#endif + extern int displayBpp; + extern int rBitLShift, gBitLShift, bBitLShift; + extern int rBitRShift, gBitRShift, bBitRShift; + if (displayBpp >= 16){ +#ifdef _HI_COLOR_32 + if (displayBpp == 32){ + extern unsigned int highColor32Palette[256]; + for (int i = 1; i < 256; i++){ + highColor32Palette[i] = + //cary 2001 10 16 + ((Palette[i].peBlue >> bBitRShift) << bBitLShift) + + ((Palette[i].peGreen >> gBitRShift) << gBitLShift) + + ((Palette[i].peRed >> rBitRShift) << rBitLShift); + } + } + else +#endif + if (displayBpp == 16){ + extern unsigned short highColorPalette[256]; + for (int i = 1; i < 256; i++){ + highColorPalette[i] = + ((Palette[i].peBlue >> bBitRShift) << bBitLShift) + + (((Palette[i].peGreen >> gBitRShift) | 1) << gBitLShift) + + ((Palette[i].peRed >> rBitRShift) << rBitLShift); + } + } +#ifdef __HI_COLOR + InitSpriteInfo(); + InitSurfaceInfo(); + extern int BackBufferDrawType; + if (BackBufferDrawType == DRAW_BACK_BATTLE){ +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap(BattleMapNo); +#else + ReadBattleMap(BattleMapNo); +#endif + SortDispBuffer(); + ClearBackSurface(); + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; + } + else repairMap(); +#endif +#ifdef __CARYTEST + extern LPREALBIN g_lpRealHead; + LPREALBIN node = g_lpRealHead; + while (node){ + node->state = 0; + } +#endif + } + else if (displayBpp == 8){ + lpDraw->lpPALETTE->SetEntries(0, 0, 256, Palette); + } + PalChangeFlag = FALSE; + } +#ifdef _NEW_SPEED_ + if (GameSpeedFlag){ + nowtime = TimeGetTime(); + nowttime1 = nowtime; + //_itoa_s( nowtime^0xffffbcde, sz, 10); + GameSpeedFlag = FALSE; + } +#endif + //nowtime = atoi( sz); + //nowtime ^= 0xffffbcde; + +#ifdef _OPTIMIZATIONFLIP_ + finishLoop = TRUE; + NoDrawCnt = 1; + + while (endloopTime > TimeGetTime()){ + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } + +#else + nowttime1 += SystemTime; + nowtime = 0; + Sleep(1); + NoDrawCnt = 1; +#endif + +#ifdef _STONDEBUG_ + // ????????????? + DrawFrameCnt++; +#endif + SurfaceDate++; + } + + return FALSE; +} + +#ifdef _STONDEBUG_ +unsigned int iTotalUseTime; +unsigned int iTotalProcTime; +unsigned int iTotalRunCount; +unsigned int iShowCount; +LARGE_INTEGER tf; +extern bool g_bMMXMode; +// ѩ *******************************************************************/ +void InfoDisp( void ) +{ + char szMoji[ 256 ]; + int x = lpDraw->xSize - 200; + int y = 64; + char c = 0; + + sprintf_s( szMoji,"ActionCnt = %d", ActCnt ); + // ????ѩ????????? + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"DispCnt = %d", DispBuffer.DispCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SurfaceCnt = %d",SurfaceCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SearchPoint = %d",SurfaceSearchPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SysramSurfaceCnt = %d",SysramSurfaceCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"VramSurfaceCnt = %d",VramSurfaceCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SurfaceUseCnt = %d",SurfaceUseCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SurfaceDispCnt = %d",SurfaceDispCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SurfaceDate = %d",SurfaceDate ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"FrameRate = %d",FrameRate ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"HitDispNo = %d",HitDispNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"HitFontNo = %d",HitFontNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"MouseLevel = %d",mouse.level ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"ProcNo = %d",ProcNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"SubProcNo = %d",SubProcNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"ActionSize = %d",sizeof( ACTION ) ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"MouseX = %d",mouse.nowPoint.x ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"MouseY = %d",mouse.nowPoint.y ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"TimeZone = %d",SaTime.hour ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + c = 0; + + sprintf_s( szMoji,"PalNo = %d",PalState.palNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"BattleMapNo = %d",BattleMapNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"HogeCnt = %d",testCnt ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"EventEnemyFlag = %d",eventEnemyFlag ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + // ?P?? + if( BattleMyNo >= 20 ){ + sprintf_s( szMoji,"BattleTurnNo = %d",BattleCliTurnNo ); + }else{ + sprintf_s( szMoji,"BattleTurnNo = %d",BattleCliTurnNo + 1 ); + } + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"BattleDebTurnNo = %d",BattleDebTurnNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; +#ifdef _READ16BITBMP +#ifdef _STONDEBUG_ + if(iTotalRunCount % 100){ + iShowCount = iTotalUseTime/iTotalRunCount; + // iTotalUseTime = 0; + // iTotalRunCount = 0; + } + sprintf_s( szMoji,"TestProcUseTime = %d",iShowCount); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + sprintf_s( szMoji,"TestRunTimes = %d",iTotalRunCount); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; +#endif +#ifdef _TALK_WINDOW + sprintf_s(szMoji,"g_iCursorCount = %d",g_iCursorCount); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; +#endif +#endif + + sprintf_s( szMoji,"selectPetNo[ 0 ] = %d",pc.selectPetNo[ 0 ] ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"selectPetNo[ 1 ] = %d",pc.selectPetNo[ 1 ] ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s( szMoji,"selectPetNo[ 2 ] = %d",pc.selectPetNo[ 2 ] ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, c++, szMoji, 0 );y += 16; + + sprintf_s(szMoji, "selectPetNo[ 3 ] = %d", pc.selectPetNo[3]); + StockFontBuffer(x, y, FONT_PRIO_FRONT, c++, szMoji, 0); y += 16; + + sprintf_s(szMoji, "selectPetNo[ 4 ] = %d", pc.selectPetNo[4]); + StockFontBuffer(x, y, FONT_PRIO_FRONT, c++, szMoji, 0); y += 16; + + sprintf_s(szMoji, "BattlePetStMenCnt= %d", BattlePetStMenCnt); + StockFontBuffer(x, y, FONT_PRIO_FRONT, c++, szMoji, 0); y += 16; + + sprintf_s(szMoji, "BattlePetReceiveFlag= %d", BattlePetReceiveFlag); + StockFontBuffer(x, y, FONT_PRIO_FRONT, c++, szMoji, 0); y += 16; + +} +#endif + +// ?????????????? +void DisplayFrameRate(void) +{ + // ?????? + if (TimeGetTime() - DrawFrameTime >= 1000){ + + // ?????????? + FrameRate = DrawFrameCnt; + // ??????? + DrawFrameTime = TimeGetTime(); + // ???????????? + DrawFrameCnt = 0; + } +} +// ??? *****************************************************************/ +void PutLogo(void) +{ + DispBuffer.DispCnt = 0; + StockDispBuffer(400, 300, DISP_PRIO_TOP, CG_LOGO, 0); + ClearBackSurface(); // ??????????????? + PutBmp(); // ???????????????? + Flip(); // +} + +void GameErrorMessage(char *buf) +{ +#ifdef _STONDEBUG_ + FILE *fp = NULL; + + if( ( fopen_s(&fp, "err.log","a+"))!=NULL ) return; + if (buf != NULL) + fprintf(fp, "%s\n", buf); + fclose(fp); +#endif +} + +BOOL InitGame(void) +{ + InitDInput(); +#ifdef _REMAKE_20 + DisableCheated(); +#ifndef _STONDEBUG_ + RegisterHotKey(hWnd,0,MOD_ALT,VK_TAB); + RegisterHotKey(hWnd,1,MOD_ALT,VK_ESCAPE); + InitialInputScript(); + DisableInputScript(); +#endif + RestoreLibrary(); + InitRestore(); + SetTimer(hWnd,0,55,NULL); +#endif +#ifdef _READ16BITBMP + unsigned int testMMX = 0; + // cpuǷMMXָ + __asm{ + push eax + mov eax,1 + CPUID + mov testMMX, edx + pop eax + } + // 23λԪΪ1ʾMMX + if (testMMX & 0x00800000) g_bMMXMode = true; + else g_bMMXMode = false; +#endif +#ifdef _STONDEBUG_ +#ifdef _READ16BITBMP + QueryPerformanceFrequency(&tf); + iTotalProcTime = 0; + iTotalRunCount = 0; +#endif +#endif + util_Init(); + if (InitDirectDraw() == FALSE){ + MessageBoxNew(hWnd, "ʼDirectDrawʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + if (InitOffScreenSurface() == FALSE){ + MessageBoxNew(hWnd, "ʼOff Screan Surfaceʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + if (InitPalette() == FALSE) + return FALSE; + if (initRealbinFileOpen(realBinName, adrnBinName) == FALSE) { + MessageBoxNew(hWnd, "Real.binʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + //PutLogo(); + initAutoMapColor(adrnBinName); + if (InitSprBinFileOpen(sprBinName, sprAdrnBinName) == FALSE){ + MessageBoxNew(hWnd, "Spr.binʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } +#ifdef _READ16BITBMP + int ref; + if ((ref = InitRealTruebinFileOpen(realtrueBinName, adrntrueBinName)) < 0){ + if (ref == -1) MessageBoxNew(hWnd, " adrntrue.bin ʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + else if (ref == -2) MessageBoxNew(hWnd, " realtrue.bin ʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } +#endif + +#ifdef _PTTERN_SEPARATION_BIN +#ifdef _SA_VERSION_25 + InitPteernSeparationBin(".//path"); +#endif +#endif + +#ifdef _WIN_LUAJIT_ + memset(gmsv, 0, sizeof(gameserver)*MAX_GMSV); + memset(gmgroup, 0, sizeof(gamegroup)*MAX_GMGROUP); + extern void LoadStoneAgeLUA(char *path); + LoadStoneAgeLUA(_LUA_PATCH_); +#endif + InitAction(); + InitFont(0); + srand(TimeGetTime()); + initRand2(); + t_music_init(); + + if (!InitIme(hWnd, StrToNowStrBuffer)){ + MessageBoxNew(hWnd, "ʼ뷨ʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + MouseInit(); + if (loadUserSetting() == FALSE){ + char msg[1024]; + sprintf_s(msg, SAVE_ERRMSG_loadNowState, savedataErrorCode); + MessageBoxNew(hWnd, msg, "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + LoadChatRegistyStr(); + NowTime = TimeGetTime(); + DrawFrameTime = TimeGetTime(); + if (MouseCursorFlag == FALSE){ +#ifdef _TALK_WINDOW + g_iCursorCount = ShowCursor(FALSE); +#else + ShowCursor(FALSE); +#endif + } + + ProcNo2 = -1; +#ifdef __NEW_CLIENT_MEM +#ifndef __NEW_CLIENT_ONLY_WRITE + if (!net_readbuf){ + if (!(net_readbuf = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + MessageBoxNew(hWnd, "net_readbuf Init ʧ!", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#else + if( !net_readbuf){ + if( !(net_readbuf=(char*)VirtualAlloc( NULL, NETBUFSIZ, MEM_COMMIT, PAGE_NOACCESS))){ + MessageBoxNew( hWnd, "net_readbuf Init ʧ!", "ȷ", MB_OK | MB_ICONSTOP ); + return FALSE; + } + } +#endif + if (!net_writebuf){ + if (!(net_writebuf = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_NOACCESS))){ + MessageBoxNew(hWnd, "net_writebuf Init ʧ!", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#else + if (!net_readbuf){ + if (!(net_readbuf = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + MessageBoxNew(hWnd, "net_readbuf Init ʧ!", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } + if (!net_writebuf){ + if (!(net_writebuf = (char*)VirtualAlloc(NULL, NETBUFSIZ, MEM_COMMIT, PAGE_READWRITE))){ + MessageBoxNew(hWnd, "net_writebuf Init ʧ!", "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#endif +#ifdef _CHANNEL_MODIFY + CreateDirectory("chat\\", NULL); +#endif + return TRUE; +} + +#ifdef _CHANNEL_MODIFY +void SaveChatData(char *msg, char KindOfChannel, bool bCloseFile); +#endif + +void EndGame(void) +{ +#ifdef __NEW_CLIENT + extern HANDLE hPing; + extern SOCKET sockRaw; + if (hPing){ + closesocket(sockRaw); + sockRaw = INVALID_SOCKET; + TerminateThread(hPing, 0); + CloseHandle(hPing); + hPing = NULL; + } +#endif + if (net_readbuf){ + VirtualFree(net_readbuf, NULL, MEM_RELEASE); + net_readbuf = NULL; + } + if (net_writebuf){ + VirtualFree(net_writebuf, NULL, MEM_RELEASE); + net_writebuf = NULL; + } + //DirectDraw ? + ReleaseDirectDraw(); + // ??????????? + EndDInput(); + // DirectSound ? + t_music_end(); + // ????_ + cdda_stop(); + // Rialbin ?? + cleanupRealbin(); + // ???????????? + DeleteObject(hFont); + // ????? + EndIme(); + // ???????? + EndAction(); + // ????????? + cleanupNetwork(); + // i??h??????????? + ReleaseMutex(hMutex); + // ???????? + saveUserSetting(); + // ?????K???V + SaveChatRegistyStr(); + + // ????? + // timeKillEvent(timerId); + + //{ + // ALT+TAB ????? + // int nOldVal; + // SystemParametersInfo (SPI_SCREENSAVERRUNNING, FALSE, &nOldVal, 0); + //} +#ifdef _CHANNEL_MODIFY + SaveChatData(NULL, 0, true); +#endif +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + UnregisterHotKey(hWnd, 0); + UnregisterHotKey(hWnd, 1); +#endif +#endif + util_Release(); +} +#ifdef _CMD_MODE + + +HANDLE hConsoleThread; +DWORD ConsoleThreadID; +volatile BOOL m_bRun; + +void ConsoleThread(void) +{ + char cmd[256]; + memset(cmd,0,sizeof(cmd)); + int c,i; + + while(m_bRun) + { + printf("\nʯʱ>"); + i = 0; + while( (c = getchar()) != '\n') + { + cmd[i] = c; + i++; + } + //cmd[i] = '\0'; + fflush(stdin); + + if( strcmp(cmd,"q") == 0) + { + m_bRun = FALSE; + FreeConsole(); + ExitThread(ConsoleThreadID); + return; + } + if( cmd[0] == 'a' && cmd[1] == ' ') + { + int level; + sscanf_s(cmd,"a %i",&level); + if( level >= 0 && level <= 14) + { + //Patch_Accelerate(level); + printf("SUCCESS: Acceleration level has been switched to %i.", level); + continue; + } + else + { + printf("ERROR: Acceleration level out of range(0-14)."); + continue; + } + } + if( cmd[0] == 'l' && cmd[1] == ' ') + { + char addr[32]; + char port[6]; + char* p,*next_p; + p = NULL; + next_p = NULL; + p = strtok_s(cmd," ",&next_p); + if(p) + { + p = strtok_s(NULL," ",&next_p); + if(p) + { + sprintf_s(addr,sizeof(addr),p); + p = strtok_s(NULL," ",&next_p); + if(p) + { + if(strtok_s(NULL," ",&next_p)) + { + continue; + } + else + { + sprintf_s(port,sizeof(port),p); + printf("%s %s",addr,port); + continue; + } + } + else + { + continue; + } + } + else + { + continue; + } + } + } + } +} + + +void InitConsoleWindow(void) +{ + int hCrt; + FILE *hf; + + + AllocConsole(); + SetConsoleTitle("ʯʱ"); + + hCrt = _open_osfhandle( + (long)GetStdHandle(STD_OUTPUT_HANDLE),O_TEXT ); + hf = _fdopen( hCrt, "w" ); + + *stdout = *hf; + setvbuf( stdout, NULL, _IONBF, 0 ); + + hCrt = _open_osfhandle( + (long)GetStdHandle(STD_INPUT_HANDLE), + _O_TEXT ); + hf = _fdopen( hCrt, "r" ); + + *stdin = *hf; + setvbuf( stdin, NULL, _IONBF, 0 ); + + + printf("\ + ===================================\n\ + ==== Console for StoneAge ====\n\ + ==== USE \"h\" FOR HELP ====\n\ + ===================================\n\ + /*----------COMMAND LINE---------*/"); + + hConsoleThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ConsoleThread, NULL, 0, &ConsoleThreadID); + if (hConsoleThread != NULL) + m_bRun = TRUE; +} + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/gemini.cpp b/石器时代8.5客户端最新源代码/石器源码/system/gemini.cpp new file mode 100644 index 0000000..9dbe103 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/gemini.cpp @@ -0,0 +1,629 @@ +//#include "main.h" +//#include "action.h" +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +#include "../oft/vg410.h" +#include "../oft/work.h" + +Sint16 DELTA_TBL[]={ +/*SPEED = 1*/ + (Sint16)0x0000,(Sint16)0xFFC0,(Sint16)0x000C,(Sint16)0xFFC2,(Sint16)0x0018,(Sint16)0xFFC5,(Sint16)0x0023,(Sint16)0xFFCB, + (Sint16)0x002D,(Sint16)0xFFD3,(Sint16)0x0035,(Sint16)0xFFDD,(Sint16)0x003B,(Sint16)0xFFE8,(Sint16)0x003E,(Sint16)0xFFF4, + (Sint16)0x0040,(Sint16)0x0000,(Sint16)0x003E,(Sint16)0x000C,(Sint16)0x003B,(Sint16)0x0018,(Sint16)0x0035,(Sint16)0x0023, + (Sint16)0x002D,(Sint16)0x002D,(Sint16)0x0023,(Sint16)0x0035,(Sint16)0x0018,(Sint16)0x003B,(Sint16)0x000C,(Sint16)0x003E, + (Sint16)0x0000,(Sint16)0x0040,(Sint16)0xFFF4,(Sint16)0x003E,(Sint16)0xFFE8,(Sint16)0x003B,(Sint16)0xFFDD,(Sint16)0x0035, + (Sint16)0xFFD3,(Sint16)0x002D,(Sint16)0xFFCB,(Sint16)0x0023,(Sint16)0xFFC5,(Sint16)0x0018,(Sint16)0xFFC2,(Sint16)0x000C, + (Sint16)0xFFC0,(Sint16)0x0000,(Sint16)0xFFC2,(Sint16)0xFFF4,(Sint16)0xFFC5,(Sint16)0xFFE8,(Sint16)0xFFCB,(Sint16)0xFFDD, + (Sint16)0xFFD3,(Sint16)0xFFD3,(Sint16)0xFFDD,(Sint16)0xFFCB,(Sint16)0xFFE8,(Sint16)0xFFC5,(Sint16)0xFFF4,(Sint16)0xFFC2, +/*SPEED = 2*/ + (Sint16)0x0000,(Sint16)0xFF80,(Sint16)0x0018,(Sint16)0xFF83,(Sint16)0x0030,(Sint16)0xFF8A,(Sint16)0x0047,(Sint16)0xFF96, + (Sint16)0x005A,(Sint16)0xFFA6,(Sint16)0x006A,(Sint16)0xFFB9,(Sint16)0x0076,(Sint16)0xFFD0,(Sint16)0x007D,(Sint16)0xFFE8, + (Sint16)0x0080,(Sint16)0x0000,(Sint16)0x007D,(Sint16)0x0018,(Sint16)0x0076,(Sint16)0x0030,(Sint16)0x006A,(Sint16)0x0047, + (Sint16)0x005A,(Sint16)0x005A,(Sint16)0x0047,(Sint16)0x006A,(Sint16)0x0030,(Sint16)0x0076,(Sint16)0x0018,(Sint16)0x007D, + (Sint16)0x0000,(Sint16)0x0080,(Sint16)0xFFE8,(Sint16)0x007D,(Sint16)0xFFD0,(Sint16)0x0076,(Sint16)0xFFB9,(Sint16)0x006A, + (Sint16)0xFFA6,(Sint16)0x005A,(Sint16)0xFF96,(Sint16)0x0047,(Sint16)0xFF8A,(Sint16)0x0030,(Sint16)0xFF83,(Sint16)0x0018, + (Sint16)0xFF80,(Sint16)0x0000,(Sint16)0xFF83,(Sint16)0xFFE8,(Sint16)0xFF8A,(Sint16)0xFFD0,(Sint16)0xFF96,(Sint16)0xFFB9, + (Sint16)0xFFA6,(Sint16)0xFFA6,(Sint16)0xFFB9,(Sint16)0xFF96,(Sint16)0xFFD0,(Sint16)0xFF8A,(Sint16)0xFFE8,(Sint16)0xFF83, +/*SPEED = 3*/ + (Sint16)0x0000,(Sint16)0xFF40,(Sint16)0x0025,(Sint16)0xFF44,(Sint16)0x0049,(Sint16)0xFF4F,(Sint16)0x006A,(Sint16)0xFF61, + (Sint16)0x0087,(Sint16)0xFF79,(Sint16)0x009F,(Sint16)0xFF96,(Sint16)0x00B1,(Sint16)0xFFB7,(Sint16)0x00BC,(Sint16)0xFFDB, + (Sint16)0x00C0,(Sint16)0x0000,(Sint16)0x00BC,(Sint16)0x0025,(Sint16)0x00B1,(Sint16)0x0049,(Sint16)0x009F,(Sint16)0x006A, + (Sint16)0x0087,(Sint16)0x0087,(Sint16)0x006A,(Sint16)0x009F,(Sint16)0x0049,(Sint16)0x00B1,(Sint16)0x0025,(Sint16)0x00BC, + (Sint16)0x0000,(Sint16)0x00C0,(Sint16)0xFFDB,(Sint16)0x00BC,(Sint16)0xFFB7,(Sint16)0x00B1,(Sint16)0xFF96,(Sint16)0x009F, + (Sint16)0xFF79,(Sint16)0x0087,(Sint16)0xFF61,(Sint16)0x006A,(Sint16)0xFF4F,(Sint16)0x0049,(Sint16)0xFF44,(Sint16)0x0025, + (Sint16)0xFF40,(Sint16)0x0000,(Sint16)0xFF44,(Sint16)0xFFDB,(Sint16)0xFF4F,(Sint16)0xFFB7,(Sint16)0xFF61,(Sint16)0xFF96, + (Sint16)0xFF79,(Sint16)0xFF79,(Sint16)0xFF96,(Sint16)0xFF61,(Sint16)0xFFB7,(Sint16)0xFF4F,(Sint16)0xFFDB,(Sint16)0xFF44, +/*SPEED = 4*/ + (Sint16)0x0000,(Sint16)0xFF00,(Sint16)0x0031,(Sint16)0xFF05,(Sint16)0x0061,(Sint16)0xFF14,(Sint16)0x008E,(Sint16)0xFF2C, + (Sint16)0x00B5,(Sint16)0xFF4B,(Sint16)0x00D4,(Sint16)0xFF72,(Sint16)0x00EC,(Sint16)0xFF9F,(Sint16)0x00FB,(Sint16)0xFFCF, + (Sint16)0x0100,(Sint16)0x0000,(Sint16)0x00FB,(Sint16)0x0031,(Sint16)0x00EC,(Sint16)0x0061,(Sint16)0x00D4,(Sint16)0x008E, + (Sint16)0x00B5,(Sint16)0x00B5,(Sint16)0x008E,(Sint16)0x00D4,(Sint16)0x0061,(Sint16)0x00EC,(Sint16)0x0031,(Sint16)0x00FB, + (Sint16)0x0000,(Sint16)0x0100,(Sint16)0xFFCF,(Sint16)0x00FB,(Sint16)0xFF9F,(Sint16)0x00EC,(Sint16)0xFF72,(Sint16)0x00D4, + (Sint16)0xFF4B,(Sint16)0x00B5,(Sint16)0xFF2C,(Sint16)0x008E,(Sint16)0xFF14,(Sint16)0x0061,(Sint16)0xFF05,(Sint16)0x0031, + (Sint16)0xFF00,(Sint16)0x0000,(Sint16)0xFF05,(Sint16)0xFFCF,(Sint16)0xFF14,(Sint16)0xFF9F,(Sint16)0xFF2C,(Sint16)0xFF72, + (Sint16)0xFF4B,(Sint16)0xFF4B,(Sint16)0xFF72,(Sint16)0xFF2C,(Sint16)0xFF9F,(Sint16)0xFF14,(Sint16)0xFFCF,(Sint16)0xFF05, +/*SPEED = 5*/ + (Sint16)0x0000,(Sint16)0xFEC0,(Sint16)0x003E,(Sint16)0xFEC7,(Sint16)0x007A,(Sint16)0xFED9,(Sint16)0x00B1,(Sint16)0xFEF6, + (Sint16)0x00E2,(Sint16)0xFF1E,(Sint16)0x010A,(Sint16)0xFF4F,(Sint16)0x0127,(Sint16)0xFF86,(Sint16)0x0139,(Sint16)0xFFC2, + (Sint16)0x0140,(Sint16)0x0000,(Sint16)0x0139,(Sint16)0x003E,(Sint16)0x0127,(Sint16)0x007A,(Sint16)0x010A,(Sint16)0x00B1, + (Sint16)0x00E2,(Sint16)0x00E2,(Sint16)0x00B1,(Sint16)0x010A,(Sint16)0x007A,(Sint16)0x0127,(Sint16)0x003E,(Sint16)0x0139, + (Sint16)0x0000,(Sint16)0x0140,(Sint16)0xFFC2,(Sint16)0x0139,(Sint16)0xFF86,(Sint16)0x0127,(Sint16)0xFF4F,(Sint16)0x010A, + (Sint16)0xFF1E,(Sint16)0x00E2,(Sint16)0xFEF6,(Sint16)0x00B1,(Sint16)0xFED9,(Sint16)0x007A,(Sint16)0xFEC7,(Sint16)0x003E, + (Sint16)0xFEC0,(Sint16)0x0000,(Sint16)0xFEC7,(Sint16)0xFFC2,(Sint16)0xFED9,(Sint16)0xFF86,(Sint16)0xFEF6,(Sint16)0xFF4F, + (Sint16)0xFF1E,(Sint16)0xFF1E,(Sint16)0xFF4F,(Sint16)0xFEF6,(Sint16)0xFF86,(Sint16)0xFED9,(Sint16)0xFFC2,(Sint16)0xFEC7, +/*SPEED = 6*/ + (Sint16)0x0000,(Sint16)0xFE80,(Sint16)0x004A,(Sint16)0xFE88,(Sint16)0x0092,(Sint16)0xFE9E,(Sint16)0x00D5,(Sint16)0xFEC1, + (Sint16)0x010F,(Sint16)0xFEF1,(Sint16)0x013F,(Sint16)0xFF2B,(Sint16)0x0162,(Sint16)0xFF6E,(Sint16)0x0178,(Sint16)0xFFB6, + (Sint16)0x0180,(Sint16)0x0000,(Sint16)0x0178,(Sint16)0x004A,(Sint16)0x0162,(Sint16)0x0092,(Sint16)0x013F,(Sint16)0x00D5, + (Sint16)0x010F,(Sint16)0x010F,(Sint16)0x00D5,(Sint16)0x013F,(Sint16)0x0092,(Sint16)0x0162,(Sint16)0x004A,(Sint16)0x0178, + (Sint16)0x0000,(Sint16)0x0180,(Sint16)0xFFB6,(Sint16)0x0178,(Sint16)0xFF6E,(Sint16)0x0162,(Sint16)0xFF2B,(Sint16)0x013F, + (Sint16)0xFEF1,(Sint16)0x010F,(Sint16)0xFEC1,(Sint16)0x00D5,(Sint16)0xFE9E,(Sint16)0x0092,(Sint16)0xFE88,(Sint16)0x004A, + (Sint16)0xFE80,(Sint16)0x0000,(Sint16)0xFE88,(Sint16)0xFFB6,(Sint16)0xFE9E,(Sint16)0xFF6E,(Sint16)0xFEC1,(Sint16)0xFF2B, + (Sint16)0xFEF1,(Sint16)0xFEF1,(Sint16)0xFF2B,(Sint16)0xFEC1,(Sint16)0xFF6E,(Sint16)0xFE9E,(Sint16)0xFFB6,(Sint16)0xFE88, +/*SPEED = 7*/ + (Sint16)0x0000,(Sint16)0xFE40,(Sint16)0x0057,(Sint16)0xFE49,(Sint16)0x00AB,(Sint16)0xFE63,(Sint16)0x00F8,(Sint16)0xFE8C, + (Sint16)0x013C,(Sint16)0xFEC4,(Sint16)0x0174,(Sint16)0xFF08,(Sint16)0x019D,(Sint16)0xFF55,(Sint16)0x01B7,(Sint16)0xFFA9, + (Sint16)0x01C0,(Sint16)0x0000,(Sint16)0x01B7,(Sint16)0x0057,(Sint16)0x019D,(Sint16)0x00AB,(Sint16)0x0174,(Sint16)0x00F8, + (Sint16)0x013C,(Sint16)0x013C,(Sint16)0x00F8,(Sint16)0x0174,(Sint16)0x00AB,(Sint16)0x019D,(Sint16)0x0057,(Sint16)0x01B7, + (Sint16)0x0000,(Sint16)0x01C0,(Sint16)0xFFA9,(Sint16)0x01B7,(Sint16)0xFF55,(Sint16)0x019D,(Sint16)0xFF08,(Sint16)0x0174, + (Sint16)0xFEC4,(Sint16)0x013C,(Sint16)0xFE8C,(Sint16)0x00F8,(Sint16)0xFE63,(Sint16)0x00AB,(Sint16)0xFE49,(Sint16)0x0057, + (Sint16)0xFE40,(Sint16)0x0000,(Sint16)0xFE49,(Sint16)0xFFA9,(Sint16)0xFE63,(Sint16)0xFF55,(Sint16)0xFE8C,(Sint16)0xFF08, + (Sint16)0xFEC4,(Sint16)0xFEC4,(Sint16)0xFF08,(Sint16)0xFE8C,(Sint16)0xFF55,(Sint16)0xFE63,(Sint16)0xFFA9,(Sint16)0xFE49, +/*SPEED = 8*/ + (Sint16)0x0000,(Sint16)0xFE00,(Sint16)0x0063,(Sint16)0xFE0A,(Sint16)0x00C3,(Sint16)0xFE27,(Sint16)0x011C,(Sint16)0xFE57, + (Sint16)0x016A,(Sint16)0xFE96,(Sint16)0x01A9,(Sint16)0xFEE4,(Sint16)0x01D9,(Sint16)0xFF3D,(Sint16)0x01F6,(Sint16)0xFF9D, + (Sint16)0x0200,(Sint16)0x0000,(Sint16)0x01F6,(Sint16)0x0063,(Sint16)0x01D9,(Sint16)0x00C3,(Sint16)0x01A9,(Sint16)0x011C, + (Sint16)0x016A,(Sint16)0x016A,(Sint16)0x011C,(Sint16)0x01A9,(Sint16)0x00C3,(Sint16)0x01D9,(Sint16)0x0063,(Sint16)0x01F6, + (Sint16)0x0000,(Sint16)0x0200,(Sint16)0xFF9D,(Sint16)0x01F6,(Sint16)0xFF3D,(Sint16)0x01D9,(Sint16)0xFEE4,(Sint16)0x01A9, + (Sint16)0xFE96,(Sint16)0x016A,(Sint16)0xFE57,(Sint16)0x011C,(Sint16)0xFE27,(Sint16)0x00C3,(Sint16)0xFE0A,(Sint16)0x0063, + (Sint16)0xFE00,(Sint16)0x0000,(Sint16)0xFE0A,(Sint16)0xFF9D,(Sint16)0xFE27,(Sint16)0xFF3D,(Sint16)0xFE57,(Sint16)0xFEE4, + (Sint16)0xFE96,(Sint16)0xFE96,(Sint16)0xFEE4,(Sint16)0xFE57,(Sint16)0xFF3D,(Sint16)0xFE27,(Sint16)0xFF9D,(Sint16)0xFE0A, +/*SPEED = 9*/ + (Sint16)0x0000,(Sint16)0xFDC0,(Sint16)0x0070,(Sint16)0xFDCC,(Sint16)0x00DC,(Sint16)0xFDEC,(Sint16)0x0140,(Sint16)0xFE22, + (Sint16)0x0197,(Sint16)0xFE69,(Sint16)0x01DE,(Sint16)0xFEC0,(Sint16)0x0214,(Sint16)0xFF24,(Sint16)0x0234,(Sint16)0xFF90, + (Sint16)0x0240,(Sint16)0x0000,(Sint16)0x0234,(Sint16)0x0070,(Sint16)0x0214,(Sint16)0x00DC,(Sint16)0x01DE,(Sint16)0x0140, + (Sint16)0x0197,(Sint16)0x0197,(Sint16)0x0140,(Sint16)0x01DE,(Sint16)0x00DC,(Sint16)0x0214,(Sint16)0x0070,(Sint16)0x0234, + (Sint16)0x0000,(Sint16)0x0240,(Sint16)0xFF90,(Sint16)0x0234,(Sint16)0xFF24,(Sint16)0x0214,(Sint16)0xFEC0,(Sint16)0x01DE, + (Sint16)0xFE69,(Sint16)0x0197,(Sint16)0xFE22,(Sint16)0x0140,(Sint16)0xFDEC,(Sint16)0x00DC,(Sint16)0xFDCC,(Sint16)0x0070, + (Sint16)0xFDC0,(Sint16)0x0000,(Sint16)0xFDCC,(Sint16)0xFF90,(Sint16)0xFDEC,(Sint16)0xFF24,(Sint16)0xFE22,(Sint16)0xFEC0, + (Sint16)0xFE69,(Sint16)0xFE69,(Sint16)0xFEC0,(Sint16)0xFE22,(Sint16)0xFF24,(Sint16)0xFDEC,(Sint16)0xFF90,(Sint16)0xFDCC, +/*SPEED = 10*/ + (Sint16)0x0000,(Sint16)0xFD80,(Sint16)0x007C,(Sint16)0xFD8D,(Sint16)0x00F4,(Sint16)0xFDB1,(Sint16)0x0163,(Sint16)0xFDEC, + (Sint16)0x01C4,(Sint16)0xFE3C,(Sint16)0x0214,(Sint16)0xFE9D,(Sint16)0x024F,(Sint16)0xFF0C,(Sint16)0x0273,(Sint16)0xFF84, + (Sint16)0x0280,(Sint16)0x0000,(Sint16)0x0273,(Sint16)0x007C,(Sint16)0x024F,(Sint16)0x00F4,(Sint16)0x0214,(Sint16)0x0163, + (Sint16)0x01C4,(Sint16)0x01C4,(Sint16)0x0163,(Sint16)0x0214,(Sint16)0x00F4,(Sint16)0x024F,(Sint16)0x007C,(Sint16)0x0273, + (Sint16)0x0000,(Sint16)0x0280,(Sint16)0xFF84,(Sint16)0x0273,(Sint16)0xFF0C,(Sint16)0x024F,(Sint16)0xFE9D,(Sint16)0x0214, + (Sint16)0xFE3C,(Sint16)0x01C4,(Sint16)0xFDEC,(Sint16)0x0163,(Sint16)0xFDB1,(Sint16)0x00F4,(Sint16)0xFD8D,(Sint16)0x007C, + (Sint16)0xFD80,(Sint16)0x0000,(Sint16)0xFD8D,(Sint16)0xFF84,(Sint16)0xFDB1,(Sint16)0xFF0C,(Sint16)0xFDEC,(Sint16)0xFE9D, + (Sint16)0xFE3C,(Sint16)0xFE3C,(Sint16)0xFE9D,(Sint16)0xFDEC,(Sint16)0xFF0C,(Sint16)0xFDB1,(Sint16)0xFF84,(Sint16)0xFD8D, +/*SPEED = 11*/ + (Sint16)0x0000,(Sint16)0xFD40,(Sint16)0x0089,(Sint16)0xFD4E,(Sint16)0x010D,(Sint16)0xFD76,(Sint16)0x0187,(Sint16)0xFDB7, + (Sint16)0x01F1,(Sint16)0xFE0F,(Sint16)0x0249,(Sint16)0xFE79,(Sint16)0x028A,(Sint16)0xFEF3,(Sint16)0x02B2,(Sint16)0xFF77, + (Sint16)0x02C0,(Sint16)0x0000,(Sint16)0x02B2,(Sint16)0x0089,(Sint16)0x028A,(Sint16)0x010D,(Sint16)0x0249,(Sint16)0x0187, + (Sint16)0x01F1,(Sint16)0x01F1,(Sint16)0x0187,(Sint16)0x0249,(Sint16)0x010D,(Sint16)0x028A,(Sint16)0x0089,(Sint16)0x02B2, + (Sint16)0x0000,(Sint16)0x02C0,(Sint16)0xFF77,(Sint16)0x02B2,(Sint16)0xFEF3,(Sint16)0x028A,(Sint16)0xFE79,(Sint16)0x0249, + (Sint16)0xFE0F,(Sint16)0x01F1,(Sint16)0xFDB7,(Sint16)0x0187,(Sint16)0xFD76,(Sint16)0x010D,(Sint16)0xFD4E,(Sint16)0x0089, + (Sint16)0xFD40,(Sint16)0x0000,(Sint16)0xFD4E,(Sint16)0xFF77,(Sint16)0xFD76,(Sint16)0xFEF3,(Sint16)0xFDB7,(Sint16)0xFE79, + (Sint16)0xFE0F,(Sint16)0xFE0F,(Sint16)0xFE79,(Sint16)0xFDB7,(Sint16)0xFEF3,(Sint16)0xFD76,(Sint16)0xFF77,(Sint16)0xFD4E, +/*SPEED = 12*/ + (Sint16)0x0000,(Sint16)0xFD00,(Sint16)0x0095,(Sint16)0xFD0F,(Sint16)0x0125,(Sint16)0xFD3B,(Sint16)0x01AA,(Sint16)0xFD82, + (Sint16)0x021F,(Sint16)0xFDE1,(Sint16)0x027E,(Sint16)0xFE56,(Sint16)0x02C5,(Sint16)0xFEDB,(Sint16)0x02F1,(Sint16)0xFF6B, + (Sint16)0x0300,(Sint16)0x0000,(Sint16)0x02F1,(Sint16)0x0095,(Sint16)0x02C5,(Sint16)0x0125,(Sint16)0x027E,(Sint16)0x01AA, + (Sint16)0x021F,(Sint16)0x021F,(Sint16)0x01AA,(Sint16)0x027E,(Sint16)0x0125,(Sint16)0x02C5,(Sint16)0x0095,(Sint16)0x02F1, + (Sint16)0x0000,(Sint16)0x0300,(Sint16)0xFF6B,(Sint16)0x02F1,(Sint16)0xFEDB,(Sint16)0x02C5,(Sint16)0xFE56,(Sint16)0x027E, + (Sint16)0xFDE1,(Sint16)0x021F,(Sint16)0xFD82,(Sint16)0x01AA,(Sint16)0xFD3B,(Sint16)0x0125,(Sint16)0xFD0F,(Sint16)0x0095, + (Sint16)0xFD00,(Sint16)0x0000,(Sint16)0xFD0F,(Sint16)0xFF6B,(Sint16)0xFD3B,(Sint16)0xFEDB,(Sint16)0xFD82,(Sint16)0xFE56, + (Sint16)0xFDE1,(Sint16)0xFDE1,(Sint16)0xFE56,(Sint16)0xFD82,(Sint16)0xFEDB,(Sint16)0xFD3B,(Sint16)0xFF6B,(Sint16)0xFD0F, +/*SPEED = 13*/ + (Sint16)0x0000,(Sint16)0xFCC0,(Sint16)0x00A2,(Sint16)0xFCD0,(Sint16)0x013E,(Sint16)0xFD00,(Sint16)0x01CE,(Sint16)0xFD4D, + (Sint16)0x024C,(Sint16)0xFDB4,(Sint16)0x02B3,(Sint16)0xFE32,(Sint16)0x0300,(Sint16)0xFEC2,(Sint16)0x0330,(Sint16)0xFF5E, + (Sint16)0x0340,(Sint16)0x0000,(Sint16)0x0330,(Sint16)0x00A2,(Sint16)0x0300,(Sint16)0x013E,(Sint16)0x02B3,(Sint16)0x01CE, + (Sint16)0x024C,(Sint16)0x024C,(Sint16)0x01CE,(Sint16)0x02B3,(Sint16)0x013E,(Sint16)0x0300,(Sint16)0x00A2,(Sint16)0x0330, + (Sint16)0x0000,(Sint16)0x0340,(Sint16)0xFF5E,(Sint16)0x0330,(Sint16)0xFEC2,(Sint16)0x0300,(Sint16)0xFE32,(Sint16)0x02B3, + (Sint16)0xFDB4,(Sint16)0x024C,(Sint16)0xFD4D,(Sint16)0x01CE,(Sint16)0xFD00,(Sint16)0x013E,(Sint16)0xFCD0,(Sint16)0x00A2, + (Sint16)0xFCC0,(Sint16)0x0000,(Sint16)0xFCD0,(Sint16)0xFF5E,(Sint16)0xFD00,(Sint16)0xFEC2,(Sint16)0xFD4D,(Sint16)0xFE32, + (Sint16)0xFDB4,(Sint16)0xFDB4,(Sint16)0xFE32,(Sint16)0xFD4D,(Sint16)0xFEC2,(Sint16)0xFD00,(Sint16)0xFF5E,(Sint16)0xFCD0, +/*SPEED = 14*/ + (Sint16)0x0000,(Sint16)0xFC80,(Sint16)0x00AE,(Sint16)0xFC92,(Sint16)0x0156,(Sint16)0xFCC5,(Sint16)0x01F1,(Sint16)0xFD18, + (Sint16)0x0279,(Sint16)0xFD87,(Sint16)0x02E8,(Sint16)0xFE0F,(Sint16)0x033B,(Sint16)0xFEAA,(Sint16)0x036E,(Sint16)0xFF52, + (Sint16)0x0380,(Sint16)0x0000,(Sint16)0x036E,(Sint16)0x00AE,(Sint16)0x033B,(Sint16)0x0156,(Sint16)0x02E8,(Sint16)0x01F1, + (Sint16)0x0279,(Sint16)0x0279,(Sint16)0x01F1,(Sint16)0x02E8,(Sint16)0x0156,(Sint16)0x033B,(Sint16)0x00AE,(Sint16)0x036E, + (Sint16)0x0000,(Sint16)0x0380,(Sint16)0xFF52,(Sint16)0x036E,(Sint16)0xFEAA,(Sint16)0x033B,(Sint16)0xFE0F,(Sint16)0x02E8, + (Sint16)0xFD87,(Sint16)0x0279,(Sint16)0xFD18,(Sint16)0x01F1,(Sint16)0xFCC5,(Sint16)0x0156,(Sint16)0xFC92,(Sint16)0x00AE, + (Sint16)0xFC80,(Sint16)0x0000,(Sint16)0xFC92,(Sint16)0xFF52,(Sint16)0xFCC5,(Sint16)0xFEAA,(Sint16)0xFD18,(Sint16)0xFE0F, + (Sint16)0xFD87,(Sint16)0xFD87,(Sint16)0xFE0F,(Sint16)0xFD18,(Sint16)0xFEAA,(Sint16)0xFCC5,(Sint16)0xFF52,(Sint16)0xFC92, +/*SPEED = 15*/ + (Sint16)0x0000,(Sint16)0xFC40,(Sint16)0x00BB,(Sint16)0xFC53,(Sint16)0x016F,(Sint16)0xFC8A,(Sint16)0x0215,(Sint16)0xFCE2, + (Sint16)0x02A6,(Sint16)0xFD5A,(Sint16)0x031E,(Sint16)0xFDEB,(Sint16)0x0376,(Sint16)0xFE91,(Sint16)0x03AD,(Sint16)0xFF45, + (Sint16)0x03C0,(Sint16)0x0000,(Sint16)0x03AD,(Sint16)0x00BB,(Sint16)0x0376,(Sint16)0x016F,(Sint16)0x031E,(Sint16)0x0215, + (Sint16)0x02A6,(Sint16)0x02A6,(Sint16)0x0215,(Sint16)0x031E,(Sint16)0x016F,(Sint16)0x0376,(Sint16)0x00BB,(Sint16)0x03AD, + (Sint16)0x0000,(Sint16)0x03C0,(Sint16)0xFF45,(Sint16)0x03AD,(Sint16)0xFE91,(Sint16)0x0376,(Sint16)0xFDEB,(Sint16)0x031E, + (Sint16)0xFD5A,(Sint16)0x02A6,(Sint16)0xFCE2,(Sint16)0x0215,(Sint16)0xFC8A,(Sint16)0x016F,(Sint16)0xFC53,(Sint16)0x00BB, + (Sint16)0xFC40,(Sint16)0x0000,(Sint16)0xFC53,(Sint16)0xFF45,(Sint16)0xFC8A,(Sint16)0xFE91,(Sint16)0xFCE2,(Sint16)0xFDEB, + (Sint16)0xFD5A,(Sint16)0xFD5A,(Sint16)0xFDEB,(Sint16)0xFCE2,(Sint16)0xFE91,(Sint16)0xFC8A,(Sint16)0xFF45,(Sint16)0xFC53, +/*SPEED = 16*/ + (Sint16)0x0000,(Sint16)0xFC00,(Sint16)0x00C7,(Sint16)0xFC14,(Sint16)0x0187,(Sint16)0xFC4E,(Sint16)0x0238,(Sint16)0xFCAD, + (Sint16)0x02D4,(Sint16)0xFD2C,(Sint16)0x0353,(Sint16)0xFDC8,(Sint16)0x03B2,(Sint16)0xFE79,(Sint16)0x03EC,(Sint16)0xFF39, + (Sint16)0x0400,(Sint16)0x0000,(Sint16)0x03EC,(Sint16)0x00C7,(Sint16)0x03B2,(Sint16)0x0187,(Sint16)0x0353,(Sint16)0x0238, + (Sint16)0x02D4,(Sint16)0x02D4,(Sint16)0x0238,(Sint16)0x0353,(Sint16)0x0187,(Sint16)0x03B2,(Sint16)0x00C7,(Sint16)0x03EC, + (Sint16)0x0000,(Sint16)0x0400,(Sint16)0xFF39,(Sint16)0x03EC,(Sint16)0xFE79,(Sint16)0x03B2,(Sint16)0xFDC8,(Sint16)0x0353, + (Sint16)0xFD2C,(Sint16)0x02D4,(Sint16)0xFCAD,(Sint16)0x0238,(Sint16)0xFC4E,(Sint16)0x0187,(Sint16)0xFC14,(Sint16)0x00C7, + (Sint16)0xFC00,(Sint16)0x0000,(Sint16)0xFC14,(Sint16)0xFF39,(Sint16)0xFC4E,(Sint16)0xFE79,(Sint16)0xFCAD,(Sint16)0xFDC8, + (Sint16)0xFD2C,(Sint16)0xFD2C,(Sint16)0xFDC8,(Sint16)0xFCAD,(Sint16)0xFE79,(Sint16)0xFC4E,(Sint16)0xFF39,(Sint16)0xFC14, +/*SPEED = 17*/ + (Sint16)0x0000,(Sint16)0xFBC0,(Sint16)0x00D4,(Sint16)0xFBD5,(Sint16)0x01A0,(Sint16)0xFC13,(Sint16)0x025C,(Sint16)0xFC78, + (Sint16)0x0301,(Sint16)0xFCFF,(Sint16)0x0388,(Sint16)0xFDA4,(Sint16)0x03ED,(Sint16)0xFE60,(Sint16)0x042B,(Sint16)0xFF2C, + (Sint16)0x0440,(Sint16)0x0000,(Sint16)0x042B,(Sint16)0x00D4,(Sint16)0x03ED,(Sint16)0x01A0,(Sint16)0x0388,(Sint16)0x025C, + (Sint16)0x0301,(Sint16)0x0301,(Sint16)0x025C,(Sint16)0x0388,(Sint16)0x01A0,(Sint16)0x03ED,(Sint16)0x00D4,(Sint16)0x042B, + (Sint16)0x0000,(Sint16)0x0440,(Sint16)0xFF2C,(Sint16)0x042B,(Sint16)0xFE60,(Sint16)0x03ED,(Sint16)0xFDA4,(Sint16)0x0388, + (Sint16)0xFCFF,(Sint16)0x0301,(Sint16)0xFC78,(Sint16)0x025C,(Sint16)0xFC13,(Sint16)0x01A0,(Sint16)0xFBD5,(Sint16)0x00D4, + (Sint16)0xFBC0,(Sint16)0x0000,(Sint16)0xFBD5,(Sint16)0xFF2C,(Sint16)0xFC13,(Sint16)0xFE60,(Sint16)0xFC78,(Sint16)0xFDA4, + (Sint16)0xFCFF,(Sint16)0xFCFF,(Sint16)0xFDA4,(Sint16)0xFC78,(Sint16)0xFE60,(Sint16)0xFC13,(Sint16)0xFF2C,(Sint16)0xFBD5, +/*SPEED = 18*/ + (Sint16)0x0000,(Sint16)0xFB80,(Sint16)0x00E0,(Sint16)0xFB97,(Sint16)0x01B8,(Sint16)0xFBD8,(Sint16)0x0280,(Sint16)0xFC43, + (Sint16)0x032E,(Sint16)0xFCD2,(Sint16)0x03BD,(Sint16)0xFD80,(Sint16)0x0428,(Sint16)0xFE48,(Sint16)0x0469,(Sint16)0xFF20, + (Sint16)0x0480,(Sint16)0x0000,(Sint16)0x0469,(Sint16)0x00E0,(Sint16)0x0428,(Sint16)0x01B8,(Sint16)0x03BD,(Sint16)0x0280, + (Sint16)0x032E,(Sint16)0x032E,(Sint16)0x0280,(Sint16)0x03BD,(Sint16)0x01B8,(Sint16)0x0428,(Sint16)0x00E0,(Sint16)0x0469, + (Sint16)0x0000,(Sint16)0x0480,(Sint16)0xFF20,(Sint16)0x0469,(Sint16)0xFE48,(Sint16)0x0428,(Sint16)0xFD80,(Sint16)0x03BD, + (Sint16)0xFCD2,(Sint16)0x032E,(Sint16)0xFC43,(Sint16)0x0280,(Sint16)0xFBD8,(Sint16)0x01B8,(Sint16)0xFB97,(Sint16)0x00E0, + (Sint16)0xFB80,(Sint16)0x0000,(Sint16)0xFB97,(Sint16)0xFF20,(Sint16)0xFBD8,(Sint16)0xFE48,(Sint16)0xFC43,(Sint16)0xFD80, + (Sint16)0xFCD2,(Sint16)0xFCD2,(Sint16)0xFD80,(Sint16)0xFC43,(Sint16)0xFE48,(Sint16)0xFBD8,(Sint16)0xFF20,(Sint16)0xFB97, +/*SPEED = 19*/ + (Sint16)0x0000,(Sint16)0xFB40,(Sint16)0x00ED,(Sint16)0xFB58,(Sint16)0x01D1,(Sint16)0xFB9D,(Sint16)0x02A3,(Sint16)0xFC0D, + (Sint16)0x035B,(Sint16)0xFCA5,(Sint16)0x03F3,(Sint16)0xFD5D,(Sint16)0x0463,(Sint16)0xFE2F,(Sint16)0x04A8,(Sint16)0xFF13, + (Sint16)0x04C0,(Sint16)0x0000,(Sint16)0x04A8,(Sint16)0x00ED,(Sint16)0x0463,(Sint16)0x01D1,(Sint16)0x03F3,(Sint16)0x02A3, + (Sint16)0x035B,(Sint16)0x035B,(Sint16)0x02A3,(Sint16)0x03F3,(Sint16)0x01D1,(Sint16)0x0463,(Sint16)0x00ED,(Sint16)0x04A8, + (Sint16)0x0000,(Sint16)0x04C0,(Sint16)0xFF13,(Sint16)0x04A8,(Sint16)0xFE2F,(Sint16)0x0463,(Sint16)0xFD5D,(Sint16)0x03F3, + (Sint16)0xFCA5,(Sint16)0x035B,(Sint16)0xFC0D,(Sint16)0x02A3,(Sint16)0xFB9D,(Sint16)0x01D1,(Sint16)0xFB58,(Sint16)0x00ED, + (Sint16)0xFB40,(Sint16)0x0000,(Sint16)0xFB58,(Sint16)0xFF13,(Sint16)0xFB9D,(Sint16)0xFE2F,(Sint16)0xFC0D,(Sint16)0xFD5D, + (Sint16)0xFCA5,(Sint16)0xFCA5,(Sint16)0xFD5D,(Sint16)0xFC0D,(Sint16)0xFE2F,(Sint16)0xFB9D,(Sint16)0xFF13,(Sint16)0xFB58, +/*SPEED = 20*/ + (Sint16)0x0000,(Sint16)0xFB00,(Sint16)0x00F9,(Sint16)0xFB19,(Sint16)0x01E9,(Sint16)0xFB62,(Sint16)0x02C7,(Sint16)0xFBD8, + (Sint16)0x0389,(Sint16)0xFC77,(Sint16)0x0428,(Sint16)0xFD39,(Sint16)0x049E,(Sint16)0xFE17,(Sint16)0x04E7,(Sint16)0xFF07, + (Sint16)0x0500,(Sint16)0x0000,(Sint16)0x04E7,(Sint16)0x00F9,(Sint16)0x049E,(Sint16)0x01E9,(Sint16)0x0428,(Sint16)0x02C7, + (Sint16)0x0389,(Sint16)0x0389,(Sint16)0x02C7,(Sint16)0x0428,(Sint16)0x01E9,(Sint16)0x049E,(Sint16)0x00F9,(Sint16)0x04E7, + (Sint16)0x0000,(Sint16)0x0500,(Sint16)0xFF07,(Sint16)0x04E7,(Sint16)0xFE17,(Sint16)0x049E,(Sint16)0xFD39,(Sint16)0x0428, + (Sint16)0xFC77,(Sint16)0x0389,(Sint16)0xFBD8,(Sint16)0x02C7,(Sint16)0xFB62,(Sint16)0x01E9,(Sint16)0xFB19,(Sint16)0x00F9, + (Sint16)0xFB00,(Sint16)0x0000,(Sint16)0xFB19,(Sint16)0xFF07,(Sint16)0xFB62,(Sint16)0xFE17,(Sint16)0xFBD8,(Sint16)0xFD39, + (Sint16)0xFC77,(Sint16)0xFC77,(Sint16)0xFD39,(Sint16)0xFBD8,(Sint16)0xFE17,(Sint16)0xFB62,(Sint16)0xFF07,(Sint16)0xFB19, +/*SPEED = 21*/ + (Sint16)0x0000,(Sint16)0xFAC0,(Sint16)0x0106,(Sint16)0xFADA,(Sint16)0x0202,(Sint16)0xFB27,(Sint16)0x02EA,(Sint16)0xFBA3, + (Sint16)0x03B6,(Sint16)0xFC4A,(Sint16)0x045D,(Sint16)0xFD16,(Sint16)0x04D9,(Sint16)0xFDFE,(Sint16)0x0526,(Sint16)0xFEFA, + (Sint16)0x0540,(Sint16)0x0000,(Sint16)0x0526,(Sint16)0x0106,(Sint16)0x04D9,(Sint16)0x0202,(Sint16)0x045D,(Sint16)0x02EA, + (Sint16)0x03B6,(Sint16)0x03B6,(Sint16)0x02EA,(Sint16)0x045D,(Sint16)0x0202,(Sint16)0x04D9,(Sint16)0x0106,(Sint16)0x0526, + (Sint16)0x0000,(Sint16)0x0540,(Sint16)0xFEFA,(Sint16)0x0526,(Sint16)0xFDFE,(Sint16)0x04D9,(Sint16)0xFD16,(Sint16)0x045D, + (Sint16)0xFC4A,(Sint16)0x03B6,(Sint16)0xFBA3,(Sint16)0x02EA,(Sint16)0xFB27,(Sint16)0x0202,(Sint16)0xFADA,(Sint16)0x0106, + (Sint16)0xFAC0,(Sint16)0x0000,(Sint16)0xFADA,(Sint16)0xFEFA,(Sint16)0xFB27,(Sint16)0xFDFE,(Sint16)0xFBA3,(Sint16)0xFD16, + (Sint16)0xFC4A,(Sint16)0xFC4A,(Sint16)0xFD16,(Sint16)0xFBA3,(Sint16)0xFDFE,(Sint16)0xFB27,(Sint16)0xFEFA,(Sint16)0xFADA, +/*SPEED = 22*/ + (Sint16)0x0000,(Sint16)0xFA80,(Sint16)0x0112,(Sint16)0xFA9C,(Sint16)0x021A,(Sint16)0xFAEC,(Sint16)0x030E,(Sint16)0xFB6E, + (Sint16)0x03E3,(Sint16)0xFC1D,(Sint16)0x0492,(Sint16)0xFCF2,(Sint16)0x0514,(Sint16)0xFDE6,(Sint16)0x0564,(Sint16)0xFEEE, + (Sint16)0x0580,(Sint16)0x0000,(Sint16)0x0564,(Sint16)0x0112,(Sint16)0x0514,(Sint16)0x021A,(Sint16)0x0492,(Sint16)0x030E, + (Sint16)0x03E3,(Sint16)0x03E3,(Sint16)0x030E,(Sint16)0x0492,(Sint16)0x021A,(Sint16)0x0514,(Sint16)0x0112,(Sint16)0x0564, + (Sint16)0x0000,(Sint16)0x0580,(Sint16)0xFEEE,(Sint16)0x0564,(Sint16)0xFDE6,(Sint16)0x0514,(Sint16)0xFCF2,(Sint16)0x0492, + (Sint16)0xFC1D,(Sint16)0x03E3,(Sint16)0xFB6E,(Sint16)0x030E,(Sint16)0xFAEC,(Sint16)0x021A,(Sint16)0xFA9C,(Sint16)0x0112, + (Sint16)0xFA80,(Sint16)0x0000,(Sint16)0xFA9C,(Sint16)0xFEEE,(Sint16)0xFAEC,(Sint16)0xFDE6,(Sint16)0xFB6E,(Sint16)0xFCF2, + (Sint16)0xFC1D,(Sint16)0xFC1D,(Sint16)0xFCF2,(Sint16)0xFB6E,(Sint16)0xFDE6,(Sint16)0xFAEC,(Sint16)0xFEEE,(Sint16)0xFA9C, +/*SPEED = 23*/ + (Sint16)0x0000,(Sint16)0xFA40,(Sint16)0x011F,(Sint16)0xFA5D,(Sint16)0x0233,(Sint16)0xFAB1,(Sint16)0x0331,(Sint16)0xFB39, + (Sint16)0x0410,(Sint16)0xFBF0,(Sint16)0x04C7,(Sint16)0xFCCF,(Sint16)0x054F,(Sint16)0xFDCD,(Sint16)0x05A3,(Sint16)0xFEE1, + (Sint16)0x05C0,(Sint16)0x0000,(Sint16)0x05A3,(Sint16)0x011F,(Sint16)0x054F,(Sint16)0x0233,(Sint16)0x04C7,(Sint16)0x0331, + (Sint16)0x0410,(Sint16)0x0410,(Sint16)0x0331,(Sint16)0x04C7,(Sint16)0x0233,(Sint16)0x054F,(Sint16)0x011F,(Sint16)0x05A3, + (Sint16)0x0000,(Sint16)0x05C0,(Sint16)0xFEE1,(Sint16)0x05A3,(Sint16)0xFDCD,(Sint16)0x054F,(Sint16)0xFCCF,(Sint16)0x04C7, + (Sint16)0xFBF0,(Sint16)0x0410,(Sint16)0xFB39,(Sint16)0x0331,(Sint16)0xFAB1,(Sint16)0x0233,(Sint16)0xFA5D,(Sint16)0x011F, + (Sint16)0xFA40,(Sint16)0x0000,(Sint16)0xFA5D,(Sint16)0xFEE1,(Sint16)0xFAB1,(Sint16)0xFDCD,(Sint16)0xFB39,(Sint16)0xFCCF, + (Sint16)0xFBF0,(Sint16)0xFBF0,(Sint16)0xFCCF,(Sint16)0xFB39,(Sint16)0xFDCD,(Sint16)0xFAB1,(Sint16)0xFEE1,(Sint16)0xFA5D, +/*SPEED = 24*/ + (Sint16)0x0000,(Sint16)0xFA00,(Sint16)0x012B,(Sint16)0xFA1E,(Sint16)0x024B,(Sint16)0xFA75,(Sint16)0x0355,(Sint16)0xFB03, + (Sint16)0x043E,(Sint16)0xFBC2,(Sint16)0x04FD,(Sint16)0xFCAB,(Sint16)0x058B,(Sint16)0xFDB5,(Sint16)0x05E2,(Sint16)0xFED5, + (Sint16)0x0600,(Sint16)0x0000,(Sint16)0x05E2,(Sint16)0x012B,(Sint16)0x058B,(Sint16)0x024B,(Sint16)0x04FD,(Sint16)0x0355, + (Sint16)0x043E,(Sint16)0x043E,(Sint16)0x0355,(Sint16)0x04FD,(Sint16)0x024B,(Sint16)0x058B,(Sint16)0x012B,(Sint16)0x05E2, + (Sint16)0x0000,(Sint16)0x0600,(Sint16)0xFED5,(Sint16)0x05E2,(Sint16)0xFDB5,(Sint16)0x058B,(Sint16)0xFCAB,(Sint16)0x04FD, + (Sint16)0xFBC2,(Sint16)0x043E,(Sint16)0xFB03,(Sint16)0x0355,(Sint16)0xFA75,(Sint16)0x024B,(Sint16)0xFA1E,(Sint16)0x012B, + (Sint16)0xFA00,(Sint16)0x0000,(Sint16)0xFA1E,(Sint16)0xFED5,(Sint16)0xFA75,(Sint16)0xFDB5,(Sint16)0xFB03,(Sint16)0xFCAB, + (Sint16)0xFBC2,(Sint16)0xFBC2,(Sint16)0xFCAB,(Sint16)0xFB03,(Sint16)0xFDB5,(Sint16)0xFA75,(Sint16)0xFED5,(Sint16)0xFA1E, +/*SPEED = 25*/ + (Sint16)0x0000,(Sint16)0xF9C0,(Sint16)0x0138,(Sint16)0xF9DF,(Sint16)0x0264,(Sint16)0xFA3A,(Sint16)0x0378,(Sint16)0xFACE, + (Sint16)0x046B,(Sint16)0xFB95,(Sint16)0x0532,(Sint16)0xFC88,(Sint16)0x05C6,(Sint16)0xFD9C,(Sint16)0x0621,(Sint16)0xFEC8, + (Sint16)0x0640,(Sint16)0x0000,(Sint16)0x0621,(Sint16)0x0138,(Sint16)0x05C6,(Sint16)0x0264,(Sint16)0x0532,(Sint16)0x0378, + (Sint16)0x046B,(Sint16)0x046B,(Sint16)0x0378,(Sint16)0x0532,(Sint16)0x0264,(Sint16)0x05C6,(Sint16)0x0138,(Sint16)0x0621, + (Sint16)0x0000,(Sint16)0x0640,(Sint16)0xFEC8,(Sint16)0x0621,(Sint16)0xFD9C,(Sint16)0x05C6,(Sint16)0xFC88,(Sint16)0x0532, + (Sint16)0xFB95,(Sint16)0x046B,(Sint16)0xFACE,(Sint16)0x0378,(Sint16)0xFA3A,(Sint16)0x0264,(Sint16)0xF9DF,(Sint16)0x0138, + (Sint16)0xF9C0,(Sint16)0x0000,(Sint16)0xF9DF,(Sint16)0xFEC8,(Sint16)0xFA3A,(Sint16)0xFD9C,(Sint16)0xFACE,(Sint16)0xFC88, + (Sint16)0xFB95,(Sint16)0xFB95,(Sint16)0xFC88,(Sint16)0xFACE,(Sint16)0xFD9C,(Sint16)0xFA3A,(Sint16)0xFEC8,(Sint16)0xF9DF, +/*SPEED = 26*/ + (Sint16)0x0000,(Sint16)0xF980,(Sint16)0x0144,(Sint16)0xF9A0,(Sint16)0x027C,(Sint16)0xF9FF,(Sint16)0x039C,(Sint16)0xFA99, + (Sint16)0x0498,(Sint16)0xFB68,(Sint16)0x0567,(Sint16)0xFC64,(Sint16)0x0601,(Sint16)0xFD84,(Sint16)0x0660,(Sint16)0xFEBC, + (Sint16)0x0680,(Sint16)0x0000,(Sint16)0x0660,(Sint16)0x0144,(Sint16)0x0601,(Sint16)0x027C,(Sint16)0x0567,(Sint16)0x039C, + (Sint16)0x0498,(Sint16)0x0498,(Sint16)0x039C,(Sint16)0x0567,(Sint16)0x027C,(Sint16)0x0601,(Sint16)0x0144,(Sint16)0x0660, + (Sint16)0x0000,(Sint16)0x0680,(Sint16)0xFEBC,(Sint16)0x0660,(Sint16)0xFD84,(Sint16)0x0601,(Sint16)0xFC64,(Sint16)0x0567, + (Sint16)0xFB68,(Sint16)0x0498,(Sint16)0xFA99,(Sint16)0x039C,(Sint16)0xF9FF,(Sint16)0x027C,(Sint16)0xF9A0,(Sint16)0x0144, + (Sint16)0xF980,(Sint16)0x0000,(Sint16)0xF9A0,(Sint16)0xFEBC,(Sint16)0xF9FF,(Sint16)0xFD84,(Sint16)0xFA99,(Sint16)0xFC64, + (Sint16)0xFB68,(Sint16)0xFB68,(Sint16)0xFC64,(Sint16)0xFA99,(Sint16)0xFD84,(Sint16)0xF9FF,(Sint16)0xFEBC,(Sint16)0xF9A0, +/*SPEED = 27*/ + (Sint16)0x0000,(Sint16)0xF940,(Sint16)0x0151,(Sint16)0xF962,(Sint16)0x0295,(Sint16)0xF9C4,(Sint16)0x03C0,(Sint16)0xFA64, + (Sint16)0x04C5,(Sint16)0xFB3B,(Sint16)0x059C,(Sint16)0xFC40,(Sint16)0x063C,(Sint16)0xFD6B,(Sint16)0x069E,(Sint16)0xFEAF, + (Sint16)0x06C0,(Sint16)0x0000,(Sint16)0x069E,(Sint16)0x0151,(Sint16)0x063C,(Sint16)0x0295,(Sint16)0x059C,(Sint16)0x03C0, + (Sint16)0x04C5,(Sint16)0x04C5,(Sint16)0x03C0,(Sint16)0x059C,(Sint16)0x0295,(Sint16)0x063C,(Sint16)0x0151,(Sint16)0x069E, + (Sint16)0x0000,(Sint16)0x06C0,(Sint16)0xFEAF,(Sint16)0x069E,(Sint16)0xFD6B,(Sint16)0x063C,(Sint16)0xFC40,(Sint16)0x059C, + (Sint16)0xFB3B,(Sint16)0x04C5,(Sint16)0xFA64,(Sint16)0x03C0,(Sint16)0xF9C4,(Sint16)0x0295,(Sint16)0xF962,(Sint16)0x0151, + (Sint16)0xF940,(Sint16)0x0000,(Sint16)0xF962,(Sint16)0xFEAF,(Sint16)0xF9C4,(Sint16)0xFD6B,(Sint16)0xFA64,(Sint16)0xFC40, + (Sint16)0xFB3B,(Sint16)0xFB3B,(Sint16)0xFC40,(Sint16)0xFA64,(Sint16)0xFD6B,(Sint16)0xF9C4,(Sint16)0xFEAF,(Sint16)0xF962, +/*SPEED = 28*/ + (Sint16)0x0000,(Sint16)0xF900,(Sint16)0x015D,(Sint16)0xF923,(Sint16)0x02AD,(Sint16)0xF989,(Sint16)0x03E3,(Sint16)0xFA2F, + (Sint16)0x04F3,(Sint16)0xFB0D,(Sint16)0x05D1,(Sint16)0xFC1D,(Sint16)0x0677,(Sint16)0xFD53,(Sint16)0x06DD,(Sint16)0xFEA3, + (Sint16)0x0700,(Sint16)0x0000,(Sint16)0x06DD,(Sint16)0x015D,(Sint16)0x0677,(Sint16)0x02AD,(Sint16)0x05D1,(Sint16)0x03E3, + (Sint16)0x04F3,(Sint16)0x04F3,(Sint16)0x03E3,(Sint16)0x05D1,(Sint16)0x02AD,(Sint16)0x0677,(Sint16)0x015D,(Sint16)0x06DD, + (Sint16)0x0000,(Sint16)0x0700,(Sint16)0xFEA3,(Sint16)0x06DD,(Sint16)0xFD53,(Sint16)0x0677,(Sint16)0xFC1D,(Sint16)0x05D1, + (Sint16)0xFB0D,(Sint16)0x04F3,(Sint16)0xFA2F,(Sint16)0x03E3,(Sint16)0xF989,(Sint16)0x02AD,(Sint16)0xF923,(Sint16)0x015D, + (Sint16)0xF900,(Sint16)0x0000,(Sint16)0xF923,(Sint16)0xFEA3,(Sint16)0xF989,(Sint16)0xFD53,(Sint16)0xFA2F,(Sint16)0xFC1D, + (Sint16)0xFB0D,(Sint16)0xFB0D,(Sint16)0xFC1D,(Sint16)0xFA2F,(Sint16)0xFD53,(Sint16)0xF989,(Sint16)0xFEA3,(Sint16)0xF923, +/*SPEED = 29*/ + (Sint16)0x0000,(Sint16)0xF8C0,(Sint16)0x016A,(Sint16)0xF8E4,(Sint16)0x02C6,(Sint16)0xF94E,(Sint16)0x0407,(Sint16)0xF9F9, + (Sint16)0x0520,(Sint16)0xFAE0,(Sint16)0x0607,(Sint16)0xFBF9,(Sint16)0x06B2,(Sint16)0xFD3A,(Sint16)0x071C,(Sint16)0xFE96, + (Sint16)0x0740,(Sint16)0x0000,(Sint16)0x071C,(Sint16)0x016A,(Sint16)0x06B2,(Sint16)0x02C6,(Sint16)0x0607,(Sint16)0x0407, + (Sint16)0x0520,(Sint16)0x0520,(Sint16)0x0407,(Sint16)0x0607,(Sint16)0x02C6,(Sint16)0x06B2,(Sint16)0x016A,(Sint16)0x071C, + (Sint16)0x0000,(Sint16)0x0740,(Sint16)0xFE96,(Sint16)0x071C,(Sint16)0xFD3A,(Sint16)0x06B2,(Sint16)0xFBF9,(Sint16)0x0607, + (Sint16)0xFAE0,(Sint16)0x0520,(Sint16)0xF9F9,(Sint16)0x0407,(Sint16)0xF94E,(Sint16)0x02C6,(Sint16)0xF8E4,(Sint16)0x016A, + (Sint16)0xF8C0,(Sint16)0x0000,(Sint16)0xF8E4,(Sint16)0xFE96,(Sint16)0xF94E,(Sint16)0xFD3A,(Sint16)0xF9F9,(Sint16)0xFBF9, + (Sint16)0xFAE0,(Sint16)0xFAE0,(Sint16)0xFBF9,(Sint16)0xF9F9,(Sint16)0xFD3A,(Sint16)0xF94E,(Sint16)0xFE96,(Sint16)0xF8E4, +/*SPEED = 30*/ + (Sint16)0x0000,(Sint16)0xF880,(Sint16)0x0176,(Sint16)0xF8A5,(Sint16)0x02DE,(Sint16)0xF913,(Sint16)0x042A,(Sint16)0xF9C4, + (Sint16)0x054D,(Sint16)0xFAB3,(Sint16)0x063C,(Sint16)0xFBD6,(Sint16)0x06ED,(Sint16)0xFD22,(Sint16)0x075B,(Sint16)0xFE8A, + (Sint16)0x0780,(Sint16)0x0000,(Sint16)0x075B,(Sint16)0x0176,(Sint16)0x06ED,(Sint16)0x02DE,(Sint16)0x063C,(Sint16)0x042A, + (Sint16)0x054D,(Sint16)0x054D,(Sint16)0x042A,(Sint16)0x063C,(Sint16)0x02DE,(Sint16)0x06ED,(Sint16)0x0176,(Sint16)0x075B, + (Sint16)0x0000,(Sint16)0x0780,(Sint16)0xFE8A,(Sint16)0x075B,(Sint16)0xFD22,(Sint16)0x06ED,(Sint16)0xFBD6,(Sint16)0x063C, + (Sint16)0xFAB3,(Sint16)0x054D,(Sint16)0xF9C4,(Sint16)0x042A,(Sint16)0xF913,(Sint16)0x02DE,(Sint16)0xF8A5,(Sint16)0x0176, + (Sint16)0xF880,(Sint16)0x0000,(Sint16)0xF8A5,(Sint16)0xFE8A,(Sint16)0xF913,(Sint16)0xFD22,(Sint16)0xF9C4,(Sint16)0xFBD6, + (Sint16)0xFAB3,(Sint16)0xFAB3,(Sint16)0xFBD6,(Sint16)0xF9C4,(Sint16)0xFD22,(Sint16)0xF913,(Sint16)0xFE8A,(Sint16)0xF8A5, +/*SPEED = 31*/ + (Sint16)0x0000,(Sint16)0xF840,(Sint16)0x0183,(Sint16)0xF867,(Sint16)0x02F7,(Sint16)0xF8D8,(Sint16)0x044E,(Sint16)0xF98F, + (Sint16)0x057A,(Sint16)0xFA86,(Sint16)0x0671,(Sint16)0xFBB2,(Sint16)0x0728,(Sint16)0xFD09,(Sint16)0x0799,(Sint16)0xFE7D, + (Sint16)0x07C0,(Sint16)0x0000,(Sint16)0x0799,(Sint16)0x0183,(Sint16)0x0728,(Sint16)0x02F7,(Sint16)0x0671,(Sint16)0x044E, + (Sint16)0x057A,(Sint16)0x057A,(Sint16)0x044E,(Sint16)0x0671,(Sint16)0x02F7,(Sint16)0x0728,(Sint16)0x0183,(Sint16)0x0799, + (Sint16)0x0000,(Sint16)0x07C0,(Sint16)0xFE7D,(Sint16)0x0799,(Sint16)0xFD09,(Sint16)0x0728,(Sint16)0xFBB2,(Sint16)0x0671, + (Sint16)0xFA86,(Sint16)0x057A,(Sint16)0xF98F,(Sint16)0x044E,(Sint16)0xF8D8,(Sint16)0x02F7,(Sint16)0xF867,(Sint16)0x0183, + (Sint16)0xF840,(Sint16)0x0000,(Sint16)0xF867,(Sint16)0xFE7D,(Sint16)0xF8D8,(Sint16)0xFD09,(Sint16)0xF98F,(Sint16)0xFBB2, + (Sint16)0xFA86,(Sint16)0xFA86,(Sint16)0xFBB2,(Sint16)0xF98F,(Sint16)0xFD09,(Sint16)0xF8D8,(Sint16)0xFE7D,(Sint16)0xF867, + +/*SPEED = 32*/ + (Sint16)0x0000,(Sint16)0xF800,(Sint16)0x018F,(Sint16)0xF828,(Sint16)0x030F,(Sint16)0xF89C,(Sint16)0x0471,(Sint16)0xF95A, + (Sint16)0x05A8,(Sint16)0xFA58,(Sint16)0x06A6,(Sint16)0xFB8F,(Sint16)0x0764,(Sint16)0xFCF1,(Sint16)0x07D8,(Sint16)0xFE71, + (Sint16)0x0800,(Sint16)0x0000,(Sint16)0x07D8,(Sint16)0x018F,(Sint16)0x0764,(Sint16)0x030F,(Sint16)0x06A6,(Sint16)0x0471, + (Sint16)0x05A8,(Sint16)0x05A8,(Sint16)0x0471,(Sint16)0x06A6,(Sint16)0x030F,(Sint16)0x0764,(Sint16)0x018F,(Sint16)0x07D8, + (Sint16)0x0000,(Sint16)0x0800,(Sint16)0xFE71,(Sint16)0x07D8,(Sint16)0xFCF1,(Sint16)0x0764,(Sint16)0xFB8F,(Sint16)0x06A6, + (Sint16)0xFA58,(Sint16)0x05A8,(Sint16)0xF95A,(Sint16)0x0471,(Sint16)0xF89C,(Sint16)0x030F,(Sint16)0xF828,(Sint16)0x018F, + (Sint16)0xF800,(Sint16)0x0000,(Sint16)0xF828,(Sint16)0xFE71,(Sint16)0xF89C,(Sint16)0xFCF1,(Sint16)0xF95A,(Sint16)0xFB8F, + (Sint16)0xFA58,(Sint16)0xFA58,(Sint16)0xFB8F,(Sint16)0xF95A,(Sint16)0xFCF1,(Sint16)0xF89C,(Sint16)0xFE71,(Sint16)0xF828, +/*SPEED = 33*/ + (Sint16)0x0000,(Sint16)0xF7C0,(Sint16)0x019C,(Sint16)0xF7E9,(Sint16)0x0328,(Sint16)0xF861,(Sint16)0x0495,(Sint16)0xF924, + (Sint16)0x05D5,(Sint16)0xFA2B,(Sint16)0x06DC,(Sint16)0xFB6B,(Sint16)0x079F,(Sint16)0xFCD8,(Sint16)0x0817,(Sint16)0xFE64, + (Sint16)0x0840,(Sint16)0x0000,(Sint16)0x0817,(Sint16)0x019C,(Sint16)0x079F,(Sint16)0x0328,(Sint16)0x06DC,(Sint16)0x0495, + (Sint16)0x05D5,(Sint16)0x05D5,(Sint16)0x0495,(Sint16)0x06DC,(Sint16)0x0328,(Sint16)0x079F,(Sint16)0x019C,(Sint16)0x0817, + (Sint16)0x0000,(Sint16)0x0840,(Sint16)0xFE64,(Sint16)0x0817,(Sint16)0xFCD8,(Sint16)0x079F,(Sint16)0xFB6B,(Sint16)0x06DC, + (Sint16)0xFA2B,(Sint16)0x05D5,(Sint16)0xF924,(Sint16)0x0495,(Sint16)0xF861,(Sint16)0x0328,(Sint16)0xF7E9,(Sint16)0x019C, + (Sint16)0xF7C0,(Sint16)0x0000,(Sint16)0xF7E9,(Sint16)0xFE64,(Sint16)0xF861,(Sint16)0xFCD8,(Sint16)0xF924,(Sint16)0xFB6B, + (Sint16)0xFA2B,(Sint16)0xFA2B,(Sint16)0xFB6B,(Sint16)0xF924,(Sint16)0xFCD8,(Sint16)0xF861,(Sint16)0xFE64,(Sint16)0xF7E9, +/*SPEED = 34*/ + (Sint16)0x0000,(Sint16)0xF780,(Sint16)0x01A8,(Sint16)0xF7AA,(Sint16)0x0340,(Sint16)0xF826,(Sint16)0x04B8,(Sint16)0xF8EF, + (Sint16)0x0602,(Sint16)0xF9FE,(Sint16)0x0711,(Sint16)0xFB48,(Sint16)0x07DA,(Sint16)0xFCC0,(Sint16)0x0856,(Sint16)0xFE58, + (Sint16)0x0880,(Sint16)0x0000,(Sint16)0x0856,(Sint16)0x01A8,(Sint16)0x07DA,(Sint16)0x0340,(Sint16)0x0711,(Sint16)0x04B8, + (Sint16)0x0602,(Sint16)0x0602,(Sint16)0x04B8,(Sint16)0x0711,(Sint16)0x0340,(Sint16)0x07DA,(Sint16)0x01A8,(Sint16)0x0856, + (Sint16)0x0000,(Sint16)0x0880,(Sint16)0xFE58,(Sint16)0x0856,(Sint16)0xFCC0,(Sint16)0x07DA,(Sint16)0xFB48,(Sint16)0x0711, + (Sint16)0xF9FE,(Sint16)0x0602,(Sint16)0xF8EF,(Sint16)0x04B8,(Sint16)0xF826,(Sint16)0x0340,(Sint16)0xF7AA,(Sint16)0x01A8, + (Sint16)0xF780,(Sint16)0x0000,(Sint16)0xF7AA,(Sint16)0xFE58,(Sint16)0xF826,(Sint16)0xFCC0,(Sint16)0xF8EF,(Sint16)0xFB48, + (Sint16)0xF9FE,(Sint16)0xF9FE,(Sint16)0xFB48,(Sint16)0xF8EF,(Sint16)0xFCC0,(Sint16)0xF826,(Sint16)0xFE58,(Sint16)0xF7AA, +/*SPEED = 35*/ + (Sint16)0x0000,(Sint16)0xF740,(Sint16)0x01B5,(Sint16)0xF76C,(Sint16)0x0359,(Sint16)0xF7EB,(Sint16)0x04DC,(Sint16)0xF8BA, + (Sint16)0x062F,(Sint16)0xF9D1,(Sint16)0x0746,(Sint16)0xFB24,(Sint16)0x0815,(Sint16)0xFCA7,(Sint16)0x0894,(Sint16)0xFE4B, + (Sint16)0x08C0,(Sint16)0x0000,(Sint16)0x0894,(Sint16)0x01B5,(Sint16)0x0815,(Sint16)0x0359,(Sint16)0x0746,(Sint16)0x04DC, + (Sint16)0x062F,(Sint16)0x062F,(Sint16)0x04DC,(Sint16)0x0746,(Sint16)0x0359,(Sint16)0x0815,(Sint16)0x01B5,(Sint16)0x0894, + (Sint16)0x0000,(Sint16)0x08C0,(Sint16)0xFE4B,(Sint16)0x0894,(Sint16)0xFCA7,(Sint16)0x0815,(Sint16)0xFB24,(Sint16)0x0746, + (Sint16)0xF9D1,(Sint16)0x062F,(Sint16)0xF8BA,(Sint16)0x04DC,(Sint16)0xF7EB,(Sint16)0x0359,(Sint16)0xF76C,(Sint16)0x01B5, + (Sint16)0xF740,(Sint16)0x0000,(Sint16)0xF76C,(Sint16)0xFE4B,(Sint16)0xF7EB,(Sint16)0xFCA7,(Sint16)0xF8BA,(Sint16)0xFB24, + (Sint16)0xF9D1,(Sint16)0xF9D1,(Sint16)0xFB24,(Sint16)0xF8BA,(Sint16)0xFCA7,(Sint16)0xF7EB,(Sint16)0xFE4B,(Sint16)0xF76C, +/*SPEED = 36*/ + (Sint16)0x0000,(Sint16)0xF700,(Sint16)0x01C1,(Sint16)0xF72D,(Sint16)0x0371,(Sint16)0xF7B0,(Sint16)0x0500,(Sint16)0xF885, + (Sint16)0x065D,(Sint16)0xF9A3,(Sint16)0x077B,(Sint16)0xFB00,(Sint16)0x0850,(Sint16)0xFC8F,(Sint16)0x08D3,(Sint16)0xFE3F, + (Sint16)0x0900,(Sint16)0x0000,(Sint16)0x08D3,(Sint16)0x01C1,(Sint16)0x0850,(Sint16)0x0371,(Sint16)0x077B,(Sint16)0x0500, + (Sint16)0x065D,(Sint16)0x065D,(Sint16)0x0500,(Sint16)0x077B,(Sint16)0x0371,(Sint16)0x0850,(Sint16)0x01C1,(Sint16)0x08D3, + (Sint16)0x0000,(Sint16)0x0900,(Sint16)0xFE3F,(Sint16)0x08D3,(Sint16)0xFC8F,(Sint16)0x0850,(Sint16)0xFB00,(Sint16)0x077B, + (Sint16)0xF9A3,(Sint16)0x065D,(Sint16)0xF885,(Sint16)0x0500,(Sint16)0xF7B0,(Sint16)0x0371,(Sint16)0xF72D,(Sint16)0x01C1, + (Sint16)0xF700,(Sint16)0x0000,(Sint16)0xF72D,(Sint16)0xFE3F,(Sint16)0xF7B0,(Sint16)0xFC8F,(Sint16)0xF885,(Sint16)0xFB00, + (Sint16)0xF9A3,(Sint16)0xF9A3,(Sint16)0xFB00,(Sint16)0xF885,(Sint16)0xFC8F,(Sint16)0xF7B0,(Sint16)0xFE3F,(Sint16)0xF72D, +/*SPEED = 37*/ + (Sint16)0x0000,(Sint16)0xF6C0,(Sint16)0x01CD,(Sint16)0xF6EE,(Sint16)0x038A,(Sint16)0xF775,(Sint16)0x0523,(Sint16)0xF850, + (Sint16)0x068A,(Sint16)0xF976,(Sint16)0x07B0,(Sint16)0xFADD,(Sint16)0x088B,(Sint16)0xFC76,(Sint16)0x0912,(Sint16)0xFE33, + (Sint16)0x0940,(Sint16)0x0000,(Sint16)0x0912,(Sint16)0x01CD,(Sint16)0x088B,(Sint16)0x038A,(Sint16)0x07B0,(Sint16)0x0523, + (Sint16)0x068A,(Sint16)0x068A,(Sint16)0x0523,(Sint16)0x07B0,(Sint16)0x038A,(Sint16)0x088B,(Sint16)0x01CD,(Sint16)0x0912, + (Sint16)0x0000,(Sint16)0x0940,(Sint16)0xFE33,(Sint16)0x0912,(Sint16)0xFC76,(Sint16)0x088B,(Sint16)0xFADD,(Sint16)0x07B0, + (Sint16)0xF976,(Sint16)0x068A,(Sint16)0xF850,(Sint16)0x0523,(Sint16)0xF775,(Sint16)0x038A,(Sint16)0xF6EE,(Sint16)0x01CD, + (Sint16)0xF6C0,(Sint16)0x0000,(Sint16)0xF6EE,(Sint16)0xFE33,(Sint16)0xF775,(Sint16)0xFC76,(Sint16)0xF850,(Sint16)0xFADD, + (Sint16)0xF976,(Sint16)0xF976,(Sint16)0xFADD,(Sint16)0xF850,(Sint16)0xFC76,(Sint16)0xF775,(Sint16)0xFE33,(Sint16)0xF6EE, +/*SPEED = 38*/ + (Sint16)0x0000,(Sint16)0xF680,(Sint16)0x01DA,(Sint16)0xF6AF,(Sint16)0x03A2,(Sint16)0xF73A,(Sint16)0x0547,(Sint16)0xF81A, + (Sint16)0x06B7,(Sint16)0xF949,(Sint16)0x07E6,(Sint16)0xFAB9,(Sint16)0x08C6,(Sint16)0xFC5E,(Sint16)0x0951,(Sint16)0xFE26, + (Sint16)0x0980,(Sint16)0x0000,(Sint16)0x0951,(Sint16)0x01DA,(Sint16)0x08C6,(Sint16)0x03A2,(Sint16)0x07E6,(Sint16)0x0547, + (Sint16)0x06B7,(Sint16)0x06B7,(Sint16)0x0547,(Sint16)0x07E6,(Sint16)0x03A2,(Sint16)0x08C6,(Sint16)0x01DA,(Sint16)0x0951, + (Sint16)0x0000,(Sint16)0x0980,(Sint16)0xFE26,(Sint16)0x0951,(Sint16)0xFC5E,(Sint16)0x08C6,(Sint16)0xFAB9,(Sint16)0x07E6, + (Sint16)0xF949,(Sint16)0x06B7,(Sint16)0xF81A,(Sint16)0x0547,(Sint16)0xF73A,(Sint16)0x03A2,(Sint16)0xF6AF,(Sint16)0x01DA, + (Sint16)0xF680,(Sint16)0x0000,(Sint16)0xF6AF,(Sint16)0xFE26,(Sint16)0xF73A,(Sint16)0xFC5E,(Sint16)0xF81A,(Sint16)0xFAB9, + (Sint16)0xF949,(Sint16)0xF949,(Sint16)0xFAB9,(Sint16)0xF81A,(Sint16)0xFC5E,(Sint16)0xF73A,(Sint16)0xFE26,(Sint16)0xF6AF, +/*SPEED = 39*/ + (Sint16)0x0000,(Sint16)0xF640,(Sint16)0x01E6,(Sint16)0xF670,(Sint16)0x03BB,(Sint16)0xF6FE,(Sint16)0x056A,(Sint16)0xF7E5, + (Sint16)0x06E4,(Sint16)0xF91C,(Sint16)0x081B,(Sint16)0xFA96,(Sint16)0x0902,(Sint16)0xFC45,(Sint16)0x0990,(Sint16)0xFE1A, + (Sint16)0x09C0,(Sint16)0x0000,(Sint16)0x0990,(Sint16)0x01E6,(Sint16)0x0902,(Sint16)0x03BB,(Sint16)0x081B,(Sint16)0x056A, + (Sint16)0x06E4,(Sint16)0x06E4,(Sint16)0x056A,(Sint16)0x081B,(Sint16)0x03BB,(Sint16)0x0902,(Sint16)0x01E6,(Sint16)0x0990, + (Sint16)0x0000,(Sint16)0x09C0,(Sint16)0xFE1A,(Sint16)0x0990,(Sint16)0xFC45,(Sint16)0x0902,(Sint16)0xFA96,(Sint16)0x081B, + (Sint16)0xF91C,(Sint16)0x06E4,(Sint16)0xF7E5,(Sint16)0x056A,(Sint16)0xF6FE,(Sint16)0x03BB,(Sint16)0xF670,(Sint16)0x01E6, + (Sint16)0xF640,(Sint16)0x0000,(Sint16)0xF670,(Sint16)0xFE1A,(Sint16)0xF6FE,(Sint16)0xFC45,(Sint16)0xF7E5,(Sint16)0xFA96, + (Sint16)0xF91C,(Sint16)0xF91C,(Sint16)0xFA96,(Sint16)0xF7E5,(Sint16)0xFC45,(Sint16)0xF6FE,(Sint16)0xFE1A,(Sint16)0xF670, +/*SPEED = 40*/ + (Sint16)0x0000,(Sint16)0xF600,(Sint16)0x01F3,(Sint16)0xF632,(Sint16)0x03D3,(Sint16)0xF6C3,(Sint16)0x058E,(Sint16)0xF7B0, + (Sint16)0x0712,(Sint16)0xF8EE,(Sint16)0x0850,(Sint16)0xFA72,(Sint16)0x093D,(Sint16)0xFC2D,(Sint16)0x09CE,(Sint16)0xFE0D, + (Sint16)0x0A00,(Sint16)0x0000,(Sint16)0x09CE,(Sint16)0x01F3,(Sint16)0x093D,(Sint16)0x03D3,(Sint16)0x0850,(Sint16)0x058E, + (Sint16)0x0712,(Sint16)0x0712,(Sint16)0x058E,(Sint16)0x0850,(Sint16)0x03D3,(Sint16)0x093D,(Sint16)0x01F3,(Sint16)0x09CE, + (Sint16)0x0000,(Sint16)0x0A00,(Sint16)0xFE0D,(Sint16)0x09CE,(Sint16)0xFC2D,(Sint16)0x093D,(Sint16)0xFA72,(Sint16)0x0850, + (Sint16)0xF8EE,(Sint16)0x0712,(Sint16)0xF7B0,(Sint16)0x058E,(Sint16)0xF6C3,(Sint16)0x03D3,(Sint16)0xF632,(Sint16)0x01F3, + (Sint16)0xF600,(Sint16)0x0000,(Sint16)0xF632,(Sint16)0xFE0D,(Sint16)0xF6C3,(Sint16)0xFC2D,(Sint16)0xF7B0,(Sint16)0xFA72, + (Sint16)0xF8EE,(Sint16)0xF8EE,(Sint16)0xFA72,(Sint16)0xF7B0,(Sint16)0xFC2D,(Sint16)0xF6C3,(Sint16)0xFE0D,(Sint16)0xF632, +/*SPEED = 41*/ + (Sint16)0x0000,(Sint16)0xF5C0,(Sint16)0x01FF,(Sint16)0xF5F3,(Sint16)0x03EC,(Sint16)0xF688,(Sint16)0x05B1,(Sint16)0xF77B, + (Sint16)0x073F,(Sint16)0xF8C1,(Sint16)0x0885,(Sint16)0xFA4F,(Sint16)0x0978,(Sint16)0xFC14,(Sint16)0x0A0D,(Sint16)0xFE01, + (Sint16)0x0A40,(Sint16)0x0000,(Sint16)0x0A0D,(Sint16)0x01FF,(Sint16)0x0978,(Sint16)0x03EC,(Sint16)0x0885,(Sint16)0x05B1, + (Sint16)0x073F,(Sint16)0x073F,(Sint16)0x05B1,(Sint16)0x0885,(Sint16)0x03EC,(Sint16)0x0978,(Sint16)0x01FF,(Sint16)0x0A0D, + (Sint16)0x0000,(Sint16)0x0A40,(Sint16)0xFE01,(Sint16)0x0A0D,(Sint16)0xFC14,(Sint16)0x0978,(Sint16)0xFA4F,(Sint16)0x0885, + (Sint16)0xF8C1,(Sint16)0x073F,(Sint16)0xF77B,(Sint16)0x05B1,(Sint16)0xF688,(Sint16)0x03EC,(Sint16)0xF5F3,(Sint16)0x01FF, + (Sint16)0xF5C0,(Sint16)0x0000,(Sint16)0xF5F3,(Sint16)0xFE01,(Sint16)0xF688,(Sint16)0xFC14,(Sint16)0xF77B,(Sint16)0xFA4F, + (Sint16)0xF8C1,(Sint16)0xF8C1,(Sint16)0xFA4F,(Sint16)0xF77B,(Sint16)0xFC14,(Sint16)0xF688,(Sint16)0xFE01,(Sint16)0xF5F3, +/*SPEED = 42*/ + (Sint16)0x0000,(Sint16)0xF580,(Sint16)0x020C,(Sint16)0xF5B4,(Sint16)0x0404,(Sint16)0xF64D,(Sint16)0x05D5,(Sint16)0xF746, + (Sint16)0x076C,(Sint16)0xF894,(Sint16)0x08BA,(Sint16)0xFA2B,(Sint16)0x09B3,(Sint16)0xFBFC,(Sint16)0x0A4C,(Sint16)0xFDF4, + (Sint16)0x0A80,(Sint16)0x0000,(Sint16)0x0A4C,(Sint16)0x020C,(Sint16)0x09B3,(Sint16)0x0404,(Sint16)0x08BA,(Sint16)0x05D5, + (Sint16)0x076C,(Sint16)0x076C,(Sint16)0x05D5,(Sint16)0x08BA,(Sint16)0x0404,(Sint16)0x09B3,(Sint16)0x020C,(Sint16)0x0A4C, + (Sint16)0x0000,(Sint16)0x0A80,(Sint16)0xFDF4,(Sint16)0x0A4C,(Sint16)0xFBFC,(Sint16)0x09B3,(Sint16)0xFA2B,(Sint16)0x08BA, + (Sint16)0xF894,(Sint16)0x076C,(Sint16)0xF746,(Sint16)0x05D5,(Sint16)0xF64D,(Sint16)0x0404,(Sint16)0xF5B4,(Sint16)0x020C, + (Sint16)0xF580,(Sint16)0x0000,(Sint16)0xF5B4,(Sint16)0xFDF4,(Sint16)0xF64D,(Sint16)0xFBFC,(Sint16)0xF746,(Sint16)0xFA2B, + (Sint16)0xF894,(Sint16)0xF894,(Sint16)0xFA2B,(Sint16)0xF746,(Sint16)0xFBFC,(Sint16)0xF64D,(Sint16)0xFDF4,(Sint16)0xF5B4, +/*SPEED = 43*/ + (Sint16)0x0000,(Sint16)0xF540,(Sint16)0x0218,(Sint16)0xF575,(Sint16)0x041D,(Sint16)0xF612,(Sint16)0x05F8,(Sint16)0xF710, + (Sint16)0x0799,(Sint16)0xF867,(Sint16)0x08F0,(Sint16)0xFA08,(Sint16)0x09EE,(Sint16)0xFBE3,(Sint16)0x0A8B,(Sint16)0xFDE8, + (Sint16)0x0AC0,(Sint16)0x0000,(Sint16)0x0A8B,(Sint16)0x0218,(Sint16)0x09EE,(Sint16)0x041D,(Sint16)0x08F0,(Sint16)0x05F8, + (Sint16)0x0799,(Sint16)0x0799,(Sint16)0x05F8,(Sint16)0x08F0,(Sint16)0x041D,(Sint16)0x09EE,(Sint16)0x0218,(Sint16)0x0A8B, + (Sint16)0x0000,(Sint16)0x0AC0,(Sint16)0xFDE8,(Sint16)0x0A8B,(Sint16)0xFBE3,(Sint16)0x09EE,(Sint16)0xFA08,(Sint16)0x08F0, + (Sint16)0xF867,(Sint16)0x0799,(Sint16)0xF710,(Sint16)0x05F8,(Sint16)0xF612,(Sint16)0x041D,(Sint16)0xF575,(Sint16)0x0218, + (Sint16)0xF540,(Sint16)0x0000,(Sint16)0xF575,(Sint16)0xFDE8,(Sint16)0xF612,(Sint16)0xFBE3,(Sint16)0xF710,(Sint16)0xFA08, + (Sint16)0xF867,(Sint16)0xF867,(Sint16)0xFA08,(Sint16)0xF710,(Sint16)0xFBE3,(Sint16)0xF612,(Sint16)0xFDE8,(Sint16)0xF575, +/*SPEED = 44*/ + (Sint16)0x0000,(Sint16)0xF500,(Sint16)0x0225,(Sint16)0xF537,(Sint16)0x0435,(Sint16)0xF5D7,(Sint16)0x061C,(Sint16)0xF6DB, + (Sint16)0x07C7,(Sint16)0xF839,(Sint16)0x0925,(Sint16)0xF9E4,(Sint16)0x0A29,(Sint16)0xFBCB,(Sint16)0x0AC9,(Sint16)0xFDDB, + (Sint16)0x0B00,(Sint16)0x0000,(Sint16)0x0AC9,(Sint16)0x0225,(Sint16)0x0A29,(Sint16)0x0435,(Sint16)0x0925,(Sint16)0x061C, + (Sint16)0x07C7,(Sint16)0x07C7,(Sint16)0x061C,(Sint16)0x0925,(Sint16)0x0435,(Sint16)0x0A29,(Sint16)0x0225,(Sint16)0x0AC9, + (Sint16)0x0000,(Sint16)0x0B00,(Sint16)0xFDDB,(Sint16)0x0AC9,(Sint16)0xFBCB,(Sint16)0x0A29,(Sint16)0xF9E4,(Sint16)0x0925, + (Sint16)0xF839,(Sint16)0x07C7,(Sint16)0xF6DB,(Sint16)0x061C,(Sint16)0xF5D7,(Sint16)0x0435,(Sint16)0xF537,(Sint16)0x0225, + (Sint16)0xF500,(Sint16)0x0000,(Sint16)0xF537,(Sint16)0xFDDB,(Sint16)0xF5D7,(Sint16)0xFBCB,(Sint16)0xF6DB,(Sint16)0xF9E4, + (Sint16)0xF839,(Sint16)0xF839,(Sint16)0xF9E4,(Sint16)0xF6DB,(Sint16)0xFBCB,(Sint16)0xF5D7,(Sint16)0xFDDB,(Sint16)0xF537, +/*SPEED = 45*/ + (Sint16)0x0000,(Sint16)0xF4C0,(Sint16)0x0231,(Sint16)0xF4F8,(Sint16)0x044E,(Sint16)0xF59C,(Sint16)0x0640,(Sint16)0xF6A6, + (Sint16)0x07F4,(Sint16)0xF80C,(Sint16)0x095A,(Sint16)0xF9C0,(Sint16)0x0A64,(Sint16)0xFBB2,(Sint16)0x0B08,(Sint16)0xFDCF, + (Sint16)0x0B40,(Sint16)0x0000,(Sint16)0x0B08,(Sint16)0x0231,(Sint16)0x0A64,(Sint16)0x044E,(Sint16)0x095A,(Sint16)0x0640, + (Sint16)0x07F4,(Sint16)0x07F4,(Sint16)0x0640,(Sint16)0x095A,(Sint16)0x044E,(Sint16)0x0A64,(Sint16)0x0231,(Sint16)0x0B08, + (Sint16)0x0000,(Sint16)0x0B40,(Sint16)0xFDCF,(Sint16)0x0B08,(Sint16)0xFBB2,(Sint16)0x0A64,(Sint16)0xF9C0,(Sint16)0x095A, + (Sint16)0xF80C,(Sint16)0x07F4,(Sint16)0xF6A6,(Sint16)0x0640,(Sint16)0xF59C,(Sint16)0x044E,(Sint16)0xF4F8,(Sint16)0x0231, + (Sint16)0xF4C0,(Sint16)0x0000,(Sint16)0xF4F8,(Sint16)0xFDCF,(Sint16)0xF59C,(Sint16)0xFBB2,(Sint16)0xF6A6,(Sint16)0xF9C0, + (Sint16)0xF80C,(Sint16)0xF80C,(Sint16)0xF9C0,(Sint16)0xF6A6,(Sint16)0xFBB2,(Sint16)0xF59C,(Sint16)0xFDCF,(Sint16)0xF4F8, +/*SPEED = 46*/ + (Sint16)0x0000,(Sint16)0xF480,(Sint16)0x023E,(Sint16)0xF4B9,(Sint16)0x0466,(Sint16)0xF561,(Sint16)0x0663,(Sint16)0xF671, + (Sint16)0x0821,(Sint16)0xF7DF,(Sint16)0x098F,(Sint16)0xF99D,(Sint16)0x0A9F,(Sint16)0xFB9A,(Sint16)0x0B47,(Sint16)0xFDC2, + (Sint16)0x0B80,(Sint16)0x0000,(Sint16)0x0B47,(Sint16)0x023E,(Sint16)0x0A9F,(Sint16)0x0466,(Sint16)0x098F,(Sint16)0x0663, + (Sint16)0x0821,(Sint16)0x0821,(Sint16)0x0663,(Sint16)0x098F,(Sint16)0x0466,(Sint16)0x0A9F,(Sint16)0x023E,(Sint16)0x0B47, + (Sint16)0x0000,(Sint16)0x0B80,(Sint16)0xFDC2,(Sint16)0x0B47,(Sint16)0xFB9A,(Sint16)0x0A9F,(Sint16)0xF99D,(Sint16)0x098F, + (Sint16)0xF7DF,(Sint16)0x0821,(Sint16)0xF671,(Sint16)0x0663,(Sint16)0xF561,(Sint16)0x0466,(Sint16)0xF4B9,(Sint16)0x023E, + (Sint16)0xF480,(Sint16)0x0000,(Sint16)0xF4B9,(Sint16)0xFDC2,(Sint16)0xF561,(Sint16)0xFB9A,(Sint16)0xF671,(Sint16)0xF99D, + (Sint16)0xF7DF,(Sint16)0xF7DF,(Sint16)0xF99D,(Sint16)0xF671,(Sint16)0xFB9A,(Sint16)0xF561,(Sint16)0xFDC2,(Sint16)0xF4B9, +/*SPEED = 47*/ + (Sint16)0x0000,(Sint16)0xF440,(Sint16)0x024A,(Sint16)0xF47A,(Sint16)0x047F,(Sint16)0xF525,(Sint16)0x0687,(Sint16)0xF63B, + (Sint16)0x084E,(Sint16)0xF7B2,(Sint16)0x09C5,(Sint16)0xF979,(Sint16)0x0ADB,(Sint16)0xFB81,(Sint16)0x0B86,(Sint16)0xFDB6, + (Sint16)0x0BC0,(Sint16)0x0000,(Sint16)0x0B86,(Sint16)0x024A,(Sint16)0x0ADB,(Sint16)0x047F,(Sint16)0x09C5,(Sint16)0x0687, + (Sint16)0x084E,(Sint16)0x084E,(Sint16)0x0687,(Sint16)0x09C5,(Sint16)0x047F,(Sint16)0x0ADB,(Sint16)0x024A,(Sint16)0x0B86, + (Sint16)0x0000,(Sint16)0x0BC0,(Sint16)0xFDB6,(Sint16)0x0B86,(Sint16)0xFB81,(Sint16)0x0ADB,(Sint16)0xF979,(Sint16)0x09C5, + (Sint16)0xF7B2,(Sint16)0x084E,(Sint16)0xF63B,(Sint16)0x0687,(Sint16)0xF525,(Sint16)0x047F,(Sint16)0xF47A,(Sint16)0x024A, + (Sint16)0xF440,(Sint16)0x0000,(Sint16)0xF47A,(Sint16)0xFDB6,(Sint16)0xF525,(Sint16)0xFB81,(Sint16)0xF63B,(Sint16)0xF979, + (Sint16)0xF7B2,(Sint16)0xF7B2,(Sint16)0xF979,(Sint16)0xF63B,(Sint16)0xFB81,(Sint16)0xF525,(Sint16)0xFDB6,(Sint16)0xF47A, +/*SPEED = 48*/ + (Sint16)0x0000,(Sint16)0xF400,(Sint16)0x0257,(Sint16)0xF43C,(Sint16)0x0497,(Sint16)0xF4EA,(Sint16)0x06AA,(Sint16)0xF606, + (Sint16)0x087C,(Sint16)0xF784,(Sint16)0x09FA,(Sint16)0xF956,(Sint16)0x0B16,(Sint16)0xFB69,(Sint16)0x0BC4,(Sint16)0xFDA9, + (Sint16)0x0C00,(Sint16)0x0000,(Sint16)0x0BC4,(Sint16)0x0257,(Sint16)0x0B16,(Sint16)0x0497,(Sint16)0x09FA,(Sint16)0x06AA, + (Sint16)0x087C,(Sint16)0x087C,(Sint16)0x06AA,(Sint16)0x09FA,(Sint16)0x0497,(Sint16)0x0B16,(Sint16)0x0257,(Sint16)0x0BC4, + (Sint16)0x0000,(Sint16)0x0C00,(Sint16)0xFDA9,(Sint16)0x0BC4,(Sint16)0xFB69,(Sint16)0x0B16,(Sint16)0xF956,(Sint16)0x09FA, + (Sint16)0xF784,(Sint16)0x087C,(Sint16)0xF606,(Sint16)0x06AA,(Sint16)0xF4EA,(Sint16)0x0497,(Sint16)0xF43C,(Sint16)0x0257, + (Sint16)0xF400,(Sint16)0x0000,(Sint16)0xF43C,(Sint16)0xFDA9,(Sint16)0xF4EA,(Sint16)0xFB69,(Sint16)0xF606,(Sint16)0xF956, + (Sint16)0xF784,(Sint16)0xF784,(Sint16)0xF956,(Sint16)0xF606,(Sint16)0xFB69,(Sint16)0xF4EA,(Sint16)0xFDA9,(Sint16)0xF43C, +/*SPEED = 49*/ + (Sint16)0x0000,(Sint16)0xF3C0,(Sint16)0x0263,(Sint16)0xF3FD,(Sint16)0x04B0,(Sint16)0xF4AF,(Sint16)0x06CE,(Sint16)0xF5D1, + (Sint16)0x08A9,(Sint16)0xF757,(Sint16)0x0A2F,(Sint16)0xF932,(Sint16)0x0B51,(Sint16)0xFB50,(Sint16)0x0C03,(Sint16)0xFD9D, + (Sint16)0x0C40,(Sint16)0x0000,(Sint16)0x0C03,(Sint16)0x0263,(Sint16)0x0B51,(Sint16)0x04B0,(Sint16)0x0A2F,(Sint16)0x06CE, + (Sint16)0x08A9,(Sint16)0x08A9,(Sint16)0x06CE,(Sint16)0x0A2F,(Sint16)0x04B0,(Sint16)0x0B51,(Sint16)0x0263,(Sint16)0x0C03, + (Sint16)0x0000,(Sint16)0x0C40,(Sint16)0xFD9D,(Sint16)0x0C03,(Sint16)0xFB50,(Sint16)0x0B51,(Sint16)0xF932,(Sint16)0x0A2F, + (Sint16)0xF757,(Sint16)0x08A9,(Sint16)0xF5D1,(Sint16)0x06CE,(Sint16)0xF4AF,(Sint16)0x04B0,(Sint16)0xF3FD,(Sint16)0x0263, + (Sint16)0xF3C0,(Sint16)0x0000,(Sint16)0xF3FD,(Sint16)0xFD9D,(Sint16)0xF4AF,(Sint16)0xFB50,(Sint16)0xF5D1,(Sint16)0xF932, + (Sint16)0xF757,(Sint16)0xF757,(Sint16)0xF932,(Sint16)0xF5D1,(Sint16)0xFB50,(Sint16)0xF4AF,(Sint16)0xFD9D,(Sint16)0xF3FD, +/*SPEED = 50*/ + (Sint16)0x0000,(Sint16)0xF380,(Sint16)0x0270,(Sint16)0xF3BE,(Sint16)0x04C8,(Sint16)0xF474,(Sint16)0x06F1,(Sint16)0xF59C, + (Sint16)0x08D6,(Sint16)0xF72A,(Sint16)0x0A64,(Sint16)0xF90F,(Sint16)0x0B8C,(Sint16)0xFB38,(Sint16)0x0C42,(Sint16)0xFD90, + (Sint16)0x0C80,(Sint16)0x0000,(Sint16)0x0C42,(Sint16)0x0270,(Sint16)0x0B8C,(Sint16)0x04C8,(Sint16)0x0A64,(Sint16)0x06F1, + (Sint16)0x08D6,(Sint16)0x08D6,(Sint16)0x06F1,(Sint16)0x0A64,(Sint16)0x04C8,(Sint16)0x0B8C,(Sint16)0x0270,(Sint16)0x0C42, + (Sint16)0x0000,(Sint16)0x0C80,(Sint16)0xFD90,(Sint16)0x0C42,(Sint16)0xFB38,(Sint16)0x0B8C,(Sint16)0xF90F,(Sint16)0x0A64, + (Sint16)0xF72A,(Sint16)0x08D6,(Sint16)0xF59C,(Sint16)0x06F1,(Sint16)0xF474,(Sint16)0x04C8,(Sint16)0xF3BE,(Sint16)0x0270, + (Sint16)0xF380,(Sint16)0x0000,(Sint16)0xF3BE,(Sint16)0xFD90,(Sint16)0xF474,(Sint16)0xFB38,(Sint16)0xF59C,(Sint16)0xF90F, + (Sint16)0xF72A,(Sint16)0xF72A,(Sint16)0xF90F,(Sint16)0xF59C,(Sint16)0xFB38,(Sint16)0xF474,(Sint16)0xFD90,(Sint16)0xF3BE, +/*SPEED = 51*/ + (Sint16)0x0000,(Sint16)0xF340,(Sint16)0x027C,(Sint16)0xF37F,(Sint16)0x04E1,(Sint16)0xF439,(Sint16)0x0715,(Sint16)0xF567, + (Sint16)0x0903,(Sint16)0xF6FD,(Sint16)0x0A99,(Sint16)0xF8EB,(Sint16)0x0BC7,(Sint16)0xFB1F,(Sint16)0x0C81,(Sint16)0xFD84, + (Sint16)0x0CC0,(Sint16)0x0000,(Sint16)0x0C81,(Sint16)0x027C,(Sint16)0x0BC7,(Sint16)0x04E1,(Sint16)0x0A99,(Sint16)0x0715, + (Sint16)0x0903,(Sint16)0x0903,(Sint16)0x0715,(Sint16)0x0A99,(Sint16)0x04E1,(Sint16)0x0BC7,(Sint16)0x027C,(Sint16)0x0C81, + (Sint16)0x0000,(Sint16)0x0CC0,(Sint16)0xFD84,(Sint16)0x0C81,(Sint16)0xFB1F,(Sint16)0x0BC7,(Sint16)0xF8EB,(Sint16)0x0A99, + (Sint16)0xF6FD,(Sint16)0x0903,(Sint16)0xF567,(Sint16)0x0715,(Sint16)0xF439,(Sint16)0x04E1,(Sint16)0xF37F,(Sint16)0x027C, + (Sint16)0xF340,(Sint16)0x0000,(Sint16)0xF37F,(Sint16)0xFD84,(Sint16)0xF439,(Sint16)0xFB1F,(Sint16)0xF567,(Sint16)0xF8EB, + (Sint16)0xF6FD,(Sint16)0xF6FD,(Sint16)0xF8EB,(Sint16)0xF567,(Sint16)0xFB1F,(Sint16)0xF439,(Sint16)0xFD84,(Sint16)0xF37F, +/*SPEED = 52*/ + (Sint16)0x0000,(Sint16)0xF300,(Sint16)0x0289,(Sint16)0xF340,(Sint16)0x04F9,(Sint16)0xF3FE,(Sint16)0x0738,(Sint16)0xF531, + (Sint16)0x0931,(Sint16)0xF6CF,(Sint16)0x0ACF,(Sint16)0xF8C8,(Sint16)0x0C02,(Sint16)0xFB07,(Sint16)0x0CC0,(Sint16)0xFD77, + (Sint16)0x0D00,(Sint16)0x0000,(Sint16)0x0CC0,(Sint16)0x0289,(Sint16)0x0C02,(Sint16)0x04F9,(Sint16)0x0ACF,(Sint16)0x0738, + (Sint16)0x0931,(Sint16)0x0931,(Sint16)0x0738,(Sint16)0x0ACF,(Sint16)0x04F9,(Sint16)0x0C02,(Sint16)0x0289,(Sint16)0x0CC0, + (Sint16)0x0000,(Sint16)0x0D00,(Sint16)0xFD77,(Sint16)0x0CC0,(Sint16)0xFB07,(Sint16)0x0C02,(Sint16)0xF8C8,(Sint16)0x0ACF, + (Sint16)0xF6CF,(Sint16)0x0931,(Sint16)0xF531,(Sint16)0x0738,(Sint16)0xF3FE,(Sint16)0x04F9,(Sint16)0xF340,(Sint16)0x0289, + (Sint16)0xF300,(Sint16)0x0000,(Sint16)0xF340,(Sint16)0xFD77,(Sint16)0xF3FE,(Sint16)0xFB07,(Sint16)0xF531,(Sint16)0xF8C8, + (Sint16)0xF6CF,(Sint16)0xF6CF,(Sint16)0xF8C8,(Sint16)0xF531,(Sint16)0xFB07,(Sint16)0xF3FE,(Sint16)0xFD77,(Sint16)0xF340, +/*SPEED = 53*/ + (Sint16)0x0000,(Sint16)0xF2C0,(Sint16)0x0295,(Sint16)0xF302,(Sint16)0x0512,(Sint16)0xF3C3,(Sint16)0x075C,(Sint16)0xF4FC, + (Sint16)0x095E,(Sint16)0xF6A2,(Sint16)0x0B04,(Sint16)0xF8A4,(Sint16)0x0C3D,(Sint16)0xFAEE,(Sint16)0x0CFE,(Sint16)0xFD6B, + (Sint16)0x0D40,(Sint16)0x0000,(Sint16)0x0CFE,(Sint16)0x0295,(Sint16)0x0C3D,(Sint16)0x0512,(Sint16)0x0B04,(Sint16)0x075C, + (Sint16)0x095E,(Sint16)0x095E,(Sint16)0x075C,(Sint16)0x0B04,(Sint16)0x0512,(Sint16)0x0C3D,(Sint16)0x0295,(Sint16)0x0CFE, + (Sint16)0x0000,(Sint16)0x0D40,(Sint16)0xFD6B,(Sint16)0x0CFE,(Sint16)0xFAEE,(Sint16)0x0C3D,(Sint16)0xF8A4,(Sint16)0x0B04, + (Sint16)0xF6A2,(Sint16)0x095E,(Sint16)0xF4FC,(Sint16)0x075C,(Sint16)0xF3C3,(Sint16)0x0512,(Sint16)0xF302,(Sint16)0x0295, + (Sint16)0xF2C0,(Sint16)0x0000,(Sint16)0xF302,(Sint16)0xFD6B,(Sint16)0xF3C3,(Sint16)0xFAEE,(Sint16)0xF4FC,(Sint16)0xF8A4, + (Sint16)0xF6A2,(Sint16)0xF6A2,(Sint16)0xF8A4,(Sint16)0xF4FC,(Sint16)0xFAEE,(Sint16)0xF3C3,(Sint16)0xFD6B,(Sint16)0xF302, +/*SPEED = 54*/ + (Sint16)0x0000,(Sint16)0xF280,(Sint16)0x02A2,(Sint16)0xF2C3,(Sint16)0x052A,(Sint16)0xF388,(Sint16)0x0780,(Sint16)0xF4C7, + (Sint16)0x098B,(Sint16)0xF675,(Sint16)0x0B39,(Sint16)0xF880,(Sint16)0x0C78,(Sint16)0xFAD6,(Sint16)0x0D3D,(Sint16)0xFD5E, + (Sint16)0x0D80,(Sint16)0x0000,(Sint16)0x0D3D,(Sint16)0x02A2,(Sint16)0x0C78,(Sint16)0x052A,(Sint16)0x0B39,(Sint16)0x0780, + (Sint16)0x098B,(Sint16)0x098B,(Sint16)0x0780,(Sint16)0x0B39,(Sint16)0x052A,(Sint16)0x0C78,(Sint16)0x02A2,(Sint16)0x0D3D, + (Sint16)0x0000,(Sint16)0x0D80,(Sint16)0xFD5E,(Sint16)0x0D3D,(Sint16)0xFAD6,(Sint16)0x0C78,(Sint16)0xF880,(Sint16)0x0B39, + (Sint16)0xF675,(Sint16)0x098B,(Sint16)0xF4C7,(Sint16)0x0780,(Sint16)0xF388,(Sint16)0x052A,(Sint16)0xF2C3,(Sint16)0x02A2, + (Sint16)0xF280,(Sint16)0x0000,(Sint16)0xF2C3,(Sint16)0xFD5E,(Sint16)0xF388,(Sint16)0xFAD6,(Sint16)0xF4C7,(Sint16)0xF880, + (Sint16)0xF675,(Sint16)0xF675,(Sint16)0xF880,(Sint16)0xF4C7,(Sint16)0xFAD6,(Sint16)0xF388,(Sint16)0xFD5E,(Sint16)0xF2C3, +/*SPEED = 55*/ + (Sint16)0x0000,(Sint16)0xF240,(Sint16)0x02AE,(Sint16)0xF284,(Sint16)0x0543,(Sint16)0xF34C,(Sint16)0x07A3,(Sint16)0xF492, + (Sint16)0x09B9,(Sint16)0xF647,(Sint16)0x0B6E,(Sint16)0xF85D,(Sint16)0x0CB4,(Sint16)0xFABD,(Sint16)0x0D7C,(Sint16)0xFD52, + (Sint16)0x0DC0,(Sint16)0x0000,(Sint16)0x0D7C,(Sint16)0x02AE,(Sint16)0x0CB4,(Sint16)0x0543,(Sint16)0x0B6E,(Sint16)0x07A3, + (Sint16)0x09B9,(Sint16)0x09B9,(Sint16)0x07A3,(Sint16)0x0B6E,(Sint16)0x0543,(Sint16)0x0CB4,(Sint16)0x02AE,(Sint16)0x0D7C, + (Sint16)0x0000,(Sint16)0x0DC0,(Sint16)0xFD52,(Sint16)0x0D7C,(Sint16)0xFABD,(Sint16)0x0CB4,(Sint16)0xF85D,(Sint16)0x0B6E, + (Sint16)0xF647,(Sint16)0x09B9,(Sint16)0xF492,(Sint16)0x07A3,(Sint16)0xF34C,(Sint16)0x0543,(Sint16)0xF284,(Sint16)0x02AE, + (Sint16)0xF240,(Sint16)0x0000,(Sint16)0xF284,(Sint16)0xFD52,(Sint16)0xF34C,(Sint16)0xFABD,(Sint16)0xF492,(Sint16)0xF85D, + (Sint16)0xF647,(Sint16)0xF647,(Sint16)0xF85D,(Sint16)0xF492,(Sint16)0xFABD,(Sint16)0xF34C,(Sint16)0xFD52,(Sint16)0xF284, +/*SPEED = 56*/ + (Sint16)0x0000,(Sint16)0xF200,(Sint16)0x02BB,(Sint16)0xF245,(Sint16)0x055B,(Sint16)0xF311,(Sint16)0x07C7,(Sint16)0xF45D, + (Sint16)0x09E6,(Sint16)0xF61A,(Sint16)0x0BA3,(Sint16)0xF839,(Sint16)0x0CEF,(Sint16)0xFAA5,(Sint16)0x0DBB,(Sint16)0xFD45, + (Sint16)0x0E00,(Sint16)0x0000,(Sint16)0x0DBB,(Sint16)0x02BB,(Sint16)0x0CEF,(Sint16)0x055B,(Sint16)0x0BA3,(Sint16)0x07C7, + (Sint16)0x09E6,(Sint16)0x09E6,(Sint16)0x07C7,(Sint16)0x0BA3,(Sint16)0x055B,(Sint16)0x0CEF,(Sint16)0x02BB,(Sint16)0x0DBB, + (Sint16)0x0000,(Sint16)0x0E00,(Sint16)0xFD45,(Sint16)0x0DBB,(Sint16)0xFAA5,(Sint16)0x0CEF,(Sint16)0xF839,(Sint16)0x0BA3, + (Sint16)0xF61A,(Sint16)0x09E6,(Sint16)0xF45D,(Sint16)0x07C7,(Sint16)0xF311,(Sint16)0x055B,(Sint16)0xF245,(Sint16)0x02BB, + (Sint16)0xF200,(Sint16)0x0000,(Sint16)0xF245,(Sint16)0xFD45,(Sint16)0xF311,(Sint16)0xFAA5,(Sint16)0xF45D,(Sint16)0xF839, + (Sint16)0xF61A,(Sint16)0xF61A,(Sint16)0xF839,(Sint16)0xF45D,(Sint16)0xFAA5,(Sint16)0xF311,(Sint16)0xFD45,(Sint16)0xF245, +/*SPEED = 57*/ + (Sint16)0x0000,(Sint16)0xF1C0,(Sint16)0x02C7,(Sint16)0xF207,(Sint16)0x0574,(Sint16)0xF2D6,(Sint16)0x07EA,(Sint16)0xF427, + (Sint16)0x0A13,(Sint16)0xF5ED,(Sint16)0x0BD9,(Sint16)0xF816,(Sint16)0x0D2A,(Sint16)0xFA8C,(Sint16)0x0DF9,(Sint16)0xFD39, + (Sint16)0x0E40,(Sint16)0x0000,(Sint16)0x0DF9,(Sint16)0x02C7,(Sint16)0x0D2A,(Sint16)0x0574,(Sint16)0x0BD9,(Sint16)0x07EA, + (Sint16)0x0A13,(Sint16)0x0A13,(Sint16)0x07EA,(Sint16)0x0BD9,(Sint16)0x0574,(Sint16)0x0D2A,(Sint16)0x02C7,(Sint16)0x0DF9, + (Sint16)0x0000,(Sint16)0x0E40,(Sint16)0xFD39,(Sint16)0x0DF9,(Sint16)0xFA8C,(Sint16)0x0D2A,(Sint16)0xF816,(Sint16)0x0BD9, + (Sint16)0xF5ED,(Sint16)0x0A13,(Sint16)0xF427,(Sint16)0x07EA,(Sint16)0xF2D6,(Sint16)0x0574,(Sint16)0xF207,(Sint16)0x02C7, + (Sint16)0xF1C0,(Sint16)0x0000,(Sint16)0xF207,(Sint16)0xFD39,(Sint16)0xF2D6,(Sint16)0xFA8C,(Sint16)0xF427,(Sint16)0xF816, + (Sint16)0xF5ED,(Sint16)0xF5ED,(Sint16)0xF816,(Sint16)0xF427,(Sint16)0xFA8C,(Sint16)0xF2D6,(Sint16)0xFD39,(Sint16)0xF207, +/*SPEED = 58*/ + (Sint16)0x0000,(Sint16)0xF180,(Sint16)0x02D4,(Sint16)0xF1C8,(Sint16)0x058C,(Sint16)0xF29B,(Sint16)0x080E,(Sint16)0xF3F2, + (Sint16)0x0A40,(Sint16)0xF5C0,(Sint16)0x0C0E,(Sint16)0xF7F2,(Sint16)0x0D65,(Sint16)0xFA74,(Sint16)0x0E38,(Sint16)0xFD2C, + (Sint16)0x0E80,(Sint16)0x0000,(Sint16)0x0E38,(Sint16)0x02D4,(Sint16)0x0D65,(Sint16)0x058C,(Sint16)0x0C0E,(Sint16)0x080E, + (Sint16)0x0A40,(Sint16)0x0A40,(Sint16)0x080E,(Sint16)0x0C0E,(Sint16)0x058C,(Sint16)0x0D65,(Sint16)0x02D4,(Sint16)0x0E38, + (Sint16)0x0000,(Sint16)0x0E80,(Sint16)0xFD2C,(Sint16)0x0E38,(Sint16)0xFA74,(Sint16)0x0D65,(Sint16)0xF7F2,(Sint16)0x0C0E, + (Sint16)0xF5C0,(Sint16)0x0A40,(Sint16)0xF3F2,(Sint16)0x080E,(Sint16)0xF29B,(Sint16)0x058C,(Sint16)0xF1C8,(Sint16)0x02D4, + (Sint16)0xF180,(Sint16)0x0000,(Sint16)0xF1C8,(Sint16)0xFD2C,(Sint16)0xF29B,(Sint16)0xFA74,(Sint16)0xF3F2,(Sint16)0xF7F2, + (Sint16)0xF5C0,(Sint16)0xF5C0,(Sint16)0xF7F2,(Sint16)0xF3F2,(Sint16)0xFA74,(Sint16)0xF29B,(Sint16)0xFD2C,(Sint16)0xF1C8, +/*SPEED = 59*/ + (Sint16)0x0000,(Sint16)0xF140,(Sint16)0x02E0,(Sint16)0xF189,(Sint16)0x05A5,(Sint16)0xF260,(Sint16)0x0831,(Sint16)0xF3BD, + (Sint16)0x0A6E,(Sint16)0xF592,(Sint16)0x0C43,(Sint16)0xF7CF,(Sint16)0x0DA0,(Sint16)0xFA5B,(Sint16)0x0E77,(Sint16)0xFD20, + (Sint16)0x0EC0,(Sint16)0x0000,(Sint16)0x0E77,(Sint16)0x02E0,(Sint16)0x0DA0,(Sint16)0x05A5,(Sint16)0x0C43,(Sint16)0x0831, + (Sint16)0x0A6E,(Sint16)0x0A6E,(Sint16)0x0831,(Sint16)0x0C43,(Sint16)0x05A5,(Sint16)0x0DA0,(Sint16)0x02E0,(Sint16)0x0E77, + (Sint16)0x0000,(Sint16)0x0EC0,(Sint16)0xFD20,(Sint16)0x0E77,(Sint16)0xFA5B,(Sint16)0x0DA0,(Sint16)0xF7CF,(Sint16)0x0C43, + (Sint16)0xF592,(Sint16)0x0A6E,(Sint16)0xF3BD,(Sint16)0x0831,(Sint16)0xF260,(Sint16)0x05A5,(Sint16)0xF189,(Sint16)0x02E0, + (Sint16)0xF140,(Sint16)0x0000,(Sint16)0xF189,(Sint16)0xFD20,(Sint16)0xF260,(Sint16)0xFA5B,(Sint16)0xF3BD,(Sint16)0xF7CF, + (Sint16)0xF592,(Sint16)0xF592,(Sint16)0xF7CF,(Sint16)0xF3BD,(Sint16)0xFA5B,(Sint16)0xF260,(Sint16)0xFD20,(Sint16)0xF189, +/*SPEED = 60*/ + (Sint16)0x0000,(Sint16)0xF100,(Sint16)0x02ED,(Sint16)0xF14A,(Sint16)0x05BD,(Sint16)0xF225,(Sint16)0x0855,(Sint16)0xF388, + (Sint16)0x0A9B,(Sint16)0xF565,(Sint16)0x0C78,(Sint16)0xF7AB,(Sint16)0x0DDB,(Sint16)0xFA43,(Sint16)0x0EB6,(Sint16)0xFD13, + (Sint16)0x0F00,(Sint16)0x0000,(Sint16)0x0EB6,(Sint16)0x02ED,(Sint16)0x0DDB,(Sint16)0x05BD,(Sint16)0x0C78,(Sint16)0x0855, + (Sint16)0x0A9B,(Sint16)0x0A9B,(Sint16)0x0855,(Sint16)0x0C78,(Sint16)0x05BD,(Sint16)0x0DDB,(Sint16)0x02ED,(Sint16)0x0EB6, + (Sint16)0x0000,(Sint16)0x0F00,(Sint16)0xFD13,(Sint16)0x0EB6,(Sint16)0xFA43,(Sint16)0x0DDB,(Sint16)0xF7AB,(Sint16)0x0C78, + (Sint16)0xF565,(Sint16)0x0A9B,(Sint16)0xF388,(Sint16)0x0855,(Sint16)0xF225,(Sint16)0x05BD,(Sint16)0xF14A,(Sint16)0x02ED, + (Sint16)0xF100,(Sint16)0x0000,(Sint16)0xF14A,(Sint16)0xFD13,(Sint16)0xF225,(Sint16)0xFA43,(Sint16)0xF388,(Sint16)0xF7AB, + (Sint16)0xF565,(Sint16)0xF565,(Sint16)0xF7AB,(Sint16)0xF388,(Sint16)0xFA43,(Sint16)0xF225,(Sint16)0xFD13,(Sint16)0xF14A, +/*SPEED = 61*/ + (Sint16)0x0000,(Sint16)0xF0C0,(Sint16)0x02F9,(Sint16)0xF10C,(Sint16)0x05D5,(Sint16)0xF1EA,(Sint16)0x0878,(Sint16)0xF352, + (Sint16)0x0AC8,(Sint16)0xF538,(Sint16)0x0CAE,(Sint16)0xF788,(Sint16)0x0E16,(Sint16)0xFA2B,(Sint16)0x0EF4,(Sint16)0xFD07, + (Sint16)0x0F40,(Sint16)0x0000,(Sint16)0x0EF4,(Sint16)0x02F9,(Sint16)0x0E16,(Sint16)0x05D5,(Sint16)0x0CAE,(Sint16)0x0878, + (Sint16)0x0AC8,(Sint16)0x0AC8,(Sint16)0x0878,(Sint16)0x0CAE,(Sint16)0x05D5,(Sint16)0x0E16,(Sint16)0x02F9,(Sint16)0x0EF4, + (Sint16)0x0000,(Sint16)0x0F40,(Sint16)0xFD07,(Sint16)0x0EF4,(Sint16)0xFA2B,(Sint16)0x0E16,(Sint16)0xF788,(Sint16)0x0CAE, + (Sint16)0xF538,(Sint16)0x0AC8,(Sint16)0xF352,(Sint16)0x0878,(Sint16)0xF1EA,(Sint16)0x05D5,(Sint16)0xF10C,(Sint16)0x02F9, + (Sint16)0xF0C0,(Sint16)0x0000,(Sint16)0xF10C,(Sint16)0xFD07,(Sint16)0xF1EA,(Sint16)0xFA2B,(Sint16)0xF352,(Sint16)0xF788, + (Sint16)0xF538,(Sint16)0xF538,(Sint16)0xF788,(Sint16)0xF352,(Sint16)0xFA2B,(Sint16)0xF1EA,(Sint16)0xFD07,(Sint16)0xF10C, +/*SPEED = 62*/ + (Sint16)0x0000,(Sint16)0xF080,(Sint16)0x0306,(Sint16)0xF0CD,(Sint16)0x05EE,(Sint16)0xF1AF,(Sint16)0x089C,(Sint16)0xF31D, + (Sint16)0x0AF5,(Sint16)0xF50B,(Sint16)0x0CE3,(Sint16)0xF764,(Sint16)0x0E51,(Sint16)0xFA12,(Sint16)0x0F33,(Sint16)0xFCFA, + (Sint16)0x0F80,(Sint16)0x0000,(Sint16)0x0F33,(Sint16)0x0306,(Sint16)0x0E51,(Sint16)0x05EE,(Sint16)0x0CE3,(Sint16)0x089C, + (Sint16)0x0AF5,(Sint16)0x0AF5,(Sint16)0x089C,(Sint16)0x0CE3,(Sint16)0x05EE,(Sint16)0x0E51,(Sint16)0x0306,(Sint16)0x0F33, + (Sint16)0x0000,(Sint16)0x0F80,(Sint16)0xFCFA,(Sint16)0x0F33,(Sint16)0xFA12,(Sint16)0x0E51,(Sint16)0xF764,(Sint16)0x0CE3, + (Sint16)0xF50B,(Sint16)0x0AF5,(Sint16)0xF31D,(Sint16)0x089C,(Sint16)0xF1AF,(Sint16)0x05EE,(Sint16)0xF0CD,(Sint16)0x0306, + (Sint16)0xF080,(Sint16)0x0000,(Sint16)0xF0CD,(Sint16)0xFCFA,(Sint16)0xF1AF,(Sint16)0xFA12,(Sint16)0xF31D,(Sint16)0xF764, + (Sint16)0xF50B,(Sint16)0xF50B,(Sint16)0xF764,(Sint16)0xF31D,(Sint16)0xFA12,(Sint16)0xF1AF,(Sint16)0xFCFA,(Sint16)0xF0CD, +/*SPEED = 63*/ + (Sint16)0x0000,(Sint16)0xF040,(Sint16)0x0312,(Sint16)0xF08E,(Sint16)0x0606,(Sint16)0xF173,(Sint16)0x08C0,(Sint16)0xF2E8, + (Sint16)0x0B23,(Sint16)0xF4DD,(Sint16)0x0D18,(Sint16)0xF740,(Sint16)0x0E8D,(Sint16)0xF9FA,(Sint16)0x0F72,(Sint16)0xFCEE, + (Sint16)0x0FC0,(Sint16)0x0000,(Sint16)0x0F72,(Sint16)0x0312,(Sint16)0x0E8D,(Sint16)0x0606,(Sint16)0x0D18,(Sint16)0x08C0, + (Sint16)0x0B23,(Sint16)0x0B23,(Sint16)0x08C0,(Sint16)0x0D18,(Sint16)0x0606,(Sint16)0x0E8D,(Sint16)0x0312,(Sint16)0x0F72, + (Sint16)0x0000,(Sint16)0x0FC0,(Sint16)0xFCEE,(Sint16)0x0F72,(Sint16)0xF9FA,(Sint16)0x0E8D,(Sint16)0xF740,(Sint16)0x0D18, + (Sint16)0xF4DD,(Sint16)0x0B23,(Sint16)0xF2E8,(Sint16)0x08C0,(Sint16)0xF173,(Sint16)0x0606,(Sint16)0xF08E,(Sint16)0x0312, + (Sint16)0xF040,(Sint16)0x0000,(Sint16)0xF08E,(Sint16)0xFCEE,(Sint16)0xF173,(Sint16)0xF9FA,(Sint16)0xF2E8,(Sint16)0xF740, + (Sint16)0xF4DD,(Sint16)0xF4DD,(Sint16)0xF740,(Sint16)0xF2E8,(Sint16)0xF9FA,(Sint16)0xF173,(Sint16)0xFCEE,(Sint16)0xF08E, +}; +/**************************************** +* * +* DELTA DATA MOVING * +* * +****************************************/ + +/* ENT : ATR_SPD(A0) +* ATR_CRS(A0) + +* EXT : d1.w:???h? +* : d2.w:???h? + +* DESTORY : D0,D1,D2,D3,D4 +* A1,A6 +*/ + +void gemini(ACTION *a0) +{ + Sint32 d1,d2,d3,d4,d5,d6; + Sint32 d0; + Uint16 a1; + d5=((Sint32)ATR_H_POS(a0))<<16; + d6=((Sint32)ATR_V_POS(a0))<<16; + d5+=(Sint32)(ATR_H_MINI(a0))<<8; + d6+=(Sint32)(ATR_V_MINI(a0))<<8; + if(!(d0=ATR_SPD(a0))) + return; + d0--; + a1=((Uint16)d0)<<6; /*32(DIR)*2(H/V)*2(BYTE)=128BYTE*/ + d0=ATR_CRS(a0); /*COURSE $00 ~ $1F*/ + a1+=((Uint16)d0)*2; + + d1=(Sint32)(DELTA_TBL[a1]); /*H DELTA*/ + d1=d1<<8; + d5+=d1; + + d1=(Sint32)(DELTA_TBL[a1+1]); /*V DELTA*/ + d1=d1<<8; + d6+=d1; + + d3=(Sint32)(ATR_H_POS(a0)); + d4=(Sint32)(ATR_V_POS(a0)); + d1=d5>>16; + d2=d6>>16; + d1-=d3; + d2-=d4; + ATR_H_MINI(a0)=(int)((d5>>8)&0x000000ff); + ATR_V_MINI(a0)=(int)((d6>>8)&0x000000ff); + ATR_H_POS(a0)+=(int)d1; + ATR_V_POS(a0)+=(int)d2; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/handletime.cpp b/石器时代8.5客户端最新源代码/石器源码/system/handletime.cpp new file mode 100644 index 0000000..24065d7 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/handletime.cpp @@ -0,0 +1,145 @@ +#define __HANDLETIME_C__ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include +#include "../systeminc/handletime.h" + +//#ifdef _STONDEBUG_ +//(180)????1T +//#define LSTIME_SECONDS_PER_DAY 180 +//#else +//(750X12)????S??1T +#define LSTIME_SECONDS_PER_DAY 5400 /* LSTIME?T?????? */ +//#endif +/* + LSTIME_SECONDS_PER_DAY ????????????????????? + + k LS????T????????? + 9000 (?) 2.5 [hour] + 900 0.25[hour] = 15[min] + 90 0.025[hour] = 1.5[min] = 90[sec] + 9 9[sec] + +*/ + +#define LSTIME_HOURS_PER_DAY 1024 /* LSTIME?T???LSTIME???? */ +#define LSTIME_DAYS_PER_YEAR 100 /* LSTIME?g???LSTIME?T? */ + + +// ????????? +LSTIME SaTime; +long serverTime; +long FirstTime; +int SaTimeZoneNo; // ?????q +BOOL TimeZonePalChangeFlag; // ??q?????????????? +#if 0 +/*------------------------------------------------------------ + * ?????????????????? + * ?? + * ?? + * ?k + * ? TRUE(1) + * FALSE(0) + ------------------------------------------------------------*/ +BOOL setNewTime( void ) +{ + if( gettimeofday( &NowTime, (struct timezone*)NULL) != 0 ) + return FALSE; + NowTime.tv_sec += DEBUG_ADJUSTTIME; + return TRUE; +} +#endif + +/******************************************************************* +??T????byHiO 1998/12/4 18:37 +*******************************************************************/ +static long era = (long)912766409 + 5400; + /* SA??????? */ + /* LS?g?e?????????k? + ???????i?????????*/ + +/******************************************************************* + ???????LS????? + long t : time?? + LSTIME *lstime : LSTIME?Bl?????? +*******************************************************************/ +void RealTimeToSATime( LSTIME *lstime ) +{ + long lsseconds; /* LS?g???? */ + long lsdays; /* LS?g???T? */ + + //cary ʮ + lsseconds = (TimeGetTime()-FirstTime)/1000 + serverTime - era; + + /* ?g?????1g?????????g??? */ + lstime->year = (int)( lsseconds/(LSTIME_SECONDS_PER_DAY*LSTIME_DAYS_PER_YEAR) ); + + lsdays = lsseconds/LSTIME_SECONDS_PER_DAY;/* ???g???T????? */ + lstime->day = lsdays % LSTIME_DAYS_PER_YEAR;/* g????T?????????T*/ + + + /*(750*12)?1T*/ + lstime->hour = (int)(lsseconds % LSTIME_SECONDS_PER_DAY ) +/* ???????T???????????? */ + * LSTIME_HOURS_PER_DAY / LSTIME_SECONDS_PER_DAY; + /* ?T????????????T???????????????? + ????????*/ + + return; +} + +/******************************************************************* + LS???????????? + LSTIME *lstime : LSTIME?Bl?????? + long *t : ???????? +*******************************************************************/ +void LSTimeToRealTime( LSTIME *lstime, long *t) +{ + *t=(long)( + ( lstime->hour*LSTIME_DAYS_PER_YEAR+lstime->day) /* ?? */ + *LSTIME_HOURS_PER_DAY + + + lstime->year) + /*??????????????????nakamura */ + + + *450; + return; +} + +/******************************************************************* + LS?????????x? + ??k int : ?0?1??2??3 + LSTIME *lstime : LSTIME?Bl?????? +*******************************************************************/ +LSTIME_SECTION getLSTime (LSTIME *lstime) +{ + if (NIGHT_TO_MORNING < lstime->hour + && lstime->hour <= MORNING_TO_NOON) + return LS_MORNING; + else if(NOON_TO_EVENING < lstime->hour + && lstime->hour <= EVENING_TO_NIGHT) + return LS_EVENING; + else if(EVENING_TO_NIGHT < lstime->hour + && lstime->hour <= NIGHT_TO_MORNING) + return LS_NIGHT; + else + return LS_NOON; +} + +// ??q????????????? ***********************************/ +void TimeZoneProc( void ) +{ + int timeZoneNo; + //???????????x? + timeZoneNo = getLSTime ( &SaTime ); + // ??q????? + if( SaTimeZoneNo != timeZoneNo ){ + SaTimeZoneNo = timeZoneNo; // ??q? + // ??q???????????? + if( TimeZonePalChangeFlag == TRUE ){ + PaletteChange( SaTimeZoneNo, PAL_CHANGE_TIME );// ???????? + } + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/help.cpp b/石器时代8.5客户端最新源代码/石器源码/system/help.cpp new file mode 100644 index 0000000..2abba30 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/help.cpp @@ -0,0 +1,137 @@ +#include "../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/loadrealbin.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/login.h" +#include"../systeminc/menu.h" +#include"../systeminc/map.h" +#include"../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/t_music.h" +#include "../systeminc/field.h" +#include"../systeminc/netmain.h" +#include "../systeminc/lssproto_cli.h" + +#ifdef _ANGEL_SUMMON +short jumpHelpPage = 0; +short jumpHelpSeg = 0; +#endif + +#ifdef _JOBDAILY +extern JOBDAILY jobdaily[MAXMISSION]; +extern int JobdailyGetMax; +#endif +short HelpProcNo; +// return: 0 ... +// !0 ... +ACTION *ptActMenuWinHelp = NULL; +int HelpProc() +{ + static int btnId[3], btnState[3]; + static int x, y, w, h; + static int page = 0; + static int pageMax=0; + static int dwPressTime=0; + //ʼ + if( ptActMenuWinHelp ==NULL){ + dwPressTime=0; + page=0; + w = 420; + h = 380; + x = (lpDraw->xSize -w)/2; + y = (lpDraw->ySize -h)/2; + ptActMenuWinHelp = MakeWindowDisp( x, y, w, h, CG_FIELD_HELP_WND, -1, FALSE); + if(ptActMenuWinHelp){ + int i; + for(i=0;i<3;i++){ + btnId[i]=-2; + btnState[i]=0; + } +#ifdef _JOBDAILY + char look[10]; + strcpy(look,"dyedye"); + lssproto_JOBDAILY_send(sockfd,look); +#endif + } + } + //ʼ + if( ptActMenuWinHelp != NULL){ + if(ptActMenuWinHelp->hp>0){ + pageMax = JobdailyGetMax%10?JobdailyGetMax/10:JobdailyGetMax/10-1; + if( CheckMenuFlag()||((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL)||HelpProcNo == 1000){ + DeathAction( ptActMenuWinHelp); + ptActMenuWinHelp = NULL; + play_se( 203, 320, 240); //Ӵر + + return 1; + } + //Ӵͼ + StockDispBuffer( ((WINDOW_DISP *)ptActMenuWinHelp->pYobi)->mx, ((WINDOW_DISP *)ptActMenuWinHelp->pYobi)->my, DISP_PRIO_MENU, CG_FIELD_HELP_WND, 1); + int i; + + if(page>0) + btnId[0] = StockDispBuffer( x+207+32, y+352+10, DISP_PRIO_IME3, CG_FIELD_HELP_PREPAGE+btnState[0], 2); + else btnId[0]=-2; + if(page < pageMax) + btnId[1] = StockDispBuffer( x+277+32, y+352+10, DISP_PRIO_IME3, CG_FIELD_HELP_NEXTPAGE+btnState[1], 2); + else btnId[1]=-2; + btnId[2] = StockDispBuffer( x+347+32, y+352+10, DISP_PRIO_IME3, CG_FIELD_HELP_EXIT+btnState[2], 2); + + int id = selGraId( btnId, sizeof(btnId)/sizeof(int)); + if(id==0){ + dwPressTime = TimeGetTime(); + btnState[0]=1; + play_se( 217, 320, 240); + } + if(id==1){ + dwPressTime = TimeGetTime(); + btnState[1]=1; + play_se( 217, 320, 240); + } + if(id==2){ + dwPressTime = TimeGetTime(); + btnState[2]=1; + play_se( 203, 320, 240); + + return 1; + } + if( dwPressTime){ + if( TimeGetTime()>(dwPressTime+100)){ + dwPressTime=0; + if(btnState[0]){ + btnState[0]=0; + page--; + } + if(btnState[1]){ + btnState[1]=0; + page++; + } + if(btnState[2]){ + btnState[2]=0; + DeathAction( ptActMenuWinHelp); + ptActMenuWinHelp = NULL; + } + } + } + StockFontBuffer( x+20, y+35, FONT_PRIO_FRONT, FONT_PAL_GREEN, "־", 0); + StockFontBuffer(x+34 ,y+70,FONT_PRIO_FRONT,FONT_PAL_YELLOW," ˵ ״̬",0); + for( i = 0; i < 10; i++){ + char buf[10]; + sprintf_s(buf,"%d",jobdaily[i+page*10].JobId); + if(!atoi(buf)) buf[0] = '\0'; //ӡ0 + StockFontBuffer(x+34 ,y+(i+1)*25+70,FONT_PRIO_FRONT,FONT_PAL_WHITE,buf,0); + StockFontBuffer(x+34+30 ,y+(i+1)*25+70,FONT_PRIO_FRONT,FONT_PAL_WHITE,jobdaily[i+page*10].explain,0); + StockFontBuffer(x+34+328 ,y+(i+1)*25+70,FONT_PRIO_FRONT,FONT_PAL_WHITE,jobdaily[i+page*10].state,0); + } + return 0; + } + } + if( CheckMenuFlag()||((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL)||HelpProcNo == 1000){ + DeathAction( ptActMenuWinHelp); + ptActMenuWinHelp = NULL; + play_se( 203, 320, 240); //Ӵر + + return 1; + } +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/ime.cpp b/石器时代8.5客户端最新源代码/石器源码/system/ime.cpp new file mode 100644 index 0000000..eaa1013 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/ime.cpp @@ -0,0 +1,186 @@ +/************************/ +/* ime.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "winnls32.h" +#include "../systeminc/font.h" +#include "../other/caryIme.h" +#include "../systeminc/menu.h" +#include "../systeminc/battleMenu.h" +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif +#include "../systeminc/DirectDraw.h" +DWORD dwInfo; +void ShowBottomLineString(int iColor,LPSTR lpstr) +{ + LPSTR lpstr1=GetImeString(); + dwInfo = 0; + if(!lpstr1 && lpstr[0]!=0){ + dwInfo = 1; + StockFontBuffer( 8, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, iColor, lpstr, 0 ); + } +} + +// Terry add 2003/12/16 for Ӵʱ,ʾƷ˵ʾ뷨 +extern BOOL bShowItemExplain; +#ifdef _MO_SHOW_FPS +extern int framesToShow; +extern int skipFramesToShow; +#endif +// end +// 뷨Ĵ +void ImeProc() +{ + // ʾ뷨 +// Terry fix 2003/12/16 for Ӵʱ,ʾƷ˵ʾ뷨 + //if( TaskBarFlag == FALSE ){ иijһ + if(TaskBarFlag == FALSE && bShowItemExplain == FALSE){ +// end + LPSTR lpstr=GetImeString(); + LPSTR lpstr1; + if(lpstr){ +#ifdef _TELLCHANNEL + StockFontBuffer(8,420 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,FONT_PAL_WHITE,lpstr,0); +#else + StockFontBuffer(8,460 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,FONT_PAL_WHITE,lpstr,0); +#endif +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + } + lpstr1=GetImeDescString(); + if( 1!=dwInfo){ + if( lpstr1){ + char* BIG5ToGB2312(const char* szBIG5String); + extern int ; + extern int 忪; + if(忪){ + char [1024]={0}; + LCMapString(0x804,0x4000000,lpstr1, strlen(lpstr1),,1024); + if(==950) + StockFontBuffer(530-strlen(lpstr1)*(FONT_SIZE>>1) + DISPLACEMENT_X,460 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,0,BIG5ToGB2312((const char *)),0); + else + StockFontBuffer(530-strlen(lpstr1)*(FONT_SIZE>>1) + DISPLACEMENT_X,460 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,0,,0); + }else{ + if(==950) + StockFontBuffer(530-strlen(lpstr1)*(FONT_SIZE>>1) + DISPLACEMENT_X,460 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,0,BIG5ToGB2312((const char *)lpstr1),0); + else + StockFontBuffer(530-strlen(lpstr1)*(FONT_SIZE>>1) + DISPLACEMENT_X,460 + DISPLACEMENT_Y ,FONT_PRIO_FRONT,0,lpstr1,0); + } + } + + char tmp[64]; + extern DWORD dwPingTime, dwPingState; + if( dwPingState & 0x80000000){ + wsprintf( tmp, "*%d", dwPingTime); + dwPingState++; + if( (dwPingState&0xff) > 40) + dwPingState = 0; + }else + wsprintf( tmp, " %d", dwPingTime); + StockFontBuffer( 605 + DISPLACEMENT_X, 460 + DISPLACEMENT_Y , FONT_PRIO_FRONT, FONT_PAL_WHITE, tmp, 0 ); +#ifndef _REMAKE_20 + lpstr = "ģʽ"; + switch( AI){ + case AI_ATTACK: + lpstr = "ǿƹ"; + break; + case AI_GUARD: + lpstr = "ǿƷ"; + break; + case AI_SELECT: + lpstr = "ģʽ"; + break; + } + StockFontBuffer( 540 + DISPLACEMENT_X, 460 + DISPLACEMENT_Y , FONT_PRIO_FRONT, FONT_PAL_WHITE, lpstr, 0 ); +#endif +#ifdef _CHANNEL_MODIFY + int FontColor = 0 ; + switch(TalkMode){ + case 0: + lpstr1 = "һƵ"; + break; + case 1: + FontColor = FONT_PAL_GREEN; + lpstr1 = "Ƶ"; + break; + case 2: + FontColor = FONT_PAL_AQUA; + lpstr1 = "Ƶ"; + break; + case 3: + FontColor = FONT_PAL_PURPLE; + lpstr1 = "Ƶ"; + break; +#ifdef _CHAR_PROFESSION + case 4: + FontColor = FONT_PAL_BLUE2; + lpstr1 = "ְҵƵ"; + break; +#else + case 4: + FontColor = FONT_PAL_PURPLE; + lpstr1 = "Ƶ"; + break; +#endif +#ifdef _CHANNEL_WORLD + case 5: + FontColor = FONT_PAL_YELLOW; + lpstr1 = "Ƶ"; + break; +#endif +#ifdef _CHANNEL_ALL_SERV + case 6: + FontColor = FONT_PAL_GREEN2; + lpstr1 = "Ƶ"; + break; +#endif + } + StockFontBuffer( 10, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, FontColor, lpstr1, 0 ); +#else + #ifdef _TELLCHANNEL + int FontColor = 0 ; + switch(TalkMode){ + case 0: + lpstr1 = "һģʽ"; + break; + case 1: + FontColor = FONT_PAL_GREEN; + lpstr1 = "ģʽ"; + break; + #ifdef _FRIENDCHANNEL + case 2: + FontColor = FONT_PAL_PURPLE; + lpstr1 = "Ƶģʽ"; + break; + #endif +#ifdef _CHANNEL_WORLD + case 6: + FontColor = FONT_PAL_BLUE; + lpstr1 = "ģʽ"; + break; +#endif +#ifdef _CHANNEL_ALL_SERV + case 7: + FontColor = FONT_PAL_BLUE; + lpstr1 = "ģʽ"; + break; +#endif + } + StockFontBuffer( 10, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, FontColor, lpstr1, 0 ); + #endif +#endif +#ifdef _MO_SHOW_FPS + + wsprintf(tmp, "ǰFPS:%3d֡/ , ֡: %d֡/", framesToShow, skipFramesToShow); + StockFontBuffer( 270, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, tmp, 0 ); +#endif + } + } +// Terry add 2003/12/16 for Ӵʱ,ʾƷ˵ʾ뷨 + bShowItemExplain = FALSE; +// end +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/init.cpp b/石器时代8.5客户端最新源代码/石器源码/system/init.cpp new file mode 100644 index 0000000..ca73712 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/init.cpp @@ -0,0 +1,15 @@ +/************************/ +/* init.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +/* ??????? *************************************************************/ +void InitProc( void ) +{ + /* ???????? */ + InitAction(); + /* ????????? */ + SubProcNo = 0; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/loadrealbin.cpp b/石器时代8.5客户端最新源代码/石器源码/system/loadrealbin.cpp new file mode 100644 index 0000000..1f5e948 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/loadrealbin.cpp @@ -0,0 +1,505 @@ +#define UNPACK2 0 +#define WIN32_LEAN_AND_MEAN +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/unpack.h" + +#include +#include +#include +#include +#include +#include + +unsigned char autoMapColorTbl[MAX_GRAPHICS]; // ????????????????? + +#ifdef _STONDEBUG_ +extern int g_iMallocCount; +#endif + +unsigned long bitmapnumbertable[MAX_GRAPHICS]; + +#ifdef _PTTERN_SEPARATION_BIN +extern int MaxAdrnID; +FILE *Realbinfp[MAX_GRAPHICS] = {NULL}; +#else +FILE *Realbinfp; +#endif + +FILE *Addrbinfp; +ADRNBIN adrnbuff[MAX_GRAPHICS]; +#ifdef _READ16BITBMP +AddressBin_s adrntruebuff[MAX_GRAPHICS_24]; +HANDLE hAdrntrueFile; +HANDLE hRealtrueFile; +RGBQUAD g_rgbPal[256]; +#endif +void initAutoMapColor( char *addrbinfilename ) +{ + char *filename = "data\\auto.dat"; + if( readAutoMapColor( filename, addrbinfilename ) == 0 ){ + makeAutoMapColor(); + writeAutoMapColor( filename, addrbinfilename ); + } +} + +void makeAutoMapColor( void ) +{ + unsigned int i; + int chgTbl[20] = { + 166, 61, 80, 112, 96, 189, 112, 60, 164, 164, + 111, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + for( i = 0; i < MAX_GRAPHICS; i++ ){ + if( adrnbuff[i].attr.bmpnumber != 0 ){ + if( 100 <= adrnbuff[i].attr.bmpnumber && adrnbuff[i].attr.bmpnumber <= 19999 ){ + autoMapColorTbl[adrnbuff[i].attr.bmpnumber] = getAutoMapColor( adrnbuff[i].bitmapno ); + }else if( 60 <= adrnbuff[i].attr.bmpnumber && adrnbuff[i].attr.bmpnumber <= 79 ){ + autoMapColorTbl[adrnbuff[i].attr.bmpnumber] = (unsigned char)chgTbl[adrnbuff[i].attr.bmpnumber-60]; + }else{ + autoMapColorTbl[adrnbuff[i].attr.bmpnumber] = 0; + } + }else{ + autoMapColorTbl[adrnbuff[i].attr.bmpnumber] = 0; + } + } +} + +int writeAutoMapColor( char *wFName, char *addrbinfilename ) +{ + FILE *wfp, *rfp; + int rfh; + struct _stat statBuf; + int adrnNo; + unsigned int adrnTime; + unsigned short autoMapColorVersion = 4; + char *tmpStr; + + // adrn.bin??????k????? + tmpStr = strstr( addrbinfilename, "adrn" ); + if( tmpStr == NULL ) + return 0; // ???????? + if( tmpStr[4] == '.' ) + adrnNo = 0; // ????????? + else{ + adrnNo = -1; + sscanf_s( tmpStr, "adrn_%d.bin", &adrnNo ); + if( adrnNo < 0 ) + return 0; + } + // adrn.bin??ΦT???? + if( (rfp = fopen( addrbinfilename, "rb" )) == NULL ) + return 0; + rfh = _fileno( rfp ); + if( _fstat( rfh, &statBuf ) < 0 ){ + fclose( rfp ); + return 0; + } + adrnTime = (UINT)statBuf.st_ctime; + fclose( rfp ); + // ??????? + if( (wfp = fopen( wFName, "wb" )) == NULL ) + return 0; + fwrite( &autoMapColorVersion, sizeof( autoMapColorVersion ), 1, wfp ); + fwrite( &adrnNo, sizeof( adrnNo ), 1, wfp ); + fwrite( &adrnTime, sizeof( adrnTime ), 1, wfp ); + fwrite( &autoMapColorTbl, sizeof( autoMapColorTbl ), 1, wfp ); + fclose( wfp ); + return 1; +} + +int readAutoMapColor( char *wFName, char *addrbinfilename ) +{ + FILE *rfp; + int rfh; + struct _stat statBuf; + int adrnNo, rAdrnNo; + unsigned int adrnTime, rAdrnTime; + unsigned short autoMapColorVersion = 4, rAutoMapColorVersion; + char *tmpStr; + // adrn.bin??????k?x + tmpStr = strstr( addrbinfilename, "adrn" ); + if( tmpStr == NULL ) + return 0; // ???????? + if( tmpStr[4] == '.' ) + adrnNo = 0; // ????????? + else{ + adrnNo = -1; + sscanf_s( tmpStr, "adrn_%d.bin", &adrnNo ); + if( adrnNo < 0 ) + return 0; + } + // adrn.bin??ΦTx + if( (rfp = fopen( addrbinfilename, "rb" )) == NULL ) + return 0; + rfh = _fileno( rfp ); + if( _fstat( rfh, &statBuf ) < 0 ){ + fclose( rfp ); + return 0; + } + adrnTime = (UINT)statBuf.st_ctime; + fclose( rfp ); + if( (rfp = fopen( wFName, "rb" )) == NULL ) + return 0; + + if( fread( &rAutoMapColorVersion, sizeof( rAutoMapColorVersion ), 1, rfp ) != 1 ){ + fclose( rfp ); + return 0; + } + if( autoMapColorVersion != rAutoMapColorVersion ){ + fclose( rfp ); + return 0; + } + // adrn.bin???????? + if( fread( &rAdrnNo, sizeof( rAdrnNo ), 1, rfp ) != 1 ){ + fclose( rfp ); + return 0; + } + if( adrnNo != rAdrnNo ){ + fclose( rfp ); + return 0; + } + // adrn.bin????? + if( fread( &rAdrnTime, sizeof( rAdrnTime ), 1, rfp ) != 1 ){ + fclose( rfp ); + return 0; + } + if( adrnTime != rAdrnTime ){ + fclose( rfp ); + return 0; + } + if( fread( &autoMapColorTbl, sizeof( autoMapColorTbl ), 1, rfp ) != 1 ){ + fclose( rfp ); + return 0; + } + fclose( rfp ); + return TRUE; +} + +BOOL initRealbinFileOpen(char *realbinfilename, char *addrbinfilename) +{ + ADRNBIN tmpadrnbuff; + if ((Addrbinfp = fopen(addrbinfilename, "rb"))==NULL) + return FALSE; +#ifdef _PTTERN_SEPARATION_BIN + FILE *Realfp; + if ((Realfp = fopen(realbinfilename, "rb"))==NULL) + return FALSE; +#else + if ((fopen_s(&Realbinfp,realbinfilename, "rb"))!=NULL) + return FALSE; +#endif + //adrn.bin + while(!feof(Addrbinfp)){ + fread(&tmpadrnbuff, sizeof(tmpadrnbuff), 1, Addrbinfp); + adrnbuff[tmpadrnbuff.bitmapno] = tmpadrnbuff; + +#ifdef _PTTERN_SEPARATION_BIN + Realbinfp[tmpadrnbuff.bitmapno] = Realfp; + if((ULONG)MaxAdrnID < tmpadrnbuff.bitmapno){ + MaxAdrnID = tmpadrnbuff.bitmapno; + } +#endif + if( tmpadrnbuff.attr.bmpnumber != 0 ){ + if( (12802 <= tmpadrnbuff.attr.bmpnumber && tmpadrnbuff.attr.bmpnumber <= 12811) + || (10132 <= tmpadrnbuff.attr.bmpnumber && tmpadrnbuff.attr.bmpnumber <= 10136) ){ + adrnbuff[tmpadrnbuff.bitmapno].attr.hit = + 300 + (adrnbuff[tmpadrnbuff.bitmapno].attr.hit % 100); + } + if( tmpadrnbuff.attr.bmpnumber<=33 && tmpadrnbuff.bitmapno>230000){//ħͼŸbug + continue; + } + bitmapnumbertable[tmpadrnbuff.attr.bmpnumber] = tmpadrnbuff.bitmapno; + }else + bitmapnumbertable[tmpadrnbuff.attr.bmpnumber] = 0; + } + fclose(Addrbinfp); + return TRUE; +} + +void cleanupRealbin(void) +{ +#ifdef _PTTERN_SEPARATION_BIN + for(int i = 0; i < MAX_GRAPHICS; i ++){ + if(Realbinfp[i] != NULL){ + fclose(Realbinfp[i]); + Realbinfp[i] = NULL; + } + } +#else + fclose(Realbinfp); +#endif + +#ifdef _READ16BITBMP + CloseHandle(hRealtrueFile); +#endif +} + +BOOL realGetPos(U4 GraphicNo , S2 *x , S2 *y) +{ +#ifndef _READ16BITBMP + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){*x=0;*y=0;return FALSE;} + *x = adrnbuff[GraphicNo].xoffset; + *y = adrnbuff[GraphicNo].yoffset; +#else + if(GraphicNo < 0) {*x=0;*y=0;return FALSE;} + if(GraphicNo >= OLD_GRAPHICS_START){ + if(GraphicNo > MAX_GRAPHICS) {*x=0;*y=0;return FALSE;} + *x = adrntruebuff[GraphicNo - OLD_GRAPHICS_START].xoffset; + *y = adrntruebuff[GraphicNo - OLD_GRAPHICS_START].yoffset; + } + else{ + *x = adrnbuff[GraphicNo].xoffset; + *y = adrnbuff[GraphicNo].yoffset; + } +#endif + return TRUE; +} + +BOOL realGetWH(U4 GraphicNo , S2 *w , S2 *h) +{ +#ifndef _READ16BITBMP + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){*w=0;*h=0;return FALSE;} + *w = adrnbuff[GraphicNo].width; + *h = adrnbuff[GraphicNo].height; +#else + if(GraphicNo < 0){*w=0;*h=0;return FALSE;} + if(GraphicNo >= OLD_GRAPHICS_START){ + if(GraphicNo > MAX_GRAPHICS) {*w=0;*h=0;return FALSE;} + *w = adrntruebuff[GraphicNo - OLD_GRAPHICS_START].width; + *h = adrntruebuff[GraphicNo - OLD_GRAPHICS_START].height; + } + else{ + *w = adrnbuff[GraphicNo].width; + *h = adrnbuff[GraphicNo].height; + } +#endif + + return TRUE; +} + +BOOL realGetHitPoints(U4 GraphicNo , S2 *HitX , S2 *HitY) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){*HitX=0;*HitY=0;return FALSE;} + + *HitX = adrnbuff[GraphicNo].attr.atari_x; + *HitY = adrnbuff[GraphicNo].attr.atari_y; + + return TRUE; +} + +BOOL realGetHitFlag(U4 GraphicNo , S2 *Hit) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){ + *Hit=0; + return FALSE; + } + + if ((GraphicNo >= 369715 && GraphicNo <= 369847) || GraphicNo == 369941)//ǿƵر + *Hit = 1; + else if (GraphicNo >= 369641 && GraphicNo <= 369654) + *Hit = 1; + else + *Hit = (adrnbuff[GraphicNo].attr.hit % 100); + + return TRUE; +} + +BOOL realGetPrioType(U4 GraphicNo , S2 *prioType) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){ + *prioType=0; + return FALSE; + } + + *prioType = (adrnbuff[GraphicNo].attr.hit / 100); + return TRUE; +} + +BOOL realGetHeightFlag(U4 GraphicNo , S2 *Height) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){*Height=0;return FALSE;} + *Height = adrnbuff[GraphicNo].attr.height; + + return TRUE; +} + +int realGetSoundEffect(U4 GraphicNo) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS)return FALSE; + return adrnbuff[bitmapnumbertable[GraphicNo]].attr.effect1; + +} + +BOOL realGetWalkSoundEffect(U4 GraphicNo ) +{ + if(GraphicNo<0 || GraphicNo>=MAX_GRAPHICS){return FALSE;} + return adrnbuff[GraphicNo].attr.effect2; + +} + +BOOL realGetNo( U4 CharAction , U4 *GraphicNo ) +{ +#ifndef _READ16BITBMP + if(CharAction<0 || CharAction>=MAX_GRAPHICS){*GraphicNo=0;return FALSE;} + *GraphicNo = bitmapnumbertable[CharAction]; + return TRUE; +#else + if(CharAction < 0){ + *GraphicNo = 0; + return FALSE; + } + if(CharAction >= OLD_GRAPHICS_START){ + if(CharAction >= MAX_GRAPHICS){ + *GraphicNo = 0; + return FALSE; + } + *GraphicNo = CharAction; + return TRUE; + } + else *GraphicNo = bitmapnumbertable[CharAction]; + return TRUE; +#endif +} + +int realGetBitmapNo( int num ) +{ +#ifndef _READ16BITBMP + if( num < 0 || num >= MAX_GRAPHICS ) return -1; + return adrnbuff[num].attr.bmpnumber; +#else + if(num < 0) return -1; + if(num >= OLD_GRAPHICS_START){ + if(num >= MAX_GRAPHICS) return -1; + return adrntruebuff[num - OLD_GRAPHICS_START].bitmapno; + } + else return adrnbuff[num].attr.bmpnumber; +#endif +} + +///////////////////////////////////////////////////////////////////?????????? +#define REALGETIMAGEMAXSIZE 1600*1600 +BYTE g_realgetimagebuf[REALGETIMAGEMAXSIZE]; +BYTE g_realgetimagebuf2[REALGETIMAGEMAXSIZE]; +#ifdef _NEW_COLOR_ +int NewColor16Flg; +#endif +BOOL realGetImage( int graphicNo, unsigned char **bmpdata, int *width, int *height) +{ +#ifdef _NEW_COLOR_ + NewColor16Flg=0; +#endif + ADRNBIN adrdata; + if(graphicNo<0 || graphicNo>=MAX_GRAPHICS)return FALSE; + adrdata=adrnbuff[graphicNo]; +#ifdef _PTTERN_SEPARATION_BIN + if (Realbinfp[graphicNo]==NULL) return FALSE; + fseek(Realbinfp[graphicNo], adrdata.adder, SEEK_SET);//real.bin??????????? + if( fread(&g_realgetimagebuf, adrdata.size, 1, Realbinfp[graphicNo] ) != 1 ) + return FALSE; +#else + fseek(Realbinfp, adrdata.adder, SEEK_SET);//real.bin??????????? + if( fread(&g_realgetimagebuf, adrdata.size, 1, Realbinfp ) != 1 ) + return FALSE; +#endif + unsigned int len; + *bmpdata = g_realgetimagebuf2; + if( decoder( g_realgetimagebuf, bmpdata, + (unsigned int*)width, (unsigned int*)height, &len ) == NULL ){ + return FALSE; + } + return TRUE; +} + +#ifdef _READ16BITBMP +int InitRealTruebinFileOpen(char *szRealTrueBinFileName,char *szAdrnTruebinFileName) +{ + BOOL bReadReturn; + AddressBin_s Addr; + DWORD dwReadByte; + + ZeroMemory(adrntruebuff,sizeof(adrntruebuff)); + // + hAdrntrueFile = CreateFile(szAdrnTruebinFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); + if(hAdrntrueFile == INVALID_HANDLE_VALUE) return -1; + hRealtrueFile = CreateFile(szRealTrueBinFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); + if(hRealtrueFile == INVALID_HANDLE_VALUE){ + CloseHandle(hAdrntrueFile); + return -2; + } + + while(1){ + // ѵڵ϶ + bReadReturn = ReadFile(hAdrntrueFile,&Addr,sizeof(AddressBin_s),&dwReadByte,NULL); + // ϶ + if(bReadReturn && dwReadByte == 0) break; + // + if(dwReadByte == 0) break; + memcpy(&adrntruebuff[Addr.bitmapno],&Addr,sizeof(AddressBin_s)); + } + CloseHandle(hAdrntrueFile); + return 0; +} + +// BmpNo ֵǼȥ OLD_GRAPHICS_START ֵ,ȫʵͼҵͼ +BOOL Read16BMP(int BmpNo,unsigned char **BmpData,int *width,int *height,BYTE **AlphaData,BOOL *useAlpha) +{ + BOOL bRet = TRUE,bReadReturn; + AddressBin_s *pAddr; + unsigned char *pBmpData; + unsigned int len,iw = 0,ih = 0; + DWORD dwReadByte; + + if(BmpNo > MAX_GRAPHICS_24) return FALSE; + pAddr = &adrntruebuff[BmpNo]; + // ƵҪȡͼλ + SetFilePointer(hRealtrueFile,pAddr->adder,NULL,FILE_BEGIN); + pBmpData = (unsigned char*)MALLOC(pAddr->size); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + if(pBmpData == NULL) return FALSE; + else{ + memset(g_rgbPal,0,sizeof(g_rgbPal)); + // ȶɫ + bReadReturn = ReadFile(hRealtrueFile,g_rgbPal,pAddr->palSize+sizeof(RGBQUAD),&dwReadByte,NULL); + // ʧ + if(bReadReturn && dwReadByte == 0) bRet = FALSE; + // ͼ϶ + bReadReturn = ReadFile(hRealtrueFile,pBmpData,pAddr->size,&dwReadByte,NULL); + // ʧ + if(bReadReturn && dwReadByte == 0) bRet = FALSE; + else{ + *BmpData = g_realgetimagebuf2; + if(decoder(pBmpData,BmpData,(unsigned int*)width,(unsigned int*)height,&len) == NULL) bRet = FALSE; + } + FREE(pBmpData); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + // alpha϶ + *useAlpha = FALSE; + if(pAddr->alpha_size > 0){ + pBmpData = (unsigned char*)MALLOC(pAddr->alpha_size); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + if(pBmpData == NULL) return FALSE; + bReadReturn = ReadFile(hRealtrueFile,pBmpData,pAddr->alpha_size,&dwReadByte,NULL); + // ʧ + if(bReadReturn && dwReadByte == 0) bRet = FALSE; + else{ + *AlphaData = g_realgetimagebuf; + if(decoder(pBmpData,AlphaData,&iw,&ih,&len) == NULL) bRet = FALSE; + } + FREE(pBmpData); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + *useAlpha = TRUE; + } + } + + return bRet; +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/loadsprbin.cpp b/石器时代8.5客户端最新源代码/石器源码/system/loadsprbin.cpp new file mode 100644 index 0000000..ee92ce3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/loadsprbin.cpp @@ -0,0 +1,167 @@ +#define sprVERSION 3 //SPR ? n?????? +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/anim_tbl.h" + +#include "../oft/vg410.h" +#include "../oft/work.h" + +#define ERRPRINT(a); + +SPRITEDATA SpriteData[mxSPRITE]; +extern int nextMaxAdrnID; +BOOL InitSprBinFileOpen(char *SPR_BIN, char *SPRADRN_BIN) +{ + SPRADRN _spradrn; + ANIM_HEADER sprhead; + FRAMELIST sprdata; + FILE *fp1, *fp2; + int j; + unsigned int k; + if ((fp1 = fopen(SPR_BIN, "rb")) == NULL) + return FALSE; + if ((fp2 = fopen(SPRADRN_BIN, "rb")) == NULL) + return FALSE; + static BOOL Sprflg = TRUE; + static BOOL Sprflg1 = TRUE; + if (Sprflg){ + Sprflg = FALSE; + memset(SpriteData, 0, sizeof(SpriteData)); + } + int no = 0; + while (TRUE){ + fread(&_spradrn, 1, sizeof(_spradrn), fp2); + if (feof(fp2) != 0) + break; + no = _spradrn.sprNo - SPRSTART; + if (no > mxSPRITE) break; + SpriteData[no].animSize = _spradrn.animSize; + SpriteData[no].ptAnimlist = (ANIMLIST*)calloc(SpriteData[no].animSize, sizeof(ANIMLIST)); + fseek(fp1, _spradrn.offset, SEEK_SET); + for (j = 0; j < SpriteData[no].animSize; j++){ + fread(&sprhead, 1, 12, fp1); + SpriteData[no].ptAnimlist[j].dir = sprhead.dir; + SpriteData[no].ptAnimlist[j].no = sprhead.no; + if (!sprhead.frameCnt) SpriteData[no].ptAnimlist[j].dtAnim = 0; + else SpriteData[no].ptAnimlist[j].dtAnim = sprhead.dtAnim / sprhead.frameCnt / 16; + SpriteData[no].ptAnimlist[j].frameCnt = sprhead.frameCnt; + SpriteData[no].ptAnimlist[j].ptFramelist = (FRAMELIST*)calloc(SpriteData[no].ptAnimlist[j].frameCnt, sizeof(FRAMELIST)); + for (k = 0; k < SpriteData[no].ptAnimlist[j].frameCnt; k++){ + fread(&sprdata, 1, 10, fp1); + SpriteData[no].ptAnimlist[j].ptFramelist[k].BmpNo = sprdata.BmpNo + nextMaxAdrnID; + SpriteData[no].ptAnimlist[j].ptFramelist[k].PosX = sprdata.PosX; + SpriteData[no].ptAnimlist[j].ptFramelist[k].PosY = sprdata.PosY; + SpriteData[no].ptAnimlist[j].ptFramelist[k].SoundNo = sprdata.SoundNo; + } + } + if (no == 1059) SpriteData[1059].ptAnimlist[80].ptFramelist[8].BmpNo = 283639; + if (no == 1059) SpriteData[1059].ptAnimlist[93].ptFramelist[8].BmpNo = 283640; + if (no == 1283) SpriteData[1283].ptAnimlist[7].ptFramelist[6].SoundNo = 10100; + if (no == 1283) SpriteData[1283].ptAnimlist[49].ptFramelist[6].SoundNo = 10100; + if (no == 1404) SpriteData[1404].ptAnimlist[0].ptFramelist[6].BmpNo = 284436; + if (no == 1409) SpriteData[1409].ptAnimlist[0].ptFramelist[6].BmpNo = 284476; + if (no == 373) + for (int kk = 0; kk < 8; kk++) { + SpriteData[373].ptAnimlist[kk * 7].ptFramelist[8].SoundNo = 254; + SpriteData[373].ptAnimlist[kk * 7].ptFramelist[10].SoundNo = 254; + SpriteData[373].ptAnimlist[kk * 7].ptFramelist[15].SoundNo = 250; + } + if (no == 102) SpriteData[102].ptAnimlist[82].ptFramelist[0].BmpNo = 126235; + if (no == 102) SpriteData[102].ptAnimlist[83].ptFramelist[0].BmpNo = 126236; + if (no == 102) SpriteData[102].ptAnimlist[83].ptFramelist[1].BmpNo = 126237; + if (no == 102) SpriteData[102].ptAnimlist[84].ptFramelist[1].BmpNo = 126238; + if (no == 1058) SpriteData[1058].ptAnimlist[80].ptFramelist[8].BmpNo = 232475; + if (no == 1058) SpriteData[1058].ptAnimlist[93].ptFramelist[8].BmpNo = 232476; + + if (no == 260) SpriteData[260].ptAnimlist[21].ptFramelist[5].SoundNo = 10001; + if (no == 502) SpriteData[502].animSize = 1; + if (no == 502) SpriteData[502].ptAnimlist = (ANIMLIST*)calloc(SpriteData[502].animSize, sizeof(ANIMLIST)); + if (no == 502) SpriteData[502].ptAnimlist[0].dir = 0; + if (no == 502) SpriteData[502].ptAnimlist[0].no = 0; + if (no == 502) SpriteData[502].ptAnimlist[0].dtAnim = 4; + if (no == 502) SpriteData[502].ptAnimlist[0].frameCnt = 3; + if (no == 502) SpriteData[502].ptAnimlist[0].ptFramelist = (FRAMELIST*)calloc(SpriteData[502].ptAnimlist[0].frameCnt, sizeof(FRAMELIST)); + int iTemp = 8590; + if (no == 382){ + for (int kkk = 0; kkk < 8; kkk++){ + SpriteData[382].ptAnimlist[7 * kkk].frameCnt = 14; + free(SpriteData[382].ptAnimlist[7 * kkk].ptFramelist); + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist = (FRAMELIST*)calloc(SpriteData[382].ptAnimlist[7 * kkk].frameCnt, sizeof(FRAMELIST)); + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[4].SoundNo = SpriteData[381].ptAnimlist[0].ptFramelist[4].SoundNo; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[9].SoundNo = SpriteData[381].ptAnimlist[0].ptFramelist[9].SoundNo; + SpriteData[382].ptAnimlist[7 * kkk].dtAnim = SpriteData[381].ptAnimlist[0].dtAnim; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[0].BmpNo = 124604 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[1].BmpNo = 124605 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[2].BmpNo = 124606 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[3].BmpNo = 124607 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[4].BmpNo = 124608 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[5].BmpNo = 124609 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[6].BmpNo = 124610 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[7].BmpNo = 124611 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[8].BmpNo = 124607 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[9].BmpNo = 124608 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[10].BmpNo = 124609 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[11].BmpNo = 124610 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[12].BmpNo = 124611 + kkk * 29; + SpriteData[382].ptAnimlist[7 * kkk].ptFramelist[13].BmpNo = 124604 + kkk * 29; + } + } + if (no == 502) + for (k = 0; k < SpriteData[502].ptAnimlist[0].frameCnt; k++){ + SpriteData[502].ptAnimlist[0].ptFramelist[k].BmpNo = iTemp++; + SpriteData[502].ptAnimlist[0].ptFramelist[k].PosX = 0; + SpriteData[502].ptAnimlist[0].ptFramelist[k].PosY = 0; + SpriteData[502].ptAnimlist[0].ptFramelist[k].SoundNo = 0; + } + + + //Change fix Ͷû趨SoundNo,սʱᵱ + if (no >= 1965 && no < 1987) { + //for(int kk=1965;kk<1987;kk++) + //{ + SpriteData[no].ptAnimlist[9].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[22].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[35].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[48].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[61].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[74].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[87].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[100].ptFramelist[4].SoundNo = 10006; + //} + } + if (no >= 1988 && no < 1990) { + //for(int kk=1988;kk<1990;kk++) + //{ + SpriteData[no].ptAnimlist[9].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[22].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[35].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[48].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[61].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[74].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[87].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[100].ptFramelist[4].SoundNo = 10006; + //} + } + + if (no >= 3347 && no <= 3370) + { + SpriteData[no].ptAnimlist[9].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[22].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[35].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[48].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[61].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[74].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[87].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[100].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[52].ptFramelist[4].SoundNo = 10006; + SpriteData[no].ptAnimlist[39].ptFramelist[5].SoundNo = 10006; + } + } + fclose(fp1); + fclose(fp2); + if (Sprflg1){ + Sprflg1 = FALSE; + } + return TRUE; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/login.cpp b/石器时代8.5客户端最新源代码/石器源码/system/login.cpp new file mode 100644 index 0000000..89a88b5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/login.cpp @@ -0,0 +1,21687 @@ +#include +#include +#include"../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/process.h" +#include"../systeminc/netproc.h" +#include"../systeminc/netmain.h" +#include"../systeminc/pc.h" +#include"../systeminc/tool.h" +#include"../systeminc/character.h" +#include"../systeminc/loadsprbin.h" +#include"../systeminc/savedata.h" +#include"../systeminc/chat.h" +#include "../other/caryIme.h" +#include "../systeminc/ime_sa.h" +#include"../systeminc/menu.h" +#include"../systeminc/t_music.h" +#include"../systeminc/VMProtectSDK.h" +#include"../systeminc/netmain.h" +#include"../systeminc/map.h" +#include"../systeminc/lssproto_cli.h" +#include"../systeminc/field.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/login.h" +#include"../systeminc/produce.h" +#include"../wgs/message.h" +#include"../wgs/descrypt.h" +#include "../mylua/winlua.h" +#include "../openssl/md5.h" +#include "../newproto/autil.h" +#ifdef _SHOWIPSLEEP_ +#include "../other/readip.h" +#endif +#ifdef _SAHOOK //Syu ADD Hook程式 +#include "..\Sa_Hk.h" +#define UM_KEYEVENT (WM_APP + 0) +#endif +#ifdef _SHOWIPSLEEP_ +#include "../wgs/Ping.h" +#endif +#ifdef _MORECHARACTERS_ +int 多人物当前页数; +#endif + +extern int 编码; +#define SA_VERSION "" +#define SA_VERSION_NUM 300 +#ifdef _AIDENGLU_ +extern Landed PcLanded; +#endif +int nGroup = 0; +int nServerGroup = 0; +#ifdef _LOGIP_ +char 玩家公网IP[128]; +#endif +BOOL logOutFlag = FALSE; +unsigned int MsgCooltime = 0; + +short createCharFlag = 0; +char szUser[32]; +char szPassword[32]; + +void initInputIdPassword(void); +int inputIdPassword(BOOL); +void initCommonMsgWin(void); +int commonMsgWin(char *); +void initCertifyIdPassword(void); +void initSelectServer(void); +int selectGroup(); +int selectServer(); +void initConnecGameServer(void); +int connecGameServer(void); +void initDownloadCharList(void); +int downloadCharList(void); +void initDeleteCharacter(void); +int deleteCharacter(void); +int commonYesNoWindow(int, int); +// add code by shan +int fmYesNoWindow(int x, int y, int id); +int fmselectdetuyWindow(int x, int y, int id); +void initStrBuffer(STR_BUFFER *, int, int, int, int, int); +void getStrSplit(char *, char *, int, int, int); +int DelCharGraColorWin(void); + +#ifdef _PET_TRACE_MOUSE +SCPlayPet PlayPet; +#endif +#ifdef _75_LOGIN +static ACTION *aEffect,*aEffect1; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +#endif +// Terry add 2001/12/07 +#ifdef __EDEN_EFFECT +void BankProc(void); +#endif +#ifdef _NEWSHOP_ +ACTION* 商城动作地址; +#endif +#ifdef _ICONBUTTONS_ +extern ACTION*转盘动作地址; +#endif +#ifdef _CHARSIGNDAY_ +extern ACTION*签到动作地址; +#endif +#ifdef _MAGIC_ITEM_ +extern ACTION* MagicItemActAddr; +extern ACTION* ShowMagicItemData(); +extern ACTION* CreateMagicItemWin(); +extern void InitMagicItemWin(char * 内容); +#endif + +// Terry end +// Terry add 2002/01/03 +#ifdef __EDEN_AUCTION +void AuctionNewWT(void); +void AuctionListWT(void); +void AuctionSurveyModifyWT(void); +void AuctionModifyWT(void); +// server所传来的资料 +typedef struct _AUCTION_LIST_DATA +{ + int index; // 委托的玩家的索引号码 + char cdkey[CHAR_NAME_LEN + 1]; // 玩家的cdkey + char account[101]; // 委托内容 + char name[CHAR_NAME_LEN + 1]; // 委托人的名字 + char money[8]; // 价钱 + int kind; // 卖宠物或是物品 + char sellname[ITEM_NAME_LEN + 1]; // 宠物或是物品的名称 + int grp_no; // 宠物或是物品的图号 + int lv, act, def, dex, hp, loyal; // 宠物的资料 + int name_color; // 道具名称的颜色 + char item_effect_string[64]; // 道具叙述 +}ALD, *pALD; + +char *szpALD = NULL; // server传来的资料内容 +BOOL bNewData = FALSE; // 是否有新的资料传来 +void AuctionGetString(int nWhichOne, pALD ald); //处理字串的分析 +void CheckNumber(char *buf, int num); // 处理非数字的输入 +void CheckSpace(char *buf); // 处理空白的输入 +#endif + +#ifdef _SAHOOK //Syu ADD Hook程式 +bool hookflag = false; +#endif + +static int selCharGraColorWinProcNo; + +short skillShopWindow4ProcNo; +short skillShopWindow1ProcNo; + + +STR_BUFFER idKey; +STR_BUFFER passwd; +static STR_BUFFER *idPasswordFocus[] = +{ &idKey, &passwd }; +STR_BUFFER *idPasswordStr = &idKey; +short idKeyReturn = 0; +static int idPasswordGraId[] = { -2, -2 }; +static int idPasswordFocusSw = 0; +static short idKeyBoxX, idKeyBoxY; +static short passwdBoxX, passwdBoxY; +BOOL bAgain = FALSE; +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 +static ACTION *pActPet20; +int BornPetNum = 0; +#endif +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 +ACTION *PkServerSel; +short PkMenuflag = 0 ; +int VersionXYZ = 1 ; //Pk Server版本号 +#endif +// Nuke 0615: Avoid 7's lock +extern int isWGS7; +#ifdef _LOGINKICK +DWORD StartTime = -1; +#endif +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif +#ifdef _NEW_COLOR_ +extern BOOL g_bUseAlpha; +#endif + + + +void idPasswordProc(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + + BOOL flag = FALSE; + int ret; + static char msg[256]; + static char szWGSState[] = "登入游戏中,请稍候!"; + + if (SubProcNo == 0){ +#ifdef __NEW_CLIENT + extern HANDLE hPing; + extern SOCKET sockRaw; + if( hPing){ + closesocket( sockRaw); + sockRaw = INVALID_SOCKET; + TerminateThread( hPing, 0); + CloseHandle( hPing); + hPing = NULL; + } +#endif +#ifndef _STONDEBUG_ + Sleep(0); +#endif + PaletteChange(DEF_PAL, 0); + SubProcNo++; + initInputIdPassword(); + idKeyReturn = 0; +#ifdef _PET_TRACE_MOUSE + PlayPet.SetActionStep(0); +#endif + } + if (SubProcNo == 1){ + if (!bAgain) + bAgain = TRUE; + else{ + //启动Hook程式 +#ifdef _SAHOOK //Syu ADD Hook程式 + if( hookflag == false) + { + hookflag = true; + KeyboardHook_Start(hWnd, UM_KEYEVENT); + } + //以下无用 + CopyMemory(idKey.buffer,szUser,32); + ecb_crypt("f;encor1c",idKey.buffer,32,DES_DECRYPT); + CopyMemory(passwd.buffer,szPassword,32); + ecb_crypt("f;encor1c",passwd.buffer,32,DES_DECRYPT); + idKey.cursor=idKey.cnt=strlen(idKey.buffer); + passwd.cursor=passwd.cnt=strlen(passwd.buffer); +#else + CopyMemory(idKey.buffer, szUser, 32); + ecb_crypt("f;encor1c", idKey.buffer, 32, DES_DECRYPT); + CopyMemory(passwd.buffer, szPassword, 32); + ecb_crypt("f;encor1c", passwd.buffer, 32, DES_DECRYPT); + idKey.cursor = idKey.cnt = strlen(idKey.buffer); + passwd.cursor = passwd.cnt = strlen(passwd.buffer); +#endif + } + idPasswordFocusSw = 0; + GetKeyInputFocus(idPasswordFocus[idPasswordFocusSw]); + SubProcNo++; + } + + // 可以输入 + if (SubProcNo == 2) + flag = TRUE; // 可以输入 + + ret = inputIdPassword(flag); + + if (ret == 1){ +#ifdef _LOGIP_ + memset(玩家公网IP,0,128); + extern BOOL 获取IP(char *IP); + if(!获取IP(玩家公网IP)){ + SubProcNo = 100; + ret = -1; + strcpy( msg, "获取游戏线路失败,请重新尝试!" ); + }else +#endif + { + SubProcNo = 3; + play_se(217, 320, 240); + } + + } + else if (ret == 2){ + play_se(217, 320, 240); // ????? + PostMessage(hWnd, WM_CLOSE, 0, 0L); + } + else if (ret < 0){ + SubProcNo = 100; + strcpy(msg, "请输入您的帐号与密码!"); + } + if (SubProcNo == 3){ +#ifdef _STONDEBUG_ + w = (strlen( szWGSState )+23)*9/64+2; +#else + w = (strlen(szWGSState) + 3) * 9 / 64 + 2; +#endif + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); + +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + initConnectServer(); + SubProcNo = 4; +#ifdef _PET_TRACE_MOUSE + PlayPet.SetActionStep(2); +#endif +#ifdef _75_LOGIN + if(g_bUseAlpha){ + DeathAction(aEffect); + DeathAction(aEffect1); + } +#endif + } + if (SubProcNo == 4){ + if (ptActMenuWin != NULL){ + if (ptActMenuWin->hp >= 1){ + int len; + int xx, yy; + if (iWGS == 7) isWGS7 = 1; // Nuke 0615: Avoid 7's lock + +#ifdef _STONDEBUG_ + switch(iWGS){ + case 0: + wsprintf(msg,"%s",szWGSState); + break; + case 1: //连接WGS + wsprintf(msg,"%s(%s)",szWGSState,"Connect to WGS!!"); + break; + case 2: //取得CSIP + wsprintf(msg,"%s(%s)",szWGSState,"Get the Redirect!!"); + break; + case 3: //连接CS + wsprintf(msg,"%s(%s)",szWGSState,"Connect to CS!!"); + break; + case 4: //取得Public key(加密) + wsprintf(msg,"%s(%s)",szWGSState,"Get the Public key!!"); + break; + case 5: //取得Session key(解密) + wsprintf(msg,"%s(%s)",szWGSState,"Send the Session key!!"); + break; + case 6: //取得连接GS表单 + wsprintf(msg,"%s(%s)",szWGSState,"Get Continue!!"); + break; + case 7: //传送帐号、密码 + wsprintf(msg,"%s(%s)",szWGSState,"Send UserName!!"); + break; + case 8: + wsprintf(msg,"%s(%s)",szWGSState,"Get Goto!!"); + break; + } +#else + wsprintf(msg, "%s(%d)", szWGSState, iWGS); +#endif + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } +#ifdef NO_WGS + int ret2 = 1; + dwServer = GS; + //void SetTestServer(); + //SetTestServer(); +#else + int ret2 = ConnectWGS(); +#endif + if (ret2 == 1){ + // 处理Title + CopyMemory(szUser, idKey.buffer, 32); + ecb_crypt("f;encor1c", szUser, 32, DES_ENCRYPT); + CopyMemory(szPassword, passwd.buffer, 32); + ecb_crypt("f;encor1c", szPassword, 32, DES_ENCRYPT); + idKey.cnt = 0; + idKey.cursor = 0; + ZeroMemory(idKey.buffer, sizeof(idKey.buffer)); + passwd.cnt = 0; + passwd.cursor = 0; + ZeroMemory(passwd.buffer, sizeof(passwd.buffer)); + ChangeProc(PROC_TITLE_MENU); + if (ptActMenuWin){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + + } + else if (ret2 == -7){ + SubProcNo = 100; + strcpy(msg, szError); + } + else if (ret2 < 0){ + SubProcNo = 100; +#ifdef _AIDENGLU_ + PcLanded.登陆延时时间 = TimeGetTime() + 2000; +#endif + strcpy(msg, netprocErrmsg); + } + else if (ret2 == -8){ + SubProcNo = 100; + strcpy(msg, szError); + } + } + if (SubProcNo == 5) + { + SubProcNo = 100; + strcpy(msg, "输入的账号或密码错误\n请再次输入!"); + } + if (SubProcNo == 100){ + cleanupNetwork(); + if (ptActMenuWin){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101){ + if (commonMsgWin(msg)){ + // OK???????? + //错误讯息回到Title画面重新启动Hook +#ifdef _SAHOOK //Syu ADD Hook程式 + if( hookflag == false) + { + hookflag = true; + KeyboardHook_Start(hWnd, UM_KEYEVENT); + } +#endif + SubProcNo = 2; + Sleep(1000); + } + } +} + +// ???????????????? +void initInputIdPassword(void) +{ + int i; + + for (i = 0; i < sizeof(idPasswordGraId) / sizeof(int); i++) + { + idPasswordGraId[i] = -2; + } + + idKeyBoxX = 364; + idKeyBoxY = 253; + initStrBuffer( &idKey, idKeyBoxX, idKeyBoxY, 18, FONT_PAL_WHITE, FONT_PRIO_BACK ); + idKey.cnt = 0; + idKey.cursor=0; + passwdBoxX = 364; + passwdBoxY = 286; + initStrBuffer( &passwd, passwdBoxX, passwdBoxY, 18, FONT_PAL_WHITE, FONT_PRIO_BACK ); + + passwd.cnt = 0; + passwd.cursor = 0; +#ifdef _SAHOOK //Syu ADD Hook程式 + passwd.filterFlag = HOOK_TYPE; +#else + passwd.filterFlag = BLIND_TYPE; +#endif + // ????? + + idPasswordFocusSw = 0; + GetKeyInputFocus(idPasswordFocus[idPasswordFocusSw]); +#ifdef _75_LOGIN + if(g_bUseAlpha){ + aEffect = MakeAnimDisp(300,244,101817,0); + aEffect1 = MakeAnimDisp(300,244,101818,0); + } +#endif +} + + +// ????? +// +// ??: 0 ... ?? +// 1 ... ??? +// 2 ... ???? +// -1 ... ???? +int inputIdPassword(BOOL flag) +{ + int id; + int selOkFlag; + static BOOL flag2 = FALSE; + static int oldId = 0; + int ret = 0; + int x1, y1, x2, y2, cx, cy; +#ifdef _AIDENGLU_ + extern int 自动登陆是否开启; +#endif + id = selGraId(idPasswordGraId, sizeof(idPasswordGraId) / sizeof(int)); + if (id == 0 +#ifdef _AIDENGLU_ + || 自动登陆是否开启 +#endif + ) + { + if (strlen(idKey.buffer) > 0 && strlen(passwd.buffer) > 0) + { + + //按下OK Button要求Dll传回真正的密码 +#ifdef _SAHOOK //Syu ADD Hook程式 + keyboardHook_Send(passwd.buffer); + passwd.cnt = strlen(passwd.buffer); + passwd.buffer[passwd.cnt] = '\0'; +#else + idKey.buffer[idKey.cnt] = '\0'; + passwd.buffer[passwd.cnt] = '\0'; +#endif + ret = 1; + } + else + { + ret = -1; + } + } + else if (id == 1) + { + ret = 2; + } + if (flag) + { + selOkFlag = 2; + } + else + { + selOkFlag = 0; + } + + StockFontBuffer2(&idKey); + StockFontBuffer2(&passwd); + id = -1; + + if (selOkFlag) + { +#ifdef _NEW_WIN_POS_ + +#ifdef _SA_VERSION_25 + x1=360; + y1=246; + x2=500; + y2=272; +#endif + +#endif + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX)) + { + id = 0; + } + x1 = passwdBoxX - 4 - 2; + y1 = passwdBoxY - 2 - 1; +#ifdef _NEW_WIN_POS_ + +#ifdef _SA_VERSION_25 + x1=360; + y1=282; + x2=500; + y2=308; +#endif + +#endif + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX)) + { + id = 1; + } + } + if (idKeyReturn) + { + id = 1; + idKeyReturn = 0; + } + + if (joy_trg[1] & JOY_TAB) + { + if (oldId == 0) + { + id = 1; + } + else + if (oldId == 1) + { + id = 0; + } + } + + if (!flag) + { + GetKeyInputFocus(NULL); + flag2 = TRUE; + } + else + if ((0 <= id && id <= 1) + || flag2) + { + if (flag2) + id = oldId; + //Hook程式启动关闭与星号处理 +#ifdef _SAHOOK //Syu ADD Hook程式 + if ( (id == 1) && (hookflag == false )) + { + hookflag = true; + KeyboardHook_Start(hWnd, UM_KEYEVENT); + + } + else if ( (id == 0) && (hookflag == true)) + { + hookflag = false; + KeyboardHook_Stop(); + extern int HOOK_PASSWD_NUM; + HOOK_PASSWD_NUM = 0; + } +#endif + GetKeyInputFocus(idPasswordFocus[id]); + flag2 = FALSE; + oldId = id; + } +#ifdef _NEW_WIN_POS_ +#ifdef _SA_VERSION_25 + x1 = 300; + y1 = 320; + x2 = x1 + 85; + y2 = y1 + 30; + cx = 343; + cy = 337; +#endif + +#endif + if (MakeHitBox(x1, y1, x2, y2, -1) && selOkFlag) + idPasswordGraId[0] = StockDispBuffer(cx, cy, DISP_PRIO_BG, CG_TITLE_ID_PASS_OK, 1); + else + idPasswordGraId[0] = -2; +#ifdef _SA_VERSION_25 + x1 = 415; + y1 = 320; + x2 = x1 + 85; + y2 = y1 + 30; + cx = 459; + cy = 338; + if (MakeHitBox(x1, y1, x2, y2, -1) && selOkFlag) + idPasswordGraId[1] = StockDispBuffer(cx, cy, DISP_PRIO_BG, CG_TITLE_ID_PASS_QUIT, 1); + else +#endif + + idPasswordGraId[1] = -2; +#ifdef __SKYISLAND +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_TITLE_ID_PASS, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_TITLE_ID_PASS, 0 ); +#endif +#endif + return ret; +} + +static short commonMsgWinProcNo = 0; + +void initCommonMsgWin(void) +{ + commonMsgWinProcNo = 0; +} + + +int commonMsgWin(char *msg) +{ + static int fontId[] = { -2 }; + static ACTION *ptActMenuWin = NULL; + int id; + int i; + static int x, y, w, h; + int ret = 0; +#ifdef _NEW_WGS_MSG // WON ADD WGS的新视窗? + char temp[256], out_msg[5][128]; + int j, count=0, temp_size=0; +#endif + + // ??? + if (commonMsgWinProcNo == 0) + { + commonMsgWinProcNo = 1; + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + +#ifdef _NEW_WGS_MSG // WON ADD WGS的新视窗? + + memset( temp, 0, sizeof(temp) ); + strcpy( temp, msg); + + i=0; j=0; + while( temp[count] != '\0' ){ + j++; + if( temp[count] == '\n' ){ + if( j > temp_size ) temp_size = j; + i++; j=0; + } + count++; + } + + if( temp_size == 0 ){ + temp_size = strlen( temp ); + i = 1; + } + + h = ((36+32)/48) * (i+2); + w = temp_size*8/64+2; + +#else + + w = strlen(msg) * 8 / 64 + 2; + h = (36 + 32) / 48; +#endif + + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); + +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); +#ifdef _AIDENGLU_ + extern int 自动登陆是否开启; +#endif +#ifdef _AIDENGLU_ + int 进入 = FALSE; + if (自动登陆是否开启){ + if (TimeGetTime() > PcLanded.登陆延时时间){ + 进入 = TRUE; + } + } +#endif + if (id == 0 +#ifdef _AIDENGLU_ + || 进入 +#endif + ) + { + ret = 1; + play_se(217, 320, 240); + } + + + // ??????????????? + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return ret; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx; + +#ifdef _NEW_WGS_MSG // WON ADD WGS的新视窗? + + memset( temp, 0, sizeof(temp) ); + strcpy( temp, msg); + + for(i=0; i<5; i++) + memset( out_msg[i], 0, sizeof(out_msg[i]) ); + + i=0; j=0; + while( temp[count] != '\0' ){ + out_msg[i][j]=temp[count]; j++; + if( temp[count] == '\n' ){ + out_msg[i][j-1] = '\0'; + i++; j=0; + } + count++; + } + + for( j=0; j<=i; j++){ + len = strlen( out_msg[j] )+1; + xx = (w*64-len*8)/2; + StockFontBuffer( x+xx, y+(j*30)+30, FONT_PRIO_FRONT, FONT_PAL_WHITE, out_msg[j], 0 ); + } + +#else + + len = strlen(msg) + 1; + xx = (w * 64 - len * 8) / 2; + + StockFontBuffer(x + xx, y + 30, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); +#endif + + xx = (w * 64 - strlen("OK") * 8) / 2; +#ifdef _SAHOOK //Syu ADD Hook程式 + if ( hookflag == true) + { + hookflag = false; + KeyboardHook_Stop(); + extern int HOOK_PASSWD_NUM; + HOOK_PASSWD_NUM = 0; + } +#endif + +#ifdef _NEW_WGS_MSG // WON ADD WGS的新视窗? + fontId[0] = StockFontBuffer( x+xx, y+(j*30)+56, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "OK", 2 ); +#else + fontId[0] = StockFontBuffer(x + xx, y + 56, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "OK", 2); +#endif + } + } + return ret; +} + + + + + + + + +// ???????????? +// ??: STR_BUFFER *pt; ... ???????????? +// int x, y; ... ? +// int len; ... ????????? +// int color; ...  +// int prio; ... ? +void initStrBuffer(STR_BUFFER *pt, int x, int y, int len, int color, int prio) +{ + pt->x = x; + pt->y = y; + pt->len = len; + pt->color = color; + pt->fontPrio = prio; +} + + +// ??????? +// ????????????????? +// ??: int *id; ... ??????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int selGraId(int *id, int cnt) +{ + int i; + + // ????????????? + if ((mouse.onceState & MOUSE_LEFT_CRICK) == 0) + return -1; + + for (i = 0; i < cnt; i++) + { + if (id[i] == HitDispNo) + { + return i; + } + } + + return -1; +} + + +// ?????????????? +// ????????????????? +// ??: int *id; ... ??????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int selRepGraId(int *id, int cnt) +{ + int i; + + // ????????????? + if ((mouse.autoState & MOUSE_LEFT_CRICK) == 0) + return -1; + + for (i = 0; i < cnt; i++) + { + if (id[i] == HitDispNo) + { + return i; + } + } + + return -1; +} + + +// ??????? +// ???????????????????? +// ??: int *id; ... ??????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int pushGraId(int *id, int cnt) +{ + int i; + + if ((mouse.state & MOUSE_LEFT_CRICK) == 0) + return -1; + + for (i = 0; i < cnt; i++) + { + if (id[i] == HitDispNo) + { + return i; + } + } + + return -1; +} + + +// ????? +// ????????????????? +// ??: int *id; ... ????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int selFontId(int *id, int cnt) +{ + int i; + // ????????????? + if ((mouse.onceState & MOUSE_LEFT_CRICK) == 0) + return -1; + for (i = 0; i < cnt; i++){ + if (id[i] == HitFontNo) + return i; + } + return -1; +} + + +// ???????????? +// ????????????????? +// ??: int *id; ... ??????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int focusGraId(int *id, int cnt) +{ + int i; + for (i = 0; i < cnt; i++) + { + if (id[i] == HitDispNo) + { + return i; + } + } + + return -1; +} + + +// ?????????? +// ????????????????? +// ??: int *id; ... ????????????? +// int cnt; ... ???? +// ??: -1 ... ?????????? +int focusFontId(int *id, int cnt) +{ + int i; + + for (i = 0; i < cnt; i++) + { + if (id[i] == HitFontNo) + { + return i; + } + } + + return -1; +} + +// ????????????? +// +static short userCertifyErrorMsgWinProcNo = 0; + + +char BigpBuffer[2048]; + +void __fastcall GBK2BIG5(char *szBuf) +{ + if (!strcmp(szBuf, "")) + return; + int nStrLen = strlen(szBuf); + wchar_t *pws = new wchar_t[nStrLen + 1]; + MultiByteToWideChar(936, 0, szBuf, nStrLen, pws, nStrLen + 1); + BOOL bValue = false; + WideCharToMultiByte(950, 0, pws, nStrLen, szBuf, nStrLen + 1, "?", &bValue); + szBuf[nStrLen] = 0; + delete[] pws; +} + + + + +wchar_t* GB2312ToUnicode(const char* szGBString)//删 +{ + UINT nCodePage = 936; //GB2312 + int nLength = MultiByteToWideChar(nCodePage, 0, szGBString, -1, NULL, 0); + wchar_t* pBuffer = new wchar_t[nLength + 1]; + MultiByteToWideChar(nCodePage, 0, szGBString, -1, pBuffer, nLength); + pBuffer[nLength] = 0; + return pBuffer; +} + + + +char* UnicodeToBIG5(const wchar_t* szUnicodeString)//删 +{ + UINT nCodePage = 950; //BIG5 + int nLength = WideCharToMultiByte(nCodePage, 0, szUnicodeString, -1, NULL, 0, NULL, NULL); + char* pBuffer = BigpBuffer; + WideCharToMultiByte(nCodePage, 0, szUnicodeString, -1, pBuffer, nLength, NULL, NULL); + pBuffer[nLength] = 0; + return pBuffer; +} +char* GB2312ToBIG5(const char* szGBString)//删 +{ + LCID lcid = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC); + int nLength = LCMapString(lcid, LCMAP_TRADITIONAL_CHINESE, szGBString, -1, NULL, 0); + char* pBuffer = new char[nLength + 1]; + LCMapString(lcid, LCMAP_TRADITIONAL_CHINESE, szGBString, -1, pBuffer, nLength); + pBuffer[nLength] = 0; + wchar_t* pUnicodeBuff = GB2312ToUnicode(pBuffer); + char* pBIG5Buff = UnicodeToBIG5(pUnicodeBuff); + delete[] pBuffer; + delete[] pUnicodeBuff; + return pBIG5Buff; +} + +wchar_t* BIG5ToUnicode(const char* szBIG5String)//删 +{ + UINT nCodePage = 950; //BIG5 + int nLength = MultiByteToWideChar(nCodePage, 0, szBIG5String, -1, NULL, 0); + wchar_t* pBuffer = new wchar_t[nLength + 1]; + MultiByteToWideChar(nCodePage, 0, szBIG5String, -1, pBuffer, nLength); + pBuffer[nLength] = 0; + return pBuffer; +} + + + +char* UnicodeToGB2312(const wchar_t* szUnicodeString)//删 +{ + UINT nCodePage = 936; //GB2312 + int nLength = WideCharToMultiByte(nCodePage, 0, szUnicodeString, -1, NULL, 0, NULL, NULL); + char* pBuffer = new char[nLength + 1]; + WideCharToMultiByte(nCodePage, 0, szUnicodeString, -1, pBuffer, nLength, NULL, NULL); + pBuffer[nLength] = 0; + return pBuffer; +} +//繁体中文BIG5 转换成 简体中文 GB2312 +char* BIG5ToGB2312(const char* szBIG5String) +{ + LCID lcid = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC); + wchar_t* szUnicodeBuff = BIG5ToUnicode(szBIG5String); + char* szGB2312Buff = UnicodeToGB2312(szUnicodeBuff); + int nLength = LCMapString(lcid, LCMAP_SIMPLIFIED_CHINESE, szGB2312Buff, -1, NULL, 0); + char* pBuffer = BigpBuffer; + LCMapString(0x0804, LCMAP_SIMPLIFIED_CHINESE, szGB2312Buff, -1, pBuffer, nLength); + pBuffer[nLength] = 0; + delete[] szUnicodeBuff; + delete[] szGB2312Buff; + return pBuffer; +} + + +extern char szAnnouncement[]; +extern struct gamegroup gmgroup[]; + +void titleProc(void) +{ + int ret; + static char msg[256]; + if (SubProcNo == 0){ + char str[128]; +#ifndef _TAIKEN + sprintf_s(str, "%s %s", DEF_APPNAME, SA_VERSION); +#else + sprintf_s( str, "%s %s [体验版] DEF_APPNAME, SA_VERSION ); +#endif + + extern int 繁体开关; + if (繁体开关){ + char 繁体[1024] = { 0 }; + LCMapString(0x804, 0x4000000, str, strlen(str), 繁体, 1024); + sprintf(str, "%s", 繁体); + } + if (编码 == 950){ + SetWindowText(hWnd, GB2312ToBIG5((const char *)str)); + } + else{ + + SetWindowText(hWnd, str); + } + if (0 1) + SubProcNo = 2; + else + SubProcNo = 3; + ProduceInitFlag = TRUE; + initSelectServer(); + // disconnectServerFlag = FALSE; + } + else{ + SubProcNo = 100; +#ifdef _AIDENGLU_ + PcLanded.登陆延时时间 = TimeGetTime() + 2000; +#endif + strcpy(netprocErrmsg, NET_ERRMSG_SOCKLIBERROR); + } + } + // 选择Group + if (SubProcNo == 2){ + ret = selectGroup(); + if (ret == 1){ + SubProcNo++; + } + else if (ret == 2){ + idPasswordFocusSw = 0; + GetKeyInputFocus(idPasswordFocus[idPasswordFocusSw]); + ChangeProc(PROC_ID_PASSWORD); + SubProcNo = 0; + cleanupNetwork(); + } + else if (ret == 3){ + SubProcNo = 100; + wsprintf(msg, "[%s]您使用的版本无法连接此星系!", gmgroup[nServerGroup].name); + cleanupNetwork(); + } + } + // 选择Server + if (SubProcNo == 3){ + ret = selectServer(); + if (ret == 1){ +#ifdef _SHOWIPSLEEP_ + + extern HANDLE IP线程; + CloseHandle(IP线程); + IP线程=NULL; +#endif + SubProcNo++; + } + else if (ret == 2){ + if (nGroup < 2){ + idPasswordFocusSw = 0; + GetKeyInputFocus(idPasswordFocus[idPasswordFocusSw]); + ChangeProc(PROC_ID_PASSWORD); + SubProcNo = 0; + } + else + SubProcNo = 2; + } + } + if (SubProcNo == 4){ + // 连接Game server的初始化 + initConnecGameServer(); + SubProcNo++; + } + if (SubProcNo == 5){ + // 连接Game server + ret = connecGameServer(); + if (ret == 1){ +#ifdef _PK2007 + ChangeProc( PROC_PKSERVER_SELECT ); +#else + ChangeProc(PROC_CHAR_SELECT); +#endif +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + } + else if (ret == -2){ + SubProcNo = 100; +#ifdef _AIDENGLU_ + PcLanded.登陆延时时间 = TimeGetTime() + 2000; +#endif + strcpy(msg, netprocErrmsg); + cleanupNetwork(); + } + } + // ???????? + if (SubProcNo == 100){ + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101){ + if (commonMsgWin(msg)){ + char str[128]; + SubProcNo = 1; +#ifndef _TAIKEN + sprintf_s(str, "%s %s", DEF_APPNAME, SA_VERSION); +#else + sprintf_s( str, "%s %s [体验版]", DEF_APPNAME, SA_VERSION ); +#endif + extern int 繁体开关; + if (繁体开关){ + char 繁体[1024] = { 0 }; + LCMapString(0x804, 0x4000000, str, strlen(str), 繁体, 1024); + sprintf(str, "%s", 繁体); + } + if (编码 == 950){ + + SetWindowText(hWnd, GB2312ToBIG5((const char *)str)); + } + else{ + + SetWindowText(hWnd, str); + } + } + } + if (SubProcNo == 200){ + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 201){ + if (commonMsgWin(szAnnouncement)) + SubProcNo = 1; + } +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_TITLE, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_TITLE, 0 ); +#endif + // ????? +#ifdef _TAIKEN + StockFontBuffer( 480, 424, FONT_PRIO_BACK, FONT_PAL_BLUE, "体验版", 0 ); +#endif +#ifdef _SA_VERSION_25 + StockFontBuffer( 620, 580, FONT_PRIO_BACK, FONT_PAL_BLUE, "体验版!", 0 ); +#endif +} + + +// ???? + +ACTION *ptActSelectServerWin = NULL; + +// ??? +void initSelectServer(void) +{ + ptActSelectServerWin = NULL; +} + +/*return: 0 ... 选择中 +1 ... 决定Group +2 ... 按回上一页 +3 ... 选择到网咖专用的服务器 */ +int selectGroup() +{ + static int fontId[] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 }; + static int x, y; + int row; + int id; + int i; + int ret = 0; + if (ptActSelectServerWin == NULL){ + y = 270; + x = 0; + row = (nGroup >> 2) + 1; + if (row == 1) + x = 256; + else if (row == 2) + x = 192; + else if (row == 3) + x = 128; + else if (row == 4) + x = 64; + ptActSelectServerWin = MakeWindowDisp(x, y, row << 1, 3, NULL, 1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActSelectServerWin->x + 22; + y = ptActSelectServerWin->y + 28; +#else + x+=22; + y+=28; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + } + if (ptActSelectServerWin != NULL){ + // 游标在第几个选项 +#ifdef _AIDENGLU_ + extern int 自动登陆是否开启; +#endif + id = selFontId(fontId, nGroup + 1); + if ((id >= 0 && id < nGroup) +#ifdef _AIDENGLU_ + || 自动登陆是否开启 +#endif + ){ +#ifdef _AIDENGLU_ + if (自动登陆是否开启) nServerGroup = PcLanded.大区; + else +#endif + nServerGroup = id; + char title[256]; + sprintf_s(title, "%s %s %s", DEF_APPNAME, SA_VERSION, gmgroup[nServerGroup].name); + extern int 繁体开关; + if (繁体开关){ + char 繁体[1024] = { 0 }; + LCMapString(0x804, 0x4000000, title, strlen(title), 繁体, 1024); + sprintf(title, "%s", 繁体); + } + if (编码 == 950){ + + SetWindowText(hWnd, GB2312ToBIG5((const char *)title)); + } + else { + + SetWindowText(hWnd, title); + } + DeathAction(ptActSelectServerWin); + ptActSelectServerWin = NULL; + play_se(217, 320, 240); // click声 + if (gmgroup[nServerGroup].used == 1) + return 1; + else{ +#ifdef _AIDENGLU_ + //自动登陆是否开启 = FALSE; +#endif + return 3; + } + } + else if (id == nGroup){ + DeathAction(ptActSelectServerWin); + ptActSelectServerWin = NULL; + play_se(217, 320, 240); // click声 + return 2; + } + if (ptActSelectServerWin->hp >= 1){ + int Hit = 0; + for (i = 0; i < nGroup; i++){ + if (gmgroup[i].used) Hit = 2; + else Hit = 0; + fontId[i] = StockFontBuffer(x + (i >> 2) * 128, y + (i % 4) * 25, FONT_PRIO_FRONT, FONT_PAL_YELLOW, gmgroup[i].name, Hit); + } +#ifdef _NEWFONT_ + fontId[i] = StockFontBuffer(x + (i >> 2) * 128 + 10, y + 75, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 回上一页 ", 2); +#else + fontId[i]=StockFontBuffer(x+(i>>2)*128,y+75,FONT_PRIO_FRONT,FONT_PAL_YELLOW," 回上一页 ",2); +#endif + } + } + return 0; +} + +#ifdef _SHOWIPSLEEP_ +HANDLE IP线程 = NULL; +CPing objPing; +DWORD WINAPI IP延时读取(PVOID pParam) +{ + int i; + WORD wVersionRequested; + WSADATA wsaData; + int err; + while(1){ + if(SubProcNo==3){ + int j=gmgroup[nServerGroup].startindex; + for(i=0;i200) nTime=-1; + gmsv[j].delay = nTime; + }else gmsv[j].delay=-1; + }else{ + gmsv[j].delay=-1; + } + } + + DWORD StartTime = GetTickCount() + 1200; + while(1){ + if(GetTickCount() > StartTime){ + break; + }else Sleep(100); + } + + }else break; + Sleep(3000); + } + return 0; +} + +#endif + +// +// ??: 0 ... ? +// 1 ... ???? +// 2 ... ???? +int selectServer() +{ + static int fontId[] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 }; + static int x, y; + int row; + int id; + int i; + int ret = 0; + if (ptActSelectServerWin == NULL){ + y = 270 + 0; + x = 0; + row = (gmgroup[nServerGroup].num >> 2) + 1; + if (row == 1) + x = 256; + else if (row == 2) + x = 192; + else if (row == 3) + x = 128; + else if (row == 4) + x = 64; + ptActSelectServerWin = MakeWindowDisp(x, y, row << 1, 3, NULL, 1); +#ifdef _SHOWIPSLEEP_ + extern DWORD WINAPI IP延时读取(PVOID pParam); + if(IP线程 ==NULL) + IP线程 = CreateThread(NULL,0,IP延时读取,0,0,NULL); +#endif +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActSelectServerWin->x + 22; + y = ptActSelectServerWin->y + 28; +#else + x+=22; + y+=28; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + } + if (ptActSelectServerWin != NULL){ + // 游标在第几个选项 + id = selFontId(fontId, gmgroup[nServerGroup].num + 1); +#ifdef _AIDENGLU_ + extern int 自动登陆是否开启; +#endif + if (id >= 0 && id < gmgroup[nServerGroup].num +#ifdef _AIDENGLU_ + || 自动登陆是否开启 +#endif + ){ + char title[256]; +#ifdef _AIDENGLU_ + if (自动登陆是否开启) selectServerIndex = gmgroup[nServerGroup].startindex + PcLanded.小区; + else +#endif + selectServerIndex = gmgroup[nServerGroup].startindex + id; + + DeathAction(ptActSelectServerWin); + ptActSelectServerWin = NULL; + play_se(217, 320, 240); // click声 + return 1; + } + else if (id == gmgroup[nServerGroup].num){ + DeathAction(ptActSelectServerWin); + ptActSelectServerWin = NULL; + play_se(217, 320, 240); // click声 + return 2; + } + if (ptActSelectServerWin->hp >= 1){ + int j = gmgroup[nServerGroup].startindex; + int Hit = 0; + for (i = 0; i < gmgroup[nServerGroup].num; i++, j++){ + if ('1' == gmsv[j].used) + Hit = 2; + else + Hit = 0; + +#ifdef _SHOW_COUNT // WON ADD 秀服务器流量 + fontId[i]=StockFontBuffer(x+(i>>2)*128+10,y+(i%4)*25,FONT_PRIO_FRONT,FONT_PAL_YELLOW,gmsv[j].name,Hit); + { + int img = 24324; + + switch( atoi(gmsv[j].count) ){ + case 1: img = 24324; break; + case 2: img = 24327; break; + case 3: img = 24326; break; + } + StockDispBuffer( x+(i>>2)*128, y+(i%4)*25 + 5, DISP_PRIO_TOP, img, 0 ); + } +#else +#ifdef _SHOWIPSLEEP_ + char dechar[64]; + sprintf(dechar,"%d",gmsv[j].delay); + StockFontBuffer(x+(i>>2)*128+70,y+(i%4)*25,FONT_PRIO_FRONT,FONT_PAL_GREEN,dechar,0); +#endif + fontId[i] = StockFontBuffer(x + (i >> 2) * 128, y + (i % 4) * 25, FONT_PRIO_FRONT, FONT_PAL_YELLOW, gmsv[j].name, Hit); +#endif + } + fontId[i] = StockFontBuffer(x + (i >> 2) * 128, y + 75, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 回上一页 ", 2); + } + } + return 0; +} + + + + + +// ???????? + +static short connecGameServerProcNo = 0; + +void initConnecGameServer(void) +{ + connecGameServerProcNo = 0; +} + + +// ????? +// +// ??: 0 ... ??? +// 1 ... ?? +// -1 ... ?????????????? +// -2 ... ?????????? +int connecGameServer(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + int ret2; + static char msg[256]; + + // ??? + if (connecGameServerProcNo == 0) + { + connecGameServerProcNo = 1; + + sprintf_s(msg, "%s服务器连线中", gmsv[selectServerIndex].name); + + // ?????? + w = (strlen(msg) * 9 + 63) / 64; + if (w < 2) + w = 2; + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ????????? + if (connecGameServerProcNo == 1) + { + cleanupNetwork(); + if (initNet()) + { + dwServer = GS; + connecGameServerProcNo = 2; + } + else + { + ret = -1; + } + } + // ???????? + if (connecGameServerProcNo == 2) + { + initConnectServer(); + connecGameServerProcNo = 3; + } + if (connecGameServerProcNo == 3) + { + ret2 = connectServer(); + if (ret2 == 1) + { + ret = 1; + } + else + if (ret2 < 0) + { + ret = -2; + } + } + + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx, yy; + + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} + + +/////////////////////////////////////////////////////////////////////////// +// +// ??????????? +// +//cary 十二、加入saac的错误讯息 +void selectCharacterProc(void) +{ + int ret; + int i, j; + int login; + int x; + static char msg[256]; + static int btnGraId[] = { -2, -2, -2, -2, -2, -2, -2 }; +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + static int PkBtn[1] = { -2 } ; + int x3 , y3 ; + char ServerName[13][32] = { + {"预设"} , + {"天鹰   "} , + {"网路家庭 "} , + {"圣兽   "} , + {"星乐园  "} , + {"银河系  "} , + {"太阳   "} , + {"北斗   "} , + {"天神   "} , + {"紫微   "} , + {"苍龙   "} , + {"香港地区 "} , + {"香港新界 "} }; +#endif + int btnUseFlag = 0; + int attrColor[4][2] = + { + { SYSTEM_PAL_GREEN, SYSTEM_PAL_GREEN2 }, + { SYSTEM_PAL_AQUA, SYSTEM_PAL_AQUA2 }, + { SYSTEM_PAL_RED, SYSTEM_PAL_RED2 }, + { SYSTEM_PAL_YELLOW, SYSTEM_PAL_YELLOW2 } + }; + int x1, y1, x2, y2; + + extern TCHAR 登陆错误内容[]; + + if (SubProcNo == 0) + { + SubProcNo++; + + initDownloadCharList(); + } + // ?????????? + if (SubProcNo == 1) + { + ret = downloadCharList(); + if (ret == 1){ + SubProcNo = 10; + play_bgm(2); + } + else if (ret == -1){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -2){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -3){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -4){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -5){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -6){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -7){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -8){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -9){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -10){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容/*"系统忙线中,请稍候再试!"*/); + } + else if (ret == -11){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } +#ifdef _CHANGEGALAXY + else if( ret == -12 ){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg,登陆错误内容); + } +#endif +#ifdef _ERROR301 + else if( ret == -13 ){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg,登陆错误内容); + } +#endif + else if (ret == -101){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -102){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -103){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -201){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -202){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -203){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -204){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -205){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -301){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -302){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -303){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -304){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -401){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + else if (ret == -402){ + SubProcNo = 100; + cleanupNetwork(); + strcpy(msg, 登陆错误内容); + } + } + + if (SubProcNo == 10) + { + for (i = 0; i < sizeof(btnGraId) / sizeof(int); i++) + { + btnGraId[i] = -2; + } + SubProcNo++; + } + if (SubProcNo == 11) + { + btnUseFlag = 2; + } + + // ??????? + if (SubProcNo == 20) + { + //cary 按下删除人物后 +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + + ret = DelCharGraColorWin(); + // ret = commonYesNoWindow( 320, 240 ); + // ?? + if (ret == 1) + { + SubProcNo++; + } + else + // ??? + if (ret == 2) + { + SubProcNo = 10; + } + } + if (SubProcNo == 21) + { + initDeleteCharacter(); + SubProcNo++; + } + // ???? + if (SubProcNo == 22) + { + ret = deleteCharacter(); + if (ret == 1) + { +#ifdef _MORECHARACTERS_ + resetCharacterList( selectPcNo+多人物当前页数*2 ); + clearUserSetting( selectPcNo+多人物当前页数*2 ); +#else + resetCharacterList(selectPcNo); + clearUserSetting(selectPcNo); +#endif + + if (saveNowState()) + { + } + if (maxPcNo > 0) + maxPcNo--; + SubProcNo = 10; + } + else + if (ret == -2) + { + SubProcNo = 300; + } + } + + // ??? + if (SubProcNo == 100) + { + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101) + { + if (commonMsgWin(msg)){ + ChangeProc(PROC_TITLE_MENU); +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + SubProcNo = 1; + } + } + //删除人物失败 + if (SubProcNo == 300) + { + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 301) + { + if (commonMsgWin("人物无法删除。")) + SubProcNo = 10; + } + + ret = selGraId(btnGraId, sizeof(btnGraId) / sizeof(int)); +#ifdef _AIDENGLU_ + extern int 自动登陆是否开启; +#endif + if (ret == 0) + { + fade_out_bgm(); +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + + ChangeProc(PROC_TITLE_MENU); + SubProcNo = 1; + play_se(217, 320, 240); // click声 + } + else if (1 <= ret && ret <= 2) + { + selectPcNo = ret - 1; + ChangeProc(PROC_CHAR_MAKE); +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + + play_se(217, 320, 240); // click声 + } + else if ((3 <= ret && ret <= 4) +#ifdef _AIDENGLU_ + || (自动登陆是否开启&&SubProcNo == 11) +#endif + ) + { + int 选择人物; +#ifdef _AIDENGLU_ + if (自动登陆是否开启) 选择人物 = PcLanded.人物; + else +#endif +#ifdef _MORECHARACTERS_ + 选择人物 = ret-3+多人物当前页数*2; +#else + 选择人物 = ret - 3; +#endif + char name[CHAR_NAME_LEN + 1]; + + strcpy(name, chartable[选择人物].name); + + strcpy(gamestate_login_charname, name); +#ifdef _AIDENGLU_ + if (自动登陆是否开启) selectPcNo = PcLanded.人物; + else +#endif + selectPcNo = ret - 3; + + newCharacterFaceGraNo = chartable[选择人物].faceGraNo; + loginDp = chartable[选择人物].dp; +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + PkMenuflag = 0 ; +#endif + ChangeProc(PROC_CHAR_LOGIN_START); + play_se(217, 320, 240); // click声 + map_bgm_no = 0; + if (ret == 3){ + sCharSide = 1; + } + else{ + sCharSide = 2; + } + } + else + if (5 <= ret && ret <= 6) + { + char name[CHAR_NAME_LEN + 1]; + +#ifdef _MORECHARACTERS_ + strcpy( name, chartable[ret-5+多人物当前页数*2].name ); +#else + strcpy(name, chartable[ret - 5].name); +#endif + //cary test sjisStringToEucString( name ); + strcpy(gamestate_deletechar_charname, name); + selectPcNo = ret - 5; + SubProcNo = 20; + selCharGraColorWinProcNo = 0; + play_se(217, 320, 240); // click声 + } + + + if (SubProcNo >= 10) + { +#ifdef _SPECIAL_LOGO + int ix = 80; + int iy = 84; + int ii = 0; + int backX = 80; +#else + int ix = 0; + int iy = 0; + int ii = 0; +#endif +#ifdef _MORECHARACTERS_ + char buff[256]; + int 按钮ID = StockDispBuffer(563+ix, 435 + iy, DISP_PRIO_CHAR, 55222, 2 ); + if((mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == 按钮ID)){ + if(!多人物当前页数) 多人物当前页数=1; + } + 按钮ID = StockDispBuffer( 72+ix, 435+iy, DISP_PRIO_CHAR, 55221, 2 ); + if((mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == 按钮ID)){ + if(多人物当前页数) 多人物当前页数=0; + } + sprintf_s(buff,"-%d/2-",多人物当前页数+1); + StockFontBuffer(300+ix,453+iy,0,4,buff,0); + int b; + for( b = 0; b < 2; b++ ) +#else + for (i = 0; i < MAXCHARACTER; i++) +#endif + { +#ifdef _MORECHARACTERS_ + i = 多人物当前页数*2+b; + if( existCharacterListEntry( i ) ) + { + StockDispBuffer( 169+b*(304 + ii) + ix, 84 + iy, DISP_PRIO_CHAR, chartable[i].faceGraNo, 0 ); + x = (144-strlen( chartable[i].name )*9)/2; + StockFontBuffer( 93+b*(304 + ii)+x + ix, 127 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, chartable[i].name, 0 ); + sprintf_s( msg, "%3d", chartable[i].level ); + StockFontBuffer( 104+b*(304 + ii) + ix, 152 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%3d", chartable[i].hp ); + StockFontBuffer( 104+b*(304 + ii) + ix, 174 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%3d", chartable[i].str ); + StockFontBuffer( 104+b*(304 + ii) + ix, 196 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%3d", chartable[i].def ); + StockFontBuffer( 104+b*(304 + ii) + ix, 218 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%3d", chartable[i].agi ); + StockFontBuffer( 104+b*(304 + ii) + ix, 240 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%3d", chartable[i].app ); + StockFontBuffer( 104+b*(304 + ii) + ix, 262 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + sprintf_s( msg, "%8d", chartable[i].dp ); + StockFontBuffer( 188+b*(304 + ii) + ix, 262 + iy,FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + for( j = 0; j < 4; j++ ) + { + if( chartable[i].attr[j] > 0 ) + { + x1 = 208+b*(304 + ii) + ix; + y1 = 177+j*22 + iy; + x2 = x1 + chartable[i].attr[j] * 8; + y2 = y1 + 8; + StockBoxDispBuffer( x1, y1, x2, y2, DISP_PRIO_IME2, attrColor[j][0], 1 ); + StockBoxDispBuffer( x1+1, y1+1, x2+1, y2+1, DISP_PRIO_IME1, attrColor[j][1], 0 ); + StockBoxDispBuffer( x1+2, y1+2, x2+2, y2+2, DISP_PRIO_IME1, attrColor[j][1], 0 ); + } + } + login = chartable[i].login; + if( login >= 1000 ) + login = 9999; + sprintf_s( msg, "%4d", login ); + StockFontBuffer( 156+b*(304 + ii) + ix, 284 + iy, + FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0 ); + btnGraId[3+b] = + StockDispBuffer( 100+b*(304 + ii) + ix, 342 + iy, + DISP_PRIO_CHAR, CG_CHR_SEL_LOGIN_BTN, btnUseFlag ); + btnGraId[5+b] = + StockDispBuffer( 230+b*(304 + ii) + ix, 342 + iy, + DISP_PRIO_CHAR, CG_CHR_SEL_DEL_BTN, btnUseFlag ); + } +#else + if (existCharacterListEntry(i)) + { + StockDispBuffer(169 + i*(304 + ii) + ix, 84 + iy, DISP_PRIO_CHAR, chartable[i].faceGraNo, 0); + x = (144 - strlen(chartable[i].name) * 9) / 2; + StockFontBuffer(93 + i*(304 + ii) + x + ix, 127 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, chartable[i].name, 0); + sprintf_s(msg, "%3d", chartable[i].level); + StockFontBuffer(104 + i*(304 + ii) + ix, 152 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%3d", chartable[i].hp); + StockFontBuffer(104 + i*(304 + ii) + ix, 174 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%3d", chartable[i].str); + StockFontBuffer(104 + i*(304 + ii) + ix, 196 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%3d", chartable[i].def); + StockFontBuffer(104 + i*(304 + ii) + ix, 218 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%3d", chartable[i].agi); + StockFontBuffer(104 + i*(304 + ii) + ix, 240 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%3d", chartable[i].app); + StockFontBuffer(104 + i*(304 + ii) + ix, 262 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + sprintf_s(msg, "%8d", chartable[i].dp); + StockFontBuffer(188 + i*(304 + ii) + ix, 262 + iy, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + for (j = 0; j < 4; j++) + { + if (chartable[i].attr[j] > 0) + { + x1 = 208 + i*(304 + ii) + ix; + y1 = 177 + j * 22 + iy; + x2 = x1 + chartable[i].attr[j] * 8; + y2 = y1 + 8; + StockBoxDispBuffer(x1, y1, x2, y2, DISP_PRIO_IME2, attrColor[j][0], 1); + StockBoxDispBuffer(x1 + 1, y1 + 1, x2 + 1, y2 + 1, DISP_PRIO_IME1, attrColor[j][1], 0); + StockBoxDispBuffer(x1 + 2, y1 + 2, x2 + 2, y2 + 2, DISP_PRIO_IME1, attrColor[j][1], 0); + } + } + login = chartable[i].login; + if (login >= 1000) + login = 9999; + sprintf_s(msg, "%4d", login); + StockFontBuffer(156 + i*(304 + ii) + ix, 284 + iy, + FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + btnGraId[3 + i] = + StockDispBuffer(100 + i*(304 + ii) + ix, 342 + iy, + DISP_PRIO_CHAR, CG_CHR_SEL_LOGIN_BTN, btnUseFlag); + btnGraId[5 + i] = + StockDispBuffer(230 + i*(304 + ii) + ix, 342 + iy, + DISP_PRIO_CHAR, CG_CHR_SEL_DEL_BTN, btnUseFlag); + } +#endif + else + if (SubProcNo < 100 || 300 <= SubProcNo) + { +#ifdef _MORECHARACTERS_ + btnGraId[1+b] = + StockDispBuffer( 160+b*(304 + ii) + ix, + 342 + iy, DISP_PRIO_CHAR, CG_CHR_SEL_NEW_BTN, btnUseFlag ); +#else + btnGraId[1 + i] = + StockDispBuffer(160 + i*(304 + ii) + ix, + 342 + iy, DISP_PRIO_CHAR, CG_CHR_SEL_NEW_BTN, btnUseFlag); +#endif + } + } + btnGraId[0] = + StockDispBuffer(320 + backX, 432 + iy, DISP_PRIO_CHAR, CG_CHR_SEL_BACK_BTN, btnUseFlag); + } +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_CHR_SEL_BG, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_SEL_BG, 0 ); +#endif +#ifdef _LOGINKICK + if (StartTime == -1) + StartTime = TimeGetTime(); + if (TimeGetTime() > StartTime + 30 * 1000 /*1000为一秒*/) { + ChangeProc(PROC_TITLE_MENU); + StartTime = -1; + } +#endif + +#ifdef _PKSERVERCHARSEL // (不可开) Syu ADD PK服务器选择星系人物 + if ( VersionXYZ == 1 ) { + PkBtn[0] = StockDispBuffer( 160, 430, DISP_PRIO_CHAR, CG_PKSERVER_BTN_UP + PkMenuflag , 2 ); + if( HitDispNo == PkBtn[ 0 ] ) { + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + ( PkMenuflag == 0 ) ? PkMenuflag = 1 : PkMenuflag = 0 ; + play_se( 217, 320, 240 ); + } + } + if ( PkMenuflag == 1 ) { + if ( PkServerSel == NULL ) { + PkServerSel = MakeWindowDisp( 255 , 5 , 2 , 7 , 0 , -1 ) ; + } else { + if( PkServerSel->hp > 0 ) { + x3 = PkServerSel->x ; + y3 = PkServerSel->y ; + StockDispBuffer( x3 + 60 , y3 + 200 , DISP_PRIO_IME3 , CG_PKSERVER_PANEL , 0 ) ; + StockFontBuffer( x3 + 20 , y3 + 155, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "选择星系人物" , 1 ); + for ( i = 0 ; i < 4 ; i ++ ) { + for ( j = 0 ; j < 3 ; j ++ ) { + StockFontBuffer( x3 - 95 + i * 83 , y3 + 178 + j * 22 , FONT_PRIO_FRONT, FONT_PAL_WHITE, ServerName[ i * 3 + j + 1] , 2 ); + if ( mouse.onceState & MOUSE_LEFT_CRICK ) { + //送出i * 4 + j + 1给Gmsv取得所要的AC资料 + } + } + } + } + } + } else { + if ( PkServerSel != NULL ) { + DeathAction(PkServerSel); + PkServerSel = NULL; + } + } + } +#endif + + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? +} +//end + + +// ????????? + +static short deleteCharacterProcNo = 0; + +// ??? +void initDeleteCharacter(void) +{ + deleteCharacterProcNo = 0; +} + +// ????? +// +// ??: 0 ... ??? +// 1 ... ???? +// -1 ... ?????? +// -2 ... ??? +int deleteCharacter(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + static char msg[] = "人物删除中"; + + // ??? + if (deleteCharacterProcNo == 0) + { + deleteCharacterProcNo = 1; + + // ?????? + w = strlen(msg) * 9 / 64 + 2; + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ?????? + if (deleteCharacterProcNo == 1) + { + delCharStart(); + deleteCharacterProcNo++; + } + else + if (deleteCharacterProcNo == 2) + { + ret = delCharProc(); + } + + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx, yy; + + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} + + + +// ?????????? + +static short downloadCharListProcNo = 0; +#ifdef _PK2007 +static short downloadpkListProcNo = 0; +#endif +// ??? +void initDownloadCharList(void) +{ + downloadCharListProcNo = 0; +} + +// ????? +// +// ??: 0 ... ? +// 1 ... ?? +// -1 ... ?????? +// -2 ... ??? +// -3 ... ????????? +// -4 ... ??? +int downloadCharList(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + static char msg[256]; + + // ??? + if (downloadCharListProcNo == 0) + { + downloadCharListProcNo = 1; + + strcpy(msg, "人物名单取得中"); + + // ?????? + w = strlen(msg) * 8 / 64 + 2; + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ?????? + if (downloadCharListProcNo == 1) + { + charListStart(); + downloadCharListProcNo++; + } + else + if (downloadCharListProcNo == 2) + { + ret = charListProc(); + } + + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx, yy; + + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} +#ifdef _PK2007 +int downloadpkList( void ) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + static char msg[256]; + if( downloadpkListProcNo == 0 ) + { + downloadpkListProcNo = 1; + strcpy( msg, "星系列表取得中" ); + w = strlen( msg )*8/64+2; + h = (16+47)/48; + if( h < 2 ) + h = 2; + x = (lpDraw->xSize-w*64)/2; + y = (lpDraw->ySize-h*48)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + if( downloadpkListProcNo == 1 ) + { + pkListStart(); + downloadpkListProcNo++; + } + else if( downloadpkListProcNo == 2 ) + { + ret = pkListProc(); + } + + if( ret != 0 ) + { + if( ptActMenuWin ) + { + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + } + } + + if( ptActMenuWin != NULL ) + { + if( ptActMenuWin->hp >= 1 ) + { + int len; + int xx, yy; + len = strlen( msg ); + xx = (w*64-len*8)/2; + yy = (h*48-16)/2; + StockFontBuffer( x+xx, y+yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0 ); + } + } + + return ret; +} +#endif + +// ???????????? +// +// ??: 0 ... ??? +// 1 ... ?????????? +// 2 ... ??????????? +int commonYesNoWindow(int x, int y) +{ + int i; + int ret = 0; + int id; + static int btnGraId[] = { -2, -2 }; + + id = selGraId(btnGraId, sizeof(btnGraId) / sizeof(int)); + // ?????????? + if (id == 0) + { + ret = 1; + play_se(217, 320, 240); // ????? + } + else + // ??????????? + if (id == 1) + { + ret = 2; + play_se(217, 320, 240); // ????? + } + + btnGraId[0] = StockDispBuffer(x, y, DISP_PRIO_YES_NO_BTN, CG_COMMON_YES_BTN, 2); + btnGraId[1] = StockDispBuffer(x, y, DISP_PRIO_YES_NO_BTN, CG_COMMON_NO_BTN, 2); + + StockDispBuffer(x, y, DISP_PRIO_YES_NO_WND, CG_COMMON_WIN_YORO, 0); + + if (ret != 0) + { + for (i = 0; i < sizeof(btnGraId) / sizeof(int); i++) + { + btnGraId[i] = -2; + } + } + + return ret; +} + +/////////////////////////////////////////////////////////////////////////// +// +// ???? +// + +// ?????? + +#ifdef _MO_IMAGE_EXTENSION +#define MaxSelectChar 18 +#else +#define MaxSelectChar 12 +#endif + +static ACTION *ptActSelChar[MaxSelectChar]; +static int selectGraNoTbl[MaxSelectChar] = +{ + SPR_001em, + SPR_011em, + SPR_021em, + SPR_031em, + SPR_041em, + SPR_051em, + SPR_061em, + SPR_071em, + SPR_081em, + SPR_091em, + SPR_101em, + SPR_111em, +#ifdef _MO_IMAGE_EXTENSION + SPRNEW_001em, + SPRNEW_005em, + SPRNEW_009em, + SPRNEW_013em, + SPRNEW_017em, + SPRNEW_021em, +#endif +}; +#ifdef _NEW_WIN_POS_ +int selectGraLocate[MaxSelectChar][2] = +{ + { 305, 290 },//豆丁 + { 240, 360 },//塞亚人 + { 410, 500 },//辫子男孩 + { 330, 400 },//酷哥 + { 200, 240 },//熊皮男 + { 480, 430 },//大个 + { 560, 410 },//豆丁妹 + { 600, 340 },//熊皮妹 + { 500, 310 },//帽子妹 + { 380, 240 },//短发妹 + { 460, 200 },//手套女 + { 280, 200 },//辣妹 +#ifdef _MO_IMAGE_EXTENSION + { 180, 440 }, + { 640, 420 }, + { 530, 520 }, + { 280, 500 }, + { 120, 350 }, + { 550, 240 }, +#endif +}; +#else +int selectGraLocate[MaxSelectChar][2] = +{ + { 198, 301 }, + { 113, 258 }, + { 248, 396 }, + { 130, 370 }, + { 137, 160 }, + { 343, 379 }, + { 479, 371 }, + { 420, 310 }, + { 376, 231 }, + { 297, 198 }, + { 381, 146 }, + { 242, 116 }, +#ifdef _MO_IMAGE_EXTENSION +#endif +}; +#endif +int selectGraHitArea[MaxSelectChar][4] = +{ + // x, y, w, h + { -32, -56, 63, 65 }, + { -21, -72, 42, 88 }, + { -19, -78, 38, 94 }, + { -20, -67, 41, 80 }, + { -30, -80, 60, 100 }, + { -36, -84, 72, 100 }, + { -30, -51, 59, 64 }, + { -19, -77, 40, 88 }, + { -18, -72, 34, 83 }, + { -22, -72, 43, 89 }, + { -18, -78, 35, 90 }, + { -20, -76, 40, 90 }, +#ifdef _MO_IMAGE_EXTENSION + { -27, -75, 57, 100 }, + { -22, -72, 43, 89 }, + { -25, -60, 46, 77 }, + { -27, -75, 57, 100 }, + { -30, -80, 60, 100 }, + { -36, -84, 72, 100 }, +#endif +}; +static int selCharColor[MaxSelectChar]; // ???? +static int selCharDir[MaxSelectChar]; // ?????? +static int selCharGraNoProcNo; +static int nowSelCharGraNo; // ????? +static int nowSelCharMouthNo; // ??????? +static int nowSelCharEyeNo; // ??????? +static int nowSelCharStatusPoint; // ?????????????????? +static int nowSelCharStatus[4]; // ?????????(?????????) +static int nowSelCharAttrPoint; // ????????????? +static int nowSelCharAttr[4]; // ????(佋???) + +// ????????????? +//static int selCharGraColorWinProcNo; + +// ???????????? +static int editCharParamProcNo; +STR_BUFFER selCharName; +static int selCharNameBoxX, selCharNameBoxY; + +// 佋?? +static int selHomeTownProcNo; +static int nowSelHomeTownNo; + +// ??????? +static int createCharProcNo; + + + +void initMakeCharacter(void); + +void initSelCharGraNo(void); +void initSelCharGraNo2(void); +int selCharGraNo(void); +void initSelCharGraColorWin(void); +int selCharGraColorWin(void); +void initEditCharParam(void); +void initEditCharParam2(void); +int editCharParam(void); +void initCreateChar(void); +int createChar(void); +void initSelHomeTown(void); +int selHomeTown(void); + + + +// ???????????? +void initMakeCharacter(void) +{ +} + +// ????????? +void makeCharacterProc(void) +{ + int ret; + + // ??? + if (SubProcNo == 0) + { + initMakeCharacter(); + SubProcNo++; + } + + // ????????? + if (SubProcNo == 1) + { + initSelCharGraNo(); + SubProcNo = 3; + } + else + if (SubProcNo == 2) + { + initSelCharGraNo2(); + SubProcNo++; + } + // ??????? + if (SubProcNo == 3) + { + ret = selCharGraNo(); + // ???? + if (ret == 1) + { + SubProcNo = 10; + } + else + // ????????? + if (ret == 2) + { + ChangeProc(PROC_CHAR_SELECT, 10); + // return; + } + } + + // ????????????? + if (SubProcNo == 10 && ret == 1) + { + initEditCharParam(); + SubProcNo = 12; + } + else + if (SubProcNo == 11) + { + initEditCharParam2(); + SubProcNo = 12; + } + if (SubProcNo == 12) + { + ret = editCharParam(); + if (ret == 1) + { + SubProcNo = 20; +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + if ( pActPet20 != NULL) + { + DeathAction( pActPet20 ); + pActPet20 = NULL; + } +#endif + } + // ????? + if (ret == 2) + { +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + if ( pActPet20 != NULL) + { + DeathAction( pActPet20 ); + pActPet20 = NULL; + } +#endif + SubProcNo = 2; + } + } + + // 佋? + if (SubProcNo == 20) + { +#ifndef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + initSelHomeTown(); +#endif + SubProcNo = 21; + } + if (SubProcNo == 21) + { +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + ret = 1; +#else + ret = selHomeTown(); +#endif + // ? + if (ret == 1) + { + SubProcNo = 30; + // ???????????? +#ifdef _MORECHARACTERS_ + resetCharacterList( selectPcNo+多人物当前页数*2 ); + clearUserSetting( selectPcNo+多人物当前页数*2 ); +#else + resetCharacterList(selectPcNo); + clearUserSetting(selectPcNo); +#endif + + } + else + // ????? + if (ret == 2) + { + SubProcNo = 11; + } + } + + // ??????????? + if (SubProcNo == 30) + { + initCreateChar(); + SubProcNo = 31; + } + if (SubProcNo == 31) + { + ret = createChar(); + if (ret == 1) + { + maxPcNo++; + strcpy(gamestate_login_charname, newCharacterName); + ChangeProc(PROC_CHAR_LOGIN_START); + createCharFlag = 1; + //return; + } + else + if (ret == 2) + { + SubProcNo = 100; + } + selHomeTown(); // ????? + } + + // ??? + if (SubProcNo == 100) + { + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101) + { + extern char 创建人物内容提示[512]; + if (commonMsgWin(创建人物内容提示)) + { + // OK???????? + ChangeProc(PROC_CHAR_SELECT, 10); + //return; + } + selHomeTown(); // ????? + } + + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? +} + + + + +// ????????? +void initSelCharGraNo(void) +{ + int i; + + selCharGraNoProcNo = 0; + + // ????????? + nowSelCharGraNo = -1; // ?-1 + nowSelCharMouthNo = 0; + nowSelCharEyeNo = 0; + /* + #ifdef _NEW_WIN_POS_ + unsigned char PlayCoordinate[]={0x02,0x01,0x00,0x00,0x69,0x01,0x00,0x00,0xAD,0x00,0x00,0x00,0x3E,0x01,0x00,0x00, + 0x34,0x01,0x00,0x00,0xC8,0x01,0x00,0x00,0xBE,0x00,0x00,0x00,0xAE,0x01,0x00,0x00,0xC5,0x00,0x00,0x00, + 0xDC,0x00,0x00,0x00,0x93,0x01,0x00,0x00,0xB7,0x01,0x00,0x00,0x1B,0x02,0x00,0x00,0xAF,0x01,0x00,0x00, + 0xE0,0x01,0x00,0x00,0x72,0x01,0x00,0x00,0xB4,0x01,0x00,0x00,0x23,0x01,0x00,0x00,0x65,0x01,0x00,0x00, + 0x02,0x01,0x00,0x00,0xB9,0x01,0x00,0x00,0xCE,0x00,0x00,0x00,0x2E,0x01,0x00,0x00,0xB0,0x00,0x00,0x00}; + memcpy_s((void*)selectGraLocate,96,PlayCoordinate,96); + #endif + */ + for (i = 0; i < MaxSelectChar; i++) + { + selCharColor[i] = 0; // ???? + selCharDir[i] = 0; // ?????? + } + + // ?????????? + for (i = 0; i < MaxSelectChar; i++) + { + if (selectGraNoTbl[i] < 0) + { + ptActSelChar[i] = NULL; + continue; + } + ptActSelChar[i] = GetAction(PRIO_CHR, 0); + if (ptActSelChar[i] != NULL) + { + ptActSelChar[i]->anim_chr_no = selectGraNoTbl[i]; + ptActSelChar[i]->anim_no = ANIM_STAND; + ptActSelChar[i]->dispPrio = DISP_PRIO_CHAR; + ptActSelChar[i]->x = selectGraLocate[i][0]; + ptActSelChar[i]->y = selectGraLocate[i][1]; + ptActSelChar[i]->anim_ang = selCharDir[i]; + } + } + +} + +// ????????? +// ??????????????????????????????? +void initSelCharGraNo2(void) +{ + int i; + + selCharGraNoProcNo = 0; + nowSelCharMouthNo = 0; + nowSelCharEyeNo = 0; + + // ????????? + nowSelCharGraNo = -1; // ?-1 + + // ?????????? + for (i = 0; i < MaxSelectChar; i++) + { + if (selectGraNoTbl[i] < 0) + { + ptActSelChar[i] = NULL; + continue; + } + + ptActSelChar[i] = GetAction(PRIO_CHR, 0); + if (ptActSelChar[i] != NULL) + { + ptActSelChar[i]->anim_chr_no = selectGraNoTbl[i]; + ptActSelChar[i]->anim_no = ANIM_STAND; + ptActSelChar[i]->dispPrio = DISP_PRIO_CHAR; + ptActSelChar[i]->x = selectGraLocate[i][0]; + ptActSelChar[i]->y = selectGraLocate[i][1]; + ptActSelChar[i]->anim_ang = selCharDir[i]; + } + } +} + + +int selCharGraNo(void) +{ + int i; + int ret = 0; + int ret2; + int x1, y1, x2, y2; + int id; + static int selCharCanselGraId[] = { -2 }; +#ifdef _TAIKEN + short taikenFlag = 0; +#endif + + // ??? + if (selCharGraNoProcNo == 0) + { + for (i = 0; i < sizeof(selCharCanselGraId) / sizeof(int); i++) + { + selCharCanselGraId[i] = -2; + } + selCharGraNoProcNo++; + } + + // ??? + if (selCharGraNoProcNo == 1) + { + for (i = 0; i < MaxSelectChar; i++) + { + if (ptActSelChar[i] != NULL) + { + x1 = ptActSelChar[i]->x + selectGraHitArea[i][0]; + y1 = ptActSelChar[i]->y + selectGraHitArea[i][1]; + x2 = x1 + selectGraHitArea[i][2]; + y2 = y1 + selectGraHitArea[i][3]; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX)) + { +#ifndef _TAIKEN + ptActSelChar[i]->anim_no = ANIM_WALK; + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // ??????? + selCharGraNoProcNo = 2; + nowSelCharGraNo = i; + play_se(217, 320, 240); // ????? + } +#else + if( i == 0 || i == 2 || i == 6 || i == 9 ) + { + ptActSelChar[i]->anim_no = ANIM_WALK; + if( mouse.onceState & MOUSE_LEFT_CRICK ) + { + // ??????? + selCharGraNoProcNo = 2; + nowSelCharGraNo = i; + play_se( 217, 320, 240 ); // ????? + } + } + else + { + ptActSelChar[i]->anim_no = ANIM_SAD; + taikenFlag = 1; + if( mouse.onceState & MOUSE_LEFT_CRICK ) + { + play_se( 220, 320, 240 ); // ??? + } + } +#endif + } + else + { + ptActSelChar[i]->anim_no = ANIM_STAND; + } + } + } + } + + // ??????? + if (selCharGraNoProcNo == 2) + { + initSelCharGraColorWin(); + selCharGraNoProcNo++; + } + if (selCharGraNoProcNo == 3) + { + ret2 = selCharGraColorWin(); + // ? + if (ret2 == 1) + { + ret = 1; + } + else + // ???????? + if (ret2 == 2) + { + selCharGraNoProcNo = 1; + nowSelCharGraNo = -1; + } + } + + // ?????????? + id = selGraId(selCharCanselGraId, sizeof(selCharCanselGraId) / sizeof(int)); + // ????? + if (id == 0) + { + ret = 2; + play_se(217, 320, 240); // ????? + } + + // ?????????? + if (ret != 0) + { + for (i = 0; i < MaxSelectChar; i++) + { + if (ptActSelChar[i] != NULL) + { + DeathAction(ptActSelChar[i]); + ptActSelChar[i] = NULL; + } + } + } + + + // ???? + for (i = 0; i < MaxSelectChar; i++) + { + if (ptActSelChar[i] != NULL) + { + if (nowSelCharGraNo == i) + { + ptActSelChar[i]->anim_no = ANIM_WALK; + x1 = ptActSelChar[i]->x + selectGraHitArea[i][0]; + y1 = ptActSelChar[i]->y + selectGraHitArea[i][1]; + x2 = x1 + selectGraHitArea[i][2]; + y2 = y1 + selectGraHitArea[i][3]; + StockBoxDispBuffer(x1, y1, x2, y2, DISP_PRIO_BOX, BoxColor, 0); + } + ptActSelChar[i]->anim_chr_no = selectGraNoTbl[i] + selCharColor[i] * 5; + ptActSelChar[i]->anim_ang = selCharDir[i]; + pattern(ptActSelChar[i], ANM_NOMAL_SPD, ANM_LOOP); + } + } + + if (selCharGraNoProcNo == 1) + { + id = focusGraId(selCharCanselGraId, sizeof(selCharCanselGraId) / sizeof(int)); + if (id == 0) + { + ShowBottomLineString(FONT_PAL_WHITE, "回到前一个画面。"); + } +#ifdef _TAIKEN + else + if( taikenFlag ) + { + ShowBottomLineString(FONT_PAL_WHITE,"体验版不能选择!"); + } +#endif + else + { + ShowBottomLineString(FONT_PAL_WHITE, "请选择一个人物。"); + } +#ifdef _NEW_WIN_POS_ + selCharCanselGraId[0] = + StockDispBuffer(64, 520, DISP_PRIO_BG, CG_CHR_MAKE_BACK_BTN, 2); +#else + // ?????? + selCharCanselGraId[0] = + StockDispBuffer( 64, 400, DISP_PRIO_BG, CG_CHR_MAKE_BACK_BTN, 2 ); +#endif + } + + if (ret == 0) + { +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_CHR_MAKE_SEL_BG, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_SEL_BG, 0 ); +#endif + } + + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + + return ret; +} + + + + +// ??????????????? +void initSelCharGraColorWin(void) +{ + selCharGraColorWinProcNo = 0; +} + +int selCharGraColorWin(void) +{ + static int fontId[] = { -2, -2, -2, -2 }; + static ACTION *ptActMenuWin = NULL; + int id; + int i; + static int x, y, w, h; + int ret = 0; + char msg[][16] = + { + " 决定 ", + " 改变颜色 ", + " 转动方向 ", + " 取消 " + }; + + // ??? + if (selCharGraColorWinProcNo == 0) + { + selCharGraColorWinProcNo = 1; + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + w = 2; + h = 3; + x = 496; + y = 41; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ? + if (id == 0) + { + ret = 1; + play_se(217, 320, 240); // ????? + } + else + // ??? + if (id == 1) + { + selCharColor[nowSelCharGraNo]++; + if (selCharColor[nowSelCharGraNo] > 3) + selCharColor[nowSelCharGraNo] = 0; + play_se(217, 320, 240); // ????? + } + else + // ???? + if (id == 2) + { + selCharDir[nowSelCharGraNo]++; + if (selCharDir[nowSelCharGraNo] > 7) + selCharDir[nowSelCharGraNo] = 0; + play_se(217, 320, 240); // ????? + } + else + // ????? + if (id == 3) + { + ret = 2; + play_se(217, 320, 240); // ????? + } + + // ??????????????? + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + + // ??????????????? + id = focusFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ? + if (id == 0) + { + ShowBottomLineString(FONT_PAL_WHITE, "决定目前所选择的人物。"); + } + else + // ??? + if (id == 1) + { + ShowBottomLineString(FONT_PAL_WHITE, "改变人物的颜色。"); + } + else + // ???? + if (id == 2) + { + ShowBottomLineString(FONT_PAL_WHITE, "转动人物的方向。"); + } + else + // ????? + if (id == 3) + { + ShowBottomLineString(FONT_PAL_WHITE, "回到选择人物的画面。"); + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = + StockFontBuffer(x + 22, y + i * 22 + 32, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, msg[i], 2); + } + } + } + + return ret; +} + + + +void initEditCharParam(void) +{ + editCharParamProcNo = 0; + + selCharNameBoxX = 104; + selCharNameBoxY = 102; + initStrBuffer(&selCharName, selCharNameBoxX, selCharNameBoxY, + CHAR_NAME_LEN, FONT_PAL_WHITE, FONT_PRIO_BACK); + selCharName.buffer[0] = '\0'; + selCharName.cnt = 0; + selCharName.cursor = 0; + GetKeyInputFocus(&selCharName); + +#ifdef __TEST_SERVER + if( (bNewServer & 0xf100000) == 0xf100000){ + nowSelCharStatusPoint = 550; + }else{ + nowSelCharStatusPoint = 20; + } +#else + //nowSelCharStatusPoint = 20; + nowSelCharStatusPoint = 0; +#endif + // nowSelCharStatus[0] = 0; + // nowSelCharStatus[1] = 0; + + nowSelCharStatus[0] = 10; + nowSelCharStatus[1] = 10; + + //end modified by lsh + nowSelCharStatus[2] = 0; + nowSelCharStatus[3] = 0; + nowSelCharAttrPoint = 10; + nowSelCharAttr[0] = 0; + nowSelCharAttr[1] = 0; + nowSelCharAttr[2] = 0; + nowSelCharAttr[3] = 0; +} + + +void initEditCharParam2(void) +{ + editCharParamProcNo = 0; + + selCharNameBoxX = 104; + selCharNameBoxY = 102; + initStrBuffer(&selCharName, selCharNameBoxX, selCharNameBoxY, + CHAR_NAME_LEN, FONT_PAL_WHITE, FONT_PRIO_BACK); + GetKeyInputFocus(&selCharName); +} +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 +typedef struct{ + int spr_num; //SPR图号 + int earth; //地属性 + int water; //水属性 + int fire; //火属性 + int wind; //风属性 + char name[16]; //宠物名称 +} BORNPETINFO; +#endif +// ??????????? +// +// ??: 0 ... ??? +// 1 ... ? +// 2 ... ????? +int editCharParam(void) +{ + int ret = 0; + char msg[64]; + int x1, y1, x2, y2; + int cnt = 1; +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + BORNPETINFO petinfo[4] = { + + { 100251 , 0 , 4 , 6 , 0 , "乌力乌力"}, + { 100296 , 2 , 0 , 0 , 8 , "凯比"}, + { 100292 , 0 , 7 , 3 , 0 , "克克尔"}, + { 100266 , 6 , 0 , 0 , 4 , "威伯"}}; + + /* { 101490 , 7 , 5 , 8 , 3 , "海贼王"}, + { 100444 , 10 , 10 , 10 , 10 , "黑暗精灵王"}, + { 100725 , 10 , 9 , 10 , 9 , "柯黑穆肯"}, + { 100451 , 1 , 1 , 1 , 1 , "玛雷菲雅"}}; + */ int BornPreBtn , BornNextBtn ; + int attrx1 , attry1 , attrx2 , attry2; + int BornBaseX = 430 , BornBaseY = 110 ; +#endif + static int graId[] = + { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + -2, -2, -2, -2, -2, -2}; +#else + - 2, -2, -2, -2 }; +#endif + int i; + int id, id2, id3; + + + int statusLocate[4][2] = + { + { 111, 250 }, + { 111, 278 }, + { 111, 305 }, + { 111, 334 } + }; + int attrLocate[4][2] = + { + { 297, 255 }, + { 297, 279 }, + { 297, 303 }, + { 297, 327 } + }; + int attrColor[4][2] = + { + { SYSTEM_PAL_GREEN, SYSTEM_PAL_GREEN2 }, + { SYSTEM_PAL_AQUA, SYSTEM_PAL_AQUA2 }, + { SYSTEM_PAL_RED, SYSTEM_PAL_RED2 }, + { SYSTEM_PAL_YELLOW, SYSTEM_PAL_YELLOW2 } + }; + int upDownBtnGraNo[][2] = + { + { CG_PREV_BTN, CG_PREV_BTN_DOWN }, + { CG_NEXT_BTN, CG_NEXT_BTN_DOWN } + }; + int selUseFlag = 0; + int btn1, btn2; + + + + GetKeyInputFocus(NULL); + + // ??? + if (editCharParamProcNo == 0) + { + for (i = 0; i < sizeof(graId) / sizeof(int); i++) + { + graId[i] = -2; + } + editCharParamProcNo++; + } + + // ??????? + id = -1; + id3 = -1; + if (editCharParamProcNo == 1) + { + selUseFlag = 2; + GetKeyInputFocus(&selCharName); + + // ?????????? + //id = selGraId( graId, sizeof( graId )/sizeof( int ) ); + id = selRepGraId(graId, sizeof(graId) / sizeof(int)); + id3 = pushGraId(graId, sizeof(graId) / sizeof(int)); + + + // ? + if (id == 0) + { + // ??????? + if (selCharName.cnt <= 0) + { + editCharParamProcNo = 100; + } + else + // ???????????????? + if (nowSelCharStatusPoint > 0) + { + editCharParamProcNo = 104; + } + else + // ??????????? + if (nowSelCharAttrPoint > 0) + { + editCharParamProcNo = 106; + } + else + // ??????? + { + strcpy(newCharacterName, selCharName.buffer); + newCharacterName[selCharName.cnt] = '\0'; + + if (cmpNameCharacterList(selCharName.buffer)) + { + // ???????? + editCharParamProcNo = 102; + } + else + // ????????????? + if (strstr(newCharacterName, " ") != NULL + || strstr(newCharacterName, " ") != NULL) + { + editCharParamProcNo = 108; + } + /*else + if(!CheckName(newCharacterName)) + { + editCharParamProcNo = 110; + }*/ + else + { + // ? + ret = 1; + newCharacterGraNo = + selectGraNoTbl[nowSelCharGraNo] + selCharColor[nowSelCharGraNo] * 5; + newCharacterFaceGraNo = + CG_CHR_MAKE_FACE + nowSelCharGraNo * 100 + + selCharColor[nowSelCharGraNo] * 25 + + nowSelCharEyeNo * 5 + nowSelCharMouthNo; + if (nowSelCharGraNo < 12) + newCharacterFaceGraNo = + CG_CHR_MAKE_FACE + nowSelCharGraNo * 100 + + selCharColor[nowSelCharGraNo] * 25 + + nowSelCharEyeNo * 5 + nowSelCharMouthNo; +#ifdef _MO_IMAGE_EXTENSION + else + newCharacterFaceGraNo = + CG_CHR_MAKE_NEWFACE+(nowSelCharGraNo-12)*100 + +selCharColor[nowSelCharGraNo]*25 + +nowSelCharEyeNo*5+nowSelCharMouthNo; +#endif + newCharacterVit = nowSelCharStatus[0]; + newCharacterStr = nowSelCharStatus[1]; + newCharacterTgh = nowSelCharStatus[2]; + newCharacterDex = nowSelCharStatus[3]; + newCharacterEarth = nowSelCharAttr[0]; + newCharacterWater = nowSelCharAttr[1]; + newCharacterFire = nowSelCharAttr[2]; + newCharacterWind = nowSelCharAttr[3]; +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + //用原来的出生点变数纪录出生宠 + newCharacterHomeTown = BornPetNum; +#endif + loginDp = 0; + play_se(217, 320, 240); // ????? + } + } + } + else + // ?? + if (id == 1) + { + ret = 2; + play_se(217, 320, 240); // ????? + } + else + // ???????????? + if (2 <= id && id <= 9) + { + id2 = id - 2; + // ????????? + if ((id2 % 2) == 0) + { + if (nowSelCharStatus[id2 / 2] > 0) + { + nowSelCharStatus[id2 / 2]--; + nowSelCharStatusPoint++; + play_se(217, 320, 240); // ????? + } + } + else + // ????????? + { + if (nowSelCharStatusPoint > 0) + { + +#ifdef __TEST_SERVER + if( nowSelCharStatusPoint > 100 ) + cnt = 10; + else + cnt = 1; + nowSelCharStatus[id2/2] += cnt; + nowSelCharStatusPoint -= cnt; + play_se( 217, 320, 240 ); +#else + nowSelCharStatus[id2 / 2]++; + nowSelCharStatusPoint--; + play_se(217, 320, 240); +#endif + + } + } + } + else + // ??? + if (10 <= id && id <= 17) + { + id2 = id - 10; + // ????????? + if ((id2 % 2) == 0) + { + if (nowSelCharAttr[id2 / 2] > 0) + { + nowSelCharAttr[id2 / 2]--; + nowSelCharAttrPoint++; + play_se(217, 320, 240); // ????? + } + } + else + // ????????? + { + int no, no2; + + no = id2 / 2; + if (no < 2) + { + no2 = no + 2; + } + else + { + no2 = no - 2; + } + + if (nowSelCharAttr[no2] == 0) + { + if (nowSelCharAttrPoint > 0) + { + nowSelCharAttr[no]++; + nowSelCharAttrPoint--; + play_se(217, 320, 240); // ????? + } + else + // ???????????????????????????? + // ????? + { + // ?????????????????????????????? + for (i = 0; i < 4; i++) + { + if (i != no && nowSelCharAttr[i] > 0) + { + break; + } + } + if (i < 4) + { + nowSelCharAttr[no]++; + nowSelCharAttr[i]--; + play_se(217, 320, 240); // ????? + } + } + } + } + } + else + if (id == 18 || id == 19) + { + // ????????? + if (id == 18) + { + if (nowSelCharEyeNo > 0) + { + nowSelCharEyeNo--; + } + else + { + nowSelCharEyeNo = 4; + } + } + else + // ????????? + { + if (nowSelCharEyeNo < 4) + { + nowSelCharEyeNo++; + } + else + { + nowSelCharEyeNo = 0; + } + } + play_se(217, 320, 240); // ????? + } + else + if (id == 20 || id == 21) + { + // ????????? + if (id == 20) + { + if (nowSelCharMouthNo > 0) + { + nowSelCharMouthNo--; + } + else + { + nowSelCharMouthNo = 4; + } + } + else + // ????????? + { + if (nowSelCharMouthNo < 4) + { + nowSelCharMouthNo++; + } + else + { + nowSelCharMouthNo = 0; + } + } + play_se(217, 320, 240); // ????? + } +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + else + if( id == 22 || id == 23 ) + { + if ( pActPet20 != NULL) + { + DeathAction( pActPet20 ); + pActPet20 = NULL; + } + if ( id == 22 ) + { + if ( BornPetNum > 0 ) + BornPetNum -- ; + else + BornPetNum = 3 ; + } + else + { + if ( BornPetNum < 3 ) + BornPetNum ++ ; + else + BornPetNum = 0 ; + } + play_se( 217, 320, 240 ); + } +#endif + } + + + // ???????? + // ???? + if (editCharParamProcNo == 100) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 101) + { + if (commonMsgWin("没有输入名字!")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + // ???? + if (editCharParamProcNo == 102) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 103) + { + if (commonMsgWin("已经有同名的人物存在了!")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + // ???????????????? + if (editCharParamProcNo == 104) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 105) + { + if (commonMsgWin("请将状态的点数分配完毕!")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + // ??????????? + if (editCharParamProcNo == 106) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 107) + { + if (commonMsgWin("请将属性的点数分配完毕!")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + // ???? + if (editCharParamProcNo == 108) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 109) + { + if (commonMsgWin("名字里面不可以有空白!")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + if (editCharParamProcNo == 110) + { + initCommonMsgWin(); + editCharParamProcNo++; + play_se(220, 320, 240); // ??? + } + if (editCharParamProcNo == 111) + { + if (commonMsgWin("你输入的名字有不允许字符")) + { + // OK???????? + editCharParamProcNo = 1; + } + } + + + //  + if (editCharParamProcNo == 1) + { + id = focusGraId(graId, sizeof(graId) / sizeof(int)); + if (id == 0) + { + ShowBottomLineString(FONT_PAL_WHITE, "决定人物的设定。"); + } + else + if (id == 1) + { + ShowBottomLineString(FONT_PAL_WHITE, "回到前一个画面。"); + } + else + if (2 <= id && id <= 9) + { + id -= 2; + id /= 2; + if (id == 0) + { + ShowBottomLineString(FONT_PAL_WHITE, "这项主要与耐久力有关。"); + } + else + if (id == 1) + { + ShowBottomLineString(FONT_PAL_WHITE, "这项主要与攻击力有关。"); + } + else + if (id == 2) + { + ShowBottomLineString(FONT_PAL_WHITE, "这项主要与防御力有关。"); + } + else + if (id == 3) + { + ShowBottomLineString(FONT_PAL_WHITE, "这项主要与战斗时的行动顺序有关。"); + } + } + else + if (10 <= id && id <= 17) + { + id -= 10; + id /= 2; + if (id == 0) + { + ShowBottomLineString(FONT_PAL_WHITE, "地属性。与水属性的对手战斗时较为有利。"); + } + else + if (id == 1) + { + ShowBottomLineString(FONT_PAL_WHITE, "水属性。与火属性的对手战斗时较为有利。"); + } + else + if (id == 2) + { + ShowBottomLineString(FONT_PAL_WHITE, "火属性。与风属性的对手战斗时较为有利。"); + } + else + if (id == 3) + { + ShowBottomLineString(FONT_PAL_WHITE, "风属性。与地属性的对手战斗时较为有利。"); + } + } + else + if (id == 18 || id == 19) + { + if (nowSelCharGraNo != 0 && nowSelCharGraNo != 6) + { + ShowBottomLineString(FONT_PAL_WHITE, "改变眼睛的形状。"); + } + else + { + ShowBottomLineString(FONT_PAL_WHITE, "改变鼻子的形状。"); + } + } + else + if (id == 20 || id == 21) + { + ShowBottomLineString(FONT_PAL_WHITE, "改变嘴巴的形状。"); + } + else + { + ShowBottomLineString(FONT_PAL_WHITE, "设定姓名、长相、基本状态与属性。"); + } + } + + + + StockFontBuffer2(&selCharName); + + if (nowSelCharGraNo < 12) + StockDispBuffer(93, 172, DISP_PRIO_BG, + CG_CHR_MAKE_FACE + nowSelCharGraNo * 100 + selCharColor[nowSelCharGraNo] * 25 + + nowSelCharEyeNo * 5 + nowSelCharMouthNo, + 0); +#ifdef _MO_IMAGE_EXTENSION + else + StockDispBuffer( 93, 172, DISP_PRIO_BG, + CG_CHR_MAKE_NEWFACE+(nowSelCharGraNo-12)*100+selCharColor[nowSelCharGraNo]*25 + +nowSelCharEyeNo*5+nowSelCharMouthNo, + 0 ); +#endif + + sprintf_s(msg, "%3d", nowSelCharStatusPoint); + StockFontBuffer(161, 224, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + + // ????????? + for (i = 0; i < 4; i++) + { + sprintf_s(msg, "%3d", nowSelCharStatus[i]); + StockFontBuffer(statusLocate[i][0], statusLocate[i][1], + FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + } + + sprintf_s(msg, "%3d", nowSelCharAttrPoint); + StockFontBuffer(350, 224, FONT_PRIO_BACK, FONT_PAL_WHITE, msg, 0); + + + // ???? + for (i = 0; i < 4; i++) + { + if (nowSelCharAttr[i] > 0) + { + x1 = attrLocate[i][0]; + y1 = attrLocate[i][1]; + x2 = x1 + nowSelCharAttr[i] * 8; + y2 = y1 + 8; + StockBoxDispBuffer(x1, y1, x2, y2, DISP_PRIO_IME2, attrColor[i][0], 1); + StockBoxDispBuffer(x1 + 1, y1 + 1, x2 + 1, y2 + 1, DISP_PRIO_IME1, attrColor[i][1], 0); + StockBoxDispBuffer(x1 + 2, y1 + 2, x2 + 2, y2 + 2, DISP_PRIO_IME1, attrColor[i][1], 0); + } + } + + + // ????? + + graId[0] = StockDispBuffer(320, 410, DISP_PRIO_CHAR, CG_CHR_MAKE_OK_BTN, selUseFlag); + // ?????? + graId[1] = StockDispBuffer(420, 410, DISP_PRIO_CHAR, CG_CHR_MAKE_BACK_BTN, selUseFlag); + + for (i = 0; i < 4; i++) + { + btn1 = 0; + btn2 = 0; + if (2 <= id3 && id3 <= 9 + && (id3 - 2) / 2 == i) + { + if (((id3 - 2) % 2) == 0) + { + btn1 = 1; + } + else + { + btn2 = 1; + } + } + // < ??? + graId[i * 2 + 2] = StockDispBuffer(statusLocate[i][0] + 51, statusLocate[i][1] + 8, + DISP_PRIO_CHAR, upDownBtnGraNo[0][btn1], selUseFlag); + + // > ??? + graId[i * 2 + 3] = StockDispBuffer(statusLocate[i][0] + 87, statusLocate[i][1] + 8, + DISP_PRIO_CHAR, upDownBtnGraNo[1][btn2], selUseFlag); + } + + for (i = 0; i < 4; i++) + { + if (i == 0 && nowSelCharAttr[i + 2] == 0 + || i == 1 && nowSelCharAttr[i + 2] == 0 + || i == 2 && nowSelCharAttr[i - 2] == 0 + || i == 3 && nowSelCharAttr[i - 2] == 0) + { + btn1 = 0; + btn2 = 0; + if (10 <= id3 && id <= 17 + && (id3 - 10) / 2 == i) + { + if (((id3 - 10) % 2) == 0) + { + btn1 = 1; + } + else + { + btn2 = 1; + } + } + + // < ??? + graId[i * 2 + 10] = StockDispBuffer(attrLocate[i][0] + 101, attrLocate[i][1] + 5, + DISP_PRIO_CHAR, upDownBtnGraNo[0][btn1], selUseFlag); + + // > ??? + graId[i * 2 + 11] = StockDispBuffer(attrLocate[i][0] + 137, attrLocate[i][1] + 5, + DISP_PRIO_CHAR, upDownBtnGraNo[1][btn2], selUseFlag); + } + else + { + graId[i * 2 + 10] = -2; + graId[i * 2 + 11] = -2; + } + } + + for (i = 0; i < 2; i++) + { + btn1 = 0; + btn2 = 0; + if (18 <= id3 && id3 <= 21 + && (id3 - 18) / 2 == i) + { + if (((id3 - 18) % 2) == 0) + { + btn1 = 1; + } + else + { + btn2 = 1; + } + } + + // < ??? + graId[i * 2 + 18] = + StockDispBuffer(156, 172 + i * 24, + DISP_PRIO_CHAR, upDownBtnGraNo[0][btn1], selUseFlag); + // > ??? + graId[i * 2 + 19] = + StockDispBuffer(260, 172 + i * 24, + DISP_PRIO_CHAR, upDownBtnGraNo[1][btn2], selUseFlag); + } + + if (nowSelCharGraNo != 0 && nowSelCharGraNo != 6) + { + StockDispBuffer(320, 240, DISP_PRIO_CHAR, CG_CHR_MAKE_EYE_SEL, 0); + } + else + { + StockDispBuffer(320, 240, DISP_PRIO_CHAR, CG_CHR_MAKE_NOSE_SEL, 0); + } +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 + BornPreBtn = 0; + BornNextBtn = 0; + if( id3 == 22 || id3 == 23 ) + { + if( id3 == 22 ) + BornPreBtn = 1; + else + BornNextBtn = 1; + } + attrx1 = BornBaseX + 35 ; + if ( petinfo[BornPetNum].earth > 0 ) + { + attry1 = BornBaseY ; + attrx2 = attrx1 + petinfo[BornPetNum].earth * 8 ; + attry2 = attry1 + 8 ; + StockBoxDispBuffer( attrx1 , attry1 , attrx2 , attry2 , DISP_PRIO_IME2 , SYSTEM_PAL_GREEN , 1); + StockBoxDispBuffer( attrx1+1 , attry1+1 , attrx2+1 , attry2+1 , DISP_PRIO_IME1 , SYSTEM_PAL_GREEN2 , 0); + StockBoxDispBuffer( attrx1+2 , attry1+2 , attrx2+2 , attry2+2 , DISP_PRIO_IME1 , SYSTEM_PAL_GREEN2 , 0); + } + if ( petinfo[BornPetNum].water > 0 ) + { + attry1 = BornBaseY + 20 ; + attrx2 = attrx1 + petinfo[BornPetNum].water * 8 ; + attry2 = attry1 + 8 ; + StockBoxDispBuffer( attrx1 , attry1 , attrx2 , attry2 , DISP_PRIO_IME2 , SYSTEM_PAL_AQUA , 1); + StockBoxDispBuffer( attrx1+1 , attry1+1 , attrx2+1 , attry2+1 , DISP_PRIO_IME1 , SYSTEM_PAL_AQUA2 , 0); + StockBoxDispBuffer( attrx1+2 , attry1+2 , attrx2+2 , attry2+2 , DISP_PRIO_IME1 , SYSTEM_PAL_AQUA2 , 0); + } + if ( petinfo[BornPetNum].fire > 0 ) + { + attry1 = BornBaseY + 40 ; + attrx2 = attrx1 + petinfo[BornPetNum].fire * 8 ; + attry2 = attry1 + 8 ; + StockBoxDispBuffer( attrx1 , attry1 , attrx2 , attry2 , DISP_PRIO_IME2 , SYSTEM_PAL_RED , 1); + StockBoxDispBuffer( attrx1+1 , attry1+1 , attrx2+1 , attry2+1 , DISP_PRIO_IME1 , SYSTEM_PAL_RED2 , 0); + StockBoxDispBuffer( attrx1+2 , attry1+2 , attrx2+2 , attry2+2 , DISP_PRIO_IME1 , SYSTEM_PAL_RED2 , 0); + } + if ( petinfo[BornPetNum].wind > 0 ) + { + attry1 = BornBaseY + 60 ; + attrx2 = attrx1 + petinfo[BornPetNum].wind * 8 ; + attry2 = attry1 + 8 ; + StockBoxDispBuffer( attrx1 , attry1 , attrx2 , attry2 , DISP_PRIO_IME2 , SYSTEM_PAL_YELLOW , 1); + StockBoxDispBuffer( attrx1+1 , attry1+1 , attrx2+1 , attry2+1 , DISP_PRIO_IME1 , SYSTEM_PAL_YELLOW2 , 0); + StockBoxDispBuffer( attrx1+2 , attry1+2 , attrx2+2 , attry2+2 , DISP_PRIO_IME1 , SYSTEM_PAL_YELLOW2 , 0); + } + + StockFontBuffer( BornBaseX + 15 , BornBaseY - 33, FONT_PRIO_FRONT, FONT_PAL_WHITE , petinfo[BornPetNum].name , 0 ); + graId[22] = StockDispBuffer( BornBaseX - 105 , BornBaseY + 85 , DISP_PRIO_CHAR, upDownBtnGraNo[0][BornPreBtn], selUseFlag ); + graId[23] = StockDispBuffer( BornBaseX - 30 , BornBaseY + 85 , DISP_PRIO_CHAR, upDownBtnGraNo[1][BornNextBtn], selUseFlag ); + StockDispBuffer( BornBaseX - 3 , BornBaseY - 4 , DISP_PRIO_CHAR , CG_NEWBORNPET_WND , 0 ); + if( pActPet20 == NULL ) + { + //3~9 + pActPet20 = MakeAnimDisp( BornBaseX - 60 , BornBaseY + 45 , petinfo[BornPetNum].spr_num , 0 ); + } +#endif +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_CHR_MAKE_BG, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_BG, 0 ); +#endif + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + FlashKeyboardCursor(); // ??????????? + ImeProc(); // ??????? + + return ret; +} + + + + +// 佋? +// ??? +void initSelHomeTown(void) +{ + selHomeTownProcNo = 0; + nowSelHomeTownNo = 0; +} + + +// 佋??? +// +// ??: 0 ... ??? +// 1 ... ? +// 2 ... ????? +int selHomeTown(void) +{ + static int btnId[] = { -2, -2, -2, -2, -2 }; + int id; + int ret = 0; + int ret2; + char *homeTownName[] = + { + "萨姆吉尔村", + "玛丽娜丝村", + "加加村", + "卡鲁它那村" + }; + int selUseFlag = 0; + int i; + + // ??? + if (selHomeTownProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + selHomeTownProcNo++; + } + + // 佋? + if (selHomeTownProcNo == 1) + { + selUseFlag = 2; + } + + // ???? + if (selHomeTownProcNo == 10) + { + ret2 = commonYesNoWindow(320, 240); + // ?? + if (ret2 == 1) + { + ret = 1; + selHomeTownProcNo = 11; // ??? + } + else + // ??? + if (ret2 == 2) + { + selHomeTownProcNo = 1; + } + } + + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + // ????? + if (id == 0) + { + ret = 2; + play_se(217, 320, 240); // ????? + } +#ifndef _TAIKEN + if (1 <= id && id <= 4) +#else + if( id == 2 ) +#endif + { + nowSelHomeTownNo = id - 1; + newCharacterHomeTown = nowSelHomeTownNo; + selHomeTownProcNo = 10; + play_se(217, 320, 240); // ????? + } +#ifdef _TAIKEN + else + if( id == 1 || 3 <= id && id <= 4 ) + { + play_se( 220, 320, 240 ); // ??? + } +#endif + + if (selHomeTownProcNo == 1) + { + id = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + } +#ifdef _SPECIAL_LOGO + int ix = 80; + int iy = 18; +#else + int ix = 50; + int iy = 0; +#endif + + + // ?????? +#ifdef _DELBORNPLACE //Syu ADD 6.0 统一出生于新手村 +#else + if (id == 1) + { + StockFontBuffer(454 + ix, 135 + iy, + FONT_PRIO_BACK, FONT_PAL_YELLOW, homeTownName[0], 0); +#ifndef _TAIKEN + StockFontBuffer(386 + ix, 158 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "位在萨伊那斯的东边,", 0); + StockFontBuffer(386 + ix, 178 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "是四个村子中最大", 0); + StockFontBuffer(386 + ix, 198 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "也是最整齐的村子。", 0); +#else + StockFontBuffer( 390 + ix, 176 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "体验版不能选择!", 0 ); +#endif + } + else + // ?????? + if (id == 2) + { + StockFontBuffer(454 + ix, 135 + iy, + FONT_PRIO_BACK, FONT_PAL_YELLOW, homeTownName[1], 0); + StockFontBuffer(390 + ix, 168 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "位在萨伊那斯的西边", 0); + StockFontBuffer(390 + ix, 188 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "面向美丽海滩的村子。", 0); + } + else + // ?????? + if (id == 3) + { + StockFontBuffer(474 + ix, 135 + iy, + FONT_PRIO_BACK, FONT_PAL_YELLOW, homeTownName[2], 0); +#ifndef _TAIKEN + StockFontBuffer(390 + ix, 158 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "位在加鲁卡的东边,", 0); + StockFontBuffer(390 + ix, 178 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "四周被森林围绕着", 0); + StockFontBuffer(390 + ix, 198 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "绿意盎然的村子。", 0); +#else + StockFontBuffer( 390, 176 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "体验版不能选择!", 0 ); +#endif + } + else + // ??????? + if (id == 4) + { + StockFontBuffer(454 + ix, 135 + iy, + FONT_PRIO_BACK, FONT_PAL_YELLOW, homeTownName[3], 0); +#ifndef _TAIKEN + StockFontBuffer(390 + ix, 158 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "位在加鲁卡的西边。", 0); + StockFontBuffer(390 + ix, 178 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "村子是在好几个小小", 0); + StockFontBuffer(390 + ix, 198 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "的岛上建立起来的。", 0); +#else + StockFontBuffer( 390 + ix, 176 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "体验版不能选择!", 0 ); +#endif + } + else + // ????????? + if (id == 0) + { + StockFontBuffer(390 + ix, 176 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "回到前一个画面。", 0); + } + else + { + StockFontBuffer(390 + ix, 176 + iy, + FONT_PRIO_BACK, FONT_PAL_BLUE, "请选择出身地。", 0); + } +#ifdef _SPECIAL_LOGO + btnId[0] = StockDispBuffer(675, 450, DISP_PRIO_CHAR, CG_CHR_MAKE_BACK_BTN, selUseFlag); + btnId[1] = StockDispBuffer(380, 295, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME0, selUseFlag); + btnId[2] = StockDispBuffer(370, 295, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME1, selUseFlag); + btnId[3] = StockDispBuffer(400, 295, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME2, selUseFlag); + btnId[4] = StockDispBuffer(445, 295, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME3, selUseFlag); +#else + btnId[0] = StockDispBuffer( 412, 296, DISP_PRIO_CHAR, CG_CHR_MAKE_BACK_BTN, selUseFlag ); + + btnId[1] = StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME0, selUseFlag ); + btnId[2] = StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME1, selUseFlag ); + btnId[3] = StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME2, selUseFlag ); + btnId[4] = StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_HOME_NAME3, selUseFlag ); +#endif +#ifdef _NEW_WIN_POS_ + StockDispBuffer(400, 300, DISP_PRIO_BG, CG_CHR_MAKE_SEL2_BG, 0); +#else + StockDispBuffer( 320, 240, DISP_PRIO_BG, CG_CHR_MAKE_SEL2_BG, 0 ); +#endif +#endif + return ret; +} + + + + +// ?????? +// ??? +void initCreateChar(void) +{ + createCharProcNo = 0; +} + + +// ?????? +// ??: 0 ... ??? +// 1 ... ?? +// 2 ...  +int createChar(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + int ret2; + char msg[] = "人物制作中..."; + + // ??? + if (createCharProcNo == 0) + { + createCharProcNo++; + + // ?????? + w = (strlen(msg) * 9 + 63) / 64; + if (w < 2) + w = 2; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ????? + if (createCharProcNo == 1) + { + createNewCharStart(); + createCharProcNo++; + } + if (createCharProcNo == 2) + { + ret2 = createNewCharProc(); + // ?? + if (ret2 == 1) + { + ret = 1; + } + else + //  + if (ret2 < 0) + { + ret = 2; + } + } + + + // ??????????????? + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx, yy; + + len = strlen(msg) / 2; + xx = (w * 64 - len * 17) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} + +void initCharLogin(void); +int charLogin(void); + +void characterLoginProc(void) +{ + int ret; + static char msg[256]; + + if (SubProcNo == 0){ + initCharLogin(); + SubProcNo++; + } + if (SubProcNo == 1){ + ret = charLogin(); + if (ret == 0) { + // 签入成功 + } + else if (ret == 1){ +#ifdef _TAIKEN + if( createCharFlag ){ + char title[128] = "体验版"; + if( bNewServer) + lssproto_FT_send( sockfd, title ); + else + old_lssproto_FT_send( sockfd, title ); + } +#endif + //andy_reedit initchat + InitChat(); + ChangeProc(PROC_GAME); + } + else + if (ret == -1) + { + SubProcNo = 100; + strcpy(msg, NET_ERRMSG_LOGINTIMEOUT); + } + else + if (ret == -2){ + SubProcNo = 100; + // strcpy(msg, "签入处理失败。(1001)"); + strcpy(msg, "您的账号目前正在离线,请重新登录。"); + } + else + if (ret == -3){ + SubProcNo = 100; + strcpy(msg, "按照版署《网络游戏未成年人防沉迷系统》规定,您未通过验证,\n将被强制离线,如有疑问请登录网站查询或进行验证"); + } + +#ifdef _NEW_WGS_MSG // WON ADD WGS的新视窗 + + else if( ret == 101 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "无法与资料服务器取得连系" ); + } + else if( ret == 102 ){ + SubProcNo = 100; + strcpy( msg, "无法由资料库取得正确资讯" ); + } + else if( ret == 103 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "服务器忙碌中,请稍待一会再试" ); + } + else if( ret == 104 ){ + SubProcNo = 100; + strcpy( msg, "输入的资料格式不正确" ); + } + else if( ret == 201 ){ + SubProcNo = 100; + strcpy( msg, "错误的使用者名称或密码, 若您尚未加入会员, 请先到游戏网站免费加入会员" ); + } + else if( ret == 202 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "同一个使用者不得重覆登入" ); + } + else if( ret == 203 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "同一帐号已在线上" ); + } + else if( ret == 204 ){ // 2.1 New // 同星系重覆登入 + SubProcNo = 100; + //strcpy( msg, "您已在此星系登入" ); + strcpy( msg, "使用者已在进行游戏" ); + } + else if( ret == 205 ){ + SubProcNo = 100; + strcpy( msg, "未登入此游戏或登入错误" ); + } + else if( ret == 206 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "同名帐号已存在" ); + } + else if( ret == 207 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "会员帐号已经启动" ); + } + else if( ret == 208 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "错误的启动码" ); + } + else if( ret == 209 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "会员帐号尚未启动" ); + } + else if( ret == 210 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "会员帐号和密码只能使用英文字母和数字" ); + } + else if( ret == 211 ){ + SubProcNo = 100; + strcpy( msg, "此帐号已被停权, 如有问题请联系客服" ); + } + else if( ret == 212 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "请先到游戏网站重新确认个人资料, 再启动此游戏" ); + } + else if( ret == 213 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "登入逾时, 请重新登入" ); + } + else if( ret == 214 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "网页尚未登入" ); + } + else if( ret == 220 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "此帐号已转换为新游戏会员" ); + } + else if( ret == 222 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "请先到游戏网站更新游戏管理帐号的密码, 再启动此游戏" ); + } + else if( ret == 301 ){ + SubProcNo = 100; + strcpy( msg, "此产品尚未注册, 请先到游戏网站完成注册" ); + } + else if( ret == 402 ){ + SubProcNo = 100; + strcpy( msg, "游戏点数卡已用完点数, 请购买点数卡再至游戏网站完成注册" ); + } + else if( ret == 405 ){ + SubProcNo = 100; + strcpy( msg, "游戏点数不足, 请购买点数卡再至游戏网站注册" ); + } + else if( ret == 999 ){ // 2.1 New + SubProcNo = 100; + strcpy( msg, "网路连线错误" ); + } + else if( ret >= 2030 && ret < 2044 ){ // 不同星系重覆登入 + int star=-1; + star = ret - 2030; + SubProcNo = 100; + + // 依照 cs 的 acid 号码设的 + switch( star ){ + case 0: strcpy( msg, "您已在其他星系登入。" ); break; + case 1: strcpy( msg, "您已在太阳星系登入" ); break; + case 2: strcpy( msg, "您已在天神星系登入" ); break; + case 3: strcpy( msg, "您已在北斗星系登入" ); break; + case 4: strcpy( msg, "您已在紫微星系登入" ); break; + case 5: strcpy( msg, "您已在苍龙星系登入" ); break; + case 6: strcpy( msg, "您已在银河星系登入" ); break; + case 7: strcpy( msg, "您已在香港星系登入" ); break; + case 8: strcpy( msg, "您已在星乐园星系登入" ); break; + case 9: strcpy( msg, "您已在网路家庭星系登入" ); break; + case 10: strcpy( msg, "您已在圣兽星系登入" ); break; + case 11: strcpy( msg, "您已在天鹰星系登入" ); break; + case 12: strcpy( msg, "您已在新界星系登入" ); break; + case 13: strcpy( msg, "您已在测试星系登入" ); break; + default: strcpy( msg, "签入处理失败。(1002)" ); break; + } + } + + else { + SubProcNo = 100; + sprintf_s( msg, "签入处理失败(%d)。", ret ); + } +#endif + +#ifdef _STONDEBUG_ + char msg2[1024]; + sprintf_s( msg2, "%d %s", ret, msg); + strncpy_s( msg, msg2, sizeof(msg) ); +#endif + + } + if (SubProcNo == 100){ + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101){ + if (commonMsgWin(msg)){ + // OK???????? + ChangeProc(PROC_TITLE_MENU); + } + } + RunAction(); + StockTaskDispBuffer(); +} + + +static short charLoginProcNo = 0; + +// ??? +void initCharLogin(void) +{ + charLoginProcNo = 0; +} + +// ????? +// +// ??: 0 ... ????? +// 1 ... ?????? +// -1 ... ?????? +// -2 ... ??? +int charLogin(void) +{ + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + static char msg[] = "签入中"; + + // ??? + if (charLoginProcNo == 0) + { + charLoginProcNo = 1; + + // ?????? + w = strlen(msg) * 9 / 64 + 2; + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + + // ???????? + if (charLoginProcNo == 1) + { +#ifdef _AIDENGLU_ + extern int 是否重登; + extern int 是否重登战斗了; + extern int 自动登陆是否开启; + extern int 是否重登AI模式; + extern int 是否重登人物方向; + extern int 是否重登组队; + extern int 是否重登喊话; + extern int 是否重开登组队_1; + 是否重登战斗了 = FALSE; + 是否重登 = FALSE; + 是否重登组队 = FALSE; + 是否重登AI模式 = FALSE; + 是否重登喊话 = FALSE; + 是否重开登组队_1 = FALSE; + if (PcLanded.大区 >= 0 && PcLanded.小区 >= 0 && PcLanded.人物 >= 0 && 自动登陆是否开启){ + 是否重登 = TRUE; + 是否重登AI模式 = TRUE; + 是否重登人物方向 = TRUE; + if (PcLanded.是否自动遇敌&&PcLanded.队模 != 1) + 是否重登战斗了 = TRUE; + if (PcLanded.队模 == 1) + 是否重登组队 = TRUE; + if (PcLanded.是否自动喊话) + 是否重登喊话 = TRUE; + if (PcLanded.队模 == 0) + 是否重开登组队_1 = TRUE; + } +#endif + charLoginStart(); + charLoginProcNo++; + } + else + if (charLoginProcNo == 2) + { + ret = charLoginProc(); + } + + if (ret != 0) + { + if (ptActMenuWin) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + + if (ptActMenuWin != NULL) + { + // ????? + if (ptActMenuWin->hp >= 1) + { + int len; + int xx, yy; + + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} + + + + +static int produce_logout(void); +static int produce_vct_no = 0; + +/////////////////////////////////////////////////////////////////////////// +// +// ???????? +// + +void initCharLogout(void); +int charLogout(void); + +void characterLogoutProc(void) +{ + int ret; + static char msg[256]; + + if (SubProcNo == 0){ + logOutFlag = TRUE; + + if (!produce_logout()){ //???? + return; + } +#ifdef __SKYISLAND + extern void SkyIslandRelease(); + SkyIslandRelease(); +#endif + //??????? + produce_vct_no = 0; + +#ifdef _AniRandom // Syu ADD 随机产生环境动画 + extern void AniRandomRelease(); + AniRandomRelease(); +#endif + +#ifdef _AniCrossFrame // Syu ADD 动画层游过画面生物 + extern void crossAniRelease(); + crossAniRelease(); +#endif +#ifdef _AniCharBubble // Syu ADD 动画层人物吐出气泡 + extern void CharbubbleRelease(); + CharbubbleRelease(); +#endif +#ifdef _AniImmobile // Syu ADD 定点产生特定动画 + extern void ImmobileAniRelease(); + ImmobileAniRelease(); +#endif +#ifdef _SPECIALSPACEANIM // Syu ADD 特殊场景动画配置 + extern void ReleaseSpecAnim(); + ReleaseSpecAnim(); +#endif + // PC???? + resetPc(); + + // ????????????? + initCharObj(); + + // ?????? + DeathAllAction(); + + // ??????? + // fade_out_bgm(); + + if (!offlineFlag) + { + SubProcNo++; + } + else + { + // ??????S? WM_CLOSE ?????????? + PostMessage(hWnd, WM_CLOSE, 0, 0L); + } + } + + if (SubProcNo == 1) + { + initCharLogout(); + SubProcNo++; + } + else + if (SubProcNo == 2){ + ret = charLogout(); + if (ret == 1){ + cleanupNetwork(); + DeathAllAction(); + ChangeProc(PROC_ID_PASSWORD); + SubProcNo = 0; + } + else + // ?????? + if (ret == -1) + { + // ????????? + cleanupNetwork(); + SubProcNo = 100; + strcpy(msg, NET_ERRMSG_LOGOUTTIMEOUT); + } + else + // ??? + if (ret == -2) + { + // ????????? + cleanupNetwork(); + SubProcNo = 100; + strcpy(msg, "签出处理失败。"); + } + } + + // ??? + if (SubProcNo == 100) + { + initCommonMsgWin(); + SubProcNo++; + } + if (SubProcNo == 101) + { + if (commonMsgWin(msg)) + { + // OK???????? + //cary + ChangeProc(PROC_ID_PASSWORD); // ????? + SubProcNo = 0; + } + } + + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? +} + + +static int charLogoutProcNo; + +// ?????????? +void initCharLogout(void) +{ + charLogoutProcNo = 0; +} + + +// ??????? +// ??: 0 ... ?????? +// 1 ... ???????? +// -1 ... ?????? +// -2 ... ??? +int charLogout(void) +{ + extern unsigned int systemWndNo; // ?????? + static ACTION *ptActMenuWin = NULL; + static int x, y, w, h; + int ret = 0; + static char msg[] = "签出中"; + + if (systemWndNo != 1){ +#ifdef _CHAR_NEWLOGOUT + lssproto_CharLogout_send(sockfd, 0); +#endif + return 1; + } + if (charLogoutProcNo == 0){ + charLogoutProcNo = 1; + w = strlen(msg) * 9 / 64 + 2; + h = (16 + 47) / 48; + if (h < 2) + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + } + if (charLogoutProcNo == 1){ + charLogoutStart(); + charLogoutProcNo++; + } + else + if (charLogoutProcNo == 2){ + ret = charLogoutProc(); + } + + if (ret != 0){ + if (ptActMenuWin){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + if (ptActMenuWin != NULL){ + if (ptActMenuWin->hp >= 1){ + int len; + int xx, yy; + len = strlen(msg); + xx = (w * 64 - len * 8) / 2; + yy = (h * 48 - 16) / 2; + StockFontBuffer(x + xx, y + yy, FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + } + } + + return ret; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + +/////////////////////////////////////////////////////////////////////////// +// ?????????????? +// +// ?????: ?40? ? 8? +// +// ????????????openServerWindowProc????? +int windowTypeWN = -1; // ???????? -1?? +int buttonTypeWN = 0; // ??????(???) +int indexWN; // ?????? +int idWN; // ?????? +// shan begin +//char msgWN[25][70]; // ?????? +char msgWN[25][256]; +//shan end +int msgWNLen; // ?????????? +int msgWN_W; // ???????????? +int msgWN_H; // ????????????? +ACTION *ptActMenuWin = NULL; + +int selStartLine; // ?????????????????? +int wnOpenX, wnOpenY; // ?????????????????? +short wnCloseFlag = 0; // ???????????? + + +#define MAX_SHOP_ITEM 8 // ?????????????????? +#define MAX_SHOP_PAGE 8 // ????????????????? +short shopWindowMode; // ??????????????0...????,1...????? +char shopWindow1Title[27]; // ?????????????? +char shopWindow1Msg[27]; // ??????????????? +#ifdef _NEW_SHOP_FRAME +char shopWindowCurrency[27]; +#endif +typedef struct +{ + int level; + int price; + int graNo; + short sealFlag; + short tbl; + char name[ITEM_NAME_LEN + 1]; + char info[3][29]; + int num; +#ifdef _NEW_MANOR_LAW + int costfame; +#endif +} ITEM_SHOP; + +int menuIndexWN; // ??????(???????????) +char shopWindow2Msg[2][45]; // ??????????????? +short shopWondow2Page, shopWondow2MaxPage; // ?????????? +ITEM_SHOP sealItem[MAX_SHOP_ITEM*MAX_SHOP_PAGE]; // ????? +short selShopItemNo; // ?????? + +char shopWindow3Msg[41]; +short sealItemCnt; + +char shopWindow4Msg[2][39]; // ??????????????? +char shopWindow5Msg[2][39]; // ??????????????? +char shopWindow6Msg[2][39]; // ??????????????? + +short nowUserItemCnt; +char shopWindow7Msg[2][39]; // ??????????????? +char shopWindow8Msg[2][39]; // ??????????????? + + +// Shan Add (Begin) +int FMmsgWN[16]; +int FMelderFlag[16]; +int FMpidWN[16]; +int FMdengonidex; +char FMnameWN[11][20]; +time_t FMHoldTime; +// end + +#ifdef _BLACK_MARKET +struct BlackMarketItem{ + int iIndex; + char iName[128]; + int iGraphicsNum; +}; +struct BlackMarketItem BMItem[12]; +int sItem = -1; +#endif + +ITEM_SHOP userItem[MAX_SHOP_ITEM*MAX_SHOP_PAGE]; // ????????????? + +short buyOffFlag; // ???? + + +#define MAX_SKILL_SHOP_SKILL 8 // ????????????????? +// Robin fix 好像太少 +//#define MAX_SKILL_SHOP_PAGE 2 // ?????????????? +#define MAX_SKILL_SHOP_PAGE 10 // ?????????????? + +typedef struct +{ + int price; + int icon; +#ifdef _PETKILL_COST_FAME + int iCoseFame; +#endif + char name[SKILL_NAME_LEN + 1]; + char info[3][25]; +} SKILL_SHOP; + +SKILL_SHOP sealSkill[MAX_SKILL_SHOP_SKILL*MAX_SKILL_SHOP_PAGE]; + + +short skillShopWindowProcNo; +short selShopSkillNo; +short selShopSkillPetNo; +short selShopSkillSlotNo; + + +#define MAX_POOL_SHOP_ITEM 8 // ?????????????? + +#ifdef _ADD_POOL_ITEM // WON ADD 增加寄放道具 +//#define MAX_POOL_SHOP_PAGE 10 +#define MAX_POOL_SHOP_PAGE 13 +#else +#define MAX_POOL_SHOP_PAGE 3 // ????? +#endif + +typedef struct +{ + int level; + int price; + int graNo; + short poolFlag; + short tbl; + char name[ITEM_NAME_LEN + 1]; + char info[3][29]; +#ifdef _ITEM_PILENUMS + int num; +#endif +} POOL_SHOP; + +int restPoolSlot; // ???????????????? + +POOL_SHOP poolItem[MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE]; + + +void initServerWindowType0(char *); +void initServerWindowType1(char *); +void initServerWindowType2(char *); +void initServerWindowType3(char *); +void initServerWindowType4(char *); +void initServerWindowType5(char *); +void initServerWindowType6(char *); +void initServerWindowType7(char *); +void serverWindowType0(int); +void serverWindowType1(void); +void serverWindowType2(void); +void serverWindowType3(void); +void serverWindowType4(void); +void serverWindowType5(void); +void serverWindowType6(void); +void serverWindowType7(void); +void serverWindowType9(void); + +#ifdef _CHAR_PROFESSION // WON ADD 人物职业技能 +void initServerWindowProfession( char *data ); +void profession_windows(); +int profession_windows_1(); +int profession_windows_2(); +char ProfessionShopTitle[27]; +char ProfessionShopMsg[2][45]; +#endif + +#ifdef _NPC_WELFARE_2 // WON ADD 职业NPC-2 +void initServerWindowProfession2( char *data ); +void profession_windows2(); +int profession_windows_12(); +int profession_windows_22(); +char ProfessionShopTitle2[27]; +char ProfessionShopMsg2[2][45]; +#endif + +#ifdef _PETSKILL_CANNEDFOOD +void initPetSkillWindowType1(char *date); +void PetSkillShowType1(void); +#endif + +void initFamilyAddWN(char *); +void familyAddWN(void); +void initFamilyList(char *); +void familyListWN(void); +void initFamilyDetail(char *); +int familyDetailWN(void); +void initMineFamilyDetail(char *); +void mineFamilyDetailWN(void); + +void initItemman(char *); +int itemmanWN(void); + +void initFamilyTaxWN(char *); +void familyTaxWN(void); + +void initFamilyLeaderChange(char *); +void familyLeaderChangeWN(void); +void familyLeaderChangeQWN(void); +void familyLeaderChangeAWN(void); +void initFamilyLeaderChangeA(char *); + +#ifdef _BLACK_MARKET +void initBlackMarket(char *); +void BMWindowType(void); +#endif + +#ifdef _ADD_FAMILY_TAX // WON ADD 增加庄园税收 +void FMTAXWindowsType( void ); +#endif + +// Shan Add +void initFMWindowType(char *); +void FMWindowType(void); +void initFMWindowType1(char *); +void FMWindowType1(void); +void initFMWindowType2(char *); +void FMWindowType2(void); +void initFMWindowType3(char *); +#ifdef _NEW_MANOR_LAW +void FMWindowType3(int king); +#else +void FMWindowType3( void ); +#endif +#ifdef _FMVER21 +void initFMWindowType4(char *, int king); +#ifdef _NEW_MANOR_LAW +void FMWindowType4(int king); +#else +void FMWindowType4( void ); +#endif +#endif +// Robin Family PK +void initFMPKListWN(char *); +void FMPKListWN(int mode); +void initFMPKSelectWN(char *); +void FMPKSelectWN(int mode); +void initFMPKDetailWN(char *); +void FMPKDetailWN(int mode); + +void initShowRidePetWN(void); +void showRidePetWN(void); + + +#ifdef _NPC_SELLSTH +void InitSellSth_Menu( char* data ); +void InitSellSth_View( char* data ); + +void InitSellSth_Sell( char* data ); +//void SellSth_Menu( void ); +void SellSth_Sell( void ); +#endif + +#ifdef _MOUSE_DBL_CLICK +void initMouseGetNameWN( char* data); +void showMouseGetNameWN( void); +#endif + +#ifdef _CONTRACT +void initContractWN( char* data); +void showContractWN(); +#endif + +#ifdef _RACEMAN +void initRacemanRankWN( char* data); +void showRacemanRankWN( void ); +#endif + +#ifdef _DRAGON_FUSION +void serverWindowDragonFusion( void ); +#endif + +#ifdef _NPC_DAYACTION +void initDayactionRankWN( char* data); +void showDayactionRankWN( void ); +#endif + +// ??? +void initOpenServerWindow(void) +{ + windowTypeWN = -1; + ptActMenuWin = NULL; +} + +// Robin 0720 Login Announce +int LoginAnnounce = 0; +char AnnounceBuf[8192]; +#ifdef _WIN_LUAJIT_ +lua_State *WinLua = NULL; +int cloasewindows = 0; +SA_WINDOWS windows; +#endif +void openServerWindow(int windowtype, int buttontype, int index, int id, char *data) +{ +#ifdef _ANGEL_SUMMON + if( windowtype == WINDOW_MESSAGETYPE_ANGELMESSAGE ) { + if( index == 520 /*CHAR_WINDOWTYPE_ANGEL_ASK*/ ) { + angelFlag = TRUE; + angelRecvType = index; + angelRecvButton = buttontype; + strcpy( angelMsg, data); + return; + } + else if( index = 521 /*CHAR_WINDOWTYPE_ANGEL_CLEAN*/) { + angelFlag = FALSE; + strcpy( angelMsg, ""); + return; + } + } +#endif + + if (windowTypeWN < 0 || windowtype == 33 || windowtype == 0 || windowtype == 36 + || windowtype == 39 || windowtype == 42){ + + if (windowtype == 0 && windowTypeWN == 13){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } +#ifdef _BLACK_MARKET + if (windowtype == 0 && windowTypeWN == WINDOW_MESSAGETYPE_BLACKMARKET){ + closeBlackMarketWN(); + } +#endif + wnOpenX = nowGx; + wnOpenY = nowGy; + wnCloseFlag = 0; + + windowTypeWN = windowtype; + buttonTypeWN = buttontype; + indexWN = index; + idWN = id; + + buyOffFlag = 0; + + // ????? + if (windowTypeWN == WINDOW_MESSAGETYPE_MESSAGE + || windowTypeWN == WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT +#ifdef _NEW_MANOR_LAW + || windowTypeWN == WINDOW_FMMESSAGETYPE_MANOR_SCHEDULE // 挑战庄园排行 +#endif + ) + { + initServerWindowType0(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_SELECT) + { + //  + initServerWindowType1(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMENU) + { + // ?????????? + initServerWindowType2(data); + } + else if (windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMAIN){ + initServerWindowType3(data); + } + else + // ??????? + if (windowTypeWN == WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN) + { + // ?????????? + initServerWindowType3(data); + buyOffFlag = 1; + } + else + // ????????????? + if (windowTypeWN == WINDOW_MESSAGETYPE_PETSKILLSHOP) + { + initServerWindowType5(data); + } + else +#ifdef _CHAR_PROFESSION // WON ADD 人物职业技能 + if( windowTypeWN == WINDOW_MESSAGETYPE_PROFESSIONSHOP ) + { + initServerWindowProfession( data ); + }else +#endif +#ifdef _NPC_WELFARE_2 // WON ADD 职业NPC-2 + if( windowTypeWN == WINDOW_MESSAGETYPE_PROFESSIONSHOP2 ) + { + initServerWindowProfession2( data ); + }else +#endif +#ifdef _PETSKILL_CANNEDFOOD + if (windowTypeWN == WINDOWS_MESSAGETYPE_PETSKILLSHOW){ + initPetSkillWindowType1(data); + } + else +#endif + // ?????????? + if (windowTypeWN == WINDOW_MESSAGETYPE_WIDEMESSAGE + || windowTypeWN == WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT) + { + // ??? + // ??????? + // ????????? + initServerWindowType4(data); + } + else + // ???????????????? + if (windowTypeWN == WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN){ + initServerWindowType6(data); + } + else + // ???????????????????? + if (windowTypeWN == WINDOW_MESSAGETYPE_POOLITEMSHOPMENU) + { + initServerWindowType7(data); + } + else + // Robin 0518 Family + if (windowTypeWN == WINDOW_MESSAGETYPE_FAMILYADD) + { + initFamilyAddWN(data); + } + +#ifdef _BLACK_MARKET + else + if (windowTypeWN == WINDOW_MESSAGETYPE_BLACKMARKET) + { + initBlackMarket(data); + } +#endif +#ifdef _ADD_FAMILY_TAX // WON ADD 增加庄园税收 + else + if( windowTypeWN == WINDOWS_MESSAGETYPE_FAMILY_TAX ) + { + initServerWindowType0( data ); + } +#endif + else + if (windowTypeWN == WINDOW_MESSAGETYPE_FAMILYJOIN) + { + initFamilyList(data); + } + + if (windowTypeWN == WINDOW_MESSAGETYPE_FAMILYDETAIL) + { + initMineFamilyDetail(data); + } + + // Shan Family Dengon + // Member List + else + if (windowTypeWN == WINDOW_FMMESSAGETYPE_SELECT) + { + initFMWindowType(data); + } +#ifdef _FMVER21 + // TOP 30 DP List + else + if (windowTypeWN == WINDOW_FMMESSAGETYPE_TOP30DP) + { + initFMWindowType4(data, 0); + } +#endif +#ifdef _NEW_MANOR_LAW + else if (windowTypeWN == WINDOW_FMMESSAGETYPE_FM_MEMONTUM) initFMWindowType4(data, 1); +#endif + // Dp List + else +#ifdef _NEW_MANOR_LAW + if (windowTypeWN == WINDOW_FMMESSAGETYPE_DP || windowTypeWN == WINDOW_FMMESSAGETYPE_10_MEMONTUM) +#else + if( windowTypeWN == WINDOW_FMMESSAGETYPE_DP ) +#endif + { + initFMWindowType3(data); + } + // Point List + else + if (windowTypeWN == WINDOW_FMMESSAGETYPE_POINTLIST) + { + initFMWindowType2(data); + } + // Family Memo + else + if (windowTypeWN == WINDOW_FMMESSAGETYPE_DENGON) + { + initFMWindowType1(data); + } + // Familys Memo + else + if (windowTypeWN == WINDOW_FMMESSAGETYPE_FMSDENGON) + { + initFMWindowType1(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_PKSCHEDULELIST) + { + initFMPKListWN(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY) + { + initFMPKSelectWN(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL) + { + initFMPKDetailWN(data); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_SHOWRIDEPET) + { + initShowRidePetWN(); + } + else + if (windowTypeWN == WINDOW_MESSAGETYPE_LOGINMESSAGE) + { + windowTypeWN = -1; + LoginAnnounce = 1; + strcpy(AnnounceBuf, data); + //windowTypeWN = WINDOW_MESSAGETYPE_MESSAGE; + //initServerWindowType0( data ); + } + else if (windowTypeWN == WINDOW_MESSAGETYPE_LEADERSELECT){ + initFamilyLeaderChange(data); + } + else if (windowTypeWN == WINDOW_MESSAGETYPE_LEADERSELECTA){ + initFamilyLeaderChangeA(data); + } +#ifdef _NPC_SELLSTH + if( windowTypeWN == WINDOWS_MESSAGETYPE_SELLSTHMENU ){ + InitSellSth_Menu( data); + }else if( windowTypeWN == WINDOWS_MESSAGETYPE_SELLSTHVIEW ){ + InitSellSth_View( data); + }else if( windowTypeWN == WINDOWS_MESSAGETYPE_SELLSTHSELL ){ + InitSellSth_Sell( data); + } +#endif + + // Terry add 2001/12/06 + // 伊甸大陆--个人银行 +#ifdef __EDEN_EFFECT + else if (windowTypeWN == WINDOW_MESSAGETYPE_BANK) + { + // 设定玩家身上的银行存款 + pc.personal_bankgold = atoi(data); + if (pc.personal_bankgold < 0) pc.personal_bankgold = 0; + else if (pc.personal_bankgold > MAX_PERSONAL_BANKGOLD) pc.personal_bankgold = MAX_PERSONAL_BANKGOLD; + } +#endif + // Terry end + // Terry add 2002/01/03 +#ifdef __EDEN_AUCTION + else if (windowTypeWN >= WINDOW_MESSAGETYPE_AUCTIONNEW && + windowTypeWN <= WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY) + { + switch (windowTypeWN) + { + // 开启委托视窗 + case WINDOW_MESSAGETYPE_AUCTIONNEW: + break; + // 开启委托列表视窗 + case WINDOW_MESSAGETYPE_AUCTIONLIST_BUY: + case WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY: + szpALD = data; + //szpALD = TESTDATA; + bNewData = TRUE; + break; + // 开启委托详细内容视窗 + case WINDOW_MESSAGETYPE_AUCTIONSURVEY: + // 开启修改委托内容视窗 + case WINDOW_MESSAGETYPE_AUCTIONMODIFY: + szpALD = data; + break; + } + } +#endif + // Terry end + +#ifdef _MOUSE_DBL_CLICK + else + if( windowTypeWN == WINDOW_MESSAGETYPE_MOUSEGETNAME ) + { + initMouseGetNameWN( data); + } +#endif + +#ifdef _CONTRACT + else + if( windowTypeWN == WINDOW_MESSAGETYPE_CONTRACT ) + { + initContractWN( data); + } +#endif + +#ifdef _RACEMAN + else + if( windowTypeWN == WINDOW_MESSAGETYPE_RACEMAN_RANK ) + { + initRacemanRankWN( data ); + } +#endif + +#ifdef _NPC_DAYACTION + else + if( windowTypeWN == WINDOW_MESSAGETYPE_DAYACTION_FMRANK ) + { + initDayactionRankWN( data ); + } +#endif + + if (CheckMenuFlag()) + { + InitMenu2(); + } + + closeEtcSwitch(); + closeCharActionAnimeChange(); + closeJoinChannelWN(); + } + +#ifdef _NEWSHOP_ + if (windowtype == 1001){ + cloasewindows = 0; + extern void 在线商城窗口初始化(char * 内容); + extern ACTION* 创建商城窗口(); + 在线商城窗口初始化(data); + 商城动作地址 = 创建商城窗口(); + return; + } +#endif +#ifdef _CHARSIGNDAY_ + if(windowtype==1002){ + cloasewindows=0; + extern void 签到窗口初始化(char * 内容); + extern ACTION* 创建签到窗口(); + 签到窗口初始化(data); + 创建签到窗口(); + return; + } +#endif +#ifdef _ICONBUTTONS_ + if(windowtype==1003){ + cloasewindows=0; + extern void 转盘窗口初始化(char * 内容); + extern ACTION* 创建转盘窗口(); + 转盘窗口初始化(data); + 创建转盘窗口(); + return; + } +#endif +#ifdef _MAGIC_ITEM_ + if(windowtype==1004){ + cloasewindows=0; + + InitMagicItemWin(data); + CreateMagicItemWin(); + return; + } +#endif + +#ifdef _WIN_LUAJIT_ + if (windowtype >= 1000){ + cloasewindows = 0; + WinLua = FindWinIntLua(windowtype, data); + } + else{ + if (windows.ptActMenuWin != NULL) + { + cloasewindows = 1; + } + } +#endif +} + + +// ???????????? +// ????????? +void openServerWindowProc(void) +{ +#if 0 + // + if( joy_trg[ 1 ] & JOY_F6 ) + { +#if 1 + openServerWindow( 9, 0x3c, 0, 0, + "1|萨姆吉尔的武器店|欢迎光临。现在推出很棒的技能喔|" + "背水一战之 |500|攻击力上升30% 防御力下降30%|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + "地球一周|1000|也许还有什么新的发现(适当)|" + ); +#endif +#if 0 + openServerWindow( 1, 0x3c, 0, 0, + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" + "BBBBBBBBBBBBBBBB\n" + "CCCC\n" + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n" + "EE\n" + "FFFFF\n" + "GGGGGGGGGGGG\n" + "H\n" + "IIIIIIIIIIIIIIIIIIIIIIIII\n" + "JJJJJJJJJJJ\n" + "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n" + "LLLLLLLLLLLLLLL\n" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" + "BBBBBBBBBBBBBBBB\n" + "CCCC\n" + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n" + "EE\n" + "FFFFF\n" + "GGGGGGGGGGGG\n" + "H\n" + "IIIIIIIIIIIIIIIIIIIIIIIII\n" + "JJJJJJJJJJJ\n" + "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n" + "LLLLLLLLLLLLLLL\n" ); +#endif +#if 0 + openServerWindow( 7, 0x3c, 0, 0, + "1|1|0|????????|?????????????|??????????????????|" + "?????????????????|????????|" + "??|0|30|24000|???????|" + "??|0|100|24001|???????|" + "????|0|200|24001|?????????|" + "?????|0|300|24001|???????|" + "????|0|50|24001|?????????|" + "??????|0|100|24001|???????????|" + "??|0|100|24001|???????|" + "??|0|100|24001|???????|" + "??|0|100|24001|???????|" + "??????|0|100|24001|??????????????????????\n???????????" ); +#endif +#if 0 + openServerWindow( 7, 0x3c, 0, 0, + "0|1|0|????????|?????????????|???????????|" + "?个???|?????????????????\n??????|???????|" + "?????????????|" + "??|0|1|30|24000|???????|" + "??|0|3|100|24001|???????|" + "????|0|5|200|24001|?????????|" + "?????|0|10|300|24001|???????|" + "????|0|1|10|24001|?????????|" + "??????|0|2|100|24001|???????????|" + "??|0|3|100|24001|???????|" + "??|0|4|100|24001|???????|" + "??|0|1|100|24001|???????|" + "??????|1|100|9999999|24001|??????????????????????\n???????????" ); +#endif + } +#endif + + // Robin 0720 Login Announce + if (LoginAnnounce) + { + LoginAnnounce = 0; + lssproto_WN_recv(sockfd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK + , -1, -1, AnnounceBuf); + } + + // ???????????????? + if (windowTypeWN < 0) + return; + + // ???????????????????????????? + if (ABS(wnOpenX - nowGx) >= 2 + || ABS(wnOpenY - nowGy) >= 2) + { + wnCloseFlag = 1; // ????????? + } + switch (windowTypeWN) + { + // ??????? + case WINDOW_MESSAGETYPE_MESSAGE: + case WINDOW_MESSAGETYPE_WIDEMESSAGE: + serverWindowType0(0); + break; + + // ????????? + case WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT: + case WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT: + serverWindowType0(1); + break; +#ifdef _NEW_MANOR_LAW + case WINDOW_FMMESSAGETYPE_MANOR_SCHEDULE: // 挑战庄园排行 + serverWindowType0(2); + break; +#endif + //  + case WINDOW_MESSAGETYPE_SELECT: + serverWindowType1(); + break; + + // ??? + case WINDOW_MESSAGETYPE_PETSELECT: + serverWindowType2(); + break; +#ifdef _NPC_FUSION + case WINDOWS_MESSAGETYPE_PETFUSION://andy_add 宠物融合 + serverWindowType9(); + break; +#endif + // ?? + case WINDOW_MESSAGETYPE_PARTYSELECT: + serverWindowType3(); + break; + + // ?????? + case WINDOW_MESSAGETYPE_PETANDPARTYSELECT: + serverWindowType4(); + break; + + // ?????????? + case WINDOW_MESSAGETYPE_ITEMSHOPMENU: + case WINDOW_MESSAGETYPE_ITEMSHOPMAIN: + case WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN: + serverWindowType5(); + break; + + // ?????????? + case WINDOW_MESSAGETYPE_PETSKILLSHOP: + serverWindowType6(); + break; + +#ifdef _CHAR_PROFESSION // WON ADD 人物职业技能 + case WINDOW_MESSAGETYPE_PROFESSIONSHOP: + profession_windows(); + break; +#endif +#ifdef _NPC_WELFARE_2 // WON ADD 职业NPC-2 + case WINDOW_MESSAGETYPE_PROFESSIONSHOP2: + profession_windows2(); + break; +#endif + +#ifdef _PETSKILL_CANNEDFOOD + case WINDOWS_MESSAGETYPE_PETSKILLSHOW: + PetSkillShowType1(); + break; + +#endif + // ???????????????? + case WINDOW_MESSAGETYPE_POOLITEMSHOPMENU: + case WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN: + serverWindowType7(); + break; + + // Robin 0517 family: + case WINDOW_MESSAGETYPE_FAMILYADD: + familyAddWN(); + break; + + case WINDOW_MESSAGETYPE_FAMILYJOIN: + familyListWN(); + break; +#ifdef _NPC_SELLSTH + case WINDOWS_MESSAGETYPE_SELLSTHMENU: + // SellSth_Menu(); + case WINDOWS_MESSAGETYPE_SELLSTHVIEW: + case WINDOWS_MESSAGETYPE_SELLSTHSELL: + SellSth_Sell(); + break; +#endif + case WINDOW_MESSAGETYPE_FAMILYDETAIL: + mineFamilyDetailWN(); + break; + + /* + case WINDOW_MESSAGETYPE_ITEMMAN: + itemmanWN(); + break; + */ +#ifdef _ADD_FAMILY_TAX // WON ADD 增加庄园税收 + case WINDOWS_MESSAGETYPE_FAMILY_TAX: + FMTAXWindowsType(); + break; +#endif +#ifdef _BLACK_MARKET + case WINDOW_MESSAGETYPE_BLACKMARKET: + BMWindowType(); + break; +#endif + // Shan family memberlist + case WINDOW_FMMESSAGETYPE_SELECT: + FMWindowType(); + break; +#ifdef _FMVER21 + // Shan family dplist top30 +#ifdef _NEW_MANOR_LAW + case WINDOW_FMMESSAGETYPE_FM_MEMONTUM: + FMWindowType4(1); + break; + case WINDOW_FMMESSAGETYPE_TOP30DP: + FMWindowType4(0); + break; +#else + case WINDOW_FMMESSAGETYPE_TOP30DP: + FMWindowType4(); + break; +#endif +#endif + // Shan family dplist +#ifdef _NEW_MANOR_LAW + case WINDOW_FMMESSAGETYPE_10_MEMONTUM: + FMWindowType3(1); + break; + case WINDOW_FMMESSAGETYPE_DP: + FMWindowType3(0); + break; +#else + case WINDOW_FMMESSAGETYPE_DP: + FMWindowType3(); + break; +#endif + // Shan family pointlist + case WINDOW_FMMESSAGETYPE_POINTLIST: + FMWindowType2(); + break; + // Shan family dengon + case WINDOW_FMMESSAGETYPE_DENGON: + case WINDOW_FMMESSAGETYPE_FMSDENGON: + FMWindowType1(); + break; + + // Robin FM_PK + case WINDOW_MESSAGETYPE_PKSCHEDULELIST: + FMPKListWN(0); + break; + case WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY: + FMPKSelectWN(0); + break; + case WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL: + FMPKDetailWN(0); + break; + + case WINDOW_MESSAGETYPE_FAMILYTAX: + familyTaxWN(); + break; + + case WINDOW_MESSAGETYPE_SHOWRIDEPET: + showRidePetWN(); + break; + + case WINDOW_MESSAGETYPE_LEADERSELECT: + familyLeaderChangeWN(); + break; + + case WINDOW_MESSAGETYPE_LEADERSELECTQ: + familyLeaderChangeQWN(); + break; + + case WINDOW_MESSAGETYPE_LEADERSELECTA: + familyLeaderChangeAWN(); + break; + // Terry 2001/12/07 +#ifdef __EDEN_EFFECT + case WINDOW_MESSAGETYPE_BANK: + BankProc(); + break; +#endif + // Terry end + + // Terry add 2002/01/03 +#ifdef __EDEN_AUCTION + // WT-->(W)indow(T)ype + // 开启委托视窗 + case WINDOW_MESSAGETYPE_AUCTIONNEW: AuctionNewWT(); break; + // 开启委托列表视窗 + case WINDOW_MESSAGETYPE_AUCTIONLIST_BUY: + case WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY: AuctionListWT(); break; + // 开启委托详细内容视窗 + case WINDOW_MESSAGETYPE_AUCTIONSURVEY: + // 开启修改委托内容视窗 + case WINDOW_MESSAGETYPE_AUCTIONMODIFY: AuctionSurveyModifyWT(); break; + break; +#endif + // Terry end + +#ifdef _MOUSE_DBL_CLICK + case WINDOW_MESSAGETYPE_MOUSEGETNAME: + showMouseGetNameWN(); + break; +#endif + +#ifdef _CONTRACT + case WINDOW_MESSAGETYPE_CONTRACT: + showContractWN(); + break; +#endif + +#ifdef _RACEMAN + case WINDOW_MESSAGETYPE_RACEMAN_RANK: + showRacemanRankWN(); + break; +#endif + +#ifdef _DRAGON_FUSION // 人龙进化 + case WINDOWS_MESSAGETYPE_DRAGONFUSION: + serverWindowDragonFusion(); + break; +#endif + +#ifdef _NPC_DAYACTION + case WINDOW_MESSAGETYPE_DAYACTION_FMRANK: + showDayactionRankWN(); + break; +#endif +#ifdef _NEWSHOP_ + case 1001: + extern ACTION* 商城数据显示(); + extern ACTION* 创建商城窗口(); + if (商城动作地址 == NULL){ + 商城动作地址 = 创建商城窗口(); + } + if (商城动作地址){ + if (商城动作地址->hp >= 1){ + 商城动作地址 = 商城数据显示(); + } + } + break; +#endif +#ifdef _ICONBUTTONS_ + case 1003: + extern ACTION* 转盘数据显示(); + extern ACTION* 创建转盘窗口(); + if(转盘动作地址==NULL){ + 转盘动作地址 = 创建转盘窗口(); + } + if(转盘动作地址){ + if(转盘动作地址->hp >=1){ + 转盘数据显示(); + } + } + break; +#endif +#ifdef _MAGIC_ITEM_ + case 1004: + + // MagicItemActAddr = CreateMagicItemWin(); + if(MagicItemActAddr==NULL){ + MagicItemActAddr = CreateMagicItemWin(); + } + if(MagicItemActAddr){ + if(MagicItemActAddr->hp >=1){ + ShowMagicItemData(); + } + } + break; +#endif +#ifdef _CHARSIGNDAY_ + case 1002: + extern ACTION* 签到数据显示(); + extern ACTION* 创建签到窗口(); + if(签到动作地址==NULL){ + 签到动作地址 = 创建签到窗口(); + } + if(签到动作地址){ + if(签到动作地址->hp >=1){ + 签到数据显示(); + } + } + break; +#endif + } +#ifdef _WIN_LUAJIT_ + if (windowTypeWN > 1004){ + if (windows.ptActMenuWin == NULL) + { + windows.ptActMenuWin = FreeCreateWinTypeLua(WinLua); + if (windows.ptActMenuWin == NULL) + { + InitMenu(); + initFieldProc(); + } + } + if (windows.ptActMenuWin != NULL && windows.ptActMenuWin->hp >= 1) + { + windows.ptActMenuWin = FreeServerWinTypeLua(WinLua); + } + } +#endif +} + +void getStrSplit(char *dist, char *src, int distSize, int line, int strLen) +{ + int i, j; + int flag; + char msg[256]; + char *ptMsg; + char *dis; + + dis = dist; + if (distSize - 1 < strLen) + { + strLen = distSize - 1; + } + + for (i = 0, j = 0; i < line && j < line; i++, j++, dis += distSize) + { + // 1??? + flag = getStringToken(src, '\n', i + 1, sizeof(msg)-1, msg); + + ptMsg = msg; + while (1) + { + // ???strLen?????? + if (strlen(ptMsg) >(unsigned int)strLen) + { + strncpy_s(dis, strLen + 1, ptMsg, strLen); + if (GetStrLastByte(dis) != 3) + { + dis[strLen] = '\0'; + ptMsg += strLen; + } + else + { + dis[strLen - 1] = '\0'; + ptMsg += (strLen - 1); + } + j++; + dis += distSize; + if (j >= line) + break; + } + else + // ????????????? + { + strcpy(dis, ptMsg); + break; + } + } + + if (flag == 1) + { + j++; + dis += distSize; + break; + } + } + // ????????NULL???? + for (; j < line; j++, dis += distSize) + dis[0] = '\0'; +} + + +// ???????? +// ???????????????? +void initServerWindowType0(char *data) +{ + msgWN_W = 7; + msgWN_H = 5; + msgWNLen = 40; + + makeStringFromEscaped(data); +#ifdef _FONT_STYLE_ + int flg = FALSE; + char *temp = sunday(data, "[style "); + if (temp){ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 256); + } + else{ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), msgWNLen); + } + getStrSplitNew(msgWN); +#else + getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + sizeof( msgWN )/sizeof( msgWN[0] ), msgWNLen ); +#endif +} + + +// ???????????? +// ???????????????? +void initServerWindowType1(char *data) +{ + makeStringFromEscaped(data); + if ('0' <= *data && *data <= '7') + { + selStartLine = getIntegerToken(data, '\n', 1); + data += 2; + } + else + { + selStartLine = 1; + } +#ifdef _FONT_STYLE_ + int flg = FALSE; + char *temp = sunday(data, "[style "); + if (temp){ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 256); + } + else{ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 40); + } + getStrSplitNew(msgWN); +#else + getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + sizeof( msgWN )/sizeof( msgWN[0] ), 40 ); +#endif + + + +} + + + +// ??????? + +short shopWindowProcNo; + +// ????????????? +void initServerWindowType2(char *data) +{ + char msg[256]; + + shopWindowProcNo = 0; + + getStringToken(data, '|', 1, sizeof(msg)-1, msg); + makeStringFromEscaped(msg); + strncpy_s(shopWindow1Title, msg, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + + getStringToken(data, '|', 2, sizeof(msg)-1, msg); + makeStringFromEscaped(msg); + strncpy_s(shopWindow1Msg, msg, sizeof(shopWindow1Msg)-1); + shopWindow1Msg[sizeof(shopWindow1Msg)-1] = '\0'; +#ifdef _NEW_MANOR_LAW + getStringToken(data, '|', 3, sizeof(msg)-1, msg); + pc.fame = atoi(msg); +#endif + + menuIndexWN = indexWN; +} + +void initServerWindowType3(char *data) +{ + char title1[128]; + char msg1[128]; + char msg2[256]; + char msg3[128]; + char msg4[128]; + char msg5[128]; + char msg6[128]; + char itemName[64]; + char info[256]; + int i, j; + int flag; + int datalen; +#ifdef _NEW_MANOR_LAW + int offset = 7; +#else + int offset = 6; +#endif + + datalen = 6; + + shopWindowMode = getIntegerToken(data, '|', 1); + if (shopWindowMode == 0){ + shopWindowProcNo = 10; + shopWondow2Page = 0; +#ifdef _NEW_SHOP_FRAME + getStringToken( data, '|', 2, sizeof( shopWindowCurrency )-1, shopWindowCurrency ); +#else + if (getIntegerToken(data, '|', 2) == 0) + return; +#endif + menuIndexWN = getIntegerToken(data, '|', 3); + + getStringToken(data, '|', 4, sizeof(title1)-1, title1); + makeStringFromEscaped(title1); + getStringToken(data, '|', 5, sizeof(msg1)-1, msg1); + makeStringFromEscaped(msg1); + getStringToken(data, '|', 6, sizeof(msg2)-1, msg2); + makeStringFromEscaped(msg2); + getStringToken(data, '|', 7, sizeof(msg3)-1, msg3); + makeStringFromEscaped(msg3); + getStringToken(data, '|', 8, sizeof(msg4)-1, msg4); + makeStringFromEscaped(msg4); + getStringToken(data, '|', 9, sizeof(msg5)-1, msg5); + makeStringFromEscaped(msg5); + getStringToken(data, '|', 10, sizeof(msg6)-1, msg6); + makeStringFromEscaped(msg6); + + strncpy_s(shopWindow1Title, title1, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + strncpy_s(shopWindow1Msg, msg1, sizeof(shopWindow1Msg)-1); + shopWindow1Msg[sizeof(shopWindow1Msg)-1] = '\0'; + + getStrSplit((char *)shopWindow2Msg, msg2, + sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg[0]) - 1); + + strncpy_s(shopWindow3Msg, msg3, sizeof(shopWindow3Msg)-1); + shopWindow3Msg[sizeof(shopWindow3Msg)-1] = '\0'; + + getStrSplit((char *)shopWindow4Msg, msg4, + sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg[0]) - 1); + + getStrSplit((char *)shopWindow5Msg, msg5, + sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg[0]) - 1); + + getStrSplit((char *)shopWindow6Msg, msg6, + sizeof(shopWindow6Msg[0]), + sizeof(shopWindow6Msg) / sizeof(shopWindow6Msg[0]), + sizeof(shopWindow6Msg[0]) - 1); + + + shopWondow2MaxPage = MAX_SHOP_ITEM*MAX_SHOP_PAGE; + for (i = 0, j = 0; i < shopWondow2MaxPage; i++){ + flag = getStringToken(data, '|', 11 + i*offset, sizeof(itemName)-1, itemName); + makeStringFromEscaped(itemName); + if (flag){ + sealItem[i].name[0] = '\0'; + continue; + } + + j++; + if (strlen(itemName) <= ITEM_NAME_LEN){ + strcpy(sealItem[i].name, itemName); + } + else{ + strcpy(sealItem[i].name, "???"); + } + sealItem[i].sealFlag = getIntegerToken(data, '|', 12 + i*offset); + sealItem[i].level = getIntegerToken(data, '|', 13 + i*offset); + sealItem[i].price = getIntegerToken(data, '|', 14 + i*offset); + sealItem[i].graNo = getIntegerToken(data, '|', 15 + i*offset); + getStringToken(data, '|', 16 + i*offset, sizeof(info)-1, info); + makeStringFromEscaped(info); + getStrSplit((char *)(&sealItem[i].info), info, + sizeof(sealItem[0].info[0]), + sizeof(sealItem[0].info) / sizeof(sealItem[0].info[0]), + sizeof(sealItem[0].info[0]) - 1); +#ifdef _NEW_MANOR_LAW + sealItem[i].costfame = getIntegerToken(data, '|', 17 + i*offset); +#endif + } + if (j > 0){ + shopWondow2MaxPage = (j + 7) / MAX_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + } + else{ +#ifdef _ITEM_PILENUMS + datalen = 7; +#endif + + shopWindowProcNo = 100; + shopWondow2Page = 0; + if (getIntegerToken(data, '|', 2) == 0) + return; + menuIndexWN = getIntegerToken(data, '|', 3); + getStringToken(data, '|', 4, sizeof(title1)-1, title1); + makeStringFromEscaped(title1); + getStringToken(data, '|', 5, sizeof(msg1)-1, msg1); + makeStringFromEscaped(msg1); + getStringToken(data, '|', 6, sizeof(msg2)-1, msg2); + makeStringFromEscaped(msg2); + getStringToken(data, '|', 7, sizeof(msg3)-1, msg3); + makeStringFromEscaped(msg3); + getStringToken(data, '|', 8, sizeof(msg4)-1, msg4); + makeStringFromEscaped(msg4); + + strncpy_s(shopWindow1Title, title1, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + + strncpy_s(shopWindow1Msg, msg1, sizeof(shopWindow1Msg)-1); + shopWindow1Msg[sizeof(shopWindow1Msg)-1] = '\0'; + + getStrSplit((char *)shopWindow7Msg, msg2, + sizeof(shopWindow7Msg[0]), + sizeof(shopWindow7Msg) / sizeof(shopWindow7Msg[0]), + sizeof(shopWindow7Msg[0]) - 1); + + getStrSplit((char *)shopWindow8Msg, msg3, + sizeof(shopWindow8Msg[0]), + sizeof(shopWindow8Msg) / sizeof(shopWindow8Msg[0]), + sizeof(shopWindow8Msg[0]) - 1); + + getStrSplit((char *)shopWindow5Msg, msg4, + sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg[0]) - 1); + + + shopWondow2MaxPage = MAX_SHOP_ITEM*MAX_SHOP_PAGE; + for (i = 0, j = 0; i < shopWondow2MaxPage; i++){ + flag = getStringToken(data, '|', 9 + i*datalen, sizeof(itemName)-1, itemName); + makeStringFromEscaped(itemName); + if (flag){ + userItem[i].name[0] = '\0'; + continue; + } + + j++; + if (strlen(itemName) <= ITEM_NAME_LEN){ + strcpy(userItem[i].name, itemName); + } + else{ + strcpy(userItem[i].name, "???"); + } + userItem[i].sealFlag = getIntegerToken(data, '|', 10 + i*datalen); + userItem[i].price = getIntegerToken(data, '|', 11 + i*datalen); + userItem[i].graNo = getIntegerToken(data, '|', 12 + i*datalen); + getStringToken(data, '|', 13 + i*datalen, sizeof(info)-1, info); + makeStringFromEscaped(info); + getStrSplit((char *)(&userItem[i].info), info, + sizeof(userItem[i].info[0]), + sizeof(userItem[i].info) / sizeof(userItem[i].info[0]), + sizeof(userItem[i].info[0]) - 1); + userItem[i].tbl = getIntegerToken(data, '|', 14 + i*datalen); +#ifdef _ITEM_PILENUMS + userItem[i].num = getIntegerToken(data, '|', 15 + i*datalen); +#endif + } + if (j > 0){ + shopWondow2MaxPage = (j + 7) / MAX_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + } +} + + +// ???????? +// ???????????????? +void initServerWindowType4(char *data) +{ + msgWN_W = 9; + msgWN_H = 9; + msgWNLen = (msgWN_W * 64 - 48) / 9; + + makeStringFromEscaped(data); +#ifdef _FONT_STYLE_ + int flg = FALSE; + char *temp = sunday(data, "[style "); + if (temp){ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 256); + } + else{ + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), msgWNLen); + } + getStrSplitNew(msgWN); +#else + getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + sizeof( msgWN )/sizeof( msgWN[0] ), msgWNLen ); +#endif + + + + + +} + +#ifdef _PETSKILL_CANNEDFOOD +short PetskillShpwWindowProcNo; +void initPetSkillWindowType1(char *data) +{ + selShopSkillPetNo = atoi(data); + PetskillShpwWindowProcNo = 0; +} +#endif + +void initServerWindowType5(char *data) +{ + char title1[128], msg2[128], skillName[64], info[256]; + int i, j, flag; + int iReadOffset = 3; +#ifdef _PETKILL_COST_FAME + iReadOffset = 4; +#endif + + skillShopWindowProcNo = 0; + shopWondow2Page = 0; + + // ????????????????????? + if (getIntegerToken(data, '|', 1) == 0) + return; + + getStringToken(data, '|', 2, sizeof(title1)-1, title1); + makeStringFromEscaped(title1); + getStringToken(data, '|', 3, sizeof(msg2)-1, msg2); + makeStringFromEscaped(msg2); + strncpy_s(shopWindow1Title, title1, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + + getStrSplit((char*)shopWindow2Msg, msg2, + sizeof(shopWindow2Msg[0]), sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg[0]) - 1); + + shopWondow2MaxPage = MAX_SKILL_SHOP_SKILL*MAX_SKILL_SHOP_PAGE; + for (i = 0, j = 0; i < shopWondow2MaxPage; i++) + { + // ??? + flag = getStringToken(data, '|', 4 + i * iReadOffset, sizeof(skillName)-1, skillName); + makeStringFromEscaped(skillName); + if (flag) + { + sealSkill[i].name[0] = '\0'; + continue; + } + + j++; + if (strlen(skillName) <= SKILL_NAME_LEN) + strcpy(sealSkill[i].name, skillName); + else + strcpy(sealSkill[i].name, "???"); + + //  + sealSkill[i].price = getIntegerToken(data, '|', 5 + i * iReadOffset); + + // ????????? + getStringToken(data, '|', 6 + i * iReadOffset, sizeof(info)-1, info); + makeStringFromEscaped(info); + getStrSplit((char*)(&sealSkill[i].info), info, + sizeof(sealSkill[0].info[0]), + sizeof(sealSkill[0].info) / sizeof(sealSkill[0].info[0]), + sizeof(sealSkill[0].info[0]) - 1); +#ifdef _PETKILL_COST_FAME + sealSkill[i].iCoseFame = getIntegerToken(data, '|', 7 + i * iReadOffset); +#endif + } + if (j > 0) + shopWondow2MaxPage = (j + 7) / MAX_SKILL_SHOP_SKILL; + else + shopWondow2MaxPage = 1; +} + + +// ???????????????????? +void initServerWindowType6(char *data) +{ + char title1[128]; + char msg1[128]; + char msg2[256]; + char msg3[128]; + char itemName[64]; + char info[256]; + int i, j; + int flag; + +#ifdef _ITEM_PILENUMS + int datalen = 7; +#else + int datalen = 6; +#endif + + shopWindowMode = getIntegerToken(data, '|', 1); + if (shopWindowMode == 0){ + shopWindowProcNo = 10; + shopWondow2Page = 0; + restPoolSlot = getIntegerToken(data, '|', 2); + getStringToken(data, '|', 3, sizeof(title1)-1, title1); + makeStringFromEscaped(title1); + getStringToken(data, '|', 4, sizeof(msg1)-1, msg1); + makeStringFromEscaped(msg1); + getStringToken(data, '|', 5, sizeof(msg2)-1, msg2); + makeStringFromEscaped(msg2); + getStringToken(data, '|', 6, sizeof(msg3)-1, msg3); + makeStringFromEscaped(msg3); + + strncpy_s(shopWindow1Title, title1, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + + getStrSplit((char *)shopWindow2Msg, msg1, + sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg[0]) - 1); + + getStrSplit((char *)shopWindow4Msg, msg2, + sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg[0]) - 1); + + getStrSplit((char *)shopWindow5Msg, msg3, + sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg[0]) - 1); + + + shopWondow2MaxPage = MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; + for (i = 0, j = 0; i < shopWondow2MaxPage; i++){ + flag = getStringToken(data, '|', 7 + i*datalen, sizeof(itemName)-1, itemName); + makeStringFromEscaped(itemName); + if (flag){ + poolItem[i].name[0] = '\0'; + continue; + } + + j++; + if (strlen(itemName) <= ITEM_NAME_LEN){ + strcpy(poolItem[i].name, itemName); + } + else{ + strcpy(poolItem[i].name, "???"); + } + poolItem[i].poolFlag = getIntegerToken(data, '|', 8 + i*datalen); + poolItem[i].price = getIntegerToken(data, '|', 9 + i*datalen); + poolItem[i].graNo = getIntegerToken(data, '|', 10 + i*datalen); + getStringToken(data, '|', 11 + i*datalen, sizeof(info)-1, info); + +#ifdef _ITEM_PILENUMS + poolItem[i].num = getIntegerToken(data, '|', 12 + i*datalen); +#endif + makeStringFromEscaped(info); + getStrSplit((char *)(&poolItem[i].info), info, + sizeof(poolItem[0].info[0]), + sizeof(poolItem[0].info) / sizeof(poolItem[0].info[0]), + sizeof(poolItem[0].info[0]) - 1); +#ifdef _ITEM_PILENUMS + poolItem[i].tbl = getIntegerToken(data, '|', 13 + i*datalen); +#else + poolItem[i].tbl = getIntegerToken( data, '|', 12+i*datalen ); +#endif + } + if (j > 0){ + shopWondow2MaxPage = (j + 7) / MAX_POOL_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + } + else{ + shopWindowProcNo = 100; + shopWondow2Page = 0; + getStringToken(data, '|', 2, sizeof(title1)-1, title1); + makeStringFromEscaped(title1); + getStringToken(data, '|', 3, sizeof(msg1)-1, msg1); + makeStringFromEscaped(msg1); + getStringToken(data, '|', 4, sizeof(msg2)-1, msg2); + makeStringFromEscaped(msg2); + getStringToken(data, '|', 5, sizeof(msg3)-1, msg3); + makeStringFromEscaped(msg3); + + strncpy_s(shopWindow1Title, title1, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + getStrSplit((char *)shopWindow2Msg, msg1, + sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]), + sizeof(shopWindow2Msg[0]) - 1); + + getStrSplit((char *)shopWindow4Msg, msg2, + sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]), + sizeof(shopWindow4Msg[0]) - 1); + + getStrSplit((char *)shopWindow5Msg, msg3, + sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]), + sizeof(shopWindow5Msg[0]) - 1); + + + shopWondow2MaxPage = MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; + for (i = 0, j = 0; i < shopWondow2MaxPage; i++){ + // ???? + flag = getStringToken(data, '|', 6 + i*datalen, sizeof(itemName)-1, itemName); + makeStringFromEscaped(itemName); + if (flag){ + poolItem[i].name[0] = '\0'; + continue; + } + + j++; + if (strlen(itemName) <= ITEM_NAME_LEN){ + strcpy(poolItem[i].name, itemName); + } + else{ + strcpy(poolItem[i].name, "???"); + } + poolItem[i].poolFlag = getIntegerToken(data, '|', 7 + i*datalen); + poolItem[i].level = getIntegerToken(data, '|', 8 + i*datalen); + poolItem[i].price = getIntegerToken(data, '|', 9 + i*datalen); + poolItem[i].graNo = getIntegerToken(data, '|', 10 + i*datalen); + getStringToken(data, '|', 11 + i*datalen, sizeof(info)-1, info); +#ifdef _ITEM_PILENUMS + poolItem[i].num = getIntegerToken(data, '|', 12 + i*datalen); +#endif + makeStringFromEscaped(info); + getStrSplit((char *)(&poolItem[i].info), info, + sizeof(poolItem[i].info[0]), + sizeof(poolItem[i].info) / sizeof(poolItem[i].info[0]), + sizeof(userItem[i].info[0]) - 1); + } + if (j > 0){ + shopWondow2MaxPage = (j + 7) / MAX_POOL_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + } +} + +void initServerWindowType7(char *data) +{ + char msg[256]; + + shopWindowProcNo = 0; + + getStringToken(data, '|', 1, sizeof(msg)-1, msg); + makeStringFromEscaped(msg); + strncpy_s(shopWindow1Title, msg, sizeof(shopWindow1Title)-1); + shopWindow1Title[sizeof(shopWindow1Title)-1] = '\0'; + + getStringToken(data, '|', 2, sizeof(msg)-1, msg); + makeStringFromEscaped(msg); + strncpy_s(shopWindow1Msg, msg, sizeof(shopWindow1Msg)-1); + shopWindow1Msg[sizeof(shopWindow1Msg)-1] = '\0'; +} + + + +// ????????? +// ???????????????? +// ?????????????????? +void serverWindowType0(int mode) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static STR_BUFFER input; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + + static int totalMsgLine; + static int lineSkip; + + + + if (ptActMenuWin == NULL) + { + winW = msgWN_W; + winH = msgWN_H; +#ifdef _NEW_MANOR_LAW + if (mode == 2) winH = 7; +#endif + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + + lineSkip = 20; + totalMsgLine = (winH * 48 - 56) / lineSkip; + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = ((winH * 48 - 56) / totalMsgLine)*(totalMsgLine - 1) + + (winH * 48 - totalMsgLine*lineSkip) / 2 + 8; + } + } + + // ????????????? + if (mode == 0 || mode == 2) + { + msgLine = totalMsgLine - 1; + input.buffer[0] = '\0'; + } + else + if (mode == 1) + { + msgLine = totalMsgLine - 2; + input.buffer[0] = '\0'; + input.cnt = 0; + input.cursor = 0; + initStrBuffer(&input, + winX + (msgWN_W * 64 - msgWNLen * 9) / 2, + winY + ((winH * 48 - 56) / totalMsgLine)*(totalMsgLine - 2) + (winH * 48 - totalMsgLine*lineSkip) / 2, + msgWNLen, FONT_PAL_WHITE, FONT_PRIO_FRONT); + GetKeyInputFocus(&input); + } + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || ((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + // OK + if (0 <= id && id < 6) + { + char msg[256]; + btn = 1; + btn <<= id; + + makeEscapeString(input.buffer, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + + if (id >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (mode == 1) + { + GetKeyInputFocus(&MyChatBuffer); + } + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + for (i = 0; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { +#ifdef _FONT_STYLE_ + PutWinText(winX + (msgWN_W * 64 - msgWNLen * 9) / 2, + winY + ((winH * 48 - 56) / totalMsgLine)*i + (winH * 48 - totalMsgLine*lineSkip) / 2, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0, i); +#else + StockFontBuffer( winX+(msgWN_W*64-msgWNLen*9)/2, + winY+((winH*48-56)/totalMsgLine)*i+(winH*48-totalMsgLine*lineSkip)/2, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0 ); +#endif + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + // ??? + if (mode == 1) + { + StockFontBuffer2(&input); + } + } + } +} + + +// ????????? +// ??????????????? +void serverWindowType1(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 196; + } + } + + msgLine = 10; //msgLine = 8; + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ???? + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + if (ptActMenuWin->hp >= 1) // ???????????? + { + for (i = selStartLine; i < msgLine; i++) + { + // ???????????? + if (strlen(msgWN[i]) > 0) + { + x1 = winX + 41; + y1 = winY + 18 + i * 21; + x2 = x1 + 366; + y2 = y1 + 20; +#ifdef _NEWFONT_ + if (MakeHitBox(x1, y1 + 2, x2, y2 + 2, DISP_PRIO_BOX2)) +#else + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ) +#endif + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id2 = i - selStartLine + 1; + } + } + } + } + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 10 + || id == 100) + { + char data[256]; + char msg[256]; + if (id == 100) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d", id2); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) +#ifdef _MOVE_SCREEN + if(pc.bMoveScreenMode) + lssproto_WN_send( sockfd, nowGx - iScreenMoveX, nowGy - iScreenMoveY, indexWN, idWN, btn, msg ) ; + else + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ) ; +#else + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); +#endif + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + + if (id >= 0 || id2 >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin->hp >= 1) + { + for (i = 0; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { +#ifdef _NEWFONT_ +#ifdef _FONT_STYLE_ + PutWinText(winX + 80, winY + 21 + i * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0, i); +#else + StockFontBuffer( winX+80, winY+21+i*21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0 ); +#endif +#else + StockFontBuffer( winX+44, winY+21+i*21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0 ); +#endif + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + +void serverWindowType2(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + int len; + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1){ + if (buttonTypeWN & mask){ + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0){ + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 196; + } + } + strcpy(msgWN[0], "=== 请选择宠物 ==="); + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL){ + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + id2 = -1; + if (ptActMenuWin->hp >= 1){ + for (i = 1, j = 1; i <= MAX_PET; i++){ + if (pet[i - 1].useFlag != 0){ + x1 = winX + 41; + y1 = winY + 18 + (j + 1) * 21; + x2 = x1 + 366; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + id2 = i; + } + } + j++; + } + } + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 8){ + char data[256]; + char msg[256]; + if (0 <= id && id < 6){ + btn = 1; + btn <<= id; + } + else{ + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d", id2); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + + if (id >= 0 || id2 >= 0){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1){ + StockFontBuffer(winX + 54, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[0], 0); + for (i = 1, j = 1; i <= MAX_PET; i++){ + len = strlen(pet[i - 1].name); + if (pet[i - 1].useFlag != 0){ + len = strlen(pet[i - 1].freeName); + if (len > 0){ + strcpy(msgWN[1], pet[i - 1].freeName); + } + else{ + len = strlen(pet[i - 1].name); + strcpy(msgWN[1], pet[i - 1].name); + } +#if 0 + StockFontBuffer( winX+152+(144-len*9)/2, winY+21+(j+1)*21, +#else + StockFontBuffer(winX + 42, winY + 21 + (j + 1) * 21,//modified by zhuo 62改成42 +#endif + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + sprintf_s(msgWN[1], "LV.%d", pet[i - 1].level); + StockFontBuffer(winX + 260, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + sprintf_s(msgWN[1], "MaxHP %d", pet[i - 1].maxHp); + StockFontBuffer(winX + 314, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + j++; + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1){ + btnId[i] = -2; + if (buttonTypeWN & mask){ + if (j < btnCnt){ + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + +void serverWindowType3(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + int len; + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 196; + } + } + + strcpy(msgWN[0], "=== 请选择队友 ==="); + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ???? + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + if (ptActMenuWin->hp >= 1) // ???????????? + { + for (i = 1; i <= MAX_PARTY; i++) + { + // ???????????? + if (partyModeFlag == 0 && i == 1) + { + strcpy(msgWN[1], pc.name); + } + else + if (party[i - 1].useFlag != 0) + { + strcpy(msgWN[1], party[i - 1].name); + } + else + { + msgWN[1][0] = '\0'; + } + len = strlen(msgWN[1]); + if (len > 0) + { + x1 = winX + 41; + y1 = winY + 18 + (i + 1) * 21; + x2 = x1 + 366; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id2 = i + 5; + } + } + } + } + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 8) + { + char data[256]; + char msg[256]; + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d", id2); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + + if (id >= 0 || id2 >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 62, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[0], 0); + for (i = 1; i <= MAX_PARTY; i++) + { + if (partyModeFlag == 0 && i == 1) + { + strcpy(msgWN[1], pc.name); + } + else + if (party[i - 1].useFlag != 0) + { + strcpy(msgWN[1], party[i - 1].name); + } + else + { + msgWN[1][0] = '\0'; + } + len = strlen(msgWN[1]); + if (len > 0) + { + StockFontBuffer(winX + 152 + (144 - len * 9) / 2, winY + 21 + (i + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + + +// ????????? +// ?????? +void serverWindowType4(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + int len; + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 196; + } + } + + strcpy(msgWN[0], "=== 请选择宠物或是队友 ==="); + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ???? + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + if (ptActMenuWin->hp >= 1) // ???????????? + { + for (i = 1; i <= MAX_PET; i++) + { + // ???????????? + if (pet[i - 1].useFlag != 0) + { + x1 = winX + 41; + y1 = winY + 18 + (i + 1) * 21; + x2 = x1 + 149; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id2 = i; + } + } + } + } + } + + for (i = 1; i <= MAX_PARTY; i++) + { + // ???????????? + if (partyModeFlag == 0 && i == 1) + { + strcpy(msgWN[1], pc.name); + } + else + if (party[i - 1].useFlag != 0) + { + strcpy(msgWN[1], party[i - 1].name); + } + else + { + msgWN[1][0] = '\0'; + } + len = strlen(msgWN[1]); + if (len > 0) + { + x1 = winX + 257; + y1 = winY + 18 + (i + 1) * 21; + x2 = x1 + 149; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id2 = i + 5; + } + } + } + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 10) + { + char data[256]; + char msg[256]; + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d", id2); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + + if (id >= 0 || id2 >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 62, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[0], 0); + + // ??? + for (i = 1; i <= MAX_PET; i++) + { + len = strlen(pet[i - 1].name); + if (pet[i - 1].useFlag != 0) + { + len = strlen(pet[i - 1].freeName); + if (len > 0) + { + strcpy(msgWN[1], pet[i - 1].freeName); + } + else + { + len = strlen(pet[i - 1].name); + strcpy(msgWN[1], pet[i - 1].name); + } + StockFontBuffer(winX + 44 + (144 - len * 9) / 2, winY + 21 + (i + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + } + } + + // ???? + for (i = 1; i <= MAX_PARTY; i++) + { + if (partyModeFlag == 0 && i == 1) + { + strcpy(msgWN[1], pc.name); + } + else + if (party[i - 1].useFlag != 0) + { + strcpy(msgWN[1], party[i - 1].name); + } + else + { + msgWN[1][0] = '\0'; + } + len = strlen(msgWN[1]); + if (len > 0) + { + StockFontBuffer(winX + 260 + (144 - len * 9) / 2, winY + 21 + (i + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + + +void serverWindowType9(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + char *btnTitle[] = { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" }; + + static int selectID[3] = { -1, -1, -1 }; + static int selects = 0; + + int id, id2; + int i, j; + int mask, btn, len; + int x1, y1, x2, y2; + + if (ptActMenuWin == NULL){ + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1){ + if (buttonTypeWN & mask){ + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0){ + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++){ + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 196; + } + } + if (selects == 0) { + strcpy(msgWN[0], "=== 请选择主体宠物 ==="); + } + else { + strcpy(msgWN[0], "=== 请选择客体宠物 ==="); + } + play_se(202, 320, 240); // ???????? + } + if (ptActMenuWin != NULL){ + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + id2 = -1; + if (ptActMenuWin->hp >= 1){ + for (i = 1, j = 1; i <= MAX_PET; i++){ + if (pet[i - 1].useFlag != 0){ + x1 = winX + 41; + y1 = winY + 18 + (j + 1) * 21; + x2 = x1 + 366; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + id2 = i; + if (selects < 3){ + int k; + for (k = 0; k < 3; k++) { + if (selectID[k] == i) + break; + } + if (k >= 3) { + selectID[selects++] = i; + } + } + } + } + j++; + } + } + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6){ + //|| 0 <= id2 && id2 < 8 ){ + char data[256]; + char msg[256]; + if (0 <= id && id < 6){ + btn = 1; + btn <<= id; + } + else{ + btn = 0; + } + if (id2 < 0) + id2 = 0; + //sprintf_s( data, "%d", id2 );//selectID + sprintf_s(data, "%d|%d|%d", selectID[0], selectID[1], selectID[2]); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + for (i = 0; i < 3; i++) { + selectID[i] = -1; + } + selects = 0; + windowTypeWN = -1; + } + + if (id >= 0 || id2 >= 0){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1){ + StockFontBuffer(winX + 54, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[0], 0); + for (i = 1, j = 1; i <= MAX_PET; i++){ + len = strlen(pet[i - 1].name); + if (pet[i - 1].useFlag != 0){ + len = strlen(pet[i - 1].freeName); + if (len > 0){ + strcpy(msgWN[1], pet[i - 1].freeName); + } + else{ + len = strlen(pet[i - 1].name); + strcpy(msgWN[1], pet[i - 1].name); + } + StockFontBuffer(winX + 62, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + //selectID + if (selectID[0] == i) { + sprintf_s(msgWN[1], "主体"); + StockFontBuffer(winX + 220, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_RED, msgWN[1], 0); + } + else if (selectID[1] == i || selectID[2] == i) { + sprintf_s(msgWN[1], "客体"); + StockFontBuffer(winX + 220, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, msgWN[1], 0); + } + sprintf_s(msgWN[1], "LV.%d", pet[i - 1].level); + StockFontBuffer(winX + 260, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + sprintf_s(msgWN[1], "MaxHP %d", pet[i - 1].maxHp); + StockFontBuffer(winX + 314, winY + 21 + (j + 1) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + j++; + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1){ + btnId[i] = -2; + if (buttonTypeWN & mask){ + if (j < btnCnt){ + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + + +// ????????? + +void initShopWindow1(void); +int shopWindow1(void); +void initShopWindow2(void); +int shopWindow2(void); +void initShopWindow3(void); +int shopWindow3(void); +void initShopWindow4(void); +int shopWindow4(void); +void initShopWindow5(void); +int shopWindow5(void); +void initShopWindow6(void); +int shopWindow6(void); +void initShopWindow7(void); +int shopWindow7(void); +void initShopWindow8(void); +int shopWindow8(void); + +#ifdef _ITEM_PILENUMS +void initShopWindow10(void); +int shopWindow10(void); +#endif + +void serverWindowType5(void) +{ + int ret; + + if (shopWindowProcNo == 0){ + initShopWindow1(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 1){ + ret = shopWindow1(); + } + + if (shopWindowProcNo == 15){ + initShopWindow2(); + shopWindowProcNo = 11; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 10){ + int i, j; + +#ifdef _NEW_ITEM_ + for( i = MAX_ITEMSTART, j= 0; i < 判断玩家道具数量(); i++ ){ +#else + for (i = MAX_ITEMSTART, j = 0; i < MAX_ITEM; i++){ +#endif + if (pc.item[i].useFlag == 0) + j++; + } + nowUserItemCnt = j; + + initShopWindow2(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 11){ + ret = shopWindow2(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "0"); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + windowTypeWN = -1; + } + else if (ret == 2){ + shopWindowProcNo = 30; + } + else if (ret == 3){ + shopWindowProcNo = 20; + } + if (ret == 4){ + shopWindowProcNo = 50; + } + } + if (shopWindowProcNo == 20){ + initShopWindow4(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 21){ + ret = shopWindow4(); + if (ret == 1){ + shopWindowProcNo = 30; + } + else if (ret == 2){ + shopWindowProcNo = 15; + } + } + if (shopWindowProcNo == 30){ + initShopWindow3(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 31){ + ret = shopWindow3(); + if (ret == 1){ + shopWindowProcNo = 40; + } + else if (ret == 2){ + shopWindowProcNo = 15; + } + } + if (shopWindowProcNo == 40){ + initShopWindow5(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 41){ + ret = shopWindow5(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "%d|%d", selShopItemNo + 1, sealItemCnt); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + nowUserItemCnt--; + pc.gold -= sealItem[selShopItemNo].price*sealItemCnt; +#ifdef _NEW_MANOR_LAW + if (sealItem[selShopItemNo].costfame > 0) + pc.fame -= sealItem[selShopItemNo].costfame * sealItemCnt; +#endif + shopWindowProcNo = 15; + } + else if (ret == 2){ + shopWindowProcNo = 30; + } + } + if (shopWindowProcNo == 50){ + initShopWindow6(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 51){ + ret = shopWindow6(); + if (ret == 1){ + shopWindowProcNo = 15; + } + } + + if (shopWindowProcNo == 100){ + initShopWindow7(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 101){ + ret = shopWindow7(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "0"); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + windowTypeWN = -1; + } + else if (ret == 2){ + shopWindowProcNo = 110; + } + else if (ret == 3){ + shopWindowProcNo = 120; + } + } + + if (shopWindowProcNo == 110){ +#ifdef _ITEM_PILENUMS + initShopWindow10(); +#else + initShopWindow5(); +#endif + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 111){ +#ifdef _ITEM_PILENUMS + ret = shopWindow10(); +#else + ret = shopWindow5(); +#endif + if (ret == 1){ + char data[256]; + char msg[256]; + +#ifdef _ITEM_PILENUMS + sprintf_s(data, "%d|%d", userItem[selShopItemNo].tbl, sealItemCnt); +#else + sprintf_s( data, "%d|%d", userItem[selShopItemNo].tbl, userItem[selShopItemNo].price ); +#endif + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + + pc.gold += userItem[selShopItemNo].price; + int i, j, k; +#ifdef _ITEM_PILENUMS + shopWindowProcNo = 100; + userItem[selShopItemNo].num -= sealItemCnt; + if (userItem[selShopItemNo].num <= 0){ +#else + shopWindowProcNo = 100; +#endif + userItem[selShopItemNo].name[0] = '\0'; + for (i = 0; i < MAX_SHOP_ITEM*MAX_SHOP_PAGE - 1; i++){ + if (userItem[i].name[0] == '\0'){ + for (j = i + 1; j < MAX_SHOP_ITEM*MAX_SHOP_PAGE; j++){ + if (userItem[j].name[0] != '\0'){ + strcpy(userItem[i].name, userItem[j].name); + userItem[i].sealFlag = userItem[j].sealFlag; + userItem[i].level = userItem[j].level; + userItem[i].price = userItem[j].price; + userItem[i].graNo = userItem[j].graNo; + userItem[i].tbl = userItem[j].tbl; +#ifdef _ITEM_PILENUMS + userItem[i].num = userItem[j].num; +#endif + for (k = 0; k < 3; k++){ + strcpy(userItem[i].info[k], userItem[j].info[k]); + } + userItem[j].name[0] = '\0'; + break; + } + } + } + } +#ifdef _ITEM_PILENUMS + } +#endif + for (i = 0; i < MAX_SHOP_ITEM*MAX_SHOP_PAGE; i++){ + if (userItem[i].name[0] == '\0') break; + } + if (i > 0){ + shopWondow2MaxPage = (i + 7) / MAX_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + if (shopWondow2Page >= shopWondow2MaxPage) + shopWondow2Page = shopWondow2MaxPage - 1; + + } + else if (ret == 2){ + shopWindowProcNo = 100; + } +} + +if (shopWindowProcNo == 120){ + initShopWindow8(); + shopWindowProcNo++; + play_se(202, 320, 240); +} +if (shopWindowProcNo == 121){ + ret = shopWindow8(); + if (ret == 1){ + shopWindowProcNo = 100; + } +} +} + +short shopWindow1ProcNo; + +void initShopWindow1(void) +{ + shopWindow1ProcNo = 0; +} + +int shopWindow1(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id = 0; + int i; + int ret = 0; + + if (shopWindow1ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 4; + h = 3; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow1ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + ret = id + 1; + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + ret = 3; // ?? + wnCloseFlag = 0; + } + + if (0 <= id && id <= 2) + { +#if 1 + char data[256]; + char msg[256]; + sprintf_s(data, "%d", ret); + makeEscapeString(data, msg, sizeof(msg)-1); +#if 0 + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, menuIndexWN, idWN, 0, msg ) ; + else + oldlssproto_WN_send( sockfd, nowGx, nowGy, menuIndexWN, idWN, 0, msg ) ; +#else + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); +#endif +#endif + } + + if (id >= 0) + { + if (ret == 3) + { + play_se(203, 320, 240); // ???????? + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + windowTypeWN = -1; + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + xx = (w * 64 - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 12, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + xx = (w * 64 - strlen(shopWindow1Msg) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 32, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Msg, 0); + + btnId[0] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 66, DISP_PRIO_IME3, CG_BUY_BTN, 2); + btnId[1] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 90, DISP_PRIO_IME3, CG_SEAL_BTN, 2); + btnId[2] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 114, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + } + } + + return ret; +} + +short shopWindow2ProcNo; +void initShopWindow2(void) +{ + shopWindow2ProcNo = 0; +} + +int shopWindow2(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if (shopWindow2ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 432; + h = 428; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow2ProcNo++; + } + + + if (ptActMenuWin != NULL){ + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + if (ptActMenuWin->hp >= 1){ + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++){ + if (sealItem[j + i].name[0] != '\0'){ + x1 = x + 32; + y1 = y + i * 21 + 116; + x2 = x1 + 372; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + + if (sealItem[j + i].price <= pc.gold && + sealItem[j + i].sealFlag == 0 +#ifdef _NEW_MANOR_LAW + && sealItem[j + i].costfame <= pc.fame +#endif + ){ +#ifdef _EVIL_KILL + if( pc.ftype != 0 ){ + if( sealItem[j+i].costfame <= pc.newfame ) selId = j+i; + else play_se( 220, 320, 240 ); + }else +#endif + selId = j + i; + } + else{ +#ifdef _EVIL_KILL + if( pc.ftype != 0 ){ + if( sealItem[j+i].costfame <= pc.newfame ) selId = j+i; + else play_se( 220, 320, 240 ); + }else +#endif + play_se(220, 320, 240); + } + } + focusId = j + i; + } + } + } + } + + if (joy_con[0] & JOY_A){ + pushId = 0; + if (joy_auto[0] & JOY_A){ + id = 0; + } + } + if (pushId == 0){ + prevBtn = 1; + if (id == 0){ + if (shopWondow2Page > 0){ + shopWondow2Page--; + play_se(217, 320, 240); // ????? + } + } + } + else{ + prevBtn = 0; + } + if (joy_con[0] & JOY_B){ + pushId = 1; + if (joy_auto[0] & JOY_B){ + id = 1; + } + } + if (pushId == 1){ + nextBtn = 1; + if (id == 1){ + if (shopWondow2Page + 1 < shopWondow2MaxPage){ + shopWondow2Page++; + play_se(217, 320, 240); + } + } + } + else{ + nextBtn = 0; + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + if (id >= 2 || selId >= 0){ + if (id == 2){ + ret = 1; + } + else if (id == 100){ + ret = 100; + } + else{ + selShopItemNo = selId; + sealItemCnt = 1; + if (nowUserItemCnt <= 0){ + ret = 4; + } + else if (sealItem[selId].level > pc.level){ + ret = 3; + } + else{ + ret = 2; + } + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1){ + int xx; + xx = (w - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + for (i = 0; i < sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]); i++){ + if (shopWindow2Msg[0] != '\0'){ + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow2Msg[i], 0); + } + } +#ifdef _NEW_SHOP_FRAME + if(atoi(shopWindowCurrency) != 1){ + StockFontBuffer(x+244,y+64,FONT_PRIO_FRONT,FONT_PAL_WHITE,shopWindowCurrency,0); + }else +#endif +#ifdef _NEW_MANOR_LAW +#ifdef _EVIL_KILL + if( pc.ftype == 0 ) + sprintf_s(tmsg,"声望 %8dF",pc.fame); + else if( pc.ftype == 1 ) + sprintf_s(tmsg,"白狼 %8dD",pc.newfame); + else if( pc.ftype == 2 ) + sprintf_s(tmsg,"法师 %8dD",pc.newfame); + else if( pc.ftype == 3 ) + sprintf_s(tmsg,"追猎 %8dD",pc.newfame); + else + sprintf_s(tmsg,"声望 %8dF",pc.fame); + + StockFontBuffer(x+244,y+64,FONT_PRIO_FRONT,FONT_PAL_WHITE,tmsg,0); +#else + sprintf_s(tmsg, "声望 %8dF", pc.fame); + StockFontBuffer(x + 244, y + 64, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); +#endif +#endif + + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + + StockFontBuffer(x + 244, y + 84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + btnId[0] = StockDispBuffer(x + 32, y + 100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[1] = StockDispBuffer(x + 200, y + 100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); + sprintf_s(tmsg, "%2d/%2d 页", shopWondow2Page + 1, shopWondow2MaxPage); + StockFontBuffer(x + 66, y + 92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++){ + if (strlen(sealItem[j + i].name) == 0) continue; + color = itemColor[0]; + if (sealItem[j + i].level > pc.level) + color = itemColor[2]; + if (sealItem[j + i].sealFlag) + color = itemColor[1]; + if (sealItem[j + i].price > pc.gold){ + color = itemColor[1]; + } +#ifdef _NEW_MANOR_LAW + if (sealItem[j + i].costfame > pc.fame){ + color = itemColor[1]; + } +#endif +#ifdef _EVIL_KILL + if( pc.ftype != 0 ){ + if( sealItem[j+i].costfame > pc.newfame ) + color = itemColor[1]; + else + color = itemColor[0]; + } +#endif + StockFontBuffer(x + 34, y + 118 + i * 21, FONT_PRIO_FRONT, color, sealItem[j + i].name, 0); +#ifdef _NEW_SHOP_FRAME + if(sealItem[j+i].costfame > -1){ + sprintf_s(tmsg,"%8d点%8dS",sealItem[j+i].costfame,sealItem[j+i].price); + StockFontBuffer(x+242,y+118+i*21,FONT_PRIO_FRONT,color,tmsg,0); + } + else +#else +#ifdef _NEW_MANOR_LAW + if (sealItem[j + i].costfame > -1){ +#ifdef _EVIL_KILL + if( pc.ftype != 0 ) + sprintf_s(tmsg,"%8dD%8dS",sealItem[j+i].costfame,sealItem[j+i].price); + else + sprintf_s(tmsg,"%8dF%8dS",sealItem[j+i].costfame,sealItem[j+i].price); + StockFontBuffer(x+242,y+118+i*21,FONT_PRIO_FRONT,color,tmsg,0); +#else +#ifdef _NEWFONT_ + extern int getTextLength(char * str); + sprintf_s(tmsg, "%8dF", sealItem[j + i].costfame); + StockFontBuffer(x + 242, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); + sprintf_s(tmsg, "%8dS", sealItem[j + i].price); + StockFontBuffer(x + 242 + 120 - getTextLength(tmsg) / 2, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); + +#else + sprintf_s(tmsg,"%8dF%8dS",sealItem[j+i].costfame,sealItem[j+i].price); + StockFontBuffer(x+242,y+118+i*21,FONT_PRIO_FRONT,color,tmsg,0); +#endif + +#endif + } + else +#endif +#endif + { +#ifdef _NEW_SHOP_FRAME + if(atoi(shopWindowCurrency) != 1){ + sprintf_s( tmsg, "%8d点", sealItem[j+i].price ); + }else +#endif + sprintf_s(tmsg, "%8dS", sealItem[j + i].price); + + StockFontBuffer(x + 312, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); + } + } + if (focusId >= 0){ + StockDispBuffer(x + 64, y + 350, DISP_PRIO_IME3, sealItem[focusId].graNo, 0); + for (i = 0; i < sizeof(sealItem[0].info) / sizeof(sealItem[0].info[0]); i++){ + StockFontBuffer(x + 120, y + 308 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + sealItem[focusId].info[i], 0); + } + } + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_WIN, 1); + } + } + return ret; +} + + +short shopWindow3ProcNo; +void initShopWindow3(void) +{ + shopWindow3ProcNo = 0; +} + +int shopWindow3(void) +{ + static int x, y, w, h; + static int btnId[4]; + int upBtnGraNo[] = { CG_UP_BTN, CG_UP_BTN_DOWN }; + int downBtnGraNo[] = { CG_DOWN_BTN, CG_DOWN_BTN_DOWN }; + int upBtn, downBtn; + int id; + int pushId = 0; + int i; + int ret = 0; + char tmsg[256]; + + if (shopWindow3ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 440; + h = 160; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow3ProcNo++; + } + + + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + } + + if (joy_con[0] & JOY_A){ + pushId = 0; + if (joy_auto[0] & JOY_A){ + id = 0; + } + } + if (pushId == 0){ + downBtn = 1; + if (id == 0){ + if (sealItemCnt > 1){ + sealItemCnt--; + play_se(217, 320, 240); // ????? + } + } + } + else{ + downBtn = 0; + } + if (joy_con[0] & JOY_B){ + pushId = 1; + if (joy_auto[0] & JOY_B){ + id = 1; + } + } + if (pushId == 1){ + upBtn = 1; + if (id == 1){ + if (sealItemCnt + 1 <= nowUserItemCnt + && sealItem[selShopItemNo].price*(sealItemCnt + 1) <= pc.gold +#ifdef _NEW_MANOR_LAW + && sealItem[selShopItemNo].costfame * (sealItemCnt + 1) <= pc.fame +#endif + ){ + sealItemCnt++; + play_se(217, 320, 240); // ????? + } + } + } + else{ + upBtn = 0; + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 2){ + if (id == 2){ + ret = 1; + } + else if (id == 3){ + ret = 2; + } + else if (id == 100){ + ret = 100; + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + if (ptActMenuWin->hp >= 1){ + int xx; + xx = (w - strlen(shopWindow3Msg) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow3Msg, 0); + StockFontBuffer(x + 16, y + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, + sealItem[selShopItemNo].name, 0); + sprintf_s(tmsg, "%2d个", sealItemCnt); + StockFontBuffer(x + 300, y + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + sprintf_s(tmsg, "%8dS x %2d = %8dS", sealItem[selShopItemNo].price, + sealItemCnt, sealItem[selShopItemNo].price*sealItemCnt); + StockFontBuffer(x + 16, y + 82, FONT_PRIO_FRONT, FONT_PAL_WHITE, + tmsg, 0); +#ifdef _NEW_MANOR_LAW + if (sealItem[selShopItemNo].costfame > -1){ +#ifdef _EVIL_KILL + if(pc.ftype !=0 ) + sprintf_s(tmsg,"%8dD x %2d = %8dD",sealItem[selShopItemNo].costfame ,sealItemCnt, + sealItem[selShopItemNo].costfame * sealItemCnt); + else +#endif + sprintf_s(tmsg, "%8dF x %2d = %8dF", sealItem[selShopItemNo].costfame, sealItemCnt, + sealItem[selShopItemNo].costfame * sealItemCnt); + StockFontBuffer(x + 16, y + 102, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + } +#ifdef _EVIL_KILL + if( pc.ftype == 1 ) + sprintf_s(tmsg,"白狼 %8dD",pc.newfame); + else if( pc.ftype == 2 ) + sprintf_s(tmsg,"法师 %8dD",pc.newfame); + else if( pc.ftype == 3 ) + sprintf_s(tmsg,"追猎 %8dD",pc.newfame); + else +#endif + sprintf_s(tmsg, "声望 %8dF", pc.fame); + StockFontBuffer(x + 248, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); +#endif + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 248, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + btnId[0] = StockDispBuffer(x + 364, y + 60, DISP_PRIO_IME3, downBtnGraNo[downBtn], 2); + btnId[1] = StockDispBuffer(x + 404, y + 60, DISP_PRIO_IME3, upBtnGraNo[upBtn], 2); + + btnId[2] = StockDispBuffer(x + 64, y + 140, DISP_PRIO_IME3, CG_OK_BTN, 2); + btnId[3] = StockDispBuffer(x + 164, y + 140, DISP_PRIO_IME3, CG_CANCEL_BTN, 2); + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_KOSU_WIN, 1); + } + } + + return ret; +} +short shopWindow4ProcNo; +void initShopWindow4(void) +{ + shopWindow4ProcNo = 0; +} + +int shopWindow4(void) +{ + static int x, y, w, h; + static int btnId[2]; + int id; + int i; + int ret = 0; + if (shopWindow4ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 6; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow4ProcNo++; + } + + + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 0){ + if (id == 0){ + ret = 1; + } + else if (id == 1){ + ret = 2; + } + else if (id == 100){ + ret = 100; + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + + + if (ptActMenuWin->hp >= 1){ + for (i = 0; i < sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]); i++){ + if (shopWindow4Msg[0] != '\0'){ + StockFontBuffer(x + 20, y + 20 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow4Msg[i], 0); + } + } + + btnId[0] = StockDispBuffer(x + 128, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + btnId[1] = StockDispBuffer(x + 256, y + 72, DISP_PRIO_IME3, CG_NO_BTN, 2); + } + } + + return ret; +} + +short shopWindow5ProcNo; + +void initShopWindow5(void) +{ + shopWindow5ProcNo = 0; +} + +int shopWindow5(void) +{ + static int x, y, w, h; + static int btnId[2]; + int id; + int i; + int ret = 0; + + if (shopWindow5ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 6; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow5ProcNo++; + } + + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + if (id >= 0){ + if (id == 0){ + ret = 1; + } + else if (id == 1){ + ret = 2; + } + else if (id == 100){ + ret = 100; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100 || ret == 1){ + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1){ + for (i = 0; i < sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]); i++){ + if (shopWindow5Msg[0] != '\0'){ + StockFontBuffer(x + 20, y + 20 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow5Msg[i], 0); + } + } + btnId[0] = StockDispBuffer(x + 128, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + btnId[1] = StockDispBuffer(x + 256, y + 72, DISP_PRIO_IME3, CG_NO_BTN, 2); + } + } + + return ret; +} +short shopWindow6ProcNo; +void initShopWindow6(void) +{ + shopWindow6ProcNo = 0; +} + +int shopWindow6(void) +{ + static int x, y, w, h; + static int btnId[1]; + int id; + int i; + int ret = 0; + + if (shopWindow6ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 6; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow6ProcNo++; + } + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 0){ + if (id == 0){ + ret = 1; + } + else if (id == 100){ + ret = 100; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + + + if (ptActMenuWin->hp >= 1) + { + // ????????? + for (i = 0; i < sizeof(shopWindow6Msg) / sizeof(shopWindow6Msg[0]); i++) + { + if (shopWindow6Msg[0] != '\0') + { + StockFontBuffer(x + 20, y + 20 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow6Msg[i], 0); + } + } + + btnId[0] = StockDispBuffer(x + 192, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + } + } + + return ret; +} + + +// ?????????? +// ?????? +short shopWindow7ProcNo; + +// ??? +void initShopWindow7(void) +{ + shopWindow7ProcNo = 0; +} + + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ? +// 3 ... ??? +int shopWindow7(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if (shopWindow7ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 432; + h = 428; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow7ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if (ptActMenuWin->hp >= 1) + { + // ???? + //id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++) + { + if (userItem[j + i].name[0] != '\0') + { + x1 = x + 32; + y1 = y + i * 21 + 116; + x2 = x1 + 372; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (userItem[j + i].sealFlag == 0) + { + selId = j + i; + } +#ifdef _EVIL_KILL //以前玩家卖的话 sealflag只有 0 或 1 + if( userItem[j+i].sealFlag == 2 ) + { + selId = j+i; + } +#endif + } + focusId = j + i; + } + } + } + } + + + // ?????? + if (joy_con[0] & JOY_A) + { + pushId = 0; + if (joy_auto[0] & JOY_A) + { + id = 0; + } + } + if (pushId == 0) + { + prevBtn = 1; + if (id == 0) + { + if (shopWondow2Page > 0) + { + shopWondow2Page--; + play_se(217, 320, 240); // ????? + } + } + } + else + { + prevBtn = 0; + } + // ??????? + if (joy_con[0] & JOY_B) + { + pushId = 1; + if (joy_auto[0] & JOY_B) + { + id = 1; + } + } + if (pushId == 1) + { + nextBtn = 1; + if (id == 1) + { + if (shopWondow2Page + 1 < shopWondow2MaxPage) + { + shopWondow2Page++; + play_se(217, 320, 240); // ????? + } + } + } + else + { + nextBtn = 0; + } + + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + // id = 0, id = 1 ?????????????? + if (id >= 2 + || selId >= 0) + { + // ????? + if (id == 2) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopItemNo = selId; + sealItemCnt = 1; + if (userItem[selShopItemNo].price + pc.gold > CHAR_getMaxHaveGold()) + { + ret = 3; +#ifdef _EVIL_KILL + if( userItem[selShopItemNo].sealFlag == 2 ) + ret = 2; +#endif + } + else + { + ret = 2; + } + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100 + || (buyOffFlag == 1 && ret == 1)) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + // ???????? + xx = (w - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + // ????????? + for (i = 0; i < sizeof(shopWindow7Msg) / sizeof(shopWindow7Msg[0]); i++) + { + if (shopWindow7Msg[0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow7Msg[i], 0); + } + } + + + // ??? + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 244, y + 84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + // 页?? + btnId[0] = StockDispBuffer(x + 32, y + 100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[1] = StockDispBuffer(x + 200, y + 100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); + sprintf_s(tmsg, "%2d/%2d 页", shopWondow2Page + 1, shopWondow2MaxPage); + StockFontBuffer(x + 66, y + 92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++){ + if (strlen(userItem[j + i].name) == 0) + continue; + color = itemColor[0]; + if (userItem[j + i].sealFlag) + color = itemColor[1]; + + if ((pc.gold + userItem[j + i].price) > CHAR_getMaxHaveGold()) + color = 7; +#ifdef _EVIL_KILL + if( userItem[j+i].sealFlag == 2 ) // _EVIL_KILL NEW + color = itemColor[0]; +#endif + StockFontBuffer(x + 34, y + 118 + i * 21, + FONT_PRIO_FRONT, color, userItem[j + i].name, 0); +#ifdef _ITEM_PILENUMS + sprintf_s(tmsg, "x%d", userItem[j + i].num); + StockFontBuffer(x + 34 + 250, y + 118 + i * 21, + FONT_PRIO_FRONT, color, tmsg, 0); +#endif +#ifdef _EVIL_KILL + if( userItem[j+i].sealFlag == 2 ){ // _EVIL_KILL NEW + sprintf_s( tmsg, "%8dD", userItem[j+i].price ); + StockFontBuffer( x+312, y+118+i*21, + FONT_PRIO_FRONT, color, tmsg, 0 ); + }else // _EVIL_KILL NEW +#endif + sprintf_s(tmsg, "%8dS", userItem[j + i].price); + StockFontBuffer(x + 312, y + 118 + i * 21, + FONT_PRIO_FRONT, color, tmsg, 0); + } + if (focusId >= 0){ + StockDispBuffer(x + 64, y + 350, DISP_PRIO_IME3, userItem[focusId].graNo, 0); + for (i = 0; i < sizeof(userItem[0].info) / sizeof(userItem[0].info[0]); i++){ + StockFontBuffer(x + 120, y + 308 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + userItem[focusId].info[i], 0); + } + } + if (buyOffFlag == 0){ + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + else{ + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + } + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_WIN, 1); + } + } + return ret; +} + + +// ?????????? +// ??????????????? +short shopWindow8ProcNo; + +// ??? +void initShopWindow8(void) +{ + shopWindow8ProcNo = 0; +} + +int shopWindow8(void) +{ + static int x, y, w, h; + static int btnId[1]; + int id; + int i; + int ret = 0; + + if (shopWindow8ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 6; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow8ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 0) + { + if (id == 0) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100) + { + windowTypeWN = -1; + } + return ret; + } + + + if (ptActMenuWin->hp >= 1) + { + // ????????? + for (i = 0; i < sizeof(shopWindow8Msg) / sizeof(shopWindow8Msg[0]); i++) + { + if (shopWindow8Msg[0] != '\0') + { + StockFontBuffer(x + 20, y + 20 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow8Msg[i], 0); + } + } + + btnId[0] = StockDispBuffer(x + 192, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + } + } + + return ret; +} +#ifdef _ITEM_PILENUMS +short shopWindow10ProcNo; +void initShopWindow10(void) +{ + shopWindow10ProcNo = 0; +} + +int shopWindow10(void) +{ + static int x, y, w, h; + static int btnId[4]; + int upBtnGraNo[] = { CG_UP_BTN, CG_UP_BTN_DOWN }; + int downBtnGraNo[] = { CG_DOWN_BTN, CG_DOWN_BTN_DOWN }; + int upBtn, downBtn; + int id; + int pushId; + int i; + int ret = 0; + char tmsg[256]; + + if (shopWindow10ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + /* + w = 5;///440; + h = 2;//160; + x = (lpDraw->xSize-w*70)/2;//(lpDraw->xSize-w)/2; + y = (lpDraw->ySize-h*40)/2;//(lpDraw->ySize-h)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, 1 ); + */ + w = 440; + h = 160; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + shopWindow10ProcNo++; + } + + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + } + + if (joy_con[0] & JOY_A){ + pushId = 0; + if (joy_auto[0] & JOY_A){ + id = 0; + } + } + if (pushId == 0){ + downBtn = 1; + if (id == 0){ + if (sealItemCnt > 1){ + sealItemCnt--; + play_se(217, 320, 240); // ????? + } + } + } + else{ + downBtn = 0; + } + if (joy_con[0] & JOY_B){ + pushId = 1; + if (joy_auto[0] & JOY_B){ + id = 1; + } + } + if (pushId == 1){ + upBtn = 1; + if (id == 1){ + if (sealItemCnt + 1 <= userItem[selShopItemNo].num + && (userItem[selShopItemNo].price*(sealItemCnt + 1) + pc.gold) <= CHAR_getMaxHaveGold()){ + sealItemCnt++; + play_se(217, 320, 240); // ????? + } + } + } + else{ + upBtn = 0; + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 2){ + if (id == 2){ + ret = 1; + } + else if (id == 3){ + ret = 2; + } + else if (id == 100){ + ret = 100; + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + if (ptActMenuWin->hp >= 1){//userItem + int xx; + xx = (w - strlen(shopWindow3Msg) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow3Msg, 0); + StockFontBuffer(x + 16, y + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, + userItem[selShopItemNo].name, 0); + sprintf_s(tmsg, "%2d个", sealItemCnt); + StockFontBuffer(x + 300, y + 52, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); +#ifdef _EVIL_KILL + if(userItem[selShopItemNo].sealFlag == 2 ) + sprintf_s( tmsg, "%8dD x %2d = %8dD", + userItem[selShopItemNo].price, + sealItemCnt, userItem[selShopItemNo].price*sealItemCnt ); + else +#endif + sprintf_s(tmsg, "%8dS x %2d = %8dS", + userItem[selShopItemNo].price, + sealItemCnt, userItem[selShopItemNo].price*sealItemCnt); + StockFontBuffer(x + 146, y + 82, FONT_PRIO_FRONT, FONT_PAL_WHITE, + tmsg, 0); + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 248, y + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + btnId[0] = StockDispBuffer(x + 364, y + 60, DISP_PRIO_IME3, downBtnGraNo[downBtn], 2); + btnId[1] = StockDispBuffer(x + 404, y + 60, DISP_PRIO_IME3, upBtnGraNo[upBtn], 2); + + btnId[2] = StockDispBuffer(x + 64, y + 120, DISP_PRIO_IME3, CG_OK_BTN, 2); + btnId[3] = StockDispBuffer(x + 164, y + 120, DISP_PRIO_IME3, CG_CANCEL_BTN, 2); + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_KOSU_WIN, 1); + } + } + + return ret; +} +#endif + + +void initSkillShopWindow1(void); +int skillShopWindow1(void); +void initSkillShopWindow2(void); +int skillShopWindow2(void); +void initSkillShopWindow3(void); +int skillShopWindow3(void); +void initSkillShopWindow4(void); +int skillShopWindow4(void); + +void serverWindowType6(void) +{ + int ret; + + // ???? + if (skillShopWindowProcNo == 0) + { + initSkillShopWindow1(); + skillShopWindowProcNo++; + play_se(202, 320, 240); // ???????? + } + if (skillShopWindowProcNo == 1) + { + ret = skillShopWindow1(); + if (ret == 2) + { + skillShopWindowProcNo = 10; + } + } + if (skillShopWindowProcNo == 10){ + initSkillShopWindow2(); + skillShopWindowProcNo++; + play_se(202, 320, 240); + } + if (skillShopWindowProcNo == 11){ + ret = skillShopWindow2(); + if (ret == 1){ + skillShopWindowProcNo = 0; + } + else if (ret == 2){ + skillShopWindowProcNo = 20; + } + } + if (skillShopWindowProcNo == 20){ + initSkillShopWindow3(); + skillShopWindowProcNo++; + play_se(202, 320, 240); + } + if (skillShopWindowProcNo == 21){ + ret = skillShopWindow3(); + if (ret == 1){ + skillShopWindowProcNo = 10; + } + else if (ret == 2){ + skillShopWindowProcNo = 30; + } + } + if (skillShopWindowProcNo == 30){ + initSkillShopWindow4(); + skillShopWindowProcNo++; + play_se(202, 320, 240); + } + if (skillShopWindowProcNo == 31){ + ret = skillShopWindow4(); + if (ret == 1){ +#if 1 + char data[256]; + char msg[256]; + sprintf_s(data, "%d|%d|%d|%d", + selShopSkillNo + 1, + selShopSkillPetNo, + selShopSkillSlotNo, + sealSkill[selShopSkillNo].price); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); +#endif + pc.gold -= sealSkill[selShopSkillNo].price; + + windowTypeWN = -1; + } + else if (ret == 2){ + skillShopWindowProcNo = 20; + } + } +} + + +#ifdef _CHAR_PROFESSION // WON ADD 人物职业技能 + +void initServerWindowProfession( char *data ) +{ + char title1[128]; + char msg2[128]; + char skillName[64]; + char info[256]; + int i, j; + int flag; + + skillShopWindowProcNo = 0; + shopWondow2Page = 0; + + if( getIntegerToken( data, '|', 1 ) == 0 ) + return; + + getStringToken( data, '|', 2, sizeof( title1 )-1, title1 ); + makeStringFromEscaped( title1 ); + getStringToken( data, '|', 3, sizeof( msg2 )-1, msg2 ); + makeStringFromEscaped( msg2 ); + + strncpy_s( ProfessionShopTitle, title1, sizeof( ProfessionShopTitle )-1 ); + ProfessionShopTitle[sizeof( ProfessionShopTitle )-1] = '\0'; + + getStrSplit( (char *)ProfessionShopMsg, msg2, + sizeof( ProfessionShopMsg[0] ), + sizeof( ProfessionShopMsg )/sizeof( ProfessionShopMsg[0] ), + sizeof( ProfessionShopMsg[0] )-1 ); + + // Robin fix 20040707 回圈过大 + //shopWondow2MaxPage = MAX_SKILL_SHOP_SKILL* 9; + shopWondow2MaxPage = MAX_SKILL_SHOP_SKILL*MAX_SKILL_SHOP_PAGE; + + for( i = 0, j = 0; i < shopWondow2MaxPage; i++ ) + { + // 技能名称 + flag = getStringToken( data, '|', 4+i*4, sizeof( skillName )-1, skillName ); + makeStringFromEscaped( skillName ); + if( flag ) + { + sealSkill[i].name[0] = '\0'; + continue; + } + + j++; + + if( strlen( skillName ) <= SKILL_NAME_LEN ) + strcpy( sealSkill[i].name, skillName ); + else + strcpy( sealSkill[i].name, "???" ); + + // 金额 + sealSkill[i].price = getIntegerToken( data, '|', 5+i*4 ); + + // 说明 + getStringToken( data, '|', 6+i*4, sizeof( info )-1, info ); + makeStringFromEscaped( info ); + getStrSplit( (char *)(&sealSkill[i].info), info, + sizeof( sealSkill[0].info[0] ), + sizeof( sealSkill[0].info )/sizeof( sealSkill[0].info[0] ), + sizeof( sealSkill[0].info[0] )-1 ); + + // 图示 + sealSkill[i].icon = getIntegerToken( data, '|', 7+i*4 ); + + } + if( j > 0 ) + { + shopWondow2MaxPage = (j+7)/MAX_SKILL_SHOP_SKILL; + } + else + { + shopWondow2MaxPage = 1; + } +} + +void profession_windows( void ) +{ + int ret; + + if( skillShopWindowProcNo == 0 ) + { + initSkillShopWindow1(); + skillShopWindowProcNo++; + play_se( 202, 320, 240 ); + } + if( skillShopWindowProcNo == 1 ) + { + ret = profession_windows_1(); + if( ret == 2 ) + { + skillShopWindowProcNo = 10; + } + } + if( skillShopWindowProcNo == 10 ){ + initSkillShopWindow4(); + skillShopWindowProcNo++; + play_se( 202, 320, 240 ); + } + if( skillShopWindowProcNo == 11 ){ + ret = profession_windows_2(); + if( ret == 1 ){ + + char data[256]; + char msg[256]; + sprintf_s( data, "%d|%d", + selShopSkillNo+1, + sealSkill[selShopSkillNo].price ); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, 0, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, 0, msg ) ; + + // Robin fix 20040707 修改Client自动扣钱bug + //pc.gold -= sealSkill[selShopSkillNo].price; + + windowTypeWN = -1; + }else if( ret == 2 ){ + skillShopWindowProcNo = 0; + } + } + +} + + +int profession_windows_1( void ) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if( skillShopWindow1ProcNo == 0 ) + { + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + + w = 432; + h = 428; + x = (lpDraw->xSize-w)/2; + y = (lpDraw->ySize-h)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, -1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + skillShopWindow1ProcNo++; + } + + + if( ptActMenuWin != NULL ) + { + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if( ptActMenuWin->hp >= 1 ) + { + id = selRepGraId( btnId, sizeof( btnId )/sizeof( int ) ); + pushId = pushGraId( btnId, sizeof( btnId )/sizeof( int ) ); + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for( i = 0; i < MAX_SKILL_SHOP_SKILL; i++ ) + { + if( sealSkill[j+i].name[0] != '\0' ) + { + x1 = x+32; + y1 = y+i*21+116; + x2 = x1 + 372; + y2 = y1 + 20; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ) + { + if( mouse.onceState & MOUSE_LEFT_CRICK ) + { + if( sealSkill[j+i].price <= pc.gold ) + { + selId = j+i; + } + else + { + play_se( 220, 320, 240 ); + } + } + focusId = j+i; + } + } + } + } + + if( joy_con[0] & JOY_A ) + { + pushId = 0; + if( joy_auto[0] & JOY_A ) + { + id = 0; + } + } + if( pushId == 0 ) + { + prevBtn = 1; + if( id == 0 ) + { + if( shopWondow2Page > 0 ) + { + shopWondow2Page--; + play_se( 217, 320, 240 ); + } + } + } + else + { + prevBtn = 0; + } + + if( joy_con[0] & JOY_B ) + { + pushId = 1; + if( joy_auto[0] & JOY_B ) + { + id = 1; + } + } + if( pushId == 1 ) + { + nextBtn = 1; + if( id == 1 ) + { + if( shopWondow2Page+1 < shopWondow2MaxPage ) + { + shopWondow2Page++; + play_se( 217, 320, 240 ); + } + } + } + else + { + nextBtn = 0; + } + + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + wnCloseFlag = 0; + } + + if( id >= 2 + || selId >= 0 ) + { + if( id == 2 ) + { + ret = 1; + play_se( 203, 320, 240 ); + } + else + if( id == 100 ) + { + ret = 100; + } + else + { + selShopSkillNo = selId; + ret = 2; + } + + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + if( ret == 100 + || ret == 1 ) + { + windowTypeWN = -1; + } + return ret; + } + + if( ptActMenuWin->hp >= 1 ) + { + int xx; + + xx = (w-strlen( ProfessionShopTitle )/2*17)/2; + StockFontBuffer( x+xx, y+18, FONT_PRIO_FRONT, FONT_PAL_WHITE, ProfessionShopTitle, 0 ); + + for( i = 0; i < sizeof( ProfessionShopMsg )/sizeof( ProfessionShopMsg[0] ); i++ ) + { + if( ProfessionShopMsg[0] != '\0' ) + { + StockFontBuffer( x+18, y+48+i*18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + ProfessionShopMsg[i], 0 ); + } + } + + sprintf_s( tmsg, "金钱 %8dS", pc.gold ); + StockFontBuffer( x+244, y+84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0 ); + + // 页?? + btnId[0] = StockDispBuffer( x +32, y+100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2 ); + btnId[1] = StockDispBuffer( x+200, y+100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2 ); + sprintf_s( tmsg, "%2d/%2d 页", shopWondow2Page+1, shopWondow2MaxPage ); + StockFontBuffer( x +66, y+92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0 ); + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for( i = 0; i < MAX_SKILL_SHOP_SKILL; i++ ) + { + if( strlen( sealSkill[j+i].name ) == 0 ) + continue; + + color = itemColor[0]; + + if( sealSkill[j+i].price > pc.gold ) + { + color = itemColor[1]; + } + + StockFontBuffer( x+34, y+118+i*21, + FONT_PRIO_FRONT, color, sealSkill[j+i].name, 0 ); + + sprintf_s( tmsg, "%8dS", sealSkill[j+i].price ); + StockFontBuffer( x+312, y+118+i*21, + FONT_PRIO_FRONT, color, tmsg, 0 ); + } + + if( focusId >= 0 ) + { + // 秀ICON + StockDispBuffer( x+58, y+340, DISP_PRIO_IME3, sealSkill[focusId].icon, 0 ); + + for( i = 0; i < sizeof( sealSkill[0].info )/sizeof( sealSkill[0].info[0] ); i++ ) + { + StockFontBuffer( x+120, y+308+i*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + sealSkill[focusId].info[i], 0 ); + + } + } + + btnId[2] = StockDispBuffer( x+216, y+402, DISP_PRIO_IME3, CG_EXIT_BTN, 2 ); + + StockDispBuffer( x+w/2, y+h/2, DISP_PRIO_MENU, CG_SKILLSHOP_WIN, 1 ); + } + } + + return ret; +} + + +int profession_windows_2( void ) +{ + static int x, y, w, h; + static int btnId[2]; + static char msg1[128]; + int id; + int i; + int ret = 0; + + if( skillShopWindow4ProcNo == 0 ) + { + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + + // ?????? + w = 8; + h = 2; + x = (lpDraw->xSize-w*64)/2; + y = (lpDraw->ySize-h*48)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + + char name[32]; + if( strlen( pc.freeName ) > 0 ) + { + strcpy( name, pc.freeName ); + } + else + { + strcpy( name, pc.name ); + } + + sprintf_s( msg1, "让[%s]将[%s]", name, + sealSkill[selShopSkillNo].name ); + + skillShopWindow4ProcNo++; + } + + + if( ptActMenuWin != NULL ) + { + id = -1; + if( ptActMenuWin->hp >= 1 ) + { + // ???? + id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + } + + // ????????????????????? + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + wnCloseFlag = 0; + } + + + if( id >= 0 ) + { + if( id == 0 ) + { + ret = 1; + } + else + if( id == 1 ) + { + ret = 2; + } + else + if( id == 100 ) + { + ret = 100; + } + + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + if( ret == 100 + || ret == 1 ) + { + windowTypeWN = -1; + } + return ret; + } + + + if( ptActMenuWin->hp >= 1 ) + { + // ?????? + StockFontBuffer( x+20, y+20+0*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + msg1, 0 ); + StockFontBuffer( x+20, y+20+1*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "学起来吗?", 0 ); + + btnId[0] = StockDispBuffer( x+w*64/3, y+72, DISP_PRIO_IME3, CG_YES_BTN, 2 ); + btnId[1] = StockDispBuffer( x+w*64/3*2, y+72, DISP_PRIO_IME3, CG_NO_BTN, 2 ); + } + } + + return ret; +} + + +#endif + + +#ifdef _NPC_WELFARE_2 // WON ADD 职业NPC-2 +void initServerWindowProfession2( char *data ) +{ + char title1[128]; + char msg2[128]; + char skillName[64]; + char info[256]; + int i, j; + int flag; + + skillShopWindowProcNo = 0; + shopWondow2Page = 0; + + if( getIntegerToken( data, '|', 1 ) == 0 ) + return; + + getStringToken( data, '|', 2, sizeof( title1 )-1, title1 ); + makeStringFromEscaped( title1 ); + getStringToken( data, '|', 3, sizeof( msg2 )-1, msg2 ); + makeStringFromEscaped( msg2 ); + + strncpy_s( ProfessionShopTitle2, title1, sizeof( ProfessionShopTitle2 )-1 ); + ProfessionShopTitle2[sizeof( ProfessionShopTitle2 )-1] = '\0'; + + getStrSplit( (char *)ProfessionShopMsg2, msg2, + sizeof( ProfessionShopMsg2[0] ), + sizeof( ProfessionShopMsg2 )/sizeof( ProfessionShopMsg2[0] ), + sizeof( ProfessionShopMsg2[0] )-1 ); + + shopWondow2MaxPage = MAX_SKILL_SHOP_SKILL* 9; + + for( i = 0, j = 0; i < shopWondow2MaxPage; i++ ) + { + // 技能名称 + flag = getStringToken( data, '|', 4+i*4, sizeof( skillName )-1, skillName ); + makeStringFromEscaped( skillName ); + if( flag ) + { + sealSkill[i].name[0] = '\0'; + continue; + } + + j++; + + if( strlen( skillName ) <= SKILL_NAME_LEN ) + strcpy( sealSkill[i].name, skillName ); + else + strcpy( sealSkill[i].name, "???" ); + + // 金额 + sealSkill[i].price = getIntegerToken( data, '|', 5+i*4 ); + + // 说明 + getStringToken( data, '|', 6+i*4, sizeof( info )-1, info ); + makeStringFromEscaped( info ); + getStrSplit( (char *)(&sealSkill[i].info), info, + sizeof( sealSkill[0].info[0] ), + sizeof( sealSkill[0].info )/sizeof( sealSkill[0].info[0] ), + sizeof( sealSkill[0].info[0] )-1 ); + + // 图示 + sealSkill[i].icon = getIntegerToken( data, '|', 7+i*4 ); + + } + if( j > 0 ) + { + shopWondow2MaxPage = (j+7)/MAX_SKILL_SHOP_SKILL; + } + else + { + shopWondow2MaxPage = 1; + } +} + +void profession_windows2( void ) +{ + int ret; + + if( skillShopWindowProcNo == 0 ) + { + initSkillShopWindow1(); + skillShopWindowProcNo++; + play_se( 202, 320, 240 ); + } + if( skillShopWindowProcNo == 1 ) + { + ret = profession_windows_12(); + if( ret == 2 ) + { + skillShopWindowProcNo = 10; + } + } + if( skillShopWindowProcNo == 10 ){ + initSkillShopWindow4(); + skillShopWindowProcNo++; + play_se( 202, 320, 240 ); + } + if( skillShopWindowProcNo == 11 ){ + ret = profession_windows_22(); + if( ret == 1 ){ + + char data[256]; + char msg[256]; + sprintf_s( data, "%d|%d", + selShopSkillNo+1, + sealSkill[selShopSkillNo].price ); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, 0, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, 0, msg ) ; + + pc.gold -= sealSkill[selShopSkillNo].price; + + windowTypeWN = -1; + }else if( ret == 2 ){ + skillShopWindowProcNo = 0; + } + } + +} + + +int profession_windows_12( void ) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if( skillShopWindow1ProcNo == 0 ) + { + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + + w = 432; + h = 428; + x = (lpDraw->xSize-w)/2; + y = (lpDraw->ySize-h)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, -1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + skillShopWindow1ProcNo++; + } + + + if( ptActMenuWin != NULL ) + { + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if( ptActMenuWin->hp >= 1 ) + { + id = selRepGraId( btnId, sizeof( btnId )/sizeof( int ) ); + pushId = pushGraId( btnId, sizeof( btnId )/sizeof( int ) ); + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for( i = 0; i < MAX_SKILL_SHOP_SKILL; i++ ) + { + if( sealSkill[j+i].name[0] != '\0' ) + { + x1 = x+32; + y1 = y+i*21+116; + x2 = x1 + 372; + y2 = y1 + 20; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ) + { + if( mouse.onceState & MOUSE_LEFT_CRICK ) + { + if( sealSkill[j+i].price <= pc.gold ) + { + selId = j+i; + } + else + { + play_se( 220, 320, 240 ); + } + } + focusId = j+i; + } + } + } + } + + if( joy_con[0] & JOY_A ) + { + pushId = 0; + if( joy_auto[0] & JOY_A ) + { + id = 0; + } + } + if( pushId == 0 ) + { + prevBtn = 1; + if( id == 0 ) + { + if( shopWondow2Page > 0 ) + { + shopWondow2Page--; + play_se( 217, 320, 240 ); + } + } + } + else + { + prevBtn = 0; + } + + if( joy_con[0] & JOY_B ) + { + pushId = 1; + if( joy_auto[0] & JOY_B ) + { + id = 1; + } + } + if( pushId == 1 ) + { + nextBtn = 1; + if( id == 1 ) + { + if( shopWondow2Page+1 < shopWondow2MaxPage ) + { + shopWondow2Page++; + play_se( 217, 320, 240 ); + } + } + } + else + { + nextBtn = 0; + } + + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + wnCloseFlag = 0; + } + + if( id >= 2 + || selId >= 0 ) + { + if( id == 2 ) + { + ret = 1; + play_se( 203, 320, 240 ); + } + else + if( id == 100 ) + { + ret = 100; + } + else + { + selShopSkillNo = selId; + ret = 2; + } + + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + if( ret == 100 + || ret == 1 ) + { + windowTypeWN = -1; + } + return ret; + } + + if( ptActMenuWin->hp >= 1 ) + { + int xx; + + xx = (w-strlen( ProfessionShopTitle2 )/2*17)/2; + StockFontBuffer( x+xx, y+18, FONT_PRIO_FRONT, FONT_PAL_WHITE, ProfessionShopTitle2, 0 ); + + for( i = 0; i < sizeof( ProfessionShopMsg2 )/sizeof( ProfessionShopMsg2[0] ); i++ ) + { + if( ProfessionShopMsg2[0] != '\0' ) + { + StockFontBuffer( x+18, y+48+i*18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + ProfessionShopMsg2[i], 0 ); + } + } + + sprintf_s( tmsg, "职业:%s 点数:%3d", pc.profession_class_name, pc.profession_skill_point ); + StockFontBuffer( x+235, y+84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0 ); + + // 页?? + btnId[0] = StockDispBuffer( x +32, y+100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2 ); + btnId[1] = StockDispBuffer( x+200, y+100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2 ); + sprintf_s( tmsg, "%2d/%2d 页", shopWondow2Page+1, shopWondow2MaxPage ); + StockFontBuffer( x +66, y+92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0 ); + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for( i = 0; i < MAX_SKILL_SHOP_SKILL; i++ ) + { + if( strlen( sealSkill[j+i].name ) == 0 ) + continue; + + color = itemColor[0]; + + if( sealSkill[j+i].price > pc.gold ) + { + color = itemColor[1]; + } + + StockFontBuffer( x+34, y+118+i*21, + FONT_PRIO_FRONT, color, sealSkill[j+i].name, 0 ); + + sprintf_s( tmsg, "熟练度:%5d", sealSkill[j+i].price ); + StockFontBuffer( x+280, y+118+i*21, + FONT_PRIO_FRONT, color, tmsg, 0 ); + } + + if( focusId >= 0 ) + { + // 秀ICON + StockDispBuffer( x+58, y+340, DISP_PRIO_IME3, sealSkill[focusId].icon, 0 ); + + for( i = 0; i < sizeof( sealSkill[0].info )/sizeof( sealSkill[0].info[0] ); i++ ) + { + StockFontBuffer( x+120, y+308+i*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + sealSkill[focusId].info[i], 0 ); + + } + } + + btnId[2] = StockDispBuffer( x+216, y+402, DISP_PRIO_IME3, CG_EXIT_BTN, 2 ); + + StockDispBuffer( x+w/2, y+h/2, DISP_PRIO_MENU, CG_SKILLSHOP_WIN, 1 ); + } + } + + return ret; +} + + +int profession_windows_22( void ) +{ + static int x, y, w, h; + static int btnId[2]; + static char msg1[128]; + int id; + int i; + int ret = 0; + + if( skillShopWindow4ProcNo == 0 ) + { + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + + // ?????? + w = 8; + h = 2; + x = (lpDraw->xSize-w*64)/2; + y = (lpDraw->ySize-h*48)/2; + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + + char name[32]; + if( strlen( pc.freeName ) > 0 ) + { + strcpy( name, pc.freeName ); + } + else + { + strcpy( name, pc.name ); + } + + sprintf_s( msg1, "要[%s]将[%s]", name, + sealSkill[selShopSkillNo].name ); + + skillShopWindow4ProcNo++; + } + + + if( ptActMenuWin != NULL ) + { + id = -1; + if( ptActMenuWin->hp >= 1 ) + { + // ???? + id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + } + + // ????????????????????? + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + wnCloseFlag = 0; + } + + + if( id >= 0 ) + { + if( id == 0 ) + { + ret = 1; + } + else + if( id == 1 ) + { + ret = 2; + } + else + if( id == 100 ) + { + ret = 100; + } + + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + if( ret == 100 + || ret == 1 ) + { + windowTypeWN = -1; + } + return ret; + } + + + if( ptActMenuWin->hp >= 1 ) + { + // ?????? + StockFontBuffer( x+20, y+20+0*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + msg1, 0 ); + StockFontBuffer( x+20, y+20+1*20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "遗忘吗?", 0 ); + + btnId[0] = StockDispBuffer( x+w*64/3, y+72, DISP_PRIO_IME3, CG_YES_BTN, 2 ); + btnId[1] = StockDispBuffer( x+w*64/3*2, y+72, DISP_PRIO_IME3, CG_NO_BTN, 2 ); + } + } + + return ret; +} + +#endif + + + + + +#ifdef _PETSKILL_CANNEDFOOD +void PetSkillShowType1(void) +{ + static int x, y, w, h; + static int btnId[1]; + int id = -1; + int i; + int ret = 0; + int x1, y1, x2, y2; + char skillName[128]; + + if (PetskillShpwWindowProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 5; + h = 6; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + PetskillShpwWindowProcNo++; + } + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1){ + if ((id = selGraId(btnId, sizeof(btnId) / sizeof(int))) < 0){ + for (i = 0; i < MAX_SKILL && i < pet[selShopSkillPetNo].maxSkill; i++){ + x1 = x + 41; + y1 = y + 33 + (i + 1) * 26; + x2 = x1 + 238; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + id = i; + } + } + } + } + else{ + id = 100; + } + + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + if (id >= 0){ + if (id == 100){ + ret = 100; + } + else{ + selShopSkillSlotNo = id; + ret = 2; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100) + { + windowTypeWN = -1; + } + else if (ret == 2){ + char data[256]; + char msg[256]; + // sprintf_s( data, "%d|%d|%d|%d", + sprintf_s(data, "%d", + // selShopSkillNo+1 + // selShopSkillPetNo, + selShopSkillSlotNo + // sealSkill[selShopSkillNo].price ); + ); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + pc.gold -= sealSkill[selShopSkillNo].price; + windowTypeWN = -1; + } + return; + } + + if (ptActMenuWin->hp >= 1){ + StockFontBuffer(x + 75, y + 33, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "要在那个位置做呢?", 0); + for (i = 0; i < MAX_SKILL && i < pet[selShopSkillPetNo].maxSkill; i++){ + sprintf_s(skillName, "技 %d: ", i + 1); + if (petSkill[selShopSkillPetNo][i].useFlag != 0){ + strcat_s(skillName, petSkill[selShopSkillPetNo][i].name); + } + StockFontBuffer(x + 46, y + 36 + (i + 1) * 26, + FONT_PRIO_FRONT, FONT_PAL_WHITE, skillName, 0); + } + btnId[0] = StockDispBuffer(x + 160, y + 256, DISP_PRIO_IME3, CG_CANCEL_BTN, 2); + } + } + return; +} +#endif + + +void initSkillShopWindow1(void) +{ + skillShopWindow1ProcNo = 0; +} + +int skillShopWindow1(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if (skillShopWindow1ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 432; + h = 428; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + skillShopWindow1ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if (ptActMenuWin->hp >= 1) + { + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for (i = 0; i < MAX_SKILL_SHOP_SKILL; i++) + { + if (sealSkill[j + i].name[0] != '\0') + { + x1 = x + 32; + y1 = y + i * 21 + 116; + x2 = x1 + 372; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (sealSkill[j + i].price <= pc.gold +#ifdef _PETKILL_COST_FAME + && sealSkill[j + i].iCoseFame <= pc.fame +#endif + ) + { + selId = j + i; + } + else + { + play_se(220, 320, 240); + } + } + focusId = j + i; + } + } + } + } + + if (joy_con[0] & JOY_A) + { + pushId = 0; + if (joy_auto[0] & JOY_A) + { + id = 0; + } + } + if (pushId == 0) + { + prevBtn = 1; + if (id == 0) + { + if (shopWondow2Page > 0) + { + shopWondow2Page--; + play_se(217, 320, 240); + } + } + } + else + { + prevBtn = 0; + } + + if (joy_con[0] & JOY_B) + { + pushId = 1; + if (joy_auto[0] & JOY_B) + { + id = 1; + } + } + if (pushId == 1) + { + nextBtn = 1; + if (id == 1) + { + if (shopWondow2Page + 1 < shopWondow2MaxPage) + { + shopWondow2Page++; + play_se(217, 320, 240); + } + } + } + else + { + nextBtn = 0; + } + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + if (id >= 2 + || selId >= 0) + { + if (id == 2) + { + ret = 1; + play_se(203, 320, 240); + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopSkillNo = selId; + ret = 2; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100 + || ret == 1) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + xx = (w - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + for (i = 0; i < sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]); i++) + { + if (shopWindow2Msg[0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow2Msg[i], 0); + } + } +#ifdef _PETKILL_COST_FAME + sprintf_s(tmsg, "声望 %8dF", pc.fame); + StockFontBuffer(x + 244, y + 64, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); +#endif + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 244, y + 84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + // 页?? + btnId[0] = StockDispBuffer(x + 32, y + 100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[1] = StockDispBuffer(x + 200, y + 100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); + sprintf_s(tmsg, "%2d/%2d 页", shopWondow2Page + 1, shopWondow2MaxPage); + StockFontBuffer(x + 66, y + 92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + j = shopWondow2Page*MAX_SKILL_SHOP_SKILL; + for (i = 0; i < MAX_SKILL_SHOP_SKILL; i++) + { + if (strlen(sealSkill[j + i].name) == 0) + continue; + + color = itemColor[0]; + + if (sealSkill[j + i].price > pc.gold) + color = itemColor[1]; +#ifdef _PETKILL_COST_FAME + if (sealSkill[j + i].iCoseFame > pc.fame) + color = itemColor[1]; +#endif + + StockFontBuffer(x + 34, y + 118 + i * 21, FONT_PRIO_FRONT, color, sealSkill[j + i].name, 0); + +#ifdef _PETKILL_COST_FAME + sprintf_s(tmsg, "%8dS", sealSkill[j + i].price); + StockFontBuffer(x + 212, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); + sprintf_s(tmsg, "%8dF", sealSkill[j + i].iCoseFame); + StockFontBuffer(x + 312, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); +#else + sprintf_s(tmsg, "%8dS", sealSkill[j + i].price); + StockFontBuffer(x + 312, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); +#endif + } + + if (focusId >= 0) + { + for (i = 0; i < sizeof(sealSkill[0].info) / sizeof(sealSkill[0].info[0]); i++) + { + StockFontBuffer(x + 27, y + 308 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + sealSkill[focusId].info[i], 0); + } + } + + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_SKILLSHOP_WIN, 1); + } + } + + return ret; +} + +short skillShopWindow2ProcNo; + +void initSkillShopWindow2(void) +{ + skillShopWindow2ProcNo = 0; +} + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ? +int skillShopWindow2(void) +{ + static int x, y, w, h; + static int btnId[1]; + int id; + int i, j; + int ret = 0; + int x1, y1, x2, y2; + int len; + + if (skillShopWindow2ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 7; + h = 5; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + skillShopWindow2ProcNo++; + } + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + + for (i = 0, j = 0; i < MAX_PET; i++) + { + // ???????????? + if (pet[i].useFlag != 0) + { + x1 = x + 41; + y1 = y + 25 + (j + 1) * 26; + x2 = x1 + 366; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id = i + 1; + } + } + j++; + } + } + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + if (id >= 0) + { + // ????? + if (id == 0) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopSkillPetNo = id; + ret = 2; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + StockFontBuffer(x + 145, y + 25, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "要让谁学呢?", 0); + for (i = 0, j = 0; i < MAX_PET; i++) + { + if (pet[i].useFlag != 0) + { + len = strlen(pet[i].freeName); + if (len > 0) + { + strcpy(msgWN[1], pet[i].freeName); + } + else + { + len = strlen(pet[i].name); + strcpy(msgWN[1], pet[i].name); + } +#if 0 + StockFontBuffer( x+88+(144-len*9)/2, y+28+(j+1)*26, +#else + StockFontBuffer(x + 62, y + 28 + (j + 1) * 26, +#endif + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + + sprintf_s(msgWN[1], "LV.%d", pet[i].level); + StockFontBuffer(x + 260, y + 28 + (j + 1) * 26, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + sprintf_s(msgWN[1], "MaxHP %d", pet[i].maxHp); + StockFontBuffer(x + 314, y + 28 + (j + 1) * 26, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0); + + j++; + } + } + btnId[0] = StockDispBuffer(x + w * 64 / 2, y + 204, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + + return ret; +} + + +// ??????? ????????? +short skillShopWindow3ProcNo; +// ??? +void initSkillShopWindow3(void) +{ + skillShopWindow3ProcNo = 0; +} + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ? +int skillShopWindow3(void) +{ + static int x, y, w, h; + static int btnId[1]; + int id; + int i; + int ret = 0; + int x1, y1, x2, y2; + char skillName[128]; + + if (skillShopWindow3ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 5; + h = 6; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + skillShopWindow3ProcNo++; + } + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + + for (i = 0; i < MAX_SKILL && i < pet[selShopSkillPetNo - 1].maxSkill; i++) + { + x1 = x + 41; + y1 = y + 33 + (i + 1) * 26; + x2 = x1 + 238; + y2 = y1 + 22; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id = i + 1; + } + } + } + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + if (id >= 0) + { + // ????? + if (id == 0) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopSkillSlotNo = id; + ret = 2; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + StockFontBuffer(x + 75, y + 33, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "要在那个位置做呢?", 0); + for (i = 0; i < MAX_SKILL && i < pet[selShopSkillPetNo - 1].maxSkill; i++) + { + sprintf_s(skillName, "技 %d: ", i + 1); + if (petSkill[selShopSkillPetNo - 1][i].useFlag != 0) + { + strcat_s(skillName, petSkill[selShopSkillPetNo - 1][i].name); + } + StockFontBuffer(x + 46, y + 36 + (i + 1) * 26, + FONT_PRIO_FRONT, FONT_PAL_WHITE, skillName, 0); + } + btnId[0] = StockDispBuffer(x + 160, y + 256, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + + return ret; +} + + +void initSkillShopWindow4(void) +{ + skillShopWindow4ProcNo = 0; +} + + +int skillShopWindow4(void) +{ + static int x, y, w, h; + static int btnId[2]; + static char msg1[128]; + int id; + int i; + int ret = 0; + + if (skillShopWindow4ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 8; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + + char name[32]; + if (strlen(pet[selShopSkillPetNo - 1].freeName) > 0) + { + strcpy(name, pet[selShopSkillPetNo - 1].freeName); + } + else + { + strcpy(name, pet[selShopSkillPetNo - 1].name); + } + + sprintf_s(msg1, "让[%s]将[%s]", name, + sealSkill[selShopSkillNo].name); + + skillShopWindow4ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 0) + { + if (id == 0) + { + ret = 1; + } + else + if (id == 1) + { + ret = 2; + } + else + if (id == 100) + { + ret = 100; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100 + || ret == 1) + { + windowTypeWN = -1; + } + return ret; + } + + + if (ptActMenuWin->hp >= 1) + { + // ?????? + StockFontBuffer(x + 20, y + 20 + 0 * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + msg1, 0); + StockFontBuffer(x + 20, y + 20 + 1 * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "学起来吗?", 0); + + btnId[0] = StockDispBuffer(x + w * 64 / 3, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + btnId[1] = StockDispBuffer(x + w * 64 / 3 * 2, y + 72, DISP_PRIO_IME3, CG_NO_BTN, 2); + } + } + + return ret; +} + + + + +#if 1 + + +// ????????? + +void initPoolShopWindow1(void); +int poolShopWindow1(void); +void initPoolShopWindow2(void); +int poolShopWindow2(void); +void initPoolShopWindow3(void); +int poolShopWindow3(void); + +void initPoolShopWindow4(void); +int poolShopWindow4(void); + + +// ?????????????? +void serverWindowType7(void) +{ + int ret; + + if (shopWindowProcNo == 0){ + initPoolShopWindow1(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 1){ + ret = poolShopWindow1(); + } + + if (shopWindowProcNo == 10){ + initPoolShopWindow2(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 11){ + ret = poolShopWindow2(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "0"); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + windowTypeWN = -1; + } + else if (ret == 2){ + shopWindowProcNo = 20; + } + } + + if (shopWindowProcNo == 20){ + initPoolShopWindow3(); + shopWindowProcNo++; + play_se(202, 320, 240); // ???????? + } + if (shopWindowProcNo == 21){ + ret = poolShopWindow3(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "%d", poolItem[selShopItemNo].tbl); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + + pc.gold -= poolItem[selShopItemNo].price; + restPoolSlot--; + if (restPoolSlot < 0) + restPoolSlot = 0; + + poolItem[selShopItemNo].name[0] = '\0'; + poolItem[selShopItemNo].info[0][0] = '\0'; + poolItem[selShopItemNo].info[1][0] = '\0'; + poolItem[selShopItemNo].info[2][0] = '\0'; +#ifdef _ITEM_PILENUMS + poolItem[selShopItemNo].num = 0; +#endif + int i, j, k; + for (i = 0; i < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE - 1; i++){ + if (poolItem[i].name[0] == '\0'){ + for (j = i + 1; j < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; j++){ + if (poolItem[j].name[0] != '\0'){ + strcpy(poolItem[i].name, poolItem[j].name); + poolItem[i].poolFlag = poolItem[j].poolFlag; + poolItem[i].level = poolItem[j].level; + poolItem[i].price = poolItem[j].price; + poolItem[i].graNo = poolItem[j].graNo; + poolItem[i].tbl = poolItem[j].tbl; +#ifdef _ITEM_PILENUMS + poolItem[i].num = poolItem[j].num; +#endif + + for (k = 0; k < 3; k++){ + strcpy(poolItem[i].info[k], poolItem[j].info[k]); + } + poolItem[j].name[0] = '\0'; + break; + } + } + } + } + for (i = 0; i < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; i++){ + if (poolItem[i].name[0] == '\0') + break; + } + if (i > 0){ + shopWondow2MaxPage = (i + 7) / MAX_POOL_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + if (shopWondow2Page >= shopWondow2MaxPage) + shopWondow2Page = shopWondow2MaxPage - 1; + + shopWindowProcNo = 10; + } + else if (ret == 2){ + shopWindowProcNo = 10; + } + } + + if (shopWindowProcNo == 100){ + initPoolShopWindow4(); + shopWindowProcNo++; + play_se(202, 320, 240); // ???????? + } + if (shopWindowProcNo == 101){ + ret = poolShopWindow4(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "0"); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + windowTypeWN = -1; + } + else if (ret == 2){ + shopWindowProcNo = 110; + } + else if (ret == 3){ + shopWindowProcNo = 120; + } + } + + if (shopWindowProcNo == 110){ + initPoolShopWindow3(); + shopWindowProcNo++; + play_se(202, 320, 240); + } + if (shopWindowProcNo == 111){ + ret = poolShopWindow3(); + if (ret == 1){ + char data[256]; + char msg[256]; + sprintf_s(data, "%d", selShopItemNo + 1); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + + poolItem[selShopItemNo].name[0] = '\0'; + poolItem[selShopItemNo].info[0][0] = '\0'; + poolItem[selShopItemNo].info[1][0] = '\0'; + poolItem[selShopItemNo].info[2][0] = '\0'; +#ifdef _ITEM_PILENUMS + poolItem[selShopItemNo].num = 0; +#endif + int i, j, k; + for (i = 0; i < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE - 1; i++){ + if (poolItem[i].name[0] == '\0'){ + for (j = i + 1; j < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; j++){ + if (poolItem[j].name[0] != '\0'){ + strcpy(poolItem[i].name, poolItem[j].name); + poolItem[i].poolFlag = poolItem[j].poolFlag; + poolItem[i].level = poolItem[j].level; + poolItem[i].price = poolItem[j].price; + poolItem[i].graNo = poolItem[j].graNo; + poolItem[i].tbl = poolItem[j].tbl; +#ifdef _ITEM_PILENUMS + poolItem[i].num = poolItem[j].num; +#endif + for (k = 0; k < 3; k++){ + strcpy(poolItem[i].info[k], poolItem[j].info[k]); + } + poolItem[j].name[0] = '\0'; + break; + } + } + } + } + for (i = 0; i < MAX_POOL_SHOP_ITEM*MAX_POOL_SHOP_PAGE; i++){ + if (poolItem[i].name[0] == '\0') + break; + } + if (i > 0){ + shopWondow2MaxPage = (i + 7) / MAX_POOL_SHOP_ITEM; + } + else{ + shopWondow2MaxPage = 1; + } + if (shopWondow2Page >= shopWondow2MaxPage) + shopWondow2Page = shopWondow2MaxPage - 1; + + shopWindowProcNo = 100; + } + else if (ret == 2){ + shopWindowProcNo = 100; + } + } +} + + +// ????????????????????? + +short poolShopWindow1ProcNo; + +// ??? +void initPoolShopWindow1(void) +{ + poolShopWindow1ProcNo = 0; +} + + +// ??? +// ??:0 ... ??? +// 1 ... ??? +// 2 ... ??? +// 3 ... ? +int poolShopWindow1(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id = 0; + int i; + int ret = 0; + + if (poolShopWindow1ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 4; + h = 3; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + poolShopWindow1ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + if (ptActMenuWin->hp >= 1) + { + // ???? + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + ret = id + 1; + } + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + ret = 3; // ?? + wnCloseFlag = 0; + } + + if (0 <= id && id <= 2) + { + char data[256]; + char msg[256]; + sprintf_s(data, "%d", ret); + makeEscapeString(data, msg, sizeof(msg)-1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + } + + if (id >= 0) + { + if (ret == 3) + { + play_se(203, 320, 240); // ???????? + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + windowTypeWN = -1; + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + xx = (w * 64 - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 12, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + xx = (w * 64 - strlen(shopWindow1Msg) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 32, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Msg, 0); + + btnId[0] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 66, DISP_PRIO_IME3, CG_SEAL_BTN, 2); + btnId[1] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 90, DISP_PRIO_IME3, CG_BUY_BTN, 2); + btnId[2] = + StockDispBuffer(x + w * 64 / 2, y + 16 / 2 + 114, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + } + } + + return ret; +} + + +// ??????????????????? + +short poolShopWindow2ProcNo; + +// ??? +void initPoolShopWindow2(void) +{ + poolShopWindow2ProcNo = 0; +} + + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ? +int poolShopWindow2(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + + if (poolShopWindow2ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + // ?????? + w = 432; + h = 428; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + poolShopWindow2ProcNo++; + } + + + if (ptActMenuWin != NULL){ + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if (ptActMenuWin->hp >= 1){ + // ???? + //id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_POOL_SHOP_ITEM; i++){ + if (poolItem[j + i].name[0] != '\0'){ + x1 = x + 32; + y1 = y + i * 21 + 116; + x2 = x1 + 372; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ????????????? + if (poolItem[j + i].price <= pc.gold + && poolItem[j + i].poolFlag == 0 + && restPoolSlot > 0){ + selId = j + i; + } + else{ + play_se(220, 320, 240); // ??? + } + } + focusId = j + i; + } + } + } + } + + + // ?????? + if (joy_con[0] & JOY_A){ + pushId = 0; + if (joy_auto[0] & JOY_A){ + id = 0; + } + } + if (pushId == 0){ + prevBtn = 1; + if (id == 0){ + if (shopWondow2Page > 0){ + shopWondow2Page--; + play_se(217, 320, 240); // ????? + } + } + } + else + { + prevBtn = 0; + } + // ??????? + if (joy_con[0] & JOY_B) + { + pushId = 1; + if (joy_auto[0] & JOY_B) + { + id = 1; + } + } + if (pushId == 1) + { + nextBtn = 1; + if (id == 1) + { + if (shopWondow2Page + 1 < shopWondow2MaxPage) + { + shopWondow2Page++; + play_se(217, 320, 240); // ????? + } + } + } + else + { + nextBtn = 0; + } + + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + // id = 0, id = 1 ?????????????? + if (id >= 2 + || selId >= 0) + { + // ????? + if (id == 2) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopItemNo = selId; + ret = 2; + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + // ???????? + xx = (w - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + // ????????? + if (restPoolSlot > 0) + { + for (i = 0; i < sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]); i++) + { + if (shopWindow2Msg[i][0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow2Msg[i], 0); + } + } + } + else + { + for (i = 0; i < sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]); i++) + { + if (shopWindow4Msg[i][0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow4Msg[i], 0); + } + } + } + + + // ??? + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 244, y + 84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + // 页?? + btnId[0] = StockDispBuffer(x + 32, y + 100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[1] = StockDispBuffer(x + 200, y + 100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); + sprintf_s(tmsg, "%2d/%2d 页", shopWondow2Page + 1, shopWondow2MaxPage); + StockFontBuffer(x + 66, y + 92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++) + { + // ??????????? + if (strlen(poolItem[j + i].name) == 0) + continue; + + // ??????? + color = itemColor[0]; + // ????????????????? + if (poolItem[j + i].poolFlag) + color = itemColor[1]; + // ???????? + if (poolItem[j + i].price > pc.gold) + { + color = itemColor[1]; + } + // ???????????? + if (restPoolSlot <= 0) + { + color = itemColor[1]; + } + + // ???? + StockFontBuffer(x + 34, y + 118 + i * 21, + FONT_PRIO_FRONT, color, poolItem[j + i].name, 0); +#ifdef _ITEM_PILENUMS + sprintf_s(tmsg, "x%d", poolItem[j + i].num); + StockFontBuffer(x + 34 + 250, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); +#endif + // ?? + sprintf_s(tmsg, "%8dS", poolItem[j + i].price); + StockFontBuffer(x + 312, y + 118 + i * 21, + FONT_PRIO_FRONT, color, tmsg, 0); + } + + if (focusId >= 0) + { + // ?????? + StockDispBuffer(x + 64, y + 350, DISP_PRIO_IME3, poolItem[focusId].graNo, 0); + + for (i = 0; i < sizeof(sealItem[0].info) / sizeof(poolItem[0].info[0]); i++) + { + //  + StockFontBuffer(x + 120, y + 308 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + poolItem[focusId].info[i], 0); + } + } + + // ????? + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + + // ????? + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_WIN, 1); + } + } + + return ret; +} + + +// ????????????????? +short poolShopWindow3ProcNo; + +// ??? +void initPoolShopWindow3(void) +{ + poolShopWindow3ProcNo = 0; +} + + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ??? +int poolShopWindow3(void) +{ + static int x, y, w, h; + static int btnId[2]; + int id; + int i; + int ret = 0; + + if (poolShopWindow3ProcNo == 0){ + for (i = 0; i < sizeof(btnId) / sizeof(int); i++){ + btnId[i] = -2; + } + w = 6; + h = 2; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + poolShopWindow3ProcNo++; + } + + + if (ptActMenuWin != NULL){ + id = -1; + if (ptActMenuWin->hp >= 1) { + id = selGraId(btnId, sizeof(btnId) / sizeof(int)); + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + id = 100; + wnCloseFlag = 0; + } + + + if (id >= 0){ + if (id == 0){ + ret = 1; + } + else + if (id == 1){ + ret = 2; + } + else + if (id == 100){ + ret = 100; + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100){ + windowTypeWN = -1; + } + return ret; + } + if (ptActMenuWin->hp >= 1){ + for (i = 0; i < sizeof(shopWindow5Msg) / sizeof(shopWindow5Msg[0]); i++) { + if (shopWindow5Msg[i][0] != '\0'){ + StockFontBuffer(x + 20, y + 20 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow5Msg[i], 0); + } + } + + btnId[0] = StockDispBuffer(x + 128, y + 72, DISP_PRIO_IME3, CG_YES_BTN, 2); + btnId[1] = StockDispBuffer(x + 256, y + 72, DISP_PRIO_IME3, CG_NO_BTN, 2); + } + } + + return ret; +} + +short poolShopWindow4ProcNo; + +// ??? +void initPoolShopWindow4(void) +{ + poolShopWindow4ProcNo = 0; +} + + +// ??? +// ??:0 ... ??? +// 1 ... ?? +// 2 ... ? +// 3 ... ????????? +int poolShopWindow4(void) +{ + static int x, y, w, h; + static int btnId[3]; + int id; + int pushId; + int focusId; + int selId; + int i, j; + int ret = 0; + char tmsg[256]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + int color; + int prevBtn, nextBtn; + int x1, y1, x2, y2; + short itemMaxFlag; + + if (poolShopWindow4ProcNo == 0) + { + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + // ?????? + w = 432; + h = 428; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + poolShopWindow4ProcNo++; + } + + + if (ptActMenuWin != NULL) + { + id = -1; + pushId = -1; + focusId = -1; + selId = -1; + + if (ptActMenuWin->hp >= 1) + { + // ?????????????? + for (i = MAX_ITEMSTART, j = 0; i < MAX_ITEM; i++) + { + if (pc.item[i].useFlag) + { + j++; + } + } + itemMaxFlag = 0; + if (j >= MAX_ITEM - MAX_ITEMSTART) + itemMaxFlag = 1; + + // ???? + //id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + id = selRepGraId(btnId, sizeof(btnId) / sizeof(int)); + pushId = pushGraId(btnId, sizeof(btnId) / sizeof(int)); + + j = shopWondow2Page*MAX_POOL_SHOP_ITEM; + for (i = 0; i < MAX_POOL_SHOP_ITEM; i++) + { + if (poolItem[j + i].name[0] != '\0') + { + x1 = x + 32; + y1 = y + i * 21 + 116; + x2 = x1 + 372; + y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (poolItem[j + i].poolFlag == 0 + && !itemMaxFlag) + { + selId = j + i; + } + else + { + play_se(220, 320, 240); // ??? + } + } + focusId = j + i; + } + } + } + } + + + // ?????? + if (joy_con[0] & JOY_A) + { + pushId = 0; + if (joy_auto[0] & JOY_A) + { + id = 0; + } + } + if (pushId == 0) + { + prevBtn = 1; + if (id == 0) + { + if (shopWondow2Page > 0) + { + shopWondow2Page--; + play_se(217, 320, 240); // ????? + } + } + } + else + { + prevBtn = 0; + } + // ??????? + if (joy_con[0] & JOY_B) + { + pushId = 1; + if (joy_auto[0] & JOY_B) + { + id = 1; + } + } + if (pushId == 1) + { + nextBtn = 1; + if (id == 1) + { + if (shopWondow2Page + 1 < shopWondow2MaxPage) + { + shopWondow2Page++; + play_se(217, 320, 240); // ????? + } + } + } + else + { + nextBtn = 0; + } + + + // ????????????????????? + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + wnCloseFlag = 0; + } + + // id = 0, id = 1 ?????????????? + if (id >= 2 + || selId >= 0) + { + // ????? + if (id == 2) + { + ret = 1; + } + else + if (id == 100) + { + ret = 100; + } + else + { + selShopItemNo = selId; +#if 0 + if( ????????? ) + { + ret = 3; + } + else +#endif + { + ret = 2; + } + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + if (ret == 100 + || ret == 1) + { + windowTypeWN = -1; + } + return ret; + } + + if (ptActMenuWin->hp >= 1) + { + int xx; + + // ???????? + xx = (w - strlen(shopWindow1Title) / 2 * 17) / 2; + StockFontBuffer(x + xx, y + 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, shopWindow1Title, 0); + + // ????????? + if (!itemMaxFlag) + { + for (i = 0; i < sizeof(shopWindow2Msg) / sizeof(shopWindow2Msg[0]); i++) + { + if (shopWindow2Msg[0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow2Msg[i], 0); + } + } + } + else + { + for (i = 0; i < sizeof(shopWindow4Msg) / sizeof(shopWindow4Msg[0]); i++) + { + if (shopWindow4Msg[0] != '\0') + { + StockFontBuffer(x + 18, y + 48 + i * 18, FONT_PRIO_FRONT, FONT_PAL_WHITE, + shopWindow4Msg[i], 0); + } + } + } + + + // ??? + sprintf_s(tmsg, "金钱 %8dS", pc.gold); + StockFontBuffer(x + 244, y + 84, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + // 页?? + btnId[0] = StockDispBuffer(x + 32, y + 100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[1] = StockDispBuffer(x + 200, y + 100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); + sprintf_s(tmsg, "%2d/%2d 页", shopWondow2Page + 1, shopWondow2MaxPage); + StockFontBuffer(x + 66, y + 92, FONT_PRIO_FRONT, FONT_PAL_WHITE, tmsg, 0); + + j = shopWondow2Page*MAX_SHOP_ITEM; + for (i = 0; i < MAX_SHOP_ITEM; i++){ + if (strlen(poolItem[j + i].name) == 0) + continue; + + color = itemColor[0]; + if (poolItem[j + i].poolFlag) + color = itemColor[1]; + if (itemMaxFlag) + color = itemColor[1]; + StockFontBuffer(x + 34, y + 118 + i * 21, + FONT_PRIO_FRONT, color, poolItem[j + i].name, 0); + +#ifdef _ITEM_PILENUMS + char tmsg[256]; + sprintf_s(tmsg, "x%d", poolItem[j + i].num); + StockFontBuffer(x + 34 + 250, y + 118 + i * 21, FONT_PRIO_FRONT, color, tmsg, 0); +#endif + } + + if (focusId >= 0){ + StockDispBuffer(x + 64, y + 350, DISP_PRIO_IME3, poolItem[focusId].graNo, 0); + + for (i = 0; i < sizeof(poolItem[0].info) / sizeof(poolItem[0].info[0]); i++){ + StockFontBuffer(x + 120, y + 308 + i * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, + poolItem[focusId].info[i], 0); + } + } + + if (buyOffFlag == 0){ + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + else{ + btnId[2] = StockDispBuffer(x + 216, y + 402, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + } + StockDispBuffer(x + w / 2, y + h / 2, DISP_PRIO_MENU, CG_ITEMSHOP_WIN, 1); + } + } + + return ret; +} + + + +#endif + + + + +// ?????? +int produce_logout() +{ + switch (produce_vct_no){ + case 0: + // ???????????? + CopyBackBuffer(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + // ??????????? + fade_out_bgm(); + // ???????? + NowTime = TimeGetTime(); + produce_vct_no++; + // ??????? + InitMenu(); + break; + case 1: + // ?? + if (DrawProduce(PRODUCE_BRAN_SMALL) == TRUE){ + BackBufferDrawType = DRAW_BACK_NORMAL; + // ???????????? + PaletteChange(DEF_PAL, 0); + return 1; //?? + } + // MenuProc(); // ?????? + // ImeProc(); // ??????? + break; + } + return 0; //?? +} + + + + +void StockDispHLine(int x, int y, int width) +{ + int i = 0; + for (i = 0; i < width; i++) + StockDispBuffer(x + 32 + (i * 64), y + 24, DISP_PRIO_IME3, 26022, 0); +} + +void StockDispVLine(int x, int y, int height) +{ + int i = 0; + for (i = 0; i < height; i++) + StockDispBuffer(x + 32, y + 24 + (i * 48), DISP_PRIO_IME3, 26024, 0); +} + +// Robin 0521 Family Add +static ACTION *pActPet10; +static int familyPetIndex = 0; +static char familyName[STR_BUFFER_SIZE]; +int familyElf = 2; +STR_BUFFER familyNameInput; +STR_BUFFER familyRuleInput; +STR_BUFFER familyRuleShow; + + +static char familySpriteName[3][10] = { + "光明精灵", + "黑暗精灵", + " ", +}; + +/* +static char StrYesNo[2][10] = { +"N O", +"YES", +}; +*/ +static int joinflg = 1; + +// Robin 0518 Family +void initFamilyAddWN(char *data) +{ + makeStringFromEscaped(data); + DeathAction(pActPet10); + pActPet10 = NULL; + familyElf = 2; +} + +void closeFamilyAddWN(void) +{ + play_se(203, 320, 240); + DeathAction(ptActMenuWin); + DeathAction(pActPet10); + pActPet10 = NULL; + ptActMenuWin = NULL; + windowTypeWN = -1; + GetKeyInputFocus(&MyChatBuffer); +} + +#ifdef _FAMILYBADGE_ +int 徽章数据[200]; +int 徽章个数; +#endif + +void familyAddWN(void) +{ + static int x = 0, y = 0, w = 0, h = 0; + static int btnId[5]; + static int fontId[6]; + static int prevBtn = 0, nextBtn = 0; + static int Inputforce = 0; +#ifdef _FAMILYBADGE_ + static int 徽章窗口; + static int 徽章索引; + int 徽章总页数; + static int 徽章当前页; +#endif + char buf[1024], buf2[1024], buf3[1024]; + + int selBtnId; + int selFontBtnId; + int i; + int ret = 0; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int itemColor[] = { FONT_PAL_WHITE, FONT_PAL_GRAY, FONT_PAL_RED }; + + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + closeFamilyAddWN(); + return; + } + + + // ???? + if (ptActMenuWin == NULL) + { + //initSkillShopWindow1(); + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } +#ifdef _FAMILYBADGE_ + 徽章窗口 = FALSE; + 徽章索引 = -1; + 徽章个数 = 0; + 徽章当前页 = 0; + memset(徽章数据, -1, 4 * 200); + extern unsigned int sockfd; + lssproto_FamilyBadge_send(sockfd); +#endif + w = 571; h = 295; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + + Inputforce = 0; + + familyRuleInput.buffer[0] = NULL; + familyRuleInput.cnt = 0; + familyRuleInput.cursor = 0; + familyRuleInput.len = 120; + familyRuleInput.lineLen = 46; + familyRuleInput.lineDist = 30; + familyRuleInput.color = 0; + familyRuleInput.x = x + 82; + familyRuleInput.y = y + 160; + familyRuleInput.fontPrio = FONT_PRIO_FRONT; + + familyNameInput.buffer[0] = NULL; + familyNameInput.cnt = 0; + familyNameInput.cursor = 0; + familyNameInput.len = 16; + familyNameInput.color = 0; + familyNameInput.x = x + 1000; + familyNameInput.y = y + 40; + familyNameInput.fontPrio = FONT_PRIO_FRONT; + + + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + play_se(202, 320, 240); // ???????? + + } + else if (ptActMenuWin->hp >= 1) + { +#ifdef _FAMILYBADGE_ + 徽章总页数 = 徽章个数 % 12 ? 徽章个数 / 12 + 1 : 徽章个数 / 12; +#endif + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + selFontBtnId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + switch (selBtnId) + { + case 0: + if (徽章索引 == -1){ + StockChatBufferLine("请选择家族徽章!", FONT_PAL_WHITE); + break; + } + if (!familyNameInput.buffer[0]) { + StockChatBufferLine("请输入家族名称!", FONT_PAL_WHITE); + break; + } + if (!familyRuleInput.buffer[0]) { + StockChatBufferLine("请输入家族主旨!", FONT_PAL_WHITE); + break; + } + if (familyElf == 2) { + StockChatBufferLine("请选择守护精灵!", FONT_PAL_WHITE); + break; + } + if (pet[familyPetIndex].useFlag == NULL) { + StockChatBufferLine("请选择家族守护兽!", FONT_PAL_WHITE); + break; + } + makeEscapeString(familyNameInput.buffer, buf2, sizeof(buf2)); + makeEscapeString(familyRuleInput.buffer, buf3, sizeof(buf3)); + sprintf_s(buf, "A|%s|%d|%d|%s|%d" + , buf2, familyPetIndex, familyElf, buf3, 徽章索引); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeFamilyAddWN(); + return; + break; + case 1: + closeFamilyAddWN(); + return; + break; + case 2: + prevBtn = TRUE; + i = 0; + while (1) { + familyPetIndex--; + if (familyPetIndex <0) familyPetIndex = 4; + if (pet[familyPetIndex].useFlag != NULL) + break; + if ((i++) >5) { + familyPetIndex = -1; + break; + } + } + if (pActPet10 != NULL) { + DeathAction(pActPet10); + pActPet10 = NULL; + } + break; + case 3: + nextBtn = TRUE; + i = 0; + while (1) { + familyPetIndex++; + if (familyPetIndex >= 5) familyPetIndex = 0; + if (pet[familyPetIndex].useFlag != NULL) + break; + if ((i++) > 5) { + familyPetIndex = -1; + break; + } + } + if (pActPet10 != NULL) { + DeathAction(pActPet10); + pActPet10 = NULL; + } + + break; + + } + switch (selFontBtnId) + { + case 0: + Inputforce = 1; + break; + case 1: + if (familyElf == 0) familyElf = 1; + else familyElf = 0; + break; + case 2: + Inputforce = 2; + break; + } + } + + if (mouse.state & MOUSE_LEFT_CRICK && prevBtn == TRUE) + prevBtn = TRUE; + else prevBtn = FALSE; + + if (mouse.state & MOUSE_LEFT_CRICK && nextBtn == TRUE) + nextBtn = TRUE; + else nextBtn = FALSE; + + btnId[0] = StockDispBuffer(x + 90, y + 274, DISP_PRIO_IME3, CG_OK_BTN, 2); + btnId[1] = StockDispBuffer(x + 270, y + 274, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + btnId[2] = StockDispBuffer(x + 435, y + 270, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[3] = StockDispBuffer(x + 495, y + 270, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); +#ifdef _FAMILYBADGE_ + fontId[5] = StockFontBuffer(x + 170, y + 135, FONT_PRIO_FRONT, FONT_PAL_RED, "设置徽章", 2); + if (徽章索引 != -1) StockDispBuffer(x + 130, y + 139, DISP_PRIO_IME4, 徽章数据[徽章索引], 0); + if (mouse.onceState & MOUSE_LEFT_CRICK) + if (HitFontNo == fontId[5]) 徽章窗口 = !徽章窗口; + if (徽章窗口){ + StockDispBuffer(x + 290, y + 335, DISP_PRIO_MENU, 55232, 1); + int 按钮ID = StockDispBuffer(x + 28, y + 333, DISP_PRIO_IME3, 55243, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + if (徽章当前页) 徽章当前页--; + } + } + 按钮ID = StockDispBuffer(x + 550, y + 333, DISP_PRIO_IME3, 55244, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + if (徽章当前页 != 徽章总页数 - 1) 徽章当前页++; + } + } + int i = 0; + for (; i < 12; i++){ + if (徽章数据[i + 徽章当前页 * 12] != -1){ + 按钮ID = StockDispBuffer(x + 70 + i * 40, y + 333, DISP_PRIO_IME3, 55245, 2); + StockDispBuffer(x + 70 + i * 40, y + 333, DISP_PRIO_IME4, 徽章数据[i + 徽章当前页 * 12], 0); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + 徽章索引 = i + 徽章当前页 * 12; + 徽章窗口 = FALSE; + } + } + } + else break; + } + } +#endif + // 家族名称: + fontId[0] = StockFontBuffer(x + 100, y + 40, FONT_PRIO_FRONT, FONT_PAL_WHITE, " ", 2); + // 族长名称: + StockFontBuffer(x + 100, y + 70, FONT_PRIO_FRONT, FONT_PAL_WHITE, pc.name, 0); + // 人数 + StockFontBuffer(x + 100, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, "无", 0); + // pet + if (pet[familyPetIndex].useFlag != NULL) + if (pet[familyPetIndex].freeName[0] == NULL) + sprintf_s(buf, " %s", pet[familyPetIndex].name); + else + sprintf_s(buf, " %s", pet[familyPetIndex].freeName); + else + sprintf_s(buf, ""); + StockFontBuffer(x + 436, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + + // sprite + sprintf_s(buf, " %s ", familySpriteName[familyElf]); + fontId[1] = StockFontBuffer(x + 436, y + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 2); + + // rule + sprintf_s(buf, "%38s", ""); + fontId[2] = StockFontBuffer(x + 82, y + 162, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 2); + + familyNameInput.x = x + 100; + familyNameInput.y = y + 40; + familyRuleInput.x = x + 82; + familyRuleInput.y = y + 162; + + if (Inputforce == 1) { + StockFontBuffer2(&familyNameInput); + GetKeyInputFocus(&familyNameInput); + if (familyRuleInput.buffer[0] != NULL) + StockFontBufferFamily(&familyRuleInput); + } + else if (Inputforce == 2) { + StockFontBufferFamily(&familyRuleInput); + GetKeyInputFocus(&familyRuleInput); + if (familyNameInput.buffer[0] != NULL) + StockFontBuffer2(&familyNameInput); + } + else { + GetKeyInputFocus(&MyChatBuffer); + if (familyRuleInput.buffer[0] != NULL) + StockFontBufferFamily(&familyRuleInput); + if (familyNameInput.buffer[0] != NULL) + StockFontBuffer2(&familyNameInput); + } + if (pActPet10 == NULL && (pet[familyPetIndex].useFlag != NULL)) + pActPet10 = MakeAnimDisp(x + 460, y + 240, pet[familyPetIndex].graNo, 0); + StockDispBuffer(x + 312, y + 79, DISP_PRIO_IME3, pc.faceGraNo, 0); + StockDispBuffer(x + 286, y + 148, DISP_PRIO_IME3, CG_FAMILY_DETAIL_WIN, 1); + } +} + + + + + +static short familyListProcNo = 0; +static int pagenum = 0; +static int familytotal = 0; +static int familynum = 0; +static ACTION *pActPet11; +typedef struct { + int index; + int tempindex; + char name[512]; + char leadername[512]; + int popu; + int DP; + int setupflag; + int acceptflag; +} TfamilyList; + +static TfamilyList familyList[10]; + +void closeFamilyList(void) +{ + play_se(203, 320, 240); // ???????? + familyListProcNo = 0; + windowTypeWN = -1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + DeathAction(pActPet11); + pActPet11 = NULL; + //GetKeyInputFocus( &MyChatBuffer ); +} + +void initFamilyList(char* data) +{ + int i = 0, j = 0; + char familybuf[128]; + char ibuf[16]; + + familyListProcNo = 1; + + if (windowTypeWN != WINDOW_MESSAGETYPE_FAMILYJOIN) + { + windowTypeWN = WINDOW_MESSAGETYPE_FAMILYJOIN; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + + for (i = 0; i < 10; i++) + { + familyList[i].index = -1; + familyList[i].name[0] = NULL; + familyList[i].leadername[0] = NULL; + familyList[i].popu = 0; + familyList[i].DP = 0; + familyList[i].tempindex = -1; + familyList[i].setupflag = 0; + familyList[i].acceptflag = 0; + } + + getStringToken(data, '|', 3, sizeof(ibuf)-1, ibuf); + familytotal = atoi(ibuf); + getStringToken(data, '|', 4, sizeof(ibuf)-1, ibuf); + pagenum = atoi(ibuf); + //makeStringFromEscaped( pagenum ); + getStringToken(data, '|', 5, sizeof(ibuf)-1, ibuf); + familynum = atoi(ibuf); + //makeStringFromEscaped( familynum ); + + + for (i = 0; i < familynum; i++) + { + getStringToken(data, '|', 6 + i, sizeof(familybuf)-1, familybuf); + + + getStringToken(familybuf, ' ', 1, sizeof(ibuf)-1, ibuf); + familyList[i].index = atoi(ibuf); + + getStringToken(familybuf, ' ', 2, sizeof(familyList[i].name) - 1, familyList[i].name); + makeStringFromEscaped(familyList[i].name); + + getStringToken(familybuf, ' ', 3, sizeof(familyList[i].leadername) - 1, familyList[i].leadername); + makeStringFromEscaped(familyList[i].leadername); + + getStringToken(familybuf, ' ', 5, sizeof(ibuf)-1, ibuf); + familyList[i].popu = atoi(ibuf); + + getStringToken(familybuf, ' ', 4, sizeof(ibuf)-1, ibuf); + familyList[i].DP = atoi(ibuf); + + getStringToken(familybuf, ' ', 6, sizeof(ibuf)-1, ibuf); + familyList[i].tempindex = atoi(ibuf); + + getStringToken(familybuf, ' ', 7, sizeof(ibuf)-1, ibuf); + familyList[i].setupflag = atoi(ibuf); + + getStringToken(familybuf, ' ', 8, sizeof(ibuf)-1, ibuf); + familyList[i].acceptflag = atoi(ibuf); + + } + +} + + +void familyListWN(void) +{ + //static ACTION *ptActMenuWin = NULL; + static int x, y, w, h, i, j; + static int btnId[5]; + static int fontId[12]; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + int prevBtnGraNo10[] = { CG_PREV_BTN2, CG_PREV_BTN2_DOWN }; + int nextBtnGraNo10[] = { CG_NEXT_BTN2, CG_NEXT_BTN2_DOWN }; + + static int prevBtn = 0, nextBtn = 0, prevBtn10 = 0, nextBtn10 = 0; + int selBtnId = -1; + int selFontBtnId = -1; + int ret = 0; + char buf[1024]; + char buf2[512]; + + + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + ) + { + closeFamilyList(); + /* + windowTypeWN = -1; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + */ + return; + } + + if (familyListProcNo == 10 || familyListProcNo == 20) { + familyDetailWN(); + } + + if (familyListProcNo == 1) { + if (ptActMenuWin == NULL) + { + familyListProcNo = 1; + + w = 7; h = 8; + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + play_se(202, 320, 240); // ???????? + + + } + //else if( ptActMenuWin != NULL ) + //if( familyListProcNo == 1 ) + else if (ptActMenuWin->hp >= 1) + { + + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + selFontBtnId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + switch (selBtnId) { + case 0: + windowTypeWN = -1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + case 1: + prevBtn = TRUE; + if (pagenum > 1) { + sprintf_s(buf, "S|F|%d|0", pagenum - 1); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + else { + sprintf_s(buf, "S|F|%d|0", (familytotal - 1) / 10 + 1); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + return; + break; + case 2: + nextBtn = TRUE; + if (pagenum < (familytotal - 1) / 10 + 1) { + sprintf_s(buf, "S|F|%d|0", pagenum + 1); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + else { + sprintf_s(buf, "S|F|1|0"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + return; + break; + case 3: + prevBtn10 = TRUE; + if (pagenum > 10) { + sprintf_s(buf, "S|F|%d|0", pagenum - 10); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + else { + sprintf_s(buf, "S|F|%d|0", (familytotal - 1) / 10 + 1); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + return; + break; + case 4: + nextBtn10 = TRUE; + if (pagenum < (familytotal - 1) / 10 + 1 - 9) { + sprintf_s(buf, "S|F|%d|0", pagenum + 10); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + else { + sprintf_s(buf, "S|F|1|0"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + return; + break; + + } + + if (selFontBtnId != -1) { + sprintf_s(buf, "S|D|%s|%d|%d", + makeEscapeString(familyList[selFontBtnId].name, buf2, sizeof(buf2)), + familyList[selFontBtnId].index, familyList[selFontBtnId].tempindex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + + } + + + if (mouse.state & MOUSE_LEFT_CRICK && prevBtn == TRUE) + prevBtn = TRUE; + else prevBtn = FALSE; + if (mouse.state & MOUSE_LEFT_CRICK && nextBtn == TRUE) + nextBtn = TRUE; + else nextBtn = FALSE; + if (mouse.state & MOUSE_LEFT_CRICK && prevBtn10 == TRUE) + prevBtn10 = TRUE; + else prevBtn10 = FALSE; + if (mouse.state & MOUSE_LEFT_CRICK && nextBtn10 == TRUE) + nextBtn10 = TRUE; + else nextBtn10 = FALSE; + + + StockFontBuffer(x + 190, y + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族列表", 0); +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( x+150, y+40, 2 ); +#endif + btnId[0] = StockDispBuffer(x + 220, y + 350, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + btnId[1] = StockDispBuffer(x + 16 + 60, y + 8 + 60, DISP_PRIO_IME4, prevBtnGraNo[prevBtn], 2); + btnId[2] = StockDispBuffer(x + 16 + 210, y + 8 + 60, DISP_PRIO_IME4, nextBtnGraNo[nextBtn], 2); + btnId[3] = StockDispBuffer(x + 16 + 20, y + 8 + 60, DISP_PRIO_IME4, prevBtnGraNo10[prevBtn10], 2); + btnId[4] = StockDispBuffer(x + 16 + 250, y + 8 + 60, DISP_PRIO_IME4, nextBtnGraNo10[nextBtn10], 2); + sprintf_s(buf, "%3d / %3d 页", pagenum, (familytotal - 1) / 10 + 1); + StockFontBuffer(x + 100, y + 60, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + +#ifdef _NEWFONT_ + sprintf_s(buf, " [家 族 名 称] [族 长] [人数] [家族声望]"); + StockFontBuffer(x + 25, y + 90, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); +#else + sprintf_s( buf, "%-4s %-16s %-16s %6s %10s", "", "[家 族 名 称]", "[族 长]", "[人数]", "[家族声望]" ); + StockFontBuffer( x+25, y+90, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); +#endif + + for (i = 0; i < 10; i++) { + if (familyList[i].name[0] == NULL) break; + if (familyList[i].acceptflag != 1) j = FONT_PAL_AQUA; + else if (familyList[i].setupflag != 1) j = FONT_PAL_GREEN; + else j = FONT_PAL_WHITE; +#ifdef _NEWFONT_ + char* str = " "; + + + //sprintf_s( buf, "%4d: %-16s %-16s %6d %10d", (pagenum-1)*10+1+i, familyList[i].name, familyList[i].leadername, + // familyList[i].popu, (familyList[i].DP /100)); + sprintf_s(buf, "%4d:%s", (pagenum - 1) * 10 + 1 + i, familyList[i].name); + StockFontBuffer(x + 15, y + 110 + (i * 20), FONT_PRIO_FRONT, j, buf, 0); + + StockFontBuffer(x + 240 - GetStrWidth(familyList[i].leadername) / 2, y + 110 + (i * 20), FONT_PRIO_FRONT, j, familyList[i].leadername, 0); + + sprintf_s(buf, "%d", familyList[i].popu); + StockFontBuffer(x + 335 - GetStrWidth(buf) / 2, y + 110 + (i * 20), FONT_PRIO_FRONT, j, buf, 0); + + sprintf_s(buf, "%d", (familyList[i].DP / 100)); + StockFontBuffer(x + 400 - GetStrWidth(buf) / 2, y + 110 + (i * 20), FONT_PRIO_FRONT, j, buf, 0); + + fontId[i] = StockFontBuffer(x + 15, y + 110 + (i * 20), FONT_PRIO_FRONT, j, str, 2); + +#else + sprintf_s( buf, "%4d: %-16s %-16s %6d %10d", (pagenum-1)*10+1+i, familyList[i].name, familyList[i].leadername, + familyList[i].popu, (familyList[i].DP /100)); + fontId[i] = StockFontBuffer( x+15, y+110+(i*20), FONT_PRIO_FRONT, j, buf, 2 ); +#endif + } + } + } +} + +struct { + int index; + int tempindex; + char name[20]; + char leadername[20]; + int leadergraph; + char petname[20]; + char petattr[64]; + int joinnum; + int joinflag; + char rule[130]; + int petgra; + int sprite; +#ifdef _FAMILYBADGE_ + int badgeNo; +#endif +} familyDetail; + + +static int changeData[2] = { 0, 0 }; +void initFamilyDetail(char* data) +{ + char ibuf[64]; + + if (familyListProcNo == 1) + familyListProcNo = 10; + else if (familyListProcNo == 0){ + familyListProcNo = 20; + lssproto_WN_recv(sockfd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK + , -1, -1, AnnounceBuf); + } + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + + familyRuleShow.buffer[0] = NULL; + familyRuleShow.cnt = 0; + familyRuleShow.cursor = 0; + familyRuleShow.len = 120; + familyRuleShow.lineLen = 46; + familyRuleShow.lineDist = 30; + familyRuleShow.color = 0; + //familyRuleShow.x = x+80; + //familyRuleShow.y = y+160; + familyRuleShow.fontPrio = FONT_PRIO_FRONT; + + getStringToken(data, '|', 3, sizeof(ibuf)-1, ibuf); + familyDetail.tempindex = atoi(ibuf); + getStringToken(data, '|', 4, sizeof(ibuf)-1, ibuf); + familyDetail.index = atoi(ibuf); + getStringToken(data, '|', 5, sizeof(familyDetail.name) - 1, familyDetail.name); + makeStringFromEscaped(familyDetail.name); + getStringToken(data, '|', 6, sizeof(familyDetail.leadername) - 1, familyDetail.leadername); + makeStringFromEscaped(familyDetail.leadername); + getStringToken(data, '|', 7, sizeof(ibuf)-1, ibuf); + familyDetail.leadergraph = atoi(ibuf); + getStringToken(data, '|', 8, sizeof(familyDetail.petname) - 1, familyDetail.petname); + makeStringFromEscaped(familyDetail.petname); + getStringToken(data, '|', 9, sizeof(familyDetail.petattr) - 1, familyDetail.petattr); + makeStringFromEscaped(familyDetail.petattr); + getStringToken(data, '|', 10, sizeof(ibuf)-1, ibuf); + familyDetail.joinnum = atoi(ibuf); + getStringToken(data, '|', 11, sizeof(ibuf)-1, ibuf); + familyDetail.joinflag = atoi(ibuf); + getStringToken(data, '|', 12, sizeof(familyDetail.rule) - 1, familyDetail.rule); + makeStringFromEscaped(familyDetail.rule); + strcpy(familyRuleShow.buffer, familyDetail.rule); + familyRuleShow.cnt = strlen(familyRuleShow.buffer); + familyRuleShow.cursor = strlen(familyRuleShow.buffer); + + getStringToken(data, '|', 13, sizeof(ibuf)-1, ibuf); + familyDetail.sprite = atoi(ibuf); +#ifdef _FAMILYBADGE_ + getStringToken(data, '|', 14, sizeof(ibuf)-1, ibuf); + familyDetail.badgeNo = atoi(ibuf); +#endif + getStringToken(familyDetail.petattr, ' ', 1, sizeof(ibuf)-1, ibuf); + familyDetail.petgra = atoi(ibuf); + + changeData[0] = 0; + changeData[1] = 0; +} + + +int familyDetailWN(void) +{ +#ifdef _FAMILYBADGE_ + static int 徽章窗口; + static int 徽章索引; + int 徽章总页数; + static int 徽章当前页; + static int 购买徽章窗口; + extern int 徽章价格; + static int 临时徽章索引; +#endif + static int w, h, x, y, xx, yy, i; + static int btnId[5]; + static int fontId[6]; + static int prevBtn = 0, nextBtn = 0; + static int familyPetIndex = 0; + int prevBtnGraNo[] = { CG_PREV_BTN, CG_PREV_BTN_DOWN }; + int nextBtnGraNo[] = { CG_NEXT_BTN, CG_NEXT_BTN_DOWN }; + + //static int changeData[2] = {0,0}; + int selBtnId = -1; + int selFontBtnId = -1; + char buf[1024]; + char buf2[512]; + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + ) + { + GetKeyInputFocus(&MyChatBuffer); + closeFamilyList(); + return 0; + } + + if (ptActMenuWin == NULL) + { + + //familyListProcNo = 11; + for (int i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + + w = 571; h = 295; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + //xx = 0; + //yy = 0; +#ifdef _FAMILYBADGE_ + 徽章窗口 = FALSE; + 徽章索引 = -1; + 徽章个数 = 0; + 徽章当前页 = 0; + 购买徽章窗口 = FALSE; + memset(徽章数据, -1, 4 * 200); + if ((pc.familyleader == FMMEMBER_LEADER) && (strcmp(pc.familyName, familyDetail.name) == 0)) { + extern unsigned int sockfd; + lssproto_FamilyBadge_send(sockfd); + } +#endif + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); + + familyRuleShow.x = x + 82; + familyRuleShow.y = y + 162; + + play_se(202, 320, 240); // ???????? + + } + + if (ptActMenuWin->hp >= 1) + { +#ifdef _FAMILYBADGE_ + if (!购买徽章窗口){ +#endif + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + selFontBtnId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + switch (selBtnId) { + case 0: + if (pc.familyName[0] != NULL) { + lssproto_TK_recv(sockfd, 0, "P|你已经加入其他家族了喔!", 0); + break; + } + + sprintf_s(buf, "J|%d|%d|%s|%d", + familyDetail.tempindex, familyDetail.index, + makeEscapeString(familyDetail.name, buf2, sizeof(buf2)), + familyDetail.sprite); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + familyListProcNo = 1; + closeFamilyList(); + GetKeyInputFocus(&MyChatBuffer); + return 0; + break; + case 1: + familyListProcNo = 1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + DeathAction(pActPet11); + pActPet11 = NULL; + GetKeyInputFocus(&MyChatBuffer); + return 0; + break; + + case 2: + prevBtn = TRUE; + i = 0; + while (1) { + familyPetIndex--; + if (familyPetIndex <0) familyPetIndex = 4; + if (pet[familyPetIndex].useFlag != NULL) + break; + if ((i++) >5) { + familyPetIndex = -1; + break; + } + } + if (pActPet11 != NULL) { + DeathAction(pActPet11); + pActPet11 = NULL; + } + changeData[1] = 1; + break; + case 3: + nextBtn = TRUE; + i = 0; + while (1) { + familyPetIndex++; + if (familyPetIndex >= 5) familyPetIndex = 0; + if (pet[familyPetIndex].useFlag != NULL) + break; + if ((i++) > 5) { + familyPetIndex = -1; + break; + } + } + if (pActPet11 != NULL) { + DeathAction(pActPet11); + pActPet11 = NULL; + } + changeData[1] = 1; + break; + case 4: + if ((changeData[0] == 1) && + (strcmp(familyRuleShow.buffer, familyDetail.rule) != 0)) { + sprintf_s(buf, "X|R|%s", familyRuleShow.buffer); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + + if (changeData[1] == 1) { + sprintf_s(buf, "X|P|%d", familyPetIndex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } +#ifdef _FAMILYBADGE_ + if (徽章索引 != 1) { + if (徽章数据[徽章索引] != familyDetail.badgeNo){ + sprintf_s(buf, "X|B|%d", 徽章索引); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + } +#endif + familyListProcNo = 1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + DeathAction(pActPet11); + pActPet11 = NULL; + GetKeyInputFocus(&MyChatBuffer); + return 0; + break; + + } + + switch (selFontBtnId) { + case 0: + changeData[0] = 1; + break; + } + + } +#ifdef _FAMILYBADGE_ + } +#endif + if (mouse.state & MOUSE_LEFT_CRICK && prevBtn == TRUE) + prevBtn = TRUE; + else prevBtn = FALSE; + + if (mouse.state & MOUSE_LEFT_CRICK && nextBtn == TRUE) + nextBtn = TRUE; + else nextBtn = FALSE; + + //StockFontBuffer( x+60, y+60, FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0 ); + //sprintf_s( buf, "", pagenum, (familytotal-1)/8 +1 ); + //StockFontBuffer( x+160, y+30, FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族资料", 0 ); + //StockDispHLine( x+140, y+ ); + + //sprintf_s( buf, "家族名称:%s", familyDetail.name ); + StockFontBuffer(x + 100, y + 40, FONT_PRIO_FRONT, FONT_PAL_WHITE, familyDetail.name, 0); + //sprintf_s( buf, "族长名称:%s", familyDetail.leadername ); + StockFontBuffer(x + 100, y + 70, FONT_PRIO_FRONT, FONT_PAL_WHITE, familyDetail.leadername, 0); + sprintf_s(buf, "%d 人", familyDetail.joinnum); + StockFontBuffer(x + 100, y + 100, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + + +#ifdef _FAMILYBADGE_ + if (徽章索引 != -1) StockDispBuffer(x + 130, y + 139, DISP_PRIO_IME4, 徽章数据[徽章索引], 0); + else StockDispBuffer(x + 130, y + 139, DISP_PRIO_IME4, familyDetail.badgeNo, 0); +#endif + // 家族主旨 + sprintf_s(buf, "%38s", ""); +#ifdef _FMVER21 + if ((pc.familyleader == FMMEMBER_LEADER) && (strcmp(pc.familyName, familyDetail.name) == 0)) { +#else + if( (pc.familyleader == 1) && ( strcmp( pc.familyName, familyDetail.name) ==0) ) { +#endif + fontId[0] = StockFontBuffer(x + 82, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 2); + btnId[2] = StockDispBuffer(x + 435, y + 270, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2); + btnId[3] = StockDispBuffer(x + 495, y + 270, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2); +#ifdef _FAMILYBADGE_ + int 按钮ID; + 徽章总页数 = 徽章个数 % 12 ? 徽章个数 / 12 + 1 : 徽章个数 / 12; + fontId[5] = StockFontBuffer(x + 170, y + 135, FONT_PRIO_FRONT, FONT_PAL_RED, "设置徽章", 2); + if (!购买徽章窗口){ + if (mouse.onceState & MOUSE_LEFT_CRICK) + if (HitFontNo == fontId[5]) 徽章窗口 = !徽章窗口; + } + if (徽章窗口){ + StockDispBuffer(x + 290, y + 335, DISP_PRIO_MENU, 55232, 1); + 按钮ID = StockDispBuffer(x + 28, y + 333, DISP_PRIO_IME3, 55243, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + if (徽章当前页) 徽章当前页--; + } + } + 按钮ID = StockDispBuffer(x + 550, y + 333, DISP_PRIO_IME3, 55244, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + if (徽章当前页 != 徽章总页数 - 1) 徽章当前页++; + } + } + int i = 0; + for (; i < 12; i++){ + if (徽章数据[i + 徽章当前页 * 12] != -1){ + 按钮ID = StockDispBuffer(x + 70 + i * 40, y + 333, DISP_PRIO_IME3, 55245, 2); + StockDispBuffer(x + 70 + i * 40, y + 333, DISP_PRIO_IME4, 徽章数据[i + 徽章当前页 * 12], 0); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + 临时徽章索引 = i + 徽章当前页 * 12; + 徽章窗口 = FALSE; + 购买徽章窗口 = TRUE; + } + } + } + else break; + } + } + if (购买徽章窗口){ + StockDispBuffer(x + 280, y + 340, DISP_PRIO_IME3, 40060, 1); + char token[125]; + sprintf_s(token, "更换徽章将收取%d金币!", 徽章价格); + StockFontBuffer(x + 200, y + 320, 2, 0, token, 0); + 按钮ID = StockDispBuffer(x + 220, y + 355, DISP_PRIO_IME4, 26093, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + 购买徽章窗口 = FALSE; + 徽章索引 = 临时徽章索引; + } + } + 按钮ID = StockDispBuffer(x + 340, y + 355, DISP_PRIO_IME4, 26042, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == 按钮ID){ + 购买徽章窗口 = FALSE; + } + } + } +#endif + } + else{ + StockDispBuffer(x + 130, y + 139, DISP_PRIO_IME4, familyDetail.badgeNo, 0); + fontId[0] = StockFontBuffer(x + 20, y + 160, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + } + //strcpy( familyRuleShow.buffer, familyDetail.rule ); + + if (changeData[0] == 1) { + StockFontBufferFamily(&familyRuleShow); + GetKeyInputFocus(&familyRuleShow); + } + else { + GetKeyInputFocus(&MyChatBuffer); + if (familyRuleShow.buffer[0] != NULL) + StockFontBufferFamily(&familyRuleShow); + } + + //StockFontBuffer( x+20, y+160, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + //StockFontBuffer( x+20, y+190, FONT_PRIO_FRONT, FONT_PAL_WHITE, familyDetail.rule, 0 ); + //StockFontBuffer( x+20, y+220, FONT_PRIO_FRONT, FONT_PAL_WHITE, familyDetail.rule, 0 ); + + + //sprintf_s( buf, "守 护 兽:%s", familyDetail.petname ); + if (changeData[1] == 0) + StockFontBuffer(x + 436, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, familyDetail.petname, 0); + else + StockFontBuffer(x + 436, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, pet[familyPetIndex].name, 0); + + StockFontBuffer(x + 436, y + 36, FONT_PRIO_FRONT, FONT_PAL_WHITE, + familySpriteName[familyDetail.sprite], 0); + + //fontId[0] = StockFontBuffer( x+200, y+250, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "加 入", 2 ); + //fontId[1] = StockFontBuffer( x+300, y+250, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "离 开", 2 ); + if (pc.familyName[0] == NULL && familyDetail.joinflag == 1) { + btnId[0] = StockDispBuffer(x + 90, y + 274, DISP_PRIO_IME3, CG_JOIN_BTN, 2); + btnId[1] = StockDispBuffer(x + 270, y + 274, DISP_PRIO_IME3, CG_EXIT_BTN2, 2); + } + else if ((changeData[0] == 1) || (changeData[1] == 1) || 徽章索引 != -1){ + btnId[4] = StockDispBuffer(x + 90, y + 274, DISP_PRIO_IME3, 26093, 2); + btnId[1] = StockDispBuffer(x + 270, y + 274, DISP_PRIO_IME3, CG_EXIT_BTN2, 2); + } + else + btnId[1] = StockDispBuffer(x + 180, y + 274, DISP_PRIO_IME3, CG_EXIT_BTN2, 2); + + if (pActPet11 == NULL) + if (changeData[1] == 0) + pActPet11 = MakeAnimDisp(x + 460, y + 240, familyDetail.petgra, 0); + else + pActPet11 = MakeAnimDisp(x + 460, y + 240, pet[familyPetIndex].graNo, 0); + + StockDispBuffer(x + 306, y + 76, DISP_PRIO_IME3, familyDetail.leadergraph, 0); + StockDispBuffer(x + 280, y + 145, DISP_PRIO_IME3, CG_FAMILY_DETAIL_WIN, 1); + } + return 0; + +} + +#ifdef _FMVER21 +/*---------- Shan (BEGIN) ----------*/ +/*--------- AD 2001/05/31 ---------*/ +// shan Family MemberList +void initFMWindowType(char *data) +{ + makeStringFromEscaped(data); + + selStartLine = 0; + FMdengonidex = 0; + + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 64); + + time(&FMHoldTime); + + char namebuf[32], lvbuf[8], statusbuf[32], onlinebuf[32], dpbuf[64]; + int int_status, onlineflag; + char tmp[32]; +#ifdef _FM_MODIFY + int iGSId; + char szGSname[64], szPlanetId[8]; +#endif +#ifdef _NEW_MANOR_LAW + char momentum[12] = { 0 }; +#endif + // 家族传送的行数为 11 ,前三行标题,后十行为资料(作为EVENT之用) + // 最后一行则为‘是否继续新增家族人员的选项’ + for (int i = 0; i < 11; i++){ + if (strlen(msgWN[i]) > 0){ + if (i >= selStartLine){ + if (i != 10){ + getStringToken(msgWN[i], '|', 6, sizeof(statusbuf)-1, tmp); + getStringToken(msgWN[i], '|', 7, sizeof(statusbuf)-1, statusbuf); + } + else + getStringToken(msgWN[i], '|', 3, sizeof(statusbuf)-1, statusbuf); + // 存的 INDEX -> 1~10 + FMmsgWN[i - (selStartLine - 1)] = atoi(statusbuf); + FMelderFlag[i - (selStartLine - 1)] = atoi(tmp); + getStringToken(msgWN[i], '|', 1, sizeof(tmp)-1, tmp); + FMpidWN[i - (selStartLine - 1)] = atoi(tmp); + getStringToken(msgWN[i], '|', 2, sizeof(FMnameWN[i - (selStartLine - 1)]) - 1, + FMnameWN[i - (selStartLine - 1)]); + //处理字串 + if (i<10){ + getStringToken(msgWN[i], '|', 2, sizeof(namebuf)-1, namebuf); + getStringToken(msgWN[i], '|', 3, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 4, sizeof(onlinebuf)-1, onlinebuf); + onlineflag = atoi(onlinebuf); + if (onlineflag > 0) + strcpy(onlinebuf, "OnLine"); + else + strcpy(onlinebuf, "OffLine"); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + getStringToken(msgWN[i], '|', 7, sizeof(statusbuf)-1, statusbuf); + int_status = atoi(statusbuf); + switch (int_status){ + // 已 加 入 + case FMMEMBER_MEMBER: // 一般族员 + strcpy(statusbuf, "一般族员"); + break; + case FMMEMBER_LEADER: // 家族族长 + strcpy(statusbuf, "族 长"); + break; + case FMMEMBER_ELDER: // 长老 + strcpy(statusbuf, "长 老"); + break; + /* case FMMEMBER_ELDER: // 长老 + strcpy(statusbuf, "长 老"); + break; + case FMMEMBER_INVITE: // 祭司 + strcpy(statusbuf, "祭 司"); + break; + case FMMEMBER_BAILEE: // 财务长 + strcpy(statusbuf, "财 务 长"); + break;*/ + case FMMEMBER_APPLY: // 申请加入 + strcpy(statusbuf, "申请加入"); + break; + /* case FMMEMBER_VICELEADER: // 副族长 + strcpy(statusbuf, "副 族 长"); + break;*/ + default: // 退 出 + strcpy(statusbuf, "退 出"); + break; + } +#ifdef _FM_MODIFY + // 处理星球名称 + getStringToken(msgWN[i], '|', 8, sizeof(szGSname)-1, szGSname); + iGSId = atoi(szGSname); + if (iGSId > 0){ + for (int j = 0; j < MAX_GMSV; j++){ + if (gmsv[j].used == '1'){ + getStringToken(gmsv[j].ipaddr, '.', 4, sizeof(szPlanetId)-1, szPlanetId); + if (iGSId == atoi(szPlanetId)){ + sprintf_s(szGSname, "%s", gmsv[j].name); + break; + } + } + } + } + else sprintf_s(szGSname, "无"); + +#ifndef _NEW_MANOR_LAW + sprintf_s(msgWN[i], "%-9s%-18s%6s%13s%10s%6s", onlinebuf, namebuf, lvbuf, dpbuf, statusbuf,szGSname); +#else + getStringToken(msgWN[i], '|', 9, sizeof(momentum)-1, momentum); + sprintf_s(msgWN[i], "%-9s%-18s%3s%12s%12s%10s%7s", onlinebuf, namebuf, lvbuf, dpbuf, momentum, statusbuf, szGSname); +#endif + +#else + sprintf_s(msgWN[i], "%-12s%-18s%3s%13s%10s", onlinebuf, namebuf, lvbuf, dpbuf, statusbuf); +#endif + } + else{ + getStringToken(msgWN[i], '|', 1, sizeof(namebuf)-1, namebuf); + getStringToken(msgWN[i], '|', 2, sizeof(tmp)-1, tmp); + FMdengonidex = atoi(tmp); + getStringToken(msgWN[i], '|', 3, sizeof(statusbuf)-1, statusbuf); + int_status = atoi(statusbuf); + switch (int_status){ + case 1: // 继续召募 + strcpy(statusbuf, "继续召募"); + break; + case 0: // 中止召募 + strcpy(statusbuf, "中止召募"); + break; + default: + break; + } + sprintf_s(msgWN[i], " %-20s %s", namebuf, statusbuf); + } + } + } + } +} + +/*---------- Shan (BEGIN) ----------*/ +/*--------- AD 2001/05/31 ---------*/ +// 家族人员列表 +int fmDutyproc = 0; // select number duty +int fmDutyRet = 0; +int fmYesNoproc = 0; // delete number +int fmYesNoRet = 0; + +#ifdef _FM_MODIFY +extern int TalkMode; +extern char secretName[32]; +extern STR_BUFFER *pNowStrBuffer; +#endif + +void FMWindowType(void) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static int fmdelid; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + char buf[1024]; +#ifdef _FM_MODIFY + int iNameX1, iNameY1, iNameX2, iNameY2; +#endif + + if (fmDutyproc == 1) { + fmDutyRet = fmselectdetuyWindow(200, 100, fmdelid); + return; + } + if (fmDutyRet != 0) + ptActMenuWin = NULL; + + if (ptActMenuWin == NULL) + { +#ifndef _FM_MODIFY + winW = 7; +#else +#ifdef _NEW_MANOR_LAW + winW = 9; +#else + winW = 8; +#endif +#endif + winH = 8; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for (i = 0; i < 10; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 335; + } + } + msgLine = 11; + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + + if (fmDutyRet != 0) + { + if (fmDutyRet != FMMEMBER_LEADER || fmDutyRet != FMMEMBER_APPLY){ + id2 = fmdelid; + FMmsgWN[id2] = fmDutyRet; + } + fmDutyRet = 0; + } + + if (ptActMenuWin->hp >= 1) + { + for (i = selStartLine; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { + if (i == 10){ + x1 = winX + 25; + y1 = winY + 28 + (i + 3) * 21; + x2 = x1 + 405; + y2 = y1 + 20; + +#ifdef _NEWFONT_ + x1 -= 60; + x2 -= 60; + y1 += 2; + y2 += 2; +#endif + + + } + else{ +#ifdef _NEW_MANOR_LAW + x1 = winX + 420; +#else + x1 = winX+364; +#endif + y1 = winY + 18 + (i + 3) * 21; + x2 = x1 + 70; + y2 = y1 + 20; +#ifdef _FM_MODIFY + iNameX1 = winX + 95; + iNameY1 = winY + 18 + (i + 3) * 21; + iNameX2 = iNameX1 + 118; + iNameY2 = iNameY1 + 20; +#endif + } + + // 只有族长、长老才可以修改 + /*if( pc.familyleader == FMMEMBER_LEADER && + FMmsgWN[i-selStartLine+1] > 0 && FMmsgWN[i-selStartLine+1] < FMMEMBER_NUMBER && + FMmsgWN[i-selStartLine+1] != FMMEMBER_LEADER || + ( pc.familyleader == FMMEMBER_ELDER || pc.familyleader == FMMEMBER_VICELEADER ) && + ( FMmsgWN[i-selStartLine+1] == FMMEMBER_MEMBER || FMmsgWN[i-selStartLine+1] == FMMEMBER_APPLY ) || + (i-selStartLine+1) == 11 && + (pc.familyleader == FMMEMBER_LEADER || pc.familyleader == FMMEMBER_ELDER || pc.familyleader == FMMEMBER_VICELEADER))*/ + if (pc.familyleader == FMMEMBER_LEADER && + FMmsgWN[i - selStartLine + 1] > 0 && FMmsgWN[i - selStartLine + 1] < FMMEMBER_NUMBER && + FMmsgWN[i - selStartLine + 1] != FMMEMBER_LEADER || + pc.familyleader == FMMEMBER_ELDER && + (FMmsgWN[i - selStartLine + 1] == FMMEMBER_MEMBER || FMmsgWN[i - selStartLine + 1] == FMMEMBER_APPLY) || + (i - selStartLine + 1) == 11 && + (pc.familyleader == FMMEMBER_LEADER || pc.familyleader == FMMEMBER_ELDER)) +#ifdef _NEWFONT_ + if (MakeHitBox(x1 + 55, y1, x2 + 55, y2, DISP_PRIO_BOX2)) +#else + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ) +#endif + { + time_t now_time; + time(&now_time); + if (mouse.onceState & MOUSE_LEFT_CRICK && (now_time - FMHoldTime) >= 1) + { + time(&FMHoldTime); + id2 = i - selStartLine + 1; + + if (id2 >= 1 && id2 <= 10) + switch (FMmsgWN[id2]){ + case FMMEMBER_MEMBER: // 一般成员 + case FMMEMBER_APPLY: // 申请加入 + case FMMEMBER_ELDER: // 长老 + //case FMMEMBER_ELDER: // 长老 + //case FMMEMBER_INVITE: // 祭司 + //case FMMEMBER_BAILEE: // 财务 + //case FMMEMBER_VICELEADER: // 副族长 + fmDutyproc = 1; + fmdelid = id2; + id2 = -1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + break; + default: + break; + } + else if (id2 == 11) + switch (FMmsgWN[id2]){ + case 1: // YES + FMmsgWN[id2] = 0; + break; + case 0: // N O + FMmsgWN[id2] = 1; + break; + default: + break; + } + } + } +#ifdef _FM_MODIFY + //滑鼠移到人名上方显示方框 + if (i < 10){ +#ifdef _NEWFONT_ + if (MakeHitBox(iNameX1, iNameY1 + 2, iNameX2 + 35, iNameY2 + 2, DISP_PRIO_BOX2)) +#else + if(MakeHitBox(iNameX1,iNameY1,iNameX2,iNameY2,DISP_PRIO_BOX2)) +#endif + { + time_t now_time; + time(&now_time); + if (mouse.onceState & MOUSE_LEFT_CRICK && (now_time - FMHoldTime) >= 1){ + //密语模式 +#ifdef _TELLCHANNEL + TalkMode = 1; + sprintf_s(secretName, "%s ", FMnameWN[i + 1]); +#endif + pNowStrBuffer->buffer[0] = NULL; + pNowStrBuffer->cursor = 0; + pNowStrBuffer->cnt = 0; +#ifdef _FRIENDCHANNEL + StrToNowStrBuffer1(secretName); +#endif + } + } + } +#endif + } + } + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 12 + || id == 100) + { + char data[256]; + char msg[256]; + if (id == 100) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d|%d|%d", FMdengonidex, id2, FMmsgWN[id2]); + makeEscapeString(data, msg, sizeof(msg)-1); + + if (1 <= id2 && id2 < 11){ + sprintf_s(buf, "M|%s|%d|%d", FMnameWN[id2], FMpidWN[id2], FMmsgWN[id2]); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + if (id2 == 11){ + sprintf_s(buf, "T|%d", FMmsgWN[id2]); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + /*if( FMmsgWN[id2] != FMMEMBER_ELDER && FMmsgWN[id2] != FMMEMBER_INVITE && + FMmsgWN[id2] != FMMEMBER_BAILEE && FMmsgWN[id2] != FMMEMBER_VICELEADER )*/ + if (FMmsgWN[id2] == FMMEMBER_NONE || FMmsgWN[id2] == FMMEMBER_MEMBER || FMmsgWN[id2] == 0){ + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + } + windowTypeWN = -1; + } + if (id >= 0 || id2 >= 0) { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + if (ptActMenuWin->hp >= 1) + { +#ifndef _FM_MODIFY + StockFontBuffer( winX+34, winY+21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘家族成员列表’", 0 ); + StockFontBuffer( winX+24, winY+21+2*21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘状态’ ‘ 成 员 姓 名 ’ ‘等级’ ‘个人声望’ ‘加入’", 0 ); +#else + +#ifdef _NEWFONT_ + StockFontBuffer(winX + 250, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "‘家族成员列表’", 0); +#else + StockFontBuffer( winX+34, winY+21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘家族成员列表’", 0 ); +#endif + + + + +#ifdef _NEW_MANOR_LAW + StockFontBuffer(winX + 24, winY + 21 + 2 * 21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "‘状态’‘ 成 员 姓 名 ’ ‘等级’‘个人声望’‘个人气势’‘加入’", 0); +#else + StockFontBuffer( winX+24, winY+21+2*21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘状态’ ‘ 成 员 姓 名 ’ ‘等级’ ‘个人声望’ ‘加入’‘服务器’", 0 ); +#endif +#endif + for (i = 0; i < msgLine; i++){ + if (strlen(msgWN[i]) > 0){ + if (i < selStartLine){ + StockFontBuffer(winX + 34, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0); + } + else if ((i - selStartLine + 1) == 11){ + int Font_Color = FONT_PAL_GREEN; + if (FMmsgWN[i + 1] == 1) Font_Color = FONT_PAL_GREEN; + else if (FMmsgWN[i + 1] == 0) Font_Color = FONT_PAL_RED; + StockFontBuffer(winX + 34, winY + 31 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, msgWN[i], 0); + } + else{ + int Font_Color = FONT_PAL_WHITE; + if (FMmsgWN[i + 1] == 2) Font_Color = FONT_PAL_BLUE2; + else if (FMmsgWN[i + 1] == -1) Font_Color = FONT_PAL_RED; + +#ifdef _NEWFONT_ + extern void ltrim(char *str); + if (i != 10){ + char strtemp[128]; + memcpy(strtemp, msgWN[i], 7); + strtemp[7] = 0; + StockFontBuffer(winX + 34, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + memcpy(strtemp, msgWN[i] + 9, 18); + strtemp[18] = 0; + StockFontBuffer(winX + 100, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + memcpy(strtemp, msgWN[i] + 27, 4); + strtemp[4] = NULL; + StockFontBuffer(winX + 258, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + memcpy(strtemp, msgWN[i] + 31, 12); + strtemp[12] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 300, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + memcpy(strtemp, msgWN[i] + 43, 12); + strtemp[12] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 385, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + memcpy(strtemp, msgWN[i] + 56, 8); + strtemp[8] = NULL; + StockFontBuffer(winX + 480, winY + 20 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + } + else{ + StockFontBuffer(winX + 34, winY + 31 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, msgWN[i], 0); + } +#else + StockFontBuffer( winX+34, winY+31+(i+3)*21, + FONT_PRIO_FRONT, Font_Color, msgWN[i], 0 ); +#endif + } + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} +#else +/*---------- Shan (BEGIN) ----------*/ +/*--------- AD 2001/05/31 ---------*/ +// shan Family MemberList +void initFMWindowType( char *data ) +{ + makeStringFromEscaped( data ); + + selStartLine = 0; + FMdengonidex = 0; + + getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + sizeof( msgWN )/sizeof( msgWN[0] ), 40 ); + + time(&FMHoldTime); + + char getstatus[3]; + char namebuf[30],lvbuf[5],statusbuf[16],onlinebuf[12],dpbuf[64]; + int int_status,onlineflag; + char tmp[32]; + // 家族传送的行数为 11 ,前三行标题,后十行为资料(作为EVENT之用) + // 最后一行则为‘是否继续新增家族人员的选项’ + for( int i = 0; i < 11; i++ ){ + if( strlen( msgWN[i] ) > 0 ){ + if( i>=selStartLine ){ + strcpy( getstatus, msgWN[i]+(strlen(msgWN[i])-1)); + // 存的 INDEX -> 1~10 + FMmsgWN[i-(selStartLine-1)] = atoi(getstatus); + getStringToken(msgWN[i], '|', 1, sizeof(tmp)-1, tmp); + FMpidWN[i-(selStartLine-1)] = atoi(tmp); + getStringToken(msgWN[i], '|', 2, sizeof(FMnameWN[i-(selStartLine-1)])-1, + FMnameWN[i-(selStartLine-1)]); + //处理字串 + if(i<10){ + getStringToken(msgWN[i], '|', 2, sizeof(namebuf)-1, namebuf); + getStringToken(msgWN[i], '|', 3, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 4, sizeof(onlinebuf)-1, onlinebuf); + onlineflag = atoi(onlinebuf); + if( onlineflag > 0 ) + strcpy(onlinebuf, "OnLine"); + else + strcpy(onlinebuf, "OffLine"); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + getStringToken(msgWN[i], '|', 6, sizeof(statusbuf)-1, statusbuf); + sprintf_s(msgWN[i], "%-12s%-18s%-7s%9s%5s", onlinebuf, namebuf, lvbuf, dpbuf, statusbuf); + }else{ + getStringToken(msgWN[i], '|', 1, sizeof(namebuf)-1, namebuf); + getStringToken(msgWN[i], '|', 2, sizeof(tmp)-1, tmp); + FMdengonidex = atoi(tmp); + getStringToken(msgWN[i], '|', 3, sizeof(statusbuf)-1, statusbuf); + int_status = atoi(statusbuf); + switch( int_status ){ + case 1: // 继续召募 + strcpy(statusbuf, "继续召募"); + break; + case 0: // 中止召募 + strcpy(statusbuf, "中止召募"); + break; + default: + break; + } + sprintf_s(msgWN[i], " %-20s %s", namebuf, statusbuf); + } + } + } + } +} + +/*---------- Shan (BEGIN) ----------*/ +/*--------- AD 2001/05/31 ---------*/ +// 家族人员列表 +int fmYesNoproc = 0; // delete number +int fmYesNoRet = 0; +void FMWindowType( void ) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static int fmdelid; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + char getstatus[3]; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + char buf[1024]; + + if( fmYesNoproc == 1) { + fmYesNoRet = fmYesNoWindow(170, 170, fmdelid); + return; + } + if(fmYesNoRet != 0) + ptActMenuWin = NULL; + + if( ptActMenuWin == NULL ) + { + winW = 7; + winH = 8; + winX = (lpDraw->XSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for( i = 0; i < 10; i++, mask <<= 1 ) + { + if( buttonTypeWN & mask ) + { + btnCnt++; + if( btnCnt == 4 ) + break; + } + } + if( btnCnt > 0 ) + { + int w; + w = winW*64/(btnCnt+1); + for( i = 0; i < btnCnt; i++ ) + { + btnLoc[i][0] = w * (i+1) - 27; + btnLoc[i][1] = 335; + } + } + msgLine = 11; + play_se( 202, 320, 240 ); + } + + if( ptActMenuWin != NULL ) + { + id = selFontId( btnId, sizeof( btnId )/sizeof( int ) ); + + id2 = -1; + + if(fmYesNoRet != 0) + { + if(fmYesNoRet==1){ + id2 = fmdelid; + FMmsgWN[id2] = 4; + } + fmYesNoRet = 0; + } + + if( ptActMenuWin->hp >= 1 ) + { + for( i = selStartLine; i < msgLine; i++ ) + { + if( strlen( msgWN[i] ) > 0 ) + { + if(i==10){ + x1 = winX+25; + y1 = winY+28+(i+3)*21; + x2 = x1 + 405; + y2 = y1 + 20; + } + else{ + x1 = winX+364; + y1 = winY+18+(i+3)*21; + x2 = x1 + 70; + y2 = y1 + 20; + } + + // 只有族长才可以修改 + + if( pc.familyleader == 1 && + FMmsgWN[i-selStartLine+1] > 0 && + FMmsgWN[i-selStartLine+1] < 4 && + FMpidWN[i-selStartLine+1] != 0 || + (i-selStartLine+1) == 11 && + pc.familyleader == 1 ) + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ) + { + time_t now_time; + time(&now_time); + if( mouse.onceState & MOUSE_LEFT_CRICK && (now_time - FMHoldTime)>=1 ) + { + time(&FMHoldTime); + id2 = i - selStartLine + 1; + + if( id2>=1 && id2<=10) + switch( FMmsgWN[id2] ){ + case 1: // 已 加 入 + fmYesNoproc = 1; + fmdelid = id2; + id2 = -1; + DeathAction( ptActMenuWin ); + break; + case 2: // 申请加入 + FMmsgWN[id2] = 1; + break; + case 3: // 申请退出 + fmYesNoproc = 1; + fmdelid = id2; + id2 = -1; + DeathAction( ptActMenuWin ); + break; + case 4: // 退 出 + break; + default: + break; + } + else if(id2==11) + switch( FMmsgWN[id2] ){ + case 1: // YES + FMmsgWN[id2] = 0; + break; + case 0: // N O + FMmsgWN[id2] = 1; + break; + default: + break; + } + } + } + } + } + } + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if( 0 <= id && id < 6 + || 0 <= id2 && id2 < 12 + || id == 100 ) + { + char data[256]; + char msg[256]; + if( id == 100 ) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if( 0 <= id && id < 6 ) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if( id2 < 0 ) + id2 = 0; + sprintf_s( data, "%d|%d", FMdengonidex, id2 ); + makeEscapeString( data, msg, sizeof( msg )-1 ); + + if(1 <= id2 && id2 < 11){ + sprintf_s(buf, "M|%s|%d|%d",FMnameWN[id2],FMpidWN[id2],FMmsgWN[id2]); + if( bNewServer) + lssproto_FM_send(sockfd,buf); + else + old_lssproto_FM_send(sockfd,buf); + } + if( id2 == 11){ + sprintf_s(buf, "T|%d",FMmsgWN[id2]); + if( bNewServer) + lssproto_FM_send(sockfd,buf); + else + old_lssproto_FM_send(sockfd,buf); + } + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ) ; + windowTypeWN = -1; + } + if( id >= 0 || id2 >= 0) { + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + if( ptActMenuWin->hp >= 1 ) + { + StockFontBuffer( winX+34, winY+21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘家族成员列表’", 0 ); + StockFontBuffer( winX+24, winY+21+2*21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘状态’ ‘ 成 员 姓 名 ’ ‘等级’ ‘个人声望’ ‘加入’", 0 ); + for( i = 0; i < msgLine; i++ ) + { + if( strlen( msgWN[i] ) > 0 ) + { + if( i=1 && int_status<=4) + switch( int_status ){ + case 1: // 已 加 入 + strcpy(msgWN[i]+(strlen(msgWN[i])-3), "已 加 入"); + break; + case 2: // 申请加入 + strcpy(msgWN[i]+(strlen(msgWN[i])-3), "申请加入"); + break; + case 3: // 申请退出 + strcpy(msgWN[i]+(strlen(msgWN[i])-3), "申请退出"); + break; + case 4: // 退 出 + strcpy(msgWN[i]+(strlen(msgWN[i])-3), "退 出"); + break; + default: + break; + } + int_status = -1; + int Font_Color = FONT_PAL_WHITE; + if(FMmsgWN[i+1] == 1) Font_Color = FONT_PAL_WHITE; + else if(FMmsgWN[i+1] == 2) Font_Color = FONT_PAL_BLUE2; + else if(FMmsgWN[i+1] == 3) Font_Color = FONT_PAL_GRAY; + else if(FMmsgWN[i+1] == 4) Font_Color = FONT_PAL_RED; + + StockFontBuffer( winX+34, winY+21+(i+3)*21, + FONT_PRIO_FRONT, Font_Color, msgWN[i], 0 ); + } + } + } + j = 0; + for( i = 0, mask = 1; i < 6; i++, mask <<= 1 ) + { + btnId[i] = -2; + if( buttonTypeWN & mask ) + { + if( j < btnCnt ) + { + btnId[i] = + StockFontBuffer( winX+btnLoc[j][0], winY+btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2 ); + j++; + } + } + } + } + } +} +#endif + +// shan Family Dengon +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) +void initFMWindowType1(char *data) +{ + char m_buf[128], m_buf1[512]; + FMdengonidex = 0; + msgWN_W = 9; + msgWN_H = 9; + msgWNLen = (msgWN_W * 64 - 48) / 9; + makeStringFromEscaped(data); + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), msgWNLen + 40); + FMdengonidex = atoi(msgWN[7]); + for (int i = 7; i < 14; i++){ + if (strlen(msgWN[i - 7]) > 0){ + if (i >= selStartLine){ + int n = 0; + char *p = msgWN[i - 7]; + for (size_t j = 0; j < strlen(msgWN[i - 7]); j++){ + if (IS_2BYTEWORD(*(p + j)) == 1){ + j++; + continue; + } + else if (*(p + j) == '|') + n++; + } + getStringToken(msgWN[i - 7], '|', (n + 1), sizeof(msgWN[i]) - 1, msgWN[i]); + getStringToken(msgWN[i - 7], '|', 1, sizeof(m_buf1)-1, m_buf1); + for (int k = 2; k < (n + 1); k++){ + getStringToken(msgWN[i - 7], '|', k, sizeof(m_buf)-1, m_buf); + strcat_s(m_buf1, "|"); + strcat_s(m_buf1, m_buf); + } + strcpy(msgWN[i - 7], m_buf1); + } + } + } +} + + +// 家族留言板 +void FMWindowType1(void) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static STR_BUFFER input; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + static int totalMsgLine; + static int lineSkip; + + if (ptActMenuWin == NULL) + { + winW = msgWN_W; + winH = msgWN_H; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + lineSkip = 20; + totalMsgLine = (winH * 48 - 56) / lineSkip; + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = ((winH * 48 - 56) / totalMsgLine)*(totalMsgLine - 1) + + (winH * 48 - totalMsgLine*lineSkip) / 2 + 8; + } + } + msgLine = totalMsgLine - 2; + input.buffer[0] = '\0'; + input.cnt = 0; + input.cursor = 0; + initStrBuffer(&input, + winX + (msgWN_W * 64 - msgWNLen * 9) / 2, + winY + ((winH * 48 - 56) / totalMsgLine)*(totalMsgLine - 2) + (winH * 48 - totalMsgLine*lineSkip) / 2, + msgWNLen, FONT_PAL_WHITE, FONT_PRIO_FRONT); + GetKeyInputFocus(&input); + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (CheckMenuFlag() + || ((joy_trg[0] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + // OK + if (id == 0 && strcmp(input.buffer, "") != 0 || id != 0) + if (0 <= id && id < 6) + { + char msg[256], msg1[256]; + btn = 1; + btn <<= id; + + makeEscapeString(input.buffer, msg1, sizeof(msg1)-1); + sprintf_s(msg, "%d|%s", FMdengonidex, msg1); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + + windowTypeWN = -1; + } + if (id >= 0) + { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + GetKeyInputFocus(&MyChatBuffer); + return; + } + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 200, + winY + 25, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘家 族 留 言 板’", 0); + for (i = 0; i < 7; i++) + { + if (strlen(msgWN[i]) > 0) + { + StockFontBuffer(winX + (msgWN_W * 64 - msgWNLen * 9) / 2, + winY + ((winH * 48 - 56) / totalMsgLine)*(i * 2) + (winH * 48 - totalMsgLine*lineSkip) / 2 + 30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0); + } + if (strlen(msgWN[i + 7]) > 0) + { + StockFontBuffer(winX + (msgWN_W * 64 - msgWNLen * 9) / 2 + 300, + winY + ((winH * 48 - 56) / totalMsgLine)*(i * 2 + 1) + (winH * 48 - totalMsgLine*lineSkip) / 2 + 30, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, msgWN[i + 7], 0); + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + StockFontBuffer2(&input); + } + } +} + +//shan Family Point +void initFMWindowType2(char *data) +{ + makeStringFromEscaped(data); + + selStartLine = 0; + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 100); + + char getstatus[4]; + char buf0[16], buf1[8], buf2[8], buf3[20], buf4[20];; + char tmp[8]; + int tmp_i; + +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + for (int i = 0; i < fm_point_num; i++){ +#else + for( int i = 0; i < 4; i++ ){ +#endif + if (strlen(msgWN[i]) > 0){ + if (i >= selStartLine){ + getStringToken(msgWN[i], '|', 5, sizeof(getstatus)-1, getstatus); + FMmsgWN[i - (selStartLine - 1)] = atoi(getstatus); + getStringToken(msgWN[i], '|', 1, sizeof(tmp)-1, tmp); + FMpidWN[i - (selStartLine - 1)] = atoi(tmp); + getStringToken(msgWN[i], '|', 2, sizeof(tmp)-1, tmp); + getStringToken(msgWN[i], '|', 6, sizeof(buf4)-1, buf4); + + tmp_i = atoi(tmp); + //(tmp_i==100)?(strcpy(buf0,"萨依那斯")):(strcpy(buf0,"加 鲁 卡")); + if (tmp_i == 100) strcpy(buf0, "萨姆吉尔"); + else if (tmp_i == 200) strcpy(buf0, "玛丽娜丝"); + else if (tmp_i == 300) strcpy(buf0, "加 加"); + else if (tmp_i == 400) strcpy(buf0, "卡鲁它那"); +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + else if (tmp_i == 500) strcpy(buf0, "伊 甸"); + else if (tmp_i == 600) strcpy(buf0, "塔 尔 塔"); + else if (tmp_i == 700) strcpy(buf0, "尼 克 斯"); + else if (tmp_i == 800) strcpy(buf0, "弗 烈 顿"); + else if (tmp_i == 900) strcpy(buf0, "亚 伊 欧"); +#endif +#ifdef _FIX_10_FMPOINT + else if (tmp_i == 1000)strcpy(buf0, "瑞尔亚斯"); +#endif + (FMmsgWN[i - (selStartLine - 1)] > 0) ? (strcpy(buf3, buf4)) : (strcpy(buf3, "未使用")); + //处理字串 + if (i < 10){ + getStringToken(msgWN[i], '|', 3, sizeof(buf1)-1, buf1); + getStringToken(msgWN[i], '|', 4, sizeof(buf2)-1, buf2); + sprintf_s(msgWN[i], "%9s%5s %5s%18s", buf0, buf1, buf2, buf3); + sprintf_s(FMnameWN[i - (selStartLine - 1)], "%s|%s|%s", tmp, buf1, buf2); + } + } + } + } +} + +// 家族据点 +void FMWindowType2(void) +{ + static int winX, winY; + static int winW, winH; +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 +#ifdef _FIX_10_FMPOINT + static int btnId[] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 }; + static int btnLoc[12][2]; +#else + static int btnId[] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2}; + static int btnLoc[11][2]; +#endif +#else + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; +#endif + + static int btnCnt; + static int msgLine; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + int x1, y1, x2, y2; + char buf[1024]; + if (ptActMenuWin == NULL) + { + winW = 5; + winH = 4 + fm_point_num / 3; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 +#ifdef _FIX_10_FMPOINT + for (i = 0; i < 16; i++, mask <<= 1) +#else + for( i = 0; i < 15; i++, mask <<= 1 ) +#endif +#else + for( i = 0; i < 10; i++, mask <<= 1 ) +#endif + { + if (buttonTypeWN & mask) + { + btnCnt++; +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + if (btnCnt == fm_point_num) +#else + if( btnCnt == 4 ) +#endif + break; + } + } + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = fm_point_num * 18; + } + } + +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + msgLine = fm_point_num; +#else + msgLine = 4; +#endif + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + if (ptActMenuWin->hp >= 1) + { + for (i = selStartLine; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { + x1 = winX + 30; + y1 = winY + 18 + (i + 3) * 21; + x2 = x1 + 260; + y2 = y1 + 20; + + // 只有族长才可以修改 +#ifdef _FMVER21 + if (pc.familyleader == FMMEMBER_LEADER && FMmsgWN[i - selStartLine + 1] <= 0) +#else + if( pc.familyleader == 1 && FMmsgWN[i-selStartLine+1] <= 0 ) +#endif + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + id2 = i - selStartLine + 1; + } + } + } + } + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 +#ifdef _FIX_10_FMPOINT + if (0 <= id && id < 16 + || 0 <= id2 && id2 < 17 +#else + if( 0 <= id && id < 11 + || 0 <= id2 && id2 < 16 +#endif +#else + if( 0 <= id && id < 6 + || 0 <= id2 && id2 < 11 +#endif + || id == 100) + { + char data[256]; + char msg[256]; + if (id == 100) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 +#ifdef _FIX_10_FMPOINT + if (0 <= id && id < 12) +#else + if( 0 <= id && id < 11 ) +#endif +#else + if( 0 <= id && id < 6 ) +#endif + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d", id2); + makeEscapeString(data, msg, sizeof(msg)-1); + + sprintf_s(buf, "P|%d|%s", FMpidWN[id2], FMnameWN[id2]); + +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + if (1 <= id2 && id2 <= fm_point_num + 1){ +#else + if(1 <= id2 && id2 < 5){ +#endif + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + } + +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 + if (0 <= id && id < fm_point_num + 2){ +#else + if( 0 <= id && id < 6 ){ +#endif + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + } + windowTypeWN = -1; + } + if (id >= 0 || id2 >= 0) { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + if (ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 34, winY + 28, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘家族据点申请列表’", 0); + StockFontBuffer(winX + 30, winY + 18 + 2 * 21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘地 点’‘东’‘南’ ‘状 态’", 0); + for (i = 0; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { + if (i < selStartLine){ + StockFontBuffer(winX + 30, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[i], 0); + } + else{ + int Font_Color = FONT_PAL_WHITE; + if (FMmsgWN[i + 1] <= 0) Font_Color = FONT_PAL_GRAY; + +#ifdef _NEWFONT_ + char strtemp[128]; + extern void ltrim(char *str); + memcpy(strtemp, msgWN[i], 11); + strtemp[11] = NULL; + StockFontBuffer(winX + 30, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 11, 6); + strtemp[6] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 100, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 14, 6); + strtemp[6] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 130, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 20, 18); + strtemp[18] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 180, winY + 21 + (i + 3) * 21, + FONT_PRIO_FRONT, Font_Color, strtemp, 0); +#else + + StockFontBuffer( winX+30, winY+21+(i+3)*21, + FONT_PRIO_FRONT, Font_Color, msgWN[i], 0 ); +#endif + } + } + } + j = 0; +#ifdef _FIX_9_FMPOINT // WON ADD 九大庄园 +#ifdef _FIX_10_FMPOINT + for (i = 0, mask = 1; i < 12; i++, mask <<= 1) +#else + for( i = 0, mask = 1; i < 11; i++, mask <<= 1 ) +#endif +#else + for( i = 0, mask = 1; i < 6; i++, mask <<= 1 ) +#endif + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + 110 + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + +#ifdef _FMVER21 +// (member list) select duty +int fmselectdetuyWindow(int x, int y, int id) +{ + static int btnId[] = { -2, -2, -2, -2 }; + static int btnLoc[4][2]; + static ACTION *ptActMenuWin = NULL; + int ret = 0; + int dutytobtn = -1; + char buff[64]; + char *btnTitle[] = + { + "一般族员", + "退 出", + "长 老", + //"长 老", + //"祭 司", + //"财 务 长", + //"副 族 长", + "取 消" + }; + + if (fmYesNoproc == 1){ + fmYesNoRet = fmYesNoWindow(170, 170, id); + return 0; + } + if (fmYesNoRet != 0){ + if (fmYesNoRet == 1){ + ret = FMMEMBER_NONE; + fmDutyproc = 0; + fmYesNoRet = 0; + return ret; + } + } + + if (ptActMenuWin == NULL){ + ptActMenuWin = MakeWindowDisp(x, y, 3, 5, NULL, 1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + for (int i = 0; i < 4; i++) + btnId[i] = -2; + for (int j = 0; j < 4; j++){ + btnLoc[j][0] = x + 65; + btnLoc[j][1] = y + 45 + 30 * (j + 1); + } + play_se(202, 320, 240); + } + + /*switch(FMmsgWN[id]){ + case FMMEMBER_ELDER: + dutytobtn = 2; + break; + case FMMEMBER_INVITE: + dutytobtn = 3; + break; + case FMMEMBER_BAILEE: + dutytobtn = 4; + break; + case FMMEMBER_VICELEADER: + dutytobtn = 5; + default: + break; + }*/ + switch (FMmsgWN[id]){ + case FMMEMBER_ELDER: + dutytobtn = 2; + break; + default: + break; + } + + sprintf_s(buff, "请选择"); + StockFontBuffer(x + 100, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, buff, 0); + sprintf_s(buff, " %s ", FMnameWN[id]); + StockFontBuffer(x + 145, y + 80, FONT_PRIO_FRONT, FONT_PAL_GREEN, buff, 0); + sprintf_s(buff, "所担任的家族职务:"); + StockFontBuffer(x + 100, y + 105, FONT_PRIO_FRONT, FONT_PAL_WHITE, buff, 0); + if (ptActMenuWin != NULL){ + for (int i = 0; i < 4; i++) + if (FMmsgWN[id] == 2 && i == 2){ + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], FONT_PRIO_FRONT, FONT_PAL_GRAY, btnTitle[i], 0); + } + else if (pc.familyleader == FMMEMBER_ELDER && i == 2){ + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], FONT_PRIO_FRONT, FONT_PAL_GRAY, btnTitle[i], 0); + } + else if (dutytobtn == i){ + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], FONT_PRIO_FRONT, FONT_PAL_GRAY, btnTitle[i], 0); + } + else if (i == 3){ + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], FONT_PRIO_FRONT, FONT_PAL_WHITE, btnTitle[i], 0); + } + else{ + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 0); + } + } + + for (int i = 0; i < 4; i++){ + int x1 = x + 130; + int y1 = y + 30 * (i + 1) + 102; + int x2 = x1 + 85; + int y2 = y1 + 20; + if (dutytobtn != i){ + if (!(FMmsgWN[id] == 2 && i == 2)){ + if (pc.familyleader == FMMEMBER_LEADER || + pc.familyleader == FMMEMBER_ELDER && (i >= 0 && i <= 1 || i == 3)){ + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + switch (i){ + case 0: // 一般成员 + ret = FMMEMBER_MEMBER; + fmDutyproc = 0; + break; + case 1: // 退出 + fmYesNoproc = 1; + break; + case 2: // 长老 + ret = FMMEMBER_ELDER; + fmDutyproc = 0; + break; + case 3: + fmDutyproc = 0; + break; + default: + break; + } + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + } + } + } + } + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + fmDutyproc = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + return ret; +} +#endif + +// (member list) delete member +int fmYesNoWindow(int x, int y, int id) +{ + static int btnId[] = { -2, -2 }; + static int btnLoc[2][2]; + static ACTION *ptActMenuWin = NULL; + int ret = 0; + char buff[64]; + char *btnTitle[] = + { + "确 定", + "取 消" + }; + + if (ptActMenuWin == NULL){ + ptActMenuWin = MakeWindowDisp(x, y, 5, 2, NULL, 1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + for (int i = 0; i < 2; i++) + btnId[i] = -2; + for (int j = 0; j < 2; j++){ + btnLoc[j][0] = x + 83 * (j + 1); + btnLoc[j][1] = y + 60; + } + play_se(202, 320, 240); + } + + sprintf_s(buff, "确定要让 %s 退出家族吗?", FMnameWN[id]); + StockFontBuffer(x + 100, y + 80, FONT_PRIO_FRONT, FONT_PAL_WHITE, buff, 0); + if (ptActMenuWin != NULL){ + for (int i = 0; i < 2; i++) + StockFontBuffer(btnLoc[i][0], btnLoc[i][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 0); + } + + for (int i = 0; i < 2; i++){ + int x1 = x + 83 * (i + 1) - 10 + 80; + int y1 = y + 58 + 59; + int x2 = x1 + 60; + int y2 = y1 + 20; + if (MakeHitBox(x1, y1, x2, y2, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ret = i + 1; + fmYesNoproc = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + } + return ret; +} + +#ifdef _FMVER21 +// shan Family DpList +short lnmake; +void initFMWindowType4(char *data, int king) +{ + makeStringFromEscaped(data); + + FMdengonidex = 0; + selStartLine = 0; + lnmake = 0; + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 80); + + time(&FMHoldTime); + + char lvbuf[8], fmnamebuf[36], namebuf[36], dpbuf[20], makecolor[4]; + int sumdp = 0, taldp = 0; +#ifdef _NEW_MANOR_LAW + int momentum = 0, fmmomentum = 0; +#endif + + FMdengonidex = atoi(msgWN[10]); + for (int i = 0; i < 10; i++){ + if (strlen(msgWN[i]) > 0){ + if (i >= selStartLine){ + if (king == 0){ + //处理字串 + getStringToken(msgWN[i], '|', 2, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 3, sizeof(fmnamebuf)-1, fmnamebuf); + makeStringFromEscaped(fmnamebuf); + getStringToken(msgWN[i], '|', 4, sizeof(namebuf)-1, namebuf); + makeStringFromEscaped(namebuf); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + sumdp = atoi(dpbuf); + getStringToken(msgWN[i], '|', 6, sizeof(dpbuf)-1, dpbuf); + taldp = atoi(dpbuf); + getStringToken(msgWN[i], '|', 7, sizeof(makecolor)-1, makecolor); + if (strcmp(makecolor, "1") == 0) lnmake = i; + + //printf("[ %-7s%-18s%-16s%13d%12d%14d%]\n\n", lvbuf, fmnamebuf, namebuf, sumdp, taldp-sumdp, taldp); + sprintf(msgWN[i], " %-7s%-18s%-16s%13d%12d%14d%", lvbuf, fmnamebuf, namebuf, sumdp, taldp - sumdp, taldp); + } + else if (king == 1){ +#ifdef _NEW_MANOR_LAW + getStringToken(msgWN[i], '|', 2, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 3, sizeof(fmnamebuf)-1, fmnamebuf); + makeStringFromEscaped(fmnamebuf); + getStringToken(msgWN[i], '|', 4, sizeof(namebuf)-1, namebuf); + makeStringFromEscaped(namebuf); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + fmmomentum = atoi(dpbuf); + getStringToken(msgWN[i], '|', 6, sizeof(dpbuf)-1, dpbuf); + momentum = atoi(dpbuf); + sprintf(msgWN[i], "%-7s%-16s%-16s%8d%12d", lvbuf, fmnamebuf, namebuf, fmmomentum, momentum); +#endif + } + } + } + } +} + +// 家族强者表 +#ifdef _NEW_MANOR_LAW +void FMWindowType4(int king) +#else +void FMWindowType4( void ) +#endif +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static int fmdelid; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + + if (ptActMenuWin == NULL) + { +#ifdef _NEW_MANOR_LAW + if (king == 0){ + winW = 10; + winH = 7; + } + else if (king == 1){ + winW = 8; + winH = 7; + } +#else + winW = 10; + winH = 7; +#endif + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for (i = 0; i < 10; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 295; + } + } + msgLine = 10; + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 12 + || id == 100) + { + char data[256]; + char msg[256]; + if (id == 100) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d|%d", FMdengonidex, id2); + makeEscapeString(data, msg, sizeof(msg)-1); + + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + windowTypeWN = -1; + } + if (id >= 0 || id2 >= 0) { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + if (ptActMenuWin->hp >= 1) + { +#ifdef _NEW_MANOR_LAW + if (king == 0){ + StockFontBuffer(winX + 235, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "‘史上最强之家族强者排行榜’", 0); + StockFontBuffer(winX + 25, winY + 16 + 2 * 21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘名次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘综合声望’‘成员声望’‘家族总声望’", 0); + } + else if (king == 1){ + StockFontBuffer(winX + 155, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "‘史上最强之家族强者排行榜’", 0); + StockFontBuffer(winX + 25, winY + 16 + 2 * 21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘名次’‘家 族 名 称’ ‘族 长 名 称’ ‘家族总气势’", 0); + } +#else + StockFontBuffer( winX+235, winY+21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "‘史上最强之家族强者排行榜’", 0 ); + StockFontBuffer( winX+25, winY+16+2*21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘名次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘综合声望’‘成员声望’‘家族总声望’", 0 ); +#endif + for (i = 0; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { + int fontcolor = FONT_PAL_WHITE; + if (lnmake != 0){ + fontcolor = FONT_PAL_GRAY; + if (lnmake == i) fontcolor = FONT_PAL_WHITE; + } + if (i < selStartLine){ +#ifdef _NEW_MANOR_LAW + if (king == 0) StockFontBuffer(winX + 40, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, msgWN[i], 0); + else if (king == 1) StockFontBuffer(winX + 60, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, msgWN[i], 0); +#else + StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor, msgWN[i], 0 ); +#endif + } +#ifdef _NEW_MANOR_LAW +#ifdef _NEWFONT_ + extern void ltrim(char *str); + char strtemp[128]; + if (strlen(msgWN[i]) >= 77){ + memcpy(strtemp, msgWN[i], 8); + strtemp[8] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 40, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 8, 26 - 8); + strtemp[26 - 8] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 85, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 26, 50 - 26); + strtemp[50 - 26] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 220, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 50, 59 - 50); + strtemp[59 - 50] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 350, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 59, 73 - 59); + strtemp[73 - 59] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 440, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 73, 81 - 73); + strtemp[81 - 73] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 540, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + } + else{ + memcpy(strtemp, msgWN[i], 7); + strtemp[7] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 40, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 7, 23 - 7); + strtemp[23 - 7] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 85, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 23, 42 - 23); + strtemp[42 - 23] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 220, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 42, 57 - 42); + strtemp[57 - 42] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 350, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + } + +#else + if(king == 0) StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor, msgWN[i], 0 ); + else if(king == 1) StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor, msgWN[i], 0 ); +#endif +#else + StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor, msgWN[i], 0 ); +#endif + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} + +void initFMWindowType3(char *data) +{ + makeStringFromEscaped(data); + + FMdengonidex = 0; + selStartLine = 0; + lnmake = 0; + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), 50); + + time(&FMHoldTime); + + char lvbuf[8], fmnamebuf[36], namebuf[36], dpbuf[20], makecolor[4]; + + FMdengonidex = atoi(msgWN[10]); + for (int i = 0; i < 10; i++){ + if (strlen(msgWN[i]) > 0){ + if (i >= selStartLine){ + //处理字串 + getStringToken(msgWN[i], '|', 2, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 3, sizeof(fmnamebuf)-1, fmnamebuf); + makeStringFromEscaped(fmnamebuf); + getStringToken(msgWN[i], '|', 4, sizeof(namebuf)-1, namebuf); + makeStringFromEscaped(namebuf); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + getStringToken(msgWN[i], '|', 6, sizeof(makecolor)-1, makecolor); + if (strcmp(makecolor, "1") == 0) lnmake = i; + sprintf_s(msgWN[i], " %-9s%-19s%-17s%12s", lvbuf, fmnamebuf, namebuf, dpbuf); + } + } + } +} + +// 家族强者表 top30 +#ifdef _NEW_MANOR_LAW +void FMWindowType3(int king) +#else +void FMWindowType3( void ) +#endif +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static int fmdelid; +#ifdef _NEW_MANOR_LAW + char szMessage[128]; +#endif + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + + if (ptActMenuWin == NULL) + { + winW = 8; + winH = 7; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(btnId) / sizeof(int); i++) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for (i = 0; i < 10; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = 295; + } + } + msgLine = 10; + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + id = selFontId(btnId, sizeof(btnId) / sizeof(int)); + + id2 = -1; + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if (0 <= id && id < 6 + || 0 <= id2 && id2 < 12 + || id == 100) + { + char data[256]; + char msg[256]; + if (id == 100) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if (id2 < 0) + id2 = 0; + sprintf_s(data, "%d|%d", FMdengonidex, id2); + makeEscapeString(data, msg, sizeof(msg)-1); + + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, msg); + windowTypeWN = -1; + } + if (id >= 0 || id2 >= 0) { + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + if (ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 34, winY + 21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘史上最强之家族强者排行榜’", 0); + +#ifdef _NEW_MANOR_LAW +#ifdef _NEWFONT_ + if (king == 0) sprintf_s(szMessage, "‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族声望值’"); + else if (king == 1) sprintf_s(szMessage, "‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族气势值’"); + StockFontBuffer(winX + 20, winY + 16 + 2 * 21, FONT_PRIO_FRONT, FONT_PAL_GREEN, szMessage, 0); +#else + if(king == 0) sprintf_s(szMessage,"‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族声望值’"); + else if(king == 1) sprintf_s(szMessage,"‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族气势值’"); + StockFontBuffer( winX+39, winY+16+2*21,FONT_PRIO_FRONT, FONT_PAL_GREEN,szMessage,0); +#endif +#else + StockFontBuffer( winX+39, winY+16+2*21,FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族声望值’", 0 ); +#endif + for (i = 0; i < msgLine; i++) + { + if (strlen(msgWN[i]) > 0) + { + int fontcolor = FONT_PAL_WHITE; + if (lnmake != 0){ + fontcolor = FONT_PAL_GRAY; + if (lnmake == i) fontcolor = FONT_PAL_WHITE; + } + if (i < selStartLine){ + StockFontBuffer(winX + 58, winY + 14 + (i + 3) * 21, + FONT_PRIO_FRONT, fontcolor, msgWN[i], 0); + } +#ifdef _NEWFONT_ + extern void ltrim(char *str); + char strtemp[128]; + memcpy(strtemp, msgWN[i], 10); + strtemp[10] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 40, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 10, 29 - 10); + strtemp[29 - 10] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 85, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 29, 53 - 29); + strtemp[53 - 29] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 220, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); + + memcpy(strtemp, msgWN[i] + 53, 58 - 53); + strtemp[58 - 53] = NULL; + ltrim(strtemp); + StockFontBuffer(winX + 350, winY + 14 + (i + 3) * 21, FONT_PRIO_FRONT, fontcolor, strtemp, 0); +#else + + + StockFontBuffer( winX+58, winY+14+(i+3)*21, + FONT_PRIO_FRONT, fontcolor, msgWN[i], 0 ); +#endif + } + } + j = 0; + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + btnId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + btnId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + } + } +} +#else +short lnmake; +void initFMWindowType3( char *data ) +{ + makeStringFromEscaped( data ); + + FMdengonidex = 0; + selStartLine = 0; + lnmake = 0; + getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + sizeof( msgWN )/sizeof( msgWN[0] ), 50 ); + + time(&FMHoldTime); + + char lvbuf[8],fmnamebuf[36],namebuf[36],dpbuf[20],makecolor[4]; + + FMdengonidex = atoi(msgWN[10]); + for( int i = 0; i < 10; i++ ){ + if( strlen( msgWN[i] ) > 0 ){ + if( i>=selStartLine ){ + //处理字串 + getStringToken(msgWN[i], '|', 2, sizeof(lvbuf)-1, lvbuf); + getStringToken(msgWN[i], '|', 3, sizeof(fmnamebuf)-1, fmnamebuf); + makeStringFromEscaped( fmnamebuf ); + getStringToken(msgWN[i], '|', 4, sizeof(namebuf)-1, namebuf); + makeStringFromEscaped( namebuf ); + getStringToken(msgWN[i], '|', 5, sizeof(dpbuf)-1, dpbuf); + getStringToken(msgWN[i], '|', 6, sizeof(makecolor)-1, makecolor); + if( strcmp(makecolor,"1") == 0 ) lnmake = i; + sprintf_s(msgWN[i], " %-9s%-19s%-17s%12s", lvbuf, fmnamebuf, namebuf, dpbuf); + } + } + } +} + +// 家族强者表 +void FMWindowType3( void ) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + static int msgLine; + static int fmdelid; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id, id2; + int i, j; + int mask; + int btn; + + if( ptActMenuWin == NULL ) + { + winW = 8; + winH = 7; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ) + { + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for( i = 0; i < 10; i++, mask <<= 1 ) + { + if( buttonTypeWN & mask ) + { + btnCnt++; + if( btnCnt == 4 ) + break; + } + } + if( btnCnt > 0 ) + { + int w; + w = winW*64/(btnCnt+1); + for( i = 0; i < btnCnt; i++ ) + { + btnLoc[i][0] = w * (i+1) - 27; + btnLoc[i][1] = 295; + } + } + msgLine = 10; + play_se( 202, 320, 240 ); + } + + if( ptActMenuWin != NULL ) + { + id = selFontId( btnId, sizeof( btnId )/sizeof( int ) ); + + id2 = -1; + + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if( 0 <= id && id < 6 + || 0 <= id2 && id2 < 12 + || id == 100 ) + { + char data[256]; + char msg[256]; + if( id == 100 ) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if( 0 <= id && id < 6 ) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + if( id2 < 0 ) + id2 = 0; + sprintf_s( data, "%d|%d", FMdengonidex, id2 ); + makeEscapeString( data, msg, sizeof( msg )-1 ); + + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ) ; + windowTypeWN = -1; + } + if( id >= 0 || id2 >= 0) { + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + if( ptActMenuWin->hp >= 1 ) + { + StockFontBuffer( winX+34, winY+21, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ‘史上最强之家族强者排行榜’", 0 ); + StockFontBuffer( winX+39, winY+16+2*21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘名 次’ ‘家 族 名 称’ ‘族 长 名 称’ ‘家族声望值’", 0 ); + for( i = 0; i < msgLine; i++ ) + { + if( strlen( msgWN[i] ) > 0 ) + { + int fontcolor = FONT_PAL_WHITE; + if( lnmake != 0){ + fontcolor = FONT_PAL_GRAY; + if( lnmake == i ) fontcolor = FONT_PAL_WHITE; + } + if( ixSize-w)/2; + y = (lpDraw->ySize-h)/2; + + ptActMenuWin = MakeWindowDisp( x, y, w, h, NULL, -1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + //InitItem4( 325, 230 ); + play_se( 202, 320, 240 ); // ???????? + + } + + if( ptActMenuWin->hp >= 1 ) + { + + selBtnId = focusGraId( btnId, sizeof( btnId )/sizeof( int ) ); + selFontBtnId = focusFontId( fontId, sizeof( fontId )/sizeof( int ) ); + + if( mouse.onceState & MOUSE_LEFT_CRICK ) + { + switch( selBtnId ) { + case 0: + closeItemmanWN(); + return 0; + case 1: + if( poolPage+1 > 1 ) + poolPage --; + break; + case 2: + if( poolPage+1 < (havenum/7)+1 ) + poolPage ++; + break; + } + + if( selFontBtnId != -1 ) { + sprintf_s( buf, "B|I|%d", myPool[(poolPage*7)+selFontBtnId].index ); + if( bNewServer) + lssproto_FM_send( sockfd, buf ); + else + old_lssproto_FM_send( sockfd, buf ); + return 0; + } + } + + if( (selFontBtnId>=0)&&(selFontBtnId<15) ) { + StockFontBuffer( x+110, y+300, FONT_PRIO_FRONT, 0, myPool[(poolPage*7)+selFontBtnId].name, 0 ); + StockFontBuffer( x+110, y+320, FONT_PRIO_FRONT, 0, myPool[(poolPage*7)+selFontBtnId].memo, 0 ); + StockDispBuffer( x + 65, y + 345, DISP_PRIO_IME3, myPool[(poolPage*7)+selFontBtnId].graNo, 0 ); + } + + for( i= 0 ; i< 7 ; i++ ) + { + fontId[i] = StockFontBuffer( x+34, y+120+(i*21), + FONT_PRIO_FRONT, 0, myPool[(poolPage*7)+i].name, 2 ); + } + + btnId[0] = StockDispBuffer( x + 220, y + 400, DISP_PRIO_IME3, CG_CANCEL_BTN, 2 ); + btnId[1] = StockDispBuffer( x +32, y+100, DISP_PRIO_IME3, prevBtnGraNo[prevBtn], 2 ); + btnId[2] = StockDispBuffer( x+200, y+100, DISP_PRIO_IME3, nextBtnGraNo[nextBtn], 2 ); + sprintf_s( buf, "%2d/%2d 页", poolPage+1, (havenum/7)+1 ); + StockFontBuffer( x +66, y+92, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + StockFontBuffer( x+175, y+18, FONT_PRIO_FRONT, 0, "家族寄物处", 0 ); + StockDispBuffer( x+w/2, y+h/2, DISP_PRIO_MENU, CG_ITEMSHOP_WIN, 1 ); + } + return 0; +} + +#endif + +// 删除人物输入密码的视窗 +// return: 0 ... 处理中 +// 1 ... 按下OK +// 2 ... 按下Cancel +int DelCharGraColorWin(void) +{ + static int fontId[] = { -2, -2 }; + static BOOL bErr = FALSE; + static ACTION *ptActMenuWin = NULL; + int id; + int i; + static int x, y, w, h; + int ret = 0; + char msg[][8] = { + " 确定 ", + " 取消 " + }; + // 初始化 + if (selCharGraColorWinProcNo == 0){ + selCharGraColorWinProcNo = 1; + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + //视窗制作 + w = 3; + h = 2; + x = 250; + y = 180; + + w = 2; + x = 250; + + + ptActMenuWin = MakeWindowDisp(x, y, w, h, NULL, 1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x; + y = ptActMenuWin->y; +#endif + initStrBuffer(&passwd, x + 20, y + 44, 20, FONT_PAL_WHITE, FONT_PRIO_FRONT); + // 设定输入密码的StrBuffer + passwd.cnt = 0; + passwd.cursor = 0; + passwd.filterFlag = BLIND_TYPE; + GetKeyInputFocus(&passwd); + bErr = FALSE; + } + // 判断是否按下文字 + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + // 按下确定 + if (id == 0){ + ret = 1; + bErr = FALSE; + play_se(217, 320, 240); + + /* + char sztemp[32]; + CopyMemory(sztemp,szPassword,32); + ecb_crypt("f;encor1c",sztemp,32,DES_DECRYPT); + + if( passwd.cnt==strlen(sztemp) && !strncmp( sztemp, passwd.buffer, passwd.cnt)){ + ret = 1; + bErr = FALSE; + play_se( 217, 320, 240 ); + }else{ + passwd.cnt = 0; + passwd.cursor=0; + bErr = TRUE; + } + */ + } + else + // 按下取消 + if (id == 1){ + ret = 2; + play_se(217, 320, 240); // click声 + } + // 已经输入结果 + if (ret != 0){ + if (ptActMenuWin){ + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + } + // 是否指向文字 + id = focusFontId(fontId, sizeof(fontId) / sizeof(int)); + // 确定 + if (id == 0) + ShowBottomLineString(FONT_PAL_WHITE, "删除人物请先输入密码"); + else + // 取消 + if (id == 1) + ShowBottomLineString(FONT_PAL_WHITE, "取消删除人物"); + if (ptActMenuWin != NULL){ + // ????? + if (ptActMenuWin->hp >= 1){ + for (i = 0; i < sizeof(fontId) / sizeof(int); i++){ + + fontId[i] = StockFontBuffer(x + 20 + i * 48, y + 64, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, msg[i], 2); + + } + if (bErr) + StockFontBuffer(x + 20, y + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "输入错误请再试", 0); + else + StockFontBuffer(x + 20, y + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "请输入安全码", 0); + StockFontBuffer2(&passwd); + FlashKeyboardCursor(); // ??????????? + } + } + return ret; +} + + + + +// Robin 0712 + +struct FMPKData { + char time[6]; + char atkFMName[20]; + char defFMName[20]; + int readyTime; + int member; + int flag; + int win; +}; +FMPKData FMPKDataList[4]; +int serverTime; + +char winStr[][16] = +{ + "乱斗生存战", + "满场打飞战" +}; + + +void initFMPKListWN(char *data) +{ + int i; + char buf2[256]; + + getStringToken(data, '|', 1, sizeof(buf2)-1, buf2); + serverTime = atoi(buf2); + + for (i = 0; i < 4; i++) + { + getStringToken(data, '|', i * 7 + 2, sizeof(buf2)-1, buf2); + strcpy(FMPKDataList[i].time, buf2); + getStringToken(data, '|', i * 7 + 3, sizeof(buf2)-1, buf2); + strcpy(FMPKDataList[i].atkFMName, makeStringFromEscaped(makeStringFromEscaped(buf2))); + getStringToken(data, '|', i * 7 + 4, sizeof(buf2)-1, buf2); + strcpy(FMPKDataList[i].defFMName, makeStringFromEscaped(makeStringFromEscaped(buf2))); + getStringToken(data, '|', i * 7 + 5, sizeof(buf2)-1, buf2); + FMPKDataList[i].readyTime = atoi(buf2); + getStringToken(data, '|', i * 7 + 6, sizeof(buf2)-1, buf2); + FMPKDataList[i].member = atoi(buf2); + getStringToken(data, '|', i * 7 + 7, sizeof(buf2)-1, buf2); + FMPKDataList[i].flag = atoi(buf2); + getStringToken(data, '|', i * 7 + 8, sizeof(buf2)-1, buf2); + FMPKDataList[i].win = atoi(buf2); + + } + +} + + + +void FMPKListWN(int mode) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + //static int msgLine; + //static STR_BUFFER input; + char dataBuf[512]; + char dataBuf2[256]; + char buf[256]; + + char *dataStatusStr[] = + { + " 新 增 ", + " 修 改 ", + " 接 受 ", + "设 定 中", + "等待回答", + "已 排 定" + }; + int showcolor; + int pushStatus; + + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + + static int totalMsgLine; + static int lineSkip; + + + if (ptActMenuWin == NULL) + { + winW = 8; + winH = 8; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = winH * 48 - 40; + } + } + + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + + // OK + if (0 <= id && id < 6) + { + //char msg[256]; + btn = 1; + btn <<= id; + + //makeEscapeString( input.buffer, msg, sizeof( msg )-1 ); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + + windowTypeWN = -1; + + } + else if ((6 <= id) && (id < 10)) + { + + int dataSel = id - 6; + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, FMPKDataList[dataSel].time); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, FMPKDataList[dataSel].time); + } + + + if (id >= 0) + { + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + + + j = 0; + + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + + + StockFontBuffer(winX + 200, winY + 30, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "家族对战时间表", 0); + sprintf_s(dataBuf, "目前时间: %d:%d", serverTime / 100, serverTime % 100); + StockFontBuffer(winX + 360, winY + 45, FONT_PRIO_FRONT, FONT_PAL_WHITE, + dataBuf, 0); + //StockDispHLine( winX+80, winY+30, 2 ); + + sprintf_s(dataBuf, "%10s %16s %16s %8s %8s" + , "开战时间", "挑战家族", "受邀家族" + , "准备时间", "参加人数"); + + StockFontBuffer(winX + 20, winY + 70, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + for (i = 0; i < 4; i++) + { + //char min[3], sec[3]; + int pktime = atoi(FMPKDataList[i].time); + if (pktime >= 10000) { + //if( strlen(FMPKDataList[i].time) > 4 ) { + //sscanf_s(FMPKDataList[i].time+1, "%2s%2s", min, sec); + //sprintf_s( buf, "明天 %d:%d", (pktime-10000)/100, pktime%100 ); + sprintf_s(buf, "明天 %d:00", (pktime - 10000) / 100); + //sprintf_s( buf, "明天 %s:%s", min, sec ); + } + else { + //sscanf_s(FMPKDataList[i].time, "%2s%2s", min, sec); + //sprintf_s( buf, "今天 %d:%d", pktime/100, pktime%100 ); + sprintf_s(buf, "今天 %d:00", pktime / 100); + //sprintf_s( buf, "今天 %s:%s", min, sec ); + } +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( winX+36, winY+90+(i*60), 7 ); +#endif + + if (FMPKDataList[i].flag != -1) + { + sprintf_s(dataBuf, "%10s %16s %16s %4d分钟 %6d人" + , buf, FMPKDataList[i].atkFMName, FMPKDataList[i].defFMName + , FMPKDataList[i].readyTime, FMPKDataList[i].member); + sprintf_s(dataBuf2, "胜利条件: %s", winStr[FMPKDataList[i].win]); + + switch (FMPKDataList[i].flag) { + case -1: + showcolor = FONT_PAL_WHITE; + pushStatus = 2; + break; + case 0: + case 1: + showcolor = FONT_PAL_YELLOW; + pushStatus = 2; + break; + case 2: + case 3: + showcolor = FONT_PAL_GREEN; + pushStatus = 0; + break; + case 4: + showcolor = FONT_PAL_RED; + pushStatus = 0; + break; + } +#ifdef _FMVER21 + if (pc.familyleader != FMMEMBER_LEADER) pushStatus = 0; +#else + if( pc.familyleader != 1) pushStatus = 0; +#endif + StockFontBuffer(winX + 20, winY + 106 + (i * 60), + FONT_PRIO_FRONT, showcolor, dataBuf, 0); + StockFontBuffer(winX + 50, winY + 130 + (i * 60), + FONT_PRIO_FRONT, showcolor, dataBuf2, 0); + + fontId[i + 6] = StockFontBuffer(winX + 400, winY + 100 + (i * 60) + 30, + FONT_PRIO_FRONT, showcolor, + dataStatusStr[FMPKDataList[i].flag + 1], pushStatus); + } + else + { + sprintf_s(dataBuf, "%10s", buf); + StockFontBuffer(winX + 20, winY + 106 + (i * 60), + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + +#ifdef _FMVER21 + if (pc.familyleader != FMMEMBER_LEADER) pushStatus = 0; +#else + if( pc.familyleader != 1) pushStatus = 0; +#endif + else pushStatus = 2; + fontId[i + 6] = StockFontBuffer(winX + 400, winY + 100 + (i * 60) + 30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, + dataStatusStr[0], pushStatus); + } + + } // for List end + + + + + + } + } +} + +struct FMPKSelect { + char fmname[16 + 1]; + int fmindex; +}; +FMPKSelect FMPKSelectData[8]; +int FMPKSelectNum; + +void initFMPKSelectWN(char *data) +{ + + int i; + char buf[256], buf2[256]; + + + getStringToken(data, '|', 1, sizeof(buf)-1, buf); + FMPKSelectNum = atoi(buf); + + for (i = 0; i < FMPKSelectNum; i++) + { + + getStringToken(data, '|', i * 2 + 2, sizeof(buf2)-1, buf2); + FMPKSelectData[i].fmindex = atoi(buf2); + getStringToken(data, '|', i * 2 + 3, sizeof(buf2)-1, buf2); + strcpy(FMPKSelectData[i].fmname, makeStringFromEscaped(buf2)); + + } + +} + +void FMPKSelectWN(int mode) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + //static int msgLine; + //static STR_BUFFER input; + char dataBuf[256]; + char buf[256]; + + //int dataStatus; + /* + char *dataStatusStr[] = + { + "未使用", + " 修改 ", + " 接受 ", + "设定中", + "等待回答", + "已排定" + }; + */ + + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + + static int totalMsgLine; + static int lineSkip; + + + if (ptActMenuWin == NULL) + { + //winW = msgWN_W; + //winH = msgWN_H; + winW = 4; + winH = 8; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + //lineSkip = 20; + //totalMsgLine = (winH*48-56)/lineSkip; + + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = winH * 48 - 56; + } + } + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + + // OK + if (0 <= id && id < 6) + { + //char msg[256]; + btn = 1; + btn <<= id; + + //makeEscapeString( input.buffer, msg, sizeof( msg )-1 ); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + + windowTypeWN = -1; + + } + else if ((6 <= id) && (id < 6 + 8)) + { + + + int dataSel = id - 6; + sprintf_s(dataBuf, "%d|%s", FMPKSelectData[dataSel].fmindex, + makeEscapeString(FMPKSelectData[dataSel].fmname, buf, sizeof(buf))); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, dataBuf); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, dataBuf); + } + + + if (id >= 0) + { + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + + + j = 0; + + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + + sprintf_s(dataBuf, "%s", "请选择想挑战的家族:"); + StockFontBuffer(winX + 30, winY + 40, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + for (i = 0; i < FMPKSelectNum; i++) + { + sprintf_s(dataBuf, "%-16s", FMPKSelectData[i].fmname); + + fontId[i + 6] = StockFontBuffer(winX + 40, winY + 60 + (i * 30) + 30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, + dataBuf, 2); + + } // for List end + + } + } + +} + +struct FMPKDetail { + char time[4 + 1]; + char atkFMName[16 + 1]; + char defFMName[16 + 1]; + int readyTime; + int member; + int win; +}; +FMPKDetail FMPKDetailData; + + +void initFMPKDetailWN(char *data) +{ + + char buf2[256]; + + getStringToken(data, '|', 1, sizeof(buf2)-1, buf2); + strcpy(FMPKDetailData.time, makeStringFromEscaped(buf2)); + getStringToken(data, '|', 2, sizeof(buf2)-1, buf2); + strcpy(FMPKDetailData.atkFMName, makeStringFromEscaped(buf2)); + getStringToken(data, '|', 3, sizeof(buf2)-1, buf2); + strcpy(FMPKDetailData.defFMName, makeStringFromEscaped(buf2)); + getStringToken(data, '|', 4, sizeof(buf2)-1, buf2); + FMPKDetailData.readyTime = atoi(buf2); + getStringToken(data, '|', 5, sizeof(buf2)-1, buf2); + FMPKDetailData.member = atoi(buf2); + getStringToken(data, '|', 6, sizeof(buf2)-1, buf2); + FMPKDetailData.win = atoi(buf2); + +} + + + +void FMPKDetailWN(int mode) +{ + + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2, -2 }; + static int btnId[] = { -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + //static int msgLine; + //static STR_BUFFER input; + static int pushBtnFlag[4]; + int selBtnId; + char dataBuf[256]; + char buf[256]; + char buf2[256]; + + + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + + static int totalMsgLine; + static int lineSkip; + + + if (ptActMenuWin == NULL) + { + winW = 6; + winH = 8; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = winH * 48 - 56; + } + } + + play_se(202, 320, 240); + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + + // OK + if (0 <= id && id < 6) + { + btn = 1; + btn <<= id; + + sprintf_s(dataBuf, "%s|%s|%s|%d|%d|%d", + FMPKDetailData.time, + makeEscapeString(FMPKDetailData.atkFMName, buf, sizeof(buf)), + makeEscapeString(FMPKDetailData.defFMName, buf2, sizeof(buf2)), + FMPKDetailData.readyTime, + FMPKDetailData.member, + FMPKDetailData.win + ); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, dataBuf); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, dataBuf); + + windowTypeWN = -1; + + } + else if (id == 6) + { + FMPKDetailData.win++; + if (FMPKDetailData.win > 1) + FMPKDetailData.win = 0; + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + switch (selBtnId) { + case 0: + pushBtnFlag[0] = TRUE; + FMPKDetailData.readyTime++; + if (FMPKDetailData.readyTime > 40) + FMPKDetailData.readyTime = 1; + break; + case 1: + pushBtnFlag[1] = TRUE; + FMPKDetailData.readyTime--; + if (FMPKDetailData.readyTime < 1) + FMPKDetailData.readyTime = 40; + break; + case 2: + pushBtnFlag[2] = TRUE; + FMPKDetailData.member++; + if (FMPKDetailData.member > 50) + FMPKDetailData.member = 1; + break; + case 3: + pushBtnFlag[3] = TRUE; + FMPKDetailData.member--; + if (FMPKDetailData.member < 1) + FMPKDetailData.member = 50; + break; + + } + + + if (id >= 0 && id < 6) + { + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + return; + } + + int i; + for (i = 0; i < 4; i++) + { + if (mouse.state & MOUSE_LEFT_CRICK && pushBtnFlag[i] == TRUE) + pushBtnFlag[i] = TRUE; + else pushBtnFlag[i] = FALSE; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + + + j = 0; + + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + + StockFontBuffer(winX + 140, winY + 30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族对战申请表", 0); +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( winX+100, winY+50, 3 ); +#endif + + sprintf_s(dataBuf, "%s %s", "挑战家族:", FMPKDetailData.atkFMName); + StockFontBuffer(winX + 40, winY + 90, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + sprintf_s(dataBuf, "%s %s", "受邀家族:", FMPKDetailData.defFMName); + StockFontBuffer(winX + 40, winY + 90 + 40, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + sprintf_s(dataBuf, "准备时间: %d 分钟", FMPKDetailData.readyTime); + StockFontBuffer(winX + 40, winY + 90 + 80, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + btnId[0] = StockDispBuffer(winX + 190, winY + 98 + 80, DISP_PRIO_IME3, + CG_UP_BTN + pushBtnFlag[0], 2); + btnId[1] = StockDispBuffer(winX + 190 + 40, winY + 98 + 80, DISP_PRIO_IME3, + CG_DOWN_BTN + pushBtnFlag[1], 2); + + sprintf_s(dataBuf, "参加人数: %d 人", FMPKDetailData.member); + StockFontBuffer(winX + 40, winY + 90 + 120, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + btnId[2] = StockDispBuffer(winX + 190, winY + 98 + 120, DISP_PRIO_IME3, + CG_UP_BTN + pushBtnFlag[2], 2); + btnId[3] = StockDispBuffer(winX + 190 + 40, winY + 98 + 120, DISP_PRIO_IME3, + CG_DOWN_BTN + pushBtnFlag[3], 2); + + sprintf_s(dataBuf, "胜利条件: %s", winStr[FMPKDetailData.win]); + fontId[6] = StockFontBuffer(winX + 40, winY + 90 + 160, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 2); + + } + } + + +} + +int familyTax; +int familyTaxChange; +int haveGold; + +void initFamilyTaxWN(char * data) +{ + char buf[256]; + getStringToken(data, '|', 3, sizeof(buf)-1, buf); + familyTax = atoi(buf); + + familyTaxChange = familyTax; + haveGold = pc.gold; + + if (windowTypeWN != WINDOW_MESSAGETYPE_FAMILYTAX) + { + windowTypeWN = WINDOW_MESSAGETYPE_FAMILYTAX; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + } + +} + +void closeFamilyTaxWN() +{ + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; +} + +void familyTaxWN() +{ + + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2 }; + static int btnId[] = { -2, -2, -2, -2 }; + static int pushBtnFlag[4]; + static int taxGoldInc = 0, taxGoldDec = 0; + static int taxGoldCnt = 0; + int selBtnId; + char dataBuf[256]; + char buf[256]; + int id; + int i; + + + if (ptActMenuWin == NULL) + { + winW = 5; + winH = 4; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + play_se(202, 320, 240); + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + closeFamilyTaxWN(); + } + + + if (mouse.onceState & MOUSE_LEFT_CRICK) + + switch (selBtnId) { + case 0: + sprintf_s(buf, "B|T|%d", familyTaxChange - familyTax); + //sprintf_s( buf, "B|T|%d", 79000000 ); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeFamilyTaxWN(); + return; + break; + case 1: + closeFamilyTaxWN(); + return; + break; + } + + + +#if 1 + switch (selBtnId) { + + // Add Gold + case 2: + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && pushBtnFlag[2] == TRUE){ + + pushBtnFlag[2] = FALSE; + } + + if ((haveGold < CHAR_getMaxHaveGold()) && (familyTaxChange > 0)) { + + if (pushBtnFlag[2] == TRUE){ + + haveGold += taxGoldInc; + //bankGold -= bankGoldInc; + taxGoldCnt++; + + // ???? + if (taxGoldCnt >= 30){ + // ????????????? + taxGoldCnt = 0; + // ???????? + if (taxGoldInc == 0) { + taxGoldInc = 1; + } + else{ + // ????? + taxGoldInc *= 5; + // ???????? + if (taxGoldInc > 10000) { + taxGoldInc = 10000; + } + } + } + // ???????? + if (haveGold >= CHAR_getMaxHaveGold()) { + haveGold = CHAR_getMaxHaveGold(); + play_se(220, 320, 240); + } + if (haveGold >= pc.gold + familyTax) { + haveGold = pc.gold + familyTax; + play_se(220, 320, 240); + } + + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK) { + // ??? + haveGold++; + // ???????? + if (haveGold >= CHAR_getMaxHaveGold()) { + haveGold = CHAR_getMaxHaveGold(); + // ??? + play_se(220, 320, 240); + } + else { + // ????? + taxGoldInc = 0; + // ????????????? + taxGoldCnt = 0; + // ??????? + pushBtnFlag[2] = TRUE; + // ????? + play_se(217, 320, 240); + } + } + } + break; + + case 3: + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && pushBtnFlag[3] == TRUE){ + + pushBtnFlag[3] = FALSE; + } + + if (haveGold > 0 && (familyTax + (pc.gold - haveGold)) < MAX_FMBANKGOLD) { + + if (pushBtnFlag[3] == TRUE){ + + haveGold -= taxGoldDec; + //bankGold -= bankGoldInc; + taxGoldCnt++; + + // ???? + if (taxGoldCnt >= 30){ + // ????????????? + taxGoldCnt = 0; + // ???????? + if (taxGoldDec == 0) { + taxGoldDec = 1; + } + else{ + // ????? + taxGoldDec *= 5; + // ???????? + if (taxGoldDec > 10000) { + taxGoldDec = 10000; + } + } + } + // ???????? + if (haveGold < 0) { + haveGold = 0; + play_se(220, 320, 240); + } + if ((familyTax + (pc.gold - haveGold)) > MAX_FMBANKGOLD) { + haveGold = familyTax + pc.gold - MAX_FMBANKGOLD; + + play_se(220, 320, 240); + } + + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK) { + // ??? + haveGold--; + // ???????? + if (haveGold < 0) { + haveGold = 0; + // ??? + play_se(220, 320, 240); + } + else { + // ????? + taxGoldDec = 0; + // ????????????? + taxGoldCnt = 0; + // ??????? + pushBtnFlag[3] = TRUE; + // ????? + play_se(217, 320, 240); + } + } + } + break; + + } + + +#endif + + for (int i = 0; i < 4; i++) + { + if (mouse.state & MOUSE_LEFT_CRICK && pushBtnFlag[i] == TRUE) + pushBtnFlag[i] = TRUE; + else pushBtnFlag[i] = FALSE; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + sprintf_s(dataBuf, "%s 家族的帐户", pc.familyName); + StockFontBuffer(winX + 80, winY + 30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( winX+64, winY+50, 3 ); +#endif + StockFontBuffer(winX + 60, winY + 70, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "存 款:", 0); + + familyTaxChange = familyTax + (pc.gold - haveGold); + sprintf_s(dataBuf, "%10d", familyTaxChange); + StockFontBuffer(winX + 200, winY + 70, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + StockFontBuffer(winX + 60, winY + 120, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "现 金:", 0); + sprintf_s(dataBuf, "%10d", haveGold); + StockFontBuffer(winX + 200, winY + 120, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + btnId[3] = StockDispBuffer(winX + 190 + 40, winY + 105, DISP_PRIO_IME3, + CG_UP_BTN + pushBtnFlag[3], 2); + +#ifdef _FMVER21 + /*if( pc.familyleader == FMMEMBER_LEADER || + pc.familyleader == FMMEMBER_VICELEADER || + pc.familyleader == FMMEMBER_BAILEE) {*/ + if (pc.familyleader == FMMEMBER_LEADER || + pc.familyleader == FMMEMBER_ELDER) { +#else + if( pc.familyleader == 1 ) { +#endif + + btnId[2] = StockDispBuffer(winX + 190, winY + 105, DISP_PRIO_IME3, + CG_DOWN_BTN + pushBtnFlag[2], 2); + + btnId[0] = StockDispBuffer(winX + 100, winY + 160, DISP_PRIO_IME3, + CG_TRADE_OK_BTN, 2); + btnId[1] = StockDispBuffer(winX + 100 + 120, winY + 160, DISP_PRIO_IME3, + CG_TRADE_CANCEL_BTN, 2); + } + else + { + btnId[0] = StockDispBuffer(winX + 100, winY + 160, DISP_PRIO_IME3, + CG_TRADE_OK_BTN, 2); + btnId[1] = StockDispBuffer(winX + 100 + 120, winY + 160, DISP_PRIO_IME3, + CG_TRADE_CANCEL_BTN, 2); + //btnId[1] = StockDispBuffer( winX+160, winY+160, DISP_PRIO_IME3, + // CG_TRADE_OK_BTN, 2 ); + //StockFontBuffer( winX+60, winY+120, + // FONT_PRIO_FRONT, FONT_PAL_WHITE, "只有族长可以取款。", 0 ); + } + + + } + } + + +} + +int rideablePet[3]; +int showNum; + +void initShowRidePetWN(void) +{ + //int baseimageNo = pc.graNo - (pc.graNo % 5); + int leaderimageNo = 100700 + ((pc.baseGraNo - 100000) / 20) * 10 + (pc.familySprite) * 5; + int i = 0, j; + + rideablePet[0] = 0; + rideablePet[1] = 0; + rideablePet[2] = 0; + + + /* + if( pc.ridePetNo != -1 ) + { + for( j=0 ; j< sizeof(ridePetTable)/sizeof(tagRidePetTable) ; j++ ) + { + if( ridePetTable[j].rideNo == pc.graNo ) + { + baseimageNo = ridePetTable[j].charNo; + break; + } + } + + }else + baseimageNo = pc.graNo - (pc.graNo % 5); + */ + + for (j = 0; j < sizeof(ridePetTable) / sizeof(tagRidePetTable); j++) + { +#ifdef _LEADERRIDE + if( ridePetTable[j].charNo == pc.baseGraNo || + ( ridePetTable[j].charNo == leaderimageNo && pc.big4fm != 0 && pc.familyleader != FMMEMBER_APPLY && pc.familyleader != FMMEMBER_NONE ) ) +#else + if (ridePetTable[j].charNo == pc.baseGraNo) +#endif + { + rideablePet[i] = ridePetTable[j].petNo; + i++; + showNum = i; + if (i >= 3) break; + } + } +} + +static ACTION *pActPet12; +static ACTION *pActPet13; +static ACTION *pActPet14; + +void showRidePetWN(void) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2 }; + + static int btnLoc[6][2]; + static int btnCnt; + //static int msgLine; + //static STR_BUFFER input; + char dataBuf[256]; + char buf[256]; + + //int dataStatus; + /* + char *dataStatusStr[] = + { + "未使用", + " 修改 ", + " 接受 ", + "设定中", + "等待回答", + "已排定" + }; + */ + + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + int id; + int i, j; + int mask; + int btn; + + + static int totalMsgLine; + static int lineSkip; + + + if (ptActMenuWin == NULL) + { + //winW = msgWN_W; + //winH = msgWN_H; + winW = 7; + winH = 6; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + //lineSkip = 20; + //totalMsgLine = (winH*48-56)/lineSkip; + + + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + { + fontId[i] = -2; + } + + mask = 1; + btnCnt = 0; + for (i = 0; i < 6; i++, mask <<= 1) + { + if (buttonTypeWN & mask) + { + btnCnt++; + if (btnCnt == 4) + break; + } + } + + // ????????????? + if (btnCnt > 0) + { + int w; + w = winW * 64 / (btnCnt + 1); + for (i = 0; i < btnCnt; i++) + { + btnLoc[i][0] = w * (i + 1) - 27; + btnLoc[i][1] = winH * 48 - 35; + } + } + + play_se(202, 320, 240); // ???????? + } + + + if (ptActMenuWin != NULL) + { + // ????? + id = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + // ????????????????????? + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + DeathAction(pActPet12); + pActPet12 = NULL; + DeathAction(pActPet13); + pActPet13 = NULL; + DeathAction(pActPet14); + pActPet14 = NULL; + } + + // OK + if (0 <= id && id < 6) + { + //char msg[256]; + btn = 1; + btn <<= id; + + //makeEscapeString( input.buffer, msg, sizeof( msg )-1 ); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, btn, ""); + + windowTypeWN = -1; + + } + else if ((6 <= id) && (id < 6 + 8)) + { + + + int dataSel = id - 6; + sprintf_s(dataBuf, "%d|%s", FMPKSelectData[dataSel].fmindex, + makeEscapeString(FMPKSelectData[dataSel].fmname, buf, sizeof(buf))); + if (bNewServer) + lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, dataBuf); + else + old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, + WINDOW_BUTTONTYPE_OK, dataBuf); + } + + + if (id >= 0) + { + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + DeathAction(pActPet12); + pActPet12 = NULL; + DeathAction(pActPet13); + pActPet13 = NULL; + DeathAction(pActPet14); + pActPet14 = NULL; + return; + } + + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + + + j = 0; + + for (i = 0, mask = 1; i < 6; i++, mask <<= 1) + { + fontId[i] = -2; + if (buttonTypeWN & mask) + { + if (j < btnCnt) + { + fontId[i] = + StockFontBuffer(winX + btnLoc[j][0], winY + btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2); + j++; + } + } + } + + sprintf_s(dataBuf, "%s", "适合你骑乘的宠物种类如下:"); + StockFontBuffer(winX + 30, winY + 40, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + if (pActPet12 == NULL) + if (rideablePet[0] != 0) + pActPet12 = MakeAnimDisp(winX + 115, winY + 180, rideablePet[0], 0); + + if (pActPet13 == NULL) + if (rideablePet[1] != 0) + pActPet13 = MakeAnimDisp(winX + 335, winY + 180, rideablePet[1], 0); + + if (pActPet14 == NULL) + if (rideablePet[2] != 0) + pActPet14 = MakeAnimDisp(winX + 225, winY + 180, rideablePet[2], 0); + + sprintf_s(dataBuf, "%s", "赶快去把它们找出来吧!"); + StockFontBuffer(winX + 30, winY + 220, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0); + + } + } + +} + +char memberName[100][36]; +int memberIndex[100]; +int memberNum; +//int pagenum; +int changeWho; + +void initFamilyLeaderChange(char* data) +{ + + int i; + char buf[256], buf2[256]; + + pagenum = 1; + changeWho = -1; + getStringToken(data, '|', 4, sizeof(buf)-1, buf); + memberNum = atoi(buf); + + for (i = 0; i < memberNum; i++) + { + getStringToken(data, '|', 5 + i * 2, sizeof(buf2)-1, buf2); + memberIndex[i] = atoi(buf2); + getStringToken(data, '|', 5 + i * 2 + 1, sizeof(buf2)-1, buf2); + strcpy(memberName[i], makeStringFromEscaped(buf2)); + + } + +} + +void closeFamilyLeaderChangeWN() +{ + windowTypeWN = -1; + //wnCloseFlag = 0; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + changeWho = -1; +} + +void familyLeaderChangeWN() +{ + + static int winX, winY; + static int winW, winH; + static int fontId[30]; + static int fontId2[3]; + int selId, selId2; + //char buf[256]; + int i; + + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 8; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + for (i = 0; i < sizeof(fontId2) / sizeof(int); i++) + fontId2[i] = -2; + + play_se(202, 320, 240); + } + + + if (ptActMenuWin != NULL) + { + selId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + selId2 = selFontId(fontId2, sizeof(fontId2) / sizeof(int)); + //selBtnId = focusGraId( btnId, sizeof( btnId )/sizeof( int ) ); + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + //id = 100; + closeFamilyLeaderChangeWN(); + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + if (selId >= 0 && selId < 30) { + closeFamilyLeaderChangeWN(); + changeWho = (pagenum - 1) * 30 + selId; + windowTypeWN = WINDOW_MESSAGETYPE_LEADERSELECTQ; + return; + } + + switch (selId2) { + case 0: + closeFamilyLeaderChangeWN(); + return; + case 1: + pagenum--; + return; + case 2: + pagenum++; + return; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + StockFontBuffer(winX + 50, winY + 30, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "请选择家族成员:", 0); + + fontId2[0] = StockFontBuffer(winX + 300, winY + 350, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 离 开 ", 2); + + switch (pagenum) + { + case 1: + for (i = 0; i< memberNum; i++) + fontId[i] = StockFontBuffer(winX + 30 + (i / 10) * 50, winY + 60 + (i % 10) * 20, + FONT_PRIO_FRONT, FONT_PAL_WHITE, memberName[i], 2); + if (memberNum > 30) + fontId2[2] = StockFontBuffer(winX + 100, winY + 350, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + "下一页", 2); + break; + case 2: + for (i = 30; i 60) + fontId2[2] = StockFontBuffer(winX + 100, winY + 350, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + "下一页", 2); + break; + case 3: + for (i = 60; i < memberNum; i++) + fontId[i] = StockFontBuffer(winX + 30 + ((i - 60) / 10) * 50, winY + 60 + (i % 10) * 20, + FONT_PRIO_FRONT, FONT_PAL_WHITE, memberName[i], 2); + fontId2[1] = StockFontBuffer(winX + 30, winY + 350, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + "上一页", 2); + break; + } + + + + } + + + } + + +} + + +void familyLeaderChangeQWN() +{ + static int winX, winY; + static int winW, winH; + static int fontId[2]; + int selId; + char buf[256]; + int i; + + if (ptActMenuWin == NULL) + { + winW = 6; + winH = 2; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + selId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + //id = 100; + closeFamilyLeaderChangeWN(); + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + + switch (selId) { + case 0: + closeFamilyLeaderChangeWN(); + return; + case 1: + sprintf_s(buf, "L|CHANGE|Q|%d|%s", memberIndex[changeWho], memberName[changeWho]); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeFamilyLeaderChangeWN(); + return; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + sprintf_s(buf, "你确定要将族长的位子交给%s吗?", memberName[changeWho]); + StockFontBuffer(winX + 50, winY + 30, FONT_PRIO_FRONT, FONT_PAL_WHITE, + buf, 0); + + fontId[0] = StockFontBuffer(winX + 200, winY + 60, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 离 开 ", 2); + fontId[1] = StockFontBuffer(winX + 280, winY + 60, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 确 定 ", 2); + + } + + } + +} + +char oldLeaderName[36]; +int oldLeaderIndex; + +void initFamilyLeaderChangeA(char *data) +{ + char buf[64]; + + //windowTypeWN = -1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + + getStringToken(data, '|', 1, sizeof(buf)-1, buf); + strcpy(oldLeaderName, makeStringFromEscaped(buf)); + getStringToken(data, '|', 2, sizeof(buf)-1, buf); + oldLeaderIndex = atoi(buf); +} + +void familyLeaderChangeAWN() +{ + static int winX, winY; + static int winW, winH; + static int fontId[2]; + int selId; + char buf[256], buf2[64]; + int i; + + if (ptActMenuWin == NULL) + { + winW = 6; + winH = 3; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + selId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + //id = 100; + closeFamilyLeaderChangeWN(); + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + + switch (selId) { + case 0: + sprintf_s(buf, "L|CHANGE|A|0|%s|%d", + makeEscapeString(oldLeaderName, buf2, sizeof(buf2)), + oldLeaderIndex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeFamilyLeaderChangeWN(); + return; + case 1: + sprintf_s(buf, "L|CHANGE|A|1|%s|%d", + makeEscapeString(oldLeaderName, buf2, sizeof(buf2)), + oldLeaderIndex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + closeFamilyLeaderChangeWN(); + return; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + sprintf_s(buf, "%s 希望将族长的位子交给你,", oldLeaderName); + StockFontBuffer(winX + 50, winY + 30, FONT_PRIO_FRONT, FONT_PAL_WHITE, + buf, 0); + StockFontBuffer(winX + 50, winY + 60, FONT_PRIO_FRONT, FONT_PAL_WHITE, + "你要接受吗?", 0); + + fontId[0] = StockFontBuffer(winX + 200, winY + 105, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 不愿意 ", 2); + fontId[1] = StockFontBuffer(winX + 280, winY + 105, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 愿 意 ", 2); + + } + + } + +} + + +struct { + char name[64]; + int member; + char leadername[64]; + int rank; + int fmdp; + int personaldp; + int job; + int sprite; + char pktime[32]; + int pkaddress; + char pkopp[64]; + char pkdata[256]; +#ifdef _NEW_MANOR_LAW + int fmMomentum; + int momentum; +#endif +#ifdef _FAMILYBADGE_ + int badgeNo; +#endif +} mineFamily; + +void initMineFamilyDetail(char* data) +{ + + char ibuf[64]; + + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + + makeStringFromEscaped(data); + + getStringToken(data, '|', 1, sizeof(mineFamily.name) - 1, mineFamily.name); + makeStringFromEscaped(mineFamily.name); + getStringToken(data, '|', 2, sizeof(ibuf)-1, ibuf); + mineFamily.member = atoi(ibuf); + getStringToken(data, '|', 3, sizeof(mineFamily.leadername) - 1, mineFamily.leadername); + makeStringFromEscaped(mineFamily.leadername); + getStringToken(data, '|', 4, sizeof(ibuf)-1, ibuf); + mineFamily.rank = atoi(ibuf); + getStringToken(data, '|', 5, sizeof(ibuf)-1, ibuf); + mineFamily.fmdp = atoi(ibuf); + getStringToken(data, '|', 6, sizeof(ibuf)-1, ibuf); + mineFamily.personaldp = atoi(ibuf); + getStringToken(data, '|', 7, sizeof(ibuf)-1, ibuf); + mineFamily.job = atoi(ibuf); + if (mineFamily.job < 0) mineFamily.job = 0; + getStringToken(data, '|', 8, sizeof(ibuf)-1, ibuf); + mineFamily.sprite = atoi(ibuf); + /* + getStringToken( data, '|', 9, sizeof( buf )-1, buf ); + makeStringFromEscaped( buf ); + getStringToken( buf, ' ', 1, sizeof( mineFamily.pktime )-1, mineFamily.pktime ); + makeStringFromEscaped( mineFamily.pktime ); + getStringToken( buf, ' ', 2, sizeof( ibuf )-1, ibuf ); + mineFamily.pkaddress = atoi( ibuf ); + getStringToken( buf, ' ', 3, sizeof( mineFamily.pkopp )-1, mineFamily.pkopp ); + makeStringFromEscaped( mineFamily.pkopp ); + */ + getStringToken(data, '|', 9, sizeof(mineFamily.pkdata) - 1, mineFamily.pkdata); + makeStringFromEscaped(mineFamily.pkdata); +#ifdef _NEW_MANOR_LAW + getStringToken(data, '|', 10, sizeof(ibuf)-1, ibuf); + mineFamily.fmMomentum = atoi(ibuf); + getStringToken(data, '|', 11, sizeof(ibuf)-1, ibuf); + mineFamily.momentum = atoi(ibuf); +#endif +#ifdef _FAMILYBADGE_ + getStringToken(data, '|', 12, sizeof(ibuf)-1, ibuf); + mineFamily.badgeNo = atoi(ibuf); +#endif + + + +} + +void closeMineFamilyDetailWN() +{ + windowTypeWN = -1; + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; +} + +char *familyJobName[] = +{ + "未加入家族", + "一般成员", + "待 审 核", + " 族 长 ", + " 长 老 ", + // " 长 老 ", + // " 祭 司 ", + // "财 务 长", +}; + +char *familyTownName[] = +{ + "", + "萨姆吉尔庄园", + "玛丽娜丝庄园", + "加加庄园", + "卡鲁它那庄园" +}; + + +void mineFamilyDetailWN() +{ + + static int winX, winY; + static int winW, winH; + static int fontId[2]; + int selId; + char buf[256]; + //char timebuf[14]; + int i; + + if (ptActMenuWin == NULL) + { + winW = 7; + winH = 6; + winX = (lpDraw->xSize - winW * 64) / 2; + winY = (lpDraw->ySize - winH * 48) / 2; + + + ptActMenuWin = MakeWindowDisp(winX, winY, winW, winH, NULL, 1, FALSE); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for (i = 0; i < sizeof(fontId) / sizeof(int); i++) + fontId[i] = -2; + + play_se(202, 320, 240); + } + + if (ptActMenuWin != NULL) + { + selId = selFontId(fontId, sizeof(fontId) / sizeof(int)); + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + closeMineFamilyDetailWN(); + } + + if (mouse.onceState & MOUSE_LEFT_CRICK) + + switch (selId) { + case 0: + closeFamilyLeaderChangeWN(); + return; + } + + if (ptActMenuWin != NULL && ptActMenuWin->hp >= 1) + { + + StockFontBuffer(winX + 190, winY + 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族资料", 0); +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( winX+160, winY+40, 2 ); +#endif + + sprintf_s(buf, "家族名称:%s", mineFamily.name); + StockFontBuffer(winX + 30, winY + 60, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, "族长名称:%s", mineFamily.leadername); + StockFontBuffer(winX + 240, winY + 60, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + + sprintf_s(buf, "家族人数:%d", mineFamily.member); + StockFontBuffer(winX + 30, winY + 90, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, "守护精灵:%s", familySpriteName[mineFamily.sprite]); + StockFontBuffer(winX + 240, winY + 90, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); +#ifdef _NEW_MANOR_LAW + sprintf_s(buf, "声望排名:%d", mineFamily.rank); +#else + sprintf_s( buf, "家族排名:%d", mineFamily.rank ); +#endif + StockFontBuffer(winX + 30, winY + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, "家族声望:%d", mineFamily.fmdp); + StockFontBuffer(winX + 240, winY + 120, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + + sprintf_s(buf, "家族职位:%s", familyJobName[mineFamily.job]); + StockFontBuffer(winX + 30, winY + 150, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, "个人声望:%d", mineFamily.personaldp); + StockFontBuffer(winX + 240, winY + 150, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + +#ifdef _NEW_MANOR_LAW + sprintf_s(buf, "家族气势:%d", mineFamily.fmMomentum); + StockFontBuffer(winX + 240, winY + 180, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); + sprintf_s(buf, "个人气势:%d", mineFamily.momentum); + StockFontBuffer(winX + 240, winY + 210, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0); +#endif + +#ifdef _FAMILYBADGE_ + StockFontBuffer(winX + 30, winY + 210, FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族徽章:", 0); + StockDispBuffer(winX + 120, winY + 215, DISP_PRIO_IME4, mineFamily.badgeNo, 0); +#endif + StockFontBuffer(winX + 30, winY + 180, FONT_PRIO_FRONT, FONT_PAL_WHITE, "家族踢馆:", 0); +#ifdef _NEW_MANOR_LAW + StockFontBuffer(winX + 30, winY + 230, FONT_PRIO_FRONT, FONT_PAL_WHITE, mineFamily.pkdata, 0); +#else + StockFontBuffer( winX+30, winY+230, FONT_PRIO_FRONT, FONT_PAL_WHITE, mineFamily.pkdata , 0 ); +#endif + + /* + if( atoi( mineFamily.pktime ) >= 10000 ) { + sprintf_s( timebuf, "明天 %d:00", ( atoi( mineFamily.pktime )-10000)/100 ); + } + else { + sprintf_s( timebuf, "今天 %d:00", atoi( mineFamily.pktime )/100 ); + } + sprintf_s( buf, "%s %s %s", timebuf, familyTownName[mineFamily.pkaddress], mineFamily.pkopp ); + StockFontBuffer( winX+50, winY+240, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + */ + + fontId[0] = StockFontBuffer(winX + 180, winY + 250, FONT_PRIO_FRONT, FONT_PAL_YELLOW, + " 离 开 ", 2); + } + + } + +} + +//Terry add 2001/12/06 +#ifdef __EDEN_EFFECT +ACTION *pBankProcWnd = NULL; + +void BankProc(void) +{ + static int BankBtNo[20]; // 按钮的编号 + static int BankBtFlag[20]; // 按钮的状态 + static int Gold = 0; // 要存入或取出的钱 + static int BankGoldInc = 0; // 金钱每加一次的值 + static int BankGoldCnt = 0; // 按钮计数 + int x, y; + char msg[256]; + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + if (pBankProcWnd != NULL) + { + windowTypeWN = -1; + DeathAction(pBankProcWnd); + pBankProcWnd = NULL; + play_se(217, 320, 240); + return; + } + } + + // 如果目前没有秀出银行介面 + if (pBankProcWnd == NULL) + { + // 秀出银行介面 +#ifdef _READ16BITBMP + if(g_bUseAlpha) pBankProcWnd = MakeWindowDisp(185,160,270,160,OLD_GRAPHICS_START+46,-1); //x=(640-w)/2 y=(480-h)/2 w=270 h=160 + else +#endif + pBankProcWnd = MakeWindowDisp(185, 160, 270, 160, 26287, -1); //x=(640-w)/2 y=(480-h)/2 w=270 h=160 + Gold = 0; + // 播音效 + play_se(202, 320, 240); + } + else + { + // 如果视窗已经开好了 + if (pBankProcWnd->hp > 0) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // 如果按下的是取消,清掉介面 + if (HitDispNo == BankBtNo[0]) + { + ZeroMemory(msg, sizeof(msg)); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 0, msg); + windowTypeWN = -1; + DeathAction(pBankProcWnd); + pBankProcWnd = NULL; + play_se(217, 320, 240); + return; + } + // 如果按下的是确定,把玩家存或领多少钱送给gs + if (HitDispNo == BankBtNo[1]) + { + sprintf_s(msg, "%d", Gold); + pc.gold -= Gold; + pc.personal_bankgold += Gold; + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 4, msg); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, 4, msg); + + windowTypeWN = -1; + DeathAction(pBankProcWnd); + pBankProcWnd = NULL; + play_se(217, 320, 240); + return; + } + } + + // 玩家存钱 + if (HitDispNo == BankBtNo[3]) + { + // 如果按钮被放开了(滑鼠左键放开),设定按钮没被按下 + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && BankBtFlag[3] == TRUE) BankBtFlag[3] = FALSE; + + // 如果要存入的钱加上已在银行里的钱比银行上限小及玩家身上的钱不小于要存入的钱 + if (Gold + pc.personal_bankgold <= MAX_PERSONAL_BANKGOLD && pc.gold - Gold > 0) + { + // 存入的按钮设为true(此时为一直按着钮的状态) + if (BankBtFlag[3] == TRUE) + { + Gold += BankGoldInc; + BankGoldCnt++; + + // 如果BankGoldCnt大于30,增加一次的钱变为五倍 + if (BankGoldCnt >= 30) + { + // 把count清为0 + BankGoldCnt = 0; + if (BankGoldInc == 0) BankGoldInc = 1; + else + { + // 增加变为五倍 + BankGoldInc *= 5; + // 最多一次加10000 + if (BankGoldInc > 10000) BankGoldInc = 10000; + } + } + // 如果存入的钱比银行上限大 + if (Gold + pc.personal_bankgold >= MAX_PERSONAL_BANKGOLD) + { + Gold = MAX_PERSONAL_BANKGOLD - pc.personal_bankgold; + play_se(220, 320, 240); + } + // 如果玩家身上的钱已小于0 + if (pc.gold - Gold < 0) + { + Gold = pc.gold; + play_se(220, 320, 240); + } + } + + // 按下左键时 + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // 存入的钱增加 + Gold++; + // 如果存入的钱加上玩家已在银行里的钱大于银行上限 + if (Gold + pc.personal_bankgold >= MAX_PERSONAL_BANKGOLD) + { + Gold = MAX_PERSONAL_BANKGOLD - pc.personal_bankgold; + // 播音效 + play_se(220, 320, 240); + } + // 如果玩家身上的钱已小于0 + if (pc.gold - Gold < 0) + { + Gold = pc.gold; + play_se(220, 320, 240); + } + else + { + // 一次增加的钱清为0 + BankGoldInc = 0; + // 计数清为0 + BankGoldCnt = 0; + // 设定按钮被按下 + BankBtFlag[3] = TRUE; + // 播音效 + play_se(217, 320, 240); + } + } + } + else + { + BankGoldInc = 0; + BankGoldCnt = 0; + } + } + else + { + // 设定按键没被按下 + BankBtFlag[3] = FALSE; + } + + // 玩家领钱 + // 因为是领钱,所以Gold为负数 + if (HitDispNo == BankBtNo[2]) + { + // 如果按钮被放开了(滑鼠左键放开),设定按钮没被按下 + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && BankBtFlag[2] == TRUE) BankBtFlag[2] = FALSE; + // 如果要领出的钱比玩家已在银行里的钱少且领出的钱加上玩家身上的钱不大于玩家身上钱的上限 + if (pc.personal_bankgold + Gold > 0 && pc.gold - Gold <= CHAR_getMaxHaveGold()) + { + // 如果按钮被按下 + if (BankBtFlag[2] == TRUE) + { + // 领出的钱增加 + Gold -= BankGoldInc; + BankGoldCnt++; + + // 如果BankGoldCnt大于30,增加一次的钱变为五倍 + if (BankGoldCnt >= 30) + { + // 把count清为0 + BankGoldCnt = 0; + if (BankGoldInc == 0) BankGoldInc = 1; + else + { + // 增加变为五倍 + BankGoldInc *= 5; + // 最多一次加10000 + if (BankGoldInc > 10000) BankGoldInc = 10000; + } + } + // 如果要领出的钱比玩家已在银行里的钱多 + if (pc.personal_bankgold + Gold < 0) + { + Gold = pc.personal_bankgold * (-1); + play_se(220, 320, 240); + } + // 如果领出的钱加上玩家身上的钱大于玩家身上钱的上限 + if (pc.gold - Gold >= CHAR_getMaxHaveGold()) + { + Gold = (CHAR_getMaxHaveGold() - pc.gold) * (-1); + play_se(220, 320, 240); + } + } + // 按下左键时 + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + Gold--; + + // 如果要领出的钱比玩家已在银行里的钱多 + if (pc.personal_bankgold + Gold < 0) + { + Gold = pc.personal_bankgold * (-1); + play_se(220, 320, 240); + } + else + // 如果领出的钱加上玩家身上的钱大于玩家身上钱的上限 + if (pc.gold - Gold >= CHAR_getMaxHaveGold()) + { + Gold = (CHAR_getMaxHaveGold() - pc.gold) * (-1); + play_se(220, 320, 240); + } + else + { + // 一次增加的钱清为0 + BankGoldInc = 0; + // 计数清为0 + BankGoldCnt = 0; + // 设定按钮被按下 + BankBtFlag[2] = TRUE; + play_se(217, 320, 240); + } + } + } + else + { + BankGoldInc = 0; + BankGoldCnt = 0; + } + } + else + { + // 设定按键没被按下 + BankBtFlag[2] = FALSE; + } + + if (pBankProcWnd != NULL) + { + // 座标设定 + x = pBankProcWnd->x; + y = pBankProcWnd->y; + + BankBtNo[0] = StockDispBuffer(x + 200, y + 140, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN, 2); + BankBtNo[1] = StockDispBuffer(x + 75, y + 140, DISP_PRIO_IME3, CG_TRADE_OK_BTN, 2); + BankBtNo[2] = StockDispBuffer(x + 140, y + 74, DISP_PRIO_IME3, CG_UP_BTN + BankBtFlag[2], 2); + BankBtNo[3] = StockDispBuffer(x + 200, y + 74, DISP_PRIO_IME3, CG_DOWN_BTN + BankBtFlag[3], 2); + + sprintf_s(msg, "%7d", pc.gold - Gold); + StockFontBuffer(x + 180, y + 42, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "%7d", pc.personal_bankgold + Gold); + StockFontBuffer(x + 180, y + 90, FONT_PRIO_FRONT, 0, msg, 0); +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer(320,240,DISP_PRIO_IME3,OLD_GRAPHICS_START+46,1); + else +#endif + StockDispBuffer(lpDraw->xSize / 2, lpDraw->ySize / 2, DISP_PRIO_IME3, 26287, 1); + } + } + } +} +#endif +//Terry end + +// Terry add 2002/01/03 +#ifdef __EDEN_AUCTION +#define AUCTION_NEW 26266 //委托拍卖介面 +#define AUCTION_OK_U 26267 //ok按钮(未按下) +#define AUCTION_OK_D 26268 //ok按钮(按下) +#define AUCTION_PLANK 26269 //在物品底下的石板 +#define AUCTION_UP_U 26188 //上箭头按钮(未按下) +#define AUCTION_UP_D 26189 //上箭头按钮(按下) +#define AUCTION_DOWN_U 26190 //下箭头按钮(未按下) +#define AUCTION_DOWN_D 26191 //下箭头按钮(按下) +#define AUCTION_LIST 26270 //拍卖列表(购买)介面 +#define AUCTION_LIST_1 26271 //拍卖列表(修改)介面 +#define AUCTION_GET_BACK_U 26272 //领回按钮(未按下) +#define AUCTION_GET_BACK_D 26273 //领回按钮(按下) +#define AUCTION_GET_BACK_N 26274 //领回按钮(无作用) +#define AUCTION_SEE_DATA_U 26275 //观看资料(未按下) +#define AUCTION_SEE_DATA_D 26276 //观看资料(按下) +#define AUCTION_SEE_DATA_N 26277 //观看资料(无作用) +#define AUCTION_PAGE_UP_U 26278 //上一页(未按下) +#define AUCTION_PAGE_UP_D 26279 //上一页(按下) +#define AUCTION_PAGE_UP_N 26280 //上一页(无作用) +#define AUCTION_PAGE_DOWN_U 26281 //下一页(未按下) +#define AUCTION_PAGE_DOWN_D 26282 //下一页(按下) +#define AUCTION_PAGE_DOWN_N 26283 //下一页(无作用) +#define AUCTION_CANCEL_Y_U 26284 //取消(未按下)(黄色的) +#define AUCTION_CANCEL_Y_D 26285 //取消(按下)(黄色的) +#define AUCTION_CANCEL_Y_N 26286 //取消(无作用)(黄色的) +#define AUCTION_DECIDE_U 26289 //确定(未按下) +#define AUCTION_DECIDE_D 26288 //确定(按下) +#define AUCTION_CANCEL_R_U 26291 //取消(未按下)(红色的) +#define AUCTION_CANCEL_R_D 26290 //取消(按下)(红色的) +#define AUCTION_SURVEY 26292 //观看(购买)介面 +#define AUCTION_SURVEY_1 26293 //观看(修改)介面 +#define AUCTION_PET_STAT 26297 //宠物五种资料的底图 + +STR_BUFFER AuctionStr; // 拍卖叙述共,50个字 +STR_BUFFER AuctionMoney; // 拍卖价钱最多一百万 +STR_BUFFER AuctionItem; // 道具叙述 +ACTION *pActAuctionWT = NULL; + +void AuctionNewWT(void) +{ + static ACTION *pShowPet1 = NULL, *pShowPet2 = NULL; + static int nButton1[3][2]; // nBotton1[x][y]-> x:0->上箭头 x:1->ok x:2->下箭头 y:0->被点选时的按钮编号 + // y:1->点选状态 0->没被点选到 1->被点选到 + static int nButton2[2][2]; // nBotton2[x][y]-> x:0->确定 x:1->取消 y:0->被点选时的按钮编号 + // y:1->点选状态 0->没被点选到 1->被点选到 + static int nItem[MAX_ITEM - MAX_ITEMSTART][2]; // nItem[x][y]-> x:->第几个物品(右上开始向右算起0~14) y:0->被点选时的按钮编号 + // y:1->点选状态 0->没被点选到 1->被点选到 + static int nPet, nPetShow; // nPet:右边列表的宠物是第几只 nPetShow:要卖的宠物 + static int nItemSelect; // 目前选到的道具是第几个 + static int nAuctionKind; // 要拍卖的是宠物还是道具 1:Pet 2:Item + static BOOL bPress; + int x, y, i, j, k; + char temp[8]; + char szSendMsg[3][260]; // szSendMsg[x][256]-> x:0->拍卖叙述 x:1->送到server端的资料 + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + if (pActAuctionWT != NULL) + { + windowTypeWN = -1; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + DeathAction(pShowPet1); + pShowPet1 = NULL; + DeathAction(pShowPet2); + pShowPet2 = NULL; + play_se(217, 320, 240); + GetKeyInputFocus(&MyChatBuffer); + return; + } + } + // 如果目前没有产生委托介面 + if (pActAuctionWT == NULL) + { + // 产生委托介面 + pActAuctionWT = MakeWindowDisp(50, 15, 540, 450, AUCTION_NEW, -1); + ZeroMemory(szSendMsg, sizeof(szSendMsg)); + ZeroMemory(nButton1, sizeof(nButton1)); + ZeroMemory(nButton2, sizeof(nButton2)); + ZeroMemory(nItem, sizeof(nItem)); + for (i = 0; i < MAX_ITEM; i++) { +#ifdef _NEW_ITEM_ + extern int 道具栏页数; + int 道具起始 = MAX_ITEMSTART+MAX_MAXHAVEITEM*道具栏页数; + int 道具结束 = 道具起始+MAX_MAXHAVEITEM; + if(i>=MAX_ITEMSTART){ + if(i<道具起始||i>=道具结束) continue; + } + nItem[i][0] = -1; +#endif + + } + nPet = nPetShow = 0; + nItemSelect = 0; + pShowPet1 = pShowPet2 = NULL; + bPress = TRUE; + // 叙述文字初始化 + ZeroMemory(AuctionStr.buffer, sizeof(AuctionStr.buffer)); + AuctionStr.cnt = 0; + AuctionStr.cursor = 0; + AuctionStr.color = 0; + AuctionStr.len = 100; + AuctionStr.lineLen = 24; + AuctionStr.lineDist = 20; + AuctionStr.x = pActAuctionWT->x + 30; + AuctionStr.y = pActAuctionWT->y + 260; + AuctionStr.fontPrio = FONT_PRIO_FRONT; + // 价钱文字初始化 + ZeroMemory(AuctionMoney.buffer, sizeof(AuctionMoney.buffer)); + AuctionMoney.cnt = 0; + AuctionMoney.cursor = 0; + AuctionMoney.color = 0; + AuctionMoney.len = 7; + AuctionMoney.lineLen = 7; + AuctionMoney.lineDist = 0; + AuctionMoney.x = pActAuctionWT->x + 95; + AuctionMoney.y = pActAuctionWT->y + 387; + AuctionMoney.fontPrio = FONT_PRIO_FRONT; + // 道具叙述初始化 + ZeroMemory(AuctionItem.buffer, sizeof(AuctionItem.buffer)); + AuctionItem.cnt = 0; + AuctionItem.cursor = 0; + AuctionItem.color = 0; + AuctionItem.len = 100; + AuctionItem.lineLen = 28; + AuctionItem.lineDist = 20; + AuctionItem.x = pActAuctionWT->x + 26; + AuctionItem.y = pActAuctionWT->y + 170; + AuctionItem.fontPrio = FONT_PRIO_FRONT; + // 播音效 + play_se(202, 320, 240); + } + else + { + // 如果视窗已经开好了 + if (pActAuctionWT->hp > 0) + { + // 座标设定 + x = pActAuctionWT->x; + y = pActAuctionWT->y; + + // 如果滑鼠左键按着 + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 3; i++) + { + if (HitDispNo == nButton1[i][0] && !nButton1[i][1]) + { + nButton1[i][1] = 1; + bPress = TRUE; + } + if (i < 2) + { + if (HitDispNo == nButton2[i][0] && !nButton2[i][1]) + { + nButton2[i][1] = 1; + bPress = TRUE; + } + } + } + } + // 如果滑鼠左键放开 + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + for (i = 0; i < 3; i++) + { + if (nButton1[i][1]) nButton1[i][1] = 0; + if (i < 2) if (nButton2[i][1]) nButton2[i][1] = 0; + } + bPress = FALSE; + } + + for (i = 0; i < 3; i++) + { + for (j = 0; j < 5; j++) + { + if (MakeHitBox(x + 261 + j * 50 - 24, y + 272 + i * 48 - 24, x + 261 + j * 50 + 25, y + 272 + i * 48 + 23, DISP_PRIO_IME3) == TRUE) + { + // 如果滑鼠左键double-click + if (mouse.onceState & MOUSE_LEFT_DBL_CRICK) + { + for (k = 0; k < MAX_ITEM - MAX_ITEMSTART; k++) nItem[k][1] = 0; +#ifdef _NEW_ITEM_ + extern int 道具栏页数; + int 道具起始 = MAX_ITEMSTART+MAX_MAXHAVEITEM*道具栏页数; + int 道具结束 = 道具起始+MAX_MAXHAVEITEM; + if(i>=MAX_ITEMSTART){ + if(i<道具起始||i>=道具结束) continue; + } +#endif + nItem[i * 5 + j][1] = 1; + // 那一个道具被点选了 + nItemSelect = i * 5 + j + 5; + nAuctionKind = 2; + DeathAction(pShowPet2); + pShowPet2 = NULL; + play_se(217, 320, 240); + break; + } + } + } + } + + // 按下了确定 + if (nButton2[0][1] || nButton2[1][1]) + { + if (nButton2[0][1]) + { + // 若是要卖宠物 + if (nAuctionKind == 1) + { + CheckSpace(AuctionStr.buffer); + // 有这只宠物 + if (pet[nPetShow].useFlag == 1) + { + makeEscapeString(AuctionStr.buffer, szSendMsg[0], sizeof(AuctionStr.buffer)); + sprintf_s(szSendMsg[1], "1|%d|%s|%d", nPetShow, szSendMsg[0], atoi(AuctionMoney.buffer)); + makeEscapeString(szSendMsg[1], szSendMsg[2], sizeof(szSendMsg[1])); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, szSendMsg[2]); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, szSendMsg[2]); + } + } + // 若是要卖道具 + if (nAuctionKind == 2) + { + // 有这个道具 + if (pc.item[nItemSelect].useFlag == 1) + { + makeEscapeString(AuctionStr.buffer, szSendMsg[0], sizeof(AuctionStr.buffer)); + sprintf_s(szSendMsg[1], "2|%d|%s|%d", nItemSelect, szSendMsg[0], atoi(AuctionMoney.buffer)); + makeEscapeString(szSendMsg[1], szSendMsg[2], sizeof(szSendMsg[1])); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, szSendMsg[2]); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, szSendMsg[2]); + } + } + } + windowTypeWN = -1; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + DeathAction(pShowPet1); + pShowPet1 = NULL; + DeathAction(pShowPet2); + pShowPet2 = NULL; + play_se(217, 320, 240); + GetKeyInputFocus(&MyChatBuffer); + return; + } + + // 按下了上箭头 + if (nButton1[0][1] && bPress) + { + bPress = FALSE; + nPet = (nPet - 1 < 0 ? 4 : nPet - 1); + DeathAction(pShowPet1); + pShowPet1 = NULL; + // 秀宠物 + for (i = 0; i < MAX_PET; i++) + { + if (pet[nPet].useFlag == 1) + { + pShowPet1 = MakeAnimDisp(x + 235 + 70, y + 55 + 120, pet[nPet].graNo, 0); + break; + } + else nPet = (nPet - 1 < 0 ? 4 : nPet - 1); + } + play_se(217, 320, 240); + } + // 按下了ok + if (nButton1[1][1] && bPress) + { + nAuctionKind = 1; + bPress = FALSE; + nItem[nItemSelect - 5][1] = 0; + //if(nPetShow != nPet && pShowPet1 != NULL) + if (pShowPet1 != NULL) + { + nPetShow = nPet; + DeathAction(pShowPet2); + pShowPet2 = NULL; + // 秀要被拍卖的宠物 + if (pet[nPetShow].useFlag == 1) pShowPet2 = MakeAnimDisp(x + 15 + 70, y + 55 + 120, pet[nPetShow].graNo, 0); + } + play_se(217, 320, 240); + } + // 按下了下箭头 + if (nButton1[2][1] && bPress) + { + bPress = FALSE; + nPet = (nPet + 1 >= 5 ? 0 : nPet + 1); + DeathAction(pShowPet1); + pShowPet1 = NULL; + // 秀宠物 + for (i = 0; i < MAX_PET; i++) + { + if (pet[nPet].useFlag == 1) + { + pShowPet1 = MakeAnimDisp(x + 235 + 70, y + 55 + 120, pet[nPet].graNo, 0); + break; + } + else nPet = (nPet + 1 >= 5 ? 0 : nPet + 1); + } + play_se(217, 320, 240); + } + + // 滑鼠在叙述区内 + if (MakeHitBox(AuctionStr.x, AuctionStr.y, AuctionStr.x + 170, AuctionStr.y + 95, DISP_PRIO_BOX2) == TRUE) + { + GetKeyInputFocus(&AuctionStr); + } + + // 滑鼠在价钱区内 + if (MakeHitBox(AuctionMoney.x, AuctionMoney.y, AuctionMoney.x + 115, AuctionMoney.y + 18, DISP_PRIO_BOX2) == TRUE) + { + GetKeyInputFocus(&AuctionMoney); + } + + if (pActAuctionWT != NULL) + { + // 显示及设定button出现的位置 + nButton1[0][0] = StockDispBuffer(x + 485, y + 70, DISP_PRIO_IME3, AUCTION_UP_U + nButton1[0][1], 2); + nButton1[1][0] = StockDispBuffer(x + 484, y + 100, DISP_PRIO_IME3, AUCTION_OK_U + nButton1[1][1], 2); + nButton1[2][0] = StockDispBuffer(x + 485, y + 130, DISP_PRIO_IME3, AUCTION_DOWN_U + nButton1[2][1], 2); + nButton2[0][0] = StockDispBuffer(x + 312, y + 422, DISP_PRIO_IME3, AUCTION_DECIDE_U + nButton2[0][1], 2); + nButton2[1][0] = StockDispBuffer(x + 432, y + 422, DISP_PRIO_IME3, AUCTION_CANCEL_R_U, 2); + + // 显示玩家身上的道具 + for (i = 0; i < 3; i++) + { + for (j = 0; j < 5; j++) + { + // 如果这一栏有道具且没被点选到,秀在右下角的身上道具栏 + if (!nItem[i * 5 + j][1]) + { + // 秀道具图 + if (pc.item[i * 5 + j + 5].useFlag == 1) nItem[i * 5 + j][0] = StockDispBuffer(x + 262 + j * 50, y + 273 + i * 48, DISP_PRIO_ITEM, pc.item[i * 5 + j + 5].graNo, 0); + } + // 如果这一栏的道具被点选到,秀在左上角的要被拍卖的栏位 + else + { + // 秀道具图 + StockDispBuffer(x + 120, y + 125, DISP_PRIO_IME3, pc.item[i * 5 + j + 5].graNo, 0); + // 秀底下的石板 + StockDispBuffer(x + 120, y + 125, DISP_PRIO_IME3, AUCTION_PLANK, 0); + // 秀道具名称 + StockFontBuffer(x + 36, y + 28, FONT_PRIO_FRONT, 0, pc.item[i * 5 + j + 5].name, 0); + // 秀道具叙述 + strncpy_s(AuctionItem.buffer, pc.item[i * 5 + j + 5].memo, 64); + StockFontBuffer2(&AuctionItem); + } + } + } + // 显示玩家身上的宠物资料 + // 把选到的宠物资料秀在右边 + if (pet[nPet].useFlag == 1) + { + if (pShowPet1 != NULL) + { + // 秀宠物名称 + StockFontBuffer(x + 256, y + 28, FONT_PRIO_FRONT, 0, pet[nPet].name, 0); + // 秀宠物的属性 + _itoa_s(pet[nPet].level, temp, 10); + StockFontBuffer(x + 400, y + 58, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPet].atk, temp, 10); + StockFontBuffer(x + 400, y + 58 + 28, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPet].def, temp, 10); + StockFontBuffer(x + 400, y + 58 + 56, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPet].quick, temp, 10); + StockFontBuffer(x + 400, y + 58 + 84, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPet].maxHp, temp, 10); + StockFontBuffer(x + 400, y + 58 + 112, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPet].ai, temp, 10); + StockFontBuffer(x + 400, y + 58 + 140, FONT_PRIO_FRONT, 0, temp, 0); + } + // 如果有按下ok 把宠物资料秀在左边 + if (nAuctionKind == 1 && pShowPet2 != NULL) + { + // 秀宠物名称 + StockFontBuffer(x + 36, y + 28, FONT_PRIO_FRONT, 0, pet[nPetShow].name, 0); + // 秀宠物属性底下的底图 + StockDispBuffer(x + 180, y + 137, DISP_PRIO_IME3, AUCTION_PET_STAT, 0); + // 秀宠物的属性 + _itoa_s(pet[nPetShow].level, temp, 10); + StockFontBuffer(x + 180, y + 58, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPetShow].atk, temp, 10); + StockFontBuffer(x + 180, y + 58 + 28, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPetShow].def, temp, 10); + StockFontBuffer(x + 180, y + 58 + 56, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPetShow].quick, temp, 10); + StockFontBuffer(x + 180, y + 58 + 84, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPetShow].maxHp, temp, 10); + StockFontBuffer(x + 180, y + 58 + 112, FONT_PRIO_FRONT, 0, temp, 0); + _itoa_s(pet[nPetShow].ai, temp, 10); + StockFontBuffer(x + 180, y + 58 + 140, FONT_PRIO_FRONT, 0, temp, 0); + } + } + StockFontBuffer2(&AuctionStr); + CheckNumber(AuctionMoney.buffer, -1); + StockFontBuffer2(&AuctionMoney); + StockDispBuffer(320, 240, DISP_PRIO_IME3, AUCTION_NEW, 1); + } + } + } +} + + +void AuctionListWT(void) +{ + static ALD aldArea[10]; // server一次传最多十个委托的内容过来 + static int nButton[5][2]; // nButton[x][y]-> x:0->领回 x:1->观看资料 x:2->上一页 x:3->下一页 x:4->取消 + // y:0->被点选时的按钮编号 y:1->点选状态 0->没点选 1->有点选 2->无作用 + static int nList[10][2]; // 传来的十个委托有无被点选到 nList[x][y]-> x:0~9->十个委托内容 + // y:0->被点选时的按钮编号 y:1->点选状态 0->没点选 1->有点选 + static int nListSelect; // 选到第几个列表 + int x, y, i; + char temp[16], szSendMsg[2][260]; + static char id[16]; // 玩家的cd key + static BOOL bPress; + static BOOL bIsThisPlayerAuction; // 选到的选项是否为这个玩家的委托 + static int nListNum; // 列表的编号 + static int nCurrentPage; // 目前页数 + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + if (pActAuctionWT != NULL) + { + windowTypeWN = -1; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + bNewData = FALSE; + play_se(217, 320, 240); + return; + } + } + + if (bNewData == TRUE) + { + ZeroMemory(aldArea, sizeof(aldArea)); + AuctionGetString(0, aldArea); + bIsThisPlayerAuction = FALSE; + bNewData = FALSE; + nButton[2][1] = 2; + nButton[3][1] = 2; + if (buttonTypeWN & WINDOW_BUTTONTYPE_PRE) nButton[2][1] = 0; + if (buttonTypeWN & WINDOW_BUTTONTYPE_NEXT) nButton[3][1] = 0; + } + + // 如果目前没有产生委托介面 + if (pActAuctionWT == NULL) + { + // 产生委托介面 + pActAuctionWT = MakeWindowDisp(50, 15, 540, 450, AUCTION_LIST, -1); + ZeroMemory(nList, sizeof(nList)); + nButton[0][1] = 2; // 一开始设定为无作用 + nButton[1][1] = 2; + nButton[2][1] = 2; + if (!(buttonTypeWN & WINDOW_BUTTONTYPE_NEXT)) nButton[3][1] = 2; + else nButton[3][1] = 0; + nButton[4][1] = 0; + nListSelect = -1; + bPress = TRUE; + nListNum = 0; + bIsThisPlayerAuction = FALSE; + extern char szUser[]; + CopyMemory(id, szUser, 16); + ecb_crypt("f;encor1c", id, 16, DES_DECRYPT); + // 播音效 + play_se(202, 320, 240); + } + else + { + // 如果视窗已经开好了 + if (pActAuctionWT->hp > 0) + { + // 座标设定 + x = pActAuctionWT->x; + y = pActAuctionWT->y; + + // 如果滑鼠左键按着 + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 10; i++) + { + nList[i][1] = 0; + if (HitFontNo == nList[i][0]) + { + // 如果点选到这个委托的玩家是这个委托的原委托者 + if (!strcmp(aldArea[i].cdkey, id)) + { + bIsThisPlayerAuction = TRUE; + nButton[0][1] = 0; + } + else bIsThisPlayerAuction = FALSE; + nListSelect = i; + nList[i][1] = 1; + nButton[1][1] = 0; + bPress = TRUE; + } + if (i < 5) + { + if (HitDispNo == nButton[i][0] && nButton[i][1] == 0) + { + nButton[i][1] = 1; + bPress = TRUE; + } + } + } + } + // 如果滑鼠左键放开 + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + if (!bIsThisPlayerAuction) nButton[0][1] = 2; + else nButton[0][1] = 0; + nButton[1][1] = 2; + for (i = 0; i < 10; i++) + { + if (nList[i][1]) + { + nButton[1][1] = 0; + break; + } + } + } + // 按了领回或按了观看资料 传aldArea[nListSelect].index回去server + if (nButton[0][1] == 1 || nButton[1][1] == 1) + { + int type; + + if (nButton[0][1] == 1) type = WINDOW_BUTTONTYPE_OK; + else type = WINDOW_BUTTONTYPE_YES; + + ZeroMemory(szSendMsg, sizeof(szSendMsg)); + sprintf_s(szSendMsg[1], "%d|", aldArea[nListSelect].index); + makeEscapeString(szSendMsg[1], szSendMsg[0], sizeof(szSendMsg[0])); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, type, szSendMsg[0]); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, type, szSendMsg[0]); + + windowTypeWN = -1; + bNewData = FALSE; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + play_se(217, 320, 240); + return; + } + // 按了上一页或按了下一页 传aldArea[0].index回去server + if ((nButton[2][1] == 1 || nButton[3][1] == 1) && bPress) + { + int type; + + if (nButton[2][1] == 1) + { + type = WINDOW_BUTTONTYPE_PRE; + nListNum -= 10; + nCurrentPage = nListNum / 10 + 1; + } + else + { + type = WINDOW_BUTTONTYPE_NEXT; + nListNum += 10; + nCurrentPage = nListNum / 10 + 1; + } + ZeroMemory(szSendMsg, sizeof(szSendMsg)); + sprintf_s(szSendMsg[1], "%d|", aldArea[0].index); + makeEscapeString(szSendMsg[1], szSendMsg[0], sizeof(szSendMsg[0])); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, type, szSendMsg[0]); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, type, szSendMsg[0]); + bPress = FALSE; + } + // 如果按了取消 + if (nButton[4][1]) + { + StockDispBuffer(x + 439, y + 386, DISP_PRIO_IME3, AUCTION_CANCEL_Y_U + nButton[4][1], 2); + windowTypeWN = -1; + bNewData = FALSE; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + play_se(217, 320, 240); + return; + } + + // 显示及设定button出现的位置 + nButton[0][0] = StockDispBuffer(x + 102, y + 386, DISP_PRIO_IME3, AUCTION_GET_BACK_U + nButton[0][1], nButton[0][1] == 2 ? 0 : 2); + nButton[1][0] = StockDispBuffer(x + 172, y + 386, DISP_PRIO_IME3, AUCTION_SEE_DATA_U + nButton[1][1], nButton[1][1] == 2 ? 0 : 2); + nButton[2][0] = StockDispBuffer(x + 299, y + 386, DISP_PRIO_IME3, AUCTION_PAGE_UP_U + nButton[2][1], nButton[2][1] == 2 ? 0 : 2); + nButton[3][0] = StockDispBuffer(x + 369, y + 386, DISP_PRIO_IME3, AUCTION_PAGE_DOWN_U + nButton[3][1], nButton[3][1] == 2 ? 0 : 2); + nButton[4][0] = StockDispBuffer(x + 439, y + 386, DISP_PRIO_IME3, AUCTION_CANCEL_Y_U, 2); + // 秀出目前页数 + sprintf_s(temp, "%d/9 页", nCurrentPage); + StockFontBuffer(x + 420, y + 350, FONT_PRIO_FRONT, 0, temp, 0); + for (i = 0; i<10; i++) + { + if (strlen(aldArea[i].account) > 0) + { + // 秀出编号 + _itoa_s(nListNum + i, temp, 16, 10); + StockFontBuffer(x + 92, y + 110 + i * 25, FONT_PRIO_FRONT, 0, temp, 0); + // 秀出叙述 + // 修改列表 + if (windowTypeWN == WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY) + { + // 如果是这个玩家的委托,叙述秀红字;点选到秀黄字 + if (!strcmp(aldArea[i].cdkey, id)) nList[i][0] = StockFontBuffer(x + 132, y + 110 + i * 25, FONT_PRIO_FRONT, nListSelect == i ? FONT_PAL_YELLOW : FONT_PAL_RED, aldArea[i].account, 2); + // 其它的叙述不能点选秀白字 + else StockFontBuffer(x + 132, y + 110 + i * 25, FONT_PRIO_FRONT, 0, aldArea[i].account, 0); + } + // 购买列表 + else nList[i][0] = StockFontBuffer(x + 132, y + 110 + i * 25, FONT_PRIO_FRONT, nListSelect == i ? FONT_PAL_YELLOW : 0, aldArea[i].account, 2); + } + } + if (windowTypeWN == WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY) StockDispBuffer(244, 72, DISP_PRIO_IME3, AUCTION_LIST_1, 1); + StockDispBuffer(320, 240, DISP_PRIO_IME3, AUCTION_LIST, 1); + } + } +} + +void AuctionSurveyModifyWT(void) +{ + static ACTION *pShowPet = NULL; + static ALD ald; // 委托物的各项资料 + static int nButton[2][2]; // nButton[x][y]-> x:0->确定 x:1->取消 + // y:0->被点选时的按钮编号 y:1->点选状态 0->没点选 1->有点选 + static BOOL bPress; + int x, y, i; + char szSendMsg[2][8]; + char szPetAttrib[8]; + + if (CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + if (pActAuctionWT != NULL) + { + windowTypeWN = -1; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + GetKeyInputFocus(&MyChatBuffer); + play_se(217, 320, 240); + return; + } + } + // 如果目前没有产生购买介面 + if (pActAuctionWT == NULL) + { + // 产生购买介面 + pActAuctionWT = MakeWindowDisp(50, 15, 540, 450, AUCTION_SURVEY, -1); + ZeroMemory(&ald, sizeof(ald)); + ZeroMemory(nButton, sizeof(nButton)); + AuctionGetString(1, &ald); + bPress = FALSE; + // 叙述文字初始化 + strcpy(AuctionStr.buffer, ald.account); + AuctionStr.cnt = strlen(AuctionStr.buffer); + AuctionStr.cursor = strlen(AuctionStr.buffer); + AuctionStr.color = 0; + AuctionStr.len = 100; + AuctionStr.lineLen = 24; + AuctionStr.lineDist = 20; + AuctionStr.x = pActAuctionWT->x + 230; + AuctionStr.y = pActAuctionWT->y + 265; + AuctionStr.fontPrio = FONT_PRIO_FRONT; + // 价钱文字初始化 + strcpy(AuctionMoney.buffer, ald.money); + AuctionMoney.cnt = strlen(AuctionMoney.buffer); + AuctionMoney.cursor = strlen(AuctionMoney.buffer); + AuctionMoney.color = 0; + AuctionMoney.len = 100; + AuctionMoney.lineLen = 28; + AuctionMoney.lineDist = 20; + AuctionMoney.x = pActAuctionWT->x + 270; + AuctionMoney.y = pActAuctionWT->y + 385; + AuctionMoney.fontPrio = FONT_PRIO_FRONT; + // 道具叙述初始化 + if (ald.kind == 2) + { + strcpy(AuctionItem.buffer, ald.item_effect_string); + AuctionItem.cnt = 0; + AuctionItem.cursor = 0; + AuctionItem.color = 0; + AuctionItem.len = 100; + AuctionItem.lineLen = 28; + AuctionItem.lineDist = 20; + AuctionItem.x = pActAuctionWT->x + 220; + AuctionItem.y = pActAuctionWT->y + 200; + AuctionItem.fontPrio = FONT_PRIO_FRONT; + } + // 播音效 + play_se(202, 320, 240); + } + else + { + // 如果视窗已经开好了 + if (pActAuctionWT->hp > 0) + { + // 座标设定 + x = pActAuctionWT->x; + y = pActAuctionWT->y; + + // 如果滑鼠左键按着 + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + for (i = 0; i < 2; i++) if (HitDispNo == nButton[i][0]) nButton[i][1] = 1; + bPress = TRUE; + } + // 如果滑鼠左键放开 + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + for (i = 0; i < 2; i++) nButton[i][1] = 0; + bPress = FALSE; + } + // 如果按下确定或取消 + if (nButton[0][1] || nButton[1][1]) + { + if (nButton[0][1]) + { + ZeroMemory(szSendMsg, sizeof(szSendMsg)); + sprintf_s(szSendMsg[0], "%d|", ald.index); + makeEscapeString(szSendMsg[0], szSendMsg[1], sizeof(szSendMsg[0])); + if (bNewServer) lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, szSendMsg[1]); + else old_lssproto_WN_send(sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, szSendMsg[1]); + } + windowTypeWN = -1; + DeathAction(pActAuctionWT); + pActAuctionWT = NULL; + if (pShowPet != NULL) + { + DeathAction(pShowPet); + pShowPet = NULL; + } + GetKeyInputFocus(&MyChatBuffer); + play_se(217, 320, 240); + return; + } + + if (windowTypeWN == WINDOW_MESSAGETYPE_AUCTIONMODIFY) + { + // 滑鼠在叙述区内 + if (MakeHitBox(AuctionStr.x, AuctionStr.y, AuctionStr.x + 170, AuctionStr.y + 95, DISP_PRIO_BOX2) == TRUE) + { + GetKeyInputFocus(&AuctionStr); + } + + // 滑鼠在价钱区内 + if (MakeHitBox(AuctionMoney.x, AuctionMoney.y, AuctionMoney.x + 115, AuctionMoney.y + 18, DISP_PRIO_BOX2) == TRUE) + { + GetKeyInputFocus(&AuctionMoney); + } + } + + // 显示及设定button出现的位置 + nButton[0][0] = StockDispBuffer(x + 210, y + 433, DISP_PRIO_IME3, AUCTION_DECIDE_U, 2); + nButton[1][0] = StockDispBuffer(x + 320, y + 433, DISP_PRIO_IME3, AUCTION_CANCEL_R_U, 2); + // 显示委托人名字 + StockFontBuffer(x + 235, y + 22, FONT_PRIO_FRONT, 0, ald.name, 1); + // 若是宠物 + if (ald.kind == 1) + { + if (pShowPet == NULL) pShowPet = MakeAnimDisp(x + 280, y + 200, ald.grp_no, 0); + // 显示宠物名字 + StockFontBuffer(x + 235, y + 55, FONT_PRIO_FRONT, 0, ald.sellname, 1); + // 秀宠物属性底下的底图 + StockDispBuffer(x + 375, y + 170, DISP_PRIO_IME3, AUCTION_PET_STAT, 0); + // 秀宠物资料 + _itoa_s(ald.lv, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 90, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + _itoa_s(ald.act, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 120, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + _itoa_s(ald.def, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 148, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + _itoa_s(ald.dex, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 174, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + _itoa_s(ald.hp, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 202, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + _itoa_s(ald.loyal, szPetAttrib, 10); + StockFontBuffer(x + 375, y + 230, FONT_PRIO_FRONT, 0, szPetAttrib, 1); + } + else + { + // 显示道具名字 + StockFontBuffer(x + 235, y + 55, FONT_PRIO_FRONT, ald.name_color, ald.sellname, 1); + // 显示道具叙述 + StockFontBuffer2(&AuctionItem); + // 秀道具图 + StockDispBuffer(x + 315, y + 155, DISP_PRIO_IME3, ald.grp_no, 0); + // 秀底下的石板 + StockDispBuffer(x + 315, y + 155, DISP_PRIO_IME3, AUCTION_PLANK, 0); + } + // 秀出叙述及价钱 + StockFontBuffer2(&AuctionStr); + CheckNumber(AuctionMoney.buffer, -1); + StockFontBuffer2(&AuctionMoney); + + // 如果是修改委托内容,秀出"修改"的图把"购买"的字盖掉 + if (windowTypeWN == WINDOW_MESSAGETYPE_AUCTIONMODIFY) StockDispBuffer(x + 160, y, DISP_PRIO_IME3, AUCTION_SURVEY_1, 1); + StockDispBuffer(320, 240, DISP_PRIO_IME3, AUCTION_SURVEY, 1); + } + } +} + +void AuctionGetString(int nWhichOne, pALD ald) +{ + int i; + char buf[256]; + char temp[256]; + + ZeroMemory(buf, sizeof(buf)); + ZeroMemory(temp, sizeof(temp)); + makeStringFromEscaped(szpALD); + // 若是开了list + if (nWhichOne == 0) + { + for (i = 0; i < 10; i++) + { + getStringToken(szpALD, '|', i + 1, sizeof(buf), buf); + makeStringFromEscaped(buf); + getStringToken(buf, '|', 1, sizeof(temp), temp); // 索引值 + ald[i].index = atoi(temp); + getStringToken(buf, '|', 2, sizeof(ald[i].cdkey), ald[i].cdkey); // 委托人的cdkey + makeStringFromEscaped(ald[i].cdkey); + getStringToken(buf, '|', 3, sizeof(ald[i].account), ald[i].account); // 叙述 + makeStringFromEscaped(ald[i].account); + } + } + // 若是开了观看资料 + if (nWhichOne == 1) + { + getStringToken(szpALD, '|', 1, sizeof(temp), temp); // 索引值 + ald->index = atoi(temp); + getStringToken(szpALD, '|', 2, sizeof(ald->name), ald->name); // 委托人名字 + makeStringFromEscaped(ald->name); + getStringToken(szpALD, '|', 3, sizeof(ald->account), ald->account); // 叙述 + makeStringFromEscaped(ald->account); + getStringToken(szpALD, '|', 4, sizeof(ald->money), ald->money); // 价钱 + getStringToken(szpALD, '|', 5, sizeof(temp), temp); // 卖宠物或是物品 + ald->kind = atoi(temp); + getStringToken(szpALD, '|', 6, sizeof(buf), buf); // 取得宠物或是物品的资料 + makeStringFromEscaped(buf); + getStringToken(buf, '|', 1, sizeof(ald->sellname), ald->sellname); // 宠物或是物品的名称 + getStringToken(buf, '|', 2, sizeof(temp), temp); // 宠物或是物品的图号 + ald->grp_no = atoi(temp); + // 若是卖宠物 + if (ald[0].kind == 1) + { + getStringToken(buf, '|', 3, sizeof(temp), temp); // 宠物的等级 + ald->lv = atoi(temp); + getStringToken(buf, '|', 4, sizeof(temp), temp); // 宠物的攻 + ald->act = atoi(temp); + getStringToken(buf, '|', 5, sizeof(temp), temp); // 宠物的防 + ald->def = atoi(temp); + getStringToken(buf, '|', 6, sizeof(temp), temp); // 宠物的敏 + ald->dex = atoi(temp); + getStringToken(buf, '|', 7, sizeof(temp), temp); // 宠物的血 + ald->hp = atoi(temp); + getStringToken(buf, '|', 8, sizeof(temp), temp); // 宠物的忠诚 + ald->loyal = atoi(temp); + } + // 卖道具 + else + { + getStringToken(buf, '|', 3, sizeof(temp), temp); // 道具名称的颜色 0:白字 4:黄字 5:绿字 + ald->name_color = atoi(temp); + getStringToken(buf, '|', 4, sizeof(temp), temp); // 道具叙述 + makeStringFromEscaped(temp); + strncpy_s(ald->item_effect_string, temp, 64); + } + } +} + +// 检查价钱是否为数字 +void CheckNumber(char *buf, int num) +{ + int i; + + for (i = 0; i<(int)strlen(buf); i++) if (*(buf + i) < '0' || *(buf + i) > '9') *(buf + i) = '0'; + if (num > -1){ + if (atoi(buf) > num) sprintf_s(buf, 260, "%d", num); + } + else if (atoi(buf) > CHAR_getMaxHaveGold()) sprintf_s(buf, 260, "%d", CHAR_getMaxHaveGold()); +} + + +// 移走叙述内的空白 +void CheckSpace(char *buf) +{ + int i, j; + char *temp; + + for (i = 0; i < (int)strlen(buf); i++) + { + if (*(buf + i) == 0x20) + { + temp = (buf + i); + for (j = 0; j < (int)strlen(buf + i); j++) + { + *temp = *(temp + 1); + temp++; + } + i = 0; + } + } + strcat_s(buf, 260, "\0"); +} +#endif +// Terry end + +#ifdef _BLACK_MARKET +void closeBlackMarketWN(void) +{ + play_se(203, 320, 240); + DeathAction(ptActMenuWin); + ptActMenuWin = NULL; + windowTypeWN = -1; + sItem = -1; + GetKeyInputFocus(&MyChatBuffer); +} +void initBlackMarket(char *data){ + int i = 0; + char sTmp[128] = ""; + makeStringFromEscaped(data); + getStrSplit((char *)msgWN, data, sizeof(msgWN[0]), + sizeof(msgWN) / sizeof(msgWN[0]), sizeof(msgWN[0]) - 1); + for (i = 0; i < 12; i++){ + getStringToken(msgWN[i], '|', 1, sizeof(sTmp)-1, sTmp); + BMItem[i].iIndex = atoi(sTmp); + getStringToken(msgWN[i], '|', 2, sizeof(sTmp)-1, sTmp); + BMItem[i].iGraphicsNum = atoi(sTmp); + getStringToken(msgWN[i], '|', 3, sizeof(BMItem[i].iName) - 1, BMItem[i].iName); + } +} + +#ifdef _ADD_FAMILY_TAX // WON ADD 增加庄园税收 +void FMTAXWindowsType( void ) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2 }; + static int btnId[] = { -2, -2, -2, -2 }; + static int pushBtnFlag[4]; + + int selBtnId; + char dataBuf[256]; + char buf[256]; + int id ; + int i; + + static int fm_tax_num = 0; + + if( ptActMenuWin == NULL ) + { + winW = 5; + winH = 4; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + + + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); + +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for( i = 0; i < sizeof( fontId )/sizeof( int ); i++ ) + { + fontId[i] = -2; + } + + play_se( 202, 320, 240 ); + } + + + if( ptActMenuWin != NULL ) + { + id = selFontId( fontId, sizeof( fontId )/sizeof( int ) ); + selBtnId = focusGraId( btnId, sizeof( btnId )/sizeof( int ) ); + + if( CheckMenuFlag() + || (joy_trg[ 0 ] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + closeFamilyTaxWN(); + } + + + if( mouse.onceState & MOUSE_LEFT_CRICK ) + + switch( selBtnId ) { + case 0: + sprintf_s( buf, "L|TAX|%d|%d", 1, fm_tax_num); + if( bNewServer) + lssproto_FM_send( sockfd, buf ); + else + old_lssproto_FM_send( sockfd, buf ); + closeFamilyTaxWN(); + return; + break; + case 1: + closeFamilyTaxWN(); + return; + break; + } + + switch( selBtnId ) { + + // Dec TAX + case 2: + + if( mouse.onceState & MOUSE_LEFT_CRICK_UP && pushBtnFlag[2] == TRUE ){ + + pushBtnFlag[2] = FALSE; + } + + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + fm_tax_num-- ; + if(fm_tax_num <=0){ + fm_tax_num = 0; + play_se( 220, 320, 240 ); + } + } + + break; + + // Add TAX + case 3: + + if( mouse.onceState & MOUSE_LEFT_CRICK_UP && pushBtnFlag[3] == TRUE ){ + + pushBtnFlag[3] = FALSE; + } + + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + fm_tax_num++ ; + if(fm_tax_num >= 30){ + fm_tax_num = 30; + play_se( 220, 320, 240 ); + } + } + + break; + + } + + for( int i=0 ; i<4 ; i++ ) + { + if( mouse.state & MOUSE_LEFT_CRICK && pushBtnFlag[i] == TRUE ) + pushBtnFlag[i] = TRUE; + else pushBtnFlag[i] = FALSE; + } + + if( ptActMenuWin != NULL && ptActMenuWin->hp >= 1 ) + { + sprintf_s( dataBuf, "%s 庄园税率调整", pc.familyName ); + StockFontBuffer( winX+80, winY+30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0 ); +#ifdef _READ16BITBMP + if(!g_bUseAlpha) StockDispHLine( winX+64, winY+50, 3 ); +#endif + StockFontBuffer( winX+60, winY+70, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "税 率:", 0 ); + + sprintf_s( dataBuf, "%5d %", fm_tax_num ); + StockFontBuffer( winX+200, winY+70, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0 ); + + btnId[3] = StockDispBuffer( winX+190+40, winY+105, DISP_PRIO_IME3, + CG_UP_BTN + pushBtnFlag[3], 2 ); + +#ifdef _FMVER21 + if( pc.familyleader == FMMEMBER_LEADER || + pc.familyleader == FMMEMBER_ELDER) { +#else + if( pc.familyleader == 1 ) { +#endif + + btnId[2] = StockDispBuffer( winX+190, winY+105, DISP_PRIO_IME3, + CG_DOWN_BTN + pushBtnFlag[2], 2 ); + + btnId[0] = StockDispBuffer( winX+100, winY+160, DISP_PRIO_IME3, + CG_TRADE_OK_BTN, 2 ); + btnId[1] = StockDispBuffer( winX+100+120, winY+160, DISP_PRIO_IME3, + CG_TRADE_CANCEL_BTN, 2 ); + } + else + { + btnId[0] = StockDispBuffer( winX+100, winY+160, DISP_PRIO_IME3, + CG_TRADE_OK_BTN, 2 ); + btnId[1] = StockDispBuffer( winX+100+120, winY+160, DISP_PRIO_IME3, + CG_TRADE_CANCEL_BTN, 2 ); + + } + + } + } + + +} +#endif + +void BMWindowType(void) +{ + static int btnId[2]; + int selBtnId; + int x, y; + int i; + + x = 0; + y = 0; + + if (CheckMenuFlag() + || joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1) + { + closeBlackMarketWN(); + return; + } + + if (ptActMenuWin == NULL) + { + for (i = 0; i < 2; i++) + btnId[i] = -2; + ptActMenuWin = MakeWindowDisp(x + 100, y + 100, 100, 100, NULL, -1); +#ifdef _NEW_RESOMODE //800 600模式 + x = ptActMenuWin->x - 100; + y = ptActMenuWin->y - 100; +#endif + play_se(202, 320, 240); + } + else if (ptActMenuWin->hp >= 1) + { + selBtnId = focusGraId(btnId, sizeof(btnId) / sizeof(int)); + if (mouse.onceState&MOUSE_LEFT_CRICK) + { + switch (selBtnId) + { + case 0: + if (sItem != -1){ + lssproto_BM_send(sockfd, BMItem[sItem].iIndex); + closeBlackMarketWN(); + return; + } + break; + case 1: + closeBlackMarketWN(); + return; + break; + } + } + + for (i = 0; i < 12; i++){ + if (sItem == i) + StockBoxDispBuffer(x + sItem % 4 * 62 + 18, y + sItem / 4 * 48 + 28, x + sItem % 4 * 62 + 68, y + sItem / 4 * 48 + 68, DISP_PRIO_BOX2, 213, 0); + if (MakeHitBox(x + i % 4 * 62 + 18, y + i / 4 * 48 + 28, x + i % 4 * 62 + 68, y + i / 4 * 48 + 68, DISP_PRIO_BOX2)){ + char iName[64] = ""; + char *sp = BMItem[i].iName; + int j = 0; + int ip = 0; + char cp; + char Tmp[256] = ""; + char *iip; + + iip = Tmp; + + while (1){ + cp = BMItem[i].iName[ip++]; + + if (cp == NULL){ + *iip = '\0'; + StockFontBuffer(x + 20, y + 205 + j * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, Tmp, 1); + break; + } + + if (IsDBCSLeadByte(cp)){ + *iip++ = cp; + *iip++ = BMItem[i].iName[ip++]; + } + else{ + *iip++ = cp; + } + + if ((iip - Tmp) >= 33){ + *iip = '\0'; + StockFontBuffer(x + 20, y + 205 + j * 20, FONT_PRIO_FRONT, FONT_PAL_WHITE, Tmp, 1); + strcpy(Tmp, ""); + iip = Tmp; + j++; + } + } + + if (mouse.onceState&MOUSE_LEFT_CRICK){ + sItem = i; + } + StockDispBuffer(x + i % 4 * 62 + 46, y + i / 4 * 48 + 48, DISP_PRIO_IME3, BMItem[i].iGraphicsNum + 1, 1); + + if (BMItem[i].iGraphicsNum == 22268) strcpy(iName, "不知名的枪"); + else if (BMItem[i].iGraphicsNum == 22270) strcpy(iName, "不知名的兜"); + else if (BMItem[i].iGraphicsNum == 22272) strcpy(iName, "不知名的服"); + else if (BMItem[i].iGraphicsNum == 22274) strcpy(iName, "不知名的铠"); + else if (BMItem[i].iGraphicsNum == 22276) strcpy(iName, "不知名的斧头"); + else if (BMItem[i].iGraphicsNum == 22278) strcpy(iName, "不知名的回旋标"); + else if (BMItem[i].iGraphicsNum == 22280) strcpy(iName, "不知名的爪"); + else if (BMItem[i].iGraphicsNum == 22282) strcpy(iName, "不知名的棍棒"); + else if (BMItem[i].iGraphicsNum == 22284) strcpy(iName, "不知名的戒指"); + else if (BMItem[i].iGraphicsNum == 22286) strcpy(iName, "不知名的首饰"); + else if (BMItem[i].iGraphicsNum == 22288) strcpy(iName, "不知名的石"); + else if (BMItem[i].iGraphicsNum == 22290) strcpy(iName, "不知名的耳饰"); + StockFontBuffer(x + 20, y + 180, FONT_PRIO_FRONT, FONT_PAL_YELLOW, iName, 1); + } + StockDispBuffer(x + i % 4 * 62 + 46, y + i / 4 * 48 + 48, DISP_PRIO_IME3, BMItem[i].iGraphicsNum, 1); + } + + btnId[0] = StockDispBuffer(x + 80, y + 272, DISP_PRIO_IME3, CG_OK_BTN, 2); + btnId[1] = StockDispBuffer(x + 190, y + 272, DISP_PRIO_IME3, CG_EXIT_BTN, 2); + + StockDispBuffer(x + 140, y + 150, DISP_PRIO_IME3, CG_BM_WND, 1); + } +} +#endif + +#ifdef _NPC_SELLSTH +static int SellSthPage = 0; +static char SellHeadString[256]; +static char SellHeadMessage[256]; + +static int SellSthBtNo[5]; +static int SellSthBtFlag[5]; +static int SellSthSPetNum = -1; + +#define MAX_LISTNUM 12 +typedef struct _tagNSellSthList{ + int use; + char name[256]; + char headmess[256]; + char sellmess[256]; +}NSellSthList; +static NSellSthList SellSthList[MAX_LISTNUM]; + +typedef struct _tagNSellSthListView{ + int num; + char username[256]; + char headmess[256]; + char sellmess[256]; + int type; + char name[256]; + char freename[256]; + int tmp[7]; + char buf[7][256]; +}NSellSthListVies; +static NSellSthListVies SellSthListView; + +//ACTION *pSellSthFindProcWnd = NULL; +ACTION *pSellSthSellProcWnd = NULL; + +static int Inputsellforce=0; +STR_BUFFER SellSthInput; +STR_BUFFER SellSthMesInput; +static int SellSubCMD = 0; +static ACTION *SellSthActPet=NULL; +static int SelectSellSthLook = -1; + +void InitSellSth_Menu( char* data ) +{ + char buf[256], buf1[256]; + int i, count=0, ti; + + SellSubCMD = 400; + SelectSellSthLook = -1; + + for( i=0; ix ; + y = pSellSthSellProcWnd->y ; + + SellSthBtNo[0] = StockDispBuffer( x+280, y+410, DISP_PRIO_IME3, CG_TRADE_OK_BTN, 2); + SellSthBtNo[1] = StockDispBuffer( x+380, y+410, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN, 2); + + selSSthBtnId = focusGraId( SellSthBtNo, sizeof( SellSthBtNo )/sizeof( int ) ); + // selSSthFontBtnId = selFontId( SSthfontId, sizeof( SSthfontId )/sizeof( int ) ); + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + switch( selSSthBtnId){ + case 0: + { + char msg[256], data[256]; + sprintf_s( data, "%d", SellSthListView.num ); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_YES, msg ) ; + wnCloseFlag = 1; + } + break; + case 1: + { + char msg[256], data[256]; + sprintf_s( data, ""); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, msg ) ; + wnCloseFlag = 1; + } + + return; + } + + } + sprintf_s( buf, "拍卖玩家:%s", SellSthListView.username); + StockFontBuffer( x+220, y+50, FONT_PRIO_FRONT, 0, buf, 0 ); + StockDispBuffer( x+100, y+30, DISP_PRIO_DRAG, CG_TRADE_LINE, 0 ); + StockDispBuffer( x+230, y+30, DISP_PRIO_DRAG, CG_TRADE_LINE, 0 ); + + StockFontBuffer( x+220, y+386, FONT_PRIO_FRONT, 0, "如欲购买,按OK可以通知对方。", 0 ); + + StockFontBuffer( x+44, y+22, FONT_PRIO_FRONT, 0, SellSthListView.headmess, 0 ); + char *splitPoint = SellSthListView.sellmess; + y1 = y+80; + while( 1 ){ + if( strlen( splitPoint ) > 28 ){ + strncpy_s( buf, splitPoint, 28 ); + buf[ 28 ] = NULL; + if( GetStrLastByte( buf ) == 3 ){ + buf[ 27 ] = NULL; + splitPoint += 27; + }else{ + buf[ 28 ] = NULL; + splitPoint += 28; + } + StockFontBuffer( x+220, y1, FONT_PRIO_FRONT, 0, buf, 0 ); y1 += 20; + }else{ + strcpy( buf, splitPoint ); + StockFontBuffer( x+220, y1, FONT_PRIO_FRONT, 0, buf, 0 ); + break; + } + } + + StockFontBuffer( x+60, y+260, FONT_PRIO_FRONT, 0, SellSthListView.name, 0 ); + if( strlen( SellSthListView.freename) > 0 && + strcmp( SellSthListView.name, SellSthListView.freename ) ) + StockFontBuffer( x+60, y+280, FONT_PRIO_FRONT, 0, SellSthListView.freename, 0 ); + + if( SellSthListView.type == 1 ){//道具 + StockDispBuffer( x+80, y+200, DISP_PRIO_DRAG, SellSthListView.tmp[1], 0 ); + y1 = y+300; + x1 = x+40; + char *splitPoint = SellSthListView.buf[0]; + while( 1 ){ + if( strlen( splitPoint ) > 28 ){ + strncpy_s( buf, splitPoint, 28 ); + buf[ 28 ] = NULL; + if( GetStrLastByte( buf ) == 3 ){ + buf[ 27 ] = NULL; + splitPoint += 27; + }else{ + buf[ 28 ] = NULL; + splitPoint += 28; + } + StockFontBuffer( x1, y1, FONT_PRIO_FRONT, 0, buf, 0 ); y1 += 20; + }else{ + strcpy( buf, splitPoint ); + StockFontBuffer( x1, y1, FONT_PRIO_FRONT, 0, buf, 0 ); + break; + } + } + }else if( SellSthListView.type == 2 ){//宠物 + if ( SellSthActPet == NULL ) { + SellSthSPetNum = SellSthListView.tmp[0]; + SellSthActPet = MakeAnimDisp( x+120, y+220, SellSthSPetNum , 0 ); + } + + StockDispBuffer( x+50, y+320, DISP_PRIO_DRAG, CG_TRADE_LV_LINE, 0 ); + StockDispBuffer( x+140, y+320, DISP_PRIO_DRAG, CG_TRADE_HP_LINE, 0 ); + StockDispBuffer( x+50, y+342, DISP_PRIO_DRAG, CG_TRADE_ATK_LINE, 0 ); + StockDispBuffer( x+140, y+342, DISP_PRIO_DRAG, CG_TRADE_DEF_LINE, 0 ); + StockDispBuffer( x+50, y+366, DISP_PRIO_DRAG, CG_TRADE_DEX_LINE, 0 ); + +#ifdef _PET_2TRANS + if( SellSthListView.tmp[2] == 1 ) + StockFontBuffer( x+140, y+260, FONT_PRIO_FRONT, 0, "一转", 0 ); + else if( SellSthListView.tmp[2] == 2 ) + StockFontBuffer( x+140, y+260, FONT_PRIO_FRONT, 0, "二转", 0 ); +#else + if( SellSthListView.tmp[2] == 1 ) + StockFontBuffer( x+140, y+260, FONT_PRIO_FRONT, 0, "转", 0 ); +#endif + x1 = x+50; + y1 = y+100; + + sprintf_s( buf, "%d", SellSthListView.tmp[1] ); + StockFontBuffer( x1+6, y1+212, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", SellSthListView.tmp[3] ); + StockFontBuffer( x1+88, y1+212, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", SellSthListView.tmp[4] ); + StockFontBuffer( x1+6, y1+232, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", SellSthListView.tmp[5] ); + StockFontBuffer( x1+96, y1+232, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", SellSthListView.tmp[6] ); + StockFontBuffer( x1+6, y1+256, FONT_PRIO_FRONT, 0, buf, 0 ); + + x1 = x+300; + y1 = y+240; + int i; + for( i=0; i<7; i++){ + if( i != 0 ) y1+=22; + StockDispBuffer( x1, y1, DISP_PRIO_DRAG, CG_TRADE_SK1_LINE+i, 0 ); + StockFontBuffer( x1-26, y1-6, FONT_PRIO_FRONT, 0, SellSthListView.buf[i], 0 ); + } + } + } +} + +void SellSth_Menu( void ) +{ + int i, selSSthBtnId=-1; + + if(pSellSthSellProcWnd == NULL){ + pSellSthSellProcWnd = MakeWindowDisp( 185, 160, 270, 160, CG_AUCWND_DETAIL, -1); + play_se(202,320,240); + + for( i=0; i<10; i++){ + SellSthBtNo[i] = -1; + SellSthBtFlag[i] = 0; + } + return; + }else { + int x, y, x1, y1, h; + char buf[256]; + + x = pSellSthSellProcWnd->x ; + y = pSellSthSellProcWnd->y ; + + SellSthBtNo[0] = StockDispBuffer( x+360, y+220, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN,2); + SellSthBtNo[2] = StockDispBuffer( x+300, y-120, DISP_PRIO_IME3, CG_PREV_BTN + SellSthBtFlag[2],2); + SellSthBtNo[3] = StockDispBuffer( x+360, y-120, DISP_PRIO_IME3, CG_NEXT_BTN + SellSthBtFlag[3],2); + + sprintf_s( buf, "%d", SellSthPage); + StockFontBuffer( x+324, y-124, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + x1 = x-160; + y1 = y-102; + h= 26; + + + for( i=0; i 0 ){ + char msg[256], data[256]; + sprintf_s( data, ""); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_PRE, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_PRE, msg ) ; + SellSthBtFlag[2] = 1; + } + break; + case 3: + if( SellSthPage < 20 ){ + char msg[256], data[256]; + + sprintf_s( data, ""); + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_NEXT, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_NEXT, msg ) ; + SellSthBtFlag[3] = 1; + } + break; + } + }else if( mouse.onceState & MOUSE_LEFT_CRICK_UP ){ + switch( selSSthBtnId){ + case 1: + break; + case 2: + SellSthBtFlag[2] = 0; + break; + case 3: + SellSthBtFlag[3] = 0; + break; + } + } + StockDispBuffer( 320, 200, DISP_PRIO_IME3, CG_AUCWND_COLUMN, 1); + } + + +} +void SellSth_SellSub_MessUpItem( void) +{ + int selSSthBtnId; + int x, y, w, h, i; + if( pSellSthSellProcWnd == NULL){ + + x = lpDraw->xSize/2; + y = lpDraw->ySize/2; + w=500; + h=400; + pSellSthSellProcWnd = MakeWindowDisp( x-w/2, y-h/2, w, h, CG_TRADE_VIEWWND, -1); + play_se( 202, 320, 240); + + for( i=0; i<10; i++) + SellSthBtNo[i] = -1; + selSSthBtnId = -1; + return; + }else { + x = pSellSthSellProcWnd->x; + y = pSellSthSellProcWnd->y; + + int x1, y1, x2, y2; + int itemX=x+296, itemY=y+242; + int w=52, h=50; + int ls = 0; + static int selectI=-1; + static int selectP=-1; + + SellSthBtNo[0] = StockDispBuffer( x+ 10, y+354, DISP_PRIO_IME3, CG_TRADE_OK_BTN,2); + SellSthBtNo[1] = StockDispBuffer( x+ 100, y+354, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN,2); + + x1 = itemX - w/2; + x2 = itemX+w/2; + for( i=0; i<15; i++){ + if( i!=0 && i%5==0) itemY+=h; + if( pc.item[i+MAX_ITEMSTART].useFlag == 0 ) continue; + y1 = itemY-h/2; + y2 = itemY+h/2; + if( MakeHitBox( x1+(i%5)*w, y1, x2+(i%5)*w, y2, DISP_PRIO_BOX2 ) == TRUE ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + selectI = i+MAX_ITEMSTART; + selectP = -1; + if( SellSthActPet != NULL ){ + DeathAction( SellSthActPet); + SellSthActPet = NULL ; + } + } + } + if( selectI == i )StockBoxDispBuffer( x1+(i%5)*w, y1, x2+(i%5)*w, y2, DISP_PRIO_BOX2, 249, 0 ); + StockDispBuffer( itemX+(i%5)*w, itemY, DISP_PRIO_DRAG, pc.item[i+MAX_ITEMSTART].graNo, 0); + } + char buf[256]; + x1 = x+280;//-110; + y1 = y-9;//-48; + for( i=0; i<5; i++){ + if( i!= 0 ) y1 += 41; + if( pet[i].useFlag == 0 ) continue; + if( MakeHitBox( x1-20, y1, x1+256, y1+40, DISP_PRIO_BOX2 ) == TRUE ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + selectI = -1; + selectP = i; + } + } + if( selectP == i ) StockBoxDispBuffer( x1-20, y1, x1+256, y1+40, DISP_PRIO_BOX2, 249, 0 ); + sprintf_s( buf, "%s", pet[i].name); + StockFontBuffer( x1, y1, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + sprintf_s( buf, "%3d", pet[i].atk ); + StockFontBuffer( x1, y1+21, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + sprintf_s( buf, "%3d", pet[i].def ); + StockFontBuffer( x1+60, y1+21, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + sprintf_s( buf, "%3d", pet[i].quick ); + StockFontBuffer( x1+110, y1+21, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + sprintf_s( buf, "%3d", pet[i].maxHp ); + StockFontBuffer( x1+160, y1+21, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + sprintf_s( buf, "%3d", pet[i].level ); + StockFontBuffer( x1+220, y1+21, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 0 ); + + } + StockFontBuffer( x, y+2, FONT_PRIO_FRONT, FONT_PAL_WHITE, "请选择欲拍卖的宠物或道具:", 0 ); + if( selectI != -1 ){ + int kk = MAX_ITEMSTART; + StockDispBuffer( x+10, y+60, DISP_PRIO_DRAG, pc.item[selectI].graNo, 0 ); + StockFontBuffer( x+80, y+60, FONT_PRIO_FRONT, 0, pc.item[selectI].name, 0 ); + StockFontBuffer( x+80, y+80, FONT_PRIO_FRONT, 0, pc.item[selectI].name2, 0 ); + sprintf_s( buf, "数量:%2d", pc.item[selectI].pile); + StockFontBuffer( x, y+100, FONT_PRIO_FRONT, 0, buf, 0 ); + + sprintf_s( buf, "耐用:%s", pc.item[selectI].damage ); + StockFontBuffer( x+80, y+100, FONT_PRIO_FRONT, 0, buf, 0 ); + + y1 = y; + char *splitPoint = pc.item[selectI].memo; + while( 1 ){ + if( strlen( splitPoint ) > 28 ){ + strncpy_s( buf, splitPoint, 28 ); + buf[ 28 ] = NULL; + if( GetStrLastByte( buf ) == 3 ){ + buf[ 27 ] = NULL; + splitPoint += 27; + }else{ + buf[ 28 ] = NULL; + splitPoint += 28; + } + StockFontBuffer( x, y1 + 140, FONT_PRIO_FRONT, 0, buf, 0 ); y1 += 20; + }else{ + strcpy( buf, splitPoint ); + StockFontBuffer( x, y1 + 140, FONT_PRIO_FRONT, 0, buf, 0 ); + break; + } + } + + }else if( selectP != -1 ) { + if ( SellSthActPet == NULL ) { + SellSthSPetNum = pet[selectP].graNo; + SellSthActPet = MakeAnimDisp( x+20, y+170, SellSthSPetNum , 0 ); + }else if ( SellSthActPet != NULL && SellSthSPetNum != pet[selectP].graNo ) { + DeathAction( SellSthActPet); + SellSthActPet = NULL ; + SellSthSPetNum = pet[selectP].graNo; + SellSthActPet = MakeAnimDisp( x+20, y+170, pet[selectP].graNo, 0 ); + } + StockDispBuffer( x+160, y+70, DISP_PRIO_DRAG, CG_TRADE_LINE, 0 ); + + StockFontBuffer( x+100, y+60, FONT_PRIO_FRONT, 0, pet[selectP].name, 0 ); + if( strlen( pet[selectP].freeName) > 0 && strcmp( pet[selectP].name, pet[selectP].freeName) ) + StockFontBuffer( x+100, y+80, FONT_PRIO_FRONT, 0, pet[selectP].freeName, 0 ); + + StockDispBuffer( x, y+220, DISP_PRIO_DRAG, CG_TRADE_LV_LINE, 0 ); + StockDispBuffer( x+90, y+220, DISP_PRIO_DRAG, CG_TRADE_HP_LINE, 0 ); + StockDispBuffer( x, y+242, DISP_PRIO_DRAG, CG_TRADE_ATK_LINE, 0 ); + StockDispBuffer( x+90, y+242, DISP_PRIO_DRAG, CG_TRADE_DEF_LINE, 0 ); + StockDispBuffer( x, y+266, DISP_PRIO_DRAG, CG_TRADE_DEX_LINE, 0 ); + + sprintf_s( buf, "%d", pet[selectP].level ); + StockFontBuffer( x+6, y+214, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", pet[selectP].maxHp ); + StockFontBuffer( x+88, y+214, FONT_PRIO_FRONT, 0, buf, 0 ); + + sprintf_s( buf, "%d", pet[selectP].atk ); + StockFontBuffer( x+6, y+234, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", pet[selectP].def ); + StockFontBuffer( x+96, y+234, FONT_PRIO_FRONT, 0, buf, 0 ); + sprintf_s( buf, "%d", pet[selectP].quick ); + StockFontBuffer( x+6, y+258, FONT_PRIO_FRONT, 0, buf, 0 ); + } + + selSSthBtnId = focusGraId( SellSthBtNo, sizeof( SellSthBtNo )/sizeof( int ) ); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + char data[256], msg[256]; + switch( selSSthBtnId){ + case 0: + if( selectI != -1 ) { + sprintf_s( data, "%s|%s|1|%d", SellSthInput.buffer, SellSthMesInput.buffer, selectI); + }else if( selectP != -1 ) { + sprintf_s( data, "%s|%s|2|%d", SellSthInput.buffer, SellSthMesInput.buffer, selectP); + } + makeEscapeString( data, msg, sizeof( msg )-1 ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, msg ) ; + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, WINDOW_BUTTONTYPE_OK, msg ) ; + case 1: + wnCloseFlag = 1; + break; + } + } + + StockDispBuffer( 320, 220, DISP_PRIO_IME3, CG_TRADE_VIEWWND, 1); + } +} + +void SellSth_SellSub_MessRegist( void ) +{ + static int SSthfontId[2]; + int selSSthBtnId; + int selSSthFontBtnId; + int x, y, w, h, i; + + // 如果目前没有秀出银行介面 + if( pSellSthSellProcWnd == NULL){ + x = lpDraw->xSize/2; + y = lpDraw->ySize/2; + w=500; + h=400; + pSellSthSellProcWnd = MakeWindowDisp( x-w/2, y-h/2, w, h, CG_AUCWND_DETAIL, -1); + play_se( 202, 320, 240); + Inputsellforce = 0; + SellSthInput.buffer[0] = NULL; + SellSthInput.cnt = 0; + SellSthInput.cursor = 0; + SellSthInput.len = 32; + SellSthInput.lineDist = 30; + SellSthInput.color = 0; + SellSthInput.x = pSellSthSellProcWnd->x+10; + SellSthInput.y = pSellSthSellProcWnd->y+42; + SellSthInput.fontPrio = FONT_PRIO_FRONT; + + SellSthMesInput.buffer[0] = NULL; + SellSthMesInput.cnt = 0; + SellSthMesInput.cursor = 0; + SellSthMesInput.len = 128; + SellSthMesInput.lineLen = 64; + SellSthMesInput.lineDist = 26; + SellSthMesInput.color = 0; + SellSthMesInput.x = pSellSthSellProcWnd->x+10; + SellSthMesInput.y = pSellSthSellProcWnd->y+66; + SellSthMesInput.fontPrio = FONT_PRIO_FRONT; + + for( i=0; i<10; i++) + SellSthBtNo[i] = -1; + selSSthBtnId = -1; + return; + }else { + + x = pSellSthSellProcWnd->x; + y = pSellSthSellProcWnd->y; + + int frontX=x-36, frontY=y+42; + char buf[256]; + + StockFontBuffer( frontX, frontY, FONT_PRIO_FRONT, FONT_PAL_WHITE, "标题:", 1); + sprintf_s( buf, "%32s", ""); + SSthfontId[0] = StockFontBuffer( x+10, frontY, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 2 ); + StockFontBuffer( frontX, frontY+26, FONT_PRIO_FRONT, FONT_PAL_WHITE, "说明:", 1); + sprintf_s( buf, "%64s", ""); + SSthfontId[1] = StockFontBuffer( x+10, frontY+26, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf, 2 ); + + SellSthBtNo[0] = StockDispBuffer( x+ 410, y+180, DISP_PRIO_IME3, CG_TRADE_OK_BTN,2); + SellSthBtNo[1] = StockDispBuffer( x+ 495, y+180, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN,2); + + selSSthBtnId = focusGraId( SellSthBtNo, sizeof( SellSthBtNo )/sizeof( int ) ); + selSSthFontBtnId = selFontId( SSthfontId, sizeof( SSthfontId )/sizeof( int ) ); + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + switch( selSSthBtnId){ + case 0: + SellSubCMD = 200; + DeathAction( pSellSthSellProcWnd); + pSellSthSellProcWnd = NULL; + play_se(217,320,240); + break; + case 1: + wnCloseFlag = 1; + break; + } + + switch( selSSthFontBtnId ){ + case -1: Inputsellforce = 0; break; + case 0: Inputsellforce = 1; break; + case 1: Inputsellforce = 2; break; + case 2: break; + } + } + if( Inputsellforce == 1 ) { + StockFontBuffer2( &SellSthInput ); + GetKeyInputFocus( &SellSthInput ); + if( SellSthMesInput.buffer[0] != NULL ) StockFontBuffer2( &SellSthMesInput ); + }else if( Inputsellforce == 2 ) { + StockFontBuffer2( &SellSthMesInput ); + GetKeyInputFocus( &SellSthMesInput ); + if( SellSthInput.buffer[0] != NULL ) StockFontBuffer2( &SellSthInput ); }else { + GetKeyInputFocus( &MyChatBuffer ); + if( SellSthInput.buffer[0] != NULL ) StockFontBuffer2( &SellSthInput ); + if( SellSthMesInput.buffer[0] != NULL ) StockFontBuffer2( &SellSthMesInput ); + } + /* + SellSthInput + SellSthMesInput + #define CG_AUCWND_DETAIL 26381 // 拍卖明细视窗 + #define CG_AUCWND_MESSAGE 26382 // 拍卖讯息视窗 + #define CG_AUCWND_COLUMN 26383 // 拍卖专栏 + #define CG_AUCWND_CHANGE 26384 // 拍卖交换视窗 + */ + StockDispBuffer( 320, 220, DISP_PRIO_IME3, CG_AUCWND_DETAIL, 1); + } + +} + + +void SellSth_Sell( void ) +{ + if( CheckMenuFlag() + || (joy_trg[0] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1){ + + GetKeyInputFocus( &MyChatBuffer ); + if(pSellSthSellProcWnd != NULL){ + windowTypeWN = -1; + DeathAction( pSellSthSellProcWnd); + pSellSthSellProcWnd = NULL; + play_se(217,320,240); + } + if( SellSthActPet != NULL ){ + DeathAction( SellSthActPet); + SellSthActPet = NULL ; + } + return; + } + + switch( SellSubCMD){ + case 100: + SellSth_SellSub_MessRegist(); + break; + case 200: + SellSth_SellSub_MessUpItem(); + break; + case 400: + SellSth_Menu(); + break; + case 500: + SellSth_SellSub_MessView(); + break; + } +} +#endif + +#ifdef _PET_TRACE_MOUSE + +#define MAX_SHOW_PET_SET 29 +#define KIND_OF_CHANGE_TIME 5 +#define TIME_TO_CHANGE_TIME 30000 + +int iKindOfPet[MAX_SHOW_PET_SET][2] = { + {100250,100298},{100307,100310},{100319,100330},{100335,100362},{100367,100396}, + {100430,100430},{100820,100919},{101152,101156},{101177,101180},{101278,101287}, + {101412,101414},{101423,101428},{101437,101489},{101493,101501},{101530,101578}, + {101607,101610},{101612,101622},{101705,101729},{101736,101737},{101741,101744}, + {101746,101748},{101759,101765},{101767,101768},{101813,101816},{101819,101823}, + {101866,101876},{101879,101882},{101884,101886},{101906,101935} +}; + +int iChangeTime[KIND_OF_CHANGE_TIME] = { 5000,10000,15000,20000,25000 }; + +int iPetAction[5] = { + ANIM_ATTACK, + ANIM_DEAD, + ANIM_STAND, + ANIM_WALK, + ANIM_GUARD +}; + +SCPlayPet::SCPlayPet() +{ + m_pPet = NULL; + m_bMove = m_bAIWalk = false; + m_bChangeDir = true; + m_iTimeToChangeAction = 0; + m_iTimeToChangeTime = m_iTimeToChangeAction + TIME_TO_CHANGE_TIME; + m_iKindOfChangeTime = 0; +} + +SCPlayPet::~SCPlayPet() +{ + /*if(m_pPet){ + DeathAction(m_pPet); + m_pPet = NULL; + }*/ +} + +void SCPlayPet::CnangePetAction(bool bUserMove) +{ + if(bUserMove) m_pPet->anim_no = iPetAction[2]; + else{ + m_pPet->anim_no = iPetAction[rand() % 5]; + if(m_pPet->anim_no == ANIM_DEAD) m_pPet->actNo = 9; + else if(m_pPet->anim_no == ANIM_WALK) + m_bAIWalk = true; + } +} + +void SCPlayPet::Proc() +{ + float tmpX,tmpY,tmpDir; + + switch(m_iActionStep){ + // 初始化 + case 0: + srand((unsigned)time(NULL)); + if(m_pPet == NULL){ + int iShowSet; + int iShowPet; + + iShowSet = rand() % MAX_SHOW_PET_SET; + iShowPet = iKindOfPet[iShowSet][1] - iKindOfPet[iShowSet][0]; + if(iShowPet == 0) iShowPet = iKindOfPet[iShowSet][0]; + else iShowPet = (rand() % iShowPet) + iKindOfPet[iShowSet][0]; + m_pPet = MakeAnimDisp(rand() % DEF_APPSIZEX,rand() % DEF_APPSIZEY,iShowPet,0); + } + m_iActionStep++; + break; + case 1: + if(mouse.onceState & MOUSE_LEFT_CRICK_UP || m_bAIWalk){ + if(m_bAIWalk){ + m_iDestX = rand() % DEF_APPSIZEX; + m_iDestY = rand() % DEF_APPSIZEY; + m_bAIWalk = false; + } + else{ + m_iDestX = mouse.nowPoint.x; + m_iDestY = mouse.nowPoint.y; + } + m_iX = m_iDestX - m_pPet->x; + m_iY = m_iDestY - m_pPet->y; + if(m_iX > 0) m_iDirx = 1; + else{ + m_iX = -m_iX; + m_iDirx = -1; + } + if(m_iY > 0) m_iDiry = 1; + else{ + m_iY = -m_iY; + m_iDiry = -1; + } + if(m_iX >= m_iY) m_iCount = m_iX; + else m_iCount = m_iY; + if(m_iX > 20 || m_iY > 20){ + m_pPet->actNo = 0; + m_bMove = true; + m_bChangeDir = true; + b = 0; + } + } + if(m_bMove){ + if(m_iCount == 0){ + CnangePetAction(true); + m_bMove = false; + } + else{ + if(m_pPet->x == m_iDestX || m_pPet->y == m_iDestY || m_bChangeDir){ + tmpX = (float)(m_pPet->x - m_iDestX); + tmpY = (float)(m_pPet->y - m_iDestY); + tmpDir = Atan(tmpX,tmpY) + 22.5F - 45.0F * 3; + AdjustDir(&tmpDir); + m_pPet->dir = m_pPet->anim_ang = (int)(tmpDir/45); + m_pPet->anim_no = ANIM_WALK; + m_bChangeDir = false; + } + } + if(m_iX >= m_iY){ + m_pPet->x += m_iDirx; + b += m_iY; + if(b > (m_iX >> 1)){ + b -= m_iX; + m_pPet->y += m_iDiry; + } + m_iCount--; + } + else{ + m_pPet->y += m_iDiry; + b += m_iX; + if(b > (m_iY >> 1)){ + b -= m_iY; + m_pPet->x += m_iDirx; + } + m_iCount--; + } + } + break; + case 2: + DeathAction(m_pPet); + m_pPet = NULL; + m_iActionStep++; + break; + default:break; + } + if(m_pPet != NULL){ + if(m_iTimeToChangeTime < TimeGetTime()){ + m_iKindOfChangeTime = rand() % KIND_OF_CHANGE_TIME; + m_iTimeToChangeTime = TimeGetTime() + TIME_TO_CHANGE_TIME; + m_iTimeToChangeAction += iChangeTime[m_iKindOfChangeTime]; + } + if(m_iTimeToChangeAction < TimeGetTime()){ + if(!m_bMove) CnangePetAction(false); + m_iTimeToChangeAction += iChangeTime[m_iKindOfChangeTime]; + } + } +} +#endif + + +#ifdef _MOUSE_DBL_CLICK + +char mouseGetName[20]; +int checkInBlacklist( char* name); +void addBlacklist( char* name); +void removeBlacklist( char* name); +void cleanBlacklist(); + +void initMouseGetNameWN( char* name ) +{ + strncpy_s( mouseGetName, name, 20); + //windowTypeWN = WINDOW_MESSAGETYPE_MOUSEGETNAME; +} + + +//showRidePetWN +void showMouseGetNameWN( void ) +{ + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2 }; + int selFontBtnId = -1; + char dataBuf[256]; + char sendName[64]; + + int id ; + int i; + + static int totalMsgLine; + static int lineSkip; + + static inBlacklist = FALSE; + + + if( ptActMenuWin == NULL ) + { + //winW = msgWN_W; + //winH = msgWN_H; + winW = 5; + winH = 5; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + + + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + //lineSkip = 20; + //totalMsgLine = (winH*48-56)/lineSkip; + + + for( i = 0; i < sizeof( fontId )/sizeof( int ); i++ ) + { + fontId[i] = -2; + } + + play_se( 202, 320, 240 ); // ???????? + + + if( checkInBlacklist( mouseGetName) ) + inBlacklist = TRUE; + else + inBlacklist = FALSE; + + } + + + if( ptActMenuWin != NULL ) + { + // ????? + id = selFontId( fontId, sizeof( fontId )/sizeof( int ) ); + + if( CheckMenuFlag() + || (joy_trg[ 0 ] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + mouseGetName[0] = NULL; + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + } + + if( id >= 0 ) + { + switch( id) { +#ifdef _TELLCHANNEL + case 1: // 密语 + //pc.etcFlag |= PC_ETCFLAG_CHAT_TELL; + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + sprintf_s( sendName, "%s ", mouseGetName); + StrToNowStrBuffer1( sendName); + TalkMode = 1; + break; +#endif + case 2: // 黑名单 + if( inBlacklist) + removeBlacklist( mouseGetName); + else { + char sendName[64]; + sprintf_s(" IceCloud go Shit!!! "); + addBlacklist( mouseGetName); + } + break; + case 3: // 清除黑名单 + cleanBlacklist(); + break; + case 4: // 查询 + // Black Jack + break; + case 5: // 踢人 + // + break; + + } + mouseGetName[0] = NULL; + + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + + if( ptActMenuWin != NULL && ptActMenuWin->hp >= 1 ) + { + + + sprintf_s( dataBuf, "你打算对 %s :", mouseGetName); + StockFontBuffer( winX+40, winY+30, + FONT_PRIO_FRONT, FONT_PAL_WHITE, dataBuf, 0 ); + + fontId[1] = + StockFontBuffer( winX+110, winY+60, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 密  语 ", 2 ); + if( inBlacklist) + fontId[2] = + StockFontBuffer( winX+110, winY+90, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "移出黑名单", 2 ); + else + fontId[2] = + StockFontBuffer( winX+110, winY+90, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "加入黑名单", 2 ); + + fontId[3] = + StockFontBuffer( winX+110, winY+120, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "清除黑名单", 2 ); + + fontId[4] = + StockFontBuffer( winX+110, winY+120, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 查 询 ", 2 ); + + fontId[5] = + StockFontBuffer( winX+110, winY+120, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 踢 人 ", 2 ); + + + fontId[0] = + StockFontBuffer( winX+110, winY+200, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, " 取  消 ", 2 ); + + } + } + +} +#endif + + +#ifdef _CONTRACT + +typedef struct{ + int used; + char name[32]; + char fmname[32]; +} contractSignTag; + +contractSignTag contractSign[4]; +char contractDetail[2048]; +int contractArgnum; +char contractTime[512]; +int contractSignIndex; +int contractSigned; + +void initContractWN( char* data ) +{ + char buf[512], token[64]; + int i, index; + char contractArg[512] =""; + + strcpy( contractTime, ""); + + getStringToken( data, '|', 1, sizeof( contractDetail )-1, contractDetail ); + getStringToken( data, '|', 2, sizeof( buf )-1, buf ); + contractArgnum = atoi( buf); + getStringToken( data, '|', 3, sizeof( contractArg )-1, contractArg ); + getStringToken( data, '|', 4, sizeof( contractTime )-1, contractTime ); + + for( i=0; i<4; i++) { + contractSign[i].used = FALSE; + } + contractSignIndex = -1; + contractSigned = FALSE; + + for( i=0; i<4; i++) { + if( getStringToken( contractArg, ',', i+1, sizeof( buf )-1, buf ) != 0) + break; + if( strlen( buf) == 0) break; + getStringToken( buf, ':', 1, sizeof( token )-1, token ); + index = atoi( token); + if( index <0 || index >=4) break; + getStringToken( buf, ':', 2, sizeof( contractSign[index].name )-1, contractSign[index].name ); + getStringToken( buf, ':', 3, sizeof( contractSign[index].fmname )-1, contractSign[index].fmname ); + contractSign[index].used = TRUE; + // 判断是否签过名 + if( !strcmp( contractSign[index].name, pc.name) ) + contractSigned = TRUE; + } + +} + +void showContractWN() +{ +#define MAX_LINE 40 +#define MAX_CHAR 56 +#define LINE_PER_PAGE 8 + static int winX, winY; + static int winW, winH; + static int fontId[] = { -2, -2, -2, -2, -2, -2, -2, -2 }; + static int page = 0; + static int max_page = 0; + static char msgLine[MAX_LINE][MAX_CHAR+1]; + char* pStart; + int selFontBtnId = -1; + char dataBuf[1024]; + + int id ; + int i; + + static int totalMsgLine; + static int lineSkip; + + static int inBlacklist = FALSE; + + + if( ptActMenuWin == NULL ) + { + //winW = msgWN_W; + //winH = msgWN_H; + winW = 9; + winH = 8; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + + + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + + // 契约内容排版 + memset( msgLine, 0, sizeof( msgLine)); + page =0; + max_page =0; + pStart = contractDetail; + for( i =0; i = MAX_CHAR ) { // 有换行符号但已超行 + strncpy_s( msgLine[i], pStart, MAX_CHAR); + pStart += MAX_CHAR; + } + else if( strlen( pStart) > MAX_CHAR ) { + strncpy_s( msgLine[i], pStart, MAX_CHAR); + pStart += MAX_CHAR; + } + else { + strncpy_s( msgLine[i], pStart, strlen( pStart) ); + pStart += strlen( pStart); + break; + } + + } + max_page = i / LINE_PER_PAGE; + + //lineSkip = 20; + //totalMsgLine = (winH*48-56)/lineSkip; + + for( i = 0; i < sizeof( fontId )/sizeof( int ); i++ ) + { + fontId[i] = -2; + } + + play_se( 202, 320, 240 ); // ???????? + + + } + + + if( ptActMenuWin != NULL ) + { + // ????? + id = selFontId( fontId, sizeof( fontId )/sizeof( int ) ); + + if( CheckMenuFlag() + || (joy_trg[ 0 ] & JOY_ESC) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + } + + if( id >= 0 ) { + switch( id) { + case 0: + case 1: + case 2: + case 3: + // 签名 + if( contractSignIndex != id) + contractSignIndex = id; + else + contractSignIndex = -1; + break; + case 6: // 上一页 + if( page > 0 ) page--; + break; + case 7: // 下一页 + if( page < max_page ) page++; + break; + case 4: // 确定 + if( contractSignIndex != -1 ) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, contractSignIndex, "" ); + default: + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + } + for( i = 0; i < sizeof( fontId )/sizeof( int ); i++ ) + { + fontId[i] = -2; + } + + if( ptActMenuWin != NULL && ptActMenuWin->hp >= 1 ) + { + char sideComment[4][10] = { "甲方", "乙方", "丙方", "丁方"}; + + // 显示契约内容 + for( i =0; i 0 ) + fontId[6] = + StockFontBuffer( winX+150, winY+248, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "上一页", 2 ); + + if( page < max_page ) + fontId[7] = + StockFontBuffer( winX+(winW*64)-200, winY+248, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "下一页", 2 ); + + } + } + +} + +#endif + +//猎宠大会 +#ifdef _RACEMAN +char linemsgWN[10][200]; //每次最多收到十笔 +char ranktitle[60]; //排行榜名称 + +void initRacemanRankWN( char* data) //把资料解一解 +{ + int i,j; + + makeStringFromEscaped( data ); + + selStartLine = 0; + char namebuf[256],catchbuf[32],rankbuf[8]; + + memset(linemsgWN,0,sizeof(linemsgWN)); + ranktitle[0]='\0'; + //lnmake = 0; + //getStrSplit( (char *)msgWN, data, sizeof( msgWN[0] ), + // sizeof( msgWN )/sizeof( msgWN[0] ), 80 ); + + getStringToken( data , ' ', 1 , sizeof(ranktitle)-1, ranktitle); + j =0 ; + for( i = 1; i < 31 ; i++ ){ + //处理字串 + if(i%3==1) + getStringToken( data , ' ', i+1 , sizeof(rankbuf)-1, rankbuf); + else if(i%3==2) + getStringToken( data , ' ', i+1 , sizeof(namebuf)-1, namebuf); + else{ + getStringToken( data , ' ', i+1, sizeof(catchbuf)-1, catchbuf); + //sprintf_s(msgWN[j]," %-7s%-18s%-16s%13d%12d%14d%", lvbuf, fmnamebuf, namebuf, sumdp, taldp-sumdp, taldp); + sprintf_s(linemsgWN[j]," %-10s%-27s%s", rankbuf , namebuf , catchbuf ); + j++; + } + } + +} + +void showRacemanRankWN( void ) +{ + static int winW,winH; + static int winX,winY; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + + int id;// id2 ; + int i, j; + int mask; + int btn; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + + + if( ptActMenuWin == NULL ) + { + winW = 10-2-2; + winH = 7; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); + mask = 1; + btnCnt = 0; + for( i = 0; i < 10; i++, mask <<= 1 ) + { + if( buttonTypeWN & mask ) + { + btnCnt++; + if( btnCnt == 4 ) + break; + } + } + if( btnCnt > 0 ) + { + int w; + w = winW*64/(btnCnt+1); + for( i = 0; i < btnCnt; i++ ) + { + btnLoc[i][0] = w * (i+1) - 27; + btnLoc[i][1] = 295; + } + } + play_se( 202, 320, 240 ); + + } + if( ptActMenuWin != NULL ) + { + id = selFontId( btnId, sizeof( btnId )/sizeof( int ) ); + + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + } + + if( 0 <= id && id < 6 + //|| 0 <= id2 && id2 < 12 + || id == 100 ) + { + //char data[256]; + //char msg[256]; + if( id == 100 ) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if( 0 <= id && id < 6 ) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + + + //makeEscapeString( data, msg, sizeof( msg )-1 ); + + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, "" ) ; + windowTypeWN = -1; + } + if( id >= 0 ){ //|| id2 >= 0) { + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + if( ptActMenuWin->hp >= 1 ) + { + StockFontBuffer( winX+235-130 , winY+21+10, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, ranktitle , 0 );//"‘猎宠个人惊为天人排行榜’", 0 ); + StockFontBuffer( winX+25, winY+16+2*21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘排名’ ‘ 名 称 ’ ‘抓宠数量’", 0 ); + + //处理资料 + int fontcolor = FONT_PAL_WHITE; + for( i = 0; i < 10 ; i++ ) //一次十行 + { + if( strlen( linemsgWN[i] ) != NULL ) + { + StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor,linemsgWN[i], 0 ); + } + } + //处理按钮 + j = 0; + for( i = 0, mask = 1; i < 6; i++, mask <<= 1 ) + { + btnId[i] = -2; + if( buttonTypeWN & mask ) + { + if( j < btnCnt ) + { + btnId[i] = + StockFontBuffer( winX+btnLoc[j][0], winY+btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2 ); + j++; + } + } + } + + } + } +} + +#endif + +#ifdef _80_LOGIN_PLAY +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +void _80LoginProc(void) +{ + static ACTION *pMainChar = NULL, *pFace = NULL, *pPet[5], *pFacePet = NULL; + static int iWaitCount = 0, iX = DEF_APPSIZEX >> 1, iY = DEF_APPSIZEY >> 1, iBackBMP = CG_LOGO; + + StockDispBuffer(iX, iY, DISP_PRIO_BG, iBackBMP, 0); + if (joy_trg[0] & JOY_ESC) + SubProcNo = 8; + switch (SubProcNo) + { + // 产生人物 + case 0: + pMainChar = MakeAnimDisp(DEF_APPSIZEX, DEF_APPSIZEY >> 1, 100400, 0); + ATR_CHR_ACT(pMainChar) = ANIM_WALK; + ATR_CHR_ANG(pMainChar) = 2; + ATR_CHR_H_POS(pMainChar) = ATR_H_POS(pMainChar); + SubProcNo++; + break; + // 人物往左跑到中间 + case 1: + ATR_H_POS(pMainChar) -= 2; + // 跑超过中间了 + if (ATR_H_POS(pMainChar) < DEF_APPSIZEX >> 1) + { + // 作生气的样子 + ATR_CHR_ACT(pMainChar) = ANIM_ANGRY; + ATR_CHR_ANG(pMainChar) = 0; + SubProcNo++; + } + break; + // 生气动作 + case 2: + if (ATR_CHR_TIM(pMainChar) <= 0) + iWaitCount++; + if (iWaitCount > 5) + { + iWaitCount = 0; + SubProcNo++; + } + break; + // 转向右边吓一跳 + case 3: + ATR_CHR_ACT(pMainChar) = ANIM_STAND; + ATR_CHR_ANG(pMainChar) = 6; + pFace = GetAction(PRIO_CHR, 0); + ATR_CHR_ACT(pFace) = ANIM_STAND; + ATR_CHR_NO(pFace) = SPR_screamer; + ATR_H_POS(pFace) = ATR_H_POS(pMainChar); + ATR_V_POS(pFace) = ATR_V_POS(pMainChar) - 100; + ATR_DISP_PRIO(pFace) = DISP_PRIO_BOX3; + SubProcNo++; + break; + // 播放惊叹号 + case 4: + if (pattern(pFace, ANM_NOMAL_SPD, ANM_NO_LOOP)) + { + int iShowSet, iShowPet; + + // 转身逃跑 + ATR_CHR_ANG(pMainChar) = 2; + ATR_CHR_ACT(pMainChar) = ANIM_WALK; + // 冒汗 + ATR_CHR_NO(pFace) = SPR_perspiration; + for (int i = 0; i < 5; i++) + { + iShowSet = RAND(0, MAX_SHOW_PET_SET); + iShowPet = iKindOfPet[iShowSet][1] - iKindOfPet[iShowSet][0]; + if (iShowPet == 0) + iShowPet = iKindOfPet[iShowSet][0]; + else + iShowPet = RAND(0, iShowPet) + iKindOfPet[iShowSet][0]; + pPet[i] = MakeAnimDisp(DEF_APPSIZEX, DEF_APPSIZEY >> 1, iShowPet, 0); + ATR_CHR_ACT(pPet[i]) = ANIM_WALK; + ATR_CHR_ANG(pPet[i]) = 2; + ATR_H_POS(pPet[i]) += RAND(10, 100); + ATR_CHR_H_POS(pPet[i]) = ATR_H_POS(pPet[i]); + } + pFacePet = GetAction(PRIO_CHR, 0); + ATR_CHR_ACT(pFacePet) = ANIM_STAND; + ATR_CHR_NO(pFacePet) = SPR_cramp; + ATR_H_POS(pFacePet) = ATR_H_POS(pPet[0]); + ATR_V_POS(pFacePet) = ATR_V_POS(pPet[0]) - 100; + ATR_DISP_PRIO(pFacePet) = DISP_PRIO_BOX3; + iX = 320; + SubProcNo++; + } + break; + // 场景往右移动 + case 5: + pattern(pFace, ANM_NOMAL_SPD, ANM_LOOP); + pattern(pFacePet, ANM_NOMAL_SPD, ANM_LOOP); + iX += 4; + if (iX > 960) + { + // 换登入画面 + iBackBMP = CG_TITLE_ID_PASS; + iX = -320; + SubProcNo++; + } + break; + // 登入画面往右移动 + case 6: + pattern(pFace, ANM_NOMAL_SPD, ANM_LOOP); + pattern(pFacePet, ANM_NOMAL_SPD, ANM_LOOP); + iX += 4; + if (iX >= 320) + SubProcNo++; + break; + // 登入画面不动,人物继续往左移动 + case 7: + pattern(pFace, ANM_NOMAL_SPD, ANM_LOOP); + pattern(pFacePet, ANM_NOMAL_SPD, ANM_LOOP); + { + int iOutOf0 = 0; + + if (ATR_H_POS(pMainChar) > -24) + { + ATR_H_POS(pMainChar) -= 4; + ATR_H_POS(pFace) -= 4; + } + for (int i = 0; i < 5; i++) + { + if (ATR_H_POS(pPet[i]) < -24) + iOutOf0++; + ATR_H_POS(pPet[i]) -= 4; + } + ATR_H_POS(pFacePet) -= 4; + if (iOutOf0 == 5) + SubProcNo++; + } + break; + default: + DeathAction(pMainChar); + DeathAction(pFace); + DeathAction(pFacePet); + DeathAction(pPet[0]); + DeathAction(pPet[1]); + DeathAction(pPet[2]); + DeathAction(pPet[3]); + DeathAction(pPet[4]); + SubProcNo = 0; + ProcNo = PROC_ID_PASSWORD; + break; + } +} +#endif + +#ifdef _DRAGON_FUSION +void serverWindowDragonFusion( void ) +{ + static int winX, winY; + static int winW, winH; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + char *btnTitle[] = { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" }; + + static int selectID[5]={-1,-1,-1,-1,-1}; + static int selects=0; + + int id, id2; + int i, j, k; + int mask, btn, len; + int x1, y1, x2, y2; + + if( ptActMenuWin == NULL ){ + winW = 7; + winH = 5; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); +#ifdef _NEW_RESOMODE //800 600模式 + winX = ptActMenuWin->x; + winY = ptActMenuWin->y; +#endif + for( i = 0; i < sizeof( btnId )/sizeof( int ); i++ ){ + btnId[i] = -2; + } + mask = 1; + btnCnt = 0; + for( i = 0; i < 6; i++, mask <<= 1 ){ + if( buttonTypeWN & mask ){ + btnCnt++; + if( btnCnt == 4 ) + break; + } + } + if( btnCnt > 0 ){ + int w; + w = winW*64/(btnCnt+1); + for( i = 0; i < btnCnt; i++ ){ + btnLoc[i][0] = w * (i+1) - 27; + btnLoc[i][1] = 196; + } + } + + if( selects >= 0 && selects < 5 ) { + sprintf_s( msgWN[0], "=== 请选择第%d只宠物 ===", selects+1 ); + } + else{ + sprintf_s( msgWN[0], "=== 决定好了吗? ===" ); + } + + play_se( 202, 320, 240 ); // ???????? + } + if( ptActMenuWin != NULL ){ + id = selFontId( btnId, sizeof( btnId )/sizeof( int ) ); + id2 = -1; + if( ptActMenuWin->hp >= 1 ){ + for( i = 1, j = 1; i <= MAX_PET; i++ ){ + if(pet[i-1].useFlag != 0 ){ + x1 = winX+41; + y1 = winY+18+(j+1)*21; + x2 = x1 + 366; + y2 = y1 + 20; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX2 ) ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + id2 = i; + if( selects < 5 ){ + int k; + for( k=0; k<5; k++) { + if( selectID[k] == i ) + break; + } + if( k>= 5 ) { + selectID[selects++] = i; + } + } + } + } + j++; + } + } + } + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ){ + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + } + + if( 0 <= id && id < 6 ){ + //|| 0 <= id2 && id2 < 8 ){ + char data[256]; + char msg[256]; + if( 0 <= id && id < 6 ){ + btn = 1; + btn <<= id; + }else{ + btn = 0; + } + if( id2 < 0 ) + id2 = 0; + + sprintf_s( data, "%d|%d|%d|%d|%d", selectID[0], selectID[1], selectID[2], selectID[3], selectID[4] ); + if( bNewServer) + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, data ); + else + old_lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, msg ); + + for( i=0; i<5; i++) { + selectID[i]=-1; + } + selects = 0; + windowTypeWN = -1; + } + + if( id >= 0 || id2 >= 0 ){ + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + + if( ptActMenuWin != NULL && ptActMenuWin->hp >= 1 ){ + StockFontBuffer( winX+54, winY+21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[0], 0 ); + for( i = 1, j = 1; i <= MAX_PET; i++ ){ + len = strlen( pet[i-1].name ); + if( pet[i-1].useFlag != 0 ){ + len = strlen( pet[i-1].freeName ); + if( len > 0 ){ + strcpy( msgWN[1], pet[i-1].freeName ); + }else{ + len = strlen( pet[i-1].name ); + strcpy( msgWN[1], pet[i-1].name ); + } + StockFontBuffer( winX+62, winY+21+(j+1)*21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0 ); + + //selectID + for( k=0; k <(sizeof(selectID)/sizeof(selectID[0])); k++) { + if( selectID[k] == i ) { + if( k == 0 ) + sprintf_s( msgWN[1], "钩召"); + else if( k == 1 ) + sprintf_s( msgWN[1], "敬爱"); + else if( k == 2 ) + sprintf_s( msgWN[1], "调伏"); + else if( k == 3 ) + sprintf_s( msgWN[1], "息灾"); + else if( k == 4 ) + sprintf_s( msgWN[1], "增益"); + + StockFontBuffer( winX+220, winY+21+(j+1)*21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, msgWN[1], 0 ); + } + } + sprintf_s( msgWN[1], "LV.%d", pet[i-1].level ); + StockFontBuffer( winX+260, winY+21+(j+1)*21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0 ); + sprintf_s( msgWN[1], "MaxHP %d", pet[i-1].maxHp ); + StockFontBuffer( winX+314, winY+21+(j+1)*21, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msgWN[1], 0 ); + + j++; + } + } + j = 0; + for( i = 0, mask = 1; i < 6; i++, mask <<= 1 ){ + btnId[i] = -2; + if( buttonTypeWN & mask ){ + if( j < btnCnt ){ + btnId[i] = + StockFontBuffer( winX+btnLoc[j][0], winY+btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2 ); + j++; + } + } + } + } + } + +} +#endif + +#ifdef _NPC_DAYACTION + +char llinemsgWN[10][200]; //每次最多收到十笔 +char rranktitle[60]; //排行榜名称 + +void initDayactionRankWN( char* data) //把资料解一解 +{ + int i,j; + + makeStringFromEscaped( data ); + + selStartLine = 0; + char namebuf[256],scorebuf[32],rankbuf[8]; + + memset(llinemsgWN,0,sizeof(llinemsgWN)); + rranktitle[0]='\0'; + + getStringToken( data , ' ', 1 , sizeof(rranktitle)-1, rranktitle); + j =0 ; + for( i = 1; i < 31 ; i++ ){ + //处理字串 + if(i%3==1) + getStringToken( data , ' ', i+1 , sizeof(rankbuf)-1, rankbuf); + else if(i%3==2) + getStringToken( data , ' ', i+1 , sizeof(namebuf)-1, namebuf); + else{ + getStringToken( data , ' ', i+1, sizeof(scorebuf)-1, scorebuf); + sprintf_s(llinemsgWN[j]," %-10s%-27s%s", rankbuf , namebuf , scorebuf ); + j++; + } + } +} + +void showDayactionRankWN( void ) +{ + static int winW,winH; + static int winX,winY; + static int btnId[] = { -2, -2, -2, -2, -2, -2 }; + static int btnLoc[6][2]; + static int btnCnt; + + int id;// id2 ; + int i, j; + int mask; + int btn; + char *btnTitle[] = + { + "确 定", + "取 消", + // " OK ", + // "CANCEL", + "确 定", + "取 消", + "上一页", + "下一页" + }; + + + if( ptActMenuWin == NULL ) + { + winW = 10-2-2; + winH = 7; + winX = (lpDraw->xSize - winW*64)/2; + winY = (lpDraw->ySize - winH*48)/2; + ptActMenuWin = MakeWindowDisp( winX, winY, winW, winH, NULL, 1, FALSE ); + mask = 1; + btnCnt = 0; + for( i = 0; i < 10; i++, mask <<= 1 ) + { + if( buttonTypeWN & mask ) + { + btnCnt++; + if( btnCnt == 4 ) + break; + } + } + if( btnCnt > 0 ) + { + int w; + w = winW*64/(btnCnt+1); + for( i = 0; i < btnCnt; i++ ) + { + btnLoc[i][0] = w * (i+1) - 27; + btnLoc[i][1] = 295; + } + } + play_se( 202, 320, 240 ); + + } + if( ptActMenuWin != NULL ) + { + id = selFontId( btnId, sizeof( btnId )/sizeof( int ) ); + + if( CheckMenuFlag() + || joy_trg[ 0 ] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 ) + { + id = 100; + windowTypeWN = -1; + wnCloseFlag = 0; + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + } + + if( (0 <= id && id < 6) + //|| 0 <= id2 && id2 < 12 + || id == 100 ) + { + //char data[256]; + //char msg[256]; + if( id == 100 ) + { + btn = WINDOW_BUTTONTYPE_CANCEL; + } + else + if( 0 <= id && id < 6 ) + { + btn = 1; + btn <<= id; + } + else + { + btn = 0; + } + + + //makeEscapeString( data, msg, sizeof( msg )-1 ); + + lssproto_WN_send( sockfd, nowGx, nowGy, indexWN, idWN, btn, "" ) ; + windowTypeWN = -1; + } + if( id >= 0 ){ //|| id2 >= 0) { + DeathAction( ptActMenuWin ); + ptActMenuWin = NULL; + return; + } + + if( ptActMenuWin->hp >= 1 ) + { + StockFontBuffer( winX+235-130 , winY+21+10, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, rranktitle , 0 ); + StockFontBuffer( winX+25, winY+16+2*21, + FONT_PRIO_FRONT, FONT_PAL_GREEN, "‘排名’ ‘ 名 称 ’ ‘友好度’", 0 ); + + //处理资料 + int fontcolor = FONT_PAL_WHITE; + for( i = 0; i < 10 ; i++ ) //一次十行 + { + if( strlen( llinemsgWN[i] ) != NULL ) + { + StockFontBuffer( winX+40, winY+14+(i+3)*21,FONT_PRIO_FRONT, fontcolor,llinemsgWN[i], 0 ); + } + } + //处理按钮 + j = 0; + for( i = 0, mask = 1; i < 6; i++, mask <<= 1 ) + { + btnId[i] = -2; + if( buttonTypeWN & mask ) + { + if( j < btnCnt ) + { + btnId[i] = + StockFontBuffer( winX+btnLoc[j][0], winY+btnLoc[j][1], + FONT_PRIO_FRONT, FONT_PAL_YELLOW, btnTitle[i], 2 ); + j++; + } + } + } + + } + } +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/lssproto_cli.cpp b/石器时代8.5客户端最新源代码/石器源码/system/lssproto_cli.cpp new file mode 100644 index 0000000..6a6cd03 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/lssproto_cli.cpp @@ -0,0 +1,3540 @@ +/*#ifdef __NEW_PROTOCOL + +/* output by ./lsgen.perl 0.41 ( 1998 May) + * made Mon Jun 12 11:17:33 2000 + * user kawata + * host unicorn.lan.titan.co.jp + * file /opt/kawata/sa/bin/output/lssproto_cli.c + * util output/lssproto_util.c , output/lssproto_util.h + * src /opt/kawata/sa/bin/../doc/lssproto.html + *//* +#define _LSSPROTOCLI_C_ +#include +#include "../systeminc/version.h" +#include "../systeminc/lssproto_cli.h" + +void lssproto_SetClientLogFiles( char *r , char *w ) +{ + lssproto_strcpysafe( lssproto_readlogfilename , r , sizeof( lssproto_readlogfilename ) ); + lssproto_strcpysafe( lssproto_writelogfilename , w , sizeof( lssproto_writelogfilename ) ); +} +int lssproto_InitClient( int (*writefunc)(int,char*,int) ,int bufsiz ,int fd) +{ + int i; + if( (void*)writefunc == NULL){lssproto.write_func = lssproto_default_write_wrap;} else {lssproto.write_func = writefunc;} + lssproto_AllocateCommonWork(bufsiz); + lssproto_stringwrapper = (char**)MALLOC(sizeof(char*) * MAXLSRPCARGS); + if(lssproto_stringwrapper ==NULL)return -1; + memset( lssproto_stringwrapper , 0, sizeof(char*)*MAXLSRPCARGS); + for(i=0;i +#include "../systeminc/version.h" +#include "../systeminc/lssproto_cli.h" + +// nuke: TNJ: ttom & nuke & jongan : prevent packet cheat +//extern char *NJT_dummy; +//extern char *NJT[NJT_MAX]; + +/*#define JNT \ + ((lssproto.work[0]+lssproto.work[1]+lssproto.work[2]+lssproto.work[3]+ \ + lssproto.work[4]+lssproto.work[5]+lssproto.work[6]+lssproto.work[7])%NJT_MAX) + +#define TNJ { if(NJT[JNT]) lssproto.work=NJT[JNT]; } +*/ + + +//cary +void old_lssproto_FC_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "FC" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +//end + + +/* +166 :

  • clienttoserver W( int x, int y, string direction);
    +167 : (Walk)?????????????????????e???????? +168 : ????????????????????????????????? +169 : ???Re??????????????????u?u???????qn? +170 : ??????????W???????????????????????? +171 : ?????????????????\??????????????? +172 : ?????????? +173 : ????????????????MC???????????????MC +174 : ???????????????????????????????????? +175 : ????֢t???????????????????? +176 : +177 : +178 : +179 :

    +180 :
    +181 :
    int x,y +182 :
    ?????????????????? +183 : +184 :
    string direction +185 :
    ???? a,b,c,d,e,f,g,h???????h?? +186 : a?(dx,dy)=(0,-1)???????? h??(-1,-1) +187 : A,B,C,D,E,F,G,H ????????????? +188 : ???????????????? "ccae"??? +189 : ?????????????????"G"?? +190 : ????????????11??n??????? +191 : ????????????? +192 : +193 :
    +194 :
    +195 :
    +196 :
    +197 :
    +*/ + +void old_lssproto_W_send( int fd,int x,int y,char* direction ) +{ + lssproto_CreateHeader( lssproto.work , "W" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( direction ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +198 :
  • clienttoserver w( int x, int y, string direction);
    +199 : ?o????u?i?????????????????????h????? +200 : ???????????????????MC?????????OK?????? +201 : ??MC??????????MC?????????????????w????????? +202 : ???????????????????????????????? CHAR_EVENT_ALTERRATIVE +203 : ??????????????????????????u??????G??????????????????? +204 :
    +205 :
    +206 :
    +207 :
    +208 : +*/ + +void old_lssproto_w_send( int fd,int x,int y,char* direction ) +{ + lssproto_CreateHeader( lssproto.work , "w" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( direction ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +212 :
  • clienttoserver EV( int event,int seqno,int x, int y, int dir);
    +213 : ??????????????????_????D??? +214 : ?????e??????????????? +215 : +216 :

    +217 :
    +218 :
    int event +219 :
    ???????char_base.h????????e???????
    +220 :
    +221 : typedef enum
    +222 : {
    +223 : 	CHAR_EVENT_NONE,		?????D???
    +224 : 	CHAR_EVENT_NPC,			?eNPC???
    +225 : 	CHAR_EVENT_ENEMY,		?e??????????
    +226 : 	CHAR_EVENT_WARP,		???????
    +227 : 	CHAR_EVENT_ALTERRATIVE,		??????????????????????????????
    +228 : 	CHAR_EVENTNUM,
    +229 : }CHAR_EVENT;
    +230 : 	    
    +231 : 	
    +232 : CHAR_EVENT_NPC????O??NPC?????????????????? +233 : ???????EV????????????Re??q??????????
    +234 :
    int seqno +235 :
    ??????????No?e?????????????T?????????????? +236 : ??????????????? +237 : ?????EV????n?????????? +238 :
    int x,y +239 :
    ??t +240 :
    int dir +241 :
    ????????????t??????????????S???i?????-1? +242 :
    +243 :
    +244 :
    +245 :
    +246 :
    +*/ + +void old_lssproto_EV_send( int fd,int event,int seqno,int x,int y,int dir ) +{ + lssproto_CreateHeader( lssproto.work , "EV" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( event ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( seqno ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dir ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +261 :
  • clienttoserver EN( int x, int y );
    +262 : ?????????e????????????????????? +263 : ????????????????????????????? +264 :

    +265 :
    +266 :
    int x,y +267 :
    ??????????????????????? +268 :
    +269 :
    +270 :
    +271 :
    +272 :
    +*/ + +void old_lssproto_EN_send( int fd,int x,int y ) +{ + lssproto_CreateHeader( lssproto.work , "EN" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +273 :
  • clienttoserver DU( int x, int y);
    +274 : ????????????i?????????????????? +275 : ????????????????????????????? +276 :

    +277 :
    +278 :
    int x,y +279 :
    ??????????????????????? +280 :
    +281 :
    +282 :
    +283 :
    +284 :
    +*/ + +void old_lssproto_DU_send( int fd,int x,int y ) +{ + lssproto_CreateHeader( lssproto.work , "DU" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +298 :
  • clienttoserver EO( int dummy );
    +299 : ????????????????????????? +300 :
    +301 :
    int dummy +302 :
    ??????????????? +303 :
    +304 :
    +305 :
    +306 :
    +307 :
    +308 : +*/ + +void old_lssproto_EO_send( int fd,int dummy ) +{ + lssproto_CreateHeader( lssproto.work , "EO" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dummy ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +309 :
  • clienttoserver BU( int dummy );
    +310 : ???????????????e???????? +311 :
    +312 :
    int dummy +313 :
    ??????????????? +314 :
    +315 :
    +316 :
    +317 :
    +318 :
    +319 : +*/ + +void old_lssproto_BU_send( int fd,int dummy ) +{ + lssproto_CreateHeader( lssproto.work , "BU" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dummy ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +320 :
  • clienttoserver JB( int x, int y );
    +321 : \?Pf?ӡP??????????? EN ????? +322 :
    +323 :
    int x, int y; +324 :
    ???????????? +325 :
    +326 :
    +327 :
    +328 :
    +329 :
    +330 : +*/ + +void old_lssproto_JB_send( int fd,int x,int y ) +{ + lssproto_CreateHeader( lssproto.work , "JB" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +331 :
  • clienttoserver LB( int x, int y );
    +332 : \?Pf??P??????????? EN ????? +333 :
    +334 :
    int x, int y; +335 :
    ???????????? +336 :
    +337 :
    +338 :
    +339 :
    +340 :
    +341 : +*/ + +void old_lssproto_LB_send( int fd,int x,int y ) +{ + lssproto_CreateHeader( lssproto.work , "LB" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +354 :
  • clienttoserver B( string command );
    +355 : ??????????????Pf??????e???????k????????e????????????D???ul?e??????D???ul??????????ul???

    +356 :
      +357 :
    • H|?k?(%X)(0?19)
      G?????k??e

      +358 :
    • E
      `???

      +359 :
    • G
      \??

      +360 :
    • N
      ??????

      +361 :
    • T|?k?(%X)
      ??

      +362 :
    • J|?k?(%X)|?k?(%X)? +363 :
      ???????k???????????k???? +364 : ???(0?5)?

      +365 :
    • W|????k?(%X)|?k?(%X)
      +366 : ?????????????????k?????????k?? +367 : ???(0?7)

      +368 :
    • S|????k?(%d)?
      ????????????????

      +369 :
    • I|?????k?(%X)|?k?(%X)? +370 :
      ???????????????k???????????????k???? +371 : ???(5?19)?

      +372 :
    +373 :
    +374 :
    +375 :
    +376 : +*/ + +void old_lssproto_B_send( int fd,char* command ) +{ + lssproto_CreateHeader( lssproto.work , "B" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( command ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +542 :
  • clienttoserver SKD( int dir , int index );
    +543 : (SKillDir) +544 : e???????????? +545 :

    +546 :
    +547 :
    int dir +548 :
    ?????? +549 :
    int index +550 :
    ????????????index. +551 :
    +552 : ???????G?????????????????????? +553 :
    +554 : 
    +555 :       ?????????????
    +556 :       rpcgen C???????????????????G??????
    +557 :       ?????????enum
    +558 : 
    +559 :       ???q??????????s???????
    +560 :       typedef enum
    +561 :       {
    +562 :       SKILL_FIRE,
    +563 :       SKILL_MAGICIAN,         ??
    +564 :       SKILL_PRIEST,           ?
    +565 :       SKILL_ALOTOFTHINGS,     ????
    +566 :                               ????
    +567 :                              7(?) + 8 (?? ) + 4*(???????)
    +568 :       SKILL_AVOIDRATEUP,      ???????? 3% ?????
    +569 :       SKILL_DETERMINEITEM,    ????
    +570 : 
    +571 :       SKILL_DETERMINOTHERS,   J??
    +572 :                              0 ??Re???(?)
    +573 :                              1 ?????????????V??
    +574 :                                  ???????V???????
    +575 :                              2 ?????
    +576 :                              3 NPC
    +577 :                              4 ????
    +578 :                              5 
    +579 : 
    +580 :       SKILL_FIRECUT,         ???  5 %
    +581 :       SKILL_THUNDERCUT,      ????  5 %
    +582 :       SKILL_ICECUT,          ??  5 %
    +583 :       SKILL_MERCHANT,         ??20% ??100% ?? 5%?????
    +584 :       SKILL_HEALER,          ?
    +585 :                               ?????????k??????????
    +586 :                               1 
    +587 :                               2 ???
    +588 :                               3 ?
    +589 :                               4 ?
    +590 :                               5 ??
    +591 :                               6 ??
    +592 :                               7 HP 1 ???
    +593 :                               8 HP ???????
    +594 :       ????u?
    +595 :       ????????????
    +596 :       0  0
    +597 :       1 50
    +598 :       2 57
    +599 :       3 64
    +600 :       4 71
    +601 :       5 78
    +602 :       6 85
    +603 :       7 92
    +604 :       8 100
    +605 :       ?????????( 100 ??? )??k??? 1 10 ????
    +606 :       ??? + ?????
    +607 :       0 0
    +608 :       1 1
    +609 :       2 2
    +610 :       3 3
    +611 :       4 4
    +612 :       5 5
    +613 :       6 6
    +614 :       7 7
    +615 :       8 8
    +616 : 
    +617 :       SKILL_FIST,             ?
    +618 :       SKILL_SWORD,            ??
    +619 :       SKILL_AXE,              ??
    +620 :       SKILL_SPEAR,            ??
    +621 :       SKILL_BOW,              ??
    +622 :       SKILL_CANE,             ?
    +623 : 
    +624 :       SKILL_LARGEVOICE,       ??   Lv 8
    +625 :                               ?????????? TK ?
    +626 :       SKILL_NUM
    +627 :       }SKILL_ID;
    +628 :       
    +629 :
    +630 :
    +631 :
    +632 : +*/ + +void old_lssproto_SKD_send( int fd,int dir,int index ) +{ + lssproto_CreateHeader( lssproto.work , "SKD" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dir ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( index ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +633 :
  • clienttoserver ID( int x, int y, int haveitemindex,int toindex);
    +634 : (useItemDir)?????????????????????????????????????????? +635 : ??????????? +636 : +637 : +638 :
    +639 :
    int x,y +640 :
    ?x,y ? +641 :
    int haveitemindex +642 :
    ????????????????????? +643 :
    int toindex +644 :
    M?????????????????????????index???????????????? +645 :
    +646 : 	      = 0
    +647 : 	  ???  = 1 ?5
    +648 : 	  ??    = 6 ?10 ?S N ?0?4?n??????????
    +649 : 	
    +650 : n?u??????????????-1?????
    +651 :
    +652 :
    +653 :
    +654 :
    +655 :
    +656 :
    +657 : +658 : +659 : +660 : +661 : +*/ + +void old_lssproto_ID_send( int fd,int x,int y,int haveitemindex,int toindex ) +{ + lssproto_CreateHeader( lssproto.work , "ID" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( haveitemindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( toindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +662 :
  • clienttoserver PI( int x, int y,int dir );
    +663 : (PickupItem) +664 : ??????????K????????9??????

    +665 :
    +666 :
    int x,y +667 :
    ?x,y ? +668 :
    int dir +669 :
    ????????K????? ????K?????? +670 :
    +671 :
    +672 :
    +673 :
    +674 : +675 : +*/ + +void old_lssproto_PI_send( int fd,int x,int y,int dir ) +{ + lssproto_CreateHeader( lssproto.work , "PI" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dir ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +676 :
  • clienttoserver DI( int x, int y, int itemindex);
    +677 : (DropItem) +678 : ?????t??t???????????t???????t? +679 : e????itemindex??????t???????q?t?? +680 :

    +681 : +682 :
    +683 :
    int x,y +684 :
    ?x,y ? +685 :
    int itemindex +686 :
    t?????????????? +687 :
    +688 :
    +689 :
    +690 :
    +691 : +692 : +*/ + +void old_lssproto_DI_send( int fd,int x,int y,int itemindex ) +{ + lssproto_CreateHeader( lssproto.work , "DI" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( itemindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +693 :
  • clienttoserver DG( int x, int y, int amount );
    +694 : (DropGold) +695 : ???t??SA?????t???D??

    +696 :
    +697 :
    int x,y +698 :
    ?x,y ? +699 :
    int amount +700 :
    t?????? +701 :
    +702 :
    +703 :
    +704 :
    +705 : +*/ + +void old_lssproto_DG_send( int fd,int x,int y,int amount ) +{ + lssproto_CreateHeader( lssproto.work , "DG" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( amount ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +706 :
  • clienttoserver DP( int x, int y,int petindex);
    +707 : (DropPet) +708 : ????t?????t?e???? +709 : petindex??????t???????q?t?? +710 :

    +711 : +712 :
    +713 :
    int x,y +714 :
    ?x,y ? +715 :
    int petindex +716 :
    t???????index????????k???????????? +717 :
    +718 :
    +719 :
    +720 :
    +721 : +*/ + +void old_lssproto_DP_send( int fd,int x,int y,int petindex ) +{ + lssproto_CreateHeader( lssproto.work , "DP" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( petindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +741 :
  • clienttoserver MI( int fromindex , int toindex);
    +742 : (MoveItem)
    +743 : ??????h/?/??????????????? +744 : ?h???????

    +745 :
    +746 :
    int fromindex +747 :
    ?h????????????? +748 :
    int toindex +749 :
    ???????????? +750 :
    +751 : ??????G?? +752 :
      +753 :
    • 0 ??????( d ) +754 :
    • 1 ??????( l ) +755 :
    • 2 ???????????() +756 :
    • 3 ?ߦ?????1 +757 :
    • 4 ?ߦ?????2 +758 :
    • ???? ????? +759 :
    +760 :
    +761 :
    +762 :
    +*/ + +void old_lssproto_MI_send( int fd,int fromindex,int toindex ) +{ + lssproto_CreateHeader( lssproto.work , "MI" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( fromindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( toindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +788 :
  • clienttoserver MSG( int index , string message , int color );
    +789 : (MeSsaGe) +790 : ??????????????????index???????? +791 : ???????????

    +792 :
    +793 :
    int index +794 :
    ?????????????????? +795 :
    string message +796 :
    ???????????EUC???????????? +797 : ???????????????????????????? +798 :
    int color +799 :
    ??????? +800 :
    +801 :
    +802 :
    +803 :
    +804 :
    +805 : +*/ + +void old_lssproto_MSG_send( int fd,int index,char* message,int color ) +{ + lssproto_CreateHeader( lssproto.work , "MSG" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( index ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( message ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( color ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +830 :
  • clienttoserver PMSG( int index, int petindex, int itemindex, string message , int color );
    +831 : (PetMeSsaGe) +832 : ??????????????????????index???????? +833 : ?????????????????????????

    +834 :
    +835 :
    int index +836 :
    ?????????????????? +837 :
    int petindex +838 :
    ?k?????????? +839 :
    int itemindex +840 :
    ?k???????????? +841 :
    string message +842 :
    ???????????EUC???????????? +843 : ???????????????????????????? +844 :
    int color +845 :
    ??????? +846 :
    +847 :
    +848 :
    +849 :
    +850 :
    +*/ + +void old_lssproto_PMSG_send( int fd,int index,int petindex,int itemindex,char* message,int color ) +{ + lssproto_CreateHeader( lssproto.work , "PMSG" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( index ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( petindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( itemindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( message ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( color ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} + +void old_lssproto_AB_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "AB" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +921 :
  • clienttoserver DAB( int index );
    +922 : (DeleteAddressBookitem)???????????????????? +923 : ???????????????????????????AB?? +924 : ???????????????????????????? +925 : ????????? +926 :
    +927 :
    int index +928 :
    ??????index.??????0???? +929 :
    +930 : ???????????????{??????????? +931 :
    +932 :
    +933 :
    +934 : +*/ + +void old_lssproto_DAB_send( int fd,int index ) +{ + lssproto_CreateHeader( lssproto.work , "DAB" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( index ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +935 :
  • clienttoserver AAB( int x, int y );
    +936 : (AddAddressBookitem) +937 : ??q?????????????????????? +938 : ???????????????????? +939 : ?????AB???????????????????? +940 :
    +941 :
    int x,y +942 :
    ????? +943 :
    +944 :
    +945 :
    +946 :
    +947 : +*/ + +void old_lssproto_AAB_send( int fd,int x,int y ) +{ + lssproto_CreateHeader( lssproto.work , "AAB" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +948 :
  • clienttoserver L( int dir);
    +949 : (Look) +950 : dir ?????????????????????????D +951 : ???????????????M???????????????? +952 : ??????????????????????????????? +953 : ???????????????????????????Y???? +954 : ??q?????(a?NPC?????)??????q???NPC?n +955 : ?????????n????????????????NPC? +956 : ??h?????????????????????l?????? +957 : TK????????????? +958 :
    +959 :
    +960 :
    +961 : +*/ + +void old_lssproto_L_send( int fd,int dir ) +{ + lssproto_CreateHeader( lssproto.work , "L" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dir ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +962 :
  • clienttoserver TK( int x, int y, string message ,int color, int area);
    +963 : (TalK) +964 : ????????????????????

    +965 :
    +966 :
    int x,y +967 :
    ????? +968 :
    string message +969 :
    string ???, "|" ?2???????????????? +970 : ????????2???????????????2?? +971 : ????????????????? +972 : ????????????????????? +973 :
      +974 :
    • P??
      +975 : Id?C???"P"??????????????V +976 : ?????????????????????????? +977 : ??????Id??????????????? +978 : ?????????????????Id?"P"? +979 : ????????Re???????d???? +980 : ???????TK??????????TK??????? +981 : ???????"P"?????????V??? +982 :
      +983 : ?????? +984 :
      +985 : 		  "P|??????????!!"
      +986 : 		  
      +987 :
      +988 : ???????????????????d??e +989 : ?????????????????????Re? +990 : ???????C?????????'!' ?u? +991 : ??V????????????????'!'???T +992 : ????????????????u???S??? +993 : ?????????!?????????????? +994 : ??????d?????? +995 : +996 : +998 : +999 :
      "..."??????????? +997 :
      +1000 :
    +1001 :
    int color +1002 :
    ???? +1003 :
    int area +1004 :
    ?????????d?????e???? +1005 : +1006 :
    +1007 :
    +1008 :
    +1009 :
    +1010 : +*/ + +void old_lssproto_TK_send( int fd,int x,int y,char* message,int color,int area ) +{ + lssproto_CreateHeader( lssproto.work , "TK" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( message ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( color ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( area ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1071 :
  • clienttoserver M(int fl , int x1 , int y1 , int x2, int y2 );
    +1072 : ??????????????????M???????????? +1073 : ????????MC??????????????????? +1074 : ?????????????????????????? +1075 :
    +1076 :
    int fl +1077 :
    ???k? +1078 :
    int x1 +1079 :
    ?X +1080 :
    int y1 +1081 :
    ?Y +1082 :
    int x2 +1083 :
    ??X +1084 :
    int y2 +1085 :
    ??Y +1086 :
    +1087 :
    +1088 :
    +1089 :
    +1090 : +*/ + +void old_lssproto_M_send( int fd,int fl,int x1,int y1,int x2,int y2 ) +{ + lssproto_CreateHeader( lssproto.work , "M" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( fl ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x1 ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y1 ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x2 ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y2 ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1128 :
  • clienttoserver C( int index );
    +1129 : ????ѩ??????????index CA ?????????? +1130 : C ???????????????????????? +1131 :
    +1132 :
    +1133 :
    +1134 : +*/ + +void old_lssproto_C_send( int fd,int index ) +{ + lssproto_CreateHeader( lssproto.work , "C" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( index ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1345 :
  • clienttoserver S( string category );
    +1346 : (Status) +1347 : ??????????????? +1348 :
    +1349 :
    string category +1350 :
    ???ѩ?????????????e? +1351 :
      +1352 :
    • P u????? +1353 :
    • C ? +1354 :
    • I u???? +1355 :
    • S u??? +1356 :
    • T u? +1357 :
    • M ?????? +1358 :
    • E ???????? +1359 :
    • K0 - K4 ??????? +1360 :
    • D ID +1361 :
    +1362 :
    +1363 : ????ѩ????????????????????? +1364 : ??????????????? +1365 :
    +1366 :
    +1367 :
    +1368 : +*/ + +void old_lssproto_S_send( int fd,char* category ) +{ + lssproto_CreateHeader( lssproto.work , "S" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( category ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1745 :
  • clienttoserver FS( int flg);
    +1746 : (FlgSet)????V????DUELϣ????????????????????On/Off???

    +1747 : +1748 :
    +1749 :
    int flg +1750 :
    0 bit 0: ??Off 1: ??On
    +1751 : ???t??1 bit 0: PfN??off 1: PfN??On
    +1752 : 2 bit 0: DUEL off 1: DUEL On
    +1753 : 3 bit 0: ?G???????? 1: ??????????????????
    +1754 : 4 bit 0: ??OK 1: ???r
    +1755 :
    +1756 :
    +1757 :
    +1758 :
    +1759 :
    +*/ + +void old_lssproto_FS_send( int fd,int flg ) +{ + lssproto_CreateHeader( lssproto.work , "FS" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( flg ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1774 :
  • clienttoserver HL( int flg);
    +1775 : (HeLp)???????@e??????ON?????\??Pf?????????

    +1776 : +1777 :
    +1778 :
    int flg +1779 :
    0: ??????Off 1: ??????On
    +1780 :
    +1781 :
    +1782 :
    +1783 :
    +1784 :
    +*/ + +void old_lssproto_HL_send( int fd,int flg ) +{ + lssproto_CreateHeader( lssproto.work , "HL" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( flg ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1795 :
  • clienttoserver PR( int x, int y,int request);
    +1796 : (PartyRequest)???V?or? ??????

    +1797 : +1798 :
    +1799 :
    int x,y +1800 :
    ?x,y ? +1801 :
    int request +1802 :
    0: ???1: ??????? +1803 :
    +1804 :
    +1805 :
    +1806 :
    +1807 :
    +*/ + +void old_lssproto_PR_send( int fd,int x,int y,int request ) +{ + lssproto_CreateHeader( lssproto.work , "PR" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( request ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1824 :
  • clienttoserver KS( int petarray);
    +1825 : (Kyoryu Select)Pf??????k???

    +1826 : +1827 :
    +1828 :
    int petarray +1829 :
    0 ? 4 ??????k??????????????????????Pf??????????????????-1?V??? +1830 :
    +1831 :
    +1832 :
    +1833 :
    +1834 :
    +*/ + +void old_lssproto_KS_send( int fd,int petarray ) +{ + lssproto_CreateHeader( lssproto.work , "KS" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( petarray ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1852 :
  • clienttoserver AC( int x, int y, int actionno);
    +1853 : (action)?W?????????

    +1854 : +1855 :
    +1856 :
    int x,y +1857 :
    ?x,y ? +1858 :
    int actionno +1859 :
    ???????????????????????????????????????????(CA)????? +1860 : ???????e??????????????????k????????n?????G??
    +1861 :
    +1862 : +1863 : +1864 : +1865 : +1866 : +1867 : +1868 : +1869 : +1870 : +1871 : +1872 : +1873 : +1874 : +1875 : +1876 : +1877 :
    actionno
    ??0
    ????1
    X??2
    ?????3
    ?4
    ??5
    ??6
    ??7
    W?8
    v??9
    ???10
    ????11
    ???12
    +1878 :
    +1879 :
    +1880 :
    +1881 :
    +1882 :
    +*/ + +void old_lssproto_AC_send( int fd,int x,int y,int actionno ) +{ + lssproto_CreateHeader( lssproto.work , "AC" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( actionno ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1883 :
  • clienttoserver MU( int x, int y, int array, int toindex);
    +1884 : (magic use)???????????????????????????????????? +1885 : ??????????? +1886 : +1887 : +1888 :
    +1889 :
    int x,y +1890 :
    ?x,y ? +1891 :
    int array +1892 :
    ????????????? P ? Jn(n ?\????)?n??????????? +1893 :
    int toindex +1894 :
    M??????????????????????index???????????????? +1895 :
    +1896 : 	      = 0
    +1897 : 	  ???  = 1 ?5
    +1898 : 	  ??    = 6 ?10 ?S N ?0?4?n??????????
    +1899 : 	
    +1900 : n?u??????????????-1?????
    +1901 :
    +1902 :
    +1903 :
    +1904 :
    +1905 :
    +1906 :
    +*/ + +void old_lssproto_MU_send( int fd,int x,int y,int array,int toindex ) +{ + lssproto_CreateHeader( lssproto.work , "MU" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( array ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( toindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1907 :
  • clienttoserver PS( int havepetindex, int havepetskill, int toindex, string data);
    +1908 : (PetSkill use )??????????????????????? +1909 : +1910 :
    +1911 :
    int havepetindex +1912 :
    ?k??????????? +1913 :
    int havepetskill +1914 :
    ?k????????? +1915 :
    int toindex +1916 :
    M??????????????????????index???????????????? +1917 :
    +1918 : 	      = 0
    +1919 : 	  ???  = 1 ?5
    +1920 : 	  ??    = 6 ?10 ?S N ?0?4?n??????????
    +1921 : 	
    +1922 : n?u??????????????-1?????
    +1923 :
    +1924 :
    string data +1925 :
    ?ѩ????????????haveitemindex1|haveitemindex2|haveitemindex3|...
    +1926 : ??????????k??V????? +1927 : +1928 :
    +1929 : +1930 :
    +1931 :
    +1932 :
    +1933 :
    +1934 : +*/ + +void old_lssproto_PS_send( int fd,int havepetindex,int havepetskill,int toindex,char* data ) +{ + lssproto_CreateHeader( lssproto.work , "PS" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( havepetindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( havepetskill ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( toindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( data ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1963 :
  • clienttoserver ST( int titleindex );
    +1964 : (SelectTitle) +1965 : ??????titleindex ? -1 ??????????????? +1966 : ??

    +1967 :
    +1968 :
    int titleindex +1969 :
    ?k????? +1970 :
    +1971 : ????Txt?????????????????????????? +1972 : ?Gl???? +1973 :
    +1974 :
    +1975 :
    +1976 :
    +1977 : +1978 : +*/ + +void old_lssproto_ST_send( int fd,int titleindex ) +{ + lssproto_CreateHeader( lssproto.work , "ST" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( titleindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1979 :
  • clienttoserver DT( int titleindex );
    +1980 : (DeleteTitle) +1981 : ???????

    +1982 :
    +1983 :
    int titleindex +1984 :
    ???????????? +1985 :
    +1986 : ????Txt?????????????????????????????G +1987 : l???? +1988 :
    +1989 :
    +1990 :
    +1991 :
    +1992 : +*/ + +void old_lssproto_DT_send( int fd,int titleindex ) +{ + lssproto_CreateHeader( lssproto.work , "DT" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( titleindex ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +1993 :
  • clienttoserver FT( string data );
    +1994 : (inputFreeTitle) +1995 : ?V?????V????

    +1996 :
    +1997 :
    string data +1998 :
    ?V?????EUC???????????????? +1999 : ??????????????????1?info??? +2000 : ????????????????????????? +2001 : ???????????? +2002 :
    +2003 : ??????Txt?????????Gl???????????? +2004 : ?CHARINDEX?n???Ch????????????????? +2005 : ??? +2006 :
    +2007 :
    +2008 :
    +2009 :
    +2010 : +*/ + +void old_lssproto_FT_send( int fd,char* data ) +{ + lssproto_CreateHeader( lssproto.work , "FT" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( data ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2019 :
  • clienttoserver SKUP( int skillid );
    +2020 : (SKillUP) +2021 : ??????????????

    +2022 :
    +2023 :
    int skillid +2024 :
    ???????????0=l?, 1=??, 2=Ǧ?, 3=?? +2025 :
    +2026 :
    +2027 :
    +2028 :
    +2029 : +*/ + +void old_lssproto_SKUP_send( int fd,int skillid ) +{ + lssproto_CreateHeader( lssproto.work , "SKUP" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( skillid ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2030 :
  • clienttoserver KN( int havepetindex, string data );
    +2031 : (inputKyoryuName) +2032 : ????q?V????

    +2033 :
    +2034 :
    int havepetindex +2035 :
    ????k?? +2036 :
    string data +2037 :
    ???????????q????? +2038 : +2039 :
    +2040 : ??????Txt?????????Gl???????????? +2041 : ??????????????????? +2042 :
    +2043 :
    +2044 :
    +2045 :
    +2046 : +*/ + +void old_lssproto_KN_send( int fd,int havepetindex,char* data ) +{ + lssproto_CreateHeader( lssproto.work , "KN" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( havepetindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( data ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2166 :
  • clienttoserver WN( int x, int y, int seqno, int objindex, int select, string data );
    +2167 :
    +2168 : ??????n???
    +2169 :
    +2170 :
    +2171 :
    int x,y +2172 :
    ???????x,y? +2173 :
    int seqno +2174 :
    ????????seqno?????? +2175 :
    int objindex +2176 :
    ????????objindex?????? +2177 :
    int select +2178 :
    ??????k????????k?????????WN ?buttontype ?define?i????? +2179 :
    string data +2180 :
    ??V?????????????V??????? +2181 : k???????????k??k???1??? +2182 : ?????????k??????????????????????????? +2183 :

    ?????
    +2184 : ????k??k??????????
    +2185 : ????k????????k??????|??
    +2186 : ??\ ??1 ??2 ?3 +2187 : +2188 :


    ?????????
    +2189 : ??????????(kk?)????????(kk?)?????????(kk?)?kh
    +2190 : +2191 :
    +2192 :
    +2193 :
    +2194 :
    +2195 :
    +*/ + +void old_lssproto_WN_send( int fd,int x,int y,int seqno,int objindex,int select,char* data ) +{ + lssproto_CreateHeader( lssproto.work , "WN" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( seqno ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( objindex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( select ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( data ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2238 :
  • clienttoserver SP( int x, int y, int dir );
    +2239 : (SetPosition)
    +2240 : ?????????????? +2241 : ??????????????????
    +2242 :
    +2243 :
    +2244 :
    int x,y, dir +2245 :
    ?,??? +2246 :
    +2247 :
    +2248 :
    +2249 :
    +2250 :
    +2251 : +2252 : +*/ + +void old_lssproto_SP_send( int fd,int x,int y,int dir ) +{ + lssproto_CreateHeader( lssproto.work , "SP" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( x ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( y ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dir ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} + +/* +2253 :
  • clienttoserver ClientLogin(string cdkey,string passwd);
    +2254 : ??????????????????????????????? +2255 : ?????????????????????????????? +2256 : ??????????????????????????????? +2257 : ???O????????ѩ?????????????????? +2258 : ??????????????????T????????? +2259 : +2260 :

    +2261 :
    +2262 :
    string cdkey +2263 :
    CDKEY +2264 :
    string passwd +2265 :
    ????????????????????? +2266 :
    +2267 :
    +2268 :
    +2269 :
    +2270 : +*/ + +void old_lssproto_ClientLogin_send( int fd,char* cdkey,char* passwd ) +{ + lssproto_CreateHeader( lssproto.work , "ClientLogin" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( cdkey ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( passwd ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2284 :
  • clienttoserver CreateNewChar(int dataplacenum, string charname,int imgno , int faceimgno, int vital, int str, int tgh, int dex, int earth, int water, int fire, int wind, int hometown);
    +2285 : ???????????? +2286 :

    +2287 :
    +2288 :
    int dataplacenum +2289 :
    ????k??????????????????????????????????????????Re??? +2290 :
    string charname +2291 :
    ???(????????????????)? +2292 : ???????????????????????????? +2293 :
    int imgno +2294 :
    ?????????k?? +2295 :
    int faceimgno +2296 :
    ????k??????????? +2297 :
    int vital, str,tgh dex +2298 :
    ??????? +2299 :
    int earth, water, fire, wind +2300 :
    ?Nͣk +2301 :
    int hometown +2302 :
    ?0???k?J???? +2303 :
    string option +2304 : +2305 : ????????????????e?????????k +2306 : ???????????????????????????? +2307 : ????? +2308 :
    +2309 :
    +2310 :
    +2311 :
    +2312 : +2313 : +*/ + +void old_lssproto_CreateNewChar_send( int fd,int dataplacenum,char* charname,int imgno,int faceimgno,int vital,int str,int tgh,int dex,int earth,int water,int fire,int wind,int hometown ) +{ + //cary + if(imgno>=100239) + return; + //end + lssproto_CreateHeader( lssproto.work , "CreateNewChar" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dataplacenum ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( charname ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( imgno ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( faceimgno ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( vital ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( str ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( tgh ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( dex ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( earth ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( water ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( fire ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( wind ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( hometown ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2338 :
  • clienttoserver CharDelete(string charname);
    +2339 : ?????? +2340 :

    +2341 :
    +2342 :
    string charname +2343 :
    ????????????????????????? +2344 :
    +2345 :
    +2346 :
    +2347 :
    +2348 :
    +*/ + +void old_lssproto_CharDelete_send( int fd,char* charname ) +{ + lssproto_CreateHeader( lssproto.work , "CharDelete" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( charname ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2366 :
  • clienttoserver CharLogin(string charname);
    +2367 : ??????????????????????? +2368 :

    +2369 :
    +2370 :
    string charname +2371 :
    ?????????????????????????? +2372 :
    +2373 :
    +2374 :
    +2375 :
    +*/ + +void old_lssproto_CharLogin_send( int fd,char* charname ) +{ + lssproto_CreateHeader( lssproto.work , "CharLogin" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( charname ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2391 :
  • clienttoserver CharList( void );
    +2392 : ???????x?? +2393 :

    +2394 :
    +2395 :
    +*/ + +void old_lssproto_CharList_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "CharList" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +// TNJ; +} +/* +2438 :
  • clienttoserver CharLogout(void);
    +2439 : ????????????????????????? +2440 : ????? +2441 :
    +2442 :
    +2443 :
    +2444 : +*/ + +void old_lssproto_CharLogout_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "CharLogout" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} + + +/* +2459 :
  • clienttoserver ProcGet(void);
    +2460 : proc ????x????????????????????????? +2461 :
    +2462 :
    +2463 :
    +2464 : +*/ + +void old_lssproto_ProcGet_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "ProcGet" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2477 :
  • clienttoserver PlayerNumGet(void);
    +2478 : ????????????x??? +2479 :
    +2480 :
    +2481 :
    +2482 : +*/ + +void old_lssproto_PlayerNumGet_send( int fd ) +{ + lssproto_CreateHeader( lssproto.work , "PlayerNumGet" ); + lssproto_strcatsafe( lssproto.work , "" ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2495 :
  • clienttoserver Echo( string test);
    +2496 : ????????????????????????? +2497 :

    +2498 :
    +2499 :
    string test +2500 :
    ???????????????? +2501 :
    +2502 :
    +2503 :
    +2504 :
    +2505 : +*/ + +void old_lssproto_Echo_send( int fd,char* test ) +{ + lssproto_CreateHeader( lssproto.work , "Echo" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( test ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} +/* +2517 :
  • clienttoserver Shutdown( string passwd, int min);
    +2518 : ???????????

    +2519 : ??????????????h???????????????????????????? +2520 : ??????????denyaccept()????????????????????? +2521 : ???closeallsockets()?????????????????????? +2522 :

    +2523 :
    +2524 :
    string passwd +2525 :
    ???????????????????@e????? +2526 :
    int min +2527 :
    ????????????????????@e??? +2528 :
    +2529 :
    +2530 :
    +2531 :
    +2532 : +*/ + +void old_lssproto_Shutdown_send( int fd,char* passwd,int min ) +{ + lssproto_CreateHeader( lssproto.work , "Shutdown" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( passwd ) ,lssproto.workbufsize ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_int( min ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} + +// Robin 2001/04/10 trade +void old_lssproto_TD_send( int fd,char* message ) +{ + lssproto_CreateHeader( lssproto.work , "TD" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( message ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} + +void old_lssproto_FM_send( int fd,char* message ) +{ + lssproto_CreateHeader( lssproto.work , "FM" ); + lssproto_strcatsafe( lssproto.work , lssproto_mkstr_string( message ) ,lssproto.workbufsize ); + lssproto_Send( fd , lssproto.work ); +} + +int lssproto_ClientDispatchMessage(int fd ,char*line) +{ + int msgid; + char funcname[1024]; + lssproto_strcpysafe( lssproto.work , line,lssproto.workbufsize ); + lssproto_splitString( lssproto.work); + lssproto_GetMessageInfo( &msgid , funcname , sizeof(funcname),lssproto.token_list); +/* +209 :
  • servertoclient XYD( int x, int y, int dir );
    +210 : ?Pf??????????t???????? +211 :

    +*/ + + if( strcmp( funcname , "XYD" ) == 0 ){ + int x; + int y; + int dir; + x = lssproto_demkstr_int( lssproto.token_list[2] ); + y = lssproto_demkstr_int( lssproto.token_list[3] ); + dir = lssproto_demkstr_int( lssproto.token_list[4] ); + lssproto_XYD_recv( fd,x,y,dir); + return 0; + } +/* +247 :
  • servertoclient EV(int seqno,int result);
    +248 : ???????EV?n???????? +249 : ???????????????????????? +250 : ???? +251 : +252 :
    +253 :
    int seqno +254 :
    ??????EV?seqno?n???? +255 :
    int result +256 :
    ???0:??????? 1:?????????????n??G??????????????? +257 :
    +258 :
    +259 :
    +260 :
    +*/ + + if( strcmp( funcname , "EV" ) == 0 ){ + int seqno; + int result; + seqno = lssproto_demkstr_int( lssproto.token_list[2] ); + result = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_EV_recv( fd,seqno,result); + return 0; + } +/* +285 :
  • servertoclient EN(int result,int field);
    +286 : ???????EN??DU?n??????????????????????????????????? +287 : +288 :
    +289 :
    int result +290 :
    ???0:???????or???? 1:??Pfϣ?2:n??Pfϣ?????Pf????G ??????????????? +291 :
    int field +292 :
    ????????k?? +293 :
    +294 :
    +295 :
    +296 :
    +297 : +*/ + + if( strcmp( funcname , "EN" ) == 0 ){ + int result; + int field; + result = lssproto_demkstr_int( lssproto.token_list[2] ); + field = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_EN_recv( fd,result,field); + return 0; + } +/* +342 :
  • servertoclient RS( string data );
    +343 : Pf???x????????????Gl?
    +344 : RS|k?(10)|?????????(10)|EXP(62),k?|?????????|EXP,???,????|????|????

    +345 : k????k?5??????","???????????????????????k??-2?
    +346 : 2???4????????k??0?4)??????k???????????????????","????
    +347 : ????????q?"|"??????????????????????"|"???? +348 : +*/ + + if( strcmp( funcname , "RS" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_RS_recv( fd,data); + return 0; + } +/* +349 :
  • servertoclient RD( string data );
    +350 : ???????x?????????????Gl?
    +351 : RD|x?(??)DP(62)|??DP(62)|

    +352 : +353 : +*/ + + if( strcmp( funcname , "RD" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_RD_recv( fd,data); + return 0; + } +/* +377 :
  • servertoclient B( string command );
    +378 : Pf???????u?????k??u? ?16???
    +379 : ???[?k?]????????????k????? +380 : q??????????q???????????D?????????? +381 :

    +382 :

    +383 : ??????? +384 :

    +385 : ?????????u?????????????????????
    +386 : ???( BATTLESTR_ADD( ?? ) )????????????????????????????????????
    +387 : ????????????u??k????????k????????????(???????????)
    +388 : +389 :
    +390 : ???????????s????????
    +391 : ---???????
    +392 : ---?????G???
    +393 : ---?????????
    +394 : ---?????\?
    +395 : ---??????????
    +396 : ---????????
    +397 : ---?????????????????
    +398 : ---?????????????????
    +399 : ---????????????????
    +400 : ---?????????
    +401 :
    +402 :
      +403 :
    • BH|????G??????
      +404 : BH|??Dk?|駍Dk?|???|????|駍Dk?|???|????|?????????駍Dk??FF?????????????????
      +405 :
      +406 : +407 : (G???) B|BH|attack_0|defense_A|flag_2|damage_32|defense_B|flag_2|damage_32|FF|
      +408 : ???0k?(attack_0)Ak(defense_A)?0x32???????(damage_32)???Bk(defense_B)????????0x32????(damage_32)??????????

      +409 : +410 : (???????) B|BH|attack_0|defense_A|flag_2|dagame_32|counter_0|flag_10|damage_16|FF|
      +411 : ???0k?(attack_0)?Ak????(defense_A)????0x32(damage_32)???????0k(counter_0)???????(flag_10)????0x16(damage_16)?????????????????Dh??????q?????????k????

      +412 : +413 : (?????) B|BH|attack_0|defense_A|flag_202|dagame_32|gardian_B|FF|
      +414 : ???0k?(attack_0)?Ak????(defense_A)????0x32(damage_32)?????????Bk????????????????????

      +415 :
      +416 : +417 :
    • BT|?????????
      +418 : BT|??Dk?|駍Dk?|???|
      +419 : ????????????????????????????? +420 : ????????????????????Re???

      +421 : +422 :
    • BE|????`????
      +423 : BE|`??Dk?|駍Dk?|???|
      +424 : ????????????????????????????? +425 : ????????????????????Re????????????`?? +426 : ???????BE???????`????????
      +427 :
      +428 : +429 :
    • bg|???????????
      +430 : bg|?????Dk?|
      +431 : ????????????????h??????????????????????????????????? +432 : ??????????????????
      +433 :
      +434 : +435 :
    • BD|??????????????
      +436 : BD|???????k?|???|?????????|??k|
      +437 : ???????????????????????????????????
      +438 :
      +439 : +440 :
    • BF|??????????????????
      +441 : BF|??????k?|
      +442 : ???????????????????????????????????? +443 : ??????????
      +444 :
      +445 : +446 :
    • BJ|??????????????
      +447 : BJ|????k?|?D?????k?|?D?????k?|?????k?|?????k?|???|FF|
      +448 : ?????????????????????k???Q??????????FF????? +449 :
      +450 :
      +451 : +452 :
    • BB|?????s???????
      +453 : BB|??Dk?|?s???|駍Dk?|???|????|駍Dk?|???|FF|
      +454 : ?k??????s????V??????G???i??
      +455 : ?s???????????????????????????????????
      +456 : +457 :
      +458 :
    • BM|??????????Ш?????
      +459 : BM|???????????k?|?????????|
      +460 : ??????Чk??
      +461 : ---????????
      +462 : ---?
      +463 : ---???
      +464 : ---??
      +465 : ---??
      +466 : ---????
      +467 : ---???
      +468 :
      +469 : +470 :
    • BO|?????????????
      +471 : BO|??Dk?|駍Dk?|???|????|駍Dk?|???|FF|
      +472 : ?k??????s????V??????G???i??
      +473 :
      +474 : +475 :
    • BS|????????V?????
      +476 : BS|????k?[0?19](%X)|???|??k?|???|??|q|
      +477 : ?????????????????????????????????
      +478 : ?????????????????????????????????????????BS??????????
      +479 : +480 :
    • BU|????Pf??I??????
      +481 : ???????????????????????֢t???w????????r??????????????????????Pf??I?????????????????
      +482 :
      +483 : +484 :
    • BV|?????????Nͨ?????
      +485 : BV|????????k?|???Nͧk?|
      +486 : ???Nͧk???
      +487 : ---?N
      +488 : ---?ԢN
      +489 : ---??N
      +490 : ---??N
      +491 : ---??N
      +492 :
      +493 : +494 :
    • BY|?????l??????
      +495 : BY|駍Dk?|??Dk?|???|????|??Dk?|???|????|?????????G?????V?v?????
      +496 :
      +497 :
    +498 : +499 :

    +500 : ?????????????? +501 :

    +502 :
      +503 :
    • BC|?????????????????????u??i?????????
      +504 : BC|k?[0?19](%X)|???(%s)|??k?(%X)|???(%X)|HP(%X)|???(%X)|???

      +505 : ?????s????????
      +506 : ---???????
      +507 : ---??????
      +508 : ---??????????????
      +509 : ---?????
      +510 : ---???????
      +511 : ---??????
      +512 : ---??????
      +513 : ---????????
      +514 : ---???????
      +515 :
      +516 :
    • BP|?????????????????o????????
      +517 : BP|?k?[0?19](%X)|???(%X)|?????(%X)|???

      +518 : ?????s????????
      +519 : ---????????
      +520 : ---???????e???????
      +521 : ---?????????????????
      +522 :
    +523 :

    +524 : ?????????e??????????????????? +525 :

    +526 :
      +527 :
    • BA|??????????????????????M??????????????????u???????
      +528 : BA|?????????(%X)|????(%X)| +529 :

      +530 : ?????????????O??????k????????????????? +531 : ????????????????????????????????????? +532 : ??????????????????????????_?????????????????????
      +533 : ??????????u?????????????????????? +534 : ?????????????????? +535 :
    +536 :
    +537 :
    +538 :
    +539 :
    +540 : +541 : +*/ + + if( strcmp( funcname , "B" ) == 0 ){ + char* command; + command = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_B_recv( fd,command); + return 0; + } +/* +722 :
  • servertoclient I( string data );
    +723 : (item)
    +724 :
    +725 : ????ѩ?S I ?u??????????n?????e???????k??????? +726 : ??????????? +727 : +728 :
    +729 :
    string data +730 :
    ????ѩ? +731 : ????????????????? +732 : ??????????????????????? +733 : ??????????S I???????i????Id????????????? +734 : ?????????????k????????Re???
    +735 :
    +736 :
    +737 :
    +738 :
    +739 :
    +740 : +*/ + + if( strcmp( funcname , "I" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_I_recv( fd,data); + return 0; + } +/* +763 :
  • servertoclient SI( int fromindex, int toindex );
    +764 : (SwapItem) +765 : ????????????????s?MI?i???? +766 : ??????????????Gl?????????? +767 : ?????????SI????????????? +768 : ????????(???????????)?? +769 : ???????????h?????????????Gl????? +770 : ????????????????????????????? +771 : ?????????u????????? +772 : ???????????????????????????? +773 : ?????????????????????????????????? +774 : ??????????????? +775 : ?k???k??????????????Gl??? +776 : +777 :
    +778 :
    int fromindex +779 :
    ?h????????????? +780 :
    int toindex +781 :
    ???????????? +782 :
    +783 : ???s??MI?i????? +784 :
    +785 :
    +786 :
    +787 : +*/ + + if( strcmp( funcname , "SI" ) == 0 ){ + int fromindex; + int toindex; + fromindex = lssproto_demkstr_int( lssproto.token_list[2] ); + toindex = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_SI_recv( fd,fromindex,toindex); + return 0; + } +/* +806 :
  • servertoclient MSG( int aindex , string text , int color );
    +807 : (MeSsaGe) +808 : ???????????????????????????????? +809 : ????????G??????????????????? +810 : ?????????????????T?????????????? +811 :
    +812 :
    int aindex +813 :
    ??????????????????????{e???? +814 : ?????????????????? +815 :
    string text +816 :
    ?????????????????????????????mm/dd hh:mm|text...|graphicsno|lv|name|itemgraphicsno +817 : ??????????????T????V?????????????????????k?? +818 : G????-1???????????????V????????mm/dd hh:mm|text|-1 +819 : ?????????????????????k???t?????? +820 : lv????????????????????q??t???????????????????? +821 : itemgraphicsno ?????????????k???t?????? +822 :
    int color +823 :
    ? +824 :
    +825 :
    +826 :
    +827 :
    +828 :
    +829 : +*/ + + if( strcmp( funcname , "MSG" ) == 0 ){ + int aindex; + char* text; + int color; + aindex = lssproto_demkstr_int( lssproto.token_list[2] ); + text = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + color = lssproto_demkstr_int( lssproto.token_list[4] ); + lssproto_MSG_recv( fd,aindex,text,color); + return 0; + } +/* +851 :
  • servertoclient PME( int objindex, int graphicsno, int x, int y, int dir, int flg, int no, string cdata );
    +852 : (PetMeSsaEffect) +853 : ?????????????K?????

    +854 :
    +855 :
    int objindex +856 :
    ??????????k?? +857 :
    int graphicsno +858 :
    K????????k? +859 :
    int x,y +860 :
    ???t????? +861 :
    int dir; +862 :
    ???????????? +863 :
    int flg +864 :
    ?????(0)??????(1)? +865 :
    int no +866 :
    ?ҧk?? +867 :
    string cdata +868 :
    C ?????V???????????????????????????????????? +869 : ????????????????????????????????? +870 : ????????C ?????????? +871 :
    +872 :
    +873 :
    +874 :
    +875 :
    +876 : +*/ + + if( strcmp( funcname , "PME" ) == 0 ){ + int objindex; + int graphicsno; + int x; + int y; + int dir; + int flg; + int no; + char* cdata; + objindex = lssproto_demkstr_int( lssproto.token_list[2] ); + graphicsno = lssproto_demkstr_int( lssproto.token_list[3] ); + x = lssproto_demkstr_int( lssproto.token_list[4] ); + y = lssproto_demkstr_int( lssproto.token_list[5] ); + dir = lssproto_demkstr_int( lssproto.token_list[6] ); + flg = lssproto_demkstr_int( lssproto.token_list[7] ); + no = lssproto_demkstr_int( lssproto.token_list[8] ); + cdata = lssproto_wrapStringAddr( lssproto_stringwrapper[8] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[9] )); + lssproto_PME_recv( fd,objindex,graphicsno,x,y,dir,flg,no,cdata); + return 0; + } +/* +882 :
  • servertoclient AB( string data );
    +883 : ???????????????????????u?? +884 :
    +885 :
    string data +886 :
    ѩ??????????ѩ??????????????????q? +887 : ??????????????????????????? +888 : ??????????? +889 : ?????????????? +890 : ??|K?|...??????? +891 : +892 : ???????????????? +893 :
    +894 : ????|q(??)|????k|duelpoint|???|??k? +895 : +896 :
    +897 : ?????? N??q????????? 4(N-1)+1k?? +898 : ??????????????????????????V?? +899 : ????????????????V?????q??????????????S????? +901 : ????0????????1???????????? +902 : ??k????????????????????? +903 : setup.cf?? servernumber=n ?n?k?????? +904 : {??u????q????????????q?AB +905 : ???????q?ѩ????????????? +906 : ??????????????q?ѩ?????? +907 : 2T?????????? +908 : +909 :
    +910 :
    +911 :
    +912 :
    +*/ + + if( strcmp( funcname , "AB" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_AB_recv( fd,data); + return 0; + } +/* +913 :
  • servertoclient ABI( int num, string data );
    +914 : AB?Ol\?num ????????????k???????V????? +915 : data???AB?????
    +916 :
    +917 :
    +918 :
    +919 :
    +920 : +*/ + + if( strcmp( funcname , "ABI" ) == 0 ){ + int num; + char* data; + num = lssproto_demkstr_int( lssproto.token_list[2] ); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_ABI_recv( fd,num,data); + return 0; + } +/* +1011 :
  • servertoclient TK( int index,string message ,int color);
    +1012 :
    +1013 :
    index +1014 :
    ????????????????-1 ????????? +1015 : ?????????????
    +1016 :
    string +1017 :
    string ???, "|" ?2???????????????? +1018 : ????????2???????????????2?? +1019 : ????????????????? +1020 : ????????????????????? +1021 :
      +1022 :
    • "P" ???
      +1023 : ???????????????????????? +1024 : ?????????????????????? +1025 :
      +1026 : 		  "P|?????"
      +1027 : 		  
      +1028 :
    • "F"???
      +1029 :
      +1030 : 	          F|charaindex|?????
      +1031 : 	          
      +1032 : ???????????e???charaindex?????? +1033 : ?????????
      +1034 : +1035 :
    +1036 :
    color +1037 :
    ????????e??? +1038 :
    +1039 :
    +1040 :
    +1041 :
    +1042 : +*/ + + if( strcmp( funcname , "TK" ) == 0 ){ + int index; + char* message; + int color; + index = lssproto_demkstr_int( lssproto.token_list[2] ); + message = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + color = lssproto_demkstr_int( lssproto.token_list[4] ); + lssproto_TK_recv( fd,index,message,color); + return 0; + } + if( strcmp( funcname , "MC" ) == 0 ){ + int fl; + int x1; + int y1; + int x2; + int y2; + int tilesum; + int objsum; + int eventsum; + char* data; + fl = lssproto_demkstr_int( lssproto.token_list[2] ); + x1 = lssproto_demkstr_int( lssproto.token_list[3] ); + y1 = lssproto_demkstr_int( lssproto.token_list[4] ); + x2 = lssproto_demkstr_int( lssproto.token_list[5] ); + y2 = lssproto_demkstr_int( lssproto.token_list[6] ); + tilesum = lssproto_demkstr_int( lssproto.token_list[7] ); + objsum = lssproto_demkstr_int( lssproto.token_list[8] ); + eventsum = lssproto_demkstr_int( lssproto.token_list[9] ); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[9] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[10] )); +#ifdef __SKYISLAND + extern void SkyIslandSetNo( int fl); + SkyIslandSetNo( fl); +#endif + lssproto_MC_recv( fd,fl,x1,y1,x2,y2,tilesum,objsum,eventsum,data); + return 0; + } + if( strcmp( funcname , "M" ) == 0 ){ + int fl; + int x1; + int y1; + int x2; + int y2; + char* data; + fl = lssproto_demkstr_int( lssproto.token_list[2] ); + x1 = lssproto_demkstr_int( lssproto.token_list[3] ); + y1 = lssproto_demkstr_int( lssproto.token_list[4] ); + x2 = lssproto_demkstr_int( lssproto.token_list[5] ); + y2 = lssproto_demkstr_int( lssproto.token_list[6] ); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[6] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[7] )); + lssproto_M_recv( fd,fl,x1,y1,x2,y2,data); + return 0; + } +/* +1135 :
  • servertoclient C( string data );
    +1136 : (Characters) +1137 : ??????? CA ???????????????????? C +1138 : ???????????????????????? +1139 :

    +1140 :
    +1141 :
    string data +1142 :
    ??????? ???3????????????? +1143 : ?????.???????????????S'|'????? +1144 : ???? +1145 : +1146 :
      +1147 :
    • ??S???????????12???
      +1148 : ??????? +1149 : +1150 : WHICHTYPE|CHARINDEX|X|Y|DIR|BASEIMG|LEVEL|NAMECOLOR|NAME|SELFTITLE|WALKABLE|HEIGHT|POPUPNAMECOLOR +1151 : ???????????????????????????
      +1152 : +1153 : WHICHTYPE ???????????????????? +1154 : ????????????????????e???????
      +1155 :
      +1156 : 		typedef enum
      +1157 : 		{
      +1158 : 		    CHAR_TYPENONE,          ?????
      +1159 : 		    CHAR_TYPEPLAYER,        ?????
      +1160 : 		    CHAR_TYPEENEMY,         
      +1161 : 		    CHAR_TYPEPET,           ???
      +1162 : 		    CHAR_TYPEDOOR,          ??
      +1163 : 		    CHAR_TYPEBOX ,          ?
      +1164 : 		    CHAR_TYPEMSG ,          ?Y
      +1165 : 		    CHAR_TYPEWARP ,         ??????
      +1166 : 		    CHAR_TYPESHOP ,         
      +1167 : 		    CHAR_TYPEHEALER ,       ????
      +1168 : 		    CHAR_TYPEOLDMAN ,       ?
      +1169 : 		    CHAR_TYPEROOMADMIN,     ۥh?
      +1170 : 		    CHAR_TYPETOWNPEOPLE,    ?????
      +1171 : 		    CHAR_TYPEDENGON,        ?\
      +1172 : 		    CHAR_TYPEADM,           ?\
      +1173 : 		    CHAR_TYPETEMPLE,        Temple master
      +1174 : 		    CHAR_TYPESTORYTELLER,   ???
      +1175 : 		    CHAR_TYPERANKING,       ۥh????????
      +1176 : 		    CHAR_TYPEOTHERNPC,      ??\???n?????NPC
      +1177 : 		    CHAR_TYPEPRINTPASSMAN,  ??????????NPC
      +1178 : 		    CHAR_TYPENPCENEMY,      ?e
      +1179 : 		    CHAR_TYPEACTION,        ??????T???NPC
      +1180 : 		    CHAR_TYPEWINDOWMAN,     ???????NPC??????)
      +1181 : 		    CHAR_TYPESAVEPOINT,     ???????
      +1182 : 		    CHAR_TYPEWINDOWHEALER,  ?????????????
      +1183 : 		    CHAR_TYPEITEMSHOP,	    ?
      +1184 : 		    CHAR_TYPESTONESHOP,	    l?????????
      +1185 : 		    CHAR_TYPEDUELRANKING,   DUEL?????NPC
      +1186 : 		    CHAR_TYPEWARPMAN,	    ?????NPC
      +1187 : 		    CHAR_TYPEEVENT,	    ????NPC
      +1188 : 		    CHAR_TYPEMIC,	    ????NPC
      +1189 : 		    CHAR_TYPELUCKYMAN,	    ????NPC
      +1190 : 		    CHAR_TYPEBUS,	    ??????
      +1191 : 		    CHAR_TYPECHARM,	    ????NPC
      +1192 : 		    CHAR_TYPENUM,
      +1193 : 		}CHAR_TYPE;
      +1194 : 		  
      +1195 : +1196 : ???\???????NPC??????????? +1197 : ????????d?????u??????? +1198 : ????????????????????????? +1199 : ????????????????????????? +1200 : ?????????????????????????? +1201 : ????????ѩ???ѩ????????? +1202 : ???????????????????????? +1203 : ??????????????????uh??? +1204 : ??????????? SELFTITLE?????????? +1205 : ?????S???????????????????? +1206 : ?????????????????(CA)??????? +1207 : ?????CHARINDEX????????????{ +1208 : e???k??BASEIMG?????k??LEVEL??? +1209 : ?????(0????????k?NPC?????) +1210 : WALKABLE?1??????G?????????0??G +1211 : ???????????HEIGHT???????????? +1212 : ?????e? +1213 : +1214 : ???????q????? +1215 : ????????????????'|'?????? +1216 : ?????????????????????????' +1217 : |'?????????????????O??'|'?? +1218 : ??????????????q?????? +1219 : ?????????S??????????? +1220 : ????????????????????@e +1221 : ??????q????????
      +1222 : +1223 :
    • ??S???????????6???
      +1224 : ??????? +1225 : INDEX|X|Y|BASEIMG|LEVEL|ITEM1LINEINFO +1226 : ????????????????ѩ???? +1227 : INDEX?????????????????INDEX???? +1228 : ??????????????X,Y????????? +1229 : ???t?BASEIMG????k??ITEM1LINEINFO?1? +1230 : info??????ѩ????????????? +1231 : ???ѩ???????????????? +1232 : ?CA?????ITEM1LINEINFO????? +1233 : ??????????????????? +1234 : +1235 :
    • ??S???????????4???
      +1236 : ??????? +1237 : INDEX|X|Y|VALUE +1238 : ??????????????ѩ??????? +1239 : ?????INDEX,X,Y ??????i??VALUE ???? +1240 : ?????????????????????ѩ???? +1241 :
    • ??S???????????1???
      +1242 : INDEX +1243 : ??????C???????? +1244 :
    +1245 :
    +1246 :
    +1247 :
    +1248 :
    +1249 :
    +1250 : +1251 : +1252 : +*/ + + if( strcmp( funcname , "C" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_C_recv( fd,data); + return 0; + } +/* +1253 :
  • servertoclient CA( string data );
    +1254 : (CharacterAction) +1255 : ???d?????????????֢t????? +1256 : ??????????????????? +1257 : ?????1????????????????????????? +1258 : ???????

    +1259 : +1260 :
    +1261 :
    string data +1262 :
    CHARINDEX|X|Y|ACTION|PARAM1|PARAM2|PARAM3|PARAM4|....?? +1263 : ?????????????PARAM???????????? +1264 : ????????????????????X,Y??t?? +1265 : ???????????????t?e??? +1266 : ??????????????? +1267 : +1268 : +1269 : +1270 : +1271 : +1272 : +1273 : +1274 : +1275 : +1276 : +1277 : +1278 : +1279 : +1280 : +1281 : +1282 : +1283 : +1284 : +1285 : +1286 : +1287 : +1288 : +1289 : +1290 : +1291 : +1292 : +1293 : +1294 : +1295 : +1296 :
    ACTIONPARAM1PARAM2PARAM3PARAM4
    Stand:0?0~7
    Walk:1?0~7
    Attack:2?0~7
    Throw:3?0~7
    Damage:4?0~7
    Dead:5?0~7
    UseMagic:6?0~7
    UseItem:7?0~7
    Effect:8?0~7?????k?
    Down:10 (X??)?0~7
    Sit:11 (??)?0~7
    Hand:12 (??)?0~7
    Pleasure:13 (??)?0~7
    Angry:14 (W?)?0~7
    Sad:15 (v??)?0~7
    Guard:16 (???)?0~7
    actionwalk:17 (???????)?0~7
    nod:18 (????)?0~7
    actionstand:19 (???????????)?0~7
    Battle:20 (Pfѩ)?0~7BattleNo(-1 ????SideNoHelpNo?????????CA???????????
    Leader:21 (????ѩ)?0~70:? 1:
    Watch:22 (Pf?P)?0~70:? 1:
    namecolor:23(q?ѩ)?0~7q?k?
    Turn:30(??)?0~7
    Warp:31(???)?0~7
    +1297 : ACTION?k?????????Z??????? +1298 :
    +1299 :
    +1300 :
    +1301 :
    +1302 :
    +1303 : +1304 : +*/ + + if( strcmp( funcname , "CA" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_CA_recv( fd,data); + return 0; + } +/* +1305 :
  • servertoclient CD( string data );
    +1306 : (CharacterDelete) +1307 : data ??????,????????????? +1308 : ????????? +1309 : ??ID???????????????????????????? +1310 : ???? +1311 :
    +1312 :
    +1313 :
    +1314 : +*/ + + if( strcmp( funcname , "CD" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_CD_recv( fd,data); + return 0; + } +/* +1315 :
  • servertoclient R( string data );
    +1316 : (Radar) +1317 : ????????????????????????????? +1318 : ??????????????????????????? +1319 : ????10????????1?????

    +1320 : +1321 :
    +1322 :
    string data +1323 :
    x ,y, kind ,???k?'|'???????????? +1324 : ???'|'???????? +1325 : x,y???????En?t?kind????????k???? +1326 : ??????????????e??????????? +1327 : ????????????????????????? +1328 : ????????? +1329 : +1330 : +1331 : +1332 : +1333 : +1334 : +1335 : +1336 :
    kind?k?
    E
    P?????
    S?
    G??
    I????(???)
    +1337 :
    +1338 : data??"12|22|E|13|24|P|14|28|P" +1339 : ??????????????? +1340 :
    +1341 :
    +1342 :
    +1343 :
    +1344 : +*/ + + if( strcmp( funcname , "R" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_R_recv( fd,data); + return 0; + } +/* +1369 :
  • servertoclient S( string data );
    +1370 : (Status) +1371 : ?????????????? +1372 : ???? ???????(??)? ????????????? +1373 : 1?????????????????2???????? +1374 : ???????????????????S??'|'????????? +1375 : 2???????????????
    +1376 :
    +1377 :
      +1378 :
    • P u?????

      +1379 : kubun hp maxhp mp maxmp str tough exp maxexp exp +1380 : level attackpower deffencepower +1381 : fixdex fixcharm fixluck fixfireat fixwaterat fixearthat fixwindat +1382 : gold ???? +1383 : ??index q ??
      +1384 : +1385 : ????? '|' ??????q????? +1386 : ?????????? +1387 : ??S????????G????
      +1388 : ?????k??????
      +1389 : kubun ???V?????q???????? +1390 : ?????????????????????????k?V????????? +1391 : ?????????hp?Maxhp?kubun ????????t???????
      +1392 : +1393 : +1394 : +1395 : +1396 : +1397 : +1398 : +1399 : +1400 : +1401 : +1402 : +1403 : +1404 : +1405 : +1406 : +1407 : +1408 : +1409 : +1410 : +1411 : +1412 : +1413 : +1414 : +1415 : +1416 : +1417 : +1418 : +1419 :
      kununint
      Hp(l?)hpint
      MaxHpint
      Mp(???)int
      MaxMpint
      Vital(l?)int
      Str(??)int
      Tough(Ǧ?)int
      Dex(??)int
      Exp(??k)expint
      MaxExp(??????k)int
      Level(???)int
      Attack(???)int
      Defense(駍?)int
      fQuick(???)int
      fCharm(u?)int
      fLuck(?)int
      fEarth()fixearthatint
      fWater(?)int
      fFire(?)int
      fWid(?)fixwindatint
      Gold(??)int
      ??indexint
      ????????int
      q??
      ????
      +1420 : ?l?( char ???????? )
      +1421 : +1422 : P10|20|10|20|10|10|10|1|2|13|13|1|100|10|???|abc|def +1423 : +1424 :

      +1425 :
    • C ?

      +1426 : floor maxx maxy x y
      +1427 : ? | ???????
      +1428 : ?l?( char ???????? )
      +1429 : +1430 : C1024|100|100|10|20 +1431 : +1432 : ?????????ID1024, ???100x100 X 10,Y 20??? +1433 : ???????????????????????????? +1434 : ????????????????l??????????? +1435 : ????????????????????t?????? +1436 : ?????????????h????????????? +1437 : ???????????????k???????????? +1438 : +1439 : +1440 :

      +1441 :
    • I u????

      +1442 : (????1)|(????2)...(????n)
      +1443 : ????????????????? +1444 : ?????????????????6??????????? +1445 : ???????????????
      +1446 :
      +1447 : q|q2|????|?????C|???k?|??u?|?n|???????|????
      +1448 :
      +1449 :
        +1450 :
      • ?????????h?????? +1451 :
      • q2??????????????u??V??e? +1452 : ?????????????2???V???? +1453 :
      • ?????q??v????? +1454 :
      • ?????C? +1455 :
      • ???k?????k?? +1456 :
      • ??u????????????????????u??V????? +1457 : ????????????????e???????
        +1458 :
        +1459 : 			typedef enum
        +1460 : 			{
        +1461 : 				ITEM_FIELD_ALL,			????????
        +1462 : 				ITEM_FIELD_BATTLE,		Pf???
        +1463 : 				ITEM_FIELD_MAP,			G?????
        +1464 : 
        +1465 : 			}ITEM_FIELDTYPE;
        +1466 : 	          
        +1467 :
        +1468 :
      • ?n??????????????????n?V????? +1469 : ????????????e??????? +1470 :
        +1471 : 			typedef enum
        +1472 : 			{
        +1473 : 				ITEM_TARGET_MYSELF,		??
        +1474 : 				ITEM_TARGET_OTHER,		\????)
        +1475 : 				ITEM_TARGET_ALLMYSIDE,		sul
        +1476 : 				ITEM_TARGET_ALLOTHERSIDE,	?Dul
        +1477 : 				ITEM_TARGET_ALL,		u?
        +1478 : 			}ITEM_TARGETTYPE;
        +1479 : 		
        +1480 : ?????100?K?????????n????
        +1481 :
      • ???????????????????????? +1482 :
      • ????????????????????n?????G??
        +1483 : +1484 : +1485 : +1486 : +1487 :
        0bit??????????u????????????u?????????????
        1Bit????????????????
        2Bit???????????????1????????
        +1488 :
        +1489 :
        +1490 :
      +1491 :
      +1492 : ??????????????
      +1493 : ?l?( char ???????? )
      +1494 : +1495 : I?? ? |str+2|1|??\|??|10|2|0 +1496 : +1497 : ?????k??s???k? +1498 : +1499 : +1500 : +1501 : +1502 : +1503 :
      1????A
      2????B
      3????C
      4????D
      +1504 : ?????????????????????5??????? +1505 : ????????S?????֢t???????? +1506 : +1507 :

      +1508 :
    • S u???

      +1509 : (???0)|(???1)|(???2) ... (???n)
      +1510 : ??i?????????????????????? +1511 : ?????? ||| ???????? +1512 : ?????????
      +1513 : ????????|???
      +1514 : ????
      +1515 : ?l?( char ???????? )
      +1516 : +1517 : S10|2|20|2||| +1518 : +1519 : +1520 :

      +1521 :
    • T ?

      +1522 : (?0)|(?1)|(?2) ... (?n)

      +1523 : ??????????? '|' ??Q??????Q??? +1524 : ????????????????????????? +1525 : ???
      +1526 : ???????????
      +1527 : q
      +1528 : ??????
      +1529 : ?l?( ?????? char ????????? )
      +1530 : +1531 : T??|????? +1532 : +1533 : ???????????
      +1534 : +1535 :
      +1536 :
    • M ??????

      +1537 : ????????????????`???????(?? +1538 : k)????????(?k??)????????????? +1539 : ??????????u???????????????? +1540 : ??????????j??????????{?HP , +1541 : MP,EXP?k??????????????????????? +1542 : ?????M????????2???????????HP? +1543 : ??k , K?????MP??????EXP???? +1544 : ????l?????? +1545 : +1546 : M54|210|8944909 +1547 : +1548 : ?????HP???k?54?MP???k?210???k?8944909 +1549 : ???????????3??{??T??????? +1550 : ????????????????????M??????? +1551 : ??P?????u?????????????????? +1552 : ?????????????????????????? +1553 : ???? +1554 : +1555 :

      +1556 :
    • D ????ID

      +1557 : ??????????????index?????????? +1558 : D1000|912766409???????? +1559 :

      +1560 :
    • E ???????????)|(?)

      +1561 : ???????????????n/100
      +1562 : ???????????k?????????????+1???????????????Re??? +1563 : ??????k??????????? +1564 : ??????????????????????????????? +1565 : +1566 :

      +1567 :
    • J0 ?J6 ????

      +1568 : ?????????
      +1569 : 0 ?6 ??????????????n?????????????d?q???ߦ? +1570 : ???????e?????????u??????ѩ???
      +1571 : J0|kubun|mp|field|target|name|comment
      +1572 : ????????????????
      +1573 : kubun ???????????????????????????????????? +1574 : mp??????
      +1575 : field????????????????????e???????
      +1576 :
      +1577 : 		typedef enum
      +1578 : 		{
      +1579 : 			MAGIC_FIELD_ALL,		????????
      +1580 : 			MAGIC_FIELD_BATTLE,		Pf???
      +1581 : 			MAGIC_FIELD_MAP,		G?????
      +1582 : 			
      +1583 : 		}MAGIC_FIELDTYPE;
      +1584 : 	    
      +1585 : target????n?????????????????e???????
      +1586 :
      +1587 : 		typedef enum
      +1588 : 		{
      +1589 : 			MAGIC_TARGET_MYSELF,		??
      +1590 : 			MAGIC_TARGET_OTHER,		\????)
      +1591 : 			MAGIC_TARGET_ALLMYSIDE,		sul
      +1592 : 			MAGIC_TARGET_ALLOTHERSIDE,	?Dul
      +1593 : 			MAGIC_TARGET_ALL,		u?
      +1594 : 			MAGIC_TARGET_NONE,		M?k????\??????
      +1595 : 			MAGIC_TARGET_OTHERWITHOUTMYSELF,\??????)
      +1596 : 			MAGIC_TARGET_WITHOUTMYSELFANDPET, ??????
      +1597 : 			MAGIC_TARGET_WHOLEOTHERSIDE,    ©????ul
      +1598 : 		}MAGIC_TARGETTYPE;
      +1599 : 	    
      +1600 : ?????100?K?????????n????
      +1601 :
      +1602 : name??
      +1603 : comment????C?
      +1604 :
      +1605 :
      +1606 :
    • N0 ? N3 ????????

      +1607 : ?????????ѩ?????
      +1608 : N0|kubun|level|charaindex|maxhp|hp|mp|name +1609 :
      +1610 : kubun ???????????????????????????????u??????
      +1611 : 2???????????????????????1bit ? level 2bit ?charaindex??? +1612 : ??????
      +1613 : charaindex ????charaindex
      +1614 : level????????
      +1615 : maxhp????MAXHP
      +1616 : hp???????HP
      +1617 : mp??????
      +1618 : name ????q?
      +1619 :

      +1620 : +1621 :
    • K0?K4 ???????

      +1622 : hp maxhp mp maxmp str tough exp +1623 : level attackpower deffencepower +1624 : fixdex fixcharm fixluck fixfireat fixwaterat fixearthat fixwindat +1625 : q status
      +1626 : K???0?4?e?????????e????? +1627 : ?????????0????????????????? +1628 : ?????????1??u?????? +1629 : 2???????????????????????1bit ? hp 2bit ?maxhp??? +1630 : ??????
      +1631 : ????? '|' ??????q????? +1632 : ?????????? +1633 : ??S????????G????
      +1634 : ?????k?????? +1635 : +1636 : +1637 : +1638 : +1639 : +1640 : +1641 : +1642 : +1643 : +1644 : +1645 : +1646 : +1647 : +1648 : +1649 : +1650 : +1651 : +1652 : +1653 : +1654 : +1655 : +1656 : +1657 : +1658 :
      No.(k?)int
      islive(?)int
      GRA(??k?)int
      Hp(o??)int
      MaxHp(?o??)int
      Mpint
      MapMpint
      Exp(??k)int
      MaxExp(??????k)int
      Level(???)int
      Attack(???)int
      Defense(駍?)int
      Quick(??)int
      Ai(?ߥT)int
      fEarth()int
      fWater(?)int
      fFire(?)int
      fWid(?)int
      Slot(?\?)int
      q??????int
      q??
      ?????????
      +1659 :
      +1660 : q???????????????q???????????????? +1661 : 1 ???ϣ??????????
      +1662 :
      +1663 :
      +1664 :
      +1665 : ?l?( char ???????? )
      +1666 : +1667 : P10|20|10|20|10|10|10|1|2|13|13|1|100|10|???|PC +1668 : +1669 : +1670 :

      +1671 : +1672 :
    • W0?W4 ????????

      +1673 : W0|skillid|field|target|name|comment| x 7
      +1674 : W0 ? W4 ??????????n??????
      +1675 : petskillid ????????k??pet_skillinfo.h?e???????
      +1676 : field ??????????????????????????e???????
      +1677 :
      +1678 : 		typedef enum
      +1679 : 		{
      +1680 : 			PETSKILL_FIELD_ALL,		????????
      +1681 : 			PETSKILL_FIELD_BATTLE,		Pf???
      +1682 : 			PETSKILL_FIELD_MAP,		G?????
      +1683 : 
      +1684 : 		}PETSKILL_FIELDTYPE;
      +1685 : 	  
      +1686 : 	  
      +1687 : target ?????n????????????????????e???????
      +1688 :
      +1689 : 		typedef enum
      +1690 : 		{
      +1691 : 			PETSKILL_TARGET_MYSELF,		??
      +1692 : 			PETSKILL_TARGET_OTHER,		\????)
      +1693 : 			PETSKILL_TARGET_ALLMYSIDE,	sul
      +1694 : 			PETSKILL_TARGET_ALLOTHERSIDE,	?Dul
      +1695 : 			PETSKILL_TARGET_ALL,		u?
      +1696 : 			PETSKILL_TARGET_NONE,		M?k????\??????
      +1697 : 			PETSKILL_TARGET_OTHERWITHOUTMYSELF,\??????) 
      +1698 : 			PETSKILL_TARGET_WITHOUTMYSELFANDPET, ??????
      +1699 : 		}PETSKILL_TARGETTYPE;
      +1700 : 	  
      +1701 :
      +1702 : name ???q?
      +1703 : comment?????n??C?
      +1704 : target|name|comment| ??????????????? +1705 : ?????????N????I?????"|"???Q??? +1706 : ???????????????
      +1707 :

      +1708 : +1709 :
    +1710 : +1711 :
    +1712 :
    +1713 :
    +1714 : +*/ + + if( strcmp( funcname , "S" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_S_recv( fd,data); + return 0; + } +/* +1715 :
  • servertoclient D( int category , int dx , int dy , string data );
    +1716 : (Display) +1717 : ????????

    +1718 : +1719 :
    +1720 :
    int category +1721 :
    ?????? +1722 : +1723 : +1724 : +1726 : +1728 :
    k?
    1???????????data?? +1725 : ?????k?
    2?????????data???? +1727 : ???k
    +1729 :
    int dx +1730 :
    ?????????????n?tX??a???????D +1731 : ???t??????????k?????t???? +1732 : ???? +1733 :
    int dy +1734 :
    ?n?tY +1735 :
    string data +1736 :
    ??????category???????? +1737 : ???????????????? +1738 : ????? +1739 :
    +1740 :
    +1741 :
    +1742 :
    +1743 :
    +1744 :
    +*/ + + if( strcmp( funcname , "D" ) == 0 ){ + int category; + int dx; + int dy; + char* data; + category = lssproto_demkstr_int( lssproto.token_list[2] ); + dx = lssproto_demkstr_int( lssproto.token_list[3] ); + dy = lssproto_demkstr_int( lssproto.token_list[4] ); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[4] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[5] )); + lssproto_D_recv( fd,category,dx,dy,data); + return 0; + } +/* +1760 :
  • servertoclient FS( int flg);
    +1761 : (FlgSet)PS?????????????????֢t??????????

    +1762 :
    +1763 :
    int flg +1764 :
    0 bit 0: ??Off 1: ??On
    +1765 : ???t??1 bit 0: PfN??off 1: PfN??On
    +1766 : 2 bit 0: DUEL off 1: DUEL On
    +1767 : 3 bit 0: ?G???????? 1: ??????????????????
    +1768 : 4 bit 0: ??OK 1: ???r
    +1769 :
    +1770 :
    +1771 :
    +1772 :
    +1773 :
    +*/ + + if( strcmp( funcname , "FS" ) == 0 ){ + int flg; + flg = lssproto_demkstr_int( lssproto.token_list[2] ); + lssproto_FS_recv( fd,flg); + return 0; + } +/* +1785 :
  • servertoclient HL( int flg);
    +1786 : (HeLp)HL????????????????Pf????????????????????

    +1787 :
    +1788 :
    int flg +1789 :
    0: ??????Off 1: ??????On
    +1790 :
    +1791 :
    +1792 :
    +1793 :
    +1794 :
    +*/ + + if( strcmp( funcname , "HL" ) == 0 ){ + int flg; + flg = lssproto_demkstr_int( lssproto.token_list[2] ); + lssproto_HL_recv( fd,flg); + return 0; + } +/* +1808 :
  • servertoclient PR( int request, int result);
    +1809 : (PartyRequest)????????PR?????????????????????????? +1810 : ?????t???I???????? +1811 :

    +1812 : +1813 :
    +1814 :
    int request +1815 :
    0: ? 1:V +1816 :
    int result +1817 :
    0: 1: ? +1818 :
    +1819 :
    +1820 :
    +1821 :
    +1822 :
    +1823 :
    +*/ + + if( strcmp( funcname , "PR" ) == 0 ){ + int request; + int result; + request = lssproto_demkstr_int( lssproto.token_list[2] ); + result = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_PR_recv( fd,request,result); + return 0; + } +/* +1835 :
  • servertoclient KS( int petarray,int result);
    +1836 : ???????KS?n???????????????????????? +1837 : ????????????????????? +1838 : ???Pf???k???????????????????????t??????k????????? +1839 : ??????????????? +1840 :

    +1841 : +1842 :
    +1843 :
    int petarray +1844 :
    ????k? +1845 :
    int result +1846 :
    0: ????k????????? 1:? +1847 :
    +1848 :
    +1849 :
    +1850 :
    +1851 :
    +*/ + + if( strcmp( funcname , "KS" ) == 0 ){ + int petarray; + int result; + petarray = lssproto_demkstr_int( lssproto.token_list[2] ); + result = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_KS_recv( fd,petarray,result); + return 0; + } +/* +1935 :
  • servertoclient PS( int result, int havepetindex, int havepetskill, int toindex);
    +1936 : (PetSkill use result)?????????????????PS?n?????????? +1937 : result ??????????PS?n????????????????????? +1938 : +1939 :
    +1940 :
    int result +1941 :
    ???0: 1:? +1942 :
    int havepetindex +1943 :
    ?k??????????? +1944 :
    int havepetskill +1945 :
    ?k????????? +1946 :
    int toindex +1947 :
    M??????????????????????index???????????????? +1948 :
    +1949 : 	      = 0
    +1950 : 	  ???  = 1 ?5
    +1951 : 	  ??    = 6 ?10 ?S N ?0?4?n??????????
    +1952 : 	
    +1953 : n?u??????????????-1?????
    +1954 :
    +1955 : +1956 :
    +1957 : +1958 :
    +1959 :
    +1960 :
    +1961 :
    +1962 : +*/ + + if( strcmp( funcname , "PS" ) == 0 ){ + int result; + int havepetindex; + int havepetskill; + int toindex; + result = lssproto_demkstr_int( lssproto.token_list[2] ); + havepetindex = lssproto_demkstr_int( lssproto.token_list[3] ); + havepetskill = lssproto_demkstr_int( lssproto.token_list[4] ); + toindex = lssproto_demkstr_int( lssproto.token_list[5] ); + lssproto_PS_recv( fd,result,havepetindex,havepetskill,toindex); + return 0; + } +/* +2011 :
  • servertoclient SKUP( int point );
    +2012 : (SKillUP) +2013 : ????????????????Gl????????????e??? +2014 :
    +2015 :
    +2016 :
    +2017 :
    +2018 : +*/ + + if( strcmp( funcname , "SKUP" ) == 0 ){ + int point; + point = lssproto_demkstr_int( lssproto.token_list[2] ); + lssproto_SKUP_recv( fd,point); + return 0; + } +/* +2047 :
  • servertoclient WN( int windowtype, int buttontype, int seqno, int objindex, string data );
    +2048 : (Window)
    +2049 : ?????????????????????Gl???
    +2050 :
    +2051 :
    +2052 :
    int windowtype +2053 :
    ?????????????????????????????buttontype ?????? +2054 : ???????e???
    +2055 : ???????????@e??????
    +2056 :
    +2057 : 		typedef enum
    +2058 : 		{
    +2059 : 			WINDOW_MESSAGETYPE_MESSAGE,			???????
    +2060 : 			WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT,		????????V?
    +2061 : 			WINDOW_MESSAGETYPE_SELECT,			k?????
    +2062 : 			WINDOW_MESSAGETYPE_PETSELECT,			???k?????
    +2063 : 			WINDOW_MESSAGETYPE_PARTYSELECT,			??k?????
    +2064 : 			WINDOW_MESSAGETYPE_PETANDPARTYSELECT,		??????k?????
    +2065 : 			WINDOW_MESSAGETYPE_ITEMSHOPMENU,		???????????
    +2066 : 			WINDOW_MWSSAGETYPE_ITEMSHOPYMAIN,		??????????
    +2067 : 			WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN,		???M???????????????
    +2068 : 			WINDOW_MESSAGETYPE_PETSKILLSHOP,		?????????????
    +2069 : 			WINDOW_MESSAGETYPE_WIDEMESSAGE,			???????????
    +2070 : 			WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT,	????????V?????
    +2071 : 
    +2072 : 		}WINDOW_MESSAGETYPE;
    +2073 : 	  
    +2074 : +2075 :
    int buttontype +2076 :
    ??????e??????????????e???????
    +2077 :
    +2078 : 		#define		WINDOW_BUTTONTYPE_NONE		(0)
    +2079 : 		#define		WINDOW_BUTTONTYPE_OK		(1 << 0)
    +2080 : 		#define		WINDOW_BUTTONTYPE_CANCEL	(1 << 1)
    +2081 : 		#define		WINDOW_BUTTONTYPE_YES		(1 << 2)
    +2082 : 		#define		WINDOW_BUTTONTYPE_NO		(1 << 3)
    +2083 : 		#define		WINDOW_BUTTONTYPE_PREV		(1 << 4)
    +2084 : 		#define		WINDOW_BUTTONTYPE_NEXT		(1 << 5)
    +2085 :             
    +2086 : ?????????????????YES????NO?????????
    +2087 : WINDOW_BUTTONTYPE_YES | WINDOW_BUTTONTYPE_NO (=12)
    +2088 : ???? +2089 : +2090 :
    int seqno +2091 :
    ????????k?????????????? +2092 : ???????WN?????????????????????k???????? +2093 : ?????????????NPC????????????Re???????? +2094 :
    int objindex +2095 :
    ?????????????NPC???index??t?????? +2096 : ????????????-1???V????? +2097 : ?????????????V???WN?????????k?????????? +2098 :
    string data +2099 :
    ???????????????????"\n"??????????s???? +2100 : ??????????????????????????h??????? +2101 : k????????????"\n"????????????????????? +2102 : ?????????????????????????e?????Q?? +2103 : ????????????????k???????q???? 1 ?? +2104 : k???????k????WN???????? +2105 :
    string data(??? +2106 :
    ???????????????????"\n"??????????s???? +2107 : ??????????????????????????h??????? +2108 : ????????"?"????????? +2109 :

    ????
    +2110 : ????????????????q???????????????1?? +2111 : ?q???????????????k?????????K??????????_?????? +2112 : ?????????????????????????????????????????????????? +2113 : kh???k??C?????????????????????????kh???k??C +2114 :

    +2115 : 0|1|????????|?????????????|???????????|?????|???????????? +2116 : K??????????|o???????|?????????????????????????| +2117 : ?|???|?????|??????\n??I?|??|?|??|?????|??????\nT?????\n??? +2118 : +2119 :

    ????
    +2120 : ????????????????q???????????????1?? +2121 : ?q???????????????????????????????|?_?????? +2122 : ????????????????kh???k??C????????????????? +2123 : kh???k??C? +2124 : +2125 :

    +2126 : ?|1|?????s??|?????????????????????????????|o???????| +2127 : ???????????????????????|?|??|?????| +2128 : ??????\n??I?|??|?|??|?????|??????\nT?????\n??? +2129 :

    ?????????
    +2130 : ??????=??????????????
    +2131 : ?q?
    +2132 : ?????????????????????????_??????
    +2133 : q????????????u????????kh???k??????????????k??????
    +2134 : q????????????u????????kh???k??????????????k??????
    +2135 :

    ?????????
    +2136 : ???????=??? +2137 : ?q????????????????????????|?_??????
    +2138 : q??????????????u????????????????kh???k?????????
    +2139 : q??????????????u????????????????kh???k?????????
    +2140 : +2141 : +2142 :

    ???\?
    +2143 : ?q?????? +2144 : +2145 :

    +2146 : ?????s??|???????????? +2147 : +2148 :


    +2149 :
    string data(?????????? +2150 :
    ???????????????????"\n"??????????s???? +2151 : ??????????????????????????h??????? +2152 : ????????"?"????????? +2153 :

    ??????x?
    +2154 : q?ѩ????????0 ???1???q?????????? +2155 : ??kh??C???kh??C +2156 :

    +2157 : 1????????????????????????????????? +2158 : ??????500????????? \?????????? +2159 : ???1000???D?????????? +2160 :
    +2161 :
    +2162 :
    +2163 :
    +2164 :
    +2165 : +*/ + + if( strcmp( funcname , "WN" ) == 0 ){ + int windowtype; + int buttontype; + int seqno; + int objindex; + char* data; + windowtype = lssproto_demkstr_int( lssproto.token_list[2] ); + buttontype = lssproto_demkstr_int( lssproto.token_list[3] ); + seqno = lssproto_demkstr_int( lssproto.token_list[4] ); + objindex = lssproto_demkstr_int( lssproto.token_list[5] ); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[5] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[6] )); + lssproto_WN_recv( fd,windowtype,buttontype,seqno,objindex,data); + return 0; + } +/* +2196 :
  • servertoclient EF( int effect, int level, string option );
    +2197 : (EFfect)
    +2198 : D????????????????ul??????????
    +2199 :
    +2200 :
    +2201 :
    int effect +2202 :
    ??k???????K????????????x????????????D??????????? +2203 :
      +2204 :
    • 1:? +2205 :
    • 2:D +2206 :
    • 4:??D??e? +2207 :
    +2208 :
    int level +2209 :
    ????????????????????? +2210 :
    string option +2211 :
    ???? +2212 :
    +2213 :
    +2214 :
    +2215 :
    +2216 :
    +2217 : +*/ + + if( strcmp( funcname , "EF" ) == 0 ){ + int effect; + int level; + char* option; + effect = lssproto_demkstr_int( lssproto.token_list[2] ); + level = lssproto_demkstr_int( lssproto.token_list[3] ); + option = lssproto_wrapStringAddr( lssproto_stringwrapper[3] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[4] )); + lssproto_EF_recv( fd,effect,level,option); + return 0; + } +/* +2218 :
  • servertoclient SE( int x, int y, int senumber, int sw );
    +2219 : (SoundEffect)
    +2220 : ???????SE?????????
    +2221 :
    +2222 :
    +2223 :
    int x,y +2224 :
    SE?D???? +2225 :
    int senumber +2226 :
    ???k? +2227 :
    int sw +2228 :
    ?????????? +2229 :
      +2230 :
    • 0:?? +2231 :
    • 1:?? +2232 :
    +2233 :
    +2234 :
    +2235 :
    +2236 :
    +2237 :
    +*/ + + if( strcmp( funcname , "SE" ) == 0 ){ + int x; + int y; + int senumber; + int sw; + x = lssproto_demkstr_int( lssproto.token_list[2] ); + y = lssproto_demkstr_int( lssproto.token_list[3] ); + senumber = lssproto_demkstr_int( lssproto.token_list[4] ); + sw = lssproto_demkstr_int( lssproto.token_list[5] ); + lssproto_SE_recv( fd,x,y,senumber,sw); + return 0; + } +/* +2271 :
  • servertoclient ClientLogin(string result);
    +2272 : ClientLogin??? +2273 :

    +2274 :
    +2275 :
    string result +2276 :
    "ok" ????????????????????? +2277 :
    +2278 :
    +2279 :
    +2280 :
    +2281 :
    +2282 : +2283 : +*/ + + if( strcmp( funcname , "ClientLogin" ) == 0 ){ + char* result; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_ClientLogin_recv( fd,result); + return 0; + } +/* +2314 :
  • servertoclient CreateNewChar(string result,string data);
    +2315 : CreateNewChar??? +2316 :

    +2317 :
    +2318 :
    string result +2319 :
    "successful" ? "failed" ??????????????? +2320 : ????? +2321 :
    string data +2322 :
    "failed" ????????????? +2323 : ????????????????????????? +2324 : ????? +2325 :
    +2326 : 	    "failed bad parameter"
    +2327 : 	    
    +2328 : ?????????????e???????d????? +2329 : ????????s??????????????????? +2330 : ????????????????????? +2331 : +2332 :
    +2333 :
    +2334 :
    +2335 :
    +2336 :
    +2337 : +*/ + + if( strcmp( funcname , "CreateNewChar" ) == 0 ){ + char* result; + char* data; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_CreateNewChar_recv( fd,result,data); + return 0; + } +/* +2349 :
  • servertoclient CharDelete(string result,string data);
    +2350 : CharDelete ??? +2351 :

    +2352 :
    +2353 :
    string result +2354 :
    "successful" ? "failed" ??????????????? +2355 :
    string data +2356 :
    "failed" ????????????? +2357 : ????????????????????????? +2358 : ?????????????????????? +2359 :
    +2360 :
    +2361 :
    +2362 :
    +2363 :
    +2364 : +2365 : +*/ + + if( strcmp( funcname , "CharDelete" ) == 0 ){ + char* result; + char* data; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_CharDelete_recv( fd,result,data); + return 0; + } +/* +2376 :
  • servertoclient CharLogin(string result,string data);
    +2377 : CharaLogin??? +2378 :

    +2379 :
    +2380 :
    string result +2381 :
    "successful" ? "failed" ??????????????? +2382 :
    string data +2383 :
    "failed" ??? ????????????????? +2384 :
    +2385 :
    +2386 :
    +2387 :
    +2388 :
    +2389 : +2390 : +*/ + + if( strcmp( funcname , "CharLogin" ) == 0 ){ + char* result; + char* data; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_CharLogin_recv( fd,result,data); + return 0; + } +/* +2396 :
  • servertoclient CharList(string result,string data);
    +2397 : CharList??? +2398 :

    +2399 :
    +2400 :
    string result +2401 :
    "successful" ? "failed" ?????????????? +2402 :
    string data +2403 :
    result?"successful"??????????????V??? +2404 : ??????????q???????????????? +2405 : ???????????????????????????? +2406 : result ? "failed" ??????????????? +2407 : ?????????????????????????
    +2408 : dataplace|faceimage|level|maxhp|atk|def|quick|charm|earth|water|fire|wind|logincount|name|place
    +2409 : +2410 :
    +2411 :
    dataplace +2412 :
    ????????k?????????????????k????e??? +2413 :
    faceimage +2414 :
    ????k? +2415 :
    level +2416 :
    ??????? +2417 :
    maxhp,atk,def,quick,charm +2418 :
    ??????? +2419 :
    earth.water,fire,wind +2420 :
    ?Nͣk +2421 :
    logincount +2422 :
    ???????? +2423 :
    name +2424 :
    ????q +2425 :
    place +2426 :
    ??????? +2427 :
    +2428 : "|" ???????? ??????????????????????????S +2430 : ??????
    +2431 : +2432 :
    +2433 :
    +2434 :
    +2435 :
    +2436 :
    +2437 : +*/ + + if( strcmp( funcname , "CharList" ) == 0 ){ + char* result; + char* data; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_CharList_recv( fd,result,data); + return 0; + } +/* +2445 :
  • servertoclient CharLogout(string result , string data);
    +2446 : Logout?n???? +2447 :

    +2448 :
    +2449 :
    string result +2450 :
    "successful" ? "failed" ??????????????? +2451 :
    string data +2452 :
    "failed" ??????s???????(֢t)??? +2453 : ??????????????????? +2454 :
    +2455 :
    +2456 :
    +2457 :
    +2458 :
    +*/ + + if( strcmp( funcname , "CharLogout" ) == 0 ){ + char* result; + char* data; + result = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_CharLogout_recv( fd,result,data); + return 0; + } +/* +2465 :
  • servertoclient ProcGet( string data);
    +2466 : ProcGet??? +2467 :

    +2468 :
    +2469 :
    string data +2470 :
    ?????????????????ѩ???????log/proc???????????i?? +2471 :
    +2472 :
    +2473 :
    +2474 :
    +2475 :
    +2476 : +*/ + + if( strcmp( funcname , "ProcGet" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_ProcGet_recv( fd,data); + return 0; + } +/* +2483 :
  • servertoclient PlayerNumGet( int logincount, int player);
    +2484 : PlayerNumGet??? +2485 :

    +2486 :
    +2487 :
    int logincount,player +2488 :
    +2489 :
    +2490 :
    +2491 :
    +2492 :
    +2493 :
    +2494 : +*/ + + if( strcmp( funcname , "PlayerNumGet" ) == 0 ){ + int logincount; + int player; + logincount = lssproto_demkstr_int( lssproto.token_list[2] ); + player = lssproto_demkstr_int( lssproto.token_list[3] ); + lssproto_PlayerNumGet_recv( fd,logincount,player); + return 0; + } +/* +2506 :
  • servertoclient Echo( string test );
    +2507 : Echo?n???? +2508 :
    +2509 :
    string test +2510 :
    ????V???????????????? +2511 :
    +2512 :
    +2513 :
    +2514 :
    +2515 :
    +2516 : +*/ + + if( strcmp( funcname , "Echo" ) == 0 ){ + char* test; + test = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_Echo_recv( fd,test); + return 0; + } + +//------------------------------------------------------- +// Add Command Count +// Robin 2001/04/06 +//------------------------------------------------------- + + if( strcmp( funcname , "NU" ) == 0 ){ + int AddCount; + AddCount = lssproto_demkstr_int( lssproto.token_list[2] ); + lssproto_NU_recv( fd, AddCount); + return 0; + } + + // Robin 04/12 trade + if( strcmp( funcname , "TD" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[2] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[3] )); + lssproto_TD_recv( fd, data); + return 0; + } + + // Robin 0529 family + if( strcmp( funcname , "FM" ) == 0 ){ + char* data; + data = lssproto_wrapStringAddr( lssproto_stringwrapper[1] , lssproto.workbufsize , lssproto_demkstr_string( lssproto.token_list[2] )); + lssproto_FM_recv( fd, data); + //lssproto_FM_recv( fd, lssproto_stringwrapper[0] ); + return 0; + } + + return -1; +} +void lssproto_SetClientLogFiles( char *r , char *w ) +{ + lssproto_strcpysafe( lssproto_readlogfilename , r , sizeof( lssproto_readlogfilename ) ); + lssproto_strcpysafe( lssproto_writelogfilename , w , sizeof( lssproto_writelogfilename ) ); +} +int lssproto_InitClient( int (*writefunc)(int,char*,int) ,int bufsiz ,int fd) +{ + int i; + if( (void*)writefunc == NULL){lssproto.write_func = lssproto_default_write_wrap;} else {lssproto.write_func = writefunc;} + lssproto_AllocateCommonWork(bufsiz); + lssproto_stringwrapper = (char**)MALLOC(sizeof(char*) * MAXLSRPCARGS); + if(lssproto_stringwrapper ==NULL)return -1; + memset( lssproto_stringwrapper , 0, sizeof(char*)*MAXLSRPCARGS); + for(i=0;i +#include +#include +#include +#ifndef WIN32 +#include +#include +#endif +#include "../systeminc/version.h" +#include "../systeminc/lssproto_util.h" +#include "../systeminc/netmain.h" +#ifdef lssproto__ENCRYPT +long lssproto_ringoCompressor( unsigned char *code , long codelen , unsigned char *text , long textlen); +long lssproto_ringoDecompressor( unsigned char *text , long textlen , unsigned char *code , long codelen); +#endif +/* + lsrpc routines +*/ +// Nuke +1 +//#include +//char *NJT_dummy; +//char *NJT[NJT_MAX]; + +int lssproto_AllocateCommonWork(int bufsiz) +{ +// Terry add for Ϊʽظдfunctionmemory leak Ҫһ˽Ƿѱй + static BOOL bInit; +// Terry end + // Nuke start + /*int i; + NJT_dummy=(char *)MALLOC(time(NULL)%bufsiz); + for (i=0;i (int)( lssproto.workbufsize*3-2) ){ + fprintf( stderr, "lsgen: badly configured work buflen\n" ); + exit(1); + } + if( (flag%2) == 1 ) flag ++; + lssproto.compresswork[0] = flag; + memcpy( lssproto.compresswork+1,src,srclen ); + compressed_l = srclen + 1; + } else { + if((flag%2)==0)flag++; + lssproto.compresswork[0] = flag; + compressed_l = lssproto_ringoCompressor( + (unsigned char*)lssproto.compresswork + 1 , + (long)lssproto.workbufsize*3 - 1, + (unsigned char*)src , + (long)strlen(src) ) + 1; /* be careful! */ + } + /* return empty line if error or buffer excess */ + if( compressed_l <= 0 ){ + lssproto_strcpysafe( out , "\n" , maxoutlen ); + return; + } + memcpy( lssproto.jencodecopy ,lssproto.compresswork ,compressed_l ); + lssproto_jEncode( lssproto.jencodecopy , compressed_l , JENCODE_KEY , + lssproto.jencodeout, &jencodedlen , lssproto.workbufsize*3 -1 ); + lssproto_encode64( (unsigned char*)lssproto.jencodeout , jencodedlen, (unsigned char*)out ); +} +/* translate code64 text to original lsrpc text */ +static void lssproto_decodeString( char *src , char *out ) +{ + int compressed_l =0, outlen64; + int l; + long decompressed_l = 0; + /* copy src to copybuffer because jencoder modifies the input buffer */ + l = strlen( src ); + if( src[l-1]=='\n' || src[l-1]=='\r' )src[l-1]=0; + if( src[l-2]=='\n' || src[l-2]=='\r' )src[l-2]=0; + outlen64 = lssproto_decode64( (unsigned char*)src , (unsigned char*)lssproto.jencodecopy ); + lssproto_jDecode( lssproto.jencodecopy , outlen64 , JENCODE_KEY, + lssproto.compresswork , &compressed_l); + /*out[outlen]=0; PENDING*/ + if( (lssproto.compresswork[0] % 2 ) == 0 ){ + if( compressed_l <= 0 ){ + decompressed_l = 0; + fprintf( stderr, "LSRPC: too short:[%s]\n", src ); + } else { + memcpy( out, lssproto.compresswork+1, compressed_l -1 ); + decompressed_l = compressed_l -1; + } + } else { + decompressed_l = + lssproto_ringoDecompressor( (unsigned char*)out , + (long)lssproto.workbufsize , + (unsigned char*)lssproto.compresswork+1 , + (long)compressed_l -1 ); + } + out[decompressed_l] = 0; +} +/* followings are taken from code64.c */ +char lssproto_charset[64]={ + 'A','B','C','D', 'E','F','G','H', + 'I','J','K','L', 'M','N','O','P', + 'Q','R','S','T', 'U','V','W','X', + 'Y','Z','a','b', 'c','d','e','f', + 'g','h','i','j', 'k','l','m','n', + 'o','p','q','r', 's','t','u','v', + 'w','x','y','z', '0','1','2','3', + '4','5','6','7', '8','9','+','-' +}; +char lssproto_reversecharset[256]={ + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,62, 0,63,0,0, + 52,53,54,55, 56,57,58,59, + 60,61,0,0, 0,0,0,0, + 0,0,1,2, 3,4,5,6, + 7,8,9,10, 11,12,13,14, + 15,16,17,18, 19,20,21,22, + 23,24,25,0, 0,0,0,0, + 0,26,27,28, 29,30,31,32, + 33,34,35,36, 37,38,39,40, + 41,42,43,44, 45,46,47,48, + 49,50,51,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0 +}; + +static void lssproto_encode64( unsigned char *in , int len , unsigned char *out ) +{ + int i; + int use_bytes; + int address = 0; + out[0] = 0; + for(i=0;;i+=3){ + unsigned char in1 , in2 , in3; + unsigned char out1 ,out2 , out3 , out4; + if( i >= len ) break; + if( i >= (len-1)){ /* the last letter ( to be thrown away ) */ + in1 = in[i] & 0xff; + in2 = in3 = 0; + use_bytes = 2; + } else if( i >= (len-2)){ /* the last 2 letters ( process only 1 byte)*/ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = 0; + use_bytes = 3; + } else { /* there are more or equal than 3 letters */ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = in[i+2] & 0xff; + use_bytes = 4; + } + out1 = ((in1 & 0xfc)>>2) & 0x3f; + out2 = ((in1 & 0x03)<<4) | ((( in2 & 0xf0)>>4)&0x0f); + out3 = ((in2 & 0x0f)<<2) | ((( in3 & 0xc0)>>6)&0x03); + out4 = (in3 & 0x3f ); + if( use_bytes >= 2 ){ + out[address++] = lssproto_charset[out1]; + out[address++] = lssproto_charset[out2]; + out[address]=0; + } + if( use_bytes >= 3 ){ + out[address++] = lssproto_charset[out3]; + out[address]=0; + } + if( use_bytes >= 4 ){ + out[address++] = lssproto_charset[out4]; + out[address]=0; + } + } +} +/* + * Decode it + * char *in : encoded ascii chars + * char *out : decoded( output) + * return value : output byte count + * + * note: no need to have bigger buffer. because output is to + * be smaller than input string size + */ +static int lssproto_decode64( unsigned char *in , unsigned char *out ) +{ + unsigned char in1 , in2 , in3 , in4; + unsigned char out1 , out2 , out3; + int use_bytes; + int address= 0; + int i; + for(i=0;;i+=4 ){ + if( in[i] == 0 ){ + break; + } else if( in[i+1] == 0 ){ /* the last letter */ + break; + } else if( in[i+2] == 0 ){ /* the last 2 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = in4 = 0; + use_bytes = 1; + } else if( in[i+3] == 0 ){ /* the last 3 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = lssproto_reversecharset[in[i+2]]; + in4 = 0; + use_bytes = 2; + } else { /* process 4 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = lssproto_reversecharset[in[i+2]]; + in4 = lssproto_reversecharset[in[i+3]]; + use_bytes = 3; + } + out1 = (in1<<2) | (((in2 & 0x30)>>4)&0x0f) ; + out2 = ((in2 & 0x0f )<<4) | ((( in3 & 0x3c)>>2)&0x0f); + out3 = ( (in3 &0x03)<<6) | ( in4 & 0x3f ); + if( use_bytes >= 1 ){ + out[address++] = out1; + } + if( use_bytes >= 2 ){ + out[address++] = out2; + } + if( use_bytes >= 3 ){ + out[address++] = out3; + } + if( use_bytes != 3 ){ + break; + } + } + return address; +} + +/* followings are taken from Jencode.c by jun */ +static void lssproto_jEncode(char *src,int srclen,int key,char *encoded,int *encodedlen,int maxencodedlen) +{ + char sum=0; + int i; + if(srclen+1 > maxencodedlen){ + *encodedlen = maxencodedlen; + for(i=0;i<(*encodedlen);i++)encoded[i] = src[i]; + } + if(srclen+1 <= maxencodedlen){ + *encodedlen=srclen+1; + for(i=0;i i) encoded[i] = src[i] + sum*((i*i)%3); + if(abs((key%srclen)) == i) encoded[i] = sum; + if(abs((key%srclen)) < i) encoded[i] = src[i-1] + sum*((i*i)%7); + } + } +} +static void lssproto_jDecode(char *src,int srclen,int key,char *decoded,int *decodedlen) +{ + char sum=0; + int i; + *decodedlen=srclen-1; + if( *decodedlen == 0 ){ + return; /* return error if length is 0 */ + } + sum = src[abs(key%(*decodedlen))]; + for(i=0;i i) decoded[i] = src[i] - sum*((i*i)%3); + if(abs((key%(*decodedlen))) < i) decoded[i-1] = src[i] - sum*((i*i)%7); + } + for(i=0;i<(*decodedlen);i++){ + if(((key%7) == (i%5))||((key%2) == (i%2)))decoded[i] = ~decoded[i]; + } +} + +/*****************************************************************/ +/* Compress / Decompress routine */ +/*****************************************************************/ +#define B00000000 0 +#define B00000001 1 +#define B00000010 2 +#define B00000011 3 +#define B00000100 4 +#define B00000101 5 +#define B00000110 6 +#define B00000111 7 +#define B00001000 8 +#define B00001001 9 +#define B00001010 10 +#define B00001011 11 +#define B00001100 12 +#define B00001101 13 +#define B00001110 14 +#define B00001111 15 +#define B00010000 16 +#define B00010001 17 +#define B00010010 18 +#define B00010011 19 +#define B00010100 20 +#define B00010101 21 +#define B00010110 22 +#define B00010111 23 +#define B00011000 24 +#define B00011001 25 +#define B00011010 26 +#define B00011011 27 +#define B00011100 28 +#define B00011101 29 +#define B00011110 30 +#define B00011111 31 +#define B00100000 32 +#define B00100001 33 +#define B00100010 34 +#define B00100011 35 +#define B00100100 36 +#define B00100101 37 +#define B00100110 38 +#define B00100111 39 +#define B00101000 40 +#define B00101001 41 +#define B00101010 42 +#define B00101011 43 +#define B00101100 44 +#define B00101101 45 +#define B00101110 46 +#define B00101111 47 +#define B00110000 48 +#define B00110001 49 +#define B00110010 50 +#define B00110011 51 +#define B00110100 52 +#define B00110101 53 +#define B00110110 54 +#define B00110111 55 +#define B00111000 56 +#define B00111001 57 +#define B00111010 58 +#define B00111011 59 +#define B00111100 60 +#define B00111101 61 +#define B00111110 62 +#define B00111111 63 +#define B01000000 64 +#define B01000001 65 +#define B01000010 66 +#define B01000011 67 +#define B01000100 68 +#define B01000101 69 +#define B01000110 70 +#define B01000111 71 +#define B01001000 72 +#define B01001001 73 +#define B01001010 74 +#define B01001011 75 +#define B01001100 76 +#define B01001101 77 +#define B01001110 78 +#define B01001111 79 +#define B01010000 80 +#define B01010001 81 +#define B01010010 82 +#define B01010011 83 +#define B01010100 84 +#define B01010101 85 +#define B01010110 86 +#define B01010111 87 +#define B01011000 88 +#define B01011001 89 +#define B01011010 90 +#define B01011011 91 +#define B01011100 92 +#define B01011101 93 +#define B01011110 94 +#define B01011111 95 +#define B01100000 96 +#define B01100001 97 +#define B01100010 98 +#define B01100011 99 +#define B01100100 100 +#define B01100101 101 +#define B01100110 102 +#define B01100111 103 +#define B01101000 104 +#define B01101001 105 +#define B01101010 106 +#define B01101011 107 +#define B01101100 108 +#define B01101101 109 +#define B01101110 110 +#define B01101111 111 +#define B01110000 112 +#define B01110001 113 +#define B01110010 114 +#define B01110011 115 +#define B01110100 116 +#define B01110101 117 +#define B01110110 118 +#define B01110111 119 +#define B01111000 120 +#define B01111001 121 +#define B01111010 122 +#define B01111011 123 +#define B01111100 124 +#define B01111101 125 +#define B01111110 126 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 +/* masks for first byte ( write )*/ +int lssproto_modifymask_first[8][9]={ + {0, B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111},/* mod 0*/ + {0, B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111},/* mod 1*/ + {0, B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111},/* mod 2*/ + {0, B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111},/* mod 3*/ + {0, B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 4*/ + {0, B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 5*/ + {0, B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 6*/ + {0, B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 7*/ +}; +/* masks for second byte ( write ) */ +int lssproto_modifymask_second[8][9]={ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},/* mod 0 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001},/* mod 1 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011},/* mod 2 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111},/* mod 3 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111},/* mod 4 */ + {0, B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111},/* mod 5 */ + {0, B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111},/* mod 6 */ + {0, B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111},/* mod 7 */ +}; +/* + * used by bitstream routines + */ +int bitstream_maxbyte, bitstream_bitaddr ; +char *bitstream_buf; +/* initialize bitstream for output */ +static int initOutputBitStream( char *buf ,int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + memset( buf,0, buflen); + return 0; +} +/* initialize bitstream for input */ +static int initInputBitStream( char *buf , int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + return 0; +} +/* + * read from bit stream. used only from 1 bit to 8 bits + * this is a base routine + */ +static unsigned int readInputBitStreamBody( int bwidth ) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return if excess */ + if( byteaddr >= bitstream_maxbyte)return 0; + if( bwidth >= 1 && bwidth <= 8){ + int b1 = (( bitstream_buf[byteaddr] & lssproto_modifymask_first[mod][bwidth] )>>mod); + int b2 = (( bitstream_buf[byteaddr+1] & lssproto_modifymask_second[mod][bwidth])<<(8-mod)); + bitstream_bitaddr += bwidth; + return b1 | b2; + } else { + return 0; + } +} +/* + * read from bit stream. used from 1 bit to 32 bits + * + */ +static unsigned int readInputBitStream( int bwidth ) +{ + if( bwidth <= 0 ){ + return 0; + } else if( bwidth >= 1 && bwidth <= 8 ){ + return readInputBitStreamBody( bwidth ); + } else if( bwidth >= 9 && bwidth <= 16 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody( bwidth-8); + return first + (second << 8 ); + } else if( bwidth >= 17 && bwidth <= 24 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ); + } else if( bwidth >= 25 && bwidth <= 32 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(8); + unsigned int forth = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ) + ( forth << 24 ); + } + return 0; +} +/* + * write to a bitstream. only used from 1 bit to 8 bits + * this is a base routine. + */ +static int writeOutputBitStreamBody( int bwidth , unsigned char b) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return error if excess */ + if( bitstream_maxbyte <= (byteaddr+1)) return -1; + bitstream_buf[byteaddr] &= lssproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr] |= (b << mod) & lssproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr+1] &= lssproto_modifymask_second[mod][bwidth]; + bitstream_buf[byteaddr+1] |= (b>>(8-mod))& lssproto_modifymask_second[mod][bwidth]; + bitstream_bitaddr += bwidth; + return byteaddr+1; +} +/* + * write to a bitstream. used from 1 bits to 32 bits + * returns -1 if error or buffer excession + */ +static int writeOutputBitStream( int bwidth, unsigned int dat) +{ + int ret; + if( bwidth <= 0){ + return -1; + } else if( bwidth >= 1 && bwidth <= 8 ){ + if((ret=writeOutputBitStreamBody( bwidth , (unsigned char)dat))<0)return -1; + } else if( bwidth > 8 && bwidth <= 16 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth - 8 , ( unsigned char)((dat>>8)&0xff)))<0)return -1; + } else if( bwidth > 16 && bwidth <= 24 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-16,(unsigned char)((dat>>16)&0xff)))<0)return -1; + } else if( bwidth > 24 && bwidth <= 32 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>16)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-24,(unsigned char)((dat>>24)&0xff)))<0)return -1; + } else { + return -1; + } + return ret; +} +#define CHAR_SIZE 256 +#define NODE_SIZE 512 +#define BITS_LEN 9 /* 9 bit lzw compression */ +typedef struct { + unsigned char chr; + int parent; + int brother; + int child; +}NODE; +long lssproto_ringoCompressor( unsigned char *code , long codelen , + unsigned char *text , long textlen) +{ + NODE node[NODE_SIZE]; + int freeNode; + int w,k; /* used in this algo */ + int textind; /* index to text buffer */ + int i; + int position = 0; /* indicates the last byte of code buffer */ + if( textlen <= 0 ) return -1; + initOutputBitStream((char*) code,codelen); + /* fill characters ( 0 ~ 255 ) in the beggining part of + Node list */ + for(i=0; i<= CHAR_SIZE; i++){ + node[i].chr = (unsigned char)i; + node[i].brother = i + 1; + node[i].parent = 0; + node[i].child = 0; + } + node[CHAR_SIZE].brother = 0; + freeNode = CHAR_SIZE + 1; + w = text[0]; + textind = 1; + while(1){ + int rv; + if( textind >= textlen ){ + k = CHAR_SIZE; /* indicates EOF */ + } else { + k = text[textind]; + } + /* search if pattern 'wk' is registered or not. */ + rv = node[w].child; + while(1){ + if( rv <= 0 ) break; + if( node[rv].chr == k ) break; + rv = node[rv].brother; + } + if( rv > 0 ){ + /* found it */ + w = rv; + } else { + position = writeOutputBitStream( BITS_LEN ,w ); + /* return if buffer excession */ + if( position > codelen ) return -1; + /* register pattern 'wk' in the dictionary */ + if( freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = k; + } + if( textind == ( textlen + 1 ) ) break; + textind++; + } + return position; +} + +/* + * Decoder. + * return -1 if buffer excession. Notice buffer text + * is modified . + */ +long lssproto_ringoDecompressor( unsigned char *text , long textlen , + unsigned char *code , long codelen) +{ + NODE node[NODE_SIZE]; + int stack[NODE_SIZE]; + int sp; + int freeNode; + int len; + int i; + int k = 0; + int w = 0; + if( codelen <= 0 ) return -1; + initInputBitStream( (char*)code , codelen ); + for(i=0;i= freeNode ){ + stack[sp++] = k; /* exception */ + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) )return -1; + k = w; + } else { + k = rv; + } + while(k> CHAR_SIZE ){ + if( k >= (sizeof(node)/sizeof(node[0]))) return -1; + stack[sp++] = node[k].chr; + k = node[k].parent; + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + } + stack[sp++] = k; + if( sp >= ( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + /* output to text buffer from stack.*/ + while(sp){ + if( ++len > textlen ) return -1; + *text++ = stack[--sp]; + } + /* register the pattern 'wk'*/ + if( len > 1 && freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + if( w >= (sizeof(node)/sizeof(node[0])))return -1; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = rv; + } + return len; +} +#endif /* ifdef lssproto__ENCRYPT */ + +/* Convert 62-base digits to 10 digits */ +int lssproto_a62toi( char *a ) +{ + int ret = 0; + int minus ; + if( a[0] == '-' ){ + minus = -1; + a++; + } else { + minus = 1; + } + + while( *a != '\0' ) + { + ret *= 62; + if( '0' <= (*a) && (*a) <= '9' ) + ret += (*a)-'0'; + else + if( 'a' <= (*a) && (*a) <= 'z' ) + ret += (*a)-'a'+10; + else + if( 'A' <= (*a) && (*a) <= 'Z' ) + ret += (*a)-'A'+36; + else + return 0; + a++; + } + return ret * minus; +} + +/* Convert 10-base digits into 62-base digits. */ +char *lssproto_cnv10to62( int a, char *out, int outlen ) +{ + int i, j; + char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + int tmp[64]; + int src; + int minus; + int baselen = sizeof( base)-1; + if( a < 0 ){ + minus = 1; + a *= -1; + } else { + minus = 0; + } + /* special case */ + if( a < baselen) { + if( minus ){ + *(out) = '-'; + *(out+1) = base[a]; + *(out+2) = '\0'; + return (out); + } else { + *out = base[a]; + *(out+1) = '\0'; + return( out); + } + } + src = a; + for( i = 0; src >= baselen; i ++ ) { + tmp[i] = src % baselen; + src /= baselen; + } + i--; + if( minus ){ + *out = '-'; + *(out+1) = base[src]; + for( j = 2; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } else { + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } + *(out+j) = '\0'; + return( out); +} + + +/* end of generated code */ diff --git a/石器时代8.5客户端最新源代码/石器源码/system/magicitem.cpp b/石器时代8.5客户端最新源代码/石器源码/system/magicitem.cpp new file mode 100644 index 0000000..45b575f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/magicitem.cpp @@ -0,0 +1,199 @@ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/pc.h" +#include "../systeminc/shop.h" +#include "../systeminc/tool.h" +#include "../systeminc/menu.h" +#include "../systeminc/t_music.h" +#include "../systeminc/netmain.h" +#include "../systeminc/map.h" +#include "../NewProto/protocol.h" +#include "../systeminc/login.h" +#include "../other/caryIme.h" +#include "../systeminc/field.h" +#include "../wgs/tea.h" + + +#ifdef _MAGIC_ITEM_ +ACTION* MagicItemActAddr; +int MagicItemCombinData[3]; +int MagicItemPosState[4]; + +void InitMagicItemWin(char * ) +{ + + if(!(MenuToggleFlag & JOY_CTRL_I)) + MenuToggleFlag |= JOY_CTRL_I; + DeathAction(MagicItemActAddr); + MagicItemActAddr=NULL; + memset(MagicItemCombinData,0,sizeof(MagicItemPosState)); + memset(MagicItemPosState,0,sizeof(MagicItemPosState)); +} + + + +ACTION* CreateMagicItemWin() +{ +#ifdef _SA_VERSION_25 + MagicItemActAddr = MakeWindowDisp(140,157,0,0,40177,0,FALSE); +#endif + + play_se(202,320,240); + return MagicItemActAddr; +} +extern int cloasewindows; +extern ACTION* pActMenuWnd; +void ClearMagicItemWin() +{ + if(MagicItemActAddr){ + wnCloseFlag = 0; + cloasewindows = 0; + DeathAction(MagicItemActAddr); + MagicItemActAddr=NULL; + windowTypeWN = -1; + wnCloseFlag = 1; + } +} + + + +ACTION* ShowMagicItemData() +{ + int λ[3][2]={ + {105+35,44+35}, + {30+35,150+35}, + {180+35,150+35} + }; + if(MakeHitBox(100+5,30+14,170+5,100+14,106)==1){ + MagicItemPosState[0] = 1; + }else MagicItemPosState[0] = 0; + if(MakeHitBox(30,150,100,220,106)==1){ + MagicItemPosState[1] = 1; + }else MagicItemPosState[1] = 0; + if(MakeHitBox(180,150,250,220,106)==1){ + MagicItemPosState[2] = 1; + }else MagicItemPosState[2] = 0; + + if(MakeHitBox(2,2,274,362,-1)==1){ + MagicItemPosState[3]=1; + }else MagicItemPosState[3]=0; + int flg=TRUE; + int i=0; + for(;i<3;i++){ + if(MagicItemCombinData[i]>0) { + StockDispBuffer(λ[i][0],λ[i][1], DISP_PRIO_DRAG,pc.item[MagicItemCombinData[i]].graNo, 0); + if(MagicItemPosState[i]){ + char *splitPoint = pc.item[MagicItemCombinData[i]].memo; + int color = pc.item[MagicItemCombinData[i]].color; + if (pc.transmigration == 0 && pc.level < pc.item[MagicItemCombinData[i]].level) color = FONT_PAL_RED; + StockFontBuffer(20, 250, FONT_PRIO_FRONT, color, pc.item[MagicItemCombinData[i]].name, 0); + char damage_msg[256]; + sprintf_s(damage_msg, ";ö(%s)", pc.item[MagicItemCombinData[i]].damage); + StockFontBuffer(150, 250, FONT_PRIO_FRONT, color, damage_msg, 0); + char moji[256]; + int x=20; + int y=272; + flg=FALSE; + while (1){ + if (strlen(splitPoint) > 28){ + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; + if (GetStrLastByte(moji) == 3){ + moji[27] = NULL; + splitPoint += 27; + }else{ + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); y += 22; + }else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + } + } + } + if(flg){ + char *str="Ϸǿװǿʯ/ʯ¿ѡԷףʯ"; + char *splitPoint = str; + char moji[256]; + int x=20; + int y=272; + while (1){ + if (strlen(splitPoint) > 34){ + strncpy_s(moji, splitPoint, 34); + moji[34] = NULL; + if (GetStrLastByte(moji) == 3){ + moji[33] = NULL; + splitPoint += 33; + }else{ + splitPoint += 34; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 5, moji, 0); y += 22; + }else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 5, moji, 0); + break; + } + } + } + + + + int id ; + id = StockFontBuffer( 70,338, FONT_PRIO_FRONT,FONT_PAL_YELLOW, " ȷ ", 2 ); + if(id ==HitFontNo){ + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + // if(MagicItemCombinData[0]>0 && MagicItemCombinData[1]>0 && MagicItemCombinData[2]>0){ + if(MagicItemCombinData[0]>0 && MagicItemCombinData[1]>0 ){ + char ʱ[10]={0}; + sprintf_s(ʱ,"%d|%d|%d",MagicItemCombinData[0],MagicItemCombinData[1],MagicItemCombinData[2]); + extern int indexWN,idWN; + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,ʱ); + windowTypeWN = -1; + wnCloseFlag = 1; + }else{ + StockChatBufferLine("ϵͳδϳɲ!",6); + } + } + } + id = StockFontBuffer( 160,338, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " ", 2 ); + if(id ==HitFontNo){ + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + windowTypeWN = -1; + wnCloseFlag = 1; + } + } + if( CheckMenuFlag() + || ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + || cloasewindows == 1) + { + if(!pActMenuWnd && wnCloseFlag==0){ + return MagicItemActAddr; + } + for(i=0;i<3;i++){ + if(MagicItemCombinData[i]>0) { + ItemBuffer[MagicItemCombinData[i]].mixFlag=0; + MagicItemCombinData[i]=0; + } + } + extern void CloseMagicItemWin(); + CloseMagicItemWin(); + ClearMagicItemWin(); + } + return MagicItemActAddr; +} +#endif + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/main.cpp b/石器时代8.5客户端最新源代码/石器源码/system/main.cpp new file mode 100644 index 0000000..458134b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/main.cpp @@ -0,0 +1,1630 @@ +/**** SYSTEM INCLUDE ****/ + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include +#include +#include +#include +#include "../other/caryIme.h" +#include "../resource.h" +#include "../systeminc/netmain.h" +#include "../systeminc/battleMap.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/netmain.h" +#include "../systeminc/login.h" +#include "../systeminc/map.h" +#ifdef _REMAKE_20 +#include "../MMOGprotect.h" +#endif +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif +#include "../wgs/message.h" +#ifdef _STONDEBUG_ +#define _CRTDBG_MAP_ALLOC +#include +#include +#endif +#include "../systeminc/VMProtectSDK.h" +#ifdef _SAHOOK //Syu ADD Hookʽ +#include "..\Sa_Hk.h" +#include "../sahook.h" +#define UM_KEYEVENT (WM_APP + 0) +#endif +#include "../systeminc/pc.h" +#include +#include +#include +#pragma comment(lib,"netapi32.lib") +#include +#pragma comment(lib, "dbghelp.lib") + +#include +#pragma comment(lib,"psapi.lib") + + +#ifdef _NEWDEBUG_ +#include "../cguixmain.h" +#pragma comment(lib,"xcgui_115.lib") +#endif + + +#ifdef _AIDENGLU_ +Landed PcLanded; +int Ƿص = FALSE; +int Ƿصս = FALSE; +int ǷصAIģʽ = FALSE; +int Ƿص = FALSE; +int ǷصǺ = FALSE; +int Ƿص﷽ = FALSE; +int Ƿؿ = FALSE; +int Զ½Ƿ = 0; +#endif +int DISPLACEMENT_X = 160; +int DISPLACEMENT_Y = 120; +int DEF_APPSIZEX = 800; +int DEF_APPSIZEY = 600; + +int SCREEN_WIDTH_CENTER = DEF_APPSIZEX / 2; +int SCREEN_HEIGHT_CENTER = DEF_APPSIZEY / 2; + +#define REALBIN_DIR "data\\real_136.bin" // REAL.BIN?? +#define ADRNBIN_DIR "data\\adrn_136.bin" // ADRN.BIN?? +#define SPRBIN_DIR "data\\spr_115.bin" // SPR.BIN?? +#define SPRADRNBIN_DIR "data\\spradrn_115.bin" // SPRADRN.BIN?? + + +#ifdef _READ16BITBMP +#define REALTRUEBIN_DIR "data/realtrue_13.bin" +#define ADRNTRUEBIN_DIR "data/adrntrue_5.bin" +#endif +//-------------------------------------------END------------------------ +extern int ; +extern char* GB2312ToBIG5(const char* szGBString); +int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) +{ + if ( == 950){ + char [1024] = { 0 }; + char 1[1024] = { 0 }; + LCMapString(0x804, 0x4000000, lpText, strlen(lpText), , 1024); + LCMapString(0x804, 0x4000000, lpCaption, strlen(lpCaption), 1, 1024); + return MessageBox(hWnd, GB2312ToBIG5((const char *)), GB2312ToBIG5((const char *)1), uType); + } + else{ + return MessageBox(hWnd, lpText, lpCaption, uType); + } +} + +//---------------------------------------------------------------------------// +// ?? ??????e? // +//---------------------------------------------------------------------------// +HINSTANCE hInst; // ??????????e? +HWND hWnd; // ????????? +int CmdShow; // WinMain?????????????? +LPSTR CmdLine; // WinMain????????????????????? +HANDLE hMutex; // i??h??????????????? +HANDLE hCheckMutex = NULL; // ³ʽõ + +//BOOL WindowMode = TRUE; // ???????? +BOOL WindowMode = TRUE; // ?????????? +// TRUE : WindowMode +// FALSE : FullScreen +BOOL NoDelay = FALSE; // TCP_NODELAY ???????add by ringo +#ifdef _NEW_RESOMODE +//ģʽ( 0 : 640 * 480 , 1 : 320 * 240 ,2 : 640 * 480, 3 : 800 * 600 , 4 : 1024 * 768 ) +int ResoMode = 3; +#else +int ResoMode = 0; +#endif +int LowResoCmdFlag = 0; // ??T???????? + +RECT g_clientRect; +POINT g_clientPoint; +RECT g_moveRect; + + +BOOL offlineFlag = FALSE; // ???????? +char DebugKey0[256]; // ??????? +char DebugKey1[256]; // ??????? +char DebugKey2[256]; // ??????? +int g_iMallocCount = 0; + + +char realBinName[256]; +char adrnBinName[256]; +char sprBinName[256]; +char sprAdrnBinName[256]; +#ifdef _READ16BITBMP +char realtrueBinName[256]; +char adrntrueBinName[256]; +extern BOOL g_bUseAlpha; +#endif +#ifdef _TALK_WINDOW +extern int MouseCursorFlag; +#endif + +void GetSettings(); +/* ???????? */ +void AnalyzeCmdLine(void); +// ?????????v???L? +void ChangeWindowMode(void); +// ??T???@e?? +void SetResoMode(int Mode); + +// ?????????Bl +WNDCLASS wndclass; + +HANDLE hProcessSnap = NULL, hParentProcess = NULL; +DWORD dwPID; +PROCESSENTRY32 pe32; + +#ifdef _TIME_GET_TIME +extern LARGE_INTEGER tickCount; +extern LARGE_INTEGER CurrentTick; +#endif + +#ifdef _TALK_WINDOW +CTalkWindow TalkWindow; +#endif + + +char [256]; +int getMAC(char * mac) +{ + NCB ncb; + typedef struct _ASTAT_ + { + ADAPTER_STATUS adapt; + NAME_BUFFER NameBuff[30]; + }ASTAT, *PASTAT; + + ASTAT Adapter; + + typedef struct _LANA_ENUM + { + UCHAR length; + UCHAR lana[MAX_LANA]; + }LANA_ENUM; + + LANA_ENUM lana_enum; + UCHAR uRetCode; + memset(&ncb, 0, sizeof(ncb)); + memset(&lana_enum, 0, sizeof(lana_enum)); + ncb.ncb_command = NCBENUM; + ncb.ncb_buffer = (unsigned char *)&lana_enum; + ncb.ncb_length = sizeof(LANA_ENUM); + uRetCode = Netbios(&ncb); + + if (uRetCode != NRC_GOODRET) + return uRetCode; + + for (int lana = 0; lana < lana_enum.length; lana++) + { + ncb.ncb_command = NCBRESET; + ncb.ncb_lana_num = lana_enum.lana[lana]; + uRetCode = Netbios(&ncb); + if (uRetCode == NRC_GOODRET) + break; + } + + if (uRetCode != NRC_GOODRET) + return uRetCode; + + memset(&ncb, 0, sizeof(ncb)); + ncb.ncb_command = NCBASTAT; + ncb.ncb_lana_num = lana_enum.lana[0]; + strcpy((char*)ncb.ncb_callname, "*"); + ncb.ncb_buffer = (unsigned char *)&Adapter; + ncb.ncb_length = sizeof(Adapter); + uRetCode = Netbios(&ncb); + + if (uRetCode != NRC_GOODRET) + return uRetCode; + + sprintf(mac, "%02X-%02X-%02X-%02X-%02X-%02X", + Adapter.adapt.adapter_address[0], + Adapter.adapt.adapter_address[1], + Adapter.adapt.adapter_address[2], + Adapter.adapt.adapter_address[3], + Adapter.adapt.adapter_address[4], + Adapter.adapt.adapter_address[5]); + + return 0; +} + +char [512]; + +void ȡ() +{ + HANDLE m_hMapFile = OpenFileMapping( //ùڴ + FILE_MAP_READ | FILE_MAP_WRITE, + FALSE, +#ifdef _SA_VERSION_25 + "shiqies"); +#endif + + if (m_hMapFile == NULL){ + HANDLE m_hMapFile = CreateFileMapping( //һĹڴ + (HANDLE)0xFFFFFFFF, //0xFFFFFFFFʾһ̼乲Ķ + NULL, + PAGE_READWRITE, //д + 0, + 1032, //С4096 +#ifdef _SA_VERSION_25 + "shiqies"); +#endif + + char *str = (char *)MapViewOfFile( //ӳ䵽̵ĵַռ + m_hMapFile, + FILE_MAP_ALL_ACCESS, + 0, + 0, + 0); + memset(str, 0, 1032); + memset(, 0, 512); + char userName[MAX_PATH]; + DWORD size = MAX_PATH; + char mac[64]; + GetComputerName(userName, &size); + getMAC(mac); + sprintf_s(, "%s%s", mac, userName); + memcpy(str, , 512); + } + else{ + char *str = (char *)MapViewOfFile( //ӳ䵽̵ĵַռ + m_hMapFile, + FILE_MAP_ALL_ACCESS, + 0, + 0, + 0); + memcpy(, str, 512); + } +} + +BOOL ļж(char * path,char * name) +{ + char ļ·[256]; + sprintf(ļ·,"%s%s",path,name); + BOOL ret = (access(ļ·,0)==0?TRUE:FALSE); + if(ret){ + ;//MessageBox(NULL,ļ·,"ʯʱ",0); + } + return ret; +} + + +BOOL ⰴ(char *path) +{ + if(ļж(path,"QMScript") || + ļж(path,"Recorder.exe") || + ļж(path,"QMColorActionCtl.ocx") || + ļж(path,"ShieldModule.dat") || + ļж(path,"qmacro.ini") || + ļж(path,"wqm.exe") || + ļж(path,"Fairy_Ape")|| + ļж(path,"LAScriptX.dll")|| + ļж(path,"mly.dll")||ļж(path,"v5_hook.dll")||ļж(path,"v5_Log.dll")||ļж(path,"v5_Process_Manager.dll") + ){ + return TRUE; + }else{ + return FALSE; + } +} + + + +void () +{ + char szProcessName[MAX_PATH]; + HMODULE hMods[4096]; + HANDLE hProcess; + DWORD aProcesses[4096], cbNeeded, cbMNeeded; + char ·[256]; + int j; + if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; + + for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++) + { + hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, aProcesses[i]); + BOOL bret=EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbMNeeded); + if(bret){ + DWORD dwret=GetModuleFileNameEx( hProcess, hMods[0], szProcessName,sizeof(szProcessName)); + CloseHandle(hProcess); + if(dwret==0){ + break; + }else{ + int i=strlen(szProcessName); + for(i;i>=0;i--){ + if(szProcessName[i]== '\\' ){ + break; + } + } + memcpy(·,szProcessName,i+1); + ·[i+1]=0; + if(ⰴ(·)){ + ExitProcess(NULL); + } + } + } + } + return; +} + +BOOL IsContainsProcess(char* strProName, BOOL ж = 1) +{ + PROCESSENTRY32 pe32; //ṹ̵Ϣ + pe32.dwSize = sizeof(pe32); //С + + HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);// + + if (hProcessSnap == INVALID_HANDLE_VALUE) + { + //MessageBox("̿ʧ","ʾ",MB_OK); + exit(1); + } + + //п + BOOL bMore = ::Process32First(hProcessSnap, &pe32); + while (bMore) + { + if (ж == 1){ + if (strcmp(strProName, pe32.szExeFile) == 0) + { + return TRUE; //ڸỵ́򷵻TRUE + bMore = FALSE;//ֹͣѭ + } + else + { + bMore = ::Process32Next(hProcessSnap, &pe32); + } + } + else{ + if (strstr(pe32.szExeFile, strProName)) + { + return TRUE; //ڸỵ́򷵻TRUE + bMore = FALSE;//ֹͣѭ + } + else + { + bMore = ::Process32Next(hProcessSnap, &pe32); + } + } + } + //ɨβ + CloseHandle(hProcessSnap); + return FALSE; +} +DWORD __forceinline IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS ep) +{ + PCONTEXT ctx = ep->ContextRecord; + + ctx->Ebx = -1; // Not running VPC + ctx->Eip += 4; // skip past the "call VPC" opcodes + return EXCEPTION_CONTINUE_EXECUTION; // we can safely resume execution since we skipped faulty instruction +} + +// high level language friendly version of IsInsideVPC() +bool IsInsideVPC() +{ + bool rc = false; + + __try + { + _asm push ebx + _asm mov ebx, 0 // Flag + _asm mov eax, 1 + + _asm __emit 0Fh + _asm __emit 3Fh + _asm __emit 07h + _asm __emit 0Bh + + _asm test ebx, ebx + _asm setz[rc] + _asm pop ebx + } + __except (IsInsideVPC_exceptionFilter(GetExceptionInformation())) + { + } + + return rc; +} + +BOOL WARE() +{ + HKEY key; + unsigned char buffer[512]; + DWORD len; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Services\\Disk\\Enum", 0, KEY_READ, &key) == ERROR_SUCCESS){ + memset(buffer, 0, 512); + len = 512; + DWORD lpReserved = 0; + DWORD lpType = REG_SZ; + if (RegQueryValueEx(key, "0", NULL, &lpType, buffer, &len) == 0){ + extern int strncmpi(char *s1, char *s2, int len); + _strlwr_s((char *)buffer, strlen((char *)buffer) + 1); + if (strstr((char *)buffer, "virtual") || strstr((char *)buffer, "vmware") || strstr((char *)buffer, "vbox")){ + return TRUE; + } + } + RegCloseKey(key); + } + return FALSE; +} + +class A; + +void fcn(A*); + +class A +{ +public: + virtual void f() = 0; + A() { fcn(this); } +}; + +class B : A +{ + void f() { } +}; + +void fcn(A* p) +{ + p->f(); +} + +int PureVirtualFunc() +{ + B b; + int n = 0; + return 0; +} + +BOOL IsTheSelfRun(char *str) +{ + HANDLE m_hMutex = CreateMutex(NULL,FALSE, str); + if(m_hMutex) + { + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + CloseHandle(m_hMutex); + return TRUE; + } + } + return FALSE; +} + +void CreateCompatibleDEVMODE(DEVMODE* pdm, DWORD BitsPerPixel, DWORD Width, DWORD Height, DWORD Frequency) +{ + ZeroMemory(pdm, sizeof(DEVMODE)); + pdm->dmSize = sizeof(DEVMODE); + + if (BitsPerPixel) + { + pdm->dmBitsPerPel = BitsPerPixel; + pdm->dmFields |= DM_BITSPERPEL; + } + + if (Width) + { + pdm->dmPelsWidth = Width; + pdm->dmFields |= DM_PELSWIDTH; + } + + if (Height) + { + pdm->dmPelsHeight = Height; + pdm->dmFields |= DM_PELSHEIGHT; + } + + if (Frequency) + { + pdm->dmDisplayFrequency = Frequency; + pdm->dmFields |= DM_DISPLAYFREQUENCY; + } +} + + + +int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ +#ifdef _NEWDEBUG_ + + HMODULE hMod ; + hMod = GetModuleHandle("xcgui_115.dll"); + if(!hMod) + { + hMod= LoadLibrary("xcgui_115.dll"); + if(!hMod){ + exit(0); + } + } + cguixmain("cmdstrtw",123); +#endif +#ifdef _NEWFONT_ + AddFontResource("./data/font/msjh.ttf"); +#else +// AddFontResource("./data/font/msjh.ttf"); +#endif +#ifdef _CMD_MODE + extern void InitConsoleWindow(void) ; + InitConsoleWindow(); +#endif + +#ifndef SWITCH_MODE + extern int displayBpp; + HDC hDcDest = GetDC(hWnd); + displayBpp = GetDeviceCaps(hDcDest, BITSPIXEL); + ReleaseDC(hWnd, hDcDest); + if(displayBpp != 32){ + DEVMODE dm; + CreateCompatibleDEVMODE(&dm, 32, GetDeviceCaps(hDcDest, HORZRES),GetDeviceCaps(hDcDest, VERTRES), GetDeviceCaps(hDcDest, VREFRESH)); + ChangeDisplaySettings(&dm, 0); + char buf[256]; + GetModuleFileName(NULL,buf,sizeof(buf)); + STARTUPINFO StartInfo; + PROCESS_INFORMATION procStruct; + memset(&StartInfo, 0, sizeof(STARTUPINFO)); + StartInfo.cb = sizeof(STARTUPINFO); + CreateProcess(buf," OpenClient",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&StartInfo,&procStruct); + Sleep(3000); + return FALSE; + } +#endif + SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); + CreateMutex(NULL,FALSE, SA_MUTE); + +#ifdef _SA_VERSION_25 + if (_access(".\\data", 6) == -1) + _mkdir(".\\data"); + if (_access(".\\data\\chardata", 6) == -1) + _mkdir(".\\data\\chardata"); +#endif + +#ifdef _NODEBUG_ + VMProtectBegin("jiance111"); + extern void (); + (); + if ( + (IsContainsProcess("VBoxTray.exe")) || + (IsContainsProcess("SbieSvc.exe")) || + (IsContainsProcess("SbieCtrl.exe")) || + (IsContainsProcess("VBoxService.exe")) || + (IsContainsProcess("VMwareUser.exe")) || + (IsContainsProcess("VMwareTray.exe")) || + (IsContainsProcess("VMUpgradeHelper.exe"))|| + (IsContainsProcess("vmtoolsd.exe")) || + (IsContainsProcess("vmacthlp.exe")) || + IsInsideVPC()|| + IsContainsProcess("ര", 0) || + IsContainsProcess("", 0)|| + IsContainsProcess("", 0) + ){ + return FALSE; + } + if (WARE()){ + return FALSE; + } + VMProtectEnd(); +#endif + = GetACP(); + if ( == 950) + { + strcpy(, GB2312ToBIG5(DEF_APPNAME)); + } + ȡ(); + hInst = hInstance; + CmdShow = nCmdShow; + CmdLine = lpCmdLine; +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + if(==950) + hMutex = CreateMutex( NULL, TRUE, ); + else + hMutex = CreateMutex( NULL, TRUE, DEF_APPNAME ); + if(GetLastError() == ERROR_ALREADY_EXISTS){ + MessageBoxNew(hWnd,"StoneAgeѾˣ","ȷ",MB_OK | MB_ICONSTOP); + return FALSE; + } +#endif +#endif + // һ,ø³ʽжǷʯִ + hCheckMutex = CreateMutex(NULL, FALSE, "CheckForUpdate"); + +#ifdef _STONDEBUG_ + _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + +#ifdef __NEW_CLIENT + dwPID = GetCurrentProcessId(); + if( INVALID_HANDLE_VALUE == (hProcessSnap=CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL))) + return 0; + { + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if( pe32.th32ProcessID == dwPID){ + dwPID = pe32.th32ParentProcessID; + break; + } + }while( Process32Next( hProcessSnap, &pe32)); + } + } +#endif + +#ifdef _DEFENSETOOENNUM_ +#ifdef _VMP_ + VMProtectBegin("xiankai"); +#endif + FILE* tempfile=NULL; + int ds=0; + char strname[128]; + + BOOL checkclientflg=FALSE; + char *pathvar; + pathvar = getenv("TEMP"); + for(ds=0;ds<_DEFENSETOOENNUM_;ds++){ +#ifdef _SA_VERSION_25 + sprintf(strname,"%s\\Etemp%d",pathvar,ds); +#endif + tempfile = fopen(strname,"w"); + if(tempfile) fclose(tempfile); + HANDLE file_handle; + file_handle = CreateFile(strname, + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + NULL, + NULL); + if(INVALID_HANDLE_VALUE != file_handle){ + if(INVALID_FILE_SIZE != (DWORD)file_handle){ + checkclientflg=TRUE; + break; + } + } + } +// int xiangeshu=0; +// int ds=0; +// char strname[127]; +// for(ds=0;ds <_DEFENSETOOENNUM_ ;ds++){ +// sprintf(strname,"%s%d",SA_MUTE,ds); +// if(IsTheSelfRun(strname)) xiangeshu++; +// else break; +// } + if(!checkclientflg) { + // sprintf_s(strname, "Ϸ%d", _DEFENSETOOENNUM_); + sprintf_s(strname, "Ϸ2"); +#ifdef _VMP_ + MessageBoxNew(NULL,VMProtectDecryptStringA(strname), DEF_APPNAME, MB_OK | MB_ICONSTOP); +#else + MessageBoxNew(NULL,strname, DEF_APPNAME, MB_OK | MB_ICONSTOP); +#endif + return FALSE; + } +#ifdef _VMP_ + VMProtectEnd(); +#endif +#endif + + if (!hPrevInstance){ + wndclass.style = CS_BYTEALIGNCLIENT | CS_DBLCLKS; + wndclass.lpfnWndProc = WindMsgProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(SA_ICON)); + wndclass.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(SA_MOUSE1)); + wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wndclass.lpszMenuName = NULL; + if ( == 950) + wndclass.lpszClassName = ; + else + wndclass.lpszClassName = DEF_APPNAME; + if (!RegisterClass(&wndclass)){ + MessageBoxNew(NULL, "ʼӴʧܣ\nִ°װǢѯͷԱ", + "ȷ", MB_OK | MB_ICONSTOP); + return FALSE; + } + } +#ifdef _TIME_GET_TIME + QueryPerformanceFrequency(&tickCount); + tickCount.QuadPart = tickCount.QuadPart / 1000; +#endif + strcpy(realBinName, REALBIN_DIR); + strcpy(adrnBinName, ADRNBIN_DIR); + strcpy(sprBinName, SPRBIN_DIR); + strcpy(sprAdrnBinName, SPRADRNBIN_DIR); +#ifdef _READ16BITBMP + strcpy(realtrueBinName,REALTRUEBIN_DIR); + strcpy(adrntrueBinName,ADRNTRUEBIN_DIR); +#endif + AnalyzeCmdLine(); + memset(lpCmdLine, 0, strlen(lpCmdLine)); + SetResoMode(ResoMode); + ChangeWindowMode(); +#ifdef _TALK_WINDOW + TalkWindow.Init(hWnd,hInstance); + if(g_bTalkWindow) TalkWindow.Create(); +#endif + +#ifdef _NEWSHOP_ + extern void ̳dzʼ(); + ̳dzʼ(); +#endif +#ifdef _AIDENGLU_ + PcLanded. = PcLanded. = PcLanded.С = PcLanded.ģ = -1; + PcLanded.ǷԶ = PcLanded.ǷԶ = PcLanded.﷽ = PcLanded.½ʱʱ = FALSE; + memset(PcLanded.½, 0, 4 * 32); +#endif + + + GameMain(); + +#ifdef __NEW_CLIENT + CloseHandle( hProcessSnap); +#endif + +#ifdef SWITCH_MODE + extern DEVMODE g_OriginalMode; + if( g_OriginalMode.dmSize != 0){ + DEVMODE DevMode; + DevMode.dmSize = sizeof(DEVMODE); + EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &DevMode); + if( DevMode.dmPelsWidth!=g_OriginalMode.dmPelsWidth || DevMode.dmPelsHeight!=g_OriginalMode.dmPelsHeight || DevMode.dmBitsPerPel!=g_OriginalMode.dmBitsPerPel){ + g_OriginalMode.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; + ChangeDisplaySettingsEx( NULL, &g_OriginalMode, NULL, CDS_UPDATEREGISTRY, NULL); + } + } +#endif +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + QuitingInputScript(); +#endif + QuitRestore(); +#endif +#ifdef _STONDEBUG_ + if(g_iMallocCount != 0){ + char MSG[256]; + sprintf_s(MSG,"g_iMallocCount = %d",g_iMallocCount); + MessageBoxNew( NULL,MSG,"ȷ", MB_OK | MB_ICONSTOP ); + } +#endif + + ReleaseMutex(hCheckMutex); + return FALSE; +} + + + +// ??????? ***********************************************************/ +void DebugKey(char *str) +{ + char *work; + int i = 0; + + // ????????????? key0: ????? + if ((work = strstr(str, "KEY0:"))) + { + work += 5; // ???????????????? + // : ???????? + while (*work != ':'){ + DebugKey0[i] = *work++; + i++; + if (i == 255){ + i = 0; + break; + } + } + } + DebugKey0[i] = NULL; // Z?? + i = 0; + // ????????????? key1: ????? + if ((work = strstr(str, "KEY1:"))) + { + work += 5; // ???????????????? + // : ???????? + while (*work != ':'){ + DebugKey1[i] = *work++; + i++; + if (i == 255){ + i = 0; + break; + } + } + } + DebugKey1[i] = NULL; // Z?? + i = 0; + // ????????????? key1: ????? + if ((work = strstr(str, "KEY2:"))) + { + work += 5; // ???????????????? + // : ???????? + while (*work != ':'){ + DebugKey2[i] = *work++; + i++; + if (i == 255){ + i = 0; + break; + } + } + } + DebugKey2[i] = NULL; // Z?? +} + + +void AnalyzeCmdLine(void) +{ + char *addr; +#ifdef _ZHENGSHIKAIFU_ +#ifdef _VMP_ + VMProtectBegin("AnalyzeCmdLine"); +#endif + if (!(addr = strstr(CmdLine, "OpenClient"))){ + MessageBoxNew(NULL, "ʹ½Ϸ", "ȷ", MB_OK | MB_ICONSTOP); + exit(0); + } +#ifdef _VMP_ + VMProtectEnd(); +#endif +#endif + if (addr = strstr(CmdLine, "realbin:")) + sprintf_s(realBinName, "data\\real_%d.bin", atoi(addr + strlen("realbin:"))); + if (addr = strstr(CmdLine, "adrnbin:")) + sprintf_s(adrnBinName, "data\\adrn_%d.bin", atoi(addr + strlen("adrnbin:"))); + if (addr = strstr(CmdLine, "sprbin:")) + sprintf_s(sprBinName, "data\\spr_%d.bin", atoi(addr + strlen("sprbin:"))); + if (addr = strstr(CmdLine, "spradrnbin:")) + sprintf_s(sprAdrnBinName, "data\\spradrn_%d.bin", atoi(addr + strlen("spradrnbin:"))); +#ifdef _READ16BITBMP + if(addr = strstr(CmdLine,"realtrue:")) + sprintf_s(realtrueBinName,"data\\realtrue_%d.bin",atoi(addr+strlen("realtrue:"))); + if(addr = strstr(CmdLine,"adrntrue:")) + sprintf_s(adrntrueBinName, "data\\adrntrue_%d.bin", atoi(addr+strlen("adrntrue:")) ); + if(strstr(CmdLine,"usealpha")) g_bUseAlpha = TRUE; +#endif +#ifdef _REMAKE_20 +#ifdef _STONDEBUG_ + if( strstr( CmdLine, "windowmode" ) ) WindowMode = TRUE; +#endif +#else + if (strstr(CmdLine, "windowmode")) WindowMode = TRUE; +#endif + if (strstr(CmdLine, "nodelay")) + NoDelay = FALSE; + + if (strstr(CmdLine, "offline")){ + ProcNo = PROC_GAME; + offlineFlag = TRUE; + } + else{ +#ifndef _80_LOGIN_PLAY + ProcNo = PROC_ID_PASSWORD; +#else + ProcNo = PROC_80_LOGIN; +#endif + offlineFlag = FALSE; + } + if (strstr(CmdLine, "PROC_OHTA_TEST")){ + ProcNo = PROC_OHTA_TEST; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "PROC_TAKE_TEST")){ + ProcNo = PROC_TAKE_TEST; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "PROC_DWAF_TEST")){ + ProcNo = PROC_DWAF_TEST; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "PROC_BATTLE")){ + ProcNo = PROC_BATTLE; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "sprview")){ + ProcNo = PROC_SPR_VIEW; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "animview")){ + ProcNo = PROC_ANIM_VIEW; + offlineFlag = TRUE; + } + if (strstr(CmdLine, "setest")){ + ProcNo = PROC_SE_TEST; + offlineFlag = TRUE; + } + // if( strstr( CmdLine, "encountoff" ) ){ + // EncountOffFlag = TRUE; + // } + if (strstr(CmdLine, "lowreso")){ + ResoMode = 1; + } + +#ifdef _LOG_MSG + if( strstr( CmdLine, "RECVDATA:" ) ){ + char *pt = strstr( CmdLine, "RECVDATA:" )+9; + char *name; + int i; + name = debugLogFileName; + for( i = 0; i < 255; i++ ){ + if( *pt != ' ' && *pt != '\0' && *pt != '\t' ) + *name++ = *pt++; + else + break; + } + *name = '\0'; + } +#endif + DebugKey(CmdLine); +} + +void ChangeWindowMode(void) +{ + RECT clientRect; + DWORD windowStyle; + ChangeMode(WindowMode); + if (WindowMode){ + windowStyle = WS_MINIMIZEBOX | WS_SYSMENU | + //WS_THICKFRAME | + WS_CAPTION | WS_OVERLAPPED; + } + else{ + windowStyle = WS_VISIBLE | WS_POPUP; + } + SetRect(&clientRect, 0, 0, lpDraw->xSize, lpDraw->ySize); + AdjustWindowRectEx(&clientRect, windowStyle, FALSE, NULL); + if (hWnd == NULL){ + if ( == 950) + hWnd = CreateWindowEx(NULL, + , + , + windowStyle, + //CW_USEDEFAULT, + //CW_USEDEFAULT, + 0, + 0, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top, + NULL, + NULL, + hInst, + NULL); + + else + hWnd = CreateWindowEx(NULL, + DEF_APPNAME, + DEF_APPNAME, + windowStyle, + //CW_USEDEFAULT, + //CW_USEDEFAULT, + 0, + 0, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top, + NULL, + NULL, + hInst, + NULL); + } + else{ + // ??????????? + SetWindowLong(hWnd, GWL_STYLE, windowStyle); + // ????????? + ShowWindow(hWnd, CmdShow); + // ???????t?????? + SetWindowPos(hWnd, + HWND_NOTOPMOST, + 0, + 0, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top, + //SWP_SHOWWINDOW ); + SWP_FRAMECHANGED); + } + // ????????? + ShowWindow(hWnd, CmdShow); + // ??????? + UpdateWindow(hWnd); +} + +// ?????????????? **********************************************************/ +void RecoverDirectDraw(void) +{ + // DirectDraw ? + ReleaseDirectDraw(); + // ??T???@e + SetResoMode(ResoMode); + // DirectDraw ??? + if (InitDirectDraw() == FALSE){ + MessageBoxNew(hWnd, "Direct ʼʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + // ???????? WM_CLOSE ?????????? + PostMessage(hWnd, WM_CLOSE, 0, 0L); + } + // ?????????v? + //ChangeWindowMode(); + // ?????????????? + InitOffScreenSurface(); + // ??????? + if (InitPalette() == FALSE){ + MessageBoxNew(hWnd, "ɫ ʼʧܣ", "ȷ", MB_OK | MB_ICONSTOP); + PostMessage(hWnd, WM_CLOSE, 0, 0L); + } + // ?????????????????????? + if (ProcNo == PROC_BATTLE){ + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap(BattleMapNo); +#else + ReadBattleMap( BattleMapNo ); +#endif + // ??????????????? + ClearBackSurface(); + // ???????????????? +#ifdef __SKYISLAND + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#else + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ???????? + NowTime = TimeGetTime(); + } + else + if (fastDrawTile && ProcNo == PROC_GAME) + { + repairMap(); // ?????? + } + // ?????????????? + if (lpDraw->lpPALETTE != NULL){ + // ?????????? + if (WindowMode){ + // ????????????? + lpDraw->lpPALETTE->SetEntries(0, 0, 256, Palette); + } + } + // ???????V????? + mouse.state = MOUSE_NO_CRICK; + mouse.onceState = MOUSE_NO_CRICK; + // ???w????? + NowTime = TimeGetTime(); +} +//---------------------------------------------------------------------------// +// ?? ???????????? // +// ?? ?? // +//---------------------------------------------------------------------------// +BOOL SystemTask(void) +{ + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ + if (msg.message == WM_QUIT) + return FALSE; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return TRUE; +} + +//---------------------------------------------------------------------------// +// ?? ?????????????? // +// ?? HWND hWnd: ?????????? // +// UINT Message: ?????????? // +// WPARAM wParam: ??????????Kѩ? // +// LPARAM lParam: ??????????Kѩ? // +//---------------------------------------------------------------------------// +#ifdef _REMAKE_20 +extern short mouseCursorMode; +#endif +LRESULT CALLBACK WindMsgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message){ +#ifdef _REMAKE_20 + case WM_TIMER: + // 8253Ƭclock + RestoreCounter(1196); + break; +#endif + /** ??????????? *****************************************************/ + case WM_ACTIVATE: // ???????????????????????????? +#ifdef SA_25 + static BOOL bInactive = FALSE; + if( bInactive && (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)){ + SetWindowPos( hWnd, NULL, 0, -100, 0, 0, NULL); + ShowWindow( hWnd, SW_MINIMIZE); + if( lpDraw && lpDraw->lpDD2){ + lpDraw->lpDD2->SetCooperativeLevel( hWnd ,DDSCL_NORMAL); + ReleaseDirectDraw(); + } + } + if( LOWORD(wParam) == WA_INACTIVE){ + bInactive = TRUE; + cleanupNetwork(); + PostQuitMessage( 0); + } + break; +#endif + // ????????????????? + if ((wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) && lpDraw != NULL){ + + // ?????? LOST ????? + if (CheckSurfaceLost() == TRUE){ + // ?????????????? + RecoverDirectDraw(); + } + // ?????????????? + if (lpDraw->lpPALETTE != NULL){ + // ?????????? + if (WindowMode){ + // ????????????? + lpDraw->lpPALETTE->SetEntries(0, 0, 256, Palette); + } + } + } + //??????????? + //?????ϣ?? + if (keyboad_flg == TRUE){ //?????ϣ?? + // ???????????????? + if (pDInputDevice != NULL){ + // ????????????????? + if (wParam == WA_INACTIVE){ + // DInput _ + DInputActiveFlag = FALSE; + // ?????????? + for (int i = 0; i < 256; i++) di_key[i] = 0; + pDInputDevice->Unacquire(); + } + else{ + // DInput ?? + DInputActiveFlag = TRUE; + pDInputDevice->Acquire(); + } + } + } + + //????????ϣ?? + if (joy_flg == TRUE){ + // ??????????????????? + if (pDInputDevice2 == NULL) + break; + + // ????????????????? + if (wParam == WA_INACTIVE){ + // DInput _ + DInputActiveFlag = FALSE; + pDInputDevice2->Unacquire(); + } + else{ + // DInput ?? + DInputActiveFlag = TRUE; + pDInputDevice2->Acquire(); + } + } + break; + case WM_CLOSE: // ????????? + DestroyWindow(hWnd); // ??????????i?? + // WM_DESTROY ?????????? + break; + case WM_DESTROY: // ???????????? + + PostQuitMessage(0); // WM_QUIT ???????? ( ???? ) + break; +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + case WM_ACTIVATEAPP: + // еӴ,뿪Ϸ + if(!wParam){ + SendMessage(hWnd,WM_CLOSE,0,0); + } + break; +#endif +#endif + +#if 0 + case WM_PALETTECHANGED: // ??????????? + // DirectDraw?????????? + if( lpDraw == NULL ) break; + // ?????????????? + if( lpDraw->lpPALETTE == NULL ) break; + // ?????????? + //if( WindowMode ){ + // ????????????? + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); + //} + break; + //if( (HWND)wParam == hWnd ) break; + + case WM_PALETTEISCHANGING: // ??????????? + // DirectDraw?????????? + if( lpDraw == NULL ) break; + // ?????????????? + if( lpDraw->lpPALETTE == NULL ) break; + // ?????????? + //if( WindowMode ){ + // ????????????? + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); + //} + break; + + case WM_QUERYNEWPALETTE: // ???????????????????????? + + // DirectDraw?????????? + if( lpDraw == NULL ) break; + // ?????????????? + if( lpDraw->lpPALETTE == NULL ) break; + + // ?????????? + //if( WindowMode ){ + // ????????????? + lpDraw->lpPALETTE->SetEntries( 0, 0, 256, Palette ); + //} + + break; +#endif + + /** ??V?????? *****************************************************/ + + case WM_KEYDOWN: // ??V??? + + if (SurfaceBusyFlag == TRUE){ + SurfaceBusyFlag = FALSE; + RecoverDirectDraw(); + } + + switch (wParam){ + case VK_LEFT: + KeyboardLeft(); + break; + + case VK_RIGHT: + KeyboardRight(); + break; + + case VK_RETURN: + KeyboardReturn(); + break; + + case VK_BACK: + if (joy_con[1] & JOY_RSHIFT || joy_con[1] & JOY_LSHIFT){ + if (pNowStrBuffer != NULL){ + pNowStrBuffer->cnt = 0; + pNowStrBuffer->buffer[0] = NULL; + } + } + else{ + KeyboardBackSpace(); + } + + break; + + case VK_DELETE: + ClearChatBuffer(); +#ifdef _TALK_WINDOW + TalkWindow.ClearChatBuffer(); + TalkWindow.Update(); +#endif + break; + + case VK_ESCAPE: + break; + } +#ifdef _TALK_WINDOW + if(g_bTalkWindow) TalkWindow.Update(); +#endif + break; +#ifdef _REMAKE_20 + case WM_HOTKEY: + // еӴ,뿪Ϸ + SendMessage(hWnd,WM_CLOSE,0,0); + break; +#endif + case WM_SYSKEYDOWN: // ALT???????? + // ??????????? + if (SurfaceBusyFlag == TRUE){ + SurfaceBusyFlag = FALSE; + MessageBoxNew(hWnd, "SurfaceBusyFlag error!", "ȷ", MB_OK | MB_ICONSTOP); + RecoverDirectDraw(); + } + switch (wParam){ + case VK_RETURN: +#ifdef _REMAKE_20 +#ifndef _STONDEBUG_ + // Ӵģʽ뿪Ϸ + SendMessage(hWnd,WM_CLOSE,0,0); + break; +#endif +#else + // ???I?? + if (BackBufferDrawType == DRAW_BACK_PRODUCE) break; + + // DirectDraw?????????? + if (lpDraw == NULL) break; + + // ???????????? + if (WindowMode == TRUE) WindowMode = FALSE; + else WindowMode = TRUE; +#ifdef _TALK_WINDOW + if(g_bTalkWindow){ + g_bTalkWindow = FALSE; + TalkWindow.Visible(FALSE); + } +#endif + ChangeMode(WindowMode); + + // DirectDraw ? + ReleaseDirectDraw(); + + // ??T???@e + SetResoMode(ResoMode); + + // DirectDraw ??? + InitDirectDraw(); + // ?????????????? + InitOffScreenSurface(); + // ?????????v? + ChangeWindowMode(); + // u?????????? + //SendMessage( HWND_BROADCAST, WM_PAINT, NULL, NULL ); + + // ??????? + if (InitPalette() == FALSE){ + //PostMessage( hWnd, WM_CLOSE, 0, 0L ); + PostMessage(hWnd, WM_SYSKEYDOWN, VK_RETURN, 0L); + } + // ?????????????????????? + if (ProcNo == PROC_BATTLE){ + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; +#ifdef _NEW_RESOMODE + //drawMap(); + ReadBattleMap(BattleMapNo); +#else + ReadBattleMap( BattleMapNo ); +#endif + // ??????????????? + ClearBackSurface(); + // ???????????????? +#ifdef __SKYISLAND + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#else + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ???????? + NowTime = TimeGetTime(); + } + else + if (fastDrawTile && ProcNo == PROC_GAME) + { + repairMap(); // ?????? + } + // ?????????????? + if (lpDraw->lpPALETTE != NULL){ + // ?????????? + if (WindowMode){ + // ????????????? + lpDraw->lpPALETTE->SetEntries(0, 0, 256, Palette); + } + } + // ???????V????? + mouse.state = MOUSE_NO_CRICK; + mouse.onceState = MOUSE_NO_CRICK; + // ???w????? + NowTime = TimeGetTime(); + break; +#endif + break; + default: + if (wParam != VK_F10){ + return DefWindowProc(hWnd, Message, wParam, lParam); + } + break; + } + break; + case WM_CHAR: // ?V??? + // ????????? + StockStrBufferChar((char)wParam); + break; + case WM_MOUSEMOVE: // ????h???? + //SetCursor( wndclass.hCursor ); + // ????????t????? + MouseNowPoint(LOWORD(lParam), HIWORD(lParam)); +#ifndef _TALK_WINDOW + if (mouse.flag == TRUE){ + ShowCursor(FALSE); // ????????? + mouse.flag = FALSE; + } +#else + if(MouseCursorFlag == FALSE && g_iCursorCount > -1){ + while(g_iCursorCount > -1) g_iCursorCount = ShowCursor( FALSE ); + mouse.flag = FALSE; + } + else if(MouseCursorFlag == TRUE && g_iCursorCount < 0){ + while(g_iCursorCount < 0) g_iCursorCount = ShowCursor( TRUE ); + } +#endif + // ??????????? + if (SurfaceBusyFlag == TRUE){ + SurfaceBusyFlag = FALSE; + // ?????????????? + RecoverDirectDraw(); + } + break; + case WM_NCMOUSEMOVE: // ??????????????? + // ???????V????? + mouse.state = MOUSE_NO_CRICK; + mouse.onceState = MOUSE_NO_CRICK; + if (mouse.flag == FALSE){ +#ifdef _TALK_WINDOW + g_iCursorCount = ShowCursor( TRUE ); +#else + ShowCursor(TRUE); // ???????? +#endif + mouse.flag = TRUE; + } + break; + case WM_LBUTTONDOWN: // ?????(????) +#ifdef _80_LOGIN_PLAY + if (ProcNo == PROC_80_LOGIN) + break; +#endif + +#ifdef _REMAKE_20 + // ʹǷİ» + if(!IsLMouseButtonDown()) mouseCursorMode = 0; + else +#endif + // ???????????????t????? + MouseCrickLeftDownPoint(LOWORD(lParam), HIWORD(lParam)); + + break; + case WM_LBUTTONUP: // ?????(????) + // ???????????????t????? + MouseCrickLeftUpPoint(LOWORD(lParam), HIWORD(lParam)); + break; + + case WM_LBUTTONDBLCLK: // ???????? +#ifdef _80_LOGIN_PLAY + if (ProcNo == PROC_80_LOGIN) + break; +#endif + // ??????????????????t????? + MouseDblCrickLeftUpPoint(LOWORD(lParam), HIWORD(lParam)); + break; + case WM_RBUTTONDOWN: // ?????(????) +#ifdef _REMAKE_20 + // ʹǷİ» + if(!IsRMouseButtonDown()) mouseCursorMode = 0; + else +#endif + // ???????????????t????? + MouseCrickRightDownPoint(LOWORD(lParam), HIWORD(lParam)); + break; + case WM_RBUTTONUP: // ?????(????) + // ???????????????t????? + MouseCrickRightUpPoint(LOWORD(lParam), HIWORD(lParam)); + break; + case WM_RBUTTONDBLCLK: // ???????? + // ??????????????????t????? + MouseDblCrickRightUpPoint(LOWORD(lParam), HIWORD(lParam)); + break; + case WM_MBUTTONDOWN: // ?????(????) + break; + case WM_MOVE: + { + g_clientPoint.x = g_clientPoint.y = 0; + GetClientRect(hWnd, &g_clientRect); + ClientToScreen(hWnd, &g_clientPoint); + OffsetRect(&g_clientRect, g_clientPoint.x, g_clientPoint.y); + SetRect(&g_moveRect, 0, 0, lpDraw->xSize, lpDraw->ySize); +#ifdef _TALK_WINDOW + if(g_bTalkWindow) SendMessage(TalkWindow.GetTalkWindowWND(),WM_MOVE,0,0); +#endif + } + break; + + //ԶHook MsgType +#ifdef _SAHOOK //Syu ADD Hookʽ + case UM_KEYEVENT: + TCHAR ac[2]; + BYTE bKeyState[256]; + GetKeyboardState(bKeyState); + if (ToAscii(wParam, (HIWORD(lParam) & (0x00FF | KF_UP)), bKeyState, (PWORD) ac, 0) == 1) + { + extern int HOOK_PASSWD_NUM; + if((HOOK_PASSWD_NUM < 12) && (wParam != 13) && (wParam != 9) && (wParam != 27)) + HOOK_PASSWD_NUM++; + } + if (wParam == 8 ) + if(HOOK_PASSWD_NUM >0 ) + HOOK_PASSWD_NUM--; +#endif + default: + if (ImeMessage(Message, wParam, lParam)) + return 0; + return DefWindowProc(hWnd, Message, wParam, lParam); + } + + + return 0; +} + +void SetResoMode(int Mode){ + ResoMode = Mode; + lpDraw = (DIRECT_DRAW *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (DWORD)sizeof(DIRECT_DRAW)); + if (lpDraw == NULL){ + MessageBoxNew(hWnd, "HeapAlloc Error ( DIRECT_DRAW )", "ȷ", MB_OK | MB_ICONSTOP); + return; + } + switch (Mode){ + case 0: + //460*480 + lpDraw->xSize = 640; + lpDraw->ySize = 480; + SurfaceSizeX = 64; + SurfaceSizeY = 48; + DISPLACEMENT_X = 0; + DISPLACEMENT_Y = 0; + break; + case 1: + //320*240 + lpDraw->xSize = 320; + lpDraw->ySize = 240; + SurfaceSizeX = 64; + SurfaceSizeY = 48; + DISPLACEMENT_X = 0; + DISPLACEMENT_Y = 0; + break; + case 2: + //ɱ + lpDraw->xSize = 640; + lpDraw->ySize = 480; + SurfaceSizeX = 64; + SurfaceSizeY = 48; + DISPLACEMENT_X = 0; + DISPLACEMENT_Y = 0; + break; +#ifdef _NEW_RESOMODE + case 3: + lpDraw->xSize = 800; + lpDraw->ySize = 600; + SurfaceSizeX = 64; + SurfaceSizeY = 48; + DISPLACEMENT_X = 160; + DISPLACEMENT_Y = 120; + break; + case 4: + lpDraw->xSize = 1024; + lpDraw->ySize = 768; + SurfaceSizeX = 64; + SurfaceSizeY = 48; + DISPLACEMENT_X = 384; + DISPLACEMENT_Y = 288; + break; +#endif + } + + DEF_APPSIZEX = lpDraw->xSize; + DEF_APPSIZEY = lpDraw->ySize; + SCREEN_WIDTH_CENTER = DEF_APPSIZEX / 2; + SCREEN_HEIGHT_CENTER = DEF_APPSIZEY / 2; + viewOffsetX = SCREEN_WIDTH_CENTER; + viewOffsetY = SCREEN_HEIGHT_CENTER; + PostMessage(hWnd, WM_MOVE, 0, 0L); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/map.cpp b/石器时代8.5客户端最新源代码/石器源码/system/map.cpp new file mode 100644 index 0000000..eccbf8a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/map.cpp @@ -0,0 +1,6156 @@ +#include +#include +#include +#include +#include + +#include "../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/map.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/pc.h" +#include"../systeminc/netproc.h" +#include"../systeminc/character.h" +#include"../systeminc/loadrealbin.h" +#include"../systeminc/loadsprbin.h" +#include"../systeminc/netmain.h" +#include"../systeminc/lssproto_cli.h" +#include"../systeminc/battleProc.h" +#include"../systeminc/t_music.h" +#include"../systeminc/field.h" +#include"../systeminc/login.h" +#include"../systeminc/menu.h" +#include"../systeminc/battleMenu.h" +#include "../systeminc/handletime.h" +#include "../systeminc/savedata.h" +#include "../systeminc/tool.h" + +// ?????L???(1 ... ?L?) +const short fastDrawTile = 1; + +short fastDrawTileFlag = 1; +int amountXFastDraw = 0, amountYFastDraw = 0; +int nowXFastDraw, nowYFastDraw; +int baseXFastDraw, baseYFastDraw; +int amountXFastDraw2 = 0, amountYFastDraw2 = 0; +int nowXFastDraw2, nowYFastDraw2; +int baseXFastDraw2, baseYFastDraw2; +#define SEARCH_AREA 11 // ?????????d??????????? + +enum +{ + MOUSE_CURSOR_MODE_NORMAL, + MOUSE_CURSOR_MODE_MOVE +}; + +// ??????? +char nowFloorName[FLOOR_NAME_LEN+1]; +int nowFloor; +int nowFloorGxSize, nowFloorGySize; +int nowGx, nowGy; +float nowX = (float)nowGx*GRID_SIZE, nowY = (float)nowGy * GRID_SIZE; +float nowVx, nowVy, nowSpdRate; +int nextGx, nextGy; +int oldGx = -1, oldGy = -1; +int oldNextGx = -1, oldNextGy = -1; +int mouseMapGx, mouseMapGy; +int mouseMapX, mouseMapY; +#define MOVE_MODE_CHANGE_TIME 1000 +short mouseCursorMode = MOUSE_CURSOR_MODE_NORMAL; +int mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2; +int mapAreaWidth, mapAreaHeight; + +unsigned short tile[MAP_X_SIZE * MAP_Y_SIZE]; // ??????? +unsigned short parts[MAP_X_SIZE * MAP_Y_SIZE]; // ??????? +unsigned short event[MAP_X_SIZE * MAP_Y_SIZE]; // ???? +unsigned short hitMap[MAP_X_SIZE * MAP_Y_SIZE]; // ??????Re + +// ??????????hw???? +BOOL mapEmptyFlag; +short mapEmptyDir; +int mapEmptyGx, mapEmptyGy; +short getMapAreaX1[2], getMapAreaY1[2], getMapAreaX2[2], getMapAreaY2[2]; +short getMapAreaCnt; +unsigned int mapEmptyStartTime; +// ????????? +BOOL floorChangeFlag = FALSE; +// ??????????? +BOOL loginFlag; +// ?????????2??????????? +BOOL warpEffectFlag = FALSE; +BOOL warpEffectStart = FALSE; // ????????? +BOOL warpEffectOk = FALSE; // ?????????ϣ +// ??????? +float viewPointX; +float viewPointY; +int viewOffsetX = SCREEN_WIDTH_CENTER; +int viewOffsetY = SCREEN_HEIGHT_CENTER; +#ifdef _MOVE_SCREEN +int iScreenMoveX = 0, iScreenMoveY = 0; +#endif + +// ?h?? +#define MOVE_CLICK_WAIT_TIME 250 // ?? +short moveAddTbl[8][2] = +{ + { -1, 1 }, // 0 + { -1, 0 }, // 1 + { -1, -1 }, // 2 + { 0, -1 }, // 3 + { 1, -1 }, // 4 + { 1, 0 }, // 5 + { 1, 1 }, // 6 + { 0, 1 } // 7 +}; +BOOL moveStackFlag = FALSE; +int moveStackGx, moveStackGy; +#define MOVE_MAX 100 +short moveRoute[MOVE_MAX]; +short moveRouteCnt = 0; +short moveRouteGx[MOVE_MAX]; +short moveRouteGy[MOVE_MAX]; +char moveRouteDir[MOVE_MAX]; + +#define MOVE_MAX2 2 // ???????h????k +short moveRouteCnt2 = 0; +short moveRoute2[MOVE_MAX2]; + +short moveLastDir = -1; + +// ?????? +BOOL mouseLeftCrick = FALSE; +BOOL mouseLeftOn = FALSE; +BOOL mouseRightCrick = FALSE; +BOOL mouseRightOn = FALSE; +#ifdef _MOUSE_DBL_CLICK +BOOL mouseDblRightOn = FALSE; +#endif +unsigned int mouseLeftPushTime; +unsigned int beforeMouseLeftPushTime; + +// ?????????I???e? + +enum +{ + CHAR_PARTS_PRIO_TYPE_CHAR, + CHAR_PARTS_PRIO_TYPE_PARTS, + CHAR_PARTS_PRIO_TYPE_ANI +}; + +typedef struct TAG_CHAR_PARTS_PRIORITY +{ + unsigned int graNo; + int x, y; + int dx, dy; + int depth; + float mx, my; + short type; + TAG_CHAR_PARTS_PRIORITY *pre; + TAG_CHAR_PARTS_PRIORITY *next; +#ifdef _SFUMATO + int sfumato; +#endif +} CHAR_PARTS_PRIORITY; + +#define MAX_CHAR_PRIO_BUF 2048 +CHAR_PARTS_PRIORITY charPrioBufTop; +CHAR_PARTS_PRIORITY charPrioBuf[MAX_CHAR_PRIO_BUF]; +int charPrioCnt; + +// ????????? +short nowEncountPercentage; // ??????? +short nowEncountExtra; // ???????? +short minEncountPercentage; // ???????? +short maxEncountPercentage; // ???????? +short sendEnFlag; // EN??????????? +short encountNowFlag; // ???????? + +// ??????? +int eventId = 0; // ??????ID +short eventWarpSendFlag; // ??????????? +short eventWarpSendId; // ??????????ID +short eventEnemySendFlag; // ?e?????????????? +short eventEnemySendId; // ?e?????????????ID +short eventEnemyFlag; // ?e??????????? +short etcEventFlag = 0; +short vsLookFlag; // ?P???? + +// ????????? +#define AUTO_MAPPING_W 54 +#define AUTO_MAPPING_H 54 +BOOL autoMappingInitFlag = TRUE; +unsigned char autoMappingBuf[AUTO_MAPPING_H][AUTO_MAPPING_W]; +/* +#define AUTO_MAPPING_SEE_W 30 +#define AUTO_MAPPING_SEE_H 30 +unsigned int readMapAfterFrame = 10000; // ??????????????? +unsigned short autoMapSeeFlagBuf[AUTO_MAPPING_SEE_H*AUTO_MAPPING_SEE_W]; +BOOL autoMapSeeFlag = FALSE; +int autoMapSeeFloor; +int autoMapSeeGx, autoMapSeeGy; +*/ + +// ???????? +// 1 ... ?????? +// 0 ... G +int transmigrationEffectFlag; + +// ??????????????????????? +// 1 ... ?????? +// 0 ... ? +int transEffectPaletteStatus; + +// ??????????????????? +// ??????????r?????? +unsigned int transEffectPaletteAfterWaitTime; + + +// ?h?? +void onceMoveProc(void); +void partyMoveProc(void); +void getPartyTbl(void); +#ifdef _MOVE_SCREEN +void MoveScreenProc(void); +#endif + +// ?????????? +//#define MAP_CACHE_PROC +#ifdef MAP_CACHE_PROC + +#define MAX_MAP_CACHE_SIZE 3 // ???????????? +#define MAP_CACHE_X_SIZE 800 // ????????? +#define MAP_CACHE_Y_SIZE 1200 // ????????? +#define MAP_CACHE_X_BYTE ((MAP_CACHE_X_SIZE+7)/8) +#define MAP_CACHE_Y_BYTE MAP_CACHE_Y_SIZE +int mapCacheFloorNo[MAX_MAP_CACHE_SIZE]; +int mapCacheFloorGxSize[MAX_MAP_CACHE_SIZE]; +int mapCacheFloorGySize[MAX_MAP_CACHE_SIZE]; +unsigned char mapCacheFlag[MAX_MAP_CACHE_SIZE][MAP_CACHE_X_BYTE*MAP_CACHE_Y_BYTE]; +int mapCacheUse; +unsigned int mapCacheLastTime[MAX_MAP_CACHE_SIZE]; + +void initMapCache(void); +BOOL checkMapCache(int, int, short *, int, int, int, int); +void clearMapCacheFlag(int); +BOOL checkMapCacheFlag(int, int, int, int, int, int, int); +BOOL checkMapCacheEvent(int, int, int, int); +#endif +BOOL readMap(int, int, int, int, int, unsigned short *, unsigned short *, unsigned short *); +void readHitMap(int, int, int, int, unsigned short *, unsigned short *, unsigned short *, unsigned short *); +void getRouteMap(void); +void shiftRouteMap(void); +void shiftRouteMap2(void); +int getDirData(int, int, int, int); +void checkAreaLimit(short *, short *, short *, short *); +void turnAround(void); +void turnAround2(int); +BOOL checkPrioPartsVsChar(CHAR_PARTS_PRIORITY *, CHAR_PARTS_PRIORITY *); +void insertCharPartsPrio(CHAR_PARTS_PRIORITY *, CHAR_PARTS_PRIORITY *); +void addCharPartsPrio(CHAR_PARTS_PRIORITY *, CHAR_PARTS_PRIORITY *); +void delCharPartsPrio(CHAR_PARTS_PRIORITY *); +BOOL createAutoMap(int, int, int); + +/////////////////////////////////////////////////////////////////////////// +// ???????? +void initMap(void) +{ + + if (offlineFlag) + { + setMap(400, 20, 20); + nowFloorGxSize = 100; + nowFloorGySize = 100; + } + else + { + nowFloor = 0; + nowFloorGxSize = 0; + nowFloorGySize = 0; + nowGx = 0; + nowGy = 0; + nowX = 0; + nowY = 0; + nextGx = 0; + nextGy = 0; + oldGx = 0, oldGy = 0; + oldNextGx = 0, oldNextGy = 0; + + loginFlag = TRUE; + } + + mapAreaX1 = nowGx+MAP_TILE_GRID_X1; + mapAreaY1 = nowGy+MAP_TILE_GRID_Y1; + mapAreaX2 = nowGx+MAP_TILE_GRID_X2; + mapAreaY2 = nowGy+MAP_TILE_GRID_Y2; + + if (mapAreaX1 < 0) + mapAreaX1 = 0; + if (mapAreaY1 < 0) + mapAreaY1 = 0; + if (mapAreaX2 > nowFloorGxSize) + mapAreaX2 = nowFloorGxSize; + if (mapAreaY2 > nowFloorGySize) + mapAreaY2 = nowFloorGySize; + + mapAreaWidth = mapAreaX2 - mapAreaX1; + mapAreaHeight = mapAreaY2 - mapAreaY1; + nowVx = 0; + nowVy = 0; + nowSpdRate = 1; + moveRouteCnt = 0; + moveRouteCnt2 = 0; + moveStackFlag = FALSE; + mapEmptyFlag = FALSE; + mouseCursorMode = MOUSE_CURSOR_MODE_NORMAL; + nowEncountPercentage = 0; + nowEncountExtra = 0; + sendEnFlag = 0; + encountNowFlag = 0; + eventWarpSendFlag = 0; + eventEnemySendFlag = 0; + eventEnemyFlag = 0; + etcEventFlag = 0; + mouseLeftPushTime = 0; + beforeMouseLeftPushTime = 0; + warpEffectFlag = FALSE; + warpEffectStart = FALSE; + warpEffectOk = FALSE; +// autoMapSeeFlag = FALSE; + eventWarpSendId = -1; + eventEnemySendId = -1; + moveLastDir = -1; + amountXFastDraw = 0; + amountYFastDraw = 0; + nowXFastDraw = 0; + nowYFastDraw = 0; + baseXFastDraw = 0; + baseYFastDraw = 0; + amountXFastDraw2 = 0; + amountYFastDraw2 = 0; + nowXFastDraw2 = 0; + nowYFastDraw2 = 0; + baseXFastDraw2 = 0; + baseYFastDraw2 = 0; + vsLookFlag = 0; + fastDrawTileFlag = 1; + transmigrationEffectFlag = 0; + transEffectPaletteStatus = 0; + transEffectPaletteAfterWaitTime = 0; +#ifdef MAP_CACHE_PROC + initMapCache(); +#endif +} + +/////////////////////////////////////////////////////////////////////////// +// ????????? +void resetMap(void) +{ + // ?h????hI???????? + nowGx = (int)(nowX / GRID_SIZE); + nowGy = (int)(nowY / GRID_SIZE); + nextGx = nowGx; + nextGy = nowGy; + nowX = (float)nowGx * GRID_SIZE; + nowY = (float)nowGy * GRID_SIZE; + oldGx = -1; + oldGy = -1; + oldNextGx = -1; + oldNextGy = -1; + mapAreaX1 = nowGx + MAP_TILE_GRID_X1; + mapAreaY1 = nowGy + MAP_TILE_GRID_Y1; + mapAreaX2 = nowGx + MAP_TILE_GRID_X2; + mapAreaY2 = nowGy + MAP_TILE_GRID_Y2; + + if (mapAreaX1 < 0) + mapAreaX1 = 0; + if (mapAreaY1 < 0) + mapAreaY1 = 0; + if (mapAreaX2 > nowFloorGxSize) + mapAreaX2 = nowFloorGxSize; + if (mapAreaY2 > nowFloorGySize) + mapAreaY2 = nowFloorGySize; + + mapAreaWidth = mapAreaX2 - mapAreaX1; + mapAreaHeight = mapAreaY2 - mapAreaY1; + nowVx = 0; + nowVy = 0; + nowSpdRate = 1; + viewPointX = nowX; + viewPointY = nowY; + moveRouteCnt = 0; + moveRouteCnt2 = 0; + moveStackFlag = FALSE; + mouseCursorMode = MOUSE_CURSOR_MODE_NORMAL; + mouseLeftPushTime = 0; + beforeMouseLeftPushTime = 0; +// autoMapSeeFlag = FALSE; +} + +/////////////////////////////////////////////////////////////////////////// +// ???????????????????????t?? +void createMap(int fl, int maxx, int maxy) +{ + FILE *fp; + char floorname[255]; + int i = 0, j, k, ox, oy; + short l = 0; + + if (fl == 0) + return; + + sprintf(floorname, "map\\%d.dat", fl); + if ((fp = fopen(floorname, "rb")) == NULL) + { + // ??????????? + _mkdir("map"); + if ((fp = fopen(floorname, "wb")) == NULL) + return; + fseek(fp, 0, SEEK_SET); + fwrite(&maxx, sizeof(int), 1, fp); + fwrite(&maxy, sizeof(int), 1, fp); + for (i = 0; i < 3; i++) + { + for (j = 0; j < maxx; j++) + { + for (k=0; k < maxy; k++) + { + fwrite(&l, sizeof(short), 1, fp); + } + } + } + fclose(fp); + } + else + { + fread(&ox, sizeof(int), 1, fp); + fread(&oy, sizeof(int), 1, fp); + if (maxx != ox || maxy != oy) + { + fclose(fp); + // ?????????V??????????? + if ((fp = fopen(floorname, "wb")) == NULL) + return; + fwrite(&maxx, sizeof(int), 1, fp); + fwrite(&maxy, sizeof(int), 1, fp); + for (i = 0; i < 3; i++) + { + for (j = 0; j < maxx; j++) + { + for (k = 0; k < maxy; k++) + { + fwrite(&l, sizeof(short), 1, fp); + } + } + } + } + fclose (fp); + } +} + +// ???????????????????????? +void setEventMemory(int x, int y, unsigned short ev) +{ + event[(y - mapAreaY1) * mapAreaWidth + (x - mapAreaX1)] = ev; +} + +// ??????????? +// +// ?????(x1,y1)-(x2,y2)?d????????????? +// +// tile, parts, event ?_?????B?????? +// +BOOL writeMap(int floor, int x1, int y1, int x2, int y2, unsigned short *tile , unsigned short *parts, unsigned short *event) +{ + FILE *fp; + char filename[255]; + int fWidth, fHeight, fOffset, mWidth, width, height, fx, fy, mx, my, len, len2, i, j; + + // ???????? + sprintf_s(filename, "map\\%d.dat", floor); + + // ???????? + if ((fp = fopen(filename, "rb+")) == NULL) + { + _mkdir("map"); + if ((fp = fopen(filename, "rb+")) == NULL) + return FALSE; + } + fseek(fp, 0, SEEK_SET); + fread(&fWidth, sizeof(int), 1, fp); + fread(&fHeight, sizeof(int), 1, fp); + mWidth = x2 - x1; + width = mWidth; + height = y2 - y1; + mx = 0; + fx = x1; + if (x1 < 0) + { + width += x1; + fx = 0; + mx -= x1; + } + if (x2 > fWidth) + width -= (x2 - fWidth); + my = 0; + fy = y1; + if (y1 < 0) + { + height += y1; + fy = 0; + my -= y1; + } + if (y2 > fHeight) + height -= (y2 - fHeight); + fOffset = sizeof(int) * 2; + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fwrite(&tile[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fwrite(&parts[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + // ????????????? + for (j = 0; j < width; j++) + { + event[len2+j] |= (MAP_SEE_FLAG | MAP_READ_FLAG); + if (nowFloor == floor && (mapAreaX1 <= x1 + j && x1 + j < mapAreaX2 && mapAreaY1 <= y1 + i && y1 + i < mapAreaY2)) + // ???????????????????????? + setEventMemory(x1 + j, y1 + i, event[len2 + j]); + } + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fwrite(&event[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fclose (fp); + + return TRUE; +} + +// ?????????? +// +// ?????(x1,y1)-(x2,y2)?d???????????? +// +BOOL readMap(int floor, int x1, int y1, int x2, int y2, unsigned short *tile, unsigned short *parts, unsigned short *event) +{ + FILE *fp; + char filename[255]; +#ifdef _FIX_DEL_MAP // WON ҳͼ + char list[10]; +#endif + int fWidth, fHeight, fOffset, mWidth, width, height, fx, fy, mx, my, len, len2, i; + //printf("floor=%d x1=%d y1=%d x2=%d y2=%d\n",floor,x1,y1,x2,y2); + // ???????? + sprintf_s(filename, "map\\%d.dat", floor); + + // ???????? + if ((fp = fopen(filename, "rb")) == NULL) + { +#ifdef _FIX_DEL_MAP //andy_add + memset(tile, 193, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + //memset(parts, 193, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); +#else + _mkdir("map"); + // ????????? + fp = fopen(filename, "wb"); + fclose(fp); +#endif + // ??????????T???? + if ((fp = fopen(filename, "rb")) == NULL) + return FALSE; + } + +#ifdef _FIX_DEL_MAP // WON ҳͼ + fseek(fp, 0, SEEK_SET); + if (!fread(list, sizeof(char), 1, fp)) { // ҳͼͼ + //andy_add + memset(tile, 193, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + //memset(parts, 193, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + fclose(fp); + //lssproto_DM_send(sockfd); + return TRUE; + } +#endif + //printf("MAP_X_SIZE=%d MAP_Y_SIZE=%d\n",MAP_X_SIZE,MAP_Y_SIZE); + memset(tile, 0, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + memset(parts, 0, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + memset(event, 0, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + fseek(fp, 0, SEEK_SET); + fread(&fWidth, sizeof(int), 1, fp); + fread(&fHeight, sizeof(int), 1, fp); + //printf("fWidth=%d fHeight=%d\n",fWidth,fHeight); + mWidth = x2 - x1; + width = mWidth; + height = y2 - y1; + mx = 0; + fx = x1; + + //printf("mWidth=%d width=%d height=%d fx=%d\n",mWidth,width,height,fx); + if (x1 < 0) + { + width += x1; + fx = 0; + mx -= x1; + } + if (x2 > fWidth) + width -= (x2 - fWidth); + my = 0; + fy = y1; + if (y1 < 0) + { + height += y1; + fy = 0; + my -= y1; + } + if (y2 > fHeight) + height -= (y2 - fHeight); + + fOffset = sizeof(int) * 2; + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&tile[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&parts[len2], sizeof(short) * width, 1, fp);//aaaaaaaaaaaaa + len += fWidth; + len2 += mWidth; + } + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&event[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fclose (fp); + + return TRUE; +} +// +// ????t@e +// +void setMap(int floor, int gx, int gy) +{ + nowFloor = floor; + setWarpMap(gx, gy); +} +// +// ????t???? +// +void setWarpMap(int gx, int gy) +{ + nowGx = gx; + nowGy = gy; + nowX = (float)nowGx * GRID_SIZE; + nowY = (float)nowGy * GRID_SIZE; + nextGx = nowGx; + nextGy = nowGy; + nowVx = 0; + nowVy = 0; + nowSpdRate = 1; + oldGx = -1; + oldGy = -1; + oldNextGx = -1; + oldNextGy = -1; + viewPointX = nowX; + viewPointY = nowY; + wnCloseFlag = 1; +#ifdef _AniCrossFrame // Syu ADD ι + extern void crossAniRelease(); + crossAniRelease(); +#endif +#ifdef _SURFACE_ANIM //ROG ADD ̬ + extern void ReleaseSpecAnim (); + ReleaseSpecAnim(); +#endif +} + +#ifdef _NEWDRAWBATTLEMAP // (ɿ) Syu ADD ԶBattleMap +//ROG ADD Զ +typedef struct{ + int x; + int y; + float mx; + float my; + int bmpNO; +}PARTS; + +typedef int CMPFUNC(const void * , const void *); +int sort_parts(PARTS *ptc, PARTS *ptp) +{ + S2 w, h; + if (ptc->mx > ptp->mx && ptc->my < ptp->my) + return 1; + else + { + realGetHitPoints(ptp->bmpNO, &w, &h); + if (ptc->x > ptp->x) + { + if (ptp->y - (w - 1) * SURFACE_HEIGHT / 2 <= ptc->y) + return -1; + } + else if (ptc->x < ptp->x) + { + if (ptp->y - (h - 1) * SURFACE_HEIGHT / 2 <= ptc->y) + return -1; + } + else + { + if (ptp->y <= ptc->y) + return -1; + } + } + return 1; + +} +//ROG ADD end +void ddrawBattleMap(void) +{ + int i, j , count = 0, x, y, tx, ty, partsCnt = 0, TilesCnt = 0, ti, tj; + float dx, dy; + U4 bmpNo; + PARTS tempParts[MAX_CHAR_PRIO_BUF / 2]; + PARTS tempTiles[MAX_CHAR_PRIO_BUF / 2]; + + draw_map_bgm_flg = 0; + // ????????t?????????????? + if (nowGx != oldGx || nowGy != oldGy) + { + if (readMap(nowFloor, mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0])) + { + // hitMap[]????Re????@e + readHitMap(mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0], &hitMap[0]); + if (mapEmptyFlag) + { + if (!checkEmptyMap(mapEmptyDir)) + { + mapEmptyFlag = FALSE; + autoMappingInitFlag = TRUE; // ????????? + } + } + else + autoMappingInitFlag = TRUE; // ????????? +// readMapAfterFrame = 0; // ???????????????????????? + } + else + return; + } + camMapToGamen(0.0, 0.0, &dx, &dy); + baseXFastDraw = (int)(dx + .5); + baseYFastDraw = (int)(dy + .5); + //??????????????? + if (ResoMode == 1) + { + nowXFastDraw = (int)(dx / 2 + .5); + nowYFastDraw = (int)(dy / 2 + .5); + } + else + { + nowXFastDraw = baseXFastDraw; + nowYFastDraw = baseYFastDraw; + } + nowXFastDraw2 = baseXFastDraw; + nowYFastDraw2 = baseYFastDraw; + amountXFastDraw = 0; + amountYFastDraw = 0; + // 1 5 12 16 ... + tx = nowXFastDraw2 + (mapAreaX1 + mapAreaY2 - 1) * SURFACE_WIDTH / 2; + ty = nowYFastDraw2 + (-mapAreaX1 + mapAreaY2 - 1) * SURFACE_HEIGHT / 2; + ti = mapAreaHeight - 1; + tj = 0; + while (ti >= 0) + { + i = ti; + j = tj; + x = tx; + y = ty; + while (i >= 0 && j >= 0) + { + // ??? + if (tile[i * mapAreaWidth+j] > CG_INVISIBLE || parts[i * mapAreaWidth+j] > CG_INVISIBLE) + { + // ??????? + if (x >= (-SURFACE_WIDTH >> 1) && x < DEF_APPSIZEX + (SURFACE_WIDTH >> 1) && + y >= (-SURFACE_HEIGHT >> 1) && y < DEF_APPSIZEY + (SURFACE_HEIGHT >> 1)) + { +//ROG ADD ʾ + if (parts[i * mapAreaWidth+j] > CG_INVISIBLE) + { + realGetNo(parts[i * mapAreaWidth + j], &bmpNo); + tempParts[partsCnt].bmpNO = parts[i * mapAreaWidth + j]; + tempParts[partsCnt].x = x; + tempParts[partsCnt].y = y; + tempParts[partsCnt].mx = (float)(mapAreaX1 + j) * GRID_SIZE; + tempParts[partsCnt].my = (float)(mapAreaY1 + i) * GRID_SIZE; + partsCnt++; + } + tempTiles[TilesCnt].x = x; + tempTiles[TilesCnt].y = y; + tempTiles[TilesCnt].bmpNO = tile[i * mapAreaWidth + j]; + TilesCnt++; + //StockDispBuffer(x, y, DISP_PRIO_TILE, tile[i*mapAreaWidth+j], 0); + // count++; + } + } +//ROG ADD end } + i--; + j--; + x -= SURFACE_WIDTH; + } + if (tj < mapAreaWidth - 1) + { + tj++; + tx += SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + else + { + ti--; + tx -= SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + } +//ROG ADD ʾ + if (partsCnt > 0) + { + qsort(tempParts, partsCnt, sizeof(PARTS), (CMPFUNC*)sort_parts); + for (i = 0; i < partsCnt; i++) + StockDispBuffer(tempParts[i].x , tempParts[i].y, DISP_PRIO_TILE, tempParts[i].bmpNO, 0); + } + SortDispBuffer(); + for (i = 0; i < TilesCnt; i++) + StockDispBuffer(tempTiles[i].x, tempTiles[i].y, DISP_PRIO_TILE, tempTiles[i].bmpNO, 0); + SortDispBuffer(); +//ROG ADD end +// stockCharParts(); + oldGx = nowGx; + oldGy = nowGy; + if (fMapBgm >= 40 && fMapBgm <= 53 && map_bgm_no == 2) + { + play_map_bgm(fMapBgm); + draw_map_bgm_flg = 1; + fMapBgm = 0; + } +} +#endif + +void drawMap(void) +{ + int i, j, x, y, tx, ty, rainFlag = 0, snowFlag = 0, tryFlag = 0;; + S2 xx, yy, ww, hh; + float dx, dy; + U4 bmpNo; + + draw_map_bgm_flg = 0; +// readMapAfterFrame++; + // ????????t?????????????? + if (nowGx != oldGx || nowGy != oldGy) + { + if (readMap(nowFloor, mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0])) + { + // hitMap[]????Re????@e + readHitMap(mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0], &hitMap[0]); + if (mapEmptyFlag) + { + if (!checkEmptyMap(mapEmptyDir)) + { + mapEmptyFlag = FALSE; + autoMappingInitFlag = TRUE; // ????????? + } + } + else + autoMappingInitFlag = TRUE; // ????????? +// readMapAfterFrame = 0; // ???????????????????????? + } + else + return; + } + camMapToGamen(0.0, 0.0, &dx, &dy); + baseXFastDraw = (int)(dx + .5); + baseYFastDraw = (int)(dy + .5); + //??????????????? + if (ResoMode == 1) + { + nowXFastDraw = (int)(dx / 2 + .5); + nowYFastDraw = (int)(dy / 2 + .5); + } + else + { + nowXFastDraw = baseXFastDraw; + nowYFastDraw = baseYFastDraw; + } + nowXFastDraw2 = baseXFastDraw; + nowYFastDraw2 = baseYFastDraw; + amountXFastDraw = 0; + amountYFastDraw = 0; + // 1 5 12 16 ... + tx = nowXFastDraw2 + (mapAreaX1 + mapAreaY2 - 1) * SURFACE_WIDTH / 2; + ty = nowYFastDraw2 + (-mapAreaX1 + mapAreaY2 - 1) * SURFACE_HEIGHT / 2; + +#if 1 + // ????k??????????? + // + // [map] + // 16 + // 15 14 + // 13 12 11 + // 10 9 8 7 + // 6 5 4 + // 3 2 + // 1 + + int ti, tj; + + ti = mapAreaHeight - 1; + tj = 0; + + while (ti >= 0) + { + i = ti; + j = tj; + x = tx; + y = ty; +// if (i==30) + while (i >= 0 && j >= 0) + { + // ??? + if (tile[i * mapAreaWidth+j] > CG_INVISIBLE) + { +#if 0 + // ????????(???) + if (193 <= tile[i * mapAreaWidth + j] && tile[i * mapAreaWidth+j] <= 196) + play_environment(0, x, y); +#endif + // ??????? + if (x >= (-SURFACE_WIDTH >> 1) && x < DEF_APPSIZEX + (SURFACE_WIDTH >> 1) && + y >= (-SURFACE_HEIGHT >> 1) && y < DEF_APPSIZEY + (SURFACE_HEIGHT >> 1)) + StockDispBuffer(x, y, DISP_PRIO_TILE, tile[i * mapAreaWidth + j], 0); + } + else + { + // {????????? + // ?????????? + if (20 <= tile[i * mapAreaWidth + j] && tile[i * mapAreaWidth + j] <= 39) + play_environment(tile[i * mapAreaWidth + j], x, y); + else if (40 <= tile[i * mapAreaWidth + j] && tile[i * mapAreaWidth + j] <= 59)// ??????????? + { + play_map_bgm(tile[i * mapAreaWidth + j]); + draw_map_bgm_flg = 1; + } + } + // ??? + if (parts[i * mapAreaWidth+j] > CG_INVISIBLE) + { +#if 0 + // ????????(???) + if (parts[i * mapAreaWidth+j] == 10011) + play_environment(2, x, y); + else if (parts[i * mapAreaWidth + j] == 10012) + play_environment(1, x, y); + else if (parts[i * mapAreaWidth + j] == 10203) + play_environment(4, x, y); + else if (parts[i * mapAreaWidth + j] == 10048) + { + play_map_bgm(2); + draw_map_bgm_flg = 1; + } +#endif + realGetNo(parts[i * mapAreaWidth + j], &bmpNo); + // ??????? + realGetPos(bmpNo, &xx, &yy); + realGetWH(bmpNo, &ww, &hh); + xx += x; + yy += y; + if (xx < DEF_APPSIZEX && xx + ww - 1 >= 0 && yy < DEF_APPSIZEY && yy + hh - 1 >= 0) + // ?IT?e????K??? + setPartsPrio(bmpNo, x, y, 0, 0, (float)(mapAreaX1 + j) * GRID_SIZE, (float)(mapAreaY1 + i) * GRID_SIZE, -1); + } + else + { + // {????????? + // ?????????? + if (20 <= parts[i * mapAreaWidth + j] && parts[i * mapAreaWidth + j] <= 39) + play_environment(parts[i * mapAreaWidth + j], x, y); + else if (40 <= parts[i * mapAreaWidth + j] && parts[i * mapAreaWidth + j] <= 59)// ??????????? + { + play_map_bgm(parts[i * mapAreaWidth + j]); + draw_map_bgm_flg = 1; + } + } + i--; + j--; + x -= SURFACE_WIDTH; + } + if (tj < mapAreaWidth - 1) + { + tj++; + tx += SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + else + { + ti--; + tx -= SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + } +#else + // ????k??????????? + // + // [map] + // 16 + // 15 12 + // 14 11 8 + // 13 10 7 4 + // 9 6 3 + // 5 2 + // 1 + x = (int)(dx + .5); + y = (int)(dy + .5); + for (i = mapAreaHeight - 1; i >= 0; i--) + { + tx = x; + ty = y; + for (j = 0; j < mapAreaWidth; j++) + { + // ??? + if (tile[i * mapAreaWidth + j] > CG_INVISIBLE) + { + // ??????? + if (x >= (-SURFACE_WIDTH >> 1) && x < DEF_APPSIZEX + (SURFACE_WIDTH >> 1) && + y >= (-SURFACE_HEIGHT >> 1) && y < DEF_APPSIZEY + (SURFACE_HEIGHT >> 1)) + StockDispBuffer(x, y, DISP_PRIO_TILE, tile[i * mapAreaWidth + j], 0); + } + // ??? + if (parts[i * mapAreaWidth + j] > CG_INVISIBLE) + { + realGetNo(parts[i * mapAreaWidth + j], &bmpNo); + // ??????? + realGetPos(bmpNo, &xx, &yy); + realGetWH(bmpNo, &ww, &hh); + xx += x; + yy += y; + if (xx < DEF_APPSIZEX && xx + ww - 1 >= 0 && yy < DEF_APPSIZEY && yy + hh - 1 >= 0) + // ?IT?e????K??? + setPartsPrio(bmpNo, x, y, 0, 0, (float)(mapAreaX1 + j) * GRID_SIZE, (float)(mapAreaY1 + i) * GRID_SIZE, -1); + } + x += SURFACE_WIDTH >> 1; + y -= SURFACE_HEIGHT >> 1; + } + x = tx-SURFACE_WIDTH >> 1; + y = ty-SURFACE_HEIGHT >> 1; + } +#endif + stockCharParts(); + oldGx = nowGx; + oldGy = nowGy; +#if 0 + if (!draw_map_bgm_flg) + { + play_map_bgm(0); + draw_map_bgm_flg = 1; + } +#endif + // shan 2002/01/18 + if (fMapBgm >= 40 && fMapBgm <= 53 && map_bgm_no == 2) + { + play_map_bgm(fMapBgm); + draw_map_bgm_flg = 1; + fMapBgm = 0; + } +} + +// ?????L?? +void drawMap2(void) +{ + int i, j, x, y, tx, ty; + S2 xx, yy, ww, hh; + float dx, dy; + U4 bmpNo; + short tileDrawFlag; + + if (!fastDrawTile) + { + drawMap(); + return; + } + draw_map_bgm_flg = 0; +// readMapAfterFrame++; + // ????????t?????????????? + if (nowGx != oldGx || nowGy != oldGy) + { + if (readMap(nowFloor, mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0])) + { + // hitMap[]????Re????@e?? + readHitMap(mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0], &hitMap[0]); + if (mapEmptyFlag) + { + if (!checkEmptyMap(mapEmptyDir)) + { + mapEmptyFlag = FALSE; + autoMappingInitFlag = TRUE; // ????????? + } + } + else + autoMappingInitFlag = TRUE; // ????????? +// readMapAfterFrame = 0; // ???????????????????????? + } + else + return; + } +#ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + { + dx = (float)(+ (-nowGx) * (SURFACE_WIDTH >> 1) + -nowGy * (SURFACE_WIDTH >> 1) + viewOffsetX); + dy = (float)(- (-nowGx) * (SURFACE_HEIGHT >> 1) + -nowGy * (SURFACE_HEIGHT >> 1) + viewOffsetY); + } + else +#endif + camMapToGamen(0.0, 0.0, &dx, &dy); + nowXFastDraw = (int)(dx + .5); + nowYFastDraw = (int)(dy + .5); + nowXFastDraw2 = nowXFastDraw; + nowYFastDraw2 = nowYFastDraw; + //??????????????? + if (ResoMode == 1) + { + nowXFastDraw = (int)(dx / 2 + .5); + nowYFastDraw = (int)(dy / 2 + .5); + } + amountXFastDraw = nowXFastDraw - baseXFastDraw; + amountYFastDraw = nowYFastDraw - baseYFastDraw; + amountXFastDraw2 = nowXFastDraw2 - baseXFastDraw2; + amountYFastDraw2 = nowYFastDraw2 - baseYFastDraw2; + tx = nowXFastDraw2 + (mapAreaX1 + mapAreaY2 - 1) * SURFACE_WIDTH / 2; + ty = nowYFastDraw2 + (-mapAreaX1 + mapAreaY2 - 1) * SURFACE_HEIGHT / 2; + // ????k??????????? + // + // [map] + // 16 + // 15 14 + // 13 12 11 + // 10 9 8 7 + // 6 5 4 + // 3 2 + // 1 + int ti, tj; + + ti = mapAreaHeight - 1; + tj = 0; + while (ti >= 0) + { + i = ti; + j = tj; + x = tx; + y = ty; + while (i >= 0 && j >= 0) + { + // ??? + if (tile[i * mapAreaWidth + j] > CG_INVISIBLE) + { + if (amountXFastDraw2 != 0 || amountYFastDraw2 != 0) + { + // ??V????????????? + if ((-SURFACE_WIDTH >> 1) < x && x < DEF_APPSIZEX + (SURFACE_WIDTH >> 1) && + (-SURFACE_HEIGHT >> 1) < y && y < DEF_APPSIZEY + (SURFACE_HEIGHT >> 1)) + { + tileDrawFlag = 0; + if (amountXFastDraw2 > 0) + { + if ((x - amountXFastDraw2) <= (SURFACE_WIDTH >> 1)) + tileDrawFlag = 1; + } + else if (amountXFastDraw2 < 0) + { + if (DEF_APPSIZEX - (SURFACE_WIDTH >> 1) <= (x - amountXFastDraw2)) + tileDrawFlag = 1; + } + if (amountYFastDraw2 > 0) + { + if ((y - amountYFastDraw2) <= (SURFACE_HEIGHT >> 1)) + tileDrawFlag = 1; + } + else if (amountYFastDraw2 < 0) + { + if (DEF_APPSIZEY - (SURFACE_HEIGHT >> 1) <= (y - amountYFastDraw2)) + tileDrawFlag = 1; + } + if (tileDrawFlag) + StockDispBuffer(x, y, DISP_PRIO_TILE, tile[i * mapAreaWidth + j], 0); + } + } + } + else + { + // {????????? + // ?????????? + if (20 <= tile[i * mapAreaWidth + j] && tile[i * mapAreaWidth + j] <= 39) + play_environment(tile[i * mapAreaWidth + j], x, y); + else if (40 <= tile[i * mapAreaWidth + j] && tile[i * mapAreaWidth + j] <= 59)// ??????????? + { + play_map_bgm(tile[i * mapAreaWidth + j]); + draw_map_bgm_flg = 1; + } + } + // ??? + if (parts[i * mapAreaWidth + j] > CG_INVISIBLE) + { + //printf("parts[i * mapAreaWidth + j]=%d i=%d j=%d\n",parts[i * mapAreaWidth + j],i,j); + + + + realGetNo(parts[i * mapAreaWidth + j], &bmpNo); + // ??????? + realGetPos(bmpNo, &xx, &yy); + realGetWH(bmpNo, &ww, &hh); + xx += x; + yy += y; + if (xx < DEF_APPSIZEX && xx + ww - 1 >= 0 && yy < DEF_APPSIZEY && yy + hh - 1 >= 0) + setPartsPrio(bmpNo, x, y, 0, 0, (float)(mapAreaX1 + j) * GRID_SIZE, (float)(mapAreaY1 + i) * GRID_SIZE, -1); + } + else + { + // {????????? + // ?????????? + if (20 <= parts[i * mapAreaWidth + j] && parts[i * mapAreaWidth + j] <= 39) + play_environment(parts[i * mapAreaWidth + j], x, y); + else if (40 <= parts[i * mapAreaWidth + j] && parts[i * mapAreaWidth + j] <= 59)// ??????????? + { + play_map_bgm(parts[i * mapAreaWidth + j]); + draw_map_bgm_flg = 1; + } + } + i--; + j--; + x -= SURFACE_WIDTH; + } + if (tj < mapAreaWidth - 1) + { + tj++; + tx += SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + else + { + ti--; + tx -= SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + } + // shan 2002/01/18 + if (fMapBgm >= 40 && fMapBgm <= 53 && map_bgm_no == 2) + { + play_map_bgm(fMapBgm); + draw_map_bgm_flg = 1; + fMapBgm = 0; + } + stockCharParts(); + oldGx = nowGx; + oldGy = nowGy; +} + +// ????? +void drawTile(void) +{ + int i, j, x, y, tx, ty; + + // ????????? + if (readMap(nowFloor, mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0])) + readHitMap(mapAreaX1, mapAreaY1, mapAreaX2, mapAreaY2, &tile[0], &parts[0], &event[0], &hitMap[0]); // hitMap[]????Re????@e?? + tx = nowXFastDraw2 + (((mapAreaX1 + mapAreaY2 - 1) * SURFACE_WIDTH) >> 1); + ty = nowYFastDraw2 + (((-mapAreaX1 + mapAreaY2 - 1) * SURFACE_HEIGHT) >> 1); + // ????k??????????? + // + // [map] + // 16 + // 15 14 + // 13 12 11 + // 10 9 8 7 + // 6 5 4 + // 3 2 + // 1 + + int ti, tj; + + ti = mapAreaHeight - 1; + tj = 0; + while (ti >= 0) + { + i = ti; + j = tj; + x = tx; + y = ty; + while (i >= 0 && j >= 0) + { + // ??? + if (tile[i * mapAreaWidth + j] > CG_INVISIBLE) + { + // ??????? + if (x >= (-SURFACE_WIDTH >> 1) && x < (DEF_APPSIZEX + (SURFACE_WIDTH >> 1)) && + y >= (-SURFACE_HEIGHT >> 1) && y < (DEF_APPSIZEY + (SURFACE_HEIGHT >> 1))) + StockDispBuffer(x, y, DISP_PRIO_TILE, tile[i * mapAreaWidth + j], 0); + } + i--; + j--; + x -= SURFACE_WIDTH; + } + if (tj < mapAreaWidth - 1) + { + tj++; + tx += SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + else + { + ti--; + tx -= SURFACE_WIDTH >> 1; + ty -= SURFACE_HEIGHT >> 1; + } + } +} + +void redrawMap(void) +{ + oldGx = -1; + oldGy = -1; +} +#if 1 +static unsigned char BitTable[] = /* ??????????????? */ +{ + 0x00 , 0x80 , 0x40 , 0xC0 , 0x20 , 0xA0 , 0x60 , 0xE0 , + 0x10 , 0x90 , 0x50 , 0xD0 , 0x30 , 0xB0 , 0x70 , 0xF0 , + 0x08 , 0x88 , 0x48 , 0xC8 , 0x28 , 0xA8 , 0x68 , 0xE8 , + 0x18 , 0x98 , 0x58 , 0xD8 , 0x38 , 0xB8 , 0x78 , 0xF8 , + 0x04 , 0x84 , 0x44 , 0xC4 , 0x24 , 0xA4 , 0x64 , 0xE4 , + 0x14 , 0x94 , 0x54 , 0xD4 , 0x34 , 0xB4 , 0x74 , 0xF4 , + 0x0C , 0x8C , 0x4C , 0xCC , 0x2C , 0xAC , 0x6C , 0xEC , + 0x1C , 0x9C , 0x5C , 0xDC , 0x3C , 0xBC , 0x7C , 0xFC , + 0x02 , 0x82 , 0x42 , 0xC2 , 0x22 , 0xA2 , 0x62 , 0xE2 , + 0x12 , 0x92 , 0x52 , 0xD2 , 0x32 , 0xB2 , 0x72 , 0xF2 , + 0x0A , 0x8A , 0x4A , 0xCA , 0x2A , 0xAA , 0x6A , 0xEA , + 0x1A , 0x9A , 0x5A , 0xDA , 0x3A , 0xBA , 0x7A , 0xFA , + 0x06 , 0x86 , 0x46 , 0xC6 , 0x26 , 0xA6 , 0x66 , 0xE6 , + 0x16 , 0x96 , 0x56 , 0xD6 , 0x36 , 0xB6 , 0x76 , 0xF6 , + 0x0E , 0x8E , 0x4E , 0xCE , 0x2E , 0xAE , 0x6E , 0xEE , + 0x1E , 0x9E , 0x5E , 0xDE , 0x3E , 0xBE , 0x7E , 0xFE , + 0x01 , 0x81 , 0x41 , 0xC1 , 0x21 , 0xA1 , 0x61 , 0xE1 , + 0x11 , 0x91 , 0x51 , 0xD1 , 0x31 , 0xB1 , 0x71 , 0xF1 , + 0x09 , 0x89 , 0x49 , 0xC9 , 0x29 , 0xA9 , 0x69 , 0xE9 , + 0x19 , 0x99 , 0x59 , 0xD9 , 0x39 , 0xB9 , 0x79 , 0xF9 , + 0x05 , 0x85 , 0x45 , 0xC5 , 0x25 , 0xA5 , 0x65 , 0xE5 , + 0x15 , 0x95 , 0x55 , 0xD5 , 0x35 , 0xB5 , 0x75 , 0xF5 , + 0x0D , 0x8D , 0x4D , 0xCD , 0x2D , 0xAD , 0x6D , 0xED , + 0x1D , 0x9D , 0x5D , 0xDD , 0x3D , 0xBD , 0x7D , 0xFD , + 0x03 , 0x83 , 0x43 , 0xC3 , 0x23 , 0xA3 , 0x63 , 0xE3 , + 0x13 , 0x93 , 0x53 , 0xD3 , 0x33 , 0xB3 , 0x73 , 0xF3 , + 0x0B , 0x8B , 0x4B , 0xCB , 0x2B , 0xAB , 0x6B , 0xEB , + 0x1B , 0x9B , 0x5B , 0xDB , 0x3B , 0xBB , 0x7B , 0xFB , + 0x07 , 0x87 , 0x47 , 0xC7 , 0x27 , 0xA7 , 0x67 , 0xE7 , + 0x17 , 0x97 , 0x57 , 0xD7 , 0x37 , 0xB7 , 0x77 , 0xF7 , + 0x0F , 0x8F , 0x4F , 0xCF , 0x2F , 0xAF , 0x6F , 0xEF , + 0x1F , 0x9F , 0x5F , 0xDF , 0x3F , 0xBF , 0x7F , 0xFF +}; +static unsigned short crctab16[] = /* crc ?????? */ +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, +}; +unsigned short CheckCRC(unsigned char *p , int size) +{ + unsigned short crc = 0; + int i; + + for (i = 0; i < size; i ++) + { + crc = (crctab16[(crc >> 8) & 0xFF] ^ (crc << 8) ^ BitTable[p[i]]); + } + return crc; +} + +BOOL mapCheckSum(int floor, int x1, int y1, int x2, int y2, int tileSum, int partsSum, int eventSum) +{ + int tilesum = 0, objsum = 0, eventsum = 0, databufferindex = 0, width = x2 - x1, height = y2 - y1, i, j; + unsigned short tile[MAP_X_SIZE*MAP_Y_SIZE]; + unsigned short parts[MAP_X_SIZE*MAP_Y_SIZE]; + unsigned short event[MAP_X_SIZE*MAP_Y_SIZE]; + + // ????????????? + + readMap(floor, x1, y1, x2, y2, tile, parts, event); + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + event[i * width + j] &= 0x0fff; + } + + tilesum = CheckCRC((unsigned char*)tile, 27 * 27 * sizeof(short)); + objsum = CheckCRC((unsigned char*)parts, 27 * 27 * sizeof(short)); + eventsum = CheckCRC((unsigned char*)event, 27 * 27 * sizeof(short)); + + if (tileSum == tilesum && partsSum == objsum && eventSum == eventsum) + { + if (loginFlag) + { + redrawMap(); + loginFlag = FALSE; + } + return TRUE; + } + else + { + if (bNewServer) + lssproto_M_send(sockfd, floor, x1, y1, x2, y2); + else + old_lssproto_M_send(sockfd, floor, x1, y1, x2, y2); + //ͼ쳣 + if (loginFlag) + loginFlag = FALSE; + + return FALSE; + } +} +#else +BOOL mapCheckSum(int floor, int x1, int y1, int x2, int y2, int tileSum, int partsSum, int eventSum) +{ + int tilesum = 0, objsum = 0, eventsum = 0, databufferindex = 0, width = x2 - x1, height = y2 - y1, i, j; + unsigned short tile[MAP_X_SIZE*MAP_Y_SIZE]; + unsigned short parts[MAP_X_SIZE*MAP_Y_SIZE]; + unsigned short event[MAP_X_SIZE*MAP_Y_SIZE]; + // ????????????? + + readMap(floor, x1, y1, x2, y2, tile, parts, event); + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + tilesum += (tile[i * width + j] % (27 * 27)) ^ databufferindex; + objsum += (parts[i * width + j] % (27 * 27)) ^ databufferindex; +#if 1 + eventsum += ((event[i * width + j] & 0x0fff) % (27 * 27)) ^ databufferindex; +#else + eventsum += (event[i * width + j] % (27 * 27)) ^ databufferindex; +#endif + databufferindex++; + } + } + + if (tileSum == tilesum && partsSum == objsum && eventSum == eventsum) + { + // ?????????????????? + if (loginFlag) + { + redrawMap(); + loginFlag = FALSE; + } + + return TRUE; + } + else + { + if (bNewServer) + lssproto_M_send(sockfd, floor, x1, y1, x2, y2); + else + old_lssproto_M_send(sockfd, floor, x1, y1, x2, y2); +#if 0 + // ??????????????FALSE??? + if (loginFlag) + loginFlag = FALSE; +#endif + return FALSE; + } +} +#endif + + +// ????????????Reѩ???? +#if 1 +void readHitMap(int x1, int y1, int x2, int y2, unsigned short *tile, unsigned short *parts, unsigned short *event, unsigned short *hitMap) +{ + int width, height, i, j, k, l; + S2 hit, hitX, hitY; + U4 bmpNo; + + memset(hitMap, 0, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + + width = x2 - x1; + height = y2 - y1; + if (width < 1 || height < 1) + return; + + // ??? + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + // ???????Re + if (tile[i * width + j] > CG_INVISIBLE || (60 <= tile[i * width + j] && tile[i * width + j] <= 79)) + { + realGetNo(tile[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0 && hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + else if (hit == 2) // hit?2??????Re??? + hitMap[i * width + j] = 2; + } + else + { + // 0??11?????????????? + switch (tile[i * width + j]) + { + case 0: // 0.bmp(???)???????Re????? + // ???????????????????? + if ((event[i * width + j] & MAP_SEE_FLAG) == 0) + break; + case 1: + case 2: + case 5: + case 6: + case 9: + case 10: + // ???Re???????@e??? + if (hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + break; + + case 4: + hitMap[i * width + j] = 2; + break; + } + } + } + } + + // ??? + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + // ???????Re + if (parts[i * width + j] > CG_INVISIBLE) + { + realGetNo(parts[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + if ((i - k) >= 0 && (j + l) < width && hitMap[(i - k) * width + j + l] != 2) + hitMap[(i - k) * width + j + l] = 1; + } + } + } + // ???Re?????????????? + // ?ɤ???????? + else if (hit == 2) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + if ((i - k) >= 0 && (j + l) < width) + hitMap[(i - k) * width + j + l] = 2; + } + } + } + else if (hit == 1 && parts[i * width + j] >= 15680 && parts[i * width + j] <= 15732) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + //if ((i - k) >= 0 && (j + l) < width) + //hitMap[(i-k)*width+j+l] = 0; + if (k == 0 && l == 0) + hitMap[(i - k) * width + j + l] = 1; + } + } + } + } + else if (60 <= parts[i * width + j] && parts[i * width + j] <= 79) + { + realGetNo(parts[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0 && hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + // hit?2??????Re??? + else if (hit == 2) + hitMap[i * width + j] = 2; + } + else + { + // 0??11?????????????? + switch (parts[i * width + j]) + { + case 1: + case 2: + case 5: + case 6: + case 9: + case 10: + // ???Re???????@e??? + if (hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + break; + + case 4: + hitMap[i * width + j] = 2; + break; + } + } + + // ?e?????????????? + if ((event[i * width + j] & 0x0fff) == EVENT_NPC) + hitMap[i * width + j] = 1; + } + } +} +#else +void readHitMap(int x1, int y1, int x2, int y2, unsigned short *tile, unsigned short *parts, unsigned short *event, unsigned short *hitMap) +{ + int width, height, i, j, k, l; + S2 hit, hitX, hitY; + U4 bmpNo; + + memset(hitMap, 0, MAP_X_SIZE * MAP_Y_SIZE * sizeof(short)); + + width = x2 - x1; + height = y2 - y1; + + if (width < 1 || height < 1) + return; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + // ???????????????????? + if ((event[i * width + j] & MAP_READ_FLAG) == 0) + continue; + + // ???????Re + if (tile[i * width + j] > CG_INVISIBLE +#if 0 + || (60 <= tile[i * width + j] && tile[i * width + j] <= 79)) +#else + ) +#endif + { + realGetNo(tile[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0 && hitMap[i * width + j] != 2) + hitMap[i*width+j] = 1; + // hit?2??????Re??? + else if (hit == 2) + hitMap[i * width + j] = 2; + } +#if 0 + else + { + // 0??11?????????????? + switch (tile[i * width + j]) + { + case 0: // 0.bmp(???)???????Re????? + case 1: + case 2: + case 5: + case 6: + case 9: + case 10: + // ???Re???????@e??? + if (hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + break; + case 4: + hitMap[i * width + j] = 2; + break; + } + } +#endif + // ???????Re + if (parts[i * width + j] > CG_INVISIBLE) + { + realGetNo(parts[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + if ((i - k) >= 0 && (j + l) < width && hitMap[(i - k) * width + j + l] != 2) + hitMap[(i - k) * width + j + l] = 1; + } + } + } + // ???Re?????????????? + // ?ɤ???????? + else if (hit == 2) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + if ((i - k) >= 0 && (j + l) < width) + hitMap[(i - k) * width + j + l] = 2; + } + } + } + } +#if 0 + else if (60 <= parts[i * width + j] && parts[i * width + j] <= 79) + { + realGetNo(parts[i * width + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0 && hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + // hit?2??????Re??? + else if (hit == 2) + hitMap[i * width + j] = 2; + } +#endif +#if 0 + else + { + // 0??11?????????????? + switch (parts[i * width + j]) + { + case 1: + case 2: + case 5: + case 6: + case 9: + case 10: + // ???Re???????@e??? + if (hitMap[i * width + j] != 2) + hitMap[i * width + j] = 1; + break; + case 4: + hitMap[i * width + j] = 2; + break; + } + } +#endif + // ?e?????????????? + if ((event[i * width + j] & 0x0fff) == EVENT_NPC) + hitMap[i * width + j] = 1; + } + } +} +#endif +// +// ???Re????? +// ??kTRUE ... V? +// +#ifdef _ITEM_PATH +BOOL ITEMPATHFLAG = FALSE; +#endif +BOOL checkHitMap(int gx, int gy) +{ + int x, y; + + x = gx - mapAreaX1; + y = gy - mapAreaY1; + + if (pc.skywalker) + return FALSE; + + // ????d???V? + if (x < 0 || mapAreaWidth <= x || y < 0 || mapAreaHeight <= y) + return TRUE; +#ifdef _ITEM_PATH + if (ITEMPATHFLAG) + { + ITEMPATHFLAG = FALSE; + return FALSE; + } +#endif + // ???Re????V? + if (hitMap[y * mapAreaWidth + x] == 1) + return TRUE; + + return FALSE; +} + +// +// ?hI?????????h????????????r?? +// +BOOL checkEmptyMap(int dir) +{ + // ?????t???11??????????????TRUE?? + int i, gx, gy, tx, ty, len; + BOOL flag = FALSE; + + if (mapAreaWidth < MAP_X_SIZE || mapAreaHeight < MAP_Y_SIZE) + return FALSE; + + getMapAreaCnt = 0; + + if (dir == 0 || dir == 1 || dir == 2) + { + gx = nowGx - SEARCH_AREA; + gy = nowGy - SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if (event[ty * mapAreaWidth + tx] == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = gx + 1; + getMapAreaY2[getMapAreaCnt] = gy + (SEARCH_AREA << 1) + 1; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gy++; + ty++; + } + } + if (dir == 2 || dir == 3 || dir == 4) + { + gx = nowGx - SEARCH_AREA; + gy = nowGy - SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if (event[ty * mapAreaWidth + tx] == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = gx + (SEARCH_AREA << 1) + 1; + getMapAreaY2[getMapAreaCnt] = gy + 1; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gx++; + tx++; + } + } + if (dir == 4 || dir == 5 || dir == 6) + { + gx = nowGx + SEARCH_AREA; + gy = nowGy - SEARCH_AREA; + tx = SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if (event[ty * mapAreaWidth + tx] == 0) + { + getMapAreaX1[getMapAreaCnt] = gx; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = gx + 2; + getMapAreaY2[getMapAreaCnt] = gy + (SEARCH_AREA << 1) + 1; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gy++; + ty++; + } + } + if (dir == 6 || dir == 7 || dir == 0) + { + gx = nowGx - SEARCH_AREA; + gy = nowGy + SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if (event[ty * mapAreaWidth + tx] == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy; + getMapAreaX2[getMapAreaCnt] = gx + (SEARCH_AREA << 1) + 1; + getMapAreaY2[getMapAreaCnt] = gy + 2; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gx++; + tx++; + } + } + + return flag; +} + +// d?????????? +void checkAreaLimit(short *x1, short *y1, short *x2, short *y2) +{ + if (*x1 < 0) + *x1 = 0; + if (*y1 < 0) + *y1 = 0; + if (*x2 > nowFloorGxSize) + *x2 = nowFloorGxSize; + if (*y2 > nowFloorGySize) + *y2 = nowFloorGySize; +} + +/////////////////////////////////////////////////////////////////////////// +// ???????????????? +// +void drawGrid(void) +{ + float x, y; + int xx, yy; + extern int mapWndFontNo[]; + extern int resultWndFontNo[]; + + // ???????????????? + if ((MenuToggleFlag & JOY_CTRL_M) == 0) + mapWndFontNo[0] = -2; + // Pf??????????????? + if (BattleResultWndFlag <= 0) + resultWndFontNo[0] = -2; + + camGamenToMap((float)mouse.nowPoint.x, (float)mouse.nowPoint.y, &x, &y); + mouseMapX = (int)(x + .5); + mouseMapY = (int)(y + .5); + mouseMapGx = (mouseMapX + (GRID_SIZE >> 1)) / GRID_SIZE; + mouseMapGy = (mouseMapY + (GRID_SIZE >> 1)) / GRID_SIZE; + xx = mouseMapGx * GRID_SIZE; + yy = mouseMapGy * GRID_SIZE; + camMapToGamen((float)xx, (float)yy, &x, &y); + + // ?????????????????????? +#if 0 + if (mouse.level < DISP_PRIO_MENU || mapWndFontNo[0] == HitDispNo || resultWndFontNo[0] == HitDispNo) +#else + if (mouse.level < DISP_PRIO_MENU) +#endif + { + // ????????? + if (mouseCursorMode == MOUSE_CURSOR_MODE_NORMAL) + StockDispBuffer((int)(x + .5), (int)(y + .5), DISP_PRIO_GRID, CG_GRID_CURSOR, 0); + //cary 2002.1.15 else + // { + // StockDispBuffer((int)(x+.5), (int)(y+.5), DISP_PRIO_GRID, 1610, 0); + // } + } + + // ?????l + // fieldProc(); moveProc(); ?????????????? + mouseLeftCrick = FALSE; + mouseLeftOn = FALSE; + mouseRightCrick = FALSE; + mouseRightOn = FALSE; +#ifdef _MOUSE_DBL_CLICK + mouseDblRightOn = FALSE; +#endif + if ((mouse.level < DISP_PRIO_MENU && mouse.itemNo == -1) || mapWndFontNo[0] == HitDispNo || resultWndFontNo[0] == HitDispNo) + { + if ((mouse.onceState & MOUSE_LEFT_CRICK)) + { +#ifdef _MOVE_SCREEN + if (!pc.bCanUseMouse) // 糡ģʽʱƶ +#endif + { +#ifdef _THEATER + // pc.iTheaterMode 0 ʱʾڱ,Ҫ pc.bCanUseMouse 趨Ϊ TRUE + if (pc.iTheaterMode > 0) + pc.bCanUseMouse = TRUE; +#endif + mouseLeftCrick = TRUE; + mouseLeftPushTime = 0; + beforeMouseLeftPushTime = TimeGetTime(); + } + } + if ((mouse.state & MOUSE_LEFT_CRICK)) + { +#ifdef _MOVE_SCREEN + if (!pc.bCanUseMouse) // 糡ģʽʱƶ +#endif + { +#ifdef _THEATER + // pc.iTheaterMode 0 ʱʾڱ,Ҫ pc.bCanUseMouse 趨Ϊ TRUE + if (pc.iTheaterMode > 0) + pc.bCanUseMouse = TRUE; +#endif + mouseLeftOn = TRUE; + if (beforeMouseLeftPushTime > 0) + mouseLeftPushTime = TimeGetTime() - beforeMouseLeftPushTime; + } + } + else + { + mouseLeftPushTime = 0; + beforeMouseLeftPushTime = 0; + } + if ((mouse.onceState & MOUSE_RIGHT_CRICK)) + mouseRightCrick = TRUE; + if ((mouse.state & MOUSE_RIGHT_CRICK)) + mouseRightOn = TRUE; +#ifdef _MOUSE_DBL_CLICK + if ((mouse.onceState & MOUSE_RIGHT_DBL_CRICK)) + mouseDblRightOn = TRUE; +#endif + // ???????????????????h??????? + // Pf??????????????????h??????? + if (mapWndFontNo[0] == HitDispNo || resultWndFontNo[0] == HitDispNo) + mouseLeftCrick = FALSE; + } + else + { + mouseCursorMode = MOUSE_CURSOR_MODE_NORMAL; + mouseLeftPushTime = 0; + beforeMouseLeftPushTime = 0; + } +} + +/////////////////////////////////////////////////////////////////////////// +// ?h?? +//Terry add 2003/11/25 +bool g_bTradesystemOpen = false; +//end +void moveProc(void) +{ + static unsigned int befortime = -1; + +#ifdef _STONDEBUG_ + { + static short tglSw = 0; + + if (tglSw == 1) + { + char msg[256]; + sprintf_s(msg, "EN send : %d", sendEnFlag); + StockFontBuffer(240, 16, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "EV (Warp) send : %d", eventWarpSendFlag); + StockFontBuffer(240, 32, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "EV (Enemy) send: %d", eventEnemySendFlag); + StockFontBuffer(240, 48, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "Empty : %d", mapEmptyFlag); + StockFontBuffer(240, 64, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, " nowGx = %3d/ nowGy = %3d", nowGx, nowGy); + StockFontBuffer(240, 80, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, " mapEmptyGx = %3d/ mapEmptyGy = %3d", mapEmptyGx, mapEmptyGy); + StockFontBuffer(240, 96, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, " mapEmptyDir = %3d", mapEmptyDir); + StockFontBuffer(240, 112, FONT_PRIO_FRONT, 0, msg, 0); + } + else if (tglSw == 2) + { + char msg[256]; + sprintf_s(msg, "nowEncountPercentage : %d", nowEncountPercentage); + StockFontBuffer(240, 16, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "nowEncountExtra : %d", nowEncountExtra); + StockFontBuffer(240, 32, FONT_PRIO_FRONT, 0, msg, 0); + } + else if (tglSw == 3 || tglSw == 4) + { + // ???Re?????? + // ????Re?????? + char msg[256]; + int x, y, xx, yy, color; + + xx = -MAP_TILE_GRID_X1; + yy = -MAP_TILE_GRID_Y1; + + if (MAP_X_SIZE > mapAreaWidth) + { + if (mapAreaX1 == 0) + xx -= (MAP_X_SIZE - mapAreaWidth); + } + if (MAP_Y_SIZE > mapAreaHeight) + { + if (mapAreaY1 == 0) + yy -= (MAP_Y_SIZE - mapAreaHeight); + } + + for (y = 0; y < mapAreaHeight && y < 26; y++) + { + for (x = 0; x < mapAreaWidth; x++) + { + if (tglSw == 3) + { + sprintf_s(msg, "%d", hitMap[y * mapAreaWidth + x]); + if (x == xx && y == yy) + color = FONT_PAL_RED; + else + color = FONT_PAL_WHITE; + } + else + { + sprintf_s(msg, "%d", (event[y * mapAreaWidth + x] & 0xfff)); + if (x == xx && y == yy) + color = FONT_PAL_RED; + else + { + if (event[y * mapAreaWidth + x] != 0) + color = FONT_PAL_YELLOW; + else + color = FONT_PAL_WHITE; + } + } + StockFontBuffer(x * 10, y * 18, FONT_PRIO_FRONT, color, msg, 0); + } + } + sprintf_s(msg, "gx = %5d / gy = %5d / hit = %d", mouseMapGx, mouseMapGy, checkHitMap(mouseMapGx, mouseMapGy)); + StockFontBuffer(332, 40, FONT_PRIO_FRONT, 0, msg, 0); + } + else if (tglSw == 5) + { + char msg[256]; + int x, y; + + x = mouseMapGx - mapAreaX1; + y = mouseMapGy - mapAreaY1; + sprintf_s(msg, "Tile Bmp = %d", tile[y * mapAreaWidth + x]); + StockFontBuffer(240, 34, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "Parts Bmp = %d", parts[y * mapAreaWidth + x]); + StockFontBuffer(240, 54, FONT_PRIO_FRONT, 0, msg, 0); + sprintf_s(msg, "Gx = %d / Gy = %d", mouseMapGx, mouseMapGy); + StockFontBuffer(240, 74, FONT_PRIO_FRONT, 0, msg, 0); + } + else if (tglSw == 6) + { + char msg[256]; + + if ((joy_trg[ 0 ] & JOY_RIGHT) && mapEffectRainLevel < 5) + mapEffectRainLevel++; + else if ((joy_trg[ 0 ] & JOY_LEFT) && mapEffectRainLevel > 0) + mapEffectRainLevel--; + sprintf_s(msg, "mapEffectRainLevel = %d", mapEffectRainLevel); + StockFontBuffer(240, 34, FONT_PRIO_FRONT, 0, msg, 0); + } + else if (tglSw == 7) + { + char msg[256]; + + if ((joy_trg[ 0 ] & JOY_RIGHT) && mapEffectSnowLevel < 5) + mapEffectSnowLevel++; + else if ((joy_trg[ 0 ] & JOY_LEFT) && mapEffectSnowLevel > 0) + mapEffectSnowLevel--; + sprintf_s(msg, "mapEffectSnowLevel = %d", mapEffectSnowLevel); + StockFontBuffer(240, 34, FONT_PRIO_FRONT, 0, msg, 0); + } + } +#endif + + // ????????????? + if (sendEnFlag == 0 && eventWarpSendFlag == 0 && eventEnemySendFlag == 0) + etcEventFlag = 0; + + + // ????Y?????????? + // ?????????????? + if (mouseLeftCrick) + { + if (lookAtAround()) + mouseLeftCrick = FALSE; +#ifdef __TALK_TO_NPC + extern BOOL TalkToNPC(); + if (TalkToNPC()) + mouseLeftCrick = FALSE; +#endif +//Terry add 2003/11/25 + if (g_bTradesystemOpen) + mouseLeftCrick = FALSE; +//end + } + // ???????????? + if (mouseRightCrick) + { + // ????? + turnAround(); + // ????? + getItem(); + } +#ifdef _MOUSE_DBL_CLICK + if (mouseDblRightOn) + { + } +#endif + // ?hI?k + // O?????????V????? + // ????????????????? + + if ((partyModeFlag == 0 || (pc.status & CHR_STATUS_LEADER) != 0) && etcSendFlag == 0 && etcEventFlag == 0) + { + // ??????????h?????? + if (mouseLeftPushTime >= MOVE_MODE_CHANGE_TIME) + mouseCursorMode = MOUSE_CURSOR_MODE_MOVE; + // ?h?????? + if (mouseCursorMode == MOUSE_CURSOR_MODE_MOVE) + { + // ????????G?????? + if (mouseLeftCrick) + mouseCursorMode = MOUSE_CURSOR_MODE_NORMAL; + else + // ???????t??hI??? + { + // ??????? + if (befortime + MOVE_CLICK_WAIT_TIME <= TimeGetTime()) + { + befortime = TimeGetTime(); + moveStackGx = mouseMapGx; + moveStackGy = mouseMapGy; + moveStackFlag = TRUE; + } + } + } + else + // G?????? + if (mouseLeftCrick) + { + // ???????t??hI??? + // ??????? + if (befortime + MOVE_CLICK_WAIT_TIME <= TimeGetTime()) + { + befortime = TimeGetTime(); + moveStackGx = mouseMapGx; + moveStackGy = mouseMapGy; + moveStackFlag = TRUE; + } + } + } + + // ?????k?????? + getPartyTbl(); + // ??????????h?? + if (partyModeFlag == 0 || (pc.status & CHR_STATUS_LEADER) != 0) + onceMoveProc(); + else + // ??????????h?? + partyMoveProc(); +#ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + MoveScreenProc(); +#endif +#ifdef _THEATER + if (pc.iSceneryNumber >= 0) + { + int iSceneryGX = -1, iSceneryGY = 3; + float fX, fY; + + if (pc.bMoveScreenMode) + { + iSceneryGX -= iScreenMoveX; + iSceneryGY -= iScreenMoveY; + } + camMapToGamen((float)iSceneryGX * GRID_SIZE, (float)iSceneryGY * GRID_SIZE, &fX, &fY); + StockDispBuffer((int)fX, (int)fY, DISP_PRIO_PARTS, pc.iSceneryNumber, 0); + } +#endif + + return; +} + +short _encountFlag = 0; +short _warpEventFlag = 0; +short _enemyEventFlag = 0; +int _enemyEventDir; +short justGoalFlag = 0; // ???????????? +#ifdef MAX_AIRPLANENUM +short _partyTbl[MAX_AIRPLANENUM]; +#else +short _partyTbl[MAX_PARTY]; // ?????ѩ???????? +#endif + +void _etcEventCheck(void); +BOOL _execEtcEvent(void); +void _getMoveRoute2(void); +void setPcMovePointToChar(int, int); +void setPartyMovePoint(void); +void _mapMove(void); +void _partyMapMove(void); +void _setMapMovePoint(int, int); +BOOL _checkEncount(void); +void _sendEncount(void); +void _sendMoveRoute(void); +BOOL _checkWarpEvent(int, int); +void _sendWarpEvent(void); +BOOL _checkEnemyEvent(int, int); +void _sendEnemyEvent(void); +//void _checkEmptyMap(void); +BOOL checkEmptyMapData(int, int, int); + +void updateMapArea(void) +{ + mapAreaX1 = nowGx+MAP_TILE_GRID_X1; + mapAreaY1 = nowGy+MAP_TILE_GRID_Y1; + mapAreaX2 = nowGx+MAP_TILE_GRID_X2; + mapAreaY2 = nowGy+MAP_TILE_GRID_Y2; + + if (mapAreaX1 < 0) + mapAreaX1 = 0; + if (mapAreaY1 < 0) + mapAreaY1 = 0; + if (mapAreaX2 > nowFloorGxSize) + mapAreaX2 = nowFloorGxSize; + if (mapAreaY2 > nowFloorGySize) + mapAreaY2 = nowFloorGySize; + + mapAreaWidth = mapAreaX2 - mapAreaX1; + mapAreaHeight = mapAreaY2 - mapAreaY1; +} + +void onceMoveProc(void) +{ + int dir; + // ???????????L???? + nowSpdRate = 1.0F; + // ????????h?????? + if (mapEmptyFlag) + return; + if (sendEnFlag == 0 && eventWarpSendFlag == 0 && eventEnemySendFlag == 0) + { + //cary say eventִУ͸server + if (_execEtcEvent()) + return; + if ((float)nextGx * GRID_SIZE == nowX && (float)nextGy * GRID_SIZE == nowY) + { + if (moveStackFlag && moveRouteCnt2 == 0) + { + moveStackFlag = FALSE; + getRouteMap(); + if (moveRouteCnt == 0) + turnAround(); + } + if (moveRouteCnt == 0 && moveRouteCnt2 == 0) + { + turnAround2(moveLastDir); + moveLastDir = -1; + } + if (moveRouteCnt > 0 && moveRouteCnt2 == 0) + { + _getMoveRoute2(); + if (moveRouteCnt2 > 0) + _etcEventCheck(); + _sendMoveRoute(); + } + if (moveRouteCnt2 > 0) + { + _checkEmptyMap(); + dir = moveRoute2[0]; + shiftRouteMap2(); + setMapMovePoint(nowGx + moveAddTbl[dir][0], nowGy + moveAddTbl[dir][1]); + setPcMovePointToChar(nowGx, nowGy); + } + } + } + // ??????????\????????hI?@e?? + setPartyMovePoint(); + // ??????????????????????? + justGoalFlag = 0; + // ????????h?????? + if (mapEmptyFlag) + return; + // ???h????h???????? + _mapMove(); + // ???????h?? + _partyMapMove(); + updateMapArea(); + + { + viewPointX = nowX; + viewPointY = nowY; + } + +} + +// ????????????? +void partyMoveProc(void) +{ + int i; + ACTION *ptAct, *ptActNext; + + // ????????????????hI?????@e? + // ???????????????????@e????? +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + if (_partyTbl[i] >= 0) + { + ptAct = party[_partyTbl[i]].ptAct; + + // ????? + if (party[_partyTbl[i]].id != pc.id) + { + // ?????????????hI?@e?? + if ((float)ptAct->nextGx * GRID_SIZE == ptAct->mx && (float)ptAct->nextGy * GRID_SIZE == ptAct->my) + { + // ?????????????@e + if (ptAct->bufCount > 0) + { + // ????????????L?? + if (i == 0) + { + nowSpdRate = 1.0F; + if (ptAct->bufCount > 5) + nowSpdRate = 2.0F; + else if (ptAct->bufCount >= 4) + nowSpdRate = 1.6F; + else if (ptAct->bufCount >= 2) + nowSpdRate = 1.2F; + } + _setCharMovePoint(ptAct, ptAct->bufGx[0], ptAct->bufGy[0]); + shiftBufCount(ptAct); +#ifdef MAX_AIRPLANENUM + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_AIRPLANENUM) +#else + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_PARTY) +#endif + { + ptActNext = party[_partyTbl[i + 1]].ptAct; + stockCharMovePoint(ptActNext, ptAct->gx, ptAct->gy); + } + } + } + } + // ???? + else + { + // ?????????????hI?@e?? + if ((float)nextGx * GRID_SIZE == nowX && (float)nextGy * GRID_SIZE == nowY) + { + // ?????????????@e + if (ptAct->bufCount > 0) + { + _setMapMovePoint(ptAct->bufGx[0], ptAct->bufGy[0]); + shiftBufCount(ptAct); +#ifdef MAX_AIRPLANENUM + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_AIRPLANENUM) +#else + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_PARTY) +#endif + { + ptActNext = party[_partyTbl[i + 1]].ptAct; + stockCharMovePoint(ptActNext, ptAct->gx, ptAct->gy); + } + } + } + } + } + else + break; + } + // ?h?? +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + if (_partyTbl[i] >= 0) + { + if (party[_partyTbl[i]].id != pc.id) + _charMove(party[_partyTbl[i]].ptAct); + else + { + //mapMove2(); + _mapMove(); + } + } + else + break; + } + updateMapArea(); + viewPointX = nowX; + viewPointY = nowY; +} + +/////////////////////////////////////////////////////////////////////////// +// ?????hI?@e +void _setMapMovePoint(int _nextGx, int _nextGy) +{ + float dx, dy, len, dir1; + int dir; + + nextGx = _nextGx; + nextGy = _nextGy; + // ?h????? + dx = nextGx * GRID_SIZE - nowX; + dy = nextGy * GRID_SIZE - nowY; + len = (float)sqrt((double)(dx * dx + dy * dy)); + if (len > 0) + { + dx /= len; + dy /= len; + } + else + { + dx = 0; + dy = 0; + } + nowVx = dx * MOVE_SPEED; + nowVy = dy * MOVE_SPEED; + // PC?????@e + if (dx != 0 || dy != 0) + { + dir1 = Atan(dx, dy) + 22.5F; + AdjustDir(&dir1); + dir = (int)(dir1 / 45); + setPcDir(dir); + setPcWalkFlag(); + } + // PC?????????t?i??? + setPcPoint(); +} + +/////////////////////////////////////////////////////////////////////////// +// ???????????h???? +// ???????????????@e???? +void setPcMovePointToChar(int gx, int gy) +{ + if (partyModeFlag != 0 && (pc.status & CHR_STATUS_LEADER) != 0) + { + if (_partyTbl[1] >= 0) + stockCharMovePoint(party[_partyTbl[1]].ptAct, gx, gy); + } +} + +/////////////////////////////////////////////////////////////////////////// +// ???????????h???\??????h??? +void setPartyMovePoint(void) +{ + int i; + ACTION *ptAct, *ptActNext; + + if (partyModeFlag != 0 && (pc.status & CHR_STATUS_LEADER) != 0) + { +#ifdef MAX_AIRPLANENUM + for (i = 1; i < MAX_AIRPLANENUM; i++) +#else + for (i = 1; i < MAX_PARTY; i++) +#endif + { + if (_partyTbl[i] >= 0) + { + ptAct = party[_partyTbl[i]].ptAct; + + // ??????????? + if ((float)ptAct->nextGx * GRID_SIZE == ptAct->mx && (float)ptAct->nextGy * GRID_SIZE == ptAct->my) + { + // ?????????????@e + if (ptAct->bufCount > 0) + { + setCharMovePoint(ptAct, ptAct->bufGx[0], ptAct->bufGy[0]); + shiftBufCount(ptAct); + // ?????????J? +#ifdef MAX_AIRPLANENUM + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_AIRPLANENUM) +#else + if (_partyTbl[i + 1] >= 0 && (i + 1) < MAX_PARTY) +#endif + { + ptActNext = party[_partyTbl[i + 1]].ptAct; + stockCharMovePoint(ptActNext, ptAct->gx, ptAct->gy); + } + } + } + } + else + break; + } + } +} + +/////////////////////////////////////////////////////////////////////////// +// ?h?? +void _mapMove(void) +{ + float nGx, nGy, vx, vy; + + if (nowVx != 0 || nowVy != 0) + { + nGx = (float)nextGx * GRID_SIZE; + nGy = (float)nextGy * GRID_SIZE; + + vx = nowVx * nowSpdRate; + vy = nowVy * nowSpdRate; + // ?????????h????????? + if (pointLen2(nowX, nowY, nGx, nGy) <= vx * vx + vy * vy) + { + // ?????????????? + nowX = nGx; + nowY = nGy; + nowVx = 0; + nowVy = 0; + justGoalFlag = 1; // ??????? + } + else + { + // ?h + nowX += vx; + nowY += vy; + } + + + setPcAction(ANIM_WALK); + setPcWalkFlag(); + + if (pc.ptAct != NULL) + mapEffectMoveDir = pc.ptAct->anim_ang; + } + else + { + // PC????????????WALK???????????STAND??? + if (checkPcWalkFlag() == 1) + { + setPcAction(ANIM_STAND); + delPcWalkFlag(); + } + mapEffectMoveDir = -1; + } +#ifdef _MOVE_SCREEN + if (!pc.bMoveScreenMode) +#endif + { + nowGx = (int)(nowX / GRID_SIZE); + nowGy = (int)(nowY / GRID_SIZE); + } + // PC?????????t?i??? + setPcPoint(); +} + +/////////////////////////////////////////////////////////////////////////// +// ??????????????? +void _partyMapMove(void) +{ + int i; + + // ???????????h???\??????h?? + if (partyModeFlag != 0 && (pc.status & CHR_STATUS_LEADER) != 0) + { +#ifdef MAX_AIRPLANENUM + for (i = 1; i < MAX_AIRPLANENUM; i++) +#else + for (i = 1; i < MAX_PARTY; i++) +#endif + { + if (_partyTbl[i] >= 0) + charMove2(party[_partyTbl[i]].ptAct); + else + break; + } + } +} + +/////////////////////////////////////////////////////////////////////////// +// ?????ѩ???? +void getPartyTbl(void) +{ + int i, j; + + if (partyModeFlag != 0) + { +#ifdef MAX_AIRPLANENUM + // ??????? + for (i = 0; i < MAX_AIRPLANENUM; i++) + _partyTbl[i] = -1; + // ?????k??????? + for (i = 0, j = 0; i < MAX_AIRPLANENUM; i++) +#else + // ??????? + for (i = 0; i < MAX_PARTY; i++) + _partyTbl[i] = -1; + // ?????k??????? + for (i = 0, j = 0; i < MAX_PARTY; i++) +#endif + { + if (party[i].useFlag != 0 && party[i].ptAct != NULL) + { + _partyTbl[j] = i; + j++; + } + } + } +} + +/////////////////////////////////////////////////////////////////////////// +// ??????????? +enum +{ + etcEventMode_None, + etcEventMode_Warp, + etcEventMode_LocalEncount, + etcEventMode_Enemy +}; + +BOOL _etcEventFlag = FALSE; +short _etcEventStep = 0; +short _etcEventMode = etcEventMode_None; +short _eventWarpNo; + +void _etcEventCheck(void) +{ + int i, dir, gx, gy, ogx, ogy; + BOOL breakFlag; + float tmpDir; + + gx = nowGx; + gy = nowGy; + ogx = gx; + ogy = gy; + breakFlag = FALSE; + + for (i = 0; i < moveRouteCnt2; i++) + { + gx += moveAddTbl[moveRoute2[i]][0]; + gy += moveAddTbl[moveRoute2[i]][1]; + tmpDir = Atan((float)(gx - ogx), (float)(gy - ogy)) + 22.5F; + AdjustDir(&tmpDir); + dir = (int)(tmpDir / 45); + + if (_checkEnemyEvent(gx, gy)) + { + _etcEventFlag = TRUE; + _etcEventStep = i; + _etcEventMode = etcEventMode_Enemy; + _enemyEventDir = dir - 3; + if (_enemyEventDir < 0) + _enemyEventDir += 8; + i--; + breakFlag = TRUE; + break; + } + else if (_checkWarpEvent(gx, gy)) + { + _etcEventFlag = TRUE; + _etcEventStep = i + 1; + _etcEventMode = etcEventMode_Warp; + breakFlag = TRUE; + break; + } + else if (_checkEncount()) + { + //cary ɰ + if (!bNewServer) + { + _etcEventFlag = TRUE; + _etcEventStep = i + 1; + _etcEventMode = etcEventMode_LocalEncount; + breakFlag = TRUE; + } + break; + //end cary + } + ogx = gx; + ogy = gy; + } + if (i < MOVE_MAX2 && breakFlag) + { + moveRouteCnt2 = i + 1; + moveRouteCnt = 0; + } +} + +BOOL _execEtcEvent(void) +{ + if (_etcEventFlag) + { + if (justGoalFlag) + { + if (_etcEventStep > 0) + _etcEventStep--; + } + if (_etcEventStep <= 0) + { + switch (_etcEventMode) + { + case etcEventMode_Warp: + _sendWarpEvent(); + break; + case etcEventMode_LocalEncount: + //cary ɰ + if (!bNewServer) + _sendEncount(); + //end test + break; + case etcEventMode_Enemy: + _sendEnemyEvent(); + break; + } + _etcEventFlag = FALSE; + _etcEventStep = 0; + return TRUE; + } + } + return FALSE; +} + +void _getMoveRoute2(void) +{ + int i; + + for (i = 0; i < MOVE_MAX2 && moveRouteCnt > 0; i++) + { + moveRoute2[moveRouteCnt2] = moveRoute[0]; + moveRouteCnt2++; + shiftRouteMap(); + } +} + +void _sendMoveRoute(void) +{ + int i; + if (moveRouteCnt2 <= 0) + return; + + for (i = 0; i < moveRouteCnt2; i++) + moveRouteDir[i] = cnvServDir(moveRoute2[i], 0); + if (!offlineFlag) + { + if (partyModeFlag == 0 || (pc.status & CHR_STATUS_LEADER) != 0) + { + moveRouteDir[i] = '\0'; + +#ifdef MAP_CACHE_PROC + if (checkMapCache(nowGx, nowGy, moveRoute2, moveRouteCnt2, nowFloor, nowFloorGxSize, nowFloorGySize)) + noChecksumWalkSendForServer(nowGx, nowGy, moveRouteDir); + else + walkSendForServer(nowGx, nowGy, moveRouteDir); +#else + walkSendForServer(nowGx, nowGy, moveRouteDir); +#endif + } + } +} + +BOOL _checkEncount(void) +{ + BOOL ret = FALSE; + + if (EncountOffFlag) + return FALSE; + + if (partyModeFlag == 0 || (pc.status & CHR_STATUS_LEADER) != 0) + { + if (nowEncountPercentage > rand2()) + { + ret = TRUE; + nowEncountExtra = 0; + } + } + if (6 > nowEncountExtra) + nowEncountExtra++; + else + { + if (maxEncountPercentage > nowEncountPercentage) + nowEncountPercentage++; + } + + return ret; +} + +void _sendEncount(void) +{ + resetMap(); + sendEnFlag = 1; + etcEventFlag = 1; + eventEnemyFlag = 0; + + if (bNewServer) + lssproto_EN_send(sockfd, nowGx, nowGy); + else + old_lssproto_EN_send(sockfd, nowGx, nowGy); +} + +BOOL _checkWarpEvent(int gx, int gy) +{ + int x, y, timeZoneNo; + + x = gx - mapAreaX1; + y = gy - mapAreaY1; + timeZoneNo = getLSTime (&SaTime); + _eventWarpNo = (event[y * mapAreaWidth + x] & 0x0fff); + // ??? + if (_eventWarpNo == EVENT_WARP) + return TRUE; + // ????? + else if (_eventWarpNo == EVENT_WARP_MONING && timeZoneNo == LS_MORNING) + return TRUE; + // ?????? + else if (_eventWarpNo == EVENT_WARP_NOON && (timeZoneNo == LS_NOON || timeZoneNo == LS_EVENING)) + return TRUE; + // ?????? + else if (_eventWarpNo == EVENT_WARP_NIGHT && timeZoneNo == LS_NIGHT) + return TRUE; + + return FALSE; +} + +void _sendWarpEvent(void) +{ + resetMap(); + eventWarpSendFlag = 1; + etcEventFlag = 1; + eventWarpSendId = eventId; + if (bNewServer) + lssproto_EV_send(sockfd, _eventWarpNo, eventId, nowGx, nowGy, -1); + else + old_lssproto_EV_send(sockfd, _eventWarpNo, eventId, nowGx, nowGy, -1); + eventId++; + wnCloseFlag = 1; // [????????? +#ifdef __AI + void AI_CloseWnd(); +// AI_CloseWnd(); +#endif + closeEtcSwitch(); // ?@e??????? + closeCharActionAnimeChange(); // ????????????? + closeJoinChannelWN(); + // ????? + + SubProcNo = 200; + // ??????? + warpEffectProc(); + warpEffectFlag = TRUE; + floorChangeFlag = TRUE; + // ????????????????? + if (MenuToggleFlag & JOY_CTRL_M) + MapWmdFlagBak = TRUE; +} + +/////////////////////////////////////////////////////////////////////////// +// ?e???????????? +// +// ???????? +BOOL _checkEnemyEvent(int gx, int gy) +{ + int x, y, ev; + + x = gx - mapAreaX1; + y = gy - mapAreaY1; + + ev = (event[y * mapAreaWidth + x] & 0x0fff); + // ?????? + if (ev == EVENT_ENEMY) + return TRUE; + + return FALSE; +} + +void _sendEnemyEvent(void) +{ + resetMap(); + eventEnemySendFlag = 1; + etcEventFlag = 1; + eventEnemySendId = eventId; + if (bNewServer) + lssproto_EV_send(sockfd, EVENT_ENEMY, eventId, nowGx, nowGy, _enemyEventDir); + else + old_lssproto_EV_send(sockfd, EVENT_ENEMY, eventId, nowGx, nowGy, _enemyEventDir); + eventId++; + wnCloseFlag = 1; + eventEnemyFlag = 1; +} + +void _checkEmptyMap(void) +{ + int dir, i, j, gx, gy; + + i = 0; + gx = nowGx; + gy = nowGy; + + dir = moveRoute2[i]; + if (checkEmptyMapData(gx, gy, dir)) + { + for (j = 0; j < getMapAreaCnt; j++) + { + if (bNewServer) + lssproto_M_send(sockfd, nowFloor, getMapAreaX1[j], getMapAreaY1[j], getMapAreaX2[j], getMapAreaY2[j]); + else + old_lssproto_M_send(sockfd, nowFloor, getMapAreaX1[j], getMapAreaY1[j], getMapAreaX2[j], getMapAreaY2[j]); + } + //mapEmptyFlag = TRUE; + mapEmptyDir = dir; + mapEmptyGx = nowGx; + mapEmptyGy = nowGy; + mapEmptyStartTime = TimeGetTime(); + } +} + +BOOL checkEmptyMapData(int _gx, int _gy, int dir) +{ + // ?????t???11??????????????TRUE?? + int i, gx, gy, tx, ty, len, egx, egy; + BOOL flag = FALSE; + + if (mapAreaWidth < MAP_X_SIZE || mapAreaHeight < MAP_Y_SIZE) + return FALSE; + + getMapAreaCnt = 0; + if (dir == 0 || dir == 1 || dir == 2) + { + gx = _gx - SEARCH_AREA; + gy = _gy - SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + egx = gx + 1; + egy = gy + (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if ((event[ty*mapAreaWidth+tx] & MAP_READ_FLAG) == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = egx; + getMapAreaY2[getMapAreaCnt] = egy; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gy++; + ty++; + } + } + if (dir == 2 || dir == 3 || dir == 4) + { + gx = _gx - SEARCH_AREA; + gy = _gy - SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + egx = gx + (SEARCH_AREA << 1) + 1; + egy = gy + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if ((event[ty*mapAreaWidth+tx] & MAP_READ_FLAG) == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = egx; + getMapAreaY2[getMapAreaCnt] = egy; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gx++; + tx++; + } + } + if (dir == 4 || dir == 5 || dir == 6) + { + gx = _gx + SEARCH_AREA; + gy = _gy - SEARCH_AREA; + tx = SEARCH_AREA - MAP_TILE_GRID_X1; + ty = -SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + egx = gx + 2; + egy = gy + (SEARCH_AREA << 1) + 1; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if ((event[ty*mapAreaWidth+tx] & MAP_READ_FLAG) == 0) + { + getMapAreaX1[getMapAreaCnt] = gx; + getMapAreaY1[getMapAreaCnt] = gy - 1; + getMapAreaX2[getMapAreaCnt] = egx; + getMapAreaY2[getMapAreaCnt] = egy; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gy++; + ty++; + } + } + if (dir == 6 || dir == 7 || dir == 0) + { + gx = _gx - SEARCH_AREA; + gy = _gy + SEARCH_AREA; + tx = -SEARCH_AREA - MAP_TILE_GRID_X1; + ty = SEARCH_AREA - MAP_TILE_GRID_Y1; + len = (SEARCH_AREA << 1) + 1; + egx = gx + (SEARCH_AREA << 1) + 1; + egy = gy + 2; + for (i = 0; i < len; i++) + { + if ((0 <= gx && gx < nowFloorGxSize) && (0 <= gy && gy < nowFloorGySize)) + { + if ((event[ty*mapAreaWidth+tx] & MAP_READ_FLAG) == 0) + { + getMapAreaX1[getMapAreaCnt] = gx - 1; + getMapAreaY1[getMapAreaCnt] = gy; + getMapAreaX2[getMapAreaCnt] = egx; + getMapAreaY2[getMapAreaCnt] = egy; + checkAreaLimit(&getMapAreaX1[getMapAreaCnt], &getMapAreaY1[getMapAreaCnt], &getMapAreaX2[getMapAreaCnt], &getMapAreaY2[getMapAreaCnt]); + getMapAreaCnt++; + flag = TRUE; + break; + } + } + gx++; + tx++; + } + } + + return flag; +} + +// ?????nok??????(x,y)??h? +// ???????q???? +void goFrontPartyCharacter(int no, int x, int y) +{ + int i, ox, oy; + ACTION *ptAct; + if(no <=0) return; + // ????ѩ?????????????? + if (party[0].ptAct == NULL) + return; + // ?????h????? + ptAct = party[0].ptAct; + if (ptAct->bufCount > 0 || (float)ptAct->nextGx*GRID_SIZE != ptAct->mx || (float)ptAct->nextGy*GRID_SIZE != ptAct->my) + return; + // I??????q???????????? + for (i = no-1; i >= 0; i--) + { +#ifdef MAX_AIRPLANENUM + if (i >= 0 && i < MAX_AIRPLANENUM){ +#else + if(i>=0 && i < MAX_PARTY ){ +#endif + if (party[i].useFlag && party[i].ptAct != NULL) + { + if (ABS(party[i].ptAct->nextGx - party[no].ptAct->nextGx) < 2 && ABS(party[i].ptAct->nextGy - party[no].ptAct->nextGy) < 2) + return; + i = -1; + break; + } + } + } + if (i >= 0) + return; + nowSpdRate = 1.0F; + i = no; +#ifdef MAX_AIRPLANENUM + while (i < MAX_AIRPLANENUM) +#else + while (i < MAX_PARTY) +#endif + { + if(i>=0){ + if (party[i].useFlag && party[i].ptAct != NULL) + { + ptAct = party[i].ptAct; + ox = party[i].ptAct->nextGx; + oy = party[i].ptAct->nextGy; + stockCharMovePoint(ptAct, x, y); + x = ox; + y = oy; + } + } + i++; + } +} + +// ?????hI?@e +void setMapMovePoint(int _nextGx, int _nextGy) +{ + float dx, dy, len, dir1, rate = 1.0F; + int dir; + + nextGx = _nextGx; + nextGy = _nextGy; + // ?h????? + dx = nextGx * GRID_SIZE - nowX; + dy = nextGy * GRID_SIZE - nowY; + len = (float)sqrt((double)(dx * dx + dy * dy)); + if (len > 0) + { + dx /= len; + dy /= len; + } + else + { + dx = 0; + dy = 0; + } + nowVx = dx * MOVE_SPEED * rate; + nowVy = dy * MOVE_SPEED * rate; + + // PC?????@e + if (dx != 0 || dy != 0) + { + dir1 = Atan(dx, dy) + 22.5F; + AdjustDir(&dir1); + dir = (int)(dir1 / 45); + setPcDir(dir); + setPcWalkFlag(); + } + // PC?????????t?i??? + setPcPoint(); +} + +// ?????hI?@e??L????? +void setMapMovePoint2(int _nextGx, int _nextGy) +{ + float dx, dy, len, dir1, rate = 1.0F; + int dir; + + if (pc.ptAct != NULL) + { + if (pc.ptAct->bufCount > 5) + rate = 2.0F; + else if (pc.ptAct->bufCount >= 4) + rate = 1.6F; + else if (pc.ptAct->bufCount >= 2) + rate = 1.2F; + } + + nextGx = _nextGx; + nextGy = _nextGy; + // ?h????? + dx = nextGx * GRID_SIZE - nowX; + dy = nextGy * GRID_SIZE - nowY; + len = (float)sqrt((double)(dx * dx + dy * dy)); + if (len > 0) + { + dx /= len; + dy /= len; + } + else + { + dx = 0; + dy = 0; + } + nowVx = dx * MOVE_SPEED * rate; + nowVy = dy * MOVE_SPEED * rate; + // PC?????@e + if (dx != 0 || dy != 0) + { + dir1 = Atan(dx, dy) + 22.5F; + AdjustDir(&dir1); + dir = (int)(dir1 / 45); + setPcDir(dir); + setPcWalkFlag(); + } + // PC?????????t?i??? + setPcPoint(); +} + +// ????h?? +void mapMove2(void) +{ + float dx, dy; + + // ?h??? + if (nowVx != 0 || nowVy != 0) + { + // ?????????????? + dx = (float)nextGx * GRID_SIZE; + dy = (float)nextGy * GRID_SIZE; + if (pointLen2(nowX, nowY, dx, dy) <= nowVx * nowVx + nowVy * nowVy) + { + nowX = dx; + nowY = dy; + nowVx = 0; + nowVy = 0; + } + // ?h + else + { + nowX += nowVx; + nowY += nowVy; + } + setPcAction(ANIM_WALK); + setPcWalkFlag(); + } + else + { + // PC????????????WALK???????????STAND??? + if (checkPcWalkFlag() == 1) + { + setPcAction(ANIM_STAND); + delPcWalkFlag(); + } + } + + nowGx = (int)(nowX / GRID_SIZE); + nowGy = (int)(nowY / GRID_SIZE); + // PC?????????t?i??? + setPcPoint(); +} + +/////////////////////////////////////////////////////////////////////////// +// ???????? +// +void turnAround(void) +{ + float tmpDir, tmpX, tmpY; + int dir; + char dir2[2]; + static unsigned int turnSendTime = 0; + + // PC????????????? + if (pc.ptAct == NULL) + return; + // ?h?N???????? + if (nowVx != 0 || nowVy != 0) + return; + // ??????????????????? + if (etcSendFlag != 0 || etcEventFlag != 0) + return; + // ??????????? +#ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + { + tmpX = (float)((mouseMapGx + iScreenMoveX) - (nowGx - iScreenMoveX)); + tmpY = (float)((mouseMapGy + iScreenMoveY) - (nowGy - iScreenMoveY)); + } + else +#endif + { + tmpX = (float)(mouseMapGx - nowGx); + tmpY = (float)(mouseMapGy - nowGy); + } + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + dir = (int)(tmpDir / 45); + // ???i???????? + if (pc.ptAct->anim_ang == dir) + return; + // ?? + if (turnSendTime+FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + setPcDir(dir); + dir2[0] = cnvServDir(dir, 1); + dir2[1] = '\0'; + walkSendForServer(nowGx, nowGy, dir2); + turnSendTime = TimeGetTime(); + extern int Ҽ; + if(Ҽ){ + lssproto_AC_send(sockfd, nowGx, nowGy, 0); + setPcAction(0); + + } + + + } +} + +void turnAround2(int dir) +{ + char dir2[2]; + static unsigned int turnSendTime = 0; + + // ?????????????? + if (dir < 0 || 7 < dir) + return; + // PC????????????? + if (pc.ptAct == NULL) + return; + // ?h?N???????? + if (nowVx != 0 || nowVy != 0) + return; + // ??????????????????? + if (etcSendFlag != 0 || etcEventFlag != 0) + return; + // ???i???????? + if (pc.ptAct->anim_ang == dir) + return; + // ?? + if (turnSendTime + FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + setPcDir(dir); + dir2[0] = cnvServDir(dir, 1); + dir2[1] = '\0'; + walkSendForServer(nowGx, nowGy, dir2); + turnSendTime = TimeGetTime(); + } +} + +/////////////////////////////////////////////////////////////////////////// +// ?h????? +// +// ????dir??1?h?????????x?? +void getRouteData(int dir, int *x, int *y) +{ + switch (dir) + { + case 0: + *x = -1; + *y = 1; + break; + + case 1: + *x = -1; + *y = 0; + break; + + case 2: + *x = -1; + *y = -1; + break; + + case 3: + *x = 0; + *y = -1; + break; + + case 4: + *x = 1; + *y = -1; + break; + + case 5: + *x = 1; + *y = 0; + break; + + case 6: + *x = 1; + *y = 1; + break; + + case 7: + *x = 0; + *y = 1; + break; + + default: + *x = 0; + *y = 0; + break; + } +} + +// (gx1,gy1)??(gx2,gy2)???? +int getDirData(int gx1, int gy1, int gx2, int gy2) +{ + float tmpDir, tmpX, tmpY; + + // ?????? + tmpX = (float)(gx2 - gx1); + tmpY = (float)(gy2 - gy1); + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + + return (int)(tmpDir / 45); +} + +// (gx1,gy2)????(gx2,gy2)???????????? +// ??kTRUE ... ????? +BOOL checkGridAround(int gx1, int gy1, int gx2, int gy2) +{ + if (((gx1 == gx2) && ABS(gy2 - gy1) == 1) || (ABS(gx2 - gx1) == 1 && (gy1 == gy2)) || (ABS(gx2 - gx1) == 1 && ABS(gy2 - gy1) == 1)) + return TRUE; + + return FALSE; +} + +void getRouteMap(void) +{ + int mx = moveStackGx, my = moveStackGy, nowx = nowGx, nowy = nowGy, dir, dx, dy, targetDir, nowDir, checkDir1, checkDir2, i; + int dirTbl[] = { 0, 1, -1 }; + float tmpDir; + float tmpX, tmpY; + BOOL flag; + + moveLastDir = -1; + if (nowx == mx && nowy == my) + return; + tmpX = (float)(mx - nowx); + tmpY = (float)(my - nowy); + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + targetDir = (int)(tmpDir / 45); + + moveRouteCnt = 0; + + while (nowx != mx || nowy != my) + { + if (moveRouteCnt >= MOVE_MAX) + { + moveRouteCnt = 0; + return; + } + + tmpX = (float)(mx - nowx); + tmpY = (float)(my - nowy); + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + nowDir = (int)(tmpDir / 45); + checkDir1 = targetDir + 1; + checkDir1 &= 7; + checkDir2 = targetDir - 1; + checkDir2 &= 7; + if (nowDir != targetDir && nowDir != checkDir1 && nowDir != checkDir2) + break; + flag = TRUE; + for (i = 0; i < sizeof(dirTbl) / sizeof(int); i++) + { + dir = nowDir + dirTbl[i]; + dir &= 7; + checkDir1 = targetDir + 1; + checkDir1 &= 7; + checkDir2 = targetDir - 1; + checkDir2 &= 7; + if (dir != targetDir && dir != checkDir1 && dir != checkDir2) + continue; + getRouteData(dir, &dx, &dy); + if (checkHitMap(nowx+dx, nowy+dy)) + { + if ((nowx+dx) == mx && (nowy+dy) == my) + { + if ((dir % 2) == 0) + continue; + flag = TRUE; + break; + } + else + continue; + } + if ((dir % 2) == 0) + { + int dir2, dx2, dy2, dir3, dx3, dy3; + BOOL flag2, flag3; + + dir2 = dir + 1; + dir2 &= 7; + getRouteData(dir2, &dx2, &dy2); + dir3 = dir - 1; + dir3 &= 7; + getRouteData(dir3, &dx3, &dy3); + flag2 = checkHitMap(nowx + dx2, nowy + dy2); + flag3 = checkHitMap(nowx + dx3, nowy + dy3); + if (flag2 && flag3) + break; + if (flag2) + { + moveRoute[moveRouteCnt] = dir3; + moveRouteGx[moveRouteCnt] = nowx + dx3; + moveRouteGy[moveRouteCnt] = nowy + dy3; + moveRouteCnt++; + dx = (nowx + dx) - (nowx + dx3); + dy = (nowy + dy) - (nowy + dy3); + dir = getDirData(0, 0, dx, dy); + nowx += dx3; + nowy += dy3; + flag = FALSE; + break; + } + if (flag3) + { + moveRoute[moveRouteCnt] = dir2; + moveRouteGx[moveRouteCnt] = nowx + dx2; + moveRouteGy[moveRouteCnt] = nowy + dy2; + moveRouteCnt++; + dx = (nowx + dx) - (nowx + dx2); + dy = (nowy + dy) - (nowy + dy2); + dir = getDirData(0, 0, dx, dy); + nowx += dx2; + nowy += dy2; + flag = FALSE; + break; + } + } + flag = FALSE; + break; + } + if (flag) + break; + nowx += dx; + nowy += dy; + moveRoute[moveRouteCnt] = dir; + moveRouteGx[moveRouteCnt] = nowx; + moveRouteGy[moveRouteCnt] = nowy; + moveRouteCnt++; + } + dx = 0; + if (mx - nowx > 0) + dx = 1; + else if (mx - nowx < 0) + dx = -1; + if (dx != 0) + { + while (!checkHitMap(nowx + dx, nowy) && mx != nowx) + { + nowx += dx; + moveRoute[moveRouteCnt] = getDirData(0, 0, dx, 0); + moveRouteGx[moveRouteCnt] = nowx; + moveRouteGy[moveRouteCnt] = nowy; + moveRouteCnt++; + } + } + dy = 0; + if (my - nowy > 0) + dy = 1; + else if (my - nowy < 0) + dy = -1; + if (dy != 0) + { + while (!checkHitMap(nowx, nowy + dy) && my != nowy) + { + nowy += dy; + moveRoute[moveRouteCnt] = getDirData(0, 0, 0, dy); + moveRouteGx[moveRouteCnt] = nowx; + moveRouteGy[moveRouteCnt] = nowy; + moveRouteCnt++; + } + } + if (moveRouteCnt > 0 && (nowx != mx || nowy != my)) + { + tmpX = (float)(mx - nowx); + tmpY = (float)(my - nowy); + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + moveLastDir = (int)(tmpDir / 45); + } + + return; +} + +void shiftRouteMap(void) +{ + int i; + + if (moveRouteCnt <= 0) + return; + + moveRouteCnt--; + for (i = 0; i < moveRouteCnt; i++) + { + moveRoute[i] = moveRoute[i + 1]; + moveRouteGx[i] = moveRouteGx[i + 1]; + moveRouteGy[i] = moveRouteGy[i + 1]; + } +} + +void shiftRouteMap2(void) +{ + int i; + + if (moveRouteCnt2 <= 0) + return; + + moveRouteCnt2--; + for (i = 0; i < moveRouteCnt2; i++) + { + moveRoute2[i] = moveRoute2[i + 1]; + } +} + +char cnvServDir(int dir, int mode) +{ + char ret = 'f'; + + if (0 <= dir && dir <= 2) + { + if (mode == 0) + ret = 'f' + dir; + else + ret = 'F' + dir; + } + else if (dir < 8) + { + if (mode == 0) + ret = 'a' + dir - 3; + else + ret = 'A' + dir - 3; + } + + return ret; +} + +/////////////////////////////////////////////////////////////////////////// +// ?????????I???e? +// ??? +void initCharPartsPrio(void) +{ + charPrioCnt = 0; + charPrioBufTop.pre = NULL; + charPrioBufTop.next = NULL; +} + +// ??????????????? +void setPartsPrio(int graNo, int x, int y, int dx, int dy, float mx, float my, int dispPrio) +{ + int i; + CHAR_PARTS_PRIORITY *ptc, *prePtc; + BOOL flag; + + // ?????????? + if (charPrioCnt >= MAX_CHAR_PRIO_BUF) + return; + + // ????????????? + charPrioBuf[charPrioCnt].graNo = graNo; + charPrioBuf[charPrioCnt].x = x; + charPrioBuf[charPrioCnt].y = y; + charPrioBuf[charPrioCnt].dx = dx; + charPrioBuf[charPrioCnt].dy = dy; + charPrioBuf[charPrioCnt].mx = mx; + charPrioBuf[charPrioCnt].my = my; + if (dispPrio == 0) + charPrioBuf[charPrioCnt].type = CHAR_PARTS_PRIO_TYPE_ANI; + else + charPrioBuf[charPrioCnt].type = CHAR_PARTS_PRIO_TYPE_PARTS; + charPrioBuf[charPrioCnt].pre = NULL; + charPrioBuf[charPrioCnt].next = NULL; + charPrioBuf[charPrioCnt].depth = y; +#ifdef _SFUMATO + charPrioBuf[charPrioCnt].sfumato = 0; +#endif + if (charPrioCnt == 0) + addCharPartsPrio(&charPrioBufTop, &charPrioBuf[charPrioCnt]); + else + { + // ???K?????????? + flag = FALSE; + ptc = charPrioBufTop.next; + for (i = 0; i < charPrioCnt && ptc != NULL; i++, ptc = ptc->next) + { + if (ptc->type == CHAR_PARTS_PRIO_TYPE_CHAR) + { + if (checkPrioPartsVsChar(ptc, &charPrioBuf[charPrioCnt])) + { + insertCharPartsPrio(ptc, &charPrioBuf[charPrioCnt]); + flag = TRUE; + break; + } + } + prePtc = ptc; + } + if (!flag) + addCharPartsPrio(prePtc, &charPrioBuf[charPrioCnt]); + } + charPrioCnt++; +} + +// ???????????? +#ifdef _SFUMATO +void setCharPrio(int graNo, int x, int y, int dx, int dy, float mx, float my, int sfumato) +#else +void setCharPrio(int graNo, int x, int y, int dx, int dy, float mx, float my) +#endif +{ + int i; + CHAR_PARTS_PRIORITY *ptc, *prePtc; + BOOL flag; + + // ?????????? + if (charPrioCnt >= MAX_CHAR_PRIO_BUF) + return; + // ????????????? + charPrioBuf[charPrioCnt].graNo = graNo; + charPrioBuf[charPrioCnt].x = x; + charPrioBuf[charPrioCnt].y = y; + charPrioBuf[charPrioCnt].dx = dx; + charPrioBuf[charPrioCnt].dy = dy; + charPrioBuf[charPrioCnt].mx = mx; + charPrioBuf[charPrioCnt].my = my; + charPrioBuf[charPrioCnt].type = CHAR_PARTS_PRIO_TYPE_CHAR; + charPrioBuf[charPrioCnt].pre = NULL; + charPrioBuf[charPrioCnt].next = NULL; + charPrioBuf[charPrioCnt].depth = y; + +#ifdef _SFUMATO + charPrioBuf[charPrioCnt].sfumato = sfumato; +#endif + + if (charPrioCnt == 0) + addCharPartsPrio(&charPrioBufTop, &charPrioBuf[charPrioCnt]); + else + { + // ???K?????????? + flag = FALSE; + ptc = charPrioBufTop.next; + for (i = 0; i < charPrioCnt && ptc != NULL; i++, ptc = ptc->next) + { + if (charPrioBuf[charPrioCnt].depth > ptc->depth) + { + insertCharPartsPrio(ptc, &charPrioBuf[charPrioCnt]); + flag = TRUE; + break; + } + prePtc = ptc; + } + if (!flag) + addCharPartsPrio(prePtc, &charPrioBuf[charPrioCnt]); + } + charPrioCnt++; +} + +// ??????????I?????? +// ??k?????????q?? TRUE +BOOL checkPrioPartsVsChar(CHAR_PARTS_PRIORITY *ptc, CHAR_PARTS_PRIORITY *ptp) +{ + short hit, prioType; + S2 w, h; + + // ??I???e?????? + realGetPrioType(ptp->graNo, &prioType); + // ???Re?? + realGetHitFlag(ptp->graNo, &hit); + // ??Ģl? prioType == 3 ?????? + if (hit != 0 && prioType == 3) + return FALSE; + // ???? + // ???????? +/* if (329585 <= ptp->graNo && ptp->graNo <= 329590) + return FALSE;*/ + if (prioType == 1) + { + if (ptc->mx <= ptp->mx || ptc->my >= ptp->my) + return FALSE; + else + return TRUE; + } +#if 0 + // ???? + // ????i?????? + else if (prioType == 2) + { + // ??@e?????????? + if ((ptc->mx <= ptp->mx && ptc->my >= ptp->my) || (ptc->mx < ptp->mx-GRID_SIZE || ptc->my > ptp->my+GRID_SIZE)) + return FALSE; + else + return TRUE; + } +#endif + // ?????????????? +#if 1 + if (ptc->mx > ptp->mx && ptc->my < ptp->my) + return TRUE; + else + { + realGetHitPoints(ptp->graNo, &w, &h); + if (ptc->x > ptp->x) + { + // PC????D??? + if (ptp->y - (w - 1) * SURFACE_HEIGHT / 2 <= ptc->y) + return FALSE; + } + else if (ptc->x < ptp->x) + { + // PC????D??? + if (ptp->y - (h - 1) * SURFACE_HEIGHT / 2 <= ptc->y) + return FALSE; + } + else + { + if (ptp->y <= ptc->y) + return FALSE; + } + } +#else + realGetHitPoints(ptp->graNo, &w, &h); + if (ptc->x >= ptp->x) + { + // PC????D??? + if (ptp->y - (w - 1) * SURFACE_HEIGHT / 2 < ptc->y) + return FALSE; + } + else + { + // PC????D??? + if (ptp->y - (h - 1) * SURFACE_HEIGHT / 2 < ptc->y) + return FALSE; + } +#endif + + return TRUE; +} + +// pt1???pt2?V?? +void insertCharPartsPrio(CHAR_PARTS_PRIORITY *pt1, CHAR_PARTS_PRIORITY *pt2) +{ + if (pt1 == NULL || pt2 == NULL) + return; + + pt2->pre = pt1->pre; + pt2->next = pt1; + (pt1->pre)->next = pt2; + pt1->pre = pt2; +} + +// pt1????p2?D??? +void addCharPartsPrio(CHAR_PARTS_PRIORITY *pt1, CHAR_PARTS_PRIORITY *pt2) +{ + if (pt1 == NULL || pt2 == NULL) + return; + + pt2->pre = pt1; + pt2->next = pt1->next; + if (pt1->next != NULL) + (pt1->next)->pre = pt2; + pt1->next = pt2; +} + +// pt1??? +void delCharPartsPrio(CHAR_PARTS_PRIORITY *pt1) +{ + if (pt1 == NULL) + return; + // Id???????????? + if (pt1->pre == NULL) + return; + (pt1->pre)->next = pt1->next; + if (pt1->next != NULL) + (pt1->next)->pre = pt1->pre; +} + +// ?????? +void stockCharParts(void) +{ + int i; + CHAR_PARTS_PRIORITY *pt; + + pt = charPrioBufTop.next; + if (pt == NULL) + return; + + for (i = 0; i < charPrioCnt && pt != NULL; i++, pt = pt->next) + { + if (pt->type == CHAR_PARTS_PRIO_TYPE_ANI){ +#ifdef _SFUMATO + StockDispBuffer2(pt->x + pt->dx, pt->y + pt->dy, 0, pt->graNo, 0, pt->sfumato); +#else + StockDispBuffer2(pt->x + pt->dx, pt->y + pt->dy, 0, pt->graNo, 0); +#endif + }else{ +#ifdef _SFUMATO + StockDispBuffer2(pt->x + pt->dx, pt->y + pt->dy, DISP_PRIO_PARTS, pt->graNo, 0, pt->sfumato); +#else + StockDispBuffer2(pt->x + pt->dx, pt->y + pt->dy, DISP_PRIO_PARTS, pt->graNo, 0); +#endif + } +#if 0 + // ????? + if (pt->type == CHAR_PARTS_PRIO_TYPE_CHAR) + break; +#endif + } +} + +/////////////////////////////////////////////////////////////////////////// +// ?????? +// +#if 0 // ??????????????Re????? +// +// NPC????????????? +// ??????????????????? +// +// ??kTRUE ... ????D +// FALSE ... ??? +BOOL checkNpcEvent(int gx, int gy, int dx, int dy) +{ + int x, y, ev; + + x = gx - mapAreaX1; + y = gy - mapAreaY1; + + ev = (event[(y + dy) * mapAreaWidth + (x + dx)] & 0x0fff); + // ?hI?NPC + if (ev == EVENT_NPC) + { + // ?h??? + resetMap(); + return TRUE; + } + + return FALSE; +} +#endif + +/////////////////////////////////////////////////////////////////////////// +// ?????????? +// +void drawAutoMap(int x, int y) +{ + if (autoMappingInitFlag) + { + createAutoMap(nowFloor, nowGx, nowGy); + autoMappingInitFlag = FALSE; + } + DrawAutoMapping(x, y, (unsigned char *)autoMappingBuf, AUTO_MAPPING_W, AUTO_MAPPING_H); +} + +BOOL createAutoMap(int floor, int gx, int gy) +{ + FILE *fp; + char filename[255]; + int fWidth, fHeight, fOffset, mWidth, width, height, fx, fy, mx, my, len, len2, i, j; + int x1, y1, x2, y2, index; + unsigned short tile[AUTO_MAPPING_W*AUTO_MAPPING_H]; + unsigned short parts[AUTO_MAPPING_W*AUTO_MAPPING_H]; + unsigned short event[AUTO_MAPPING_W*AUTO_MAPPING_H]; + + memset(autoMappingBuf, 0, sizeof(autoMappingBuf)); + sprintf(filename, "map\\%d.dat", floor); + if ((fp = fopen(filename, "rb"))==NULL) + { + _mkdir("map"); + if ((fp = fopen(filename, "rb")) == NULL) + return FALSE; + } + + memset(tile, 0, sizeof(tile)); + memset(parts, 0, sizeof(parts)); + memset(event, 0, sizeof(event)); + fseek(fp, 0, SEEK_SET); + fread(&fWidth, sizeof(int), 1, fp); + fread(&fHeight, sizeof(int), 1, fp); + x1 = gx - (AUTO_MAPPING_W >> 1); + y1 = gy - (AUTO_MAPPING_H >> 1); + x2 = x1 + AUTO_MAPPING_W; + y2 = y1 + AUTO_MAPPING_H; + mWidth = x2 - x1; + width = mWidth; + height = y2 - y1; + mx = 0; + fx = x1; + if (x1 < 0) + { + width += x1; + fx = 0; + mx -= x1; + } + if (x2 > fWidth) + width -= (x2 - fWidth); + my = 0; + fy = y1; + if (y1 < 0) + { + height += y1; + fy = 0; + my -= y1; + } + if (y2 > fHeight) + height -= (y2 - fHeight); + + fOffset = sizeof(int) << 1; + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&tile[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&parts[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fOffset += sizeof(short) * (fWidth * fHeight); + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short) * len + fOffset, SEEK_SET); + fread(&event[len2], sizeof(short) * width, 1, fp); + len += fWidth; + len2 += mWidth; + } + fclose (fp); + // ???@e + for (i = 0; i < AUTO_MAPPING_H; i++) + { + for (j = 0; j < AUTO_MAPPING_W; j++) + { + // ??????????????????? + if (event[i * AUTO_MAPPING_W + j] & MAP_SEE_FLAG) + { + autoMappingBuf[i][j] = autoMapColorTbl[tile[i * AUTO_MAPPING_W + j]]; + } + } + } + // ???@e + for (i = 0; i < AUTO_MAPPING_H; i++) + { + for (j = 0; j < AUTO_MAPPING_W; j++) + { + // ??????????????????? + if (event[i*AUTO_MAPPING_W+j] & MAP_SEE_FLAG) + { + index = autoMapColorTbl[parts[i * AUTO_MAPPING_W + j]]; + if (index != 0) + { + U4 bmpNo; + S2 hit, hitX, hitY; + int k, l; + + realGetNo(parts[i * AUTO_MAPPING_W + j], &bmpNo); + // ???Re?? + realGetHitFlag(bmpNo, &hit); + // ???Re?????????@e + if (hit == 0) + { + realGetHitPoints(bmpNo, &hitX, &hitY); + for (k = 0; k < hitY; k++) + { + for (l = 0; l < hitX; l++) + { + if ((i - k) >= 0 && (j + l) < AUTO_MAPPING_W) + autoMappingBuf[i - k][j + l] = index; + } + } + } + else + autoMappingBuf[i][j] = index; + } + } + } + } + + return TRUE; +} + +/* +// ??????????? +void readAutoMapSeeFlag(void) +{ + FILE *fp; + char filename[255]; + int fWidth, fHeight, fOffset; + int mWidth; + int width, height; + int fx, fy; + int mx, my; + int len, len2; + int i, j; + int x1, y1, x2, y2; + + + // ???????? + sprintf_s(filename, "map\\%d.dat", nowFloor); + + // ???????? + if ((fp = fopen_s(filename, "rb"))==NULL) + { + return; + } + + memset(autoMapSeeFlagBuf, 0, sizeof(autoMapSeeFlagBuf)); + + fseek(fp, 0, SEEK_SET); + fread(&fWidth, sizeof(int), 1, fp); + fread(&fHeight, sizeof(int), 1, fp); + + x1 = nowGx - AUTO_MAPPING_SEE_W/2; + y1 = nowGy - AUTO_MAPPING_SEE_H/2; + x2 = x1 + AUTO_MAPPING_SEE_W; + y2 = y1 + AUTO_MAPPING_SEE_H; + + + mWidth = x2 - x1; + width = mWidth; + height = y2 - y1; + + mx = 0; + fx = x1; + if (x1 < 0) + { + width += x1; + fx = 0; + mx -= x1; + } + if (x2 > fWidth) + { + width -= (x2 - fWidth); + } + my = 0; + fy = y1; + if (y1 < 0) + { + height += y1; + fy = 0; + my -= y1; + } + if (y2 > fHeight) + { + height -= (y2 - fHeight); + } + + + fOffset = sizeof(int) * 2 + sizeof(short) * (fWidth * fHeight) * 2; + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short)*len+fOffset, SEEK_SET); + fread(&autoMapSeeFlagBuf[len2], sizeof(short)*width, 1, fp); + len += fWidth; + len2 += mWidth; + } + + fclose (fp); + + // G?????????????????????????? + for (i = 0; i < AUTO_MAPPING_SEE_H; i++) + { + for (j = 0; j < AUTO_MAPPING_SEE_W; j++) + { + autoMapSeeFlagBuf[i*AUTO_MAPPING_SEE_W+j] |= MAP_SEE_FLAG; + } + } + + autoMapSeeFloor = nowFloor; + autoMapSeeGx = nowGx; + autoMapSeeGy = nowGy; + + autoMapSeeFlag = TRUE; +} + + +// ???????????? +void writeAutoMapSeeFlag(void) +{ + FILE *fp; + char filename[255]; + int fWidth, fHeight, fOffset; + int mWidth; + int width, height; + int fx, fy; + int mx, my; + int len, len2; + int i; + int x1, y1, x2, y2; + + + // ?????????????????? + if (!autoMapSeeFlag) + return; + + autoMapSeeFlag = FALSE; + + // ???????? + sprintf_s(filename, "map\\%d.dat", autoMapSeeFloor); + + // ???????? + if ((fp = fopen_s(filename, "rb+"))==NULL) + { + return; + } + + + fseek(fp, 0, SEEK_SET); + fread(&fWidth, sizeof(int), 1, fp); + fread(&fHeight, sizeof(int), 1, fp); + + x1 = autoMapSeeGx - AUTO_MAPPING_SEE_W/2; + y1 = autoMapSeeGy - AUTO_MAPPING_SEE_H/2; + x2 = x1 + AUTO_MAPPING_SEE_W; + y2 = y1 + AUTO_MAPPING_SEE_H; + + mWidth = x2 - x1; + width = mWidth; + height = y2 - y1; + + mx = 0; + fx = x1; + if (x1 < 0) + { + width += x1; + fx = 0; + mx -= x1; + } + if (x2 > fWidth) + { + width -= (x2 - fWidth); + } + my = 0; + fy = y1; + if (y1 < 0) + { + height += y1; + fy = 0; + my -= y1; + } + if (y2 > fHeight) + { + height -= (y2 - fHeight); + } + + fOffset = sizeof(int) * 2 + sizeof(short) * (fWidth * fHeight) * 2; + len = fy * fWidth + fx; + len2 = my * mWidth + mx; + for (i = 0; i < height; i++) + { + fseek(fp, sizeof(short)*len+fOffset, SEEK_SET); + fwrite(&autoMapSeeFlagBuf[len2], sizeof(short)*width, 1, fp); + len += fWidth; + len2 += mWidth; + } + + fclose (fp); +} +*/ + + +/////////////////////////////////////////////////////////////////////////// +// ?????????? +#ifdef MAP_CACHE_PROC + + +// ??? +void initMapCache(void) +{ + int i; + + for (i = 0; i < MAX_MAP_CACHE_SIZE; i++) + { + mapCacheFloorNo[i] = -1; + mapCacheFloorGxSize[i] = 0; + mapCacheFloorGySize[i] = 0; + clearMapCacheFlag(i); + mapCacheLastTime[i] = 0; + } + mapCacheUse = 0; +} + +// ?hI???????????????????? +BOOL checkMapCache(int gx, int gy, short *buf, int size, int floor, int gxSize, int gySize) +{ + #define MAP_CACHE_RANGE 14 + #define MAP_CACHE_RANGE2 13 + int x1[2], y1[2], x2[2], y2[2]; + int tx1[2] = { 0xffff, 0xffff }; + int ty1[2] = { 0xffff, 0xffff }; + int tx2[2] = { 0, 0 }; + int ty2[2] = { 0, 0 }; + int dir, dx, dy, cnt, i, mask; + unsigned char bit, tbit; + + // ?h????????????d????? + tbit = 0; + for (cnt = 0; cnt < size; cnt++) + { + dir = buf[cnt]; + bit = 0; + if (0 <= dir && dir <= 2) + { + x1[0] = gx - MAP_CACHE_RANGE; + x2[0] = x1[0] + 1; + y1[0] = gy - MAP_CACHE_RANGE2; + y2[0] = gy + MAP_CACHE_RANGE2 + 1; + bit |= 1; + } + else if (4 <= dir && dir <= 6) + { + x1[0] = gx + MAP_CACHE_RANGE; + x2[0] = x1[0] + 1; + y1[0] = gy - MAP_CACHE_RANGE2; + y2[0] = gy + MAP_CACHE_RANGE2 + 1; + bit |= 1; + } + if (2 <= dir && dir <= 4) + { + x1[1] = gx - MAP_CACHE_RANGE2; + x2[1] = gx + MAP_CACHE_RANGE2 + 1; + y1[1] = gy - MAP_CACHE_RANGE; + y2[1] = y1[1] + 1; + bit |= 2; + } + else if (6 <= dir && dir <= 7 || dir == 0) + { + x1[1] = gx - MAP_CACHE_RANGE2; + x2[1] = gx + MAP_CACHE_RANGE2 + 1; + y1[1] = gy + MAP_CACHE_RANGE; + y2[1] = y1[1] + 1; + bit |= 2; + } + if ((bit & 1) != 0) + { + if (x1[0] < tx1[0]) + tx1[0] = x1[0]; + if (x2[0] > tx2[0]) + tx2[0] = x2[0]; + if (y1[0] < ty1[0]) + ty1[0] = y1[0]; + if (y2[0] > ty2[0]) + ty2[0] = y2[0]; + tbit |= 1; + } + if ((bit & 2) != 0) + { + if (x1[1] < tx1[1]) + tx1[1] = x1[1]; + if (x2[1] > tx2[1]) + tx2[1] = x2[1]; + if (y1[1] < ty1[1]) + ty1[1] = y1[1]; + if (y2[1] > ty2[1]) + ty2[1] = y2[1]; + tbit |= 2; + } + getRouteData(dir, &dx, &dy); + gx += dx; + gy += dy; + } + // ????d????????????? + bit = 0; + for (i = 0, mask = 1; i < 2; i++, mask <<= 1) + { + if ((tbit & mask) != 0) + { + if (checkMapCacheFlag(floor, gxSize, gySize, tx1[i], ty1[i], tx2[i], ty2[i])) + { + if (!checkMapCacheEvent(tx1[i], ty1[i], tx2[i], ty2[i])) + bit |= mask; + } + } + } + if (tbit == bit) + return TRUE; + else + return FALSE; +} + +// ??????? +void clearMapCacheFlag(int no) +{ + if (no < 0 || MAX_MAP_CACHE_SIZE <= no) + return; + memset(mapCacheFlag[no], 0, MAP_CACHE_X_BYTE*MAP_CACHE_Y_BYTE); +} + +// e?t??????????? +// ??kTRUE ... ???????? +// FALSE ... ???????? +BOOL checkMapCacheFlag(int floor, int gxSize, int gySize, int x1, int y1, int x2, int y2) +{ + int xByteStart, xByteEnd, yByteStart, yByteEnd, i, j; + unsigned char bits, mask; + BOOL ret = TRUE; + BOOL thisFloorCacheFlag = FALSE; + + // e????k??????? + j = mapCacheUse; + for (i = 0; i < MAX_MAP_CACHE_SIZE; i++) + { + if (mapCacheFloorNo[j] == floor) + { + // ??????? + mapCacheUse = j; + thisFloorCacheFlag = TRUE; + break; + } + j++; + if (j >= MAX_MAP_CACHE_SIZE) + j = 0; + } + // ???????? + if (!thisFloorCacheFlag) + { + BOOL flag; + unsigned int tmpTime; + + // ??????????????t?????????? + if (gxSize < 100 || gySize < 100) + return FALSE; + // ?????????????????S? + flag = FALSE; + for (i = 0; i < MAX_MAP_CACHE_SIZE; i++) + { + if (mapCacheFloorNo[i] == -1) + { + flag = TRUE; + break; + } + } + // ???????k????????? + if (!flag) + { + i = 0; + tmpTime = 0xffffffff; + for (j = 0; j < MAX_MAP_CACHE_SIZE; j++) + { + if (tmpTime > mapCacheLastTime[j]) + { + i = j; + tmpTime = mapCacheLastTime[j]; + } + } + } + // ?????K? + mapCacheUse = i; + mapCacheFloorNo[i] = floor; + mapCacheFloorGxSize[i] = gxSize; + mapCacheFloorGySize[i] = gySize; + clearMapCacheFlag(i); + ret = FALSE; + } + // ?????????????K? + mapCacheLastTime[mapCacheUse] = TimeGetTime(); + if (x1 < 0) + x1 = 0; + if (y1 < 0) + y1 = 0; + if (x2 > mapCacheFloorGxSize[mapCacheUse]) + x2 = mapCacheFloorGxSize[mapCacheUse]; + if (y2 > mapCacheFloorGySize[mapCacheUse]) + y2 = mapCacheFloorGySize[mapCacheUse]; + // ???d?? + if (x1 > x2 || y1 > y2) + return FALSE; + + xByteStart = x1 >> 3; // xByteStart = x1 / 8 + xByteEnd = x2 >> 3; // xByteEnd = x2 / 8; + yByteStart = y1; + yByteEnd = y2; + for (i = xByteStart; i <= xByteEnd; i++) + { + bits = 0xff; + if (i == xByteStart) + { + mask = ((unsigned char)0xff >> (x1 % 8)); + bits &= mask; + } + if (i == xByteEnd) + { + mask = ((unsigned char)0xff << (7 - (x1 % 8))); + bits &= mask; + } + for (j = yByteStart; j <= yByteEnd; j++) + { + if ((mapCacheFlag[mapCacheUse][j * MAP_CACHE_X_BYTE + i] & bits) != bits) + // ????????????? + ret = FALSE; + mapCacheFlag[mapCacheUse][j * MAP_CACHE_X_BYTE + i] |= bits; + } + } + + return ret; +} + +// ????ѩ?EVENT_ALTERRATIVE?????TRUE??? +BOOL checkMapCacheEvent(int x1, int y1, int x2, int y2) +{ + int x, y, w, h, i, j; + + // ????????d??????????? + // ??????????????? + if (x1 >= mapAreaX2 || x2 < 0 || y1 >= mapAreaY2 || y2 < 0) + return TRUE; + + w = x2 - x1; + h = y2 - y1; + x = x1 - mapAreaX1; + y = y1 - mapAreaY1; + if (x < 0) + { + w += x; + x = 0; + } + if (y < 0) + { + h += y; + y = 0; + } + if (mapAreaX1 + w > mapAreaX2) + w -= (mapAreaX1 + w - mapAreaX2); + if (mapAreaY1 + h > mapAreaY2) + h -= (mapAreaY1 + h - mapAreaY2); + for (i = 0; i < h; i++, y++) + { + for (j = 0; j < w; j++, x++) + { + if ((event[y * mapAreaWidth + x] & 0x0fff) == EVENT_ALTERRATIVE) + return TRUE; + } + } + + return FALSE; +} +#endif + +/////////////////////////////////////////////////////////////////////////// +// ???????? + +#define MAX_MAP_EFFECT_BUF 500 + +MAP_EFFECT masterBufMapEffect[MAX_MAP_EFFECT_BUF]; +MAP_EFFECT *emptyBufMapEffect; +MAP_EFFECT *useBufMapEffect; + +short mapEffectDrawFlag = 0; +short mapEffectRainLevel = 0; +short oldMapEffectRainLevel = 0; +short mapEffectRainCnt = 0; +short mapEffectSnowLevel = 0; +short oldMapEffectSnowLevel = 0; +short mapEffectSnowCnt = 0; +short mapEffectMoveDir = -1; +short mapEffectStarFlag = 0; +short mapEffectFallingStarFlag = 0; +int mapEffectFallingStarTime; +#ifdef _HALLOWEEN_EFFECT +int mapEffectHalloween = 0; +#endif +short mapEffectKamiFubukiLevel = 0; +//short oldMapEffectKamiFubukiLevel = 0; +short mapEffectKamiFubukiCnt = 0; +#ifdef __EDEN_DICE +BOOL bMapEffectDice = FALSE; +#endif + +// ???????????? +void initMapEffect(BOOL bFirstRun) +{ + int i; + + emptyBufMapEffect = &masterBufMapEffect[0]; + masterBufMapEffect[0].pre = (MAP_EFFECT *)NULL; + for (i = 1; i < MAX_MAP_EFFECT_BUF; i++) + { + masterBufMapEffect[i - 1].next = &masterBufMapEffect[i]; + masterBufMapEffect[i].pre = &masterBufMapEffect[i - 1]; +#ifdef _HALLOWEEN_EFFECT + if (bFirstRun) + masterBufMapEffect[i - 1].pAction = NULL; + else + { + if (masterBufMapEffect[i - 1].pAction) + { + DeathAction(masterBufMapEffect[i - 1].pAction); + masterBufMapEffect[i - 1].pAction = NULL; + } + } +#endif + } + masterBufMapEffect[i - 1].next = (MAP_EFFECT*)NULL; + useBufMapEffect = (MAP_EFFECT*)NULL; + mapEffectRainLevel = 0; + mapEffectRainCnt = 0; + mapEffectSnowLevel = 0; + mapEffectSnowCnt = 0; + mapEffectMoveDir = -1; + mapEffectStarFlag = 0; + mapEffectFallingStarFlag = 1; + mapEffectKamiFubukiLevel = 0; + mapEffectKamiFubukiCnt = 0; +#ifdef __EDEN_DICE + bMapEffectDice = FALSE; +#endif +#ifdef _HALLOWEEN_EFFECT + mapEffectHalloween = 0; +#endif +} + +// ??????????x?@e??? +MAP_EFFECT *getMapEffectBuf(void) +{ + MAP_EFFECT *buf; + + if (emptyBufMapEffect == (MAP_EFFECT *)NULL) + return (MAP_EFFECT*)NULL; + buf = emptyBufMapEffect; + emptyBufMapEffect = emptyBufMapEffect->next; + if (emptyBufMapEffect != (MAP_EFFECT*)NULL) + emptyBufMapEffect->pre = (MAP_EFFECT*)NULL; + buf->next = useBufMapEffect; + buf->pre = (MAP_EFFECT*)NULL; + if (useBufMapEffect != (MAP_EFFECT*)NULL) + useBufMapEffect->pre = buf; + useBufMapEffect = buf; + return buf; +} + +// ????????????? +void delMapEffectBuf(MAP_EFFECT *buf) +{ + if (buf == (MAP_EFFECT*)NULL) + return; + if (buf->pre != (MAP_EFFECT*)NULL) + buf->pre->next = buf->next; + if (buf->next != (MAP_EFFECT*)NULL) + buf->next->pre = buf->pre; + if (useBufMapEffect == buf) + useBufMapEffect = buf->next; + buf->next = emptyBufMapEffect; + buf->pre = (MAP_EFFECT*)NULL; + emptyBufMapEffect = buf; + buf->type = MAP_EFFECT_TYPE_NONE; +} + +// ?h??? +void mapEffectDirHosei(int *x, int *y) +{ + if (mapEffectMoveDir < 0) + return; + if (mapEffectMoveDir == 0) + (*y) -= 2; + else if (mapEffectMoveDir == 1) + { + (*x)++; + (*y)--; + } + else if (mapEffectMoveDir == 2) + (*x) += 2; + else if (mapEffectMoveDir == 3) + { + (*x)++; + (*y)++; + } + else if (mapEffectMoveDir == 4) + (*y) += 2; + else if (mapEffectMoveDir == 5) + { + (*x)--; + (*y)++; + } + else if (mapEffectMoveDir == 6) + (*x) -= 2; + else if (mapEffectMoveDir == 7) + { + (*x)--; + (*y)--; + } +} + +// sprdisp.cpp?PutBmp()????? +void drawMapEffect(void) +{ + if (mapEffectDrawFlag) + { + DrawMapEffect(); + mapEffectDrawFlag = 0; + } +} + +// ???????? +void mapEffectProc(void) +{ + mapEffectRain(); + mapEffectSnow(); + mapEffectStar(); + mapEffectFallingStar(); + mapEffectKamiFubuki(); +#ifdef __EDEN_DICE + mapEffectDice(); +#endif +#ifdef _HALLOWEEN_EFFECT + mapEffectHalloweenProc(); +#endif + if (transEffectPaletteStatus == 2 && transEffectPaletteAfterWaitTime == 0) + transEffectPaletteAfterWaitTime = GetTickCount(); + // ?????????r??V??????????? + else if (transEffectPaletteStatus == 2 && (GetTickCount() - transEffectPaletteAfterWaitTime) > 2500) + { + transEffectPaletteStatus = 0; + transEffectPaletteAfterWaitTime = 0; + } +} + +void mapEffectProc2(int n) +{ + mapEffectRain2(n); + mapEffectSnow2(n); +} + +// ??????? +void mapEffectRain(void) +{ + short mapEffectRainWaitTime = 0; + short mapEffectRainFrameMax = 0; + int hosei1 = 840, hosei2 = -200, ww = DEF_APPSIZEX, hh = DEF_APPSIZEY, i; + static unsigned int time = TimeGetTime(); + MAP_EFFECT *buf; + + // ??????????????? + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 370; + hosei2 = -50; + } + // ?D + if (mapEffectRainLevel) + { + if (mapEffectRainLevel < 3) + { + mapEffectRainWaitTime = (51 - 25 * mapEffectRainLevel); + if (time + mapEffectRainWaitTime < TimeGetTime()) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_RAIN; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->dx = 2 + (rand() % 2); + buf->dy = 9; + time = TimeGetTime(); + mapEffectRainCnt++; + } + } + } + else + { + mapEffectRainFrameMax = (mapEffectRainLevel - 2) << 2; + if (ResoMode == 1) + mapEffectRainFrameMax >>= 1; + for (i = 0; i < mapEffectRainFrameMax; i++) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_RAIN; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->dx = 2 + (rand() % 2); + buf->dy = 9; + time = TimeGetTime(); + mapEffectRainCnt++; + } + } + } + } + // ?h?? + buf = useBufMapEffect; + while (buf != (MAP_EFFECT *)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_RAIN) + { + buf->x += buf->dx; + buf->y += buf->dy; + mapEffectDirHosei(&buf->x, &buf->y); + if (ww <= buf->x || hh <= buf->y) + { + // ?h? + MAP_EFFECT *buf2 = buf->next; + delMapEffectBuf(buf); + buf = buf2; + mapEffectRainCnt--; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + } +} + +// D?????? +void mapEffectSnow(void) +{ + short mapEffectSnowWaitTime = 0; + short mapEffectSnowFrameMax = 0; + int hosei1 = 940; + int hosei2 = -200; + int ww = DEF_APPSIZEX; + int hh = DEF_APPSIZEY; + static unsigned int time = TimeGetTime(); + MAP_EFFECT *buf; + int i, j; + // ??????????????? + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 370; + hosei2 = -50; + } + // DD + if (mapEffectSnowLevel) + { + if (mapEffectSnowLevel < 3) + { + mapEffectSnowWaitTime = (51 - 25 * mapEffectSnowLevel); + if (time + mapEffectSnowWaitTime < TimeGetTime()) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_SNOW; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 2); + j = (rand() % 2); + if (j == 0) + { + buf->dx = 0 + (rand() % 2); + buf->dy = 3 + (rand() % 2); + } + else if (j == 1) + { + buf->dx = 1; + buf->dy = 4 + (rand() % 2); + } + time = TimeGetTime(); + mapEffectSnowCnt++; + } + } + } + else + { + mapEffectSnowFrameMax = (mapEffectSnowLevel - 2) << 1; + if (ResoMode == 1) + mapEffectSnowFrameMax >>= 1; + for (i = 0; i < mapEffectSnowFrameMax; i++) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_SNOW; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 2); + j = (rand() % 2); + if (j == 0) + { + buf->dx = 0 + (rand() % 2); + buf->dy = 3 + (rand() % 2); + } + else if (j == 1) + { + buf->dx = 1; + buf->dy = 4 + (rand() % 2); + } + time = TimeGetTime(); + mapEffectSnowCnt++; + } + } + } + } + // ?h?? + buf = useBufMapEffect; + while (buf != (MAP_EFFECT*)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_SNOW) + { + buf->x += buf->dx; + buf->y += buf->dy; + mapEffectDirHosei(&buf->x, &buf->y); + if (ww + 100 <= buf->x || hh <= buf->y) + { + // ?h? + MAP_EFFECT *buf2 = buf->next; + delMapEffectBuf(buf); + buf = buf2; + mapEffectSnowCnt--; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + } +} + +// ?????????e? +void setEffectStar(MAP_EFFECT *buf, int gx, int gy, int ggx, int ggy, int type) +{ + if (buf) + { + buf->type = MAP_EFFECT_TYPE_STAR; + buf->gx = gx; + buf->gy = gy; + buf->ggx = ggx; + buf->ggy = ggy; + buf->type2 = type; + } +} + +void calEffectStar(MAP_EFFECT *buf) +{ + float mx, my; + // ??t + camMapToGamen((float)buf->gx * GRID_SIZE, (float)buf->gy * GRID_SIZE, &mx, &my); + buf->x = (int)(mx + .5) + buf->ggx; + buf->y = (int)(my + .5) + buf->ggy; + //??????????????? + if (ResoMode == 1) + { + buf->x >>= 1; + buf->y >>= 1; + } +} + +void mapEffectStar(void) +{ + static MAP_EFFECT *buf[30]; + int i; + + if ((nowFloor == 1200 || nowFloor == 20105 || nowFloor == 10920 || nowFloor == 20406) + && NOON_TO_EVENING + 10 <= SaTime.hour && SaTime.hour < NIGHT_TO_MORNING + 80) + { + if (nowFloor == 1200 && mapEffectStarFlag == 0) + { + for (i = 0; i < sizeof(buf) / sizeof(void*); i++) + buf[i] = NULL; + buf[0] = getMapEffectBuf(); + setEffectStar(buf[0], 62, 28, 0, 0, 0); + buf[1] = getMapEffectBuf(); + setEffectStar(buf[1], 63, 27, -5, -5, 1); + buf[2] = getMapEffectBuf(); + setEffectStar(buf[2], 63, 28, 16, -10, 0); + buf[3] = getMapEffectBuf(); + setEffectStar(buf[3], 63, 29, 10, 5, 1); + buf[4] = getMapEffectBuf(); + setEffectStar(buf[4], 64, 29, 0, -8, 1); + + buf[5] = getMapEffectBuf(); + setEffectStar(buf[5], 65, 29, -8, 5, 0); + buf[6] = getMapEffectBuf(); + setEffectStar(buf[6], 65, 30, 16, 10, 0); + buf[7] = getMapEffectBuf(); + setEffectStar(buf[7], 66, 31, 0, 0, 1); + buf[8] = getMapEffectBuf(); + setEffectStar(buf[8], 66, 30, 8, -12, 1); + buf[9] = getMapEffectBuf(); + setEffectStar(buf[9], 67, 31, 20, 0, 0); + + buf[10] = getMapEffectBuf(); + setEffectStar(buf[10], 69, 34, -8, -8, 0); + buf[11] = getMapEffectBuf(); + setEffectStar(buf[11], 70, 34, 5, 10, 1); + buf[12] = getMapEffectBuf(); + setEffectStar(buf[12], 70, 35, 2, 24, 0); + buf[13] = getMapEffectBuf(); + setEffectStar(buf[13], 70, 36, -20, -16, 1); + buf[14] = getMapEffectBuf(); + setEffectStar(buf[14], 71, 36, 2, 4, 1); + + buf[15] = getMapEffectBuf(); + setEffectStar(buf[15], 71, 37, 5, -10, 1); + buf[16] = getMapEffectBuf(); + setEffectStar(buf[16], 72, 37, 0, 12, 0); + + mapEffectStarFlag = 1; + } + else if (nowFloor == 20105 && mapEffectStarFlag == 0) + { + for (i = 0; i < sizeof(buf) / sizeof(void*); i++) + buf[i] = NULL; + buf[0] = getMapEffectBuf(); + setEffectStar(buf[0], 21, 8, 5, 0, 1); + buf[1] = getMapEffectBuf(); + setEffectStar(buf[1], 20, 10, -5, 5, 1); + buf[2] = getMapEffectBuf(); + setEffectStar(buf[2], 18, 11, 5, 10, 0); + buf[3] = getMapEffectBuf(); + setEffectStar(buf[3], 20, 12, 0, -5, 1); + buf[4] = getMapEffectBuf(); + setEffectStar(buf[4], 23, 11, 0, 0, 0); + + buf[5] = getMapEffectBuf(); + setEffectStar(buf[5], 23, 14, 0, 0, 0); + buf[6] = getMapEffectBuf(); + setEffectStar(buf[6], 25, 13, 8, 6, 1); + buf[7] = getMapEffectBuf(); + setEffectStar(buf[7], 25, 16, 0, 0, 1); + buf[8] = getMapEffectBuf(); + setEffectStar(buf[8], 26, 18, 4, -8, 0); + buf[9] = getMapEffectBuf(); + setEffectStar(buf[9], 28, 16, -16, 0, 0); + + buf[10] = getMapEffectBuf(); + setEffectStar(buf[10], 21, 14, -5, 0, 1); + buf[11] = getMapEffectBuf(); + setEffectStar(buf[11], 27, 14, 0, 0, 1); + buf[12] = getMapEffectBuf(); + setEffectStar(buf[12], 24, 15, 4, -10, 1); + buf[13] = getMapEffectBuf(); + setEffectStar(buf[13], 28, 12, 5, -8, 0); + buf[14] = getMapEffectBuf(); + setEffectStar(buf[14], 32, 14, 0, 0, 0); + + buf[15] = getMapEffectBuf(); + setEffectStar(buf[15], 30, 17, 0, 0, 0); + buf[16] = getMapEffectBuf(); + setEffectStar(buf[16], 32, 19, 0, 0, 1); + buf[17] = getMapEffectBuf(); + setEffectStar(buf[17], 36, 19, 5, 2, 1); + buf[18] = getMapEffectBuf(); + setEffectStar(buf[18], 34, 22, -4, 4, 0); + buf[19] = getMapEffectBuf(); + setEffectStar(buf[19], 36, 25, 1, 1, 0); + + buf[20] = getMapEffectBuf(); + setEffectStar(buf[20], 39, 23, 0, 0, 0); + buf[21] = getMapEffectBuf(); + setEffectStar(buf[21], 38, 25, -8, 2, 1); + buf[22] = getMapEffectBuf(); + setEffectStar(buf[22], 40, 24, -5, -5, 1); + buf[23] = getMapEffectBuf(); + setEffectStar(buf[23], 39, 27, 0, 0, 0); + buf[24] = getMapEffectBuf(); + setEffectStar(buf[24], 39, 30, 0, 0, 1); + + buf[25] = getMapEffectBuf(); + setEffectStar(buf[25], 43, 29, 0, 0, 0); + buf[26] = getMapEffectBuf(); + setEffectStar(buf[26], 42, 32, 2, 0, 0); + buf[27] = getMapEffectBuf(); + setEffectStar(buf[27], 44, 33, 0, 0, 1); + buf[28] = getMapEffectBuf(); + setEffectStar(buf[28], 43, 34, 8, 2, 0); + buf[29] = getMapEffectBuf(); + setEffectStar(buf[29], 45, 36, 0, 0, 0); + + mapEffectStarFlag = 1; + } + else if (nowFloor == 10920 && mapEffectStarFlag == 0) + { + for (i = 0; i < sizeof(buf) / sizeof(void *); i++) + buf[i] = NULL; + buf[0] = getMapEffectBuf(); + setEffectStar(buf[0], 71, 2, 0, 0, 1); + buf[1] = getMapEffectBuf(); + setEffectStar(buf[1], 71, 5, 0, 0, 0); + buf[2] = getMapEffectBuf(); + setEffectStar(buf[2], 70, 7, 0, 0, 1); + buf[3] = getMapEffectBuf(); + setEffectStar(buf[3], 73, 7, 0, 0, 1); + buf[4] = getMapEffectBuf(); + setEffectStar(buf[4], 75, 6, 0, 0, 0); + + buf[5] = getMapEffectBuf(); + setEffectStar(buf[5], 75, 9, 0, 0, 0); + buf[6] = getMapEffectBuf(); + setEffectStar(buf[6], 75, 11, 0, 0, 1); + buf[7] = getMapEffectBuf(); + setEffectStar(buf[7], 77, 9, 0, 0, 1); + buf[8] = getMapEffectBuf(); + setEffectStar(buf[8], 76, 13, 0, 0, 0); + buf[9] = getMapEffectBuf(); + setEffectStar(buf[9], 79, 12, 0, 0, 0); + + buf[10] = getMapEffectBuf(); + setEffectStar(buf[10], 78, 15, 0, 0, 1); + buf[11] = getMapEffectBuf(); + setEffectStar(buf[11], 80, 14, 0, 0, 0); + buf[12] = getMapEffectBuf(); + setEffectStar(buf[12], 79, 16, 0, 0, 1); + buf[13] = getMapEffectBuf(); + setEffectStar(buf[13], 80, 18, 0, 0, 0); + buf[14] = getMapEffectBuf(); + setEffectStar(buf[14], 83, 18, 0, 0, 0); + + buf[15] = getMapEffectBuf(); + setEffectStar(buf[15], 83, 20, 0, 0, 1); + buf[16] = getMapEffectBuf(); + setEffectStar(buf[16], 84, 20, 0, 0, 1); + buf[17] = getMapEffectBuf(); + setEffectStar(buf[17], 84, 22, 0, 0, 0); + buf[18] = getMapEffectBuf(); + setEffectStar(buf[18], 85, 19, 0, 0, 0); + buf[19] = getMapEffectBuf(); + setEffectStar(buf[19], 87, 20, 0, 0, 1); + + buf[20] = getMapEffectBuf(); + setEffectStar(buf[20], 89, 21, 0, 0, 0); + buf[21] = getMapEffectBuf(); + setEffectStar(buf[21], 89, 23, 0, 0, 1); + buf[22] = getMapEffectBuf(); + setEffectStar(buf[22], 89, 26, 0, 0, 1); + buf[23] = getMapEffectBuf(); + setEffectStar(buf[23], 91, 25, 0, 0, 0); + buf[24] = getMapEffectBuf(); + setEffectStar(buf[24], 91, 27, 0, 0, 1); + + buf[25] = getMapEffectBuf(); + setEffectStar(buf[25], 93, 26, 0, 0, 1); + buf[26] = getMapEffectBuf(); + setEffectStar(buf[26], 93, 30, 0, 0, 0); + + mapEffectStarFlag = 1; + } + else if (nowFloor == 20406 && mapEffectStarFlag == 0) + { + for (i = 0; i < sizeof(buf) / sizeof(void *); i++) + buf[i] = NULL; + buf[0] = getMapEffectBuf(); + setEffectStar(buf[0], 16, 8, 0, 0, 1); + buf[1] = getMapEffectBuf(); + setEffectStar(buf[1], 16, 10, 0, 0, 0); + buf[2] = getMapEffectBuf(); + setEffectStar(buf[2], 18, 10, 0, 0, 0); + buf[3] = getMapEffectBuf(); + setEffectStar(buf[3], 19, 12, 0, 0, 1); + buf[4] = getMapEffectBuf(); + setEffectStar(buf[4], 20, 12, 0, 0, 1); + + buf[5] = getMapEffectBuf(); + setEffectStar(buf[5], 21, 14, 0, 0, 0); + buf[6] = getMapEffectBuf(); + setEffectStar(buf[6], 22, 16, 0, 0, 0); + buf[7] = getMapEffectBuf(); + setEffectStar(buf[7], 23, 16, 0, 0, 1); + buf[8] = getMapEffectBuf(); + setEffectStar(buf[8], 22, 11, 0, 0, 0); + buf[9] = getMapEffectBuf(); + setEffectStar(buf[9], 26, 15, 0, 0, 0); + + buf[10] = getMapEffectBuf(); + setEffectStar(buf[10], 25, 18, 0, 0, 1); + buf[11] = getMapEffectBuf(); + setEffectStar(buf[11], 26, 17, 0, 0, 1); + buf[12] = getMapEffectBuf(); + setEffectStar(buf[12], 27, 13, 0, 0, 0); + buf[13] = getMapEffectBuf(); + setEffectStar(buf[13], 29, 14, 0, 0, 1); + buf[14] = getMapEffectBuf(); + setEffectStar(buf[14], 29, 12, 0, 0, 1); + + buf[15] = getMapEffectBuf(); + setEffectStar(buf[15], 31, 17, 0, 0, 0); + buf[16] = getMapEffectBuf(); + setEffectStar(buf[16], 31, 19, 0, 0, 1); + buf[17] = getMapEffectBuf(); + setEffectStar(buf[17], 34, 18, 0, 0, 1); + buf[18] = getMapEffectBuf(); + setEffectStar(buf[18], 33, 21, 0, 0, 1); + buf[19] = getMapEffectBuf(); + setEffectStar(buf[19], 34, 23, 0, 0, 0); + + buf[20] = getMapEffectBuf(); + setEffectStar(buf[20], 38, 26, 0, 0, 0); + buf[21] = getMapEffectBuf(); + setEffectStar(buf[21], 41, 25, 0, 0, 1); + buf[22] = getMapEffectBuf(); + setEffectStar(buf[22], 41, 26, 0, 0, 1); + buf[23] = getMapEffectBuf(); + setEffectStar(buf[23], 41, 32, 0, 0, 0); + buf[24] = getMapEffectBuf(); + setEffectStar(buf[24], 44, 31, 0, 0, 0); + + buf[25] = getMapEffectBuf(); + setEffectStar(buf[25], 44, 33, 0, 0, 0); + buf[26] = getMapEffectBuf(); + setEffectStar(buf[26], 42, 43, 0, 0, 1); + buf[27] = getMapEffectBuf(); + setEffectStar(buf[27], 45, 36, 0, 0, 0); + buf[28] = getMapEffectBuf(); + setEffectStar(buf[28], 38, 21, 0, 0, 0); + buf[29] = getMapEffectBuf(); + setEffectStar(buf[29], 37, 19, 0, 0, 1); + + mapEffectStarFlag = 1; + } + for (i = 0; i < sizeof(buf) / sizeof(void*); i++) + { + if (buf[i]) + { + calEffectStar(buf[i]); + // ???? + // ??? + if (SaTime.hour < NOON_TO_EVENING + 20 || NIGHT_TO_MORNING + 70 < SaTime.hour) + buf[i]->mode = 5; + // ???? + // ??? + else if ((NOON_TO_EVENING + 20 <= SaTime.hour && SaTime.hour < NOON_TO_EVENING +30) || NIGHT_TO_MORNING + 60 < SaTime.hour) + buf[i]->mode = 6; + // ???? + // ??? + else if ((NOON_TO_EVENING + 30 <= SaTime.hour && SaTime.hour < NOON_TO_EVENING + 40) || NIGHT_TO_MORNING + 40 < SaTime.hour) + buf[i]->mode = 8; + else + { + if (buf[i]->type2 == 0) + { + // ????????? + // ?????????? + if (SaTime.hour < NOON_TO_EVENING + 50 || NIGHT_TO_MORNING + 30 < SaTime.hour) + buf[i]->mode = 4; + // ??????????? + // ???????? + else if (SaTime.hour < NOON_TO_EVENING + 80 || NIGHT_TO_MORNING + 20 < SaTime.hour) + buf[i]->mode = 1; + else + buf[i]->mode = (rand() % 2); + } + else if (buf[i]->type2 == 1) + buf[i]->mode = 8; + } + } + } + mapEffectDrawFlag = 1; + } + else + { + if (mapEffectStarFlag) + { + for (i = 0; i < sizeof(buf) / sizeof(void*); i++) + { + delMapEffectBuf(buf[i]); + buf[i] = NULL; + } + mapEffectStarFlag = 0; + } + } +} + +// ??????? +void mapEffectFallingStar(void) +{ + static MAP_EFFECT *buf = NULL; + + if (mapEffectFallingStarFlag != 0 && (SaTime.hour < EVENING_TO_NIGHT || NIGHT_TO_MORNING < SaTime.hour)) + { + mapEffectFallingStarFlag = 0; + mapEffectFallingStarTime = (rand() % 300) + 400; + } + if (!mapEffectFallingStarFlag && mapEffectFallingStarTime == SaTime.hour) + { + if (nowFloor == 10920) + { + buf = getMapEffectBuf(); + if (buf) + { + int i = (rand() % 5); + + switch (i) + { + case 0: + setEffectStar(buf, 76, 6, 0, 0, 0); + buf->dx = 10; + buf->dy = 6; + buf->ey = 120; + break; + case 1: + setEffectStar(buf, 77, 7, 0, 0, 0); + buf->dx = 8; + buf->dy = 7; + buf->ey = 120; + break; + case 2: + setEffectStar(buf, 80, 13, 0, 0, 0); + buf->dx = -10; + buf->dy = 9; + buf->ey = 120; + break; + case 3: + setEffectStar(buf, 84, 19, 0, 0, 0); + buf->dx = 12; + buf->dy = 7; + buf->ey = 90; + break; + case 4: + setEffectStar(buf, 95, 26, 0, 0, 0); + buf->dx = -10; + buf->dy = 7; + buf->ey = 120; + break; + } + // ?? + if ((rand() % 10) < 6) + buf->mode = 8; + else + buf->mode = 1; + } + mapEffectFallingStarFlag = 1; + } + else if (nowFloor == 20105) + { + buf = getMapEffectBuf(); + if (buf) + { + int i = (rand() % 8); + + i = 7; + switch (i) + { + case 0: + setEffectStar(buf, 22, 9, 0, 0, 0); + buf->dx = 10; + buf->dy = 7; + buf->ey = 120; + break; + case 1: + setEffectStar(buf, 27, 15, 0, 0, 0); + buf->dx = -8; + buf->dy = 9; + buf->ey = 120; + break; + case 2: + setEffectStar(buf, 31, 14, 0, 0, 0); + buf->dx = -10; + buf->dy = 6; + buf->ey = 120; + break; + case 3: + setEffectStar(buf, 33, 18, 0, 0, 0); + buf->dx = 12; + buf->dy = 8; + buf->ey = 120; + break; + case 4: + setEffectStar(buf, 38, 22, 0, 0, 0); + buf->dx = -11; + buf->dy = 7; + buf->ey = 120; + break; + case 5: + setEffectStar(buf, 43, 27, 0, 0, 0); + buf->dx = -9; + buf->dy = 6; + buf->ey = 120; + break; + case 6: + setEffectStar(buf, 41, 29, 0, 0, 0); + buf->dx = 12; + buf->dy = 6; + buf->ey = 120; + break; + case 7: + setEffectStar(buf, 43, 33, 0, 0, 0); + buf->dx = 14; + buf->dy = 8; + buf->ey = 80; + break; + } + // ?? + if ((rand() % 10) < 6) + buf->mode = 8; + else + buf->mode = 1; + } + mapEffectFallingStarFlag = 1; + } + else if (nowFloor == 1200) + { + buf = getMapEffectBuf(); + if (buf) + { + int i = (rand() % 3); + + i = 2; + switch (i) + { + case 0: + setEffectStar(buf, 63, 26, 0, 0, 0); + buf->dx = 10; + buf->dy = 7; + buf->ey = 80; + break; + case 1: + setEffectStar(buf, 66, 30, 0, 0, 0); + buf->dx = -10; + buf->dy = 6; + buf->ey = 70; + break; + case 2: + setEffectStar(buf, 70, 35, 0, 0, 0); + buf->dx = 8; + buf->dy = 6; + buf->ey = 40; + break; + } + // ?? + if ((rand() % 10) < 6) + buf->mode = 8; + else + buf->mode = 1; + } + mapEffectFallingStarFlag = 1; + } + else if (nowFloor == 20406) + { + buf = getMapEffectBuf(); + if (buf) + { + int i = (rand() % 6); + + i = 5; + switch (i) + { + case 0: + setEffectStar(buf, 20, 11, 0, 0, 0); + buf->dx = -12; + buf->dy = 9; + buf->ey = 80; + break; + case 1: + setEffectStar(buf, 23, 11, 0, 0, 0); + buf->dx = 10; + buf->dy = 8; + buf->ey = 120; + break; + case 2: + setEffectStar(buf, 32, 14, 0, 0, 0); + buf->dx = -9; + buf->dy = 6; + buf->ey = 120; + break; + case 3: + setEffectStar(buf, 36, 20, 0, 0, 0); + buf->dx = -10; + buf->dy = 9; + buf->ey = 120; + break; + case 4: + setEffectStar(buf, 41, 24, 0, 0, 0); + buf->dx = 11; + buf->dy = 7; + buf->ey = 120; + break; + case 5: + setEffectStar(buf, 44, 32, 0, 0, 0); + buf->dx = 10; + buf->dy = 8; + buf->ey = 120; + break; + } + // ?? + if ((rand() % 10) < 6) + buf->mode = 8; + else + buf->mode = 1; + } + mapEffectFallingStarFlag = 1; + } + } + if (buf) + { + buf->ggx += buf->dx; + buf->ggy += buf->dy; + if (buf->ggy > buf->ey) + { + delMapEffectBuf(buf); + buf = NULL; + } + else + { + calEffectStar(buf); + mapEffectDrawFlag = 1; + } + } +} + +// D?????? +void mapEffectSnow2(int n) +{ + short mapEffectSnowWaitTime = 0; + short mapEffectSnowFrameMax = 0; + int hosei1 = 940, hosei2 = -200, ww = DEF_APPSIZEX, hh = DEF_APPSIZEY, time = 0, i, j, k; + MAP_EFFECT *buf; + + // ??????????????? + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 420; + hosei2 = -50; + } + for (k = 0; k < n; k++) + { + // DD + if (mapEffectSnowLevel) + { + if (mapEffectSnowLevel < 3) + { + mapEffectSnowWaitTime = (2 - mapEffectSnowLevel) << 1; + if (time >= mapEffectSnowWaitTime) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_SNOW; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 2); + j = (rand() % 2); + if (j == 0) + { + buf->dx = 0 + (rand() % 2); + buf->dy = 3 + (rand() % 2); + } + else if (j == 1) + { + buf->dx = 1; + buf->dy = 4 + (rand() % 2); + } + time = 0; + mapEffectSnowCnt++; + } + } + } + else + { + mapEffectSnowFrameMax = (mapEffectSnowLevel - 2) << 1; + if (ResoMode == 1) + mapEffectSnowFrameMax >>= 1; + for (i = 0; i < mapEffectSnowFrameMax; i++) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_SNOW; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 2); + j = (rand() % 2); + if (j == 0) + { + buf->dx = 0 + (rand() % 2); + buf->dy = 3 + (rand() % 2); + } + else if (j == 1) + { + buf->dx = 1; + buf->dy = 4 + (rand() % 2); + } + time = 0; + mapEffectSnowCnt++; + } + } + } + } + // ?h?? + i = 0; + buf = useBufMapEffect; + while (buf != (MAP_EFFECT*)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_SNOW) + { + buf->x += buf->dx; + buf->y += buf->dy; + mapEffectDirHosei(&buf->x, &buf->y); + if (ww + 100 <= buf->x || hh <= buf->y) + { + // ?h? + MAP_EFFECT *buf2 = buf->next; + delMapEffectBuf(buf); + buf = buf2; + mapEffectSnowCnt--; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + i++; + } + time++; + } +} + +// ??????? +void mapEffectRain2(int n) +{ + short mapEffectRainWaitTime = 0; + short mapEffectRainFrameMax = 0; + int hosei1 = 840, hosei2 = -200, ww = DEF_APPSIZEX, hh = DEF_APPSIZEY, time = 0, i, k; + MAP_EFFECT *buf; + + // ??????????????? + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 370; + hosei2 = -50; + } + for (k = 0; k < n; k++) + { + // ?D + if (mapEffectRainLevel) + { + if (mapEffectRainLevel < 3) + { + mapEffectRainWaitTime = (2 - mapEffectRainLevel) << 1; + if (time >= mapEffectRainWaitTime) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_RAIN; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->dx = 2 + (rand() % 2); + buf->dy = 9; + time = 0; + mapEffectRainCnt++; + } + } + } + else + { + mapEffectRainFrameMax = (mapEffectRainLevel - 2) << 2; + if (ResoMode == 1) + mapEffectRainFrameMax >>= 1; + for (i = 0; i < mapEffectRainFrameMax; i++) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_RAIN; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->dx = 2 + (rand() % 2); + buf->dy = 9; + time = 0; + mapEffectRainCnt++; + } + } + } + } + // ?h?? + i = 0; + buf = useBufMapEffect; + while (buf != (MAP_EFFECT*)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_RAIN) + { + buf->x += buf->dx; + buf->y += buf->dy; + mapEffectDirHosei(&buf->x, &buf->y); + if (ww <= buf->x || hh <= buf->y) + { + // ?h? + MAP_EFFECT *buf2 = buf->next; + delMapEffectBuf(buf); + buf = buf2; + mapEffectRainCnt--; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + i++; + } + } +} + +// ?????????? +void mapEffectKamiFubuki(void) +{ + short mapEffectKamiFubukiWaitTime = 0; + short mapEffectKamiFubukiFrameMax = 0; + int hosei1 = 1240, hosei2 = -100, ww = DEF_APPSIZEX, hh = DEF_APPSIZEY, i, j; + static unsigned int time = TimeGetTime(); + MAP_EFFECT *buf; + + // ??????????????? + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 470; + hosei2 = -50; + } + // ????D + if (mapEffectKamiFubukiLevel) + { + if (mapEffectKamiFubukiLevel < 3) + { + mapEffectKamiFubukiWaitTime = (51 - 25 * mapEffectKamiFubukiLevel); + if (time + mapEffectKamiFubukiWaitTime < TimeGetTime()) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_KAMIFUBUKI; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 4); + buf->cnt = 4; + j = (rand() % 2); + if (j == 0) + { + buf->dx = -1; + buf->dy = 2; + } + else if (j == 1) + { + buf->dx = -1; + buf->dy = 3; + } + time = TimeGetTime(); + mapEffectKamiFubukiCnt++; + } + } + } + else + { + mapEffectKamiFubukiFrameMax = (mapEffectKamiFubukiLevel - 2) << 1; + if (ResoMode == 1) + mapEffectKamiFubukiFrameMax >>= 1; + for (i = 0; i < mapEffectKamiFubukiFrameMax; i++) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_KAMIFUBUKI; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 4); + buf->cnt = 4; + j = (rand() % 2); + if (j == 0) + { + buf->dx = -1; + buf->dy = 2; + } + else if (j == 1) + { + buf->dx = -1; + buf->dy = 3; + } + time = TimeGetTime(); + mapEffectKamiFubukiCnt++; + } + } + } + } + // ?h?? + i = 0; + buf = useBufMapEffect; + while (buf != (MAP_EFFECT*)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_KAMIFUBUKI) + { + buf->x += (buf->dx + (rand() % 3) - 1); + buf->y += (buf->dy + (rand() % 3) - 1); + if (buf->cnt <= 0) + { + buf->type2 = (rand() % 3); + buf->w = (rand() % 8) + 1; + buf->h = (rand() % 8) + 1; + buf->cnt = 4; + } + else + buf->cnt--; + mapEffectDirHosei(&buf->x, &buf->y); + if (hh <= buf->y) + { + // ?h? + MAP_EFFECT *buf2 = buf->next; + delMapEffectBuf(buf); + buf = buf2; + mapEffectKamiFubukiCnt--; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + i++; + } +} + +/////////////////////////////////////////////////////////////////////////// +// ??????????????????????? +// +void camMapToGamen(float sx, float sy, float *ex, float *ey) +{ + float x0, y0, x, y, tx = (float)(SURFACE_WIDTH >> 1), ty = (float)(SURFACE_HEIGHT >> 1); + + x0 = (sx - viewPointX) / GRID_SIZE; + y0 = (sy - viewPointY) / GRID_SIZE; + x = + x0 * tx + y0 * tx; + y = - x0 * ty + y0 * ty; + //?? + *ex = x + viewOffsetX; + *ey = y + viewOffsetY; +} + +// +// ?????????(????????)???? +// +void camGamenToMap(float sx, float sy, float *ex, float *ey) +{ + float x0, y0, x, y; + + // ?? + x0 = sx - viewOffsetX; + y0 = sy - viewOffsetY; + x = x0 - (float)SURFACE_WIDTH / (float)SURFACE_HEIGHT * y0; + y = x0 + (float)SURFACE_WIDTH / (float)SURFACE_HEIGHT * y0; + *ex = x + viewPointX; + *ey = y + viewPointY; +} + +#ifdef __EDEN_DICE +extern char *pCommand; +extern DWORD dwDiceTimer; + +void mapEffectDice(void) +{ + char temp[16]; + static int d1, d2, i = 0, nState = 0; + + if (bMapEffectDice) + { + switch (nState) + { + case 0: + getStringToken(pCommand, '|', 3, sizeof(temp), temp); + d1 = atoi(temp); + getStringToken(pCommand, '|', 6, sizeof(temp), temp); + d2 = atoi(temp); + FREE(pCommand); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + pCommand = NULL; + nState++; + delCharObj(1); + break; + case 1: + if (TimeGetTime() - dwDiceTimer > 100) + { +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, gm_name); + #else +#ifdef _NPC_PICTURE + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, 0); +#else + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0); +#endif + #endif +#else + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, gm_name); + #else + #ifdef _NPC_PICTURE + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0); + #else + setNpcCharObj(0, 26400 + i, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48); + #endif + #endif +#endif + dwDiceTimer = TimeGetTime(); + if (++i > 10) + { + i = 0; + nState++; + } + } + break; + case 2: +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + setNpcCharObj(0, 26410 + d1, 12, 8, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, ""); + setNpcCharObj(1, 26416 + d2, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, ""); + #else + #ifdef _NPC_PICTURE + setNpcCharObj(0, 26410 + d1, 12, 8, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, 0); + setNpcCharObj(1, 26416 + d2, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0, 0); + #else + setNpcCharObj(0, 26410 + d1, 12, 8, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0); + setNpcCharObj(1, 26416 + d2, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48, 0); + #endif + #endif +#else + setNpcCharObj(0, 26410 + d1, 12, 8, 0, "", "", "", 1, "", 1, 0, 1, 0, 48); + setNpcCharObj(1, 26416 + d2, 13, 9, 0, "", "", "", 1, "", 1, 0, 1, 0, 48); +#endif + bMapEffectDice = FALSE; + nState = 0; + break; + } + } +} +#endif + +#ifdef _HALLOWEEN_EFFECT +void mapEffectHalloweenProc(void) +{ + int hosei1 = 940, hosei2 = -200, ww = DEF_APPSIZEX, hh = DEF_APPSIZEY, j; + static unsigned int time = TimeGetTime(); + MAP_EFFECT *buf; + + if (ResoMode == 1) + { + ww >>= 1; + hh >>= 1; + hosei1 = 370; + hosei2 = -50; + } + if (mapEffectHalloween) + { + if (time + 100 < TimeGetTime()) + { + MAP_EFFECT *buf = getMapEffectBuf(); + if (buf != (MAP_EFFECT*)NULL) + { + buf->type = MAP_EFFECT_TYPE_HALLOWEEN; + buf->x = (rand() % hosei1) + hosei2; + buf->y = 0; + buf->mode = (rand() % 2); + buf->pAction = MakeAnimDisp(buf->x, buf->y, mapEffectHalloween, 0); + if (buf->pAction != NULL) + { + buf->pAction->hitDispNo = 0; + buf->pAction->dispPrio = DISP_PRIO_GRID; + j = (rand() % 2); + if (j == 0) + { + buf->dx = rand() % 2; + buf->dy = 3 + (rand() % 2); + } + else if (j == 1) + { + buf->dx = 1; + buf->dy = 4 + (rand() % 2); + } + } + } + time = TimeGetTime(); + } + } + buf = useBufMapEffect; + while (buf != (MAP_EFFECT*)NULL) + { + if (buf->type == MAP_EFFECT_TYPE_HALLOWEEN) + { + buf->pAction->x = buf->x += buf->dx; + buf->pAction->y = buf->y += buf->dy; + mapEffectDirHosei(&buf->x, &buf->y); + if (ww + 100 <= buf->x || hh <= buf->y) + { + MAP_EFFECT *buf2 = buf->next; + DeathAction(buf->pAction); + buf->pAction = NULL; + delMapEffectBuf(buf); + buf = buf2; + continue; + } + } + buf = buf->next; + mapEffectDrawFlag = 1; + } +} +#endif + +#ifdef _MOVE_SCREEN +void MoveScreenProc(void) +{ + if (pc.iDestX != nowGx || pc.iDestY != nowGy) + { + if (nowGx > pc.iDestX) + { + nowGx--; + iScreenMoveX--; + } + else if (nowGx < pc.iDestX) + { + nowGx++; + iScreenMoveX++; + } + if (nowGy > pc.iDestY) + { + nowGy--; + iScreenMoveY--; + } + else if (nowGy < pc.iDestY) + { + nowGy++; + iScreenMoveY++; + } + } + else + drawTile(); +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/math2.cpp b/石器时代8.5客户端最新源代码/石器源码/system/math2.cpp new file mode 100644 index 0000000..3217ee3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/math2.cpp @@ -0,0 +1,385 @@ +/************************/ +/* math2.c */ +/************************/ +#include +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +#define ASIN_DIV 64 +#define ATAN_DIV 64 + +#define MAX_RND2_TBL 100 +int randTbl[MAX_RND2_TBL]; + + +/* ??????? */ +double SinTbl[ 360 ] = { + +0.000000,0.017452,0.034899,0.052336,0.069756,0.087156,0.104528,0.121869,0.139173,0.156434, +0.173648,0.190809,0.207912,0.224951,0.241922,0.258819,0.275637,0.292372,0.309017,0.325568, +0.342020,0.358368,0.374607,0.390731,0.406737,0.422618,0.438371,0.453991,0.469472,0.484810, +0.500000,0.515038,0.529919,0.544639,0.559193,0.573576,0.587785,0.601815,0.615662,0.629320, +0.642788,0.656059,0.669131,0.681998,0.694658,0.707107,0.719340,0.731354,0.743145,0.754710, +0.766044,0.777146,0.788011,0.798635,0.809017,0.819152,0.829038,0.838671,0.848048,0.857167, +0.866025,0.874620,0.882948,0.891007,0.898794,0.906308,0.913545,0.920505,0.927184,0.933580, +0.939693,0.945519,0.951057,0.956305,0.961262,0.965926,0.970296,0.974370,0.978148,0.981627, +0.984808,0.987688,0.990268,0.992546,0.994522,0.996195,0.997564,0.998630,0.999391,0.999848, +1.000000,0.999848,0.999391,0.998630,0.997564,0.996195,0.994522,0.992546,0.990268,0.987688, +0.984808,0.981627,0.978148,0.974370,0.970296,0.965926,0.961262,0.956305,0.951056,0.945519, +0.939693,0.933580,0.927184,0.920505,0.913545,0.906308,0.898794,0.891007,0.882948,0.874620, +0.866025,0.857167,0.848048,0.838671,0.829037,0.819152,0.809017,0.798635,0.788011,0.777146, +0.766044,0.754710,0.743145,0.731354,0.719340,0.707107,0.694658,0.681998,0.669131,0.656059, +0.642788,0.629320,0.615661,0.601815,0.587785,0.573576,0.559193,0.544639,0.529919,0.515038, +0.500000,0.484810,0.469472,0.453990,0.438371,0.422618,0.406737,0.390731,0.374607,0.358368, +0.342020,0.325568,0.309017,0.292372,0.275637,0.258819,0.241922,0.224951,0.207912,0.190809, +0.173648,0.156434,0.139173,0.121869,0.104528,0.087156,0.069756,0.052336,0.034900,0.017452, +-0.000000,-0.017452,-0.034900,-0.052336,-0.069757,-0.087156,-0.104528,-0.121869,-0.139173,-0.156434, +-0.173648,-0.190809,-0.207912,-0.224951,-0.241922,-0.258819,-0.275637,-0.292372,-0.309017,-0.325568, +-0.342020,-0.358368,-0.374606,-0.390731,-0.406737,-0.422618,-0.438371,-0.453991,-0.469472,-0.484810, +-0.500000,-0.515038,-0.529919,-0.544639,-0.559193,-0.573576,-0.587785,-0.601815,-0.615661,-0.629320, +-0.642788,-0.656059,-0.669131,-0.681998,-0.694658,-0.707107,-0.719340,-0.731354,-0.743145,-0.754710, +-0.766045,-0.777146,-0.788011,-0.798635,-0.809017,-0.819152,-0.829038,-0.838671,-0.848048,-0.857167, +-0.866025,-0.874620,-0.882948,-0.891007,-0.898794,-0.906308,-0.913545,-0.920505,-0.927184,-0.933581, +-0.939692,-0.945519,-0.951056,-0.956305,-0.961262,-0.965926,-0.970296,-0.974370,-0.978148,-0.981627, +-0.984808,-0.987688,-0.990268,-0.992546,-0.994522,-0.996195,-0.997564,-0.998630,-0.999391,-0.999848, +-1.000000,-0.999848,-0.999391,-0.998630,-0.997564,-0.996195,-0.994522,-0.992546,-0.990268,-0.987688, +-0.984808,-0.981627,-0.978148,-0.974370,-0.970296,-0.965926,-0.961262,-0.956305,-0.951056,-0.945519, +-0.939693,-0.933580,-0.927184,-0.920505,-0.913545,-0.906308,-0.898794,-0.891007,-0.882948,-0.874620, +-0.866025,-0.857167,-0.848048,-0.838671,-0.829038,-0.819152,-0.809017,-0.798635,-0.788011,-0.777146, +-0.766044,-0.754710,-0.743145,-0.731354,-0.719340,-0.707107,-0.694659,-0.681998,-0.669131,-0.656059, +-0.642788,-0.629321,-0.615661,-0.601815,-0.587785,-0.573576,-0.559193,-0.544639,-0.529919,-0.515038, +-0.500000,-0.484809,-0.469472,-0.453991,-0.438371,-0.422618,-0.406736,-0.390731,-0.374607,-0.358368, +-0.342020,-0.325568,-0.309017,-0.292372,-0.275638,-0.258819,-0.241922,-0.224951,-0.207912,-0.190809, +-0.173648,-0.156434,-0.139173,-0.121869,-0.104528,-0.087156,-0.069757,-0.052336,-0.034900,-0.017452 + +}; + +#if 0 +double asin_table1[ ASIN_DIV + 1 ] = { + 0.000000, 0.895283, 1.790785, 2.686724, + 3.583322, 4.480799, 5.379379, 6.279288, + 7.180756, 8.084014, 8.989299, 9.896853, + 10.806923, 11.719760, 12.635625, 13.554784, + 14.477512, 15.404094, 16.334823, 17.270005, + 18.209957, 19.155010, 20.105510, 21.061818, + 22.024313, 22.993394, 23.969482, 24.953021, + 25.944480, 26.944358, 27.953187, 28.971532, + 30.000000, 31.039240, 32.089951, 33.152888, + 34.228866, 35.318773, 36.423574, 37.544325, + 38.682187, 39.838440, 41.014500, 42.211944, + 43.432537, 44.678264, 45.951374, 47.254431, + 48.590378, 49.962627, 51.375167, 52.832715, + 54.340912, 55.906609, 57.538255, 59.246480, + 61.044976, 62.951890, 64.992167, 67.201752, + 69.635865, 72.387561, 75.638489, 79.858207, + 90.000000 +}; + +double asin_table2[ ASIN_DIV + 1 ] = { + 71.805128, 71.949032, 72.094054, 72.240221, + 72.387561, 72.536105, 72.685883, 72.836928, + 72.989273, 73.142954, 73.298007, 73.454472, + 73.612389, 73.771799, 73.932748, 74.095283, + 74.259452, 74.425307, 74.592902, 74.762296, + 74.933549, 75.106724, 75.281891, 75.459120, + 75.638489, 75.820077, 76.003973, 76.190268, + 76.379061, 76.570456, 76.764567, 76.961516, + 77.161432, 77.364457, 77.570743, 77.780455, + 77.993773, 78.210893, 78.432029, 78.657415, + 78.887310, 79.122001, 79.361804, 79.607074, + 79.858207, 80.115650, 80.379910, 80.651564, + 80.931279, 81.219822, 81.518097, 81.827168, + 82.148310, 82.483070, 82.833357, 83.201569, + 83.590796, 84.005130, 84.450191, 84.934071, + 85.469191, 86.076460, 86.796651, 87.735038, + 90.000000 +}; + +double asin_table3[ ASIN_DIV + 1 ] = { + 84.268032, 84.313027, 84.358379, 84.404097, + 84.450191, 84.496669, 84.543543, 84.590821, + 84.638515, 84.686635, 84.735195, 84.784205, + 84.833678, 84.883629, 84.934071, 84.985019, + 85.036488, 85.088496, 85.141058, 85.194194, + 85.247923, 85.302265, 85.357241, 85.412875, + 85.469191, 85.526213, 85.583971, 85.642492, + 85.701809, 85.761954, 85.822963, 85.884876, + 85.947732, 86.011577, 86.076460, 86.142431, + 86.209549, 86.277876, 86.347478, 86.418431, + 86.490816, 86.564724, 86.640256, 86.717523, + 86.796651, 86.877782, 86.961076, 87.046716, + 87.134913, 87.225909, 87.319991, 87.417496, + 87.518826, 87.624472, 87.735038, 87.851282, + 87.974183, 88.105034, 88.245614, 88.398482, + 88.567568, 88.759486, 88.987131, 89.283798, + 90.000000 +}; +#endif + +double atan_table[ ATAN_DIV + 1 ] = { + 0.000000, 0.895174, 1.789911, 2.683775, + 3.576334, 4.467159, 5.355825, 6.241914, + 7.125016, 8.004729, 8.880659, 9.752425, + 10.619655, 11.481991, 12.339087, 13.190611, + 14.036243, 14.875682, 15.708638, 16.534838, + 17.354025, 18.165957, 18.970408, 19.767169, + 20.556045, 21.336859, 22.109448, 22.873665, + 23.629378, 24.376469, 25.114835, 25.844388, + 26.565051, 27.276763, 27.979474, 28.673147, + 29.357754, 30.033280, 30.699723, 31.357085, + 32.005383, 32.644640, 33.274888, 33.896167, + 34.508523, 35.112011, 35.706691, 36.292630, + 36.869898, 37.438572, 37.998732, 38.550465, + 39.093859, 39.629005, 40.156000, 40.674940, + 41.185925, 41.689059, 42.184443, 42.672185, + 43.152390, 43.625165, 44.090620, 44.548862, + 45.000000 +}; + +/* ?T ? ????? ??? ?*******************************************************/ +void AdjustDir( float *dir ) +{ + if( *dir >= 360.0 ){ + *dir -= 360.0F; + AdjustDir(dir); + }else + if ( *dir < 0.0 ){ + *dir += 360.0F; + AdjustDir(dir); + } +} + +void AdjustDir( int *dir ) +{ + if( *dir >= 360 ){ + *dir -= 360; + AdjustDir(dir); + }else + if ( *dir < 0 ){ + *dir += 360; + AdjustDir(dir); + } +} + +/* ????????????? ***********************************************************/ +float SinT( float theat ) +{ + float ans; + + /* ?T */ + AdjustDir( &theat ); + /* ?????????? */ + ans = ( float )SinTbl[ (int)theat ]; + + return ans; +} + +/* ????????????? ***********************************************************/ +float CosT( float theat ) +{ + float ans; + + ans = SinT( theat + 90.0f ); + + return ans; +} + +/* ????????? *********************************************************************/ +float Atan( float x, float y ) +{ + int c = 0; + float a; + float r = 0; + float v, w; + int index1, index2; + float a1, a2; + float ratio; + + + if (0.0 == x && 0.0 == y) { + return 0.0; + } + + if ( x < 0 ) { + c += 1; + v = -x; + } else { + v = x; + } + + if ( y < 0 ) { + c += 2; + w = -y; + } else { + w = y; + } + + if ( v < w ) { + c += 4; + index1 = ( int )( v / w * ATAN_DIV ); + index2 = index1 + 1; + ratio = ( v / w * ATAN_DIV ) - ( float ) index1; + } else { + index1 = ( int )( w / v * ATAN_DIV ); + index2 = index1 + 1; + ratio = ( w / v * ATAN_DIV ) - ( float ) index1; + } + + if ( index2 > ATAN_DIV ) index2 = ATAN_DIV; + a1 = ( float )atan_table[ index1 ]; + a2 = ( float )atan_table[ index2 ]; + a = ( 1 - ratio ) * a1 + ratio * a2; + + switch (c) { + case 0: + r = a; + break; + case 1: + r = 180.0f - a; + break; + case 2: + r = 360.0f - a; + break; + case 3: + r = 180.0f + a; + break; + case 4: + r = 90.0f - a; + break; + case 5: + r = 90.0f + a; + break; + case 6: + r = 270.0f + a; + break; + case 7: + r = 270.0f - a; + break; + } + + // StoneAge? + r -= 135; + if (r < 0.0) r += 360.0; + ///////////// + + return r; +} + +/* ?????D *************************************************************************/ +int Rnd( int min, int max ) +{ + int rnd; + if( ( max + 1 - min ) + min == 0 ) return 0; + rnd = rand() % ( max + 1 - min ) + min; + + return rnd; +} + +void initRand2( void ) +{ + int i; + int j; + j = (rand() % 100); + for( i = 0; i < MAX_RND2_TBL; i++ ){ + randTbl[j] = i; + j++; + if( j >= MAX_RND2_TBL ) + j = 0; + } +} + +#if 1 + +int rand2( void ) +{ + static int r = 0; + int ret; + + ret = randTbl[r]; + r++; + if( r >= MAX_RND2_TBL ) + r = 0; + + return ret; +} + +#else + +int rand2( void ) +{ +// static int r = 0; + static int under25 = 0; + static int cnt = 0; + static int cnt2 = 5; + int ret; + + ret = (rand() % 100); + +// ret = randTbl[r]; +// r++; +// if( r >= MAX_RND2_TBL ) +// r = 0; + + if( ret < 25 ) + { + under25++; + if( under25 >= 4 && cnt >= cnt2 ) + { + under25 = 0; + cnt = 0; + cnt2++; + if( cnt2 > 6 ) + cnt2 = 4; + } + else + { + ret = 99 - ret; + cnt++; + } + } + else + { + if( ret > 85 && cnt > 10 ) + { + ret = 99 - ret; + cnt = 0; + cnt2++; + if( cnt2 > 6 ) + cnt2 = 4; + } + else + { + cnt++; + } + under25 = 0; + } + + return ret; +} + +#endif + + +/* ????????? *******************************************************************/ +float pointLen( float x1, float y1, float x2, float y2 ) +{ + float x, y; + + x = x2 - x1; + y = y2 - y1; + + return (float)sqrt( x*x + y*y ); +} + +float pointLen2( float x1, float y1, float x2, float y2 ) +{ + float x, y; + + x = x2 - x1; + y = y2 - y1; + + return( x*x + y*y ); +} + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/menu.cpp b/石器时代8.5客户端最新源代码/石器源码/system/menu.cpp new file mode 100644 index 0000000..8da8c42 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/menu.cpp @@ -0,0 +1,22835 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/font.h" +#include "../other/caryIme.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/pc.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/savedata.h" +#include "../systeminc/t_music.h" +#include "../systeminc/menu.h" +#include "../systeminc/tool.h" +#include "../systeminc/map.h" +#include "../systeminc/field.h" +#include "../systeminc/pet_skillinfo.h" +#include "../wgs/descrypt.h" +#include "../systeminc/character.h" +#include "../redMemoy.h" +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif +#ifdef _MAGIC_ITEM_ +ACTION* ߹⻷Act=NULL; +extern ACTION* MagicItemActAddr; +extern int MagicItemCombinData[3]; +extern int MagicItemPosState[4]; +#endif +#ifdef _RENWU_ +BOOL ѯ=FALSE; +#endif +extern int MessageBoxNew(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); +int 忪 = FALSE; +int 鿪 = TRUE; +int ο = FALSE; +int Ҽ = FALSE; + +#ifdef _PETBLESS_ +int ףڿ = FALSE; +char ף[128]; +int ףѡ; +#endif + + +#ifdef _AIDENGLU_ +extern void ShowBottomLineString(int iColor, LPSTR lpstr); +extern Landed PcLanded; +#endif +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ +#ifdef _SYUTEST3 +#define MENU_STATUS_0 25 +#else +#define MENU_STATUS_0 17 +#endif +#else +#define MENU_STATUS_0 12 +#endif +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ +#define MENU_PET_0 24 +#else +#define MENU_PET_0 20 +#endif +#define MENU_ITEM_0 40 +#define MENU_MAIL_0 40 +#define MENU_ALBUM_0 20 +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +#define MENU_TRADE_0 22 +#endif +#define MENU_BANK_0 20 +#define MENU_BTL_RESULT_0 1 +//Terry add 2003/11/19 +extern bool g_bTradesystemOpen; +//end +#ifdef _READ16BITBMP +//extern BOOL g_bUseAlpha; +#endif +#ifdef _NEW_COLOR_ +extern BOOL g_bUseAlpha; +#endif +// ???? + +#define MAX_CHAT_REGISTY_STR 8 // ??????K??? +#define MAX_CHAT_REGISTY_STR_LEN 26 // ??????K???? + +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ +bool DropPetWndflag = false; //Ӵʾ +short DropI = -1; //ݴiֵ +#endif +#ifdef _NEW_ITEM_ +int ҳ = 0; +int жҵ() +{ + int ret = MAX_MAXHAVEITEM + MAX_ITEMSTART; + if (pc.״̬ & 1 << 1){ + ret += MAX_MAXHAVEITEM; + if (pc.״̬ & 1 << 2){ + ret += MAX_MAXHAVEITEM; + } + } + return ret; +} +#endif +#ifdef _DIEJIA_ +//ƷǷܶѵ +BOOL ItemCanPile(int flg) +{ + return (flg & 1 << 6); +} +#endif +#ifdef _AniCrossFrame // Syu ADD ι +#define RAND(x,y) ((x-1)+1+ (int)((double)(y-(x-1))*rand()/(RAND_MAX+1.0))) +int UpDownflag = 0; +#endif + +#define CAHT_REGISTY_STR_FILE_NAME "data\\chatreg.dat" // ?????K??V???? +static int systemWndFontNo[MENU_SYSTEM_0]; // ???Rek? +unsigned int systemWndNo; // ?????k? +STR_BUFFER chatRegistryStr[MAX_CHAT_REGISTY_STR]; // ??????K??V?????? +int MouseCursorFlag = FALSE; // ??????? + +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի +char talkmsg[4][256]; //еݴBuffer +int talkwndx = 300, talkwndy = 350; //ʼλ +bool talkwndflag = false; //Ƿҷ +bool tradetalkwndflag = false; //ǷԻ +#endif + +#ifdef _MONEYINPUT //Syu ADD ֶǮ +STR_BUFFER MymoneyBuffer; +bool Moneyflag = false; +#endif +STR_BUFFER TradeBuffer; +bool Tradeflag = false; //λFocus +bool TradeBtnflag = false; //ťʾ +// ??? +int mapWndFontNo[MENU_MAP_0]; // ???Rek? +static unsigned int mapWndNo; // ?????k? +int MapWmdFlagBak; // Pf??h????????????? + +// ????? +static int statusWndFontNo[MENU_STATUS_0]; // ???Rek? +static int statusWndBtnFlag[MENU_STATUS_0]; // ??????? +static unsigned int statusWndNo; // ?????k? +STR_BUFFER shougouChange; // ?????????? +int StatusUpPoint; // ???????????? + +#ifdef _TRADESYSTEM2 +static int tradeWndFontNo[MENU_TRADE_0]; // ???Rek? +static int tradeWndBtnFlag[MENU_TRADE_0]; // ??????? +#endif +static unsigned int tradeWndNo = 0; // ?????k? + +int showindex[7] = { 0, 0, 0, 0, 0, 0, 0 }; + +static char opp_sockfd[128] = "-1"; +static char opp_name[128] = ""; +static char trade_command[128]; +static char trade_kind[128]; +static int opp_showindex; +static char opp_goldmount[1024]; +static char opp_itemgraph[1024]; +static char opp_itemname[1024]; +static char opp_itemeffect[1024]; +static char opp_itemindex[1024]; +static char opp_itemdamage[1024]; + +struct showitem { + char name[128]; + char freename[256]; + char graph[128]; + char effect[1024]; + char color[128]; + char itemindex[128]; + char damage[128]; +}; +static int tradePetIndex = -1; +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +//ΪҷߣΪҷΪҷǮ +//ΪԷߣΪԷΪԷǮ + +static showitem opp_item[MAX_MAXHAVEITEM]; //׵Ϊ15 +struct showpet { + char opp_petname[128]; + char opp_petfreename[128]; + char opp_petgrano[128]; + char opp_petlevel[128]; + char opp_petatk[128]; + char opp_petdef[128]; + char opp_petquick[128]; + char opp_petindex[128]; + char opp_pettrans[128]; + char opp_petshowhp[128]; + char opp_petslot[128]; + char opp_petskill1[128]; + char opp_petskill2[128]; + char opp_petskill3[128]; + char opp_petskill4[128]; + char opp_petskill5[128]; + char opp_petskill6[128]; + char opp_petskill7[128]; +#ifdef _SHOW_FUSION + char opp_fusion[64]; +#endif +#ifdef _PET_ITEM + PetItemInfo oPetItemInfo[MAX_PET_ITEM]; // ϵĵ +#endif +}; //Է׳ݴ +static showpet opp_pet[5]; +#ifdef _NEW_ITEM_ +int itemflag[MAX_MAXHAVEITEM * 3]; +#else +int itemflag[MAX_MAXHAVEITEM]; +#endif +static ACTION *SecondActPet; //ڶӴAction +bool MainTradeWndflag = true; //Ӵʾflag +bool SecondTradeWndflag = false; //ڶӴʾflag +ACTION *SecondTradeWnd; //ڶӴ +ACTION *TradeTalkWnd = NULL; //ԻӴ +int ShowPetNum = 0; //ʾij +static int SecondtradeWndFontNo[6]; //ڶӴİť +int mytradelist[51] = { -1 }; //ҷҳ˳嵥 +int opptradelist[51] = { -1 }; //Էҳ˳嵥 +int drag1Y = 67, drag2Y = 257; //ҷťʼλ +int tmpdrag1Y, tmpdrag2Y; //קʼλ +bool dragflag1 = false, dragflag2 = false; //ҷť +int locknum = -1, locknum2 = -1; +#endif +static PET tradePet[2]; +static char tradepetindexget[128] = "-1"; +#ifdef _PET_ITEM +static bool g_bPetItemWndFlag = false; +#endif + +static ACTION *pActPet3 = NULL; //ʱӴҷPet Action +static ACTION *pActPet4 = NULL; +static ACTION *pActPet5 = NULL; + +struct tradelist { + char kind; + int data; + char name[256]; + char damage[256]; + char freename[256]; + int level; + int trns; +#ifdef _ITEM_PILENUMS + int pilenum; +#endif +#ifdef _SHOW_FUSION + int fusion; +#endif +#ifdef _NPC_ITEMUP + int itemup; +#endif +}; +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +static tradelist tradeList[45]; +#endif +static int mine_itemindex[2] = { -1, -1 }; +static char mine_itemname[2][128]; + +static int bankGold; +static int bankWndFontNo[MENU_TRADE_0]; // ???Rek? +static int bankWndBtnFlag[MENU_TRADE_0]; // ??????? +static int cashGold = 0; +static int totalGold = 0; +static int bankGoldInc = 0; +static int bankGoldCnt = 0; + +#ifdef _TELLCHANNEL //ROG ADD Ƶ +BOOL MultiTells = FALSE; +ACTION *pActMsgWnd; +int CharNum = 0; +char TellInfo[10][128]; +char name[10][32]; +int index[10]; +char reSendMsg[STR_BUFFER_SIZE]; +int TalkMode = 0; //0:һ 1: 2: 3: 4:ְҵ +char secretName[32] = { "" }; //Ҫ֮˵ +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ +typedef struct{ + char roomNo[4]; + char chiefName[CHAR_NAME_LEN+1]; + int chiefIndex; + int chiefFlag; + int memberNum; + char memberName[MAX_ROOM_NUM][CHAR_NAME_LEN+1]; + int memberIndex[MAX_ROOM_NUM]; + char roomName[32]; + char nickName[MAX_ROOM_NUM][CHAR_FREENAME_LEN+1]; +}CHATINFO; +CHATINFO chatInfo; + +bool secretFlag = FALSE; // +bool BtnType = FALSE; //ťʾ +bool setRoomFlag = FALSE; +bool assentFlag = FALSE; //ͬӴ +bool scrollFlag = FALSE; +char roomInfo[MAX_ROOM_NUM][64]; //ѡ +char memInfo[64]; //member information +int scrlBtnIndex = 0; //scrollλ +int BtnNo = 0; //ť +int firMemNo = 0; //һԱ +int selChar = -1; //Ҫ֮˵ı +int closeBtn ,leaveBtn ,delBtn,chaBtn,outBtn,scrlHBtn,scrlLBtn; //ťͼ +int roomIndex[MAX_ROOM_NUM]; +int roomNum = 0; +int memIndex = 0; //member index +static int ChatRoomBtn[ 16 ]; //Ұť +STR_BUFFER chatRoomName; //趨 +ACTION *pSetRoomWnd; //趨 +ACTION *pAssentWnd; //ͬӴ +ACTION *pChtChanlWnd; //Ӵ +ACTION *pSelChanlWnd; //ѡӴ +#endif + +#ifdef _TIMEBAR_FUNCTION //ʱbarʽ +ACTION *pTimeBarWnd; +char timeBarTitle[32]; +int timeBarRange; +int timeBarCurPos; +bool timeBarFlag = FALSE; +bool barHolder[2]; //лʱ +void DrawTimeBar(); +/////////TEST///////////////// +int StartTime = 0; +int timBarIdent = -1; +////////////////////////////// +#endif + +// ??? +static int petWndFontNo[MENU_PET_0]; // ???Rek? +static int petWndBtnFlag[MENU_PET_0]; // ??????? +static unsigned int petWndNo; // ????????k? +int petStatusNo; // ????????????????k? +int mixPetNo; // ????????k? +static ACTION *pActPet; // ????????????? +BOOL BattlePetReceiveFlag; // ӡP????????????? +#ifdef _STANDBYPET +BOOL StandbyPetSendFlag = FALSE; +#endif +STR_BUFFER petNameChange; // ????q???? +int BattlePetReceivePetNo = -1; // ????????k? +int SelectWazaNo; // k???k? + +// ???? +static int itemWndFontNo[MENU_ITEM_0]; // ???Rek? +static int itemWndBtnFlag[MENU_ITEM_0]; // ??????? +static unsigned int itemWndNo; +static int jujutuNo = -1; // k?????ӧk? +int itemNo = -1; // k?????????k? +static int itemWndDropGold; // ???? +static int itemWndDropGoldInc; // ????? +static int itemWndDropGoldCnt; // ?????????? + +static int tradeWndDropGold = 0; // trade???? +static int tradeWndDropGoldInc = 0; // trade????? +static int tradeWndDropGoldCnt = 0; // trade?????????? +static int tradeWndDropGoldSend = 0; +static int tradeWndDropGoldGet = 0; +#ifdef _PET_ITEM +static int nSelectPet; // 򿪵ʱ¼Ŀǰõij +#endif + +ACTION *pActPet2; // ?????????????? +BOOL ItemMixRecvFlag; // ?????? +int ItemMixPetNo = -1; // ?????????k? +static unsigned int ItemUseTime = 0; // ??????????? + +// ????????? +ITEM_BUFFER ItemBuffer[MAX_ITEM]; + +#ifdef _PET_ITEM +// ÿһĵһװʱĵͼͼ,ڶDzװʱĵͼͼ +int nPetItemEquipBmpNumber[PET_EQUIPNUM][2] = +{ + {26463, 26470}, {26460, 26467}, {26458, 26465}, {26461, 26468}, {26459, 26466}, + {26457, 26464}, {26462, 26469} +}; +#endif +// ??? +#define MAIL_HISTORY_FILE_NAME "data\\mail.dat" // ??V???? +#ifdef _TRANS_6 +char *TransmigrationStr[ 7 ] = { "","Ҽ","","","","","½" }; +#else +char *TransmigrationStr[6] = { "", "Ҽ", "", "", "", "" }; + +int Transmigrationcolor[6] = {0,4,5,3,6,2}; + + +#endif +static int mailWndFontNo[MENU_MAIL_0]; +static int mailWndBtnFlag[MENU_MAIL_0]; // ??????? +static MAIL_WND_TYPE mailWndNo; // ???????????k? +static MAIL_WND_TYPE mailWndNoBak; // q?????????k? +static int mailViewWndPageNo; // ???????????k? +static int mailSendWndPageNo; // ?G??????????k? +static int mailPetSendWndPageNo; // ?????????????k? +static int mailItemNo; // ??????????????k? +static int mailWndSendFlag[MAX_ADR_BOOK]; // ??????? +int mailHistoryWndPageNo; // ???????????k? +int mailHistoryWndSelectNo; // k?????k? +static int mailHistoryWndNowPageNo; // ??????k? +STR_BUFFER MailStr; // ?? +MAIL_HISTORY MailHistory[MAX_ADR_BOOK]; // ???????? +ACTION *pActLetter[4]; // ????????????????? +ACTION *pActMailItem = NULL; // ???????????????? + +// ???? +#define ALBUM_FILE_NAME "data\\album.dat" // ????V???? +#define ALBUM_FILE_NAME_4 "data\\album_4.dat" // ????V???? +#define ALBUM_FILE_NAME_5 "data\\album_5.dat" // ????V???? +#define ALBUM_FILE_NAME_6 "data\\album_6.dat" // ????V???? +#define ALBUM_FILE_NAME_7 "data\\album_7.dat" // ????V???? +#define ALBUM_FILE_NAME_8 "data\\album_8.dat" // ????V???? +#define ALBUM_FILE_NAME_9 "data\\album_9.dat" // ????V???? +#define ALBUM_FILE_NAME_10 "data\\album_10.dat" // ????V???? +#define ALBUM_FILE_NAME_11 "data\\album_11.dat" // ????V???? +#define ALBUM_FILE_NAME_12 "data\\album_12.dat" +#define ALBUM_FILE_NAME_13 "data\\album_13.dat" +#define ALBUM_FILE_NAME_14 "data\\album_14.dat" +#define ALBUM_FILE_NAME_15 "data\\album_14.dat" +#define ALBUM_FILE_NAME_16 "data\\album_15.dat" +#define ALBUM_FILE_NAME_17 "data\\album_16.dat" +#define ALBUM_FILE_NAME_18 "data\\album_17.dat" +#define ALBUM_FILE_NAME_19 "data\\album_18.dat" +#define ALBUM_FILE_NAME_20 "data\\album_19.dat" +#define ALBUM_FILE_NAME_21 "data\\album_20.dat" +#define ALBUM_FILE_NAME_22 "data\\album_21.dat" +#define ALBUM_FILE_NAME_23 "data\\album_22.dat" +#define ALBUM_FILE_NAME_24 "data\\album_23.dat" +#define ALBUM_FILE_NAME_25 "data\\album_24.dat" +#define ALBUM_FILE_NAME_26 "data\\album_25.dat" +#define ALBUM_FILE_NAME_27 "data\\album_26.dat" +#define ALBUM_FILE_NAME_28 "data\\album_27.dat" +#define ALBUM_FILE_NAME_29 "data\\album_28.dat" +#define ALBUM_FILE_NAME_30 "data\\album_29.dat" +#define ALBUM_FILE_NAME_31 "data\\album_30.dat" +#define ALBUM_FILE_NAME_32 "data\\album_31.dat" +#define ALBUM_FILE_NAME_33 "data\\album_32.dat" +#define ALBUM_FILE_NAME_34 "data\\album_33.dat" +#define ALBUM_FILE_NAME_35 "data\\album_34.dat" +#define ALBUM_FILE_NAME_36 "data\\album_35.dat" +#define ALBUM_FILE_NAME_37 "data\\album_36.dat" +#define ALBUM_FILE_NAME_38 "data\\album_37.dat" +#define ALBUM_FILE_NAME_39 "data\\album_38.dat" +#define ALBUM_FILE_NAME_40 "data\\album_39.dat" +#define ALBUM_FILE_NAME_41 "data\\album_40.dat" +#define ALBUM_FILE_NAME_42 "data\\album_41.dat" +#define ALBUM_FILE_NAME_43 "data\\album_42.dat" +#define ALBUM_FILE_NAME_44 "data\\album_43.dat" +#define ALBUM_FILE_NAME_45 "data\\album_44.dat" +#define ALBUM_FILE_NAME_46 "data\\album_45.dat" +#define ALBUM_FILE_NAME_47 "data\\album_46.dat" +#define ALBUM_FILE_NAME_48 "data\\album_47.dat" + +static int albumWndFontNo[MENU_ALBUM_0]; +static int albumWndBtnFlag[MENU_ALBUM_0]; +static unsigned int albumWndNo; +static int albumWndPageNo; // ???k? +static int albumNo; // ????k? +// ????????????????Bl +PET_ALBUM_TBL PetAlbumTbl[] = { +#include "../systeminc/petName.h" // ??????????? +}; +PET_ALBUM PetAlbum[MAX_PET_KIND]; // ?????Bl +int AlbumIdCnt = 0; // ??????????????????? +// ????????? +int IdEncryptionTbl[16] = { 48, 158, 98, 23, 134, 29, 92, 67, +70, 28, 235, 20, 189, 48, 57, 125 }; + +// Pf??????? +int resultWndFontNo[MENU_BTL_RESULT_0]; // ???Rek? +int ResultWndTimer; // ??????????? + +// ????? +#define TASK_BAR 7 +#define TASK_BAR_X 320 +#define TASK_BAR_Y 468 + DISPLACEMENT_Y +BOOL TaskBarFlag = FALSE; // ???????? +// Terry add 2003/12/16 for Ӵʱ,ʾƷ˵ʾ뷨 +BOOL bShowItemExplain = FALSE; +// end +static int taskBarFontNo[TASK_BAR]; +static int taskBarX = TASK_BAR_X, taskBarY = TASK_BAR_Y + 24; + +// ?????? +unsigned int MenuToggleFlag; +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +#define CHAR_MAX_DETAIL 8 +char CharDetail[CHAR_MAX_DETAIL][16] ; +char DetailDesc[CHAR_MAX_DETAIL][64] = { + "ħԡ" , + "ˮħԡ" , + "ħԡ" , + "ħԡ" , + "ħȣ" , + "ˮħȣ" , + "ħȣ" , + "ħȣ" +}; +#endif +#ifdef _MAG_MENU +int DetailDescicon[CHAR_MAX_DETAIL]={26479, 26475, 26477, 26481, 26478, 26474, 26476, 26480}; +char DetailDescchar[4][4]={"","ˮ","",""}; +#endif + +#ifdef _ALCHEPLUS +int iCharAlchePlus[25]; +char sAlchePlus_list[25][16] = +{ + "ʯ", "ľ", "", "", "Ƥ", + "", "", "צ", "", "Ҷ", + "", "", "", "", "ʯ", + "", "", "˯", "ظ", "", + "ˮ", "", "ˮ", "", "" +}; + +int iAlchePlusIcon[25] = { 26536, 26529, 26545, 26534, 26535, /*"ʯ", "ľ", "", "", "Ƥ"*/ +26540, 26548, 26533, 26541, 26549, /*"", "", "צ", "", "Ҷ"*/ +26551, 26552, 26553, 26542, 26537, /*"", "", "", "", "ʯ"*/ +26546, 26544, 26550, 26538, 26547, /*"", "", "˯", "ظ", ""*/ +26531, 26539, 26530, 26532, 26543 }; /*"ˮ", "", "ˮ", "", ""*/ +#endif + +// ?????????????? +ACTION *pActMenuWnd; +ACTION *pActMenuWnd2; +ACTION *pActMenuWnd3; +ACTION *pActMenuWnd4; +ACTION *pActYesNoWnd; +ACTION *pActMenuWnd5; + + +void checkRidePet(int); +//andy_add 2002/06/24 +int RIDEPET_getNOindex(int baseNo); +int RIDEPET_getPETindex(int PetNo, int learnCode); +int RIDEPET_getRIDEno(int index, int ti); + +#ifdef RIDE_PET_LIMIT +int RIDEPET_getPETindex_New(int PetNo, int learnCode); +#endif + +static char *monoStereoStr[] = { " ", +" " }; + +static char *mouseCursor[] = { " ", +" ƽ " }; + +#define WINDOW_CREATE_FRAME 10 // ?????????????? + +// ???????????????? +extern unsigned char crs_change_tbl[]; +// ???????????????? +extern unsigned char crs_change_tbl2[]; +// T???? +extern unsigned char crs_bound_tbl[][32]; + +#ifdef _STREET_VENDOR +extern short sStreetVendorBuyBtn; +#endif + +#ifdef __ONLINEGM +extern BOOL OnlineGmFlag; +#endif + +#ifdef _PET_ITEM +/* 0x01:PET_HEAD // ͷ + 0x02:PET_WING // + 0x04:PET_TOOTH // + 0x08:PET_PLATE // + 0x10:PET_BACK // + 0x20:PET_CLAW // צ + 0x40:PET_FOOT // () + */ +// ֵͬijװͲװIJλ +unsigned char byShowPetItemBackground[MAX_PET_SPECIES + 1] = +{ + /* ȭ ˿˶ ڱ */ + 0x5d, 0x5d, 0x7d, 0x5d, 0x5d, 0x7d, 0x5f, 0x5d, 0x5f, 0x7f, + /* ͷ ڹ ΰ */ + 0x5d, 0x5d, 0x5d, 0x5d, 0x5d, 0x7d, 0x7d, 0x5d, 0x5d, 0x7d, + /* ˮ Ϳ ϻ ë ϵ ϵ ɽ ϵ ϵ*/ + 0x5d, 0x7d, 0x7d, 0x5d, 0x5d, 0x5f, 0x5d, 0x5d, 0x09, 0x1d, + /* С Ƥ Ϻз ϵ ţϵ ϵ*/ + 0x5d, 0x79, 0x1d, 0x5d, 0x79, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d, + /* ϵ ϵ ںϳ*/ + 0x5d, 0x5d, 0x00 +}; +#endif + +int charDetailPage = 3; + +#ifdef _ITEM_JIGSAW +bool DrawJigsawFlag = false; +int JigsawIdx = 0; +int JigsawImg[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; +int JigsawOK[][3] = {//ͼ,һͼ,ͼͼ + { 25151, 25261, 25241 }, { 25152, 25270, 25242 }, { 25153, 25279, 25243 }, { 25154, 25288, 25244 }, { 25155, 25297, 25245 }, { 25156, 25306, 25246 }, { 25157, 25315, 25247 }, { 25158, 25324, 25248 }, { 25159, 25333, 25249 }, { 25150, 25252, 25250 } +}; +void SetJigsaw(int img, char *str) +{ + int i, start; + for (i = 0; i < 10; i++){ + if (img == JigsawOK[i][0]){ + JigsawImg[0] = JigsawOK[i][2]; + start = JigsawOK[i][1]; + break; + } + } + for (i = 0; i < 9; i++){ + if (str[i] == '1') + JigsawImg[i + 1] = start + i; + else + JigsawImg[i + 1] = -1; + } +} +bool CheckJigsaw(int img) +{ + if (img >= 25151 && img <= 25240) + return true; + return false; +} +#endif + +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ +bool SkillWndflag = false ; +short SkillWnd = 0 ; +ACTION *pActSkillMenuWnd; +void SkillWndfunc2() { + int x =0, y=0, j=0 ; + char buf[256]; + char msg[256]; + char msg2[256]; + if( pActSkillMenuWnd == NULL ) { + pActSkillMenuWnd = MakeWindowDisp( 354 , 0, 300, 456, 0, -1 ); + }else{ + if( pActSkillMenuWnd->hp > 0 ){ + StockDispBuffer( ( ( WINDOW_DISP *)pActSkillMenuWnd->pYobi )->mx - 10, ( ( WINDOW_DISP *)pActSkillMenuWnd->pYobi )->my - 5 , DISP_PRIO_MENU, CG_FIELD_SKILL_PANEL, 1 ); + x = pActSkillMenuWnd->x + 2; + y = pActSkillMenuWnd->y - 5; + statusWndFontNo[ 15 ] = StockDispBuffer( x + 201, y + 442, DISP_PRIO_IME3, CG_CLOSE_BTN , 2 ) ; + StockFontBuffer( x + 58 , y + 40 , FONT_PRIO_FRONT, 1 , pc.profession_class_name , 0 ); + sprintf_s( msg , "%d" , pc.profession_skill_point ) ; + StockFontBuffer( x + 228 , y + 40 , FONT_PRIO_FRONT, 1 , msg , 0 ); + memset( msg, -1, sizeof( msg ) ); + } + } + for ( int i = 0 ; i < 3 ; i ++ ) { +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if( MakeHitBox( x + 254 , y + 15 + i * 78, x + 284 , y + 93 + i * 78 , DISP_PRIO_IME3 ) == TRUE ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + SkillWnd = i ; + play_se( 217, 320, 240 ); + break; + } + } + } + else +#endif + if( MakeHitBox( x + 250 , y + 18 + i * 79, x + 280 , y + 96 + i * 79 , DISP_PRIO_IME3 ) == TRUE ) { + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + SkillWnd = i ; + play_se( 217, 320, 240 ); + break; + } + } + } + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + if( HitDispNo == statusWndFontNo[ 15 ] ) { + SkillWndflag = false ; + play_se( 217, 320, 240 ); + } + } + extern int BattleSkill[20]; + extern int AssitSkill[20]; + extern int AdvanceSkill[20]; + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( j = 0 ; j < 4 ; j ++ ) { + StockDispBuffer( x + 143 + j * 60 , y + 210 + i * 57 , DISP_PRIO_IME3, CG_FIELD_SKILL_TILE , 0 ); + } + } + sprintf_s( msg , " "); + switch ( SkillWnd ) { + case 0 : +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( x + 147, y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT , 0 ); + else +#endif + StockDispBuffer( x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_ASSIT , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + if ( AssitSkill [ j + i * 4 ] == -1 ) + break; + if ( HitDispNo == StockDispBuffer( x + 29 + j * 60 , y + 102 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ AssitSkill [ j + i * 4 ] ].icon , 2 ) ) { + + int use_color = 0; + if( pc.mp >= profession_skill[AssitSkill [ j + i * 4 ]].costmp && profession_skill[AssitSkill [ j + i * 4 ]].costmp != 0 ){ + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } + + sprintf_s( msg , "%s" , profession_skill[AssitSkill [ j + i * 4 ]].name ); + StockFontBuffer( 355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%d", profession_skill[AssitSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "(ķMP:%d)" , profession_skill[AssitSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%s" , profession_skill[AssitSkill [ j + i * 4 ]].memo ) ; +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if ( mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[ AssitSkill [ j + i * 4 ] ].useFlag == 0 ) { + if( pc.mp >= profession_skill[AssitSkill [ j + i * 4 ]].costmp && profession_skill[AssitSkill [ j + i * 4 ]].costmp != 0 ) { + lssproto_BATTLESKILL_send ( sockfd , AssitSkill [ j + i * 4 ] ) ; + play_se( 217, 320, 240 ); + } + } +#endif + } + sprintf_s( msg2 , "%8s" , profession_skill[AssitSkill [ j + i * 4 ]].name ); + StockFontBuffer(x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, profession_skill[ AssitSkill [ j + i * 4 ] ].useFlag + 1 , msg2 , 2 ); + } + } + break; + case 1 : +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( x + 147, y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE , 0 ); + else +#endif + StockDispBuffer( x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_BATTLE , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( j = 0 ; j < 4 ; j ++ ) { + if ( BattleSkill [ j + i * 4 ] == -1 ) + break; + if ( HitDispNo == StockDispBuffer( x + 29 + j * 60 , y + 102 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ BattleSkill [ j + i * 4 ] ].icon , 2 ) ) { + + int use_color = 0; + if( pc.mp >= profession_skill[BattleSkill [ j + i * 4 ]].costmp && profession_skill[BattleSkill [ j + i * 4 ]].costmp != 0 ){ + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } + + sprintf_s( msg , "%s" , profession_skill[BattleSkill [ j + i * 4 ]].name ); + StockFontBuffer( 355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%d", profession_skill[BattleSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "(ķMP:%d)" , profession_skill[BattleSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%s" , profession_skill[BattleSkill [ j + i * 4 ]].memo ) ; +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if ( mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[ BattleSkill [ j + i * 4 ]].useFlag == 0 ) { + if( pc.mp >= profession_skill[BattleSkill [ j + i * 4 ]].costmp && profession_skill[BattleSkill [ j + i * 4 ]].costmp != 0 ) { + lssproto_BATTLESKILL_send ( sockfd , BattleSkill [ j + i * 4 ] ) ; + play_se( 217, 320, 240 ); + } + } +#endif + } + sprintf_s( msg2 , "%8s" , profession_skill[BattleSkill [ j + i * 4 ]].name ); + StockFontBuffer(x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, profession_skill[ BattleSkill [ j + i * 4 ]].useFlag + 1 , msg2 , 0 ); + } + } + break; + case 2: +#ifdef _READ16BITBMP + if(g_bUseAlpha) StockDispBuffer( x + 147, y + 225, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK , 0 ); + else +#endif + StockDispBuffer( x + 138, y + 228, DISP_PRIO_IME3, CG_FIELD_SKILL_ADVSK , 0 ); + for ( int i = 0 ; i < 4 ; i ++ ) { + for ( j = 0 ; j < 4 ; j ++ ) { + if ( AdvanceSkill [ j + i * 4 ] == -1 ) + break; + if ( HitDispNo == StockDispBuffer( x + 29 + j * 60 , y + 102 + i * 57 , DISP_PRIO_IME3 + 1 , profession_skill[ AdvanceSkill [ j + i * 4 ] ].icon , 2 ) ) { + + int use_color = 0; + if( pc.mp >= profession_skill[AdvanceSkill [ j + i * 4 ]].costmp && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp != 0 ){ + use_color = FONT_PAL_WHITE; + }else{ + use_color = FONT_PAL_GRAY; + } + + sprintf_s( msg , "%s" , profession_skill[AdvanceSkill [ j + i * 4 ]].name ); + StockFontBuffer( 355, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%d", profession_skill[AdvanceSkill [ j + i * 4 ]].skill_level ) ; + StockFontBuffer( 440, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "(ķMP:%d)" , profession_skill[AdvanceSkill [ j + i * 4 ]].costmp ); + StockFontBuffer( 500, 310 + DISPLACEMENT_Y, FONT_PRIO_FRONT, use_color, msg, 0 ); + + sprintf_s( msg , "%s" , profession_skill[AdvanceSkill [ j + i * 4 ]].memo ) ; +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + if ( mouse.onceState & MOUSE_LEFT_CRICK && profession_skill[AdvanceSkill [ j + i * 4 ]].useFlag == 0 ) { + if( pc.mp >= profession_skill[AdvanceSkill [ j + i * 4 ]].costmp && profession_skill[AdvanceSkill [ j + i * 4 ]].costmp != 0 ) { + lssproto_BATTLESKILL_send ( sockfd , AdvanceSkill [ j + i * 4 ] ) ; + play_se( 217, 320, 240 ); + } + } +#endif + } + sprintf_s( msg2 , "%8s" , profession_skill[AdvanceSkill [ j + i * 4 ]].name ); + StockFontBuffer(x + j * 60 , y + 110 + i * 57 , FONT_PRIO_FRONT, profession_skill[AdvanceSkill [ j + i * 4 ]].useFlag + 1 , msg2 , 0 ); + } + } + break; + } + char *splitPoint = msg ; + sprintf_s( buf , "%s" , msg ) ; + x = 355 ; + y = 340 ; + while( 1 ){ + if( strlen( splitPoint ) > 34 ) { + strncpy_s( msg, splitPoint, 34 ); + buf[ 34 ] = NULL; + if( GetStrLastByte( buf ) == 3 ){ + buf[ 33 ] = NULL; + splitPoint += 33; + }else{ + buf[ 34 ] = NULL; + splitPoint += 34; + } + StockFontBuffer( x, y , FONT_PRIO_FRONT, 0, buf, 0 ); y += 24; + }else{ + strcpy( buf, splitPoint ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, buf, 0 ); + break; + } + } +} +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի +void TradeTalk(char *msg) { + char buf[256]; + if (pActMenuWnd4 != NULL || SecondTradeWnd != NULL) { + sprintf_s(buf, "%s", msg); + //жǷ˫˵ + if (strstr(buf, pc.name) || strstr(buf, opp_name)) { + //ת + while (1){ + if (strlen(msg) > 44) { + strncpy_s(buf, msg, 44); + buf[44] = NULL; + if (GetStrLastByte(buf) == 3){ + buf[43] = NULL; + msg += 43; + } + else{ + buf[44] = NULL; + msg += 44; + } + for (int i = 0; i < 3; i++) + strcpy(talkmsg[i], talkmsg[i + 1]); + sprintf_s(talkmsg[3], "%s", buf); + } + else{ + for (int i = 0; i < 3; i++) + strcpy(talkmsg[i], talkmsg[i + 1]); + strcpy(buf, msg); + sprintf_s(talkmsg[3], "%s", buf); + break; + } + } + tradetalkwndflag = true; + } + } +} +#endif +void LockAndOkfunction() +{ + char buffer[1024]; + char myitembuff[1024]; + char mypetbuff[1024]; + char oppitembuff[1024]; + char opppetbuff[1024]; + // ˫԰ȷ״̬ + if (pc.trade_confirm == 4) { + // ȷ + if ((MainTradeWndflag == true && HitDispNo == tradeWndFontNo[0]) || + //andy_reEdit 2003/04/27 + (SecondTradeWndflag == true && HitDispNo == SecondtradeWndFontNo[2])){ + // ˫Ʒbuffer + sprintf_s(myitembuff, "T|%s|%s|K|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|" + , opp_sockfd, opp_name + , tradeList[1].data, tradeList[2].data + , tradeList[3].data, tradeList[4].data + , tradeList[5].data, tradeList[6].data + , tradeList[7].data, tradeList[8].data + , tradeList[9].data, tradeList[10].data + , tradeList[11].data, tradeList[12].data + , tradeList[13].data, tradeList[14].data + , tradeList[15].data); + sprintf_s(mypetbuff, "P|%d|P|%d|P|%d|P|%d|P|%d|G|%d|" + , tradeList[16].data, tradeList[17].data + , tradeList[18].data, tradeList[19].data + , tradeList[20].data, tradeList[21].data); + sprintf_s(oppitembuff, "I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|I|%d|" + , tradeList[22].data, tradeList[23].data + , tradeList[24].data, tradeList[25].data + , tradeList[26].data, tradeList[27].data + , tradeList[28].data, tradeList[29].data + , tradeList[30].data, tradeList[31].data + , tradeList[32].data, tradeList[33].data + , tradeList[34].data, tradeList[35].data + , tradeList[36].data); + sprintf_s(opppetbuff, "P|%d|P|%d|P|%d|P|%d|P|%d|G|%d|" + , tradeList[37].data, tradeList[38].data + , tradeList[39].data, tradeList[40].data + , tradeList[41].data, tradeList[42].data); + sprintf_s(buffer, "%s%s%s%s", myitembuff, mypetbuff, oppitembuff, opppetbuff); + lssproto_TD_send(sockfd, buffer); + tradeStatus = 2; + } + } + // ԷLockҷҪLock + if (pc.trade_confirm == 1 || pc.trade_confirm == 3) { + if ((MainTradeWndflag == true && HitDispNo == tradeWndFontNo[0]) || + //andy_reEdit 2003/04/27 + (SecondTradeWndflag == true && HitDispNo == SecondtradeWndFontNo[2])) { + //ԷδLock״̬ 2 + if (pc.trade_confirm == 1) pc.trade_confirm = 2; + //ԷѾLock״̬ 4 + if (pc.trade_confirm == 3) pc.trade_confirm = 4; + sprintf_s(buffer, "T|%s|%s|C|confirm", opp_sockfd, opp_name); + lssproto_TD_send(sockfd, buffer); + } + } + // Lock ȷ End +} +#endif + +// ?????????? ***************************************************/ +void WindowDisp(ACTION *pAct) +{ + // ??Bl????? + WINDOW_DISP *pYobi = (WINDOW_DISP *)pAct->pYobi; + int i, j; + int x = pAct->x + 32, y = pAct->y + 24; + // ?hk??? + switch (pAct->actNo){ + + case 0: // ???????? + + StockBoxDispBuffer(pYobi->mx - pYobi->nowX, + pYobi->my - pYobi->nowY, + pYobi->mx + pYobi->nowX, + pYobi->my + pYobi->nowY, + pYobi->boxDispPrio, SYSTEM_PAL_BLACK, 0); + // ???? + pYobi->nowX += pAct->dx; + pYobi->nowY += pAct->dy; + // ???????? + pYobi->cnt++; + // ???????? + if (pYobi->cnt >= WINDOW_CREATE_FRAME){ + // ????? + if (pYobi->wndType == -1) pAct->actNo = 1; + else + // ?_??????? + if (pYobi->wndType == -2) pAct->actNo = 3; + else pAct->actNo = 2; + } + break; + case 1: // ????? + pAct->hp = 1; + break; + case 2: // ?????? + for (j = 0; j < pYobi->sizeY; j++){ + // Ƥ + if (j == 0){ + for (i = 0; i < pYobi->sizeX; i++){ + // ?Z + if (i == 0) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 0, pYobi->hitFlag); + // ?Z + else if (i == pYobi->sizeX - 1) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 2, pYobi->hitFlag); + // ?? +#ifdef _READ16BITBMP + else if(g_bUseAlpha){ + if(pYobi->wndType == CG_WND_G_0) StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 1, pYobi->hitFlag ); + else if(pYobi->wndType == CG_WND2_G_0)StockDispBuffer( x, y+1, DISP_PRIO_MENU, pYobi->wndType + 1, pYobi->hitFlag ); + else StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 1, pYobi->hitFlag ); + } +#endif + else StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 1, pYobi->hitFlag); + x += 64; // ???? + } + } + else + // ? + if (j == pYobi->sizeY - 1){ + for (i = 0; i < pYobi->sizeX; i++){ + // ?Z + if (i == 0) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 6, pYobi->hitFlag); + // ?Z + else if (i == pYobi->sizeX - 1) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 8, pYobi->hitFlag); + // ?? +#ifdef _READ16BITBMP + else if(g_bUseAlpha){ + if(pYobi->wndType == CG_WND_G_0) StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 7, pYobi->hitFlag ); + else if(pYobi->wndType == CG_WND2_G_0) StockDispBuffer( x, y-1, DISP_PRIO_MENU, pYobi->wndType + 7, pYobi->hitFlag ); + else StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 7, pYobi->hitFlag ); + } +#endif + else StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 7, pYobi->hitFlag); + x += 64; // ???? + } + } + else + // ?? + for (i = 0; i < pYobi->sizeX; i++){ + // ?Z + if (i == 0) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 3, pYobi->hitFlag); + // ?Z +#ifdef _READ16BITBMP + else if(g_bUseAlpha){ + if( i == pYobi->sizeX - 1 ){ + if(pYobi->wndType == CG_WND_G_0) StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 5, pYobi->hitFlag ); + else if(pYobi->wndType == CG_WND2_G_0) StockDispBuffer( x-1, y, DISP_PRIO_MENU, pYobi->wndType + 5, pYobi->hitFlag ); + } + else if( i == pYobi->sizeX - 1 ) StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 5, pYobi->hitFlag ); + else StockDispBuffer( x, y, DISP_PRIO_MENU, pYobi->wndType + 4, pYobi->hitFlag ); + } +#endif + else if (i == pYobi->sizeX - 1) StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 5, pYobi->hitFlag); + // ?? + else StockDispBuffer(x, y, DISP_PRIO_MENU, pYobi->wndType + 4, pYobi->hitFlag); + x += 64; // ???? + } + x = pAct->x + 32; // ?Z??? + y += 48; // ???? + } + // ????? + if (pYobi->titleNo != 0) StockDispBuffer(pYobi->titleX, pYobi->titleY, DISP_PRIO_IME3, pYobi->titleNo, pYobi->hitFlag); + pAct->hp = 1; + break; + case 3: // ?_????? + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???? + if (HitDispNo == pYobi->yesDispNo){ + pYobi->yesNoResult = TRUE; + } + // ????? + if (HitDispNo == pYobi->noDispNo){ + pYobi->yesNoResult = FALSE; + } + } + // ?_????????? + StockDispBuffer(pYobi->mx, pYobi->my, DISP_PRIO_YES_NO_WND, CG_COMMON_WIN_YORO, 1); + // ????? + pYobi->yesDispNo = StockDispBuffer(pYobi->mx, pYobi->my, DISP_PRIO_YES_NO_BTN, CG_COMMON_YES_BTN, 2); + // ?????? + pYobi->noDispNo = StockDispBuffer(pYobi->mx, pYobi->my, DISP_PRIO_YES_NO_BTN, CG_COMMON_NO_BTN, 2); + break; + } +} + +// ????????? **************************************************************/ +// ?? int x,y ???? +// int sizeX,sizeY ????????????O????????????O?? +// int titleNo ????????????k????????????? +// int wndType ???????????Re??? +// ????????????Re??? +// ???????????Re?? +// ????????????Re?? +// ??_?????????Re??? +// -1??? +//****************************************************************************************/ +ACTION *MakeWindowDisp(int x, int y, int sizeX, int sizeY, int titleNo, int wndType +#ifdef _NEW_RESOMODE //800 600ģʽ + , BOOL fixType /*= TRUE*/ +#endif + ) +{ + ACTION *pAct; + WINDOW_DISP *pYobi; +#ifdef _NEW_RESOMODE //800 600ģʽ + if (fixType == TRUE){ + if (x > 320){ + x += DISPLACEMENT_X; + } + else if (x > 40) + { + x += DISPLACEMENT_X / 2; + } + if (y > 40) + y += DISPLACEMENT_Y / 2; + } +#endif + pAct = GetAction(PRIO_JIKI, sizeof(WINDOW_DISP)); + if (pAct == NULL) return NULL; + + // ??? + pAct->func = WindowDisp; + // ?IT + pAct->dispPrio = DISP_PRIO_MENU; + // ???Re?? + pAct->atr |= ACT_ATR_HIT; + // ??? + pAct->atr |= ACT_ATR_HIDE; + + // ??Bl????? + pYobi = (WINDOW_DISP *)pAct->pYobi; + // ???? + pAct->x = x; + pAct->y = y; + pYobi->titleX = x + (sizeX * 64) / 2; + pYobi->titleY = pAct->y + 27; + // ?????? + pYobi->sizeX = sizeX; + pYobi->sizeY = sizeY; + // ????k??? + pYobi->titleNo = titleNo; + pYobi->boxDispPrio = DISP_PRIO_MENU; + // ?????????? + if (wndType == 0) pYobi->wndType = CG_WND_G_0; + else if (wndType == 1) pYobi->wndType = CG_WND_G_0; + else if (wndType == 2) pYobi->wndType = CG_WND_G_0; + else if (wndType == 3) pYobi->wndType = CG_WND_G_0; + else if (wndType == 4){ + pYobi->wndType = -2; + // ???Re??? + pYobi->yesDispNo = -2; + pYobi->noDispNo = -2; + pYobi->boxDispPrio = DISP_PRIO_YES_NO_WND; + } + else pYobi->wndType = -1; + + // YesNo ?????? + pYobi->yesNoResult = -1; + + // ???Re??? + if (wndType >= 2) pYobi->hitFlag = FALSE; + else pYobi->hitFlag = TRUE; + + // ??? + // ?????????_??????? + if (wndType == -1 || wndType == 4){ + pYobi->mx = sizeX / 2 + pAct->x; + pYobi->my = sizeY / 2 + pAct->y; + } + else{ // [???????? + pYobi->mx = (sizeX * 64) / 2 + pAct->x; + pYobi->my = (sizeY * 48) / 2 + pAct->y; + } + // ?? + pAct->dx = (pYobi->mx - pAct->x) / WINDOW_CREATE_FRAME; + pAct->dy = (pYobi->my - pAct->y) / WINDOW_CREATE_FRAME; + + return pAct; +} + +// ???????????? ***********************************************/ +void AnimDisp(ACTION *pAct) +{ + int flag = FALSE; + int x, y, i; + + // ????? + switch (pAct->actNo){ + + case ANIM_DISP_PET: // ??? + + // ???????? + if (pAct->hitDispNo == HitDispNo && mouse.autoState & MOUSE_LEFT_CRICK) + { + // ?? + pAct->anim_ang++; + // ???????? + if (pAct->anim_ang >= 8) pAct->anim_ang = 0; + play_se(217, 320, 240); // ????? + } + // ??????? + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + + break; + + case ANIM_DISP_PET_SEND: // ?????????????h + + // h?k? + pAct->anim_no = ANIM_WALK; + // ?????????( ??? )( ??????? ) + pAct->anim_ang = 2; + // ? + pAct->crs = crs_change_tbl2[pAct->anim_ang]; + // ????? + pAct->dx++; + // ?????????L + if (pAct->dx % 3 == 0){ + // ?????L + if (pAct->spd < 20){ + pAct->spd++; + } + } + // ?????????L + if (pAct->dx % 5 == 0){ + if (pAct->dy >= 2) pAct->dy--; + } + // ?h?? + gemini(pAct); + + // ??????? + if (pActMailItem != NULL){ + // ?????????? + if (pAct->x <= pActMailItem->x){ + pActMailItem->x = pAct->x; + } + } + // ????????????? + if (pAct->x <= -100){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ???????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ???????? + mailWndNo = MAIL_WND_VIEW; + // ???????? + play_se(203, 320, 240); + // V???????? + GetKeyInputFocus(&MyChatBuffer); + } + // ??????? + pattern(pAct, pAct->dy, ANM_LOOP); + + break; + + case ANIM_DISP_PET_RECIEVE: // ???????????h + + // h?k? + pAct->anim_no = ANIM_WALK; + // ?????????( ??? )( ??????? ) + pAct->anim_ang = 6; + // ? + pAct->crs = crs_change_tbl2[pAct->anim_ang]; + // ????? + pAct->dx++; + // ?????L + if (pAct->spd > 0){ + // ?????????L + if (pAct->dx % 3 == 0){ + pAct->spd--; + // ??????h???? + if (pAct->spd <= 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + // ??????? + if (pActMailItem != NULL){ + pActMailItem->dispPrio = DISP_PRIO_BOX3; + } + } + } + } + // ?????????L + if (pAct->dx % 8 == 0){ + // ????????L + if (pAct->dy < 12) pAct->dy++; + } + // ?h?? + gemini(pAct); + + // ??????? + if (pActMailItem != NULL){ + // ?????????? + if (pAct->x >= pActMailItem->x){ + pActMailItem->x = pAct->x; + } + } + // ??????? + pattern(pAct, pAct->dy, ANM_LOOP); + + break; + + case ANIM_DISP_PET_MAIN: // ?????hk?? + + // ????? + if (Rnd(0, 4) >= 2){ + pAct->actNo = ANIM_DISP_PET_WALK; + // ????? + pAct->anim_ang = Rnd(0, 7); + // ???@e + pAct->crs = crs_change_tbl2[pAct->anim_ang]; + // ?????h???? + pAct->spd = Rnd(1, 12); + // ??????????? + pAct->dy = 13 - pAct->spd; + } + else pAct->actNo = Rnd(ANIM_DISP_PET_STAND, ANIM_DISP_PET_DEAD); + + // q????????????? + pAct->anim_no_bak = -1; + + break; + + case ANIM_DISP_PET_WALK: // ? + + // h?k? + pAct->anim_no = ANIM_WALK; + + // ?h?? + gemini(pAct); + + // ??????? + if (pattern(pAct, pAct->dy, ANM_NO_LOOP)){ + // ??????? + if (Rnd(0, 3) == 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + } + else{ + // q????????????? + pAct->anim_no_bak = -1; + } + } + if (pActPet == NULL || pActMenuWnd == NULL){ + return; + } + // ???????? + // + if (pActPet->y < pActMenuWnd->y + 64){ + pActPet->y = pActMenuWnd->y + 64; + // ???@e + pAct->crs = crs_bound_tbl[0][pAct->crs]; + // ??@e + pAct->anim_ang = crs_change_tbl[pAct->crs]; + } + // ? + if (pActPet->y > pActMenuWnd->y + 424 - 32){ + pActPet->y = pActMenuWnd->y + 424 - 32; + // ???@e + pAct->crs = crs_bound_tbl[2][pAct->crs]; + // ??@e + pAct->anim_ang = crs_change_tbl[pAct->crs]; + } + // ? + if (pActPet->x < pActMenuWnd->x + 32){ + pActPet->x = pActMenuWnd->x + 32; + // ???@e + pAct->crs = crs_bound_tbl[3][pAct->crs]; + // ??@e + pAct->anim_ang = crs_change_tbl[pAct->crs]; + } + // ? + if (pActPet->x > pActMenuWnd->x + 272 - 32){ + pActPet->x = pActMenuWnd->x + 272 - 32; + // ???@e + pAct->crs = crs_bound_tbl[1][pAct->crs]; + // ??@e + pAct->anim_ang = crs_change_tbl[pAct->crs]; + } + break; + + case ANIM_DISP_PET_STAND: // r? + + // h?k? + pAct->anim_no = ANIM_STAND; + + // ??????? + if (pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP)){ + // ??????? + pAct->actNo = ANIM_DISP_PET_MAIN; + } + + break; + + case ANIM_DISP_PET_ATTACK: // ?? + + // h?k? + pAct->anim_no = ANIM_ATTACK; + + // ??????? + if (pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP)){ + // ??????? + if (Rnd(0, 1) == 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + } + else{ + // q????????????? + pAct->anim_no_bak = -1; + } + } + + break; + + case ANIM_DISP_PET_GUARD: // ??? + + // h?k? + pAct->anim_no = ANIM_GUARD; + + // ??????? + if (pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP)){ + // ??????? + if (Rnd(0, 1) == 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + } + } + + break; + + case ANIM_DISP_PET_DAMAGE: // ???? + + // h?k? + pAct->anim_no = ANIM_DAMAGE; + + // ??????? + if (pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP)){ + // ??????? + if (Rnd(0, 1) == 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + } + else{ + // q????????????? + pAct->anim_no_bak = -1; + } + } + + break; + + case ANIM_DISP_PET_DEAD: // ? + + // h?k? + pAct->anim_no = ANIM_DEAD; + + // ??????? + if (pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP)){ + // ??????? + if (Rnd(0, 2) == 0){ + pAct->actNo = ANIM_DISP_PET_MAIN; + } + } + + break; + + case ANIM_DISP_PET_ITEM: // ???????? + + // ??????? + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + + break; + + case ANIM_DISP_LETTER_MOVE: // ??h + + // ?h + if (pAct->x < 245) pAct->x += 5; + // ????????? + else{ + pAct->actNo = ANIM_DISP_LETTER; + // ??????? + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + pAct->anim_cnt += 8; + } + break; + + case ANIM_DISP_LETTER: // ???????? + + // ??????? + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + + break; + + case ANIM_DISP_MIX_PET_INIT: // ??????? + + // ?????h???? + pAct->spd = 11;//Rnd( 6, 12 ); + // ??????????? + pAct->dy = 14 - pAct->spd; + + // h?k? + pAct->anim_no = ANIM_WALK; + + // ????????S? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + if (ItemBuffer[i].mixFlag >= 1){ + pAct->dx = i; + break; + } + } + // ?h? + + + pAct->actNo = ANIM_DISP_MIX_PET_MOVE; + break; + + case ANIM_DISP_MIX_PET_MOVE: // ?????????h + + // ?ԡ@e + x = ItemBuffer[pAct->dx].defX; + y = ItemBuffer[pAct->dx].defY; + + // ???? + radar(pAct, &x, &y); + + // h?k? + pAct->anim_no = ANIM_WALK; + + // ????????? + if (y >= pAct->spd / 2){ + // ???@e + pAct->crs = x; + // ??@e??Ԩ???????? + if (pAct->level == FALSE){ + pAct->anim_ang = crs_change_tbl[pAct->crs]; + // ?????????? + pAct->level = TRUE; + } + + // ?h?? + gemini(pAct); + // ??????? + pattern(pAct, pAct->dy, ANM_LOOP); + } + // ????? + else{ + // ??????????? + pAct->level = FALSE; + // ?????? + play_se(204, 320, 240); + + // ?????????????? + if (pAct->delta == 1){ + // ??????? + pAct->actNo = ANIM_DISP_MIX_PET_MOJI; + // h?k? + pAct->anim_no = ANIM_STAND; + + // ?????h???? + pAct->spd = 10;//Rnd( 6, 12 ); + // ??????????? + pAct->dy = 14 - pAct->spd; + + // ?????? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + if (ItemBuffer[i].mixFlag >= 1){ + ItemBuffer[i].mixFlag = 4; + } + } + + // ???????????? + pAct->delta = Rnd(2, 15); + pAct->mp = 15; + break; + } + + // ?h????w??? + pAct->spd = (int)((double)pAct->spd * 0.79); + // ???????? + if (pAct->spd < 2) pAct->spd = 2; + // ??????????? + pAct->dy = 13 - pAct->spd; + + // ?????????????? +#ifdef _ITEM_UPINSLAY + if( ItemBuffer[ pAct->dx ].mixFlag != 12 + && ItemBuffer[ pAct->dx ].mixFlag != 13 ) +#endif + ItemBuffer[pAct->dx].mixFlag = 3; + + // ???????S? + for (i = pAct->dx + 1; i < MAX_ITEM; i++){ + if (ItemBuffer[i].mixFlag >= 1){ + pAct->dx = i; + break; + } + } + + // ???????? + if (i >= MAX_ITEM){ + // ???????????S? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + // ??????????? + if (pc.item[i].useFlag == FALSE){ + // ????e + pAct->dx = i; + break; + } + else + // ???????????? + if (ItemBuffer[i].mixFlag >= 1){ + // ????e + pAct->dx = i; + break; + } + } + // ???????????? + pAct->delta = 1; + } + } + break; + + case ANIM_DISP_MIX_PET_MOJI: // ????????????? + + // ??????? + pattern(pAct, 1, ANM_LOOP); + // ?????? + if (pAct->maxHp >= pAct->mp) pAct->maxHp = 0; + else{ + pAct->maxHp++; + break; + } + // ?????? + switch (pAct->hp){ + + // ??? + case 0: + case 3: + // ??@e + pAct->anim_ang++; + // ???????? + if (pAct->anim_ang >= 8) pAct->anim_ang = 0; + // ????? + if (pAct->hp == 0){ + // ?????? + play_se(216, 320, 240); + } + // ??????? + if (pAct->hp == 3){ + pAct->dir++; + pAct->hp = 0; + // ?????? + pAct->mp--; + if (pAct->mp < 4) pAct->mp = 4; + } + else pAct->hp++; + break; + + // ??? + case 1: + case 2: + // ??@e + pAct->anim_ang--; + // ???????? + if (pAct->anim_ang < 0) pAct->anim_ang = 7; + pAct->hp++; + break; + } + + // ??????? + if (pAct->dir >= pAct->delta){ + // ??? + if (pAct->dir == pAct->delta){ + pAct->dir++; + // ???? + char moji[256]; + // ???? + moji[0] = NULL; + // ???????????? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + // ?????????? + if (ItemBuffer[i].mixFlag >= TRUE){//ttom + char work[256]; + // ??? + sprintf_s(work, "%d|", i); + strcat_s(moji, work); + // ?????? + }//ttom + } + // ???|???????? + moji[strlen(moji) - 1] = NULL; + + // ?????????????????? + if (bNewServer) + lssproto_PS_send(sockfd, mixPetNo, SelectWazaNo, 0, moji); + else + old_lssproto_PS_send(sockfd, mixPetNo, SelectWazaNo, 0, moji); + // r?????? + ItemMixRecvFlag = TRUE; + } + + // r?????? + if (ItemMixRecvFlag == FALSE){ + // ?????? + play_se(115, 320, 240); + // ???????? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + ItemBuffer[i].mixFlag = FALSE; + } + // ?????h???? + pAct->spd = 11; + // ??????????? + pAct->dy = 14 - pAct->spd; + // ??? + pAct->actNo = ANIM_DISP_MIX_PET_END; + } + } + + break; + + case ANIM_DISP_MIX_PET_END: // ??????? + + // ?ԡ@e + x = 750; + y = 240; + + // ???? + radar(pAct, &x, &y); + + // h?k? + pAct->anim_no = ANIM_WALK; + + // ????????? + if (y >= pAct->spd / 2){ + // ???@e + pAct->crs = x; + + // ??@e??Ԩ???????? + if (pAct->level == FALSE){ + pAct->anim_ang = crs_change_tbl[pAct->crs]; + // ?????????? + pAct->level = TRUE; + } + + // ?h?? + gemini(pAct); + // ??????? + pattern(pAct, pAct->dy, ANM_LOOP); + } + // ????? + else{ + // ?????? + DeathAction(pAct); + pActPet2 = NULL; + // ????k???? + ItemMixPetNo = -1; + } + break; +#ifdef _AniCrossFrame // Syu ADD ι + case ANIM_DISP_CROSSFRAME: + { + extern bool delFlag; + extern bool flag22; + pAct->anim_no = ANIM_WALK; + pAct->anim_ang = 2; + pAct->crs = crs_change_tbl2[pAct->anim_ang]; + //ƶٶ + pAct->spd = 1; + //ʾ㼶 + pAct->dispPrio = DISP_PRIO_JIKI; + if (pAct->dx % 5 == 0){ + if (pAct->dy >= 2) pAct->dy--; + } + gemini(pAct); + //ַλ + if (((pAct->anim_chr_no > 101511) && (pAct->anim_chr_no < 101516)) || + (pAct->anim_chr_no == 101517) || (pAct->anim_chr_no == 101519)) + { + pAct->x--; + if (pAct->y == 0) + UpDownflag = 4; + if (UpDownflag == 0) + UpDownflag = RAND(1, 5); + if (UpDownflag > 3) + pAct->y++; + else + pAct->y = pAct->y; + } + else if ((pAct->anim_chr_no == 101516) || (pAct->anim_chr_no == 101518)) + { + pAct->x++; + if (pAct->y == 0) + UpDownflag = 4; + if (UpDownflag == 0) + UpDownflag = RAND(1, 5); + if (UpDownflag > 3) + pAct->y++; + else + pAct->y = pAct->y; + } + else if ((pAct->anim_chr_no == 101520) || (pAct->anim_chr_no == 101522) || + (pAct->anim_chr_no <= 101593 && pAct->anim_chr_no >= 101588)) // + { + pAct->x++; + pAct->y--; + } + else if ((pAct->anim_chr_no == 101521) || (pAct->anim_chr_no == 101523) || + (pAct->anim_chr_no <= 101587 && pAct->anim_chr_no >= 101582)) // + { + pAct->x--; + pAct->y--; + } + else + { + pAct->x++; + pAct->y++; + } + //ӫĻΧ + if ((pAct->x <= -100 || pAct->y <= -100 || pAct->x >= 740 || pAct->y >= 580) && delFlag == true && flag22 == true) + { + flag22 = false; + UpDownflag = 0; + } + pattern(pAct, pAct->dy, ANM_LOOP); + } + break; +#endif +#ifdef _THEATER + case ANIM_DISP_THEATER_NPC: // 糡NPCʾ + { + float fX, fY; + + camMapToGamen((float)pAct->gx * GRID_SIZE, (float)pAct->gy * GRID_SIZE, &fX, &fY); + ATR_H_POS(pAct) = (int)fX; + ATR_V_POS(pAct) = (int)fY; + setCharPrio(pAct->bmpNo, pAct->x, pAct->y, 0, 0, pAct->mx, pAct->my +#ifdef _SFUMATO + , pAct->sfumato +#endif + ); + switch (ATR_CHR_ACT(pAct)) + { + case 0: // + case 1: // + case 2: // ε + case 5: // + case 10: // + case 12: // Ͷ + pattern(pAct, ANM_NOMAL_SPD, ANM_NO_LOOP); // ظ + break; + default: + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + break; + } + } + break; +#endif + } + + // ?????h????? + if (ANIM_DISP_PET_MAIN <= pAct->actNo && pAct->actNo <= ANIM_DISP_PET_DEAD){ + // ???????????? + if (pAct->hitDispNo == HitDispNo && + mouse.autoState & MOUSE_LEFT_CRICK){ + // ?h??? + pAct->actNo = ANIM_DISP_PET_WALK; + // ????? + pAct->anim_ang = Rnd(0, 7); + // ???@e + pAct->crs = crs_change_tbl2[pAct->anim_ang]; + // ?????h???? + pAct->spd = 15; + + pAct->dy = 2; + play_se(217, 320, 240); // ????? + } + } +} + +// ??????????? ***********************************************/ +ACTION *MakeAnimDisp(int x, int y, int sprNo, int mode) +{ + ACTION *pAct; + + // ?????????x + pAct = GetAction(PRIO_JIKI, NULL); + if (pAct == NULL) return NULL; + + // ??? + pAct->func = AnimDisp; + // ???Re?? + pAct->atr |= ACT_ATR_HIT; + pAct->anim_chr_no = sprNo; + // h?k? + pAct->anim_no = ANIM_STAND; + // ?????????( ??? )( ??????? ) + pAct->anim_ang = 1; + /* ?IT */ + pAct->dispPrio = DISP_PRIO_BOX3; + /* ???t */ + pAct->x = x; + pAct->y = y; + // ???@e + pAct->actNo = mode; + // ?????????? + if (pAct->actNo == ANIM_DISP_PET){ + // ??????????? + pAct->dy = 12; + } + else + if (pAct->actNo == ANIM_DISP_PET_RECIEVE){ + pAct->dy = 1; + pAct->spd = 30; + } + // ??????? + pattern(pAct, ANM_NOMAL_SPD, ANM_LOOP); + + return pAct; +} + +// ???????V ****************************************************************/ +BOOL SaveMailHistory(int no) +{ + FILE *fp; + + // ???????????? + if ((fp = fopen(MAIL_HISTORY_FILE_NAME, "r+b")) == NULL){ + return FALSE; + } +#ifdef _MORECHARACTERS_ + // ????????????????????????? + extern int ﵱǰҳ; + fseek(fp, sizeof(MAIL_HISTORY)* MAX_ADR_BOOK * (selectPcNo + ﵱǰҳ * 2), SEEK_SET); +#else + fseek(fp, sizeof(MAIL_HISTORY)* MAX_ADR_BOOK * (selectPcNo), SEEK_SET); +#endif + // ??????k????????????????? + fseek(fp, sizeof(MAIL_HISTORY)* no, SEEK_CUR); + + // ??????? + if (fwrite(&MailHistory[no], sizeof(MAIL_HISTORY), 1, fp) < 1){ + + fclose(fp);// ???????? + return FALSE; + } + + fclose(fp); + + return TRUE; +} + +// ?????????? ****************************************************************/ +BOOL LoadMailHistory(void) +{ + FILE *fp; + MAIL_HISTORY work[MAX_ADR_BOOK * 2]; // ?????????Bl + + // ??????????? + if ((fp = fopen(MAIL_HISTORY_FILE_NAME, "rb")) == NULL){ + // ?????ɤ?? + if ((fp = fopen(MAIL_HISTORY_FILE_NAME, "wb")) != NULL){ + // ??????? + fwrite(MailHistory, sizeof(MAIL_HISTORY), MAX_ADR_BOOK, fp); + fwrite(MailHistory, sizeof(MAIL_HISTORY), MAX_ADR_BOOK, fp); + fclose(fp); // ???????? + } + + return FALSE; + } + + // ???????????? + if (fread(work, sizeof(MAIL_HISTORY), MAX_ADR_BOOK * 2, fp) < MAX_ADR_BOOK * 2){ + // ??????? + // ?????ɤ?? + if ((fp = fopen(MAIL_HISTORY_FILE_NAME, "wb")) != NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "ɾǰmailϡ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + // ??????? + fwrite(MailHistory, sizeof(MAIL_HISTORY), MAX_ADR_BOOK, fp); + fwrite(MailHistory, sizeof(MAIL_HISTORY), MAX_ADR_BOOK, fp); + fclose(fp); // ???????? + } + + return FALSE; + } + +#ifdef _MORECHARACTERS_ + // ?????????????????? + extern int ﵱǰҳ; + fseek(fp, sizeof(MAIL_HISTORY)* MAX_ADR_BOOK * (selectPcNo + ﵱǰҳ * 2), SEEK_SET); +#else + fseek(fp, sizeof(MAIL_HISTORY)* MAX_ADR_BOOK * (selectPcNo), SEEK_SET); +#endif + // ?????? + if (fread(MailHistory, sizeof(MAIL_HISTORY), MAX_ADR_BOOK, fp) < MAX_ADR_BOOK){ + + fclose(fp); // ???????? + return FALSE; + } + // ???????? + fclose(fp); + + return TRUE; +} + +// ?????K???V ****************************************************************/ +BOOL SaveChatRegistyStr(void) +{ + FILE *fp; + + // ???????????? + if ((fp = fopen(CAHT_REGISTY_STR_FILE_NAME, "r+b")) == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "¼ĵ¼ʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + return FALSE; + } + + // ??????? + if (fwrite(chatRegistryStr, sizeof(STR_BUFFER), MAX_CHAT_REGISTY_STR, fp) < MAX_CHAT_REGISTY_STR){ + +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "¼ĵ¼ʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + fclose(fp);// ???????? + return FALSE; + } +#ifdef _TALK_WINDOW + fwrite(&g_bTalkWindow,sizeof(BOOL),1,fp); +#endif + // ???????? + fclose(fp); + + return TRUE; +} + +// ?????K?????? ****************************************************************/ +BOOL LoadChatRegistyStr(void) +{ + FILE *fp; + int i; + + // ??????????? + if ((fp = fopen(CAHT_REGISTY_STR_FILE_NAME, "rb")) == NULL){ + // ?????ɤ?? + if ((fp = fopen(CAHT_REGISTY_STR_FILE_NAME, "wb")) != NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "ĵ¼ֵ", "ȷ", MB_OK ); +#endif + // ??????K??V?????????? + for (i = 0; i < 8; i++){ + // ??? ??@e + chatRegistryStr[i].buffer[0] = NULL; + chatRegistryStr[i].cnt = 0; + chatRegistryStr[i].cursor = 0; + // ???? + chatRegistryStr[i].len = MAX_CHAT_REGISTY_STR_LEN; + // ???? + chatRegistryStr[i].lineLen = 0; + // ????? + chatRegistryStr[i].lineDist = 20; + // ??? + chatRegistryStr[i].color = 0; + // ???? + // ????I?? + chatRegistryStr[i].fontPrio = FONT_PRIO_FRONT; + } + // ??????? + fwrite(chatRegistryStr, sizeof(STR_BUFFER), MAX_CHAT_REGISTY_STR, fp); +#ifdef _TALK_WINDOW + fwrite(&g_bTalkWindow,sizeof(BOOL),1,fp); +#endif + fclose(fp); // ???????? + } + return FALSE; + } + + // ?????? + if (fread(chatRegistryStr, sizeof(STR_BUFFER), MAX_CHAT_REGISTY_STR, fp) < MAX_CHAT_REGISTY_STR){ + +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "ĵ¼ʧܣ", "ȷ", MB_OK | MB_ICONSTOP ); +#endif + fclose(fp); // ???????? + return FALSE; + } +#ifdef _TALK_WINDOW + fread(&g_bTalkWindow,sizeof(BOOL),1,fp); + if(g_bTalkWindow) TalkWindow.Create(); +#endif + // ???????? + fclose(fp); + + return TRUE; +} +#ifdef __ALBUM_47 +int MAX_PET_TBL; +#endif +// ?????V ****************************************************************/ +BOOL SaveAlbum(int no) +{ + FILE *fp; + +#if defined(__ALBUM_47) + BOOL ret = FALSE; + if (0 <= no && no < MAX_PET_TBL){ + if (fp = fopen(ALBUM_FILE_NAME_48, "r+b")){ + if (0 != fseek(fp, (16 + sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew(hWnd, "ಾʧܣ", "ȷ", MB_OK); + if (0 != fseek(fp, 16 + sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew(hWnd, "ಾʧܣ", "ȷ", MB_OK); + if (fwrite(&PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose(fp); + } + else + MessageBoxNew(hWnd, "ಾʧܣ", "ȷ", MB_OK); + } + return ret; +#elif defined(__ALBUM_46) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_47, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_45) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_46, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_44) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if( !fopen_s( &fp,ALBUM_FILE_NAME_45, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_43) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_44, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_42) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s( &fp,ALBUM_FILE_NAME_43, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_41) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s( &fp,ALBUM_FILE_NAME_42, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_40) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_41, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_39) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if( !fopen_s( &fp,ALBUM_FILE_NAME_40, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_38) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s( &fp,ALBUM_FILE_NAME_39, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_37) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s( &fp,ALBUM_FILE_NAME_38, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_36) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s( &fp,ALBUM_FILE_NAME_37, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; + +#elif defined(__ALBUM_35) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if( !fopen_s( &fp,ALBUM_FILE_NAME_36, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; +#elif defined(__ALBUM_34) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_35, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; +#elif defined(__ALBUM_33) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if( !fopen_s(&fp, ALBUM_FILE_NAME_34, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; +#elif defined(__ALBUM_32) + BOOL ret = FALSE; + if( 0 <= no && no < MAX_PET_TBL ){ + if(!fopen_s(&fp, ALBUM_FILE_NAME_33, "r+b")){ + if( 0 != fseek( fp, (16+sizeof(PET_ALBUM)*MAX_PET_KIND)*AlbumIdCnt, SEEK_SET)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( 0 != fseek( fp, 16+sizeof(PET_ALBUM)*no, SEEK_CUR)) + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + if( fwrite( &PetAlbum[no], sizeof(PET_ALBUM), 1, fp) >= 1) + ret = TRUE; + fclose( fp ); + }else + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); + } + return ret; +#else + // ???????????? + if ((fopen_s(&fp, ALBUM_FILE_NAME, "r+b")) != NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); +#endif + return FALSE; + } + // \??????? + for (int i = 0; i < AlbumIdCnt; i++){ + // ???????????? + fseek(fp, 16, SEEK_CUR); + fseek(fp, sizeof(PET_ALBUM)* MAX_PET_KIND, SEEK_CUR); + } + // ??????? + fseek(fp, 16, SEEK_CUR); + // ??????????k????? + fseek(fp, sizeof(PET_ALBUM)* no, SEEK_CUR); + + // ??????? + if (fwrite(&PetAlbum[no], sizeof(PET_ALBUM), 1, fp) < 1){ + +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd, "ಾʧܣ", "ȷ", MB_OK ); +#endif + fclose(fp);// ???????? + return FALSE; + } + // ???????? + fclose(fp); + + return TRUE; +#endif +} + +#if defined(__ALBUM_4) + +BOOL LoadAlbum_4( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_4, "r+b")) != NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_4, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + // ?????????? + // ???????????? + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + // + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbum1_4( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} + +#elif defined(__ALBUM_47) +BOOL LoadAlbum_47(char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[16]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy(id, user, 16); + DeleteFile("data\\album_2.dat"); + DeleteFile("data\\album_3.dat"); + DeleteFile("data\\album_10.dat"); + for (i = 0; i < MAX_PET_KIND; i++){ + for (int j = 0; j < PET_NAME_LEN + 1; j++){ + PetAlbum[i].name[j] = Rnd(1, 255); + PetAlbum[i].freeName[j] = Rnd(1, 255); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd(1, 60000); + PetAlbum[i].level = Rnd(1, 30000); + PetAlbum[i].faceGraNo = Rnd(1, 30000); + PetAlbum[i].maxHp = Rnd(1, 30000); + PetAlbum[i].str = Rnd(1, 30000); + PetAlbum[i].quick = Rnd(1, 30000); + PetAlbum[i].def = Rnd(1, 30000); + PetAlbum[i].earth = Rnd(1, 30000); + PetAlbum[i].water = Rnd(1, 30000); + PetAlbum[i].fire = Rnd(1, 30000); + PetAlbum[i].wind = Rnd(1, 30000); + } + if ((fp = fopen(ALBUM_FILE_NAME_48, "r+b")) == NULL){ + if ((fp = fopen(ALBUM_FILE_NAME_48, "wb")) != NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd(1, 100); + for (i = 0; i < 16; i++) + id[i] ^= IdEncryptionTbl[i]; + if (fwrite(id, sizeof(id), 1, fp) >= 1){ + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose(fp); + } + return ret; + } + while (1){ + if (fread(id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd(1, 100); + for (i = 0; i < 16; i++) + id[i] ^= IdEncryptionTbl[i]; + if (fwrite(id, sizeof(id), 1, fp) >= 1){ + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose(fp); + return FALSE; + } + for (i = 0; i < 16; i++) + id2[i] ^= IdEncryptionTbl[i]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if (strcmp(id, id2) != 0){ + //Ǵʺŵļ¼ + if (fseek(fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek(fp, (sizeof(PET_ALBUM)*MAX_PET_KIND + 16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd(1, 100); + for (i = 0; i < 16; i++) + id[i] ^= IdEncryptionTbl[i]; + if (fwrite(id, sizeof(id), 1, fp) >= 1){ + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose(fp); + return FALSE; + } + } + else{ + //ҵʺŵļ¼ + if (fread(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose(fp); + return FALSE; + } + fclose(fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose(fp); + return ret; +} + +BOOL ConvertAlbumTo47(char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[MAX_PET_KIND]; + char id2[32]; + int i; + FILE *fp; + if ((fp = fopen(oldfile, "r+b")) == NULL) + return FALSE; + while (1){ + //ID + if (fread(id2, 16, 1, fp) < 1){ + fclose(fp); + return FALSE; + } + //ID + for (i = 0; i < 16; i++){ + id2[i] ^= IdEncryptionTbl[i]; + } + id2[id2[15]] = NULL; + if (strcmp(user, id2) != 0){ + //ID + if (fseek(fp, sizeof(PET_ALBUM)* num, SEEK_CUR) != 0){//һ + fclose(fp); + return FALSE; + } + } + else{ + //ҵID¼ + if (fread(OldAlbum, sizeof(PET_ALBUM), num, fp) < num){ + fclose(fp); + return FALSE; + } + for (DWORD i = 0; i < num; i++){ + if (440 <= i && i <= 461) continue; //Q + CopyMemory(&PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum(i); + } + break; + } + } + fclose(fp); + return TRUE; +} + +BOOL ConvertAlbum1_47(char *user) +{ + PET_ALBUM OldAlbum[MAX_PET_KIND_1]; + char id2[16]; + int i; + FILE *fp; + if ((fp = fopen(ALBUM_FILE_NAME, "r+b")) == NULL) + return FALSE; + while (1){ + //ID + if (fread(id2, sizeof(id2), 1, fp) < 1){ + fclose(fp); + return FALSE; + } + //ID + for (i = 0; i < 16; i++){ + id2[i] ^= IdEncryptionTbl[i]; + } + id2[id2[15]] = NULL; + if (strcmp(user, id2) != 0){ + //ID + if (fseek(fp, sizeof(PET_ALBUM)* MAX_PET_KIND_1, SEEK_CUR) != 0){//һ + fclose(fp); + return FALSE; + } + } + else{ + // + if (fread(OldAlbum, sizeof(PET_ALBUM), MAX_PET_KIND_1, fp) < MAX_PET_KIND_1){ + fclose(fp); + return FALSE; + } + for (int i = 0; i < MAX_PET_KIND_1; i++){ + for (int j = 0; j < MAX_PET_TBL; j++){ + if (!OldAlbum[i].flag) + break; + if (OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory(&PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum(PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose(fp); + return TRUE; +} +#elif defined(__ALBUM_46) +BOOL LoadAlbum_46( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_47, "r+b")) != NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_47, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo46( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_46( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_45) +BOOL LoadAlbum_45( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s(&fp, ALBUM_FILE_NAME_46, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_46, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo45( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_45( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_44) +BOOL LoadAlbum_44( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s(&fp, ALBUM_FILE_NAME_45, "r+b"))!= NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_45, "wb"))== NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo44( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_44( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_43) +BOOL LoadAlbum_43( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_44, "r+b"))!= NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_44, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo43( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_43( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_42) +BOOL LoadAlbum_42( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_43, "r+b"))!= NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_43, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo42( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_42( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_41) +BOOL LoadAlbum_41( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_42, "r+b")) != NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_42, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo41( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_41( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_40) +BOOL LoadAlbum_40( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_41, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_41, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo40( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_40( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_39) +BOOL LoadAlbum_39( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s(&fp, ALBUM_FILE_NAME_40, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_40, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo39( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( (fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_39( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_38) +BOOL LoadAlbum_38( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s(&fp, ALBUM_FILE_NAME_39, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_39, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo38( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_38( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_37) +BOOL LoadAlbum_37( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_38, "r+b")) != NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_38, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo37( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_37( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_36) +BOOL LoadAlbum_36( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_37, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_37, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo36( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + if( 440 <= i && i <= 461 ) continue; //Q + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_36( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_35) +BOOL LoadAlbum_35( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_36, "r+b")) != NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_36, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo35( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_35( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_34) +BOOL LoadAlbum_34( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s(&fp, ALBUM_FILE_NAME_35, "r+b"))!= NULL){ + if( (fopen_s(&fp, ALBUM_FILE_NAME_35, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo34( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_34( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s(&fp, ALBUM_FILE_NAME, "r+b" ) ) != NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_33) +BOOL LoadAlbum_33( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fopen_s( &fp,ALBUM_FILE_NAME_34, "r+b")) != NULL){ + if( (fopen_s( &fp,ALBUM_FILE_NAME_34, "wb")) == NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo33( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fopen_s( &fp,oldfile, "r+b" ) ) != NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_33( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fp = fopen( ALBUM_FILE_NAME, "r+b" ) ) == NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#elif defined(__ALBUM_32) +BOOL LoadAlbum_32( char *user) +{ + FILE *fp; + BOOL ret = FALSE; + char id[16]; + char id2[ 16 ]; + int i; + MAX_PET_TBL = sizeof(PetAlbumTbl) / sizeof(PetAlbumTbl[0]); + AlbumIdCnt = 0; + memcpy( id, user, 16); + DeleteFile( "data\\album_2.dat"); + DeleteFile( "data\\album_3.dat"); + DeleteFile( "data\\album_10.dat"); + for( i = 0; i < MAX_PET_KIND; i++){ + for( int j = 0 ; j < PET_NAME_LEN+1 ; j++){ + PetAlbum[i].name[j] = Rnd( 1, 255 ); + PetAlbum[i].freeName[j] = Rnd( 1, 255 ); + } + PetAlbum[i].flag = 0; + PetAlbum[i].faceGraNo = Rnd( 1, 60000 ); + PetAlbum[i].level = Rnd( 1, 30000 ); + PetAlbum[i].faceGraNo = Rnd( 1, 30000 ); + PetAlbum[i].maxHp = Rnd( 1, 30000 ); + PetAlbum[i].str = Rnd( 1, 30000 ); + PetAlbum[i].quick = Rnd( 1, 30000 ); + PetAlbum[i].def = Rnd( 1, 30000 ); + PetAlbum[i].earth = Rnd( 1, 30000 ); + PetAlbum[i].water = Rnd( 1, 30000 ); + PetAlbum[i].fire = Rnd( 1, 30000 ); + PetAlbum[i].wind = Rnd( 1, 30000 ); + } + if( (fp=fopen( ALBUM_FILE_NAME_4, "r+b")) == NULL){ + if( (fp=fopen( ALBUM_FILE_NAME_4, "wb")) != NULL){ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + } + return ret; + } + while( 1 ){ + if( fread( id2, sizeof(id2), 1, fp) < 1){ + //Ҳʺŵļ¼ + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0 ; i < 16 ; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + for( i = 0 ; i < 16 ; i++) + id2[ i ] ^= IdEncryptionTbl[ i ]; + id2[15] &= 0xf; + id2[id2[15]] = NULL; + if( strcmp( id, id2) != 0){ + //Ǵʺŵļ¼ + if( fseek( fp, sizeof(PET_ALBUM)*MAX_PET_KIND, SEEK_CUR) != 0){ + fseek( fp, (sizeof(PET_ALBUM)*MAX_PET_KIND+16)*AlbumIdCnt, SEEK_SET); + id[15] &= 0xf; + id[id[15]] = Rnd( 1, 100); + for( i = 0; i < 16; i++) + id[ i ] ^= IdEncryptionTbl[ i ]; + if( fwrite( id, sizeof( id ), 1, fp ) >= 1){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + } + fclose( fp); + return FALSE; + } + }else{ + //ҵʺŵļ¼ + if( fread( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fwrite( PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose( fp); + return FALSE; + } + fclose( fp); + return TRUE; + } + AlbumIdCnt++; + } + fclose( fp ); + return ret; +} + +BOOL ConvertAlbumTo32( char *user, char *oldfile, DWORD num) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fp = fopen( oldfile, "r+b" ) ) == NULL ) + return FALSE; + while( 1){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * num, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + //ҵID¼ + if( fread( OldAlbum, sizeof( PET_ALBUM ), num, fp ) < num ){ + fclose( fp ); + return FALSE; + } + for( DWORD i = 0; i < num; i++){ + CopyMemory( &PetAlbum[i], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( i); + } + break; + } + } + fclose( fp ); + return TRUE; +} + +BOOL ConvertAlbum1_32( char *user) +{ + PET_ALBUM OldAlbum[ MAX_PET_KIND_1 ]; + char id2[ 16 ]; + int i; + FILE *fp; + if( ( fp = fopen( ALBUM_FILE_NAME, "r+b" ) ) == NULL ) + return FALSE; + while( 1 ){ + //ID + if( fread( id2, sizeof( id2 ), 1, fp ) < 1 ){ + fclose( fp ); + return FALSE; + } + //ID + for( i = 0 ; i < 16 ; i++ ){ + id2[ i ] ^= IdEncryptionTbl[ i ]; + } + id2[ id2[ 15 ] ] = NULL; + if( strcmp( user, id2 ) != 0 ){ + //ID + if( fseek( fp, sizeof( PET_ALBUM ) * MAX_PET_KIND_1, SEEK_CUR ) != 0 ){//һ + fclose( fp ); + return FALSE; + } + }else{ + // + if( fread( OldAlbum, sizeof( PET_ALBUM ), MAX_PET_KIND_1, fp ) < MAX_PET_KIND_1 ){ + fclose( fp ); + return FALSE; + } + for( int i = 0; i < MAX_PET_KIND_1; i++){ + for( int j = 0; j < MAX_PET_TBL; j++){ + if( !OldAlbum[i].flag) + break; + if( OldAlbum[i].faceGraNo == PetAlbumTbl[j].faceGraNo){ + CopyMemory( &PetAlbum[PetAlbumTbl[j].albumNo], &OldAlbum[i], sizeof(PET_ALBUM)); + SaveAlbum( PetAlbumTbl[j].albumNo); + break; + } + } + } + break; + } + } + fclose( fp ); + return TRUE; +} +#endif + + +// ???????? ****************************************************************/ +BOOL LoadAlbum(void) +{ + char id[32]; + + // ?????x + extern char szUser[]; + CopyMemory(id, szUser, 32); + ecb_crypt("f;encor1c", id, 32, DES_DECRYPT); + // ????x + id[15] = strlen(id); + +#if defined(__ALBUM_47) + if (LoadAlbum_47(id)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_47, MAX_PET_KIND_46)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_46, MAX_PET_KIND_45)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_45, MAX_PET_KIND_44)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_44, MAX_PET_KIND_43)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_43, MAX_PET_KIND_42)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5)) + return TRUE; + if (ConvertAlbumTo47(id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4)) + return TRUE; + if (ConvertAlbum1_47(id)) + return TRUE; + return FALSE; +#elif defined(__ALBUM_46) + if( LoadAlbum_46( id) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_46, MAX_PET_KIND_45) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_45, MAX_PET_KIND_44) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_44, MAX_PET_KIND_43) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_43, MAX_PET_KIND_42) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo46( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_46( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_45) + if( LoadAlbum_45( id) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_45, MAX_PET_KIND_44) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_44, MAX_PET_KIND_43) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_43, MAX_PET_KIND_42) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo45( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_45( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_44) + if( LoadAlbum_44( id) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_44, MAX_PET_KIND_43) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_43, MAX_PET_KIND_42) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo44( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_44( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_43) + if( LoadAlbum_43( id) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_43, MAX_PET_KIND_42) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo43( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_43( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_42) + if( LoadAlbum_42( id) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_42, MAX_PET_KIND_41) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo42( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_42( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_41) + if( LoadAlbum_41( id) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_41, MAX_PET_KIND_40) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo41( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_41( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_40) + if( LoadAlbum_40( id) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_40, MAX_PET_KIND_39) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo40( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_40( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_39) + if( LoadAlbum_39( id) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_39, MAX_PET_KIND_38) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo39( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_39( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_38) + if( LoadAlbum_38( id) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_38, MAX_PET_KIND_37) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo38( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_38( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_37) + if( LoadAlbum_37( id) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_37, MAX_PET_KIND_36) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo37( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_37( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_36) + if( LoadAlbum_36( id) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_36, MAX_PET_KIND_35) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo36( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_36( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_35) + if( LoadAlbum_35( id) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_35, MAX_PET_KIND_34) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo35( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_35( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_34) + if( LoadAlbum_34( id) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_34, MAX_PET_KIND_33) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo34( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_34( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_33) + if( LoadAlbum_33( id) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_33, MAX_PET_KIND_32) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo33( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_33( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_32) + if( LoadAlbum_32( id) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_32, MAX_PET_KIND_31) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_31, MAX_PET_KIND_30) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_30, MAX_PET_KIND_29) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_29, MAX_PET_KIND_28) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_28, MAX_PET_KIND_27) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_27, MAX_PET_KIND_26) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_26, MAX_PET_KIND_25) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_25, MAX_PET_KIND_24) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_24, MAX_PET_KIND_23) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_23, MAX_PET_KIND_22) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_22, MAX_PET_KIND_21) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_21, MAX_PET_KIND_20) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_20, MAX_PET_KIND_19) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_19, MAX_PET_KIND_18) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_18, MAX_PET_KIND_17) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_17, MAX_PET_KIND_16) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_16, MAX_PET_KIND_15) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo32( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_32( id) ) + return TRUE; + return FALSE; +#elif defined(__ALBUM_15) + if( LoadAlbum_15( id) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_15, MAX_PET_KIND_14) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_14, MAX_PET_KIND_13) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_13, MAX_PET_KIND_12) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_12, MAX_PET_KIND_11) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_10, MAX_PET_KIND_10) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_9, MAX_PET_KIND_9) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_8, MAX_PET_KIND_8) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_7, MAX_PET_KIND_7) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_6, MAX_PET_KIND_6) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_5, MAX_PET_KIND_5) ) + return TRUE; + if( ConvertAlbumTo15( id, ALBUM_FILE_NAME_4, MAX_PET_KIND_4) ) + return TRUE; + if( ConvertAlbum1_15( id) ) + return TRUE; + return FALSE; +#else + char id2[16]; + int i; + FILE *fp; + // ????????? + AlbumIdCnt = 0; + // ??????????? + if ((fp = fopen(ALBUM_FILE_NAME, "r+b")) == NULL){ + + // ?????ɤ?? + if ((fp = fopen(ALBUM_FILE_NAME, "wb")) != NULL){ + // ???????????? + id[id[15]] = Rnd(1, 100); + // ?????? + for (i = 0; i < 16; i++){ + id[i] ^= IdEncryptionTbl[i]; + + } + // ????????? + fwrite(id, sizeof(id), 1, fp); + + // ?????Bl?????? + for (i = 0; i < MAX_PET_KIND; i++){ + int j; + // q??? + for (j = 0; j < PET_NAME_LEN + 1; j++){ + PetAlbum[i].name[j] = Rnd(1, 255); + PetAlbum[i].freeName[j] = Rnd(1, 255); + } + + PetAlbum[i].faceGraNo = Rnd(1, 60000); + PetAlbum[i].level = Rnd(1, 30000); + PetAlbum[i].faceGraNo = Rnd(1, 30000); + PetAlbum[i].maxHp = Rnd(1, 30000); + PetAlbum[i].str = Rnd(1, 30000); + PetAlbum[i].quick = Rnd(1, 30000); + PetAlbum[i].def = Rnd(1, 30000); + + PetAlbum[i].earth = Rnd(1, 30000); + PetAlbum[i].water = Rnd(1, 30000); + PetAlbum[i].fire = Rnd(1, 30000); + PetAlbum[i].wind = Rnd(1, 30000); + } + + // ??????? + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose(fp); // ???????? + } + + return FALSE; + } + // ??S??????? ????? ? + while (1){ + // ?????? + if (fread(id2, sizeof(id2), 1, fp) < 1){ + // ?????????? + // ???????????? + id[id[15]] = Rnd(1, 100); + // ?????? + for (i = 0; i < 16; i++){ + id[i] ^= IdEncryptionTbl[i]; + } + // ????????? + fwrite(id, sizeof(id), 1, fp); + // ??????? + fwrite(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp); + fclose(fp); // ???????? + return FALSE; + } + // ????????? + for (i = 0; i < 16; i++){ + id2[i] ^= IdEncryptionTbl[i]; + } + // ????????? + id2[id2[15]] = NULL; + // ?????? + if (strcmp(id, id2) != 0){ + // ???????????????????? + if (fseek(fp, sizeof(PET_ALBUM)* MAX_PET_KIND, SEEK_CUR) != 0){ + fclose(fp); // ???????? + return FALSE; + } + } + else{// ???? + // ?????????? + if (fread(PetAlbum, sizeof(PET_ALBUM), MAX_PET_KIND, fp) < MAX_PET_KIND){ + fclose(fp); // ???????? + return FALSE; + } + break; + } + // ?????? + AlbumIdCnt++; + } + // ???????? + fclose(fp); + + return TRUE; +#endif +} + +// ??????????^M?? **************************************************/ +void InitOhtaParam(void) +{ + LoadMailHistory(); // ?????????? + LoadChatHistoryStr(); // ???????????? + //LoadReadNameShield(); + //LoadReadSayShield(); + mailLamp = CheckMailNoReadFlag(); // t???? + StatusUpPoint = 0; // ??????????????? + battleResultMsg.useFlag = 0; // Pf???????? + MapWmdFlagBak = 0; +} + +// ???t???? ****************************************************************/ +BOOL CheckMailNoReadFlag(void) +{ + int i, j; + + // ??? + for (i = 0; i < MAX_ADR_BOOK; i++){ + // ????? + for (j = 0; j < MAIL_MAX_HISTORY; j++){ + // t??????? + if (MailHistory[i].noReadFlag[j] >= TRUE) return TRUE; + } + } + return FALSE; +} + +// ???????? ****************************************************************/ +void CheckNewPet(int sprNo) +{ + int tblNo = sprNo - 100250; // ?????k? + int albumNo; + // ????k? +#if defined(__ALBUM_47) + if (tblNo > 1800){ //Сħ + tblNo -= 1208; + } + else if (tblNo > 1755){ //Ϲħ + tblNo -= 1201; + } + else if (tblNo > 1739){ //1710 ){ // + tblNo -= 1200; + } + else if (tblNo > 1686){ //ںϳ + tblNo -= 1175; + } + else if (tblNo > 1641){ //4 ׳2 8.0һϲ + tblNo -= 1167; + } + else if (tblNo > 1635){ // + tblNo -= 1148; + } + else if (tblNo > 1634){ //èŮ1 èŮ2 + tblNo -= 1149; + } + else if (tblNo > 1616){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + } + else if (tblNo > 1568){// + tblNo -= 1103; + } + else if (tblNo > 1564){//ɫ + tblNo -= 1101; + } + else if (tblNo > 1516){ + tblNo -= 1055; + } + else if (tblNo == 1516){// + tblNo = 455; + } + else if (tblNo > 1509){ + tblNo -= 1054; + } + else if (tblNo == 1497){ + tblNo = 395; + } + else if (tblNo > 1495){ + tblNo -= 1044; + } + else if (tblNo > 1490){ + tblNo -= 1043; + } + else if (tblNo > 1485){ + tblNo -= 1040; + } + else if (tblNo > 1454) { + tblNo -= 1034; + } + else if (tblNo == 1214) { + tblNo = 331; + } + else if (tblNo == 1217) { + tblNo = 328; + } + else if (tblNo > 1361){ + tblNo -= 952; + } + else if (tblNo > 1356){ + tblNo -= 999; + } + else if (tblNo > 1281){ + tblNo -= 919; + } + else if (tblNo > 1239){ + tblNo -= 889; + } + else if (tblNo > 1186){ + tblNo -= 886; + } + else if (tblNo > 1173){ + tblNo -= 877; + } + else if (tblNo > 1172){ + tblNo -= 877; + } + else if (tblNo > 1161){ + tblNo -= 868; + } + else if (tblNo > 930){ + tblNo -= 745; + } + else if (tblNo == 927){ + tblNo -= 634; + } + else if (tblNo > 929){ + tblNo -= 644; + } + else if (tblNo > 927){ + tblNo -= 643; + } + else if (tblNo > 900){ + tblNo -= 621; + } + else if (tblNo > 180){ + tblNo -= (333 + 56); + } +#elif defined(__ALBUM_46) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_45) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_44) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_43) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_42) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_41) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_40) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_39) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_38) + + if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201; + }else if (tblNo > 1739 ){ //1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_37) + + if (tblNo > 1710 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //ںϳ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_36) + + if (tblNo > 1686 ){ //4 ׳2 8.0һϲ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_35) + + if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_34) + + if (tblNo > 1639 ){ //4 + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_33) + + if (tblNo > 1635 ){ + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_32) + + if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_31) + + if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_30) + + if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_29) + + if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_28) + + if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_27) + + if ( tblNo > 1616 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_26) + + if ( tblNo > 1616 ){// ۷1 ۷2 1 2 + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_25) + if( tblNo > 1616 ){// + tblNo -= 1146; + }else if ( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_24) + if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_23) + if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_22) + if ( tblNo == 1516 ){// + tblNo = 455; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_21) + if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_20) + if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_19) + if ( tblNo > 1490 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_18) + if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_17) + if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_16) + if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_15) + if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#endif + // ???????k????? + if (0 <= tblNo && tblNo < MAX_PET_TBL){ + // ??K????????k? + albumNo = PetAlbumTbl[tblNo].albumNo; + // ???????? + if (albumNo != -1 ){ + // ??????????? + if (PetAlbum[albumNo].flag == 0){ + // ??????? + PetAlbum[albumNo].flag = 1; + // q??? + strcpy(PetAlbum[albumNo].name, PetAlbumTbl[tblNo].name); + // ?????V + SaveAlbum(albumNo); + } + } + } +} + +// Pf?????????? **********************************************************/ +void CheckBattleNewPet(void) +{ + int i; + + // ??l??? + for (i = 0; i < BATTLKPKPLYAERNUM; i++){ + // ?????????? + if (p_party[i] == NULL) continue; + // ?????????? + if (p_party[i]->func == NULL) continue; + // ????????? + CheckNewPet(p_party[i]->anim_chr_no); + } +} + +// ?????????? *****************************************************/ +void CenteringStr(char *inStr, char *outStr, int max) +{ + int len, space, amari; + + // ????? + len = strlen(inStr); + + // ???????? + if (len >= max){ + // ??????? + strncpy_s(outStr, max + 1, inStr, max); + outStr[max] = NULL; // Z?????? + return; + } + + // ??????? + amari = (max - len) % 2; + // ????? + space = (max - len) / 2; + + // ????????? + if (space != 0){ + // ??? + sprintf(outStr, "%*c%s%*c", space, ' ', inStr, space + amari, ' '); + } + else{ + // ??? + sprintf(outStr, "%s ", inStr); + } +} + +// e????????????????? *************************************/ +int CheckPetSkill(int skillId) +{ + int i, j; + + // ???????? + for (j = 0; j < MAX_PET; j++){ + // ??????????? + if (pet[j].useFlag == TRUE){ + // ????? + for (i = 0; i < pet[j].maxSkill; i++){ + // ???????? + if (petSkill[j][i].useFlag == TRUE){ + // ?????? + if (petSkill[j][i].skillId == skillId){ + return TRUE; + } + } + } + } + } + return FALSE; +} + +// ?????????? *******************************************************/ +void InitItem(int x, int y, BOOL bPetItemFlag) +{ + int i, j = 0, k = 0; + +#ifdef _ITEM_EQUITSPACE + +#ifdef _SA_VERSION_25 + struct _tagInitXY{ + int x; + int y; + }InitXY[CHAR_EQUIPPLACENUM] = { + { x + 84, y + 51 }, { x + 85, y + 119 }, { x + 33, y + 122 }, + { x + 137, y + 63 }, { x + 33, y + 63 }, { x + 137, y + 122 }, + { x + 137, y + 122 }, { x + 136, y + 130 } +#ifdef _EQUIT_NEWGLOVE + , { x + 137, y + 122 } +#endif + }; +#endif +#ifdef _PET_ITEM + if (bPetItemFlag) // Ŀǰʾdz + { + // seting x + InitXY[0].x = InitXY[5].x = x + 63; + InitXY[1].x = InitXY[6].x = x + 113; + InitXY[2].x = x + 36; + InitXY[3].x = x + 87; + InitXY[4].x = x + 138; + // seting y + InitXY[0].y = InitXY[1].y = y + 34; + InitXY[2].y = InitXY[3].y = InitXY[4].y = y + 83; + InitXY[5].y = InitXY[6].y = y + 132; + } +#endif + for (i = 0; i < MAX_ITEMSTART; i++) + { + ItemBuffer[i].defX = InitXY[i].x; + ItemBuffer[i].defY = InitXY[i].y; + ItemBuffer[i].x = ItemBuffer[0].defX; + ItemBuffer[i].y = ItemBuffer[0].defY; + ItemBuffer[i].bmpNo = 20000 + 0; + ItemBuffer[i].dispPrio = DISP_PRIO_ITEM; + } +#else + ItemBuffer[ 0 ].defX = x + 136; + ItemBuffer[ 0 ].defY = y + 59; + ItemBuffer[ 0 ].x = ItemBuffer[ 0 ].defX; + ItemBuffer[ 0 ].y = ItemBuffer[ 0 ].defY; + ItemBuffer[ 0 ].bmpNo = 20000 + 0; + ItemBuffer[ 0 ].dispPrio = DISP_PRIO_ITEM; + + ItemBuffer[ 1 ].defX = x + 134; + ItemBuffer[ 1 ].defY = y + 129; + ItemBuffer[ 1 ].x = ItemBuffer[ 1 ].defX; + ItemBuffer[ 1 ].y = ItemBuffer[ 1 ].defY; + ItemBuffer[ 1 ].bmpNo = 20200 + 1; + ItemBuffer[ 1 ].dispPrio = DISP_PRIO_ITEM; + + ItemBuffer[ 2 ].defX = x + 61; + ItemBuffer[ 2 ].defY = y + 129; + ItemBuffer[ 2 ].x = ItemBuffer[ 2 ].defX; + ItemBuffer[ 2 ].y = ItemBuffer[ 2 ].defY; + ItemBuffer[ 2 ].bmpNo = 20400 + 2; + ItemBuffer[ 2 ].dispPrio = DISP_PRIO_ITEM; + + ItemBuffer[ 3 ].defX = x + 32; + ItemBuffer[ 3 ].defY = y + 68; + ItemBuffer[ 3 ].x = ItemBuffer[ 3 ].defX; + ItemBuffer[ 3 ].y = ItemBuffer[ 3 ].defY; + ItemBuffer[ 3 ].bmpNo = 20600 + 3; + ItemBuffer[ 3 ].dispPrio = DISP_PRIO_ITEM; + + ItemBuffer[ 4 ].defX = x + 83; + ItemBuffer[ 4 ].defY = y + 68; + ItemBuffer[ 4 ].x = ItemBuffer[ 4 ].defX; + ItemBuffer[ 4 ].y = ItemBuffer[ 4 ].defY; + ItemBuffer[ 4 ].bmpNo = 20800 + 4; + ItemBuffer[ 4 ].dispPrio = DISP_PRIO_ITEM; +#endif + + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + ItemBuffer[i].defX = x + 32 + j; + ItemBuffer[i].defY = y + 56 + 48 + 48 + 48 + k; + ItemBuffer[i].x = ItemBuffer[i].defX; + ItemBuffer[i].y = ItemBuffer[i].defY; + ItemBuffer[i].bmpNo = 20000 + j / 48; + ItemBuffer[i].dispPrio = DISP_PRIO_ITEM; + ItemBuffer[i].mixFlag = FALSE; + j += 51; + if (j >= 48 * 5){ + j = 0; +#ifdef _NEW_ITEM_ + if (k >= 48 * 2){ + k = 0; + } + else k += 48; +#else + k += 48; +#endif + } + } +} + +// CoolFish: Trade 04/14 +void InitItem3(int x, int y) +{ + int i, j = 0, k = 0; + // ???????? + for (i = MAX_ITEMSTART; i < MAX_ITEM; i++){ + ItemBuffer[i].defX = x + 32 + j; + ItemBuffer[i].defY = y + 56 + 48 + 48 + 48 - 160 + k; + ItemBuffer[i].x = ItemBuffer[i].defX; + ItemBuffer[i].y = ItemBuffer[i].defY; + ItemBuffer[i].bmpNo = 20000 + j / 48; + ItemBuffer[i].dispPrio = DISP_PRIO_ITEM; + j += 51; // ????? + // ???????? + if (j >= 48 * 5){ + j = 0; +#ifdef _NEW_ITEM_ + if (k >= 48 * 2){ + k = 0; + } + else k += 48; +#else + k += 48; +#endif + } + } +} +// CoolFish: End + +// ???Re????? ******************************************************/ +BOOL MakeHitBox(int x1, int y1, int x2, int y2, int dispPrio) +{ + // ?????Re + if (mouse.nowPoint.x <= x2 && x1 <= mouse.nowPoint.x && + mouse.nowPoint.y <= y2 && y1 <= mouse.nowPoint.y){ + // ??????? + if (dispPrio >= 0){ + // ???????????????? + StockBoxDispBuffer(x1, y1, x2, y2, dispPrio, BoxColor, 0); + } + return TRUE; + } + return FALSE; +} + +// ????????? **************************************************************/ +void DeathLetterAction(void) +{ + int i; + + for (i = 0; i < 4; i++){ + DeathAction(pActLetter[i]); + pActLetter[i] = NULL; + } +} + +// ???????? ***************************************************************/ +void InitMailSendFlag(void) +{ + int i; + + for (i = 0; i < MAX_ADR_BOOK; i++) mailWndSendFlag[i] = 0; +} + +#ifdef _PET_SKINS +extern int originalPetSkin; +extern void initPetSkinWin(); +extern void petSkinProc(); +extern void petChange(int graphNo); +#endif + + +// ????????????D? *****************************************************/ +void DeathMenuAction(void) +{ + +#ifdef _MAGIC_ITEM_ + if(߹⻷Act) DeathAction(߹⻷Act); + ߹⻷Act=NULL; +#endif + if(pActMenuWnd) + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + chatRoomBtn = 0; + assentFlag = FALSE; + DeathAction( pAssentWnd ); + pAssentWnd = NULL; + setRoomFlag = FALSE; + DeathAction( pSetRoomWnd ); + pSetRoomWnd = NULL; +#endif + // лͼBUG + extern ACTION * ptActMenuWin1; + if (ptActMenuWin1){ + DeathAction(ptActMenuWin1); + ptActMenuWin1 = NULL; + } + if(pActMenuWnd3) + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + if(pActPet) + DeathAction(pActPet); + pActPet = NULL; + if(pActMailItem) + DeathAction(pActMailItem); + pActMailItem = NULL; + if(pActYesNoWnd) + DeathAction(pActYesNoWnd); + pActYesNoWnd = NULL; + // ????????? + DeathLetterAction(); + + // Robin 04/14 trade + if (pActMenuWnd4){ + DeathAction(pActMenuWnd4); + pActMenuWnd4 = NULL; + } +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ʹAction + if (SecondTradeWnd){ + DeathAction(SecondTradeWnd); + SecondTradeWnd = NULL; + } + if (SecondActPet){ + DeathAction(SecondActPet); + SecondActPet = NULL; + } + if (TradeTalkWnd){ + DeathAction(TradeTalkWnd); + TradeTalkWnd = NULL; + } +#endif + if (pActPet3){ + DeathAction(pActPet3); + pActPet3 = NULL; + } + + if (pActPet4){ + DeathAction(pActPet4); + pActPet4 = NULL; + } + if (pActPet5){ + DeathAction(pActPet5); + pActPet5 = NULL; + } + if (pActMenuWnd5){ + DeathAction(pActMenuWnd5); + pActMenuWnd5 = NULL; + } +#ifdef _PET_SKINS + initPetSkinWin(); + petWndNo = 0; +#endif +} +// ????????????D? *****************************************************/ +void DeathMenuAction2(void) +{ +#ifdef _MAGIC_ITEM_ + if(߹⻷Act) DeathAction(߹⻷Act); + ߹⻷Act=NULL; + extern void ClearMagicItemWin(); + ClearMagicItemWin(); +#endif + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + // ????? + DeathAction(pActPet2); + pActPet2 = NULL; + // ????????k???? + ItemMixPetNo = -1; + + // Robin 04/14 trade + DeathAction(pActMenuWnd4); +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + chatRoomBtn = 0; + assentFlag = FALSE; + DeathAction( pAssentWnd ); + pAssentWnd = NULL; + setRoomFlag = FALSE; + DeathAction( pSetRoomWnd ); + pSetRoomWnd = NULL; +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ʹAction + DeathAction(SecondTradeWnd); + SecondTradeWnd = NULL; + DeathAction(SecondActPet); + SecondActPet = NULL; + DeathAction(TradeTalkWnd); + TradeTalkWnd = NULL; +#endif + //Ӵʱԭ趨 + Tradeflag = false; + pActMenuWnd4 = NULL; + DeathAction(pActPet3); + pActPet3 = NULL; + DeathAction(pActPet4); + pActPet4 = NULL; + DeathAction(pActPet5); + pActPet5 = NULL; + DeathAction(pActMenuWnd5); + pActMenuWnd5 = NULL; + +} + +// ?????????? *******************************************************/ +void InitMenu(void) +{ + + int i; + + // ???? + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + // ??? + for (i = 0; i < MENU_MAP_0; i++) mapWndFontNo[i] = -2; + mapWndNo = 0; + // ????? + for (i = 0; i < MENU_STATUS_0; i++) statusWndFontNo[i] = -2; + for (i = 0; i < MENU_STATUS_0; i++) statusWndBtnFlag[i] = 0; + + // Robin 04/14 trade + for (i = 0; i < MENU_TRADE_0; i++) tradeWndFontNo[i] = -2; + for (i = 0; i < MENU_TRADE_0; i++) tradeWndBtnFlag[i] = 0; + + // ??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + petWndNo = 0; + // ???? + for (i = 0; i < MENU_ITEM_0; i++) itemWndFontNo[i] = -2; + for (i = 0; i < MENU_ITEM_0; i++) itemWndBtnFlag[i] = 0; + itemWndNo = 0; + // ??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + for (i = 0; i < MAX_ADR_BOOK; i++) mailWndSendFlag[i] = 0; + mailWndNo = MAIL_WND_VIEW; + // ???? + for (i = 0; i < MENU_ALBUM_0; i++) albumWndFontNo[i] = -2; + albumWndNo = 0; + // ????? + for (i = 0; i < TASK_BAR; i++) taskBarFontNo[i] = -2; + // Pf??????? + for (i = 0; i < MENU_BTL_RESULT_0; i++) resultWndFontNo[i] = -2; + // ?????? + MenuToggleFlag = 0; +#ifdef _ITEM_JIGSAW + JigsawIdx = 0; +#endif +#ifdef _TELLCHANNEL //ROG ADD Ƶ + MultiTells = FALSE; +#endif + + // ????????????D? + DeathMenuAction(); + // ????????????D? + DeathMenuAction2(); + // ??????????? + mouse.itemNo = -1; + // ????kk???? + itemNo = -1; + // k??????? + jujutuNo = -1; + // ????k???? + ItemMixPetNo = -1; +#ifdef __AI + void AI_CloseWnd(); + AI_CloseWnd(); +#endif +} + +// ??????????? *******************************************************/ +void InitMenu2(void) +{ + // ?????? + MenuToggleFlag = 0; + // ????????????D? + DeathMenuAction(); + // ????????????D? + DeathMenuAction2(); + // ??????????? + mouse.itemNo = -1; + // ????kk???? + itemNo = -1; + // k??????? + jujutuNo = -1; + // Pf??????????? + BattleResultWndFlag = FALSE; + +} + +// ??????????? *******************************************************/ +BOOL CheckMenuFlag(void) +{ + BOOL flag = FALSE; + + // ?????? + if (MenuToggleFlag != 0) flag = TRUE; + // Pf??????????? + if (BattleResultWndFlag >= 1) flag = TRUE; + // ????????????????? + if (MapWmdFlagBak >= TRUE) flag = TRUE; +#ifdef _FRIENDCHANNEL + if( assentFlag ) flag = assentFlag; + if( setRoomFlag ) flag = setRoomFlag; +#endif + + return flag; +} + +#ifdef __PHONEMESSAGE +void CleanSMS() +{ + extern STR_BUFFER ptext; + extern HANDLE MHandle; + ptext.buffer[0]='\0'; + if(MHandle) + { + TerminateThread(MHandle,1); + CloseHandle(MHandle); + } +} +#endif + + +#ifdef _AIDENGLU_ +BOOL Զ½ = FALSE; +ACTION *pԶ½ = NULL; +ACTION * ; +ACTION * ﶯ; +extern struct gameserver gmsv[]; +extern struct gamegroup gmgroup[]; +void Զ½ڻص() +{ + static int 򴰿Ƿ; + static int btnId[15], btnState[15]; + static int x = 0, y = 0; + static DWORD dwPressTime; + static char msg[][8] = { + "ӳ", + "Ա", + "" + }; + static char chardir[][8] = { + "", + "", + "", + "", + "", + "", + "", + "" + }; + if (pԶ½ == NULL){ + 򴰿Ƿ = FALSE; + = NULL; + ﶯ = NULL; + int w = 412; + int h = 301; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + pԶ½ = MakeWindowDisp(x, y, w, h, 55241, -1, FALSE); + for (int i = 0; i < 14; i++){ + btnId[i] = -2; + if (i < 10) + btnState[i] = 0; + } + dwPressTime = 0; + } + else{ + if (pԶ½->hp >= 1){ + if (joy_trg[0] & JOY_ESC){ + Զ½ = FALSE; + DeathAction(pԶ½); + DeathAction(); + DeathAction(ﶯ); + ﶯ = NULL; + 򴰿Ƿ = FALSE; + = NULL; + pԶ½ = NULL; + actBtn = 0; + return; + } + if (dwPressTime){ + if (TimeGetTime() > (dwPressTime + 100)){ + dwPressTime = 0; + if (btnState[0] == 1){// + btnState[0] = 0; + play_se(217, 320, 240); + while (TRUE){ + PcLanded.--; + if (PcLanded. < 0){ + PcLanded. = 18; + } + if (gmgroup[PcLanded.].used){ + break; + } + } + } + if (btnState[1] == 1){// + btnState[1] = 0; + play_se(217, 320, 240); + while (TRUE){ + PcLanded.++; + if (PcLanded. > 18){ + PcLanded. = 0; + } + if (gmgroup[PcLanded.].used){ + break; + } + } + } + + if (btnState[2] == 1){//С + btnState[2] = 0; + play_se(217, 320, 240); + if (PcLanded. != -1) + { + while (TRUE){ + PcLanded.С--; + if (PcLanded.С < 0){ + PcLanded.С = gmgroup[PcLanded.].num - 1; + } + if (gmsv[gmgroup[PcLanded.].startindex + PcLanded.С].used){ + break; + } + } + } + } + if (btnState[3] == 1){//С + btnState[3] = 0; + play_se(217, 320, 240); + if (PcLanded. != -1) + { + while (TRUE){ + PcLanded.С++; + if (PcLanded.С >= gmgroup[PcLanded.].num){ + PcLanded.С = 0; + } + if (gmsv[gmgroup[PcLanded.].startindex + PcLanded.С].used){ + break; + } + } + } + } + if (btnState[4] == 1){//ģ + btnState[4] = 0; + play_se(217, 320, 240); + PcLanded.ģ--; + if (PcLanded.ģ < 0){ + PcLanded.ģ = 2; + } + if (PcLanded.ģ == 0 || PcLanded.ģ == 2){ + PcLanded.ǷԶ = FALSE; + } + if (PcLanded.ģ == 1){ + PcLanded.ǷԶ = FALSE; + } + } + if (btnState[5] == 1){//ģ + btnState[5] = 0; + play_se(217, 320, 240); + PcLanded.ģ++; + if (PcLanded.ģ > 2){ + PcLanded.ģ = 0; + } + if (PcLanded.ģ == 0 || PcLanded.ģ == 2){ + PcLanded.ǷԶ = FALSE; + } + if (PcLanded.ģ == 1){ + PcLanded.ǷԶ = FALSE; + } + } + if (btnState[6] == 1){//ɫ + btnState[6] = 0; + play_se(217, 320, 240); + while (TRUE){ + PcLanded.--; + if (PcLanded. < 0){ + PcLanded. = 3; + } + if (PcLanded.½[PcLanded.][0]) break; + } + } + if (btnState[7] == 1){//ɫ + btnState[7] = 0; + play_se(217, 320, 240); + while (TRUE){ + PcLanded.++; + if (PcLanded. > 3){ + PcLanded. = 0; + } + if (PcLanded.½[PcLanded.][0]) break; + } + } + if (btnState[8] == 1){//ȷ + btnState[8] = 0; + play_se(217, 320, 240); + DeathAction(pԶ½); + pԶ½ = NULL; + Զ½ = FALSE; + if (){ + DeathAction(); + = NULL; + DeathAction(ﶯ); + ﶯ = NULL; + } + extern short actBtn; + actBtn = 0; + return; + } + if (btnState[9] == 1){//ȡ + btnState[9] = 0; + play_se(217, 320, 240); + DeathAction(pԶ½); + pԶ½ = NULL; + Զ½ = FALSE; + if (){ + DeathAction(); + = NULL; + DeathAction(ﶯ); + ﶯ = NULL; + } + extern short actBtn; + actBtn = 0; + return; + } + if (btnState[10] == 1){// + btnState[10] = 0; + play_se(217, 320, 240); + DeathAction(); + = NULL; + DeathAction(ﶯ); + ﶯ = NULL; + 򴰿Ƿ = FALSE; + } + } + } + else{ + for (int i = 0; i < 10; i++){ + if (HitDispNo == btnId[i]){ + if (i == 0 || i == 1) ShowBottomLineString(FONT_PAL_WHITE, "ô"); + if (i == 2 || i == 3) ShowBottomLineString(FONT_PAL_WHITE, "·,ôá"); + if (i == 4 || i == 5) ShowBottomLineString(FONT_PAL_WHITE, "ӳԶ Ա躰Զ ˣԶ psصԶAIģʽ"); + if (i == 6 || i == 7) ShowBottomLineString(FONT_PAL_WHITE, "õ½"); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + dwPressTime = TimeGetTime(); + btnState[i] = 1; + break; + } + } + } + if (HitDispNo == btnId[14]){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + dwPressTime = TimeGetTime(); + btnState[10] = 1; + } + } + } + + extern int Զ½Ƿ; + if (HitFontNo == btnId[10]){ + ShowBottomLineString(FONT_PAL_WHITE, "½ϷпɰF9͹ر,Աģʽ½Ϸ󺰻ɹرոùֹͣ"); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (PcLanded. != -1 && PcLanded.С != -1 && PcLanded. != -1){ + Զ½Ƿ = !Զ½Ƿ; + if (!Զ½Ƿ){ + extern int Ƿص, ǷصǺ, Ƿؿ_1; + Ƿص = FALSE; + ǷصǺ = FALSE; + Ƿؿ_1 = FALSE; + } + } + else{ + StockChatBufferLine("Ѵ·ͽɫѡܲ", FONT_PAL_RED); + } + } + } + if (HitFontNo == btnId[12]){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ShowBottomLineString(FONT_PAL_WHITE, "ӳ͵˿øùܡ"); + if (PcLanded.ģ == 0 || PcLanded.ģ == 2) + PcLanded.ǷԶ = !PcLanded.ǷԶ; + else{ + PcLanded.ǷԶ = FALSE; + StockChatBufferLine("ģʽֻжӳ͵˿ɿ", FONT_PAL_RED); + } + } + } + if (HitFontNo == btnId[13]){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ShowBottomLineString(FONT_PAL_WHITE, "ֻжԱøùܡ"); + if (PcLanded.ģ == 1) + PcLanded.ǷԶ = !PcLanded.ǷԶ; + else{ + PcLanded.ǷԶ = FALSE; + StockChatBufferLine("ԶֻжԱģʽɿ", FONT_PAL_RED); + } + } + } + if (HitFontNo == btnId[11]){ + ShowBottomLineString(FONT_PAL_WHITE, "½ķ"); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (򴰿Ƿ){ + 򴰿Ƿ = FALSE; + if (){ + DeathAction(); + = NULL; + DeathAction(ﶯ); + ﶯ = NULL; + } + } + else 򴰿Ƿ = TRUE; + } + } + int ƫX = 0; + if (򴰿Ƿ) ƫX = -90; + if (򴰿Ƿ){ + if (!){ + = MakeWindowDisp(607 + ƫX, 147, 192, 148, 55242, -1, FALSE); + ﶯ = MakeAnimDisp(660 + ƫX, 240, pc.graNo, 0); + ﶯ->anim_ang = PcLanded.﷽; + pattern(ﶯ, ANM_NOMAL_SPD, ANM_LOOP); + btnId[14] = -2; + btnState[10] = 0; + } + else if (->hp >= 1){ + StockDispBuffer(((WINDOW_DISP *)->pYobi)->mx, ((WINDOW_DISP *)->pYobi)->my, DISP_PRIO_MENU, 55242, 1); + PcLanded.﷽ = ﶯ->anim_ang; + btnId[14] = StockDispBuffer(((WINDOW_DISP *)->pYobi)->mx - 55, ((WINDOW_DISP *)->pYobi)->my - 90, DISP_PRIO_IME3, 26262 + btnState[10], 2); + } + } + StockDispBuffer(((WINDOW_DISP *)pԶ½->pYobi)->mx + ƫX, ((WINDOW_DISP *)pԶ½->pYobi)->my, DISP_PRIO_MENU, 55241, 1); + btnId[0] = StockDispBuffer(x + 128 + ƫX, y + 92 + 70, DISP_PRIO_IME3, 26064 + btnState[0], 2); + btnId[1] = StockDispBuffer(x + 109 + ƫX, y + 107 + 71, DISP_PRIO_IME3, 26066 + btnState[1], 2); + + btnId[2] = StockDispBuffer(x + 273 + ƫX, y + 92 + 70, DISP_PRIO_IME3, 26064 + btnState[2], 2); + btnId[3] = StockDispBuffer(x + 254 + ƫX, y + 107 + 71, DISP_PRIO_IME3, 26066 + btnState[3], 2); + + btnId[4] = StockDispBuffer(x + 128 + ƫX, y + 92 + 106, DISP_PRIO_IME3, 26064 + btnState[4], 2); + btnId[5] = StockDispBuffer(x + 109 + ƫX, y + 107 + 107, DISP_PRIO_IME3, 26066 + btnState[5], 2); + + btnId[6] = StockDispBuffer(x + 128 + ƫX, y + 92 + 142, DISP_PRIO_IME3, 26064 + btnState[6], 2); + btnId[7] = StockDispBuffer(x + 109 + ƫX, y + 107 + 143, DISP_PRIO_IME3, 26066 + btnState[7], 2); + + btnId[8] = StockDispBuffer(x + 207 + ƫX, y + 152, DISP_PRIO_IME3, 26262 + btnState[8], 2); + btnId[9] = StockDispBuffer(x + 207 + ƫX, y + 152, DISP_PRIO_IME3, 26264 + btnState[9], 2); + + char moji[256]; + if (PcLanded. != -1){ + CenteringStr(gmgroup[PcLanded.].name, moji, CHAR_NAME_LEN); + StockFontBuffer(x + 105 + ƫX, y + 64, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + } + if (PcLanded.ģ != -1){ + StockFontBuffer(x + 150 + ƫX, y + 100, FONT_PRIO_FRONT, FONT_PAL_YELLOW, msg[PcLanded.ģ], 0); + } + if (PcLanded. != -1){ + CenteringStr(PcLanded.½[PcLanded.], moji, CHAR_NAME_LEN); + StockFontBuffer(x + 105 + ƫX, y + 136, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + } + + if (Զ½Ƿ) + btnId[10] = StockFontBuffer(x + 150 + ƫX, y + 171, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "", 2); + else + btnId[10] = StockFontBuffer(x + 150 + ƫX, y + 171, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ر", 2); + if (PcLanded.С != -1){ + StockFontBuffer(x + 305 + ƫX, y + 64, FONT_PRIO_FRONT, FONT_PAL_YELLOW, gmsv[gmgroup[PcLanded.].startindex + PcLanded.С].name, 0); + } + btnId[11] = StockFontBuffer(x + 320 + ƫX, y + 100, FONT_PRIO_FRONT, FONT_PAL_YELLOW, chardir[PcLanded.﷽], 2); + if (PcLanded.ǷԶ) + btnId[12] = StockFontBuffer(x + 320 + ƫX, y + 136, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "", 2); + else + btnId[12] = StockFontBuffer(x + 320 + ƫX, y + 136, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ر", 2); + if (PcLanded.ǷԶ) + btnId[13] = StockFontBuffer(x + 320 + ƫX, y + 171, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "", 2); + else + btnId[13] = StockFontBuffer(x + 320 + ƫX, y + 171, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ر", 2); + } + } +} + +#endif + + + + +#ifdef _AI_OTHER +extern int AI_Other_State; +extern void AI_OtherProc(); +#endif +void MenuProc(void) +{ + int x, y, i; + x = y = i = 0; + char moji[256]; +#ifdef _ITEM_JIGSAW + DrawJigsawFlag = false; +#endif +#ifdef __AI + extern int AI_State; + if (AI_State){ + extern BOOL AI_SettingProc(); + if (AI_SettingProc()){ + AI_State = 0; + extern short actBtn; + actBtn = 0; + } + } +#endif +#ifdef _AIDENGLU_ + if (Զ½){ + Զ½ڻص(); + } +#endif +#ifdef _AI_OTHER + if (AI_Other_State) AI_OtherProc(); +#endif + +#ifdef _TELLCHANNEL //ROG ADD Ƶ + if (MultiTells == TRUE) + { + SelectChar(); + if (MenuToggleFlag & JOY_ESC) + DeathTellChannel(); + } +#endif + +#ifdef _PET_SKINS + + if (petWndNo == 1){ + petSkinProc(); + } + else + { + initPetSkinWin(); + } + +#endif + +#ifdef _TIMEBAR_FUNCTION + if(timeBarFlag == TRUE) + { + DrawTimeBar(); + } +#endif + + // ?????????????? +#ifdef __AI + if (joy_trg[0] & JOY_ESC && checkFieldMenuFlag() == FALSE && !AI_State&&!Զ½ + + + ){ +#else + if( joy_trg[ 0 ] & JOY_ESC && checkFieldMenuFlag() == FALSE ){ +#endif + // ????????????? + if (GetImeString() == NULL){ + // ??????? + if (MenuToggleFlag != 0 || BattleResultWndFlag >= 1){ + MenuToggleFlag = 0; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ??????????? + mouse.itemNo = -1; + // ????kk???? + itemNo = -1; + // k??????? + jujutuNo = -1; + // ???????????? + if (MapWmdFlagBak != TRUE){ + // ???????? + play_se(203, 320, 240); + } + } + else{ // ?????????? + if (GetImeString() == NULL){ + + MenuToggleFlag ^= JOY_ESC; // ????? + // ???????? + play_se(202, 320, 240); + // ???? + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + systemWndNo = 0; // ?????k???? + + // ???????? + if (MenuToggleFlag & JOY_ESC){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_ESC; // ????? + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } + } + } + // ?????????? + DeathMenuAction(); + DeathMenuAction2(); + // ???????? + saveUserSetting(); + } + } + // ?????????????? +#ifdef __AI + if (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[3] && !AI_State&&!Զ½ + + ){ +#else + if( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 3 ] ){ +#endif +#ifdef _BATTLESKILL + extern int wonflag ; + if ( wonflag == 1 ) + play_se( 220, 320, 240 ); + else { +#endif + MenuToggleFlag ^= JOY_ESC; // ????? + // ???? + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + systemWndNo = 0; // ?????k???? + // ?????????? + DeathMenuAction(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_ESC){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_ESC; // ????? + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } +#ifdef _BATTLESKILL + } +#endif + } + + // ?????????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_S && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[1])) + + + ){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_S && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 1 ] ) ){ +#endif + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ??? + play_se(220, 320, 240); + } + else{ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ????? + for (i = 0; i < MENU_STATUS_0; i++) statusWndFontNo[i] = -2; + for (i = 0; i < MENU_STATUS_0; i++) statusWndBtnFlag[i] = 0; + statusWndNo = 0; + // ?????????? + DeathMenuAction(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_CTRL_S){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_CTRL_S; // ?????????? + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } + } + } + + // Nuke 0413: Trade +#ifdef __AI + if (!AI_State&&!Զ½ && joy_trg[0] & JOY_CTRL_T && GetImeString() == NULL) { +#else + if ( joy_trg[ 0 ] & JOY_CTRL_T && GetImeString() == NULL ) { +#endif + joy_trg[0] &= ~JOY_CTRL_T; + + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ??? + play_se(220, 320, 240); + } + else{ + +#if 0 + MenuToggleFlag ^= JOY_CTRL_T; // CTRL + T ?? + + for (i = 0; i < MENU_TRADE_0; i++) tradeWndFontNo[i] = -2; + for (i = 0; i < MENU_TRADE_0; i++) tradeWndBtnFlag[i] = 0; + + tradeWndNo = 0; + + tradeInit(); + + DeathMenuAction(); + DeathMenuAction2(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_CTRL_T){ + MenuToggleFlag &= 0; + MenuToggleFlag |= JOY_CTRL_T; // ?????????? + // Pf??????????? + BattleResultWndFlag = FALSE; + + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } +#else + int dx, dy; + int flag; + + // ??????????? + getRouteData(pc.dir, &dx, &dy); + flag = checkCharObjPoint(nowGx + dx, nowGy + dy, CHAROBJ_TYPE_USER_NPC); + // ?????V????????????? + if (partyModeFlag == 0 && flag == TRUE && eventWarpSendFlag == 0 && eventEnemySendFlag == 0 + && sendEnFlag == 0 && tradeFlag == 0 +#ifdef _STREET_VENDOR + && (pc.iOnStreetVendor == 0 || sStreetVendorBuyBtn == 2) +#endif +#ifdef _THEATER + && pc.iTheaterMode == 0 +#endif + ) + { + if (!(MenuToggleFlag & JOY_CTRL_T))// ?? + { + if (bNewServer) + lssproto_TD_send(sockfd, "D|D"); + else + old_lssproto_TD_send(sockfd, "D|D"); + } + } +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1) + StockChatBufferLine("̯вýн", FONT_PAL_RED); +#endif +#ifdef _THEATER + if (pc.iTheaterMode > 0) + StockChatBufferLine("רı", FONT_PAL_RED); +#endif + play_se(217, 320, 240); // ????? + +#endif + + } + } + + // ???????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_P && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[2])) + + + ){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_P && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 2 ] ) ){ +#endif + // Pf??????????????? + if (ProcNo == PROC_BATTLE){ + // ??? + play_se(220, 320, 240); + } + else{ + { + MenuToggleFlag ^= JOY_CTRL_P; // CTRL + P ?? + // ??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + petWndNo = 0; // ?????k???? + + // ?????????? + DeathMenuAction(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_CTRL_P){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_CTRL_P; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } + } + } + } + // ????????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_I && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[4])) + + ){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_I && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 4 ] ) ){ +#endif + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ??? + play_se(220, 320, 240); + } + else{ +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1 || sStreetVendorBuyBtn == 2) StockChatBufferLine("̯вʹõ", FONT_PAL_RED); + else +#endif +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000002) + StockChatBufferLine("רı", FONT_PAL_RED); + else if (pc.iTheaterMode & 0x00000001) + StockChatBufferLine("רĿ", FONT_PAL_RED); + else +#endif + { + MenuToggleFlag ^= JOY_CTRL_I; // CTRL + I ?? + // ????????k???? + for (i = 0; i < MENU_ITEM_0; i++) itemWndFontNo[i] = -2; + for (i = 0; i < MENU_ITEM_0; i++) itemWndBtnFlag[i] = 0; + itemWndNo = 0; + mouse.itemNo = -1; + itemWndDropGold = 0; + + // ?????????? + if (BattleResultWndFlag >= 1) DeathMenuAction(); + // ?????????? + DeathMenuAction2(); + // ???????? + saveUserSetting(); + // ???????? + if (MenuToggleFlag & JOY_CTRL_I){ + MenuToggleFlag &= ~JOY_CTRL_M; // ??????????? + MenuToggleFlag &= ~JOY_CTRL_T; + MenuToggleFlag &= ~JOY_B; + MenuToggleFlag |= JOY_CTRL_I; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ????????? + MapWmdFlagBak = FALSE; + // ???????? + play_se(202, 320, 240); + + } + else{ + // ???????? + play_se(203, 320, 240); + } + } + } + } + + // ???????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_M && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[0]) + || (MapWmdFlagBak == TRUE && BattleResultWndFlag == FALSE && EncountFlag == FALSE && ProcNo == PROC_GAME && SubProcNo == 3 + + ) + )){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_M && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 0 ] ) + || ( MapWmdFlagBak == TRUE && BattleResultWndFlag == FALSE && EncountFlag == FALSE && ProcNo == PROC_GAME && SubProcNo == 3 ) + ){ +#endif + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ??? + play_se(220, 320, 240); + } + else{ + + MenuToggleFlag ^= JOY_CTRL_M; // CTRL + M ?? + // ??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + mapWndNo = 0; // ?????k???? + + // ?????????? + if (BattleResultWndFlag >= 1) DeathMenuAction(); + DeathMenuAction2(); + // ???????? + // ???????? + if (MenuToggleFlag & JOY_CTRL_M){ + MenuToggleFlag &= ~JOY_CTRL_I; // ???????????? + MenuToggleFlag &= ~JOY_CTRL_T; + MenuToggleFlag &= ~JOY_B; + MenuToggleFlag |= JOY_CTRL_M; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ????????? + MapWmdFlagBak = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } + } + } + + // ???????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_E && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[5])) + + ){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_E && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 5 ] ) ){ +#endif +#ifdef _BATTLESKILL + extern int wonflag ; + if ( wonflag == 1 ) + play_se( 220, 320, 240 ); + else { +#endif + MenuToggleFlag ^= JOY_CTRL_E; // CTRL + E ?? + // ??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + mailWndNo = MAIL_WND_VIEW; // ?????k???? + mailViewWndPageNo = 0; // ???????????k???? + mailItemNo = -1; // ??????????k???? + InitMailSendFlag(); // ???????? + // ?????????? + DeathMenuAction(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_CTRL_E){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_CTRL_E; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } +#ifdef _BATTLESKILL + } +#endif + //} + } + + // ????????? +#ifdef __AI + if (!AI_State&&!Զ½ && ((joy_trg[0] & JOY_CTRL_A && GetImeString() == NULL) + || (TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[6])) + + + ){ +#else + if( ( joy_trg[ 0 ] & JOY_CTRL_A && GetImeString() == NULL ) + || ( TaskBarFlag == TRUE && mouse.onceState & MOUSE_LEFT_CRICK && HitDispNo == taskBarFontNo[ 6 ] ) ){ +#endif +#ifdef _BATTLESKILL + extern int wonflag ; + if ( wonflag == 1 ) + play_se( 220, 320, 240 ); + else { +#endif + MenuToggleFlag ^= JOY_CTRL_A; // CTRL + A ?? + // ??? + for (i = 0; i < MENU_ALBUM_0; i++) albumWndFontNo[i] = -2; + mapWndNo = 0; // ?????k???? + + // ?????????? + DeathMenuAction(); + // ???????? + saveUserSetting(); + + // ???????? + if (MenuToggleFlag & JOY_CTRL_A){ + MenuToggleFlag &= JOY_CTRL_I | JOY_CTRL_M; // ?????????????????? + MenuToggleFlag |= JOY_CTRL_A; + // Pf??????????? + BattleResultWndFlag = FALSE; + // ???????? + play_se(202, 320, 240); + } + else{ + // ???????? + play_se(203, 320, 240); + } + //} +#ifdef _BATTLESKILL + } +#endif + } + +#ifdef _SA_LIAOTIAN_ + static int ״̬1=0; + static int ״̬2=0; + static int ״̬3=0; + char ʾ[128]; + StockDispBuffer(785, 505, DISP_PRIO_IME3, 55260+״̬1, 1); + if( MakeHitBox(785-10, 505-10,785+10,505+10, DISP_PRIO_IME4 ) == TRUE ){ + sprintf(ʾ,"Ϣ,ǰϢλ%d",NowChatLine); + ShowBottomLineString(FONT_PAL_WHITE, ʾ); + if(mouse.state & MOUSE_LEFT_CRICK){ + ״̬1 = 1; + if(mouse.onceState & MOUSE_LEFT_CRICK){ + if(NowChatLine > NowMaxChatLine){ + NowChatLine--; + if (NowChatLine <= 0){ + NowChatLine = 1; + } + } + play_se(203, 320, 240); + } + }else ״̬1=0; + }else ״̬1=0; + StockDispBuffer(785, 530, DISP_PRIO_IME3, 55262+״̬2, 1); + if( MakeHitBox(785-10, 530-10,785+10,530+10, DISP_PRIO_IME4 ) == TRUE ){ + sprintf(ʾ,"Ϣ,ǰϢλ%d",NowChatLine); + ShowBottomLineString(FONT_PAL_WHITE, ʾ); + if( (mouse.state & MOUSE_LEFT_CRICK)){ + ״̬2 = 1; + if(mouse.onceState & MOUSE_LEFT_CRICK){ + if(*ChatBuffer[ NowChatLine].buffer){ + NowChatLine++; + if (NowChatLine > MAX_CHAT_LINE) + NowChatLine = MAX_CHAT_LINE; + } + play_se(203, 320, 240); + } + }else ״̬2=0; + }else ״̬2=0; + StockDispBuffer(785, 555, DISP_PRIO_IME3, 55264+״̬3, 1); + if( MakeHitBox(785-10, 555-10,785+10,555+10, DISP_PRIO_IME4 ) == TRUE ){ + sprintf(ʾ,"Ϣʾ,ǰϢλ%d",NowChatLine); + ShowBottomLineString(FONT_PAL_WHITE, ʾ); + if( (mouse.state & MOUSE_LEFT_CRICK)){ + ״̬3 = 1; + if(mouse.onceState & MOUSE_LEFT_CRICK){ + extern int NowChatLine_Bak; + NowChatLine=NowChatLine_Bak; + play_se(203, 320, 240); + } + }else ״̬3=0; + }else ״̬3=0; +#endif +#ifdef _EFFECT_MAP_ + if(ProcNo==PROC_GAME){ + StockDispBuffer(400, 288, DISP_PRIO_MENU-1, 55256, 0); + } +#endif +#ifdef _RED_MEMOY_ + RedMemoyCall(); + +#endif + StockDispBuffer(TASK_BAR_X, TASK_BAR_Y, DISP_PRIO_MENU, CG_TASK_BAR_BACK, 1); + if (mouse.nowPoint.y >= 456 + DISPLACEMENT_Y){ + if (taskBarY > TASK_BAR_Y) taskBarY--; + TaskBarFlag = TRUE; +#ifdef __ONLINEGM + if(OnlineGmFlag==TRUE){ + TaskBarFlag = FALSE; + } +#endif + } + else{ + if (TaskBarFlag == TRUE){ + if (taskBarY < TASK_BAR_Y + 24) taskBarY++; + if (taskBarY == TASK_BAR_Y + 24){ + for (i = 0; i < TASK_BAR; i++) albumWndFontNo[i] = -2; + TaskBarFlag = FALSE; + } + } + } + + if (TaskBarFlag == TRUE){ + x = taskBarX, y = taskBarY; + + taskBarFontNo[0] = StockDispBuffer(x, y, DISP_PRIO_IME3, CG_TASK_BAR_MAP_UP + ((MenuToggleFlag & JOY_CTRL_M) ? 1 : 0), 2); + taskBarFontNo[1] = StockDispBuffer(x + 24, y, DISP_PRIO_IME3, CG_TASK_BAR_STATUS_UP + ((MenuToggleFlag & JOY_CTRL_S) ? 1 : 0), 2); + taskBarFontNo[2] = StockDispBuffer(x + 48, y, DISP_PRIO_IME3, CG_TASK_BAR_PET_UP + ((MenuToggleFlag & JOY_CTRL_P) ? 1 : 0), 2); + taskBarFontNo[4] = StockDispBuffer(x + 72, y, DISP_PRIO_IME3, CG_TASK_BAR_ITEM_UP + ((MenuToggleFlag & JOY_CTRL_I) ? 1 : 0), 2); + taskBarFontNo[5] = StockDispBuffer(x + 95, y, DISP_PRIO_IME3, CG_TASK_BAR_MAIL_UP + ((MenuToggleFlag & JOY_CTRL_E) ? 1 : 0), 2); + taskBarFontNo[6] = StockDispBuffer(x + 118, y, DISP_PRIO_IME3, CG_TASK_BAR_ALBUM_UP + ((MenuToggleFlag & JOY_CTRL_A) ? 1 : 0), 2); + taskBarFontNo[3] = StockDispBuffer(x + 140, y, DISP_PRIO_IME3, CG_TASK_BAR_SYSTEM_UP + ((MenuToggleFlag & JOY_ESC) ? 1 : 0), 2); + } + + if (MenuToggleFlag & JOY_ESC + + ){ + int w = 7; + int h = 8; + // ?????k??? + switch (systemWndNo){ + + case 0: // ???? ?????? + + if (pActMenuWnd == NULL){ +#ifdef _NEW_SYSTEM_MENU + x = (lpDraw->xSize - w * 64) / 2; + y = (lpDraw->ySize - h * 48) / 2; + + pActMenuWnd = MakeWindowDisp(x, y, w, h, CG_WND_TITLE_SYSTEM, 1, FALSE); +#else + pActMenuWnd = MakeWindowDisp( 4, 4, 3, 7, CG_WND_TITLE_SYSTEM, 1 ); +#endif + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??????? + if (HitFontNo == systemWndFontNo[0]){ + // ?????? +#ifdef __PHONEMESSAGE + CleanSMS(); +#endif + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 1; + // ???????? + play_se(202, 320, 240); + break; + } + // ????@e?? + if (HitFontNo == systemWndFontNo[1]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 2; + // ???????? + play_se(202, 320, 240); + break; + } + // ???@e?? + if (HitFontNo == systemWndFontNo[4]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 4; + // ???????? + play_se(202, 320, 240); + break; + } + // ???@e?? + if (HitFontNo == systemWndFontNo[3]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 3; + // ???????? + play_se(202, 320, 240); + break; + } + // ????@e?? + if (HitFontNo == systemWndFontNo[5]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 6; + // ???????? + play_se(202, 320, 240); + break; + } + //ԭصdz + if (HitFontNo == systemWndFontNo[6]){ + // ?????? +#ifdef __PHONEMESSAGE + CleanSMS(); +#endif + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 7; + // ???????? + play_se(202, 320, 240); + + break; + } + // ??? + if (HitFontNo == systemWndFontNo[2]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ??????????? + MenuToggleFlag ^= JOY_ESC; + // ???????? + play_se(203, 320, 240); + break; + } +#ifdef __AI + //Զս趨 + if (HitFontNo == systemWndFontNo[7]){ + // ?????? + extern int AI_State; + AI_State = 1; + extern short actBtn; + actBtn = 1; + closeEtcSwitch(); + closeJoinChannelWN(); + MenuToggleFlag = 0; + DeathMenuAction2(); + DeathMenuAction(); + // ???????? + play_se(202, 320, 240); + break; + } + if (HitFontNo == systemWndFontNo[24]){ + if (AI == AI_SELECT){ + AI = AI_NONE; + StockChatBufferLine("رգģʽ", FONT_PAL_RED); + pc.etcFlag &= (~PC_AI_MOD); + lssproto_FS_send(sockfd, pc.etcFlag); + } + else { + AI = AI_SELECT; + StockChatBufferLine("ģʽ", FONT_PAL_RED); + pc.etcFlag |= PC_AI_MOD; + lssproto_FS_send(sockfd, pc.etcFlag); + } + play_se(202, 320, 240); + break; + } +#endif + static BOOL stopBGMClicked = FALSE; + if (HitFontNo == systemWndFontNo[8]){ + if (MuteFlag){ + StockChatBufferLine("", FONT_PAL_RED); + MuteFlag = FALSE; + if (stopBGMClicked) + { + play_bgm(map_bgm_no); + } + } + else{ + stopBGMClicked = TRUE; + StockChatBufferLine("ر", FONT_PAL_RED); + play_se(202, 320, 240); + stop_bgm(); + MuteFlag = TRUE; + } + saveUserSetting(); + break; + } +#ifdef _AIDENGLU_ + if (HitFontNo == systemWndFontNo[9]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + play_se(202, 320, 240); + closeEtcSwitch(); + closeJoinChannelWN(); + MenuToggleFlag = 0; + DeathMenuAction2(); + DeathMenuAction(); + Զ½ = TRUE; + extern short actBtn; + actBtn = 1; + break; + } +#endif + if (HitFontNo == systemWndFontNo[10]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + MenuToggleFlag ^= JOY_ESC; +#ifdef _CANCEL_FANTI + StockChatBufferLine("ܿУ", FONT_PAL_RED); + play_se(202, 320, 240); +#else + if (忪) + { + 忪 = FALSE; + StockChatBufferLine("л壡", FONT_PAL_RED); + } + else{ + 忪 = TRUE; + StockChatBufferLine("л壡", FONT_PAL_RED); + } + play_se(202, 320, 240); + break; +#endif + + } + if (HitFontNo == systemWndFontNo[15]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + MenuToggleFlag ^= JOY_ESC; + Ҽ = !Ҽ; + if (Ҽ) + StockChatBufferLine("Ҽ", FONT_PAL_RED); + else + StockChatBufferLine("رҼ", FONT_PAL_RED); + + play_se(202, 320, 240); + break; + } + + if (HitFontNo == systemWndFontNo[23]){ + play_se(202, 320, 240); + 鿪 = !鿪; + if (鿪) + StockChatBufferLine("ʾ", FONT_PAL_RED); + else + StockChatBufferLine("رվʾ", FONT_PAL_RED); + + break; + } + if (HitFontNo == systemWndFontNo[22]){ + play_se(202, 320, 240); + ο = !ο; + if (ο) + StockChatBufferLine("ܱ", FONT_PAL_RED); + else{ + //extern void þֹĶΪվ( void ); + //þֹĶΪվ(); + StockChatBufferLine("ʾܱ", FONT_PAL_RED); + } + + + break; + } +#ifdef _RENWU_ + if (HitFontNo == systemWndFontNo[21]){ + closeEtcSwitch(); + closeJoinChannelWN(); + if (CheckMenuFlag()) + InitMenu2(); + extern short HelpProcNo; + HelpProcNo = 0; + ѯ=TRUE; + + break; + } +#endif +#ifdef _NEW_SYSTEM_MENU + for (int i = 11; i < MENU_SYSTEM_0; i++){ + if (i != 24 && i != 15 && i != 23 && i != 22 +#ifdef _RENWU_ + && i != 21 +#endif + ) + if (HitFontNo == systemWndFontNo[i]){ +#ifdef _RELUA_ + extern void ReLoadStoneAgeLUA(char *filename); + if (i == 16){ + extern int windowTypeWN; + extern short wnCloseFlag; + extern int cloasewindows; + extern SA_WINDOWS windows; + DeathAction(windows.ptActMenuWin); + windows.ptActMenuWin = 0; + wnCloseFlag = 0; + windowTypeWN = -1; + wnCloseFlag = 1; + cloasewindows = 1; + ReLoadStoneAgeLUA(""); + } +#endif + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + MenuToggleFlag ^= JOY_ESC; + lssproto_SaMenu_send(sockfd, i); + play_se(202, 320, 240); + break; + } + } + +#endif + break; + } + // ?@e + x = pActMenuWnd->x + 28; + + // ????????? + y = pActMenuWnd->y + 54; +#ifdef _CHAR_NEWLOGOUT + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ؼ¼ ", 2); y += 34;//y += 40; +#else + systemWndFontNo[ 0 ] = StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, " ", 2 ); y += 34;//y += 40; +#endif + systemWndFontNo[6] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ԭصdz ", 2); y += 34;//y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " 趨 ", 2); y += 34;//y += 40; + systemWndFontNo[4] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 34;//y += 40; + systemWndFontNo[3] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " Ч趨 ", 2); y += 34;//y += 40; + systemWndFontNo[5] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " 趨 ", 2); y += 34;//y += 52; + systemWndFontNo[7] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ս趨 ", 2); y += 34;//y += 40; + if (MuteFlag){ + systemWndFontNo[8] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 34;//y += 40; + } + else{ + systemWndFontNo[8] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ر ", 2); y += 34;//y += 40; + } +#ifdef _NEW_SYSTEM_MENU + y = pActMenuWnd->y + 54; + systemWndFontNo[17] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ٷҳ ", 2); y += 34;//y += 40; + systemWndFontNo[18] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ҵ ", 2); y += 34;//y += 40; + + systemWndFontNo[11] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ԭ ", 2); y += 34;//y += 40; + systemWndFontNo[12] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ȡԭ ", 2); y += 34;//y += 40; + systemWndFontNo[13] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ֧Ʊ ", 2); y += 34;//y += 40; + systemWndFontNo[14] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ѯ ", 2); y += 34;//y += 40; + systemWndFontNo[15] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " Ҽ ", 2); y += 34;//y += 40; + systemWndFontNo[16] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " Ϣ ", 2); y += 34;//y += 40; + y = pActMenuWnd->y + 54; + systemWndFontNo[19] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ֵ߳ ", 2); y += 34;//y += 40; + systemWndFontNo[20] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ʹ ", 2); y += 34;//y += 40; + systemWndFontNo[21] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ݴ ", 2); y += 34;//y += 40; + systemWndFontNo[9] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ", 2); y += 34;//y += 40; + if (忪){ + systemWndFontNo[10] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " л ", 2); y += 34;//y += 40; + } + else{ + systemWndFontNo[10] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " л ", 2); y += 34;//y += 40; + } + if (ο){ + systemWndFontNo[22] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ʾ ", 2); y += 34;//y += 40; + } + else{ + systemWndFontNo[22] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ", 2); y += 34;//y += 40; + } + if (鿪){ + systemWndFontNo[23] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ر ", 2); y += 34;//y += 40; + } + else{ + systemWndFontNo[23] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ʾ ", 2); y += 34;//y += 40; + } + if (AI == AI_SELECT){ + systemWndFontNo[24] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " رս ", 2); y += 34;//y += 40; + } + else{ + systemWndFontNo[24] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " Զս ", 2); y += 34;//y += 40; + } + + systemWndFontNo[25] = StockFontBuffer(x + 0 , y, FONT_PRIO_FRONT, 0, " ս ", 2); //y += 40; + systemWndFontNo[26] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, 0, " ", 2); //y += 40; + systemWndFontNo[27] = StockFontBuffer(x + 280, y, FONT_PRIO_FRONT, 0, " ɾ ", 2); y += 34;//y += 40; + + systemWndFontNo[2] = StockFontBuffer(x + 140, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " ", 2); +#else + systemWndFontNo[ 2 ] = StockFontBuffer( x, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " ", 2 ); +#endif + break; + + case 1: // + if (pActMenuWnd == NULL){ + x = (lpDraw->xSize - 3 * 64) / 2; + y = (lpDraw->ySize - 3 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 3, 3, CG_WND_TITLE_LOGOUT, 1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???? + if (HitFontNo == systemWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; +#ifdef _CHAR_NEWLOGOUT + systemWndNo = 0; + lssproto_CharLogout_send(sockfd, 1); +#else + GameState = GAME_LOGIN; + ChangeProc2( PROC_CHAR_LOGOUT ); +#endif + play_se(206, 320, 240); + break; + } + // ????? + if (HitFontNo == systemWndFontNo[1]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ?????? + systemWndNo = 0; + play_se(203, 320, 240); + break; + } + } + + // ?@e + x = pActMenuWnd->x + 38; + y = pActMenuWnd->y + 56; + +#ifdef _NEWFONT_ + systemWndFontNo[0] = StockFontBuffer(x+20, y, FONT_PRIO_FRONT, 0, " ȷ ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x+20, y, FONT_PRIO_FRONT, 0, " Ҫ ", 2); y += 40; +#else + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ȷ ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " Ҫ ", 2); y += 40; +#endif + break; + + case 2: // ?????@e ?????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? +#ifndef _TALK_WINDOW + x = (lpDraw->xSize - 4 * 64) / 2; + y = (lpDraw->ySize - 8 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 4, 8, CG_WND_TITLE_CHAT, 1, FALSE); +#else + x = (lpDraw->xSize - 4 * 64) / 2; + y = (lpDraw->ySize - 9 * 48) / 2; + pActMenuWnd = MakeWindowDisp( x, y, 4, 9, CG_WND_TITLE_CHAT, 1, FALSE ); +#endif + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ????????????? + if (mouse.autoState & MOUSE_LEFT_CRICK){ + // ??????? ???? + if (HitFontNo == systemWndFontNo[0]){ + NowMaxChatLine++; + if (NowMaxChatLine > DEF_CHAT_LINE){ + NowMaxChatLine = DEF_CHAT_LINE; + play_se(220, 320, 240); + } + else{ + // ????? + play_se(217, 320, 240); + } + } + // ??????? ???? + if (HitFontNo == systemWndFontNo[1]){ + // ??? + NowMaxChatLine--; + // ???????? + if (NowMaxChatLine <= -1){ + NowMaxChatLine = 0; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + play_se(217, 320, 240); + } + } + // ??????@e?? + if (HitFontNo == systemWndFontNo[2]){ + // ? + MyChatBuffer.color++; + // ???????? + if (MyChatBuffer.color >= FONT_PAL_NUM) MyChatBuffer.color = 0; + // ????? + play_se(217, 320, 240); + } + + // ?K? + if (HitFontNo == systemWndFontNo[4]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + systemWndNo = 5; + // ???????? + play_se(202, 320, 240); + break; + } + // ??????? ???? + if (HitFontNo == systemWndFontNo[5]){ + // ??? + NowMaxVoice++; + // ???????? + if (NowMaxVoice > MAX_VOICE){ + NowMaxVoice = MAX_VOICE; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + play_se(217, 320, 240); + } + } + // ??????? ???? + if (HitFontNo == systemWndFontNo[6]){ + // ??? + NowMaxVoice--; + // ???????? + if (NowMaxVoice <= 0){ + NowMaxVoice = 1; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + play_se(217, 320, 240); + } + } +#ifdef _TALK_WINDOW + if(HitFontNo == systemWndFontNo[7]){ + g_bTalkWindow = !g_bTalkWindow; + if(!WindowMode && g_bTalkWindow){ + StockChatBufferLine("ȫӫĻģʽ޷ʹñ",FONT_PAL_RED); + g_bTalkWindow = FALSE; + } + play_se(217,320,240); + if(g_bTalkWindow) TalkWindow.Create(); + else TalkWindow.Visible(FALSE); + } +#endif + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitFontNo == systemWndFontNo[3]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????@e?????? + systemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // ???????? + saveUserSetting(); + break; + } + } + // ?@e + x = pActMenuWnd->x + 56; + y = pActMenuWnd->y + 56; + sprintf_s(moji, "Ŀǰʾ%3d С", NowMaxChatLine); + StockFontBuffer(x - 16, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 32; + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 32; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 32; + systemWndFontNo[2] = StockFontBuffer(x, y, FONT_PRIO_FRONT, MyChatBuffer.color, " ıɫ ", 2); y += 32; + systemWndFontNo[4] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ¼ ", 2); y += 44; + + sprintf_s(moji, "Ŀǰ%3d ", NowMaxVoice); + StockFontBuffer(x - 16, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 32; + systemWndFontNo[5] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 32; + systemWndFontNo[6] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 44; + +#ifdef _TALK_WINDOW + StockFontBuffer(x - 16,y,FONT_PRIO_FRONT,FONT_PAL_YELLOW,"Ӵ趨",0);y += 32; + systemWndFontNo[7] = StockFontBuffer(x + 20,y,FONT_PRIO_FRONT,0,g_bTalkWindow ? "رӴ":"Ӵ",2);y += 32; +#endif + + systemWndFontNo[3] = StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " һҳ ", 2); y += 40; + + break; + + case 3: // ????@e ?????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + x = (lpDraw->xSize - 4 * 64) / 2; + y = (lpDraw->ySize - 6 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 4, 6, CG_WND_TITLE_SE, 1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ????????????? + if (mouse.autoState & MOUSE_LEFT_CRICK){ + // ??????? + if (HitFontNo == systemWndFontNo[0]){ + // ??? + t_music_se_volume++; + // ???????? + if (t_music_se_volume > 15){ + t_music_se_volume = 15; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + play_se(217, 320, 240); + } + } + // ??????? + if (HitFontNo == systemWndFontNo[1]){ + t_music_se_volume--; + if (t_music_se_volume <= 0){ + t_music_se_volume = 1; + play_se(220, 320, 240); + } + else{ + play_se(217, 320, 240); + } + } + // ???????????v??? + if (HitFontNo == systemWndFontNo[2]){ + // ????????? + stereo_flg = !stereo_flg; + // ????? + play_se(217, 320, 240); + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitFontNo == systemWndFontNo[3]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????@e?????? + systemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // ???????? + saveUserSetting(); + break; + } + } + // ?@e + x = pActMenuWnd->x + 56; + y = pActMenuWnd->y + 64; + sprintf_s(moji, " Ŀǰ%3d ", t_music_se_volume); + StockFontBuffer(x - 8, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 40; + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 40; + systemWndFontNo[2] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, monoStereoStr[stereo_flg], 2); y += 52; + systemWndFontNo[3] = StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " һҳ ", 2); y += 40; + + break; + + case 4: // ????@e ?????? + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + x = (lpDraw->xSize - 4 * 64) / 2; + y = (lpDraw->ySize - 8 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 4, 8, CG_WND_TITLE_BGM, 1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ????????????? + if (mouse.autoState & MOUSE_LEFT_CRICK){ + // ??????? + if (HitFontNo == systemWndFontNo[0]){ + // ??? + t_music_bgm_volume++; + // ???????? + if (t_music_bgm_volume > 15){ + t_music_bgm_volume = 15; + // ??? + play_se(220, 320, 240); + } + else{ + play_se(217, 320, 240); // ????? + bgm_volume_change(); // ??? + } + } + // ??????? + if (HitFontNo == systemWndFontNo[1]){ + // ??? + t_music_bgm_volume--; + // ???????? + if (t_music_bgm_volume <= 0){ + t_music_bgm_volume = 1; + // ??? + play_se(220, 320, 240); + } + else{ + play_se(217, 320, 240); // ????? + bgm_volume_change(); // ??? + } + } + // ????L???? + if (HitFontNo == systemWndFontNo[3]){ + // ?????? + t_music_bgm_pitch[t_music_bgm_no]++; + set_gbm_pitch(); + // ???????? + if (t_music_bgm_pitch[t_music_bgm_no] > 8){ + t_music_bgm_pitch[t_music_bgm_no] = 8; + // ??? + play_se(220, 320, 240); + } + else{ + play_se(217, 320, 240); // ????? + set_gbm_pitch(); // ???? + } + } + // ????w??? + if (HitFontNo == systemWndFontNo[4]){ + // ?????? + t_music_bgm_pitch[t_music_bgm_no]--; + // ???????? + if (t_music_bgm_pitch[t_music_bgm_no] < -8){ + t_music_bgm_pitch[t_music_bgm_no] = -8; + // ??? + play_se(220, 320, 240); + } + else{ + play_se(217, 320, 240); // ????? + set_gbm_pitch(); // ???? + } + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitFontNo == systemWndFontNo[2]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????@e?????? + systemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // ???????? + saveUserSetting(); + break; + } + } + // ?@e + x = pActMenuWnd->x + 56; + y = pActMenuWnd->y + 64; + sprintf_s(moji, " Ŀǰ %3d ", t_music_bgm_volume); + StockFontBuffer(x - 8, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 40; + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 48; + if (t_music_bgm_pitch[t_music_bgm_no] == 0){ + sprintf_s(moji, " ĿǰĽ 0 "); + } + else + sprintf_s(moji, " ĿǰĽ %+3d ", t_music_bgm_pitch[t_music_bgm_no]); + StockFontBuffer(x - 8, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 40; + systemWndFontNo[3] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 40; + systemWndFontNo[4] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ", 2); y += 52; + systemWndFontNo[2] = StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " һҳ ", 2); y += 40; + + break; + + case 5: // ?K??? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + x = (lpDraw->xSize - 272) / 2; + y = (lpDraw->ySize - 430) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 272, 430, CG_WND_TITLE_CHAT, -1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + // V??????? + GetKeyInputFocus(&chatRegistryStr[0]); + + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ?K?????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_CHAT_REGISTY_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == systemWndFontNo[3]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ????@e?????? + systemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // ???????? + saveUserSetting(); + // ?????K???V + SaveChatRegistyStr(); + break; + } + } + // ?@e + x = pActMenuWnd->x + 18; + y = pActMenuWnd->y + 58; + + // K????? + for (i = 0; i < 8; i++){ + // ???? + chatRegistryStr[i].x = x + 2; + chatRegistryStr[i].y = y; + StockFontBuffer2(&chatRegistryStr[i]); y += 43; + // ??V????? + if (MakeHitBox(chatRegistryStr[i].x - 4, chatRegistryStr[i].y - 3, + chatRegistryStr[i].x + 234 + 3, chatRegistryStr[i].y + 16 + 3, DISP_PRIO_IME3) == TRUE){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // V??????? + GetKeyInputFocus(&chatRegistryStr[i]); + play_se(217, 320, 240); // ????? + } + } + } + // ????? + systemWndFontNo[3] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, y + 5, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + + break; + + case 6: // ???@e?? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + x = (lpDraw->xSize - 3 * 64) / 2; + y = (lpDraw->ySize - 4 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 3, 4, CG_WND_TITLE_MOUSE, 1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ?????????? + if (HitFontNo == systemWndFontNo[0]){ + // ??? + if (MouseCursorFlag == TRUE){ + // ?????? + strcpy(OneLineInfoStr, "ɫĻα꣬ӦϿ졣"); + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ?????????? +#ifdef _TALK_WINDOW + g_iCursorCount = ShowCursor( FALSE ); +#else + ShowCursor(FALSE); +#endif + MouseCursorFlag = FALSE; + play_se(217, 320, 240); // ????? + } + } + else{ + // ?????? + strcpy(OneLineInfoStr, "ͨĻαꡣ"); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ?????????? +#ifdef _TALK_WINDOW + g_iCursorCount = ShowCursor( TRUE ); +#else + //ShowCursor( TRUE ); +#endif + MouseCursorFlag = FALSE; + play_se(217, 320, 240); // ????? + } + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitFontNo == systemWndFontNo[1]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???@e??????? + systemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // ???????? + saveUserSetting(); + break; + } + } + + // ?@e + x = pActMenuWnd->x + 38; + y = pActMenuWnd->y + 56; + + // ????????? + StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, " α趨 ", 0); y += 40; + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, mouseCursor[MouseCursorFlag], 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_AQUA, " һҳ ", 2); y += 40; + break; + + case 7: // ????? ?????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + x = (lpDraw->xSize - 3 * 64) / 2; + y = (lpDraw->ySize - 3 * 48) / 2; + pActMenuWnd = MakeWindowDisp(x, y, 3, 3, CG_WND_TITLE_LOGOUT, 1, FALSE); + for (i = 0; i < MENU_SYSTEM_0; i++) systemWndFontNo[i] = -2; + break; + } + else{ + if (pActMenuWnd->hp <= 0) break; + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???? + if (HitFontNo == systemWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + GameState = GAME_LOGIN; + ChangeProc2(PROC_CHAR_LOGOUT); + + play_se(206, 320, 240); + break; + } + // ????? + if (HitFontNo == systemWndFontNo[1]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ?????? + systemWndNo = 0; + play_se(203, 320, 240); + break; + } + } + + // ?@e + x = pActMenuWnd->x + 38; + y = pActMenuWnd->y + 56; + +#ifdef _NEWFONT_ + + systemWndFontNo[0] = StockFontBuffer(x+20, y, FONT_PRIO_FRONT, 0, " ȷ ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x+20, y, FONT_PRIO_FRONT, 0, " Ҫ ", 2); y += 40; +#else + + systemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ȷ ", 2); y += 40; + systemWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " Ҫ ", 2); y += 40; +#endif + break; + } + } + + //? ???????????? *****************************************************/ +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + if(setRoomFlag == TRUE) + { + setRoomName(); + } + + if(assentFlag == TRUE) + { + AssentWnd(); + } +#endif + + + if (MenuToggleFlag & JOY_CTRL_S){ + + // ?????k??? + switch (statusWndNo){ + + case 0: // ?????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + + pActMenuWnd = MakeWindowDisp(4, 4, 272, 360, 0, -1); +#ifdef _CHARTITLE_STR_ + extern void óƺȡ(); + extern BOOL ȡƺȡ(); + if(ȡƺȡ()) óƺȡ(); +#endif + // ???Re??? + for (i = 0; i < MENU_STATUS_0; i++) statusWndFontNo[i] = -2; + for (i = 0; i < MENU_STATUS_0; i++) statusWndBtnFlag[i] = 0; +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + SkillWndflag = false ; +#endif + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ??????????????? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + if ( SkillWndflag == true ) { + SkillWndfunc2(); + } + else { + if ( pActSkillMenuWnd != NULL ) { + DeathAction( pActSkillMenuWnd ) ; + pActSkillMenuWnd = NULL ; + } + } + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx-1, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my+34, DISP_PRIO_MENU, CG_NEW_STATUS_WND, 1 ); +#else +#ifdef _NEW_CHARDATA_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20, DISP_PRIO_MENU, 55266, 1); +#else + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_STATUS_WND, 1); +#endif +#endif + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // + if (HitDispNo == statusWndFontNo[0]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 1; + play_se(202, 320, 240); + } + // ر + if (HitDispNo == statusWndFontNo[1]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + MenuToggleFlag ^= JOY_CTRL_S; + play_se(203, 320, 240); + } +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + if( HitDispNo == statusWndFontNo[ 12 ] ){ + DeathAction( pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 3; + play_se( 202, 320, 240); +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ + lssproto_RESIST_send ( sockfd , "" ) ; +#endif +#ifdef _ALCHEPLUS + lssproto_ALCHEPLUS_send ( sockfd , "" ) ; +#endif + } + if( HitDispNo == statusWndFontNo[ 14 ] ){ + play_se( 202, 320 , 240 ) ; + SkillWndflag = true ; + MenuToggleFlag &= ~JOY_CTRL_I; + MenuToggleFlag &= ~JOY_CTRL_M; + if( pActMenuWnd3 != NULL ) { + DeathAction ( pActMenuWnd3 ) ; + pActMenuWnd3 = NULL ; + GetKeyInputFocus( &MyChatBuffer ); + } + } +#endif + + } + // ıƺ + if (HitDispNo == statusWndFontNo[6]){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ +#ifdef _CHARTITLE_ + statusWndBtnFlag[6] = TRUE; + extern void 򿪳ƺŴڳʼ(); + 򿪳ƺŴڳʼ(); + if (pActMenuWnd3 == NULL){ + pActMenuWnd3 = MakeWindowDisp(363, 105, 0, 0, 55249, -1, 0); + play_se(202, 320, 240); + } + else{ + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + play_se(203, 320, 240); + } +#else +#ifdef _CHARTITLE_STR_ + statusWndBtnFlag[6] = TRUE; + extern void 򿪳ƺŴڳʼ(); + 򿪳ƺŴڳʼ(); + if (pActMenuWnd3 == NULL){ + pActMenuWnd3 = MakeWindowDisp(363, 105, 0, 0, 55249, -1, 0); + play_se(202, 320, 240); + } + else{ + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + play_se(203, 320, 240); + } +#else +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + SkillWndflag = false ; + MenuToggleFlag &= ~JOY_CTRL_I; + //MenuToggleFlag &= ~JOY_CTRL_M; +#endif +#ifdef _TAIKEN + // ??? + play_se( 220, 320, 240 ); + // ??????? + sprintf_s( moji,"治ѡ" ); + // ?????????????????? + StockChatBufferLine( moji, FONT_PAL_WHITE ); +#else + if (pActMenuWnd3 == NULL){ + // ????????? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + pActMenuWnd3 = MakeWindowDisp( 304, 16 + 280 + 48, 272, 88, 0, -1 ); +#else +#ifdef _NEW_CHARDATA_ + pActMenuWnd3 = MakeWindowDisp(4, 16 + 280 + 78 + 35, 272, 88, 0, -1, 0); +#else + pActMenuWnd3 = MakeWindowDisp( 4, 16 + 280 + 78, 272, 88, 0, -1 ,0); +#endif +#endif + // ???????? + play_se(202, 320, 240); + // q???? + shougouChange.buffer[0] = NULL; + shougouChange.cnt = 0; + shougouChange.cursor = 0; + // ???? + shougouChange.len = 12; + // ??? + shougouChange.color = 0; + // ???? + shougouChange.x = pActMenuWnd3->x + 38; + shougouChange.y = pActMenuWnd3->y + 25; + // ????I?? + shougouChange.fontPrio = FONT_PRIO_FRONT; + // ???? + statusWndBtnFlag[6] = TRUE; + } + else{ + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + statusWndBtnFlag[6] = TRUE; +#endif +#endif +#endif + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && statusWndBtnFlag[6] == TRUE){ + // ???? + statusWndBtnFlag[6] = TRUE; + } + else{ + // ??? + statusWndBtnFlag[6] = FALSE; + } + } + else{ + // ??? + statusWndBtnFlag[6] = FALSE; + } + // ?????????? + if (StatusUpPoint != 0){ + // ???????? + for (i = 2; i < 6; i++){ + // ????? + if (HitDispNo == statusWndFontNo[i]){ + // ???? + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??????? + if (bNewServer) + lssproto_SKUP_send(sockfd, i - 2); + else + old_lssproto_SKUP_send(sockfd, i - 2); + + +#ifndef _CHAR_PROFESSION // WON ADD ְҵ + StatusUpPoint--; +#endif + + play_se(211, 320, 240); + + statusWndBtnFlag[i] = TRUE; + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && statusWndBtnFlag[i] == TRUE){ + // ???? + statusWndBtnFlag[i] = TRUE; + } + else{ + // ??? + statusWndBtnFlag[i] = FALSE; + } + } + else{ + // ??? + statusWndBtnFlag[i] = FALSE; + } + } + } + // ???????? + if (pActMenuWnd != NULL){ +#define PET_WND_ATTR_X 159 +#define PET_WND_ATTR_Y 5 + int x2; + x = pActMenuWnd->x + 20; + y = pActMenuWnd->y + 28; + CenteringStr(pc.name, moji, CHAR_NAME_LEN); + StockFontBuffer(x - 6, y - 2, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%8d", pc.dp); + StockFontBuffer(x + 170, y - 2, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + // ?????????? +#ifndef _CHARTITLE_ +#ifndef _CHARTITLE_STR_ + CenteringStr(pc.freeName, moji, 32); // ?eu??? +#endif +#endif +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + //λƳƺ + StockFontBuffer( x + 77, y + 2 , FONT_PRIO_FRONT, 0, moji, 0 ); +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + //Ӣսƺ + if ( pc.herofloor == 132 ) sprintf_s( moji , "%s" , "˹½Ӣ" ) ; + else if ( pc.herofloor >= 130 ) sprintf_s( moji , "%s" , "˹½սʿ" ) ; + else if ( pc.herofloor >= 125 ) sprintf_s( moji , "%s" , "˹½ʿ" ) ; + else if ( pc.herofloor >= 120 ) sprintf_s( moji , "%s" , "˹Ӣ" ) ; + else if ( pc.herofloor >= 115 ) sprintf_s( moji , "%s" , "˹ʹսʿ" ) ; + else if ( pc.herofloor >= 110 ) sprintf_s( moji , "%s" , "ķսʿ" ) ; + else if ( pc.herofloor >= 100 ) sprintf_s( moji , "%s" , "˿սʿ" ) ; + else if ( pc.herofloor >= 80 ) sprintf_s( moji , "%s" , "̹սʿ" ) ; + else if ( pc.herofloor >= 60 ) sprintf_s( moji , "%s" , "ضսʿ" ) ; + else if ( pc.herofloor >= 40 ) sprintf_s( moji , "%s" , "ħʿ" ) ; + else if ( pc.herofloor >= 20 ) sprintf_s( moji , "%s" , "ʥʿ" ) ; + else if ( pc.herofloor >= 1 ) sprintf_s( moji , "%s" , "ʿ" ) ; + else sprintf_s( moji , " " ); + StockFontBuffer( x + 72, y + 28 , FONT_PRIO_FRONT, 5, moji, 0 ); + sprintf_s( moji , "%d" , pc.profession_level); + StockFontBuffer( x + 157, y + 53 , FONT_PRIO_FRONT, 0, moji, 0 ); +#endif +#else +#ifndef _CHARTITLE_ +#ifndef _CHARTITLE_STR_ +#ifdef _NEWFONT_ + StockFontBuffer( x-20, y, FONT_PRIO_FRONT, 0, moji, 0 ); +#else + StockFontBuffer(x - 60, y, FONT_PRIO_FRONT, 0, moji, 0); +#endif +#endif +#endif +#endif +#ifdef _TRANS_6 + if( pc.transmigration >= 1 && pc.transmigration <= 6 ){ +#else + if (pc.transmigration >= 1 && pc.transmigration <= 5){ +#endif +#ifndef _NEW_CHARDATA_ + sprintf_s(moji, "ת%s", TransmigrationStr[pc.transmigration]); + StockFontBuffer(x + 178 + 12, y + 2, FONT_PRIO_FRONT, FONT_PAL_AQUA, moji, 0); +#else + ; +#endif + } +#ifdef _CHARTITLE_ + y += 32; + +#else +#ifdef _CHARTITLE_STR_ + y += 19; +#else + y += 21; +#endif +#endif + sprintf_s(moji, "%3d", pc.level); +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + y += 35; + StockFontBuffer( x + 38, y - 2, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%8d", pc.exp ); + StockFontBuffer( x + 48, y + 2 , FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%8d",pc.maxExp ); + StockFontBuffer( x + 48, y + 4, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%4d", pc.hp ); + StockFontBuffer( x + 48, y + 8, FONT_PRIO_FRONT, 0, moji, 0 ); + sprintf_s( moji, "%4d", pc.maxHp ); + StockFontBuffer( x + 98, y + 8, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%3d", pc.mp ); + StockFontBuffer( x + 50, y + 12 , FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%3d", pc.atk ); + StockFontBuffer( x + 50, y + 16, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%3d", pc.def ); + StockFontBuffer( x + 50, y + 20, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%3d", pc.quick ); + StockFontBuffer( x + 50, y + 24, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + sprintf_s( moji, "%3d", pc.charm ); + StockFontBuffer( x + 50, y + 28, FONT_PRIO_FRONT, 0, moji, 0 ); y += 21; + y += 29; + sprintf_s( moji, "%3d", pc.vital ); + StockFontBuffer( x + 55, y + 34 , FONT_PRIO_FRONT, 0, moji, 0 ); + sprintf_s( moji, "%3d", pc.str ); + StockFontBuffer( x + 55 + 120, y + 34 , FONT_PRIO_FRONT, 0, moji, 0 ); y += 20; + sprintf_s( moji, "%3d", pc.tgh ); + StockFontBuffer( x + 55, y + 34 , FONT_PRIO_FRONT, 0, moji, 0 ); + sprintf_s( moji, "%3d", pc.dex ); + StockFontBuffer( x + 55 + 120, y + 34 , FONT_PRIO_FRONT, 0, moji, 0 ); y += 20; +#else +#ifdef _NEW_CHARDATA_ + + /* + static int ͷ״̬=0,ͷ״̬=0; + + StockDispBuffer( pActMenuWnd->x + 187, pActMenuWnd->y + 118+72, DISP_PRIO_IME3,CG_PREV_BTN+ͷ״̬, 1 ); + if( MakeHitBox( pActMenuWnd->x + 187-18, pActMenuWnd->y + 118+72-10, pActMenuWnd->x + 187+18,pActMenuWnd->y + 118+72+10, DISP_PRIO_IME4 ) == TRUE ){ + ShowBottomLineString(FONT_PAL_WHITE, "޸ͷ"); + if(mouse.state & MOUSE_LEFT_CRICK){ + ͷ״̬ = 1; + if(mouse.onceState & MOUSE_LEFT_CRICK){ + play_se(203, 320, 240); + //ͷ + } + }else ͷ״̬=0; + }else ͷ״̬=0; + StockDispBuffer( pActMenuWnd->x + 232, pActMenuWnd->y + 118+72, DISP_PRIO_IME3,CG_NEXT_BTN+ͷ״̬, 1 ); + if( MakeHitBox( pActMenuWnd->x + 232-18, pActMenuWnd->y + 118+72-10, pActMenuWnd->x + 232+18,pActMenuWnd->y + 118+72+10, DISP_PRIO_IME4 ) == TRUE ){ + ShowBottomLineString(FONT_PAL_WHITE, "޸ͷ"); + if(mouse.state & MOUSE_LEFT_CRICK){ + ͷ״̬ = 1; + if(mouse.onceState & MOUSE_LEFT_CRICK){ + play_se(203, 320, 240); + //ͷ + } + }else ͷ״̬=0; + }else ͷ״̬=0; + + */ + + + StockFontBuffer(x + 50, y + 44, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", TransmigrationStr[pc.transmigration]); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, Transmigrationcolor[pc.transmigration], moji, 0); + sprintf_s(moji, "%s", pc.chusheng); + StockFontBuffer(x + 50, y + 21, FONT_PRIO_FRONT, 0, moji, 0); + y += 21 + 44; + sprintf_s(moji, "%8d", pc.exp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%8d", pc.maxExp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%4d", pc.hp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%4d", pc.maxHp); + StockFontBuffer(x + 98, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.mp); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.charm); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + y += 29; + sprintf_s(moji, "%3d", pc.vital); + StockFontBuffer(x + 61, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pc.str); + StockFontBuffer(x + 61 + 120, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; + sprintf_s(moji, "%3d", pc.tgh); + StockFontBuffer(x + 61, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pc.dex); + StockFontBuffer(x + 61 + 120, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; +#else + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%8d", pc.exp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%8d", pc.maxExp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%4d", pc.hp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%4d", pc.maxHp); + StockFontBuffer(x + 98, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.mp); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + sprintf_s(moji, "%3d", pc.charm); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 21; + y += 29; + sprintf_s(moji, "%3d", pc.vital); + StockFontBuffer(x + 61, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pc.str); + StockFontBuffer(x + 61 + 120, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; + sprintf_s(moji, "%3d", pc.tgh); + StockFontBuffer(x + 61, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pc.dex); + StockFontBuffer(x + 61 + 120, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; +#endif +#endif + +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + y += 50; +#else + y += 17; +#endif + statusWndFontNo[0] = StockDispBuffer(x + 59, y, DISP_PRIO_IME3, CG_STATUS_WND_GROUP_BTN, 2); + statusWndFontNo[1] = StockDispBuffer(x + 173, y, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + // ??????? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + statusWndFontNo[ 12 ] = StockDispBuffer( x + 164 , y - 102, DISP_PRIO_IME3, CG_STATUS_DETAIL, 2 ); + if ( pc.profession_class != 0 ) + statusWndFontNo[ 14 ] = StockDispBuffer( x + 213 , y - 318 , DISP_PRIO_IME3, CG_WAR_ICON_BIG + pc.profession_class - 1, 2 ); + //else //ʱſͼ + // statusWndFontNo[ 14 ] = StockDispBuffer( x + 213 , y - 318 , DISP_PRIO_IME3, CG_WAR_ICON_BIG + pc.profession_class - 1, 2 ); + + + StockDispBuffer( pActMenuWnd->x + 216, pActMenuWnd->y + 168, DISP_PRIO_IME3, pc.faceGraNo, 0 ); +#else +#ifdef _CHARTITLE_ + StockDispBuffer(pActMenuWnd->x + 209, pActMenuWnd->y + 118 + 11, DISP_PRIO_IME3, pc.faceGraNo, 0); +#else +#ifdef _CHARTITLE_STR_ + StockDispBuffer(pActMenuWnd->x + 209+1, pActMenuWnd->y + 118 + 13, DISP_PRIO_IME3, pc.faceGraNo, 0); +#else +#ifdef _NEW_CHARDATA_ + StockDispBuffer(pActMenuWnd->x + 210, pActMenuWnd->y + 118 + 13, DISP_PRIO_IME3, pc.faceGraNo, 0); +#else + StockDispBuffer( pActMenuWnd->x + 209, pActMenuWnd->y + 118, DISP_PRIO_IME3, pc.faceGraNo, 0 ); +#endif +#endif +#endif +#endif + if (StatusUpPoint != 0){ + // ?????????? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 14 , ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 67 , DISP_PRIO_IME3, CG_STATUS_WND_LV_UP_POINT, 0 ); + sprintf_s( moji, "%2d", StatusUpPoint ); + StockFontBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 70, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 156, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0 ); + statusWndFontNo[ 2 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx , ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 66 , DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 2 ], 2 ); + statusWndFontNo[ 3 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 120, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 66 , DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 3 ], 2 ); + statusWndFontNo[ 4 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx , ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 86, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 4 ], 2 ); + statusWndFontNo[ 5 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 120, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 86, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 5 ], 2 ); +#else +#ifdef _CHARTITLE_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11, DISP_PRIO_IME3, CG_STATUS_WND_LV_UP_POINT, 0); + sprintf_s(moji, "%2d", StatusUpPoint); + StockFontBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 50, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 88 + 11, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + + // ?????? + statusWndFontNo[2] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[2], 2); + statusWndFontNo[3] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[3], 2); + statusWndFontNo[4] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 11, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[4], 2); + statusWndFontNo[5] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 11, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[5], 2); +#else +#ifdef _CHARTITLE_STR_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11+31, DISP_PRIO_IME3, CG_STATUS_WND_LV_UP_POINT, 0); + sprintf_s(moji, "%2d", StatusUpPoint); + StockFontBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 50, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 88 + 11+31, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + + // ?????? + statusWndFontNo[2] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11+31, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[2], 2); + statusWndFontNo[3] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 11+31, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[3], 2); + statusWndFontNo[4] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 11+31, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[4], 2); + statusWndFontNo[5] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 11+31, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[5], 2); +#else +#ifdef _NEW_CHARDATA_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 42, DISP_PRIO_IME3, CG_STATUS_WND_LV_UP_POINT, 0); + sprintf_s(moji, "%2d", StatusUpPoint); + StockFontBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 50, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 88 + 42, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + statusWndFontNo[2] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 42, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[2], 2); + statusWndFontNo[3] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 42, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[3], 2); + statusWndFontNo[4] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 42, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[4], 2); + statusWndFontNo[5] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 120, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 20 + 42, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[5], 2); +#else + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my, DISP_PRIO_IME3, CG_STATUS_WND_LV_UP_POINT, 0 ); + sprintf_s( moji, "%2d", StatusUpPoint ); + StockFontBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 50, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 88, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0 ); + // ?????? + statusWndFontNo[ 2 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 2 ], 2 ); + statusWndFontNo[ 3 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 120, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 3 ], 2 ); + statusWndFontNo[ 4 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 20, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 4 ], 2 ); + statusWndFontNo[ 5 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx + 120, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my + 20, DISP_PRIO_IME3, CG_STATUS_WND_UP_BTN_UP + statusWndBtnFlag[ 5 ], 2 ); +#endif +#endif +#endif +#endif + } + // ?? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + //λƸıƺť + statusWndFontNo[ 6 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx - 124 , ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my, DISP_PRIO_IME3, CG_STATUS_WND_SHOUGOU_BTN_UP + statusWndBtnFlag[ 6 ], 2 ); +#else +#ifdef _CHARTITLE_ + extern void ƺչʾ(); + ƺչʾ(); + statusWndFontNo[6] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx - 125, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my + 3, DISP_PRIO_IME3, CG_STATUS_WND_SHOUGOU_BTN_UP + statusWndBtnFlag[6], 2); +#else +#ifdef _CHARTITLE_STR_ + extern void ƺչʾ(); + extern BOOL ȡǰƺǷ(); + extern BOOL ȡƺȡ(); + extern void óƺȡ(); + if(ȡƺȡ()){ + StockDispBuffer(138,450,DISP_PRIO_MENU,55259,1);//ȷڵͼ + int bnt; + StockFontBuffer(70,425,1,0,"Ƿȡƺʾ",0); + bnt = StockFontBuffer(90,462,1,FONT_PAL_YELLOW,"ȷ",2); + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(HitFontNo == bnt){ + óƺȡ(); + if(ȡǰƺǷ()){ + int checksum=0; + char buf[1024*4]; + memset(buf,0,1024*4); + checksum += util_mkint(buf, -1); + util_mkint(buf, checksum); + util_SendMesg(sockfd, LSSPROTO_CHARTITLE_SEND, buf); + } + play_se(203, 320, 240); + } + } + bnt = StockFontBuffer(155,462,1,FONT_PAL_YELLOW,"ȡ",2); + if(mouse.onceState & MOUSE_LEFT_CRICK>0){ + if(HitFontNo == bnt){ + óƺȡ(); + play_se(203, 320, 240); + } + } + } + ƺչʾ(); + statusWndFontNo[6] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_IME3, CG_STATUS_WND_SHOUGOU_BTN_UP + statusWndBtnFlag[6], 2); +#else + statusWndFontNo[6] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_IME3, CG_STATUS_WND_SHOUGOU_BTN_UP + statusWndBtnFlag[6], 2); +#endif +#endif +#endif + + // ?@e + x = pActMenuWnd->x + 19; + y = pActMenuWnd->y + 174; +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + x -= 4; + y += 43; +#endif +#ifdef _CHARTITLE_ + y += 11; +#endif +#ifdef _NEW_CHARDATA_ + y += 42; +#endif + if (pc.earth > 0){ + x2 = (int)(pc.earth * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_GREEN, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + } + y += 20; + + // ?N??? + if (pc.water > 0){ + x2 = (int)(pc.water * 0.8); + + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_AQUA, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + } + y += 20; + + // ?N??? + if (pc.fire > 0){ + x2 = (int)(pc.fire * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_RED, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + } + y += 20; + + // ?N??? + if (pc.wind > 0){ + x2 = (int)(pc.wind * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_YELLOW, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + } + + } + } + } + // ??????????? + if (pActMenuWnd3 != NULL){ + // ?????????????? + if (pActMenuWnd3->hp > 0){ + // ????????? +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd3->pYobi )->mx, ( ( WINDOW_DISP *)pActMenuWnd3->pYobi )->my, DISP_PRIO_MENU, CG_NAME_CHANGE_WND, 1 ); +#else +#ifdef _CHARTITLE_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd3->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd3->pYobi)->my + 27, DISP_PRIO_MENU, 55249, 1); +#else +#ifdef _CHARTITLE_STR_ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd3->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd3->pYobi)->my + 27, DISP_PRIO_MENU, 55249, 1); +#else + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd3->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd3->pYobi)->my, DISP_PRIO_MENU, CG_NAME_CHANGE_WND, 1); +#endif +#endif +#endif +#ifdef _CHARTITLE_ + extern BOOL ƺŴ(ACTION * pct); + if (ƺŴ(pActMenuWnd3)){ + pActMenuWnd3 = NULL; + + } +#else +#ifdef _CHARTITLE_STR_ + extern BOOL ƺŴ(ACTION * pct); + if (ƺŴ(pActMenuWnd3)){ + pActMenuWnd3 = NULL; + + } +#else + GetKeyInputFocus(&shougouChange); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??ϣ??? + if (HitDispNo == statusWndFontNo[7]){ + // ???????? + KeyboardReturn(); + } + // ?????????? + if (HitDispNo == statusWndFontNo[8]){ + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + } + // ?????????????? + if (pActMenuWnd3 != NULL){ + // ??? + StockFontBuffer2(&shougouChange); + + // ?@e + x = pActMenuWnd3->x + 20; + y = pActMenuWnd3->y + 60; + statusWndFontNo[7] = StockDispBuffer(x + 60, y + 7, DISP_PRIO_IME3, CG_OK_BTN, 2); + statusWndFontNo[8] = StockDispBuffer(x + 170, y + 7, DISP_PRIO_IME3, CG_CANCEL_BTN, 2); + } +#endif +#endif + } + } + break; + + case 1: // ?????????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(4, 0, 256, 456, 0, -1); + // ???Re??? + for (i = 0; i < MENU_STATUS_0; i++) statusWndFontNo[i] = -2; + for (i = 0; i < MENU_STATUS_0; i++) statusWndBtnFlag[i] = 0; + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ???????????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_STATUS_WND_GROUP_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == statusWndFontNo[11]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 0; + // ???????? + play_se(203, 320, 240); + } +#ifdef _TEAM_KICKPARTY + for (i = 0; i < 5; i++){ + if (HitDispNo == statusWndFontNo[i + 12]){ + lssproto_KTEAM_send(sockfd, i); + play_se(203, 320, 240); + } + } +#endif + } + // ???????? + if (pActMenuWnd != NULL){ + int selectFlag; // k?????????? + // ?@e + x = pActMenuWnd->x + 17; + y = pActMenuWnd->y + 25; + + if (itemNo != -1 || jujutuNo != -1) selectFlag = 2; + else selectFlag = FALSE; + + CenteringStr(pc.name, moji, CHAR_NAME_LEN); + statusWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, selectFlag); y += 19; + sprintf_s(moji, "%4d", pc.mp); +#ifdef _NEWFONT_ + StockFontBuffer(x + 79, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%d", pc.hp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%d",pc.maxHp); + StockFontBuffer(x + 190, y, FONT_PRIO_FRONT, 0, moji, 0); + y += 20; +#else + StockFontBuffer(x + 77, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%4d %4d", pc.hp, pc.maxHp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; +#endif + + for (i = 0; i < 5; i++){ + if (pet[i].useFlag == TRUE){ + if (pet[i].freeName[0] != NULL) CenteringStr(pet[i].freeName, moji, PET_NAME_LEN); + else CenteringStr(pet[i].name, moji, PET_NAME_LEN); +#ifdef _NEWFONT_ + statusWndFontNo[i + 1] = StockFontBuffer(x, y-2, FONT_PRIO_FRONT, 0, moji, selectFlag); y += 20; + sprintf_s(moji, "%d", pet[i].hp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%d", pet[i].maxHp); + StockFontBuffer(x + 190, y, FONT_PRIO_FRONT, 0, moji, 0); + y += 20; +#else + statusWndFontNo[i + 1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, selectFlag); y += 20; + sprintf_s(moji, "%4d %4d", pet[i].hp, pet[i].maxHp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; +#endif + } + } + y = 268; + for (i = 0; i < 5; i++){ + if (pc.id != party[i].id && party[i].useFlag == TRUE){ + CenteringStr(party[i].name, moji, CHAR_NAME_LEN); + statusWndFontNo[i + 6] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, selectFlag); y += 20; +#ifdef _TEAM_KICKPARTY + //andy_add ӳ + statusWndFontNo[i + 12] = StockDispBuffer(x + 187, y - 10, DISP_PRIO_IME3, CG_MAIL_WND_DELETE_BTN, 2); +#endif + sprintf_s(moji, "%4d", party[i].mp); + StockFontBuffer(x + 77, y, FONT_PRIO_FRONT, 0, moji, 0); +#ifdef _NEWFONT_ + sprintf_s(moji, "%d", party[i].hp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%d", party[i].maxHp); + StockFontBuffer(x + 190, y, FONT_PRIO_FRONT, 0, moji, 0); + y += 20; +#else + sprintf_s(moji, "%4d %4d", party[i].hp, party[i].maxHp); + StockFontBuffer(x + 142, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; +#endif + } + } + statusWndFontNo[11] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, 441, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; +#ifdef _NEWPANEL + case 3: + if( pActMenuWnd == NULL ){ + pActMenuWnd = MakeWindowDisp( 4, 0, 256, 456, 0, -1 ); + for( i = 0 ; i < MENU_STATUS_0 ; i++ ) statusWndFontNo[ i ] = -2; + for( i = 0 ; i < MENU_STATUS_0 ; i++ ) statusWndBtnFlag[ i ] = 0; + }else{ + if( pActMenuWnd->hp > 0 ){ + x = pActMenuWnd->x ; + y = pActMenuWnd->y ; +#ifdef _MAG_MENU + if( charDetailPage == 1 ) { + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_MENU, 26528, 1 ); + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_IME3 + 1, 26555, 1 ); + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-135, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-60, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 2; + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-60, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my+40, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 3; + } + if( charDetailPage == 2 ) { + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_MENU, 26528, 1 ); + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_IME3 + 1, 26556, 1 ); + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-215, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-136, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 1; + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-60, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my+40, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 3; + } + + if( charDetailPage == 1 || charDetailPage == 2 ) { + int index; + for ( i = 0 ; i < 4 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + index = j+i*4 + (charDetailPage-1)*(4*4); + if( index >= 25 ) break; + if( iCharAlchePlus[index] <= 0 ) continue; + if( HitDispNo == StockDispBuffer( x + 45 + j * 60 , y + 96 + i * 57 , DISP_PRIO_IME3 + 1, iAlchePlusIcon[index], 2 ) ) { + sprintf_s( moji , "%s IJϼ", sAlchePlus_list[index]); + StockFontBuffer( 25, 311, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + sprintf_s( moji , "%d %%", iCharAlchePlus[index] / 1000 ); + StockFontBuffer( 220, 311, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + + sprintf_s( moji , " %s ϵļȣ", sAlchePlus_list[index] ); + StockFontBuffer( 25, 340, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + sprintf_s( moji , "زĺϳɳɹʡ"); + StockFontBuffer( 25, 360, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + + } + } + } + } + + + if( charDetailPage == 3 ) { + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_MENU, CG_SKILL_TABLE, 1 ); + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+28, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_IME3 + 1, 26486, 1 ); + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-215, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-136, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 1; + if( MakeHitBox( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+140, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-135, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+170, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-60, DISP_PRIO_IME3) == TRUE) + if( mouse.onceState & MOUSE_LEFT_CRICK ) + charDetailPage = 2; + + for ( i = 0 ; i < 2 ; i ++ ) { + for ( int j = 0 ; j < 4 ; j ++ ) { + if ( HitDispNo == StockDispBuffer( x + 45 + j * 60 , y + 102 + i * 57 , DISP_PRIO_IME3 + 1, DetailDescicon[ j + i * 4 ], 2 ) ) { + sprintf_s( moji , "%s%d" , DetailDesc[j + i * 4] , atoi ( CharDetail[j + i * 4] ) ) ; + StockFontBuffer( 25, 310, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + if( i == 0 ){ + sprintf_s( moji , "%sħĿԣɼܵ", DetailDescchar[j] ); + StockFontBuffer( 25, 330, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + sprintf_s( moji , "%sħ˺", DetailDescchar[j] ); + StockFontBuffer( 25, 350, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + } + else if( i == 1 ){ + sprintf_s( moji , "ʹ%sħȣʹ", DetailDescchar[j] ); + StockFontBuffer( 25, 330, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + sprintf_s( moji , "%sħʱ", DetailDescchar[j] ) ; + StockFontBuffer( 25, 350, FONT_PRIO_FRONT, FONT_PAL_WHITE, moji, 0 ); + } + + } + } + } + + } +#else + StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx+8, ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->my-5, DISP_PRIO_MENU, CG_SKILL_TABLE, 1 ); + statusWndFontNo[ 13 ] = StockDispBuffer( x+139, y+423, DISP_PRIO_IME3, CG_TRADE_BACK_BTN, 2 ); +#endif + statusWndFontNo[ 13 ] = StockDispBuffer( x+215, y+437, DISP_PRIO_IME3, CG_TRADE_BACK_BTN, 2 ); +#ifdef _SYUTEST3 + for ( i = 14 ; i < 22 ; i ++ ) + statusWndFontNo[ i ] = StockDispBuffer( x+139 , y+ 200 + ( i - 14 ) * 20 , DISP_PRIO_IME3, CG_TRADE_BACK_BTN, 2 ); +#endif +#ifndef _MAG_MENU + for ( i = 0 ; i < CHAR_MAX_DETAIL ; i ++ ) { + sprintf_s( moji , "%s%d" , DetailDesc[i] , atoi ( CharDetail[i] ) ) ; + StockFontBuffer( 20 , 35 + i * 20 , FONT_PRIO_FRONT, 1, moji, 0 ); + } +#endif + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if( HitDispNo == statusWndFontNo[ 13 ] ){ + DeathAction( pActMenuWnd ); + pActMenuWnd = NULL; + statusWndNo = 0; + play_se( 202, 320, 240); + } +#ifdef _SYUTEST3 + if( HitDispNo == statusWndFontNo[ 14 ] ) + lssproto_CHATROOM_send ( sockfd , "C|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 15 ] ) + lssproto_CHATROOM_send ( sockfd , "D|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 16 ] ) + lssproto_CHATROOM_send ( sockfd , "J|0" ) ; + if( HitDispNo == statusWndFontNo[ 17 ] ) + lssproto_CHATROOM_send ( sockfd , "L|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 18 ] ) + lssproto_CHATROOM_send ( sockfd , "K|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 19 ] ) + lssproto_CHATROOM_send ( sockfd , "M|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 20 ] ) + lssproto_CHATROOM_send ( sockfd , "T|123456798" ) ; + if( HitDispNo == statusWndFontNo[ 21 ] ) + lssproto_CHATROOM_send ( sockfd , "B|123456798" ) ; +#endif + } + } + } + break; +#endif +#ifdef _ITEM_JIGSAW + case 4: + if (JigsawImg[0] != -1){ + StockDispBuffer(190, 220, DISP_PRIO_MENU, 25251, 1); + StockDispBuffer(189, 219, DISP_PRIO_MENU, JigsawImg[0], 0); + if (JigsawImg[1] != -1) + StockDispBuffer(103, 138, DISP_PRIO_IME3 + 1, JigsawImg[1], 1); + if (JigsawImg[2] != -1) + StockDispBuffer(189, 138, DISP_PRIO_IME3 + 1, JigsawImg[2], 1); + if (JigsawImg[3] != -1) + StockDispBuffer(275, 138, DISP_PRIO_IME3 + 1, JigsawImg[3], 1); + if (JigsawImg[4] != -1) + StockDispBuffer(103, 219, DISP_PRIO_IME3 + 1, JigsawImg[4], 1); + if (JigsawImg[5] != -1) + StockDispBuffer(189, 219, DISP_PRIO_IME3 + 1, JigsawImg[5], 1); + if (JigsawImg[6] != -1) + StockDispBuffer(275, 219, DISP_PRIO_IME3 + 1, JigsawImg[6], 1); + if (JigsawImg[7] != -1) + StockDispBuffer(103, 300, DISP_PRIO_IME3 + 1, JigsawImg[7], 1); + if (JigsawImg[8] != -1) + StockDispBuffer(189, 300, DISP_PRIO_IME3 + 1, JigsawImg[8], 1); + if (JigsawImg[9] != -1) + StockDispBuffer(275, 300, DISP_PRIO_IME3 + 1, JigsawImg[9], 1); + DrawJigsawFlag = true; + } + break; +#endif + } + + } + + //? ?????????? ********************************************************/ + + if (MenuToggleFlag & JOY_CTRL_P){ +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1 || sStreetVendorBuyBtn == 2){ + StockChatBufferLine("̯вø״̬", FONT_PAL_RED); + MenuToggleFlag ^= JOY_CTRL_P; + // Ϊ˲ִгӴ趨Ϊ 3, + petWndNo = 3; + } +#endif +#ifdef _THEATER + if (pc.iTheaterMode > 0) + { + if (pc.iTheaterMode & 0x00000002) + StockChatBufferLine("רı", FONT_PAL_RED); + else if (pc.iTheaterMode & 0x00000001) + StockChatBufferLine("רĿ", FONT_PAL_RED); + MenuToggleFlag ^= JOY_CTRL_P; + // Ϊ˲ִгӴ趨Ϊ 3, + petWndNo = 3; + } +#endif +#ifdef _NPC_DANCE + if (pc.iDanceMode) + { + StockChatBufferLine("״̬޷鿴", FONT_PAL_RED); + MenuToggleFlag ^= JOY_CTRL_P; + petWndNo = 3; + } +#endif + // ?????k??? + switch (petWndNo){ + + case 0: // ?????????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(4, 4, 272, 320, 0, -1); + + // ???Re??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + // k???? + BattlePetReceivePetNo = -1; +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ + DropPetWndflag = false; + DropI = -1; +#endif + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ?????????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_PET_WND_VIEW, 1); + + // ?????????? + for (i = 0; i < 5; i++){ + // ???????????? + if (pet[i].useFlag == FALSE){ + // ?????? + if (i == pc.battlePetNo) + pc.battlePetNo = -1; + // ????? + if (i == pc.mailPetNo) + pc.mailPetNo = -1; + // ?????????? + pc.selectPetNo[i] = FALSE; + } + } + // ??????????? + BattlePetStMenCnt = 0; + // ???????? + for (i = 0; i < 5; i++){ + if (pc.selectPetNo[i] == TRUE) BattlePetStMenCnt++; + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???????? + for (i = 0; i < 5; i++){ + // ??????????????????? + if (pet[i].useFlag == TRUE && BattlePetReceivePetNo != i){ + // ???k??? + if (HitDispNo == petWndFontNo[i]){ + // ride Pet +#if 1 + if (i == pc.mailPetNo){ + pc.mailPetNo = -1; + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 0); +#ifndef _RIDEPET_ + checkRidePet(i); +#endif + play_se(217, 320, 240); // ????? + } + else + // when ride Pet + if (i == pc.ridePetNo && pc.graNo != SPR_pet021 + && pc.graNo != 100362){// + char buf[64]; + sprintf_s(buf, "R|P|-1"); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + lssproto_FM_send(sockfd, buf); + play_se(217, 320, 240); // ????? + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 0); + } + else + // ID?? + if (i == pc.battlePetNo && BattlePetReceiveFlag == FALSE){ + // ID????? + if (bNewServer) + lssproto_KS_send(sockfd, -1); + else + old_lssproto_KS_send(sockfd, -1); + // r?????? + BattlePetReceiveFlag = TRUE; + // ????????k??? + BattlePetReceivePetNo = i; + + // ????? + pc.selectPetNo[i] = FALSE; + BattlePetStMenCnt--; // ????????? + // ????????? + if (pc.mailPetNo == -1){ + // ?????? + pc.mailPetNo = i; + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 4); + } + else{ +#ifndef _RIDEPET_ + checkRidePet(i); +#endif + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 0); + } + play_se(217, 320, 240); // ????? + } + else + // ?????? + if (pc.selectPetNo[i] == TRUE){ + // ID??????? + if (pc.battlePetNo == -1 && BattlePetReceiveFlag == FALSE){ + // ????? + if (pet[i].hp > 0){ + // ID? + if (bNewServer) + lssproto_KS_send(sockfd, i); + else + old_lssproto_KS_send(sockfd, i); + // r?????? + BattlePetReceiveFlag = TRUE; + // ????????k??? + BattlePetReceivePetNo = i; + play_se(217, 320, 240); // ????? + } + else{ + play_se(220, 320, 240); // ??? + } + } + else{ + // ????????? + if (pc.mailPetNo == -1){ + pc.mailPetNo = i; + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 4); + } + // ride Pet + else + { +#ifndef _RIDEPET_ + checkRidePet(i); +#endif + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 0); + } + + pc.selectPetNo[i] = FALSE; + BattlePetStMenCnt--; + play_se(217, 320, 240); + } + + } + else + if (pc.selectPetNo[i] == FALSE){ + // ????????? + if (BattlePetStMenCnt < 4){ + // ??????? + pc.selectPetNo[i] = TRUE; + BattlePetStMenCnt++; // ???????? + play_se(217, 320, 240); // ????? + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 1); + } + else{ + // ????????? + if (pc.mailPetNo == -1){ + pc.mailPetNo = i; + play_se(217, 320, 240); // ????? + // shan + if ((bNewServer & 0xf000000) == 0xf000000) + lssproto_PETST_send(sockfd, i, 4); + } + // ride Pet + else + { +#ifndef _RIDEPET_ + checkRidePet(i); +#endif + } + } + } +#endif + + } + // ??????k??? + if (HitFontNo == petWndFontNo[i + 5]){ + petStatusNo = i; // ???k??? + petWndNo = 1; + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???????? + play_se(202, 320, 240); + } + + } + } + // ?? + if (HitDispNo == petWndFontNo[10]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ?????????? + MenuToggleFlag ^= JOY_CTRL_P; + // ???????? + play_se(203, 320, 240); + // ???????? + + saveUserSetting(); + } + // ???? + if (HitDispNo == petWndFontNo[11]){ + petStatusNo = 0; // ???k??? + // ?????????? + for (i = 0; i < 5; i++){ + // ??????????? + if (pet[i].useFlag == TRUE){ + petStatusNo = i; + break; + } + } + petWndNo = 1; + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???????? + play_se(202, 320, 240); + } +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ + if (HitDispNo == petWndFontNo[21]) { + i = DropI; + DropI = -1; + lssproto_DP_send(sockfd, nowGx, nowGy, i); + if (pc.selectPetNo[i] == TRUE) { + pc.selectPetNo[i] = FALSE; + BattlePetStMenCnt--; + } + if (i == pc.battlePetNo) + lssproto_KS_send(sockfd, -1); + if (pc.mailPetNo == i) { + pc.mailPetNo = -1; + } + play_se(217, 320, 240); + DropPetWndflag = false; + } + if (HitDispNo == petWndFontNo[22]) { + DropPetWndflag = false; + DropI = -1; + play_se(217, 320, 240); + } +#endif + } + // ???????? + if (mouse.onceState & MOUSE_RIGHT_CRICK){ + // ???????? + for (i = 0; i < 5; i++){ + // ??????????? + if (pet[i].useFlag == TRUE && eventWarpSendFlag == FALSE){ + // ???k??? + if (HitFontNo == petWndFontNo[i + 5]){ + // ?????????? or ride Pet + if (ItemMixPetNo != i + && pc.ridePetNo != i) + { +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ + DropPetWndflag = true; + DropI = i; +#else + + + // ????t?? + if( bNewServer) + lssproto_DP_send( sockfd, nowGx, nowGy, i ); + else + old_lssproto_DP_send( sockfd, nowGx, nowGy, i ); + // ?????? + if( pc.selectPetNo[ i ] == TRUE ){ + pc.selectPetNo[ i ] = FALSE; // ???? + BattlePetStMenCnt--; // ????????? + } + // ID?? + if( i == pc.battlePetNo ){ + // ID????? + if( bNewServer) + lssproto_KS_send( sockfd, -1 ); + else + old_lssproto_KS_send( sockfd, -1 ); + } + // ????? + if( pc.mailPetNo == i ){ + pc.mailPetNo = -1; + } + play_se( 217, 320, 240 ); // ????? +#endif + } + else + { + // ??? + play_se(220, 320, 240); + } + } + } + } + } +#ifdef _DROPPETWND // (ɿ) Syu ADD ȷ + if (DropPetWndflag == true) { + StockFontBuffer(245, 220, FONT_PRIO_AFRONT, 3, "ȷҪij", 0); y += 40; + StockDispBuffer(320, 240, DISP_PRIO_YES_NO_WND, CG_DROPWND, 0); + petWndFontNo[21] = StockDispBuffer(320, 240, DISP_PRIO_YES_NO_BTN, CG_COMMON_YES_BTN, 2); + petWndFontNo[22] = StockDispBuffer(320, 240, DISP_PRIO_YES_NO_BTN, CG_COMMON_NO_BTN, 2); + } +#endif + // ???????? + if (pActMenuWnd != NULL){ + + int flag = FALSE; + int color; + int btnNo; + int atrFlag = FALSE; + int atrGraNo[4]; + + x = pActMenuWnd->x + 16 + 50, y = pActMenuWnd->y + 31; + // ?????? + for (i = 0; i < 5; i++){ + // ??????????? + if (pet[i].useFlag == TRUE){ + + color = FONT_PAL_WHITE; // ????? + btnNo = 0; // ??????? + // ????V??? + if (pc.selectPetNo[i] == TRUE){ + color = FONT_PAL_AQUA; + btnNo = 2; + } + // ID?? + if (i == pc.battlePetNo){ + color = FONT_PAL_YELLOW; + btnNo = 1; + } + // ????? + if (i == pc.mailPetNo){ + color = FONT_PAL_GREEN; + btnNo = 3; + } + // ride Pet + if (i == pc.ridePetNo){ + color = FONT_PAL_YELLOW; + btnNo = 195; + } + if (pet[i].freeName[0] != NULL){ +#ifdef _NEWFONT_ + sprintf(moji," %-26s",pet[i].freeName); + //CenteringStr(pet[i].freeName, moji, PET_NAME_LEN); +#else + CenteringStr(pet[i].freeName, moji, PET_NAME_LEN); +#endif + + } + else{ +#ifdef _NEWFONT_ + sprintf(moji," %-26s",pet[i].name); + //CenteringStr(pet[i].name, moji, PET_NAME_LEN); +#else + CenteringStr(pet[i].name, moji, PET_NAME_LEN); +#endif + } + petWndFontNo[i + 5] = StockFontBuffer(x + 3, y, FONT_PRIO_FRONT, color, moji, 2); y += 24; +#ifdef _SHOWPETTRN_ + sprintf(moji, "%dת", pet[i].trn); + StockFontBuffer(x + 122, y - 24, FONT_PRIO_FRONT, color, moji, 2); +#endif + atrFlag = FALSE; + // Nͤ + if (pet[i].earth > 0){ // + // ?? + if (pet[i].earth > 50) atrGraNo[atrFlag] = CG_ATR_ICON_EARTH_BIG; + // ?? + else atrGraNo[atrFlag] = CG_ATR_ICON_EARTH_SML; + atrFlag++; // ????? + } + if (pet[i].water > 0){ // ? + // ?? + if (pet[i].water > 50) atrGraNo[atrFlag] = CG_ATR_ICON_WATER_BIG; + // ?? + else atrGraNo[atrFlag] = CG_ATR_ICON_WATER_SML; + atrFlag++; // ????? + } + if (pet[i].fire > 0){ // ? + // ?? + if (pet[i].fire > 50) atrGraNo[atrFlag] = CG_ATR_ICON_FIRE_BIG; + // ?? + else atrGraNo[atrFlag] = CG_ATR_ICON_FIRE_SML; + atrFlag++; // ????? + } + if (pet[i].wind > 0){ // ? + // ?? + if (pet[i].wind > 50) atrGraNo[atrFlag] = CG_ATR_ICON_WIND_BIG; + // ?? + else atrGraNo[atrFlag] = CG_ATR_ICON_WIND_SML; + atrFlag++; // ????? + } + // ??? + if (atrFlag > 0) StockDispBuffer(pActMenuWnd->x + 228, y - 16, DISP_PRIO_IME3, atrGraNo[0], 0); + // K?? + if (atrFlag > 1) StockDispBuffer(pActMenuWnd->x + 228 + 16, y - 16, DISP_PRIO_IME3, atrGraNo[1], 0); + + petWndFontNo[i] = StockDispBuffer(x - 27, y - 14, DISP_PRIO_IME3, CG_PET_WND_REST_BTN + btnNo, 2); + +#ifdef _RIDEPET_ + if (pet[i].rideflg == 1 && pet[i].ai == 100){ + if ((i == pc.ridePetNo) || pc.ridePetNo < 0){ + int rideid = StockDispBuffer(x - 27, y + 11, DISP_PRIO_IME3, 55257, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == rideid){ + checkRidePet(i); + } + } + } + } +#endif +#ifdef _NEWFONT_ + sprintf_s(moji, "%3d", pet[i].level); + StockFontBuffer(x + 15 + 27, y, FONT_PRIO_FRONT, color, moji, 0); + + sprintf_s(moji, "%4d",pet[i].hp); + StockFontBuffer(x + 70 + 32, y, FONT_PRIO_FRONT, color, moji, 0); + sprintf_s(moji, "%4d", pet[i].maxHp); + StockFontBuffer(x + 130 + 27, y, FONT_PRIO_FRONT, color, moji, 0); + y += 27; +#else + sprintf_s(moji, "%3d %4d %4d", pet[i].level, pet[i].hp, pet[i].maxHp); + StockFontBuffer(x + 26 + 27, y, FONT_PRIO_FRONT, color, moji, 0); y += 27; +#endif + flag = TRUE; + } + } + // ???????? + if (flag != TRUE){ + // ?? + petWndFontNo[10] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, pActMenuWnd->y + 299, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + StockFontBuffer(x + 10, y, FONT_PRIO_FRONT, 0, "ûг", 0); y += 40; + } + else{ + // ?? + petWndFontNo[10] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 56, pActMenuWnd->y + 299, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + petWndFontNo[11] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx - 56, pActMenuWnd->y + 299, DISP_PRIO_IME3, CG_PET_WND_STATUS_BTN, 2); + } + } + } + } + break; + + case 1: // ?????????? + if (pActMenuWnd == NULL){ + // ????????? + + pActMenuWnd = MakeWindowDisp(4, 4, 272, 332, 0, -1); +#ifdef _PETBLESS_ + ףڿ = 0; + memset(ף, 0, 128); +#endif + // ???Re??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ????????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_PET_WND_DETAIL, 1); + // ???????????????? + if (pActPet == NULL) + { +#ifdef _LIZARDPOSITION // (ɿ) Syu ADD ʾλù + if ((pet[petStatusNo].graNo == 101493) || (pet[petStatusNo].graNo == 101494) || + (pet[petStatusNo].graNo == 101495) || (pet[petStatusNo].graNo == 101496)) + { + pActPet = MakeAnimDisp(pActMenuWnd->x + 220, pActMenuWnd->y + 124, pet[petStatusNo].graNo, ANIM_DISP_PET); + } + else + pActPet = MakeAnimDisp(pActMenuWnd->x + 200, pActMenuWnd->y + 144, pet[petStatusNo].graNo, ANIM_DISP_PET); +#else + pActPet = MakeAnimDisp( pActMenuWnd->x + 200, pActMenuWnd->y + 144, pet[ petStatusNo ].graNo, ANIM_DISP_PET ); +#endif + } +#ifdef _PET_SKINS + originalPetSkin = pet[petStatusNo].graNo; +#endif + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ????????????? + if (HitDispNo == petWndFontNo[0]){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????????????? + petWndNo = 0; + // q??????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + // ???????? + if (HitDispNo == petWndFontNo[4]){ + // ??????k? + petWndNo = 2; + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????????????? + petWndNo = 2; + // q??????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(202, 320, 240); + } + } + // q?????????? + if (HitDispNo == petWndFontNo[1] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + // q?????????? + if (pActMenuWnd3 != NULL){ + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + while (1){ + petStatusNo--; + // ???????? + if (petStatusNo <= -1) petStatusNo = 4; + if (pet[petStatusNo].useFlag == TRUE) break; + } + // ???????k?? +#ifdef _LIZARDPOSITION // (ɿ) Syu ADD ʾλù + if ((pet[petStatusNo].graNo == 101493) || (pet[petStatusNo].graNo == 101494) || + (pet[petStatusNo].graNo == 101495) || (pet[petStatusNo].graNo == 101496)) + { + pActPet->x = pActMenuWnd->x + 220; + pActPet->y = pActMenuWnd->y + 124; + } + else + { + pActPet->x = pActMenuWnd->x + 200; + pActPet->y = pActMenuWnd->y + 144; + } +#endif + pActPet->anim_chr_no = pet[petStatusNo].graNo; +#ifdef _PET_SKINS + petChange(pActPet->anim_chr_no); +#endif + // ????? + play_se(217, 320, 240); + petWndBtnFlag[1] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && petWndBtnFlag[1] == TRUE){ + // ???? + petWndBtnFlag[1] = TRUE; + } + else{ + // ??? + petWndBtnFlag[1] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[1] = FALSE; + } + // ??????????? + if (HitDispNo == petWndFontNo[2] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + // q?????????? + if (pActMenuWnd3 != NULL){ + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + while (1){ + petStatusNo++; + // ???????? + if (petStatusNo >= 5) petStatusNo = 0; + if (pet[petStatusNo].useFlag == TRUE) break; + } + // ???????k? +#ifdef _LIZARDPOSITION // (ɿ) Syu ADD ʾλù + if ((pet[petStatusNo].graNo == 101493) || (pet[petStatusNo].graNo == 101494) || + (pet[petStatusNo].graNo == 101495) || (pet[petStatusNo].graNo == 101496)) + { + pActPet->x = pActMenuWnd->x + 220; + pActPet->y = pActMenuWnd->y + 124; + } + else + { + pActPet->x = pActMenuWnd->x + 200; + pActPet->y = pActMenuWnd->y + 144; + } +#endif + pActPet->anim_chr_no = pet[petStatusNo].graNo; +#ifdef _PET_SKINS + petChange(pActPet->anim_chr_no); +#endif + // ????? + play_se(217, 320, 240); + petWndBtnFlag[2] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && petWndBtnFlag[2] == TRUE){ + // ???? + petWndBtnFlag[2] = TRUE; + } + else{ + // ??? + petWndBtnFlag[2] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[2] = FALSE; + } + // q???? + if (HitDispNo == petWndFontNo[3]){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??????u? + if (pet[petStatusNo].changeNameFlag == TRUE){ + if (pActMenuWnd3 == NULL){ + // ????????? + pActMenuWnd3 = MakeWindowDisp(4, 4 + 280 + 56, 272, 88, 0, -1, 0); + // ???????? + play_se(202, 320, 240); + // q???? + petNameChange.buffer[0] = NULL; + petNameChange.cnt = 0; + petNameChange.cursor = 0; + // ???? + petNameChange.len = 16; + // ??? + petNameChange.color = 0; + // ???? + petNameChange.x = pActMenuWnd3->x + 22; + petNameChange.y = pActMenuWnd3->y + 25; + // ????I?? + petNameChange.fontPrio = FONT_PRIO_FRONT; + } + else{ // ??????????? + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + petWndBtnFlag[3] = TRUE; + + } + else{ + // ??? + play_se(220, 320, 240); + } + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && petWndBtnFlag[3] == TRUE){ + // ???? + petWndBtnFlag[3] = TRUE; + } + else{ + // ??? + petWndBtnFlag[3] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[3] = FALSE; + } +#ifndef _PET_SKINS + if (HitDispNo == petWndFontNo[7]){ + // ???????? + if (pet[petStatusNo].graNo != 100451 && pet[petStatusNo].graNo != 100432 && + pet[petStatusNo].graNo != 101280 && pet[petStatusNo].graNo != 101281 && + pet[petStatusNo].graNo != 100015 && pet[petStatusNo].graNo != 100018 && + pet[petStatusNo].graNo != 101279 && pet[petStatusNo].graNo != 100401 && + pet[petStatusNo].graNo != 101414 && pet[petStatusNo].graNo != 101167 && + pet[petStatusNo].graNo != 101172 && pet[petStatusNo].graNo != 102011 && + pet[petStatusNo].graNo != 102012) // fix Щﲻճ + if (mouse.onceState & MOUSE_LEFT_CRICK){ +#ifdef _TAIKEN + // ??? + play_se( 220, 320, 240 ); + // ??????? + sprintf_s( moji,"治ѡ" ); + // ?????????????????? + StockChatBufferLine( moji, FONT_PAL_WHITE ); +#else + int tblNo = pet[petStatusNo].graNo - 100250; // ?????k? +#if defined(__ALBUM_47) + if (tblNo > 1800){ //Сħ + tblNo -= 1208; + } + else if (tblNo > 1755){ //Ϲħ + tblNo -= 1201; + } + else if (tblNo > 1739){ // + tblNo -= 1200; + } + else if (tblNo > 1686){ //8.0 + tblNo -= 1175; + } + else if (tblNo > 1641){ //4 ׳2 8.0һϲ + tblNo -= 1167; + } + else if (tblNo > 1635){ // + tblNo -= 1148; + } + else if (tblNo > 1634){ //èŮ1 èŮ2 + tblNo -= 1149; + } + else if (tblNo > 1628){ //1 2 ţ1 ţ2 + tblNo -= 1147; + } + else if (tblNo > 1615){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + } + else if (tblNo > 1568){// + tblNo -= 1103; + } + else if (tblNo > 1564){//ɫ + tblNo -= 1101; + } + else if (tblNo > 1516){ + tblNo -= 1055; + } + else if (tblNo == 1516){// + tblNo = 455; + } + else if (tblNo > 1509){ + tblNo -= 1054; + } + else if (tblNo == 1497){ + tblNo = 395; + } + else if (tblNo > 1495){ + tblNo -= 1044; + } + else if (tblNo > 1490){ + tblNo -= 1043; + } + else if (tblNo > 1485){ + tblNo -= 1040; + } + else if (tblNo > 1454) { + tblNo -= 1034; + } + else if (tblNo == 1214) { + tblNo = 331; + } + else if (tblNo == 1217) { + tblNo = 328; + } + else if (tblNo > 1361){ + tblNo -= 952; + } + else if (tblNo > 1356){ + tblNo -= 999; + } + else if (tblNo > 1281){ + tblNo -= 919; + } + else if (tblNo > 1239){ + tblNo -= 889; + } + else if (tblNo > 1186){ + tblNo -= 886; + } + else if (tblNo > 1173){ + tblNo -= 877; + } + else if (tblNo > 1172){ + tblNo -= 877; + } + else if (tblNo > 1161){ + tblNo -= 868; + } + else if (tblNo > 930){ + tblNo -= 745; + } + else if (tblNo == 927){ + tblNo -= 634; + } + else if (tblNo > 929){ + tblNo -= 644; + } + else if (tblNo > 927){ + tblNo -= 643; + } + else if (tblNo > 900){ + tblNo -= 621; + } + else if (tblNo > 180){ + tblNo -= (333 + 56); + } +#elif defined(__ALBUM_46) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_45) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_44) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_43) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_42) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_41) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_40) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_39) + if( tblNo > 1800 ){ //Сħ + tblNo -= 1208; + }else if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_38) + if( tblNo > 1755 ){ //Ϲħ + tblNo -= 1201 ; + }else if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_37) + if (tblNo > 1739 ){ // + tblNo -= 1200; + }else if (tblNo > 1686 ){ //8.0 + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_36) + if (tblNo > 1686 ){ //4 ׳2 8.0һϲ + tblNo -= 1175; + }else if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_35) + if (tblNo > 1641 ){ //4 ׳2 8.0һϲ + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_34) + if (tblNo > 1639 ){ //4 + tblNo -= 1167; + }else if (tblNo > 1635 ){ // + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_33) + if (tblNo > 1635 ){ + tblNo -= 1148; + }else if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_32) + if ( tblNo > 1634 ){ //èŮ1 èŮ2 + tblNo -= 1149; + }else if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_31) + if ( tblNo > 1628 ){ //1 2 ţ1 ţ2 + tblNo -= 1147; + }else if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_30) + if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_29) + if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_28) + if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_27) + if( tblNo > 1615 ){// ۷1 ۷2 1 2 ʨ1 ʨ2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_26) + if( tblNo > 1615 ){// ۷1 ۷2 1 2 + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_25) + if( tblNo > 1615 ){// + tblNo -= 1145; + }else if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_24) + if( tblNo > 1568 ){// + tblNo -= 1103; + }else if( tblNo > 1564 ){//ɫ + tblNo -= 1101; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_23) + if( tblNo > 1518 ){ + tblNo -= 1057; + }else if( tblNo > 1516 ){ + tblNo -= 1055; + }else if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_22) + if ( tblNo == 1516 ){// + tblNo = 455 ; + }else if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_21) + if ( tblNo > 1509 ){ + tblNo -= 1054; + }else if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_20) + if ( tblNo == 1497 ){ + tblNo = 395; + }else if ( tblNo > 1495 ){ + tblNo -= 1044 ; + }else if ( tblNo > 1490 ){ + tblNo -= 1043 ; + }else if ( tblNo > 1485 ){ + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } + +#elif defined(__ALBUM_19) + if ( tblNo > 1485 ) { + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_18) + if ( tblNo > 1490 ){ + tblNo -= 1044; + }else if ( tblNo > 1485 ) { + tblNo -= 1040 ; + }else if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_17) + if ( tblNo > 1454 ) { + tblNo -= 1034 ; + }else if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_16) + if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#elif defined(__ALBUM_15) + if ( tblNo == 1214 ) { + tblNo = 331 ; + }else if ( tblNo == 1217 ) { + tblNo = 328 ; + }else if ( tblNo > 1361){ + tblNo -= 952; + }else if( tblNo > 1356){ + tblNo -= 999; + }else if( tblNo > 1281){ + tblNo -= 919; + }else if( tblNo > 1239){ + tblNo -= 889; + }else if( tblNo > 1186 ){ + tblNo -= 886; + }else if( tblNo > 1173 ){ + tblNo -= 877; + }else if( tblNo > 1172){ + tblNo -= 877; + }else if( tblNo > 1161){ + tblNo -= 868; + }else if( tblNo > 930){ + tblNo -= 745; + }else if( tblNo == 927){ + tblNo -= 634; + }else if( tblNo > 929){ + tblNo -= 644; + }else if( tblNo > 927){ + tblNo -= 643; + }else if( tblNo > 900){ + tblNo -= 621; + }else if( tblNo > 180){ + tblNo -= (333+56); + } +#endif + int albumNo; + // ??????? + if (0 <= tblNo && tblNo < MAX_PET_TBL){ + // ??????? + + if (tblNo == 442) + albumNo = 0; + + albumNo = PetAlbumTbl[tblNo].albumNo; + // ???????? + if (albumNo != -1){ + // ??????? + PetAlbum[albumNo].flag = 2; + + // ?????? + if (pet[petStatusNo].freeName[0] != NULL){ + strcpy(PetAlbum[albumNo].freeName, pet[petStatusNo].freeName); + } + else{ + // o??? + strcpy(PetAlbum[albumNo].freeName, PetAlbumTbl[tblNo].name); + } + // o??? + strcpy(PetAlbum[albumNo].name, PetAlbumTbl[tblNo].name); + // ???????k? + PetAlbum[albumNo].faceGraNo = PetAlbumTbl[tblNo].faceGraNo; + // ??? + PetAlbum[albumNo].level = pet[petStatusNo].level; + // ??? + PetAlbum[albumNo].maxHp = pet[petStatusNo].maxHp; + // ?? + PetAlbum[albumNo].str = pet[petStatusNo].atk; + // ?? + PetAlbum[albumNo].quick = pet[petStatusNo].quick; + // \? + PetAlbum[albumNo].def = pet[petStatusNo].def; + + // + PetAlbum[albumNo].earth = pet[petStatusNo].earth; + // ? + PetAlbum[albumNo].water = pet[petStatusNo].water; + // ? + PetAlbum[albumNo].fire = pet[petStatusNo].fire; + // ? + PetAlbum[albumNo].wind = pet[petStatusNo].wind; + + // ??? + play_se(201, 320, 240); + // ??????? + sprintf_s(moji, "%s ɣ", PetAlbum[albumNo].freeName); + // ?????????????????? + StockChatBufferLine(moji, FONT_PAL_WHITE); + + petWndBtnFlag[7] = TRUE; + // ?????V + SaveAlbum(albumNo); + + } + else{ + // ??? + play_se(220, 320, 240); +#ifdef _STONDEBUG_ + sprintf_s( moji,"ͼαź %d",pet[ petStatusNo ].graNo ); + MessageBoxNew( hWnd, moji, "ȷ", MB_OK | MB_ICONSTOP ); +#endif + // } + } + } + else{ + // ??? + play_se(220, 320, 240); +#ifdef _STONDEBUG_ + sprintf_s( moji,"tableź %d",tblNo ); + MessageBoxNew( hWnd, moji, "ȷ", MB_OK | MB_ICONSTOP ); +#endif + } +#endif + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && petWndBtnFlag[7] == TRUE){ + // ???? + petWndBtnFlag[7] = TRUE; + } + else{ + // ??? + petWndBtnFlag[7] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[7] = FALSE; + } +#endif + + + if (pActMenuWnd != NULL){ +#define PET_WND_ATTR_X 159 +#define PET_WND_ATTR_Y 5 + int x2; + x = pActMenuWnd->x + 20; + y = pActMenuWnd->y + 35; +#ifdef _PETBLESS_ + /* + if (pet[petStatusNo].blessflg){ + int blessNoid; + if (pet[petStatusNo].blesshp != 2){ + blessNoid = StockDispBuffer(x + 140, y + 128, DISP_PRIO_IME3, 55258, 2); + if (HitDispNo == blessNoid) ShowBottomLineString(FONT_PAL_WHITE, "ף"); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + ףѡ = 1; + if (!ףڿ) + lssproto_petbless_send(sockfd, petStatusNo, -1); + ףڿ = TRUE; + } + } + if (pet[petStatusNo].blessatk != 2){ + blessNoid = StockDispBuffer(x + 92, y + 150, DISP_PRIO_IME3, 55258, 2); + if (HitDispNo == blessNoid) ShowBottomLineString(FONT_PAL_WHITE, "ף"); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + + ףѡ = 2; + if (!ףڿ) + lssproto_petbless_send(sockfd, petStatusNo, -2); + ףڿ = TRUE; + + } + } + if (pet[petStatusNo].blessdef != 2){ + blessNoid = StockDispBuffer(x + 92, y + 175, DISP_PRIO_IME3, 55258, 2); + if (HitDispNo == blessNoid) ShowBottomLineString(FONT_PAL_WHITE, "ף"); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + + ףѡ = 3; + if (!ףڿ) + lssproto_petbless_send(sockfd, petStatusNo, -3); + ףڿ = TRUE; + } + } + if (pet[petStatusNo].blessquick != 2){ + blessNoid = StockDispBuffer(x + 92, y + 200, DISP_PRIO_IME3, 55258, 2); + if (HitDispNo == blessNoid) ShowBottomLineString(FONT_PAL_WHITE, "ף"); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + + ףѡ = 4; + if (!ףڿ) + lssproto_petbless_send(sockfd, petStatusNo, -4); + ףڿ = TRUE; + } + } + if (ףڿ){ + StockDispBuffer(x + 115, y + 345, DISP_PRIO_MENU, 55259, 1); + StockFontBuffer(x - 10, y + 325, FONT_PRIO_FRONT, 0, ף, 0); + blessNoid = StockDispBuffer(x + 65, y + 367, DISP_PRIO_IME3, 55233, 2); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + if (ףڿ) lssproto_petbless_send(sockfd, petStatusNo, ףѡ); + ףڿ = FALSE; + + } + blessNoid = StockDispBuffer(x + 165, y + 367, DISP_PRIO_IME3, 55235, 2); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == blessNoid)){ + ףڿ = FALSE; + } + } + } + */ +#endif +#ifdef _PETCOM_ + extern void ShowBottomLineString(int iColor, LPSTR lpstr); + static int ͼƬ = 0; + static int 㴰ڰťID = 0; + 㴰ڰťID = StockDispBuffer(x + 193, y + 5, DISP_PRIO_IME3, CG_PETCOM_CHANGE_BTN + ͼƬ, 2); + if (HitDispNo == 㴰ڰťID) + ShowBottomLineString(FONT_PAL_WHITE, "ɳ㡣"); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == 㴰ڰťID)){ + ͼƬ = 1; + if (mouse.onceState & MOUSE_LEFT_CRICK){ + petWndNo = 4; + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + DeathAction(pActPet); + pActPet = NULL; + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + GetKeyInputFocus(&MyChatBuffer); + play_se(202, 320, 240); + } + } + else{ + ͼƬ = 0; + } +#endif + + if (pet[petStatusNo].freeName[0] != NULL) + CenteringStr(pet[petStatusNo].freeName, moji, PET_NAME_LEN); + else + CenteringStr(pet[petStatusNo].name, moji, PET_NAME_LEN); + StockFontBuffer(x - 7, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#ifdef _SHOWPETTRN_ + sprintf(moji, "[%dת]", pet[petStatusNo].trn); + StockFontBuffer(x + 108, y - 24, FONT_PRIO_FRONT, 5, moji, 0); +#endif + petWndFontNo[3] = StockDispBuffer(x + 66, y + 7, DISP_PRIO_IME3, CG_NAME_CHANGE_BTN + petWndBtnFlag[3], 2); + y += 23; + sprintf_s(moji, "%3d", pet[petStatusNo].level); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + sprintf_s(moji, "%8d", pet[petStatusNo].exp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + sprintf_s(moji, "%8d", pet[petStatusNo].maxExp); + StockFontBuffer(x + 48, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#ifdef _PETBLESS_ + if (pet[petStatusNo].blesshp){ + sprintf_s(moji, "%4d", pet[petStatusNo].hp); + StockFontBuffer(x + 46, y, FONT_PRIO_FRONT, 2, moji, 0); + sprintf_s(moji, "%4d", pet[petStatusNo].maxHp); + StockFontBuffer(x + 48 + 45, y, FONT_PRIO_FRONT, 2, moji, 0); y += 24; + }else{ + sprintf_s(moji, "%4d", pet[petStatusNo].hp); + StockFontBuffer(x + 46, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%4d", pet[petStatusNo].maxHp); + StockFontBuffer(x + 48 + 45, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } +#else +#ifdef _PET_VAL_COLOR_ + sprintf_s(moji, "%4d", pet[petStatusNo].hp); + StockFontBuffer(x + 46, y, FONT_PRIO_FRONT, 1, moji, 0); + sprintf_s(moji, "%4d", pet[petStatusNo].maxHp); + StockFontBuffer(x + 48 + 45, y, FONT_PRIO_FRONT, 1, moji, 0); y += 24; +#else + sprintf_s(moji, "%4d", pet[petStatusNo].hp); + StockFontBuffer(x + 46, y, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%4d", pet[petStatusNo].maxHp); + StockFontBuffer(x + 48 + 45, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#endif +#endif + // ԢN??? + if (pet[petStatusNo].earth > 0){ + x2 = (int)(pet[petStatusNo].earth * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_GREEN, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + } + +#ifdef _PETBLESS_ + if (pet[petStatusNo].blessatk){ + sprintf_s(moji, "%3d", pet[petStatusNo].atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 2, moji, 0); y += 24; + } + else{ + sprintf_s(moji, "%3d", pet[petStatusNo].atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } +#else +#ifdef _PET_VAL_COLOR_ + sprintf_s(moji, "%3d", pet[petStatusNo].atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 6, moji, 0); y += 24; +#else + sprintf_s(moji, "%3d", pet[petStatusNo].atk); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#endif +#endif + // ?N??? + if (pet[petStatusNo].water > 0){ + x2 = (int)(pet[petStatusNo].water * 0.8); + + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_AQUA, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + } + +#ifdef _PETBLESS_ + if (pet[petStatusNo].blessdef){ + sprintf_s(moji, "%3d", pet[petStatusNo].def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 2, moji, 0); y += 24; + } + else{ + sprintf_s(moji, "%3d", pet[petStatusNo].def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } +#else +#ifdef _PET_VAL_COLOR_ + sprintf_s(moji, "%3d", pet[petStatusNo].def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 5, moji, 0); y += 24; +#else + sprintf_s(moji, "%3d", pet[petStatusNo].def); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#endif +#endif + // ?N??? + if (pet[petStatusNo].fire > 0){ + x2 = (int)(pet[petStatusNo].fire * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_RED, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + } +#ifdef _PETBLESS_ + if (pet[petStatusNo].blessquick){ + sprintf_s(moji, "%3d", pet[petStatusNo].quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 2, moji, 0); y += 24; + } + else{ + sprintf_s(moji, "%3d", pet[petStatusNo].quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } +#else +#ifdef _PET_VAL_COLOR_ + sprintf_s(moji, "%3d", pet[petStatusNo].quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 4, moji, 0); y += 24; +#else + sprintf_s(moji, "%3d", pet[petStatusNo].quick); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; +#endif +#endif + // ?N??? + if (pet[petStatusNo].wind > 0){ + x2 = (int)(pet[petStatusNo].wind * 0.8); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 0, y + PET_WND_ATTR_Y + 0, x + PET_WND_ATTR_X + 0 + x2, y + PET_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_YELLOW, 1); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 1, y + PET_WND_ATTR_Y + 1, x + PET_WND_ATTR_X + 1 + x2, y + PET_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + StockBoxDispBuffer(x + PET_WND_ATTR_X + 2, y + PET_WND_ATTR_Y + 2, x + PET_WND_ATTR_X + 2 + x2, y + PET_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + } + sprintf_s(moji, "%3d", pet[petStatusNo].ai); + StockFontBuffer(x + 50, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + y += 12; + // ????? + +#ifndef _PET_SKINS + petWndFontNo[7] = StockDispBuffer(x + 52, y, DISP_PRIO_IME3, CG_ALBUM_WND_SNAP_BTN_UP + petWndBtnFlag[7], 2); +#endif + petWndFontNo[4] = StockDispBuffer(x + 178, y, DISP_PRIO_IME3, CG_PET_WND_WAZA_BTN, 2); y += 31; + petWndFontNo[0] = StockDispBuffer(x + 100 + 70, y, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + petWndFontNo[1] = StockDispBuffer(x + 16 + 16 + 8, y, DISP_PRIO_IME3, CG_PREV_BTN + petWndBtnFlag[1], 2); + petWndFontNo[2] = StockDispBuffer(x + 50 + 16 + 18, y, DISP_PRIO_IME3, CG_NEXT_BTN + petWndBtnFlag[2], 2); + } + } + } + if (pActMenuWnd3 != NULL){ + if (pActMenuWnd3->hp > 0){ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd3->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd3->pYobi)->my, DISP_PRIO_MENU, CG_NAME_CHANGE_WND, 1); + // V??????x + GetKeyInputFocus(&petNameChange); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // q?ϣ??? + if (HitDispNo == petWndFontNo[5]){ + // ???????? + KeyboardReturn(); + + } + // q????????? + if (HitDispNo == petWndFontNo[6]){ + // ?????? + DeathAction(pActMenuWnd3); + pActMenuWnd3 = NULL; + // V???????? + GetKeyInputFocus(&MyChatBuffer); + // ???????? + play_se(203, 320, 240); + } + } + // ?????????????? + if (pActMenuWnd3 != NULL){ + // ??? + StockFontBuffer2(&petNameChange); + + // ?@e + x = pActMenuWnd3->x + 20; + y = pActMenuWnd3->y + 60; + petWndFontNo[5] = StockDispBuffer(x + 60, y + 7, DISP_PRIO_IME3, CG_OK_BTN, 2); + petWndFontNo[6] = StockDispBuffer(x + 170, y + 7, DISP_PRIO_IME3, CG_CANCEL_BTN, 2); + } + } + } + break; + + case 2: // ?????????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(4, 4, 272, 348, 0, -1); + // ???Re??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ????????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_PET_WAZA_WND, 1); + // ????????? + for (i = 0; i < pet[petStatusNo].maxSkill; i++){ + // ????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_IME3, CG_PET_WAZA_BAR_1 + i, 1); + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???????????? + if (HitDispNo == petWndFontNo[7]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????????? + petWndNo = 1; + // ???????? + play_se(203, 320, 240); + } + } + // q?????????? + if (HitDispNo == petWndFontNo[8] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + while (1){ + petStatusNo--; + // ???????? + if (petStatusNo <= -1) petStatusNo = 4; + if (pet[petStatusNo].useFlag == TRUE) break; + } + // ???Re??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + // ????? + play_se(217, 320, 240); + petWndBtnFlag[8] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && petWndBtnFlag[8] == TRUE){ + // ???? + petWndBtnFlag[8] = TRUE; + } + else{ + // ??? + petWndBtnFlag[8] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[8] = FALSE; + } + // ??????????? + if (HitDispNo == petWndFontNo[9] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + while (1){ + petStatusNo++; + // ???????? + if (petStatusNo >= 5) petStatusNo = 0; + if (pet[petStatusNo].useFlag == TRUE) break; + } + // ???Re??? + for (i = 0; i < MENU_PET_0; i++) petWndFontNo[i] = -2; + // ????? + play_se(217, 320, 240); + petWndBtnFlag[9] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && petWndBtnFlag[9] == TRUE){ + // ???? + petWndBtnFlag[9] = TRUE; + } + else{ + // ??? + petWndBtnFlag[9] = FALSE; + } + } + else{ + // ??? + petWndBtnFlag[9] = FALSE; + } + + // ???????? + if (pActMenuWnd != NULL){ + + // ?@e + x = pActMenuWnd->x + 32; + y = pActMenuWnd->y + 252; + + // C? + for (i = 0; i < pet[petStatusNo].maxSkill; i++){ + // ???????? + if (petSkill[petStatusNo][i].useFlag == TRUE){ + // ??????? + if (HitFontNo == petWndFontNo[i]){ + // ?????? + char *splitPoint = petSkill[petStatusNo][i].memo; + // ????? + while (1){ + // ????????? + if (strlen(splitPoint) > 24){ + strncpy_s(moji, splitPoint, 24); + moji[24] = NULL; // Z?????? + // u??S???? + if (GetStrLastByte(moji) == 3){ + moji[23] = NULL; + splitPoint += 23; + } + else{ + moji[24] = NULL; + splitPoint += 24; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); y += 20; + } + else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } +#ifdef _STONDEBUG_ + // ???????? + if( mouse.onceState & MOUSE_RIGHT_CRICK ){ + // ????????? + if( petSkill[ petStatusNo ][ i ].field != PETSKILL_FIELD_BATTLE ){ + int j; + int cnt = 0; + switch( petSkill[ petStatusNo ][ i ].skillId ){ + + case PETSKILL_MERGE: // ?G????? + // K????????????????? + for( j = MAX_ITEMSTART ; j < MAX_ITEMSTART ; j++ ){ + if( ItemBuffer[ j ].mixFlag == 1 ) cnt++; + } + break; + + case PETSKILL_MERGE2: // ??????? + // K????????????????? + for( j = MAX_ITEMSTART ; j < MAX_ITEM ; j++ ){ + if( ItemBuffer[ j ].mixFlag == 2 ) cnt++; + } + break; + } + + // K???????? + if( cnt >= 2 ){ + // ???? + moji[ 0 ] = NULL; + // ???????????? + for( j = MAX_ITEMSTART ; j < MAX_ITEM ; j++ ){ + // ?????????? + if( ItemBuffer[ j ].mixFlag >= TRUE ){ + char work[ 256 ]; + // ??? + sprintf_s( work,"%d|", j ); + strcat_s( moji, work ); + // ?????? + ItemBuffer[ j ].mixFlag = FALSE; + } + } + // ???|???????? + moji[ strlen( moji ) - 1 ] = NULL; + + // ?????????????????? + if( bNewServer) + lssproto_PS_send( sockfd, mixPetNo, i, 0, moji ); + else + old_lssproto_PS_send( sockfd, mixPetNo, i, 0, moji ); + + // ?????? + play_se(212, 320, 240); + } + else{ + // ??? + play_se(220, 320, 240); + } + } + else{ + // ??? + play_se(220, 320, 240); + } + } +#endif + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???????????????????????????????????? + if (petSkill[petStatusNo][i].field != PETSKILL_FIELD_BATTLE && pActPet2 == NULL + /* && MenuToggleFlag & JOY_CTRL_I*/){ + int j; + int cnt = 0; + // ????? + switch (petSkill[petStatusNo][i].skillId){ + + case PETSKILL_MERGE: // ?G????? + // K????????????????? + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 1) cnt++; + } + break; + + case PETSKILL_MERGE2: // ??????? + // K????????????????? + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 2) cnt++; + } + break; + case PETSKILL_INSLAY: //andy_add inslay + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 10) cnt++; + } + break; + case PETSKILL_FIXITEM: + case PETSKILL_FIXITEM2: + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 11) cnt++; + } + break; +#ifdef _ITEM_INTENSIFY + case PETSKILL_INTENSIFY: + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 12) cnt++; + } + break; +#endif +#ifdef _ITEM_UPINSLAY + case PETSKILL_UPINSLAY: + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 13) cnt++; + } + break; +#endif +#ifdef _ALCHEMIST + case PETSKILL_ALCHEMIST: + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++){ + if (ItemBuffer[j].mixFlag == 9) cnt++; + } + break; +#endif +#ifdef _CALLBUS + case PETSKILL_CALLBUS: + lssproto_PS_send(sockfd, petStatusNo, i, 0, ""); + break; +#endif + } + // K???????? + if (cnt >= 2){ + + // ???????????????? + if (pActPet2 == NULL){ + // ????????? + pActPet2 = MakeAnimDisp(750, 240, pet[petStatusNo].graNo, ANIM_DISP_MIX_PET_INIT); + // ????k??? + ItemMixPetNo = petStatusNo; + } + // ?k??? + SelectWazaNo = i; + // ????????k??? + mixPetNo = petStatusNo; + + // ?????? + play_se(212, 320, 240); + } + else{ +#ifdef _CALLBUS + if (petSkill[petStatusNo][i].skillId != PETSKILL_CALLBUS){ +#endif + // ????????????????? + if (!(MenuToggleFlag & JOY_CTRL_I) || (MenuToggleFlag & JOY_CTRL_I && itemWndNo != 0)){ + int j; + MenuToggleFlag |= JOY_CTRL_I; // CTRL + I ?? + // ????????k???? + for (j = 0; j < MENU_ITEM_0; j++) itemWndFontNo[j] = -2; + for (j = 0; j < MENU_ITEM_0; j++) itemWndBtnFlag[j] = 0; + itemWndNo = 0; + mouse.itemNo = -1; + itemWndDropGold = 0; + + // ?????????? + if (BattleResultWndFlag >= 1) DeathMenuAction(); + // ?????????? + DeathMenuAction2(); + // ???????? + saveUserSetting(); + + MenuToggleFlag &= ~JOY_CTRL_M; // ??????????? + // Pf??????????? + BattleResultWndFlag = FALSE; + // ????????? + MapWmdFlagBak = FALSE; + // ???????? + play_se(202, 320, 240); + } + else + // ??? + play_se(220, 320, 240); +#ifdef _CALLBUS + } +#endif + } + } + else{ + // ??? + play_se(220, 320, 240); + } + } + } + } + } + + x = pActMenuWnd->x + 40; + y = pActMenuWnd->y + 32; + if (pet[petStatusNo].freeName[0] != NULL) + CenteringStr(pet[petStatusNo].freeName, moji, PET_NAME_LEN); + else + CenteringStr(pet[petStatusNo].name, moji, PET_NAME_LEN); + StockFontBuffer(x - 28, y, FONT_PRIO_FRONT, 0, moji, 0); y += 26; x += 18; + for (i = 0; i < pet[petStatusNo].maxSkill; i++){ + if (petSkill[petStatusNo][i].useFlag == TRUE){ + int color = FONT_PAL_GRAY; +#ifdef _NEWFONT_ + sprintf_s(moji, " %-42s", petSkill[petStatusNo][i].name); +#else + sprintf_s(moji, " %-22s", petSkill[petStatusNo][i].name); +#endif + if (petSkill[petStatusNo][i].field != PETSKILL_FIELD_BATTLE) color = FONT_PAL_WHITE; + petWndFontNo[i] = StockFontBuffer(x - 43, y, FONT_PRIO_FRONT, color, moji, 2); + } + y += 25; + } + + // ?@e + x = pActMenuWnd->x + 20; + y = pActMenuWnd->y + 330; + + // ????????? + petWndFontNo[7] = StockDispBuffer(x + 100 + 70, y, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + petWndFontNo[8] = StockDispBuffer(x + 16 + 16 + 8, y, DISP_PRIO_IME3, CG_PREV_BTN + petWndBtnFlag[8], 2); + petWndFontNo[9] = StockDispBuffer(x + 50 + 16 + 18, y, DISP_PRIO_IME3, CG_NEXT_BTN + petWndBtnFlag[9], 2); + } + } + } + break; +#ifdef _STREET_VENDOR + case 3: petWndNo = 0; break; +#endif +#ifdef _PETCOM_ + case 4: + if (pActMenuWnd == NULL){ + pActMenuWnd = MakeWindowDisp(4, 4, 272, 320, 0, -1); + } + else{ + if (pActMenuWnd->hp > 0){ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_PETCOM_WND, 1); + int ťID = StockDispBuffer(pActMenuWnd->x + 190, pActMenuWnd->y + 300, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + if ((mouse.onceState & MOUSE_LEFT_CRICK) && (HitDispNo == ťID)){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + petWndNo = 1; + play_se(203, 320, 240); + break; + } + static int ť = 0; + static int Ұť = 0; + ťID = StockDispBuffer(pActMenuWnd->x + 60, pActMenuWnd->y + 300, DISP_PRIO_IME3, CG_PREV_BTN + ť, 2); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == ťID)){ + ť = 1; + if (mouse.onceState & MOUSE_LEFT_CRICK){ + while (1){ + petStatusNo--; + if (petStatusNo <= -1) petStatusNo = 4; + if (pet[petStatusNo].useFlag == TRUE) break; + } + play_se(203, 320, 240); + } + } + else{ + ť = 0; + } + ťID = StockDispBuffer(pActMenuWnd->x + 104, pActMenuWnd->y + 300, DISP_PRIO_IME3, CG_NEXT_BTN + Ұť, 2); + if ((mouse.state & MOUSE_LEFT_CRICK && HitDispNo == ťID)){ + Ұť = 1; + if (mouse.onceState & MOUSE_LEFT_CRICK){ + while (1){ + petStatusNo++; + // ???????? + if (petStatusNo >= 5) petStatusNo = 0; + if (pet[petStatusNo].useFlag == TRUE) break; + } + play_se(203, 320, 240); + } + } + else{ + Ұť = 0; + } +#define _PETCMOX 10 + if (pet[petStatusNo].freeName[0] != NULL) + CenteringStr(pet[petStatusNo].freeName, moji, PET_NAME_LEN); + else + CenteringStr(pet[petStatusNo].name, moji, PET_NAME_LEN); + StockFontBuffer(85, 36, FONT_PRIO_FRONT, 0, moji, 0); + + int atrFlag = FALSE; + int atrGraNo[4]; + atrFlag = 0; + if (pet[petStatusNo].earth > 0){ + if (pet[petStatusNo].earth > 50) atrGraNo[atrFlag] = CG_ATR_ICON_EARTH_BIG; + else atrGraNo[atrFlag] = CG_ATR_ICON_EARTH_SML; + atrFlag++; + } + if (pet[petStatusNo].water > 0){ + if (pet[petStatusNo].water > 50) atrGraNo[atrFlag] = CG_ATR_ICON_WATER_BIG; + else atrGraNo[atrFlag] = CG_ATR_ICON_WATER_SML; + atrFlag++; + } + if (pet[petStatusNo].fire > 0){ + if (pet[petStatusNo].fire > 50) atrGraNo[atrFlag] = CG_ATR_ICON_FIRE_BIG; + else atrGraNo[atrFlag] = CG_ATR_ICON_FIRE_SML; + atrFlag++; + } + if (pet[petStatusNo].wind > 0){ + if (pet[petStatusNo].wind > 50) atrGraNo[atrFlag] = CG_ATR_ICON_WIND_BIG; + else atrGraNo[atrFlag] = CG_ATR_ICON_WIND_SML; + atrFlag++; + } + if (atrFlag > 0) StockDispBuffer(232, 44, DISP_PRIO_IME3, atrGraNo[0], 0); + if (atrFlag > 1) StockDispBuffer(232 + 16, 44, DISP_PRIO_IME3, atrGraNo[1], 0); + + sprintf_s(moji, "%3d", pet[petStatusNo].oldlevel); + StockFontBuffer(80, 98, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[petStatusNo].oldhp); + StockFontBuffer(80, 120, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[petStatusNo].oldatk); + StockFontBuffer(80, 142, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[petStatusNo].olddef); + StockFontBuffer(80, 164, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[petStatusNo].oldquick); + StockFontBuffer(80, 186, FONT_PRIO_FRONT, 0, moji, 0); + float a, b, c, d, e, f; + float a1, b1, c1, d1, e1; + + if (pet[petStatusNo].level != pet[petStatusNo].oldlevel && pet[petStatusNo].oldlevel){ + f = (float)(pet[petStatusNo].level - pet[petStatusNo].oldlevel); + a = (pet[petStatusNo].maxHp - pet[petStatusNo].oldhp) / f; + b = (pet[petStatusNo].atk - pet[petStatusNo].oldatk) / f; + c = (pet[petStatusNo].def - pet[petStatusNo].olddef) / f; + d = (pet[petStatusNo].quick - pet[petStatusNo].oldquick) / f; + + f = 140.00 - pet[petStatusNo].oldlevel; + + a1 = f*a + pet[petStatusNo].oldhp; + b1 = f*b + pet[petStatusNo].oldatk; + c1 = f*c + pet[petStatusNo].olddef; + d1 = f*d + pet[petStatusNo].oldquick; + } + else{ + a = b = c = d = 1.0000; + a1 = b1 = c1 = d1 = 0; + } + e = b + c + d; + e1 = pet[petStatusNo].maxHp*0.25 + pet[petStatusNo].atk + pet[petStatusNo].def + pet[petStatusNo].quick; + + sprintf_s(moji, "%3d", 140); + + StockFontBuffer(155, 98, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.2f", a1); + StockFontBuffer(143, 120, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.2f", b1); + StockFontBuffer(143, 142, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.2f", c1); + StockFontBuffer(143, 164, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.2f", d1); + StockFontBuffer(143, 186, FONT_PRIO_FRONT, 0, moji, 0); + + sprintf_s(moji, "%3.4f", a); + StockFontBuffer(215, 120, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.4f", b); + StockFontBuffer(215, 142, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.4f", c); + StockFontBuffer(215, 164, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.4f", d); + StockFontBuffer(215, 186, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3.4f", e); + StockFontBuffer(80, 210, FONT_PRIO_FRONT, 0, moji, 0); + + sprintf_s(moji, "%3.2f", e1); + StockFontBuffer(210, 210, FONT_PRIO_FRONT, 0, moji, 0); + + + } + } + break; +#endif + } + } + + //? ??????????? *******************************************************/ + if (MenuToggleFlag & JOY_CTRL_I){ + int x1 = 0, y1 = 0; +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + SkillWndflag = false ; + /* if( pActMenuWnd3 != NULL ) { + DeathAction ( pActMenuWnd3 ) ; + pActMenuWnd3 = NULL ; + GetKeyInputFocus( &MyChatBuffer ); + } + */ +#endif +#ifdef _NPC_DANCE + if (pc.iDanceMode) + { + StockChatBufferLine("״̬޷ʹõ", FONT_PAL_RED); + MenuToggleFlag ^= JOY_CTRL_I; + itemWndNo = 3; + } +#endif + + switch (itemWndNo){ + case 0: + if (pActMenuWnd2 == NULL) + { + // ????????? +#ifndef _PET_ITEM + pActMenuWnd2 = MakeWindowDisp(365, 4, 271, 440, 0, -1); +#ifdef _NEW_ITEM_ + ҳ = 0; +#endif +#ifdef _MAGIC_ITEM_ + ߹⻷Act=NULL; +#endif + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, 0); +#else + pActMenuWnd2 = MakeWindowDisp(351, 4, 271, 440, 0, -1); +#ifdef _NEW_ITEM_ + ҳ = 0; +#endif + pActMenuWnd2->x += 14; + ((WINDOW_DISP*)pActMenuWnd2->pYobi)->mx = 271 / 2 + pActMenuWnd2->x; + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, g_bPetItemWndFlag); +#endif + // k???????k???? + itemNo = -1; + // ????k???? + ItemMixPetNo = -1; + // ???????????k??????? + if (MenuToggleFlag & JOY_CTRL_E && mailWndNo == MAIL_WND_ITEM){ + // ??????????? + MenuToggleFlag &= ~JOY_CTRL_E; + DeathMenuAction(); + } +#ifdef _MONEYINPUT //Syu ADD ֶǮ + MymoneyBuffer.buffer[0] = NULL; + MymoneyBuffer.cnt = 0; + MymoneyBuffer.cursor = 0; + MymoneyBuffer.len = 8; + MymoneyBuffer.color = 0; + MymoneyBuffer.x = pActMenuWnd2->x + 191; + MymoneyBuffer.y = pActMenuWnd2->y + 138; + MymoneyBuffer.fontPrio = FONT_PRIO_FRONT; + x1 = pActMenuWnd2->x + 173; + y1 = pActMenuWnd2->y + 133; +#endif +#ifdef _PET_ITEM + nSelectPet = -1; + + for (i = 0; i < MAX_PET; i++) + { + // ֻ + if (pet[i].useFlag) + { + nSelectPet = i; + break; + } + } +#endif + } + else + { + //andy_log װλ޸Ĵ + if (pActMenuWnd2->hp > 0) + { +#ifdef _PET_ITEM + // Ƿ˵Ӵߵıǩ + x1 = pActMenuWnd2->x - 21; + y1 = pActMenuWnd2->y + 12; + if (g_bPetItemWndFlag) + { + if (MakeHitBox(x1, y1, x1 + 23, y1 + 60, DISP_PRIO_IME3) == TRUE) // װ + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + g_bPetItemWndFlag = false; + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, g_bPetItemWndFlag); + } + } + else + { + if (MakeHitBox(x1, y1 + 78, x1 + 23, y1 + 142, DISP_PRIO_IME3) == TRUE) // ˳װ + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + g_bPetItemWndFlag = true; + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, g_bPetItemWndFlag); + } + } + if (g_bPetItemWndFlag) + StockDispBuffer(((WINDOW_DISP*)pActMenuWnd2->pYobi)->mx - 14, ((WINDOW_DISP*)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, 26456, 1); + else + StockDispBuffer(((WINDOW_DISP*)pActMenuWnd2->pYobi)->mx - 14, ((WINDOW_DISP*)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_NEWITEM_WND, 1); +#else +#ifdef _ITEM_EQUITSPACE + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_NEWITEM_WND, 1); +#else + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_ITEM_WND_0, 1); + + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_ITEM_WND_1, 1); +#endif +#endif + +#ifdef _MONEYINPUT //Syu ADD ֶǮ +#ifdef _PET_ITEM + if (!g_bPetItemWndFlag) // װҪʾµĶ +#endif + { + x1 = pActMenuWnd2->x + 175; + y1 = pActMenuWnd2->y + 133; + if (MakeHitBox(x1, y1, x1 + 86, y1 + 25, DISP_PRIO_IME3) == TRUE) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + strcpy(MymoneyBuffer.buffer, ""); + MymoneyBuffer.buffer[0] = NULL; + MymoneyBuffer.cursor = 0; + MymoneyBuffer.cnt = 0; + Moneyflag = true; + GetKeyInputFocus(&MymoneyBuffer); + play_se(217, 320, 240); + } + } + } + if (Moneyflag == true) + { + MymoneyBuffer.x = pActMenuWnd2->x + 240 - strlen(MymoneyBuffer.buffer) * 7; + StockFontBuffer2(&MymoneyBuffer); + itemWndDropGold = atoi(MymoneyBuffer.buffer); + if (atoi(MymoneyBuffer.buffer) >= pc.gold) + { + sprintf_s(MymoneyBuffer.buffer, "%d", pc.gold); + itemWndDropGold = pc.gold; + } + } +#endif + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // ¹رť + if (HitDispNo == itemWndFontNo[0]){ +#ifdef _MAGIC_ITEM_ + if(߹⻷Act) DeathAction(߹⻷Act); + ߹⻷Act=NULL; + extern void ClearMagicItemWin(); + ClearMagicItemWin(); +#endif + DeathAction(pActMenuWnd2); + + pActMenuWnd2 = NULL; + // ???? + DeathAction(pActPet2); + pActPet2 = NULL; + // ????k???? + ItemMixPetNo = -1; + // ??????????? + MenuToggleFlag ^= JOY_CTRL_I; + // ?????????????????? + if (MenuToggleFlag & JOY_CTRL_S){ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ?????????? + DeathMenuAction(); + } + // ???????? + play_se(203, 320, 240); + itemNo = -1; +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + } + // + if (HitDispNo == itemWndFontNo[1]){ + itemWndNo = 1; + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + DeathAction(pActPet2); + pActPet2 = NULL; + ItemMixPetNo = -1; + play_se(202, 320, 240); + if (!(MenuToggleFlag & JOY_CTRL_S)){ + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + for (i = 0; i < MENU_STATUS_0; i++) statusWndFontNo[i] = -2; + for (i = 0; i < MENU_STATUS_0; i++) statusWndBtnFlag[i] = 0; + statusWndNo = 1; + DeathMenuAction(); + saveUserSetting(); + MenuToggleFlag &= JOY_CTRL_I; + MenuToggleFlag |= JOY_CTRL_S; + } + else{ + if (statusWndNo != 1){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 1; + } + } + } + if (itemNo != -1 && MenuToggleFlag & JOY_CTRL_S && statusWndNo == 1){ + for (i = 0; i < 11; i++){ + if (HitFontNo == statusWndFontNo[i] && eventWarpSendFlag == FALSE){ + if (bNewServer) + lssproto_ID_send(sockfd, nowGx, nowGy, itemNo, i); + else + old_lssproto_ID_send(sockfd, nowGx, nowGy, itemNo, i); + play_se(212, 320, 240); + itemNo = -1; + + } + } + } +#ifdef _PET_ITEM + // ĿǰڳװӴ + if (g_bPetItemWndFlag) + { + // ͷ + if (HitDispNo == itemWndFontNo[5]) + { + if (nSelectPet != -1) + { + do + { + nSelectPet--; + if (nSelectPet == pc.ridePetNo) + nSelectPet--; + if (nSelectPet < 0) + nSelectPet = MAX_PET - 1; + } + while (!pet[nSelectPet].useFlag); + } + } + // Ҽͷ + if (HitDispNo == itemWndFontNo[6]) + { + if (nSelectPet != -1) + { + do + { + nSelectPet++; + if (nSelectPet == pc.ridePetNo) + nSelectPet++; + if (nSelectPet >= MAX_PET) + nSelectPet = 0; + } + while (!pet[nSelectPet].useFlag); + } + } + } +#endif + } + + if (HitDispNo == itemWndFontNo[2]){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (itemWndDropGold > 0 && eventWarpSendFlag == FALSE){ + itemWndBtnFlag[2] = TRUE; + play_se(217, 320, 240); + } + else{ + play_se(220, 320, 240); + } + } + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && itemWndBtnFlag[2] == TRUE){ + itemWndBtnFlag[2] = FALSE; + play_se(212, 320, 240); + if (bNewServer) + lssproto_DG_send(sockfd, nowGx, nowGy, itemWndDropGold); + else + old_lssproto_DG_send(sockfd, nowGx, nowGy, itemWndDropGold); + itemWndDropGold = 0; +#ifdef _MONEYINPUT //Syu ADD ֶǮ + Moneyflag = false; +#endif + + } + } + else + itemWndBtnFlag[2] = FALSE; + + if (HitDispNo == itemWndFontNo[3]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && itemWndBtnFlag[3] == TRUE){ + + itemWndBtnFlag[3] = FALSE; + } + // ?????? + if (itemWndBtnFlag[3] == TRUE){ +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + // ??? + itemWndDropGold += itemWndDropGoldInc; + // ????????????? + itemWndDropGoldCnt++; + // ?ƨ??? + if (itemWndDropGoldCnt >= 30){ + // ????????????? + itemWndDropGoldCnt = 0; + // ???????? + if (itemWndDropGoldInc == 0) itemWndDropGoldInc = 1; + else{ + // ????? + itemWndDropGoldInc *= 5; + // ???????? + if (itemWndDropGoldInc > 10000) itemWndDropGoldInc = 10000; + } + } + // ???????? + if (itemWndDropGold >= pc.gold){ + itemWndDropGold = pc.gold; + // ??? + play_se(220, 320, 240); + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + itemWndDropGold++; + // ???????? + if (itemWndDropGold >= pc.gold){ + itemWndDropGold = pc.gold; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + itemWndDropGoldInc = 0; + // ????????????? + itemWndDropGoldCnt = 0; + // ??????? + itemWndBtnFlag[3] = TRUE; + // ????? + play_se(217, 320, 240); + } + } + + } + else + // ?????? + itemWndBtnFlag[3] = FALSE; + + // ?????????? + if (HitDispNo == itemWndFontNo[4]) + { + // ??????????????? + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && itemWndBtnFlag[4] == TRUE){ + itemWndBtnFlag[4] = FALSE; + } + // ?????? + if (itemWndBtnFlag[4] == TRUE){ + // ???? +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + itemWndDropGold -= itemWndDropGoldInc; + // ????????????? + itemWndDropGoldCnt++; + // ?ƨ??? + if (itemWndDropGoldCnt >= 30){ + // ????????????? + itemWndDropGoldCnt = 0; + // ???????? + if (itemWndDropGoldInc == 0) itemWndDropGoldInc = 1; + else{ + // ????? + itemWndDropGoldInc *= 5; + // ???????? + if (itemWndDropGoldInc > 10000) itemWndDropGoldInc = 10000; + } + } + // ???????? + if (itemWndDropGold < 0){ + itemWndDropGold = 0; + // ??? + play_se(220, 320, 240); + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???? + itemWndDropGold--; + // ???????? + if (itemWndDropGold <= 0){ + itemWndDropGold = 0; + // ??? + play_se(220, 320, 240); + } + else{ + // ????? + itemWndDropGoldInc = 0; + // ????????????? + itemWndDropGoldCnt = 0; + // ??????? + itemWndBtnFlag[4] = TRUE; + // ????? + play_se(217, 320, 240); + + } + } + } + else + itemWndBtnFlag[4] = FALSE; + + if (pActMenuWnd2 != NULL) + { +#ifdef _NEW_ITEM_ + //ҳ + for (i = 0; i < 3; i++){ + if (i == ҳ){ + StockDispBuffer(513, 188 + i * 56, DISP_PRIO_IME3, 55113 + i, 1); + } + else{ + BOOL flg = FALSE; + if (i){ + if (pc.״̬ & 1 << i){ + flg = TRUE; + } + } + else flg = TRUE; + if (flg){ + StockDispBuffer(518, 188 + i * 56, DISP_PRIO_IME3, 55110 + i, 1); + if (MakeHitBox(508, 160 + i * 56, 508 + 20, 157 + i * 56 + 60, DISP_PRIO_IME4)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ҳ = i; + } + if (mouse.itemNo != -1) ҳ = i; + } + } + else StockDispBuffer(518, 188 + i * 56, DISP_PRIO_IME3, 55107 + i, 1); + } + } +#endif + x = pActMenuWnd2->x + 16; + y = pActMenuWnd2->y + 351 + 7; + if (itemNo != -1) + { + StockBoxDispBuffer(ItemBuffer[itemNo].defX - 24, ItemBuffer[itemNo].defY - 24, + ItemBuffer[itemNo].defX + 26, ItemBuffer[itemNo].defY + 23, + DISP_PRIO_IME4, SYSTEM_PAL_AQUA, 0); + } + + for (i = MAX_ITEM - 1; i >= 0; i--) + { +#ifdef _NEW_ITEM_ + int ʼ = MAX_ITEMSTART + MAX_MAXHAVEITEM*ҳ; + int ߽ = ʼ + MAX_MAXHAVEITEM; + if (i >= MAX_ITEMSTART){ + if (i < ʼ || i >= ߽) continue; + } +#endif +#ifdef _MAGIC_ITEM_ + if(pc.߹⻷Ч > 100000){ + if(߹⻷Act==NULL){ + ߹⻷Act = MakeAnimDisp(ItemBuffer[i].defX, ItemBuffer[i].defY,pc.߹⻷Ч, 0); + } + } +#endif +#ifdef _PET_ITEM + // ʾʱ,ϵװֻʾ߸,ľ + if (g_bPetItemWndFlag && (i >= PET_EQUIPNUM && i < MAX_ITEMSTART)) + continue; +#endif +#ifdef _ZENGJIASHUO_ +#ifdef _MAGIC_ITEM_ +#ifdef _SA_VERSION_25 + if ( i == 8 || i == 5 || i==7) +#endif +#else + if ( i == 5 || i == 6 || i==7) +#endif + { + continue; + } +#endif + if (MakeHitBox(ItemBuffer[i].defX - 24, ItemBuffer[i].defY - 24, + ItemBuffer[i].defX + 26, ItemBuffer[i].defY + 23, DISP_PRIO_IME3) == TRUE) + { +#ifdef _PET_ITEM + // ʾװ + if (g_bPetItemWndFlag && (i >= PET_HEAD && i < PET_EQUIPNUM) && nSelectPet > -1) + { + if (pet[nSelectPet].item[i].useFlag == TRUE && (ItemBuffer[i].mixFlag <= 2 || ItemBuffer[i].mixFlag == 10)) + { + char *splitPoint = pet[nSelectPet].item[i].memo; + char damage_msg[256]; + int color = pet[nSelectPet].item[i].color; + + StockFontBuffer(pActMenuWnd2->x + 16, pActMenuWnd2->y + 331, FONT_PRIO_FRONT, color, pet[nSelectPet].item[i].name, 0); + + // ʾƷ;ö + sprintf_s(damage_msg, ";ö(%s)", pet[nSelectPet].item[i].damage); + StockFontBuffer(pActMenuWnd2->x + 150, pActMenuWnd2->y + 331, FONT_PRIO_FRONT, color, damage_msg, 0); + +#ifdef _NPC_ITEMUP + ShowItemup(pet[nSelectPet].item[i].itemup,mouse.nowPoint.x,mouse.nowPoint.y);// ʾƷ״̬ +#endif +#ifdef _ITEM_COUNTDOWN + ShowCounttime(pet[nSelectPet].item[i].counttime,mouse.nowPoint.x,mouse.nowPoint.y);// ʾƷʱ״̬ +#endif + while (1) + { + if (strlen(splitPoint) > 28) + { + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; + if (GetStrLastByte(moji) == 3) + { + moji[27] = NULL; + splitPoint += 27; + } + else + { + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0); + y += 24; + } + else + { + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + } + } + else + // װ +#endif + { +#ifdef _ALCHEMIST + if (pc.item[i].useFlag == TRUE) +#else + if (pc.item[i].useFlag == TRUE && (ItemBuffer[i].mixFlag <= 2 || ItemBuffer[i].mixFlag == 10)) +#endif + { + char *splitPoint = pc.item[i].memo; + int color = pc.item[i].color; + if (pc.transmigration == 0 && pc.level < pc.item[i].level) color = FONT_PAL_RED; + StockFontBuffer(pActMenuWnd2->x + 16, pActMenuWnd2->y + 331, FONT_PRIO_FRONT, color, pc.item[i].name, 0); + { + + // ʾƷ;ö + char damage_msg[256]; + sprintf_s(damage_msg, ";ö(%s)", pc.item[i].damage); + StockFontBuffer(pActMenuWnd2->x + 150, pActMenuWnd2->y + 331, FONT_PRIO_FRONT, color, damage_msg, 0); + } +#ifdef _NPC_ITEMUP + ShowItemup(pc.item[i].itemup, mouse.nowPoint.x, mouse.nowPoint.y);// ʾƷ״̬ +#endif +#ifdef _ITEM_COUNTDOWN + ShowCounttime(pc.item[i].counttime, mouse.nowPoint.x, mouse.nowPoint.y);// ʾƷʱ״̬ +#endif + while (1){ + if (strlen(splitPoint) > 28){ + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; + if (GetStrLastByte(moji) == 3){ + moji[27] = NULL; + splitPoint += 27; + } + else{ + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } + else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + } + } + if (pActPet2 == NULL) + { + if (mouse.onceState & MOUSE_LEFT_CRICK && mouse.itemNo == -1) + { +#ifdef _MAGIC_ITEM_ + extern int MagicItemCombinData[3]; + if(MagicItemCombinData[0]==i) MagicItemCombinData[0]=0; + if(MagicItemCombinData[1]==i) MagicItemCombinData[1]=0; + if(MagicItemCombinData[2]==i) MagicItemCombinData[2]=0; +#endif + ItemBuffer[i].mixFlag = FALSE; +#ifdef _PET_ITEM + if (g_bPetItemWndFlag && (i >= PET_HEAD && i < PET_EQUIPNUM) && nSelectPet > -1) + { + if (pet[nSelectPet].item[i].useFlag == TRUE) + { + ItemBuffer[i].dragFlag = TRUE; + mouse.itemNo = i; + itemNo = -1; + } + } + else +#endif + if (pc.item[i].useFlag == TRUE){ + ItemBuffer[i].dragFlag = TRUE; + mouse.itemNo = i; + itemNo = -1; + } + } + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + if (mouse.itemNo != -1) + { + if (mouse.itemNo != i && ItemBuffer[i].mixFlag == 0) + { +#ifdef _PET_ITEM + if (g_bPetItemWndFlag) + { + if (nSelectPet > -1 && !(mouse.itemNo >= CHAR_EQUIPPLACENUM && i >= CHAR_EQUIPPLACENUM)) + { + if (i < CHAR_EQUIPPLACENUM && nSelectPet == pc.ridePetNo) // Ҫװȥ,Dz + StockChatBufferLine("費װװ", FONT_PAL_YELLOW); + else + lssproto_PetItemEquip_send(sockfd, nowGx, nowGy, nSelectPet, mouse.itemNo, i); + } + else + { + if (bNewServer) + lssproto_MI_send(sockfd, mouse.itemNo, i); + else + old_lssproto_MI_send(sockfd, mouse.itemNo, i); + } + } + else +#endif + { + if (bNewServer) + lssproto_MI_send(sockfd, mouse.itemNo, i); + else + old_lssproto_MI_send(sockfd, mouse.itemNo, i); + } + play_se(217, 320, 240); + } + ItemBuffer[mouse.itemNo].dragFlag = FALSE; + mouse.itemNo = -1; + } + } + if (mouse.onceState & MOUSE_LEFT_DBL_CRICK && ItemUseTime < TimeGetTime() - 500) + { + ItemUseTime = TimeGetTime(); +#ifdef _PET_ITEM + // Ŀǰװװװʱ,Զеװ + if (!g_bPetItemWndFlag) + { + if (pc.item[i].useFlag && pc.item[i].type >= ITEM_PET_HEAD && pc.item[i].type < ITEM_CATEGORYNUM) + { + g_bPetItemWndFlag = true; + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, g_bPetItemWndFlag); + break; + } + } + // Ŀǰڳװװװʱ,Զеװ + else + { + if (pc.item[i].useFlag && pc.item[i].type < ITEM_PET_HEAD && i >= MAX_ITEMSTART) + { + g_bPetItemWndFlag = false; + InitItem(pActMenuWnd2->x, pActMenuWnd2->y, g_bPetItemWndFlag); + break; + } + } +#endif + if (pc.item[i].useFlag != TRUE || pc.item[i].field == ITEM_FIELD_BATTLE || pc.transmigration == 0 && pc.level < pc.item[i].level){ + play_se(220, 320, 240); + } + else{ // ??u?? + mouse.itemNo = -1; + switch (pc.item[i].target){ + case ITEM_TARGET_MYSELF: // ?? + if (eventWarpSendFlag == FALSE){ +#ifdef _ITEM_JIGSAW + if (strlen(pc.item[i].jigsaw)){ + if (pc.item[i].graNo >= 25151 && pc.item[i].graNo <= 25159 //װͼ + && strcmp(pc.item[i].jigsaw, "111111111") + || pc.item[i].graNo == 25150){ + SetJigsaw(pc.item[i].graNo, pc.item[i].jigsaw); + if (!(MenuToggleFlag & JOY_CTRL_S)){ + int j; + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + for (j = 0; j < MENU_STATUS_0; j++) statusWndFontNo[j] = -2; + for (j = 0; j < MENU_STATUS_0; j++) statusWndBtnFlag[j] = 0; + statusWndNo = 4; + DeathMenuAction(); + saveUserSetting(); + play_se(202, 320, 240); + MenuToggleFlag &= JOY_CTRL_I; + MenuToggleFlag |= JOY_CTRL_S; + } + else{ + if (statusWndNo != 4){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 4; + play_se(202, 320, 240); + } + } + JigsawIdx = i; + break; + } + else{ + if (!DrawJigsawFlag){ + if (pc.item[i].graNo >= 25151 && pc.item[i].graNo <= 25159) + StockChatBufferLine("ȿƴͼװ", FONT_PAL_YELLOW); + else + StockChatBufferLine("ȿСƴͼװ", FONT_PAL_YELLOW); + break; + } + if (statusWndNo == 4 && CheckJigsaw(pc.item[i].graNo)) + lssproto_ID_send(sockfd, nowGx, nowGy, i, JigsawIdx); + break; + } + } + if (CheckJigsaw(pc.item[i].graNo)){ + if (!DrawJigsawFlag){ + if (pc.item[i].graNo >= 25151 && pc.item[i].graNo <= 25159){ + StockChatBufferLine("ȿƴͼװ", FONT_PAL_YELLOW); + } + else{ + StockChatBufferLine("ȿСƴͼװ", FONT_PAL_YELLOW); + } + break; + } + if (statusWndNo == 4) + lssproto_ID_send(sockfd, nowGx, nowGy, i, JigsawIdx); + break; + } +#endif + if (bNewServer) + lssproto_ID_send(sockfd, nowGx, nowGy, i, 0); + else + old_lssproto_ID_send(sockfd, nowGx, nowGy, i, 0); + play_se(212, 320, 240); + } + break; + case ITEM_TARGET_OTHER: // \????) + itemNo = i; + play_se(217, 320, 240); + if (!(MenuToggleFlag & JOY_CTRL_S)){ + int j; + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + for (j = 0; j < MENU_STATUS_0; j++) statusWndFontNo[j] = -2; + for (j = 0; j < MENU_STATUS_0; j++) statusWndBtnFlag[j] = 0; + statusWndNo = 1; + DeathMenuAction(); + saveUserSetting(); + play_se(202, 320, 240); + MenuToggleFlag &= JOY_CTRL_I; + MenuToggleFlag |= JOY_CTRL_S; + } + else{ + if (statusWndNo != 1){ + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + statusWndNo = 1; + play_se(202, 320, 240); + } + } + break; +#ifdef _PET_ITEM + case ITEM_TARGET_PET: + if (eventWarpSendFlag == FALSE) + { + // װװ򲻶 + if (i >= PET_HEAD && i < PET_EQUIPNUM) + break; + if (pc.ridePetNo != -1 && nSelectPet == pc.ridePetNo) // Dz + StockChatBufferLine("費װװ", FONT_PAL_YELLOW); + else + lssproto_PetItemEquip_send(sockfd, nowGx, nowGy, nSelectPet, i, -1); + play_se(212, 320, 240); + } + break; +#endif + } + } + } + //#ifdef _STONDEBUG_ + // ??????????????????????Τ + if (mouse.onceState & MOUSE_RIGHT_CRICK && mouse.itemNo == -1) + { + int j; + int cnt = 0; + // ????????????????????????????? + if (pc.item[i].useFlag == TRUE && i >= MAX_ITEMSTART /*&& pc.item[ i ].sendFlag & ITEM_FLAG_MIX */) + { + int j; + int flag = 0; + // k????k???? + if (itemNo != -1) itemNo = -1; + // ?????? + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++) + { + // ?????????? + if (ItemBuffer[j].mixFlag >= TRUE){ + flag = ItemBuffer[j].mixFlag; + break; + } + } + // ????????? + if (ItemBuffer[i].mixFlag == FALSE) + { + // ????k???????? + if (flag == 0){ + // ???? + if (pc.item[i].sendFlag & ITEM_FLAG_COOKING_MIX){ + // ?????????????? + if (CheckPetSkill(PETSKILL_MERGE2) == TRUE){ + ItemBuffer[i].mixFlag = 2; + // ????? + play_se(217, 320, 240); + } + else{ + // ??? + play_se(220, 320, 240); + } + } + //andy_add + else if (pc.item[i].sendFlag & ITEM_FLAG_METAL_MIX || + pc.item[i].sendFlag & ITEM_FLAG_JEWEL_MIX){ + if (CheckPetSkill(PETSKILL_INSLAY)){ + ItemBuffer[i].mixFlag = 10; + play_se(217, 320, 240); + } + else{ + play_se(220, 320, 240); + } + } + else if (pc.item[i].sendFlag & ITEM_FLAG_FIX_MIX){ + if (CheckPetSkill(PETSKILL_FIXITEM) || CheckPetSkill(PETSKILL_FIXITEM2)){ + ItemBuffer[i].mixFlag = 11; + play_se(217, 320, 240); + } + else{ + play_se(220, 320, 240); + } + } +#ifdef _ITEM_INTENSIFY + else if (pc.item[i].sendFlag & ITEM_FLAG_INTENSIFY_MIX){ + if (CheckPetSkill(PETSKILL_INTENSIFY)){ + ItemBuffer[i].mixFlag = 12; + play_se(217, 320, 240); + } + else{ + play_se(220, 320, 240); + } + } +#endif +#ifdef _ITEM_UPINSLAY + else if (pc.item[i].sendFlag & ITEM_FLAG_UPINSLAY_MIX){ + if (CheckPetSkill(PETSKILL_UPINSLAY)){ + ItemBuffer[i].mixFlag = 13; + play_se(217, 320, 240); + } + else{ + play_se(220, 320, 240); + } + } +#endif + else{ +#ifdef _ALCHEMIST // һǷ + if (CheckPetSkill(PETSKILL_ALCHEMIST) == TRUE && + pc.item[i].sendFlag & ITEM_FLAG_MIX && + strcmp(pc.item[i].alch, "") != NULL){ + ItemBuffer[i].mixFlag = 9; + } + else +#endif + // ?????????????? + if (CheckPetSkill(PETSKILL_MERGE) == TRUE && + pc.item[i].sendFlag & ITEM_FLAG_MIX){ + ItemBuffer[i].mixFlag = 1; + // ????? + play_se(217, 320, 240); + } + else{ + // ??? + play_se(220, 320, 240); + } + } + } + else{ + + // ???? + if (pc.item[i].sendFlag & ITEM_FLAG_COOKING_MIX){ + if (flag == 2){ + ItemBuffer[i].mixFlag = 2; + // ????? + play_se(217, 320, 240); + } + else{ + // ??? + play_se(220, 320, 240); + } + } + + else{ + if (flag == 1){ + ItemBuffer[i].mixFlag = 1; + // ????? + play_se(217, 320, 240); + } +#ifdef _ALCHEMIST // һ֮ľ + else if (flag == 9){ + if (strcmp(pc.item[i].alch, pc.item[j].alch) == FALSE) { + ItemBuffer[i].mixFlag = 9; + } + play_se(217, 320, 240); + } +#endif + else if (flag == 10){ //andy_add inslay + ItemBuffer[i].mixFlag = 10; + play_se(217, 320, 240); + } + else if (flag == 11){ //andy_add fixitem + ItemBuffer[i].mixFlag = 11; + play_se(217, 320, 240); + } +#ifdef _ITEM_INTENSIFY + else if (flag == 12){ + ItemBuffer[i].mixFlag = 12; + play_se(217, 320, 240); + } +#endif +#ifdef _ITEM_UPINSLAY + else if (flag == 13){ + ItemBuffer[i].mixFlag = 13; + play_se(217, 320, 240); + } +#endif + + else{ + // ??? + play_se(220, 320, 240); + } + + } + } + } + else + { +#ifdef _ALCHEMIST // ȡһϳʱ... + if (ItemBuffer[i].mixFlag == 9) { + int k; + ItemBuffer[i].mixFlag = 1; + for (k = MAX_ITEMSTART; k < MAX_ITEM; k++){ + if (ItemBuffer[k].mixFlag >= TRUE && (k != i)){ + ItemBuffer[i].mixFlag = FALSE; + break; + } + } + } +#ifdef _MAGIC_ITEM_ + else if (ItemBuffer[i].mixFlag == 14) { + extern int MagicItemCombinData[3],MagicItemPosState[4]; + MagicItemCombinData[0]=-1; + + ItemBuffer[i].mixFlag = FALSE; + } + else if (ItemBuffer[i].mixFlag == 15) { + extern int MagicItemCombinData[3],MagicItemPosState[4]; + MagicItemCombinData[1]=-1; + + ItemBuffer[i].mixFlag = FALSE; + } + else if (ItemBuffer[i].mixFlag == 16) { + extern int MagicItemCombinData[3],MagicItemPosState[4]; + MagicItemCombinData[2]=-1; + + ItemBuffer[i].mixFlag = FALSE; + } +#endif + else { + ItemBuffer[i].mixFlag = FALSE; + } +#else + ItemBuffer[i].mixFlag = FALSE; +#endif + play_se(217, 320, 240); + } + } + else + play_se(220, 320, 240); + + for (j = MAX_ITEMSTART; j < MAX_ITEM; j++) + { + if (ItemBuffer[j].mixFlag >= 1) cnt++; + } + if (cnt >= 2) + { + if (!(MenuToggleFlag & JOY_CTRL_P)) + { + + MenuToggleFlag ^= JOY_CTRL_P; // CTRL + S ?? + for (j = 0; j < MENU_PET_0; j++) petWndFontNo[j] = -2; + for (j = 0; j < MENU_PET_0; j++) petWndBtnFlag[j] = 0; + petWndNo = 0; + DeathMenuAction(); + saveUserSetting(); + play_se(202, 320, 240); + + MenuToggleFlag &= JOY_CTRL_I; // ?????????????? + MenuToggleFlag |= JOY_CTRL_P; // ?????????? + } + } + } + } + } +#ifdef _PET_ITEM + if (g_bPetItemWndFlag && nSelectPet > -1 && (i >= PET_HEAD && i < PET_EQUIPNUM) && pet[nSelectPet].useFlag == TRUE) + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pet[nSelectPet].item[i].graNo, 0); + else +#endif + if (pc.item[i].useFlag == TRUE) + { +#ifdef _PET_ITEM + if (!(g_bPetItemWndFlag && i < CHAR_EQUIPPLACENUM)) +#endif + { +#if 0 + if (ItemBuffer[i].mixFlag <= 9) +#else + if (ItemBuffer[i].mixFlag <= 2) +#endif + { + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); +#ifdef _ITEM_PILENUMS + if (pc.item[i].pile > 1) + { + char pile[256]; + sprintf_s(pile, "%d", pc.item[i].pile); + StockFontBuffer(ItemBuffer[i].defX + 10, ItemBuffer[i].defY, FONT_PRIO_FRONT, FONT_PAL_WHITE, pile, 0); + } +#endif + } +#ifdef _ALCHEMIST + else if (ItemBuffer[i].mixFlag == 9) + { + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } +#endif + else if (ItemBuffer[i].mixFlag == 10) + { //andy_add inslay + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } + else if (ItemBuffer[i].mixFlag == 11) + { //andy_add fixitem + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } +#ifdef _ITEM_INTENSIFY + else if (ItemBuffer[i].mixFlag == 12) + { //andy_add fixitem + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } +#endif +#ifdef _ITEM_UPINSLAY + else if (ItemBuffer[i].mixFlag == 13) + { //andy_add fixitem + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } +#endif + else if (ItemBuffer[i].mixFlag == 3) + { // ?????? + // ???? + StockDispBuffer(pActPet2->x, pActPet2->y - 16, DISP_PRIO_DRAG, pc.item[i].graNo, 0); + } + else if (ItemBuffer[i].mixFlag == 4) + { // ???????? + // ???? + StockDispBuffer(pActPet2->x, pActPet2->y, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } +#ifdef _MAGIC_ITEM_ + if (ItemBuffer[i].mixFlag == 14 || ItemBuffer[i].mixFlag == 15 || ItemBuffer[i].mixFlag == 16){ + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } + +#endif + + + + } + } + // ʾϳ + if (ItemBuffer[i].mixFlag >= TRUE) + { + // ????????????? + if (pc.item[i].useFlag == TRUE){ + // ͨϳɵʱ + if (ItemBuffer[i].mixFlag == 1){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "ϳ", 0); + } + else + // ϳɵʱ + if (ItemBuffer[i].mixFlag == 2){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "", 0); + } +#ifdef _ALCHEMIST + if (ItemBuffer[i].mixFlag == 9){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "", 0); + } +#endif + if (ItemBuffer[i].mixFlag == 10){// PETSKILL_INSLAY ANDY_ADD + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "", 0); + } + if (ItemBuffer[i].mixFlag == 11){// PETSKILL_FIXITEM ANDY_ADD + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "޸", 0); + } +#ifdef _ITEM_INTENSIFY + if (ItemBuffer[i].mixFlag == 12){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "ǿ", 0); + } +#endif +#ifdef _ITEM_UPINSLAY + if (ItemBuffer[i].mixFlag == 13){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "", 0); + } +#endif +#ifdef _MAGIC_ITEM_ + if (ItemBuffer[i].mixFlag == 14){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "", 0); + } + if (ItemBuffer[i].mixFlag == 15){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "ʯ", 0); + } + if (ItemBuffer[i].mixFlag == 16){ + StockFontBuffer(ItemBuffer[i].defX - 17, ItemBuffer[i].defY, FONT_PRIO_FRONT, 0, "ף", 0); + } +#endif + + } + else{ + // ??????? + ItemBuffer[i].mixFlag = TRUE; + } + } + } + // ????????? + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + +#ifdef _MAGIC_ITEM_ + + if(MagicItemActAddr){ + if(MagicItemPosState[0]){ + if(MagicItemCombinData[0]) ItemBuffer[MagicItemCombinData[0]].mixFlag= 0; + // if(mouse.itemNo!=-1 && pc.item[mouse.itemNo].==25) { + if(mouse.itemNo!=-1 && pc.item[mouse.itemNo].>=0&&pc.item[mouse.itemNo].<20 && pc.item[mouse.itemNo].!=16) { + MagicItemCombinData[0] = mouse.itemNo; + ItemBuffer[mouse.itemNo].mixFlag=14; + } + else MagicItemCombinData[0]=-1; + } + else if(MagicItemPosState[1]){ + if(MagicItemCombinData[1]) ItemBuffer[MagicItemCombinData[1]].mixFlag= 0; + if(mouse.itemNo!=-1 && pc.item[mouse.itemNo].==38){ + ItemBuffer[mouse.itemNo].mixFlag=15; + MagicItemCombinData[1] = mouse.itemNo; + }else MagicItemCombinData[1]=-1; + + } + else if(MagicItemPosState[2]){ + if(MagicItemCombinData[2]) ItemBuffer[MagicItemCombinData[2]].mixFlag= 0; + if(mouse.itemNo!=-1 && pc.item[mouse.itemNo].==39) { + ItemBuffer[mouse.itemNo].mixFlag=16; + MagicItemCombinData[2] = mouse.itemNo; + }else MagicItemCombinData[2]=-1; + } + mouse.itemNo=-1; + } +#endif + + // ??????????? + + if (mouse.itemNo != -1){ + // ???????? + if (mouse.nowPoint.x <= pActMenuWnd2->x && mouse.itemNo != -1 && eventWarpSendFlag == FALSE){ +#ifdef _PET_ITEM + if (g_bPetItemWndFlag) + lssproto_PetItemEquip_send(sockfd, nowGx, nowGy, nSelectPet, mouse.itemNo, -2); + else +#endif + // ?????t?? + if (bNewServer) { + lssproto_DI_send(sockfd, nowGx, nowGy, mouse.itemNo); + } + else + old_lssproto_DI_send(sockfd, nowGx, nowGy, mouse.itemNo); + + } + // ?????????? + ItemBuffer[mouse.itemNo].dragFlag = FALSE; + // ????????k???? + mouse.itemNo = -1; + // ????? + play_se(217, 320, 240); + } + } + // ????????? + if (mouse.itemNo != -1) + { + // ?????????????? + if (mouse.onceState & MOUSE_RIGHT_CRICK) + { + // ???t??? + // ?????????? + ItemBuffer[mouse.itemNo].dragFlag = FALSE; + // ????????k???? + mouse.itemNo = -1; + // ????? + play_se(217, 320, 240); + } + // ???? +#ifdef _PET_ITEM + if (g_bPetItemWndFlag && nSelectPet > -1 && (mouse.itemNo >= PET_HEAD && mouse.itemNo < PET_EQUIPNUM) && pet[nSelectPet].useFlag == TRUE) + StockDispBuffer(mouse.nowPoint.x, mouse.nowPoint.y, DISP_PRIO_DRAG, pet[nSelectPet].item[mouse.itemNo].graNo, 0); + else +#endif + StockDispBuffer(mouse.nowPoint.x, mouse.nowPoint.y, DISP_PRIO_DRAG, pc.item[mouse.itemNo].graNo, 0); + } + // ???????? + if (pActMenuWnd2 != NULL) + { +#ifdef _DIEJIA_ + static int ʱ = 0; + int ťID = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx - 60, pActMenuWnd2->y + 422, DISP_PRIO_IME3, 55246, 2); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + if (HitDispNo == ťID){ + if (TimeGetTime() > ʱ){ + ʱ = TimeGetTime() + 4000; + int itemMax = CHAR_EQUIPPLACENUM + MAX_MAXHAVEITEM; +#ifdef _NEW_ITEM_ + if (pc.״̬ & 1 << 1){ + itemMax += MAX_MAXHAVEITEM; + } + if (pc.״̬ & 1 << 2){ + itemMax += MAX_MAXHAVEITEM; + } +#endif + chatStrSendForServer("/",0); + } + else{ + StockChatBufferLine("̫Ƶ", FONT_PAL_YELLOW); + } + } + } + itemWndFontNo[0] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx + 60, pActMenuWnd2->y + 422, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); +#else + itemWndFontNo[ 0 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd2->pYobi )->mx, pActMenuWnd2->y + 422, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); +#endif + + + +#ifdef _PET_ITEM + if (g_bPetItemWndFlag) + { + itemWndFontNo[1] = -2; + // ʾͷ + itemWndFontNo[5] = StockDispBuffer(pActMenuWnd2->x + 188, pActMenuWnd2->y + 142, DISP_PRIO_IME3, 26047, 2); + // ʾҼͷ + itemWndFontNo[6] = StockDispBuffer(pActMenuWnd2->x + 236, pActMenuWnd2->y + 142, DISP_PRIO_IME3, 26048, 2); + + // ʾ + if (nSelectPet > -1 && pet[nSelectPet].useFlag) + { + char szTemp[16]; + WORD wSpecies = HIWORD(pet[nSelectPet].fusion); + + if (wSpecies < 0 || wSpecies >= MAX_PET_SPECIES) + wSpecies = MAX_PET_SPECIES; + // ʾװĵͼ + for (i = 0; i < PET_EQUIPNUM; i++) + { + if (byShowPetItemBackground[wSpecies] & (1 << i)) + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, DISP_PRIO_IME3, nPetItemEquipBmpNumber[i][0], 0); + else + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY, DISP_PRIO_IME3, nPetItemEquipBmpNumber[i][1], 0); + } + + // ʾ + if (strlen(pet[nSelectPet].freeName) > 0) + StockFontBuffer(pActMenuWnd2->x + 148, pActMenuWnd2->y + 17, FONT_PRIO_FRONT, 0, pet[nSelectPet].freeName, 0); + else + StockFontBuffer(pActMenuWnd2->x + 148, pActMenuWnd2->y + 17, FONT_PRIO_FRONT, 0, pet[nSelectPet].name, 0); + // ʾ + _itoa_s(pet[nSelectPet].maxHp, szTemp, 10); + StockFontBuffer(pActMenuWnd2->x + 222, pActMenuWnd2->y + 40, FONT_PRIO_FRONT, FONT_PAL_WHITE, szTemp, 0); + _itoa_s(pet[nSelectPet].atk, szTemp, 10); + StockFontBuffer(pActMenuWnd2->x + 222, pActMenuWnd2->y + 40 + 25, FONT_PRIO_FRONT, FONT_PAL_WHITE, szTemp, 0); + _itoa_s(pet[nSelectPet].def, szTemp, 10); + StockFontBuffer(pActMenuWnd2->x + 222, pActMenuWnd2->y + 40 + 49, FONT_PRIO_FRONT, FONT_PAL_WHITE, szTemp, 0); + _itoa_s(pet[nSelectPet].quick, szTemp, 10); + StockFontBuffer(pActMenuWnd2->x + 222, pActMenuWnd2->y + 40 + 73, FONT_PRIO_FRONT, FONT_PAL_WHITE, szTemp, 0); + } + else + { + nSelectPet = -1; + for (i = 0; i < MAX_PET; i++) + { + // ֻ + if (pet[i].useFlag) + { + nSelectPet = i; + break; + } + } + } + } + else +#endif + { + itemWndFontNo[1] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_IME3, CG_ITEM_WND_JUJUTU_BTN, 2); + // ?? + sprintf_s(moji, "%7d", pc.gold); + StockFontBuffer(pActMenuWnd2->x + 32 + 48 * 3 + 16, pActMenuWnd2->y + 87, FONT_PRIO_FRONT, 0, moji, 0); + // ????? + sprintf_s(moji, "%7d", itemWndDropGold); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + if (Moneyflag == false) + StockFontBuffer(pActMenuWnd2->x + 32 + 48 * 3 + 16, pActMenuWnd2->y + 138, FONT_PRIO_FRONT, 0, moji, 0); +#else + StockFontBuffer(pActMenuWnd2->x + 32 + 48 * 3 + 16, pActMenuWnd2->y + 138, FONT_PRIO_FRONT, 0, moji, 0); +#endif + // ???????? + itemWndFontNo[2] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_IME3, CG_ITEM_WND_GOLD_DROP_BTN_UP + itemWndBtnFlag[2], 2); + // ???????? + itemWndFontNo[3] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_IME3, CG_ITEM_WND_GOLD_INC_BTN_UP + itemWndBtnFlag[3], 2); + // ????????? + itemWndFontNo[4] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_IME3, CG_ITEM_WND_GOLD_DEC_BTN_UP + itemWndBtnFlag[4], 2); + } + } + } + } + } + break; + + case 1: // ӡk????? + + // ????????? + if (pActMenuWnd2 == NULL){ + pActMenuWnd2 = MakeWindowDisp(364, 4, 272, 280, 0, -1); + // ???? + for (i = 0; i < MENU_ITEM_0; i++) itemWndFontNo[i] = -2; + for (i = 0; i < MENU_ITEM_0; i++) itemWndBtnFlag[i] = 0; + jujutuNo = -1; // k??????? + + } + else{ + // ?????????????? + if (pActMenuWnd2->hp > 0){ + x = pActMenuWnd2->x + 74; + y = pActMenuWnd2->y + 208; + // ?????????Ƥ +#ifdef _READ16BITBMP + if (g_bUseAlpha) StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my + 7, DISP_PRIO_MENU, CG_JUJUTU_WND, 1); + else +#endif + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my + 10, DISP_PRIO_MENU, CG_JUJUTU_WND, 1); + // ӡk??? + for (i = 0; i < 5; i++){ + if (HitFontNo == itemWndFontNo[i]){ + // ?????? + char *splitPoint = magic[i].memo; + sprintf_s(moji, "%2d/%2d", magic[i].mp, pc.mp); + StockFontBuffer(pActMenuWnd2->x + 74 + 81, pActMenuWnd2->y + 183, FONT_PRIO_FRONT, 0, moji, 0); + while (1){ + // ????????? + if (strlen(splitPoint) > 22){ + strncpy_s(moji, splitPoint, 22); + moji[22] = NULL; // Z?????? + // u??S???? + if (GetStrLastByte(moji) == 3){ + moji[21] = NULL; + splitPoint += 21; + } + else{ + moji[22] = NULL; + splitPoint += 22; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } + else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } +#if 0 + // ?????? + if( magic[ i ].memo[ 0 ] != NULL ){ + strncpy_s(moji, magic[i].memo, 22); + moji[22] = NULL; + StockFontBuffer(pActMenuWnd2->x + 74, pActMenuWnd2->y + 204, FONT_PRIO_FRONT, 0, moji, 0); + + if (magic[i].memo[22] != NULL){ + strncpy_s(moji, magic[i].memo + 22, 22); + moji[22] = NULL; + StockFontBuffer(pActMenuWnd2->x + 74, pActMenuWnd2->y + 224, FONT_PRIO_FRONT, 0, moji, 0); + } + } +#endif + // ???? + StockDispBuffer(pActMenuWnd2->x + 37, pActMenuWnd2->y + 220, DISP_PRIO_ITEM, pc.item[i].graNo, 0); + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??????ۢK?? + if (magic[i].field == MAGIC_FIELD_BATTLE || magic[i].mp > pc.mp){ + // ??? + play_se(220, 320, 240); + } + else{ // ??u?? + // ??????? + switch (magic[i].target){ + + case MAGIC_TARGET_MYSELF: // ?? + + // ???????????? + if (eventWarpSendFlag == FALSE){ + // ?? + if (bNewServer) + lssproto_MU_send(sockfd, nowGx, nowGy, i, 0); + else + old_lssproto_MU_send(sockfd, nowGx, nowGy, i, 0); + play_se(100, 320, 240); + } + break; + + case MAGIC_TARGET_OTHER: // \????) + jujutuNo = i; + // ????? + play_se(217, 320, 240); + //itemNo = -1; + break; +#if 0 + case MAGIC_TARGET_ALLMYSIDE: // sul + + // ?? + if( bNewServer) + lssproto_MU_send( sockfd, nowGx, nowGy, i, 0 ); + else + old_lssproto_MU_send( sockfd, nowGx, nowGy, i, 0 ); + // ? + play_se( 100, 320, 240 ); + break; + + case MAGIC_TARGET_ALLOTHERSIDE: // ?Dul + + // ?? + if( bNewServer) + lssproto_MU_send( sockfd, nowGx, nowGy, i, 0 ); + else + old_lssproto_MU_send( sockfd, nowGx, nowGy, i, 0 ); + // ? + play_se( 100, 320, 240 ); + break; + + case MAGIC_TARGET_ALL: // u? + + // ?? + if (bNewServer) + lssproto_MU_send(sockfd, nowGx, nowGy, i, 0); + else + old_lssproto_MU_send(sockfd, nowGx, nowGy, i, 0); + // ? + play_se(100, 320, 240); + break; +#endif + } + } + } + } + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == itemWndFontNo[12]){ + // ?????? + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + itemWndNo = 0; + // ???????? + play_se(203, 320, 240); + // k??????? + jujutuNo = -1; + + // ?????????????????? + if (MenuToggleFlag & JOY_CTRL_S){ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ?????????? + DeathMenuAction(); + } + } + // ӡk????? + if (jujutuNo != -1 && MenuToggleFlag & JOY_CTRL_S && statusWndNo == 1){ + // ???? + for (i = 0; i < 11; i++){ + // ?k + if (HitFontNo == statusWndFontNo[i] && eventWarpSendFlag == FALSE){ + // ?? + if (bNewServer) + lssproto_MU_send(sockfd, nowGx, nowGy, jujutuNo, i); + else + old_lssproto_MU_send(sockfd, nowGx, nowGy, jujutuNo, i); + // ? + play_se(100, 320, 240); + // ???? + if (magic[jujutuNo].mp > pc.mp - magic[jujutuNo].mp) jujutuNo = -1;; // ??ۢK?? + + } + } + } + + } + // ???????? + if (pActMenuWnd2 != NULL){ + int flag = FALSE; + int col; + // ?@e + x = pActMenuWnd2->x + 30; + y = pActMenuWnd2->y + 35; + + // Ӥ + for (i = 0; i < 5; i++){ + if (magic[i].useFlag == TRUE){ + col = FONT_PAL_WHITE; // ??u???? + if (jujutuNo == i) col = FONT_PAL_AQUA; // k?? + //cary 2001.12.3 + if (pc.familySprite == 0){ + if ((magic[i].mp * 80 / 100) > pc.mp) col = FONT_PAL_RED; // ??ۢK?? + } + else{ + if (magic[i].mp > pc.mp) col = FONT_PAL_RED; // ??ۢK?? + } + if (magic[i].field == MAGIC_FIELD_BATTLE) col = FONT_PAL_GRAY; // ????? + CenteringStr(magic[i].name, moji, MAGIC_NAME_LEN); + itemWndFontNo[i] = StockFontBuffer(x, y, FONT_PRIO_FRONT, col, moji, 2); y += 28; + flag = TRUE; + } + } + if (flag == FALSE) StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, "û", 0); + // ????????? + itemWndFontNo[12] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, pActMenuWnd2->y + 262 + 10, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + + case 2: // ?????k????? + + // ????????? + if (pActMenuWnd2 == NULL){ + pActMenuWnd2 = MakeWindowDisp(368, 4, 192, 304, 0, -1); + // ???? + for (i = 0; i < MENU_ITEM_0; i++) itemWndFontNo[i] = -2; + for (i = 0; i < MENU_ITEM_0; i++) itemWndBtnFlag[i] = 0; + + } + else{ + // ?????????????? + if (pActMenuWnd2->hp > 0){ + // ?????????Ƥ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_ITEM_WND_SELECT_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ?k??? + for (i = 0; i < 11; i++){ + if (HitFontNo == itemWndFontNo[i] && eventWarpSendFlag == FALSE){ + // ӡk?? + if (jujutuNo != -1){ + // ?? + if (bNewServer) + lssproto_MU_send(sockfd, nowGx, nowGy, jujutuNo, i); + else + old_lssproto_MU_send(sockfd, nowGx, nowGy, jujutuNo, i); + // ? + play_se(100, 320, 240); + // ????????? + if (magic[jujutuNo].mp > pc.mp - magic[jujutuNo].mp){ + // ?????? + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + itemWndNo = 1; + // ???????? + play_se(203, 320, 240); + } + } + else{ // ?????? + //?????? + if (bNewServer) + lssproto_ID_send(sockfd, nowGx, nowGy, itemNo, i); + else + old_lssproto_ID_send(sockfd, nowGx, nowGy, itemNo, i); + // ?????? + play_se(212, 320, 240); + // ?????? + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + itemWndNo = 0; + // ?????????????????? + if (MenuToggleFlag & JOY_CTRL_S){ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ?????????? + DeathMenuAction(); + } + // ???????? + play_se(203, 320, 240); + } + } + } + // ??? + if (HitDispNo == itemWndFontNo[11]){ + // ?????? + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + // ӡk?? + if (jujutuNo != -1) itemWndNo = 1; + else{ + // ???????????? + itemWndNo = 0; + // ?????????????????? + if (MenuToggleFlag & JOY_CTRL_S){ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ?????????? + DeathMenuAction(); + } + } + // ???????? + play_se(203, 320, 240); + } + } + // ???????? + if (pActMenuWnd2 != NULL){ + // ?@e + x = pActMenuWnd2->x + 25; + y = pActMenuWnd2->y + 30; + + // ????????? + // ?q + sprintf_s(moji, "%-16s", pc.name); + itemWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 2); y += 23; + // ??? + for (i = 0; i < 5; i++){ + // ??????????? + if (pet[i].useFlag == TRUE){ + // ?????? + if (pet[i].freeName[0] != NULL) + sprintf_s(moji, "%-16s", pet[i].freeName); + else + sprintf_s(moji, "%-16s", pet[i].name); + itemWndFontNo[i + 1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 2); y += 23; + } + } + y = 183; + // ?? + for (i = 0; i < 5; i++){ + // ???????????????? + if (pc.id != party[i].id && party[i].useFlag == TRUE){ + sprintf_s(moji, "%-16s", party[i].name); + itemWndFontNo[i + 6] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 2); y += 23; + } + } + // ????????? + itemWndFontNo[11] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, pActMenuWnd2->y + 287, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + } + } + + //? ?????????? *******************************************************/ + + if (MenuToggleFlag & JOY_CTRL_M){ +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ + SkillWndflag = false; +#endif + // ?????k??? + switch (mapWndNo){ + + case 0: // ???????? + + // ????????? + if (pActMenuWnd2 == NULL){ + pActMenuWnd2 = MakeWindowDisp(388, 4, 248, 240, 0, -1); + for (i = 0; i < MENU_MAP_0; i++) mapWndFontNo[i] = -2; + + } + else{ + // ?????????????? + if (pActMenuWnd2->hp > 0){ + // ???????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd2->pYobi)->my, DISP_PRIO_MENU, CG_MAP_WND, 0); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == mapWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd2); +#ifdef _MONEYINPUT //Syu ADD ֶǮ + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif + pActMenuWnd2 = NULL; + // ??????? + MenuToggleFlag ^= JOY_CTRL_M; + // ???????? + play_se(203, 320, 240); + } + } + + // ???????? + if (pActMenuWnd2 != NULL){ + // ?@e + x = pActMenuWnd2->x + 61; + y = pActMenuWnd2->y + 186; + + // ????q + StockFontBuffer(pActMenuWnd2->x + 22, pActMenuWnd2->y + 31, FONT_PRIO_FRONT, 0, nowFloorName, 0); + + // ????????? + sprintf_s(moji, " %3d", nowGx); + StockFontBuffer(x, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); + sprintf_s(moji, " %3d", nowGy); + StockFontBuffer(x + 73, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, moji, 0); y += 36; + // ????? + mapWndFontNo[0] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd2->pYobi)->mx, y, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + } + } + } + break; + } + } + + //? ?????????? *******************************************************/ + + if (MenuToggleFlag & JOY_CTRL_E){ + // ?????k??? + switch (mailWndNo){ + + case MAIL_WND_VIEW: // ??????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(4, 4, 272, 440, 0, -1); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + // ???????????k??S??????????? + for (i = 0; i < MAX_ADR_BOOK; i++){ + int j; + // ???????? + for (j = 0; j < MAIL_MAX_HISTORY; j++){ + // t???? + if (MailHistory[i].noReadFlag[j] >= TRUE){ + // ???k????? + mailViewWndPageNo = i / MAX_ADR_BOOK_COUNT; + i = MAX_ADR_BOOK; + break; + } + } + } + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + static int nowDelNo; + // ??????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_MAIL_WND, 1); + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK && pActYesNoWnd == NULL){ + + int nowNo = mailViewWndPageNo * MAX_ADR_BOOK_COUNT; + // ?????? + for (i = 0; i < 12; i += 3, nowNo++){ + // q?????????V??????? +#ifdef _EXTEND_AB + if (addressBook[nowNo].useFlag == TRUE + || addressBook[nowNo].useFlag == 2 + || addressBook[nowNo].useFlag == 3){ +#else + if (addressBook[nowNo].useFlag == TRUE){ +#endif + if (HitFontNo == mailWndFontNo[i]){ + mailHistoryWndSelectNo = nowNo; + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????? + DeathLetterAction(); + // ???????? + mailWndNo = MAIL_WND_HISTORY; + // ???????? + play_se(202, 320, 240); + } + + // ????? + if (HitDispNo == mailWndFontNo[i + 1]){ + // ?_???????? + if (pActYesNoWnd == NULL){ + // ???????? + play_se(202, 320, 240); + // ?_????????? + pActYesNoWnd = MakeWindowDisp(pActMenuWnd->x + 42, i * 32 + 54, 176, 56, 0, 4); + + // ????k???? + nowDelNo = nowNo; + } + } + // ?????? + if (HitDispNo == mailWndFontNo[i + 2]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????? + DeathLetterAction(); + // ???????? + InitMailSendFlag(); + // ?????????? + mailWndSendFlag[nowNo] = TRUE; + // ?????k??????? + mailWndNoBak = mailWndNo; + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ?G????????? + mailWndNo = MAIL_WND_SEND; + } + else{ + // ???????k?????? + if (pc.mailPetNo != -1){ + // k?????? + mailWndNo = MAIL_WND_SELECT; + } + else{ + // ?G????????? + mailWndNo = MAIL_WND_SEND; + } + } + // ???????? + play_se(202, 320, 240); + } + } + } + // ??? + if (HitDispNo == mailWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????? + DeathLetterAction(); + MenuToggleFlag ^= JOY_CTRL_E; + // ???????? + play_se(203, 320, 240); + } + } + + // q??? + if ((HitDispNo == mailWndFontNo[26] || joy_con[0] & JOY_A) && pActYesNoWnd == NULL){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + mailViewWndPageNo--; // ????? + if (mailViewWndPageNo < 0) mailViewWndPageNo = MAX_ADR_BOOK_PAGE - 1; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[26] = TRUE; + // ????????? + DeathLetterAction(); + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && mailWndBtnFlag[26] == TRUE){ + // ???? + mailWndBtnFlag[26] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[26] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[26] = FALSE; + } + // ??? + if ((HitDispNo == mailWndFontNo[27] || joy_con[0] & JOY_B) && pActYesNoWnd == NULL){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + mailViewWndPageNo++; // ?????? + if (mailViewWndPageNo >= MAX_ADR_BOOK_PAGE) mailViewWndPageNo = 0; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[27] = TRUE; + // ????????? + DeathLetterAction(); + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && mailWndBtnFlag[27] == TRUE){ + // ???? + mailWndBtnFlag[27] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[27] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[27] = FALSE; + } + + // ???????? + if (pActMenuWnd != NULL){ + int nowNo = mailViewWndPageNo * MAX_ADR_BOOK_COUNT; + // ?@e + x = pActMenuWnd->x; + y = pActMenuWnd->y; + + // ????????????????????k? + int graNo[7] = { CG_MAIL_WND_OFF_LINE_BTN, + CG_MAIL_WND_ON_LINE_SUN_BTN, + CG_MAIL_WND_ON_LINE_MOON_BTN, + CG_MAIL_WND_ON_LINE_MERCURY_BTN, + CG_MAIL_WND_ON_LINE_VINUS_BTN, + CG_MAIL_WND_ON_LINE_EARTH_BTN, + CG_MAIL_WND_ON_LINE_MARS_BTN + }; + + for (i = 0; i < 12; i += 3, nowNo++){ + // q???? +#ifdef _EXTEND_AB + if (addressBook[nowNo].useFlag == TRUE + || addressBook[nowNo].useFlag == 2 + || addressBook[nowNo].useFlag == 3){ +#else + if (addressBook[nowNo].useFlag == TRUE){ +#endif + int j = 0; + // ???????? + for (j = 0; j < MAIL_MAX_HISTORY; j++){ + // ?????????? + if (pActLetter[i / 3] == NULL){ + if (MailHistory[nowNo].noReadFlag[j] >= TRUE){ + // ??????????? + pActLetter[i / 3] = MakeAnimDisp(x - 20, y + 38, SPR_mail, ANIM_DISP_LETTER_MOVE); + } + } + } + // ? +#ifdef _EXTEND_AB + if (addressBook[nowNo].useFlag == 2) + StockFontBuffer(x + 15, y + 85, FONT_PRIO_FRONT, 5, "ʹ", 0); + if (addressBook[nowNo].useFlag == 3) + StockFontBuffer(x + 15, y + 85, FONT_PRIO_FRONT, 5, "", 0); +#endif + StockDispBuffer(x + 44, y + 68, DISP_PRIO_IME3, addressBook[nowNo].graNo, 0); + CenteringStr(addressBook[nowNo].name, moji, CHAR_NAME_LEN); + mailWndFontNo[i] = StockFontBuffer(x + 80, y + 30, FONT_PRIO_FRONT, 0, moji, 2); + sprintf_s(moji, "%3d", addressBook[nowNo].level); + StockFontBuffer(x + 104, y + 60, FONT_PRIO_FRONT, 0, moji, 0); +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + sprintf_s(moji, "%8s", addressBook[nowNo].planetname); + StockFontBuffer(x + 198, y + 30, FONT_PRIO_FRONT, 5, moji, 0); +#endif + // +#ifdef _TRANS_6 + if (addressBook[nowNo].transmigration < 0 || addressBook[nowNo].transmigration >= 7) addressBook[nowNo].transmigration = 0; +#else + if (addressBook[nowNo].transmigration < 0 || addressBook[nowNo].transmigration >= 6) addressBook[nowNo].transmigration = 0; +#endif + StockFontBuffer(x + 152, y + 59, FONT_PRIO_FRONT, FONT_PAL_AQUA, TransmigrationStr[addressBook[nowNo].transmigration], 0); + sprintf_s(moji, "%8d", addressBook[nowNo].dp); + StockFontBuffer(x + 103, y + 88, FONT_PRIO_FRONT, 0, moji, 0); + StockDispBuffer(x + 225, y + 60, DISP_PRIO_IME3, graNo[(addressBook[nowNo].onlineFlag == 0) ? 0 : 1], 0); + mailWndFontNo[i + 2] = StockDispBuffer(x + 225, y + 80, DISP_PRIO_IME3, CG_MAIL_WND_MAIL_BTN, 2); + mailWndFontNo[i + 1] = StockDispBuffer(x + 225, y + 100, DISP_PRIO_IME3, CG_MAIL_WND_DELETE_BTN, 2); + + } +#ifdef _EXTEND_AB + else{ + if (nowNo == MAX_ADR_BOOK - 1) + { + StockFontBuffer(x + 100, y + 30, FONT_PRIO_FRONT, FONT_PAL_RED, "ٻ", 0); + } + } +#endif + y += 96; + } + // q??? + mailWndFontNo[26] = StockDispBuffer(pActMenuWnd->x + 25 + 28 - 8, pActMenuWnd->y + 421, DISP_PRIO_IME3, CG_PREV_BTN + mailWndBtnFlag[26], 2); + // ???k? + sprintf_s(moji, "%2d", mailViewWndPageNo + 1); + StockFontBuffer(pActMenuWnd->x + 46 + 28 - 8, pActMenuWnd->y + 413, FONT_PRIO_FRONT, 0, moji, 0); + // ???? + mailWndFontNo[27] = StockDispBuffer(pActMenuWnd->x + 75 + 28, pActMenuWnd->y + 421, DISP_PRIO_IME3, CG_NEXT_BTN + mailWndBtnFlag[27], 2); + mailWndFontNo[19] = StockDispBuffer(pActMenuWnd->x + 220 - 28, pActMenuWnd->y + 421, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + } + + // ?_???????? + if (pActYesNoWnd != NULL){ + // ???? + if (((WINDOW_DISP *)pActYesNoWnd->pYobi)->yesNoResult == TRUE){ + // ?????? + if (bNewServer) + lssproto_DAB_send(sockfd, nowDelNo); + else + old_lssproto_DAB_send(sockfd, nowDelNo); + play_se(217, 320, 240); + // ?_?????? + DeathAction(pActYesNoWnd); + pActYesNoWnd = NULL; + // ???????? + play_se(203, 320, 240); + } + else + // ????? + if (((WINDOW_DISP *)pActYesNoWnd->pYobi)->yesNoResult == FALSE){ + // ?_?????? + DeathAction(pActYesNoWnd); + pActYesNoWnd = NULL; + // ???????? + play_se(203, 320, 240); + } + } + } + + } + break; + + case MAIL_WND_SELECT: // k????? + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(40, 40, 3, 3, NULL, 0); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + // ?????????? + for (i = 0; i < 5; i++){ + // ???????????? + if (pet[i].useFlag == FALSE){ + // ????? + if (i == pc.mailPetNo){ + pc.mailPetNo = -1; + // ???????? + saveUserSetting(); + } + } + } + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ?G????? + if (HitFontNo == mailWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ?G?????????? + mailWndNo = MAIL_WND_SEND; + // ???????? + play_se(202, 320, 240); + } + // ???????? + if (HitFontNo == mailWndFontNo[1]){ +#ifdef _TAIKEN + // ??? + play_se(220, 320, 240); + // ??????? + sprintf_s(moji, "治ѡ"); + // ?????????????????? + StockChatBufferLine( moji, FONT_PAL_WHITE ); +#else +#ifdef _STREET_VENDOR + if (pc.iOnStreetVendor == 1){ + play_se(220, 320, 240); + StockChatBufferLine("̯вʹóʼ", FONT_PAL_RED); + } + else +#endif +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000002) + StockChatBufferLine("רı", FONT_PAL_RED); + else if (pc.iTheaterMode & 0x00000001) + StockChatBufferLine("רĿ", FONT_PAL_RED); + else +#endif + // ??????k????? + if (pc.mailPetNo != -1){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????????? + mailWndNo = MAIL_WND_PET_SEND; + // ???????? + play_se(202, 320, 240); + } + else{ + // ??? + play_se(220, 320, 240); + } +#endif + } + // ??? + if (HitDispNo == mailWndFontNo[2]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???????? + mailWndNo = MAIL_WND_VIEW; + // ???????? + play_se(203, 320, 240); + } + } + + // ???????? + if (pActMenuWnd != NULL){ + int color = FONT_PAL_WHITE; + + // ??????k????? + if (pc.mailPetNo == -1) + color = FONT_PAL_RED; + + // ?@e + x = pActMenuWnd->x + 28; + y = pActMenuWnd->y + 32; + + // ????????? + mailWndFontNo[0] = StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, " ͨ ", 2); y += 32; + mailWndFontNo[1] = StockFontBuffer(x, y, FONT_PRIO_FRONT, color, " ", 2); y += 48; + mailWndFontNo[2] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, y, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + + case MAIL_WND_SEND: // ?G????????? + + // ????????? + if (pActMenuWnd == NULL){ + pActMenuWnd = MakeWindowDisp(4, 4, 272, 304, 0, -1); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + mailPetSendWndPageNo = mailViewWndPageNo; // ?G?????k???? + + MailStr.len = 140; + // ???? + MailStr.lineLen = 28; + // ????? + MailStr.lineDist = 20; + // ??? + MailStr.color = 0; + // ???? + MailStr.x = pActMenuWnd->x + 12; + MailStr.y = pActMenuWnd->y + 280 - 136; + // ????I?? + MailStr.fontPrio = FONT_PRIO_FRONT; + + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ?????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_MAIL_WND_SEND_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + int nowNo = mailPetSendWndPageNo * MAX_ADR_BOOK_COUNT; + // ?????? + for (i = 0; i < MAX_ADR_BOOK_COUNT; i++){ + // ??k??? + if (HitFontNo == mailWndFontNo[i]){ + // q?????? +#ifdef _EXTEND_AB + if (addressBook[nowNo + i].useFlag == TRUE + || addressBook[nowNo + i].useFlag == 2 + || addressBook[nowNo + i].useFlag == 3){ +#else ???V??????? + if (addressBook[nowNo + i].useFlag == TRUE){ +#endif + // k????????? + if (mailWndSendFlag[nowNo + i] == FALSE) mailWndSendFlag[nowNo + i] = TRUE; + else mailWndSendFlag[nowNo + i] = FALSE; + // ????? + play_se(217, 320, 240); + } + } + + } + // ??? + if (HitDispNo == mailWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // q????????? + mailWndNo = mailWndNoBak; + // ???????? + play_se(203, 320, 240); + // V???????? + GetKeyInputFocus(&MyChatBuffer); + } + } + // ???? + if (HitDispNo == mailWndFontNo[18]){ + // ??????????????????0.5??? + if (mouse.onceState & MOUSE_LEFT_CRICK && ItemUseTime < TimeGetTime() - 5000){ + int flag = FALSE; + // ????? + ItemUseTime = TimeGetTime(); + // ??k???????? + for (i = 0; i < MAX_ADR_BOOK; i++){ + if (mailWndSendFlag[i] == TRUE) flag = TRUE; + } + // ?????? + if (MailStr.buffer[0] != NULL && flag == TRUE){ + // ????? + for (i = 0; i < MAX_ADR_BOOK; i++){ + // ???????? + if (mailWndSendFlag[i] == TRUE){ + char moji2[256]; + // ???????? + strcpy(moji2, MailStr.buffer); + // ??????? + makeEscapeString(moji2, moji, sizeof(moji)); + // ???? + if (bNewServer) + lssproto_MSG_send(sockfd, i, moji, FONT_PAL_WHITE); + else + old_lssproto_MSG_send(sockfd, i, moji, FONT_PAL_WHITE); + + } + } + play_se(101, 320, 240); + mailWndBtnFlag[18] = TRUE; + } + else{ + // ??? + play_se(220, 320, 240); + } + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && mailWndBtnFlag[18] == TRUE){ + // ???? + mailWndBtnFlag[18] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[18] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[18] = FALSE; + } + + // q??? + if (HitDispNo == mailWndFontNo[16] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + mailPetSendWndPageNo--; // ????? + if (mailPetSendWndPageNo < 0) mailPetSendWndPageNo = MAX_ADR_BOOK_PAGE - 1; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[16] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && mailWndBtnFlag[16] == TRUE){ + // ???? + mailWndBtnFlag[16] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + // ??? + if (HitDispNo == mailWndFontNo[17] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + mailPetSendWndPageNo++; // ?????? + if (mailPetSendWndPageNo >= MAX_ADR_BOOK_PAGE) mailPetSendWndPageNo = 0; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[17] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && mailWndBtnFlag[17] == TRUE){ + // ???? + mailWndBtnFlag[17] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + + // ?????? + if (HitDispNo == mailWndFontNo[14]){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? ??@e + MailStr.buffer[0] = NULL; + MailStr.cnt = 0; + MailStr.cursor = 0; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[14] = TRUE; + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && mailWndBtnFlag[14] == TRUE){ + // ???? + mailWndBtnFlag[14] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[14] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[14] = FALSE; + } + // k?????? + if (HitDispNo == mailWndFontNo[15]){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ???????? + InitMailSendFlag(); + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[15] = TRUE; + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && mailWndBtnFlag[15] == TRUE){ + // ???? + mailWndBtnFlag[15] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[15] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[15] = FALSE; + } + + // ???????? + if (pActMenuWnd != NULL){ + int nowNo = mailPetSendWndPageNo * MAX_ADR_BOOK_COUNT; + int color; + + // ?@e + x = pActMenuWnd->x; + y = pActMenuWnd->y; + // V??????x + GetKeyInputFocus(&MailStr); + // ??? + StockFontBuffer2(&MailStr); + + for (i = 0; i < MAX_ADR_BOOK_COUNT; i++){ + // q?????????V??????? +#ifdef _EXTEND_AB + if (addressBook[nowNo + i].useFlag == TRUE + || addressBook[nowNo + i].useFlag == 2 + || addressBook[nowNo + i].useFlag == 3){ +#else + if (addressBook[nowNo + i].useFlag == TRUE){ +#endif + color = FONT_PAL_GRAY; // ????? + // ??????? + if (addressBook[nowNo + i].onlineFlag > 0){ + // ? + color = FONT_PAL_WHITE; + } + // k?????? + if (mailWndSendFlag[nowNo + i] == TRUE){ + // ? + color = FONT_PAL_AQUA; + } + // q + CenteringStr(addressBook[nowNo + i].name, moji, CHAR_NAME_LEN); + mailWndFontNo[i] = StockFontBuffer(x + 111, y + 177 - 136, FONT_PRIO_FRONT, color, moji, 2); + + } + y += 23; + } + // k?????? + mailWndFontNo[15] = StockDispBuffer(pActMenuWnd->x + 51, pActMenuWnd->y + 211 - 136, DISP_PRIO_IME3, CG_MAIL_WND_CLEAR_BTN_UP + mailWndBtnFlag[15], 2); + // q??? + mailWndFontNo[16] = StockDispBuffer(pActMenuWnd->x + 26 - 8 + 4, pActMenuWnd->y + 241 - 132, DISP_PRIO_IME3, CG_PREV_BTN + mailWndBtnFlag[16], 2); + // ???k? + sprintf_s(moji, "%2d", mailPetSendWndPageNo + 1); + StockFontBuffer(pActMenuWnd->x + 47 - 8 + 4, pActMenuWnd->y + 233 - 132, FONT_PRIO_FRONT, 0, moji, 0); + // ???? + mailWndFontNo[17] = StockDispBuffer(pActMenuWnd->x + 76 + 4, pActMenuWnd->y + 241 - 132, DISP_PRIO_IME3, CG_NEXT_BTN + mailWndBtnFlag[17], 2); + // ?????? + mailWndFontNo[14] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 60, pActMenuWnd->y + 390 - 136, DISP_PRIO_IME3, CG_MAIL_WND_CLEAR_BTN_UP + mailWndBtnFlag[14], 2); + // ???? + mailWndFontNo[18] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx - 60, pActMenuWnd->y + 421 - 136, DISP_PRIO_IME3, CG_SEND_BTN + mailWndBtnFlag[18] * 75, 2); + // ?? + mailWndFontNo[19] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 60, pActMenuWnd->y + 421 - 136, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + + case MAIL_WND_PET_SEND: // ???????????? + + // ????????? + if (pActMenuWnd == NULL){ + pActMenuWnd = MakeWindowDisp(4, 4, 272, 440, 0, -1); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + mailPetSendWndPageNo = mailViewWndPageNo; // ?G?????k???? + MailStr.len = MAIL_STR_LEN; + // ???? + MailStr.lineLen = 28; + // ????? + MailStr.lineDist = 20; + // ??? + MailStr.color = 0; + // ???? + MailStr.x = pActMenuWnd->x + 12; + MailStr.y = pActMenuWnd->y + 280; + // ????I?? + MailStr.fontPrio = FONT_PRIO_FRONT; + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ???????????????? + if (pActPet == NULL){ + // ????????? + pActPet = MakeAnimDisp(pActMenuWnd->x + 190, pActMenuWnd->y + 120, pet[pc.mailPetNo].graNo, ANIM_DISP_PET); + } + // ???????????????????k?????? + if (pActMailItem == NULL && mailItemNo != -1){ + // ?????????? + pActMailItem = MakeAnimDisp(pActMenuWnd->x + 56, pActMenuWnd->y + 96, pc.item[mailItemNo].graNo, ANIM_DISP_PET_ITEM); + pActMailItem->atr |= ACT_ATR_INFO; + pActMailItem->atr |= ACT_ATR_TYPE_ITEM; + pActMailItem->dispPrio = DISP_PRIO_DRAG; + // ??????? + strcpy(pActMailItem->name, pc.item[mailItemNo].name); + } + // ?????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_MAIL_WND_PET_SEND_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + int nowNo = mailPetSendWndPageNo * MAX_ADR_BOOK_COUNT; + // ?????? + for (i = 0; i < MAX_ADR_BOOK_COUNT; i++){ + // ??k???????????????????? + if (HitFontNo == mailWndFontNo[i]){ + // q???????? +#ifdef _EXTEND_AB + if (addressBook[nowNo + i].useFlag == TRUE + || addressBook[nowNo + i].useFlag == 2 + || addressBook[nowNo + i].useFlag == 3){ +#else ?V??????? + if (addressBook[nowNo + i].useFlag == TRUE){ +#endif + int j, flag = FALSE; + // ??k???????? + for (j = 0; j < MAX_ADR_BOOK; j++){ + if (mailWndSendFlag[j] == TRUE) flag = TRUE; + } + + // k??????? + if (flag == FALSE){ + mailWndSendFlag[nowNo + i] = TRUE; + // ????? + play_se(217, 320, 240); + } + else{ // ??k?????? + // k???????????????? + if (mailWndSendFlag[nowNo + i] == TRUE){ + mailWndSendFlag[nowNo + i] = FALSE; + // ????? + play_se(217, 320, 240); + } + else{ // k????????????????? + // ??? + play_se(220, 320, 240); + } + } + } + } + } + // ??? + if (HitDispNo == mailWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ???????? + mailWndNo = MAIL_WND_VIEW; + // ???????? + play_se(203, 320, 240); + // V???????? + GetKeyInputFocus(&MyChatBuffer); + } + // ??????? + if (HitDispNo == mailWndFontNo[15]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // q????????? + mailWndNo = MAIL_WND_ITEM; + // ???????? + play_se(202, 320, 240); + // V???????? + GetKeyInputFocus(&MyChatBuffer); + } + } + // ???? + if (HitDispNo == mailWndFontNo[18]){ + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + int flag = FALSE; + // ??k???????? + for (i = 0; i < MAX_ADR_BOOK; i++){ + if (mailWndSendFlag[i] == TRUE) flag = TRUE; + } + // ?????? + if (MailStr.buffer[0] != NULL && flag == TRUE + && pActPet != NULL + && pActPet->actNo == ANIM_DISP_PET + && pc.mailPetNo != ItemMixPetNo){ + for (i = 0; i < MAX_ADR_BOOK; i++){ + // ???????? + if (mailWndSendFlag[i] == TRUE){ + // Terry add fix can send mail to offline character 2004/2/5 + if (addressBook[i].onlineFlag == 0) StockChatBufferLine("Ҳϣ", FONT_PAL_RED); + else + // end + { + char moji2[256]; + // ???????? + strcpy(moji2, MailStr.buffer); + // ??????? + makeEscapeString(moji2, moji, sizeof(moji)); + // ??????? + if (bNewServer) + lssproto_PMSG_send(sockfd, i, pc.mailPetNo, mailItemNo, moji2, FONT_PAL_WHITE); + else + old_lssproto_PMSG_send(sockfd, i, pc.mailPetNo, mailItemNo, moji2, FONT_PAL_WHITE); + pc.mailPetNo = -1; + // ?????????? + ItemBuffer[mailItemNo].mixFlag = 0; + // ???????? + saveUserSetting(); + // ???????????????? + if (pActPet != NULL){ + // ?????? + pActPet->actNo = 1; + } + } + } + } + play_se(101, 320, 240); + mailWndBtnFlag[18] = TRUE; + } + else{ + // ??? + play_se(220, 320, 240); + } + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && mailWndBtnFlag[18] == TRUE){ + // ???? + mailWndBtnFlag[18] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[18] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[18] = FALSE; + } + + // q??? + if (HitDispNo == mailWndFontNo[16] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + mailPetSendWndPageNo--; // ????? + if (mailPetSendWndPageNo < 0) mailPetSendWndPageNo = MAX_ADR_BOOK_PAGE - 1; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[16] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && mailWndBtnFlag[16] == TRUE){ + // ???? + mailWndBtnFlag[16] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + // ??? + if (HitDispNo == mailWndFontNo[17] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + mailPetSendWndPageNo++; // ?????? + if (mailPetSendWndPageNo >= MAX_ADR_BOOK_PAGE) mailPetSendWndPageNo = 0; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[17] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && mailWndBtnFlag[17] == TRUE){ + // ???? + mailWndBtnFlag[17] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + + // ?????? + if (HitDispNo == mailWndFontNo[14]){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? ??@e + MailStr.buffer[0] = NULL; + MailStr.cnt = 0; + MailStr.cursor = 0; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[14] = TRUE; + } + // ????????? + if (mouse.state & MOUSE_LEFT_CRICK && mailWndBtnFlag[14] == TRUE){ + // ???? + mailWndBtnFlag[14] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[14] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[14] = FALSE; + } + + // ???????? + if (pActMenuWnd != NULL){ + int nowNo = mailPetSendWndPageNo * MAX_ADR_BOOK_COUNT; + int color; + + // ?@e + x = pActMenuWnd->x; + y = pActMenuWnd->y; + // V??????x + GetKeyInputFocus(&MailStr); + + if (pet[pc.mailPetNo].freeName[0] == NULL){ + CenteringStr(pet[pc.mailPetNo].name, moji, PET_NAME_LEN); + } + else{ + CenteringStr(pet[pc.mailPetNo].freeName, moji, PET_NAME_LEN); + } + StockFontBuffer(x + 120, y + 14, FONT_PRIO_FRONT, 0, moji, 0); + StockFontBuffer2(&MailStr); + for (i = 0; i < MAX_ADR_BOOK_COUNT; i++){ + // q?????????V??????? +#ifdef _EXTEND_AB + if (addressBook[nowNo + i].useFlag == TRUE + || addressBook[nowNo + i].useFlag == 2 + || addressBook[nowNo + i].useFlag == 3){ +#else + if (addressBook[nowNo + i].useFlag == TRUE){ +#endif + color = FONT_PAL_GRAY; // ????? + // ??????? + if (addressBook[nowNo + i].onlineFlag > 0){ + // ? + color = FONT_PAL_WHITE; + } + // k?????? + if (mailWndSendFlag[nowNo + i] == TRUE){ + // ? + color = FONT_PAL_AQUA; + } + // q + CenteringStr(addressBook[nowNo + i].name, moji, CHAR_NAME_LEN); + mailWndFontNo[i] = StockFontBuffer(x + 111, y + 177, FONT_PRIO_FRONT, color, moji, 2); + + } + y += 23; + } + // ??????? + mailWndFontNo[15] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_IME3, CG_MAIL_WND_ITEM_BTN, 2); + // q??? + mailWndFontNo[16] = StockDispBuffer(pActMenuWnd->x + 25 - 8 + 4, pActMenuWnd->y + 241, DISP_PRIO_IME3, CG_PREV_BTN + mailWndBtnFlag[16], 2); + // ???k? + sprintf_s(moji, "%2d", mailPetSendWndPageNo + 1); + StockFontBuffer(pActMenuWnd->x + 46 - 8 + 4, pActMenuWnd->y + 233, FONT_PRIO_FRONT, 0, moji, 0); + // ???? + mailWndFontNo[17] = StockDispBuffer(pActMenuWnd->x + 75 + 4, pActMenuWnd->y + 241, DISP_PRIO_IME3, CG_NEXT_BTN + mailWndBtnFlag[17], 2); + // ?????? + mailWndFontNo[14] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 60, pActMenuWnd->y + 390, DISP_PRIO_IME3, CG_MAIL_WND_CLEAR_BTN_UP + mailWndBtnFlag[14], 2); + // ???? + mailWndFontNo[18] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx - 60, pActMenuWnd->y + 421, DISP_PRIO_IME3, CG_SEND_BTN + mailWndBtnFlag[18] * 75, 2); + // ?? + mailWndFontNo[19] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx + 60, pActMenuWnd->y + 421, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + + case MAIL_WND_ITEM: // ????k????? + // ????????? + if (pActMenuWnd == NULL){ +#ifdef _NEW_ITEM_ + ҳ = 0; +#endif + pActMenuWnd = MakeWindowDisp(4, 30, 271, 281, 0, -1); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + mailSendWndPageNo = 0; // ?????k???? + // ?????????? + InitItem(pActMenuWnd->x, pActMenuWnd->y - 1, FALSE); + // ??????????? + if (MenuToggleFlag & JOY_CTRL_I && itemWndNo == 0){ + // ??????????? + MenuToggleFlag &= ~JOY_CTRL_I; + DeathMenuAction2(); + } + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_IME3, CG_ITEM_WND_1, 1); + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my-80, DISP_PRIO_IME3, CG_BTL_ITEM_WND_TITLE, 1); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == mailWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???????? + mailWndNo = MAIL_WND_PET_SEND; + // ???????? + play_se(203, 320, 240); + } + } + // ???????? + if (pActMenuWnd != NULL){ + // ?@e + x = pActMenuWnd->x + 16; + y = pActMenuWnd->y + 191 + 6; +#ifdef _NEW_ITEM_ + for (i = 0; i < 3; i++){ + if (i == ҳ){ + StockDispBuffer(287, 39 + i * 56, DISP_PRIO_BOX2, 55223 + i, 1); + } + else{ + BOOL flg = FALSE; + if (i){ + if (pc.״̬ & 1 << i){ + flg = TRUE; + } + } + else flg = TRUE; + if (flg){ + StockDispBuffer(271 + 10, 39 + i * 56, DISP_PRIO_IME3, 55226 + i, 1); + if (MakeHitBox(261 + 10, 11 + i * 56, 281 + 10, 8 + i * 56 + 60, DISP_PRIO_IME3)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ҳ = i; + } + } + } + else StockDispBuffer(271 + 10, 39 + i * 56, DISP_PRIO_IME3, 55229 + i, 1); + } + } +#endif + for (i = MAX_ITEM - 1; i >= MAX_ITEMSTART; i--){ +#ifdef _NEW_ITEM_ + //ʼ + int ʼ = MAX_ITEMSTART + MAX_MAXHAVEITEM*ҳ; + int ߽ = ʼ + MAX_MAXHAVEITEM; + if (i >= MAX_ITEMSTART){ + if (i < ʼ || i >= ߽) continue; + } +#endif + if (MakeHitBox(ItemBuffer[i].defX - 24, ItemBuffer[i].defY - 24 - 160, + ItemBuffer[i].defX + 25, ItemBuffer[i].defY + 23 - 160, DISP_PRIO_IME4) == TRUE){ + // ????????????? + if (pc.item[i].useFlag == TRUE){ + // ?????? + char *splitPoint = pc.item[i].memo; + int color = pc.item[i].color; + + // ????????? + if (pc.level < pc.item[i].level) color = FONT_PAL_RED; + // ?????q + StockFontBuffer(pActMenuWnd->x + 16, pActMenuWnd->y + 332 - 160 - 1, FONT_PRIO_FRONT, color, pc.item[i].name, 0); + // ?????C + // ????? + while (1){ + // ????????? + if (strlen(splitPoint) > 28){ + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; // Z?????? + // u??S???? + if (GetStrLastByte(moji) == 3){ + moji[27] = NULL; + splitPoint += 27; + } + else{ + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + } + else{ + strcpy(moji, splitPoint); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + } + + // ?????????????? + if (mouse.onceState & MOUSE_LEFT_DBL_CRICK){ + if (pc.item[i].useFlag == TRUE && pc.item[i].sendFlag & ITEM_FLAG_PET_MAIL){ + mailItemNo = i; // ????k??? + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ???????? + mailWndNo = MAIL_WND_PET_SEND; + // ???????? + play_se(203, 320, 240); + // V???????? + GetKeyInputFocus(&MyChatBuffer); + } + else{ + // ??? + play_se(220, 320, 240); + } + } + } + if (pc.item[i].useFlag == TRUE){ + // ???? + StockDispBuffer(ItemBuffer[i].defX, ItemBuffer[i].defY - 160, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + } + } + // ????????? + if (pActMenuWnd != NULL){ + // ????????? + mailWndFontNo[19] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, pActMenuWnd->y + 262, DISP_PRIO_IME4, CG_CLOSE_BTN, 2); + } + } + } + } + break; + + case MAIL_WND_HISTORY: // ??????? + // ????????? + if (pActMenuWnd == NULL){ + pActMenuWnd = MakeWindowDisp(4, 4, 272, 424, 0, -1); + // ???Re??? + for (i = 0; i < MENU_MAIL_0; i++) mailWndFontNo[i] = -2; + + // ??????@e??k??t????k??? + // ????? + for (mailHistoryWndPageNo = MAIL_MAX_HISTORY - 1; mailHistoryWndPageNo > 0; mailHistoryWndPageNo--){ + // ???????? + if (mailHistoryWndPageNo < 0) mailHistoryWndPageNo = MAIL_MAX_HISTORY - 1; + // ??????k? + mailHistoryWndNowPageNo = (MailHistory[mailHistoryWndSelectNo].newHistoryNo + mailHistoryWndPageNo) % MAIL_MAX_HISTORY; + // t??????????I?? + if (MailHistory[mailHistoryWndSelectNo].noReadFlag[mailHistoryWndNowPageNo] >= TRUE) break; + } +#if 0 + // ???????????????? + if( pActPet == NULL ){ + // ????????? + pActPet = MakeAnimDisp( pActMenuWnd->x - 204, pActMenuWnd->y + 160, pet[ pc.mailPetNo ].graNo, ANIM_DISP_PET_RECIEVE ); + pActPet->atr |= ACT_ATR_INFO; + pActPet->atr |= ACT_ATR_TYPE_PET; + pActPet->level = 32; + strcpy( pActPet->name, "Գ" ); + } + // ????????????????????????? + if (pActMailItem == NULL && MailHistory[mailHistoryWndSelectNo].itemGraNo[mailHistoryWndNowPageNo] != -1){ + // ?????????? + pActMailItem = MakeAnimDisp(pActMenuWnd->x - 204, pActMenuWnd->y + 128, pc.item[5].graNo, ANIM_DISP_PET_ITEM); + pActMailItem->atr |= ACT_ATR_INFO; + pActMailItem->atr |= ACT_ATR_TYPE_ITEM; + pActMailItem->dispPrio = DISP_PRIO_DRAG; + // ??????? + strcpy(pActMailItem->name, ""); + } +#endif + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + static int nowDelNo; + // ??????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_MAIL_WND_HISTORY_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ?????? + if (HitDispNo == mailWndFontNo[18]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????? + DeathLetterAction(); + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ?????k??????? + mailWndNoBak = mailWndNo; + // ???????? + InitMailSendFlag(); + // ?????????? + mailWndSendFlag[mailHistoryWndSelectNo] = TRUE; + // Pf??? + if (ProcNo == PROC_BATTLE){ + // ?G????????? + mailWndNo = MAIL_WND_SEND; + } + else{ + // ???????k?????? + if (pc.mailPetNo != -1){ + // k?????? + mailWndNo = MAIL_WND_SELECT; + } + else{ + // ?G????????? + mailWndNo = MAIL_WND_SEND; + } + } + // ???????? + play_se(202, 320, 240); + } + // ??? + if (HitDispNo == mailWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ????????? + DeathLetterAction(); + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ???????? + mailWndNo = MAIL_WND_VIEW; + // ???????? + play_se(203, 320, 240); + } + } + // q??? + if (HitDispNo == mailWndFontNo[16] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + mailHistoryWndPageNo--; // ????? + if (mailHistoryWndPageNo < 0) mailHistoryWndPageNo = MAIL_MAX_HISTORY - 1; + // ????????? + DeathLetterAction(); + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[16] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && mailWndBtnFlag[16] == TRUE){ + // ???? + mailWndBtnFlag[16] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[16] = FALSE; + } + // ??? + if (HitDispNo == mailWndFontNo[17] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + mailHistoryWndPageNo++; // ?????? + if (mailHistoryWndPageNo >= MAIL_MAX_HISTORY) mailHistoryWndPageNo = 0; + // ????????? + DeathLetterAction(); + // ???? + DeathAction(pActPet); + pActPet = NULL; + // ????? + DeathAction(pActMailItem); + pActMailItem = NULL; + // ????? + play_se(217, 320, 240); + mailWndBtnFlag[17] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && mailWndBtnFlag[17] == TRUE){ + // ???? + mailWndBtnFlag[17] = TRUE; + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + } + else{ + // ??? + mailWndBtnFlag[17] = FALSE; + } + + // ???????? + if (pActMenuWnd != NULL){ + // ?@e + x = pActMenuWnd->x; + y = pActMenuWnd->y; + char *splitPoint; + // ??????k? + mailHistoryWndNowPageNo = (MailHistory[mailHistoryWndSelectNo].newHistoryNo + mailHistoryWndPageNo) % MAIL_MAX_HISTORY; + // t????????? + if (MailHistory[mailHistoryWndSelectNo].noReadFlag[mailHistoryWndNowPageNo] >= TRUE){ + // ???????? + if (MailHistory[mailHistoryWndSelectNo].noReadFlag[mailHistoryWndNowPageNo] > TRUE){ + // ???????????????? + if (pActPet == NULL){ + // ????????? + pActPet = MakeAnimDisp(pActMenuWnd->x - 204, pActMenuWnd->y + 160, MailHistory[mailHistoryWndSelectNo].noReadFlag[mailHistoryWndNowPageNo], ANIM_DISP_PET_RECIEVE); + pActPet->atr |= ACT_ATR_INFO; + pActPet->atr |= ACT_ATR_TYPE_PET; + // ?????? + pActPet->level = MailHistory[mailHistoryWndSelectNo].petLevel[mailHistoryWndNowPageNo]; + // ????q + strcpy(pActPet->name, MailHistory[mailHistoryWndSelectNo].petName[mailHistoryWndNowPageNo]); + } + // ????????????????????????? + if (pActMailItem == NULL && MailHistory[mailHistoryWndSelectNo].itemGraNo[mailHistoryWndNowPageNo] != -1){ + // ?????????? + pActMailItem = MakeAnimDisp(pActMenuWnd->x - 204, pActMenuWnd->y + 128, MailHistory[mailHistoryWndSelectNo].itemGraNo[mailHistoryWndNowPageNo], ANIM_DISP_PET_ITEM); + pActMailItem->atr |= ACT_ATR_INFO; + pActMailItem->atr |= ACT_ATR_TYPE_ITEM; + pActMailItem->dispPrio = DISP_PRIO_DRAG; + // ??????? + strcpy(pActMailItem->name, ""); + } + } + // ??????????? + if (pActLetter[0] == NULL){ + // ??????????? + pActLetter[0] = MakeAnimDisp(x + 28, y + 244, SPR_mail, ANIM_DISP_LETTER); + } + // ???? + MailHistory[mailHistoryWndSelectNo].noReadFlag[mailHistoryWndNowPageNo] = FALSE; + // ???????V + SaveMailHistory(mailHistoryWndSelectNo); + // t???? + mailLamp = CheckMailNoReadFlag(); + + } + // ?????? + splitPoint = MailHistory[mailHistoryWndSelectNo].str[mailHistoryWndNowPageNo]; + // q + CenteringStr(addressBook[mailHistoryWndSelectNo].name, moji, CHAR_NAME_LEN); + StockFontBuffer(x + 64, y + 34, FONT_PRIO_FRONT, 0, moji, 0); + // Tܤ + StockFontBuffer(x + 148, y + 236, FONT_PRIO_FRONT, 0, MailHistory[mailHistoryWndSelectNo].dateStr[mailHistoryWndNowPageNo], 0); + // + while (1){ + // ????????? + if (strlen(splitPoint) > 28){ + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; // Z?????? + // u??S???? + if (GetStrLastByte(moji) == 3){ + moji[27] = NULL; + splitPoint += 27; + } + else{ + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x + 12, y + 260, FONT_PRIO_FRONT, 0, moji, 0); y += 20; + } + else{ + strcpy(moji, splitPoint); + StockFontBuffer(x + 12, y + 260, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + // q??? + mailWndFontNo[16] = StockDispBuffer(pActMenuWnd->x + 25 + 16 + 8, pActMenuWnd->y + 405, DISP_PRIO_IME3, CG_PREV_BTN + mailWndBtnFlag[16], 2); + // ???k? + sprintf_s(moji, "%2d", mailHistoryWndPageNo + 1); + StockFontBuffer(pActMenuWnd->x + 46 + 16 + 9, pActMenuWnd->y + 397, FONT_PRIO_FRONT, 0, moji, 0); + // ???? + mailWndFontNo[17] = StockDispBuffer(pActMenuWnd->x + 75 + 16 + 9 + 8, pActMenuWnd->y + 405, DISP_PRIO_IME3, CG_NEXT_BTN + mailWndBtnFlag[17], 2); + // ?????? + mailWndFontNo[18] = StockDispBuffer(pActMenuWnd->x + 196, pActMenuWnd->y + 371, DISP_PRIO_IME3, CG_MAIL_WND_MAIL_BTN, 2); + // ????? + mailWndFontNo[19] = StockDispBuffer(pActMenuWnd->x + 220 - 16 - 8, pActMenuWnd->y + 405, DISP_PRIO_IME3, CG_RETURN_BTN, 2); + } + } + } + break; + + + } + } + + //? ??????????? *******************************************************/ + + if (MenuToggleFlag & JOY_CTRL_A){ + + // ?????k??? + switch (albumWndNo){ + + case 0: // ?????? + + // ????????? + if (pActMenuWnd == NULL){ + // ????????? + pActMenuWnd = MakeWindowDisp(4, 4, 272, 448, 0, -1); + // ???Re??? + for (i = 0; i < MENU_ALBUM_0; i++) albumWndFontNo[i] = -2; + // ???k???? + albumWndPageNo = 0; + // ????k???? + albumNo = -1; + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ????????? + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd->pYobi)->my, DISP_PRIO_MENU, CG_ALBUM_WND, 1); + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ????Id????k? + int nowTopNo = albumWndPageNo * 8; + // ??????? + for (i = 0; i < 8; i++){ + // ???k????????????? + if (HitFontNo == albumWndFontNo[i] && PetAlbum[nowTopNo + i].flag >= 2){ + // ????k??? + albumNo = nowTopNo + i; + // ?????? + PetAlbum[albumNo].flag = 3; + // ?????V + SaveAlbum(albumNo); + // ????? + play_se(217, 320, 240); + } + } + // ??? + if (HitDispNo == albumWndFontNo[19]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ??????? + MenuToggleFlag ^= JOY_CTRL_A; + // ???????? + play_se(203, 320, 240); + } + } + + // q??? + if (HitDispNo == albumWndFontNo[16] || joy_con[0] & JOY_A){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_A){ + int limitPage = ((MAX_PET_KIND + MAX_PET_PAGE_SIZE - 1) / MAX_PET_PAGE_SIZE) - 1; + albumWndPageNo--; // ????? + // ???????? + if (albumWndPageNo < 0) albumWndPageNo = limitPage; + // ????? + play_se(217, 320, 240); + albumWndBtnFlag[16] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_A) && albumWndBtnFlag[16] == TRUE){ + // ???? + albumWndBtnFlag[16] = TRUE; + } + else{ + // ??? + albumWndBtnFlag[16] = FALSE; + } + } + else{ + // ??? + albumWndBtnFlag[16] = FALSE; + } + // ??? + if (HitDispNo == albumWndFontNo[17] || joy_con[0] & JOY_B){ + // ???????? + if (mouse.autoState & MOUSE_LEFT_CRICK || joy_auto[0] & JOY_B){ + int limitPage = ((MAX_PET_KIND + MAX_PET_PAGE_SIZE - 1) / MAX_PET_PAGE_SIZE) - 1; + albumWndPageNo++; // ?????? + // ???????? + if (albumWndPageNo > limitPage) albumWndPageNo = 0; + // ????? + play_se(217, 320, 240); + albumWndBtnFlag[17] = TRUE; + } + // ????????? + if ((mouse.state & MOUSE_LEFT_CRICK || joy_con[0] & JOY_B) && albumWndBtnFlag[17] == TRUE){ + // ???? + albumWndBtnFlag[17] = TRUE; + } + else{ + // ??? + albumWndBtnFlag[17] = FALSE; + } + } + else{ + // ??? + albumWndBtnFlag[17] = FALSE; + } + + + // ???????? + if (pActMenuWnd != NULL){ +#define ALBUM_WND_ATTR_X 34 +#define ALBUM_WND_ATTR_Y 0 + int x2; + int nowTopNo; // ????Id????k? + // ?@e + x = pActMenuWnd->x; + y = pActMenuWnd->y + 28; + + // ????k???? + if (albumNo != -1){ + // q?????????? + CenteringStr(PetAlbum[albumNo].freeName, moji, PET_NAME_LEN); + StockFontBuffer(x + 13, y, FONT_PRIO_FRONT, 0, moji, 0); y += 22; + + sprintf_s(moji, "%3d", PetAlbum[albumNo].level); + StockFontBuffer(x + 36, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + + sprintf_s(moji, "%4d", PetAlbum[albumNo].maxHp); + StockFontBuffer(x + 36, y, FONT_PRIO_FRONT, 0, moji, 0); + + sprintf_s(moji, "%3d", PetAlbum[albumNo].str); + StockFontBuffer(x + 36 + 72, y, FONT_PRIO_FRONT, 0, moji, 0); y += 24; + + sprintf_s(moji, "%4d", PetAlbum[albumNo].quick); + StockFontBuffer(x + 36, y, FONT_PRIO_FRONT, 0, moji, 0); + + sprintf_s(moji, "%3d", PetAlbum[albumNo].def); + StockFontBuffer(x + 36 + 72, y, FONT_PRIO_FRONT, 0, moji, 0); y += 29; + + // ԢN??? + if (PetAlbum[albumNo].earth > 0){ + x2 = (int)(PetAlbum[albumNo].earth * 0.8); + + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 0, y + ALBUM_WND_ATTR_Y + 0, x + ALBUM_WND_ATTR_X + 0 + x2, y + ALBUM_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_GREEN, 1); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 1, y + ALBUM_WND_ATTR_Y + 1, x + ALBUM_WND_ATTR_X + 1 + x2, y + ALBUM_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 2, y + ALBUM_WND_ATTR_Y + 2, x + ALBUM_WND_ATTR_X + 2 + x2, y + ALBUM_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_GREEN2, 0); + } + y += 20; + + // ?N??? + if (PetAlbum[albumNo].water > 0){ + x2 = (int)(PetAlbum[albumNo].water * 0.8); + + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 0, y + ALBUM_WND_ATTR_Y + 0, x + ALBUM_WND_ATTR_X + 0 + x2, y + ALBUM_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_AQUA, 1); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 1, y + ALBUM_WND_ATTR_Y + 1, x + ALBUM_WND_ATTR_X + 1 + x2, y + ALBUM_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 2, y + ALBUM_WND_ATTR_Y + 2, x + ALBUM_WND_ATTR_X + 2 + x2, y + ALBUM_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_AQUA2, 0); + } + y += 20; + + // ?N??? + if (PetAlbum[albumNo].fire > 0){ + x2 = (int)(PetAlbum[albumNo].fire * 0.8); + + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 0, y + ALBUM_WND_ATTR_Y + 0, x + ALBUM_WND_ATTR_X + 0 + x2, y + ALBUM_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_RED, 1); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 1, y + ALBUM_WND_ATTR_Y + 1, x + ALBUM_WND_ATTR_X + 1 + x2, y + ALBUM_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 2, y + ALBUM_WND_ATTR_Y + 2, x + ALBUM_WND_ATTR_X + 2 + x2, y + ALBUM_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_RED2, 0); + } + y += 20; + + // ?N??? + if (PetAlbum[albumNo].wind > 0){ + x2 = (int)(PetAlbum[albumNo].wind * 0.8); + + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 0, y + ALBUM_WND_ATTR_Y + 0, x + ALBUM_WND_ATTR_X + 0 + x2, y + ALBUM_WND_ATTR_Y + 8, DISP_PRIO_IME4, SYSTEM_PAL_YELLOW, 1); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 1, y + ALBUM_WND_ATTR_Y + 1, x + ALBUM_WND_ATTR_X + 1 + x2, y + ALBUM_WND_ATTR_Y + 9, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + StockBoxDispBuffer(x + ALBUM_WND_ATTR_X + 2, y + ALBUM_WND_ATTR_Y + 2, x + ALBUM_WND_ATTR_X + 2 + x2, y + ALBUM_WND_ATTR_Y + 10, DISP_PRIO_IME3, SYSTEM_PAL_YELLOW2, 0); + } + + StockDispBuffer(pActMenuWnd->x + 151 + 48, pActMenuWnd->y + 65 + 52, DISP_PRIO_IME3, PetAlbum[albumNo].faceGraNo, 0); + } + + y = pActMenuWnd->y + 215; + + // ????Id????k? + nowTopNo = albumWndPageNo * 8; + // ??????? + for (i = 0; i < 8; i++){ + // ???????? + if (nowTopNo + i >= MAX_PET_KIND) break; + + // ?????????? + if (PetAlbum[nowTopNo + i].flag == 2){ + // ? + StockDispBuffer(x + 24, y + 9, DISP_PRIO_IME3, CG_ALBUM_WND_NEW_ICON, 0); + } + // ?????? + sprintf_s(moji, "No.%3d", nowTopNo + i + 1); + StockFontBuffer(x + 46, y + 1, FONT_PRIO_FRONT, 0, moji, 0); + + if (PetAlbum[nowTopNo + i].flag != 0){ + // ???? + if (PetAlbum[nowTopNo + i].flag == 1){ + CenteringStr(PetAlbum[nowTopNo + i].name, moji, PET_NAME_LEN); + StockFontBuffer(x + 112, y, FONT_PRIO_FRONT, FONT_PAL_GRAY, moji, 0); + // ???Rek???? + albumWndFontNo[i] = -2; + } + else + // ??? + if (PetAlbum[nowTopNo + i].flag >= 2){ + CenteringStr(PetAlbum[nowTopNo + i].name, moji, PET_NAME_LEN); + albumWndFontNo[i] = StockFontBuffer(x + 112, y, FONT_PRIO_FRONT, 0, moji, 2); + } + } + else{ + // ???Rek???? + albumWndFontNo[i] = -2; + } + y += 22; + } + + // q??? + albumWndFontNo[16] = StockDispBuffer(pActMenuWnd->x + 25 + 32 + 10 + 40, pActMenuWnd->y + 400, DISP_PRIO_IME3, CG_PREV_BTN + albumWndBtnFlag[16], 2); + albumWndFontNo[17] = StockDispBuffer(pActMenuWnd->x + 75 + 32 + 9 + 10 + 40, pActMenuWnd->y + 400, DISP_PRIO_IME3, CG_NEXT_BTN + albumWndBtnFlag[17], 2); + // ????? + albumWndFontNo[19] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, pActMenuWnd->y + 448 - 19, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + } + } + } + break; + } + } + + //? Pf??????? ***********************************************************/ + if (BattleResultWndFlag >= 1 && ProcNo == PROC_GAME && SubProcNo == 3){ + // ?????? + if (--ResultWndTimer <= 0){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ??????????? + BattleResultWndFlag = FALSE; + // ???????????? + if (MapWmdFlagBak != TRUE){ + // ???????? + play_se(203, 320, 240); + } + } + + static int ᆳж = FALSE; + switch (BattleResultWndFlag){ + + case 1: // ??k??????? + if (pActMenuWnd == NULL){ + ᆳж = FALSE; + int flag = 0; + // ????????? + pActMenuWnd = MakeWindowDisp(320 - 160, 240 - 120, 5, 6, CG_WND_TITLE_RESULT, 2); + // ???Re??? + for (i = 0; i < MENU_BTL_RESULT_0; i++) resultWndFontNo[i] = -2; + // ?????????? + for (i = 0; i < 4; i++){ + // ????????????? + if (battleResultMsg.resChr[i].levelUp == TRUE) flag = TRUE; + } + if (flag == TRUE){ + // ??????? + play_se(211, 320, 240); + } + else{ + // ???????? + play_se(202, 320, 240); + } + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == resultWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ??????????? + BattleResultWndFlag = FALSE; + // ???????????? + if (MapWmdFlagBak != TRUE){ + // ???????? + play_se(203, 320, 240); + } + } + } + + // ???????? + if (pActMenuWnd != NULL){ + int color; + int flag, j; + // ?@e + x = pActMenuWnd->x + 12; + y = pActMenuWnd->y + 44; + + // ?q + CenteringStr( pc.name, moji, CHAR_NAME_LEN ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); + color = FONT_PAL_GRAY; // ????? + // ???????? + if( battleResultMsg.resChr[ 0 ].levelUp == TRUE ){ + // ?????? + StockFontBuffer( x + 152, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW, "LvUp!", 0 ); + } + // ??k + sprintf( moji,"Exp %+5d", battleResultMsg.resChr[ 0 ].exp ); + StockFontBuffer( x + 148 + 58, y, FONT_PRIO_FRONT, 0, moji, 0 ); + y += 20; + + // ?????? + for( i = 0 ; i < 5 ; i++ ){ + // ??????????? ?? ?????? + if( pet[ i ].useFlag == TRUE + && (pc.selectPetNo[ i ] == TRUE || pc.ridePetNo == i ) ){ + // q???? + // ?????? + if( pet[ i ].freeName[ 0 ] != NULL ) + CenteringStr( pet[ i ].freeName, moji, PET_NAME_LEN ); + else + CenteringStr( pet[ i ].name, moji, PET_NAME_LEN ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, moji, 0 ); + color = FONT_PAL_GRAY; // ????? + flag = FALSE; // ?????? + // Pf???Bl????S?? + for( j = 1 ; j < RESULT_CHR_EXP ; j++ ){ + // ???? + if( battleResultMsg.resChr[ j ].petNo == i ){ + // ???????? + if( battleResultMsg.resChr[ j ].levelUp == TRUE ){ // ???????? + // ?????? + StockFontBuffer( x + 152, y, FONT_PRIO_FRONT, FONT_PAL_YELLOW,"LvUp!", 0 ); + } + // ??k + sprintf( moji,"Exp %+5d", battleResultMsg.resChr[ j ].exp ); + StockFontBuffer( x + 148 + 58, y, FONT_PRIO_FRONT, 0, moji, 0 ); + flag = TRUE; + } + } + // ???? + if( flag == FALSE ){ + sprintf( moji,"Exp %+4d", battleResultMsg.resChr[ j ].exp ); + StockFontBuffer( x + 148 + 58, y, FONT_PRIO_FRONT, 0, "Exp +0", 0 ); + } + y += 20; + } + } + flag = FALSE; + y = pActMenuWnd->y + 134; + // ????: + StockFontBuffer( x, y+30, FONT_PRIO_FRONT, 0, " ", 0 ); + char itemName[128]; + memset(itemName,0,128); + for( i = 0 ; i < 3 ; i++ ){ + // ????????? + if( battleResultMsg.item[ i ][ 0 ] != NULL ){ + sprintf_s(itemName + strlen(itemName), sizeof(itemName)-strlen(itemName), " %s ", battleResultMsg.item[i]); + StockFontBuffer( x + 85, y+30, FONT_PRIO_FRONT, 0, battleResultMsg.item[ i ], 0 ); + y += 22; + flag = TRUE; + } + } + if( flag == FALSE ){ + StockFontBuffer( x + 85, y+30, FONT_PRIO_FRONT, 0, "ûеõκεߡ", 0 ); + } + resultWndFontNo[ 0 ] = StockDispBuffer( ( ( WINDOW_DISP *)pActMenuWnd->pYobi )->mx, pActMenuWnd->y + 216+30, DISP_PRIO_IME3, CG_CLOSE_BTN, 2 ); + + if (!ᆳж&&鿪){ + int petexp[2]; + int petlevel[2]; + int petindex[2]; + petexp[0] = petexp[1] = -1; + petindex[0] = petindex[1] = -1; + petlevel[0] = petlevel[1] = 0; + int num = 1; + for(num;num < RESULT_CHR_EXP;num++){ + if(battleResultMsg.resChr[num].petNo>=0){ + if(pet[battleResultMsg.resChr[num].petNo].useFlag){ + if(pc.battlePetNo==battleResultMsg.resChr[num].petNo){ + petexp[1] = battleResultMsg.resChr[num].exp; + petlevel[1] = battleResultMsg.resChr[num].levelUp; + petindex[1] = battleResultMsg.resChr[num].petNo; + } + if(pc.ridePetNo==battleResultMsg.resChr[num].petNo){ + petexp[0] = battleResultMsg.resChr[num].exp; + petlevel[0] = battleResultMsg.resChr[num].levelUp; + petindex[0] = battleResultMsg.resChr[num].petNo; + } + } + } + } + ᆳж = !ᆳж; + char token[256]; + if(battleResultMsg.resChr[0].levelUp) + sprintf_s(token, "õ飺[Լ%d UpLv!] ", battleResultMsg.resChr[0].exp); + else + sprintf_s(token, "õ飺[Լ%d] ", battleResultMsg.resChr[0].exp); + if(petindex[0]>=0){ + if (petlevel[0]) + sprintf_s(token + strlen(token), sizeof(token)-strlen(token), "[%s%d UpLv!] ",pet[ petindex[0] ].name , petexp[0]); + else + sprintf_s(token + strlen(token), sizeof(token)-strlen(token), "[%s%d] ", pet[ petindex[0] ].name , petexp[0]); + } + if(petindex[1]>=0){ + if (petlevel[1]) + sprintf_s(token + strlen(token), sizeof(token)-strlen(token), "[%s%d UpLv!] ",pet[ petindex[1] ].name , petexp[1]); + else + sprintf_s(token + strlen(token), sizeof(token)-strlen(token), "[%s%d] ", pet[ petindex[1] ].name , petexp[1]); + } + if (itemName[0]) sprintf_s(token + strlen(token), sizeof(token)-strlen(token), "õƷ[%s]", itemName); + StockChatBufferLine(token, FONT_PAL_YELLOW); + } + } + } + } + break; + + case 2: // ?????????? + + // ????????? + if (pActMenuWnd == NULL){ + int flag = 0; + // ????????? + pActMenuWnd = MakeWindowDisp(320 - 96, 240 - 72, 3, 3, CG_WND_TITLE_RESULT, 2); + // ???Re??? + for (i = 0; i < MENU_BTL_RESULT_0; i++) resultWndFontNo[i] = -2; + // ???????? + play_se(202, 320, 240); + } + else{ + // ?????????????? + if (pActMenuWnd->hp > 0){ + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK){ + // ??? + if (HitDispNo == resultWndFontNo[0]){ + // ?????? + DeathAction(pActMenuWnd); + pActMenuWnd = NULL; + // ??????????? + BattleResultWndFlag = FALSE; + // ???????????? + if (MapWmdFlagBak != TRUE){ + // ???????? + play_se(203, 320, 240); + } + } + } + + // ???????? + if (pActMenuWnd != NULL){ + int color = FONT_PAL_WHITE; + // ?@e + x = pActMenuWnd->x + 17; + y = pActMenuWnd->y + 48; + // ?? + sprintf_s(moji, " %+8d", battleResultMsg.resChr[0].exp); + StockFontBuffer(x, y, FONT_PRIO_FRONT, color, moji, 0); + y += 28; + // ?? + sprintf_s(moji, " %8d", battleResultMsg.resChr[1].exp); + StockFontBuffer(x, y, FONT_PRIO_FRONT, 0, moji, 0); + + // ????????? + resultWndFontNo[0] = StockDispBuffer(((WINDOW_DISP *)pActMenuWnd->pYobi)->mx, pActMenuWnd->y + 120, DISP_PRIO_IME3, CG_CLOSE_BTN, 2); + } + } + } + break; + } + } + + //¿ʼΪӴ + if (MenuToggleFlag & JOY_CTRL_T) + { + char buffer[1024]; +#ifdef _TRADESYSTEM2 // Syu ADD ½ϵͳ + char buffer2[1024]; + int j; +#endif +#ifdef _PET_ITEM + static BOOL bViewPetEquip = FALSE; +#endif + switch (tradeWndNo){ +#ifdef _COMFIRM_TRADE_REQUEST + case 1: + { + static int btnYes = -1, btnNo = -1; + char questStr[200]; + sprintf(questStr, "ȷ[style c=5]%s[/style]Ľ", opp_name); + StockFontBuffer(245, 220, FONT_PRIO_AFRONT, 3, questStr, 0); + StockDispBuffer(320, 240, DISP_PRIO_YES_NO_WND, CG_DROPWND, 0); + btnYes = StockDispBuffer(320, 240, DISP_PRIO_YES_NO_BTN, CG_COMMON_YES_BTN, 2); + btnNo = StockDispBuffer(320, 240, DISP_PRIO_YES_NO_BTN, CG_COMMON_NO_BTN, 2); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (btnYes == HitDispNo) + { + sprintf_s(buffer, "C|%s|%s|1", opp_sockfd, opp_name); + //ͳȡѶϢServer֪ͨԷ + lssproto_TD_send(sockfd, buffer); + play_se(203, 320, 240); + btnYes = -1; + btnNo = -1; + tradeWndNo = 0; + } + else if (btnNo == HitDispNo) + { + sprintf_s(buffer, "C|%s|%s|0", opp_sockfd, opp_name); + //ͳȡѶϢServer֪ͨԷ + lssproto_TD_send(sockfd, buffer); + play_se(203, 320, 240); + btnYes = -1; + btnNo = -1; + tradeWndNo = 0; + } + } + break; + } +#endif + default: + //ӴΪʱʼ + if (pActMenuWnd4 == NULL) + { + DeathMenuAction(); + DeathMenuAction2(); + //ֶbuffʼ + TradeBuffer.buffer[0] = NULL; + TradeBuffer.cnt = 0; + TradeBuffer.cursor = 0; + TradeBuffer.len = 8; + TradeBuffer.color = 0; + TradeBuffer.x = 600; + TradeBuffer.y = 120; + TradeBuffer.fontPrio = FONT_PRIO_FRONT; + + x = (lpDraw->xSize - 620) / 2; + y = (lpDraw->ySize - 456) / 2; + pActMenuWnd4 = MakeWindowDisp(x, y, 620, 456, 0, -1, FALSE); +#ifdef _NEW_ITEM_ + ҳ = 0; +#endif +#ifdef _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + TradeBtnflag = false; +#endif + + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //״̬ʼ + locknum = -1; + locknum2 = -1; + MainTradeWndflag = true; + SecondTradeWndflag = false; + + //andy_add 20030610 + for (i = 0; i < MENU_TRADE_0; i++) tradeWndFontNo[i] = -2; + for (i = 0; i < 6; i++) SecondtradeWndFontNo[i] = -2; + + for (i = 0; i < 43; i++) + tradeList[i].data = -1; +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + //Ӵ + tradetalkwndflag = false; + for (i = 0; i < 4; i++) + sprintf_s(talkmsg[i], ""); +#endif + drag1Y = 67; + drag2Y = 257; + + x = (lpDraw->xSize - 620) / 2; + y = (lpDraw->ySize - 456) / 2; + SecondTradeWnd = MakeWindowDisp(x, y, 620, 456, 0, -1, FALSE); + for (i = 0; i < 43; i++) { //б + tradeList[i].data = -1; + tradeList[i].kind = 'S'; + } + for (i = 0; i < 21; i++){ //б + mytradelist[i] = -1; + opptradelist[i] = -1; + } +#ifdef _NEW_ITEM_ + for (i = 0; i < MAX_MAXHAVEITEM * 3; i++) { +#ifdef _ITEM_PILENUMS + itemflag[i] = pc.item[i + MAX_ITEMSTART].pile; +#else + itemflag[i] = 0 ; +#endif + +#ifdef _NPC_ITEMUP +#endif + } +#endif + + + for (i = 0; i < MAX_MAXHAVEITEM; i++) { +#ifndef _NEW_ITEM_ +#ifdef _ITEM_PILENUMS + itemflag[i] = pc.item[i + MAX_ITEMSTART].pile; +#else + itemflag[i] = 0; +#endif +#endif + strcpy(opp_item[i].itemindex, "-1"); + strcpy(opp_item[i].damage, ""); + strcpy(opp_item[i].effect, ""); + strcpy(opp_item[i].name, ""); +#ifdef _NPC_ITEMUP +#endif + } + +#endif + + InitItem3(325, 230); + //Terry add 2003/11/19 + g_bTradesystemOpen = true; + //end + + } + else + { + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + // Ӵ + if (MainTradeWndflag == true) + { + SecondTradeWndflag = false; +#endif + + if (pActMenuWnd4->hp > 0) + { + + + //Ӵ +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ӴʱӴPetAction + if (SecondActPet != NULL) + { + DeathAction(SecondActPet); + SecondActPet = NULL; + } + + + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd4->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd4->pYobi)->my - 20, DISP_PRIO_MENU, CG_TRADE_WND, 1); +#endif + + + // Ϊʱ Start + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // ȡ Start + //ȡ + if (HitDispNo == tradeWndFontNo[1]) + { + //رսӴ + MenuToggleFlag &= ~JOY_CTRL_T; + + //ӴرЧ + play_se(203, 320, 240); + sprintf_s(buffer, "W|%s|%s", opp_sockfd, opp_name); + //ͳȡѶϢServer֪ͨԷ + lssproto_TD_send(sockfd, buffer); + tradeStatus = 0; + tradeInit(); + pc.trade_confirm = 1; + } + // ȡ End + + + // Lock ȷ Start +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ӴӴLockȷfunction + LockAndOkfunction(); + // Lock ȷ End + + //Ӵлť + if (HitDispNo == tradeWndFontNo[21]) + { + MainTradeWndflag = false; + SecondTradeWndflag = true; + //andy_add 20030610 + for (i = 0; i < MENU_TRADE_0; i++) tradeWndFontNo[i] = -2; + for (i = 0; i < 6; i++) SecondtradeWndFontNo[i] = -2; + + } + //ԷƷϾť + if (HitDispNo == tradeWndFontNo[18]) + { + if (drag1Y >= 67) + drag1Y -= 4; + if (drag1Y < 67) + drag1Y = 67; + } + //ԷƷ¾ť + if (HitDispNo == tradeWndFontNo[19]) + { + if (drag1Y <= 151) + drag1Y += 4; + if (drag1Y > 151) + drag1Y = 151; + } + //ҷƷϾť + if (HitDispNo == tradeWndFontNo[15]) + { + if (drag2Y >= 257) + drag2Y -= 4; + if (drag2Y < 257) + drag2Y = 257; + } + //ҷƷ¾ť + if (HitDispNo == tradeWndFontNo[16]) + { + if (drag2Y <= 341) + drag2Y += 4; + if (drag2Y > 341) + drag2Y = 341; + } + //ҷƷҷ + if (HitDispNo == tradeWndFontNo[20]) + { + if (!dragflag1) + { + tmpdrag1Y = drag1Y; + dragflag1 = true; + } + } + //ԷƷҷ + if (HitDispNo == tradeWndFontNo[17]) + { + if (!dragflag2) + { + tmpdrag2Y = drag2Y; + dragflag2 = true; + } + } +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + //ҷť + if (HitDispNo == tradeWndFontNo[14]) + talkwndflag = true; + //رť + +#endif +#endif + + } + // Ϊʱ End + + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ҷҷť + if (dragflag1 == true && + (tmpdrag1Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y) <= 151 && + (tmpdrag1Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y) >= 67){ + drag1Y = tmpdrag1Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y; + } + + //Էҷť + if (dragflag2 == true && + (tmpdrag2Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y) <= 341 && + (tmpdrag2Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y) >= 257){ + drag2Y = tmpdrag2Y - mouse.crickLeftDownPoint.y + mouse.nowPoint.y; + } +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + //Իҷλ + if (talkwndflag == true) + { + talkwndx = mouse.nowPoint.x; + talkwndy = mouse.nowPoint.y; + } + if (mouse.onceState & MOUSE_RIGHT_CRICK) + tradetalkwndflag = false; +#endif +#endif + + // ѡȡ Start + // ѡȡ + if (HitDispNo == tradeWndFontNo[2]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + tradeWndBtnFlag[2] = TRUE; + int i = 0; + while (1) + { + tradePetIndex++; + if (tradePetIndex >= 5) tradePetIndex = 0; + if (pet[tradePetIndex].useFlag != NULL + && pc.ridePetNo != tradePetIndex) + break; + if ((i++) > 5) + { + tradePetIndex = -1; + break; + } + } + if (pActPet3 != NULL) + { + DeathAction(pActPet3); + pActPet3 = NULL; + } + + } + } + // ѡȡ End + + // ѡȡҼ Start + // ѡȡҼ + if (HitDispNo == tradeWndFontNo[3]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + tradeWndBtnFlag[3] = TRUE; + int i = 0; + while (1) + { + tradePetIndex--; + if (tradePetIndex <0) tradePetIndex = 4; + if (pet[tradePetIndex].useFlag != NULL + && pc.ridePetNo != tradePetIndex) + break; + if ((i++) >5) + { + tradePetIndex = -1; + break; + } + } + if (pActPet3 != NULL) + { + DeathAction(pActPet3); + pActPet3 = NULL; + } + + } + } + + // ѡȡҼ End + + // Ӽ Start + if (HitDispNo == tradeWndFontNo[4]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && tradeWndBtnFlag[4] == TRUE) + tradeWndBtnFlag[4] = FALSE; + if (tradeWndBtnFlag[4] == TRUE) + { + // ʱFocusChatBuffer + GetKeyInputFocus(&MyChatBuffer); + // Ӵʱԭ趨 + Tradeflag = false; + tradeWndDropGold += tradeWndDropGoldInc; + tradeWndDropGoldCnt++; + if (tradeWndDropGoldCnt >= 30){ + tradeWndDropGoldCnt = 0; + if (tradeWndDropGoldInc == 0) + tradeWndDropGoldInc = 1; + else { + tradeWndDropGoldInc *= 5; + if (tradeWndDropGoldInc > 10000) + tradeWndDropGoldInc = 10000; + } + } + //ȷ + if (tradeWndDropGold >= pc.gold) + { + tradeWndDropGold = pc.gold; + play_se(220, 320, 240); + } + } + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + tradeWndDropGold++; + if (tradeWndDropGold >= pc.gold) + { + tradeWndDropGold = pc.gold; + play_se(220, 320, 240); + } + else + { + tradeWndDropGoldInc = 0; + tradeWndDropGoldCnt = 0; + tradeWndBtnFlag[4] = TRUE; + play_se(217, 320, 240); + } + } + } + else + tradeWndBtnFlag[4] = FALSE; + // Ӽ End + + // ټ Start + if (HitDispNo == tradeWndFontNo[5]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && tradeWndBtnFlag[5] == TRUE) + tradeWndBtnFlag[5] = FALSE; + if (tradeWndBtnFlag[5] == TRUE) + { + // ¼ʱFocusChatBuffer + GetKeyInputFocus(&MyChatBuffer); + // Ӵʱԭ趨 + Tradeflag = false; + tradeWndDropGold -= tradeWndDropGoldInc; + tradeWndDropGoldCnt++; + if (tradeWndDropGoldCnt >= 30) + { + tradeWndDropGoldCnt = 0; + if (tradeWndDropGoldInc == 0) + { + tradeWndDropGoldInc = 1; + } + else + { + tradeWndDropGoldInc *= 5; + if (tradeWndDropGoldInc > 10000) + tradeWndDropGoldInc = 10000; + } + } + if (tradeWndDropGold < 0) + { + tradeWndDropGold = 0; + play_se(220, 320, 240); + } + } + if (mouse.onceState & MOUSE_LEFT_CRICK) { + tradeWndDropGold--; + if (tradeWndDropGold <= 0) + { + tradeWndDropGold = 0; + play_se(220, 320, 240); + } + else + { + tradeWndDropGoldInc = 0; + tradeWndDropGoldCnt = 0; + tradeWndBtnFlag[5] = TRUE; + play_se(217, 320, 240); + } + } + } + else + tradeWndBtnFlag[5] = FALSE; + // ټ End + + // ü Start + if (HitDispNo == tradeWndFontNo[6]) + { + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + // ·ʱFocusChatBuffer + GetKeyInputFocus(&MyChatBuffer); + // Ӵʱԭ趨 + Tradeflag = false; + if (tradeWndDropGold > 0 && eventWarpSendFlag == FALSE) + { + tradeWndBtnFlag[6] = TRUE; + play_se(217, 320, 240); + } + else + play_se(220, 320, 240); + } + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && tradeWndBtnFlag[6] == TRUE) + { + if (tradeStatus != 1) return; + if (pc.trade_confirm == 2 || pc.trade_confirm == 4) return; + tradeWndBtnFlag[6] = FALSE; + int TradeGoldIndex = 0; + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + if ((tradeList[21].data == -1)) + { + tradeList[21].data = tradeWndDropGold; + tradeList[21].kind = 'G'; + TradeGoldIndex = 3; + } +#endif + + if (TradeGoldIndex != 0) + { +#ifdef _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + TradeBtnflag = true; +#endif + play_se(212, 320, 240); + tradeWndDropGoldSend = tradeWndDropGold; + sprintf_s(buffer, "T|%s|%s|G|%d|%d", opp_sockfd, opp_name, TradeGoldIndex, tradeWndDropGoldSend); + lssproto_TD_send(sockfd, buffer); + tradeWndDropGold = 0; + } + } + } + else + tradeWndBtnFlag[6] = FALSE; + // ü End + + // ü Start + if (HitDispNo == tradeWndFontNo[7]) + { +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + tradeWndBtnFlag[7] = TRUE; +#endif + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + if (tradeStatus != 1) return; + if (pc.trade_confirm == 2 || pc.trade_confirm == 4) return; + + if (pet[tradePetIndex].useFlag + && pc.ridePetNo != tradePetIndex) + { + + if (pet[tradePetIndex].freeName[0] != NULL) + strcpy(tradePet[0].name, pet[tradePetIndex].freeName); + else + strcpy(tradePet[0].name, pet[tradePetIndex].name); + tradePet[0].level = pet[tradePetIndex].level; + tradePet[0].atk = pet[tradePetIndex].atk; + tradePet[0].def = pet[tradePetIndex].def; + tradePet[0].quick = pet[tradePetIndex].quick; + tradePet[0].graNo = pet[tradePetIndex].graNo; + tradePet[0].trn = pet[tradePetIndex].trn; + tradePet[0].maxHp = pet[tradePetIndex].maxHp; + + tradePet[0].index = tradePetIndex; +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + pet[tradePetIndex].useFlag = NULL; + if (pActPet3) + { + DeathAction(pActPet3); + pActPet3 = NULL; + } +#endif + + + DeathAction(pActPet4); + pActPet4 = NULL; +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + tradeList[tradePetIndex + 16].data = tradePetIndex; + tradeList[tradePetIndex + 16].kind = 'P'; + strcpy(tradeList[tradePetIndex + 16].name, pet[tradePetIndex].name); + tradeList[tradePetIndex + 16].level = pet[tradePetIndex].level; + tradeList[tradePetIndex + 16].trns = pet[tradePetIndex].trn; +#ifdef _SHOW_FUSION + tradeList[tradePetIndex + 16].fusion = pet[tradePetIndex].fusion; +#endif + + if (pet[tradePetIndex].freeName[0] != NULL) + strcpy(tradeList[tradePetIndex + 16].freename, pet[tradePetIndex].freeName); + else + strcpy(tradeList[tradePetIndex + 16].freename, "");// change fix ֹδijʾһĸbug +#endif + + if (tradeStatus) + { +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ͳ׳ļܡԭ + sprintf_s(buffer2, "%s|%s|%s|%s|%s|%s|%s|%s|%s", + petSkill[tradePetIndex][0].name, + petSkill[tradePetIndex][1].name, + petSkill[tradePetIndex][2].name, + petSkill[tradePetIndex][3].name, + petSkill[tradePetIndex][4].name, + petSkill[tradePetIndex][5].name, + petSkill[tradePetIndex][6].name, + pet[tradePetIndex].name, + pet[tradePetIndex].freeName + ); + sprintf_s(buffer, "T|%s|%s|P|3|%d|%s", opp_sockfd, opp_name, tradePetIndex, buffer2); +#endif + lssproto_TD_send(sockfd, buffer); + } + } + } + } + // ü End + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ŵȡҷ + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + dragflag1 = false; + dragflag2 = false; +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + talkwndflag = false; +#endif + } +#endif + //δµťȫԭ + for (i = 2; i <= 8; i++) + { + if (mouse.state & MOUSE_LEFT_CRICK && tradeWndBtnFlag[i] == TRUE) + tradeWndBtnFlag[i] = TRUE; + else + tradeWndBtnFlag[i] = FALSE; + } + // Ӵ + if (pActMenuWnd4 != NULL) + { + // ȡӴ׼X , Y + x = pActMenuWnd4->x; + y = pActMenuWnd4->y; + // ˽ֵʾ + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + //Ի + if (tradetalkwndflag != false) + { + for (i = 3; i >= 0; i--) + { + sprintf_s(moji, "%s", talkmsg[i]); + StockFontBuffer(talkwndx - 154, talkwndy - 26 + i * 20, FONT_PRIO_AFRONT, FONT_PAL_YELLOW, moji, 0); + } + tradeWndFontNo[14] = StockDispBuffer(talkwndx, talkwndy, DISP_PRIO_BOX3, CG_TRADE_TALK_WND, 2); + } +#endif + int ShowPoint; + int j = 0; + //ԷĽ嵥ֿʼλ + ShowPoint = (drag2Y - 257) / 4; + //ҷList嵥 + for (i = 0; i < 21; i++) //б xiezi + { + if (tradeList[i + 1].data != -1) + { + mytradelist[j] = i + 1; + j++; + } + } + j = 0; + //ԷList嵥 + for (i = 21; i < 42; i++) //б xiezi + { + if (tradeList[i + 1].data != -1) + { + opptradelist[j] = i + 1; + j++; + } + } + j = 0; + //ʾҷ嵥 + for (i = ShowPoint; i < ShowPoint + 5 && i < 21; i++) //嵥 xiezi + { + if (mytradelist[i] == -1) break; + //˵õHitBoxʱ + // if( MakeHitBox( x + 10 , y + 226 + j * 29, x + 280 , y + 244 + j * 29 , DISP_PRIO_IME3 ) == TRUE ){ + // } + sprintf_s(moji, "%c", tradeList[mytradelist[i]].kind); + //ʾ + if (strcmp(moji, "I") == 0) + { + sprintf_s(moji, "%s", tradeList[mytradelist[i]].name); + StockFontBuffer(x + 12, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + +#ifdef _ITEM_PILENUMS + sprintf_s(moji, "x%d", tradeList[mytradelist[i]].pilenum); + StockFontBuffer(x + 180, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); +#endif +#ifdef _NPC_ITEMUP + //if( MakeHitBox( x + 10 , y + 226 + j * 29, x + 280 , y + 244 + j * 29 , DISP_PRIO_IME3 ) == TRUE ) + // ShowItemup(tradeList[mytradelist[i]].itemup,x+160,y + 246 + j * 29); +#endif + sprintf_s(moji, "%s", tradeList[mytradelist[i]].damage); + StockFontBuffer(x + 220, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + j++; + } + //ʾ + else if (strcmp(moji, "P") == 0) + { + int colors = 0; + int mylist = mytradelist[i]; + sprintf_s(moji, "%s", tradeList[mylist].name); + StockFontBuffer(x + 12, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + + if (strcmp(tradeList[mylist].freename, tradeList[mylist].name)) + { + sprintf_s(moji, "[%s]", tradeList[mylist].freename); + colors = FONT_PAL_RED; + StockFontBuffer(x + 102, y + 228 + j * 29, FONT_PRIO_FRONT, colors, moji, 0); + } +#ifdef _PET_2TRANS + sprintf_s( moji , "Lv:%d%s" , tradeList[mylist].level, ""); + if (tradeList[mylist].trns == 1) + sprintf_s(moji, "Lv:%d%s", tradeList[mylist].level, "һת"); + else if (tradeList[mylist].trns == 2) + sprintf_s(moji, "Lv:%d%s", tradeList[mylist].level, "ת"); +#ifdef _SHOW_FUSION + if (LOWORD(tradeList[mylist].fusion) == 1) + sprintf_s(moji, "Lv:%d%s", tradeList[mylist].level, "ں"); +#endif +#else + sprintf_s(moji, "Lv:%d%s", tradeList[mylist].level, (tradeList[mylist].trns == 0) ? "" : "ת"); +#endif + StockFontBuffer(x + 220, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + + j++; + } + //ʾǮ + else if (strcmp(moji, "G") == 0) + { + StockFontBuffer(x + 12, y + 228 + j * 29, FONT_PRIO_FRONT, 0, "ʯ", 0); + sprintf_s(moji, "%d", tradeList[mytradelist[i]].data); + StockFontBuffer(x + 102, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", "Gold"); + StockFontBuffer(x + 220, y + 228 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + j++; + } + if (j == 5) + break; + } + j = 0; + //ԷĽ嵥ֿʼλ + ShowPoint = (drag1Y - 67) / 4; + //ʾԷ嵥 + for (i = ShowPoint; i < ShowPoint + 5 && i < 21; i++) //嵥 xiezi + { + if (opptradelist[i] == -1) break; + //˵õHitBoxʱ + // if( MakeHitBox( x + 10 , y + 37 + j * 29, x + 280 , y + 55 + j * 29 , DISP_PRIO_IME3 ) == TRUE ){ + // } + sprintf_s(moji, "%c", tradeList[opptradelist[i]].kind); + //ʾ + if (strcmp(moji, "I") == 0) + { + int colors = 0; + int opptradlist = opptradelist[i]; + // Terry modify for ԭ 2004/6/9 + sprintf_s(moji, "%s", tradeList[opptradlist].name); + // sprintf_s( moji , "%s" , tradeList[ opptradlist].freename ) ; + // if( strcmp( tradeList[opptradlist].name, tradeList[opptradlist].freename ) ){ + // sprintf_s( moji , "[%s]" , tradeList[ opptradlist].freename ) ; + // colors = 6; + // } + StockFontBuffer(x + 12, y + 40 + j * 29, FONT_PRIO_FRONT, colors, moji, 0); +#ifdef _ITEM_PILENUMS + sprintf_s(moji, "x%d", tradeList[opptradelist[i]].pilenum); + StockFontBuffer(x + 180, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); +#endif +#ifdef _NPC_ITEMUP + //if( MakeHitBox( x + 10 , y + 37 + j * 29, x + 280 , y + 55 + j * 29 , DISP_PRIO_IME3 ) == TRUE ) + // ShowItemup(tradeList[opptradelist[i - 22]].itemup,x+160,y + 57 + j * 29); +#endif + + sprintf_s(moji, "%s", tradeList[opptradelist[i]].damage); + StockFontBuffer(x + 220, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + j++; + } + else if (strcmp(moji, "P") == 0) + {//ʾ + int colors = 0; //FONT_PAL_RED + int opplist = opptradelist[i]; + sprintf_s(moji, "%s", tradeList[opplist].name); + StockFontBuffer(x + 12, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); +#ifdef _SHOW_FUSION + // change fix ֻΪʾ-----> [] + if (strcmp(tradeList[opplist].freename, tradeList[opplist].name) == 0) + { + sprintf_s(moji, "[]"); + colors = FONT_PAL_RED; + StockFontBuffer(x + 102, y + 40 + j * 29, FONT_PRIO_FRONT, colors, moji, 0); + } +#endif + if (strcmp(tradeList[opplist].freename, tradeList[opplist].name)) + { + sprintf_s(moji, "[%s]", tradeList[opplist].freename); + colors = FONT_PAL_RED; + StockFontBuffer(x + 102, y + 40 + j * 29, FONT_PRIO_FRONT, colors, moji, 0); + } +#ifdef _PET_2TRANS + sprintf_s( moji , "Lv:%d%s" , tradeList[opplist].level, (tradeList[opplist].trns==0)?"":""); + if (tradeList[opplist].trns == 1) + sprintf_s(moji, "Lv:%d%s", tradeList[opplist].level, "һת"); + else if (tradeList[opplist].trns == 2) + sprintf_s(moji, "Lv:%d%s", tradeList[opplist].level, "ת"); +#ifdef _SHOW_FUSION + if (LOWORD(tradeList[opplist].fusion) == 1) + sprintf_s(moji, "Lv:%d%s", tradeList[opplist].level, "ں"); +#endif +#else + sprintf_s(moji, "Lv:%d%s", tradeList[opplist].level, (tradeList[opplist].trns == 0) ? "" : "ת"); +#endif + StockFontBuffer(x + 220, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + j++; + } + //ʾǮ + else if (strcmp(moji, "G") == 0) + { + StockFontBuffer(x + 12, y + 40 + j * 29, FONT_PRIO_FRONT, 0, "ʯ", 0); + sprintf_s(moji, "%d", tradeList[opptradelist[i]].data); + StockFontBuffer(x + 102, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", "Gold"); + StockFontBuffer(x + 220, y + 40 + j * 29, FONT_PRIO_FRONT, 0, moji, 0); + + j++; + } + if (j == 5) + break; + } +#endif + sprintf_s(moji, "%7d", pc.gold); + StockFontBuffer(x + 550, y + 65, FONT_PRIO_FRONT, 0, moji, 0); + // Focusֶʱʾԭֵ + if (Tradeflag == false) + { + sprintf_s(moji, "%7d", tradeWndDropGold); + StockFontBuffer(x + 550, y + 120, FONT_PRIO_FRONT, 0, moji, 0); + } + if (pet[tradePetIndex].useFlag + && pc.ridePetNo != tradePetIndex) + { + if (pActPet3 == NULL) + { +#ifdef _LIZARDPOSITION // (ɿ) Syu ADD ʾλù + if ((pet[tradePetIndex].graNo == 101493) || (pet[tradePetIndex].graNo == 101494) || + (pet[tradePetIndex].graNo == 101495) || (pet[tradePetIndex].graNo == 101496)) + { + pActPet3 = MakeAnimDisp(480, 230, pet[tradePetIndex].graNo, ANIM_DISP_PET); + } + else + pActPet3 = MakeAnimDisp(480, 230, pet[tradePetIndex].graNo, ANIM_DISP_PET); +#else + pActPet3 = MakeAnimDisp(400, /*175*/145, pet[tradePetIndex].graNo, ANIM_DISP_PET); +#endif + } + + if (pet[tradePetIndex].freeName[0] != NULL) + CenteringStr(pet[tradePetIndex].freeName, moji, PET_NAME_LEN); + else + CenteringStr(pet[tradePetIndex].name, moji, PET_NAME_LEN); + + //תʱɫʾɫ +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ϵͳλƫ + if (pet[tradePetIndex].trn == 1) + StockFontBuffer(x + 330, y + 33, FONT_PRIO_FRONT, 1, moji, 0); + else + StockFontBuffer(x + 330, y + 33, FONT_PRIO_FRONT, 0, moji, 0); + + sprintf_s(moji, "%3d", pet[tradePetIndex].level); + StockFontBuffer(x + 485, y + 105, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[tradePetIndex].atk); + StockFontBuffer(x + 485, y + 129, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[tradePetIndex].def); + StockFontBuffer(x + 485, y + 153, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[tradePetIndex].quick); + StockFontBuffer(x + 485, y + 177, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%3d", pet[tradePetIndex].maxHp); + StockFontBuffer(x + 485, y + 201, FONT_PRIO_FRONT, 0, moji, 0); +#endif + } + + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + // Խ׽е״̬Buttonʽ + if (pc.trade_confirm == 1 || pc.trade_confirm == 3) + tradeWndFontNo[0] = StockDispBuffer(x + 59, y + 390, DISP_PRIO_IME3, CG_TRADE_LOCK_BTN, 2); + if (pc.trade_confirm == 4) + tradeWndFontNo[0] = StockDispBuffer(x + 59, y + 390, DISP_PRIO_IME3, CG_TRADE_OK_BTN, 2); + //ƫ + tradeWndFontNo[1] = StockDispBuffer(x + 240, y + 390, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN, 2); +#endif + + tradeWndFontNo[2] = StockDispBuffer(x + 452 + 20, y + 63 + 8, DISP_PRIO_IME3, CG_TRADE_LEFT_BTN_UP + tradeWndBtnFlag[2], 2); + tradeWndFontNo[3] = StockDispBuffer(x + 486 + 20, y + 63 + 8, DISP_PRIO_IME3, CG_TRADE_RIGHT_BTN_UP + tradeWndBtnFlag[3], 2); + tradeWndFontNo[4] = StockDispBuffer(x + 554 - 94, y + 93 + 106, DISP_PRIO_IME3, CG_TRADE_UP_BTN_UP + tradeWndBtnFlag[4], 2); + tradeWndFontNo[5] = StockDispBuffer(x + 560 - 94, y + 93 + 106, DISP_PRIO_IME3, CG_TRADE_DOWN_BTN_UP + tradeWndBtnFlag[5], 2); +#ifdef _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + if (TradeBtnflag == false) + tradeWndFontNo[6] = StockDispBuffer(x + 562 - 62 + 25, y + 148 + 108 + 8, DISP_PRIO_IME3, CG_TRADE_PUT_BTN_UP + tradeWndBtnFlag[6], 2); +#else + tradeWndFontNo[6] = StockDispBuffer(x + 562 - 62 + 25, y + 148 + 108 + 8, DISP_PRIO_IME3, CG_TRADE_PUT_BTN_UP + tradeWndBtnFlag[6], 2); +#endif +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ƫ + tradeWndFontNo[7] = StockDispBuffer(x + 365 - 62 + 25, y + 190 + 108 + 8, DISP_PRIO_IME3, CG_TRADE_PUT_BTN_UP + tradeWndBtnFlag[7], 2); +#endif +#ifndef _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + tradeWndFontNo[8] = StockDispBuffer(x + 55 + 25, y + 190 + 18, DISP_PRIO_IME3, CG_MAIL_WND_CLEAR_BTN_UP + tradeWndBtnFlag[8], 2); +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ƫ + //ʾ˫ + StockFontBuffer(x + 5, y + 193, FONT_PRIO_FRONT, FONT_PAL_PURPLE, pc.name, 0); + StockFontBuffer(x + 5, y + 6, FONT_PRIO_FRONT, FONT_PAL_PURPLE, opp_name, 0); + //Ӵť + tradeWndFontNo[21] = StockDispBuffer(x + 150, y + 390, DISP_PRIO_IME3, CG_TRADE_VIEW_BTN, 2); + //ҷҷť + tradeWndFontNo[18] = StockDispBuffer(x + 302, y + 42, DISP_PRIO_IME3, CG_TRADE_SCROLL_UP, 2); + //ҷť + tradeWndFontNo[19] = StockDispBuffer(x + 302, y + 176, DISP_PRIO_IME3, CG_TRADE_SCROLL_DOWN, 2); + //ҷť + tradeWndFontNo[20] = StockDispBuffer(x + 302, y + drag1Y, DISP_PRIO_IME3, CG_TRADE_SCROLL_BTN, 2); + //Էҷť + tradeWndFontNo[15] = StockDispBuffer(x + 302, y + 232, DISP_PRIO_IME3, CG_TRADE_SCROLL_UP, 2); + //Էť + tradeWndFontNo[16] = StockDispBuffer(x + 302, y + 366, DISP_PRIO_IME3, CG_TRADE_SCROLL_DOWN, 2); + //Էť + tradeWndFontNo[17] = StockDispBuffer(x + 302, y + drag2Y, DISP_PRIO_IME3, CG_TRADE_SCROLL_BTN, 2); +#endif + + // αڽλʱ + if (MakeHitBox(x + 530, y + 115, x + +530 + 86, y + 115 + 25, DISP_PRIO_IME3) == TRUE) + { + // »ȡfocusʼ + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + strcpy(TradeBuffer.buffer, ""); + TradeBuffer.buffer[0] = NULL; + TradeBuffer.cursor = 0; + TradeBuffer.cnt = 0; + Tradeflag = true; + GetKeyInputFocus(&TradeBuffer); + play_se(217, 320, 240); + } + } + // focusֶʱʾbuffer + if (Tradeflag == true) + { + TradeBuffer.x = pActMenuWnd4->x + 600 - strlen(TradeBuffer.buffer) * 7; + TradeBuffer.y = pActMenuWnd4->y + 120; + StockFontBuffer2(&TradeBuffer); + tradeWndDropGold = atoi(TradeBuffer.buffer); + if (atoi(TradeBuffer.buffer) >= pc.gold) + { + sprintf_s(TradeBuffer.buffer, "%d", pc.gold); + tradeWndDropGold = pc.gold; + } + } + + if (pc.trade_confirm == 2) + { +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ƫ + StockFontBuffer(x + 220, y + 194, FONT_PRIO_FRONT, FONT_PAL_RED, "", 0); + } + if (pc.trade_confirm == 3) + { + StockFontBuffer(x + 210, y + 194, FONT_PRIO_FRONT, FONT_PAL_RED, "Է", 0); + } + if (pc.trade_confirm == 4) + { + if (tradeStatus == 2) + StockFontBuffer(x + 220, y + 194, FONT_PRIO_FRONT, FONT_PAL_RED, "ȷ", 0); + else + StockFontBuffer(x + 210, y + 194, FONT_PRIO_FRONT, FONT_PAL_RED, "ȷ", 0); + } +#endif + } +#ifdef _NEW_ITEM_ + for (i = 0; i < 3; i++){ + if (i == ҳ){ + StockDispBuffer(722, 335 + i * 56, DISP_PRIO_IME2, 55223 + i, 1); + } + else{ + BOOL flg = FALSE; + if (i){ + if (pc.״̬ & 1 << i){ + flg = TRUE; + } + } + else flg = TRUE; + if (flg){ + StockDispBuffer(727 - 11, 335 + i * 56, DISP_PRIO_IME2, 55226 + i, 1); + if (MakeHitBox(717 - 11, 307 + i * 56, 717 + 20 - 11, 304 + i * 56 + 60, DISP_PRIO_IME4)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + ҳ = i; + } + } + } + else StockDispBuffer(727 - 11, 335 + i * 56, DISP_PRIO_IME2, 55229 + i, 1); + } + } +#endif + for (i = MAX_ITEM - 1; i >= MAX_ITEMSTART; i--) + { +#ifdef _NEW_ITEM_ + int ʼ = MAX_ITEMSTART + MAX_MAXHAVEITEM*ҳ; + int ߽ = ʼ + MAX_MAXHAVEITEM; + if (i >= MAX_ITEMSTART){ + if (i < ʼ || i >= ߽) continue; + } +#endif +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ѡȡ׵ĸӡ +#ifdef _ITEM_PILENUMS + if (itemflag[i - MAX_ITEMSTART] <= 0) + { +#else + if (itemflag[i - MAX_ITEMSTART] == 1) + { +#endif + //ԭΪʾԭ߲ + //StockDispBuffer( ItemBuffer[ i ].defX, ItemBuffer[ i ].defY, ItemBuffer[ i ].dispPrio, CG_TRADE_SEAL , 0 ); + //Ϊأֱʾ + + continue; + + } +#endif + + if (MakeHitBox(x + ItemBuffer[i].defX - 35, y + ItemBuffer[i].defY - 22, + x + ItemBuffer[i].defX + 15, y + ItemBuffer[i].defY + 28, DISP_PRIO_IME3) == TRUE) + { +#ifdef _TELLCHANNEL + // Terry fix 2003/12/16 for Ӵʱ,ʾƷ˵ʾ뷨 + //TaskBarFlag = TRUE;вҪ + bShowItemExplain = TRUE; // + // end +#endif + // λеߵ + if (pc.item[i].useFlag == TRUE && ItemBuffer[i].mixFlag <= 2) + { + char *splitPoint = pc.item[i].memo; + int color = pc.item[i].color; + // ƷܷʹCheck + if (pc.transmigration == 0 && pc.level < pc.item[i].level) + color = FONT_PAL_RED; + // ʾ + StockFontBuffer(0, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, color, pc.item[i].name, 0); + // ˵ + StockFontBuffer(160, 460 + DISPLACEMENT_Y, FONT_PRIO_FRONT, 0, splitPoint, 0); +#ifdef _NPC_ITEMUP + ShowItemup(pc.item[i].itemup, mouse.nowPoint.x, mouse.nowPoint.y); +#endif + } + // ڵϵµ + if (mouse.onceState & MOUSE_LEFT_DBL_CRICK) + { + if (tradeStatus != 1) return; + if (pc.trade_confirm == 2 || pc.trade_confirm == 4) return; + // ϳر + ItemBuffer[i].mixFlag = FALSE; + // ȷϸλе + if (pc.item[i].useFlag == TRUE){ + ItemBuffer[i].dragFlag = TRUE; + mouse.itemNo = i; + // ѡڻ + itemNo = -1; + } +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + if (mouse.itemNo != -1) + { + //ҳ + char buf[1024]; + + int chkindex = 0, frontempIndex = 0; + //tradeListռǷ xiezi + for (int scanindex = 1; scanindex < 16; scanindex++) + { + if (tradeList[chkindex].data == i) + { + chkindex = scanindex; + break; + } + if (tradeList[scanindex].data == -1 && frontempIndex < 1) + { + frontempIndex = scanindex; + } + } + chkindex = chkindex > 0 ? chkindex : frontempIndex; + + if (chkindex > 0) + { + tradeList[chkindex].kind = 'I'; + tradeList[chkindex].data = i; + strcpy(tradeList[chkindex].name, pc.item[i].name); + strcpy(tradeList[chkindex].damage, pc.item[i].damage); +#ifdef _ITEM_PILENUMS + itemflag[i - MAX_ITEMSTART]--; +#else + itemflag[i - MAX_ITEMSTART] = 1; +#endif +#ifdef _ITEM_PILENUMS + tradeList[chkindex].pilenum = pc.item[i].pile - itemflag[i - MAX_ITEMSTART]; +#endif +#ifdef _NPC_ITEMUP + tradeList[i - 4].itemup = pc.item[i].itemup; +#endif + sprintf_s(buf, "T|%s|%s|I|1|%d", opp_sockfd, opp_name, i); + lssproto_TD_send(sockfd, buf); + } + } +#endif + mouse.itemNo = -1; + } + } + if (pc.item[i].useFlag == TRUE) + { + // ǺϳƷ + if (ItemBuffer[i].mixFlag <= 2) { + char buf[256]; + // ʾ + StockDispBuffer(x + ItemBuffer[i].defX - 8, y + ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + + +#ifdef _ITEM_PILENUMS + sprintf_s(buf, "%d", itemflag[i - MAX_ITEMSTART]); + StockFontBuffer(x + ItemBuffer[i].defX - 8, y + ItemBuffer[i].defY, FONT_PRIO_FRONT, FONT_PAL_RED, buf, 0); +#endif + + } + else if (ItemBuffer[i].mixFlag == 10) + StockDispBuffer(x + ItemBuffer[i].defX - 8, y + ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + else if (ItemBuffer[i].mixFlag == 11) + StockDispBuffer(x + ItemBuffer[i].defX - 8, y + ItemBuffer[i].defY, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + else if (ItemBuffer[i].mixFlag == 3) + StockDispBuffer(pActPet2->x, pActPet2->y - 16, DISP_PRIO_DRAG, pc.item[i].graNo, 0); + else if (ItemBuffer[i].mixFlag == 4) + StockDispBuffer(pActPet2->x, pActPet2->y, ItemBuffer[i].dispPrio, pc.item[i].graNo, 0); + + } + + } + } +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + } + // Ӵ + else if (SecondTradeWndflag == true) + { + MainTradeWndflag = false; + if (pActMenuWnd4 != NULL && SecondTradeWnd != NULL) + { + x = SecondTradeWnd->x; + y = SecondTradeWnd->y; +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + //Ի + if (tradetalkwndflag != false) + { + for (i = 3; i >= 0; i--) + { + sprintf_s(moji, "%s", talkmsg[i]); + StockFontBuffer(talkwndx - 154, talkwndy - 26 + i * 20, FONT_PRIO_AFRONT, FONT_PAL_YELLOW, moji, 0); + } + SecondtradeWndFontNo[4] = StockDispBuffer(talkwndx, talkwndy, DISP_PRIO_BOX3, CG_TRADE_TALK_WND, 2); + } +#endif + SecondtradeWndFontNo[0] = StockDispBuffer(x + 254, y + 380, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN, 2); + SecondtradeWndFontNo[1] = StockDispBuffer(x + 159, y + 380, DISP_PRIO_IME3, CG_TRADE_BACK_BTN, 2); + //׽״̬ + if (pc.trade_confirm == 1 || pc.trade_confirm == 3) + SecondtradeWndFontNo[2] = StockDispBuffer(x + 63, y + 380, DISP_PRIO_IME3, CG_TRADE_LOCK_BTN, 2); + if (pc.trade_confirm == 4) + SecondtradeWndFontNo[2] = StockDispBuffer(x + 63, y + 380, DISP_PRIO_IME3, CG_TRADE_OK_BTN, 2); + + sprintf_s(moji, "%7d", tradeWndDropGoldGet); + +#ifdef _PET_ITEM + // ʾװ + if (locknum != -1 && tradeList[locknum + 37].data != -1) + { + if (bViewPetEquip) + SecondtradeWndFontNo[5] = StockDispBuffer(x + 259, y + 310, DISP_PRIO_IME3, 26472, 2); + else + SecondtradeWndFontNo[5] = StockDispBuffer(x + 259, y + 310, DISP_PRIO_IME3, 26471, 2); + } +#endif + + //ʾǮ + if (tradeWndDropGoldGet > 0) + StockFontBuffer(x + 95, y + 336, FONT_PRIO_FRONT, 0, moji, 0); + for (i = 0; i < 5; i++) + { + if (MakeHitBox(x + 320, y + 12 + i * 42, x + 600, y + 51 + i * 42, DISP_PRIO_IME3) == TRUE) + { +#ifdef _TRADELOCKBTN // (ɿ) Syu ADD + if (mouse.onceState & MOUSE_LEFT_CRICK) + { +#ifdef _PET_ITEM + bViewPetEquip = FALSE; + HitDispNo = 0; +#endif + locknum = i; + locknum2 = -1; + } + if (locknum == -1) + { + locknum = i; + locknum2 = -1; + } + } + if (locknum != -1) + { + if (tradeList[locknum + 37].data != -1) + { +#ifdef _PET_ITEM + if (bViewPetEquip) + { + int iY = 251, iColor; + char *splitPoint; + + // ʾװĵͼװ + for (int iCount = 0; iCount < PET_EQUIPNUM; iCount++) + { + StockDispBuffer(ItemBuffer[iCount].defX, ItemBuffer[iCount].defY, DISP_PRIO_IME3, nPetItemEquipBmpNumber[iCount][0], 0); + if (opp_pet[locknum].oPetItemInfo[iCount].bmpNo > 0) + StockDispBuffer(ItemBuffer[iCount].defX, ItemBuffer[iCount].defY, DISP_PRIO_ITEM, opp_pet[locknum].oPetItemInfo[iCount].bmpNo, 0); + } + for (int iCount = 0; iCount < PET_EQUIPNUM; iCount++) + { + // ʾװ + if (MakeHitBox( ItemBuffer[iCount].defX - 26, ItemBuffer[iCount].defY - 26, + ItemBuffer[iCount].defX + 26, ItemBuffer[iCount].defY + 23, DISP_PRIO_IME3) == TRUE) + { + if (opp_pet[locknum].oPetItemInfo[iCount].bmpNo > 0) + { + iColor = opp_pet[locknum].oPetItemInfo[iCount].color; + splitPoint = opp_pet[locknum].oPetItemInfo[iCount].memo; + // װ + StockFontBuffer(x + 25, y + 195, FONT_PRIO_FRONT, iColor, opp_pet[locknum].oPetItemInfo[iCount].name,0); + // ;ö + sprintf_s(moji, ";ö(%s)", opp_pet[locknum].oPetItemInfo[iCount].damage); + StockFontBuffer(x + 25, y + 215, FONT_PRIO_FRONT, iColor, moji, 0); + + // ʾ + while (1) + { + if (strlen(splitPoint) > 28) + { + sprintf_s(moji, 28, "%s", splitPoint); + moji[28] = NULL; + if (GetStrLastByte(moji) == 3) + { + moji[27] = NULL; + splitPoint += 27; + } + else + { + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x + 25, iY, FONT_PRIO_FRONT, 0, moji, 0); + iY += 24; + } + else + { + strcpy(moji, splitPoint); + StockFontBuffer(x + 25, iY, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + } + } + } + } + else +#endif + { + //Action + if (SecondActPet == NULL) { + ShowPetNum = atoi(opp_pet[locknum].opp_petgrano); + SecondActPet = MakeAnimDisp(x + 215, y + 130, ShowPetNum, ANIM_DISP_PET); + } + //Ѵʾij + else if (SecondActPet != NULL && ShowPetNum != atoi(opp_pet[locknum].opp_petgrano)) { + DeathAction(SecondActPet); + SecondActPet = NULL; + ShowPetNum = atoi(opp_pet[locknum].opp_petgrano); + SecondActPet = MakeAnimDisp(x + 215, y + 130, atoi(opp_pet[locknum].opp_petgrano), ANIM_DISP_PET); + } + + //opp_petfreename + //ʾֵ ( ) + StockDispBuffer(x + 95, y + 40, DISP_PRIO_IME3, CG_TRADE_LINE, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petname); + StockFontBuffer(x + 55, y + 30, FONT_PRIO_FRONT, 0, moji, 0); + + if (strcmp(opp_pet[locknum].opp_petfreename, opp_pet[locknum].opp_petname)){ + sprintf_s(moji, "[%s]", opp_pet[locknum].opp_petfreename); + StockFontBuffer(x + 155, y + 30, FONT_PRIO_FRONT, 6, moji, 0); + } + + StockDispBuffer(x + 55, y + 70, DISP_PRIO_IME3, CG_TRADE_LV_LINE, 0); + + sprintf_s(moji, "%3d", atoi(opp_pet[locknum].opp_petlevel)); + StockFontBuffer(x + 55, y + 62, FONT_PRIO_FRONT, 0, moji, 0); + +#ifdef _PET_2TRANS + sprintf_s( moji,"%s", "" ); + if (atoi(opp_pet[locknum].opp_pettrans) == 1) + sprintf_s(moji, "%s", "һת"); + else if (atoi(opp_pet[locknum].opp_pettrans) == 2) + sprintf_s(moji, "%s", "ת"); +#ifdef _SHOW_FUSION + if (LOWORD(atoi(opp_pet[locknum].opp_fusion)) == 1) + sprintf_s(moji, "%s", "ں"); +#endif +#else + sprintf_s(moji, "%s", (atoi(opp_pet[locknum].opp_pettrans) == 0) ? "" : "ת"); +#endif + StockFontBuffer(x + 90, y + 62, FONT_PRIO_FRONT, 2, moji, 0); + + + StockDispBuffer(x + 55, y + 100, DISP_PRIO_IME3, CG_TRADE_HP_LINE, 0); +#ifdef _PETBLESS_ + sprintf_s(moji, "%3d", abs(atoi(opp_pet[locknum].opp_petshowhp))); + if (atoi(opp_pet[locknum].opp_petshowhp) < 0) + StockFontBuffer(x + 55, y + 92, FONT_PRIO_FRONT, FONT_PAL_RED, moji, 0); + else + StockFontBuffer(x + 55, y + 92, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(x + 55, y + 130, DISP_PRIO_IME3, CG_TRADE_ATK_LINE, 0); + + sprintf_s(moji, "%3d", abs(atoi(opp_pet[locknum].opp_petatk))); + if (atoi(opp_pet[locknum].opp_petatk) < 0) + StockFontBuffer(x + 55, y + 124, FONT_PRIO_FRONT, FONT_PAL_RED, moji, 0); + else + StockFontBuffer(x + 55, y + 124, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(x + 55, y + 160, DISP_PRIO_IME3, CG_TRADE_DEF_LINE, 0); + sprintf_s(moji, "%3d", abs(atoi(opp_pet[locknum].opp_petdef))); + + if(atoi(opp_pet[locknum].opp_petdef) < 0) + StockFontBuffer(x + 55, y + 154, FONT_PRIO_FRONT, FONT_PAL_RED, moji, 0); + else + StockFontBuffer(x + 55, y + 154, FONT_PRIO_FRONT, 0, moji, 0); + StockDispBuffer(x + 55, y + 190, DISP_PRIO_IME3, CG_TRADE_DEX_LINE, 0); + sprintf_s(moji, "%3d",abs( atoi(opp_pet[locknum].opp_petquick))); + if(atoi(opp_pet[locknum].opp_petquick) < 0) + StockFontBuffer(x + 55, y + 184, FONT_PRIO_FRONT, FONT_PAL_RED, moji, 0); + else + StockFontBuffer(x + 55, y + 184, FONT_PRIO_FRONT, 0, moji, 0); +#else + sprintf_s(moji, "%3d", atoi(opp_pet[locknum].opp_petshowhp)); + StockFontBuffer(x + 55, y + 92, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(x + 55, y + 130, DISP_PRIO_IME3, CG_TRADE_ATK_LINE, 0); + sprintf_s(moji, "%3d", atoi(opp_pet[locknum].opp_petatk)); + StockFontBuffer(x + 55, y + 124, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(x + 55, y + 160, DISP_PRIO_IME3, CG_TRADE_DEF_LINE, 0); + sprintf_s(moji, "%3d", atoi(opp_pet[locknum].opp_petdef)); + StockFontBuffer(x + 55, y + 154, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(x + 55, y + 190, DISP_PRIO_IME3, CG_TRADE_DEX_LINE, 0); + sprintf_s(moji, "%3d", atoi(opp_pet[locknum].opp_petquick)); + StockFontBuffer(x + 55, y + 184, FONT_PRIO_FRONT, 0, moji, 0); + +#endif + for (j = 0; j < 4; j++) + StockDispBuffer(x + 100, y + 220 + j * 30, DISP_PRIO_IME3, CG_TRADE_SK1_LINE + j, 0); + for (j = 4; j < atoi(opp_pet[locknum].opp_petslot); j++) + StockDispBuffer(x + 230, y + 220 + (j - 4) * 30, DISP_PRIO_IME3, CG_TRADE_SK5_LINE + j - 4, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill1); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 65, y + 212, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill2); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 65, y + 242, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill3); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 65, y + 272, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill4); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 65, y + 302, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill5); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 195, y + 212, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill6); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 195, y + 242, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%s", opp_pet[locknum].opp_petskill7); + if (strcmp(moji, "(null)") != 0) + StockFontBuffer(x + 195, y + 272, FONT_PRIO_FRONT, 0, moji, 0); + } + } + else if (SecondActPet != NULL) { + DeathAction(SecondActPet); + SecondActPet = NULL; + } +#endif + } + //ʾֵ ( ҷ ) + if (tradeList[i + 37].data != -1) + { + sprintf_s(moji, "%s", opp_pet[i].opp_petname); + StockFontBuffer(x + 322, y + 13 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + + if (strcmp(opp_pet[i].opp_petname, opp_pet[i].opp_petfreename)) + { + sprintf_s(moji, "[%s]", opp_pet[i].opp_petfreename); + StockFontBuffer(x + 442, y + 13 + i * 42, FONT_PRIO_FRONT, 6, moji, 0); + } + +#ifdef _PET_2TRANS + sprintf_s( moji,"%s", "" ); + if (atoi(opp_pet[i].opp_pettrans) == 1) + sprintf_s(moji, "%s", "һת"); + else if (atoi(opp_pet[i].opp_pettrans) == 2) + sprintf_s(moji, "%s", "ת"); +#ifdef _SHOW_FUSION + if (LOWORD(atoi(opp_pet[i].opp_fusion)) == 1) + sprintf_s(moji, "%s", "ں"); +#endif +#else + sprintf_s(moji, "%s", (atoi(opp_pet[i].opp_pettrans) == 0) ? "" : "ת"); +#endif + StockFontBuffer(x + 590, y + 13 + i * 42, FONT_PRIO_FRONT, 2, moji, 0); + + sprintf_s(moji, "%4d", abs(atoi(opp_pet[i].opp_petshowhp))); + StockFontBuffer(x + 504, y + 33 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + sprintf_s(moji, "%3d", atoi(opp_pet[i].opp_petlevel)); + StockFontBuffer(x + 558, y + 33 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + sprintf_s(moji, "%3d", abs(atoi(opp_pet[i].opp_petatk))); + StockFontBuffer(x + 345, y + 33 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + sprintf_s(moji, "%3d", abs(atoi(opp_pet[i].opp_petdef))); + StockFontBuffer(x + 398, y + 33 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + sprintf_s(moji, "%3d", abs(atoi(opp_pet[i].opp_petquick))); + StockFontBuffer(x + 451, y + 33 + i * 42, FONT_PRIO_FRONT, atoi(opp_pet[i].opp_pettrans), moji, 0); + } + } + //ʾ + for (i = 0; i < 3; i++) + { + for (j = 0; j < 5; j++) + { + if (MakeHitBox(x + 368 + 51 * j - 35, y + 265 + 47 * i - 23, + x + 368 + 51 * j + 18, y + 265 + 47 * i + 23, DISP_PRIO_IME3) == TRUE) + { +#ifdef _TRADELOCKBTN // (ɿ) Syu ADD + if (mouse.onceState & MOUSE_LEFT_CRICK) { + locknum2 = i * 5 + j; + locknum = -1; + } + if (locknum2 == -1) { + locknum2 = i * 5 + j; + locknum = -1; + } + if (SecondActPet != NULL) { + DeathAction(SecondActPet); + SecondActPet = NULL; + } +#ifdef _PET_ITEM + bViewPetEquip = FALSE; +#endif + } + if (locknum2 != -1) + { + x = SecondTradeWnd->x; + y = SecondTradeWnd->y; + if (tradeList[locknum2 + 22].data != -1) + { + //˵ + char *splitPoint = opp_item[locknum2].effect; + while (1) + { + if (y > 40) + break; + if (strlen(splitPoint) > 28) + { + strncpy_s(moji, splitPoint, 28); + moji[28] = NULL; + if (GetStrLastByte(moji) == 3) + { + moji[27] = NULL; + splitPoint += 27; + } + else + { + moji[28] = NULL; + splitPoint += 28; + } + StockFontBuffer(x + 50, y + 160, FONT_PRIO_FRONT, 0, moji, 0); y += 40; + } + else + { + strcpy(moji, splitPoint); + StockFontBuffer(x + 50, y + 160, FONT_PRIO_FRONT, 0, moji, 0); + break; + } + } + StockDispBuffer(x + 80, y + 90, DISP_PRIO_IME3, atoi(opp_item[locknum2].graph), 0); + + sprintf_s(moji, "%s ", opp_item[locknum2].name); + StockFontBuffer(x + 50, y + 120, FONT_PRIO_FRONT, 0, moji, 0); + if (strcmp(opp_item[locknum2].name, opp_item[locknum2].freename)) + { + sprintf_s(moji, "[%s]", opp_item[locknum2].freename); + StockFontBuffer(x + 50, y + 140, FONT_PRIO_FRONT, 6, moji, 0); + } +#ifdef _ITEM_PILENUMS + sprintf_s(moji, "x%d", tradeList[locknum2 + 22].pilenum); +#else + sprintf_s(moji, "%s", opp_item[locknum2].name); +#endif + StockFontBuffer(x + 140, y + 80, FONT_PRIO_FRONT, 0, moji, 0); +#ifdef _NPC_ITEMUP + ShowItemup(tradeList[locknum2 + 22].itemup, 240, 120); +#endif + + + if (strcmp(opp_item[locknum2].damage, "") != 0) + sprintf_s(moji, ";öȣ%s", opp_item[locknum2].damage); + StockFontBuffer(x + 50, y + 240, FONT_PRIO_FRONT, 0, moji, 0); + } +#endif + } + if (tradeList[i * 5 + j + 22].data != -1) + { + StockDispBuffer(x + 368 + 47 * j, y + 265 + 47 * i, DISP_PRIO_IME3, atoi(opp_item[i * 5 + j].graph), 0); +#ifdef _ITEM_PILENUMS + if (tradeList[i * 5 + j + 22].pilenum > 1) + { + sprintf_s(moji, "%d", tradeList[i * 5 + j + 22].pilenum); + StockFontBuffer(x + 370 + 51 * j + 10, y + 265 + 47 * i + 2, FONT_PRIO_FRONT, 0, moji, 0); + } +#endif + + } + } + } + } + if (SecondTradeWnd != NULL) { + + if (SecondTradeWnd->hp > 0) + { + //׵ڶӴ + if (pActPet3 != NULL) + { + DeathAction(pActPet3); + pActPet3 = NULL; + } + StockDispBuffer(((WINDOW_DISP *)SecondTradeWnd->pYobi)->mx, ((WINDOW_DISP *)SecondTradeWnd->pYobi)->my - 25, DISP_PRIO_MENU, CG_TRADE_VIEWWND, 1); + + if (mouse.onceState & MOUSE_LEFT_CRICK) + { + if (HitDispNo == SecondtradeWndFontNo[0]) { + //رսӴ + MenuToggleFlag &= ~JOY_CTRL_T; + //ӴرЧ + play_se(203, 320, 240); + sprintf_s(buffer, "W|%s|%s", opp_sockfd, opp_name); + //ͳȡѶϢServer֪ͨԷ + lssproto_TD_send(sockfd, buffer); + tradeStatus = 0; + tradeInit(); + pc.trade_confirm = 1; + } + else if (HitDispNo == SecondtradeWndFontNo[1]) + { + MainTradeWndflag = true; + SecondTradeWndflag = false; + //andy_add 20030610 + for (i = 0; i < MENU_TRADE_0; i++) tradeWndFontNo[i] = -2; + for (i = 0; i < 6; i++) SecondtradeWndFontNo[i] = -2; +#ifdef _PET_ITEM + InitItem3( 325, 230 ); + bViewPetEquip = FALSE; +#endif + } +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + else if (HitDispNo == SecondtradeWndFontNo[4]) + talkwndflag = true; +#endif +#ifdef _PET_ITEM + else if (HitDispNo == SecondtradeWndFontNo[5]) + { + bViewPetEquip = !bViewPetEquip; + InitItem(SecondTradeWnd->x, SecondTradeWnd->y + 20, bViewPetEquip); + } +#endif + else + LockAndOkfunction(); + } +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + if (talkwndflag == true) + { + talkwndx = mouse.nowPoint.x; + talkwndy = mouse.nowPoint.y; + } + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + talkwndflag = false; + if (mouse.onceState & MOUSE_RIGHT_CRICK) + tradetalkwndflag = false; +#endif + } + } + } + +#endif + } + break; + } + } + else if (tradeStatus != 0) + { + char buffer[1024] = ""; + tradeStatus = 0; + MenuToggleFlag &= ~JOY_CTRL_T; + sprintf_s(buffer, "W|%s|%s", opp_sockfd, opp_name); + lssproto_TD_send(sockfd, buffer); + tradeInit(); + pc.trade_confirm = 1; + } + + // Ӵֵ˽ + + + // show Bank Window + if (MenuToggleFlag & JOY_B){ + + char buffer[1024]; + int x, y, w, h; + + if (checkPcWalkFlag() == 1) closeBankman(); + + + if (joy_trg[0] & JOY_ESC + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + ) + { + closeBankman(); + return; + } + + // ????????? + if (pActMenuWnd5 == NULL){ + w = 270; h = 160; + x = (lpDraw->xSize - w) / 2; + y = (lpDraw->ySize - h) / 2; + + pActMenuWnd5 = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); + play_se(202, 320, 240); // ???????? + + } + else{ + // ?????????????? + if (pActMenuWnd5->hp > 0){ + + if (mouse.onceState & MOUSE_LEFT_CRICK){ + + // ??? + if (HitDispNo == bankWndFontNo[0]){ + closeBankman(); + return; + } + + if (HitDispNo == bankWndFontNo[1]) { + sprintf_s(buffer, "B|G|%d", pc.gold - cashGold); + if (bNewServer) + lssproto_FM_send(sockfd, buffer); + else + old_lssproto_FM_send(sockfd, buffer); + closeBankman(); + return; + } + + } + + // Add Gold + if (HitDispNo == bankWndFontNo[2]){ + + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && bankWndBtnFlag[2] == TRUE){ + + bankWndBtnFlag[2] = FALSE; + } + + if ((cashGold < CHAR_getMaxHaveGold()) && (totalGold - cashGold > 0)) { + + if (bankWndBtnFlag[2] == TRUE){ + + cashGold += bankGoldInc; + bankGoldCnt++; + + // ?ƨ??? + if (bankGoldCnt >= 30){ + // ????????????? + bankGoldCnt = 0; + // ???????? + if (bankGoldInc == 0) { + bankGoldInc = 1; + } + else{ + // ????? + bankGoldInc *= 5; + // ???????? + if (bankGoldInc > 10000) { + bankGoldInc = 10000; + } + } + } + // ???????? + if (cashGold >= CHAR_getMaxHaveGold()) { + cashGold = CHAR_getMaxHaveGold(); + play_se(220, 320, 240); + } + if (cashGold >= totalGold) { + cashGold = totalGold; + play_se(220, 320, 240); + } + + } + + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK) { + // ??? + cashGold++; + // ???????? + if (cashGold >= CHAR_getMaxHaveGold()) { + cashGold = CHAR_getMaxHaveGold(); + // ??? + play_se(220, 320, 240); + } + else { + // ????? + bankGoldInc = 0; + // ????????????? + bankGoldCnt = 0; + // ??????? + bankWndBtnFlag[2] = TRUE; + // ????? + play_se(217, 320, 240); + } + + } + } + } + else{ + // ?????? + bankWndBtnFlag[2] = FALSE; + } + // ?????????? + if (HitDispNo == bankWndFontNo[3]){ + // ??????????????? + if (mouse.onceState & MOUSE_LEFT_CRICK_UP && bankWndBtnFlag[3] == TRUE){ + bankWndBtnFlag[3] = FALSE; + // ?????? + //play_se( 212, 320, 240 ); + } + if ((cashGold > 0) && (totalGold - cashGold < MAX_BANKGOLD)) { + // ?????? + if (bankWndBtnFlag[3] == TRUE){ + + // ???? + cashGold -= bankGoldInc; + // ????????????? + bankGoldCnt++; + + // ?ƨ??? + if (bankGoldCnt >= 30){ + // ????????????? + bankGoldCnt = 0; + // ???????? + if (bankGoldInc == 0) { + bankGoldInc = 1; + } + else{ + // ????? + bankGoldInc *= 5; + // ???????? + if (bankGoldInc > 10000) { + bankGoldInc = 10000; + } + } + } + // ???????? + if (cashGold <= 0){ + cashGold = 0; + play_se(220, 320, 240); + } + if (totalGold - cashGold >= MAX_BANKGOLD){ + cashGold = totalGold - MAX_BANKGOLD; + play_se(220, 320, 240); + } + + } + // ???????? + if (mouse.onceState & MOUSE_LEFT_CRICK) { + + cashGold--; + + if (cashGold <= 0){ + cashGold = 0; + // ??? + play_se(220, 320, 240); + } + else if (totalGold - cashGold >= MAX_BANKGOLD) { + cashGold = totalGold - MAX_BANKGOLD; + play_se(220, 320, 240); + } + else{ + // ????? + bankGoldInc = 0; + // ????????????? + bankGoldCnt = 0; + // ??????? + bankWndBtnFlag[3] = TRUE; + // ????? + play_se(217, 320, 240); + + } + + } + } + else { + bankGoldInc = 0; + bankGoldCnt = 0; + } + + } + else{ + // ?????? + bankWndBtnFlag[3] = FALSE; + } + // ????????? + for (int i = 2; i <= 8; i++) { + if (mouse.state & MOUSE_LEFT_CRICK && tradeWndBtnFlag[i] == TRUE){ + // ???? + tradeWndBtnFlag[i] = TRUE; + } + else{ + // ??? + tradeWndBtnFlag[i] = FALSE; + } + } + if (pActMenuWnd5 != NULL) { + // ?@e + x = pActMenuWnd5->x; + y = pActMenuWnd5->y + 5; + + bankWndFontNo[0] = StockDispBuffer(x + 200, y + 133, DISP_PRIO_IME3, CG_TRADE_CANCEL_BTN, 2); + bankWndFontNo[1] = StockDispBuffer(x + 75, y + 133, DISP_PRIO_IME3, CG_TRADE_OK_BTN, 2); + bankWndFontNo[2] = StockDispBuffer(x + 140, y + 70, DISP_PRIO_IME3, CG_UP_BTN + bankWndBtnFlag[2], 2); + bankWndFontNo[3] = StockDispBuffer(x + 200, y + 70, DISP_PRIO_IME3, CG_DOWN_BTN + bankWndBtnFlag[3], 2); + sprintf_s(moji, "%7d", cashGold); + StockFontBuffer(x + 180, y + 40, FONT_PRIO_FRONT, 0, moji, 0); + sprintf_s(moji, "%7d", totalGold - cashGold); + StockFontBuffer(x + 180, y + 86, FONT_PRIO_FRONT, 0, moji, 0); + + StockDispBuffer(((WINDOW_DISP *)pActMenuWnd5->pYobi)->mx, ((WINDOW_DISP *)pActMenuWnd5->pYobi)->my, DISP_PRIO_IME3, CG_FAMILY_BANK_WIN, 1); + } + } + } + } + +#ifdef _STANDBYPET + if (StandbyPetSendFlag == FALSE){ + int s_pet = 0; + int i; + + for (i = 0; i < MAX_PET; i++) { + if (pc.selectPetNo[i]) + s_pet |= (1 << i); + } + if (s_pet != pc.standbyPet) + send_StandBy_Pet(); + } +#endif + + +} +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +void lssproto_RESIST_recv ( int fd, char *data) +{ + for ( int i = 0 ; i < CHAR_MAX_DETAIL ; i ++ ) + getStringToken( data, '|', i + 1 , sizeof( CharDetail[i] ) - 1 , CharDetail[i] ); +} +#endif + +#ifdef _ALCHEPLUS +void lssproto_ALCHEPLUS_recv(int fd, char *data) +{ + char token[64]; + int i; + for (i = 0; i < 25; i++) { + getStringToken(data, '|', i + 1, sizeof(token)-1, token); + iCharAlchePlus[i] = atoi(token); + } +} +#endif + +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +void lssproto_BATTLESKILL_recv(int fd, char *data) { + setCharMind(pc.ptAct, atoi(data)); +} +#endif + +void lssproto_CHAREFFECT_recv(int fd, char *data) { + if (data[0] == '1') + setCharFamily(pc.ptAct, atoi(data + 2)); + else if (data[0] == '2') + setCharMind(pc.ptAct, atoi(data + 2)); + else if (data[0] == '3') + setCharmFamily(pc.ptAct, atoi(data + 2)); +#ifdef _CHARTITLE_ + else if (data[0] == '4'){ + setCharmTitle(pc.ptAct, atoi(data + 2)); + } +#endif +#ifdef _CHAR_MANOR_ + else if (data[0] == '5') + setCharmManor(pc.ptAct, atoi(data + 2)); +#endif +} + +#ifdef _TRADE_BUG_LOG +bool __writeFirstTime; +#endif + + +void lssproto_TD_recv(int fd, char *data) +{ + char Head[2] = ""; + char buf_sockfd[128] = ""; + char buf_name[128] = ""; + char buf[128] = ""; +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + char opp_index[128]; + int index; + char realname[256]; + char freename[256]; +#endif + + + getStringToken(data, '|', 1, sizeof(char), Head); + + // ׿ϳʼ + if (strcmp(Head, "C") == 0) { + +#ifdef _TRADE_BUG_LOG + __writeFirstTime = true; +#endif + + memset(opp_sockfd, 0, sizeof(opp_sockfd)); + memset(opp_name, 0, sizeof(opp_name)); + memset(trade_command, 0, sizeof(trade_command)); + + getStringToken(data, '|', 2, sizeof(opp_sockfd)-1, opp_sockfd); + getStringToken(data, '|', 3, sizeof(opp_name)-1, opp_name); + getStringToken(data, '|', 4, sizeof(trade_command)-1, trade_command); + + if (strcmp(trade_command, "0") == 0) { + return; + } + else if (strcmp(trade_command, "1") == 0) { + tradeStatus = 1; + MenuToggleFlag = JOY_CTRL_T; + pc.trade_confirm = 1; + } +#ifdef _COMFIRM_TRADE_REQUEST + else if (strcmp(trade_command, "2") == 0) + { + tradeStatus = 1; + MenuToggleFlag = JOY_CTRL_T; + pc.trade_confirm = 1; + tradeWndNo = 1; + } +#endif + + } + //ƷѶ + else if (strcmp(Head, "T") == 0) { + + if (tradeStatus == 0) return; + char buf_showindex[128]; + + //andy_add mttrade + getStringToken(data, '|', 4, sizeof(trade_kind)-1, trade_kind); + if (strcmp(trade_kind, "S") == 0) { + char buf1[256]; + int objno = -1, showno = -1; + if (pActMenuWnd4 == NULL){ + DeathMenuAction(); + DeathMenuAction2(); + + int w = 620; int h = 456; + int x = (lpDraw->xSize - w) / 2; + int y = (lpDraw->ySize - h) / 2; + + pActMenuWnd4 = MakeWindowDisp(x, y, w, h, NULL, -1, FALSE); + InitItem3(325, 230); +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + if (SecondTradeWnd == NULL) + SecondTradeWnd = MakeWindowDisp(10, 0, 620, 456, 0, -1); +#endif + } + getStringToken(data, '|', 6, sizeof(buf1)-1, buf1); + objno = atoi(buf1); + getStringToken(data, '|', 7, sizeof(buf1)-1, buf1); + showno = atoi(buf1); + getStringToken(data, '|', 5, sizeof(buf1)-1, buf1); + + ItemBuffer[objno].mixFlag = FALSE; + if (pc.item[objno].useFlag == TRUE){ + ItemBuffer[objno].dragFlag = TRUE; + mouse.itemNo = objno; + } + + if (!strcmp(buf1, "I")) { //I + } + else { //P + tradePetIndex = objno; + tradePet[0].index = objno; + + if (pet[objno].useFlag && pc.ridePetNo != objno){ + if (pet[objno].freeName[0] != NULL) + strcpy(tradePet[0].name, pet[objno].freeName); + else + strcpy(tradePet[0].name, pet[objno].name); + tradePet[0].level = pet[objno].level; + tradePet[0].atk = pet[objno].atk; + tradePet[0].def = pet[objno].def; + tradePet[0].quick = pet[objno].quick; + tradePet[0].graNo = pet[objno].graNo; + + showindex[3] = 3; + DeathAction(pActPet4); + pActPet4 = NULL; + } + } + + mouse.itemNo = -1; + + return; + } + + getStringToken(data, '|', 2, sizeof(buf_sockfd)-1, buf_sockfd); + getStringToken(data, '|', 3, sizeof(buf_name)-1, buf_name); + getStringToken(data, '|', 4, sizeof(trade_kind)-1, trade_kind); + getStringToken(data, '|', 5, sizeof(buf_showindex)-1, buf_showindex); + opp_showindex = atoi(buf_showindex); + + if ((strcmp(buf_sockfd, opp_sockfd) != 0) || (strcmp(buf_name, opp_name) != 0)) + return; + + if (strcmp(trade_kind, "G") == 0) { + + getStringToken(data, '|', 6, sizeof(opp_goldmount)-1, opp_goldmount); + int mount = atoi(opp_goldmount); +#ifdef _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + if (tradeWndDropGoldGet != 0) { + MenuToggleFlag ^= JOY_CTRL_T; + play_se(203, 320, 240); + sprintf_s(buf, "W|%s|%s", opp_sockfd, opp_name); + if (bNewServer) + lssproto_TD_send(sockfd, buf); + else + old_lssproto_TD_send(sockfd, buf); + sprintf_s(buf, "%sԲʽ޸Ľ׽ǮϵͳǿƹرսӴ", opp_name); + StockChatBufferLine(buf, FONT_PAL_RED); + return; + } +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //andy_reEdit + if (mount != -1) { + tradeList[42].kind = 'G'; + tradeList[42].data = mount; + tradeWndDropGoldGet = mount; + } + else { + tradeList[42].data = 0; + tradeWndDropGoldGet = 0; + } + /* + if( opp_showindex == 3 ) { + if( mount != -1 ) { + tradeList[42].kind = 'G' ; + tradeList[42].data = mount ; + tradeWndDropGoldGet = mount; + }else { + tradeList[42].data = 0; + tradeWndDropGoldGet = 0; + } + }else + */ + +#else + if( opp_showindex == 1 ) { + if( mount != -1 ) { + showindex[4] = 2; + tradeWndDropGoldGet = mount; + }else { + showindex[4] = 0; + tradeWndDropGoldGet = 0; + } + } + else if (opp_showindex == 2) { + if (mount != -1) { + showindex[5] = 2; + tradeWndDropGoldGet = mount; + } + else { + showindex[5] = 0; + tradeWndDropGoldGet = 0; + } + } + else return; +#endif + + } + + if (strcmp(trade_kind, "I") == 0) { + char pilenum[256], item_freename[256]; + + getStringToken(data, '|', 6, sizeof(opp_itemgraph)-1, opp_itemgraph); + + getStringToken(data, '|', 7, sizeof(opp_itemname)-1, opp_itemname); + getStringToken(data, '|', 8, sizeof(item_freename)-1, item_freename); + + getStringToken(data, '|', 9, sizeof(opp_itemeffect)-1, opp_itemeffect); + getStringToken(data, '|', 10, sizeof(opp_itemindex)-1, opp_itemindex); + getStringToken(data, '|', 11, sizeof(opp_itemdamage)-1, opp_itemdamage);// ʾƷ;ö + +#ifdef _ITEM_PILENUMS + getStringToken(data, '|', 12, sizeof(pilenum)-1, pilenum);//pilenum +#endif +#ifdef _NPC_ITEMUP + getStringToken(data, '|', 13, sizeof(itemup)-1, itemup); +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + if (strcmp(opp_itemgraph, "-1") == 0) + return; + + int i = atoi(opp_itemindex); + + + int chkindex = -1, frontempIndex = -1; + //opp_itemռǷ xiezi + for (int scanindex = 0; scanindex < 15; scanindex++) + { + if (strcmp(opp_item[chkindex].itemindex, opp_itemindex) == 0) + { + chkindex = scanindex; + break; + } + if ((opp_item[scanindex].itemindex[0] == NULL || strcmp(opp_item[scanindex].itemindex, "-1") == 0) && frontempIndex < 0) + { + frontempIndex = scanindex; + } + } + chkindex = chkindex > -1 ? chkindex : frontempIndex; + if (chkindex > -1) + { + strcpy(opp_item[chkindex].name, makeStringFromEscaped(opp_itemname)); + strcpy(opp_item[chkindex].freename, makeStringFromEscaped(item_freename)); + strcpy(opp_item[chkindex].graph, opp_itemgraph); + strcpy(opp_item[chkindex].effect, makeStringFromEscaped(opp_itemeffect)); + strcpy(opp_item[chkindex].itemindex, opp_itemindex); + strcpy(opp_item[chkindex].damage, makeStringFromEscaped(opp_itemdamage)); + + chkindex = 0, frontempIndex = 0; + //tradeListռǷ xiezi + for (int scanindex = 22; scanindex < 37; scanindex++) + { + if (tradeList[chkindex].data == i) + { + chkindex = scanindex; + break; + } + if (tradeList[scanindex].data == -1 && frontempIndex < 1) + { + frontempIndex = scanindex; + } + } + chkindex = chkindex > 0 ? chkindex : frontempIndex; + + if (chkindex > 0){ + tradeList[chkindex].kind = 'I'; + tradeList[chkindex].data = atoi(opp_itemindex); + strcpy(tradeList[chkindex].name, makeStringFromEscaped(opp_itemname)); + + strcpy(tradeList[chkindex].freename, makeStringFromEscaped(item_freename)); + + strcpy(tradeList[chkindex].damage, makeStringFromEscaped(opp_itemdamage)); +#ifdef _ITEM_PILENUMS + tradeList[chkindex].pilenum = atoi(pilenum); +#endif +#ifdef _NPC_ITEMUP + tradeList[chkindex].itemup = atoi(itemup); +#endif + +#endif //_TRADESYSTEM2 + } + } + } + + if (strcmp(trade_kind, "P") == 0) { +#ifdef _PET_ITEM + int iItemNo; + char szData[256]; +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + getStringToken(data, '|', 12, sizeof(opp_index)-1, opp_index); + index = -1; + + //opp_itemռǷ xiezi + for (int scanindex = 0; scanindex < 5; scanindex++) + { + if (opp_pet[scanindex].opp_petindex[0] == NULL || strcmp(opp_pet[scanindex].opp_petindex, "-1") == 0) + { + index = scanindex; + break; + } + } + + if (index > -1){ + + getStringToken(data, '|', 6, sizeof(opp_pet[index].opp_petgrano) - 1, opp_pet[index].opp_petgrano); + getStringToken(data, '|', 7, sizeof(opp_pet[index].opp_petname) - 1, opp_pet[index].opp_petname); + getStringToken(data, '|', 8, sizeof(opp_pet[index].opp_petlevel) - 1, opp_pet[index].opp_petlevel); + getStringToken(data, '|', 9, sizeof(opp_pet[index].opp_petatk) - 1, opp_pet[index].opp_petatk); + getStringToken(data, '|', 10, sizeof(opp_pet[index].opp_petdef) - 1, opp_pet[index].opp_petdef); + getStringToken(data, '|', 11, sizeof(opp_pet[index].opp_petquick) - 1, opp_pet[index].opp_petquick); + getStringToken(data, '|', 12, sizeof(opp_pet[index].opp_petindex) - 1, opp_pet[index].opp_petindex); + getStringToken(data, '|', 13, sizeof(opp_pet[index].opp_pettrans) - 1, opp_pet[index].opp_pettrans); + getStringToken(data, '|', 14, sizeof(opp_pet[index].opp_petshowhp) - 1, opp_pet[index].opp_petshowhp); + getStringToken(data, '|', 15, sizeof(opp_pet[index].opp_petslot) - 1, opp_pet[index].opp_petslot); + getStringToken(data, '|', 16, sizeof(opp_pet[index].opp_petskill1) - 1, opp_pet[index].opp_petskill1); + getStringToken(data, '|', 17, sizeof(opp_pet[index].opp_petskill2) - 1, opp_pet[index].opp_petskill2); + getStringToken(data, '|', 18, sizeof(opp_pet[index].opp_petskill3) - 1, opp_pet[index].opp_petskill3); + getStringToken(data, '|', 19, sizeof(opp_pet[index].opp_petskill4) - 1, opp_pet[index].opp_petskill4); + getStringToken(data, '|', 20, sizeof(opp_pet[index].opp_petskill5) - 1, opp_pet[index].opp_petskill5); + getStringToken(data, '|', 21, sizeof(opp_pet[index].opp_petskill6) - 1, opp_pet[index].opp_petskill6); + getStringToken(data, '|', 22, sizeof(opp_pet[index].opp_petskill7) - 1, opp_pet[index].opp_petskill7); + getStringToken(data, '|', 23, sizeof(realname), realname); + getStringToken(data, '|', 24, sizeof(freename), freename); +#ifdef _SHOW_FUSION + getStringToken(data, '|', 25, sizeof(opp_pet[index].opp_fusion) - 1, opp_pet[index].opp_fusion); +#endif + strcpy(opp_pet[index].opp_petname, realname); + strcpy(opp_pet[index].opp_petfreename, freename); +#endif + +#ifdef _PET_ITEM + for (int i = 0;; i++){ + if (getStringToken(data, '|', 26 + i * 6, sizeof(szData), szData)) + break; + iItemNo = atoi(szData); + getStringToken(data, '|', 27 + i * 6, sizeof(opp_pet[index].oPetItemInfo[iItemNo].name), opp_pet[index].oPetItemInfo[iItemNo].name); + getStringToken(data, '|', 28 + i * 6, sizeof(opp_pet[index].oPetItemInfo[iItemNo].memo), opp_pet[index].oPetItemInfo[iItemNo].memo); + getStringToken(data, '|', 29 + i * 6, sizeof(opp_pet[index].oPetItemInfo[iItemNo].damage), opp_pet[index].oPetItemInfo[iItemNo].damage); + getStringToken(data, '|', 30 + i * 6, sizeof(szData), szData); + opp_pet[index].oPetItemInfo[iItemNo].color = atoi(szData); + getStringToken(data, '|', 31 + i * 6, sizeof(szData), szData); + opp_pet[index].oPetItemInfo[iItemNo].bmpNo = atoi(szData); + } +#endif + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + tradeList[index + 37].data = atoi(opp_pet[index].opp_petindex); + tradeList[index + 37].kind = 'P'; + strcpy(tradeList[index + 37].freename, freename); + strcpy(tradeList[index + 37].name, realname); + tradeList[index + 37].level = atoi(opp_pet[index].opp_petlevel); + tradeList[index + 37].trns = atoi(opp_pet[index].opp_pettrans); +#ifdef _SHOW_FUSION + tradeList[index + 37].fusion = atoi(opp_pet[index].opp_fusion); +#endif +#endif + + if (opp_showindex == 3) { +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + if (strcmp(opp_pet[index].opp_petgrano, "-1") == 0) { +#endif + showindex[6] = 0; + } + else { + showindex[6] = 3; + } + DeathAction(pActPet5); + pActPet5 = NULL; + } + } + } + + + // shan trade(DoubleCheck) begin + if (strcmp(trade_kind, "C") == 0) { + if (pc.trade_confirm == 1) pc.trade_confirm = 3; + if (pc.trade_confirm == 2) pc.trade_confirm = 4; + } + // end + + if (strcmp(trade_kind, "A") == 0) + tradeStatus = 2; + + } + else if (strcmp(Head, "W") == 0) {//ȡ + getStringToken(data, '|', 2, sizeof(buf_sockfd)-1, buf_sockfd); + getStringToken(data, '|', 3, sizeof(buf_name)-1, buf_name); + if ((strcmp(buf_sockfd, opp_sockfd) == 0) && (strcmp(buf_name, opp_name) == 0)) { + tradeStatus = 0; + MenuToggleFlag &= ~JOY_CTRL_T; + tradeInit(); + pc.trade_confirm = 1; + play_se(203, 320, 240); + } + } +} + +void tradeInit(void) +{ +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + //ʼʱAction + DeathAction(SecondTradeWnd); + SecondTradeWnd = NULL; + DeathAction(SecondActPet); + SecondActPet = NULL; + DeathAction(TradeTalkWnd); + TradeTalkWnd = NULL; + //Terry add 2003/11/25 + g_bTradesystemOpen = false; + //end +#endif + DeathAction(pActMenuWnd4); + // Ӵʼʱfocuschat + GetKeyInputFocus(&MyChatBuffer); + Tradeflag = false; + pActMenuWnd4 = NULL; + DeathAction(pActPet3); + pActPet3 = NULL; + DeathAction(pActPet4); + pActPet4 = NULL; + DeathAction(pActPet5); + pActPet5 = NULL; + for (int i = 0; i <= 6; i++) + showindex[i] = 0; + strcpy(opp_sockfd, "-1"); + strcpy(opp_name, ""); + tradePetIndex = 0; + strcpy(tradepetindexget, "-1"); + mine_itemindex[0] = -1; + mine_itemindex[1] = -1; + + tradeWndDropGoldSend = 0; + tradeWndDropGoldGet = 0; + tradeWndDropGold = 0; + //strcpy(opp_item[0].itemindex, "-1"); + //strcpy(opp_item[1].itemindex, "-1"); + + memset(opp_pet, 0, sizeof(showpet)* 5); + for (int i = 0; i < MAX_MAXHAVEITEM; i++) + { + strcpy(opp_item[i].itemindex, "-1"); + } + memset(tradeList, 0, sizeof(tradelist)* 45); +} + +void BankmanInit(char *data) +{ + char token1[1024]; + getStringToken(data, '|', 3, sizeof(token1)-1, token1); + + bankGold = atoi(token1); + cashGold = pc.gold; + totalGold = bankGold + cashGold; + + MenuToggleFlag = JOY_B; + DeathAction(pActMenuWnd5); + pActMenuWnd5 = NULL; +} + +void closeBankman(void) { + + MenuToggleFlag ^= JOY_B; + play_se(203, 320, 240); + DeathAction(pActMenuWnd5); + pActMenuWnd5 = NULL; + +} +#ifdef _RIDEPET_ +void checkRidePet(int pindex) +{ + char buf[128]; + sprintf_s(buf, "R|P|%d", pindex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + return; +} +#else +void checkRidePet(int pindex) +{ + int j; +#ifdef _PET_ITEM + BOOL bHavePetItem = FALSE; +#endif + + if (!bNewServer) + return; + +#ifdef _PET_ITEM + // װ + for (j = 0; j < MAX_PET_ITEM; ++j){ + if (pet[pindex].item[j].useFlag){ // װװ + bHavePetItem = TRUE; + break; + } + } +#endif + if( pc.ridePetNo < 0 + && pc.learnride >= pet[pindex].level //Change fix ﱻע 20050801 + && (pc.level + 5) > pet[pindex].level + && pet[pindex].ai >= 100 + && pc.graNo != SPR_pet021 + && pc.graNo != 100362 // +#ifdef _PETSKILL_BECOMEPIG // в + && pc.graNo != 100250 +#endif +#ifdef _THEATER + && pc.graNo != 101989 // żװʱ +#endif + ) + { + pc.ridePetNo = -1; + for (j = 0; j < sizeof(ridePetTable) / sizeof(tagRidePetTable); j++){ + int baseimageNo = pc.graNo - (pc.graNo % 5); + int leaderimageNo = 100700 + ((baseimageNo - 100000) / 20) * 10 + (pc.familySprite) * 5; +// //andy_edit +// if (((ridePetTable[j].charNo == pc.graNo) || (ridePetTable[j].charNo == pc.baseGraNo)) /*&& ridePetTable[j].petNo == pet[pindex].graNo*/){ +// char buf[64]; +//#ifdef _PET_ITEM +// if (bHavePetItem){ // װ +// StockChatBufferLine("װˣ", FONT_PAL_YELLOW); +// pc.selectPetNo[pindex] = 0; +// return; +// } +//#endif +// sprintf(buf, "R|P|%d", pindex); +// if (bNewServer) +// lssproto_FM_send(sockfd, buf); +// else +// old_lssproto_FM_send(sockfd, buf); +// pc.ridePetNo = pindex; +// return; + char buf[64]; + sprintf(buf, "R|P|%d", pindex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + pc.ridePetNo = pindex; + return; + + +#ifdef _LEADERRIDE + if (ridePetTable[j].charNo == leaderimageNo && ridePetTable[j].petNo == pet[pindex].graNo && + pc.big4fm != 0 && pc.familyleader != FMMEMBER_APPLY && pc.familyleader != FMMEMBER_NONE){ + char buf[64]; +#ifdef _PET_ITEM + if (bHavePetItem){ // װ + StockChatBufferLine("װˣ", FONT_PAL_YELLOW); + pc.selectPetNo[pindex] = 0; + return; + } +#endif + sprintf(buf, "R|P|%d", pindex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + pc.ridePetNo = pindex; + return; + } +#endif + } + {//andy_add + int ti = -1, index; + unsigned int LRCode = 1<<30; + if ((ti = RIDEPET_getPETindex(pet[pindex].graNo, pc.lowsride)) < 0) + { +#ifdef RIDE_PET_LIMIT + if (pc.lowsride >= LRCode) + { + if ((ti = RIDEPET_getPETindex_New(pet[pindex].graNo, LRCode)) < 0) + { + return; + } + } + else + { + return; + } +#endif + } + if ((index = RIDEPET_getNOindex(pc.baseGraNo)) >= 0){ + char buf[64]; + if (RIDEPET_getRIDEno(index, ti) >= 0){ +#ifdef _PET_ITEM + if (bHavePetItem){ // װ + StockChatBufferLine("װˣ", FONT_PAL_YELLOW); + pc.selectPetNo[pindex] = 0; + return; + } +#endif + sprintf(buf, "R|P|%d", pindex); + if (bNewServer) + lssproto_FM_send(sockfd, buf); + else + old_lssproto_FM_send(sockfd, buf); + pc.ridePetNo = pindex; + return; + } + } + } + } +} +#endif + +//andy_add 2002/06/24 +int RIDEPET_getNOindex(int baseNo) +{ + int i; + for (i = 0; i < sizeof(RPlistMode) / sizeof(tagRidePetList); i++) { + if (RPlistMode[i].charNo == baseNo) + return RPlistMode[i].Noindex; + } + return -1; +} +//andy_add 2002/06/24 +int RIDEPET_getPETindex(int PetNo, int learnCode) +{ + int i; + for (i = 0; i < sizeof(RideCodeMode) / sizeof(tagRideCodeMode); i++){ + if (RideCodeMode[i].petNo == PetNo && + (RideCodeMode[i].learnCode & learnCode)) + return i; + } + return -1; +} +#ifdef RIDE_PET_LIMIT +int RIDEPET_getPETindex_New(int PetNo, int learnCode) +{ + int i; + for (i = 0; i < sizeof(RideCodeMode) / sizeof(tagRideCodeMode); i++) { + if (RideCodeMode[i].petNo == PetNo/* && + (RideCodeMode[i].learnCode & learnCode)*/) { + return i; + } + } + return -1; +} +#endif + +//andy_add 2002/06/24 +int RIDEPET_getRIDEno(int index, int ti) +{ + if (index < 0 || index >= sizeof(RideNoList) / sizeof(tagRideNoList)) + return -1; + if (ti < 0 || ti >= MAXNOINDEX) + return -1; + return RideNoList[index].RideNo[ti]; +} + +#ifdef _TELLCHANNEL //ROG ADD Ƶ +void InitSelectChar(char *msg, BOOL endFlag) +{ + int turn, level; + char name1[32]; + if (MultiTells == TRUE) + DeathTellChannel(); + + if (!endFlag){ +#ifndef _CHANNEL_MODIFY + index[CharNum] = getIntegerToken(msg, '|', 2); + turn = getIntegerToken(msg, '|', 3); + level = getIntegerToken(msg, '|', 4); + getStringToken(msg, '|', 5, sizeof(name[CharNum]) - 1, name[CharNum]); + getStringToken(msg, '|', 6, sizeof(name1)-1, name1); +#else + index[CharNum] = getIntegerToken(msg, '|', 3); + turn = getIntegerToken(msg, '|', 4); + level = getIntegerToken(msg, '|', 5); + getStringToken(msg, '|', 6, sizeof(name[CharNum]) - 1, name[CharNum]); + getStringToken(msg, '|', 7, sizeof(name1)-1, name1); +#endif + sprintf_s(TellInfo[CharNum], " %15s %15s %5d %5d ", name[CharNum], name1, turn, level); + CharNum++; + } + else{ +#ifndef _CHANNEL_MODIFY + getStringToken(msg, '|', 2, sizeof(reSendMsg)-1, reSendMsg); +#else + getStringToken(msg, '|', 3, sizeof(reSendMsg)-1, reSendMsg); +#endif + MultiTells = TRUE; + } + //test////////////// +#ifdef _TIMEBAR_FUNCTION + StartTime = TimeGetTime(); + timBarIdent = SetTimeBar("aaaaaa", 50); +#endif + ////////////////// +} + +void SelectChar(void) +{ + char tmpMsg[1024]; + int x, y; + if (pActMsgWnd == NULL){ + pActMsgWnd = MakeWindowDisp(80, 200, 6, CharNum / 2 + 1, 2, 0); + } + else if (pActMsgWnd->hp > 0){ + x = pActMsgWnd->x; + y = pActMsgWnd->y; + char title[] = { " ת " }; + StockFontBuffer(x + 10, y + 15, FONT_PRIO_FRONT, 4, title, 0); + for (int i = 0; i < CharNum; i++){ + StockFontBuffer(x + 10, y + 40 + i * 20, FONT_PRIO_FRONT, 5, TellInfo[i], 0); + if (MakeHitBox(x + 10, y + 37 + i * 20, x + 360, y + 56 + i * 20, DISP_PRIO_BOX2)){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + sprintf_s(tmpMsg, "%s %s /T%d ", name[i], reSendMsg, index[i]); + TalkMode = 1; + chatStrSendForServer(tmpMsg, 0); + DeathTellChannel(); + } + } + } + } + + //test////////////// +#ifdef _TIMEBAR_FUNCTION + int Now = TimeGetTime(); + Now -= StartTime; + int rsut = SetTimeBarPos(timBarIdent, Now / 1000); + if (rsut == 1) + StartTime += 50000; + else if (rsut == -1){ + DeathAction(pTimeBarWnd); + pTimeBarWnd = NULL; + } + +#endif + //////////////////// +} + +void DeathTellChannel(void) +{ + DeathAction(pActMsgWnd); + pActMsgWnd = NULL; + MultiTells = FALSE; + CharNum = 0; +} + +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + +void initSetRoomName() +{ + DeathMenuAction(); + DeathMenuAction2(); + DeathAction(pSetRoomWnd); + pSetRoomWnd = NULL; + GetKeyInputFocus( &MyChatBuffer ); + setRoomFlag = TRUE; + SelRoomBtn = 0; +} + +void setRoomName(void) +{ + static int setRoomBtn[2]; //趨 + + if(pSetRoomWnd == NULL){ + pSetRoomWnd = MakeWindowDisp( 270, 0, 3, 2, NULL, 0 ); + play_se( 202, 320, 240 ); + chatRoomName.buffer[ 0 ] = NULL; + chatRoomName.cnt = 0; + chatRoomName.cursor=0; + chatRoomName.len = 16; + chatRoomName.color = 0; + chatRoomName.x = pSetRoomWnd->x + 22; + chatRoomName.y = pSetRoomWnd->y + 35; + chatRoomName.fontPrio = FONT_PRIO_FRONT; + } + else if(pSetRoomWnd->hp > 0 ){ + int x = pSetRoomWnd->x; + int y = pSetRoomWnd->y; + + setRoomBtn[0] = StockDispBuffer( pSetRoomWnd->x + 53, pSetRoomWnd->y + 70, DISP_PRIO_IME3, CG_OK_BTN, 2 ); + setRoomBtn[1] = StockDispBuffer( pSetRoomWnd->x + 140, pSetRoomWnd->y + 70, DISP_PRIO_IME3, CG_CANCEL_BTN, 2 ); + + char title[] = {"Ƶ"}; + StockFontBuffer( x + 22, y + 10, FONT_PRIO_FRONT,4 , title, 0 ); + GetKeyInputFocus( &chatRoomName ); + StockFontBuffer2( &chatRoomName ); + + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if( HitDispNo == setRoomBtn[0] ) + KeyboardReturn(); + else if( HitDispNo == setRoomBtn[1] ){ + GetKeyInputFocus( &MyChatBuffer ); +#ifdef _CHATROOMPROTOCOL + lssproto_CHATROOM_send ( sockfd , "B|" ) ; +#endif + DeathAction(pSetRoomWnd); + pSetRoomWnd = NULL; + setRoomFlag = FALSE; + } + } + } +} + +void InitSelChatRoom(char *msg) +{ + char tempRoomNum[32],RoomName[32]; + int memberNum = 0; + char chiefName[128] = {""}; + char temp[16],*temp1; + int i = 2, k=0; + roomNum = 0; + + while( getStringToken( msg, '|', i , sizeof(tempRoomNum) -1 ,tempRoomNum )!=1){ + if( tempRoomNum[0] == 'r' ){ + temp1 = tempRoomNum; + temp1++; + roomNum = atoi( temp1); + + getStringToken( msg, '|', i+1 , sizeof(RoomName) -1 ,RoomName ); + getStringToken( msg, '|', i+3 , sizeof(chiefName) -1 ,chiefName ); + getStringToken( msg, '|', i+4 , sizeof(temp) -1 ,temp ); + char *sss; + if( (temp1 = strtok_s(temp,"p",&sss))!= NULL ) + memberNum = atoi(temp1); + + roomIndex[k] = roomNum; + sprintf_s(roomInfo[k]," %16s %16s %2d ",RoomName,chiefName,memberNum); + k++; + roomNum ++; + i += 5; + } + else + break; + } + SelRoomBtn = 1; +} + +#ifdef _CHATROOMPROTOCOL +void SelectChatRoom(void) +{ + char tmpMsg[128] = {""}; + + if(pSelChanlWnd == NULL){ + pSelChanlWnd = MakeWindowDisp( 120, 100, 7, roomNum / 2 + 2 , 2, 0 ); + } + else if(pSelChanlWnd->hp > 0 ){ + int x = pSelChanlWnd->x; + int y = pSelChanlWnd->y; + char title[] = {" Ƶ ӳ "}; + StockFontBuffer( x + 10, y + 15, FONT_PRIO_FRONT,4 , title, 0 ); + int i; + for(i = 0 ; i < roomNum ; i++ ){ + StockFontBuffer( x + 10, y + 40 + i * 20, FONT_PRIO_FRONT,5 , roomInfo[i], 0 ); + if( MakeHitBox( x +10, y+ 37 + i * 20 , x + 320 , y + 58 + i * 20, DISP_PRIO_BOX2 )){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + sprintf_s(tmpMsg,"J|%d",roomIndex[i]); + lssproto_CHATROOM_send ( sockfd , tmpMsg ) ; + SelRoomBtn = 0; //رѡƵӴ + } + } + } + + StockFontBuffer( x + 30, y + 50 + i * 20, FONT_PRIO_FRONT,5 , " µ", 0 ); + if( MakeHitBox(x + 30 ,y + 47 + i * 20 , x + 340 , y + 68 + i * 20, DISP_PRIO_BOX2 )){ + if( mouse.onceState & MOUSE_LEFT_CRICK ) + initSetRoomName(); + } + } +} +#endif + +void SwapOrder(int pos1,int pos2 ) +{ + char tempName[CHAR_NAME_LEN+1]; + int tempIndex; + char tempNick[CHAR_FREENAME_LEN+1]; + + strcpy(tempName,chatInfo.memberName[pos1]); + strcpy(tempNick,chatInfo.nickName[pos1]); + tempIndex = chatInfo.memberIndex[pos1]; + + strcpy(chatInfo.memberName[pos1],chatInfo.memberName[pos2]); + strcpy(chatInfo.nickName[pos1],chatInfo.nickName[pos2]); + chatInfo.memberIndex[pos1] = chatInfo.memberIndex[pos2]; + + strcpy(chatInfo.memberName[pos2],tempName); + strcpy(chatInfo.nickName[pos2],tempNick); + chatInfo.memberIndex[pos2] = tempIndex; +} + +void InitRoomInfo() +{ + for (int i=0; i<50; i++){ + chatInfo.memberIndex[i] = 0; + strcpy(chatInfo.memberName[i],""); + strcpy(chatInfo.nickName[i],""); + } + chatInfo.chiefFlag = 0; + chatInfo.chiefIndex = 0; + chatInfo.memberNum = 0; + firMemNo = 0; +} + +void InitCreateChatRoom(char *msg) //ʼӴ +{ + char temp[64],*temp1; + chatInfo.chiefFlag = 0; + InitRoomInfo(); //ʼ + chatRoomBtn = 1; + getStringToken( msg, '|', 2 , sizeof(temp) -1 ,temp ); + char *sss; + if((temp1 = strtok_s(temp,"r",&sss))!= NULL ){ + strcpy(chatInfo.roomNo,temp1); + strcpy(pc.chatRoomNum,chatInfo.roomNo); + + getStringToken( msg, '|', 3 , sizeof(chatInfo.roomName) -1 ,chatInfo.roomName ); + + chatInfo.chiefIndex = getIntegerToken( msg, '|', 4 ); + + getStringToken( msg, '|', 5 , sizeof(temp) -1 ,temp ); + strcpy(chatInfo.chiefName,temp); + + getStringToken( msg, '|', 6 , sizeof(temp) -1 ,temp ); + + + char *sss; + if( (temp1 = strtok_s(temp,"p",&sss))!= NULL ) + chatInfo.memberNum = atoi(temp1); + int i; + for(i = 0; i< chatInfo.memberNum; i ++){ + getStringToken( msg, '|', 7+i*3, sizeof(temp) -1 ,temp ); + if ((temp1 = strchr(temp,'I')) == NULL ) + break; + chatInfo.memberIndex[i] = atoi(temp1+1); + getStringToken( msg, '|', 8+i*3, sizeof(chatInfo.memberName[i]) -1 + ,chatInfo.memberName[i] ); + getStringToken( msg, '|', 9+i*3, sizeof(chatInfo.nickName[i]) -1 + ,chatInfo.nickName[i] ); + if(i > 0 && chatInfo.memberIndex[i] == chatInfo.chiefIndex) + SwapOrder(i, 0); //ҳ + secretFlag = FALSE; + selChar = -1; + } + chatInfo.chiefFlag = getIntegerToken( msg, '|', 9 + i * 3 - 2 ); + } +#ifdef _CHANNEL_MODIFY + pc.etcFlag |= PC_ETCFLAG_CHAT_CHAT; +#endif +} + +#ifdef _CHATROOMPROTOCOL +void ChatRoomWnd( void ) //Ӵ +{ + char tmpMsg[STR_BUFFER_SIZE]; + int nameColor; + int scrlLenth = 183; + + if(pChtChanlWnd == NULL){ + pChtChanlWnd = MakeWindowDisp( 350, 60, 540, 456, 0, -1 ); + } + else if( pChtChanlWnd->hp > 0 ){ + int x = pChtChanlWnd->x + 2; + int y = pChtChanlWnd->y - 5; + + int scrTop = y + 69; //Scroll߶ + + StockDispBuffer( ( ( WINDOW_DISP *)pChtChanlWnd->pYobi )->mx - 120, ( ( WINDOW_DISP *)pChtChanlWnd->pYobi )->my -28, DISP_PRIO_MENU, CG_FIELD_CHATROOM_PANEL, 1 ); + char title[32] = {""}; + + sprintf_s(title,"%s" ,chatInfo.roomName); + + StockFontBuffer( x + 140 - strlen(title) * 4 , y + 50, FONT_PRIO_FRONT,4 , title, 0 ); + + if(!BtnType){ + closeBtn = CG_FIELD_CLOSE_BTN_UP; + leaveBtn = CG_FIELD_LEAVE_BTN_UP; + scrlHBtn = CG_FIELD_SCROLL_HUP; + scrlLBtn = CG_FIELD_SCROLL_LUP; + + if(chatInfo.chiefFlag == 1){ //ӳרаť + delBtn = CG_FIELD_DELETE_BTN_UP; + if(secretFlag && chatInfo.chiefIndex != chatInfo.memberIndex[selChar]){ + outBtn = CG_FIELD_OUTMEMBER_BTN_UP; + chaBtn = CG_FIELD_CHANGECHIEF_BTN_UP; + } + else{ + outBtn = CG_FIELD_OUTMEMBER_BTN_DISABLE; + chaBtn = CG_FIELD_CHANGECHIEF_BTN_DISABLE; + } + }else{ + outBtn = CG_FIELD_OUTMEMBER_BTN_DISABLE; + chaBtn = CG_FIELD_CHANGECHIEF_BTN_DISABLE; + delBtn = CG_FIELD_DELETE_BTN_DISABLE; + } + } + ChatRoomBtn[0] = StockDispBuffer( x + 70 , y + 335, DISP_PRIO_IME3, closeBtn, 2 ); + ChatRoomBtn[1] = StockDispBuffer( x + 230, y + 335, DISP_PRIO_IME3, leaveBtn, 2 ); + ChatRoomBtn[2] = StockDispBuffer( x + 150, y + 305, DISP_PRIO_IME3, outBtn, 2 ); + ChatRoomBtn[3] = StockDispBuffer( x + 230, y + 305, DISP_PRIO_IME3, chaBtn, 2 ); + ChatRoomBtn[4] = StockDispBuffer( x + 70, y + 305, DISP_PRIO_IME3, delBtn, 2 ); + ChatRoomBtn[5] = StockDispBuffer( x + 267, scrTop + scrlBtnIndex, DISP_PRIO_IME3, CG_FIELD_CHANNEL_SCROLL ,2); + ChatRoomBtn[6] = StockDispBuffer( x + 267, scrTop -20, DISP_PRIO_IME3, scrlHBtn ,2); + ChatRoomBtn[7] = StockDispBuffer( x + 267, y + 274, DISP_PRIO_IME3, scrlLBtn ,2); + + for(int i = 0 ; i < 10 ; i++ ){ + if(chatInfo.memberNum - 1 < i + firMemNo ) + break; + //ɫ + if( MakeHitBox(x + 20 ,y + 77 + i * 20 , x + 250 , y + 96+ i * 20, DISP_PRIO_BOX2 )){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if(strcmp(chatInfo.memberName[i + firMemNo], pc.name) != 0 || strcmp(chatInfo.nickName[i + firMemNo], pc.freeName) != 0){ + if(secretFlag == TRUE && selChar == i){ + strcpy(secretName,""); + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer1(secretName); + secretFlag = FALSE; + selChar = -1; + TalkMode = 0; + }else{ + sprintf_s(secretName,"%s ",chatInfo.memberName[i+ firMemNo]); + pNowStrBuffer->buffer[ 0 ] = NULL; + pNowStrBuffer->cursor=0; + pNowStrBuffer->cnt = 0; + StrToNowStrBuffer1(secretName); + secretFlag = TRUE; + TalkMode = 1; + selChar = i + firMemNo; + } + } + } + } + + if(secretFlag && selChar == i + firMemNo) + nameColor = 4; + else + nameColor = 5; + + StockFontBuffer( x + 30, y + 80 + i * 20, FONT_PRIO_FRONT,nameColor , chatInfo.memberName[i + firMemNo], 0 ); + StockFontBuffer( x + 160, y + 80 + i * 20, FONT_PRIO_FRONT,nameColor , chatInfo.nickName[i + firMemNo], 0 ); + + } + + for( int i = 0; i < 8; i++){ + if( i == 2 && chatInfo.chiefFlag == 0 ) //Ƕӳť + i = 5; + else if( i == 2 && chatInfo.chiefFlag == 1 && selChar == -1) //Ƕӳδѡ + i = 4; + + if( HitDispNo == ChatRoomBtn[ i ] ) { + if( mouse.onceState & MOUSE_LEFT_CRICK ) { + switch(i){ + case 0: + closeBtn = CG_FIELD_CLOSE_BTN_DOWN; + break; + case 1: + leaveBtn = CG_FIELD_LEAVE_BTN_DOWN; + break; + case 2: + outBtn = CG_FIELD_OUTMEMBER_BTN_DOWN; + break; + case 3: + chaBtn = CG_FIELD_CHANGECHIEF_BTN_DOWN; + break; + case 4: + delBtn = CG_FIELD_DELETE_BTN_DOWN; + break; + case 5: + scrollFlag = TRUE; + break; + case 6: + if(firMemNo >0) + { + firMemNo --; + scrlBtnIndex = (scrlLenth/(chatInfo.memberNum -10)) * firMemNo; + scrlHBtn = CG_FIELD_SCROLL_HDOWN; + } + break; + case 7: + if( chatInfo.memberNum > firMemNo + 10 && chatInfo.memberNum > 10) + { + firMemNo ++; + scrlBtnIndex = (scrlLenth/(chatInfo.memberNum -10)) * firMemNo; + scrlLBtn = CG_FIELD_SCROLL_LDOWN; + } + break; + } + BtnNo = i; + BtnType = TRUE; + + }else if(mouse.onceState & MOUSE_LEFT_CRICK_UP){ + switch(i){ + case 0: //رӴ + DeathMenuAction(); + break; + + case 1: //뿪Ƶ + if(chatInfo.chiefFlag == 1) + StockChatBufferLine( "ҳ뿪,뿪뻻˵ҳ" , FONT_PAL_RED); + else{ + lssproto_CHATROOM_send ( sockfd , "L|" ) ; + strcpy(pc.chatRoomNum,""); + DeathMenuAction(); + StockChatBufferLine( "뿪" , FONT_PAL_BLUE); + TalkMode = 0; +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_CHAT; +#endif + } + break; + + case 2: // + sprintf_s(tmpMsg,"K|%d", chatInfo.memberIndex[selChar]); + lssproto_CHATROOM_send ( sockfd , tmpMsg ) ; + break; + + case 3: //ӳ + sprintf_s(tmpMsg,"M|%d", chatInfo.memberIndex[selChar]); + lssproto_CHATROOM_send ( sockfd , tmpMsg ); + TalkMode = 0; + break; + + case 4: //ɾƵ + lssproto_CHATROOM_send ( sockfd ,"D|") ; + strcpy(pc.chatRoomNum,""); + TalkMode = 0; +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_CHAT; +#endif + break; + } + secretFlag = FALSE; + selChar = -1; + + } + } + } + + if(mouse.onceState & MOUSE_LEFT_CRICK_UP || HitDispNo != ChatRoomBtn[ BtnNo ]) + BtnType = FALSE; + + if(mouse.onceState & MOUSE_LEFT_CRICK_UP || mouse.nowPoint.x < x ) + scrollFlag =FALSE; + + if(scrollFlag){ + if( mouse.nowPoint.y > scrTop -2 && mouse.nowPoint.y < (scrTop + scrlLenth + 4) ){ + if(chatInfo.memberNum > 10){ + firMemNo = (mouse.nowPoint.y - scrTop) / (scrlLenth/(chatInfo.memberNum -10)); + scrlBtnIndex = mouse.nowPoint.y - scrTop; + }else + scrlBtnIndex = 0; + } + } + } +} +#endif + +void initAssentWnd(char *data) //ҪӴ +{ + assentFlag = TRUE; + char temp[64]; + getStringToken( data, '|', 2 , sizeof(temp) -1 ,temp ); + sprintf_s(memInfo,"%s ",temp); + memIndex = getIntegerToken( data, '|', 3); +} + +#ifdef _CHATROOMPROTOCOL +void AssentWnd(void) //ҪӴ +{ + int i = 0; + char tmpMsg[128] = {""}; + + int AssentBtn[2]; + int x,y; + if(pAssentWnd == NULL) + pAssentWnd = MakeWindowDisp( 270, 0, 3, 2 , 2, 0 ); + else if( pAssentWnd->hp > 0){ + x = pAssentWnd->x; + y = pAssentWnd->y; + + StockFontBuffer( x + 20 , y + 30, FONT_PRIO_FRONT,5 , memInfo, 0 ); + AssentBtn[0] = StockDispBuffer( x + 90, y + 60, DISP_PRIO_IME3, CG_FIELD_AGREE_BTN, 2 ); + AssentBtn[1] = StockDispBuffer( x + 100, y + 60, DISP_PRIO_IME3, CG_FIELD_DISAGREE_BTN, 2 ); + + for( i = 0; i < 2; i++){ + if( HitDispNo == AssentBtn[ i ] ){ + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + if(i == 0){ + sprintf_s(tmpMsg,"A|%d|1", memIndex); + lssproto_CHATROOM_send ( sockfd ,tmpMsg) ; + } + else{ + sprintf_s(tmpMsg,"A|%d|0", memIndex); + lssproto_CHATROOM_send ( sockfd , tmpMsg ) ; + } + DeathAction(pAssentWnd); + pAssentWnd = NULL; + assentFlag = FALSE; + } + } + } + } +} +#endif + +#ifdef _CHANNEL_MODIFY +void SaveChatData(char *msg,char KindOfChannel,bool bCloseFile); +#endif + +void InitRecvMsg(char *data) +{ + char temp[STR_BUFFER_SIZE]; + char msg[STR_BUFFER_SIZE]; + getStringToken( data, '|', 2 , sizeof(temp) -1 ,temp ); +#ifndef _CHANNEL_MODIFY + sprintf_s(msg,"[Ƶ]%s",temp); +#else + sprintf_s(msg,"[]%s",temp); + TradeTalk(msg); + SaveChatData(msg,'R',false); +#endif + StockChatBufferLine( msg, 2); +} + +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +void lssproto_CHATROOM_recv ( int fd, char *data) +{ + char type[3] = {""}; + int i = 0; + getStringToken( data, '|', 1, sizeof( type ) - 1, type); + switch(type[0]){ + case 'B': + InitSelChatRoom(data); + break; + case 'D': //Delete + chatRoomBtn = 0; + strcpy(pc.chatRoomNum,""); + StockChatBufferLine( "ѱɾ" , FONT_PAL_RED); +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_CHAT; +#endif + break; + case 'T': + InitRecvMsg(data); //ѶϢ + break; + case 'K'://޳ + chatRoomBtn = 0; + strcpy(pc.chatRoomNum,""); + StockChatBufferLine( "ѱҳ߳ң" , FONT_PAL_RED); +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_CHAT; +#endif + break; + case 'J':// + if(assentFlag == FALSE) + { + DeathAction(pAssentWnd); + pAssentWnd = NULL; + initAssentWnd(data); + } + break; + case 'R': //Ѷ + InitCreateChatRoom(data); + break; + } +} +#endif + +#endif + +#ifdef _TIMEBAR_FUNCTION +/*********************************************************** +: +title : TimeBar ͷ Χ32bit +range : TimeBar Χ +شֵ: TimeBar ʶ.趨ȷֵ + +barHolder[timBarIdent] : жǷΪ˺ʽӵ +***********************************************************/ +int SetTimeBar(char *title, int range) +{ + int timBarIdent = 0; + if(strlen(title) > 32) + return -1; + if(timeBarFlag = TRUE){ + DeathAction(pTimeBarWnd); + pTimeBarWnd = NULL; + if(barHolder[0]){ + barHolder[0] = FALSE; + barHolder[1] = TRUE; + timBarIdent = 1; + } + else{ + barHolder[1] = FALSE; + barHolder[0] = TRUE; + timBarIdent = 0; + } + } + else{ + barHolder[0] = TRUE; + timBarIdent = 0; + } + strcpy(timeBarTitle , title); + timeBarRange = range; + timeBarFlag = TRUE; + + return timBarIdent; +} +/******************************************* +return -1: ע!!޷趨ڵλַ,ܱʽռ +return 1: Ѿ 100 % +*******************************************/ +int SetTimeBarPos(int timBarIdent, int CurPos) +{ + if(!barHolder[timBarIdent] )//|| CurPos > timeBarRange) + return -1; + timeBarCurPos = 20 * CurPos / timeBarRange; //20Ϊbarĵλ. + if(timeBarCurPos > 20){ + timeBarCurPos = 20; + return 1; //Ѿ100 % + } + return 0; +} + +void DrawTimeBar() +{ + if(pTimeBarWnd == NULL){ + pTimeBarWnd = MakeWindowDisp( 270, 0, 3, 2 , 2, 0 ); + } + else if( pTimeBarWnd->hp > 0){ + int x = pTimeBarWnd->x; + int y = pTimeBarWnd->y; + char percent[4] = { "" }; + sprintf_s(percent, "%d", (timeBarCurPos * 5)); + StockFontBuffer(x + 20, y + 30, FONT_PRIO_FRONT, 5, timeBarTitle, 0); + StockFontBuffer(x + 50, y + 50, FONT_PRIO_FRONT, 5, percent, 0); + for (int i = 0; i < timeBarCurPos; i++) + StockDispBuffer(x + i * 10, y + 60, DISP_PRIO_IME3, CG_TIMEBAR_UNIT, 2); + } +} +#endif + +#ifdef _STANDBYPET +void send_StandBy_Pet(void) +{ + int standbypet = 0; + int i, cnt = 0; + for (i = 0; i 4) + break; + standbypet |= (1 << i); + } + } + lssproto_SPET_send(sockfd, standbypet); + StandbyPetSendFlag = TRUE; +} +#endif +/* ========================================= + +ע!! +Ѿ15ǧˣVC༭Чʵ䣬 +뾡ҪںCodeˡ + +~Robin~ + +ӵmenu2.cpp by Change +========================================= */ + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/menu2.cpp b/石器时代8.5客户端最新源代码/石器源码/system/menu2.cpp new file mode 100644 index 0000000..96bad04 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/menu2.cpp @@ -0,0 +1,230 @@ +/* + menu.cpp ̫,¹д + */ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/font.h" +#include "../other/caryIme.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/pc.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/savedata.h" +#include "../systeminc/t_music.h" +#include "../systeminc/menu.h" +#include "../systeminc/tool.h" +#include "../systeminc/map.h" +#include "../systeminc/field.h" +#include "../systeminc/pet_skillinfo.h" +#include "../wgs/descrypt.h" +#include "../systeminc/character.h" +#ifdef _TALK_WINDOW +#include "../systeminc/talkwindow.h" +#endif + +#ifdef _NPC_ITEMUP +void ShowItemup(int value, int x, int y) +{ + char itemup_msg[256]=""; + int sx=-50,sy=-20; + int s = ((((value)&0xff000000)>>24)&0x000000ff);// + int t = ((((value)&0x00ff0000)>>16)&0x000000ff);// + int d = ((((value)&0x0000ff00)>>8 )&0x000000ff);// + int h = ((value)&0x000000ff);// + if( s > 0 ){ + sprintf_s( itemup_msg, " %d", s); + StockFontBuffer( x+sx , y+sy, FONT_PRIO_FRONT, FONT_PAL_WHITE, itemup_msg, 0 ); + sy-=20; + } + if( t > 0 ){ + sprintf_s( itemup_msg, " %d", t); + StockFontBuffer( x+sx , y+sy, FONT_PRIO_FRONT, FONT_PAL_WHITE, itemup_msg, 0 ); + sy-=20; + } + if( d > 0 ){ + sprintf_s( itemup_msg, " %d", d); + StockFontBuffer( x+sx , y+sy, FONT_PRIO_FRONT, FONT_PAL_WHITE, itemup_msg, 0 ); + sy-=20; + } + +} +#endif + +#ifdef _ITEM_COUNTDOWN +void ShowCounttime(int sectime, int x, int y) +{ + char buf[256]; + int day; + int hour; + int min; + + if( sectime <= 0 ) return; + if (sectime > 86400) + { + day = sectime / 86400; + hour = (sectime / 3600) - (day * 24); + min = (sectime / 60) - (day * 1440) - (hour * 60); + sprintf_s( buf, "Լ%d%dʱ%d", day, hour, min); + } + else if( sectime > 3600 ){ + hour = sectime/3600; + min = (sectime/60)-(hour*60); + sprintf_s( buf,"Լ%dʱ%d",hour,min); + }else if(sectime > 60 ){ + min = sectime/60; + sprintf_s( buf," Լ%d",min); + }else{ + sprintf_s( buf," Լ1"); + } + //StockFontBuffer( x-20 , y-20, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf , 0 ); + StockFontBuffer(x + 30 , y + 10, FONT_PRIO_FRONT, FONT_PAL_WHITE, buf , 0); +} +#endif + + + + +#ifdef _PET_SKINS + +static int btnShowSkinWin = -2; +static int btnShowSkinWinState = FALSE; +ACTION *petActSkins = NULL; +int originalPetSkin; + +void initPetSkinWin() +{ + if (btnShowSkinWin != -2) + { + btnShowSkinWin = -2; + btnShowSkinWinState = FALSE; + if (petActSkins != NULL) + { + DeathAction(petActSkins); + petActSkins = NULL; + } + } +} + +void petChange(int graphNo) +{ + if (petActSkins != NULL) + { + petActSkins->anim_chr_no = graphNo; + } +} + +void petSkinProc() +{ + static int btnPrev; + static int btnNext; + static int btnPrevState; + static int btnNextState; + static int btnSkinSet; + static int btnExit; + static int x = 293, y = 120; + + btnShowSkinWin = StockDispBuffer(76, 290, DISP_PRIO_IME3, CG_PET_SKINS_SHOW_BTN + btnShowSkinWinState, 2); + + if (petActSkins == NULL && btnShowSkinWinState) + { + petActSkins = MakeAnimDisp(x + 65, y + 35, originalPetSkin, ANIM_DISP_PET); + } + + if (HitDispNo == btnShowSkinWin){ + extern void ShowBottomLineString(int iColor, LPSTR lpstr); + ShowBottomLineString(FONT_PAL_WHITE, "Ƥ"); + if (mouse.onceState & MOUSE_LEFT_CRICK){ + + if (btnShowSkinWinState){ + initPetSkinWin(); + play_se(203, 320, 240); + } + else + { + play_se(202, 320, 240); + btnShowSkinWinState = TRUE; + } + } + } + + if (btnShowSkinWinState) + { + //һƤ + if (HitDispNo == btnPrev){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + btnPrevState = TRUE; + } + } + + //һƤ + if (HitDispNo == btnNext){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + btnNextState = TRUE; + } + } + + //趨Ƥ + if (HitDispNo == btnSkinSet){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + + } + } + + //رԤ + if (HitDispNo == btnExit){ + if (mouse.onceState & MOUSE_LEFT_CRICK){ + initPetSkinWin(); + } + } + + if (mouse.onceState & MOUSE_LEFT_CRICK_UP) + { + btnPrevState = FALSE; + btnNextState = FALSE; + } + + StockDispBuffer(358, 133, DISP_PRIO_MENU, CG_PET_SKINS_WIN, 0); + btnPrev = StockDispBuffer(x, y, DISP_PRIO_IME3, CG_PET_SKINS_PREV_BTN + btnPrevState, 2); + btnNext = StockDispBuffer(x + 132, y, DISP_PRIO_IME3, CG_PET_SKINS_NEXT_BTN + btnNextState, 2); + btnSkinSet = StockDispBuffer(323, 246, DISP_PRIO_IME3, CG_PET_SKINS_SET, 2); + btnExit = StockDispBuffer(395, 246, DISP_PRIO_IME3, 55252, 2); + } +} +#endif + + +void CloseMagicItemWin() +{ + extern ACTION* pActMenuWnd2,*pActPet2; + DeathAction(pActMenuWnd2); + + pActMenuWnd2 = NULL; + // ???? + DeathAction(pActPet2); + pActPet2 = NULL; + extern int ItemMixPetNo,itemNo; + // ????k???? + ItemMixPetNo = -1; + // ??????????? + MenuToggleFlag ^= JOY_CTRL_I; + // ?????????????????? + if (MenuToggleFlag & JOY_CTRL_S){ + + MenuToggleFlag ^= JOY_CTRL_S; // CTRL + S ?? + // ?????????? + extern void DeathMenuAction(void); + DeathMenuAction(); + } + // ???????? + play_se(203, 320, 240); + + itemNo = -1; +#ifdef _MONEYINPUT //Syu ADD ֶǮ + extern bool Moneyflag ; + GetKeyInputFocus(&MyChatBuffer); + Moneyflag = false; +#endif +} \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/mouse.cpp b/石器时代8.5客户端最新源代码/石器源码/system/mouse.cpp new file mode 100644 index 0000000..2ece3a1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/mouse.cpp @@ -0,0 +1,850 @@ +/************************/ +/* mouse.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/pc.h" +#include "../systeminc/menu.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/map.h" +#include "../systeminc/login.h" + +// ???????Re??? +#define MOUSE_HIT_SIZE_X 48 +#define MOUSE_HIT_SIZE_Y 48 + +// ?????????????? +#define MOUSE_AUTO_REPEATE_TIME 100 + +// Robin + +// ????Bl +MOUSE mouse; +// ????????????????k???????? +int HitFontNo; +// ????????????k??????? +int HitDispNo; +// ???????? +char OneLineInfoStr[ 256 ]; + +int oneLineInfoFlag = 1; +// ????? +int BoxColor; +extern int transmigrationEffectFlag; + +// ???ѩ???? //////////////////////////////////////////////////////// +void MouseInit( void ) +{ + memset( &mouse, 0, sizeof( MOUSE ) ); + mouse.itemNo = -1; // ????k???? + + +} + +// ????????t????? ////////////////////////////////////////////// +void MouseNowPoint( int x, int y ) +{ + if(ResoMode == 1){ + if(x > 640)x = 640; + if(y > 480)y = 480; + }else{ + if(x > lpDraw->xSize)x = lpDraw->xSize; + if(y > lpDraw->ySize)y = lpDraw->ySize; + } + // ????? + //??????????????? + if(ResoMode == 1){ + mouse.nowPoint.x = x * 2; + mouse.nowPoint.y = y * 2; + } else { + mouse.nowPoint.x = x; + mouse.nowPoint.y = y; + } +} + +// ????????????????????t????? ////////////////////// +void MouseCrickLeftDownPoint( int x, int y ) +{ + // ֢t???? + mouse.state |= MOUSE_LEFT_CRICK; + mouse.onceState |= MOUSE_LEFT_CRICK; + mouse.autoState |= MOUSE_LEFT_CRICK; + // ????? + mouse.crickLeftDownPoint.x = x; + mouse.crickLeftDownPoint.y = y; + // ????????????????@e??q? + mouse.beforeLeftPushTime = TimeGetTime(); + mouse.leftPushTime = 0; +} + +// ???????????????????t????? //////////////////////// +void MouseCrickLeftUpPoint( int x, int y ) +{ + // ֢t???? + mouse.state &= (~MOUSE_LEFT_CRICK); + mouse.onceState |= MOUSE_LEFT_CRICK_UP; + mouse.autoState &= (~MOUSE_LEFT_CRICK); + // ????? + mouse.crickLeftUpPoint.x = x; + mouse.crickLeftUpPoint.y = y; + // ???????????????? + mouse.beforeLeftPushTime = 0; + mouse.leftPushTime = 0; +} + +// ??????????????????t????? ////////////////////////// +void MouseDblCrickLeftUpPoint( int x, int y ) +{ + // ֢t???? + //mouse.onceState |= ( MOUSE_LEFT_DBL_CRICK | MOUSE_LEFT_CRICK ); + mouse.state |= MOUSE_LEFT_CRICK; + mouse.onceState |= MOUSE_LEFT_DBL_CRICK; + mouse.onceState |= MOUSE_LEFT_CRICK; + mouse.autoState |= MOUSE_LEFT_CRICK; + // ????? + mouse.crickLeftDownPoint.x = x; + mouse.crickLeftDownPoint.y = y; + // ????????????????@e??q? + mouse.beforeLeftPushTime = TimeGetTime(); + mouse.leftPushTime = 0; +} + +// ???????????????????t????? //////////////////////// +void MouseCrickRightDownPoint( int x, int y ) +{ + // ֢t???? + mouse.state |= MOUSE_RIGHT_CRICK; + mouse.onceState |= MOUSE_RIGHT_CRICK; + mouse.autoState |= MOUSE_RIGHT_CRICK; + // ????? + mouse.crickRightDownPoint.x = x; + mouse.crickRightDownPoint.y = y; + // ????????????????@e??q? + mouse.beforeRightPushTime = TimeGetTime(); + mouse.rightPushTime = 0; +} + +// ???????????????????t????? //////////////////////// +void MouseCrickRightUpPoint( int x, int y ) +{ + // ֢t???? + mouse.state &= (~MOUSE_RIGHT_CRICK); + mouse.onceState |= MOUSE_RIGHT_CRICK_UP; + mouse.autoState &= (~MOUSE_RIGHT_CRICK); + // ????? + mouse.crickRightUpPoint.x = x; + mouse.crickRightUpPoint.y = y; + // ???????????????? + mouse.beforeRightPushTime = 0; + mouse.rightPushTime = 0; +} + +// ??????????????????t????? ////////////////////////// +void MouseDblCrickRightUpPoint( int x, int y ) +{ + // ֢t???? + mouse.state |= MOUSE_RIGHT_CRICK; + mouse.onceState |= MOUSE_RIGHT_DBL_CRICK; + mouse.onceState |= MOUSE_RIGHT_CRICK; + mouse.autoState |= MOUSE_RIGHT_CRICK; + // ????? + mouse.crickRightDownPoint.x = x; + mouse.crickRightDownPoint.y = y; + // ????????????????@e??q? + mouse.beforeRightPushTime = TimeGetTime(); + mouse.rightPushTime = 0; +} + +// ????? /////////////////////////////////////////////////////////////// +void MouseProc( void ) +{ + static UINT leftPushTimeBak; + static UINT rightPushTimeBak; + + // ֢t???? + mouse.onceState = MOUSE_NO_CRICK; + // ??????????????????? + if( mouse.beforeLeftPushTime > 0 ) + { + mouse.leftPushTime = TimeGetTime() - mouse.beforeLeftPushTime; + } + // ??????????????????? + if( mouse.beforeRightPushTime > 0 ) + { + mouse.rightPushTime = TimeGetTime() - mouse.beforeRightPushTime; + } + // ????????? + // ???????????? + // ????????? + if( mouse.leftPushTime > 500 ){ + // ??????? + if( leftPushTimeBak == 0 ){ + mouse.autoState |= MOUSE_LEFT_CRICK; // ????? + leftPushTimeBak = mouse.leftPushTime; // ????? + }else + // ????????? + if( mouse.leftPushTime - leftPushTimeBak >= MOUSE_AUTO_REPEATE_TIME ){ + mouse.autoState |= MOUSE_LEFT_CRICK; // ????? + leftPushTimeBak = mouse.leftPushTime; // ????? + }else{ // ????????? + mouse.autoState &= (~MOUSE_LEFT_CRICK); // ?????? + } + }else{ + mouse.autoState &= (~MOUSE_LEFT_CRICK); // ?????? + leftPushTimeBak = 0; + } + + // ???????????? + // ????????? + if( mouse.rightPushTime > 500 ){ + // ??????? + if( rightPushTimeBak == 0 ){ + mouse.autoState |= MOUSE_RIGHT_CRICK; // ????? + rightPushTimeBak = mouse.rightPushTime; // ????? + }else + // ????????? + if( mouse.rightPushTime - rightPushTimeBak >= MOUSE_AUTO_REPEATE_TIME ){ + mouse.autoState |= MOUSE_RIGHT_CRICK; // ????? + rightPushTimeBak = mouse.rightPushTime; // ????? + }else{ // ????????? + mouse.autoState &= (~MOUSE_RIGHT_CRICK); // ?????? + } + }else{ + mouse.autoState &= (~MOUSE_RIGHT_CRICK); // ?????? + rightPushTimeBak = 0; + } + + + + // ???????????? + //if( mouse.rightPushTime > 0 ){ + //}else mouse.state &= (~MOUSE_RIGHT_AUTO_CRICK); + // ???????????? + //if( !WindowMode ){ + //if( 0 <= mouse.nowPoint.x && mouse.nowPoint.x < 640 && + // 0 <= mouse.nowPoint.y && mouse.nowPoint.y < 480 ){ + + // ???????? + if( MouseCursorFlag == FALSE ){ + if( mouse.flag == FALSE ){ + StockDispBuffer( mouse.nowPoint.x + 16, mouse.nowPoint.y + 16, DISP_PRIO_MOUSE, CG_MOUSE_CURSOR, 0 ); + } + } + +} +// ????k???? *********************************************************/ +void CheckGroupSelect( int no ) +{ + int i; + DISP_INFO *pDispInfo; + DISP_SORT *pDispSort; + /* ??????????????I???????? */ + for( i = 0 ; i < DispBuffer.DispCnt ; i++ ){ + + pDispInfo = DispBuffer.DispInfo + i; + pDispSort = DispBuffer.DispSort + i; + + // ?????????? + if( pDispInfo->hitFlag == no ){ + // ?????????? + if( pDispSort->dispPrio >= DISP_PRIO_MENU ){ + // ???????????????? +#ifndef __CARYTEST + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX2, BoxColor, 0 ); +#else + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX2, BoxColor, 0 ); +#endif + }else{ + // ???????????????? +#ifndef __CARYTEST + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX, BoxColor, 0 ); + //pDispSort->dispPrio, 250, 0 ); +#else + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX, BoxColor, 0 ); +#endif + } + } + } +} + +#if 1 +// ???????????? +UCHAR BoxColorTbl[] = { + //255, 255, 255, 255, 255, + //8,8,8,8,8, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 250,250,250,250,250, + 15,15,15,15,15, + 2,2,2,2,2, + 15,15,15,15,15, + //250,250,250,250,250, + //8,8,8,8,8, + }; +#else +UCHAR BoxColorTbl[] = { + 255,255,255,255,255,255,255,255,255,255, + 255,255,255,255,255,255,255,255,255,255, + 7,7,7,7,7,7,7,7,7,7, + 248,248,248,248,248,248,248,248,248,248, + 0,0,0,0,0,0,0,0,0,0, + 248,248,248,248,248,248,248,248,248,248, + 7,7,7,7,7,7,7,7,7,7, + }; +#endif + +/* ???????????Re **************************************************/ +void HitMouseCursor( void ) +{ + int i; // ??????? + int strWidth; // ??????? + int hitFlag = FALSE; // ???Re??? + static int cnt = 0; // ????? + int itemNameColor = FONT_PAL_WHITE; // ????? + + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt - 1; + DISP_INFO *pDispInfo; + + // ?????? + if( !transmigrationEffectFlag ) + oneLineInfoFlag = 1; + else + oneLineInfoFlag = 0; + + if( cnt >= sizeof( BoxColorTbl ) - 1 ) cnt = 0; + else cnt++; + + // ?????@e + BoxColor = BoxColorTbl[ cnt ]; +#ifdef _ITEM_PATH + ITEMPATHFLAG = FALSE; +#endif + /* ?????????????????????????????i??*/ + for( i = 0 ; i < FontCnt ; i++ ){ + + // ???Re?????? + if( FontBuffer[ i ].hitFlag == 0 ) continue; + + // ?????????????? + + strWidth = GetStrWidth( FontBuffer[ i ].str ); + + // ?????Re + if( mouse.nowPoint.x <= FontBuffer[ i ].x + strWidth + 2 && + FontBuffer[ i ].x - 2 <= mouse.nowPoint.x && + + mouse.nowPoint.y <= FontBuffer[ i ].y + FONT_SIZE + 2 && + + FontBuffer[ i ].y - 2 <= mouse.nowPoint.y ){ + + // ??????k????? + HitFontNo = i; + + // ???????? + if( FontBuffer[ i ].hitFlag == 2 ){ + // ???????????????? + StockBoxDispBuffer( FontBuffer[ i ].x - 3, +#ifdef _NEWFONT_ + FontBuffer[ i ].y - 2, +#else + FontBuffer[ i ].y - 4, +#endif + FontBuffer[ i ].x + strWidth + 2, +#ifdef _NEWFONT_ + FontBuffer[ i ].y + FONT_SIZE + 6, +#else + FontBuffer[ i ].y + FONT_SIZE + 4, +#endif + + DISP_PRIO_BOX2, BoxColor, 0 ); + + SortDispBuffer(); + } + HitDispNo = -1; + // ?????? + mouse.level = DISP_PRIO_MENU; + // ????????? + if( TaskBarFlag == FALSE && oneLineInfoFlag ){ + ShowBottomLineString(itemNameColor, OneLineInfoStr); + //the third StockFontBuffer( 8, 460, FONT_PRIO_FRONT, itemNameColor, OneLineInfoStr, 0 ); + } + // ????? + OneLineInfoStr[ 0 ] = NULL; + return; // ??????????????Re???? + } + } + // ??????k??????? + HitFontNo = -1; + + /* ??????????????I???????? */ + for( i = DispBuffer.DispCnt - 1; i >= 0 ; i--, pDispSort-- ){ + // ????V???????????? + pDispInfo = DispBuffer.DispInfo + pDispSort->no; + + // ???Re?????? + if( pDispInfo->hitFlag == 0 ) continue; + + // ????????????Q + //if( SpriteInfo[ pDispInfo->bmpNo ].lpSurfaceInfo == NULL ) continue; + // ????????????????????????? + // ????????? + if( LoadBmp( pDispInfo->bmpNo ) == FALSE ) continue; + + // ????????? + if( pDispInfo->pAct == NULL ){ + // ?????Re +#ifndef __CARYTEST + if( mouse.nowPoint.x <= pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width && + pDispInfo->x <= mouse.nowPoint.x && + mouse.nowPoint.y <= pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height && + pDispInfo->y <= mouse.nowPoint.y ) +#else + if( mouse.nowPoint.x <= pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width && + pDispInfo->x <= mouse.nowPoint.x && + mouse.nowPoint.y <= pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height && + pDispInfo->y <= mouse.nowPoint.y ) +#endif + hitFlag = TRUE; + }else{ + // ?????Re???????? +#ifndef __CARYTEST + if( mouse.nowPoint.x <= pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width * 0.5 + MOUSE_HIT_SIZE_X * 0.5 && + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width * 0.5 - MOUSE_HIT_SIZE_X * 0.5 <= mouse.nowPoint.x && + mouse.nowPoint.y <= pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height && + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height - MOUSE_HIT_SIZE_Y <= mouse.nowPoint.y ) +#else + if( mouse.nowPoint.x <= pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width * 0.5 + MOUSE_HIT_SIZE_X * 0.5 && + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width * 0.5 - MOUSE_HIT_SIZE_X * 0.5 <= mouse.nowPoint.x && + mouse.nowPoint.y <= pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height && + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height - MOUSE_HIT_SIZE_Y <= mouse.nowPoint.y ) +#endif + hitFlag = TRUE; + } + + // ??????? + if( hitFlag == TRUE ){ + + #ifdef __ATTACK_MAGIC + + int cnt; + + for( cnt = 0 ; cnt < BATTLKPKPLYAERNUM ; cnt++ ) + { + if( p_party[cnt] == pDispInfo->pAct ) + break; + } + + // ϵ±Ϊ6 , 7 , 8 , 9 + // ѡĿǰѡҷλ + if( BattleMyNo >= 10 && ( 6 == pDispInfo->hitFlag || 7 == pDispInfo->hitFlag ) ) + { + hitFlag = FALSE; + continue; + } + // ѡĿǰѡҷλ + if( BattleMyNo < 10 && ( 8 == pDispInfo->hitFlag || 9 == pDispInfo->hitFlag ) ) + { + hitFlag = FALSE; + continue; + } +#ifdef _SKILL_ADDBARRIER + // ֻѡҷ + if( BattleMyNo < 10 && ( 10 == pDispInfo->hitFlag || 11 == pDispInfo->hitFlag ) ) + { + hitFlag = FALSE; + continue; + } + if( BattleMyNo >= 10 && ( 12 == pDispInfo->hitFlag || 13 == pDispInfo->hitFlag ) ) + { + hitFlag = FALSE; + continue; + } +#endif + #endif + + // ????????? +// StockFontBuffer( pDispInfo->x, pDispInfo->y, FONT_PRIO_FRONT, 0, "Hit", 1 ); + + // ??????k???? + HitDispNo = pDispSort->no; + + // ???????? + if( pDispInfo->hitFlag >= 2 ){ + // ?????????? + if( pDispSort->dispPrio >= DISP_PRIO_YES_NO_WND ){ + // ???????????????? +#ifndef __CARYTEST + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height + 2, + //DISP_PRIO_BOX2, 250, 0 ); + DISP_PRIO_BOX3, BoxColor, 0 ); +#else + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX3, BoxColor, 0 ); +#endif + }else + // ?????????? + if( pDispSort->dispPrio >= DISP_PRIO_MENU ){ + // ???????????????? +#ifndef __CARYTEST + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height + 2, + //DISP_PRIO_BOX2, 250, 0 ); + DISP_PRIO_BOX2, BoxColor, 0 ); +#else + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX2, BoxColor, 0 ); +#endif + }else{ + // ???????????????? +#ifndef __CARYTEST + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + SpriteInfo[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + SpriteInfo[ pDispInfo->bmpNo ].height + 2, + //DISP_PRIO_BOX, 250, 0 ); + DISP_PRIO_BOX, BoxColor, 0 ); + //pDispSort->dispPrio, 250, 0 ); +#else + StockBoxDispBuffer( pDispInfo->x - 2, pDispInfo->y - 2, + pDispInfo->x + g_lpRealAdrn[ pDispInfo->bmpNo ].width + 2, + pDispInfo->y + g_lpRealAdrn[ pDispInfo->bmpNo ].height + 2, + DISP_PRIO_BOX, BoxColor, 0 ); +#endif + } + + // ????k??????k? + if( pDispInfo->hitFlag >= 3 ) CheckGroupSelect( pDispInfo->hitFlag ); + SortDispBuffer(); // ??????? + } + + // ????????? + if( TaskBarFlag == FALSE ){ + // ????????????? + if( pDispInfo->pAct != NULL ){ + // ?????????? + if( pDispInfo->pAct->atr & ACT_ATR_INFO ){ + if( ProcNo == PROC_GAME ){ +#ifdef _MOUSE_SHOW_INFO_FOR_HEAD + int left = GetStrWidth(pDispInfo->pAct->name)/2; + itemNameColor = pDispInfo->pAct->itemNameColor; + StockFontBuffer( pDispInfo->x+20 - left, pDispInfo->y-10, FONT_PRIO_FRONT, itemNameColor, pDispInfo->pAct->name, 0 ); +#endif + + + + // ??? + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%4d/%4d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // ?????????? + // ??????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_PC ){ + // q?@e + itemNameColor = pDispInfo->pAct->itemNameColor; + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // shan add + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + if( pDispInfo->pAct->petName[ 0 ] != NULL ) + if( pc.familyName[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s [%s] Lv%d ͣ%d%d %d %s Lv%d", + pc.familyName, pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %d %s Lv%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + if( pc.familyName[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s [%s] Lv%d ͣ%d%d %d", + pc.familyName, pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + if( pDispInfo->pAct->petName[ 0 ] != NULL ) + if( pc.familyName[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s Lv%d ͣ%d%d %d %s Lv%d", + pc.familyName, pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d %s Lv%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + if( pc.familyName[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s Lv%d ͣ%d%d %d", + pc.familyName, pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pc.mp ); + } + }else + // \???????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_OTHER_PC ){ +#ifdef _MOUSE_DBL_CLICK + if( mouseDblRightOn ) { + openServerWindow( WINDOW_MESSAGETYPE_MOUSEGETNAME, 0, 0, 0, pDispInfo->pAct->name); + return; + } +#endif + // q?@e + itemNameColor = pDispInfo->pAct->itemNameColor; + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // shan add + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + if( pDispInfo->pAct->petName[ 0 ] != NULL ) + if( pDispInfo->pAct->fmname[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s [%s] Lv%d %s Lv%d", pDispInfo->pAct->fmname, pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d %s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + if( pDispInfo->pAct->fmname[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s [%s] Lv%d", pDispInfo->pAct->fmname, pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + if( pDispInfo->pAct->petName[ 0 ] != NULL ) + if( pDispInfo->pAct->fmname[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s Lv%d %s Lv%d", pDispInfo->pAct->fmname, pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d %s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); + else + if( pDispInfo->pAct->fmname[0] != NULL ) + sprintf_s( OneLineInfoStr,"{%s} %s Lv%d", pDispInfo->pAct->fmname, pDispInfo->pAct->name, pDispInfo->pAct->level ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + } + }else + // ????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_PET ){ + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + }else{ + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + } + }else + // ?????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_ITEM ){ + // q?@e + itemNameColor = pDispInfo->pAct->itemNameColor; + sprintf_s( OneLineInfoStr,"%s", pDispInfo->pAct->name ); +#ifdef _ITEM_PATH + ITEMPATHFLAG = TRUE; +#endif + }else + // ???? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_GOLD ){ + sprintf_s( OneLineInfoStr,"%s", pDispInfo->pAct->name ); + }else + // ??\?????????Y? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_OTHER ){ + sprintf_s( OneLineInfoStr,"%s", pDispInfo->pAct->name ); + } + }else + // Pf?? + if( ProcNo == PROC_BATTLE ){ + // ????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_PET ){ + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + }else{ + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + } + }else + // ?????? + if( pDispInfo->pAct->atr & ACT_ATR_TYPE_ITEM ){ + // q?@e + //itemNameColor = pDispInfo->pAct->itemNameColor; + sprintf_s( OneLineInfoStr,"%s", pDispInfo->pAct->name ); + }else + // ?P????????? + if( BattleMyNo < BATTLKPKPLYAERNUM ){ + // ??????? + if( ( (ATR_EQU *)pDispInfo->pAct->pYobi )->place_no == BattleMyNo ){ + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // Robin 0728 ride Pet + if( pDispInfo->pAct->onRide == 1 ) + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %d %s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pDispInfo->pAct->mp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp, pDispInfo->pAct->petMaxHp ); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pDispInfo->pAct->mp ); + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, BattleMyMp ); + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pDispInfo->pAct->mp ); + // Robin 0728 + if( pDispInfo->pAct->onRide == 1 ) + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d %s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pDispInfo->pAct->mp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp, pDispInfo->pAct->petMaxHp ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, pDispInfo->pAct->mp ); + } + } + else + // s???? + if( ( (ATR_EQU *)p_party[ BattleMyNo ]->pYobi )->group_flg == ( (ATR_EQU *)pDispInfo->pAct->pYobi )->group_flg ){ + // ??? + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%4d/%4d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // shan add + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // Robin 0728 + if( pDispInfo->pAct->onRide == 1 ) + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d %s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp, pDispInfo->pAct->petMaxHp); + else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // Robin 0728 + if( pDispInfo->pAct->onRide == 1 ) + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d %s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp, pDispInfo->pAct->petMaxHp ); + else + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + } + }else{ // ??? + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // shan add + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + // Robin + if( pDispInfo->pAct->onRide == 1 ) +#ifdef _STONDEBUG_ + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d %s Lv%d ͣ%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp ); +#else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d %s Lv%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); +#endif + else +#ifdef _STONDEBUG_ + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); +#else + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", + pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); +#endif + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + // Robin + if( pDispInfo->pAct->onRide == 1 ) +#ifdef _STONDEBUG_ + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d %s Lv%d ͣ%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel, pDispInfo->pAct->petHp ); +#else + sprintf_s( OneLineInfoStr,"%s Lv%d %s Lv%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, + pDispInfo->pAct->petName, pDispInfo->pAct->petLevel ); +#endif + else +#ifdef _STONDEBUG_ + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", + pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); +#else + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); +#endif + } + } + }else{ // ?P????? +#ifdef _STONDEBUG_ + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + // shan add + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + }else{ + // shan add + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + //sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + } +#else + // ???? + if( pDispInfo->pAct->freeName[ 0 ] != NULL ){ + //sprintf_s( OneLineInfoStr,"%s [%s] Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // shan add + sprintf_s( OneLineInfoStr,"%s [%s] Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->freeName, pDispInfo->pAct->level ); + }else{ + //sprintf_s( OneLineInfoStr,"%s Lv%d ͣ%d%d", pDispInfo->pAct->name, pDispInfo->pAct->level, pDispInfo->pAct->hp, pDispInfo->pAct->maxHp ); + // shan add + sprintf_s( OneLineInfoStr,"%s Lv%d", pDispInfo->pAct->name, pDispInfo->pAct->level ); + } +#endif + } + } + } + } + if( oneLineInfoFlag) + ShowBottomLineString(itemNameColor, OneLineInfoStr); + } + // ????? + OneLineInfoStr[ 0 ] = NULL; + + // ?????? + mouse.level = pDispSort->dispPrio; + return; + } + } + // ?????? + mouse.level = DISP_PRIO_TILE; + // ??????k??????? + HitDispNo = -1; + + // ????????? + if( TaskBarFlag == FALSE ){ + ShowBottomLineString(itemNameColor, OneLineInfoStr); + } + // ????? + OneLineInfoStr[ 0 ] = NULL; + +} + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/netmain.cpp b/石器时代8.5客户端最新源代码/石器源码/system/netmain.cpp new file mode 100644 index 0000000..95a7250 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/netmain.cpp @@ -0,0 +1,661 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include +#include "../systeminc/netmain.h" +#include "../systeminc/lssproto_cli.h" +#include "../wgs/message.h" +#include "../systeminc/login.h" +#include +#include "zlib.h" +#pragma comment(lib,"zlib.lib") +// Nuke 0615: Avoid 7's lock +int isWGS7=0; + +unsigned int sockfd; // SOCKET ? unsigned int? +int init_net; // WSAStartup??????????????????server_choosed?????? +int server_choosed; // ?????k??????????????? + +char *net_writebuf = NULL; +char *net_readbuf = NULL; +int net_readbuflen; +int net_writebuflen; + +BOOL disconnectServerFlag = FALSE; +BOOL oldDisconnectServerFlag = FALSE; + +#ifdef _LOG_MSG +char debugLogFileName[256] = "recvdata.txt"; // ????????????????? +#endif + + +struct gameserver gmsv[MAX_GMSV]; + +// ????????ѩ?x?? +// ??: int index : V?????k??0 ??getServerMax?k-1?????? +// char *hostname : IP????? +// short *port : ???k? +// ??k: 0 ... ? +// -1 ... +// +// ?????I/O???? +int getServerInfo( int index, char *hostname, short *port ) +{ + if( index < 0 || index >= sizeof( gmsv)/sizeof( gmsv[0] ) ) + return -1; + + strcpy( hostname,gmsv[index].ipaddr ); + *port = atoi( gmsv[index].port ); + + return 0; +} + +/* + ???????????????????????????? + + ?????????????????????? + + + ?????I/O?????? + + */ +char rpc_linebuffer[NETBUFSIZ]; // rpc? + +extern int testCnt; + +#ifdef _STONDEBUG_ +int CheckNetErrror( void ) +{ + int error = WSAGetLastError(); + // ??????Re + switch ( error ){ + case WSANOTINITIALISED: + return error; + case WSAENETDOWN: + return error; + case WSAEACCES: + return error; + case WSAEINTR: + return error; + case WSAEINPROGRESS: + return error; + case WSAEFAULT: + return error; + case WSAENETRESET: + return error; + case WSAENOBUFS: + return error; + case WSAENOTCONN: + return error; + case WSAENOTSOCK: + return error; + case WSAEOPNOTSUPP: + return error; + case WSAESHUTDOWN: + return error; + case WSAEWOULDBLOCK: + return error; + case WSAEMSGSIZE: + return error; + case WSAEINVAL: + return error; + case WSAECONNABORTED: + return error; + case WSAECONNRESET: + return error; + case WSAETIMEDOUT: + return error; + default: + return error; + } + return error; +} +#endif + +#ifdef _STONDEBUG_ + +/* + ???Web??????????? + + do_http_request_forever() + + static ??????????????u???????? + + char *ip : IP????(??????????q?w????????) + unsigned short port : ???k??????80? + char *obj : ?????????????? + int sec : ??????? + + ???? 0?????????????? + */ +static int http_sock; +static int http_call_counter = 0; +static time_t http_call_last_time; +static int http_connecting = 0; +static int http_sent_request = 0; + +int +do_http_request_forever( char *ip, unsigned short port, + char *obj, int sec ) +{ + fd_set rfds,wfds; + int r; + struct timeval tm; + + /* ?????????????????? + 1?1?????????? */ + if( http_call_last_time != time(NULL )){ + http_call_last_time = time(NULL); + } else { + return 0; + } + + //fprintf(stderr,"."); + + if( http_call_counter == 0 ){ + struct sockaddr_in sin; + + /* sec?1?connect?? */ + if( time(NULL) % sec != 0 )return 0; + + http_sock = socket( AF_INET, SOCK_STREAM, 0 ); + if( http_sock < 0 )return -1; + + unsigned long flg = 1; + ioctlsocket( http_sock, FIONBIO, &flg ); +#if 0 + fprintf(stderr,"socket()\n" ); + flags = fcntl( http_sock, F_GETFL,0); + if( fcntl( http_sock, F_SETFL, flags|O_NONBLOCK )< 0){ + close( http_sock ); + return -2; + } +#endif + memset( &sin, 0 , sizeof( sin )); + sin.sin_addr.s_addr = inet_addr( ip ); + sin.sin_port = htons( port ); + sin.sin_family = AF_INET; + + if( connect( http_sock, (struct sockaddr*)&sin, + sizeof(sin))== SOCKET_ERROR ){ + + if( WSAGetLastError() == WSAEWOULDBLOCK ) + { + // o????????????????? + } + else + { + closesocket( http_sock ); + return -5; + } + } + + http_call_counter ++; + http_sent_request = 0; + //fprintf(stderr,"connected\n" ); + return 0; + } + + FD_ZERO( &rfds ); + FD_SET( http_sock, &rfds ); + FD_ZERO( &wfds ); + FD_SET( http_sock, &wfds ); + + tm.tv_usec = tm.tv_sec = 0; + r = select( http_sock+1, &rfds, &wfds,(fd_set*)NULL,&tm); + + if( r > 0 && FD_ISSET( http_sock, &rfds ) ){ + char buf[1000]; + r = recv( http_sock, buf,sizeof(buf), 0); + if( r <= 0 ){ + closesocket( http_sock ); + /* ????????? */ + http_call_counter = 0; + } + //fprintf(stderr,"read %d\n",r ); + } + + if( r > 0 && FD_ISSET( http_sock, &wfds ) && http_sent_request == 0 ){ + /* HTTP????MSS????????? + 1??write????????e????? + ???????????????u???????????? + ????? */ + int r; + char fuck[1000]; + sprintf_s( fuck, "GET %s HTTP/1.0\r\n\r\n" , obj ); + + r = send( http_sock, fuck, strlen( fuck ), 0 ); + + if( r <= 0 ){ + closesocket(r ); + http_call_counter = 0; + return -10; + } + //fprintf(stderr,"wrote %d\n",r ); + http_sent_request = 1; + } + return 0; +} +#endif + +void networkLoop(void) +{ + if( init_net == FALSE ) + return; + + if( disconnectServerFlag && !oldDisconnectServerFlag){ + // ???????e??? + ChangeProc( PROC_DISCONNECT_SERVER ); + } + oldDisconnectServerFlag = disconnectServerFlag; + if( disconnectServerFlag) + return; + + if( server_choosed == 0)return; + fd_set rfds , wfds, efds; + + struct timeval tm; + tm.tv_sec = 0; + tm.tv_usec = 0; + + FD_ZERO( &rfds ); + FD_ZERO( &wfds ); + FD_ZERO( &efds ); + + FD_SET( sockfd , &rfds ); + FD_SET( sockfd , &wfds ); + FD_SET( sockfd , &efds ); + + int a = select( 2 , &rfds , &wfds , (fd_set*)NULL, &tm ); +#if 0 + if( FD_ISSET( sockfd , &efds )){ + char buf[256]; + memset( buf , 0 , sizeof(buf)); + int len = recv( sockfd , buf , sizeof( buf ) -1 , 0 ); + if( len == SOCKET_ERROR ){ +#ifdef _STONDEBUG_ + CheckNetErrror(); +#endif + closesocket( sockfd ); + dwServer = NULL; + // ??????Q?N??????? + disconnectServerFlag = TRUE; + } + } +#endif + + // ??? + int len = SOCKET_ERROR; +#ifdef __NEW_CLIENT_MEM + BOOL ret; + DWORD oldprotect; +#ifndef __NEW_CLIENT_ONLY_WRITE + ret = VirtualProtect( net_readbuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); +#endif +#endif + if( FD_ISSET( sockfd , &rfds) ){ + len = recv( sockfd , rpc_linebuffer , (NETBUFSIZ >> 1) - 1, 0 ); + if (isWGS7) { + if ((len>1400)&&(len<=1460)) { + Sleep(500); + len += recv( sockfd , rpc_linebuffer+len , (NETBUFSIZ >> 1) - 1, 0 ); + } + isWGS7=0; + } + if( len == SOCKET_ERROR ){ + if( WSAGetLastError() != WSAEWOULDBLOCK ){ +#ifdef _STONDEBUG_ + CheckNetErrror(); +#endif + closesocket(sockfd); + dwServer = NULL; + // ??????Q?N??????? + disconnectServerFlag = TRUE; + } + } else appendReadBuf( rpc_linebuffer , len ); + } + int aaaaaaaa=0; + while( len!=SOCKET_ERROR && net_readbuflen>0){ + // get line from read buffer + if(GS==dwServer){ + if(!getLineFromReadBuf( rpc_linebuffer ,sizeof(rpc_linebuffer) )){ + + if( bNewServer) + SaDispatchMessage( sockfd , rpc_linebuffer ); + else + lssproto_ClientDispatchMessage( sockfd , rpc_linebuffer ); + }else break; + }else ReadWGSMessage(net_readbuf,net_readbuflen); + } +#ifdef __NEW_CLIENT_MEM +#ifndef __NEW_CLIENT_ONLY_WRITE + ret = VirtualProtect( net_readbuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); +#endif +#endif + + static unsigned int writetime = TimeGetTime(); + + // ???? + if( FD_ISSET( sockfd , &wfds)){ +#ifdef __NEW_CLIENT_MEM + ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); +#endif + len = 0; + if( net_writebuflen) len = send( sockfd, net_writebuf , net_writebuflen , 0 ); + /*???????*/ + if(len > 0) writetime = TimeGetTime(); + + if( len == SOCKET_ERROR ){ + if( WSAGetLastError() != WSAEWOULDBLOCK ){ +#ifdef _STONDEBUG_ + CheckNetErrror(); +#endif + closesocket(sockfd); + dwServer = NULL; + // ??????Q?N??????? + disconnectServerFlag = TRUE; + } + } else { + if( len) shiftWriteBuf( len ); + } +#ifdef __NEW_CLIENT_MEM + ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); +#endif + } + if((GS==dwServer) && (writetime + 30*1000 NETBUFSIZ ) + return -1; + + memcpy( net_readbuf + net_readbuflen, buf, size ); + net_readbuflen += size; + return 0; +} + + +// ????????????D? +// +// ??k 0 ... ? +// -1 ... ?????K??? +// -100 ... ????k????? +int appendWriteBuf( int index, char *buf, int size ) +{ + if( server_choosed == 0 ) + return -100; +#ifndef __NEW_CLIENT_MEM + if( (net_writebuflen + size) > NETBUFSIZ ) + return -1; + memcpy( net_writebuf + net_writebuflen, buf, size ); + net_writebuflen += size; +#else + DWORD oldprotect; + BOOL ret; + ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect); + + if( (net_writebuflen + size) > NETBUFSIZ ) + return -1; + memcpy( net_writebuf + net_writebuflen, buf, size ); + net_writebuflen += size; + + ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect); +#endif + return 0; +} + + +// ????????????size???ơq???? +// ?????size???????????? +// +// ??k 0 ... ? +// -1 ... ????????? +// -100 ... ???k????? +int shiftReadBuf( int size ) +{ + int i; + if( server_choosed == 0 ) + return -100; + + if( size > net_readbuflen ) + return -1; + for( i = size; i < net_readbuflen; i++ ) + { + net_readbuf[i-size] = net_readbuf[i]; + } + net_readbuflen -= size; + return 0; +} + + +// ????????????size???ơq???? +// ?????size???????????? +// +// ??k 0 ... ? +// -1 ... ????????? +// -100 ... ???k????? +int shiftWriteBuf( int size ) +{ + int i; + + if( server_choosed == 0 ) + return -100; + if( size > net_writebuflen ) + return -1; + for( i = size; i < net_writebuflen; i++ ) + { + net_writebuf[i-size] = net_writebuf[i]; + } + net_writebuflen -= size; + return 0; +} + + +// ???????????????????????? +// +// ??k 0 ... ? +// -1 ... ??????? +// -100 ... ????k????? +int getLineFromReadBuf( char *output, int maxlen ) +{ + int i; + + if( server_choosed == 0 ) + return -100; + int j; + for( i = 0; i < net_readbuflen && i < (maxlen-1); i++ ) + { + if( net_readbuf[i] == '\n' ) + { + memcpy( output, net_readbuf, i ); + output[i] = '\0'; + // ?????????????? 0x0d?????? + for( j = i+1; j >= 0; j-- ) + { + if( output[j] == 0x0d ) + { + output[j] = '\0'; + break; + } + } + + // ??????? + shiftReadBuf( i+1 ); + + // ??????D?????????????? + // ????????????????????????????????? + net_readbuf[net_readbuflen] = '\0'; + + return 0; + } + } + return -1; +} + + +// ???????len?????? +// +// ??k 0? ... ??????? +// -100 ... ????k?????? +int sendn( SOCKET s, char *buffer, int len ) +{ + int total = 0; + int r; + + if( server_choosed == 0 ) + return -100; + + while( 1 ) + { + r = send( s, buffer, len, 0 ); + if( r == SOCKET_ERROR ) + return SOCKET_ERROR; + total += r; + if( total == len ) + return total; + } +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/netproc.cpp b/石器时代8.5客户端最新源代码/石器源码/system/netproc.cpp new file mode 100644 index 0000000..e41e52d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/netproc.cpp @@ -0,0 +1,5122 @@ +#include +#include +#include +#include +#include "../systeminc/version.h" +#include"../systeminc/system.h" +#include "../systeminc/netmain.h" +#include "../systeminc/netproc.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/savedata.h" +#include "../systeminc/process.h" +#include "../systeminc/pc.h" +#include "../systeminc/tool.h" +#include "../systeminc/map.h" +#include "../systeminc/character.h" +#include "../systeminc/action.h" +#include "../systeminc/battlemenu.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/battleMap.h" +#include "../systeminc/menu.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/login.h" +#include "../systeminc/handletime.h" +#include "../systeminc/field.h" +#include "../systeminc/t_music.h" +#include "../systeminc/battleMenu.h" +#include "../wgs/message.h" +#include "../wgs/descrypt.h" +#include "./test.h" +#include "../NewProto/autil.h" +#ifdef _REMAKE_20 +#include "../MMOGprotect.h" +#endif +#ifdef _AIDENGLU_ +#include "../systeminc/pc.h" +extern Landed PcLanded; +#endif + +#ifdef _TALK_WINDOW +#include "../systeminc/TalkWindow.h" +#endif +#include "../openssl/md5.h" +#include "../systeminc/VMProtectSDK.h" +#pragma comment(lib, "libeay32.lib") +#pragma comment(lib, "ssleay32.lib") + + +#ifdef _STONDEBUG_ +extern int g_iMallocCount; +#endif +#define NETPROC_NOTSEND 0 // ?????????? +#define NETPROC_SENDING 1 // ?????N? +#define NETPROC_RECEIVED 2 // ??? +#define SET_SENDTIME(time) time = TimeGetTime() +#define CHECK_TIMEOUT(time, timeout) \ + if ((TimeGetTime() - (time)) > (timeout)) \ + return -1; +#define SETSENDING netproc_sending = NETPROC_SENDING; start_time = TimeGetTime(); +#define SETTIMEOUT(msg, state) \ + if ((TimeGetTime() - start_time) > TIMEOUT) \ + return; +#define SETTIMEOUT2(msg) \ + if ((TimeGetTime() - start_time) > TIMEOUT) \ +{ \ + sprintf_s( netprocErrmsg, msg ); \ + return -1; \ +} +#define SETNEEDCHOOSE(mode) \ + if (server_choosed == 0) \ + return; +#ifdef _STONDEBUG_ +void sendDataToServer(char* data); +#endif + +extern char szUser[], szPassword[]; + +short selectServerIndex = -1; +short clientLoginStatus = 0; +short charListStatus = 0; + +short charDelStatus = 0; +short newCharStatus = 0; +short charLoginStatus = 0; +short charLogoutStatus = 0; + +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ +extern struct gameserver gmsv[]; +#endif + +#ifdef _NEW_WGS_MSG // WON ADD WGSӴ +int ERROR_MESSAGE = 0; +#endif + +// GAMESTATE_CHOOSESERVER????@e?????????ѩ? +char gamestate_chooseserver_name[128]; +// GAMESTATE_LOGIN????@e?????????ѩ? +char gamestate_login_charname[128]; +// GAMESTATE_DELETECHAR????@e?????????ѩ? +char gamestate_deletechar_charname[128]; +char netprocErrmsg[1024]; +int netproc_sending = NETPROC_NOTSEND; +DWORD start_time = 0; +BOOL bNewServer; +char c_temp[1024]; +int connectServerCounter = 0; + +#ifdef _SKILLSORT +int AdvanceSkill[20] = {-1}; +int AssitSkill[20] = {-1}; +int BattleSkill[20] = {-1}; +void SortSkill() +{ + int count1 = 0, count2 = 0, count3 = 0; + + for (int i = 0; i < 20; i++) + { + AdvanceSkill[i] = -1; + AssitSkill[i] = -1; + BattleSkill[i] = -1; + } +#ifdef _PRO3_ADDSKILL + for (int i = 0; i < 30; i++) +#else + for (int i = 0; i < 26; i++) +#endif + { + switch (profession_skill[i].kind) + { + case 1: // ս + BattleSkill[count1] = i; + count1++; + break; + case 2: // + AssitSkill[count2] = i; + count2++; + break; + case 3: // + AdvanceSkill[count3] = i; + count3++; + break; + } + } +} +#endif + +#ifdef _CHANNEL_MODIFY +// Ի +void SaveChatData(char *msg,char KindOfChannel,bool bCloseFile); +#endif +void initConnectServer(void) +{ + connectServerCounter = 0; +} + +void LogToRecvdata2(char *data) +{ + char lssproto_readlogfilename[256] = "recvdata.txt"; + + if (lssproto_readlogfilename[0] != '\0') + { + FILE *rfp; + rfp = fopen(lssproto_readlogfilename, "a+"); + if (rfp) + { + fprintf(rfp, "յ\t%s\n", data); + fclose(rfp); + } + } +} + +extern int iEncrypt; +int ConnectWGS() +{ + if (connectServerCounter == 0) + { + HANDLE hFileMapping = NULL; + LPSTR lpstr = NULL; + + cleanupNetwork(); + if (initNet()) + { + unsigned long flg = 1; + struct sockaddr_in sin; + struct hostent *h; + + iWGS = 0; + iEncrypt = E_INIT; + start_time = TimeGetTime(); + if (INVALID_SOCKET == (sockfd = socket(AF_INET, SOCK_STREAM, 0))) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_SOCKETERROR); + return -3; + } + ioctlsocket(sockfd, FIONBIO, &flg); + sin.sin_family = AF_INET; + sin.sin_port = htons(wWGS); + sin.sin_addr.s_addr = inet_addr(szWGS); + if (sin.sin_addr.s_addr == -1) + { + if (!(h = gethostbyname(szWGS))) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTGETADDR); + closesocket(sockfd); + dwServer = NULL; + return -4; + } + memcpy((void*)&sin.sin_addr.s_addr, h->h_addr, sizeof(struct in_addr)); + } + int ret = connect(sockfd, (struct sockaddr*)&sin, sizeof(sin)); + if (ret == SOCKET_ERROR) + { + if (WSAGetLastError() != WSAEWOULDBLOCK) + { + closesocket(sockfd); + dwServer = NULL; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT_S); + return -5; + } + } + dwServer = WGS; + iWGS = 1; + connectServerCounter = 1; + } + else + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + strcpy(netprocErrmsg, NET_ERRMSG_SOCKLIBERROR); + return -1; + } + } + else if (connectServerCounter >= 1 && connectServerCounter <= 70) + { + fd_set rfds, wfds, efds; + struct timeval tm; + + if (++connectServerCounter == 70) + connectServerCounter = 69; + tm.tv_sec = 0; + tm.tv_usec = 0; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + FD_SET(sockfd, &rfds); + FD_SET(sockfd, &wfds); + FD_SET(sockfd, &efds); + int a = select(2, &rfds, &wfds, &efds, &tm); + if (FD_ISSET(sockfd, &wfds)) + { + connectServerCounter = 71; + server_choosed = 100; + } +#ifdef _OMIT_WGS + testtest(); + connectServerCounter = 143; // ݶ + iWGS = 7; +#endif + if (FD_ISSET(sockfd, &efds)) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + } + else if (connectServerCounter == 71) + { + if (iWGS == 2) + { + unsigned long flg = 1; + struct sockaddr_in sin; + struct hostent *h; + + closesocket(sockfd); + dwServer = NULL; + if (INVALID_SOCKET == (sockfd = socket(AF_INET, SOCK_STREAM, 0))) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_SOCKETERROR); + return -3; + } + ioctlsocket(sockfd, FIONBIO, &flg); + sin.sin_family = AF_INET; + sin.sin_port = htons(wCS); + sin.sin_addr.s_addr = inet_addr(szCSIP); + if (sin.sin_addr.s_addr == -1) + { + if (!(h = gethostbyname(szCSIP))) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTGETADDR); + closesocket(sockfd); + dwServer = NULL; + return -4; + } + memcpy((void*)&sin.sin_addr.s_addr, h->h_addr, sizeof(struct in_addr)); + } + int ret = connect(sockfd, (struct sockaddr*)&sin, sizeof(sin)); + if (ret == SOCKET_ERROR) + { + if (WSAGetLastError() != WSAEWOULDBLOCK) + { + closesocket(sockfd); + dwServer = NULL; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT_S); + return -5; + } + } + dwServer = CS; + iWGS = 3; + connectServerCounter = 72; + } + } + else if (connectServerCounter >= 72 && connectServerCounter <= 140) + { + fd_set rfds, wfds, efds; + struct timeval tm; + + if (++connectServerCounter == 140) + connectServerCounter = 139; + tm.tv_sec = 0; + tm.tv_usec = 0; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + FD_SET(sockfd, &rfds); + FD_SET(sockfd, &wfds); + FD_SET(sockfd, &efds); + int a = select(2, &rfds, &wfds, &efds, &tm); + if (FD_ISSET(sockfd, &wfds)) + { + connectServerCounter = 141; + server_choosed = 100; + } + if (FD_ISSET(sockfd, &efds)) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + } + else if (connectServerCounter == 141) + { + if (iWGS == 4) + { + DoSKey(); + connectServerCounter = 142; + iWGS = 5; + } + } + else if (connectServerCounter == 142) + { + if (iWGS == 6) + { + DoHellow(); + connectServerCounter = 143; + iWGS = 7; + } + } + else if (connectServerCounter == 143) + { + if (iWGS == 8) + { + cleanupNetwork(); + disconnectServerFlag = TRUE; + oldDisconnectServerFlag = TRUE; + closesocket(sockfd); + dwServer = GS; + return 1; + } + } + if (iWGS == 9) + return -7; + SETTIMEOUT2(NET_ERRMSG_CONNECTTIMEOUT); + return 0; +} + +struct sockaddr_in sin_server; +int connectServer(void) +{ + if (!init_net) + return 0; + static int count = 0; + if (connectServerCounter == 0) + { + char hostname[128]; + short pt; + unsigned long flg = 1; + struct hostent *h; +#ifdef _VMP_ + lstrcpy(PersonalKey, VMProtectDecryptStringA(_DEFAULT_PKEY)); +#else + lstrcpy(PersonalKey, _DEFAULT_PKEY); +#endif + // lstrcpy(PersonalKey, "forever"); + start_time = TimeGetTime(); + if (getServerInfo(selectServerIndex, hostname, &pt) < 0) + { + count = 0; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_BADNAME); + return -2; + } + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd == INVALID_SOCKET) + { + count = 0; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_SOCKETERROR); + return -3; + } + ioctlsocket(sockfd, FIONBIO, &flg); + + extern BOOL NoDelay; + if (NoDelay) + { + int flag = 1; + + if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int)) != 0) + { + count = 0; + return -100; + } + } + ZeroMemory(&sin_server, sizeof(sin_server)); + sin_server.sin_family = AF_INET; + sin_server.sin_port = htons(pt); + sin_server.sin_addr.s_addr = inet_addr(hostname); /* accept only dot notaion */ + if (sin_server.sin_addr.s_addr == -1) + { + h = gethostbyname(hostname); + if (h == NULL) + { + count = 0; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTGETADDR); + closesocket(sockfd); + dwServer = NULL; + return -4; + } + memcpy((void*)&sin_server.sin_addr.s_addr, h->h_addr, sizeof(struct in_addr)); + } + // Non blocking Connect + int ret = connect(sockfd, (struct sockaddr*)&sin_server, sizeof(sin_server)); + if (ret == SOCKET_ERROR) + { + if (WSAGetLastError() != WSAEWOULDBLOCK) + { + count = 0; + closesocket(sockfd); + dwServer = NULL; +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT_S); + return -5; + } + connectServerCounter = 1; + c_temp[0] = 0; + bNewServer = FALSE; + /*sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; */ + } + } + else if (connectServerCounter >= 1 && connectServerCounter <= 70) + { + fd_set rfds, wfds, efds; + struct timeval tm; + + connectServerCounter++; + if (connectServerCounter == 70) + connectServerCounter = 69; + // select?? + tm.tv_sec = 0; + tm.tv_usec = 0; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + FD_SET(sockfd, &rfds); + FD_SET(sockfd, &wfds); + FD_SET(sockfd, &efds); + int a = select(sockfd, &rfds, &wfds, &efds, &tm); + if (a > 0) + { + if (FD_ISSET(sockfd, &rfds)) + { + // Nuke start + int i_len = recv(sockfd, c_temp, sizeof(c_temp) - 1, 0); + + if (i_len > 0) + { + if (c_temp[0] == 'E') + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + sprintf_s(netprocErrmsg, c_temp + 1); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + else if (c_temp[0] == _SA_VERSION) + { + bNewServer = 0xf000000 | 1; + if (FD_ISSET(sockfd, &wfds)) + { + connectServerCounter = 71; + server_choosed = 1; + } + } + else + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + sprintf_s(netprocErrmsg, NET_ERRMSG_VERSIONERROR); + closesocket(sockfd); + dwServer = NULL; + return -8; + } + }else + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + } + //end cary + if (FD_ISSET(sockfd, &efds)) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + }else + { + count++; + + if(count >= 1500) + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + sprintf_s(netprocErrmsg, NET_ERRMSG_NOTCONNECT); + closesocket(sockfd); + dwServer = NULL; + return -6; + } + } + } + else if (connectServerCounter >= 71 && connectServerCounter <= 80) + { + count = 0; + if (connectServerCounter == 71) + { + char userId[32], userPassword[32]; + + clientLoginStatus = 0; + CopyMemory(userId, szUser, 32); + ecb_crypt("f;encor1c", userId, 32, DES_DECRYPT); + CopyMemory(userPassword, szPassword, 32); + ecb_crypt("f;encor1c", userPassword, 32, DES_DECRYPT); + + extern char []; + unsigned char tmp[256]; + CHAR mac[64]; + MD5( (const unsigned char*), strlen(), tmp ); + size_t leng = 0; + for (int i = 0; i < 16; i ++) + { + sprintf( &mac[ leng ], "%02x", tmp[ i ] ); + leng = strlen( mac ); + } +#ifdef _NEW_CLIENT_LOGIN +#ifdef _SA_MAC_VERSION_CONTROL + CHAR token[64]; + sprintf_s(token, "%s-%s",_SA_MAC_VERSION, mac); +#ifdef _LOGIP_ + extern char ҹIP[]; + lssproto_ClientLogin_send(sockfd, userId,userPassword, token, selectServerIndex,ҹIP); +#else + lssproto_ClientLogin_send(sockfd, userId,userPassword, token, selectServerIndex,"192.168.1.1"); +#endif +#else + lssproto_ClientLogin_send(sockfd, userId,userPassword, mac, selectServerIndex,"192.168.1.1"); +#endif +#endif + if ((bNewServer & 0xf000000) == 0xf000000) + { + lstrcpy(PersonalKey, userId); +#ifdef _VMP_ + lstrcat(PersonalKey, VMProtectDecryptStringA(_RUNNING_KEY)); +#else + lstrcat(PersonalKey, _RUNNING_KEY); +#endif + // lstrcat(PersonalKey, "520999"); + } + else + { + lstrcpy(PersonalKey, userId); + lstrcat(PersonalKey, "19761101"); + } + netproc_sending = NETPROC_SENDING; + } + if (netproc_sending == NETPROC_RECEIVED) + { + // recv ????? + if (clientLoginStatus) + connectServerCounter = 81; + else + { +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime() + 2000; +#endif + count = 0; + netproc_sending = NETPROC_NOTSEND; + sprintf_s(netprocErrmsg, NET_ERRMSG_LOGINFAIL); + closesocket(sockfd); + dwServer = NULL; + return -7; + } + } + connectServerCounter++; + if (connectServerCounter == 81) + connectServerCounter = 80; + } + else if (connectServerCounter >= 81 && connectServerCounter <= 98) + connectServerCounter ++; + else if (connectServerCounter == 99) + { + netproc_sending = NETPROC_NOTSEND; + return 1; + } + SETTIMEOUT2(NET_ERRMSG_CONNECTTIMEOUT); + return 0; +} +void lssproto_ClientLogin_recv(int fd, char *result) +{ + if (netproc_sending == NETPROC_SENDING) + { + netproc_sending = NETPROC_RECEIVED; + if (strcmp(result, OKSTR) == 0) + { + clientLoginStatus = 1; + time(&serverAliveLongTime); + localtime_s(&serverAliveTime,&serverAliveLongTime); + }else if(strcmp (result, CANCLE) == 0) + { + //ChangeProc(PROC_TITLE_MENU , 6 ); + + cleanupNetwork(); + // ???????????? + PaletteChange(DEF_PAL, 0); + // ?????? + //cary + ChangeProc( PROC_ID_PASSWORD ); + SubProcNo = 5; + // ?????? + DeathAllAction(); + + } + } +} + +void charListStart(void) +{ + int i; + + for (i = 0; i < MAXCHARACTER; i++) + resetCharacterList(i); +#ifdef _MORECHARACTERS_ + extern int ﵱǰҳ; + ﵱǰҳ=0; +#endif + charListStatus = 0; + if (bNewServer) + lssproto_CharList_send(sockfd); + else + old_lssproto_CharList_send(sockfd); + SETSENDING; +} + +int charListProc(void) +{ + if (netproc_sending == NETPROC_RECEIVED) + { + netproc_sending = NETPROC_NOTSEND; + if (charListStatus == 1) + return 1; + else if (charListStatus == 2) + return -3; +#ifdef _CHANGEGALAXY + else if (charListStatus == 3) + return -12; +#endif +#ifdef _ERROR301 + else if (charListStatus == 4) + return -13; +#endif + else + return -2; + } + SETTIMEOUT2(NET_ERRMSG_CHARLISTTIMEOUT); + return 0; +} + + +TCHAR ½[1024]; + +void lssproto_CharList_recv(int fd, char *result, char *data) +{ + memset(½,0,1024); + if(strcmp(result,_T("failed"))==0) { + strcpy(½,data); +#ifdef _AIDENGLU_ + PcLanded.½ʱʱ = TimeGetTime()+2000; +#endif + } + if (netproc_sending == NETPROC_SENDING) + { + char nm[1024], opt[1024]; + int i; + + netproc_sending = NETPROC_RECEIVED; + if (strcmp(result, SUCCESSFULSTR) != 0) + { + if (strcmp(data, "OUTOFSERVICE") == 0) + charListStatus = 2; +#ifdef _CHANGEGALAXY + if (strcmp(data, "CHANGE_GALAXY") == 0) + charListStatus = 3; +#endif +#ifdef _ERROR301 + if (strcmp(data, "301") == 0) + charListStatus = 4; +#endif + return; + } + charListStatus = 1; + for (i = 0; i < MAXCHARACTER; i++) + { + strcpy(nm, ""); + strcpy(opt, ""); + getStringToken(data, '|', i * 2 + 1, sizeof(nm) - 1 , nm); + getStringToken(data, '|', i * 2 + 2, sizeof(opt) - 1, opt); + setCharacterList(nm, opt); + } + } +} + +void charLoginStart(void) +{ + charLoginStatus = 0; +#ifdef _NEW_WGS_MSG // WON ADD WGSӴ + ERROR_MESSAGE = 0; +#endif + if (bNewServer){ +#ifdef _TRADITIONAL_LONG_ + CHAR szOutBuffer[128+1] = {0}; + WORD wLanguageID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + LCID Locale = MAKELCID(wLanguageID, SORT_CHINESE_PRCP); + int iRet = LCMapString(Locale, + LCMAP_SIMPLIFIED_CHINESE, + gamestate_login_charname, -1, + szOutBuffer, 128); + lssproto_CharLogin_send(sockfd, szOutBuffer); +#else + lssproto_CharLogin_send(sockfd, gamestate_login_charname); +#endif + } + else + old_lssproto_CharLogin_send(sockfd, gamestate_login_charname); + SETSENDING; +} + +int charLoginProc(void) +{ + tradeStatus = 0; + if (!server_choosed) + return 0; + if (netproc_sending == NETPROC_RECEIVED) + { + netproc_sending = NETPROC_NOTSEND; + if (charLoginStatus == 1) + return 1; + else + +#ifdef _NEW_WGS_MSG // WON ADD WGSӴ + if (ERROR_MESSAGE != 0) + return ERROR_MESSAGE; + else +#endif + return -2; + } + SETTIMEOUT2(NET_ERRMSG_LOGINTIMEOUT); + return 0; +} + +#ifdef __NEW_CLIENT +HANDLE hPing = NULL; +DWORD dwPingID; +DWORD WINAPI PingFunc(LPVOID param); +#endif + +void lssproto_CharLogin_recv(int fd, char* result, char* data) +{ + if (netproc_sending == NETPROC_SENDING) + { + netproc_sending = NETPROC_RECEIVED; +#ifdef __NEW_CLIENT + if (strcmp(result, SUCCESSFULSTR) == 0 && !hPing) +#else + if (strcmp(result, SUCCESSFULSTR) == 0) +#endif + { + charLoginStatus = 1; +#ifdef __NEW_CLIENT + hPing = CreateThread(NULL, 0, PingFunc, &sin_server.sin_addr, 0, &dwPingID); +#endif + } + +#ifdef __NEW_CLIENT +#ifdef _NEW_WGS_MSG // WON ADD WGSӴ + if (strcmp(result, "failed" ) == 0 && !hPing) + ERROR_MESSAGE = atoi(data); +#endif +#endif +#ifdef _ANGEL_SUMMON + angelFlag = FALSE; + angelMsg[0] = NULL; +#endif + } +} + +void charLogoutStart(void) +{ + charLogoutStatus = 0; + if (bNewServer) + lssproto_CharLogout_send(sockfd, 1); + else + old_lssproto_CharLogout_send(sockfd); + SETSENDING; +} + +int charLogoutProc(void) +{ + if (netproc_sending == NETPROC_RECEIVED) + { + netproc_sending = NETPROC_NOTSEND; + if (charLogoutStatus == 1) + return 1; + else + return -2; + } + SETTIMEOUT2(NET_ERRMSG_LOGOUTTIMEOUT); + return 0; +} + +void lssproto_CharLogout_recv(int fd, char *result, char *data) +{ + if (netproc_sending == NETPROC_SENDING) + { + netproc_sending = NETPROC_RECEIVED; + if (strcmp(result, SUCCESSFULSTR) == 0) + charLogoutStatus = 1; + } +} + +#define S_DELIM '|' + +/*================================ +C warp +D ʱ +X +P ״̬ +F ״̬ +M HP,MP,EXP +K ״̬ +E nowEncountPercentage +J ħ +N Ѷ +I +W \ +S ְҵ +G ְҵȴʱ +================================*/ +void lssproto_S_recv(int fd, char *data) +{ + if (logOutFlag) + return; + switch (data[0]) + { + case 'C': + { + int fl, maxx, maxy, gx, gy; + + floorChangeFlag = TRUE; + if (!loginFlag && ProcNo == PROC_GAME) + { + if (!warpEffectFlag) + { + SubProcNo = 200; + warpEffectProc(); + if (MenuToggleFlag & JOY_CTRL_M) + MapWmdFlagBak = TRUE; + } + resetPc(); + warpEffectFlag = FALSE; + warpEffectStart = TRUE; + } + data++; + fl = getIntegerToken(data, S_DELIM, 1); + maxx = getIntegerToken(data, S_DELIM, 2); + maxy = getIntegerToken(data, S_DELIM, 3); + gx = getIntegerToken(data, S_DELIM, 4); + gy = getIntegerToken(data, S_DELIM, 5); + setMap(fl, gx, gy); + createMap(fl, maxx, maxy); + nowFloorGxSize = maxx; + nowFloorGySize = maxy; + resetCharObj(); + mapEmptyFlag = FALSE; + nowEncountPercentage = minEncountPercentage; + nowEncountExtra = 0; + resetMap(); + transmigrationEffectFlag = 0; +#ifdef __SKYISLAND + extern void SkyIslandSetNo( int fl); + SkyIslandSetNo( fl); +#endif + break; + } + case 'D': + data++; + setPcId(getIntegerToken(data, S_DELIM, 1)); + serverTime = getIntegerToken(data, S_DELIM, 2); + FirstTime = TimeGetTime(); + RealTimeToSATime(&SaTime); + SaTimeZoneNo = getLSTime(&SaTime); + PaletteChange(SaTimeZoneNo, 0); + break; + //andy_add + case 'X': + pc.lowsride = getIntegerToken(data, S_DELIM, 2); + break; + case 'P': + { + char name[256], freeName[256]; + int i, kubun; + unsigned int mask; + + data++; + kubun = getInteger62Token(data, S_DELIM, 1); + if (!bNewServer) + pc.ridePetNo = -1; + if (kubun == 1) + { + pc.hp = getIntegerToken(data, S_DELIM, 2); // 0x00000002 + pc.maxHp = getIntegerToken(data, S_DELIM, 3); // 0x00000004 + pc.mp = getIntegerToken(data, S_DELIM, 4); // 0x00000008 + pc.maxMp = getIntegerToken(data, S_DELIM, 5); // 0x00000010 + pc.vital = getIntegerToken(data, S_DELIM, 6); // 0x00000020 + pc.str = getIntegerToken(data, S_DELIM, 7); // 0x00000040 + pc.tgh = getIntegerToken(data, S_DELIM, 8); // 0x00000080 + pc.dex = getIntegerToken(data, S_DELIM, 9); // 0x00000100 + pc.exp = getIntegerToken(data, S_DELIM, 10); // 0x00000200 + pc.maxExp = getIntegerToken(data, S_DELIM, 11); // 0x00000400 + pc.level = getIntegerToken(data, S_DELIM, 12); // 0x00000800 + pc.atk = getIntegerToken(data, S_DELIM, 13); // 0x00001000 + pc.def = getIntegerToken(data, S_DELIM, 14); // 0x00002000 + pc.quick = getIntegerToken(data, S_DELIM, 15); // 0x00004000 + pc.charm = getIntegerToken(data, S_DELIM, 16); // 0x00008000 + pc.luck = getIntegerToken(data, S_DELIM, 17); // 0x00010000 + pc.earth = getIntegerToken(data, S_DELIM, 18); // 0x00020000 + pc.water = getIntegerToken(data, S_DELIM, 19); // 0x00040000 + pc.fire = getIntegerToken(data, S_DELIM, 20); // 0x00080000 + pc.wind = getIntegerToken(data, S_DELIM, 21); // 0x00100000 + pc.gold = getIntegerToken(data, S_DELIM, 22); // 0x00200000 + pc.titleNo = getIntegerToken(data, S_DELIM, 23); // 0x00400000 + pc.dp = getIntegerToken(data, S_DELIM, 24); // 0x00800000 + pc.transmigration = getIntegerToken(data, S_DELIM, 25);// 0x01000000 + pc.ridePetNo = getIntegerToken(data, S_DELIM, 26); // 0x02000000 + pc.learnride = getIntegerToken(data, S_DELIM, 27); // 0x04000000 + pc.baseGraNo = getIntegerToken(data, S_DELIM, 28); // 0x08000000 +#ifdef _NEW_RIDEPETS + pc.lowsride = getIntegerToken(data, S_DELIM, 29); // 0x08000000 +#endif +#ifdef _SFUMATO + pc.sfumato = 0xff0000; +#endif + getStringToken(data, S_DELIM, 30, sizeof(name) - 1, name); + makeStringFromEscaped(name); + if (strlen(name) <= CHAR_NAME_LEN) + strcpy_s(pc.name, name); + getStringToken(data, S_DELIM, 31, sizeof(freeName) - 1, freeName); + makeStringFromEscaped(freeName); + if (strlen(freeName) <= CHAR_FREENAME_LEN) + strcpy_s(pc.freeName, freeName); +#ifdef _NEW_ITEM_ + pc.״̬ = getIntegerToken(data, S_DELIM, 32); +#endif +#ifdef _SA_VERSION_25 + int pointindex = getIntegerToken(data, S_DELIM, 33); + char pontname[][32]={ + "ķ", + "˿", + "ӼӴ", + "³Ǵ", + }; + sprintf(pc.chusheng,"%s",pontname[pointindex]); +#ifdef _MAGIC_ITEM_ + pc.״̬ = getIntegerToken(data, S_DELIM, 34); + pc.߹⻷Ч = getIntegerToken(data, S_DELIM, 35); +#endif +#endif + + } + else + { + mask = 2; + i = 2; + for (; mask > 0; mask <<= 1) + { + if (kubun & mask) + { + if (mask == 0x00000002) // ( 1 << 1 ) + { + pc.hp = getIntegerToken(data, S_DELIM, i);// 0x00000002 + i++; + } + else if (mask == 0x00000004) // ( 1 << 2 ) + { + pc.maxHp = getIntegerToken(data, S_DELIM, i);// 0x00000004 + i++; + } + else if (mask == 0x00000008) + { + pc.mp = getIntegerToken(data, S_DELIM, i);// 0x00000008 + i++; + } + else if (mask == 0x00000010) + { + pc.maxMp = getIntegerToken(data, S_DELIM, i);// 0x00000010 + i++; + } + else if (mask == 0x00000020) + { + pc.vital = getIntegerToken(data, S_DELIM, i);// 0x00000020 + i++; + } + else if (mask == 0x00000040) + { + pc.str = getIntegerToken(data, S_DELIM, i);// 0x00000040 + i++; + } + else if (mask == 0x00000080) + { + pc.tgh = getIntegerToken(data, S_DELIM, i);// 0x00000080 + i++; + } + else if (mask == 0x00000100) + { + pc.dex = getIntegerToken(data, S_DELIM, i);// 0x00000100 + i++; + } + else if (mask == 0x00000200) + { + pc.exp = getIntegerToken(data, S_DELIM, i);// 0x00000200 + i++; + } + else if (mask == 0x00000400) + { + pc.maxExp = getIntegerToken(data, S_DELIM, i);// 0x00000400 + i++; + } + else if (mask == 0x00000800) + { + pc.level = getIntegerToken(data, S_DELIM, i);// 0x00000800 + i++; + } + else if (mask == 0x00001000) + { + pc.atk = getIntegerToken(data, S_DELIM, i);// 0x00001000 + i++; + } + else if (mask == 0x00002000) + { + pc.def = getIntegerToken(data, S_DELIM, i);// 0x00002000 + i++; + } + else if (mask == 0x00004000) + { + pc.quick = getIntegerToken(data, S_DELIM, i);// 0x00004000 + i++; + } + else if (mask == 0x00008000) + { + pc.charm = getIntegerToken(data, S_DELIM, i);// 0x00008000 + i++; + } + else if (mask == 0x00010000) + { + pc.luck = getIntegerToken(data, S_DELIM, i);// 0x00010000 + i++; + } + else if (mask == 0x00020000) + { + pc.earth = getIntegerToken(data, S_DELIM, i);// 0x00020000 + i++; + } + else if (mask == 0x00040000) + { + pc.water = getIntegerToken(data, S_DELIM, i);// 0x00040000 + i++; + } + else if (mask == 0x00080000) + { + pc.fire = getIntegerToken(data, S_DELIM, i);// 0x00080000 + i++; + } + else if (mask == 0x00100000) + { + pc.wind = getIntegerToken(data, S_DELIM, i);// 0x00100000 + i++; + } + else if (mask == 0x00200000) + { + pc.gold = getIntegerToken(data, S_DELIM, i);// 0x00200000 + i++; + } + else if (mask == 0x00400000) + { + pc.titleNo = getIntegerToken(data, S_DELIM, i);// 0x00400000 + i++; + } + else if (mask == 0x00800000) + { + pc.dp = getIntegerToken(data, S_DELIM, i);// 0x00800000 + i++; + } + else if (mask == 0x01000000) + { + pc.transmigration = getIntegerToken(data, S_DELIM, i);// 0x01000000 + i++; + } + else if (mask == 0x02000000) + { + getStringToken(data, S_DELIM, i, sizeof(name) - 1, name);// 0x01000000 + makeStringFromEscaped(name); + if (strlen(name) <= CHAR_NAME_LEN) + strcpy_s(pc.name, name); + i++; + } + else if (mask == 0x04000000) + { + getStringToken(data, S_DELIM, i, sizeof(freeName) - 1, freeName);// 0x02000000 + makeStringFromEscaped(freeName); + if (strlen(freeName) <= CHAR_FREENAME_LEN) + strcpy_s(pc.freeName, freeName); + i++; + } + else if (mask == 0x08000000) // ( 1 << 27 ) + { + pc.ridePetNo = getIntegerToken(data, S_DELIM, i);// 0x08000000 + i++; + } + else if (mask == 0x10000000) // ( 1 << 28 ) + { + pc.learnride = getIntegerToken(data, S_DELIM, i);// 0x10000000 + i++; + } + else if (mask == 0x20000000) // ( 1 << 29 ) + { + pc.baseGraNo = getIntegerToken(data, S_DELIM, i);// 0x20000000 + i++; + } + else if (mask == 0x40000000) // ( 1 << 30 ) + { + pc.skywalker = getIntegerToken(data, S_DELIM, i);// 0x40000000 + i++; + } +#ifdef _CHARSIGNADY_NO_ + else if (mask == 0x80000000) // ( 1 << 31 ) + { + pc.ǩ = getIntegerToken(data, S_DELIM, i);// 0x80000000 + i++; + } +#endif + } + } + } + updataPcAct(); + if ((pc.status & CHR_STATUS_LEADER) != 0 && party[0].useFlag != 0) + { + party[0].level = pc.level; + party[0].maxHp = pc.maxHp; + party[0].hp = pc.hp; + strcpy_s(party[0].name, pc.name); + } + +#ifdef _STONDEBUG_ + char title[128]; + sprintf_s( title, "%s %s [%s %s:%s]", DEF_APPNAME, "԰汾", + gmsv[selectServerIndex].name, + gmsv[selectServerIndex].ipaddr, gmsv[selectServerIndex].port ); +#else + char title[128]; + extern int nServerGroup; + sprintf_s( title, "%s %s [%s] %s", DEF_APPNAME, gmgroup[nServerGroup].name, gmsv[selectServerIndex].name,pc.name ); + + extern int 忪; + if(忪){ + char [1024]={0}; + LCMapString (0x804,0x4000000,title, strlen(title),,1024); + sprintf(title,"%s",); + } + +#endif + extern int ; + extern char* GB2312ToBIG5(const char* szGBString); + if(==950){ + SetWindowText( hWnd, GB2312ToBIG5((const char *)title)); + }else{ + + SetWindowText(hWnd,title); + } + } + if (!bNewServer) + pc.ridePetNo = -1; + if ((bNewServer & 0xf000000) == 0xf000000 && sPetStatFlag == 1) + saveUserSetting(); + break; + case 'F': + char familyName[256]; + + data++; + getStringToken(data, S_DELIM, 1, sizeof(familyName) - 1, familyName); + makeStringFromEscaped(familyName); + if (strlen(familyName) <= CHAR_NAME_LEN) + strcpy_s(pc.familyName, familyName); + pc.familyleader = getIntegerToken(data, S_DELIM, 2); + pc.channel = getIntegerToken(data, S_DELIM, 3); + pc.familySprite = getIntegerToken(data, S_DELIM, 4); + pc.big4fm = getIntegerToken(data, S_DELIM, 5); +#ifdef _CHANNEL_MODIFY + if (pc.familyleader == FMMEMBER_NONE){ + pc.etcFlag &= ~PC_ETCFLAG_CHAT_FM; + TalkMode = 0; + } +#endif + break; + // HP,MP,EXP + case 'M': + data++; + pc.hp = getIntegerToken(data, '|', 1); + pc.mp = getIntegerToken(data, '|', 2); + pc.exp = getIntegerToken(data, '|', 3); + updataPcAct(); + if ((pc.status & CHR_STATUS_LEADER) != 0 && party[0].useFlag != 0) + party[0].hp = pc.hp; + break; + case 'K': + { + char name[256], freeName[256]; + int no, kubun, i; + unsigned int mask; + + no = data[1] - '0'; + data += 3; + kubun = getInteger62Token(data, S_DELIM, 1); + if (kubun == 0) + { + if (pet[no].useFlag) + { + if (no == pc.battlePetNo) + pc.battlePetNo = -1; + if (no == pc.mailPetNo) + pc.mailPetNo = -1; + pc.selectPetNo[no] = FALSE; + } + pet[no].useFlag = 0; + break; + }else{ + pet[no].useFlag = 1; + if (kubun == 1){ + pet[no].graNo = getIntegerToken(data, S_DELIM, 2); // 0x00000002 + pet[no].hp = getIntegerToken(data, S_DELIM, 3); // 0x00000004 + pet[no].maxHp = getIntegerToken(data, S_DELIM, 4); // 0x00000008 + pet[no].mp = getIntegerToken(data, S_DELIM, 5); // 0x00000010 + pet[no].maxMp = getIntegerToken(data, S_DELIM, 6); // 0x00000020 + pet[no].exp = getIntegerToken(data, S_DELIM, 7); // 0x00000040 + pet[no].maxExp = getIntegerToken(data, S_DELIM, 8); // 0x00000080 + pet[no].level = getIntegerToken(data, S_DELIM, 9); // 0x00000100 + pet[no].atk = getIntegerToken(data, S_DELIM, 10); // 0x00000200 + pet[no].def = getIntegerToken(data, S_DELIM, 11); // 0x00000400 + pet[no].quick = getIntegerToken(data, S_DELIM, 12); // 0x00000800 + pet[no].ai = getIntegerToken(data, S_DELIM, 13); // 0x00001000 + pet[no].earth = getIntegerToken(data, S_DELIM, 14); // 0x00002000 + pet[no].water = getIntegerToken(data, S_DELIM, 15); // 0x00004000 + pet[no].fire = getIntegerToken(data, S_DELIM, 16); // 0x00008000 + pet[no].wind = getIntegerToken(data, S_DELIM, 17); // 0x00010000 + pet[no].maxSkill= getIntegerToken(data, S_DELIM, 18); // 0x00020000 + pet[no].changeNameFlag = getIntegerToken(data, S_DELIM, 19);// 0x00040000 + pet[no].trn = getIntegerToken(data , S_DELIM, 20); +#ifdef _SHOW_FUSION + pet[no].fusion = getIntegerToken(data , S_DELIM, 21); + getStringToken(data, S_DELIM, 22, sizeof(name) - 1, name);// 0x00080000 + makeStringFromEscaped(name); + if (strlen(name) <= PET_NAME_LEN) + strcpy(pet[no].name, name); + getStringToken(data, S_DELIM, 23, sizeof(freeName) - 1, freeName);// 0x00100000 + makeStringFromEscaped(freeName); + if (strlen(freeName) <= PET_NAME_LEN) + strcpy(pet[no].freeName, freeName); +#else + getStringToken(data, S_DELIM, 21, sizeof(name) - 1, name);// 0x00080000 + makeStringFromEscaped(name); + if (strlen(name) <= PET_NAME_LEN) + strcpy(pet[no].name, name); + getStringToken(data, S_DELIM, 22, sizeof(freeName) - 1, freeName);// 0x00100000 + makeStringFromEscaped(freeName); + if (strlen(freeName) <= PET_NAME_LEN) + strcpy(pet[no].freeName, freeName); +#endif +#ifdef _PETCOM_ + pet[no].oldhp = getIntegerToken(data, S_DELIM, 24); + pet[no].oldatk = getIntegerToken(data, S_DELIM, 25); + pet[no].olddef = getIntegerToken(data, S_DELIM, 26); + pet[no].oldquick = getIntegerToken(data, S_DELIM, 27); + pet[no].oldlevel = getIntegerToken(data, S_DELIM, 28); +#endif +#ifdef _RIDEPET_ + pet[no].rideflg = getIntegerToken(data, S_DELIM, 29); +#endif +#ifdef _PETBLESS_ + pet[no].blessflg = getIntegerToken(data, S_DELIM, 30); + pet[no].blesshp = getIntegerToken(data, S_DELIM, 31); + pet[no].blessatk = getIntegerToken(data, S_DELIM, 32); + pet[no].blessdef = getIntegerToken(data, S_DELIM, 33); + pet[no].blessquick = getIntegerToken(data, S_DELIM, 34); +#endif + } + else + { + mask = 2; + i = 2; + for (; mask > 0; mask <<= 1) + { + if (kubun & mask) + { + if (mask == 0x00000002) + { + pet[no].graNo = getIntegerToken(data, S_DELIM, i);// 0x00000002 + i++; + } + else if (mask == 0x00000004) + { + pet[no].hp = getIntegerToken(data, S_DELIM, i);// 0x00000004 + i++; + } + else if (mask == 0x00000008) + { + pet[no].maxHp = getIntegerToken(data, S_DELIM, i);// 0x00000008 + i++; + } + else if (mask == 0x00000010) + { + pet[no].mp = getIntegerToken(data, S_DELIM, i);// 0x00000010 + i++; + } + else if (mask == 0x00000020) + { + pet[no].maxMp = getIntegerToken(data, S_DELIM, i);// 0x00000020 + i++; + } + else if (mask == 0x00000040) + { + pet[no].exp = getIntegerToken(data, S_DELIM, i);// 0x00000040 + i++; + } + else if (mask == 0x00000080) + { + pet[no].maxExp = getIntegerToken(data, S_DELIM, i);// 0x00000080 + i++; + } + else if (mask == 0x00000100) + { + pet[no].level = getIntegerToken(data, S_DELIM, i);// 0x00000100 + i++; + } + else if (mask == 0x00000200) + { + pet[no].atk = getIntegerToken(data, S_DELIM, i);// 0x00000200 + i++; + } + else if (mask == 0x00000400) + { + pet[no].def = getIntegerToken(data, S_DELIM, i);// 0x00000400 + i++; + } + else if (mask == 0x00000800) + { + pet[no].quick = getIntegerToken(data, S_DELIM, i);// 0x00000800 + i++; + } + else if (mask == 0x00001000 ) + { + pet[no].ai = getIntegerToken(data, S_DELIM, i);// 0x00001000 + i++; + } + else if (mask == 0x00002000) + { + pet[no].earth = getIntegerToken(data, S_DELIM, i);// 0x00002000 + i++; + } + else if (mask == 0x00004000 ) + { + pet[no].water = getIntegerToken(data, S_DELIM, i);// 0x00004000 + i++; + } + else if (mask == 0x00008000) + { + pet[no].fire = getIntegerToken(data, S_DELIM, i);// 0x00008000 + i++; + } + else if (mask == 0x00010000) + { + pet[no].wind = getIntegerToken(data, S_DELIM, i);// 0x00010000 + i++; + } + else if (mask == 0x00020000) + { + pet[no].maxSkill = getIntegerToken(data, S_DELIM, i);// 0x00020000 + i++; + } + else if (mask == 0x00040000) + { + pet[no].changeNameFlag = getIntegerToken(data, S_DELIM, i);// 0x00040000 + i++; + } + else if (mask == 0x00080000) + { + getStringToken(data, S_DELIM, i, sizeof(name) - 1, name);// 0x00080000 + makeStringFromEscaped(name); + if (strlen(name) <= PET_NAME_LEN) + strcpy(pet[no].name, name); + i++; + } + else if (mask == 0x00100000) + { + getStringToken(data, S_DELIM, i, sizeof(freeName) - 1, freeName);// 0x00100000 + makeStringFromEscaped(freeName); + if (strlen(freeName) <= PET_NAME_LEN) + strcpy(pet[no].freeName, freeName); + i++; + } +#ifdef _PETCOM_ + else if (mask == 0x200000) + { + pet[no].oldhp = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x400000) + { + pet[no].oldatk = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x800000) + { + pet[no].olddef = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x1000000) + { + pet[no].oldquick = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x2000000) + { + pet[no].oldlevel = getIntegerToken(data, S_DELIM, i); + i++; + } +#endif +#ifdef _PETBLESS_ + else if (mask == 0x4000000) + { + pet[no].blessflg = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x8000000) + { + pet[no].blesshp = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x10000000) + { + pet[no].blessatk = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x20000000) + { + pet[no].blessquick = getIntegerToken(data, S_DELIM, i); + i++; + } + else if (mask == 0x40000000) + { + pet[no].blessdef = getIntegerToken(data, S_DELIM, i); + i++; + } +#endif + } + } + } + } + } + break; + case 'E': + { + data++; + minEncountPercentage = getIntegerToken(data, S_DELIM, 1); + maxEncountPercentage = getIntegerToken(data, S_DELIM, 2); + nowEncountPercentage = minEncountPercentage; + } + break; + case 'J': + { + char name[256], memo[256]; + int no; + + no = data[1] - '0'; + data += 3; + magic[no].useFlag = getIntegerToken(data, S_DELIM, 1); + if (magic[no].useFlag != 0) + { + magic[no].mp = getIntegerToken(data, S_DELIM, 2); + magic[no].field = getIntegerToken(data, S_DELIM, 3); + magic[no].target = getIntegerToken(data, S_DELIM, 4); + if (magic[no].target >= 100) + { + magic[no].target %= 100; + magic[no].deadTargetFlag = 1; + } + else + magic[no].deadTargetFlag = 0; + getStringToken(data, S_DELIM, 5, sizeof(name) - 1, name); + makeStringFromEscaped(name); + if (strlen(name) <= sizeof(magic[no].name) - 1){ + strcpy_s(magic[no].name, name); + } + getStringToken(data, S_DELIM, 6, sizeof(memo) - 1, memo); + makeStringFromEscaped(memo); + if (strlen(memo) <= sizeof(magic[no].memo) - 1){ + strcpy_s(magic[no].memo, memo); + } + } + } + break; + case 'N': + { + ACTION *ptAct; + char name[256]; + int no, kubun, i, checkPartyCount, gx, gy, no2; + unsigned int mask; + + no = data[1] - 48; + data += 3; + kubun = getInteger62Token(data, S_DELIM, 1); + if (kubun == 0) + { + if (party[no].useFlag != 0 && party[no].id != pc.id) + { + ptAct = getCharObjAct(party[no].id); + if (ptAct != NULL) + delCharParty(ptAct); + } + gx = -1; + gy = -1; + if (party[no].ptAct != NULL) + { + gx = party[no].ptAct->nextGx; + gy = party[no].ptAct->nextGy; + } + party[no].useFlag = 0; + party[no].ptAct = NULL; + checkPartyCount = 0; + no2 = -1; +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + if (party[i].useFlag != 0) + { + checkPartyCount++; + if (no2 == -1 && i > no) + no2 = i; + } + } + if (checkPartyCount <= 1) + { + partyModeFlag = 0; + clearPartyParam(); +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_MODE; + if (TalkMode == 2) + TalkMode = 0; +#endif + } + else + { + if (no2 >= 0 || gx >= 0 || gy >= 0) + goFrontPartyCharacter(no2, gx, gy); + } + break; + } + partyModeFlag = 1; + prSendFlag = 0; + party[no].useFlag = 1; + + if (kubun == 1) + { + party[no].id = getIntegerToken(data, S_DELIM, 2); // 0x00000002 + party[no].level = getIntegerToken(data, S_DELIM, 3); // 0x00000004 + party[no].maxHp = getIntegerToken(data, S_DELIM, 4); // 0x00000008 + party[no].hp = getIntegerToken(data, S_DELIM, 5); // 0x00000010 + party[no].mp = getIntegerToken(data, S_DELIM, 6); // 0x00000020 + getStringToken(data, S_DELIM, 7, sizeof(name) - 1, name); // 0x00000040 + makeStringFromEscaped(name); + if (strlen(name) <= sizeof(party[no].name) - 1) + strcpy(party[no].name, name); + else + strcpy(party[no].name, "???"); + } + else + { + mask = 2; + i = 2; + for (; mask > 0; mask <<= 1) + { + if (kubun & mask) + { + if (mask == 0x00000002) + { + party[no].id = getIntegerToken(data, S_DELIM, i);// 0x00000002 + i++; + } + else if (mask == 0x00000004) + { + party[no].level = getIntegerToken(data, S_DELIM, i);// 0x00000004 + i++; + } + else if (mask == 0x00000008) + { + party[no].maxHp = getIntegerToken(data, S_DELIM, i);// 0x00000008 + i++; + } + else if (mask == 0x00000010) + { + party[no].hp = getIntegerToken(data, S_DELIM, i);// 0x00000010 + i++; + } + else if (mask == 0x00000020) + { + party[no].mp = getIntegerToken(data, S_DELIM, i);// 0x00000020 + i++; + } + else if (mask == 0x00000040) + { + getStringToken(data, S_DELIM, i, sizeof(name) - 1, name);// 0x00000040 + makeStringFromEscaped(name); + if (strlen(name) <= sizeof(party[no].name) - 1) + strcpy(party[no].name, name); + else + strcpy(party[no].name, "???"); + i++; + } + } + } + } + if (party[no].id != pc.id) + { + ptAct = getCharObjAct(party[no].id); + if (ptAct != NULL) + { + party[no].ptAct = ptAct; + setCharParty(ptAct); + // NPC??????? + if (no == 0) + setCharLeader(ptAct); + } + else + party[no].ptAct = NULL; + } + else + { + party[no].ptAct = pc.ptAct; + setPcParty(); + // PC??????? + if (no == 0) + setPcLeader(); + } + } + break; + case 'I': + { + int i, no; + char temp[256]; + + data++; + for (i = 0; i < MAX_ITEM; i++) + { +#ifdef _ITEM_JIGSAW +#ifdef _NPC_ITEMUP +#ifdef _ITEM_COUNTDOWN + no = i * 16; +#else + no = i * 15; +#endif +#else + no = i * 14; +#endif +#else +#ifdef _PET_ITEM + no = i * 13; +#else +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST //#ifdef _ITEMSET7_TXT + no = i * 14; +#else + + no = i * 11; + +#endif//_ALCHEMIST +#else + + no = i * 10; + + //end modified by lsh + +#endif//_ITEM_PILENUMS +#endif//_PET_ITEM +#endif//_ITEM_JIGSAW + getStringToken(data, '|', no + 1, sizeof(temp) - 1 , temp); + makeStringFromEscaped(temp); + if (strlen(temp) == 0 ) + { + pc.item[i].useFlag = 0; + continue; + } + pc.item[i].useFlag = 1; + if (strlen(temp) <= ITEM_NAME_LEN) + strcpy(pc.item[i].name, temp); + getStringToken(data, '|', no + 2, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + if (strlen(temp) <= ITEM_NAME2_LEN) + strcpy(pc.item[i].name2, temp); + pc.item[i].color = getIntegerToken(data, '|', no + 3); + if (pc.item[i].color < 0) + pc.item[i].color = 0; + getStringToken(data, '|', no + 4, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + if (strlen(temp) <= ITEM_MEMO_LEN) + strcpy(pc.item[i].memo, temp); + pc.item[i].graNo = getIntegerToken(data, '|', no + 5); + pc.item[i].field = getIntegerToken(data, '|', no + 6); + pc.item[i].target = getIntegerToken(data, '|', no + 7); + if (pc.item[i].target >= 100) + { + pc.item[i].target %= 100; + pc.item[i].deadTargetFlag = 1; + } + else + pc.item[i].deadTargetFlag = 0; + pc.item[i].level = getIntegerToken(data, '|', no + 8); + pc.item[i].sendFlag = getIntegerToken(data, '|', no + 9); + + // ʾƷ;ö + getStringToken(data, '|', no + 10, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + if (strlen(temp) <= 16) + strcpy(pc.item[i].damage, temp); +#ifdef _ITEM_PILENUMS + getStringToken(data, '|', no + 11, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + pc.item[i].pile = atoi(temp); +#endif +#ifdef _ALCHEMIST //_ITEMSET7_TXT + getStringToken(data, '|', no + 12, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + strcpy(pc.item[i].alch, temp); +#endif +#ifdef _PET_ITEM + pc.item[i].type = getIntegerToken(data, '|', no + 13); +#else +#ifdef _MAGIC_ITEM_ + pc.item[i]. = getIntegerToken(data, '|', no + 13); +#endif +#endif +#ifdef _ITEM_JIGSAW + getStringToken(data, '|', no + 14, sizeof(temp) - 1 , temp); + if (strlen(temp) <= 10) + strcpy(pc.item[i].jigsaw, temp); +#endif +#ifdef _NPC_ITEMUP + pc.item[i].itemup = getIntegerToken(data, '|', no + 15); +#endif +#ifdef _ITEM_COUNTDOWN + pc.item[i].counttime = getIntegerToken(data, '|', no + 16); +#endif + } + } + break; + //յij\ + case 'W': + { + int i, no, no2; + char temp[256]; + + no = data[1] - '0'; + data += 3; + for (i = 0; i < MAX_SKILL; i++) + petSkill[no][i].useFlag = 0; + for (i = 0; i < MAX_SKILL; i++) + { + no2 = i * 5; + getStringToken(data, '|', no2 + 4, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + if (strlen(temp) == 0) + continue; + petSkill[no][i].useFlag = 1; + if (strlen(temp) <= SKILL_NAME_LEN) + strcpy(petSkill[no][i].name, temp); + else + strcpy(petSkill[no][i].name, "??? name ???"); + petSkill[no][i].skillId = getIntegerToken(data, '|', no2 + 1); + petSkill[no][i].field = getIntegerToken(data, '|', no2 + 2); + petSkill[no][i].target = getIntegerToken(data, '|', no2 + 3); + getStringToken(data, '|', no2 + 5, sizeof(temp) - 1, temp); + makeStringFromEscaped(temp); + if (strlen(temp) <= SKILL_MEMO_LEN) + strcpy(petSkill[no][i].memo, temp); + else + strcpy(petSkill[no][i].memo, "??? memo ???"); + } + } + break; +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + case 'S': + { + char name[CHAR_NAME_LEN + 1]; + char memo[PROFESSION_MEMO_LEN + 1]; + int i, count = 0; + + data++; + for (i = 0; i < MAX_PROFESSION_SKILL; i++) + { + profession_skill[i].useFlag = 0; + profession_skill[i].kind = 0; + } + for (i = 0; i < MAX_PROFESSION_SKILL; i++) + { + count = i * 9; + profession_skill[i].useFlag = getIntegerToken(data, S_DELIM, 1 + count); + profession_skill[i].skillId = getIntegerToken(data, S_DELIM, 2 + count); + profession_skill[i].target = getIntegerToken(data, S_DELIM, 3 + count); + profession_skill[i].kind = getIntegerToken(data, S_DELIM, 4 + count); + profession_skill[i].icon = getIntegerToken(data, S_DELIM, 5 + count); + profession_skill[i].costmp = getIntegerToken(data, S_DELIM, 6 + count); + profession_skill[i].skill_level = getIntegerToken(data, S_DELIM, 7 + count); + memset(name, 0, sizeof(name)); + getStringToken(data, S_DELIM, 8 + count, sizeof(name) - 1, name); + makeStringFromEscaped(name); + if (strlen(name) <= CHAR_NAME_LEN) + strcpy(profession_skill[i].name, name); + memset(memo, 0, sizeof(memo)); + getStringToken(data, S_DELIM, 9 + count, sizeof(memo) - 1, memo); + makeStringFromEscaped(memo); + if (strlen(memo) <= PROFESSION_MEMO_LEN) + strcpy(profession_skill[i].memo, memo); + } +#ifdef _SKILLSORT + SortSkill(); +#endif + } + break; +#endif +#ifdef _PRO3_ADDSKILL + case 'G': + { + int i, count = 0; + data++; + for (i = 0; i < MAX_PROFESSION_SKILL; i++) + profession_skill[i].cooltime = 0; + for (i = 0; i < MAX_PROFESSION_SKILL; i++) + { + count = i * 1; + profession_skill[i].cooltime = getIntegerToken(data, S_DELIM, 1 + count); + } + } + break; +#endif +#ifdef _PET_ITEM + case 'B': + { + int i, no, nPetIndex; + char szData[256]; + + nPetIndex = data[1] - '0'; + data += 2; + for (i = 0; i < MAX_PET_ITEM; i++) + { +#ifdef _ITEM_JIGSAW + #ifdef _NPC_ITEMUP + #ifdef _ITEM_COUNTDOWN + no = i * 16; + #else + no = i * 15; + #endif + #else + no = i * 14; + #endif +#else + no = i * 13; +#endif + getStringToken(data, '|', no + 1, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + if (strlen(szData) == 0) // û + { + memset(&pet[nPetIndex].item[i], 0, sizeof(pet[nPetIndex].item[i])); + continue; + } + pet[nPetIndex].item[i].useFlag = 1; + if (strlen(szData) <= ITEM_NAME_LEN) + strcpy(pet[nPetIndex].item[i].name, szData); + getStringToken(data, '|', no + 2, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + if (strlen(szData) <= ITEM_NAME2_LEN) + strcpy(pet[nPetIndex].item[i].name2, szData); + pet[nPetIndex].item[i].color = getIntegerToken(data, '|', no + 3); + if (pet[nPetIndex].item[i].color < 0) + pet[nPetIndex].item[i].color = 0; + getStringToken(data, '|', no + 4, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + if (strlen(szData) <= ITEM_MEMO_LEN) + strcpy(pet[nPetIndex].item[i].memo, szData); + pet[nPetIndex].item[i].graNo = getIntegerToken(data, '|', no + 5); + pet[nPetIndex].item[i].field = getIntegerToken(data, '|', no + 6); + pet[nPetIndex].item[i].target = getIntegerToken(data, '|', no + 7); + if (pet[nPetIndex].item[i].target >= 100) + { + pet[nPetIndex].item[i].target %= 100; + pet[nPetIndex].item[i].deadTargetFlag = 1; + } + else + pet[nPetIndex].item[i].deadTargetFlag = 0; + pet[nPetIndex].item[i].level = getIntegerToken(data, '|', no + 8); + pet[nPetIndex].item[i].sendFlag = getIntegerToken(data, '|', no + 9); + + // ʾƷ;ö + getStringToken(data, '|', no + 10, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + if (strlen(szData) <= 16) + strcpy(pet[nPetIndex].item[i].damage, szData); + pet[nPetIndex].item[i].pile = getIntegerToken(data, '|', no + 11); + #ifdef _ALCHEMIST //_ITEMSET7_TXT + getStringToken(data, '|', no + 12, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + strcpy(pet[nPetIndex].item[i].alch, szData); + #endif + pet[nPetIndex].item[i].type = getIntegerToken(data, '|', no + 13); +#ifdef _ITEM_JIGSAW + getStringToken(data, '|', no + 14, sizeof(szData) - 1, szData); + makeStringFromEscaped(szData); + strcpy( pet[nPetIndex].item[i].jigsaw, szData ); + //øװĵ,Ͳƴͼ,¾ + //if( i == JigsawIdx ) + // SetJigsaw( pc.item[i].graNo, pc.item[i].jigsaw ); +#endif +#ifdef _NPC_ITEMUP + pet[nPetIndex].item[i].itemup = getIntegerToken(data, '|', no + 15); +#endif +#ifdef _ITEM_COUNTDOWN + pet[nPetIndex].item[i].counttime = getIntegerToken(data, '|', no + 16); +#endif + } + } + break; +#endif + } +} + +void lssproto_MC_recv( int fd, int fl, int x1, int y1, int x2, int y2, int tileSum, int partsSum, int eventSum, char *data) +{ + char showString[512], floorName[32]; + + if (logOutFlag) + return; + +#ifdef DEBUGPUSH + char msg[800]; + sprintf_s(msg, "???????????????FL%d %d,%d-%d,%d (%ud/%ud)", fl, x1, y1, x2, y2, tileSum, partsSum); + PUSH(msg); +#endif + getStringToken(data, '|', 1, sizeof(showString) - 1, showString); + makeStringFromEscaped(showString); + if (nowFloor == fl) + { + char strPal[32]; + + getStringToken(showString, '|', 1, sizeof(floorName) - 1, floorName); + if (strlen(floorName) <= FLOOR_NAME_LEN) + strcpy(nowFloorName, floorName); + else + strcpy(nowFloorName, "???"); + palNo = -2; + getStringToken(showString, '|', 2, sizeof(strPal) - 1, strPal); + if (strlen(strPal) == 0) + { + if (TimeZonePalChangeFlag == FALSE || loginFlag) + { + palNo = -1; + palTime = 0; + drawTimeAnimeFlag = 1; + } + } + else + { + int pal; + + pal = atoi(strPal); + if (pal >= 0) + { + if (TimeZonePalChangeFlag == TRUE || loginFlag) + { + palNo = pal; + palTime = 0; + drawTimeAnimeFlag = 0; + } + } + else + { + if (TimeZonePalChangeFlag == FALSE || loginFlag) + { + palNo = -1; + palTime = 0; + drawTimeAnimeFlag = 1; + } + } + } + } + + if (mapCheckSum(fl, x1, y1, x2, y2, tileSum, partsSum, eventSum)) + { + if (nowFloor == fl) + { + floorChangeFlag = FALSE; + if (warpEffectStart) + warpEffectOk = TRUE; + } + loginFlag = FALSE; + } +} + +void lssproto_M_recv(int fd, int fl, int x1, int y1, int x2, int y2, char* data) +{ + char showString[512], floorName[32], tilestring[18192], partsstring[18192], eventstring[18192], tmp[100]; + unsigned short tile[2048] , parts[2048], event[2048]; + int i, flag; + + if (logOutFlag) + return; + +#ifdef DEBUGPUSH + char msg[800]; + sprintf_s(msg , "??????????????FL%d %d,%d-%d,%d", fl, x1, y1, x2, y2); + PUSH(msg); +#endif + getStringToken(data, '|', 1, sizeof(showString) - 1, showString); + makeStringFromEscaped(showString); + if (nowFloor == fl) + { + char strPal[32]; + + getStringToken(showString, '|', 1, sizeof(floorName) - 1, floorName); + if (strlen(floorName) <= FLOOR_NAME_LEN) + strcpy(nowFloorName, floorName); + else + strcpy(nowFloorName, "???"); + palNo = -2; + getStringToken(showString, '|', 2, sizeof(strPal) - 1, strPal); + if (strlen(strPal) == 0) + { + if (TimeZonePalChangeFlag == FALSE || loginFlag) + { + palNo = -1; + palTime = 0; + drawTimeAnimeFlag = 1; + } + } + else + { + int pal; + + pal = atoi(strPal); + if (pal >= 0) + { + if (TimeZonePalChangeFlag == TRUE || loginFlag) + { + palNo = pal; + palTime = 0; + drawTimeAnimeFlag = 0; + } + } + else + { + if (TimeZonePalChangeFlag == FALSE || loginFlag) + { + palNo = -1; + palTime = 0; + drawTimeAnimeFlag = 1; + } + } + } + } + getStringToken(data, '|', 2, sizeof(tilestring) - 1, tilestring); + getStringToken(data, '|', 3, sizeof(partsstring) - 1, partsstring); + getStringToken(data, '|', 4, sizeof(eventstring) - 1, eventstring); + for (i = 0; ; i++) + { + flag = getStringToken(tilestring, ',', i + 1, sizeof(tmp) - 1, tmp); + tile[i] = a62toi(tmp); + getStringToken(partsstring, ',', i + 1, sizeof(tmp) - 1, tmp); + parts[i] = a62toi(tmp); + getStringToken(eventstring, ',', i + 1, sizeof(tmp) - 1, tmp); + event[i] = a62toi(tmp); + if (flag == 1) + break; + } + writeMap(fl, x1, y1, x2, y2, tile, parts, event); + if (mapEmptyFlag || floorChangeFlag) + { + if (nowFloor == fl) + { + redrawMap(); + floorChangeFlag = FALSE; + if (warpEffectStart) + warpEffectOk = TRUE; + } + } + loginFlag = FALSE; +} + +/*=========================== +1 OBJTYPE_CHARA +2 OBJTYPE_ITEM +3 OBJTYPE_GOLD +4 NPC&other player +===========================*/ +void lssproto_C_recv(int fd, char *data) +{ + int i, j, id, x, y, dir, graNo, level, nameColor, walkable, height, classNo, money, charType, charNameColor; + char bigtoken[2048], smalltoken[2048], name[2048], freeName[2048], info[1024], fmname[2048], petname[1024]; +#ifdef _CHARTITLE_STR_ + char titlestr[128]; + int titleindex=0; + *titlestr = 0; +#endif + int petlevel; +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + int profession_class, profession_level, profession_skill_point; +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + int herofloor; +#endif +#ifdef _NPC_PICTURE + int picture; +#endif +#ifdef _NPC_EVENT_NOTICE + int noticeNo; +#endif + ACTION *ptAct; + if (logOutFlag) + return; + if (encountNowFlag) + return; + for (i = 0; ; i++) + { + getStringToken(data, ',', i + 1, sizeof(bigtoken) - 1, bigtoken); + if (strlen(bigtoken) == 0) + break; +#ifdef _OBJSEND_C + getStringToken(bigtoken, '|', 1, sizeof(smalltoken) - 1, smalltoken); + if (strlen(smalltoken) == 0) + return; + switch (atoi(smalltoken)) + { + case 1://OBJTYPE_CHARA + charType = getIntegerToken(bigtoken, '|', 2); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + + extern BOOL ο; + if(ο){ + if(id != pc.id){ + if(charType <4 ) + continue; + } + } + + + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 6, sizeof(smalltoken) - 1, smalltoken); + dir = (atoi(smalltoken) + 3) % 8; + getStringToken(bigtoken, '|', 7, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + if(graNo==9999) continue; + getStringToken(bigtoken, '|', 8, sizeof(smalltoken) - 1,smalltoken); + level = atoi(smalltoken); + nameColor = getIntegerToken(bigtoken, '|', 9); + getStringToken(bigtoken, '|', 10, sizeof(name) - 1, name); + makeStringFromEscaped(name); + getStringToken(bigtoken, '|', 11, sizeof(freeName) - 1, freeName); + makeStringFromEscaped(freeName); + getStringToken(bigtoken, '|', 12, sizeof(smalltoken) - 1, smalltoken); + walkable = atoi(smalltoken); + getStringToken(bigtoken, '|', 13, sizeof(smalltoken) - 1, smalltoken); + height = atoi(smalltoken); + charNameColor = getIntegerToken(bigtoken, '|', 14); + getStringToken(bigtoken , '|', 15, sizeof(fmname) - 1, fmname); + makeStringFromEscaped(fmname); + getStringToken(bigtoken , '|', 16, sizeof(petname) - 1, petname); + makeStringFromEscaped(petname); + getStringToken(bigtoken, '|', 17, sizeof(smalltoken) - 1, smalltoken); + petlevel = atoi(smalltoken); +#ifdef _NPC_EVENT_NOTICE + getStringToken(bigtoken, '|', 18, sizeof(smalltoken) - 1, smalltoken); + noticeNo = atoi(smalltoken); +#endif +#ifdef _CHARTITLE_STR_ + getStringToken(bigtoken, '|', 23, sizeof(titlestr) - 1, titlestr); + titleindex = atoi(titlestr); + memset(titlestr,0,128); + if(titleindex > 0){ + extern char* FreeGetTitleStr(int id); + sprintf(titlestr,"%s",FreeGetTitleStr(titleindex)); + } +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + getStringToken(bigtoken, '|', 18, sizeof(smalltoken) - 1, smalltoken); + profession_class = atoi(smalltoken); + getStringToken(bigtoken, '|', 19, sizeof(smalltoken) - 1, smalltoken); + profession_level = atoi(smalltoken); +// getStringToken(bigtoken, '|', 20, sizeof(smalltoken) - 1, smalltoken); +// profession_exp = atoi(smalltoken); + getStringToken(bigtoken, '|', 20, sizeof(smalltoken) - 1, smalltoken); + profession_skill_point = atoi(smalltoken); +#ifdef _ALLDOMAN // Syu ADD аNPC + getStringToken(bigtoken, '|', 21, sizeof(smalltoken) - 1, smalltoken); + herofloor = atoi(smalltoken); +#endif +#ifdef _NPC_PICTURE + getStringToken(bigtoken, '|', 22, sizeof(smalltoken) - 1, smalltoken); + picture = atoi(smalltoken); +#endif +// #ifdef _GM_IDENTIFY // Rog ADD GMʶ +// getStringToken(bigtoken , '|', 23 , sizeof( gm_name ) - 1, gm_name ); +// makeStringFromEscaped( gm_name ); +// #endif +#endif + if (charNameColor < 0) + charNameColor = 0; + if (pc.id == id) + { + if (pc.ptAct == NULL) + { + createPc(graNo, x, y, dir); + updataPcAct(); + } + else + setPcGraNo(graNo, pc.dir); + +#ifdef _CHARTITLE_STR_ + getCharTitleSplit(titlestr,&pc.ptAct->TitleText); +#endif + updateMapArea(); +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +// #ifdef _GM_IDENTIFY // Rog ADD GMʶ +// setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height, profession_class, profession_level, profession_exp, profession_skill_point , gm_name); +// setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height, profession_class, profession_level, profession_skill_point , gm_name); +// #else +// setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height, profession_class, profession_level, profession_exp, profession_skill_point); +#ifdef _ALLDOMAN // Syu ADD аNPC + setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height, profession_class, profession_level, profession_skill_point , herofloor); +#else + setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height, profession_class, profession_level, profession_skill_point); +#endif +// #endif +#else + setPcParam(name, freeName, level, petname, petlevel, nameColor, walkable, height); +#endif + setPcNameColor(charNameColor); + if ((pc.status & CHR_STATUS_LEADER) != 0 && party[0].useFlag != 0) + { + party[0].level = pc.level; + strcpy(party[0].name, pc.name); + } +#ifdef MAX_AIRPLANENUM + for (j = 0; j < MAX_AIRPLANENUM; j++) +#else + for (j = 0; j < MAX_PARTY; j++) +#endif + { + if (party[j].useFlag != 0 && party[j].id == id) + { + party[j].ptAct = pc.ptAct; + setPcParty(); + if (j == 0) + setPcLeader(); + break; + } + } + } + else + { +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + setNpcCharObj(id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType, profession_class, gm_name); + #else + #ifdef _NPC_PICTURE + setNpcCharObj(id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType, profession_class, picture ); + #else + setNpcCharObj(id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType, profession_class ); + #endif + #endif +#else +#ifdef _NPC_EVENT_NOTICE + setNpcCharObj(id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType,noticeNo +#ifdef _CHARTITLE_STR_ + ,titlestr +#endif + + ); +#else + setNpcCharObj(id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType); +#endif +#endif + ptAct = getCharObjAct(id); +#ifdef _NPC_EVENT_NOTICE + // noticeNo=120137; + if(charType==13 && noticeNo>0){ + setNpcNotice( ptAct, noticeNo); + } +#endif + if (ptAct != NULL) + { +#ifdef MAX_AIRPLANENUM + for (j = 0; j < MAX_AIRPLANENUM; j++) +#else + for (j = 0; j < MAX_PARTY; j++) +#endif + { + if (party[j].useFlag != 0 && party[j].id == id) + { + party[j].ptAct = ptAct; + setCharParty(ptAct); + if (j == 0) + setCharLeader(ptAct); + break; + } + } + setCharNameColor(ptAct, charNameColor); + } + } + break; + case 2://OBJTYPE_ITEM + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + classNo = getIntegerToken(bigtoken, '|', 6); + getStringToken(bigtoken, '|', 7, sizeof(info) - 1, info); + makeStringFromEscaped(info); + setItemCharObj(id, graNo, x, y, 0, classNo, info); + break; + case 3://OBJTYPE_GOLD + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + money = atoi(smalltoken); + sprintf_s(info, "%d Stone", money); + if (money > 10000) + setMoneyCharObj(id, 24050, x, y, 0, money, info); + else if (money > 1000) + setMoneyCharObj(id, 24051, x, y, 0, money, info); + else + setMoneyCharObj(id, 24052, x, y, 0, money, info); + break; + case 4: + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(name) - 1, name); + makeStringFromEscaped(name); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + dir = (atoi(smalltoken) + 3) % 8; + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + getStringToken(bigtoken, '|', 6, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 7, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + setNpcCharObj( id, graNo, x, y, dir, "", name, "", + level, petname, petlevel, nameColor, 0, height, 2, 0, ""); + #else + #ifdef _NPC_PICTURE + setNpcCharObj( id, graNo, x, y, dir, "", name, "", + level, petname, petlevel, nameColor, 0, height, 2, 0, 0 ); + #else + setNpcCharObj( id, graNo, x, y, dir, "", name, "", + level, petname, petlevel, nameColor, 0, height, 2, 0 ); + #endif + #endif +#else +#ifdef _NPC_EVENT_NOTICE + setNpcCharObj( id, graNo, x, y, dir, "", name, "", + level, petname, petlevel, nameColor, 0, height, 2, 0 +#ifdef _CHARTITLE_STR_ + ,titlestr +#endif + ); +#else + setNpcCharObj( id, graNo, x, y, dir, "", name, "", + level, petname, petlevel, nameColor, 0, height, 2); +#endif +#endif + ptAct = getCharObjAct( id ); + break; + } +#else + getStringToken(bigtoken , '|' , 11 , sizeof(smalltoken) - 1, smalltoken); + if ( strlen(smalltoken) > 0 ){ + // NPC?ѩ + charType = getIntegerToken(bigtoken, '|', 1 ); + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + dir = (atoi(smalltoken) + 3) % 8; + getStringToken(bigtoken, '|', 6, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + getStringToken(bigtoken, '|', 7, sizeof(smalltoken) - 1,smalltoken); + level = atoi(smalltoken); + nameColor = getIntegerToken(bigtoken, '|', 8 ); + getStringToken(bigtoken , '|' , 9 , sizeof(name) - 1, name ); + makeStringFromEscaped(name); + getStringToken(bigtoken , '|' , 10 , sizeof( freeName ) - 1, freeName ); + makeStringFromEscaped( freeName ); + getStringToken(bigtoken, '|', 11, sizeof(smalltoken) - 1, smalltoken); + walkable = atoi(smalltoken); + getStringToken(bigtoken, '|', 12, sizeof(smalltoken) - 1, smalltoken); + height = atoi(smalltoken); + charNameColor = getIntegerToken(bigtoken, '|', 13 ); + getStringToken(bigtoken , '|' , 14, sizeof( fmname ) - 1, fmname ); + makeStringFromEscaped( fmname ); + getStringToken(bigtoken , '|' , 15 , sizeof( petname ) - 1, petname ); + makeStringFromEscaped( petname ); + getStringToken(bigtoken, '|', 16, sizeof(smalltoken) - 1, smalltoken); + petlevel = atoi(smalltoken); + if ( charNameColor < 0 ) + charNameColor = 0; + + if ( pc.id == id ){ + if ( pc.ptAct == NULL ){ + createPc( graNo, x, y, dir ); + updataPcAct(); + }else{ + setPcGraNo( graNo, pc.dir ); + } + updateMapArea(); + setPcParam( name, freeName, level, petname, petlevel, nameColor, walkable, height ); + setPcNameColor( charNameColor ); + if ( (pc.status & CHR_STATUS_LEADER) != 0 + && party[0].useFlag != 0 ){ + party[0].level = pc.level; + strcpy( party[0].name, pc.name ); + } + for ( j = 0; j < MAX_PARTY; j++ ){ + if ( party[j].useFlag != 0 && party[j].id == id ){ + party[j].ptAct = pc.ptAct; + setPcParty(); + if ( j == 0 ){ + setPcLeader(); + } + break; + } + } + }else{ +#ifdef _NPC_PICTURE + setNpcCharObj( id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType, 0 ); +#else + setNpcCharObj( id, graNo, x, y, dir, fmname, name, freeName, + level, petname, petlevel, nameColor, walkable, height, charType ); +#endif + ptAct = getCharObjAct( id ); + if ( ptAct != NULL ){ + for ( j = 0; j < MAX_PARTY; j++ ){ + if ( party[j].useFlag != 0 && party[j].id == id ){ + party[j].ptAct = ptAct; + setCharParty( ptAct ); + if ( j == 0 ){ + setCharLeader( ptAct ); + } + break; + } + } + setCharNameColor( ptAct, charNameColor ); + } + } + }else{ + getStringToken(bigtoken, '|', 6, sizeof(smalltoken) - 1, smalltoken); + if ( strlen(smalltoken) > 0 ){ + getStringToken(bigtoken, '|', 1, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + classNo = getIntegerToken(bigtoken, '|', 5 ); + getStringToken(bigtoken, '|', 6, sizeof( info ) - 1, info ); + makeStringFromEscaped( info ); + setItemCharObj( id, graNo, x, y, 0, classNo, info ); + }else{ + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + if ( strlen(smalltoken) > 0 ){ + getStringToken(bigtoken, '|', 1, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + money = atoi(smalltoken); + sprintf_s( info, "%d Stone", money ); + if ( money > 10000 ){ + setMoneyCharObj( id, 24050, x, y, 0, money, info ); + }else + if ( money > 1000 ){ + setMoneyCharObj( id, 24051, x, y, 0, money, info ); + }else{ + setMoneyCharObj( id, 24052, x, y, 0, money, info ); + } + } + } + } +#endif + } + +} + + +void lssproto_CA_recv( int fd, char *data ) +{ + char bigtoken[2048]; + char smalltoken[2048]; + int alreadytellC[1024]; + int tellCindex = 0; + int tellflag; + int i, j; + int charindex; + int x; + int y; + int act; + int dir; + int effectno = 0, effectparam1 = 0, effectparam2 = 0; +#ifdef _STREET_VENDOR + char szStreetVendorTitle[32]; +#endif + ACTION *ptAct; + + + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + // Pf????? + if ( encountNowFlag ) + { + return; + } + + for ( i = 0; ; i++ ) + { + getStringToken(data, ',', i+1, sizeof(bigtoken ) - 1, bigtoken ); + if ( strlen(bigtoken ) == 0 ) + break; + getStringToken(bigtoken, '|', 1, sizeof(smalltoken) - 1, smalltoken); + charindex = a62toi(smalltoken); + getStringToken(bigtoken, '|', 2, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken(bigtoken, '|', 3, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken(bigtoken, '|', 4, sizeof(smalltoken) - 1, smalltoken); + act = atoi(smalltoken); + getStringToken(bigtoken, '|', 5, sizeof(smalltoken) - 1, smalltoken); + dir = (atoi(smalltoken)+3)%8; + getStringToken(bigtoken, '|', 6, sizeof(smalltoken) - 1, smalltoken); +#ifdef _STREET_VENDOR + if (act == 41) strncpy_s(szStreetVendorTitle,sizeof(szStreetVendorTitle),smalltoken,sizeof(szStreetVendorTitle)); + else +#endif + { + effectno = atoi(smalltoken); + effectparam1 = getIntegerToken(bigtoken, '|', 7 ); + effectparam2 = getIntegerToken(bigtoken, '|', 8 ); + } + + + if ( pc.id == charindex ) + { + // PC????h?? + if ( pc.ptAct == NULL + || (pc.ptAct != NULL && pc.ptAct->anim_chr_no == 0) ) + { + // ???????????C???????????? + if (bNewServer) + lssproto_C_send(sockfd, charindex ); + else + old_lssproto_C_send(sockfd, charindex ); + } + else + { +#ifdef _STREET_VENDOR + if (act == 41){ + if (pc.iOnStreetVendor == 1){ + memset(pc.ptAct->szStreetVendorTitle,0,sizeof(pc.ptAct->szStreetVendorTitle)); + sprintf_s(pc.ptAct->szStreetVendorTitle,sizeof(pc.ptAct->szStreetVendorTitle),"%s",szStreetVendorTitle); + changePcAct( x, y, dir, act, effectno, effectparam1, effectparam2 ); +#ifdef _STREET_VENDOR_CHANGE_ICON + if (bNewServer) + lssproto_AC_send(sockfd,nowGx,nowGy,5); + else + old_lssproto_AC_send(sockfd,nowGx,nowGy,5); + setPcAction(5); +#endif + } + } + else +#endif + changePcAct( x, y, dir, act, effectno, effectparam1, effectparam2 ); + } + continue; + } + + ptAct = getCharObjAct( charindex ); + if ( ptAct == NULL ) + { + // i?ID???????????????????ID?????? + tellflag = 0; + for ( j = 0; j < tellCindex; j++ ) + { + if ( alreadytellC[j] == charindex ) + { + tellflag = 1; + break; + } + } + if ( tellflag == 0 && tellCindex < sizeof(alreadytellC) ) + { + alreadytellC[tellCindex] = charindex; + tellCindex++; + + if (bNewServer) + lssproto_C_send(sockfd, charindex ); + else + old_lssproto_C_send(sockfd, charindex ); + } + } + else + { +#ifdef _STREET_VENDOR + if (act == 41){ + memset(ptAct->szStreetVendorTitle,0,sizeof(ptAct->szStreetVendorTitle)); + strncpy_s(ptAct->szStreetVendorTitle,szStreetVendorTitle,sizeof(szStreetVendorTitle)); + } +#endif + changeCharAct( ptAct, x, y, dir, act, effectno, effectparam1, effectparam2 ); + } + } +} + + +// ????? +void lssproto_CD_recv( int fd, char *data ) +{ + int i, j; + int id; + + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + for ( i = 1; ; i++ ) + { +// id = getInteger62Token(data, '|', i ); + id = getInteger62Token(data, ',', i ); + if ( id == -1 ) + break; + + delCharObj( id ); + +#ifdef MAX_AIRPLANENUM + for (j = 0; j < MAX_AIRPLANENUM; j++) +#else + for ( j = 0; j < MAX_PARTY; j++ ) +#endif + { + if ( party[j].useFlag != 0 && party[j].id == id ) + { + party[j].ptAct = NULL; + break; + } + } + } +} + + + + +// ?h /////////////////////////////////////////////////////////////////// +// ?????h??????? +void walkSendForServer( int x, int y, char *direction ) +{ +#ifdef _REMAKE_20 + if (!ChangedLibrary()) + RestoreLibrary(); +#endif + if (bNewServer) + lssproto_W_send(sockfd , x, y, direction ); + else + old_lssproto_W_send(sockfd , x, y, direction ); +} + + +// ?????h??????? +// ????????????????????T?????????????? +void noChecksumWalkSendForServer( int x, int y, char *direction ) +{ + if (bNewServer) + lssproto_W2_send(sockfd , x, y, direction ); + else + old_lssproto_w_send(sockfd , x, y, direction ); +} + + +// ?h?????? +void lssproto_W_recv( int fd, int id, int x, int y ) +{ + // ??????Re??????????? + // ?????????????????????? +} + +#ifdef _SETTICK_COUNT +float *fTalkTick=NULL; +#endif +void chatStrSendForServer( char *str, int color ) +{ + char dest[1024], m[1024]; + int x, y; +#ifdef _FRIENDCHANNEL + char tmpMsg[128]; +#endif +#ifdef _TELLCHANNEL + char tmp1[128] ; +#endif + + +#ifdef _STONDEBUG_ // ֶͳ + { + if ( !strncmp( str, "send ", 5) ) { + sendDataToServer( str+5); + return; + } + } +#endif + + +#ifdef _SETTICK_COUNT + if ( fTalkTick == NULL || (GetTickCount() - *fTalkTick) > 60000 ){ + FREE( fTalkTick); +#ifdef _STONDEBUG_ + g_iMallocCount--; +#endif + fTalkTick = (float *)MALLOC( sizeof(float)); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + *fTalkTick = (float)0.00; + } + if ( (GetTickCount() - *fTalkTick) > 2500 ){ + *fTalkTick = (float)GetTickCount(); + }else{ + return; + } +#endif +#ifdef _CHAR_MANOR_DEBUG + if(strstr(str,".⻷")){ + int ⻷ID=0; + ⻷ID = getIntegerToken(str, ' ',2); + setCharmManor(pc.ptAct, ⻷ID); + return; + } +#endif + x = nowGx; + y = nowGy; + makeEscapeString( str, dest, sizeof(dest) ); + +#ifdef _TELLCHANNEL + getStringToken( str , ' ', 1, sizeof( tmp1 ) -1, tmp1 ); + char *found; + char tellName[32]={""}; + + switch (TalkMode){ + case 0: +#ifdef _THEATER + if (pc.iTheaterMode & 0x00000001) + { + StockChatBufferLine("", FONT_PAL_YELLOW); + return; + } +#endif +#ifdef _NPC_DANCE + if( pc.iDanceMode ) + { + StockChatBufferLine("ܻ꣡ᳳˡ", FONT_PAL_YELLOW); + return; + } +#endif +#ifdef _CHANNEL_MODIFY + case 2: +#endif + sprintf_s( m, "P|%s", dest ); + break; + case 1: + if ( strcmp ( tmp1 , str ) == 0 || strlen(tmp1) > 16) { + StockChatBufferLine( "ָʹøʽȷ" , FONT_PAL_RED); + strcpy(secretName,""); + return ; + } + if ( found = strstr( str, " " )){ + strncpy_s(tellName, str, strlen(str) - strlen(found)); + } + sprintf_s( secretName, "%s ",tellName); + sprintf_s( m, "P|/tell %s", dest ); + break; +#ifndef _CHANNEL_MODIFY + #ifdef _FRIENDCHANNEL + case 2: + sprintf_s(tmpMsg,"T|%s : %s",pc.name,dest); + lssproto_CHATROOM_send (sockfd ,tmpMsg); + return; + #endif +#else + case 3: + sprintf_s(m,"P|/FM%s",dest); + break; + /* + case 4: + sprintf_s(m,"P|/OCC%s%s",pc.name,dest); + break; +#ifdef _CHATROOMPROTOCOL + case 5: + sprintf_s(tmpMsg,"T|%s%s",pc.name,dest); + lssproto_CHATROOM_send (sockfd ,tmpMsg); + return; +#endif + */ +#ifdef _CHANNEL_WORLD ///Ƶ + case 4: + sprintf_s(m,"P|/WD %s",dest); + break; +#endif +#ifdef _CHANNEL_ALL_SERV + case 5: + sprintf_s(m,"P|/XQ %s",dest); + break; +#endif +#endif + + } +#else + sprintf_s( m, "P|%s", dest ); +#endif + if (bNewServer){ + CHAR szOutBuffer[1280+1] = {0}; + WORD wLanguageID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + LCID Locale = MAKELCID(wLanguageID, SORT_CHINESE_PRCP); + int iRet = LCMapString(Locale, + LCMAP_SIMPLIFIED_CHINESE, + m, -1, + szOutBuffer, 1280); + lssproto_TK_send(sockfd, x, y, szOutBuffer, color, NowMaxVoice ); + } + else + old_lssproto_TK_send(sockfd, x, y, m, color, NowMaxVoice ); +} + + + + +// ???? /////////////////////////////////////////////////////////// +void lssproto_TK_recv( int fd, int index, char *message, int color ) +{ + char id[2]; +#ifdef _MESSAGE_FRONT_ + char msg1[2024]; + char *msg; +#else + char msg[2024]; +#endif + ACTION *ptAct; + int fontsize =0; +#ifdef _MESSAGE_FRONT_ + msg1[0] = 0xA1; + msg1[1] = 0xF4; + msg1[2] = 0; + msg = msg1+2; +#endif + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + getStringToken( message, '|', 1, sizeof( id ) - 1, id ); + + if ( id[0] == 'P' ){ +#ifndef _CHANNEL_MODIFY + getStringToken( message, '|', 2, 2022 - 1, msg ); + makeStringFromEscaped( msg ); + #ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + TradeTalk( msg ) ; + #endif +#endif + +#ifdef _CHANNEL_MODIFY + char szToken[4]; + + if (getStringToken(message,'|',2,sizeof(szToken) - 1,szToken) == 0){ + getStringToken(message,'|',3,2022 - 1,msg); + makeStringFromEscaped(msg); +#ifdef _FONT_SIZE + char token[10]; + if ( getStringToken(message,'|',4,sizeof(token) - 1,token) == 1) { + fontsize = atoi( token); + if ( fontsize < 0 ) fontsize = 0; + }else { + fontsize = 0; + } +#endif + if (strlen(szToken) > 1){ + if (strcmp(szToken,"TK") == 0) InitSelectChar(message,0); + else if (strcmp(szToken,"TE") == 0) InitSelectChar(message,1); + return; + } + else{ + switch (szToken[0]){ + // Ƶ + case 'M': + { + char tellName[32] = { "" }; + char szMsgBuf[2024]; + char temp[] = "㣺"; + char *found; + + if (found = strstr(msg,temp)){ + strncpy_s(tellName,msg,strlen(msg) - strlen(found)); + color = 5; + strncpy_s(szMsgBuf,found,sizeof(szMsgBuf)); + memset(msg,0,2022); + sprintf(msg,"[%s]%s",tellName,szMsgBuf); + sprintf(secretName,"%s ",tellName); + } + } + break; + // Ƶ + case 'F': + // Ƶ + case 'T': + // ְҵƵ + case 'O': + break; + } + SaveChatData(msg,szToken[0],false); + } + } + else getStringToken(message,'|',2,2022 - 1,msg); +#ifdef _TALK_WINDOW + if (!g_bTalkWindow) +#endif + TradeTalk(msg); + if (strcmp(msg,"ҿ۳ʯ") == 0) pc.gold -= 200; +#ifdef _FONT_SIZE +#ifdef _MESSAGE_FRONT_ + StockChatBufferLineExt( msg-2, color, fontsize ); +#else + StockChatBufferLineExt( msg, color, fontsize ); +#endif +#else +#ifdef _MESSAGE_FRONT_ + StockChatBufferLine(msg-2,color); +#else + StockChatBufferLine(msg,color); +#endif +#endif +#else + #ifdef _TELLCHANNEL // (ɿ) ROG ADD Ƶ + char tellName[128] = { "" }; + char tmpMsg[STR_BUFFER_SIZE + 32]; + char TK[4]; + + if ( getStringToken( msg, '|', 1, sizeof( TK ) - 1, TK ) == 0){ + if (strcmp(TK,"TK") == 0) InitSelectChar( msg, 0); + else if (strcmp(TK,"TE") == 0) InitSelectChar( msg, 1); + } + else{ + char temp[] = "㣺"; + char *found; + + if (strcmp( msg, "ҿ۳ʯ") == 0) pc.gold -= 200; + + if ( found = strstr( msg, temp )){ + strncpy_s(tellName, msg, strlen(msg) - strlen(found)); + color = 5; + sprintf_s(tmpMsg,"[%s]%s",tellName, found); + StockChatBufferLine( tmpMsg, color ); + sprintf_s(msg,""); + sprintf_s(secretName,"%s ",tellName); + }else StockChatBufferLine( msg, color ); + } + #else +#ifdef _FONT_SIZE + StockChatBufferLineExt( msg, color, fontsize ); +#else + StockChatBufferLine( msg, color ); +#endif +#endif +#endif + if ( index >= 0 ){ + if ( pc.ptAct != NULL && pc.id == index ){ + // 1000?? + setPcFukidashi( 1000 ); + } + else + { + ptAct = getCharObjAct( index ); + if ( ptAct != NULL ) + { + // 1000?? + setCharFukidashi( ptAct, 1000 ); + } + } + } + } + return; +} + + + + +// ???? /////////////////////////////////////////////////////////// +// ???????????????? +void createNewCharStart(void) +{ + newCharStatus = 0; + + // ????V?t??e??????????? + if (bNewServer){ +#ifdef _MORECHARACTERS_ + extern int ﵱǰҳ; + lssproto_CreateNewChar_send(sockfd, selectPcNo+ﵱǰҳ*2, newCharacterName, + newCharacterGraNo, newCharacterFaceGraNo, + newCharacterVit, newCharacterStr, newCharacterTgh, newCharacterDex, + newCharacterEarth, newCharacterWater, newCharacterFire, newCharacterWind, + newCharacterHomeTown ); +#else +#ifdef _TRADITIONAL_LONG_ + CHAR szOutBuffer[128+1] = {0}; + WORD wLanguageID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + LCID Locale = MAKELCID(wLanguageID, SORT_CHINESE_PRCP); + int iRet = LCMapString(Locale, + LCMAP_SIMPLIFIED_CHINESE, + newCharacterName, -1, + szOutBuffer, 128); +#endif + lssproto_CreateNewChar_send(sockfd, selectPcNo, +#ifdef _TRADITIONAL_LONG_ + szOutBuffer, +#else + newCharacterName, +#endif + newCharacterGraNo, newCharacterFaceGraNo, + newCharacterVit, newCharacterStr, newCharacterTgh, newCharacterDex, + newCharacterEarth, newCharacterWater, newCharacterFire, newCharacterWind, + newCharacterHomeTown ); +#endif + }else + old_lssproto_CreateNewChar_send(sockfd, selectPcNo, newCharacterName, + newCharacterGraNo, newCharacterFaceGraNo, + newCharacterVit, newCharacterStr, newCharacterTgh, newCharacterDex, + newCharacterEarth, newCharacterWater, newCharacterFire, newCharacterWind, + newCharacterHomeTown ); + + SETSENDING; +} + + +// ???K???r? +// ??k 0 ... r? / 1 ... ?? / -1 ... ?????? / -2 ... ????????? +int createNewCharProc(void) +{ + if ( netproc_sending == NETPROC_RECEIVED ) + { + netproc_sending = NETPROC_NOTSEND; + if ( newCharStatus == 1 ) + { + return 1; + } + else + { + return -2; + } + } + + SETTIMEOUT2( NET_ERRMSG_CREATECHARTIMEOUT ); + + return 0; +} + +char ʾ[512]; +void lssproto_CreateNewChar_recv( int fd, char *result, char *data ) +{ + if ( netproc_sending == NETPROC_SENDING ) + { + netproc_sending = NETPROC_RECEIVED; + + if ( strcmp( result, SUCCESSFULSTR ) == 0 ) + { + newCharStatus = 1; + }else{ + sprintf(ʾ,data); + } + } +} + + + + + + + + +// ????? ///////////////////////////////////////////////////////////// +// ?????k?? +void delCharStart(void) +{ + charDelStatus = 0; + + if (bNewServer) + lssproto_CharDelete_send(sockfd, gamestate_deletechar_charname ); + else + old_lssproto_CharDelete_send(sockfd, gamestate_deletechar_charname ); + + SETSENDING; +} + + +// ?????r? +// ??k 0 ... ??r? / 1 ... ???? / -1 ... ?????? / -2 ... ????????? +int delCharProc(void) +{ + if ( netproc_sending == NETPROC_RECEIVED ) + { + netproc_sending = NETPROC_NOTSEND; + if ( charDelStatus ) + { + return 1; + } + else + { + return -2; + } + } + + SETTIMEOUT2( NET_ERRMSG_DELETECHARTIMEOUT ); + + return 0; +} + + +// ??????? +void lssproto_CharDelete_recv( int fd, char *result, char *data ) +{ + if ( netproc_sending == NETPROC_SENDING ) + { + netproc_sending = NETPROC_RECEIVED; + if ( strcmp( result, SUCCESSFULSTR ) == 0 ) + { + charDelStatus = 1; + } + } +} + +// ????? ///////////////////////////////////////////////////////// +void lssproto_PR_recv( int fd, int request, int result ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + if ( request == 1 && result == 1 ) + { + // M????????V????G?? + setPcParty(); + } + else + if ( request == 0 && result == 1 ) + { + // ?????????? + //delPcParty(); + //delPcLeader(); + partyModeFlag = 0; + clearPartyParam(); +#ifdef _CHANNEL_MODIFY + pc.etcFlag &= ~PC_ETCFLAG_CHAT_MODE; + if (TalkMode == 2) TalkMode = 0; +#endif + + char dir = (pc.dir+5) % 8; + if (bNewServer) + lssproto_SP_send(sockfd, nextGx, nextGy, dir ); + else + old_lssproto_SP_send(sockfd, nextGx, nextGy, dir ); + } + prSendFlag = 0; +} + + + +// EV?????????r? ///////////////////////////////////////// +void lssproto_EV_recv( int fd, int seqno, int result ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + if ( eventWarpSendId == seqno ) + { + eventWarpSendFlag = 0; + if ( result == 0 ) + { + // ????????????? + redrawMap(); + floorChangeFlag = FALSE; + // ?ɤ?????????? + warpEffectStart = TRUE; + warpEffectOk = TRUE; + } + } + else + if ( eventEnemySendId == seqno ) + { + if ( result == 0 ) + { + eventEnemySendFlag = 0; + } + //else + //{ + // ??????process.cpp??? + //} + } +} + + +// ??OK?PfN??OK????? ϣ?֢t //////////////////////// +void lssproto_FS_recv( int fd, int flg ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + pc.etcFlag = (unsigned short)flg; +} + + + +// ????????? /////////////////////////////////////////////// +void lssproto_AB_recv( int fd, char *data ) +{ + int i; + int no; + int nameLen; + char name[256]; + int flag; + int useFlag; +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + char planetid[8]; + int j ; +#endif + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + for ( i = 0; i < MAX_ADR_BOOK; i++ ) + { + //no = i * 6; //the second + no = i * 8; + useFlag = getIntegerToken(data, '|', no+1 ); + if ( useFlag == -1 ) + { + useFlag = 0; + } + if ( useFlag <= 0 ) + { +#if 0 + if ( addressBook[i].useFlag == 1 ) +#else + if ( MailHistory[i].dateStr[MAIL_MAX_HISTORY-1][0] != '\0' ) +#endif + { + memset( &MailHistory[i], 0, sizeof( MailHistory[0] ) ) ; + SaveMailHistory( i ); + // t???? + mailLamp = CheckMailNoReadFlag(); + // ????? + DeathLetterAction(); + } + addressBook[i].useFlag = 0; + addressBook[i].name[0] = '\0'; + continue; + } + +#ifdef _EXTEND_AB + if ( i == MAX_ADR_BOOK-1 ) + addressBook[i].useFlag = useFlag; + else + addressBook[i].useFlag = 1; +#else + addressBook[i].useFlag = 1; +#endif + + flag = getStringToken(data, '|', no+2, sizeof(name) - 1 , name ); + + if ( flag == 1 ) + break; + + makeStringFromEscaped(name); + nameLen = strlen(name); + if ( 0 < nameLen && nameLen <= CHAR_NAME_LEN ) + { + strcpy( addressBook[i].name, name ); + } + addressBook[i].level = getIntegerToken(data, '|', no+3 ); + addressBook[i].dp = getIntegerToken(data, '|', no+4 ); + addressBook[i].onlineFlag = (short)getIntegerToken(data, '|', no+5 ); + addressBook[i].graNo = getIntegerToken(data, '|', no+6 ); + addressBook[i].transmigration = getIntegerToken(data, '|', no+7 ); +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + for ( j = 0 ; j < MAX_GMSV ; j ++ ) { + if ( gmsv[j].used == '1' ) { + getStringToken( gmsv[j].ipaddr, '.', 4, sizeof( planetid ) -1, planetid ); + if ( addressBook[i].onlineFlag == atoi(planetid) ) { + sprintf_s( addressBook[i].planetname , "%s" , gmsv[j].name ) ; + break; + } + } + } +#endif + } +} + + +// ??????????Ol?//////////////////////////////////////// +void lssproto_ABI_recv( int fd, int num, char* data ) +{ + char name[256]; + int nameLen; + int useFlag; +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + char planetid[8]; + int j ; +#endif + + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + useFlag = getIntegerToken(data, '|', 1 ); + if ( useFlag == -1 ) + { + useFlag = 0; + } + if ( useFlag == 0 ) + { +#if 0 + if ( addressBook[num].useFlag == 1 ) +#else + if ( MailHistory[num].dateStr[MAIL_MAX_HISTORY-1][0] != '\0' ) +#endif + { + memset( &MailHistory[num], 0, sizeof( MailHistory[0] ) ) ; + SaveMailHistory( num ); + // t???? + mailLamp = CheckMailNoReadFlag(); + // ????? + DeathLetterAction(); + } + addressBook[num].useFlag = useFlag; + addressBook[num].name[0] = '\0'; + return; + } + +#ifdef _EXTEND_AB + if ( num == MAX_ADR_BOOK-1 ) + addressBook[num].useFlag = useFlag; + else + addressBook[num].useFlag = 1; +#else + addressBook[num].useFlag = useFlag; +#endif + + getStringToken(data, '|', 2, sizeof(name) - 1 , name ); + makeStringFromEscaped(name); + nameLen = strlen(name); + if ( 0 < nameLen && nameLen <= CHAR_NAME_LEN ) + { + strcpy( addressBook[num].name, name ); + } + addressBook[num].level = getIntegerToken(data, '|', 3 ); + addressBook[num].dp = getIntegerToken(data, '|', 4 ); + addressBook[num].onlineFlag = (short)getIntegerToken(data, '|', 5 ); + addressBook[num].graNo = getIntegerToken(data, '|', 6 ); + addressBook[num].transmigration = getIntegerToken(data, '|', 7 ); +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + if ( addressBook[num].onlineFlag == 0 ) + sprintf_s( addressBook[num].planetname , " "); + for ( j = 0 ; j < MAX_GMSV ; j ++ ) { + if ( gmsv[j].used == '1' ) { + getStringToken( gmsv[j].ipaddr, '.', 4, sizeof( planetid ) -1, planetid ); + if ( addressBook[num].onlineFlag == atoi(planetid) ) { + sprintf_s( addressBook[num].planetname ,64, "%s" , gmsv[j].name ) ; + break; + } + } + } +#endif + + +} + + +// Pf??????? ///////////////////////////////////////////////// +void lssproto_RS_recv( int fd, char *data ) +{ + int i; + char token[2048]; + char item[2048]; + + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + battleResultMsg.useFlag = 1; + //cary ȷ λ + int cols = RESULT_CHR_EXP; + getStringToken(data, ',', RESULT_CHR_EXP+1, sizeof( token ) - 1, token ); + if ( token[0] == 0){ + cols = RESULT_CHR_EXP - 1; + battleResultMsg.resChr[RESULT_CHR_EXP-1].petNo = -1; + battleResultMsg.resChr[RESULT_CHR_EXP-1].levelUp = -1; + battleResultMsg.resChr[RESULT_CHR_EXP-1].exp = -1; + } + //end cary + + for ( i = 0; i < cols; i++ ){ + getStringToken(data, ',', i+1, sizeof( token ) - 1, token ); + + battleResultMsg.resChr[i].petNo = getIntegerToken( token, '|', 1 ); + battleResultMsg.resChr[i].levelUp = getIntegerToken( token, '|', 2 ); + battleResultMsg.resChr[i].exp = getInteger62Token( token, '|', 3 ); + } + + getStringToken(data, ',', i+1, sizeof( token ) - 1, token ); + getStringToken( token, '|', 1, sizeof( item ) - 1, item ); + makeStringFromEscaped( item ); + if ( strlen( item ) <= RESULT_ITEM_NAME_LEN ) + { + strcpy( battleResultMsg.item[0], item ); + } + getStringToken( token, '|', 2, sizeof( item ) - 1, item ); + makeStringFromEscaped( item ); + if ( strlen( item ) <= RESULT_ITEM_NAME_LEN ) + { + strcpy( battleResultMsg.item[1], item ); + } + getStringToken( token, '|', 3, sizeof( item ) - 1, item ); + makeStringFromEscaped( item ); + if ( strlen( item ) <= RESULT_ITEM_NAME_LEN ) + { + strcpy( battleResultMsg.item[2], item ); + } +} + + +// ??????????? ///////////////////////////////////////////////// +void lssproto_RD_recv( int fd, char *data ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + battleResultMsg.useFlag = 2; + + battleResultMsg.resChr[0].exp = getInteger62Token(data, '|', 1 ); + battleResultMsg.resChr[1].exp = getInteger62Token(data, '|', 2 ); +} + + +// ?????t? /////////////////////////////////////////////////// +void lssproto_SI_recv( int fd, int from, int to ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + swapItem( from, to ); +} + + +// ????ѩ /////////////////////////////////////////////////////// +void lssproto_I_recv( int fd, char *data ) +{ + int i, j; + int no; + char name[256]; + char name2[256]; + char memo[256]; + //char *data = "9|˹̹||0|;10ǰظ|24002|0|1|0|7||1||20||10|˹̹||0|;10ǰظ|24002|0|1|0|7||1||20|"; + if ( logOutFlag )//δ½򲻽 + return; + + for ( j = 0; ; j++ ){ +#ifdef _ITEM_JIGSAW +#ifdef _NPC_ITEMUP +#ifdef _ITEM_COUNTDOWN + no = j * 17; +#else + no = j * 16; +#endif +#else + no = j * 15; +#endif +#else +#ifdef _PET_ITEM + no = j * 14; +#else +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST +#ifdef _MAGIC_ITEM_ + no = j * 15; +#else + no = j * 13; +#endif +#else + no = j * 12; +#endif +#else + + no = j * 11; +#endif +#endif//_PET_ITEM +#endif//_ITEM_JIGSAW + i = getIntegerToken(data, '|', no+1 );//λ + if ( getStringToken(data, '|', no+2, sizeof(name) - 1 , name ) == 1 )// + break; + makeStringFromEscaped(name); + if ( strlen(name) == 0 ){ + pc.item[i].useFlag = 0; + continue; + } + pc.item[i].useFlag = 1; + if ( strlen(name) <= ITEM_NAME_LEN ){ + strcpy( pc.item[i].name, name ); + } + getStringToken(data, '|', no+3, sizeof( name2 ) - 1, name2 );//ڶ + makeStringFromEscaped( name2 ); + if ( strlen( name2 ) <= ITEM_NAME2_LEN ){ + strcpy( pc.item[i].name2, name2 ); + } + pc.item[i].color = getIntegerToken(data, '|', no+4 );//ɫ + if ( pc.item[i].color < 0 ) + pc.item[i].color = 0; + getStringToken(data, '|', no+5, sizeof( memo ) - 1, memo );//߽ + makeStringFromEscaped( memo ); + if ( strlen( memo ) <= ITEM_MEMO_LEN ){ + strcpy( pc.item[i].memo, memo ); + } + pc.item[i].graNo = getIntegerToken(data, '|', no+6 );// + pc.item[i].field = getIntegerToken(data, '|', no+7 );// + pc.item[i].target = getIntegerToken(data, '|', no+8 ); + if ( pc.item[i].target >= 100 ){ + pc.item[i].target %= 100; + pc.item[i].deadTargetFlag = 1; + }else{ + pc.item[i].deadTargetFlag = 0; + } + pc.item[i].level = getIntegerToken(data, '|', no+9 );//ȼ + pc.item[i].sendFlag = getIntegerToken(data, '|', no+10 ); + + { + // ʾƷ;ö + char damage[256]; + getStringToken(data, '|', no+11, sizeof( damage ) - 1, damage ); + makeStringFromEscaped( damage ); + if ( strlen( damage ) <= 16 ){ + strcpy( pc.item[i].damage, damage ); + } + } +#ifdef _ITEM_PILENUMS + { + char pile[256]; + getStringToken(data, '|', no+12, sizeof( pile ) - 1, pile ); + makeStringFromEscaped( pile ); + pc.item[i].pile = atoi( pile); + } +#endif + +#ifdef _ALCHEMIST //_ITEMSET7_TXT + { + char alch[256]; + getStringToken(data, '|', no+13, sizeof( alch ) - 1, alch ); + makeStringFromEscaped( alch ); + strcpy( pc.item[i].alch, alch ); + } +#endif +#ifdef _PET_ITEM + { + char type[8]; + getStringToken(data, '|', no + 14, sizeof(type) - 1, type); + makeStringFromEscaped(type); + pc.item[i].type = atoi(type); + } +#else +#ifdef _MAGIC_ITEM_ + pc.item[i]. = getIntegerToken(data, '|', no + 14); +#endif +#endif + /* +#ifdef _ITEM_JIGSAW + { + char jigsaw[10]; + getStringToken(data, '|', no + 15, sizeof(jigsaw) - 1, jigsaw); + makeStringFromEscaped(jigsaw); + strcpy( pc.item[i].jigsaw, jigsaw ); + if( i == JigsawIdx ){ + SetJigsaw( pc.item[i].graNo, pc.item[i].jigsaw ); + } + } +#endif +#ifdef _NPC_ITEMUP + pc.item[i].itemup = getIntegerToken(data, '|', no + 16); +#endif +#ifdef _ITEM_COUNTDOWN + pc.item[i].counttime = getIntegerToken(data, '|', no + 17); +#endif + */ + + } +} + +void lssproto_WN_recv( int fd,int windowtype,int buttontype,int seqno,int objindex,char* data ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + if( strstr(data,"֮ʧࡣ") ){ + if( TimeGetTime() - MsgCooltime > 300000 ) + MsgCooltime = TimeGetTime(); + else + return; + } + openServerWindow( windowtype, buttontype, seqno, objindex, data ); + +} + + +// ??????? /////////////////////////////////////////////////////// +void lssproto_PME_recv( int fd, int objindex, + int graphicsno, int x, int y, int dir, int flg, int no, char *cdata ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + // Pf????? + if ( encountNowFlag ) + return; + + // ?? + if ( flg == 0 ) + { + switch ( no ) + { + case 0: + createPetAction( graphicsno, x, y, dir, 0, dir, -1 ); + break; + case 1: + createPetAction( graphicsno, x, y, dir, 2, 0, -1 ); + break; + } + } + else + // ? + { + char smalltoken[2048]; + int id; + int x; + int y; + int dir; + int graNo; + int level; + int nameColor; + char name[2048]; + char freeName[2048]; + int walkable; + int height; + int charType; + int ps=1; +#ifdef _OBJSEND_C + ps = 2; +#endif + charType = getIntegerToken( cdata, '|', ps++); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + id = a62toi(smalltoken); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + x = atoi(smalltoken); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + y = atoi(smalltoken); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + dir = (atoi(smalltoken)+3)%8; + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + graNo = atoi(smalltoken); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1,smalltoken); + level = atoi(smalltoken); + nameColor = getIntegerToken( cdata, '|', ps++ ); + getStringToken( cdata, '|' , ps++ , sizeof(name) - 1, name ); + makeStringFromEscaped(name); + getStringToken( cdata, '|' , ps++ , sizeof( freeName ) - 1, freeName ); + makeStringFromEscaped( freeName ); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + walkable = atoi(smalltoken); + getStringToken( cdata, '|', ps++, sizeof(smalltoken) - 1, smalltoken); + height = atoi(smalltoken); + + // ???ѩ?????????? + if ( setReturnPetObj( id, graNo, x, y, dir, name, freeName, + level, nameColor, walkable, height, charType ) ) + { + switch ( no ) + { + case 0: + createPetAction( graphicsno, x, y, dir, 1, 0, objindex ); + break; + + case 1: + createPetAction( graphicsno, x, y, dir, 3, 0, objindex ); + break; + } + } + } +} + +char *pCommand = NULL; +DWORD dwDiceTimer; +// ?????????r? ///////////////////////////////////////////// +void lssproto_EF_recv( int fd, int effect, int level, char *option ) +{ + // u?????????? + if ( effect == 0 ) + { + mapEffectRainLevel = 0; + mapEffectSnowLevel = 0; + mapEffectKamiFubukiLevel = 0; +#ifdef _HALLOWEEN_EFFECT + mapEffectHalloween = 0; + initMapEffect(FALSE); +#endif + return; + } + // ??????? + if ( effect & 1 ) + { + mapEffectRainLevel = level; + } + // D?????? + if ( effect & 2 ) + { + mapEffectSnowLevel = level; + } + // ???? + if ( effect & 4 ) + { + mapEffectKamiFubukiLevel = level; + } +#ifdef _HALLOWEEN_EFFECT + if (effect & 8) mapEffectHalloween = level; +#endif +// Terry add 2002/01/14 +#ifdef __EDEN_DICE + // + if (effect == 10) + { + pCommand = (char*)MALLOC(strlen(option)+1); +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + if (pCommand != NULL) + { + strcpy(pCommand,strlen(option)+1,option); + bMapEffectDice = TRUE; + dwDiceTimer = TimeGetTime(); + } + } +#endif +// Terry end +} + + +// ? /////////////////////////////////////////////////////////////////// +void lssproto_IS_recv( int fd, char* cdata ) +{ +} +void lssproto_EN_recv( int fd,int result,int field ) +{ + + if ( logOutFlag ) + return; + if ( result > 0 ){ + EncountFlag = TRUE; + if ( result == 4 ) + vsLookFlag = 1; + else + vsLookFlag = 0; + if ( result == 6 || result == 2 ) + eventEnemyFlag = 1; + else + eventEnemyFlag = 0; + + if ( field < 0 || BATTLE_MAP_FILES <= field ) + BattleMapNo = 0; + else + BattleMapNo = field; + if ( result == 2 ) + DuelFlag = TRUE; + else + DuelFlag = FALSE; + + if ( result == 2 || result == 5 ) + NoHelpFlag = TRUE; + else + NoHelpFlag = FALSE; + + BattleStatusReadPointer = BattleStatusWritePointer =0; + BattleCmdReadPointer = BattleCmdWritePointer =0; +#ifdef PK_SYSTEM_TIMER_BY_ZHU + BattleCliTurnNo = -1; +#endif + }else{ + sendEnFlag = 0; + duelSendFlag = 0; + jbSendFlag = 0; + } +} + + +void lssproto_HL_recv( int fd, int flg ) +{ + helpFlag = flg; +} + +void lssproto_B_recv( int fd,char* command ) +{ + + if ( *( command + 1 ) == 'C'){ + strcpy( BattleStatusBak[ BattleStatusWritePointer ], command ); + BattleStatusWritePointer = ( BattleStatusWritePointer + 1 ) & ( BATTLE_BUF_SIZE-1 ); + } + + else if ( *( command + 1 ) == 'P') + sscanf_s( command + 3, "%X|%X|%X", &BattleMyNo, &BattleBpFlag, &BattleMyMp ); + + else if ( *( command + 1 ) == 'A'){ + sscanf_s( command + 3, "%X|%X", &BattleAnimFlag, &BattleSvTurnNo ); + + if ( BattleTurnReceiveFlag == TRUE ){ + BattleCliTurnNo = BattleSvTurnNo; + BattleTurnReceiveFlag = FALSE; + } + } + + else if ( *( command + 1 ) == 'U') + BattleEscFlag = TRUE; +#ifdef PK_SYSTEM_TIMER_BY_ZHU + else if ( *( command + 1 ) == 'Z') { + int TurnNo = -1; + sscanf( command + 3, "%X", &TurnNo ); + if ( TurnNo >= 0 ) + { + if ( TurnNo > 0 ) + { + BattleCntDownRest = TRUE; + } else { + BattleCntDown = TimeGetTime() + BATTLE_CNT_DOWN_TIME; + } + BattleCliTurnNo = TurnNo; + } + } + else if ( *( command + 1 ) == 'F') { + int TurnNo = -1; + sscanf( command + 3, "%X", &TurnNo ); + if ( TurnNo >= 0 ) + { + BattleCliTurnNo = TurnNo; + } + //if ( TurnNo >= 0 ) + //{ + // if ( TurnNo > 0 ) + // { + // BattleCntDownRest = TRUE; + // } else { + // BattleCntDown = TimeGetTime() + BATTLE_CNT_DOWN_TIME; + // } + // BattleCliTurnNo = TurnNo; + //} + BattleDown(); + //BattleSetWazaHitBox( 0, 0 ); + } + else if ( *( command + 1 ) == 'O') { + int TurnNo = -1; + sscanf( command + 3, "%X", &TurnNo ); + if ( TurnNo >= 0 ) + { + BattleCliTurnNo = TurnNo; + BattleCntDown = TimeGetTime() + BATTLE_CNT_DOWN_TIME; + } + } +#endif + else { + strcpy( BattleCmdBak[ BattleCmdWritePointer ], command ); + BattleCmdWritePointer = ( BattleCmdWritePointer + 1 ) & ( BATTLE_BUF_SIZE-1 ); + } + +#ifdef _STONDEBUG__MSG + //StockChatBufferLine( command, FONT_PAL_RED ); +#endif + +} + +#ifdef _PETS_SELECTCON +void lssproto_PETST_recv( int fd,int petarray,int result ) +{ + if ( petarray < 0 || petarray >= 5 ) return; + pc.selectPetNo[ petarray] = result; + BattlePetStMenCnt--; + if ( BattlePetStMenCnt < 0 ) BattlePetStMenCnt = 0; + if ( BattlePetStMenCnt > 4 ) BattlePetStMenCnt = 4; + if ( pc.battlePetNo == petarray ) + pc.battlePetNo = -1; +} + +#endif + +void lssproto_KS_recv( int fd,int petarray,int result ) +{ + int cnt = 0; + int i; + + BattlePetReceiveFlag = FALSE; + BattlePetReceivePetNo = -1; + if ( result == TRUE ){ + battlePetNoBak = -2; + if ( petarray != -1 ){ + pc.selectPetNo[ petarray ] = TRUE; + if ( pc.mailPetNo == petarray ) pc.mailPetNo = -1; + for ( i = 0 ; i < 5 ; i++ ){ + if ( pc.selectPetNo[ i ] == TRUE && i != petarray ) cnt++; + if ( cnt >= 4 ){ + pc.selectPetNo[ i ] = FALSE; + cnt--; + } + } + } + pc.battlePetNo = petarray; + } +#ifdef _AFTER_TRADE_PETWAIT_ + else{ + if (tradeStatus==2){ + pc.selectPetNo[petarray] = 0; + if (petarray==pc.battlePetNo) + pc.battlePetNo = -1; + } + } +#endif +} + +#ifdef _STANDBYPET +void lssproto_SPET_recv( int fd, int standbypet, int result ) +{ + int cnt = 0; + int i; + + StandbyPetSendFlag = FALSE; + + if ( result == TRUE ) { + pc.standbyPet = standbypet; + for ( i =0; i = MAIL_MAX_HISTORY ) mailHistoryWndPageNo = 0; + // ????????? + // DeathLetterAction(); + } + // ? + play_se( 101, 320, 240 ); + // ???????V + SaveMailHistory( aindex ); +} + + +// ??????????? +void lssproto_PS_recv( int fd,int result,int havepetindex,int havepetskill,int toindex ) +{ + char moji[ 256 ]; + + // ??????? + ItemMixRecvFlag = FALSE; + + // ??? + if ( result == 0 ){ + //??????? + sprintf_s( moji,"ʧܣ"); + // ?????????????????? + StockChatBufferLine( moji, FONT_PAL_WHITE ); + } + +} + + +// ???????D?? +void lssproto_SE_recv( int fd, int x, int y, int senumber, int sw ) +{ + // ????????????????ѩ???? + if ( logOutFlag ) + return; + + if ( sw ) + { + play_se( senumber, x, y ); + } + else + { + // ????????Y???? + } +} + +// Pf?q????????? +void lssproto_XYD_recv( int fd, int x, int y, int dir ) +{ + updateMapArea(); + setPcWarpPoint( x, y ); + setPcPoint(); + dir = (dir+3) % 8; + setPcDir( dir ); +} + +void lssproto_WO_recv( int fd, int effect ) +{ + return; + // ??????? + if ( effect == 0 ) + { + // ???????? + transmigrationEffectFlag = 1; + // ????????????? + transEffectPaletteStatus = 1; + // ???????? + palNo = 15; + palTime = 300; + } +} + +// ?????? ///////////////////////////////////////////////////////// +void lssproto_Echo_recv( int fd, char *test ) +{ +#if 1 +#ifdef _STONDEBUG__MSG + + // ???T??x + time( &serverAliveLongTime ); + localtime_s(&serverAliveTime, &serverAliveLongTime ); + +#endif +#endif +} + + +// Robin 2001/04/06 +void lssproto_NU_recv( int fd, int AddCount) +{ + +} + + +// ????? +void lssproto_PlayerNumGet_recv( int fd, int logincount, int player ) +{ +} + + +void lssproto_ProcGet_recv( int fd, char* data ) +{ +} + + + + +/* + ?????ѩ?????? + +*/ +void lssproto_R_recv( int fd, char* data ) +{ +} + + +void lssproto_D_recv( int fd,int category,int dx,int dy,char* data ) +{ +} + +/* + ???d???????????????????? +*/ +void lssproto_ACI_recv( int fd, char* data ) +{ + +} + +extern void initFamilyList( char * ); +extern void initFamilyDetail( char * ); +extern void initJoinChannelWN( char * ); +extern void initJoinChannel2WN( char * ); +extern void initFamilyTaxWN( char * ); +extern void initFamilyLeaderChange( char * ); + +void lssproto_FM_recv( int fd, char* data ) +{ + char FMType1[512]; + char FMType2[512]; + char FMType3[512]; + + getStringToken(data, '|', 1, sizeof( FMType1 ) - 1, FMType1 ); + //makeStringFromEscaped( FMType1 ); + getStringToken(data, '|', 2, sizeof( FMType2 ) - 1, FMType2 ); + //makeStringFromEscaped( FMType2 ); + + if ( strcmp(FMType1,"S") ==0 ) + { + if ( strcmp(FMType2,"F") ==0) // б + { + initFamilyList(data ); + + } + if ( strcmp(FMType2,"D") ==0) // ϸ + { + initFamilyDetail(data ); + + } + + } + else if ( strcmp(FMType1,"C") ==0 ) + { + if ( strcmp(FMType2,"J") ==0) // Ƶ + { + getStringToken(data, '|', 3, sizeof( FMType3 ) - 1, FMType3 ); + pc.channel = atoi( FMType3 ); + if ( pc.channel != -1 ) + pc.quickChannel = pc.channel; + } + if ( strcmp(FMType2,"L") ==0) // Ƶб + { + initJoinChannel2WN(data ); + + } + } + else if ( strcmp(FMType1,"B") ==0 ) + { + + //MenuToggleFlag = JOY_CTRL_B; + if ( strcmp(FMType2,"G") ==0) + { + //getStringToken(data, '|', 3, sizeof( FMType3 ) - 1, FMType3 ); + BankmanInit(data ); + } + if ( strcmp(FMType2,"I") ==0) + { + //getStringToken(data, '|', 3, sizeof( FMType3 ) - 1, FMType3 ); + //ItemmanInit(data ); + //initItemman(data ); + } + if ( strcmp(FMType2,"T") ==0) + { + initFamilyTaxWN(data ); + } + + + } + else if ( strcmp(FMType1,"R") ==0 ) + { + if ( strcmp(FMType2,"P") ==0) // ride Pet + { + //initFamilyList(data ); + getStringToken(data, '|', 3, sizeof( FMType3 ) - 1, FMType3 ); + pc.ridePetNo = atoi( FMType3 ); + + } + + } + else if ( strcmp(FMType1,"L") ==0 ) // 峤 + { + if ( strcmp(FMType2,"CHANGE") ==0) + { + initFamilyLeaderChange(data ); + } + } + +} + + +DWORD dwPingTime; +DWORD dwPingState; + +#ifdef __NEW_CLIENT + +#define ICMP_ECHO 8 +#define ICMP_ECHOREPLY 0 +#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header) + +/* The IP header */ +typedef struct iphdr { + unsigned int h_len:4; // length of the header + unsigned int version:4; // Version of IP + unsigned char tos; // Type of service + unsigned short total_len; // total length of the packet + unsigned short ident; // unique identifier + unsigned short frag_and_flags; // flags + unsigned char ttl; + unsigned char proto; // protocol (TCP, UDP etc) + unsigned short checksum; // IP checksum + + unsigned int sourceIP; + unsigned int destIP; + +}IpHeader; + +typedef struct _ihdr { + BYTE i_type; + BYTE i_code; /* type sub code */ + USHORT i_cksum; + USHORT i_id; + USHORT i_seq; + /* This is not the std header, but we reserve space for time */ + ULONG timestamp; +}IcmpHeader; + +#define STATUS_FAILED 0xFFFF +#define DEF_PACKET_SIZE 32 +#define MAX_PACKET 1024 + +USHORT checksum(USHORT *buffer, int size) +{ + unsigned long cksum=0; + while( size > 1){ + cksum += *buffer++; + size -=sizeof(USHORT); + } + if ( size) + cksum += *(UCHAR*)buffer; + cksum = (cksum >> 16) + (cksum & 0xffff); + cksum += (cksum >>16); + return (USHORT)(~cksum); +} + +int iWrote, iRead; +SOCKET sockRaw = INVALID_SOCKET; +DWORD WINAPI PingFunc(LPVOID param) +{ + struct sockaddr_in from; + struct sockaddr_in dest; + int datasize; + int fromlen = sizeof(from); + int timeout = 1000; + IcmpHeader *icmp_hdr; + + char icmp_data[MAX_PACKET]; + char recvbuf[MAX_PACKET]; + USHORT seq_no = 0; + + ZeroMemory( &dest, sizeof(dest)); + memcpy( &(dest.sin_addr), (void*)param, 4); + dest.sin_family = AF_INET; + if ( sockRaw != INVALID_SOCKET){ + closesocket( sockRaw); + sockRaw = INVALID_SOCKET; + } + sockRaw = socket( AF_INET, SOCK_RAW, IPPROTO_ICMP); + if ( sockRaw != INVALID_SOCKET){ + iRead = setsockopt( sockRaw, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)); + if ( iRead != SOCKET_ERROR){ + timeout = 1000; + iRead = setsockopt( sockRaw, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout)); + if ( iRead != SOCKET_ERROR){ + datasize = DEF_PACKET_SIZE + sizeof(IcmpHeader); + + icmp_hdr = (IcmpHeader*)icmp_data; + icmp_hdr->i_type = ICMP_ECHO; + icmp_hdr->i_code = 0; + icmp_hdr->i_id = (USHORT)GetCurrentProcessId(); + icmp_hdr->i_cksum = 0; + icmp_hdr->i_seq = 0; + memset( icmp_data+sizeof(IcmpHeader), 'E', datasize - sizeof(IcmpHeader)); + while( 1){ + ((IcmpHeader*)icmp_data)->i_cksum = 0; + ((IcmpHeader*)icmp_data)->timestamp = GetTickCount(); + + ((IcmpHeader*)icmp_data)->i_seq = seq_no; + ((IcmpHeader*)icmp_data)->i_cksum = checksum( (USHORT*)icmp_data, datasize); + + iWrote = sendto( sockRaw, icmp_data, datasize, 0, (struct sockaddr*)&dest, sizeof(struct sockaddr)); + if ( iWrote == SOCKET_ERROR){ + if ( WSAGetLastError() == WSAETIMEDOUT){ + dwPingTime = -1; + continue; + } + dwPingState = 0x40000000 | WSAGetLastError(); + continue; + } + if ( iWrote < datasize) + dwPingState = 0x04000000;//len error + while( 1){ + iRead = recvfrom( sockRaw, recvbuf, MAX_PACKET, 0, (struct sockaddr*)&from, &fromlen); + if ( iRead == SOCKET_ERROR){ + if ( WSAGetLastError() == WSAETIMEDOUT){ + dwPingTime = -1; + break; + } + dwPingState = 0x40000000 | WSAGetLastError(); + continue; + } + IpHeader *iphdr; + unsigned short iphdrlen; + iphdr = (IpHeader *)recvbuf; + iphdrlen = iphdr->h_len * 4 ; // number of 32-bit words *4 = bytes + if ( iRead < iphdrlen + ICMP_MIN) + dwPingState = 0x08000000;//len error + icmp_hdr = (IcmpHeader*)(recvbuf + iphdrlen); + if ( icmp_hdr->i_type != ICMP_ECHOREPLY){ + dwPingState = 0x10000000;//non-echo type recvd + continue; + } + if ( icmp_hdr->i_seq != seq_no) + continue; + if ( icmp_hdr->i_id != (USHORT)GetCurrentProcessId()){ + dwPingState = 0x20000000;//someone else's packet! + continue; + } + dwPingTime = GetTickCount()-icmp_hdr->timestamp; + break; + } + seq_no++; + dwPingState = 0x80000000; + Sleep( 3000); + } + } + } + } + return 0; +} + +#endif +#ifdef _ITEM_CRACKER +extern bool m_bt; +void lssproto_IC_recv(int fd, int x, int y) +{ + m_bt = true; setCharMind( pc.ptAct, SPR_cracker); + m_bt = false; +} +#endif + +#ifdef _CHECK_GAMESPEED +static int delaytimes=0; +void lssproto_CS_recv( int fd, int deltimes) +{ + delaytimes = deltimes; +} +int lssproto_getdelaytimes() +{ + if ( delaytimes < 0 ) delaytimes = 0; + return delaytimes; +} +void lssproto_setdelaytimes( int delays) +{ + delaytimes = delays; +} +#endif + +#ifdef _MAGIC_NOCAST//Ĭ +void lssproto_NC_recv( int fd, int flg ) +{ + if (flg==1 ) + NoCastFlag=TRUE; + else + NoCastFlag=FALSE; +} +#endif +#ifdef _CHANNEL_MODIFY +// Ի +FILE *pSaveChatDataFile[6]={NULL,NULL,NULL,NULL,NULL,NULL}; +void SaveChatData(char *msg,char KindOfChannel,bool bCloseFile){ + static char szFileName[256]; + static struct tm nowTime; + static time_t longTime; + static unsigned short Channel[] = { + PC_ETCFLAG_CHAT_MODE //Ƶ + ,PC_ETCFLAG_CHAT_TELL //Ƶ + ,PC_ETCFLAG_CHAT_FM //Ƶ +#ifdef _CHAR_PROFESSION + ,PC_ETCFLAG_CHAT_OCC //ְҵƵ +#endif +#ifdef _CHATROOMPROTOCOL + ,PC_ETCFLAG_CHAT_CHAT //ҿ +#endif +#ifdef _CHANNEL_WORLD + ,PC_ETCFLAG_CHAT_WORLD //Ƶ +#endif +#ifdef _CHANNEL_ALL_SERV + ,PC_ETCFLAG_ALL_SERV //Ƶ +#endif + }; + char ChannelType[] = {'T','M','F', +#ifdef _CHAR_PROFESSION + 'O', +#endif + 'R', +#ifdef _CHANNEL_WORLD + 'W', +#endif +#ifdef _CHANNEL_ALL_SERV + 'S', +#endif + }; + + // Իѡ + if ((pc.etcFlag & PC_ETCFLAG_CHAT_SAVE) && !bCloseFile){ + time(&longTime); + localtime_s(&nowTime,&longTime); + for (int i=0;i<6;i++){ + if (pc.etcFlag & Channel[i]){ + if (pSaveChatDataFile[i] == NULL){ + sprintf_s(szFileName,"chat\\%c%02d%02d%02d.TXT",ChannelType[i],(nowTime.tm_year % 100),nowTime.tm_mon+1,nowTime.tm_mday); + if ((pSaveChatDataFile[i] = fopen(szFileName,"a")) == NULL) continue; + } + } + else{ + if (pSaveChatDataFile[i] != NULL){ + fclose(pSaveChatDataFile[i]); + pSaveChatDataFile[i]=NULL; + } + } + } + for (int i=0;i<6;i++){ + if (KindOfChannel == ChannelType[i]){ + if (pSaveChatDataFile[i] != NULL) fprintf(pSaveChatDataFile[i],"[%02d:%02d:%02d]%s\n",nowTime.tm_hour,nowTime.tm_min,nowTime.tm_sec,msg); + } + } + } + else bCloseFile = 1; + + if (bCloseFile){ + for (int i=0;i<6;i++) + if (pSaveChatDataFile[i] != NULL){ + fclose(pSaveChatDataFile[i]); + pSaveChatDataFile[i]=NULL; + } + } +} +#endif + +#ifdef _STREET_VENDOR +extern short sStreetVendorBtn; +extern short sStreetVendorBuyBtn; +extern void StreetVendorWndfunc(bool bReset,char *data); +extern void StreetVendorBuyWndfunc(char *data); + +void lssproto_STREET_VENDOR_recv(int fd,char *data) +{ + char szMessage[32]; + + getStringToken(data,'|',1,sizeof(szMessage) - 1,szMessage); + switch (szMessage[0]){ + // °̯ + case 'O': + sStreetVendorBtn = 1; + pc.iOnStreetVendor = 1; + break; + // 趨̯ + case 'S': + sStreetVendorBtn = 3; + StreetVendorWndfunc(false,data); + break; + // server + case 'B': + sStreetVendorBuyBtn = 1; + StreetVendorBuyWndfunc(data); + break; + // server رӴ + case 'C': + sStreetVendorBuyBtn = 0; + break; + // server ĵʷϸ + case 'D': + StreetVendorBuyWndfunc(data); + break; + } +} +#endif + + +#ifdef _STONDEBUG_ // ֶͳ Robin +/* + ()`d`(ֵ)`s`(ִ)`...... + : 35`d`100`d`100`s`P|Hellp~~`d`1`d`1 +*/ +void sendDataToServer( char* data) +{ + char token[1024]; + char token2[1024]; + char token3[1024]; + char sendbuf[16384] =""; + char showbuf[16384] =""; + char showsubbuf[1024]; + int checksum=0; + int datakind; + int i =1; + + strcat_s( showbuf, "ֶͳ "); + + getStringToken(data, '`', i++, sizeof(token), token ); + if ( token[0] == NULL ) return; + datakind = atoi( token); + sprintf_s( showsubbuf, "=%d ", datakind); + strcat_s( showbuf, showsubbuf); + + while(1) { + + getStringToken(data, '`', i++, sizeof(token2), token2 ); + if ( token2[0] == NULL ) break; + getStringToken(data, '`', i++, sizeof(token3), token3 ); + if ( token3[0] == NULL ) break; + + if ( !strcmp( token2, "d") ) { + checksum += util_mkint( sendbuf, atoi(token3)); + sprintf_s( showsubbuf, "=%d ", atoi(token3)); + strcat_s( showbuf, showsubbuf); + } + else if ( !strcmp( token2, "s") ) { + checksum += util_mkstring( sendbuf, token3); + sprintf_s( showsubbuf, "=%s ", token3); + strcat_s( showbuf, showsubbuf); + } + else { + break; + } + + } + + util_mkint( sendbuf, checksum); + util_SendMesg(sockfd, datakind, sendbuf); + + StockChatBufferLine( showbuf, FONT_PAL_RED); + +} +#endif +#ifdef _FAMILYBADGE_ +extern int []; +extern int ¸; +int ¼۸; +void lssproto_FamilyBadge_recv(char *data) +{ + ¸=0; + int i=2; + ¼۸ = getIntegerToken(data,'|',1); + for(i;i<201;i++){ + [i-2] = getIntegerToken(data,'|',i); + if([i-2]==-1) break; + ¸++; + } +} +#endif + + +#ifdef _JOBDAILY +extern JOBDAILY jobdaily[MAXMISSION]; +extern int JobdailyGetMax; //Ƿнյ +void lssproto_JOBDAILY_recv(int fd,char *data) +{ + // + int i=1,j=1; + char getdata[250]; + char perdata[200]; + + //StockChatBufferLine(data,FONT_PAL_RED); + + memset(jobdaily,0,sizeof(jobdaily)); + getdata[0] = '\0'; + perdata[0] = '\0'; + while(getStringToken(data,'#',i,sizeof(getdata) - 1,getdata)!=1){ + while(getStringToken(getdata,'|',j,sizeof(perdata) - 1,perdata)!=1){ + switch (j){ + case 1: jobdaily[i-1].JobId = atoi(perdata);break; + case 2: strcpy(jobdaily[i-1].explain,perdata); break; + case 3: strcpy(jobdaily[i-1].state,perdata); break; + default: StockChatBufferLine("ÿڲд",FONT_PAL_RED); break; + } + perdata[0] = '\0'; + j++; + } + getdata[0] = '\0'; + j=1; + i++; + } + if (i>1) + JobdailyGetMax= i-2; + else JobdailyGetMax = -1; +} + +#endif + +#ifdef _TEACHER_SYSTEM +extern short sTeacherSystemBtn; +extern void TeacherSystemWndfunc(int flag,char *data); +void lssproto_TEACHER_SYSTEM_recv(int fd,char *data) +{ + char szMessage[16]; + + getStringToken(data,'|',1,sizeof(szMessage) - 1,szMessage); + switch (szMessage[0]){ + // ʾ˵ + case 'M':sTeacherSystemBtn = 1;break; + // ѯǷҪԷĵʦ + case 'C': + sTeacherSystemBtn = 2; + TeacherSystemWndfunc(0,data); + break; + // һ,ѯҪ˭ʦ + case 'A': + sTeacherSystemBtn = 3; + TeacherSystemWndfunc(1,data); + break; + // ʾʦ + case 'V': + sTeacherSystemBtn = 4; + TeacherSystemWndfunc(2,data); + break; +#ifdef _TEACHER_SYSTEM_2 + case 'S': + sTeacherSystemBtn = 6; + TeacherSystemWndfunc(4,data); + break; +#endif + } +} +#endif + +#ifdef _ADD_STATUS_2 +void lssproto_S2_recv(int fd,char *data) +{ + char szMessage[16]; +#ifdef _EVIL_KILL + int ftype = 0 , newfame = 0; +#endif + + getStringToken(data,'|',1,sizeof(szMessage) - 1,szMessage); + +#ifdef _NEW_MANOR_LAW + if (strcmp(szMessage,"FAME") == 0){ + getStringToken(data,'|',2,sizeof(szMessage) - 1,szMessage); + pc.fame = atoi(szMessage); + } +#endif + +#ifdef _EVIL_KILL + pc.ftype = 0; + pc.newfame = 0; + + if( getStringToken(data,'|',3,sizeof(szMessage) - 1,szMessage) == 1 ) return; + ftype = atoi(szMessage); + getStringToken(data,'|',4,sizeof(szMessage) - 1,szMessage); + newfame = atoi(szMessage); + pc.ftype = ftype; + pc.newfame = newfame; +#endif +} +#endif + +#ifdef _ITEM_FIREWORK +void lssproto_Firework_recv(int fd, int nCharaindex, int nType, int nActionNum) +{ + ACTION *pAct; + + if (pc.id == nCharaindex) + changePcAct(0, 0, 0, 51, nType, nActionNum, 0); + else + { + pAct = getCharObjAct(nCharaindex); + changeCharAct(pAct, 0, 0, 0, 51, nType, nActionNum, 0); + + } +} +#endif + +#ifdef _MOVE_SCREEN +// client ƶӫĻ +void lssproto_MoveScreen_recv(int fd, BOOL bMoveScreenMode, int iXY) +{ + pc.bMoveScreenMode = bMoveScreenMode; + pc.bCanUseMouse = bMoveScreenMode; + if (bMoveScreenMode) + { + pc.iDestX = HIWORD(iXY); + pc.iDestY = LOWORD(iXY); + } + else + iScreenMoveX = iScreenMoveY = 0; +} +#endif + +#ifdef _THEATER +void lssproto_TheaterData_recv(int fd, char *pData) +{ + int iType, iData; + char szMessage[16]; + float fX, fY; + + getStringToken(pData, '|', 1, sizeof(szMessage) - 1, szMessage); + iType = atoi(szMessage); + getStringToken(pData, '|', 2, sizeof(szMessage) - 1, szMessage); + iData = atoi(szMessage); + switch (iType) + { + case E_THEATER_SEND_DATA_THEATER_MODE: + pc.iTheaterMode = iData; + if (iData == 0) + { + pc.bCanUseMouse = FALSE; // ,ʹûƶ + pc.iSceneryNumber = -1; + } + else + { + pc.bCanUseMouse = TRUE; // + pc.iSceneryNumber = 26558; + } + break; + case E_DATA_TYPE_MOVE: // ƶ + camMapToGamen((float)(HIWORD(iData) * GRID_SIZE), float(LOWORD(iData) * GRID_SIZE), &fX, &fY); + MouseNowPoint((int)(fX + 0.5f), (int)(fY + 0.5f)); + MouseCrickLeftDownPoint((int)(fX + 0.5f), (int)(fY + 0.5f)); + MouseCrickLeftUpPoint((int)(fX + 0.5f), (int)(fY + 0.5f)); + pc.bCanUseMouse = FALSE; // Ϊ FALSE,Ȼﲻƶ + mouse.level = DISP_PRIO_TILE; + closeCharActionAnimeChange(); + break; + case E_DATA_TYPE_DIR: // + setPcDir(iData); + szMessage[0] = cnvServDir(iData, 1 ); + szMessage[1] = '\0'; + walkSendForServer(nowGx, nowGy, szMessage); + break; + case E_DATA_TYPE_SCENERY: // + pc.iSceneryNumber = iData; + break; + case E_DATA_TYPE_BGM: // + play_bgm(iData); + break; + case E_THEATER_SEND_DATA_DISPLAY_SCORE: // ʾ + pc.iTheaterMode |= 0x00000004; + pc.iTheaterMode |= iData << 16; // iData Ƿֵ + break; + case E_DATA_TYPE_NPC: // ʧʱNPC + // iType Ϊ E_DATA_TYPE_NPC ʱȡ iData NPC + if (iData >= 0 && iData < 5) + { + int iSprNum, iGX, iGY, iAction, iDir; + + getStringToken(pData, '|', 3, sizeof(szMessage) - 1, szMessage); // ȡָ + if (atoi(szMessage) == 1) + { + getStringToken(pData, '|', 4, sizeof(szMessage) - 1, szMessage); // ȡͼ + iSprNum = atoi(szMessage); + getStringToken(pData, '|', 5, sizeof(szMessage) - 1, szMessage); // ȡ + iGX = atoi(szMessage); + getStringToken(pData, '|', 6, sizeof(szMessage) - 1, szMessage); // ȡ + iGY = atoi(szMessage); + getStringToken(pData, '|', 7, sizeof(szMessage) - 1, szMessage); // ȡ + iAction = atoi(szMessage); + getStringToken(pData, '|', 8, sizeof(szMessage) - 1, szMessage); // ȡ + iDir = atoi(szMessage); + camMapToGamen((float)iGX * GRID_SIZE, (float)iGY * GRID_SIZE, &fX, &fY); + if (pc.pActNPC[iData] == NULL) + { + pc.pActNPC[iData] = MakeAnimDisp((int)fX, (int)fY, iSprNum, ANIM_DISP_THEATER_NPC); + ATR_DISP_PRIO(pc.pActNPC[iData]) = DISP_PRIO_CHAR - 1; + } + if (pc.iTheaterMode & 0x00000001) + { + iGX -= iScreenMoveX; + iGY -= iScreenMoveY; + } + pc.pActNPC[iData]->gx = iGX; + pc.pActNPC[iData]->gy = iGY; + pc.pActNPC[iData]->mx = (float)(iGX * GRID_SIZE); + pc.pActNPC[iData]->my = (float)(iGY * GRID_SIZE); + ATR_CHR_NO(pc.pActNPC[iData]) = iSprNum; + ATR_CHR_ACT(pc.pActNPC[iData]) = iAction; + ATR_CHR_ANG(pc.pActNPC[iData]) = iDir; + } + else + { + if (pc.pActNPC[iData]) + { + DeathAction(pc.pActNPC[iData]); + pc.pActNPC[iData] = NULL; + } + } + } + break; + } +} +#endif + +#ifdef _NPC_MAGICCARD + +bool bShowflag[20]; +int iShowdamage[20]; +int iPosition[20]; +int iOffsetY[20]; +int ioffsetsx = 0; +int ioffsetsy = 0; +unsigned int inextexet = 0; + +void lssproto_MagiccardDamage_recv(int fd, int position , int damage , int offsetx , int offsety ) +{ + int i; + + if( position == 10 ) + { + wnCloseFlag = 1; + return; + } + + for ( i=0;i<20;i++ ){ + if ( bShowflag[i]==TRUE) continue; + iPosition[i] = position; + iShowdamage[i] = damage; + bShowflag[i] = TRUE; + break; + } + ioffsetsx = offsetx; + ioffsetsy = offsety; +} + +void lssproto_MagiccardAction_recv(int fd, char *data) +{ + ACTION *pAct; + int charaindex,player,card,dir,actionNum,action,offsetx,offsety; + char token[2048]; + + getStringToken(data , '|', 1, sizeof( token ) - 1, token ); + charaindex = atoi( token ); + getStringToken(data, '|', 2, sizeof( token ) - 1, token ); + player = atoi( token ); + getStringToken(data, '|', 3, sizeof( token ) - 1, token ); + card = atoi(token); + getStringToken(data, '|', 4, sizeof( token ) - 1, token ); + dir = (atoi( token )+3)%8; + getStringToken(data, '|', 5, sizeof( token ) - 1, token ); + actionNum = atoi( token ); //ͼ + getStringToken(data, '|', 6, sizeof( token ) - 1, token ); + action = atoi( token ); + getStringToken(data, '|', 7, sizeof( token ) - 1, token ); + offsetx = atoi( token ); + getStringToken(data, '|', 8, sizeof( token ) - 1, token ); + offsety = atoi( token ); + + //if ( actionNum == 101652 ){ + // dir = 1; + // dir = 2; + //} + if (pc.id == charaindex) + //changePcAct(0, 0, 0, 51, nType, nActionNum, 0); + changePcAct( offsetx , offsety , dir, 60 , player , actionNum , action); + else{ + pAct = getCharObjAct(charaindex); + //changeCharAct( ptAct, x, y, dir, act, effectno, effectparam1, effectparam2 ); + changeCharAct(pAct, offsetx , offsety , dir, 60, player , actionNum , action ); + } +} +#endif + +#ifdef _NPC_DANCE +void lssproto_DancemanOption_recv( int fd , int option ) +{ + switch( option ) + { + case 0: //رӴ + wnCloseFlag = 1; + break; + case 1: //һģʽ + pc.iDanceMode = 1; + break; + case 2: //رնһģʽ + pc.iDanceMode = 0; + break; + } +} +#endif + +#ifdef _HUNDRED_KILL +void lssproto_hundredkill_recv( int fd, int flag ){ + + if ( flag == 1 ) + BattleHundredFlag = TRUE; + else + BattleHundredFlag = FALSE; +} +#endif + +#ifdef _ANNOUNCEMENT_ + +void lssproto_DENGON_recv(char *data, int colors, int nums) +{ + extern int ; + extern char [512]; + extern int ɫ; + extern int ʱ; + ʱ=0; + sprintf(, "%s", data); + ɫ = colors; + = nums; +} +#endif + + +#ifdef _PET_SKINS + +void lssproto_PetSkins_recv(char *data) +{ + char *str = "λ|ǰʹƤͼ|Ƥ|Ƥͼ|˵|Ƥͼ|˵|..."; +} + +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/netproc.zip b/石器时代8.5客户端最新源代码/石器源码/system/netproc.zip new file mode 100644 index 0000000..9437209 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/system/netproc.zip differ diff --git a/石器时代8.5客户端最新源代码/石器源码/system/onlinegm.cpp b/石器时代8.5客户端最新源代码/石器源码/system/onlinegm.cpp new file mode 100644 index 0000000..afeadfb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/onlinegm.cpp @@ -0,0 +1,2022 @@ +//cyg ʵһϵͳ (ϻرϵͳ) +#include"../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/loadrealbin.h" +#include"../systeminc/loadsprbin.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/login.h" +#include"../systeminc/menu.h" +#include"../systeminc/map.h" +#include"../systeminc/lssproto_cli.h" +#include"../systeminc/pc.h" +#include"../systeminc/netmain.h" +#include"../systeminc/handletime.h" +#include"../systeminc/character.h" +#include"../other/caryIme.h" +#include"../systeminc/ime_sa.h" +#include"../systeminc/t_music.h" +#include"../systeminc/netproc.h" +#include"../systeminc/tool.h" +#include "time.h" +#include "../wgs/descrypt.h" +#include"../systeminc/onlinegm.h" + +char ProblemClass[DEF_CLASS_TOTAL][16]={ + "쳣", + "һ" +}; +char ProblemC1[DEF_C1_TOTAL][30]={ + "˿ʯ", + "ҳָ", + "ͷƷ", + "װ", + "Աʺ", + "Ʒ", + "Ʒ", + "Ϸ򼰴ֵ", + "", + "/ŷ/ܱƷ", + "//·״Ӧ", + "Ϸѯ", + "ǷͶ", + "" +}; +char ProblemC1Help[DEF_C1_TOTAL][60]={ + "ע쳣ʺšꡢص㡢ѶϢϵ", + "ṩ", + "ȲѯϷרվԼͷ", + "뾡ĵ䱸", + "״", + "ṩ", + "ṩ", + "Ϸֿ۵㲻ѡΪ(Ϸ۵)", + "", + "Ȳѯרҳػ", + "", + "ȲѯҳFAQ", + "", + "" +}; +char ProblemC2[DEF_C2_TOTAL][16]={ + "쳣", + "쳣", + "쳣", + "", + "Ƶ", + "", + "", + "ףǣӿ۵", + "", + "Ա", + "ϵ", +}; +//쳣 +char ProblemC2_1[3][16]={ + "ʧ", + "쳣", + "" +}; +//쳣 +char ProblemC2_2[3][16]={ + "ʧ", + "", + "߹쳣" +}; +//쳣 +char ProblemC2_3[5][16]={ + "ʧ", + "ʼ", + "", + "ﵰ", + "" +}; +// +char ProblemC2_4[2][16]={ + "׺ʧ", + "" +}; +//Ƶ +char ProblemC2_5[2][16]={ + "Ƶòѯ", + "" +}; +// +char ProblemC2_6[3][16]={ + "屻ɢ", + "쳣", + "" +}; +//ϵ +char ProblemC2_7[3][16]={ + "ʧ", + "ʧ", + "" +}; + +//HELPʹõҳϽṹ +typedef struct PAGE{ + short desc_index; //˵ṹʼ(desc_indexΪseg_indexhelp_indexȡDESCеindex) + int desc_num;//BYTE desc_num; //˵Ľṹ +}*LPPAGE; + +//ע +//HELPʹõ˵Ͻṹ +typedef struct DESC{ + BYTE color; //ɫ + char description[60]; //˵ +}*LPDESC; + + +// ṹ cyg +typedef struct{ + char no[20]; + char state[40]; + char okdate[10]; + int okH; + char wrongdate[10]; + int wrongH; + int class0; + char class1[40]; + char cont[4000]; + char answer[4000]; + char error[2000]; + BOOL delflag; +}PRODATA; + + +DESC Prohelp_desc1[]={ + //ɫ˵ //fix + { 4 , "1. ʹ˵"}, + { 0 , " Ϊ20ʣѴȽⵥɾ"}, + { 0 , " ҳ쳣ڡ"}, + { 0 , " ⵥʾϷ"}, + { 4 , "2. ﵰ쳣"}, + { 0 , " 2003/12/31շʱﵰ趨ijʽ"}, + { 0 , " ͷĽҳﵰ쳣"}, + { 0 , " ijﵰ趨£"}, + { 0 , " ι趨һһСʱ"}, + { 0 , " ߻ﵰڳУٴε"}, + { 0 , " ¼ιʱ䡣"}, + { 4 , "3. ʧ"}, + { 0 , " Ϸʽ趨ͬһŷڣſڵ[Ա]"}, +}; + +DESC Prohelp_desc2[]={ + { 0 , " ȡأ޷ȡṩϳơȼԭ"}, + { 0 , " ʺšڡʧڡ"}, + { 4 , "4. ʧ"}, + { 0 , " Ϸʽ趨ͬһŷڣſڵ[Ա]"}, + { 0 , " ȡأ޷ȡṩϳơȼԭ"}, + { 0 , " ʺšڡʧڡ"}, + //{ 4 , "4. ս-޷"}, + //{ 0 , " ҳ϶ȵ20£սоͻߡΪԭϷ趨"}, + //{ 0 , " ͷIJظ"}, + { 4 , "5. ׺Ʒʧ-ṩ"}, + { 0 , " ׷ʺŻơڡ׵ijԼȼ"}, + { 0 , " Լ"}, + { 4 , "6. NPC-޷"}, + { 0 , " ΪԭϷ趨ͷIJظߡ"}, + { 4 , "7. ߶ϵͳ-޷"}, + { 0 , " ΪԭϷ趨ͷIJظߣҿ"}, +}; + +DESC Prohelp_desc3[]={ + { 0 , " Ϸ͸׽תơ"}, + { 4 , "8. 쳣-ṩ"}, + { 0 , " 쳣峤ʺעơš쳣"}, + { 0 , " ״Ϊ㣬ϵͳԶɢļ壬ͬ"}, + { 0 , " дͷ޷"}, + { 0 , " ڼɢԱδ߶Զ˳趨ϵ"}, + { 0 , " ͳÿ᲻ʱɨ衢⡣"}, + { 0 , " ĿǰԱ趨˳7޷ټ塣"}, + { 4 , "9. DP쳣-޷ "}, + { 0 , " DPϷвӰ죬޿Ŵ˹ܹҲѯ"}, + { 4 , "10. Ƭʧ-޷"}, + { 0 , " ƬĶӦһԶ(һӵжλҵ"}, + { 0 , " Ƭ)һҲ޷ʹȷ޿Ŵ"}, +}; + +DESC Prohelp_desc4[]={ + { 0 , " ܹҲѯ"}, + { 4 , "11. &թƭ-ṩ"}, + { 0 , " ơȼԼơƵ Ա"}, + { 0 , " ɲѯɾ¼ҲҪԱظ"}, + { 0 , " (ûгԼʯ) Աṩ֮ߡ"}, + { 0 , " вѯĶ"}, + { 4 , "12. ȸת趨 2003/06/21"}, + { 0 , " ֮ȸֵתСɳռ䣬ԭ"}, + { 0 , " ֵݲһάתǰߵ㣬ڴҪתȸʱ"}, + { 0 , " ӿǡͷIJظתǰȸ֮"}, +}; + +//DESC Prohelp_desc5[]={ +//}; + +LPDESC Prohelp_Index[] ={ + &Prohelp_desc1[0], + &Prohelp_desc2[0], + &Prohelp_desc3[0], + &Prohelp_desc4[0] +// &Prohelp_desc5[0] +}; + +PAGE ProHelp_page[]={ + { 0 , sizeof(Prohelp_desc1)/sizeof(Prohelp_desc1[0])}, + { 0 , sizeof(Prohelp_desc2)/sizeof(Prohelp_desc2[0])}, + { 0 , sizeof(Prohelp_desc3)/sizeof(Prohelp_desc3[0])}, + { 0 , sizeof(Prohelp_desc4)/sizeof(Prohelp_desc4[0])} +// { 0 , sizeof(Prohelp_desc5)/sizeof(Prohelp_desc5[0])} +}; + + +INPUT_HISTORY InputHistory ; // ÿһеݣ + +STR_BUFFER SubBuffer ; // ÿһдbuf + +#ifdef __ONLINEGM // ȫص + +char DataBuffer[500]; // ϺõرһIJ +char InputBuffer[8050]; // ҵ +char ContentBuf[8050]; // Ϻõ + +PRODATA Prodata[100]; // Խ100 + +int PutKey,PushKey ; + +int ProNoSelect; // ѡĵ +int HistorySelect; // ϴѡѯĵ +BOOL ProNoSelectFlag; // ûѡŵ +int ProNoIndex; // ⵥ +int ProNoValue; // ʾмⵥ + +BOOL TitleFlag ; +int SegmentIndex ; // һһݵ +int SegmentTotal ; // ¼ܹм +char SegmentBuf[2][2500];// ¼ijʵŵݺͿͷӦ + +int okY,okM,okD,okH,wrongY,wrongM,wrongD,wrongH; +int ClassIndex , ClassIndex1 , ClassIndex2 ; // + +BOOL DeleteBtnFlag; //ҪѡijŲɾ + + +//OnlineGm Log ר Begin +#ifdef _STONDEBUG_ +char inlogstr[512]; +#define filename "onlinegm.log" +#endif +//OnlineGm Log ר End + +//߻ϵͳ Server IP : 10.1.0.17 + +BOOL QueryOnlineGmIP(char HostName[]); +char *OnlineGmIP; //ʹdomain name +//char OnlineGmIP[20]; //ʹֱip +#define SMSDomainName "ingame.wayi.com.tw"//"sms.hwaei.com.tw" + +int ResultCode; // + +static char *pContent=NULL; + +BOOL ResetFlag = TRUE; +BOOL DirFlag = TRUE; +DWORD LastTime = 0; +int iReturnNo; //¼شĵ + +int TotalAddValue; //¼Ŀǰ + +int ProblemType ; //¼ͼʱⵥ һ0쳣1 +int SendType ; //¼͸serverǰ + +unsigned int ichecklooptime = 0; //߻Ȧʱ + +//************************************* +// ʼ +//************************************* +void InitOnlineGm( void ) +{ + int i; + + PutKey = 0; + PushKey = 0; + ProNoSelectFlag = FALSE; + ProNoSelect = 0; + HistorySelect = 5000; // + ProNoIndex = 0; + ProNoValue = 0; + SegmentIndex =0; + SegmentTotal = 0; + okY=okM=okD=okH=wrongY=wrongM=wrongD=wrongH=0; + ClassIndex = 1; + ClassIndex1 = ClassIndex2 =0; + + ResetFlag = TRUE ; + DirFlag = TRUE ; + DeleteBtnFlag = FALSE ; + + DataBuffer[0] = '\0'; + InputBuffer[0] = '\0'; + ContentBuf[0] = '\0'; + + SegmentBuf[0][0]='\0'; + SegmentBuf[1][0]='\0'; + + for( i=0;i16) return 3; + +#ifdef _FIX_URLENCODE + char OutTmp[8000]; + char *pOutTmp ; + char *pInTmp ; + char Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + // do encoding + pInTmp=pinput; + pOutTmp=OutTmp; + while (*pInTmp) + { + if ( (*pInTmp>= '0') && (*pInTmp <= '9') + || (*pInTmp>= 'a') && (*pInTmp <= 'z') + || (*pInTmp>= 'A') && (*pInTmp <= 'Z') + ) + *pOutTmp++ = *pInTmp; + else + { + if(*pInTmp==0x20&&(!IsDBCSLeadByte(*pInTmp))) + *pOutTmp++ = '+'; + else + { + *pOutTmp++ = '%'; + *pOutTmp++ = Hex[(*pInTmp>>4)&0x0f]; + *pOutTmp++ = Hex[(*pInTmp)&0x0f]; + } + } + + pInTmp++; + + } + *pOutTmp = '\0'; + sprintf_s(pinput,8050,"&qcontent=%s",OutTmp); +#endif + + SOCKET hSock; + SOCKADDR_IN stName; + fd_set rfds,wfds; + timeval tmTimeOut; + char *result; + int len, cnt, ret ; + + tmTimeOut.tv_usec=0; + tmTimeOut.tv_sec=5; + if( INVALID_SOCKET != ( hSock = socket( AF_INET, SOCK_STREAM, 0) ) ) + { + DWORD flg = 1; + if( SOCKET_ERROR != ioctlsocket( hSock, FIONBIO, &flg)) + { + ZeroMemory( &stName, sizeof(struct sockaddr)); + stName.sin_family = PF_INET; + stName.sin_port = htons(80); + stName.sin_addr.s_addr = inet_addr(OnlineGmIP); + ret = connect( hSock, (LPSOCKADDR)&stName, sizeof(struct sockaddr) ); + if( SOCKET_ERROR != ret || WSAEWOULDBLOCK == WSAGetLastError() ) + { + cnt = 0; + char buf[3000]; + if(ProblemType==0){ + SendType=0; //һ + sprintf_s(buf,"GET //normal_check.asp?wgsid=%s&gamepwd=%s&game=1%s%s",pid,ppw,pdb,pinput); + }else{ + SendType=1; //쳣 + sprintf_s(buf,"GET //handle_check.asp?wgsid=%s&gamepwd=%s&game=1%s%s",pid,ppw,pdb,pinput); + } + strcat_s(buf," HTTP/1.1\r\nAccept: text/*\r\nUser-Agent: StoneAge\r\n"); + sprintf_s(buf,"%sHost: %s\r\n\r\n",buf,OnlineGmIP); +#ifdef _STONDEBUG_ //дonlinegm.log + WriteInLog( buf , filename); +#endif + len = lstrlen(buf); + ichecklooptime = TimeGetTime(); + while(1) + { + FD_ZERO( &wfds); + FD_SET( hSock, &wfds); + nRet = select( NULL, (fd_set*)NULL, &wfds, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return 4; + }else if(nRet == 0){ + closesocket(hSock); + return 8; + } + if( FD_ISSET( hSock, &wfds) ){ + ret = send( hSock, &buf[cnt], len, 0); + cnt += ret; + len -= ret; + if(len<1) break; //ok + } + if( TimeGetTime() - ichecklooptime > 3000 ){ + closesocket(hSock); + return 8; + } + } + Sleep(500); + len = (InputHistory.newNo*70)+500 ; //1024; + cnt = 0; + ichecklooptime = TimeGetTime(); + while(1) + { + if(wait>=3){ + closesocket(hSock); + return 8; + } + FD_ZERO( &rfds); + FD_SET( hSock, &rfds); + select( NULL, &rfds, (fd_set*)NULL, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return 4; + } + if(nRet == 0){ + wait++; + continue; + } + if( FD_ISSET( hSock, &rfds) ){ + ret = recv( hSock, &buf[cnt], len, 0); + if(ret<0){ + closesocket(hSock); + return 4; + } + } + buf[cnt+ret] = 0; + result = strstr( buf, "\r\n\r\n") + 4; + getStringToken(result ,',',1,sizeof(returndata)-1,returndata); + if(atoi(returndata)!=1){ //شʾ1ʾok + closesocket(hSock); + return atoi(returndata); + }else{ + getStringToken(result ,':',2,sizeof(returndata)-1,returndata); + iReturnNo = atoi(returndata); // + } + if(result) break; + cnt += ret; + len -= ret; + if( TimeGetTime() > ichecklooptime + 3000 ){ + closesocket(hSock); + return 8; + } + } + }else{ + closesocket(hSock); + return 6; + } + } + closesocket(hSock); + return 1; + } + return 4; +} + +//************************************************ +// Ҫɾŵʽ +// شֵ :0 --- & ɾɹ +// 3 --- ݴ +// 4 --- ·˴ +// 6 --- ʱ(DNSʧ) +//************************************************ +int SendDeleteMsg(char pid[16], char ppw[16] , char pno[16] ) +{ + int nRet; + if(!QueryOnlineGmIP(SMSDomainName)) return 6; + + int ret,len,cnt,icheck,wait=1; + SOCKET hSock; + SOCKADDR_IN stName; + fd_set rfds,wfds; + timeval tmTimeOut; + char *result; + tmTimeOut.tv_usec=0; + tmTimeOut.tv_sec=5; + if( INVALID_SOCKET != ( hSock = socket( AF_INET, SOCK_STREAM, 0) ) ) + { + DWORD flg = 1; + if( SOCKET_ERROR != ioctlsocket( hSock, FIONBIO, &flg)) + { + ZeroMemory( &stName, sizeof(struct sockaddr)); + stName.sin_family = PF_INET; + stName.sin_port = htons(80); + stName.sin_addr.s_addr = inet_addr(OnlineGmIP); + ret = connect( hSock, (LPSOCKADDR)&stName, sizeof(struct sockaddr) ); + if( SOCKET_ERROR != ret || WSAEWOULDBLOCK == WSAGetLastError() ) + { + cnt = 0; + char buf[1024]; + sprintf_s(buf,"GET //DelForm.asp?wgsid=%s&gamepwd=%s&rcount=1&idno=%s",pid,ppw,pno); + strcat_s(buf," HTTP/1.1\r\nAccept: text/*\r\nUser-Agent: StoneAge\r\n"); + sprintf_s(buf,"%sHost: %s\r\n\r\n",buf,OnlineGmIP); + len = lstrlen(buf); + ichecklooptime = TimeGetTime(); + while(1) + { + FD_ZERO( &wfds); + FD_SET( hSock, &wfds); + nRet = select( NULL, (fd_set*)NULL, &wfds, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return 4; + }else if(nRet == 0){ + closesocket(hSock); + return 8; + } + if( FD_ISSET( hSock, &wfds) ){ + ret = send( hSock, &buf[cnt], len, 0); + cnt += ret; + len -= ret; + if(len<1) break; //ok + } + if( TimeGetTime() > ichecklooptime + 3000 ){ + closesocket(hSock); + return 8; + } + } + Sleep(500); + len = 1024; + cnt = 0; + ichecklooptime = TimeGetTime(); + while(1) + { + if(wait>=3){ + closesocket(hSock); + return 8; + } + FD_ZERO( &rfds); + FD_SET( hSock, &rfds); + nRet = select( NULL, &rfds, (fd_set*)NULL, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return 4; + } + if(nRet == 0){ + wait++; + continue; + } + if( FD_ISSET( hSock, &rfds) ){ + ret = recv( hSock, &buf[cnt], len, 0); + if(ret<0){ + closesocket(hSock); + return 4; + } + buf[cnt+ret] = 0; + result = strstr( buf, "\r\n\r\n") + 4; + char *sss; + strtok_s(result,",",&sss); + icheck=atoi(result); + if(icheck != 1){ + closesocket(hSock); + return icheck; + } + if(result) break; + cnt += ret; + len -= ret; + } + if( TimeGetTime() > ichecklooptime + 3000 ){ + closesocket(hSock); + return 8; + } + } + }else{ + closesocket(hSock); + return 6; + } + } + closesocket(hSock); + return 1 ; + } + return 4 ; +} + +//************************************************ +// ServerҪҵⵥ +// شֵ 0: ȷ +// 2: κⵥ +// 4: ·˴ +// 6: ʱ(DNSʧ) +//************************************************ +int SendDirMsg(char pid[16], char ppw[16] ) +{ + if(!QueryOnlineGmIP(SMSDomainName)) return 6; + + int nRet,i=1; + int wait=1,j=1; + char alldata[65536],getdata[6000],perdata[3000],statedata[100]; //ȫ,ÿ,ÿ,״̬ + char returndata[20] ; + BOOL Okflag = FALSE , Firstflag = TRUE; +#ifdef _STONDEBUG_ + char logbuf[50]; +#endif + int ret,len,cnt; + SOCKET hSock; + SOCKADDR_IN stName; + fd_set rfds,wfds; + timeval tmTimeOut; + char *result; + + tmTimeOut.tv_usec=0; + tmTimeOut.tv_sec=5; + memset(alldata,0,sizeof(alldata)); + if( INVALID_SOCKET != ( hSock = socket( AF_INET, SOCK_STREAM, 0) ) ) + { + DWORD flg = 1; + if( SOCKET_ERROR != ioctlsocket( hSock, FIONBIO, &flg)) + { + ZeroMemory( &stName, sizeof(struct sockaddr)); + stName.sin_family = PF_INET; + stName.sin_port = htons(80); + stName.sin_addr.s_addr = inet_addr(OnlineGmIP); + ret = connect( hSock, (LPSOCKADDR)&stName, sizeof(struct sockaddr) ); + if( SOCKET_ERROR != ret || WSAEWOULDBLOCK == WSAGetLastError() ) + { + cnt = 0; + char buf[65536]; + sprintf_s(buf,"GET //userFormList.asp?wgsid=%s&gamepwd=%s",pid,ppw); + strcat_s(buf," HTTP/1.1\r\nAccept: text/*\r\nUser-Agent: StoneAge\r\n"); + sprintf_s(buf,"%sHost: %s\r\n\r\n",buf,OnlineGmIP); + len = lstrlen(buf); + ichecklooptime = TimeGetTime(); + while(1) + { + FD_ZERO( &wfds); + FD_SET( hSock, &wfds); + nRet = select( NULL, (fd_set*)NULL, &wfds, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return -400; + }else if(nRet == 0){ + closesocket(hSock); + return -800; + } + if( FD_ISSET( hSock, &wfds) ){ + ret = send( hSock, &buf[cnt], len, 0); + cnt += ret; + len -= ret; + if(len<1) break; //ok + } + if( TimeGetTime() > ichecklooptime + 3000 ){ + closesocket(hSock); + return -800; + } + } + Sleep(500); + len = 65536;//8000; + cnt = 0; + ichecklooptime = TimeGetTime(); + while(1) + { + if(wait>=3){ + closesocket(hSock); + return -800; + } + FD_ZERO( &rfds); + FD_SET( hSock, &rfds); + nRet = select( NULL, &rfds, (fd_set*)NULL, (fd_set*)NULL, &tmTimeOut); + if(nRet == SOCKET_ERROR||nRet==-1){ + closesocket(hSock); + return -400; + } + if(nRet == 0){ + wait++; + continue; + } + if( FD_ISSET( hSock, &rfds) ){ + ret = recv( hSock, &buf[cnt], len, 0); + if(ret<0){ + closesocket(hSock); + return -400; + } + buf[cnt+ret] = 0; + result = strstr( buf, "\r\n\r\n") + 4; + if(strcmp(result,"0")==0){ + closesocket(hSock); + return -200; + } + strcpy(alldata,result); + cnt += ret; + len -= ret; + } + if(strstr(alldata,"&#")){ //ok + break; + } + if( TimeGetTime() > ichecklooptime + 3000 ){ + closesocket(hSock); + return -800; + } + } + getStringToken(result ,',',1,sizeof(returndata)-1,returndata); + if(atoi(returndata)<0){ //شʾ󣬴0ӴͬʱҲʾok + closesocket(hSock); + return atoi(returndata); + }else{ + TotalAddValue = atoi(returndata); + } + result = alldata; + result = strstr( result , ",") + 1; + strcpy(alldata,result); + }else{ +#ifdef _STONDEBUG_ + sprintf_s(logbuf,"Get last error:%d",WSAGetLastError()); + WriteInLog( logbuf , filename); +#endif + return -600; + } + } + closesocket(hSock); + ProNoValue = 0; + ProNoSelectFlag = FALSE; +#ifdef _STONDEBUG_ //дonlinegm.log + WriteInLog( alldata , filename); +#endif + perdata[0] = '\0'; + getdata[0] = '\0'; + //sprintf_s(alldata,"21||*|*|*|*|18|˿ʯ|װάллŬ~л֧밮ҲٴεԤף޸죡˳⣡|װάллŬ~л֧밮ҲٴεԤף޸죡˳⣡|&#"); + while(getStringToken( alldata,'&',i,sizeof(getdata)-1,getdata)!=1){ + while(getStringToken(getdata,'|',j,sizeof(perdata)-1,perdata)!=1){ + if( strcmp( perdata , "*")){ + switch(j){ + case 1:sprintf_s(Prodata[ProNoValue].no,"%s",perdata); break; + case 2: + getStringToken(perdata,'>',2,sizeof(statedata)-1,statedata); + getStringToken(statedata,'<',1,sizeof(statedata)-1,statedata); + if(lstrlen(statedata) == NULL) + sprintf_s(Prodata[ProNoValue].state,"%s",perdata); + else + sprintf_s(Prodata[ProNoValue].state,"%s",statedata); + break; + case 3:sprintf_s(Prodata[ProNoValue].okdate,"%s",perdata);break; + case 4:Prodata[ProNoValue].okH=atoi(perdata); break; + case 5:sprintf_s(Prodata[ProNoValue].wrongdate,"%s",perdata);break; + case 6:Prodata[ProNoValue].wrongH=atoi(perdata); break; + case 7:Prodata[ProNoValue].class0=atoi(perdata);break; + case 8:sprintf_s(Prodata[ProNoValue].class1,"%s",perdata);break; + case 9:sprintf_s(Prodata[ProNoValue].cont,"%s",perdata);break; + case 10:sprintf_s(Prodata[ProNoValue].answer,"%s",perdata);break; + default: sprintf_s(Prodata[ProNoValue].error,"%s",perdata);break; + } + } + perdata[0] = '\0'; + j++; + } + getdata[0] = '\0'; + ProNoValue++; + j=1; + i++; + } + //TotalAddValue = ProNoValue; + return 1 ; // ok + } + return 4 ; +} +//************************************************ +// ѯⵥ +//************************************************ +void vReadContent( int pno ) +{ + static char *pRecv ; + char date[10]; + char data[40]; + char classbuf1[40],classbuf2[40]; + int i=1; + + ClassIndex=Prodata[pno].class0 - 18; + + if(ClassIndex == 0 ){ //쳣 + while(getStringToken(Prodata[pno].okdate,'/',i,sizeof(date)-1,date)!=1){ + if( i==1 ) okY = atoi(date); + else if( i==2) okM = atoi(date); + i ++; + } + okD = atoi(date); + okH = Prodata[pno].okH; + i = 1; + date[0] = '\0'; + while(getStringToken(Prodata[pno].wrongdate,'/',i,sizeof(date)-1,date)!=1){ + if( i==1 ) wrongY = atoi(date); + else if( i==2) wrongM = atoi(date); + i ++; + } + wrongD = atoi(date); + wrongH = Prodata[pno].wrongH; + } + + if(getStringToken(Prodata[pno].class1,',',1,sizeof(data)-1,data)!=1){ + sprintf_s(classbuf1,"%s",data); + data[0] = '\0'; + if(getStringToken(Prodata[pno].class1,',',2,sizeof(data)-1,data)==1) + sprintf_s(classbuf2,"%s",data); + }else{ + sprintf_s(classbuf1,"%s",data); + } + + if(ClassIndex){ // һ + for(i=0;i=ProNoValue) + break ; + if (ProNoIndex+i==ProNoSelect && ProNoSelectFlag == TRUE){ + sprintf_s(buf,"%s %s",Prodata[ProNoIndex+i].no,Prodata[ProNoIndex+i].state); + fontId[i] = StockFontBuffer( x + 20 , y+7+(i*20) , FONT_PRIO_FRONT, 1 , buf , 2 ); + }else{ + sprintf_s(buf,"%s %s",Prodata[ProNoIndex+i].no,Prodata[ProNoIndex+i].state); + fontId[i] = StockFontBuffer( x + 20 , y+7+(i*20) , FONT_PRIO_FRONT, 0 , buf, 2 ); + } + if(Prodata[ProNoIndex+i].delflag == TRUE){ + sprintf_s(buf,"ɾ"); + StockFontBuffer( x + 70 , y+7+(i*20) , FONT_PRIO_FRONT, 4 , buf, 2 ); + } + } + + Keyid = selFontId( fontId, sizeof( fontId )/sizeof( int ) ); + if ( 0 <= Keyid && Keyid < 5 ){ + if (ProNoIndex + Keyid < ProNoValue){ + //ѯijȵŵ + ProNoSelectFlag = TRUE; + ProNoSelect = ProNoIndex + Keyid; + if ( ProNoSelect != HistorySelect ){ + HistorySelect = ProNoSelect; + InitOnlineGmInput(x, y); + SegmentIndex = 0; + SegmentTotal = 0; + SegmentBuf[0][0] = '\0'; + SegmentBuf[1][0] = '\0'; + vReadContent( ProNoSelect ); + } + } + } + + if( SegmentTotal > SegmentIndex ){ // + InputHistory.addNo =0; // Բü + GetKeyInputFocus(&SubBuffer); + if( SegmentIndex %2 == 0 ){ + if(TitleFlag==TRUE){ + StrToNowStrBuffer1("ǰݣ"); + for ( k=0;k<60+10;k++ ) + StrToNowStrBuffer(" "); + InputHistory.color[InputHistory.newNo]=TRUE; + pContent = SegmentBuf[SegmentIndex]; + TitleFlag = FALSE; + }else{ + if(pContent!=NULL){ + word = StrToNowStrBuffer2(pContent); + pContent+=word ; + if(word<70){ + for ( k=0;k<(80-word);k++ ) + StrToNowStrBuffer(" "); + } + if(*pContent == NULL){ + pContent = NULL; + SegmentIndex++; + TitleFlag = TRUE; + } + /* + if (i>70){ + StrToNowStrBuffer(pContent); + pContent+=70 ; + }else{ + StrToNowStrBuffer(pContent); + pContent+=i ; + for ( k=0;k<(70-i);k++ ) //cyg ո + StrToNowStrBuffer(" "); + } + if(*pContent == NULL){ + pContent = NULL; + SegmentIndex++; + TitleFlag = TRUE; + } + */ + } + } + }else{ + if(TitleFlag==TRUE){ + StrToNowStrBuffer1("ͷ"); + for ( k=0;k<60+10;k++ ) //cyg ո + StrToNowStrBuffer(" "); + InputHistory.color[InputHistory.newNo]=TRUE; + pContent = SegmentBuf[SegmentIndex]; + TitleFlag = FALSE; + }else{ + if(pContent!=NULL){ + word = StrToNowStrBuffer2(pContent); + pContent+=word ; + if(word<70){ + for ( k=0;k<(80-word);k++ ){ + StrToNowStrBuffer(" "); + } + } + if(*pContent == NULL){ + pContent = NULL; + SegmentIndex++; + TitleFlag = TRUE; + } + } + } + } + }else{ + if( TitleFlag == TRUE ){ + GetKeyInputFocus(&SubBuffer); + StrToNowStrBuffer1("ݣ"); + for ( k=0;k<56+10;k++ ) + StrToNowStrBuffer(" "); + InputHistory.color[InputHistory.newNo]=TRUE; + TitleFlag = FALSE; + InputHistory.addNo = 0; + InputHistory.lockNo = InputHistory.newNo; + + } + } +} + +//************************************************ +//ʽ : λʽ +//شֵ : None +//************************************************ +void InputOnlineGmData( int x, int y, int Key ) +{ + int Changelineflag = 0; + int i; + + if ( InputHistory.newNo - InputHistory.nowNo <= 4) + GetKeyInputFocus(&SubBuffer); + else + pNowStrBuffer = NULL ; + + if (Key == 1) //ϼͷ + { + if (InputHistory.newNo >4 && InputHistory.nowNo ){ + InputHistory.nowNo -- ; + if (InputHistory.newNo - (InputHistory.nowNo+4) == 1 ){ + strcpy( InputHistory.str[ InputHistory.newNo ],SubBuffer.buffer); + SubBuffer.buffer[0] = NULL ; + } + } + } + if (Key == 2) // ¼ͷ + { + if (InputHistory.newNo >4){ + if (InputHistory.nowNo+4= 5) + InputHistory.nowNo = InputHistory.newNo -4; + }else{ + //SubBuffer.cursor + } + } + + for ( i=0;i<5;i++ ) // ܹ + { + if ((InputHistory.nowNo+i)!=InputHistory.newNo){ + if(InputHistory.color[InputHistory.nowNo+i]==FALSE) + StockFontBuffer( SubBuffer.x , y+300+(i*(30-5)) , FONT_PRIO_FRONT, 0 ,InputHistory.str[ InputHistory.nowNo+i ], 0 ); + else + StockFontBuffer( SubBuffer.x , y+300+(i*(30-5)) , FONT_PRIO_FRONT, 5 ,InputHistory.str[ InputHistory.nowNo+i ], 0 ); + } + } +} + +HANDLE GMHandle; +extern char szUser[],szPassword[]; +//************************************************ +//ʽ : ѯŵʽ +//شֵ : OL +//************************************************ +DWORD WINAPI DirThread(LPVOID param) +{ + ResultCode = -1; + char id[32], password[32]; + CopyMemory(id,szUser,32); + ecb_crypt("f;encor1c",id,32,DES_DECRYPT); + CopyMemory(password,szPassword,32); + ecb_crypt("f;encor1c",password,32,DES_DECRYPT); + + ResultCode = SendDirMsg( id,password ); + + switch(ResultCode) + { + case -200: + StockChatBufferLine("κⵥ¼!!",FONT_PAL_RED); + StockChatBufferLine("ⵥ!",FONT_PAL_RED); + ProNoValue = 0; + break; + case -400: + StockChatBufferLine("·!!",FONT_PAL_RED); + StockChatBufferLine("޷ѯⵥ!",FONT_PAL_RED); + break; + case -600: + StockChatBufferLine("ϻر޷!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case -800: + StockChatBufferLine("·ʱ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case 1: // ѯɹ + break; + case -999: + StockChatBufferLine("·æ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_RED); + break; + default: + StockChatBufferLine("Ǹʽڲ!!!",FONT_PAL_RED); + StockChatBufferLine("ⵥѯʧ!",FONT_PAL_RED); + break; + } +#ifdef _STONDEBUG_ //дonlinegm.log + if( ResultCode != 1 ){ + sprintf_s(inlogstr,"ѯʧܴ%d",ResultCode); + WriteInLog(inlogstr,filename); + } +#endif + CloseHandle(GMHandle); + ExitThread(0); + return 0L; +} + +//************************************************ +//ʽ : ɾŵʽ +//شֵ : OL +//************************************************ +DWORD WINAPI DeleteThread(LPVOID param) +{ + ResultCode = -1; + char id[32], password[32] ; + CopyMemory(id,szUser,32); + ecb_crypt("f;encor1c",id,32,DES_DECRYPT); + CopyMemory(password,szPassword,32); + ecb_crypt("f;encor1c",password,32,DES_DECRYPT); +#ifdef _STONDEBUG_ + inlogstr[0] = 0; +#endif + + ResultCode = SendDeleteMsg(id,password,Prodata[ProNoSelect].no); + + switch(ResultCode) + { + case 4: + StockChatBufferLine("·!!",FONT_PAL_RED); + StockChatBufferLine("޷ɾ򵥺!",FONT_PAL_RED); + break; + case 6: + StockChatBufferLine("ϻر޷!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case 8: + StockChatBufferLine("·ʱ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case 1: + StockChatBufferLine("ⵥɾ!",FONT_PAL_YELLOW); + Prodata[ProNoSelect].delflag = TRUE ; + TotalAddValue --; + break; + case -999: + StockChatBufferLine("·æ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_RED); + break; + default: + StockChatBufferLine("Ǹʽڲ!!!",FONT_PAL_RED); + StockChatBufferLine("򵥺ɾʧ!",FONT_PAL_RED); + break; + } +#ifdef _STONDEBUG_ //дonlinegm.log + if( ResultCode != 1){ + sprintf_s(inlogstr,"ɾʧܴ%d",ResultCode); + WriteInLog(inlogstr,filename); + } +#endif + + CloseHandle(GMHandle); + ExitThread(0); + return 0L; +} + +//************************************************ +//ʽ : Multithreadʽ +//شֵ : OL +//************************************************ +DWORD WINAPI OnlineGmThread(LPVOID param) +{ + ResultCode = -1; + char id[32], password[32] ,buf[50]; + CopyMemory(id,szUser,32); + ecb_crypt("f;encor1c",id,32,DES_DECRYPT); + CopyMemory(password,szPassword,32); + ecb_crypt("f;encor1c",password,32,DES_DECRYPT); +#ifdef _STONDEBUG_ + inlogstr[0] = 0; +#endif + + ResultCode = SendProblemMsg(id,password,DataBuffer,InputBuffer); + + switch(ResultCode) + { + case 4: + StockChatBufferLine("·!!",FONT_PAL_RED); + StockChatBufferLine("޷ͱ!",FONT_PAL_RED); + break; + case 6: + StockChatBufferLine("ϻر޷!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case 8: + StockChatBufferLine("·ʱ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case -9: + if(SendType==0){ + StockChatBufferLine("ÿηһⵥ",FONT_PAL_RED); + StockChatBufferLine("ʮлл...",FONT_PAL_RED); + }else{ + StockChatBufferLine("ÿη쳣ⵥ",FONT_PAL_RED); + StockChatBufferLine("һСʱлл...",FONT_PAL_RED); + } + break; + case -999: + StockChatBufferLine("·æ!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_RED); + break; + case 1: + sprintf_s(buf,"ⵥ%dͳ!",iReturnNo); + StockChatBufferLine( buf ,FONT_PAL_YELLOW); + TotalAddValue ++; + ResetFlag = TRUE ; // ֻгɹreset + DirFlag = TRUE ; + break; + default: + StockChatBufferLine("Ǹʽڲ!!!",FONT_PAL_RED); + StockChatBufferLine("򵥺Ŵʧ!",FONT_PAL_RED); + break; + } +#ifdef _STONDEBUG_ //дonlinegm.log + if( ResultCode != 1 ){ + sprintf_s(inlogstr,"ⵥ:%d ʧܴ:%d",SendType,ResultCode); + WriteInLog(inlogstr,filename); + } +#endif + CloseHandle(GMHandle); + ExitThread(0); + return 0L; +} + +extern int nServerGroup; +extern short selectServerIndex; +extern short onlinegmProcNo; +extern int sCharSide ; +//************************************************** +//ʽ: +//شֵ:0 ʾӴ 1 ʾ +//************************************************** +int iOnlineGmProc() +{ + int i , id ; + static DWORD dwPressTime; + static int btnId[50] , btnState[50] , HelpId[10] , HelpidState[10] ; + static int SureId[2]; + char buf[100]= "/0" ; // test + static ACTION *pActOnlineGmWnd = NULL; + static ACTION *pActSureWnd = NULL; + static struct tm nowTime; + time_t longTime; + DWORD PushdirTime; + static LPPAGE page; + static LPDESC desc; + static int desc_index,page_index; + int x, y; + if (onlinegmProcNo == 0) + { + // һӴ + if (pActOnlineGmWnd == NULL ) + { + x = (lpDraw->xSize - 600) / 2; + y = (lpDraw->ySize - 450) / 2; + + pActOnlineGmWnd = MakeWindowDisp(x,y,600,450,NULL,-1, FALSE); + + x = pActOnlineGmWnd->x; + y = pActOnlineGmWnd->y; + + if(ResetFlag==TRUE){ + InitOnlineGmInput(x, y); + InitOnlineGm(); + dwPressTime = 0; + for ( i = 0 ; i < sizeof(btnId)/sizeof(int) ; i++ ) + { + btnId[i] = 0; + btnState[i] = 0; + } + for ( i = 0 ; i < sizeof(HelpId)/sizeof(int) ; i++ ) + { + HelpId[i] = 0; + HelpidState[i] = 0; + } + time( &longTime ); + localtime_s(&nowTime, &longTime ); + wrongY = okY = nowTime.tm_year+1900 ; + /*//fix + wrongM = okM = nowTime.tm_mon+1 ; + wrongD = okD = nowTime.tm_mday ; + wrongH = okH = nowTime.tm_hour ; + */ + //reset + ProNoIndex = 0; + desc_index = 0; + page_index = 0; + PushKey = 3; // Զѯ + } + + } + else + { + x = pActOnlineGmWnd->x; + y = pActOnlineGmWnd->y; + + if (DeleteBtnFlag==FALSE) + { + id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + if(dwPressTime) + { + if( TimeGetTime()>(dwPressTime+100)) + { + for( i = 0 ; i < DEF_BUTTON_TOTAL ; i ++ ) + { + if(btnState[i]) + { + btnState[i] = 0; + switch (i) + { + case 0://ѯ + PushdirTime = TimeGetTime(); + if ( DirFlag==TRUE || (PushdirTime-LastTime)>5000 ){ //(ر)вѯͲڲ + LastTime = TimeGetTime(); + PushKey = 3; + DirFlag = FALSE; + } + break; + case 1://ɾ + if (ProNoSelectFlag){ //ҪѡijŲɾ + DeleteBtnFlag = TRUE ; + } + break; + case 2:// + DeathAction( pActOnlineGmWnd ); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 2; + return 0; + case 3:// + InitOnlineGmInput(x, y); break; + case 4://ע + DeathAction( pActOnlineGmWnd ); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 1; + return 0; + case 5://ر + ResetFlag = TRUE; + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + return 1 ; + case 6://ѶϢϾ + if(ProNoValue){ + PushKey = 1; + } + break; + case 7://ѶϢ¾ + if(ProNoValue){ + PushKey = 2; + } + break; + case 8:PutKey = 1; break;//Ͼ + case 9:PutKey = 2; break;//¾ + case 10://Ͼ + okM--; + if (okM<=0){ //fix + okY--; + okM=12; + } + break; + case 11://¾ + okM++; + if (okM>12){ + okY++; + okM=1; + } + break; + case 12://Ͼ + okD--; + if (okD<=0) okD = 31 ; //fix + break; + case 13://¾ + okD++; + if (okD>31) okD = 1; + break; + case 14://ʱϾ + okH--; + if (okH<0) okH = 23; + break; + case 15://ʱ¾ + okH++; + if (okH>23) okH=0; + break; + case 16://Ͼ + wrongM--; + if (wrongM<=0){ //fix + wrongY--; + wrongM=12; + } + break; + case 17://¾ + wrongM++; + if (wrongM>12){ + wrongY++; + wrongM=1; + } + break; + case 18://Ͼ + wrongD--; + if (wrongD<=0) wrongD = 31; //fix + break; + case 19://¾ + wrongD++; + if (wrongD > 31) wrongD = 1; + break; + case 20://ʱϾ + wrongH--; + if (wrongH<0) wrongH = 23; + break; + case 21://ʱ¾ + wrongH++; + if (wrongH>23) wrongH = 0; + break; + case 22://һϾ + ClassIndex -- ; + ClassIndex1 = 0 ; + ClassIndex2 = 0 ; + if (ClassIndex<0) ClassIndex = DEF_CLASS_TOTAL-1; + break; + case 23://һ¾ + ClassIndex ++ ; + ClassIndex1 = 0 ; + ClassIndex2 = 0 ; + if (ClassIndex==DEF_CLASS_TOTAL) ClassIndex = 0; + break; + case 24://Ͼ + ClassIndex1 -- ; + ClassIndex2 = 0 ; + if (ClassIndex==1){ // һ + if (ClassIndex1<0) ClassIndex1 = DEF_C1_TOTAL-1; + }else{ + if (ClassIndex1<0) ClassIndex1 = DEF_C2_TOTAL-1; + } + break; + case 25://¾ + ClassIndex1 ++ ; + ClassIndex2 = 0 ; + if (ClassIndex==1){ // һ + if (ClassIndex1==DEF_C1_TOTAL) ClassIndex1=0; + }else{ + if (ClassIndex1==DEF_C2_TOTAL) ClassIndex1=0; + } + break; + case 26://Ͼ + ClassIndex2 -- ; + switch (ClassIndex1) + { + case 0:if (ClassIndex2<0) ClassIndex2=2;break; + case 1:if (ClassIndex2<0) ClassIndex2=2;break; + case 2:if (ClassIndex2<0) ClassIndex2=4;break; + case 3:if (ClassIndex2<0) ClassIndex2=1;break; + case 4:if (ClassIndex2<0) ClassIndex2=1;break; + case 5:if (ClassIndex2<0) ClassIndex2=2;break; + case 10:if (ClassIndex2<0) ClassIndex2=2;break; + default: ClassIndex2=0;break; + } + break; + case 27://¾ + ClassIndex2 ++ ; + switch (ClassIndex1) + { + case 0:if (ClassIndex2>2) ClassIndex2=0;break; + case 1:if (ClassIndex2>2) ClassIndex2=0;break; + case 2:if (ClassIndex2>4) ClassIndex2=0;break; + case 3:if (ClassIndex2>1) ClassIndex2=0;break; + case 4:if (ClassIndex2>1) ClassIndex2=0;break; + case 5:if (ClassIndex2>2) ClassIndex2=0;break; + case 10:if (ClassIndex2>2) ClassIndex2=0;break; + default: ClassIndex2=0;break; + } + break; + } + } + } + dwPressTime = 0; + } + } + else + { + if ( 0 <= id && id < DEF_BUTTON_TOTAL ) + { + btnState[id] = 1; + dwPressTime = TimeGetTime(); + } + } + }else{ + if (pActSureWnd == NULL){ + pActSureWnd = MakeWindowDisp( 200+100+20 , 100-63 , 4-1 , 6-4 , NULL , -1); + } + else if(pActSureWnd->hp > 0) + { + StockDispBuffer(416+15+15,100,DISP_PRIO_MENU,ONLINEGM_YES_OR_NO,1); + MakeHitBox( 338+15+15,100,405+15+15,124, DISP_PRIO_BOX2 ); + MakeHitBox( 426+15+15,100,494+15+15,124, DISP_PRIO_BOX2 ); + selGraId( SureId, sizeof( SureId )/sizeof( int ) ); + SureId[0] = StockDispBuffer( 372+15+15 , 112 , DISP_PRIO_IME3, ONLINEGM_SURE_U , 1); + SureId[1] = StockDispBuffer( 460+15+15 , 112 , DISP_PRIO_IME3, ONLINEGM_CHANCEL , 1); + if(Prodata[ProNoSelect].delflag == TRUE){ + sprintf_s(buf,"˱ʵɾ"); + StockFontBuffer( 365+15+15 , 81 , FONT_PRIO_FRONT, 2 , buf , 0 ); + }else{ + sprintf_s(buf,"ɾ %s ?",Prodata[ProNoSelect].no); + StockFontBuffer( 355+15+15 , 81 , FONT_PRIO_FRONT, 5 , buf , 0 ); + } + + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureId[0]){ //ȷ + if(Prodata[ProNoSelect].delflag == FALSE){ + DWORD dwThreadID,dwThrdParam = 1; + GMHandle = CreateThread(NULL, 0, DeleteThread,&dwThrdParam,0,&dwThreadID); + if(GMHandle == NULL) + { + StockChatBufferLine("ҵϵͳԴѲ!!",FONT_PAL_RED); + StockChatBufferLine("򵥺ɾʧ!",FONT_PAL_RED); + ResetFlag = TRUE; + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + return 1; + } + } + DeathAction( pActSureWnd); + pActSureWnd = NULL; + DeleteBtnFlag = FALSE ; + } + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureId[1]){ //ȡ + DeathAction( pActSureWnd); + pActSureWnd = NULL; + DeleteBtnFlag = FALSE ; + } + } + } + if (pActOnlineGmWnd->hp > 0) + { + x = pActOnlineGmWnd->x; + y = pActOnlineGmWnd->y; + if(PushKey != 3){ + ShowProblemNo(x, y, PushKey); + }else{ //ѯ + for( i=0;ixSize - 7*64)/2; + y = (lpDraw->ySize - 8*48)/2; + + pActOnlineGmWnd = MakeWindowDisp( x , y , 4+3 , 6+2 ,NULL,0, FALSE);//( 210 , 120, 10 , 10 , NULL , 0 ); + pNowStrBuffer = NULL ; + } + else if (pActOnlineGmWnd->hp > 0) + { + x = pActOnlineGmWnd->x; + y = pActOnlineGmWnd->y; + page = &ProHelp_page[page_index]; + desc = Prohelp_Index[page_index]+page->desc_index; + desc_index = page->desc_index; + + id = selGraId( HelpId, sizeof( HelpId )/sizeof( int ) ); + if (HelpidState[0]>=0) + HelpId[0] = StockDispBuffer( x+207+32-160, y+352, DISP_PRIO_IME3, CG_FIELD_HELP_PREPAGE+btnState[1], 2); + else + StockDispBuffer( x+207+32-160, y+352, DISP_PRIO_IME3, CG_FIELD_HELP_PREPAGE+btnState[1], 1); + + if (HelpidState[1]>=0) + HelpId[1] = StockDispBuffer( x+277+32-100, y+352, DISP_PRIO_IME3, CG_FIELD_HELP_NEXTPAGE+btnState[2], 2); + else + StockDispBuffer( x+277+32-100, y+352, DISP_PRIO_IME3, CG_FIELD_HELP_NEXTPAGE+btnState[2], 1); + + HelpId[2] = StockDispBuffer( x+347+32-40, y+352, DISP_PRIO_IME3, CG_FIELD_HELP_EXIT+btnState[3], 2); + + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == HelpId[0]){ //һҳ + if (page_index){ + page_index--; + page = &ProHelp_page[page_index]; //ָһҳ + desc_index = page->desc_index; + desc = Prohelp_Index[page_index]+desc_index;//ָһҳdescͷ + } + } + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == HelpId[1]){ //һҳ + if (page_index < 4-1) + { + page_index++; + page = &ProHelp_page[page_index]; //ָһҳ + desc_index = page->desc_index; + desc = Prohelp_Index[page_index]+desc_index;//ָһҳdescͷ + } + } + HelpidState[0] = page_index==0 ? -2 : 0 ; + HelpidState[1] = page_index==4-1 ? -2 : 0 ; + + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == HelpId[2]) + { + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 0 ; + ResetFlag = FALSE; + return 0 ; + } + for( i = 0; i < page->desc_num; i++){ + StockFontBuffer( x+30+5 , y+i*25+10, FONT_PRIO_FRONT, desc->color, desc->description, 0); + desc++; + } + } + } + else if (onlinegmProcNo == 2) //cyg ׼͵ȷӴ + { + if (pActOnlineGmWnd==NULL){ + x = (lpDraw->xSize - 5*64)/2; + y = (lpDraw->ySize - 5*48)/2; + + pActOnlineGmWnd = MakeWindowDisp( x , y , 5 , 5 ,NULL,0, FALSE); + pNowStrBuffer = NULL ; + } + else if (pActOnlineGmWnd->hp > 0) + { + x = pActOnlineGmWnd->x; + y = pActOnlineGmWnd->y; + MakeHitBox( x + 36,y + 238-85-35,x + 40,y + 238-85+35, DISP_PRIO_BOX ); + MakeHitBox( x + 156+18,y + 238-85-35,x + 156+18,y + 238-85+35, DISP_PRIO_BOX ); + id = selGraId( btnId, sizeof( btnId )/sizeof( int ) ); + int SureBtn[2]; + SureBtn[0] = StockDispBuffer( x + 70 , y + 250-85+35 , DISP_PRIO_IME3, ONLINEGM_SURE_U , 1); + SureBtn[1] = StockDispBuffer( x + 190+18 , y + 250-85+35 , DISP_PRIO_IME3, ONLINEGM_CHANCEL , 1); + sprintf_s( buf ,"ѶϢ->"); + StockFontBuffer( x + 20 , y+ 20+60 , FONT_PRIO_FRONT, 4 , buf , 0 ); + + if( TotalAddValue >= DEF_MAX_ADD_VALUE ){ // ûд󽨵 + sprintf_s( buf ,"ⵥѴ20!!"); + StockFontBuffer( x + 235 , y + 150 , FONT_PRIO_FRONT, 4 , buf , 0 ); + sprintf_s( buf ,"ɾⵥлл",TotalAddValue ); + StockFontBuffer( x + 235 , y + 185 , FONT_PRIO_FRONT, 4 , buf , 0 ); + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureBtn[0]) + { + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 0 ; + ResetFlag = FALSE; + return 0 ; + } + }else{ + if (ClassIndex==1){ + sprintf_s( buf ,"-> %s",ProblemClass[ClassIndex]); + StockFontBuffer( x + 20 , y + 20+10, FONT_PRIO_FRONT, 1 , buf , 0 ); + sprintf_s( buf ,"-> %s",ProblemC1[ClassIndex1]); + StockFontBuffer( x + 20 , y + 20+35, FONT_PRIO_FRONT, 1 , buf , 0 ); + }else{ + sprintf_s( buf ,"-> %s",ProblemClass[ClassIndex]); + StockFontBuffer( x + 20 , y + 20+10, FONT_PRIO_FRONT, 1 , buf , 0 ); + sprintf_s( buf ,"-> %s",ProblemC2[ClassIndex1]); + StockFontBuffer( x + 20 , y + 20+35, FONT_PRIO_FRONT, 1 , buf , 0 ); + switch (ClassIndex1) + { + case 0: sprintf_s( buf,"ϸ-> %s",ProblemC2_1[ClassIndex2] );break; + case 1: sprintf_s( buf,"ϸ-> %s",ProblemC2_2[ClassIndex2] );break; + case 2: sprintf_s( buf,"ϸ-> %s",ProblemC2_3[ClassIndex2] );break; + case 3: sprintf_s( buf,"ϸ-> %s",ProblemC2_4[ClassIndex2] );break; + case 4: sprintf_s( buf,"ϸ-> %s",ProblemC2_5[ClassIndex2] );break; + case 5: sprintf_s( buf,"ϸ-> %s",ProblemC2_6[ClassIndex2] );break; + case 10: sprintf_s( buf,"ϸ-> %s",ProblemC2_7[ClassIndex2] );break; + default: buf[0] = '\0'; + } + StockFontBuffer( x + 220-25 , y + 120+60, FONT_PRIO_FRONT, 1 , buf , 0 ); + sprintf_s( buf ,"-> %4d%02d%02d%02dʱ",okY,okM,okD,okH); + StockFontBuffer( x + 220-25 , y + 120+85, FONT_PRIO_FRONT, 1 , buf , 0 ); + sprintf_s( buf ,"-> %4d%02d%02d%02dʱ",wrongY,wrongM,wrongD,wrongH ); + StockFontBuffer( x + 220-25 , y + 120+110, FONT_PRIO_FRONT, 1 , buf , 0 ); + } + + if( lstrlen(InputHistory.str[InputHistory.lockNo+1]) == 0 && lstrlen(SubBuffer.buffer) == 0 ){ + sprintf_s( buf ,""); + StockFontBuffer( x + 20 , y + 120, FONT_PRIO_FRONT, 4 , buf , 0 ); + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureBtn[0]) + { + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 0 ; + ResetFlag = FALSE; + return 0 ; + } + }else if(ClassIndex==0&&(!okY||!okM||!okD||!wrongY||!wrongM||!wrongD)){ //fix + sprintf_s( buf ,"д[][]"); + StockFontBuffer( x + 280-10+2 , y + 260 , FONT_PRIO_FRONT, 4 , buf , 0 ); + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureBtn[0]) + { + DeathAction( pActOnlineGmWnd); + pActOnlineGmWnd = NULL; + onlinegmProcNo = 0 ; + ResetFlag = FALSE; + return 0 ; + } + }else{ + if((mouse.onceState & MOUSE_LEFT_CRICK) && HitDispNo == SureBtn[0]) + { + ResetFlag = FALSE; + ContentBuf[0] = '\0'; + for ( i=0;ih_addr_list); + } + return TRUE; + +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/pattern.cpp b/石器时代8.5客户端最新源代码/石器源码/system/pattern.cpp new file mode 100644 index 0000000..6f2a671 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/pattern.cpp @@ -0,0 +1,270 @@ +/************************/ +/* pattern.cpp */ +/************************/ + +/* ENT : ACTION *a0 , + : ???????LT???????????LT?? + : ???????????????????????????? + + RET : ????????? + : ?????? +*/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/t_music.h" + + + +#ifdef _NPC_PICTURE +extern BOOL g_bUseAlpha; +void picture_play( ACTION *a0 ) +{ + //int i,j; + int pictable[9]={100388,100841,101178,100854,101570,100353,101759,101424,101489}; + if( a0->picture != 0 ){ + int picture1 = ((((a0->picture)&0xff000000)>>24)&0x000000ff); + int picture2 = ((((a0->picture)&0x00ff0000)>>16)&0x000000ff); + int picture3 = ((((a0->picture)&0x0000ff00)>>8 )&0x000000ff); + int picture4 = ( (a0->picture)&0x000000ff ); + //a0->anim_no = ANIM_WALK; + if( picture1 == 1 ){//ϱ + if( a0->anim_chr_no == 101936 ){ + a0->anim_chr_no = 101863; + return; + } + else if( a0->anim_chr_no == 101863 ){ + a0->anim_chr_no = pictable[a0->picturetemp]; + } + else + a0->anim_chr_no = 101863; + ++a0->picturetemp; + if(a0->picturetemp == 9 ) + a0->picturetemp = 0; + } + else if( picture1 == 2 ){//ijͼ + if( a0->anim_chr_no != pictable[picture2] ){ + if( a0->anim_chr_no == 101863 ) + a0->anim_chr_no = pictable[a0->picturetemp]; + else + a0->anim_chr_no = 101863; + } + else{ + if( a0->anim_no == 0 )//趨 + a0->anim_no = 3; + else + a0->anim_no = 0; + } + ++a0->picturetemp; + if(a0->picturetemp == 9 ) + a0->picturetemp = 0; + } + else if( picture1 == 3 ){ + if(g_bUseAlpha) a0->anim_chr_no = 101805; else a0->anim_chr_no = 101858; + a0->picture = (((1)<<24)&0xff000000) + |(((picture2)<<16)&0x00ff0000) + |(((picture3)<< 8)&0x0000ff00) + |( (picture4) &0x000000ff); + } + + } +} +#endif + +/*---------- ????????? ----------*/ +// Return 1:˴˶( ظŵ״ ) +// Return 0:Ŵ˶ +int pattern( ACTION *a0, int anim_spd, int loop_flg) +{ + ANIMLIST *ptAnimlist; + FRAMELIST *ptFramelist; + int i; + short dx,dy; + int BmpNo; + U4 chrNo; + extern int getCharType(ACTION *ptAct); + if(getCharType(a0)){ + if(ATR_PAT_NO(a0)){ + ATR_PAT_BAK_NO(a0) = ATR_PAT_NO(a0); + ATR_PAT_NO(a0) = 0; + } + return 0; + }else{ + if(!ATR_PAT_NO(a0) && ATR_PAT_BAK_NO(a0)) ATR_PAT_NO(a0) = ATR_PAT_BAK_NO(a0); + } + if(ATR_CHR_ACT_OLD(a0) != ATR_CHR_ACT(a0) || + ATR_CHR_ANG(a0) != ATR_CHR_ANG_OLD(a0) || + ATR_CHR_NO(a0) != ATR_CHR_NO_OLD(a0)){ + ATR_CHR_NO_OLD(a0) = ATR_CHR_NO(a0); /*????????????*/ + ATR_CHR_ACT_OLD(a0) = ATR_CHR_ACT(a0); /*??h????*/ + ATR_CHR_ANG_OLD(a0) = ATR_CHR_ANG(a0); /*???????*/ + ATR_CHR_TIM(a0) = 0;//frame counterΪһ + ATR_CHR_CNT(a0) = 0;//ĵڼͼ + } + if(ATR_CHR_TIM(a0)){ + ATR_CHR_TIM(a0)--; //frame counterһ + return 0; + } + if(ATR_CHR_NO(a0) <= CG_INVISIBLE){ + ATR_PAT_NO(a0) = 0; //ָΪ0ͼ +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 0; + } + if(ATR_CHR_NO(a0) < SPRSTART){ //sprite + realGetNo( ATR_CHR_NO(a0) , (U4 *)&BmpNo ); + realGetPos( BmpNo , &dx, &dy); + ATR_PAT_NO(a0) = BmpNo; //BMPͼ +#ifdef _FIX_CG_ATR_ICON + if (ATR_CHR_NO(a0)>= CG_ATR_ICON_EARTH_BATTLE && ATR_CHR_NO(a0)<=CG_ATR_ICON_WIND_BATTLE){ + ATR_CHR_H_POS(a0) = dx - 20; //X + }else{ + ATR_CHR_H_POS(a0) = dx; //X + } +#else + ATR_CHR_H_POS(a0) = dx; //X +#endif + ATR_CHR_V_POS(a0) = dy; //Y + ATR_CHR_TIM(a0)=0x7fffffff; + //cary + if( ATR_CHR_ACT(a0) == ANIM_ATTACK && ATR_CHR_CNT(a0) == 0){ + ATR_CHR_TIM(a0)=0; + ATR_HIT(a0) = 10000; + ATR_CHR_CNT(a0) = 1; +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 0; + } + ATR_CHR_CNT(a0) = 0; + ATR_CHR_ACT(a0) = ANIM_STAND; + if( loop_flg == ANM_NO_LOOP){ +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 1; + } + //cary end +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 0; + } + if(ATR_CHR_NO(a0) > SPRSTART + mxSPRITE){ +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 0; //spriteķΧ + } + chrNo = ATR_CHR_NO(a0) - SPRSTART; + ptAnimlist = SpriteData[chrNo].ptAnimlist; + if( SpriteData[chrNo].animSize == 0 ){ +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + return 0; //޶ + } + //ѡҪķͶ + for(i=0 ; i < SpriteData[chrNo].animSize; i++){ + if( ATR_CHR_ANG(a0) == ptAnimlist[i].dir && ptAnimlist[i].no == ATR_CHR_ACT(a0) ) + break; + } + if( i >= SpriteData[chrNo].animSize ){ + // shan remark + // i = 0; + for( int sh_i=0 ; sh_i < SpriteData[chrNo].animSize; sh_i++){ + if( ATR_CHR_ANG(a0) == ptAnimlist[sh_i].dir && ptAnimlist[sh_i].no == ANIM_STAND){ + i = sh_i; + break; + }else{ + i = 0; + } + } + } + ptFramelist = ptAnimlist[i].ptFramelist; + if(anim_spd) //ָٶ + ATR_CHR_TIM(a0) = anim_spd; + else + ATR_CHR_TIM(a0) = ptAnimlist[i].dtAnim; +#ifdef _NPC_PICTURE + if( a0->picture != 0 ){ + int pictable[9]={100388,100841,101178,100854,101570,100353,101759,101424,101489}; + /*if( (((a0->picture&0xff000000)>>24) & 0x000000ff) == 1 + || (((a0->picture&0xff000000)>>24) & 0x000000ff) == 3 + || ( (((a0->picture&&0xff000000)>>24) & 0x000000ff) == 2 + && ( a0->anim_chr_no != pictable[(((a0->picture&0x00ff0000)>>16)&0x000000ff)] ) ) ) + ATR_CHR_TIM(a0) = 1;//npcٶȵ + */ + if( a0->anim_chr_no != pictable[(((a0->picture&0x00ff0000)>>16)&0x000000ff)] + || (((a0->picture&0xff000000)>>24) & 0x000000ff) == 1 + || (((a0->picture&0xff000000)>>24) & 0x000000ff) == 3 ) + if( a0->anim_chr_no != 101805 && a0->anim_chr_no != 101858 && a0->anim_chr_no != 101936 ) + ATR_CHR_TIM(a0) = 1;//npcٶȵ + } +#endif + if((U4)ATR_CHR_CNT(a0) >= ptAnimlist[i].frameCnt){ //???????????? +#ifdef _NPC_PICTURE + picture_play(a0); +#endif + if(loop_flg == ANM_NO_LOOP){ //????? + ATR_CHR_TIM(a0) = 255; + return 1; //???????? + } else + ATR_CHR_CNT(a0) = 0; //Id??? + } + //?????? + if( ptFramelist[ATR_CHR_CNT(a0)].SoundNo != 0 ){ + if(ptFramelist[ATR_CHR_CNT(a0)].SoundNo < 10000) + play_se( ptFramelist[ATR_CHR_CNT(a0)].SoundNo, ATR_H_POS(a0), ATR_V_POS(a0) ); + else + ATR_HIT(a0) = ptFramelist[ATR_CHR_CNT(a0)].SoundNo; + } +#ifdef _PROFESSION_ADDSKILL + else{ + if(ATR_CHR_NO(a0) >= 101769 && ATR_CHR_NO(a0) <= 101797){ + int soundnum = 0; + switch(ATR_PAT_NO(a0)){ + case 156+OLD_GRAPHICS_START: + soundnum = 390;break;//ˮ390 + case 193+OLD_GRAPHICS_START: + soundnum = 390;break;//ˮ390 + case 304+OLD_GRAPHICS_START: + soundnum = 327;break;//ؽ + case 341+OLD_GRAPHICS_START: + soundnum = 327;break;//ؽ + case 231+OLD_GRAPHICS_START: + soundnum = 395;break;// + case 268+OLD_GRAPHICS_START: + soundnum = 268;break;// + case 380+OLD_GRAPHICS_START: + soundnum = 154;break;// + case 417+OLD_GRAPHICS_START: + soundnum = 154;break;// + case 75+OLD_GRAPHICS_START: + soundnum = 324;break;//ƽ + case 97+OLD_GRAPHICS_START: + soundnum = 324;break;//ƽ + case 117+OLD_GRAPHICS_START: + soundnum = 385;break;//Ȼ + case 137+OLD_GRAPHICS_START: + soundnum = 385;break;//Ȼ + case 60+OLD_GRAPHICS_START: + soundnum = 388;break;//Ȼ + } + play_se(soundnum,ATR_H_POS(a0),ATR_V_POS(a0)); + } + } +#endif + ATR_PAT_NO(a0) = ptFramelist[ATR_CHR_CNT(a0)].BmpNo; //???k???? + realGetPos(ptFramelist[ATR_CHR_CNT(a0)].BmpNo, &dx, &dy); //???????????? + ATR_CHR_H_POS(a0) = ptFramelist[ATR_CHR_CNT(a0)].PosX + dx; //?????????? + ATR_CHR_V_POS(a0) = ptFramelist[ATR_CHR_CNT(a0)].PosY + dy; //?????????? + ATR_CHR_CNT(a0)++; + ATR_CHR_TIM(a0)--; + return 0; + } + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/pc.cpp b/石器时代8.5客户端最新源代码/石器源码/system/pc.cpp new file mode 100644 index 0000000..f35c688 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/pc.cpp @@ -0,0 +1,1681 @@ +#include "../systeminc/version.h" +#include"../systeminc/system.h" +#include"../systeminc/action.h" +#include"../systeminc/pc.h" +#include"../systeminc/character.h" +#include"../systeminc/map.h" +#include"../systeminc/tool.h" +#include"../systeminc/anim_tbl.h" +#include"../systeminc/loadsprbin.h" +#include"../systeminc/netmain.h" +#include"../systeminc/lssproto_cli.h" +#include"../systeminc/savedata.h" +#include"../systeminc/menu.h" +#include"../systeminc/field.h" +#include"../systeminc/login.h" +#include"../systeminc/netproc.h" + +PC pc; +short maxPcNo; +short selectPcNo; +short prSendMode = 0; +short prSendFlag = 0; + +short jbSendFlag; +short duelSendFlag; + +int loginDp; + +short helpFlag = 0; + +short tradeFlag = 0; +short tradeStatus = 0; + +PET pet[MAX_PET]; + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +PROFESSION_SKILL profession_skill[MAX_PROFESSION_SKILL]; +#endif + +MAGIC magic[MAX_MAGIC]; + +#ifdef MAX_AIRPLANENUM +PARTY party[MAX_AIRPLANENUM]; +#else +PARTY party[MAX_PARTY]; +#endif +short partyModeFlag = 0; + + +CHARLISTTABLE chartable[MAXCHARACTER]; + +ADDRESS_BOOK addressBook[MAX_ADR_BOOK]; + +BATTLE_RESULT_MSG battleResultMsg; + +PET_SKILL petSkill[MAX_PET][MAX_SKILL]; + + +char newCharacterName[CHAR_NAME_LEN+1]; +int newCharacterGraNo; +int newCharacterFaceGraNo; +int newCharacterVit; +int newCharacterStr; +int newCharacterTgh; +int newCharacterDex; +int newCharacterEarth; +int newCharacterWater; +int newCharacterFire; +int newCharacterWind; +int newCharacterHomeTown; + +template +inline void swap(T &T1, T &T2) +{ + T TTemp; + + TTemp = T1; + T1 = T2; + T2 = TTemp; +} + +void swap(char *a, char *b) +{ + char tmp[256]; + + if(strlen(a) > 255 || strlen(b) > 255) + return; + + strcpy(tmp, a); + strcpy(a, b); + strcpy(b, tmp); +} + +//void swapInteger(int *, int *); +//void swapShort(short *, short *); +//void swapString(char *, char *); + +void initPcAll(void) +{ + int i; + memset(&pc, 0, sizeof(pc)); + memset(&pet, 0, sizeof(pet)); + memset(&magic, 0, sizeof(magic)); + memset(&party, 0, sizeof(party)); + memset(&petSkill, 0, sizeof(petSkill)); + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + memset(&profession_skill, 0, sizeof(profession_skill)); +#endif + + pc.mailPetNo = -1; +#ifdef _MORECHARACTERS_ + extern int ﵱǰҳ; + getUserSetting(selectPcNo+ﵱǰҳ*2); +#else + getUserSetting(selectPcNo); +#endif + + partyModeFlag = 0; + sPetStatFlag = 1; + +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + party[i].useFlag = 0; + party[i].id = 0; + party[i].ptAct = NULL; + } + + +#if 1 + pc.faceGraNo = newCharacterFaceGraNo; + pc.dp = loginDp; +#endif + + // shan 2002/01/18 + { + FILE *fp; + char filename[255]; + char vTemp[32]; + + sprintf_s(filename, "map\\bgm%d.dat", sCharSide); + if((fp = fopen(filename, "rb+"))!=NULL) + { + fread(&vTemp, sizeof(char), 2, fp); + fclose (fp); + fMapBgm = atoi(vTemp); + } + } +#ifdef _STREET_VENDOR + pc.iOnStreetVendor = 0; +#endif +#ifdef _MOVE_SCREEN + pc.bCanUseMouse = FALSE;//TRUE; + pc.bMoveScreenMode = FALSE; + iScreenMoveX = 0; + iScreenMoveY = 0; +#endif +#ifdef _THEATER + pc.iTheaterMode = 0; + pc.iSceneryNumber = -1; +#endif +#ifdef _SFUMATO + pc.sfumato = 0; // Ⱦͼɫ +#endif +} + + +void initPc(void) +{ + int walk = 0, height = 0; + int i; +#ifndef _STONDEBUG_ + createPc(pc.graNo, nowGx, nowGy, pc.dir); +#else + if(offlineFlag) + { + createPc(SPR_pet004, nowGx, nowGy, pc.dir); + } + else + { + createPc(pc.graNo, nowGx, nowGy, pc.dir); + } +#endif + + if((pc.status & CHR_STATUS_W)) + { + walk = 1; + } + if((pc.status & CHR_STATUS_H)) + { + height = 1; + } +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +// #ifdef _GM_IDENTIFY // Rog ADD GMʶ +// setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height, pc.profession_class, pc.profession_level, pc.profession_exp, pc.profession_skill_point, pc.ptAct->gm_name); +// setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height, pc.profession_class, pc.profession_level, pc.profession_skill_point, pc.ptAct->gm_name); +// #else +// setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height, pc.profession_class, pc.profession_level, pc.profession_exp, pc.profession_skill_point); +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height, pc.profession_class, pc.profession_level, pc.profession_skill_point , pc.herofloor); +#else + setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height, pc.profession_class, pc.profession_level, pc.profession_skill_point); +#endif +// #endif +#else + setPcParam(pc.name, pc.freeName, pc.level, pc.ridePetName, pc.ridePetLevel, pc.nameColor, walk, height); +#endif + +#ifdef _FRIENDCHANNEL +// strcpy(pc.chatRoomNum,""); +#endif + + if(pc.ptAct != NULL) + { + pc.ptAct->hp = pc.hp; + pc.ptAct->maxHp = pc.maxHp; + + // ??ѩ???????????????? +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for(i = 0; i < MAX_PARTY; i++) +#endif + { + if(party[i].useFlag != 0 && party[i].id == pc.id) + { + party[i].ptAct = pc.ptAct; + break; + } + } + } + + + prSendMode = 0; + prSendFlag = 0; + jbSendFlag = 0; + duelSendFlag = 0; + helpFlag = 0; + +#ifdef _NPC_MAGICCARD + for(i=0;i<20;i++){ + bShowflag[i] = FALSE; + iShowdamage[i]=0; + iOffsetY[i] = 0; + iPosition[i] = 0; + } +#endif +} + + +// PC???? +void createPc(int graNo, int gx, int gy, int dir) +{ + pc.graNo = graNo; + pc.dir = dir; + if(pc.ptAct == NULL) + { + pc.ptAct = createCharAction(graNo, gx, gy, dir); + if(pc.ptAct != NULL) + { + pc.ptAct->atr |= ACT_ATR_TYPE_PC; + } + } + else + { + setPcGraNo(graNo, dir); + setPcWarpPoint(gx, gy); + setPcPoint(); + } +} + + +// PC??????? +void resetPc(void) +{ + int i; + + if(pc.ptAct != NULL) + { +#ifdef _ITEM_FIREWORK + if (((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[0]) + { + DeathAction(((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[0]); + ((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[0] = NULL; + } + if (((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[1]) + { + DeathAction(((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[1]); + ((CHAREXTRA*)pc.ptAct->pYobi)->pActFirework[1] = NULL; + } +#endif +#ifdef _NPC_MAGICCARD + for(i=0;i<4;i++){ + if (((CHAREXTRA*)pc.ptAct->pYobi)->pActMagiccard[i]){ + DeathAction(((CHAREXTRA*)pc.ptAct->pYobi)->pActMagiccard[i]); + ((CHAREXTRA*)pc.ptAct->pYobi)->pActMagiccard[i] = NULL; + } + } +#endif +#ifdef _THEATER + for (i = 0; i < 5; i++) + { + if (pc.pActNPC[i]) + { + DeathAction(pc.pActNPC[i]); + pc.pActNPC[i] = NULL; + } + } +#endif + DeathAction(pc.ptAct); + pc.ptAct = NULL; + } + + // ???????????? + delPcLeader(); +} + + +// PC?????????k?@e +void setPcGraNo(int graNo, int dir) +{ + pc.graNo = graNo; + pc.dir = dir; + + if(pc.ptAct == NULL) + return; + + pc.ptAct->anim_chr_no = graNo; + pc.ptAct->anim_ang = dir; +#ifdef _SFUMATO + pc.ptAct->sfumato = pc.sfumato; // Ⱦͼɫ +#endif +} + + +// PC???ID?@e +void setPcId(int id) +{ + pc.id = id; +} + + +// PC??????I@e +void setPcWarpPoint(int gx, int gy) +{ +// if(pc.ptAct == NULL) +// return; + + setWarpMap(gx, gy); +} + + +// PC???????t?i??? +void setPcPoint(void) +{ + if(pc.ptAct == NULL) + return; + + pc.ptAct->mx = nowX; + pc.ptAct->my = nowY; + pc.ptAct->gx = nowGx; + pc.ptAct->gy = nowGy; + pc.ptAct->vx = nowVx; + pc.ptAct->vy = nowVy; + pc.ptAct->nextGx = nextGx; + pc.ptAct->nextGy = nextGy; + +} + + +// PC???????@e +void setPcDir(int dir) +{ + pc.dir = dir; + + if(pc.ptAct == NULL) + return; + + pc.ptAct->anim_ang = dir; +} + + +// ???????@e +void setPcAction(int act) +{ + if(pc.ptAct == NULL) + return; + + pc.ptAct->anim_no = act; + if(pc.ptAct->anim_no != ANIM_WALK) + { + pc.ptAct->anim_no_bak = -1; + } +} + +#ifdef __EMOTION +void setPcEmotion(int emotion) +{ + CHAREXTRA *ext; + if(pc.ptAct == NULL) + return; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + if(ext->ptActEmotion){ + DeathAction(ext->ptActEmotion); + ext->ptActEmotion = NULL; + } + ext->ptActEmotion = + createCommmonEffectAction(emotion, pc.ptAct->gx, pc.ptAct->gy, 0, 0, DISP_PRIO_CHAR); +} +#endif + +// ????????֢tx +int getPcAction(void) +{ + if(pc.ptAct == NULL) + return -1; + + return pc.ptAct->anim_no; +} + +#ifdef _CHANNEL_MODIFY +extern int TalkMode; +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +// #ifdef _GM_IDENTIFY // Rog ADD GMʶ +// void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height, int profession_class, int profession_level, int profession_exp, int profession_skill_point , char *gm_name) +// void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height, int profession_class, int profession_level, int profession_skill_point , char *gm_name) +// #else +// void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height, int profession_class, int profession_level, int profession_exp, int profession_skill_point) +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height, int profession_class, int profession_level, int profession_skill_point , int herofloor) +#else + void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height, int profession_class, int profession_level, int profession_skill_point) +#endif +// #endif +#else + void setPcParam(char *name, char *freeName, int level, char *petname, int petlevel, int nameColor, int walk, int height) +#endif +{ + int nameLen; + int freeNameLen; + int petnameLen; +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + int gmnameLen; +#endif + nameLen = strlen(name); + if(nameLen <= CHAR_NAME_LEN) + { + strcpy(pc.name, name); + } + + freeNameLen = strlen(freeName); + if(freeNameLen <= CHAR_FREENAME_LEN) + { + strcpy(pc.freeName, freeName); + } + + pc.level = level; + + petnameLen = strlen(petname); + if(petnameLen <= CHAR_FREENAME_LEN) + { + strcpy(pc.ridePetName, petname); + } + + pc.ridePetLevel = petlevel; + + pc.nameColor = nameColor; + if(walk != 0) // ????? + { + pc.status |= CHR_STATUS_W; + } + if(height != 0) // ????? + { + pc.status |= CHR_STATUS_H; + } + + if(pc.ptAct == NULL) + return; + + if(nameLen <= CHAR_NAME_LEN) + { + strcpy(pc.ptAct->name, name); + } + if(freeNameLen <= CHAR_FREENAME_LEN) + { + strcpy(pc.ptAct->freeName, freeName); + } + pc.ptAct->level = level; + + if(petnameLen <= CHAR_FREENAME_LEN) + { + strcpy(pc.ptAct->petName, petname); + } + pc.ptAct->petLevel = petlevel; + + pc.ptAct->itemNameColor = nameColor; + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + pc.profession_class = profession_class; + pc.ptAct->profession_class = profession_class; + pc.profession_level = profession_level; +// pc.profession_exp = profession_exp; + pc.profession_skill_point = profession_skill_point; +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + pc.herofloor = herofloor; +#endif +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + gmnameLen = strlen(gm_name); + if(gmnameLen <= 33){ + strcpy(pc.ptAct->gm_name, gm_name); + } +#endif + +#ifdef _CHANNEL_MODIFY +#ifdef _CHAR_PROFESSION + if(pc.profession_class == 0){ + pc.etcFlag &= ~PC_ETCFLAG_CHAT_OCC; + //TalkMode = 0; + } +#endif +#endif +} + + +// PC????ѩ???????@e???? +void updataPcAct(void) +{ + if(pc.ptAct == NULL) + return; + + if(strlen(pc.name) <= CHAR_NAME_LEN) + { + strcpy(pc.ptAct->name, pc.name); + } + if(strlen(pc.freeName) <= CHAR_FREENAME_LEN) + { + strcpy(pc.ptAct->freeName, pc.freeName); + } + pc.ptAct->level = pc.level; + pc.ptAct->hp = pc.hp; + pc.ptAct->maxHp = pc.maxHp; +#ifdef _SFUMATO + pc.ptAct->sfumato = pc.sfumato; // Ⱦͼɫ +#endif +} + + +// PC??????????? +void setPcLeader(void) +{ + pc.status |= CHR_STATUS_LEADER; +} + + +// PC???????????????? +void delPcLeader(void) +{ + pc.status &= (~CHR_STATUS_LEADER); +} + + +// PC??????????????? +void setPcParty(void) +{ + pc.status |= CHR_STATUS_PARTY; +} + + +// PC????????????????? +void delPcParty(void) +{ + pc.status &= (~CHR_STATUS_PARTY); +} + + +// PC?????P?????? +void setPcWatch(void) +{ + pc.status |= CHR_STATUS_WATCH; +} + + +// PC?????P?????????? +void delPcWatch(void) +{ + pc.status &= (~CHR_STATUS_WATCH); +} + + +// ???????????? +//???????????????v???? +void setPcWalkFlag(void) +{ + if(pc.ptAct == NULL) + return; + + pc.ptAct->walkFlag = 1; +} + +// ???????????????? +//???????????????v???? +void delPcWalkFlag(void) +{ + if(pc.ptAct == NULL) + return; + + pc.ptAct->walkFlag = 0; +} + + +// ????? +int checkPcWalkFlag(void) +{ + if(pc.ptAct == NULL) + return 0; + + return (int)pc.ptAct->walkFlag; +} + + +// ???????? +void setPcUseMagic(void) +{ + pc.status |= CHR_STATUS_USE_MAGIC; +} + + +// ???????? +void delPcUseMagic(void) +{ + pc.status &= (~CHR_STATUS_USE_MAGIC); +} + + +// PC?????? +void setPcFukidashi(unsigned int offTime) +{ + CHAREXTRA *ext; + + if(pc.ptAct == NULL) + return; + + pc.status |= CHR_STATUS_FUKIDASHI; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + ext->drawFukidashiTime = offTime + TimeGetTime(); +} + + +// ???????????q??@e +void setPcNameColor(int color) +{ + pc.pcNameColor = color; + + if(pc.ptAct == NULL) + return; + + pc.ptAct->charNameColor = color; +} + +#ifdef _ANGEL_SUMMON +void setPcAngel(void) +{ + int find = FALSE; + for(int i =0; i = 0){ + if(pc.familyName[0]) + setCharFamily( pc.ptAct, effectno); + }else + delCharFamily( pc.ptAct); + break; +#endif +#ifdef FAMILY_MANOR_ + case 44: + if(effectno >= 0){ + if(pc.familyName[0]) + setCharmFamily( pc.ptAct, effectno); + }else + delCharmFamily( pc.ptAct); + break; +#endif +#ifdef _CHAR_MANOR_ + case 46: + if(effectno >= 0){ + setCharmManor( pc.ptAct, effectno); + }else + delCharmManor( pc.ptAct); + break; +#endif +#ifdef _CHARTITLE_ + case 45: + if(effectno >= 0){ + setCharmTitle(pc.ptAct, effectno); + }else + delCharmTitle(pc.ptAct); + break; +#endif + case 31: +#if 1 + setPcWarpPoint(x, y); + setPcDir(dir); +#else + // ?????????????????? + if(partyModeFlag == 0 || (pc.status & CHR_STATUS_LEADER) != 0) + { + setPcWarpPoint(x, y); + setPcDir(dir); + } +#endif + setPcAction(ANIM_STAND); + break; + + // ?? + case 30: + setPcDir(dir); + break; + + // ? + case 1: + setPcAction(ANIM_WALK); + break; + + // ?? + case 2: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_ATTACK); + break; + + // ??? + case 3: + setPcDir(dir); + setPcAction(ANIM_THROW); + break; + + // ???? + case 4: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_DAMAGE); + break; + + // ? + case 5: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_DEAD); + break; + + // ?? + case 6: + break; + + // ????? + case 7: + break; + + // ????? + case 8: /* UsedMagic */ + break; + + // X?? + case 10: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_DEAD); + break; + + // ?? + case 11: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_SIT); + break; + + // ?? + case 12: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_HAND); + break; + + // ?? + case 13: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_HAPPY); + break; + + // W? + case 14: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_ANGRY); + break; + + // v?? + case 15: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_SAD); + break; + + // ??? + case 16: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_GUARD); + break; + + // ??h???? + case 17: + setPcDir(dir); + setPcAction(ANIM_WALK); + break; + + // ???? + case 18: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_NOD); + break; + + // ??֢t??????? + case 19: + //setPcWarpPoint(x, y); + setPcDir(dir); + setPcAction(ANIM_STAND); + break; + + // Pfѩ + case 20: + setPcWarpPoint(x, y); + setPcDir(dir); + break; + + // ????ѩ + case 21: + setPcWarpPoint(x, y); + setPcDir(dir); + if(effectno == 1) + { + // ??????? + setPcLeader(); +#if 0 + if(pc.ptAct != NULL) + { + pc.ptAct->partyGx = -1; + pc.ptAct->partyGy = -1; + } +#endif + } + else + { + // ???????? + delPcLeader(); + } + break; + + // ?Pѩ + case 22: + setPcWarpPoint(x, y); + setPcDir(dir); + if(effectno == 1) + { + setPcWatch(); + } + else + { + delPcWatch(); + } + break; + + // ???????????q? + case 23: + setPcNameColor(effectno); + break; +#ifdef _STREET_VENDOR + case 41: + { + CHAREXTRA *ext; + if(pc.ptAct == NULL) break; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + if(ext->ptStreetVendor){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } + ext->ptStreetVendor = GetAction(PRIO_CHR,0); + } + break; + case 42: + { + CHAREXTRA *ext; + if(pc.ptAct == NULL) break; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + if(ext->ptStreetVendor){ + DeathAction(ext->ptStreetVendor); + ext->ptStreetVendor = NULL; + } + } + break; +#endif + +#ifdef _ANGEL_SUMMON + case 34: + setPcWarpPoint(x, y); + setPcDir(dir); + if(effectno == 1) + { + setPcAngel(); + } + else + { + delPcAngel(); + } + break; +#endif +#ifdef _ITEM_FIREWORK + case 51: + { + CHAREXTRA *ext; + + if (pc.ptAct == NULL) + break; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + if (ext->pActFirework[0]) + { + DeathAction(ext->pActFirework[0]); + ext->pActFirework[0] = NULL; + } + if (ext->pActFirework[1]) + { + DeathAction(ext->pActFirework[1]); + ext->pActFirework[1] = NULL; + } + ext->pActFirework[0] = GetAction(PRIO_CHR, 0); + ext->pActFirework[0]->damage = effectno; // damage type (effectno = type) + ext->pActFirework[0]->anim_chr_no = effectparam1; + ext->pActFirework[0]->anim_no = ANIM_STAND; + ext->pActFirework[0]->anim_ang = 1; + ext->pActFirework[0]->dispPrio = DISP_PRIO_RESERVE; + if (effectno == 3) + { + ext->pActFirework[0]->gx = pc.ptAct->gx + 3; + ext->pActFirework[0]->gy = pc.ptAct->gy - 3; + ext->pActFirework[0]->bufGx[0] = pc.ptAct->gx; + ext->pActFirework[0]->bufGy[0] = pc.ptAct->gy; + } + else + { + ext->pActFirework[0]->gx = pc.ptAct->gx; + ext->pActFirework[0]->gy = pc.ptAct->gy; + } + ext->pActFirework[0]->actNo = 0; + } + break; +#endif +#ifdef _NPC_MAGICCARD + case 60: + { + CHAREXTRA *ext; + int i; + + if (pc.ptAct == NULL) + break; + ext = (CHAREXTRA *)pc.ptAct->pYobi; + + for(i=0;i<4;i++){ + if(ext->pActMagiccard[i]){ + DeathAction(ext->pActMagiccard[i]); + ext->pActMagiccard[i] = NULL; + } + } + //changePcAct(x, y, dir, 60 , giver , actionNum , petaction) + //changePcAct(int x, int y, int dir, int action,int effectno, int effectparam1, int effectparam2) + + //effectno ֵʩߵλñ + if(effectparam2 == 3){ //ħ + ext->pActMagiccard[0] = GetAction(PRIO_CHR,0); + ext->pActMagiccard[0]->anim_chr_no = effectparam1; + ext->pActMagiccard[0]->dispPrio = DISP_PRIO_RESERVE; + if(effectparam1 == 101120 || effectparam1 == 101628){ + ext->pActMagiccard[0]->gx = Positiontable[effectno].humanX+1 + x; //.magic1X; + ext->pActMagiccard[0]->gy = Positiontable[effectno].humanY-1 + y; //.magic1Y; + }else{ + ext->pActMagiccard[0]->gx = Positiontable[effectno].petX+1 + x; + ext->pActMagiccard[0]->gy = Positiontable[effectno].petY-1 + y; + } + }else if(effectparam2 == 0){ //ӡǷ + ext->pActMagiccard[0] = GetAction(PRIO_CHR,0); + ext->pActMagiccard[0]->anim_chr_no = 101290; + ext->pActMagiccard[0]->dispPrio = DISP_PRIO_RESERVE; + ext->pActMagiccard[0]->gx = Positiontable[effectno].humanX+1 + x; + ext->pActMagiccard[0]->gy = Positiontable[effectno].humanY-1 + y; + }else{ + for(i=0;i<4;i++){ + ext->pActMagiccard[i] = GetAction(PRIO_CHR,0); + if(i == 0){ + ext->pActMagiccard[i]->anim_chr_no = 101942; + }else if(i == 3){ + ext->pActMagiccard[i]->anim_chr_no = 101943; + }else{ + ext->pActMagiccard[i]->anim_chr_no = effectparam1; + } + ext->pActMagiccard[i]->gx = Positiontable[effectno].petX + x; + ext->pActMagiccard[i]->gy = Positiontable[effectno].petY + y; + ext->pActMagiccard[i]->dispPrio = DISP_PRIO_RESERVE; + ext->pActMagiccard[i]->anim_ang = dir;//1; // + } + + ext->pActMagiccard[1]->anim_no = ANIM_STAND; + + if(effectparam2 == 1) //ƹ + ext->pActMagiccard[2]->anim_no = ANIM_ATTACK; + else if(effectparam2 == 2) //Ʒ + ext->pActMagiccard[2]->anim_no = ANIM_GUARD; + } +#ifdef _MOVE_SCREEN + if(pc.bMoveScreenMode) + { + for(i=0;i<4;i++){ + if(ext->pActMagiccard[i]){ + ext->pActMagiccard[i]->gx -= iScreenMoveX; + ext->pActMagiccard[i]->gy -= iScreenMoveY; + } + } + } +#endif + } + break; +#endif + + } +} + + +// ??ѩ???? ///////////////////////////////////////////////////////// +void clearPartyParam(void) +{ + int i; +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + // ??????????????????????? + if(party[i].useFlag != 0) + { + if( party[i].id == pc.id) + { + // ????h?????????? + if(party[i].ptAct != NULL) + { + party[i].ptAct->bufCount = 0; + } + delPcParty(); + } + else + { + // ??????????\?????h???????? + if((pc.status & CHR_STATUS_LEADER) != 0 + && party[i].ptAct != NULL) + { + party[i].ptAct->bufCount = 0; + } + delCharParty(party[i].ptAct); + } + } + party[i].useFlag = 0; + party[i].id = 0; + party[i].ptAct = NULL; + + } + + delPcLeader(); +} + + +// ??ѩ?ptAct?NULL?V???? +void clearPtActPartyParam(void) +{ + int i; + +#ifdef MAX_AIRPLANENUM + for (i = 0; i < MAX_AIRPLANENUM; i++) +#else + for (i = 0; i < MAX_PARTY; i++) +#endif + { + party[i].ptAct = NULL; + } +} + + + + + +// ???????????@e???????? ///////////////////////////// +int existCharacterListEntry(int index) +{ + if(index < 0 || index >= MAXCHARACTER) + return -1; + + if(chartable[index].name[0] != '\0') + { + return 1; + } + else + { + return 0; + } +} + + +// ???????i????????? +int cmpNameCharacterList(char *name) +{ + int i; + + for(i = 0; i < MAXCHARACTER; i++) + { + if(strcmp(name, chartable[i].name) == 0) + return 1; + } + + return 0; +} + +#ifdef _AIDENGLU_ +extern Landed PcLanded; +#endif +// ??????????@e???????????t????????????? +int setCharacterList(char *name, char *opt) +{ + int index; + + makeStringFromEscaped(name); + makeStringFromEscaped(opt); + + index = getIntegerToken(opt, '|', 1); + + if(index < 0 || index >= MAXCHARACTER) + return -1; +#ifdef _AIDENGLU_ + memset(PcLanded.½[index],0,32); +#endif + memset(&chartable[index], 0, sizeof(CHARLISTTABLE)); + + if(strlen(name) <= CHAR_NAME_LEN) + { + strcpy(chartable[index].name, name); + } + else + { + strcpy(chartable[index].name, "???"); + } + chartable[index].faceGraNo = getIntegerToken(opt, '|', 2); + chartable[index].level = getIntegerToken(opt, '|', 3); + chartable[index].hp = getIntegerToken(opt, '|', 4); + chartable[index].str = getIntegerToken(opt, '|', 5); + chartable[index].def = getIntegerToken(opt, '|', 6); + chartable[index].agi = getIntegerToken(opt, '|', 7); + chartable[index].app = getIntegerToken(opt, '|', 8); + chartable[index].dp = getIntegerToken(opt, '|', 9); + chartable[index].attr[0] = getIntegerToken(opt, '|', 10)/10; + chartable[index].attr[1] = getIntegerToken(opt, '|', 11)/10; + chartable[index].attr[2] = getIntegerToken(opt, '|', 12)/10; + chartable[index].attr[3] = getIntegerToken(opt, '|', 13)/10; + chartable[index].login = getIntegerToken(opt, '|', 14); +#ifdef _AIDENGLU_ + strcpy(PcLanded.½[index],name); +#endif + return 0; +} + + +// ???????????? +// int index : ???????0 ~ 7 +int resetCharacterList(int index) +{ + if(index < 0 || index >= MAXCHARACTER) + return -1; + + memset(&chartable[index], 0, sizeof(CHARLISTTABLE)); + + return 0; +} + + +// ?????? ///////////////////////////////////////////////////////// +void getItem(void) +{ + float tmpDir; + float tmpX, tmpY; + int dir; + static unsigned int piSendTime = 0; + + // ???????????????????????? + if(windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMENU + || windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMAIN + || windowTypeWN == WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN) + return; + + // kI?K?????????????????? + if(ABS(nowGx - mouseMapGx) > 1 + || ABS(nowGy - mouseMapGy) > 1) + return; + + // kI????????????????? + if(!checkCharObjPoint(mouseMapGx, mouseMapGy, + CHAROBJ_TYPE_NPC|CHAROBJ_TYPE_ITEM|CHAROBJ_TYPE_MONEY)) +// CHAROBJ_TYPE_ITEM|CHAROBJ_TYPE_MONEY)) + return; + + // ??????????? + tmpX = (float)(mouseMapGx - nowGx); + tmpY = (float)(mouseMapGy - nowGy); + tmpDir = Atan(tmpX, tmpY) + 22.5F - 45.0F*3; + AdjustDir(&tmpDir); + dir = (int)(tmpDir/45); + + // ?? + if(piSendTime+FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + // ?????? + if(bNewServer) { + lssproto_PI_send(sockfd, nowGx, nowGy, dir); + } + else + old_lssproto_PI_send(sockfd, nowGx, nowGy, dir); + piSendTime = TimeGetTime(); + } +} + +#ifdef __TALK_TO_NPC + +BOOL TalkToNPC(void) +{ + float tmpDir; + float tmpX, tmpY; + int dir; + static unsigned int talkSendTime = 0; + if(windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMENU + || windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMAIN + || windowTypeWN == WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN) + return FALSE; + + if(nowVx != 0 || nowVy != 0) + return FALSE; + if(ABS(nowGx - mouseMapGx) > 2 + || ABS(nowGy - mouseMapGy) > 2) + return FALSE; + if(!checkCharObjPoint(mouseMapGx, mouseMapGy, CHAROBJ_TYPE_NPC)) + return FALSE; + tmpX = (float)(mouseMapGx - nowGx); + tmpY = (float)(mouseMapGy - nowGy); + tmpDir = Atan(tmpX, tmpY) + 22.5F; + AdjustDir(&tmpDir); + dir = (int)(tmpDir/45); + if(talkSendTime+FIELD_BTN_PUSH_WAIT < TimeGetTime()){ + if(pc.ptAct->anim_ang != dir){ + char dir2[2]; + setPcDir(dir); + + dir2[0] = cnvServDir(dir, 1); + dir2[1] = '\0'; + + walkSendForServer(nowGx, nowGy, dir2); + } + char dest[1024], m[1024]; + extern STR_BUFFER chatRegistryStr[]; + if(chatRegistryStr[7].cnt > 0) + makeEscapeString(chatRegistryStr[7].buffer, dest, sizeof(dest)); + else + makeEscapeString("hi", dest, sizeof(dest)); + sprintf_s(m, "P|%s", dest); + if(bNewServer) + lssproto_TK_send(sockfd, nowGx, nowGy, m, MyChatBuffer.color, NowMaxVoice); + else + old_lssproto_TK_send(sockfd, nowGx, nowGy, m, MyChatBuffer.color, NowMaxVoice); + talkSendTime = TimeGetTime(); + } + return TRUE; +} + +#endif + +// ?????V?v? ///////////////////////////////////////////////////// +void swapItem(int from, int to) +{ + if(from < 0 || to < 0) + return; +// swapShort(&pc.item[from].useFlag, &pc.item[to].useFlag); + swap(pc.item[from].useFlag, pc.item[to].useFlag); +// swapString(pc.item[from].name, pc.item[to].name); + swap(pc.item[from].name, pc.item[to].name); +// swapString(pc.item[from].name2, pc.item[to].name2); + swap(pc.item[from].name2, pc.item[to].name2); +// swapString(pc.item[from].memo, pc.item[to].memo); + swap(pc.item[from].memo, pc.item[to].memo); +// swapInteger(&pc.item[from].color, &pc.item[to].color); + swap(pc.item[from].color, pc.item[to].color); +// swapInteger(&pc.item[from].graNo, &pc.item[to].graNo); + swap(pc.item[from].graNo, pc.item[to].graNo); +// swapInteger(&pc.item[from].level, &pc.item[to].level); + swap(pc.item[from].level, pc.item[to].level); +// swapShort(&pc.item[from].field, &pc.item[to].field); + swap(pc.item[from].field, pc.item[to].field); +// swapShort(&pc.item[from].target, &pc.item[to].target); + swap(pc.item[from].target, pc.item[to].target); +// swapShort(&pc.item[from].deadTargetFlag, &pc.item[to].deadTargetFlag); + swap(pc.item[from].deadTargetFlag, pc.item[to].deadTargetFlag); +// swapShort(&pc.item[from].sendFlag, &pc.item[to].sendFlag); + swap(pc.item[from].sendFlag, pc.item[to].sendFlag); +// swapString(pc.item[from].damage, pc.item[to].damage); + swap(pc.item[from].damage, pc.item[to].damage); +#ifdef _ITEM_PILENUMS +// swapInteger(&pc.item[from].pile, &pc.item[to].pile); + swap(pc.item[from].pile, pc.item[to].pile); +#endif +#ifdef _PET_ITEM + swap(pc.item[from].type, pc.item[to].type); +#endif +#ifdef _ITEM_JIGSAW + swap(pc.item[from].jigsaw, pc.item[to].jigsaw); +#endif +#ifdef _NPC_ITEMUP + swap(pc.item[from].itemup, pc.item[to].itemup); +#endif +#ifdef _ITEM_COUNTDOWN + swap(pc.item[from].counttime, pc.item[to].counttime); +#endif +} + +// ?k?V?? +/*void swapInteger(int *a, int *b) +{ + int tmp; + + tmp = *a; + *a = *b; + *b = tmp; +}*/ + + +/*void swapShort(short *a, short *b) +{ + short tmp; + + tmp = *a; + *a = *b; + *b = tmp; +}*/ + + +// ???V?v??????255??????? +/*void swapString(char *a, char *b) +{ + char tmp[256]; + + if(strlen(a) > 255 || strlen(b) > 255) + return; + + strcpy(tmp, a); + strcpy(a, b); + strcpy(b, tmp); +} +*/ + +// ?????????? ///////////////////////////////////////////////// +BOOL lookAtAround(void) +{ + float tmpDir; + float tmpX, tmpY; + int dir; + static unsigned int lSendTime = 0; + + // ???????????????????????? + if(windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMENU + || windowTypeWN == WINDOW_MESSAGETYPE_ITEMSHOPMAIN + || windowTypeWN == WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN) + return FALSE; + + // kI?K?????????????????? + if(ABS(nowGx - mouseMapGx) > 2 + || ABS(nowGy - mouseMapGy) > 2) + return FALSE; + + // kI????????????????? + if(!checkCharObjPoint(mouseMapGx, mouseMapGy, CHAROBJ_TYPE_LOOKAT)) + return FALSE; + + // ??????????? + tmpX = (float)(mouseMapGx - nowGx); + tmpY = (float)(mouseMapGy - nowGy); + if(tmpX == 0 && tmpY == 0) // ?Y????????????? + return FALSE; + + tmpDir = Atan(tmpX, tmpY) + 22.5F - 45.0F*3; + AdjustDir(&tmpDir); + dir = (int)(tmpDir/45); + + // ?? + if(lSendTime+FIELD_BTN_PUSH_WAIT < TimeGetTime()) + { + // ?????? + if(bNewServer) + lssproto_L_send(sockfd, dir); + else + old_lssproto_L_send(sockfd, dir); + lSendTime = TimeGetTime(); + } + + return TRUE; +} + + + + + +// ????????? ///////////////////////////////////////////////////// +BOOL addressBookFlag = FALSE; +ACTION *ptActAddressBookWin = NULL; +int addressBookX = 16; +int addressBookY = 16; +int addressBookPage = 0; +ACTION *ptActAddressBookChar[MAX_ADR_BOOK_COUNT]; + +// k???????? +int addressBookSelectStrItem[1+3*MAX_ADR_BOOK_COUNT]; +// 0 ... ?? +// n*3+1 ... ? +// n*3+2 ... +// n*3+3 ... ?? + + +BOOL addressBookSendMsgFlag = FALSE; +ACTION *ptActAddressBookSendMsgWin = NULL; + + +void addressBookWindow1(void); + + +// ??????????? +void initAddressBook(void) +{ + int i; + + addressBookFlag = FALSE; + ptActAddressBookWin = NULL; + memset(&ptActAddressBookChar, 0, sizeof(ptActAddressBookChar)); + addressBookPage = 0; + for(i = 0; i < sizeof(addressBookSelectStrItem)/sizeof(int); i++) + { + addressBookSelectStrItem[i] = -2; + } + + addressBookSendMsgFlag = FALSE; + ptActAddressBookSendMsgWin = NULL; +} + + +// ????????? +void addressBookProc(void) +{ + int i; + int no; + + // ?????????? + if(addressBookFlag + && ptActAddressBookWin == NULL) + { + // ?????????????? + ptActAddressBookWin = MakeWindowDisp(addressBookX, addressBookY, 4, 8, NULL, 1); + // ?????????? + for(i = 0; i < MAX_ADR_BOOK_COUNT; i++) + { + no = addressBookPage*MAX_ADR_BOOK_COUNT+i; + + ptActAddressBookChar[i] = GetAction(PRIO_CHR, 0); + if(ptActAddressBookChar[i] != NULL) + { + ptActAddressBookChar[i]->anim_chr_no = addressBook[no].graNo; + ptActAddressBookChar[i]->atr = ACT_ATR_HIDE; + ptActAddressBookChar[i]->anim_no = ANIM_STAND; + ptActAddressBookChar[i]->dispPrio = DISP_PRIO_ITEM; + ptActAddressBookChar[i]->x = addressBookX + 40; + ptActAddressBookChar[i]->y = addressBookY + i * 110 + 80; + pattern(ptActAddressBookChar[i], ANM_NOMAL_SPD, ANM_LOOP); + } + } + } + // ?????????? + else + if(!addressBookFlag + && ptActAddressBookWin != NULL) + { + DeathAction(ptActAddressBookWin); + ptActAddressBookWin = NULL; + for(i = 0; i < MAX_ADR_BOOK_COUNT; i++) + { + if(ptActAddressBookChar[i] != NULL) + { + DeathAction(ptActAddressBookChar[i]); + ptActAddressBookChar[i] = NULL; + } + } + } + // ??????? + else + if(addressBookFlag + && ptActAddressBookWin != NULL) + { + addressBookWindow1(); + } +} + + +// ??????? +void addressBookWindow1(void) +{ + int mode = 0; + int i; + int no; + char msg[256]; + + // ???k?????????? + // ??????????????????? + if(mouse.onceState & MOUSE_LEFT_CRICK) + { + for(i = 0; i < sizeof(addressBookSelectStrItem)/sizeof(int); i++) + { + if(addressBookSelectStrItem[i] == HitFontNo) + { + mode = i + 1; + break; + } + } + } + + // ?????????????? + if(mode == 1) + { + addressBookFlag = FALSE; + return; + } + // ????????????????????? + else + if((mode-2) < MAX_ADR_BOOK_COUNT*3 + && ((mode-2) % 3) == 2) + { + if(bNewServer) + lssproto_DAB_send(sockfd, addressBookPage*MAX_ADR_BOOK_COUNT+((mode-2)/3)); + else + old_lssproto_DAB_send(sockfd, addressBookPage*MAX_ADR_BOOK_COUNT+((mode-2)/3)); + } + + // ????????????????? + if(ptActAddressBookWin->hp >= 1) + { + for(i = 0; i < MAX_ADR_BOOK_COUNT; i++) + { + no = addressBookPage*MAX_ADR_BOOK_COUNT+i; + + if(ptActAddressBookChar[i] != NULL) + { + // q?????????V??????? + if(strlen(addressBook[no].name) > 0) + { + // ??????k?????ѩ + // ??? + ptActAddressBookChar[i]->atr &= (~ACT_ATR_HIDE); + ptActAddressBookChar[i]->anim_chr_no = addressBook[no].graNo; + // q + sprintf_s(msg, "NAME. %s", addressBook[no].name); + StockFontBuffer(addressBookX + 68, addressBookY + i * 110 + 28, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + + // ??? + sprintf_s(msg, "LV. %d", addressBook[no].level); + StockFontBuffer(addressBookX + 68, addressBookY + i * 110 + 46, + FONT_PRIO_FRONT, FONT_PAL_WHITE, msg, 0); + // ????? + if(addressBook[i].onlineFlag != 0) + { + StockFontBuffer(addressBookX + 130, addressBookY + i * 110 + 46, + FONT_PRIO_FRONT, FONT_PAL_WHITE, "", 0); + } + else + { + StockFontBuffer(addressBookX + 130, addressBookY + i * 110 + 46, + FONT_PRIO_FRONT, FONT_PAL_GRAY, "", 0); + } + // ???? + addressBookSelectStrItem[i*3+1] = + StockFontBuffer(addressBookX + 68, addressBookY + i * 110 + 64, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "", 2); + // ??? + addressBookSelectStrItem[i*3+2] = + StockFontBuffer(addressBookX + 112, addressBookY + i * 110 + 64, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "", 2); + // ????? + addressBookSelectStrItem[i*3+3] = + StockFontBuffer(addressBookX + 156, addressBookY + i * 110 + 64, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ɾ", 2); + } + else + { + ptActAddressBookChar[i]->atr |= ACT_ATR_HIDE; + + ptActAddressBookChar[i]->anim_chr_no = 0; + } + } + } + + addressBookSelectStrItem[0] = + StockFontBuffer(addressBookX + 56, addressBookY + 352, + FONT_PRIO_FRONT, FONT_PAL_YELLOW, "ر", 2); + } +} + +int CHAR_getMaxHaveGold() +{ + int MaxGold; +#ifdef _FIX_MAXGOLD // WON ADD Ǯ + int trans = pc.transmigration; + MaxGold = 1000000 + trans*(1800000); +#else + MaxGold = MAX_GOLD; +#endif + return MaxGold; +} \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/phonemsg.cpp b/石器时代8.5客户端最新源代码/石器源码/system/phonemsg.cpp new file mode 100644 index 0000000..90711a0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/phonemsg.cpp @@ -0,0 +1,615 @@ +//========================================================================== +// : PhoneMsg.cpp +// : ʯʱ[Ѷ]ťĹʵ(V3.0Ĺ) +// ׫д : (Leiboy) +// : 20020126 +// ڶ : 20020202==>Multithread(ʽ) +// : 20020220==>MFCдWinsockʽ!(Ϊɰ!) +// İ : 20020226==>DNS(ʽ) +// ʽ : 20020304 +// ˵ : ϷгɹشһͨѶÿνWGS! +//========================================================================== + +//汾Ŀ +#include "../systeminc/version.h" +#ifdef __PHONEMESSAGE + +#include +#include "time.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/login.h" +#include "../systeminc/menu.h" +#include "../systeminc/map.h" +#include "../systeminc/ime_sa.h" +#include "../systeminc/t_music.h" +#include "../systeminc/field.h" +#include "../systeminc/pc.h" +#include "../wgs/descrypt.h" +#include "../other/caryIme.h" + +#define MSG_SURE_D 26288 //ȷ()(ɫ) +#define MSG_SURE_U 26289 //ȷ()(ɫ) +#define MSG_CANCEL_U 26284 //ȡ(δ) +#define MSG_CANCEL_D 26285 //ȡ() +#define MSG_CLEAR_U 26298 //() +#define MSG_CLEAR_D 26299 //() + +//Messsage Log ר Begin +#ifdef _STONDEBUG_ +char logstr[512]; +#define logfilename "message.log" +#endif +//Messsage Log ר End + +BOOL QueryMyIP(char HostName[]); +//ʯѶServer IP : 210.64.97.17 +char *MsgIP; +#define SMSDomainName "sms.hwaei.com.tw" +//ĿǰõASP filename +#define ASPname "//sms//stoneage.asp" //2002 Feb. 20! +int myvalue; +char seqno[14]; //Wayia_seqno +//************************************************ +//ʽһ : ʽASP乵ͨרúʽ +//شֵ : 0 --- & Ѷͳɹ +// 1 --- Ѷʧ +// 2 --- ֻ +// 3 --- ֻѶϢ() +// 4 --- ·˴ +// 5 --- WGS(ͨ)Ѳ!!(С) +// 6 --- ʱ(DNSʧ) +// 7 --- ASPش +//************************************************ +int SendPhoneMsg(char pid[16], char ppw[16], char pps[], char pms[]) +{ + if(!QueryMyIP(SMSDomainName)) return 6; + if((pps[0] =='\0') || (lstrlen(pps) != 10)) return 2; + if((pps[0] != '0') || (pps[1] != '9')) return 2; + int dv,i=0; + do + { + dv = isdigit(pps[i+2]); + i++; + }while( dv && (i<8)); + if(!dv) return 2; + //Jasonۺ,¶Ϊ66bytes!! Feb. 5,2002 + //16bytes! Feb.22,2002 + int x=0,mc=0; + do + { + if(IsDBCSLeadByte(pms[x])) + x+=2; + else + x++; + mc++; + }while(x < lstrlen(pms)); + if((mc<1) || (mc>50)) return 3; + char extpms[120]; + if(lstrlen(pc.name)>16) + return 3; + else + +#ifdef _FIX_URLENCODE // WON ADD Ѷ޷ӿո + { + char OutTmp[768]; + char *pInTmp,*pOutTmp; + char Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + // do encoding + pInTmp=pms; + pOutTmp=OutTmp; +// ZeroMemory(OutTmp,sizeof(OutTmp)); + while (*pInTmp) + { + // if(isalnum(*pInTmp)&&(!IsDBCSLeadByte(*pInTmp))) + if ( (*pInTmp> '0') && (*pInTmp < '9') + || (*pInTmp> 'a') && (*pInTmp < 'z') + || (*pInTmp> 'A') && (*pInTmp < 'Z') + ) + *pOutTmp++ = *pInTmp; + else + { + // if(isspace(*pInTmp)) + if(*pInTmp==0x20&&(!IsDBCSLeadByte(*pInTmp))) + *pOutTmp++ = '+'; + else + { + *pOutTmp++ = '%'; + *pOutTmp++ = Hex[(*pInTmp>>4)&0x0f]; + *pOutTmp++ = Hex[(*pInTmp)&0x0f]; + } + } + + pInTmp++; + + } + + *pOutTmp = '\0'; + sprintf_s(extpms,"%s:%s",pc.name,OutTmp); + } +#else + sprintf_s(extpms,"%s:%s",pc.name,pms); +#endif + + SOCKET hSock; + SOCKADDR_IN stName; + fd_set rfds,wfds; + timeval tmTimeOut; + DWORD timeout; + char *result; + int len, cnt, ret; + tmTimeOut.tv_usec=0; + tmTimeOut.tv_sec=0; + if( INVALID_SOCKET != ( hSock = socket( AF_INET, SOCK_STREAM, 0) ) ) + { + DWORD flg = 1; + if( SOCKET_ERROR != ioctlsocket( hSock, FIONBIO, &flg)) + { + ZeroMemory( &stName, sizeof(struct sockaddr)); + stName.sin_addr.s_addr = inet_addr(MsgIP); + stName.sin_family = PF_INET; + stName.sin_port = htons(80); + ret = connect( hSock, (LPSOCKADDR)&stName, sizeof(struct sockaddr) ); + if( SOCKET_ERROR != ret || WSAEWOULDBLOCK == WSAGetLastError() ) + { + timeout = TimeGetTime(); + while(1) + { + FD_ZERO( &wfds); + FD_SET( hSock, &wfds); + if( select( NULL, (fd_set*)NULL, &wfds, (fd_set*)NULL, &tmTimeOut)>0 && FD_ISSET( hSock, &wfds)) + break; + DWORD curtime = TimeGetTime(); + if( (timeout+5000) < curtime ) + { + closesocket(hSock); + return 6; + } + Sleep(1); + } + cnt = 0; + char buf[1024]; + sprintf_s(buf,"GET //sms//stoneage.asp?ID=%s&PWD=%s&TEL=%s&MSG=%s",pid,ppw,pps,extpms); + strcat_s(buf," HTTP/1.1\r\nAccept: text/*\r\nUser-Agent: StoneAge\r\n"); + sprintf_s(buf,"%sHost: %s\r\n\r\n",buf,MsgIP); + len = lstrlen(buf); + timeout = TimeGetTime(); + while(len) + { + DWORD stime = TimeGetTime(); + if( (timeout+3000) < stime ) + { + closesocket(hSock); + return 6; + } + FD_ZERO( &wfds); + FD_SET( hSock, &wfds); + select( NULL, (fd_set*)NULL, &wfds, (fd_set*)NULL, &tmTimeOut); + if( !FD_ISSET( hSock, &wfds) ) + { + Sleep(1); + continue; + } + ret = send( hSock, &buf[cnt], len, 0); + if( SOCKET_ERROR == ret) + { + closesocket(hSock); + return 4; + } + cnt += ret; + len -= ret; + if(len<1) break; + } + Sleep(500); + len = 1024; + cnt = 0; + timeout = TimeGetTime(); + while(1) + { + DWORD rtime = TimeGetTime(); + if( (timeout+3000) < rtime ) + { + closesocket(hSock); + return 6; + } + FD_ZERO( &rfds); + FD_SET( hSock, &rfds); + select( NULL, &rfds, (fd_set*)NULL, (fd_set*)NULL, &tmTimeOut); + if( !FD_ISSET( hSock, &rfds) ) + { + Sleep(1); + continue; + } + ret = recv( hSock, &buf[cnt], len, 0); + if( SOCKET_ERROR == ret) + { + closesocket(hSock); + return 4; + } + if( 0 == ret) + break; + buf[cnt+ret] = 0; + result = strstr( buf, "\r\n\r\n") + 4; + if(result) break; + cnt += ret; + len -= ret; + } + } + } + closesocket(hSock); + if(result[0]=='\0') return 4; + if(result[0]=='1') + { +#ifdef _STONDEBUG_ + lstrcpy(logstr,"ʧ "); + lstrcat(logstr,pps); + sprintf_s(logstr,"%s %s",logstr,extpms); +#endif + return 1; + } + else + { + result++; + if(lstrlen(result) < 14) + return 7; + int j=0; + i=0; + do + { + seqno[i] = result[i]; + if(result[i] == '0') j++; + i++; + }while(i<14); + seqno[14] = 0; + if(j == 14) return 5; +#ifdef _STONDEBUG_ + lstrcpy(logstr,"ɹ-"); + lstrcat(logstr,seqno); + lstrcat(logstr," "); + lstrcat(logstr,pps); + sprintf_s(logstr,"%s %s",logstr,extpms); +#endif + } + return 0; + } + else + return 4; +} + +//************************************************ +//ʽ : Log(LocalĿ¼)רúʽ +//شֵ : None +// ע : ֻDebug modeӲдlog!! +//************************************************ +#ifdef _STONDEBUG_ +void WriteLog( char cData[], char cFile[]) +{ + char totals[1024]; + struct tm nowTime; + time_t longTime; + time( &longTime ); + localtime_s(&nowTime, &longTime ); + sprintf_s(totals,"%02d/%02d/%02d %02d:%02d:%02d ",(nowTime.tm_year % 100), nowTime.tm_mon+1, nowTime.tm_mday, + nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec); + lstrcat(totals,cData); + lstrcat(totals,"\r\n"); + FILE *fp; + fp = fopen(logfilename, "a" ); + if(fp) + { + fprintf(fp,totals); + fclose(fp); + } +} +#endif + +static int mx = 20, my = 10; +STR_BUFFER pno,ptext; +static STR_BUFFER *MsgFocus[] ={ &pno, &ptext }; +static int MsgFocusSw; +//************************************************ +//ʽ : λijʼʽ +//شֵ : None +//************************************************ +void InitMsgInput() +{ + pno.buffer[0]='\0'; + //ptext.buffer[0]='\0'; + pno.x = mx+125; + pno.y = my+47; + pno.len = 10; + pno.color = FONT_PAL_RED; + pno.fontPrio = FONT_PRIO_FRONT; + pno.cnt = 0; + pno.cursor = 0; + + ptext.x = mx+17; + ptext.y = my+87; + ptext.len = 100; + ptext.color = FONT_PAL_AQUA; + ptext.fontPrio = FONT_PRIO_FRONT; + ptext.lineLen=34; + ptext.lineDist=20; + int x = lstrlen(ptext.buffer); + if(x) + ptext.cursor = x; + else + { + ptext.cnt=0; + ptext.cursor=0; + } +} + +//************************************************ +//ʽ : λʽ +//شֵ : None +//************************************************ +int InputMsgData() +{ + int id,x1,x2,y1,y2; + StockFontBuffer2(&pno); + StockFontBuffer2(&ptext); + id = -1; + x1 = mx + 115; + y1 = my + 45; + x2 = x1 + 108; + y2 = y1 + 19; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX ) ) + { + id = 0; + MsgFocusSw = 0; + } + x1 = mx + 16; + y1 = my + 80; + x2 = x1 + 240; + y2 = y1 + 70; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX ) ) + { + id = 1; + MsgFocusSw = 1; + } + x1 = mx + 39; + y1 = my + 190; + x2 = x1 + 67; + y2 = y1 + 24; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX ) ) + { + id = 2; + } + x1 = mx + 155; + y1 = my + 190; + x2 = x1 + 67; + y2 = y1 + 24; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX ) ) + { + id = 3; + } + x1 = mx + 167; + y1 = my + 160; + x2 = x1 + 84; + y2 = y1 + 19; + if( MakeHitBox( x1, y1, x2, y2, DISP_PRIO_BOX ) ) + { + id = 4; + } + return id; +} + +HANDLE MHandle; +extern short msgBtn; +extern char szUser[],szPassword[]; +//************************************************ +//ʽ : Multithreadʽ +//شֵ : OL +//************************************************ +DWORD WINAPI MsgThread(LPVOID param) +{ + msgBtn=1; + myvalue = -1; + char id[32], password[32]; + CopyMemory(id,szUser,32); + ecb_crypt("f;encor1c",id,32,DES_DECRYPT); + CopyMemory(password,szPassword,32); + ecb_crypt("f;encor1c",password,32,DES_DECRYPT); + //GetKeyInputFocus(NULL); +#ifdef _STONDEBUG_ + logstr[0] = 0; +#endif + myvalue = SendPhoneMsg(id,password,pno.buffer,ptext.buffer); + //GetKeyInputFocus(&MyChatBuffer); + switch(myvalue) + { + case 1: + StockChatBufferLine("Ѷʧ!",FONT_PAL_RED); + StockChatBufferLine("²!!",FONT_PAL_WHITE); + break; + case 2: + StockChatBufferLine("ֻʽ!!",FONT_PAL_RED); + StockChatBufferLine("޷ͱѶ!",FONT_PAL_RED); + break; + case 3: + StockChatBufferLine("ֻѶϢ!!",FONT_PAL_RED); + StockChatBufferLine("޷ͱѶ!",FONT_PAL_RED); + break; + case 4: + StockChatBufferLine("·!!",FONT_PAL_RED); + StockChatBufferLine("޷ͱѶ!",FONT_PAL_RED); + break; + case 5: + StockChatBufferLine("WGS(ͨ)Ѳ!!",FONT_PAL_RED); + StockChatBufferLine("޷ͱѶ!",FONT_PAL_RED); + break; + case 6: + StockChatBufferLine("Ѷ޷!!",FONT_PAL_RED); + StockChatBufferLine("Ժ...",FONT_PAL_WHITE); + break; + case 7: + StockChatBufferLine("ѶûȷػӦ!!",FONT_PAL_RED); + StockChatBufferLine("޷ȷѶǷɹ?!",FONT_PAL_WHITE); + break; + case -1: + StockChatBufferLine("ʽڲ!!!",FONT_PAL_RED); + StockChatBufferLine("Ѷʧ!",FONT_PAL_RED); + break; + default: + StockChatBufferLine("ѶѾͳ!",FONT_PAL_YELLOW); + } +#ifdef _STONDEBUG_ + if(logstr[0] != 0) WriteLog(logstr,logfilename); +#endif + msgBtn=0; + CloseHandle(MHandle); + ExitThread(0); + return 0L; +} + +int MsgID; +//************************************************ +//ʽ : ֻѶܵҪʽ +//شֵ : 0 --- ӴOPEN +// 1 --- ӴCLOSE +// 2 --- ȷĽ +//************************************************ +int MsgProc() +{ + int id , i , ret; + static int btnId[3]; + static int btnState[2]; + static DWORD dwPressTime; + static ACTION *pActMenuWin = NULL; + char MsgHint[][30] = {"Էֻ롣","Ѷ(50/Ӣ)","ͳѶ","رռѶӴ","ռѶݡ"}; + + if(MsgID == 0) + { + for( i = 0; i < sizeof(btnId)/sizeof(int); i++) + btnId[i] = -2; + for( i = 0; i < 3; i++) + btnState[i] = -1; + pActMenuWin = MakeWindowDisp(mx,my,275,225,CG_MSG_WND,-1); + InitMsgInput(); + MsgFocusSw = 0; + dwPressTime = 0; + MsgID++; + } + if( pActMenuWin != NULL) + { + id = selGraId( btnId, sizeof(btnId)/sizeof(int)); + if(dwPressTime) + { + if( TimeGetTime()>(dwPressTime+100)) + { + dwPressTime = 0; + if(btnState[2] == 1) + { + if(ptext.buffer[0]!='\0') + { + ptext.buffer[0]='\0'; + ptext.cnt=0; + ptext.cursor=0; + } + if(id==-1) btnState[2] = -1; + } + else if(btnState[0] == 1) + { + if((lstrlen(pno.buffer) > 0) && (lstrlen(ptext.buffer) > 0)) + { + pno.buffer[pno.cnt]='\0'; + ptext.buffer[ptext.cnt]='\0'; + id=50; + } + else + { + if(id==-1) + btnState[0] = -1; + } + } + } + } + else + { + if( -1 < id && id < 3) + { + btnState[id] = 1; + id = -1; + dwPressTime = TimeGetTime(); + play_se( 217, 320, 240); //ť + } + } + + if( pActMenuWin->hp > 0) + { + StockDispBuffer( ((WINDOW_DISP *)pActMenuWin->pYobi)->mx, ((WINDOW_DISP *)pActMenuWin->pYobi)->my, DISP_PRIO_MENU, CG_MSG_WND, 1); + if(btnState[2] != 1) + btnId[2] = StockDispBuffer( (mx+209), (my+170), DISP_PRIO_IME3, MSG_CLEAR_U , 1); + else + StockDispBuffer( (mx+209), (my+170), DISP_PRIO_IME3, MSG_CLEAR_D , 1); + if(btnState[0] != 1) + btnId[0] = StockDispBuffer( (mx+73), (my+202), DISP_PRIO_IME3, MSG_SURE_U , 1); + else + StockDispBuffer( (mx+73), (my+202), DISP_PRIO_IME3, MSG_SURE_D, 1); + if(btnState[1] != 1) + { + btnId[1] = StockDispBuffer( (mx+189), (my+202), DISP_PRIO_IME3, MSG_CANCEL_U, 1); + ret = InputMsgData(); + if(ret>=0) ShowBottomLineString( FONT_PAL_WHITE, MsgHint[ret]); + GetKeyInputFocus(MsgFocus[MsgFocusSw]); + } + } + + if(CheckMenuFlag()) + { + id = 99; + } + else //Escر + if( (joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + { + id = 100; + play_se( 203, 320, 240);//Ӵر + } + else //ȡť + if(btnState[1] == 1) + { + id = 100; + play_se( 203, 320, 240); + } + //رռѶӴ + if( id >= 0) + { + DeathAction( pActMenuWin); + pActMenuWin = NULL; + if(id == 50) + { + DWORD dwThreadID,dwThrdParam = 1; + MHandle = CreateThread(NULL, 0, MsgThread,&dwThrdParam,0,&dwThreadID); + if(MHandle == NULL) + { + StockChatBufferLine("ҵϵͳԴѲ!!",FONT_PAL_RED); + StockChatBufferLine("Ѷʧ!",FONT_PAL_RED); + return 1; + } + return 2; + } + else + return 1; + } + } + return 0; +} + +//************************************************ +//ʽ : DNSרúʽ +//شֵ : TRUE --- תɹ +// FALSE --- תʧ +//************************************************ +BOOL QueryMyIP(char HostName[]) +{ + PHOSTENT info; + if( (info = gethostbyname(HostName)) == NULL) + return FALSE; + else + MsgIP = inet_ntoa(*(struct in_addr *)*info->h_addr_list); + return TRUE; +} + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/process.cpp b/石器时代8.5客户端最新源代码/石器源码/system/process.cpp new file mode 100644 index 0000000..3607778 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/process.cpp @@ -0,0 +1,873 @@ +/************************/ +/* process.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../ohta/ohta.h" +//#include "../dwaf/dwafTestProc.h" +#include "../systeminc/map.h" +#include "../systeminc/ime_sa.h" +#include "../other/caryIme.h" +#include "../systeminc/menu.h" +#include "../systeminc/pc.h" +#include "../systeminc/character.h" +#include "../systeminc/login.h" +#include "../systeminc/netproc.h" +#include "../systeminc/savedata.h" +#include "../systeminc/testView.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/produce.h" +#include "../systeminc/lssproto_cli.h" +#include "../systeminc/netmain.h" +#include "../systeminc/battleMenu.h" +#include "../systeminc/t_music.h" +#include "../systeminc/field.h" +#include "../systeminc/handletime.h" + +#ifdef _NEW_MUISC_ +BOOL ʼ=TRUE; +#endif +/* ???????? *******************************************************************/ +extern void kakushi_command(void); +/* ????k? */ +UINT ProcNo; +/* ??????k? */ +UINT SubProcNo; +/* ????k?(?????????v??) */ +int ProcNo2; +int SubProcNo2; + +int palNo; +int oldPalNo; +int palTime; + +#ifdef _PET_TRACE_MOUSE +extern SCPlayPet PlayPet; +#endif + +/* ?????? ********************************************************************/ +void Process( void ) +{ + if (ProcNo2 >= 0) + { + ProcNo = ProcNo2; + ProcNo2 = -1; + SubProcNo = SubProcNo2; + } + + /* ????? */ + switch (ProcNo) + { + case PROC_OPENNING: + break; + case PROC_INIT: /* ??????? */ + InitProc(); + initMapEffect(TRUE); // ??????????? + break; + // ????????V??? + case PROC_ID_PASSWORD: +#ifdef _NEW_MUISC_ + if(ʼ) { + ʼ=FALSE; + play_bgm(27); + } +#endif + BackBufferDrawType = DRAW_BACK_NORMAL; + idPasswordProc(); +#ifdef _PET_TRACE_MOUSE + PlayPet.Proc(); +#endif + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + FlashKeyboardCursor(); // ??????????? + ImeProc(); // ??????? +#ifdef _LOGINKICK + extern DWORD StartTime; + StartTime = -1 ; +#endif + + break; + // ?????????k + case PROC_TITLE_MENU: + // ?????????? + BackBufferDrawType = DRAW_BACK_NORMAL; + titleProc(); + TitleProduce(); // ????? + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + +//cary 2002.1.4 kakushi_command(); // ???????? + break; + // ???k? + case PROC_CHAR_SELECT: // ???k + // ?????????? + BackBufferDrawType = DRAW_BACK_NORMAL; + selectCharacterProc(); + break; + // ???? + case PROC_CHAR_MAKE: + // ?????????? + BackBufferDrawType = DRAW_BACK_NORMAL; + makeCharacterProc(); + break; + // k?????????? + case PROC_CHAR_LOGIN_START: + // ?????????? + BackBufferDrawType = DRAW_BACK_NORMAL; + // charLoginStart();??????????????????? + // ????????????? + initMap(); // ?????? + initPcAll(); // PCѩ????????? + initCharObj(); // ???????????? + initOpenServerWindow(); // ???????????????? + initFieldProc(); // ?????????? + initMapEffect(FALSE); // ??????????? + EncountFlag = FALSE; + logOutFlag = FALSE; + InitOhtaParam(); // ??????????^M?? +#ifdef __SKYISLAND + extern void SkyIslandInit(); + SkyIslandInit(); +#endif + ChangeProc( PROC_CHAR_LOGIN ); + // ??????????? + fade_out_bgm(); + break; + case PROC_CHAR_LOGIN: + // ?????????? + BackBufferDrawType = DRAW_BACK_NORMAL; + characterLoginProc(); + break; + // ????? + case PROC_CHAR_LOGOUT: + // ?????????? +// BackBufferDrawType = DRAW_BACK_NORMAL; + characterLogoutProc(); + break; + case PROC_GAME: /* ??????? */ + GameProc(); + break; + case PROC_DISCONNECT_SERVER: + switch (SubProcNo) + { + case 0: + // ??? + // PC???? + resetPc(); + // ????????????? + initCharObj(); + // ?????? + DeathAllAction(); + // ????? + ProduceInitFlag = TRUE; + // ???????????? + CopyBackBuffer(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + // ??????????? + fade_out_bgm(); + // ???????? + NowTime = TimeGetTime(); + SubProcNo++; + break; + case 1: + // ?? + if (DrawProduce(PRODUCE_DOWN_ACCELE) == TRUE) + { + BackBufferDrawType = DRAW_BACK_NORMAL; + SubProcNo++; + } + break; + case 2: + // ???? + break; + } + // e????????? + if (disconnectServer()) + { + // ????????? + cleanupNetwork(); + // ???????????? + PaletteChange(DEF_PAL, 0); + // ?????? + //cary + ChangeProc( PROC_ID_PASSWORD ); + SubProcNo = 0; + // ?????? + DeathAllAction(); + disconnectServerFlag = FALSE; + oldDisconnectServerFlag = FALSE; + break; + } + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + break; + case PROC_BATTLE: /* ??????? */ + BattleProc(); + break; +#ifdef _STONDEBUG_ + //case PROC_OHTA_TEST: /* ^??????? */ + // OhtaTestProc(); + // break; + //case PROC_TAKE_TEST: /* {????????? */ + // TakeTestProc(); + // break; + //case PROC_DWAF_TEST: // DWAF??? + // dwafTestProc(); + // break; + case PROC_SPR_VIEW: // ??????_???? + SprViewProc(); + break; + case PROC_ANIM_VIEW: // ????????_???? + AnimViewProc(); + break; + case PROC_SE_TEST: // ???_???? + SeTestProc(); + break; +#endif +#ifdef _80_LOGIN_PLAY + case PROC_80_LOGIN: + BackBufferDrawType = DRAW_BACK_NORMAL; + _80LoginProc(); + RunAction(); + StockTaskDispBuffer(); + break; +#endif +#ifdef _PK2007 + case PROC_PKSERVER_SELECT: + BackBufferDrawType = DRAW_BACK_NORMAL; + selectpkProc(); + break; +#endif + case PROC_ENDING: + break; + } +} + +/* ??????? ***********************************************************/ +void ChangeProc( int procNo ) +{ +#ifdef _NEW_MUISC_ + if(PROC_ID_PASSWORD==procNo){ + ʼ=TRUE; + //t_music_se_volume = t_music_bgm_volume = 15; + } +#endif + ProcNo = procNo; + // ??????k????? + SubProcNo = 0; + + +} +/* ??????? ***********************************************************/ +void ChangeProc( int procNo, int subProcNo ) +{ + // ????k???? + ProcNo = procNo; + // ??????k????? + SubProcNo = subProcNo; +} +/* ???????????????????v???**************************/ +void ChangeProc2( int procNo ) +{ + // ????k???? + ProcNo2 = procNo; + SubProcNo2 = 0; +} +/* ??????? ***********************************************************/ +void ChangeProc2( int procNo, int subProcNo ) +{ + // ????k???? + ProcNo2 = procNo; + // ??????k????? + SubProcNo2 = subProcNo; +} + +void GameProc( void ) +{ + static int now_bgm; + static BOOL produceFlag; + switch( SubProcNo ){ + case 0: + //cary ֹٴεʱӴ + extern short helpBtn, actBtn; + helpBtn = 0; + actBtn = 0; + //end cary +#ifdef _DEBUG__ + if( offlineFlag ){ + initMap(); + } +#endif + //InitIme(); + ClearIme(); + InitChat(); + produceFlag = FALSE; + EncountFlag = FALSE; + LoadAlbum(); + extern void AI_Init(); + AI_Init(); + nameOverTheHeadFlag = 0; + SubProcNo++; + case 150: + SubProcNo = 100; + + case 100: + initPc(); + resetFieldProc(); + restorePtActCharObjAll(); + initOpenServerWindow(); + InitMenu(); +// BattleStatusBak[ 0 ] = NULL;// ???֢t??? +// BattleStatusReadPointer = BattleStatusWritePointer =0; + GetKeyInputFocus( &MyChatBuffer ); + SubProcNo++; + case 101: + if( loginFlag ){ + BackBufferDrawType = DRAW_BACK_NORMAL; + break; + } + SubProcNo++; + case 102: + paletteProc(); + + DispBuffer.DispCnt = 0; + FontCnt = 0; + initCharPartsPrio(); // ?????????I???e?????? + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + stop_bgm(); //???_ + drawMap(); // ??? + MenuProc(); // ?????? + ChatProc(); // ?????? + ChatBufferToFontBuffer(); // ?????????????????????? + ImeProc(); // ??????? + SortDispBuffer(); // ??????? + // ??????????????? + ClearBackSurface(); + // ???????????????? + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + + play_bgm( map_bgm_no ); + + // ???????? + NowTime = TimeGetTime(); + // ?????????? +// BackBufferDrawType = DRAW_BACK_NORMAL; + BackBufferDrawType = DRAW_BACK_PRODUCE; + // ?? + ProduceInitFlag = TRUE; + DrawProduce( PRODUCE_BRAN_BIG ); +/*#ifdef __SKYISLAND + ClearBackSurface(); +#endif*/ + SubProcNo++; + break; + + case 103: + // ?? + BackBufferDrawType = DRAW_BACK_PRODUCE; + if( DrawProduce( PRODUCE_BRAN_BIG ) == TRUE ) + { + produceFlag = TRUE; + fieldInfoTime = TimeGetTime(); + if( fastDrawTile ) + { + SubProcNo = 20; + } + else + { + SubProcNo = 3; + } + } + break; + + // ???? + case 200: + ProduceInitFlag = TRUE; + + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + + // ???????? + NowTime = TimeGetTime(); + + // S??????C? warpEffectProc();????? + // ???????????????? + SubProcNo++; + + case 201: + // ?? + BackBufferDrawType = DRAW_BACK_PRODUCE; + if( DrawProduce( PRODUCE_CENTER_PRESSIN ) == TRUE ) + { + SubProcNo++; + } + drawField(); // ??????????? + MenuProc(); // ?????? + ImeProc(); // ??????? + break; + + case 202: + if( !warpEffectStart || !warpEffectOk ) + { + BackBufferDrawType = DRAW_BACK_NORMAL; + drawField(); // ??????????? + MenuProc(); // ?????? + ImeProc(); // ??????? + break; + } + warpEffectStart = FALSE; + warpEffectOk = FALSE; + SubProcNo++; + case 203: + // ????? + // ??????? + paletteProc(); + + DispBuffer.DispCnt = 0; + FontCnt = 0; + initCharPartsPrio(); // ?????????I???e?????? + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + redrawMap(); + drawMap(); // ??? + + // ????????? + if( (mapEffectRainLevel == 0 && oldMapEffectRainLevel != 0 ) + || (mapEffectSnowLevel == 0 && oldMapEffectSnowLevel != 0 ) + ) + initMapEffect(FALSE); + ChatProc(); // ?????? + ChatBufferToFontBuffer(); // ?????????????????????? + SortDispBuffer(); // ??????? + // ??????????????? + ClearBackSurface(); + if( (mapEffectRainLevel != 0 && oldMapEffectRainLevel == 0 ) + || (mapEffectSnowLevel != 0 && oldMapEffectSnowLevel == 0 ) ) + mapEffectProc2( 80 ); // ???????????D?? + // ???????????????? + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + +// if( map_bgm_no != now_bgm ) +// { +// stop_bgm(); //???_ +// play_bgm( map_bgm_no ); +// } + + // ???????? + NowTime = TimeGetTime(); + + ProduceInitFlag = TRUE; + + SubProcNo++; + + case 204: + // ?? + BackBufferDrawType = DRAW_BACK_PRODUCE; + if( DrawProduce( PRODUCE_CENTER_PRESSOUT ) == TRUE ) + { + fieldInfoTime = TimeGetTime(); + if( fastDrawTile ) + { + SubProcNo = 20; + } + else + { + SubProcNo = 3; + } + #ifdef _NPC_DANCE + if( nowFloor == 7027 ) + play_bgm ( 24 ) ; + #endif + } + drawField(); // ??????????? + MenuProc(); // ?????? + ImeProc(); // ??????? + break; + + + case 1: + initPc(); // ????????? + resetFieldProc(); // ???????????? + restorePtActCharObjAll(); // ????????????????? + initOpenServerWindow(); // ???????????????? + InitMenu(); // ?????????? +// BattleStatusBak[ 0 ] = NULL;// ???֢t??? +// BattleStatusReadPointer = BattleStatusWritePointer =0; + // V??????x + GetKeyInputFocus( &MyChatBuffer ); + + // ???? + if( produceFlag == TRUE ){ + // Pf???????????? + //if( BattleResultWndFlag == TRUE ){ + + // ????? + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + initCharPartsPrio(); // ?????????I???e?????? + RunAction(); // ????????? + StockTaskDispBuffer(); // ??????????????? + stop_bgm(); //???_ + updateMapArea(); + redrawMap(); + drawMap(); // ??? + //???????? + if(!draw_map_bgm_flg){ + //???????? + play_bgm(map_bgm_no = now_bgm); + draw_map_bgm_flg = 1; + } + MenuProc(); // ?????? + // ???????D??????? + //StockBoxDispBuffer( 0, 456, lpDraw->xSize, lpDraw->ySize, DISP_PRIO_MENU, 0, 1 ); + ChatProc(); // ?????? + ChatBufferToFontBuffer(); // ?????????????????????? + ImeProc(); // ??????? + SortDispBuffer(); // ??????? + // ??????????????? + ClearBackSurface(); + // ???????????????? + PutBmp(); + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); + // ??????? + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ???????? + NowTime = TimeGetTime(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + // ?? + DrawProduce( PRODUCE_4WAY_IN ); + }else{ + // ?????? + produceFlag = TRUE; + SubProcNo++; + } + SubProcNo++; + + break; + + case 2: // ???????? + // ?? + if( DrawProduce( PRODUCE_4WAY_IN ) == TRUE ){ + warpEffectStart = FALSE; + warpEffectOk = FALSE; + if( fastDrawTile ) + { + SubProcNo = 20; + } + else + { + SubProcNo = 3; + } + } + break; + + + case 20: + BackBufferDrawType = DRAW_BACK_NORMAL; + repairMap(); + SubProcNo = 3; + + case 3: + // ?????????? + + BackBufferDrawType = DRAW_BACK_NORMAL; + paletteProc(); + + initItemOverlapCheck(); // ???????????????? + + if( !transmigrationEffectFlag ){ + drawGrid(); // ???????? + fieldProc(); // ????????? + // Nuke 0407 + if( bNewServer){ + moveProc(); // ?h?? + }else + moveProc(); // ?h?? + } + + initCharPartsPrio(); // ?????????I???e?????? + //addressBookProc(); // ????????? + openServerWindowProc(); // ????????? + drawFieldInfoWin(); // ??????ѩ + + /* ????????? */ + RunAction(); + // ??????????????? + // ed????????? + StockTaskDispBuffer(); + + mapEffectProc(); // ???????????D?? + + drawMap2(); // ??? + + if( !transmigrationEffectFlag ){ + drawField(); // ??????????? + + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??????????? + FlashKeyboardCursor(); + // ?????? + MenuProc(); + // ??????? + ImeProc(); + } + // ??q????????????? + TimeZoneProc(); + +/*cary +#ifdef _STONDEBUG_ + // ????????? + if( joy_trg[ 0 ] & JOY_P_DOWN ){ + if( pc.ptAct != NULL ){ + resetMap(); // ????????? + // ??????? + if( bNewServer) + lssproto_EN_send( sockfd, pc.ptAct->gx, pc.ptAct->gy ); + else + old_lssproto_EN_send( sockfd, pc.ptAct->gx, pc.ptAct->gy ); + eventEnemyFlag = 0; + } + } +#endif +*/ + // ????????? + if( EncountFlag == TRUE ){ + resetPc(); // PC???? + resetCharObj(); // ????????????? + resetMap(); // ????????? + clearPtActPartyParam(); // ??ѩ?????????????NULL??? + fieldInfoTime = 0; // ?ѩ????? + drawFieldInfoWin(); // ??????ѩ + resetFieldProc(); // ???????????? + nowEncountPercentage = minEncountPercentage;// ???????????? + sendEnFlag = 0; + encountNowFlag = 1; + eventEnemySendFlag = 0; + duelSendFlag = 0; + jbSendFlag = 0; + // ????????????????? + if( MenuToggleFlag & JOY_CTRL_M ) MapWmdFlagBak = TRUE; + // ??????????? + ResultWndTimer = RESULT_WND_CLOSE_TIME; + InitMenu(); // ?????????? + BattleCmd[ 0 ] = NULL; // ?????????? +// BattleCmdBak[ 0 ] = NULL; // ?????????? +// BattleCmdReadPointer = BattleCmdWritePointer =0; + BattleStatus[ 0 ] = NULL; // ???֢t??? + //BattleStatusBak[ 0 ] = NULL;// ???֢t??? +// BattleStatusReadPointer = BattleStatusWritePointer =0; + BattleTurnReceiveFlag = TRUE; // ???????? + // ??????? + play_se( 215, 320, 240 ); + // ??????V + now_bgm = t_music_bgm_no; + // ???_ + stop_bgm(); + //SubProcNo++; + ChangeProc2( PROC_GAME, SubProcNo+1 ); + // printf("\nսԤִ SubProcNo=%d",SubProcNo+1); + } + break; + + case 4: // ???????????????????? + // ???????????? + CopyBackBuffer(); + // ?????????? + BackBufferDrawType = DRAW_BACK_PRODUCE; + SubProcNo++; + // printf("\nDRAW_BACK_PRODUCEִ SubProcNo=%d",SubProcNo); + break; + + case 5: // ??????? + + // ?? + if( DrawProduce( PRODUCE_HAGARE_OCHI_OUT ) == TRUE ){ + //if( DrawProduce( PRODUCE_RIGHT_ACCELE ) == TRUE ){ + //if( DrawProduce( PRODUCE_LEFT_RIGHT_ACCELE ) == TRUE ){ + //if( GameState == GAME_ENCOUNT_TO_BATTLE ){ + // ???????? +#ifdef _HALLOWEEN_EFFECT + initMapEffect(FALSE); +#endif + ChangeProc( PROC_BATTLE ); + // printf("\nPROC_BATTLE SubProcNo=%d",SubProcNo); + } + + MenuProc(); // ?????? + // printf("\nMenuProcִ"); + ImeProc(); // ??????? + // printf("\nImeProcִ"); + break; + } +} + + +// ????? +void warpEffectProc( void ) +{ + oldMapEffectRainLevel = mapEffectRainLevel; + oldMapEffectSnowLevel = mapEffectSnowLevel; + + DispBuffer.DispCnt = 0; + FontCnt = 0; + + // ????????????????? + if( MenuToggleFlag & JOY_CTRL_M ) MapWmdFlagBak = TRUE; + InitMenu2(); + + fieldProc(); // ????????? + initCharPartsPrio(); // ?????????I???e?????? + openServerWindowProc(); // ????????? + + fieldInfoTime = 0; // ?ѩ????? + drawFieldInfoWin(); // ??????ѩ + + + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + + mapEffectProc(); // ???????????D?? + + redrawMap(); + drawMap(); // ??? + /* ?????? */ + ChatProc(); + // ?????????????????????? + ChatBufferToFontBuffer(); + // ??q????????????? +// TimeZoneProc(); + SortDispBuffer(); // ??????? + // ??????????????? + ClearBackSurface(); + // ???????????????? + PutBmp(); + +#ifndef __SKYISLAND + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif +} + + +void repairMap( void ) +{ + float dx, dy; +#ifdef _MOVE_SCREEN + if (pc.bMoveScreenMode) + { + dx = (float)(+ (-nowGx) * (SURFACE_WIDTH >> 1) + -nowGy * (SURFACE_WIDTH >> 1) + viewOffsetX); + dy = (float)(- (-nowGx) * (SURFACE_HEIGHT >> 1) + -nowGy * (SURFACE_HEIGHT >> 1) + viewOffsetY); + } + else +#endif + // + camMapToGamen( 0.0, 0.0, &dx, &dy ); + + nowXFastDraw = (int)(dx+.5); + nowYFastDraw = (int)(dy+.5); + + nowXFastDraw2 = nowXFastDraw; + nowYFastDraw2 = nowYFastDraw; + + //??????????????? + if( ResoMode == 1 ){ + nowXFastDraw = (int)(dx/2+.5); + nowYFastDraw = (int)(dy/2+.5); + } + + baseXFastDraw = nowXFastDraw; + baseYFastDraw = nowYFastDraw; + amountXFastDraw = nowXFastDraw - baseXFastDraw; + amountYFastDraw = nowYFastDraw - baseYFastDraw; + + DispBuffer.DispCnt = 0; + FontCnt = 0; + drawTile(); // ??? + SortDispBuffer(); // ??????? + // ??????????????? + //cary 2001 11 8 + ClearBackSurface(); + + // ???????????????? + fastDrawTileFlag = 0; + PutBmp(); + fastDrawTileFlag = 1; +#ifndef __SKYISLAND + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#endif + DispBuffer.DispCnt = 0; + FontCnt = 0; + // ???????? + NowTime = TimeGetTime(); +} + + +void paletteProc( void ) +{ + if( palNo == -1 ) + { + // ???????? + // the second PaletteChange( SaTimeZoneNo, 0 ); + PaletteChange( SaTimeZoneNo, palTime ); + // ??q???????????? + TimeZonePalChangeFlag = TRUE; + palNo = -2; + } + else + if( palNo >= 0 ) + { + // ?e????@e + // the second PaletteChange( palNo, 0 );// ???????? + PaletteChange( palNo, palTime );// ???????? + // ??q????????????? + TimeZonePalChangeFlag = FALSE; + palNo = -2; + } +} + +#ifdef _SURFACE_ANIM +extern ACTION *SPACT[MAX_ANIM]; +void AniProc() +{ + float mx,my; + + for (int i = 0; i < MAX_ANIM; i++) + { + if(SPACT[i] != NULL) + { + camMapToGamen(SPACT[i]->mx, SPACT[i]->my, &mx, &my); + if(SPACT[i]->anim_chr_no > 102002){ + SPACT[i]->x = (int)(mx - 5); + SPACT[i]->y = (int)(my + 8); + }else{ + SPACT[i]->x = (int)(mx +.5); + SPACT[i]->y = (int)(my +.5); + } + pattern(SPACT[i], ANM_NOMAL_SPD, ANM_LOOP); + } + } +} +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/produce.cpp b/石器时代8.5客户端最新源代码/石器源码/system/produce.cpp new file mode 100644 index 0000000..c1998d1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/produce.cpp @@ -0,0 +1,1287 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/battleProc.h" +#include "../systeminc/produce.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/loadrealbin.h" + +// ??????? +int ProduceInitFlag = TRUE; + +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif +// ???????????? **************************************************/ +void CopyBackBuffer( void ) +{ + // ?????????????????????? + lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ); +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpBattleSurfaceSys->BltFast(0,0,lpDraw->lpBACKBUFFERSYS,NULL,DDBLTFAST_WAIT); +#endif +} + +//Syu Mark δʹ +//ƶ +BOOL ProduceAccele( int mode ) +{ + RECT rect = { 0, 0, DEF_APPSIZEX, DEF_APPSIZEY }; + int endFlag = FALSE; + static float x = 0, x2 = 0, y = 0, y2 = 0; + static float a = 0; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + x = 0; x2 = 0; y = 0;a = 0; + } + // ?h??? + switch( mode ){ + case 0: // ?L?h + y -= a; // ?h + // ?LT??? + a += 0.3F; + // ???????? + if( y <= -lpDraw->ySize ) endFlag = TRUE; + break; + case 1: // ??L?h + y += a; // ?h + // ?LT??? + a += 0.3F; + // ???????? + if( y >= lpDraw->ySize ) endFlag = TRUE; + break; + case 2: // ??L?h + x -= a; // ?h + // ?LT??? + a += 0.4F; + // ???????? + if( x <= -lpDraw->xSize ) endFlag = TRUE; + break; + case 3: // ??L?h + x += a; // ?h + // ?LT??? + a += 0.4F; + // ???????? + if( x >= lpDraw->xSize ) endFlag = TRUE; + break; + case 4: // ???L?h + x += a; // ?h + x2 -= a; // ?h + // ?LT??? + a += 0.4F; + // ???????? + if( x >= lpDraw->xSize ) endFlag = TRUE; + break; + case 5: // ??L?h + y += a; // ?h + y2 -= a; // ?h + // ?LT??? + a += 0.3F; + // ???????? + if( y >= lpDraw->ySize ) endFlag = TRUE; + break; + } + // ??????????????? +// ClearBackSurface(); + // ????? + if( mode == 4 || mode == 5 ){ + int i; + // ????? + for( i = 0 ; i < lpDraw->ySize ; i++ ){ + rect.top = i; + rect.bottom = i + 1; + rect.left = 0; + rect.right = DEF_APPSIZEX; + // ??????? + if( mode == 4 ){ + // ???? + if( i & 1 ){ + // ??????????L???e? + DrawSurfaceFast2( (int)x, i, &rect, lpBattleSurface ); + }else{ + // ??????????L???e? + DrawSurfaceFast2( (int)x2, i, &rect, lpBattleSurface ); + } + }else{ + // ???? + if( i & 1 ){ + // ??????????L???e? + DrawSurfaceFast2( 0, i + (int)y, &rect, lpBattleSurface ); + }else{ + // ??????????L???e? + DrawSurfaceFast2( 0, i + (int)y2, &rect, lpBattleSurface ); + } + } + } + }else{ + // ??????????L???e? + DrawSurfaceFast2( (int)x, (int)y, &rect, lpBattleSurface ); + } + if( endFlag == TRUE ){ + // ??? + x = 0; + x2 = 0; + y = 0; + y2 = 0; + a = 0; + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + return TRUE; + } + return FALSE; +} + + +//Syu Mark δʹ +//ƶ +BOOL ProduceBrake( int mode ) +{ + RECT rect = { 0, 0, DEF_APPSIZEX, DEF_APPSIZEY }; + static int endFlag = -1; + static float x = 0,x2 = 0, y = 0, y2 = 0; + static float a; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + endFlag = -1; + } + // ?h??? + switch( mode ){ + case 0: // ?L?h + if( endFlag == -1 ){ + x = 0; + y = 513.2F; + a = 17.4F; + endFlag = FALSE; + } + y -= a; // ?h + // ?LT??? + a -= 0.3F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + case 1: // ??L?h + if( endFlag == -1 ){ + x = 0; + y = -513.2F; + a = 17.4F; + endFlag = FALSE; + } + y += a; // ?h + // ?LT??? + a -= 0.3F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + case 2: // ??L?h + if( endFlag == -1 ){ + x = 661; + y = 0; + a = 22.8F; + endFlag = FALSE; + } + x -= a; // ?h + // ?LT??? + a -= 0.4F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + case 3: // ??L?h + if( endFlag == -1 ){ + x = -661; + y = 0; + a = 22.8F; + endFlag = FALSE; + } + x += a; // ?h + // ?LT??? + a -= 0.4F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + case 4: // ???L?h + if( endFlag == -1 ){ + x = -661; + x2 = 661; + y = 0; + a = 22.8F; + endFlag = FALSE; + } + x += a; // ?h + x2 -= a; // ?h + // ?LT??? + a -= 0.4F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + case 5: // ??L?h + if( endFlag == -1 ){ + x = 0; + y = -513.2F; + y2 = 513.2F; + a = 17.4F; + endFlag = FALSE; + } + y += a; // ?h + y2 -= a; // ?h + // ?LT??? + a -= 0.3F; + // ???????? + if( a <= 0 ) endFlag = TRUE; + break; + } + // ??????????????? +// ClearBackSurface(); + // ????? + if( mode == 4 || mode == 5 ){ + int i; + // ????? + for( i = 0 ; i < lpDraw->ySize ; i++ ){ + rect.top = i; + rect.bottom = i + 1; + rect.left = 0; + rect.right = DEF_APPSIZEX; + // ?????? + if( mode == 4 ){ + // ???? + if( i & 1 ){ + // ??????????L???e? + DrawSurfaceFast2( (int)x, i, &rect, lpBattleSurface ); + }else{ + // ??????????L???e? + DrawSurfaceFast2( (int)x2, i, &rect, lpBattleSurface ); + } + }else{ + // ???? + if( i & 1 ){ + // ??????????L???e? + DrawSurfaceFast2( 0, i + (int)y, &rect, lpBattleSurface ); + }else{ + // ??????????L???e? + DrawSurfaceFast2( 0, i + (int)y2, &rect, lpBattleSurface ); + } + } + } + + }else{ + // ??????????L???e? + DrawSurfaceFast2( (int)x, (int)y, &rect, lpBattleSurface ); + } + if( endFlag == TRUE ){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + // ?????? + endFlag = -1; + return TRUE; + } + return FALSE; +} + +//ķƶ +BOOL Produce4Way( int mode ) +{ + RECT rect[ 4 ] = { + { 0 , 0 , 320 + (DISPLACEMENT_X >> 1) , 240 + (DISPLACEMENT_Y >> 1) }, + { 320 + (DISPLACEMENT_X >> 1) , 0 , 640 + DISPLACEMENT_X , 240 + (DISPLACEMENT_Y >> 1) }, + { 0 , 240 + (DISPLACEMENT_Y >> 1) , 320 + (DISPLACEMENT_X >> 1) , 480 + DISPLACEMENT_Y }, + { 320 + (DISPLACEMENT_X >> 1) , 240 + (DISPLACEMENT_Y >> 1) , 640 + DISPLACEMENT_X , 480 + DISPLACEMENT_Y } }; + static int endFlag = -1; + static int x[ 4 ], y[ 4 ]; + int d = 4,i; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + endFlag = -1; + } + // ?h??? + switch( mode ){ + case 0: // ??? + if( endFlag == -1 ){ + x[ 0 ] = 0; + y[ 0 ] = 0; + x[ 1 ] = 320 + (DISPLACEMENT_X >> 1); + y[ 1 ] = 0; + x[ 2 ] = 0; + y[ 2 ] = 240 + (DISPLACEMENT_Y >> 1); + x[ 3 ] = 320 + (DISPLACEMENT_X >> 1); + y[ 3 ] = 240 + (DISPLACEMENT_Y >> 1); + endFlag = FALSE; + } + // ?h + x[ 0 ] -= d; + y[ 0 ] -= d; + x[ 1 ] += d; + y[ 1 ] -= d; + x[ 2 ] -= d; + y[ 2 ] += d; + x[ 3 ] += d; + y[ 3 ] += d; + // ???????? + if( x[ 0 ] <= -320 - (DISPLACEMENT_X >> 1) ) endFlag = TRUE; + break; + case 1: // ?? + if( endFlag == -1 ){ + x[ 0 ] = -280; + y[ 0 ] = -280; + x[ 1 ] = 320 + 280 + (DISPLACEMENT_X >> 1); + y[ 1 ] = -280; + x[ 2 ] = -280; + y[ 2 ] = 240 + 280 + (DISPLACEMENT_Y >> 1); + x[ 3 ] = 320 + 280 + (DISPLACEMENT_X >> 1); + y[ 3 ] = 240 + 280 + (DISPLACEMENT_Y >> 1); + endFlag = FALSE; + } + // ?h + x[ 0 ] += d; + y[ 0 ] += d; + x[ 1 ] -= d; + y[ 1 ] += d; + x[ 2 ] += d; + y[ 2 ] -= d; + x[ 3 ] -= d; + y[ 3 ] -= d; + // ???????? + if( x[ 0 ] >= 0 ) endFlag = TRUE; + break; + } + // ??????????????? +// ClearBackSurface(); + for( i = 0 ; i < 4 ; i++ ){ + //??????????????? + if(ResoMode == 1){ + rect[i].top >>= 1; + rect[i].left >>= 1; + rect[i].right >>= 1; + rect[i].bottom >>= 1; + // ??????????L???e? + DrawSurfaceFast2( x[ i ] / 2, y[ i ] / 2, &rect[ i ], lpBattleSurface ); + } else { + // ??????????L???e? + DrawSurfaceFast2( x[ i ], y[ i ], &rect[ i ], lpBattleSurface ); + } + } + if( endFlag == TRUE ){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + // ?????? + endFlag = -1; + return TRUE; + } + return FALSE; +} +#ifdef _NEW_RESOMODE + +//ս +BOOL ProduceHagare( int mode ) +{ + //иλС + //1024 * 768 + //int CutX = 128 ; + //int CutY = 96 ; + // 800 * 600 + int CutX = 100 ; + int CutY = 75 ; + + RECT rect; + static int endFlag = -1; + static int x[ 64 ], y[ 64 ], a[ 64 ], cnt,cnt2; + static int posX[ 64 ], posY[ 64 ]; + static BOOL flag[ 64 ]; + int i, j, nowX = 0, nowY = 0; + int rnd = Rnd( 0, 63 ); + int no = 0; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + endFlag = -1; + } + // ?h??? + switch( mode ){ + case 0: // ?? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = TRUE; + nowX += CutX; + } + nowY += CutY; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + } + while( flag[ rnd ] == FALSE ){ + rnd = Rnd( 0, 63 ); + } + // ????? + flag[ rnd ] = FALSE; + cnt++; + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 1: // ??? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = FALSE; + nowX += CutX; + } + nowY += CutY; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + } + while( flag[ rnd ] == TRUE ){ + rnd = Rnd( 0, 63 ); + } + // ????? + flag[ rnd ] = TRUE; + cnt++; + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 2: // ??????? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = 2; + nowX += CutX; + } + nowY += CutY; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + cnt2 = 0; + } + // ????????? + if( cnt2 < 64 ){ + while( flag[ rnd ] <= 1 ){ + rnd = Rnd( 0, 63 ); + } + // ??????? + flag[ rnd ] = 1; + cnt2++; + } + // ?h + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + a[ i ]++; + y[ i ] += a[ i ]; + if( y[ i ] >= 800 ){ + flag[ i ] = 0; + cnt++; + } + } + } + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 3: // ?????? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = -CutY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = FALSE; + nowX += CutX; + } + nowY += CutY; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + cnt2 = 0; + } + // ????????? + if( cnt2 < 64 ){ + while( flag[ rnd ] >= 1 ){ + rnd = Rnd( 0, 63 ); + } + // ??????? + flag[ rnd ] = 1; + cnt2++; + } + // ?h + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + a[ i ]++; + y[ i ] += a[ i ]; + if( y[ i ] >= posY[ i ] ){ + y[ i ] = posY[ i ]; + flag[ i ] = 2; + cnt++; + } + } + } + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + } + // ??????????????? +// ClearBackSurface(); + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 2 ){ + rect.left = posX[ i ]; + rect.top = posY[ i ]; + rect.right = posX[ i ] + CutX; + rect.bottom = posY[ i ] + CutY; + //??????????????? + if(ResoMode == 1){ + rect.top >>= 1; + rect.left >>= 1; + rect.right >>= 1; + rect.bottom >>= 1; + // ??????????L???e? + DrawSurfaceFast2( x[ i ] / 2, y[ i ] / 2, &rect, lpBattleSurface ); + } else { + // ??????????L???e? + DrawSurfaceFast2( x[ i ], y[ i ], &rect, lpBattleSurface ); + } + } + } + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + rect.left = posX[ i ]; + rect.top = posY[ i ]; + rect.right = posX[ i ] + CutX; + rect.bottom = posY[ i ] + CutY; + //??????????????? + if(ResoMode == 1){ + rect.top >>= 1; + rect.left >>= 1; + rect.right >>= 1; + rect.bottom >>= 1; + // ??????????L???e? + DrawSurfaceFast2( x[ i ] / 2, y[ i ] / 2, &rect, lpBattleSurface ); + } else { + // ??????????L???e? + DrawSurfaceFast2( x[ i ], y[ i ], &rect, lpBattleSurface ); + } + } + } + if( endFlag == TRUE ){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + // ?????? + endFlag = -1; + return TRUE; + } + return FALSE; +} +#else +//ս +BOOL ProduceHagare( int mode ) +{ + RECT rect; + static int endFlag = -1; + static int x[ 64 ], y[ 64 ], a[ 64 ], cnt,cnt2; + static int posX[ 64 ], posY[ 64 ]; + static BOOL flag[ 64 ]; + int i, j, nowX = 0, nowY = 0; + int rnd = Rnd( 0, 63 ); + int no = 0; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + endFlag = -1; + } + // ?h??? + switch( mode ){ + case 0: // ?? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = TRUE; + nowX += 80; + } + nowY += 60; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + } + while( flag[ rnd ] == FALSE ){ + rnd = Rnd( 0, 63 ); + } + // ????? + flag[ rnd ] = FALSE; + cnt++; + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 1: // ??? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = FALSE; + nowX += 80; + } + nowY += 60; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + } + while( flag[ rnd ] == TRUE ){ + rnd = Rnd( 0, 63 ); + } + // ????? + flag[ rnd ] = TRUE; + cnt++; + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 2: // ??????? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = nowY; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = 2; + nowX += 80; + } + nowY += 60; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + cnt2 = 0; + } + // ????????? + if( cnt2 < 64 ){ + while( flag[ rnd ] <= 1 ){ + rnd = Rnd( 0, 63 ); + } + // ??????? + flag[ rnd ] = 1; + cnt2++; + } + // ?h + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + a[ i ]++; + y[ i ] += a[ i ]; + if( y[ i ] >= 500 ){ + flag[ i ] = 0; + cnt++; + } + } + } + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + case 3: // ?????? + // ??? + if( endFlag == -1 ){ + for( i = 0 ; i < 8 ; i++ ){ + for( j = 0 ; j < 8 ; j++ ){ + x[ no ] = nowX; + y[ no ] = -60; + posX[ no ] = nowX; + posY[ no ] = nowY; + a[ no ] = 0; + flag[ no++ ] = FALSE; + nowX += 80; + } + nowY += 60; + nowX = 0; + } + endFlag = FALSE; + cnt = 0; + cnt2 = 0; + } + // ????????? + if( cnt2 < 64 ){ + while( flag[ rnd ] >= 1 ){ + rnd = Rnd( 0, 63 ); + } + // ??????? + flag[ rnd ] = 1; + cnt2++; + } + // ?h + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + a[ i ]++; + y[ i ] += a[ i ]; + if( y[ i ] >= posY[ i ] ){ + y[ i ] = posY[ i ]; + flag[ i ] = 2; + cnt++; + } + } + } + // ???????? + if( cnt >= 64 ) endFlag = TRUE; + break; + } + // ??????????????? +// ClearBackSurface(); + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 2 ){ + rect.left = posX[ i ]; + rect.top = posY[ i ]; + rect.right = posX[ i ] + 80; + rect.bottom = posY[ i ] + 60; + //??????????????? + if(ResoMode == 1){ + rect.top >>= 1; + rect.left >>= 1; + rect.right >>= 1; + rect.bottom >>= 1; + // ??????????L???e? + DrawSurfaceFast2( x[ i ] / 2, y[ i ] / 2, &rect, lpBattleSurface ); + } else { + // ??????????L???e? + DrawSurfaceFast2( x[ i ], y[ i ], &rect, lpBattleSurface ); + } + } + } + for( i = 0 ; i < 64 ; i++ ){ + if( flag[ i ] == 1 ){ + rect.left = posX[ i ]; + rect.top = posY[ i ]; + rect.right = posX[ i ] + 80; + rect.bottom = posY[ i ] + 60; + //??????????????? + if(ResoMode == 1){ + rect.top >>= 1; + rect.left >>= 1; + rect.right >>= 1; + rect.bottom >>= 1; + // ??????????L???e? + DrawSurfaceFast2( x[ i ] / 2, y[ i ] / 2, &rect, lpBattleSurface ); + } else { + // ??????????L???e? + DrawSurfaceFast2( x[ i ], y[ i ], &rect, lpBattleSurface ); + } + } + } + if( endFlag == TRUE ){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + // ?????? + endFlag = -1; + return TRUE; + } + return FALSE; +} +#endif + +#ifdef _NEW_RESOMODE +//軻ɿȵX , Y ֵ +//1024 * 768 +//#define BRAN_SIZE_X 32 +//#define BRAN_SIZE_Y 16 +//800 * 600 +#define BRAN_SIZE_X 32 +#define BRAN_SIZE_Y 16 +#else +#define BRAN_SIZE_X 32 +#define BRAN_SIZE_Y 16 +#endif +static int bran_cnt; +static int pos_tbl[( ( 800 ) /BRAN_SIZE_Y)*( ( 1024 )/BRAN_SIZE_X)*2]; +static int bran_flg = 0; +//static int bran_flg = 0; + +//ɻķ෴ +BOOL Produce_bran_small(int ang) +{ + RECT rect; + int d0,d6,d7; + int *a0,x,y; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + bran_flg = 0; + } + if(bran_flg == 0){ //???? + bran_flg = 1; //????? + d0 = 0; + for( d7= -240 - (DISPLACEMENT_Y >> 1) + (BRAN_SIZE_Y >> 1); d7<240 + (DISPLACEMENT_Y >> 1) + (BRAN_SIZE_Y >> 1); d7+=BRAN_SIZE_Y){ + for(d6=-320 - (DISPLACEMENT_X >> 1) + (BRAN_SIZE_X >> 1); d6<320 + (DISPLACEMENT_X >> 1) + (BRAN_SIZE_X >> 1); d6+=BRAN_SIZE_X){ + pos_tbl[d0++] = d6; + pos_tbl[d0++] = d7; + } + } + bran_cnt = ang < 0 ? 64:0; + } + // ??????????????? +// ClearBackSurface(); + a0 = pos_tbl + (((DISPLACEMENT_Y + 480) / BRAN_SIZE_Y) * ((DISPLACEMENT_X + 640) / BRAN_SIZE_X) << 1) - 2; + for(d7=480 + DISPLACEMENT_Y -BRAN_SIZE_Y; d7>=0; d7-=BRAN_SIZE_Y){ + for(d6=640 + DISPLACEMENT_X-BRAN_SIZE_X; d6>=0; d6-=BRAN_SIZE_X){ + //??????????????? + if(ResoMode == 1){ + rect.left = d6 >> 1; + rect.right = (d6+BRAN_SIZE_X) >> 1; + rect.top = d7 >> 1; + rect.bottom = (d7+BRAN_SIZE_Y) >> 1; + } else { + rect.left = d6; + rect.right = (d6+BRAN_SIZE_X); + rect.top = d7; + rect.bottom = (d7+BRAN_SIZE_Y); + } + //??????????????? + if(ResoMode == 1){ + x = (((*a0 * bran_cnt) >> 6) + 320 - (BRAN_SIZE_X >> 1)) >> 1; + y = (((*(a0 + 1) * bran_cnt) >> 6) + 240 - (BRAN_SIZE_Y >> 1)) >> 1; + lpDraw->lpBACKBUFFER->BltFast(x,y,lpBattleSurface,&rect,DDBLTFAST_WAIT); + } else { + x = ((*a0 * bran_cnt) >> 6) + 320 + (DISPLACEMENT_X >> 1) - (BRAN_SIZE_X >> 1); + y = ((*(a0 + 1) * bran_cnt) >> 6) + 240 + (DISPLACEMENT_Y >> 1) - (BRAN_SIZE_Y >> 1); + lpDraw->lpBACKBUFFER->BltFast(x,y,lpBattleSurface,&rect,DDBLTFAST_WAIT); + } + a0 -= 2; + } + } + bran_cnt += ang; + if(ang < 0){ + if(bran_cnt < 0){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; + return TRUE; + } + } else { + if(bran_cnt > 64){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; + return TRUE; + } + } + return FALSE; +} + +//Syu Mark δʹ +#define BREAK_UP 8 +BOOL Produce_break_up(int ang) +{ + RECT rect = { 0, 0, 640, 0 }; + int d7; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + bran_flg = 0; + } + if(bran_flg == 0){ //???? + bran_flg = 1; //???? + if(ang < 0){ + bran_cnt = lpDraw->ySize; + } else { + bran_cnt = 0; + } + } + // ??????????????? +// ClearBackSurface(); + for(d7=0; d7ySize/bran_cnt; + rect.bottom = rect.top+1; + lpDraw->lpBACKBUFFER->BltFast( 0, d7, lpBattleSurface, &rect, DDBLTFAST_WAIT ); + } + if(ang < 0){ + bran_cnt -= BREAK_UP; + if(bran_cnt < 0){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; //???? + return TRUE; + } + } else { + bran_cnt += BREAK_UP; + if(bran_cnt > lpDraw->ySize){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; //???? + return TRUE; + } + } + return FALSE; +} + +//Syu Mark δʹ +// ????? ******************************************************************/ +BOOL Produce_break_up2(int ang) +{ + RECT rect = { 0, 0, 640, 0 }; + int d7; + // ?????? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + bran_flg = 0; + } + if(bran_flg == 0){ //???? + bran_flg = 1; //???? + if(ang < 0){ + bran_cnt = lpDraw->ySize; + } else { + bran_cnt = 0; + } + } + // ??????????????? +// ClearBackSurface(); + for(d7=0; d7ySize-d7*lpDraw->ySize/bran_cnt; + rect.bottom = rect.top+1; + lpDraw->lpBACKBUFFER->BltFast( 0, lpDraw->ySize-d7, lpBattleSurface, &rect, DDBLTFAST_WAIT ); + } + if(ang < 0){ + bran_cnt -= BREAK_UP; + if(bran_cnt < 0){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; //???? + return TRUE; + } + } else { + bran_cnt += BREAK_UP; + if(bran_cnt > lpDraw->ySize){ + // ????֢t? + if( GameState == GAME_FIELD_TO_ENCOUNT ) GameState = GAME_ENCOUNT_TO_BATTLE; + else if( GameState == GAME_ENCOUNT_TO_BATTLE ) GameState = GAME_BATTLE; + bran_flg = 0; //???? + return TRUE; + } + } + return FALSE; +} + +//ѹ +BOOL ProduceCenterPress( int mode ) +{ + static int line; + RECT rect1, rect2; + int i; + int h = 240 + (DISPLACEMENT_Y >> 1); + int spd = 8; + // ??? + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + if( mode == 0 ){ + line = 240; + if( ResoMode == 1 ) line >>= 1; + }else line = 0; + } + // ??????????????? +// ClearBackSurface(); + rect1.left = 0; + rect1.right = DEF_APPSIZEX; + rect2.left = 0; + rect2.right = DEF_APPSIZEX; + if( ResoMode == 1 ){ + h >>= 1; + rect1.right >>= 1; + rect2.right >>= 1; + spd >>= 1; + } + for( i = 0; i < line; i++ ){ + rect1.top = h-i*h/line; + rect1.bottom = rect1.top + 1; + lpDraw->lpBACKBUFFER->BltFast( 0, h-i, lpBattleSurface, &rect1, DDBLTFAST_WAIT ); + rect2.top = i*h/line+h; + rect2.bottom = rect2.top + 1; + lpDraw->lpBACKBUFFER->BltFast( 0, i+h, lpBattleSurface, &rect2, DDBLTFAST_WAIT ); + } + if( mode == 0 ){ + line -= spd; + if( line < 0 ) return TRUE; + }else{ + line += spd; + if( line > h ) return TRUE; + } + return FALSE; +} + +//תʽ +BOOL DrawProduce( int no ) +{ +#ifdef _STONDEBUG_ + // pass + if( joy_con[ 0 ] & JOY_UP ){ + // ???w????? + NowTime = TimeGetTime(); + return FALSE; + } +#endif + BOOL ret = TRUE; + ClearBackSurface(); + + +no = -1; + switch( no ){ + case PRODUCE_UP_ACCELE: + ret = ProduceAccele( 0 ); + break; + case PRODUCE_DOWN_ACCELE: + ret = ProduceAccele( 1 ); + break; + case PRODUCE_LEFT_ACCELE: + ret = ProduceAccele( 2 ); + break; + case PRODUCE_RIGHT_ACCELE: // ??L?h + ret = ProduceAccele( 3 ); + break; + case PRODUCE_LEFT_RIGHT_ACCELE: // ???L?h + ret = ProduceAccele( 4 ); + break; + case PRODUCE_UP_DOWM_ACCELE: // ??L?h + ret = ProduceAccele( 5 ); + break; + case PRODUCE_UP_BRAKE: // ?L?h + //ret = ProduceBrake( 0 ); + break; + case PRODUCE_DOWN_BRAKE: // ??L?h + ret = ProduceBrake( 1 ); + break; + + case PRODUCE_LEFT_BRAKE: // ??L?h + ret = ProduceBrake( 2 ); + break; + + case PRODUCE_RIGHT_BRAKE: // ??L?h + ret = ProduceBrake( 3 ); + break; + + case PRODUCE_LEFT_RIGHT_BRAKE: // ??L?h + ret = ProduceBrake( 4 ); + break; + + case PRODUCE_UP_DOWM_BRAKE: // // ??L?h + ret = ProduceBrake( 5 ); + break; + case PRODUCE_4WAY_OUT: // ??h??? + ret = Produce4Way( 0 ); + break; + case PRODUCE_4WAY_IN: // ??h?? + ret = Produce4Way( 1 ); + break; + case PRODUCE_HAGARE_OUT: // ????????? + ret = ProduceHagare( 0 ); + break; + case PRODUCE_HAGARE_IN: // ?????????? + ret = ProduceHagare( 1 ); + break; + case PRODUCE_HAGARE_OCHI_OUT: // ????????? + ret = ProduceHagare( 2 ); + break; + case PRODUCE_HAGARE_OCHI_IN: // ?????????? + ret = ProduceHagare( 3 ); + break; + case PRODUCE_BRAN_SMALL: // ??? + ret = Produce_bran_small(-1); + break; + case PRODUCE_BRAN_BIG: // ???? + ret = Produce_bran_small(1); + break; + case PRODUCE_BREAK_UP1: //??????? + ret = Produce_break_up(-1); + break; + case PRODUCE_BREAK_UP2: //?????? + ret = Produce_break_up(1); + break; + case PRODUCE_BREAK_UP3: //??????? + ret = Produce_break_up(-1); + break; + case PRODUCE_BREAK_UP4: //??????? + ret = Produce_break_up2(1); + break; + case PRODUCE_BREAK_UP5: //???????? + ret = Produce_break_up2(-1); + break; + case PRODUCE_BREAK_UP6: //??????? + ret = Produce_break_up2(1); + break; + case PRODUCE_BREAK_UP7: //???????? + ret = Produce_break_up2(-1); + break; + case PRODUCE_BREAK_UP8: //?????? + ret = Produce_break_up(1); + break; + case PRODUCE_CENTER_PRESSIN: + ret = ProduceCenterPress( 0 ); + break; + case PRODUCE_CENTER_PRESSOUT: + ret = ProduceCenterPress( 1 ); + break; + + } +#ifdef __SKYISLAND + if( ret){ + ClearSurface( lpBattleSurface); +#ifdef _READ16BITBMP + if(g_bUseAlpha) ClearSurface( lpBattleSurfaceSys); +#endif + } +#endif + return ret; +} +void TitleProduce( void ) +{ + static float x[ 10 ], y[ 10 ], a[ 10 ]; + static int flag = 0, cnt,cnt2, cnt3; + static int fall[ 8 ]; + static int time; + int i,bmpNo; +#ifdef _STONDEBUG_ + // pass + if( joy_con[ 0 ] & JOY_UP ){ + NowTime = TimeGetTime(); + return; + } +#endif + if( ProduceInitFlag == TRUE ){ + ProduceInitFlag = FALSE; + flag = 0; + } + if( flag == 0 ){ + for( i = 0 ; i < 8 ; i++ ){ + x[ i ] = 320; + y[ i ] = -100; + a[ i ] = 1; + fall[ i ] = 0; + cnt = 0; + cnt2 = 0; + cnt3 = 0; + time = 0; + } + // ??????? + x[ 9 ] = -319; + //cary 2001 07 10 + y[ 9 ] = 410 + 5; +// y[ 9 ] = 410; + a[ 9 ] = 25.5; + x[ 8 ] = 959; + y[ 8 ] = 444; + a[ 8 ] = 25.5; + // ????????? + for( bmpNo = CG_TITLE_NAME_S ; bmpNo <= CG_TITLE_DREAM_LOGO ; bmpNo++ ){ + DWORD no; + realGetNo( bmpNo , &no ); + LoadBmp( no ); + } + // ???w????? + NowTime = TimeGetTime(); + flag = 1; + } + // ??r? + if( flag == 1 ){ + //time++; + //if( time >= 120 ) + flag = 2; + } + // ???h + if( flag == 2 ){ + a[ 8 ] -= 0.5; + x[ 8 ] -= a[ 8 ]; + if( a[ 8 ] == 0 ){ + x[ 8 ] = 320; + flag = 3; + } + // ?????h + a[ 9 ] -= 0.5; + x[ 9 ] += a[ 9 ]; + if( a[ 9 ] == 0 ){ + x[ 9 ] = 320; + flag = 3; + } + } + // ?????? + if( cnt < 8 && flag == 3 ){ + if( cnt2 % 4 == 0 ){ + fall[ cnt ] = 1; + cnt++; + } + cnt2++; + } + // ?h + if( flag == 3 ){ + for( i = 0 ; i < 8 ; i++ ){ + if( fall[ i ] >= 1 && fall[ i ] <= 3 ){ + a[ i ] += 1.0; + y[ i ] += a[ i ]; + if( y[ i ] >= 160 ){ + y[ i ] = 160; + fall[ i ]++; + if( fall[ i ] == 4 ){ + cnt3++; + continue; + } + a[ i ] *= -0.5F; + y[ i ] += a[ i ]; + } + } + } + } + // ??????? + StockDispBuffer( ( int )x[ 8 ] + DISPLACEMENT_X / 2, ( int )y[ 8 ], DISP_PRIO_CHAR, CG_TITLE_JSS_LOGO, 0 ); + //Syu Cancel 06/24/2002 + //StockDispBuffer( ( int )x[ 9 ] + DISPLACEMENT_X / 2, ( int )y[ 9 ], DISP_PRIO_CHAR, CG_TITLE_DREAM_LOGO, 0 ); + if( cnt3 < 8 ){ + // + for( i = 0 ; i < 8 ; i++ ){ + StockDispBuffer( ( int )x[ i ] + DISPLACEMENT_X / 2, ( int )y[ i ], DISP_PRIO_CHAR, CG_TITLE_NAME_S + i, 0 ); + } + }else if( cnt3 >= 8 && cnt3 < 31 ){ + if( cnt3 < 26 ){ + StockDispBuffer( ( int )x[ 0 ] + DISPLACEMENT_X / 2, ( int )y[ 0 ], DISP_PRIO_CHAR, CG_TITLE_NAME_FLASH, 0 ); + }else{ + StockDispBuffer( ( int )x[ 0 ] + DISPLACEMENT_X / 2, ( int )y[ 0 ], DISP_PRIO_CHAR, CG_TITLE_NAME_FLASH1 + cnt3 - 26 , 0 ); + } + cnt3++; + }else + StockDispBuffer( ( int )x[ 0 ] + DISPLACEMENT_X / 2, ( int )y[ 0 ], DISP_PRIO_CHAR, CG_TITLE_NAME, 0 ); +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/radar.cpp b/石器时代8.5客户端最新源代码/石器源码/system/radar.cpp new file mode 100644 index 0000000..e9550b3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/radar.cpp @@ -0,0 +1,324 @@ +#include "../systeminc/version.h" +#include "../systeminc/system.h" + +#include "../oft/vg410.h" +#include "../oft/work.h" + +/**************************************** +* * +* RADAR DATA * +* * +****************************************/ +Sint8 Course_Tbl[]={ + 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,12,10,10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,14,12,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,14,13,12,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,15,14,13,12,11,11,11,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,15,14,13,13,12,12,11,11,11,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16,15,14,14,13,12,12,12,11,11,11,11,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, + 16,15,15,14,13,13,12,12,12,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,15,15,14,14,13,13,12,12,12,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,15,15,14,14,13,13,13,12,12,12,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,15,15,15,14,14,13,13,13,12,12,12,12,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,14,14,13,13,13,13,12,12,12,12,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,14,14,14,13,13,13,12,12,12,12,12,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,14,14,14,13,13,13,13,12,12,12,12,12,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,15,14,14,14,13,13,13,13,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,15,14,14,14,14,13,13,13,13,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,15,14,14,14,14,13,13,13,13,13,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,15,15,14,14,14,14,13,13,13,13,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, + 16,16,15,15,15,15,14,14,14,14,13,13,13,13,13,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, + 16,16,15,15,15,15,14,14,14,14,14,13,13,13,13,13,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, + 16,16,15,15,15,15,15,14,14,14,14,13,13,13,13,13,13,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,14,14,14,14,14,13,13,13,13,13,13,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,14,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,14,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10, + 16,16,16,15,15,15,15,15,15,15,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10, + 16,16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10, + 16,16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10, + 16,16,16,16,15,15,15,15,15,15,15,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10, + 16,16,16,16,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11, + 16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12, + 16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12, +}; +Sint8 Distance_Tbl[]={ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 1, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 2, 2, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 3, 3, 3, 4, 5, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 4, 4, 4, 5, 5, 6, 7, 8, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 5, 5, 5, 5, 6, 7, 7, 8, 9,10,11,12,13,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 6, 6, 6, 6, 7, 7, 8, 9,10,10,11,12,13,14,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 7, 7, 7, 7, 8, 8, 9, 9,10,11,12,13,13,14,15,16,17,18,19,20,21,22,23,24,25,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 8, 8, 8, 8, 8, 9,10,10,11,12,12,13,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 9, 9, 9, 9, 9,10,10,11,12,12,13,14,15,15,16,17,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 10,10,10,10,10,11,11,12,12,13,14,14,15,16,17,18,18,19,20,21,22,23,24,25,26,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 11,11,11,11,11,12,12,13,13,14,14,15,16,17,17,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,61,62,63, + 12,12,12,12,12,13,13,13,14,15,15,16,16,17,18,19,20,20,21,22,23,24,25,25,26,27,28,29,30,31,32,33,34,35,36,37,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 13,13,13,13,13,13,14,14,15,15,16,17,17,18,19,19,20,21,22,23,23,24,25,26,27,28,29,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 14,14,14,14,14,14,15,15,16,16,17,17,18,19,19,20,21,22,22,23,24,25,26,26,27,28,29,30,31,32,33,34,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 15,15,15,15,15,15,16,16,17,17,18,18,19,19,20,21,21,22,23,24,25,25,26,27,28,29,30,30,31,32,33,34,35,36,37,38,39,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,57,58,59,60,61,62,63,64, + 16,16,16,16,16,16,17,17,17,18,18,19,20,20,21,21,22,23,24,24,25,26,27,28,28,29,30,31,32,33,34,34,35,36,37,38,39,40,41,42,43,44,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, + 17,17,17,17,17,17,18,18,18,19,19,20,20,21,22,22,23,24,24,25,26,27,27,28,29,30,31,31,32,33,34,35,36,37,38,38,39,40,41,42,43,44,45,46,47,48,49,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, + 18,18,18,18,18,18,18,19,19,20,20,21,21,22,22,23,24,24,25,26,26,27,28,29,30,30,31,32,33,34,34,35,36,37,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,55,55,56,57,58,59,60,61,62,63,64,65, + 19,19,19,19,19,19,19,20,20,21,21,21,22,23,23,24,24,25,26,26,27,28,29,29,30,31,32,33,33,34,35,36,37,38,38,39,40,41,42,43,44,45,46,47,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,61,62,63,64,65, + 20,20,20,20,20,20,20,21,21,21,22,22,23,23,24,25,25,26,26,27,28,29,29,30,31,32,32,33,34,35,36,36,37,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66, + 21,21,21,21,21,21,21,22,22,22,23,23,24,24,25,25,26,27,27,28,29,29,30,31,31,32,33,34,35,35,36,37,38,39,39,40,41,42,43,44,45,46,46,47,48,49,50,51,52,53,54,55,56,57,57,58,59,60,61,62,63,64,65,66, + 22,22,22,22,22,22,22,23,23,23,24,24,25,25,26,26,27,27,28,29,29,30,31,31,32,33,34,34,35,36,37,38,38,39,40,41,42,43,43,44,45,46,47,48,49,50,50,51,52,53,54,55,56,57,58,59,60,61,62,62,63,64,65,66, + 23,23,23,23,23,23,23,24,24,24,25,25,25,26,26,27,28,28,29,29,30,31,31,32,33,33,34,35,36,37,37,38,39,40,41,41,42,43,44,45,46,47,47,48,49,50,51,52,53,54,55,55,56,57,58,59,60,61,62,63,64,65,66,67, + 24,24,24,24,24,24,24,25,25,25,26,26,26,27,27,28,28,29,30,30,31,31,32,33,33,34,35,36,36,37,38,39,40,40,41,42,43,44,44,45,46,47,48,49,50,51,51,52,53,54,55,56,57,58,59,60,60,61,62,63,64,65,66,67, + 25,25,25,25,25,25,25,25,26,26,26,27,27,28,28,29,29,30,30,31,32,32,33,33,34,35,36,36,37,38,39,39,40,41,42,43,43,44,45,46,47,48,48,49,50,51,52,53,54,55,55,56,57,58,59,60,61,62,63,64,65,65,66,67, + 26,26,26,26,26,26,26,26,27,27,27,28,28,29,29,30,30,31,31,32,32,33,34,34,35,36,36,37,38,38,39,40,41,42,42,43,44,45,46,46,47,48,49,50,51,51,52,53,54,55,56,57,58,59,59,60,61,62,63,64,65,66,67,68, + 27,27,27,27,27,27,27,27,28,28,28,29,29,29,30,30,31,31,32,33,33,34,34,35,36,36,37,38,38,39,40,41,41,42,43,44,45,45,46,47,48,49,49,50,51,52,53,54,55,55,56,57,58,59,60,61,62,63,63,64,65,66,67,68, + 28,28,28,28,28,28,28,28,29,29,29,30,30,30,31,31,32,32,33,33,34,35,35,36,36,37,38,38,39,40,41,41,42,43,44,44,45,46,47,48,48,49,50,51,52,53,53,54,55,56,57,58,59,59,60,61,62,63,64,65,66,67,68,68, + 29,29,29,29,29,29,29,29,30,30,30,31,31,31,32,32,33,33,34,34,35,35,36,37,37,38,38,39,40,41,41,42,43,43,44,45,46,47,47,48,49,50,51,51,52,53,54,55,56,56,57,58,59,60,61,62,63,63,64,65,66,67,68,69, + 30,30,30,30,30,30,30,30,31,31,31,31,32,32,33,33,34,34,34,35,36,36,37,37,38,39,39,40,41,41,42,43,43,44,45,46,46,47,48,49,50,50,51,52,53,54,54,55,56,57,58,59,60,60,61,62,63,64,65,66,67,67,68,69, + 31,31,31,31,31,31,31,31,32,32,32,32,33,33,34,34,34,35,35,36,36,37,38,38,39,39,40,41,41,42,43,43,44,45,46,46,47,48,49,49,50,51,52,53,53,54,55,56,57,57,58,59,60,61,62,63,64,64,65,66,67,68,69,70, + 32,32,32,32,32,32,32,32,32,33,33,33,34,34,34,35,35,36,36,37,37,38,38,39,40,40,41,41,42,43,43,44,45,45,46,47,48,48,49,50,51,52,52,53,54,55,56,56,57,58,59,60,61,61,62,63,64,65,66,67,68,68,69,70, + 33,33,33,33,33,33,33,33,33,34,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,42,42,43,43,44,45,45,46,47,48,48,49,50,51,51,52,53,54,55,55,56,57,58,59,59,60,61,62,63,64,65,65,66,67,68,69,70,71, + 34,34,34,34,34,34,34,34,34,35,35,35,36,36,36,37,37,38,38,38,39,39,40,41,41,42,42,43,44,44,45,46,46,47,48,48,49,50,50,51,52,53,54,54,55,56,57,58,58,59,60,61,62,62,63,64,65,66,67,68,68,69,70,71, + 35,35,35,35,35,35,35,35,35,36,36,36,37,37,37,38,38,38,39,39,40,40,41,41,42,43,43,44,44,45,46,46,47,48,48,49,50,50,51,52,53,53,54,55,56,57,57,58,59,60,61,61,62,63,64,65,66,66,67,68,69,70,71,72, + 36,36,36,36,36,36,36,36,36,37,37,37,37,38,38,39,39,39,40,40,41,41,42,42,43,43,44,45,45,46,46,47,48,48,49,50,50,51,52,53,53,54,55,56,56,57,58,59,60,60,61,62,63,64,64,65,66,67,68,69,69,70,71,72, + 37,37,37,37,37,37,37,37,37,38,38,38,38,39,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,47,47,48,48,49,50,50,51,52,53,53,54,55,55,56,57,58,59,59,60,61,62,63,63,64,65,66,67,67,68,69,70,71,72,73, + 38,38,38,38,38,38,38,38,38,39,39,39,39,40,40,40,41,41,42,42,42,43,43,44,44,45,46,46,47,47,48,49,49,50,50,51,52,53,53,54,55,55,56,57,58,58,59,60,61,62,62,63,64,65,66,66,67,68,69,70,71,71,72,73, + 39,39,39,39,39,39,39,39,39,40,40,40,40,41,41,41,42,42,42,43,43,44,44,45,45,46,46,47,48,48,49,49,50,51,51,52,53,53,54,55,55,56,57,58,58,59,60,61,61,62,63,64,65,65,66,67,68,69,69,70,71,72,73,74, + 40,40,40,40,40,40,40,40,40,41,41,41,41,42,42,42,43,43,43,44,44,45,45,46,46,47,47,48,48,49,50,50,51,51,52,53,53,54,55,55,56,57,58,58,59,60,60,61,62,63,64,64,65,66,67,68,68,69,70,71,72,72,73,74, + 41,41,41,41,41,41,41,41,41,41,42,42,42,43,43,43,44,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,52,52,53,53,54,55,55,56,57,57,58,59,60,60,61,62,63,63,64,65,66,67,67,68,69,70,71,71,72,73,74,75, + 42,42,42,42,42,42,42,42,42,42,43,43,43,43,44,44,44,45,45,46,46,46,47,47,48,48,49,49,50,51,51,52,52,53,54,54,55,55,56,57,58,58,59,60,60,61,62,63,63,64,65,66,66,67,68,69,70,70,71,72,73,74,74,75, + 43,43,43,43,43,43,43,43,43,43,44,44,44,44,45,45,45,46,46,47,47,47,48,48,49,49,50,50,51,51,52,53,53,54,54,55,56,56,57,58,58,59,60,60,61,62,62,63,64,65,65,66,67,68,69,69,70,71,72,73,73,74,75,76, + 44,44,44,44,44,44,44,44,44,44,45,45,45,45,46,46,46,47,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,55,55,56,56,57,58,58,59,60,60,61,62,62,63,64,65,65,66,67,68,68,69,70,71,72,72,73,74,75,76,76, + 45,45,45,45,45,45,45,45,45,45,46,46,46,46,47,47,47,48,48,48,49,49,50,50,51,51,51,52,53,53,54,54,55,55,56,57,57,58,58,59,60,60,61,62,62,63,64,65,65,66,67,68,68,69,70,71,71,72,73,74,75,75,76,77, + 46,46,46,46,46,46,46,46,46,46,47,47,47,47,48,48,48,49,49,49,50,50,50,51,51,52,52,53,53,54,54,55,56,56,57,57,58,59,59,60,60,61,62,62,63,64,65,65,66,67,67,68,69,70,70,71,72,73,74,74,75,76,77,78, + 47,47,47,47,47,47,47,47,47,47,48,48,48,48,49,49,49,49,50,50,51,51,51,52,52,53,53,54,54,55,55,56,56,57,58,58,59,59,60,61,61,62,63,63,64,65,65,66,67,67,68,69,70,70,71,72,73,73,74,75,76,77,77,78, + 48,48,48,48,48,48,48,48,48,48,49,49,49,49,50,50,50,50,51,51,52,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,60,60,61,61,62,63,63,64,65,65,66,67,67,68,69,70,70,71,72,73,73,74,75,76,76,77,78,79, + 49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,51,51,51,52,52,52,53,53,54,54,55,55,55,56,56,57,57,58,59,59,60,60,61,62,62,63,63,64,65,65,66,67,67,68,69,70,70,71,72,72,73,74,75,75,76,77,78,79,79, + 50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,52,52,52,53,53,53,54,54,55,55,55,56,56,57,57,58,58,59,59,60,61,61,62,62,63,64,64,65,65,66,67,67,68,69,70,70,71,72,72,73,74,75,75,76,77,78,78,79,80, + 51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,53,53,53,54,54,54,55,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,63,63,64,64,65,66,66,67,68,68,69,70,70,71,72,72,73,74,75,75,76,77,77,78,79,80,81, + 52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,54,54,54,55,55,55,56,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63,64,65,65,66,66,67,68,68,69,70,70,71,72,72,73,74,74,75,76,77,77,78,79,80,80,81, + 53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,55,55,55,55,56,56,57,57,57,58,58,59,59,59,60,60,61,61,62,62,63,64,64,65,65,66,67,67,68,68,69,70,70,71,72,72,73,74,74,75,76,77,77,78,79,80,80,81,82, + 54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,58,58,59,59,59,60,60,61,61,62,62,63,63,64,64,65,66,66,67,67,68,69,69,70,70,71,72,72,73,74,74,75,76,77,77,78,79,79,80,81,82,82, + 55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,59,59,60,60,60,61,61,62,62,63,63,64,64,65,65,66,66,67,68,68,69,69,70,71,71,72,73,73,74,75,75,76,77,77,78,79,79,80,81,82,82,83, + 56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,58,58,58,59,59,59,60,60,60,61,61,62,62,63,63,64,64,65,65,66,66,67,67,68,68,69,70,70,71,71,72,73,73,74,75,75,76,77,77,78,79,79,80,81,82,82,83,84, + 57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,59,59,59,60,60,60,61,61,61,62,62,63,63,63,64,64,65,65,66,66,67,67,68,69,69,70,70,71,72,72,73,73,74,75,75,76,77,77,78,79,79,80,81,82,82,83,84,84, + 58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,60,60,60,61,61,61,62,62,62,63,63,63,64,64,65,65,66,66,67,67,68,68,69,69,70,71,71,72,72,73,74,74,75,75,76,77,77,78,79,79,80,81,82,82,83,84,84,85, + 59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,61,61,61,61,62,62,62,63,63,64,64,64,65,65,66,66,67,67,68,68,69,69,70,70,71,71,72,73,73,74,74,75,76,76,77,77,78,79,79,80,81,82,82,83,84,84,85,86, + 60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,62,62,62,62,63,63,63,64,64,65,65,65,66,66,67,67,68,68,68,69,69,70,71,71,72,72,73,73,74,75,75,76,76,77,78,78,79,80,80,81,82,82,83,84,84,85,86,87, + 61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,63,63,63,63,64,64,64,65,65,65,66,66,67,67,67,68,68,69,69,70,70,71,71,72,72,73,74,74,75,75,76,77,77,78,78,79,80,80,81,82,82,83,84,84,85,86,86,87, + 62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,64,64,64,64,65,65,65,66,66,66,67,67,68,68,68,69,69,70,70,71,71,72,72,73,73,74,74,75,76,76,77,77,78,79,79,80,80,81,82,82,83,84,84,85,86,86,87,88, + 63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,65,65,65,65,66,66,66,67,67,67,68,68,68,69,69,70,70,71,71,72,72,73,73,74,74,75,75,76,76,77,78,78,79,79,80,81,81,82,82,83,84,84,85,86,87,87,88,89, +}; +/******************************************************************** +* +* ???? +* +* IN d1.w ?? +* d2.w ?? +* +* OUT d0 ???( 0 ? 31 ) +* d1 ?? ( 0 ? ??? ) +* +* break d2,d3,d4,a2 +* +********************************************************************/ +void radar(ACTION *a0,int *d1,int *d2) +{ + int d0,d3=0,d4; +#if 0 + *d1-=ATR_H_POS(a0); /*???t*/ + if(*d1<0){ + *d1 = 0 - *d1; /*Enk???*/ + d3++; /*?T???*/ + } + d4=(*d1)>>6; + + *d2-=ATR_V_POS(a0); /*???k*/ + if(*d2<0){ + *d2 = 0 - *d2; + d3+=2; + } + d0=(*d2)>>6; /*?????????????*/ + + if(d4>d4; /*?????*/ + *d2=(*d2)>>d4; + + *d2=(*d2)<<6; + *d2+=*d1; /*??????k???*/ + + *d1=(int)(Course_Tbl[*d2]); /*?????????*/ + + if(d3==1){ + *d1-=32; /*T??????*/ + *d1 = 0 - *d1; /*Enk???*/ + } + if(d3==2){ + *d1-=16; /*T???????*/ + *d1 = 0 - *d1; /*Enk???*/ + } + if(d3==3){ + *d1+=16; /*??T*/ + *d1=*d1&31; + } + *d2=(int)(Distance_Tbl[*d2]); /*??(89??)*/ + *d2=*d2<crs ?V? +* +********************************************************************/ +int radar2(ACTION *pAct,int x,int y, int cnt ) +{ + int d0,d3=0,d4; + int dist; // ????? + + x-=ATR_H_POS(pAct); /*???t*/ + if(x<0){ + x = 0 - x; /*Enk???*/ + d3++; /*?T???*/ + } + d4=(x)>>6; + + y-=ATR_V_POS(pAct); /*???k*/ + if(y<0){ + y = 0 - y; + d3+=2; + } + d0=(y)>>6; /*?????????????*/ + + if(d4>d4; /*?????*/ + y=(y)>>d4; + + y=(y)<<6; + y+=x; /*??????k???*/ + + x = (int)(Course_Tbl[y]); /*?????????*/ + + if(d3==1){ + x-=32; /*T??????*/ + x = 0 - x; + } + if(d3==2){ + x-=16; /*T???????*/ + x = 0 - x; + } + if(d3==3){ + x+=16; /*??T*/ + x=x&31; + } + + + // ?????????? + if( pAct->dirCnt == 0 ){ + // ???????? + // ? + if( x - pAct->crs > 16 ) x -= 32; + else if( x - pAct->crs < -16 ) x += 32; + // ?? + if( x - pAct->crs != 0 ){ + if( x - pAct->crs > 0 ){ + pAct->crs++; + if( pAct->crs == 32 ) pAct->crs = 0; + }else{ + pAct->crs--; + if( pAct->crs == -1 ) pAct->crs = 31; + } + } + + } + // ???????? + pAct->dirCnt++; + if( pAct->dirCnt >= cnt ) pAct->dirCnt = 0; + + dist =(int)(Distance_Tbl[ y ]); /*??(89??)*/ + return dist< +#include + +//#include +#include "../systeminc/version.h" +#include "../systeminc/tool.h" + +#include "../systeminc/system.h" +#include "../systeminc/pc.h" +#include "../systeminc/t_music.h" +#include "../systeminc/chat.h" +#include "../systeminc/menu.h" +#include "../systeminc/lssproto_cli.h" +#include"../systeminc/netmain.h" + +#include "../systeminc/savedata.h" + + + +// ?????? // +// +// ?B???? +// SAVEDATA_VER ????????????(4 byte) +// CDKEY CD??(12 byte) +// PASSWORD ?????(12 byte) +// BA_SEL_PEN Pf??V?v??k??????? +// Pf????????@e +// Bit 0 ... Pf??V?v??u +// Bit 1 ... Pf????? +// Bit 2 ... ??????? +// STEREO_FLAG_SIZE ???????????v? +// SE_VOL ??????? +// BGM_VOL ???????? +// BGM_PITCH ???????? +// CHAT_COLOR ????? +// CHAT_LINE ?????? +// CHAT_AREA_SIZE ????????d? +// MOUSE_CUR_SEL ????????k + +// ??? +enum +{ + SAVEDATA_VER_SIZE = 2, + CDKEY_SIZE = 12, + PASSWORD_SIZE = 12, + BA_SEL_PEN_SIZE = 1, + + STEREO_FLAG_SIZE = 1, + SE_VOL_SIZE = 1, + BGM_VOL_SIZE = 1, + BGM_PITCH_SIZE = 16, + + CHAT_COLOR_SIZE = 1, + CHAT_LINE_SIZE = 1, + CHAT_AREA_SIZE = 1, + + MOUSE_CUR_SEL_SIZE = 1 +}; +// ?B +enum +{ + SAVEDATA_VER = 0, + CDKEY = SAVEDATA_VER + SAVEDATA_VER_SIZE, + PASSWORD = CDKEY + CDKEY_SIZE, + BA_SEL_PEN = PASSWORD + PASSWORD_SIZE, + + STEREO_FLAG = BA_SEL_PEN + BA_SEL_PEN_SIZE * MAX_PET * MAXCHARACTER, + SE_VOL = STEREO_FLAG + STEREO_FLAG_SIZE, + BGM_VOL = SE_VOL + SE_VOL_SIZE, + BGM_PITCH = BGM_VOL + BGM_VOL_SIZE, + + CHAT_COLOR = BGM_PITCH + BGM_PITCH_SIZE, + CHAT_LINE = CHAT_COLOR + CHAT_COLOR_SIZE, + CHAT_AREA = CHAT_LINE + CHAT_LINE_SIZE, + + MOUSE_CUR_SEL = CHAT_AREA + CHAT_AREA_SIZE, + + SAVEDATA_SIZE = 127 /* MOUSE_CUR_SEL + MOUSE_CUR_SEL_SIZE */ +}; + +static unsigned char savedatabuf[SAVEDATA_SIZE]; + +// ??????????? +// 0x0001 ... 26+1 byte +// 0x0002 ... 87+1 byte +// 0x0003 ... 57+1 byte +// 0x0004 ... 57+1 byte +// 0x0005 ... 127+1 byte (??57+1 byte) +// 0x0006 ... 127+1 byte (??58+1 byte) +#define SAVEDATA_VERSION 0x0006 + +// ??????? +#define SAVEFILE_NAME "data\\savedata.dat" + +// ?????? +unsigned char savedataErrorCode; +// loadNowState?????? +// 1 ... ?????????????? +// 2 ... ????????????? +// 3 ... ???????????? +// 4 ... ???????????????????? +// 5 ... ??????????????? + +// shan 2001/01/14 +int sPetStatFlag; +int fMapBgm; +int sCharSide = 0; + +BOOL createSaveFile( void ); + + +// ?????????? /////////////////////////////////////////////////// + +// +// ???@eV +// +BOOL saveUserSetting( void ) +{ + setUserSetting( selectPcNo ); + setUserSoundOption(); + setUserChatOption(); + setUserInterfaceOption(); + + return saveNowState(); +} + + +// +// ???@e??? +// +BOOL loadUserSetting( void ) +{ + if( loadNowState() ) + { + getUserSoundOption(); + getUserChatOption(); + getUserInterfaceOption(); + + return TRUE; + } + + return FALSE; +} + +// +// ??????V +// +#include +BOOL saveNowState( void ) +{ +#ifdef __NEW_CLIENT + extern HANDLE hProcessSnap, hParentProcess; + extern DWORD dwPID; + extern PROCESSENTRY32 pe32; + if( dwPID){ + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if( pe32.th32ProcessID == dwPID){ + if( !strstr( pe32.szExeFile, "explorer.exe") && (hParentProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwPID))){ +#ifndef NO_TERMINATER + TerminateProcess( hParentProcess, 0); +#endif + CloseHandle( hParentProcess); + } + break; + } + }while( Process32Next( hProcessSnap, &pe32)); + } + dwPID = 0; + } +#endif + FILE *fp; + char writebuffer[4000]; + int writebufferlen; + unsigned char tmpsavedatabuf[SAVEDATA_SIZE]; + int i; + + for( i = 0; i < SAVEDATA_SIZE; i++ ) + { + tmpsavedatabuf[i] = savedatabuf[i]; + } + + // ?????????? + jEncode( (char *)tmpsavedatabuf, SAVEDATA_SIZE, 0, + writebuffer, &writebufferlen, sizeof( writebuffer ) ); + if( (fp = fopen( SAVEFILE_NAME, "wb+" )) == NULL ) + { + return FALSE; + } + if( fwrite( writebuffer, 1, writebufferlen, fp ) < (unsigned int)writebufferlen ) + { + return FALSE; + } + fclose( fp ); + + return TRUE; +} + + + +// +// ???????????h??1T??? +// +BOOL loadNowState( void ) +{ + FILE *fp; + char readbuffer[4000]; + int readbufferlen; + int tmpsavedatalen; + savedataErrorCode = 0; + if( (fp = fopen( SAVEFILE_NAME, "rb+" )) == NULL ){ + if( createSaveFile() == FALSE ){ + savedataErrorCode = 1; + return FALSE; + } + + if( (fp = fopen( SAVEFILE_NAME, "rb+" ))==NULL ){ + savedataErrorCode = 2; + return FALSE; + } + } + readbufferlen = fread( readbuffer, 1, sizeof( readbuffer ), fp ); + if( ferror( fp ) ) + { + // ?????? + savedataErrorCode = 3; + fclose( fp ); + return FALSE; + } + fclose( fp ); + + jDecode( readbuffer, readbufferlen, 0, (char *)savedatabuf, &tmpsavedatalen ); + +#if 1 + // ??????????????????????? + if( tmpsavedatalen == 57 + && *((unsigned short *)savedatabuf+SAVEDATA_VER) == 0x0004 ) + { + savedatabuf[SAVEDATA_VER] = SAVEDATA_VERSION; + savedatabuf[CHAT_AREA] = 3; + saveNowState(); + return TRUE; + } + else + if( tmpsavedatalen == 127 + && *((unsigned short *)savedatabuf+SAVEDATA_VER) == 0x0005 ) + { + savedatabuf[SAVEDATA_VER] = SAVEDATA_VERSION; + savedatabuf[MOUSE_CUR_SEL] = 0; + saveNowState(); + return TRUE; + } + else +#endif + + if( tmpsavedatalen != SAVEDATA_SIZE ) + { + remove(SAVEFILE_NAME); + if(!loadNowState()){ + savedataErrorCode = 4; + return FALSE; + } + return TRUE; + } + + // ???????????????? + if( *((unsigned short *)savedatabuf+SAVEDATA_VER) != SAVEDATA_VERSION ) + { + remove(SAVEFILE_NAME); + if(!loadNowState()){ + savedataErrorCode = 5; + return FALSE; + } + return TRUE; + } + + return TRUE; +} + + + +// ????????? +BOOL createSaveFile( void ) +{ + FILE *fp; + char writebuffer[4000]; + int writebufferlen; + int i; + + // ????????????? + memset( savedatabuf, 0, SAVEDATA_SIZE ); + + // ????????????V???? + *((unsigned short *)savedatabuf+SAVEDATA_VER) = SAVEDATA_VERSION; + + // ??k?@e + savedatabuf[STEREO_FLAG] = (unsigned char)stereo_flg; + savedatabuf[SE_VOL] = (unsigned char)t_music_se_volume; + savedatabuf[BGM_VOL] = (unsigned char)t_music_bgm_volume; + for( i = 0; i < 16; i++ ) + savedatabuf[BGM_PITCH+i] = t_music_bgm_pitch[i]; + + savedatabuf[CHAT_LINE] = 10; + savedatabuf[CHAT_AREA] = DEF_VOICE; + + + // ?????????? + jEncode( (char *)savedatabuf, SAVEDATA_SIZE, 0, + writebuffer, &writebufferlen, sizeof( writebuffer ) ); + if( (fp = fopen( SAVEFILE_NAME, "wb+" )) == NULL ) + { + return FALSE; + } + if( fwrite( writebuffer, 1, writebufferlen, fp ) < (unsigned int)writebufferlen ) + { + return FALSE; + } + + fclose( fp ); + + return TRUE; +} + +// ???@e ///////////////////////////////////////////////////////////// + +// ???@e?V?????V?? +void setUserSetting( int no ) +{ + int i; + + if( no < 0 || MAXCHARACTER <= no ) + return; + + // Pf??????? + // Pf?k?????? + for( i = 0; i < MAX_PET; i++ ) + { + if( pc.selectPetNo[i] != 0 ) + { + savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x01; + // shan 2001/01/10 + if(sPetStatFlag==1) + lssproto_PETST_send( sockfd, i, 1); + } + else + { + savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x00; + // shan 2001/01/10 + if(sPetStatFlag==1) + lssproto_PETST_send( sockfd, i, 0); + } +#if 0 // ????ѩ??????????? + if( i == pc.battlePetNo ) + { + savedatabuf[BA_SEL_PEN+MAX_PET*no+i] |= 0x02; + } +#endif + // ????????? + if( i == pc.mailPetNo ) + { + savedatabuf[BA_SEL_PEN+MAX_PET*no+i] |= 0x04; + // shan 2001/01/10 + if(sPetStatFlag==1) + lssproto_PETST_send( sockfd, i, 4); + } + } + sPetStatFlag = 0; +} + + +// ???@e?V??????? +void getUserSetting( int no ) +{ + int i; + + if( no < 0 || MAXCHARACTER <= no ) + return; + + // Pf??????? + // Pf?k?????? + pc.battlePetNo = -1; + for( i = 0; i < MAX_PET; i++ ) + { + if( (savedatabuf[BA_SEL_PEN+MAX_PET*no+i] & 0x01) ) + { + pc.selectPetNo[i] = 1; + } + else + { + pc.selectPetNo[i] = 0; + } + // ?????? + if( (savedatabuf[BA_SEL_PEN+MAX_PET*no+i] & 0x04) ) + { + pc.mailPetNo = i; + } + } +} + + +// ???@e??????V?????V?? +void clearUserSetting( int no ) +{ + int i; + + if( no < 0 || MAXCHARACTER <= no ) + return; + + pc.battlePetNo = -1; + + // Pf??????? + // Pf?k?????? + for( i = 0; i < MAX_PET; i++ ) + { + savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x00; + } +} + + +// ?????????@e?V?????V?? +void setUserSoundOption( void ) +{ + int i; + + savedatabuf[STEREO_FLAG] = (unsigned char)stereo_flg; // ?????v???? + savedatabuf[SE_VOL] = (unsigned char)t_music_se_volume; // SE????? + if (MuteFlag) + { + savedatabuf[BGM_VOL] = (unsigned char)(t_music_bgm_volume | 0x80); + } + else + { + savedatabuf[BGM_VOL] = (unsigned char)t_music_bgm_volume;// BGM????? + } + + for( i = 0; i < 16; i++ ) // BGM??? + savedatabuf[BGM_PITCH+i] = t_music_bgm_pitch[i]; +} + +// ?????????@e?V??????? +void getUserSoundOption( void ) +{ + int i; + + stereo_flg = (int)savedatabuf[STEREO_FLAG]; // ?????v???? + t_music_se_volume = (int)savedatabuf[SE_VOL]; // SE????? + t_music_bgm_volume = (int)(savedatabuf[BGM_VOL] & 0x7f); // BGM????? + MuteFlag = (savedatabuf[BGM_VOL] & 0x80); + + for( i = 0; i < 16; i++ ) // BGM??? + t_music_bgm_pitch[i] = savedatabuf[BGM_PITCH+i]; +} + + +// ?????????@e?V?????V?? +void setUserChatOption( void ) +{ + savedatabuf[CHAT_COLOR] = MyChatBuffer.color; // ????? + savedatabuf[CHAT_LINE] = (unsigned char)NowMaxChatLine; // ?????? + savedatabuf[CHAT_AREA] = NowMaxVoice; // ????d? +} + + +// ?????????@e?V??????? +void getUserChatOption( void ) +{ + MyChatBuffer.color = savedatabuf[CHAT_COLOR]; // ????? + NowMaxChatLine = (int)savedatabuf[CHAT_LINE]; // ?????? + NowMaxVoice = savedatabuf[CHAT_AREA]; // ????d? +} + + +// ???????????????@e?V?????V?? +void setUserInterfaceOption( void ) +{ + savedatabuf[MOUSE_CUR_SEL] = (unsigned char)MouseCursorFlag; +} + + +// ???????????????@e?V??????? +void getUserInterfaceOption( void ) +{ + MouseCursorFlag = (int)savedatabuf[MOUSE_CUR_SEL]; +} + + + + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/shop.cpp b/石器时代8.5客户端最新源代码/石器源码/system/shop.cpp new file mode 100644 index 0000000..9111d42 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/shop.cpp @@ -0,0 +1,786 @@ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/pc.h" +#include "../systeminc/shop.h" +#include "../systeminc/tool.h" +#include "../systeminc/menu.h" +#include "../systeminc/t_music.h" +#include "../systeminc/netmain.h" +#include "../systeminc/map.h" +#include "../NewProto/protocol.h" +#include "../systeminc/login.h" +#include "../other/caryIme.h" +#include "../systeminc/field.h" +#include "../wgs/tea.h" +#include "../systeminc/VMProtectSDK.h" +int getfilesize(FILE* fp) +{ + if( fp == NULL) return 0; + int size; + fseek(fp,0,SEEK_END); + size = ftell(fp); + fseek(fp,0,SEEK_SET); + return size; +} +#ifdef _NEWSHOP_ + +void ̳ǽ(short x,short y,UCHAR ); +void ̳Ƕ(); +void ﳵƷɾ(short ); + +extern void getStrSplit( char *, char *, int, int, int ); +void StockFontBufferSplit(int x, int y, char unk1, int color, char* data, int unk2,int strLen){ + + char token[310]={0}; + getStrSplit(token,(char *)data,0x64,3,strLen); + char * b = token; + int c = 20; + int d = 0; + do{ + if(strlen(b)!=1) StockFontBuffer(x,y+c*d,unk1,color,b,unk2); + ++d; + b+=100; + }while(d < 3); +} + +typedef int BOOL; +extern int indexWN; +extern int idWN; +extern int cloasewindows; +typedef struct { + char Ʒ[32]; + unsigned int Ʒ; + unsigned int ϸƷ; + unsigned int Ʒ۸; + char Ʒ˵[500]; + short ; + +}Ʒݽṹ; + + +̳ļ_ ̳ļ[5]; + +typedef struct { + short ǰ; + short յ; +} ṹ; + +typedef struct { + BOOL ʹ; + unsigned int ; + Ʒݽṹ * Ʒ; +}ﳵƷṹ; + +typedef struct { + ﳵƷṹ [15]; + short Ʒ; + short Ʒ͸; + short ǰҳ; + short ҳ; + unsigned int ܼ۸; +} ﳵṹ; + +typedef struct { + ṹ ; + ﳵṹ ﳵ; + short ߿; + short ID; + short ʾ; + short Ʒ; + BOOL 㴰; + unsigned int Ҳʱ; + ACTION * ﶯṹ; + ACTION * ڶṹ; + short ; + short ; + short X; + short Y; + short λ; + BOOL ﹺ״̬; +} ̳ǽṹ; + + + +Ʒݽṹ Ʒ[200]; +̳ǽṹ ̳; + +short ̳ǵ[][2] = { + {90,100}, + {245,100}, + {90,193}, + {245,193}, + {90,282}, + {242,282}, + {90,369}, + {242,369} + }; + +short [][2]={ + {0,5}, + {1,9}, + {2,11}, + {3,14}, + {4,17}, + {5,19} + }; + +unsigned short ʾ[][4] ={ + {40041,40046,40066,35}, + {40042,40047,40067,106}, + {40043,40048,40068,176}, + {40044,40049,40069,246}, + {40045,40050,40070,316}, + }; + +void ̳ݳʼ() +{ + memset(&Ʒ,0,sizeof(Ʒݽṹ)*200); + memset(&̳,0,sizeof(̳ǽṹ)); +} + +int ַи( char *arr[], char *str, const char *del)//ַָļ򵥶ʵ +{ + int num = 0; + char *s =NULL; + char *p =NULL; + s=strtok_s(str,del,&p); + while(s != NULL) { + arr[num] = s; + s = strtok_s(NULL,del,&p); + num++; + } + num--; + return num; +} + + +void ̳Ǵڳʼ(char * ) +{ + if(̳.ڶṹ) DeathAction(̳.ڶṹ); + ̳.ڶṹ=0; + if(̳.ﶯṹ) DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + ̳ݳʼ(); + ̳.߿ = getIntegerToken(,'|',1); + ̳.Ҳʱ = getIntegerToken(,'|',2); + ̳.ID = getIntegerToken(,'|',3); + ̳..ǰ=1; + if(̳ļ[̳.ID-1].̳!=NULL){ + int strlena=strlen(̳ļ[̳.ID-1].̳); + char *ʱ̳ = new char [strlena+1]; + memset(ʱ̳,0,strlena+1); + memcpy(ʱ̳,̳ļ[̳.ID-1].̳,strlena); + char *ʱȫ[200] ={0}; + char *ʱ[5]={0}; + ̳.Ʒ = ַи(ʱȫ,ʱ̳,"#"); + int i=0; + for(;i<=̳.Ʒ;i++){ + ַи(ʱ,ʱȫ[i],"|"); + sprintf_s(Ʒ[i].Ʒ,"%s",ʱ[0]); + Ʒ[i].Ʒ = atoi( ʱ[1]); + Ʒ[i].ϸƷ = atoi( ʱ[2]); + Ʒ[i].Ʒ۸ = atoi( ʱ[3]); + sprintf_s(Ʒ[i].Ʒ˵,"%s",ʱ[4]); + Ʒ[i].Ʒ[strlen(Ʒ[i].Ʒ)]=0; + Ʒ[i].Ʒ˵[strlen(Ʒ[i].Ʒ˵)]=0; + Ʒ[i].=i; + } + ̳.Ʒ++; + if(̳.Ʒ > 8) + ̳..յ= ̳.Ʒ%8 ? ̳.Ʒ/8+1 : ̳.Ʒ/8; + else ̳..յ= 1; + ̳.λ=-1; + ̳.ﹺ״̬=FALSE; + delete ʱ̳; + } + ̳.=628; + ̳.=386; + ̳.X=(800-̳.)/2; + ̳.Y=(600-̳.)/2-40; +} + + +ACTION* ̳Ǵ() +{ + + if(̳.ڶṹ) DeathAction(̳.ڶṹ); + ̳.ڶṹ = MakeWindowDisp(̳.X,̳.Y,0,0,ʾ[̳.ID-1][0],0,FALSE); + play_se(202,320,240); + return ̳.ڶṹ; +} + + + +ACTION* ̳ʾ() +{ + if(̳.ID!=5){ + if(̳.ﶯṹ){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + + int ťID; + StockDispBuffer(̳.X,̳.Y+28,104,ʾ[̳.ID-1][0],1); + //Ͱť + int i=0; + for(;i<5;i++){ + if(i!=(̳.ID-1)){ + if(MakeHitBox(̳.X+1,̳.Y+ʾ[i][3],̳.X+29,̳.Y+ʾ[i][3]+69,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+1,̳.Y+ʾ[i][3],106,ʾ[i][2],1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + char ʱ[10]={0}; + sprintf_s(ʱ,"%d",i+1); + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,ʱ); + windowTypeWN = -1; + wnCloseFlag = 1; + }else StockDispBuffer(̳.X+1,̳.Y+ʾ[i][3],106,ʾ[i][1],1); + } + }else StockDispBuffer(̳.X+1,̳.Y+ʾ[i][3],106,ʾ[i][1],1); + } + } + + + //رհť + if(MakeHitBox(̳.X+595,̳.Y+27,̳.X+626,̳.Y+53,-1)==1){ + StockDispBuffer(̳.X+594,̳.Y+27,105,40054,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + cloasewindows = 1; + } + }else StockDispBuffer(̳.X+595,̳.Y+27,105,40061,1); + if(̳.㴰) ̳ǽ(̳.X+130,̳.Y+140,110); + + //㰴ť + + if(MakeHitBox(̳.X+534,̳.Y+372,̳.X+591,̳.Y+391,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+534,̳.Y+372,105,40072,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳.ﳵ.Ʒ){ + ̳.ʾ=1; + ̳.㴰=TRUE; + }else{ + ̳.ʾ=2; + ̳.㴰=TRUE; + } + } + }else StockDispBuffer(̳.X+534,̳.Y+372,105,40058,1); + }else StockDispBuffer(̳.X+534,̳.Y+372,105,40058,1); + + //չ + if(MakeHitBox(̳.X+435,̳.Y+372,̳.X+435+58,̳.Y+372+19,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+435,̳.Y+372,105,40059,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + ̳.ﳵ.ǰҳ=0; + ̳.ﳵ.ҳ=0; + ̳.ﳵ.Ʒ͸=0; + ̳.ﳵ.Ʒ=0; + ̳.ﳵ.ܼ۸=0; + ̳.ﳵ.ҳ=0; + memset(̳.ﳵ.,0,sizeof(ﳵƷṹ)*15); + } + }else StockDispBuffer(̳.X+435,̳.Y+372,105,40073,1); + }else StockDispBuffer(̳.X+435,̳.Y+372,105,40073,1); + + + //Ʒҳ + if(MakeHitBox(̳.X+379,̳.Y+39,̳.X+405,̳.Y+66,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+379,̳.Y+39,105,40055,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳..ǰ>1) ̳..ǰ-=1; + } + }else StockDispBuffer(̳.X+379,̳.Y+39,105,40062,1); + }else StockDispBuffer(̳.X+379,̳.Y+39,105,40062,1); + + //Ʒҳ + if(MakeHitBox(̳.X+379,̳.Y+370,̳.X+405,̳.Y+397,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+379,̳.Y+370,105,40056,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳..ǰ<̳..յ) ̳..ǰ+=1; + } + }else StockDispBuffer(̳.X+379,̳.Y+370,105,40063,1); + }else StockDispBuffer(̳.X+379,̳.Y+370,105,40063,1); + + //printf("ǰ=%d =%d\n",̳..ǰ,̳..յ); + short λ=0; + if(̳..ǰ==1 || ̳..ǰ==0) λ=75; + else if(̳..ǰ==̳..յ) λ=361; + else λ=(361-75)/(̳..յ-1)*(̳..ǰ-1)+75; + StockDispBuffer(̳.X+391,̳.Y+λ,105,26447,1); + + //̳ʾ + + if(̳.Ʒ>0){ + short ʼ,; + ʼ = (̳..ǰ-1)*8+1; + = ʼ+7; + if( >̳.Ʒ) = ̳.Ʒ; + short ʱλ=0; + BOOL ж=FALSE; + i=ʼ; + for(;i<=;i++){ + ʱλ++; + ťID = StockDispBuffer(̳.X+̳ǵ[ʱλ-1][0],̳.Y+̳ǵ[ʱλ-1][1],106,Ʒ[i-1].Ʒ,1); + if(HitDispNo==ťID){ + if(!̳.㴰){ + if(̳.ﶯṹ){ + if(̳.λ!=ťID){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + ʾ(̳.X+̳ǵ[ʱλ-1][0],̳.Y+̳ǵ[ʱλ-1][1],109,Ʒ[i-1].Ʒ˵,Ʒ[i-1].ϸƷ,Ʒ[i-1].Ʒ); + ж=TRUE; + if(̳.ﶯṹ) ̳.λ=ťID; + }else{ + if(̳.ﶯṹ){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + } + //ť + if(MakeHitBox(̳.X+̳ǵ[ʱλ-1][0]+40,̳.Y+̳ǵ[ʱλ-1][1],̳.X+̳ǵ[ʱλ-1][0]+40+59,̳.Y+̳ǵ[ʱλ-1][1]+22,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+̳ǵ[ʱλ-1][0]+40,̳.Y+̳ǵ[ʱλ-1][1],105,40071,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳.Ҳʱ < ̳.ﳵ.ܼ۸ + Ʒ[i-1].Ʒ۸){ + StockChatBufferLine("ϵͳϵĽҲ㡣",6); + break; + } + if(̳.߿ < ̳.ﳵ.Ʒ+1){ + StockChatBufferLine("ϵͳϵĵλ㡣",6); + break; + } + if(!̳.ﳵ.Ʒ͸){ + memset(&̳.ﳵ.,0,sizeof(ﳵƷṹ)*15); + ̳.ﳵ.[0].ʹ=TRUE; + ̳.ﳵ.[0].=1; + ̳.ﳵ.ǰҳ=1; + ̳.ﳵ.[0].Ʒ=&Ʒ[i-1]; + ̳.ﳵ.Ʒ͸++; + ̳.ﳵ.Ʒ++; + ̳.ﳵ.ܼ۸+=̳.ﳵ.[0].Ʒ->Ʒ۸; + }else{ + BOOL жǷѾ=FALSE; + int k=0; + for(;k<15;k++){ + if(̳.ﳵ.[k].ʹ){ + //printf("ַ1=%x ַ2=%x\n",̳.ﳵ.[0].Ʒ,&Ʒ[i-1]); + if(̳.ﳵ.[k].Ʒ == &Ʒ[i-1]){ + жǷѾ=TRUE; + ̳.ﳵ.[k].++; + ̳.ﳵ.Ʒ++; + ̳.ﳵ.ܼ۸+=̳.ﳵ.[k].Ʒ->Ʒ۸; + break; + } + } + } + if(!жǷѾ){ + if(̳.ﳵ.[0].ʹ){ + ﳵƷṹ ʱﳵ1; + ﳵƷṹ ʱﳵ2; + ʱﳵ1.Ʒ = ̳.ﳵ.[0].Ʒ; + ʱﳵ1. = ̳.ﳵ.[0].; + k=1; + for(;k<15;k++){ + if(̳.ﳵ.[k].ʹ){ + ʱﳵ2.Ʒ = ̳.ﳵ.[k].Ʒ; + ʱﳵ2. = ̳.ﳵ.[k].; + ̳.ﳵ.[k].Ʒ=ʱﳵ1.Ʒ; + ̳.ﳵ.[k].=ʱﳵ1.; + ʱﳵ1.Ʒ=ʱﳵ2.Ʒ; + ʱﳵ1.=ʱﳵ2.; + }else{ + ̳.ﳵ.[k].ʹ = TRUE; + ̳.ﳵ.[k].Ʒ=ʱﳵ1.Ʒ; + ̳.ﳵ.[k].=ʱﳵ1.; + break; + } + } + } + ̳.ﳵ.[0].Ʒ = &Ʒ[i-1]; + ̳.ﳵ.[0]. = 1; + ̳.ﳵ.[0].ʹ = TRUE; + ̳.ﳵ.Ʒ͸++; + ̳.ﳵ.Ʒ++; + ̳.ﳵ.ܼ۸+=̳.ﳵ.[0].Ʒ->Ʒ۸; + } + } + // printf("̳.ﳵ.Ʒ͸%3 = %d\n",̳.ﳵ.Ʒ͸%3); + ̳.ﳵ.ҳ = ̳.ﳵ.Ʒ͸%3 ? ̳.ﳵ.Ʒ͸/3+1 : ̳.ﳵ.Ʒ͸/3; + if(̳.ﳵ.ҳ*3-2>̳.ﳵ.Ʒ͸) ̳.ﳵ.ҳ--; + if(!̳.ﳵ.ҳ) ̳.ﳵ.ҳ=1; + } + }else StockDispBuffer(̳.X+̳ǵ[ʱλ-1][0]+40,̳.Y+̳ǵ[ʱλ-1][1],105,40057,1); + }else StockDispBuffer(̳.X+̳ǵ[ʱλ-1][0]+40,̳.Y+̳ǵ[ʱλ-1][1],105,40057,1); + char ʱ[128]={0}; + sprintf_s(ʱ,"%-5d",Ʒ[i-1].Ʒ۸); + StockFontBuffer(̳.X+̳ǵ[ʱλ-1][0]+15,̳.Y+̳ǵ[ʱλ-1][1]-45,1,0,Ʒ[i-1].Ʒ,0); + StockFontBuffer(̳.X+̳ǵ[ʱλ-1][0]+38,̳.Y+̳ǵ[ʱλ-1][1]-20,1,4,ʱ,0); + } + if(!̳.ﹺ״̬ && !ж){ + if(̳.ﶯṹ){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + } + //ﳵ + if(̳.ﳵ.Ʒ>0){ + short ʼ,; + ʼ = (̳.ﳵ.ǰҳ-1)*3+1; + = ̳.ﳵ.ǰҳ*3; + if(>̳.ﳵ.Ʒ͸) = ̳.ﳵ.Ʒ͸; + short ʱλ =0; + BOOL ж = FALSE; + int i=ʼ; + for(;i<=;i++){ + ʱλ++; + + StockDispBuffer(̳.X+412,̳.Y+67+((ʱλ-1)*80),105,40053,1); + //ﳵҳ + if(MakeHitBox(̳.X+505,̳.Y+121+((ʱλ-1)*80),̳.X+505+31,̳.Y+121+((ʱλ-1)*80)+16,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+505,̳.Y+121+((ʱλ-1)*80),106,40064,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + ̳.ﳵ.ܼ۸-= ̳.ﳵ.[i-1].Ʒ->Ʒ۸; + ̳.ﳵ.Ʒ-=1; + if(̳.ﳵ.[i-1].==1){ + ﳵƷɾ(i-1); + ̳.ﳵ.Ʒ͸--; + ̳.ﳵ.ҳ = ̳.ﳵ.Ʒ͸%3 ? ̳.ﳵ.Ʒ͸/3+1 : ̳.ﳵ.Ʒ͸/3; + if(̳.ﳵ.ҳ*3>̳.ﳵ.Ʒ͸) ̳.ﳵ.ҳ--; + if(!̳.ﳵ.ҳ&&̳.ﳵ.Ʒ͸) ̳.ﳵ.ҳ=1; + if(̳.ﳵ.ǰҳ>̳.ﳵ.ҳ) ̳.ﳵ.ǰҳ = ̳.ﳵ.ҳ; + if(!̳.ﳵ.Ʒ͸) + { + ̳.ﳵ.ǰҳ=0; + ̳.ﳵ.ҳ=0; + } + break; + }else ̳.ﳵ.[i-1].-=1; + } + }else StockDispBuffer(̳.X+505,̳.Y+121+((ʱλ-1)*80),106,40051,1); + }else StockDispBuffer(̳.X+505,̳.Y+121+((ʱλ-1)*80),106,40051,1); + + + + if(MakeHitBox(̳.X+571,̳.Y+121+((ʱλ-1)*80),̳.X+571+31,̳.Y+121+((ʱλ-1)*80)+16,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+571,̳.Y+121+((ʱλ-1)*80),106,40065,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳.Ҳʱ < ̳.ﳵ.ܼ۸ + ̳.ﳵ.[i-1].Ʒ->Ʒ۸){ + StockChatBufferLine("ϵͳϵĽҲ㡣",6); + break; + } + if(̳.߿ < ̳.ﳵ.Ʒ+1){ + StockChatBufferLine("ϵͳϵĵλ㡣",6); + break; + } + ̳.ﳵ.Ʒ++; + ̳.ﳵ.ܼ۸+=̳.ﳵ.[i-1].Ʒ->Ʒ۸; + ̳.ﳵ.[i-1].++; + } + }else StockDispBuffer(̳.X+571,̳.Y+121+((ʱλ-1)*80),106,40052,1); + }else StockDispBuffer(̳.X+571,̳.Y+121+((ʱλ-1)*80),106,40052,1); + ťID = StockDispBuffer(̳.X+455,̳.Y+105+((ʱλ-1)*80),106,̳.ﳵ.[i-1].Ʒ->Ʒ,1); + + if(HitDispNo==ťID){ + if(!̳.㴰){ + if(̳.ﶯṹ){ + if(̳.λ!=ťID){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + ʾ(̳.X+455,̳.Y+105+((ʱλ-1)*80),109,̳.ﳵ.[i-1].Ʒ->Ʒ˵,̳.ﳵ.[i-1].Ʒ->ϸƷ,̳.ﳵ.[i-1].Ʒ->Ʒ); + ж=TRUE; + if(̳.ﶯṹ) ̳.λ=ťID; + }else if(̳.ﶯṹ){ + DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + } + } + char ʱ[128]={0}; + sprintf_s(ʱ,"%-5d",̳.ﳵ.[i-1].Ʒ->Ʒ۸); + StockFontBuffer(̳.X+500,̳.Y+80+((ʱλ-1)*80),1,0,̳.ﳵ.[i-1].Ʒ->Ʒ,0); + StockFontBuffer(̳.X+535,̳.Y+100+((ʱλ-1)*80),1,4,ʱ,0); + sprintf_s(ʱ,"%d",̳.ﳵ.[i-1].); + ʱ[strlen(ʱ)]=0; + StockFontBuffer(̳.X+549,̳.Y+121+((ʱλ-1)*80),1,4,ʱ,0); + } + if(ж) ̳.ﹺ״̬=TRUE; + else ̳.ﹺ״̬ = FALSE; +//ﳵťҳ + if(MakeHitBox(̳.X+420,̳.Y+312,̳.X+420+31,̳.Y+312+16,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+420,̳.Y+312,105,40064,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳.ﳵ.ǰҳ!=1) ̳.ﳵ.ǰҳ-=1; + } + }else StockDispBuffer(̳.X+420,̳.Y+312,105,40051,1); + }else StockDispBuffer(̳.X+420,̳.Y+312,105,40051,1); +//ﳵťҳ + if(MakeHitBox(̳.X+575,̳.Y+312,̳.X+575+31,̳.Y+312+16,-1)==1){ + if(!̳.㴰){ + StockDispBuffer(̳.X+575,̳.Y+312,105,40065,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + if(̳.ﳵ.ǰҳ!=̳.ﳵ.ҳ) ̳.ﳵ.ǰҳ+=1; + } + }else StockDispBuffer(̳.X+575,̳.Y+312,105,40052,1); + }else StockDispBuffer(̳.X+575,̳.Y+312,105,40052,1); + } + char ʱ[20]={0}; + sprintf_s(ʱ,"%-3d/ %-3d",̳.ﳵ.ǰҳ,̳.ﳵ.ҳ); + StockFontBuffer(̳.X+490,̳.Y+314,1,0,ʱ,0); + memset(ʱ,0,20); + sprintf_s(ʱ,"%d",̳.Ҳʱ); + StockFontBuffer(̳.X+462,̳.Y+342,1,0,ʱ,0); + memset(ʱ,0,20); + sprintf_s(ʱ,"%d",̳.ﳵ.ܼ۸); + StockFontBuffer(̳.X+573,̳.Y+342,1,0,ʱ,0); + + if( CheckMenuFlag() + || ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL) + || actBtn == 1 + || menuBtn == 1 + || disconnectServerFlag == TRUE + || wnCloseFlag == 1 + || cloasewindows == 1) + { + wnCloseFlag = 0; + cloasewindows = 0; + ̳Ƕ(); + } + return ̳.ڶṹ; +} + + + +void ̳Ƕ() +{ + if(̳.ڶṹ) DeathAction(̳.ڶṹ); + ̳.ڶṹ=0; + if(̳.ﶯṹ) DeathAction(̳.ﶯṹ); + ̳.ﶯṹ=0; + ̳.λ=-1; + wnCloseFlag=0; + windowTypeWN = -1; + wnCloseFlag = 1; +} + +void ̳ǽ(short x,short y,UCHAR ) +{ + if(̳.ʾ==1){ + StockDispBuffer(x,y,,40088,1); + StockFontBuffer(x+110,y+50,2,0,"ȷҪЩƷ",0); + if(MakeHitBox(x+60,y+100,x+60+105,y+100+18,-1)==1){ + StockDispBuffer(x+60,y+100,+1,40084,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)){ + char [256]={0}; + int i=0; + for(;i<15;i++){ + if(̳.ﳵ.[i].ʹ){ + char ʱ[15]={0}; + sprintf_s(ʱ,"%d|%d#",̳.ﳵ.[i].Ʒ->+1,̳.ﳵ.[i].); + strcat_s(,ʱ); + } + } + lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,̳.ID,); + windowTypeWN = -1; + wnCloseFlag = 1; + } + }else StockDispBuffer(x+60,y+100,+1,40086,1); + if(MakeHitBox(x+220,y+100,x+220+105,y+100+18,-1)==1){ + StockDispBuffer(x+220,y+100,+1,40085,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)) ̳.㴰=FALSE; + }else StockDispBuffer(x+220,y+100,+1,40087,1); + }else{ + StockDispBuffer(x,y,,40088,1); + StockFontBuffer(x+130,y+50,2,0,"ĹﳵûƷ",0); + if(MakeHitBox(x+140,y+100,x+140+105,y+100+18,-1)==1){ + StockDispBuffer(x+140,y+100,+1,40090,1); + if( (mouse.onceState & MOUSE_LEFT_CRICK)) ̳.㴰=FALSE; + }else StockDispBuffer(x+140,y+100,+1,40089,1); + } +} + +void ʾ(short x,short y,UCHAR ,char* ,unsigned int ,char* ) +{ + char ʱ[500]={0}; + sprintf_s(ʱ,"%s",); + char *[30]={0}; + int = 0; + if(̳.ID!=5){ + = ַи(,ʱ,"\n"); + if([-1][0]==0) --; + } + int 1=; + int ͼƬ,ͼƬx,ͼƬy,i=0; + if(̳.ID!=5){ + for(;i<6;i++){ + if(i==5) { + = [i][0]; + break; + } + if([i][1]>=){ + = [i][0]; + break; + } + } + ͼƬ = *48+144; + if((x-190) >(628+̳.X-x-65)) ͼƬx=x-190; + else ͼƬx=x+35; + ͼƬy=y-(ͼƬ/2); + BOOL ж=FALSE; + while(true){ + if(̳.Y > ͼƬy-20){ + ͼƬy +=10; + ж=TRUE; + } + if((̳.Y+386+30) < (ͼƬy+ͼƬ)){ + ͼƬy -=10; + ж=TRUE; + } + if(ж) ж=FALSE; + else break; + } + + StockDispBuffer(ͼƬx+80,ͼƬy+50,,40171,1); + int =48; + if( >=1){ + for(i=1;i<=;i++) StockDispBuffer(ͼƬx+80,ͼƬy+50+*(i-1)+83,,40172,1); + } + StockDispBuffer(ͼƬx+80,ͼƬy+50+*+83,,40173,1); + int x,y; + x=ͼƬx+6-10; + y=ͼƬy-25+50; + + for(i=1;i<=1+1;i++) StockFontBufferSplit(x+15,y+((i-1)*20),FONT_PRIO_AFRONT,0,[i-1],0,20); + }else{ + ͼƬ = 1*48+144; + if((x-190) >(628+̳.X-x-65)) ͼƬx=x-190; + else ͼƬx=x+35; + ͼƬy=y-(ͼƬ/2); + BOOL ж=FALSE; + while(true){ + if(̳.Y > ͼƬy-20){ + ͼƬy +=10; + ж=TRUE; + } + if((̳.Y+386+30) < (ͼƬy+ͼƬ)){ + ͼƬy -=10; + ж=TRUE; + } + if(ж) ж=FALSE; + else break; + } + StockDispBuffer(ͼƬx+80,ͼƬy+50,,40171,1); + int =48; + StockDispBuffer(ͼƬx+80,ͼƬy+50+83,,40173,1); + if(!̳.ﶯṹ) ̳.ﶯṹ = MakeAnimDisp(ͼƬx+76,ͼƬy+80,,0); + StockFontBufferSplit(ͼƬx+15,ͼƬy+100,2,0,ʱ,0,20); + } +} + +void ﳵƷɾ(short ) +{ + + ̳.ﳵ.[].Ʒ=0; + ̳.ﳵ.[].=0; + ̳.ﳵ.[].ʹ=FALSE; + int i = +1; + if(i>14) return; + for(i;i<15;i++){ + if(!̳.ﳵ.[i].ʹ) break; + ̳.ﳵ.[].Ʒ = ̳.ﳵ.[i].Ʒ; + ̳.ﳵ.[]. = ̳.ﳵ.[i].; + ̳.ﳵ.[].ʹ=TRUE; + ̳.ﳵ.[i].Ʒ=0; + ̳.ﳵ.[i].=0; + ̳.ﳵ.[i].ʹ=FALSE; + = i; + } +} + +void ̳ļȡ(char * ·,̳ļ_ *̳) +{ + FILE *fp; + fopen_s(&fp,·,"rb"); + if( fp == NULL ) + { + ̳->MD5[0]=NULL; + ̳->̳=NULL; + return; + } + int size = getfilesize(fp); + char *ʱ = (char*)malloc(size); + fread(ʱ,1,size,fp); + fclose(fp); + ̳->̳ = (char*)malloc(size-34+1); + memset(̳->̳,0,size-34+1); + memset(̳->MD5,0,64); + memcpy_s(̳->MD5,34,ʱ,34); + memcpy_s(̳->̳,size-34,ʱ+34,size-34); + TEA((long*)̳->̳,((size-34)/4),(long*)_KEY_); + free(ʱ); +} + + +void ̳ļ(char * ·,̳ļ_ *̳) +{ + FILE *fp; + fopen_s(&fp,·,"wb"); + int length=strlen(̳->̳); + int length1 = length%4?length+(4-length%4):length; + char *ʱ = (char*)malloc(34+length1); + memset(ʱ,0,34+length1); + memcpy_s(ʱ,34,̳->MD5,34); + memcpy_s((ʱ+34),length,̳->̳,length); +#ifdef _VMP_ + TEA((long *)(ʱ+34),(long)(length1/4),(long*)VMProtectDecryptStringA(_KEY_)); +#else + TEA((long *)(ʱ+34),(long)(length1/4),(long*)_KEY_); +#endif + fwrite(ʱ, length1+34, 1, fp); + free(ʱ); + fclose(fp); +} + + +void ̳dzʼ() +{ + ̳ļȡ("./data/shop1.bin",&̳ļ[0]); + ̳ļȡ("./data/shop2.bin",&̳ļ[1]); + ̳ļȡ("./data/shop3.bin",&̳ļ[2]); + ̳ļȡ("./data/shop4.bin",&̳ļ[3]); + ̳ļȡ("./data/shop5.bin",&̳ļ[4]); +} +#endif + + + + + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/skyisland.cpp b/石器时代8.5客户端最新源代码/石器源码/system/skyisland.cpp new file mode 100644 index 0000000..a9f110c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/skyisland.cpp @@ -0,0 +1,546 @@ + +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/map.h" +#include "../systeminc/pc.h" + +DWORD sky_island_no = 0; +DWORD sky_island_no_bak = 0; + +LPDIRECTDRAWSURFACE lpsurLand = NULL; +LPDIRECTDRAWSURFACE lpsurCloud1 = NULL; +LPDIRECTDRAWSURFACE lpsurCloud2 = NULL; + +#ifdef _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ +BOOL moonFlag = FALSE; +#endif +#ifdef _NEW_CLOUD +BOOL NCLOUD_Flag = FALSE; +#endif +short LandWidth, LandHeight; +short CloudWidth1, CloudHeight1; +short CloudWidth2, CloudHeight2; +int fMapWidth, fMapHeight; +int iCloudX1, iCloudY1, iCloudX2, iCloudY2; +int iCloudDX, iCloudDY; +BOOL bDrawUpCloud; +RECT g_rc; +#ifdef _NEW_CLOUD +extern void SkyIslandDraw(int floor); +#else +extern void SkyIslandDraw(); +#endif +extern int displayBpp; +extern unsigned short highColorPalette[256]; +#ifdef _READ16BITBMP +extern BOOL g_bUseAlpha; +#endif + +void LoadBmpToSurface( int noFrom, LPDIRECTDRAWSURFACE lpsurTo, int w, int h) +{ + DDSURFACEDESC ddsd; + ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) ); + ddsd.dwSize = sizeof(DDSURFACEDESC); + if( lpsurTo->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK ){ + if( realGetImage( noFrom, + ( unsigned char **)&pRealBinBits, + &RealBinWidth, + &RealBinHeight ) ){ + // realbinͼҪŶ + pRealBinBits += (w * (h-1)); + if( displayBpp == 32){ + extern unsigned int highColor32Palette[256]; + int* surface; + surface = (int *)ddsd.lpSurface; + // ߲һҪ2byte,pitch2ɫֵ + ddsd.lPitch >>= 2; // ddsd.lPitch /= 2; + unsigned int pixel; + for( int i = 0; i < h; i++){ + for( int j = 0; j < w; j++){ + pixel = highColor32Palette[(unsigned char)pRealBinBits[j]]; + // ͸ɫ + if( pixel) surface[j] = pixel; + } + // һ + surface += ddsd.lPitch; + pRealBinBits -= w; + } + }else if( displayBpp == 16){ + LPWORD surface; + surface = (LPWORD)ddsd.lpSurface; + // ߲һҪ2byte,pitch2ɫֵ + ddsd.lPitch >>= 1; // ddsd.lPitch /= 2; + unsigned short pixel; + for( short i = 0; i < h; i++){ + for( short j = 0; j < w; j++){ + pixel = highColorPalette[(unsigned char)pRealBinBits[j]]; + // ͸ɫ + if( pixel) surface[j] = pixel; + } + // һ + surface += ddsd.lPitch; + pRealBinBits -= w; + } + }else{ + LPBYTE surface; + surface = (LPBYTE)ddsd.lpSurface; + for( short i = 0; i < h; i++){ + CopyMemory( surface, pRealBinBits, w); + surface += ddsd.lPitch; + pRealBinBits -= w; + } + } + } + lpsurTo->Unlock( NULL); + } +} + +void SkyIslandInit() +{ + sky_island_no = 0; + sky_island_no_bak = 0; + LandWidth = 0; + LandHeight = 0; + CloudWidth1 = CloudHeight1 = 0; + CloudWidth2 = CloudHeight2 = 0; + iCloudX1 = iCloudY1 = 0; + iCloudX2 = iCloudY2 = 0; + iCloudDX = iCloudDY = 0; +} + +void SkyIslandRelease() +{ + LandWidth = 0; + CloudWidth1 = 0; + CloudWidth2 = 0; + if( lpsurLand){ + lpsurLand->Release(); + lpsurLand = NULL; + } + if( lpsurCloud1){ + lpsurCloud1->Release(); + lpsurCloud1 = NULL; + } + if( lpsurCloud2){ + lpsurCloud2->Release(); + lpsurCloud2 = NULL; + } +} + +void SkyIslandLoadBmp() +{ + if( sky_island_no){ + short w, h; + DWORD no; + realGetNo( sky_island_no & 0xffff, &no ); + realGetWH( no, &w, &h); + if( w != LandWidth || h != LandHeight){ + fMapWidth = ((nowFloorGxSize + nowFloorGySize) * SURFACE_WIDTH) >> 1; // fMapWidth = (nowFloorGxSize+nowFloorGySize)*SURFACE_WIDTH/2; + fMapHeight = ((nowFloorGxSize + nowFloorGySize) * SURFACE_HEIGHT) >> 1; //fMapWidth = (nowFloorGxSize+nowFloorGySize)*SURFACE_WIDTH/2; + LandWidth = w; + LandHeight = h; + if( lpsurLand){ + lpsurLand->Release(); + lpsurLand = NULL; + } + lpsurLand = CreateSurface( w, h, 0, DDSCAPS_SYSTEMMEMORY); + } + if( lpsurLand){ + LoadBmpToSurface( no, lpsurLand, w, h); + if( !lpsurCloud1){ +#ifdef _NEW_CLOUD + if( NCLOUD_Flag == TRUE ) + realGetNo( 29077+(rand()%2), &no); + else + realGetNo( 40500+(rand()&0x3), &no); +#else + realGetNo( 40500+(rand()&0x3), &no); +#endif + realGetWH( no, &w, &h); + CloudWidth1 = w; + CloudHeight1 = h; + iCloudX1 = rand() % w; + iCloudY1 = rand() % h; + + if( lpsurCloud1 = CreateSurface( lpDraw->xSize, lpDraw->ySize, 0, DDSCAPS_SYSTEMMEMORY) ){ + LoadBmpToSurface( no, lpsurCloud1, w, h); + } + } + if( !lpsurCloud2){ + short w, h; + DWORD no; +#ifdef _NEW_CLOUD + if( NCLOUD_Flag == TRUE ) + realGetNo( 29077+(rand()%2), &no); + else + realGetNo( 40500+(rand()&0x3), &no); +#else + realGetNo( 40500+(rand()&0x3), &no); +#endif + realGetWH( no, &w, &h); + CloudWidth2 = w; + CloudHeight2 = h; + iCloudX2 = rand() % w; + iCloudY2 = rand() % h; + if( lpsurCloud2 = CreateSurface( lpDraw->xSize, lpDraw->ySize, 0, DDSCAPS_SYSTEMMEMORY) ){ + LoadBmpToSurface( no, lpsurCloud2, w, h); + } + } + } + + } +} + +void SkyIslandSetNo( int fl) +{ + sky_island_no_bak = sky_island_no; + sky_island_no = 0; + +#ifdef _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ + moonFlag = FALSE; +#endif +#ifdef _NEW_CLOUD + NCLOUD_Flag = FALSE; +#endif + switch( fl){ +//ظloadmap + case 30691: + sky_island_no = (1<<16) | 40510; + break; + case 30692: + sky_island_no = (2<<16) | 40510; + break; + case 30693: + sky_island_no = (3<<16) | 40510; + break; + case 30694: + sky_island_no = (4<<16) | 40510; + break; + case 30695: + sky_island_no = (5<<16) | 40510; + break; + case 30689: + sky_island_no = (6<<16) | 40510; + break; + case 5581://ɺ + sky_island_no = (1<<16) | 40511; + break; +#ifdef _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ + case 8255: + sky_island_no = (1<<16) | 40512; + moonFlag = TRUE; + break; + case 8256: + sky_island_no = (2<<16) | 40512; + moonFlag = TRUE; + break; + case 8257: + sky_island_no = (3<<16) | 40512; + moonFlag = TRUE; + break; +#endif + +#ifdef _LOST_FOREST_FOG + case 7450: + case 7451: + sky_island_no = (1<<16); + break; +#endif + // ̨ + case 104: + sky_island_no = (2<<16) | 40511; + break; +#ifdef _NEW_CLOUD + case 61000: + case 61100: + sky_island_no = (1<<16); + NCLOUD_Flag = TRUE; + break; +#endif + } + if( sky_island_no_bak != sky_island_no){ + SkyIslandLoadBmp(); + int x,y; + + x = ((nowGx + nowGy) * (SURFACE_WIDTH >> 1)); + y = ((nowFloorGySize + nowGy - nowGx) * (SURFACE_HEIGHT >> 1)); + g_rc.left = ((LandWidth-DEF_APPSIZEX)*x/fMapWidth); + g_rc.top = ((LandHeight-DEF_APPSIZEY)*y/fMapHeight); + g_rc.right = g_rc.left + DEF_APPSIZEX; + g_rc.bottom = g_rc.top + DEF_APPSIZEY; + } +} + +#ifdef _NEW_CLOUD +void SkyIslandDraw(int floor) +#else +void SkyIslandDraw() +#endif +{ + static DWORD dwSlow1; + static int compx = (int)pc.ptAct->mx,compy = (int)pc.ptAct->my; + int x,y; + DWORD now; + RECT rc; + + if( sky_island_no && lpsurCloud1 && lpsurLand && pc.ptAct){ + bDrawUpCloud = TRUE; + if(compx != (int)pc.ptAct->mx || compy != (int)pc.ptAct->my){ + switch(pc.dir){ + // + case 0: g_rc.top++; break; + // + case 1: + g_rc.left--; + g_rc.top++; + break; + // + case 2: g_rc.left--; break; + // + case 3: + g_rc.left--; + g_rc.top--; + break; + // + case 4: g_rc.top--; break; + // + case 5: + g_rc.left++; + g_rc.top--; + break; + // + case 6: g_rc.left++; break; + // + case 7: + g_rc.left++; + g_rc.top++; + break; + } + compx = (int)pc.ptAct->mx; + compy = (int)pc.ptAct->my; + } + g_rc.right = g_rc.left + DEF_APPSIZEX; + g_rc.bottom = g_rc.top + DEF_APPSIZEY; + SetRect(&rc,g_rc.left,g_rc.top,g_rc.right,g_rc.bottom); + if(g_rc.left < 0){ + rc.left = 0; + rc.right = rc.left + DEF_APPSIZEX; + } + if(g_rc.top < 0){ + rc.top = 0; + rc.bottom = rc.top + DEF_APPSIZEY; + } + if(g_rc.right > LandWidth){ + rc.right = LandWidth; + rc.left = LandWidth - DEF_APPSIZEX; + } + if(g_rc.bottom > LandHeight){ + rc.bottom = LandHeight; + rc.top = LandHeight - DEF_APPSIZEY; + } + lpDraw->lpBACKBUFFER->BltFast( 0, 0, lpsurLand, &rc, DDBLTFAST_WAIT); +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast( 0, 0, lpsurLand, &rc, DDBLTFAST_WAIT); +#endif +#ifdef _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ + if(moonFlag == TRUE) return; +#endif + + if( (now = TimeGetTime()) > dwSlow1){ + dwSlow1 = now + 177; + iCloudX1 += iCloudDX; + iCloudY1 += iCloudDY; + if(((iCloudX1>=DEF_APPSIZEX) || (iCloudY1>=DEF_APPSIZEY)) ){ + //һµ +#ifdef __CARYTEST + iCloudNo1 = 40500+(rand()&0x3); + DWORD no; + short w, h; + realGetNo( iCloudNo1, &no); + realGetWH( no, &w, &h); + CloudWidth1 = w; + CloudHeight1 = h; +#else + DWORD no; + short w, h; +#ifdef _NEW_CLOUD + if( floor == 61000 || floor == 61100 ) + realGetNo( 29077+(rand()%2), &no); + else + realGetNo( 40500+(rand()&0x3), &no); +#else + realGetNo( 40500+(rand()&0x3), &no); +#endif + realGetWH( no, &w, &h); + if( w!=CloudWidth1 || h!=CloudHeight1){ + CloudWidth1 = w; + CloudHeight1 = h; + LoadBmpToSurface( no, lpsurCloud1, w, h); + } +#endif + int dx = 0, dy = 0; + switch( rand()%3){ + case 0: + dx = rand() & 0x1f; + break; + case 1: + dy = rand() & 0x1f; + break; + default: + break; + } + iCloudX1 = -CloudWidth1 + dx + 40; + iCloudY1 = -CloudHeight1 + dy + 30; + } + } + // int x, y; + x = iCloudX1; + y = iCloudY1; + SetRect( &rc, 0, 0, CloudWidth1, CloudHeight1); + if( x < 0){ + rc.left = -x; + x = 0; + } + if( (x+CloudWidth1) >= DEF_APPSIZEX){ + rc.right = DEF_APPSIZEX - x; + } + if( y < 0){ + rc.top = -y; + y = 0; + } + if( (y+CloudHeight1) >= DEF_APPSIZEY){ + rc.bottom = DEF_APPSIZEY -y; + } + if( (rc.bottom-rc.top)>0 && (rc.right-rc.left)>0){ + lpDraw->lpBACKBUFFER->BltFast( x, y, lpsurCloud1, &rc, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast( x, y, lpsurCloud1, &rc, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); +#endif + + } + } +} + +#ifdef _NEW_CLOUD +void SkyIslandDraw2( int fl ) +#else +void SkyIslandDraw2() +#endif +{ +#ifdef _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ + if(moonFlag == TRUE) + return; +#endif + + static DWORD dwSlow2; + DWORD now; + RECT rc; + if( bDrawUpCloud){ + bDrawUpCloud = FALSE; + if( sky_island_no && lpsurCloud2 +#ifdef _NEW_CLOUD + || ( fl == 61000 || fl == 61100 ) +#endif + ){ + if( (now = TimeGetTime()) > dwSlow2){ + dwSlow2 = now + 73; + iCloudX2 += iCloudDX; + iCloudY2 += iCloudDY; + if( (iCloudX2>=DEF_APPSIZEX) || //((iCloudX2+CloudWidth2)<0) || + (iCloudY2>=DEF_APPSIZEY) /*|| ((iCloudY2+CloudHeight2)<0)*/){ + //һµ + DWORD no; +#ifdef _NEW_CLOUD + if( fl == 61000 || fl == 61100 ){ + realGetNo( 29077+(rand()%2), &no); + } + else + realGetNo( 40500+(rand()&0x3), &no); +#else + realGetNo( 40500+(rand()&0x3), &no); +#endif + short w, h; + realGetWH( no, &w, &h); + if( w!=CloudWidth2 || h!=CloudHeight2){ + CloudWidth2 = w; + CloudHeight2 = h; + LoadBmpToSurface( no, lpsurCloud2, w, h); + } + int dx = 0, dy = 0; + switch( rand()%3){ + case 0: + dx = rand() & 0x1f; + break; + case 1: + dy = rand() & 0x1f; + break; + default: + break; + } + iCloudX2 = -CloudWidth2 + dx + 40; + iCloudY2 = -CloudHeight2 + dy + 30; + } + } + int x, y; + x = iCloudX2; + y = iCloudY2; + SetRect( &rc, 0, 0, CloudWidth2, CloudHeight2); + if( x < 0){ + rc.left = -x; + x = 0; + } + if( (x+CloudWidth2) >= DEF_APPSIZEX){ + rc.right = DEF_APPSIZEX - x; + } + if( y < 0){ + rc.top = -y; + y = 0; + } + if( (y+CloudHeight2) >= DEF_APPSIZEY){ + rc.bottom = DEF_APPSIZEY -y; + } + if( (rc.bottom-rc.top)>0 && (rc.right-rc.left)>0){ + lpDraw->lpBACKBUFFER->BltFast( x, y, lpsurCloud2, &rc, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpDraw->lpBACKBUFFERSYS->BltFast( x, y, lpsurCloud2, &rc, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); +#endif + } + } + } +} + +BOOL SkyIslandCheckSurface() +{ + if( lpsurLand) + if( lpsurLand->IsLost() ) + return TRUE; + if( lpsurCloud1) + if( lpsurCloud1->IsLost() ) + return TRUE; + return FALSE; +} + +void SkyIslandProc() +{ + static DWORD speed = 0; + if( sky_island_no){ + DWORD now = TimeGetTime(); + if( now > speed){ + speed = now + 1000; + int dx = 0, dy = 0; + switch( rand() & 0x3){ + case 0: + dx = rand() & 0x2; + break; + case 1: + break; + default: + dy = rand() & 0x2; + break; + } + iCloudDX = 4 - dx; + iCloudDY = 2 + dy; + } + } +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/sprdisp.cpp b/石器时代8.5客户端最新源代码/石器源码/system/sprdisp.cpp new file mode 100644 index 0000000..a05035a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/sprdisp.cpp @@ -0,0 +1,2932 @@ +/************************/ +/* sprdisp.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/anim_tbl.h" +#include "../systeminc/map.h" +#include "../systeminc/battleMap.h" + +#define STOCK_DISP_BUFFER_NO_BMP ( 1 << 31 ) // ??????? +#define STOCK_DISP_BUFFER_LINE ( 1 << 30 ) // ??? +#define STOCK_DISP_BUFFER_BOX ( 1 << 29 ) // ???? +#define STOCK_DISP_BUFFER_BOX_FILL ( 1 << 28 ) // ????D???? +#define STOCK_DISP_BUFFER_CIRCLE ( 1 << 27 ) // ? +extern int displayBpp; +// ?????Bl +DISP_BUFFER DispBuffer; + +#ifndef __CARYTEST +// Realbin ??????????????? +char *pRealBinBits; +// ?? Realbin ???????????? +int RealBinWidth, RealBinHeight; +#endif +#ifdef _READ16BITBMP +BYTE *pRealBinAlpha; +#endif +// ???????????? +int SurfaceBusyFlag = 0; + +// ????????? +extern ACTION* pActMenuWnd2; +// ?????? +extern unsigned int MenuToggleFlag; + +// Robin 04/14 for Trade +extern ACTION* pActMenuWnd4; + +// Bankman +extern ACTION* pActMenuWnd5; + +extern unsigned short highColorPalette[256]; +#ifdef _READ16BITBMP +extern AddressBin_s adrntruebuff[MAX_GRAPHICS_24]; +extern BOOL g_bUseAlpha; +#endif + +// ???{??? +int SortComp( DISP_SORT *pDisp1, DISP_SORT *pDisp2 ); +typedef int CMPFUNC( const void *, const void * ); +// ????????????????? +inline void GetBoxDispBuffer( DISP_INFO *pDispInfo, int bmpNo ); +#ifdef _SURFACE_ANIM +void DrawAni(void); +int iProcessAniNum; +#endif +void DrawGrayA(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType); +#ifdef _READ16BITBMP +void DrawAlpha(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,int Alpha,bool bLastOne); +extern int displayBpp; +void DrawStaturated(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne); +#ifdef _SFUMATO +void DrawGray(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType, int sfumato); +#else +void DrawGray(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType); +#endif +void DrawAlphaChannel(SURFACE_INFO *surface_info,BYTE *AlphaData,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne); + +#ifdef _SFUMATO +void DrawSfumato(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType, int sfumato); +#endif +#endif +void DrawStaturated(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne); +void DrawGray(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType); +// ??????? /////////////////////////////////////////////////////////// +void SortDispBuffer( void ) +{ + //??????? + qsort( DispBuffer.DispSort, // ?Bl????? + DispBuffer.DispCnt, // {????? + sizeof( DISP_SORT ), // ?Bl???? + ( CMPFUNC * )SortComp // {????????? + ); +} +DISP_SORT *pSortTileTail; + + +#ifdef __SKYISLAND + +// ????? ///////////////////////////////////////////////////////////////// +BOOL PutTileBmp( void ) +{ + DISP_INFO *pDispInfo; + int i; + int bmpNo; + RECT src; + int sx, sy; + BOOL retainbackbuffer = FALSE; + pSortTileTail = DispBuffer.DispSort; + SURFACE_INFO *lpSurfaceInfo; +#ifdef _READ16BITBMP + SURFACE_INFO *lpSurfaceInfoSys; +#endif + if( (ProcNo==PROC_GAME/* && SubProcNo==3*/) || ProcNo==PROC_BATTLE){ +#ifdef _SURFACE_ANIM + iProcessAniNum = 0; +#endif + if( fastDrawTile && (fastDrawTileFlag==0 || amountXFastDraw || amountYFastDraw) ){ + retainbackbuffer = TRUE; + // ????????????????????????????? + if( ProcNo != PROC_BATTLE){ + src.top = 0; + src.left = 0; + src.right = DEF_APPSIZEX; + src.bottom = DEF_APPSIZEY; + sx = 0; + sy = 0; + //??????????????? + if( ResoMode == 1 ){ + //src.right /= 2; + //src.bottom /= 2; + src.right >>= 1; + src.bottom >>= 1; + } + if( amountXFastDraw > 0 ){ + src.right -= amountXFastDraw; + sx += amountXFastDraw; + }else if( amountXFastDraw < 0 ){ + src.left -= amountXFastDraw; + } + if( amountYFastDraw > 0 ){ + src.bottom -= amountYFastDraw; + sy += amountYFastDraw; + }else if( amountYFastDraw < 0 ){ + src.top -= amountYFastDraw; + } + if( lpDraw->lpBACKBUFFER->BltFast( sx, sy, lpBattleSurface, &src, DDBLTFAST_WAIT ) == DDERR_SURFACEBUSY ) + SurfaceBusyFlag = TRUE; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if(lpDraw->lpBACKBUFFERSYS->BltFast(sx,sy,lpBattleSurfaceSys,&src,DDBLTFAST_WAIT) == DDERR_SURFACEBUSY) + SurfaceBusyFlag = TRUE; + } +#endif + } + // ??????????? + for( i = 0; idispPrio == 0) continue; +#endif + // Ϊ,Ŀǰʾ˳ȵرĻ,ʾرѾ + if( pSortTileTail->dispPrio > DISP_PRIO_TILE){ + DispBuffer.DispCnt -= i; +#ifdef _SURFACE_ANIM + iProcessAniNum = i; +#endif + break; + } + // ????V???????????? + // ȡõһҪͼ DispInfo + pDispInfo = DispBuffer.DispInfo + pSortTileTail->no; + bmpNo = pDispInfo->bmpNo; // ???k? + + // ????? + // ???Re?????? + if( pDispInfo->pAct != NULL ){ + if( pDispInfo->pAct->atr & ACT_ATR_HIDE2 ) continue; + } + // ????????????????????????? + // ????????? + if( LoadBmp( bmpNo ) == FALSE ) continue; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + for(lpSurfaceInfo = SpriteInfo[ bmpNo ].lpSurfaceInfo,lpSurfaceInfoSys = SpriteInfo[bmpNo].lpSurfaceInfoSys + ;lpSurfaceInfo != NULL,lpSurfaceInfoSys != NULL + ;lpSurfaceInfo = lpSurfaceInfo->pNext,lpSurfaceInfoSys = lpSurfaceInfoSys->pNext){ + if(ResoMode == 1){ + if(DrawSurfaceFast((pDispInfo->x >> 1) + lpSurfaceInfo->offsetX, + (pDispInfo->y >> 1) + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface,lpSurfaceInfoSys->lpSurface) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + else{ + if(DrawSurfaceFast(pDispInfo->x + lpSurfaceInfo->offsetX, + pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface,lpSurfaceInfoSys->lpSurface) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + lpSurfaceInfo->date = SurfaceDate; + } + } + else +#endif + { + for(lpSurfaceInfo = SpriteInfo[ bmpNo ].lpSurfaceInfo;lpSurfaceInfo != NULL;lpSurfaceInfo = lpSurfaceInfo->pNext ){ + if(ResoMode == 1){ + if(DrawSurfaceFast((pDispInfo->x >> 1) + lpSurfaceInfo->offsetX, + (pDispInfo->y >> 1) + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface ) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + else{ +#ifdef _CACHE_SURFACE_ + DrawSurfaceFromPalette(lpSurfaceInfo); +#endif + if(DrawSurfaceFast(pDispInfo->x + lpSurfaceInfo->offsetX, + pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface ) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + lpSurfaceInfo->date = SurfaceDate; + } + } + } + } + } + if(retainbackbuffer){ + if( lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ) == DDERR_SURFACEBUSY ) SurfaceBusyFlag = TRUE; +#ifdef _READ16BITBMP + if(g_bUseAlpha) if(lpBattleSurfaceSys->BltFast(0,0,lpDraw->lpBACKBUFFERSYS,NULL,DDBLTFAST_WAIT) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; +#endif + } + if( ProcNo != PROC_BATTLE){ +#ifdef _LOST_FOREST_FOG + if(nowFloor!=7450 && nowFloor!=7451 +#ifdef _NEW_CLOUD + //&& nowFloor != 61000 && nowFloor != 61100 +#endif + ){ +#endif + extern DWORD sky_island_no; + if( sky_island_no){ +#ifdef _NEW_CLOUD + extern void SkyIslandDraw(int floor); + SkyIslandDraw(nowFloor); +#else + extern void SkyIslandDraw(); + SkyIslandDraw(); +#endif + return FALSE; + } +#ifdef _LOST_FOREST_FOG + } +#endif + } + return retainbackbuffer; +} +#endif +unsigned char AlphaBytes[64*48+1]; +unsigned char AlphaColorBytes[64*48*4+1]; + +// ????? ///////////////////////////////////////////////////////////////// +void PutBmp( void ) +{ +#ifdef __SKYISLAND + // ??????????? + switch( BackBufferDrawType ){// + case DRAW_BACK_NORMAL://ޱ + ClearBackSurface(); //ձʾ + void SkyIslandProc(); + SkyIslandProc(); + if( !PutTileBmp() ){ + if( fastDrawTile && lpDraw->lpBACKBUFFER->BltFast( 0, 0, lpBattleSurface, NULL, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY ) == DDERR_SURFACEBUSY ){ + SurfaceBusyFlag = TRUE; + return; + } + } +#ifdef _SURFACE_ANIM + DrawAni(); +#endif + break; + case DRAW_BACK_BATTLE: //ս + amountXFastDraw = amountYFastDraw = 0; + PutTileBmp(); + DrawBattleMap(); + break; + default: + if( !PutTileBmp() ){ + if( fastDrawTile && lpDraw->lpBACKBUFFER->BltFast( 0, 0, lpBattleSurface, NULL, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY ) == DDERR_SURFACEBUSY ){ + SurfaceBusyFlag = TRUE; + return; + } + } + break; + } + DISP_SORT *pDispSort = pSortTileTail; +#else + DISP_SORT *pDispSort = DispBuffer.DispSort; +#endif + DISP_INFO *pDispInfo; + int i; + int bmpNo; + UCHAR putTextFlag = 0; + unsigned char drawMapEffectFlag = 0; + unsigned char drawFastTileFlag = 0; + unsigned char drawFastTileFlag2 = 0; +#ifndef __CARYTEST + SURFACE_INFO *lpSurfaceInfo; +#ifdef _READ16BITBMP + SURFACE_INFO *lpSurfaceInfoSys; +#endif +#else + DDSURFACEDESC ddsd; // ??????Bl + LPWORD surface; + int pitch; + BOOL locked = FALSE; + int x, y; + short width, height; + ZeroMemory( &ddsd, sizeof( DDSURFACEDESC ) ); + ddsd.dwSize = sizeof( DDSURFACEDESC ); + if( lpDraw->lpBACKBUFFER->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) == DD_OK ){ + surface = (LPWORD)ddsd.lpSurface; + pitch = ddsd.lPitch; + locked = TRUE; + } +#endif + // ??????????? + for( i = 0; i < DispBuffer.DispCnt ; i++, pDispSort++ ){ + pDispInfo = &DispBuffer.DispInfo[pDispSort->no]; + bmpNo = pDispInfo->bmpNo;//ͼID + if( putTextFlag == 0 ){ + if( pDispSort->dispPrio >= DISP_PRIO_MENU ){ + PutText( FONT_PRIO_BACK ); +#ifdef _CHANNEL_MODIFY + PutText(FONT_PRIO_CHATBUFFER); +#endif + putTextFlag = 1; + } + } + if( putTextFlag == 1 ){ + if( pDispSort->dispPrio >= DISP_PRIO_YES_NO_WND ){ + PutText( FONT_PRIO_FRONT ); + putTextFlag = 2; + } + } +#ifdef _TRADETALKWND // Syu ADD Ի + //һµʾ˳ + if( putTextFlag == 2 ){ + if( pDispSort->dispPrio >= DISP_PRIO_BOX3 ){ + PutText( FONT_PRIO_AFRONT ); + putTextFlag = 2; + } + } +#endif + if( pDispSort->dispPrio > DISP_PRIO_MENU ){ + if( MenuToggleFlag & JOY_CTRL_M && pActMenuWnd2 != NULL ){ + if( pActMenuWnd2->hp > 0 ){ +#ifdef _2005_ValentineDay + // ҿСͼ + if (nowFloor != 17006) +#endif + drawAutoMap( pActMenuWnd2->x, pActMenuWnd2->y ); + } + } + } + // ????????? + if( pDispSort->dispPrio >= DISP_PRIO_RESERVE ){ +#ifdef __SKYISLAND +#ifdef _NEW_CLOUD + extern void SkyIslandDraw2(int fl); + SkyIslandDraw2(nowFloor); +#else + extern void SkyIslandDraw2(); + SkyIslandDraw2(); +#endif +#endif + drawMapEffect(); + drawMapEffectFlag = 1; + } +#ifndef __SKYISLAND + // ?????L? + if( fastDrawTile ){ + RECT src; + int sx, sy; + if( pDispSort->dispPrio >= DISP_PRIO_TILE && drawFastTileFlag2 == 0 ){ + if( ProcNo == PROC_GAME && SubProcNo == 3 && fastDrawTileFlag ){ + // ????????????????????????????? + src.top = 0; + src.left = 0; + src.right = DEF_APPSIZEX; + src.bottom = DEF_APPSIZEY; + sx = 0; + sy = 0; + //??????????????? + if( ResoMode == 1 ){ + src.right >>= 1; + src.bottom >>= 1; + } + if( amountXFastDraw > 0 ){ + src.right -= amountXFastDraw; + sx += amountXFastDraw; + } + else if( amountXFastDraw < 0 ) src.left -= amountXFastDraw; + + if( amountYFastDraw > 0 ){ + src.bottom -= amountYFastDraw; + sy += amountYFastDraw; + } + else if( amountYFastDraw < 0 ) src.top -= amountYFastDraw; + + if( lpDraw->lpBACKBUFFER->BltFast( sx, sy, lpBattleSurface, &src, DDBLTFAST_WAIT ) == DDERR_SURFACEBUSY ) + SurfaceBusyFlag = TRUE; + drawFastTileFlag2 = 1; + } + } + if( pDispSort->dispPrio > DISP_PRIO_TILE && drawFastTileFlag == 0 ){ + if( ProcNo == PROC_GAME && SubProcNo == 3 && fastDrawTileFlag ){ + // ???????????????????????????? + if( lpBattleSurface->BltFast( 0, 0, lpDraw->lpBACKBUFFER, NULL, DDBLTFAST_WAIT ) == DDERR_SURFACEBUSY ) + SurfaceBusyFlag = TRUE; + drawFastTileFlag = 1; + } + } + } +#endif + // ??????? + if( bmpNo & STOCK_DISP_BUFFER_NO_BMP ){ + if( bmpNo & ( STOCK_DISP_BUFFER_BOX | STOCK_DISP_BUFFER_BOX_FILL | STOCK_DISP_BUFFER_LINE ) ){ + GetBoxDispBuffer( pDispInfo, bmpNo ); + } + continue; + } + if( pDispInfo->pAct != NULL ){ + if( pDispInfo->pAct->atr & ACT_ATR_HIDE2 ) continue; + } + if( LoadBmp( bmpNo ) == FALSE ) continue; + { + for(lpSurfaceInfo = SpriteInfo[ bmpNo ].lpSurfaceInfo;lpSurfaceInfo != NULL;lpSurfaceInfo = lpSurfaceInfo->pNext){ +#ifdef _CACHE_SURFACE_ + DrawSurfaceFromPalette(lpSurfaceInfo); +#endif + if(pDispInfo->DrawEffect == 2)//ʹ + DrawStaturated(lpSurfaceInfo->lpSurface, + pDispInfo->x + lpSurfaceInfo->offsetX,pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->offsetX,lpSurfaceInfo->offsetY, + SpriteInfo[bmpNo].width,SpriteInfo[bmpNo].height,(lpSurfaceInfo->pNext == NULL ? true:false)); + else if(pDispInfo->DrawEffect == 3 || pDispInfo->DrawEffect == 4)//ʯж + DrawGray(lpSurfaceInfo->lpSurface, + pDispInfo->x + lpSurfaceInfo->offsetX,pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->offsetX,lpSurfaceInfo->offsetY, + SpriteInfo[bmpNo].width,SpriteInfo[bmpNo].height,(lpSurfaceInfo->pNext == NULL ? true:false),pDispInfo->DrawEffect); +#ifdef _PETCOLOR_ + else if(pDispInfo->DrawEffect==5){ + DrawGray(lpSurfaceInfo->lpSurface, + pDispInfo->x + lpSurfaceInfo->offsetX,pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->offsetX,lpSurfaceInfo->offsetY, + SpriteInfo[bmpNo].width,SpriteInfo[bmpNo].height,(lpSurfaceInfo->pNext == NULL ? true:false),3); + } +#endif +#ifdef _NEW_COLOR_ + else{ + extern int NewColor16Flg; + if(SpriteInfo[ bmpNo ].AlphaFlg){ + DDSURFACEDESC ddsd; + DDSURFACEDESC ddsd2; + short bx, by; + short x0, y0; + long w, h; + int Dstpitch, Srcpitch; + RECT rect = { 0, 0, SurfaceSizeX, SurfaceSizeY }; + bx = x0 = pDispInfo->x + lpSurfaceInfo->offsetX; + by = y0 = pDispInfo->y + lpSurfaceInfo->offsetY; + w = rect.right - rect.left; + h = rect.bottom - rect.top; + if (bx >= lpDraw->xSize || bx + w <= 0 || by >= lpDraw->ySize || by + h <= 0) continue; + if (bx < 0){ + rect.left -= bx; + x0 = 0; + } + if (bx + w > lpDraw->xSize) rect.right -= bx + w - lpDraw->xSize; + if (by < 0){ + rect.top -= by; + y0 = 0; + } + if (by + h > lpDraw->ySize) rect.bottom -= by + h - lpDraw->ySize; + ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC)); + ddsd2.dwSize = sizeof(DDSURFACEDESC); + if (lpDraw->lpBACKBUFFER->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) continue; + if (lpSurfaceInfo->lpSurface->Lock(NULL, &ddsd2, DDLOCK_WAIT, NULL) != DD_OK) continue; + unsigned char *Dst, *Src; + Dst = (unsigned char *)ddsd.lpSurface; + Dstpitch = ddsd.lPitch; + Src = (unsigned char *)ddsd2.lpSurface; + Srcpitch = ddsd2.lPitch; + if(displayBpp==16){ + ablend_565(lpSurfaceInfo->lpAlphaData, 64, Src, rect.left, rect.top, Srcpitch, Dst, x0 , y0 , rect.right-rect.left, rect.bottom-rect.top, Dstpitch); + }else{ + DrawAlpha32((unsigned long *)Dst, x0, y0, Dstpitch, (unsigned long *)Src, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, Srcpitch); + } + if (lpSurfaceInfo->lpSurface->Unlock(NULL) != DD_OK) continue; + if (lpDraw->lpBACKBUFFER->Unlock(NULL) != DD_OK) continue; + }else +#endif + { + if( DrawSurfaceFast( pDispInfo->x + lpSurfaceInfo->offsetX, + pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface ) == DDERR_SURFACEBUSY ) SurfaceBusyFlag = TRUE; + } + lpSurfaceInfo->date = SurfaceDate; + } + } + } + } + /* +#ifdef _LOST_FOREST_FOG + if(nowFloor==7450||nowFloor==7451 +#ifdef _NEW_CLOUD + //|| nowFloor==61000 || nowFloor==61100 +#endif + ){ + extern DWORD sky_island_no; + if( sky_island_no){ +#ifdef _NEW_CLOUD + extern void SkyIslandDraw(int floor); + SkyIslandDraw(nowFloor); +#else + extern void SkyIslandDraw(); + SkyIslandDraw(); +#endif + } + } +#endif + */ + +#ifdef __SKYISLAND +#ifdef _NEW_CLOUD + extern void SkyIslandDraw2(int fl); + SkyIslandDraw2(nowFloor); +#else + extern void SkyIslandDraw2(); + SkyIslandDraw2(); +#endif +#endif + if( putTextFlag == 0 ){ + // ????????????????? + PutText( FONT_PRIO_BACK ); + // ????? +#ifdef _CHANNEL_MODIFY + PutText(FONT_PRIO_CHATBUFFER); +#endif + putTextFlag = 1; + } + // ?????( FRONT ) + if( putTextFlag == 1 ){ + PutText( FONT_PRIO_FRONT ); + } + // ????????? + if( drawMapEffectFlag == 0 ) drawMapEffect(); + + memset(&DispBuffer,0,sizeof(DispBuffer)); + + +} + +//**************************************************************************/ +// ?? ?????????????? +// ?? UCHAR dispPrio???????? +// int x, int y +// int bmpNoͼƬ +// int chr_no??????k? +// int pat_no????k? +//**************************************************************************/ +// ҪŵImage +int StockDispBuffer( int x, int y, UCHAR dispPrio, int bmpNo, BOOL hitFlag ) +{ + short dx,dy; + int BmpNo; + + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt; + DISP_INFO *pDispInfo = DispBuffer.DispInfo + DispBuffer.DispCnt; + + if( DispBuffer.DispCnt >= DISP_BUFFER_SIZE ) return -2; + + if( -1 <= bmpNo && bmpNo <= CG_INVISIBLE ) return -2; + + if( bmpNo > CG_INVISIBLE ){ + realGetNo( bmpNo , (U4 *)&BmpNo ); + realGetPos( BmpNo , &dx, &dy); + }else{ + dx = 0; + dy = 0; + BmpNo = bmpNo; + } + + pDispSort->dispPrio = dispPrio; + pDispSort->no = DispBuffer.DispCnt; + pDispInfo->hitFlag = hitFlag; + if(hitFlag >= 20 && hitFlag < 30){ + pDispInfo->DrawEffect = 2; + pDispInfo->hitFlag = hitFlag - 20; + }else if(hitFlag >= 30 && hitFlag < 40){ + pDispInfo->DrawEffect = 3; + pDispInfo->hitFlag = hitFlag - 30; + } + else if(hitFlag >= 40 && hitFlag < 50){ + pDispInfo->DrawEffect = 4; + pDispInfo->hitFlag = hitFlag - 40; + } + else pDispInfo->DrawEffect = 0; + + pDispInfo->x = x + dx; + pDispInfo->y = y + dy; + pDispInfo->bmpNo = BmpNo; + pDispInfo->pAct = NULL; + return DispBuffer.DispCnt++; +} + +#ifdef _SFUMATO +int StockDispBuffer2( int x, int y, UCHAR dispPrio, int bmpNo, BOOL hitFlag, int sfumato/* = 0*/) +#else +int StockDispBuffer2( int x, int y, UCHAR dispPrio, int bmpNo, BOOL hitFlag ) +#endif +{ + short dx,dy; + int BmpNo; + // ??V????????????? + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt; + DISP_INFO *pDispInfo = DispBuffer.DispInfo + DispBuffer.DispCnt; + // ?????????? + if( DispBuffer.DispCnt >= DISP_BUFFER_SIZE ) return -2; + // ?????????????? + if( -1 <= bmpNo && bmpNo <= CG_INVISIBLE ) return -2; + // GФ??? + if( bmpNo > CG_INVISIBLE ){ + BmpNo = bmpNo; + realGetPos( BmpNo , &dx, &dy); + }else{// ???????????? + dx = 0; + dy = 0; + BmpNo = bmpNo; + } + // ?I?????Bl + pDispSort->dispPrio = dispPrio; + pDispSort->no = DispBuffer.DispCnt; + // ѩ?Bl? ??????? ? + pDispInfo->x = x + dx; + pDispInfo->y = y + dy; + pDispInfo->bmpNo = BmpNo; + pDispInfo->hitFlag = hitFlag; + pDispInfo->pAct = NULL; +#ifdef _READ16BITBMP + if(pDispInfo->bmpNo >= OLD_GRAPHICS_START && pDispInfo->bmpNo < MAX_GRAPHICS){ + if(adrntruebuff[pDispInfo->bmpNo - OLD_GRAPHICS_START].staturated == 1) pDispInfo->DrawEffect = 2; + } +#endif +#ifdef _SFUMATO + pDispInfo->sfumato = sfumato; +#endif + return DispBuffer.DispCnt++; +} + + +// ҪŵImageAct״趨 +void StockTaskDispBuffer( void ) +{ + ACTION *pActLoop; /* Id????????x */ + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt; + DISP_INFO *pDispInfo = DispBuffer.DispInfo + DispBuffer.DispCnt; + + /* ?????????? */ + //while( pActLoop != pActBtm ){ + for(pActLoop = pActTop->pNext ; + pActLoop != pActBtm ; + /* ?????????? */ + pActLoop = pActLoop->pNext ){ + + // ?????????? + if( DispBuffer.DispCnt >= DISP_BUFFER_SIZE ) break; + + // ?????????????? + if( -1 <= pActLoop ->bmpNo && pActLoop ->bmpNo <= CG_INVISIBLE ) continue; + + // ???????????? + if( pActLoop ->deathFlag == TRUE ) continue; + + /* ??I?? */ + if( pActLoop->atr & ACT_ATR_HIDE ) continue; + + // ?I?????Bl + pDispSort->dispPrio = pActLoop->dispPrio; + pDispSort->no = DispBuffer.DispCnt; + // ѩ?Bl? ??????? ? + pDispInfo->x = pActLoop->x + pActLoop->anim_x; + pDispInfo->y = pActLoop->y + pActLoop->anim_y; + pDispInfo->bmpNo = pActLoop->bmpNo; + pDispInfo->pAct = pActLoop; + + // ???Re???? + // ?k?? + + + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL1 ) pDispInfo->hitFlag = 7; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL2 ) pDispInfo->hitFlag = 8; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL3 ) pDispInfo->hitFlag = 9; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL4 ) pDispInfo->hitFlag = 10; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL5 ) pDispInfo->hitFlag = 11; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL6 ) pDispInfo->hitFlag = 12; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL7 ) pDispInfo->hitFlag = 13; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_COL8 ) pDispInfo->hitFlag = 14; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_ALL4 ) pDispInfo->hitFlag = 6; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_ALL3 ) pDispInfo->hitFlag = 5; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_ALL2 ) pDispInfo->hitFlag = 4; + else + if( pActLoop->atr & ACT_ATR_HIT_BOX_ALL1 ) pDispInfo->hitFlag = 3; + else // ???? + if( pActLoop->atr & ACT_ATR_HIT_BOX ) pDispInfo->hitFlag = 2; + else // Re?? + if( pActLoop->atr & ACT_ATR_HIT ) pDispInfo->hitFlag = 1; + else pDispInfo->hitFlag = FALSE; + // 4 ʯ + if(pActLoop->status == 4) pDispInfo->DrawEffect = 3; + // 1 + else if(pActLoop->status == 1) pDispInfo->DrawEffect = 4; + else pDispInfo->DrawEffect = 0; +#ifdef _PETCOLOR_ + extern BOOL EncountFlag,DuelFlag,NoHelpFlag; + if(!pDispInfo->DrawEffect) + if(ProcNo==PROC_BATTLE && !EncountFlag && !vsLookFlag&&!eventEnemyFlag&&!DuelFlag&&!NoHelpFlag){ + if(pActLoop->actNo == 0){ + if (pActLoop->level == 1 && (ATR_PLACE_NO(pActLoop) >= 2 * MAX_BATTLE_ROW_CHARS && ATR_PLACE_NO(pActLoop)< 4 * MAX_BATTLE_ROW_CHARS)){ + pDispInfo->DrawEffect=5; + } + } + } +#endif +#ifdef _READ16BITBMP + if(pDispInfo->bmpNo >= OLD_GRAPHICS_START && pDispInfo->bmpNo < MAX_GRAPHICS){ + if(adrntruebuff[pDispInfo->bmpNo - OLD_GRAPHICS_START].staturated == 1) pDispInfo->DrawEffect = 2; + } +#endif + // ??????????Rek??? + pActLoop->hitDispNo = DispBuffer.DispCnt; +#ifdef _SFUMATO + pDispInfo->sfumato = pActLoop->sfumato; +#endif + // ???????? + DispBuffer.DispCnt++; + + // ??????? + pDispSort++; + pDispInfo++; + } + +} + +// ??????????????? /////////////////////////////////////////////////// +// ???prio1??prio2??????????? +void StockTaskDispBuffer2( int prio1, int prio2 ) +{ + ACTION *pActLoop; /* Id????????x */ + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt; + DISP_INFO *pDispInfo = DispBuffer.DispInfo + DispBuffer.DispCnt; + int tmp; + + if( prio1 > prio2 ) + { + tmp = prio1; + prio1 = prio2; + prio2 = tmp; + } + + /* ?????????? */ + //while( pActLoop != pActBtm ){ + for(pActLoop = pActTop->pNext ; + pActLoop != pActBtm ; + /* ?????????? */ + pActLoop = pActLoop->pNext ){ + + // ?????????? + if( DispBuffer.DispCnt >= DISP_BUFFER_SIZE ) break; + + // prio1??prio2?ed??????? + if( prio1 <= pActLoop->dispPrio && pActLoop->dispPrio <= prio2 ) + continue; + + // ?????????????? + if( -1 <= pActLoop ->bmpNo && pActLoop ->bmpNo <= CG_INVISIBLE ) continue; + + // ???????????? + if( pActLoop ->deathFlag == TRUE ) continue; + + /* ??I?? */ + if( pActLoop->atr & ACT_ATR_HIDE ) continue; + + // ?I?????Bl + pDispSort->dispPrio = pActLoop->dispPrio; + pDispSort->no = DispBuffer.DispCnt; + // ѩ?Bl? ??????? ? + pDispInfo->x = pActLoop->x + pActLoop->anim_x; + pDispInfo->y = pActLoop->y + pActLoop->anim_y; + pDispInfo->bmpNo = pActLoop->bmpNo; + pDispInfo->pAct = pActLoop; + + // ???Re???? + if( pActLoop->atr & ACT_ATR_HIT_BOX ) pDispInfo->hitFlag = 2; + else + if( pActLoop->atr & ACT_ATR_HIT ) pDispInfo->hitFlag = 1; + else pDispInfo->hitFlag = FALSE; + // ??????????Rek??? + pActLoop->hitDispNo = DispBuffer.DispCnt; + + // ???????? + DispBuffer.DispCnt++; + // ??????? + pDispSort++; + pDispInfo++; + } + +} + +// ???????????????? ***************************************/ +void StockBoxDispBuffer( int x1, int y1, int x2, int y2, UCHAR dispPrio, int color, BOOL fill ) +{ + int col; // ?e + // int ? short ?????? + int x = ( x1 << 16 ) | x2; // ???????????????? + int y = ( y1 << 16 ) | y2; // ???????????????? + + // ??????? + if( fill == 0 ) col = color | STOCK_DISP_BUFFER_BOX | STOCK_DISP_BUFFER_NO_BMP ; + // D??????? + else if( fill == 1 ) col = color | STOCK_DISP_BUFFER_BOX_FILL | STOCK_DISP_BUFFER_NO_BMP ; + // ????? + else if( fill == 2 ) col = color | STOCK_DISP_BUFFER_LINE | STOCK_DISP_BUFFER_NO_BMP ; + + // ????????????? + StockDispBuffer( x, y, dispPrio, col, 0 ); +} + +// ????????????????? *********************************/ +inline void GetBoxDispBuffer( DISP_INFO *pDispInfo, int bmpNo ) +{ + // ?????? + RECT rect; + int color; // + BOOL fill = FALSE; // D??????? + int DispInfoX = pDispInfo->x; + int DispInfoY = pDispInfo->y; + + // ???? + rect.right = ( LONG )( pDispInfo->x & 0xffff ); + rect.bottom = ( LONG )( pDispInfo->y & 0xffff ); + + // ?????????? + _asm{ + // rect.left ??? + mov cl,16 // ?????????? + mov eax, [ DispInfoX ] + sar eax, cl // ?????? + mov [ rect.left ], eax + // rect.top ??? + mov eax, [ DispInfoY ] + sar eax, cl + mov [ rect.top ], eax + } + + + // ??????? + if( bmpNo & STOCK_DISP_BUFFER_BOX ){ + color = bmpNo & 0xff; // ?????? + DrawBox( &rect, color, 0 ); // ????? + + // D??????? + }else if( bmpNo & STOCK_DISP_BUFFER_BOX_FILL ){ + color = color = bmpNo & 0xff; // e + DrawBox( &rect, color, 1 ); // ????? + + }else if( bmpNo & STOCK_DISP_BUFFER_LINE ){ + color = color = bmpNo & 0xff; // e + DrawBox( &rect, color, 2 ); // ???? + } +} + +// ???{??? ////////////////////////////////////////////////////////////// +int SortComp( DISP_SORT *pDisp1, DISP_SORT *pDisp2 ) +{ + // pDisp1 ??IT??????V?v? + if( pDisp1->dispPrio > pDisp2->dispPrio ){ + return 1; + } + + // pDisp2 ??IT?????????? + if( pDisp1->dispPrio < pDisp2->dispPrio ){ + return -1; + } + // ?????K???? + // pDisp1 ?????????????????? + if( pDisp1->no > pDisp2->no ){ + return -1; + } + // ????????V?v??????? + return 1; +} + +#ifdef _SURFACE_ANIM +// ̬ر(ȨΪ0Ķ̬ر) +void DrawAni() +{ + DISP_INFO *pDispInfo; + int bmpNo; + SURFACE_INFO *lpSurfaceInfo; +#ifdef _READ16BITBMP + SURFACE_INFO *lpSurfaceInfoSys; +#endif + + if(ProcNo != PROC_BATTLE){ + pSortTileTail = DispBuffer.DispSort; + DispBuffer.DispCnt += iProcessAniNum; + for(int i = 0; idispPrio == DISP_PRIO_TILE) continue; + // Ϊ,Ŀǰʾ˳ȵرĻ,ʾرѾ + if( pSortTileTail->dispPrio > DISP_PRIO_TILE){ + DispBuffer.DispCnt -= i; + break; + } + // ȡõһҪͼ DispInfo + pDispInfo = DispBuffer.DispInfo + pSortTileTail->no; + bmpNo = pDispInfo->bmpNo; // ???k? + + if( pDispInfo->pAct != NULL ){ + if( pDispInfo->pAct->atr & ACT_ATR_HIDE2 ) continue; + } + if( LoadBmp( bmpNo ) == FALSE ) continue; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + for(lpSurfaceInfo = SpriteInfo[ bmpNo ].lpSurfaceInfo,lpSurfaceInfoSys = SpriteInfo[ bmpNo ].lpSurfaceInfoSys + ;lpSurfaceInfo != NULL,lpSurfaceInfoSys != NULL + ;lpSurfaceInfo = lpSurfaceInfo->pNext,lpSurfaceInfoSys = lpSurfaceInfoSys->pNext){ + if(ResoMode == 1){ + if(DrawSurfaceFast((pDispInfo->x >> 1) + lpSurfaceInfo->offsetX,(pDispInfo->y >> 1) + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface,lpSurfaceInfoSys->lpSurface) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + else{ + if(DrawSurfaceFast(pDispInfo->x + lpSurfaceInfo->offsetX, + pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface,lpSurfaceInfoSys->lpSurface) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + lpSurfaceInfo->date = SurfaceDate; + } + } + else +#endif + { + for(lpSurfaceInfo = SpriteInfo[ bmpNo ].lpSurfaceInfo;lpSurfaceInfo != NULL;lpSurfaceInfo = lpSurfaceInfo->pNext ){ + if(ResoMode == 1){ + if(DrawSurfaceFast((pDispInfo->x >> 1) + lpSurfaceInfo->offsetX, + (pDispInfo->y >> 1) + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface ) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + else{ +#ifdef _CACHE_SURFACE_ + DrawSurfaceFromPalette(lpSurfaceInfo); +#endif + if(DrawSurfaceFast(pDispInfo->x + lpSurfaceInfo->offsetX, + pDispInfo->y + lpSurfaceInfo->offsetY, + lpSurfaceInfo->lpSurface ) == DDERR_SURFACEBUSY) SurfaceBusyFlag = TRUE; + } + lpSurfaceInfo->date = SurfaceDate; + } + } + } + if(fastDrawTile && lpDraw->lpBACKBUFFER->BltFast( 0, 0, lpBattleSurface, NULL, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY ) == DDERR_SURFACEBUSY){ + SurfaceBusyFlag = TRUE; + return; + } + +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if(fastDrawTile && lpDraw->lpBACKBUFFERSYS->BltFast( 0, 0, lpBattleSurfaceSys, NULL, DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY ) == DDERR_SURFACEBUSY){ + SurfaceBusyFlag = TRUE; + return; + } + } +#endif + } +} +#endif +extern int gBitRShift; + +void DrawGray(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2,nColorOverlayer; + int i,j,w = SURFACE_WIDTH,h = SURFACE_HEIGHT,subx,dx = 0,dy = 0; + int R,G,B,Gray,g; + bool odd = false; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + subx = ox; + + if(iGrayType == 3) g = 6; + else if(iGrayType == 4) g = 5; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFER->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFER->Unlock(NULL); + return; + } +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest = (DWORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (DWORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 0){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + Gray = (R*3+G*5+B)/10; + *(DWORD*)ptSourceDest = (DWORD)(Gray << 16 | Gray << 8 | Gray); + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + }else +#endif + if(displayBpp == 16){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xf800) >> 11; + G = (nColorOverlayer & 0x07e0) >> 6; + B = nColorOverlayer & 0x001f; + Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)(Gray << 11 | Gray << g | Gray); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + } + lpSurface->Unlock(NULL); + lpDraw->lpBACKBUFFER->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFER,&rect,DDBLTFAST_WAIT); + return; +} + +void DrawGrayA(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2,nColorOverlayer; + int i,j,w = SURFACE_WIDTH,h = SURFACE_HEIGHT,subx,dx = 0,dy = 0; + int R,G,B,Gray,g; + bool odd = false; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + subx = ox; + + if(iGrayType == 3) g = 6; + else if(iGrayType == 4) g = 5; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFER->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFER->Unlock(NULL); + return; + } + + unsigned char ALPHA = 150, RED = 250, GREEN = 0, BLUE = 250; +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest = (DWORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (DWORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + // 565 ʾģʽ + if(gBitRShift == 0){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + + R = RED + (R - RED) * ALPHA / 0xff; + G = GREEN + (G - GREEN) * ALPHA / 0xff; + B = BLUE + (B - BLUE) * ALPHA / 0xff; + Gray = 0xff; + *(DWORD*)ptSourceDest = (DWORD)(Gray << 24 | R<<16 | G << 8 | B); + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + }else +#endif + if(displayBpp == 16){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xf800) >> 8; + G = (nColorOverlayer & 0x07e0) >> 3; + B = (nColorOverlayer & 0x001f) << 3; + R = RED + (R - RED) * ALPHA / 0xff; + G = GREEN + (G - GREEN) * ALPHA / 0xff; + B = BLUE + (B - BLUE) * ALPHA / 0xff; + Gray = 0xff; + + //Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)((R & 0xf8) << 8 | (G & 0xfc) << 3 | B >> 3); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + } + lpSurface->Unlock(NULL); + lpDraw->lpBACKBUFFER->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFER,&rect,DDBLTFAST_WAIT); + return; +} + +void DrawStaturated(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2; + int w = SURFACE_WIDTH,h = SURFACE_HEIGHT,dx = 0,dy = 0; + DWORD Is4Multiple; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + Is4Multiple = w % 4; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFER->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFER->Unlock(NULL); + return; + } + + void *ptSourceDest,*ptOverLayerDest; +#ifdef _HI_COLOR_32 + void *ptSourceDest32,*ptOverLayerDest32; + if( displayBpp == 32 ){ + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest32 = (DWORD *)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest32 = (DWORD *)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + }else +#endif + { + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + } + + { + int i,j,nColorSource,nColorOverlayer; + DWORD SR,SG,SB,OR,OG,OB; + + // 565 ʾģʽ + if(gBitRShift == 2){ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + // SR = (((SR + OR) > 0x00ff ? 0x00ff:SR+OR) << 8) & 0xf800; + // SG = (((SG + OG) > 0x00ff ? 0x00ff:SG+OG) << 3) & 0x07e0; + // SB = (((SB + OB) > 0x00ff ? 0x00ff:SB+OB) >> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) << 8) & 0xff0000; + SG = ((OG > SG ? OG:SG) << 3) & 0x00ff00; + SB = ((OB > SB ? OB:SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + } + }else +#endif + { + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x07e0) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x001f) << 3; + OR = (nColorOverlayer & 0xf800) >> 8; + OG = (nColorOverlayer & 0x07e0) >> 3; + OB = (nColorOverlayer & 0x001f) << 3; + // SR = (((SR + OR) > 0x00ff ? 0x00ff:SR+OR) << 8) & 0xf800; + // SG = (((SG + OG) > 0x00ff ? 0x00ff:SG+OG) << 3) & 0x07e0; + // SB = (((SB + OB) > 0x00ff ? 0x00ff:SB+OB) >> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) << 8) & 0xf800; + SG = ((OG > SG ? OG:SG) << 3) & 0x07e0; + SB = ((OB > SB ? OB:SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + } + } + } + // 555 ʾģʽ + else{ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x00ff00) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorSource & 0xff0000) >> 7; + OG = (nColorOverlayer & 0x00ff00) >> 2; + OB = (nColorOverlayer & 0x0000ff) << 3; + // SR = ((SR + OR) & 0x00ff)<< 7; + // SG = (((SG + OG) & 0x00ff)<< 2) & 0x03e0; + // SB = (((SB + OB) & 0x00ff)>> 3) & 0x001f; + SR = (((OR > SR ? OR:SR) & 0x00ff)<< 7) & 0xff0000; + SG = (((OG > SG ? OG:SG) & 0x00ff)<< 2) & 0x00ff00; + SB = (((OB > SB ? OB:SB) & 0x00ff)>> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + } + }else +#endif + { + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x03e0) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x001f) << 3; + OR = nColorOverlayer >> 7; + OG = (nColorOverlayer & 0x03e0) >> 2; + OB = (nColorOverlayer & 0x001f) << 3; + // SR = ((SR + OR) & 0x00ff)<< 7; + // SG = (((SG + OG) & 0x00ff)<< 2) & 0x03e0; + // SB = (((SB + OB) & 0x00ff)>> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) & 0x00ff)<< 7; + SG = (((OG > SG ? OG:SG) & 0x00ff)<< 2) & 0x03e0; + SB = (((OB > SB ? OB:SB) & 0x00ff)>> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + } + } + } + } + lpDraw->lpBACKBUFFER->Unlock(NULL); + lpSurface->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFER,&rect,DDBLTFAST_WAIT); + + return; +} + +#ifdef _READ16BITBMP +extern int gBitRShift; + + +void DrawAlpha(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,int Alpha,bool bLastOne){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2; + int w = SURFACE_WIDTH,h = SURFACE_HEIGHT,dx = 0,dy = 0; + DWORD Is4Multiple; + bool odd = false; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + if((w % 2) == 1) odd = true; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + if((w % 2) == 1) odd = true; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + if((w % 2) == 1) odd = true; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + Is4Multiple = w % 4; + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + return; + } + + void *ptSourceDest,*ptOverLayerDest; +#ifdef _HI_COLOR_32 + void *ptSourceDest32,*ptOverLayerDest32; + if( displayBpp == 32 ){ + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest32 = (int *)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest32 = (int *)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + }else +#endif + { + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + + + } + + { + int i,j,nColorSource,nColorOverlayer; + DWORD SR,SG,SB,OR,OG,OB; + + w >>= 1; + // 565 ʾģʽ + if(gBitRShift == 2){ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + for(i=0;i> 8; + SG = (nColorSource & 0x00ff00) >> 3; + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = SB | SG | SR; + } + ptSourceDest32 = (DWORD*)ptSourceDest + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + (surfacePitch1 >> 2) - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + (surfacePitch2 >> 2) - w; + if(odd){ + ptSourceDest32 = (WORD*)ptSourceDest - 1; + ptOverLayerDest32 = (WORD*)ptOverLayerDest32 - 1; + } + } + }else +#endif + { + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x07e0) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x001f) << 3; + OR = (nColorOverlayer & 0xf800) >> 8; + OG = (nColorOverlayer & 0x07e0) >> 3; + OB = (nColorOverlayer & 0x001f) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xf800; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x07e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + for(i=0;i> 8; + SG = (nColorSource & 0x07e007e0) >> 3; + SB = (nColorSource & 0x001f001f) << 3; + OR = (nColorOverlayer & 0xf800f800) >> 8; + OG = (nColorOverlayer & 0x07e007e0) >> 3; + OB = (nColorOverlayer & 0x001f001f) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xf800f800; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x07e007e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f001f; + *(DWORD*)ptSourceDest = SB | SG | SR; + } + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + (surfacePitch1 >> 1) - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + (surfacePitch2 >> 1) - w; + if(odd){ + ptSourceDest = (WORD*)ptSourceDest - 1; + ptOverLayerDest = (WORD*)ptOverLayerDest - 1; + } + } + } + + } + // 555 ʾģʽ + else{ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x00ff00) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 7; + OG = (nColorOverlayer & 0x00ff00) >> 2; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 7) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 2) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + for(i=0;i> 7; + SG = (nColorSource & 0x00ff00) >> 2; + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 7; + OG = (nColorOverlayer & 0x00ff00) >> 2; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 7) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 2) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = SB | SG | SR; + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + (surfacePitch1 >> 2) - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + (surfacePitch2 >> 2) - w; + if(odd){ + ptSourceDest32 = (WORD*)ptSourceDest32 - 1; + ptOverLayerDest32 = (WORD*)ptOverLayerDest32 - 1; + } + } + }else +#endif + { + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x03e0) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x001f) << 3; + OR = nColorOverlayer >> 7; + OG = (nColorOverlayer & 0x03e0) >> 2; + OB = (nColorOverlayer & 0x001f) << 3; + SR = ((((OR - SR) * Alpha) >> 5) + SR) << 7; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 2) & 0x03e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + for(i=0;i> 7; + SG = (nColorSource & 0x03e003e0) >> 2; + SB = (nColorSource & 0x001f001f) << 3; + OR = (nColorOverlayer & 0x7c007c00) >> 7; + OG = (nColorOverlayer & 0x03e003e0) >> 2; + OB = (nColorOverlayer & 0x001f001f) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 7) & 0x7c007c00; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 2) & 0x03e003e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f001f; + *(DWORD*)ptSourceDest = SB | SG | SR; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + (surfacePitch1 >> 1) - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + (surfacePitch2 >> 1) - w; + if(odd){ + ptSourceDest = (WORD*)ptSourceDest - 1; + ptOverLayerDest = (WORD*)ptOverLayerDest - 1; + } + } + } + } + } + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + lpSurface->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFERSYS,&rect,DDBLTFAST_WAIT); + + return; +} + +void DrawStaturated(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2; + int w = SURFACE_WIDTH,h = SURFACE_HEIGHT,dx = 0,dy = 0; + DWORD Is4Multiple; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + Is4Multiple = w % 4; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + return; + } + + void *ptSourceDest,*ptOverLayerDest; +#ifdef _HI_COLOR_32 + void *ptSourceDest32,*ptOverLayerDest32; + if( displayBpp == 32 ){ + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest32 = (DWORD *)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest32 = (DWORD *)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + }else +#endif + { + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + } + + { + int i,j,nColorSource,nColorOverlayer; + DWORD SR,SG,SB,OR,OG,OB; + + // 565 ʾģʽ + if(gBitRShift == 2){ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + // SR = (((SR + OR) > 0x00ff ? 0x00ff:SR+OR) << 8) & 0xf800; + // SG = (((SG + OG) > 0x00ff ? 0x00ff:SG+OG) << 3) & 0x07e0; + // SB = (((SB + OB) > 0x00ff ? 0x00ff:SB+OB) >> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) << 8) & 0xff0000; + SG = ((OG > SG ? OG:SG) << 3) & 0x00ff00; + SB = ((OB > SB ? OB:SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + } + }else +#endif + { + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x07e0) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x001f) << 3; + OR = (nColorOverlayer & 0xf800) >> 8; + OG = (nColorOverlayer & 0x07e0) >> 3; + OB = (nColorOverlayer & 0x001f) << 3; + // SR = (((SR + OR) > 0x00ff ? 0x00ff:SR+OR) << 8) & 0xf800; + // SG = (((SG + OG) > 0x00ff ? 0x00ff:SG+OG) << 3) & 0x07e0; + // SB = (((SB + OB) > 0x00ff ? 0x00ff:SB+OB) >> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) << 8) & 0xf800; + SG = ((OG > SG ? OG:SG) << 3) & 0x07e0; + SB = ((OB > SB ? OB:SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + } + } + } + // 555 ʾģʽ + else{ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x00ff00) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorSource & 0xff0000) >> 7; + OG = (nColorOverlayer & 0x00ff00) >> 2; + OB = (nColorOverlayer & 0x0000ff) << 3; + // SR = ((SR + OR) & 0x00ff)<< 7; + // SG = (((SG + OG) & 0x00ff)<< 2) & 0x03e0; + // SB = (((SB + OB) & 0x00ff)>> 3) & 0x001f; + SR = (((OR > SR ? OR:SR) & 0x00ff)<< 7) & 0xff0000; + SG = (((OG > SG ? OG:SG) & 0x00ff)<< 2) & 0x00ff00; + SB = (((OB > SB ? OB:SB) & 0x00ff)>> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest32 + 1; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + } + }else +#endif + { + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x03e0) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x001f) << 3; + OR = nColorOverlayer >> 7; + OG = (nColorOverlayer & 0x03e0) >> 2; + OB = (nColorOverlayer & 0x001f) << 3; + // SR = ((SR + OR) & 0x00ff)<< 7; + // SG = (((SG + OG) & 0x00ff)<< 2) & 0x03e0; + // SB = (((SB + OB) & 0x00ff)>> 3) & 0x001f; + SR = ((OR > SR ? OR:SR) & 0x00ff)<< 7; + SG = (((OG > SG ? OG:SG) & 0x00ff)<< 2) & 0x03e0; + SB = (((OB > SB ? OB:SB) & 0x00ff)>> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + } + } + } + } + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + lpSurface->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFERSYS,&rect,DDBLTFAST_WAIT); + + return; +} + +void DrawGray(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2,nColorOverlayer; + int i,j,w = SURFACE_WIDTH,h = SURFACE_HEIGHT,subx,dx = 0,dy = 0; + int R,G,B,Gray,g; + bool odd = false; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + subx = ox; + + if(iGrayType == 3) g = 6; + else if(iGrayType == 4) g = 5; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + return; + } +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest = (DWORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (DWORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + Gray = (R*3+G*6+B)/10; + *(DWORD*)ptSourceDest = (DWORD)(Gray << 16 | Gray << 8 | Gray); + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + // 555 ʾģʽ + else{ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + + Gray = (R*3+G*5+B)/10; + *(DWORD*)ptSourceDest = (DWORD)(Gray << 16 | Gray << 8 | Gray); + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + }else +#endif + if(displayBpp == 16){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xf800) >> 11; + G = (nColorOverlayer & 0x07e0) >> 6; + B = nColorOverlayer & 0x001f; + Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)(Gray << 11 | Gray << g | Gray); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + // 555 ʾģʽ + else{ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = nColorOverlayer >> 10; + G = (nColorOverlayer & 0x03e0) >> 5; + B = nColorOverlayer & 0x001f; + Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)(Gray << 10 | Gray << g | Gray); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + } + lpSurface->Unlock(NULL); + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFERSYS,&rect,DDBLTFAST_WAIT); + + return; +} + +void DrawAlphaChannel(SURFACE_INFO *surface_info,BYTE *AlphaData,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2; + int w = SURFACE_WIDTH,h = SURFACE_HEIGHT,dx = 0,dy = 0; + DWORD Is4Multiple; + RECT rect; + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + Is4Multiple = w % 4; + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(surface_info->lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT | DDLOCK_READONLY ,NULL) != DD_OK){ + lpDraw->lpBACKBUFFERSYS->Unlock(&ddsdSource); + return; + } + void *ptSourceDest,*ptOverLayerDest; +#ifdef _HI_COLOR_32 + void *ptSourceDest32,*ptOverLayerDest32; + if( displayBpp == 32){ + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest32 = (int *)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest32 = (int *)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + }else +#endif + { + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) + dy * surfacePitch2 + dx; + } + + int i,j,nColorSource,nColorOverlayer; + DWORD SR,SG,SB,OR,OG,OB,Alpha; + // 565 ʾģʽ + if(gBitRShift == 2){ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + AlphaData++; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + AlphaData += SURFACE_WIDTH - w; + } + }else +#endif + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x07e0) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x001f) << 3; + OR = (nColorOverlayer & 0xf800) >> 8; + OG = (nColorOverlayer & 0x07e0) >> 3; + OB = (nColorOverlayer & 0x001f) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xf800; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x07e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + AlphaData++; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + AlphaData += SURFACE_WIDTH - w; + } + } + // 555 ʾģʽ + else{ +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + for(j=0;j> 8; // ԭҪ113,򻯳8 + SG = (nColorSource & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + SB = (nColorSource & 0x0000ff) << 3; + OR = (nColorOverlayer & 0xff0000) >> 8; + OG = (nColorOverlayer & 0x00ff00) >> 3; + OB = (nColorOverlayer & 0x0000ff) << 3; + SR = (((((OR - SR) * Alpha) >> 5) + SR) << 8) & 0xff0000; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 3) & 0x00ff00; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest32 = (DWORD)(SB | SG | SR); + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + 1; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + 1; + AlphaData++; + } + ptSourceDest32 = (DWORD*)ptSourceDest32 + surfacePitch1 - w; + ptOverLayerDest32 = (DWORD*)ptOverLayerDest32 + surfacePitch2 - w; + AlphaData += SURFACE_WIDTH - w; + } + }else +#endif + + { + for(j=0;j> 7; // ԭҪ103,򻯳7 + SG = (nColorSource & 0x03e0) >> 2; // ԭҪ53,򻯳2 + SB = (nColorSource & 0x001f) << 3; + OR = nColorOverlayer >> 7; + OG = (nColorOverlayer & 0x03e0) >> 2; + OB = (nColorOverlayer & 0x001f) << 3; + SR = ((((OR - SR) * Alpha) >> 5) + SR) << 7; + SG = (((((OG - SG) * Alpha) >> 5) + SG) << 2) & 0x03e0; + SB = (((((OB - SB) * Alpha) >> 5) + SB) >> 3) & 0x001f; + *(WORD*)ptSourceDest = (WORD)(SB | SG | SR); + } + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + AlphaData++; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + AlphaData += SURFACE_WIDTH - w; + } + } + + } + lpDraw->lpBACKBUFFERSYS->Unlock(&ddsdSource); + surface_info->lpSurface->Unlock(&ddsdOverlayer); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFERSYS,&rect,DDBLTFAST_WAIT); + return; +} +#endif + +#ifdef _SFUMATO +void DrawSfumato(LPDIRECTDRAWSURFACE lpSurface,int ox,int oy,int offsetx,int offsety,int ow,int oh,bool bLastOne,int iGrayType, int sfumato){ + static DDSURFACEDESC ddsdSource,ddsdOverlayer; + int surfacePitch1,surfacePitch2,nColorOverlayer; + int i,j,w = SURFACE_WIDTH,h = SURFACE_HEIGHT,subx,dx = 0,dy = 0; + int R,G,B,Gray,g; + bool odd = false; + RECT rect; + + if(ox >= lpDraw->xSize || ox + w <= 0 || oy >= lpDraw->ySize || oy + h <= 0 ) return; + if(bLastOne){ + w = ow - offsetx; + h = oh - offsety; + } + if(ox + w >= lpDraw->xSize){ + w = lpDraw->xSize - ox; + } + if(oy + h >= lpDraw->ySize) h = lpDraw->ySize - oy; + if(ox < 0){ + w = w + ox; + if(w < 0) return; + dx = ox*-1; + ox = 0; + } + if(oy < 0){ + h = h + oy; + if(h < 0) return; + dy = oy*-1; + oy = 0; + } + subx = ox; + + if(iGrayType == 3) g = 6; + else if(iGrayType == 4) g = 5; + + ZeroMemory(&ddsdSource,sizeof(DDSURFACEDESC)); + ddsdSource.dwSize = sizeof(DDSURFACEDESC); + ZeroMemory(&ddsdOverlayer,sizeof(DDSURFACEDESC)); + ddsdOverlayer.dwSize = sizeof(DDSURFACEDESC); + if(lpDraw->lpBACKBUFFERSYS->Lock(NULL,&ddsdSource,DDLOCK_WAIT,NULL) != DD_OK) return; + if(lpSurface->Lock(NULL,&ddsdOverlayer,DDLOCK_WAIT,NULL) != DD_OK){ + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + return; + } +#ifdef _HI_COLOR_32 + if( displayBpp == 32 ){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 2; + surfacePitch2 = ddsdOverlayer.lPitch >> 2; + ptSourceDest = (DWORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (DWORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + Gray = (R*3+G*6+B)/10; + *(DWORD*)ptSourceDest = (DWORD)(Gray << 16 | Gray << 8 | Gray); + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + // 555 ʾģʽ + else{ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(DWORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xff0000) >> 16; + G = (nColorOverlayer & 0x00ff00) >> 8; + B = (nColorOverlayer & 0x0000ff); + + + if(sfumato > 0){ + int x = G - R; + int y = G - B; + if((R > 0x30 && G > 0x30 && B > 0x30)/* &&(R < 0xf0 && G < 0xf0 && B < 0xf0) */&& (x > -40 && x < 40) && (y > -40 && y < 40)){ + R = (nColorOverlayer & 0xff0000) >> 8; // ԭҪ113,򻯳8 + G = (nColorOverlayer & 0x00ff00) >> 3; // ԭҪ52,򻯳3 + B = (nColorOverlayer & 0x0000ff) << 3; + + int OR = (sfumato & 0xff0000) >> 8; + int OG = (sfumato & 0x00ff00) >> 3; + int OB = (sfumato & 0x0000ff) << 3; + + R = (((((OR - R) * 12) >> 5) + R) << 8) & 0xff0000; + G = (((((OG - G) * 12) >> 5) + G) << 3) & 0x00ff00; + B = (((((OB - B) * 12) >> 5) + B) >> 3) & 0x0000ff; + *(DWORD*)ptSourceDest = (DWORD)(B | G | R); + + }else{ + *(DWORD*)ptSourceDest = nColorOverlayer; + } + }else{ + *(DWORD*)ptSourceDest = nColorOverlayer; + } + } + } + else subx++; + ptSourceDest = (DWORD*)ptSourceDest + 1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + 1; + } + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (DWORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (DWORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + }else +#endif + if(displayBpp == 16){ + void *ptSourceDest,*ptOverLayerDest; + surfacePitch1 = ddsdSource.lPitch >> 1; + surfacePitch2 = ddsdOverlayer.lPitch >> 1; + ptSourceDest = (WORD*)(ddsdSource.lpSurface) + oy * surfacePitch1 + ox; + ptOverLayerDest = (WORD*)(ddsdOverlayer.lpSurface) +dy * surfacePitch2 + dx; + + // 565 ʾģʽ + if(gBitRShift == 2){ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = (nColorOverlayer & 0xf800) >> 11; + G = (nColorOverlayer & 0x07e0) >> 6; + B = nColorOverlayer & 0x001f; + Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)(Gray << 11 | Gray << g | Gray); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + // 555 ʾģʽ + else{ + for(j=0;j= 0){ + for(i=0;i= 0){ + nColorOverlayer = *(WORD*)ptOverLayerDest; + if(nColorOverlayer != DEF_COLORKEY){ + R = nColorOverlayer >> 10; + G = (nColorOverlayer & 0x03e0) >> 5; + B = nColorOverlayer & 0x001f; + Gray = (R*3+G*6+B)/10; + *(WORD*)ptSourceDest = (WORD)(Gray << 10 | Gray << g | Gray); + } + } + else subx++; + ptSourceDest = (WORD*)ptSourceDest + 1; + ptOverLayerDest = (WORD*)ptOverLayerDest + 1; + } + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1 - w; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2 - w; + subx = ox; + } + else{ + ptSourceDest = (WORD*)ptSourceDest + surfacePitch1; + ptOverLayerDest = (WORD*)ptOverLayerDest + surfacePitch2; + oy++; + } + } + } + } + lpSurface->Unlock(NULL); + lpDraw->lpBACKBUFFERSYS->Unlock(NULL); + rect.left = ox; + rect.top = oy; + rect.right = ox+w; + rect.bottom = oy+h; + lpDraw->lpBACKBUFFER->BltFast(ox,oy,lpDraw->lpBACKBUFFERSYS,&rect,DDBLTFAST_WAIT); + + return; +} +#endif + +void ablend_565(unsigned char *lpAlpha, unsigned int iAlpPitch, + unsigned char *lpSrc, unsigned int iSrcX, unsigned int iSrcY, + unsigned int iSrcPitch, unsigned char *lpDst, + unsigned int iDstX, unsigned int iDstY, + unsigned int iDstW, unsigned int iDstH, + unsigned int iDstPitch) +{ + //Mask for isolating the red,green, and blue components + static __int64 MASKB = 0x001F001F001F001F; + static __int64 MASKG = 0x07E007E007E007E0; + static __int64 MASKSHIFTG = 0x03F003F003F003F0; + static __int64 MASKR = 0xF800F800F800F800; + static __int64 SIXTEEN = 0x0010001000100010; + static __int64 FIVETWELVE = 0x0200020002000200; + static __int64 SIXONES = 0x003F003F003F003F; + unsigned char *lpLinearDstBp = (iDstX << 1) + (iDstY*iDstPitch) + lpDst; + unsigned char *lpLinearSrcBp = (iSrcX << 1) + (iSrcY*iSrcPitch) + lpSrc; + unsigned char *lpLinearAlpBp = iSrcX + (iSrcY*iAlpPitch) + lpAlpha; + _asm{ + mov esi, lpLinearSrcBp; + mov edi, lpLinearDstBp; + mov eax, lpLinearAlpBp; + mov ecx, iDstH; + mov ebx, iDstW; + test esi, 6; + jnz done; + primeloop: + movd mm1, [eax]; + pxor mm2, mm2; + movq mm4, [esi]; + punpcklbw mm1, mm2; + loopqword: + mov edx, [eax]; + test ebx, 0xFFFFFFFC; + jz checkback; + cmp edx, 0xffffffff; + je copyback; + test edx, 0xffffffff; + jz leavefront; + movq mm5, [edi]; + psrlw mm1, 2; + movq mm7, MASKSHIFTG; + psrlw mm4, 1; + movq mm0, mm1; + psrlw mm5, 1; + psrlw mm1, 1; + pand mm4, mm7; + movq mm2, SIXONES; + pand mm5, mm7; + movq mm3, [esi]; + psubsb mm2, mm0; + movq mm7, MASKB; + pmullw mm4, mm0; + movq mm0, [edi]; + pmullw mm5, mm2; + movq mm2, mm7; + pand mm3, mm7; + pmullw mm3, mm1; + pand mm0, mm7; + movq mm7, [esi]; + paddw mm4, mm5; + pand mm7, MASKR; + psubsb mm2, mm1; + paddw mm4, FIVETWELVE; + pmullw mm0, mm2; + movq mm5, mm4; + psrlw mm7, 11; + psrlw mm4, 6; + paddw mm4, mm5; + paddw mm0, mm3; + movq mm5, [edi]; + paddw mm0, SIXTEEN; + pand mm5, MASKR; + psrlw mm4, 5; + movq mm3, mm0; + psrlw mm0, 5; + psrlw mm5, 11; + paddw mm0, mm3; + psrlw mm0, 5; + pmullw mm7, mm1; //mm7=sr?*a? + + pand mm4, MASKG; //g16: mm4=00g0 00g0 00g0 00g0 green + + pmullw mm5, mm2; //r7: mm5=dr?*(31-a?) + + por mm0, mm4; //mm0=00gb 00gb 00gb 00gb + + add eax, 4; //move to next 4 alphas + + add esi, 8; //move to next 4 pixels in src + + add edi, 8; //move to next 4 pixels in dst + + movd mm1, [eax]; //mm1=00 00 00 00 a3 a2 a1 a0 + + paddw mm5, mm7; //r8: mm5=sr?*a?+dr?*(31-a?) + + paddw mm5, SIXTEEN; //r9: mm5=(mm5+16) red + + pxor mm2, mm2; //mm2=0; + + movq mm7, mm5; //r10: mm7=mm5 red + + psrlw mm5, 5; //r11: mm5=mm5>>5 red + + movq mm4, [esi]; //g1: mm4=src3 src2 src1 src0 + + paddw mm5, mm7; //r12: mm5=mm7+mm5 red + + punpcklbw mm1, mm2; //mm1=00a3 00a2 00a1 00a0 + + psrlw mm5, 5; //r13: mm5=mm5>>5 red + + psllw mm5, 11; //r14: mm5=mm5<<10 red + + por mm0, mm5; //mm0=0rgb 0rgb 0rgb 0rgb + + sub ebx, 4; //polished off 4 pixels + + movq[edi - 8], mm0; //dst=0rgb 0rgb 0rgb 0rgb + + jmp loopqword; //go back to start + + copyback: + + movq[edi], mm4; //copy source to destination + + leavefront: + + add edi, 8; //advance destination by 4 pixels + + add eax, 4; //advance alpha by 4 + + add esi, 8; //advance source by 4 pixels + + sub ebx, 4; //decrease pixel count by 4 + + jmp primeloop; + + checkback: + + test ebx, 0xFF; //check if 0 pixels left + + jz nextline; //done with this span + + //backalign: //work out back end pixels + + movq mm5, [edi]; //g2: mm5=dst3 dst2 dst1 dst0 + + psrlw mm1, 2; //mm1=a?>>2 nuke out lower 2 bits + + movq mm7, MASKSHIFTG; //g3: mm7=shift 1 bit green mask + + psrlw mm4, 1; //g3a: move src green down by 1 so that we won't overflow + + movq mm0, mm1; //mm0=00a3 00a2 00a1 00a0 + + psrlw mm5, 1; //g3b: move dst green down by 1 so that we won't overflow + + psrlw mm1, 1; //mm1=a?>>1 nuke out lower 1 bits + + pand mm4, mm7; //g5: mm4=sg3 sg2 sg1 sg0 + + movq mm2, SIXONES;//g4: mm2=63 + + pand mm5, mm7; //g7: mm5=dg3 dg2 dg1 dg0 + + movq mm3, [esi]; //b1: mm3=src3 src2 src1 src0 + + psubsb mm2, mm0; //g6: mm2=63-a3 63-a2 63-a1 63-a0 + + movq mm7, MASKB; //b2: mm7=BLUE MASK + + pmullw mm4, mm0; //g8: mm4=sg?*a? + + movq mm0, [edi]; //b3: mm0=dst3 dst2 dst1 dst0 + + pmullw mm5, mm2; //g9: mm5=dg?*(1-a?) + + movq mm2, mm7; //b4: mm2=fiveones + + pand mm3, mm7; //b4: mm3=sr3 sr2 sr1 sr0 + + pmullw mm3, mm1; //b6: mm3=sb?*a? + + pand mm0, mm7; //b5: mm0=db3 db2 db1 db0 + + movq mm7, [esi]; //r1: mm7=src3 src2 src1 src0 + + paddw mm4, mm5; //g10: mm4=sg?*a?+dg?*(1-a?) + + pand mm7, MASKR; //r2: mm7=sr3 sr2 sr1 sr0 + + psubsb mm2, mm1; //b5a: mm2=31-a3 31-a2 31-a1 31-a0 + + paddw mm4, FIVETWELVE; //g11: mm4=(i+512) green + + pmullw mm0, mm2; //b7: mm0=db?*(1-a?) + + movq mm5, mm4; //g12: mm5=(i+512) green + + psrlw mm7, 11; //r4: shift src red down to position 0 + + psrlw mm4, 6; //g13: mm4=(i+512)>>6 + + paddw mm4, mm5; //g14: mm4=(i+512)+((i+512)>>6) green + + paddw mm0, mm3; //b8: mm0=sb?*a?+db?*(1-a?) + + movq mm5, [edi]; //r3: mm5=dst3 dst2 dst1 dst0 + + paddw mm0, SIXTEEN; //b9: mm0=(i+16) blue + + pand mm5, MASKR; //r5: mm5=dr3 dr2 dr1 dr0 + + psrlw mm4, 5; //g15: mm4=0?g0 0?g0 0?g0 0?g0 green + + movq mm3, mm0; //b10: mm3=(i+16) blue + + psrlw mm0, 5; //b11: mm0=(i+16)>>5 blue + + psrlw mm5, 11; //r6: shift dst red down to position 0 + + paddw mm0, mm3; //b12: mm0=(i+16)+(i+16)>>5 blue + + psrlw mm0, 5; //b13: mm0=000r 000r 000r 000r blue + + pmullw mm7, mm1; //mm7=sr?*a? + + pand mm4, MASKG; //g16: mm4=00g0 00g0 00g0 00g0 green + + pmullw mm5, mm2; //r7: mm5=dr?*(31-a?) + + por mm0, mm4; //mm0=00gb 00gb 00gb 00gb + + add eax, 4; //move to next 4 alphas + + //stall + + paddw mm5, mm7; //r8: mm5=sr?*a?+dr?*(31-a?) + + paddw mm5, SIXTEEN; //r9: mm5=(i+16) red + + movq mm7, mm5; //r10: mm7=(i+16) red + + psrlw mm5, 5; //r11: mm5=(i+16)>>5 red + + paddw mm5, mm7; //r12: mm5=(i+16)+((i+16)>>5) red + + psrlw mm5, 5; //r13: mm5=(i+16)+((i+16)>>5)>>5 red + + psllw mm5, 11; //r14: mm5=mm5<<10 red + + por mm0, mm5; //mm0=0rgb 0rgb 0rgb 0rgb + + test ebx, 2; //check if there are 2 pixels + + jz oneendpixel; //goto one pixel if that's it + + movd[edi], mm0; //dst=0000 0000 0rgb 0rgb + + psrlq mm0, 32; //mm0>>32 + + add edi, 4; //edi=edi+4 + + sub ebx, 2; //saved 2 pixels + + jz nextline; //all done goto next line + + oneendpixel: //work on last pixel + + movd edx, mm0; //edx=0rgb + + mov[edi], dx; //dst=0rgb + + nextline: //goto next line + + dec ecx; //nuke one line + + jz done; //all done + + mov eax, lpLinearAlpBp; //alpha + + mov esi, lpLinearSrcBp; //src + + mov edi, lpLinearDstBp; //dst + + add eax, iAlpPitch; //inc alpha ptr by 1 line + + add esi, iSrcPitch; //inc src ptr by 1 line + + add edi, iDstPitch; //inc dst ptr by 1 line + + mov lpLinearAlpBp, eax; //save new alpha base ptr + + mov ebx, iDstW; //ebx=span width to copy + + mov lpLinearSrcBp, esi; //save new src base ptr + + mov lpLinearDstBp, edi; //save new dst base ptr + + jmp primeloop; //start the next span + + done: + emms + } + +} + + +//mmx ARGB +void DrawAlpha32( + unsigned long* lpDst, // Ŀ껺 + unsigned long iDstX, // Ŀλ + unsigned long iDstY, // Ŀλ + unsigned long iDstPitch, // Ŀ껺pitch + unsigned long* lpSrc, // ԭɫʻ + unsigned long iSrcX, // ԭɫλ + unsigned long iSrcY, // ԭɫλ + unsigned long iSrcW, // ԭijߴ + unsigned long iSrcH, // ԭijߴ + unsigned long iSrcPitch // ԭɫpitch + ) +{ + unsigned long *lpLinearDstBp = (iDstX)+(iDstY*iDstPitch / sizeof(DWORD)) + lpDst; //base pointer for linear destination + unsigned long *lpLinearSrcBp = (iSrcX)+(iSrcY*iSrcPitch / sizeof(DWORD)) + lpSrc; //base pointer for linear source + +_asm{ + mov edx, 0xFFFFFFFF; //255-Alpha mask + pxor mm7,mm7; //MM70 + movd mm6,edx; //MM6=FFFFFFFF + + mov esi, lpLinearSrcBp; // Դػַ + mov edi, lpLinearDstBp; // Ŀػַ + mov ecx, iSrcH; // ԭĸ߶ȺͿ + mov ebx, iSrcW; + +MainLoop: + //Ŀ꣺0xFF585C58 Դ0x71000008 + movd mm0,[esi]; //mm0=SRC MM0=0000 0000 7100 0008 + punpcklbw mm0,mm7; //SRC:32λBit64λBit MM0=0071 0000 0000 0008 + movq mm2,mm0; //mm2=SRC MM2=0071 0000 0000 0008 + punpckhwd mm0,mm0; //λALPHA ԭ0071 0000 0000 0008 0071 0071 0000 0000 + punpckhdq mm0,mm0; //˫ƶ,а˸صAlpha! 0071 0071 0071 0071 + + movd edx,mm0; + cmp edx,0x00ff00ff; + je CopySrc; + test edx, 0xffffffff; // alphaΪ0 ôӰĴı־λ,ZF=1 + jz BeginPixel; + + movq mm1,mm6; //MM1=0000 0000 FFFF FFFF + punpckhdq mm1,mm1; + movd mm3,[edi]; //mm3=DST MM3=0000 0000 FF58 5C58 + punpcklbw mm3,mm7; //mm3=32λBit64λBit MM3=00FF 0058 005C 0058 + psubb mm1,mm0; //mm1=255-src alpha bit MM1=00FF 00FF 00FF 00FF MM0=0071 0071 0071 0071 MM1=008E 008E 008E 008E + + pmullw mm2,mm0; //mm2=src*srcAlpha MM2= 0071 0000 0000 0008 MM0=0071 0071 FF71 0071 MM2= 31E1 0000 0000 0388 + pmullw mm3,mm1; //mm3=dst*(255-srcAlpha) MM3= 00FF 0058 005C 0058 MM1=008F 008F FF8E FF8E MM3=8E71 3128 D708 D8D0 + paddusw mm3,mm2; //mm3=src*srcAlpha+dst*(255-srcAlpha) MM3=8E71 3128 D708 D8D0 MM2=31E1 0000 0000 0388 MM3=C052 3128 D708 DC58 + psrlw mm3, 8; //mm3=src*srcAlpha/256+dst*(255-srcAlpha)/256 MM3=C052 3128 D708 DC58 MM3=00C0 0031 00D7 00DC + packuswb mm3,mm7; //mm3=packed dst MM3=00C0 0031 00D7 00DC MM3=0000 0000 C031 D7DC + movd [edi],mm3; + jmp BeginPixel; +CopySrc: + packuswb mm2, mm2; // + movd[edi], mm2; +BeginPixel: + add edi, 4; // Ŀǰƶ4 + add esi, 4; // Դǰƶ4 + sub ebx, 1; // ȼ4 + test ebx, 0xffffffff; // check if only 0 pixels left + jz NextLine; // ֻ0أתNextLine + jmp MainLoop; // תʼ¼ +NextLine: + dec ecx; + jz Done; // + mov esi, lpLinearSrcBp; // src + mov edi, lpLinearDstBp; // dst + add esi, iSrcPitch; // inc src ptr by 1 line + add edi, iDstPitch; // inc dst ptr by 1 line + mov ebx, iSrcW; // ebx=span width to copy + mov lpLinearSrcBp, esi; // save new src base ptr + mov lpLinearDstBp, edi; // save new dst base ptr + jmp MainLoop; // start the next span +Done: + emms; + } +} + + + +BOOL ȡߴ(ACTION* a0,S2 *wx,S2* wy) +{ + int chrNo = ATR_CHR_NO(a0) - SPRSTART; + if(chrNo < 0){ + int BmpNo; + realGetNo( ATR_CHR_NO(a0) , (U4 *)&BmpNo ); + if(realGetWH(BmpNo, wx, wy)) return TRUE; + else return FALSE; + }else{ + if(chrNo >= mxSPRITE) return FALSE; + ANIMLIST * ptAnimlist = SpriteData[chrNo].ptAnimlist; + if(ptAnimlist){ + FRAMELIST * ptFramelist = ptAnimlist[0].ptFramelist; + if(realGetWH(ptFramelist[0].BmpNo, wx, wy)) return TRUE; + else return FALSE; + } + } + return FALSE; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/sprmgr.cpp b/石器时代8.5客户端最新源代码/石器源码/system/sprmgr.cpp new file mode 100644 index 0000000..b9c30b6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/sprmgr.cpp @@ -0,0 +1,437 @@ +/************************/ +/* sprmgr.c */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadrealbin.h" +#include "../systeminc/loadsprbin.h" +LPDIRECTDRAWSURFACE lpBattleSurface; +#ifdef _READ16BITBMP +LPDIRECTDRAWSURFACE lpBattleSurfaceSys; +#endif +extern int MessageBoxNew(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); +#ifdef _STONDEBUG_ +int SurfaceDispCnt; +#endif + +int SurfaceSizeX; +int SurfaceSizeY; +UINT SurfaceDate = 3; + +#define SURACE_INFO_MAX 3072 +#define SURACE_BMP_DEATH_DATE 2 +SPRITE_INFO SpriteInfo[ MAX_GRAPHICS ]; +SURFACE_INFO SurfaceInfo[ SURACE_INFO_MAX ]; +#ifdef _READ16BITBMP +SURFACE_INFO SurfaceInfoSys[SURACE_INFO_MAX]; +extern BOOL g_bUseAlpha; +#endif +int SurfaceSearchPoint; + +#ifdef _STONDEBUG_ +int SurfaceUseCnt; +extern int g_iMallocCount; +#endif + +int SurfaceCnt; +int VramSurfaceCnt; +int SysramSurfaceCnt; +#ifdef _READ16BITBMP +void AllocateBmpToSurface( int bmpNo,BOOL useAlpha ) +#else +void AllocateBmpToSurface( int bmpNo) +#endif +{ + int bmpWidth = RealBinWidth; // ???????? + int bmpHeight = RealBinHeight; // ??????? + + int offsetX, offsetY; // ??????????????? + int sizeX, sizeY; // ?????? + int surfaceCntX; // ??????????? + int surfaceCntY; // ??????????? + int totalSurface; // ?????????? + int totalSurfaceCnt = 0; // ??????????????? ??????? ? + int SurfaceSearchPointBak = SurfaceSearchPoint; // ???????????????t??? + int amariSizeX = FALSE; // ??????????? + int amariSizeY = FALSE; // ?????????? + BOOL vramFullFlag = FALSE; // VRAM????????? + SURFACE_INFO *prevSurfaceInfo; // q???????????Bl????? + offsetX = 0; +#ifdef _READ16BITBMP + SURFACE_INFO *prevSurfaceInfoSys; + RECT rect = {0,0,SurfaceSizeX,SurfaceSizeY}; + if(bmpNo >= OLD_GRAPHICS_START) offsetY = 0; + else +#endif + offsetY = bmpHeight; + surfaceCntX = bmpWidth / SURFACE_WIDTH; + if( (amariSizeX = bmpWidth % SURFACE_WIDTH)){ + surfaceCntX++; + } + + surfaceCntY = bmpHeight / SURFACE_HEIGHT; + if( ( amariSizeY = bmpHeight % SURFACE_HEIGHT ) ){ + surfaceCntY++; // ?????? + } + totalSurface = surfaceCntX * surfaceCntY; +#ifdef _READ16BITBMP + if(bmpNo < OLD_GRAPHICS_START) +#endif + { + if((RealBinWidth & 3)) RealBinWidth += 4 - RealBinWidth & 3; + } + while( 1 ){ + if( SurfaceInfo[ SurfaceSearchPoint ].date < SurfaceDate - SURACE_BMP_DEATH_DATE ){ +#ifdef _STONDEBUG_ + SurfaceUseCnt++; +#endif + // ʹ + if( SurfaceInfo[ SurfaceSearchPoint ].bmpNo != -1 ){ + SURFACE_INFO *lpSurfaceInfo; +#ifdef _READ16BITBMP + SURFACE_INFO *lpSurfaceInfoSys; +#endif + lpSurfaceInfo = SpriteInfo[ SurfaceInfo[ SurfaceSearchPoint ].bmpNo ].lpSurfaceInfo; + SpriteInfo[ SurfaceInfo[ SurfaceSearchPoint ].bmpNo ].lpSurfaceInfo = NULL; +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + lpSurfaceInfoSys = SpriteInfo[ SurfaceInfo[ SurfaceSearchPoint ].bmpNo ].lpSurfaceInfoSys; + SpriteInfo[SurfaceInfo[SurfaceSearchPoint].bmpNo].lpSurfaceInfoSys = NULL; + } +#endif + for( ; lpSurfaceInfo != NULL; + lpSurfaceInfo = lpSurfaceInfo->pNext ){ + lpSurfaceInfo->bmpNo = -1; +#ifdef _READ16BITBMP + if(g_bUseAlpha) lpSurfaceInfoSys->bmpNo = -1; +#endif +#ifdef _STONDEBUG_ + SurfaceUseCnt--; +#endif + } + } + if( SpriteInfo[ bmpNo ].lpSurfaceInfo == NULL ){ + // һͼsurfaceinfo + SpriteInfo[ bmpNo ].lpSurfaceInfo = &SurfaceInfo[ SurfaceSearchPoint ]; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SpriteInfo[bmpNo].lpSurfaceInfoSys = &SurfaceInfoSys[SurfaceSearchPoint]; +#endif + }else{ + // ָһsurfaceinfo + prevSurfaceInfo->pNext = &SurfaceInfo[ SurfaceSearchPoint ]; +#ifdef _READ16BITBMP + if(g_bUseAlpha) prevSurfaceInfoSys->pNext = &SurfaceInfoSys[SurfaceSearchPoint]; +#endif + } + SurfaceInfo[ SurfaceSearchPoint ].bmpNo = bmpNo; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].bmpNo = bmpNo; +#endif + if(ResoMode == 1){ + SurfaceInfo[ SurfaceSearchPoint ].offsetX = offsetX / 2; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetX = offsetX / 2; + if(bmpNo >= OLD_GRAPHICS_START){ + SurfaceInfo[SurfaceSearchPoint].offsetY = offsetY / 2; + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetY = offsetY / 2; + } + else +#endif + { + SurfaceInfo[ SurfaceSearchPoint ].offsetY = ( bmpHeight - offsetY ) / 2; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetY = ( bmpHeight - offsetY ) / 2; +#endif + } + } + else{ + SurfaceInfo[ SurfaceSearchPoint ].offsetX = offsetX; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetX = offsetX; + if(bmpNo >= OLD_GRAPHICS_START){ + SurfaceInfo[SurfaceSearchPoint].offsetY = offsetY; + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetY = offsetY; + } + else +#endif + { + SurfaceInfo[ SurfaceSearchPoint ].offsetY = bmpHeight - offsetY; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].offsetY = bmpHeight - offsetY; +#endif + } + } + + if( offsetX >= bmpWidth - SURFACE_WIDTH && amariSizeX ){ + ClearSurface( SurfaceInfo[ SurfaceSearchPoint ].lpSurface ); +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + ClearSurface(SurfaceInfoSys[SurfaceSearchPoint].lpSurface); + if(SurfaceInfo[SurfaceSearchPoint].lpAlphaData) + memset(SurfaceInfo[SurfaceSearchPoint].lpAlphaData,0,SurfaceSizeX*SurfaceSizeY); + } +#endif + sizeX = amariSizeX; + } + else sizeX = SURFACE_WIDTH; + +#ifdef _READ16BITBMP + if(bmpNo >= OLD_GRAPHICS_START){ + if(offsetY >= bmpHeight - SURFACE_HEIGHT && amariSizeY){ + ClearSurface(SurfaceInfo[SurfaceSearchPoint].lpSurface); + if(g_bUseAlpha){ + ClearSurface(SurfaceInfoSys[SurfaceSearchPoint].lpSurface); + if(SurfaceInfo[SurfaceSearchPoint].lpAlphaData) + memset(SurfaceInfo[SurfaceSearchPoint].lpAlphaData,0,SurfaceSizeX*SurfaceSizeY); + } + sizeY = amariSizeY; + }else sizeY = SURFACE_HEIGHT; + } + else +#endif + { + if( offsetY - SURFACE_HEIGHT <= 0 && amariSizeY ){ + if( sizeX != amariSizeX ){ + ClearSurface( SurfaceInfo[ SurfaceSearchPoint ].lpSurface ); +#ifdef _READ16BITBMP + if(g_bUseAlpha) ClearSurface(SurfaceInfoSys[SurfaceSearchPoint].lpSurface); +#endif + } + sizeY = amariSizeY; + }else sizeY = SURFACE_HEIGHT; + } + +#ifdef _READ16BITBMP + SurfaceInfo[SurfaceSearchPoint].useAlpha = useAlpha; + SurfaceInfoSys[SurfaceSearchPoint].useAlpha = useAlpha; + if(bmpNo >= OLD_GRAPHICS_START){ + Draw16BitmapToSurface2(&SurfaceInfo[SurfaceSearchPoint], + SurfaceInfoSys[SurfaceSearchPoint].lpSurface, + offsetX, + offsetY, + sizeX, + sizeY, + NULL); + } + else{ + if(g_bUseAlpha){ + DrawBitmapToSurface2(&SurfaceInfo[ SurfaceSearchPoint ], + SurfaceInfoSys[SurfaceSearchPoint].lpSurface, + offsetX, + offsetY - 1, + sizeX, + sizeY, + NULL ); + } + else{ + DrawBitmapToSurface2(SurfaceInfo[ SurfaceSearchPoint ].lpSurface, + offsetX, + offsetY - 1, + sizeX, + sizeY, + NULL ); + } + } +#else + DrawBitmapToSurface2( &SurfaceInfo[ SurfaceSearchPoint ], + offsetX, + offsetY - 1, + sizeX, + sizeY, + NULL ); +#endif + totalSurfaceCnt++; + // еͼѴoffscreen + if( totalSurfaceCnt >= totalSurface ){ + SurfaceInfo[ SurfaceSearchPoint ].pNext = NULL; +#ifdef _READ16BITBMP + if(g_bUseAlpha) SurfaceInfoSys[SurfaceSearchPoint].pNext = NULL; +#endif + SurfaceSearchPoint++; + + if( SurfaceSearchPoint >= SurfaceCnt ) SurfaceSearchPoint = 0; + break; + }else{ + prevSurfaceInfo = &SurfaceInfo[ SurfaceSearchPoint ]; +#ifdef _READ16BITBMP + if(g_bUseAlpha) prevSurfaceInfoSys = &SurfaceInfoSys[SurfaceSearchPoint]; +#endif + if( offsetX >= bmpWidth - SURFACE_WIDTH ){ + offsetX = 0; +#ifdef _READ16BITBMP + if(bmpNo >= OLD_GRAPHICS_START) offsetY += SURFACE_HEIGHT; + else +#endif + offsetY -= SURFACE_HEIGHT; + }else{ + offsetX += SURFACE_WIDTH; + } + } + } + SurfaceSearchPoint++; + if( SurfaceSearchPoint >= SurfaceCnt ) SurfaceSearchPoint = 0; + if( SurfaceSearchPoint == SurfaceSearchPointBak ) break; + } +} + +BOOL InitOffScreenSurface( void ) +{ + int i; + BOOL vramFullFlag = TRUE; + SurfaceCnt = 0; + VramSurfaceCnt = 0; + SysramSurfaceCnt = 0; + for( i = 0 ; i < SURACE_INFO_MAX ; i++ ){ + if( vramFullFlag == FALSE ){ + if ((SurfaceInfo[i].lpSurface = CreateSurface(SurfaceSizeX, SurfaceSizeY, DEF_COLORKEY, /*DDSCAPS_SYSTEMMEMORY*/ DDSCAPS_VIDEOMEMORY)) == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd ,"SurfaceInfo:VideoRAM Surfaceʧܣ" ,"ȷ",MB_OK | MB_ICONSTOP ); +#endif + vramFullFlag = TRUE; + }else{ + VramSurfaceCnt++; + } + } + if( vramFullFlag == TRUE ){ + if( ( SurfaceInfo[ i ].lpSurface = CreateSurface( SurfaceSizeX, SurfaceSizeY, DEF_COLORKEY, DDSCAPS_SYSTEMMEMORY )) == NULL ){ +#ifdef _STONDEBUG_ + MessageBoxNew( hWnd ,"SysRAM Surfaceʧܣ" ,"ȷ",MB_OK | MB_ICONSTOP ); +#endif + return FALSE; + }else SysramSurfaceCnt++; + } +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if((SurfaceInfo[i].lpAlphaData = (BYTE*)MALLOC(SurfaceSizeX*SurfaceSizeY)) == NULL){ + #ifdef _STONDEBUG_ + MessageBoxNew( hWnd ,"alphaʧܣ","ȷ",MB_OK | MB_ICONSTOP); + #endif + return FALSE; + } + else{ +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + SysramSurfaceCnt++; + } + } +#endif +#ifdef _READ16BITBMP + if(g_bUseAlpha){ + if((SurfaceInfoSys[i].lpSurface = CreateSurface(SurfaceSizeX,SurfaceSizeY,DEF_COLORKEY,DDSCAPS_SYSTEMMEMORY )) == NULL){ + #ifdef _STONDEBUG_ + MessageBoxNew(hWnd,"SysRAM Surface(2)ʧܣ","ȷ",MB_OK | MB_ICONSTOP); + #endif + return FALSE; + } + else SysramSurfaceCnt++; + } +#endif + } + SurfaceCnt = i; + InitSurfaceInfo(); + InitSpriteInfo(); + return TRUE; +} + +void InitSurfaceInfo( void ) +{ + int i; +#ifdef _STONDEBUG_ + SurfaceUseCnt = 0; +#endif + SurfaceSearchPoint = 0; + for( i = 0 ; i < SurfaceCnt ; i++ ){ + SurfaceInfo[ i ].bmpNo = -1; + SurfaceInfo[ i ].date = 0; + SurfaceInfo[ i ].pNext = NULL; +#ifdef _READ16BITBMP + SurfaceInfo[i].useAlpha = FALSE; + SurfaceInfoSys[i].bmpNo = -1; + SurfaceInfoSys[i].date = 0; + SurfaceInfoSys[i].pNext = NULL; + SurfaceInfoSys[i].useAlpha = FALSE; +#endif + } +} + +void InitSpriteInfo( void ) +{ + int i; + for( i = 0 ; i < MAX_GRAPHICS ; i++ ){ + SpriteInfo[ i ].lpSurfaceInfo = NULL; +#ifdef _READ16BITBMP + SpriteInfo[i].lpSurfaceInfoSys = NULL; +#endif + } +} +extern int NewColor16Flg; +#define REALGETIMAGEMAXSIZE 1600*1600 + +extern int displayBpp; +BOOL LoadBmp( int bmpNo ) +{ +#ifndef _READ16BITBMP + if((unsigned)bmpNo > MAX_GRAPHICS) return FALSE; + if(SpriteInfo[bmpNo].lpSurfaceInfo == NULL){ + if( realGetImage(bmpNo,(unsigned char **)&pRealBinBits, + &RealBinWidth,&RealBinHeight ) == FALSE ){ + return FALSE; + } + SpriteInfo[ bmpNo ].width = RealBinWidth; + SpriteInfo[ bmpNo ].height = RealBinHeight; +#ifdef _NEW_COLOR_ + if(NewColor16Flg==2)SpriteInfo[bmpNo].AlphaFlg=TRUE; + else SpriteInfo[bmpNo].AlphaFlg=FALSE; +#endif + AllocateBmpToSurface( bmpNo ); + } +#ifdef _CACHE_SURFACE_ + else{ + //Ѿ棬ˢdateⱻͷ + for (SURFACE_INFO* info = SpriteInfo[bmpNo].lpSurfaceInfo; info->pNext != NULL; info = info->pNext) + { + info->date = SurfaceDate; + } + } +#endif + return TRUE; +#else + BOOL useAlpha; + + if((unsigned)bmpNo >= OLD_GRAPHICS_START){ + if((unsigned)bmpNo >= MAX_GRAPHICS) return FALSE; + if(SpriteInfo[bmpNo].lpSurfaceInfo == NULL){ + pRealBinAlpha = NULL; + if(Read16BMP(bmpNo - OLD_GRAPHICS_START,(unsigned char **)&pRealBinBits, + &RealBinWidth,&RealBinHeight,(unsigned char **)&pRealBinAlpha,&useAlpha) == FALSE) return FALSE; + SpriteInfo[bmpNo].width = RealBinWidth; + SpriteInfo[bmpNo].height = RealBinHeight; + AllocateBmpToSurface(bmpNo,useAlpha); + } + return TRUE; + }else{ + if(SpriteInfo[bmpNo].lpSurfaceInfo == NULL){ + pRealBinAlpha = NULL; + if(realGetImage(bmpNo,(unsigned char **)&pRealBinBits, + &RealBinWidth,&RealBinHeight) == FALSE) return FALSE; + + if(NewColor16Flg==2){ + #define REALGETIMAGEMAXSIZE 1600*1600 + extern BYTE g_realgetimagebuf[REALGETIMAGEMAXSIZE]; + int i=0; + int b = RealBinWidth*RealBinHeight; + memset(g_realgetimagebuf,0,b); + pRealBinAlpha = g_realgetimagebuf; + for(i;i +#include "../systeminc/version.h" +#include "../systeminc/process.h" +#include "../systeminc/t_music.h" +#include "../systeminc/handletime.h" +#include "../systeminc/savedata.h" +#include "../systeminc/system.h" +#define ACTIVE 1 +//#include "system.h" +//#include "../oft/vg410.h" + +extern DWORD NowTime; +//extern double NowTime; // ??????? + +/*???????????*/ +#define DEBUG_ON 1 +#define THREAD_ON 1 +#define MODE98 0 +#define CLASS_UP 1 +#define VOICE_KILL_ON 0 + +//־ +BOOL MuteFlag = FALSE; + +typedef struct{ + int name; + int tone_no; + int volume; + int note_no; + int release_cnt; + int release_spd; + int lfo_h; + int lfo_m; + int lfo_s; + int lfo_s_cnt; + int lfo_s_ang; + int pan; + int loop_flg; + int delay_cnt; + long freq; +} VOICE_EQU; + +#define MAX_ENV 20 +typedef struct{ + int voice_address; //??????????????? + int tone; + int count; + int distance; + int volume; + int volume_old; + int side; + int panpot; + int panpot_old; +} ENVIRONMENT_EQU; +ENVIRONMENT_EQU env_tbl[MAX_ENV]; + +#define DEBUG 0 +#define MY_TIMER 1 +#define VOICE_MAX 64 +#define TRACK_MAX 32 +//#define STRICT +#include +#include +#include +#include +#include +#include "../systeminc/math2.h" +#include +#include "../systeminc/main.h" + +#include +#include +#include +extern int MessageBoxNew(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType); +#define RELEASE(x) if(x){x->Release();x=NULL;} +#define LOG(a,b) (log((float)b)/log((float)a)) + +static int mes_flg=0; + +#if THREAD_ON +int thread_flg=0; +#endif +int dsound_flg=0; + +/*------------------------------------------- + ??? +--------------------------------------------*/ +LPDIRECTSOUND pDSound = NULL; +LPDIRECTSOUNDBUFFER pDSPrimary = NULL; +LONG primaryVolume; +LONG primaryPan; +LONG primaryFrequency; + +LPDIRECTSOUNDBUFFER pDSData_tone[TONE_MAX + 1]; +LPDIRECTSOUNDBUFFER pDSData_stream; +LPDIRECTSOUNDBUFFER pDSData[VOICE_MAX]; +BOOL dataPlay[VOICE_MAX]; +int dataVolume[TRACK_MAX]; +int dataPan[TRACK_MAX]; +LONG dataFrequency[TRACK_MAX]; +VOICE_EQU voice[VOICE_MAX]; +TONE_EQU tone_tbl[TONE_MAX]; +int tone_max_buf; + +#if VOICE_KILL_ON +int voice_kill_buf[VOICE_MAX]; +int voice_kill_point; +#endif + +int t_music_playing_flg = 0; +int t_music_fade_flg = 0; +int t_music_fade_vol; +int draw_map_bgm_flg = 0; +static int map_bgm_vct_no = 0; +int map_bgm_no = 0; + +/*------------------------------------------- + Wave???????? +--------------------------------------------*/ +BOOL LoadWave( + LPCTSTR lpName, // Wave??? + WAVEFORMATEX* (&pWaveHeader), // WAVEFORMATEX?Bl?????? + BYTE* (&pbWaveData), // ?????????????? + DWORD &cbWaveSize) // ???????????? +{ + pWaveHeader = NULL; // WAVEFORMATEX?Bl?????? + pbWaveData = NULL; // ?????????????? + cbWaveSize = 0; // ???????????? + const char c_szWAV[] = "WAVE"; // ??????Wave????????"WAVE"??? + + // ?????????????????? + HRSRC hResInfo = FindResource(NULL, lpName, c_szWAV); + if(hResInfo == NULL) + return FALSE; + HGLOBAL hResData = LoadResource(NULL, hResInfo); + if(hResData == NULL) + return FALSE; + void *pvRes = LockResource(hResData); + if(pvRes == NULL) + return FALSE; + + // ??????????????????????????????????x?? + DWORD *pdw = (DWORD *)pvRes; + DWORD *pdwEnd; + DWORD dwRiff = *pdw++; + DWORD dwLength = *pdw++; + DWORD dwType = *pdw++; + + if (dwRiff != mmioFOURCC('R', 'I', 'F', 'F')) + return FALSE; // ???????RIFF????????? + if (dwType != mmioFOURCC('W', 'A', 'V', 'E')) + return FALSE; // ???????Wave????????? + pdwEnd = (DWORD *)((BYTE *)pdw + dwLength-4); + + while (pdw < pdwEnd) + { + dwType = *pdw++; + dwLength = *pdw++; + + switch (dwType) + { + case mmioFOURCC('f', 'm', 't', ' '): + if (pWaveHeader == NULL) + { + if (dwLength < sizeof(WAVEFORMAT)) + return FALSE; // ?????????Wave????????? + pWaveHeader = (WAVEFORMATEX *)pdw; + } + break; + case mmioFOURCC('d', 'a', 't', 'a'): + if ((pbWaveData == NULL) || (!cbWaveSize)) + { + pbWaveData = (LPBYTE)pdw; + cbWaveSize = dwLength; + } + break; + } + if(pWaveHeader && (pbWaveData != NULL) && cbWaveSize) + break; + pdw = (DWORD *)((BYTE *)pdw + ((dwLength+1)&~1)); + } + if(pdwEnd <= pdw) + return FALSE; // ?????????Wave????????? + + // Wave???x? + + return TRUE; +} + +/*------------------------------------------- + ???????????????????? +--------------------------------------------*/ +BOOL CreateSoundData(LPCSTR pName, LPDIRECTSOUNDBUFFER &pDSData) +{ + // ??????Wave??????? + WAVEFORMATEX *pWaveHeader = NULL; // WAVEFORMATEX?Bl?????? + BYTE *pbWaveData = NULL; // ?????????????? + DWORD cbWaveSize = 0; // ???????????? + if(!LoadWave(pName, pWaveHeader, pbWaveData, cbWaveSize)) + { +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡWaveʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + + // ?????????????? + DSBUFFERDESC dsbdesc; + HRESULT hr; + // DSBUFFERDESC?Bl?@e + ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); + dsbdesc.dwSize = sizeof(DSBUFFERDESC); + // ?????????????? +#if ACTIVE + dsbdesc.dwFlags = DSBCAPS_STATIC | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; +#else + dsbdesc.dwFlags = DSBCAPS_STATIC | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2; +#endif + dsbdesc.dwBufferBytes = cbWaveSize; + dsbdesc.lpwfxFormat = pWaveHeader; + // ??????? + hr = pDSound->CreateSoundBuffer(&dsbdesc, &pDSData, NULL); + if(DS_OK != hr) { + // ??????? + return FALSE; + } + + // ???????????Wave???????? + LPVOID lpvPtr1; // ???????????? + DWORD dwBytes1; // ??????????? + LPVOID lpvPtr2; // ?k??????????? + DWORD dwBytes2; // ?k?????????? + + hr = pDSData->Lock(0, cbWaveSize, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0); + + // DSERR_BUFFERLOST??????Restore???????????????? + if(DSERR_BUFFERLOST == hr) { + pDSData->Restore(); + hr = pDSData->Lock(0, cbWaveSize, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0); + } + if(DS_OK == hr) { + // ???? + + // ????????????? + // ?????????????? + CopyMemory(lpvPtr1, pbWaveData, dwBytes1); + if ( 0 != dwBytes2 ) + CopyMemory(lpvPtr2, pbWaveData + dwBytes1, dwBytes2); + + // ????????????Unlock??? + hr = pDSData->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2); + } + + return TRUE; +} + +// ???????ѩ??? +// +// ? ? hmmio ... ???????????? +// pWfmtx ... ???ѩ?t?????? +// pDataSize ... ?????? +// ??k TRUE ... ? +// FALSE ... +static BOOL WaveFormatRead( HMMIO hmmio, WAVEFORMATEX *pWfmtx, DWORD *pDataSize ) +{ + MMCKINFO parent, child; + + parent.ckid = (FOURCC)0; + parent.cksize = 0; + parent.fccType = (FOURCC)0; + parent.dwDataOffset = 0; + parent.dwFlags = 0; + child = parent; + + //WAVE?????S? + parent.fccType = mmioFOURCC('W','A','V','E'); + if ( (int)mmioDescend(hmmio,&parent,NULL,MMIO_FINDRIFF) ){ +// ERRPRINT("WAVE?????S?"); + return FALSE; + } + + //fmt?????V? + child.ckid = mmioFOURCC('f', 'm', 't', ' '); + if ( mmioDescend( hmmio , &child , &parent , MMIO_FINDCHUNK ) ){ +// ERRPRINT("fmt?????V?"); + return FALSE; + } + + //??????????x + if (mmioRead( hmmio , (char *)pWfmtx , sizeof(WAVEFORMATEX) ) != sizeof(WAVEFORMATEX) ){ +// ERRPRINT("??????????x"); + return FALSE; + } + + //?????????????????? + if (pWfmtx->wFormatTag != WAVE_FORMAT_PCM ){ +// ERRPRINT("????????????????"); + return FALSE; + } + //?????????I?? + if (mmioAscend( hmmio , &child , 0 )){ +// ERRPRINT("?????????I??"); + return FALSE; + } + + //data?????V? + child.ckid = mmioFOURCC( 'd' , 'a' , 't' , 'a' ); + if ( mmioDescend( hmmio , &child , &parent , MMIO_FINDCHUNK ) ){ +// ERRPRINT("data?????V?"); + return FALSE; + } + + *pDataSize = child.cksize; + + return TRUE; +} + +static BYTE *pDSbuffData; + +// +// ?????????? +// +// ? ? hmmio ... ???????????? +// pDataSize ... ????????? +// pData ... DirectSoundBuffer +// ??k TRUE ... ? +// FALSE ... +static BOOL WaveDataRead( HMMIO hmmio , DWORD *pDataSize, LPDIRECTSOUNDBUFFER pData ) +{ +// BYTE *pDSbuffData; + + //?????????? + if( pData->Lock(0 , *pDataSize , (LPVOID*)&pDSbuffData , pDataSize , NULL , 0, 0 ) != DS_OK ) + return FALSE; + + //??????????? + *pDataSize = (DWORD)mmioRead(hmmio , (char*)pDSbuffData , *pDataSize); + + //????? + if( pData->Unlock( pDSbuffData , *pDataSize , NULL , 0 ) != DS_OK ) + return FALSE; + + return TRUE; +} + + +// +// ??????????x +// +// ? ? pWfmtx ... ??????????? +// DataSize ... ???????? +// ppData ... x???????????????? +// ??k TRUE ... ? +// FALSE ... +static BOOL dwSoundInit( WAVEFORMATEX *pWfmtx, DWORD DataSize, LPDIRECTSOUNDBUFFER *ppData ) +{ + DSBUFFERDESC dsbufferdesc; + + //?????????????? + memset( &dsbufferdesc , 0 , sizeof( DSBUFFERDESC ) ); + dsbufferdesc.dwSize = sizeof( DSBUFFERDESC ); +// dsbufferdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_CTRLDEFAULT | DSBCAPS_GETCURRENTPOSITION2; +#if ACTIVE + dsbufferdesc.dwFlags = DSBCAPS_STATIC | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; +#else + dsbufferdesc.dwFlags = DSBCAPS_STATIC | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2; +#endif + dsbufferdesc.dwBufferBytes = DataSize; + dsbufferdesc.lpwfxFormat = pWfmtx; + if ( pDSound->CreateSoundBuffer( &dsbufferdesc , ppData , NULL ) != DS_OK ) + return FALSE; + + return TRUE; +} + +int f_get(FILE *fp); +int get_num(FILE *fp); +int num_check(FILE *fp); + +// ?????q?????? +#define mxSTR 200 +/*------------------------------------------- + DirectSound ??? +--------------------------------------------*/ +int InitDSound(void) +{ + HRESULT ret; + int d7; + + pDSound = NULL; + pDSPrimary = NULL; + for(d7=0;d7SetCooperativeLevel(hWnd, DSSCL_PRIORITY); + if(ret != DS_OK){ + // ?????@e? + RELEASE(pDSound); +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "趨Эȼʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + // ?????@e + pDSound ->SetSpeakerConfig(DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE)); + // ???????????? + // DSBUFFERDESC?Bl?@e + DSBUFFERDESC dsbdesc; + ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); + dsbdesc.dwSize = sizeof(DSBUFFERDESC); + // ???????????e + dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + dsbdesc.dwBufferBytes = 0; + dsbdesc.lpwfxFormat = NULL; + // ??????? + ret = pDSound->CreateSoundBuffer(&dsbdesc, &pDSPrimary, NULL); + if(ret != DS_OK) { +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "Ҫbufferʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + // ???????????Wave???????@e + // ?I???????????@e???????????? + WAVEFORMATEX pcmwf; + ZeroMemory(&pcmwf, sizeof(WAVEFORMATEX)); + pcmwf.wFormatTag = WAVE_FORMAT_PCM; + pcmwf.nChannels = 2; // ???????????? + pcmwf.nSamplesPerSec = 22050; // ?????????? 22.05kHz + pcmwf.nBlockAlign = 4; + pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign; + pcmwf.wBitsPerSample = 16; // 16??? + ret = pDSPrimary->SetFormat(&pcmwf); + if(ret != DS_OK){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "Ҫbufferĸʽʧܣ", "Error", MB_OK); +#endif + return FALSE; + } +/* +//cary ʹresourcesound data + // ????????????????????? + for(d7=0;d7 TONE_MAX){ //??????? + goto InitDSound_err2; //??? + } + tone_tbl[ program_no ].voice_place = tone_max_buf; //????IV + //q?x + strcpy( fname, sndconfig[ d1 ].name ); + + if(sndconfig[ d1 ].vol < 0){ //???????????? + goto InitDSound_err2; + } + tone_tbl[ program_no ].voice_volume = sndconfig[ d1 ].vol; //??????V + + if(sndconfig[ d1 ].note > 60){ //???k?????? + goto InitDSound_err2; + } + if(sndconfig[ d1 ].note){ //???k?V + tone_tbl[ program_no ].voice_note = sndconfig[ d1 ].note; + } else { + tone_tbl[ program_no ].voice_note = 0; + } + //????????? + tone_tbl[ program_no ].voice_loop = sndconfig[ d1 ].loop_flg; + + //??????????? + int d2; + FILE *fp; + fp = fopen( fname, "rb" ); + if( fp == NULL ){ + d1++; //SNDCONFIG?????? + continue; + } + d2 = 8; //?????????????? + d2 += 4; //?????????????? + d2 += 4; //???? ????????? + d2 += 8; //???????? + fseek(fp,d2,SEEK_CUR); //??????????h + d2 = fgetc(fp); //??????????? + d2 |= fgetc(fp) << 8; //??????????? + d2 |= fgetc(fp) << 16; //??????????? + d2 |= fgetc(fp) << 24; //??????????? + switch(d2){ + case 11025: + tone_tbl[ program_no ].voice_rate = 25; + break; + case 22050: + tone_tbl[ program_no ].voice_rate = 37; + break; + case 44100: + tone_tbl[ program_no ].voice_rate = 49; + break; + } + fclose(fp); + + //???????????? + if( (hmmio = mmioOpen(fname, NULL, MMIO_READ | MMIO_ALLOCBUF )) == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "WAVʧܣ", "Error", MB_OK); +#endif + goto InitDSound_err; + } + //??????????? + if( WaveFormatRead( hmmio , &Wfmtx , &WaveSize ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡWAVʽʧܣ", "Error", MB_OK); +#endif + goto InitDSound_err; + } + DataSize = WaveSize; + //?????????????? + if( dwSoundInit( &Wfmtx, DataSize, &pDSData_tone[tone_max_buf] ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ʼbufferʧܣ", "Error", MB_OK); +#endif + goto InitDSound_err; + } + //??????? + if( WaveDataRead( hmmio, &DataSize, pDSData_tone[tone_max_buf] ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡWAVʧܣ", "Error", MB_OK); +#endif + goto InitDSound_err; + } + mmioClose( hmmio , 0 ); + hmmio = (HMMIO)-1; //????????? + d1++; //SNDCONFIG?????? + tone_max_buf++; //????I? + } + +InitDSound_err: //????????????? + mmioClose( hmmio , 0 ); + for(d7=0;d7DuplicateSoundBuffer(pDSData_tone[0],&pDSData[d7]) != DS_OK ){ + for(d7=0;d7GetVolume(&primaryVolume); + // ????? + pDSPrimary->GetPan(&primaryPan); + // ? + pDSPrimary->GetFrequency((DWORD*)&primaryFrequency); + return TRUE; +} + +volatile static char exit_thread_flg = 0; +static int thread_loop_start; +//static int thread_loop_end; +static int thread_stop_flg = 0; +static LPDIRECTSOUNDNOTIFY pDSNotify = NULL; +static char stream_flg = 0; +/*------------------------------------------- + ????_?? +--------------------------------------------*/ +void stop_thread(void) +{ + //????_?? + if(thread_stop_flg){ + //???_ + pDSData_tone[ TONE_MAX ]->Stop(); +// pDSData_stream->Stop(); + while(1){ + if(exit_thread_flg == 1) + break; + } + thread_stop_flg = 0; + exit_thread_flg = 0; + RELEASE(pDSData_stream); + } + //?????????? + RELEASE(pDSData_tone[TONE_MAX]); +} + +/*------------------------------------------- + ???_?? +--------------------------------------------*/ +void stop_bgm(void) +{ + if (MuteFlag) return; + //????_?? + if(thread_stop_flg){ + //????_? + stop_thread(); + } else { + //?????????? + RELEASE(pDSData_tone[TONE_MAX]); + } + //?????????? + t_music_fade_flg = 0; + //???????? + t_music_playing_flg = 0; + //????????k???? + map_bgm_vct_no = 0; + map_bgm_no = t_music_bgm_no; +} + +/*------------------------------------------- + ????????? +--------------------------------------------*/ +void fade_out_bgm(void) +{ + //???????? + t_music_fade_flg = 1; + //?????V + t_music_fade_vol = bgm_tbl[t_music_bgm_no].volume * t_music_bgm_volume / 15; + +} + +/*------------------------------------------- + ???? +--------------------------------------------*/ +int EndApp(void) +{ + int d7; + //????_? + stop_thread(); + RELEASE(pDSData_tone[TONE_MAX]); + //????? + if(stream_flg == 1){ + RELEASE(pDSNotify); + } + for(d7=0;d7Stop(); + RELEASE( pDSData[d7] ); + } + for(d7=0;d7Stop(); + RELEASE( pDSData_tone[d7] ); + } + RELEASE(pDSPrimary); + RELEASE(pDSound); + + return TRUE; +} + +#define MUSIC_END -1 +#define MUSIC_R -2 +#define MUSIC_LOOP -3 +#define MUSIC_FREQ -4 +#define MUSIC_VOL -5 +#define MUSIC_PAN -6 +#define MUSIC_TEMPO -7 +#define MUSIC_PEDAL -8 +#define MUSIC_NEIRO_NO -9 +#define MUSIC_KURI_RET -10 +#define MUSIC_KURI_SKIP -11 +#define MUSIC_KURI_START -12 +#define MUSIC_WAVE -13 +#define MUSIC_WAON -14 +#define MUSIC_DETUNE -15 +#define MUSIC_LFO_H -16 +#define MUSIC_LFO_M -17 +#define MUSIC_LFO_S -18 +static int cnt=0,cnt2=0; +static LARGE_INTEGER d_cnt; +static int ch; +static int step_time[TRACK_MAX]; +static int gate_time[TRACK_MAX]; +static int d_pedal[TRACK_MAX]; +static int wave[TRACK_MAX]; +static int step_point[TRACK_MAX]; +static int step_def[TRACK_MAX]; +static int play_flg[TRACK_MAX]; +static int play_track_flg[TRACK_MAX]; +static int play_kuri_num[8][TRACK_MAX]; +static int play_kuri_lv[TRACK_MAX]; +static int play_use_task[TRACK_MAX][8]; +static int dataToneNo[TRACK_MAX]; +static int tie_flg[TRACK_MAX]; +static int note_old[TRACK_MAX][8]; +static int play_use_task_cnt[TRACK_MAX]; +static int play_detune[TRACK_MAX]; +static int play_lfo_h[TRACK_MAX]; +static int play_lfo_m[TRACK_MAX]; +static int play_lfo_s[TRACK_MAX]; +static int pause_flg; +static LARGE_INTEGER tempo; +static int step[TRACK_MAX][16384]; +typedef enum { + M_OPEN_ERR = 0, + M_STEP_ERR, + M_TRACK_ERR, + M_LCOMMAND_ERR, + M_TCOMMAND_ERR, + M_VCOMMAND_ERR, + M_V2COMMAND_ERR, + M_P2COMMAND_ERR, + M_F2COMMAND_ERR, + M_2COMMAND_ERR, + M_KAKKO_ERR, + M_MML_ERR, + M_D2COMMAND_ERR, + M_NOTE_ERR, + M_PLAY_ERR, + M_KURI_ERR, + M_KURISU_ERR, + M_MUTE_ERR, + M_W2COMMAND_ERR, + M_TOCOMMAND_ERR, + M_QCOMMAND_ERR, + M_K2COMMAND_ERR, + M_WAON_ERR, + M_OCOMMAND_ERR, + M_H2COMMAND_ERR, + M_M2COMMAND_ERR, + M_S2COMMAND_ERR, +} err_number; + +static char *err_msg[]={ + "ʧ", + "ӣʱ", + "ָ", + "ָ", + "ָ", + "ָ", + "ָ", + "ָ", + "ָ", + "ָ", + "ãָ", + "̴ͣͣ", + "ָ", + "ܲ", + "ָ", + "ָ", + "", + "ָ", + "ָ", + "ָ", + "ָ", + "ָ", + "", + "ָ", + "ָ", + "ָ", + "ָ", +}; +//c c+ d d+ e f f+ g g+ a a+ b +//0 1 2 3 4 5 6 7 8 9 10 11 +static int note_change_tbl[]={9,11,0,2,4,5,7}; +static int freq_tbl[]={ + (int)(44100.0 / 261.63 * 277.18 / 32.0), //b (o-1) 0 ?t?? + 2756, //c (o0) 1 + (int)(44100.0 / 261.63 * 277.18 / 16.0), //c+ + (int)(44100.0 / 261.63 * 293.67 / 16.0), //d + (int)(44100.0 / 261.63 * 311.13 / 16.0), //d+ + (int)(44100.0 / 261.63 * 329.63 / 16.0), //e + (int)(44100.0 / 261.63 * 349.23 / 16.0), //f + (int)(44100.0 / 261.63 * 366.99 / 16.0), //f+ + (int)(44100.0 / 261.63 * 392.00 / 16.0), //g + (int)(44100.0 / 261.63 * 415.31 / 16.0), //g+ + (int)(44100.0 / 261.63 * 440.00 / 16.0), //a + (int)(44100.0 / 261.63 * 466.16 / 16.0), //a+ + (int)(44100.0 / 261.63 * 493.88 / 16.0), //b + 5512, //c (o1) 13 + (int)(44100.0 / 261.63 * 277.18 / 8.0), //c+ + (int)(44100.0 / 261.63 * 293.67 / 8.0), //d + (int)(44100.0 / 261.63 * 311.13 / 8.0), //d+ + (int)(44100.0 / 261.63 * 329.63 / 8.0), //e + (int)(44100.0 / 261.63 * 349.23 / 8.0), //f + (int)(44100.0 / 261.63 * 366.99 / 8.0), //f+ + (int)(44100.0 / 261.63 * 392.00 / 8.0), //g + (int)(44100.0 / 261.63 * 415.31 / 8.0), //g+ + (int)(44100.0 / 261.63 * 440.00 / 8.0), //a + (int)(44100.0 / 261.63 * 466.16 / 8.0), //a+ + (int)(44100.0 / 261.63 * 493.88 / 8.0), //b + 11025, //c (o2) 25 + (int)(44100.0 / 261.63 * 277.18 / 4.0), //c+ + (int)(44100.0 / 261.63 * 293.67 / 4.0), //d + (int)(44100.0 / 261.63 * 311.13 / 4.0), //d+ + (int)(44100.0 / 261.63 * 329.63 / 4.0), //e + (int)(44100.0 / 261.63 * 349.23 / 4.0), //f + (int)(44100.0 / 261.63 * 366.99 / 4.0), //f+ + (int)(44100.0 / 261.63 * 392.00 / 4.0), //g + (int)(44100.0 / 261.63 * 415.31 / 4.0), //g+ + (int)(44100.0 / 261.63 * 440.00 / 4.0), //a + (int)(44100.0 / 261.63 * 466.16 / 4.0), //a+ + (int)(44100.0 / 261.63 * 493.88 / 4.0), //b + 22050, //c (o3) 37 + (int)(44100.0 / 261.63 * 277.18 / 2.0), //c+ + (int)(44100.0 / 261.63 * 293.67 / 2.0), //d + (int)(44100.0 / 261.63 * 311.13 / 2.0), //d+ + (int)(44100.0 / 261.63 * 329.63 / 2.0), //e + (int)(44100.0 / 261.63 * 349.23 / 2.0), //f + (int)(44100.0 / 261.63 * 366.99 / 2.0), //f+ + (int)(44100.0 / 261.63 * 392.00 / 2.0), //g + (int)(44100.0 / 261.63 * 415.31 / 2.0), //g+ + (int)(44100.0 / 261.63 * 440.00 / 2.0), //a + (int)(44100.0 / 261.63 * 466.16 / 2.0), //a+ + (int)(44100.0 / 261.63 * 493.88 / 2.0), //b + 44100, //c (o4) 49 + (int)(44100.0 / 261.63 * 277.18), //c+ + (int)(44100.0 / 261.63 * 293.67), //d + (int)(44100.0 / 261.63 * 311.13), //d+ + (int)(44100.0 / 261.63 * 329.63), //e + (int)(44100.0 / 261.63 * 349.23), //f + (int)(44100.0 / 261.63 * 366.99), //f+ + (int)(44100.0 / 261.63 * 392.00), //g + (int)(44100.0 / 261.63 * 415.31), //g+ + (int)(44100.0 / 261.63 * 440.00), //a + (int)(44100.0 / 261.63 * 466.16), //a+ + (int)(44100.0 / 261.63 * 493.88), //b + 88200, //b+ (o5) 61 + (int)(44100.0 / 261.63 * 277.18 * 2.0), //c+ + (int)(44100.0 / 261.63 * 293.67 * 2.0), //d ???t??63 + (int)(44100.0 / 261.63 * 311.13 * 2.0), //d+ + (int)(44100.0 / 261.63 * 329.63 * 2.0), //e + (int)(44100.0 / 261.63 * 349.23 * 2.0), //f + (int)(44100.0 / 261.63 * 366.99 * 2.0), //f+ + (int)(44100.0 / 261.63 * 392.00 * 2.0), //g + (int)(44100.0 / 261.63 * 415.31 * 2.0), //g+ + (int)(44100.0 / 261.63 * 440.00 * 2.0), //a + (int)(44100.0 / 261.63 * 466.16 * 2.0), //a+ + (int)(44100.0 / 261.63 * 493.88 * 2.0), //b +}; +static long volume_tbl[128]; +static long panpot_tbl[128]; +static int detune_tbl[12*5+5]; + +int get_num(FILE *fp); +/*------------------------------------------- + ????????? +--------------------------------------------*/ +int f_get(FILE *fp) +{ + int d0; + while(1){ + d0 = fgetc( fp ); //????k??? + if( d0 == EOF ) + return d0; + if( d0 == '\t' ) //??? + continue; + if( d0 != 0x20 ) //????? + break; + } + if(d0 >= 'A' && d0 <= 'Z') //???? + d0+=0x20; // + return d0; +} + +/*------------------------------------------- + ?k????? +--------------------------------------------*/ +int get_num(FILE *fp) +{ + int d0,d1; + while(1){ + d0 = f_get( fp ); //????k??? + if( d0 == EOF ) + return d0; + if( d0 >= '0' && d0<= '9' ) //??? + break; //?????? + } + d1=d0-'0'; //????? + + while(1){ + d0 = fgetc( fp ); //????k??? + if( d0 == EOF ) + break; + if( d0 < '0' || d0> '9' ) //??? + break; //????????? + d1*=10; //??????? + d1+=d0-'0'; // + } + fseek(fp,-1,SEEK_CUR); //?????? + return d1; +} +/*------------------------------------------- + ?k?????????????? +--------------------------------------------*/ +int get_num2(FILE *fp) +{ + int d0,d1,d2=1; + d0 = f_get( fp ); //?????? + if(d0=='-') //?????? + d2=-1; + else + fseek(fp,-1,SEEK_CUR); //?????? + + while(1){ + d0 = fgetc( fp ); //????k??? + if( d0 == EOF ) + return d0; + if( d0 >= '0' && d0<= '9' ) //??? + break; //?????? + } + d1=d0-'0'; //????? + + while(1){ + d0 = fgetc( fp ); //????k??? + if( d0 == EOF ) + break; + if( d0 < '0' || d0> '9' ) //??? + break; //????????? + d1*=10; //??????? + d1+=d0-'0'; // + } + fseek(fp,-1,SEEK_CUR); //?????? + return d1*d2; +} +/*------------------------------------------- + ????????????????? +--------------------------------------------*/ +int num_check2(FILE *fp) +{ + int d0; + d0 = f_get( fp ); //?????? + if(d0=='-'){ //?????? + d0 = fgetc( fp ); //????????? + fseek(fp,-2,SEEK_CUR); //?????? + if( d0 >= '0' && d0<= '9' ) //??? + return 1; //?? + else + return 0; //??? + } else { + fseek(fp,-1,SEEK_CUR); //?????? + if( d0 >= '0' && d0<= '9' ) //??? + return 1; //?? + else + return 0; //??? + } +} + +/*------------------------------------------- + ???????? +--------------------------------------------*/ +int num_check(FILE *fp) +{ + int d0; + d0 = f_get( fp ); //?????? + fseek(fp,-1,SEEK_CUR); //?????? + if( d0 >= '0' && d0<= '9' ) //??? + return 1; //?? + else + return 0; //??? +} +/*------------------------------------------- + ???????????? +--------------------------------------------*/ +int get_step(FILE *fp,int ch) +{ + int d0,futen,total; + total = 0; + futen = 0; + while(1){ + d0 = f_get( fp ); //????? + if( d0 >= '0' && d0<= '9' ){ //???? + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if(d0 > 192) + return -1; + futen = 192 / d0; + total += futen; + } else if(d0 == '.'){ //ܤ?? + if(!total){ //????@e???? + total = step_def[ch]; //ܤ????? + futen = step_def[ch]; // + } + futen /= 2; + total += futen; + } else if(d0 == '^'){ //?????? + d0 = f_get( fp ); //????? + fseek(fp,-1,SEEK_CUR); //?????? + if(d0 == '*'){ //En??? + continue; + } + if(!num_check( fp )){ //??????? + return -1; //??? + } + d0 = get_num( fp ); + if(d0 > 192) + return -1; + if(!total){ //????@e???? + total = step_def[ch]; //ܤ????? + } + futen = 192 / d0; + total += futen; + } else if(d0 == '*'){ //En??? + if(!num_check( fp )){ //??????? + return -1; //??? + } + futen = get_num( fp ); + total += futen; + } else { + fseek(fp,-1,SEEK_CUR); //?????? + if(total) //????@e???? + break; + futen = step_def[ch]; + total = futen; + } + } + return total; +} +/*------------------------------------------- + ?????????? +--------------------------------------------*/ +int music_read( void ) +{ + int d0,d1,d7,ch,ch_p[TRACK_MAX],do_p[TRACK_MAX],ch_oct[TRACK_MAX],err_flg=-1,err_line=0; + int ch_ret[8][TRACK_MAX],ch_skip[8][TRACK_MAX],ch_kuri_lv[TRACK_MAX],waon_delay[TRACK_MAX]; + int o_tempo,q_com[TRACK_MAX]; + long d6; + char moji[256]; + FILE *fp; + fp = fopen( "oft.mml", "r" ); + if( fp == NULL ){ + sprintf( moji ,"%s" ,err_msg[0] ); +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, moji, "Error", MB_OK); +#endif + return err_flg; + } + + for(d7=0;d7= '0' && d0<= '9' ){ //??? + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if(d0 < 1 || d0 > TRACK_MAX){ + err_flg=M_PLAY_ERR; + goto music_read_999; + } + play_track_flg[ d0-1 ] = 1; //???????? + } + } + err_line--; //??Q?????????? + continue; + } + + if( d0 == 's' ){ //????????e? + while(1){ + if((d0 = fgetc( fp )) == EOF){ //?? + err_flg=M_MUTE_ERR; + goto music_read_999; + } + if( d0 == ')') //?? + break; + + if( d0 >= '0' && d0<= '9' ){ //??? + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if(d0 < 1 || d0 > TRACK_MAX){ + err_flg=M_MUTE_ERR; + goto music_read_999; + } + play_track_flg[ d0-1 ] = 0; //??????????? + } + } + err_line--; //??Q?????????? + continue; + } + + if( d0 == 'o' ){ //???e? + if(!num_check( fp )){ //??????? + err_flg=M_TOCOMMAND_ERR; + goto music_read_999; + } + o_tempo = get_num( fp ); //????? + if((d0 = fgetc( fp )) == EOF){ //?? + err_flg=M_TOCOMMAND_ERR; + goto music_read_999; + } + if(d0 != ')'){ + err_flg=M_TOCOMMAND_ERR; + goto music_read_999; + } + err_line--; //??Q?????????? + continue; + } + + if( d0 != 't' ){ //????? + err_flg=M_TRACK_ERR; + goto music_read_999; + } + if((d0 = f_get( fp )) == EOF) //????k??? + break; //?????Z? + if( d0 < '0' || d0> '9' ){ //????? + err_flg=M_TRACK_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + ch = get_num( fp ); + if((d0 = f_get( fp )) == EOF) //????k??? + break; //?????Z? + if( d0 != ')' ){ //????? + err_flg=M_TRACK_ERR; + goto music_read_999; + } + + if(ch < 1 || ch > TRACK_MAX){ + err_flg=M_TRACK_ERR; + goto music_read_999; + } + + ch--; //?????e + play_track_flg[ ch ] = 1; // + + if(o_tempo!=0 && ch_p[ch]==0){ //???e????? + step[ch][ch_p[ch]++] = MUSIC_TEMPO; //u??????????? +#if MODE98 + step[ch][ch_p[ch]++] = (int)((float)120 / (float)o_tempo * (float)12600)*2; +#else + step[ch][ch_p[ch]++] = (int)((float)120 / (float)o_tempo * (float)12600); +#endif + } + + //?????????? ???????@e ?????????? + +music_read_100: + if((d0 = f_get( fp )) == EOF) //?????? + break; //?????Z? + switch(d0){ + case '\n': //?? + break; + case '/': //????? + while(1){ //???????? + d0 = f_get( fp ); + if(d0 == '\n' || d0 == EOF ) + break; + } + break; + case '\'': //???? + int waon_step,waon_note[8+1],waon_cnt,octave,waon_delay_point; + waon_step = waon_cnt = 0; + octave = ch_oct[ch]; + + while(1){ + d0 = f_get( fp ); //????? + if( d0 >= '0' && d0<= '9' ){ //???????? + err_flg=M_WAON_ERR; //??? + goto music_read_999; + } + if(d0 =='<'){ //??????? + octave++; + continue; + } + if(d0 =='>'){ //???????? + octave--; + if(octave < 0){ //???????? + err_flg=M_NOTE_ERR; //??? + goto music_read_999; // + } + continue; + } + if(d0 =='\''){ //????? + break; + } + switch(d0){ + case 'c': //?? + case 'd': //?? + case 'e': //?? + case 'f': //?? + case 'g': //?? + case 'a': //?? + case 'b': //?? + d0-='a'; + d1 = note_change_tbl[d0]; + d0 = f_get( fp ); //????? + if(d0 == '+') + d1++; + else if(d0 == '-') + d1--; + else fseek(fp,-1,SEEK_CUR); //?????? + + d0 = octave * 12 + d1 +1; //???k??????? + if(d0 < 1 || d0 > 62){ // + err_flg=M_NOTE_ERR; //??? + goto music_read_999; // + } + waon_note[ waon_cnt++ ] = d0; //???k???? + + d0 = f_get( fp ); //????? + fseek(fp,-1,SEEK_CUR); //?????? + if( d0 < '0' || d0> '9' ){ //??????? + if( d0 != '*' ){ //??????????? + break; + } + } + waon_step = get_step( fp, ch ); //????????? + if(waon_step == -1){ //????? + err_flg=M_WAON_ERR; //??? + goto music_read_999; + } + break; + default: + err_flg=M_WAON_ERR; //??? + goto music_read_999; + } + } + if(waon_cnt > 8 || waon_cnt == 0){ //???????? + err_flg=M_WAON_ERR; //??? + goto music_read_999; + } + + if(num_check( fp )){ //???? + waon_step = get_num( fp ); //?????????? + } + step[ch][ch_p[ch]++] = MUSIC_WAON; //????? + step[ch][ch_p[ch]++] = waon_cnt; //?????? + waon_delay_point = ch_p[ch]; //??????????V + ch_p[ch]++; //??@e?? + + for(d7=0;d7= '0' && d0<= '9' ){ //??? + fseek(fp,-1,SEEK_CUR); //?????? + d0 = 192 / get_num( fp ); + if(d0 > 192 || d0 == 0){ + err_flg=M_LCOMMAND_ERR; + goto music_read_999; + } + step_def[ ch ] = d0; + goto music_read_100; + } + if( d0 != '*' ){ //En?? + err_flg=M_LCOMMAND_ERR; + goto music_read_999; + } + d0 = f_get( fp ); //???k? + if( d0 >= '0' && d0<= '9' ){ //??? + fseek(fp,-1,SEEK_CUR); //?????? + step_def[ ch ] = get_num( fp ); + goto music_read_100; + } + err_flg=M_LCOMMAND_ERR; + goto music_read_999; + case 'r': //?? + step[ch][ch_p[ch]++]=MUSIC_R; + d0 = get_step( fp, ch ); //????????? + if(d0 == -1){ //???? + err_flg=M_STEP_ERR; //?????? + goto music_read_999; + } + step[ch][ch_p[ch]++] = d0; //?????????? + d1 = f_get( fp ); //???? + if(d1 == '&'){ + step[ch][ch_p[ch]++] = -1; //????????? + } else { + fseek(fp,-1,SEEK_CUR); //?????? + step[ch][ch_p[ch]++] = d0 * q_com[ch] / 8; //????????? + } + goto music_read_100; + case 'o': //?????e? + if(!num_check( fp )){ //??????? + err_flg=M_OCOMMAND_ERR; //??? + goto music_read_999; + } + ch_oct[ch] = get_num( fp ); + if(ch_oct[ch]<0 || ch_oct[ch]>5){ //d???? + err_flg=M_OCOMMAND_ERR; //??? + goto music_read_999; + } + goto music_read_100; + case '<': //?????? + ch_oct[ch]++; + goto music_read_100; + case '>': //??????? + ch_oct[ch]--; + if(ch_oct[ch] < 0){ //???????? + err_flg=M_NOTE_ERR; //??? + goto music_read_999; // + } + goto music_read_100; + case 'q': //??????? + if(!num_check( fp )){ //??????? + err_flg=M_QCOMMAND_ERR; + goto music_read_999; + } + q_com[ch] = get_num( fp ); //????????? + if(q_com[ch] > 8 || q_com[ch] == 0){ //d???? + err_flg=M_QCOMMAND_ERR; + goto music_read_999; + } + goto music_read_100; + case 'c': //?? + case 'd': //?? + case 'e': //?? + case 'f': //?? + case 'g': //?? + case 'a': //?? + case 'b': //?? +// if(ch >= 6){ + d0-='a'; + d1 = note_change_tbl[d0]; + d0 = f_get( fp ); //????? + if(d0 == '+') + d1++; + else if(d0 == '-') + d1--; + else fseek(fp,-1,SEEK_CUR); //?????? + + if(ch_oct[ch] >= 5){ //???k?????? + if(d1 >= 2){ // + err_flg=M_NOTE_ERR; //?? + goto music_read_999; // + } + } +#if 0 + step[ch][ch_p[ch]++] = MUSIC_FREQ; + d1 = freq_tbl[d1+1]; + if(ch_oct[ch] > 0){ + d0 = ch_oct[ch]; + d0 = 1 << d0; + d1 *= d0; + } else if(ch_oct[ch] < 0){ + d0 = -ch_oct[ch]; + d0 = 1 << d0; + d1 /= d0; + } +#endif + d0 = ch_oct[ch] * 12 + d1 + 1; //???k??????? + if(d0 < 1 || d0 > 62){ // + err_flg=M_NOTE_ERR; //??? + goto music_read_999; // + } + step[ch][ch_p[ch]++] = d0; //???k???? +// } + d0 = get_step( fp, ch ); //????????? + if(d0 == -1){ //???? + err_flg=M_STEP_ERR; //?????? + goto music_read_999; + } + step[ch][ch_p[ch]++] = d0; //?????????? + d1 = f_get( fp ); //???? + if(d1 == '&'){ + step[ch][ch_p[ch]++] = -1; //????????? + } else { + fseek(fp,-1,SEEK_CUR); //?????? + step[ch][ch_p[ch]++] = d0 * q_com[ch] / 8; //????????? + } + goto music_read_100; + case 't': //??? + d0 = f_get( fp ); //????? + if( d0 < '0' || d0> '9' ){ //??? + err_flg=M_TCOMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + step[ch][ch_p[ch]++] = MUSIC_TEMPO; +#if MODE98 + step[ch][ch_p[ch]++] = (int)((float)120 / (float)d0 * (float)12600)*2; +#else + step[ch][ch_p[ch]++] = (int)((float)120 / (float)d0 * (float)12600); +#endif + goto music_read_100; + case 'v': //????? + d0 = f_get( fp ); //???? + if( d0 < '0' || d0> '9' ){ //??? + err_flg=M_VCOMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if(d0>15){ //??????? + err_flg=M_VCOMMAND_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++]=MUSIC_VOL; + if( d0 ){ + d0 = 15 - d0; +// d0 *= d0; +// d0 = (int)((float)d0 * 39.0625); +// step[ch][ch_p[ch]++] = -d0; + d6 = d0; + d6 = d6*d6*d6; + d6 = (long)(10000.0 / ( 16.0 * 16.0 * 16.0 ) * d6 ); + step[ch][ch_p[ch]++] = -d6; + } else { + step[ch][ch_p[ch]++] = -10000; + } + goto music_read_100; + case '@': //????? + d0 = f_get( fp ); //?????? + + if( d0 >= '0' && d0<= '9' ){ //??? + fseek(fp,-1,SEEK_CUR); //?????? + step[ch][ch_p[ch]++] = MUSIC_NEIRO_NO; //?k???? + step[ch][ch_p[ch]++] = get_num( fp ) - 1; + goto music_read_100; + } + + switch(d0){ + case 'v': //????? + d0 = f_get( fp ); //???? + if( d0 < '0' || d0> '9' ){ //??? + err_flg=M_V2COMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if(d0>127){ //??????? + err_flg=M_V2COMMAND_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++]=MUSIC_VOL; +#if 0 + if( d0 ){ + d0 = 127 - d0; +// d0 *= d0; +// d0 = (int)((float)d0 * 0.61); +// step[ch][ch_p[ch]++] = -d0; + d6 = d0; + d6 = d6*d6*d6; + d6 = (long)(10000.0 / ( 128.0 * 128.0 * 128.0 ) * d6 ); + step[ch][ch_p[ch]++] = -d6; + } else { + step[ch][ch_p[ch]++] = -10000; + } +#else +// d6=(long)(LOG(100,127)*10000) - (long)(LOG(100,(double)(d0))*10000); +// step[ch][ch_p[ch]++] = -d6; + + step[ch][ch_p[ch]++] = d0; + +#endif + goto music_read_100; + case 'h': //?? + if(!num_check( fp )){ //??????? + err_flg=M_H2COMMAND_ERR; + goto music_read_999; + } + d0 = get_num( fp ); + step[ch][ch_p[ch]++] = MUSIC_LFO_H; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'm': //?? + if(!num_check( fp )){ //??????? + err_flg=M_M2COMMAND_ERR; + goto music_read_999; + } + d0 = get_num( fp ); + if(d0 > 127){ //d???? + err_flg=M_M2COMMAND_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++] = MUSIC_LFO_M; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 's': //?? + if(!num_check2( fp )){ //??????? + err_flg=M_S2COMMAND_ERR; + goto music_read_999; + } + d0 = get_num2( fp ); + step[ch][ch_p[ch]++] = MUSIC_LFO_S; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'p': //????? + d0 = f_get( fp ); //?h??? + if( d0 < '0' || d0 > '9' ){ //??? + err_flg=M_P2COMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + if( d0 > 127 ){ //d?????? + err_flg=M_P2COMMAND_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++]=MUSIC_PAN; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'f': //? + if(!num_check2( fp )){ //??????? + err_flg=M_F2COMMAND_ERR; + goto music_read_999; + } + d0 = get_num2( fp ); + step[ch][ch_p[ch]++] = MUSIC_FREQ; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'k': //???? + if(!num_check2( fp )){ //??????? + err_flg=M_K2COMMAND_ERR; + goto music_read_999; + } + d0 = get_num2( fp ); + if(d0 > 64 || d0 < -64){ //d???? + err_flg=M_K2COMMAND_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++] = MUSIC_DETUNE; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'd': //??????? + d0 = f_get( fp ); //??????? + if( d0 < '0' || d0> '9' ){ //??? + err_flg=M_D2COMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + step[ch][ch_p[ch]++] = MUSIC_PEDAL; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + case 'w': //??????? + d0 = f_get( fp ); //??????? + if( d0 < '0' || d0> '9' ){ //??? + err_flg=M_W2COMMAND_ERR; + goto music_read_999; + } + fseek(fp,-1,SEEK_CUR); //?????? + d0 = get_num( fp ); + step[ch][ch_p[ch]++] = MUSIC_WAVE; + step[ch][ch_p[ch]++] = d0; + goto music_read_100; + default: + err_flg=M_2COMMAND_ERR; + goto music_read_999; + } + case '[': //??????? + d0 = f_get( fp ); //?????? + switch(d0){ + case 'l': + d0 = f_get( fp ); //?????? + if(d0 != 'o'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + d0 = f_get( fp ); //?????? + if(d0 != 'o'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + d0 = f_get( fp ); //?????? + if(d0 != 'p'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + d0 = f_get( fp ); //?????? + if(d0 != ']'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++]=MUSIC_LOOP; + step[ch][ch_p[ch]++]=do_p[ch]; + goto music_read_100; + case 'd': //????t + d0 = f_get( fp ); //?????? + if(d0 != 'o'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + d0 = f_get( fp ); //?????? + if(d0 != ']'){ + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + do_p[ch]=ch_p[ch]; //??I??? + goto music_read_100; + default: + err_flg=M_KAKKO_ERR; + goto music_read_999; + } + case '|': //??????? + d0 = f_get( fp ); //?????? + if(d0 == ':'){ //????? + ch_kuri_lv[ch]++; //??????? + if(ch_kuri_lv[ch] == 8){ //??????? + err_flg=M_KURI_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++] = MUSIC_KURI_START; + if(num_check( fp )){ //??? + step[ch][ch_p[ch]++] = get_num( fp ); + } else { + step[ch][ch_p[ch]++] = 2; + } + ch_ret[ch_kuri_lv[ch]][ ch ] = ch_p[ch]; + } else { + fseek(fp,-1,SEEK_CUR); //?????? + step[ch][ch_p[ch]++]=MUSIC_KURI_SKIP; + ch_skip[ch_kuri_lv[ch]][ ch ] = ch_p[ch]; + ch_p[ch]++; + } + goto music_read_100; + + case ':': //???????? + d0 = f_get( fp ); //?????? + if(d0 != '|'){ //????? + err_flg=M_KURI_ERR; + goto music_read_999; + } + step[ch][ch_p[ch]++] = MUSIC_KURI_RET; + step[ch][ch_p[ch]++] = ch_ret[ch_kuri_lv[ch]][ ch ]; //?? + if(ch_skip[ch_kuri_lv[ch]][ ch ] >= 0){ + step[ch][ch_skip[ch_kuri_lv[ch]][ ch ]] = ch_p[ch]; //D? + ch_skip[ch_kuri_lv[ch]][ ch ] = -1; + } + ch_kuri_lv[ch]--; //??????? + goto music_read_100; + + default: //?????? + err_flg=M_MML_ERR; + goto music_read_999; + } + } + for(d7=0;d7=0;d6--){ + if(!((int)d6&1)) + continue; + y=(int)(LOG(100,127)*PAN_POINT) - (int)(LOG(100,d6)*PAN_POINT); + if(y>PAN_POINT) + y=10000; + panpot_tbl[d7++]=y; + } + for(d7=64,d6=127;d6>=0;d6--){ + if(!((int)d6&1)) + continue; + y=(int)(LOG(100,127)*PAN_POINT) - (int)(LOG(100,d6)*PAN_POINT); + if(y>PAN_POINT) + y=10000; + panpot_tbl[d7--]=-y; + } + d6=panpot_tbl[0]=-10000; + d6=panpot_tbl[127]=10000; + //?????????? + for(d6=127;d6>=0;d6--){ + y=(int)(LOG(100,127)*10000) - (int)(LOG(100,d6)*10000); + if(y>10000) + y=10000; + volume_tbl[(int)d6]=-y; + } + //?????????? + for(d7=0;d7<12*5+5;d7++) + detune_tbl[d7]=freq_tbl[d7+1]-freq_tbl[d7]; + +// play_bgm( 2); + +} + +/*------------------------------------------- + ??e?? +--------------------------------------------*/ +void play_stop( void ) +{ + int d7; + for(d7=0;d7Stop(); + pDSData[d7]->SetCurrentPosition(0); +// play_flg[ d7 ] = 0; + } + pause_flg=1; +} +void stop_voice(int ch); +/*------------------------------------------- + ???? +--------------------------------------------*/ +void play_start( void ) +{ + int d7; + for(d7=0;d7Stop(); + pDSData[d7]->SetCurrentPosition(0); + } + music_init(); //???????? +} + +//?????????? ????? ?????????? +void voice_lfo( int a0 ) +{ + long d0; + if(!voice[ a0 ].lfo_m){ //?????? + return; + } + if(!voice[ a0 ].lfo_s){ //?????? + return; + } + if(voice[ a0 ].lfo_h){ //????????? + voice[ a0 ].lfo_h--; + return; + } + + voice[ a0 ].lfo_s_cnt += voice[ a0 ].lfo_s_ang; //??????? + +// if(voice[ a0 ].lfo_s_ang >= 0){ //??????? + if(voice[ a0 ].lfo_s_cnt >= 0){ //??????? + d0 = detune_tbl[ voice[ a0 ].note_no ] * voice[ a0 ].lfo_m / 128 * voice[ a0 ].lfo_s_cnt / abs(voice[ a0 ].lfo_s); + } else { + d0 = detune_tbl[ voice[ a0 ].note_no-1 ] * voice[ a0 ].lfo_m / 128 * voice[ a0 ].lfo_s_cnt / abs(voice[ a0 ].lfo_s); + } + pDSData[ a0 ]->SetFrequency((DWORD)(voice[ a0 ].freq + d0)); // ???? + + if(abs(voice[ a0 ].lfo_s_cnt) == abs(voice[ a0 ].lfo_s)){ //???? + voice[ a0 ].lfo_s_ang *= -1; + } +} + +//?????????? ?????? ?????????? +#define VOICE_KEY_ON 1 +#define VOICE_NORMAL 2 +#define VOICE_TIE_SET 10 +#define VOICE_KEY_OFF 100 +#define VOICE_KEY_OFF_FAST 110 +#define VOICE_KEY_OFF_WAIT 200 + +void voice_action( int a0 ) +{ + DWORD Status = 0; + + switch(voice[ a0 ].name){ + case VOICE_KEY_ON: //G???? + if(voice[ a0 ].delay_cnt){ //????????? + voice[ a0 ].delay_cnt--; + return; + } + pDSData[ a0 ]->SetVolume(volume_tbl[ voice[ a0 ].volume ]); // ???????? + pDSData[ a0 ]->SetFrequency((DWORD)voice[ a0 ].freq); // ???? + pDSData[ a0 ]->SetPan(panpot_tbl[ voice[ a0 ].pan ]); // ???????? + pDSData[ a0 ]->Play(0, 0, voice[ a0 ].loop_flg); //???? + voice[ a0 ].name = VOICE_NORMAL; + voice_lfo( a0 ); //?????? + break; + case VOICE_NORMAL: //G????? + voice_lfo( a0 ); //?????? + break; + case VOICE_TIE_SET: //??????? + pDSData[ a0 ]->SetVolume(volume_tbl[ voice[ a0 ].volume ]); // ???????? + pDSData[ a0 ]->SetFrequency((DWORD)voice[ a0 ].freq); // ???? + pDSData[ a0 ]->SetPan(panpot_tbl[ voice[ a0 ].pan ]); // ???????? + voice[ a0 ].name = VOICE_NORMAL; + break; + case VOICE_KEY_OFF: //G???? +// if( pDSData[ a0 ]->GetStatus( &Status ) == DS_OK ){ +/// pDSData[ a0 ]->GetStatus( &Status ); //?????????? +/// if( Status & DSBSTATUS_PLAYING || Status & DSBSTATUS_LOOPING ){ //???? + if(voice[ a0 ].volume){ //?????????? + voice[ a0 ].release_cnt++; //?????????? + if(voice[ a0 ].release_spd != voice[ a0 ].release_cnt){ + voice_lfo( a0 ); //?????? + break; //???????I?? + } + voice[ a0 ].release_cnt = 0; //??????? + voice[ a0 ].volume--; //???????? +// if(voice[ a0 ].volume < 0){ //?????????? +// voice[ a0 ].volume=0; //????????? +// } + pDSData[ a0 ]->SetVolume(volume_tbl[ voice[ a0 ].volume ]); // ?????? + voice_lfo( a0 ); //?????? + break; //????I?? + } +/// } + pDSData[ a0 ]->Stop(); //???? + pDSData[ a0 ]->SetCurrentPosition(0); // + voice[ a0 ].name = VOICE_KEY_OFF_WAIT; //?????r? +// play_use_task[ voice[ a0 ].track_no ] = -1; // + break; +#if !VOICE_KILL_ON + case VOICE_KEY_OFF_FAST: //L????? + pDSData[ a0 ]->Stop(); //???? + pDSData[ a0 ]->SetCurrentPosition(0); // + voice[ a0 ].name = 0; // + break; +#endif + } +} +//?????????? ??????????? ?????????? +void set_voice_param( int task_no, long note, int delay, int lfo_flg) +{ + voice[ task_no ].volume = dataVolume[ch]; // ???????? +// voice[ task_no ].freq = freq + dataFrequency[ch]; // ???? + // ???? + if(play_detune[ch]>0){ //??????????? + voice[ task_no ].freq = freq_tbl[ note ] + detune_tbl[ note ]*play_detune[ch]/64 + dataFrequency[ch]; + } else if(play_detune[ch]<0){ //???????????? + voice[ task_no ].freq = freq_tbl[ note ] + detune_tbl[ note-1 ]*play_detune[ch]/64 + dataFrequency[ch]; + } else { //?????e????? + voice[ task_no ].freq = freq_tbl[ note ] + dataFrequency[ch]; + } + voice[ task_no ].note_no = note; // ???k???? + voice[ task_no ].pan = dataPan[ch]; // ???????? + voice[ task_no ].release_spd = wave[ch]; // ????????? + voice[ task_no ].release_cnt = 0; // + if(voice[ task_no ].tone_no == 12-1){ //?????? + voice[ task_no ].loop_flg = DSBPLAY_LOOPING; // + } else { + voice[ task_no ].loop_flg = 0; // + } + if(delay >= 0){ //????????????? + voice[ task_no ].delay_cnt = delay; // + } + if(lfo_flg){ //?????????? + voice[ task_no ].lfo_h = play_lfo_h[ ch ]; //?????? + voice[ task_no ].lfo_m = play_lfo_m[ ch ]; // + if((voice[ task_no ].lfo_s = play_lfo_s[ ch ]) >= 0){ // + voice[ task_no ].lfo_s_ang = 1; // + } else { + voice[ task_no ].lfo_s_ang = -1; // + } + voice[ task_no ].lfo_s_cnt = 0; // + } +} + +//?????????? ??????? ?????????? +static int voice_seek_point=0; +int set_tone( int tone, long note, int use_task_cnt, int delay) +{ + int d7,d1=0; + + for(d7=0;d7DuplicateSoundBuffer(pDSData_tone[tone],&pDSData[d7]) != DS_OK ){ //???? +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + play_use_task[ch][use_task_cnt]=-1; //?????? + return -1; + } + +set_tone_500: + set_voice_param( d7, note, delay, 1 ); //??????????? + + return 0; +} + +//?????????? L????? ?????????? +void stop_voice(void) +{ + for(int cnt=0;cnt0){ // + return; //???????I?? + } else { + if(!tie_flg[ch]){ //??????? + if( !d_pedal[ch] ){ //???????? + if( !wave[ch] ){ //??????? + stop_voice(); //??????? + } else { + for(int cnt=0;cnt= 0){ //???k??? + if(play_use_task_cnt[ch]!=1 && tie_flg[ch]==1){ //?????????? + tie_flg[ch]=0; //??? + } + if(!tie_flg[ch]){ //??????? + stop_voice(); //??????_ + set_tone( dataToneNo[ch], next_command, 0, 0); //O????? + note_old[ch][0] = next_command; //??????k?V + } else { + for(int cnt=0;cnt 0){ + step_point[ch] = step[ch][step_point[ch]]; + } else { + step_point[ch]++; + play_kuri_lv[ch]--; //??????? + } + goto gate_100; + } + if(next_command==MUSIC_R){ //?? + if(tie_flg[ch]){ //???? + for(int cnt=0;cntSetVolume(dataVolume[ch]); + goto gate_100; + } + if(next_command==MUSIC_DETUNE){ //?????? + play_detune[ch] = step[ch][step_point[ch]++]; + goto gate_100; + } + if(next_command==MUSIC_FREQ){ //?? + dataFrequency[ch]=step[ch][step_point[ch]++]; +// pDSData[play_use_task[ch]]->SetFrequency((DWORD)dataFrequency[ch]); + goto gate_100; + } + if(next_command==MUSIC_PAN){ //?????? + dataPan[ch]=step[ch][step_point[ch]++]; +// pDSData[play_use_task[ch]]->SetPan(dataPan[ch]); + goto gate_100; + } + if(next_command==MUSIC_END){ //?? + play_flg[ ch ] = 0; + return; + } + } +} + +//void CALLBACK music( HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime ) +void music( void ) +{ + int d7; +#if 1 +#if THREAD_ON + while(!thread_flg){ +#if CLASS_UP + //Sleep(1); //?? +#endif +#endif + LARGE_INTEGER d0; + QueryPerformanceCounter( &d0 ); + if((d_cnt.LowPart + tempo.LowPart) > d0.LowPart) +#if THREAD_ON + { + continue; + } +#else + return; +#endif +#if !DEBUG_ON + if(abs(d0.LowPart - d_cnt.LowPart) > 3333333) +#if THREAD_ON + continue; +#else + return; +#endif +#endif + d_cnt.LowPart += tempo.LowPart; +#endif + if(!pause_flg){ +#if VOICE_KILL_ON + for( d7 = 0 ; d7 < voice_kill_point ; d7++ ){ + voice[ voice_kill_buf[ d7 ] ].name = 0; //?????? + pDSData[ voice_kill_buf[ d7 ] ]->Stop(); //???? + pDSData[ voice_kill_buf[ d7 ] ]->SetCurrentPosition(0); // + } + voice_kill_point=0; +#endif + for( d7 = 0 ; d7 < VOICE_MAX ; d7++ ){ + if(voice[ d7 ].name){ + voice_action( d7 ); + } + } + for( ch = 0 ; ch < TRACK_MAX ; ch++ ){ + if(play_track_flg[ ch ]) + gate(); + } + } else { + +#if CLASS_UP + //Sleep(8); //???? +#endif + QueryPerformanceCounter( &d_cnt ); + } + +#if 0 //-------------- + +#if CLASS_UP +#if MODE98 + if( tempo.LowPart > 10080*2 ) //??????t??? +#else + if( tempo.LowPart > 10080 ) //??????t??? +#endif + Sleep(2); //?? + else + Sleep(1); //?? +#endif + +#endif //-------------- + +#if THREAD_ON + } + thread_flg=2; + ExitThread( TRUE ); +#endif + d7=0; + return; +} + +/*-------------------------------------------- + ?????????? +---------------------------------------------*/ +int t_music_init() +{ + if( GetAsyncKeyState( 0x10 ) & 0x8000 ){ //????????????? + dsound_flg = -1; + return FALSE; + } + if(!InitDSound()){ + dsound_flg = -1; + return FALSE; + } + music_init(); //???????? + +/* +//cary ȡ + if(!music_read()){ + play_start(); + } else { + play_stop(); + dsound_flg = -1; + return FALSE; + } + QueryPerformanceCounter(&d_cnt); +#if THREAD_ON + static DWORD dwChildThreadId = 0; + HANDLE hChildThred = CreateThread( NULL, + 16384, + (LPTHREAD_START_ROUTINE)music, +// (LPVOID)hWnd, + NULL, + NULL, + &dwChildThreadId ); +#if CLASS_UP + SetThreadPriority(hChildThred,THREAD_PRIORITY_HIGHEST); +#endif +#endif +*/ + return TRUE; +} + +/*-------------------------------------------- + ???????? +---------------------------------------------*/ +void t_music_end() +{ + //????????? + if(dsound_flg == -1) + return; +#if THREAD_ON +// thread_flg=1; +// while(thread_flg!=2); +#endif + EndApp(); +} + + +#if 0 +//?????????? ???? ?????????? +//static voice_seek_point=0; +int play_se(int tone, int x, int y) +{ + int distance; + //????????? + if(dsound_flg == -1){ + return -1; + } + + if(tone > TONE_MAX){ //??????? + return -1; + } + + if(tone_tbl[ tone ].voice_place == -1){ //te???? + return -1; + } + + if(tone_tbl[ tone ].play_time){ //?????? + return 0; + } + + if(voice[ voice_seek_point ].tone_no != tone){ //i??k?????? + voice[ voice_seek_point ].tone_no = tone; //?k?V + RELEASE(pDSData[voice_seek_point]); //? + //???? + if( pDSound->DuplicateSoundBuffer(pDSData_tone[tone_tbl[ tone ].voice_place],&pDSData[voice_seek_point]) != DS_OK ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + return -1; + } + } + + if(stereo_flg == T_MUSIC_MONO){ //?????? + distance = 127 * tone_tbl[ tone ].voice_volume / 10; + x = 64; + } else { //?????? + distance = abs(y - 240); //????????? + y = abs(x - 320); //????????? + if(distance < y) //???? + distance = y; // + + distance = distance << 4; //?????k?? + distance /= 0x5a; // + + if(distance >= 127) //d???? + return 0; //???? + + x /= 5; //?????k?? + if(x < 0) // + x = 0; // + if(x > 127) // + x = 127; // + + distance = (127 - distance) * tone_tbl[ tone ].voice_volume / 10; //??????? + } + + pDSData[ voice_seek_point ]->SetVolume(volume_tbl[ distance ]); // ???????? + pDSData[ voice_seek_point ]->SetPan(panpot_tbl[ x ]); // ???????? + pDSData[ voice_seek_point ]->Play(0, 0, 0); //???? + + voice_seek_point = voice_seek_point++; //?????? + voice_seek_point&=VOICE_MAX-1; // + tone_tbl[ tone ].play_time = 8; //??????? + + return 0; +} + +#else + +//??????????????? ? ??????????????? +HANDLE hEvent[3]; // ????????? +HANDLE hThreadHandle; // ????????????? +DWORD dwThreadID; // ??????????? +/*------------------------------------------- + ???????????????????? +--------------------------------------------*/ +// ???????????J??Bl?? +struct SoundData { + LPDIRECTSOUNDBUFFER pDSBuffer; // ???????????????? + HANDLE *phEvent; // ??????Gl?t??????????????????????? + DWORD dwEventNum; // ?????? + DWORD dwStopEventNum; // ?ؤ_?????????????????? + LPBYTE lpWaveData; // ??????????? + DWORD dwWaveSize; // ??????????????? + DWORD dwBlock_size; // ????????????????? +} sd; + +// ????????? +void Block_Copy(LPDIRECTSOUNDBUFFER lpBuffer, + DWORD blockadd, DWORD blocksize, + LPBYTE lpWave, LONG &waveAdd, LONG waveSize) +{ + LPBYTE lpBlockAdd1, lpBlockAdd2; + DWORD blockSize1, blockSize2; + LONG ws = waveSize - waveAdd; + + // ???????? + HRESULT hr = lpBuffer->Lock(blockadd, blocksize, (LPVOID*)&lpBlockAdd1, &blockSize1, (LPVOID*)&lpBlockAdd2, &blockSize2, 0); + if(hr == DS_OK) + { + if(ws < (long)blockSize1) + { + CopyMemory(lpBlockAdd1, lpWave + waveAdd, ws); + waveAdd = blockSize1 - ws; + CopyMemory(lpBlockAdd1 + ws, lpWave + thread_loop_start, waveAdd); + waveAdd += thread_loop_start; + } + else + { + CopyMemory(lpBlockAdd1, lpWave + waveAdd, blockSize1); + waveAdd += blockSize1; + } + if(lpBlockAdd2) + { + ws = waveSize - waveAdd; + if(ws < (long)blockSize2) + { + CopyMemory(lpBlockAdd1, lpWave + waveAdd, ws); + waveAdd = blockSize2 - ws; + CopyMemory(lpBlockAdd1 + ws, lpWave + thread_loop_start, waveAdd); + waveAdd += thread_loop_start; + } + else + { + CopyMemory(lpBlockAdd2, lpWave + waveAdd, blockSize2); + waveAdd += blockSize2; + } + } + lpBuffer->Unlock(lpBlockAdd1, blockSize1, lpBlockAdd2, blockSize2); + } +} + +static LONG wave_count = 0; +static LONG wave_address = 0; +static LONG buffer_address = 0; +volatile static int thread_start_flg = 0; + +// ?????????? +DWORD WINAPI MyThreadFunc(LPVOID param) +{ + LONG waveAdd = 0; + // ?????????????????????? + Block_Copy(sd.pDSBuffer, 0, sd.dwBlock_size, sd.lpWaveData, waveAdd, sd.dwWaveSize); + thread_start_flg = 1; + while(TRUE) + { + DWORD i = WaitForMultipleObjects(sd.dwEventNum, sd.phEvent, FALSE, INFINITE); + wave_count++; + switch(i) + { + case WAIT_OBJECT_0 + 1: + // ?k??????????? + buffer_address = 0; wave_address = waveAdd; + Block_Copy(sd.pDSBuffer, 0, sd.dwBlock_size, sd.lpWaveData, waveAdd, sd.dwWaveSize); + break; + case WAIT_OBJECT_0: + // ?k??????????? + buffer_address = sd.dwBlock_size; wave_address = waveAdd; + Block_Copy(sd.pDSBuffer, sd.dwBlock_size, sd.dwBlock_size, sd.lpWaveData, waveAdd, sd.dwWaveSize); + break; + case WAIT_OBJECT_0 + 2: + // ????????????? + exit_thread_flg = 1; + ExitThread(TRUE); + default: + // ????????????? + exit_thread_flg = 1; + ExitThread(TRUE); + } +// InvalidateRect(hwndApp, NULL, TRUE); + } + return 0L; +} + +// +// ??????????x +// +// ? ? pWfmtx ... ??????????? +// DataSize ... ???????? +// ppData ... x???????????????? +// ??k TRUE ... ? +// FALSE ... +static BOOL dwSoundInit2( WAVEFORMATEX *pWfmtx, DWORD DataSize, LPDIRECTSOUNDBUFFER *ppData, HMMIO hmmio ) +{ + // ????????????????????? + WAVEFORMATEX pcmwf = *pWfmtx; + DSBUFFERDESC dsbufferdesc; + HRESULT ret; + + //????? + if(stream_flg == 1){ + RELEASE(pDSNotify); + stream_flg = 0; + } + //?????????????? + memset( &dsbufferdesc , 0 , sizeof( DSBUFFERDESC ) ); + dsbufferdesc.dwSize = sizeof( DSBUFFERDESC ); + dsbufferdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2; +// dsbufferdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_STATIC | DSBCAPS_CTRLDEFAULT | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; + dsbufferdesc.dwBufferBytes = DataSize; + dsbufferdesc.lpwfxFormat = pWfmtx; + if ( pDSound->CreateSoundBuffer( &dsbufferdesc , ppData , NULL ) != DS_OK ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + + + //?????????? + if( WaveDataRead( hmmio, &DataSize, pDSData_stream ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡWAVʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + + // ????????????????????? +// WAVEFORMATEX pcmwf = *pWaveHeader; + DSBUFFERDESC dsbdesc; + // DSBUFFERDESC?Bl?@e + ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); + dsbdesc.dwSize = sizeof(DSBUFFERDESC); +#if ACTIVE + dsbdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; +#else + dsbdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | /*DSBCAPS_CTRLDEFAULT*/DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2; +#endif + // ?@e??Wave?????????????????? + dsbdesc.dwBufferBytes = 2 * pcmwf.nAvgBytesPerSec; + dsbdesc.lpwfxFormat = &pcmwf; + ret = pDSound->CreateSoundBuffer(&dsbdesc, &pDSData_tone[ TONE_MAX ], NULL); + if(ret != DS_OK) { + // ??????? +// RELEASE(pDSound); + RELEASE(pDSData_stream); +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + + // DirectSoundNotify?????????? + ret = pDSData_tone[ TONE_MAX ]->QueryInterface(IID_IDirectSoundNotify, (LPVOID*)&pDSNotify); + if(ret != DS_OK) + { +// RELEASE(pDSound); + RELEASE(pDSData_stream); + RELEASE(pDSData_tone[ TONE_MAX ]); +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "DirectSoundNotifyʧܣ", "Error", MB_OK); +#endif + return FALSE; + // ?? + } + + // ????????????? + hEvent[0] = CreateEvent(NULL, FALSE, FALSE, NULL); + hEvent[1] = CreateEvent(NULL, FALSE, FALSE, NULL); + hEvent[2] = CreateEvent(NULL, FALSE, FALSE, NULL); + + // DirectSoundNotify???????@e?? + // ?Bl???? + DSBPOSITIONNOTIFY pn[3]; + pn[0].dwOffset = 0; // ?? + pn[0].hEventNotify = hEvent[0]; + pn[1].dwOffset = 1 * pcmwf.nAvgBytesPerSec; // ?? + pn[1].hEventNotify = hEvent[1]; + pn[2].dwOffset = DSBPN_OFFSETSTOP; // ?ؤ_ + pn[2].hEventNotify = hEvent[2]; // ??????????????_?????????? + + // _?t@e + HRESULT hr; + hr = pDSNotify->SetNotificationPositions(3, pn); + if(hr != DS_OK) + { + // @e + RELEASE(pDSNotify); +// RELEASE(pDSound); + RELEASE(pDSData_stream); + RELEASE(pDSData_tone[ TONE_MAX ]); +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "趨DirectSoundNotifyʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + + stream_flg = 1; //??????? + + // ?????????????? + thread_start_flg = 0; + + // ????????? + sd.pDSBuffer = pDSData_tone[ TONE_MAX ]; // ??????????DirectSoundBuffer?????? + sd.phEvent = hEvent; // 4.4.??????????????? + sd.dwEventNum = 3; // ???????????? + sd.dwStopEventNum = 2; // ??????????????_????? + sd.lpWaveData = pDSbuffData; // ???Wave?????????@e? + sd.dwWaveSize = DataSize; // ???Wave???????@e? + sd.dwBlock_size = pcmwf.nAvgBytesPerSec; // 44.1kHz??????????? + + // ?????????? + hThreadHandle = CreateThread(NULL, 0, MyThreadFunc, &sd, 0, &dwThreadID); + if(hThreadHandle == NULL) + { +#ifdef _STONDEBUG_ + // ?????? +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "Threadʧܣ", "Error", MB_OK); +#endif +#endif + return FALSE; + } + + // ??????????r? + while(1){ + if(thread_start_flg) + break; + } + +// SetThreadPriority(hThreadHandle,THREAD_PRIORITY_HIGHEST); +// SetThreadPriority(hThreadHandle,THREAD_PRIORITY_ABOVE_NORMAL); +// pDSData_tone[ TONE_MAX ]->Play(0, 0, DSBPLAY_LOOPING); + return TRUE; +} +//??????????????? ? ??????????????? + +int t_music_bgm_no = -1; +char t_music_bgm_pitch[16]={ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + +//aaa +//?????????? ???? ?????????? +#define BGM_AUTO_LOOP 1 +T_MUSIC_BGM bgm_tbl[] = { + {"data\\bgm\\sabgm_s0.wav", 110,0,0}, //00 ???? + {"data\\bgm\\sabgm_s1.wav", 120,0,0}, //01 ???? + {"data\\bgm\\sabgm_s1.wav", 105,2,0}, //02 ???k?N?? + {"data\\bgm\\sabgm_t1.wav", 127,2,0}, //03 ?????N?? + {"data\\bgm\\sabgm_t0.wav", 95,2,0}, //04 ??N?? + + {"data\\bgm\\sabgm_b0.wav", 122,1,0}, //05 ???Pf??Id? + {"data\\bgm\\sabgm_b1.wav", 122,2,0}, //06 ???Pf??N?? + + {"data\\bgm\\sabgm_d0.wav", 120,1,0}, //07 ???n??Id? + {"data\\bgm\\sabgm_d1.wav", 105,1,0}, //08 [?n???Id? + {"data\\bgm\\sabgm_d2.wav", 100,2,0}, //09 [?n???N?? + + {"data\\bgm\\sabgm_f0.wav", 127,2,0}, //10 ?????N?? + {"data\\bgm\\sabgm_f1.wav", 100,2,0}, //11 ?????N?? + + {"data\\bgm\\sabgm_b3.wav", 110,2,0}, //12 µһս + {"data\\bgm\\sabgm_b2.wav", 110,2,0}, //13 µbossս + {"data\\bgm\\sabgm_b4.wav", 110,2,0}, //14 µbossս + + {"data\\bgm\\sabgm_f2.wav", 110,2,0}, //15 ½ + + {"data\\bgm\\sabgm_t2.wav", 110,2,0}, //16 ԰ + {"data\\bgm\\sabgm_t3.wav", 110,2,0}, //17 س + {"data\\bgm\\sabgm_t4.wav", 110,2,0}, //18 ˮ + {"data\\bgm\\sabgm_t5.wav", 110,2,0}, //19 + {"data\\bgm\\sabgm_t6.wav", 110,2,0}, //20 + {"data\\bgm\\sabgm_t7.wav", 110,2,0}, //21 + +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + {"data\\bgm\\sabgm_t8.wav", 110,2,0}, //22 ׶ + {"data\\bgm\\sabgm_t9.wav", 110,2,0}, //23 ƽԭ + {"data\\bgm\\sabgm_t10.wav", 110,2,0}, //24 ս +#endif + {"data\\bgm\\sabgm_t11.wav", 110,2,0}, //25 + {"data\\bgm\\sabgm_t12.wav", 110,2,0}, //26 +#ifdef _NEW_MUISC_ + {"data\\bgm\\sabgm_s2.wav", 110,2,0}, //26 +#endif +}; + +int play_bgm(int bgm_no) +{ + if (MuteFlag) return -1; + + + + HMMIO hmmio; //???????? + WAVEFORMATEX Wfmtx; //WAVE?????????????? + DWORD DataSize; //????????? + DWORD WaveSize; //Wave???????? + +// bgm_no = 0; + //cary 2001 7 17 + if( bgm_no < 0) + bgm_no = 0; + + //?????????? + t_music_fade_flg = 0; + + if(dsound_flg == -1) + return -1; + + //??????????? + if(t_music_bgm_no != -1){ + //????_? + stop_thread(); + } + + //???????????? +// if( (hmmio = mmioOpen(fname[bgm_no], NULL, MMIO_READ | MMIO_ALLOCBUF )) == NULL){ + if( (hmmio = mmioOpen(bgm_tbl[bgm_no].fname, NULL, MMIO_READ | MMIO_ALLOCBUF )) == NULL){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "WAVʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + //??????????? + if( WaveFormatRead( hmmio , &Wfmtx , &WaveSize ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡʽʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + DataSize = WaveSize; + //?????????????? + if(bgm_tbl[bgm_no].loop_flg == 2){ //N?????? + thread_stop_flg = 1; //????? + //???ѩ??? +#if BGM_AUTO_LOOP + FILE *fp; + int d0,d1,d2; + fp = fopen( bgm_tbl[bgm_no].fname, "rb" ); + if( fp == NULL ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + d2 = 8; //?????????????? + d2 += 4; //?????????????? + d2 += 4; //???? ????????? + d2 += 16; //????????? + fseek(fp,d2,SEEK_CUR); //??????????h + d0 = fgetc(fp); //???????????? + d0 |= fgetc(fp) << 8; // + d2 = 2; //???????? + d2 += 12+DataSize; //?????????? ? ?????????? + if(DataSize&1){ //???????? + d2++; //????? + } + d2 += 12*4; //?????????? + fseek(fp,d2,SEEK_CUR); //??????????h + + //?????t + d1 = fgetc(fp); //?????????? + d1 |= fgetc(fp) << 8; // + d1 |= fgetc(fp) << 16; // + d1 |= fgetc(fp) << 24; // + if( d1 < 0) + thread_loop_start = 0; + else + thread_loop_start = d1 * d0; //????t??? + //?????t + d1 = fgetc(fp); + d1 |= fgetc(fp) << 8; + d1 |= fgetc(fp) << 16; + d1 |= fgetc(fp) << 24; +// thread_loop_end = d1 * d0; + + fclose(fp); +#else + thread_loop_start = bgm_tbl[bgm_no].loop_point << 1; +#endif +// thread_loop_start = bgm_tbl[bgm_no].loop_start; +// thread_loop_end = bgm_tbl[bgm_no].loop_end; +// if( dwSoundInit2( &Wfmtx, DataSize, &pDSData_tone[TONE_MAX], hmmio ) == FALSE ){ + if( dwSoundInit2( &Wfmtx, DataSize, &pDSData_stream, hmmio ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + return FALSE; + } +#if BGM_AUTO_LOOP + if( d1 > 0) + sd.dwWaveSize = d1 * d0; //?????t???????????????? +#endif + } else { + thread_stop_flg = 0; //????? + if( dwSoundInit( &Wfmtx, DataSize, &pDSData_tone[TONE_MAX] ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + //??????? + if( WaveDataRead( hmmio, &DataSize, pDSData_tone[TONE_MAX] ) == FALSE ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "ȡWAVʧܣ", "Error", MB_OK); +#endif + return FALSE; + } + } + mmioClose( hmmio , 0 ); + + //?????? + pDSData_tone[ TONE_MAX ]->SetFrequency((DWORD)freq_tbl[36+1+t_music_bgm_pitch[bgm_no]]); + //????? + pDSData_tone[ TONE_MAX ]->SetVolume(volume_tbl[ bgm_tbl[bgm_no].volume * t_music_bgm_volume / 15 ]); // ???????? + + //????? + if(bgm_tbl[bgm_no].loop_flg){ //????? + pDSData_tone[ TONE_MAX ]->Play(0, 0, DSBPLAY_LOOPING); + } else { + pDSData_tone[ TONE_MAX ]->Play(0, 0, 0); + } + + //?????k?V + t_music_bgm_no = bgm_no; + if(t_music_bgm_no < 0) t_music_bgm_no=0; + // ???????? + NowTime = TimeGetTime(); + + //???????? + t_music_playing_flg = 1; + + //?????k?V +// map_bgm_no = t_music_bgm_no; + + return TRUE; +} + +//?????????? ???????? ?????????? +void bgm_volume_change(void) +{ + if (MuteFlag) return; + + if(dsound_flg == -1) + return; + + if(t_music_bgm_volume > 15){ //d???? + t_music_bgm_volume = 15; + } + if(t_music_bgm_volume < 0){ //d???? + t_music_bgm_volume = 0; + } + //????? + if (pDSData_tone[TONE_MAX]) + { + pDSData_tone[TONE_MAX]->SetVolume(volume_tbl[bgm_tbl[t_music_bgm_no].volume * t_music_bgm_volume / 15]); // ???????? + } +} + +//?????????? ????????? ?????????? +void set_gbm_pitch(void) +{ + if(dsound_flg == -1) + return; + + //?????? + pDSData_tone[ TONE_MAX ]->SetFrequency((DWORD)freq_tbl[36+1+t_music_bgm_pitch[t_music_bgm_no]]); +} + +int t_music_se_no = -1; +//?????????? ???? ?????????? +//static voice_seek_point=0; +int play_se(int tone, int x, int y) +{ + if (MuteFlag) return -1; + + + int d0; + int total_level = 127; + t_music_se_no = tone; + + if(dsound_flg == -1) + return -1; + + if(tone > TONE_MAX){ //??????? + return -1; + } + + if(tone_tbl[ tone ].voice_place == -1){ //te???? + return -1; + } + + if(tone_tbl[ tone ].play_time){ //?????? + return 0; + } + + //q???k???? + d0 = voice[ voice_seek_point ].tone_no; + if(voice[ voice_seek_point ].tone_no != tone){ //i??k?????? + voice[ voice_seek_point ].tone_no = tone; //?k?V + //???????????????? + if(d0 != -2){ + RELEASE(pDSData[voice_seek_point]); //? + } + //???? + if( pDSound->DuplicateSoundBuffer(pDSData_tone[tone_tbl[ tone ].voice_place],&pDSData[voice_seek_point]) != DS_OK ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + //????????????????? + voice[ voice_seek_point ].tone_no = -2; + return -1; + } + } else { + pDSData[voice_seek_point]->SetCurrentPosition(0); //????????? + } +#if 0 + total_level = abs(y - 240); //????????? + y = abs(x - 320) >> 1; //????????? + if(total_level < y) //???? + total_level = y; // + + total_level = total_level << 4; //?????k?? + total_level /= 0x5a; // + + if(total_level >= 127) //d???? + return 0; //???? + + total_level = 127 - total_level; // + +#endif + + if(stereo_flg == T_MUSIC_MONO){ //?????? + x = 64; + } else { + x /= 5; //?????k?? + if(x < 0) // + x = 0; // + if(x > 127) // + x = 127; // + } + + //?????? + total_level = 127 * tone_tbl[ tone ].voice_volume / 127; +// total_level = total_level * tone_tbl[ tone ].voice_volume / 127; + + //????????? + total_level = total_level * t_music_se_volume / 15; + + pDSData[ voice_seek_point ]->SetVolume(volume_tbl[ total_level ]); // ???????? + pDSData[ voice_seek_point ]->SetPan(panpot_tbl[ x ]); // ???????? + if(tone_tbl[ tone ].voice_note){ //???k?e?? + pDSData[ voice_seek_point ]->SetFrequency( + (DWORD)freq_tbl[tone_tbl[ tone ].voice_note + tone_tbl[ tone ].voice_rate]); + } + +#if 0 + if(tone_tbl[ tone ].voice_loop == 0 ){ //?????? + pDSData[ voice_seek_point ]->Play(0, 0, 0); //???? + } else { + voice[ voice_seek_point ].loop_flg = 1; //???? + pDSData[ voice_seek_point ]->Play(0, 0, DSBPLAY_LOOPING); //???? + } +#else + pDSData[ voice_seek_point ]->Play(0, 0, 0); //???? +#endif + while(1){ + voice_seek_point++; //?????? + voice_seek_point&=VOICE_MAX-1; // + if(voice[ voice_seek_point ].loop_flg == 0){ //?????????? + break; + } + } + tone_tbl[ tone ].play_time = 5; //??????? + + return 0; +} +#endif + +//?????????? ???? ?????????? +//int play_environment_tone(int tone, int distance, int voice_address, int panpot, int new_flg) +int play_environment_tone(int tbl_no, int new_flg) +{ + int d0; +// int total_level; + +// t_music_se_no = tone; + + if (MuteFlag) return -1; + + if(dsound_flg == -1) + return -1; + + if(env_tbl[tbl_no].tone > TONE_MAX){ //??????? + return -1; + } + + if(tone_tbl[ env_tbl[tbl_no].tone ].voice_place == -1){ //te???? + return -1; + } + +// if(tone_tbl[ env_tbl[tbl_no].tone ].play_time){ //?????? +// return 0; +// } + + env_tbl[tbl_no].distance = env_tbl[tbl_no].distance << 4; //?????k?? + env_tbl[tbl_no].distance /= 0x6a; // + +// if(env_tbl[tbl_no].distance >= 127) //d???? +// return 0; //???? + + if(env_tbl[tbl_no].distance >= 127) //d???? + env_tbl[tbl_no].distance = 127; //???? + + if(new_flg){ //??? + //q???k???? + d0 = voice[ env_tbl[tbl_no].voice_address ].tone_no; + if(voice[ env_tbl[tbl_no].voice_address ].tone_no != env_tbl[tbl_no].tone){ //i??k?????? + voice[ env_tbl[tbl_no].voice_address ].tone_no = env_tbl[tbl_no].tone; //?k?V + //???????????????? + if(d0 != -2){ + RELEASE(pDSData[env_tbl[tbl_no].voice_address]); //? + } + //???? + if( pDSound->DuplicateSoundBuffer(pDSData_tone[tone_tbl[ env_tbl[tbl_no].tone ].voice_place],&pDSData[env_tbl[tbl_no].voice_address]) != DS_OK ){ +#ifdef _STONDEBUG_ + MessageBoxNew(hWnd, "bufferʧܣ", "Error", MB_OK); +#endif + //????????????????? + voice[ env_tbl[tbl_no].voice_address ].tone_no = -2; + return -1; + } + } + } + + //?????? +// total_level = (127 - env_tbl[tbl_no].volume) * tone_tbl[ env_tbl[tbl_no].tone ].voice_volume / 127; + + //????????? +// total_level = total_level * t_music_se_volume / 15; + + //??????????? + if(env_tbl[tbl_no].volume != env_tbl[tbl_no].volume_old){ + // ???????? + pDSData[ env_tbl[tbl_no].voice_address ]->SetVolume(volume_tbl[ env_tbl[tbl_no].volume ]); + env_tbl[tbl_no].volume_old = env_tbl[tbl_no].volume; + } + + //??????????? + if(env_tbl[tbl_no].panpot != env_tbl[tbl_no].panpot_old){ + // ???????? + pDSData[ env_tbl[tbl_no].voice_address ]->SetPan(panpot_tbl[ env_tbl[tbl_no].panpot ]); + env_tbl[tbl_no].panpot_old = env_tbl[tbl_no].panpot; + } + + //???k?e?? + if(tone_tbl[ env_tbl[tbl_no].tone ].voice_note){ + pDSData[ env_tbl[tbl_no].voice_address ]->SetFrequency( + (DWORD)freq_tbl[tone_tbl[ env_tbl[tbl_no].tone ].voice_note + tone_tbl[ env_tbl[tbl_no].tone ].voice_rate]); + } + + if(new_flg){ //??? + pDSData[ env_tbl[tbl_no].voice_address ]->SetCurrentPosition(0); // + if(tone_tbl[ env_tbl[tbl_no].tone ].voice_loop == 0 ){ //?????? + pDSData[ env_tbl[tbl_no].voice_address ]->Play(0, 0, 0); //???? + } else { + voice[ env_tbl[tbl_no].voice_address ].loop_flg = 1; //???? + pDSData[ env_tbl[tbl_no].voice_address ]->Play(0, 0, DSBPLAY_LOOPING); //???? + } + + while(1){ + voice_seek_point++; //?????? + voice_seek_point&=VOICE_MAX-1; // + if(voice[ voice_seek_point ].loop_flg == 0){ //?????????? + break; + } + } + } +// tone_tbl[ env_tbl[tbl_no].tone ].play_time = 8; //??????? + + return 0; +} + +//?????????? ?????????? ?????????? +void play_map_bgm_check(void) +{ + switch(map_bgm_vct_no){ + case 0: //???????? + if(draw_map_bgm_flg){ + if(t_music_bgm_no != map_bgm_no){ //?????? + map_bgm_vct_no++; //????????? + } + } + draw_map_bgm_flg = 0; + break; + + case 1: //??????????? + fade_out_bgm(); + map_bgm_vct_no++; //????????r?? + break; + + case 2: //???????????r? + if(t_music_fade_flg == 0){ //?????????? + map_bgm_vct_no++; //????? + } + break; + + case 3: //???? + play_bgm(map_bgm_no); //???? + map_bgm_vct_no = 0; //????????? + break; + } +} + +//?????????? ??????? ?????????? + +int BakBgm = 0; +int play_map_bgm(int tone) +{ + // shan 2002/01/18 +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + if( BakBgm != tone && tone >= 40 && tone <= 55 ) +#else + if( BakBgm != tone && tone >= 40 && tone <= 53 ) +#endif + { + FILE *fp; + char filename[255]; + char vTemp[32]; + BakBgm = tone; + + sprintf_s( filename, "map\\bgm%d.dat", sCharSide); + sprintf_s( vTemp, "%d", tone); + if( (fp = fopen( filename, "rb+" ))==NULL ) + { + _mkdir( "map" ); + fp = fopen( filename, "wb" ); + fclose( fp ); + if( (fp = fopen( filename, "rb+" ))==NULL ) + return FALSE; + } + fwrite( vTemp, sizeof(char), 2, fp ); + fclose (fp); + } + switch(tone){ + //????? + case 40: //?? + map_bgm_no = 4; + break; + case 41: //?? + map_bgm_no = 3; + break; + case 42: //n?? + map_bgm_no = 7; + break; + case 43: //n?? + map_bgm_no = 8; + break; + case 44: //n?? + map_bgm_no = 9; + break; + case 45: //????? + map_bgm_no = 10; + break; + case 46: //???????????? + map_bgm_no = 11; + break; + case 47: //½ + map_bgm_no = 15; + break; + case 48: //԰ + map_bgm_no = 16; + break; + case 49: //ij + map_bgm_no = 21; + break; + case 50: //س + map_bgm_no = 17; + break; + case 51: //ˮ + map_bgm_no = 18; + break; + case 52: // + map_bgm_no = 19; + break; + case 53: // + map_bgm_no = 20; + break; + +#ifdef _NEWMUSICFILE6_0 // Syu ADD 6.0 µͼ + case 54: + map_bgm_no = 22; // ׶ + break; + case 55: + map_bgm_no = 23; // ƽԭ + break; +#endif + } + return 0; +} + +//?????????? ???? ?????????? +int play_environment(int tone, int x, int y) +{ + int d0,d1,distance,volume; + d0 = d1 = 0; + float dx, dy; + if (MuteFlag) return 0; +// tone = 157; + + if(tone < 20 || tone > 37){ //??k?? + return 0; //???? + } + + switch(tone){ + case 28: //??? + if(SaTimeZoneNo != LS_MORNING){ //????? + return 0; //???? + } + break; + case 29: //? + if(SaTimeZoneNo != LS_NIGHT){ //?????? + return 0; //???? + } + break; + case 37: //? + if(SaTimeZoneNo == LS_MORNING){ //?? + return 0; //???? + } + if(SaTimeZoneNo == LS_NIGHT){ //??? + tone = 29; //??? + break; + } + break; + } + + + + + + + dx = (float)(x - 320); + dy = (float)(y - 240); + + distance = (int)sqrt( (double)(dx*dx+dy*dy) ); + + volume = distance << 4; //?????k?? + volume /= 0x6a; // + + if(volume >= 127) //d???? + return 0; //???? + + d0 = tone - 20; + tone = 151 + d0; + if(env_tbl[d0].count == 0){ //??? + //??V + env_tbl[d0].distance = distance; + volume = (127 - volume) * tone_tbl[ tone ].voice_volume / 127; + env_tbl[d0].volume = volume * t_music_se_volume / 15; + d1 = 1; //???????? + if(env_tbl[d0].voice_address == -1){ //??? + env_tbl[d0].tone = tone; + } + } else { + //?????V + if(env_tbl[d0].distance > distance){ + env_tbl[d0].distance = distance; + volume = (127 - volume) * tone_tbl[ tone ].voice_volume / 127; + env_tbl[d0].volume = volume * t_music_se_volume / 15; + d1 = 1; //???????? + } + } + //???? + if(d1){ + env_tbl[d0].side = x; + } + env_tbl[d0].count++; + return 0; +} + +//?????????? ??????? ?????????? +void play_environment_check(void) +{ + if(t_music_bgm_volume==1) return; + int d0,d1,d3,d7; + for(d7=0; d7Stop(); //???? + voice[ env_tbl[d7].voice_address ].loop_flg = 0; //????? + env_tbl[d7].voice_address = -1; + } + continue; + } + if(env_tbl[d7].voice_address == -1){ //??? + env_tbl[d7].voice_address = voice_seek_point; + env_tbl[d7].volume_old = -1; + env_tbl[d7].panpot_old = -1; + d0 = 1; + } else { + d0 = 0; + } + + if(stereo_flg == T_MUSIC_MONO){ //?????? + env_tbl[d7].panpot = d1 = 64; + } else { + d1 = env_tbl[d7].side / 5; //?????k?? + if(d1 < 0) // + d1 = 0; // + if(d1 > 127) // + d1 = 127; // + } + + if(d0){ //??? + env_tbl[d7].panpot = d1; + } else { + d3 = d1 - env_tbl[d7].panpot; + if(d3 > 2) + d3 = 2; + if(d3 < -2) + d3 = -2; + //?????@e + env_tbl[d7].panpot += d3; + } +// play_environment_tone(env_tbl[d7].tone, env_tbl[d7].distance, env_tbl[d7].voice_address, env_tbl[d7].panpot, d0); + play_environment_tone(d7, d0); + + env_tbl[d7].count = 0; //???????? + } +} + +//?????????? ??????????? ?????????? +void bgm_fade_check(void) +{ + //??????? + if(t_music_playing_flg == 0){ + t_music_fade_flg = 0; + return; + } + //???????????? + if(!t_music_fade_flg){ + return; + } + + if(!t_music_fade_vol || (t_music_bgm_volume==1 && t_music_se_volume == 1)){ + stop_bgm(); + t_music_bgm_no = -1; + } else { + // ???????? + pDSData_tone[ TONE_MAX ]->SetVolume(volume_tbl[ --t_music_fade_vol ]); + } +} + +//?????????? ??????? ?????????? +void check_se_loop(void){ + int d7; + + if(dsound_flg == -1) + return; + for(d7=0; d7 1); + +// MCI_OPEN_PARMS open = {0}; +// MCIERROR dwRes = {0}; + +// ??????? + open.lpstrDeviceType = "cdaudio"; + dwRes = mciSendCommand( 0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD)&open); + if ( dwRes) + { +#ifdef _STONDEBUG_ +// MessageBoxNew(hWnd, "CDʧܣ", "ȷ", MB_OK); +#endif + cdda_flg = 1; + return FALSE; + } + +// ?????????????e??? + MCI_SET_PARMS set; + set.dwTimeFormat = MCI_FORMAT_TMSF; + dwRes = mciSendCommand( open.wDeviceID, MCI_SET, + MCI_SET_TIME_FORMAT, (DWORD)&set); + if ( dwRes) + { +#ifdef _STONDEBUG_ +// MessageBoxNew(hWnd, "CDʧܣ", "ȷ", MB_OK); +#endif + cdda_flg = 1; + return FALSE; + } + return TRUE; +} +/*-------------------------------------------- + ????????? +---------------------------------------------*/ +bool cdda_start(int n) +{ +// ??? + // ???? n?? + MCI_PLAY_PARMS play; + play.dwFrom = MCI_MAKE_TMSF( n,0,0,0); + play.dwTo = MCI_MAKE_TMSF( n+1,0,0,0); + dwRes = mciSendCommand( open.wDeviceID, + MCI_PLAY, MCI_FROM | MCI_TO, + (DWORD)&play); + if ( dwRes) + { +#ifdef _STONDEBUG_ +// MessageBoxNew(hWnd, "??????????????", "ȷ", MB_OK); +#endif + cdda_flg = 2; //???????? + return FALSE; + } + return TRUE; +} +/*-------------------------------------------- + ?????_ +---------------------------------------------*/ +bool cdda_stop(void) +{ + if(cdda_flg == 1) //?????????? + return TRUE; + + mciSendCommand(open.wDeviceID, MCI_STOP, 0, NULL); + +// ??????? + dwRes = mciSendCommand( open.wDeviceID, MCI_CLOSE, 0, (DWORD)NULL); + if ( dwRes) + { +#ifdef _STONDEBUG_ +// MessageBoxNew(hWnd, "??????????????", "ȷ", MB_OK); +#endif + return FALSE; + } + return TRUE; +} +/*-------------------------------------------- + ?????? +---------------------------------------------*/ +extern DWORD NowTime; +//extern double NowTime; + +bool cdda_play(int n) +{ + check_se_loop(); //???????? + + cdda_flg = 1; //?????????? + return TRUE; + + if(cdda_flg == 1) //?????????? + return TRUE; + + if(cdda_no != n ){ //?????? + cdda_flg = 0; //?????? + cdda_check_cnt = -1; + } + + if(cdda_flg) //?????? + return TRUE; + + cdda_check_cnt++; + cdda_check_cnt&=63; + if(cdda_check_cnt) + return TRUE; + + if(cdda_no == n ){ //???? + MCI_STATUS_PARMS mcisp; mcisp.dwItem = MCI_STATUS_MODE; + if(mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&mcisp)){ //??? + cdda_flg = 3; //?????????? + return FALSE; + } + if(mcisp.dwReturn == MCI_MODE_PLAY){ //???? + return TRUE; + } else { //????? + cdda_no = Rnd( 11, 34 ); + cdda_start( cdda_no ); + // ???w????? + NowTime = TimeGetTime(); + return TRUE; + } + } else { + cdda_no = n; //??? + cdda_stop(); + cdda_open( n ); + cdda_start( n ); + // ???w????? + NowTime = TimeGetTime(); + } + return TRUE; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/talkwindow.cpp b/石器时代8.5客户端最新源代码/石器源码/system/talkwindow.cpp new file mode 100644 index 0000000..7a81496 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/talkwindow.cpp @@ -0,0 +1,616 @@ +#include "../systeminc/version.h" +#include "../systeminc/talkwindow.h" +#include "../systeminc/main.h" +#include "../resource.h" +#include "../systeminc/loadrealbin.h" +#include "../oft/work.h" +#include "../systeminc/font.h" +#include "../systeminc/mouse.h" +#include "../systeminc/tool.h" + +#ifdef _TALK_WINDOW + +int g_iCursorCount = -1; +extern HFONT hFont; + +#ifdef _CHANNEL_MODIFY +extern char g_szChannelTitle[][13]; +extern int TalkMode; +#endif + +CTalkWindow::CTalkWindow() {}; +CTalkWindow::~CTalkWindow() +{ + Release(); +}; + +void CTalkWindow::Init(HWND hWnd,HINSTANCE hInstance) +{ + int i; + ChatBufferLink *pCBL; + + m_hdcBackBuffer = 0; + m_hbmpOldBackBuffer = 0; + m_hbmpBackBuffer = 0; + m_bScroll = FALSE; + m_bUpArrowHit = FALSE; + m_bDownArrowHit = FALSE; + m_bInit = FALSE; + m_hTalkWindow = NULL; + m_hWnd = hWnd; + m_hInstance = hInstance; + m_iline = 0; + + for(i=0;inext = (ChatBufferLink*)MALLOC(sizeof(ChatBufferLink)); + if(pCBL == NULL){ + MessageBoxNew(hWnd,TEXT("CTalkWindow::Init()ʧ(2)!!"),TEXT("ȷ"),MB_OK); + Release(); + return; + } + memset(pCBL->next,0,sizeof(ChatBufferLink)); + pCBL->next->prev = pCBL; + pCBL = pCBL->next; + } + pCBL->next = NULL; + m_pCBLTail = pCBL; + m_bInit = TRUE; + LoadSkin("data\\skin\\default"); +#ifdef _STONDEBUG_ + m_iSymbolCount = 0; + memset(m_fsFaceSymbol,0,sizeof(m_fsFaceSymbol)); + memset(m_ssStoreSymbol,0,sizeof(m_ssStoreSymbol)); + ReadFaceSymbolFile(); +#endif +}; + +void CTalkWindow::Release(void) +{ + ChatBufferLink *pCBL = m_pCBLHead,*pCBLTemp; + + for(int i=0;inext){ + if(pCBL->next->next){ + pCBLTemp = pCBL->next->next; + FREE(pCBL->next); + pCBL->next = pCBLTemp; + } + else FREE(pCBL->next); + } + } + FREE(m_pCBLHead); +#ifdef _STONDEBUG_ + ReleaseFaceSymbol(); +#endif +}; + +void CTalkWindow::Create() +{ + RECT rect; + WNDCLASS wndclass; + + if(!m_bInit) return; + if(m_hTalkWindow){ + ShowWindow(m_hTalkWindow,SW_SHOW); + SetFocus(hWnd); + return; + } + wndclass.style = CS_OWNDC; + wndclass.lpfnWndProc = TalkWindowProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = m_hInstance; + wndclass.hIcon = NULL; + wndclass.hCursor = LoadCursor(m_hInstance ,MAKEINTRESOURCE(SA_MOUSE1)); + wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wndclass.lpszMenuName= NULL; + wndclass.lpszClassName = "TALK"; + RegisterClass(&wndclass); + GetWindowRect(hWnd,&rect); + m_hTalkWindow = CreateWindow("TALK","TalkWIndow",WS_OVERLAPPED, + rect.left,rect.top + rect.bottom, + SKIN_WIDTH,SKIN_HEIGHT,hWnd,NULL,m_hInstance,NULL); + if(m_hTalkWindow){ + DWORD dwStyle; + HRGN hRegion; + + ShowWindow(m_hTalkWindow,SW_SHOW); + UpdateWindow(m_hTalkWindow); + hRegion = CreateRectRgn(0,0,SKIN_WIDTH,SKIN_HEIGHT+GetSystemMetrics(SM_CYSIZE)+GetSystemMetrics(SM_CXFIXEDFRAME)); + SetWindowRgn(m_hTalkWindow,hRegion,true); + DeleteObject(hRegion); + dwStyle = GetWindowLong(m_hTalkWindow,GWL_STYLE); + dwStyle &= ~(WS_CAPTION|WS_SIZEBOX); + SetWindowLong(m_hTalkWindow,GWL_STYLE,dwStyle); + InvalidateRect(m_hTalkWindow,NULL,TRUE); + SetWindowPos(m_hTalkWindow,NULL,0,0,SKIN_WIDTH,SKIN_HEIGHT+GetSystemMetrics(SM_CYSIZE),SWP_NOMOVE|SWP_NOZORDER); + SetTimer(m_hTalkWindow,1,500,(TIMERPROC)NULL); + TalkWindow.Update(); + SetFocus(hWnd); + } +} + +void CTalkWindow::Update() +{ + if(g_bTalkWindow) SendMessage(m_hTalkWindow,WM_UPDATE_SKIN,0,0); +} + +void CTalkWindow::LoadSkin(char *szSkinPath) +{ + char szFileName[5][32] = + { "\\base.bmp","\\up_arrow_g.bmp","\\up_arrow_r.bmp","\\down_arrow_g.bmp","\\down_arrow_r.bmp"}; + char szTemp[128]; + // skinͼ + for(int i=0;iChatBuffer.buffer); +#endif + color = pCBL->ChatBuffer.color; + if(pCBL->bUse){ + SetTextColor(m_hdcBackBuffer,0); + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXO + 1,TALK_WINDOW_SYO + 1 + j * 18,szBuffer,(int)strlen(szBuffer)); + SetTextColor(m_hdcBackBuffer,FontPal[color]); + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXO,TALK_WINDOW_SYO + j * 18,szBuffer,(int)strlen(szBuffer)); + j++; + } + } + if(pCBL->next == NULL) pCBL = m_pCBLHead; + else pCBL = pCBL->next; + } + // ʾ + strcpy(szBuffer,MyChatBuffer.buffer); + color = MyChatBuffer.color; + SetTextColor(m_hdcBackBuffer,0); +#ifdef _CHANNEL_MODIFY + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXI - 25,TALK_WINDOW_SYI+1,g_szChannelTitle[TalkMode],(int)strlen(g_szChannelTitle[TalkMode])); // ʾƵ +#endif + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXI + 1,TALK_WINDOW_SYI + 1,szBuffer,(int)strlen(szBuffer)); + SetTextColor(m_hdcBackBuffer,FontPal[color]); +#ifdef _CHANNEL_MODIFY + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXI - 26,TALK_WINDOW_SYI,g_szChannelTitle[TalkMode],(int)strlen(g_szChannelTitle[TalkMode])); // ʾƵ +#endif + TextOut(m_hdcBackBuffer,TALK_WINDOW_SXI,TALK_WINDOW_SYI,szBuffer,(int)strlen(szBuffer)); + + // ʾα + if(bShowCursor){ + int x; + + x = TALK_WINDOW_SXI + MyChatBuffer.cursor * (FONT_SIZE>>1); + SetTextColor(m_hdcBackBuffer,0); + TextOut(m_hdcBackBuffer,x + 1,TALK_WINDOW_SYI + 1,"_",1); + SetTextColor(m_hdcBackBuffer,FontPal[color]); + TextOut(m_hdcBackBuffer,x,TALK_WINDOW_SYI,"_",1); + } + SelectObject(m_hdcBackBuffer,hOldFont); +#ifdef _STONDEBUG_ + ShowFaceSymbol(); +#endif + // draw to window dc + hdc = GetDC(m_hTalkWindow); + BitBlt(hdc,0,0,SKIN_WIDTH,SKIN_HEIGHT,m_hdcBackBuffer,0,0,SRCCOPY); + ReleaseDC(m_hTalkWindow,hdc); +} + +void CTalkWindow::AddString(char *szString,int color) +{ + if(m_hTalkWindow){ + // Ϸһʼûִ,ҪȰ m_iline ۼӵ MAX_TALK_WINDOW_LINE Žʾƶ + if(m_iline <= MAX_TALK_WINDOW_LINE) m_iline++; + strcpy(m_pCBLString->ChatBuffer.buffer,szString); + m_pCBLString->ChatBuffer.color = color; + m_pCBLString->bUse = TRUE; + // Ϸһʼûִ,Ҫ m_iline ֵڵ MAX_TALK_WINDOW_LINE ʱŽʾƶ + // ھ״̬ʱʾƶ + if(!m_bScroll && m_iline > MAX_TALK_WINDOW_LINE){ + if(m_pCBLView->next != NULL) m_pCBLView = m_pCBLView->next; + else m_pCBLView = m_pCBLHead; + } + // ھ״̬ʱʾƶ + if(!m_bScroll){ + if(m_pCBLViewBottom->next != NULL) m_pCBLViewBottom = m_pCBLViewBottom->next; + else m_pCBLViewBottom = m_pCBLHead; + } + // m_pCBLString->next ʱ,ʾѵ list β,ָ list ͷ + if(m_pCBLString->next == NULL) m_pCBLString = m_pCBLHead; + else m_pCBLString = m_pCBLString->next; + } +} + +// Ͼ +void CTalkWindow::UpArrowHit(BOOL bHit) +{ + m_bUpArrowHit = bHit; + if(bHit){ + m_bScroll = FALSE; + // m_pCBLView m_pCBLString ,ʾĿǰʾΧû m_pCBLString + if(m_pCBLView != m_pCBLString){ + // m_pCBLView->prev Ϊ NULL,ʾϾ + if(m_pCBLView->prev == NULL){ + // listβʹõĻ, m_pCBLView ָ m_pCBLTail + if(m_pCBLTail->bUse){ + m_pCBLView = m_pCBLTail; + m_bScroll = TRUE; + m_pCBLViewBottom = m_pCBLViewBottom->prev; // ƶʾ + if(m_pCBLViewBottom == NULL) m_pCBLViewBottom = m_pCBLTail; + } + } + // δ + else if(m_pCBLView->prev->bUse){ + m_pCBLView = m_pCBLView->prev; + m_bScroll = TRUE; + m_pCBLViewBottom = m_pCBLViewBottom->prev; + if(m_pCBLViewBottom == NULL) m_pCBLViewBottom = m_pCBLTail; + } + } + } +} + +// ¾ +void CTalkWindow::DownArrowHit(BOOL bHit) +{ + m_bDownArrowHit = bHit; + if(bHit){ + m_bScroll = FALSE; + // m_pCBLViewBottom m_pCBLString ,ʾĿǰʾΧû m_pCBLString + if(m_pCBLViewBottom != m_pCBLString){ + // m_pCBLView->next Ϊ NULL,ʾ¾ + if(m_pCBLView->next == NULL){ + // listβʹõĻ, m_pCBLView ָ m_pCBLHead + if(m_pCBLTail->bUse){ + m_pCBLView = m_pCBLHead; + m_bScroll = TRUE; + m_pCBLViewBottom = m_pCBLViewBottom->next; // ƶʾ + if(m_pCBLViewBottom == NULL) m_pCBLViewBottom = m_pCBLHead; + } + } + // δ + else if(m_pCBLView->next->bUse){ + m_pCBLView = m_pCBLView->next; + m_bScroll = TRUE; + m_pCBLViewBottom = m_pCBLViewBottom->next; + if(m_pCBLViewBottom == NULL) m_pCBLViewBottom = m_pCBLHead; + } + } + } +} + +void CTalkWindow::ClearChatBuffer(void) +{ + ChatBufferLink *pCBL = m_pCBLHead; + + while(pCBL != NULL){ + memset(&pCBL->ChatBuffer,0,sizeof(CHAT_BUFFER)); + pCBL->bUse = FALSE; + pCBL = pCBL->next; + } + m_pCBLView = m_pCBLViewBottom = m_pCBLString = m_pCBLHead; + m_iline = 0; +} + +void CTalkWindow::Visible(BOOL flag) +{ + ShowWindow(m_hTalkWindow,SW_HIDE); + ::ClearChatBuffer(); +} + +#ifdef _STONDEBUG_ +void CTalkWindow::ReadFaceSymbolFile(void) +{ + FILE *pfFaceSymbolFile = NULL; + char szReadBuffer[32]; + int iStrlen; + fopen_s(&pfFaceSymbolFile,"data\\facesymbol.ini","r"); + if(pfFaceSymbolFile){ + for(int i=0;iChatBuffer.buffer,sizeof(szSourString)); + memset(szTemp,0,sizeof(szTemp)); + iStrlen = strlen(szSourString); + for(int i=0;i>1)) > 610){ + if(pCBL->next != NULL){ + sprintf_s(szTemp,"%s%s",&szSourString[iStoreX],pCBL->next->ChatBuffer.buffer); + sprintf_s(pCBL->next->ChatBuffer.buffer,"%s",szTemp); + }else{ + sprintf_s(szTemp,"%s%s",&szSourString[iStoreX],m_pCBLHead->ChatBuffer.buffer); + sprintf_s(m_pCBLHead->ChatBuffer.buffer,"%s",szTemp); + } + // ԭȵִɶ + memcpy(szTemp,szSourString,iStoreX); + sprintf_s(szSourString,"%s",szTemp); + sprintf_s(pCBL->ChatBuffer.buffer,"%s",szTemp); + // 趨 i Ϊ STR_BUFFER_SIZE + 1 Ϊֱ뿪 i Dz loop + i = STR_BUFFER_SIZE + 1; + bBreak = TRUE; + break; + } + szDestString[iCount++] = ' '; + szDestString[iCount++] = ' '; + szDestString[iCount++] = ' '; + // ¼ҪǸλʾ + m_ssStoreSymbol[m_iSymbolCount].bUse = TRUE; + m_ssStoreSymbol[m_iSymbolCount].hDraw = m_fsFaceSymbol[j].hDraw; + m_ssStoreSymbol[m_iSymbolCount].hDrawMask = m_fsFaceSymbol[j].hDrawMask; + m_ssStoreSymbol[m_iSymbolCount].x = x + (iStoreX + iSymbolNum) * (FONT_SIZE>>1); + m_ssStoreSymbol[m_iSymbolCount].y = y; + m_iSymbolCount++; + bBreak = TRUE; + iSymbolNum++; + break; + } + i++; + } + else{ + i = iStoreX; + break; + } + } + } + //if(bBreak) break; + } + if(j == FACE_SYMBOL_NUM){ + szDestString[iCount++] = szSourString[iStoreX]; + } + } + szDestString[iCount] = '\0'; +} + +void CTalkWindow::ShowFaceSymbol(void) +{ + SetTextColor(m_hdcBackBuffer,0); + for(int i=0;icnt = 0; + pNowStrBuffer->buffer[0] = NULL; + } + }else KeyboardBackSpace(); + break; + case VK_DELETE: + TalkWindow.ClearChatBuffer(); + break; + case VK_CONTROL: + if(di_key[DIK_V] & 0x80) GetClipboad(); + break; + case VK_V: + if(GetKeyState(VK_CONTROL) & 0xff00) GetClipboad(); + break; + case VK_UP: + joy_auto[0] |= JOY_UP; + ChatProc(); + break; + case VK_DOWN: + joy_auto[0] |= JOY_DOWN; + ChatProc(); + break; + } + TalkWindow.Update(); + break; + case WM_CHAR: + StockStrBufferChar((char)wParam); + break; + case WM_TIMER: + bShowCursor = !bShowCursor; + TalkWindow.DrawSkin(bShowCursor); + break; + case WM_PAINT: + BeginPaint(hWnd,&ps); + EndPaint(hWnd,&ps); + case WM_UPDATE_SKIN: + TalkWindow.DrawSkin(bShowCursor); + break; + case WM_MOVE: + RECT rect; + + GetWindowRect(::hWnd,&rect); + SetWindowPos(hWnd,NULL,rect.left,rect.bottom,0,0,SWP_NOZORDER|SWP_NOSIZE); + break; + case WM_LBUTTONDOWN: + if(MAKEPOINTS(lParam).x >= 620 && MAKEPOINTS(lParam).x <= 638 && + MAKEPOINTS(lParam).y >= 8 && MAKEPOINTS(lParam).y <= 26){ + TalkWindow.UpArrowHit(TRUE); + TalkWindow.DrawSkin(bShowCursor); + } + if(MAKEPOINTS(lParam).x >= 620 && MAKEPOINTS(lParam).x <= 638 && + MAKEPOINTS(lParam).y >= 98 && MAKEPOINTS(lParam).y <= 116){ + TalkWindow.DownArrowHit(TRUE); + TalkWindow.DrawSkin(bShowCursor); + } + break; + case WM_LBUTTONUP: + TalkWindow.UpArrowHit(FALSE); + TalkWindow.DownArrowHit(FALSE); + TalkWindow.DrawSkin(bShowCursor); + break; + default: + return DefWindowProc( hWnd, Message, wParam, lParam ); + } + return 0; +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/test.cpp b/石器时代8.5客户端最新源代码/石器源码/system/test.cpp new file mode 100644 index 0000000..3dcb380 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/test.cpp @@ -0,0 +1,14 @@ +#include "../systeminc/version.h" +#include +#include "test.h" + +void test(char *data) +{ + FILE *logfile; + logfile = fopen("test.txt","a+"); + if(logfile) + { + fprintf(logfile,"%s\n",data); + fclose(logfile); + } +} \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/test.h b/石器时代8.5客户端最新源代码/石器源码/system/test.h new file mode 100644 index 0000000..e79728d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/test.h @@ -0,0 +1,2 @@ + +void test(char *data); diff --git a/石器时代8.5客户端最新源代码/石器源码/system/testview.cpp b/石器时代8.5客户端最新源代码/石器源码/system/testview.cpp new file mode 100644 index 0000000..330b0c6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/testview.cpp @@ -0,0 +1,559 @@ +/************************/ +/* testView.cpp */ +/************************/ +#include "../systeminc/version.h" +#include "../systeminc/system.h" +#include "../systeminc/loadsprbin.h" +#include "../systeminc/anim_tbl.h" +#include "../oft/vg410.h" +#include "../systeminc/t_music.h" + +#ifdef _STONDEBUG_ + +// ??????????? +extern void hit_mark_critical( ACTION *a0 ); + +// ?????????????????? +void StockDispBufferSprView( int x, int y, UCHAR dispPrio, int bmpNo ) +{ + // ??V????????????? + DISP_SORT *pDispSort = DispBuffer.DispSort + DispBuffer.DispCnt; + DISP_INFO *pDispInfo = DispBuffer.DispInfo + DispBuffer.DispCnt; + + // ?????????? + if( DispBuffer.DispCnt >= DISP_BUFFER_SIZE ) return; + + // ?I?????Bl + pDispSort->dispPrio = dispPrio; + pDispSort->no = DispBuffer.DispCnt; + // ѩ?Bl? ??????? ? + pDispInfo->x = x; + pDispInfo->y = y; + pDispInfo->bmpNo = bmpNo; + pDispInfo->hitFlag = 2; + + // ???????? + DispBuffer.DispCnt++; +} + +/* ??????_???? ********************************************************************/ +void SprViewProc( void ) +{ + char szMoji[ 256 ]; + int bmpX; + int bmpY; + static int bmpNo = 0; + int bmpNoBak; + static int no = 0; // ?Ƨk? + static BOOL fontFlag = TRUE; // ??????? + // ????? + int zoubunTbl[] ={ 1, 5, 25, 100, 500, 1000, + -1, -5, -25, -100, -500, -1000 }; + static int palNo = 0; // ????k? + static int time = 600; // ????k? + + /* ??????k??? */ + switch( SubProcNo ){ + + case 0: + // ??????????? + //BackBufferDrawType = DRAW_BACK_NON + // ??????????? + // ??? + if( joy_auto[ 0 ] & JOY_RIGHT ) bmpNo += zoubunTbl[ no ]; + // ?? + if( joy_auto[ 0 ] & JOY_LEFT ) bmpNo -= zoubunTbl[ no ]; + // ???? + if( joy_trg[ 0 ] & JOY_UP ){ + no++; + if( no >= 6 ) no = 0; // ???????? + } + // ????? + if( joy_trg[ 0 ] & JOY_DOWN ){ + no--; + if( no <= -1 ) no = 5; // ???????? + } +#if 0 + // ????????? + // ??????? + if( mouse.onceState & MOUSE_LEFT_CRICK ){ + bmpNo += zoubunTbl[ no ]; + // ????? + play_se( 201, 320, 240 ); + } + // ????????? + if( GetAsyncKeyState( VK_MBUTTON ) ){ + bmpNo += zoubunTbl[ no ]; + } + + // ???????ƨ? + if( mouse.onceState & MOUSE_RIGHT_CRICK ){ + //if( mouse.state & MOUSE_RIGHT_CRICK ){ + no++; + if( no == 6 ) no = 0; // ???????? + // ????? + play_se( 201, 320, 240 ); + } +#endif + // ???????? + if( bmpNo < 0 ) bmpNo = 0; + if( bmpNo >= MAX_GRAPHICS - 25 ) bmpNo = MAX_GRAPHICS -25; + + // ????? + if( joy_trg[ 0 ] & JOY_A ){ /* ??? */ + palNo--; + if( palNo < 0 ) palNo = MAX_PAL - 1; + // ???????? + PaletteChange( palNo, 10 ); + // ???????? + play_se( 202, 320, 240 ); + } + if( joy_trg[ 0 ] & JOY_B ){ /* ???? */ + palNo++; + if( palNo >= MAX_PAL ) palNo = 0; + // ???????? + PaletteChange( palNo, 10 ); + // ???????? + play_se( 202, 320, 240 ); + } + // ???????? + if( joy_trg[ 0 ] & JOY_DEL ){ /* ??? */ + if( fontFlag ) fontFlag = 0; + else fontFlag = 1; + // ?????? + play_se( 212, 320, 240 ); + } + + // ????? + if( joy_trg[ 0 ] & JOY_ESC ){ /* ???? */ + // ???????? WM_CLOSE ?????????? + PostMessage( hWnd, WM_CLOSE, 0, 0L ); + } + + // ???k??????? + bmpNoBak = bmpNo; + + // ?????????? + for( bmpY = 0 ; bmpY < lpDraw->ySize ; bmpY += 96 ){ + for( bmpX = 0 ; bmpX < lpDraw->xSize ; bmpX += 128 ){ + // ??????????? + if( fontFlag == TRUE ){ + // ???k? + wsprintf( szMoji,"%7d", bmpNoBak ); + StockFontBuffer( bmpX, bmpY, FONT_PRIO_BACK, 0, szMoji, 0 ); + } + // ??????????? + StockDispBufferSprView( bmpX, bmpY, 0, bmpNoBak++ ); + } + } + // ??????????? + if( fontFlag == TRUE ){ + // ?Ƥ + wsprintf( szMoji, "PAL:%2d ?:%6d", palNo, zoubunTbl[ no ] ); + StockFontBuffer( 640 - 16 * 12, 462, FONT_PRIO_FRONT, 0, szMoji, 0 ); + + // ? + StockFontBuffer( 4, 462, FONT_PRIO_FRONT, 0, "ESC: X or Y:PAL DEL: ON/OFF", 0 ); + } + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + + // ????? + StockBoxDispBuffer( 0, 0, lpDraw->xSize, lpDraw->ySize, DISP_PRIO_BG, SYSTEM_PAL_PURPLE , 1 ); + + // ???????? + NowTime = TimeGetTime(); + + break; + } +} + +/* ?????????????? ***********************************************/ +void AnimSpr( ACTION *pAct ) +{ + char szMoji[ 256 ]; + int x = 32, y = 32; + int c = 0,d0; + ACTION *a1; + static int palNo = 0; + static int anim_spd = 0; + static bool slowFlag = FALSE; + static int hitNo = 0; + + /* ֢t?? */ + switch( pAct->state ){ + /* G? */ + case ACT_STATE_ACT: + // ??????? + if( slowFlag == FALSE ){ + // ?????k?????? + if( joy_auto[ 0 ] & JOY_RIGHT ){ /* ??? */ + while( 1 ){ + pAct->anim_chr_no++; + if( SpriteData[pAct->anim_chr_no - SPRSTART].ptAnimlist !=NULL ) break; + if( pAct->anim_chr_no > 1000000 ){ + pAct->anim_chr_no = 1000000; + break; + } + } + } + if( joy_auto[ 0 ] & JOY_LEFT ){ /* ???? */ + while( 1 ){ + pAct->anim_chr_no--; + if( SpriteData[pAct->anim_chr_no - SPRSTART].ptAnimlist !=NULL ) break; + if( pAct->anim_chr_no < SPRSTART ){ + pAct->anim_chr_no = SPRSTART; + break; + } + } + } + // ?????k????????? + if( joy_trg[ 0 ] & JOY_INS ){ /* ??? */ + pAct->anim_chr_no += 1000; + while( 1 ){ + pAct->anim_chr_no++; + if( SpriteData[pAct->anim_chr_no - SPRSTART].ptAnimlist !=NULL ) break; + if( pAct->anim_chr_no > 1000000 ){ + pAct->anim_chr_no = 1000000; + break; + } + } + } + if( joy_trg[ 0 ] & JOY_DEL ){ /* ???? */ + pAct->anim_chr_no -= 1000; + while( 1 ){ + pAct->anim_chr_no--; + if( SpriteData[pAct->anim_chr_no - SPRSTART].ptAnimlist !=NULL ) break; + if( pAct->anim_chr_no < SPRSTART ){ + pAct->anim_chr_no = SPRSTART; + break; + } + } + } + // ?????????????? + //while( 1 ){ + //if( SpriteData[ pAct->anim_chr_no ].ptAnimlist == NULL ) + //{ + + + // ?? + if( joy_auto[ 0 ] & JOY_UP ){ /* ??? */ + pAct->anim_ang++; + if( pAct->anim_ang >= 8 ) pAct->anim_ang = 0; + } + if( joy_auto[ 0 ] & JOY_DOWN ){ /* ???? */ + pAct->anim_ang--; + if( pAct->anim_ang < 0 ) pAct->anim_ang = 7; + } + + // ???????k? + if( joy_trg[ 0 ] & JOY_HOME ){ /* ??? */ + pAct->anim_no++; + if( pAct->anim_no > 12 ) pAct->anim_no = 12; + } + if( joy_trg[ 0 ] & JOY_END ){ /* ???? */ + pAct->anim_no--; + if( pAct->anim_no < 0 ) pAct->anim_no = 0; + } + + // ????? + if( joy_trg[ 0 ] & JOY_A ){ /* ??? */ + anim_spd--; + if( anim_spd < 0 ) anim_spd = 0; + } + if( joy_trg[ 0 ] & JOY_B ){ /* ???? */ + anim_spd++; + if( anim_spd >= 255 ) anim_spd = 255; + } + } + // ????? + if( joy_trg[ 0 ] & JOY_ESC ){ /* ???? */ + // ???????? WM_CLOSE ?????????? + PostMessage( hWnd, WM_CLOSE, 0, 0L ); + } + + + // ????????? + if( joy_trg[ 1 ] & JOY_F12 ){ + pAct->anim_frame_cnt = 0; + slowFlag = TRUE; + } + // ????????? + if( joy_trg[ 1 ] & JOY_F11 ){ + pAct->anim_cnt -= 2; + // ???????? + if( pAct->anim_cnt <= 0 ) pAct->anim_cnt = 0; + pAct->anim_frame_cnt = 0; + slowFlag = TRUE; + } + // ?????????? + if( joy_trg[ 1 ] & JOY_F10 ) + slowFlag = FALSE; + + if( slowFlag == FALSE || joy_trg[ 1 ] & JOY_F11 || joy_trg[ 1 ] & JOY_F12 ){ + // ??????? + pattern( pAct, anim_spd, ANM_LOOP ); + } + + // ???Re?? + if( pAct->anim_hit >= 10000 ){ + hitNo = pAct->anim_hit; // ???Rek??? + pAct->anim_hit = 0; // ??? + // ??????? + for( d0=5 ;d0>0 ;d0--){ + //????????? + a1 = GetAction( PRIO_JIKI, sizeof( ATR_EQU ) ); + if( a1 == NULL ) return; + /* ?IT */ + ATR_DISP_PRIO(a1) = DISP_PRIO_CHAR + 1; + /* ?????k? */ + ATR_CHR_NO(a1) = CG_HIT_MARK_22; + ATR_H_POS(a1) = 320; + ATR_V_POS(a1) = 240; + ATR_SPD(a1) = Rnd( 4, 7 ); + ATR_CRS(a1) = d0 * 6; + ATR_FIRST_FLG(a1) = ATR_STIMER(a1) = 32; //????? + ATR_KAISHIN(a1) = 1; + ATR_NAME(a1) = hit_mark_critical; + ATR_CHR_NO(a1) = CG_HIT_MARK_01; + } + } + // ?????k? + wsprintf( szMoji, " = %8d Left or Right ( 1 )", pAct->anim_chr_no ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + StockFontBuffer( x + 236, y, FONT_PRIO_FRONT, 0, " DEL or INS ( ?1000 )", 0 ); y += 20; + // ? + wsprintf( szMoji, " = %8d Down or UP", pAct->anim_ang ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ???????k? + wsprintf( szMoji, " = %8d END or HOME", pAct->anim_no ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ?Ƥ + wsprintf( szMoji, " = %8d Z or X", anim_spd ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + + // ???k? + wsprintf( szMoji, " Ч = %8d", t_music_se_no ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ?????? + if( t_music_se_no != -1 ){ + // ?????? + if( joy_trg[ 1 ] & JOY_F8 ){ /* ??? */ + tone_tbl[ t_music_se_no ].voice_volume++; + if( tone_tbl[ t_music_se_no ].voice_volume >= 128 ) tone_tbl[ t_music_se_no ].voice_volume = 127; + } + if( joy_trg[ 1 ] & JOY_F7 ){ /* ???? */ + tone_tbl[ t_music_se_no ].voice_volume--; + if( tone_tbl[ t_music_se_no ].voice_volume <= -1 ) tone_tbl[ t_music_se_no ].voice_volume = 0; + } + + // ??????? + if( joy_trg[ 1 ] & JOY_F6 ){ /* ??? */ + tone_tbl[ t_music_se_no ].voice_note++; + if( tone_tbl[ t_music_se_no ].voice_note + tone_tbl[ t_music_se_no ].voice_rate >= 63 ) tone_tbl[ t_music_se_no ].voice_note = 62 - tone_tbl[ t_music_se_no ].voice_rate; + } + if( joy_trg[ 1 ] & JOY_F5 ){ /* ???? */ + tone_tbl[ t_music_se_no ].voice_note--; + if( tone_tbl[ t_music_se_no ].voice_note + tone_tbl[ t_music_se_no ].voice_rate <= 0 ) tone_tbl[ t_music_se_no ].voice_note = -tone_tbl[ t_music_se_no ].voice_rate + 1; + } + // ????? + wsprintf( szMoji, " Ч = %8d F7 or F8", tone_tbl[ t_music_se_no ].voice_volume ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ?????? + wsprintf( szMoji, " Ч = %8d F5 or F6", tone_tbl[ t_music_se_no ].voice_note ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + }else{ + // ????? + wsprintf( szMoji, " Ч = %8d F7 or F8", 0 ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ?????? + wsprintf( szMoji, " Ч = %8d F5 or F6", 0 ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + } + + // ???k? + //wsprintf( szMoji, "??? k ? = %8d", pAct->bmpNo ); + //StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ??? + //wsprintf( szMoji, "??? ??? = %4d,%4d", SpriteInfo[ pAct->bmpNo ].width, SpriteInfo[ pAct->bmpNo ].height ); + //StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + + // ???Rek? + wsprintf( szMoji, "???Rek? = %8d", hitNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + + // ?????C + wsprintf( szMoji, "F12???? F11???? F10???" ); + StockFontBuffer( 8, 460, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + + // ? + StockFontBuffer( 530, 460, FONT_PRIO_FRONT, 0, "ESC", 0 ); + + break; + + /* ?? */ + case ACT_STATE_DEAD: + + DeathAction( pAct ); + + break; + } +} + +/* ????????????? ***********************************************/ +ACTION *MakeAnimSpr( void ) +{ + ACTION *pAct; + + /* ?????????K? */ + pAct = GetAction( PRIO_JIKI, 0 ); + if( pAct == NULL ) return NULL; + + /* ??? */ + pAct->func = AnimSpr; + // anim_tbl.h ?k? + pAct->anim_chr_no = SPRSTART; + // h?k? + pAct->anim_no = 0;//ANIM_ATTACK; + // ?????????( ??? )( ??????? ) + pAct->anim_ang = 0;//Rnd( 0, 7 ); + // ???? + pAct->atr |= ACT_ATR_HIT_BOX; + /* ?IT */ + pAct->dispPrio = DISP_PRIO_CHAR; + /* ???t */ + pAct->x = 320; + pAct->y = 360; + + // ??????? + pattern( pAct, ANM_NOMAL_SPD, ANM_LOOP ); + + return pAct; +} + +/* ????????_???? ********************************************************************/ +void AnimViewProc( void ) +{ + /* ??????k??? */ + switch( SubProcNo ){ + + case 0: + + // ????????????? + MakeAnimSpr(); + // Pf????? + play_bgm( 1 ); + // ??????k???? + SubProcNo++; + + break; + + case 1: + + /* ????????? */ + RunAction(); + // ??????????????? + StockTaskDispBuffer(); + + // ????? + StockBoxDispBuffer( 0, 0, lpDraw->xSize, lpDraw->ySize, DISP_PRIO_BG, SYSTEM_PAL_PURPLE , 1 ); + + break; + } +} + +/* ???_???? ********************************************************************/ +void SeTestProc( void ) +{ + char szMoji[ 256 ]; + int x = 128, y = 196; + static int seNo = 1, bgmFlag; + + /* ??????k??? */ + switch( SubProcNo ){ + + case 0: + + // ??????k???? + SubProcNo++; + + break; + + case 1: + + // ????? + if( joy_trg[ 0 ] & JOY_A ) play_se( seNo, 320, 240 ); + // ?????????? + if( joy_trg[ 0 ] & JOY_B ){ + if( bgmFlag == FALSE ){ + bgmFlag = TRUE; + play_bgm( 0 ); + }else{ + bgmFlag = FALSE; + stop_bgm(); + } + } + + // ???k?????? + if( joy_auto[ 0 ] & JOY_RIGHT ){ /* ??? */ + while( 1 ){ + seNo++; + if( seNo >= TONE_MAX ) seNo = 1; + if( tone_tbl[ seNo ].voice_volume != 0 ) break; + } + } + if( joy_auto[ 0 ] & JOY_LEFT ){ /* ???? */ + while( 1 ){ + seNo--; + if( seNo < 0 ) seNo = TONE_MAX - 1; + if( tone_tbl[ seNo ].voice_volume != 0 ) break; + } + } + // ?????? + if( joy_auto[ 1 ] & JOY_F8 ){ /* ??? */ + tone_tbl[ seNo ].voice_volume++; + if( tone_tbl[ seNo ].voice_volume >= 128 ) tone_tbl[ seNo ].voice_volume = 127; + } + if( joy_auto[ 1 ] & JOY_F7 ){ /* ???? */ + tone_tbl[ seNo ].voice_volume--; + if( tone_tbl[ seNo ].voice_volume <= -1 ) tone_tbl[ seNo ].voice_volume = 0; + } + + // ??????? + if( joy_auto[ 1 ] & JOY_F6 ){ /* ??? */ + tone_tbl[ seNo ].voice_note++; + if( tone_tbl[ seNo ].voice_note + tone_tbl[ seNo ].voice_rate >= 63 ) tone_tbl[ seNo ].voice_note = 62 - tone_tbl[ seNo ].voice_rate; + } + if( joy_auto[ 1 ] & JOY_F5 ){ /* ???? */ + tone_tbl[ seNo ].voice_note--; + if( tone_tbl[ seNo ].voice_note + tone_tbl[ seNo ].voice_rate <= 0 ) tone_tbl[ seNo ].voice_note = -tone_tbl[ seNo ].voice_rate + 1; + } + + // ????? + if( joy_trg[ 0 ] & JOY_ESC ){ /* ???? */ + // ???????? WM_CLOSE ?????????? + PostMessage( hWnd, WM_CLOSE, 0, 0L ); + } + // ???k? + wsprintf( szMoji, " Ч = %4d Left or Right", seNo ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ????? + wsprintf( szMoji, " Ч = %4d F7 or F8", tone_tbl[ seNo ].voice_volume ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ?????? + wsprintf( szMoji, " Ч = %4d F5 or F6", tone_tbl[ seNo ].voice_note ); + StockFontBuffer( x, y, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + // ???????? + wsprintf( szMoji, "Z Ч Xֲ" ); + StockFontBuffer( 16, 460, FONT_PRIO_FRONT, 0, szMoji, 0 ); y += 20; + + // ? + StockFontBuffer( 530, 460, FONT_PRIO_FRONT, 0, "ESC", 0 ); + + break; + } +} + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/system/tool.cpp b/石器时代8.5客户端最新源代码/石器源码/system/tool.cpp new file mode 100644 index 0000000..3709325 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/tool.cpp @@ -0,0 +1,877 @@ +#include +#include +#include +#include +#include +/* WIN32_LEAN_AND_MEAN?define???WINDOWS.H??? +??????????????????????? +????????????????? */ +#define WIN32_LEAN_AND_MEAN +#include +#include +#include "iphlpapi.h" +#pragma comment(lib, "iphlpapi.lib ") +#include "../systeminc/version.h" +#include "../systeminc/tool.h" + + +#ifdef _TIME_GET_TIME +LARGE_INTEGER tickCount; +LARGE_INTEGER CurrentTick; +#endif + + +void Delay(ULONG ulMicroSeconds) +{ + LARGE_INTEGER timeStop; + LARGE_INTEGER timeStart; + LARGE_INTEGER Freq; + ULONG ulTimeToWait; + + if (!QueryPerformanceFrequency(&Freq)) + return; + + ulTimeToWait = Freq.QuadPart * ulMicroSeconds / 1000 / 1000; + + QueryPerformanceCounter(&timeStart); + + timeStop = timeStart; + + while (timeStop.QuadPart - timeStart.QuadPart < ulTimeToWait) + { + QueryPerformanceCounter(&timeStop); + } +} + + +BOOL isXP() +{ + OSVERSIONINFOEX os; + os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if (GetVersionEx((OSVERSIONINFO *)&os)) + { + //ݰ汾Ϣжϲϵͳ + switch (os.dwMajorVersion){ //ж汾 + case 4: + return FALSE; + case 5: + return TRUE; + case 6: + return FALSE; + default: + return FALSE; + } + } + else + { + return FALSE; + } +} + + + +unsigned int TimeGetTime(void) +{ +#ifdef _TIME_GET_TIME + static __int64 time; + QueryPerformanceCounter(&CurrentTick); + return (unsigned int)(time = CurrentTick.QuadPart / tickCount.QuadPart); + //return GetTickCount(); +#else + return GetTickCount(); + //return timeGetTime(); +#endif +} + +static int copyStringUntilDelim(unsigned char *, char delim, int, unsigned char *); + + +// ?????????t?????????? +int wordchk(char **pp) +{ + char *p = *pp; + + while (*p != 0) + { + switch (*p) + { + case '\t': + p++; + break; + + case ' ': + p++; + break; + + default: + *pp = p; + return 1; + } + } + + return 0; +} + + +// ?????????????????????h +int getword(char **pp, char *q) +{ + int i = 0; + char *p = *pp; + + wordchk(&p); + + for (i = 0; *p != ' ' && *p != '\t' && *p != '\0'; p++, q++, i++) + { + *q = *p; + } + + *q = '\0'; + *pp = p; + + return i; +} + + +#if 0 +// ????????? +void freadline( char *ptbuf, FILE *fp ) +{ + char buf; + int i; + + for( i = 0; ; i++ ) + { + if( feof( fp ) != 0 ) + { + *ptbuf--; + *ptbuf = '\0'; + break; + } + + fread( &buf, 1, sizeof( unsigned char ), fp ); + if( buf == ' ' ) + { + *ptbuf++ = buf; + }else if (buf == '\t'){ + *ptbuf++ = buf; + }else if (buf != 0x0d && buf != 0x0a){ + *ptbuf++ = buf; + }else{ + *ptbuf++ = '\0'; + break; + } + } + while ( feof(fp ) == 0 ){ + fread( &buf ,1 , sizeof(unsigned char) , fp ); + if (buf != 0x0d && buf != 0x0a ){ + fseek( fp, -1, SEEK_CUR); + break; + } + } +} +#endif + + +// ????i????????????h?? +int strstr2(char **pp, char *q) +{ + char *p = *pp; + int i; + + wordchk(&p); + + for (i = 1; *p++ == *q++; i++) + { + if (*q == 0) + { + *pp = p; + return i; + } + } + + return 0; +} + + +// ?????????????????k????? +int strint2(char **pp) +{ + char moji[1024] = ""; + char *p = *pp; + + getword(&p, moji); + *pp = p; + + return atoi(moji); +} + + +// ????????????????long??k????? +long strlong2(char **pp) +{ + char moji[1024] = ""; + char *p = *pp; + + getword(&p, moji); + *pp = p; + + return atol(moji); +} + +// ????S??????????? +// ??kNULL?? ... ?????????? +// NULL ... ???Z??? +inline unsigned char *searchDelimPoint(unsigned char *src, unsigned char delim) +{ + unsigned char *pt = src; + + while (1) + { + if (*pt == '\0') + return (unsigned char *)0; + + if (*pt < 0x80) + { + // 1bayte???? + if (*pt == delim) + { + // ?????????????????? + pt++; + return pt; + } + pt++; + } + else + { + // 2byte???? + pt++; + if (*pt == '\0') + return (unsigned char *)0; + pt++; + } + } +} + + +/* + ???????????????????????e??????????? + ?????????? + + char *src : ????? + char delim : ???? + int count : ???????????????? + int maxlen : out ??????????? + char *out : ? + + + ??k 0???????? + 1:??Z???? + */ +int getStringToken(char *src, char delim, int count, int maxlen, char *out) +{ + int c = 1; + int i; + unsigned char *pt; + + pt = (unsigned char *)src; + for (i = 0; i < count - 1; i++) + { + if (pt == (unsigned char *)0) + break; + + pt = searchDelimPoint(pt, delim); + } + + if (pt == (unsigned char *)0) + { + out[0] = '\0'; + return 1; + } + + return copyStringUntilDelim(pt, delim, maxlen, (unsigned char *)out); +} + + +/* + ????????????????????????????? + + char *src : ???? + char delim : ???? + int maxlen : ??????? + char *out : ? + + ??k 0???????? + 1:??Z???? + */ +static int copyStringUntilDelim(unsigned char *src, char delim, + int maxlen, unsigned char *out) +{ + int i; + + for (i = 0; i < maxlen; i++) + { + if (src[i] < 0x80) + { + // 1byte???? + + if (src[i] == delim) + { + // ???????? + out[i] = '\0'; + return 0; + } + + // ???????? + out[i] = src[i]; + + // Z????? + if (out[i] == '\0') + return 1; + } + else + { + // 2byte???? + + // ???????? + out[i] = src[i]; + + i++; + if (i >= maxlen) // ??????????? + break; + + // ???????? + out[i] = src[i]; + + // Z??????????????????? + if (out[i] == '\0') + return 1; + } + } + + out[i] = '\0'; + + return 1; +} + + +/* + ???????intk?????? + + char *src : ????? + char delim: ????????? + int count :????????? ?????????? + + return value : k + + */ +int getIntegerToken(char *src, char delim, int count) +{ + char s[128]; + + getStringToken(src, delim, count, sizeof(s)-1, s); + + if (s[0] == '\0') + return -1; + + return atoi(s); +} + + +/* + double??????????? + char *src : ????? + char delim: ????????? + int count :????????? ?????????? + + return value: k + */ +double getDoubleToken(char *src, char delim, int count) +{ + char s[128]; + + getStringToken(src, delim, count, sizeof(s)-1, s); + + return strtod(s, NULL); +} + + +/* + chop??(UNIX????) + + char *src : ????? ?????????????? + + */ +void chop(char *src) +{ + int i; + + for (i = 0;; i++) + { + if (src[i] == 0) + break; + if (src[i] == '\n' && src[i + 1] == '\0') + { + src[i] = '\0'; + break; + } + } +} + + +/* +int?????????? + +int *a : ?????? +int siz : ????? +int count : ??????????? +???????????? +*/ +void shiftIntArray(int *a, int siz, int count) +{ + int i; + + for (i = 0; i < siz - count; i++) + { + a[i] = a[i + count]; + } + for (i = siz - count; i < siz; i++) + { + a[i] = 0; + } +} + + +// 62???int???? +// 0-9,a-z(10-35),A-Z(36-61) +int a62toi(char *a) +{ + int ret = 0; + int fugo = 1; + + while (*a != NULL) + { + ret *= 62; + if ('0' <= (*a) && (*a) <= '9') + ret += (*a) - '0'; + else + if ('a' <= (*a) && (*a) <= 'z') + ret += (*a) - 'a' + 10; + else + if ('A' <= (*a) && (*a) <= 'Z') + ret += (*a) - 'A' + 36; + else + if (*a == '-') + fugo = -1; + else + return 0; + a++; + } + return ret*fugo; +} + + +/* + ???????intk?????? + + char *src : ????? + char delim: ????????? + int count :????????? ?????????? + + return value : k + + */ +int getInteger62Token(char *src, char delim, int count) +{ + char s[128]; + + getStringToken(src, delim, count, sizeof(s)-1, s); + if (s[0] == '\0') + return -1; + + return a62toi(s); +} + + +/* + ???????????{???? + + char *s1 : ??? + char *s2 : ??? + int len : ?{???? + + + */ +int strncmpi(char *s1, char *s2, int len) +{ + int i; + int c1, c2; + + for (i = 0; i < len; i++) + { + if (s1[i] == '\0' || s2[i] == '\0') + return 0; + + c1 = tolower(s1[i]); + c2 = tolower(s2[i]); + + if (c1 != c2) + return 1; + } + + return 0; +} + + + + +RECT intToRect(int left, int top, int right, int bottom) +{ + RECT rc = { left, top, right, bottom }; + + return rc; +} + + + + +/***************************************************************** + ?????????????1?\????????? + 0???SJIS?? + ******************************************************************/ +int isOnlySpaceChars(char *data) +{ + int i = 0; + int returnflag = 0; + + while (data[i] != '\0') + { + returnflag = 0; + if ((unsigned char)data[i] == ' ') + returnflag = 1; + if (IsDBCSLeadByte(data[i])) + { + if ((unsigned char)data[i] == 0x81 + && (unsigned char)data[i + 1] == 0x40) + { + returnflag = 1; + } + i++; + } + if (returnflag == 0) + return 0; + i++; + } + + if (i == 0) + return 0; + + return returnflag; +} + + +/**************************** + ????????V??? + buffer: ???? + string: V???? + whereToinsert: ???V??? + ****************************/ +void insertString(char *buffer, char *string, int whereToInsert) +{ + int stringLength, bufferLength, i; + + stringLength = strlen(string); + bufferLength = strlen(buffer); + + for (i = 0; i <= bufferLength - whereToInsert; i++) + { + buffer[bufferLength + stringLength - i] = buffer[bufferLength - i]; + } + for (i = 0; i < stringLength; i++) + { + buffer[whereToInsert + i] = string[i]; + } +} + + +/**************************** + ???????V??? + buffer: ???? + character: V???? + whereToinsert: ???V??? + ****************************/ +void insertChar(char *buffer, char character, int whereToInsert) +{ + int bufferLength, i; + + bufferLength = strlen(buffer); + + for (i = 0; i <= bufferLength - whereToInsert; i++) + { + buffer[bufferLength + 1 - i] = buffer[bufferLength - i]; + } + buffer[whereToInsert] = character; +} + + +/************************************************************* +?????????????????? +*************************************************************/ +typedef struct tagEscapeChar +{ + char escapechar; + char escapedchar; +} EscapeChar; + +static EscapeChar escapeChar[] = +{ + { '\n', 'n' }, + { ',', 'c' }, + { '|', 'z' }, + { '\\', 'y' }, +}; + + +// ???????GЧ???? +// ??kGЧ?(?????????????????) +char makeCharFromEscaped(char c) +{ + int i; + + for (i = 0; i < sizeof(escapeChar) / sizeof(escapeChar[0]); i++) + { + if (escapeChar[i].escapedchar == c) + { + c = escapeChar[i].escapechar; + break; + } + } + + return c; +} + + + +/*---------------------------------------- + * makeEscapeString???????????? + * ?? + * src char* ????????????v?? + * ?k + * src ???(???V??????????) + ----------------------------------------*/ +char *makeStringFromEscaped(char *src) +{ + int srclen = strlen(src); + int searchindex = 0; + for (int i = 0; i < srclen; i++){ + if (IsDBCSLeadByte(src[i])){ + src[searchindex++] = src[i++]; + src[searchindex++] = src[i]; + } + else{ + if (src[i] == '\\'){ + int j; + i++; + for (j = 0; j < sizeof(escapeChar) / sizeof(escapeChar[0]); j++) + if (escapeChar[j].escapedchar == src[i]){ + src[searchindex++] = escapeChar[j].escapechar; + goto NEXT; + } + src[searchindex++] = src[i]; + } + else + src[searchindex++] = src[i]; + } + NEXT: + ; + } + src[searchindex] = '\0'; + return src; +} + + +/*---------------------------------------- + * ???????? + * ?? + * src char* ?????? + * dest char* ?????????? + * sizeofdest int dest ? ??? + * ?k + * dest ???(???V??????????) + ----------------------------------------*/ +char *makeEscapeString(char *src, char *dest, int sizeofdest) +{ + int srclen = strlen(src); + int destindex = 0; + for (int i = 0; i < srclen; i++){ + if (destindex + 1 >= sizeofdest) + break; + if (IsDBCSLeadByte(src[i])){ + if (destindex + 2 < sizeofdest){ + dest[destindex++] = src[i++]; + dest[destindex++] = src[i]; + } + else + break; + } + else{ + BOOL dirty = FALSE; + char escapechar = '\0'; + for (int j = 0; j < sizeof(escapeChar) / sizeof(escapeChar[0]); j++) + if (src[i] == escapeChar[j].escapechar){ + dirty = TRUE; + escapechar = escapeChar[j].escapedchar; + break; + } + if (dirty == TRUE){ + if (destindex + 2 < sizeofdest){ + dest[destindex++] = '\\'; + dest[destindex++] = escapechar; + } + else + break; + } + else + dest[destindex++] = src[i]; + } + } + dest[destindex] = '\0'; + return dest; +} + + +/*************************************************************** + ????????? by Jun + ***************************************************************/ +/* +char *src ????adress +int srclen ????src???? +int keystring ???????????? +char *encoded ????????????t?????????? +int *encodedlen ???????????????????? +int maxencodedlen ?????????? +*/ +void jEncode(char *src, int srclen, int key, + char *encoded, int *encodedlen, int maxencodedlen) +{ + char sum = 0; + int i; + + if (srclen + 1 > maxencodedlen) + { + // ????????? 1 ???? + // ????????????????O???????? + *encodedlen = maxencodedlen; + for (i = 0; i < (*encodedlen); i++) + { + encoded[i] = src[i]; + } + } + + if (srclen + 1 <= maxencodedlen) + { + // ?????????? + *encodedlen = srclen + 1; + for (i = 0; i < srclen; i++) + { + sum = sum + src[i]; + // Id??7?????2????????????T + if (((key % 7) == (i % 5)) || ((key % 2) == (i % 2))) + { + src[i] = ~src[i]; + } + } + for (i = 0; i < (*encodedlen); i++) + { + if (abs((key%srclen)) > i) + { + encoded[i] = src[i] + sum*((i*i) % 3); // ????????? + } + else + // key%srclen??t?u??????????t? + if (abs((key%srclen)) == i) + { + encoded[i] = sum; + } + else + if (abs((key%srclen)) < i) + { + encoded[i] = src[i - 1] + sum*((i*i) % 7); // ????????? + } + } + } +} + + +/* +char *src ????????? +int srclen ??????????????? +int key ????????i??? +char *decoded ??????????? +int *decodedlen ??????????? +*/ +void jDecode(char *src, int srclen, int key, char *decoded, int *decodedlen) +{ + char sum; + int i; + + *decodedlen = srclen - 1; + sum = src[abs(key % (*decodedlen))]; + + for (i = 0; i < srclen; i++) + { + if (abs((key % (*decodedlen))) > i) + { + decoded[i] = src[i] - sum*((i*i) % 3); + } + + if (abs((key % (*decodedlen))) < i) + { + decoded[i - 1] = src[i] - sum*((i*i) % 7); + } + } + for (i = 0; i < (*decodedlen); i++) + { + if (((key % 7) == (i % 5)) || ((key % 2) == (i % 2))) + { + decoded[i] = ~decoded[i]; + } + } +} + + +bool GetMacAddress(char *strMac) +{ + PIP_ADAPTER_INFO pAdapterInfo; + DWORD AdapterInfoSize; + TCHAR szMac[32] = { 0 }; + DWORD Err; + AdapterInfoSize = 0; + Err = GetAdaptersInfo(NULL, &AdapterInfoSize); + if ((Err != 0) && (Err != ERROR_BUFFER_OVERFLOW)){ + //TRACE("Ϣʧܣ"); + return FALSE; + } + // Ϣڴ + pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, AdapterInfoSize); + if (pAdapterInfo == NULL){ + //TRACE("Ϣڴʧ"); + return FALSE; + } + if (GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize) != 0){ + //TRACE(_T("Ϣʧܣ\n")); + GlobalFree(pAdapterInfo); + return FALSE; + } + sprintf_s(strMac, 64, "%02X-%02X-%02X-%02X-%02X-%02X", + pAdapterInfo->Address[0], + pAdapterInfo->Address[1], + pAdapterInfo->Address[2], + pAdapterInfo->Address[3], + pAdapterInfo->Address[4], + pAdapterInfo->Address[5]); + + GlobalFree(pAdapterInfo); + return TRUE; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/system/unpack.cpp b/石器时代8.5客户端最新源代码/石器源码/system/unpack.cpp new file mode 100644 index 0000000..c547168 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/unpack.cpp @@ -0,0 +1,331 @@ +#include +#include +#include +#include "../systeminc/version.h" +#include"../systeminc/unpack.h" +#include "zlib.h" +#pragma comment(lib,"zlib.lib") +#ifdef _STONDEBUG_ +extern int g_iMallocCount; +#endif + +#define BIT_CMP (unsigned char)0x80 +#define BIT_ZERO (unsigned char)0x40 +#define BIT_REP_LARG (unsigned char)0x10 +#define BIT_REP_LARG2 (unsigned char)0x20 +unsigned char *encoder( unsigned char *buf, unsigned char **disBuf, + unsigned int width, unsigned int height, unsigned int *len, int cmpFlag ) +{ + unsigned char *wBuf, *ewBuf, *eBuf; + unsigned char *wBuf1, *buf1; + unsigned char *wBuf2, *buf2; + unsigned char idx; + int flag = 1; + RD_HEADER *header; + unsigned int cnt, cnt2; + unsigned char repData; + int mode; + unsigned int l, el; + int addWBuf; + + if( *disBuf == NULL ){ + if( (wBuf = (unsigned char *)MALLOC( width * height + sizeof( RD_HEADER ) )) == NULL ) + { + return NULL; + } +#ifdef _STONDEBUG_ + g_iMallocCount++; +#endif + *disBuf = wBuf; + }else{ + wBuf = *disBuf; + } + + if( cmpFlag ){ + flag = 1; + }else{ + flag = 0; + } + eBuf = buf + width * height; + ewBuf = wBuf + width * height + sizeof( RD_HEADER ); + wBuf1 = wBuf+sizeof( RD_HEADER ); + buf1 = buf; + while( cmpFlag ){ + if( buf1 >= eBuf ){ + flag = 1; + break; + } + if( wBuf1 >= ewBuf ){ + flag = 0; + break; + } + + if( *buf1 == 0 && *(buf1+1) == 0 ){ + idx = BIT_CMP | BIT_ZERO; + cnt = 2; + buf1 += 2; + while( buf1 < eBuf && cnt < 0xfffff ){ + if( *buf1 != 0 ){ + break; + } + buf1++; + cnt++; + } + if( cnt <= 0xf ){ + addWBuf = 0; + }else + if( cnt <= 0xfff ){ + addWBuf = 1; + }else{ + addWBuf = 2; + } + if( wBuf1+addWBuf >= ewBuf ){ + flag = 0; + break; + } + if( addWBuf == 0 ){ + idx |= (cnt & 0x0f); + *wBuf1++ = idx; + continue; + }else + if( addWBuf == 1 ){ + idx |= (BIT_REP_LARG | ((cnt >> 8) & 0xf)); + *wBuf1++ = idx; + *wBuf1++ = (unsigned char)(cnt & 0xff); + continue; + }else{ + idx |= (BIT_REP_LARG2 | ((cnt >> 16) & 0xf)); + *wBuf1++ = idx; + *wBuf1++ = (unsigned char)((cnt >> 8) & 0xff); + *wBuf1++ = (unsigned char)(cnt & 0xff); + continue; + } + } + if( *buf1 == *(buf1+1) && *buf1 == *(buf1+2) ){ + repData = *buf1; + idx = BIT_CMP; + cnt = 3; + buf1 += 3; + while( buf1 < eBuf && cnt < 0xfffff ){ + if( *buf1 != repData ){ + break; + } + buf1++; + cnt++; + } + if( cnt <= 0xf ){ + addWBuf = 1; + }else + if( cnt <= 0xfff ){ + addWBuf = 2; + }else{ + addWBuf = 3; + } + if( wBuf1+addWBuf >= ewBuf ){ + flag = 0; + break; + } + if( addWBuf == 1 ){ + idx |= (cnt & 0x0f); + *wBuf1++ = idx; + *wBuf1++ = repData; + continue; + }else + if( addWBuf == 2 ){ + idx |= (BIT_REP_LARG | ((cnt >> 8) & 0xf)); + *wBuf1++ = idx; + *wBuf1++ = repData; + *wBuf1++ = (unsigned char)(cnt & 0xff); + continue; + }else{ + idx |= (BIT_REP_LARG2 | ((cnt >> 16) & 0xf)); + *wBuf1++ = idx; + *wBuf1++ = repData; + *wBuf1++ = (unsigned char)((cnt >> 8) & 0xff); + *wBuf1++ = (unsigned char)(cnt & 0xff); + continue; + } + } + idx = 0; + cnt2 = 0; + buf2 = buf1; + wBuf2 = wBuf1; + while( 1 ){ + if( buf2 >= eBuf || cnt2 >= 0xfff ){ + mode = 0; + break; + } + if( wBuf2 >= ewBuf ){ + mode = 1; + break; + } + if( buf2+2 < eBuf ){ + if( *buf2 == 0 && *(buf2+1) == 0 ){ + mode = 0; + break; + } + if( *buf2 != 0 && *buf2 == *(buf2+1) && *(buf2+1) == *(buf2+2) ){ + mode = 0; + break; + } + + } + buf2++; + wBuf2++; + cnt2++; + } + if( cnt2 <= 0xf ){ + addWBuf = 0; + }else + if( cnt2 <= 0xfff ){ + addWBuf = 1; + }else{ + addWBuf = 2; + } + + if( mode == 1 || wBuf2+addWBuf >= ewBuf ){ + flag = 0; + break; + } + if( addWBuf == 0 ){ + idx = (cnt2 & 0xf); + *wBuf1++ = idx; + }else + if( addWBuf == 1 ){ + idx = BIT_REP_LARG | ((cnt2 >> 8) & 0xf); + *wBuf1++ = idx; + *wBuf1++ = (unsigned char)(cnt2 & 0xff); + }else{ + idx = BIT_REP_LARG2 | ((cnt2 >> 16) & 0xf); + *wBuf1++ = idx; + *wBuf1++ = (unsigned char)((cnt2 >> 8) & 0xff); + *wBuf1++ = (unsigned char)(cnt2 & 0xff); + } + for( cnt = 0; cnt < cnt2; cnt++ ){ + *wBuf1++ = *buf1++; + } + } + + + header = (RD_HEADER *)wBuf; + header->id[0] = 'R'; + header->id[1] = 'D'; + header->width = width; + header->height = height; + + if( flag == 1 ) + { + header->compressFlag = 1; + header->size = wBuf1 - wBuf; + l = header->size; + } + else + // ??????? + { + header->compressFlag = 0; + header->size = (int)wBuf + width * height + sizeof( RD_HEADER ); + wBuf1 = wBuf + sizeof( RD_HEADER ); + buf1 = buf; + el = width * height; + for( l = 0; l < el; l++ ) + *wBuf1++ = *buf1++; + l += sizeof( RD_HEADER ); + } + + *len = l; + return wBuf; +} +#ifdef _NEW_COLOR_ +extern int NewColor16Flg; +#endif +unsigned char *decoder( unsigned char *buf, unsigned char **disBuf, + unsigned int *width1, unsigned int *height1, unsigned int *len ) +{ + RD_HEADER *header; + unsigned char *wBuf, *ewBuf, *eBuf; + unsigned char *wBuf1, *buf1; + unsigned int width, height; + unsigned int cnt; + unsigned int l, el; + unsigned char repData; + unsigned char idx; + if( *disBuf == NULL ) + return NULL; + wBuf = *disBuf; + header = (RD_HEADER *)buf; + if( header->id[0] != 'R' || header->id[1] != 'D' ){ + return NULL; + } + width = header->width; + height = header->height; + if( header->compressFlag == 0 ){//û + wBuf1 = wBuf; + buf1 = buf+sizeof( RD_HEADER ); + el = width * height; + for( l = 0; l < el; l++ ) + *wBuf1++ = *buf1++; + + *len = l; + *width1 = width; + *height1 = height; + return wBuf; +#ifdef _NEW_COLOR_ + }else if( header->compressFlag >= 16 ){ + *len = width * height * 4; + *width1 = width; + *height1 = height; + uncompress(*disBuf,(unsigned long *)len,buf+sizeof(RD_HEADER),header->size - sizeof(RD_HEADER)); + if(header->compressFlag == 16) + NewColor16Flg=1; + else{ + NewColor16Flg=2; + } + return wBuf; +#endif + }else{// + eBuf = buf + header->size; + ewBuf = wBuf + width * height; + wBuf1 = wBuf; + buf1 = buf+sizeof( RD_HEADER ); + while( buf1 < eBuf ){ + idx = *buf1++; + if( (idx & BIT_CMP) != 0 ){ + if( (idx & BIT_ZERO) != 0 ){ + repData = 0; + }else{ + repData = *buf1++; + } + if( (idx & BIT_REP_LARG2) != 0 ){ + cnt = ((idx & 0x0f)<<16); + cnt |= ((*buf1) << 8); + buf1++; + cnt |= *buf1++; + }else + if( (idx & BIT_REP_LARG) != 0 ){ + cnt = ((idx & 0x0f)<<8); + cnt |= *buf1++; + }else{ + cnt = (idx & 0x0f); + } + memset( wBuf1, repData, cnt ); + wBuf1 += cnt; + }else{ + if( (idx & BIT_REP_LARG) != 0 ) { + cnt = ((idx & 0x0f)<<8); + cnt |= *buf1++; + }else{ + cnt = (idx & 0x0f); + } + if( cnt >= 0xfffff ){ + return NULL; + } + for( l = 0; l < cnt; l++ ) + *wBuf1++ = *buf1++; + } + } + *len = width * height; + *width1 = width; + *height1 = height; + return wBuf; + } +} diff --git a/石器时代8.5客户端最新源代码/石器源码/system/vssver.scc b/石器时代8.5客户端最新源代码/石器源码/system/vssver.scc new file mode 100644 index 0000000..e3025c8 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/vssver.scc @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/system/zconf.h b/石器时代8.5客户端最新源代码/石器源码/system/zconf.h new file mode 100644 index 0000000..ec93af6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/zconf.h @@ -0,0 +1,506 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2012 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +/* ./configure may #define Z_U4 here */ + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# else +# if (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# else +# if (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +# endif +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#ifdef WIN32 +# include /* for wchar_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/system/zlib.h b/石器时代8.5客户端最新源代码/石器源码/system/zlib.h new file mode 100644 index 0000000..3e0c767 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/system/zlib.h @@ -0,0 +1,1768 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.8, April 28th, 2013 + + Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.8" +#define ZLIB_VERNUM 0x1280 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 8 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#else +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#endif + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#ifdef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if defined(_WIN32) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/石器时代8.5客户端最新源代码/石器源码/system/zlib.lib b/石器时代8.5客户端最新源代码/石器源码/system/zlib.lib new file mode 100644 index 0000000..09df0a7 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/system/zlib.lib differ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/BinLoad.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/BinLoad.h new file mode 100644 index 0000000..31ce0fd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/BinLoad.h @@ -0,0 +1,30 @@ +#pragma once + +#include "../systeminc/version.h" + +#ifdef BIN_LOAD +class BinLoad +{ +public: + BinLoad(void); + ~BinLoad(void); + +public: + static void LoadBinData(); + +private: + static void EncryptSimple( const char* szSrc, char* szDes ); + static void LoadOneBin( char* pszFilePath ); + + static void SetBinData( char* pszFileName, char* pszData, int iLine ); +#ifdef QUEST_EXTERN + static void SetQuestData( char* pszData, int iLine ); + static void SetActData( char* pszData, int iLine ); +#endif +#ifdef PET_EXTERN + static void SetPetLifeType( char* pszData ); +#endif + static int GetStringData( char* pszData, int iBegin, char cEnd, char* pszToken ); +}; + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/CharSignDay.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/CharSignDay.h new file mode 100644 index 0000000..7d5a1eb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/CharSignDay.h @@ -0,0 +1,7 @@ +void ǩڳʼ(char * str); +ACTION* ǩ(); +ACTION* ǩʾ(); +void ǩ״̬(int ״̬); + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/EncryptClient.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/EncryptClient.h new file mode 100644 index 0000000..e106025 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/EncryptClient.h @@ -0,0 +1,97 @@ +#ifndef ENCRYPTCLIENT_H +#define ENCRYPTCLIENT_H + +#include + +template +class CEncryptClient +{ +public: + CEncryptClient(){ Init(); } +public: + void Init() { m_nPos1 = m_nPos2 = 0; } + void Encrypt(unsigned char * bufMsg, int nLen, bool bMove = true); + void ChangeCode(DWORD dwData); +protected: + int m_nPos1; + int m_nPos2; +protected: + class CEncryptCode + { + public: + CEncryptCode() + { + //* ELSE㷨ֻͬΪǿԣ) + unsigned char nCode = fst1; + int i; + for(i = 0; i < 256; i++) + { + m_bufEncrypt1[i] = nCode; + int nTemp = (a1*nCode) % 256; + nCode = (c1 + nTemp*nCode + b1*nCode) % 256; + } + //@@@ assert(nCode == fst1); + + nCode = fst2; + for( i = 0; i < 256; i++) + { + m_bufEncrypt2[i] = nCode; + int nTemp = a2*nCode; + nCode = ((b2 + nTemp)*nCode + c2) & 0xFF; + } + //@@@ assert(nCode == fst2); + } + unsigned char m_bufEncrypt1[256]; + unsigned char m_bufEncrypt2[256]; + }m_cGlobalEncrypt; //??? Ӧijɾ̬ijԱԽԼԴ +}; + +template +inline void CEncryptClient::Encrypt(unsigned char * bufMsg, int nLen, bool bMove /*= true*/) +{ + int nOldPos1 = m_nPos1; + int nOldPos2 = m_nPos2; + for(int i = 0; i < nLen; i++) + { + bufMsg[i] ^= m_cGlobalEncrypt.m_bufEncrypt1[m_nPos1]; + bufMsg[i] ^= m_cGlobalEncrypt.m_bufEncrypt2[m_nPos2]; + if(++m_nPos1 >= 256) + { + m_nPos1 = 0; + if(++m_nPos2 >= 256) + m_nPos2 = 0; + } + //@@@ assert(m_nPos1 >=0 && m_nPos1 < 256); + //@@@ assert(m_nPos2 >=0 && m_nPos2 < 256); + } + + if(!bMove) + { + // ָָ + m_nPos1 = nOldPos1; + m_nPos2 = nOldPos2; + } + /*@@@ LOGCATCH("Encrypt fail."); exit(3);*/ +} + +template +inline void CEncryptClient::ChangeCode(DWORD dwData) +{ + + DWORD dwData2 = dwData*dwData; + for(int i = 0; i < 256; i += 4) + { + *(DWORD*)(&m_cGlobalEncrypt.m_bufEncrypt1[i]) ^= dwData; + *(DWORD*)(&m_cGlobalEncrypt.m_bufEncrypt2[i]) ^= dwData2; + } + /*LOGCATCH("ChangeCode fail.");*/ +} + + + + + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/SDLDraw.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/SDLDraw.h new file mode 100644 index 0000000..c2bc3d4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/SDLDraw.h @@ -0,0 +1,13 @@ +/* + SDL Ⱦ + create by xiezi + date 2015/8/16 +*/ +#ifndef _SDL_DRAW_H_ +#define _SDL_DRAW_H_ + + + + + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/Turntable.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/Turntable.h new file mode 100644 index 0000000..b1fd641 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/Turntable.h @@ -0,0 +1,7 @@ +#ifndef _ICONBUTTONS_ +void ת̴ڳʼ(char * ); +ACTION* ת̴(); +ACTION* תʾ(); +void ת(int ѡ); +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/VMProtectSDK.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/VMProtectSDK.h new file mode 100644 index 0000000..068899a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/VMProtectSDK.h @@ -0,0 +1,89 @@ +#pragma once + +#ifdef _WIN64 + #pragma comment(lib, "VMProtectSDK64.lib") +#else + #pragma comment(lib, "VMProtectSDK32.lib") +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// protection +__declspec(dllimport) void __stdcall VMProtectBegin(const char *); +__declspec(dllimport) void __stdcall VMProtectBeginVirtualization(const char *); +__declspec(dllimport) void __stdcall VMProtectBeginMutation(const char *); +__declspec(dllimport) void __stdcall VMProtectBeginUltra(const char *); +__declspec(dllimport) void __stdcall VMProtectBeginVirtualizationLockByKey(const char *); +__declspec(dllimport) void __stdcall VMProtectBeginUltraLockByKey(const char *); +__declspec(dllimport) void __stdcall VMProtectEnd(void); + +// utils +__declspec(dllimport) BOOL __stdcall VMProtectIsDebuggerPresent(BOOL); +__declspec(dllimport) BOOL __stdcall VMProtectIsVirtualMachinePresent(void); +__declspec(dllimport) BOOL __stdcall VMProtectIsValidImageCRC(void); +__declspec(dllimport) char * __stdcall VMProtectDecryptStringA(const char *value); +__declspec(dllimport) wchar_t * __stdcall VMProtectDecryptStringW(const wchar_t *value); +__declspec(dllimport) BOOL __stdcall VMProtectFreeString(void *value); + +// licensing +enum VMProtectSerialStateFlags +{ + SERIAL_STATE_FLAG_CORRUPTED = 0x00000001, + SERIAL_STATE_FLAG_INVALID = 0x00000002, + SERIAL_STATE_FLAG_BLACKLISTED = 0x00000004, + SERIAL_STATE_FLAG_DATE_EXPIRED = 0x00000008, + SERIAL_STATE_FLAG_RUNNING_TIME_OVER = 0x00000010, + SERIAL_STATE_FLAG_BAD_HWID = 0x00000020, + SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED = 0x00000040, +}; +#pragma pack(push, 1) +typedef struct +{ + WORD wYear; + BYTE bMonth; + BYTE bDay; +} VMProtectDate; +typedef struct +{ + INT nState; // VMProtectSerialStateFlags + wchar_t wUserName[256]; // user name + wchar_t wEMail[256]; // email + VMProtectDate dtExpire; // date of serial number expiration + VMProtectDate dtMaxBuild; // max date of build, that will accept this key + INT bRunningTime; // running time in minutes + BYTE nUserDataLength; // length of user data in bUserData + BYTE bUserData[255]; // up to 255 bytes of user data +} VMProtectSerialNumberData; + +#pragma pack(pop) +__declspec(dllimport) INT __stdcall VMProtectSetSerialNumber(const char * SerialNumber); +__declspec(dllimport) INT __stdcall VMProtectGetSerialNumberState(); +__declspec(dllimport) BOOL __stdcall VMProtectGetSerialNumberData(VMProtectSerialNumberData *pData, UINT nSize); +__declspec(dllimport) INT __stdcall VMProtectGetCurrentHWID(char * HWID, UINT nSize); + +// activation +enum VMProtectActivationFlags +{ + ACTIVATION_OK = 0, + ACTIVATION_SMALL_BUFFER, + ACTIVATION_NO_CONNECTION, + ACTIVATION_BAD_REPLY, + ACTIVATION_BANNED, + ACTIVATION_CORRUPTED, + ACTIVATION_BAD_CODE, + ACTIVATION_ALREADY_USED, + ACTIVATION_SERIAL_UNKNOWN, + ACTIVATION_EXPIRED +}; + +__declspec(dllimport) INT __stdcall VMProtectActivateLicense(const char *code, char *serial, int size); +__declspec(dllimport) INT __stdcall VMProtectDeactivateLicense(const char *serial); +__declspec(dllimport) INT __stdcall VMProtectGetOfflineActivationString(const char *code, char *buf, int size); +__declspec(dllimport) INT __stdcall VMProtectGetOfflineDeactivationString(const char *serial, char *buf, int size); + + +#ifdef __cplusplus +} +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/action.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/action.h new file mode 100644 index 0000000..6720227 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/action.h @@ -0,0 +1,235 @@ +/************************/ +/* action.h */ +/************************/ +#ifndef _ACTION_H_ +#define _ACTION_H_ + +#include "version.h" +#include "../newproto/autil.h" +//˳ +enum{ + PRIO_TOP, // + + PRIO_CHR, //ͬChar + + PRIO_BG, /* ?? */ + PRIO_JIKI, /* ? */ + PRIO_ENEMY, /* */ + PRIO_ENEMY_TAMA, /* d */ + PRIO_JIKI_TAMA, /* ?d */ + PRIO_ITEM, /* ???? */ + PRIO_BOSS, /* ?? */ + PRIO_GAME_OVER, /* GAME OVER */ + PRIO_BTM = 255 /* ?? */ +}; + +//Action״̬ +enum{ + ACT_STATE_ACT = 0, //ͨ״̬ + ACT_STATE_DEAD //״̬ +}; +// +#define ACT_ATR_HIDE ( 1 << 1 ) // ʾ/* */ +#define ACT_ATR_HIT ( 1 << 2 ) // Աѡ/* ???Re?? */ +#define ACT_ATR_HIT_BOX ( 1 << 3 ) // Աѡ/* ???Re + ???? */ +#define ACT_ATR_INFO ( 1 << 4 ) // ʾѶϢ/* ?????? */ +#define ACT_ATR_HIDE2 ( 1 << 5 ) // ʾ + Աѡ/* +???Re?? */ +#define ACT_ATR_BTL_CMD_END ( 1 << 6 ) // սָ,δһᶯ,򲻻ᶯ/* Pf????V????? */ +#define ACT_ATR_TYPE_PC ( 1 << 7 ) // /* ?? */ +#define ACT_ATR_TYPE_OTHER_PC ( 1 << 8 ) // /* \??? */ +#define ACT_ATR_TYPE_PET ( 1 << 9 ) /* ??? */ +#define ACT_ATR_TYPE_ITEM ( 1 << 10 ) /* ???? */ +#define ACT_ATR_TYPE_GOLD ( 1 << 11 ) /* ?? */ +#define ACT_ATR_TYPE_OTHER ( 1 << 12 ) /* ??\???????Y? */ +#define ACT_ATR_HIT_BOX_ALL1 ( 1 << 13 ) // Աѡ + ʾ1 +#define ACT_ATR_HIT_BOX_ALL2 ( 1 << 14 ) // Աѡ + ʾ2 +#define ACT_ATR_HIT_BOX_ALL3 ( 1 << 15 ) // Աѡ + ʾ3 +#define ACT_ATR_HIT_BOX_ALL4 ( 1 << 16 ) // Աѡ + ʾ3 +#define ACT_ATR_TRAVEL ( 1 << 17 ) /* ??? */ + +#define ACT_ATR_HIT_BOX_COL1 ( 1 << 18 ) // ϵһ +#define ACT_ATR_HIT_BOX_COL2 ( 1 << 19 ) // ϵڶ +#define ACT_ATR_HIT_BOX_COL3 ( 1 << 20 ) // µһ +#define ACT_ATR_HIT_BOX_COL4 ( 1 << 21 ) // µڶ +#define ACT_ATR_HIT_BOX_COL5 ( 1 << 22 ) // ϵһ +#define ACT_ATR_HIT_BOX_COL6 ( 1 << 23 ) // ϵڶ +#define ACT_ATR_HIT_BOX_COL7 ( 1 << 24 ) // µһ +#define ACT_ATR_HIT_BOX_COL8 ( 1 << 25 ) // µڶ + + + + +/* ??????Bl **********************************************************/ +struct action{ + struct action *pPrev, *pNext; //һһactionָ + void ( *func )( struct action * ); //actionִеfunctionָ + void *pYobi; //õstructָ + void *pOther; //;structָ + UCHAR prio; //actionʱ˳ + UCHAR dispPrio; //ͼʱ˳ + int x, y; //ͼ + int hitDispNo; //ǷĿ + BOOL deathFlag; //actionǷ + int dx, dy; //ͼλ + int dir; // + int delta; //ϳ + + char name[ 29 ]; // + char freeName[ 33 ]; //free name + int hp; +#ifdef _PET_ITEM + int iOldHp; +#endif + int maxHp; + int mp; + int maxMp; + int level; + int status; + int itemNameColor; /* ?????q? */ + int charNameColor; // ????????????q? + + int bmpNo; //ͼ + int bmpNo_bak; //ͼ + int atr; // + int state; //״̬ + int actNo; //ж + int damage; + + int gx, gy; //Ŀǰĵͼϵ + int nextGx, nextGy; //һ + int bufGx[10], bufGy[10]; //Ŀǰ굽һ֮buffer + short bufCount; //趨ĿǰҪߵһ + short walkFlag; // ?????????????v????????? + float mx, my; //ͼ + float vx, vy; // ?h? + +// + short earth; // N + short water; // ? N + short fire; // ? N + short wind; // ? N +//raderʹ + int dirCnt; // ??????? +//geminiʹ + int spd; //ƶٶ(0~63)( ?????? ) + int crs; //(0~31)(ϷΪ0,˳ʱӷ) ?( ???? )( ?????? ) + int h_mini; // ?? + int v_mini; // ? +//patternʹ + int anim_chr_no; //ı(anim_tbl.hı) + int anim_chr_no_bak; //һε + int anim_no; //Ķ + int anim_no_bak; //һε + int anim_ang; //ķ(0~7)(0) + int anim_ang_bak; //һεķ + int anim_cnt; //ڼframe + int anim_frame_cnt; //frameͣʱ + int anim_x; //X(Sprbin+Adrnbin) + int anim_y; //Y(Sprbin+Adrnbin) + int anim_hit; // ???Re + // shan add +1 + char fmname[33]; // + // Robin 0728 ride Pet + int onRide; + char petName[16+1]; + int petLevel; + int petHp; + int petMaxHp; + int petDamage; + int petFall; +#ifdef _MIND_ICON + unsigned int sMindIcon; +#endif +#ifdef _SHOWFAMILYBADGE_ + unsigned int sFamilyIcon; +#endif +#ifdef FAMILY_MANOR_ + unsigned int mFamilyIcon; +#endif +#ifdef _CHAR_MANOR_ + unsigned int mManorIcon; +#endif +#ifdef _CHARTITLE_STR_ + TITLE_STR TitleText; +#endif +#ifdef _CHARTITLE_ + unsigned int TitleIcon; +#endif +#ifdef _NPC_EVENT_NOTICE + int noticeNo; +#endif + +#ifdef _SKILL_ROAR + int petRoar; //() +#endif +#ifdef _SKILL_SELFEXPLODE //Ա + int petSelfExplode; +#endif +#ifdef _MAGIC_DEEPPOISION //綾 + int petDeepPoision; +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + int profession_class; +#endif +//#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + int warrioreffect; +//#endif +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + char gm_name[33]; +#endif +#ifdef _STREET_VENDOR + char szStreetVendorTitle[64]; +#endif +#ifdef _NPC_PICTURE + int picture; + int picturetemp; +#endif +#ifdef _PETSKILL_RIDE + int saveride; +#endif +#ifdef _MOUSE_DBL_CLICK + int index; // !! Serverеcharaindex +#endif + +#ifdef _SFUMATO + int sfumato; // Ⱦͼɫ +#endif +}; + +typedef struct action ACTION; + +/* ?????????????????? */ +extern ACTION *pActTop; +extern ACTION *pActBtm; + +/* ?????? */ +extern ACTION *pJiki; + +#ifdef _STONDEBUG_ +/* ?????????? */ +extern int ActCnt; +#endif + +/* ?????????K? *****************************************************/ +ACTION *GetAction( UCHAR prio, UINT yobiSize ); + +/* ??????????? *****************************************************/ +void InitAction( void ); + +/* ????????? *********************************************************/ +void RunAction( void ); + +/* ????????????************************************************/ +void DeathAction( ACTION *pAct ); + +/* u??????? *******************************************************/ +void DeathAllAction( void ); + +/* ???????????u? ***********************************************/ +void ClearAction( ACTION *pAct ); + +/* ???????? *********************************************************/ +void EndAction( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/anim_tbl.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/anim_tbl.h new file mode 100644 index 0000000..769829b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/anim_tbl.h @@ -0,0 +1,2480 @@ +#ifndef _ANIM_TBL_H_ +#define _ANIM_TBL_H_ + +#include "../other/anim_tbl_set.h" + +/*ʯרͼ ӣԣң*/ + +#define CG_DROPWND 35322 //26195ͼ ȷ + +#define CG_PKSERVER_BTN_UP 26193 // ѡȡϵťUp +#define CG_PKSERVER_BTN_DOWN 26194 // ѡȡϵťDown +#define CG_STATUS_DETAIL 26387 // ״̬ϸť +#define CG_AUCWND_DETAIL 26381 // ϸӴ +#define CG_AUCWND_MESSAGE 26382 // ѶϢӴ +#define CG_AUCWND_COLUMN 26383 // ר +#define CG_AUCWND_CHANGE 26384 // Ӵ +#define CG_AUCWND_DETAIL2 26385 // ϸӴ2 + +#define CG_BATTLE_ATT_DOWN 26361 // սťDown +#define CG_BATTLE_ATT_UP 26362 // սťUp +#define CG_BATTLE_HELP_DOWN 26363 // սťDown +#define CG_BATTLE_HELP_UP 26364 // սťUp +#define CG_BATTLE_DEF_DOWN 26365 // սťDown +#define CG_BATTLE_DEF_UP 26366 // սťUp +#define CG_BATTLE_JUJUTSU_DOWN 26367 // սťDown +#define CG_BATTLE_JUJUTSU_UP 26368 // սťUp +#define CG_BATTLE_PANEL 26369 // սװ +#define CG_BATTLE_ESCAPE_DOWN 26370 // սťDown +#define CG_BATTLE_ESCAPE_UP 26371 // սťUp +#define CG_BATTLE_PET_DOWN 26372 // սťDown +#define CG_BATTLE_PET_UP 26373 // սťUp +#define CG_BATTLE_CAPTURE_DOWN 26374 // ս׽ťDown +#define CG_BATTLE_CAPTURE_UP 26375 // ս׽ťUp +#define CG_BATTLE_ITEM_DOWN 26376 // սťDown +#define CG_BATTLE_ITEM_UP 26377 // սťUp +#define CG_BATTLE_PROSKL_DOWN 26378 // սťDown +#define CG_BATTLE_PROSKL_UP 26379 // սťUp + +#define CG_FIELD_SKILL_TILE 26354 // ְҵܵװ +#define CG_FIELD_SKILL_ADVSK 26355 // ְҵܽ׼ť +#define CG_FIELD_SKILL_BATTLE 26357 // ְҵܽսť +#define CG_FIELD_SKILL_ASSIT 26356 // ְҵܽ渨ť + +#define CG_FIELD_SKILL_MENU 26358 // ϰť +#define CG_FIELD_SKILL_BTN_OFF 26360 // ְҵťOFF +#define CG_FIELD_SKILL_BTN_ON 26361 // ְҵťON + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ +#define CG_FIELD_CHATROOM_BTN_ON 26453 //ϰť +#define CG_FIELD_CHATROOM_BTN_OFF 26454 //ϰť +#define CG_FIELD_CLOSE_BTN_UP 26444 //ҹرհť +#define CG_FIELD_CLOSE_BTN_DOWN 26445 //ҹرհť +#define CG_FIELD_CHANGECHIEF_BTN_UP 26435 //Ҹҳť +#define CG_FIELD_CHANGECHIEF_BTN_DOWN 26436 //Ҹҳť +#define CG_FIELD_CHANGECHIEF_BTN_DISABLE 26437 //Ҹҳť +#define CG_FIELD_OUTMEMBER_BTN_UP 26432 // +#define CG_FIELD_OUTMEMBER_BTN_DOWN 26433 // +#define CG_FIELD_OUTMEMBER_BTN_DISABLE 26434 // +#define CG_FIELD_LEAVE_BTN_UP 26441 //뿪ť +#define CG_FIELD_LEAVE_BTN_DOWN 26442 //뿪ť +#define CG_FIELD_DELETE_BTN_UP 26438 //ɾ +#define CG_FIELD_DELETE_BTN_DOWN 26439 //ɾ +#define CG_FIELD_DELETE_BTN_DISABLE 26440 //ɾ +#define CG_FIELD_AGREE_BTN 26091 //ͬⰴť +#define CG_FIELD_DISAGREE_BTN 26092 //񶨰ť +#define CG_FIELD_CHANNEL_MENU 26452 //ϰť +#define CG_FIELD_CHANNEL_SCROLL 26447 // +#define CG_FIELD_SCROLL_HUP 26448 // +#define CG_FIELD_SCROLL_HDOWN 26449 // +#define CG_FIELD_SCROLL_LUP 26450 // +#define CG_FIELD_SCROLL_LDOWN 26451 // +#endif + +#ifdef _STREET_VENDOR +#define CG_FIELD_SV_BTN_OFF 35227 // ϰ̯ܰ() +#define CG_FIELD_SV_BTN_ON 35226 // ϰ̯ܰ() +#define CG_FIELD_SV_BUY_PANEL 35240 // ̯() +#endif + +#ifdef _TEACHER_SYSTEM +#define CG_FIELD_TS_BTN_OFF 28555 // еʦܰ() +#define CG_FIELD_TS_BTN_ON 28554 // еʦܰ() +#define CG_FIELD_TS_LEFT_MENU 28553 +#endif + +#ifdef _TIMEBAR_FUNCTION //ʱBARʽ +#define CG_TIMEBAR_PANEL 26350 //ʱbarĿ +#define CG_TIMEBAR_UNIT 26428 //ʱĵλ +#endif + +#ifdef _NEWPANEL //Syu ADD 7.0 ״̬ +#define CG_NEW_STATUS_SKILL_BTN_UP 26312 +#ifdef _MAG_MENU +#define CG_SKILL_TABLE 26473 +#else +#define CG_SKILL_TABLE 26380 +#endif +#define CG_WAR_ICON_BIG 29281 +#define CG_WIZ_ICON_BIG 29282 +#define CG_HUNTER_ICON_BIG 29283 +#define CG_WAR_ICON_SMALL 29284 +#define CG_WIZ_ICON_SMALL 29285 +#define CG_HUNTER_ICON_SMALL 29286 +#endif + +//#define CG_NEWITEM_WND 26349 // װλӴ(֡) +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +#define CG_TRADE_SEAL 26330 // ӡ +#define CG_TRADE_SCROLL_UP 26331 // ׾ϼͷ +#define CG_TRADE_SCROLL_DOWN 26332 // ׾¼ͷ +#define CG_TRADE_SCROLL_BTN 26333 // ׾ҷť +#define CG_TRADE_DEF_LINE 26334 // Ӵ +#define CG_TRADE_LV_LINE 26335 // Ӵȼ +#define CG_TRADE_LINE 26336 // Ӵ +#define CG_TRADE_DEX_LINE 26337 // Ӵٶ +#define CG_TRADE_ATK_LINE 26338 // Ӵ +#define CG_TRADE_SK1_LINE 26339 // Ӵܣ +#define CG_TRADE_SK2_LINE 26340 // Ӵܣ +#define CG_TRADE_SK3_LINE 26341 // Ӵܣ +#define CG_TRADE_SK4_LINE 26342 // Ӵܣ +#define CG_TRADE_SK5_LINE 26343 // Ӵܣ +#define CG_TRADE_SK6_LINE 26344 // Ӵܣ +#define CG_TRADE_SK7_LINE 26345 // Ӵܣ +#define CG_TRADE_HP_LINE 26346 // ӴѪ +#define CG_TRADE_VIEW_BTN 26347 // Ӵť +#define CG_TRADE_BACK_BTN 26348 // Ӵť +#define CG_TRADE_TALK_WND 26350 // ׶ԻӴ +#endif + +/* +#define CG_BATTLE_ANGRY 26521 +#define CG_BATTLE_CRAZY 26520 +#define CG_BATTLE_GUARD 26519 +#define CG_BATTLE_ATTPET 26518 +#define CG_BATTLE_FORGOT 26517 +#define CG_BATTLE_CAPTURE_UP 26516 +*/ +/* +#define SPR_bloodbug 101623 //Ѫ ( Wiz ) +#define SPR_bthunder 101624 // ( Wiz ) +#define SPR_bugnet 101625 //ѱ ( Hunter ) +#define SPR_lightning 101626 // ( War ) +#define SPR_redsmoke 101627 // ( ) +#define SPR_sthunder 101628 // ( Wiz ) +#define SPR_track 101629 //׷Ѱ ( Hunter ) +#define SPR_trap 101630 // ( Hunter ) +#define SPR_shieldattack 101631 //ܻ ( War ) +#define SPR_shieldattack2 101632 //ܻ ( War ) ҷ +#define SPR_bloodsucker 101633 //һѪ ( Wiz ) +#define SPR_bstorm 101634 // ( Wiz ) ұ +#define SPR_bstorm2 101635 // ( Wiz ) +#define SPR_concentrate 101636 //רעս ( War ) +#define SPR_deadattach 101637 // ( War ) +#define SPR_dodge 101638 //ر ( War ) +#define SPR_doom 101639 //ĩ ( Wiz ) ҷ +#define SPR_doom2 101640 //ĩ ( Wiz ) +#define SPR_dragonbreath 101641 //ǹ ( Wiz ) +#define SPR_dragonbreath2 101642 //ǹ ( Wiz ) ҷ +#define SPR_encloseghost 101643 // ( Wiz ) ҷ +#define SPR_encloseghost2 101644 // ( Wiz ) +#define SPR_energycollect 101645 //ۼ ( War ) +#define SPR_fireresist1 101646 //濹 ( Hunter ) ų +#define SPR_fireresist2 101647 //濹 ( Hunter ) +#define SPR_icearrow 101648 // ( Wiz ) +#define SPR_icearrow2 101649 // ( Wiz ) ҷ +#define SPR_iceexplode 101650 // ( Wiz ) ҷ +#define SPR_iceexplode2 101651 // ( Wiz ) +#define SPR_icemirror 101652 // ( Wiz ) +#define SPR_iceresist1 101653 // ( Hunter ) ų +#define SPR_iceresist2 101654 // ( Hunter ) +#define SPR_lgyration 101655 // ( War ) +#define SPR_lgyration1 101656 // ( War ) +#define SPR_lgyration2 101657 // ( War ) ǰ +#define SPR_lightresist1 101658 //翹 ( Hunter ) ų +#define SPR_lightresist2 101659 //翹 ( Hunter ) +#define SPR_lpentrate1 101660 //ᴩ ( War ) ҷķ +#define SPR_lpentrate2 101661 //ᴩ ( War ) +#define SPR_lpentrate3 101662 //ᴩ ( War ) +#define SPR_lpentrate4 101663 //ᴩ ( War ) +#define SPR_lpentrate5 101664 //ᴩ ( War ) +#define SPR_lpentrate6 101665 //ᴩ ( War ) +#define SPR_poisonresist1 101666 //綾 ( Hunter ) ų +#define SPR_poisonresist2 101667 //綾 ( Hunter ) +#define SPR_rgyration 101668 // ( War ) +#define SPR_rgyration1 101669 // ( War ) +#define SPR_rgyration2 101670 // ( War ) +#define SPR_rpentrate1 101671 //ᴩ ( War ) 󷽵ķ +#define SPR_rpentrate2 101672 //ᴩ ( War ) +#define SPR_rpentrate3 101673 //ᴩ ( War ) +#define SPR_rpentrate4 101674 //ᴩ ( War ) +#define SPR_rpentrate5 101675 //ᴩ ( War ) +#define SPR_rpentrate6 101676 //ᴩ ( War ) +#define SPR_storm 101677 //ѩ ( Wiz ) ҷ +#define SPR_storm2 101678 //ѩ ( Wiz ) +#define SPR_violent 101679 // ( War ) +#define SPR_waterdrop 101680 //ˮ״̬ +#define SPR_weakness 101681 //㹥 ( Hunter ) +#define SPR_root 101682 // ( Hunter ) +#define SPR_net 101683 //޵ ( Hunter ) +#define SPR_boomattack 101684 // ( War ) +#define SPR_superthunder 101685 // Lv10 ( Wiz ) +#define SPR_volspring1 101686 //ɽȪ ( Wiz ) +#define SPR_volspring2 101687 //ɽȪ ( Wiz ) +#define SPR_volspring3 101688 //ɽȪ ( Wiz ) +#define SPR_bloodthirsty1 101689 //Ѫ Lv10 ( Wiz ) +#define SPR_bloodthirsty2 101690 //Ѫ Lv7 ( Wiz ) +#define SPR_bloodthirsty3 101691 //Ѫ Lv4 ( Wiz ) +#define SPR_bloodthirsty4 101692 //Ѫ Lv1 ( Wiz ) +#define SPR_lfireplanet 101693 // ( Wiz ) +#define SPR_rfireplanet 101694 // ( Wiz ) ҷ +#define SPR_tree 101695 //λλ ( Wiz ) +#define SPR_trap1 101696 // +#define SPR_wizuse 101697 //ʦʹ +#define SPR_hunteruse 101698 //ʹ +#define SPR_fireattack 101699 //幥 +#define SPR_iceattack 101700 //幥 +#define SPR_lightattack 101701 //׸幥 +101705 ˮ +101706 纣 +101707 ˮ𺣲 +101708 غ +101709 ط +101710 +101711 ˮ׾ +101712 ˮ׾ +101713 شè +101714 è +101715 ˮ ( δ ) +101716 纣 ( δ ) +101717 սʿ +101718 ˮսʿ +101719 Сè +101720 ˮСè +101721 ͷ +101722 ͷ +101723 ɡ ( δ ) +101724 ˮɡ ( δ ) +101725 ʨӵˮ +101726 ʨˮ +101727 ʨӻ +101728 ʨӷ +101729 +*/ +/*ʯרͼ ţΣ */ + + + +#define SPRSTART 100000 // SPR???????k? +// ??? +#define SPR_001em 100000 // ?i? +#define SPR_001ax 100001 // ? +#define SPR_001cl 100002 // ??S +#define SPR_001sp 100003 // ? +#define SPR_001bw 100004 // ? + +#define SPR_002em 100005 // ?i? +#define SPR_002ax 100006 // ? +#define SPR_002cl 100007 // ??S +#define SPR_002sp 100008 // ? +#define SPR_002bw 100009 // ? + +#define SPR_003em 100010 // ?i? +#define SPR_003ax 100011 // ? +#define SPR_003cl 100012 // ??S +#define SPR_003sp 100013 // ? +#define SPR_003bw 100014 // ? + +#define SPR_004em 100015 // ?i? +#define SPR_004ax 100016 // ? +#define SPR_004cl 100017 // ??S +#define SPR_004sp 100018 // ? +#define SPR_004bw 100019 // ? + +#define SPR_011em 100020 // g? +#define SPR_011ax 100021 // ? +#define SPR_011cl 100022 // ??S +#define SPR_011sp 100023 // ? +#define SPR_011bw 100024 // ? + +#define SPR_012em 100025 // g? +#define SPR_012ax 100026 // ? +#define SPR_012cl 100027 // ??S +#define SPR_012sp 100028 // ? +#define SPR_012bw 100029 // ? + +#define SPR_013em 100030 // g? +#define SPR_013ax 100031 // ? +#define SPR_013cl 100032 // ??S +#define SPR_013sp 100033 // ? +#define SPR_013bw 100034 // ? + +#define SPR_014em 100035 // g? +#define SPR_014ax 100036 // ? +#define SPR_014cl 100037 // ??S +#define SPR_014sp 100038 // ? +#define SPR_014bw 100039 // ? + +#define SPR_021em 100040 // g? +#define SPR_021ax 100041 // ? +#define SPR_021cl 100042 // ??S +#define SPR_021sp 100043 // ? +#define SPR_021bw 100044 // ? + +#define SPR_022em 100045 +#define SPR_022ax 100046 +#define SPR_022cl 100047 +#define SPR_022sp 100048 +#define SPR_022bw 100049 + +#define SPR_023em 100050 +#define SPR_023ax 100051 +#define SPR_023cl 100052 +#define SPR_023sp 100053 +#define SPR_023bw 100054 + +#define SPR_024em 100055 +#define SPR_024ax 100056 +#define SPR_024cl 100057 +#define SPR_024sp 100058 +#define SPR_024bw 100059 + +#define SPR_031em 100060 // g? +#define SPR_031ax 100061 // ? +#define SPR_031cl 100062 // ??S +#define SPR_031sp 100063 // ? +#define SPR_031bw 100064 // ? + +#define SPR_032em 100065 +#define SPR_032ax 100066 +#define SPR_032cl 100067 +#define SPR_032sp 100068 +#define SPR_032bw 100069 + +#define SPR_033em 100070 +#define SPR_033ax 100071 +#define SPR_033cl 100072 +#define SPR_033sp 100073 +#define SPR_033bw 100074 + +#define SPR_034em 100075 +#define SPR_034ax 100076 +#define SPR_034cl 100077 +#define SPR_034sp 100078 +#define SPR_034bw 100079 + +#define SPR_041em 100080 // g? +#define SPR_041ax 100081 // ? +#define SPR_041cl 100082 // ??S +#define SPR_041sp 100083 // ? +#define SPR_041bw 100084 // ? + +#define SPR_042em 100085 +#define SPR_042ax 100086 +#define SPR_042cl 100087 +#define SPR_042sp 100088 +#define SPR_042bw 100089 + +#define SPR_043em 100090 +#define SPR_043ax 100091 +#define SPR_043cl 100092 +#define SPR_043sp 100093 +#define SPR_043bw 100094 + +#define SPR_044em 100095 +#define SPR_044ax 100096 +#define SPR_044cl 100097 +#define SPR_044sp 100098 +#define SPR_044bw 100099 + +#define SPR_051em 100100 // g? +#define SPR_051ax 100101 // ? +#define SPR_051cl 100102 // ??S +#define SPR_051sp 100103 // ? +#define SPR_051bw 100104 // ? + +#define SPR_052em 100105 +#define SPR_052ax 100106 +#define SPR_052cl 100107 +#define SPR_052sp 100108 +#define SPR_052bw 100109 + +#define SPR_053em 100110 +#define SPR_053ax 100111 +#define SPR_053cl 100112 +#define SPR_053sp 100113 +#define SPR_053bw 100114 + +#define SPR_054em 100115 +#define SPR_054ax 100116 +#define SPR_054cl 100117 +#define SPR_054sp 100118 +#define SPR_054bw 100119 + +#define SPR_061em 100120 // ??? +#define SPR_061ax 100121 // ? +#define SPR_061cl 100122 // ??S +#define SPR_061sp 100123 // ? +#define SPR_061bw 100124 // ? + +#define SPR_062em 100125 +#define SPR_062ax 100126 +#define SPR_062cl 100127 +#define SPR_062sp 100128 +#define SPR_062bw 100129 + +#define SPR_063em 100130 +#define SPR_063ax 100131 +#define SPR_063cl 100132 +#define SPR_063sp 100133 +#define SPR_063bw 100134 + +#define SPR_064em 100135 +#define SPR_064ax 100136 +#define SPR_064cl 100137 +#define SPR_064sp 100138 +#define SPR_064bw 100139 + +#define SPR_071em 100140 // ??? +#define SPR_071ax 100141 // ? +#define SPR_071cl 100142 // ??S +#define SPR_071sp 100143 // ? +#define SPR_071bw 100144 // ? + +#define SPR_072em 100145 +#define SPR_072ax 100146 +#define SPR_072cl 100147 +#define SPR_072sp 100148 +#define SPR_072bw 100149 + +#define SPR_073em 100150 +#define SPR_073ax 100151 +#define SPR_073cl 100152 +#define SPR_073sp 100153 +#define SPR_073bw 100154 + +#define SPR_074em 100155 +#define SPR_074ax 100156 +#define SPR_074cl 100157 +#define SPR_074sp 100158 +#define SPR_074bw 100159 + +#define SPR_081em 100160 // ?? +#define SPR_081ax 100161 // ? +#define SPR_081cl 100162 // ??S +#define SPR_081sp 100163 // ? +#define SPR_081bw 100164 // ? + +#define SPR_082em 100165 +#define SPR_082ax 100166 +#define SPR_082cl 100167 +#define SPR_082sp 100168 +#define SPR_082bw 100169 + +#define SPR_083em 100170 +#define SPR_083ax 100171 +#define SPR_083cl 100172 +#define SPR_083sp 100173 +#define SPR_083bw 100174 + +#define SPR_084em 100175 +#define SPR_084ax 100176 +#define SPR_084cl 100177 +#define SPR_084sp 100178 +#define SPR_084bw 100179 + +#define SPR_091em 100180 // ?? +#define SPR_091ax 100181 // ? +#define SPR_091cl 100182 // ??S +#define SPR_091sp 100183 // ? +#define SPR_091bw 100184 // ? + +#define SPR_092em 100185 +#define SPR_092ax 100186 +#define SPR_092cl 100187 +#define SPR_092sp 100188 +#define SPR_092bw 100189 + +#define SPR_093em 100190 +#define SPR_093ax 100191 +#define SPR_093cl 100192 +#define SPR_093sp 100193 +#define SPR_093bw 100194 + +#define SPR_094em 100195 +#define SPR_094ax 100196 +#define SPR_094cl 100197 +#define SPR_094sp 100198 +#define SPR_094bw 100199 + +#define SPR_101em 100200 // ?? +#define SPR_101ax 100201 // ? +#define SPR_101cl 100202 // ??S +#define SPR_101sp 100203 // ? +#define SPR_101bw 100204 // ? + +#define SPR_102em 100205 +#define SPR_102ax 100206 +#define SPR_102cl 100207 +#define SPR_102sp 100208 +#define SPR_102bw 100209 + +#define SPR_103em 100210 +#define SPR_103ax 100211 +#define SPR_103cl 100212 +#define SPR_103sp 100213 +#define SPR_103bw 100214 + +#define SPR_104em 100215 +#define SPR_104ax 100216 +#define SPR_104cl 100217 +#define SPR_104sp 100218 +#define SPR_104bw 100219 + +#define SPR_111em 100220 // ?? +#define SPR_111ax 100221 // ? +#define SPR_111cl 100222 // ??S +#define SPR_111sp 100223 // ? +#define SPR_111bw 100224 // ? + +#define SPR_112em 100225 +#define SPR_112ax 100226 +#define SPR_112cl 100227 +#define SPR_112sp 100228 +#define SPR_112bw 100229 + +#define SPR_113em 100230 +#define SPR_113ax 100231 +#define SPR_113cl 100232 +#define SPR_113sp 100233 +#define SPR_113bw 100234 + +#define SPR_114em 100235 +#define SPR_114ax 100236 +#define SPR_114cl 100237 +#define SPR_114sp 100238 +#define SPR_114bw 100239 + + +// ???????? +#define SPR_pet001 100250 // ??? +#define SPR_pet002 100251 // ???? +#define SPR_pet003 100252 // ?????? +#define SPR_pet004 100253 // ???? + +#define SPR_pet011 100254 // ???? +#define SPR_pet012 100255 // ??????? +#define SPR_pet013 100256 // ??? +#define SPR_pet014 100257 // ????? +#define SPR_pet015 100258 // ???? + +#define SPR_pet021 100259 // ???? +#define SPR_pet022 100260 // ???? +#define SPR_pet023 100261 // ???? +#define SPR_pet024 100262 // ???? + +#define SPR_pet031 100263 // ??? +#define SPR_pet032 100264 // ???? +#define SPR_pet033 100265 // ???? +#define SPR_pet034 100266 // ???? + +#define SPR_pet041 100267 // ???? +#define SPR_pet042 100268 // ????? +#define SPR_pet043 100269 // ?????? +#define SPR_pet044 100270 // ???? + +#define SPR_pet051 100271 // ????? +#define SPR_pet052 100272 // ??? +#define SPR_pet053 100273 // ???? +#define SPR_pet054 100274 // ???? + +#define SPR_pet061 100275 // ??? +#define SPR_pet062 100276 // ???? +#define SPR_pet063 100277 // ???? +#define SPR_pet064 100278 // ???? + +#define SPR_pet071 100279 // ???? +#define SPR_pet072 100280 // ??? +#define SPR_pet073 100281 // ????? +#define SPR_pet074 100282 // ???? + +#define SPR_pet081 100283 // ???? +#define SPR_pet082 100284 // ????? +#define SPR_pet083 100285 // ???? +#define SPR_pet084 100286 // ????? + +#define SPR_pet091 100287 // ????? +#define SPR_pet092 100288 // ????? +#define SPR_pet093 100289 // ????? +#define SPR_pet094 100290 // ????? + +#define SPR_pet101 100291 // ??? +#define SPR_pet102 100292 // ??? +#define SPR_pet103 100293 // ???? +#define SPR_pet104 100294 // ???? + +#define SPR_pet111 100295 // ???? +#define SPR_pet112 100296 // ???? +#define SPR_pet113 100297 // ???? +#define SPR_pet114 100298 // ????? + +#define SPR_pet121 100299 // ?? +#define SPR_pet122 100300 // ?? +#define SPR_pet123 100301 // ?? +#define SPR_pet124 100302 // ?? + +#define SPR_pet131 100303 // ?? +#define SPR_pet132 100304 // ?? +#define SPR_pet133 100305 // ?? +#define SPR_pet134 100306 // ?? + +#define SPR_pet141 100307 // ???? +#define SPR_pet142 100308 // ???? +#define SPR_pet143 100309 // ?????? +#define SPR_pet144 100310 // ???? + +#define SPR_pet151 100311 // ?? +#define SPR_pet152 100312 // ?? +#define SPR_pet153 100313 // ?? +#define SPR_pet154 100314 // ?? + +#define SPR_pet161 100315 // ?? +#define SPR_pet162 100316 // ?? +#define SPR_pet163 100317 // ?? +#define SPR_pet164 100318 // ?? + +#define SPR_pet171 100319 // ???? +#define SPR_pet172 100320 // ???? +#define SPR_pet173 100321 // ???? +#define SPR_pet174 100322 // ????? + +#define SPR_pet181 100323 // ???? +#define SPR_pet182 100324 // ???? +#define SPR_pet183 100325 // ??? +#define SPR_pet184 100326 // ???? + +#define SPR_pet191 100327 // ???? +#define SPR_pet192 100328 // ????? +#define SPR_pet193 100329 // ???? +#define SPR_pet194 100330 // ??????? + +#define SPR_pet201 100331 // ?? +#define SPR_pet202 100332 // ?? +#define SPR_pet203 100333 // ?? +#define SPR_pet204 100334 // ?? + +#define SPR_pet211 100335 // ????? +#define SPR_pet212 100336 // ???? +#define SPR_pet213 100337 // ????? +#define SPR_pet214 100338 // ???? + +#define SPR_pet221 100339 // ????? +#define SPR_pet222 100340 // ???? +#define SPR_pet223 100341 // ???? +#define SPR_pet224 100342 // ???? + +#define SPR_pet231 100343 // ???? +#define SPR_pet232 100344 // ??? +#define SPR_pet233 100345 // ????? +#define SPR_pet234 100346 // ????? + +#define SPR_pet241 100347 // ???? +#define SPR_pet242 100348 // ???? +#define SPR_pet243 100349 // ???? +#define SPR_pet244 100350 // ????? + +#define SPR_pet251 100351 // ????? +#define SPR_pet252 100352 // ????? +#define SPR_pet253 100353 // ????? +#define SPR_pet254 100354 // ????? + +#define SPR_pet261 100355 // ???? +#define SPR_pet262 100356 // ??? +#define SPR_pet263 100357 // ???? +#define SPR_pet264 100358 // ????? + +#define SPR_pet271 100359 // ???? +#define SPR_pet272 100360 // ???? +#define SPR_pet273 100361 // ????? +#define SPR_pet274 100362 // ???? + +#define SPR_pet281 100363 // ?? +#define SPR_pet282 100364 // ?? +#define SPR_pet283 100365 // ?? +#define SPR_pet284 100366 // ?? + +#define SPR_pet291 100367 // ???? +#define SPR_pet292 100368 // ???? +#define SPR_pet293 100369 // ???? +#define SPR_pet294 100370 // ????? + +#define SPR_pet301 100371 // ???? +#define SPR_pet302 100372 // ????? +#define SPR_pet303 100373 // ???? +#define SPR_pet304 100374 // ????? + +#define SPR_pet311 100375 // ??? +#define SPR_pet312 100376 // ????? +#define SPR_pet313 100377 // ????? +#define SPR_pet314 100378 // ????? + +#define SPR_pet321 100379 // ?????? +#define SPR_pet322 100380 // ???? +#define SPR_pet323 100381 // ????? +#define SPR_pet324 100382 // ????? +#define SPR_pet325 100383 // ???? + +#define SPR_pet331 100384 // ????? +#define SPR_pet332 100385 // ????? +#define SPR_pet333 100386 // ????? +#define SPR_pet334 100387 // ?????? + +// ?D???? +#define SPR_pet005 100388 // ?? +#define SPR_pet085 100389 // ?????? +#define SPR_pet086 100390 // ???? +#define SPR_pet087 100391 // ????????? +#define SPR_pet088 100392 // ?????????? +#define SPR_pet065 100393 // ?N??? +#define SPR_pet095 100394 // ?N????? +#define SPR_pet175 100395 // ?N???? +#define SPR_pet255 100396 // ?N????? + +// ?D????????? +#define SPR_121em 100400 // ???? +#define SPR_121ax 100401 // ? +#define SPR_121cl 100402 // ?S +#define SPR_121sp 100403 // ? +#define SPR_121bw 100404 // ? + +#define SPR_122em 100405 // ???? +#define SPR_122ax 100406 // ? +#define SPR_122cl 100407 // ?S +#define SPR_122sp 100408 // ? +#define SPR_122bw 100409 // ? + +#define SPR_123em 100410 // ???? +#define SPR_123ax 100411 // ? +#define SPR_123cl 100412 // ?S +#define SPR_123sp 100413 // ? +#define SPR_123bw 100414 // ? + +#define SPR_124em 100415 // ???? +#define SPR_124ax 100416 // ? +#define SPR_124cl 100417 // ?S +#define SPR_124sp 100418 // ? +#define SPR_124bw 100419 // ? + +#define SPR_131em 100420 // ???? +#define SPR_131ax 100421 // ? +#define SPR_131cl 100422 // ?S +#define SPR_131sp 100423 // ? +#define SPR_131bw 100424 // ? + +#define SPR_132em 100425 // ???? +#define SPR_132ax 100426 // ? +#define SPR_132cl 100427 // ?S +#define SPR_132sp 100428 // ? +#define SPR_132bw 100429 // ? + +#define SPR_pet315 100430 // ?????? + +#define SPR_141em 100431 // ????? +#define SPR_141ax 100432 // ? +#define SPR_141cl 100433 // ?S +#define SPR_141sp 100434 // ? +#define SPR_141bw 100435 // ? + +#define SPR_142em 100436 // ????? +#define SPR_142ax 100437 // ? +#define SPR_142cl 100438 // ?S +#define SPR_142sp 100439 // ? +#define SPR_142bw 100440 // ? + +#define SPR_133em 100441 // ???? +#define SPR_133ax 100442 // ? +#define SPR_133cl 100443 // ?S +#define SPR_133sp 100444 // ? +#define SPR_133bw 100445 // ? + +#define SPR_151em 100446 // ??? +#define SPR_151ax 100447 // ? +#define SPR_151cl 100448 // ??S +#define SPR_151sp 100449 // ? +#define SPR_151bw 100450 // ? + +#define SPR_152em 100451 +#define SPR_152ax 100452 +#define SPR_152cl 100453 +#define SPR_152sp 100454 +#define SPR_152bw 100455 + +#define SPR_161em 100456 // ??? +#define SPR_161ax 100457 // ? +#define SPR_161cl 100458 // ??S +#define SPR_161sp 100459 // ? +#define SPR_161bw 100460 // ? + +#define SPR_162em 100461 +#define SPR_162ax 100462 +#define SPR_162cl 100463 +#define SPR_162sp 100464 +#define SPR_162bw 100465 + +//? ?? ????? +#define SPR_mwood1 100466 +#define SPR_mwood2 100467 +#define SPR_mwood3 100468 +#define SPR_mstone1 100469 +#define SPR_mstone2 100470 +#define SPR_mstone3 100471 + +//???????? +#define SPR_leader 100500 // ?????????????? +#define SPR_star 100501 // ??????????? +#define SPR_boomerang 100502 // ????????????? +#define SPR_stonebomb 100503 // ?????????? +#define SPR_ono 100504 // ?????????? +#define SPR_onokage 100505 // ????????????? +#define SPR_isiware 100506 // ????????? +#define SPR_mail 100507 // ??????????? +//????? +#define SPR_stone 100550 // ?????? +#define SPR_shock 100551 // ??????? +#define SPR_drunk 100552 // ??????? +#define SPR_sleep 100553 // ?????? +#define SPR_conf 100554 // ??????? +#define SPR_poison 100555 // ????? +#define SPR_zokusei 100556 // Nͨ?????? +#ifdef _MAGIC_WEAKEN +#define SPR_weaken 101420 // +#endif +#ifdef _MAGIC_DEEPPOISION +#define SPR_deeppoison 101417 //綾 +#endif +#ifdef _MAGIC_BARRIER +#define SPR_barrier 101421 //ħ +#endif +#ifdef _MAGIC_NOCAST +#define SPR_nocast 101419 //Ĭ +#endif + +//ǿ +#define SPR_all_att 101406 //ȫ +#define SPR_land_att 101403 // +#define SPR_water_att 101404 //ˮ +#define SPR_fire_att 101402 // +#define SPR_wind_att 101405 // +//ת +//#define SPR_all_att 101406 //ȫ +#define SPR_ch_earth 101408 // +#define SPR_ch_water 101409 //ˮ +#define SPR_ch_fire 101407 // +#define SPR_ch_wind 101410 // + +#define SPR_tooth 101415 // +#define SPR_mic_def 101411 //ħ +#define SPR_ironwall 101416 // +#define SPR_bomb 101418 //Ա + +#ifdef _MIND_ICON +#define SPR_heart 101296 +#define SPR_broken 101297 +#define SPR_m_clip 101300 +#define SPR_m_stone 101301 +#define SPR_m_burlap 101302 +#define SPR_screamer 101299 +#define SPR_question_mark 101289 +#define SPR_cramp 101292 +#define SPR_black_squall 101293 +#define SPR_perspiration 101298 +#define SPR_silence 101291 +#define SPR_asleep 101290 +#define SPR_cafe 101294 +#define SPR_lightbulb 101295 +#define SPR_accent 101288 +#define SPR_money 101303 +#define SPR_pk 101304 +#endif +//???????????? +#define SPR_effect01 100600 // ??????? +//#define SPR_heal 100601 // ???????????? +#define SPR_heal 100601 // ???????????? +#define SPR_heal2 100602 // ???????????? +#define SPR_heal3 100603 // ???????????? +#define SPR_tyusya 100604 // ????????????????? +#define SPR_hoshi 100605 // ???????????????? +#define SPR_kyu 100606 // ??????????????????????? +#define SPR_fukkatu1 100607 // ????????????????????? +#define SPR_fukkatu2 100608 // ????????????????????? +#define SPR_fukkatu3 100609 // ????????????????????? +#define SPR_difence 100610 // \?????????????????? +#define SPR_item 100611 // ?????????????????? +#define SPR_item3 100612 // ?????????????????? +//\????????? +#define SPR_mirror 100650 // T??????? +#define SPR_barrior 100651 // ?????????? +#define SPR_kyusyu 100652 // ????????????? + +#define SPR_005em 100700 +#define SPR_005ax 100701 +#define SPR_005cl 100702 +#define SPR_005sp 100703 +#define SPR_005bw 100704 + +#define SPR_006em 100705 +#define SPR_006ax 100706 +#define SPR_006cl 100707 +#define SPR_006sp 100708 +#define SPR_006bw 100709 + +#define SPR_015em 100710 +#define SPR_015ax 100711 +#define SPR_015cl 100712 +#define SPR_015sp 100713 +#define SPR_015bw 100714 + +#define SPR_016em 100715 +#define SPR_016ax 100716 +#define SPR_016cl 100717 +#define SPR_016sp 100718 +#define SPR_016bw 100719 + +#define SPR_025em 100720 +#define SPR_025ax 100721 +#define SPR_025cl 100722 +#define SPR_025sp 100723 +#define SPR_025bw 100724 + +#define SPR_026em 100725 +#define SPR_026ax 100726 +#define SPR_026cl 100727 +#define SPR_026sp 100728 +#define SPR_026bw 100729 + +#define SPR_035em 100730 +#define SPR_035ax 100731 +#define SPR_035cl 100732 +#define SPR_035sp 100733 +#define SPR_035bw 100734 + +#define SPR_036em 100735 +#define SPR_036ax 100736 +#define SPR_036cl 100737 +#define SPR_036sp 100738 +#define SPR_036bw 100739 + +#define SPR_045em 100740 +#define SPR_045ax 100741 +#define SPR_045cl 100742 +#define SPR_045sp 100743 +#define SPR_045bw 100744 + +#define SPR_046em 100745 +#define SPR_046ax 100746 +#define SPR_046cl 100747 +#define SPR_046sp 100748 +#define SPR_046bw 100749 + +#define SPR_055em 100750 +#define SPR_055ax 100751 +#define SPR_055cl 100752 +#define SPR_055sp 100753 +#define SPR_055bw 100754 + +#define SPR_056em 100755 +#define SPR_056ax 100756 +#define SPR_056cl 100757 +#define SPR_056sp 100758 +#define SPR_056bw 100759 + +#define SPR_065em 100760 +#define SPR_065ax 100761 +#define SPR_065cl 100762 +#define SPR_065sp 100763 +#define SPR_065bw 100764 + +#define SPR_066em 100765 +#define SPR_066ax 100766 +#define SPR_066cl 100767 +#define SPR_066sp 100768 +#define SPR_066bw 100769 + +#define SPR_075em 100770 +#define SPR_075ax 100771 +#define SPR_075cl 100772 +#define SPR_075sp 100773 +#define SPR_075bw 100774 + +#define SPR_076em 100775 +#define SPR_076ax 100776 +#define SPR_076cl 100777 +#define SPR_076sp 100778 +#define SPR_076bw 100779 + +#define SPR_085em 100780 +#define SPR_085ax 100781 +#define SPR_085cl 100782 +#define SPR_085sp 100783 +#define SPR_085bw 100784 + +#define SPR_086em 100785 +#define SPR_086ax 100786 +#define SPR_086cl 100787 +#define SPR_086sp 100788 +#define SPR_086bw 100789 + +#define SPR_095em 100790 +#define SPR_095ax 100791 +#define SPR_095cl 100792 +#define SPR_095sp 100793 +#define SPR_095bw 100794 + +#define SPR_096em 100795 +#define SPR_096ax 100796 +#define SPR_096cl 100797 +#define SPR_096sp 100798 +#define SPR_096bw 100799 + +#define SPR_105em 100800 +#define SPR_105ax 100801 +#define SPR_105cl 100802 +#define SPR_105sp 100803 +#define SPR_105bw 100804 + +#define SPR_106em 100805 +#define SPR_106ax 100806 +#define SPR_106cl 100807 +#define SPR_106sp 100808 +#define SPR_106bw 100809 + +#define SPR_115em 100810 +#define SPR_115ax 100811 +#define SPR_115cl 100812 +#define SPR_115sp 100813 +#define SPR_115bw 100814 + +#define SPR_116em 100815 +#define SPR_116ax 100816 +#define SPR_116cl 100817 +#define SPR_116sp 100818 +#define SPR_116bw 100819 + + + +#define SPR_pet006 100820 +#define SPR_pet007 100821 +#define SPR_pet008 100822 + +#define SPR_pet016 100823 +#define SPR_pet017 100824 +#define SPR_pet018 100825 + +#define SPR_pet025 100826 +#define SPR_pet026 100827 +#define SPR_pet027 100828 +#define SPR_pet028 100829 + +#define SPR_pet035 100830 +#define SPR_pet036 100831 +#define SPR_pet037 100832 +#define SPR_pet038 100833 + +#define SPR_pet045 100834 +#define SPR_pet046 100835 +#define SPR_pet047 100836 +#define SPR_pet048 100837 + +#define SPR_pet055 100838 +#define SPR_pet056 100839 +#define SPR_pet057 100840 +#define SPR_pet058 100841 + +#define SPR_pet066 100842 +#define SPR_pet067 100843 +#define SPR_pet068 100844 + +#define SPR_pet075 100845 +#define SPR_pet076 100846 +#define SPR_pet077 100847 +#define SPR_pet078 100848 + +#define SPR_pet096 100849 +#define SPR_pet097 100850 +#define SPR_pet098 100851 + +#define SPR_pet105 100852 +#define SPR_pet106 100853 +#define SPR_pet107 100854 +#define SPR_pet108 100855 + +#define SPR_pet115 100856 +#define SPR_pet116 100857 +#define SPR_pet117 100858 +#define SPR_pet118 100859 + +#define SPR_pet145 100860 +#define SPR_pet146 100861 +#define SPR_pet147 100862 +#define SPR_pet148 100863 + +#define SPR_pet176 100864 +#define SPR_pet177 100865 +#define SPR_pet178 100866 + +#define SPR_pet185 100867 +#define SPR_pet186 100868 +#define SPR_pet187 100869 +#define SPR_pet188 100870 + +#define SPR_pet195 100871 +#define SPR_pet196 100872 +#define SPR_pet197 100873 +#define SPR_pet198 100874 + +#define SPR_pet215 100875 +#define SPR_pet216 100876 +#define SPR_pet217 100877 +#define SPR_pet218 100878 + +#define SPR_pet225 100879 +#define SPR_pet226 100880 +#define SPR_pet227 100881 +#define SPR_pet228 100882 + +#define SPR_pet235 100883 +#define SPR_pet236 100884 +#define SPR_pet237 100885 +#define SPR_pet238 100886 + +#define SPR_pet245 100887 +#define SPR_pet246 100888 +#define SPR_pet247 100889 +#define SPR_pet248 100890 + +#define SPR_pet256 100891 +#define SPR_pet257 100892 +#define SPR_pet258 100893 + +#define SPR_pet265 100894 +#define SPR_pet266 100895 +#define SPR_pet267 100896 +#define SPR_pet268 100897 + +#define SPR_pet275 100898 +#define SPR_pet276 100899 +#define SPR_pet277 100900 +#define SPR_pet278 100901 + +#define SPR_pet295 100902 +#define SPR_pet296 100903 +#define SPR_pet297 100904 +#define SPR_pet298 100905 + +#define SPR_pet305 100906 +#define SPR_pet306 100907 +#define SPR_pet307 100908 +#define SPR_pet308 100909 + +#define SPR_pet316 100910 +#define SPR_pet317 100911 +#define SPR_pet318 100912 + +#define SPR_pet326 100913 +#define SPR_pet327 100914 +#define SPR_pet328 100915 + +#define SPR_pet335 100916 +#define SPR_pet336 100917 +#define SPR_pet337 100918 +#define SPR_pet338 100919 + +#define SPR_ride000 101000 +#define SPR_ride001 101001 +#define SPR_ride002 101002 +#define SPR_ride003 101003 +#define SPR_ride004 101004 +#define SPR_ride005 101005 +#define SPR_ride006 101006 +#define SPR_ride007 101007 +#define SPR_ride008 101008 +#define SPR_ride009 101009 + +#define SPR_ride010 101010 +#define SPR_ride011 101011 +#define SPR_ride012 101012 +#define SPR_ride013 101013 +#define SPR_ride014 101014 +#define SPR_ride015 101015 +#define SPR_ride016 101016 +#define SPR_ride017 101017 +#define SPR_ride018 101018 +#define SPR_ride019 101019 + +#define SPR_ride020 101020 +#define SPR_ride021 101021 +#define SPR_ride022 101022 +#define SPR_ride023 101023 +#define SPR_ride024 101024 +#define SPR_ride025 101025 +#define SPR_ride026 101026 +#define SPR_ride027 101027 +#define SPR_ride028 101028 +#define SPR_ride029 101029 + +#define SPR_ride030 101030 +#define SPR_ride031 101031 +#define SPR_ride032 101032 +#define SPR_ride033 101033 +#define SPR_ride034 101034 +#define SPR_ride035 101035 +#define SPR_ride036 101036 +#define SPR_ride037 101037 +#define SPR_ride038 101038 +#define SPR_ride039 101039 + +#define SPR_ride040 101040 +#define SPR_ride041 101041 +#define SPR_ride042 101042 +#define SPR_ride043 101043 +#define SPR_ride044 101044 +#define SPR_ride045 101045 +#define SPR_ride046 101046 +#define SPR_ride047 101047 +#define SPR_ride048 101048 +#define SPR_ride049 101049 + +#define SPR_ride050 101050 +#define SPR_ride051 101051 +#define SPR_ride052 101052 +#define SPR_ride053 101053 +#define SPR_ride054 101054 +#define SPR_ride055 101055 +#define SPR_ride056 101056 +#define SPR_ride057 101057 +#define SPR_ride058 101058 +#define SPR_ride059 101059 + +#define SPR_ride060 101060 +#define SPR_ride061 101061 +#define SPR_ride062 101062 +#define SPR_ride063 101063 +#define SPR_ride064 101064 +#define SPR_ride065 101065 +#define SPR_ride066 101066 +#define SPR_ride067 101067 +#define SPR_ride068 101068 +#define SPR_ride069 101069 + +#define SPR_ride070 101070 +#define SPR_ride071 101071 +#define SPR_ride072 101072 +#define SPR_ride073 101073 +#define SPR_ride074 101074 +#define SPR_ride075 101075 +#define SPR_ride076 101076 +#define SPR_ride077 101077 +#define SPR_ride078 101078 +#define SPR_ride079 101079 + +#define SPR_ride080 101080 +#define SPR_ride081 101081 +#define SPR_ride082 101082 +#define SPR_ride083 101083 +#define SPR_ride084 101084 +#define SPR_ride085 101085 +#define SPR_ride086 101086 +#define SPR_ride087 101087 +#define SPR_ride088 101088 +#define SPR_ride089 101089 + +#define SPR_ride090 101090 +#define SPR_ride091 101091 +#define SPR_ride092 101092 +#define SPR_ride093 101093 +#define SPR_ride094 101094 +#define SPR_ride095 101095 +#define SPR_ride096 101096 +#define SPR_ride097 101097 +#define SPR_ride098 101098 +#define SPR_ride099 101099 + +#define SPR_ride100 101100 +#define SPR_ride101 101101 +#define SPR_ride102 101102 +#define SPR_ride103 101103 +#define SPR_ride104 101104 +#define SPR_ride105 101105 +#define SPR_ride106 101106 +#define SPR_ride107 101107 +#define SPR_ride108 101108 +#define SPR_ride109 101109 + +#define SPR_ride110 101110 +#define SPR_ride111 101111 +#define SPR_ride112 101112 +#define SPR_ride113 101113 +#define SPR_ride114 101114 +#define SPR_ride115 101115 +#define SPR_ride116 101116 +#define SPR_ride117 101117 +#define SPR_ride118 101118 +#define SPR_ride119 101119 + +#define SPR_pet340 101152 // +#define SPR_pet341 101153 // +#define SPR_pet342 101154 // +#define SPR_pet343 101155 // +#define SPR_180m 101156 // + +#define SPR_170em 101157 +#define SPR_170ax 101158 +#define SPR_170cl 101159 +#define SPR_170sp 101160 +#define SPR_170bw 101161 + +#define SPR_171em 101162 +#define SPR_171ax 101163 +#define SPR_171cl 101164 +#define SPR_171sp 101165 +#define SPR_171bw 101166 + +#define SPR_172em 101167 +#define SPR_172ax 101168 +#define SPR_172cl 101169 +#define SPR_172sp 101170 +#define SPR_172bw 101171 + +#define SPR_173em 101172 +#define SPR_173ax 101173 +#define SPR_173cl 101174 +#define SPR_173sp 101175 +#define SPR_173bw 101176 + +#define SPR_GP_1 101177 +#define SPR_GP_2 101178 +#define SPR_GP_3 101179 + +#define SPR_DRAGON 101180 + +#define SPR_pet1115 102079 // ѩ +#define SPR_pet1116 102080 // ѩ + +//#define SPR_pet1170 102079 // +//#define SPR_pet1171 102080 // + +#define SPR_pet1180 102081 // +#define SPR_pet1181 102082 +#define SPR_pet1182 102083 +#define SPR_pet1183 102084 + + +#define SPR_ride262 103262 // +#define SPR_ride263 103263 +#define SPR_ride264 103264 +#define SPR_ride265 103265 +#define SPR_ride266 103266 +#define SPR_ride267 103267 +#define SPR_ride268 103268 +#define SPR_ride269 103269 +#define SPR_ride270 103270 +#define SPR_ride271 103271 +#define SPR_ride272 103272 +#define SPR_ride273 103273 + +#define SPR_ride274 103274 // +#define SPR_ride275 103275 +#define SPR_ride276 103276 +#define SPR_ride277 103277 +#define SPR_ride278 103278 +#define SPR_ride279 103279 +#define SPR_ride280 103280 +#define SPR_ride281 103281 +#define SPR_ride282 103282 +#define SPR_ride283 103283 +#define SPR_ride284 103284 +#define SPR_ride285 103285 + + + + +#ifdef _WATERANIMATION //Syu ADD ֮ +#define SPR_learthbubble1 101502 +#define SPR_learthbubble2 101503 +#define SPR_learthbubble3 101504 +#define SPR_rearthbubble1 101505 +#define SPR_rearthbubble2 101506 +#define SPR_rearthbubble3 101507 +#define SPR_charbubble1 101508 +#define SPR_charbubble2 101509 +#define SPR_whirlpool1 101510 +#define SPR_whirlpool2 101511 +#define SPR_goldfish1 101512 +#define SPR_goldfish2 101513 +#define SPR_tropicalfish1 101514 +#define SPR_tropicalfish2 101515 +#define SPR_turtle1 101516 +#define SPR_turtle2 101517 +#define SPR_turtle3 101518 +#define SPR_turtle4 101519 +#define SPR_turtle5 101520 +#define SPR_turtle6 101521 +#define SPR_turtle7 101522 +#define SPR_turtle8 101523 +#define SPR_learthbubble4 101524 +#define SPR_learthbubble5 101525 +#define SPR_learthbubble6 101526 +#define SPR_rearthbubble4 101527 +#define SPR_rearthbubble5 101528 +#define SPR_rearthbubble6 101529 +#define SPR_whirlpool3 101579 +#define SPR_lightget 101580 +#define SPR_lightbreak 101581 +#define SPR_lfish1 101582 +#define SPR_lfish2 101583 +#define SPR_lfish3 101584 +#define SPR_lfish4 101585 +#define SPR_lbenthos1 101586 +#define SPR_lbenthos2 101587 +#define SPR_rfish1 101588 +#define SPR_rfish2 101589 +#define SPR_rfish3 101590 +#define SPR_rfish4 101591 +#define SPR_rbenthos1 101592 +#define SPR_rbenthos2 101593 +#define SPR_bseaweed1 101594 +#define SPR_bseaweed2 101595 +#define SPR_bseaweed3 101596 +#define SPR_bseaweed4 101597 +#define SPR_mseaweed1 101598 +#define SPR_mseaweed2 101599 +#define SPR_mseaweed3 101600 +#define SPR_mseaweed4 101601 +#define SPR_sseaweed1 101602 +#define SPR_sseaweed2 101603 +#define SPR_sseaweed3 101604 +#define SPR_sseaweed4 101605 +#define SPR_smoke 101606 +#endif + +/* +#define SPR_pet025 100653 +#define SPR_pet035 100654 +#define SPR_pet036 100655 +#define SPR_pet045 100656 +#define SPR_pet055 100657 +#define SPR_pet075 100658 +#define SPR_pet096 100659 +#define SPR_pet105 100660 +#define SPR_pet115 100661 +#define SPR_pet145 100662 +#define SPR_pet185 100663 +#define SPR_pet195 100664 +#define SPR_pet196 100665 +#define SPR_pet215 100666 +#define SPR_pet225 100667 +#define SPR_pet235 100668 +#define SPR_pet245 100669 +#define SPR_pet265 100670 +#define SPR_pet275 100671 +#define SPR_pet295 100672 +#define SPR_pet305 100673 +#define SPR_pet335 100674 +*/ +/* +// Fix +#define SPR_051emfix 100700 // g? +#define SPR_051axfix 100701 // ? +#define SPR_051clfix 100702 // ??S +#define SPR_051spfix 100703 // ? +#define SPR_051bwfix 100704 // ? + +#define SPR_052emfix 100705 +#define SPR_052axfix 100706 +#define SPR_052clfix 100707 +#define SPR_052spfix 100708 +#define SPR_052bwfix 100709 + +#define SPR_053emfix 100710 +#define SPR_053axfix 100711 +#define SPR_053clfix 100712 +#define SPR_053spfix 100713 +#define SPR_053bwfix 100714 + +#define SPR_054emfix 100715 +#define SPR_054axfix 100716 +#define SPR_054clfix 100717 +#define SPR_054spfix 100718 +#define SPR_054bwfix 100719 +*/ +#ifdef _ITEM_CRACKER// +#define SPR_cracker 101401 +#endif +#ifdef _SKILL_SELFEXPLODE //Ա +#define SPR_selfexplod 101418//101126 +#endif +// ???????????????? ****************************************************/ +#define CG_INVISIBLE 99 // ???????????? +#define CG_MOUSE_CURSOR 25000 +#define CG_GRID_CURSOR 25001 + +// ???????????? +#define CG_BTL_BUTTON_ATTACK_UP 25100 +#define CG_BTL_BUTTON_ATTACK_DOWN 25101 +#define CG_BTL_BUTTON_JUJUTU_UP 25102 +#define CG_BTL_BUTTON_JUJUTU_DOWN 25103 +#define CG_BTL_BUTTON_CAPTURE_UP 25104 +#define CG_BTL_BUTTON_CAPTURE_DOWN 25105 +#define CG_BTL_BUTTON_HELP_UP 25106 +#define CG_BTL_BUTTON_HELP_DOWN 25107 +#define CG_BTL_BUTTON_GUARD_UP 25108 +#define CG_BTL_BUTTON_GUARD_DOWN 25109 +#define CG_BTL_BUTTON_ITEM_UP 25110 +#define CG_BTL_BUTTON_ITEM_DOWN 25111 +#define CG_BTL_BUTTON_PET_UP 25112 +#define CG_BTL_BUTTON_PET_DOWN 25113 +#define CG_BTL_BUTTON_ESCAPE_UP 25114 +#define CG_BTL_BUTTON_ESCAPE_DOWN 25115 +#define CG_BTL_BUTTON_BASE 25116 // ????U +#define CG_BTL_BUTTON_CROSS 25117 // ???? + +// N???? +#define CG_ATR_ICON_EARTH_BIG 25120 // ?? +#define CG_ATR_ICON_EARTH_MDL 25121 // ??? +#define CG_ATR_ICON_EARTH_SML 25122 // ?? +#define CG_ATR_ICON_WATER_BIG 25123 // ??? +#define CG_ATR_ICON_WATER_MDL 25124 // ???? +#define CG_ATR_ICON_WATER_SML 25125 // ??? +#define CG_ATR_ICON_FIRE_BIG 25126 // ??? +#define CG_ATR_ICON_FIRE_MDL 25127 // ???? +#define CG_ATR_ICON_FIRE_SML 25128 // ??? +#define CG_ATR_ICON_WIND_BIG 25129 // ??? +#define CG_ATR_ICON_WIND_MDL 25130 // ???? +#define CG_ATR_ICON_WIND_SML 25131 // ??? + +// Pf?N???? +#define CG_ATR_ICON_EARTH_BATTLE 25132 // ?? +#define CG_ATR_ICON_WATER_BATTLE 25133 // ??? +#define CG_ATR_ICON_FIRE_BATTLE 25134 // ??? +#define CG_ATR_ICON_WIND_BATTLE 25135 // ??? + +// ?????????? +#define CG_PET_BTL_BUTTON_BASE 25140 // ????U +#define CG_PET_BTL_BUTTON_WAZA_UP 25141 // ???? +#define CG_PET_BTL_BUTTON_WAZA_DOWN 25142 // ????? +#define CG_PET_BTL_BUTTON_CANCEL_UP 25143 // ???????? + +// ?????? +#define CG_HIT_MARK_00 25500 // Ѣ +#define CG_HIT_MARK_01 25501 // + +#define CG_HIT_MARK_10 25502 // +#define CG_HIT_MARK_11 25503 +#define CG_HIT_MARK_12 25504 + +#define CG_HIT_MARK_20 25505 // +#define CG_HIT_MARK_21 25506 +#define CG_HIT_MARK_22 25507 + +#define CG_HIT_MARK_30 25508 // ? +#define CG_HIT_MARK_31 25509 +#define CG_HIT_MARK_32 25510 + +#define CG_HIT_MARK_40 25511 // ? +#define CG_HIT_MARK_41 25512 +#define CG_HIT_MARK_42 25513 + +// ? +#define CG_SPEECH_BTL_OK 25520 +#define CG_SPEECH_CHANGE 25521 +#define CG_SPEECH_GROUP 25522 +#define CG_SPEECH_SUCCESS 25523 +#define CG_SPEECH_YATTA 25524 +#define CG_SPEECH_HELP 25525 + +// ????????? +#define CG_VS_MARK_1A 25610 +#define CG_VS_MARK_1B 25611 +#define CG_VS_MARK_2A 25612 +#define CG_VS_MARK_2B 25613 +#define CG_VS_MARK_3A 25614 +#define CG_VS_MARK_3B 25615 +#define CG_VS_MARK_4A 25616 +#define CG_VS_MARK_4B 25617 +#define CG_VS_MARK_5A 25618 +#define CG_VS_MARK_5B 25619 +#define CG_VS_MARK_6A 25620 +#define CG_VS_MARK_6B 25621 +#define CG_VS_MARK_7A 25622 +#define CG_VS_MARK_7B 25623 +#define CG_VS_MARK_8A 25624 +#define CG_VS_MARK_8B 25625 +#define CG_VS_MARK_9A 25626 +#define CG_VS_MARK_9B 25627 +#define CG_VS_MARK_10A 25628 +#define CG_VS_MARK_10B 25629 + + +// ?? +#define CG_ARROW_00 25630 +#define CG_ARROW_01 25631 +#define CG_ARROW_02 25632 +#define CG_ARROW_03 25633 +#define CG_ARROW_04 25634 +#define CG_ARROW_05 25635 +#define CG_ARROW_06 25636 +#define CG_ARROW_07 25637 +#define CG_ARROW_08 25638 +#define CG_ARROW_09 25639 +#define CG_ARROW_10 25640 +#define CG_ARROW_11 25641 +#define CG_ARROW_12 25642 +#define CG_ARROW_13 25643 +#define CG_ARROW_14 25644 +#define CG_ARROW_15 25645 + +// ????????? +#define CG_CNT_DOWN_0 25900 //սʱ +#define CG_CNT_DOWN_1 25901 +#define CG_CNT_DOWN_2 25902 +#define CG_CNT_DOWN_3 25903 +#define CG_CNT_DOWN_4 25904 +#define CG_CNT_DOWN_5 25905 +#define CG_CNT_DOWN_6 25906 +#define CG_CNT_DOWN_7 25907 +#define CG_CNT_DOWN_8 25908 +#define CG_CNT_DOWN_9 25909 + +// ????????? +#define CG_WND_TITLE_SYSTEM 26010 +#define CG_WND_TITLE_LOGOUT 26011 +#define CG_WND_TITLE_CHAT 26015 +#define CG_WND_TITLE_BGM 26016 +#define CG_WND_TITLE_SE 26017 +#define CG_WND_TITLE_RESULT 26018 +#define CG_WND_TITLE_MOUSE 26030 + +// ????? +#define CG_TASK_BAR_BACK 26012 + +// Pf????????? +#define CG_BATTLE_BAR_PLAYER 26013 // ????? +#define CG_BATTLE_BAR_PLAYER_2 26019 // ????? +#define CG_BATTLE_BAR_PET 26014 // \? +#define CG_BATTLE_BAR_PET_2 26020 // ????????? + +//#define CG_BTL_PET_CHANGE_WND 126230 +#define CG_BTL_PET_RETURN_BTN 26041 // Pf???????????[?? + +// [???? +#define CG_CLOSE_BTN 26042 // ??????[?? +#define CG_RETURN_BTN 26043 // ??????[?? +#define CG_OK_BTN 26093 // ϣ????[?? +#define CG_CANCEL_BTN 26050 // ?????????[?? + +#define CG_YES_BTN 26094 // "??"??? +#define CG_NO_BTN 26095 // "???"??? +#define CG_EXIT_BTN 26096 // "?"??? +#define CG_SEAL_BTN 26097 // "??"??? +#define CG_BUY_BTN 26098 // "??"??? + + +#define CG_PET_WND_WAZA_BTN 26046 // ?????[?? +//#define CG_PREV_BTN 26047 // q??v??????[?? +//#define CG_NEXT_BTN 26048 // ???v??????[?? + +//#define CG_NAME_CHANGE_BTN 26051 // q???? +#define CG_NAME_CHANGE_BTN 26058 // q???? +#define CG_NAME_CHANGE_BTN_DOWN 26059 // q????? + +#ifdef _PETCOM_ +#define CG_PETCOM_CHANGE_BTN 55218 //ɳɰť +#define CG_PETCOM_WND 55220 //ɳ +#endif + +#define CG_PET_WND_REST_BTN 26052 // ???????? +#define CG_PET_WND_STANDBY_BTN 26053 // ???r???? +#define CG_PET_WND_BTL_BTN 26054 // ????????? +#define CG_PET_WND_MAIL_BTN 26055 // ????????? +#define CG_PET_WND_FAMILY_BTN 26245 // +#define CG_PET_WND_STATUS_BTN 26056 // ??????? +#define CG_PET_WND_RIDE_BTN 26247 // + + +// ????????? +#define CG_ITEM_WND_0 26060 // ????????? +#define CG_ITEM_WND_GOLD_DROP_BTN_UP 26062 // ???????? +#define CG_ITEM_WND_GOLD_DROP_BTN_DOWN 26063 // ????????? +#define CG_ITEM_WND_GOLD_INC_BTN_UP 26064 // ???????? +#define CG_ITEM_WND_GOLD_INC_BTN_DOWN 26065 // ????????? +#define CG_ITEM_WND_GOLD_DEC_BTN_UP 26066 // ???????? +#define CG_ITEM_WND_GOLD_DEC_BTN_DOWN 26067 // ????????? +#define CG_ITEM_WND_JUJUTU_BTN 26069 // ????????????? +#define CG_BTL_ITEM_WND_TITLE 26072 // Pf??????????????? + +// ?????????? +#define CG_STATUS_WND_VICTORY_MARK 26074 // ????? +#define CG_STATUS_WND_LV_UP_POINT 26075 // ??????? +#define CG_STATUS_WND_UP_BTN_UP 26076 // ??????????? +#define CG_STATUS_WND_UP_BTN_DOWN 26077 // ???????????? +#define CG_STATUS_WND_SHOUGOU_BTN_UP 26078 // ???? +#define CG_STATUS_WND_SHOUGOU_BTN_DOWN 26079 // ????? +#define CG_STATUS_WND_GROUP_BTN 26080 // ????????? + +#ifdef _DELBORNPLACE //Syu ADD 6.0 ͳһִ +#define CG_NEWBORNPET_WND 26326 +#endif + +#define CG_MAIL_WND_ITEM_BTN 26202 // ??????? + +//#define CG_MAIL_WND_MAIL_BTN 26083 // ?????? +#define CG_MAIL_WND_ON_LINE_SUN_BTN 26084 // ????????????? +#define CG_MAIL_WND_ON_LINE_MOON_BTN 26088 // ?????????????? +#define CG_MAIL_WND_OFF_LINE_BTN 26085 // ????????? +#define CG_MAIL_WND_MAIL_BTN 26086 // ????? +#define CG_MAIL_WND_DELETE_BTN 26087 // ????? +#define CG_MAIL_WND_CLEAR_BTN_UP 26172 // ?????? +#define CG_MAIL_WND_CLEAR_BTN_DOWN 26173 // ??????? +#define CG_SEND_BTN 26099 // "?"??? +#define CG_SEND_BTN_DOWN 26174 // "?"???? +//sa3 ?????????????? +#define CG_MAIL_WND_ON_LINE_MERCURY_BTN 25910 // ??????????? +#define CG_MAIL_WND_ON_LINE_VINUS_BTN 25911 // ??????????? +#define CG_MAIL_WND_ON_LINE_EARTH_BTN 25912 // ?????????? +#define CG_MAIL_WND_ON_LINE_MARS_BTN 25913 // ? + +#define CG_ALBUM_WND_NEW_ICON 26231 // ????? +#define CG_ALBUM_WND_SNAP_BTN_UP 26170 // ?? +#define CG_ALBUM_WND_SNAP_BTN_DOWN 26171 // ??? + +//Ƥ +#ifdef _PET_SKINS + +#define CG_PET_SKINS_WIN 55270 //Ƥ +#define CG_PET_SKINS_SET 55271 //Ϊʹ +#define CG_PET_SKINS_PREV_BTN 55272 //< +#define CG_PET_SKINS_PREV_PRESSED_BTN 55273 //< +#define CG_PET_SKINS_NEXT_BTN 55274 //> +#define CG_PET_SKINS_NEXT_PRESSED_BTN 55275 //> +#define CG_PET_SKINS_SHOW_BTN 55276 //Ƥť +#define CG_PET_SKINS_SHOW_PRESSED_BTN 55277 //Ƥ + +#endif + +// ?V?[?????? +#define CG_COMMON_YES_BTN 26091 // ????? +#define CG_COMMON_NO_BTN 26092 // ?????? + +#ifdef __PHONEMESSAGE +#define CG_FIELD_MENU_LEFT 26100 +#else +// ?????????? +#define CG_FIELD_MENU_LEFT_OLD 26100 // mail call Ͻǵװ +//#ifdef __FAMILY_UI_ +#ifdef _SPECIAL_LOGO +#define CG_FIELD_MENU_LEFT_NEW 28553 +#else +#define CG_FIELD_MENU_LEFT_NEW 26236 // ?Ƣ? +#endif +//#else +#define CG_FIELD_MENU_LEFT 26233 // ?Ƣ? +//#endif +#endif + +#ifdef _ANGEL_SUMMON +#define CG_FIELD_ANGEL_LAMP 35270 +#define CG_FIELD_MENU_LEFT_75 35271 +#endif + +#define CG_FIELD_MENU_BTN_OFF 26101 // ?????????֢t +#define CG_FIELD_MENU_BTN_ON 26102 // ?????????֢t +#define CG_FIELD_CARD_BTN_OFF 26103 // ?????֢t +#define CG_FIELD_CARD_BTN_ON 26104 // ?????֢t +#define CG_FIELD_GROUP_BTN_OFF 26105 // ?????????֢t +#define CG_FIELD_GROUP_BTN_ON 26106 // ?????????֢t +#define CG_FIELD_MAIL_LAMP 26107 // ?????? +#define CG_FIELD_MENU_RIGHT 26260 +#define CG_FIELD_HELP_PRELAYER 26250 +#define CG_FIELD_HELP_PREPAGE 26252 +#define CG_FIELD_HELP_NEXTPAGE 26254 +#define CG_FIELD_HELP_EXIT 26256 +#define CG_FIELD_JOIN_BTL_BTN_OFF 26111 // ӡP?????֢t +#define CG_FIELD_JOIN_BTL_BTN_ON 26112 // ӡP?????֢t +#define CG_FIELD_DUEL_BTN_OFF 26113 // nP?????֢t +#define CG_FIELD_DUEL_BTN_ON 26114 // nP????? +#ifdef _CHANGE_HELP_BUTTON +#define CG_FIELD_HELP_BTN_OFF 55237 +#define CG_FIELD_HELP_BTN_ON 55238 +#else +#define CG_FIELD_HELP_BTN_OFF 26249 +#define CG_FIELD_HELP_BTN_ON 26248 +#endif +#define CG_FIELD_ACT_BTN_OFF 26115 // ??????????֢t +#define CG_FIELD_ACT_BTN_ON 26116 // ??????????֢t +#define CG_FIELD_AM_PM_00 26117 // ???????? +#define CG_FIELD_AM_PM_01 26118 // ???????? +#define CG_FIELD_AM_PM_02 26119 // ???????? +#define CG_FIELD_AM_PM_03 26120 // ???????? +#define CG_FIELD_MENU_RIGHT_BACK 26121 // ?Ƣ????? +#define CG_FIELD_TRADE_BTN_OFF 26234 // TRADE?????֢t +#define CG_FIELD_TRADE_BTN_ON 26235 // TRADE?????֢t +#define CG_FIELD_CHANNEL_BTN_OFF 26237 // CHANNEL?????֢t +#define CG_FIELD_CHANNEL_BTN_ON 26238 // CHANNEL?????֢t +#define CG_FIELD_MSG_BTN_ON 26294 // Msg-Down button,added by LeiBoy +#define CG_FIELD_MSG_BTN_OFF 26295 // Msg-Up button ,added by LeiBoy +#ifdef _MO_SIGN_IN +#define CG_FIELD_SIGNIN_BTN_ON 55239 +#define CG_FIELD_SIGNIN_BTN_OFF 55240 +#endif +#ifdef _CHANGETEAM_ +#define CG_FIELD_CHANGETEAM_BTN_OFF 55247 +#define CG_FIELD_CHANGETEAM_BTN_ON 55248 +#endif + +#ifdef _NEWSHOP_ +#define CG_FIELD_MARKET_BTN_ON 55100 +#define CG_FIELD_MARKET_BTN_OFF 55101 +#endif + +#define CG_PET_WAZA_BAR_1 26131 +#define CG_PET_WAZA_BAR_2 26132 +#define CG_PET_WAZA_BAR_3 26133 +#define CG_PET_WAZA_BAR_4 26134 +#define CG_PET_WAZA_BAR_5 26135 +#define CG_PET_WAZA_BAR_6 26136 +#define CG_PET_WAZA_BAR_7 26137 + +// ???????? +#define CG_TASK_BAR_MAP_UP 26150 +#define CG_TASK_BAR_MAP_DOWM 26151 +#define CG_TASK_BAR_STATUS_UP 26152 +#define CG_TASK_BAR_STATUS_DOWN 26153 +#define CG_TASK_BAR_PET_UP 26154 +#define CG_TASK_BAR_PET_DOWN 26155 +#define CG_TASK_BAR_ITEM_UP 26156 +#define CG_TASK_BAR_ITEM_DOWN 26157 +#define CG_TASK_BAR_MAIL_UP 26158 +#define CG_TASK_BAR_MAIL_DOWN 26159 +#define CG_TASK_BAR_ALBUM_UP 26160 +#define CG_TASK_BAR_ALBUM_DOWN 26161 +#define CG_TASK_BAR_SYSTEM_UP 26162 +#define CG_TASK_BAR_SYSTEM_DOWN 26163 + +// q???? +#define CG_PREV_BTN 26180 // ???? +#define CG_PREV_BTN_DOWN 26181 // ????? +#define CG_NEXT_BTN 26182 // ???? +#define CG_NEXT_BTN_DOWN 26183 // ????? + +#define CG_PREV_BTN2 26184 // ???? +#define CG_PREV_BTN2_DOWN 26185 // ????? +#define CG_NEXT_BTN2 26186 // ???? +#define CG_NEXT_BTN2_DOWN 26187 // ????? + +#define CG_UP_BTN 26188 // ???? +#define CG_UP_BTN_DOWN 26189 // ????? +#define CG_DOWN_BTN 26190 // ???? +#define CG_DOWN_BTN_DOWN 26191 // ????? + + +// ???? +#define CG_ICON_FUKIDASI 26500 // ????V??????? +#define CG_ICON_COME_ON 26501 // ?Come On!? +#define CG_ICON_GO 26502 // ?Go!? +#define CG_ICON_WATCHING 26503 // ?Watching? +#define CG_ICON_MISS 26504 // ?Miss...? +#define CG_ICON_FAIL 26505 // ?Fail...? +#define CG_ICON_GET 26506 // ?Get!!? +#define CG_ICON_COUNTER 26507 // ?Counter!? +#define CG_ICON_DANGER 26508 // ?Danger!? +#define CG_ICON_NO 26509 // ?No!? +#define CG_ICON_GUARD 26510 // ?Guard!? +#define CG_ICON_ESCAPE 26511 // ?Escape!? +#define CG_ICON_CAPTURE 26512 // ?Capture!? +#define CG_ICON_LEAVE 26513 // ?Leave!? +#define CG_ICON_GUARD_BREAK 26514 // ?Guard Break!? +#define CG_ICON_CRUSH 26515 // ?Crush!? +#define CG_ICON_CAPTURE_UP 26516 // ?Capture Up!? +#ifdef _SKILL_ROAR //輼:() +#define CG_ICON_ROAR 25869 // ?Hwaoo!? +#endif + +// ???????????? +#define CG_NOW_PAINTING 28999 + +// ???? +// shan remark +//#define CG_LOGO 29000 +//#define CG_LOGO 29026 +// Syu ReEdit +#define CG_LOGO 35262//28995 +#ifdef _v4_0 +#define CG_TITLE 29025 +#endif +#ifdef _NEWLOGO // Syu ADD 6.0뻭logo Ҫ_v4_0 +#define CG_TITLE 29025 +#endif +#ifdef _SPECIAL_LOGO +#define CG_TITLE 29025 +#define CG_TITLE_ID_PASS 26301 +#define CG_TITLE_ID_PASS_OK 26302 +#define CG_TITLE_ID_PASS_QUIT 26303 +#endif +#define CG_TITLE_NAME_S 29002 +#define CG_TITLE_NAME_T 29003 +#define CG_TITLE_NAME_O 29004 +#define CG_TITLE_NAME_N 29005 +#define CG_TITLE_NAME_E 29006 +#define CG_TITLE_NAME_A 29007 +#define CG_TITLE_NAME_G 29008 +#define CG_TITLE_NAME_E2 29009 +#define CG_TITLE_NAME 29010 +#define CG_TITLE_NAME_FLASH 29011 +#define CG_TITLE_NAME_FLASH1 29012 +#define CG_TITLE_NAME_FLASH2 29013 +#define CG_TITLE_NAME_FLASH3 29014 +#define CG_TITLE_NAME_FLASH4 29015 +#define CG_TITLE_NAME_FLASH5 29016 +#define CG_TITLE_JSS_LOGO 29017 +#define CG_TITLE_DREAM_LOGO 29018 +#define CG_TITLE_NOW_LOADING 29019 + +#ifdef _v4_0 +#define CG_TITLE_ID_PASS 29046 // 29029->29046 +#define CG_TITLE_ID_PASS_OK 29027 +#define CG_TITLE_ID_PASS_QUIT 29028 +#endif + +#ifdef _NEWLOGO // Syu ADD 6.0뻭logo Ҫ_v4_0 + +#ifdef _NEWPANEL_71 + #ifdef _BACK_LOGO + #define CG_TITLE_ID_PASS 35265 + #else + #ifdef _75_LOGIN + #define CG_TITLE_ID_PASS OLD_GRAPHICS_START+822 + #else + #define CG_TITLE_ID_PASS 28997 + #endif //_75_LOGIN + #endif //_BACK_LOGO +#else + #ifdef _NEWPANEL_70 + #define CG_TITLE_ID_PASS 28996 + #else + #define CG_TITLE_ID_PASS 28994 // 29046->28993 + #endif //_NEWPANEL_70 +#endif //_NEWPANEL_71 +#ifdef _80_LOGIN + #undef CG_TITLE_ID_PASS + #define CG_TITLE_ID_PASS 26301 +#endif +#ifdef _85_LOGIN + #undef CG_TITLE_ID_PASS + #define CG_TITLE_ID_PASS 26304 +#endif +#ifdef _BACK_LOGO + #define CG_TITLE_ID_PASS_OK 35266 + #define CG_TITLE_ID_PASS_QUIT 35267 +#else + #ifdef _75_LOGIN + #define CG_TITLE_ID_PASS_OK OLD_GRAPHICS_START+823 + #define CG_TITLE_ID_PASS_QUIT OLD_GRAPHICS_START+824 + #else + #define CG_TITLE_ID_PASS_OK 29027 + #define CG_TITLE_ID_PASS_QUIT 29028 + #endif //_75_LOGIN +#endif //_BACK_LOGO +#endif //_NEWLOGO +#ifdef _80_LOGIN + #undef CG_TITLE_ID_PASS_OK + #undef CG_TITLE_ID_PASS_QUIT + #define CG_TITLE_ID_PASS_OK 26302 + #define CG_TITLE_ID_PASS_QUIT 26303 +#endif +#ifdef _85_LOGIN + #undef CG_TITLE_ID_PASS_OK + #undef CG_TITLE_ID_PASS_QUIT + #define CG_TITLE_ID_PASS_OK 26305 + #define CG_TITLE_ID_PASS_QUIT 26306 +#endif +#define CG_TITLE_SPRITEKING 29023 + +// ???? +#define CG_CHR_MAKE_SEL_BG 29030 // ????k? +#define CG_CHR_MAKE_BG 29031 // ???????????? +#define CG_CHR_SEL_BG 29032 // ?????k? +#define CG_CHR_SEL_LOGIN_BTN 29033 // ??????? +#define CG_CHR_SEL_NEW_BTN 29034 // ???? +#define CG_CHR_SEL_DEL_BTN 29035 // ????? +#define CG_CHR_SEL_BACK_BTN 29036 // ????? +#define CG_CHR_MAKE_OK_BTN 29037 // ???? ?e??? +#define CG_CHR_MAKE_BACK_BTN 29038 // ???? ????? +#define CG_CHR_MAKE_SEL2_BG 29039 // ԡk? +#define CG_CHR_MAKE_HOME_NAME0 29040 // ??????Z? +#define CG_CHR_MAKE_HOME_NAME1 29041 // ??????Z? +#define CG_CHR_MAKE_HOME_NAME2 29042 // ??????Z? +#define CG_CHR_MAKE_HOME_NAME3 29043 // ???????Z? +#define CG_CHR_MAKE_EYE_SEL 29044 // ???? ???k +#define CG_CHR_MAKE_NOSE_SEL 29045 // ???? ??k +#define CG_CHR_MAKE_FACE 30000 // ??????? + + +// trade sys +//#define CG_TRADE_WND 40001 +#define CG_TRADE_LEFT_BTN_UP 26180 +#define CG_TRADE_LEFT_BTN_DOWN 26181 +#define CG_TRADE_RIGHT_BTN_UP 26182 +#define CG_TRADE_RIGHT_BTN_DOWN 26183 +#define CG_TRADE_UP_BTN_UP 26064 +#define CG_TRADE_UP_BTN_DOWN 26065 +#define CG_TRADE_DOWN_BTN_UP 26066 +#define CG_TRADE_DOWN_BTN_DOWN 26067 +#define CG_TRADE_PUT_BTN_UP 26062 +#define CG_TRADE_PUT_BTN_DOWN 26063 +#define CG_TRADE_OK_BTN 26093 +#define CG_TRADE_CANCEL_BTN 26050 +#define CG_TRADE_LOCK_BTN 26300 + + +// family +//#define CG_FAMILY_ADD_WIN 26139 +//#define CG_FAMILY_CHANNEL_BTN_OFF 26234 +//#define CG_FAMILY_CHANNEL_BTN_ON 26235 + +#define CG_EXIT_BTN2 26241 +#define CG_EXIT_BTN2_DOWN 26242 +#define CG_JOIN_BTN 26243 +#define CG_JOIN_BTN_DOWN 26244 + +#define CG_TRADE_MARK 26246 + +#ifdef _ANGEL_SUMMON +#define CG_ANGEL_MARK 26246 +#endif + +//andy_ride +#define RIDE_OLD 0x00 +// ride Pet table +typedef struct +{ + int rideNo; + int charNo; + int petNo; + //ANDY_ADD + int rideCode; +} tagRidePetTable; + +static tagRidePetTable ridePetTable[] = +{ + { 101000, 100000, 100352, RIDE_OLD }, + { 101001, 100005, 100352, RIDE_OLD }, + { 101002, 100010, 100352, RIDE_OLD }, + { 101003, 100015, 100352, RIDE_OLD }, + { 101004, 100000, 100329, RIDE_OLD }, + { 101005, 100005, 100327, RIDE_OLD }, + { 101006, 100010, 100330, RIDE_OLD }, + { 101007, 100015, 100328, RIDE_OLD }, + { 101008, 100700, 100372, RIDE_OLD }, + { 101009, 100705, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101989, 100705, 101576, RIDE_OLD }, + { 101978, 100705, 101532, RIDE_OLD }, +#endif + { 101010, 100020, 100396, RIDE_OLD }, + { 101011, 100025, 100396, RIDE_OLD }, + { 101012, 100030, 100396, RIDE_OLD }, + { 101013, 100035, 100396, RIDE_OLD }, + { 101014, 100020, 100328, RIDE_OLD }, + { 101015, 100025, 100329, RIDE_OLD }, + { 101016, 100030, 100327, RIDE_OLD }, + { 101017, 100035, 100330, RIDE_OLD }, + { 101018, 100710, 100372, RIDE_OLD }, + { 101019, 100715, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101988, 100715, 101576, RIDE_OLD }, + { 101986, 100715, 101532, RIDE_OLD }, +#endif + { 101020, 100040, 100351, RIDE_OLD }, + { 101021, 100045, 100351, RIDE_OLD }, + { 101022, 100050, 100351, RIDE_OLD }, + { 101023, 100055, 100351, RIDE_OLD }, + { 101024, 100040, 100328, RIDE_OLD }, + { 101025, 100045, 100330, RIDE_OLD }, + { 101026, 100050, 100327, RIDE_OLD }, + { 101027, 100055, 100329, RIDE_OLD }, + { 101028, 100720, 100372, RIDE_OLD }, + { 101029, 100725, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101965, 100725, 101576, RIDE_OLD }, + { 101975, 100725, 101532, RIDE_OLD }, +#endif + { 101030, 100060, 100353, RIDE_OLD }, + { 101031, 100065, 100353, RIDE_OLD }, + { 101032, 100070, 100353, RIDE_OLD }, + { 101033, 100075, 100353, RIDE_OLD }, + { 101034, 100060, 100329, RIDE_OLD }, + { 101035, 100065, 100327, RIDE_OLD }, + { 101036, 100070, 100330, RIDE_OLD }, + { 101037, 100075, 100328, RIDE_OLD }, + { 101038, 100730, 100372, RIDE_OLD }, + { 101039, 100735, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101966, 100735, 101576, RIDE_OLD }, + { 101976, 100735, 101532, RIDE_OLD }, +#endif + { 101040, 100080, 100396, RIDE_OLD }, + { 101041, 100085, 100396, RIDE_OLD }, + { 101042, 100090, 100396, RIDE_OLD }, + { 101043, 100095, 100396, RIDE_OLD }, + { 101044, 100080, 100328, RIDE_OLD }, + { 101045, 100085, 100327, RIDE_OLD }, + { 101046, 100090, 100330, RIDE_OLD }, + { 101047, 100095, 100329, RIDE_OLD }, + { 101048, 100740, 100372, RIDE_OLD }, + { 101049, 100745, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101973, 100745, 101576, RIDE_OLD }, + { 101984, 100745, 101532, RIDE_OLD }, +#endif + { 101050, 100100, 100353, RIDE_OLD }, + { 101051, 100105, 100353, RIDE_OLD }, + { 101052, 100110, 100353, RIDE_OLD }, + { 101053, 100115, 100353, RIDE_OLD }, + { 101054, 100100, 100329, RIDE_OLD }, + { 101055, 100105, 100328, RIDE_OLD }, + { 101056, 100110, 100330, RIDE_OLD }, + { 101057, 100115, 100327, RIDE_OLD }, + { 101058, 100750, 100372, RIDE_OLD }, + { 101059, 100755, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101974, 100755, 101576, RIDE_OLD }, + { 101985, 100755, 101532, RIDE_OLD }, +#endif + { 101060, 100120, 100354, RIDE_OLD }, + { 101061, 100125, 100354, RIDE_OLD }, + { 101062, 100130, 100354, RIDE_OLD }, + { 101063, 100135, 100354, RIDE_OLD }, + { 101064, 100120, 100327, RIDE_OLD }, + { 101065, 100125, 100330, RIDE_OLD }, + { 101066, 100130, 100328, RIDE_OLD }, + { 101067, 100135, 100329, RIDE_OLD }, + { 101068, 100760, 100372, RIDE_OLD }, + { 101069, 100765, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101967, 100765, 101576, RIDE_OLD }, + { 101977, 100765, 101532, RIDE_OLD }, +#endif + { 101070, 100140, 100354, RIDE_OLD }, + { 101071, 100145, 100354, RIDE_OLD }, + { 101072, 100150, 100354, RIDE_OLD }, + { 101073, 100155, 100354, RIDE_OLD }, + { 101074, 100140, 100327, RIDE_OLD }, + { 101075, 100145, 100329, RIDE_OLD }, + { 101076, 100150, 100330, RIDE_OLD }, + { 101077, 100155, 100328, RIDE_OLD }, + { 101078, 100770, 100372, RIDE_OLD }, + { 101079, 100775, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101968, 100775, 101576, RIDE_OLD }, + { 101979, 100775, 101532, RIDE_OLD }, +#endif + { 101080, 100160, 100352, RIDE_OLD }, + { 101081, 100165, 100352, RIDE_OLD }, + { 101082, 100170, 100352, RIDE_OLD }, + { 101083, 100175, 100352, RIDE_OLD }, + { 101084, 100160, 100330, RIDE_OLD }, + { 101085, 100165, 100329, RIDE_OLD }, + { 101086, 100170, 100327, RIDE_OLD }, + { 101087, 100175, 100328, RIDE_OLD }, + { 101088, 100780, 100372, RIDE_OLD }, + { 101089, 100785, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101970, 100785, 101576, RIDE_OLD }, + { 101981, 100785, 101532, RIDE_OLD }, +#endif + { 101090, 100180, 100351, RIDE_OLD }, + { 101091, 100185, 100351, RIDE_OLD }, + { 101092, 100190, 100351, RIDE_OLD }, + { 101093, 100195, 100351, RIDE_OLD }, + { 101094, 100180, 100328, RIDE_OLD }, + { 101095, 100185, 100330, RIDE_OLD }, + { 101096, 100190, 100329, RIDE_OLD }, + { 101097, 100195, 100327, RIDE_OLD }, + { 101098, 100790, 100372, RIDE_OLD }, + { 101099, 100795, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101969, 100795, 101576, RIDE_OLD }, + { 101980, 100795, 101532, RIDE_OLD }, +#endif + { 101100, 100200, 100353, RIDE_OLD }, + { 101101, 100205, 100353, RIDE_OLD }, + { 101102, 100210, 100353, RIDE_OLD }, + { 101103, 100215, 100353, RIDE_OLD }, + { 101104, 100200, 100329, RIDE_OLD }, + { 101105, 100205, 100328, RIDE_OLD }, + { 101106, 100210, 100327, RIDE_OLD }, + { 101107, 100215, 100330, RIDE_OLD }, + { 101108, 100800, 100372, RIDE_OLD }, + { 101109, 100805, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101972, 100805, 101576, RIDE_OLD }, + { 101983, 100805, 101532, RIDE_OLD }, +#endif + { 101110, 100220, 100396, RIDE_OLD }, + { 101111, 100225, 100396, RIDE_OLD }, + { 101112, 100230, 100396, RIDE_OLD }, + { 101113, 100235, 100396, RIDE_OLD }, + { 101114, 100220, 100330, RIDE_OLD }, + { 101115, 100225, 100327, RIDE_OLD }, + { 101116, 100230, 100329, RIDE_OLD }, + { 101117, 100235, 100328, RIDE_OLD }, + { 101118, 100810, 100372, RIDE_OLD }, + { 101119, 100815, 100373, RIDE_OLD }, +#ifdef _8_RIDEPETS + { 101971, 100815, 101576, RIDE_OLD }, + { 101982, 100815, 101532, RIDE_OLD }, +#endif + { 101179, 101177, 101178, RIDE_OLD}, + { 101179, 101178, 101177, RIDE_OLD}, +}; + +#define RIDE_PET0 1 +#define RIDE_PET1 ( 1 << 1 ) +#define RIDE_PET2 ( 1 << 2 ) +#define RIDE_PET3 ( 1 << 3 ) +#define RIDE_PET4 ( 1 << 4 ) +#define RIDE_PET5 ( 1 << 5 ) +#define RIDE_PET6 ( 1 << 6 ) +#define RIDE_PET7 ( 1 << 7 ) +#define RIDE_PET8 ( 1 << 8 ) +#define RIDE_PET9 ( 1 << 9 ) +#ifdef _8_RIDEPETS +#define RIDE_PET10 ( 1 << 10 ) +#define RIDE_PET11 ( 1 << 11 ) +#define RIDE_PET12 ( 1 << 12 ) +#define RIDE_PET13 ( 1 << 13 ) +#define MAXNOINDEX 14 +#else +#define MAXNOINDEX 10 +#endif + +//andy_add 2002/6/24 +typedef struct { + int petNo; + int learnCode; +}tagRideCodeMode; + +static tagRideCodeMode RideCodeMode[] = { + { 100374, RIDE_PET0 }, + { 100358, RIDE_PET1 }, + { 100362, RIDE_PET2 }, + { 100279, RIDE_PET3 }, + { 100288, RIDE_PET4 }, + { 100283, RIDE_PET5 }, + { 100346, RIDE_PET6 }, + { 100310, RIDE_PET7 }, + { 100372, RIDE_PET8 }, + { 100373, RIDE_PET9 } +#ifdef _8_RIDEPETS + ,{ 101576, RIDE_PET10 } + ,{ 101532, RIDE_PET11 } + + ,{ 100873, RIDE_PET12 } + ,{ 100907, RIDE_PET13 } +#endif +}; + +//andy_add 2002/6/24 +typedef struct { + int RideNo[MAXNOINDEX]; +}tagRideNoList; + +static tagRideNoList RideNoList[] = { +#ifdef _8_RIDEPETS + //{ , ë, , Χ, , ɽ, , , , 챩, , , , } + { 101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009, 101989, 101978, SPR_ride278, SPR_ride266}, // ͷ + { 101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019, 101988, 101986, SPR_ride274, SPR_ride262}, // ͷ + { 101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029, 101965, 101975, SPR_ride275, SPR_ride263}, // Сβ + { 101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039, 101966, 101976, SPR_ride276, SPR_ride264}, // + { 101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049, 101973, 101984, SPR_ride284, SPR_ride272}, // Ƥֹ + { 101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059, 101974, 101985, SPR_ride285, SPR_ride273}, // + + { 101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069, 101967, 101977, SPR_ride277, SPR_ride265}, // СŮ + { 101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079, 101968, 101979, SPR_ride279, SPR_ride267}, // ٷ + { 101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089, 101970, 101981, SPR_ride281, SPR_ride269}, // Сñ + { 101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099, 101969, 101980, SPR_ride280, SPR_ride268}, // + { 101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109, 101972, 101983, SPR_ride283, SPR_ride271}, // Ů + { 101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119, 101971, 101982, SPR_ride282, SPR_ride270}, // Ů +#else + { 101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009}, + { 101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019}, + { 101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029}, + { 101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039}, + { 101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049}, + { 101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059}, + { 101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069}, + { 101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079}, + { 101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089}, + { 101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099}, + { 101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109}, + { 101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119}, +#endif +}; + +typedef struct { + int charNo; + int Noindex; +}tagRidePetList; + +static tagRidePetList RPlistMode[] = { + { 100000, 0 }, { 100005, 0 }, { 100010, 0 }, { 100015, 0 }, //С + { 100020, 1 }, { 100025, 1 }, { 100030, 1 }, { 100035, 1 }, // + { 100040, 2 }, { 100045, 2 }, { 100050, 2 }, { 100055, 2 }, //к + { 100060, 3 }, { 100065, 3 }, { 100070, 3 }, { 100075, 3 }, // + { 100080, 4 }, { 100085, 4 }, { 100090, 4 }, { 100095, 4 }, //Ƥ + { 100100, 5 }, { 100105, 5 }, { 100110, 5 }, { 100115, 5 }, // + + { 100120, 6 }, { 100125, 6 }, { 100130, 6 }, { 100135, 6 }, //С + { 100140, 7 }, { 100145, 7 }, { 100150, 7 }, { 100155, 7 }, //Ƥ + { 100160, 8 }, { 100165, 8 }, { 100170, 8 }, { 100175, 8 }, //ñ + { 100180, 9 }, { 100185, 9 }, { 100190, 9 }, { 100195, 9 }, //̷ + { 100200, 10 }, { 100205, 10 }, { 100210, 10 }, { 100215, 10 }, //Ů + { 100220, 11 }, { 100225, 11 }, { 100230, 11 }, { 100235, 11 }, // +}; + +#endif + +#ifdef _MO_IMAGE_EXTENSION +#define CG_CHR_MAKE_NEWFACE 54500 +#define SPRNEW_001em 102003 // +#define SPRNEW_001ax 102004 //ͷ ? +#define SPRNEW_001cl 102005 //ľ ??S +#define SPRNEW_001sp 102006 //ì ? +#define SPRNEW_001bw 102007 // ? + +#define SPRNEW_002em 102008 //ˮ +#define SPRNEW_002ax 102009 //ͷ ? +#define SPRNEW_002cl 102010 //ľ ??S +#define SPRNEW_002sp 102011 //ì ? +#define SPRNEW_002bw 102012 // + +#define SPRNEW_003em 102013 // +#define SPRNEW_003ax 102014 //ͷ ? +#define SPRNEW_003cl 102015 //ľ ??S +#define SPRNEW_003sp 102016 //ì ? +#define SPRNEW_003bw 102017 // + +#define SPRNEW_004em 102018 // +#define SPRNEW_004ax 102019 //ͷ ? +#define SPRNEW_004cl 102020 //ľ ??S +#define SPRNEW_004sp 102021 //ì ? +#define SPRNEW_004bw 102022 // + + +#define SPRNEW_005em 102023 // +#define SPRNEW_005ax 102024 //ͷ ? +#define SPRNEW_005cl 102025 //ľ ??S +#define SPRNEW_005sp 102026 //ì ? +#define SPRNEW_005bw 102027 // ? + +#define SPRNEW_006em 102028 //ˮ +#define SPRNEW_006ax 102029 //ͷ ? +#define SPRNEW_006cl 102030 //ľ ??S +#define SPRNEW_006sp 102031 //ì ? +#define SPRNEW_006bw 102032 // + +#define SPRNEW_007em 102033 // +#define SPRNEW_007ax 102034 //ͷ ? +#define SPRNEW_007cl 102035 //ľ ??S +#define SPRNEW_007sp 102036 //ì ? +#define SPRNEW_007bw 102037 // + +#define SPRNEW_008em 102038 // +#define SPRNEW_008ax 102039 //ͷ ? +#define SPRNEW_008cl 102040 //ľ ??S +#define SPRNEW_008sp 102041 //ì ? +#define SPRNEW_008bw 102042 // + +#define SPRNEW_009em 102043 // +#define SPRNEW_009ax 102044 //ͷ ? +#define SPRNEW_009cl 102045 //ľ ??S +#define SPRNEW_009sp 102046 //ì ? +#define SPRNEW_009bw 102047 // ? + +#define SPRNEW_010em 102048 //ˮ +#define SPRNEW_010ax 102049 //ͷ ? +#define SPRNEW_010cl 102050 //ľ ??S +#define SPRNEW_010sp 102051 //ì ? +#define SPRNEW_010bw 102052 // + +#define SPRNEW_011em 102053 // +#define SPRNEW_011ax 102054 //ͷ ? +#define SPRNEW_011cl 102055 //ľ ??S +#define SPRNEW_011sp 102056 //ì ? +#define SPRNEW_011bw 102057 // + +#define SPRNEW_012em 102058 // +#define SPRNEW_012ax 102059 //ͷ ? +#define SPRNEW_012cl 102060 //ľ ??S +#define SPRNEW_012sp 102061 //ì ? +#define SPRNEW_012bw 102062 // + + +#define SPRNEW_013em 102063 // +#define SPRNEW_013ax 102064 //ͷ ? +#define SPRNEW_013cl 102065 //ľ ??S +#define SPRNEW_013sp 102066 //ì ? +#define SPRNEW_013bw 102067 // ? + +#define SPRNEW_014em 102068 //ˮ +#define SPRNEW_014ax 102069 //ͷ ? +#define SPRNEW_014cl 102070 //ľ ??S +#define SPRNEW_014sp 102071 //ì ? +#define SPRNEW_014bw 102072 // + +#define SPRNEW_015em 102073 // +#define SPRNEW_015ax 102074 //ͷ ? +#define SPRNEW_015cl 102075 //ľ ??S +#define SPRNEW_015sp 102076 //ì ? +#define SPRNEW_015bw 102077 // + +#define SPRNEW_016em 102078 // +#define SPRNEW_016ax 102079 //ͷ ? +#define SPRNEW_016cl 102080 //ľ ??S +#define SPRNEW_016sp 102081 //ì ? +#define SPRNEW_016bw 102082 // + +#define SPRNEW_016em 102078 // +#define SPRNEW_016ax 102079 //ͷ ? +#define SPRNEW_016cl 102080 //ľ ??S +#define SPRNEW_016sp 102081 //ì ? +#define SPRNEW_016bw 102082 // + +#define SPRNEW_017em 102089 // +#define SPRNEW_017ax 102090 //ͷ ? +#define SPRNEW_017cl 102091 //ľ ??S +#define SPRNEW_017sp 102092 //ì ? +#define SPRNEW_017bw 102093 // + +#define SPRNEW_018em 102094 // +#define SPRNEW_018ax 102095 //ͷ ? +#define SPRNEW_018cl 102096 //ľ ??S +#define SPRNEW_018sp 102097 //ì ? +#define SPRNEW_018bw 102098 // + +#define SPRNEW_019em 102099 // +#define SPRNEW_019ax 102100 //ͷ ? +#define SPRNEW_019cl 102101 //ľ ??S +#define SPRNEW_019sp 102102 //ì ? +#define SPRNEW_019bw 102103 // + +#define SPRNEW_020em 102104 // +#define SPRNEW_020ax 102105 //ͷ ? +#define SPRNEW_020cl 102106 //ľ ??S +#define SPRNEW_020sp 102107 //ì ? +#define SPRNEW_020bw 102108 // + +#define SPRNEW_021em 102109 // +#define SPRNEW_021ax 102110 //ͷ ? +#define SPRNEW_021cl 102111 //ľ ??S +#define SPRNEW_021sp 102112 //ì ? +#define SPRNEW_021bw 102113 // + +#define SPRNEW_022em 102114 // +#define SPRNEW_022ax 102115 //ͷ ? +#define SPRNEW_022cl 102116 //ľ ??S +#define SPRNEW_022sp 102117 //ì ? +#define SPRNEW_022bw 102118 // + +#define SPRNEW_023em 102119 // +#define SPRNEW_023ax 102120 //ͷ ? +#define SPRNEW_023cl 102121 //ľ ??S +#define SPRNEW_023sp 102122 //ì ? +#define SPRNEW_023bw 102123 // + +#define SPRNEW_024em 102124 // +#define SPRNEW_024ax 102125 //ͷ ? +#define SPRNEW_024cl 102126 //ľ ??S +#define SPRNEW_024sp 102127 //ì ? +#define SPRNEW_024bw 102128 // +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battlebcdeb.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlebcdeb.h new file mode 100644 index 0000000..da94c32 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlebcdeb.h @@ -0,0 +1,34 @@ +#if 0 +"BC|0|0|ԢO?????|ԢO?|18837|5C|280|280|5|5|????????||187E3|4E|2CF|2CF|1|A|???||186F2|4A|149|149|5|B|???|?????b|186A5|4F|122|122|5|F|???||1880A|45|2B4|2B4|1|10|D???k??||1880A|40|25A|25A|1|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|280|280|4|5|????????||187E3|4E|25B|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|122|122|404|F|???||1880A|45|1FE|2B4|400|10|D???k??||1880A|40|25A|25A|400|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|1A9|280|4|5|????????||187E3|4E|132|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|122|122|404|F|???||1880A|45|1FE|2B4|400|10|D???k??||1880A|40|25A|25A|400|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|1A9|280|4|5|????????||187E3|4E|D6|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|C6|122|40C|F|???||1880A|45|1FE|2B4|400|10|D???k??||1880A|40|25A|25A|400|", +"BC|0|0|ԢO?????|ԢO?|18837|5C|E7|280|4|5|????????||187E3|4E|D6|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|8C|122|404|F|???||1880A|45|1FE|2B4|400|10|D???k??||1880A|40|25A|25A|400|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|5D|280|4|5|????????||187E3|4E|D6|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|8C|122|404|F|???||1880A|45|1FE|2B4|400|10|D???k??||1880A|40|129|25A|400|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|173|280|4|5|????????||187E3|4E|D6|2CF|0|A|???||186F2|4A|149|149|404|B|???|?????b|186A5|4F|8C|122|404|F|???||1880A|45|1FE|2B4|400|", + +"BC|2|0|ԢO?????|ԢO?|18837|5C|173|280|4|5|????????||187E3|4E|0|2CF|2|A|???||186F2|4A|113|149|40C|B|???|?????b|186A5|4F|8C|122|404|F|???||1880A|45|1FE|2B4|400|10|??||187C0|2F|20E|20E|0|", +"BC|0|0|ԢO?????|ԢO?|18837|5C|B5|280|4|5|???????||187B8|4E|2E5|2E5|0|A|???||186F2|4A|DD|149|40C|B|???|?????b|186A5|4F|8C|122|404|F|???||1880A|45|1FE|2B4|400|10|??||187C0|2F|20E|20E|0|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|1DB|280|4|5|???????||187B8|4E|2E5|2E5|0|A|???||186F2|4A|A7|149|40C|B|???|?????b|186A5|4F|89|122|404|F|???||1880A|45|1FE|2B4|400|10|??||187C0|2F|20E|20E|0|", +"BC|2|0|ԢO?????|ԢO?|18837|5C|1DB|280|4|5|???????||187B8|4E|2E5|2E5|0|A|???||186F2|4A|A7|149|404|B|???|?????b|186A5|4F|87|122|404|F|???||1880A|45|1FE|2B4|400|10|??||187C0|2F|172|20E|0|", +#else +"BC|14|0|ԢOɽ|ɽ|18837|5C|10E|280|4|5|???????||187B8|4E|2E5|2E5|0|A|???||186F2|4A|A7|149|404|B|???|?????b|186A5|4F|86|122|404|F|???||1880A|45|1FE|2B4|400|10|??||187C0|2F|CE|20E|0|", +"BC|14|0|ԢOɽ|ɽ|18837|5C|10E|280|4|5|???????||187B8|4E|2E0|2E5|0|A|???||186F2|4A|A7|149|404|B|???|?????b|186A5|4F|86|122|404|F|???||1880A|45|1A8|2B4|400|10|??||187C0|2F|10|20E|0|", +"BC|14|0|ԢOɽ|ɽ|18837|5C|10E|280|4|5|???????||187B8|4E|2E0|2E5|0|A|???||186F2|4A|9C|149|404|B|???|?????b|186A5|4F|86|122|404|F|???||1880A|45|108|2B4|400|10|??||187C0|2F|0|20E|2|", +#endif +"BC|14|0|ԢO?????|ԢO?|18837|5C|10E|280|4|5|???????||187B8|4E|2E0|2E5|0|A|???||186F2|4A|52|149|404|B|???|?????b|186A5|4F|86|122|404|F|???||1880A|45|108|2B4|400|10|??||187C0|2F|0|20E|2|", + + + + + + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemap.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemap.h new file mode 100644 index 0000000..a295f56 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemap.h @@ -0,0 +1,19 @@ +/************************/ +/* battleMap.h */ +/************************/ +#ifndef _BATTLE_MAP_H_ +#define _BATTLE_MAP_H_ + +// ???????????? +#define BATTLE_MAP_FILES 220 + +// ?????????k? +extern int BattleMapNo; + +// ?????????????????????? ***************************/ +BOOL ReadBattleMap( int no ); + +// ??????? ***********************************************************/ +void DrawBattleMap( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemapname.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemapname.h new file mode 100644 index 0000000..d31cf5a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemapname.h @@ -0,0 +1,221 @@ +// ?????? ???? +"data\\battleMap\\battle00.sabex", // U??? +"data\\battleMap\\battle01.sabex", // U??? +"data\\battleMap\\battle02.sabex", // U??? +"data\\battleMap\\battle03.sabex", // U????? +"data\\battleMap\\battle04.sabex", // U????? +"data\\battleMap\\battle05.sabex", // U????? +"data\\battleMap\\battle06.sabex", // ???? +"data\\battleMap\\battle07.sabex", // ???? +"data\\battleMap\\battle08.sabex", // ???? +"data\\battleMap\\battle09.sabex", // ???? +"data\\battleMap\\battle10.sabex", // ???? +"data\\battleMap\\battle11.sabex", // ???? +"data\\battleMap\\battle12.sabex", // U???????? +"data\\battleMap\\battle13.sabex", // U???????? +"data\\battleMap\\battle14.sabex", // U???????? +"data\\battleMap\\battle15.sabex", // U???????? +"data\\battleMap\\battle16.sabex", // U???????? +"data\\battleMap\\battle17.sabex", // U???????? +"data\\battleMap\\battle18.sabex", // ????????? +"data\\battleMap\\battle19.sabex", // ????????? +"data\\battleMap\\battle20.sabex", // ????????? +"data\\battleMap\\battle21.sabex", // ???????? +"data\\battleMap\\battle22.sabex", // ???????? +"data\\battleMap\\battle23.sabex", // ???????? +"data\\battleMap\\battle24.sabex", // ????????? +"data\\battleMap\\battle25.sabex", // ????????? +"data\\battleMap\\battle26.sabex", // ????????? +"data\\battleMap\\battle27.sabex", // ???? +"data\\battleMap\\battle28.sabex", // ???? +"data\\battleMap\\battle29.sabex", // ???? +"data\\battleMap\\battle30.sabex", // U??? +"data\\battleMap\\battle31.sabex", // U??? +"data\\battleMap\\battle32.sabex", // U??? +"data\\battleMap\\battle33.sabex", // U???????? +"data\\battleMap\\battle34.sabex", // U???????? +"data\\battleMap\\battle35.sabex", // U???????? +"data\\battleMap\\battle36.sabex", // U???????? +"data\\battleMap\\battle37.sabex", // U???????? +"data\\battleMap\\battle38.sabex", // U???????? +"data\\battleMap\\battle39.sabex", // ? +"data\\battleMap\\battle40.sabex", // ? +"data\\battleMap\\battle41.sabex", // ? +"data\\battleMap\\battle42.sabex", // U??? +"data\\battleMap\\battle43.sabex", // U??? +"data\\battleMap\\battle44.sabex", // U??? +"data\\battleMap\\battle45.sabex", // U??U????? +"data\\battleMap\\battle46.sabex", // U??U????? +"data\\battleMap\\battle47.sabex", // U??U????? +"data\\battleMap\\battle48.sabex", // q??????? +"data\\battleMap\\battle49.sabex", // q??????? +"data\\battleMap\\battle50.sabex", // q??????? +"data\\battleMap\\battle51.sabex", // U?????h?? +"data\\battleMap\\battle52.sabex", // U?????h?? +"data\\battleMap\\battle53.sabex", // U?????h?? +"data\\battleMap\\battle54.sabex", // U?????h?? +"data\\battleMap\\battle55.sabex", // U?????h?? +"data\\battleMap\\battle56.sabex", // U?????h?? +"data\\battleMap\\battle57.sabex", // U?????h?? +"data\\battleMap\\battle58.sabex", // U?????h?? +"data\\battleMap\\battle59.sabex", // U?????h?? +"data\\battleMap\\battle60.sabex", // ??????h?? +"data\\battleMap\\battle61.sabex", // ??????h?? +"data\\battleMap\\battle62.sabex", // ??????h?? +"data\\battleMap\\battle63.sabex", // ??????h?? +"data\\battleMap\\battle64.sabex", // ??????h?? +"data\\battleMap\\battle65.sabex", // ??????h?? +"data\\battleMap\\battle66.sabex", // U??U????? +"data\\battleMap\\battle67.sabex", // U??U????? +"data\\battleMap\\battle68.sabex", // U??U????? +"data\\battleMap\\battle69.sabex", // s???????U? +"data\\battleMap\\battle70.sabex", // s???????U? +"data\\battleMap\\battle71.sabex", // s???????U? +"data\\battleMap\\battle72.sabex", // ????????U? +"data\\battleMap\\battle73.sabex", // ????????U? +"data\\battleMap\\battle74.sabex", // ????????U? +"data\\battleMap\\battle75.sabex", // ??????????? +"data\\battleMap\\battle76.sabex", // ??????????? +"data\\battleMap\\battle77.sabex", // ??????????? +"data\\battleMap\\battle78.sabex", // ??????????? +"data\\battleMap\\battle79.sabex", // ??????????? +"data\\battleMap\\battle80.sabex", // ??????????? +"data\\battleMap\\battle81.sabex", // ????????? +"data\\battleMap\\battle82.sabex", // ????????? +"data\\battleMap\\battle83.sabex", // ????????? +"data\\battleMap\\battle84.sabex", // s???????U??????? +"data\\battleMap\\battle85.sabex", // s???????U??????? +"data\\battleMap\\battle86.sabex", // s???????U??????? +"data\\battleMap\\battle87.sabex", // ???????? +"data\\battleMap\\battle88.sabex", // ???????? +"data\\battleMap\\battle89.sabex", // ???????? +"data\\battleMap\\battle90.sabex", // s???????U??????? +"data\\battleMap\\battle91.sabex", // s???????U??????? +"data\\battleMap\\battle92.sabex", // s???????U??????? +"data\\battleMap\\battle93.sabex", // ????????? +"data\\battleMap\\battle94.sabex", // ????????? +"data\\battleMap\\battle95.sabex", // ????????? +"data\\battleMap\\battle96.sabex", // s???????U?????????U???? +"data\\battleMap\\battle97.sabex", // s???????U?????????U???? +"data\\battleMap\\battle98.sabex", // s???????U?????????U???? +"data\\battleMap\\battle99.sabex", // ??V???? +"data\\battleMap\\battle100.sabex", // ??V???? +"data\\battleMap\\battle101.sabex", // ??V???? +"data\\battleMap\\battle102.sabex", // ??V???? +"data\\battleMap\\battle103.sabex", // ??V???? +"data\\battleMap\\battle104.sabex", // ??V???? +"data\\battleMap\\battle105.sabex", // ?? +"data\\battleMap\\battle106.sabex", // ?? +"data\\battleMap\\battle107.sabex", // ?? +"data\\battleMap\\battle108.sabex", // ??U????? +"data\\battleMap\\battle109.sabex", // ??U????? +"data\\battleMap\\battle110.sabex", // ??U????? +"data\\battleMap\\battle111.sabex", // ??????? +"data\\battleMap\\battle112.sabex", // ??????? +"data\\battleMap\\battle113.sabex", // ??????? +"data\\battleMap\\battle114.sabex", // ??????????? +"data\\battleMap\\battle115.sabex", // ??????????? +"data\\battleMap\\battle116.sabex", // ??????????? +"data\\battleMap\\battle117.sabex", // ?????????? +"data\\battleMap\\battle118.sabex", // ?????????? +"data\\battleMap\\battle119.sabex", // ?????????? +"data\\battleMap\\battle120.sabex", // ??U???????? +"data\\battleMap\\battle121.sabex", // ??U???????? +"data\\battleMap\\battle122.sabex", // ??U???????? +"data\\battleMap\\battle123.sabex", // ??n???? +"data\\battleMap\\battle124.sabex", // ??n???? +"data\\battleMap\\battle125.sabex", // ??n???? +"data\\battleMap\\battle126.sabex", // ??n???? +"data\\battleMap\\battle127.sabex", // ??n???? +"data\\battleMap\\battle128.sabex", // ??n???? +"data\\battleMap\\battle129.sabex", // ?n?? +"data\\battleMap\\battle130.sabex", // ?n?? +"data\\battleMap\\battle131.sabex", // ?n?? +"data\\battleMap\\battle132.sabex", // X?? +"data\\battleMap\\battle133.sabex", // X?? +"data\\battleMap\\battle134.sabex", // X?? +"data\\battleMap\\battle135.sabex", // ?n?? +"data\\battleMap\\battle136.sabex", // ?n?? +"data\\battleMap\\battle137.sabex", // ?n?? +"data\\battleMap\\battle138.sabex", // ??????? +"data\\battleMap\\battle139.sabex", // ??????? +"data\\battleMap\\battle140.sabex", // ??????? +"data\\battleMap\\battle141.sabex", // ??????? +"data\\battleMap\\battle142.sabex", // ??????? +"data\\battleMap\\battle143.sabex", // ??????? +"data\\battleMap\\battle144.sabex", // ??? +"data\\battleMap\\battle145.sabex", // s +"data\\battleMap\\battle146.sabex", // f??? +"data\\battleMap\\battle147.sabex", // f??? +"data\\battleMap\\battle148.sabex", // ??? +"data\\battleMap\\battle149.sabex", // ??? +"data\\battleMap\\battle150.sabex", // ??? +"data\\battleMap\\battle151.sabex", // ???????? +"data\\battleMap\\battle152.sabex", // ???????? +"data\\battleMap\\battle153.sabex", // ???????? +"data\\battleMap\\battle154.sabex", // ????????? +"data\\battleMap\\battle155.sabex", // ????????? +"data\\battleMap\\battle156.sabex", // ????????? +"data\\battleMap\\battle157.sabex", // ????????? +"data\\battleMap\\battle158.sabex", // ????????? +"data\\battleMap\\battle159.sabex", // ????????? +"data\\battleMap\\battle160.sabex", // ????????? +"data\\battleMap\\battle161.sabex", // ????????? +"data\\battleMap\\battle162.sabex", // ????????? +"data\\battleMap\\battle163.sabex", // ???U????? +"data\\battleMap\\battle164.sabex", // ???U????? +"data\\battleMap\\battle165.sabex", // ???U????? +"data\\battleMap\\battle166.sabex", // ???U????? +"data\\battleMap\\battle167.sabex", // ???U????? +"data\\battleMap\\battle168.sabex", // ???U????? +"data\\battleMap\\battle169.sabex", // ??????? +"data\\battleMap\\battle170.sabex", // ??????? +"data\\battleMap\\battle171.sabex", // ??????? +"data\\battleMap\\battle172.sabex", // ??????? +"data\\battleMap\\battle173.sabex", // ??????? +"data\\battleMap\\battle174.sabex", // ??????? +"data\\battleMap\\battle175.sabex", // ??????????????? +"data\\battleMap\\battle176.sabex", // ??????????????? +"data\\battleMap\\battle177.sabex", // ??????????????? +"data\\battleMap\\battle178.sabex", // ??????????? +"data\\battleMap\\battle179.sabex", // ??????????? +"data\\battleMap\\battle180.sabex", // ??????????? +"data\\battleMap\\battle181.sabex", // ???????? +"data\\battleMap\\battle182.sabex", // ???????? +"data\\battleMap\\battle183.sabex", // ???????? +"data\\battleMap\\battle184.sabex", // ??????????? +"data\\battleMap\\battle185.sabex", // ??????????? +"data\\battleMap\\battle186.sabex", // ??????????? +"data\\battleMap\\battle187.sabex", // ??????????? +"data\\battleMap\\battle188.sabex", // ??????????? +"data\\battleMap\\battle189.sabex", // ??????????? +"data\\battleMap\\battle190.sabex", // ??????????? +"data\\battleMap\\battle191.sabex", // ??????????? +"data\\battleMap\\battle192.sabex", // ??????????? +"data\\battleMap\\battle193.sabex", // ?????U????? +"data\\battleMap\\battle194.sabex", // ?????U????? +"data\\battleMap\\battle195.sabex", // ?????U????? +"data\\battleMap\\battle196.sabex", // ?????U????? +"data\\battleMap\\battle197.sabex", // ?????U????? +"data\\battleMap\\battle198.sabex", // ?????U????? +"data\\battleMap\\battle199.sabex", // ?????Z +"data\\battleMap\\battle200.sabex", // ?????Z +"data\\battleMap\\battle201.sabex", // U????? +"data\\battleMap\\battle202.sabex", // U??????? +"data\\battleMap\\battle203.sabex", // U?????????? +"data\\battleMap\\battle204.sabex", // U??U??????? +"data\\battleMap\\battle205.sabex", // q????????? +"data\\battleMap\\battle206.sabex", // U?????h???? +"data\\battleMap\\battle207.sabex", // ????????????? +"data\\battleMap\\battle208.sabex", // ??????????? +"data\\battleMap\\battle209.sabex", // ????????????? +"data\\battleMap\\battle210.sabex", // ???????????? +"data\\battleMap\\battle211.sabex", // ??U?????????? +"data\\battleMap\\battle212.sabex", // ?n???? +"data\\battleMap\\battle213.sabex", // ?n???? +"data\\battleMap\\battle214.sabex", // ?n???? +"data\\battleMap\\battle215.sabex", // ???U??????? +"data\\battleMap\\battle216.sabex", // ?????U??????? +"data\\battleMap\\battle217.sabex", // ?????U??????? +"data\\battleMap\\battle218.sabex", // ?????? +"data\\battleMap\\battle219.sabex", // \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemenu.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemenu.h new file mode 100644 index 0000000..86a8066 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemenu.h @@ -0,0 +1,107 @@ +/************************/ +/* battleMenu.h */ +/************************/ +#ifndef _BATTLE_MENU_H_ +#define _BATTLE_MENU_H_ + +#define AI_NONE 0 +#define AI_ATTACK 1 +#define AI_GUARD 2 +#define AI_SELECT 3 +#define AI_ESCAPE 4 + +extern int AI; +extern DWORD PauseAI; + +// BattleBpFlag????ѩ +#define BATTLE_BP_JOIN ( 1 << 0 ) // ӡP +#define BATTLE_BP_PLAYER_MENU_NON ( 1 << 1 ) // ??????????? +#define BATTLE_BP_BOOMERANG ( 1 << 2 ) // ????? +#define BATTLE_BP_PET_MENU_NON ( 1 << 3 ) // ????????? +#define BATTLE_BP_ENEMY_SURPRISAL ( 1 << 4 ) // ??e???????????? +#define BATTLE_BP_PLAYER_SURPRISAL ( 1 << 5 ) // ???????e????? + +// ?????????? +#define BATTLE_BUF_SIZE 4 +#define BATTLE_COMMAND_SIZE 4096 +// ????????? +extern char BattleCmd[ BATTLE_COMMAND_SIZE ]; +extern char BattleCmdBak[ BATTLE_BUF_SIZE ][ BATTLE_COMMAND_SIZE ]; +// ?????????????? +extern int BattleCmdReadPointer; +extern int BattleCmdWritePointer; +// ??????????????? +//extern char BattleCmdBak[]; +// ???֢t?? +extern char BattleStatus[ BATTLE_COMMAND_SIZE ]; +extern char BattleStatusBak[ BATTLE_BUF_SIZE ][ BATTLE_COMMAND_SIZE ]; +// ???֢t??????? +extern int BattleStatusReadPointer; +extern int BattleStatusWritePointer; + +// ???֢t???????? +//extern char BattleStatusBak[]; +// ???֢t???????? +//extern char BattleStatusBak2[]; +// ?????????? +extern int battleMenuFlag2; +// ??k? +extern int BattleMyNo; +// Pf????? +extern int BattleMyMp; +// Pf????? +extern int BattleEscFlag; +// ???????????? +extern int BattlePetStMenCnt; +// ӡP???k??????? +extern int battlePetNoBak; +// ӡP???k???????? +extern int battlePetNoBak2; + +// ????? +extern int BattleBpFlag; +// ????V?????? +extern int BattleAnimFlag; +// ?????? +extern BOOL BattleTurnReceiveFlag; +#ifdef PK_SYSTEM_TIMER_BY_ZHU +extern BOOL BattleCntDownRest; +extern BOOL SendToServer; +extern DWORD BattleCntDown; +#define BATTLE_CNT_DOWN_TIME 30000 +#endif +extern int BattleCliTurnNo; +// ??????????k? +extern int BattleSvTurnNo; + +// Pf?????????? +extern BOOL BattleResultWndFlag; + +#ifdef _HUNDRED_KILL +extern BOOL BattleHundredFlag; +#endif + +// ????????? *********************************************************/ +void BattleMenuProc( void ); +// ??????u??? *****************************************************/ +void ClearBattleButton( void ); +// ?????????? ********************************************************/ +void InitBattleMenu( void ); +// ????V??????????? ********************************************/ +void CheckBattleAnimFlag( void ); +// ???K?????? ********************************************/ +int CheckBattle1P2P( void ); +// o?????? ***********************************************************/ +void HpMeterDisp( int no ); +// q? ************************************************************************/ +void BattleNameDisp( void ); +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ +void BattleSetWazaHitBox( int no , int typeflag ) ; +#endif +#ifdef PK_SYSTEM_TIMER_BY_ZHU +void BattleDown(); +#endif +void battleMenuFix(void); // ޸սAIתBUG + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemvdeb.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemvdeb.h new file mode 100644 index 0000000..7271a6b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battlemvdeb.h @@ -0,0 +1,42 @@ +#if 0 +"BJ|a0|m58|e188F8|e188FD|rA|rB|rF|r10|FF|BH|aF|r5|f2|d74|FF|BH|a10|r5|f20|d0|FF|BH|a5|rA|f202|dB6|gF|FF|BJ|aB|m46|e188F8|e188FE|rA|rB|rF|r10|FF|BR|A|1|BR|B|1|BR|F|1|BR|10|1|BV|A|2|", +"BJ|a0|m4C|e188F8|e188FD|rA|rB|rF|r10|FF|BH|aF|r5|f2|d129|FF|BH|a5|rA|f20|d0|FF|BH|a10|r0|f2|dD7|FF|BH|aB|r0|f20|d0|r0|f20|d0|FF|BJ|aA|m4A|e188F8|e18902|rF|FF|", +"BJ|a0|m40|e188F8|e188FD|rA|rB|rF|r10|FF|BM|B|1|BH|aF|r5|f2|d5C|FF|BH|a5|rB|fA|d22|FF|BH|a10|r0|f20|d0|FF|BD|rB|0|0|3A|bg|b|BJ|aA|m36|e188F8|e18902|rA|FF|", +"BH|a0|rB|f20|d0|FF|BH|a10|r0|f2|dC2|FF|BH|aF|r0|f20|d0|FF|bn|5|bt|5|BD|rB|0|0|3A|BJ|aB|m31|e188F8|e188FC|rA|rB|rF|r10|FF|BM|B|0|BJ|aA|m22|e188F8|e18902|rB|FF|BV|15|0|", +"BH|a0|rB|f402|d88|FF|BN|aB|186A5|BH|a5|r10|f2|d131|FF|BH|aF|r0|f20|d0|FF|BH|a10|r0|f2|d2|FF|BV|A|2|", +"BJ|a0|m2C|e188F8|e188FA|r0|FF|BD|r0|0|1|d117|BH|a5|r10|f45|d13E|FF|BH|aF|r0|f20|d0|FF|BB|aB|w1|r0|f2|d1|FF|BJ|aA|m8|e188F8|e18902|FF|", +"BJ|a0|m20|e188F8|e188FD|rA|rB|rF|FF|BM|A|1|BH|a5|rF|f403|d10E|FF|BH|aF|r0|f20|d0|FF|BS|sB|f1|g187C0|l2F|h20E|??|m20E|BD|rA|0|0|36|BH|aA|r0|f20|d0|FF|", + +"BS|s0|f0|BS|s0|f1|g187B8|l4E|h2E5|???????|m2E5|BH|aF|r0|f20|d0|FF|bg|b|BH|a10|r0|f2|dBE|FF|BD|rA|0|0|36|BH|aA|r0|f20|d0|FF|BV|15|0|", +"BJ|a0|mC|e188F8|e188FA|r0|FF|BD|r0|0|1|d126|BH|a5|rB|fA|d3|FF|BH|aF|r0|f20|d0|FF|bg|b|BH|a10|r0|f20|d0|FF|BD|rA|0|0|36|BV|A|2|", +"BH|a0|r10|f2|d9C|FF|BH|a5|rB|fA|d2|FF|BH|aF|r0|f20|d0|FF|bg|b|BM|A|0|bg|a|BM|A|0|BH|a10|r0|f20|d0|FF|", +"BH|a0|r10|f2|dA4|FF|BH|aF|r0|f20|d0|FF|BH|a5|rB|fA|d1|FF|bg|b|BH|a10|r0|f4|dCD|FF|bg|a|", + +#else +"BH|a0|r17|f4|dBE|FF|BH|aF|r0|f20|d0|rF|f10|counter56|FF|BH|a5|rC|f402|d5|FF|bg|b|bg|a|BH|a10|r0|f20|d0|r10|f30|counter0|FF|BV|15|0|", +"BH|a0|r10|f3|dC6|FF|BH|a5|rC|fA|dB|FF|BH|aF|r0|f20|d0|rF|f14|counterA0|FF|bg|b|bg|a|", +"BY|r10|a0|fC|d49|a5|fA|d1|FF|BH|aF|r0|f20|d0|FF|BJ|aB|m31|e188F8|e188FD|r0|FF|bg|a|", +#endif +"BH|a0|r17|f45|dCD|FF|BH|a5|rF|f2|dEA|FF|BH|aF|r0|f20|d0|rF|f15|counterBA|FF|bg|a|", + + + + + + + + + + + + + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/battleproc.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/battleproc.h new file mode 100644 index 0000000..b99b17e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/battleproc.h @@ -0,0 +1,38 @@ +/************************/ +/* battleProc.h */ +/************************/ +#ifndef _BATTLE_PROC_H_ +#define _BATTLE_PROC_H_ + +// ??????? ??????k? +enum{ + BATTLE_SUBPROC_INIT, // ???? + BATTLE_SUBPROC_IN_PRODUCE, // ??????? + BATTLE_SUBPROC_RECEIVE_BC, // ???r? + BATTLE_SUBPROC_CHAR_IN, // ?K? + BATTLE_SUBPROC_CMD_INPUT, // ?????V? + BATTLE_SUBPROC_RECEIVE_MOVIE, // ?????r? + BATTLE_SUBPROC_MOVIE, // ??????? + BATTLE_SUBPROC_OUT_PRODUCE_INIT, // ?????? + BATTLE_SUBPROC_OUT_PRODUCE, // ??? +}; + +// ????????? +extern BOOL EncountFlag; +// ?????? +extern BOOL NoHelpFlag; +#ifdef _MAGIC_NOCAST//Ĭ +extern BOOL NoCastFlag; +#endif +// ??????????? +extern BOOL EncountOffFlag; +// ??????? +extern BOOL DuelFlag; + +// ?????????? +extern int BattleDebTurnNo; +// ??????? +void BattleProc( void ); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/character.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/character.h new file mode 100644 index 0000000..27a1dc9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/character.h @@ -0,0 +1,341 @@ +#ifndef _CHARACTER_H_ +#define _CHARACTER_H_ + +#include"action.h" +#include"pc.h" + +enum +{ + CHR_STATUS_P = 0x0001, // + CHR_STATUS_N = 0x0002, // ?? + CHR_STATUS_Q = 0x0004, // ? + CHR_STATUS_S = 0x0008, // ? + CHR_STATUS_D = 0x0010, // ?? + CHR_STATUS_C = 0x0020, // ?? + CHR_STATUS_W = 0x0040, // ?????? + CHR_STATUS_H = 0x0080, // ?????? + CHR_STATUS_LEADER = 0x0100, // ???? + CHR_STATUS_PARTY = 0x0200, // ??????? + CHR_STATUS_BATTLE = 0x0400, // Pf? + CHR_STATUS_USE_MAGIC= 0x0800, // ? + CHR_STATUS_HELP = 0x1000, // ??? + CHR_STATUS_FUKIDASHI= 0x2000, // ??? + CHR_STATUS_WATCH = 0x4000, // ?P? + CHR_STATUS_TRADE = 0x8000, // +#ifdef _ANGEL_SUMMON + CHR_STATUS_ANGEL = 0x10000 // ʹ +#endif +}; + +enum +{ // ???????? + CHAROBJ_TYPE_NPC = 0x0001, // NPC + CHAROBJ_TYPE_ITEM = 0x0002, // ???? + CHAROBJ_TYPE_MONEY = 0x0004, // ?? + CHAROBJ_TYPE_USER_NPC = 0x0008, // \?????? + CHAROBJ_TYPE_LOOKAT = 0x0010, // ??? + CHAROBJ_TYPE_PARTY_OK = 0x0020, // ?????V?? + CHAROBJ_TYPE_ALL = 0x00FF // u? +}; + +// ???????k? +enum +{ + CHAR_TYPENONE, // ????? + CHAR_TYPEPLAYER, // ????? + CHAR_TYPEENEMY, // + CHAR_TYPEPET, // ??? + CHAR_TYPEDOOR, // ?? + CHAR_TYPEBOX , // ? + CHAR_TYPEMSG , // ?Y + CHAR_TYPEWARP , // ?????? + CHAR_TYPESHOP , // + CHAR_TYPEHEALER , // ???? + CHAR_TYPEOLDMAN , // ? + CHAR_TYPEROOMADMIN, // ۥh? + CHAR_TYPETOWNPEOPLE, // ????? + CHAR_TYPEDENGON, // ?\ + CHAR_TYPEADM, // ?\ + CHAR_TYPETEMPLE, // Temple master + CHAR_TYPESTORYTELLER, // ??? + CHAR_TYPERANKING, // ۥh???????? + CHAR_TYPEOTHERNPC, // ??\???n?????NPC + CHAR_TYPEPRINTPASSMAN, // ??????????NPC + CHAR_TYPENPCENEMY, // ?e + CHAR_TYPEACTION, // ??????T???NPC + CHAR_TYPEWINDOWMAN, // ???????NPC??????) + CHAR_TYPESAVEPOINT, // ??????? + CHAR_TYPEWINDOWHEALER, // ????????????? + CHAR_TYPEITEMSHOP, // ? + CHAR_TYPESTONESHOP, // l????????? + CHAR_TYPEDUELRANKING, // DUEL?????NPC + CHAR_TYPEWARPMAN, // ?????NPC + CHAR_TYPEEVENT, // ????NPC + CHAR_TYPEMIC, // ????NPC + CHAR_TYPELUCKYMAN, // ????NPC + CHAR_TYPEBUS, // ?????? + CHAR_TYPECHARM, // ????NPC + CHAR_TYPENUM +}; + +typedef struct +{ + short use; // ??? + short type; // ? + int id; // ??????k? + int graNo; // ??????k? + int gx, gy; // ????? + int level; // ??? + int dir; // ?? + int stockDir; // ?h???????????? + int stockDirX, stockDirY;// stockDir????? + short nameColor; // q?? +#ifdef _ANGEL_SUMMON + unsigned status; // ????? +#else + unsigned short status; // ????? +#endif + int classNo; // ???????? + int money; // ??? + char name[CHAR_NAME_LEN+1]; // q + char freeName[CHAR_FREENAME_LEN+1]; // ??????? + char info[64]; // ????????????ACTION?V?????????? + int battleNo; // Pfk? + short sideNo; // Pf?????????N????? + short helpMode; // ?????? + int charType; // ??????@e??N + short newFoundFlag; // D???????????????? + ACTION *ptAct; + int charNameColor; // ???????????q? + // shan add + char fmname[CHAR_FMNAME_LEN+1]; // + // Robin + char petName[CHAR_FREENAME_LEN+1]; + int petLevel; + +//#ifdef _CHAR_PROFESSION // WON ADD ְҵ +// int profession_class; +//#endif + +} CHAROBJ; + +typedef struct +{ + int charObjTblId; // ????????k??V????? + unsigned int drawFukidashiTime; // ??????? + ACTION *ptActLeaderMark; // ???????? + ACTION *ptActMagicEffect; // ????? +#ifdef __EMOTION + ACTION *ptActEmotion; +#endif +#ifdef _MIND_ICON + ACTION *ptMindIcon; +#endif +#ifdef _SHOWFAMILYBADGE_ + ACTION *ptFamilyIcon; +#endif +#ifdef FAMILY_MANOR_ + ACTION *ptmFamilyIcon; +#endif +#ifdef _CHAR_MANOR_ + ACTION *ptmManorIcon; +#endif +#ifdef _CHARTITLE_ + ACTION *ptTitleIcon; +#endif +#ifdef _STREET_VENDOR + ACTION *ptStreetVendor; +#endif +#ifdef _ANGEL_SUMMON + ACTION *ptActAngelMark; +#endif +#ifdef _ITEM_FIREWORK + ACTION *pActFirework[2]; +#endif +#ifdef _NPC_MAGICCARD + ACTION *pActMagiccard[4]; +#endif +#ifdef _NPC_PICTURE + ACTION *ptActPicture; +#endif +#ifdef _NPC_EVENT_NOTICE + ACTION *ptNoticeIcon; +#endif +} CHAREXTRA; + +typedef struct +{ + short mode; // ????h???? + short moveDir; // ?h?????? + short preDir; // ???q??????? + short dirCnt; // ?Q??????? + int preGx, preGy; // ???q????? + int walkCnt; // ?h? + unsigned int createTime; // ??? + ACTION *ptAct; + ACTION *ptAct2; + float angle; + int r; + int id; // ??????k? +} PETEXTRA; + +#ifdef _NPC_MAGICCARD +struct Posstruct +{ + int humanX; + int humanY; + int petX; + int petY; + int magic1X; + int magic1Y; + //int offsetX; //ӫĻλʱ + //int offsetY; + +}; +#endif + +extern short nameOverTheHeadFlag; + +void charMove( ACTION * ); +void charMove2( ACTION * ); +void _charMove( ACTION * ); +void shiftBufCount( ACTION * ); + +ACTION *createCharAction( int, int, int, int ); + +#ifdef _WATERANIMATION //Syu ADD ֮ +ACTION *createWaterAnimation( int , int , int , int ); +#endif + +void stockCharMovePoint( ACTION *, int, int ); +void correctCharMovePoint( ACTION *, int, int ); + +void setCharMovePoint( ACTION *, int, int ); +void _setCharMovePoint( ACTION *, int, int ); +void setCharWarpPoint( ACTION *, int, int ); +void setCharStatus( unsigned short *, char * ); + +ACTION *createCommmonEffectAction( int, int, int, int, int, int ); +ACTION *createCommmonEffectNoLoop( int, int, int, int, int, int ); +void drawCharStatus( ACTION * ); + +void changeCharAct( ACTION *, int, int, int, int, int, int, int ); + +void setCharLeader( ACTION * ); +void delCharLeader( ACTION * ); +void setCharParty( ACTION * ); +void delCharParty( ACTION * ); +void setCharWatch( ACTION * ); +void delCharWatch( ACTION * ); +void setCharBattle( ACTION *, int, short, short ); +void delCharBattle( ACTION * ); +void setCharTrade( ACTION *, int ); +void delCharTrade( ACTION * ); +void setCharUseMagic( ACTION * ); +void delCharUseMagic( ACTION * ); +#ifdef _ANGEL_SUMMON +void setCharAngel( ACTION * ); +void delCharAngel( ACTION * ); +#endif + + +#ifdef _MIND_ICON +void setCharMind( ACTION *ptAct, int MindNo); +void delCharMind( ACTION *ptAct); +#endif +#ifdef _SHOWFAMILYBADGE_ +void setCharFamily( ACTION *ptAct, int MindNo); +void delCharFamily( ACTION *ptAct); +#endif +#ifdef FAMILY_MANOR_ +void setCharmFamily( ACTION *ptAct, int MindNo); +void delCharmFamily( ACTION *ptAct); +#endif +#ifdef _CHAR_MANOR_ +void setCharmManor( ACTION *ptAct, int MindNo); +void delCharmManor( ACTION *ptAct); +#endif + + + +#ifdef _CHARTITLE_ +void setCharmTitle( ACTION *ptAct, int MindNo); +void delCharmTitle( ACTION *ptAct); +#endif +#ifdef _NPC_EVENT_NOTICE +void setNpcNotice( ACTION *ptAct, int MindNo); +void delNpcNotice( ACTION *ptAct); +#endif + +void setCharFukidashi( ACTION *, unsigned int ); +void setCharNameColor( ACTION *, int ); + + +BOOL checkCharObjPoint( int, int, short ); +#ifdef _ANGEL_SUMMON +int checkCharObjPointStatus( int, int, short, unsigned ); +int checkCharObjPointNotStatus( int, int, short, unsigned ); +#else +int checkCharObjPointStatus( int, int, short, unsigned short ); +int checkCharObjPointNotStatus( int, int, short, unsigned short ); +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _GM_IDENTIFY // Rog ADD GMʶ + void setNpcCharObj( int, int, int, int, int, char *, char *, char *, int, char *, int, int, int, int, int, int, char *); + #else + #ifdef _NPC_PICTURE + void setNpcCharObj( int, int, int, int, int, char *, char *, char *, int, char *, int, int, int, int, int, int, int ); + #else + void setNpcCharObj( int, int, int, int, int, char *, char *, char *, int, char *, int, int, int, int, int, int ); + #endif + #endif +#else + #ifdef _NPC_EVENT_NOTICE + void setNpcCharObj( int, int, int, int, int, char *, char *, char *, int, char *, int, int, int, int, int, int +#ifdef _CHARTITLE_STR_ + ,char * +#endif + ); + #else + void setNpcCharObj( int, int, int, int, int, char *, char *, char *, int, char *, int, int, int, int, int); + #endif +#endif + +BOOL setReturnPetObj( int, int, int, int, int, char *, char *, int, int, int, int, int ); +void setItemCharObj( int, int, int, int, int, int, char * ); +void setMoneyCharObj( int, int, int, int, int, int, char * ); +int getAtrCharType( int ); +int getAtrCharObjType( int ); +void delCharObj( int ); +void initCharObj( void ); +void resetCharObj( void ); +void clearPtActCharObj( void ); +void restorePtActCharObjAll( void ); +void restorePtActCharObj( int ); +void setMovePointCharObj( int, int, int ); +ACTION *getCharObjAct( int ); + +int getCharObjBuf( void ); + +void initItemOverlapCheck( void ); +BOOL itemOverlapCheck( unsigned int, int, int ); + +ACTION *createPetAction( int, int, int, int, int, int, int ); +void ajustClientDir( short * ); + +#endif +#ifdef _WIN_LUAJIT_ +typedef struct{ + char data[25][100]; + int len[25]; +}SA_MESSAGE; + +typedef struct{ + ACTION *ptActMenuWin; + STR_BUFFER input; + SA_MESSAGE message; + int totalMsgLine; +}SA_WINDOWS; +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/chat.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/chat.h new file mode 100644 index 0000000..04ae8f2 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/chat.h @@ -0,0 +1,156 @@ +/************************/ +/* chat.h */ +/************************/ +#ifndef _CHAT_H_ +#define _CHAT_H_ +//cary 256 -> 260 +#define STR_BUFFER_SIZE 260 // ??????????? +#ifdef _NEW_RESOMODE +#ifdef _SA_LIAOTIAN_ + #define MAX_CHAT_LINE 200 // +#else + #define MAX_CHAT_LINE 20 // +#endif +#else + #define MAX_CHAT_LINE 20 // +#endif +#define DEF_CHAT_LINE 20 // ??@e??????? +#define MAX_CHAT_HISTORY 64 // ??????????? +#define DEF_VOICE 3 // ???????? +#define MAX_VOICE 10 // ???????k + +#define NORMAL_TYPE 0 +#define BLIND_TYPE 1 +#define NUMBER_TYPE 2 + +#ifdef _SAHOOK //Syu ADD Hookʽ +#define HOOK_TYPE 3 +#endif +// ????????Bl + +typedef struct{ + char buffer[ STR_BUFFER_SIZE ]; // ?????????? + unsigned char len; // ??? + unsigned char lineLen; // ?????? + unsigned char lineDist; // ????????????? + unsigned char cnt; // ?????? + unsigned char color; // ?? + unsigned char cursor; //αλ + int x, y; // ???? + int imeX, imeY; // ???????? + int fontPrio; // ??IT + BOOL filterFlag; // ??????????????? + int hitFontNo; // ???k?????????Re?? + +}STR_BUFFER; + +typedef struct _CHAT_BUFFER{ + char buffer[ STR_BUFFER_SIZE + 1 ]; // ?????????? + unsigned char color; +#ifdef _MO_CHAT_EXPRESSION + int BmpNo; + int x; + _CHAT_BUFFER * NextChatBuffer; +#endif +#ifdef _FONT_SIZE + int fontsize; +#endif +}CHAT_BUFFER; + +// ???????????Bl +typedef struct{ + char str[ MAX_CHAT_HISTORY ][ STR_BUFFER_SIZE + 1 ]; // ???????????? + int newNo; // ???????????k? + int nowNo; // ????????????k? +}CHAT_HISTORY; + +// onlinegm¼ +typedef struct{ + char str[115][STR_BUFFER_SIZE + 1 ]; + int newNo; + int nowNo; + int addNo; + int lockNo; + BOOL color[115]; +}INPUT_HISTORY; + +// ??????????????????????? +extern STR_BUFFER *pNowStrBuffer; + +// ????????? +extern CHAT_BUFFER ChatBuffer[]; +// ?V???????? +extern STR_BUFFER MyChatBuffer; + +// ?????????? +extern int NowChatLine; + +// ?????????? +extern int NowMaxChatLine; + +// ????? +extern int NowMaxVoice; + +/* һԪĿǰString buffer +parameter: c: Ԫ */ +void StockStrBufferChar(char c); + +/* ˫λԪԪĿǰString buffer +parameter: lpc: ˫λԪԪ */ +void StockStrBufferDBChar(char *lpc); + +/* ?????????????????????? */ +void ChatBufferToFontBuffer( void ); +void ChatProc( void ); +void StockChatBufferLine( char *str, unsigned char color ); +#ifdef _FONT_SIZE +void StockChatBufferLineExt( char *str, unsigned char color, int fontsize ); +#endif +void ClearChatBuffer( void ); +int GetStrLastByte( char *str ); +int GetStrWidth( char *str ); +void GetKeyInputFocus( STR_BUFFER *pStrBuffer ); + +/* ????????? **********************************************************/ +void InitChat( void ); + +/* ???????? ************************************************************/ +void ChatProc( void ); + +// ??????????? **************************************************/ +void FlashKeyboardCursor( void ); + +void KeyboardLeft(); +void KeyboardRight(); + +/* ???????? ************************************************************/ +void KeyboardReturn( void ); + +// ?????? ***************************************************************/ +void KeyboardBackSpace( void ); + +// ?????????V ****************************************************************/ +BOOL SaveChatHistoryStr( int no ); +// ???????????? ****************************************************************/ +BOOL LoadChatHistoryStr( void ); + +BOOL LoadReadSayShield( void ); +BOOL LoadReadNameShield( void ); + +bool CheckSay( const char* strSay, const char szReplace = '*' ); +bool CheckName( const char* strSay/*, char* word*/ ); +// ?????????V????????? ********************************************/ +void GetClipboad( void ); +// ??????????????????????? ***********************************/ +void SetClipboad( void ); +int GetCharByte( char c ); + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ +void StrToNowStrBuffer( char *str ); +#endif + +#ifdef __ONLINEGM +int StrToNowStrBuffer2( char *str ); +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/directdraw.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/directdraw.h new file mode 100644 index 0000000..c6623f0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/directdraw.h @@ -0,0 +1,129 @@ +#ifndef _DIRECT_DRAW_H_ +#define _DIRECT_DRAW_H_ + +#include "sprmgr.h" + +extern const int MAX_PAL; +#define DEF_PAL 0 //????? +#define PAL_CHANGE_TIME 3600 +#define SYSTEM_PAL_WHITE 255 +#define SYSTEM_PAL_AQUA 254 +#define SYSTEM_PAL_PURPLE 253 +#define SYSTEM_PAL_BLUE 252 +#define SYSTEM_PAL_YELLOW 251 +#define SYSTEM_PAL_GREEN 250 +#define SYSTEM_PAL_RED 249 +#define SYSTEM_PAL_GRAY 248 +#define SYSTEM_PAL_BLUE3 247 +#define SYSTEM_PAL_GREEN3 246 + +#define SYSTEM_PAL_WHITE2 7 +#define SYSTEM_PAL_AQUA2 6 +#define SYSTEM_PAL_PURPLE2 5 +#define SYSTEM_PAL_BLUE2 4 +#define SYSTEM_PAL_YELLOW2 3 +#define SYSTEM_PAL_GREEN2 2 +#define SYSTEM_PAL_RED2 1 +#define SYSTEM_PAL_BLACK 0 +#define SYSTEM_PAL_BLUE4 8 +#define SYSTEM_PAL_GREEN4 9 + +enum{ + FONT_PAL_WHITE, + FONT_PAL_AQUA, + FONT_PAL_PURPLE, + FONT_PAL_BLUE, + FONT_PAL_YELLOW, + FONT_PAL_GREEN, + FONT_PAL_RED, + FONT_PAL_GRAY, + FONT_PAL_BLUE2, + FONT_PAL_GREEN2, + FONT_PAL_10, + FONT_PAL_11, + FONT_PAL_12, + FONT_PAL_13, + FONT_PAL_14, + FONT_PAL_15, + FONT_PAL_16, + FONT_PAL_17, + FONT_PAL_18, + FONT_PAL_19, + FONT_PAL_20, + FONT_PAL_21, + FONT_PAL_22, + FONT_PAL_23, + FONT_PAL_24, + FONT_PAL_25, + FONT_PAL_NUM +}; + + +enum{ + DRAW_BACK_NORMAL, + DRAW_BACK_NON, + DRAW_BACK_PRODUCE, + DRAW_BACK_BATTLE, +}; +typedef struct +{ + LPDIRECTDRAW lpDD; // DirectDraw?????? + LPDIRECTDRAW2 lpDD2; // DirectDraw2?????? + LPDIRECTDRAWSURFACE lpFRONTBUFFER; // ???? + LPDIRECTDRAWSURFACE lpBACKBUFFER; // ????? +#ifdef _READ16BITBMP + LPDIRECTDRAWSURFACE lpBACKBUFFERSYS; +#endif + LPDIRECTDRAWCLIPPER lpCLIPPER; // ????? + DDSURFACEDESC ddsd; // ??????????????Ble? + LPDIRECTDRAWPALETTE lpPALETTE; // ???? + int xSize, ySize; // ????????? +} DIRECT_DRAW; +extern PALETTEENTRY Palette[256]; +typedef struct{ + int palNo; // ????k? + int time; // ????? + int flag; // ?????? +}PALETTE_STATE; +extern DIRECT_DRAW *lpDraw; +extern BOOL DDinitFlag; +extern HFONT hFont; +extern PALETTE_STATE PalState; +extern BOOL PalChangeFlag; +extern int BackBufferDrawType; +BOOL InitDirectDraw( void ); +BOOL InitPalette( void ); +void ClearBackSurface( void ); +void ClearSurface( LPDIRECTDRAWSURFACE lpSurface ); +LPBITMAPINFO LoadDirectDrawBitmap( char *pFile ); +LPDIRECTDRAWSURFACE CreateSurface( short sizeX, short sizeY, DWORD ColorKey, unsigned int VramOrSysram ); +#ifdef _READ16BITBMP +HRESULT DrawSurfaceFast( long bx, long by, LPDIRECTDRAWSURFACE lpSurface,LPDIRECTDRAWSURFACE lpSurfaceSys); +void DrawBitmapToSurface2(SURFACE_INFO *surface_info,LPDIRECTDRAWSURFACE lpSurfaceSys,int offsetX,int offsetY,int sizeX,int sizeY,LPBITMAPINFO pBmpInfo); +void Draw16BitmapToSurface2(SURFACE_INFO *surface_info,LPDIRECTDRAWSURFACE lpSurfaceSys,int offsetX,int offsetY,int sizeX,int sizeY,LPBITMAPINFO pBmpInfo); +#endif +HRESULT DrawSurfaceFast( short bx, short by, LPDIRECTDRAWSURFACE lpSurface ); +void DrawBitmapToSurface2(SURFACE_INFO *surface_info, int offsetX, int offsetY, int sizeX, int sizeY, LPBITMAPINFO pBmpInfo ); +HRESULT DrawSurfaceFast2( short bx, short by, RECT *rect, LPDIRECTDRAWSURFACE lpSurface ); +void DrawBitmapToSurface( LPDIRECTDRAWSURFACE lpSurface, int offsetX, int offsetY, LPBITMAPINFO pInfo ); +void Flip( void ); +BOOL CheckSurfaceLost( void ); +void ReleaseDirectDraw( void ); +void DrawDebugLine( unsigned char color ); +void DrawBox( RECT *rect, unsigned char color, BOOL fill ); +void InitFont( int fontNo ); +void PutText( char fontPrio ); +void PaletteProc( void ); +#ifdef _CACHE_SURFACE_ +BOOL IsSurfaceExpired(SURFACE_INFO *surface); +void DrawSurfaceFromPalette(SURFACE_INFO* surface_info); +#endif +void PaletteChange( int palNo, int time ); +void DrawAutoMapping( int x, int y, unsigned char *autoMap, int w, int h ); +int getAutoMapColor( unsigned int GraphicNo ); +int getNearestColorIndex( COLORREF color, PALETTEENTRY *palette, int entry ); +void snapShot( void ); +BOOL saveBmpFile( const char *, BYTE *, int, int, int, int, int, RGBQUAD *, int ); +BOOL saveBmpFile16( const char *, BYTE *, int, int); +void DrawMapEffect( void ); +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/field.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/field.h new file mode 100644 index 0000000..989f74b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/field.h @@ -0,0 +1,195 @@ +#ifndef _FIELD_H_ +#define _FIELD_H_ + +#include + +// ?????????? +#define FIELD_BTN_PUSH_WAIT 500 // 0.5 + +// ????????? +#define FIELD_MAIL_LAMP_FLASH_TIME 1000 // 1?? + +enum +{ + FIELD_FUNC_MENU, + FIELD_FUNC_CARD, + FIELD_FUNC_PARTY, + FIELD_FUNC_JOIN_BATTLE, + FIELD_FUNC_DUEL, + FIELD_FUNC_ACT, + FIELD_FUNC_TRADE, // Robin 04/12 trade + FIELD_FUNC_CHANNEL, +#ifdef __HELP + FIELD_FUNC_HELP, //CARY +#endif +#ifdef __PHONEMESSAGE + FIELD_FUNC_MSG, //LeiBoy +#endif +#ifdef _STREET_VENDOR + FIELD_FUNC_STREET_VENDOR, +#else + #ifdef _TABLEOFSKILL + FIELD_FUNC_SKILL, + #endif +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + FIELD_FUNC_CHATROOM, +#endif + +#ifdef _ANGEL_SUMMON + FIELD_FUNC_ANGEL, +#endif + +#ifdef _TEACHER_SYSTEM + FIELD_FUNC_TEACHER, +#endif +#ifdef _MO_SIGN_IN + FIELD_FUNC_SIGNIN, +#endif +#ifdef _NEWSHOP_ + FIELD_FUNC_MARKET, +#endif +#ifdef _CHANGETEAM_ + FIELD_FUNC_CHANGETEAM, +#endif +#ifdef _RED_MEMOY_ + FIELD_FUNC_RED_MEMOY, +#endif + FIELD_FUNC_END +}; + +#ifdef _PET_ITEM +typedef struct SPetItemInfo +{ + int bmpNo; // ͼ + int color; // ɫ + char memo[ITEM_MEMO_LEN+1]; // ˵ + char name[ITEM_NAME_LEN+1]; // + char damage[16]; // ;ö +}PetItemInfo; +#endif + +#ifdef _STREET_VENDOR +#define MAX_SELL_ITEM 20 // ߼ӳﹲʮ +typedef struct _Show_Sell_Item{ + int index; // + int pile; // + int price; // ۸ + bool needGetPrice; // ǷҪõ۸ + bool usage; // Ƿʹ + char name[ITEM_NAME_LEN+1]; // + char freeName[ITEM_NAME_LEN+1]; // + char kind; // ߻dz 0: 1: +}Show_Sell_Item; + +typedef struct _Show_Vendor_Item{ + int bmpNo; // ͼ + int pile; // + int price; // ۸ + int color; // ɫ + int level; // ȼ + int maxhp,attack,defence,dex; // Χ + int earth,water,fire,wind,fidelity; // Լҳ϶ + int maxSkill; // 輼 + int index; // serverĴλ + bool usage; // Ƿʹ + bool bBuy; // ǷҪ + bool bGetData; // Ƿѽյϸ + char name[ITEM_NAME_LEN+1]; // + char freeName[ITEM_NAME_LEN+1]; // + char memo[ITEM_MEMO_LEN+1]; // ˵ + char damage[20]; // ;ö + char skillname[MAX_SKILL][SKILL_NAME_LEN+1]; // 輼 + char kind; // ߻dz 0: 1: + char trans; // ת +#ifdef _PET_ITEM + PetItemInfo oPetItemInfo[MAX_PET_ITEM]; // ϵĵ +#endif +#ifdef _NPC_ITEMUP + int itemup; +#endif +#ifdef _PETCOM_ + int ylv,yhp,yack,ydef,ydex; //ʼΧ +#endif +}Show_Vendor_Item; + +#endif + +#ifdef _JOBDAILY + +#define MAXMISSION 300 +typedef struct _JOBDAILY{ + int JobId; // + char explain[200]; // ˵ + char state[10]; // ״̬ +}JOBDAILY; + +#endif + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ + extern short chatRoomBtn; + extern short SelRoomBtn; +#endif + +#ifdef _ANGEL_SUMMON +extern int angelFlag; +extern int angelRecvType; +extern int angelRecvButton; +extern char angelMsg[]; +#endif + +extern short drawTimeAnimeFlag; + +extern short etcSendFlag; + +extern short actBtn; +extern short menuBtn; +extern short mailLamp; + +extern unsigned int fieldInfoTime; + +extern struct tm serverAliveTime; +extern time_t serverAliveLongTime; + + +void initFieldProc( void ); +void resetFieldProc( void ); +void fieldProc( void ); +void fieldProc2( void ); +void drawField( void ); + +BOOL checkFieldMenuFlag( void ); + +void closeCharActionAnimeChange( void ); +void closeEtcSwitch( void ); +void closeJoinChannelWN( void ); + +int disconnectServer( void ); + +void drawFieldInfoWin( void ); + +void actionShortCutKeyProc( void ); + +#ifdef _SPECIALSPACEANIM // Syu ADD ⳡ + #ifdef _SURFACE_ANIM //̬ʾ +//#define TOTAL_ANIM 5 // +#ifdef _SA_VERSION_25 + #define MAX_ANIM 256 //ͬһfloor޶ +#endif + + #else + #ifdef _MOON_FAIRYLAND // ROG ADD ֮ɾ + #define TOTAL_ANIM 5 // + #define MAX_ANIM 4 //ͬһfloorִAnim + #else + #define TOTAL_ANIM 1 // + #define MAX_ANIM 1 //ͬһfloorִAnim + #endif +#endif + +void SpecAnim ( int ) ; +void ReleaseSpecAnim( void ); + +#endif +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/font.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/font.h new file mode 100644 index 0000000..e808662 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/font.h @@ -0,0 +1,69 @@ +/************************/ +/* font.h */ +/************************/ +#ifndef _FONT_H_ +#define _FONT_H_ + +#define FONT_SIZE 14 +#ifdef _NEWFONT_ +#define FONT_SIZE1 19 +#else +#define FONT_SIZE1 14 +#define FONT_SIZE2 19 +#endif +extern int FontZenkauWidth; +// S??????????? +extern int FontHankakuWidth; + +/* ?????I?? fontPrio ?k ****************************************/ +enum{ + FONT_PRIO_BACK, /* ??? */ + FONT_PRIO_FRONT /* q? */ + +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի + , FONT_PRIO_AFRONT +#endif +#ifdef _CHANNEL_MODIFY + ,FONT_PRIO_CHATBUFFER +#endif +}; + +// ??????????Bl +typedef struct{ + short x, y; // ? + char color; // + char str[ 256 ]; // ?? + UCHAR fontPrio; // ??I?? + BOOL hitFlag; // ???Re?????? ??? ???? +#ifdef _FONT_SIZE + int size; +#endif +}FONT_BUFFER; + +// ????????? +extern FONT_BUFFER FontBuffer[]; + +// ????????? +extern int FontCnt; +void FontPrint( char *moji, int x, int y, int dispPrio ); + +// ???????? /////////////////////////////////////////////////////// +void FontPrintDec( char *moji, int x, int y, int dispPrio ); + +/* ????ѩ????????? *********************************************/ +int StockFontBuffer( int x, int y, char fontPrio, int color, char *str, BOOL hitFlag ); +#ifdef _MO_CHAT_EXPRESSION +void NewStockFontBuffer(CHAT_BUFFER *chatbuffer,int x, unsigned char color,char *str, int size); +void delFontBuffer(CHAT_BUFFER *chatbuffer); +#endif +void CreatFontHdc(); +#ifdef _FONT_SIZE +int StockFontBufferExt( int x, int y, char fontPrio, int color, char *str, BOOL hitFlag, int size ); +HFONT CreateNewFont( int size); +#endif + +void StockFontBuffer2(STR_BUFFER *strBuffer ); +/* ONLINEGM ADD */ +int StockFontBuffer3( STR_BUFFER *strBuffer ); +void StockFontBufferFamily( STR_BUFFER *strBuffer ); +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/gamemain.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/gamemain.h new file mode 100644 index 0000000..e5e29c4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/gamemain.h @@ -0,0 +1,38 @@ +// gamemain.cpp ??????? + +#ifndef _GAMEMAIN_H_ +#define _GAMEMAIN_H_ + +// ????֢t +enum{ + GAME_LOGIN, // ???? + GAME_FIELD, // ???????? + GAME_FIELD_TO_ENCOUNT, // ?????????????????? + GAME_ENCOUNT_TO_BATTLE, // ?????????Pf + GAME_BATTLE // ?????????Pf +}; + + +extern int GameState; // ????֢t +extern DWORD NowTime; +//extern double NowTime; // ??????? + +//---------------------------------------------------------------------------// +// ????????L? // +//---------------------------------------------------------------------------// +BOOL GameMain( void ); + +BOOL InitGame( void ); + +void EndGame( void ); + + +#ifdef _STONDEBUG_ +// ѩ +void InfoDisp( void ); +#endif + +// ?????????????? +void DisplayFrameRate( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/gemini.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/gemini.h new file mode 100644 index 0000000..9ebf251 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/gemini.h @@ -0,0 +1,9 @@ +/************************/ +/* gemini.h */ +/************************/ +#ifndef _GEMINI_ +#define _GEMINI_ + +void gemini(ACTION *); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/handletime.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/handletime.h new file mode 100644 index 0000000..c6ce813 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/handletime.h @@ -0,0 +1,67 @@ +#ifndef __HANDLETIME_H__ +#define __HANDLETIME_H__ + +//#undef EXTERN +//#ifdef __HANDLETIME_C__ +//#define EXTERN +//#else /*__HANDLETIME_C__*/ +//#define EXTERN extern +//#endif + +//EXTERN struct timeval NowTime; +//EXTERN int DEBUG_ADJUSTTIME; + + + +//BOOL setNewTime( void ); +#if 0 + +#define NIGHT_TO_MORNING 906 +#define MORNING_TO_NOON 1006 +#define NOON_TO_EVENING 356 +#define EVENING_TO_NIGHT 456 + +#else + +#define NIGHT_TO_MORNING 700 +#define MORNING_TO_NOON 930 +#define NOON_TO_EVENING 200 +#define EVENING_TO_NIGHT 300 + +#endif + +/*??????HiO?LS?????*/ +/* ??150()*60=9000=750*12 ? LS1T */ +/* LS1200?? LS1T */ +/* LS100T? LS1g */ +typedef struct tagLSTIME +{ + int year; + int day; + int hour; +}LSTIME; + + +typedef enum +{ + LS_NOON, + LS_EVENING , + LS_NIGHT, + LS_MORNING , +}LSTIME_SECTION; + +// ????????? +extern LSTIME SaTime; +extern long serverTime; +extern long FirstTime; //the second +extern long clientTime; //the third +extern int SaTimeZoneNo; // ?????q +extern BOOL TimeZonePalChangeFlag; // ??q?????????????? + +void RealTimeToSATime( LSTIME *lstime ); +/*void LSTimeToRealTime( LSTIME *lstime, long *t);*/ +LSTIME_SECTION getLSTime (LSTIME *lstime); +// ??q??????????? ***********************************/ +void TimeZoneProc( void ); + +#endif /*__HANDLETIME_H__*/ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/ime_sa.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/ime_sa.h new file mode 100644 index 0000000..199958b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/ime_sa.h @@ -0,0 +1,11 @@ +/************************/ +/* ime.h */ +/************************/ +#ifndef _IME_H_ +#define _IME_H_ + +void ShowBottomLineString(int iColor,LPSTR lpstr); +void ImeProc(); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/init.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/init.h new file mode 100644 index 0000000..0f55c7d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/init.h @@ -0,0 +1,11 @@ +/************************/ +/* init.h */ +/************************/ +#ifndef _INIT_H_ +#define _INIT_H_ + +/* ??????? *************************************************************/ +void InitProc( void ); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/loadrealbin.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/loadrealbin.h new file mode 100644 index 0000000..681d7eb --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/loadrealbin.h @@ -0,0 +1,153 @@ +#ifndef _LOADREALBIN_H_ +#define _LOADREALBIN_H_ +#include "directdraw.h" +void initAutoMapColor( char * ); +void makeAutoMapColor( void ); +int writeAutoMapColor( char *, char * ); +int readAutoMapColor( char *, char * ); + +int initRealbinFileOpen(char *realbinfilename, char *addrbinfilename); +#ifdef _READ16BITBMP +int InitRealTruebinFileOpen(char *szRealTrueBinFileName,char *szAdrnTruebinFileName); +#endif +void cleanupRealbin(void); + +extern unsigned char autoMapColorTbl[]; + +#include +typedef unsigned char MOJI; +typedef unsigned char U1; +typedef char S1; +typedef unsigned short U2; +typedef short S2; +typedef unsigned long U4; +typedef long S4; +typedef float F4; +typedef double F8; +#ifdef _READ16BITBMP +BOOL Read16BMP(int BmpNo,unsigned char **BmpData,int *width,int *height,BYTE **AlphaData,BOOL *useAlpha); +#endif +int realGetImage(int graphicNo, unsigned char **bmpdata, int *width, int *height); +int realGetPos(U4 GraphicNo , S2 *x , S2 *y); +int realGetWH(U4 GraphicNo , S2 *w , S2 *h); +int realGetHitPoints(U4 GraphicNo , S2 *HitX , S2 *HitY); +int realGetHitFlag(U4 GraphicNo , S2 *Hit); +BOOL realGetPrioType(U4 GraphicNo , S2 *prioType); +int realGetHeightFlag(U4 GraphicNo , S2 *Height); +int realGetNo( U4 CharAction , U4 *GraphicNo ); +int realGetSoundEffect(U4 GraphicNo); +int realGetWalkSoundEffect(U4 GraphicNo); +int realGetBitmapNo( int num ); +typedef struct { + unsigned char atari_x,atari_y; //?? + unsigned short hit; // ɷ //??? + short height; //????? + short broken; //???? + short indamage; //VHP???? + short outdamage; //???? + short inpoison; //V + short innumb; //V??? + short inquiet; //V? + short instone; //V? + short indark; //V?? + short inconfuse; //V?? + short outpoison; //ҥ + short outnumb; //?? + short outquiet; //ң? + short outstone; //? + short outdark; //?? + short outconfuse; //?? + short effect1; //?????1??????????????? + short effect2; //?????2?V???????????? + unsigned short damy_a; + unsigned short damy_b; + unsigned short damy_c; + unsigned int bmpnumber; //??k? +} MAP_ATTR; + +struct ADRNBIN{ + unsigned long bitmapno; + unsigned long adder; + unsigned long size; + int xoffset; + int yoffset; + unsigned int width; + unsigned int height; + MAP_ATTR attr; +}; + +#ifdef _READ16BITBMP +struct AddressBin_s{ + unsigned int bitmapno; // ͼ + unsigned int adder; // ͼصʼλַ + unsigned int palSize; // ɫϴС + unsigned int size; // һϵĴС + unsigned int alpha_size; // alpha_sizeΪ0ʾͼϺalpha,alpha_sizealphaϵĴС + // alpha_sizeΪ0ʾûдalpha + int xoffset; + int yoffset; + unsigned int width; // ͼ + unsigned int height; // ͼ + unsigned int staturated; // ǷñЧ +}; +#endif + +// ???????? +static DWORD FontPal[FONT_PAL_NUM]={ +#ifdef _SA_VERSION_25 + RGB(0xff ,0xff, 0xff ), // 0:FONT_PAL_WHITE + RGB(0x00 ,0xff, 0xff ), // 1:FONT_PAL_AQUA + RGB(0xff ,0x00, 0xff ), // 2:FONT_PAL_PURPLE + RGB(0x48 ,0x48, 0xfa ), // 3:FONT_PAL_BLUE + RGB(0xff ,0xea, 0x39 ), // 4:FONT_PAL_YELLOW + RGB(0xa0 ,0xf4, 0x3a ), // 5:FONT_PAL_GREEN a0f43a + RGB(0xB5 ,0x38, 0x17 ), // 6:FONT_PAL_RED + RGB(0xa0 ,0xa0, 0xa4 ), // 7:FONT_PAL_GRAY + RGB(0xa6 ,0xca, 0xf0 ), // 8:FONT_PAL_BLUE2 + RGB(0xc0 ,0xdc, 0xc0 ), // 9:FONT_PAL_GREEN +#endif + + +#ifdef _EXTEND_FONT_PAL + RGB(0xff ,0x80, 0x00 ), // 10 + RGB(0x6f ,0xc6, 0x6f ), // 11 + RGB(0x98 ,0x3d, 0xf3 ), // 12 + RGB(0xff ,0x80, 0xff ), // 13 + RGB(0x4a ,0x9f, 0xf4 ), // 14 + RGB(0xb4 ,0x0e, 0xb4 ), // 15 + RGB(0xbf ,0xbf, 0x19 ), // 16 + RGB(0xff ,0x00, 0x80 ), // 17 + RGB(0xff ,0x80, 0x80 ), // 18 + RGB(0x80 ,0x80, 0x80 ), // 19 + + RGB(0xff ,0xff, 0x80 ), // 20 + RGB(0x80 ,0xff, 0xff ), // 21 + RGB(0x80 ,0xff, 0x00 ), // 22 + RGB(0x00 ,0x80, 0xff ), // 23 + RGB(0xd0 ,0x2a, 0x7d ), // 24 + RGB(0x8d ,0x56, 0x8d ), // 25 +#endif +}; + +/* +BOOL InitRealbinFileOpen( char *realbinfilename, char *addrbinfilename); //ʼrealbinϲصļ +//void SetCurFrame(); //ۼCurFramecounterÿframeִһ +void CacheRLU( int howlong); //ͷ̫ûʹõͼ +BOOL realGetNo( DWORD CharAction, DWORD *GraphicNo); //char actionתͼ +DWORD realGetNo2( DWORD bnum); //bnumתͼ +BOOL realIsValid( DWORD CharAction); //ͼǷЧ +DWORD realGetBitmapNo( DWORD num); //ͼתbnum +BOOL realGetPos( DWORD GraphicNo, short *x, short *y); //ȡGraphicNoxy offset +BOOL realGetWH( DWORD GraphicNo, short *w, short *h); //ȡGraphicNoĿ͸ +BOOL realGetHitPoints( DWORD GraphicNo, short *HitX, short *HitY); //ȡGraphicNoʵʿ͸ +BOOL realGetPrioType( DWORD GraphicNo , short *prioType); //ȡGraphicNoȨ +BOOL realGetHitFlag( DWORD GraphicNo, short *Hit); //ȡGraphicNoHit +BOOL realGetHeightFlag( DWORD GraphicNo, short *Height); //ȡGraphicNoǷи߶ +int realGetSoundEffect( DWORD GraphicNo); //ȡGraphicNoĻ +int realGetWalkSoundEffect( DWORD GraphicNo); //ȡGraphicNoĽŲ +LPBYTE ReadRealBin( DWORD GraphicNo); +//realbin +BOOL DrawScaleImage( DWORD GraphicNo, int screenx, int screeny, int screenw, int screenh, LPWORD dest, + int destw, int desth, int pitch, LPWORD pal); +*/ +#endif /*_LOADREALBIN_H_*/ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/loadsprbin.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/loadsprbin.h new file mode 100644 index 0000000..9f9a524 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/loadsprbin.h @@ -0,0 +1,101 @@ +#ifndef _SPRITE_H_ +#define _SPRITE_H_ + +//??????????e?????? +#define mxSPRITE 40000 + +#define maxBUFFER 1024*1024*6 + + + +typedef unsigned char MOJI; +typedef unsigned char U1; +typedef char S1; +typedef unsigned short U2; +typedef short S2; +typedef unsigned long U4; +typedef long S4; +typedef float F4; +typedef double F8; + +typedef enum { + ANIM_ATTACK, // + ANIM_DAMAGE, // + ANIM_DEAD, // + ANIM_STAND, //վ + ANIM_WALK, // + ANIM_SIT, // + ANIM_HAND, // + ANIM_HAPPY, // + ANIM_ANGRY, // + ANIM_SAD, // + ANIM_GUARD, // + ANIM_NOD, //ͷ + ANIM_THROW, //Ͷ + ANIM_LIST_ +} ANIM_LIST; + + +// 1?????ѩ +typedef struct +{ + U4 BmpNo; //AdrnͼƬ + S2 PosX,PosY; //ͼƬʾʱxyƫ + U2 SoundNo; // С10000Ч,ʾҪЧ;ڵ10000С10100Ҫʾ˺Ч,ֻЧ + // ڵ10100????k? +} FRAMELIST;//һ֡ľϢ + +typedef struct +{ + U2 dir; // (0-8) + U2 no; // ķANIM_LISTĶ + U4 dtAnim; // ζѭĺʱ + U4 frameCnt; // FRAMELIST + FRAMELIST *ptFramelist; +} ANIMLIST; + + +// SPR??tѩ +typedef struct +{ + U4 sprNo; // Spr + U4 offset; // ָspr.binеĵַ + U2 animSize; // ɫжٸĶ +} SPRADRN; + + +typedef struct +{ + U2 animSize; + ANIMLIST *ptAnimlist; +} SPRITEDATA; + + +typedef struct { + U2 dtz; + U2 noSpritedata; + U2 mdAnim; + U2 mdAnim2; + U2 dir; + U2 ctLoop; + float ctAnim; + float dtAnim; +} SPRITE; + + +typedef struct +{ + U2 dir; // (0-8) + U2 no; // ķANIM_LISTĶ + U4 dtAnim; // һζѭĺʱ + U4 frameCnt; // +} ANIM_HEADER; + + +extern SPRITEDATA SpriteData[mxSPRITE]; + + +BOOL InitSprBinFileOpen( char *, char * ); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/login.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/login.h new file mode 100644 index 0000000..00e8214 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/login.h @@ -0,0 +1,203 @@ +#ifndef _LOGIN_H_ +#define _LOGIN_H_ +#include "version.h" +#include "action.h" + + + + +enum +{ + WINDOW_MESSAGETYPE_MESSAGE, // ??????? + WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, // ????????V? + WINDOW_MESSAGETYPE_SELECT, // k????? + WINDOW_MESSAGETYPE_PETSELECT, // ???k????? + WINDOW_MESSAGETYPE_PARTYSELECT, // ??k????? + WINDOW_MESSAGETYPE_PETANDPARTYSELECT, // ??????k????? + WINDOW_MESSAGETYPE_ITEMSHOPMENU, // ??????????? + WINDOW_MESSAGETYPE_ITEMSHOPMAIN, // ?????????? + WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN, // ???M??????????????? + WINDOW_MESSAGETYPE_PETSKILLSHOP, // ????????????? + WINDOW_MESSAGETYPE_WIDEMESSAGE, // ??????????? + WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, // ????????V????? + WINDOW_MESSAGETYPE_POOLITEMSHOPMENU, // ????????????????? + WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN, // ????????????????? + + WINDOW_MESSAGETYPE_FAMILYADD, + WINDOW_MESSAGETYPE_FAMILYJOIN, + WINDOW_MESSAGETYPE_FAMILYLEAVE, + WINDOW_MESSAGETYPE_FAMILYEND, + + // shan add + WINDOW_FMMESSAGETYPE_SELECT, + WINDOW_FMMESSAGETYPE_DENGON, + WINDOW_FMMESSAGETYPE_FMSDENGON, //20 + WINDOW_FMMESSAGETYPE_POINTLIST, +#ifdef _FMVER21 + WINDOW_FMMESSAGETYPE_TOP30DP, +#endif + WINDOW_FMMESSAGETYPE_DP, + + WINDOW_MESSAGETYPE_BANK, + + // Arminius 7.12 scheduleman + WINDOW_MESSAGETYPE_PKSCHEDULELIST, //25 + WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + + // Robin + WINDOW_MESSAGETYPE_LOGINMESSAGE, + WINDOW_MESSAGETYPE_FAMILYTAX, + WINDOW_MESSAGETYPE_SHOWRIDEPET, //30 + WINDOW_MESSAGETYPE_FAMILYDETAIL, + + WINDOW_MESSAGETYPE_LEADERSELECT, + WINDOW_MESSAGETYPE_LEADERSELECTQ, + WINDOW_MESSAGETYPE_LEADERSELECTA, +//Terry add 2002/01/03 +#ifdef __EDEN_AUCTION + WINDOW_MESSAGETYPE_AUCTIONNEW, //35 + WINDOW_MESSAGETYPE_AUCTIONLIST_BUY, + WINDOW_MESSAGETYPE_AUCTIONSURVEY, + WINDOW_MESSAGETYPE_AUCTIONMODIFY, + WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY, +#endif +//Terry end +#ifdef _BLACK_MARKET + WINDOW_MESSAGETYPE_BLACKMARKET, +#endif +#ifdef _ADD_FAMILY_TAX // WON ADD ׯ԰˰ + WINDOWS_MESSAGETYPE_FAMILY_TAX, +#endif +#ifdef _NPC_FUSION + WINDOWS_MESSAGETYPE_PETFUSION, +#endif +#ifdef _PETSKILL_CANNEDFOOD + WINDOWS_MESSAGETYPE_PETSKILLSHOW, +#endif + +#ifdef _NPC_SELLSTH + WINDOWS_MESSAGETYPE_SELLSTHMENU, + WINDOWS_MESSAGETYPE_SELLSTHVIEW, + WINDOWS_MESSAGETYPE_SELLSTHSELL, +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + WINDOW_MESSAGETYPE_PROFESSIONSHOP, +#endif +#ifdef _NPC_WELFARE_2 // WON ADD ְҵNPC-2 + WINDOW_MESSAGETYPE_PROFESSIONSHOP2, +#endif +#ifdef _NEW_MANOR_LAW + WINDOW_FMMESSAGETYPE_10_MEMONTUM, // ʮƼ + WINDOW_FMMESSAGETYPE_FM_MEMONTUM, // Լ + WINDOW_FMMESSAGETYPE_MANOR_SCHEDULE, // սׯ԰ +#endif + +#ifdef _ANGEL_SUMMON + WINDOW_MESSAGETYPE_ANGELMESSAGE = 101, + WINDOW_MESSAGETYPE_ANGELASK, +#endif + +#ifdef _MOUSE_DBL_CLICK + WINDOW_MESSAGETYPE_MOUSEGETNAME, +#endif + +#ifdef _CONTRACT + WINDOW_MESSAGETYPE_CONTRACT, +#endif + +#ifdef _RACEMAN + WINDOW_MESSAGETYPE_RACEMAN_RANK, +#endif + +#ifdef _DRAGON_FUSION + WINDOWS_MESSAGETYPE_DRAGONFUSION, +#endif + +#ifdef _NPC_DAYACTION + WINDOW_MESSAGETYPE_DAYACTION_FMRANK, +#endif + +}; + +#define WINDOW_BUTTONTYPE_NONE (0) +#define WINDOW_BUTTONTYPE_OK (1 << 0) +#define WINDOW_BUTTONTYPE_CANCEL (1 << 1) +#define WINDOW_BUTTONTYPE_YES (1 << 2) +#define WINDOW_BUTTONTYPE_NO (1 << 3) +#define WINDOW_BUTTONTYPE_PRE (1 << 4) +#define WINDOW_BUTTONTYPE_NEXT (1 << 5) + +#define MAX_GMGROUP 19 +#define MAX_GMSV 150 + +extern BOOL logOutFlag; +extern unsigned int MsgCooltime; + +extern short createCharFlag; + +extern int windowTypeWN; +extern short wnCloseFlag; + +void idPasswordProc( void ); +void titleProc( void ); +void selectCharacterProc( void ); +void characterLoginProc( void ); + +void makeCharacterProc( void ); + +void characterLogoutProc( void ); +#ifdef _80_LOGIN_PLAY +void _80LoginProc(void); +#endif + +void initOpenServerWindow( void ); +void openServerWindow( int, int, int, int, char * ); +void openServerWindowProc( void ); + + + +int selGraId( int *, int ); +int selRepGraId( int *, int ); +int pushGraId( int *, int ); +int selFontId( int *, int ); +int focusGraId( int *, int ); +int focusFontId( int *, int ); +#ifdef _BLACK_MARKET +void closeBlackMarketWN( void ); +#endif + +#ifdef _PET_TRACE_MOUSE +class SCPlayPet{ +private: + ACTION *m_pPet; + int m_iDestX,m_iDestY,m_iX,m_iY,m_iCount,m_iDirx,m_iDiry,b,m_iActionStep; + bool m_bMove,m_bChangeDir,m_bAIWalk; + unsigned int m_iTimeToChangeAction,m_iTimeToChangeTime,m_iKindOfChangeTime; + + void CnangePetAction(bool bUserMove); +public: + SCPlayPet(); + ~SCPlayPet(); + + void Proc(void); + void SetActionStep(int iActionStep) { m_iActionStep = iActionStep;}; +}; +#endif + +#ifdef _PK2007 +void selectpkProc( void ); +#endif + +#endif + +#ifdef _NEWSHOP_ +typedef struct { + char MD5[64]; + char * ̳; +}̳ļ_; +#endif + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_cli.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_cli.h new file mode 100644 index 0000000..5e4f7c5 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_cli.h @@ -0,0 +1,152 @@ +/* output by ./lsgen.perl 0.41 ( 1998 May) + * made Mon Jun 12 11:17:33 2000 + * user kawata + * host unicorn.lan.titan.co.jp + * file /opt/kawata/sa/bin/output/lssproto_cli.h + * util output/lssproto_util.c , output/lssproto_util.h + * src /opt/kawata/sa/bin/../doc/lssproto.html + */ +#ifndef _LSSPROTOCLI_H_ +#define _LSSPROTOCLI_H_ + +#include "../NewProto/protocol.h" +/*#ifdef __NEW_PROTOCOL +#include "lssproto_util.h" + +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 13 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 13 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 13 + 1 ) +#endif + +int lssproto_InitClient( int(*)(int,char*,int) , int bufsiz , int fd); +void lssproto_SetClientLogFiles( char *read , char *write); +void lssproto_CleanupClient(void); + + +#else + */ + + +#include "lssproto_util.h" + +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 13 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 13 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 13 + 1 ) +#endif + +void old_lssproto_W_send( int fd,int x,int y,char* direction ) ; /* ../doc/lssproto.html line 166 */ +void old_lssproto_w_send( int fd,int x,int y,char* direction ) ; /* ../doc/lssproto.html line 198 */ +void lssproto_XYD_recv( int fd,int x,int y,int dir ) ; /* ../doc/lssproto.html line 209 */ +void old_lssproto_EV_send( int fd,int event,int seqno,int x,int y,int dir ) ; /* ../doc/lssproto.html line 212 */ +void lssproto_EV_recv( int fd,int seqno,int result ) ; /* ../doc/lssproto.html line 247 */ +void old_lssproto_EN_send( int fd,int x,int y ) ; /* ../doc/lssproto.html line 261 */ +void old_lssproto_DU_send( int fd,int x,int y ) ; /* ../doc/lssproto.html line 273 */ +void lssproto_EN_recv( int fd,int result,int field ) ; /* ../doc/lssproto.html line 285 */ +void old_lssproto_EO_send( int fd,int dummy ) ; /* ../doc/lssproto.html line 298 */ +void old_lssproto_BU_send( int fd,int dummy ) ; /* ../doc/lssproto.html line 309 */ +void old_lssproto_JB_send( int fd,int x,int y ) ; /* ../doc/lssproto.html line 320 */ +void old_lssproto_LB_send( int fd,int x,int y ) ; /* ../doc/lssproto.html line 331 */ +void lssproto_RS_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 342 */ +void lssproto_RD_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 349 */ +void old_lssproto_B_send( int fd,char* command ) ; /* ../doc/lssproto.html line 354 */ +void lssproto_B_recv( int fd,char* command ) ; /* ../doc/lssproto.html line 377 */ +void old_lssproto_SKD_send( int fd,int dir,int index ) ; /* ../doc/lssproto.html line 542 */ +void old_lssproto_ID_send( int fd,int x,int y,int haveitemindex,int toindex ) ; /* ../doc/lssproto.html line 633 */ +void old_lssproto_PI_send( int fd,int x,int y,int dir ) ; /* ../doc/lssproto.html line 662 */ +void old_lssproto_DI_send( int fd,int x,int y,int itemindex ) ; /* ../doc/lssproto.html line 676 */ +void old_lssproto_DG_send( int fd,int x,int y,int amount ) ; /* ../doc/lssproto.html line 693 */ +void old_lssproto_DP_send( int fd,int x,int y,int petindex ) ; /* ../doc/lssproto.html line 706 */ +void lssproto_I_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 722 */ +void old_lssproto_MI_send( int fd,int fromindex,int toindex ) ; /* ../doc/lssproto.html line 741 */ +void lssproto_SI_recv( int fd,int fromindex,int toindex ) ; /* ../doc/lssproto.html line 763 */ +void old_lssproto_MSG_send( int fd,int index,char* message,int color ) ; /* ../doc/lssproto.html line 788 */ +void lssproto_MSG_recv( int fd,int aindex,char* text,int color ) ; /* ../doc/lssproto.html line 806 */ +void old_lssproto_PMSG_send( int fd,int index,int petindex,int itemindex,char* message,int color ) ; /* ../doc/lssproto.html line 830 */ +void lssproto_PME_recv( int fd,int objindex,int graphicsno,int x,int y,int dir,int flg,int no,char* cdata ) ; /* ../doc/lssproto.html line 851 */ +void old_lssproto_AB_send( int fd ) ; /* ../doc/lssproto.html line 877 */ +void lssproto_AB_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 882 */ +void lssproto_ABI_recv( int fd,int num,char* data ) ; /* ../doc/lssproto.html line 913 */ +void old_lssproto_DAB_send( int fd,int index ) ; /* ../doc/lssproto.html line 921 */ +void old_lssproto_AAB_send( int fd,int x,int y ) ; /* ../doc/lssproto.html line 935 */ +void old_lssproto_L_send( int fd,int dir ) ; /* ../doc/lssproto.html line 948 */ +void old_lssproto_TK_send( int fd,int x,int y,char* message,int color,int area ) ; /* ../doc/lssproto.html line 962 */ +void lssproto_TK_recv( int fd,int index,char* message,int color ) ; /* ../doc/lssproto.html line 1011 */ +void lssproto_MC_recv( int fd,int fl,int x1,int y1,int x2,int y2,int tilesum,int objsum,int eventsum,char* data ) ; /* ../doc/lssproto.html line 1043 */ +void old_lssproto_M_send( int fd,int fl,int x1,int y1,int x2,int y2 ) ; /* ../doc/lssproto.html line 1071 */ +void lssproto_M_recv( int fd,int fl,int x1,int y1,int x2,int y2,char* data ) ; /* ../doc/lssproto.html line 1091 */ +void old_lssproto_C_send( int fd,int index ) ; /* ../doc/lssproto.html line 1128 */ +void lssproto_C_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 1135 */ +void lssproto_CA_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 1253 */ +void lssproto_CD_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 1305 */ +void lssproto_R_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 1315 */ +void old_lssproto_S_send( int fd,char* category ) ; /* ../doc/lssproto.html line 1345 */ +void lssproto_S_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 1369 */ +void lssproto_D_recv( int fd,int category,int dx,int dy,char* data ) ; /* ../doc/lssproto.html line 1715 */ +void old_lssproto_FS_send( int fd,int flg ) ; /* ../doc/lssproto.html line 1745 */ +void lssproto_FS_recv( int fd,int flg ) ; /* ../doc/lssproto.html line 1760 */ +void old_lssproto_HL_send( int fd,int flg ) ; /* ../doc/lssproto.html line 1774 */ +void lssproto_HL_recv( int fd,int flg ) ; /* ../doc/lssproto.html line 1785 */ +void old_lssproto_PR_send( int fd,int x,int y,int request ) ; /* ../doc/lssproto.html line 1795 */ +void lssproto_PR_recv( int fd,int request,int result ) ; /* ../doc/lssproto.html line 1808 */ +void old_lssproto_KS_send( int fd,int petarray ) ; /* ../doc/lssproto.html line 1824 */ +void lssproto_KS_recv( int fd,int petarray,int result ) ; /* ../doc/lssproto.html line 1835 */ + +void old_lssproto_AC_send( int fd,int x,int y,int actionno ) ; /* ../doc/lssproto.html line 1852 */ +void old_lssproto_MU_send( int fd,int x,int y,int array,int toindex ) ; /* ../doc/lssproto.html line 1883 */ +void old_lssproto_PS_send( int fd,int havepetindex,int havepetskill,int toindex,char* data ) ; /* ../doc/lssproto.html line 1907 */ +void lssproto_PS_recv( int fd,int result,int havepetindex,int havepetskill,int toindex ) ; /* ../doc/lssproto.html line 1935 */ +void old_lssproto_ST_send( int fd,int titleindex ) ; /* ../doc/lssproto.html line 1963 */ +void old_lssproto_DT_send( int fd,int titleindex ) ; /* ../doc/lssproto.html line 1979 */ +void old_lssproto_FT_send( int fd,char* data ) ; /* ../doc/lssproto.html line 1993 */ +void lssproto_SKUP_recv( int fd,int point ) ; /* ../doc/lssproto.html line 2011 */ +void old_lssproto_SKUP_send( int fd,int skillid ) ; /* ../doc/lssproto.html line 2019 */ +void old_lssproto_KN_send( int fd,int havepetindex,char* data ) ; /* ../doc/lssproto.html line 2030 */ +void lssproto_WN_recv( int fd,int windowtype,int buttontype,int seqno,int objindex,char* data ) ; /* ../doc/lssproto.html line 2047 */ +void old_lssproto_WN_send( int fd,int x,int y,int seqno,int objindex,int select,char* data ) ; /* ../doc/lssproto.html line 2166 */ +void lssproto_EF_recv( int fd,int effect,int level,char* option ) ; /* ../doc/lssproto.html line 2196 */ +void lssproto_SE_recv( int fd,int x,int y,int senumber,int sw ) ; /* ../doc/lssproto.html line 2218 */ +void old_lssproto_SP_send( int fd,int x,int y,int dir ) ; /* ../doc/lssproto.html line 2238 */ +void old_lssproto_ClientLogin_send( int fd,char* cdkey,char* passwd ) ; /* ../doc/lssproto.html line 2253 */ +void lssproto_ClientLogin_recv( int fd,char* result ) ; /* ../doc/lssproto.html line 2271 */ +void old_lssproto_CreateNewChar_send( int fd,int dataplacenum,char* charname,int imgno,int faceimgno,int vital,int str,int tgh,int dex,int earth,int water,int fire,int wind,int hometown ) ; /* ../doc/lssproto.html line 2284 */ +void lssproto_CreateNewChar_recv( int fd,char* result,char* data ) ; /* ../doc/lssproto.html line 2314 */ +void old_lssproto_CharDelete_send( int fd,char* charname ) ; /* ../doc/lssproto.html line 2338 */ +void lssproto_CharDelete_recv( int fd,char* result,char* data ) ; /* ../doc/lssproto.html line 2349 */ +void old_lssproto_CharLogin_send( int fd,char* charname ) ; /* ../doc/lssproto.html line 2366 */ +void lssproto_CharLogin_recv( int fd,char* result,char* data ) ; /* ../doc/lssproto.html line 2376 */ +void old_lssproto_CharList_send( int fd ) ; /* ../doc/lssproto.html line 2391 */ +void lssproto_CharList_recv( int fd,char* result,char* data ) ; /* ../doc/lssproto.html line 2396 */ +void old_lssproto_CharLogout_send( int fd ) ; /* ../doc/lssproto.html line 2438 */ +void lssproto_CharLogout_recv( int fd,char* result,char* data ) ; /* ../doc/lssproto.html line 2445 */ +void old_lssproto_ProcGet_send( int fd ) ; /* ../doc/lssproto.html line 2459 */ +void lssproto_ProcGet_recv( int fd,char* data ) ; /* ../doc/lssproto.html line 2465 */ +void old_lssproto_PlayerNumGet_send( int fd ) ; /* ../doc/lssproto.html line 2477 */ +void lssproto_PlayerNumGet_recv( int fd,int logincount,int player ) ; /* ../doc/lssproto.html line 2483 */ +void old_lssproto_Echo_send( int fd,char* test ) ; /* ../doc/lssproto.html line 2495 */ +void lssproto_Echo_recv( int fd,char* test ) ; /* ../doc/lssproto.html line 2506 */ +void old_lssproto_Shutdown_send( int fd,char* passwd,int min ) ; /* ../doc/lssproto.html line 2517 */ +int lssproto_InitClient( int(*)(int,char*,int) , int bufsiz , int fd); +void lssproto_SetClientLogFiles( char *read , char *write); +void lssproto_CleanupClient(void); +int lssproto_ClientDispatchMessage(int fd ,char*line); +// Robin 2001/04/06 +void lssproto_NU_recv( int fd, int AddCount ) ; /* ../doc/lssproto.html line */ +void old_lssproto_TD_send( int fd, char *data ) ; +void lssproto_TD_recv( int fd, char *data ) ; +// Robin 05/25 +void old_lssproto_FM_send( int fd, char *data ) ; +void lssproto_FM_recv( int fd, char *data ) ; +#ifdef _FIX_DEL_MAP +void lssproto_DM_send(int fd); // WON ADD ҳͼͼ +#endif +//#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_util.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_util.h new file mode 100644 index 0000000..8e7d7a1 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/lssproto_util.h @@ -0,0 +1,133 @@ +#ifndef _LSSPROTOUTIL_H_ +#define _LSSPROTOUTIL_H_ +#include +#include +#include +#ifndef WIN32 +#include +#include +#endif + +//#ifndef __NEW_PROTOCOL +// Arminius +1 +#define lssproto__ENCRYPT +//#endif + +#define lssproto__NODEBUG +struct lssproto_ { + int (*write_func)(int,char*,int) ; /* write function */ + size_t workbufsize; /* size of work area */ + char *work,*arraywork,*escapework,*val_str,*ret_work; /* work areas which have same size */ + char *cryptwork,*jencodecopy,*jencodeout,*compresswork; /* these work has bigger size (3times)*/ + char** token_list; /* token list */ + unsigned long message_id; /*= 1, */ /* for generating message IDs */ +}; +#ifdef _LSSPROTOUTIL_C_ +struct lssproto_ lssproto = { + NULL, + 0, + NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL, + NULL, + 1, +}; +char **lssproto_stringwrapper; +char lssproto_readlogfilename[1024]; +char lssproto_writelogfilename[1024]; +#else +extern struct lssproto_ lssproto; +extern char **lssproto_stringwrapper; +extern char lssproto_readlogfilename[1024]; +extern char lssproto_writelogfilename[1024]; +#endif +char* lssproto_escapeString( char*a ); +char* lssproto_descapeString( char*a ); +void lssproto_splitString( char *src ); +void lssproto_strcpysafe( char *dest, char *src, int len ); +void lssproto_strcatsafe( char *dest , char *src , int maxlen ); +char*lssproto_mkstr_int( int i ); +char*lssproto_mkstr_u_int( unsigned int i ); +char*lssproto_mkstr_long( long l ); +char*lssproto_mkstr_u_long( unsigned long l ); +char*lssproto_mkstr_short( short s ); +char*lssproto_mkstr_u_short( short s ); +char*lssproto_mkstr_char( char c ); +char*lssproto_mkstr_u_char( char c); +char*lssproto_mkstr_string( char*a ); +char*lssproto_mkstr_float( float f ); +char*lssproto_mkstr_double( double d ); +char*lssproto_mkstr_int_array( int size , int *array ); +char*lssproto_mkstr_u_int_array( int size , int *array ); +char*lssproto_mkstr_short_array( int size , short *array ); +char*lssproto_mkstr_u_short_array(int size , short *array ); +char *lssproto_mkstr_char_array( int size , char *array ); +char *lssproto_mkstr_u_char_array( int size , unsigned char *array ); +char *lssproto_mkstr_float_array( int size , float *array ); +char *lssproto_mkstr_double_array( int size , double *array ); +int lssproto_demkstr_int( char*a ); +unsigned int lssproto_demkstr_u_int( char*a ); +long lssproto_demkstr_long( char*a ); +unsigned long lssproto_demkstr_u_long(char*a ); +short lssproto_demkstr_short( char*a ); +unsigned short lssproto_demkstr_u_short( char*a ); +char lssproto_demkstr_char( char*a ); +unsigned char lssproto_demkstr_u_char( char*a ); +float lssproto_demkstr_float( char*a ); +double lssproto_demkstr_double(char*a ); +char* lssproto_demkstr_string( char*a); +int *lssproto_demkstr_int_array( char**tk ,int *buf ,int start , int size ); +int *lssproto_demkstr_u_int_array( char **tk , int *buf , int start , int size ); +unsigned int *lssproto_demkstr_long_array( + char **tk , unsigned int *buf , int start , int size ); +unsigned long *lssproto_demkstr_u_long_array( + char **tk , unsigned long *buf , int start , int size ); +short *lssproto_demkstr_short_array( char **tk , short *buf , int start , int size ); +unsigned short*lssproto_demkstr_u_short_array( + char **tk , unsigned short *buf , int start , int size ); +char *lssproto_demkstr_char_array( char **tk , char *buf , int start , int size ); +unsigned char *lssproto_demkstr_u_char_array( + char **tk , unsigned char*buf , int start , int size ); +float *lssproto_demkstr_float_array( char **tk , float *buf , int start , int size ); +double *lssproto_demkstr_u_double_array( char **tk , double *buf , int start , int size ); +char *lssproto_wrapStringAddr( char *copy , int maxcopylen , char*src ); + +void lssproto_GetMessageInfo( int *id , char *funcname , int len,char **tk ); +int lssproto_ClientRead(void); +void lssproto_consumeLine(char *buf , int ofs ); +void lssproto_copyLine( char*src , char *out , int maxoutlen ); +void lssproto_Send( int fd , char *msg ); +int lssproto_AllocateCommonWork(int bufsiz); +unsigned int lssproto_GetNewMessageID(void); +void lssproto_CreateHeader(char*out, char *fname ); +void lssproto_CreateHeaderID( char *out,int,unsigned long msgid , char *fname ); +int lssproto_default_write_wrap( int fd , char *buf , int size ); +void lssproto_bzero( char *b , int siz ); +void lssproto_bcopy(char*s , char *d , int siz ); +char *lssproto_Ltoa( long v ); +char *lssproto_Ultoa( unsigned long v ); +void lssproto_STONDEBUG_Send( int fd , char *msg ); +/* Modified by ringo to fasten int type transfer */ +char *lssproto_cnv10to62( int a, char *out, int outlen ); +int lssproto_a62toi( char *a ); + +extern BOOL bNewServer; + +#endif +// Nuke +1 +//#define NJT_MAX 32 + + + + + + + + + + + + + + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/magicitem.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/magicitem.h new file mode 100644 index 0000000..2981491 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/magicitem.h @@ -0,0 +1,4 @@ +void InitMagicItemWin(char * ); +ACTION* CreateMagicItemWin(); +ACTION* ShowMagicItemData(); + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/main.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/main.h new file mode 100644 index 0000000..0962415 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/main.h @@ -0,0 +1,55 @@ +// main.cpp ??????? + +#ifndef _MAIN_H_ +#define _MAIN_H_ + +#include "version.h" + +//---------------------------------------------------------------------------// +// ?? ????define)L? // +//---------------------------------------------------------------------------// + +extern int DEF_APPSIZEX; +extern int DEF_APPSIZEY; +extern int SCREEN_WIDTH_CENTER; +extern int SCREEN_HEIGHT_CENTER; + +//---------------------------------------------------------------------------// +// ?? ????????L? // +//---------------------------------------------------------------------------// + +int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); // ????? + +LRESULT CALLBACK PASCAL WindMsgProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); //?????????? +BOOL SystemTask( void ); // ?????????? + +// ?????? +extern HWND hWnd; // ????????? +extern BOOL WindowMode; // ???????? +extern int ResoMode; +extern int LowResoCmdFlag; // ??T???????? +extern int CmdShow; // Wi5nMain?????????????? +extern LPSTR CmdLine; // WinMain????????????????????? +extern HANDLE hMutex; // i??h??????????????? + +extern char realBinName[]; +extern char adrnBinName[]; +extern char sprBinName[]; +extern char sprAdrnBinName[]; +#ifdef _READ16BITBMP +extern char realtrueBinName[]; +extern char adrntrueBinName[]; +#endif +//add jeffrey +extern struct gameserver gmsv[]; +extern struct gamegroup gmgroup[]; +//end + +extern BOOL offlineFlag; +extern char DebugKey0[ 256 ]; +extern char DebugKey1[ 256 ]; +extern char DebugKey2[ 256 ]; + + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/map.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/map.h new file mode 100644 index 0000000..e5c8f40 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/map.h @@ -0,0 +1,250 @@ +#ifndef _MAP_H_ +#define _MAP_H_ + +// ????????????d???????nd?? + +#define MAP_TILE_GRID_X1 -20 +#define MAP_TILE_GRID_X2 +17 // Z????? +#define MAP_TILE_GRID_Y1 -16 +#define MAP_TILE_GRID_Y2 +21 // Z????? + +// ?????? +#define MAP_X_SIZE (MAP_TILE_GRID_X2 - MAP_TILE_GRID_X1) +#define MAP_Y_SIZE (MAP_TILE_GRID_Y2 - MAP_TILE_GRID_Y1) + +// ???????? +#define GRID_SIZE 64 + +// ?hLT +#define MOVE_SPEED 4 +#define MOVE_FRAME (GRID_SIZE/MOVE_SPEED) + +// ????k? +enum +{ + EVENT_NONE, // ?????D??? + EVENT_NPC, // ?eNPC + EVENT_ENEMY, // ?e?????? + EVENT_WARP, // ??? + EVENT_DOOR, // ?? + EVENT_ALTERRATIVE, // ??????l??????????????? + EVENT_WARP_MONING, // ?e??? + EVENT_WARP_NOON, // ??e??? + EVENT_WARP_NIGHT, // ??e??? + + EVENT_END // ????k???? +}; + +// ??????? +#define MAP_READ_FLAG 0x8000 // ??????????????????? +#define MAP_SEE_FLAG 0x4000 // ???????????????? + +// ????? +#define FLOOR_NAME_LEN 24 + +extern char nowFloorName[]; +extern int nowFloor; +extern int nowFloorGxSize, nowFloorGySize; +extern int nowGx, nowGy; +extern float nowX, nowY; +extern float nowVx, nowVy, nowSpdRate; +extern int nextGx, nextGy; +extern int oldGx, oldGy; +extern int oldNextGx, oldNextGy; +extern int mouseMapGx, mouseMapGy; +extern int mouseMapX, mouseMapY; + +extern short moveRouteCnt; + +extern BOOL mapEmptyFlag; + +extern float viewPointX; +extern float viewPointY; +extern int viewOffsetX; +extern int viewOffsetY; + +extern short moveAddTbl[8][2]; + + +extern BOOL mouseLeftCrick; +extern BOOL mouseLeftOn; +extern BOOL mouseRightCrick; +extern BOOL mouseRightOn; +#ifdef _MOUSE_DBL_CLICK +extern BOOL mouseDblRightOn; +#endif +extern unsigned int mouseLeftPushTime; +extern unsigned int beforeMouseLeftPushTime; + + +extern short nowEncountPercentage; +extern short nowEncountExtra; +extern short minEncountPercentage; +extern short maxEncountPercentage; +extern short sendEnFlag; +extern short encountNowFlag; + +extern short eventWarpSendFlag; +extern short eventWarpSendId; +extern short eventEnemySendFlag; +extern short eventEnemySendId; +extern short eventEnemyFlag; + +extern BOOL loginFlag; + +extern short vsLookFlag; + +extern BOOL floorChangeFlag; + +extern BOOL warpEffectFlag; +extern BOOL warpEffectStart; +extern BOOL warpEffectOk; + +extern int transmigrationEffectFlag; +extern int transEffectPaletteStatus; + +void initMap( void ); +void resetMap( void ); +void createMap( int, int, int ); +BOOL writeMap( int, int, int, int, int, + unsigned short *, unsigned short *, unsigned short * ); +void setMap( int, int, int ); +void setWarpMap( int, int ); +BOOL mapCheckSum( int, int, int, int, int, int, int, int ); + +#ifdef _NEWDRAWBATTLEMAP // (ɿ) Syu ADD ԶBattleMap +void ddrawBattleMap( void ); +#endif +void drawMap( void ); +void drawMap2( void ); +void drawTile( void ); +void redrawMap( void ); +void drawGrid( void ); +void moveProc( void ); +BOOL checkEmptyMap( int ); +void setMapMovePoint( int, int ); +void setMapMovePoint2( int, int ); +void mapMove2( void ); +void updateMapArea( void ); + +void getRouteData( int, int *, int * ); + +char cnvServDir( int, int ); + +void goFrontPartyCharacter( int, int, int ); + + +void initCharPartsPrio( void ); +void setPartsPrio( int, int, int, int, int, float, float, int); +#ifdef _SFUMATO +void setCharPrio( int, int, int, int, int, float, float, int ); +#else +void setCharPrio( int, int, int, int, int, float, float); +#endif +void stockCharParts( void ); + + +#if 0 +BOOL checkNpcEvent( int, int, int, int ); +#endif + +void drawAutoMap( int x, int y ); +void readAutoMapSeeFlag( void ); +void writeAutoMapSeeFlag( void ); + +BOOL checkHitMap( int, int ); + +void camMapToGamen( float, float, float *, float * ); +void camGamenToMap( float, float, float *, float * ); + + +#if 1 + +enum +{ + MAP_EFFECT_TYPE_NONE, + MAP_EFFECT_TYPE_RAIN, + MAP_EFFECT_TYPE_SNOW, + MAP_EFFECT_TYPE_STAR, + MAP_EFFECT_TYPE_KAMIFUBUKI, + MAP_EFFECT_TYPE_HOTARU +#ifdef _HALLOWEEN_EFFECT + ,MAP_EFFECT_TYPE_HALLOWEEN +#endif +}; + +typedef struct _MAP_EFFECT +{ + int x, y; + int dx, dy; + int gx, gy; + int ggx, ggy; + int ex, ey; + int w, h; + int cnt; + _MAP_EFFECT *pre; + _MAP_EFFECT *next; + short type; + short type2; + short mode; +#ifdef _HALLOWEEN_EFFECT + ACTION *pAction; +#endif +} MAP_EFFECT; + +extern MAP_EFFECT *useBufMapEffect; + +extern short mapEffectRainLevel; +extern short oldMapEffectRainLevel; +extern short mapEffectSnowLevel; +extern short oldMapEffectSnowLevel; +extern short mapEffectMoveDir; +extern short mapEffectKamiFubukiLevel; +#ifdef _HALLOWEEN_EFFECT +extern int mapEffectHalloween; +#endif +#ifdef __EDEN_DICE +extern BOOL bMapEffectDice; +#endif + + +extern const short fastDrawTile; +extern short fastDrawTileFlag; +extern int amountXFastDraw, amountYFastDraw; +extern int nowXFastDraw, nowYFastDraw; +extern int baseXFastDraw, baseYFastDraw; +extern int amountXFastDraw2, amountYFastDraw2; +extern int nowXFastDraw2, nowYFastDraw2; +extern int baseXFastDraw2, baseYFastDraw2; +#ifdef _MOVE_SCREEN +extern int iScreenMoveX, iScreenMoveY; +#endif + + +void initMapEffect( BOOL bFirstRun ); +void drawMapEffect( void ); +void mapEffectProc( void ); +void mapEffectRain( void ); +void mapEffectSnow( void ); +void mapEffectStar( void ); +void mapEffectFallingStar( void ); +void mapEffectKamiFubuki( void ); +void mapEffectDice(void); + +#ifdef _HALLOWEEN_EFFECT +void mapEffectHalloweenProc(void); +#endif + +void mapEffectProc2( int ); +void mapEffectRain2( int ); +void mapEffectSnow2( int ); + +void _checkEmptyMap( void ); + +#endif + +#ifdef _ITEM_PATH + extern BOOL ITEMPATHFLAG; +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/math2.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/math2.h new file mode 100644 index 0000000..df311cd --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/math2.h @@ -0,0 +1,35 @@ +/************************/ +/* math2.h */ +/************************/ +#ifndef _MATH2_H_ +#define _MATH2_H_ + +#define PAI 3.1415926535897932384626433832795 + +#define ABS(a) ( ( (a)<0 ) ? -(a) : (a) ) + +/* ?T ? ?? ??? ??? ?*******************************************************/ +void AdjustDir( float *dir ); +void AdjustDir( int *dir ); + +/* ????????????? ***********************************************************/ +float SinT( float theat ); + +/* ????????????? ***********************************************************/ +float CosT( float theat ); + +/* ????????? *********************************************************************/ +float Atan( float x, float y ); + +/* ?????D *************************************************************************/ +int Rnd( int min, int max ); + +void initRand2( void ); +int rand2( void ); + +/* ????????? *******************************************************************/ +float pointLen( float x1, float y1, float x2, float y2 ); +float pointLen2( float x1, float y1, float x2, float y2 ); + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/menu.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/menu.h new file mode 100644 index 0000000..967cef0 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/menu.h @@ -0,0 +1,972 @@ +/************************/ +/* menu.h */ +/************************/ +#ifndef _MENU_H_ +#define _MENU_H_ + +#include "pc.h" +#include "chat.h" + +#ifdef _TELLCHANNEL //ROG ADD Ƶ +#include "netproc.h" +#endif + +#ifdef _NEW_SYSTEM_MENU +#define MENU_SYSTEM_0 28 +#else +#define MENU_SYSTEM_0 9 +#endif +#define MENU_MAP_0 3 + +#define MAIL_STR_LEN 140 // ?????? +#define MAIL_DATE_STR_LEN 20 // T????? +#define MAIL_MAX_HISTORY 20 // ????? +#define MAX_CHAT_REGISTY_STR 8 // ??????K??? + +// ??????????Bl +typedef struct{ + int x, y; // ? + int defX, defY; // ?????? + int bmpNo; // ??k? + int dispPrio; // ?I + BOOL dragFlag; // ??????? + BOOL mixFlag; // ???? +}ITEM_BUFFER; + +// ???????Bl +typedef struct{ + char str[ MAIL_MAX_HISTORY ][ MAIL_STR_LEN + 1 ]; // ???????? + char dateStr[ MAIL_MAX_HISTORY ][ MAIL_DATE_STR_LEN + 1 ]; // T??? + int noReadFlag[ MAIL_MAX_HISTORY ]; // t??????????????k?? + int petLevel[ MAIL_MAX_HISTORY ]; // ??????????k? + char petName[ MAIL_MAX_HISTORY ][ PET_NAME_LEN + 1 ]; // ????q + int itemGraNo[ MAIL_MAX_HISTORY ]; // ?????????????k? + int newHistoryNo; // ????k? +}MAIL_HISTORY; + +// ????????????Bl +typedef struct{ + int sizeX,sizeY; // ??? + int titleNo; // ????k? + int titleX, titleY; // ?????? + int mx, my; // ?? + int nowX, nowY; // ?????? + int cnt; // ?? + int wndType; // ??????? + int hitFlag; // ???Re??? + int yesDispNo; // ??????Rek? + int noDispNo; // ???????Rek? + int boxDispPrio; // ???????I?? + int yesNoResult; // YesNo???????? ???? +}WINDOW_DISP; + +#if defined(__ALBUM_47) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND_42 545 +#define MAX_PET_KIND_43 549 +#define MAX_PET_KIND_44 551 +#define MAX_PET_KIND_45 553 +#define MAX_PET_KIND_46 555 +//#define MAX_PET_KIND 557 +//#define MAX_PET_KIND 558 // Robin fix +//#define MAX_PET_KIND 564 // Robin fix +//#define MAX_PET_KIND 566 // Robin fix +#define MAX_PET_KIND 570 // Robin fix + +#elif defined(__ALBUM_46) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND_42 545 +#define MAX_PET_KIND_43 549 +#define MAX_PET_KIND_44 551 +#define MAX_PET_KIND_45 553 +#define MAX_PET_KIND 555 + +#elif defined(__ALBUM_45) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND_42 545 +#define MAX_PET_KIND_43 549 +#define MAX_PET_KIND_44 551 +#define MAX_PET_KIND 553 + +#elif defined(__ALBUM_44) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND_42 545 +#define MAX_PET_KIND_43 549 +#define MAX_PET_KIND 551 + +#elif defined(__ALBUM_43) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND_42 545 +#define MAX_PET_KIND 549 + +#elif defined(__ALBUM_42) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND_41 543 +#define MAX_PET_KIND 545 + +#elif defined(__ALBUM_41) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND_40 542 +#define MAX_PET_KIND 543 + +#elif defined(__ALBUM_40) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND_39 540 +#define MAX_PET_KIND 542 + +#elif defined(__ALBUM_39) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND_38 521 +#define MAX_PET_KIND 540 + +#elif defined(__ALBUM_38) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND_37 498 +#define MAX_PET_KIND 521 + +#elif defined(__ALBUM_37) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND_36 483 +#define MAX_PET_KIND 496 + +#elif defined(__ALBUM_36) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND_35 462 +#define MAX_PET_KIND 483 +#elif defined(__ALBUM_35) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND_34 436 +#define MAX_PET_KIND 462 //460 + +#elif defined(__ALBUM_34) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND_33 432 +#define MAX_PET_KIND 436 + +#elif defined(__ALBUM_33) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND_32 431 +#define MAX_PET_KIND 432 + +#elif defined(__ALBUM_32) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND_15 357 +#define MAX_PET_KIND_16 364 +#define MAX_PET_KIND_17 389 +#define MAX_PET_KIND_18 391 +#define MAX_PET_KIND_19 395 +#define MAX_PET_KIND_20 398 +#define MAX_PET_KIND_21 401 +#define MAX_PET_KIND_22 405 +#define MAX_PET_KIND_23 407 +#define MAX_PET_KIND_24 414 +#define MAX_PET_KIND_25 415 +#define MAX_PET_KIND_26 420 +#define MAX_PET_KIND_27 422 +#define MAX_PET_KIND_28 423 +#define MAX_PET_KIND_29 424 +#define MAX_PET_KIND_30 425 +#define MAX_PET_KIND_31 429 +#define MAX_PET_KIND 431 + +#elif defined(__ALBUM_15) +#define MAX_PET_KIND_1 124 +#define MAX_PET_KIND_4 224 +#define MAX_PET_KIND_5 228 +#define MAX_PET_KIND_6 229 +#define MAX_PET_KIND_7 230 +#define MAX_PET_KIND_8 237 +#define MAX_PET_KIND_9 240 +#define MAX_PET_KIND_10 297 +#define MAX_PET_KIND_11 301 +#define MAX_PET_KIND_12 305 +#define MAX_PET_KIND_13 306 +#define MAX_PET_KIND_14 353 +#define MAX_PET_KIND 357 +#else +#define MAX_PET_KIND 10000 // ????? +#define MAX_PET_TBL 181 // ??????????? +#endif + +#define MAX_PET_PAGE_SIZE 8 // ????????????? +#ifdef _PET_ITEM +#define MAX_PET_SPECIES 42 // +#endif + +// ????????????hk? +enum{ + ANIM_DISP_PET, // ??? + ANIM_DISP_PET_SEND, // ?????????????h + ANIM_DISP_PET_RECIEVE, // ???????????h + + ANIM_DISP_PET_MAIN, // ?????hk?? + ANIM_DISP_PET_WALK, // ? + ANIM_DISP_PET_STAND, // r? + ANIM_DISP_PET_ATTACK, // ?? + ANIM_DISP_PET_GUARD, // ??? + ANIM_DISP_PET_DAMAGE, // ???? + ANIM_DISP_PET_DEAD, // ? + ANIM_DISP_PET_ITEM, // ??????? + + ANIM_DISP_LETTER_MOVE, // ??h + ANIM_DISP_LETTER, // ???????? + + ANIM_DISP_MIX_PET_INIT, // ??????? + ANIM_DISP_MIX_PET_MOVE, // ?????????h + ANIM_DISP_MIX_PET_MOJI, // ??????????????? +#ifdef _THEATER + ANIM_DISP_THEATER_NPC, // 糡NPCʾ +#endif +#ifdef _AniCrossFrame // Syu ADD ι + ANIM_DISP_CROSSFRAME = 18, +#endif + ANIM_DISP_MIX_PET_END, // ??????? +}; + +// ?????Bl +typedef struct{ + char name[ PET_NAME_LEN + 1 ]; // ????q + char freeName[ PET_NAME_LEN + 1 ]; // ?????? + int faceGraNo; // ???????????k? + int level; // ??? + int maxHp; // ??? + int str; // ??? + int quick; // ?? + int def; // \?? + int earth, water, fire, wind; // ??? + int flag; // K???????????? ??? ?????? ?K??? ? +}PET_ALBUM; + +// ????????????????Bl +typedef struct{ + int albumNo; // ?????????k? + char name[ PET_NAME_LEN + 1 ]; // ????q + int faceGraNo; // ???????????k? +}PET_ALBUM_TBL; + + +// ???????? +extern BOOL TaskBarFlag; +// ?????? +extern unsigned int MenuToggleFlag; +// ????????? +extern ITEM_BUFFER ItemBuffer[]; +// ???????????? +extern int StatusUpPoint; +// ӡP????????????? +extern BOOL BattlePetReceiveFlag; +#ifdef _STANDBYPET +extern BOOL StandbyPetSendFlag; +#endif +// ????????k? +extern int BattlePetReceivePetNo; +// ???????? +extern MAIL_HISTORY MailHistory[]; +// ??????K??V?????? +extern STR_BUFFER chatRegistryStr[]; +// ????V??? +extern STR_BUFFER MailStr; +// ?????????????? +extern ACTION *pActMenuWnd3; +// ??????K??V?????? +extern STR_BUFFER chatRegistryStr[]; +// ?????????? +extern STR_BUFFER shougouChange; + +#ifdef _MONEYINPUT //Syu ADD ֶǮ +extern STR_BUFFER MymoneyBuffer; +#endif +#ifdef _ITEM_JIGSAW +extern int JigsawIdx; +void SetJigsaw(int img, char *str); +#endif + +typedef enum{ + MAIL_WND_VIEW, + MAIL_WND_SELECT, + MAIL_WND_SEND, + MAIL_WND_PET_SEND, + MAIL_WND_ITEM, + MAIL_WND_HISTORY, +}MAIL_WND_TYPE; + +extern STR_BUFFER TradeBuffer; +// ????q???? +extern STR_BUFFER petNameChange; +// Terry add 2002/01/04 +#ifdef __EDEN_AUCTION +extern STR_BUFFER AuctionStr; // ,50 +extern STR_BUFFER AuctionMoney; // Ǯһ +#endif +// Terry end +// ????????????????k? +extern int petStatusNo; + +extern int mailHistoryWndPageNo; // ???????????k? +extern int mailHistoryWndSelectNo; // k?????k? +//extern int mailReceivePetGraNo; // ??????????????????k? + +// Pf??h????????????? +extern int MapWmdFlagBak; + +// Pf?????????????????? +#define RESULT_WND_CLOSE_TIME 300 // ? +// Pf????????????????? +extern int ResultWndTimer; + +// ?????? +extern BOOL ItemMixRecvFlag; + +// ??????? +extern int MouseCursorFlag; +#ifdef _TRADETALKWND // (ɿ) Syu ADD Ի +void TradeTalk ( char *msg ) ; +#endif + +void InitItem( int x, int y , BOOL bPetItemFlag); + +// ?????????? *******************************************************/ +void InitMenu( void ); + +// ??????????? *******************************************************/ +void InitMenu2( void ); + +// ??????????? *******************************************************/ +BOOL CheckMenuFlag( void ); + +// ?????? ***************************************************************/ +void MenuProc( void ); + +// ????????? ***************************************************/ +ACTION *MakeWindowDisp( int x, int y, int sizeX, int sizeY, int titleNo, int wndType +#ifdef _NEW_RESOMODE //800 600ģʽ + , BOOL fixType = TRUE +#endif + ); + +// ???Re????? ******************************************************/ +BOOL MakeHitBox( int x1, int y1, int x2, int y2, int dispPrio ); + +// ???????V ****************************************************************/ +BOOL SaveMailHistory( int no ); + +// ?????????? ****************************************************************/ +BOOL LoadMailHistory( void ); + +// ???t???? ****************************************************************/ +BOOL CheckMailNoReadFlag( void ); + +// ??????????^M?? **************************************************/ +void InitOhtaParam( void ); + +// ????????? **********************************************************/ +void DeathLetterAction( void ); + +// ?????K???V ****************************************************************/ +BOOL SaveChatRegistyStr( void ); + +// ?????K?????? ****************************************************************/ +BOOL LoadChatRegistyStr( void ); + +// ?????????? *****************************************************/ +void CenteringStr( char *inStr, char *outStr, int max ); + +// ????????? ****************************************************************/ +void CheckNewPet( int sprNo ); + +// Pf?????????? **********************************************************/ +void CheckBattleNewPet( void ); + +// ???????? ****************************************************************/ +BOOL LoadAlbum( void ); + +// ?????V ****************************************************************/ +BOOL SaveAlbum( int no ); +ACTION *MakeAnimDisp( int x, int y, int sprNo, int mode ); + +// Robin 04/16 trade +void tradeInit( void ); + +void BankmanInit( char* data ); +void BankmanWN( void ); +void closeBankman( void ); +#endif + +#ifdef _TELLCHANNEL //ROG ADD Ƶ +void InitSelectChar( char *msg, BOOL endFlag); +void SelectChar( void ); +void DeathTellChannel( void ); +extern int TalkMode; +extern char secretName[32]; +#endif + + +#ifdef _FRIENDCHANNEL //ROG ADD Ƶ +#define MAX_ROOM_NUM 50 +extern bool setRoomFlag; +extern bool secretFlag; // +extern int selChar; +extern ACTION *pChtChanlWnd; //Ӵ +extern ACTION *pSelChanlWnd; +void SelectChatRoom( void ); +void InitSelChatRoom(char *msg); +void InitCreateChatRoom(char *msg); +void ChatRoomWnd(void); +void initAssentWnd(char *data); +void AssentWnd(void); +extern STR_BUFFER chatRoomName; // +extern ACTION *pSetRoomWnd; +void setRoomName(void); //趨 + +#endif + + +///////////////////////////////////////// +#ifdef _TIMEBAR_FUNCTION +int SetTimeBarPos(int timBarIdent, int CurPos); +int SetTimeBar(char *title, int range); +#endif + +#ifdef _STANDBYPET +void send_StandBy_Pet( void); +#endif + +#ifdef _NPC_ITEMUP +void ShowItemup(int value, int x, int y); +#endif + +#ifdef _NPC_ITEMUP +void ShowCounttime(int value, int x, int y); +#endif + +#ifdef _NEW_SPEED_ +extern BOOL GameSpeedFlag; +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/mouse.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/mouse.h new file mode 100644 index 0000000..fe923ec --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/mouse.h @@ -0,0 +1,89 @@ +/************************/ +/* mouse.h */ +/************************/ +#ifndef _MOUSE_H_ +#define _MOUSE_H_ + +//#include "menu.h" + +// ????֢t + +#define MOUSE_NO_CRICK 0 // ??????? +#define MOUSE_LEFT_CRICK ( 1 << 0 ) // ?????֢t +#define MOUSE_RIGHT_CRICK ( 1 << 1 ) // ?????֢t +#define MOUSE_LEFT_CRICK_UP ( 1 << 2 ) // ????????֢t +#define MOUSE_RIGHT_CRICK_UP ( 1 << 3 ) // ????????֢t +#define MOUSE_LEFT_DBL_CRICK ( 1 << 4 ) // ????????֢t +#define MOUSE_RIGHT_DBL_CRICK ( 1 << 5 ) // ????????֢t +//#define MOUSE_LEFT_AUTO_CRICK ( 1 << 6 ) // ????????֢t +//#define MOUSE_RIGHT_AUTO_CRICK ( 1 << 7 ) // ????????֢t + +// ????? ?Bl +typedef struct{ + int x, y; // ????( ?,? )? +}MOUSE_POINT; + +// ????Bl +typedef struct{ + MOUSE_POINT nowPoint; // ???????? + MOUSE_POINT crickLeftDownPoint; // ??????????????? + MOUSE_POINT crickLeftUpPoint; // ????????????????? + MOUSE_POINT crickRightDownPoint;// ??????????????? + MOUSE_POINT crickRightUpPoint; // ????????????????? + int state; // ???????֢t???????? + int onceState; // ???????֢t????????????????k?V? + int autoState; // ???????֢t??????? + UINT beforeLeftPushTime; // ?????????????? + UINT leftPushTime; // ?????????????? + UINT beforeRightPushTime;// ?????????????? + UINT rightPushTime; // ?????????????? + UCHAR level; // ????????????? + int itemNo; // ?????????????k? + BOOL flag; // ???????????? +}MOUSE; + +// ????? ??? +extern MOUSE mouse; + +// ????????????????k???????? +extern int HitFontNo; +// ????????????????????????????? +extern int HitDispNo; + +// ???????? +extern char OneLineInfoStr[]; + +// ????? +extern int BoxColor; + +// ???ѩ???? //////////////////////////////////////////////////////// +void MouseInit( void ); + +// ????????t????? ////////////////////////////////////////////// +void MouseNowPoint( int x, int y ); + +// ????????????????????t????? ////////////////////// +void MouseCrickLeftDownPoint( int x, int y ); + +// ????????????????????t????? ////////////////////// +void MouseCrickLeftUpPoint( int x, int y ); + +// ????????????????????t????? ////////////////////// +void MouseCrickRightDownPoint( int x, int y ); + +// ????????????????????t????? ////////////////////// +void MouseCrickRightUpPoint( int x, int y ); + +// ??????????????????t????? ////////////////////////// +void MouseDblCrickLeftUpPoint( int x, int y ); + +// ??????????????????t????? ////////////////////////// +void MouseDblCrickRightUpPoint( int x, int y ); + +// ????? /////////////////////////////////////////////////////////////// +void MouseProc( void ); + +/* ???????????Re **************************************************/ +void HitMouseCursor( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/netmain.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/netmain.h new file mode 100644 index 0000000..880f2b3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/netmain.h @@ -0,0 +1,97 @@ +#ifndef _NETMAIN_H_ +#define _NETMAIN_H_ + +#include "../systeminc/version.h" + +struct gameserver +{ + char used; + char ipaddr[127]; + char port[64]; + char name[64]; +#ifdef _SHOW_COUNT // WON ADD + char count[64]; +#endif +#ifdef _SHOWIPSLEEP_ + int delay; +#endif +}; + +struct gamegroup{ + char used; + char num; + char startindex; + char name[61]; +}; + +#define SUCCESSFULSTR "successful" // ????????e?? +#define FAILEDSTR "failed" +#define OKSTR "ok" +#define CANCLE "cancle" + +#define TIMEOUT (600*1000) // ???????????????????????? + +//#define NETBUFSIZ (1024*16) +//#define NETBUFSIZ (1024*8) +#define NETBUFSIZ (1024*64) // Robin 2004.05.04 + +extern char *net_writebuf; +extern char *net_readbuf; +extern int net_readbuflen; +extern int net_writebuflen; + +extern unsigned int sockfd; +extern int server_choosed; +extern int init_net; + +extern struct gameserver gmsv[]; + +#ifdef _LOG_MSG +extern char debugLogFileName[]; +#endif + +typedef int BOOL; +extern BOOL disconnectServerFlag; +extern BOOL oldDisconnectServerFlag; + + +int getServerInfo( int, char *, short * ); + + +void networkLoop(void); +void networkMycharWalk( int gx , int gy , char *direction ); + +int initNet(void); +void cleanupNetwork( void ); +int appendReadBuf( char *buf , int size ); +int appendWriteBuf( int index , char *buf , int size ); +int shiftReadBuf( int size ); +int shiftWriteBuf( int size ); +int getLineFromReadBuf( char *output , int maxlen ); +int sendn( unsigned int s , char *buffer , int len ); + + + +int getServerInfoByServerName( char *servername , char *hostname , short *port ); + + +// ???????? +#define NET_ERRMSG_SOCKLIBERROR "·δ׼á" +#define NET_ERRMSG_BADNAME "Ʋȷ" +#define NET_ERRMSG_SOCKETERROR "޷ִsocketTCP" +#define NET_ERRMSG_NOTGETADDR ",ϵͷ" +#define NET_ERRMSG_NOTCONNECT_S "޷ʼзӡ" +#define NET_ERRMSG_NOTCONNECT "δ볢" +#define NET_ERRMSG_CONNECTTIMEOUT "ʱѵ" +#define NET_ERRMSG_LOGINTIMEOUT "봦ʱѵ" +#define NET_ERRMSG_CHARLISTTIMEOUT "ȡʱѵ" +#define NET_ERRMSG_LOGOUTTIMEOUT "dzʱѵ" +#define NET_ERRMSG_LOGINFAIL "޷" +#define NET_ERRMSG_CREATECHARTIMEOUT "ʱѵ" +#define NET_ERRMSG_DELETECHARTIMEOUT "ʱѵ" +#define NET_ERRMSG_VERSIONERROR "ǰİ汾̫ɣʹøϷ½" + +#define GAMESTATE_ERRMSG_LOGOUTDENY "ܾdz" + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/netproc.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/netproc.h new file mode 100644 index 0000000..5aad0b9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/netproc.h @@ -0,0 +1,87 @@ +#ifndef _NETPROC_H_ +#define _NETPROC_H_ + +#ifdef _THEATER +enum +{ + E_DATA_TYPE_PLAYER, // + E_DATA_TYPE_TALK, // ̨ + E_DATA_TYPE_ASIDE, // ԰ + E_DATA_TYPE_ACTION, // + E_DATA_TYPE_MOVE, // ƶ + E_DATA_TYPE_SCENERY, // + E_DATA_TYPE_CHANGE, // + E_DATA_TYPE_DIR, // + E_DATA_TYPE_EFFECT, // Ч + E_DATA_TYPE_FACE, // + E_DATA_TYPE_NOTE, // ע + E_DATA_TYPE_BGM, // + E_DATA_TYPE_NPC, // NPC + E_DATA_TYPE_END +}; + +// lssproto_TheaterData_recv ʹ +enum +{ + E_THEATER_SEND_DATA_THEATER_MODE = E_DATA_TYPE_END + 1, // Ժģʽ : 0:ȡ糡ģʽ 1: 2: + E_THEATER_SEND_DATA_DISPLAY_SCORE, // ʾ : + E_THEATER_SEND_DATA_END +}; +#endif + +extern short selectServerIndex; +extern short clientLoginStatus; +extern short charListStatus; +extern short charDelStatus; + +#ifdef _NPC_MAGICCARD +extern bool bShowflag[20]; +extern int iPosition[20]; +extern int iShowdamage[20]; +extern int iOffsetY[20]; +extern int ioffsetsx; +extern int ioffsetsy; +extern unsigned int inextexet ; +#endif + +extern char gamestate_chooseserver_name[]; +extern char gamestate_login_charname[]; +extern char gamestate_deletechar_charname[]; + +extern char netprocErrmsg[]; + +extern int connectServer2Counter; +/* +#ifdef _TELLCHANNEL // (ɿ) ROG ADD Ƶ +extern char ReTellName[]; +#endif +*/ +void initConnectServer( void ); +int ConnectWGS(); +int connectServer( void ); + +void charListStart( void ); +int charListProc( void ); +void charLoginStart( void ); +int charLoginProc( void ); + +void createNewCharStart( void ); +int createNewCharProc( void ); + +void charLogoutStart( void ); +int charLogoutProc( void ); + +void walkSendForServer( int, int, char * ); +void noChecksumWalkSendForServer( int, int, char * ); + +void chatStrSendForServer( char *, int ); + +void delCharStart( void ); +int delCharProc( void ); + +#ifdef _PK2007 +void pkListStart( void ); +int pkListProc( void ); +#endif + +#endif /* ifndef _NETPROC_H_ */ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/onlinegm.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/onlinegm.h new file mode 100644 index 0000000..36c9768 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/onlinegm.h @@ -0,0 +1,111 @@ + +#ifndef _ONLINEGM_ +#define _ONLINEGM_ + +#define ONLINEGM_BACKGROUND OLD_GRAPHICS_START+821 //ͼ +#define ONLINEGM_YES_OR_NO 35322 //Сʯ屳ͼ 26195ͼ +#define ONLINEGM_CHECK_U OLD_GRAPHICS_START+820 //ѯ() +#define ONLINEGM_CHECK_D 35319 //ѯ() +#define ONLINEGM_DELETE_U OLD_GRAPHICS_START+819 //ɾ() +#define ONLINEGM_DELETE_D 35321 //ɾ() +#define ONLINEGM_ENTER_U 26099 //() +#define ONLINEGM_ENTER_D 35320//() +#define ONLINEGM_CLEAR_U 26298 //() +#define ONLINEGM_CLEAR_D 26299 //() +#define ONLINEGM_HELP_U OLD_GRAPHICS_START+818 //ע() +#define ONLINEGM_HELP_D 35318 //ע() +#define ONLINEGM_QUIT 26042 //ر +#define ONLINEGM_UP_U 26064 //Ͼ() +#define ONLINEGM_UP_D 26065 //Ͼ() +#define ONLINEGM_DOWN_U 26066 //¾() +#define ONLINEGM_DOWN_D 26067 //¾() +#define ONLINEGM_SURE_D 26288 //ȷ()(ɫ) +#define ONLINEGM_SURE_U 26289 //ȷ()(ɫ) +#define ONLINEGM_CHANCEL 26291 //ȡ + + +#define DEF_UPDOWN_TOTAL 22 // ¾ +#define DEF_BUTTON_TOTAL 28 // ϻرϵͳť +#define DEF_CLASS_TOTAL 2 // +#define DEF_C1_TOTAL 14 // һϸ +#define DEF_C2_TOTAL 11 // ϸ + +#define DEF_MAX_ADD_VALUE 20 //Ŀǰ趨20 + +#define MAX_INPUT_LINE 30 // + +#define DEF_INPUT_LINE 4 // ʾ chat20 + +#define MAX_INPUT_HISTORY 20 // ??????????? + +const long UP_ANIM_ID[DEF_BUTTON_TOTAL]={ + ONLINEGM_CHECK_U , + ONLINEGM_DELETE_U , + ONLINEGM_ENTER_U , + ONLINEGM_CLEAR_U , + ONLINEGM_HELP_U , + ONLINEGM_QUIT , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U , + ONLINEGM_UP_U , + ONLINEGM_DOWN_U +}; +const long DOWN_ANIM_ID[DEF_BUTTON_TOTAL]={ + ONLINEGM_CHECK_D , + ONLINEGM_DELETE_D , + ONLINEGM_ENTER_D , + ONLINEGM_CLEAR_D , + ONLINEGM_HELP_D , + ONLINEGM_QUIT , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D , + ONLINEGM_UP_D , + ONLINEGM_DOWN_D +}; +const short BUTTON_XY[DEF_BUTTON_TOTAL][2]={ + {584,97 },{584 ,120},{584,316},{584, 340},{584,409},{584 ,434}, + {550-100,54+100 },{530+1-100,72+100 },{550-100,366+100},{530+1-100,384+100}, + {164-100,175+100},{144+1-100,193+100},{229-100,175+100},{209+1-100,193+100},{298-100,175+100},{278+1-100,193+100}, + {468-100+21,175+100},{448+1-100+21,193+100},{530-100+21,175+100},{510+1-100+21,193+100},{593-100+21,175+100},{573+1-100+21,193+100}, + {164-100,212+100},{144+1-100,230+100},{392-100,212+100},{372+1-100,230+100},{614-100,212+100},{594+1-100,230+100} +}; + +int iOnlineGmProc( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/palname.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/palname.h new file mode 100644 index 0000000..589b072 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/palname.h @@ -0,0 +1,21 @@ +// ??????????? +"data\\pal\\Palet_1.sap", // ? +"data\\pal\\Palet_2.sap", // ? +"data\\pal\\Palet_3.sap", // ? +"data\\pal\\Palet_4.sap", // + +"data\\pal\\Palet_5.sap", // ԢN +"data\\pal\\Palet_6.sap", // ?N +"data\\pal\\Palet_7.sap", // ?N +"data\\pal\\Palet_8.sap", // ?N +"data\\pal\\Palet_9.sap", // +"data\\pal\\Palet_10.sap", // ???? +"data\\pal\\Palet_11.sap", // ??? +"data\\pal\\Palet_12.sap", // ? +"data\\pal\\Palet_13.sap", // +"data\\pal\\Palet_14.sap", // ? +"data\\pal\\Palet_15.sap", // ? +"data\\pal\\Palet_0.sap", //Waei logo +"white.sap", // ??{??? +"black.sap", // ??{??? + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/pattern.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/pattern.h new file mode 100644 index 0000000..efdc771 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/pattern.h @@ -0,0 +1,10 @@ +/************************/ +/* pattern.h */ +/************************/ +#ifndef _PATTERN_ +#define _PATTERN_ +int pattern( ACTION *a0, int anim_spd, int loop_flg ); +#define ANM_NOMAL_SPD 0 +#define ANM_LOOP 0 +#define ANM_NO_LOOP 1 +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/pc.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/pc.h new file mode 100644 index 0000000..3dab232 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/pc.h @@ -0,0 +1,723 @@ +#ifndef _PC_H_ +#define _PC_H_ + +#include "action.h" +#ifdef _MORECHARACTERS_ +#define MAXCHARACTER 4 +#else +#define MAXCHARACTER 2 +#endif +#define CHAR_NAME_LEN 16 +#define CHAR_FREENAME_LEN 32 +#define MAGIC_NAME_LEN 28 +#define MAGIC_MEMO_LEN 72 +#define ITEM_NAME_LEN 28 +#define ITEM_NAME2_LEN 16 +#define ITEM_MEMO_LEN 84 +#define PET_NAME_LEN 16 +#define PET_FREENAME_LEN 32 +#define CHAR_FMNAME_LEN 33 // + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#define PROFESSION_MEMO_LEN 84 +#endif + +#ifdef _GM_IDENTIFY // Rog ADD GMʶ +#define GM_NAME_LEN 32 +#endif + +//#define CHARNAMELEN 256 // ??????? + +#define MAX_PET 5 + +#define MAX_MAGIC 9 + +#define MAX_PARTY 5 + +#define MAX_ADR_BOOK_COUNT 4 +#ifdef _EXTEND_AB + #define MAX_ADR_BOOK_PAGE 20//20 //10 20050214 cyg 10 add to 20 +#else + #define MAX_ADR_BOOK_PAGE 10 +#endif +#define MAX_ADR_BOOK (MAX_ADR_BOOK_COUNT*MAX_ADR_BOOK_PAGE) + +#ifdef _ITEM_EQUITSPACE +typedef enum +{ + CHAR_HEAD, + CHAR_BODY, + CHAR_ARM, + CHAR_DECORATION1, + CHAR_DECORATION2, + +#ifdef _ITEM_EQUITSPACE + CHAR_EQBELT, + CHAR_EQSHIELD, + CHAR_EQSHOES, +#endif + +#ifdef _EQUIT_NEWGLOVE + CHAR_EQGLOVE, +#endif + CHAR_EQUIPPLACENUM, +#ifdef _PET_ITEM + PET_HEAD = 0, // ͷ + PET_WING, // + PET_TOOTH, // + PET_PLATE, // + PET_BACK, // + PET_CLAW, // צ + PET_FOOT, // () + PET_EQUIPNUM +#endif +}CHAR_EquipPlace; + +#ifdef _PET_ITEM +typedef enum +{ +// , + ITEM_PET_HEAD = 29, // ͷ + ITEM_PET_WING, // + ITEM_PET_TOOTH, // + ITEM_PET_PLATE, // 廤 + ITEM_PET_BACK, // + ITEM_PET_CLAW, // צ + ITEM_PET_1_FOOT, // Ų,˫ + ITEM_PET_2_FOOT, // Ų, + ITEM_PET_FIN, // Ų, + ITEM_CATEGORYNUM +}ITEM_CATEGORY; +#define MAX_PET_ITEM 7 +#endif + +#define MAX_ITEMSTART CHAR_EQUIPPLACENUM +#define MAX_MAXHAVEITEM 15 +#ifdef _NEW_ITEM_ +#define MAX_ITEM (MAX_ITEMSTART+MAX_MAXHAVEITEM*3) +int жҵ(); +#else +#define MAX_ITEM (MAX_ITEMSTART+MAX_MAXHAVEITEM) +#endif +#else +#define MAX_ITEMSTART 5 +#define MAX_ITEM 20 +#endif + +#define RESULT_ITEM_COUNT 3 +#define RESULT_ITEM_NAME_LEN 24 +//#define RESULT_CHR_EXP 4 +#define RESULT_CHR_EXP 5 + +#define SKILL_NAME_LEN 24 +#define SKILL_MEMO_LEN 72 +#define MAX_SKILL 7 + + + +#define MAX_GOLD 1000000 +#define MAX_BANKGOLD 10000000 +#define MAX_FMBANKGOLD 100000000 + + +#define MAX_PERSONAL_BANKGOLD 50000000 + +#ifdef _FMVER21 +#define FAMILY_MAXMEMBER 100 // +#else +#define FAMILY_MAXMEMBER 50 // +#endif + +enum +{ + PC_ETCFLAG_PARTY = (1 << 0), + PC_ETCFLAG_DUEL = (1 << 1), + PC_ETCFLAG_CHAT_MODE = (1 << 2), //Ƶ + PC_ETCFLAG_MAIL = (1 << 3), //ƬƵ + PC_ETCFLAG_TRADE = (1 << 4) +#ifdef _CHANNEL_MODIFY + ,PC_ETCFLAG_CHAT_TELL = (1 << 5) //Ƶ + ,PC_ETCFLAG_CHAT_FM = (1 << 6) //Ƶ +#ifdef _CHAR_PROFESSION + ,PC_ETCFLAG_CHAT_OCC = (1 << 7) //ְҵƵ +#endif + ,PC_ETCFLAG_CHAT_SAVE = (1 << 8) //Ի濪 +#ifdef _CHATROOMPROTOCOL + ,PC_ETCFLAG_CHAT_CHAT = (1 << 9) //ҿ +#endif +#endif +#ifdef _CHANNEL_WORLD + ,PC_ETCFLAG_CHAT_WORLD = (1 << 10) //Ƶ +#endif +#ifdef _CHANNEL_ALL_SERV + ,PC_ETCFLAG_ALL_SERV = (1 << 11) //Ƶ +#endif + ,PC_AI_MOD = (1 << 12) +}; + +enum +{ + PC_ETCFLAG_CHAT_MODE_ID = 0 + +#ifdef _CHANNEL_MODIFY + ,PC_ETCFLAG_CHAT_TELL_ID //Ƶ + ,PC_ETCFLAG_CHAT_PARTY_ID //Ƶ + ,PC_ETCFLAG_CHAT_FM_ID //Ƶ +#ifdef _CHAR_PROFESSION + ,PC_ETCFLAG_CHAT_OCC_ID //ְҵƵ +#endif +#ifdef _CHATROOMPROTOCOL + ,PC_ETCFLAG_CHAT_CHAT_ID // +#endif +#else + ,PC_ETCFLAG_CHAT_PARTY_ID //Ƶ +#endif +#ifdef _CHANNEL_WORLD + ,PC_ETCFLAG_CHAT_WORLD_ID //Ƶ +#endif +#ifdef _CHANNEL_ALL_SERV + ,PC_ETCFLAG_ALL_SERV_ID //Ƶ +#endif + ,PC_ETCFLAG_CHAT_WORLD_NUM +}; + +#define ITEM_FLAG_PET_MAIL ( 1 << 0 ) +#define ITEM_FLAG_MIX ( 1 << 1 ) +#define ITEM_FLAG_COOKING_MIX ( 1 << 2 ) +#define ITEM_FLAG_METAL_MIX ( 1 << 3 ) // +#define ITEM_FLAG_JEWEL_MIX ( 1 << 4 ) //ʯ +#define ITEM_FLAG_FIX_MIX ( 1 << 5 ) //޸ +#ifdef _ITEM_INTENSIFY +#define ITEM_FLAG_INTENSIFY_MIX ( 1 << 6 ) //ǿ +#endif +#ifdef _ITEM_UPINSLAY +#define ITEM_FLAG_UPINSLAY_MIX ( 1 << 7 ) // +#endif + +typedef struct +{ + int color; // q? + int graNo; // ??k? + int level; // ??????? +#ifdef _ITEM_PILENUMS + int pile; +#endif +#ifdef _ALCHEMIST //#ifdef _ITEMSET7_TXT + char alch[4+200]; +#endif + short useFlag; // ???? + short field; // ????? + short target; // n + short deadTargetFlag; // ???????n??? + short sendFlag; // ?????????u? + char name[ITEM_NAME_LEN*2+1]; // ???? + char name2[ITEM_NAME2_LEN*2+1]; // ????? + char memo[ITEM_MEMO_LEN*2+1]; // ?? + char damage[20]; +#ifdef _PET_ITEM + char type; +#endif +#ifdef _ITEM_JIGSAW + char jigsaw[50]; +#endif +#ifdef _NPC_ITEMUP + int itemup; +#endif +#ifdef _ITEM_COUNTDOWN + int counttime; +#endif +#ifdef _MAGIC_ITEM_ + int ; +#endif +} ITEM; + +typedef struct +{ + int graNo; + int faceGraNo; + int id; + int dir; + int hp, maxHp; + int mp, maxMp; + int vital; + int str, tgh, dex; + int exp, maxExp; + int level; + int atk, def; + int quick, charm, luck; + int earth, water, fire, wind; + int gold; +#ifdef _NEW_MANOR_LAW + int fame; +#endif + int titleNo; + int dp; + char name[CHAR_NAME_LEN+1]; + char freeName[CHAR_FREENAME_LEN+1]; + short nameColor; +#ifdef _ANGEL_SUMMON + unsigned status; +#else + unsigned short status; +#endif + unsigned short etcFlag; + short battlePetNo; + short selectPetNo[MAX_PET]; + short mailPetNo; +#ifdef _STANDBYPET + short standbyPet; +#endif + int battleNo; + short sideNo; + short helpMode; + ITEM item[MAX_ITEM]; + ACTION *ptAct; + int pcNameColor; + short transmigration; + char chusheng[61]; + char familyName[CHAR_NAME_LEN+1]; + int familyleader; + int channel; + int quickChannel; + int personal_bankgold; + int ridePetNo;// + int learnride; + unsigned int lowsride; + char ridePetName[CHAR_FREENAME_LEN+1]; + int ridePetLevel; + int familySprite; + int baseGraNo; + ITEM itempool[MAX_ITEM]; + int big4fm; + int trade_confirm; // 1 -> ʼֵ + // 2 -> [ҷȷ + // 3 -> Էȷ + // 4 -> ˫԰ȷ + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + int profession_class; + int profession_level; +// int profession_exp; + int profession_skill_point; + char profession_class_name[32]; +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + int herofloor; +#endif + +#ifdef _GM_IDENTIFY // Rog ADD GMʶ + char gm_name[GM_NAME_LEN+1]; +#endif + +#ifdef _FRIENDCHANNEL // ROG ADD Ƶ + char chatRoomNum[4]; +#endif +#ifdef _STREET_VENDOR + int iOnStreetVendor; // ̯ģʽ +#endif + int skywalker; // GM?? +#ifdef _MOVE_SCREEN + BOOL bMoveScreenMode; // ƶӫĻģʽ + BOOL bCanUseMouse; // Ƿʹûƶ + int iDestX; // Ŀ X + int iDestY; // Ŀ Y +#endif +#ifdef _THEATER + int iTheaterMode; // 糡ģʽ + int iSceneryNumber; // ¼Ժͼ + ACTION *pActNPC[5]; // ¼糡ʱNPC +#endif +#ifdef _NPC_DANCE + int iDanceMode; // һģʽ +#endif +#ifdef _EVIL_KILL + int newfame; // ַħ + short ftype; +#endif + + int debugmode; +#ifdef _SFUMATO + int sfumato; // Ⱦͼɫ +#endif +#ifdef _NEW_ITEM_ + int ״̬; +#endif +#ifdef _CHARSIGNADY_NO_ + int ǩ; +#endif +#ifdef _MAGIC_ITEM_ + int ״̬; + int ߹⻷Ч; +#endif +} PC; + +#ifdef _FMVER21 +enum +{ + FMMEMBER_NONE = -1, // δκμ + FMMEMBER_MEMBER = 1, // һԱ + FMMEMBER_APPLY, // + FMMEMBER_LEADER, // 峤 + FMMEMBER_ELDER, // + //FMMEMBER_INVITE, // ˾ + //FMMEMBER_BAILEE, // + //FMMEMBER_VICELEADER, // 峤 + FMMEMBER_NUMBER, +}; +#endif + +enum +{ + MAGIC_FIELD_ALL, + MAGIC_FIELD_BATTLE, + MAGIC_FIELD_MAP +}; + +enum +{ + MAGIC_TARGET_MYSELF, + MAGIC_TARGET_OTHER, + MAGIC_TARGET_ALLMYSIDE, + MAGIC_TARGET_ALLOTHERSIDE, + MAGIC_TARGET_ALL, + MAGIC_TARGET_NONE, + MAGIC_TARGET_OTHERWITHOUTMYSELF, + MAGIC_TARGET_WITHOUTMYSELFANDPET, + MAGIC_TARGET_WHOLEOTHERSIDE, + #ifdef __ATTACK_MAGIC + MAGIC_TARGET_SINGLE, // Եзijһ + MAGIC_TARGET_ONE_ROW, // Եзijһ + MAGIC_TARGET_ALL_ROWS, // Եз + #endif +}; + +enum +{ + PETSKILL_FIELD_ALL, + PETSKILL_FIELD_BATTLE, + PETSKILL_FIELD_MAP +}; + +enum +{ + PETSKILL_TARGET_MYSELF, + PETSKILL_TARGET_OTHER, + PETSKILL_TARGET_ALLMYSIDE, + PETSKILL_TARGET_ALLOTHERSIDE, + PETSKILL_TARGET_ALL, + PETSKILL_TARGET_NONE, + PETSKILL_TARGET_OTHERWITHOUTMYSELF, + PETSKILL_TARGET_WITHOUTMYSELFANDPET +#ifdef _BATTLESKILL // (ɿ) Syu ADD սܽ + ,PETSKILL_TARGET_ONE_ROW + ,PETSKILL_TARGET_ONE_LINE + ,PETSKILL_TARGER_DEATH +#endif +#ifdef _SKILL_ADDBARRIER + ,PETSKILL_TARGET_ONE_ROW_ALL //ѡҷĵ +#endif +}; + +enum +{ + ITEM_FIELD_ALL, + ITEM_FIELD_BATTLE, + ITEM_FIELD_MAP, +}; + +enum +{ + ITEM_TARGET_MYSELF, + ITEM_TARGET_OTHER, + ITEM_TARGET_ALLMYSIDE, + ITEM_TARGET_ALLOTHERSIDE, + ITEM_TARGET_ALL, + ITEM_TARGET_NONE, + ITEM_TARGET_OTHERWITHOUTMYSELF, + ITEM_TARGET_WITHOUTMYSELFANDPET, +#ifdef _PET_ITEM + ITEM_TARGET_PET +#endif +}; + +typedef struct +{ + int index; //λ + int graNo; // ??k? + int hp, maxHp; // ?????? + int mp, maxMp; // ?????? + int exp, maxExp; // ??k???????????k + int level; // ??? + int atk, def; // ????????\?? + int quick; // զ? + int ai; // ?ߥT + int earth, water, fire, wind; // ??? + int maxSkill; // ????? + int trn; // ת +#ifdef _SHOW_FUSION + int fusion; // low word: 走, hi word: ֱ +#endif +#ifdef _ANGEL_SUMMON + unsigned status; +#else + unsigned short status; // ?????(??????) +#endif + char name[CHAR_NAME_LEN+1]; // ? + char freeName[PET_NAME_LEN+1]; // ???????q + short useFlag; // ?????????????? + short changeNameFlag; // q????????? +#ifdef _PET_ITEM + ITEM item[MAX_PET_ITEM]; // +#endif +#ifdef _PETCOM_ + int oldlevel,oldhp,oldatk,oldquick,olddef; +#endif +#ifdef _RIDEPET_ + int rideflg; +#endif +#ifdef _PETBLESS_ + int blessflg; + int blesshp; + int blessatk; + int blessquick; + int blessdef; +#endif +} PET; + + +typedef struct +{ + short useFlag; + int mp; + short field; + short target; + short deadTargetFlag; + char name[MAGIC_NAME_LEN+1]; + char memo[MAGIC_MEMO_LEN+1]; +} MAGIC; + + +typedef struct +{ + short useFlag; + int id; + int level; + int maxHp; + int hp; + int mp; + char name[CHAR_NAME_LEN+1]; + ACTION *ptAct; +} PARTY; + + +typedef struct +{ + short useFlag; + short onlineFlag; + int level; + short transmigration; + int dp; + int graNo; + char name[CHAR_NAME_LEN+1]; +#ifdef _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ + char planetname[64]; +#endif +} ADDRESS_BOOK; + + +typedef struct +{ + short petNo; + short levelUp; + int exp; +} BATTLE_RESULT_CHR; + +typedef struct +{ + short useFlag; + BATTLE_RESULT_CHR resChr[RESULT_CHR_EXP]; + char item[RESULT_ITEM_COUNT][RESULT_ITEM_NAME_LEN+1]; +} BATTLE_RESULT_MSG; + + +typedef struct +{ + short useFlag; + short skillId; + short field; + short target; + char name[SKILL_NAME_LEN+1]; + char memo[SKILL_MEMO_LEN+1]; +} PET_SKILL; + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +typedef struct +{ + short useFlag; + short skillId; + short target; + short kind; + char name[PROFESSION_MEMO_LEN+1]; + char memo[PROFESSION_MEMO_LEN+1]; + int icon; + int costmp; + int skill_level; +#ifdef _PRO3_ADDSKILL + int cooltime; +#endif +} PROFESSION_SKILL; +#endif + + +typedef struct +{ + char name[CHAR_NAME_LEN+1]; // SJIS?q???? + short level; // ??? + int login; // ?????? + + int faceGraNo; // ???k? + int hp; // ?? + int str; // ??? + int def; // \?? + int agi; // ? + int app; // u? + int attr[4]; // N???????? + int dp; // ???????? +} CHARLISTTABLE; +#ifdef _AIDENGLU_ +typedef struct +{ + int ; + int ģ; + int С; + int ; + int ǷԶ; + int ǷԶ; + int ﷽; + char ½[4][32]; + int ½ʱʱ; +}Landed; +#endif + +extern PC pc; +extern short maxPcNo; +extern short selectPcNo; +extern short prSendMode; +extern short prSendFlag; +extern short jbSendFlag; +extern short duelSendFlag; + +extern int loginDp; + +extern short helpFlag; + +extern short tradeFlag; +extern short tradeStatus; + +//extern short channel; + +extern MAGIC magic[]; + +extern PET pet[]; + +extern PARTY party[]; +extern short partyModeFlag; + +extern ADDRESS_BOOK addressBook[]; +extern BOOL addressBookFlag; + + +extern BATTLE_RESULT_MSG battleResultMsg; + +extern PET_SKILL petSkill[][MAX_SKILL]; + +extern CHARLISTTABLE chartable[]; + +extern char newCharacterName[]; +extern int newCharacterGraNo; +extern int newCharacterFaceGraNo; +extern int newCharacterVit; +extern int newCharacterStr; +extern int newCharacterTgh; +extern int newCharacterDex; +extern int newCharacterEarth; +extern int newCharacterWater; +extern int newCharacterFire; +extern int newCharacterWind; +extern int newCharacterHomeTown; + +void initPcAll( void ); +void initPc( void ); +void createPc( int, int, int, int ); +void resetPc( void ); +void setPcWarpPoint( int, int ); +void setPcPoint( void ); +void setPcGraNo( int, int ); +void setPcId( int ); +void setPcDir( int ); +void setPcAction( int ); +#ifdef __EMOTION + void setPcEmotion( int emotion ); +#endif +int getPcAction( void ); + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _PRO3_ADDSKILL + #define MAX_PROFESSION_SKILL 30 +#else + #define MAX_PROFESSION_SKILL 26 +#endif + extern PROFESSION_SKILL profession_skill[]; +// #ifdef _GM_IDENTIFY // Rog ADD GMʶ +// void setPcParam( char *, char *, int, char *, int, int, int, int, int, int, int, int, char *); +// void setPcParam( char *, char *, int, char *, int, int, int, int, int, int, int, char *); +// #else +// void setPcParam( char *, char *, int, char *, int, int, int, int, int, int, int, int ); +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + void setPcParam( char *, char *, int, char *, int, int, int, int, int, int, int , int ); +#else + void setPcParam( char *, char *, int, char *, int, int, int, int, int, int, int ); +#endif +// #endif +#else + void setPcParam( char *, char *, int, char *, int, int, int, int ); +#endif + +void updataPcAct( void ); +void setPcLeader( void ); +void delPcLeader( void ); +void setPcParty( void ); +void delPcParty( void ); +void setPcWatch( void ); +void delPcWatch( void ); +void changePcAct( int, int, int, int, int, int, int ); +void setPcWalkFlag( void ); +void delPcWalkFlag( void ); +int checkPcWalkFlag( void ); +void setPcUseMagic( void ); +void delPcUseMagic( void ); +void setPcFukidashi( unsigned int ); +void setPcNameColor( int ); + +void clearPartyParam( void ); +void clearPtActPartyParam( void ); + +int existCharacterListEntry( int ); +int cmpNameCharacterList( char * ); +int setCharacterList( char *, char * ); +int resetCharacterList( int ); + +void getItem( void ); +void swapItem( int, int ); + +BOOL lookAtAround( void ); + + +void initAddressBook( void ); +void addressBookProc( void ); + +int CHAR_getMaxHaveGold( void); + +#endif + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/pet_skillinfo.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/pet_skillinfo.h new file mode 100644 index 0000000..c75cbba --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/pet_skillinfo.h @@ -0,0 +1,42 @@ +/* generated by makedefs.perl */ + +#define PETSKILL_NONE ( 0 ) +#define PETSKILL_NORMALATTACK ( 1 ) +#define PETSKILL_NORMALGUARD ( 2 ) +#define PETSKILL_GUARDBREAK ( 3 ) +#define PETSKILL_CONTINUATIONATTACK1 ( 10 ) +#define PETSKILL_GUARDIAN ( 20 ) +#define PETSKILL_MIGHTY1 ( 40 ) +#define PETSKILL_POWERBALANCE1 ( 50 ) +#define PETSKILL_POWERBALANCE2 ( 51 ) +#define PETSKILL_POISON_ATTACK1 ( 60 ) +#define PETSKILL_POISON_ATTACK2 ( 61 ) +#define PETSKILL_STONE ( 80 ) +#define PETSKILL_CONFUSION_ATTACK ( 90 ) +#define PETSKILL_DRUNK_ATTACK ( 100 ) +#define PETSKILL_CHARGE1 ( 30 ) +#define PETSKILL_SLEEP_ATTACK ( 110 ) +#define PETSKILL_Abduct ( 130 ) +#define PETSKILL_STEAL ( 140 ) +#define PETSKILL_NOGUARD1 ( 150 ) +#define PETSKILL_MERGE ( 200 ) +#ifdef _ALCHEMIST +#define PETSKILL_ALCHEMIST ( 202 ) +#endif +#define PETSKILL_EARTHROUND1 ( 120 ) +#define PETSKILL_CONTINUATIONATTACK2 ( 11 ) +#define PETSKILL_CONTINUATIONATTACK3 ( 12 ) +#define PETSKILL_CONTINUATIONATTACK4 ( 13 ) +#define PETSKILL_CHARGE2 ( 31 ) +#define PETSKILL_MIGHTY2 ( 41 ) +#define PETSKILL_NOGUARD2 ( 151 ) +#define PETSKILL_NOGUARD3 ( 152 ) +#define PETSKILL_POWERBALANCE3 ( 52 ) +#define PETSKILL_MERGE2 ( 201 ) +#define PETSKILL_INSLAY (572) +#define PETSKILL_FIXITEM (540) +#define PETSKILL_FIXITEM2 (664) +#define PETSKILL_INTENSIFY (650) +#define PETSKILL_UPINSLAY (651) +#define PETSKILL_CALLBUS (668) +/* end of generated code */ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/petname.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/petname.h new file mode 100644 index 0000000..36feab4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/petname.h @@ -0,0 +1,757 @@ + + +// ??????????? + +//??{ ?????K?k??q??k? } + +{ 0, "" /*"???"*/, 28001 }, +{ 1, "" /*"????"*/, 28002 }, +{ 2, "˹̹" /*"??????"*/, 28003 }, +{ 3, "³" /*"????"*/, 28004 }, + +//(pet01) +{ 8, "" /*"????"*/, 28011 }, +{ 9, "" /*"???????"*/, 28012 }, +{ 10, "" /*"???"*/, 28013 }, +{ 11, "" /*"?????"*/, 28014 }, +{ 12, "" /*"????"*/, 28015 }, + +//(pet02) +{ 16, "" /*"????"*/, 28021 }, +{ 17, "ӱ" /*"????"*/, 28022 }, +{ 18, "ӱȰ" /*"????"*/, 28023 }, +{ 19, "˹" /*"????"*/, 28024 }, + +//(pet03) +{ 24, "ڱ" /*"???"*/, 28031 }, +{ 25, "" /*"????"*/, 28032 }, +{ 26, "ڿ³" /*"????"*/, 28033 }, +{ 27, "" /*"?????"*/, 28034 }, + +//(pet04) +{ 32, "" /*"????"*/, 28041 }, +{ 33, "" /*"?????"*/, 28042 }, +{ 34, "屦˶" /*"??????"*/, 28043 }, +{ 35, "屦" /*"????"*/, 28044 }, + +//(pet05) +{ 40, "֮" /*"?????"*/, 28051 }, +{ 41, "̹" /*"????"*/, 28052 }, +{ 42, "÷" /*"????"*/, 28053 }, +{ 43, "ʯ" /*"????"*/, 28054 }, + +//(pet06) +{ 48, "" /*"????"*/, 28062 }, +{ 49, "˹" /*"???"*/, 28061 }, +{ 50, "" /*"????"*/, 28063 }, +{ 51, "˶" /*"????"*/, 28064 }, + +//(pet07? +{ 56, "³" /*"????"*/, 28071 }, +{ 57, "ΰ" /*"???"*/, 28072 }, +{ 58, "" /*"?????"*/, 28073 }, +{ 59, "³˹" /*"????"*/, 28074 }, + + +//(pet08) +{ 64, "³˹" /*"?????"*/, 28081 }, +{ 65, "" /*"????"*/, 28082 }, +{ 66, "˹" /*"?????"*/, 28083 }, +{ 67, "氲" /*"????"*/, 28084 }, + + +//(pet09) +{ 72, "ŵ" /*"?????"*/, 28091 }, +{ 73, "˹" /*"?????"*/, 28092 }, +{ 74, "˹" /*"?????"*/, 28093 }, +{ 75, "ŵ" /*"?????"*/, 28094 }, + + +//(pet10) +{ 80, "׶" /*"???"*/, 28101 }, +{ 81, "˿˶" /*"???"*/, 28102 }, +{ 82, "" /*"????"*/, 28103 }, +{ 83, "˹" /*"????"*/, 28104 }, + +//(pet11) +{ 88, "" /*"????"*/, 28111 }, +{ 89, "" /*"????"*/, 28112 }, +{ 90, "" /*"????"*/, 28113 }, +{ 91, "" /*"?????"*/, 28114 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +//(pet14) +{ 96, "" /*"????"*/, 28141 }, +{ 97, "" /*"????"*/, 28142 }, +{ 98, "" /*"??????"*/, 28143 }, +{ 99, "" /*"????"*/, 28144 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +//(pet17) +{ 104, "ޱ" /*"????"*/, 28171 }, +{ 105, "˹" /*"????"*/, 28172 }, +{ 106, "˲" /*"?????"*/, 28173 }, +{ 107, "" /*"?????"*/, 28174 }, + +//(pet18) +{ 112, "˶" /*"????"*/, 28181 }, +{ 113, "Ϳ" /*"????"*/, 28182 }, +{ 114, "" /*"??"*/, 28183 }, +{ 115, "" /*"????"*/, 28184 }, + +//(pet19) +{ 120, "³" /*"????"*/, 28191 }, +{ 121, "³" /*"?????"*/, 28192 }, +{ 122, "³˹" /*"????"*/, 28193 }, +{ 123, "³" /*"???????"*/, 28194 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +//(pet21) +{ 128, "ŵ˹" /*"?????"*/, 28211 }, +{ 129, "˹" /*"????"*/, 28212 }, +{ 130, "" /*"?????"*/, 28213 }, +{ 131, "岼˹" /*"????"*/, 28214 }, + +//(pet22) +{ 136, "˰˹" /*"?????"*/, 28221 }, +{ 137, "ӿ" /*"????"*/, 28222 }, +{ 138, "Ӹ" /*"????"*/, 28223 }, +{ 139, "" /*"????"*/, 28224 }, + +//(pet23) +{ 144, "濨˹" /*"????"*/, 28231 }, +{ 145, "" /*"???"*/, 28232 }, +{ 146, "濨˹" /*"?????"*/, 28233 }, +{ 147, "" /*"?????"*/, 28234 }, + +//(pet24) +{ 152, "" /*"????"*/, 28241 }, +{ 153, "ķ" /*"????"*/, 28242 }, +{ 154, "" /*"?????"*/, 28243 }, +{ 155, "³" /*"?????"*/, 28244 }, + +//(pet25) +{ 160, "˹" /*"?????"*/, 28251 }, +{ 161, "˹" /*"?????"*/, 28252 }, +{ 162, "˹" /*"?????"*/, 28253 }, +{ 163, "˹˹" /*"?????"*/, 28254 }, + + +//(pet26) +{ 168, "Ħ" /*"????"*/, 28261 }, +{ 169, "ĦĦ" /*"???"*/, 28262 }, +{ 170, "Ħ˹" /*"????"*/, 28263 }, +{ 171, "Ħ˹" /*"?????"*/, 28264 }, + +//(pet27) +{ 176, "" /*"????"*/, 28271 }, +{ 177, "忨׶" /*"????"*/, 28272 }, +{ 178, "ӱ" /*"?????"*/, 28273 }, +{ 179, "˹" /*"????"*/, 28274 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +//(pet29) +{ 184, "" /*"????"*/, 28291 }, +{ 185, "˿˹" /*"????"*/, 28292 }, +{ 186, "" /*"????"*/, 28293 }, +{ 187, "汦" /*"?????"*/, 28294 }, + + +//(pet30) +{ 192, "¿˹" /*"????"*/, 28301 }, +{ 193, "˹" /*"?????"*/, 28302 }, +{ 194, "Ͷ" /*"????"*/, 28303 }, +{ 195, "" /*"?????"*/, 28304 }, + +//(pet31) +{ 200, "" /*"???"*/, 28311 }, +{ 201, "Ħ" /*"?????"*/, 28312 }, +{ 202, "" /*"?????"*/, 28313 }, +{ 203, "" /*"?????"*/, 28314 }, + +//(pet32) +{ 208, "ʷ" /*"??????"*/, 28321 }, +{ 209, "˹" /*"????"*/, 28322 }, +{ 210, "˹" /*"?????"*/, 28323 }, +{ 211, "ŵ˹" /*"?????"*/, 28324 }, +{ 212, "˹" /*"????"*/, 28325 }, + +//(pet33) +{ 216, "˹" /*"?????"*/, 28331 }, +{ 217, "³˹" /*"?????"*/, 28332 }, +{ 218, "˹" /*"?????"*/, 28333 }, +{ 219, "ŵ˹˹" /*"??????"*/, 28334 }, + +// ?D???? +{ 4, "" /*"????"*/, 28005 }, +{ 68, "˹" /*"????"*/, 28085 }, +{ 69, "" /*"????"*/, 28086 }, +{ 70, "³" /*"????"*/, 28087 }, +{ 71, "彫" /*"??????"*/, 28088 }, +{ 52, "ؿ˶" /*"????"*/, 28065 }, +{ 76, "³" /*"????"*/, 28095 }, +{ 108, "³" /*"????"*/, 28175 }, +{ 164, "˹" /*"?????"*/, 28255 }, + +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +{ -1, "" /*"??"*/, 0 }, // 100400 +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +{ -1, "" /*"??"*/, 0 }, // 100410 +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + +{ -1, "" /*"??"*/, 0 }, // 100420 +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, +{ -1, "" /*"??"*/, 0 }, + + +{ 204, "" /*"??????"*/, 28315 }, // 100430 + + +{ 5, "" /*"??????"*/, 28006 }, // 100820 +{ 6, "" /*"??????"*/, 28007 }, +{ 7, "" /*"??????"*/, 28008 }, + +{ 13, "³" /*"??????"*/, 28016 }, +{ 14, "" /*"??????"*/, 28017 }, +{ 15, "" /*"??????"*/, 28018 }, + +{ 20, "Ӽ" /*"??????"*/, 28025 }, +{ 21, "˹" /*"??????"*/, 28026 }, +{ 22, "Ӹ" /*"??????"*/, 28027 }, +{ 23, "ȱȼ" /*"??????"*/, 28028 }, + +{ 28, "ڱ" /*"??????"*/, 28035 }, +{ 29, "˹" /*"??????"*/, 28036 }, +{ 30, "" /*"??????"*/, 28037 }, +{ 31, "" /*"??????"*/, 28038 }, + +{ 36, "" /*"??????"*/, 28045 }, +{ 37, "" /*"??????"*/, 28046 }, +{ 38, "屴" /*"??????"*/, 28047 }, +{ 39, "岨" /*"??????"*/, 28048 }, + +{ 44, "" /*"??????"*/, 28055 }, +{ 45, "" /*"??????"*/, 28056 }, +{ 46, "֮" /*"??????"*/, 28057 }, +{ 47, "" /*"??????"*/, 28058 }, + + +{ 53, "˹" /*"??????"*/, 28066 }, +{ 54, "˹" /*"??????"*/, 28067 }, +{ 55, "˹" /*"??????"*/, 28068 }, + +{ 60, "" /*"??????"*/, 28075 }, +{ 61, "³³" /*"??????"*/, 28076 }, +{ 62, "³˹" /*"??????"*/, 28077 }, +{ 63, "˹˹" /*"??????"*/, 28078 }, + + +{ 77, "ŵ˹" /*"??????"*/, 28096 }, +{ 78, "˹" /*"??????"*/, 28097 }, +{ 79, "ϻ˹" /*"??????"*/, 28098 }, + +{ 84, "" /*"??????"*/, 28105 }, +{ 85, "˹" /*"??????"*/, 28106 }, +{ 86, "" /*"??????"*/, 28107 }, +{ 87, "˴" /*"??????"*/, 28108 }, + +{ 92, "" /*"??????"*/, 28115 }, +{ 93, "" /*"??????"*/, 28116 }, +{ 94, "" /*"??????"*/, 28117 }, +{ 95, "ɿ" /*"??????"*/, 28118 }, + +{ 100, "˾" /*"??????"*/, 28145 }, +{ 101, "ϣ" /*"??????"*/, 28146 }, +{ 102, "÷ " /*"??????"*/, 28147 }, +{ 103, "Ƕ" /*"??????"*/, 28148 }, + + +{ 109, "" /*"??????"*/, 28176 }, +{ 110, "±" /*"??????"*/, 28177 }, +{ 111, "ë" /*"??????"*/, 28178 }, + +{ 116, "ŷּ³" /*"??????"*/, 28185 }, +{ 117, "ʷ³" /*"??????"*/, 28186 }, +{ 118, "Ү³" /*"??????"*/, 28187 }, +{ 119, "" /*"??????"*/, 28188 }, + +{ 124, "³" /*"??????"*/, 28195 }, +{ 125, "¶" /*"??????"*/, 28196 }, +{ 126, "³" /*"??????"*/, 28197 }, +{ 127, "˹" /*"??????"*/, 28198 }, + +{ 132, "󶡲˹" /*"??????"*/, 28215 }, +{ 133, "Ү˹" /*"??????"*/, 28216 }, +{ 134, "ײ˹" /*"??????"*/, 28217 }, +{ 135, "岼˹" /*"??????"*/, 28218 }, + +{ 140, "ϼ" /*"??????"*/, 28225 }, +{ 141, "ɰ" /*"??????"*/, 28226 }, +{ 142, "" /*"??????"*/, 28227 }, +{ 143, "÷³ɯ" /*"??????"*/, 28228 }, + +{ 148, "" /*"??????"*/, 28235 }, +{ 149, "" /*"??????"*/, 28236 }, +{ 150, "" /*"??????"*/, 28237 }, +{ 151, "ﰺ" /*"??????"*/, 28238 }, + +{ 156, "ŷɪ" /*"??????"*/, 28245 }, +{ 157, "Ī˾" /*"??????"*/, 28246 }, +{ 158, "˹" /*"??????"*/, 28247 }, +{ 159, "ɳ" /*"??????"*/, 28248 }, + +{ 165, "֨" /*"??????"*/, 28256 }, +{ 166, "˹˹" /*"??????"*/, 28257 }, +{ 167, "ɸ˹" /*"??????"*/, 28258 }, + +{ 172, "Ħ" /*"??????"*/, 28265 }, +{ 173, "ĦĦ" /*"??????"*/, 28266 }, +{ 174, "Ħ" /*"??????"*/, 28267 }, +{ 175, "Ħ" /*"??????"*/, 28268 }, + + +{ 180, "ɿɶ" /*"??????"*/, 28275 }, +{ 181, "" /*"??????"*/, 28276 }, +{ 182, "" /*"??????"*/, 28277 }, +{ 183, "ϲ" /*"??????"*/, 28278 }, + +{ 188, "" /*"??????"*/, 28295 }, +{ 189, "Ħ" /*"??????"*/, 28296 }, +{ 190, "" /*"??????"*/, 28297 }, +{ 191, "˹" /*"??????"*/, 28298 }, + +{ 196, "" /*"??????"*/, 28305 }, +{ 197, "Ͽ" /*"??????"*/, 28306 }, +{ 198, "׶" /*"??????"*/, 28307 }, +{ 199, "˾" /*"??????"*/, 28308 }, + +{ 205, "" /*"??????"*/, 28316 }, +{ 206, "˹" /*"??????"*/, 28317 }, +{ 207, "" /*"??????"*/, 28318 }, + +{ 213, "ķ˹" /*"??????"*/, 28326 }, +{ 214, "˹" /*"??????"*/, 28327 }, +{ 215, "˹" /*"??????"*/, 28328 }, + +{ 220, "³˹" /*"??????"*/, 28335 }, +{ 221, "ŵ˹" /*"??????"*/, 28336 }, +{ 222, "Ϳ˾" /*"??????"*/, 28337 }, +{ 223, "׵˹" /*"??????"*/, 28338 }, + +{ 224, "׻ŷ", 28343 }, +{ 225, "", 28341 }, +{ 226, "׼³", 28342 }, +{ 227, "", 28344 }, + +{ 228, "", 28351 }, +{ 229, "", 28352 }, + +{ 230, "ʷն", 28355 }, +{ 231, "˹", 28354 }, +{ 232, "", 28358 }, +{ 233, "", 28356 }, +{ 234, "", 28357 }, +{ 235, "ޱ", 28359 }, +{ 236, "³", 28360 }, + +{ 237, "", 28362 }, +{ 238, "", 28361 }, +{ 239, "ϣ", 28363 }, + +{ 240, "׶Ϳ", 28364 }, +{ 241, "ǰͿ", 28365 }, +{ 242, "ŷͿ", 28367 }, +{ 243, "ְͿ", 28366 }, +{ 244, "Ա", 28368 }, +{ 245, "˹", 28369 }, + +{ 246, "³", 28372}, +{ 247, "³", 28373}, +{ 248, "Ħ", 28374}, +{ 249, "˹", 28370}, +{ 250, "", 28371}, +{ 251, "˹", 28375}, +{ 252, "", 28376}, +{ 253, "˹", 28377}, +{ 254, "", 28378}, +{ 255, "ʷο", 28379}, +{ 256, "˹", 28380}, +{ 257, "˹", 28381}, +{ 258, "", 28382}, +{ 259, "ϸ˹", 28383}, +{ 260, "ñ˹", 28384}, +{ 261, "˹", 28385}, +{ 262, "˹", 28386}, +{ 263, "", 28387}, +{ 264, "׸", 28388}, +{ 265, "˶", 28389}, +{ 266, "׶˹", 28390}, +{ 267, "", 28391}, +{ 268, "", 28392}, +{ 269, "", 28393}, +{ 270, "", 28394}, +{ 271, "˹", 28395}, +{ 272, "ն", 28396}, +{ 273, "˹", 28398}, +{ 274, "˹", 28397}, +{ 275, "ǹ˹", 28399}, +{ 276, "³˹", 28400}, +{ 277, "", 28401}, +{ 278, "", 28402}, +{ 279, "", 28403}, +{ 280, "", 28404}, +{ 281, "", 28405}, +{ 282, "", 28406}, +{ 283, "˹", 28411}, +{ 284, "ǵ", 28410}, +{ 285, "ΰ", 28408}, +{ 286, "˹", 28407}, +{ 287, "", 28409}, +{ 288, "ŷ", 28412}, +{ 289, "", 28413}, +{ 290, "ӹ", 28414}, +{ 291, "", 28415}, +{ 292, "ŷ", 28416}, +{ 293, "³", 28417}, +{ 294, "ٿ˶", 28418}, +{ 295, "˹", 28419}, +{ 296, "ﵰ", 28420}, + +{ 297, "᲼", 28421}, +{ 298, "ᱴ", 28422}, +{ 299, "", 28423}, +{ 300, "˹", 28424}, + +{ 301, "˹", 28425}, +{ 302, "", 28426}, +{ 303, "϶", 28427}, +{ 304, "ȿ", 28428}, + +{ 305, "׵˹", 28429}, + +{ 306, "ʷ³", 28459}, +{ 307, "ʷ", 28458}, +{ 308, "尲", 28462}, +{ 309, "˹", 28463}, +{ 310, "ױ", 28461}, +{ 311, "", 28460}, +{ 312, "ؿ", 28442}, +{ 313, "˹", 28443}, +{ 314, "ɳ߿", 28430}, +{ 315, "ɳп", 28431}, +{ 316, "׿", 28468}, +{ 317, "׼", 28469}, +{ 318, "", 28439}, +{ 319, "˹", 28438}, +{ 320, "˹", 28464}, +{ 321, "˹", 28465}, +{ 322, "", 28435}, +{ 323, "Ƕ˹", 28434}, +{ 324, "", 28450}, +{ 325, "", 28451}, +{ 326, "", 28470}, +{ 327, "˹", 28471}, +{ 328, "ɳ", 28457}, +{ 329, "", 28456}, +{ 330, "ʷ", 28466}, +{ 331, "˹̹", 28467}, +{ 332, "", 28454}, +{ 333, "", 28455}, +{ 334, "", 28441}, +{ 335, "˹", 28440}, +{ 336, "", 28437}, +{ 337, "", 28436}, +{ 338, "յ", 28444}, +{ 339, "˹", 28445}, +{ 340, "", 28452}, +{ 341, "˶", 28453}, +{ 342, "", 28446}, +{ 343, "˹", 28447}, +{ 344, "", 28432}, +{ 345, "˹", 28433}, +{ 346, "˹Ħ", 28472}, +{ 347, "ŷĦ", 28473}, +{ 348, "Ħ", 28474}, +{ 349, "Ħ", 28475}, +{ 350, "޶", 28476}, +{ 351, "ؿ", 28449}, +{ 352, "", 28477}, + +{ 353, "ʷƤŵ", 28478}, +{ 354, "ʷƤ", 28479}, +{ 355, "ʷƤ", 28480}, +{ 356, "ʷƤ", 28481}, + +{ 357, "", 28482}, +{ 358, "޶", 28487}, +{ 359, "", 28488}, +{ 360, "׶", 28483}, +{ 361, "޶", 28484}, +{ 362, "Ͽ˹", 28485}, +{ 363, "Ͽ˹", 28486}, + +{ 364, "", 28489}, +{ 365, "¶", 28490}, +{ 366, "", 28491}, +{ 367, "", 28492}, +{ 368, "ʷ˽", 28493}, +{ 369, "ʷ", 28494}, +{ 370, "·", 28495}, +{ 371, "·", 28496}, +{ 372, "ִ", 28497}, +{ 373, "ŷִ", 28498}, +{ 374, "˹", 28499}, +{ 375, "˹", 28500}, +{ 376, "", 28501}, +{ 377, "Ͽ", 28502}, +{ 378, "ִ", 28503}, +{ 379, "ִ", 28504}, +{ 380, "˹", 28505}, +{ 381, "ʷο", 28506}, +{ 382, "", 28507}, +{ 383, "", 28508}, +{ 384, "ŷ", 28509}, +{ 385, "ŷ", 28510}, +{ 386, "³ŷ", 28511}, +{ 387, "ŷ", 28512}, +{ 388, "¶", 28513}, +{ 389, "˹", 28514}, +{ 390, "µϱ", 28515}, +{ 391, "ɫ1", 28516}, +{ 392, "ɫ2", 28517}, +{ 393, "", 28518}, +{ 394, "¶", 28519}, +{ 395, "1", 28521}, +{ 396, "2", 28522}, +{ 397, "˹", 28520}, +{ 398, "", 28523}, +{ 399, "", 28524}, +{ 400, "׵", 28525}, +{ 401, "Ƶ", 28526}, +{ 402, "˹", 28527}, +{ 403, "", 28528}, +{ 404, "", 28529}, +{ 405, "˹", 28530}, +{ 406, "ֶ", 28531}, +{ 407, "׶", 28532}, +{ 408, "˹", 28533}, +{ 409, "ŵ˹", 28534}, +{ 410, "ŵ", 28535}, +{ 411, "˹", 28536}, +{ 412, "ŵ", 28537}, +{ 413, "³", 28538}, +{ 414, "", 28539}, +{ 415, "ֿ˱", 28540}, +{ 416, "˹ķ", 28541}, +{ 417, "", 28542}, +{ 418, "", 28543}, +{ 419, "", 28544}, +{ 420, "", 28545}, +{ 421, "", 28546}, +{ 422, "˹", 28547}, +{ 423, "ַ", 28548}, +{ 424, "", 28549}, +{ 425, "ƶ", 28556}, +{ 426, "", 28557}, +{ 427, "ο", 28558}, +{ 428, "", 28559}, +{ 429, "ܽ", 28583}, +{ 430, "", 28582}, +{ 431, "Ħ˼", 28584}, +{ 432, "", 28585}, +{ 433, "", 28586}, +{ 434, "ŷ", 28587}, +{ 435, "", 28588}, +{ 436, "ֿܶ", 28611}, +{ 437, "", 28612}, +{ 438, "", 28613}, +{ 439, "ֶ", 28614}, +// 8.0 +{ 440, "˹", 28589}, +{ 441, "³", 28590}, +{ 442, "꼪", 28591}, +{ 443, "", 28592}, +{ 444, "", 28593}, +{ 445, "", 28594}, +{ 446, "", 28595}, +{ 447, "˷", 28596}, +{ 448, "", 28597}, +{ 449, "", 28598}, +{ 450, "", 28599}, +{ 451, "ɪ", 28600}, +{ 452, "", 28601}, +{ 453, "ŷŷ", 28602}, +{ 454, "", 28603}, +{ 455, "ķ", 28604}, +{ 456, "˹", 28605}, +{ 457, "˹˹", 28606}, +{ 458, "˹", 28607}, +{ 459, "˹", 28608}, +{ 460, "èŮ3", 28610}, +{ 461, "走", 28609}, +{ 462, "նǒO", 28616}, +{ 463, "ՒOO", 28617}, +{ 464, "ՒO", 28618}, +{ 465, "ՒO", 28619}, +{ 466, "˹׿", 28615}, +{ 467, "ŵ", 28620}, +{ 468, "ŵ", 28621}, +{ 469, "ŵ", 28622}, +{ 470, "ŵ", 28623}, +{ 471, "¹ŵ±", 28624}, +{ 472, "˹ŵ", 28625}, +{ 473, "ŵ", 28626}, +{ 474, "չŵ", 28627}, +{ 475, "˾", 28628}, +{ 476, "ն", 28629}, +{ 477, "ձ", 28630}, +{ 478, "", 28631}, +{ 479, "޸", 28632}, +{ 480, "޿", 28633}, +{ 481, "̹", 28634}, +{ 482, "", 28635}, +{ 483, "˾", 28637},//1740 +{ 484, "Ī│", 28638},//1741 +{ 485, "޿", 28639}, +{ 486, "꿨", 28640}, +{ 487, "", 28641}, +{ 488, "", 28642}, +{ 489, "", 28643}, +{ 490, "˹", 28644}, +{ 491, "˴", 28645}, +{ 492, "Ŀ", 28646}, +{ 493, "Ļ", 28647}, +{ 494, "Ƥ", 28648}, +{ 495, "Ƥ", 28649}, +{ 496, "ʷѸ", 28650},//ţ1 1753 +{ 497, "ʷڶ", 28651},//ţ2 +{ 498, "", 28652},//ż +{ 499, "ά", 28653}, +{ 500, "ά", 28654}, +{ 501, "", 28655}, +{ 502, "ϣ", 28656}, +{ 503, "", 28657}, +{ 504, "", 28658}, +{ 505, "³", 28659}, +{ 506, "˹", 28660}, +{ 507, "ϸ", 28661}, +{ 508, "յ¶", 28662}, //Ȯһֻ +{ 509, "", 28663}, +{ 510, "ɭ", 28663}, //èͷӥ1 +{ 511, "", 28664}, //èͷӥ2 +{ 512, "", 28665}, //1 +{ 513, "", 28666}, //2 +{ 514, "", 28667}, //1 +{ 515, "", 28668}, //2 +{ 516, "", 28669}, //ػ +{ 517, "˹", 28670}, //1 8.5 +{ 518, "ɵ˹", 28671}, //2 8.5 +{ 519, "DZ", 28672}, //3 8.5 +{ 520, "", 28673}, //4 8.5 +{ 521, "" , 28674}, // +{ 522, "" , 28675}, // +{ 523, "" , 28676}, // +{ 524, "" , 28677}, // +{ 525, "׶" , 28678}, // +{ 526, "" , 28679}, // +{ 527, "" , 28680}, // +{ 528, "" , 28681}, // +{ 529, "" , 28682}, // +{ 530, "" , 28683}, // +{ 531, "" , 28684}, // +{ 532, "" , 28685}, // +{ 533, "" , 28686}, // +{ 534, "" , 28687}, // +{ 535, "" , 28688}, // +{ 536, "˹", 28689}, //Сħ1 +{ 537, "", 28690}, //Сħ2 +{ 538, "ﲼ", 28691}, //Сħ3 +{ 539, "沨", 28692}, //Сħ4 +{ 540, "Ħ˹", 28693}, //1 +{ 541, "Ħ˹", 28694}, //2 +{ 542, "", 28695}, // +{ 543, "", 28696}, //ʼ1 +{ 544, "", 28697}, //ʼ2 +{ 545, "ڶߵ", 28698}, //1 +{ 546, "׸ߵ", 28699}, //2 +{ 547, "ͼߵ", 28700}, //3 +{ 548, "ߵ", 28701}, //4 +{ 549, "Ŷ", 28702}, // +{ 550, "Ŷ", 28703}, // +{ 551, "Ŷ", 28704}, // +{ 552, "Ŷ", 28705}, // +{ 553, "", 28706}, //Ա +{ 554, "ɭ", 28707}, //Ա +{ 555, "Ī", 28708}, // +{ 556, "IJ", 28709}, // +// Robin add +{ 557, "ֵ", 28710}, // +{ 558, "Ī", 28711}, // +{ 559, "Ī", 28712}, // + +{ 560, "׶", 28713}, // +{ 561, "׶", 28714}, // +{ 562, "ֶ", 28715}, // +{ 563, "", 28716}, // + +{ 564, "", 28717}, // ѩ +{ 565, "", 28718}, // ѩ + +//{ 564, "", 28718}, // +//{ 565, "", 28717}, // + +{ 566, "ſ", 28719}, // +{ 567, "ŵ", 28720}, +{ 568, "", 28721}, +{ 569, "ȶ", 28722}, + +// ಾλʱҲҪ menu.h MAX_PET_KIND Ŀ + + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/process.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/process.h new file mode 100644 index 0000000..8a714aa --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/process.h @@ -0,0 +1,88 @@ +/************************/ +/* process.h */ +/************************/ +#ifndef _PROCESS_H_ +#define _PROCESS_H_ + +/* ?????? */ +enum{ + PROC_INIT, + PROC_ID_PASSWORD, // ????????V??? + PROC_TITLE_MENU, // ????????? + PROC_CHAR_SELECT, // ???k + PROC_CHAR_MAKE, // ???? + PROC_CHAR_LOGIN_START, // ???????? + PROC_CHAR_LOGIN, // ???????? + PROC_CHAR_LOGOUT, // ???????? + PROC_OPENNING, + PROC_GAME, // ??????? + PROC_BATTLE, // ??????? + PROC_DISCONNECT_SERVER, // ???????e??????? + + PROC_TAKE_TEST, // {??? + PROC_OHTA_TEST, // ^??? + PROC_DWAF_TEST, // Z??? + PROC_SPR_VIEW, // ??????_???? + PROC_ANIM_VIEW, // ????????_???? + PROC_SE_TEST, // ???_???? + +#ifdef _80_LOGIN_PLAY + PROC_80_LOGIN, +#endif +#ifdef _PK2007 + PROC_PKSERVER_SELECT, +#endif + PROC_ENDING +}; + +/* ????k? */ +extern UINT ProcNo; +/* ??????k? */ +extern UINT SubProcNo; +/* ????k? */ +extern int ProcNo2; +/* ??????k? */ +extern int SubProcNo2; + +extern int palNo; +extern int oldPalNo; +extern int palTime; //the third + + +/* ?????? */ +void Process( void ); +/* ??????? */ +void ChangeProc( int procNo ); +/* ??????? */ +void ChangeProc( int procNo, int subProcNo ); +/* ??????? */ +void ChangeProc2( int procNo ); +/* ??????? */ +void ChangeProc2( int procNo, int subProcNo ); + +/* ????????? */ +void GameProc( void ); + +// ????? +void warpEffectProc( void ); +// ????? +void repairMap( void ); + +void paletteProc( void ); + +#ifdef _STONDEBUG_ + +/* {????????? */ +void TakeTestProc( void ); + +/* ^??????? */ +void OhtaTestProc( void ); + +#endif + +#ifdef _SURFACE_ANIM +void AniProc(void); +#endif + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/produce.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/produce.h new file mode 100644 index 0000000..715b01c --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/produce.h @@ -0,0 +1,70 @@ +/************************/ +/* produce.h */ +/************************/ +#ifndef _PRODUCE_H_ +#define _PRODUCE_H_ + +// ???????????? +enum{ + PRODUCE_UP_ACCELE, // ?L?h + PRODUCE_UP_BRAKE, // ?L?h + + PRODUCE_DOWN_ACCELE, // ??L?h + PRODUCE_DOWN_BRAKE, // ??L?h + + PRODUCE_LEFT_ACCELE, // ??L?h + PRODUCE_LEFT_BRAKE, // ??L?h + + PRODUCE_RIGHT_ACCELE, // ??L?h + PRODUCE_RIGHT_BRAKE, // ??L?h + + PRODUCE_LEFT_RIGHT_ACCELE, // ???L?h + PRODUCE_LEFT_RIGHT_BRAKE, // ???L?h + + PRODUCE_UP_DOWM_ACCELE, // ??L?h + PRODUCE_UP_DOWM_BRAKE, // ??L?h + + PRODUCE_4WAY_OUT, // ??h??? + PRODUCE_4WAY_IN, // ??h?? + + PRODUCE_HAGARE_OUT, // ????????? + PRODUCE_HAGARE_IN, // ?????????? + + PRODUCE_HAGARE_OCHI_OUT, // ????????? + PRODUCE_HAGARE_OCHI_IN, // ?????????? + + PRODUCE_BRAN_SMALL, // ??? + PRODUCE_BRAN_BIG, // ???? + + PRODUCE_BREAK_UP1, //??????? + PRODUCE_BREAK_UP2, //?????? + + PRODUCE_BREAK_UP3, //??????? + PRODUCE_BREAK_UP4, //??????? + + PRODUCE_BREAK_UP5, //???????? + PRODUCE_BREAK_UP6, //??????? + + PRODUCE_BREAK_UP7, //???????? + PRODUCE_BREAK_UP8, //?????? + + PRODUCE_CENTER_PRESSIN, // ???????? + PRODUCE_CENTER_PRESSOUT, // ????????? + + PRODUCE_END, // ? + +}; + +// ??????? +extern int ProduceInitFlag; + +// ???????????? **************************************************/ +void CopyBackBuffer( void ); + +// ?Ҥ? ********************************************************************/ +BOOL DrawProduce( int no ); + +// ????? ********************************************************************/ +void TitleProduce( void ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/radar.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/radar.h new file mode 100644 index 0000000..afff865 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/radar.h @@ -0,0 +1,25 @@ +/************************/ +/* radar.h */ +/************************/ +#ifndef _RADAR_ +#define _RADAR_ + +void radar(ACTION *,int *,int *); + +/******************************************************************** +* +* ???? +* +* IN pAct ?????????? +* x ??? +* y ??? +* cnt ??????? +* +* OUT d1 ?? ( 0 ? ??? ) +* +* ???( 0 ? 31 )? a0->crs ?V? +* +********************************************************************/ +int radar2(ACTION *pAct,int x,int y, int cnt ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/savedata.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/savedata.h new file mode 100644 index 0000000..e2e2863 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/savedata.h @@ -0,0 +1,31 @@ +#ifndef _SAVEDATA_H_ +#define _SAVEDATA_H_ + +BOOL saveUserSetting( void ); +BOOL loadUserSetting( void ); +void setUserSetting( int ); +void getUserSetting( int ); +void clearUserSetting( int ); +void setUserSoundOption( void ); +void getUserSoundOption( void ); +void setUserChatOption( void ); +void getUserChatOption( void ); +void setUserInterfaceOption( void ); +void getUserInterfaceOption( void ); + +BOOL saveNowState( void ); +BOOL loadNowState( void ); + +extern unsigned char savedataErrorCode; +// shan 2001/01/14 +extern int sPetStatFlag; +extern int fMapBgm; +extern int sCharSide; + + +// ???????? +#define SAVE_ERRMSG_loadNowState "ȡ浵ʧܡ(code = %d)" + + + +#endif // _SAVEDATA_H_ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/shop.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/shop.h new file mode 100644 index 0000000..52f5a7e --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/shop.h @@ -0,0 +1,19 @@ +/************************/ +/* battleMap.h */ +/************************/ +#ifndef _BATTLE_MAP_H_ +#define _BATTLE_MAP_H_ + +// ???????????? +#define BATTLE_MAP_FILES 220 + +// ?????????k? +extern int BattleMapNo; + +// ?????????????????????? ***************************/ +BOOL ReadBattleMap( int no ); + +// ??????? ***********************************************************/ +void DrawBattleMap( void ); +void ʾ(short x,short y,UCHAR ,char* ,unsigned int ,char* ); +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/sndcnf.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/sndcnf.h new file mode 100644 index 0000000..101ffba --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/sndcnf.h @@ -0,0 +1,238 @@ +// k?????????????????S?O?????????????????????????????? + +SNDCONFIG sndconfig[] = +{ + // ????? + { 1, "data\\se\\sap_01.wav", 85, 0, 0 /*, "a?????"*/ }, + { 2, "data\\se\\sap_02.wav", 85, 0, 0 /*, "a?????S?"*/ }, + { 3, "data\\se\\sap_03.wav", 85, 0, 0 /*, "a??????"*/ }, + { 4, "data\\se\\sap_04.wav", 100, 0, 0 /*, "a????"*/ }, + { 5, "data\\se\\sap_05.wav", 85, 0, 0 /*, "a????"*/ }, + { 6, "data\\se\\sap_06.wav", 60, 0, 0 /*, "a?"*/ }, + { 7, "data\\se\\sap_07.wav", 123, 0, 0 /*, "a??????"*/ }, + { 8, "data\\se\\sap_08.wav", 80, 0, 0 /*, "?????"*/ }, + { 9, "data\\se\\sap_09.wav", 80, 0, 0 /*, "a??????"*/ }, + { 10, "data\\se\\sap_10.wav", 80, 0, 0 /*, "a???????"*/ }, +//x { 11, "data\\se\\sap_11.wav", 105, 7, 0 /*, "??"*/ }, + { 11, "data\\se\\sap_11.wav", 105, 0, 0 /*, "??"*/ }, + { 12, "data\\se\\sap_14.wav", 100, 0, 0 /*, "??"*/ }, + { 13, "data\\se\\sap_12.wav", 90, 0, 0 /*, "?????"*/ }, + { 14, "data\\se\\sap_13.wav", 105, 0, 0 /*, "??????"*/ }, + + // ????? + { 51, "data\\se\\sae_01.wav", 123, 0, 0 /*, ""*/ }, + { 52, "data\\se\\sae_02.wav", 123, 0, 0 /*, ""*/ }, + { 53, "data\\se\\sae_03.wav", 123, 0, 0 /*, ""*/ }, + { 54, "data\\se\\sae_04.wav", 123, 0, 0 /*, ""*/ }, + { 55, "data\\se\\sae_05.wav", 123, 0, 0 /*, ""*/ }, + { 56, "data\\se\\sae_06.wav", 105, 0, 0 /*, "?????"*/ }, + { 57, "data\\se\\sae_07.wav", 80, 0, 0 /*, "???????"*/ }, + { 58, "data\\se\\sae_08.wav", 123, 0, 0 /*, ""*/ }, + { 59, "data\\se\\sae_09.wav", 123, 0, 0 /*, ""*/ }, + { 60, "data\\se\\sae_10.wav", 80, 0, 0 /*, "????"*/ }, + { 61, "data\\se\\sae_11.wav", 123, 0, 0 /*, ""*/ }, + { 62, "data\\se\\sae_12.wav", 95, 0, 0 /*, "????"*/ }, + { 63, "data\\se\\sae_13.wav", 80, 0, 0 /*, "?????"*/ }, + { 64, "data\\se\\sae_14.wav", 90, 0, 0 /*, "???"*/ }, + { 65, "data\\se\\sae_15.wav", 95, 0, 0 /*, "?????"*/ }, + { 66, "data\\se\\sae_16.wav", 95, 0, 0 /*, "???"*/ }, + { 67, "data\\se\\sae_17.wav", 123, 0, 0 /*, ""*/ }, + { 68, "data\\se\\sae_18.wav", 123, 0, 0 /*, ""*/ }, + { 69, "data\\se\\sae_19.wav", 123, 0, 0 /*, ""*/ }, + { 70, "data\\se\\sae_20.wav", 123, 0, 0 /*, ""*/ }, + { 71, "data\\se\\sae_21.wav", 123, 0, 0 /*, ""*/ }, + { 72, "data\\se\\sae_22.wav", 123, 0, 0 /*, ""*/ }, + { 73, "data\\se\\sae_23.wav", 90, 0, 0 /*, "????"*/ }, + { 74, "data\\se\\sae_24.wav", 90, 0, 0 /*, "????"*/ }, + { 75, "data\\se\\sae_25.wav", 100, 0, 0 /*, "???"*/ }, + { 76, "data\\se\\sae_26.wav", 75, 0, 0 /*, "???"*/ }, + { 77, "data\\se\\sae_27.wav", 123, 0, 0 /*, ""*/ }, + { 78, "data\\se\\sae_28.wav", 90, 0, 0 /*, "????"*/ }, + { 79, "data\\se\\sae_29.wav", 123, 0, 0 /*, ""*/ }, + { 80, "data\\se\\sae_30.wav", 100, 0, 0 /*, "?????"*/ }, + { 81, "data\\se\\sae_31.wav", 123, 0, 0 /*, ""*/ }, + { 82, "data\\se\\sae_32.wav", 123, 0, 0 /*, ""*/ }, + + // ? + { 100, "data\\se\\sam_01.wav", 75, 0, 0 /*, "??????"*/ }, + { 101, "data\\se\\sam_02.wav", 75, 0, 0 /*, "????"*/ }, + { 102, "data\\se\\sam_03.wav", 75, 0, 0 /*, "??"*/ }, + { 103, "data\\se\\sam_04.wav", 123, 0, 0 /*, "????"*/ }, + { 104, "data\\se\\sam_05.wav", 123, 0, 0 /*, "?????"*/ }, + { 105, "data\\se\\sam_06.wav", 123, 0, 0 /*, "????"*/ }, + { 106, "data\\se\\sam_07.wav", 123, 0, 0 /*, "????"*/ }, + { 107, "data\\se\\sam_08.wav", 123, 0, 0 /*, "?????"*/ }, + { 108, "data\\se\\sam_09.wav", 123, 0, 0 /*, "????"*/ }, + { 109, "data\\se\\sam_10.wav", 123, 0, 0 /*, "????"*/ }, + { 110, "data\\se\\sam_11.wav", 123, 0, 0 /*, "?????"*/ }, + { 111, "data\\se\\sam_12.wav", 123, 0, 0 /*, "????"*/ }, + { 112, "data\\se\\sam_13.wav", 123, 0, 0 /*, "????"*/ }, + { 113, "data\\se\\sam_14.wav", 123, 0, 0 /*, "?????"*/ }, + { 114, "data\\se\\sam_15.wav", 85, 0, 0 /*, "?????????"*/ }, + { 115, "data\\se\\sam_16.wav", 123, 0, 0 /*, "???"*/ }, + { 116, "data\\se\\sam_17.wav", 123, 0, 0 /*, "?_"*/ }, + { 117, "data\\se\\sam_18.wav", 123, 0, 0 /*, "????"*/ }, + { 118, "data\\se\\sam_19.wav", 123, 0, 0 /*, "??"*/ }, + { 119, "data\\se\\sam_20.wav", 123, 0, 0 /*, "?"*/ }, + { 120, "data\\se\\sam_21.wav", 123, 0, 0 /*, "?"*/ }, + { 121, "data\\se\\sam_22.wav", 123, 0, 0 /*, ""*/ }, + { 122, "data\\se\\sam_23.wav", 123, 0, 0 /*, "?d"*/ }, + { 123, "data\\se\\sam_24.wav", 123, 0, 0 /*, "?"*/ }, + + // ?? +// { 151, "data\\se\\sak_01.wav", 121, 0, 1 /*, "????"*/ }, +// { 152, "data\\se\\sak_02.wav", 121, 0, 1 /*, "???]?"*/ }, + { 151, "data\\se\\sak_01.wav", 127, 0, 1 /*, "?????"*/ }, +//x { 152, "data\\se\\sak_02.wav", 127, 4, 1 /*, "?????"*/ }, + { 152, "data\\se\\sak_02.wav", 127, 0, 1 /*, "?????"*/ }, + { 153, "data\\se\\sak_03.wav", 121, 0, 1 /*, "?"*/ }, + { 154, "data\\se\\sak_04.wav", 90, 0, 1 /*, "?"*/ }, + { 155, "data\\se\\sak_05.wav", 95, 0, 1 /*, "?D"*/ }, + { 156, "data\\se\\sak_06.wav", 127, 0, 1 /*, "?"*/ }, + { 157, "data\\se\\sak_07.wav", 125, 0, 1 /*, "O?????"*/ }, + { 158, "data\\se\\sak_08.wav", 125, 0, 1 /*, "??????"*/ }, + { 159, "data\\se\\sak_09a.wav", 120, 0, 1 /*, "??"*/ }, + { 160, "data\\se\\sak_10.wav", 115, 0, 1 /*, "??????"*/ }, + { 161, "data\\se\\sak_11.wav", 85, 0, 1 /*, "?"*/ }, + { 162, "data\\se\\sak_12.wav", 120, 0, 1 /*, "?"*/ }, + { 163, "data\\se\\sak_13.wav", 100, 0, 1 /*, "???????"*/ }, + { 164, "data\\se\\sak_14.wav", 127, 0, 1 /*, "??"*/ }, + { 165, "data\\se\\sak_15.wav", 120, 0, 1 /*, "??"*/ }, + { 166, "data\\se\\sak_16.wav", 120, 0, 1 /*, "????????"*/ }, + { 167, "data\\se\\sak_17.wav", 110, 0, 1 /*, "??"*/ }, + { 168, "data\\se\\sak_09b.wav", 120, 0, 1 /*, "????"*/ }, + + // ???? + { 201, "data\\se\\sas_01.wav", 90, 0, 0 /*, "???"*/ }, + { 202, "data\\se\\sas_02.wav", 80, 0, 0 /*, "????????"*/ }, + { 203, "data\\se\\sas_03.wav", 75, 0, 0 /*, "????????"*/ }, + { 204, "data\\se\\sas_04.wav", 80, 0, 0 /*, "?????????"*/ }, + { 205, "data\\se\\sas_05.wav", 80, 0, 0 /*, "?????????"*/ }, + { 206, "data\\se\\sas_06.wav", 80, 0, 0 /*, "???????"*/ }, + { 207, "data\\se\\sas_07.wav", 123, 0, 0 /*, ""*/ }, + { 208, "data\\se\\sas_08.wav", 123, 0, 0 /*, ""*/ }, + { 209, "data\\se\\sas_09.wav", 123, 0, 0 /*, ""*/ }, + { 210, "data\\se\\sas_10.wav", 123, 0, 0 /*, ""*/ }, + { 211, "data\\se\\sas_11.wav", 65, 0, 0 /*, ??????""*/ }, + { 212, "data\\se\\sas_12.wav", 80, 0, 0 /*, "?????"*/ }, + { 213, "data\\se\\sas_13.wav", 123, 0, 0 /*, "????"*/ }, +// { 214, "data\\se\\sas_14.wav", 127, 0, 0 /*, "??"*/ }, + { 215, "data\\se\\sas_15.wav", 82, 0, 0 /*, "??????"*/ }, + { 216, "data\\se\\sas_16.wav", 110, 0, 0 /*, "?????"*/ }, + { 217, "data\\se\\sas_17.wav", 85, 0, 0 /*, "????????"*/ }, + { 218, "data\\se\\sas_18.wav", 123, 0, 0 /*, ""*/ }, + { 219, "data\\se\\sas_19.wav", 82, 0, 0 /*, "?"*/ }, + { 220, "data\\se\\sas_20.wav", 60, 0, 0 /*, "???Y?"*/ }, + { 221, "data\\se\\sas_21.wav", 123, 0, 0 /*, ""*/ }, + + // ???? + { 250, "data\\se\\sad_01.wav", 85, 0, 0 /*, "???????"*/ }, + { 251, "data\\se\\sad_02.wav", 80, 0, 0 /*, "?????????S?"*/ }, +//x { 252, "data\\se\\sad_03.wav", 95, -3, 0 /*, "????????"*/ }, + { 252, "data\\se\\sad_03.wav", 95, 0, 0 /*, "????????"*/ }, + { 253, "data\\se\\sad_04.wav", 85, 0, 0 /*, "????????"*/ }, + { 254, "data\\se\\sad_05.wav", 90, 0, 0 /*, "??????Y?"*/ }, + +#ifdef __ATTACK_MAGIC + { 300,"data\\se\\saam_01.wav",120, 0, 0 /*, "ǰħ ħ"*/ }, + { 301,"data\\se\\saam_02.wav",120, 0, 0 /*, "ħ ͼ"*/ }, + { 302,"data\\se\\saam_03.wav",120, 0, 0 /*, "ħ ħLv1"*/ }, + { 303,"data\\se\\saam_04.wav",120, 0, 0 /*, "ħ ħLv2"*/ }, + { 304,"data\\se\\saam_05.wav",120, 0, 0 /*, "ħ ħLv3-1"*/ }, + { 305,"data\\se\\saam_06.wav",120, 0, 0 /*, "ħ ħLv3-2*/ }, + { 306,"data\\se\\saam_07.wav",120, 0, 0 /*, "ħ ħLv3-3*/ }, + { 307,"data\\se\\saam_08.wav",120, 0, 0 /*, "ħ ħLv4*/ }, + { 308,"data\\se\\saam_09.wav",120, 0, 0 /*, "ˮħ ħLv1"*/ }, + { 309,"data\\se\\saam_10.wav",120, 0, 0 /*, "ˮħ ħLv2"*/ }, + { 310,"data\\se\\saam_11.wav",120, 0, 0 /*, "ˮħ ħLv3-1"*/ }, + { 311,"data\\se\\saam_12.wav",120, 0, 0 /*, "ˮħ ħLv3-2"*/ }, + { 312,"data\\se\\saam_13.wav",120, 0, 0 /*, "ˮħ ħLv3-3"*/ }, + { 313,"data\\se\\saam_14.wav",120, 0, 0 /*, "ˮħ ħLv4"*/ }, + { 314,"data\\se\\saam_15.wav",120, 0, 0 /*, "ħ ħLv1"*/ }, + { 315,"data\\se\\saam_16.wav",120, 0, 0 /*, "ħ ħLv2"*/ }, + { 316,"data\\se\\saam_17.wav",120, 0, 0 /*, "ħ ħLv3-1"*/ }, + { 317,"data\\se\\saam_18.wav",120, 0, 0 /*, "ħ ħLv3-2"*/ }, + { 318,"data\\se\\saam_19.wav",120, 0, 0 /*, "ħ ħLv3-3"*/ }, + { 319,"data\\se\\saam_20.wav",120, 0, 0 /*, "ħ ħLv4"*/ }, + { 320,"data\\se\\saam_21.wav",120, 0, 0 /*, "ħ ħLv1"*/ }, + { 321,"data\\se\\saam_22.wav",120, 0, 0 /*, "ħ ħLv2"*/ }, + { 322,"data\\se\\saam_23.wav",120, 0, 0 /*, "ħ ħLv3-1"*/ }, + { 323,"data\\se\\saam_24.wav",120, 0, 0 /*, "ħ ħLv3-2"*/ }, + { 324,"data\\se\\saam_25.wav",120, 0, 0 /*, "ħ ħLv3-3"*/ }, + { 325,"data\\se\\saam_26.wav",120, 0, 0 /*, "ħ ħLv4"*/ }, + { 326,"data\\se\\saam_27.wav",120, 0, 0 /*, "ħħ ħLv5"*/ }, +#endif +#ifdef _NEWSOUNDEFFECT + { 327,"data\\se\\sa1_01.wav",120, 0 ,0 } , //ĩ + { 328,"data\\se\\sa1_02.wav",120, 0 ,0 } , //ǹ + { 371,"data\\se\\sa2_01.wav",120, 0 ,0 } , //ر + { 372,"data\\se\\sa2_02.wav",120, 0 ,0 } , // + { 373,"data\\se\\sa2_03.wav",120, 0 ,0 } , //ۼ + { 374,"data\\se\\sa2_04.wav",120, 0 ,0 } , //רעս + { 375,"data\\se\\sa2_05.wav",120, 0 ,0 } , // + { 376,"data\\se\\sa2_06.wav",120, 0, 0 } , //ʿܹʮֹ + { 377,"data\\se\\sa2_07.wav",120, 0, 0 } , //ᴩ1 + { 378,"data\\se\\sa2_08.wav",120, 0, 0 } , //ᴩ2 + { 379,"data\\se\\sa2_09.wav",120, 0, 0 } , //1 + { 380,"data\\se\\sa2_10.wav",120, 0, 0 } , //2 + { 381,"data\\se\\sa3_01.wav",120, 0, 0 } , //׷Ѱ + { 382,"data\\se\\sa3_02.wav",120, 0, 0 } , // + { 383,"data\\se\\sa3_03.wav",120, 0, 0 } , // + { 384,"data\\se\\sa3_04.wav",120, 0, 0 } , // + { 385,"data\\se\\sa3_05.wav",120, 0, 0 } , //׵翹 + { 386,"data\\se\\sa3_06.wav",120, 0, 0 } , //濹Է + { 387,"data\\se\\sa3_07.wav",120, 0, 0 } , //濹 + { 388,"data\\se\\sa1_03.wav",120, 0, 0 } , // + { 389,"data\\se\\sa1_04.wav",120, 0, 0 } , // + { 390,"data\\se\\sa1_05.wav",120, 0, 0 } , // + { 391,"data\\se\\sa1_06.wav",120, 0, 0 } , // + { 392,"data\\se\\sa1_07.wav",120, 0, 0 } , // + { 393,"data\\se\\sa1_08.wav",120, 0, 0 } , // + { 394,"data\\se\\sa1_09.wav",120, 0, 0 } , //С + { 395,"data\\se\\sa1_10.wav",120, 0, 0 } , //ɽȪ + { 396,"data\\se\\sa1_11.wav",120, 0, 0 } , //ɽȪ + { 397,"data\\se\\sa1_12.wav",120, 0, 0 } , //ɽȪС + { 398,"data\\se\\sa3_08.wav",120, 0, 0 } , //ʹ + { 399,"data\\se\\sa3_09.wav",120, 0, 0 } , //㹥 + { 271,"data\\se\\sa1_13.wav",120, 0, 0 } , //һѪ + + { 261,"data\\se\\sa1_14.wav",120, 0, 0 } , //׸ + { 262,"data\\se\\sa1_15.wav",120, 0, 0 } , // + { 263,"data\\se\\sa1_16.wav",120, 0, 0 } , //Ѫ + { 264,"data\\se\\sa1_17.wav",120, 0, 0 } , // + { 265,"data\\se\\sa1_18.wav",120, 0, 0 } , //Ѫ10 + { 266,"data\\se\\sa1_19.wav",120, 0, 0 } , //Ѫ7 + { 267,"data\\se\\sa1_20.wav",120, 0, 0 } , //Ѫ4 + { 268,"data\\se\\sa1_21.wav",120, 0, 0 } , //Ѫ1 + { 269,"data\\se\\sa1_22.wav",120, 0, 0 } , // + { 270,"data\\se\\sa1_23.wav",120, 0, 0 } , //λλ + { 272,"data\\se\\sa2_12.wav",120, 0, 0 } , // + + + +#endif +#ifdef _PROFESSION_ADDSKILL + { 400,"data\\se\\sae_10.wav",120, 0, 0 } , //Ȼsak_92.wav +#endif +// BGM +// { 401, "data\\bgm\\ls2b_01.wav", 5 /*, "????????"*/ }, +// { 402, "data\\bgm\\ls2b_02.wav", 5 /*, "??????"*/ }, +// { 403, "data\\bgm\\ls2b_03.wav", 5 /*, "???"*/ }, +// { 404, "data\\bgm\\ls2b_04.wav", 5 /*, "????"*/ }, + +#ifdef _FIREWORK_SOUND + { 405,"data\\se\\sax_01.wav",120, 0, 0 } , //̻Ч + { 406,"data\\se\\sax_02.wav",120, 0, 0 } , //̻Ч + { 407,"data\\se\\sax_03.wav",120, 0, 0 } , //Ը̻Ч +#endif + { 408,"data\\se\\sak_91.wav",120, 0, 0 } , //Ч¼ + { 409,"data\\se\\sak_93.wav",120, 0, 0 } , //һǾЧ¼ + { 130,"data\\se\\sap_14.wav",100, 0, 0 } , //רЧ + { 410,"data\\se\\sak_94.wav",120, 0, 0 } , //ӥЧ +#ifdef _NPC_DANCE + { 222,"data\\se\\sas_33.wav",120, 0, 0 } , //һЧ1 + { 223,"data\\se\\sas_34.wav",120, 0, 0 } , //һЧ2 + { 224,"data\\se\\sas_35.wav",120, 0, 0 } , //һЧ3 +#endif + { -1 } // Z?????????? +}; diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/sprdisp.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/sprdisp.h new file mode 100644 index 0000000..9ce17ce --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/sprdisp.h @@ -0,0 +1,100 @@ +/************************/ +/* sprdisp.h */ +/************************/ +#ifndef _SPRDISP_H_ +#define _SPRDISP_H_ + +#include "version.h" +#define DISP_BUFFER_SIZE 4096 // ??????? +enum{ + DISP_PRIO_BG = 0, // + DISP_PRIO_TILE = 1, //ر// ???????????????? + DISP_PRIO_CHAR = 10, //// ??? + DISP_PRIO_PARTS = 10, //// ??????? + DISP_PRIO_RESERVE = 20, //Ԥ + DISP_PRIO_JIKI = 30, /* ? */ + DISP_PRIO_GRID = 100, // ???????? + DISP_PRIO_BOX, /* ???? */ + DISP_PRIO_IME1, /* ???????????? ?? */ + DISP_PRIO_IME2, /* ???????????? ? */ + /* ??????? */ + DISP_PRIO_MENU, //ѡ/* ???? */ + DISP_PRIO_IME3, /* ????????????? ?? */ + DISP_PRIO_IME4, /* ????????????? ? */ + DISP_PRIO_BOX2, /* ????? */ + DISP_PRIO_ITEM, /* ???? */ + /* ???????? */ + DISP_PRIO_YES_NO_WND, /* ?_????? */ + DISP_PRIO_YES_NO_BTN, /* ?_??? */ + DISP_PRIO_BOX3, /* ????? */ + DISP_PRIO_DRAG, /* ????? */ + DISP_PRIO_MOUSE, /* ??????? */ + DISP_PRIO_TOP = 255 /* ??I */ +}; + +typedef struct { + int x, y; //ͼʱ// ? + int bmpNo; //ͼ + ACTION *pAct; // + BOOL hitFlag; // ʮλΪ 1:Ҫʾalpha 2:ʹ 3:ʯ 4:ж + char DrawEffect; // 0:ر 1:alpha 2:ʹ 3:ʯ 4:ж +#ifdef _READ16BITBMP + char DrawEffect; // 0:ر 1:alpha 2:ʹ 3:ʯ 4:ж +#endif +#ifdef _SFUMATO + int sfumato; // Ⱦͼɫ +#endif +}DISP_INFO; + +typedef struct { + short no; //ͼDISP_INFOλ// ?????t??k? + UCHAR dispPrio; //ʾʱ˳// ??I?? +}DISP_SORT; + +typedef struct{ + DISP_INFO DispInfo[ DISP_BUFFER_SIZE ]; + DISP_SORT DispSort[ DISP_BUFFER_SIZE ]; + short DispCnt; //Ŀǰ// +}DISP_BUFFER; +extern DISP_BUFFER DispBuffer; + +extern char *pRealBinBits; +extern int RealBinWidth, RealBinHeight; +#ifdef _READ16BITBMP +extern BYTE *pRealBinAlpha; +#endif + +void DrawAlpha32( + unsigned long* lpDst, // Ŀ껺 + unsigned long iDstX, // Ŀλ + unsigned long iDstY, // Ŀλ + unsigned long iDstPitch, // Ŀ껺pitch + unsigned long* lpSrc, // ԭɫʻ + unsigned long iSrcX, // ԭɫλ + unsigned long iSrcY, // ԭɫλ + unsigned long iSrcW, // ԭijߴ + unsigned long iSrcH, // ԭijߴ + unsigned long iSrcPitch // ԭɫpitch + ); + +void ablend_565(unsigned char *lpAlpha, unsigned int iAlpPitch, + unsigned char *lpSrc, unsigned int iSrcX, unsigned int iSrcY, + unsigned int iSrcPitch, unsigned char *lpDst, + unsigned int iDstX, unsigned int iDstY, + unsigned int iDstW, unsigned int iDstH, + unsigned int iDstPitch); +extern int SurfaceBusyFlag; +void SortDispBuffer( void ); +BOOL ȡߴ(ACTION* a0,short* wx,short* wy); +void PutBmp( void ); +int StockDispBuffer( int x, int y, UCHAR prio, int bmpNo, BOOL hitFlag ); +#ifdef _SFUMATO +int StockDispBuffer2( int x, int y, UCHAR dispPrio, int bmpNo, BOOL hitFlag, int sfumato/* = 0*/); +#else +int StockDispBuffer2( int x, int y, UCHAR dispPrio, int bmpNo, BOOL hitFlag ); +#endif +void StockTaskDispBuffer( void ); +void StockTaskDispBuffer2( int prio1, int prio2 ); +void StockBoxDispBuffer( int x1, int y1, int x2, int y2, UCHAR dispPrio, int color, BOOL fill ); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/sprmgr.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/sprmgr.h new file mode 100644 index 0000000..b2f9b36 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/sprmgr.h @@ -0,0 +1,99 @@ +/************************/ +/* sprmgr.h */ +/************************/ +#ifndef _SPRMGR_H_ +#define _SPRMGR_H_ +#include +#ifndef _READ16BITBMP + //غ _READ16BITBMPVARIABLES IJ + #define OLD_GRAPHICS_START 1000000 // ԭrealbinͼ + #define MAX_GRAPHICS OLD_GRAPHICS_START // ͼ// ????? +#else + #define MAX_GRAPHICS_24 50000 // ߲ͼͼ + #define OLD_GRAPHICS_START 1000000 // ԭrealbinͼ + #define MAX_GRAPHICS OLD_GRAPHICS_START + MAX_GRAPHICS_24 // ͼ// ????? + #define MAX_GRAPHICS_ALPHA 50000 // ߲ͼalphaͨͼ +#endif + +#ifdef _READ16BITBMPVARIABLES // _READ16BITBMP ҪIJ + #define MAX_GRAPHICS_24 50000 // ߲ͼͼ + #define OLD_GRAPHICS_START 500000 // ԭrealbinͼ + #define MAX_GRAPHICS OLD_GRAPHICS_START + MAX_GRAPHICS_24 // ͼ// ?? +#endif + +#define DEF_COLORKEY 0 //Ԥ͸ɫ// a???k? + +#define SURFACE_WIDTH 64 //ͼõsource face// +#define SURFACE_HEIGHT 48 //ͼõsource face// + +extern LPDIRECTDRAWSURFACE lpBattleSurface; +#ifdef _READ16BITBMP +extern LPDIRECTDRAWSURFACE lpBattleSurfaceSys; +#endif +extern int SurfaceDispCnt; +extern int SurfaceSizeX; +extern int SurfaceSizeY; +extern UINT SurfaceDate; +struct surfaceInfo{ + LPDIRECTDRAWSURFACE lpSurface; +#ifdef _CACHE_SURFACE_ + char *lpCacheData; // + int palNo; //ǰɫ + int sizeX; //ƿ + int sizeY; //Ƹ߶ + BOOL colordepth; //ʹõɫ +#endif +#ifdef _READ16BITBMP + BYTE *lpAlphaData; + BOOL useAlpha; +#endif +#ifdef _NEW_COLOR_ + BOOL useAlpha; + BYTE *lpAlphaData; //16λֱ±͸ +#endif + int bmpNo; //ͼı,-1 source faceΪյ// ??????k? + UINT date; //¼source faceʹõ + short offsetX; + short offsetY; + surfaceInfo *pNext; +}; + +typedef struct surfaceInfo SURFACE_INFO; +typedef struct{ + SURFACE_INFO *lpSurfaceInfo; +#ifdef _READ16BITBMP + SURFACE_INFO *lpSurfaceInfoSys; +#endif + short width,height; + int AlphaFlg; +}SPRITE_INFO; + +extern SPRITE_INFO SpriteInfo[]; +extern SURFACE_INFO SurfaceInfo[]; +#ifdef _READ16BITBMP +extern SURFACE_INFO SurfaceInfoSys[]; +#endif +extern int SurfaceCnt; +extern int VramSurfaceCnt; +extern int SysramSurfaceCnt; +extern int SurfaceSearchPoint; +#ifdef _READ16BITBMP + #ifdef _STONDEBUG_ + extern unsigned int iTotalUseTime; + extern unsigned int iTotalProcTime; + extern unsigned int iTotalRunCount; + extern LARGE_INTEGER tf; + #endif +#endif + +#ifdef _STONDEBUG_ +extern int SurfaceUseCnt; +#endif + +BOOL InitOffScreenSurface( void ); +void InitSurfaceInfo( void ); +void InitSpriteInfo( void ); +BOOL LoadBmp( int bmpNo ); + + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/system.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/system.h new file mode 100644 index 0000000..6381a5d --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/system.h @@ -0,0 +1,41 @@ +/************************/ +/* system.h */ +/************************/ +#ifndef _SYSTEM_H_ +#define _SYSTEM_H_ + +/**** SYSTEM INCLUDE ****/ +#include +#include +#include +#include + +/**** DirectDraw Include ****/ +#include + +/**** USER INCLUDE ****/ +#include "directDraw.h" +#include "main.h" +#include "gamemain.h" +#include "sprmgr.h" +#include "init.h" +#include "process.h" +#include "action.h" +#include "sprdisp.h" +#include "math2.h" +#include "../oft/work.h" +#include "chat.h" +#include "font.h" +#include "mouse.h" +#include "radar.h" +#include "gemini.h" +#include "pattern.h" + +#ifdef _STONDEBUG_ +extern unsigned int iTotalUseTime; +extern unsigned int iTotalProcTime; +extern unsigned int iTotalRunCount; +extern LARGE_INTEGER tf; +#endif + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/t_music.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/t_music.h new file mode 100644 index 0000000..b8122c4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/t_music.h @@ -0,0 +1,60 @@ +/************************/ +/* t_music.h */ +/************************/ +#ifndef _T_MUSIC_ +#define _T_MUSIC_ + +#define T_MUSIC_MONO 0 +#define T_MUSIC_STEREO 1 + +#define TONE_MAX 500//400//256 + +typedef struct{ + int voice_place; //??????????????? + int voice_cnt; //????? + int voice_loop; //?????? + int voice_volume; //?????? + int voice_note; //???k? + int play_time; //??? + int voice_rate; + int voice_address; +} TONE_EQU; + +typedef struct +{ + char *fname; + int volume; + char loop_flg; + int loop_point; +} T_MUSIC_BGM; + +extern T_MUSIC_BGM bgm_tbl[]; + +extern TONE_EQU tone_tbl[]; + +int t_music_init(void); +void t_music_end(void); +extern int cdda_no; +extern int stereo_flg; +extern int t_music_se_volume; +extern int t_music_bgm_volume; +extern int t_music_bgm_no; +extern int t_music_se_no; +extern char t_music_bgm_pitch[16]; +extern int draw_map_bgm_flg; +extern int map_bgm_no; +//־ +extern BOOL MuteFlag; + +bool cdda_play(int); +bool cdda_stop(void); +int play_se(int tone, int x, int y); +int play_bgm(int bgm_no); +void bgm_volume_change(void); +void set_gbm_pitch(void); +void stop_bgm(void); +void fade_out_bgm(void); +int play_environment(int tone, int x, int y); +int play_map_bgm(int tone); + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/talkwindow.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/talkwindow.h new file mode 100644 index 0000000..3e7840a --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/talkwindow.h @@ -0,0 +1,112 @@ +#ifndef _TALKWINDOW_H_ +#define _TALKWINDOW_H_ +#include +#include "../systeminc/chat.h" + +#define WM_UPDATE_SKIN 0x8000 +#define MAX_TALK_WINDOW_LINE 6 +#define TALK_WINDOW_SXO 12 // ԻӴֵʼx +#define TALK_WINDOW_SYO 10 // ԻӴֵʼy +#define TALK_WINDOW_SXI 30 // ԻӴֵʼx +#define TALK_WINDOW_SYI 128 // ԻӴֵʼy +#define SKIN_WIDTH 645 +#define SKIN_HEIGHT 155 +#define SKIN_KIND 5 +#define TALK_WINDOW_MAX_CHAT_LINE 40 // buffer +#ifdef _STONDEBUG_ +#define FACE_SYMBOL_NUM 20 // +#define STORE_SYMBOL_NUM 200 // ¼λ +#define LINE_HEIGHT 20 // ʱо +#define SYMBOL_WIDTH 19 // ͼ +#define SYMBOL_HEIGHT 19 // ͼ +#endif + +extern BOOL g_bTalkWindow; +extern int g_iCursorCount; + +#ifdef _STONDEBUG_ +typedef struct _tsFaceSymbol{ // + HDC hDraw; + HDC hDrawMask; + HBITMAP hbmpMaskBMP; + HANDLE hLoadBMP; + HANDLE hOldLoadBMP; + HANDLE hOldMaskBMP; + BOOL bUse; + char szSymbol[8]; // ( :) :( :D ...etc) + char szFaceName[32]; // +}FaceSymbol; + +typedef struct _tsStoreSymbol{ // ¼ʾ + BOOL bUse; + HDC hDraw; + HDC hDrawMask; + int x; + int y; +}StoreSymbol; +#endif + +typedef struct _tsChatBufferLink{ + CHAT_BUFFER ChatBuffer; + _tsChatBufferLink *prev; + _tsChatBufferLink *next; + BOOL bUse; +}ChatBufferLink; + +LRESULT CALLBACK TalkWindowProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam); + +class CTalkWindow +{ +private: + HWND m_hWnd; // Ӵ HWND + HWND m_hTalkWindow; // Լ HWND + HINSTANCE m_hInstance; // Ӵ HINSTANCE + HANDLE m_hSkin[SKIN_KIND]; // SKIN_KIND->0:base 1:up arrow 2:up arrow hit 3:down arrow 4:down arrow hit + HANDLE m_hOldSkin[SKIN_KIND]; + HDC m_hdcSkin[SKIN_KIND]; // SKIN_KIND->0:base 1:up arrow 2:up arrow hit 3:down arrow 4:down arrow hit + HDC m_hdcBackBuffer; // backbuffer dc for draw + HBITMAP m_hbmpBackBuffer; // backbuffer of memory for draw + HANDLE m_hbmpOldBackBuffer; + BOOL m_bUpArrowHit; // ϾťǷ + BOOL m_bDownArrowHit; // ¾ťǷ + BOOL m_bScroll; // Ƿھ + BOOL m_bInit; // ʼɹʧ + ChatBufferLink *m_pCBLHead; // ָԻlinkһlinkָ + ChatBufferLink *m_pCBLTail; // ָԻlinkһlinkָ + ChatBufferLink *m_pCBLString; // ָԻlink׼ִlinkָ + ChatBufferLink *m_pCBLView; // ָҪʾڻϵһеִlinkָ + ChatBufferLink *m_pCBLViewBottom; // ָҪʾڻһеִlinkָ +#ifdef _STONDEBUG_ + FaceSymbol m_fsFaceSymbol[FACE_SYMBOL_NUM]; // + StoreSymbol m_ssStoreSymbol[STORE_SYMBOL_NUM]; // ¼DZʾ + int m_iSymbolCount; +#endif + int m_iline; +public: + CTalkWindow(void); + ~CTalkWindow(void); + + void Create(); + void Update(void); + void LoadSkin(char *szSkinPath); + void DrawSkin(BOOL bShowCursor); + void AddString(char *szString,int color); + HWND GetTalkWindowWND(void) { return m_hTalkWindow;}; + void UpArrowHit(BOOL bHit); + void DownArrowHit(BOOL bHit); + void ClearChatBuffer(void); + void Init(HWND hWnd,HINSTANCE hInstance); + void Visible(BOOL flag); + void Release(void); +#ifdef _STONDEBUG_ + void ReadFaceSymbolFile(void); + void InitFaceSymbol(COLORREF MaskColor); + void ReleaseFaceSymbol(void); + void SetToFaceSymbolString(char *szDestString,ChatBufferLink *pCBL,int x,int y); + void ShowFaceSymbol(void); +#endif +}; + +extern CTalkWindow TalkWindow; + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/testview.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/testview.h new file mode 100644 index 0000000..2f722b3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/testview.h @@ -0,0 +1,21 @@ +/************************/ +/* testView.h */ +/************************/ +#ifndef _TEST_VIEW_H_ +#define _TEST_VIEW_H_ + +#ifdef _STONDEBUG_ + +// ??????_???? +void SprViewProc( void ); + +// ????????_???? +void AnimViewProc( void ); + +// ???_???? +void SeTestProc( void ); + +#endif + +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/tool.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/tool.h new file mode 100644 index 0000000..d22da71 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/tool.h @@ -0,0 +1,48 @@ +#ifndef _TOOL_H_ +#define _TOOL_H_ + +#include + +#if 0 +//?????????????? +void freadline( char *ptbuf , FILE *ptFile ); +#endif + +//?????????t?????????? +int wordchk( char **pp ); +//????i????????????h?? +int strstr2( char **pp , char *q ); +//?????????????????????h +int getword(char **pp , char *q); +//?????????????k????? +int strint2( char **pp ); +//????????????????long??k????? +long strlong2( char **pp ); + +int getStringToken( char *src , char delim , int count , int maxlen , char *out ); +int getIntegerToken( char *src , char delim , int count ); +double getDoubleToken( char *src , char delim , int count ); +void chop( char *src ); +void shiftIntArray( int *a , int siz , int count ); + +int a62toi( char * ); +int getInteger62Token( char *, char, int ); + + +void jEncode( char *, int, int, char *, int *, int ); +void jDecode( char *, int, int, char *, int * ); + +int strncmpi( char *s1 , char *s2 , int len ); +struct tagRECT intToRect( int left, int top, int right, int bottom ); +void insertString( char *buffer, char *string, int whereToInsert ); +void insertChar( char *buffer, char character, int whereToInsert ); +int isOnlySpaceChars( char *data ); + +char makeCharFromEscaped( char ); + +char* makeStringFromEscaped( char* src ); +char* makeEscapeString( char* src , char* dest, int sizeofdest); + +bool GetMacAddress(char *strMac); + +#endif /*_TOOL_H_*/ diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/unpack.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/unpack.h new file mode 100644 index 0000000..b9a0974 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/unpack.h @@ -0,0 +1,17 @@ +#ifndef _UNPACK_H_ +#define _UNPACK_H_ + +typedef struct +{ + unsigned char id[2]; + unsigned char compressFlag; + unsigned int width; + unsigned int height; + unsigned int size; +} RD_HEADER; + +unsigned char *encoder( unsigned char *, unsigned char **, + unsigned int, unsigned int, unsigned int *, int ); +unsigned char *decoder( unsigned char *, unsigned char **, + unsigned int *, unsigned int *, unsigned int * ); +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/systeminc/version.h b/石器时代8.5客户端最新源代码/石器源码/systeminc/version.h new file mode 100644 index 0000000..5fec8a6 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/systeminc/version.h @@ -0,0 +1,686 @@ +#ifndef __VERSION_H__ +#define __VERSION_H__ + +#ifdef _WIN32 +#include +#endif + + +#ifdef _SA_VERSION_SPECIAL +#define _SA_VERSION_60 +#define __ALBUM_47 +#define _FONT_SIZE // Robin (Ҫ) ɸʹС +#define _ITEM_PILENUMS // (ɿ) ANDY زĶѵ +#define _ITEM_INTENSIFY // (ɿ) Change 輼:ǿ +#define _ALCHEMIST // Robin +#define _CHAR_NEWLOGOUT // (ɿ) ANDY µdz +//#define _ITEM_JIGSAW // (ɿ) Change ƴͼ +#define _TELLCHANNEL // (ɿ) ROG ADD Ƶ +#define _TRADETALKWND // (ɿ) Syu ADD Ի +#define _DROPPETWND // (ɿ) Syu ADD ȷ +#define _TEAM_KICKPARTY // (ɿ) ANDY ӳ +#define _MONEYINPUT // (ɿ) Syu ADD ֶǮ + +#define _STREET_VENDOR // ̯ +#define _STREET_VENDOR_CHANGE_ICON // ޸İ̯ͼʾ +#define _NEW_MANOR_LAW // ׯ԰ +#define _PETS_SELECTCON // (ɿ) ANDY ѡ +#define _FM_MODIFY // 幦޸ +#define _CHANNEL_MODIFY // Ƶ +#define _TRADELOCKBTN // (ɿ) Syu ADD +#define _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ +#define _LOCKPARTYFLOOR // (ɿ) Syu ADD Ӳӵĵͼ +#define _LOCKHELP_OK // (ɿ) Syu ADD ɼս +#define _JOBDAILY // cyg ־ +// #define _TALK_WINDOW // ԻӴ +#define _SHOW_FUSION // (ɿ) Change ںϳCLIENTֻʾת,޸ΪںϳʾΪں +#define _ITEM_FIREWORK // ̻ +#define _FIREWORK_SOUND // cyg Ч(̻) +//#define _GET_HOSTNAME // (ɿ) Change ȡõ +#define _NPC_MAGICCARD // cyg ħϷ +#define _THEATER // Terry 糡 +#define _MOVE_SCREEN // Terry ƶӫĻָ +#define _NPC_DANCE // cyg һnpc +#define _CHANNEL_WORLD // Ƶ +#define _STANDBYPET // Robin ʹбServer +#define _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ +#define _EXTEND_AB // cyg Ƭ +#define _ITEM_EQUITSPACE // (ɿ) ANDY װλ +#define _EQUIT_ARRANGE // (ɿ) ANDY +#define _EQUIT_NEWGLOVE // (ɿ) ANDY λ +//#define _ALCHEMIST // Robin +//#define _ALCHEPLUS // Robin +//#define _NPC_ITEMUP // (ɿ) Change õNPC +//#define _ITEM_COUNTDOWN // cyg ߵ +//#define _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +//#define _FRIENDCHANNEL // (ɿ) ROG ADD Ƶ +//#define __ONLINEGM +#endif +//#define _BATTLE_PK_PLAYER_FOR_40 // 40ս +//#define _BATTLE_PK_PLAYER_FOR_6VS6 // 6 vs 6 XIEZI + +#ifdef _BATTLE_PK_PLAYER_FOR_40 +#define BATTLESIDENUM 4 //ս +#define BATTLKPKPLYAERNUM 40 //սɫ +#define MAX_BATTLE_ROW_CHARS 5 //ÿսɫ +#else +#define BATTLESIDENUM 2 //ս +#ifdef _BATTLE_PK_PLAYER_FOR_6VS6 +#define BATTLKPKPLYAERNUM 24 //սɫ +#define MAX_BATTLE_ROW_CHARS 6 //ÿսɫ +#else +#define BATTLKPKPLYAERNUM 20 //սɫ +#define MAX_BATTLE_ROW_CHARS 5 //ÿսɫ +#endif +#endif + +#define _NEW_SYSTEM_MENU // ϵͳ˵ 2011/12/21 +#define _PTTERN_SEPARATION_BIN // 벹 +//#define _SFUMATO // Ⱦ δƣԴ +#define _SPECIAL_LOGO // µ½ͼ +#define _CHANNEL_ALL_SERV // Ƶ 2011/12/21 +#define _EXTEND_FONT_PAL // չɫɫ 2011/12/22 +//#define _FONT_PARAGRAPH_COLOR // ɫ 2011/12/22 +#define _NEW_CLIENT_LOGIN // ½¼MACַ·ѡ 2011/12/22 +//#define _NEW_SHOP_FRAME // ̵ 2011/12/22 + +#define _HI_COLOR_16 // (ɿ) ANDY (8bit to 16bit) ͼ +#define _HI_COLOR_32 // (ɿ) longzoro (32 bit) ͼ +#define _NEW_RESOMODE //800 600ģʽ +#define _MOUSE_SHOW_INFO_FOR_HEAD // (ɿ) longzoro ʾϢ +//#define _NEWLOGO // (ɿ) Syu ADD 6.0뻭logo Ҫ_v4_0 +/* ------------------------------------------------------------------- +* ¹ܣʯ 800 * 600 +* Ա, +* ˵ +*/ + +extern int DISPLACEMENT_X; +extern int DISPLACEMENT_Y; +extern int viewOffsetX; +extern int viewOffsetY; + +//#define _NEWDRAWBATTLEMAP_FIX // (ɿ)ROG ADD սͼ޸ + +// 汾ָ +#ifdef _SA_VERSION_85 +#define _SA_VERSION_80 +#endif + +#ifdef _SA_VERSION_80 +#define _SA_VERSION_75 +#endif + +#ifdef _SA_VERSION_75 +#define _SA_VERSION_70 +#endif + +#ifdef _SA_VERSION_70 +#define _SA_VERSION_60 +#endif + +#ifdef _SA_VERSION_60 +#define _SA_VERSION_50 +#endif + +#ifdef _SA_VERSION_50 +#define _SA_VERSION_40 +#endif + + + +/* 뽫ר definition +* Ȼ remark/unmark ع +*/ + + + +/* ------------------------------------------------------------------- +* רְ幦ܲ +* ԱС褡ѫ־ΰС +* ˵ +*/ +#define _FMVER21 // (ɿ) ְƹ +#define _PERSONAL_FAME // (ɿ) Arminius 8.30 + + +// ------------------------------------------------------------------- +// ר½NPC̸ +// Ա +// ˵__EDEN_EFFECT:ijNPC'ίн׵NPC +// __EDEN_AUCTION:ίNPCƷ +#define __EDEN_EFFECT // (ɿ) ʱҪ +#define __EDEN_AUCTION // (ɿ) ʱҪ + +// ------------------------------------------------------------------- +// ר +// Ա־ +// ˵ +#define __ATTACK_MAGIC + +// ------------------------------------------------------------------- +// ר޵ı +// Ա +// ˵ +#define _ITEM_FIRECREAKER + +/* ------------------------------------------------------------------- +* ¹ܣPKϵ +* Աѫ +* ˵ +*/ +//#define _PKSERVER // (ɿ) + + +// ------------------------------------------------------------------- +// רֻѶҽʵ +// Ա (LeiBoy) +// ˵ҿԴѶضASPҳ +// Ҫص : PhoneMsg.cpp +// : 20020128 +// : 20020304 +// Status : Ready! +//#define __PHONEMESSAGE +#define _FIX_URLENCODE // WON ADD ( ) Ѷ޷ӿո + + +// ------------------------------------------------------------------- +// רֻѶĶڹ +// Ա(ԭ) (Ӱδ) +// ˵ҿԴѶƬкѵֻ +// : ֹ!! +// Status : ... +//#define __CARDMESSAGE //()!! + + +//#define __NEW_CLIENT_ONLY_WRITE //Cary(,δ) +//#define CHINA_VER //Cary () +//#define __ALBUM_4 +//#define __ALBUM_6 //Cary µijಾ() +//#define __TEST_SERVER //Cary 3.0IJserver + +#define __HELP //Cary ˵ +#define __NEW_PROTOCOL //Cary µĵײ + +#define __NEW_CLIENT_MEM //Cary +#define __SKYISLAND //Cary յĹ +#define __HI_COLOR //Cary ߲ʵĹ(debug versionר) +#define __TALK_TO_NPC //Cary ʹnpc˵ +#define __NEW_BATTLE_EFFECT //Cary 2002.2.21 µսЧ: +#define _AFTER_TRADE_PETWAIT_ // ( ) set pet status to wait after trade :vincent + + + +#ifdef _SA_VERSION_40 +/* ------------------------------------------------------------------- +* ¹ܣ4 +* Ա־ +* ˵ +*/ +#define _FIX_DEL_MAP // (ɿ) WON ADD ҳͼ + +#define _FIX_9_FMPOINT // (ɿ) WON ADD Ŵׯ԰ +#define _FIX_10_FMPOINT //(ɿ) Change ʮׯ԰ 20050404 +#ifdef _FIX_10_FMPOINT +#define fm_point_num 10 // ׯ԰ +#else +#define fm_point_num 9 // (ɿ) WON ADD ׯ԰ +#endif + +#define _ADD_POOL_ITEM // (ɿ) WON ADD Ӽķŵ +//#define _ADD_FAMILY_TAX // (ɿ) WON ADD ׯ԰˰ + +#define _LOST_FOREST_FOG // (ɿ) the lostforest's fog. code:shan +#define _MIND_ICON // (ɿ) show icon from char mind. code:shan +#define _MAGIC_WEAKEN // (ɿ) show magic(weaken). code:shan + +#define _BLACK_MARKET // (ɿ) a black market. code:shan + +// ------------------------------------------------------------------- +// vincent define +#define _MAGIC_DEEPPOISION // (ɿ) show magic(deeppoison). code:vincent +#define _MAGIC_BARRIER // (ɿ) show magic(barrier). code:vincent +#define _MAGIC_NOCAST // (ɿ) show magic(nocast). code:vincent +#define _ITEM_CRACKER // (ɿ) : code:vincent +#define _SKILL_ROAR // (ɿ) vincent 輼:() +#define _SKILL_SELFEXPLODE // (ɿ) vincent 輼:Ա + +#define _NEW_RIDEPETS // (ɿ) + +#define _ATTDOUBLE_ATTACK // (ɿ) ǿ +#define __TOCALL_MAGIC // (ɿ) kjl 02/06/24 +#define _VARY_WOLF // (ɿ) pet skill : vary wolf. code:shan +#define _PIRATE_ANM // (ɿ) monster move(). code: shan +#define _TRADE_PETCOLOR // (ɿ) Syu ADD ı佻ʱתɫ +#define _FIXSHOWMPERR // (ɿ) Syu ADD ʱʾ +#define _LIZARDPOSITION // (ɿ) Syu ADD ʾλù + + +/* ------------------------------------------------------------------- +* ¹ܣ +* 2002/12/18 14:00 +*/ + +#define _TEAM_KICKPARTY // (ɿ) ANDY ӳ +#define _MONEYINPUT // (ɿ) Syu ADD ֶǮ + +#define _PETS_SELECTCON // (ɿ) ANDY ѡ + +#endif // _SA_VERSION_40 + + + +#ifdef _SA_VERSION_60 +/* ------------------------------------------------------------------- +* ¹ܣʯ6.0 +* +*/ +#define _OBJSEND_C // (ɿ) ANDY 6.0 +#define _ADD_SHOW_ITEMDAMAGE // (ɿ) WON ADD ʾߵ;ö +#define _WATERANIMATION // (ɿ) Syu ADD ֮ +#define _NEWDRAWBATTLEMAP // (ɿ) Syu ADD ˮսرսЧ +#define _AniCharBubble // (ɿ) Syu ADD ³ +#define _AniCrossFrame // (ɿ) Syu ADD ι +#define _AniImmobile // (ɿ) Syu ADD ض +#define _AniRandom // (ɿ) Syu ADD +//#define _DELBORNPLACE // (ɿ) Syu ADD 6.0 ͳһִ +#define _NEWMUSICFILE6_0 // (ɿ) Syu ADD 6.0 µͼ +#define _TRADESHOWNAME // (ɿ) Syu ADD ʾԷ +#define _TRADEINPUTMONEY // (ɿ) Syu ADD ֶǮ +#define _TRADE_SHOWHP // (ɿ) Syu ADD ʾѪ +#define _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ +#define _PETSKILL_CANNEDFOOD // (ɿ) ANDY \ܹͷ +#define _SPECIALSPACEANIM // (ɿ) Syu ADD ⳡ +#define _SHOOTCHESTNUT // (ɿ) Syu ADD 輼 +//#define _NEWLOGO // (ɿ) Syu ADD 6.0뻭logo Ҫ_v4_0 +#endif //SA_VERSION_60 + +#define _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + +#ifdef _SA_VERSION_70 +/* ------------------------------------------------------------------- +* ¹ܣʯ7.0 +* +*/ +//ѿ +#define _SARS // (ɿ) WON ADD ɷ +#define _FIX_MAXGOLD // (ɿ) WON ADD Ǯ + +#define _ITEM_PILENUMS // (ɿ) ANDY زĶѵ + +#define _ITEM_EQUITSPACE // (ɿ) ANDY װλ +#define _EQUIT_ARRANGE // (ɿ) ANDY +#define _EQUIT_NEWGLOVE // (ɿ) ANDY λ + +#define _LOCKPARTYFLOOR // (ɿ) Syu ADD Ӳӵĵͼ +#define _LOCKHELP_OK // (ɿ) Syu ADD ɼս + +#define _TRADETALKWND // (ɿ) Syu ADD Ի +#define _TRADELOCKBTN // (ɿ) Syu ADD + +#define _WAVETRACK // (ɿ) Syu ADD + +#define _CHAR_NEWLOGOUT // (ɿ) ANDY µdz + +//¹ܣְҵ +#define _TABLEOFSKILL // (ɿ) Syu ADD 7.0 \ܱ +//#define _NEWPANEL_71 // (ɿ) ROG ADD login +//#define _NEWPANEL_70 // (ɿ) Syu ADD ʯ7.0 LOGIN +#define _CHAR_PROFESSION // (ɿ) WON ADD ְҵ +#define _SKILLSORT // (ɿ) Syu ADD ְҵз +#define _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +#define _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +#define _NEWSOUNDEFFECT // (ɿ) Syu ADD Ч +#define _FIXSTATUS // (ɿ) Syu ADD ս״̬ʾʽ +#define _ALLDOMAN // (ɿ) Syu ADD аNPC +#define _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +#define _FRIENDCHANNEL // (ɿ) ROG ADD Ƶ +#define _TELLCHANNEL // (ɿ) ROG ADD Ƶ + +#define _DROPPETWND // (ɿ) Syu ADD ȷ + +#define _MAILSHOWPLANET // (ɿ) Syu ADD ʾƬ +#define _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ +#define _SPECIALSPACEANIM_FIX // (ɿ) ROG ADD +//#define _TIMEBAR_FUNCTION // (ɿ) ROG ADD ʱbarʽ + + +//10/23 +#define _FM_MODIFY // 幦޸ + +#define _FIREHUNTER_SKILL // (ɿ) ROG ADD ȸ_ɱ +#define _PETSKILL_ACUPUNCTURE // (ɿ) Change 輼:Ƥ +#define _PETSKILL_DAMAGETOHP // (ɿ) Change 輼:¿(Ѫı) +#define _PETSKILL_BECOMEFOX // (ɿ) Change 輼:Ļ +#define _PETSKILL_BECOMEPIG // (ɿ) Change 輼: + + +// ¹ܣϿ(¸ѻ) +#define _NEW_WGS_MSG // (ɿ) WON ADD WGSӴ + + +#define _CHANNEL_MODIFY // Ƶ + + +#define _CHANGEGALAXY // Robin ϵ +#define _ERROR301 // Robin APش301,Ʒδע + +#define _STANDBYPET // Robin ʹбServer +#endif //SA_VERSION_70 + + +#define DIRECTINPUT_VERSION 0x0700 // Robin DirectX SDK + +#define _CLOUD_EFFECT // (ɿ) ROG ADD ƲЧ +//#define _NPC_WELFARE_2 // (ɿ) WON ADD ְҵNPC-2 + +//#define _NPC_SELLSTH // (ɿ) ANDY +//#define _SYUTEST +//#define _SYUTEST2 +//#define _SYUTEST3 +//#define _AUCPROTOCOL // (ɿ) Syu ADD ƵProtocol + +/* ------------------------------------------------------------------- +* ¹ܣPK +* +*/ +// +// + +//#define _PKSERVERCHARSEL // (ɿ) Syu ADD PKѡϵ +// ------------------------------------------------------------------- +// ²ɿ +/* ------------------------------------------------------------------- +* ¹ܣreal.binͼ +* +*/ +//F +//#define _SAHOOK // (ɿ) Syu ADD Hookʽ +//#define _REALDIVISION // (ɿ) Syu ADD real.binͼҪrealtxt.txt +// ------------------------------------------------------------------- +//#define _OMIT_WGS // (ɿ) ԹʺšWGS. code:shan +// ------------------------------------------------------------------- +#ifdef _SA_VERSION_50 +/* ------------------------------------------------------------------- +* ¹ܣʯ5.0 +* ˵ +*/ +//#define _CANT_ATK // (ɿ) can't attack(own team). code: shan +//#define _SETTICK_COUNT // (ɿ) ANDY ظ +//#define _GM_MARK // (ɿ) WON ADD GM ʶ +//#define _GM_IDENTIFY // (ɿ)Rog ADD GMʶgmָ + +//#define _LOGINKICK // (ɿ) Syu ADD 뻭泬30߻ϵб +#endif //SA_VERSION_50 +#define MALLOC(s) malloc(s) +#define CALLOC(c,s) calloc(c,s) +#define new new(_NORMAL_BLOCK,__FILE__,__LINE__) +#define FREE(p) free(p) + +//#define _PET_TRACE_MOUSE +//#define __EDEN_DICE // (ɿ) ij +#define _AI_OTHER // AI +#define __AI // Cary Զս +#ifdef _AI_OTHER +#define _AI_CAPTURE +#endif +//----------------------- +unsigned int TimeGetTime(void); + +#ifdef _SA_VERSION_70 +#ifdef _BACK_VERSION +#define _REMAKE_20 // ʯ̹ܿ() +#define _BACK_LOGO +#define _BACK_WINDOW //̰Ӵ(debugſɿ,ڲԱʹ) +#define _READ16BITBMP // Terry ɶ뼰ʾ߲ͼ +#else +#define _ATTACK_AI // ڹҹAI +#define _AI_NEW_FIRST // AI ״οְҵ +#define _BATTLESKILL // (ɿ) Syu ADD սܽ +#define _NEWPANEL // (ɿ) Syu ADD 7.0 ״̬ +#endif +#endif + +#ifdef _SA_VERSION_75 +/* ------------------------------------------------------------------- +* ¹ܣʯ7.5 +* +*/ + +#define _ANGEL_SUMMON // ʹл Robin +#define _PROFESSION_ADDSKILL // (ɿ) Change ׷ְҵ +#define _TRANS_6 // (ɿ) Change 6ת +#define _PET_2TRANS // (ɿ) Change 2ת +//#define _75_LOGIN // 7.5login +#define _STREET_VENDOR // ̯ +#define _NEW_MANOR_LAW // ׯ԰ + +#define _PETSKILL_LER // ׶ +//#define _PK_SERVER //PK +//#define _8_TEST //8.0server + +// ------------------------------------------------------------------- +// רϻرϵͳ +// Աݿ +// ˵ +//#define __ONLINEGM +//-------------------------------------------------------------------- + +#define _STREET_VENDOR_CHANGE_ICON // ޸İ̯ͼʾ + +#define _TALK_WINDOW // ԻӴ +#define _SHOW_FUSION // (ɿ) Change ںϳCLIENTֻʾת,޸ΪںϳʾΪں +#define _NPC_FUSION // (m) ANDY NPCо + +#define _FONT_SIZE // Robin (Ҫ) ɸʹС +#define _CONTRACT // Robin (Ҫ) Լ +#define _HALLOWEEN_EFFECT // ʥЧ +#define _ADD_STATUS_2 // ״̬ڶ +#define _PETSKILL_BATTLE_MODEL // \սģ +#define _RACEMAN // cyg Գnpc +#define _PETSKILL_ANTINTER // (ɿ) Change 輼:֮ +#define _PETSKILL_EXPLODE // (ɿ) Change 輼:ѹ +#define _ITEM_FIREWORK // ̻ +#define _FIREWORK_SOUND // cyg Ч(̻) +#define _GET_HOSTNAME // (ɿ) Change ȡõ +#define _SKILL_ADDBARRIER // (ɿ) Change 輼:Ϊħ쳣Թ +#define _PETSKILL_PEEL // (ɿ) Change 輼:ѿ + +//#define _MOUSE_DBL_CLICK // Robin Ҽ˫ +#endif //SA_VERSION_75 + +#ifdef _SA_VERSION_80 +//-------------------------------------------------------------------------------------------------------- +//ר 8.0 ʧ ¼ӹܶ Աѫ ݿ +//-------------------------------------------------------------------------------------------------------- +#define _PET_ITEM // Terry װ +#define _NPC_PICTURE // (ɿ) Change ¶ij(ʱNPC) +#define _JOBDAILY // cyg ־ +#define _ITEM_PATH // (ɿ) Change ̤ϲĵ +#define _ALCHEMIST // Robin +#define _ALCHEPLUS // Robin +#define _EXTEND_AB // cyg Ƭ +#define _ITEM_INTENSIFY // (ɿ) Change 輼:ǿ +#define _TEACHER_SYSTEM // Terry ʦϵͳ +#define _ITEM_UPINSLAY // (ɿ) Change 輼:(õ߿ϸ౦ʯ) +#define _MAG_MENU // (ɿ) Change ħȡʾΪͼʾ +#define _NPC_MAGICCARD // cyg ħϷ +#define _THEATER // Terry 糡 +#define _MOVE_SCREEN // Terry ƶӫĻָ +// #define _80_LOGIN // Terry 8.0 뻭 +#define _8_RIDEPETS // (ɿ) Change 8.0 +#define _8BATTLEMAP // Change 8.0 սر +#define _PETKILL_COST_FAME // Terry \ܵѧҪ +#define _DRAGON_FUSION // Robin + +#define _MACADDRESSD // (ɿ) Change get MAC card +#define _NEW_EARTH // Terry µ,ɿڲ +//#define _80_LOGIN_PLAY // Terry 8.0 뻭 +//---------------------------------------------------------------------- + +//#define _ITEM_JIGSAW // (ɿ) Change ƴͼ + +#define _NPC_DANCE // cyg һnpc +#define _ATTACK_EFFECT // ɫᲥŹЧ + +//#define _2005_ValentineDay // Terry 2005 ˽ڻ +#define _PETSKILL_ADDATTCRAZED // (ɿ) Change 輼:ұӹ +#define _PETSKILL_JUSTICE // (ɿ) Change 輼: +#define _CALLBUS // (ɿ) Change ùбеĹ + +//#define _NPC_ITEMUP // (ɿ) Change õNPC +//#define _ITEM_COUNTDOWN // cyg ߵ + +#define _PRO_KILLME // Change ְ ʰյ +#define _PETSKILL_EVOLUTION // (ɿ) Change ܳ輼: +#define _PETSKILL_PROVOKEFIGHT // (ɿ) Change Ȯ輼:Ʒ +#define _FIX_ACUPUNCTURE // (ɿ) Change Ƥ޸ +#define _PETSKILL_RIDE // (ɿ) Change 輼: + +#endif // _SA_VERSION_80 + +#ifdef _SA_VERSION_85 +//-------------------------------------------------------------------------------------------------------- +//ר 8.5 ħð ¼ӹܶ Ա ݿ +//-------------------------------------------------------------------------------------------------------- +#define _PRO_ABSOLUTE_DEFENSE // (ɿ) Change ְ Է +#define _PRO3_ADDSKILL // (ɿ) Change ׷8.5ְҵ +#define _NPC_DAYACTION // cyg ÿջ +#define _EVIL_KILL // cyg ַħϵͳ +#define _HUNDRED_KILL // cyg ˫ +#define _NEW_CLOUD // (ɿ) Change µĵͼЧ +//#define _85_LOGIN // (ɿ) Change 8.5뻭 +//---------------------------------------------------------------------- +#define _AI_SKILL_UPDATE //AI +#define _TEACHER_SYSTEM_2 // cyg µʦϵͳ +#endif +#endif + + +/* + +*/ +#define _FIX_MAXGOLD // (ɿ) WON ADD Ǯ +#define _MOON_FAIRYLAND // (ɿ) ROG ADD ֮ɾ +#define _SPECIALSPACEANIM_FIX // (ɿ) ROG ADD +#define _LOGINKICK // (ɿ) Syu ADD 뻭泬30߻ϵб +//#define _CHECK_GAMESPEED // (ɿ) ANDY +#define _NEW_CLOUD // (ɿ) Change µĵͼЧ +#define _FIX_BATTLE_AI // ޸սAIתBUG +#define _WIN_LUAJIT_ //LUAJITչ ֧Ľӿں·LUAļ +#define _NEW_COLOR_ //֧16λRGB565߲ͼƬ +#define _NEW_WIN_POS_ //800ƫ +#define _NEW_ALPHA_ //½͸ +//#define _CACHE_SURFACE_ // +//#define _OPTIMIZATIONFLIP_ //ŻFlip +#define _KEY_ "AEB3A729E71F8870D4611FBDC01D0A4B" //м +//#define _NEWFONT_ + + +#define _MO_SIGN_IN //ͻǩť +#define _CHANGE_HELP_BUTTON //޸İťͼ +#define _PETCOM_ //ɳԶ +#define _NEW_SPEED_ //Ϸٶ + +#define _PETCOLOR_ //1ɫ +#define _PETKILL_COST_FAME // Terry \ܵѧҪ +#define _AIDENGLU_ //Զ½ +#define _ZHENGSHIKAIFU_ //ʽ +#define _ZENGJIASHUO_ //һߵͼ꣬ͬʱĵ߲ѡ +#define _BUDING_ "554CDB1A99DF514B2F0B09DBDA0A6E9D" // +#define _TIME_GET_TIME // QueryPerformanceCounterȡtimeGetTime +#define _FAMILYBADGE_ // +#define _SHOWFAMILYBADGE_ //ʾ +#define _NEWNET_ //· +//#define _LOGIP_ //½ʱȡIP +//#define _SHOWIPSLEEP_ //ʾ·ʱ +//#define _MEMORYLEAK_CHECK //ڴй© +//#define _COMFIRM_TRADE_REQUEST //ȷ +#define _DIEJIA_ //ӹ +#define _FANILYTEXIAOY_ 45 //ƫY ԽԽڶ +#define _OTHERTEXIAOY_ 70 //ͼƫY ԽԽڶ +#define _ATTACK_EFFECT // ɫᲥŹЧ +#define _SA_VERSION 'N' +#define _SA_MAC_VERSION_CONTROL //MAC汾ſ +#define FAMILY_MANOR_ //ׯ԰⻷ +#define _CHAR_MANOR_ //¹⻷ +//#define _CHAR_MANOR_DEBUG //¹⻷DEBUG +#define _ANNOUNCEMENT_ //ϵͳ +//#define _EFFECT_MAP_ //Ч +#ifndef _DEBUG__ +#define _VMP_ //VMPܿ +//#define _NODEBUG_ // Եʱˣʽʹ +#else +#define _CMD_MODE //ģʽ +//#define _STONDEBUG__PACKET_ //Է +//#define _MO_SHOW_FPS //ʾfps +#define _RELUA_ //DEBUGģʽðϢضLUA +#endif +#define SHOW_VERSION "www.shiqi.hk" +//#define _TRADE_BUG_LOG //bug־ +#define _SECONDARY_WINDOW_DATA_ // +#define LABEL_STR_ //ض[][] + +#ifdef _SA_VERSION_25 +#define _DEFAULT_PKEY "shiqi" // ĬϵԿ +#define _RUNNING_KEY "shiqi.hk" // Կ +#define _SYSTEM_SLEEP_ 6 //Ϸٶ +#define _SURFACE_ANIM // ̬ʾ +#define _DEFENSETOOENNUM_ 5 //޼ +#define DENGLUKEY1 "6D27AEB8326A2A8E7D04B9F9B44C59C7" +#define _LEADERRIDE // (ɿ) Ĵﱩ Robin 0921 +//#define _MO_IMAGE_EXTENSION //չ +#define _NEW_ITEM_ //µ +#ifdef _WIN_LUAJIT_ +#define _LUA_PATCH_ ".//lua" //LUA· +#define _LUA_KEY_ "6A68673107B8C5B829815A507FF5C274" //LUAԿ +#endif +#define _MAGIC_ITEM_ // +#define _ICONBUTTONS_ //ת +#define _BATTLE_TIME_ 99000 +#define _PET_2TRANS // (ɿ) Change 2ת +#define _DEBUGVER_ "2.2" //DEBUG汾 +#define _NEWSHOP_ //̳ +#define _SHOWPETTRN_ //ʾת +#ifdef _SA_MAC_VERSION_CONTROL +#define _SA_MAC_VERSION "7sa2" +#endif +#define _CHANGETEAM_ //ӳл +#define SA_MUTE "sa25.exe" +#define _NEW_CHARDATA_ // +#define _PETBLESS_ //ף +#define _RIDEPET_ //迪 +#define DEF_APPNAME "STONEAGE" // Ϸ +#define _RIDEQUERY_ //ѯ +#define _CHAT_SPACING 24 //о 20 +#define __EMOTION //Cary ı飬ֻclient +//#define _PET_SKINS //Ƥ +#define _PET_2TRANS // (ɿ) Change 2ת +#define _NPC_EVENT_NOTICE //npcϢʾ +#define _SHOWPETTRN_ //ʾת +//#define _PET_VAL_COLOR_ //ɫ +#define _MO_CHAT_EXPRESSION //鹦 +#define _SA_LIAOTIAN_ //ɾť +#define _CHARTITLE_STR_ //ֳƺ óƺſ,ͼγƺʧЧ +#define _FONT_STYLE_ //֘ʽ +#define _MESSAGE_FRONT_ //ϢǰӸ +#define _TRADITIONAL_LONG_ //ϵͳ½ +#define _FONTDATALEN_ 100 //Ϣ 112 +#define MAX_AIRPLANENUM 8 +#define _FIX_CG_ATR_ICON +#define _PETSKILL_LER +//#define _CANCEL_FANTI //ȡл +//#define _RED_MEMOY_ // +#endif + +#ifdef _MO_CHAT_EXPRESSION +#define CG_FIELD_CHAT_BTN_ON 55102 +#define CG_FIELD_CHAT_BTN_OFF 55102 +//#define EXPRESSION_NOID_START 55300 //ͼʼID +//#define EXPRESSION_NOID_END 55421 //ͼŽID +#define EXPRESSION_NOID_START 55117 //ͼʼID +#define EXPRESSION_NOID_END 55215 //ͼŽID +#define EXPRESSION_NOID_NUM EXPRESSION_NOID_END-EXPRESSION_NOID_START +#define _SUNDAY_STR_SEARCH //SUNDAYַ㷨 KMPţٶȸ㷨 +#endif + diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.cpp new file mode 100644 index 0000000..23502a3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.cpp @@ -0,0 +1,218 @@ +//ping.cpp +#include +#include +#include "ping.h" +#pragma comment(lib, "ws2_32.lib") + +bool CPing::Ping(LPCSTR pstrHost, UINT nRetries) +{ + //һRaw׽ + SOCKET rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); + if (rawSocket == INVALID_SOCKET) + { + int err = WSAGetLastError(); + return false; + } + int nNetTimeout = 1000;//1 + //ʱ + setsockopt(rawSocket, SOL_SOCKET, SO_SNDTIMEO, (char *)&nNetTimeout, sizeof(int)); + //ʱ + setsockopt(rawSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&nNetTimeout, sizeof(int)); + + //Ϣ + LPHOSTENT lpHost = gethostbyname(pstrHost); + if (lpHost == NULL) + { + return false; + } + //Ŀ׽ֵַϢ + struct sockaddr_in saDest; + struct sockaddr_in saSrc; + saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); + saDest.sin_family = AF_INET; + saDest.sin_port = 3077; + + DWORD dwTimeSent; + u_char cTTL; + int nRet; + int nRecvNum = 0; + int nTotalTime = 0; + + //ping + for (UINT nLoop = 0; nLoop < nRetries; ++nLoop) + { + //ICMPӦ + if ((nRet = SendEchoRequest(rawSocket, &saDest)) < 0) + { + break; + } + + if ((nRet = WaitForEchoReply(rawSocket)) == SOCKET_ERROR) + { + break; + } + + if (nRet) + { + //ûӦ + if ((dwTimeSent = RecvEchoReply(rawSocket, &saSrc, &cTTL)) < 0) + { + nRet = dwTimeSent; + break; + } + + //ʱ + nTotalTime += GetTickCount() - dwTimeSent; + ++nRecvNum; + } + } + + closesocket(rawSocket); + + if (nRecvNum > 0 && nRet >= 0) + { + m_Result.nElapseTime = nTotalTime / nRetries; + m_Result.cTTL = cTTL; + m_Result.fMissPack = (float)(nRetries - nRecvNum) / nRetries; + return true; + } + return false; +} + + + +//ICMPECHOݰ +int CPing::SendEchoRequest(SOCKET s, LPSOCKADDR_IN lpstToAddr) +{ + static ECHOREQUEST echoReq; + static int nId = 1; + static int nSeq = 1; + int nRet; + + //Ӧ + echoReq.icmpHdr.Type = ICMP_ECHOREQ; + echoReq.icmpHdr.Code = 0; + echoReq.icmpHdr.Checksum = 0; + echoReq.icmpHdr.ID = nId++; + echoReq.icmpHdr.Seq = nSeq++; + + for (nRet = 0; nRet < REQ_DATASIZE; nRet++) + echoReq.cData[nRet] = ' ' + nRet; + + //淢ʱ + echoReq.dwTime = GetTickCount(); + + echoReq.icmpHdr.Checksum = in_cksum((u_short *)&echoReq, sizeof(ECHOREQUEST)); + + // + nRet = sendto(s, + (LPSTR)&echoReq, + sizeof(ECHOREQUEST), + 0, + (LPSOCKADDR)lpstToAddr, + sizeof(SOCKADDR_IN)); + //鷵ֵ + if (nRet == SOCKET_ERROR) + { + + } + + return (nRet); +} + + + +//ICMPECHOݰӦ +DWORD CPing::RecvEchoReply(SOCKET s, LPSOCKADDR_IN lpsaFrom, u_char *pTTL) +{ + ECHOREPLY echoReply; + int nRet; + int nAddrLen = sizeof(struct sockaddr_in); + + //Ӧ + nRet = recvfrom(s, + (LPSTR)&echoReply, + sizeof(ECHOREPLY), + 0, + (LPSOCKADDR)lpsaFrom, + &nAddrLen); + + //鷵ֵ + if (nRet == SOCKET_ERROR) + { + return nRet; + } + + //ط͵ʱ + *pTTL = echoReply.ipHdr.TTL; + + return(echoReply.echoRequest.dwTime); +} + + + +//ȴӦ +int CPing::WaitForEchoReply(SOCKET s) +{ + struct timeval Timeout; + fd_set readfds; + + FD_ZERO(&readfds); + FD_SET(s,&readfds); + Timeout.tv_sec = 1; + Timeout.tv_usec = 0; + + int ret = select(s+1, &readfds, NULL, NULL, &Timeout); + + return ret; +} + + + +//תַ +u_short CPing::in_cksum(u_short *addr, int len) +{ + register int nleft = len; + register u_short *w = addr; + register u_short answer; + register int sum = 0; + + while (nleft > 1) { + sum += *w++; + nleft -= 2; + } + + if (nleft == 1) { + u_short u = 0; + + *(u_char *)(&u) = *(u_char *)w; + sum += u; + } + + sum = (sum >> 16) + (sum & 0xffff); + sum += (sum >> 16); + answer = ~sum; + return (answer); +} + + + +void CPing::Result(int* nElapseTime, float* fMissPack, u_char* cTTL) +{ + if (nElapseTime) + { + *nElapseTime = m_Result.nElapseTime; + } + + if (fMissPack) + { + *fMissPack = m_Result.fMissPack; + } + if (cTTL) + { + *cTTL = m_Result.cTTL; + } +} + + + diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.h b/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.h new file mode 100644 index 0000000..d07db10 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/Ping.h @@ -0,0 +1,87 @@ +//ping.h +#ifndef _CPING_H_ +#define _CPING_H_ +#pragma pack(1) + +#define ICMP_ECHOREPLY 0 +#define ICMP_ECHOREQ 8 +#define REQ_DATASIZE 32 // Echo ݵĴС + +class CPing +{ +public: + //ping host nRetries-ping + bool Ping(LPCSTR pstrHost, UINT nRetries = 4); + + void Result(int* nElapseTime, float* fMissPack = NULL, u_char* cTTL = NULL); + //void Result(CPing::REQ_RESULT& result); + +private: + int WaitForEchoReply(SOCKET s); + //ICMPӦͻش + int SendEchoRequest(SOCKET, LPSOCKADDR_IN); + DWORD RecvEchoReply(SOCKET, LPSOCKADDR_IN, u_char *); + u_short in_cksum(u_short *addr, int len); + +private: + struct REQ_RESULT + { + int nElapseTime; //Ӧʱ䡣 + u_char cTTL; //TTL(ʱ) + float fMissPack; // + }; + + REQ_RESULT m_Result; + +}; + + + +// IP Header -- RFC 791 +typedef struct tagIPHDR +{ + u_char VIHL; // Version and IHL + u_char TOS; // Type Of Service + short TotLen; // Total Length + short ID; // Identification + short FlagOff; // Flags and Fragment Offset + u_char TTL; // Time To Live + u_char Protocol; // Protocol + u_short Checksum; // Checksum + struct in_addr iaSrc; // Internet Address - Source + struct in_addr iaDst; // Internet Address - Destination +}IPHDR, *PIPHDR; + + +// ICMP Header - RFC 792 +typedef struct tagICMPHDR +{ + u_char Type; // Type + u_char Code; // Code + u_short Checksum; // Checksum + u_short ID; // Identification + u_short Seq; // Sequence + char Data; // Data +}ICMPHDR, *PICMPHDR; + + +// ICMP Echo Request +typedef struct tagECHOREQUEST +{ + ICMPHDR icmpHdr; + DWORD dwTime; + char cData[REQ_DATASIZE]; +}ECHOREQUEST, *PECHOREQUEST; + + +// ICMP Echo Reply +typedef struct tagECHOREPLY +{ + IPHDR ipHdr; + ECHOREQUEST echoRequest; + char cFiller[256]; +}ECHOREPLY, *PECHOREPLY; + +#pragma pack() + +#endif diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/common.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/common.cpp new file mode 100644 index 0000000..7cf961f --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/common.cpp @@ -0,0 +1,378 @@ +/*----------------------------------------------- + Common.cpp -- common function + (c) ʤCary Hsu, 1999.10.4 +-----------------------------------------------*/ +#include +#include +#include "../systeminc/version.h" +#include "Message.h" +#include "../systeminc/login.h" + +#ifdef _MEMORYLEAK_CHECK +#include "../LeakDetector/vld.h" +#endif + +char szPid[10]; + +char szCSIP[125]; +char szError[1024]; +char szAnnouncement[1024]; + + +//#ifdef CHINA_VER + // ½ +// char szWGS[]="210.51.17.41"; +// WORD wWGS=9125; +//#else + + +#ifdef _BACK_VERSION //// + // ̰ + char szWGS[]="210.64.97.28"; + WORD wWGS=13009; +#else + +#ifdef _PK_SERVER + // PK + char szWGS[]="210.64.97.28"; + WORD wWGS=13010; +#else + // ʽ + char szWGS[]="210.64.97.28"; + //char szWGS[]="wgs.hwaei.com.tw"; + WORD wWGS=13005; + +#endif + +#endif + +WORD wCS; +char szPlain[80]; +char szCipher[80]; +char P_Key[8]; +char P_Key1[256]; +extern int iEncrypt; + +DWORD dwServer=NULL; +int iWGS=0; + +BOOL ReadWGSMessage(LPSTR lpstr,int &iStrLen) +{ + TCHAR cMessage=0; + Parameter *param; + if(RET_OK==AnalyzeMessage(lpstr,iStrLen)){ + if(WGS==dwServer){ + while(messHead){ + cMessage=*messHead->param->lpstrParam; + param=ReleaseMessHeadParam(); + if(M_REDI==cMessage){ + if(GetIP_PORT(param)){ + iWGS=2; + ReleaseMessList(); + } + }else if(M_PKEY==cMessage){ + iEncrypt=E_ECB; + dwServer=CS; + GetEncrypt(param); + PKey_Init(); + iWGS=4; + ReleaseMessList(); + }else if(M_ERRO==cMessage){ + iWGS=9; + if(messHead->param && messHead->param->lpstrParam) + lstrcpy(szError,messHead->param->lpstrParam); + } + RemoveMessHead(); + } + }else{ + while(messHead){ + cMessage=*messHead->param->lpstrParam; + param=ReleaseMessHeadParam(); + if(M_PKEY==cMessage){ + iEncrypt=E_ECB; + GetEncrypt(param); + iWGS=4; + }else if(M_CONT==cMessage){ + iWGS=6; + }else if(M_GOTO==cMessage){ + iWGS=8; + iEncrypt=E_NO; + ipAddressAnalyze(); + ReleaseMessList(); + }else if(M_ERRO==cMessage){ + iWGS=9; + if(messHead->param && messHead->param->lpstrParam) + lstrcpy(szError,messHead->param->lpstrParam); + ReleaseMessList(); + } + RemoveMessHead(); + } + } + }else + return FALSE; + iStrLen=0; + return TRUE; +} + +BOOL GetIP_PORT(Parameter *param) +{ + if((param)&&(param->lpstrParam)){ + lstrcpy(szCSIP,param->lpstrParam); + if((param=ReleaseMessHeadParam())&&(param->lpstrParam)){ + wCS=(WORD)atoi(param->lpstrParam); + if((param=ReleaseMessHeadParam())&&(param->lpstrParam)){ + lstrcpy(szPid,param->lpstrParam); + return TRUE; + } + } + } + return FALSE; +} + +void GetEncrypt(Parameter *param) +{ + if(param && param->lpstrParam){ + int iLen=strlen(param->lpstrParam); + iLen>>=1; + strncpy_s(szPlain,param->lpstrParam,iLen); + szPlain[iLen]='\0'; + strcpy(szCipher,param->lpstrParam+iLen); + } +} + +void PKey_Init() +{ + TCHAR szTemp[17],szTemp1[3]; + srand((unsigned)time(NULL)); + int i; + for(i=0;i<7;i++) + szTemp[i]=P_Key[i]=rand()%256; + P_Key[7]='\0'; + for(i=7;i<16;i++) + szTemp[i]=rand()%256; + P_Key1[0]='\0'; + for(i=0;i<16;i++){ + wsprintf(szTemp1,"%02X",(unsigned char)~szTemp[i]); + lstrcat(P_Key1,szTemp1); + } +} + +#include "../systeminc/chat.h" +extern STR_BUFFER idKey; +extern STR_BUFFER passwd; +int appendWriteBuf( int index , char *buf , int size ); + +void DoHellow() +{ + AddParamForFormat(M_HELO2,FORMAT_START); + AddParamForFormat(idKey.buffer,idKey.cnt,NULL); + AddParamForFormat(passwd.buffer,passwd.cnt,FORMAT_FINISH); + int iLen; + LPTSTR lpstr=GetString(iLen,P_Key); + appendWriteBuf(NULL,lpstr,iLen); +} + +void DoSKey() +{ + int iLen; + AddParamForFormat(M_SKEY,FORMAT_START); + PKey_Init(); + AddParamForFormat(P_Key1,32,FORMAT_FINISH); + LPTSTR lpstr=GetString(iLen,SZ_ECB); + appendWriteBuf(NULL,lpstr,iLen); +} + +#ifdef _OMIT_WGS +void testtest() +{ + LPTSTR lpstr = O_WGS_Format(); + appendWriteBuf(NULL,lpstr, 6); +} +#endif + +#include "../systeminc/netmain.h" +extern struct gameserver gmsv[]; +struct gamegroup gmgroup[MAX_GMGROUP]; +extern int nGroup; + +#ifdef NO_WGS +void SetTestServer() +{ + ZeroMemory( gmsv, sizeof(gameserver)*MAX_GMSV); + ZeroMemory( gmgroup, sizeof(gamegroup)*MAX_GMGROUP); + /* + nGroup = 2; + strcpy( gmgroup[0].name, ""); + gmgroup[0].num = 2; + gmgroup[0].startindex = 0; + gmgroup[0].used = 1; + strcpy( gmgroup[1].name, "Դ"); + gmgroup[1].num = 2; + gmgroup[1].startindex = 2; + gmgroup[1].used = 1; + + strcpy( gmsv[0].ipaddr, "127.0.0.1"); + strcpy( gmsv[0].name, "һ"); + strcpy( gmsv[0].port, "7001"); + gmsv[0].used = '1'; + + strcpy( gmsv[1].ipaddr, "114.215.158.113"); + strcpy( gmsv[1].name, "Զ"); + strcpy( gmsv[1].port, "7001"); + gmsv[1].used = '1'; + + strcpy( gmsv[2].ipaddr, "192.168.0.104"); + strcpy( gmsv[2].name, ""); + strcpy( gmsv[2].port, "7001"); + gmsv[2].used = '1'; + + strcpy( gmsv[3].ipaddr, "my.gamma7happy.com"); + strcpy( gmsv[3].name, ""); + strcpy( gmsv[3].port, "7001"); + gmsv[3].used = '1'; + */ + HRESULT hr = ::CoInitialize( NULL ); + if ( FAILED( hr ) ) + { + MessageBoxA( NULL, "ʼʧ", "ERROR", MB_OK ); + return; + } + ::CoUninitialize(); + +} +#endif + +void ipAddressAnalyze() +{ + char szIP[50]; + DWORD dwLevel = 0; + DWORD dwID, dwResult; + int nGroup1, indexgm; + LPSTR lpstrTemp; + DWORD dwCafeKey = GetCafeNumber(); + Parameter *param = messHead->param; + HKEY hkey; + if( RegOpenKeyEx( HKEY_LOCAL_MACHINE , "Software\\Waei\\ʯʱ\\5.00.000" , 0 , KEY_READ , &hkey ) == ERROR_SUCCESS ){ + dwCafeKey |= 0x02; + RegCloseKey( hkey ); + } + if( param && param->lpstrParam){ + nGroup = 0;// + indexgm = 0; + ZeroMemory( gmsv, sizeof(gameserver)*MAX_GMSV); + ZeroMemory( gmgroup, sizeof(gamegroup)*MAX_GMGROUP); + nGroup1 = atoi( param->lpstrParam); + if( nGroup1 > MAX_GMGROUP) + nGroup1 = MAX_GMGROUP; + param = ReleaseMessHeadParam(); + +#ifdef _SHOW_COUNT // WON ADD + if( param && param->lpstrParam){ + param = ReleaseMessHeadParam(); + } +#endif + + for( int i = 0; i < nGroup1; i++){ + if( param && param->lpstrParam){ + dwID = atoi( param->lpstrParam); + param = ReleaseMessHeadParam(); + dwResult = dwID & dwCafeKey; + dwLevel = 1; //ѡ + if( dwCafeKey){ + // ֻҪСͿԿϵ + /*if(dwID){ + if( 0 == dwResult) + dwLevel = 0; // + }*/ + }else{ + if(dwID){ + dwLevel = 0;// + } +#ifdef _8_TEST + if( dwID == 2 ) + dwLevel = 1; + else + dwLevel = 0; +#endif + } +/* + dwLevel = 1; //ѡ + if( 0 == dwResult){ + if( dwID > 1) + dwLevel = 2; //ֻܿѡ + else if( 1 == dwID) + dwLevel = 0; // + } +*/ + } + if( param && param->lpstrParam){ + if( dwLevel) + strcpy( gmgroup[nGroup].name, param->lpstrParam); + param = ReleaseMessHeadParam(); + } + if( param && param->lpstrParam){ + gmgroup[nGroup].num = atoi(param->lpstrParam); + param = ReleaseMessHeadParam(); + } + if( param && param->lpstrParam){ + strcpy( szIP, param->lpstrParam); + param = ReleaseMessHeadParam(); + gmgroup[nGroup].startindex = indexgm; + +#ifdef _SHOW_COUNT // WON ADD + if( param && param->lpstrParam){ + param = ReleaseMessHeadParam(); + } +#endif + + + for( int j = 0; jlpstrParam){ + if( dwLevel) + strcpy( gmsv[indexgm].name, param->lpstrParam); + param = ReleaseMessHeadParam(); + } + if( param && param->lpstrParam){ + if( dwLevel){ + char *sss; + if( lpstrTemp = strtok_s( param->lpstrParam, ":",&sss)){ + if( szIP[0]){ //ͬһgroupͬһC classķΧ + strcpy( gmsv[indexgm].ipaddr, szIP); + strcat_s( gmsv[indexgm].ipaddr, "."); + strcat_s( gmsv[indexgm].ipaddr, lpstrTemp); + }else //Copy IP address + strcpy( gmsv[indexgm].ipaddr, lpstrTemp); + char *sss; + if( lpstrTemp = strtok_s( NULL, ":",&sss)){ + strcpy( gmsv[indexgm].port, lpstrTemp); + gmsv[indexgm].used = '1'; + } + } + } + param = ReleaseMessHeadParam(); + } +#ifdef _SHOW_COUNT // WON ADD + if( param && param->lpstrParam){ + strcpy( gmsv[indexgm].count, param->lpstrParam); + param = ReleaseMessHeadParam(); + } +#endif + } + if( dwLevel){ + gmgroup[nGroup].used = (char)dwLevel; + nGroup++; + } + } + } + if (param && param->lpstrParam){ + strcpy( szAnnouncement, param->lpstrParam); + param = ReleaseMessHeadParam(); + }else + szAnnouncement[0] = '\0'; + } +} + + +#ifdef _MEMORYLEAK_CHECK + +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.cpp new file mode 100644 index 0000000..9398ad9 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.cpp @@ -0,0 +1,1597 @@ +/* + * ecb_crypt, cbc_crypt, des_setparity - DES encryption/decryption routine + * + * Written by Koichiro Mori (kmori@lsi-j.co.jp) + */ +#include +#include "../systeminc/version.h" +#include "descrypt.h" + +#define YES 1 +#define NO 0 +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; + + + + +void des_setparity(char *key) +{ + int n; + + for (n = 8; n > 0; n--) { + char c; + + c = *key &= 0x7f; + c ^= c << 4; + c ^= c << 2; + c ^= c << 1; + *key++ ^= ~c & 0x80; + } +} + + +ulong Keys[16][2]; + +void des_setkey(char *key) +{ + static char nshifts[] + = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; +#define C 28 +#define D 0 + static uchar pc1[] = { + C + 20, C + 12, C + 4, D + 0, D + 4, D + 12, D + 20, + C + 21, C + 13, C + 5, D + 1, D + 5, D + 13, D + 21, + C + 22, C + 14, C + 6, D + 2, D + 6, D + 14, D + 22, + C + 23, C + 15, C + 7, D + 3, D + 7, D + 15, D + 23, + C + 24, C + 16, C + 8, C + 0, D + 8, D + 16, D + 24, + C + 25, C + 17, C + 9, C + 1, D + 9, D + 17, D + 25, + C + 26, C + 18, C +10, C + 2, D +10, D + 18, D + 26, + C + 27, C + 19, C +11, C + 3, D +11, D + 19, D + 27 + }; + static uchar pc2_c[] = { + 14, 11, 17, 4, 27, 23, + 25, 0, 13, 22, 7, 18, + 5, 9, 16, 24, 2, 20, + 12, 21, 1, 8, 15, 26 + }; + static uchar pc2_d[] = { + 15, 4, 25, 19, 9, 1, + 26, 16, 5, 11, 23, 8, + 12, 7, 17, 0, 22, 3, + 10, 14, 6, 20, 27, 24, + }; + ulong c, d; + uchar b, *p; + int i, j; + + /* PC-1 (Permuted Choice 1) */ + c = d = 0; + p = pc1; + for (i = 0; i < 8; i++) { + b = *key++; + for (j = 0; j < 7; j++) { + if (b & 0x80) { + if (*p >= C) + c |= 1L << (*p - C); + else + d |= 1L << *p; + } + p++; + b <<= 1; + } + } + + for (i = 0; i < 16; i++) { + uchar *k, mask, w[8]; + uint n = nshifts[i]; + + c = (c << n | c >> (28 - n)) & 0x0fffffff; + d = (d << n | d >> (28 - n)) & 0x0fffffff; + /* PC-2 (Permuted Choice 2) */ + k = w; + p = pc2_c; + for (j = 0; j < 4; j++) { + *k = 0; + for (mask = 0x20; mask > 0; mask >>= 1) { + if ((c >> *p++) & 1) + *k |= mask; + } + k++; + } + p = pc2_d; + for (j = 0; j < 4; j++) { + *k = 0; + for (mask = 0x20; mask > 0; mask >>= 1) { + if ((d >> *p++) & 1) + *k |= mask; + } + k++; + } + + Keys[i][0] = ((ulong)w[0] << 24) | ((ulong)w[2] << 16) + | ((ulong)w[4] << 8) | (ulong)w[6]; + Keys[i][1] = ((ulong)w[1] << 24) | ((ulong)w[3] << 16) + | ((ulong)w[5] << 8) | (ulong)w[7]; + + } +} + + + + + +#if MSC +#define ror4(x) _lrotr(x, 4) +#define rol1(x) _lrotl(x, 1) + +#else +#define ror4(x) ((x) >> 4 | (x) << 28) +#define rol1(x) ((x) << 1 | (x) >> 31) + +#endif + + +#if SMALL +uchar Sboxes[8][64] = { + { + 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, + 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, + 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, + 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, + }, + { + 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, + 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, + 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, + 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, + }, + { + 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, + 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, + 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, + 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, + }, + { + 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, + 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, + 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, + 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, + }, + { + 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, + 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, + 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, + 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, + }, + { + 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, + 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, + 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, + 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, + }, + { + 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, + 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, + 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, + 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, + }, + { + 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, + 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, + 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, + 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11, + }, +}; + +ulong Ptbl[8][16] = { + { + 0x00000000, 0x00000002, 0x00000200, 0x00000202, + 0x00008000, 0x00008002, 0x00008200, 0x00008202, + 0x00800000, 0x00800002, 0x00800200, 0x00800202, + 0x00808000, 0x00808002, 0x00808200, 0x00808202, + }, + { + 0x00000000, 0x00004000, 0x40000000, 0x40004000, + 0x00000010, 0x00004010, 0x40000010, 0x40004010, + 0x00080000, 0x00084000, 0x40080000, 0x40084000, + 0x00080010, 0x00084010, 0x40080010, 0x40084010, + }, + { + 0x00000000, 0x04000000, 0x00000004, 0x04000004, + 0x00010000, 0x04010000, 0x00010004, 0x04010004, + 0x00000100, 0x04000100, 0x00000104, 0x04000104, + 0x00010100, 0x04010100, 0x00010104, 0x04010104, + }, + { + 0x00000000, 0x80000000, 0x00400000, 0x80400000, + 0x00001000, 0x80001000, 0x00401000, 0x80401000, + 0x00000040, 0x80000040, 0x00400040, 0x80400040, + 0x00001040, 0x80001040, 0x00401040, 0x80401040, + }, + { + 0x00000000, 0x20000000, 0x00000080, 0x20000080, + 0x00040000, 0x20040000, 0x00040080, 0x20040080, + 0x01000000, 0x21000000, 0x01000080, 0x21000080, + 0x01040000, 0x21040000, 0x01040080, 0x21040080, + }, + { + 0x00000000, 0x00002000, 0x00200000, 0x00202000, + 0x00000008, 0x00002008, 0x00200008, 0x00202008, + 0x10000000, 0x10002000, 0x10200000, 0x10202000, + 0x10000008, 0x10002008, 0x10200008, 0x10202008, + }, + { + 0x00000000, 0x02000000, 0x00000400, 0x02000400, + 0x00100000, 0x02100000, 0x00100400, 0x02100400, + 0x00000001, 0x02000001, 0x00000401, 0x02000401, + 0x00100001, 0x02100001, 0x00100401, 0x02100401, + }, + { + 0x00000000, 0x00000800, 0x00020000, 0x00020800, + 0x00000020, 0x00000820, 0x00020020, 0x00020820, + 0x08000000, 0x08000800, 0x08020000, 0x08020800, + 0x08000020, 0x08000820, 0x08020020, 0x08020820, + }, +}; + +#define ps(i, j) Ptbl[i][Sboxes[i][j]] + +#else /* MIDDLE */ + +ulong Psboxes[8][64] = { + { + 0x00808200, 0x00000000, 0x00008000, 0x00808202, + 0x00808002, 0x00008202, 0x00000002, 0x00008000, + 0x00000200, 0x00808200, 0x00808202, 0x00000200, + 0x00800202, 0x00808002, 0x00800000, 0x00000002, + 0x00000202, 0x00800200, 0x00800200, 0x00008200, + 0x00008200, 0x00808000, 0x00808000, 0x00800202, + 0x00008002, 0x00800002, 0x00800002, 0x00008002, + 0x00000000, 0x00000202, 0x00008202, 0x00800000, + 0x00008000, 0x00808202, 0x00000002, 0x00808000, + 0x00808200, 0x00800000, 0x00800000, 0x00000200, + 0x00808002, 0x00008000, 0x00008200, 0x00800002, + 0x00000200, 0x00000002, 0x00800202, 0x00008202, + 0x00808202, 0x00008002, 0x00808000, 0x00800202, + 0x00800002, 0x00000202, 0x00008202, 0x00808200, + 0x00000202, 0x00800200, 0x00800200, 0x00000000, + 0x00008002, 0x00008200, 0x00000000, 0x00808002, + }, + { + 0x40084010, 0x40004000, 0x00004000, 0x00084010, + 0x00080000, 0x00000010, 0x40080010, 0x40004010, + 0x40000010, 0x40084010, 0x40084000, 0x40000000, + 0x40004000, 0x00080000, 0x00000010, 0x40080010, + 0x00084000, 0x00080010, 0x40004010, 0x00000000, + 0x40000000, 0x00004000, 0x00084010, 0x40080000, + 0x00080010, 0x40000010, 0x00000000, 0x00084000, + 0x00004010, 0x40084000, 0x40080000, 0x00004010, + 0x00000000, 0x00084010, 0x40080010, 0x00080000, + 0x40004010, 0x40080000, 0x40084000, 0x00004000, + 0x40080000, 0x40004000, 0x00000010, 0x40084010, + 0x00084010, 0x00000010, 0x00004000, 0x40000000, + 0x00004010, 0x40084000, 0x00080000, 0x40000010, + 0x00080010, 0x40004010, 0x40000010, 0x00080010, + 0x00084000, 0x00000000, 0x40004000, 0x00004010, + 0x40000000, 0x40080010, 0x40084010, 0x00084000, + }, + { + 0x00000104, 0x04010100, 0x00000000, 0x04010004, + 0x04000100, 0x00000000, 0x00010104, 0x04000100, + 0x00010004, 0x04000004, 0x04000004, 0x00010000, + 0x04010104, 0x00010004, 0x04010000, 0x00000104, + 0x04000000, 0x00000004, 0x04010100, 0x00000100, + 0x00010100, 0x04010000, 0x04010004, 0x00010104, + 0x04000104, 0x00010100, 0x00010000, 0x04000104, + 0x00000004, 0x04010104, 0x00000100, 0x04000000, + 0x04010100, 0x04000000, 0x00010004, 0x00000104, + 0x00010000, 0x04010100, 0x04000100, 0x00000000, + 0x00000100, 0x00010004, 0x04010104, 0x04000100, + 0x04000004, 0x00000100, 0x00000000, 0x04010004, + 0x04000104, 0x00010000, 0x04000000, 0x04010104, + 0x00000004, 0x00010104, 0x00010100, 0x04000004, + 0x04010000, 0x04000104, 0x00000104, 0x04010000, + 0x00010104, 0x00000004, 0x04010004, 0x00010100, + }, + { + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x00401040, 0x80400040, 0x80400000, 0x80001000, + 0x00000000, 0x00401000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00400040, 0x80400000, + 0x80000000, 0x00001000, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x80001000, 0x00001040, + 0x80400040, 0x80000000, 0x00001040, 0x00400040, + 0x00001000, 0x00401040, 0x80401040, 0x80000040, + 0x00400040, 0x80400000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00000000, 0x00401000, + 0x00001040, 0x00400040, 0x80400040, 0x80000000, + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x80401040, 0x80000040, 0x80000000, 0x00001000, + 0x80400000, 0x80001000, 0x00401040, 0x80400040, + 0x80001000, 0x00001040, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x00001000, 0x00401040, + }, + { + 0x00000080, 0x01040080, 0x01040000, 0x21000080, + 0x00040000, 0x00000080, 0x20000000, 0x01040000, + 0x20040080, 0x00040000, 0x01000080, 0x20040080, + 0x21000080, 0x21040000, 0x00040080, 0x20000000, + 0x01000000, 0x20040000, 0x20040000, 0x00000000, + 0x20000080, 0x21040080, 0x21040080, 0x01000080, + 0x21040000, 0x20000080, 0x00000000, 0x21000000, + 0x01040080, 0x01000000, 0x21000000, 0x00040080, + 0x00040000, 0x21000080, 0x00000080, 0x01000000, + 0x20000000, 0x01040000, 0x21000080, 0x20040080, + 0x01000080, 0x20000000, 0x21040000, 0x01040080, + 0x20040080, 0x00000080, 0x01000000, 0x21040000, + 0x21040080, 0x00040080, 0x21000000, 0x21040080, + 0x01040000, 0x00000000, 0x20040000, 0x21000000, + 0x00040080, 0x01000080, 0x20000080, 0x00040000, + 0x00000000, 0x20040000, 0x01040080, 0x20000080, + }, + { + 0x10000008, 0x10200000, 0x00002000, 0x10202008, + 0x10200000, 0x00000008, 0x10202008, 0x00200000, + 0x10002000, 0x00202008, 0x00200000, 0x10000008, + 0x00200008, 0x10002000, 0x10000000, 0x00002008, + 0x00000000, 0x00200008, 0x10002008, 0x00002000, + 0x00202000, 0x10002008, 0x00000008, 0x10200008, + 0x10200008, 0x00000000, 0x00202008, 0x10202000, + 0x00002008, 0x00202000, 0x10202000, 0x10000000, + 0x10002000, 0x00000008, 0x10200008, 0x00202000, + 0x10202008, 0x00200000, 0x00002008, 0x10000008, + 0x00200000, 0x10002000, 0x10000000, 0x00002008, + 0x10000008, 0x10202008, 0x00202000, 0x10200000, + 0x00202008, 0x10202000, 0x00000000, 0x10200008, + 0x00000008, 0x00002000, 0x10200000, 0x00202008, + 0x00002000, 0x00200008, 0x10002008, 0x00000000, + 0x10202000, 0x10000000, 0x00200008, 0x10002008, + }, + { + 0x00100000, 0x02100001, 0x02000401, 0x00000000, + 0x00000400, 0x02000401, 0x00100401, 0x02100400, + 0x02100401, 0x00100000, 0x00000000, 0x02000001, + 0x00000001, 0x02000000, 0x02100001, 0x00000401, + 0x02000400, 0x00100401, 0x00100001, 0x02000400, + 0x02000001, 0x02100000, 0x02100400, 0x00100001, + 0x02100000, 0x00000400, 0x00000401, 0x02100401, + 0x00100400, 0x00000001, 0x02000000, 0x00100400, + 0x02000000, 0x00100400, 0x00100000, 0x02000401, + 0x02000401, 0x02100001, 0x02100001, 0x00000001, + 0x00100001, 0x02000000, 0x02000400, 0x00100000, + 0x02100400, 0x00000401, 0x00100401, 0x02100400, + 0x00000401, 0x02000001, 0x02100401, 0x02100000, + 0x00100400, 0x00000000, 0x00000001, 0x02100401, + 0x00000000, 0x00100401, 0x02100000, 0x00000400, + 0x02000001, 0x02000400, 0x00000400, 0x00100001, + }, + { + 0x08000820, 0x00000800, 0x00020000, 0x08020820, + 0x08000000, 0x08000820, 0x00000020, 0x08000000, + 0x00020020, 0x08020000, 0x08020820, 0x00020800, + 0x08020800, 0x00020820, 0x00000800, 0x00000020, + 0x08020000, 0x08000020, 0x08000800, 0x00000820, + 0x00020800, 0x00020020, 0x08020020, 0x08020800, + 0x00000820, 0x00000000, 0x00000000, 0x08020020, + 0x08000020, 0x08000800, 0x00020820, 0x00020000, + 0x00020820, 0x00020000, 0x08020800, 0x00000800, + 0x00000020, 0x08020020, 0x00000800, 0x00020820, + 0x08000800, 0x00000020, 0x08000020, 0x08020000, + 0x08020020, 0x08000000, 0x00020000, 0x08000820, + 0x00000000, 0x08020820, 0x00020020, 0x08000020, + 0x08020000, 0x08000800, 0x08000820, 0x00000000, + 0x08020820, 0x00020800, 0x00020800, 0x00000820, + 0x00000820, 0x00020020, 0x08000000, 0x08020800, + }, +}; + +#define ps(i, j) Psboxes[i][j] + +#endif /* SMALL */ + +#if ASSEMBLY + +extern void des_crypt(); + +#else + +unsigned long Ip_l[] = { + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, +}; +unsigned long Ip_r[] = { + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, +}; +unsigned long Ip_inv_l[] = { + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, +}; +unsigned long Ip_inv_r[] = { + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, +}; + + +void des_crypt(char *block, int dflag) +{ + ulong l, r, l2, r2; + uchar *s; + int i; + + /* Initial Transpose */ + s = (uchar *)block; + l = (((((((Ip_l[s[0]] >> 1 + | Ip_l[s[1]]) >> 1 + | Ip_l[s[2]]) >> 1 + | Ip_l[s[3]]) >> 1 + | Ip_l[s[4]]) >> 1 + | Ip_l[s[5]]) >> 1 + | Ip_l[s[6]]) >> 1 + | Ip_l[s[7]]); + r = (((((((Ip_r[s[0]] >> 1 + | Ip_r[s[1]]) >> 1 + | Ip_r[s[2]]) >> 1 + | Ip_r[s[3]]) >> 1 + | Ip_r[s[4]]) >> 1 + | Ip_r[s[5]]) >> 1 + | Ip_r[s[6]]) >> 1 + | Ip_r[s[7]]); + + if (dflag == 0) { + for (i = 0; i < 16; i++) { + ulong v, x1, x2; + + /* E-transpose, Xor, S-box and P-transpose */ + x1 = rol1(r); + x2 = ror4(x1) ^ Keys[i][0]; + x1 ^= Keys[i][1]; + v = l ^ ps(7, x1 & 0x3f) + ^ ps(5, (x1 >> 8) & 0x3f) + ^ ps(3, (x1 >> 16) & 0x3f) + ^ ps(1, (x1 >> 24) & 0x3f) + ^ ps(6, x2 & 0x3f) + ^ ps(4, (x2 >> 8) & 0x3f) + ^ ps(2, (x2 >> 16) & 0x3f) + ^ ps(0, (x2 >> 24) & 0x3f); + l = r; + r = v; + } + } else { + for (i = 16; --i >= 0; ) { + ulong v, x1, x2; + + /* E-transpose, Xor, S-box and P-transpose */ + x1 = rol1(r); + x2 = ror4(x1) ^ Keys[i][0]; + x1 ^= Keys[i][1]; + v = l ^ ps(7, x1 & 0x3f) + ^ ps(5, (x1 >> 8) & 0x3f) + ^ ps(3, (x1 >> 16) & 0x3f) + ^ ps(1, (x1 >> 24) & 0x3f) + ^ ps(6, x2 & 0x3f) + ^ ps(4, (x2 >> 8) & 0x3f) + ^ ps(2, (x2 >> 16) & 0x3f) + ^ ps(0, (x2 >> 24) & 0x3f); + l = r; + r = v; + } + } + /* Final transpose */ + l2 = (((((((Ip_inv_l[r & 0xff] >> 1 + | Ip_inv_l[l & 0xff]) >> 1 + | Ip_inv_l[r>>8 & 0xff]) >> 1 + | Ip_inv_l[l>>8 & 0xff]) >> 1 + | Ip_inv_l[r>>16 & 0xff]) >> 1 + | Ip_inv_l[l>>16 & 0xff]) >> 1 + | Ip_inv_l[r>>24 & 0xff]) >> 1 + | Ip_inv_l[l>>24 & 0xff]); + r2 = (((((((Ip_inv_r[r & 0xff] >> 1 + | Ip_inv_r[l & 0xff]) >> 1 + | Ip_inv_r[r>>8 & 0xff]) >> 1 + | Ip_inv_r[l>>8 & 0xff]) >> 1 + | Ip_inv_r[r>>16 & 0xff]) >> 1 + | Ip_inv_r[l>>16 & 0xff]) >> 1 + | Ip_inv_r[r>>24 & 0xff]) >> 1 + | Ip_inv_r[l>>24 & 0xff]); + *block++ = (char)(l2 >> 24); + *block++ = (char)(l2 >> 16); + *block++ = (char)(l2 >> 8); + *block++ = (char)l2; + *block++ = (char)(r2 >> 24); + *block++ = (char)(r2 >> 16); + *block++ = (char)(r2 >> 8); + *block++ = (char)r2; +} +#endif /* ASSEMBLY */ + + +int ecb_crypt(char *key, char *buf, unsigned len, unsigned mode) +{ + des_setkey(key); + for (len = (len + 7) & ~7; len != 0; buf += 8, len -= 8) + des_crypt(buf, mode & DES_DIRMASK); + return ((mode & DES_DEVMASK) == DES_SW ? DESERR_NONE + : DESERR_NOHWDEVICE); +} + + +int cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec) +{ + char nvec[8]; + + des_setkey(key); + switch (mode & DES_DIRMASK) { + case DES_ENCRYPT: + for (len = (len + 7) & ~7; len != 0; len -= 8) { + buf[0] ^= ivec[0]; + buf[1] ^= ivec[1]; + buf[2] ^= ivec[2]; + buf[3] ^= ivec[3]; + buf[4] ^= ivec[4]; + buf[5] ^= ivec[5]; + buf[6] ^= ivec[6]; + buf[7] ^= ivec[7]; + des_crypt(buf, DES_ENCRYPT); + ivec[0] = *buf++; + ivec[1] = *buf++; + ivec[2] = *buf++; + ivec[3] = *buf++; + ivec[4] = *buf++; + ivec[5] = *buf++; + ivec[6] = *buf++; + ivec[7] = *buf++; + } + break; + case DES_DECRYPT: + for (len = (len + 7) & ~7; len != 0; len -= 8) { + nvec[0] = buf[0]; + nvec[1] = buf[1]; + nvec[2] = buf[2]; + nvec[3] = buf[3]; + nvec[4] = buf[4]; + nvec[5] = buf[5]; + nvec[6] = buf[6]; + nvec[7] = buf[7]; + des_crypt(buf, DES_DECRYPT); + *buf++ ^= ivec[0]; + *buf++ ^= ivec[1]; + *buf++ ^= ivec[2]; + *buf++ ^= ivec[3]; + *buf++ ^= ivec[4]; + *buf++ ^= ivec[5]; + *buf++ ^= ivec[6]; + *buf++ ^= ivec[7]; + ivec[0] = nvec[0]; + ivec[1] = nvec[1]; + ivec[2] = nvec[2]; + ivec[3] = nvec[3]; + ivec[4] = nvec[4]; + ivec[5] = nvec[5]; + ivec[6] = nvec[6]; + ivec[7] = nvec[7]; + } + break; + } + return ((mode & DES_DEVMASK) == DES_SW ? DESERR_NONE + : DESERR_NOHWDEVICE); +} diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.h b/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.h new file mode 100644 index 0000000..5b9ca13 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/descrypt.h @@ -0,0 +1,43 @@ +/* + * DES encryption/decryption library interface + * + * Written by Koichiro Mori (kmori@lsi-j.co.jp) + */ + +#define DES_DIRMASK 001 +#define DES_ENCRYPT (0 * DES_DIRMASK) +#define DES_DECRYPT (1 * DES_DIRMASK) + +#define DES_DEVMASK 002 +#define DES_HW (0 * DES_DEVMASK) +#define DES_SW (1 * DES_DEVMASK) + +#define DESERR_NONE 0 +#define DESERR_NOHWDEVICE 1 +#define DESERR_HWERROR 2 +#define DESERR_BADPARAM 3 + +#define DES_FAILED(err) ((err) > DESERR_NOHWDEVICE) + +//#if __STDC__ || LSI_C + +int ecb_crypt(char *key, char *buf, unsigned len, unsigned mode); +int cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec); +void des_setparity(char *key); + +/* Not defined by Sun Microsystems - internally used by desbench program */ +void des_setkey(char *key); +void des_crypt(char *buf, int dflag); +/* +#else + + int ecb_crypt(); + int cbc_crypt(); + void des_setparity(); + +// Not defined by Sun Microsystems - internally used by desbench program + void des_setkey(); + void des_crypt(); + +#endif // __STDC__ || LSI_C +*/ \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/message.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/message.cpp new file mode 100644 index 0000000..fe3f7ed --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/message.cpp @@ -0,0 +1,431 @@ +/*----------------------------------------------- + Message.cpp -- Message format definition + (c) ʤCary Hsu, 1999.8.18 +-----------------------------------------------*/ +#include +#include "../systeminc/version.h" +#include "Message.h" +#include "descrypt.h" + +//DWORD dwCafeKey=0; + +//for AnalyzeMessage() +enum +{ + ZERO, + READHEAD, + READLEN, + READPARAM, + GETHEAD +}; + +int iEncrypt=E_INIT; +Parameter *messNewTailParam; +MessNode *messNew; +MessNode *messHead; +MessNode *messTail; +//ѶϢʽʱʹ +int iFormatLen; //ѶϢʽij,DWORDΪλ +int iNumStart=0; +char szFormatBuf[1024]; +//ʱʹ +char szAnalyzeBuf[1024]; +int nState; +BOOL backslash; +BOOL bAnd; +int indexBuf; +int nParamCounter; + +extern TCHAR P_Key[]; +extern TCHAR szPid[]; + +const DWORD RET_OK=1; +const DWORD RET_MEMORY=2; +const DWORD RET_PARAM=3; + +#ifdef _OMIT_WGS +LPTSTR O_WGS_Format() +{ + szFormatBuf[0]='&'; + szFormatBuf[1]=';'; + szFormatBuf[2]='0'; + szFormatBuf[3]=';'; + szFormatBuf[4]='Q'; + szFormatBuf[5]=';'; + iFormatLen = 6; + return szFormatBuf; +} +#endif + +inline void StartFormat() +{ + szFormatBuf[0]='&'; + szFormatBuf[1]=';'; + lstrcpy(szFormatBuf+2,szPid); + iNumStart=lstrlen(szPid)+2; + szFormatBuf[iNumStart++]=';'; + szFormatBuf[iNumStart++]='0'; + szFormatBuf[iNumStart++]='0'; + szFormatBuf[iNumStart++]='0'; + szFormatBuf[iNumStart]='1'; + szFormatBuf[iNumStart+1]=';'; + iFormatLen=iNumStart+2; +} + +inline void FinishFormat() +{ + int j; + if((j=iFormatLen & 0x07)>0){ + for(;j<8;j++) + szFormatBuf[iFormatLen++]='&'; + } +} + +inline void FormatAdd() +{ + char *ch=&szFormatBuf[iNumStart]; + (*ch)++; + if(*ch>'9'){ + *ch='0'; + if((*(ch-=1)+=1)>'9'){ + *ch='0'; + if((*(ch-=1)+=1)>'9'){ + *ch='0'; + if((*(ch-=1)+=1)>'9') + *ch=szFormatBuf[3]=szFormatBuf[4]=szFormatBuf[5]='9'; + } + } + } +} + +void AddParamForFormat(LPSTR lpstr,int iLen,DWORD flag) +{ + if(flag & FORMAT_START) + StartFormat(); + for(int j=0;jlpstrParam) + delete[] param->lpstrParam; + delete param; +} + +inline void LinkParamToMessNew(Parameter *paramNew) +{ + if(messNewTailParam) + { + messNewTailParam->next=paramNew; + messNewTailParam=paramNew; + } + else + messNew->param=messNewTailParam=paramNew; +} + +inline void LinkMessNewToMessTail() +{ + if(messTail) + { + messTail->next=messNew; + messTail=messNew; + } + else + messTail=messHead=messNew; + messNew=NULL; + messNewTailParam=NULL; +} + +inline void ReleaseMessNew() +{ + register Parameter *paramTemp; + if(messNew) + { + while(messNew->param) + { + paramTemp=messNew->param->next; + ReleaseParam(messNew->param); + messNew->param=paramTemp; + } + delete messNew; + messNew=NULL; + messNewTailParam=NULL; + } +} + +inline DWORD HandleZero(LPSTR &lpstr,int &iStrLen) +{ + indexBuf=0; + nParamCounter=0; + backslash=FALSE; + bAnd=FALSE; + nState=READHEAD; + + if(messNew=new MessNode) + return RET_OK; + return RET_MEMORY; +} + +inline void HandleHead(LPSTR &lpstr,int &iStrLen) +{ + char ch; + while(iStrLen-- > 0) + { + if(bAnd) + { + if(';'==(ch=*lpstr++)) + { + bAnd=FALSE; + nState=READLEN; + return; + } + else if('&'!=ch) + bAnd=FALSE; + } + else + { + if('&'==*lpstr++) + bAnd=TRUE; + } + } +} + +inline DWORD HandleLen(LPSTR &lpstr,int &iStrLen) +{ + char ch; + while(iStrLen-- > 0) + { + if(';'==(ch=*lpstr++)) + { + szAnalyzeBuf[indexBuf]='\0'; + nParamCounter=atoi(szAnalyzeBuf); + if(!nParamCounter) + { + nState=ZERO; + return RET_PARAM; + } + messNew->nParam=(nParamCounter-=1); + indexBuf=0; + nState=READPARAM; + return RET_OK; + } + szAnalyzeBuf[indexBuf++]=ch; + if(indexBuf>5) + { + nState=ZERO; + return RET_PARAM; + } + } + return RET_OK; +} + +inline DWORD HandleParam(LPSTR &lpstr,int &iStrLen) +{ + char ch; + while(iStrLen-- > 0) + { + if(backslash) + { + backslash=FALSE; + szAnalyzeBuf[indexBuf++]=*lpstr++; + } + else + { + if(';'==(ch=*lpstr++)) + { + Parameter *paramNew=NULL; + szAnalyzeBuf[indexBuf++]='\0'; + if((paramNew=new Parameter) && (paramNew->lpstrParam=new char[indexBuf+1])) + { + paramNew->next=NULL; + CopyMemory(paramNew->lpstrParam,szAnalyzeBuf,indexBuf); + paramNew->lpstrParam[indexBuf]='\0'; + paramNew->iLen=indexBuf-1; + LinkParamToMessNew(paramNew); + } + else + { + if(paramNew) + delete paramNew; + ReleaseMessNew(); + return RET_MEMORY; + } + if(--nParamCounter<=0) + { + LinkMessNewToMessTail(); + nState=ZERO; + return RET_OK; + } + indexBuf=0; + } + else + { + if('\\'==ch) + backslash=TRUE; + else if('&'==ch) + { + ReleaseMessNew(); + nState=ZERO; + return RET_PARAM; + } + else + szAnalyzeBuf[indexBuf++]=ch; + } + } + } + return RET_OK; +} + +DWORD AnalyzeMessage(LPSTR lpstr,int iStrLen) +{ + if(0param)){ + paramTemp=messHead->param->next; + ReleaseParam(messHead->param); + messHead->param=paramTemp; + } + return paramTemp; +} + +void RemoveMessHead() +{ + register Parameter *paramTemp; + MessNode *messTemp; + if(messHead) + { + messTemp=messHead->next; + while(messHead->param) + { + paramTemp=messHead->param->next; + ReleaseParam(messHead->param); + messHead->param=paramTemp; + } + delete messHead; + if(!messTemp) + messTail=NULL; + messHead=messTemp; + } +} + +void ReleaseMessList() +{ + ReleaseMessNew(); + nState=ZERO; + MessNode *messTemp; + register Parameter *paramTemp; + while(messHead) + { + messTemp=messHead->next; + while(messHead->param) + { + paramTemp=messHead->param->next; + ReleaseParam(messHead->param); + messHead->param=paramTemp; + } + delete messHead; + messHead=messTemp; + } + messTail=NULL; +} + +DWORD GetCafeNumber() +{ + HANDLE hFileMapping=NULL; + LPSTR lpstr=NULL; + DWORD Id=0; +#ifdef _NEW_EARTH + if (hFileMapping = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, "vup2u4fu.6")) + { + int *pFlag; + + if (pFlag = (int*)MapViewOfFile(hFileMapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0)) + Id = *pFlag; + CloseHandle(hFileMapping); + } +#else + char szTemp[64]; + if(hFileMapping=OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,FALSE,"f; enc ")){ + if(lpstr=(LPSTR)MapViewOfFile(hFileMapping,FILE_MAP_READ | FILE_MAP_WRITE,0,0,0)){ + strcpy(szTemp,lpstr); + ecb_crypt("lbgorj/",szTemp,8,DES_DECRYPT); + UnmapViewOfFile((LPVOID)lpstr); + Id=atoi(szTemp); + } + CloseHandle(hFileMapping); + } +#endif + return Id; +} diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/message.h b/石器时代8.5客户端最新源代码/石器源码/wgs/message.h new file mode 100644 index 0000000..8d01aa4 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/message.h @@ -0,0 +1,177 @@ +/*----------------------------------------------- + Message.h -- Message format definition + (c) ʤCary Hsu, 1999.8.18 + +----+------------+------------------+ + |name|Data len'\0'| Data | + |1B | 5 Byte | 0~4090B | + +----+------------+------------------+ +-----------------------------------------------*/ +#ifndef __MESSAGE +#define __MESSAGE + +#include +// Message name +#define M_NULL '@' +#define M_ECHO 'A' +#define M_HELO 'H' // H ID CodingData +#define M_HELO1 'I' // H ID CodingData +#define M_HELO2 'J' // H ID CodingData +#define M_REDI 'R' // R 202.52.121.208:10000 pid +#define M_MESG 'M' +#define M_ERRO 'E' // (E Error) or E ID +#define M_SKEY 'S' // S 1234567 +#define M_LOAD 'L' // L +#define M_ACKN 'K' // K ID CodingData +#define M_DATA 'D' // D ID SaveData +#define M_GOTO 'G' // G 202.52.121.208 +#define M_LINE 'N' // N SubMessage +#define M_GAME '(' // M GameMessage +#define M_PKEY 'T' +#define M_CONT 'U' + +// SubMessage +#define A_SEND 'T' // A_SEND string \0 +#define A_WHISPER 'W' // A_WHISPER player \n string \0 +#define A_QUERY 'P' // A_QUERY PlayerName \0 +#define A_NEW 'N' // A_NEW description \0 +#define A_QUIT 'Q' // A_QUIT \0 +#define A_KICK 'K' // A_KICK \0 +#define A_START 'S' // A_START \0 +#define A_GAMEOVER 'G' // A_GAMEOVER PlayerName \n score \0 +#define A_JOIN 'J' // A_JOIN PlayerName \0 +#define A_REFRESH 'R' // A_REFRESH \0 +//#define A_CLIENT 'C' // A_CLIENT \0 +#define A_ENTER 'E' // A_ENTER RoomName \0 +#define A_EXIT 'X' // A_EXIT \0 +#define A_ERROR 'Z' +// +#define B_PLAYER 'y' // B_PLAYER numPlayer \n state \n PlayerName \n ..... \0 +#define B_DESK 'd' // B_DESK numDesk \n state \n DealerName \n description \n ...... \0 +#define B_ROOM 'r' // B_ROOM numRoom \n numUser \n Name \n ......\0 +#define B_SEND 't' // B_SEND PlayerName:string \0 +#define B_WHISPER 'w' // B_WHISPER PlayerName:string \0 +#define B_QUERY 'p' // B_QUERY string \0 +#define B_NEW 'n' // B_NEW Y \0 or B_NEW N cause \0 +#define B_QUIT 'q' // B_QUIT \0 +#define B_SOMEONE 'o' // B_SOMEONE PlayerName \n IP \0 +#define B_KICK 'k' // B_KICK \0 +#define B_START 's' // B_START \0 +#define B_GAMEOVER 'g' // B_GAMEOVER numChart \n PlayerName \n score \n ...... \0 +#define B_JOIN 'j' // B_JOIN Y IP \0 or B_JOIN N cause \0 +//#define B_CLIENT 'c' // B_CLIENT \0 +#define B_ENTER 'e' // B_ENTER Y \0 or B_ENTER N cause \0 +#define B_EXIT 'x' // B_EXIT Y \0 or B_EXIT N cause \0 +#define B_ERROR 'z' +// Game Message +#define S_NEWGAME 'N' // S_NEW parameter +#define S_GAMEOVER 'O' // S_GAMEOVER +#define S_BORNDICE 'B' +#define S_WAVEFLAG 'W' +#define S_RAISECOUNT 'R' //for RaiseCount +#define S_JiaYiu 'J' //forJiaYiuCount +#define S_CLIENTKEY 'C' //for ParamSav +#define S_SERVERKEY 'S' +#define S_WANTOVER 'A' +#define S_ECHO 'E' +#define S_TOKEN 'T' +// +#define C_NEW 'n' // C_NEW +#define C_ECHO 'e' +#define C_CANSEND 'x' + + +//#ifdef _STONDEBUG_ +#define NO_WGS //ʹWGS֤ +//#endif + +struct Parameter +{ + char *lpstrParam; + int iLen; + Parameter *next; + Parameter(){ + lpstrParam=NULL; + next=NULL;} +}; + +struct MessNode +{ + int nParam; + Parameter *param; + MessNode *next; + MessNode(){ + param=NULL; + next=NULL;} +}; + +enum +{ + WGS=1, + CS, + GS +}; + +//state of encrypt or decrypt +enum +{ + E_INIT, + E_ECB, + E_NO +}; + +#define FORMAT_APPEND 0x00 +#define FORMAT_START 0x01 +#define FORMAT_FINISH 0x02 +#define FORMAT_ONLYONE 0x03 + +#ifdef _BACK_VERSION //// +#define SZ_ECB "9304001" //Ʒ +#else +#ifdef _PK_SERVER +#define SZ_ECB "9306001" +#else +#define SZ_ECB "8904001" +#endif +#endif + +extern const DWORD RET_OK; +extern const DWORD RET_MEMORY; +extern const DWORD RET_PARAM; + +extern MessNode *messNew; +extern MessNode *messHead; +extern MessNode *messTail; + +extern DWORD dwServer; +extern int iWGS; +extern TCHAR szWGS[]; +extern WORD wWGS; +extern TCHAR szCSIP[]; +extern WORD wCS; +extern TCHAR szError[1024]; + +void AddParamForFormat(LPSTR lpstr,int iLen,DWORD flag); +void AddParamForFormat(char ch,DWORD flag); +LPTSTR GetString(int &iLen,LPTSTR lpstrEncrypt); +DWORD AnalyzeMessage(LPSTR lpstr,int iStrLen); +Parameter *ReleaseMessHeadParam(); +void RemoveMessHead(); +void ReleaseMessList(); +BOOL GetIP_PORT(Parameter *param); +void GetEncrypt(Parameter *param); +void PKey_Init(); +void ReleaseSendData(); +void ipAddressAnalyze( ); + +BOOL ReadWGSMessage(LPSTR lpstr,int &iStrLen); +void DoHellow(); +void DoSKey(); +#ifdef _OMIT_WGS +void testtest(); +LPTSTR O_WGS_Format(); +#endif +DWORD GetCafeNumber(); +#ifdef NO_WGS +void SetTestServer(); +#endif +#endif \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/reproc.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/reproc.cpp new file mode 100644 index 0000000..6040880 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/reproc.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include "../systeminc/version.h" +/* +HANDLE hProcessSnap = NULL; +DWORD dwPID; + +void CloseParentProcess() +{ + PROCESSENTRY32 pe32; + HANDLE hParentProcess; + dwPID = GetCurrentProcessId(); + if( INVALID_HANDLE_VALUE != (hProcessSnap=CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL))){ + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + if( Process32First( hProcessSnap, &pe32)){ + do{ + if( pe32.th32ProcessID == dwPID){ + if( hParentProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ParentProcessID)){ +// MessageBoxNew( NULL, "ҵ", "ѰҸʽ", MB_OK); + TerminateProcess( hParentProcess, 0); + CloseHandle( hParentProcess); + } + break; + } + }while( Process32Next( hProcessSnap, &pe32)); + } + CloseHandle( hProcessSnap); + } +} + +*/ \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/tea.cpp b/石器时代8.5客户端最新源代码/石器源码/wgs/tea.cpp new file mode 100644 index 0000000..b0e069b --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/tea.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "tea.h" +#include "../systeminc/VMProtectSDK.h" +unsigned long DELTA=0x9e3779b9; +#define MX (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (k[p&3^e]^z); +long TEA(long* v, long n, long* k) +{ +#ifdef _VMP_ + VMProtectBegin("teajiami"); +#endif + unsigned long z,y,sum,e; + z=v[n-1]; + y=v[0]; + sum=0; + long p, q; + /* ܹ */ + q = 6 + 52/n; + while (q-- > 0) + { + sum += DELTA; + e = (sum >> 2) & 3; + for (p=0; p> 2) & 3; + for (p=n-1; p>0; p--) + z = v[p-1], y = v[p] -= MX; + z = v[n-1]; y = v[0] -= MX; + sum -= DELTA; + } + return 0; +} + diff --git a/石器时代8.5客户端最新源代码/石器源码/wgs/tea.h b/石器时代8.5客户端最新源代码/石器源码/wgs/tea.h new file mode 100644 index 0000000..99abba3 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/wgs/tea.h @@ -0,0 +1,2 @@ +long TEA(long* v, long n, long* k); +long TEA(long* v, long n, long* k); diff --git a/石器时代8.5客户端最新源代码/石器源码/石器源码.suo b/石器时代8.5客户端最新源代码/石器源码/石器源码.suo new file mode 100644 index 0000000..377ce48 Binary files /dev/null and b/石器时代8.5客户端最新源代码/石器源码/石器源码.suo differ diff --git a/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj new file mode 100644 index 0000000..aa6a843 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj @@ -0,0 +1,556 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + VER25_DEBUG + Win32 + + + VER25_RELEASE + Win32 + + + VER_TW_Debug + Win32 + + + VER_TW_Release + Win32 + + + VER + Win32 + + + _TW_SERVER_DEBUG + Win32 + + + _TW_SERVER_RELEASE + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {7BCA4759-A8C8-4746-ABD8-C2B4C3C2DEFE} + Win32Proj + 石器源码 + + + + Application + true + MultiByte + v120 + + + Application + true + MultiByte + v100 + + + Application + true + MultiByte + v100 + + + Application + true + MultiByte + v120_xp + + + Application + false + true + MultiByte + v100 + + + Application + false + true + MultiByte + v100 + + + Application + false + true + MultiByte + v100 + + + Application + false + true + MultiByte + v120_xp + + + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa + + + true + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa25 + F:\石器时代\7-sa\ + + + true + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + saex + ..\..\石器时代-复刻版 + + + true + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa + ..\..\saex + + + false + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa + ..\..\石器时代-重制版 + + + false + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa25 + F:\7-sa\ + $(Configuration)\ + + + false + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + saex + ..\..\石器时代-复刻版 + + + false + .\openssl;.\mylua\lua;.\curl;$(IncludePath) + .\mylua\lua;.\sdk;$(LibraryPath) + sa + ..\..\saex + + + + + + TurnOffAllWarnings + Disabled + WIN32;NDEBUG;_WINDOWS;DI_2;_DEBUG__;_SA_VERSION_SPECIAL;_SA_VERSION_182;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + + + Windows + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;%(AdditionalDependencies) + /NODEFAULTLIB:msvcrt.lib %(AdditionalOptions) + false + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + G:\台式数据\石器HK\sa.exe + + + + + + + + + + + TurnOffAllWarnings + Disabled + WIN32;_WINDOWS;DI_2;_SA_VERSION_25;_DEBUG__;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + + + Windows + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;%(AdditionalDependencies) + false + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + F:\7-sa\sa25.exe + + + + + + + + + + + TurnOffAllWarnings + Disabled + WIN32;_WINDOWS;DI_2;_TW_SERVER_;_DEBUG__;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + + + Windows + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;%(AdditionalDependencies) + false + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + + + + + + + + + + + TurnOffAllWarnings + Disabled + WIN32;_WINDOWS;DI_2;_TW_SERVER_;_DEBUG__;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + + + Windows + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;%(AdditionalDependencies) + false + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + LeakDetector;%(AdditionalLibraryDirectories) + + + + + + + + + TurnOffAllWarnings + Disabled + true + true + WIN32;NDEBUG;_WINDOWS;DI_2;_SA_VERSION_SPECIAL;_SA_VERSION_182;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + Sync + MultiThreaded + + + true + true + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;dbghelp.lib;%(AdditionalDependencies) + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + false + $(OutDir)$(TargetName)$(TargetExt) + + + + + + TurnOffAllWarnings + Disabled + true + true + WIN32;_WINDOWS;DI_2;_SA_VERSION_25;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + Sync + MultiThreaded + + + true + true + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;dbghelp.lib;%(AdditionalDependencies) + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + false + F:\7-sa\sa25.exe + + + + + + TurnOffAllWarnings + Disabled + true + true + WIN32;_WINDOWS;DI_2;_TW_SERVER_;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + Sync + MultiThreaded + + + true + true + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;dbghelp.lib;%(AdditionalDependencies) + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + false + + + + + + TurnOffAllWarnings + MaxSpeed + true + true + WIN32;_WINDOWS;DI_2;_TW_SERVER_;_SA_VERSION_SPECIAL;%(PreprocessorDefinitions) + lua;%(AdditionalIncludeDirectories) + Sync + MultiThreaded + + + false + true + true + odbc32.lib;odbccp32.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;imm32.lib;dinput.lib;wsock32.lib;caryIme.lib;GetMacAddress.lib;lua51.lib;dbghelp.lib;%(AdditionalDependencies) + LIBC.lib;msvcrt.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + false + LeakDetector;%(AdditionalLibraryDirectories) + + + + + + + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.filters b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.filters new file mode 100644 index 0000000..5051f48 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.filters @@ -0,0 +1,595 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {72911117-d973-49aa-9117-473efef02155} + + + {d7100c24-4a4b-4b5d-8822-11afff0f4fba} + + + {5bf32498-8a50-4b06-a511-77709be73520} + + + {d3fa6e03-20c0-432c-9719-faa29ff67a79} + + + {eeb42c62-9ab6-40d0-8083-e07daf666292} + + + {7492c248-40d4-4cbe-b2fe-6d5628a56aec} + + + {4a02ec63-4e41-49df-bf00-ba2b3f7e1e6c} + + + {ec85f1e6-33b8-44b2-8a6f-f4fe8c63d432} + + + {57a83dd7-7eec-44de-910d-9e9000bf3bc4} + + + {d7dc1f68-9a37-42c9-8b01-8748304d71ad} + + + {b61f6141-e94b-456d-8477-8ef77edef122} + + + {f590bc36-ff3d-43f9-abcf-66404ce861f4} + + + {25d72ef7-761e-4684-9c25-6a368c533e2e} + + + {fd5cde2a-2c32-407e-a59c-3071cf350dc3} + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件\mylua + + + 头文件\mylua + + + 头文件\protocol + + + 头文件\protocol + + + 头文件\wgs + + + 头文件\wgs + + + 头文件\wgs + + + 头文件\oft + + + 头文件\oft + + + 头文件\oft + + + 头文件\oft + + + 头文件\ohta + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\other + + + 头文件\wgs + + + 头文件 + + + 头文件\detours + + + 头文件\detours + + + 头文件\detours + + + 资源文件 + + + 头文件\other + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件\mylua + + + 源文件\mylua + + + 源文件\mylua + + + 源文件\mylua + + + 源文件\mylua + + + 源文件\mylua + + + 源文件\protocol + + + 源文件\protocol + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件\wgs + + + 源文件\wgs + + + 源文件\wgs + + + 源文件\wgs + + + 源文件\wgs + + + 源文件\oft + + + 源文件\oft + + + 源文件\oft + + + 源文件\oft + + + 源文件\oft + + + 源文件\ohta + + + 源文件\ohta + + + 源文件\other + + + 源文件\other + + + 源文件\other + + + 源文件\other + + + 源文件\other + + + 源文件\other + + + 源文件\wgs + + + 源文件 + + + 源文件\detours + + + 源文件\detours + + + 源文件\detours + + + 源文件\detours + + + 源文件\detours + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 资源文件 + + + 资源文件 + + + 资源文件 + + + + + 资源文件 + + + \ No newline at end of file diff --git a/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.user b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.user new file mode 100644 index 0000000..9681f02 --- /dev/null +++ b/石器时代8.5客户端最新源代码/石器源码/石器源码.vcxproj.user @@ -0,0 +1,50 @@ + + + + G:\台式数据\石器HK-使用版\sa.exe + + + OpenClient + + + G:\台式数据\石器HK-使用版 + WindowsLocalDebugger + + + G:\台式数据\石器HK\sa.exe + WindowsLocalDebugger + OpenClient + G:\台式数据\石器HK + + + G:\台式数据\石器HK\sa.exe + + + G:\台式数据\石器HK + WindowsLocalDebugger + + + F:\7-sa\sa25.exe + + + G:\台式数据\石器TW\saex.exe + + + F:\7-sa\ + WindowsLocalDebugger + OpenClient + + + G:\台式数据\石器TW + WindowsLocalDebugger + OpenClient + + + F:\7-sa\sa25.exe + + + F:\7-sa + WindowsLocalDebugger + OpenClient + + \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv.zip b/石器时代服务器端最新完整源代码/Serv.zip new file mode 100644 index 0000000..ff003ca Binary files /dev/null and b/石器时代服务器端最新完整源代码/Serv.zip differ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/.cproject b/石器时代服务器端最新完整源代码/Serv/gmsv/.cproject new file mode 100644 index 0000000..df79596 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/.cproject @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/.project b/石器时代服务器端最新完整源代码/Serv/gmsv/.project new file mode 100644 index 0000000..5be350d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/.project @@ -0,0 +1,27 @@ + + + gmsv-0925 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/language.settings.xml b/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/language.settings.xml new file mode 100644 index 0000000..f8142bb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/language.settings.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/org.eclipse.core.resources.prefs b/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..bb29a1d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=GBK diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/all b/石器时代服务器端最新完整源代码/Serv/gmsv/all new file mode 100755 index 0000000..f6de954 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/all @@ -0,0 +1,8 @@ +./vip_21.sh +./vip_30.sh +./vip_33.sh +./vip_35.sh +./vip_36.sh +./vip_37.sh +./vip_40.sh +./vip_44.sh diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/all.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/all.sh new file mode 100644 index 0000000..f6de954 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/all.sh @@ -0,0 +1,8 @@ +./vip_21.sh +./vip_30.sh +./vip_33.sh +./vip_35.sh +./vip_36.sh +./vip_37.sh +./vip_40.sh +./vip_44.sh diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/autil.c b/石器时代服务器端最新完整源代码/Serv/gmsv/autil.c new file mode 100644 index 0000000..cb1de39 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/autil.c @@ -0,0 +1,588 @@ +// Arminius' protocol utilities ver 0.1 +// +// Any questions and bugs, mailto: arminius@mail.hwaei.com.tw + +// ------------------------------------------------------------------- +// The following definitions is to define game-dependent codes. +// Before compiling, remove the "//". +#define __STONEAGE +#include "version.h" +#include +#include +#include "autil.h" +#include "char.h" +#ifdef __STONEAGE +#include "lssproto_util.h" +#include "common.h" +#endif + +// Nuke 0701 fix +char *MesgSlice[SLICE_MAX]; +int SliceCount; + +char PersonalKey[4096]; + +// ------------------------------------------------------------------- +// Initialize utilities +// +BOOL util_Init( void) +{ + int i; + + for (i=0; i=0)) { + ptr[0] = '\0'; + if (strlen(head)= 65) { b = (src[i] - 65 + 10); } + else { b = src[i] - 48; } + if (i % 2) + { + tmp = tmp + b; + dst[i / 2] = tmp; + } + else + { + tmp = b <<4; + } + } + dst[strlen(dst)]=0; +} + +unsigned long DELTA=0x9e3779b9; +#define MX (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (k[p&3^e]^z); +long DecodeTea(long* v, long n, long* k) +{ + unsigned long z,y,sum,e; + z=v[n-1]; + y=v[0]; + sum=0; + long p, q; + q = 6 + 52/n; + sum = q*DELTA; + while(sum != 0) + { + e = (sum >> 2) & 3; + for (p=n-1; p>0; p--) + z = v[p-1], y = v[p] -= MX; + z = v[n-1]; y = v[0] -= MX; + sum -= DELTA; + } + return 0; +} +BOOL util_DecodeMessageTea(char *dst,char *sac) +{ + int len = strlen(sac)/2; + if (sac[0]=='\0') return FALSE; + if(len/4 <= 0 ) return FALSE; + + hexstrtostring(dst,sac); + DecodeTea((long*)dst,len/4,(long *)DENGLUKEY1); + return TRUE; +} +#endif + +void util_DecodeMessage(char *dst, char *src) +{ +// strcpy(dst, src); +// util_xorstring(dst, src); + +#define INTCODESIZE (sizeof(int)*8+5)/6 + + int rn; + int *t1, t2; + char t3[4096], t4[4096]; // This buffer is enough for an integer. + char tz[65500]; + if (src[strlen(src)-1]=='\n') src[strlen(src)-1]='\0'; + util_xorstring(tz, src); + + // get seed + strncpy(t4, tz, INTCODESIZE); + t4[INTCODESIZE] = '\0'; + util_64to256(t3, t4, DEFAULTTABLE); + t1 = (int *) t3; + t2 = *t1 ^ 0xffffffff; + util_swapint(&rn, &t2, "3142"); + + util_shrstring(dst, tz + INTCODESIZE, rn); +} + +// ------------------------------------------------------------------- +// Get a function information from MesgSlice. A function is a complete +// and identifiable message received, beginned at DEFAULTFUNCBEGIN and +// ended at DEFAULTFUNCEND. This routine will return the function ID +// (Action ID) and how many fields this function have. +// +// arg: func=return function ID fieldcount=return fields of the function +// ret: 1=success 0=failed (function not complete) +int util_GetFunctionFromSlice(int *func, int *fieldcount) +{ + char t1[16384]; + int i; + +// if (strcmp(MesgSlice[0], DEFAULTFUNCBEGIN)!=0) util_DiscardMessage(); + + strcpy(t1, MesgSlice[1]); + // Robin adjust +#ifdef _VERSION_NEW + *func=atoi(t1) - 13; +#else +#ifdef _VERSION_80 + *func=atoi(t1) - 13; +#else + *func=atoi(t1); +#endif +#endif + for (i=0; i func(%d)\n", file, line, func); + return; + } +#ifdef _VERSION_NEW + sprintf(t1, "&;%d%s;#;", func+23, buffer); +#else +#ifdef _VERSION_80 + sprintf(t1, "&;%d%s;#;", func+23, buffer); +#else + sprintf(t1, "&;%d%s;#;", func, buffer); +#endif +#endif + util_EncodeMessage(t2, t1); +#ifdef __STONEAGE + lssproto_Send(fd, t2); +#endif + +} + +int util_256to64(char *dst, char *src, int len, char *table) +{ + unsigned int dw,dwcounter,i; + + if (!dst || !src || !table) return 0; + dw=0; + dwcounter=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ dw & 0x3f ]; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ dw ]; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Convert 6-bit strings into 8-bit strings, buffers that store these strings +// must have enough space. +// +// arg: dst=6-bit string; src=8-bit string; table=mapping table +// ret: 0=failed >0=bytes converted +int util_64to256(char *dst, char *src, char *table) +{ + unsigned int dw,dwcounter,i; + char *ptr = NULL; + + dw=0; + dwcounter=0; + if (!dst || !src || !table) return 0; + for (i=0; i> 8; + } else { + dw = (unsigned int)(ptr-table) & 0x3f; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// This basically is a 256to64 encoder. But it shifts the result by key. +// +// arg: dst=6-bit string; src=8-bit string; len=src strlen; +// table=mapping table; key=rotate key; +// ret: 0=failed >0=bytes converted +int util_256to64_shr(char *dst, char *src, int len, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j; + + if (!dst || !src || !table || !key) return 0; + if (strlen(key)<1) return 0; // key can't be empty. + dw=0; + dwcounter=0; + j=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ ((dw & 0x3f) + key[j]) % 64 ];// check! + j++; if (!key[j]) j=0; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ (dw + key[j]) % 64 ]; // check! + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Decoding function of util_256to64_shr. +// +// arg: dst=8-bit string; src=6-bit string; table=mapping table; +// key=rotate key; +// ret: 0=failed >0=bytes converted +int util_shl_64to256(char *dst, char *src, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j; + char *ptr = NULL; + + if (!key || (strlen(key)<1)) return 0; // must have key + + dw=0; + dwcounter=0; + j=0; + if (!dst || !src || !table) return 0; + for (i=0; i> 8; + } else { + // check! + dw = (((unsigned int)(ptr-table) & 0x3f) + 64 - key[j]) % 64; + j++; if (!key[j]) j=0; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// This basically is a 256to64 encoder. But it shifts the result by key. +// +// arg: dst=6-bit string; src=8-bit string; len=src strlen; +// table=mapping table; key=rotate key; +// ret: 0=failed >0=bytes converted +int util_256to64_shl(char *dst, char *src, int len, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j; + + if (!dst || !src || !table || !key) return 0; + if (strlen(key)<1) return 0; // key can't be empty. + dw=0; + dwcounter=0; + j=0; + for (i=0; i> 6 ); + if (i%3==2) { + dst[ dwcounter++ ] = table[ ((dw & 0x3f) + 64 - key[j]) % 64 ]; // check! + j++; if (!key[j]) j=0; + dw = 0; + } + } + if (dw) dst[ dwcounter++ ] = table[ (dw + 64 - key[j]) % 64 ]; // check! + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Decoding function of util_256to64_shl. +// +// arg: dst=8-bit string; src=6-bit string; table=mapping table; +// key=rotate key; +// ret: 0=failed >0=bytes converted +int util_shr_64to256(char *dst, char *src, char *table, char *key) +{ + unsigned int dw,dwcounter,i,j; + char *ptr = NULL; + + if (!key || (strlen(key)<1)) return 0; // must have key + + dw=0; + dwcounter=0; + j=0; + if (!dst || !src || !table) return 0; + for (i=0; i> 8; + } else { + // check! + dw = (((unsigned int)(ptr-table) & 0x3f) + key[j]) % 64; + j++; if (!key[j]) j=0; + } + } + if (dw) dst[ dwcounter++ ] = dw & 0xff; + dst[ dwcounter ] = '\0'; + return dwcounter; +} + +// ------------------------------------------------------------------- +// Swap a integer (4 byte). +// The value "rule" indicates the swaping rule. It's a 4 byte string +// such as "1324" or "2431". +// +void util_swapint(int *dst, int *src, char *rule) +{ + char *ptr, *qtr; + int i; + + ptr = (char *) src; + qtr = (char *) dst; + for (i=0; i<4; i++) qtr[rule[i]-'1']=ptr[i]; +} + +// ------------------------------------------------------------------- +// Xor a string. Be careful that your string contains '0xff'. Your +// data may lose. +// +void util_xorstring(char *dst, char *src) +{ + int i; + if (strlen(src)>65500) return; + + for (i=0; i +#include +#include +#include "buf.h" +#include"object.h" +#include"char.h" +#include"char_base.h" +#include"char_data.h" +#include"battle.h" +#include"battle_event.h" +#include"battle_command.h" +#include"battle_ai.h" +#include"configfile.h" +#include"lssproto_serv.h" +#include"encount.h" +#include"enemy.h" +#include"handletime.h" +#include"readmap.h" +#include"pet_skill.h" +#include "npcutil.h" +#include "magic.h" +#include "npc_npcenemy.h" +#include "log.h" +#include "pet_skillinfo.h" +#include "anim_tbl.h" +#include "common.h" +#include "battle_magic.h" +#include "lssproto_serv.h" +#ifdef _Item_ReLifeAct +#include "item.h" +#endif +#ifdef _TRADE_PK +#include "trade.h" +#endif +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#include "npc_healer.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#include "skill.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#include "mylua/mylua.h" +extern MY_Lua MYLua; +#endif + +#ifdef _ABSOLUTE_DEBUG +extern int debugline; +extern int comnum; +#endif + +//#define DANTAI +static int Total_BattleNum=0; +BATTLE *BattleArray; +int BATTLE_battlenum; +static int BATTLE_searchCnt = 0; + +#ifdef _PET_LIMITLEVEL //ANDY_ADD + void Pet_Check_Die( int petindex); +#endif +static int BATTLE_SearchTask( void ); +static int BATTLE_Battling( int battleindex ); + +#ifdef _Item_ReLifeAct + BOOL CHECK_ITEM_RELIFE( int battleindex, int toindex); +#endif +#ifdef _LOSE_FINCH_ + BOOL CHECK_PET_RELIFE( int battleindex, int petindex); +#endif +char szAllBattleString[BATTLE_STRING_MAX]; +#ifdef _OTHER_MAGICSTAUTS +void BATTLE_MagicStatusSeq( int charaindex ); +#endif + +//Terry 2001/11/28 +char szBattleString[1024]; +char *pszBattleTop, + *pszBattleLast; + +char szBadStatusString[1024]; + +int gWeponType; +float gDamageDiv; +int gItemCrushRate = 400000; +int BoomerangVsTbl[4][5] = { + { 4+5*0,2+5*0,0+5*0,1+5*0,3+5*0 }, + { 4+5*1,2+5*1,0+5*1,1+5*1,3+5*1 }, + { 4+5*2,2+5*2,0+5*2,1+5*2,3+5*2 }, + { 4+5*3,2+5*3,0+5*3,1+5*3,3+5*3 }, + +}; + +BOOL BATTLE_CHECKINDEX( int battleindex ) +{ + if(battleindex>=BATTLE_battlenum || battleindex<0 )return FALSE; + + return BattleArray[battleindex].use; +} + +void BATTLE_BadStatusAllClr( int charaindex ) +{ + int i ; + for( i = 1; i < BATTLE_ST_END; i ++ ){ + CHAR_setWorkInt( charaindex, StatusTbl[i], 0 ); + } +#ifdef _OTHER_MAGICSTAUTS + for( i = 1; i < MAXSTATUSTYPE; i++ ){ + CHAR_setWorkInt( charaindex, MagicTbl[i], 0); + CHAR_setWorkInt( charaindex, CHAR_OTHERSTATUSNUMS, 0); + } +#endif +#ifdef _IMPRECATE_ITEM + for( i=0; i<3; i++) { + CHAR_setWorkInt( charaindex, CHAR_WORKIMPRECATENUM1+i, 0 ); + } +#endif + +#ifdef _PETSKILL_SETDUCK + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCK, 0); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER, 0 ); +#ifdef _MAGICPET_SKILL + CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTR, 0); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTRPOWER, 0 ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGH, 0); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGHPOWER, 0 ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEX, 0); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEXPOWER, 0 ); + CHAR_setWorkInt( charaindex, CHAR_MAGICPETMP, 0 ); +#endif +#endif +#ifdef _STRENGTH_PETSKILL + CHAR_setWorkInt( charaindex, CHAR_WORK_STRENGTH, 0 ); +#endif +#ifdef _LOSTLOST_PETSKILL + CHAR_setWorkInt( charaindex, CHAR_WORK_LOSTLOST, 0 ); +#endif +#ifdef _PETSKILL_NEW_PASSIVE + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_DUCK, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_ACURATE, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_CRITICAL, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_COUNTER, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_MULTIPLE, 0); +#endif + CHAR_setFlg( charaindex, CHAR_ISDIE, 0 ); +#ifdef _BATTLE_PROPERTY + { + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return; + strcpysafe( ch->charfunctable[CHAR_BATTLEPROPERTY].string, + sizeof( ch->charfunctable[CHAR_BATTLEPROPERTY]), "");//ս + CHAR_constructFunctable( charaindex); + } +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_P_DUCK, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKMOD_P_DUCK, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_WEAPON, 0 ); // ר + + // 翹 + for( i=0; i<3; i++) + CHAR_setWorkInt( charaindex, CHAR_WORK_F_RESIST+i, 0/*CHAR_getInt( charaindex, PROFESSION_FIRE_R+i )*/ ); + +#endif + +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) + { + for( i =0; i < CHAR_MAXPETHAVE; i++){ + int pindex = CHAR_getCharPet( charaindex, i ); + if( !CHAR_CHECKINDEX( pindex ) ) + continue; + CHAR_setInt( pindex, CHAR_BECOMEPIG, -1 ); + } + } +#endif + +} + +int BATTLE_getTopBattle( int battleindex ) +{ + + BATTLE *pBattleTop; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return -1; + + pBattleTop = &BattleArray[battleindex]; + + while( pBattleTop != NULL ){ + pBattleTop = BattleArray[battleindex].pBefore; + } + + if( BATTLE_CHECKINDEX( pBattleTop->battleindex ) == FALSE ){ + return -1; + }else{ + return pBattleTop->battleindex; + } +} + +static int BATTLE_getBattleFieldNo( int floor, int x, int y ) +{ + int tile[2], map[3], iRet; + if( !MAP_getTileAndObjData( floor, x, y, &tile[0], &tile[1] ) ) + return FALSE; + map[0] = MAP_getImageInt( tile[0], MAP_BATTLEMAP ); + map[1] = MAP_getImageInt( tile[0], MAP_BATTLEMAP2 ); + map[2] = MAP_getImageInt( tile[0], MAP_BATTLEMAP3 ); + iRet = map[RAND( 0, 2 )]; + return iRet; +} + +void BATTLE_BadStatusString( int defNo, int status ) +{ + char szWork[256]; + if( status < 1 || status >= BATTLE_ST_END ){ + status = 0; + } + sprintf( szWork, "BM|%X|%X|", defNo, status ); + strncat( szBadStatusString, szWork, sizeof( szBadStatusString ) ); +} + + + +#ifdef _ATTACK_MAGIC + +static int CharTableIdx[20][2] = +{ + { 3 , 2 } , { 3 , 1 } , { 3 , 3 } , { 3 , 0 } , { 3 , 4 } , + { 2 , 2 } , { 2 , 1 } , { 2 , 3 } , { 2 , 0 } , { 2 , 4 } , + { 0 , 2 } , { 0 , 1 } , { 0 , 3 } , { 0 , 0 } , { 0 , 4 } , + { 1 , 2 } , { 1 , 1 } , { 1 , 3 } , { 1 , 0 } , { 1 , 4 } + +}; + +typedef int ( *FUNCSORTLOC )( const void* , const void* ); + +static int SortLoc( const int *pEle1 , const int *pEle2 ) +{ + int ele1basex , ele1basey; + int ele2basex , ele2basey; + + ele1basex = CharTableIdx[*pEle1][1]; + ele1basey = CharTableIdx[*pEle1][0]; + ele2basex = CharTableIdx[*pEle2][1]; + ele2basey = CharTableIdx[*pEle2][0]; + + if( *pEle1 >= 10 ){ + if( ele1basey != ele2basey ) + return ( ele1basey - ele2basey ); + return ( ele1basex - ele2basex ); + }else{ // · + if( ele1basey != ele2basey ) + return ( ele2basey - ele1basey ); + return ( ele2basex - ele1basey ); + } + return 0; +} +#endif + +int BATTLE_MultiList( int battleindex, int toNo, int ToList[] ) +{ + int j , i , cnt=0,nLife = 0,nLifeArea[10]; +#ifdef _ATTACK_MAGIC + // ˹ + if(0 <= toNo && toNo <= 19){ + memset(nLifeArea,-1,sizeof(nLifeArea)); + // · + if(toNo >= 0 && toNo <= 9){ + for(i=0;i<10;i++){ + // ȷŵ,¼ŵ˵ĺ + if(BATTLE_TargetCheck(battleindex,i) == TRUE) nLifeArea[nLife++] = i; + } + } + // Ϸ + if(toNo >= 10 && toNo <= 19){ + for(i=10;i<20;i++){ + // ȷŵ,¼ŵ˵ĺ + if(BATTLE_TargetCheck(battleindex,i) == TRUE) nLifeArea[nLife++] = i; + } + } + + // ȫ(Ȼ̫,..) + if(nLife == 0){ + print("\nAll die!!"); + return -1; + }else{ + // ĶѾս + if(BATTLE_TargetCheck(battleindex,toNo) == FALSE) + // һֻ + while((toNo = nLifeArea[rand()%10]) == -1); + } + ToList[0] = toNo; + ToList[1] = -1; + cnt = 1; + } + // һй + else if( TARGET_SIDE_0_B_ROW == toNo ){ + for( j = 0 , i = 0 ; i < SIDE_OFFSET / 2 ; i++ ){ + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ){ + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // һŶû˿Դ + if(j == 0){ + // ǰһ + for( j = 0 , i = SIDE_OFFSET / 2 ; i < SIDE_OFFSET ; i++ ){ + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ){ + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // ȫ + if(j == 0) return -1; + toNo = TARGET_SIDE_0_F_ROW; + } + } + // ǰһй + else if( TARGET_SIDE_0_F_ROW == toNo ) + { + for( j = 0 , i = SIDE_OFFSET / 2 ; i < SIDE_OFFSET ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // һŶû˿Դ + if(j == 0) + { + // һ + for( j = 0 , i = 0 ; i < SIDE_OFFSET / 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // ȫ + if(j == 0) return -1; + toNo = TARGET_SIDE_0_B_ROW; + } + } + // һй + else if( TARGET_SIDE_1_B_ROW == toNo ) + { + for( j = 0 , i = SIDE_OFFSET ; i < SIDE_OFFSET + SIDE_OFFSET / 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // һŶû˿Դ + if(j == 0) + { + // ǰһ + for( j = 0 , i = SIDE_OFFSET + SIDE_OFFSET / 2 ; i < SIDE_OFFSET * 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // ȫ + if(j == 0) return -1; + toNo = TARGET_SIDE_1_F_ROW; + } + } + // ǰһй + else if( TARGET_SIDE_1_F_ROW == toNo ) + { + for( j = 0 , i = SIDE_OFFSET + SIDE_OFFSET / 2 ; i < SIDE_OFFSET * 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // һŶû˿Դ + if(j == 0) + { + // һ + for( j = 0 , i = SIDE_OFFSET ; i < SIDE_OFFSET + SIDE_OFFSET / 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + ToList[j] = -1; + cnt = j; + // ȫ + if(j == 0) return -1; + toNo = TARGET_SIDE_1_B_ROW; + } + } + // ·й + else if( TARGET_SIDE_0 == toNo ) + { + //print("BATTLE_MultiList(20)toNo->%d\n",toNo); + for( j = 0 , i = 0 ; i < SIDE_OFFSET ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + + ToList[j] = -1; + cnt = j; + } + // Ϸй + else if( toNo == TARGET_SIDE_1 ) + { + for( j = 0 , i = SIDE_OFFSET ; i < SIDE_OFFSET * 2 ; i++ ) + { + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ) + { + ToList[j] = i; + j++; + } + } + + ToList[j] = -1; + cnt = j; + } + // ˹ + else if( toNo == TARGET_ALL ){ +#ifdef _FIX_ARRAYBUG + for( j = 0 , i = 0 ; i < SIDE_OFFSET * 2 ; i++ ){ +#else + for( j = 0 , i = 0 ; i < SIDE_OFFSET * 2 ; i++ , j++ ) { +#endif + if( TRUE == BATTLE_TargetCheck( battleindex , i ) ){ + ToList[j] = i; + j++; + } + } + ToList[i] = -1; + cnt = j; + // won add ǰŹ + }else if( toNo == TARGER_THROUGH ){ + int toNo2=-1, count=0; + + if(BATTLE_TargetCheck(battleindex,toNo) != FALSE){ + ToList[count] = toNo; + count++; + cnt = count; + } + + if( toNo < (SIDE_OFFSET/2) ) toNo2= toNo + (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET) ) toNo2= toNo - (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET*1.5) ) toNo2= toNo + (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET*2) ) toNo2= toNo - (SIDE_OFFSET/2); + + if(BATTLE_TargetCheck(battleindex,toNo2) != FALSE){ + ToList[count] = toNo2; + count++; + cnt = count; + } + }else{ + ToList[0] = toNo; + ToList[1] = -1; + cnt = 1; + } + + if( cnt > 1 ) qsort( ToList , cnt , sizeof( ToList[0] ) , ( FUNCSORTLOC )SortLoc ); + return toNo; + +#else + if( 0 <= toNo && toNo <= 19 ) + { + if( BATTLE_TargetCheck( battleindex, toNo ) == TRUE ) + { + ToList[0] = toNo; + ToList[1] = -1; + cnt = 1; + } + else + { + ToList[0] = -1; + ToList[1] = -1; + cnt = 0; + } + } + else if( toNo == TARGET_SIDE_0 ) + { + for( j = 0, i = 0; i < SIDE_OFFSET; i ++) + { + if( BATTLE_TargetCheck( battleindex, i ) == TRUE ) + { + ToList[j] = i; + j ++ ; + } + } + ToList[j] = -1; + cnt = j; + } + else if( toNo == TARGET_SIDE_1 ) + { + for( j = 0, i = SIDE_OFFSET; i < SIDE_OFFSET*2; i ++ ) + { + if( BATTLE_TargetCheck( battleindex, i ) == TRUE ) + { + ToList[j] = i; + j ++ ; + } + } + ToList[j] = -1; + cnt = j; + } + else if( toNo == TARGET_ALL ){ + for( j = 0, i = 0; i < SIDE_OFFSET*2; i ++, j ++ ){ + if( BATTLE_TargetCheck( battleindex, i ) == TRUE ){ + ToList[j] = i; + j ++ ; + } + } + ToList[i] = -1; + cnt = j; + } + else + { + ToList[0] = toNo; + ToList[1] = -1; + cnt = 1; + } + + return 1; +#endif +} + +void BATTLE_MultiListDead( int battleindex, int toNo, int ToList[] ) +{ + int j, i; + if( 0 <= toNo && toNo <= 19 ){ + if( BATTLE_TargetCheckDead( battleindex, toNo ) == TRUE ){ + ToList[0] = toNo; + ToList[1] = -1; + }else{ + ToList[0] = -1; + ToList[1] = -1; + } + }else + if( toNo == TARGET_SIDE_0 ){ + for( j = 0, i = 0; i < SIDE_OFFSET; i ++){ + if( BATTLE_TargetCheckDead( battleindex, i ) == TRUE ){ + ToList[j] = i; + j ++ ; + } + } + ToList[j] = -1; + }else + if( toNo == TARGET_SIDE_1 ){ + for( j = 0, i = SIDE_OFFSET; i < SIDE_OFFSET*2; i ++ ){ + if( BATTLE_TargetCheckDead( battleindex, i ) == TRUE ){ + ToList[j] = i; + j ++ ; + } + } + ToList[j] = -1; + }else{ + if( toNo == TARGET_ALL ){ +#ifdef _FIX_ARRAYBUG + for( j = 0, i = 0; i < SIDE_OFFSET*2; i ++){ +#else + for( j = 0, i = 0; i < SIDE_OFFSET*2; i ++, j ++ ){ +#endif + if( BATTLE_TargetCheckDead( battleindex, i ) == TRUE ){ + ToList[j] = i; + j ++ ; + } + } +#ifdef _FIX_ITEMRELIFE // WON ADD + ToList[j] = -1; +#else + ToList[i] = -1; +#endif + }else{ + ToList[0] = toNo; + ToList[1] = -1; + } + } +} + +BOOL BATTLE_IsThrowWepon( int itemindex){ + int itemtype; + if( ITEM_CHECKINDEX( itemindex ) == FALSE ){ + return FALSE; + } + itemtype = ITEM_getInt( itemindex, ITEM_TYPE ); + if( itemtype == ITEM_BOOMERANG + || itemtype == ITEM_BOW + || itemtype == ITEM_BREAKTHROW + || itemtype == ITEM_BOUNDTHROW ){ + return TRUE; + }else{ + return FALSE; + } +} + +int BATTLE_ClearGetExp( int charaindex ) +{ + int i, pindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE ){ + return BATTLE_ERR_CHARAINDEX; + } + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, 0 ); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + pindex = CHAR_getCharPet( charaindex, i ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + CHAR_setWorkInt( pindex, CHAR_WORKGETEXP, 0 ); + } + + return 0; +} + +INLINE void _BATTLE_ExitAll( char *file, int line, int battleindex) +{ + int j,i, charaindex; + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[j].Entry[i].charaindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); + BATTLE_Exit( charaindex, battleindex ); + } + } +} + +void BATTLE_AllCharaFinishSet( int battleindex ) +{ + int j,i, charaindex; + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_FINAL ); + } + } +} + +BOOL BATTLE_IsCharge( int charaindex ) +{ + int com; + com = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + if( com == BATTLE_COM_S_CHARGE + || com == BATTLE_COM_S_EARTHROUND1 + || com == BATTLE_COM_S_EARTHROUND0 +#ifdef _PROFESSION_ADDSKILL + || CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) > 0 +#endif + ){ + return TRUE; + } + return FALSE; +} + +void BATTLE_AllCharaCWaitSet( int battleindex ) +{ + int j,i, charaindex; + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + + if( BATTLE_IsCharge( charaindex ) == TRUE ){ + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, + BATTLE_COM_NONE ); + } + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_C_WAIT ); + } + } +} + +void BATTLE_AllCharaWatchWaitSet( int battleindex ) +{ + int i, charaindex; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + != BATTLE_CHARMODE_WATCHINIT + ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_C_WAIT ); + } + } +} + +void BATTLE_SurpriseSet( + int battleindex, + int side +) +{ + BATTLE_ENTRY *pEntry; + int i, charaindex; + + pEntry = BattleArray[battleindex].Side[side].Entry; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } + } + + +} + +BOOL BATTLE_initBattleArray( + int battlenum +) +{ + + int i; + BATTLE_battlenum = battlenum; + + BattleArray = allocateMemory( sizeof( BATTLE ) * BATTLE_battlenum ); + if( BattleArray == NULL ) return FALSE; + for( i = 0 ; i < BATTLE_battlenum ; i ++ ){ + memset( &BattleArray[i], 0 , sizeof( BATTLE )); + } + print(" %4.2f MB ռ...", ((float)sizeof( Char )*BATTLE_battlenum)/1024.0/1024.0); + return TRUE; + +} + +static void EntryInit( BATTLE_ENTRY *pEntry ){ + int i; + pEntry->charaindex = -1; + pEntry->bid = -1; + pEntry->escape = 0; + for( i = 0; i < GETITEM_MAX; i ++ ){ + pEntry->getitem[i] = -1; + } +} + +int BATTLE_CreateBattle( void ) +{ + int battleindex, i, j; + BATTLE *pBattle; + battleindex = BATTLE_SearchTask( ); + // NUKE 0701 + if( battleindex < 0 )return -1; + memset( &BattleArray[battleindex], 0 , sizeof( BATTLE )); + pBattle = &BattleArray[battleindex]; + + // NUKE 0701 + if (pBattle==NULL) return -1; + pBattle->use = TRUE; + pBattle->mode = BATTLE_MODE_INIT; + pBattle->turn = 0; + pBattle->dpbattle = 0; + pBattle->norisk = 0; + pBattle->flg = 0; + pBattle->field_att = BATTLE_ATTR_NONE; + pBattle->att_count = 0; + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + EntryInit( &pBattle->Side[j].Entry[i] ); + } + } + for( i = 0; i < BATTLE_ENTRY_MAX*2; i ++ ){ + pBattle->iEntryBack[i] = -1; + pBattle->iEntryBack2[i] = -1; + } + pBattle->WinFunc = NULL; + pBattle->pNext = NULL; + pBattle->pBefore = NULL; + pBattle->battleindex = battleindex; + Total_BattleNum ++; +#ifdef _BATTLECOMMAND_TIME + pBattle->PartTime = 0; +#endif +#ifdef _PROFESSION_ADDSKILL + // +/* pBattle->ice_count = 0; + for( i = 0; i < 20; i ++ ){ + pBattle->ice_bout[i]=0; + pBattle->ice_use[i]=FALSE; + pBattle->ice_toNo[i]=0; + pBattle->ice_level[i]=0; + pBattle->ice_array[i]=0; + pBattle->ice_attackNo[i]=0; + pBattle->ice_charaindex[i]=-1; + }*/ +#endif +#ifdef _BATTLE_BOUT_TIME + pBattle->tv_sec = NowTime.tv_sec; + pBattle->tv_usec = NowTime.tv_usec; +#endif + return battleindex; +} + +static int BATTLE_SearchTask( void ) +{ + int i, j; + i = BATTLE_searchCnt; + for( j = 0; j < BATTLE_battlenum; j ++ ){ + if( i >= BATTLE_battlenum ) i = 0; + if( BattleArray[i].use == FALSE ){ + BATTLE_searchCnt = i + 1; + return i; + } + i ++; + } + return -1; +} + +void BATTLE_DeleteItem( int battleindex ) +{ + int i, j, k; + BATTLE_ENTRY *pEntry; + + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pEntry = &BattleArray[battleindex].Side[j].Entry[i]; + for( k = 0; k < GETITEM_MAX; k ++ ){ + if( pEntry->getitem[k] >= 0 ){ +// print( "// Ѱ(ȥ)(%d),(%s)\n", pEntry->getitem[k], ITEM_getAppropriateName(pEntry->getitem[k]) ); + ITEM_endExistItemsOne( pEntry->getitem[k] ); + } + } + } + } +} + + +int BATTLE_DeleteBattle( + int battleindex +) +{ + int i, j; + BATTLE *pBattle; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + fprint( "err:battle index error\n" ); + return BATTLE_ERR_BATTLEINDEX; + } + if( BATTLE_WatchUnLink( battleindex ) == FALSE ){ + fprint( "err:battle link \n" ); + } + + pBattle = &BattleArray[battleindex]; + pBattle->use = FALSE; + pBattle->mode = BATTLE_MODE_NONE; + BATTLE_DeleteItem( battleindex ); + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + EntryInit( &pBattle->Side[j].Entry[i] ); + } + } + Total_BattleNum--; + return 0; +} + + +int BATTLE_No2Index( + int battleindex, + int bid +) +{ + BATTLE_ENTRY *pEntry; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -1; + if( BATTLE_CHECKNO( bid ) == FALSE )return -1; + + if( bid >= 10 ){ + pEntry = BattleArray[battleindex].Side[1].Entry; + bid -= SIDE_OFFSET; + }else{ + pEntry = BattleArray[battleindex].Side[0].Entry; + } + if( CHAR_CHECKINDEX( pEntry[bid].charaindex ) == FALSE )return -1; + + return pEntry[bid].charaindex; + +} +#ifdef _Item_ReLifeAct +int BATTLE_getBattleDieIndex( int battleindex, int bid ) +{ + BATTLE_ENTRY *pEntry; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -1; + if( BATTLE_CHECKNO( bid ) == FALSE )return -1; + + if( bid >= 10 ){ + pEntry = BattleArray[battleindex].Side[1].Entry; + bid -= SIDE_OFFSET; + }else{ + pEntry = BattleArray[battleindex].Side[0].Entry; + } + if( CHAR_CHECKINDEX( pEntry[bid].charaindex ) == FALSE )return -1; + if( pEntry[bid].flg & BENT_FLG_ULTIMATE ) return -1; + + return pEntry[bid].charaindex; + +} +#endif + +#ifdef _PROFESSION_ADDSKILL +BOOL BATTLE_BattleUltimate( int battleindex, int bid ) //λDǷ񱻴 +{ + BATTLE_ENTRY *pEntry; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return FALSE; + if( BATTLE_CHECKNO( bid ) == FALSE )return FALSE; + if( bid >= 10 ){ + pEntry = BattleArray[battleindex].Side[1].Entry; + bid -= SIDE_OFFSET; + }else{ + pEntry = BattleArray[battleindex].Side[0].Entry; + } + if( pEntry[bid].flg & BENT_FLG_ULTIMATE ) return FALSE; + else return TRUE; +} +#endif + +int BATTLE_Index2No( + int battleindex, + int charaindex +) +{ + BATTLE_ENTRY *pEntry; + int i, j; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -1; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return -1; + + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + if( pEntry[i].charaindex == charaindex ){ + return i + j * SIDE_OFFSET; + } + } + } + + return -1; + +} + + +char *BATTLE_CharTitle( int charaindex ) +{ + char *pName; + static char Len0Buff[2] = ""; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pName = Len0Buff; + }else{ + pName = CHAR_getChar( charaindex, CHAR_OWNTITLE ); + if( pName[0] == 0 ){ + pName = Len0Buff; + } + } + return pName; +} + + +int BATTLE_CharaBackUp( int battleindex ) +{ + int i, j, k, charaindex; + BATTLE *pBattle; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + return BATTLE_ERR_BATTLEINDEX; + } + + pBattle = &BattleArray[battleindex]; + k = 0; + + for( j = 0; j < 2; j ++ ){ + k = j * SIDE_OFFSET; + for( i = 0; i < BATTLE_ENTRY_MAX/2; i ++ ){ + charaindex = pBattle->Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == TRUE + && CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ){ + pBattle->iEntryBack[k] = pBattle->Side[j].Entry[i].charaindex; + pBattle->iEntryBack2[k] = pBattle->Side[j].Entry[i].charaindex; + }else{ + pBattle->iEntryBack[k] = -1; + pBattle->iEntryBack2[k] = -1; + } + k ++; + } + } + + return 0; +} + + + + +int BATTLE_NewEntry( + int charaindex, + int battleindex, + int side +) +{ + BATTLE_ENTRY *pEntry; + BATTLE *pBattle; + int i, iEntryMax, iEntryFirst; + + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + pBattle = &BattleArray[battleindex]; + + if( pBattle->use == FALSE )return BATTLE_ERR_NOUSE; + + if( side < 0 || side > 1 ){ + return BATTLE_ERR_PARAM; + } + + switch( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) ){ + int work; + + case CHAR_TYPEPLAYER: + if( pBattle->Side[side].type != BATTLE_S_TYPE_PLAYER ){ + return BATTLE_ERR_TYPE; + } + iEntryFirst = 0; + iEntryMax = BATTLE_PLAYER_MAX; + break; + case CHAR_TYPEENEMY: + if( pBattle->Side[side].type != BATTLE_S_TYPE_ENEMY ){ + return BATTLE_ERR_TYPE; + } + iEntryFirst = 0; + iEntryMax = BATTLE_ENTRY_MAX; + break; + case CHAR_TYPEPET: + if( pBattle->Side[side].type != BATTLE_S_TYPE_PLAYER ){ + return BATTLE_ERR_TYPE; + } + + work = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX ); + pEntry = pBattle->Side[side].Entry; + + work = BATTLE_Index2No( battleindex, work ); + work -= side * SIDE_OFFSET; + work += 5; + iEntryFirst = work; + iEntryMax = work+1; + break; +#ifdef _PLAYER_NPC + case CHAR_TYPEPLAYERNPC: + iEntryFirst = 0; + iEntryMax = BATTLE_ENTRY_MAX; + break; + + case CHAR_TYPEPLAYERPETNPC: + work = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX ); + pEntry = pBattle->Side[side].Entry; + + work = BATTLE_Index2No( battleindex, work ); + work -= side * SIDE_OFFSET; + work += 5; + iEntryFirst = work; + iEntryMax = work+1; + break; +#endif + default: + print( "(%s)(%d)\n", + CHAR_getUseName( charaindex ), + CHAR_getInt( charaindex, CHAR_WHICHTYPE ) ); + return BATTLE_ERR_TYPE; + } + + + pEntry = pBattle->Side[side].Entry; + + for( i = iEntryFirst; i < iEntryMax; i ++ ){ + if( pEntry[i].charaindex == -1 )break; + } + + if( i == iEntryMax ){ + return BATTLE_ERR_ENTRYMAX; + } + + EntryInit( &pEntry[i] ); + + pEntry[i].charaindex = charaindex; + + pEntry[i].bid = i + side * SIDE_OFFSET; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, + battleindex ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_INIT ); + + CHAR_setWorkInt( charaindex, CHAR_WORKDBATTLEESCAPE, + 0 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLESIDE, side ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, 0 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM3, -1 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKMODATTACK, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKMODDEFENCE, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKMODQUICK, 0 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKDAMAGEABSROB, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKDAMAGEREFLEC, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKDAMAGEVANISH, 0 ); + + + CHAR_setWorkInt( charaindex, CHAR_WORKMODCAPTURE, 0 ); + + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + + BATTLE_BadStatusAllClr( charaindex ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEWATCH, 0 ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + CHAR_setWorkInt( charaindex, CHAR_WORKTRAP, 0 ); // + BATTLE_ProfessionStatus_init( battleindex, charaindex ); +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + CHAR_setWorkInt( charaindex, CHAR_WORKACUPUNCTURE, 0 );//Ƥ +#endif + +#ifdef _PETSKILL_RETRACE + CHAR_setWorkInt( charaindex, CHAR_WORKRETRACE, 0 );//׷ +#endif + +#ifdef _PETSKILL_BECOMEFOX //ĻʱΪ-1 + CHAR_setWorkInt( charaindex, CHAR_WORKFOXROUND, -1 ); +#endif +#ifdef _PROFESSION_ADDSKILL + // + CHAR_setWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY, 0 ); + CHAR_setWorkInt( charaindex, CHAR_DOOMTIME, 0 );//ĩռ + CHAR_setWorkInt( charaindex, CHAR_WORK_com1, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_toNo, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_mode, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_skill_level, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_array, 0 ); +#endif + return 0; +} + +INLINE int _BATTLE_Exit( char *file, int line, int charaindex ,int battleindex) +{ + BATTLE_ENTRY *pEntry; + int i, j, k; + BATTLE *pBattle; + char szPet[32]; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + return BATTLE_ERR_BATTLEINDEX; + } + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ +#ifdef _BATTLE_OVER_STAR_TIME + int floorid = CHAR_getInt( charaindex, CHAR_FLOOR); + if(floorid == 1042 || floorid == 2032 || floorid == 3032 || floorid ==4032){ + CHAR_setWorkInt(charaindex, CHAR_WORKDBATTLETIME, time(NULL)); + } +#endif +#ifdef _ALLBLUES_LUA_1_4 + BattleFinish(battleindex, charaindex); +#endif + } + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E ){ + BATTLE_ENTRY *pWinEntry; + char token[256]; + pWinEntry = BattleArray[battleindex].Side[0].Entry; + + for( i = 0 ; i < BATTLE_ENTRY_MAX ; i ++ ){ + int winindex = pWinEntry[i].charaindex; + if( CHAR_CHECKINDEX( winindex ) == TRUE ){ + if( CHAR_getInt( winindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + BattleFinishPvEFunction(battleindex, charaindex); + } + } + } + } +#ifdef _ROOKIE_ITEM + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_CheckUserItem( charaindex ); + } +#endif + +#ifdef _PROFESSION_ADDSKILL + CHAR_setWorkInt( charaindex, CHAR_DOOMTIME, 0 );//ĩռ +#endif +#ifdef _PETSKILL_BECOMEFOX // 뿪սʱĻɵıЧ + //print("\nͼ:%s,%d", CHAR_getChar( charaindex, CHAR_NAME), CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)); + + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER) == 101749 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //С + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER) ); + CHAR_setWorkInt( charaindex, CHAR_WORKFOXROUND, -1); + //print("\nȥ:%d",CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)); + } +#endif + +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 + && CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BECOMEPIG_BBI ) ); + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + } +#endif + + +#ifdef _MAGIC_NOCAST // :Ĭ + // WON ADD + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + lssproto_NC_send( getfdFromCharaIndex( charaindex ), 0);//ԭ + CHAR_setWorkInt( charaindex, CHAR_WORKNOCAST, 0); + } +#endif + pBattle = &BattleArray[battleindex]; + if( pBattle->use == FALSE ) + return BATTLE_ERR_NOUSE; + + for( j = 0; j < 2; j ++ ){ + pEntry = pBattle->Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + if( pEntry[i].charaindex != charaindex ) + continue; + pEntry[i].charaindex = -1; + pEntry[i].escape = 0; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_FINAL ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, -1 ); +#ifdef _LOSE_FINCH_ + CHAR_setWorkInt( charaindex, CHAR_WORKSPETRELIFE, 0); +#endif + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + CHAR_endCharOneArray( charaindex ); +#ifdef _PLAYER_NPC + }else if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, -1 ); +{ + CHAR_setInt( charaindex , CHAR_HP ,CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( charaindex , CHAR_MP ,CHAR_getWorkInt( charaindex, CHAR_WORKMAXMP ) ); + for(i = 0 ; i < CHAR_MAXPETHAVE; i ++) { + int petindex = CHAR_getCharPet( charaindex, i); + if( CHAR_CHECKINDEX( petindex) == FALSE ) continue; + CHAR_setFlg( petindex, CHAR_ISDIE, 0); + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + } +} + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + CHAR_setFlg( charaindex, CHAR_ISDIE, FALSE ); + } + BATTLE_BadStatusAllClr( charaindex ); + CHAR_complianceParameter( charaindex ); + CHAR_sendBattleEffect( charaindex, OFF); +#endif + }else if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) != 0){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, -1 ); + CHAR_sendBattleEffect( charaindex, OFF); + } +#endif + +#ifdef _PET_ITEM + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 0) ) ){ + CHAR_sendPetItemData(charaindex,0); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 1) ) ){ + CHAR_sendPetItemData(charaindex,1); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 2) ) ){ + CHAR_sendPetItemData(charaindex,2); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 3) ) ){ + CHAR_sendPetItemData(charaindex,3); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 4) ) ){ + CHAR_sendPetItemData(charaindex,4); + } +#endif + + int petindex = pEntry[i+5].charaindex; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ) + { + +#ifdef _FIX_SPEED_UPLEVEL // WON ADD + // Robin cancel + //if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + //}else + { +#ifdef _OFFLINE_SYSTEM + if( CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE) == 0 ) +#endif + { + unsigned int Dtimes; + unsigned int battletime; + int fd = getfdFromCharaIndex( charaindex ); + if( CONNECT_checkfd( fd ) == TRUE ){ + Dtimes = BattleArray[battleindex].CreateTime; + battletime = (unsigned int)(BattleArray[battleindex].flgTime/100); + + //if( CHAR_getWorkInt( charaindex, CHAR_WORKFLG) & WORKFLG_DEBUGMODE ){ + //}else + { + CheckDefBTime( charaindex, fd, Dtimes, battletime, 10);//lowTimeӳʱ + } + } + } + } +#endif + CHAR_setFlg( charaindex, CHAR_ISDIE, 0 ); + CHAR_setInt( charaindex, CHAR_HP, 1 ); + // CoolFish: Faily PK 2001/8/3 + CHAR_setWorkInt(charaindex, CHAR_WORKFMPKFLAG, -1); + + }else { +#ifdef _BATTLE_TIMESPEED + // Robin cancel +#ifdef _OFFLINE_SYSTEM + if( CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE) == 0 ) +#endif + { + unsigned int Dtimes; + unsigned int battletime; + + int fd = getfdFromCharaIndex( charaindex ); + if( CONNECT_checkfd( fd ) == TRUE ){ + Dtimes = BattleArray[battleindex].CreateTime; + battletime = (unsigned int)(BattleArray[battleindex].flgTime/100); + //if( CHAR_getWorkInt( charaindex, CHAR_WORKFLG) & WORKFLG_DEBUGMODE ) { + //}else + { + CheckDefBTime( charaindex, fd, Dtimes, battletime, 0);//lowTimeӳʱ + } + } + } +#endif + } + if( CHAR_CHECKINDEX( petindex ) == TRUE ){ + pEntry[i+5].charaindex = -1; + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEINDEX, -1 ); + } + BATTLE_BadStatusAllClr( charaindex ); + CHAR_complianceParameter( charaindex ); + CHAR_Skillupsend( charaindex ); + // Robin 0730 + if( CHAR_getWorkInt( charaindex, CHAR_WORKPETFALL) ) + { + CHAR_setWorkInt( charaindex, CHAR_WORKPETFALL, 0 ); + CHAR_setInt( charaindex, CHAR_RIDEPET, -2 ); + } + CHAR_send_P_StatusString( charaindex , + CHAR_P_STRING_HP|CHAR_P_STRING_EXP| + CHAR_P_STRING_MP|CHAR_P_STRING_DUELPOINT| + CHAR_P_STRING_CHARM | + CHAR_P_STRING_EARTH | + CHAR_P_STRING_WATER | + CHAR_P_STRING_FIRE | + CHAR_P_STRING_WIND | + CHAR_P_STRING_RIDEPET + ); + // Robin 0730 + if( CHAR_getInt( charaindex, CHAR_RIDEPET ) == -2 ){ + CHAR_setInt( charaindex, CHAR_RIDEPET, -1 ); + } + for( k = 0; k < CHAR_MAXPETHAVE; k ++ ){ + petindex = CHAR_getCharPet( charaindex, k ); + if( CHAR_CHECKINDEX( petindex ) == FALSE )continue; + if( CHAR_getInt( petindex, CHAR_MAILMODE) != CHAR_PETMAIL_NONE ) continue; + if( CHAR_getFlg( petindex, CHAR_ISDIE ) == TRUE + || CHAR_getInt( petindex, CHAR_HP ) <= 0 ){ + CHAR_setFlg( petindex, CHAR_ISDIE, 0 ); + CHAR_setInt( petindex, CHAR_HP, 1 ); + } + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); +#ifdef _LOSE_FINCH_ + CHAR_setWorkInt( charaindex, CHAR_WORKSPETRELIFE, 0); +#endif +#ifdef _VARY_WOLF + if( CHAR_getInt( petindex, CHAR_BASEBASEIMAGENUMBER) != CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER) ) // Robin fix + { + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( petindex, CHAR_BASEBASEIMAGENUMBER)); + sprintf( szPet, "K%d", k); + CHAR_sendStatusString( charaindex , szPet); + } +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + // + if( CHAR_getWorkInt( petindex, CHAR_WORKOBLIVION ) > 0 ) // Robin fix + { + int pet_no = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + CHAR_setWorkInt( petindex, CHAR_WORKOBLIVION, 0 ); + // + sprintf( szPet, "W%d", pet_no); + CHAR_sendStatusString( charaindex , szPet); + } +#endif + BATTLE_BadStatusAllClr( petindex ); + CHAR_complianceParameter( petindex ); + CHAR_send_K_StatusString( charaindex , k, + CHAR_K_STRING_HP|CHAR_K_STRING_EXP| + CHAR_K_STRING_AI| CHAR_K_STRING_MP | + CHAR_K_STRING_ATK | CHAR_K_STRING_DEF | + CHAR_K_STRING_QUICK | + CHAR_K_STRING_EARTH | + CHAR_K_STRING_WATER | + CHAR_K_STRING_FIRE | + CHAR_K_STRING_WIND + ); + } + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + int flg = 0; + CHAR_setFlg( charaindex, CHAR_ISDUEL, 0); + if( CHAR_getFlg( charaindex, CHAR_ISPARTY)) flg |= CHAR_FS_PARTY; + if( CHAR_getFlg( charaindex, CHAR_ISDUEL)) flg |= CHAR_FS_DUEL; + if( CHAR_getFlg( charaindex, CHAR_ISPARTYCHAT)) flg |= CHAR_FS_PARTYCHAT; + if( CHAR_getFlg( charaindex, CHAR_ISTRADECARD)) flg |= CHAR_FS_TRADECARD; +#ifdef _CHANNEL_MODIFY + if( CHAR_getFlg( charaindex, CHAR_ISTELL)) flg |= CHAR_FS_TELL; + if( CHAR_getFlg( charaindex, CHAR_ISFM)) flg |= CHAR_FS_FM; +#ifdef _VERSION_NEW + if( CHAR_getFlg( charaindex, CHAR_ISOCC)) flg |= CHAR_FS_OCC; +#endif + if( CHAR_getFlg( charaindex, CHAR_ISCHAT)) flg |= CHAR_FS_CHAT; + if( CHAR_getFlg( charaindex, CHAR_ISSAVE)) flg |= CHAR_FS_SAVE; +#ifdef _CHATROOMPROTOCOL +#ifdef _THE_WORLD_SEND + if( CHAR_getFlg( charaindex, CHAR_ISWORLD)) flg |= CHAR_FS_WORLD; +#endif +#ifdef _ONLINE_TALK_IP + if( CHAR_getFlg( charaindex, CHAR_ISTALKIP)) flg |= CHAR_FS_TALKIP; +#endif +#endif +#endif + if( CHAR_getFlg( charaindex, CHAR_AI_MOD)) flg |= CHAR_FS_AI; + + lssproto_FS_send( getfdFromCharaIndex(charaindex), flg); + } + + lssproto_XYD_send( getfdFromCharaIndex(charaindex), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), + CHAR_getInt( charaindex, CHAR_DIR ) ); + } + break; + } + } + CHAR_PartyUpdate( charaindex, CHAR_N_STRING_HP ); + +#ifdef _TIME_TICKET + if( CHAR_CHECKINDEX(charaindex) == TRUE ) + { + int nowtime = time(NULL); + int tickettime = CHAR_getWorkInt( charaindex, CHAR_WORKTICKETTIME); + int totaltime; + char msg[1024]; + if( tickettime > 0 && tickettime < nowtime ) { + //int floor, x, y; + CHAR_talkToCli( charaindex, -1, "ллˡ", CHAR_COLORYELLOW); + if( CHAR_getWorkInt( charaindex, CHAR_WORKTICKETTIMESTART) > 0 ) { + totaltime = nowtime - CHAR_getWorkInt( charaindex, CHAR_WORKTICKETTIMESTART); + sprintf( msg, "볡ʱ%d%d롣", totaltime/60, totaltime%60); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + } + CHAR_setWorkInt( charaindex, CHAR_WORKTICKETTIME, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKTICKETTIMESTART, 0); + /*if( CHAR_getElderPosition( CHAR_getInt( charaindex, CHAR_LASTTALKELDER), &floor, &x, &y ) != TRUE ) { + CHAR_warpToSpecificPoint( charaindex, 1006, 15, 15); + } + else { + CHAR_warpToSpecificPoint( charaindex, floor, x, y); + }*/ + CHAR_warpToSpecificPoint( charaindex, 7001, 41, 6); + } + } +#endif + if( CHAR_CHECKINDEX(charaindex) == TRUE ) + { + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + if(BattleArray[battleindex].type != BATTLE_TYPE_WATCH){ +#ifdef _MAP_HEALERALLHEAL + int floor=CHAR_getInt(charaindex, CHAR_FLOOR); + int i; + for(i=0;i<32;i++){ + if(floor == getMapHeal(i)){ + break; + } + } + if(i < 32 +#ifdef _TRADE_PK + || floor == 50000 +#endif +#ifdef _AUTO_PK + || floor == 20000 +#endif +#ifdef _VIP_POINT_PK + || floor == 11111 + || floor == 22222 + || floor == 33333 + || floor == 44444 +#endif +#ifdef _VIP_ONLINE + || CHAR_getInt(charaindex, CHAR_VIPRIDE) > 0 +#endif +#ifdef _FMPOINT_WELFARE + || (CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) == 1041 && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) == 2031 && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) == 3031 && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) == 4031 && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) +#endif + ) + { + char petsend[3]; + CHAR_setInt( charaindex , CHAR_HP ,CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( charaindex , CHAR_MP ,CHAR_getWorkInt( charaindex, CHAR_WORKMAXMP ) ); + CHAR_setFlg( charaindex, CHAR_ISDIE, 0 ); + for(i = 0 ; i < CHAR_MAXPETHAVE; i ++) { + int petindex = CHAR_getCharPet( charaindex, i); + + if( petindex == -1 ) continue; + + /* ƽҷ¼ */ + if( !CHAR_CHECKINDEX( charaindex ) ) continue; + + /* ʸindexë */ + if( CHAR_CHECKINDEX( petindex) == FALSE ) continue; + + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + + /*--ɷ¶Ʃ--*/ + CHAR_complianceParameter( charaindex ); + sprintf( petsend, "K%d", i ); + CHAR_sendStatusString( charaindex , petsend ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_HP); + } + } +#endif + } + } + } + return BATTLE_ERR_NONE; +} + + +int BATTLE_PetDefaultExit( + int charaindex, + int battleindex +) +{ + int pno, pindex, iRet; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER) return 0; + pno = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + if( pno < 0 )return 0; + pindex = CHAR_getCharPet( charaindex, pno ); + + iRet = BATTLE_Exit( pindex, battleindex ); + + if( iRet ){ + iRet *= -1; + }else{ + return 1; + } + + return iRet; +} + + +int BATTLE_PetDefaultEntry( + int charaindex, + int battleindex, + int side +) +{ + int pindex; + +#if 1 + int pno; + + int ret = 0; + + pno = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + if( pno == -1 ) return 0; + pindex = CHAR_getCharPet( charaindex, pno ); + if( CHAR_CHECKINDEX( pindex ) && + !CHAR_getFlg( pindex, CHAR_ISDIE ) && + CHAR_getInt( pindex, CHAR_HP ) > 0 ) + { + if( BATTLE_NewEntry( pindex, battleindex, side ) ){ + }else{ + ret = 0; + } + } + else { +#ifdef _PLAYER_NPC + if(CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYERNPC) +#endif + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1 ); + } + + return ret; +#else + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + pindex = CHAR_getCharPet( charaindex, i ); + + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + + if( CHAR_getFlg( pindex, CHAR_ISDIE ) == TRUE )continue; + if( CHAR_getInt( pindex, CHAR_HP ) <= 0 )continue; + + if( BATTLE_NewEntry( pindex, battleindex, side ) ){ + }else{ + CHAR_setInt( charaindex, CHAR_DEFAULTPET, i ); + break; + } + } + + if( i == CHAR_MAXPETHAVE ){ + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1 ); + } + return 0; +#endif +} + +int BATTLE_RescueEntry( int charaindex, int toindex ) +{ + int iRet = 0, battleindex, fd, pindex; + char szBuffer[256]=""; + +#ifdef _BATTLE_TIMESPEED + fd = getfdFromCharaIndex( charaindex); + if( CONNECT_checkfd( fd ) == TRUE ){ + if( CONNECT_getBDTime( fd) > time( NULL) ) { + return 1; + } + } +#endif + + battleindex = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEINDEX ); + if( !BATTLE_CHECKINDEX( battleindex) ) return 1; + if( ( fd = getfdFromCharaIndex(charaindex) ) < 0 ) return 1; + + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_FINAL + || CHAR_getWorkInt( toindex, CHAR_WORKBATTLEINDEX ) == -1 ){ + iRet = 1; + } +#ifndef _FIX_P_VS_P_PARENT + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + iRet = 1; + }else +#endif + { + iRet = BATTLE_NewEntry( + charaindex, + battleindex, + CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE ) ); + } + + if( iRet == 0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_RESCUE ); + iRet = BATTLE_PetDefaultEntry( + charaindex, + battleindex, + CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE ) + ); + } + + + + if( iRet == 0 ){ + int flg; + if( CHAR_getInt( charaindex, CHAR_DEFAULTPET ) >= 0 ){ + pindex = CHAR_getCharPet( charaindex, CHAR_getInt( charaindex, CHAR_DEFAULTPET ) ); + CHAR_setWorkInt( pindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_RESCUE ); + } + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)ս", + // CHAR_getUseName( charaindex ) ); + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + if( ( fd = getfdFromCharaIndex(charaindex) ) != -1 ){ + lssproto_EN_send( fd, BattleArray[battleindex].type, BattleArray[battleindex].field_no ); + } + flg = (BattleArray[battleindex].Side[ + CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE)].flg + & BSIDE_FLG_HELP_OK)? TRUE:FALSE; + lssproto_HL_send( fd, flg); + sprintf( szBuffer, "BP|%X|%X|%X", + BATTLE_Index2No( battleindex, charaindex ), BP_FLG_JOIN, CHAR_getInt(charaindex, CHAR_MP ) ); + BATTLE_CommandSend( charaindex, szBuffer ); + }else{ + snprintf( szBuffer, sizeof( szBuffer ), "޷ս" ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORYELLOW); + if( ( fd = getfdFromCharaIndex(charaindex) ) != -1 ){ + lssproto_EN_send( fd, FALSE, BattleArray[battleindex].field_no ); + } + } + BATTLE_ClearGetExp( charaindex ); + return iRet; +} + +BOOL BATTLE_RescueTry( int charaindex) +{ + int x,y; + OBJECT object; + int pfound = FALSE; + int result = FALSE; + int fd; + int i; + int cnt; + + fd = getfdFromCharaIndex( charaindex); + if( CONNECT_checkfd( fd ) == FALSE ) return FALSE; +#if 1 // òսظս Robin + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) { + CHAR_talkToCli( charaindex, -1, " ظս! ", CHAR_COLORRED); + print("\n ķ!!ظս!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + //lssproto_EN_send( fd, FALSE, 0 ); + return FALSE; + } +#endif + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) { + lssproto_EN_send( fd, FALSE, 0 ); + return FALSE; + } +#ifdef _BATTLE_TIMESPEED + if( CONNECT_getBDTime( fd) > time( NULL) ) { + return FALSE; + } +#endif + for( i = 0; i < CONNECT_WINDOWBUFSIZE; i ++ ) { + CONNECT_setBattlecharaindex(fd,i,-1); + } + CHAR_getCoordinationDir( CHAR_getInt( charaindex, CHAR_DIR ) , + CHAR_getInt( charaindex , CHAR_X ), + CHAR_getInt( charaindex , CHAR_Y ) , + 1 , &x , &y ); + + cnt = 0; + for( object = MAP_getTopObj( CHAR_getInt( charaindex, CHAR_FLOOR),x,y) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int toindex; + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) continue; + toindex = OBJECT_getIndex( objindex); + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + && CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYERNPC +#endif + ) continue; + pfound = TRUE; + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + continue; + } + if( BattleArray[ CHAR_getWorkInt( toindex, CHAR_WORKBATTLEINDEX)].type + != BATTLE_TYPE_P_vs_E ){ + continue; + } + if( !(BattleArray[CHAR_getWorkInt( toindex,CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE)].flg + & BSIDE_FLG_HELP_OK)){ + continue; + } + CONNECT_setBattlecharaindex( fd, cnt, toindex ); + cnt++; + if( cnt == CONNECT_WINDOWBUFSIZE ) break; + } + if( cnt == 0 ) { + if( pfound == FALSE ) { + CHAR_talkToCli( charaindex, -1, "ûκˡ", + CHAR_COLORYELLOW); + } + lssproto_EN_send( fd, FALSE, 0 ); + }else if( cnt == 1 ) { + if( BATTLE_RescueEntry( charaindex, + CONNECT_getBattlecharaindex(fd,0) ) ){ + CHAR_talkToCli( charaindex, -1, "޷ս", CHAR_COLORYELLOW); + }else { + result = TRUE; + } + }else if( cnt > 1 ) { + int strlength; + char msgbuf[1024]; + char escapebuf[2048]; + strcpy( msgbuf, "1\n˭սأ\n"); + strlength = strlen( msgbuf); + for( i = 0; + CONNECT_getBattlecharaindex( fd,i ) != -1 + && i< CONNECT_WINDOWBUFSIZE; i ++ ){ + char *a = CHAR_getChar( CONNECT_getBattlecharaindex(fd,i), CHAR_NAME); + char buf[256]; + snprintf( buf, sizeof( buf),"%s\n", a); + if( strlength + strlen( buf) > arraysizeof( msgbuf)){ + print( "\nerr:%s:%d ӴѶϢ岻\n", + __FILE__,__LINE__); + break; + } + strcpy( &msgbuf[strlength], buf); + strlength += strlen(buf); + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SELECTBATTLE, + -1, + makeEscapeString( msgbuf, escapebuf, sizeof(escapebuf))); + + } + + return result; +} + + + + +BOOL BATTLE_RescueParentTry( int charaindex, int pindex) +{ + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) { + return FALSE; + } + if( CHAR_CHECKINDEX( pindex) == FALSE ) + return FALSE; + int result = FALSE; + if( CHAR_getFlg( charaindex, CHAR_ISDIE)) return FALSE; + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1) != pindex ) return FALSE; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + return FALSE; + } + if( BATTLE_RescueEntry( charaindex, pindex ) ){ + result = FALSE; + }else{ + result = TRUE; + } + if( result == FALSE ) { + CHAR_talkToCli( charaindex, -1, "޷ս", CHAR_COLORYELLOW); + } + return result; +} + +int BATTLE_PartyNewEntry( + int charaindex, + int battleindex, + int side +) +{ + int iRet = 0, i, work; +#if 1 + + iRet = BATTLE_NewEntry( charaindex, battleindex, side ); + if( iRet )return iRet; + CAflush( charaindex ); + CDflush( charaindex ); + iRet = BATTLE_PetDefaultEntry( charaindex, battleindex, side ); + if( iRet )return iRet; + BATTLE_ClearGetExp( charaindex ); +#endif + +#ifdef _BATTLE_GETITEM_RATE + if(BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P){ + if(CHAR_getInt( charaindex, CHAR_FLOOR ) == getBattleGetItemRateMap()){ + CHAR_setWorkInt( charaindex, CHAR_WORK_BATTLEPK, TRUE); + } + } +#endif + + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + work = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( work ) == FALSE )continue; + if( CHAR_getWorkInt( work, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE && CHAR_getWorkInt( work, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_FINAL){ + continue; + } + +#ifdef _BATTLE_GETITEM_RATE + if(BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P){ + if(CHAR_getInt( work, CHAR_FLOOR ) == getBattleGetItemRateMap()){ + CHAR_setWorkInt( work, CHAR_WORK_BATTLEPK, TRUE); + } + } +#endif + + + iRet = BATTLE_NewEntry( work, battleindex, side ); + + if( iRet )break; + CAflush( work ); + CDflush( work ); + iRet = BATTLE_PetDefaultEntry( work, battleindex, side ); + + if( iRet )return iRet; + BATTLE_ClearGetExp( work ); + } + + return iRet; +} + + +#if 1 + +int BATTLE_WatchNewEntry( + int charaindex, + int battleindex, + int side +) +{ + BATTLE_ENTRY *pEntry; + BATTLE *pBattle; + int iEntryFirst = 0, iEntryMax = BATTLE_ENTRY_MAX, i; + + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + pBattle = &BattleArray[battleindex]; + + if( pBattle->use == FALSE )return BATTLE_ERR_NOUSE; + + if( side < 0 || side > 1 ){ + return BATTLE_ERR_PARAM; + } + + switch( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) ){ + + + case CHAR_TYPEPLAYER: + if( pBattle->Side[side].type != BATTLE_S_TYPE_PLAYER ){ + return BATTLE_ERR_TYPE; + } + iEntryFirst = 0; + iEntryMax = BATTLE_PLAYER_MAX; + break; + default: + print( "(%s)(%d)\n", + CHAR_getUseName( charaindex ), + CHAR_getInt( charaindex, CHAR_WHICHTYPE ) ); + return BATTLE_ERR_TYPE; + } + + + pEntry = pBattle->Side[side].Entry; + + for( i = iEntryFirst; i < iEntryMax; i ++ ){ + if( pEntry[i].charaindex == -1 )break; + } + + if( i == iEntryMax ){ + return BATTLE_ERR_ENTRYMAX; + } + + EntryInit( &pEntry[i] ); + + pEntry[i].charaindex = charaindex; + + pEntry[i].bid = i + side * SIDE_OFFSET; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, + battleindex ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_WATCHINIT ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLESIDE, side ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, 0 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM3, -1 ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEWATCH, 1 ); + + return 0; +} + + +int BATTLE_WatchPartyNewEntry( + int charaindex, + int battleindex, + int side +) +{ + int iRet = 0, i, work; +#if 1 + + iRet = BATTLE_WatchNewEntry( charaindex, battleindex, side ); + if( iRet )return iRet; + + CAflush( charaindex ); + + CDflush( charaindex ); + +#endif + + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + + work = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( work ) == FALSE )continue; + + if( CHAR_getWorkInt( work, CHAR_WORKBATTLEMODE ) != 0 ){ + continue; + } + + iRet = BATTLE_WatchNewEntry( work, battleindex, side ); + + if( iRet )break; + + CAflush( work ); + CDflush( work ); + } + return iRet; + +} + + + + +int BATTLE_CreateForWatcher( int charaindex, int topbattleindex ); + +int BATTLE_WatchEntry( + int charaindex, + int toindex + ) +{ + int iRet = 0, battleindex, fd; + char szBuffer[256]=""; + + battleindex = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEINDEX ); + + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_FINAL + || CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE + || CHAR_getWorkInt( toindex, CHAR_WORKBATTLEINDEX ) == -1 + ){ + iRet = 1; + } + + if( iRet == 0 ){ + iRet = BATTLE_CreateForWatcher( charaindex, battleindex ); + } + if( iRet == 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)ʼս", + // CHAR_getUseName( charaindex ) ); + + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + if( ( fd = getfdFromCharaIndex(charaindex) ) != -1 ){ + lssproto_EN_send( fd, BattleArray[battleindex].type, BattleArray[battleindex].field_no ); + } + + sprintf( szBuffer, "BP|%X|%X|%X", + 20, BP_FLG_JOIN, CHAR_getInt(charaindex, CHAR_MP ) ); + BATTLE_CommandSend( charaindex, szBuffer ); + CHAR_setWorkInt(charaindex,CHAR_WATCHBATTLETYPE,1); + }else{ + snprintf( szBuffer, sizeof( szBuffer ), "޷ս" ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORYELLOW); + + if( ( fd = getfdFromCharaIndex(charaindex) ) != -1 ){ + lssproto_EN_send( fd, FALSE, 0 ); + } + } + + return iRet; +} + + + +BOOL BATTLE_WatchTry( int charaindex ) +{ + int x,y; + OBJECT object; + int pfound = FALSE; + int result = FALSE; + int fd; + int i; + int cnt; + + fd = getfdFromCharaIndex( charaindex); + if( CONNECT_checkfd( fd ) == FALSE )return FALSE; + + for( i = 0; i < CONNECT_WINDOWBUFSIZE ; i ++ ) { + CONNECT_setBattlecharaindex( fd,i,-1); + } + CHAR_getCoordinationDir( CHAR_getInt( charaindex, CHAR_DIR ) , + CHAR_getInt( charaindex , CHAR_X ), + CHAR_getInt( charaindex , CHAR_Y ) , + 1 , &x , &y ); + + cnt = 0; + /*м 󡼰ƽҷë */ + for( object = MAP_getTopObj( CHAR_getInt( charaindex, CHAR_FLOOR),x,y) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int toindex; + int objindex = GET_OBJINDEX(object); + /* ƽҷԪئ */ + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) continue; + toindex = OBJECT_getIndex( objindex); + /* Ԫئ */ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + && CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYERNPC +#endif + ) continue; + pfound = TRUE; + /* ƥئئݳ */ + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + continue; + } + + CONNECT_setBattlecharaindex( fd,cnt, toindex ); + cnt++; + if( cnt == CONNECT_WINDOWBUFSIZE ) break; + } + if( cnt == 0 ) { + if( pfound == FALSE ) { + CHAR_talkToCli( charaindex, -1, "ûκˡ", + CHAR_COLORYELLOW); + } + // ľئʻ + lssproto_EN_send( fd, FALSE, 0 ); + } + /* ƾئ޼ */ + else if( cnt == 1 ) { + if( BATTLE_WatchEntry( charaindex,CONNECT_getBattlecharaindex(fd,0)) ) + { + result = FALSE; + } else { + result = TRUE; + } + } + /* ūëƻ */ + else if( cnt > 1 ) { + int strlength; + char msgbuf[1024]; + char escapebuf[2048]; + strcpy( msgbuf, "1\nۿ˭սأ\n"); + strlength = strlen( msgbuf); + /* ū + * ƽҷ¼ + */ + for( i = 0; + CONNECT_getBattlecharaindex( fd,i ) != -1 + && i< CONNECT_WINDOWBUFSIZE; + i ++ ) + { + char *a = CHAR_getChar( CONNECT_getBattlecharaindex(fd,i), + CHAR_NAME); + char buf[256]; + snprintf( buf, sizeof( buf),"%s\n", a); + if( strlength + strlen( buf) > arraysizeof( msgbuf)){ + print( "\nerr:%s:%d ӴѶϢ岻\n", + __FILE__,__LINE__); + break; + } + strcpy( &msgbuf[strlength], buf); + strlength += strlen(buf); + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SELECTBATTLEWATCH, + -1, + makeEscapeString( msgbuf, escapebuf, sizeof(escapebuf))); + } + + return result; +} + + +#endif + + + + + + + +#define MAX_DOUJYOUENEMY 64 +static int DoujyouEnemyTbl[10]; // +/*************************************************************** + * ƹñƽҷ + ***************************************************************/ +int *Doujyou_GetEnemy( int meindex, int charaindex ) +{ + int i; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + int ret; + int insert; + int WorkEnemyTbl[MAX_DOUJYOUENEMY]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* */ + for( i = 0; i < arraysizeof(WorkEnemyTbl); i ++ ) { + WorkEnemyTbl[i] = -1; + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "enemyno", buf, sizeof( buf)) + == NULL ) + { + return NULL; + } + + insert = 0; + /* ¦ѱ̤лؤ³ë޼ */ + for( i = 0; i < MAX_DOUJYOUENEMY; i ++ ) { + int curEnemy; + char data[128]; + + ret = getStringFromIndexWithDelim( buf,",", i + 1,data, sizeof(data)); + if( ret == FALSE) { + break; + } + + curEnemy = ENEMY_getEnemyArrayFromId( atoi( data)); + if( !ENEMY_CHECKINDEX( curEnemy) ) continue; + WorkEnemyTbl[insert] = curEnemy; + insert ++; + } + // ľئվ޷¡ + if( insert <= 0 )return NULL; + + // ¼ĸةɬ + DoujyouEnemyTbl[0] = WorkEnemyTbl[RAND( 0, insert-1 )]; + + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "enemypetno", buf, sizeof( buf)) + == NULL ) + { + // ئ̤ئ + DoujyouEnemyTbl[1] = -1; + }else{ + insert = 0; + /* ¦ѱ̤лؤ³ë޼ */ + for( i = 0; i < MAX_DOUJYOUENEMY; i ++ ) { + int curEnemy; + char data[128]; + + ret = getStringFromIndexWithDelim( buf,",", i + 1,data, sizeof(data)); + if( ret == FALSE) { + break; + } + + curEnemy = ENEMY_getEnemyArrayFromId( atoi( data)); + if( !ENEMY_CHECKINDEX( curEnemy) ) continue; + WorkEnemyTbl[insert] = curEnemy; + insert ++; + } + // ¼ĸةɬ + DoujyouEnemyTbl[1] = WorkEnemyTbl[RAND( 0, insert-1 )]; + } + + // + DoujyouEnemyTbl[2] = -1; + + return DoujyouEnemyTbl; +} + + + +static int DoujyouWeponTbl[] = { + -1, + ITEM_FIST, + ITEM_AXE, + ITEM_CLUB, + ITEM_SPEAR, + ITEM_BOW, + ITEM_BOOMERANG, + ITEM_BOUNDTHROW, + ITEM_BREAKTHROW, +}; +int DoujyouRandomWeponSet( int charaindex ){ + int wepon = -1, itemindex; + int work = RAND( 0, arraysizeof( DoujyouWeponTbl ) - 1 ); + switch( DoujyouWeponTbl[work] ){ + case ITEM_AXE: wepon = 0;break; + case ITEM_CLUB: wepon = 100;break; + case ITEM_SPEAR: wepon = 200;break; + case ITEM_BOW: wepon = 2498;break; + case ITEM_BOOMERANG:wepon = 500;break; + case ITEM_BOUNDTHROW:wepon = 600;break; + case ITEM_BREAKTHROW:wepon = 700;break; + } + itemindex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( itemindex ) == TRUE ){ + ITEM_endExistItemsOne( itemindex ); + } + + if( wepon >= 0 ){ + itemindex = ITEM_makeItemAndRegist( wepon ) ; + CHAR_setItemIndex( charaindex, CHAR_ARM, itemindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charaindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1 ); + } + switch( DoujyouWeponTbl[work] ){ + case -1: + case ITEM_AXE: + case ITEM_CLUB: + case ITEM_SPEAR: + return 0; + } + return 1; + +} + +static int BattleERSkill1[]={ +3, 10, 11, 12, 30, 31, 40, 41, 50, 51, 52, 60, 61, 80, 90, 110, 120, 150, 210, +303, 309, 315, 321, 503, 504, 506, 507, 541, 542, 543, 544, 545, 546, 547, 575, 579, 580, +606, 613, 615 }; + +static int BattleERSkill2[]={ +12, 13, 20, 41, 52, 152, 210, 306, 312, 318, 324, 325, 500, 501, 502, 505, +508, 541, 542, 543, 544, 545, 546, 547, 576, 580, 594, 606, 613, 616 }; + +static int BattleERSkill3[]={ +13, 31, 41, 52, 60, 61, 80, 90, 100, 110, 120, 152, 210, 325, 500, 501, 504, 503, 504, 505, 506, 507, 508, 516, 610}; + +static int BattleERSkill4[]={ +609,610,611}; + + + +void BATTLE_EnemyRandowSetSkill( int enemyindex, int skillType) +{ + int i; + for( i=0; i<7; i++){ + int skillarray, skillID, Ri; + switch( skillType){ + case 1: + Ri = RAND( 0, arraysizeof( BattleERSkill1) - 1 ); + skillID = BattleERSkill1[Ri]; + break; + case 2: + Ri = RAND( 0, arraysizeof( BattleERSkill2) - 1 ); + skillID = BattleERSkill2[Ri]; + break; + case 3: + Ri = RAND( 0, arraysizeof( BattleERSkill3) - 1 ); + skillID = BattleERSkill3[Ri]; + break; + case 4: + Ri = RAND( 0, arraysizeof( BattleERSkill4) - 1 ); + skillID = BattleERSkill4[Ri]; + break; + case 5: + skillID = RAND( 301, 325 ); + break; + default : return; + } + skillarray = PETSKILL_getPetskillArray( skillID); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ){ + CHAR_setPetSkill( enemyindex, i, 1); + //andy_log + print("ANDY EnemyRandowSetSkill( ) skillID:%d array:%d err \n", + skillID, skillarray ); + continue; + } + CHAR_setPetSkill( enemyindex, i, skillID); + } +} + +int BATTLE_CreateVsEnemyNew( int charaindex, int npcindex, int *table ) +{ + int battleindex, iRet = 0, enemyindex, i, pindex; + int fd, field_no, baselevel = 0; + int skillType=0; + int EnemyList[20]; + + int *enemytable = table; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + +#ifdef _PLAYER_NPC + if(CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) +#endif +{ +#ifdef _STREET_VENDOR + // ̯вɽս + if( CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) > -1) return BATTLE_ERR_END; +#endif + +#ifdef _ANGEL_SUMMON // װʹﲻ + if( CHAR_getWorkInt(charaindex,CHAR_WORKANGELMODE) == TRUE ) return BATTLE_ERR_END; +#endif +} + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + battleindex = BATTLE_CreateBattle(); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; + + if( CHAR_CHECKINDEX( npcindex) ){ + skillType = CHAR_getWorkInt( npcindex, CHAR_NPCWORKINT11); + } + + + field_no = BATTLE_getBattleFieldNo( + CHAR_getInt( charaindex, CHAR_FLOOR ) , + CHAR_getInt( charaindex, CHAR_X ) , + CHAR_getInt( charaindex, CHAR_Y ) ); + if( field_no > BATTLE_MAP_MAX || field_no < 0 ){ + field_no = RAND( 0, BATTLE_MAP_MAX ); + } + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_ENEMY; + BattleArray[battleindex].leaderindex = charaindex; + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_E; + BattleArray[battleindex].createindex = npcindex; + BattleArray[battleindex].field_no = field_no; + BattleArray[battleindex].BattleFloor = CHAR_getInt( charaindex, CHAR_FLOOR ); + + BattleArray[battleindex].Side[0].flg &= ~BSIDE_FLG_HELP_OK; + + if( CHAR_CHECKINDEX( npcindex) ){ + if(CHAR_getInt( npcindex, CHAR_LV )>1){ + baselevel = CHAR_getInt( npcindex, CHAR_LV ); + } + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEINDEX, battleindex ); + }else if( npcindex == -1 ){ + enemytable = ENEMY_getEnemy( charaindex, + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + } + + BattleArray[battleindex].norisk = 0; + if( enemytable == NULL ) { + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + + for( i = 0; *(enemytable+i)!= -1 && i < arraysizeof( EnemyList )-1; i ++ ){ + EnemyList[i] = *(enemytable+i); + } + EnemyList[i] = -1; + +#ifdef _BATTLE_TIMESPEED + fd = getfdFromCharaIndex( charaindex ); + BattleArray[battleindex].CreateTime = time(NULL); + BattleArray[battleindex].flgTime = 200; // 1/100 sec +#endif + for( i = 0; EnemyList[i] != -1; i ++ ){ + int work; + enemyindex = ENEMY_createEnemy( EnemyList[i], baselevel ); + + if( !CHAR_CHECKINDEX( enemyindex ) ){ + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + CHAR_setInt(enemyindex, CHAR_WHICHTYPE, CHAR_TYPEENEMY); + if( skillType > 0 ){ + //int ENEMY_RandomChange( int enemyindex, int tempno ){ + BATTLE_EnemyRandowSetSkill( enemyindex, skillType); + } +#ifdef _ALLBLUES_LUA_1_9 + SetBattleEnmeyFunction(npcindex, enemyindex, i); +#endif + + if( ( iRet = BATTLE_NewEntry( enemyindex, battleindex, 1 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + if( CHAR_getInt( enemyindex, CHAR_DUELPOINT ) > 0 ){ + BattleArray[battleindex].dpbattle = 1; + } + work = CHAR_getInt( enemyindex, CHAR_BASEBASEIMAGENUMBER ); + if( 100466 <= work && work <= 100471 ){ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEFLG, + CHAR_getWorkInt( enemyindex, CHAR_WORKBATTLEFLG ) | CHAR_BATTLEFLG_ABIO ); + //print( "(%s)\n", CHAR_getUseName( enemyindex ) ); + } + } + + if( (iRet = BATTLE_PartyNewEntry( charaindex, battleindex, 0 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + { + BATTLE_ENTRY *pEntry, EntryWork; + pEntry = BattleArray[battleindex].Side[1].Entry; + for( i = 0; i < 5; i ++ ){ + EntryWork = pEntry[i]; + pEntry[i] = pEntry[i+5]; + pEntry[i+5] = EntryWork; + pEntry[i].bid = i + SIDE_OFFSET; + pEntry[i+5].bid = i + 5 + SIDE_OFFSET; + } + } + +BATTLE_CreateVsEnemy_End:; + fd = getfdFromCharaIndex( charaindex); + if( iRet ){ + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ +// if(npcindex > -1){ + if( fd != -1 ){ + if( BattleArray[battleindex].dpbattle ){ + lssproto_EN_send( fd, BATTLE_TYPE_DP_BATTLE, field_no ); + }else{ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + } + } else { +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0) +#endif + { + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + return iRet; + } + } +// } + + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_FINAL ) continue; + fd = getfdFromCharaIndex(pindex); + + if( fd != -1 ){ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + } + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect( charaindex, ON); + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + } + + CHAR_sendBattleEffect( pindex, ON); + } + } + + return iRet; +} + +int BATTLE_CreateVsEnemyLvNew( int charaindex, int npcindex, int *table, int *lvtable ) +{ + int battleindex, iRet = 0, enemyindex, i, pindex; + int fd, field_no, baselevel = 0; + int skillType=0; + int EnemyList[20]; + + int *enemytable = table; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + +#ifdef _PLAYER_NPC + if(CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) +#endif +{ +#ifdef _STREET_VENDOR + // ̯вɽս + if( CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) > -1) return BATTLE_ERR_END; +#endif + +#ifdef _ANGEL_SUMMON // װʹﲻ + if( CHAR_getWorkInt(charaindex,CHAR_WORKANGELMODE) == TRUE ) return BATTLE_ERR_END; +#endif +} + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + battleindex = BATTLE_CreateBattle(); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; +#ifdef _WAN_FIX + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLEPROTYPE,1); +#endif + if( CHAR_CHECKINDEX( npcindex) ){ + skillType = CHAR_getWorkInt( npcindex, CHAR_NPCWORKINT11); + } + + + field_no = BATTLE_getBattleFieldNo( + CHAR_getInt( charaindex, CHAR_FLOOR ) , + CHAR_getInt( charaindex, CHAR_X ) , + CHAR_getInt( charaindex, CHAR_Y ) ); + if( field_no > BATTLE_MAP_MAX || field_no < 0 ){ + field_no = RAND( 0, BATTLE_MAP_MAX ); + } + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_ENEMY; + BattleArray[battleindex].leaderindex = charaindex; + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_E; + BattleArray[battleindex].createindex = npcindex; + BattleArray[battleindex].field_no = field_no; + BattleArray[battleindex].BattleFloor = CHAR_getInt( charaindex, CHAR_FLOOR ); + + BattleArray[battleindex].Side[0].flg &= ~BSIDE_FLG_HELP_OK; + + if( CHAR_CHECKINDEX( npcindex) ){ + if(CHAR_getInt( npcindex, CHAR_LV )>1){ + baselevel = CHAR_getInt( npcindex, CHAR_LV ); + } + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEINDEX, battleindex ); + }else if( npcindex == -1 ){ + enemytable = ENEMY_getEnemy( charaindex, + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + } + + BattleArray[battleindex].norisk = 0; + if( enemytable == NULL ) { + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + + for( i = 0; *(enemytable+i)!= -1 && i < arraysizeof( EnemyList )-1; i ++ ){ + EnemyList[i] = *(enemytable+i); + } + EnemyList[i] = -1; + +#ifdef _BATTLE_TIMESPEED + fd = getfdFromCharaIndex( charaindex ); + BattleArray[battleindex].CreateTime = time(NULL); + BattleArray[battleindex].flgTime = 200; // 1/100 sec +#endif + for( i = 0; EnemyList[i] != -1; i ++ ){ + int work; + enemyindex = ENEMY_createEnemy( EnemyList[i], lvtable[i] ); + + if( !CHAR_CHECKINDEX( enemyindex ) ){ + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + CHAR_setInt(enemyindex, CHAR_WHICHTYPE, CHAR_TYPEENEMY); + if( skillType > 0 ){ + //int ENEMY_RandomChange( int enemyindex, int tempno ){ + BATTLE_EnemyRandowSetSkill( enemyindex, skillType); + } +#ifdef _ALLBLUES_LUA_1_9 + SetBattleEnmeyFunction(npcindex, enemyindex, i); +#endif + + if( ( iRet = BATTLE_NewEntry( enemyindex, battleindex, 1 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + if( CHAR_getInt( enemyindex, CHAR_DUELPOINT ) > 0 ){ + BattleArray[battleindex].dpbattle = 1; + } + work = CHAR_getInt( enemyindex, CHAR_BASEBASEIMAGENUMBER ); + if( 100466 <= work && work <= 100471 ){ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEFLG, + CHAR_getWorkInt( enemyindex, CHAR_WORKBATTLEFLG ) | CHAR_BATTLEFLG_ABIO ); + //print( "(%s)\n", CHAR_getUseName( enemyindex ) ); + } + } + + if( (iRet = BATTLE_PartyNewEntry( charaindex, battleindex, 0 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + { + BATTLE_ENTRY *pEntry, EntryWork; + pEntry = BattleArray[battleindex].Side[1].Entry; + for( i = 0; i < 5; i ++ ){ + EntryWork = pEntry[i]; + pEntry[i] = pEntry[i+5]; + pEntry[i+5] = EntryWork; + pEntry[i].bid = i + SIDE_OFFSET; + pEntry[i+5].bid = i + 5 + SIDE_OFFSET; + } + } + +BATTLE_CreateVsEnemy_End:; + fd = getfdFromCharaIndex( charaindex); + if( iRet ){ + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ +// if(npcindex > -1){ + if( fd != -1 ){ + if( BattleArray[battleindex].dpbattle ){ + lssproto_EN_send( fd, BATTLE_TYPE_DP_BATTLE, field_no ); + }else{ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + } + } else { +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0) +#endif + { + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + return iRet; + } + } +// } + + for( i = 1; i < CHAR_PARTYMAX; i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_FINAL ) continue; + fd = getfdFromCharaIndex(pindex); + + if( fd != -1 ){ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + } + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect( charaindex, ON); + for( i = 1; i < CHAR_PARTYMAX; i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + } + + CHAR_sendBattleEffect( pindex, ON); + } + } + + return iRet; +} + +int BATTLE_CreateVsEnemy( int charaindex, int mode, int npcindex ) +{ + int battleindex, iRet = 0, enemyindex, i, pindex; + int *enemytable = NULL, fd, field_no, baselevel = 0; + int skillType=0; + int EnemyList[20]; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + if( CHAR_getWorkInt(charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT) return BATTLE_ERR_END; + +#ifdef _STREET_VENDOR + // ̯вɽս + if( CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) > -1) return BATTLE_ERR_END; +#endif + +#ifdef _ANGEL_SUMMON // װʹﲻ + if( CHAR_getWorkInt(charaindex,CHAR_WORKANGELMODE) == TRUE ) return BATTLE_ERR_END; +#endif + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + battleindex = BATTLE_CreateBattle( ); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; + +#ifdef _ALLBLUES_LUA_1_7 + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ + if(CharVsEnemyFunction( charaindex ) == TRUE)return 0; + } + } +#endif + + if( CHAR_CHECKINDEX( npcindex) ){ + skillType = CHAR_getWorkInt( npcindex, CHAR_NPCWORKINT11); + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEINDEX, battleindex ); + } + + field_no = BATTLE_getBattleFieldNo( + CHAR_getInt( charaindex, CHAR_FLOOR ) , + CHAR_getInt( charaindex, CHAR_X ) , + CHAR_getInt( charaindex, CHAR_Y ) ); + if( field_no > BATTLE_MAP_MAX || field_no < 0 ){ + field_no = RAND( 0, BATTLE_MAP_MAX ); + } + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_ENEMY; + BattleArray[battleindex].leaderindex = charaindex; + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_E; + BattleArray[battleindex].createindex = npcindex; + BattleArray[battleindex].field_no = field_no; + BattleArray[battleindex].BattleFloor = CHAR_getInt( charaindex, CHAR_FLOOR ); + //andy_edit 2002/10/23 + /* + if( (iRet = BATTLE_PartyNewEntry( charaindex, battleindex, 0 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + */ + BattleArray[battleindex].Side[0].flg &= ~BSIDE_FLG_HELP_OK; + if( mode == 0 ) { + enemytable = ENEMY_getEnemy( charaindex, + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + }else if( mode == 1 ) { + enemytable = NPC_Util_getEnemy( npcindex, charaindex); + }else if( mode == 2 ) { + enemytable = Doujyou_GetEnemy( npcindex, charaindex ); + baselevel = CHAR_getInt( npcindex, CHAR_LV ); + BattleArray[battleindex].norisk = 1; + } + if( enemytable == NULL ) { + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + + for( i = 0; *(enemytable+i)!= -1 && i < arraysizeof( EnemyList )-1; i ++ ){ + EnemyList[i] = *(enemytable+i); + } + EnemyList[i] = -1; + +#ifdef _BATTLE_TIMESPEED + BattleArray[battleindex].CreateTime = time(NULL); + BattleArray[battleindex].flgTime = 200; // 1/100 sec +#endif + for( i = 0; EnemyList[i] != -1; i ++ ){ + int work; + enemyindex = ENEMY_createEnemy( EnemyList[i], baselevel ); + + if( enemyindex < 0 ){ + iRet = BATTLE_ERR_NOENEMY; + goto BATTLE_CreateVsEnemy_End; + } + + if( skillType > 0 ){ + //int ENEMY_RandomChange( int enemyindex, int tempno ){ + BATTLE_EnemyRandowSetSkill( enemyindex, skillType); + } + + if( mode == 2 ){ + if( i == 0 ){ + CHAR_setInt( enemyindex, CHAR_BASEBASEIMAGENUMBER, + CHAR_getInt( npcindex, CHAR_BASEBASEIMAGENUMBER ) ); + CHAR_setInt( enemyindex, CHAR_BASEIMAGENUMBER, + CHAR_getInt( npcindex, CHAR_BASEBASEIMAGENUMBER ) ); + CHAR_setChar( enemyindex, CHAR_NAME, + CHAR_getChar( npcindex, CHAR_NAME ) ); + CHAR_complianceParameter( enemyindex ); + } + } + if( ( iRet = BATTLE_NewEntry( enemyindex, battleindex, 1 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + if( CHAR_getInt( enemyindex, CHAR_DUELPOINT ) > 0 ){ + BattleArray[battleindex].dpbattle = 1; + } + work = CHAR_getInt( enemyindex, CHAR_BASEBASEIMAGENUMBER ); + if( 100466 <= work && work <= 100471 ){ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEFLG, + CHAR_getWorkInt( enemyindex, CHAR_WORKBATTLEFLG ) | CHAR_BATTLEFLG_ABIO ); + //print( "(%s)\n", CHAR_getUseName( enemyindex ) ); + } + } + //andy_edit 2002/10/23 + if( (iRet = BATTLE_PartyNewEntry( charaindex, battleindex, 0 ) ) ){ + goto BATTLE_CreateVsEnemy_End; + } + { + BATTLE_ENTRY *pEntry, EntryWork; + pEntry = BattleArray[battleindex].Side[1].Entry; + for( i = 0; i < 5; i ++ ){ + EntryWork = pEntry[i]; + pEntry[i] = pEntry[i+5]; + pEntry[i+5] = EntryWork; + pEntry[i].bid = i + SIDE_OFFSET; + pEntry[i+5].bid = i + 5 + SIDE_OFFSET; + } + } + +BATTLE_CreateVsEnemy_End:; + fd = getfdFromCharaIndex( charaindex); + + if( iRet ){ +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0) +#endif + { + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + } + }else{ + if( fd != -1 ){ + if( BattleArray[battleindex].dpbattle ){ + lssproto_EN_send( fd, BATTLE_TYPE_DP_BATTLE, field_no ); + }else{ + if( mode == 1 ){ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + }else{ + lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + } + } + }else { +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0) +#endif + { + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + return iRet; + } + } + + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == + BATTLE_CHARMODE_FINAL ) continue; + fd = getfdFromCharaIndex(pindex); + if( fd != -1 ){ + if( mode == 1 ){ + lssproto_EN_send( fd, BATTLE_TYPE_BOSS_BATTLE, field_no ); + }else{ + lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + } + } + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect( charaindex, ON); + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect( pindex, ON); + } + } + return iRet; +} + +int BATTLE_CreateVsPlayer( int charaindex0, int charaindex1 ) +{ + int battleindex, pindex, field_no, + i, j, charaindex[2], + parent[2], fd, + iRet = 0; + + if( CHAR_CHECKINDEX( charaindex0 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( CHAR_CHECKINDEX( charaindex1 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + if( CHAR_getWorkInt( charaindex0, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + if( CHAR_getWorkInt( charaindex1, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + +#ifdef _BATTLE_OVER_STAR_TIME + if( CHAR_getWorkInt( charaindex0, CHAR_WORKDBATTLETIME ) + 120 > time(NULL)){ + char token[256]; + sprintf(token, "㵱ǰȴ%dܽPK", CHAR_getWorkInt( charaindex0, CHAR_WORKDBATTLETIME ) + 120 - time(NULL)); + CHAR_talkToCli( charaindex0, -1, token, CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + if( CHAR_getWorkInt( charaindex1, CHAR_WORKDBATTLETIME ) + 120 > time(NULL)){ + char token[256]; + sprintf(token, "Էȴ%dܽPK", CHAR_getWorkInt( charaindex1, CHAR_WORKDBATTLETIME ) + 120 - time(NULL)); + CHAR_talkToCli( charaindex0, -1, token, CHAR_COLORYELLOW ); + sprintf(token, "㵱ǰȴ%dܽPK", CHAR_getWorkInt( charaindex1, CHAR_WORKDBATTLETIME ) + 120 - time(NULL)); + CHAR_talkToCli( charaindex1, -1, token, CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } +#endif + + field_no = BATTLE_getBattleFieldNo( + CHAR_getInt( charaindex0, CHAR_FLOOR ) , + CHAR_getInt( charaindex0, CHAR_X ), + CHAR_getInt( charaindex0, CHAR_Y ) ); + + charaindex[0] = charaindex0; + charaindex[1] = charaindex1; + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKBATTLEMODE ) != 0 ){ + return BATTLE_ERR_ALREADYBATTLE; + } + } + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + parent[j] = charaindex[j]; + }else + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + parent[j] = CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYINDEX1 ); + }else{ + parent[j] = -1; + } + } + if( parent[0] != -1 && parent[0] == parent[1] ){ + return BATTLE_ERR_SAMEPARTY; + } + battleindex = BATTLE_CreateBattle( ); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].leaderindex = charaindex0; + +#ifdef _AUTO_PK + strcpy(BattleArray[battleindex].leadercdkey,CHAR_getChar(charaindex0,CHAR_CDKEY)); + strcpy(BattleArray[battleindex].leadername,CHAR_getChar(charaindex0,CHAR_NAME)); + BattleArray[battleindex].rivalindex = charaindex1; + strcpy(BattleArray[battleindex].rivalcdkey,CHAR_getChar(charaindex1,CHAR_CDKEY)); + strcpy(BattleArray[battleindex].rivalname,CHAR_getChar(charaindex1,CHAR_NAME)); +#endif + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_P; + BattleArray[battleindex].dpbattle = 1; + BattleArray[battleindex].field_no = field_no; + BattleArray[battleindex].BattleFloor = CHAR_getInt( charaindex0, CHAR_FLOOR ); +#ifdef _BATTLE_TIMESPEED + BattleArray[battleindex].CreateTime = time(NULL); +#endif + for( j = 0; j < 2; j ++ ){ + iRet = BATTLE_PartyNewEntry( charaindex[j], battleindex, j ); + if( iRet ){ + goto BATTLE_CreateVsPlayer_End; + } + BattleArray[battleindex].Side[j].flg &= ~BSIDE_FLG_HELP_OK; + } +BATTLE_CreateVsPlayer_End:; + if( iRet ){ + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + fd = getfdFromCharaIndex(charaindex[0]); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ + for( j = 0; j < 2; j ++ ){ + fd = getfdFromCharaIndex(charaindex[j]); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex[j], CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex[j], CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( charaindex[j], ON); + for( i = 1; i < getPartyNum(charaindex[j]); i ++ ){ + pindex = CHAR_getWorkInt( charaindex[j], i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == + BATTLE_CHARMODE_FINAL ) continue; + + fd = getfdFromCharaIndex(pindex); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( pindex, ON ); + } + } + } + return iRet; +} + + + +#ifdef _TRADE_PK +int BATTLE_CreateVsPlayerForTrade( STradeList TradeList1, STradeList TradeList2 ) +{ + int battleindex, pindex, field_no, + i, j, charaindex[2], + parent[2], fd, + iRet = 0; + + + int charaindex0 = TradeList1.charaindex; + int charaindex1 = TradeList2.charaindex; + + if( CHAR_CHECKINDEX( charaindex0 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( CHAR_CHECKINDEX( charaindex1 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + if( CHAR_getWorkInt( charaindex0, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + if( CHAR_getWorkInt( charaindex1, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + + field_no = BATTLE_getBattleFieldNo( + CHAR_getInt( charaindex0, CHAR_FLOOR ) , + CHAR_getInt( charaindex0, CHAR_X ), + CHAR_getInt( charaindex0, CHAR_Y ) ); + + charaindex[0] = charaindex0; + charaindex[1] = charaindex1; + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKBATTLEMODE ) != 0 ){ + return BATTLE_ERR_ALREADYBATTLE; + } + } + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + parent[j] = charaindex[j]; + }else + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + parent[j] = CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYINDEX1 ); + }else{ + parent[j] = -1; + } + } + if( parent[0] != -1 && parent[0] == parent[1] ){ + return BATTLE_ERR_SAMEPARTY; + } + battleindex = BATTLE_CreateBattle( ); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].leaderindex = charaindex0; + BattleArray[battleindex].rivalindex = charaindex1; + +#ifdef _TRADE_PK + memcpy( &BattleArray[battleindex].TradeList[0], &TradeList1, sizeof( STradeList) ); + memcpy( &BattleArray[battleindex].TradeList[1], &TradeList2, sizeof( STradeList) ); +#endif + + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_P; + BattleArray[battleindex].dpbattle = 1; + BattleArray[battleindex].field_no = field_no; + BattleArray[battleindex].BattleFloor = CHAR_getInt( charaindex0, CHAR_FLOOR ); +#ifdef _BATTLE_TIMESPEED + BattleArray[battleindex].CreateTime = time(NULL); +#endif + for( j = 0; j < 2; j ++ ){ + iRet = BATTLE_PartyNewEntry( charaindex[j], battleindex, j ); + if( iRet ){ + goto BATTLE_CreateVsPlayer_End; + } + BattleArray[battleindex].Side[j].flg &= ~BSIDE_FLG_HELP_OK; + } +BATTLE_CreateVsPlayer_End:; + if( iRet ){ + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + fd = getfdFromCharaIndex(charaindex[0]); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ + for( j = 0; j < 2; j ++ ){ + fd = getfdFromCharaIndex(charaindex[j]); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex[j], CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex[j], CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( charaindex[j], ON); + for( i = 1; i < getPartyNum(charaindex[j]); i ++ ){ + pindex = CHAR_getWorkInt( charaindex[j], i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == + BATTLE_CHARMODE_FINAL ) continue; + + fd = getfdFromCharaIndex(pindex); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( pindex, ON ); + } + } + } + return iRet; +} + +#endif + + +//********************************************************* +// +// ëܰѣݱɬ +// +int BATTLE_WatchLink( int topbattleindex, int battleindex ) +// +// +//********************************************************* +{ + BATTLE *pWork, *pTop; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + fprint( "err:battle index (%d)\n", battleindex ); + return FALSE; + } + if( BATTLE_CHECKINDEX( topbattleindex ) == FALSE ){ + fprint( "err:battle index (%d)\n", topbattleindex ); + return FALSE; + } + + pTop = &BattleArray[topbattleindex]; + + if( BATTLE_CHECKADDRESS( pTop ) == FALSE ){ + fprint( "err:battle address (%p)\n", pTop ); + return FALSE; + } + + + pWork = pTop->pNext; // ʧ + + if( pWork ){ + if( BATTLE_CHECKADDRESS( pWork ) == FALSE ){ + fprint( "err:battle address (%p)\n", pWork ); + return FALSE; + } + } + + // ë󡼰ݱ + pTop->pNext = &BattleArray[battleindex]; + // мëɬ + BattleArray[battleindex].pBefore = pTop; + // мëɬ + BattleArray[battleindex].pNext = pWork; + // ݼ󡷴 + if( pWork ){ + pWork->pBefore = &BattleArray[battleindex]; + } + return TRUE; +} + +//********************************************************* +// +// ë繴 +// +int BATTLE_WatchUnLink( int battleindex ) +// +// +//********************************************************* +{ + BATTLE *pTop; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + fprint( "err:battle index (%d)\n", battleindex ); + return FALSE; + } + + // ë󡼰 + pTop = BattleArray[battleindex].pBefore; + + if( pTop ){ + if( BATTLE_CHECKADDRESS( pTop ) == FALSE ){ + fprint( "err:battle address (%p)\n", pTop ); + }else{ + // ئئ + pTop->pNext = BattleArray[battleindex].pNext; + } + } + if( BattleArray[battleindex].pNext ){ + if( BATTLE_CHECKADDRESS( BattleArray[battleindex].pNext ) == FALSE ){ + fprint( "err:battle address (%p)\n", BattleArray[battleindex].pNext ); + }else{ + BattleArray[battleindex].pNext->pBefore = pTop; + } + } + // мëɬ + BattleArray[battleindex].pBefore = NULL; + // мﷴ + BattleArray[battleindex].pNext = NULL; + + return TRUE; + +} + + +//********************************************************* +// +// ñë +// +int BATTLE_CreateForWatcher( int charaindex, int topbattleindex ) +// +// Ի BATTLE_ERR +// +//********************************************************* +{ + int battleindex, field_no , pindex, + i, fd, + iRet = 0; + + // ɷ¶ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + + // ƥ ƥئо + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != 0 ){ + return BATTLE_ERR_ALREADYBATTLE; + } + + // ë + battleindex = BATTLE_CreateBattle( ); + if( battleindex < 0 )return BATTLE_ERR_NOTASK;// έƥئ׾޷¡ + + // ռɷƥؤ£ + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + // 𵤴ƥؤ£ + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_PLAYER; + // ĸë + BattleArray[battleindex].leaderindex = charaindex; + // + BattleArray[battleindex].type = BATTLE_TYPE_WATCH; + BattleArray[battleindex].mode = BATTLE_MODE_WATCHBC; + // ū į + field_no = BattleArray[battleindex].field_no = BattleArray[topbattleindex].field_no; + BattleArray[battleindex].turn = BattleArray[topbattleindex].turn; + + // ͽ + if( BATTLE_WatchLink( topbattleindex, battleindex ) == FALSE ){ + fprint( "err:battle link error(%d),(%d)\n", + topbattleindex, battleindex ); + // ޷¡ ƥ GOTO + goto BATTLE_CreateForWatcher_End; + } + + // ɡ ū޼ + iRet = BATTLE_WatchPartyNewEntry( charaindex, battleindex, 0 ); + if( iRet ){ + // ޷¡ ƥ GOTO + goto BATTLE_CreateForWatcher_End; + } + + +// ޷¡ʲ +BATTLE_CreateForWatcher_End:; + + if( iRet ){ // ޷¡ؤ + // 幻 + BATTLE_ExitAll( battleindex ); + // ʹ + BATTLE_DeleteBattle( battleindex ); + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ + fd = getfdFromCharaIndex( charaindex ); + /* ޼ ë */ + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + /* к̡˪ */ + if( CHAR_getWorkInt( charaindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, -1); + } + /* ʧ CA˪ */ + CHAR_sendBattleWatch( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX ), ON); + + // ޱ + for( i = 1; i < getPartyNum(charaindex); i ++ ){ + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + // ޼ƥ廯ئئ˪ئ + // FINAL 󡼰 έ + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == + BATTLE_CHARMODE_FINAL ) continue; + + fd = getfdFromCharaIndex(pindex); + /* ޼ */ + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + /* к̡˪ */ + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + } + /* ʧ CA˪ */ + CHAR_sendBattleWatch( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX ), ON); + } +/* + print( "(%s)Ϊо֡", + CHAR_getChar( charaindex, CHAR_NAME ) ); +*/ + } + + + return iRet; +} + + + + + + +/*------------------------------------------------------------ + * ë Ӭ + ------------------------------------------------------------*/ +void BATTLE_WatchStop( int charaindex ) +{ + int battleindex; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return; + // ƽҷ + BATTLE_Exit( charaindex, battleindex ); + // ɡ ū + CHAR_DischargePartyNoMsg( charaindex ); + + CHAR_talkToCli( charaindex, -1, + "սֹ", CHAR_COLORYELLOW ); + CHAR_setWorkInt(charaindex,CHAR_WATCHBATTLETYPE,0); + lssproto_B_send( getfdFromCharaIndex( charaindex ), "BU" ); + +} + + + + + + + + + +//************************************************************* +// +// ƥ Ӽɷ¶ëٴƻ +// +void BATTLE_TurnParam( + int charaindex, + int fixkind, + int mod, + int last +) +// +// +//************************************************************* +{ + int modparam, fixparam, lastparam; + + if( fixkind == -1 ){ + fixparam = 0; // 绥 + }else{ + fixparam = CHAR_getWorkInt( charaindex, fixkind ); + } + if( last == -1 ){ + lastparam = 0; + }else{ + lastparam = CHAR_getWorkInt( charaindex, last ); + } + modparam = CHAR_getWorkInt( charaindex, mod ); + // ƥ ëέ + // ëٴƻ + + // ᷴ MODPARAM ëߡӼƻ + modparam *= 0.8; + CHAR_setWorkInt( charaindex, mod, modparam ); + + // + if( last != -1 ){ + CHAR_setWorkInt( + charaindex, + last, + lastparam + modparam * 0.01 ); + } + +} + +void BATTLE_AttReverse( int charaindex ) +{ + int earth, water, fire, wind; + //ttom start because the second had this + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_REVERSE ){ + // ƻئݳ + }else{ + // ƻئмƥ + return; + } + //ttom end + earth = CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT ); + water = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT ); + fire = CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT ); + wind = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT ); + + CHAR_setWorkInt( charaindex, CHAR_WORKFIXEARTHAT, fire ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWATERAT, wind ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXFIREAT, earth ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWINDAT, water ); +} + +void BATTLE_PreCommandSeq( int battleindex ) +{ + BATTLE_ENTRY *pEntry; + BATTLE *pBattle; + int i, j, charaindex; + BATTLE_CharSendAll( battleindex ); + BATTLE_CharaBackUp( battleindex ); + BattleArray[battleindex].timer = NowTime.tv_sec; + BATTLE_AllCharaCWaitSet( battleindex ); + BATTLE_ActSettingSend( battleindex ); + BattleArray[battleindex].flg |= BATTLE_FLG_FREEDP; + pBattle = &BattleArray[battleindex]; + for( j = 0; j < 2; j ++ ){ + int flg; + pEntry = pBattle->Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pEntry[i].guardian = -1; + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); +//ttom the second only one //flg &= ~CHAR_BATTLEFLG_GUARDIAN; + flg &= ~CHAR_BATTLEFLG_GUARDIAN; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ) continue; + + CHAR_complianceParameter( charaindex ); + BATTLE_TurnParam( charaindex, + CHAR_WORKFIXSTR, // + CHAR_WORKMODATTACK, + CHAR_WORKATTACKPOWER + ); + BATTLE_TurnParam( charaindex, + CHAR_WORKFIXTOUGH, // + CHAR_WORKMODDEFENCE, + CHAR_WORKDEFENCEPOWER + ); + BATTLE_TurnParam( charaindex, + CHAR_WORKFIXDEX, // ٶƽ + CHAR_WORKMODQUICK, + CHAR_WORKQUICK + ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + BATTLE_TurnParam( charaindex, + -1, + CHAR_WORKMODCHARM, // + CHAR_WORKFIXCHARM + ); + } + BATTLE_TurnParam( charaindex, + -1, // + CHAR_WORKMODCHARM, + -1 + ); + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_REVERSE ){ + BATTLE_AttReverse( charaindex ); + } + } + } +} + + +//************************************************** +// +// Ѩг ݼ ľ +// +void BATTLE_PreWatchWaitSeq( int battleindex ) +// +// +//************************************************** +{ + // ƥݶ + BattleArray[battleindex].timer = NowTime.tv_sec; + // 幻ƹëѨ + BATTLE_AllCharaWatchWaitSet( battleindex ); +} +static int BATTLE_Init( int battleindex ) +{ + BATTLE *pBattle; + int iRet = 0; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + pBattle = &BattleArray[battleindex]; + pBattle->mode = BATTLE_MODE_BATTLE; + iRet = BATTLE_SurpriseCheck( battleindex ); + if( iRet == 0 ){ + }else + if( iRet == 1 ){ + BattleArray[battleindex].Side[1].flg |= BSIDE_FLG_SURPRISE; + }else + if( iRet == 2 ){ + BattleArray[battleindex].Side[0].flg |= BSIDE_FLG_SURPRISE; + } + BATTLE_PreCommandSeq( battleindex ); +#ifdef _MO_LUA_BATTLE_START + BattleStartFunction(battleindex); +#endif + return 0; +} +int BATTLE_CountEntry( + int battleindex, + int side +) +{ + int i; + BATTLE_ENTRY *pEntry; + int cnt = 0; + + // ɷ¶ + if( BATTLE_CHECKSIDE( side ) == FALSE )return -BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -BATTLE_ERR_BATTLEINDEX; + + // ޼ + pEntry = BattleArray[battleindex].Side[side].Entry; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + if( pEntry[i].charaindex != -1 ){ // ƽҷ» + cnt ++; + } + } + return cnt; +} + +static BOOL BATTLE_CommandWait( int battleindex, int side) +{ + int i, charaindex, BeOk=0; + BATTLE_ENTRY *pEntry; + BOOL iRet = TRUE; + BOOL TimeOut = FALSE; + if( BATTLE_CHECKSIDE( side ) == FALSE )return TRUE;//ֵǷںϷ Χ + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return TRUE; + if( BattleArray[battleindex].Side[side].type == BATTLE_S_TYPE_ENEMY ) return TRUE; + pEntry = BattleArray[battleindex].Side[side].Entry; + int playerindex; +#ifdef _BATTLECOMMAND_TIME + //print("\nPartTime=%d",BattleArray[battleindex].PartTime); + if( BattleArray[battleindex].PartTime > 1 && + BattleArray[battleindex].PartTime < time(NULL) ){ + TimeOut = TRUE; + } +#endif + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + continue; + } + +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 1 + ){ + OffLineCommand( battleindex, charaindex, side ); + if(CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + ||CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC +#endif + ){ + int petnum = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + int petindex = CHAR_getCharPet( charaindex, petnum ); + if( CHAR_CHECKINDEX( petindex )){ + OffLineCommand( battleindex, petindex, side ); + } + } + } +#endif + switch ( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) ){ + case BATTLE_CHARMODE_C_OK: +#ifdef _BATTLE_BOUT_TIME + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + if(CHAR_getWorkInt(charaindex, CHAR_BATTLE_BOUT_TIME) > (int)time(NULL) - 1){ + if(CHAR_getInt(charaindex, CHAR_MP)>0){ + CHAR_talkToCli( charaindex, -1, "ϵͳ⵽ڿսMPԶ0", CHAR_COLORYELLOW); + CHAR_setInt(charaindex, CHAR_MP, 0); + } + } + } +#endif + BeOk++; + case BATTLE_CHARMODE_INIT: + case BATTLE_CHARMODE_RESCUE: + case BATTLE_CHARMODE_WATCHINIT: + break; + case BATTLE_CHARMODE_C_WAIT: + { +#ifdef _BATTLECOMMAND_TIME + if( TimeOut == TRUE ){ +/* + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + }else{ + //andy_log + print("ANDY TimeOut Exit:%d-[%s|%s]\n", + charaindex, CHAR_getUseName( charaindex), + CHAR_getChar( charaindex, CHAR_CDKEY) ); + + CHAR_talkToCli( charaindex, -1, "ʱδָǿ뿪ս", CHAR_COLORYELLOW); + + CHAR_DischargeParty( charaindex, 0);//ɢŶ + CHAR_setWorkInt(charaindex, CHAR_WORKFMPKFLAG, -1); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_COMPELESCAPE ); + BATTLE_Exit( charaindex, battleindex ); + lssproto_B_send( getfdFromCharaIndex( charaindex ), "BU" ); + // CONNECT_setCloseRequest( getfdFromCharaIndex( charaindex) , 1 ); + break; + + + } +*/ +#ifdef _OFFLINE_SYSTEM +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); +#ifdef _OFFLINE_SYSTEM +#endif + } +#endif + iRet = FALSE; + } + break; + default : + BATTLE_Exit( charaindex, battleindex ); + break; + } + } + + if( BeOk > 0 ){ +#ifdef _BATTLECOMMAND_TIME + if( BattleArray[ battleindex].PartTime <= 0 ){ + //սһִָ, ӳʱΪ120 + BattleArray[battleindex].PartTime = (int)time(NULL) + 120; + } +#endif + }else{ + if( BattleArray[ battleindex].PartTime <= 0 ){ + BattleArray[battleindex].PartTime = (int)time(NULL) + 99; + } + } + return iRet; +} + +#ifdef _ITEM_ADDEXP //vincent +#ifdef _ITEM_ADDEQUIPEXP +int BATTLE_GetExp( int charaindex, int midx ) +#else +int BATTLE_GetExp( int charaindex ) +#endif +{ + int addexp,i; + int modexp=0, getexp=0; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return 0; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET) { + int ownerindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + if( CHAR_CHECKINDEX( ownerindex) ){ + if(CHAR_getWorkInt(ownerindex,CHAR_WORKITEM_ADDEXP) > 0){ + modexp += CHAR_getWorkInt( ownerindex, CHAR_WORKITEM_ADDEXP); + } +#ifdef _PET_ADD_EXP + if(CHAR_getWorkInt(charaindex,CHAR_WORKITEM_ADDEXP) > 0){ + modexp += CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXP); + } +#endif + } + }else if(CHAR_getWorkInt(charaindex,CHAR_WORKITEM_ADDEXP) > 0){ + modexp = CHAR_getWorkInt(charaindex,CHAR_WORKITEM_ADDEXP); + } + + getexp = CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP ); +#ifdef _NEWOPEN_MAXEXP + if( getexp > 1000000000 ) getexp = 1000000000; +#endif +#ifdef _BATTLE_GOLD + int gold=CHAR_getInt( charaindex , CHAR_GOLD ); + if((gold+getBattleGold()) > CHAR_getMaxHaveGold(charaindex)) + gold=CHAR_getMaxHaveGold(charaindex); + else + gold+=getBattleGold(); + CHAR_setInt( charaindex , CHAR_GOLD , gold ); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); +#endif + if( getexp < 0 || CHAR_GetLevelExp( charaindex, CHAR_getInt( charaindex, CHAR_LV)+1)==-1){ +#ifdef _ALLBLUES_LUA_1_9 + FreeCharExpSave(charaindex, getexp); +#endif + getexp = 0; + } +#ifdef _ALLBLUES_LUA_1_9 + addexp = FreeModeExp(charaindex, getexp, modexp); +#else + addexp = getexp+((getexp*modexp*2)/100); +#endif +#ifdef _GET_BATTLE_EXP + //addexp += getexp * getBattleexp(); +#endif + + int badindex = -1; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + badindex = charaindex; + }else if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + badindex = CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX); + } + if( CHAR_CHECKINDEX( badindex ) == TRUE ){ +#ifdef _VIP_BATTLE_EXP + if( CHAR_getInt(badindex, CHAR_VIPTIME) > 0 +#ifdef _FMPOINT_WELFARE + || (CHAR_getWorkInt( badindex, CHAR_WORKFMFLOOR) == 1041 && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( badindex, CHAR_WORKFMFLOOR) == 2031 && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( badindex, CHAR_WORKFMFLOOR) == 3031 && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + || (CHAR_getWorkInt( badindex, CHAR_WORKFMFLOOR) == 4031 && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE && CHAR_getInt( badindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) +#endif +#ifdef _PLAYER_TITLE + //|| CHAR_getInt( badindex, CHAR_TITLE_LV) >= 20 +#endif + ){ + addexp*=getVipBattleexp(); + } +#endif + addexp = (addexp * FreePlayerExp(badindex)) / 100; + } + + +#ifdef _ITEM_ADDEQUIPEXP + if( CHAR_CHECKINDEX( midx ) ){ + for( i = 0 ; i < CHAR_EQUIPPLACENUM ; i ++ ){ + int id = CHAR_getItemIndex(midx,i);//id + if( ITEM_CHECKINDEX(id) ){ + char *arg,*P; + arg = ITEM_getChar(id, ITEM_ARGUMENT );//߲ + if( (P = strstr( arg, "EXPUP" )) ){ + if( (P = strstr( arg, "" )) ){//ֻЧ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) + addexp += getexp*atoi(P+=2)*0.01*getBattleexp(); + } + else if( (P = strstr( arg, "" )) ){//ֻԳЧ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET + && (CHAR_getInt( midx, CHAR_RIDEPET) != charaindex ) ) + addexp += getexp*atoi(P+=2)*0.01*getBattleexp(); + } + else if( (P = strstr( arg, "" )) ){//ֻЧ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET + && (CHAR_getInt( midx, CHAR_RIDEPET) == charaindex ) ) + addexp += getexp*atoi(P+=2)*0.01*getBattleexp(); + } + else{ + P = strstr( arg, "EXPUP" ); + addexp += getexp*atoi(P+=5)*0.01*getBattleexp(); + } + } + } + } + } +#endif +#ifdef _ITEM_ADDPETEXP + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ) + if( CHAR_getInt( charaindex, CHAR_PETID) == 1163 ) + addexp = 0; + +#endif + addexp = (addexp<0)?0:addexp; + if( CHAR_getInt( charaindex, CHAR_LV) >= CHAR_MAXUPLEVEL ) addexp = 0; + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, addexp );//شCHAR_WORKGETEXP + + CHAR_AddMaxExp( charaindex, addexp); + + return addexp; +} +#else + +#ifdef _ITEM_ADDEQUIPEXP +int BATTLE_GetExp( int charaindex, int midx ) +#else +int BATTLE_GetExp( int charaindex ) +#endif +{ + int addexp, nowexp; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return 0; + nowexp = CHAR_getInt( charaindex, CHAR_EXP ); + addexp = CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP ); + // shan 11/27 10^9 1224160000 + CHAR_AddMaxExp( charaindex, addexp); + return addexp; +} +#endif + +int BATTLE_DpCalc( int battleindex ) +{ + BATTLE_ENTRY *pLooseEntry, *pWinEntry; + int winside, looseside, i, charaindex, dpadd, dpall, num = 0; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + + winside = BattleArray[battleindex].winside; + looseside = 1 - winside; + if( winside != -1 && winside != 1 )return BATTLE_ERR_PARAM; + + // Ͱ + dpall = 0; + + // ë뵤 + pLooseEntry = BattleArray[battleindex].Side[looseside].Entry; + for( i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pLooseEntry[i].charaindex; + // ½ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + // м + dpadd = CHAR_getInt( charaindex, CHAR_DUELPOINT ) * DUELPOINT_RATE; + // 巴 ëѨ̹ϵɬ + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP) - dpadd ); + // Ͱң + dpall += dpadd; + } + // ձ Իü ëң + dpall += BattleArray[battleindex].Side[winside].common_dp; + + pWinEntry = BattleArray[battleindex].Side[winside].Entry; + for( num = 0,i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pWinEntry[i].charaindex; + // ½ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + num++; + } + // ئ⾮ ׻õ岾ئ + if( num <= 0 )return BATTLE_ERR_BATTLEINDEX; + dpadd = dpall / num; + if( dpadd <= 0 )dpadd = 1; // ƥ֨෴ܸ + + for( num = 0,i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pWinEntry[i].charaindex; + // ½ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + + // 巴 ëɬ + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP) + dpadd ); + } + return 0; +} + +//#define RS_LIST_MAX 4 // ݱо ˪¾ +#define RS_LIST_MAX 5 +typedef struct{ + int num; + int exp; + int levelup; +}RS_LIST; + +int BATTLE_GetDuelPoint( + int battleindex, // ̼͵ + int side, // + int num // з ƽҷ¾ +) +{ + char szBuffer[1024]=""; + int charaindex; + int dpnow, dpadd; + int fd; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + charaindex = BattleArray[battleindex].Side[side].Entry[num].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_PARAM; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + return 0; + } + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_PLAYER ){ + return 0; + } + dpadd = CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP ); + +#ifdef _VIP_POINT_PK + int floor = CHAR_getInt(charaindex, CHAR_FLOOR); + if(floor == 11111 || floor == 22222 || floor == 33333 || floor == 44444){ + int point=0; + int oldpoint=CHAR_getInt( charaindex, CHAR_AMPOINT ); + if( floor == 44444){ + point = getVipPointPK(3); + }else if( floor == 33333){ + point = getVipPointPK(2); + }else if( floor == 22222){ + point = getVipPointPK(1); + }else if( floor == 11111){ + point = getVipPointPK(0); + } + + if( dpadd < 0 ){ + CHAR_setInt( charaindex, CHAR_AMPOINT, oldpoint - point ); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -point, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + sprintf(szBuffer, "սʧȥֵ:%d\n", point); + CHAR_talkToCli(charaindex, -1, szBuffer, CHAR_COLORCYAN); + + if(CHAR_getInt( charaindex, CHAR_AMPOINT ) < point){ + sprintf(szBuffer, "Ļֵ㲻%dԶŶӣ", point); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORYELLOW ); + CHAR_DischargePartyNoMsg(charaindex); + } + + int i; + int num = 0; + BATTLE_ENTRY *pWinEntry = BattleArray[battleindex].Side[1-side].Entry; + for( i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + int charaindex = pWinEntry[i].charaindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + num++; + } + + int addpoint = point / num; + addpoint -= addpoint * getVipPointPKCost(); + for( i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + int charaindex = pWinEntry[i].charaindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + + int oldpoint=CHAR_getInt( charaindex, CHAR_AMPOINT ); + CHAR_setInt( charaindex, CHAR_AMPOINT, oldpoint + addpoint ); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + addpoint, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + sprintf(szBuffer, "ϲӮûֵ:%d\n", addpoint); + CHAR_talkToCli(charaindex, -1, szBuffer, CHAR_COLORCYAN); + } + } + }else +#endif +#ifdef _NEW_AUTO_PK + if( floor == 20000 && AutoPk_PKTimeGet() <= 0){ + if( dpadd == 0 ){ + CHAR_talkToCli(charaindex, -1, "ս룬δӼ֣", CHAR_COLORRED); + }else if( dpadd < 0 ){ + int fl = 0, x = 0, y = 0; + if(CHAR_CHECKINDEX(charaindex) != FALSE){ + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), &fl, &x, &y); + CHAR_warpToSpecificPoint(charaindex, fl, x, y); +#ifdef _FORMULATE_AUTO_PK +// saacproto_FormulateAutoPk_send(acfd, CHAR_getChar(charaindex, CHAR_CDKEY), CHAR_getWorkInt(charaindex,CHAR_WORK_AUTOPK)); + CHAR_setInt( charaindex , CHAR_AMPOINT, CHAR_getInt( charaindex , CHAR_AMPOINT)+CHAR_getWorkInt(charaindex,CHAR_WORK_AUTOPK)); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getWorkInt(charaindex,CHAR_WORK_AUTOPK), + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(ԶPK)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + CHAR_setInt( charaindex , CHAR_WORK_AUTOPK, 0); +#endif + CHAR_DischargeParty( charaindex, 0); + CHAR_talkToCli(charaindex, -1, "սܣϵͳԶͻؼ¼", CHAR_COLORYELLOW); + + int playernum = CHAR_getPlayerMaxNum(); + int num = 0; + int lastindex=0; + int i; + for(i=0;i= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + charaindex = BattleArray[battleindex].Side[side].Entry[num].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return BATTLE_ERR_PARAM; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + return 0; + } + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ +#ifdef _PLAYER_NPC + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC){ + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE ){ +#ifdef _ITEM_ADDEQUIPEXP + BATTLE_GetExp( charaindex , charaindex ); +#else + BATTLE_GetExp( charaindex ); +#endif + int UpLevel = CHAR_LevelUpCheck( charaindex , -1); + int i; + for( i = 0; i < UpLevel; i ++ ){ + CHAR_PetLevelUp( charaindex ); + CHAR_PetAddVariableAi( charaindex, AI_FIX_PETLEVELUP ); + } + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + petindex = CHAR_getCharPet( charaindex, i ); + if( CHAR_CHECKINDEX( petindex ) == FALSE )continue; + if( CHAR_getFlg( petindex, CHAR_ISDIE ) == TRUE )continue; + if( CHAR_getWorkInt( petindex, CHAR_WORKGETEXP ) <= 0 ){ + CHAR_complianceParameter( petindex ); + sprintf( szBuffer, "K%d", i ); + CHAR_sendStatusString( charaindex , szBuffer ); + continue; + } +#ifdef _ITEM_ADDEQUIPEXP + BATTLE_GetExp( petindex, charaindex ); +#else + BATTLE_GetExp( petindex ); +#endif + UpLevel = CHAR_LevelUpCheck( petindex , charaindex); + if( UpLevel > 0 ){ + for( j = 0; j < UpLevel; j ++ ){ + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + } + aRsList[rsCnt].levelup = 1; + }else{ + aRsList[rsCnt].levelup = 0; + } + aRsList[rsCnt].num = i; + aRsList[rsCnt].exp = CHAR_getWorkInt( petindex, CHAR_WORKGETEXP ); + rsCnt ++; + CHAR_complianceParameter( petindex ); + if( UpLevel > 0 ){ + sprintf( szBuffer, "K%d", i ); + CHAR_sendStatusString( charaindex , szBuffer ); + } + } + } + } +#endif + return 0; + } + pEntryChara = &BattleArray[battleindex].Side[side].Entry[num]; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE ){ +#ifdef _ITEM_ADDEQUIPEXP + BATTLE_GetExp( charaindex , charaindex ); +#else + BATTLE_GetExp( charaindex ); +#endif + if( getBattleDebugMsg( ) != 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) õ EXP %d", + CHAR_getUseName( charaindex ), + CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP ) + ); + BATTLE_talkToCli( charaindex, szBuffer, CHAR_COLORYELLOW ); + } + + } + UpLevel = CHAR_LevelUpCheck( charaindex , -1); + if( UpLevel > 0 ){ + aRsList[rsCnt].levelup = 1; + }else{ + aRsList[rsCnt].levelup = 0; + } + aRsList[rsCnt].num = -2; + aRsList[rsCnt].exp = CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP ); + rsCnt ++; + if( UpLevel > 0 ){ + int work; + + if( getBattleDebugMsg( ) != 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) %d", + CHAR_getUseName( charaindex ), + CHAR_getInt( charaindex, CHAR_LV ) + ); + BATTLE_talkToCli( charaindex, szBuffer, CHAR_COLORYELLOW ); + } +#ifdef _SKILLUPPOINT_CF + CHAR_setInt( charaindex, CHAR_SKILLUPPOINT, + CHAR_getInt( charaindex, CHAR_SKILLUPPOINT) + UpLevel*getSkup()); +#else + CHAR_setInt( charaindex, CHAR_SKILLUPPOINT, + CHAR_getInt( charaindex, CHAR_SKILLUPPOINT) + UpLevel*3); +#endif + work = CHAR_getInt( charaindex, CHAR_CHARM ); + work += CH_FIX_PLAYERLEVELUP; + CHAR_setInt( charaindex, CHAR_CHARM, min( 100, work ) ); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , + CHAR_P_STRING_LV|CHAR_P_STRING_NEXTEXP|CHAR_P_STRING_DUELPOINT + ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX ) ); + CHAR_PartyUpdate( charaindex, CHAR_N_STRING_LV ); +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( charaindex, TRUE ); +#endif + } + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + petindex = CHAR_getCharPet( charaindex, i ); + if( CHAR_CHECKINDEX( petindex ) == FALSE )continue; + if( CHAR_getFlg( petindex, CHAR_ISDIE ) == TRUE )continue; + if( CHAR_getWorkInt( petindex, CHAR_WORKGETEXP ) <= 0 ){ + CHAR_complianceParameter( petindex ); + sprintf( szBuffer, "K%d", i ); + CHAR_sendStatusString( charaindex , szBuffer ); + + continue; + } +#ifdef _ITEM_ADDEQUIPEXP + BATTLE_GetExp( petindex, charaindex ); +#else + BATTLE_GetExp( petindex ); +#endif + if( getBattleDebugMsg( ) != 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) õ EXP %d", + CHAR_getUseName( petindex ), + CHAR_getWorkInt( petindex, CHAR_WORKGETEXP ) + ); + BATTLE_talkToCli( charaindex, szBuffer, CHAR_COLORYELLOW ); + } + UpLevel = CHAR_LevelUpCheck( petindex , charaindex); + if( UpLevel > 0 ){ + if( getBattleDebugMsg( ) != 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) %d", + CHAR_getUseName( petindex ), + CHAR_getInt( petindex, CHAR_LV ) + ); + BATTLE_talkToCli( charaindex, szBuffer, CHAR_COLORYELLOW ); + } + for( j = 0; j < UpLevel; j ++ ){ + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + } + aRsList[rsCnt].levelup = 1; + }else{ + aRsList[rsCnt].levelup = 0; + } + aRsList[rsCnt].num = i; + aRsList[rsCnt].exp = CHAR_getWorkInt( petindex, CHAR_WORKGETEXP ); + rsCnt ++; + CHAR_complianceParameter( petindex ); + if( UpLevel > 0 ){ + sprintf( szBuffer, "K%d", i ); + CHAR_sendStatusString( charaindex , szBuffer ); + + } + + } + szItemString[0] = 0; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE +#ifdef _OFFLINE_SYSTEM + && CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0 +#endif + ){ + for( i = 0; i < GETITEM_MAX; i ++ ){ + int ItemGet = FALSE; + szEscItemString[0] = 0; + itemindex = pEntryChara->getitem[i]; + +#ifdef _BATTLE_GETITEM_RATE + if( itemindex < 0 ){ + int floor = CHAR_getInt( charaindex, CHAR_FLOOR ); + if(floor == getBattleGetItemRateMap()){ + int rate = rand() % 10000; + if(rate<2){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(0) ); + }else if(rate<5){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(1) ); + }else if(rate<10){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(2) ); + }else if(rate<18){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(3) ); + }else if(rate<28){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(4) ); + }else if(rate<40){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(5) ); + }else if(rate<65){ + itemindex = ITEM_makeItemAndRegist( getBattleGetItemRate(6) ); + } + } + int i; + int playernum = CHAR_getPlayerMaxNum(); + int num=0; + for(i=0;i= 0 ){ + int ret = CHAR_addItemSpecificItemIndex(charaindex,itemindex); + if( 0 <= ret && ret < CHAR_EQUIPPLACENUM ){ + print( "itemget err: ﲻȡitem(%s)(%d)(%s)\n", + CHAR_getUseName( charaindex ), + ret, + ITEM_getAppropriateName(itemindex) + ); + } + if( !CHAR_CHECKITEMINDEX( charaindex, ret) ){ + ItemGet = FALSE; + }else{ + ItemGet = TRUE; + itemgroup[itemnum] = ret; + itemnum ++; + } + } + if( ItemGet == TRUE ){ + if( getBattleDebugMsg( ) != 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "ʰ(%s)", + ITEM_getAppropriateName(itemindex) ); + BATTLE_talkToCli( charaindex, szBuffer, CHAR_COLORYELLOW ); + } + + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "BattleGet(սõĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar(itemindex, ITEM_UNIQUECODE),// shan 2001/12/14 + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + makeEscapeString( ITEM_getAppropriateName(itemindex), + szEscItemString, + sizeof( szEscItemString ) ); + strncat( szItemString, szEscItemString, sizeof( szItemString ) ); + pEntryChara->getitem[i] = -1; + }else{ + if( itemindex >= 0 ){ + ITEM_endExistItemsOne(itemindex); + }else{ + } + pEntryChara->getitem[i] = -1; + } + strncat( szItemString, "|", sizeof( szItemString ) ); + } + } + + szBuffer[0] = 0; + for( i = 0; i < RS_LIST_MAX; i ++ ){ + char szWork[256], sz62[64]; + szWork[0] = 0; + if( aRsList[i].exp > 0 || i == 0 ){ + cnv10to62( aRsList[i].exp, sz62, sizeof( sz62 ) ); + snprintf( szWork, sizeof( szWork ), + "%d|%d|%s", aRsList[i].num, + aRsList[i].levelup, + sz62 + ); + } + strncat( szBuffer, szWork, sizeof( szBuffer ) ); + strncat( szBuffer, ",", sizeof( szBuffer ) ); + } + strncat( szBuffer, szItemString, sizeof( szBuffer ) ); + { + int fd; + fd = getfdFromCharaIndex( charaindex ); + lssproto_RS_send( fd, szBuffer ); + } + if( itemnum > 0 ){ + int inum, ie; + for( inum = 0; inum < itemnum; inum ++ ){ + ie = CHAR_getItemIndex( charaindex, itemgroup[inum] ); + } + CHAR_sendItemData( charaindex, itemgroup, itemnum); + } + return 0; +} + +int BATTLE_GetProfit( int battleindex, int side, int num ) +{ + if( BattleArray[battleindex].dpbattle == 1 ){ + return BATTLE_GetDuelPoint( battleindex, side, num ); + }else{ + return BATTLE_GetExpGold( battleindex, side, num ); + } + +} + +int BATTLE_FinishSet( battleindex ) +{ + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + BattleArray[battleindex].mode = BATTLE_MODE_FINISH; + return 0; +} + +static int BATTLE_Finish( int battleindex ) +{ + BATTLE *pBattle; + BATTLE_ENTRY *pEntry; + int i,charaindex, j; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + + if( BattleArray[battleindex].winside == -1 + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E + && BattleArray[battleindex].WinFunc != NULL){ + BattleArray[battleindex].WinFunc( battleindex, + BattleArray[battleindex].createindex ); + } +#ifdef _ALLBLUES_LUA + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E ){ + if(CHAR_CHECKINDEX( BattleArray[battleindex].createindex ) == TRUE){ + CHAR_setWorkInt( BattleArray[battleindex].createindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE ); + CHAR_sendBattleEffect( BattleArray[battleindex].createindex, OFF); + if( BattleArray[battleindex].winside == -1){ + RunCharBattleOverEvent( BattleArray[battleindex].createindex, battleindex, 1); + }else{ + RunCharBattleOverEvent( BattleArray[battleindex].createindex, battleindex, 0); + } + } + } +#endif +#ifdef _BATTLE_PK + if(CHAR_CHECKINDEX(BattleArray[battleindex].rivalindex) && + CHAR_CHECKINDEX(BattleArray[battleindex].leaderindex)){ + if(CHAR_getWorkInt( BattleArray[battleindex].rivalindex, CHAR_WORK_BATTLEPK)==TRUE || + CHAR_getWorkInt( BattleArray[battleindex].leaderindex, CHAR_WORK_BATTLEPK)==TRUE){ + int winindex,lostindex; + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P){ + if( BattleArray[battleindex].winside == -1 ){ + winindex=BattleArray[battleindex].leaderindex; + lostindex=BattleArray[battleindex].rivalindex; + }else{ + winindex=BattleArray[battleindex].rivalindex; + lostindex=BattleArray[battleindex].leaderindex; + } + + int fl = 0, x = 0, y = 0; + CHAR_getElderPosition(CHAR_getInt(lostindex, CHAR_LASTTALKELDER), &fl, &x, &y); + CHAR_warpToSpecificPoint(lostindex, fl, x, y); + CHAR_DischargeParty( lostindex, 0); + CHAR_setWorkInt( winindex, CHAR_WORK_BATTLEPK, FALSE); + CHAR_setWorkInt( lostindex, CHAR_WORK_BATTLEPK, FALSE); + } + } + } +#endif + +#ifdef _TRADE_PK + if(CHAR_CHECKINDEX(BattleArray[battleindex].TradeList[0].charaindex) && + CHAR_CHECKINDEX(BattleArray[battleindex].TradeList[1].charaindex)){ + if(CHAR_getInt(BattleArray[battleindex].TradeList[0].charaindex, CHAR_FLOOR)==50000 && + CHAR_getInt(BattleArray[battleindex].TradeList[1].charaindex, CHAR_FLOOR)==50000){ + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + if( BattleArray[battleindex].winside == -1 ){ + TRADE_HandleTradeForPK( &BattleArray[battleindex].TradeList[0], &BattleArray[battleindex].TradeList[1] ); + }else if(BattleArray[battleindex].winside == 1){ + TRADE_HandleTradeForPK( &BattleArray[battleindex].TradeList[1], &BattleArray[battleindex].TradeList[0] ); + } + } + } + } +#endif + + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ +#ifdef DANTAI + BATTLE_DpCalc( battleindex ); +#endif + BATTLE_ENTRY *pWinEntry, *pLostEntry; + char token[256]; + if( BattleArray[battleindex].winside == -1){ + pWinEntry = BattleArray[battleindex].Side[0].Entry; + pLostEntry = BattleArray[battleindex].Side[1].Entry; + }else{ + pWinEntry = BattleArray[battleindex].Side[1].Entry; + pLostEntry = BattleArray[battleindex].Side[0].Entry; + } + + for( i = 0 ; i < BATTLE_ENTRY_MAX ; i ++ ){ + int winindex = pWinEntry[i].charaindex; + if( CHAR_CHECKINDEX( winindex ) == TRUE ){ + + CHAR_setInt( winindex, CHAR_DUELSTWINCOUNT, CHAR_getInt( winindex, CHAR_DUELSTWINCOUNT ) + 1); + +#ifdef _ALLBLUES_LUA_1_9 + BattleFinishFunction(winindex, BattleArray[battleindex].CreateTime, BattleArray[battleindex].turn, 1); +#endif + + CHAR_setInt( winindex, CHAR_DUELBATTLECOUNT, CHAR_getInt( winindex, CHAR_DUELBATTLECOUNT ) + 1); + CHAR_setInt( winindex, CHAR_DUELWINCOUNT, CHAR_getInt( winindex, CHAR_DUELWINCOUNT ) + 1); + + CHAR_setInt( winindex, CHAR_DUELSTLOSECOUNT, 0); + if(CHAR_getInt( winindex, CHAR_DUELSTWINCOUNT) > CHAR_getInt( winindex, CHAR_DUELMAXSTWINCOUNT)){ + CHAR_setInt( winindex, CHAR_DUELMAXSTWINCOUNT, CHAR_getInt( winindex, CHAR_DUELSTWINCOUNT )); + } + } + + int lostindex = pLostEntry[i].charaindex; + if( CHAR_CHECKINDEX( lostindex ) == TRUE ){ + + CHAR_setInt( lostindex, CHAR_DUELSTLOSECOUNT, CHAR_getInt( lostindex, CHAR_DUELSTLOSECOUNT ) + 1); + +#ifdef _ALLBLUES_LUA_1_9 + BattleFinishFunction(lostindex, BattleArray[battleindex].CreateTime, BattleArray[battleindex].turn, 0); +#endif + CHAR_setInt( lostindex, CHAR_DUELBATTLECOUNT, CHAR_getInt( lostindex, CHAR_DUELBATTLECOUNT ) + 1); + CHAR_setInt( lostindex, CHAR_DUELLOSECOUNT, CHAR_getInt( lostindex, CHAR_DUELLOSECOUNT ) + 1); + + CHAR_setInt( lostindex, CHAR_DUELSTWINCOUNT, 0); + } + } + } + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; +#ifdef _PET_TALK + for( i = 0 ; i < BATTLE_ENTRY_MAX ; i ++ ) +#else + for( i = BATTLE_ENTRY_MAX-1; i >= 0 ; i -- ) +#endif + { + charaindex = pEntry[i].charaindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + continue; + + + BATTLE_GetProfit( battleindex, j, i ); //ȡþֵ + BATTLE_Exit( charaindex, battleindex ); + } + } + if( BattleArray[battleindex].type == BATTLE_TYPE_WATCH ){ + }else{ + pBattle = BattleArray[battleindex].pNext; + for( ;pBattle; pBattle = pBattle->pNext ){ + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:battle address (%p)\n", pBattle ); + break; + } + for( i = BATTLE_ENTRY_MAX-1; i >= 0 ; i -- ){ + charaindex = pBattle->Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + BATTLE_Exit( charaindex, pBattle->battleindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_FINAL ); + } + } + pBattle = BattleArray[battleindex].pNext; + for( ;pBattle; pBattle = pBattle->pNext ){ + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:battle address (%p)\n", pBattle ); + break; + } + BATTLE_DeleteBattle( pBattle->battleindex ); + } + } + BATTLE_DeleteBattle( battleindex ); + return 0; +} + +int BATTLE_StopSet( battleindex ) +{ + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + BattleArray[battleindex].mode = BATTLE_MODE_STOP; + + return 0; +} + +static int BATTLE_Stop( int battleindex ) +{ + BATTLE_ENTRY *pEntry; + int i, charaindex, j; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = BATTLE_ENTRY_MAX-1; i >= 0 ; i -- ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + continue; + BATTLE_GetProfit( battleindex, j, i ); + BATTLE_Exit( charaindex, battleindex ); + } + } + + BATTLE_DeleteBattle( battleindex ); + return 0; +} + +int BATTLE_DefaultAttacker( int battleindex, int side ) +{ + int i, rnd, cnt; + int CharaTbl[BATTLE_ENTRY_MAX]; + + BATTLE_ENTRY *pEntry; + + pEntry = BattleArray[battleindex].Side[side].Entry; + cnt = 0; + + for( i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ){ + CharaTbl[i] = -1; + if( CHAR_CHECKINDEX( pEntry[i].charaindex ) == FALSE ){ + continue; + } + + if( CHAR_getWorkInt( pEntry[i].charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_RESCUE ){ + continue; + } + + if( BATTLE_TargetCheck( battleindex, i + side * SIDE_OFFSET ) == FALSE )continue; + + CharaTbl[cnt] = i + side * SIDE_OFFSET; + cnt ++; + } + + if( cnt == 0 ){ + return -1; + } + + rnd = RAND( 0, cnt-1 ); + return CharaTbl[rnd]; + +} + +//********************************************************* +// +// ؤϷԻ ëң +// +int BATTLE_AddDpAlive( + int battleindex, // ̼͵ + int side, // ( 0 or 1 ) + int dp +) +// +// ԻϷȻ +// ľئľ +// +//********************************************************* +{ + int i, charaindex; + BATTLE_ENTRY *pEntry; + int cnt = 0; + + // ɷ¶ + if( BATTLE_CHECKSIDE( side ) == FALSE )return -BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -BATTLE_ERR_BATTLEINDEX; + + // ޼ + pEntry = BattleArray[battleindex].Side[side].Entry; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) continue; + // ʸ𼰶ئ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) continue; + // Ϸ廯ʣ۵ң + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex, CHAR_WORKGETEXP) + dp ); + } + } + + return cnt; +} + +#if 1 +//********************************************************* +// +// ϷȻ¾Ʃ +// +int BATTLE_CountAlive( + int battleindex, // ̼͵ + int side // ( 0 or 1 ) +) +// +// ԻϷȻ +// ľئľ +// +//********************************************************* +{ + int i, charaindex; + BATTLE_ENTRY *pEntry; + int cnt = 0; + + // ɷ¶ + if( BATTLE_CHECKSIDE( side ) == FALSE )return -BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -BATTLE_ERR_BATTLEINDEX; + + // ޼ + pEntry = BattleArray[battleindex].Side[side].Entry; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) continue; + // ʸ𼰶ئ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) continue; + // Ϸ廯ʣ + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE ){ + cnt ++; + } + } + + return cnt; +} +#endif + + +//********************************************************* +// +// ׻ĻϷ廯ؾë +// +int BATTLE_OnlyRescue( + int battleindex, // ̼͵ + int side, // ( 0 or 1 ) + int *pOnlyFlg +) +// +// ԻϷȻ +// ľئľ +// +//********************************************************* +{ + int i, charaindex; + BATTLE_ENTRY *pEntry; + int cnt = 0, OnlyRescue = 1; + + (*pOnlyFlg) = 0; + + // ɷ¶ + if( BATTLE_CHECKSIDE( side ) == FALSE )return -BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return -BATTLE_ERR_BATTLEINDEX; + + // ޼ + pEntry = BattleArray[battleindex].Side[side].Entry; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ){ + continue; + } + // ʸ𼰶ئ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) continue; + // Ϸ廯ʣ + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == FALSE ){ + cnt ++; + // Ϸ廯֧ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_RESCUE ){ + }else{ + OnlyRescue = 0; + } + } +#ifdef _PETSKILL_LER + if(CHAR_getWorkInt(charaindex,CHAR_WORK_RELIFE) > 0) cnt++; +#endif + } + + // Ϸ廯֧лй + if( cnt > 0 && OnlyRescue ){ + // ׷ºë + (*pOnlyFlg) = 1; + }else{ + // лը߱ + (*pOnlyFlg) = 0; + } + + return cnt; +} + +static BOOL BATTLE_TimeOutCheck( int battleindex ) +{ + int i, j, charaindex; + BATTLE *pBattle; + BATTLE_ENTRY *pEntry; + pBattle = &BattleArray[battleindex]; + + if( NowTime.tv_sec > pBattle->timer + BATTLE_TIME_LIMIT ){ + }else{ + return FALSE; + } + //BATTLE_BroadCast( battleindex, "serverʱѵ", CHAR_COLORYELLOW ); + for( j = 0; j < 2; j ++ ){ + pEntry = pBattle->Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + continue; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_C_WAIT ){ + BATTLE_Exit( charaindex, battleindex ); + CHAR_DischargePartyNoMsg( charaindex ); + CHAR_talkToCli( charaindex, -1, + "ʱ䵽ս", CHAR_COLORYELLOW ); + BATTLE_CommandSend( charaindex, "BU" ); + } + } + } + + return TRUE; +} + +int BATTLE_WatchWait( int battleindex ) +{ + BATTLE *pBattle; + BOOL commandflg = TRUE; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + pBattle = &BattleArray[battleindex]; + if( BATTLE_TimeOutCheck( battleindex ) == TRUE ){ + commandflg = TRUE; + } + if( commandflg == FALSE ){ + return 0; + } + pBattle->mode = BATTLE_MODE_WATCHMOVIE; + pBattle->turn ++; + return 0; +} + +int BATTLE_WatchMovie( int battleindex ) +{ + return 0; + +} + +int BATTLE_WatchAfter( int battleindex ) +{ + BattleArray[battleindex].mode = BATTLE_MODE_WATCHPRE; + + return 0; + +} + +int BATTLE_WatchBC( int battleindex ) +{ + return 0; +} + +int BATTLE_WatchPre( int battleindex ) +{ + // Ѩг ݼ ľ + BATTLE_PreWatchWaitSeq( battleindex ); + BattleArray[battleindex].mode = BATTLE_MODE_WATCHWAIT; + return 0; +} + +static int BATTLE_Command( int battleindex ) +{ + BATTLE *pBattle, *pWatchBattle; + BOOL commandflg = TRUE, iFinish = FALSE; + int OnlyRescue[2], i, j, charaindex; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + pBattle = &BattleArray[battleindex]; + if( BATTLE_CommandWait( battleindex, 0) == FALSE ){ + commandflg = FALSE; + } + if( BATTLE_CommandWait( battleindex, 1) == FALSE ){ + commandflg = FALSE; + } + + pWatchBattle = pBattle->pNext; + for( ; pWatchBattle ; pWatchBattle = pWatchBattle->pNext ){ + if( BATTLE_CHECKADDRESS( pWatchBattle ) == FALSE ){ + fprint( "err:սbattle address(%p)\n", pWatchBattle ); + break; + } + + if( pWatchBattle->mode == BATTLE_MODE_WATCHBC ){ + BATTLE_MakeCharaString( battleindex, szAllBattleString, + sizeof(szAllBattleString) ); + BATTLE_BpSendToWatch( pWatchBattle, szAllBattleString ); + pWatchBattle->mode = BATTLE_MODE_WATCHPRE; + commandflg = FALSE; + }else if( pWatchBattle->mode != BATTLE_MODE_WATCHMOVIE ){ + commandflg = FALSE; + } + } + if( BATTLE_TimeOutCheck( battleindex ) == TRUE ){ + commandflg = TRUE; + } + if( commandflg == FALSE ){ + return 0; + } + + + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pBattle->Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == TRUE ){ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + +#ifdef _ALLBLUES_LUA_1_9 +// BattleCommand( charaindex, battleindex ); +#endif + +#ifdef _BATTLE_BOUT_TIME + if(CHAR_getInt( charaindex, CHAR_FLOOR) == 40001 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40002 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40003 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40004 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40005 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40006 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40007 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40008 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40009 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 40010 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 50001 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 50002 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 50003 + || CHAR_getInt( charaindex, CHAR_FLOOR) == 50004 + ){ + CHAR_setWorkInt( charaindex, CHAR_BATTLE_BOUT_TIME, (int)time(NULL)); + }else{ + CHAR_setWorkInt( charaindex, CHAR_BATTLE_BOUT_TIME, 0); + } +#endif + } + } + } + } + +#ifdef _BATTLECOMMAND_TIME + BattleArray[battleindex].PartTime = 0; +#endif + pBattle->turn ++;//Լغ + BATTLE_ai_all( battleindex, 0, 0); + BATTLE_ai_all( battleindex, 1, 0); + BATTLE_Battling( battleindex );//ս + pBattle->Side[0].flg &= ~BSIDE_FLG_SURPRISE; + pBattle->Side[1].flg &= ~BSIDE_FLG_SURPRISE; + if( BATTLE_OnlyRescue( battleindex, 0, &OnlyRescue[0] ) == 0 ){ + pBattle->winside = 1; + iFinish = TRUE; + }else if( BATTLE_OnlyRescue( battleindex, 1, &OnlyRescue[1] ) == 0 ){ + pBattle->winside = -1; + iFinish = TRUE; + } + for( j = 0; j < 2; j ++ ){ + if( OnlyRescue[j] != 1 )continue; + for( i = 0; i < BATTLE_ENTRY_MAX/2; i ++ ){ + charaindex = pBattle->Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + continue; + + if( CHAR_getInt( charaindex, CHAR_HP ) <= 0 ){ + BATTLE_Exit( charaindex, battleindex ); + } + } + } + BATTLE_PreCommandSeq( battleindex ); + if( iFinish == TRUE ){ + BATTLE_FinishSet( battleindex ); + } + return 0; +} + +extern void BATTLE_changeRideImage( int index ); + +int BATTLE_Loop( void ) +{ + int i, cnt = 0; + rand(); + for( i = 0; i < BATTLE_battlenum; i ++ ){//ս + //if( BattleArray[i].use == FALSE )continue; + if( !BATTLE_CHECKINDEX( i ) )continue; +#ifdef _BATTLE_TIME + struct timeval old; + old.tv_sec = BattleArray[i].tv_sec; + old.tv_usec = BattleArray[i].tv_usec; + if( getBattleTime() > 0 && time_diff_us(NowTime,old) < getBattleTime() * 1000.0 )continue; + BattleArray[i].tv_sec = NowTime.tv_sec; + BattleArray[i].tv_usec = NowTime.tv_usec; +#endif + if( BattleArray[i].type == BATTLE_TYPE_WATCH ){//ǹսģʽ + if( BATTLE_CountAlive( i, 0 ) == 0 ){ + BATTLE_FinishSet( i ); + } + } + + switch( BattleArray[i].mode ){ + case BATTLE_MODE_NONE://δս + break; + case BATTLE_MODE_INIT://սʼ + BATTLE_Init( i ); + break; + case BATTLE_MODE_BATTLE://Serverڲս + BATTLE_Command( i ); + break; + case BATTLE_MODE_FINISH://ս + BATTLE_Finish( i ); + break; + case BATTLE_MODE_STOP://սж + BATTLE_Stop( i ); + break; + case BATTLE_MODE_WATCHBC://ս... + BATTLE_WatchBC( i ); + break; + case BATTLE_MODE_WATCHPRE: + BATTLE_WatchPre( i ); + break; + case BATTLE_MODE_WATCHWAIT: + BATTLE_WatchWait( i ); + break; + case BATTLE_MODE_WATCHMOVIE: + BATTLE_WatchMovie( i ); + break; + case BATTLE_MODE_WATCHAFTER: + BATTLE_WatchAfter( i ); + break; + } + cnt ++; + } + + return cnt; +} + +typedef struct { + int charaindex; // ƽҷ̼͵ + int side; // + int dex; // ٶƽ + int num; // ޼ į + int combo; // ޾ +#ifdef _EQUIT_SEQUENCE + int sequence; +#endif +}BATTLE_CHARLIST; + + +typedef int (*FUNC)( const void *, const void * ); + +//************************************************************ +// +// ٶƽ ʤ +// +// ٶƽ񷴰 ľ£ϴĩƥؤ£ +// +static int EsCmp( + const BATTLE_CHARLIST *pC1, + const BATTLE_CHARLIST *pC2 +) +{ +#ifdef _EQUIT_SEQUENCE + return( (pC2->dex+pC2->sequence) > (pC1->dex+pC1->sequence) ); + +#else + return( pC2->dex - pC1->dex ); +#endif +} + +#ifdef _EQUIT_SEQUENCE +void Replacement_Entry( BATTLE_CHARLIST *temp1, BATTLE_CHARLIST *temp2) +{ + temp1->charaindex = temp2->charaindex; + temp1->combo = temp2->combo; + temp1->dex = temp2->dex; + temp1->num = temp2->num; + temp1->sequence = temp2->sequence; + temp1->side = temp2->side; +} +#endif +static void EntrySort( BATTLE_CHARLIST *EntryList, int listsize) +{ +#ifdef _EQUIT_SEQUENCE +// int i, j; + qsort( EntryList, listsize, sizeof( BATTLE_CHARLIST ), (FUNC)EsCmp ); +/* + for( i=0; i 0 ){ + int maxcheck, now; + BATTLE_CHARLIST temp; + + maxcheck = EntryList[i].sequence/8; + maxcheck = RAND( 1, maxcheck); + maxcheck = ( maxcheck>=i )?(i/3):maxcheck; + maxcheck = ( maxcheck<0)?0:maxcheck; + now = i; + for( j=0; j0; j++){ + if( EntryList[now].sequence > (EntryList[now-1].sequence *0.9) ){ + + Replacement_Entry( &temp, &EntryList[now]); + Replacement_Entry( &EntryList[now], &EntryList[now-1]); + Replacement_Entry( &EntryList[now-1], &temp); + now = now-1; + + +// temp = &EntryList[now]; +// EntryList[now] = EntryList[now-1]; +// EntryList[now-1] = *temp; +// temp = NULL; + + } + } + } + } +*/ +#else + qsort( EntryList, listsize, sizeof( BATTLE_CHARLIST ), (FUNC)EsCmp ); +#endif +} + +#ifdef _PETSKILL_NEW_PASSIVE + void BATTLE_PassiveSkill(int charaindex){ + int i,pskill_array,skill_type; + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++){ + + if( CHAR_getCharHaveSkill( charaindex, i ) == NULL ){ + continue; + } + pskill_array = PETSKILL_GetArray( charaindex, i ); + skill_type = PETSKILL_getInt( pskill_array, PETSKILL_FIELD ); + if( skill_type == PETSKILL_FIELD_MAP){ + PETSKILL_Use( charaindex, i, NULL, NULL ) ; + } + else{ + continue; + } + } +} +#endif +//************************************************************ +// +// ٶƽëң£ +// +static int BATTLE_DexCalc( + int charaindex +) +// +// Ի ٶƽ +// +//************************************************************ +{ + int dex = 0; + int work, COM; + int petindex = BATTLE_getRidePet( charaindex ); +#ifdef _PETSKILL_NEW_PASSIVE + //ֱӳ + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_DUCK, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_ACURATE, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_CRITICAL, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_COUNTER, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPASSIVE_MULTIPLE, 0); +//¼㱻ӳ +if (CHAR_getInt(charaindex,CHAR_WHICHTYPE)==CHAR_TYPEPET){ + BATTLE_PassiveSkill(charaindex); +} +#endif + + // Ѩ + COM = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + +#ifdef _PETSKILL_BECOMEFOX // ˳еݽ20% + if( CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work *0.8;//20% + } +#endif +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( charaindex, CHAR_WORKFEAR ) > 0 ){ + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work*0.8;//20% + } +#endif + // ɧ + switch( COM ){ +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + case BATTLE_COM_S_BLOOD: // Ѫ + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + case BATTLE_COM_S_SIGN: // һѪ +#endif + +#ifdef _BATTLE_NEWPOWER + case BATTLE_COM_JYUJYUTU: + case BATTLE_COM_S_ATTACK_MAGIC: + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( 0, 15 ); + break; +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + case BATTLE_COM_S_FIRE_ENCLOSE: // + case BATTLE_COM_S_ICE_ENCLOSE: // + case BATTLE_COM_S_THUNDER_ENCLOSE: // ׸ + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( work * 0.3, work * 0.5 ); + break; + case BATTLE_COM_S_VOLCANO_SPRINGS:// ɽȪ + case BATTLE_COM_S_SUMMON_THUNDER: // + case BATTLE_COM_S_ICE_ARROW: // + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( 0, work * 0.2 ); + break; + case BATTLE_COM_S_CURRENT: // + case BATTLE_COM_S_FIRE_BALL:// + case BATTLE_COM_S_ICE_CRACK: // + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( 0, work * 0.5 ); + break; + case BATTLE_COM_S_FIRE_SPEAR:// ǹ + case BATTLE_COM_S_STORM: // + case BATTLE_COM_S_ICE_MIRROR: // + case BATTLE_COM_S_ENCLOSE: // + case BATTLE_COM_S_TRANSPOSE: // λλ + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( work * 0.2, work * 0.5 ); + break; + + case BATTLE_COM_S_DOOM: // ĩ + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( 0.3, work * 0.6 ); + break; +#endif + +#ifdef _SKILL_SPEEDY_ATT //vincent 輼:ٹ + case BATTLE_COM_S_SPEEDYATTACK: + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work + work*0.3;//30% + break; +#endif +#ifdef _PETSKILL_DAMAGETOHP //輼:¿(Ѫı) + case BATTLE_COM_S_DAMAGETOHP2: + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work + work*0.2;//20% + break; +#endif + + case BATTLE_COM_ITEM: // ʧ ةë + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work - RAND( 0, work * 0.1 ) + work * 0.15; + break; + default: // ɧ ئ) + // Robin 0727 ride pet + if( petindex == -1 ) + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + else + work = BATTLE_adjustRidePet3A( charaindex, petindex, CHAR_WORKQUICK, ATTACKSIDE )+20; + dex = work - RAND( 0, work * 0.1 ); + break; + } + + //if( dex <= 1 )dex = 1; + return dex; +} + + + + + + +//************************************************************* +// +// ؤ¾ +// +static void ComboCheck( + BATTLE_CHARLIST *pEntryList, + int entrynum +) +// +//************************************************************* +{ + + int i, + charaindex, + com, + enemy, + side, + oldside = -3, // ؤԻئа + oldenemy = -3, // ؤԻئа + armtype, + move, + per, + ComboId = 1, // ʾ + start = -1; + for( i = 0; i < entrynum; i ++ ){ + + charaindex = pEntryList[i].charaindex; + com = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + enemy = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + side = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + armtype = 0; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + per = 20; // ķߡ + }else{ + per = 50; // зߡ + } + // ߾ ئ + if( CHAR_getInt( charaindex, CHAR_HP ) <= 0 + || BATTLE_CanMoveCheck( charaindex ) == FALSE + ){ + move = 0; + }else{ + move = 1; + } + + // տë ئĸ + // ئĸ + if( BATTLE_IsThrowWepon( + CHAR_getItemIndex( charaindex, CHAR_ARM ) ) == TRUE + ){ + armtype = 1; + } + + pEntryList[i].combo = 0; // + + if( start != -1 ){ // + if( com != BATTLE_COM_ATTACK // Ѩƥئ + || enemy != oldenemy // Ȼ³Ļ Ԫƥئ + || side != oldside // ਵ + || armtype == 1 // ƥؤ + || move == 0 // ئ + ){ + start = -1; // + oldside = side; // + }else{ + // ʾɬ + CHAR_setWorkInt( pEntryList[i].charaindex, + CHAR_WORKBATTLECOM1,BATTLE_COM_COMBO ); + pEntryList[i].combo = ComboId; + // ټɱɬ + CHAR_setWorkInt( pEntryList[start].charaindex, + CHAR_WORKBATTLECOM1,BATTLE_COM_COMBO ); + pEntryList[start].combo = ComboId; + } + } + if( start == -1 ){// ƻئ + if( com == BATTLE_COM_ATTACK + && armtype != 1 // ƥئ + && move == 1 // + && RAND( 1, 100 ) <= per + ){ // ɧ ƥؤ + start = i; + oldenemy = enemy; // Ȼ³ë + oldside = side; // + ComboId ++; + } + } + + } + +} + +//************************************************************* +// +// ƥ¾ +//ݼлʾƥԪئ FALSE +// +static BOOL ComboCheck2( + BATTLE_CHARLIST *pEntryList, // ޼ + int nownum, // ػ + int entrynum // ޼ +) +// +// ʾƥ TRUE +// ƥئ FALSE +// +//************************************************************* +{ + + int i, + iRet = FALSE, + ComboId, + charaindex; + + // ʾ + ComboId = pEntryList[nownum].combo; + + charaindex = pEntryList[nownum].charaindex; + if( !CHAR_CHECKINDEX( charaindex ) ){ + // лպ ƻ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG) & CHAR_BATTLEFLG_AIBAD ) + { +// print( "ҳ϶Ȳʹñɱʧ( %s )\n",CHAR_getUseName( charaindex ) ); + return FALSE; + } + } + // ݼлʾ帨ƥ¾ + for( i = nownum+1; i < entrynum; i ++ ){ + charaindex = pEntryList[i].charaindex; + if( !CHAR_CHECKINDEX( charaindex ) )continue; + // ʾ ਵ + if( ComboId != pEntryList[i].combo )break; + + // 帨ƻئݳ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == 0 ) break; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_FINAL ) break; + + if( CHAR_getInt( charaindex, CHAR_HP ) <= 0 + || BATTLE_CanMoveCheck( charaindex ) == FALSE + ){ + }else{ + iRet = TRUE; + break; + } + } +/* + if( iRet == FALSE ){ + print( "ɱʧ( %s )\n", + CHAR_getUseName( pEntryList[nownum].charaindex ) ); + } +*/ + return iRet; + +} + + +void BATTLE_UltimateExtra( + int battleindex, + int charaindex, + int enemyindex +) +{ + char szBuffer[256]=""; + int pindex, pno; + int floor=0, x=0, y=0; + szBuffer[0] = 0; + + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC +#endif + ){ + BATTLE_PetDefaultExit( enemyindex, battleindex ); + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + CHAR_setInt( enemyindex, CHAR_DUELBATTLECOUNT, CHAR_getInt( enemyindex, CHAR_DUELBATTLECOUNT ) + 1); + CHAR_setInt( enemyindex, CHAR_DUELLOSECOUNT, CHAR_getInt( enemyindex, CHAR_DUELLOSECOUNT ) + 1); + CHAR_setInt( enemyindex, CHAR_DUELSTWINCOUNT, 0); + } + }else if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E ){ + int levelflg = 1; +#ifdef _ULTIMATE_ANNOUNCE + if(( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET) + && ( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC + )){ + int badindex; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + badindex = charaindex; + }else{ + badindex = CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX); + } + if(CHAR_getWorkInt( charaindex, CHAR_WORKCONFUSION ) <= 0){ + if(enemyindex != badindex){ + // CHAR_warpToSpecificPoint( badindex, 117, 289, 168 ); + // CHAR_DischargePartyNoMsg( badindex ); + // BATTLE_Exit( badindex, battleindex ); + /* + if (CHAR_getInt(badindex,CHAR_FAME) <10000){ + CHAR_setInt(badindex,CHAR_FAME,0); + }else{ + CHAR_setInt(badindex,CHAR_FAME,CHAR_getInt(badindex,CHAR_FAME)-10000); + } + */ + char message[256]; + sprintf(message, "%s %s Զ %s ˣ裩˶Թֵ", CHAR_getUseName( enemyindex ), CHAR_getUseName( badindex ), CHAR_getUseName( badindex )); + int i; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, message, CHAR_COLORRED); + } + } + } + } + } +#endif + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)Զ", + // CHAR_getUseName( enemyindex ) ); + if( CHAR_getInt( enemyindex, CHAR_LV ) <= 10 ){ + levelflg = 2; + } + + if( BattleArray[battleindex].norisk == 0 ){ + CHAR_AddCharm( enemyindex, CH_FIX_PLAYEULTIMATE/levelflg ); + pno = CHAR_getInt( enemyindex, CHAR_DEFAULTPET ); + if( 0 <= pno && pno < CHAR_MAXPETHAVE ){ + pindex = CHAR_getCharPet( enemyindex, pno ); + if( CHAR_CHECKINDEX( pindex ) == TRUE ){ + CHAR_PetAddVariableAi( pindex, AI_FIX_PLAYERULTIMATE/levelflg ); + } + } + } + if( CHAR_getElderPosition( + CHAR_getInt( enemyindex, CHAR_LASTTALKELDER), &floor, &x, &y ) + != TRUE + ){ + }else{ + CHAR_warpToSpecificPoint( enemyindex, floor, x, y ); + } + } + BATTLE_Exit( enemyindex, battleindex ); + CHAR_DischargePartyNoMsg( enemyindex ); + if( getBattleDebugMsg( ) != 0 ){ + BATTLE_talkToCli( enemyindex, szBuffer, CHAR_COLORYELLOW ); + } + + }else + // ʸئ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int levelflg = 1; + int playerindex = CHAR_getWorkInt( enemyindex, CHAR_WORKPLAYERINDEX ); + + // ìﻥ Ӽ + if( CHAR_getInt( playerindex, CHAR_LV ) <= 10 ){ + levelflg = 2; + } + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ɡ", + // CHAR_getUseName( enemyindex ) ); + + // DZмɻշ + CHAR_setInt( playerindex, CHAR_DEFAULTPET, -1 ); + + // ب޻ﶯ½ëƱ + if( BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + // ͼ ᆴؤئ ëƱ + if( BattleArray[battleindex].norisk == 0 ){ + CHAR_PetAddVariableAi( enemyindex, AI_FIX_PETULTIMATE/levelflg ); + } + // DZмʸϷּë + CHAR_setInt( playerindex, CHAR_DEADPETCOUNT, + CHAR_getInt( playerindex, CHAR_DEADPETCOUNT ) + 1 ); + } +/* + // ʸվ ն£ + BATTLE_PetDefaultExit( enemyindex, battleindex ); +*/ + + // + BATTLE_Exit( enemyindex, battleindex ); + + }else{ + int flg; + // ľ½ƥʧ ū + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ɡ", + // CHAR_getUseName( enemyindex ) ); + // ƽҷ·ӡƻ +// BATTLE_Exit( enemyindex, battleindex ); + flg = CHAR_getWorkInt( enemyindex, CHAR_WORKBATTLEFLG ); + flg |= CHAR_BATTLEFLG_ULTIMATE; // ʧ ū + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEFLG, flg ); + BATTLE_Exit( enemyindex, battleindex ); + } + + // ú + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + +} + + +//************************************************************* +// +// ɧٱ忢姽 +// +void BATTLE_NormalDeadExtra( + int battleindex, // ̼͵ + int charaindex, // ڽƽҷ¼̼͵ + int enemyindex // ڽľƽҷ¼̼͵ +) +// +// +//************************************************************* +{ + int pindex, pno; + char szBuffer[256]=""; + + szBuffer[0] = 0; + // ƥ + // 缰 + // ͼ ئ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E + && BattleArray[battleindex].norisk == 0 + ){ +#ifdef _ULTIMATE_ANNOUNCE + if(( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET) + && ( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC + )){ + int badindex; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + badindex = charaindex; + }else{ + badindex = CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX); + } + if(CHAR_getWorkInt( charaindex, CHAR_WORKCONFUSION ) <= 0){ + if(enemyindex != badindex){ + // CHAR_warpToSpecificPoint( badindex, 117, 289, 168 ); + // CHAR_DischargePartyNoMsg( badindex ); + // BATTLE_Exit( badindex, battleindex ); + /* + if (CHAR_getInt(badindex,CHAR_FAME) <10000){ + CHAR_setInt(badindex,CHAR_FAME,0); + }else{ + CHAR_setInt(badindex,CHAR_FAME,CHAR_getInt(badindex,CHAR_FAME)-10000); + } + */ + char message[256]; + sprintf(message, "%s %s Զ %s ˣ˶Թֵ", CHAR_getUseName( enemyindex ), CHAR_getUseName( badindex ), CHAR_getUseName( badindex )); + int i; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, message, CHAR_COLORRED); + } + } + } + } + } +#endif + + int levelflg = 1; + // м ëƱ + // ì߶Ʊз зƱ + if( CHAR_getInt( enemyindex, CHAR_LV ) <= 10 ){ + levelflg = 2; + } + CHAR_AddCharm( enemyindex, CH_FIX_PLAYERDEAD/levelflg ); + // 帨ƻʸ ëƱ + pno = CHAR_getInt( enemyindex, CHAR_DEFAULTPET ); + if( 0 <= pno && pno < CHAR_MAXPETHAVE ){ + // ʸ̼͵ + pindex = CHAR_getCharPet( enemyindex, pno ); + if( CHAR_CHECKINDEX( pindex ) == TRUE ){ + CHAR_PetAddVariableAi( pindex, AI_FIX_PLAYERDEAD/levelflg ); + } + } + // Ϸƽҷ¼Ѩ٨ľ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + }else + // ʸئ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E + && BattleArray[battleindex].norisk == 0 + ){ + int levelflg = 1; + int playerindex = CHAR_getWorkInt( enemyindex, CHAR_WORKPLAYERINDEX ); + + // DZмì߶Ʊз зƱ + if( CHAR_getInt( playerindex, CHAR_LV ) <= 10 ){ + levelflg = 2; + } + // мëƱ + CHAR_PetAddVariableAi( enemyindex, AI_FIX_PETDEAD/levelflg ); + // DZмʸϷּë + CHAR_setInt( playerindex, CHAR_DEADPETCOUNT, + CHAR_getInt( playerindex, CHAR_DEADPETCOUNT ) + 1 ); + + // Ϸƽҷ¼Ѩ٨ľ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + }else{ + // ľ½ + } + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ʧȥʶ", + // CHAR_getUseName( enemyindex ) ); + + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + +} + +#ifndef DANTAI +void BATTLE_EscapeDpSend( int battleindex, int charaindex ) +{ + + int enemyside, cnt, dpadd; + BATTLE_ENTRY *pEntry; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ){ + return; + } + + if( BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + return; + } + if( BattleArray[battleindex].flg & BATTLE_FLG_FREEDP ){ + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, 0 ); + return ; + } + BattleArray[battleindex].flg |= BATTLE_FLG_CHARALOST; + enemyside = 1 - CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + pEntry = BattleArray[battleindex].Side[enemyside].Entry; + cnt = BATTLE_CountAlive( battleindex, enemyside ); + if( cnt == 0 )return; + + dpadd = CHAR_getInt( charaindex, CHAR_DUELPOINT ) * DUELPOINT_RATE; + + if( dpadd < 1 )dpadd = 1; + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, -dpadd*2 ); + dpadd /= cnt; + if( dpadd < 1 )dpadd = 1; + BATTLE_AddDpAlive( battleindex, enemyside, dpadd ); + + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + CHAR_setInt( charaindex, CHAR_DUELBATTLECOUNT, CHAR_getInt( charaindex, CHAR_DUELBATTLECOUNT ) + 1); + CHAR_setInt( charaindex, CHAR_DUELLOSECOUNT, CHAR_getInt( charaindex, CHAR_DUELLOSECOUNT ) + 1); + CHAR_setInt( charaindex, CHAR_DUELSTWINCOUNT, 0); + } + } +} +#else +void BATTLE_EscapeDpSend( int battleindex, int charaindex ) +{ + + int enemyside, dpadd; + BATTLE_ENTRY *pEntry; + + // Nuke 0725: Avoid too large number + if ((battleindex<0)||(battleindex>getBattlenum())) return; + // ½ + if( BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + return; + } + + // + enemyside = 1 - CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + + pEntry = BattleArray[battleindex].Side[enemyside].Entry; + + // 촡ë + dpadd = CHAR_getInt( charaindex, CHAR_DUELPOINT ) * DUELPOINT_RATE; + if( dpadd < 1 )dpadd = 1; // ƥ֨ + + // о¦л + CHAR_setWorkInt( charaindex, CHAR_WORKGETEXP, -dpadd*2 ); + + // 촡巴 + BattleArray[battleindex].Side[enemyside].common_dp += dpadd; + + +} +#endif + + +#ifndef DANTAI +int BATTLE_AddDuelPoint( int battleindex, int *pBidList ) +{ + int enemyindex, i, side, num, j, k, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy; + int allnum = 0; + int bid = pBidList[0]; + + if( pBidList < 0 )return BATTLE_ERR_PARAM; + if( bid >= SIDE_OFFSET ){ + num = bid - SIDE_OFFSET; + side = 1; + }else{ + num = bid ; + side = 0; + } + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + + for( i = 0; i < BATTLE_ENTRY_MAX + 1 ; i ++ ){ + charaindex[i] = -1; + } + + for( i = 0; i < BATTLE_ENTRY_MAX && pBidList[i] != -1 ; i ++ ){ + int work; + work = BATTLE_No2Index( battleindex, pBidList[i] ); + if( work < 0 )return BATTLE_ERR_PARAM; + if( CHAR_getInt( work, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + continue; + } + if( CHAR_getInt( work, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + work = CHAR_getWorkInt( work, CHAR_WORKPLAYERINDEX ); + } + if( work < 0 )return BATTLE_ERR_PARAM; + for( k = 0; k < allnum; k ++ ){ + if( charaindex[i] == work )break; + } + if( i < allnum )continue; + charaindex[i] = work; + allnum ++; + } + charaindex[i] = -1; + + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + int enemytype = 0; + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE){ + }else{ + continue; + } + enemytype = CHAR_getInt( enemyindex, CHAR_WHICHTYPE ); + if( enemytype == CHAR_TYPEPLAYER ){ + BattleArray[battleindex].flg |= BATTLE_FLG_CHARALOST; + } + if( enemytype == CHAR_TYPEPLAYER || enemytype == CHAR_TYPEENEMY ){ + int dpadd, dpnow; + dpnow = CHAR_getInt( enemyindex, CHAR_DUELPOINT ); + dpadd = dpnow * DUELPOINT_RATE; + + dpnow -= dpadd; + CHAR_setWorkInt( enemyindex, CHAR_WORKGETEXP, + CHAR_getWorkInt( enemyindex, CHAR_WORKGETEXP) - dpadd ); + + if( side != j ){ + for( k = 0; charaindex[k] != -1; k ++ ); + if( k <= 0 )k = 1; + dpadd /= k; + if( dpadd <= 0 ) dpadd = 1; + for( k = 0; charaindex[k] != -1; k ++ ){ + CHAR_setWorkInt( charaindex[k], CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex[k], CHAR_WORKGETEXP ) + dpadd ); + } + }else{ + int dpdiv = dpadd, alive; + alive = BATTLE_CountAlive( battleindex, 1-j ); + if( alive <= 0 )alive = 1; + dpdiv /= alive; + if( dpdiv <= 0 )dpdiv = 1; + BATTLE_AddDpAlive( battleindex, 1-j, dpdiv ); + } + } + CHAR_setFlg( enemyindex, CHAR_ISDIE, 1 ); + CHAR_setInt( enemyindex, CHAR_DEADCOUNT, + CHAR_getInt( enemyindex, CHAR_DEADCOUNT ) + 1 ); + if( pEntryEnemy[i].flg & BENT_FLG_ULTIMATE ){ + BATTLE_GetProfit( battleindex, j, i ); + BATTLE_UltimateExtra( battleindex, charaindex[0], enemyindex ); + }else{ + BATTLE_NormalDeadExtra( battleindex, charaindex[0], enemyindex ); + } + } + } + return 0; +} +#else + +int BATTLE_AddDuelPoint( + int battleindex, + int *pBidList ) +{ + int enemyindex, i, otherside, j, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy; + if( pBidList < 0 )return BATTLE_ERR_PARAM; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + otherside = 1 - j; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE){ + }else{ + continue; + } + + CHAR_setFlg( enemyindex, CHAR_ISDIE, 1 ); + CHAR_setInt( enemyindex, CHAR_DEADCOUNT, + CHAR_getInt( enemyindex, CHAR_DEADCOUNT ) + 1 ); + if( pEntryEnemy[i].flg & BENT_FLG_ULTIMATE ){ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int dpadd, dpnow; + dpnow = CHAR_getInt( enemyindex, CHAR_DUELPOINT ); + dpadd = dpnow * DUELPOINT_RATE; // м + dpnow -= dpadd; + CHAR_setWorkInt( enemyindex, CHAR_WORKGETEXP, + CHAR_getWorkInt( enemyindex, CHAR_WORKGETEXP) - dpadd ); + BattleArray[battleindex].Side[otherside].common_dp += dpadd; + BATTLE_GetProfit( battleindex, j, i ); + } + BATTLE_UltimateExtra( battleindex, charaindex[0], enemyindex ); + }else{ + BATTLE_NormalDeadExtra( battleindex, charaindex[0], enemyindex ); + } + } + } + return 0; +} +#endif + +int BATTLE_ItemDelCheck( int itemindex ) +{ int icnt, jcnt, playernum; + playernum = getFdnum(); + for( icnt = 0; icnt < playernum; icnt ++ ) { + if( CHAR_CHECKINDEX( icnt ) ) { +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(icnt); + for( jcnt = 0; jcnt < itemMax; jcnt ++ ) { +#else + for( jcnt = 0; jcnt < CHAR_MAXITEMHAVE; jcnt ++ ) { +#endif + if( CHAR_getItemIndex( icnt, jcnt ) == itemindex ) { + print( "err:սƷֵitem(%s)(%s)index(%d)\n", + CHAR_getUseName(icnt),ITEM_getAppropriateName(itemindex), + itemindex ); + return FALSE; + } + } + } + } + return TRUE; +} + +#ifdef _COMBO_EXP +int BATTLE_AddComboExp(int battleindex, int *pBidList){ + int enemyindex, i, side, num, proflg = 1, j, exp, k, enemylevel, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy; + int item=0,itemindex,itemloop,allnum = 0; + int bid = pBidList[0]; + if( pBidList[0] < 0 )return BATTLE_ERR_PARAM; + if( bid >= SIDE_OFFSET ){ + num = bid - SIDE_OFFSET; + side = 1; + }else{ + num = bid ; + side = 0; + } + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + for( i = 0; i < BATTLE_ENTRY_MAX + 1 ; i ++ ){ + charaindex[i] = -1; + } + + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_PLAYER + || BattleArray[battleindex].Side[1-side].type == BATTLE_S_TYPE_PLAYER){ + proflg = 0; + } + for( i = 0; i < BATTLE_ENTRY_MAX && pBidList[i] != -1 ; i ++ ){ + int subnum; + charaindex[i] = BATTLE_No2Index( battleindex, pBidList[i] ); + if( charaindex[i] < 0 )return BATTLE_ERR_PARAM; + } + + charaindex[i] = -1; + allnum = i; + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE ){ + }else{ + continue; + } + if( proflg == 1 && side != j ){ + + exp = CHAR_getInt( enemyindex, CHAR_EXP ); + enemylevel = CHAR_getInt( enemyindex, CHAR_LV ); + for( k = 0; charaindex[k] != -1; k ++ ){ + int nowexp, b_level; + int ridepet; + b_level = CHAR_getInt( charaindex[k], CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){// 5 + nowexp = exp; + }else{//춹5 + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + CHAR_setWorkInt( charaindex[k], CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex[k], CHAR_WORKGETEXP ) + nowexp ); + ridepet = BATTLE_getRidePet( charaindex[k] ); + //andy_edit + if( CHAR_CHECKINDEX( ridepet) ){ + int nowexp, b_level; + b_level = CHAR_getInt( ridepet, CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){ + nowexp = exp; + }else{ + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + nowexp *= 0.6; + CHAR_setWorkInt( ridepet, CHAR_WORKGETEXP, + CHAR_getWorkInt( ridepet, CHAR_WORKGETEXP ) + nowexp ); + } + } + } + } + } + return 0; +} +#endif +#ifdef _SHARE_EXP +int BATTLE_AddExp(int battleindex, int *pBidList){ + int enemyindex, i, side, num, proflg = 1, j, exp, k, enemylevel, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy, + *pEntryChara[BATTLE_ENTRY_MAX+1], + *pEntryPlayer[BATTLE_ENTRY_MAX+1]; + int item=0,itemindex,itemloop,allnum = 0; + int bid = pBidList[0]; + if( pBidList[0] < 0 )return BATTLE_ERR_PARAM; + if( bid >= SIDE_OFFSET ){ + num = bid - SIDE_OFFSET; + side = 1; + }else{ + num = bid ; + side = 0; + } + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + for( i = 0; i < BATTLE_ENTRY_MAX + 1 ; i ++ ){ + charaindex[i] = -1; + pEntryPlayer[i] = NULL; + } + + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_PLAYER + || BattleArray[battleindex].Side[1-side].type == BATTLE_S_TYPE_PLAYER){ + proflg = 0; + } + for( i = 0; i < BATTLE_ENTRY_MAX && pBidList[i] != -1 ; i ++ ){ + int subnum; + charaindex[i] = BATTLE_No2Index( battleindex, pBidList[i] ); + if( charaindex[i] < 0 )return BATTLE_ERR_PARAM; + subnum = pBidList[i]-side*SIDE_OFFSET; + pEntryChara[i] = &BattleArray[battleindex].Side[side].Entry[subnum]; + if( CHAR_getInt( charaindex[i], CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pEntryPlayer[i] = &BattleArray[battleindex].Side[side].Entry[subnum-5]; + }else{ + pEntryPlayer[i] = pEntryChara[i]; + } + } + + charaindex[i] = -1; + allnum = i; + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE ){ + }else{ + continue; + } + if( proflg == 1 && side != j ){ + + exp = CHAR_getInt( enemyindex, CHAR_EXP ); + enemylevel = CHAR_getInt( enemyindex, CHAR_LV ); + for( k = 0; charaindex[k] != -1; k ++ ){ + int nowexp, b_level; + int ridepet; + b_level = CHAR_getInt( charaindex[k], CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){// 5 + nowexp = exp; + }else{//춹5 + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + CHAR_setWorkInt( charaindex[k], CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex[k], CHAR_WORKGETEXP ) + nowexp ); + CHAR_setInt( charaindex[k], CHAR_KILLPETCOUNT, + CHAR_getInt( charaindex[k], CHAR_KILLPETCOUNT ) + 1 ); + ridepet = BATTLE_getRidePet( charaindex[k] ); + //andy_edit + if( CHAR_CHECKINDEX( ridepet) ){ + int nowexp, b_level; + b_level = CHAR_getInt( ridepet, CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){ + nowexp = exp; + }else{ + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + nowexp *= 0.6; + + CHAR_setWorkInt( ridepet, CHAR_WORKGETEXP, + CHAR_getWorkInt( ridepet, CHAR_WORKGETEXP ) + nowexp ); + CHAR_setInt( ridepet, CHAR_KILLPETCOUNT, + CHAR_getInt( ridepet, CHAR_KILLPETCOUNT ) + 1 ); + } + if( BattleArray[battleindex].norisk == 0 + && CHAR_getInt( charaindex[k], CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + if( CHAR_getInt( enemyindex, CHAR_LV ) > CHAR_getInt( charaindex[k], CHAR_LV ) ){ + CHAR_PetAddVariableAi( charaindex[k], AI_FIX_PETGOLDWIN ); + }else{ + CHAR_PetAddVariableAi( charaindex[k], AI_FIX_PETWIN ); + } + } + } + CHAR_setMaxExp( enemyindex, 0); + } + CHAR_setFlg( enemyindex, CHAR_ISDIE, 1 ); +#ifdef _PET_LIMITLEVEL + Pet_Check_Die( enemyindex ); +#endif + CHAR_setInt( enemyindex, CHAR_DEADCOUNT, + CHAR_getInt( enemyindex, CHAR_DEADCOUNT ) + 1 ); + if( pEntryEnemy[i].flg & BENT_FLG_ULTIMATE ){ + BATTLE_UltimateExtra( battleindex, charaindex[0], enemyindex ); + }else{ + BATTLE_NormalDeadExtra( battleindex, charaindex[0], enemyindex ); + } + } + } + return 0; +} + + int BATTLE_AddItem(int battleindex, int *pBidList){ + int enemyindex, i, side, num, proflg = 1, j, exp, k, enemylevel, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy, + *pEntryChara[BATTLE_ENTRY_MAX+1], + *pEntryPlayer[BATTLE_ENTRY_MAX+1]; + int item=0,itemindex,itemloop,allnum = 0; + int bid = pBidList[0]; + if( pBidList[0] < 0 )return BATTLE_ERR_PARAM; + if( bid >= SIDE_OFFSET ){ + num = bid - SIDE_OFFSET; + side = 1; + }else{ + num = bid ; + side = 0; + } + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + for( i = 0; i < BATTLE_ENTRY_MAX + 1 ; i ++ ){ + charaindex[i] = -1; + pEntryPlayer[i] = NULL; + } + + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_PLAYER + || BattleArray[battleindex].Side[1-side].type == BATTLE_S_TYPE_PLAYER){ + proflg = 0; + } + for( i = 0; i < BATTLE_ENTRY_MAX && pBidList[i] != -1 ; i ++ ){ + int subnum; + charaindex[i] = BATTLE_No2Index( battleindex, pBidList[i] ); + if( charaindex[i] < 0 )return BATTLE_ERR_PARAM; + subnum = pBidList[i]-side*SIDE_OFFSET; + pEntryChara[i] = &BattleArray[battleindex].Side[side].Entry[subnum]; + if( CHAR_getInt( charaindex[i], CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pEntryPlayer[i] = &BattleArray[battleindex].Side[side].Entry[subnum-5]; + }else{ + pEntryPlayer[i] = pEntryChara[i]; + } + } + + charaindex[i] = -1; + allnum = i; + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE ){ + }else{ + continue; + } + if( proflg == 1 && side != j ){ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) != CHAR_TYPEENEMY ){ + print( "\nerr: ȡսƷ(%s:%d)\n", + __FILE__, __LINE__ ); + } + for(item=CHAR_STARTITEMARRAY; item < CHAR_STARTITEMARRAY+10; item++){ + itemindex = CHAR_getItemIndex( enemyindex, item ); + if(ITEM_CHECKINDEX( itemindex ) == FALSE ){ + continue; + } + if( ITEM_getWorkInt( itemindex, ITEM_WORKCHARAINDEX ) <= getFdnum() ){ + print( "\nerr: ҵitemսƷ(%s:%d)\n", + __FILE__, __LINE__ ); + continue; + } + CHAR_setItemIndex( enemyindex, item, -1 ); + k = RAND( 0, (allnum-1) ); + for(itemloop=0;itemloop<3;itemloop++){ + if(pEntryPlayer[k]->getitem[itemloop]==-1){ + pEntryPlayer[k]->getitem[itemloop]=itemindex; + break; + } + } + if( itemloop >= 3 ){ + if( RAND( 0, 1 ) ) { + int olditem; + int randwork = RAND( 0, 2 ); + olditem = pEntryPlayer[k]->getitem[randwork]; + pEntryPlayer[k]->getitem[randwork]=itemindex; + if( BATTLE_ItemDelCheck( olditem ) == TRUE ){ + ITEM_endExistItemsOne(olditem); + } + }else { + ITEM_endExistItemsOne(itemindex); + } + } + } + } + } + } + return 0; + } + +#endif + + + int BATTLE_AddExpItem( int battleindex, int *pBidList ) + { + int enemyindex, i, side, num, proflg = 1, j, exp, k, enemylevel, + charaindex[BATTLE_ENTRY_MAX+1]; + BATTLE_ENTRY + *pEntryEnemy, + *pEntryChara[BATTLE_ENTRY_MAX+1], + *pEntryPlayer[BATTLE_ENTRY_MAX+1]; + int item=0,itemindex,itemloop,allnum = 0; + int bid = pBidList[0]; + if( pBidList[0] < 0 )return BATTLE_ERR_PARAM; + if( bid >= SIDE_OFFSET ){ + num = bid - SIDE_OFFSET; + side = 1; + }else{ + num = bid ; + side = 0; + } + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( num < 0 || num >= BATTLE_ENTRY_MAX )return BATTLE_ERR_PARAM; + for( i = 0; i < BATTLE_ENTRY_MAX + 1 ; i ++ ){ + charaindex[i] = -1; + pEntryPlayer[i] = NULL; + } + + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_PLAYER + || BattleArray[battleindex].Side[1-side].type == BATTLE_S_TYPE_PLAYER){ + proflg = 0; + } + for( i = 0; i < BATTLE_ENTRY_MAX && pBidList[i] != -1 ; i ++ ){ + int subnum; + charaindex[i] = BATTLE_No2Index( battleindex, pBidList[i] ); + if( charaindex[i] < 0 )return BATTLE_ERR_PARAM; + subnum = pBidList[i]-side*SIDE_OFFSET; + pEntryChara[i] = &BattleArray[battleindex].Side[side].Entry[subnum]; + if( CHAR_getInt( charaindex[i], CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pEntryPlayer[i] = &BattleArray[battleindex].Side[side].Entry[subnum-5]; + }else{ + pEntryPlayer[i] = pEntryChara[i]; + } + } + + charaindex[i] = -1; + allnum = i; + for( j = 0; j < 2; j ++ ){ + pEntryEnemy = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntryEnemy[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + + if( CHAR_getInt( enemyindex, CHAR_HP ) <= 0 + && CHAR_getFlg( enemyindex, CHAR_ISDIE ) == FALSE ){ + }else{ + continue; + } + if( proflg == 1 && side != j ){ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE ) != CHAR_TYPEENEMY ){ + print( "\nerr: ȡսƷ(%s:%d)\n", + __FILE__, __LINE__ ); + } + for(item=CHAR_STARTITEMARRAY; item < CHAR_STARTITEMARRAY+10; item++){ + itemindex = CHAR_getItemIndex( enemyindex, item ); + if(ITEM_CHECKINDEX( itemindex ) == FALSE ){ + continue; + } + if( ITEM_getWorkInt( itemindex, ITEM_WORKCHARAINDEX ) <= getFdnum() ){ + print( "\nerr: ҵitemսƷ(%s:%d)\n", + __FILE__, __LINE__ ); + continue; + } + CHAR_setItemIndex( enemyindex, item, -1 ); + k = RAND( 0, (allnum-1) ); + for(itemloop=0;itemloop<3;itemloop++){ + if(pEntryPlayer[k]->getitem[itemloop]==-1){ + pEntryPlayer[k]->getitem[itemloop]=itemindex; + break; + } + } + if( itemloop >= 3 ){ + if( RAND( 0, 1 ) ) { + int olditem; + int randwork = RAND( 0, 2 ); + olditem = pEntryPlayer[k]->getitem[randwork]; + pEntryPlayer[k]->getitem[randwork]=itemindex; + if( BATTLE_ItemDelCheck( olditem ) == TRUE ){ + ITEM_endExistItemsOne(olditem); + } + }else { + ITEM_endExistItemsOne(itemindex); + } + } + + } + + #define EXPGET_MAXLEVEL 5 + #define EXPGET_DIV 15 + exp = CHAR_getInt( enemyindex, CHAR_EXP ); + enemylevel = CHAR_getInt( enemyindex, CHAR_LV ); + for( k = 0; charaindex[k] != -1; k ++ ){ + int nowexp, b_level; + int ridepet; + b_level = CHAR_getInt( charaindex[k], CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){// 5 + nowexp = exp; + }else{//춹5 + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + CHAR_setWorkInt( charaindex[k], CHAR_WORKGETEXP, + CHAR_getWorkInt( charaindex[k], CHAR_WORKGETEXP ) + nowexp ); + CHAR_setInt( charaindex[k], CHAR_KILLPETCOUNT, + CHAR_getInt( charaindex[k], CHAR_KILLPETCOUNT ) + 1 ); + ridepet = BATTLE_getRidePet( charaindex[k] ); + //andy_edit + if( CHAR_CHECKINDEX( ridepet) ){ + int nowexp, b_level; + b_level = CHAR_getInt( ridepet, CHAR_LV ) - enemylevel; + if( b_level <= EXPGET_MAXLEVEL ){ + nowexp = exp; + }else{ + b_level = EXPGET_MAXLEVEL+EXPGET_DIV - b_level; + if( b_level > EXPGET_DIV ) b_level = EXPGET_DIV; + if( b_level <= 0 ){ + nowexp = 1; + }else{ + nowexp = exp * b_level / EXPGET_DIV; + } + if( nowexp < 1 ) nowexp = 1; + } + nowexp *= 0.6; + + CHAR_setWorkInt( ridepet, CHAR_WORKGETEXP, + CHAR_getWorkInt( ridepet, CHAR_WORKGETEXP ) + nowexp ); + CHAR_setInt( ridepet, CHAR_KILLPETCOUNT, + CHAR_getInt( ridepet, CHAR_KILLPETCOUNT ) + 1 ); + } + if( BattleArray[battleindex].norisk == 0 + && CHAR_getInt( charaindex[k], CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + if( CHAR_getInt( enemyindex, CHAR_LV ) > CHAR_getInt( charaindex[k], CHAR_LV ) ){ + CHAR_PetAddVariableAi( charaindex[k], AI_FIX_PETGOLDWIN ); + }else{ + CHAR_PetAddVariableAi( charaindex[k], AI_FIX_PETWIN ); + } + } + } + CHAR_setMaxExp( enemyindex, 0); + } + CHAR_setFlg( enemyindex, CHAR_ISDIE, 1 ); + #ifdef _PET_LIMITLEVEL + Pet_Check_Die( enemyindex ); + #endif + CHAR_setInt( enemyindex, CHAR_DEADCOUNT, + CHAR_getInt( enemyindex, CHAR_DEADCOUNT ) + 1 ); + if( pEntryEnemy[i].flg & BENT_FLG_ULTIMATE ){ + BATTLE_UltimateExtra( battleindex, charaindex[0], enemyindex ); + }else{ + BATTLE_NormalDeadExtra( battleindex, charaindex[0], enemyindex ); + } + } + } + return 0; + } + +#ifdef _PET_LIMITLEVEL +void Pet_Check_Die( int petindex ) +{ + + int LevelUpPoint; + int vital, str, tgh, dex; + float modai; + +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + // ۻԼҳ + if( CHAR_getInt( petindex, CHAR_PETID) == 718 ) { + LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + vital = (( LevelUpPoint >> 24 ) & 0xff); + str = (( LevelUpPoint >> 16 ) & 0xff); + tgh = (( LevelUpPoint >> 8 ) & 0xff); + dex = (( LevelUpPoint >> 0 ) & 0xff); +// enemyindex = pEntryEnemy[i].charaindex; + + print("\n lvup <<%d %d %d %d>>", vital, str, tgh, dex ); + + vital = vital - RAND( 1, 8); + str = str - RAND( 1, 4); + tgh = tgh - RAND( 1, 4); + dex = dex - RAND( 1, 4); + print("\n lvup <<%d %d %d %d>>", vital, str, tgh, dex ); + + if( vital < 0 ) vital = 0; + if( str < 0 ) str = 0; + if( tgh < 0 ) tgh = 0; + if( dex < 0 ) dex = 0; + + if( vital > 50 ) vital = 50; + if( str > 50 ) str = 50; + if( tgh > 50 ) tgh = 50; + if( dex > 50 ) dex = 50; + LevelUpPoint = ( vital << 24 ) + ( str << 16 ) + ( tgh << 8 ) + ( dex << 0 ); + CHAR_setInt( petindex, CHAR_ALLOCPOINT , LevelUpPoint ); + print("\n lvup <<%d %d %d %d>>", vital, str, tgh, dex ); + modai = CHAR_getInt( petindex, CHAR_MODAI ); + modai = modai - ( (modai * 5) / 100 ); + CHAR_setInt( petindex, CHAR_MODAI, modai); + + LogPetPointChange( + CHAR_getChar( petindex, CHAR_OWNERCHARANAME), + CHAR_getChar( petindex, CHAR_OWNERCDKEY), + CHAR_getChar( petindex, CHAR_NAME), + petindex, 2, + CHAR_getInt( petindex, CHAR_LV), + "battle_die(ս)", + CHAR_getInt( petindex,CHAR_FLOOR), + 0, + 0 + ); + } + return; + +} +#endif +/* +int BATTLE_AddProfit( int battleindex, int *pBidList) +{ + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + + if( BattleArray[battleindex].dpbattle == 1 ){ + return BATTLE_AddDuelPoint( battleindex, pBidList ); + }else{ +#ifdef _SHARE_EXP + if(getExpShare()==1 && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E){ + + if (pBidList[0] >= SIDE_OFFSET || pBidList[0] <0) + return BATTLE_AddExpItem( battleindex, pBidList ); + + int aAttackList[BATTLE_ENTRY_MAX+1]; + int i = 0; + int k = 0; + for(i=0;i= SIDE_OFFSET || pBidList[0] <0) + return BATTLE_AddExpItem( battleindex, pBidList ); + +#ifdef _COMBO_EXP + if (pBidList[0]>-1 && pBidList[1]>-1){ + BATTLE_AddComboExp( battleindex, pBidList ); + } +#endif + BATTLE_AddItem( battleindex, pBidList ); + int aAttackList[BATTLE_ENTRY_MAX+1]; + int i = 0; + int k = 0; + for(i=0;i= 0 ){ + hp = ((hp-downs)<1)?1:(hp-downs); + CHAR_setInt( charaindex, CHAR_HP, hp ); + *down1 = downs; + } + if( flg == -1 ) { + }else {//˳ + if( !CHAR_CHECKINDEX( rideindex)) return; + downs = + CHAR_getInt( rideindex, CHAR_VITAL ) + + CHAR_getInt( rideindex, CHAR_STR ) + + CHAR_getInt( rideindex, CHAR_DEX ) + + CHAR_getInt( rideindex, CHAR_TOUGH ); + if( (downs = (((downs/100)-20)/4)) < 1 ) + downs = 1; + pethp = CHAR_getInt( rideindex, CHAR_HP ); + if( pethp <= downs ) downs = pethp - 1; + if( downs >= 0 ){ + pethp = ((pethp-downs)<1)?1:(pethp-downs); + + CHAR_setInt( rideindex, CHAR_HP, pethp); + *down2 = downs; + } + } +} + +#ifdef _PET_SKILL_SARS // WON ADD ɷ +void Compute_Down_SARS( int charaindex, int rideindex, int *down1, int *down2, int flg) +{ + int hp=0, pethp=0; + int downs = 0; + + *down1 = 0; + *down2 = 0; + // +/* + downs = + CHAR_getInt( charaindex, CHAR_VITAL ) + + CHAR_getInt( charaindex, CHAR_STR ) + + CHAR_getInt( charaindex, CHAR_DEX ) + + CHAR_getInt( charaindex, CHAR_TOUGH ); + if( (downs = (((downs/100)-20)/4)) < 1 ) + downs = 1; +*/ + + hp = CHAR_getInt( charaindex, CHAR_HP ); + downs = hp * 10 / 100; + + if( hp <= downs ) downs = hp - 1; + if( downs >= 0 ){ + hp = ((hp-downs)<1)?1:(hp-downs); + CHAR_setInt( charaindex, CHAR_HP, hp ); + *down1 = downs; + } + if( flg == -1 ) { + }else {//˳ + if( !CHAR_CHECKINDEX( rideindex)) return; + downs = + CHAR_getInt( rideindex, CHAR_VITAL ) + + CHAR_getInt( rideindex, CHAR_STR ) + + CHAR_getInt( rideindex, CHAR_DEX ) + + CHAR_getInt( rideindex, CHAR_TOUGH ); + if( (downs = (((downs/100)-20)/4)) < 1 ) + downs = 1; + pethp = CHAR_getInt( rideindex, CHAR_HP ); + if( pethp <= downs ) downs = pethp - 1; + if( downs >= 0 ){ + pethp = ((pethp-downs)<1)?1:(pethp-downs); + + CHAR_setInt( rideindex, CHAR_HP, pethp); + *down2 = downs; + } + } +} +#endif + +#ifdef _PROFESSION_ADDSKILL +void WorkIceCrackPlay(int charaindex, int cnt, int workicecracknum ) +{ + char szBuffer[256]=""; + int i,value=0; + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + int defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 );//defNo = BATTLE_Index2No( battleindex, charaindex ); + int ridepet = BATTLE_getRidePet( charaindex ); + int bid = BATTLE_Index2No( battleindex, charaindex ); + value = CHAR_getWorkInt( charaindex, workicecracknum ); + + if( cnt <= 0 && value > 0 ){ + int damage=0, petdamage=0; + + int ToList[SIDE_OFFSET*2+1]; + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, TARGET_SIDE_1, ToList ); + // ħ붯 + analysis_profession_parameter( 2, 4, defNo, charaindex ); + PROFESSION_MAGIC_ATTAIC_Effect( battleindex, bid, ToList, 2); + + if( defNo == 20 || defNo == 25 || defNo == 26 )// + bid = 0; + else + bid = 10; + + + for( i = bid ; i < bid+10 ; i++ ) { + int defType, charaidx, petidx; + charaidx = BATTLE_No2Index( battleindex , i); + if( CHAR_CHECKINDEX( charaidx ) ){ + if( CHAR_getInt( charaidx, CHAR_HP ) > 0 ){ + int hp,pethp = 0; + petidx = BATTLE_getRidePet( charaidx ); + defType = CHAR_getInt(charaidx, CHAR_WHICHTYPE); + CHAR_setWorkInt( charaidx, workicecracknum, 0 ); + + damage = value; + + hp = CHAR_getInt( charaidx, CHAR_HP ); + if( petidx == -1 ) { + hp -= damage; + if( hp < 0 ) hp = 0; + }else { + int defquick=0, petquick=0, playerdamage=0; + pethp = CHAR_getInt( petidx, CHAR_HP ); + defquick = CHAR_getWorkInt( charaidx, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( petidx, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ){ + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else{ + hp -= damage; + } + if( hp < 0 ) hp = 0; + if( pethp < 0 ) pethp = 0; + CHAR_setInt( petidx, CHAR_HP, pethp ); + } + + CHAR_setInt( charaidx, CHAR_HP, hp ); + + if( hp <= 0 ){ + CHAR_setFlg( charaidx, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( charaidx, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + if( pethp <= 0 ){ + CHAR_setFlg( petidx, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( ridepet, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + + if( damage >= 0 ){ + sprintf( szBuffer , "%X|%X|%X|%X|" , i , i ,(int)(damage) , (int)(petdamage)); + BATTLESTR_ADD( szBuffer ); + } + if( petidx != -1 && petdamage >= 0 ){ + + } + } + } + } + sprintf( szBuffer , "%X|" , 0x5711438 ); + BATTLESTR_ADD( szBuffer ); + } +} +#endif + +static int BATTLE_StatusSeq( int charaindex ) +{ + int cnt, i, bid, battleindex, down; + char szBuffer[256]=""; +#ifdef _MAGIC_DEEPPOISON + int defNo,defindex=0; + char szCommand[1024]; +#endif + int ridepet = BATTLE_getRidePet( charaindex ); + int hp=0, pethp=0; + + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + +#ifdef _MAGIC_DEEPPOISON + defNo = BATTLE_Index2No( battleindex, charaindex ); + defindex = BATTLE_No2Index( battleindex, defNo ); +#endif + bid = BATTLE_Index2No( battleindex, charaindex ); + if( BATTLE_CanMoveCheck( charaindex ) == FALSE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + for( i = 1; i < BATTLE_ST_END; i++ ){ + if( ( cnt = CHAR_getWorkInt( charaindex, StatusTbl[i] )) <= 0 )continue; + CHAR_setWorkInt( charaindex, StatusTbl[i], --cnt ); +#ifdef _MAGIC_WEAKEN // + if(CHAR_getWorkInt(charaindex,CHAR_WORKWEAKEN) > 0) + CHAR_setWorkInt( charaindex, StatusTbl[i], cnt+1 ); +#endif +#ifdef _MAGIC_BARRIER// vincent :ħ + if(CHAR_getWorkInt(charaindex,CHAR_WORKBARRIER) > 0) + CHAR_setWorkInt( charaindex, StatusTbl[i], cnt+1 ); +#endif + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( cnt <= 0 && ( StatusTbl[i] != CHAR_WORKICECRACK ) +#ifdef _PROFESSION_ADDSKILL + && ( StatusTbl[i] != CHAR_WORKICECRACK2 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK3 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK4 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK5 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK6 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK7 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK8 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK9 ) + && ( StatusTbl[i] != CHAR_WORKICECRACK10 ) +#endif + ){ // +#else + if( cnt <= 0 ){ +#endif + BATTLE_BadStatusString( bid, 0 ); + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)(%s)ϡ", + // CHAR_getUseName( charaindex ), aszStatusFull[i] ); + // BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; +//Terry del +// sprintf( szBuffer, "BM|%X|%X|", bid, 0 ); +// BATTLESTR_ADD( szBuffer ); +#ifdef _MAGIC_NOCAST + if( StatusTbl[i] == CHAR_WORKNOCAST ){ + lssproto_NC_send( getfdFromCharaIndex( charaindex ), 0);//ԭ + } +#endif + if( StatusTbl[i] == CHAR_WORKDRUNK ){ + if( ridepet != -1 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, + CHAR_getWorkInt( charaindex, CHAR_WORKQUICK ) + + CHAR_getWorkInt( ridepet, CHAR_WORKQUICK ) ); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, + CHAR_getWorkInt( charaindex, CHAR_WORKQUICK ) * 2 ); + } + } + continue; + } + + switch( StatusTbl[i] ){ + + case CHAR_WORKPOISON: + { + int petdown=-1; + Compute_Down( charaindex, ridepet, &down, &petdown, ridepet); + if( down >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // down ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + +#ifdef _NOTRIDE_ + sprintf( szBuffer, "BD|r%X|0|0|%X|", bid, (int)(down) ); + BATTLESTR_ADD( szBuffer ); +#else + sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|", bid, (int)(down), (int)(petdown) ); + BATTLESTR_ADD( szBuffer ); +#endif + } + if( ridepet != -1 && petdown >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], petdown ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + } + break; +#ifdef _MAGIC_DEEPPOISON + case CHAR_WORKDEEPPOISON: + if(CHAR_getInt( defindex, CHAR_HP ) <= 1){ + snprintf( szCommand, sizeof( szCommand ),"Bd|a%X|r%X|f%X|d%X|p%X|FF|",defNo,defNo,BCF_NORMAL,1, 0 ); + BATTLESTR_ADD( szCommand ); + CHAR_setInt( defindex, CHAR_HP,0); + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setFlg( defindex, CHAR_ISDIE, 1 ); + break; + } + + if(CHAR_getWorkInt( defindex, CHAR_WORKDEEPPOISON) <= 1){ + snprintf( szCommand, sizeof( szCommand ),"Bd|a%X|r%X|f%X|d%X|p%X|FF|",defNo,defNo,BCF_NORMAL,CHAR_getInt( charaindex, CHAR_HP), 0 ); + BATTLESTR_ADD( szCommand ); + CHAR_setInt( defindex, CHAR_HP,0); + CHAR_setFlg( defindex, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + sprintf(szBuffer, "%sо綾δ!!", CHAR_getChar( defindex, CHAR_NAME )); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHAR_talkToCli( CHAR_getWorkInt(defindex, CHAR_WORKPLAYERINDEX), -1, szBuffer, CHAR_COLORYELLOW); + }else{ + CHAR_talkToCli( defindex, -1, szBuffer, CHAR_COLORYELLOW); + } + break; + } + if( ridepet == -1 ){// Robin 0728 ride Pet + down = + CHAR_getInt( charaindex, CHAR_VITAL ) + + CHAR_getInt( charaindex, CHAR_STR ) + + CHAR_getInt( charaindex, CHAR_DEX ) + + CHAR_getInt( charaindex, CHAR_TOUGH ); + down = ( down / 100 - 20 ) / 4; + if( down < 1 ) down = 1; + hp = CHAR_getInt( charaindex, CHAR_HP ); + if( hp <= down ) down = hp - 1; + if( down >= 0 ){ + CHAR_setInt( charaindex, CHAR_HP, hp - down ); + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // down ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; +#ifdef _NOTRIDE_ + sprintf( szBuffer, "BD|r%X|0|0|%X|", bid, (int)(down) ); + BATTLESTR_ADD( szBuffer ); +#else + sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|", bid, (int)(down), 0 ); + BATTLESTR_ADD( szBuffer ); +#endif + } + break; + }else { + int petdown; + down = + CHAR_getInt( charaindex, CHAR_VITAL ) + + CHAR_getInt( charaindex, CHAR_STR ) + + CHAR_getInt( charaindex, CHAR_DEX ) + + CHAR_getInt( charaindex, CHAR_TOUGH ); + petdown = + CHAR_getInt( ridepet, CHAR_VITAL ) + + CHAR_getInt( ridepet, CHAR_STR ) + + CHAR_getInt( ridepet, CHAR_DEX ) + + CHAR_getInt( ridepet, CHAR_TOUGH ); + down = ( down / 100 - 20 ) / 4; + petdown = ( petdown / 100 - 20 ) /4; + if( down < 1 ) down = 1; + if( petdown < 1 ) petdown = 1; + hp = CHAR_getInt( charaindex, CHAR_HP ); + pethp = CHAR_getInt( ridepet, CHAR_HP ); + if( hp <= down ) down = hp - 1; + if( pethp <= petdown ) petdown = pethp - 1; + if( down >= 0 ){ + CHAR_setInt( charaindex, CHAR_HP, hp - down ); + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // down ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + #ifdef _NOTRIDE_ + sprintf( szBuffer, "BD|r%X|0|0|%X|", bid, (int)(down) ); + BATTLESTR_ADD( szBuffer ); + #else + sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|", bid, (int)(down), (int)(petdown) ); + BATTLESTR_ADD( szBuffer ); + #endif + } + if( petdown >= 0 ){ + CHAR_setInt( ridepet, CHAR_HP, pethp - petdown ); + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // petdown ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + break; + } +#endif +#ifdef _MAGIC_NOCAST // :Ĭ + case CHAR_WORKNOCAST: + lssproto_NC_send( getfdFromCharaIndex( charaindex ), 1);//Ĭ + break; +#endif + case CHAR_WORKCONFUSION: + { int side, pos, defNo, lop; + if( RAND( 1, 100 ) > 80 ){ + break; + } + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + side = RAND( 0, 1 ); + pos = RAND( 0, 9 ); + for( lop = 0; lop < SIDE_OFFSET; lop ++ ){ + if( ++pos >= SIDE_OFFSET )pos = 0; + defNo = side * SIDE_OFFSET + pos; + if( defNo == bid ) continue; + if( BATTLE_TargetCheck( battleindex, defNo ) == TRUE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, defNo ); + break; + } + } + if( lop >= SIDE_OFFSET ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, -1 ); + } + } + break; +#ifdef _PROFESSION_ADDSKILL + case CHAR_WORKANNEX:// + { int side, pos, defNo, lop; + + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + side = RAND( 0, 1 ); + pos = RAND( 0, 9 ); + for( lop = 0; lop < SIDE_OFFSET; lop ++ ){ + if( ++pos >= SIDE_OFFSET )pos = 0; + defNo = side * SIDE_OFFSET + pos; + if( defNo == bid ) continue; + if( BATTLE_TargetCheck( battleindex, defNo ) == TRUE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, defNo ); + break; + } + } + if( lop >= SIDE_OFFSET ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, -1 ); + } + + } + break; +#endif + case CHAR_WORKDRUNK: + break; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + case CHAR_WORKOBLIVION: // + { + // ָ + if( cnt <= 1 ){ + int defNo = BATTLE_Index2No( battleindex, charaindex ); + int toNo = defNo - 5; + int toNoindex = -1, pet_no = -1; + char msg[20]; + + memset( msg, -1, sizeof(msg) ); + + // index + toNoindex = BATTLE_No2Index( battleindex, toNo ); + CHAR_setWorkInt(charaindex, StatusTbl[BATTLE_ST_OBLIVION], 0 ); + + // + pet_no = CHAR_getInt( toNoindex, CHAR_DEFAULTPET ); + sprintf( msg, "W%d", pet_no ); + + CHAR_sendStatusString( toNoindex, msg ); + + + BATTLE_BadStatusString( bid, 0 ); + sprintf( szBuffer, "BM|%X|%X|", bid, 0 ); + BATTLESTR_ADD( szBuffer ); + } + break; + } + case CHAR_WORK_F_ENCLOSE: // + { + int ToList[SIDE_OFFSET*2+1]; + int defNo = BATTLE_Index2No( battleindex, charaindex ); + int old_hp = CHAR_getInt( charaindex, CHAR_HP ); + int dec_hp = 0, hp = 0; + int DAMAGE = 50; + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo, ToList ); + BATTLE_MagicEffect( battleindex, defNo, ToList, 101699, 101699 ); + + // ȡħ˺ֵ + DAMAGE = DAMAGE * cnt; +#ifdef _PROFESSION_ADDSKILL + dec_hp = PROFESSION_MAGIC_GET_DAMAGE( charaindex, charaindex, 1, DAMAGE, 0); +#else + dec_hp = PROFESSION_MAGIC_GET_DAMAGE( charaindex, charaindex, 1, DAMAGE ); +#endif + hp = old_hp - dec_hp; + + if( hp <= 0 ){ + CHAR_setInt( charaindex, CHAR_HP, 0 ); + CHAR_setFlg( charaindex, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + }else{ + CHAR_setInt( charaindex, CHAR_HP, hp ); + } + + sprintf( szCommand, "BD|r%X|0|0|%X|", defNo, dec_hp ); + BATTLESTR_ADD( szCommand ); + + break; + } + case CHAR_WORK_I_ENCLOSE: // + { + int old_dex = CHAR_getInt( charaindex, CHAR_DEX ); + int dex = 0; + int ToList[SIDE_OFFSET*2+1]; + int defNo = BATTLE_Index2No( battleindex, charaindex ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo, ToList ); + BATTLE_MagicEffect( battleindex, defNo, ToList, 27692, 101700 ); + + dex = old_dex * 0.9; + CHAR_setWorkInt(charaindex,CHAR_WORKFIXDEX, dex ); + sprintf( szCommand, "BD|r%X|0|6|%X|", defNo, (-1) * (int)((old_dex * 0.1) / 100) ); + BATTLESTR_ADD( szCommand ); + + break; + } + case CHAR_WORKRESIST_F: // + { + // ָ + if( cnt <= 1 ){ + int add_value = 0; + int old_value = 0; + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_F_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_F ); + + CHAR_setWorkInt( charaindex, CHAR_WORK_F_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "Իָ" , CHAR_COLORYELLOW ); + } + break; + } + case CHAR_WORKRESIST_I: // + { + // ָ + if( cnt <= 1 ){ + int add_value = 0; + int old_value = 0; + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_I_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_I ); + + CHAR_setWorkInt( charaindex, CHAR_WORK_I_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "Իָ" , CHAR_COLORYELLOW ); + } + + break; + } + case CHAR_WORKRESIST_T: // ׿ + { + // ָ + if( cnt <= 1 ){ + int add_value = 0; + int old_value = 0; + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_T_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_T ); + + CHAR_setWorkInt( charaindex, CHAR_WORK_T_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "׿Իָ" , CHAR_COLORYELLOW ); + } + + break; + } +#ifdef _PROFESSION_ADDSKILL +/* case CHAR_WORKERSIST_F_I_T: // ׿ + { + // ָ + if( cnt <= 1 ){ + int add_value = 0; + int old_value = 0; + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_F_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_F ); + CHAR_setWorkInt( charaindex, CHAR_WORK_F_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "Իָ" , CHAR_COLORYELLOW ); + + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_I_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_I ); + CHAR_setWorkInt( charaindex, CHAR_WORK_I_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "Իָ" , CHAR_COLORYELLOW ); + + old_value = CHAR_getWorkInt( charaindex, CHAR_WORK_T_RESIST ); + add_value = CHAR_getWorkInt( charaindex, CHAR_WORKMODRESIST_T ); + CHAR_setWorkInt( charaindex, CHAR_WORK_T_RESIST, old_value - add_value ); + CHAR_talkToCli( charaindex, -1 , "׿Իָ" , CHAR_COLORYELLOW ); + } + + break; + }*/ + case CHAR_WORKFEAR: + if( cnt <= 0 ) + CHAR_talkToCli( charaindex, -1 , "ָ" , CHAR_COLORYELLOW ); + break; +#endif + case CHAR_WORKINSTIGATE: // + { + int side, pos, defNo, lop, rate=0; + if( RAND( 1, 100 ) > 80 ){ + break; + } + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + side = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + + rate = CHAR_getWorkInt( charaindex, CHAR_WORKMODINSTIGATE); + + CHAR_setWorkInt( charaindex, CHAR_WORKFIXSTR, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR) * (100 - rate) /100 )); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXTOUGH, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH) * (100 - rate) /100 )); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXDEX, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX) * (100 - rate) /100 )); + + pos = RAND( 0, 9 ); + for( lop = 0; lop < SIDE_OFFSET; lop ++ ){ + if( ++pos >= SIDE_OFFSET )pos = 0; + defNo = side * SIDE_OFFSET + pos; + if( defNo == bid ) continue; + if( BATTLE_TargetCheck( battleindex, defNo ) == TRUE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, defNo ); + break; + } + } + if( lop >= SIDE_OFFSET ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, -1 ); + } + break; + } +/* + case CHAR_WORK_FOCUS: // רעս + { + if( cnt <= 1 ){ + int atk_to_index = CHAR_getWorkInt( charaindex, CHAR_WORKMOD_FOCUS ); + int atk_to_no = BATTLE_Index2No( battleindex, atk_to_index ); + + if( BATTLE_TargetCheck( battleindex, atk_to_no ) != TRUE ) break; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, atk_to_no ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, 1 ); + } + break; + } +*/ + case CHAR_WORKSIGN: // һѪ + { + // Ѫ + int skill_level = CHAR_getWorkInt( charaindex, CHAR_WORKMODSIGN ); + int old_hp = CHAR_getInt( charaindex, CHAR_HP ); + int old_mp = CHAR_getInt( charaindex, CHAR_MP ); + int to_index = CHAR_getWorkInt( charaindex, CHAR_WORKSIGNID ); + int to_old_hp = CHAR_getInt( to_index, CHAR_HP ); + int to_old_mp = CHAR_getInt( to_index, CHAR_MP ); + int dec_hp=0, dec_mp=0, rate=0, hp=0, mp=0, add_hp=0, add_mp=0; + + if( old_hp <= 0 ) break; + +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ){ + dec_hp = 200; + dec_mp = 30; + }else if( skill_level > 6 ){ + dec_hp = 150; + dec_mp = 20; + }else if( skill_level > 3 ){ + dec_hp = 100; + dec_mp = 15; + }else{ + dec_hp = 50; + dec_mp = 10; + } + // hp + if( skill_level > 8 ) rate = 100; + else if( skill_level > 7 ) rate = 50; + else rate = 0; + add_hp = dec_hp * rate / 100; + + // mp + if( skill_level > 8 ) rate = 100; + else rate = 0; + add_mp = dec_mp * rate / 100; + +#else + if( skill_level >= 10 ){ + dec_hp = 300; + dec_mp = 70; + }else if( skill_level >= 9 ){ + dec_hp = 200; + dec_mp = 50; + }else if( skill_level >= 7 ){ + dec_hp = 150; + dec_mp = 30; + }else if( skill_level >= 4 ){ + dec_hp = 100; + dec_mp = 20; + }else{ + dec_hp = 50; + dec_mp = 10; + } + // hp + if( skill_level >= 9 ) rate = 80; + else if( skill_level >= 7 ) rate = (skill_level - 1 ) * 10; + else if( skill_level >= 4 ) rate = (skill_level - 2 ) * 10; + else rate = skill_level * 10; + add_hp = dec_hp * rate / 100; + + // mp + if( skill_level >= 9 ) rate = 100; + else if( skill_level >= 7 ) rate = (skill_level - 1 ) * 10; + else if( skill_level >= 4 ) rate = (skill_level - 2 ) * 10; + else rate = skill_level * 10; + add_mp = dec_mp * rate / 100; +#endif + + // ѪƵ˼ HP + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + mp = old_mp - dec_mp; + if( mp < 0 ){ + mp = 0; + add_mp=0; + } + CHAR_setInt(charaindex, CHAR_MP, mp); + } + + // ѪƵ˼ HP + if( ridepet == -1 ) { + hp = old_hp - dec_hp; + if( hp < 0 ) hp = 0; + CHAR_setInt(charaindex, CHAR_HP, hp); + sprintf( szCommand, "BD|r%X|0|0|%X|m%X|", bid, dec_hp, dec_mp ); + }else{ + int pet_old_hp = CHAR_getInt( ridepet, CHAR_HP ); + int pet_hp=0; + + dec_hp /= 2; + hp = old_hp - dec_hp; + pet_hp = pet_old_hp - dec_hp; + + if( hp < 0 ) hp = 0; + if( pet_hp < 0 ) pet_hp = 0; + + CHAR_setInt(charaindex, CHAR_HP, hp); + CHAR_setInt(ridepet, CHAR_HP, pet_hp); + if( pet_hp <= 0 ){ + CHAR_setFlg( ridepet, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( ridepet, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + sprintf( szCommand, "BD|r%X|0|0|%X|m%X|p%X|", bid, dec_hp, dec_mp, dec_hp ); + } + + if( hp <= 0 ){ + CHAR_setFlg( charaindex, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + BATTLESTR_ADD( szCommand ); + + // ʹѪƵ˼ HPMP + if( (add_hp > 0) && (to_old_hp > 0) ){ + int to_bid=0, to_hp=0, to_mp=0; + + to_bid = BATTLE_Index2No( battleindex, to_index ); + sprintf( szCommand, "BD|r%X|0|1|%X|m%X|", to_bid, add_hp, add_mp ); + BATTLESTR_ADD( szCommand ); + + to_hp = to_old_hp + add_hp; + if( to_hp > CHAR_getWorkInt( to_index , CHAR_WORKMAXHP ) ) + to_hp = CHAR_getWorkInt( to_index , CHAR_WORKMAXHP ); + + to_mp = to_old_mp + add_mp; + if( to_mp > CHAR_getWorkInt( to_index , CHAR_WORKMAXMP ) ) + to_mp = CHAR_getWorkInt( to_index , CHAR_WORKMAXMP ); + + CHAR_setInt(to_index, CHAR_HP, to_hp); + CHAR_setInt(to_index, CHAR_MP, to_mp); + } + + break; + } + case CHAR_WORKBLOODWORMS: // Ѫ + { + // Ѫ + int skill_level = CHAR_getWorkInt( charaindex, CHAR_WORKMODBLOODWORMS ); + int old_hp = CHAR_getInt( charaindex, CHAR_HP ); + int to_index = CHAR_getWorkInt( charaindex, CHAR_WORKBLOODWORMSID ); + int to_old_hp = CHAR_getInt( to_index, CHAR_HP ); + int dec_hp=0, rate=0, hp=0, add_hp=0; + + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( old_hp <= 0 ) break; + + dec_hp = skill_level * 10 + 30; + if( skill_level >= 10 ) rate = 20; + else if( skill_level >= 7 ) rate = 15; + else if( skill_level >= 5 ) rate = 10; + else rate = 5; + + add_hp = dec_hp * rate / 100; + + // ѪƵ˼ HP + if( ridepet == -1 ) { + hp = old_hp - dec_hp; + if( hp < 0 ) hp = 0; + + CHAR_setInt(charaindex, CHAR_HP, hp); + sprintf( szCommand, "BD|r%X|0|0|%X|", bid, dec_hp ); + }else{ + int pet_old_hp = CHAR_getInt( ridepet, CHAR_HP ); + int pet_hp=0; + + dec_hp /= 2; + hp = old_hp - dec_hp; + pet_hp = pet_old_hp - dec_hp; + + if( hp < 0 ) hp = 0; + if( pet_hp < 0 ) pet_hp = 0; + + CHAR_setInt(charaindex, CHAR_HP, hp); + CHAR_setInt(ridepet, CHAR_HP, pet_hp); + if( pet_hp == 0 ){ + CHAR_setFlg( ridepet, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( ridepet, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + sprintf( szCommand, "BD|r%X|0|0|%X|p%X|", bid, dec_hp, dec_hp ); + } + + if( hp <= 0 ){ + CHAR_setFlg( charaindex, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + BATTLESTR_ADD( szCommand ); + + // ʹѪƵ˼ HP + if( (add_hp > 0) && (to_old_hp > 0) ){ + int to_bid=0, to_hp=0; + + to_bid = BATTLE_Index2No( battleindex, to_index ); + sprintf( szCommand, "BD|r%X|0|1|%X|", to_bid, add_hp ); + BATTLESTR_ADD( szCommand ); + + to_hp = to_old_hp + add_hp; + if( to_hp > CHAR_getWorkInt( to_index , CHAR_WORKMAXHP ) ) + to_hp = CHAR_getWorkInt( to_index , CHAR_WORKMAXHP ); + + CHAR_setInt(to_index, CHAR_HP, to_hp); + } + + break; + } + case CHAR_WORKICEARROW: // + { + // + int dec_dex = CHAR_getWorkInt( charaindex, CHAR_WORKMODICEARROW ); + int old_dex = CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX ); + int dex=0; + + dex = old_dex * ( 100 - dec_dex ) / 100; + CHAR_setWorkInt(charaindex,CHAR_WORKFIXDEX, dex); + sprintf( szCommand, "BD|r%X|0|6|%X|", bid, (-1) * dec_dex ); + + BATTLESTR_ADD( szCommand ); + + break; + } + case CHAR_WORKICECRACK: // + { + int value=0; + int defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 );//defNo = BATTLE_Index2No( battleindex, charaindex ); + + value = CHAR_getWorkInt( charaindex, CHAR_WORKMODICECRACK ); + + if( cnt <= 0 && value > 0 ){ + int damage=0, petdamage=0; + + int ToList[SIDE_OFFSET*2+1]; + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, TARGET_SIDE_1, ToList ); + // ħ붯 + analysis_profession_parameter( 2, 4, defNo, charaindex ); + PROFESSION_MAGIC_ATTAIC_Effect( battleindex, bid, ToList, 2); + + if( defNo == 20 || defNo == 25 || defNo == 26 )// + bid = 0; + else + bid = 10; + + + for( i = bid ; i < bid+10 ; i++ ) { + int defType, charaidx, petidx; + charaidx = BATTLE_No2Index( battleindex , i); + if( CHAR_CHECKINDEX( charaidx ) ){ + if( CHAR_getInt( charaidx, CHAR_HP ) > 0 ){ + petidx = BATTLE_getRidePet( charaidx ); + defType = CHAR_getInt(charaidx, CHAR_WHICHTYPE); + CHAR_setWorkInt( charaidx, CHAR_WORKICECRACK, 0 ); + //BATTLE_BadStatusString( bid, 0 ); + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)(%s)ϡ", + // CHAR_getUseName( charaindex ), aszStatusFull[i] ); + // BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //sprintf( szBuffer, "BM|%X|%X|", bid, 0 ); + //BATTLESTR_ADD( szBuffer ); + + damage = value; + + hp = CHAR_getInt( charaidx, CHAR_HP ); + if( petidx == -1 ) { + hp -= damage; + if( hp < 0 ) hp = 0; + } + else{ + int defquick=0, petquick=0, playerdamage=0; + pethp = CHAR_getInt( petidx, CHAR_HP ); + defquick = CHAR_getWorkInt( charaidx, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( petidx, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ){ + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + } + else{ + hp -= damage; + } + if( hp < 0 ) hp = 0; + if( pethp < 0 ) pethp = 0; + CHAR_setInt( petidx, CHAR_HP, pethp ); + } + + CHAR_setInt( charaidx, CHAR_HP, hp ); + + if( hp <= 0 ){ + CHAR_setFlg( charaidx, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( charaidx, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + if( pethp <= 0 ){ + CHAR_setFlg( petidx, CHAR_ISDIE, 1 ); + CHAR_setWorkInt( ridepet, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + if( damage >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // damage ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + sprintf( szBuffer , "%X|%X|%X|%X|" , i , i ,(int)(damage) , (int)(petdamage)); + + //sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|", i, (int)(damage), (int)(petdamage) ); + BATTLESTR_ADD( szBuffer ); + } + if( petidx != -1 && petdamage >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], petdamage ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + } + } + } + sprintf( szBuffer , "%X|" , 0x5711438 ); + BATTLESTR_ADD( szBuffer ); + } + } + print("\n"); + break; +#ifdef _PROFESSION_ADDSKILL + case CHAR_WORKICECRACK2: // 2 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK2 );print("\n2");break; + case CHAR_WORKICECRACK3: // 3 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK3 );print("\n3");break; + case CHAR_WORKICECRACK4: // 4 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK4 );print("\n4");break; + case CHAR_WORKICECRACK5: // 5 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK5 );print("\n5");break; + case CHAR_WORKICECRACK6: // 6 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK6 );print("\n6");break; + case CHAR_WORKICECRACK7: // 7 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK7 );print("\n7");break; + case CHAR_WORKICECRACK8: // 8 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK8 );print("\n8");break; + case CHAR_WORKICECRACK9: // 9 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK9 );print("\n9");break; + case CHAR_WORKICECRACK10: // 10 + WorkIceCrackPlay( charaindex, cnt, CHAR_WORKICECRACK10 );print("\n10");break; +#endif //_PROFESSION_ADDSKILL + +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + case CHAR_WORKSARS: + { + int j; + int rate = 60; // Ⱦ SARS + + // ܴȾ + { + int petdown=-1; + int dec_mp = 0; + + Compute_Down_SARS( charaindex, ridepet, &down, &petdown, ridepet); + if( down >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], + // down ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + // ҿ MP + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int old_mp = CHAR_getInt( charaindex, CHAR_MP ); + dec_mp = old_mp / 10 ; + if( dec_mp < 0 ) dec_mp = 0; + CHAR_setInt( charaindex, CHAR_MP, old_mp - dec_mp ); + sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|m%X|", bid, (int)(down), (int)(petdown), dec_mp ); + }else + sprintf( szBuffer, "BD|r%X|0|0|%X|p%X|", bid, (int)(down), (int)(petdown) ); + + BATTLESTR_ADD( szBuffer ); + } + if( ridepet != -1 && petdown >= 0 ){ + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)ܵ(%d)ˡ", + // CHAR_getUseName( charaindex ), + // aszStatusFull[i], petdown ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + } + + // ȾߴSARS + if( CHAR_getWorkInt( charaindex, CHAR_WORKMODSARS ) > 0 ){ + int buf2[5], ti=0; + int tibuf[10]={ + 3,1,0,2,4, + 8,6,5,7,9 }; + + memset( buf2, -1, sizeof(buf2)); + + if( defNo > 9 ){ + for( j=0; j<10; j++ ){ + tibuf[j] += 10; + } + } + + for( j=0; j<10; j++){ + if( tibuf[j] != defNo ) continue; + if( j > 4 ){ + if( (j+1) < 10 ) buf2[ti++]=tibuf[j+1]; + if( (j-1) > 4 ) buf2[ti++]=tibuf[j-1]; + //ȱ + if( (j-5+1) < 5 ) buf2[ti++]=tibuf[j-5+1]; + if( (j-5-1) >= 0 ) buf2[ti++]=tibuf[j-5-1]; + if( (j-5) >= 0 ) buf2[ti++]=tibuf[j-5]; + }else{ + if( (j+1) < 5 ) buf2[ti++]=tibuf[j+1]; + if( (j-1) >= 0 ) buf2[ti++]=tibuf[j-1]; + //ȱ + if( (j+5+1) < 10 ) buf2[ti++]=tibuf[j+5+1]; + if( (j+5-1) > 4 ) buf2[ti++]=tibuf[j+5-1]; + if( (j+5) < 10 ) buf2[ti++]=tibuf[j+5]; + } + break; + } + + print("buf2[%d,%d,%d,%d,%d]\n", buf2[0], buf2[1], buf2[2], buf2[3], buf2[4]); + + for( j=0; j<5; j++ ){ + + int toindex = 0; + if( buf2[j] == -1 ) continue; + + toindex = BATTLE_No2Index( battleindex, buf2[j] ); + if( !CHAR_CHECKINDEX(toindex) )continue; + // õsars뿪 + if( CHAR_getWorkInt( toindex,CHAR_WORKSARS ) > 0 ) continue; + + if( RAND( 1, 100 ) <= rate ){ // SARS + if( toindex == charaindex ) continue; + if( CHAR_getInt( toindex, CHAR_HP ) <= 0 ) continue; + + CHAR_setWorkInt( toindex,CHAR_WORKSARS, 3 ); + } + } + } + } + break; +#endif + + default : + //snprintf( szBuffer, sizeof( szBuffer ), + // "(%s)(%s)", CHAR_getUseName( charaindex ), + // aszStatusFull[i] ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + break; + } + } + +#ifdef _SUIT_ITEM + { + int defCode; + int AddHp=0, AddMp=0; +#ifdef _IMPRECATE_ITEM + int nums1, nums2, nums3, delMp=0; +#endif + if( (defCode=CHAR_getWorkInt( charaindex, CHAR_WORKSUITITEM)) > 0){ + AddHp = CHAR_getWorkInt( charaindex, CHAR_WORKROUNDHP); + AddMp = CHAR_getWorkInt( charaindex, CHAR_WORKROUNDMP); + } + +#ifdef _IMPRECATE_ITEM + if( (nums1 = CHAR_getWorkInt( charaindex, CHAR_WORKIMPRECATENUM1)) > 0 ){ + delMp = CHAR_getWorkInt( charaindex, CHAR_WORKHURTMP); + CHAR_setWorkInt( charaindex, CHAR_WORKIMPRECATENUM1, nums1-1); + } + if( (nums2 = CHAR_getWorkInt( charaindex, CHAR_WORKIMPRECATENUM2)) > 0 ){ + AddHp += CHAR_getWorkInt( charaindex, CHAR_WORKWISHESHP); + CHAR_setWorkInt( charaindex, CHAR_WORKIMPRECATENUM2, nums2-1); + } + if( (nums3 = CHAR_getWorkInt( charaindex, CHAR_WORKIMPRECATENUM3)) > 0 ){ + AddMp += CHAR_getWorkInt( charaindex, CHAR_WORKWISHESMP); + CHAR_setWorkInt( charaindex, CHAR_WORKIMPRECATENUM3, nums3-1); + } + AddMp = AddMp - delMp; +#endif + if( AddHp != 0 || AddMp != 0 ) { + int AddPHp=0; + + +#ifdef _TYPE_TOXICATION + if( AddHp != 0 && CHAR_CanCureFlg( charaindex, "FALSE") != FALSE ){ +#else + if( AddHp != 0 ) { +#endif + int MyHp = CHAR_getInt( charaindex, CHAR_HP); + int MaxHp = CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP); + MyHp = ((MyHp+AddHp)>=MaxHp)?MaxHp:(MyHp+AddHp); + MyHp = (MyHp<= 1 )?1:MyHp; + CHAR_setInt( charaindex, CHAR_HP, MyHp); + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)(%d)HP", + // CHAR_getUseName( charaindex ), AddHp ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + if( ridepet != -1 ){ + int PetMaxHp = CHAR_getWorkInt( ridepet, CHAR_WORKMAXHP); + int PetHp = CHAR_getInt( ridepet, CHAR_HP); + AddPHp = AddHp; + PetHp = ((PetHp+AddPHp)>=PetMaxHp)?PetMaxHp:(PetHp+AddPHp); + PetHp = (PetHp<=1)?1:PetHp; + CHAR_setInt( ridepet, CHAR_HP, PetHp); + } + } + if( AddMp != 0 ) { + int MyMp = CHAR_getInt( charaindex, CHAR_MP); + int MaxMp = CHAR_getWorkInt( charaindex, CHAR_WORKMAXMP); + MyMp = ((MyMp+AddMp)>MaxMp)?MaxMp:(MyMp+AddMp); + MyMp = (MyMp<0)?0:MyMp; + CHAR_setInt( charaindex, CHAR_MP, MyMp); +/* +#ifdef _FIXITEMANISHOW + sprintf( szBuffer, "BD|r%X|0|1|%X|p%X|m%X|", bid, AddHp, AddPHp, AddMp); + }else { + sprintf( szBuffer, "BD|r%X|0|1|%X|p%X|", bid, AddHp, AddPHp ); +#else +*/ + sprintf( szBuffer, "BD|r%X|0|2|%X|p%X|m%X|", bid, AddHp, AddPHp, AddMp); + }else { + sprintf( szBuffer, "BD|r%X|0|2|%X|p%X|", bid, AddHp, AddPHp ); +//#endif + } + BATTLESTR_ADD( szBuffer ); + } + } +#endif +#ifdef _PETSKILL_SETDUCK + { + int turns=0, nums=0; + if( (turns=CHAR_getWorkInt( charaindex, CHAR_MYSKILLDUCK)) > 0 ){ + turns--; + if( turns == 0 ){ + nums = CHAR_getWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER); + sprintf( szBuffer, "BD|r%X|0|3|%X|", bid, nums*(-1)); + BATTLESTR_ADD( szBuffer ); + } + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCK, turns); + } +#ifdef _MAGICPET_SKILL + if( (turns=CHAR_getWorkInt( charaindex, CHAR_MYSKILLSTR)) > 0 ){ + turns--; + if( turns == 0 ){ + nums = CHAR_getWorkInt( charaindex, CHAR_MYSKILLSTRPOWER); + sprintf( szBuffer, "BD|r%X|0|4|%X|", bid, nums*(-1)); + BATTLESTR_ADD( szBuffer ); + } + CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTR, turns); + } + if( (turns=CHAR_getWorkInt( charaindex, CHAR_MYSKILLTGH)) > 0 ){ + turns--; + if( turns == 0 ){ + nums = CHAR_getWorkInt( charaindex, CHAR_MYSKILLTGHPOWER); + sprintf( szBuffer, "BD|r%X|0|5|%X|", bid, nums*(-1)); + BATTLESTR_ADD( szBuffer ); + } + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGH, turns); + } + if( (turns=CHAR_getWorkInt( charaindex, CHAR_MYSKILLDEX)) > 0 ){ + turns--; + if( turns == 0 ){ + nums = CHAR_getWorkInt( charaindex, CHAR_MYSKILLDEXPOWER); + sprintf( szBuffer, "BD|r%X|0|6|%X|", bid, nums*(-1)); + BATTLESTR_ADD( szBuffer ); + } + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEX, turns); + } +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( (turns=CHAR_getWorkInt( charaindex, CHAR_MYSKILLHIT)) > 0 ){ + turns--; + if( turns == 0 ){ + int dec_num = CHAR_getWorkInt( charaindex, CHAR_MYSKILLHIT_NUM); + nums = CHAR_getWorkInt( charaindex, CHAR_WORKHITRIGHT); + nums -= dec_num; + CHAR_setWorkInt( charaindex, CHAR_WORKHITRIGHT, nums); + + CHAR_talkToCli( charaindex, -1, "ָ", CHAR_COLORYELLOW); + //sprintf( szBuffer, "BD|r%X|0|6|%X|", bid, dec_num*(-1)); + //BATTLESTR_ADD( szBuffer ); + } + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT, turns); + } +#endif + +#endif + } +#endif + return 0; + +} + + +BOOL BATTLE_CanMoveCheck( int charaindex ) +{ + + // + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARALYSIS ) > 0 ){ + return FALSE; + } + + // ޼ + if( CHAR_getWorkInt( charaindex, CHAR_WORKSTONE ) > 0 ){ + return FALSE; + } + // Ի + if( CHAR_getWorkInt( charaindex, CHAR_WORKSLEEP ) > 0 ){ + return FALSE; + } +#ifdef _MAGIC_BARRIER + if( CHAR_getWorkInt( charaindex, CHAR_WORKBARRIER ) > 0 ){ + return FALSE; + } +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + // ѣ + if( CHAR_getWorkInt( charaindex, CHAR_WORKDIZZY ) > 0 ){ + return FALSE; + } + // ޵ + if( CHAR_getWorkInt( charaindex, CHAR_WORKDRAGNET ) > 0 ){ + return FALSE; + } +/* + // + if( CHAR_getWorkInt( charaindex, CHAR_WORKICEARROW ) > 0 ){ + return FALSE; + } +*/ +/* + // רעս + if( CHAR_getWorkInt( charaindex, CHAR_WORK_FOCUS ) > 0 ){ + return FALSE; + } +*/ + // ׸ + if( CHAR_getWorkInt( charaindex, CHAR_WORK_T_ENCLOSE ) > 0 ){ + return FALSE; + } +#endif +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) > 0 ){ + return FALSE; + } +#endif + return TRUE; +} + +#ifdef _ITEM_EQUITSPACE +int BATTLE_GetEqShield( int charaindex ) +{ + int iRet = ITEM_FIST, itemindex; + + itemindex = CHAR_getItemIndex( charaindex, CHAR_EQSHIELD ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE ){ + iRet = ITEM_FIST; + }else{ + iRet = ITEM_getInt( itemindex, ITEM_TYPE ); + } + return iRet; +} +#endif + +int BATTLE_GetWepon( int charaindex ) //ȡýɫֳ +{ + int iRet = ITEM_FIST, itemindex; + + itemindex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE ){ + iRet = ITEM_FIST; + }else{ + iRet = ITEM_getInt( itemindex, ITEM_TYPE ); + } + + return iRet; +} + +static int aBowW[50] = +{ + 0, 2, 1, 4, 3, 0, 1, 2, 3, 4, + 1, 0, 3, 2, 4, 1, 3, 0, 2, 4, + 2, 4, 0, 1, 3, 2, 0, 4, 1, 3, + 3, 1, 0, 2, 4, 3, 1, 0, 2, 4, + 4, 2, 0, 1, 3, 4, 2, 0, 1, 3, +}; + +void BATTLE_TargetListSet( int charaindex, int attackNo, int *pList) +{ + int i, j=0, defNo, battleindex=-1; + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + +#ifdef _PREVENT_TEAMATTACK +#ifdef _SKILLLIMIT // (ɿ) Syu ADD ùҷ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_FALLRIDE || // + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_WILDVIOLENTATTACK || //񱩹 + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_TIMID || // ս + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_MPDAMAGE || // MP + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_WEAKEN || // + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_DAMAGETOHP || // Ѫ + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_STEALMONEY ) { // + if( BATTLE_CheckSameSide( charaindex, defNo) == 1 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); +// BATTLE_NoAction( battleindex, attackNo ); + return; + } + } +#endif +#endif + + for( i = 0; i < BATTLE_ENTRY_MAX*2; i ++ ){ + pList[i] = defNo; + } +#ifdef _BATTLE_ATTCRAZED // ANDY +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTCRAZED || + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT ){ +#else + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTCRAZED ){ +#endif + int deftop,defsub; + int plive[10]; + int n = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + +#ifdef _PREVENT_TEAMATTACK +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if( BATTLE_CheckSameSide( charaindex, defNo) == 1 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + BATTLE_NoAction( battleindex, attackNo ); + return; + } +#endif +#endif + if( 0 <= defNo && defNo <= 9 ){ + defsub = 0; + deftop = 9; + }else if( 10 <= defNo && defNo <= 19 ){ + defsub = 10; + deftop = 19; + }else{ + pList[1] = -1; + return; + } + for( i = defsub; i < deftop; i ++ ){ + if( BATTLE_TargetCheck( battleindex, i) == FALSE ) continue; + plive[j++] = i; + } + if( j == 0 ) return; + for( i=0; i= CHAR_MAXPETSKILLHAVE ) i = 0; + + if( CHAR_getCharHaveSkill( charaindex, i ) == NULL ){ + continue; + } + + pskill_array = PETSKILL_GetArray( charaindex, i ); + skill_type = PETSKILL_getInt( pskill_array, PETSKILL_FIELD ); + + + if( skill_type == PETSKILL_FIELD_BATTLE + || skill_type == PETSKILL_FIELD_ALL + ){ + }else{ + continue; + } + + if( j < iNum ){ + j++; + continue; + } + + if(strcmp(PETSKILL_getChar( pskill_array, PETSKILL_FUNCNAME ), "PETSKILL_AttackMagic") == 0){ + continue; + } + + if(strcmp(PETSKILL_getChar( pskill_array, PETSKILL_FUNCNAME ), "PETSKILL_Combined") == 0){ + continue; + } + + if( PETSKILL_Use( charaindex, iNum, toNo, NULL ) == TRUE ){ + + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + break; + } + + if( k >= PETSKILLSERCHTIME ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + return 0; +} + + +enum{ + PETAI_MODE_NORMAL, + PETAI_MODE_TARGETRANDOM, + PETAI_MODE_RANDOMACT, + PETAI_MODE_OWNERATTACK, + PETAI_MODE_ENEMYATTACK, + PETAI_MODE_ESCAPE, + PETAI_MODE_NOACT, + PETAI_MODE_END +}; + +static int BATTLE_PetLoyalCheck( int battleindex, int bid, int charaindex ) +{ + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) { + return FALSE; + } + if( CHAR_CHECKINDEX( charaindex) == FALSE ) + return FALSE; + + int ai, toNo, mode = 0, type, Rand, toSide = 1, flg, i; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPET ){ + return 0; + } + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ) + return 0; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_WAIT ){ + return 0; + } + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); + flg &= ~CHAR_BATTLEFLG_AIBAD; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + if( BATTLE_CanMoveCheck( charaindex ) == FALSE ){ + return 0; + } + toNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + toSide = ( 0 <= toNo && toNo < BATTLE_ENTRY_MAX )?(0):(1); + ai = CHAR_getWorkInt( charaindex, CHAR_WORKFIXAI ); + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + || bid == toNo + ){ + type = 1; + }else{ + type = 0; + } + + Rand = RAND( 1, 100 ); + + mode = 0; // е + if( ai >= 80 ){ // պߡѶ + mode = PETAI_MODE_NORMAL; // 姸 + }else + if( ai >= 70 ){ // պߡѶ + if( Rand < 10 )mode = PETAI_MODE_TARGETRANDOM; // + }else + if( ai >= 60 ){ + if( Rand < 20 )mode = PETAI_MODE_TARGETRANDOM; // + }else + if( ai >= 50 ){ + if( Rand < 35 )mode = PETAI_MODE_TARGETRANDOM; // + }else + if( ai >= 40 ){ + if( Rand < 50 )mode = PETAI_MODE_TARGETRANDOM; // + }else + if( ai >= 30 ){ + if( Rand < 70 )mode = PETAI_MODE_RANDOMACT; // ¼ĸة + }else + if( ai >= 20 ){ + if( Rand < 70 )mode = PETAI_MODE_RANDOMACT; // ¼ĸة + }else + if( ai >= 10 ){ + if( Rand < 80 ){ + mode = PETAI_MODE_OWNERATTACK; // DZ + }else{ + mode = PETAI_MODE_ENEMYATTACK; // + } + }else{ + if( Rand < 60 ){ + mode = PETAI_MODE_OWNERATTACK; // DZ + }else{ + mode = PETAI_MODE_ESCAPE; // + } + } + + + if( mode == PETAI_MODE_NORMAL )return 0; + + for( i = 0; i < CHAR_MAXPETSKILLHAVE;i ++ ){ + if( CHAR_getCharHaveSkill( charaindex, i ) ){ + break; + } + } + if( i >= CHAR_MAXPETSKILLHAVE ){ + mode = PETAI_MODE_NOACT; + } + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); + flg |= CHAR_BATTLEFLG_AIBAD; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + + + switch( mode ){ + case PETAI_MODE_NOACT: + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, + BATTLE_COM_NONE ); + break; + case PETAI_MODE_TARGETRANDOM: + if( type == 1 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, + BATTLE_COM_NONE ); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, + BATTLE_DefaultAttacker( battleindex, toSide ) ); + + } + break; + case PETAI_MODE_RANDOMACT: // ¼ĸة + // Ѩ 󡷴姸ĸ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ){ + return 0; + } + + // ūʧ׷ºë + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); + flg &= ~CHAR_BATTLEFLG_GUARDIAN; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + + if( toNo == bid ){ // ëƥ + // ƥئг + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + }else{ + // ¼ĸة ë + BATTLE_PetRandomSkill( battleindex, charaindex ); + } + break; + + case PETAI_MODE_OWNERATTACK: // DZ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, bid-5 ); + break; + + case PETAI_MODE_ENEMYATTACK: // + { int myside = 0; + if( bid >= BATTLE_ENTRY_MAX ) myside = 1; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + // + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, + BATTLE_DefaultAttacker( battleindex, 1 - myside ) ); + } + break; + + case PETAI_MODE_ESCAPE: // ¹ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_LOSTESCAPE ); + break; + + } + + return 1; + +} + +#ifdef _ATTACK_MAGIC + +#define MAX_MAGIC_NUMBER 25 + +// ÿһħĹ Χ (id,area) +int TargetIndex[MAX_MAGIC_NUMBER][2] = +{ + {301,-1},{302,-1},{303,26},{304,-1},{305,20},{306,20}, + {307,-1},{308,-1},{309,-1},{310,-1},{311,26},{312,20}, + {313,-1},{314,-1},{315,-1},{316,-1},{317,26},{318,20}, + {319,-1},{320,-1},{321,26},{322,-1},{323,26},{324,20},{325,20} +}; + +int magic,toindex,magic_count; + +#endif + +static int BATTLE_Battling( int battleindex ) +{ + BATTLE *pBattle, *pWatchBattle; + BATTLE_ENTRY *pEntry[2]; + char *aszFieldAttr[] = { "", "", "ˮ", "", "" }, + szBuffer[256]="", + szWork[256]; + int i,j,k, + len, + entrynum, + charaindex, + attackNo, + defNo=-1, + aAttackList[BATTLE_ENTRY_MAX*2+1], + aDefList[BATTLE_ENTRY_MAX*2+1], + ComboId, + itemindex, + AllSize = 0; + BATTLE_CHARLIST EntryList[40]; + int ContFlg, attackNoSub, defNoSub; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + pBattle = &BattleArray[battleindex]; + pEntry[0] = pBattle->Side[0].Entry; + pEntry[1] = pBattle->Side[1].Entry; + + for( i = 0; i < arraysizeof(EntryList); i ++ ){ + EntryList[i].charaindex = -1; + EntryList[i].combo = 0; + } + sprintf( szBuffer, "ս %d ת %d %s", + battleindex, pBattle->turn, + aszFieldAttr[pBattle->field_att] + ); + + entrynum = 0; + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pEntry[j][i].flg &= ~BENT_FLG_ULTIMATE; + if(!CHAR_CHECKINDEX(pEntry[j][i].charaindex))continue; + EntryList[entrynum].charaindex = pEntry[j][i].charaindex; + EntryList[entrynum].side = j; + EntryList[entrynum].num = pEntry[j][i].bid; + EntryList[entrynum].dex = BATTLE_DexCalc( pEntry[j][i].charaindex ); +#ifdef _EQUIT_SEQUENCE + EntryList[entrynum].sequence = CHAR_getWorkInt( pEntry[j][i].charaindex, CHAR_WORKSEQUENCEPOWER); +#endif + BATTLE_talkToCli( pEntry[j][i].charaindex, szBuffer, CHAR_COLORYELLOW ); + entrynum ++; + } + } + szAllBattleString[0] = 0; + k = 0; + for( j = 0; j < 2; j ++ ){ + k = j * SIDE_OFFSET; + for( i = 0; i < BATTLE_ENTRY_MAX/2; i ++ ){ + szBattleString[0] = 0; + if( pBattle->iEntryBack[k] >= 0 + && pBattle->Side[j].Entry[i].charaindex == -1){ + if( pBattle->iEntryBack2[k] >= 0 ){ + sprintf( szBattleString, "BE|et%X|f1|", k ); + //BATTLE_BroadCast( battleindex, "ͻȻ˲ˡ", CHAR_COLORYELLOW ); + }else{ + print( "ӦIDȷֵerror\n" ); + //BATTLE_BroadCast( battleindex, "IDerror", CHAR_COLORYELLOW ); + } + } + k ++; + strcat( szAllBattleString, szBattleString ); + } + } + len = strlen( szAllBattleString ); + AllSize += len; + EntrySort( EntryList, entrynum ); + ComboCheck( EntryList, entrynum ); + for( i = 0; i < entrynum; i ++ ){ + int COM, myside, otherside, bi, + attack_flg = 1, + attack_max = 1, + attack_count = 0; + charaindex = EntryList[i].charaindex; + myside = EntryList[i].side; + otherside = 1-myside; + attackNo = EntryList[i].num; + bi = attackNo - myside * SIDE_OFFSET; + aAttackList[0] = attackNo; + aAttackList[1] = -1; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE )continue; + szBadStatusString[0] = 0; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + != BATTLE_CHARMODE_C_OK ){ + //sprintf( szBuffer, "ָ벻ȫ(%s)", CHAR_getUseName( charaindex ) ); + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + continue; + } + if( CHAR_getInt( charaindex, CHAR_HP ) <= 0 )continue; + +#ifdef _ABSOLUTE_DEBUG + comnum = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); +#endif + szBattleString[0] = 0; + pszBattleTop = szBattleString; + pszBattleLast = szBattleString+arraysizeof(szBattleString); + // WON ADD + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) != TRUE ) + BATTLE_StatusSeq( charaindex ); +#ifdef _OTHER_MAGICSTAUTS + BATTLE_MagicStatusSeq( charaindex ); +#endif +#ifdef _MAGIC_DEEPPOISON // 綾 + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + BATTLE_ProfessionStatusSeq( battleindex, charaindex); +#endif + + if( BATTLE_CanMoveCheck( charaindex ) == FALSE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + gBattleDamageModyfy = 1.0; + gBattleDuckModyfy = 0; + gBattleStausChange = -1; + gBattleStausTurn = 0; + gWeponType = ITEM_FIST; + gWeponType = BATTLE_GetWepon( charaindex ); +#ifdef _PETSKILL_BECOMEFOX + if( CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 //DZС + || CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101749) + { + int COM = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + gWeponType = ITEM_FIST; + + if( !(COM == BATTLE_COM_ATTACK + || COM == BATTLE_COM_GUARD + || COM == BATTLE_COM_NONE) ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_talkToCli( charaindex, -1, "Сֻܹʹ", CHAR_COLORYELLOW ); + } + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 // + && (CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) ) + { + int COM = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + gWeponType = ITEM_FIST; + //CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + if( !(COM == BATTLE_COM_ATTACK + || COM == BATTLE_COM_GUARD + || COM == BATTLE_COM_NONE + || COM == BATTLE_COM_ITEM + || COM == BATTLE_COM_ESCAPE + || COM == BATTLE_COM_CAPTURE + || COM == BATTLE_COM_WAIT + || COM == BATTLE_COM_PETIN + || COM == BATTLE_COM_PETOUT) ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + //CHAR_talkToCli( charaindex, -1, "ֻܹܺʹõߣ", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex, -1, "᲻ʹְҵܣ", CHAR_COLORYELLOW ); + } + } +#endif + gDamageDiv = 1.0; + attack_max = BATTLE_GetAttackCount( charaindex ); + if( attack_max <= 0 ){ + int work, randwork; + work = CHAR_getInt( charaindex, CHAR_LV ); + if( work < 10 || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + attack_max = 1; + }else{ + int luckwork = CHAR_getInt( charaindex, CHAR_LUCK )*5; + if( luckwork > 5*5 ){ + print( "\nerr:(%s)(%d)\n", + CHAR_getUseName( charaindex ), + CHAR_getInt( charaindex, CHAR_LUCK ) ); + luckwork = 5*5; + } + randwork = RAND( 1, 1000 ); + if( randwork <= 10 + luckwork){ + attack_max = RAND( 5, 10 ); + }else + if( randwork <= 30 + luckwork ){ + attack_max = 3; + }else + if( randwork <= 70 + luckwork ){ + attack_max = 2; + }else{ + attack_max = 1; + } + } + }else{ + if( gWeponType == ITEM_FIST )gDamageDiv = attack_max; + } + if( gWeponType == ITEM_BREAKTHROW ){ + gBattleStausChange = BATTLE_ST_PARALYSIS; + gBattleStausTurn = 1-1; + }else{ + } + + if( BattleArray[battleindex].Side[myside].flg & BSIDE_FLG_SURPRISE ){ + }else{ + if( BATTLE_PetLoyalCheck( battleindex, attackNo, charaindex ) ) { +#ifdef _FIXWOLF // Syu ADD ˱Bug + if ( CHAR_getInt ( charaindex , CHAR_BASEIMAGENUMBER) == 101428 +#ifdef _EXPANSION_VARY_WOLF + ||CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==104109 +#endif + ) { + if( CHAR_getWorkInt ( charaindex , CHAR_WORKTURN ) == 0){ + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex , CHAR_BASEBASEIMAGENUMBER)); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex , CHAR_WORKFIXSTR)); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex , CHAR_WORKFIXDEX)); + } + } +#endif + sprintf( szWork, "BX|%X|", attackNo); + BATTLESTR_ADD( szWork ); + } + } +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) > 0 ){ + CHAR_setWorkInt( charaindex, CHAR_DOOMTIME, CHAR_getWorkInt( charaindex, CHAR_DOOMTIME) - 1 ); + } + if( CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) == 0 + && ( CHAR_getWorkInt( charaindex, CHAR_WORK_com1 ) == BATTLE_COM_S_FIRE_SPEAR + || CHAR_getWorkInt( charaindex, CHAR_WORK_com1 ) == BATTLE_COM_S_DOOM ) ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, CHAR_getWorkInt( charaindex, CHAR_WORK_com1 ) ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, CHAR_getWorkInt( charaindex, CHAR_WORK_toNo ) ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, CHAR_getWorkInt( charaindex, CHAR_WORK_mode ) ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, CHAR_getWorkInt( charaindex, CHAR_WORK_skill_level ) ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, CHAR_getWorkInt( charaindex, CHAR_WORK_array ) ); + CHAR_setWorkInt( charaindex, CHAR_WORK_com1, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_toNo, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_mode, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_skill_level, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_array, 0 ); + } + +#endif + COM = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + //printf("=%s COM=%d\n",CHAR_getChar(charaindex,CHAR_NAME),COM); + + switch( COM ){ + case BATTLE_COM_ATTACK: + if( gWeponType == ITEM_BOOMERANG ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_BOOMERANG ); + +#ifdef _PETSKILL_BECOMEFOX + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101749 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС겻ʹû + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 ){// + gWeponType = ITEM_FIST; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + } +#endif + } + break; + case BATTLE_COM_COMBO: + if( ComboCheck2( EntryList, i, entrynum ) == FALSE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + } + break; + + case BATTLE_COM_S_STATUSCHANGE: + gBattleStausChange = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ); + gBattleStausTurn = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ); + break; + +#ifdef _PETSKILL_HECTOR + case BATTLE_COM_S_HECTOR: + gBattleStausChange = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ); + gBattleStausTurn = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ); + break; +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + case BATTLE_COM_S_SARS: + gBattleStausChange = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ); + gBattleStausTurn = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ); + break; +#endif + + case BATTLE_COM_S_CHARGE: + BATTLE_Charge( battleindex, attackNo ); + break; + case BATTLE_COM_S_RENZOKU: + attack_max = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ); + gDamageDiv = attack_max; + break; +#ifdef _VARY_WOLF + case BATTLE_COM_S_VARY: + // ò + break; +#endif +#ifdef _SKILL_WILDVIOLENT_ATT + //񱩹 vincent add 2002/05/16 + case BATTLE_COM_S_WILDVIOLENTATTACK: + attack_max = RAND(3,10);// + gDamageDiv = attack_max;//ÿι˺ + gBattleDuckModyfy = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 );// + break; +#endif + case BATTLE_COM_S_EARTHROUND0: + gBattleDamageModyfy = 1.0 + 0.01 * CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM3 ); + break; +#ifdef _BATTLE_ATTCRAZED + case BATTLE_COM_S_ATTCRAZED: + attack_max = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + break; +#endif +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + case BATTLE_COM_S_ATTSHOOT: + attack_max = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + gDamageDiv = attack_max;//ÿι˺ + break; +#endif + case BATTLE_COM_S_MIGHTY: + gBattleDamageModyfy = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ) * 0.01; + gBattleDuckModyfy = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ); // ľĤɧٳ + break; + } + + BATTLE_TargetListSet( charaindex, attackNo, aDefList ); + COM = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + + ContFlg = FALSE; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_AIBAD + && COM == BATTLE_COM_COMBO ){ + print( "ҳ϶Ȳʹñɱʧ(%s)\n", CHAR_getUseName( charaindex ) ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + } +#ifdef _BATTLE_TIMESPEED//ٶ + { + int flgtime = 0; + switch( COM ){ +#ifdef _BATTLE_ATTCRAZED + case BATTLE_COM_S_ATTCRAZED: + flgtime = 200*3; + break; +#endif +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + case BATTLE_COM_S_ATTSHOOT: + flgtime = 80*attack_max; + break; +#endif + case BATTLE_COM_JYUJYUTU: + case BATTLE_COM_S_ATTACK_MAGIC: + flgtime = 260; // 1/100sec + break; + case BATTLE_COM_COMBO: + flgtime = 200; // 1/100sec + break; + case BATTLE_COM_GUARD: + break; + case BATTLE_COM_WAIT: + default : + flgtime = 150; // 1/100sec + break; + } + BattleArray[battleindex].flgTime += flgtime; + } +#endif +#ifdef _PETSKILL_BECOMEFOX // Ļṥ 20% + if( CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //С + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.8);//20% + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.8);//20% + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*0.8);//20% + } +#endif + switch( COM ){// + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + //==== ֱӹϵ =============================================================== + case BATTLE_COM_S_BRUST: // + case BATTLE_COM_S_CHAIN_ATK: // + case BATTLE_COM_S_CHAIN_ATK_2: // ˫ع + case BATTLE_COM_S_CAVALRY: // ﹥ + case BATTLE_COM_S_DEAD_ATTACK: // + case BATTLE_COM_S_ATTACK_WEAK: // 㹥 + case BATTLE_COM_S_PLUNDER: // Ӷ + case BATTLE_COM_S_CHAOS: // ҹ +#ifdef _PREVENT_TEAMATTACK + { + // ֹͬӻ + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + if( BATTLE_CheckSameSide( charaindex, defNo) == 1 ){ + BATTLE_NoAction( battleindex, attackNo ); break; + } + } +#endif + case BATTLE_COM_S_ENRAGE_PET: // ŭ + { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + battle_profession_attack_fun(battleindex, attackNo, defNo, charaindex); + //change fix ʹְҵò + //BATTLE_AddProfit( battleindex, aAttackList); + } + break; + //==== ħϵ ================================================================ + case BATTLE_COM_S_VOLCANO_SPRINGS: // ɽȪ + case BATTLE_COM_S_FIRE_BALL: // + case BATTLE_COM_S_FIRE_SPEAR: // ǹ + case BATTLE_COM_S_SUMMON_THUNDER: // + case BATTLE_COM_S_CURRENT: // + case BATTLE_COM_S_STORM: // + case BATTLE_COM_S_ICE_ARROW: // + case BATTLE_COM_S_ICE_CRACK: // + case BATTLE_COM_S_ICE_MIRROR: // + case BATTLE_COM_S_DOOM: // ĩ + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + case BATTLE_COM_S_SIGN: // һѪ + case BATTLE_COM_S_ENCLOSE: // + case BATTLE_COM_S_THROUGH_ATTACK: // ᴩ + case BATTLE_COM_S_CONVOLUTE: // + { +#ifdef _PROFESSION_ADDSKILL + /* if( COM == BATTLE_COM_S_DOOM //ĩռ + || COM == BATTLE_COM_S_FIRE_SPEAR){ + if( CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) > 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + sprintf( szWork, "bt|%x|", attackNo ); + BATTLESTR_ADD( szWork ); + break; + } + }*/ +#endif +#ifdef _PREVENT_TEAMATTACK + // ֹͬӻ + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + if( BATTLE_CheckSameSide( charaindex, defNo) == 1 ){ + BATTLE_NoAction( battleindex, attackNo ); break; + } +#endif + } + case BATTLE_COM_S_BLOOD: // Ѫ + { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); +#if 1 // Robin fix Ѫ˵Ѫ + if( defNo != attackNo && COM == BATTLE_COM_S_BLOOD ){ + print("\n ķ!Ѫ˵Ѫ!!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + defNo = attackNo; + + CHAR_talkToCli( charaindex, -1, "쳣ߡ", CHAR_COLORYELLOW); + CONNECT_setCloseRequest( CHAR_getWorkInt( charaindex, CHAR_WORKFD ) , 1 ); + break; + } +#endif +#ifdef _PROFESSION_ADDSKILL + if( COM == BATTLE_COM_S_ICE_CRACK ){ + if( pBattle->ice_count >= 20 ) + pBattle->ice_count = 0; + pBattle->ice_use[pBattle->ice_count] = TRUE; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + pBattle->ice_level[pBattle->ice_count] = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + pBattle->ice_bout[pBattle->ice_count] = 2; + pBattle->ice_toNo[pBattle->ice_count] = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + pBattle->ice_array[pBattle->ice_count] = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + pBattle->ice_charaindex[pBattle->ice_count] = charaindex; + pBattle->ice_attackNo[pBattle->ice_count] = attackNo; + ++pBattle->ice_count; + BATTLE_NoAction( battleindex, attackNo ); + print("\n"); + break; + } +#endif + battle_profession_attack_magic_fun(battleindex, attackNo, defNo, charaindex); + //change fix ʹְҵò + //BATTLE_AddProfit( battleindex, aAttackList); + break; + } + //==== ϵ ==================================================================== + case BATTLE_COM_S_FOCUS: // רעս + case BATTLE_COM_S_AVOID: // ر + case BATTLE_COM_S_RECOVERY: // Ѫ + case BATTLE_COM_S_SCAPEGOAT: // Ϊ + case BATTLE_COM_S_ENRAGE: // + case BATTLE_COM_S_COLLECT: // ۼ + case BATTLE_COM_S_TRAP: // + case BATTLE_COM_S_TRANSPOSE: // λλ + case BATTLE_COM_S_DOCILE: // ѱ +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_CALL_NATURE: // Ȼ +#endif + { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + battle_profession_assist_fun(battleindex, attackNo, defNo, charaindex); + break; + } + //==== иı״̬ϵ ==================================================================== + case BATTLE_COM_S_SHIELD_ATTACK: // ܻ + case BATTLE_COM_S_ENTWINE: // + case BATTLE_COM_S_DRAGNET: // ޵ + case BATTLE_COM_S_TOXIN_WEAPON: // + case BATTLE_COM_S_INSTIGATE: // + case BATTLE_COM_S_OBLIVION: // + { +#ifdef _PREVENT_TEAMATTACK + // ֹͬӻ + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + if( BATTLE_CheckSameSide( charaindex, defNo) == 1 ){ + BATTLE_NoAction( battleindex, attackNo ); + if( COM == BATTLE_COM_S_TOXIN_WEAPON ) + printf("\nbug-ͬӻ"); + break; + } +#endif + } + case BATTLE_COM_S_RESIST_FIRE: // + case BATTLE_COM_S_RESIST_ICE: // + case BATTLE_COM_S_RESIST_THUNDER: // ׿ +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_RESIST_F_I_T: // Ȼ + case BATTLE_COM_S_BOUNDARY: // Խ +#endif + case BATTLE_COM_S_FIRE_ENCLOSE: // + case BATTLE_COM_S_ICE_ENCLOSE: // + case BATTLE_COM_S_THUNDER_ENCLOSE: // ׸ + { + + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + battle_profession_status_chang_fun(battleindex, attackNo, defNo, charaindex); + + break; + } + //==================================================================================== +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + case BATTLE_COM_S_ACUPUNCTURE: //Ƥ + CHAR_setWorkInt( charaindex, CHAR_WORKACUPUNCTURE, 1); + //print("\n:%s",CHAR_getChar(charaindex,CHAR_NAME)); +#endif + case BATTLE_COM_S_CHARGE_OK: + case BATTLE_COM_S_POWERBALANCE: + case BATTLE_COM_S_STATUSCHANGE: + case BATTLE_COM_S_EARTHROUND0: + case BATTLE_COM_S_MIGHTY: + case BATTLE_COM_S_GUARDIAN_ATTACK: + case BATTLE_COM_S_RENZOKU: +#ifdef _BATTLE_ATTCRAZED // ANDY + case BATTLE_COM_S_ATTCRAZED: +#endif +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + case BATTLE_COM_S_ATTSHOOT: +#endif +#ifdef _SKILL_WILDVIOLENT_ATT + case BATTLE_COM_S_WILDVIOLENTATTACK://񱩹 vincent add 2002/05/16 +#endif + +#ifdef _SKILL_SPEEDY_ATT + case BATTLE_COM_S_SPEEDYATTACK: //ٹ vincent add 2002/05/20 +#endif + case BATTLE_COM_ATTACK: +#ifdef _PET_SKILL_SARS // WON ADD ɷ + case BATTLE_COM_S_SARS: +#endif + +#ifdef _PETSKILL_BECOMEFOX + case BATTLE_COM_S_BECOMEFOX: +#endif + +#ifdef _PETSKILL_BECOMEPIG + case BATTLE_COM_S_BECOMEPIG: +#endif + +#ifdef _PETSKILL_SHOWMERCY + case BATTLE_COM_S_SHOWMERCY: +#endif +#ifdef _MASSAGE_PETSKILL + case BATTLE_COM_S_MASSAGE: +#endif +#ifdef _INVERSION_PETSKILL + case BATTLE_COM_S_INVERSION: +#endif +#ifdef _PETOUT_PETSKILL + case BATTLE_COM_S_PETOUT: + if( COM == BATTLE_COM_S_PETOUT ){ + int defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + int defindex =BATTLE_No2Index( battleindex, defNo ); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int array = CHAR_GETWORKINT_LOW(charaindex, CHAR_WORKBATTLECOM3); + char *skillarg = PETSKILL_getChar( array, PETSKILL_OPTION ); + char key[32]; + char jl[32]; + getStringFromIndexWithDelim( skillarg, "|", 1, key, sizeof( key)); + getStringFromIndexWithDelim( skillarg, "|", 2, jl, sizeof( jl)); + + char token[256]; + if((rand() % 100) > atoi(jl)){ + sprintf(token, "BK|%s ʹ %s ɹ|", CHAR_getUseName( defindex ), PETSKILL_getChar( array, PETSKILL_OPTION )); + strcat( szBadStatusString, token ); + break; + } + + int petid; + for(petid=0;petid=5 && defNo < 10) + f_num = 5; + else if(defNo >=10 && defNo < 15) + f_num = 10; + else + f_num = 15; + + // ȡսϴ + for( i=f_num; i 0){ + sprintf( szWork, "BH|a%X|", attackNo ); //¹ָ + BATTLESTR_ADD( szWork ); + } + for(i=0;i= 10 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + defNo = aDefList[0]; + }else + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 + || defNo == attackNo){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + if( COM == BATTLE_COM_S_EARTHROUND0 ){ + sprintf( szWork, "BI|a%X|", attackNo ); + }else { +#ifdef _FIXBUG_ATTACKBOW + if( CHAR_getWorkInt( charaindex, CHAR_WORKITEMMETAMO) > 0 || + CHAR_getWorkInt( charaindex, CHAR_WORKNPCMETAMO) > 0 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС + + if( gWeponType == ITEM_BOW || gWeponType == ITEM_BOUNDTHROW || + gWeponType == ITEM_BREAKTHROW || gWeponType == ITEM_BOOMERANG) { + CHAR_talkToCli( charaindex, -1, "޷ʹԶ!!", CHAR_COLORYELLOW); + continue; + } + + } +#endif + if( gWeponType == ITEM_BOW ) sprintf( szWork, "BB|a%X|w0|", attackNo ); + else if( gWeponType == ITEM_BOUNDTHROW ) //Ƕͷ + sprintf( szWork, "BB|a%X|w1|", attackNo ); + else if( gWeponType == ITEM_BREAKTHROW ) + sprintf( szWork, "BB|a%X|w2|", attackNo ); + else sprintf( szWork, "BH|a%X|", attackNo ); + } +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( COM == BATTLE_COM_S_ATTSHOOT ) + sprintf( szWork, "BB|a%X|w0|", attackNo ); +#endif + BATTLESTR_ADD( szWork ); + if( COM == BATTLE_COM_S_CHARGE_OK || + COM == BATTLE_COM_S_EARTHROUND0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + }else{ +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( CHAR_getWorkInt(charaindex, CHAR_WORKBATTLECOM1) != BATTLE_COM_S_ATTSHOOT) +#endif +#ifdef _PETSKILL_SHOWMERCY + if( CHAR_getWorkInt(charaindex, CHAR_WORKBATTLECOM1) != BATTLE_COM_S_SHOWMERCY) +#endif +#ifdef _MASSAGE_PETSKILL + if( CHAR_getWorkInt(charaindex, CHAR_WORKBATTLECOM1) != BATTLE_COM_S_MASSAGE) +#endif +#ifdef _GRAPPLING_PETSKILL + if( CHAR_getWorkInt(charaindex, CHAR_WORKBATTLECOM1) != BATTLE_COM_S_GRAPPLING) +#endif +#ifdef _INVERSION_PETSKILL + if( CHAR_getWorkInt(charaindex, CHAR_WORKBATTLECOM1) != BATTLE_COM_S_INVERSION) +#endif + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1,BATTLE_COM_ATTACK ); + } + + + for( attack_count = 0, k = 0;; ){ + if( gWeponType == ITEM_BOW ){ + if( BATTLE_TargetCheck( battleindex, defNo ) == FALSE ){ + attack_flg = 0; + }else{ + attack_flg = 1; + } + } + + if( attack_flg ){ + + ContFlg = BATTLE_Attack( battleindex, attackNo, defNo ); +#ifdef _PETSKILL_RETRACE + if( Battle_Attack_ReturnData_x.Battle_Attack_ReturnData == BATTLE_RET_DODGE + && COM == BATTLE_COM_S_RETRACE ){ + if( RAND(1,100) < 80 ){ //80%ʷ2ι + //+20% + + CHAR_setWorkInt( BATTLE_No2Index( battleindex, attackNo ), + CHAR_WORKATTACKPOWER, + ( CHAR_getWorkInt( BATTLE_No2Index( battleindex, attackNo ), CHAR_WORKFIXSTR) + ( CHAR_getWorkInt( BATTLE_No2Index( battleindex, attackNo ), CHAR_WORKFIXSTR) * 0.2 ) ) ); + + BATTLE_Attack( battleindex, attackNo, defNo ); + + } + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = 0; + } +#endif + BATTLE_AddProfit( battleindex, aAttackList); + if( ++attack_count >= attack_max ) break; + if( CHAR_getInt( charaindex, CHAR_HP ) <= 0 ) { + ContFlg = FALSE; + break; + } + } + defNo = aDefList[++k]; + if( defNo < 0 ) break; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, defNo ); + if( gWeponType == ITEM_BOW ){ + }else + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + break; + } + if( BATTLE_CountAlive( battleindex, 0) == 0 || BATTLE_CountAlive( battleindex, 1) == 0) { + break; + } + } + gBattleDamageModyfy = 1.0; + gBattleDuckModyfy = 0; + for( k = 0; k < 5 && ContFlg == TRUE; k ++ ){ + if( ( k & 1 ) == 1 ){ + attackNoSub = attackNo; + defNoSub = defNo; + }else{ + defNoSub = attackNo; + attackNoSub = defNo; + } + //ж + ContFlg = BATTLE_Counter(battleindex, attackNoSub, defNoSub ); + aAttackList[0] = attackNoSub; + aAttackList[1] = -1; + BATTLE_AddProfit( battleindex, aAttackList); + } + aAttackList[0] = -1; + BATTLESTR_ADD( "FF|" ); + + +#ifdef _INVERSION_PETSKILL + if(COM == BATTLE_COM_S_INVERSION ){ + if((Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_MISS) //ûmiss + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_DODGE) + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_ALLGUARD) //ûܹ + && (BATTLE_TargetCheck( battleindex, defNo )) // + ){ + int flg, OnOff; + int toindex = BATTLE_No2Index( battleindex, defNo ); + flg = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEFLG ); + flg ^= CHAR_BATTLEFLG_REVERSE; + CHAR_setWorkInt( toindex, CHAR_WORKBATTLEFLG, flg ); + OnOff = ( flg & CHAR_BATTLEFLG_REVERSE )?(1):(0); + BATTLE_AttReverse( toindex ); + sprintf( szWork, "FF|BR|%X|%X|FF|", defNo, OnOff ); + BATTLESTR_ADD( szWork ); + } + } +#endif + +#ifdef _PETSKILL_BECOMEFOX // ԷʹĻ + if ( (COM == BATTLE_COM_S_BECOMEFOX ) + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_MISS) //ûmiss + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_DODGE) //ûܹ + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_ALLGUARD) +#ifdef _EQUIT_ARRANGE + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_ARRANGE) +#endif + && (BATTLE_TargetCheck( battleindex, defNo )) // + && (rand()%100 < 31) + && (CHAR_getInt( BATTLE_No2Index( battleindex, defNo ), CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER) //ֻг(CHAR_TYPEPET)ſԱĻ + && (CHAR_getWorkInt( BATTLE_No2Index( battleindex, defNo ), CHAR_WORK_PETFLG ) != 0 ) +#ifdef _PETSKILL_BECOMEPIG + && (CHAR_getInt( charaindex, CHAR_BECOMEPIG) == -1)//ûд +#endif + ) + { + int ToList[SIDE_OFFSET*2+1]; + int defindex = BATTLE_No2Index( battleindex, defNo ); + + BATTLE_MultiList( battleindex, defNo, ToList ); + BATTLE_MagicEffect( battleindex, defNo, ToList, 101120, 101750); + CHAR_setWorkInt( defindex, CHAR_WORKFOXROUND, pBattle->turn ); + + if( CHAR_getInt( defindex, CHAR_RIDEPET) != -1 ) { //Ҫ + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + } + + CHAR_setInt( defindex, CHAR_BASEIMAGENUMBER, 101749); + } +#endif +#ifdef _PETSKILL_BECOMEPIG // Էʹ + if ( (COM == BATTLE_COM_S_BECOMEPIG ) + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_MISS) //ûmiss + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_DODGE) //ûܹ + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_ALLGUARD) +#ifdef _EQUIT_ARRANGE + && (Battle_Attack_ReturnData_x.Battle_Attack_ReturnData != BATTLE_RET_ARRANGE) +#endif + && (BATTLE_TargetCheck( battleindex, defNo )) // + && (CHAR_getInt( BATTLE_No2Index( battleindex, defNo ), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) //ֻҲſԱ +#ifdef _PREVENT_TEAMATTACK + && (BATTLE_CheckSameSide( charaindex, defNo) != 1 ) // ֹͬӻ +#endif + && CHAR_getInt( BATTLE_No2Index( battleindex, defNo ), CHAR_BECOMEPIG) < 2000000000 ) //ֹƱ + { + char temp[64]; + int ToList[SIDE_OFFSET*2+1], compute,petrate,pettime,pigbbi=100250; + char *pszOption=NULL; + int defindex = BATTLE_No2Index( battleindex, defNo ); + pszOption = PETSKILL_getChar( CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ), PETSKILL_OPTION ); + if( pszOption == "\0") + sscanf( pszOption, "%d %d %d", &petrate, &pettime, &pigbbi); + else + petrate = 30, pettime = 60, pigbbi = 100250; + + if( rand()%100 < petrate ){ + CHAR_setWorkInt( defindex, CHAR_WORKITEMMETAMO, 0);//߱ȡ + CHAR_setWorkInt( defindex, CHAR_WORKNPCMETAMO, 0 );//NPCȡ + CHAR_setWorkInt( defindex, CHAR_WORKFOXROUND, -1);//Ļȡ + + BATTLE_MultiList( battleindex, defNo, ToList ); + BATTLE_MagicEffect( battleindex, defNo, ToList, 101120, 101750); + + if( CHAR_getInt( defindex, CHAR_RIDEPET) != -1 ){ //Ҫ + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + } + + CHAR_setInt( defindex, CHAR_BECOMEPIG_BBI, pigbbi ); + + compute = CHAR_getInt( defindex, CHAR_BECOMEPIG); + CHAR_setInt( defindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( defindex, CHAR_BECOMEPIG_BBI ) ); + if( compute == -1 )//һ + CHAR_setInt( defindex, CHAR_BECOMEPIG, pettime + 1 + compute ); //ʱ(λ:) + else + CHAR_setInt( defindex, CHAR_BECOMEPIG, pettime + compute ); + sprintf(temp, "ʱ:%d", CHAR_getInt( defindex, CHAR_BECOMEPIG) ); + CHAR_talkToCli( defindex, -1, temp, CHAR_COLORYELLOW); + + print("\nʼ0:%s,round:%d", CHAR_getChar( defindex, CHAR_NAME), CHAR_getWorkInt( defindex, CHAR_WORKFOXROUND)); + } + } +#endif + break; +//´⹥ + case BATTLE_COM_BOOMERANG: + gBattleDamageModyfy = 0.3; + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + if( defNo < 0 ){ + defNo = BATTLE_DefaultAttacker( battleindex, 1 - myside ); + } + if( 0 <= defNo && defNo <= 19 ){ + defNo /= 5; // + }else{ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + if( (int)(attackNo / 5 ) == defNo ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + { + int *pBoomerangTbl = BoomerangVsTbl[defNo]; + for( k = 0; k < 5; k ++ ){ + if( BATTLE_TargetCheck( battleindex, pBoomerangTbl[k] ) == FALSE ){ + continue; + }else{ + break; + } + } + if( k == 5 ){ + defNo = BATTLE_DefaultAttacker( battleindex, 1 - myside ); + if( 0 <= defNo && defNo <= 19 ){ + defNo /= 5; + }else{ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + } + } + sprintf( szWork, "BO|a%X|", attackNo ); + BATTLESTR_ADD( szWork ); + { + int *pBoomerangTbl = BoomerangVsTbl[defNo]; + if( myside == 1 ){ + k = 4; j = -1; + }else{ + k = 0; j = 1; + } + for( ; ; k += j ){ + if( j > 0 && k > 4 )break; + if( j < 0 && k < 0 )break; + defNo = pBoomerangTbl[k]; + if( BATTLE_TargetCheck( battleindex, defNo ) == FALSE ){ + continue; + } + BATTLE_Attack( battleindex, attackNo, defNo ); + } + } + gBattleDamageModyfy = 1.0; + gBattleDuckModyfy = 0; + BATTLESTR_ADD( "FF|" ); + break; + + //--------------------------------------------- + case BATTLE_COM_CAPTURE: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + BATTLE_Capture( battleindex, attackNo, defNo ); + break; + + //--------------------------------------------- +#ifdef _VARY_WOLF + case BATTLE_COM_S_VARY: + { + int ToList[SIDE_OFFSET*2+1]; + int bk_amn = 0; + + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } +#ifdef _EXPANSION_VARY_WOLF + if(CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101428){ + bk_amn = (CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER) + 5) + (myside*4); + }else{ + bk_amn = (CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)); + } + + BATTLE_MultiList( battleindex, defNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, 101120, bk_amn); +#endif + } + break; +#endif + case BATTLE_COM_GUARD: + BATTLE_Guard( battleindex, attackNo ); + + break; + case BATTLE_COM_ESCAPE: + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPET ){ + if (BATTLE_Escape(battleindex, attackNo, 0) == TRUE) + { + if( CHAR_CHECKINDEX( charaindex) ){ + if (CHAR_getWorkInt(charaindex, CHAR_WORKFMPKFLAG) == 1){ + CHAR_setWorkInt(charaindex, CHAR_WORKFMPKFLAG, -1); + } + } + } + } + break; + case BATTLE_COM_COMPELESCAPE: //ǿ뿪 + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPET ){ + BATTLE_Escape( battleindex, attackNo, 1); + if (CHAR_getWorkInt(charaindex, CHAR_WORKFMPKFLAG) == 1) + CHAR_setWorkInt(charaindex, CHAR_WORKFMPKFLAG, -1); + } + break; + + case BATTLE_COM_PETIN: + if( CHAR_getInt( charaindex, CHAR_DEFAULTPET ) == -1 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + { + char szWork[256]; + snprintf( szWork, sizeof( szWork ), "K%d", CHAR_getInt( charaindex, CHAR_DEFAULTPET ) ); + CHAR_sendStatusString( charaindex, szWork ); + + } + BATTLE_PetIn( battleindex, attackNo ); + lssproto_KS_send( + getfdFromCharaIndex( charaindex ), + CHAR_getInt( charaindex, CHAR_DEFAULTPET ), 1 ); + break; + case BATTLE_COM_PETOUT: + if( CHAR_getInt( charaindex, CHAR_DEFAULTPET ) != -1 ){ + lssproto_KS_send( + getfdFromCharaIndex( charaindex ), + CHAR_getInt( charaindex, CHAR_DEFAULTPET ), 1 ); + { + char szWork[256]; + snprintf( szWork, sizeof( szWork ), "K%d", CHAR_getInt( charaindex, CHAR_DEFAULTPET ) ); + CHAR_sendStatusString( charaindex, szWork ); + } + + BATTLE_PetIn( battleindex, attackNo ); + } +/* +#ifndef _VERSION_25 + // shan 2002/01/14 Begin ֻ + { + int attackindex, petNo; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + petNo = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM2 ); + if( CHAR_getWorkInt(charaindex, CHAR_WORK_PET0_STAT+petNo) != PET_STAT_SELECT) + break; + } +#endif +*/ + // shan End + BATTLE_PetOut( battleindex, attackNo ); + lssproto_KS_send( + getfdFromCharaIndex( charaindex ), + CHAR_getInt( charaindex, CHAR_DEFAULTPET ), 1 ); + break; +// Terry add 2001/11/05 +#ifdef _ATTACK_MAGIC + case BATTLE_COM_S_ATTACK_MAGIC: // ħ + + magic = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + toindex = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); +// print("magic->%d,toindex->%d\n",magic,toindex); + // жϹ Χ + for(magic_count=0;magic_count= 10 ){ + toindex = 21; + }else{ + toindex = 20; + } +#else + toindex = TargetIndex[magic_count][1]; +#endif + } + // Ǵ˵ħ + else if(TargetIndex[magic_count][1] != -1){ + // Ǵµһ + if(toindex >= 0 && toindex <= 4) + toindex = TargetIndex[magic_count][1]; + // µǰһ + else + toindex = TargetIndex[magic_count][1]-1; + } + break; + } + } +// print("toindex->%d\n",toindex); + MAGIC_DirectUse(charaindex,magic,toindex,CHAR_GETWORKINT_HIGH(charaindex,CHAR_WORKBATTLECOM3)); + BATTLE_AddProfit( battleindex, aAttackList ); + break; +#endif + case BATTLE_COM_JYUJYUTU: + MAGIC_DirectUse( + charaindex, + CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ), + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ), + CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ) + ); + break; + + case BATTLE_COM_ITEM: + itemindex = CHAR_getItemIndex(charaindex, CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM3 )); + if( ITEM_CHECKINDEX( itemindex ) == FALSE ){ + print( "\nerr:Ҫʹõitemλ(%s)(%d)\n", + CHAR_getUseName( charaindex ), CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM3 ) ); + break; + } +/* +#ifndef _VERSION_25 // Robin fix սɻƷ + { + int itemtype = ITEM_getInt( itemindex, ITEM_TYPE ); + if( itemtype == ITEM_HELM + || itemtype == ITEM_ARMOUR + || itemtype == ITEM_BRACELET + //|| itemtype == ITEM_MUSIC + || itemtype == ITEM_NECKLACE + || itemtype == ITEM_RING + || itemtype == ITEM_BELT + || itemtype == ITEM_EARRING + || itemtype == ITEM_NOSERING + || itemtype == ITEM_AMULET + //|| itemtype == CHAR_HEAD + ) + { + print("\n ķ!սɻ!!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + break; + } + } +#endif +*/ +#ifdef _FIXBUG_ATTACKBOW + { + if( CHAR_getWorkInt( charaindex, CHAR_WORKITEMMETAMO) > 0 || + CHAR_getWorkInt( charaindex, CHAR_WORKNPCMETAMO) > 0 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС + + int armtype; + int itemindex = CHAR_getItemIndex( charaindex, CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM3 )); + if( !ITEM_CHECKINDEX(itemindex) ) break; + armtype = ITEM_getInt( itemindex, ITEM_TYPE ); + + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( charaindex, -1, "޷ʹԶ", CHAR_COLORYELLOW ); + break; + } + } + } +#endif + CHAR_ItemUse(charaindex,CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ), CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM3 )); + + int itemtype = ITEM_getEquipPlace( charaindex, itemindex ); + if( itemtype == CHAR_ARM + || itemtype == CHAR_HEAD + || itemtype == CHAR_BODY + || itemtype == CHAR_DECORATION1 + || itemtype == CHAR_DECORATION2 + ){ + sprintf( szWork, "BN|a%X|%X|", attackNo, + CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER ) ); + BATTLESTR_ADD( szWork ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + // ר + BATTLE_ProfessionStatus_init( battleindex, charaindex ); +#endif + + } + + break; + +#ifdef _PSKILL_FALLGROUND + case BATTLE_COM_S_FALLRIDE:// + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + ContFlg = BATTLE_S_FallGround( battleindex, attackNo, defNo, BATTLE_COM_S_FALLRIDE); + break; + +#endif +#ifdef _PETSKILL_EXPLODE + case BATTLE_COM_S_EXPLODE: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + ContFlg = BATTLE_S_Explode( battleindex, attackNo, defNo, BATTLE_COM_S_EXPLODE); + break; +#endif + +#ifdef _PETSKILL_TIMID + case BATTLE_COM_S_TIMID: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_TIMID, skill); + } + break; +#endif +#ifdef _PETSKILL_2TIMID + case BATTLE_COM_S_2TIMID: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_2TIMID, skill); + } + break; +#endif + +#ifdef _PETSKILL_PROPERTY + case BATTLE_COM_S_PROPERTYSKILL: + { + int skill; + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + BATTLE_S_PetSkillProperty( battleindex, attackNo, COM, skill); + BATTLE_NoAction( battleindex, attackNo ); + } + break; +#endif + +#ifdef _BATTLE_LIGHTTAKE + case BATTLE_COM_S_LIGHTTAKE: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_LIGHTTAKE, skill); + } + break; +#endif + +#ifdef _SKILL_DAMAGETOHP + case BATTLE_COM_S_DAMAGETOHP: //Ѫ + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_DAMAGETOHP, skill); + } + break; +#endif + +#ifdef _PETSKILL_DAMAGETOHP + case BATTLE_COM_S_DAMAGETOHP2: //¿(Ѫı) + { + int skill,attackidxtemp; + attackidxtemp = BATTLE_No2Index( battleindex, attackNo ); + + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_DAMAGETOHP2, skill); + + } + break; +#endif + +#ifdef _Skill_MPDAMAGE + case BATTLE_COM_S_MPDAMAGE: //MP˺ + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_MPDAMAGE, skill); + break; + } + break; +#endif +#ifdef _SKILL_TOOTH + case BATTLE_COM_S_TOOTHCRUSHE: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_TOOTHCRUSHE, skill); + break; + } + break; +#endif +#ifdef _PSKILL_MODIFY + case BATTLE_COM_S_MODIFYATT: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_MODIFYATT, skill); + } + break; +#endif +#ifdef _PSKILL_MDFYATTACK + case BATTLE_COM_S_MDFYATTACK: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_MDFYATTACK, skill); + } + break; +#endif + +#ifdef _PETSKILL_TEAR + case BATTLE_COM_S_PETSKILLTEAR: + { + int skill; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_PETSKILLTEAR, skill); + } + break; +#endif + +#ifdef _SONIC_ATTACK // WON ADD + case BATTLE_COM_S_SONIC: + { + int skill, defNo2=-1, index2=-1; + + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + + if( defNo >= 15 && defNo < 20 ) defNo2 = defNo - 5; + else if( defNo >= 5 && defNo < 10 ) defNo2 = defNo - 5; + else defNo2 = -1; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + index2 = BATTLE_No2Index( battleindex, defNo2 ); + + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_SONIC, skill ); + + if( index2 >= 0 ){ + if( defNo2 >= 0 ){ + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo2, BATTLE_COM_S_SONIC2, skill ); + } + } + + } + break; +#endif + +#ifdef _PETSKILL_REGRET + case BATTLE_COM_S_REGRET: + { + int skill, defNo2=-1, index2=-1; + + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + + if( defNo >= 15 && defNo < 20 ) defNo2 = defNo - 5; + else if( defNo >= 5 && defNo < 10 ) defNo2 = defNo - 5; + else defNo2 = -1; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + index2 = BATTLE_No2Index( battleindex, defNo2 ); + + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo, BATTLE_COM_S_REGRET, skill ); + if( index2 >= 0 ){ + if( defNo2 >= 0 ){ + ContFlg = BATTLE_S_AttackDamage( battleindex, attackNo, defNo2, BATTLE_COM_S_REGRET2, skill ); + } + } + + } + break; +#endif + +#ifdef _MAGIC_SUPERWALL + case BATTLE_COM_S_SUPERWALL: + { + int skill; + defNo = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = PETSKILL_MagicStatusChange_Battle( battleindex, attackNo, defNo, skill); + } + break; +#endif +#ifdef _PETSKILL_SETDUCK + case BATTLE_COM_S_SETDUCK: + { + int skill; + defNo = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = PETSKILL_SetDuckChange_Battle( battleindex, attackNo, defNo, skill); + break; + } +#endif +#ifdef _MAGICPET_SKILL + case BATTLE_COM_S_SETMAGICPET: + { + int skill; + defNo = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = PETSKILL_SetMagicPet_Battle( battleindex, attackNo, defNo, skill); + break; + } +#endif +#ifdef _STRENGTH_PETSKILL + case BATTLE_COM_S_STRENGTH: + { + int skill; + defNo = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + skill = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = PETSKILL_SetStrength_Battle( battleindex, attackNo, defNo, skill); + break; + } +#endif +#ifdef _OFFLINE_SYSTEM + case BATTLE_COM_S_OFFLINE_RECOVERY: + { + defNo = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + int HP = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = OFFLINE_MultiRessurect( battleindex, attackNo, defNo, HP, 0); + break; + } +#endif +#ifdef _PRO_BATTLEENEMYSKILL + case BATTLE_COM_S_ENEMYRELIFE: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + + ContFlg =BATTLE_E_ENEMYREFILE( battleindex, attackNo, defNo, BATTLE_COM_S_ENEMYRELIFE); + if( ContFlg == FALSE ) { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + ContFlg = BATTLE_Attack( battleindex, attackNo, defNo ); + BATTLE_AddProfit( battleindex, aAttackList ); + } + BATTLE_AddProfit( battleindex, aAttackList ); + break; + + case BATTLE_COM_S_ENEMYREHP: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + ContFlg =BATTLE_E_ENEMYREHP( battleindex, attackNo, defNo, BATTLE_COM_S_ENEMYREHP); + if( ContFlg == FALSE ) { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + ContFlg = BATTLE_Attack( battleindex, attackNo, defNo ); + BATTLE_AddProfit( battleindex, aAttackList ); + } + BATTLE_AddProfit( battleindex, aAttackList ); + break; + + case BATTLE_COM_S_ENEMYHELP: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + print("\n BATTLE_NoAction()"); + break; + } + ContFlg =BATTLE_E_ENEMYHELP( battleindex, attackNo, defNo, BATTLE_COM_S_ENEMYREHP); + if( ContFlg == FALSE ) { + CHAR_setFlg( charaindex, CHAR_ISATTACKED, 1 ); + ContFlg = BATTLE_Attack( battleindex, attackNo, defNo ); + BATTLE_AddProfit( battleindex, aAttackList ); + } + BATTLE_AddProfit( battleindex, aAttackList ); + break; +#endif + case BATTLE_COM_S_GBREAK: //Ƴ + + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + ContFlg = BATTLE_S_GBreak( battleindex, attackNo, defNo ); + break; +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 + case BATTLE_COM_S_GBREAK2: + //ȷ + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + ContFlg = BATTLE_S_GBreak2( battleindex, attackNo, defNo ); + break; +#endif + +#ifdef _SKILL_SACRIFICE + case BATTLE_COM_S_SACRIFICE://Ԯ vincent add 2002/05/30 + //ȷ + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + ContFlg = BATTLE_S_Sacrifice( battleindex, attackNo, defNo ); + + break; +#endif + +#ifdef _SKILL_REFRESH + case BATTLE_COM_S_REFRESH://״̬ظ vincent add 2002/08/08 + { + int array; + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); +// print("\n vincent--case BATTLE_COM_S_REFRESH:-->defNo:%d",defNo); + ContFlg = BATTLE_S_Refresh( battleindex, attackNo, defNo ,array); + } + break; +#endif + +#ifdef _SKILL_WEAKEN //vincent輼: + case BATTLE_COM_S_WEAKEN: + { + int array; + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + //print("\n vincent--case BATTLE_COM_S_WEAKEN:-->defNo:%d",defNo); + ContFlg = BATTLE_S_Weaken( battleindex, attackNo, defNo ,array); + } + break; +#endif + +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 + case BATTLE_COM_S_DEEPPOISON: + { + int array; + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + ContFlg = BATTLE_S_Deeppoison( battleindex, attackNo, defNo ,array); + } + break; +#endif + +#ifdef _SKILL_BARRIER //vincent輼:ħ + case BATTLE_COM_S_BARRIER: + { + int array; + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + ContFlg = BATTLE_S_Barrier( battleindex, attackNo, defNo ,array); + } + break; +#endif + +#ifdef _SKILL_NOCAST //vincent輼:Ĭ + case BATTLE_COM_S_NOCAST: + { + int array; + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + ContFlg = BATTLE_S_Nocast( battleindex, attackNo, defNo ,array); + } + break; +#endif + +#ifdef _SKILL_ROAR //vincent輼: + case BATTLE_COM_S_ROAR: + { + int array; + //ȷ + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + array = CHAR_GETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3); + ContFlg = BATTLE_S_Roar( battleindex, attackNo, defNo ,array); + } + break; +#endif + case BATTLE_COM_S_ABDUCT: + { + int array; + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + array = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + BATTLE_Abduct( battleindex, attackNo, defNo, array); + } + break; + case BATTLE_COM_COMBO: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + gDamageDiv = 1.0; + ComboId = EntryList[i].combo; + aAttackList[0] = EntryList[i].num; // + i ++; // ݼо + k = 1; + for( ; EntryList[i].combo == ComboId && i < entrynum; i ++ ){ + int charmode; + // ¾ + if( CHAR_CHECKINDEX( EntryList[i].charaindex ) == FALSE )continue; + + // 帨ƻئݳ + charmode = CHAR_getWorkInt( EntryList[i].charaindex, CHAR_WORKBATTLEMODE ); + if( charmode == 0 || charmode == BATTLE_CHARMODE_FINAL ){ + continue; + } + + // ټ + BATTLE_StatusSeq( EntryList[i].charaindex ); +#ifdef _OTHER_MAGICSTAUTS + BATTLE_MagicStatusSeq( EntryList[i].charaindex ); +#endif + // ئ + if( BATTLE_CanMoveCheck( EntryList[i].charaindex ) == FALSE ){ + continue; + } + if( CHAR_getInt( EntryList[i].charaindex, CHAR_HP ) <= 0 ){ + continue; + } + aAttackList[k++] = EntryList[i].num; + } + aAttackList[k] = -1; + i--; + if( k == 1 ){ + print( "\nerr:һcombo bug\n" ); + } + sprintf( szWork, "BY|r%X|", defNo ); + BATTLESTR_ADD( szWork ); + BATTLE_Combo( battleindex, aAttackList, defNo ); + +#ifdef _Item_ReLifeAct + BATTLE_AddProfit( battleindex, aAttackList ); +#endif + // FF ëȹ + BATTLESTR_ADD( "FF|" ); + break; + + //--------------------------------------------- + case BATTLE_COM_WAIT: + case BATTLE_COM_NONE: + BATTLE_NoAction( battleindex, attackNo ); + break; + + //--------------------------------------------- + case BATTLE_COM_S_EARTHROUND1: + BATTLE_EarthRoundHide( battleindex, attackNo ); + break; + + //--------------------------------------------- + case BATTLE_COM_S_LOSTESCAPE: + BATTLE_LostEscape( battleindex, attackNo ); + break; + + case BATTLE_COM_S_STEAL: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + BATTLE_Steal( battleindex, attackNo, defNo ); + break; + +#ifdef _BATTLESTEAL_FIX + case BATTLE_COM_S_STEALMONEY: + if( (defNo = BATTLE_TargetAdjust( battleindex, charaindex, myside )) < 0 ){ + BATTLE_NoAction( battleindex, attackNo ); + break; + } + BATTLE_StealMoney( battleindex, attackNo, defNo) ; + break; +#endif + case BATTLE_COM_S_NOGUARD: + BATTLE_NoAction( battleindex, attackNo ); + break; + case BATTLE_COM_S_CHARGE: + sprintf( szWork, "bt|%x|", attackNo ); + BATTLESTR_ADD( szWork ); + break; +#ifdef _PETSKILL_LER + case BATTLE_COM_S_BAT_FLY: + { + if((defNo = BATTLE_TargetAdjust(battleindex,charaindex,myside)) < 0){ + BATTLE_NoAction(battleindex,attackNo); + break; + } + + BATTLE_BatFly(battleindex,attackNo,myside); + } + break; + case BATTLE_COM_S_DIVIDE_ATTACK: + { + if((defNo = BATTLE_TargetAdjust(battleindex,charaindex,myside)) < 0){ + BATTLE_NoAction(battleindex,attackNo); + break; + } + + BATTLE_DivideAttack(battleindex,attackNo,myside); + } + break; +#endif +#ifdef _PETSKILL_BATTLE_MODEL + case BATTLE_COM_S_BATTLE_MODEL: + BATTLE_BattleModel(battleindex,attackNo,myside); + break; +#endif + //--------------------------------------------- + default: + printf( "\nerr:ֵ(%d:%d:%s)\n", charaindex, COM, + CHAR_getUseName( charaindex ) ); + sprintf( szWork, "bg|%x|", attackNo ); + BATTLESTR_ADD( szWork ); + break; + } + if(CHAR_CHECKINDEX(charaindex)){ +#ifdef _VARY_WOLF + if(CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101428 +#ifdef _EXPANSION_VARY_WOLF + ||CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==104109 +#endif + ) + { + if(CHAR_getWorkInt( charaindex, CHAR_WORKTURN)==0) + CHAR_setWorkInt( charaindex, CHAR_WORKTURN, 1); + else + CHAR_setWorkInt( charaindex, CHAR_WORKTURN, CHAR_getWorkInt( charaindex, CHAR_WORKTURN)+1); + + if(CHAR_getWorkInt( charaindex, CHAR_WORKTURN)>5) + { + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER)); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)); + CHAR_setWorkInt( charaindex, CHAR_WORKTURN, 0); + } + } +#endif +#ifdef _PETSKILL_BECOMEFOX // жĻǷѵָĻغ + //if(CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101749) //ͼжϵĻ,˱ʱ,ᱻԶĻȥ + if( CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ) //DZС + { + if(CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)!=101749) + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, 101749 ); + + if(pBattle->turn - CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND) > 2) + { + int defNo = BATTLE_Index2No( battleindex, charaindex ); + int toNo = defNo - 5;//˵ı + //print("\nظ:%s,round:%d", CHAR_getChar( charaindex, CHAR_NAME), CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND)); + + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER)); + + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)); + CHAR_setWorkInt( charaindex, CHAR_WORKFOXROUND, -1); + + //Change fix ظļ + sprintf( szWork, "W%d", CHAR_getInt( BATTLE_No2Index( battleindex, toNo ), CHAR_DEFAULTPET ) ); + CHAR_sendStatusString( BATTLE_No2Index( battleindex, toNo ), szWork ); + } + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 + && (CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) ) + { + char pigbuffer[128]; + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BECOMEPIG_BBI ) ); + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > 0 ){ + sprintf(pigbuffer, "ʱ:%d", CHAR_getInt( charaindex, CHAR_BECOMEPIG )); + CHAR_talkToCli( charaindex,-1,pigbuffer,CHAR_COLORWHITE); + } + else{ + sprintf(pigbuffer, " ʱ뿪սɽ:%d ", CHAR_getInt( charaindex, CHAR_BECOMEPIG )); + CHAR_talkToCli( charaindex,-1,pigbuffer,CHAR_COLORWHITE); + } + } +#endif +#ifdef _PROFESSION_ADDSKILL + { +/* for(i=0;i<20;i++){ + if( pBattle->ice_use[i] ){//׼ + print("\n׼"); + if( pBattle->ice_bout[i] > 0 ){// + print("\n"); + if( --pBattle->ice_bout[i] == 0 ){//ű + print("\nű"); + pBattle->ice_use[i] = FALSE; + if( CHAR_CHECKINDEX(pBattle->ice_charaindex[i]) ){ + int battlecom = CHAR_getWorkInt( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM1 ); + print("\n"); + print("\nbattlecom:%d",battlecom); + CHAR_setWorkInt( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM1, BATTLE_COM_S_ICE_CRACK ); + CHAR_SETWORKINT_HIGH( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM3, pBattle->ice_level[i] ); + CHAR_setWorkInt( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM2, pBattle->ice_toNo[i] ); + CHAR_SETWORKINT_HIGH( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM3, pBattle->ice_level[i] ); + CHAR_SETWORKINT_LOW( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM3, pBattle->ice_array[i] ); + battle_profession_attack_magic_fun(battleindex, pBattle->ice_attackNo[i], pBattle->ice_toNo[i], pBattle->ice_charaindex[i]); + CHAR_setWorkInt( pBattle->ice_charaindex[i], CHAR_WORKBATTLECOM1, battlecom ); + } + } + } + } + }*/ + } + { + int earth_boundary = GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY ) ); + int water_boundary = GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY ) ); + int fire_boundary = GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY ) ); + int wind_boundary = GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY ) ); + int boundary_turn=0; + BOOL boundaryclear = FALSE; + if( earth_boundary > 0 ){//ؽ + boundary_turn = GETLOWVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY ) ) - 1; +// print("\n:%d ",boundary_turn ); + if( boundary_turn <= -1 ) + CHAR_setWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY, 0 ),boundaryclear = TRUE; + else + CHAR_setWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY, MAKE2VALUE(earth_boundary,boundary_turn) ); + + } + if( water_boundary > 0 ){//ˮ + boundary_turn = GETLOWVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY ) ) - 1; +// print("\nˮ:%d ",boundary_turn ); + + if( boundary_turn <= -1 ) + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY, 0 ),boundaryclear = TRUE; + else + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY, MAKE2VALUE(water_boundary,boundary_turn) ); + + } + if( fire_boundary > 0 ){// + boundary_turn = GETLOWVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY ) ) - 1; +// print("\n:%d ",boundary_turn ); + + if( boundary_turn <= -1 ) + CHAR_setWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY, 0 ),boundaryclear = TRUE; + else + CHAR_setWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY, MAKE2VALUE(fire_boundary,boundary_turn) ); + + } + if( wind_boundary > 0 ){// + boundary_turn = GETLOWVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY ) ) - 1; +// print("\n:%d ",boundary_turn ); + + if( boundary_turn <= -1 ) + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY, 0 ),boundaryclear = TRUE; + else + CHAR_setWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY, MAKE2VALUE(wind_boundary,boundary_turn) ); + + } + if( GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY ) ) == 0 + && GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY ) ) == 0 + && GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY ) ) == 0 + && GETHIGHVALUE( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY ) ) == 0 + && boundaryclear ){ + int toNo = BATTLE_Index2No( battleindex, charaindex ); + if( toNo < 10 )//ҷ + snprintf( szWork, sizeof( szWork ), "Ba|%X|%X|", 0,1 ); + else + snprintf( szWork, sizeof( szWork ), "Ba|%X|%X|", 0,0 ); + BATTLESTR_ADD( szWork ); + BATTLESTR_ADD( "FF|" ); + } + } +#endif + } +#ifdef _Item_ReLifeAct + { + //pEntry + int k, userindex=-1; + // if( BattleArray[ battleindex].type != BATTLE_TYPE_P_vs_P){ + for( k=0; k<20; k++) { + userindex = BATTLE_getBattleDieIndex( battleindex, k); + if( !CHAR_CHECKINDEX( userindex) ) continue; + //Change fix CHECK_ITEM_RELIFEм,ﲻ + //if( CHAR_getFlg( userindex, CHAR_ISDIE ) == FALSE ) + // continue; + if( CHAR_getInt( userindex, CHAR_HP) > 0 ) + continue; + if( CHAR_getInt( userindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + CHECK_ITEM_RELIFE( battleindex, userindex); + } +#ifdef _LOSE_FINCH_ + else if( CHAR_getInt( userindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHECK_PET_RELIFE( battleindex, userindex); + } +#endif + } + } +#endif + BATTLESTR_ADD( szBadStatusString ); + BATTLE_AddProfit( battleindex, aAttackList );//ȡþֵ + len = pszBattleTop - szBattleString; + if( AllSize + len >= sizeof( szAllBattleString ) - 1 ){ + // ƥ׾ئ + }else{ + memcpy( szAllBattleString+AllSize, szBattleString, len ); + szAllBattleString[AllSize+len] = 0;// NULL ë + AllSize += len; + } + if( BATTLE_CountAlive( battleindex, 0 ) == 0 || BATTLE_CountAlive( battleindex, 1 ) == 0 ) { + break; + } + } +#ifdef _PETSKILL_LER + { + register int i,dieindex; + for(i=0;i<20;i++){ + dieindex = BATTLE_getBattleDieIndex(battleindex,i); + if(!CHAR_CHECKINDEX(dieindex)) continue; + if(CHAR_getFlg(dieindex,CHAR_ISDIE) == FALSE) continue; + if(CHAR_getInt(dieindex,CHAR_HP) > 0) continue; + // ׶, + if(CHAR_getInt(dieindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(dieindex,CHAR_BASEBASEIMAGENUMBER) == 101814) + BATTLE_LerChange(battleindex,dieindex,i); + } + } +#endif + szBattleString[0] = 0; + pszBattleTop = szBattleString; + pszBattleLast = szBattleString+arraysizeof(szBattleString); + //printf("ǰ szBattleString=%s\n",szBattleString); + if( pBattle->field_att != BATTLE_ATTR_NONE ){ + pBattle->att_count--; + if( pBattle->att_count <= 0 ){ + pBattle->field_att = BATTLE_ATTR_NONE; + //snprintf( szBuffer, sizeof(szBuffer), + // "fieldظԡ" + //); + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + BATTLESTR_ADD( "BV|15|0|" ); + } + } + //printf(" szBattleString=%s\n",szBattleString); + strncat( szAllBattleString, szBattleString, sizeof( szAllBattleString ) ); + for( i = 0; i < entrynum; i ++ ){ + charaindex = EntryList[i].charaindex; + if( !CHAR_CHECKINDEX(charaindex) )continue; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_RESCUE ) + continue; + + if( BATTLE_CommandSend( charaindex, szAllBattleString ) == TRUE ){ + } + } + pWatchBattle = pBattle->pNext; + for( ; pWatchBattle ; pWatchBattle = pWatchBattle->pNext ){ + if( BATTLE_CHECKADDRESS( pWatchBattle ) == FALSE ){ + print( "err:սbattle address(%p)\n", pWatchBattle ); + break; + } + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pWatchBattle->Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + BATTLE_CommandSend( charaindex, szAllBattleString ); + } + pWatchBattle->mode = BATTLE_MODE_WATCHAFTER; + } + return 0; +} + +#ifdef _Item_ReLifeAct +BOOL CHECK_ITEM_RELIFE( int battleindex, int toindex) +{ + int i, itemindex; + CHAR_EquipPlace ep; + typedef void (*DIERELIFEFUNC)(int,int,int); + DIERELIFEFUNC Drf; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) { + return FALSE; + } + + if( CHAR_CHECKINDEX( toindex) == FALSE ) + return FALSE; + + if( CHAR_getInt( toindex, CHAR_HP) > 0 ) + return FALSE; + +#ifdef _DUMMYDIE + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == FALSE && CHAR_getFlg( toindex, CHAR_ISDUMMYDIE ) == FALSE ) +#else + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == FALSE ) +#endif + return FALSE; + + for( i = 0 ; i < CHAR_EQUIPPLACENUM ; i++ ){ + itemindex = CHAR_getItemIndex( toindex , i ); + if( !ITEM_CHECKINDEX( itemindex)) + continue; + ep = ITEM_getEquipPlace( toindex, itemindex ); + if( ep == -1 ) + continue; + Drf=(DIERELIFEFUNC)ITEM_getFunctionPointer(itemindex, ITEM_DIERELIFEFUNC); + + if( Drf ) { + Drf( toindex, itemindex, i); + return TRUE; + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + if(RunItemDieReLifeEvent(toindex, itemindex, i) == TRUE) + return TRUE; + } +#endif + + } + + return FALSE; + +} +#endif + +#ifdef _LOSE_FINCH_ +BOOL CHECK_PET_RELIFE( int battleindex, int petindex) +{ + int ReceveEffect=-1; + int toNo; + int attackNo=-1; + int WORK_HP=1; + int i; + struct _RePet{ + int petid; + int Effect; + int Addhp; +//Syu Mod +// }rePet[]={{1,SPR_fukkatu3,100},{-1,0,0}}; + }rePet[]={{-1,0,0}}; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) { + return FALSE; + } + if( CHAR_CHECKINDEX( petindex) == FALSE ) + return FALSE; + + if( CHAR_getFlg( petindex, CHAR_ISDIE) == FALSE ) { + print("\n PET_RELIFE:[ %d, CHAR_ISDIE FALSE] return !", petindex); + return FALSE; + } + if( CHAR_getWorkInt( petindex, CHAR_WORKSPETRELIFE) != 0 ) + return FALSE; + for( i=0;iskill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( skill_level >= 6 ) add_practice = (skill_level-5) * 3 + 10; + else add_practice = skill_level * 2; + if( add_practice > 25 ) add_practice = 25; + + add_practice += old_practice; + // Ϊold_practice=0add_practiceΪ2~25 + + CHAR_setWorkInt( charaindex, CHAR_WORK_F_PROFICIENCY, add_practice ); + + }else + // + if( (strcmp( skill_name , "PROFESSION_ICE_PRACTICE" )) == 0 ){ + int old_practice = CHAR_getInt( charaindex, PROFESSION_ICE_P ); + int add_practice = 0; + int skill_level = 0; + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( skill_level >= 6 ) add_practice = (skill_level-5) * 3 + 10; + else add_practice = skill_level * 2; + if( add_practice > 25 ) add_practice = 25; + + add_practice += old_practice; + + CHAR_setWorkInt( charaindex, CHAR_WORK_I_PROFICIENCY, add_practice ); + + }else + // + if( (strcmp( skill_name , "PROFESSION_THUNDER_PRACTICE" )) == 0 ){ + int old_practice = CHAR_getInt( charaindex, PROFESSION_THUNDER_P ); + int add_practice = 0; + int skill_level = 0; + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( skill_level >= 6 ) add_practice = (skill_level-5) * 3 + 10; + else add_practice = skill_level * 2; + if( add_practice > 25 ) add_practice = 25; + + add_practice += old_practice; + + CHAR_setWorkInt( charaindex, CHAR_WORK_T_PROFICIENCY, add_practice ); + + }else + // ر + if( (strcmp( skill_name , "PROFESSION_AVOID" )) == 0 ){ + int skill_level = 0; + + if( profession_class != PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS) ) return; + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + if( skill_level <=5 ) + value = skill_level * 2; + else + value = (skill_level-5) * 3; + if( value > 25 ) value = 25; + + CHAR_setWorkInt( charaindex, CHAR_WORK_P_DUCK, 1); + CHAR_setWorkInt( charaindex, CHAR_WORKMOD_P_DUCK, value ); + + }else + // + if( (strcmp( skill_name , "PROFESSION_DEFLECT" )) == 0 ){ + int skill_level = 0; + int old_value = 0, add_value = 0; + + if( profession_class != PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS) ) return; + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + old_value = CHAR_getWorkInt( charaindex, CHAR_WORKFIXARRANGE ); + add_value = old_value + skill_level + 10; + + CHAR_setWorkInt( charaindex, CHAR_WORKFIXARRANGE, add_value ); + CHAR_complianceParameter( charaindex ); + + }else + // ר + if( (strcmp( skill_name , "PROFESSION_WEAPON_FOCUS" )) == 0 ){ + int skill_level = 0; + + rate = 0; + if( profession_class != PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS) ) continue; + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + // ܲ + pszOption = PROFESSION_SKILL_getChar( Pskillid, PROFESSION_SKILL_OPTION); + if( pszOption == "\0" ) continue; + + // װ + WeaponType = BATTLE_GetWepon( charaindex ); + + switch( WeaponType ){ + case ITEM_AXE: + if( (pszP=strstr( pszOption, "" ))!=NULL) rate = 1; break; + case ITEM_CLUB: + if( (pszP=strstr( pszOption, "" ))!=NULL) rate = 1; break; + case ITEM_SPEAR: + if( (pszP=strstr( pszOption, "ǹ" ))!=NULL) rate = 1; break; + case ITEM_BOW: + if( (pszP=strstr( pszOption, "" ))!=NULL) rate = 1; break; + case ITEM_BOOMERANG: // + if( (pszP=strstr( pszOption, "" ))!=NULL) rate = 1; break; + case ITEM_BOUNDTHROW: // Ͷͷ + if( (pszP=strstr( pszOption, "Ͷ" ))!=NULL) rate = 1; break; + case ITEM_BREAKTHROW: // Ͷʯ + if( (pszP=strstr( pszOption, "ʯ" ))!=NULL) rate = 1; break; + default: rate = 0; break; + } + + if( rate == 1 ){ + old_value = CHAR_getWorkInt( charaindex, CHAR_MYSKILLSTRPOWER); + + if( skill_level <=5 ) + value = skill_level * 2 + old_value; + else + value = (skill_level-5) * 3 + 10 + old_value; + + if( value > 25 ) value = 25; + + CHAR_setWorkInt( charaindex, CHAR_WORK_WEAPON, 1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKMOD_WEAPON, value ); + } + } + } + } + return; +} + + +void BATTLE_ProfessionStatusSeq( int battleindex, int charaindex ) +{ + int profession_class=0, i=0, j=0, Pskillid=-1, skillid=-1; + int skill_level=0, value=0, old_value=0; + int bid=-1, hp=0, flag=0; + char *skill_name, szcommand[256]; + CHAR_HaveSkill* hskill; + + + int status_table[9]={ 2, // + 3, //˯ + 4, //ʯ + 12, //ѣ + 13, // + 14, // + 15, // + 17, // + 23, }; //׸ + +#ifdef _PETSKILL_DAMAGETOHP +/* { + char msg[32]={0}; + int pet,pindex; + pet = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + if( pet >= 0 ){ + sprintf( msg, "o%d", pet ); + //if(CHAR_getInt( petindex, CHAR_PETID) == "" //ID + // && CHAR_getInt( petindex, CHAR_HP) ) + CHAR_sendStatusString( charaindex, msg ); + pindex = CHAR_getCharPet( charaindex, pet ); + print("\n:%s",CHAR_getChar( pindex, CHAR_NAME)); + } + else + print("\޳"); + + } */ +#endif + + if ( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) return; + + profession_class=CHAR_getInt( charaindex, PROFESSION_CLASS); + if( profession_class <= PROFESSION_CLASS_NONE ) return; + + for( i=0; i 0 ){ + flag=1; + break; + } + } + + if( flag > 0 ){ + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + value = skill_level * 2; + if( value > 20 ) value = 20; + + old_value = CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP); + + value = old_value * value / 100 ; + + hp = CHAR_getInt( charaindex, CHAR_HP); + + if( value + hp > old_value ) + value = old_value - hp; + + if( value < 0 ) value = 0; + + CHAR_setInt( charaindex, CHAR_HP, value + hp ); + + bid = BATTLE_Index2No( battleindex, charaindex ); + sprintf( szcommand, "BD|r%X|0|1|%X|", bid, value ); + BATTLESTR_ADD( szcommand ); + + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_REBACK" ); + } + } + + // + if( (strcmp( skill_name , "PROFESSION_TRAP" )) == 0 ){ + int count=0; + + count = CHAR_getWorkInt( charaindex, CHAR_WORKTRAP); + if( count > 0 ){ + count--; + CHAR_setWorkInt( charaindex, CHAR_WORKTRAP, count ); + }else if( count == 0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKMODTRAP, 0 ); + } + } + } + + return; +} + +#endif + +#ifdef _ALLBLUES_LUA_1_4 +INLINE BOOL BATTLE_setLUAFunction( int battleindex, int functype, lua_State *L, const char *luafunctable) +{ + if( !BATTLE_CHECKINDEX(battleindex) )return FALSE; + + if( functype < 0 || functype >= BATTLE_FUNCTABLENUM )return FALSE; + + BattleArray[battleindex].lua[functype] = L; + BattleArray[battleindex].luafunctable[functype] = allocateMemory( strlen(luafunctable) ); + memset(BattleArray[battleindex].luafunctable[functype], 0, strlen(luafunctable)); + strcpy(BattleArray[battleindex].luafunctable[functype], luafunctable); + + return TRUE; +} + +INLINE lua_State *BATTLE_getLUAFunction( int battleindex, int functype) +{ + + if( !BATTLE_CHECKINDEX(battleindex) )return NULL; + + if( functype < 0 || functype >= BATTLE_FUNCTABLENUM ) + return NULL; + + if(BattleArray[battleindex].lua[functype] == NULL){ + return NULL; + } + + lua_getglobal( BattleArray[battleindex].lua[functype], BattleArray[battleindex].luafunctable[functype]); + return BattleArray[battleindex].lua[functype]; +} +#endif + +int BATTLE_getType( int battleindex ) +{ + if(battleindex>=BATTLE_battlenum || battleindex<0 )return -1; + + return BattleArray[battleindex].type; +} +#ifdef _BATTLE_TIMESPEED +int BATTLE_getCreateTime( int battleindex ) +{ + if(battleindex>=BATTLE_battlenum || battleindex<0 )return -1; + + return BattleArray[battleindex].CreateTime; +} +#endif + +int BATTLE_getBattleFloor( int battleindex ) +{ + if(battleindex>=BATTLE_battlenum || battleindex<0 )return -1; + + return BattleArray[battleindex].BattleFloor; +} +#ifdef _JZ_NEWSCRIPT_LUA +int SearchFmWarRandIndex(int charaindex,int fmwarfloor) +{ + int i=1,j,fmwarindex; + int bindex[100]; + bindex[0]=-1; + for( j = 0; j < BATTLE_battlenum; j ++ ){ + if( BattleArray[j].use == FALSE ){ + continue; + }else{ + if(BattleArray[j].floor!=fmwarfloor){ + continue; + }else{ + bindex[i-1]=j; + i++; + continue; + } + } + } + if(bindex[0]>-1){ + fmwarindex = bindex[RAND(1,i)-1]; + if(BATTLE_CHECKINDEX(fmwarindex)==FALSE) + return -1; + else{ + if(BattleArray[fmwarindex].floor!=fmwarfloor) + return -1; + if(BATTLE_CreateForWatcher( charaindex, fmwarindex )==0){ + int fd; + if( ( fd = getfdFromCharaIndex(charaindex) ) != -1 ){ + lssproto_EN_send( fd, BattleArray[fmwarindex].type, BattleArray[fmwarindex].field_no ); + } + char szBuffer[256]; + sprintf( szBuffer, "BP|%X|%X|%X", + 20, BP_FLG_JOIN, CHAR_getInt(charaindex, CHAR_MP ) ); + BATTLE_CommandSend( charaindex, szBuffer ); + return 0; + } + } + } + return -1; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_ai.c b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_ai.c new file mode 100644 index 0000000..74af45c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_ai.c @@ -0,0 +1,528 @@ +#include "version.h" +#include +#include "common.h" +#include "char.h" +#include "char_base.h" +#include "battle.h" +#include "npcutil.h" +#include "pet_skill.h" + +struct B_AI_RESULT { + BATTLE_COM command; /* ë¾ */ + int target; /* */ +}; + +static int BATTLE_ai_normal( int, int, BATTLE_ENTRY *,struct B_AI_RESULT *); + +static int (*functbl[])( int, int, BATTLE_ENTRY *,struct B_AI_RESULT *) = { + NULL, + BATTLE_ai_normal, +}; +int BATTLE_ai_all( int battleindex, int side, int turn) +{ + int i; + int rc = FALSE; + BATTLE_ENTRY *pEntry; + struct B_AI_RESULT result; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( BATTLE_CHECKSIDE( side ^1) == FALSE )return BATTLE_ERR_PARAM; + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_ENEMY ) return FALSE; + pEntry = BattleArray[battleindex].Side[side^1].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + int charaindex = BattleArray[battleindex].Side[side].Entry[i].charaindex; + int mode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + mode = CHAR_getWorkInt( charaindex, CHAR_WORKTACTICS); + if( mode < 0 || mode >= arraysizeof( functbl)){ + print( "BATTLE_ai_all ,ս߼ģʽ(%s)(%d)\n", + CHAR_getUseName( charaindex ), mode ); + mode = 1; + } + if( BATTLE_IsCharge( charaindex ) == TRUE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + continue; + } + if( BattleArray[battleindex].Side[side].flg & BSIDE_FLG_SURPRISE) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + }else { + if( functbl[mode] != NULL ) { + rc = functbl[mode]( turn, charaindex, pEntry, &result); + if( BATTLE_CanMoveCheck( charaindex ) == FALSE ){ + result.command = BATTLE_COM_NONE; + } + } + if( rc ) { +#ifdef _BATTLENPC_WARP_PLAYER + if(result.command==BATTLE_COM_WARP){ + for( i=0; icharaindex; + if( !CHAR_CHECKINDEX( tindex ))continue; + if( CHAR_getFlg( tindex, CHAR_ISDIE)) continue; + if( CHAR_getWorkInt( tindex, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_RESCUE ) continue; + if( CHAR_getInt( tindex, CHAR_WHICHTYPE)==CHAR_TYPEPLAYER){ + char sBuff[1024]="", sBuff1[1024]=""; + int ss[3]; + int sii; + int rc = 1; + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_ACT_CONDITION), + "wp", sBuff, sizeof( sBuff))!=NULL){ + for( sii=1; sii<=3; sii++){ + if(getStringFromIndexWithDelim( sBuff, ";", sii, sBuff1, sizeof( sBuff1))) + {ss[sii-1]=atoi(sBuff1);} + else + {rc=0;} + } + if(rc){ + CHAR_warpToSpecificPoint( tindex, ss[0], ss[1], ss[2]); + BATTLE_WatchStop( tindex); + } + } + } + } + } +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, result.command ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, + result.target + (side^1)*SIDE_OFFSET); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + } + } + } + return TRUE; +} + +int BATTLE_ai_one( int charaindex, int battleindex, int side, int turn) +{ + int rc = FALSE; + BATTLE_ENTRY *pEntry; + struct B_AI_RESULT result; + int mode; + + /* ɷ¶ */ + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + if( BATTLE_CHECKSIDE( side ) == FALSE )return BATTLE_ERR_PARAM; + if( BATTLE_CHECKSIDE( side ^1) == FALSE )return BATTLE_ERR_PARAM; + + /* 浤 */ + /* ƽҷ¶½ */ + if( BattleArray[battleindex].Side[side].type != BATTLE_S_TYPE_ENEMY ) return 0; + + /* */ + pEntry = BattleArray[battleindex].Side[side^1].Entry; + + mode = CHAR_getWorkInt( charaindex, CHAR_WORKTACTICS); + /* ëԻ */ + if( mode < 0 || mode >= arraysizeof( functbl)) return FALSE; + /* ëԻ */ + if( functbl[mode] != NULL ) { + rc = functbl[mode]( turn, charaindex, pEntry, &result); + } + if( rc ) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, result.command ); + if( result.command == BATTLE_COM_ATTACK) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, + result.target + (side^1)*SIDE_OFFSET); + } + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } + return TRUE; +} + +/* ɧë裻 */ + +#define B_AI_NORMAL_ATTACKOPTION "at" /* */ +#define B_AI_NORMAL_GUARDOPTION "gu" /* */ +#define B_AI_NORMAL_MAGICOPTION "ma" /* */ +#define B_AI_NORMAL_ESCAPEOPTION "es" /* */ +#define B_AI_NORMAL_WAZAOPTION "wa" /* */ +#ifdef _ENEMY_ATTACK_AI +#define B_AI_NORMAL_RANDAOPTION "rn" +#define B_AI_NORMAL_RANDOMOPTIONNUM 1 +#endif + +#define B_AI_NORMAL_ATTACKSUBOPTIONNUM 3 +#define B_AI_NORMAL_GUARDSUBOPTIONNUM 1 +#define B_AI_NORMAL_MAGICSUBOPTIONNUM 1 +#define B_AI_NORMAL_ESCAPESUBOPTIONNUM 1 +#define B_AI_NORMAL_WAZASUBOPTIONNUM 7 + +/* ¦Ѽ ٯ */ +#define B_AI_NORMAL_TARGET_ALL 1 +#define B_AI_NORMAL_TARGET_PLAYER 2 +#define B_AI_NORMAL_TARGET_PET 3 +#ifdef _ENEMY_ATTACK_AI +#define B_AI_NORMAL_TARGET_LEADER 4 +#endif +#define B_AI_NORMAL_SELECT_RANDOM 1 +#define B_AI_NORMAL_SELECT_HP_MAX 2 +#define B_AI_NORMAL_SELECT_HP_MIN 3 +#ifdef _ENEMY_ATTACK_AI +#define B_AI_NORMAL_SELECT_STR_MAX 4 +#define B_AI_NORMAL_SELECT_DEX_MAX 5 +#define B_AI_NORMAL_SELECT_DEX_MIN 6 +#define B_AI_NORMAL_SELECT_ATT_SUBDUE 7 +enum{ + AI_ATT_EARTHAT = 1, + AI_ATT_WATERAT, + AI_ATT_FIREAT, + AI_ATT_WINDAT +}; +int GetSubdueAttribute(int index){ + int s_a = CHAR_getWorkInt( index, CHAR_WORKFIXEARTHAT); + int s_b = CHAR_getWorkInt( index, CHAR_WORKFIXWATERAT); + int s_c = CHAR_getWorkInt( index, CHAR_WORKFIXFIREAT); + int s_d = CHAR_getWorkInt( index, CHAR_WORKFIXWINDAT); + return ((s_a>s_c)?((s_b>s_d)?((s_a>s_b)?(2):(3)):((s_a>s_d)?(2):(1))):((s_b>s_d)?((s_c>s_b)?(4):(3)):((s_c>s_d)?(4):(1)))); +} +#endif + +typedef enum { + B_AI_ATTACKMODE = 1, + B_AI_GURADMODE, + B_AI_MAGICMODE, + B_AI_ESCAPEMODE, + B_AI_WAZAMODE0, + B_AI_WAZAMODE1, + B_AI_WAZAMODE2, + B_AI_WAZAMODE3, + B_AI_WAZAMODE4, + B_AI_WAZAMODE5, + B_AI_WAZAMODE6, +}B_AI_MODE; + +static int BATTLE_ai_normal( int turn, int charaindex, + BATTLE_ENTRY *pEntry, + struct B_AI_RESULT *result) +{ + int at[B_AI_NORMAL_ATTACKSUBOPTIONNUM] = { 0,0,0}; /* */ + int gu[B_AI_NORMAL_GUARDSUBOPTIONNUM] = {0}; /* */ + int ma[B_AI_NORMAL_MAGICSUBOPTIONNUM] = {0}; /* */ + int es[B_AI_NORMAL_ESCAPESUBOPTIONNUM] = {0}; /* */ + int wa[B_AI_NORMAL_WAZASUBOPTIONNUM] = {0,0,0,0, 0,0,0};/* */ +#ifdef _ENEMY_ATTACK_AI + int rn[B_AI_NORMAL_RANDOMOPTIONNUM] = {1}; +#endif + int target[BATTLE_ENTRY_MAX]; + int cnt; + int i; + int r; + int rc; + int mode=0; + char buff[256]; + char buff2[256]; + + if( turn == 1 ) { + print( "Ӧû¡\n" ); + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_ATTACKOPTION, buff, sizeof( buff)) != NULL ){ + for( i = 1; i < B_AI_NORMAL_ATTACKSUBOPTIONNUM + 1; i ++ ) { + rc = getStringFromIndexWithDelim( buff, ";", i, buff2, sizeof( buff2)); + if( rc != TRUE ) { + print( "battle_ai.c:Invarid Param [%s]\n", + CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION)); + return FALSE; + } + at[i-1] = atoi( buff2); + } + } + + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_GUARDOPTION, buff, sizeof( buff)) != NULL ){ + for( i = 1; i < B_AI_NORMAL_GUARDSUBOPTIONNUM + 1; i ++ ) { + rc = getStringFromIndexWithDelim( buff, ";", i, buff2, sizeof( buff2)); + if( rc != TRUE ) { + print( "battle_ai.c:Invarid Param [%s]\n", + CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION)); + return FALSE; + } + gu[i-1] = atoi( buff2); + } + } + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_MAGICOPTION, + buff, sizeof( buff)) != NULL ){ + for( i = 1; i < B_AI_NORMAL_MAGICSUBOPTIONNUM + 1; i ++ ) { + rc = getStringFromIndexWithDelim( buff, ";", i, buff2, sizeof( buff2)); + if( rc != TRUE ) { + print( "battle_ai.c:Invarid Param [%s]\n", + CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION)); + return FALSE; + } + ma[i-1] = atoi( buff2); + + } + } + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_ESCAPEOPTION, + buff, sizeof( buff)) != NULL ){ + for( i = 1; i < B_AI_NORMAL_ESCAPESUBOPTIONNUM + 1; i ++ ) { + rc = getStringFromIndexWithDelim( buff, ";", i, buff2, sizeof( buff2)); + + if( rc != TRUE ) { + print( "battle_ai.c:Invarid Param [%s]\n", + CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION)); + return FALSE; + } + es[i-1] = atoi( buff2); + } + } + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_WAZAOPTION, + buff, sizeof( buff)) != NULL ){ + for( i = 1; i < B_AI_NORMAL_WAZASUBOPTIONNUM + 1; i ++ ) { + rc = getStringFromIndexWithDelim( buff, ";", i, buff2, sizeof( buff2)); + if( rc != TRUE ) { + }else{ + wa[i-1] = atoi( buff2); + } + } + } +#ifdef _ENEMY_ATTACK_AI + if( NPC_Util_GetStrFromStrWithDelim( CHAR_getWorkChar( charaindex, CHAR_WORKBATTLE_TACTICSOPTION), + B_AI_NORMAL_RANDAOPTION, + buff, sizeof( buff))!=NULL){ + for( i=1; icommand = BATTLE_COM_WARP; + return TRUE; + } + } +#endif + if( at[0] == 0 && gu[0] == 0 && ma[0] == 0 && es[0] == 0 ){ + for( i = 0; i < B_AI_NORMAL_WAZASUBOPTIONNUM; i ++ ){ + if( wa[i] != 0 )break; + } + if( i >= B_AI_NORMAL_WAZASUBOPTIONNUM ){ + print( "ָκεĹʽ\n" ); + return FALSE; + } + } + while( !mode ) { + int work = 0; + work = at[0]+gu[0]+ma[0]+es[0]; + for( i = 0; i < B_AI_NORMAL_WAZASUBOPTIONNUM; i ++ ){ + work += wa[i]; + } + r = RAND( 0, work - 1 ); + if( at[0] != 0 && r < at[0] ) mode = B_AI_ATTACKMODE; + else if( gu[0] != 0 && r < at[0] + gu[0]) mode = B_AI_GURADMODE; + else if( ma[0] != 0 && r < at[0] + gu[0] + ma[0]) mode = B_AI_MAGICMODE; + else if( es[0] != 0 && r < at[0] + gu[0] + ma[0] + es[0] ){ + mode = B_AI_ESCAPEMODE; + } + if( mode ) break; + work = at[0] + gu[0] + ma[0] + es[0]; + for( i = 0; i < B_AI_NORMAL_WAZASUBOPTIONNUM; i ++ ){ + work += wa[i]; + if( wa[i] != 0 && r < work ){ + mode = B_AI_WAZAMODE0+i; + break; + } + } + } + if( mode == B_AI_ATTACKMODE || ( B_AI_WAZAMODE0 <= mode && mode <= B_AI_WAZAMODE6 )){ + while( 1 ) { + for( i = 0 ; i < BATTLE_ENTRY_MAX; i ++ ) { + target[i] = -1; + } + cnt = 0; + for( i = 0; i < BATTLE_ENTRY_MAX ; i ++ ) { + int tindex = (pEntry+i)->charaindex; + if( !CHAR_CHECKINDEX( tindex ))continue; + if( CHAR_getFlg( tindex, CHAR_ISDIE)) continue; + if( CHAR_getWorkInt( tindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_RESCUE ) continue; + switch( at[1]) { + case B_AI_NORMAL_TARGET_PLAYER: + if( CHAR_getInt( tindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + target[cnt++] = i; + } + break; + case B_AI_NORMAL_TARGET_PET: + if( CHAR_getInt( tindex, CHAR_WHICHTYPE) == CHAR_TYPEPET){ + target[cnt++] = i; + } + break; +#ifdef _ENEMY_ATTACK_AI + case B_AI_NORMAL_TARGET_LEADER: + if( CHAR_getWorkInt( tindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER) { + target[cnt++] = i; + }else if(!RAND( 0, 2)) { + target[cnt++] = i; + } + break; +#endif + default: + target[cnt++] = i; + break; + } + } + if( cnt == 0 && at[1] == B_AI_NORMAL_TARGET_ALL ) return FALSE; + if( cnt > 0 ) break; + at[1] = B_AI_NORMAL_TARGET_ALL; + } + result->command = BATTLE_COM_NONE; + if( at[2] == B_AI_NORMAL_SELECT_RANDOM ) { + r = RAND( 0, cnt-1); + result->command = BATTLE_COM_ATTACK; + result->target = target[r]; + }else if( at[2] == B_AI_NORMAL_SELECT_HP_MAX || at[2] == B_AI_NORMAL_SELECT_HP_MIN ){ + int top = 0; + for( i = 0; i < cnt; i ++ ) { + if( i ==0 ) top = target[i]; + else { + int tophp = CHAR_getInt((pEntry+top)->charaindex, CHAR_HP); + int comphp = CHAR_getInt((pEntry+target[i])->charaindex, CHAR_HP); + if( at[2] == B_AI_NORMAL_SELECT_HP_MAX ) { + if( comphp > tophp ) top = target[i]; + } + else { + if( comphp < tophp ) top = target[i]; + } + } + } +#ifdef _ENEMY_ATTACK_AI + if(!RAND( 0, rn[0])) + result->target = target[RAND( 0, cnt-1)]; + else + result->target = top; + result->command = BATTLE_COM_ATTACK; +#else + result->command = BATTLE_COM_ATTACK; + result->target = top; +#endif + } +#ifdef _ENEMY_ATTACK_AI + else if(at[2] == B_AI_NORMAL_SELECT_STR_MAX) { + int top = 0; + for( i=0; icharaindex, CHAR_STR); + int compstr = CHAR_getInt( (pEntry+target[i])->charaindex, CHAR_STR); + if(compstr>topstr) top = target[i]; + } + } + if(!RAND( 0, rn[0])) + result->target = target[RAND( 0, cnt-1)]; + else + result->target = top; + result->command = BATTLE_COM_ATTACK; + } + else if(at[2] == B_AI_NORMAL_SELECT_DEX_MAX || + at[2] == B_AI_NORMAL_SELECT_DEX_MIN) { + int top = 0; + for( i=0; icharaindex, CHAR_DEX); + int compdex = CHAR_getInt( (pEntry+target[i])->charaindex, CHAR_DEX); + if(at[2]==B_AI_NORMAL_SELECT_DEX_MAX) { + if(compdex>topdex) top = target[i]; + }else { + if(compdextarget = target[RAND( 0, cnt-1)]; + else + result->target = top; + result->command = BATTLE_COM_ATTACK; + } + else if(at[2] == B_AI_NORMAL_SELECT_ATT_SUBDUE) { + int top = 0; + for( i=0; icharaindex, CHAR_WORKFIXEARTHAT); + int compatt = CHAR_getWorkInt( (pEntry+target[i])->charaindex, CHAR_WORKFIXEARTHAT); + if(compatt>topatt) top = target[i]; + } + break; + case AI_ATT_WATERAT: + { + int topatt = CHAR_getWorkInt( (pEntry+top)->charaindex, CHAR_WORKFIXWATERAT); + int compatt = CHAR_getWorkInt( (pEntry+target[i])->charaindex, CHAR_WORKFIXWATERAT); + if(compatt>topatt) top = target[i]; + } + break; + case AI_ATT_FIREAT: + { + int topatt = CHAR_getWorkInt( (pEntry+top)->charaindex, CHAR_WORKFIXFIREAT); + int compatt = CHAR_getWorkInt( (pEntry+target[i])->charaindex, CHAR_WORKFIXFIREAT); + if(compatt>topatt) top = target[i]; + } + break; + case AI_ATT_WINDAT: + { + int topatt = CHAR_getWorkInt( (pEntry+top)->charaindex, CHAR_WORKFIXWINDAT); + int compatt = CHAR_getWorkInt( (pEntry+target[i])->charaindex, CHAR_WORKFIXWINDAT); + if(compatt>topatt) top = target[i]; + } + break; + default: + break; + } + } + } + if(!RAND( 0, rn[0])) + result->target = target[RAND( 0, cnt-1)]; + else + result->target = top; + result->command = BATTLE_COM_ATTACK; + } +#endif + else{ + return FALSE; + } + if( B_AI_WAZAMODE0 <= mode && mode <= B_AI_WAZAMODE6 ){ + if( PETSKILL_Use( charaindex, mode - B_AI_WAZAMODE0, result->target,NULL ) == TRUE ){ + result->command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + return TRUE; + }else{ +// print( "δ趨(%s):(%d)\n", +// CHAR_getUseName( charaindex), mode - B_AI_WAZAMODE0 ); + return FALSE; + } + }else + if( mode == B_AI_ATTACKMODE ){ + result->command = BATTLE_COM_ATTACK; + return TRUE; + } + }else if( mode == B_AI_GURADMODE ) { + result->command = BATTLE_COM_GUARD; + return TRUE; + }else if( mode == B_AI_ESCAPEMODE ) { + result->command = BATTLE_COM_ESCAPE; + return TRUE; + } + return FALSE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_command.c b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_command.c new file mode 100644 index 0000000..96e00fa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_command.c @@ -0,0 +1,1251 @@ +#include "version.h" +#include +#include +#include"char.h" +#include"char_base.h" +#include "battle.h" +#include "pet_skill.h" +#include "battle_event.h" +#include "battle_command.h" +#include "lssproto_serv.h" +#include "magic.h" +#include "magic_base.h" +#include "handletime.h" +#include "configfile.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#endif +int checkErrorStatus( int charaindex); +int NowBattlerFd; +#if 1 +int BATTLE_MpDown( int charaindex, int down ) +{ + return 0; +} +#else +{ + int mp, battleindex; + // о??? + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return TRUE; + // оԪئ?? + if( BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + return TRUE; + } + + // ??ëӼ¾ + mp = CHAR_getInt( charaindex, CHAR_MP ); + if( mp < down ){ + // Ӽئмƥئ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + // ѨOK϶ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return FALSE; + } + mp -= down; + CHAR_setInt( charaindex, CHAR_MP, mp ); + return TRUE; +} +#endif + + +void BattleCommandDispach( int fd, char *command ) +{ + int endFlg = 0, battleindex; + int EscapeFree = BATTLE_FLG_FREEDP; + int charaindex = CONNECT_getCharaindex(fd); + char szBuffer[256]=""; +#ifdef _FIXWOLF // Syu ADD ˱Bug + int i , j , pindex; + BATTLE_ENTRY *pEntry; +#endif + + NowBattlerFd = fd; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + //printf("BattleCommandDispach:%s %d\n", __FILE__, __LINE__); + return; + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE || + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + //printf("BattleCommandDispach:%s %d\n", __FILE__, __LINE__); + return; + } + + + if( BattleArray[battleindex].flg & BATTLE_FLG_CHARALOST ){ + EscapeFree = 0; + } + + if( strncmp( command, "U", 1 ) == 0 ){ + // shan 2001/12/25 begin + EscapeFree = 0; + if (CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEWATCH )!=TRUE){ + CHAR_talkToCli( charaindex, -1, + "ħʹ㶨ս", CHAR_COLORYELLOW ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + BATTLE_MpDown( charaindex, 2 ); + }else{ + BATTLE_WatchStop( charaindex ); + } + // shan end + }else + if( strncmp( command, "E", 1 ) == 0 ){ + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } +#ifdef _NOT_ESCAPE + + int i; + for(i=0;i<32;i++){ + if(getNotEscape(i) == CHAR_getInt(charaindex, CHAR_FLOOR)){ + CHAR_talkToCli( charaindex, -1, + "ħʹ㶨ս", CHAR_COLORYELLOW ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + break; + } + } + if(i==32) +#endif +{ + CHAR_setWorkInt( charaindex, CHAR_WORKDBATTLEESCAPE,1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ESCAPE ); +} + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + + BATTLE_MpDown( charaindex, 20 ); + + }else + if( strncmp( command, "H|", 2 ) == 0 ){ + int iNum = -1, At_SoubiIndex; + if( sscanf( command+2, "%X", &iNum ) != 1 + || ( iNum < 0 || iNum >= 20 ) + ){ + iNum = -1; + } + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, iNum ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + + At_SoubiIndex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( At_SoubiIndex ) == FALSE ){ + + }else{ + + if( ITEM_getInt( At_SoubiIndex, ITEM_TYPE ) == ITEM_BOOMERANG ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_BOOMERANG ); + //print("ITEM_TYPE=%d iNum=%d",At_SoubiIndex,iNum); +#ifdef _PETSKILL_BECOMEFOX + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101749 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС겻ʹû + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 ){// + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + } +#endif + } + } + + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, 1 ); + //sprintf( szBuffer, "Command(%s)(ս)", CHAR_getUseName( charaindex ) ); + + endFlg = 1; + + BATTLE_MpDown( charaindex, 5 ); + + }else + if( strncmp( command, "G", 1 ) == 0 ){ + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + + BATTLE_MpDown( charaindex, 2 ); + + }else + if( strncmp( command, "N", 1 ) == 0 ){ + + EscapeFree = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); +// sprintf( szBuffer, "Command(%s)(serverй)", CHAR_getUseName( charaindex ) ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + + }else + if( strncmp( command, "T|", 2 ) == 0 ){ + int iNum = -1; + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + if( sscanf( command+2, "%X", &iNum ) != 1 + || ( iNum < 0 || iNum >= 20 ) + ){ + iNum = -1; + } + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, iNum ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_CAPTURE ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + + BATTLE_MpDown( charaindex, 20 ); + + }else + if( strncmp( command, "S|", 2 ) == 0 ){ + int iNum = -1; + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + // shan 2002/01/08 begin + if( sscanf( command+2, "%d", &iNum ) != 1 + || ( iNum < -1 || iNum >= CHAR_MAXPETHAVE ) + || ( CHAR_getInt(charaindex,CHAR_RIDEPET)==iNum) + ){ + iNum = -1; + } + // shan end +#ifdef _STANDBYPET + //if( iNum >= 0) { + // if( ! (CHAR_getWorkInt( charaindex, CHAR_WORKSTANDBYPET) & ( 1 << iNum)) ) { + // print("\n ķ!гǴ!!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + // iNum = -1; + // } + //} +#endif + + + int petindex = CHAR_getCharPet( charaindex, iNum); + /* + if(CHAR_CHECKINDEX(petindex) == 1){ + if(( CHAR_getWorkInt( petindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND1 + || CHAR_getWorkInt( petindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 + )&&(CHAR_getFlg( petindex, CHAR_ISDIE ) == TRUE)){ + CHAR_talkToCli( charaindex, -1,"ʹõһܣ޷裬˰ѳջأ", CHAR_COLORYELLOW ); + iNum = -1; + } + } +*/ +#ifdef _PET_VALIDITY + if(CHAR_getInt ( petindex, CHAR_PETVALIDITY) > 0 && CHAR_getInt ( petindex, CHAR_PETVALIDITY) < time(NULL) ){ + CHAR_talkToCli(charaindex, -1, "óѾʧЧˣ", CHAR_COLORYELLOW); + iNum = -1; + } +#endif + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, iNum ); + if( iNum < 0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_PETIN ); + //sprintf( szBuffer, "Command(%s)(س)", CHAR_getUseName( charaindex ) ); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_PETOUT ); + //sprintf( szBuffer, "Command(%s)(г)", CHAR_getUseName( charaindex ) ); + } + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + endFlg = 1; + + BATTLE_MpDown( charaindex, 10 ); + + }else + if( strncmp( command, "W|", 2 ) == 0 ){ + int iNum = -1, petskillindex = -1, ToNo = -1, petnum, petindex; + + if( sscanf( command+2, "%X|%X", &iNum, &ToNo ) < 1 ){ + iNum = -1; ToNo = -1; + } + if(iNum == 255)iNum=-1; + if(ToNo == 255)ToNo=-1; + + petnum = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + petindex = CHAR_getCharPet( charaindex, petnum ); + if( CHAR_CHECKINDEX( petindex ) == FALSE ){ + }else{ +#ifdef _FIX_PETSKILL_BUG + if(CHAR_getWorkInt( petindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_C_OK + || CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_C_OK){ + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + }else +#endif + if( iNum < 0 || iNum >= CHAR_MAXPETSKILLHAVE +#ifdef _PETSKILLBUG //Add By Syu 2002.0805 + || (CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE )|| + (CHAR_getInt( charaindex, CHAR_HP ) <= 0) +#endif + || checkErrorStatus( petindex) + ) + { + //sprintf( szBuffer, "Command(%s)(Զ)", CHAR_getUseName( petindex ) ); + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); +#ifdef _PETSKILLBUG //Add By Syu 2002.0805 + }else if ((CHAR_getInt(petindex, CHAR_TRANSMIGRATION)<1) + && ( iNum>=CHAR_getInt(petindex, CHAR_SLOT) ) ) + { + //sprintf( szBuffer, "Command(%s)(Զ)", CHAR_getUseName( petindex ) ); + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); +#endif + }else{ + petskillindex = PETSKILL_GetArray( petindex, iNum); +#ifdef _FIXWOLF // Syu ADD ˱Bug + if( (CHAR_getPetSkill( petindex , iNum )== 600) && (ToNo == -1)) + { + for( j = 0; j < 2; j ++ ) + { + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ) + { + pindex = pEntry[i].charaindex; + if( pindex == petindex) + { + ToNo=i + ( j * 10 ); + break; + } + } + } + } +#endif + if( petskillindex >= 0 + && PETSKILL_Use( petindex, iNum, ToNo, NULL ) == TRUE + ){ + //sprintf( szBuffer, "Command(%s)(ʯ)", CHAR_getUseName( petindex ) ); + + EscapeFree = 0; + + }else{ + //sprintf( szBuffer, "Command(%s)(Զ)", CHAR_getUseName( petindex ) ); + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } + } + } + endFlg = 1; + + BATTLE_MpDown( charaindex, 10 ); + + }else + if( strncmp( command, "J|", 1 ) == 0 ){ + int iNum = -1, magicindex = -1, ToNo = -1; + int valid = -1; + int itemindex=-1; + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + if( sscanf( command+2, "%X|%X", &iNum, &ToNo ) != 2 ){ + iNum = -1; ToNo = -1; + } + + if( iNum < CHAR_EQUIPPLACENUM && iNum >= CHAR_HEAD ){ + magicindex = MAGIC_GetArrayNo( charaindex, iNum ); + itemindex = CHAR_getItemIndex( charaindex, iNum ); + valid = MAGIC_isTargetValid( magicindex, ToNo); + + if ((valid <0 ) || ( magicindex < 0 ) || (itemindex < 0 )){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + }else{ +#ifdef _ITEM_ATTSKILLMAGIC + char *magicarg; + int magic_array = -1; + magic_array = MAGIC_getMagicArray( magicindex ); + magicarg = MAGIC_getChar( magic_array, MAGIC_OPTION ); + if( magicarg != "\0" && strstr( magicarg, "SKILL") != NULL ) { + int mp = ITEM_getInt( itemindex, ITEM_MAGICUSEMP ); + if( MAGIC_AttSkill( charaindex, ToNo, magic_array, mp) == FALSE ) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } + }else { +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, ToNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_JYUJYUTU ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, magicindex ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, iNum ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); +#ifdef _ITEM_ATTSKILLMAGIC + } +#endif + } + }else{ + EscapeFree = 0; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + } + endFlg = 1; + }else + if( strncmp( command, "I|", 1 ) == 0 ){ + int iNum = -1, ToNo = -1; + int valid = 0, itemindex = -1; + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + if( sscanf( command+2, "%X|%X", &iNum, &ToNo ) != 2 ){ + iNum = -1; ToNo = -1; + } + itemindex = CHAR_getItemIndex( charaindex, iNum ); + if ( !ITEM_CHECKINDEX( itemindex) ) valid=-1; + if (valid >= 0) valid = ITEM_isTargetValid( charaindex, itemindex, ToNo ); + if (valid < 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } else { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, ToNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ITEM ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM3, iNum ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); + endFlg = 1; + } + }else + if( strncmp( command, "@", 1 ) == 0 ){ + //sprintf( szBuffer, "Command(%s)(ͨ)", CHAR_getUseName( charaindex ) ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + endFlg = 1; + + CHAR_setInt( charaindex, CHAR_MP, + min( 100, CHAR_getInt( charaindex, CHAR_MP ) + 30 ) ); + + }else +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( strncmp( command, "P", 1 ) == 0 ){ + int iNum=-1, ToNo=-1; + + if( checkErrorStatus( charaindex) ) { + BattleCommandDispach( fd, "N"); + return; + } + + EscapeFree = 0; + + if( sscanf( command+2, "%X|%X", &iNum, &ToNo ) < 1 ){ + iNum = -1; ToNo = -1; + } + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ +// print("\n\n Ƿ(19001)(%s)(%s)\n\n", CHAR_getChar(charaindex, CHAR_CDKEY), CHAR_getChar(charaindex, CHAR_NAME) ); +#ifdef _PROSKILL_ERR_KICK + CONNECT_setCloseRequest( fd , 1 ); +#endif + return; + } +#ifndef _PROSKILL_OPTIMUM // Robin fix cancel ˴Թְҵ, PROFESSION_SKILL_Use м + // ְҵ + char_pskill = CHAR_getInt( charaindex, PROFESSION_CLASS ); + // ְܵҵ + skillindex = PROFESSION_SKILL_GetArray( charaindex, iNum); + Pskillid = PROFESSION_SKILL_getskillArray( skillindex); + profession_skill = PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS); + + if( (char_pskill > 0) && (char_pskill == profession_skill) ){ +#else + if( 1 ) { +#endif + if( PROFESSION_SKILL_Use( charaindex, iNum, ToNo, NULL ) == 1 ){ + //sprintf( szBuffer, "Command(%s)(ְҵ)", CHAR_getUseName( charaindex ) ); + endFlg = 1; + }else{ +// print("\nְҵʧ!!\n"); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); +#ifdef _PROSKILL_ERR_KICK + CONNECT_setCloseRequest( fd , 1 ); +#endif + } + }else{ +// print("\nķ??ְҵIDȷ:%s:%d:%d \n", CHAR_getChar( charaindex, CHAR_CDKEY), char_pskill, profession_skill); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_WAIT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //sprintf( szBuffer, "Command(%s)()", CHAR_getUseName( charaindex ) ); +#ifdef _PROSKILL_ERR_KICK + CONNECT_setCloseRequest_debug( fd , 1 ); +#endif + } + + EscapeFree = 0; + }else +#endif + + { + //sprintf( szBuffer, "Command(%s)(ʧ)", CHAR_getUseName( charaindex ) ); + endFlg = 2; + } + + + if( endFlg ){ + BATTLE_ActSettingSend( battleindex ); +/* + if( endFlg==1 ){ + int fd; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPLAYER ){ + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + CONNECT_SetBattleRecvTime( fd, &NowTime); + } + } +*/ + } + + { + //if( BATTLE_CHECKINDEX( battleindex ) == TRUE ){ + // BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORWHITE ) ; + //} + } + + if( BattleArray[battleindex].turn == 0 ){ + BattleArray[battleindex].flg |= EscapeFree; + }else{ + BattleArray[battleindex].flg &= EscapeFree; + } +} + + +void BATTLE_ActSettingSend( int battleindex ) +{ + int pindex, k = 0, i, j, charaindex; + int endBit = 0; + char szBA[256]; + BATTLE_ENTRY *pEntry; + BATTLE *pBattle; + + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( pindex ) ){ + // Ѩ ƥ廯 + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_C_OK + ){ + endBit |= 1 << k; // + }else + // ķ姸 + if( CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY +#ifdef _PLAYER_NPC + || CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC +#endif + ) + { + endBit |= 1 << k; // + } + } + k ++; + } + } + sprintf( szBA, "BA|%X|%X|", endBit, BattleArray[battleindex].turn ); +// print( "%s\n", szBA ); + //ձ幻ƻ˪ + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + // ׻ƽҷ±巴˪ئ + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_RESCUE )continue; + // + if( CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ){ // Ѩ˪ + BATTLE_CommandSend( pindex, szBA ); + } + } + } + + + // ƻб˪ + pBattle = BattleArray[battleindex].pNext; + for( ; pBattle ; pBattle = pBattle->pNext ){ + + // ʧо + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:սbattle address(%p)\n", pBattle ); + break; + } + // 幻˪ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pBattle->Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + // Ѩ˪ + BATTLE_CommandSend( pindex, szBA ); + } + } +} + + + +BOOL BATTLE_IsHide( int charaindex ){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 + ){ + return TRUE; + } + return FALSE; +} + + + + + +//******************************************************* +// +// PѨëͷʧ˪ +// +BOOL _BATTLE_CommandSend( int charaindex, char *pszCommand,char *file,int line) +// +//******************************************************** +{ +// printf("=%s\n",pszCommand); + +// printf("·%s =%d\n",file,line); + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + if( getfdFromCharaIndex( charaindex ) < 0 )return FALSE; + lssproto_B_send( getfdFromCharaIndex( charaindex ), pszCommand ); + return TRUE; +} + + +BOOL BATTLE_MakeCharaString( + int battleindex, + char *pszCommand, + int size +) +{ + int i, j, iOffset, charaindex, flg; + BATTLE_ENTRY *pEntry; + char szBuffer[4096]="", *pszTop, *pszLast; + char szEscapeName[128], szEscapeTitle[128]; + char szEscapePetName[128]; + int rideflg = 0, petindex = -1, petlevel, pethp, petmaxhp; + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return FALSE; + pszTop = pszCommand; + pszLast = pszCommand+size-1; +#if 1 + sprintf( szBuffer, "BC|%X|", BattleArray[battleindex].field_att ); +#else + sprintf( szBuffer, "BC|" ); +#endif + STRCPY_TAIL( pszTop, pszLast, szBuffer ); + + for( j = 0; j < 2; j ++ ){ + if( j == 1 ){ + iOffset = SIDE_OFFSET; // 𵤴µ + }else{ + iOffset = 0; + } + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ) + & CHAR_BATTLEFLG_ULTIMATE )continue; + flg = 0; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_INIT ) flg |= BC_FLG_NEW; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_RESCUE ) flg |= BC_FLG_NEW; + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE ){ + flg |= BC_FLG_DEAD; + }else + if( CHAR_getWorkInt( charaindex, CHAR_WORKPOISON ) > 0 ){ + flg |= BC_FLG_POISON; + }else +#ifdef _MAGIC_WEAKEN // + if( CHAR_getWorkInt( charaindex, CHAR_WORKWEAKEN ) > 0 ){ + flg |= BC_FLG_WEAKEN; + }else +#endif +#ifdef _MAGIC_DEEPPOISON // 綾 + if( CHAR_getWorkInt( charaindex, CHAR_WORKDEEPPOISON ) > 0 ){ + flg |= BC_FLG_DEEPPOISON; + }else +#endif +#ifdef _MAGIC_NOCAST // Ĭ + if( CHAR_getWorkInt( charaindex, CHAR_WORKNOCAST ) > 0 ){ + flg |= BC_FLG_NOCAST; + }else +#endif +#ifdef _MAGIC_BARRIER // ħ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBARRIER ) > 0 ){ + flg |= BC_FLG_BARRIER; + }else +#endif + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARALYSIS ) > 0 ){ + flg |= BC_FLG_PARALYSIS; + }else + if( CHAR_getWorkInt( charaindex, CHAR_WORKSLEEP ) > 0 ){ + flg |= BC_FLG_SLEEP; + }else + if( CHAR_getWorkInt( charaindex, CHAR_WORKSTONE ) > 0 ){ + flg |= BC_FLG_STONE; + }else + if( CHAR_getWorkInt( charaindex, CHAR_WORKDRUNK ) > 0 ){ + flg |= BC_FLG_DRUNK; + }else + if( CHAR_getWorkInt( charaindex, CHAR_WORKCONFUSION ) > 0 ){ + flg |= BC_FLG_CONFUSION; + } + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + flg |= BC_FLG_PLAYER; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_REVERSE ){ + flg |= BC_FLG_REVERSE; + } + if( BATTLE_IsHide( charaindex ) == TRUE ){ + flg |= BC_FLG_HIDE; + } +#ifdef _PET_SKILL_SARS // WON ADD ɷ + if( CHAR_getWorkInt( charaindex, CHAR_WORKSARS ) > 0 ){ + flg |= BC_FLG_SARS; + } +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( CHAR_getWorkInt( charaindex, CHAR_WORKDIZZY ) > 0 ){ + flg |= BC_FLG_DIZZY; // ѣ + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKENTWINE ) > 0 ){ + flg |= BC_FLG_ENTWINE; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKDRAGNET ) > 0 ){ + flg |= BC_FLG_DRAGNET; // ޵ + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKICECRACK ) > 0 ){ + // flg |= BC_FLG_ICECRACK; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKOBLIVION ) > 0 ){ + flg |= BC_FLG_OBLIVION; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKICEARROW ) > 0 ){ + flg |= BC_FLG_ICEARROW; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKBLOODWORMS ) > 0 ){ + flg |= BC_FLG_BLOODWORMS; // Ѫ + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKSIGN ) > 0 ){ + flg |= BC_FLG_SIGN; // һѪ + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKINSTIGATE ) > 0 ){ + flg |= BC_FLG_CARY; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORK_F_ENCLOSE ) > 0 ){ + flg |= BC_FLG_F_ENCLOSE; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORK_I_ENCLOSE ) > 0 ){ + flg |= BC_FLG_I_ENCLOSE; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORK_T_ENCLOSE ) > 0 ){ + flg |= BC_FLG_T_ENCLOSE; // ׸ + } +#endif +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( charaindex, CHAR_WORKANNEX ) > 0 ){ + flg |= BC_FLG_T_ENCLOSE; // + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKWATER ) > 0 ){ + flg |= BC_FLG_WATER; // ˮ + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKFEAR ) > 0 ){ + flg |= BC_FLG_FEAR; // ־ + } +#endif +#ifdef _PETSKILL_LER + if(CHAR_getWorkInt(charaindex,CHAR_WORK_RELIFE) > 0){ + flg |= BC_FLG_CHANGE; // ׶ + CHAR_setWorkInt(charaindex,CHAR_WORK_RELIFE,0); + } +#endif + makeEscapeString( CHAR_getUseName( charaindex ), + szEscapeName, + sizeof( szEscapeName ) ); + makeEscapeString( BATTLE_CharTitle( charaindex ), + szEscapeTitle, + sizeof( szEscapeTitle ) ); + // Robin 0728 ride Pet + petindex = BATTLE_getRidePet( charaindex ); + if( petindex != -1 ){ + rideflg = 1; + makeEscapeString( CHAR_getUseName( petindex ), + szEscapePetName, + sizeof( szEscapePetName ) ); + petlevel = CHAR_getInt( petindex, CHAR_LV); + pethp = CHAR_getInt( petindex, CHAR_HP); + petmaxhp = CHAR_getWorkInt( petindex, CHAR_WORKMAXHP); + + }else { + if( CHAR_getWorkInt( charaindex, CHAR_WORKPETFALL ) == 1 ){ + rideflg = -1; +#ifdef _PETSKILL_BECOMEFOX // ĻʱѶϢ Client + if( CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ) + rideflg = -2; //clientжʾ (ӦclientΪp_party[ BattleMyNo ]->onRide) +#endif +#ifdef _PETSKILL_BECOMEPIG // ʱѶϢ Client + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > 120 )// + rideflg = -3; //clientжʾ (ӦclientΪp_party[ BattleMyNo ]->onRide) +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKPETFALL, 0 ); + } + else + rideflg = 0; + szEscapePetName[0] = 0; + petlevel = 0; + pethp = 0; + petmaxhp = 0; + } + + sprintf( szBuffer, "%X|%s|%s|%X|%X|%X|%X|%X|%X|%s|%X|%X|%X|", + pEntry[i].bid, + szEscapeName, + szEscapeTitle, + CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER ), + CHAR_getInt( charaindex, CHAR_LV ), + max( CHAR_getInt( charaindex, CHAR_HP ),0), + CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP ), + flg, + rideflg, + szEscapePetName, + petlevel, + pethp, + petmaxhp + ); + STRCPY_TAIL( pszTop, pszLast, szBuffer ); + if( pszTop >= pszLast )return FALSE;// + } + } + + return TRUE; +} + +void BATTLE_BpSendToWatch( + BATTLE *pBattle, // ͼ̼ + char *pszBcString // BC ٯ +) +{ + + char szBp[256]; + int flg = 0, i, charaindex; + +// for( ; pBattle ; pBattle = pBattle->pNext ){ + if( pBattle == NULL )return; + // ʧо + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:սbattle address(%p)\n", pBattle ); + return; + } + + // 幻˪ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = pBattle->Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) + != CHAR_TYPEPLAYER ) continue; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_WATCHINIT){ + flg |= BP_FLG_JOIN; // ޥ + } + flg |= BP_FLG_PLAYER_MENU_OFF; // بئ + // į˪ + sprintf( szBp, "BP|%X|%X|%X", 20, flg, 0 ); + BATTLE_CommandSend( charaindex, szBp ); + // 幻ɧ ˪ + BATTLE_CommandSend( charaindex, pszBcString ); + } + // Ѩг + pBattle->mode = BATTLE_MODE_WATCHPRE; +// } +} + +void BATTLE_CharSendAll( int battleindex ) +{ + int i, j, charaindex, flg, pet, At_SoubiIndex, pindex; + char szBp[256]; + BATTLE *pBattle; + + BATTLE_MakeCharaString( + battleindex, + szAllBattleString, + sizeof(szAllBattleString) + ); + + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + flg = 0; + if( BattleArray[battleindex].Side[j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_ENEMY_SURPRISAL; + }else + if( BattleArray[battleindex].Side[1-j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_PLAYER_SURPRISAL; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_RESCUE){ + flg |= BP_FLG_JOIN; // + } + At_SoubiIndex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( At_SoubiIndex ) == FALSE ){ + }else{ + if( ITEM_getInt( At_SoubiIndex, ITEM_TYPE ) == ITEM_BOOMERANG ){ + flg |= BP_FLG_BOOMERANG; + } + } + + pet = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + if( pet >= 0 ){ + snprintf( szBp, sizeof( szBp ), "K%d", pet ); + CHAR_sendStatusString( charaindex, szBp ); + + pindex = CHAR_getCharPet( charaindex, pet ); + +#ifdef _PETSKILL_DAMAGETOHP + { +/* + ÿ,ÿ~~~~~~~ + qTTr + qsU + tѨTѨs± +*/ + char msg[32]={0}; + //print("\nid:%d",CHAR_getInt( pindex, CHAR_PETID)); + //print("\n:%s",CHAR_getChar( pindex, CHAR_NAME)); + //if( CHAR_getInt( pindex, CHAR_PETID) == 777 ){//ID ˮ˫ͷ + // || CHAR_getInt( pindex, CHAR_PETID) == 146 ) //˫ͷ + // && CHAR_getInt( pindex, CHAR_HP) ){ + sprintf( msg, "o%d", pet ); + CHAR_sendStatusString( charaindex, msg ); + + //} + } +#endif + +#ifdef _PETSKILL_BECOMEFOX // Ļijļ + //if( CHAR_getInt( pindex, CHAR_BASEIMAGENUMBER) == 101749 ){ + if( CHAR_getWorkInt( pindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС + char msg[32]={0}; + sprintf( msg, "a%d", pet ); + CHAR_sendStatusString( charaindex, msg ); + + } +#endif + + if( CHAR_CHECKINDEX( pindex ) == TRUE ){ + if( BATTLE_IsCharge( pindex ) == TRUE){ + flg |= BP_FLG_PET_MENU_OFF; + } + if( BATTLE_CanMoveCheck( pindex ) == FALSE ){ + flg |= BP_FLG_PET_MENU_OFF; + } + + if( CHAR_getFlg( pindex, CHAR_ISDIE ) == TRUE ){ + flg |= BP_FLG_PET_MENU_OFF; + } + } + }else{ + flg |= BP_FLG_PET_MENU_OFF; + } + + if( BATTLE_CanMoveCheck( charaindex ) == FALSE + || CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE + ){ + flg |= BP_FLG_PLAYER_MENU_OFF; + } + + if( BattleArray[battleindex].Side[j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_PLAYER_MENU_OFF; + flg |= BP_FLG_PET_MENU_OFF; + } + sprintf( szBp, "BP|%X|%X|%X", + i + SIDE_OFFSET * j, + flg, CHAR_getInt( charaindex, CHAR_MP ) + ); + BATTLE_CommandSend( charaindex, szBp ); + BATTLE_CommandSend( charaindex, szAllBattleString ); + } + } + pBattle = BattleArray[battleindex].pNext; + for( ; pBattle ; pBattle = pBattle->pNext ){ + // ʧо + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:սbattle address(%p)\n", pBattle ); + break; + } + + BATTLE_BpSendToWatch( pBattle, szAllBattleString ); + + } + + + +} + +void BattleEncountOut( int charaindex) +{ + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_FINAL){ + return; + } + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEINDEX, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_MODE_NONE ); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX ) ); + CHAR_sendArroundCharaData( charaindex ); + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEWATCH ) == 0 ){ + CHAR_sendBattleEffect( charaindex, OFF); + }else{ + CHAR_sendBattleWatch( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX ), OFF); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEWATCH, 0 ); + } + + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + int pmode/*, battleindex*/; + int pindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1 ); + pmode = CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ); + if( pmode > 0 && pmode != BATTLE_CHARMODE_FINAL ){ + BATTLE_RescueParentTry( charaindex, pindex ); +// print( "μս(%s)\n", CHAR_getUseName( charaindex ) ); + } + } + +} + + +//************************************************** +// +// ɻѨë ľʸ +// +BOOL BATTLE_PetDefaultCommand( int petindex ) +// +//************************************************** +{ + if( CHAR_CHECKINDEX( petindex ) == FALSE )return FALSE; + // 켰϶ + CHAR_setWorkInt( petindex, CHAR_WORKBATTLECOM2, -1 ); + // ɧ ϶ + CHAR_setWorkInt( petindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + // ѨOK϶ + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; +} + +// Robin fix ʯ˯ս +int checkErrorStatus( int charaindex) +{ + //if( BATTLE_CanMoveCheck( charaindex) == FALSE) { + + if( + CHAR_getWorkInt( charaindex, CHAR_WORKPARALYSIS ) > 0 // + || CHAR_getWorkInt( charaindex, CHAR_WORKSTONE ) > 0 // ʯ + || CHAR_getWorkInt( charaindex, CHAR_WORKSLEEP ) > 0 // ˯ + //|| CHAR_getWorkInt( charaindex, CHAR_WORKBARRIER ) > 0 // ħ +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + || CHAR_getWorkInt( charaindex, CHAR_WORKDIZZY ) > 0 // ѣ + || CHAR_getWorkInt( charaindex, CHAR_WORKDRAGNET ) > 0 // ޵ + //|| CHAR_getWorkInt( charaindex, CHAR_WORK_T_ENCLOSE ) > 0 // ׸ +#ifdef _PROFESSION_ADDSKILL +// || CHAR_getWorkInt( charaindex, CHAR_DOOMTIME ) > 0 //ĩռ +#endif +#endif + ) + { + + char cdkey[128]; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) + strcpy( cdkey, CHAR_getChar( charaindex, CHAR_CDKEY)); + else + strcpy( cdkey, CHAR_getChar( charaindex, CHAR_OWNERCDKEY) ); + +// print("\n ķ!ս״̬!!:%s ", cdkey ); + + return 1; + } + return 0; +} +void BATTLE_CharSendOne( int battleindex,int mycharaindex ) +{ + int i, j, charaindex, flg, pet, At_SoubiIndex, pindex; + char szBp[256]; + BATTLE *pBattle; + + BATTLE_MakeCharaString( + battleindex, + szAllBattleString, + sizeof(szAllBattleString) + ); + print("\nCharSendOne %d %d",battleindex, mycharaindex); + for( j = 0; j < 2; j ++ ){ + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + charaindex = BattleArray[battleindex].Side[j].Entry[i].charaindex; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )continue; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + if( charaindex != mycharaindex )continue; + flg = 0; + if( BattleArray[battleindex].Side[j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_ENEMY_SURPRISAL; + }else + if( BattleArray[battleindex].Side[1-j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_PLAYER_SURPRISAL; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) + == BATTLE_CHARMODE_RESCUE){ + flg |= BP_FLG_JOIN; // + } + At_SoubiIndex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( At_SoubiIndex ) == FALSE ){ + }else{ + if( ITEM_getInt( At_SoubiIndex, ITEM_TYPE ) == ITEM_BOOMERANG ){ + flg |= BP_FLG_BOOMERANG; + } + } + + pet = CHAR_getInt( charaindex, CHAR_DEFAULTPET ); + if( pet >= 0 ){ + snprintf( szBp, sizeof( szBp ), "K%d", pet ); + CHAR_sendStatusString( charaindex, szBp ); + + pindex = CHAR_getCharPet( charaindex, pet ); + +#ifdef _PETSKILL_DAMAGETOHP + { +/* + ÿ,ÿ~~~~~~~ + qTTr + qsU + tѨTѨs± +*/ + char msg[32]={0}; + //print("\nid:%d",CHAR_getInt( pindex, CHAR_PETID)); + //print("\n:%s",CHAR_getChar( pindex, CHAR_NAME)); + //if( CHAR_getInt( pindex, CHAR_PETID) == 777 ){//ID ˮ˫ͷ + // || CHAR_getInt( pindex, CHAR_PETID) == 146 ) //˫ͷ + // && CHAR_getInt( pindex, CHAR_HP) ){ + sprintf( msg, "o%d", pet ); + CHAR_sendStatusString( charaindex, msg ); + + //} + } +#endif + +#ifdef _PETSKILL_BECOMEFOX // Ļijļ + //if( CHAR_getInt( pindex, CHAR_BASEIMAGENUMBER) == 101749 ){ + if( CHAR_getWorkInt( pindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС + char msg[32]={0}; + sprintf( msg, "a%d", pet ); + CHAR_sendStatusString( charaindex, msg ); + + } +#endif + + if( CHAR_CHECKINDEX( pindex ) == TRUE ){ + if( BATTLE_IsCharge( pindex ) == TRUE){ + flg |= BP_FLG_PET_MENU_OFF; + } + if( BATTLE_CanMoveCheck( pindex ) == FALSE ){ + flg |= BP_FLG_PET_MENU_OFF; + } + + if( CHAR_getFlg( pindex, CHAR_ISDIE ) == TRUE ){ + flg |= BP_FLG_PET_MENU_OFF; + } + } + }else{ + flg |= BP_FLG_PET_MENU_OFF; + } + + if( BATTLE_CanMoveCheck( charaindex ) == FALSE + || CHAR_getFlg( charaindex, CHAR_ISDIE ) == TRUE + ){ + flg |= BP_FLG_PLAYER_MENU_OFF; + } + + if( BattleArray[battleindex].Side[j].flg & BSIDE_FLG_SURPRISE ){ + flg |= BP_FLG_PLAYER_MENU_OFF; + flg |= BP_FLG_PET_MENU_OFF; + } + sprintf( szBp, "BP|%X|%X|%X", + i + SIDE_OFFSET * j, + flg, CHAR_getInt( charaindex, CHAR_MP ) + ); + BATTLE_CommandSend( charaindex, szBp ); + BATTLE_CommandSend( charaindex, szAllBattleString ); + } + } + pBattle = BattleArray[battleindex].pNext; + for( ; pBattle ; pBattle = pBattle->pNext ){ + // ʧо + if( BATTLE_CHECKADDRESS( pBattle ) == FALSE ){ + fprint( "err:սbattle address(%p)\n", pBattle ); + break; + } + + BATTLE_BpSendToWatch( pBattle, szAllBattleString ); + + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_event.c b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_event.c new file mode 100644 index 0000000..819e09b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_event.c @@ -0,0 +1,10432 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "char_event.h" +#include "battle.h" +#include "battle_event.h" +#include "configfile.h" +#include "pet.h" +#include "log.h" +#include "lssproto_serv.h" +#include "anim_tbl.h" +#include "battle_magic.h" +#include "util.h" +#include "enemy.h" +#include "pet_skill.h" +#include "char_base.h" +#include "item_event.h" +#include "autil.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#include "item.h" +#include "skill.h" +#endif +#ifdef _PETSKILL_LER +#include "magic_base.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#define DEFENSE_RATE (0.5) +#define DAMAGE_RATE (2.0) +#define CRITICAL_RATE (1.0) +#define KAWASHI_MAX_RATE (75) + +#define AJ_SAME (1.0) + +#define AJ_UP (1.5) +#define AJ_DOWN (0.6) + +#define ATTR_MAX 100 +#define D_ATTR (1.0/(ATTR_MAX*ATTR_MAX)) + +#define D_16 (1.0/16) +#define D_8 (1.0/8) + +float gKawashiPara = 0.02; +float gCounterPara = 0.08; +float gCriticalPara = 0.09; + +float gBattleDamageModyfy; +int gBattleDuckModyfy; +int gBattleStausChange; +int gBattleStausTurn; +float gDuckPer; +int gCriper; + +int gBattleBadStatusTbl[BATTLE_ENTRY_MAX*2]; + +#ifdef _OTHER_MAGICSTAUTS +#ifdef _MAGICSTAUTS_RESIST +char MagicStatus[MAXSTATUSTYPE][36] = { "NULL","ħ","","","翹",""}; +int MagicTbl[] = { -1, CHAR_DEFMAGICSTATUS, CHAR_MAGICSUPERWALL, CHAR_MAGICFIRE, CHAR_MAGICTHUNDER, CHAR_MAGICICE }; +#else +char MagicStatus[MAXSTATUSTYPE][36] = { "NULL","ħ",""}; +int MagicTbl[] = { -1, CHAR_DEFMAGICSTATUS, CHAR_MAGICSUPERWALL }; +#endif //_MAGICSTAUTS_RESIST +#endif + +char *aszStatus[] = { "ȫ", "", "", "", "ʯ", "", "", "", "", "", "Ĭ" +#ifdef _PET_SKILL_SARS // WON ADD ɷ + ,"ɷ" +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,"","","","","","","","","","","˪","","ר","","","","","","" +#endif +#ifdef _PROFESSION_ADDSKILL + ,"" +#endif +}; + +char *aszStatusFull[] = { "ȫ", "", "", "˯", "ʯ", "", "", "", "綾", "ħ", "Ĭ" +#ifdef _PET_SKILL_SARS // WON ADD ɷ + ,"ɷ" +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,"ѣ","","","","","","Ѫ","һѪ","","", + "","׸","רעս","","","׿","","","׸" +#endif +}; + +int StatusTbl[] = { -1, CHAR_WORKPOISON, CHAR_WORKPARALYSIS, + CHAR_WORKSLEEP, CHAR_WORKSTONE, + CHAR_WORKDRUNK, CHAR_WORKCONFUSION, + CHAR_WORKWEAKEN, CHAR_WORKDEEPPOISON, + CHAR_WORKBARRIER, CHAR_WORKNOCAST +#ifdef _PET_SKILL_SARS // WON ADD ɷ + ,CHAR_WORKSARS +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,CHAR_WORKDIZZY, CHAR_WORKENTWINE + ,CHAR_WORKDRAGNET, CHAR_WORKICECRACK + ,CHAR_WORKOBLIVION, CHAR_WORKICEARROW + ,CHAR_WORKBLOODWORMS, CHAR_WORKSIGN + ,CHAR_WORKINSTIGATE, CHAR_WORK_F_ENCLOSE + ,CHAR_WORK_I_ENCLOSE, CHAR_WORK_T_ENCLOSE + ,CHAR_WORK_FOCUS, CHAR_WORKRESIST_F + ,CHAR_WORKRESIST_I, CHAR_WORKRESIST_T + ,CHAR_WORK_F_ENCLOSE_2, CHAR_WORK_I_ENCLOSE_2 + ,CHAR_WORK_T_ENCLOSE_2 +#endif +#ifdef _PROFESSION_ADDSKILL + ,CHAR_WORKERSIST_F_I_T, CHAR_WORKWATER//ˮ + ,CHAR_WORKANNEX// + ,CHAR_WORKFEAR//־ + ,CHAR_WORKICECRACK2 + ,CHAR_WORKICECRACK3 + ,CHAR_WORKICECRACK4 + ,CHAR_WORKICECRACK5 + ,CHAR_WORKICECRACK6 + ,CHAR_WORKICECRACK7 + ,CHAR_WORKICECRACK8 + ,CHAR_WORKICECRACK9 + ,CHAR_WORKICECRACK10 +#endif + }; + +int RegTbl[] = { -1, CHAR_WORKMODPOISON, CHAR_WORKMODPARALYSIS, + CHAR_WORKMODSLEEP, CHAR_WORKMODSTONE, + CHAR_WORKMODDRUNK, CHAR_WORKMODCONFUSION, + CHAR_WORKMODWEAKEN, CHAR_WORKMODDEEPPOISON, + CHAR_WORKMODBARRIER, CHAR_WORKMODNOCAST +#ifdef _PET_SKILL_SARS // WON ADD ɷ + ,CHAR_WORKMODSARS +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,CHAR_WORKMODDIZZY, CHAR_WORKMODENTWINE + ,CHAR_WORKMODDRAGNET, CHAR_WORKMODICECRACK + ,CHAR_WORKMODOBLIVION, CHAR_WORKMODICEARROW + ,CHAR_WORKMODBLOODWORMS, CHAR_WORKMODSIGN + ,CHAR_WORKMODINSTIGATE, CHAR_WORKMOD_F_ENCLOSE + ,CHAR_WORKMOD_I_ENCLOSE, CHAR_WORKMOD_T_ENCLOSE + ,CHAR_WORKMOD_FOCUS, CHAR_WORKMODRESIST_F + ,CHAR_WORKMODRESIST_I, CHAR_WORKMODRESIST_T + ,CHAR_WORKMOD_F_ENCLOSE_2, CHAR_WORKMOD_I_ENCLOSE_2 + ,CHAR_WORKMOD_T_ENCLOSE_2 +#endif + }; + +char *aszMagicDef[] = { "", "", "", "" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,"" +#endif +#ifdef _PETSKILL_ACUPUNCTURE + ,"" +#endif +}; + + + +char *aszMagicDefFull[] = { "ͨ", "", "", "Ч" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,"" +#endif +#ifdef _PETSKILL_ACUPUNCTURE + ,"" +#endif +}; + + +int MagicDefTbl[] = { -1, CHAR_WORKDAMAGEABSROB, CHAR_WORKDAMAGEREFLEC, CHAR_WORKDAMAGEVANISH +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + ,CHAR_WORKTRAP +#endif +#ifdef _PETSKILL_ACUPUNCTURE + ,CHAR_WORKACUPUNCTURE +#endif +}; + +char *aszParamChange[] = { "", "", "", "", "", "" }; +char *aszParamChangeFull[] = { "", "", "", "ٶ", "", "" }; +int aParamChangeTbl[] = { -1, CHAR_WORKMODATTACK, CHAR_WORKMODDEFENCE, + CHAR_WORKMODQUICK, CHAR_WORKMODCHARM, CHAR_WORKMODCAPTURE }; + +// Robin 0727 Ride Pet +// ȡindex +int BATTLE_getRidePet( int charaindex ) +{ + int petindex = -1; + + if( !CHAR_CHECKINDEX(charaindex) ) return -1; + + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + && CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYERNPC + && CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPELUANPC +#endif + ){ + return -1; + }else + { + int rideIndex = CHAR_getInt( charaindex, CHAR_RIDEPET ); + + if( rideIndex == -1 ) + return -1; + petindex = CHAR_getCharPet( charaindex, rideIndex ); + if( !CHAR_CHECKINDEX( petindex ) ) return -1; + + } + + return petindex; + +} + +// ȡʱΧ +float BATTLE_adjustRidePet3A( int charaindex, int petindex, int workindex, int action ) +{ + float ret = CHAR_getWorkInt( charaindex, workindex ); + BOOL throwweapon = BATTLE_IsThrowWepon(CHAR_getItemIndex( charaindex, CHAR_ARM ) ); + + switch( workindex ) { + case CHAR_WORKATTACKPOWER : // + if( throwweapon ) // Ͷ + ret = CHAR_getWorkInt( charaindex, CHAR_WORKATTACKPOWER ) +#ifdef _BATTLE_NEWPOWER //andy 1/24 reEdit + + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER )*0.4; +#else + + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER )*0.2; +#endif + else // ս + ret = CHAR_getWorkInt( charaindex, CHAR_WORKATTACKPOWER )*0.8 + + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER )*0.8; + break; + case CHAR_WORKDEFENCEPOWER : // + ret = CHAR_getWorkInt( charaindex, CHAR_WORKDEFENCEPOWER )*0.7 + + CHAR_getWorkInt( petindex, CHAR_WORKDEFENCEPOWER )*0.7; + break; + case CHAR_WORKQUICK : // + if( action == ATTACKSIDE ) { + if( throwweapon ) { + ret = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )*0.8 + + CHAR_getWorkInt( petindex, CHAR_WORKQUICK )*0.2; + }else { +#ifdef _BATTLE_NEWPOWER //andy 1/24 reEdit + ret = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )*0.2 + + CHAR_getWorkInt( petindex, CHAR_WORKQUICK )*0.8; + +#else + ret = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )*0.5 + + CHAR_getWorkInt( petindex, CHAR_WORKQUICK )*0.5; +#endif + } + }else + if( action == DEFFENCESIDE ){ + ret = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )*0.1 + + CHAR_getWorkInt( petindex, CHAR_WORKQUICK )*0.9; + } + break; + default : + ret = CHAR_getWorkInt( charaindex, workindex ); + } + + //print(" adj3A_Now:%d:%d=%f ", charaindex, workindex, ret); + + return ret; +} + +// Robin 0727 ride Pet ͼ +void BATTLE_changeRideImage( int index ) +{ + + int itemindex = CHAR_getItemIndex(index,CHAR_ARM); + int category; + int newimagenumber; + int basebaseimagenumber + = CHAR_getInt(index,CHAR_BASEBASEIMAGENUMBER); + if( !ITEM_CHECKINDEX(itemindex) ) { + category = ITEM_FIST; + }else { + category = ITEM_getInt(itemindex,ITEM_TYPE ); + } + newimagenumber = CHAR_getNewImagenumberFromEquip( + index,basebaseimagenumber, category); + if( newimagenumber == -1) { + CHAR_setInt( index, CHAR_BASEIMAGENUMBER, basebaseimagenumber); + }else { + CHAR_setInt( index, CHAR_BASEIMAGENUMBER, newimagenumber); + } +} + +void BATTLE_talkToCli( + int charaindex, + char *pszBuffer, + int color +) +{ + if( getBattleDebugMsg( ) != 0 + && CHAR_getFlg( charaindex, CHAR_ISSHOWBATTLEMSG ) + ){ + CHAR_talkToCli( charaindex, -1, pszBuffer, color ); + } +} + + +int BATTLE_BroadCastBase( + int battleindex, + char *pszBuffer, + int color, + int flg +) +{ + int i, j, pindex; + BATTLE_ENTRY *pEntry; + + if( flg != 1 && getBattleDebugMsg( ) == 0 )return 0; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return BATTLE_ERR_BATTLEINDEX; + + for( j = 0; j < 2; j ++ ){ + pEntry = BattleArray[battleindex].Side[j].Entry; + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + pindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getInt( pindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + if( CHAR_getFlg( pindex, CHAR_ISSHOWBATTLEMSG ) == FALSE ) continue; + CHAR_talkToCli( pindex, -1, pszBuffer, color ); + } + } + + return 0; +} + +// Nuke 20040112 fix for performance +/*int BATTLE_BroadCast( + int battleindex, + char *pszBuffer, + int color +) +{ + return BATTLE_BroadCastBase( battleindex, pszBuffer, color, 0 ); + +} + +int BATTLE_BroadCastOn( + int battleindex, + char *pszBuffer, + int color +) +{ + return BATTLE_BroadCastBase( battleindex, pszBuffer, color, 1 ); +} +*/ + +#ifdef _TAKE_ITEMDAMAGE +int BATTLE_ItemCrushCheck( int charaindex , int flg) +{//flg def 1 att 2 + int EquipTbl[CHAR_EQUIPPLACENUM], itemindex; + int i, rndwork; + int Crushs=0; + //char szBuffer[256]; + + memset( EquipTbl, -1, sizeof( EquipTbl)); + if( flg == 2 ) { + itemindex = CHAR_getItemIndex( charaindex, CHAR_ARM); + if( ITEM_CHECKINDEX( itemindex) == TRUE ) { + return CHAR_ARM; + } + return -1; + }else { + int equipnum; +#ifdef _TAKE_ITEMDAMAGE_FOR_PET + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET){ + equipnum = CHAR_PETITEMNUM; + }else +#endif + equipnum = CHAR_EQUIPPLACENUM; +#ifdef _TAKE_ITEMDAMAGE_FIX + rndwork = rand() % equipnum; +#else + Crushs = rand()%100; + if( Crushs < 50 ) { + rndwork = CHAR_BODY; + }else if( Crushs >= 50 && Crushs < 67 ) { + rndwork = CHAR_HEAD; + }else if( Crushs >= 67 && Crushs < 84 ) { + rndwork = CHAR_DECORATION1; + }else { + rndwork = CHAR_DECORATION2; + } +#endif + for( i = 0; i < equipnum; i ++ ){//CHAR_ARM + itemindex = CHAR_getItemIndex( charaindex, rndwork); + if( ITEM_CHECKINDEX( itemindex) == TRUE && rndwork != CHAR_ARM ){ + return rndwork; + }else { + rndwork++; + rndwork=rndwork%5; + } + } + } + + return -1; +} +#else +int BATTLE_ItemCrushCheck( int charaindex ) +{ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return FALSE; + } + if( RAND( 1, gItemCrushRate ) < CHAR_getInt( charaindex, CHAR_LV ) ){ + return TRUE; + }else{ + return FALSE; + } +} +#endif + +#define BREAK_NAME_WEPON "" +#define BREAK_NAME_AROMER "" +#define BREAK_BRACELET "" +#define BREAK_MUSIC "" +#define BREAK_NECKLACE "ͷ" +#define BREAK_RING "ָ" +#define BREAK_BELT "Ƥ" +#define BREAK_EARRING "" +#define BREAK_NOSERING "ǻ" +#define BREAK_AMULET "" +#define BREAK_OTHER "" + +#ifdef _TAKE_ITEMDAMAGE +static char *aszCrushTbl[] = { "", "", "ٻ" , "ʹ" , "Ƭ" }; +#else +static char *aszCrushTbl[] = { "", "ٻ" }; +#endif + + +#ifdef _TAKE_ITEMDAMAGE +int BATTLE_ItemCrush( int charaindex, int ItemEquip, int Damages, int flg) +{ + int itemindex, breadnums; + int crushlevel, crushenum, maxcrushenum; + char szBuffer[256]=""; + int battleindex, bid; + + itemindex = CHAR_getItemIndex( charaindex, ItemEquip ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE ) + return -1; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + bid = BATTLE_Index2No( battleindex, charaindex ); + + crushlevel = ITEM_getInt( itemindex, ITEM_CRUSHLEVEL); + if( crushlevel < 0 ) crushlevel=0; + + crushenum = ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE); + maxcrushenum = ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE); + if( maxcrushenum < 1 ) return -1; + if( ItemEquip == CHAR_ARM ) { + if( (breadnums = ((Damages-50)/40)) <= 0 ) + breadnums = 1; + }else { + if( Damages >= 200 ) breadnums = 1; + if( (breadnums = ((200 - Damages)/20)) < 0 ) + breadnums = 1; + } + crushenum = crushenum - RAND( breadnums, (breadnums*1.4) ); + ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, crushenum); + + if( crushenum <= 0 ){ //ʧ + crushenum = 0; + sprintf(szBuffer, "%s𻵶ʧ\n", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORYELLOW); + + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "𻵶ʧ", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_DelItem( charaindex, ItemEquip); + crushlevel = 4; + }else { //𻵿ֵ + int defs, level=0; + + + defs = (crushenum*100)/maxcrushenum; + + if( defs >= 70 ){ + level = 0; + }else if( defs >= 50 && defs < 70 ) { + level = 1; + }else if( defs >= 30 && defs < 50 ) { + level = 2; + }else if( defs < 30 ) { + level = 3; + } + + if( level != crushlevel && defs < 70 ) { + ITEM_setInt( itemindex, ITEM_CRUSHLEVEL, level); +// for( i = 0; i < arraysizeof( ItemBreakPos ); i ++ ){ +// work = ITEM_getInt( itemindex, ItemBreakPos[i] ); +// if( work <= 0 )continue; +// work *=0.95; +// ITEM_setInt( itemindex, ItemBreakPos[i], work ); +// } + sprintf( szBuffer, "%s%sġ", + ITEM_getChar( itemindex, ITEM_NAME ), aszCrushTbl[level] ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORRED); + //ĵ˵ +// buf1 = ITEM_getChar( itemindex, ITEM_SECRETNAME); +// if( strstr( buf1, "(") != 0 ) { +// char buf5[256]; +// if( getStringFromIndexWithDelim( buf1,"(",1, buf5, sizeof( buf5)) != FALSE ) { +// sprintf( buf1, buf5); +// } +// } +// sprintf( buf2, "%s(%s)", buf1, aszCrushTbl[level]); +// ITEM_setChar( itemindex, ITEM_SECRETNAME, buf2); + } + } + + CHAR_sendItemDataOne( charaindex, ItemEquip ); + //CHAR_complianceParameter( charaindex ); + //CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_ATK | CHAR_P_STRING_DEF + // | CHAR_P_STRING_QUICK | CHAR_P_STRING_CHARM ); + + return TRUE; +} +#else +int BATTLE_ItemCrush( int charaindex ) +{ + int EquipTbl[CHAR_EQUIPPLACENUM], i, itemindex, rndwork, type; + int work, crushlevel, j, ItemEquip; + char szBuffer[256]=""; + + int ItemBreakPos[] = { + ITEM_ATTACKNUM_MIN, + ITEM_ATTACKNUM_MAX, + ITEM_MODIFYATTACK, + ITEM_MODIFYDEFENCE, + ITEM_MODIFYQUICK, + ITEM_MODIFYHP, + ITEM_MODIFYMP, + ITEM_MODIFYLUCK, + ITEM_MODIFYCHARM, + ITEM_MODIFYAVOID, + }; + + for( j = 0, i = 0; i < CHAR_EQUIPPLACENUM; i ++ ){ + itemindex = CHAR_getItemIndex( charaindex, i ); + if( ITEM_CHECKINDEX( itemindex ) == TRUE + && ITEM_getInt( itemindex, ITEM_MERGEFLG ) == 1 ){ + EquipTbl[j] = i; + j ++; + } + } + if( j == 0 )return FALSE; + rndwork = RAND( 0, j-1 ); + ItemEquip = EquipTbl[rndwork]; + itemindex = CHAR_getItemIndex( charaindex, ItemEquip ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE )return FALSE; + crushlevel = ITEM_getInt( itemindex, ITEM_CRUSHLEVEL ); + if( crushlevel > 1 ) return FALSE; + { + if( crushlevel == 1 ){ + sprintf( szBuffer, "CrushLv2(ٻLv2)" ); + }else{ + sprintf( szBuffer, "CrushLv1(ٻLv1)" ); + } + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + szBuffer, + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + + /*{ int battleindex, bid; + //sprintf( szBuffer, "(%s)(%s)(%s)\n", + // CHAR_getUseName( charaindex ), + // ITEM_getChar( itemindex, ITEM_NAME ), + // aszCrushTbl[crushlevel] ); + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + bid = BATTLE_Index2No( battleindex, charaindex ); + //BATTLE_BroadCast( battleindex, szBuffer, + (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }*/ + + type = ITEM_getInt( itemindex, ITEM_TYPE ); + szBuffer[0] = 0; + switch( type ){ + case ITEM_FIST: + case ITEM_AXE: + case ITEM_CLUB: + case ITEM_SPEAR: + case ITEM_BOW: + case ITEM_BOOMERANG: + case ITEM_BOUNDTHROW: + case ITEM_BREAKTHROW: + sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_NAME_WEPON ); + break; + + case ITEM_HELM: + case ITEM_ARMOUR: + sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_NAME_AROMER ); + break; + + case ITEM_BRACELET: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_BRACELET );break; + case ITEM_MUSIC: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_MUSIC );break; + case ITEM_NECKLACE: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_NECKLACE );break; + case ITEM_RING: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_RING );break; + case ITEM_BELT: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_BELT );break; + case ITEM_EARRING: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_EARRING );break; + case ITEM_NOSERING: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_NOSERING );break; + case ITEM_AMULET: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_AMULET );break; + case ITEM_OTHER: sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_OTHER );break; + default: + sprintf( szBuffer, "%s%s", aszCrushTbl[crushlevel], BREAK_OTHER );break; + break; + } + ITEM_setChar( itemindex, ITEM_SECRETNAME, szBuffer ); + + for( i = 0; i < arraysizeof( ItemBreakPos ); i ++ ){ + work = ITEM_getInt( itemindex, ItemBreakPos[i] ); + if( work <= 0 )continue; + if( crushlevel == 1 ){ + work = 1; + }else{ + work /= 2; + if( work < 1 ) work = 1; + } + ITEM_setInt( itemindex, ItemBreakPos[i], work ); + } + CHAR_sendItemDataOne( charaindex, ItemEquip ); + ITEM_setInt( itemindex, ITEM_CRUSHLEVEL, crushlevel + 1 ); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex, + CHAR_P_STRING_ATK + | CHAR_P_STRING_DEF + | CHAR_P_STRING_QUICK + | CHAR_P_STRING_CHARM ); + + return TRUE; +} +#endif + +#ifdef _TAKE_ITEMDAMAGE +static int BATTLE_ItemCrushSeq( int attackindex, int charaindex, int Damages) +{ + int iRet = FALSE; + int crushindex=-1, crushpower; + int flg=0;//flg def 1 att 2 + + flg=1; + if( ( crushindex = BATTLE_ItemCrushCheck( charaindex, flg) ) >= 0 ) { + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER +#ifdef _TAKE_ITEMDAMAGE_FOR_PET + || CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPET +#endif + ){ + crushpower = CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER); + BATTLE_ItemCrush( charaindex, crushindex, Damages, flg); + } + } + flg=2; + if( ( crushindex = BATTLE_ItemCrushCheck( attackindex, flg) ) >= 0 ) { + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER +#ifdef _TAKE_ITEMDAMAGE_FOR_PET + || CHAR_getInt( attackindex, CHAR_WHICHTYPE) == CHAR_TYPEPET +#endif + ){ + crushpower = CHAR_getWorkInt( charaindex, CHAR_WORKDEFENCEPOWER); + BATTLE_ItemCrush( attackindex, crushindex, Damages, flg); + } + } + + return iRet; +} + +#else + +static int BATTLE_ItemCrushSeq( int charaindex ) +{ + char szWork[256]; + int iRet = FALSE; + + if( BATTLE_ItemCrushCheck( charaindex ) == TRUE ){ + if( BATTLE_ItemCrush( charaindex ) == TRUE ){ + sprintf( szWork, "BK|%s\tװܵˡ|", + CHAR_getUseName( charaindex ) ); + strcat( szBadStatusString, szWork ); + iRet = TRUE; + } + } + return iRet; +} +#endif + +#ifdef _EQUIT_ARRANGE +static BOOL BATTLE_ArrangeCheck( int attackindex, int defindex) +{ + int DEF_ARR; + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD ){ + return FALSE; + } + if( BATTLE_GetDamageReact( defindex ) > 0 ){ + return FALSE; + } + if( BATTLE_CanMoveCheck( defindex ) == FALSE ){ + return FALSE; + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_NODUCK ){ + return FALSE; + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + return FALSE; + } + if( (DEF_ARR = CHAR_getWorkInt( defindex, CHAR_WORKARRANGEPOWER )) > 0 ){ + int per = (DEF_ARR > 700)?700:DEF_ARR; + if( RAND( 1, 1000 ) <= per ){ + return TRUE; + } + } + + return FALSE; +} +#endif + +//رж +static BOOL BATTLE_DuckCheck( + int attackindex, + int defindex +) +{ + int flg = FALSE; + + int Df_Dex, At_Dex, Df_Luck = 0; + float per, Work, wari, Big, Small; + + gDuckPer = 0; + + if(CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_S_CHARGE_OK ){ + return FALSE; + } + + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD ){ + return FALSE; + } + if( BATTLE_GetDamageReact( defindex ) > 0 ){ + return FALSE; + } + if( BATTLE_CanMoveCheck( defindex ) == FALSE ){ +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( defindex, CHAR_DOOMTIME ) <= 0 )//ʱ(ûд޵Ͷܻ״̬) + return FALSE; + else{ + if( CHAR_getWorkInt( defindex, CHAR_WORKDRAGNET ) == 0 + && CHAR_getWorkInt( defindex, CHAR_WORKDIZZY ) == 0 ){ + } + else{ + return FALSE; + } + } +#else + return FALSE; +#endif + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_NODUCK ){ + return FALSE; + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + return FALSE; + } + +#ifdef _PETSKILL_SETDUCK + if( BATTLE_CheckMySkillDuck( defindex ) == TRUE ){ + return TRUE; + } +#endif + + At_Dex = CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX ); + Df_Dex = CHAR_getWorkInt( defindex, CHAR_WORKFIXDEX ); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + Df_Luck = CHAR_getWorkInt( defindex, CHAR_WORKFIXLUCK ); + } + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + At_Dex *= 0.8; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) != CHAR_TYPEENEMY + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + ){ + Df_Dex *= 0.8; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + At_Dex *= 0.6; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + Df_Dex *= 0.6; + } + + if( Df_Dex >= At_Dex ){ + Big = Df_Dex; + Small = At_Dex; + wari = 1.0; + }else{ + Big = At_Dex; + Small = Df_Dex; + if( Big <= 0 ){ + wari = 0.0; + }else{ + wari = Small / Big; + } + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_JYUJYUTU ){ + gKawashiPara = 0.027; + }else{ + gKawashiPara = 0.02; + } + Work = ( Big - Small ) / gKawashiPara; + if( Work <= 0 ) Work = 0; + per = (float)( sqrt( (double)Work ) ); + per *= wari; + per += Df_Luck; + + per += gBattleDuckModyfy; + if( CHAR_getWorkInt( attackindex, CHAR_WORKDRUNK ) > 0 ){ + per += RAND( 20, 30 ); + } + if( gWeponType == ITEM_BOW ){ + per += 20; + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_NOGUARD ){ + per += CHAR_GETWORKINT_HIGH( defindex, CHAR_WORKBATTLECOM3 ); + } + + +#ifdef _PETSKILL_NEW_PASSIVE + per -= CHAR_getWorkInt( attackindex, CHAR_WORKPASSIVE_ACURATE ); + per += CHAR_getWorkInt( defindex, CHAR_WORKPASSIVE_DUCK ); +#endif + per *= 100; + if( per > KAWASHI_MAX_RATE*100 ) per = KAWASHI_MAX_RATE*100; + if( per <= 0 ) per = 1; + + gDuckPer = per * 0.01; +#ifdef _EQUIT_HITRIGHT + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int AddHit = CHAR_getWorkInt( attackindex, CHAR_WORKHITRIGHT); + per -= RAND( AddHit*0.8, AddHit*1.2); + per = ( per < 0 )?0:per; + } +#endif + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + per = BATTLE_check_profession_duck( defindex, per ); +#endif + +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_CHAOS ){ //ҹʱн + per += (per*0.4); + } +#endif + + if( RAND( 1, 10000 ) <= per ){ + flg = TRUE; +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + // رܼ + if( (CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) ){ + PROFESSION_SKILL_LVEVEL_UP( defindex, "PROFESSION_AVOID" ); + } +#endif + }else{ + flg = FALSE; + } + return flg; +} + +static int BATTLE_AttrCalc( + int My_Fire, + int My_Water, + int My_Earth, + int My_Wind, + int My_None, + int Vs_Fire, + int Vs_Water, + int Vs_Earth, + int Vs_Wind, + int Vs_None +) +{ + int iRet = 0; + My_Fire = My_Fire * Vs_None * AJ_UP + + My_Fire * Vs_Fire * AJ_SAME + + My_Fire * Vs_Water * AJ_DOWN + + My_Fire * Vs_Earth * AJ_SAME + + My_Fire * Vs_Wind * AJ_UP; + My_Water = My_Water * Vs_None * AJ_UP + + My_Water * Vs_Fire * AJ_UP + + My_Water * Vs_Water * AJ_SAME + + My_Water * Vs_Earth * AJ_DOWN + + My_Water * Vs_Wind * AJ_SAME; + + My_Earth = My_Earth * Vs_None * AJ_UP + + My_Earth * Vs_Fire * AJ_SAME + + My_Earth * Vs_Water * AJ_UP + + My_Earth * Vs_Earth * AJ_SAME + + My_Earth * Vs_Wind * AJ_DOWN; + + My_Wind = My_Wind * Vs_None * AJ_UP + + My_Wind * Vs_Fire * AJ_DOWN + + My_Wind * Vs_Water * AJ_SAME + + My_Wind * Vs_Earth * AJ_UP + + My_Wind * Vs_Wind * AJ_SAME; + + My_None = My_None * Vs_None * AJ_SAME + + My_None * Vs_Fire * AJ_DOWN + + My_None * Vs_Water * AJ_DOWN + + My_None * Vs_Earth * AJ_DOWN + + My_None * Vs_Wind * AJ_DOWN; + + iRet = (My_Fire + My_Water + My_Earth + My_Wind + My_None) ; + return (iRet * D_ATTR); +} + +static void BATTLE_GetAttr( int charaindex, int *T_pow ) +{ +#ifdef _BATTLE_NEWPOWER +#else + int petindex = BATTLE_getRidePet( charaindex ); + if( petindex == -1 ){ +#endif + T_pow[0] = CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT ); + T_pow[1] = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT ); + T_pow[2] = CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT ); + T_pow[3] = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT ); +/* + *pAt_Fire = CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT ); + *pAt_Water = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT ); + *pAt_Earth = CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT ); + *pAt_Wind = CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT ); +*/ +#ifdef _BATTLE_NEWPOWER +#else + }else { // Robin 0727 when Ride Pet +#endif +#ifdef _BATTLE_NEWPOWER +#else + T_pow[0] = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXEARTHAT )) /2; + T_pow[1] = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXWATERAT )) /2; + T_pow[2] = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXFIREAT )) /2; + T_pow[3] = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXWINDAT )) /2; +/* + *pAt_Fire = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXFIREAT )) /2; + *pAt_Water = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXWATERAT )) /2; + *pAt_Earth = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXEARTHAT )) /2; + *pAt_Wind = ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT ) + + CHAR_getWorkInt( petindex, CHAR_WORKFIXWINDAT )) /2; +*/ + } +#endif +#ifdef _PROFESSION_ADDSKILL + //Ͻ + //T_pow[0] += T_pow[0]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXEARTHAT_BOUNDARY )>>16&0x0000ffff) /100 ); + //T_pow[1] += T_pow[1]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY )>>16&0x0000ffff) /100 ); + //T_pow[2] += T_pow[2]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY )>>16&0x0000ffff) /100 ); + //T_pow[3] += T_pow[3]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY )>>16&0x0000ffff) /100 ); +#endif +#ifdef _SUIT_TWFWENDUM + T_pow[0] = (T_pow[0]+CHAR_getWorkInt( charaindex, CHAR_WORK_EA ))>100?100:(T_pow[0]+CHAR_getWorkInt( charaindex, CHAR_WORK_EA )); + T_pow[1] = (T_pow[1]+CHAR_getWorkInt( charaindex, CHAR_WORK_WR ))>100?100:(T_pow[1]+CHAR_getWorkInt( charaindex, CHAR_WORK_WR )); + T_pow[2] = (T_pow[2]+CHAR_getWorkInt( charaindex, CHAR_WORK_FI ))>100?100:(T_pow[2]+CHAR_getWorkInt( charaindex, CHAR_WORK_FI )); + T_pow[3] = (T_pow[3]+CHAR_getWorkInt( charaindex, CHAR_WORK_WI ))>100?100:(T_pow[3]+CHAR_getWorkInt( charaindex, CHAR_WORK_WI )); +#endif + { + int i, renum=ATTR_MAX; + for( i=0; i<4; i++) { + if( T_pow[ i] < 0 ) T_pow[ i] = 0; + renum -= T_pow[ i]; + } + if( renum < 0 ) renum = 0; + T_pow[ 4] = renum; + } +/* + if( *pAt_Fire < 0 ) *pAt_Fire = 0; + if( *pAt_Water < 0 ) *pAt_Water = 0; + if( *pAt_Earth < 0 ) *pAt_Earth = 0; + if( *pAt_Wind < 0 ) *pAt_Wind = 0; + *pAt_None = ATTR_MAX - *pAt_Fire - *pAt_Water - *pAt_Earth - *pAt_Wind; + if( *pAt_None < 0 )*pAt_None = 0; +*/ +} + + +float BATTLE_FieldAttAdjust( + int battleindex, + int pAt_Fire, + int pAt_Water, + int pAt_Earth, + int pAt_Wind +) +{ +#define AJ_BOTTOM (0.5) +#define AJ_PLUS (0.5) + int att; + float power, a_pow; + att = BattleArray[battleindex].field_att; + a_pow = (float)(BattleArray[battleindex].att_pow); + + switch( att ){ + case BATTLE_ATTR_EARTH: + power = AJ_BOTTOM + (pAt_Earth) * a_pow * 0.01 * 0.01 * AJ_PLUS; + break; + case BATTLE_ATTR_WATER: + power = AJ_BOTTOM + (pAt_Water) * a_pow * 0.01 * 0.01 * AJ_PLUS ; + break; + case BATTLE_ATTR_FIRE: + power = AJ_BOTTOM + (pAt_Fire) * a_pow * 0.01 * 0.01 * AJ_PLUS ; + break; + case BATTLE_ATTR_WIND: + power = AJ_BOTTOM + (pAt_Wind) * a_pow * 0.01 * 0.01 * AJ_PLUS ; + break; + default: + power = AJ_BOTTOM; + break; + } + return power; +} + +static int BATTLE_AttrAdjust( + int attackindex, + int defindex, + int damage +) +{ + int At_pow[5]={0,0,0,0,0}; //ˮ + int Dt_pow[5]={0,0,0,0,0}; + int i; + float At_FieldPow, Df_FieldPow; +#ifdef _BATTLE_PROPERTY + int (*loopfunc)(int,int,int*,int*,int)=NULL; +#endif + + BATTLE_GetAttr( attackindex, At_pow); + BATTLE_GetAttr( defindex, Dt_pow); + +#ifdef _PSKILL_MDFYATTACK + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_S_MDFYATTACK ) { + int MKind=-1, MODS=0; + MKind = CHAR_GETWORKINT_LOW( attackindex, CHAR_WORKBATTLECOM4); + MODS = CHAR_GETWORKINT_HIGH( attackindex, CHAR_WORKBATTLECOM4); + + for( i=0; i<5; i++) { + At_pow[ i] = 0; + } + + if( MKind >= 0 && MKind <= 4 ){ + At_pow[ MKind] = MODS; + At_pow[ 4] = 0; + } + } +#endif + +#ifdef _BATTLE_PROPERTY + loopfunc =(int(*)(int,int,int*,int*,int))CHAR_getFunctionPointer( attackindex, CHAR_BATTLEPROPERTY); + if( loopfunc ){ + loopfunc( attackindex, defindex, &damage, At_pow, 5); + } +#endif +#ifdef _BATTLE_PROPERTY + loopfunc = NULL; + loopfunc =(int(*)(int,int,int*,int*,int))CHAR_getFunctionPointer( defindex, CHAR_BATTLEPROPERTY); + if( loopfunc ){ + loopfunc( defindex, attackindex, &damage, Dt_pow, 5); + } +#endif + + At_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ), At_pow[ 2], At_pow[ 1], At_pow[ 0], At_pow[ 3] ); + Df_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ), Dt_pow[ 2], Dt_pow[ 1], Dt_pow[ 0], Dt_pow[ 3] ); + + for( i=0; i<5; i++) { + At_pow[ i] *= damage; + } +/* + At_Fire *= damage; At_Water *= damage; At_pow[0] *= damage; + At_Wind *= damage; At_none *= damage; +*/ + damage = BATTLE_AttrCalc(//2ˮ103 + At_pow[ 2], At_pow[ 1], At_pow[ 0], At_pow[ 3], At_pow[ 4], + Dt_pow[ 2], Dt_pow[ 1], Dt_pow[ 0], Dt_pow[ 3], Dt_pow[ 4] ); + damage *= (At_FieldPow / Df_FieldPow); + + return damage; +} + +int BATTLE_GuardAdjust( int damage ) +{ + int Rand = RAND( 1, 100 ); + if( Rand <= 25 ){ + damage *= 0.00; + }else{ + if( Rand <= 50 ){ + damage *= 0.10; + }else{ + if( Rand <= 70 ){ + damage *= 0.20; + }else{ + if( Rand <= 85 ){ + damage *= 0.30; + }else{ + if( Rand <= 95 ){ + damage *= 0.40; + }else{ + damage *= 0.50; + } + } + } + } + } + return damage; +} + +//˺ֵ +int BATTLE_DamageCalc( int attackindex, int defindex ) +{ + float attack, defense; + int damage = 0; + int attackpet = BATTLE_getRidePet( attackindex ); + int defpet = BATTLE_getRidePet( defindex ); + + // Robin 0727 Ride Pet + if( attackpet == -1 ) { + attack = CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ); + }else { + attack = BATTLE_adjustRidePet3A( attackindex, attackpet, CHAR_WORKATTACKPOWER, ATTACKSIDE ); + } + if( defpet == -1 ) { +#ifdef _BATTLE_NEWPOWER + defense = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ) * 0.70; +#else + defense = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ) * 0.45; + defense += CHAR_getWorkInt( defindex, CHAR_WORKQUICK ) * 0.2; + defense += CHAR_getWorkInt( defindex, CHAR_WORKFIXVITAL ) * 0.1; +#endif + }else { +#ifdef _BATTLE_NEWPOWER + defense = BATTLE_adjustRidePet3A( defindex, defpet, CHAR_WORKDEFENCEPOWER, DEFFENCESIDE ) * 0.70; +#else + defense = BATTLE_adjustRidePet3A( defindex, defpet, CHAR_WORKDEFENCEPOWER, DEFFENCESIDE ) * 0.45; + defense += BATTLE_adjustRidePet3A( defindex, defpet, CHAR_WORKQUICK, DEFFENCESIDE ) * 0.20; + defense += CHAR_getWorkInt( defindex, CHAR_WORKFIXVITAL ) * 0.05; +#endif + } + +#ifdef _MAGIC_SUPERWALL //ڷ + if( CHAR_getWorkInt( defindex, CHAR_MAGICSUPERWALL ) > 0 ){ + float def = (float)(CHAR_getWorkInt( defindex, CHAR_OTHERSTATUSNUMS )); + def = (def + rand()%20)/100; + defense += defense * def; + } +#endif +#ifdef _NPCENEMY_ADDPOWER //޸Ĺֵ + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + defense += (defense*(rand()%10)+2)/100; + } + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + attack += (attack*(rand()%10)+2)/100; + } +#endif + if( CHAR_getWorkInt( defindex, CHAR_WORKSTONE ) > 0 ) defense *= 2.0; + +#ifdef _PETSKILL_REGRET + //װ + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_REGRET + || CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_REGRET2 ) + defense = CHAR_getWorkInt(defindex,CHAR_WORKFIXTOUGH); +#endif + +#ifdef _EQUIT_NEGLECTGUARD //Ŀ% + if( CHAR_getWorkInt( attackindex, CHAR_WORKNEGLECTGUARD) > 1 ) { + float defp = (float)CHAR_getWorkInt( attackindex, CHAR_WORKNEGLECTGUARD); + defp = 1 - (defp/100); + defense = defense*defp; + } +#endif + + if( defense <= attack && attack < (defense * 8.0/7.0) ){ + damage = (int)(RAND( 0, attack * D_16 )); + }else + if( defense > attack ){ + damage = (int)(RAND( 0, 1 )); + }else + if( attack >= (defense * 8/7) ){ + float K0; + K0 = RAND( 0, attack*D_8 ) - attack*D_16; + damage = (int)(( (attack - defense )*DAMAGE_RATE ) + K0); + } + + // + damage = BATTLE_AttrAdjust( attackindex, defindex, damage ); + +#ifdef _PROFESSION_ADDSKILL + { + // + if( ((CHAR_getWorkInt( defindex, CHAR_WORKFIXEARTHAT_BOUNDARY )>>16) & 0x0000ffff) > 0 ){ + if( CHAR_getWorkInt( attackindex, CHAR_WORKFIXEARTHAT ) > 0 ) + damage -= damage*(float)((CHAR_getWorkInt( attackindex, CHAR_WORKFIXEARTHAT )/200.0)); + }else if( ((CHAR_getWorkInt( defindex, CHAR_WORKFIXWATERAT_BOUNDARY )>>16) & 0x0000ffff) > 0 ){ + if( CHAR_getWorkInt( attackindex, CHAR_WORKFIXWATERAT ) > 0 ) + damage -= damage*(float)((CHAR_getWorkInt( attackindex, CHAR_WORKFIXWATERAT )/200.0)); + }else if( ((CHAR_getWorkInt( defindex, CHAR_WORKFIXFIREAT_BOUNDARY )>>16) & 0x0000ffff) > 0 ){ + if( CHAR_getWorkInt( attackindex, CHAR_WORKFIXFIREAT ) > 0 ) + damage -= damage*(float)((CHAR_getWorkInt( attackindex, CHAR_WORKFIXFIREAT )/200.0)); + }else if( ((CHAR_getWorkInt( defindex, CHAR_WORKFIXWINDAT_BOUNDARY )>>16) & 0x0000ffff) > 0 ){ + if( CHAR_getWorkInt( attackindex, CHAR_WORKFIXWINDAT ) > 0 ) + damage -= damage*(float)((CHAR_getWorkInt( attackindex, CHAR_WORKFIXWINDAT )/200.0)); + } + //T_pow[1] += T_pow[1]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXWATERAT_BOUNDARY )>>16&0x0000ffff) /100 ); + //T_pow[2] += T_pow[2]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXFIREAT_BOUNDARY )>>16&0x0000ffff) /100 ); + //T_pow[3] += T_pow[3]*( (CHAR_getWorkInt( charaindex, CHAR_WORKFIXWINDAT_BOUNDARY )>>16&0x0000ffff) /100 ); + } +#endif + +#ifdef _ADD_DEAMGEDEFC //˺ & ӹ + { + int apower, dpower, otherpower; + apower = CHAR_getWorkInt( attackindex, CHAR_WORKOTHERDMAGE); + dpower = CHAR_getWorkInt( defindex, CHAR_WORKOTHERDEFC); + + otherpower = RAND( apower*0.3, apower) - RAND( dpower*0.3, dpower); + if( otherpower != 0 ) { + damage += otherpower; + } + } + if( damage < 0 ) + damage = 0; +#endif +#ifdef _DAMMAGE_CALC + return damage * getDamageCalc() / 100; +#else + return damage; +#endif +} + +static int BATTLE_CriticalCheckPlayer( int attackindex, int defindex ) +{ + int At_Dex, At_Luck = 0, At_Kiryoku = 0, At_Soubi = 0; + int At_SoubiIndex, Df_Dex, root = 1; + float per, Work, Big, Small, wari, divpara = gCriticalPara; + + // WON REM + //if( gWeponType == ITEM_BOW )return 0; + + At_Dex = CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX ); + Df_Dex = CHAR_getWorkInt( defindex, CHAR_WORKFIXDEX ); + + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + At_Luck = CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ); + } + At_SoubiIndex = CHAR_getItemIndex( attackindex, CHAR_ARM ); + At_Kiryoku = CHAR_getInt( attackindex, CHAR_MP ); + + if( ITEM_CHECKINDEX( At_SoubiIndex ) == TRUE ){ + At_Soubi = ITEM_getInt( At_SoubiIndex, ITEM_CRITICAL ); + } + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY){ + Df_Dex *= 0.8; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + divpara = 10.0; + root = 0; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + divpara = 10.0; + root = 0; + }else + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER){ + Df_Dex *= 0.6; + } + + if( At_Dex >= Df_Dex ){ + Big = At_Dex; + Small = Df_Dex; + wari = 1.0; + }else{ + Big = Df_Dex; + Small = At_Dex; + if( Big <= 0 ){ + wari = 0.0; + }else{ + wari = Small / Big; + } + } + Work = ( Big - Small ) / divpara; + if( Work <= 0 ) Work = 0; + + if( root == 1 ){ + per = (float)( sqrt( (double)Work ) ) + At_Soubi * 0.5; + }else{ + per = (float)Work + At_Soubi * 0.5; + } + per *= wari; + per += At_Luck ; + per *= 100; + if( per < 0 ) per = 1; + if( per > 10000 ) per = 10000; +#ifdef _PETSKILL_LER + // ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) per = 0; +#endif + return (int)per; +} + +static int BATTLE_CounterCalc( int attackindex, int defindex ) +{ + int Df_Dex, At_Dex, Work, root = 1; + float per, Big, Small, wari, divpara = gCounterPara; + + At_Dex = CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX ); + Df_Dex = CHAR_getWorkInt( defindex, CHAR_WORKFIXDEX ); + + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + ){ + divpara = 10; + root = 0; + }else if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + ){ + Df_Dex *= 0.8; + }else if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ){ + divpara = 10; + root = 0; + }else if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER + ){ + Df_Dex *= 0.6; + } + + if( At_Dex >= Df_Dex ){ + Big = At_Dex; + Small = Df_Dex; + wari = 1.0; + }else{ + Big = Df_Dex; + Small = At_Dex; + if( Big <= 0 ){ + wari = 0.0; + }else{ + wari = Small / Big; + } + } + Work = ( Big - Small ) / divpara; + if( Work <= 0 ) Work = 0; + if( root == 1 ){ + per = (float)( (double)sqrt( Work ) ); + }else{ + per = (float)( Work); + } + per *= wari; + + return per; +} + +static int BATTLE_CriticalCheck( int attackindex, int defindex ) +{ + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + return BATTLE_CriticalCheckPlayer( attackindex, defindex ); + }else{ + return BATTLE_CriticalCheckPlayer( attackindex, defindex ); + } +} + +static int BATTLE_CriDamageCalc( int attackindex, int defindex ) +{ + int damage = 0; + damage = BATTLE_DamageCalc( attackindex, defindex ); + + damage += CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ) + * (float)CHAR_getInt( attackindex, CHAR_LV ) + / (float)CHAR_getInt( defindex, CHAR_LV ) + * 0.5; + return damage; +} + +static int BATTLE_GuardianCheck( int attackindex, int defindex ) +{ + int GuardianIndex, Guardian, battleindex; + int DefSide = 0, i, DefNo; + //char szBuffer[256]=""; + + battleindex = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ); + + DefNo = BATTLE_Index2No( battleindex, defindex ); + i = DefNo; + if( i >= SIDE_OFFSET ){ + i -= SIDE_OFFSET; + DefSide = 1; + } + + if( BattleArray[battleindex].Side[DefSide].Entry[i].guardian == -1 ){ + return -1; + } + + Guardian = BattleArray[battleindex].Side[DefSide].Entry[i].guardian; +// Terry add fix ʹΪ˼ʱ,ʹô˼ܵclientᵱ + if(Guardian == DefNo) return -1; +// end + GuardianIndex = BATTLE_No2Index( battleindex, Guardian ); + + if( CHAR_CHECKINDEX( GuardianIndex ) == FALSE )return -1; + + if( CHAR_getFlg( GuardianIndex, CHAR_ISDIE ) == TRUE )return -1; + + if( CHAR_getWorkInt( GuardianIndex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_GUARDIAN ){ + }else{ + return -1; + } + + if( CHAR_getWorkInt( GuardianIndex, CHAR_WORKSLEEP ) > 0 + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKCONFUSION ) > 0 + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKPARALYSIS ) > 0 + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKSTONE ) > 0 + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKBARRIER ) > 0 + || GuardianIndex == attackindex +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKDIZZY ) > 0 // ѣ + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKDRAGNET ) > 0 // ޵ + || CHAR_getWorkInt( GuardianIndex, CHAR_WORKINSTIGATE ) > 0 // +#endif +#ifdef _PROFESSION_ADDSKILL + || CHAR_getWorkInt( GuardianIndex, CHAR_DOOMTIME ) > 0 //ĩռ +#endif + ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)Ҫס(%s)ûɹ\", + // CHAR_getUseName( GuardianIndex ), + // CHAR_getUseName( defindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (DefNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + return -1; + } + + if( BATTLE_IsThrowWepon( + CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == TRUE + ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)Ҫס(%s)ûɹ\", + // CHAR_getUseName( GuardianIndex ), + // CHAR_getUseName( defindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (DefNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + return -1; + } + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ס(%s)", + // CHAR_getUseName( GuardianIndex ), + // CHAR_getUseName( defindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (DefNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + return Guardian; +} + + +static int BATTLE_DamageWakeUp( int battleindex, int defindex ) +{ + if(!BATTLE_CHECKINDEX(battleindex)) return 0; + if(!CHAR_CHECKINDEX(defindex)) return 0; + int bid; + char szBuffer[256]=""; + CHAR_setInt( defindex, CHAR_DAMAGECOUNT, + CHAR_getInt( defindex, CHAR_DAMAGECOUNT ) +1 ); + + if( CHAR_getWorkInt( defindex, CHAR_WORKSLEEP ) > 0 ){ + CHAR_setWorkInt( defindex, CHAR_WORKSLEEP, 0 ); + bid = BATTLE_Index2No( battleindex, defindex ); + //sprintf( szBuffer, "(%s)\n", + // CHAR_getUseName( defindex ) ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (bid >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + sprintf( szBuffer, "BM|%X|%X|", bid, 0 ); + strcat( szBadStatusString, szBuffer ); + } + return 0; +} + +static int BATTLE_AttackSeq( int attackindex, int defindex, int *pDamage, int *pGuardian, int opt ) +{ + int iRet = 0, perCri = 0; + int GuardianIndex = -1,battleindex; + + battleindex = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ); + + // ˴ + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET + && BattleArray[battleindex].norisk == 0 + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E){ + if( CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX ) == attackindex ){ + CHAR_PetAddVariableAi( defindex, AI_FIX_SEKKAN ); // ҳ϶ + } + } + + // + if( opt != BATTLE_COM_COMBO ){ + if( BATTLE_DuckCheck( attackindex, defindex ) == TRUE ){ + return BATTLE_RET_DODGE; + } +#ifdef _SUIT_ADDPART3 + if( CHAR_getWorkInt( defindex, CHAR_WORKDUCKPOWER) > 0 ){ + if( rand()%100 < CHAR_getWorkInt( defindex, CHAR_WORKDUCKPOWER) ) + return BATTLE_RET_DODGE; + } +#endif + } + + // 鱻ޱȮ + if( *pGuardian == -1 ){ + *pGuardian = BATTLE_GuardianCheck( attackindex, defindex ); + if( *pGuardian != -1 ){ + GuardianIndex = BATTLE_No2Index( battleindex, *pGuardian ); + defindex = GuardianIndex; + } + } + + // һ + perCri = BATTLE_CriticalCheck( attackindex, defindex ); + +#ifdef _PETSKILL_DAMAGETOHP + if( opt == BATTLE_COM_S_DAMAGETOHP2 ){ //¿ (һ30%) && CHAR_getInt( attackindex, CHAR_HP) <= CHAR_getWorkInt( attackindex, CHAR_MAXMP)*0.5 + //print("\n1һ:%d",perCri); + //print("\n1:%d", CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER)); + //print("\n1:%d", CHAR_getWorkInt( attackindex, CHAR_WORKQUICK)); + perCri = perCri + (perCri*0.3); //һ30% + CHAR_setWorkInt( attackindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( attackindex,CHAR_WORKFIXSTR)+CHAR_getWorkInt( attackindex,CHAR_WORKFIXSTR)*0.2);//20% + CHAR_setWorkInt( attackindex, CHAR_WORKQUICK, CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX)+CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX) *0.2 );//20% + //print("\n2һ:%d",perCri); + //print("\n2:%d", CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER)); + //print("\n2:%d", CHAR_getWorkInt( attackindex, CHAR_WORKQUICK)); + } +#endif + + gCriper = perCri; + if( RAND( 1, 10000 ) < perCri ){ + // WON ADD + int gWeponType = BATTLE_GetWepon( attackindex ); + if( gWeponType != ITEM_BOW ){ + (*pDamage) = BATTLE_CriDamageCalc( attackindex, defindex ); + }else{ + (*pDamage) = BATTLE_DamageCalc( attackindex, defindex ); + } + iRet = BATTLE_RET_CRITICAL; +#ifdef _CHAR_PROFESSION + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + // ʿר + PROFESSION_SKILL_WEAPON_FOCUS_LVEVEL_UP( attackindex, "PROFESSION_WEAPON_FOCUS" ); + // ʿ + PROFESSION_SKILL_DUAL_WEAPON_LVEVEL_UP( attackindex, "PROFESSION_DUAL_WEAPON" ); + } +#endif + }else{ + (*pDamage) = BATTLE_DamageCalc( attackindex, defindex ); + iRet = BATTLE_RET_NORMAL; + } + + if( opt == BATTLE_COM_S_GBREAK){ + ;; + }else +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 + if( opt == BATTLE_COM_S_GBREAK2){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD){ + (*pDamage) = (*pDamage)*1.3; + }else{ + (*pDamage) = (*pDamage)*0.7; + } + }else +#endif + +#ifdef _PETSKILL_REGRET + if( opt == BATTLE_COM_S_REGRET2 ){// ˺ + (*pDamage) = (*pDamage)*0.8; + }else +#endif +#ifdef _SONIC_ATTACK // WON ADD + if( opt == BATTLE_COM_S_SONIC2 ){// ˺ + (*pDamage) = (*pDamage)*0.5; + }else +#endif + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 ){ + (*pDamage) = BATTLE_GuardAdjust( (*pDamage) ); + } + if( (*pDamage) < 1 ) (*pDamage) = RAND( 0, 1 ); + +#ifdef _PREVENT_TEAMATTACK // ֹͬӻ + if (CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER || + CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + int myside = CHAR_getWorkInt( defindex, CHAR_WORKBATTLESIDE);//attackindex + if( myside == CHAR_getWorkInt( attackindex, CHAR_WORKBATTLESIDE)){ + if( CHAR_getWorkInt( attackindex, CHAR_WORKCONFUSION) > 0 +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + || CHAR_getWorkInt( attackindex, CHAR_WORKINSTIGATE) > 0 // +#endif +#ifdef _PROFESSION_ADDSKILL + || CHAR_getWorkInt( attackindex, CHAR_WORKANNEX) > 0 // +#endif + ){ //쳣 +#ifdef _PETSKILL_TEMPTATION + }else if( CHAR_getWorkInt( attackindex, CHAR_WORKTEMPTATION ) > 0 ){//ˮջ +#endif + }else if( CHAR_getInt( attackindex, CHAR_WHICHTYPE) == CHAR_TYPEPET && + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEFLG) & CHAR_BATTLEFLG_AIBAD ){ //nono + }else if( CHAR_getInt( defindex, CHAR_WHICHTYPE) == CHAR_TYPEPET && + CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX) == attackindex ){ // ѳ + }else { + int myhp, mymaxhp; + mymaxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP); + myhp = CHAR_getInt( defindex, CHAR_HP ) - *pDamage; + mymaxhp = mymaxhp *0.40; + if( mymaxhp >= myhp || mymaxhp < 40 ){ + *pDamage = 0; + }else { + *pDamage = 1; + } + } + } + } +#endif + +#ifdef _EQUIT_ARRANGE + if( BATTLE_ArrangeCheck( attackindex, defindex) == TRUE ){ + *pDamage *= 0.1; + iRet = BATTLE_RET_ARRANGE; +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + // ʿ񵲼 + if( (CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) ) + PROFESSION_SKILL_LVEVEL_UP( defindex, "PROFESSION_DEFLECT" ); +#endif + } +#endif + if( (*pDamage) == 0 ){ + iRet = BATTLE_RET_MISS; + if( GuardianIndex != -1 ){ + iRet = BATTLE_RET_NORMAL; + *pDamage = 1; + }else if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 ){ + iRet = BATTLE_RET_ALLGUARD; + } + } + + (*pDamage) *= gBattleDamageModyfy; + return iRet; +} + +#ifdef _PETSKILL_SETDUCK +BOOL BATTLE_CheckMySkillDuck( int charaindex ) +{ + int SDuck=0,rad=0; + if( !CHAR_CHECKINDEX( charaindex) ) + return FALSE; + if( (SDuck=CHAR_getWorkInt( charaindex, CHAR_MYSKILLDUCK)) > 0 ){ + int duck1 = CHAR_getWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER); + if( (rad = (rand()%100)) > duck1 ){ + return FALSE; + }else {//ر + return TRUE; + } + } + return FALSE; +} +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +int BATTLE_check_profession_duck( int charaindex, int per ) +{ + + int SDuck=0; + + if( (SDuck=CHAR_getWorkInt( charaindex, CHAR_WORK_P_DUCK)) > 0 ){ + int duck1 = CHAR_getWorkInt( charaindex, CHAR_WORKMOD_P_DUCK); + per = per * ( 100 + duck1 ) / 100; + } + + return per; +} +#endif + + +int BATTLE_GetDamageReact( int charaindex ) +{ + if( CHAR_getWorkInt( charaindex, CHAR_WORKDAMAGEVANISH ) > 0 ){ + return BATTLE_MD_VANISH; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKDAMAGEABSROB ) > 0 ){ + return BATTLE_MD_ABSROB; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKDAMAGEREFLEC ) > 0 ){ + return BATTLE_MD_REFLEC; + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( CHAR_getWorkInt( charaindex, CHAR_WORKTRAP ) > 0 ){ // + return BATTLE_MD_TRAP; + } +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( CHAR_getWorkInt( charaindex, CHAR_WORKACUPUNCTURE ) > 0 ){ //Ƥ + //print("\n:BATTLE_GetDamageReact"); + return BATTLE_MD_ACUPUNCTURE; + } +#endif + return 0; +} + +int BATTLE_DamageSub( int attackindex, int defindex, int *pDamage, int *pPetDamage, int *pRefrect ) +{ + + int hp = 0, addpoint = 0, maxhp, IsUltimate = 0, react, work, battleindex; + int damage, playerdamage, petdamage; + int attackpet, defpet; + int pethp = 0, petmaxhp = 0; + int defquick = 0, petquick = 0; + + damage = *pDamage; + petdamage = *pPetDamage; + playerdamage = damage; + if( damage <= 0 )return 0; + +#ifdef _PETSKILL_SHOWMERCY + if( CHAR_getInt( defindex, CHAR_HP ) - damage <= 0 + && CHAR_getWorkInt(attackindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_S_SHOWMERCY ){ + damage = CHAR_getInt( defindex, CHAR_HP ) - 1; + *pDamage = damage; + playerdamage = damage; + } +#endif + + attackpet = BATTLE_getRidePet( attackindex ); + defpet = BATTLE_getRidePet( defindex ); + if( defpet != -1 ) { + defquick = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( defpet, CHAR_WORKDEFENCEPOWER ); + } + + if( *pRefrect != -1 ){ + react = BATTLE_GetDamageReact( defindex ); + }else{ + react = BATTLE_MD_NONE; + } + battleindex = CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ); + + if( react == BATTLE_MD_REFLEC ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + *pRefrect = BATTLE_MD_REFLEC; + }else{ + *pRefrect = BATTLE_MD_NONE; + } + }else{ + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ) + *pRefrect = BATTLE_MD_TRAP; + else + *pRefrect = BATTLE_MD_NONE; + } +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + *pRefrect = BATTLE_MD_ACUPUNCTURE; + }else{ + *pRefrect = BATTLE_MD_NONE; + } + } +#endif + + if( react == BATTLE_MD_ABSROB ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet == -1 ) { + hp += damage; + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + playerdamage = (damage*petquick)/(defquick+petquick) +1 ; + petdamage = damage - playerdamage +1 ; + hp += playerdamage; + pethp += petdamage; + + } + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEABSROB ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEABSROB, max( work, 0 ) ); + *pRefrect = BATTLE_MD_ABSROB; + }else + if( *pRefrect == BATTLE_MD_REFLEC ){ +#ifdef _PETSKILL_BATTLE_MODEL + if(CHAR_getWorkInt(defindex,CHAR_NPCWORKINT1) == BATTLE_COM_S_BATTLE_MODEL){ + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max( work, 0 ) ); + hp = CHAR_getInt(defindex,CHAR_HP); + pethp = CHAR_getInt(defpet,CHAR_HP); + } + else +#endif + { + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max( work, 0 ) ); + defindex = attackindex; + defpet = attackpet; + } + }else +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( *pRefrect == BATTLE_MD_TRAP ){ // +#ifdef _PETSKILL_BATTLE_MODEL + if(CHAR_getWorkInt(defindex,CHAR_NPCWORKINT1) == BATTLE_COM_S_BATTLE_MODEL){ + CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( defindex, CHAR_WORKMODTRAP, 0 ); + hp = CHAR_getInt(defindex,CHAR_HP); + pethp = CHAR_getInt(defpet,CHAR_HP); + } + else +#endif + { + int value=0; + value = CHAR_getWorkInt( defindex, CHAR_WORKMODTRAP ); + damage = value; + + playerdamage = damage; + + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + + CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( defindex, CHAR_WORKMODTRAP, 0 ); + + defindex = attackindex; + defpet = attackpet; + } + }else +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( *pRefrect == BATTLE_MD_ACUPUNCTURE ){ //Ƥ + + if( damage%2 != 0 ) + damage+=1; + playerdamage = damage; + + //ȿ۱Ѫ,Ϊ֮ĶǶԹ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + defquick = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( defpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + if(playerdamage%2 != 0) playerdamage+=1; + if(petdamage%2 != 0) petdamage+=1; + hp -= playerdamage; + pethp -= petdamage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + }else{ + hp -= damage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + } + } + + //Change 2003/08/22 + if( (damage) >= CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ) * 1.2 + 20 ){ + int DefSide=0,i; + int defNo = BATTLE_Index2No( battleindex, defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + + //ijΪϢ + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + }else{ + i = defNo; + } + i = defNo-DefSide*SIDE_OFFSET; + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + //ƤܻغΪ0 + CHAR_setWorkInt( defindex, CHAR_WORKACUPUNCTURE, 0); + //if( CHAR_getWorkInt( defindex, CHAR_WORKSLEEP ) > 0 )//޻˯ + // CHAR_setWorkInt( defindex, CHAR_WORKSLEEP, 0); + +#ifdef _PETSKILL_BATTLE_MODEL + if(CHAR_getWorkInt(defindex,CHAR_NPCWORKINT1) != BATTLE_COM_S_BATTLE_MODEL) +#endif + { + //۹Ѫ + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage/2; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + if(playerdamage%2 != 0) playerdamage+=1; + if(petdamage%2 != 0) petdamage+=1; + hp -= playerdamage/2; + pethp -= petdamage/2; + }else + hp -= damage/2; + } + playerdamage /= 2; + + defindex = attackindex; + defpet = attackpet; + } + }else +#endif + if( react == BATTLE_MD_VANISH ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet != -1 ) + pethp = CHAR_getInt( defpet, CHAR_HP ); + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEVANISH, max( work, 0 ) ); + *pRefrect = BATTLE_MD_VANISH; + //andy_log +// print("*pRefrect = BATTLE_MD_VANISH !!\n"); + }else{ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + if( pethp > 0 ) { + //andy_edit 2002/07/31 + defquick = defquick>0?defquick:1; + petquick = petquick>0?petquick:1; + playerdamage = (damage*petquick)/(defquick+petquick)+ 1; + //playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1; + hp -= playerdamage; + pethp -= petdamage; + //print(" def_damage:%d ridepet_damage:%d ", (damage*petquick)/(defquick+petquick), damage - playerdamage); + }else + hp -= damage; + } + *pRefrect = 0; + } + + if( hp < 0 ){ + addpoint = -hp; + hp = 0; + } + + + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + if( defpet != -1 ) { + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + // Robin 0804 + if( pethp <= 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + //print(" defpet_die! "); + } + } + + if( (damage) >= maxhp * 1.2 + 20 ){ + IsUltimate = 2; + }else{ + if( addpoint > 0 ){ + addpoint += CHAR_getWorkInt( defindex, CHAR_WORKULTIMATE ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, addpoint ); + if( addpoint >= maxhp * 1.2 + 20 )IsUltimate = 1; + } + } + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) IsUltimate = 0; +#endif + + if( IsUltimate ){ + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + } + if( playerdamage < 0 ) playerdamage = 0; + if( petdamage < 0 ) petdamage = 0; + *pDamage = playerdamage; + *pPetDamage = petdamage; + + return IsUltimate; +} + +#ifdef _PETSKILL_FIREKILL //ɱר +int BATTLE_DamageSub_FIREKILL( int attackindex, int defindex, int *pDamage, int *pPetDamage, int *pRefrect ) +{ + + int hp, addpoint = 0, maxhp, IsUltimate = 0, react, work, battleindex; + int damage, playerdamage, petdamage; + int attackpet, defpet; + int pethp = 0, petmaxhp = 0; + int defquick = 0, petquick = 0; + damage = *pDamage; + petdamage = *pPetDamage; + playerdamage = damage; + if( damage <= 0 )return 0; + + attackpet = BATTLE_getRidePet( attackindex ); + defpet = BATTLE_getRidePet( defindex ); + if( defpet != -1 ) { + defquick = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( defpet, CHAR_WORKDEFENCEPOWER ); + } + + if( *pRefrect != -1 ){ + react = BATTLE_GetDamageReact( defindex ); + }else{ + react = BATTLE_MD_NONE; + } + + react = BATTLE_MD_NONE; + + battleindex = CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ); + + if( react == BATTLE_MD_REFLEC ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + *pRefrect = BATTLE_MD_REFLEC; + }else{ + *pRefrect = BATTLE_MD_NONE; + } + }else{ + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ) + *pRefrect = BATTLE_MD_TRAP; + else + *pRefrect = BATTLE_MD_NONE; + } +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + *pRefrect = BATTLE_MD_ACUPUNCTURE; + }else{ + *pRefrect = BATTLE_MD_NONE; + } + } +#endif + + if( react == BATTLE_MD_ABSROB ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet == -1 ) { + hp += damage; + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + playerdamage = (damage*petquick)/(defquick+petquick) +1 ; + petdamage = damage - playerdamage +1 ; + hp += playerdamage; + pethp += petdamage; + + } + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEABSROB ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEABSROB, max( work, 0 ) ); + *pRefrect = BATTLE_MD_ABSROB; + }else + if( *pRefrect == BATTLE_MD_REFLEC ){ + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max( work, 0 ) ); + defindex = attackindex; + defpet = attackpet; + + }else +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( *pRefrect == BATTLE_MD_TRAP ){ // + int value=0; + value = CHAR_getWorkInt( defindex, CHAR_WORKMODTRAP ); + damage = value; + + playerdamage = damage; + + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + + CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( defindex, CHAR_WORKMODTRAP, 0 ); + + defindex = attackindex; + defpet = attackpet; + + }else +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( *pRefrect == BATTLE_MD_ACUPUNCTURE ){ //Ƥ + + if( damage%2 != 0 ) + damage+=1; + playerdamage = damage; + + //ȿ۱Ѫ,Ϊ֮ĶǶԹ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + defquick = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( defpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + if(playerdamage%2 != 0) playerdamage+=1; + if(petdamage%2 != 0) petdamage+=1; + hp -= playerdamage; + pethp -= petdamage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + }else{ + hp -= damage; + if(hp<0)hp=0; + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + } + } + + //Change 2003/08/22 + if( (damage) >= CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ) * 1.2 + 20 ){ + int DefSide=0,i; + int defNo = BATTLE_Index2No( battleindex, defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + + //ijΪϢ + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + }else{ + i = defNo; + } + i = defNo-DefSide*SIDE_OFFSET; + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + //ƤܻغΪ0 + CHAR_setWorkInt( defindex, CHAR_WORKACUPUNCTURE, 0); + //if( CHAR_getWorkInt( defindex, CHAR_WORKSLEEP ) > 0 )//޻˯ + // CHAR_setWorkInt( defindex, CHAR_WORKSLEEP, 0); + + //۹Ѫ + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage/2; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + if(playerdamage%2 != 0) playerdamage+=1; + if(petdamage%2 != 0) petdamage+=1; + hp -= playerdamage/2; + pethp -= petdamage/2; + }else + hp -= damage/2; + } + + playerdamage /= 2; + + defindex = attackindex; + defpet = attackpet; + + }else +#endif + if( react == BATTLE_MD_VANISH ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet != -1 ) + pethp = CHAR_getInt( defpet, CHAR_HP ); + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEVANISH, max( work, 0 ) ); + *pRefrect = BATTLE_MD_VANISH; + //andy_log +// print("*pRefrect = BATTLE_MD_VANISH !!\n"); + }else{ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet == -1 ) { + hp -= damage; + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + if( pethp > 0 ) { + //andy_edit 2002/07/31 + defquick = defquick>0?defquick:1; + petquick = petquick>0?petquick:1; + playerdamage = (damage*petquick)/(defquick+petquick)+ 1; + //playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1; + hp -= playerdamage; + pethp -= petdamage; + //print(" def_damage:%d ridepet_damage:%d ", (damage*petquick)/(defquick+petquick), damage - playerdamage); + }else + hp -= damage; + } + *pRefrect = 0; + } + if( hp < 0 ){ + addpoint = -hp; + hp = 0; + } + + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + if( defpet != -1 ) { + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + // Robin 0804 + if( pethp <= 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + print(" defpet_die! "); + } + } + + if( (damage) >= maxhp * 1.2 + 20 ){ + IsUltimate = 2; + }else{ + if( addpoint > 0 ){ + addpoint += CHAR_getWorkInt( defindex, CHAR_WORKULTIMATE ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, addpoint ); + if( addpoint >= maxhp * 1.2 + 20 )IsUltimate = 1; + } + } + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + } + +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) IsUltimate = 0; +#endif + + if( IsUltimate ){ + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + } + if( playerdamage < 0 ) playerdamage = 0; + if( petdamage < 0 ) petdamage = 0; + *pDamage = playerdamage; + *pPetDamage = petdamage; + + return IsUltimate; +} +#endif + + +// Robin 0910 RidePetDebug +int BATTLE_DamageSub2( int attackindex, int defindex, int *pDamage, int *pPetDamage, int *pRefrect ) +{ + + int hp, addpoint = 0, maxhp, IsUltimate = 0, react, work, battleindex; + int damage, playerdamage, petdamage; + int attackpet, defpet; + int pethp = 0, petmaxhp = 0; + + damage = *pDamage; + petdamage = *pPetDamage; + playerdamage = *pDamage; + + if( damage <= 0 )return 0; + + attackpet = BATTLE_getRidePet( attackindex ); + defpet = BATTLE_getRidePet( defindex ); + + if( *pRefrect != -1 ){ + react = BATTLE_GetDamageReact( defindex ); + }else{ + react = BATTLE_MD_NONE; + } + + if( react == BATTLE_MD_REFLEC ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + *pRefrect = BATTLE_MD_REFLEC; + }else{ + *pRefrect = BATTLE_MD_NONE; + } + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ){ + if( BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ) + *pRefrect = BATTLE_MD_TRAP; + else + *pRefrect = BATTLE_MD_NONE; + } +#endif + + if( react == BATTLE_MD_ABSROB ){ + + hp = CHAR_getInt( defindex, CHAR_HP ); + hp += playerdamage; + if( defpet != -1 ) { + pethp = CHAR_getInt( defpet, CHAR_HP ); + pethp += petdamage; + } + + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEABSROB ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEABSROB, max( work, 0 ) ); + + *pRefrect = BATTLE_MD_ABSROB; + + }else + if( *pRefrect == BATTLE_MD_REFLEC ){ + + hp = CHAR_getInt( attackindex, CHAR_HP ); + hp -= playerdamage; + if( attackpet != -1 ) { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + if( pethp > 0 ) { + pethp -= petdamage; + } + } + + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max( work, 0 ) ); + + defindex = attackindex; + defpet = attackpet; + + }else +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( *pRefrect == BATTLE_MD_TRAP ){ // + + hp = CHAR_getInt( attackindex, CHAR_HP ); + hp -= playerdamage; + if( attackpet != -1 ) { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + if( pethp > 0 ) { + pethp -= petdamage; + } + } + + CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( defindex, CHAR_WORKMODTRAP, 0 ); + + defindex = attackindex; + defpet = attackpet; + + }else +#endif + if( react == BATTLE_MD_VANISH ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet != -1 ) + pethp = CHAR_getInt( defpet, CHAR_HP ); + + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEVANISH, max( work, 0 ) ); + + *pRefrect = BATTLE_MD_VANISH; + + }else{ + hp = CHAR_getInt( defindex, CHAR_HP ); + hp -= playerdamage; + if( defpet != -1 ){ + pethp = CHAR_getInt( defpet, CHAR_HP ); + if( pethp > 0 ) { + pethp -= petdamage; + //print(" def_damage:%d ridepet_damage:%d ", (damage*petquick)/(defquick+petquick), damage - playerdamage); + } + } + *pRefrect = 0; + } + + if( hp < 0 ){ + addpoint = -hp; + hp = 0; + } + + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + + + if( defpet != -1 ) { + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + + // Robin 0804 + if( pethp <= 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + print(" defpet_die! "); + } + } + + if( (damage) >= maxhp * 1.2 + 20 ){ + IsUltimate = 2; + }else{ + if( addpoint > 0 ){ + addpoint += CHAR_getWorkInt( defindex, CHAR_WORKULTIMATE ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, addpoint ); + if( addpoint >= maxhp * 1.2 + 20 )IsUltimate = 1; + } + } + + battleindex = CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ); + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) IsUltimate = 0; +#endif + + if( IsUltimate ){ + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + } + + //*pDamage = damage; + *pDamage = playerdamage; + *pPetDamage = petdamage; + + return IsUltimate; +} + + + +void BATTLE_DamageSubCale( + int attackindex, + int defindex, + int *pDamage, + int *pPetDamage +) +{ + int pethp; + int damage, playerdamage, petdamage; + int attackpet, defpet; + int defquick = 0, petquick = 0; + + damage = *pDamage; + petdamage = *pPetDamage; + playerdamage = damage; + + attackpet = BATTLE_getRidePet( attackindex ); + defpet = BATTLE_getRidePet( defindex ); + + defquick = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + defquick = ( defquick < 1)?1:defquick; + if( defpet != -1 ) { + petquick = CHAR_getWorkInt( defpet, CHAR_WORKDEFENCEPOWER ); + petquick = ( petquick < 1)?1:petquick; + + pethp = CHAR_getInt( defpet, CHAR_HP ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick); + petdamage = damage - playerdamage; + if( damage > 0 && playerdamage < 1 ) + playerdamage = 1; + } + } + + *pDamage = playerdamage; + *pPetDamage = petdamage; + +} + +int BATTLE_Attack( int battleindex, int attackNo, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, attackindex, toindex, ultimate = 0, + defindex, react = 0, statusDefNo, opt = 0; + int flg = 0, iWork, par, perStatus, i, DefSide = 0, Guardian = -1; + BOOL iRet = TRUE; + int suitpoison=30;//ж% + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = toindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return FALSE; + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return FALSE; + +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = 0; +#endif + + if( gWeponType == ITEM_BOW ){ + if( toindex < 0 || CHAR_getInt( toindex, CHAR_HP ) <= 0 ){ + snprintf( szCommand, sizeof( szCommand ), "r%X|f0|d0|", defNo ); + BATTLESTR_ADD( szCommand ); + return FALSE; + } + } + + if( CHAR_getInt( toindex, CHAR_HP ) <= 0 ) return FALSE; + + if( CHAR_getInt( attackindex, CHAR_HP ) <= 0 ) return FALSE; + + // ⡢ + if( BATTLE_GetDamageReact( attackindex ) > 0 ) iRet = FALSE; + else if( BATTLE_GetDamageReact( defindex ) > 0 ) iRet = FALSE; + + // ģʽ + iWork = BATTLE_AttackSeq( attackindex, toindex, &damage, &Guardian, opt ); + + if( Guardian >= 0 ) + defindex = BATTLE_No2Index( battleindex, Guardian ); + + if( gDamageDiv != 0.0 && damage > 0 ){ + damage /= gDamageDiv; + if( damage <= 0 ) damage = 1; + } + + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + react = 0; + + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ){ + defindex = attackindex; + statusDefNo = attackNo; + } +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ + defindex = attackindex; + statusDefNo = attackNo; + } +#endif + if( react == BATTLE_MD_REFLEC ){ + defindex = attackindex; + statusDefNo = attackNo; + }else{ + if( 0 <= Guardian && Guardian <= 19 ){ + statusDefNo = Guardian; + }else{ + statusDefNo = defNo; + } + } + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ //Ƥʱ޷򷽵״̬,԰index + defindex = toindex = BATTLE_No2Index( battleindex, defNo ); + statusDefNo = defNo; + } +#endif + + //˯ʱ,״̬(Ҳ״̬) + if( damage > 0 && ( react != BATTLE_MD_ABSROB ) && ( react != BATTLE_MD_VANISH ) ){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ + defindex = attackindex; + statusDefNo = attackNo; + } +#endif + + switch( iWork ){ + case BATTLE_RET_ALLGUARD: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),׵ر㿪", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + flg |= BCF_NORMAL; +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = BATTLE_RET_ALLGUARD; +#endif + break; + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = BATTLE_RET_MISS; +#endif + break; + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = BATTLE_RET_DODGE; +#endif + break; + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)Ĺ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + break; + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)(%s)CRITICAL(%d%%)(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // (int)(gCriper*0.01), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_KAISHIN; + iRet = FALSE; + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = BATTLE_RET_ARRANGE; +#endif + break; +#endif + } + + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + flg |= BCF_GUARD; + iRet = FALSE; + } + +#ifdef _MASSAGE_PETSKILL + if(CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_S_MASSAGE ){ + int j; + for( j = 1; j < BATTLE_ST_END; j ++ ){ + if( CHAR_getWorkInt( defindex, StatusTbl[j] ) > 0 ){ + CHAR_setWorkInt( defindex, StatusTbl[j], 0 ); + BATTLE_BadStatusString( defNo, 0 ); + } + } + } +#endif + +#ifdef _GRAPPLING_PETSKILL + + if(CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_S_GRAPPLING ){ + char token[256]; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int array = CHAR_GETWORKINT_LOW(attackindex, CHAR_WORKBATTLECOM3); + char *skillarg = PETSKILL_getChar( array, PETSKILL_OPTION ); + char buf[64]; + int fromid; + int toid; + int itemindex; + int lj; + char item[8][32]={"ͷ","","","","","","","Ь"}; + + getStringFromIndexWithDelim( skillarg, "|", 1, buf, sizeof( buf)); + fromid = min(atoi(buf), 7); + getStringFromIndexWithDelim( skillarg, "|", 2, buf, sizeof( buf)); + lj = atoi(buf); + toid = CHAR_findEmptyItemBox( defindex ); + + if(fromid == -1)fromid=rand() % CHAR_EQUIPPLACENUM; + + itemindex = CHAR_getItemIndex( defindex, fromid ); + + if( CHAR_CHECKITEMINDEX( defindex, itemindex) == FALSE ){ + sprintf(token, "BK|%s δװ %s |", CHAR_getUseName( defindex ), item[fromid]); + }else{ + + if(toid == -1){ + sprintf(token, "BK|%s޿λж%s|", CHAR_getUseName( defindex ), item[fromid]); + }else{ + if(rand() % 100 <= lj){ + sprintf(token, "BK|%s%sж|", CHAR_getUseName( defindex ), item[fromid]); + CHAR_moveEquipItem(defindex, fromid, toid); + }else{ + sprintf(token, "BK|%s%s㱻ж|", CHAR_getUseName( attackindex ), item[fromid]); + } + } + } + }else{ + sprintf(token, "BK|޷ж|"); + } + strcat( szBadStatusString, token); + } +#endif + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER && flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } + +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ){ //Ƥᷴ״̬,ҪĻ + defindex = toindex = BATTLE_No2Index( battleindex, defNo ); + statusDefNo = defNo; + } + //ע:֮ҪҪٸĻԭ.......???? +#endif + +#ifdef _SUIT_ADDPART4 + if( gBattleStausChange == -1 && CHAR_getWorkInt( attackindex, CHAR_SUITPOISON ) > 0 )//װ + gBattleStausChange = 1,gBattleStausTurn = 3, suitpoison=CHAR_getWorkInt( attackindex, CHAR_SUITPOISON ); +#endif + + if( damage > 0 && gBattleStausChange >= 0 ){ + if( BATTLE_StatusAttackCheck( + attackindex, + defindex, + gBattleStausChange, + suitpoison, + 40, + 2.0, + &perStatus + ) == TRUE + ){ + CHAR_setWorkInt( defindex, StatusTbl[gBattleStausChange], + gBattleStausTurn + 1 ); + + if( gBattleStausChange == BATTLE_ST_DRUNK ){ + CHAR_setWorkInt( defindex, CHAR_WORKDRUNK, + CHAR_getWorkInt( defindex, CHAR_WORKDRUNK ) / 2 ); + } + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + if( gBattleStausChange == BATTLE_ST_SARS ){ + CHAR_setWorkInt( defindex, CHAR_WORKMODSARS, 1); + } +#endif + + if( gBattleStausChange == BATTLE_ST_PARALYSIS + || gBattleStausChange == BATTLE_ST_SLEEP + || gBattleStausChange == BATTLE_ST_STONE + || gBattleStausChange == BATTLE_ST_BARRIER + ){ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)(%s)(%d%%)", + // CHAR_getUseName( defindex ), + // aszStatusFull[gBattleStausChange], + // perStatus + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + BATTLE_BadStatusString( statusDefNo, gBattleStausChange ); + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)޷ɹ\(%d%%)", + // aszStatusFull[gBattleStausChange], + // perStatus ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + } +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( ( damage > 0 ) && ( CHAR_getWorkInt( attackindex , CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT ) ) { + if ( RAND ( 1 , 5 ) > 4 ) { + CHAR_setWorkInt( defindex, CHAR_WORKSLEEP , 3 ); //趨˯ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE );//Ϊ趨˻˯,趨޶ + } + } +#endif + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( damage > 0 && (CHAR_getInt(attackindex, CHAR_WHICHTYPE)== CHAR_TYPEPLAYER) ){ + int i; + // 𡢱׸ + for( i=0; i<3; i++ ){ + int turn = 0, status = -1; + + turn = CHAR_getWorkInt( attackindex, CHAR_WORK_F_ENCLOSE_2+i ); + + if( turn > 0 ){ + int skill_type = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ); + int perStatus = 0, j = 0; + int skill_level = CHAR_getWorkInt( attackindex, CHAR_WORKMOD_F_ENCLOSE_2+i ); + char pszP[3][10] = { "","˪","" }; + int img1 = 101697, img2 = 101698 + i; + + // ״̬ + for( j = 1; j < BATTLE_ST_END; j ++ ){ + if( strncmp( pszP[i], aszStatus[j], 2 ) == 0 ){ + status = j; + break; + } + } + + // + perStatus = 20 + skill_level * 2; + + // غ + if( skill_level >= 10 ) turn = 3; + else if( skill_level >= 5 ) turn = 2; + else turn = 1; + + // ׸һغ + if( i == 2 ) turn = 1; + + // 𡢱׸帽ӹ +// Terry add fix Ȯbug + if(Guardian >= 0) iRet = BATTLE_PROFESSION_RANG_ATTACK_DAMAGE(attackindex, attackNo, Guardian, skill_type, status, turn, perStatus, 0, img1, img2 ); + else iRet = BATTLE_PROFESSION_RANG_ATTACK_DAMAGE(attackindex, attackNo, defNo, skill_type, status, turn, perStatus, 0, img1, img2 ); + + break; + } + } + } +#endif + + + if( 0 <= Guardian && Guardian <= 19 ){ + iRet = FALSE; + flg |= BCF_GUARDIAN; + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|d%X|p%X|g%X|", + defNo, + flg, + damage, + petdamage, + Guardian ); + }else{ + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|d%X|p%X|", + defNo, + flg, + damage, + petdamage ); + } +#ifdef _ATTACK_EFFECT + // Ч + if (CHAR_getInt(attackindex, CHAR_ATTACK_EFFECT) > 0) + { + sprintf(szBuffer, "s%X|", CHAR_getInt(attackindex, CHAR_ATTACK_EFFECT)); + strcat(szCommand, szBuffer); + } +#endif + BATTLESTR_ADD( szCommand ); + + defNo = BATTLE_Index2No( battleindex, defindex ); + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + }else{ + i = defNo; + } + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + return iRet; + +} + +#ifdef _PETSKILL_FIREKILL +int BATTLE_Attack_FIREKILL( int battleindex, int attackNo, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, attackindex, toindex, ultimate = 0, + defindex, react = 0, statusDefNo, opt = 0; + int flg = 0, iWork, par, perStatus, i, DefSide = 0, Guardian = -1; + BOOL iRet = TRUE; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = toindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return FALSE; + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return FALSE; + + +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = 0; +#endif + + if( gWeponType == ITEM_BOW ){ + if( toindex < 0 || CHAR_getInt( toindex, CHAR_HP ) <= 0 ){ + snprintf( szCommand, sizeof( szCommand ), "r%X|f0|d0|", defNo ); + BATTLESTR_ADD( szCommand ); + return FALSE; + } + } + + if( CHAR_getInt( toindex, CHAR_HP ) <= 0 ) return FALSE; + + if( CHAR_getInt( attackindex, CHAR_HP ) <= 0 ) return FALSE; + + // ⡢ +// if( BATTLE_GetDamageReact( attackindex ) > 0 ) iRet = FALSE; +// else if( BATTLE_GetDamageReact( defindex ) > 0 ) iRet = FALSE; + + // ģʽ + iWork = BATTLE_AttackSeq( attackindex, toindex, &damage, &Guardian, opt ); + + if( Guardian >= 0 ) + defindex = BATTLE_No2Index( battleindex, Guardian ); + + if( gDamageDiv != 0.0 && damage > 0 ){ + damage /= gDamageDiv; + if( damage <= 0 ) damage = 1; + } + + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + react = 0; + + ultimate = BATTLE_DamageSub_FIREKILL( attackindex, defindex, &damage, &petdamage, &react ); + +//#ifdef _PROFESSION_SKILL // WON ADD ְҵ +// if( react == BATTLE_MD_TRAP ){ +// defindex = attackindex; +// statusDefNo = attackNo; +// } +//#endif +//#ifdef _PETSKILL_ACUPUNCTURE +// if( react == BATTLE_MD_ACUPUNCTURE ){ +// defindex = attackindex; +// statusDefNo = attackNo; +// } +//#endif +// if( react == BATTLE_MD_REFLEC ){ +// defindex = attackindex; +// statusDefNo = attackNo; +// }else{ + if( 0 <= Guardian && Guardian <= 19 ){ + statusDefNo = Guardian; + }else{ + statusDefNo = defNo; + } +// } + +//#ifdef _PETSKILL_ACUPUNCTURE +// if( react == BATTLE_MD_ACUPUNCTURE ){ //Ƥʱ޷򷽵״̬,԰index +// defindex = toindex = BATTLE_No2Index( battleindex, defNo ); +// statusDefNo = defNo; +// } +//#endif + + //˯ʱ,״̬(Ҳ״̬) + if( damage > 0 && ( react != BATTLE_MD_ABSROB ) && ( react != BATTLE_MD_VANISH ) ){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + +//#ifdef _PETSKILL_ACUPUNCTURE +// if( react == BATTLE_MD_ACUPUNCTURE ){ +// defindex = attackindex; +// statusDefNo = attackNo; +// } +//#endif + + switch( iWork ){ + case BATTLE_RET_ALLGUARD: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),׵ر㿪", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + flg |= BCF_NORMAL; + break; + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + break; + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; +#ifdef _PETSKILL_RETRACE + Battle_Attack_ReturnData_x.Battle_Attack_ReturnData = BATTLE_RET_DODGE; +#endif + break; + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)Ĺ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + break; + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)(%s)CRITICAL(%d%%)(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // (int)(gCriper*0.01), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_KAISHIN; + iRet = FALSE; + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; + break; +#endif + } + + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + flg |= BCF_GUARD; + iRet = FALSE; + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER && flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + +//#ifdef _PETSKILL_ACUPUNCTURE +// if( react == BATTLE_MD_ACUPUNCTURE ){ //Ƥᷴ״̬,ҪĻ +// defindex = toindex = BATTLE_No2Index( battleindex, defNo ); +// statusDefNo = defNo; +// } +// //ע:֮ҪҪٸĻԭ.......???? +//#endif + + + if( damage > 0 && gBattleStausChange >= 0 ){ + if( BATTLE_StatusAttackCheck( + attackindex, + defindex, + gBattleStausChange, + 30, + 40, + 2.0, + &perStatus + ) == TRUE + ){ + CHAR_setWorkInt( defindex, StatusTbl[gBattleStausChange], + gBattleStausTurn + 1 ); + + if( gBattleStausChange == BATTLE_ST_DRUNK ){ + CHAR_setWorkInt( defindex, CHAR_WORKDRUNK, + CHAR_getWorkInt( defindex, CHAR_WORKDRUNK ) / 2 ); + } + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + if( gBattleStausChange == BATTLE_ST_SARS ){ + CHAR_setWorkInt( defindex, CHAR_WORKMODSARS, 1); + } +#endif + + if( gBattleStausChange == BATTLE_ST_PARALYSIS + || gBattleStausChange == BATTLE_ST_SLEEP + || gBattleStausChange == BATTLE_ST_STONE + || gBattleStausChange == BATTLE_ST_BARRIER + ){ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)(%s)(%d%%)", + // CHAR_getUseName( defindex ), + // aszStatusFull[gBattleStausChange], + // perStatus + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + BATTLE_BadStatusString( statusDefNo, gBattleStausChange ); + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)޷ɹ\(%d%%)", + // aszStatusFull[gBattleStausChange], + // perStatus ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + } +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( ( damage > 0 ) && ( CHAR_getWorkInt( attackindex , CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT ) ) { + if ( RAND ( 1 , 5 ) > 4 ) { + CHAR_setWorkInt( defindex, CHAR_WORKSLEEP , 3 ); //趨˯ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE );//Ϊ趨˻˯,趨޶ + } + } +#endif + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( damage > 0 && (CHAR_getInt(attackindex, CHAR_WHICHTYPE)== CHAR_TYPEPLAYER) ){ + int i; + // 𡢱׸ + for( i=0; i<3; i++ ){ + int turn = 0, status = -1; + + turn = CHAR_getWorkInt( attackindex, CHAR_WORK_F_ENCLOSE_2+i ); + + if( turn > 0 ){ + int skill_type = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ); + int perStatus = 0, j = 0; + int skill_level = CHAR_getWorkInt( attackindex, CHAR_WORKMOD_F_ENCLOSE_2+i ); + char pszP[3][10] = { "","˪","" }; + int img1 = 101697, img2 = 101698 + i; + + // ״̬ + for( j = 1; j < BATTLE_ST_END; j ++ ){ + if( strncmp( pszP[i], aszStatus[j], 2 ) == 0 ){ + status = j; + break; + } + } + + // + perStatus = 20 + skill_level * 2; + + // غ + if( skill_level >= 10 ) turn = 3; + else if( skill_level >= 5 ) turn = 2; + else turn = 1; + + // ׸һغ + if( i == 2 ) turn = 1; + + // 𡢱׸帽ӹ +// Terry add fix Ȯbug + if(Guardian >= 0) iRet = BATTLE_PROFESSION_RANG_ATTACK_DAMAGE(attackindex, attackNo, Guardian, skill_type, status, turn, perStatus, 0, img1, img2 ); + else iRet = BATTLE_PROFESSION_RANG_ATTACK_DAMAGE(attackindex, attackNo, defNo, skill_type, status, turn, perStatus, 0, img1, img2 ); + + break; + } + } + } +#endif + + if( 0 <= Guardian && Guardian <= 19 ){ + iRet = FALSE; + flg |= BCF_GUARDIAN; + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|d%X|p%X|g%X|", + defNo, + flg, + damage, + petdamage, + Guardian ); + }else{ + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|d%X|p%X|", + defNo, + flg, + damage, + petdamage ); + } + + BATTLESTR_ADD( szCommand ); + + defNo = BATTLE_Index2No( battleindex, defindex ); + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + }else{ + i = defNo; + } + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + return iRet; + +} + +#endif + + +enum { + BATTLE_C_NONE = 0, + BATTLE_C_CLAW, + BATTLE_C_AXE, + BATTLE_C_CLUB, + BATTLE_C_SPEAR, + BATTLE_C_BOW, + BATTLE_C_THROU, + BATTLE_C_OTHER, + BATTLE_C_MAX +}; + +static int CounterTbl[] = { + 10, 9, 8, 8, 5, 0, 0, 0 , + 10, 9, 7, 7, 6, 0, 0, 0 , + 9, 8,10,10, 7, 0, 0, 0 , + 8, 8,10,10, 7, 0, 0, 0 , + 6, 6, 8, 8, 9, 0, 0, 0 , + 0, 0, 0, 0, 0, 0, 0, 0 , + 0, 0, 0, 0, 0, 0, 0, 0 , +}; + +static int BATTLE_ItemType2ItemMap( int type ){ + int iRet = BATTLE_C_NONE; + if( type == ITEM_FIST ) iRet = BATTLE_C_CLAW; + if( type == ITEM_AXE ) iRet = BATTLE_C_AXE; + if( type == ITEM_CLUB ) iRet = BATTLE_C_CLUB; + if( type == ITEM_BOW ) iRet = BATTLE_C_BOW; + if( type == ITEM_BOOMERANG ) iRet = BATTLE_C_THROU; + if( type == ITEM_BOUNDTHROW ) iRet = BATTLE_C_THROU; + if( type == ITEM_BREAKTHROW ) iRet = BATTLE_C_THROU; + return iRet; +} + +static BOOL BATTLE_CounterCheckPlayer( int attackindex, int defindex, int *pPar ) +{ + int + At_SoubiIndex, At_SoubiType, + Df_SoubiIndex, Df_SoubiType, + At_Soubi, CriPer, + At_Luck = 0, + flg = FALSE; + + float per; + + CriPer = BATTLE_CounterCalc( attackindex, defindex ); + + At_SoubiIndex = CHAR_getItemIndex( attackindex, CHAR_ARM ); + + if( BATTLE_IsThrowWepon( At_SoubiIndex ) == TRUE ){ + *pPar = 0.0; + return FALSE; + } + + if( ITEM_CHECKINDEX( At_SoubiIndex ) == FALSE ){ + At_SoubiType = ITEM_FIST; + }else{ + At_SoubiType = ITEM_getInt( At_SoubiIndex, ITEM_TYPE ); + } + + At_SoubiIndex = BATTLE_ItemType2ItemMap( At_SoubiType ); + + Df_SoubiIndex = CHAR_getItemIndex( defindex, CHAR_ARM ); + + if( BATTLE_IsThrowWepon( Df_SoubiIndex ) == TRUE ){ + *pPar = 0.0; + return FALSE; + } + + if( ITEM_CHECKINDEX( Df_SoubiIndex ) == FALSE ){ + Df_SoubiType = ITEM_FIST; + }else{ + Df_SoubiType = ITEM_getInt( Df_SoubiIndex, ITEM_TYPE ); + } + + Df_SoubiIndex = BATTLE_ItemType2ItemMap( Df_SoubiType ); + + At_Soubi = CounterTbl[BATTLE_C_MAX * At_SoubiIndex + Df_SoubiIndex]; + + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + At_Luck = CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ); + } + +#ifdef _SUIT_ADDENDUM + per = CriPer * At_Soubi * 0.1 + At_Luck + CHAR_getWorkInt( attackindex, CHAR_WORKCOUNTER ); +#else + per = CriPer * At_Soubi * 0.1 + At_Luck; +#endif + + *pPar = per; + + per *= 100; + if( per <= 0 ){ + per = 1; + *pPar = 0; + } + + if( RAND( 1, 10000 ) < per ){ + flg = TRUE; + }else{ + flg = FALSE; + } + return flg; +} + + +static BOOL BATTLE_CounterCheckPet( int attackindex, int defindex, int *pPer ) +{ + int At_SoubiIndex; + int flg = FALSE, Df_SoubiIndex, iWork; + + float per; + + At_SoubiIndex = CHAR_getItemIndex( attackindex, CHAR_ARM ); + + if( BATTLE_IsThrowWepon( At_SoubiIndex ) == TRUE ){ + *pPer = 0.0; + return FALSE; + } + + + Df_SoubiIndex = CHAR_getItemIndex( defindex, CHAR_ARM ); + + if( BATTLE_IsThrowWepon( Df_SoubiIndex ) == TRUE ){ + *pPer = 0.0; + return FALSE; + } + + per = BATTLE_CounterCalc( attackindex, defindex ); + + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_NOGUARD ){ + iWork = CHAR_GETWORKINT_LOW( attackindex, CHAR_WORKBATTLECOM3 ); + iWork = iWork >> 8; + if( iWork > 127 )iWork *= -1; + per += iWork; + } + + if( per > 100 ) per = 100; + *pPer = per; + per *= 100; + + if( per <= 0 ){ + per = 1; + *pPer = per; + } + + if( RAND( 1, 10000 ) <= per ){ + flg = TRUE; + }else{ + flg = FALSE; + } + return flg; +} + +static BOOL BATTLE_CounterCheck( int attackindex, int defindex, int *pPar ) +{ +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT || + CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT + ) { + return FALSE; + } +#endif + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + return BATTLE_CounterCheckPlayer( attackindex, defindex, pPar ); + }else{ + return BATTLE_CounterCheckPet( attackindex, defindex, pPar ); + } +} + + + +//ж +BOOL BATTLE_Counter( int battleindex, int attackNo, int defNo ) +{ + if(!BATTLE_CHECKINDEX(battleindex)) return FALSE; + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, attackindex, defindex, Guardian = -2, react = 0, ultimate = 0; + int flg = 0, iWork, par, DefSide = 0, i, per = 0; + BOOL iRet = TRUE; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + + if(!CHAR_CHECKINDEX(attackindex)) return FALSE; + if(!CHAR_CHECKINDEX(defindex)) return FALSE; +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + if ( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ATTSHOOT ) { + return FALSE; + } +#endif + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ) return FALSE; + if( CHAR_getInt( attackindex, CHAR_HP ) <= 0 ) return FALSE; + + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_ATTACK + || CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_NOGUARD){ + ;; + }else{ + return FALSE; + } + + // nono + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ) return FALSE; + + // + if( BATTLE_CounterCheck( attackindex, defindex, &per ) == FALSE ) return FALSE; + + // ⡢ + if( BATTLE_GetDamageReact( attackindex ) > 0 ) + iRet = FALSE; + else if( BATTLE_GetDamageReact( defindex ) > 0 ) + iRet = FALSE; + + gWeponType = BATTLE_GetWepon( attackindex ); + + gDamageDiv = 1.0; + + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, &Guardian, -1 ); + + if( damage <= 0 ){ + damage = 0; + }else{ + damage *= 0.75; + if( damage < 1 ) damage = 1; + } + + react = 0; + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + if( react == BATTLE_MD_REFLEC ) defindex = attackindex; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + + if( damage > 0 && ( react != BATTLE_MD_ABSROB ) && ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + switch( iWork ){ + case BATTLE_RET_MISS: +/* + snprintf( szBuffer, sizeof(szBuffer), + "(%s)(%s),ûС", + CHAR_getUseName( attackindex ), + CHAR_getUseName( defindex ) + ); +*/ + return FALSE; + + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)⹥(%d%%)!(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // per, + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; + break; + + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)ķ!(%d%%)(%d) (%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // per, + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; + + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)CRITICAL(%d%%)(%d) (%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // per, + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_KAISHIN; + iRet = FALSE; + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; + break; +#endif + } + + flg |= BCF_COUNTER; + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER + && flg & BCF_KAISHIN + ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + +#ifdef _NOTRIDE_ + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|counter%X|", + defNo, + flg, + damage ); +#else + snprintf( szCommand, sizeof( szCommand ), + "r%X|f%X|counter%X|p%X|", + defNo, + flg, + damage, + petdamage + ); +#endif + +#ifdef _ATTACK_EFFECT + // Ч + if (CHAR_getInt(attackindex, CHAR_ATTACK_EFFECT) > 0) + { + sprintf(szBuffer, "s%X|", CHAR_getInt(attackindex, CHAR_ATTACK_EFFECT)); + strcat(szCommand, szBuffer); + } +#endif + BATTLESTR_ADD( szCommand ); + + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + return iRet; +} + + +static BOOL BATTLE_CaptureCheck( + int attackindex, + int defindex, + float *pPer +) +{ + float + Df_MaxHp = 0, + Df_HpPer = 0, + At_Charm = 0, + At_Level = 0, + At_Dex = 0, + At_Luck = 0, + Df_Level = 0, + Df_Dex = 0, + Df_Ge = 30; + float WorkGet; + + *pPer = 0; + + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) != CHAR_TYPEENEMY ){ + return FALSE; + } + + if( CHAR_getWorkInt( defindex, CHAR_WORK_PETFLG ) == 0 ){ + return FALSE; + } + + if( CHAR_getWorkInt( attackindex, CHAR_PickAllPet) != TRUE ) { + if( CHAR_getInt( attackindex, CHAR_LV ) + 5 < CHAR_getInt( defindex, CHAR_LV )){ + return FALSE; + } + } + + At_Charm = CHAR_getWorkInt( attackindex, CHAR_WORKFIXCHARM ); + At_Level = CHAR_getInt( attackindex, CHAR_LV ); + Df_Level = CHAR_getInt( defindex, CHAR_LV ); + At_Dex = CHAR_getWorkInt( attackindex, CHAR_WORKFIXDEX ); + Df_Dex = CHAR_getWorkInt( defindex, CHAR_WORKFIXDEX ); + Df_Ge = CHAR_getWorkInt( defindex, CHAR_WORKMODCAPTUREDEFAULT ); + At_Luck = CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ); + Df_HpPer = CHAR_getInt( defindex, CHAR_HP ); + Df_MaxHp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + if( Df_MaxHp <= 0 ) Df_MaxHp = 1; + + Df_HpPer = 10 - ( Df_HpPer * Df_HpPer ) / Df_MaxHp; + Df_Level = ( At_Level/2 - Df_Level/2 ); + Df_Dex = At_Dex / 15 - Df_Dex / 15; + + WorkGet = ( Df_HpPer + Df_Level + Df_Dex + ( Df_Ge + At_Luck ) ) * At_Charm / 50; + + WorkGet += CHAR_getWorkInt( attackindex, CHAR_WORKMODCAPTURE ); + + if( CHAR_getWorkInt( defindex, CHAR_WORKSLEEP ) > 0 ){ + WorkGet += 15; + } + + if( WorkGet > 99 ) WorkGet = 99; + + *pPer = WorkGet; + + if( RAND( 1,100 ) < WorkGet ){ + return TRUE; + }else{ + return FALSE; + } + +} +#ifdef _CAPTURE_FREES +#define MAXCAPTRUEFREE 15 + +typedef struct _NeedItemEnemy{ + int EnemyId; + int ItemId[MAXCAPTRUEFREE]; +}NEEDITEMENEMY; +NEEDITEMENEMY NeedEnemy[] = { + { 524, { 2456, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, +#ifndef _DEL_NOT_25_NEED_ITEM + // + { 961, {20219, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + { 953, {20223, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + { 962, {20222, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + + { 777, {20253, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + { 796, {20247, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + { 812, {20259, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + + { 1105, {1690, 1691, 1692, -1, -1, -1, -1, -1, -1, -1} }, + { 8, {1810, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, +#ifdef _WOLF_TAKE_AXE // WON ADD ץ˫ͷǵ + { 145, {2236, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, + { 146, {2236, -1, -1, -1, -1, -1, -1, -1, -1, -1} }, +#endif +#endif +}; + + +#ifdef _NEED_ITEM_ENEMY +int need_item_eneny_init() +{ + FILE* fp; + int i; + int num=0; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/needitemeneny.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/needitemeneny.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + while(1){ + char line[128], buf[16]; + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + if(line[0]=='#')continue; + + getStringFromIndexWithDelim(line,"|", 1, buf, sizeof(buf)); + NeedEnemy[num].EnemyId=atoi(buf); + for(i=0;i=128)break; + } + fclose(fp); + return TRUE; +} +#endif + + +#else +typedef struct _NeedItemEnemy{ + int EnemyId; + int ItemId; +}NEEDITEMENEMY; +NEEDITEMENEMY NeedEnemy[] = { + { 524, 2456 }, +#ifndef _DEL_NOT_25_NEED_ITEM + // + { 961, 20219}, + { 953, 20223}, + { 962, 20222}, + +// { 777, 20253}, + { 796, 20247}, + { 812, 20259}, +#endif +}; +#endif + +static int IsNeedCaptureItem( int charaindex ) +{ + int i=0; + for( i = 0; i < arraysizeof( NeedEnemy ); i ++ ){ + if( NeedEnemy[i].EnemyId != CHAR_getInt( charaindex, CHAR_PETID ) )continue; +#ifdef _CAPTURE_FREES + return i; +#else + return NeedEnemy[i].ItemId; +#endif + } + return -1; +} +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +BOOL BATTLE_CaptureItemCheck( int attackindex, int defindex ) +{ +#ifdef _CAPTURE_FREES + int i; +#endif + int j, ti, itemindex; + + ti = IsNeedCaptureItem( defindex ); + if( ti < 0 ) return TRUE; + +#ifdef _CAPTURE_FREES + for( i=0; i= CheckCharMaxItem(attackindex) ) return FALSE; + } + return TRUE; +#else + for( j = CHAR_STARTITEMARRAY; j < CheckCharMaxItem(attackindex); j ++ ){ + itemindex =CHAR_getItemIndex( attackindex, j ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE )continue; + if( ITEM_getInt( itemindex, ITEM_ID ) == ti ){ + return TRUE; + } + } + return FALSE; +#endif + +} + +#ifdef _CAPTURE_FREES +BOOL BATTLE_CaptureItemDelAll( int attackindex, int defindex ) +{ + int i, j, itemindex=-1,ti; + + ti = IsNeedCaptureItem( defindex ); + if( ti < 0 ) return TRUE; + + for( i=0; i= 0 ){ + for( i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(attackindex); i ++ ) { + itemindex = CHAR_getItemIndex( attackindex, i ); + if( ITEM_CHECKINDEX( itemindex ) == FALSE )continue; + if( ITEM_getInt( itemindex, ITEM_ID ) == needItemId ){ + { + char token[256]; + LogItem( + CHAR_getChar( attackindex, CHAR_NAME ), + CHAR_getChar( attackindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "PetEaten(ʹ)", + CHAR_getInt( attackindex,CHAR_FLOOR), + CHAR_getInt( attackindex,CHAR_X ), + CHAR_getInt( attackindex,CHAR_Y ), + ITEM_getChar(itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_DelItem( attackindex, i); + } + } + } +#endif + + CHAR_setInt( attackindex, CHAR_GETPETCOUNT, + CHAR_getInt( attackindex, CHAR_GETPETCOUNT ) + 1 ); + + BATTLE_Exit( defindex, battleindex ); + CHAR_complianceParameter( pindex ); + CHAR_setInt( pindex, CHAR_VARIABLEAI, 0 ); + ai = CHAR_DEFAULTMAXAI - CHAR_getWorkInt( pindex, CHAR_WORKFIXAI ); + if( ai < 0 ){ + CHAR_PetAddVariableAi( pindex, ai * 100 ); + CHAR_setWorkInt( pindex, CHAR_WORKFIXAI, + CHAR_getWorkInt( pindex, CHAR_WORKFIXAI ) + ai ); + } + } + } + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + { + char szCommand[1024]; + snprintf( szCommand, sizeof( szCommand ), + "BT|a%X|r%X|f%X|", + attackNo, + defNo, + flg ); + BATTLESTR_ADD( szCommand ); + } + return ( flg )?(TRUE):(FALSE); +} + +void BATTLE_Guard( + int battleindex, + int attackNo +) +{ + char szCommand[128]; + //int attackindex; + sprintf( szCommand, "bg|%x|", attackNo ); + BATTLESTR_ADD( szCommand ); + /*attackindex = BATTLE_No2Index( battleindex, attackNo ); + { + char szBuffer[256]=""; + //snprintf( szBuffer, sizeof(szBuffer), "(%s)סȫ", + // CHAR_getUseName( attackindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }*/ + +} + +BOOL BATTLE_EscapeCheck( int attackindex, int attackNo, int *pPar ) +{ + int Esc = 100; + + int myside, otherside, battleindex; + int mylevel, enemylevel = 0, enemycnt = 0, i, enemyindex, luck, + escape_cnt, rare, SubNo; + BATTLE_ENTRY *pEntry; + + myside = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLESIDE ); + otherside = 1 - myside; + + battleindex = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ); + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return TRUE; + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P )return TRUE; + + if( attackNo >= SIDE_OFFSET ){ + SubNo = attackNo - SIDE_OFFSET; + }else{ + SubNo = attackNo; + } + + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + rare = CHAR_getInt( attackindex, CHAR_RARE ); + switch( rare ){ + case 0: luck = 1; break; + case 1: luck = 3; break; + default:luck = 5; break; + } + }else{ + luck = min( 5, CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ) ); + luck = max( 1, luck ); + } + + mylevel = CHAR_getInt( attackindex, CHAR_LV ); + pEntry = BattleArray[battleindex].Side[otherside].Entry; + + escape_cnt = BattleArray[battleindex].Side[myside].Entry[SubNo].escape+1; + + for( i = 0; i < BATTLE_ENTRY_MAX; i ++ ){ + enemyindex = pEntry[i].charaindex; + if( CHAR_CHECKINDEX( enemyindex ) == FALSE )continue; + + if( CHAR_getWorkInt( enemyindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ) + enemylevel -= 100; + + enemylevel += CHAR_getInt( enemyindex, CHAR_LV ); + + enemycnt ++; + } + + if( enemycnt <= 0 ){ + enemylevel = 0; + Esc = 100; + }else{ + enemylevel /= enemycnt; + if( luck >= 5 ){ + Esc = 95 * escape_cnt; + }else + if( luck >= 4 ){ + Esc = ( 60 * escape_cnt ) - 2*( enemylevel - mylevel ); + }else + if( luck >= 3 ){ + Esc = ( 50 * escape_cnt ) - 2*( enemylevel - mylevel ); + }else + if( luck >= 2 ){ + Esc = ( 40 * escape_cnt ) - 2*( enemylevel - mylevel ); + }else + if( luck >= 1 ){ + Esc = ( 30 * escape_cnt ) - 2*( enemylevel - mylevel ); + }else{ + Esc = 95 * escape_cnt; + } + } + + if( Esc < 1 )Esc = 1; + + *pPar = Esc; + + if( RAND( 1,100 ) < Esc ){ + return TRUE; + }else{ + return FALSE; + } +} + + +BOOL BATTLE_Escape( int battleindex, int attackNo, int flag) +{ + //char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, flg = FALSE, side, SubNo, iPar; + + sprintf( szCommand, "BE|e%X|", attackNo ); + BATTLESTR_ADD( szCommand ); + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + if( !CHAR_CHECKINDEX( attackindex ) ){ + return FALSE; + } + + if( attackNo >= SIDE_OFFSET ){ + side = 1; SubNo = attackNo - SIDE_OFFSET; + }else{ + side = 0; SubNo = attackNo; + } + + BattleArray[battleindex].Side[side].Entry[SubNo].escape ++; + + if( BATTLE_EscapeCheck( attackindex, attackNo, &iPar ) == FALSE ){ + flg = 0; + }else{ + flg = 1; + } + + if( flg == 1 || flag == 1 ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s)(%d%%)", + // CHAR_getUseName( attackindex ), iPar + //); + //if( getBattleDebugMsg( ) != 0 ){ + // BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P + && CHAR_getInt( attackindex, CHAR_HP ) > 0 ){ + BATTLE_EscapeDpSend( battleindex, attackindex ); + BATTLE_GetDuelPoint( battleindex, side, SubNo ); + } + +#ifdef _ALLBLUES_LUA_1_4 + BattleEscape(battleindex, attackindex); +#endif + + CHAR_setWorkInt( attackindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_FINAL ); + CHAR_DischargePartyNoMsg( attackindex ); + BATTLE_Exit( attackindex, battleindex ); + }else{ + //if( getBattleDebugMsg( ) != 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s)(%d%%)", + // CHAR_getUseName( attackindex ), iPar + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + } + snprintf( szCommand, sizeof( szCommand ), "f%X|", flg ); + BATTLESTR_ADD( szCommand ); + + return ( flg )?(TRUE):(FALSE); +} + + +int BATTLE_SurpriseCheck( int battleindex ) +{ + int iRet = 0, Rnd, charaindex, luck, a = 0, b = 7; + + if( BattleArray[battleindex].Side[0].type == BATTLE_S_TYPE_PLAYER + && BattleArray[battleindex].Side[1].type == BATTLE_S_TYPE_PLAYER + ){ + return 0; + } + + charaindex = BattleArray[battleindex].Side[0].Entry[0].charaindex; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return 0; + + if( BattleArray[battleindex].WinFunc != NULL )return 0; + + luck = CHAR_getWorkInt( charaindex, CHAR_WORKFIXLUCK ); + + switch( luck ){ + case 5: a = 20; b = 0; break; + case 4: a = 15; b = 2; break; + case 3: a = 10; b = 3; break; + case 2: a = 5; b = 5; break; + default: a = 0; b = 7; break; + } + + Rnd = RAND( 1, 100 ); + + if( Rnd <= a ){ + iRet = 1; + }else + if( Rnd < a + b ){ + iRet = 2; + } + + return iRet; +} + + +int BATTLE_NoAction( int battleindex, int attackNo ) +{ + //char szBuffer[512]=""; + char szCommand[512]; + int attackindex ; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + sprintf( szCommand, "bn|%x|", attackNo ); + BATTLESTR_ADD( szCommand ); + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)ʲҲ", + // CHAR_getUseName( attackindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + return 0; +} + + +int BATTLE_PetIn( int battleindex, int attackNo ) +{ + //char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, petindex ; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + petindex = CHAR_getInt( attackindex, CHAR_DEFAULTPET ); + petindex = CHAR_getCharPet( attackindex, petindex ); +#ifdef _FIXWOLF // Syu ADD ˱Bug + if ( CHAR_getInt ( petindex , CHAR_BASEIMAGENUMBER) == 101428 ) + { + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( petindex , CHAR_BASEBASEIMAGENUMBER)); + CHAR_setWorkInt( petindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( petindex , CHAR_WORKFIXSTR)); + CHAR_setWorkInt( petindex, CHAR_WORKQUICK, CHAR_getWorkInt( petindex , CHAR_WORKFIXDEX)); + } +#endif +#ifdef _PETSKILL_BECOMEFOX // ĻջٷųʱҪָ״̬ + if ( CHAR_getWorkInt ( petindex , CHAR_WORKFOXROUND) != -1 + || CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER) == 101749 ){ //DZΪ + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( petindex , CHAR_BASEBASEIMAGENUMBER)); + CHAR_setWorkInt( petindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( petindex , CHAR_WORKFIXSTR)); + CHAR_setWorkInt( petindex, CHAR_WORKQUICK, CHAR_getWorkInt( petindex , CHAR_WORKFIXDEX)); + CHAR_setWorkInt( petindex, CHAR_WORKFOXROUND, -1 ); + } +#endif + if( CHAR_getWorkInt( petindex, CHAR_WORKBATTLEFLG ) + & CHAR_BATTLEFLG_NORETURN + ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s)޷ظ(%s)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( petindex ) + //); + return 0; + } + + BATTLE_PetDefaultExit( attackindex, battleindex ); + CHAR_setInt( attackindex, CHAR_DEFAULTPET, -1 ); + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)ظ(%s)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( petindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + sprintf( szCommand, "BS|s%X|f0|", attackNo ); + BATTLESTR_ADD( szCommand ); + + return 0; + +} + +int BATTLE_PetOut( int battleindex, int attackNo ) +{ + //char szBuffer[512]=""; + char szCommand[1024], szEscapeName[128]; + int attackindex, petindex, petNo, flg = 0,iRet ; + + szCommand[0] = 0; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + petNo = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM2 ); + + CHAR_setInt( attackindex, CHAR_DEFAULTPET, petNo ); + + iRet = BATTLE_PetDefaultEntry( attackindex, battleindex, + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLESIDE ) ); + + if( iRet < 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s),ûгټ", + // CHAR_getUseName( attackindex ) + //); + }else + if( CHAR_getInt( attackindex, CHAR_DEFAULTPET ) < 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s),ûгټ", + // CHAR_getUseName( attackindex ) + //); + }else{ + flg = 1; + petNo = CHAR_getInt( attackindex, CHAR_DEFAULTPET ); + petindex = CHAR_getCharPet( attackindex, petNo ); + + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_C_OK ); + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)(%s)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( petindex ) + //); + + makeEscapeString( CHAR_getUseName( petindex ), + szEscapeName, + sizeof( szEscapeName ) ); + + sprintf( szCommand, "BS|s%X|f1|g%X|l%X|h%X|%s|m%X|", + attackNo, + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + CHAR_getInt( petindex, CHAR_LV), + CHAR_getInt( petindex, CHAR_HP), + szEscapeName, + CHAR_getWorkInt( petindex, CHAR_WORKMAXHP) + ); + BATTLESTR_ADD( szCommand ); + } + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + return ( flg )?(TRUE):(FALSE); + +} + +#ifdef _PETOUT_PETSKILL +int BATTLE_S_PetOut( int battleindex, int attackNo, int petNo ) +{ + //char szBuffer[512]=""; + char szCommand[1024], szEscapeName[128]; + int attackindex, petindex, flg = 0,iRet ; + + szCommand[0] = 0; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + CHAR_setInt( attackindex, CHAR_DEFAULTPET, petNo ); + + iRet = BATTLE_PetDefaultEntry( attackindex, battleindex, + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLESIDE ) ); + + if( iRet < 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s),ûгټ", + // CHAR_getUseName( attackindex ) + //); + }else{ + flg = 1; + petNo = CHAR_getInt( attackindex, CHAR_DEFAULTPET ); + petindex = CHAR_getCharPet( attackindex, petNo ); + + CHAR_setWorkInt( petindex, CHAR_WORKBATTLEMODE, + BATTLE_CHARMODE_C_OK ); + + makeEscapeString( CHAR_getUseName( petindex ), + szEscapeName, + sizeof( szEscapeName ) ); + + sprintf( szCommand, "|BS|s%X|f1|g%X|l%X|h%X|%s|m%X|", + attackNo, + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + CHAR_getInt( petindex, CHAR_LV), + CHAR_getInt( petindex, CHAR_HP), + szEscapeName, + CHAR_getWorkInt( petindex, CHAR_WORKMAXHP) + ); + BATTLESTR_ADD( szCommand ); + } + + return ( flg )?(TRUE):(FALSE); + +} +#endif + + +int BATTLE_Magic( int battleindex, int attackNo ) +{ + int attackindex, defindex, defNo; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defNo = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM2 ); + defindex = BATTLE_No2Index( battleindex, defNo ); + + return 0; +} + + +//б𹥻Ƿ +int BATTLE_S_GBreak( int battleindex, int attackNo, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, attackindex, defindex, ultimate = 0; + int flg = 0, iWork, par, i, DefSide = 0, + react = 0, + Guardian = -1; + BOOL iRet = FALSE; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, + &Guardian, BATTLE_COM_S_GBREAK ); + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 + ){ + react = 0; + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + if( react == BATTLE_MD_REFLEC )defindex = attackindex; +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + + }else{ + //зǷdamageΪ0 + damage = 0; + iWork = BATTLE_RET_MISS; + } + + if( damage > 0 + && ( react != BATTLE_MD_ABSROB ) + && ( react != BATTLE_MD_VANISH ) + ){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + switch( iWork ){ + + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + iRet = TRUE; + break; + + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)չ(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; + iRet = TRUE; + break; + + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)ľ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + iRet = TRUE; + break; + + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)ܵ(%s)ľCRITICAL(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_KAISHIN; + iRet = FALSE; + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; + break; +#endif + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 + ){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + iRet = FALSE; + } + + flg |= BCF_GBREAK; + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + && flg & BCF_KAISHIN + ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + +#ifdef _NOTRIDE_ + snprintf( szCommand, sizeof( szCommand ), + "BH|a%X|r%X|f%X|d%X|FF|", + attackNo, + defNo, + flg, + damage ); +#else + snprintf( szCommand, sizeof( szCommand ), + "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, + defNo, + flg, + damage, + petdamage + ); +#endif + + BATTLESTR_ADD( szCommand ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + return iRet; +} + + +#ifdef _SKILL_SACRIFICE//Ԯ vincent add 2002/05/30 +int BATTLE_S_Sacrifice( int battleindex, int attackNo, int defNo ) +{ + int attackindex, defindex = 0; + int DefSide ,Damage= 0; + BOOL iRet = FALSE; + char szCommand[256]; + int ToList[SIDE_OFFSET*2+1]; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + if( defNo >= SIDE_OFFSET ){ + DefSide = 1; + } + + //HP + CHAR_setInt(attackindex,CHAR_HP,(CHAR_getInt(attackindex,CHAR_HP)*0.5)); + CHAR_setInt(defindex,CHAR_HP,min(CHAR_getInt(attackindex,CHAR_HP)+CHAR_getInt(defindex,CHAR_HP),CHAR_getWorkInt(defindex,CHAR_WORKMAXHP))); + Damage=CHAR_getInt(attackindex,CHAR_HP); + + //ħ + BATTLE_MultiList( battleindex, defNo, ToList ); + //hpıֵ + BATTLE_MagicEffect(battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_heal2 ); + snprintf( szCommand, sizeof(szCommand),"BD|r%X|%X|%X|d%X|p%X|", attackNo, BD_KIND_HP, 0, Damage, 0 ); + BATTLESTR_ADD( szCommand ); + snprintf( szCommand, sizeof(szCommand),"BD|r%X|%X|%X|d%X|p%X|", ToList[0], BD_KIND_HP, 1, Damage, 0 ); + BATTLESTR_ADD( szCommand ); + return iRet; +} +#endif + + +#ifdef _SKILL_REFRESH +int BATTLE_S_Refresh( int battleindex, int attackNo, int defNo, int marray ) +{ + BOOL iRet = FALSE; + char *magicarg; + int status = -1, i,charaindex; + int ReceveEffect= 0; + char *pszP; + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + pszP = magicarg; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 0; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return iRet; + charaindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_getWorkInt( charaindex, StatusTbl[status] ) > 0 ){ + ReceveEffect = SPR_tyusya; + iRet = TRUE; + }else{ + ReceveEffect = SPR_hoshi; + } + + BATTLE_MultiStatusRecovery( battleindex, attackNo, defNo, + status, MAGIC_EFFECT_USER, ReceveEffect ); + return iRet; +} +#endif + +#ifdef _SKILL_ROAR //vincent輼: +int BATTLE_S_Roar( int battleindex, int attackNo, int defNo, int marray ) +{ + int masteridx=-1, index2, charaindex; + BOOL iRet = FALSE; + char buf1[256]; + char szWork[128]; + int petid=-1, i=1; + BOOL FINDPET=FALSE; + + char *magicarg; + int flg=0; + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + + index2 = BATTLE_No2Index( battleindex, defNo);//Ŀ֮index + + if( !CHAR_CHECKINDEX( index2) ) return iRet; + if( BATTLE_Index2No( battleindex, charaindex ) == defNo ){// + return iRet; + } + + if( CHAR_getInt( index2, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + petid = -1;// + }else if( CHAR_getInt( index2, CHAR_WHICHTYPE) == CHAR_TYPEPET ) { + masteridx = BATTLE_No2Index(battleindex,defNo-5);//ڳ + if( !CHAR_CHECKINDEX( masteridx) ) return iRet; + petid = CHAR_getInt(index2,CHAR_PETID);//id + }else if( CHAR_getInt( index2, CHAR_WHICHTYPE) == CHAR_TYPEENEMY ) { + petid = CHAR_getInt(index2,CHAR_PETID); + } + + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + while( getStringFromIndexWithDelim( magicarg,"|", i, buf1, sizeof( buf1)) != FALSE ) { + if( petid == atoi( buf1) ){//б + FINDPET = TRUE; + break; + } + i++; + } + +//ѶϢ + if( FINDPET == TRUE ) {//Ϊ + char buf4[255]; + sprintf( buf4, "%sˣ", CHAR_getChar( index2, CHAR_NAME)); + BATTLE_Exit(index2,battleindex);//뿪ս + if( CHAR_CHECKINDEX( masteridx) ){ + CHAR_setInt(masteridx,CHAR_DEFAULTPET,-1);//޲ս + CHAR_talkToCli( masteridx,-1, buf4, CHAR_COLORYELLOW); + } + + //ǰ + flg |= BCF_ROAR; + sprintf( szWork, "BH|a%X|", attackNo ); + BATTLESTR_ADD( szWork ); + snprintf( szWork, sizeof( szWork ), "r%X|f%X|d%X|p%X|", defNo, flg, 0, 0 ); + + BATTLESTR_ADD(szWork); + BATTLESTR_ADD( "FF|" ); + sprintf(szWork,"BQ|e%X|",defNo);//ܶ + BATTLESTR_ADD(szWork); + CHAR_talkToCli( CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX),-1, buf4, CHAR_COLORYELLOW); + } + + return iRet; +} +#endif + +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 +int BATTLE_S_GBreak2( int battleindex, int attackNo, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, attackindex, defindex, ultimate = 0; + int flg = 0, iWork, par, i, DefSide = 0, + react = 0, + Guardian = -1; + BOOL iRet = FALSE; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, + &Guardian, BATTLE_COM_S_GBREAK2 ); + react = 0; + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + if( react == BATTLE_MD_REFLEC )defindex = attackindex; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + + + if( damage > 0 + && ( react != BATTLE_MD_ABSROB ) + && ( react != BATTLE_MD_VANISH ) + ){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + switch( iWork ){ + + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + iRet = TRUE; + break; + + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)չ(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; + iRet = TRUE; + break; + + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)ľ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + iRet = TRUE; + break; + + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)ܵ(%s)ľCRITICAL(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_KAISHIN; + iRet = FALSE; + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; + break; +#endif + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 + ){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + flg |= BCF_GUARD; + flg |= BCF_GBREAK; + iRet = FALSE; + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY && flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + +#ifdef _NOTRIDE_ + snprintf( szCommand, sizeof( szCommand ), + "BH|a%X|r%X|f%X|d%X|FF|", + attackNo, + defNo, + flg, + damage ); +#else + snprintf( szCommand, sizeof( szCommand ), + "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, + defNo, + flg, + damage, + petdamage + ); +#endif + + BATTLESTR_ADD( szCommand ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + return iRet; + +} +#endif + + +int BATTLE_Charge( int battleindex, int attackNo ) +{ + //char szBuffer[512]=""; + int attackindex, iWork, N, pow; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + iWork = CHAR_GETWORKINT_LOW( attackindex, CHAR_WORKBATTLECOM3 ); + + if( iWork <= 0 ){ + + N = CHAR_GETWORKINT_HIGH( attackindex, CHAR_WORKBATTLECOM3 ); + pow = CHAR_getWorkInt( attackindex, CHAR_WORKFIXSTR ); + pow += pow * N * 0.01; + CHAR_setWorkInt( attackindex, CHAR_WORKATTACKPOWER, + pow + CHAR_getWorkInt( attackindex, CHAR_WORKMODATTACK ) ); + + CHAR_setWorkInt( attackindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_CHARGE_OK ); + return TRUE; + }else{ + + CHAR_SETWORKINT_LOW( attackindex, CHAR_WORKBATTLECOM3, iWork - 1); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)С", + // CHAR_getUseName( attackindex ) + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + BATTLE_NoAction( battleindex, attackNo ); + + return FALSE; + } +} + +//״̬ж +int BATTLE_StatusAttackCheck( + int attackindex, + int defindex, + int status, + int PerOffset, + int Range, + float Bai, + int *pPer +) +{ + + int Df_Reg = 0, level = 0, per = 0, i ; + int battleindex; + if( status >= BATTLE_ST_END || status <= 0 )return FALSE; + for( i = 1; i < BATTLE_ST_END; i++ ){//쳣״̬return + if( CHAR_getWorkInt( defindex, StatusTbl[i] ) > 0 )return FALSE; + } + + if( status == BATTLE_ST_PARALYSIS){ + per = 20; + per -= CHAR_getWorkInt( defindex, RegTbl[status] ); +#ifdef _MO_LUA_RESIST + per -= CHAR_getWorkInt( defindex, CHAR_WORK_RESIST_PARALYSIS); + if (per < 0) per = 0; +#endif + *pPer = per; + }else{ + float templP = 0.0; + float fVitalP = 0.0; + fVitalP = CHAR_getInt( defindex, CHAR_VITAL ) + + CHAR_getInt( defindex, CHAR_STR ) + + CHAR_getInt( defindex, CHAR_TOUGH ) + + CHAR_getInt( defindex, CHAR_DEX ); + + templP = (float)CHAR_getInt( defindex, CHAR_VITAL ) / (fVitalP); + +#ifdef _PET_SKILL_SARS //andy_add 2003/06/20 + if( status == BATTLE_ST_SARS ){ + templP = (1 - templP)*0.9; + } +#endif + + fVitalP = templP / 0.25; + + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + fVitalP *= 10.0; + }else{ + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + fVitalP *= 10.0; + }else{ + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + fVitalP *= 10.0; + }else{ + fVitalP *= 10.0; + } + } + } + + if( status >= arraysizeof( RegTbl) || status < 0 ) { + Df_Reg = 0; + }else { + Df_Reg = CHAR_getWorkInt( defindex, RegTbl[status] ); +#ifdef _MO_LUA_RESIST + Df_Reg += CHAR_getWorkInt( defindex, RegTbl[status]+CHAR_WORK_RESIST_POISON-CHAR_WORKMODPOISON); +#endif + } + + battleindex = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ); + if( BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + level = CHAR_getInt( attackindex, CHAR_LV ) + - CHAR_getInt( defindex, CHAR_LV ); + level *= Bai; + }else{ + level = 0; + } + if( level > Range )level = Range; + if( level < -Range )level = -Range; + +#ifdef _SUIT_ADDENDUM + per = PerOffset + level + CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ) + - Df_Reg - fVitalP - CHAR_getWorkInt( defindex, CHAR_WORKRESIST ); +#else + per = PerOffset + level + CHAR_getWorkInt( attackindex, CHAR_WORKFIXLUCK ) + - Df_Reg - fVitalP; +#endif //_SUIT_ADDENDUM +#ifdef _EQUIT_RESIST + if( status == CHAR_WORKWEAKEN ) + per -= CHAR_getWorkInt( defindex, CHAR_WORKEQUITWEAKEN ); + else if( status == CHAR_WORKBARRIER ) + per -= CHAR_getWorkInt( defindex, CHAR_WORKEQUITBARRIER ); + else if( status == CHAR_WORKNOCAST ) + per -= CHAR_getWorkInt( defindex, CHAR_WORKEQUITNOCAST ); +#endif //_EQUIT_RESIST +#ifdef _SUIT_ADDPART3 + if( status == CHAR_WORKWEAKEN ) + per -= CHAR_getWorkInt( defindex, CHAR_WORKRENOCAST ); +#endif + if( per > 80 )per = 80; + *pPer = per; + } + + if( RAND( 1, 100 ) < per ){ + return TRUE; + }else{ + return FALSE; + } +} + +//ְҵ״̬ж +int PROFESSION_BATTLE_StatusAttackCheck( int charaindex, int toindex, int status, int Success ) +{ + int rand_num = RAND( 1, 100 ); + int i; + + if( status >= BATTLE_ST_END || status <= 0 ) return 0; + if( CHAR_getInt( toindex , CHAR_HP) <= 0 ) return 0; + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == TRUE ) return 0; + +#ifdef _PROFESSION_ADDSKILL + if( status == BATTLE_ST_RESIST_F_I_T ){//Ȼ + if( CHAR_getWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_F] ) > 0 ) return 0; + if( CHAR_getWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_I] ) > 0 ) return 0; + if( CHAR_getWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_T] ) > 0 ) return 0; + return 1; + } +/* + if( status == CHAR_WORKICECRACK + || status == CHAR_WORKICECRACK2 + || status == CHAR_WORKICECRACK3 + || status == CHAR_WORKICECRACK4 + || status == CHAR_WORKICECRACK5 + || status == CHAR_WORKICECRACK6 + || status == CHAR_WORKICECRACK7 + || status == CHAR_WORKICECRACK8 + || status == CHAR_WORKICECRACK9 + || status == CHAR_WORKICECRACK10){ + return 1; + } +*/ +#endif + + for( i = 1; i < BATTLE_ST_END; i++ ){//쳣״̬return + if( CHAR_getWorkInt( toindex, StatusTbl[i] ) > 0 ) return 0; + } + + if( rand_num < Success ){ + return 1; + }else{ + return 0; + } +} + + + +int BATTLE_Combo( int battleindex, int *pAttackList, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int damage = 0, petdamage = 0, + attackindex, + toindex, + defindex, + ultimate = 0, + AllDamage = 0, + AllPetDamage = 0, + react = 0, + attackNo; + int flg = 0, iWork, par, i, DefSide = 0, + Guardian = -2; + BOOL iRet = FALSE; + + defindex = toindex = BATTLE_No2Index( battleindex, defNo ); + + //BATTLE_BroadCast( battleindex, "ɱ", + // (pAttackList[0] >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + for( i = 0; pAttackList[i] != -1 && i < BATTLE_ENTRY_MAX; i ++ ){ + attackNo = pAttackList[i]; + + defindex = toindex; + + flg = 0; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + if( CHAR_getInt( toindex, CHAR_HP ) <= 0 ){ + return FALSE; + } + + if( CHAR_getInt( attackindex, CHAR_HP ) <= 0 ){ + return FALSE; + } + + Guardian = -2; + iWork = BATTLE_AttackSeq( attackindex, toindex, &damage, + &Guardian, BATTLE_COM_COMBO ); + Guardian = -1; + if( damage <= 0 )damage = 1; + + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + + react = BATTLE_GetDamageReact( defindex ); + if( ( react == BATTLE_MD_REFLEC +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + || react == BATTLE_MD_TRAP +#endif +#ifdef _PETSKILL_ACUPUNCTURE + || react == BATTLE_MD_ACUPUNCTURE +#endif + ) && BATTLE_IsThrowWepon( CHAR_getItemIndex( attackindex, CHAR_ARM ) ) == FALSE ){ + + int refrect = 0; + BATTLE_DamageSub( attackindex, + defindex, &damage, &petdamage, &refrect ); + }else + if( react == BATTLE_MD_ABSROB + || react == BATTLE_MD_VANISH + ){ + int refrect = 0; + BATTLE_DamageSub( attackindex, + defindex, &damage, &petdamage, &refrect ); + }else{ + + BATTLE_DamageSubCale( attackindex, + defindex, &damage, &petdamage ); + AllDamage += damage; + AllPetDamage += petdamage; + } + + if( pAttackList[i+1] == -1 ){ + int refrect = -1; + ultimate = BATTLE_DamageSub2( attackindex, + defindex, &AllDamage, &AllPetDamage, &refrect ); + } + if( react == BATTLE_MD_REFLEC ){ + defindex = attackindex; + } +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + szBuffer[0] = 0; + switch( iWork ){ + + case BATTLE_RET_MISS: + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)Ĺ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_NORMAL; + iRet = TRUE; + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; + + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)(%s)CRITICAL(%d%%)(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // (int)(gCriper*0.01), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_KAISHIN; + iRet = FALSE; + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + break; + + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 + ){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + flg |= BCF_GUARD; + iRet = FALSE; + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else + + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY + && flg & BCF_KAISHIN + ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } +#ifdef _NOTRIDE_ + if( 0 <= Guardian && Guardian <= 19 ){ + iRet = FALSE; + flg |= BCF_GUARDIAN; + snprintf( szCommand, sizeof( szCommand ), + "a%X|f%X|d%X|g%X|", + attackNo, + flg, + damage, + Guardian ); + }else{ + snprintf( szCommand, sizeof( szCommand ), + "a%X|f%X|d%X|", + attackNo, + flg, + damage ); + } +#else + if( 0 <= Guardian && Guardian <= 19 ){ + iRet = FALSE; + flg |= BCF_GUARDIAN; + snprintf( szCommand, sizeof( szCommand ), + "a%X|f%X|d%X|p%X|g%X|", + attackNo, + flg, + damage, + petdamage, + Guardian ); + }else{ + snprintf( szCommand, sizeof( szCommand ), + "a%X|f%X|d%X|p%X|", + attackNo, + flg, + damage, + petdamage ); + } + +#endif + BATTLESTR_ADD( szCommand ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + defNo = BATTLE_Index2No( battleindex, defindex ); + + if( defNo >= SIDE_OFFSET ){ + iWork = defNo - SIDE_OFFSET; + DefSide = 1; + }else{ + iWork = defNo; + } + + iWork = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[iWork].flg |= BENT_FLG_ULTIMATE; + } + + } + + return iRet; +} + + + +int BATTLE_EarthRoundHide( int battleindex, int attackNo ) +{ + //char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, flg = 0 ; + + szCommand[0] = 0; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + sprintf( szCommand, "BF|%X|", attackNo ); + BATTLESTR_ADD( szCommand ); + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)Ƶȥ", + // CHAR_getUseName( attackindex ) + //); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + CHAR_setFlg( attackindex, CHAR_ISATTACKED, 0 ); + + CHAR_setWorkInt( attackindex, CHAR_WORKBATTLECOM1, + BATTLE_COM_S_EARTHROUND0 ); + + return ( flg )?(TRUE):(FALSE); + +} + + + +BOOL BATTLE_LostEscape( int battleindex, int attackNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, flg = FALSE, side, SubNo, + oyaindex, pno; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + + if( attackNo >= SIDE_OFFSET ){ + side = 1; SubNo = attackNo - SIDE_OFFSET; + }else{ + side = 0; SubNo = attackNo; + } + + oyaindex = CHAR_getWorkInt( attackindex, CHAR_WORKPLAYERINDEX ); + + pno = CHAR_getInt( oyaindex, CHAR_DEFAULTPET ); + if( pno < 0 )return FALSE; + +// print(" nonoϢ "); + + BATTLE_Exit( attackindex, battleindex ); + + CHAR_setInt( oyaindex, CHAR_DEFAULTPET, -1 ); + + CHAR_AddCharm( oyaindex, CH_FIX_PETESCAPE ); + + LogPet( + CHAR_getUseName( oyaindex ), + CHAR_getUseID( oyaindex ), + CHAR_getChar( attackindex, CHAR_NAME ), + CHAR_getInt( attackindex, CHAR_LV ), + + "EscapeLost(ս߲)", + + CHAR_getInt( oyaindex, CHAR_FLOOR ), + CHAR_getInt( oyaindex, CHAR_X ), + CHAR_getInt( oyaindex, CHAR_Y ), + CHAR_getChar( attackindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)ߵˡ", + // CHAR_getUseName( attackindex ) + //); + //if( getBattleDebugMsg( ) != 0 ){ + // BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + + sprintf( szCommand, "BQ|e%X|", attackNo ); + BATTLESTR_ADD( szCommand ); + + snprintf( szBuffer, sizeof( szBuffer ), "K%d", pno ); + + CHAR_sendStatusString( oyaindex, szBuffer ); + + + + return ( flg )?(TRUE):(FALSE); + + +} + +BOOL BATTLE_Abduct( + int battleindex, + int attackNo, + int defNo, + int array +) +{ + //char szBuffer[512]=""; + char szCommand[1024]; +#ifdef _BATTLE_ABDUCTII + char *pszP=NULL; +#endif + int attackindex, defindex, per, flg, attackoyaindex, defoyaindex = -1; + int attacklevel, deflevel; + int Attacktype, Deftype; + BOOL iRet = FALSE; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return iRet; + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return iRet; +#ifdef _BATTLE_ABDUCTII + // ȡó\ + pszP = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszP == "\0" ) return iRet; +#endif + + //ANDY_ReEdit + Attacktype = CHAR_getInt( attackindex, CHAR_WHICHTYPE); + + if( Attacktype == CHAR_TYPEENEMY ) + { + attackoyaindex = -1; + }else if( Attacktype == CHAR_TYPEPET ) { + attackoyaindex = CHAR_getWorkInt( attackindex, CHAR_WORKPLAYERINDEX ); + if( CHAR_CHECKINDEX( attackoyaindex ) == FALSE ) return iRet; + }else { + return iRet; + } + //ANDY_ReEdit + Deftype = CHAR_getInt( defindex, CHAR_WHICHTYPE ); + if( Deftype == CHAR_TYPEPET ){ + defoyaindex = CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX ); + if( CHAR_CHECKINDEX( defoyaindex ) == FALSE ) return iRet; + }else { + defoyaindex = -1; + } + + if( Deftype != CHAR_TYPEPLAYER ){ +#ifdef _BATTLE_ABDUCTII + int AiPer=0; + // ȡó\ + AiPer = atoi( pszP); + if( AiPer <= 0 || Deftype != CHAR_TYPEPET ){ +#endif + attacklevel = CHAR_getInt( attackindex, CHAR_LV ); + deflevel = CHAR_getInt( defindex, CHAR_LV ); + per = ( deflevel - attacklevel ) * 0.6 + 30; + per = max( per, 50 ); +#ifdef _BATTLE_ABDUCTII + }else { + per = 0; + if( CHAR_getWorkInt( defindex, CHAR_WORKFIXAI) < AiPer ){ + per = 200; + } + } +#endif + }else{ + per = 0; + return iRet; + } + if( BattleArray[battleindex].WinFunc != NULL ){ + per = 0; + } +#ifdef _ALLBLUES_LUA + else if( CHAR_getInt( BattleArray[battleindex].createindex, CHAR_WHICHTYPE ) == CHAR_TYPELUANPC ){ + per = 0; + } +#endif + iRet = TRUE; + if( RAND( 1, 100 ) < per ){ + flg = 1; + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)뿪ô(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // per + //); + if( Deftype == CHAR_TYPEPET ){ + BATTLE_PetDefaultExit( defoyaindex, battleindex ); + CHAR_setInt( defoyaindex, CHAR_DEFAULTPET, -1 ); + } + else if( Deftype == CHAR_TYPEENEMY ) + { + BATTLE_Exit( defindex, battleindex ); + } + }else{ + flg = 0; + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)޷(%s)һĬĬ뿪(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // per + //); + } + + //if( getBattleDebugMsg( ) != 0 ){ + // BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + sprintf( szCommand, "B!|a%X|d%X|f%X|", attackNo, defNo, flg ); + BATTLESTR_ADD( szCommand ); + + //ANDY_ReEdit + if( Attacktype == CHAR_TYPEPET ) { + BATTLE_PetDefaultExit( attackoyaindex, battleindex ); + CHAR_setInt( attackoyaindex, CHAR_DEFAULTPET, -1 ); + }else { + BATTLE_Exit( attackindex, battleindex); + } + return iRet; +} +#ifdef _BATTLESTEAL_FIX +void BATTLE_StealMoney( int battleindex, int attackNo, int defNo) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex, per; + int S_FLG = 0, GOLD = 0; + int LV=0; + char buf1[256]; + int masterindex; + int safeSide=0; + + if( BATTLE_CHECKINDEX( battleindex) == FALSE ) return; + attackindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return; + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return; + masterindex = CHAR_getWorkInt( attackindex, CHAR_WORKPLAYERINDEX ); + if( !CHAR_CHECKINDEX( masterindex ) ) return; + LV = CHAR_getInt( defindex, CHAR_LV ); + per = 0; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + if( attackNo > 10 ) { + safeSide = 1; + } + if( defNo>=safeSide*SIDE_OFFSET && defNo<((safeSide*SIDE_OFFSET)+SIDE_OFFSET)){//ͬ + per = 0; + }else { //ͬ + per = 50; + per = (((per+LV)/4)+10)>>1; + } + }else if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + per=5; + } + S_FLG = 0; + + + + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + if( CHAR_getInt( masterindex, CHAR_GOLD) >= CHAR_getMaxHaveGold( masterindex) ) + per = 0; + } + + if( RAND( 1, 100 ) < per ){ + S_FLG = 1; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + GOLD = CHAR_getInt( defindex, CHAR_GOLD ); + GOLD = (int)( (float)GOLD * RAND( 1, 15 ) * 0.01 ); + if( (CHAR_getInt( masterindex, CHAR_GOLD) + GOLD) >= CHAR_getMaxHaveGold( masterindex) ) { + GOLD = CHAR_getMaxHaveGold( masterindex) - CHAR_getInt( masterindex, CHAR_GOLD); + } + }else { + GOLD = RAND( 10, 100); + } + if( GOLD <= 0 ){ + S_FLG = 0; + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%d)STONE(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // GOLD, + // per + // ); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + CHAR_setInt( defindex, CHAR_GOLD, CHAR_getInt( defindex, CHAR_GOLD ) - GOLD ); + CHAR_send_P_StatusString( defindex, CHAR_P_STRING_GOLD ); + } + } + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)û(%s)ö(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // per + //); + } + sprintf( buf1, "͵һЩʯ"); + if( S_FLG) { + sprintf( szBuffer, "BK|%s%s|", CHAR_getUseName( defindex ), buf1 ); + strcat( szBadStatusString, szBuffer ); + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int attackoyaindex = CHAR_getWorkInt( attackindex, CHAR_WORKPLAYERINDEX ); + if( CHAR_CHECKINDEX( attackoyaindex ) == TRUE ){ + BATTLE_PetDefaultExit( attackoyaindex, battleindex ); + CHAR_setInt( attackoyaindex, CHAR_DEFAULTPET, -1 ); + { + int playergold=CHAR_getInt( attackoyaindex, CHAR_GOLD)+GOLD; + if( playergold > CHAR_getMaxHaveGold( attackoyaindex) ) playergold = CHAR_getMaxHaveGold( attackoyaindex); + CHAR_setInt( attackoyaindex, CHAR_GOLD , playergold); + CHAR_send_P_StatusString( attackoyaindex, CHAR_P_STRING_GOLD ); + } + lssproto_KS_send( getfdFromCharaIndex( attackoyaindex ), + CHAR_getInt( attackoyaindex, CHAR_DEFAULTPET ), 1 ); + } + BATTLE_Exit( attackindex, battleindex ); + }else{ + BATTLE_Exit( attackindex, battleindex ); + } + } + //if( getBattleDebugMsg( ) != 0 ) { + // BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + sprintf( szCommand, "B#|a%X|d%X|f%X|", attackNo, defNo, S_FLG ); + BATTLESTR_ADD( szCommand ); +} +#endif + +void BATTLE_Steal( int battleindex, int attackNo, int defNo ) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex, per, flg, i, j; + int enemytype, stealmode = 0, gold, itemindex; + int itemtbl[CHAR_MAXITEMNUM]; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE )return; + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( defindex ) == FALSE )return; + enemytype = CHAR_getInt( defindex, CHAR_WHICHTYPE ); + if( enemytype == CHAR_TYPEPLAYER ){ + per = 50; + }else{ + per = 0; + } + + if( RAND( 1, 100 ) < per ){ + flg = 1; + if( RAND( 1, 100 ) < 50 ){ + stealmode = 0; + gold = CHAR_getInt( defindex, CHAR_GOLD ); + gold = (int)( (float)gold * RAND( 8, 12 ) * 0.01 ); + if( gold <= 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)޷(%s)STONE(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // per + //); + flg = 0; + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%d)STONE(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gold, + // per + //); + CHAR_setInt( defindex, CHAR_GOLD, + CHAR_getInt( defindex, CHAR_GOLD ) - gold ); + CHAR_send_P_StatusString( defindex, CHAR_P_STRING_GOLD ); + } + }else{ + stealmode = 1; + for( j = 0, i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(defindex); i ++ ){ + itemindex = CHAR_getItemIndex( defindex, i ); + if( ITEM_CHECKINDEX( itemindex ) == TRUE ){ + itemtbl[j++] = i; + } + } + if( j <= 0 ){ + itemindex = -1; + }else{ + itemindex = -1; + i = RAND( 0, j-1 ); + if( i >= 0 ){ + if( 0 <= itemtbl[i] && itemtbl[i] < CHAR_STARTITEMARRAY ){ + fprint( "err:ҪȡװƷ(%d)\n", itemtbl[i] ); + }else{ + itemindex = CHAR_getItemIndex( defindex, itemtbl[i] ); + } + } + } + if( itemindex == - 1 ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)޷(%s)ĵ(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // per + //); + flg = 0; + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // ITEM_getAppropriateName( itemindex ), + // per + //); + CHAR_setItemIndex( defindex, itemtbl[i], -1 ); + CHAR_sendItemDataOne( defindex, itemtbl[i] ); + { + LogItem( + CHAR_getChar( defindex, CHAR_NAME ), + CHAR_getChar( defindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "Stealed(͵Եĵ)", + CHAR_getInt( defindex,CHAR_FLOOR), + CHAR_getInt( defindex,CHAR_X ), + CHAR_getInt( defindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + ITEM_endExistItemsOne( itemindex ); + } + } + }else{ + flg = 0; + //snprintf( szBuffer, sizeof(szBuffer), "(%s)û(%s)ö(%d%%)", + // CHAR_getUseName( attackindex ), CHAR_getUseName( defindex ), per ); + } + if( flg == 1 ){ + sprintf( szBuffer, "BK|%s͵һЩ|", + CHAR_getUseName( defindex ) ); + strcat( szBadStatusString, szBuffer ); + if( CHAR_getInt( attackindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int attackoyaindex = CHAR_getWorkInt( attackindex, CHAR_WORKPLAYERINDEX ); + if( CHAR_CHECKINDEX( attackoyaindex ) == TRUE ){ + BATTLE_PetDefaultExit( attackoyaindex, battleindex ); + CHAR_setInt( attackoyaindex, CHAR_DEFAULTPET, -1 ); + }else{ + BATTLE_Exit( attackindex, battleindex ); + } + }else{ + BATTLE_Exit( attackindex, battleindex ); + } + } + //if( getBattleDebugMsg( ) != 0 ){ + // BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + //} + sprintf( szCommand, "B#|a%X|d%X|f%X|", attackNo, defNo, flg ); + BATTLESTR_ADD( szCommand ); +} + +#ifdef _PSKILL_FALLGROUND // +int BATTLE_S_FallGround( int battleindex, int attackNo, int defNo, int skill_type) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex; + int damage=0, petdamage=0, i=0, iWork, Guardian=-1; + int flg = 0, DefSide=0,par,ultimate=0, react=0; + BOOL iRet = FALSE; + attackindex = BATTLE_No2Index( battleindex, attackNo ); //index + defindex = BATTLE_No2Index( battleindex, defNo ); //طindex + + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + react = 0; + react = BATTLE_GetDamageReact( defindex);//й⾵ + //ȡù״̬ + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, + &Guardian, BATTLE_COM_S_FALLRIDE ); + + + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + if( react == BATTLE_MD_REFLEC ) defindex = attackindex; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + + + + switch( iWork ){ + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + iRet = TRUE; + break; + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)չ(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_DODGE; + iRet = TRUE; + break; + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)ľ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + //andy_edit + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + iRet = TRUE; + break; + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)ܵ(%s)ľCRITICAL(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + flg |= BCF_KAISHIN; + iRet = FALSE; + flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + flg |= BCF_B_ARRANGE; + break; +#endif + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 ){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + iRet = FALSE; + } + + if( skill_type == BATTLE_COM_S_FALLRIDE && damage > 0 && react == 0 +#ifdef _PREVENT_TEAMATTACK + && BATTLE_CheckSameSide( attackindex, defNo) == 0 +#endif + ){ // + int fallflg = RAND( 0, 100); + if( +#ifdef _EQUIT_RESIST + fallflg > 50 + CHAR_getWorkInt( defindex, CHAR_WORKEQUITFALLRIDE ) +#else + fallflg > 50 +#endif + ){ + if( CHAR_getInt( defindex , CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { +#ifdef _FIXPETFALL //Syu ADD + if( CHAR_getInt( defindex, CHAR_RIDEPET) >= 0 ) { +#else + if( CHAR_getInt( defindex, CHAR_RIDEPET) > 0 ) { +#endif + flg |= BCF_FALL; + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + } + } +#ifdef _ENEMY_FALLGROUND + else if( CHAR_getInt( defindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + if( CHAR_getInt( defindex, CHAR_RIDEPET) > 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + + CHAR_setInt( defindex, CHAR_STR, CHAR_getInt( defindex, CHAR_STR)*0.7); + CHAR_setInt( defindex, CHAR_TOUGH, CHAR_getInt( defindex, CHAR_TOUGH)*0.7); + CHAR_setInt( defindex, CHAR_VITAL, CHAR_getInt( defindex, CHAR_VITAL)*0.7); + CHAR_complianceParameter( defindex ); + if( CHAR_getInt( defindex , CHAR_HP) > CHAR_getWorkInt( defindex , CHAR_WORKMAXHP ) ) { + CHAR_setInt( defindex , CHAR_HP , CHAR_getWorkInt( defindex , CHAR_WORKMAXHP ) ); + } + } + } +#endif + } + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY && flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + + BATTLESTR_ADD( szCommand ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + return iRet; +} +#endif +#ifdef _PETSKILL_EXPLODE +int BATTLE_S_Explode( int battleindex, int attackNo, int defNo, int skill_type) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex; + int damage=0, petdamage=0, i=0, iWork, Guardian=-1; + int flg = 0, DefSide=0,par,ultimate=0, react=0; + BOOL iRet = FALSE; + attackindex = BATTLE_No2Index( battleindex, attackNo ); //index + defindex = BATTLE_No2Index( battleindex, defNo ); //طindex + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + react = 0; + react = BATTLE_GetDamageReact( defindex);//й⾵ + //ȡù״̬ + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, + &Guardian, BATTLE_COM_S_EXPLODE ); + + if( damage > 0 ){ + damage = ( CHAR_getInt(defindex,CHAR_HP) >> 1 ); + flg |= BCF_EXPLODE; + CHAR_setInt( attackindex, CHAR_HP ,1); + } + + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react ); + if( react == BATTLE_MD_REFLEC ) defindex = attackindex; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + + switch( iWork ){ + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_MISS: + iRet = TRUE; + break; + case BATTLE_RET_DODGE: + flg |= BCF_DODGE; + iRet = TRUE; + break; + case BATTLE_RET_NORMAL: + flg |= BATTLE_getReactFlg( defindex, react); + flg |= BCF_NORMAL; + iRet = TRUE; + break; + case BATTLE_RET_CRITICAL: + flg |= BCF_KAISHIN; + iRet = FALSE; + flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + flg |= BCF_B_ARRANGE; + break; +#endif + } + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 ){ + strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + iRet = FALSE; + } + + if( skill_type == BATTLE_COM_S_EXPLODE && damage > 0 && react == 0 +#ifdef _PREVENT_TEAMATTACK + && BATTLE_CheckSameSide( attackindex, defNo) == 0 +#endif + ){ // + int fallflg = 100;//= RAND( 0, 100); + if( +#ifdef _EQUIT_RESIST + fallflg > 50 + CHAR_getWorkInt( defindex, CHAR_WORKEQUITFALLRIDE ) +#else + fallflg > 50 +#endif + ){ + if( CHAR_getInt( defindex , CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { +#ifdef _FIXPETFALL //Syu ADD + if( CHAR_getInt( defindex, CHAR_RIDEPET) >= 0 ) { +#else + if( CHAR_getInt( defindex, CHAR_RIDEPET) > 0 ) { +#endif + flg |= BCF_FALL; + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + } + } +#ifdef _ENEMY_FALLGROUND + else if( CHAR_getInt( defindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + if( CHAR_getInt( defindex, CHAR_RIDEPET) > 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + + CHAR_setInt( defindex, CHAR_STR, CHAR_getInt( defindex, CHAR_STR)*0.7); + CHAR_setInt( defindex, CHAR_TOUGH, CHAR_getInt( defindex, CHAR_TOUGH)*0.7); + CHAR_setInt( defindex, CHAR_VITAL, CHAR_getInt( defindex, CHAR_VITAL)*0.7); + CHAR_complianceParameter( defindex ); + if( CHAR_getInt( defindex , CHAR_HP) > CHAR_getWorkInt( defindex , CHAR_WORKMAXHP ) ) { + CHAR_setInt( defindex , CHAR_HP , CHAR_getWorkInt( defindex , CHAR_WORKMAXHP ) ); + } + } + } +#endif + } + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + ultimate = 1; + }else + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY && flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + ultimate = 1; + } + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) ultimate = 0; +#endif + iRet = FALSE; + flg |= BCF_DEATH; + if( ultimate == 1 ){ + flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate" ); + } + if( ultimate == 2 ){ + flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate" ); + } + } + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + + BATTLESTR_ADD( szCommand ); + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + return iRet; +} +#endif + +#ifdef _PRO_BATTLEENEMYSKILL +int BATTLE_E_ENEMYREFILE( int battleindex, int attackNo, int defNo, int skill_type ) +{ + int ReceveEffect; + BOOL iRet = FALSE; + int attackindex, defindex, pow, toNo; + + toNo=-1; + attackindex = BATTLE_No2Index( battleindex, attackNo); + + if( !CHAR_CHECKINDEX( attackindex) ) return iRet; + if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + int k=0, j=0, index; + int ToNoList[10]; + int l=0; + memset( ToNoList,-1, sizeof( ToNoList)); + + for( k=10;k<20;k++) { + index = BATTLE_getBattleDieIndex( battleindex, k); + if( !CHAR_CHECKINDEX( index) ) continue; + if( CHAR_getFlg( index, CHAR_ISDIE ) == TRUE ) { + ToNoList[j] = k; + j++; + } + } + if( j == 0 ) return iRet; + toNo = ToNoList[ l=RAND( 0, j-1)]; + if( toNo < 0 || toNo > 20 ) + return iRet; + }else if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + toNo = defNo; + }else { + return iRet; + } + if( !BATTLE_CHECKNO( toNo) ) return iRet; + ReceveEffect = SPR_fukkatu1; + defindex = BATTLE_No2Index( battleindex, toNo); + if( !CHAR_CHECKINDEX( defindex) ) return iRet; + pow = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP)/2; + BATTLE_MultiRessurect( battleindex, attackNo, toNo, + pow, 0, SPR_item3, ReceveEffect ); + iRet = TRUE; + + return iRet; +} + +int BATTLE_E_ENEMYREHP( int battleindex, int attackNo, int defNo, int skill_type) +{ + BOOL iRet=FALSE; + int attackindex, defindex; + int power = 0, per = 0, HealedEffect, toNo=-1; + int kind; + + attackindex = BATTLE_No2Index( battleindex, attackNo); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return iRet; + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_INIT || + !CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEMODE ) ){ + return iRet; + } + + if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + int k=0, j=0, l, index; + int ToNoList[10]; + memset( ToNoList,-1, sizeof( ToNoList)); + for( k=10;k<20;k++) { + index = BATTLE_No2Index( battleindex, k); + if( !CHAR_CHECKINDEX( index) ) continue; + if( CHAR_getInt( index, CHAR_HP) <= 0 ) continue; + if( CHAR_getInt( index, CHAR_HP) < (CHAR_getWorkInt( index, CHAR_WORKMAXHP) *2/3)) { + ToNoList[j] = k; + j++; + } + } + if( j == 0 ) return iRet; + toNo = ToNoList[ l=RAND( 0, j-1)]; + if( toNo < 0 || toNo > 20 ) + return iRet; + + }else if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + toNo = defNo; + }else { + return iRet; + } + defindex = BATTLE_No2Index( battleindex, toNo); + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return iRet; + + kind = 0; + power = RAND( 100, CHAR_getWorkInt( defindex, CHAR_WORKMAXHP)); + HealedEffect = SPR_heal2; + BATTLE_MultiRecovery( battleindex, attackNo, toNo,kind, power, per, SPR_item3, HealedEffect ); + + iRet = TRUE; + return iRet; +} + +int BATTLE_E_ENEMYHELP( int battleindex, int attackNo, int defNo, int skill_type ) +{ + BOOL iRet = FALSE; + int attackindex, enindex, array; + int Side=-1, LV, i, enemynum, PetID; + //char szBuffer[256]=""; + print("\n BATTLE_E_ENEMYHELP()"); + + attackindex = BATTLE_No2Index( battleindex, attackNo); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return iRet; + if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) != CHAR_TYPEENEMY || + BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P || + CHAR_getInt( attackindex , CHAR_HP) <= 0 ) { + return iRet; + } + + if( CHAR_getInt( attackindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) { + int k=0, index; + int ToNoList[10]; + memset( ToNoList,-1, sizeof( ToNoList)); + for( k=10;k<20;k++) { + index = BATTLE_No2Index( battleindex, k); + if( !CHAR_CHECKINDEX( index) ) { + break; + } + } + if( k == 20 ) return iRet; + } + LV = CHAR_getInt( attackindex, CHAR_LV ); + + PetID = CHAR_getInt( attackindex, CHAR_PETID ); + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + //if( ENEMY_getInt( i, ENEMY_ID ) == PetID ) + if( ENEMY_getInt( i, ENEMY_TEMPNO ) == PetID ) + break; + } + if( i == enemynum ) + return iRet; + array = i; + + Side = CHAR_getWorkInt( attackindex, CHAR_WORKBATTLESIDE ); + enindex = ENEMY_createEnemy( array, RAND( (LV*0.8), LV*1.2)); + if( !CHAR_CHECKINDEX( enindex ) ) return iRet; + if( BATTLE_NewEntry( enindex, battleindex, Side) ) { + //CHAR_setWorkInt( enindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_RESCUE ); + CHAR_setWorkInt( enindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + //snprintf( szBuffer, sizeof( szBuffer ), "(%s)ս", + // CHAR_getUseName( enindex ) ); + //BATTLE_BroadCast( battleindex, szBuffer, CHAR_COLORYELLOW ); + }else { + + } + iRet = TRUE; + return iRet; + +} + +#endif + +int BATTLE_DefineAttack( int attackindex, int defindex, int iWork, + char *szBuffer, int damage, int react, int *flg) +{ + int iRet; + int par; + iRet = TRUE; + par = BATTLE_AttrAdjust( attackindex, defindex, 100 ); + switch( iWork ){ + case BATTLE_RET_ALLGUARD: + case BATTLE_RET_MISS: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s),ûС", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ) + //); + iRet = TRUE; + break; + case BATTLE_RET_DODGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)չ(%s)㿪(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + *flg |= BCF_DODGE; + iRet = TRUE; + break; + case BATTLE_RET_NORMAL: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܵ(%s)ľ(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + + *flg |= BATTLE_getReactFlg( defindex, react); + *flg |= BCF_NORMAL; + iRet = TRUE; + break; + case BATTLE_RET_CRITICAL: + //snprintf( szBuffer, sizeof(szBuffer), + //"(%s)ܵ(%s)ľCRITICAL(%d)(%d:%d:%d%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // damage, + // CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ), + // CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ), + // par + //); + *flg |= BCF_KAISHIN; + iRet = FALSE; + *flg |= BATTLE_getReactFlg( defindex, react); + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE: + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%.2f%%)", + // CHAR_getUseName( attackindex ), + // CHAR_getUseName( defindex ), + // gDuckPer + //); + *flg |= BCF_B_ARRANGE; + break; +#endif + } + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_GUARD + && CHAR_getWorkInt( defindex, CHAR_WORKCONFUSION ) <= 0 ){ + //strncat( szBuffer, "(GUARD)", sizeof( szBuffer ) ); + iRet = FALSE; + } + + return iRet; +} + +int BATTLE_DefDieType( int defindex, int iRet, int *ultimate, int *flg, char *szBuffer) +{ + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO ){ + *ultimate = 1; + }else + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEENEMY && *flg & BCF_KAISHIN ){ + if( RAND( 1, 100 ) < 50 ){ + *ultimate = 1; + } + } + +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) *ultimate = 0; +#endif + iRet = FALSE; + *flg |= BCF_DEATH; + if( *ultimate == 1 ){ + *flg |= BCF_ULTIMATE_1; + strcat( szBuffer, "ultimate?" ); + } + if( *ultimate == 2 ){ + *flg |= BCF_ULTIMATE_2; + strcat( szBuffer, "ultimate?" ); + } + } + return iRet; +} + +#ifdef _SKILL_DAMAGETOHP +int BATTLE_S_DamageToHp( int battleindex, int attackindex, int defindex, int Damage, int skill) +{ + char *pszOption; + char buf1[256]; + int A_HP=0, pHP,defi=0; + float def=0.00; + if( Damage < 1 ) return A_HP; + if( BATTLE_GetDamageReact( defindex) > 0 )//й⾵ + return A_HP; + + pszOption = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( pszOption == "\0" ) + return A_HP; + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( pszOption, "|",2, buf1,sizeof( buf1)) == FALSE ) + return A_HP; + + defi = atoi( buf1); + def = ((float)defi)/100; + A_HP = (int)(Damage*def); + if( (A_HP+CHAR_getInt( attackindex, CHAR_HP)) > CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP ) ){ + A_HP = CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP )-CHAR_getInt( attackindex, CHAR_HP); + } + + pHP = CHAR_getInt( attackindex, CHAR_HP) + A_HP; + CHAR_setInt( attackindex, CHAR_HP, min( pHP, CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP ))); + CHAR_send_P_StatusString( attackindex, CHAR_P_STRING_HP); + return A_HP; +} +#endif + +#ifdef _PETSKILL_DAMAGETOHP +int BATTLE_S_DamageToHp2( int battleindex, int attackindex, int defindex, int Damage, int skill) +{ + char *pszOption; + char buf1[256]; + int A_HP=0, pHP,defi=0; + float def=0.00; + if( Damage < 1 ) return A_HP; + if( BATTLE_GetDamageReact( defindex) > 0 )//й⾵ + return A_HP; + + pszOption = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( pszOption == "\0" ) + return A_HP; + memset( buf1, 0, sizeof( buf1)); + sprintf(buf1,"%s",pszOption); + //if( getStringFromIndexWithDelim( pszOption, "|",2, buf1,sizeof( buf1)) == FALSE ) + // return A_HP; + + defi = atoi( buf1); + def = ((float)defi)/100; + A_HP = (int)(Damage*def); + if( (A_HP+CHAR_getInt( attackindex, CHAR_HP)) > CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP ) ){ + A_HP = CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP )-CHAR_getInt( attackindex, CHAR_HP); + } + //print("\n:%d Ѫ:%d",Damage,A_HP); + pHP = CHAR_getInt( attackindex, CHAR_HP) + A_HP; + CHAR_setInt( attackindex, CHAR_HP, min( pHP, CHAR_getWorkInt( attackindex, CHAR_WORKMAXHP ))); + CHAR_send_P_StatusString( attackindex, CHAR_P_STRING_HP); + return A_HP; +} +#endif + +#ifdef _Skill_MPDAMAGE //BATTLE_COM_S_MPDAMAGE +int BATTLE_S_MpDamage( int battleindex, int attackindex, int defindex, int damage, int skill) +{ + char *pszOption; + char buf1[256]; + int D_MP=0,defi=0; + float def=0.00; + if( damage < 1 ) return D_MP; + if( BATTLE_GetDamageReact( defindex) > 0 )//й⾵ + return D_MP; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE) == CHAR_TYPEENEMY || + CHAR_getInt( defindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ) + return D_MP; + if( CHAR_getInt( defindex, CHAR_MP) <= 0 ) return D_MP; + + pszOption = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( pszOption == "\0" ) return D_MP; + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( pszOption, "|",2, buf1,sizeof( buf1)) == FALSE ) + return D_MP; + defi = atoi( buf1); + def = ((float)defi)/100; + D_MP = (int)(CHAR_getInt( defindex, CHAR_MP)*def); + CHAR_setInt( defindex, CHAR_MP, ( CHAR_getInt( defindex, CHAR_MP) - D_MP) ); + CHAR_send_P_StatusString( defindex, CHAR_P_STRING_MP); + return D_MP; +} +#endif +#ifdef _SKILL_TOOTH +void BATTLE_S_ToothCrushe( int battleindex, int attackindex, int defindex, int damage, int skill) +{ + + //char *strCrushTbl[] = { "", "", "ٻ" , "ʹ" , "Ƭ" }; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER +#ifdef _TAKE_ITEMDAMAGE_FOR_PET + && CHAR_getInt( defindex, CHAR_WHICHTYPE) == CHAR_TYPEPET +#endif + ) + return; +#ifdef _TAKE_ITEMDAMAGE + int crushindex, itemindex; //aszCrushTbl + if( ( crushindex = BATTLE_ItemCrushCheck( defindex, 1) ) >= 0 ) { + int crushenum, maxcrushenum, level=0; + float def=0.00; + itemindex = CHAR_getItemIndex( defindex, crushindex ); + if( ITEM_CHECKINDEX(itemindex) == FALSE ) return; + crushenum = ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE); + maxcrushenum = ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE); + if( maxcrushenum < 1 ) return; + def = ((float)crushenum/maxcrushenum); + if( def >= 1 ) { + level = 1; + def = 0.70; + }else if( def >= 0.50 ){ + level = 2; + def = 0.30; + }else if( def >= 0.30 ){ + level = 3; + def = 0.10; + }else{ + def = 0.00; + } + crushenum = (int)((float)maxcrushenum*def); + ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, crushenum); + + if( crushenum <= 0 ) { + char buf2[256]; + sprintf(buf2, "%s𻵶ʧ\n", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( defindex, -1, buf2, CHAR_COLORYELLOW); + + LogItem( + CHAR_getChar( defindex, CHAR_NAME ), + CHAR_getChar( defindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "𻵶ʧ", + CHAR_getInt( defindex,CHAR_FLOOR), + CHAR_getInt( defindex,CHAR_X ), + CHAR_getInt( defindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + + CHAR_setItemIndex( defindex, crushindex ,-1); + ITEM_endExistItemsOne( itemindex); + + }else { + char buf2[256]; + sprintf( buf2, "%s%sġ", ITEM_getChar( itemindex, ITEM_NAME ), aszCrushTbl[level] ); + CHAR_talkToCli( defindex, -1, buf2, CHAR_COLORYELLOW); + //ĵ˵ +// buf1 = ITEM_getChar( itemindex, ITEM_SECRETNAME); +// if( strstr( buf1, "(") != 0 ) { +// char buf5[256]; +// if( getStringFromIndexWithDelim( buf1,"(",1, buf5, sizeof( buf5)) != FALSE ) { +// sprintf( buf1, buf5); +// } +// } +// sprintf( buf2, "%s(%s)", buf1, aszCrushTbl[level]); +// ITEM_setChar( itemindex, ITEM_SECRETNAME, buf2); + ITEM_setInt( itemindex, ITEM_CRUSHLEVEL, level); + } + CHAR_sendItemDataOne( defindex, crushindex ); + CHAR_complianceParameter( defindex ); + CHAR_send_P_StatusString( defindex, CHAR_P_STRING_ATK | CHAR_P_STRING_DEF + | CHAR_P_STRING_QUICK | CHAR_P_STRING_CHARM ); + + } +#endif +} +#endif + +#ifdef _PSKILL_MODIFY +void BATTLE_S_Modifyattack( int battleindex, int attackindex, int defindex, int *damage, int skill) +{ + int i; + char *pszOption=NULL; + int array = skill; + char buf1[256], buf2[256]; + float def=0.00; + struct tagModKind{ + char szModKind[36]; + int Kind; + }KModKind[5] = { + { "EA", CHAR_EARTHAT}, { "WA", CHAR_WATERAT}, + { "FI", CHAR_FIREAT} , { "WI", CHAR_WINDAT}, + { "ALL",100} + }; + + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return; + + if( getStringFromIndexWithDelim( pszOption, "|", 2, buf2, sizeof( buf1)) == FALSE ) + return; + def = ((float)(atoi( buf2))/100); + + for( i=0; i< 4; i++) { + int ModNum=0; + if( strcmp( KModKind[i].szModKind , buf1)) continue; + if( (ModNum = CHAR_getInt( defindex, KModKind[i].Kind )) > 0 ) { + def += (float)((rand()%(ModNum+5))/100); + *damage += *damage * def; + break; + } + } +} +#endif + +#ifdef _PETSKILL_PROPERTY +int BATTLE_S_PetSkillProperty( int battleindex, int attackNo, int skill_type, int skill) +{ + int attackindex; + BOOL iRet = FALSE; + char *pszP=NULL; + + pszP = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( pszP == "\0" ) return iRet; + + + attackindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( attackindex)) return iRet; + switch( skill_type){ + case BATTLE_COM_S_PROPERTYSKILL: + { + Char *ch; + ch = CHAR_getCharPointer( attackindex); + if( ch == NULL ) return iRet; + strcpysafe( ch->charfunctable[CHAR_BATTLEPROPERTY].string, + sizeof( ch->charfunctable[CHAR_BATTLEPROPERTY]), pszP);//ս + CHAR_constructFunctable( attackindex); + iRet = TRUE; + } + break; + } + return iRet; +} +#endif + +int BATTLE_S_AttackDamage( int battleindex, int attackNo, int defNo, int skill_type, int skill) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex; + int damage=0, petdamage=0, i=0, iWork, Guardian=-1,react; + int flg = 0, DefSide=0,ultimate=0; + int otherdamage=0; + BOOL iRet = FALSE; + int ReactType = 0; + + char *pszP=NULL; + pszP = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( pszP == "\0" ) return iRet; + + react = 0; + attackindex = BATTLE_No2Index( battleindex, attackNo ); //index + defindex = BATTLE_No2Index( battleindex, defNo ); //طindex + if( (ReactType=BATTLE_GetDamageReact( defindex)) > 0 ){ //й⾵ + react = ReactType; +#ifdef _BATTLE_LIGHTTAKE + if( skill_type == BATTLE_COM_S_LIGHTTAKE ){ + int Statustype = -2; + if( strstr( pszP, "VANISH") != 0 ) Statustype = BATTLE_MD_VANISH; + else if( strstr( pszP, "ABSROB") != 0 ) Statustype = BATTLE_MD_ABSROB; + else if( strstr( pszP, "REFLEC") != 0 ) Statustype = BATTLE_MD_REFLEC; + if( ReactType == Statustype ){ + react=0; + }else{ + skill_type=-1; + } + }else{ + skill_type=-1; + } +#else + skill_type=-1; +#endif + } + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + + //ȡù״̬ + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, &Guardian, skill_type ); + + switch( skill_type){ +#ifdef _PSKILL_MODIFY + case BATTLE_COM_S_MODIFYATT: + if( damage > 0 ){ + BATTLE_S_Modifyattack( battleindex, attackindex, defindex, &damage, skill); + } + break; +#endif +#ifdef _PETSKILL_TEAR + case BATTLE_COM_S_PETSKILLTEAR: +#ifdef _PREVENT_TEAMATTACK + if( BATTLE_CheckSameSide( attackindex, defNo) == 1 ){ + }else +#endif + if( iWork != BATTLE_RET_DODGE && react == 0 ){ + int userhp=0, petindex; + float def=0; + userhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP) - CHAR_getInt( defindex, CHAR_HP); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + (petindex = BATTLE_getRidePet( defindex )) != -1 ){ + userhp += CHAR_getWorkInt( petindex, CHAR_WORKMAXHP) - CHAR_getInt( petindex, CHAR_HP); + } + def = ((float)atoi( pszP))/100; + userhp = userhp * def; + if( userhp <= 0 ) damage = 0; + else damage += userhp; + } + break; +#endif + } + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react); + + if( react == BATTLE_MD_REFLEC ) defindex = attackindex; + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + iRet = BATTLE_DefineAttack( attackindex, defindex, iWork, szBuffer, damage, react, &flg); + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ) + iRet = BATTLE_DefDieType( defindex, iRet, &ultimate, &flg, szBuffer); +#ifdef _PETSKILL_ANTINTER + //ǿƽij + if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ANTINTER + && CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + ultimate = 2; + flg &= (!BCF_ULTIMATE_1); + flg |= BCF_DEATH; + flg |= BCF_ULTIMATE_2; + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + damage=1;//ж damage<=0 skill_type=-1 damageΪ1 + } +#endif + + if( damage > 0 ){ +#ifdef _TAKE_ITEMDAMAGE + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ){ +#else + if( BATTLE_ItemCrushSeq( defindex ) == TRUE ){ +#endif + flg |= BCF_CRUSH; + } + } + + if( damage <= 0 ) { +#ifdef _SONIC_ATTACK // WON ADD + if( skill_type != BATTLE_COM_S_SONIC && skill_type != BATTLE_COM_S_SONIC2 +#ifdef _PETSKILL_REGRET + && skill_type != BATTLE_COM_S_REGRET && skill_type != BATTLE_COM_S_REGRET2 +#endif + ) +#endif + skill_type=-1; + } + + + + + memset( szCommand, 0, sizeof( szCommand)); + switch( skill_type) { + case -1: + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + break; + +#ifdef _PETSKILL_TEAR + case BATTLE_COM_S_PETSKILLTEAR: + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _SKILL_DAMAGETOHP + case BATTLE_COM_S_DAMAGETOHP: + otherdamage = BATTLE_S_DamageToHp( battleindex, attackindex, defindex,damage+petdamage, skill); + snprintf( szCommand, sizeof( szCommand ), "Bh|a%X|r%X|f%X|d%X|p%X|j%X|FF|", + attackNo, defNo, flg, damage, petdamage, otherdamage); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _PETSKILL_DAMAGETOHP + case BATTLE_COM_S_DAMAGETOHP2: + otherdamage = BATTLE_S_DamageToHp2( battleindex, attackindex, defindex,damage+petdamage, skill); + snprintf( szCommand, sizeof( szCommand ), "Bh|a%X|r%X|f%X|d%X|p%X|j%X|FF|", + attackNo, defNo, flg, damage, petdamage, otherdamage); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _Skill_MPDAMAGE + case BATTLE_COM_S_MPDAMAGE: + otherdamage = BATTLE_S_MpDamage( battleindex, attackindex, defindex, damage, skill); + snprintf( szCommand, sizeof( szCommand ), "Bp|a%X|r%X|f%X|d%X|p%X|j%X|FF|", + attackNo, defNo, flg, damage, petdamage, otherdamage); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _SKILL_TOOTH + case BATTLE_COM_S_TOOTHCRUSHE: //ܳ tooth + flg |= BCF_TOOTH; + BATTLE_S_ToothCrushe( battleindex, attackindex, defindex, damage, skill); + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _PSKILL_MDFYATTACK + case BATTLE_COM_S_MDFYATTACK: + flg |= BCF_MODIFY; + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|g%X|FF|", + attackNo, defNo, flg, damage, petdamage, skill); + BATTLESTR_ADD( szCommand ); + break; +#endif +#ifdef _PSKILL_MODIFY + case BATTLE_COM_S_MODIFYATT: + flg |= BCF_ATTDOUBLE; + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|g%X|FF|", + attackNo, defNo, flg, damage, petdamage, skill); + BATTLESTR_ADD( szCommand ); + break; +#endif + +#ifdef _PETSKILL_TIMID + case BATTLE_COM_S_TIMID: + { + int timid = rand()%100; + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + if( timid < 15 && damage > 1 ){//ս + BATTLE_NoAction( battleindex, defNo ); + sprintf( szCommand, "BE|e%X|", defNo ); + BATTLESTR_ADD( szCommand ); + snprintf( szCommand, sizeof( szCommand ), "f%X|", 1); + BATTLESTR_ADD( szCommand ); + + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int defkoyaindex = CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX ); +#ifdef _PETS_SELECTCON + lssproto_PETS_send( getfdFromCharaIndex(defkoyaindex), + CHAR_getInt( defkoyaindex, CHAR_DEFAULTPET), FALSE); + CHAR_setWorkInt( defkoyaindex, + CHAR_WORK_PET0_STAT+CHAR_getInt( defkoyaindex, CHAR_DEFAULTPET), FALSE); +#endif + BATTLE_PetDefaultExit( defkoyaindex, battleindex ); + CHAR_setInt( defkoyaindex, CHAR_DEFAULTPET, -1 ); + + }else { + BATTLE_Exit( defindex, battleindex); + CHAR_DischargePartyNoMsg( defindex);//ɢŶ + } + } + } + break; +#endif +#ifdef _PETSKILL_2TIMID + case BATTLE_COM_S_2TIMID: + { + int timid=0; + char *timidc=NULL; + pszP = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( ( timidc = strstr( pszP, "%" ) ) != NULL ) + sscanf( timidc+3,"%d", &timid ); + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + if( rand()%100 < timid && damage > 1 ){ + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int defkoyaindex = CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX ); + + snprintf( szCommand, sizeof( szCommand ), "K%d", CHAR_getInt( defkoyaindex, CHAR_DEFAULTPET ) ); + CHAR_sendStatusString( defkoyaindex, szCommand ); + + BATTLE_PetIn( battleindex, defNo-5 ); + lssproto_KS_send( getfdFromCharaIndex( defkoyaindex ), CHAR_getInt( defkoyaindex, CHAR_DEFAULTPET ), 1 ); + + /*BATTLE_NoAction( battleindex, defNo ); + sprintf( szCommand, "BE|e%X|", defNo ); + BATTLESTR_ADD( szCommand ); + snprintf( szCommand, sizeof( szCommand ), "f%X|", 1); + BATTLESTR_ADD( szCommand ); + + BATTLE_PetDefaultExit( defkoyaindex, battleindex ); + CHAR_setInt( defkoyaindex, CHAR_DEFAULTPET, -1 ); + + print("\ndefNo:%d",defNo);*/ + } + } + } + break; +#endif + +#ifdef _PETSKILL_ANTINTER + case BATTLE_COM_S_ANTINTER: + { + pszP = PETSKILL_getChar( skill, PETSKILL_OPTION ); + //flg &= !(BCF_ULTIMATE_1 | BCF_ULTIMATE_2); + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg |= BCF_ANTINTER , 0, 0 ); + BATTLESTR_ADD( szCommand ); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + int defkoyaindex = CHAR_getWorkInt( defindex, CHAR_WORKPLAYERINDEX ); + BATTLE_PetDefaultExit( defkoyaindex, battleindex );//뿪ս + CHAR_setInt( defkoyaindex, CHAR_DEFAULTPET, -1 );//趨޲ս + } + } + break; +#endif + +#ifdef _BATTLE_LIGHTTAKE + case BATTLE_COM_S_LIGHTTAKE: + { + int Typenum = 0; + pszP = PETSKILL_getChar( skill, PETSKILL_OPTION ); + if( strstr( pszP, "VANISH") != 0 ){ + if( ReactType == BATTLE_MD_VANISH ){ + Typenum = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ); + CHAR_setWorkInt( attackindex, CHAR_WORKDAMAGEVANISH, Typenum + 1); + } + }else if( strstr( pszP, "ABSROB") != 0 ){ + if( ReactType == BATTLE_MD_ABSROB ){ + Typenum = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEABSROB ); + CHAR_setWorkInt( attackindex, CHAR_WORKDAMAGEABSROB, Typenum + 1); + } + }else if( strstr( pszP, "REFLEC") != 0 ){ + if( ReactType == BATTLE_MD_REFLEC ){ + Typenum = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ); + CHAR_setWorkInt( attackindex, CHAR_WORKDAMAGEREFLEC, Typenum + 1); + } + } + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + } + break; +#endif + +#ifdef _SONIC_ATTACK // WON ADD + // ˺ + case BATTLE_COM_S_SONIC: + { + int img2=0; + if( defNo >= 10 ) img2 = 101703; + else img2 = 101704; + + flg |= BCF_B_SKILLACT; //ͼ + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, damage, 0, 0, img2 ); + BATTLESTR_ADD( szCommand ); + + break; + } + // ˺ + case BATTLE_COM_S_SONIC2: + { + sprintf( szCommand, "BD|r%X|0|0|d%X|p%X|", defNo, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + + break; + } +#endif +#ifdef _PETSKILL_REGRET + // ˺ + case BATTLE_COM_S_REGRET: + { + int img2=0,Success=0; + char *psz = NULL; + if( (psz = strstr( pszP, "%" ) ) != NULL ) sscanf( psz+3, "%d", &Success ); + if( (PROFESSION_BATTLE_StatusAttackCheck( attackindex, defindex, 12, Success ) == 0 ) + || (CHAR_getInt( defindex, CHAR_HP ) <= 0 ) ){ + + }else{ + CHAR_setWorkInt( defindex, StatusTbl[12], 2 );//ѣ1غ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + BATTLE_BadStatusString( defNo, 12 ); + } + + if( defNo >= 10 ) img2 = 101418;//101703; + else img2 = 101418;//101704; + + flg |= BCF_B_SKILLACT; //ͼ + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, damage, 0, 0, img2 ); + BATTLESTR_ADD( szCommand ); + break; + } + // ˺ + case BATTLE_COM_S_REGRET2: + { + int Success; + char *psz = NULL; + if( (psz = strstr( pszP, "%" ) ) != NULL ) sscanf( psz+3, "%d", &Success ); + if( (PROFESSION_BATTLE_StatusAttackCheck( attackindex, defindex, 12, Success ) == 0 ) + || (CHAR_getInt( defindex, CHAR_HP ) <= 0 ) ){ + + }else{ + CHAR_setWorkInt( defindex, StatusTbl[12], 2 );//ѣ1غ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + BATTLE_BadStatusString( defNo, 12 ); + } + + sprintf( szCommand, "BD|r%X|0|0|d%X|p%X|", defNo, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + break; + } +#endif + + default: + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", + attackNo, defNo, flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + break; + } + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + return iRet; +} + +#ifdef _MAGIC_SUPERWALL +int PETSKILL_MagicStatusChange_Battle( int battleindex, int attackNo, int toNo, int marray) +{ + char *magicarg; + int status = -1, i, turn = 3, nums=0; + int ReceveEffect, charaindex=-1; + char buf1[256]; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( charaindex)) return FALSE; + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( getStringFromIndexWithDelim( magicarg,"|",1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + for( i=0; i= 20 ) + return FALSE; + } + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + //attackNo = BATTLE_Index2No( battleindex, charaindex ); +/* //ͼž + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; + }else{ + ReceveEffect = SPR_hoshi; + } +*/ + ReceveEffect = SPR_hoshi; + BATTLE_MultiMagicStatusChange( + battleindex, attackNo, toNo, status, + turn, MAGIC_EFFECT_USER, ReceveEffect, nums ); + + return TRUE; +} +#endif + +#ifdef _PETSKILL_SETDUCK +int PETSKILL_SetDuckChange_Battle( int battleindex, int attackNo, int toNo, int marray) +{ + char *skillarg=NULL; + int turn = 3, nums=0; + int charaindex=-1; + char buf1[256]; + + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( charaindex)) return FALSE; + if( BATTLE_No2Index( battleindex, toNo ) != charaindex ) return FALSE; + + skillarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( skillarg == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( skillarg,"|",1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + turn = atoi( buf1); + if( getStringFromIndexWithDelim( skillarg,"|",2, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + nums = atoi( buf1); + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + { + int ToList[SIDE_OFFSET*2+1]; + char szBuffer[256]=""; + memset( szBuffer, 0, sizeof( szBuffer)); + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, toNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi ); + if( CHAR_getWorkInt( charaindex, CHAR_MYSKILLDUCK) > 0){ + }else { + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCK, turn); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER, nums ); + sprintf( szBuffer, "BD|r%X|0|3|%X|", toNo, nums); + BATTLESTR_ADD( szBuffer ); + } + } + return TRUE; +} +#endif + +#ifdef _MAGICPET_SKILL +int PETSKILL_SetMagicPet_Battle( int battleindex, int attackNo, int toNo, int marray) +{ + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return FALSE; + char *skillarg=NULL; + int turn = 3, nums=0; + int charaindex=-1; + char buf1[256]; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( charaindex)) return FALSE; + + skillarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( skillarg == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( skillarg,"|",1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + turn = atoi( buf1); + if( getStringFromIndexWithDelim( skillarg,"|",2, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + nums = atoi( buf1); + if( getStringFromIndexWithDelim( skillarg,"|",3, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + if( strstr( buf1, "HP") != 0 ) { + BATTLE_MultiRecovery( battleindex, attackNo, toNo, + BD_KIND_HP, nums, 0, MAGIC_EFFECT_USER, SPR_heal3 ); + }else{ + int ToList[SIDE_OFFSET*2+1]; + char szBuffer[256]=""; + int todef=0, i; + + memset( szBuffer, 0, sizeof( szBuffer)); + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, toNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi ); + + for( i = 0; ToList[i] != -1; i ++ ){ + int bid; + int toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( !CHAR_CHECKINDEX( toindex ))continue; + + if( CHAR_getWorkInt( toindex, CHAR_MYSKILLDUCK) > 0 || + CHAR_getWorkInt( toindex, CHAR_MYSKILLSTR) > 0 || + CHAR_getWorkInt( toindex, CHAR_MYSKILLTGH) > 0 || + CHAR_getWorkInt( toindex, CHAR_MYSKILLDEX) > 0 ) continue; + + if( strstr( buf1, "STR") != 0 ) { + CHAR_setWorkInt( toindex, CHAR_MYSKILLSTR, turn); + CHAR_setWorkInt( toindex, CHAR_MYSKILLSTRPOWER, nums ); + todef = 4; + }else if( strstr( buf1, "TGH") != 0 ){ + CHAR_setWorkInt( toindex, CHAR_MYSKILLTGH, turn); + CHAR_setWorkInt( toindex, CHAR_MYSKILLTGHPOWER, nums ); + todef = 5; + }else if( strstr( buf1, "DEX") != 0 ){ + CHAR_setWorkInt( toindex, CHAR_MYSKILLDEX, turn); + CHAR_setWorkInt( toindex, CHAR_MYSKILLDEXPOWER, nums ); + todef = 6; + } + bid = BATTLE_Index2No( battleindex, toindex ); + sprintf( szBuffer, "BD|r%X|0|%d|%X|", bid, todef, nums); + BATTLESTR_ADD( szBuffer ); + } + } + return TRUE; +} +#endif + + +#ifdef _STRENGTH_PETSKILL +int PETSKILL_SetStrength_Battle( int battleindex, int attackNo, int toNo, int marray) +{ + char *skillarg=NULL; + int charaindex=-1; + char buf1[256]; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return FALSE; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( charaindex)) return FALSE; + + skillarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + + if( getStringFromIndexWithDelim( skillarg,"|",2, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + if( strstr( buf1, "HP") != 0 ) { + BATTLE_MultiRecovery( battleindex, attackNo, toNo, + BD_KIND_HP, -1, 1, MAGIC_EFFECT_USER, SPR_heal3 ); + } + if( strstr( buf1, "MP") != 0 ) { + BATTLE_MultiRecovery( battleindex, attackNo, toNo, + BD_KIND_MP, -1, 1, MAGIC_EFFECT_USER, SPR_heal3 ); + } + if( strstr( buf1, "RS") != 0 ) { + BATTLE_MultiRessurect( battleindex, attackNo, toNo, -1, 1, MAGIC_EFFECT_USER, SPR_fukkatu3 ); + } + return TRUE; +} +#endif + +#ifdef _OFFLINE_SYSTEM +int OFFLINE_MultiRessurect( int battleindex, int attackNo, int toNo, int HP, int flg) +{ + + int charaindex=-1; + + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return FALSE; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + if( !CHAR_CHECKINDEX( charaindex)) return FALSE; + + if( flg == 0 ){ + BATTLE_MultiRecovery( battleindex, attackNo, toNo, + BD_KIND_HP, HP, 1, MAGIC_EFFECT_USER, SPR_heal3 ); + }else if( flg == 1 ){ + BATTLE_MultiRecovery( battleindex, attackNo, toNo, + BD_KIND_MP, HP, 1, MAGIC_EFFECT_USER, SPR_heal3 ); + }else if( flg == 2 ){ + BATTLE_MultiRessurect( battleindex, attackNo, toNo, HP, 1, MAGIC_EFFECT_USER, SPR_fukkatu3 ); + } + return TRUE; +} +#endif + +#ifdef _SKILL_WEAKEN //vincent輼: +int BATTLE_S_Weaken( + int battleindex, + int attackNo, + int defNo, + int marray +) +{ + BOOL iRet = FALSE; + char *magicarg; + int status = -1, i, turn = 3; + int ReceveEffect, Success = 0; + char *pszP; + char szTurn[] = "turn"; + char szSuccess[] = ""; + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return FALSE; + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; + }else{ + ReceveEffect = SPR_hoshi; + } + BATTLE_MultiParamChangeTurn( battleindex, attackNo, defNo, status, + MAGIC_EFFECT_USER, ReceveEffect, turn, Success); + + return iRet; +} +#endif + +#ifdef _PETSKILL_TEMPTATION +BOOL BATTLE_S_Temptation( int battleindex,int attackNo,int defNo, int skill ) +{ + BOOL iRet = FALSE; + char *magicarg; + char szWork[256]; + int attackindex,defindex,defside,flg=0,img2,img1; + int target; + + magicarg = PETSKILL_getChar( skill , PETSKILL_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return iRet; + } + attackindex = BATTLE_No2Index( battleindex, attackNo ); + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE )return iRet; + if( CHAR_CHECKINDEX( defindex ) == FALSE )return iRet; + if( CHAR_getInt( defindex, CHAR_WHICHTYPE) != CHAR_TYPEPET ) return iRet; + if( CHAR_getWorkInt( defindex , CHAR_WORKFIXAI ) <= atoi(magicarg)){ + //ܹ + CHAR_setWorkInt( defindex, CHAR_WORKTEMPTATION , 1 ); //Լ1Ѫ + defside = CHAR_getWorkInt( defindex, CHAR_WORKBATTLESIDE); + target = CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM2 ); + + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_ATTACK ){ + CHAR_setWorkInt( defindex , CHAR_WORKBATTLECOM2, + BATTLE_DefaultAttacker(battleindex,defside)); + }else{ + CHAR_setWorkInt( defindex , CHAR_WORKBATTLECOM2, + BATTLE_DefaultAttacker(battleindex,defside)); + } + img1 = 101505; //鶯101637; //׼ڶ + img2 = 101502; //鶯101645; //ᶯ + flg |= BCF_NO_DAMAGE; + flg |= BCF_B_SKILLACT; //ͼ + snprintf( szWork, sizeof( szWork ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, 0, 0, 1 , img1 , img2 ); + BATTLESTR_ADD( szWork ); + iRet = TRUE; + } + return iRet; + +} +#endif + +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 +int BATTLE_S_Deeppoison( int battleindex, int attackNo, int defNo, int marray ) +{ + BOOL iRet = FALSE; + char *magicarg; + int status = -1, i, turn = 3; + int ReceveEffect, Success = 0; + char *pszP; + char szTurn[] = "turn"; + char szSuccess[] = ""; + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return FALSE; + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; + }else{ + ReceveEffect = SPR_hoshi; + } + + BATTLE_MultiStatusChange( battleindex, attackNo, defNo, + status, turn+2, MAGIC_EFFECT_USER, ReceveEffect, Success ); + + return iRet; +} +#endif + +#ifdef _SKILL_BARRIER //vincent輼:ħ +int BATTLE_S_Barrier( + int battleindex, + int attackNo, + int defNo , + int marray +) +{ + BOOL iRet = FALSE; + int battlemode; + int i,turn,perStatus,charaindex,toindex; + int ToList[SIDE_OFFSET*2+1]; + char *magicarg; + int Success = 0; + char szTurn[] = "turn"; + char szSuccess[] = ""; + char *pszP; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + //check index + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + + pszP = magicarg; + + //ȡûغ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + // + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + BATTLE_MultiList( battleindex, defNo, ToList ); + + //ʩħЧ + BATTLE_MagicEffect(battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi); + + //checkǷս + if( IsBATTLING( charaindex ) == TRUE ) + { + + for( i = 0; ToList[i] != -1; i ++ ) + { + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BATTLE_StatusAttackCheck( charaindex,toindex, BATTLE_ST_BARRIER, Success, 30, 1.0, &perStatus ) == TRUE ) + { + CHAR_setWorkInt( toindex, CHAR_WORKBARRIER, turn+1); + } + } + + } + return iRet; +} +#endif + +#ifdef _SKILL_NOCAST //vincent輼:Ĭ +int BATTLE_S_Nocast( + int battleindex, + int attackNo, + int defNo , + int marray +) +{ + BOOL iRet = FALSE; + int battlemode; + int i,turn,perStatus,charaindex,toindex; + int ToList[SIDE_OFFSET*2+1]; + char *magicarg; + int Success = 0; + char szTurn[] = "turn"; + char szSuccess[] = ""; + char *pszP; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + //check index + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + magicarg = PETSKILL_getChar( marray, PETSKILL_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + + pszP = magicarg; + + //ȡûغ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + // + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + BATTLE_MultiList( battleindex, defNo, ToList ); + + //ʩħЧ + BATTLE_MagicEffect(battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi); + + //checkǷս + if( IsBATTLING( charaindex ) == TRUE ){ + + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BATTLE_StatusAttackCheck( charaindex,toindex, BATTLE_ST_NOCAST, Success, 30, 1.0, &perStatus ) == TRUE + && CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET){ + //޷չҳ + lssproto_NC_send( getfdFromCharaIndex( toindex ), 1); + CHAR_setWorkInt( toindex, CHAR_WORKNOCAST, turn ); + BATTLE_BadStatusString( ToList[i], BATTLE_ST_NOCAST ); + } + } + + } + return iRet; +} +#endif + +int BATTLE_getReactFlg( int index, int react) +{ + int flg=0; + if( react == BATTLE_MD_ABSROB )flg |= BCF_ABSORB; + if( react == BATTLE_MD_REFLEC )flg |= BCF_REFRECT; + if( react == BATTLE_MD_VANISH )flg |= BCF_VANISH; +#ifdef _MAGIC_SUPERWALL + if( CHAR_getWorkInt( index, CHAR_MAGICSUPERWALL ) > 0 ){ + flg |= BCF_SUPERWALL; + } +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( react == BATTLE_MD_TRAP ) flg |= BCF_TRAP; +#endif +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) flg |= BCF_ACUPUNCTURE; +#endif + return flg; +} + +#ifdef _PREVENT_TEAMATTACK +int BATTLE_CheckSameSide( int charaindex, int toNo) +{ + if(!CHAR_CHECKINDEX(charaindex))return 0; + int ToList[SIDE_OFFSET*2+1]; + int toindex, i, battleindex; + int MySide; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if(!BATTLE_CHECKINDEX(battleindex))return 0; + MySide = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE); + +//toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( toNo < 20 ){//һĿ + toindex = BATTLE_No2Index( battleindex, toNo); + if(!CHAR_CHECKINDEX(toindex))return 0; + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE) == MySide ) return 1;//ͬ + }else if( toNo){ + + BATTLE_MultiList( battleindex, toNo, ToList ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( !CHAR_CHECKINDEX( toindex) ) continue; + + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLESIDE) == MySide ) return 1;//ͬ + } + } + return 0; +} +#endif + + +#ifdef _USER_CHARLOOPS +int CHAR_BattleStayLoop( int charaindex) +{ +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) > 0){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + CHAR_setWorkChar( charaindex, CHAR_WORKWALKARRAY,""); + BATTLE_CreateVsEnemy( charaindex,0, -1); + } + return 1; + } +#endif + + int fd = getfdFromCharaIndex( charaindex); + if( getStayEncount( fd) ) { + if( CONNECT_getBDTime( fd) < time( NULL) ){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + lssproto_EN_recv( fd, CHAR_getInt( charaindex,CHAR_X), CHAR_getInt( charaindex,CHAR_Y)); + CONNECT_setBDTime( fd, (int)time( NULL)); + } + } + }else{ + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return 0; + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "");//ս + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 0); + CHAR_constructFunctable( charaindex); + } + + return 1; +} +#endif + + + +#ifdef _PETSKILL_PROPERTY +int PET_PetskillPropertyEvent( int Myindex, int defindex, int *damage, int *T_Pow, int size) +{ + int My_Pow[5]={0,0,0,0,0}; + int i, totals=100; + if( !CHAR_CHECKINDEX( Myindex)) return 0; + if( !CHAR_CHECKINDEX( defindex)) return 0; + BATTLE_GetAttr( defindex, My_Pow); + + //ת + for( i=0; i<4; i++) { + int nums = (i+3)%4; + if( My_Pow[i] != 0 ){ + T_Pow[ nums] = My_Pow[i]; + totals -= My_Pow[i]; + }else{ + T_Pow[ nums] = 0; + } + } + T_Pow[ 4] = totals; + return 1; +} +#endif + + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + +// ֱӹʽ +int battle_profession_attack_fun(int battleindex, int attackNo, int defNo, int charaindex) +{ + char szBuffer[512]=""; + char szCommand[1024]; + int attackindex, defindex=-1; + int damage=0, petdamage=0, i=0, iWork, Guardian=-1,react; + int flg = 0, DefSide=0,ultimate=0; + BOOL iRet = FALSE; + int ReactType=0, skill_type=-1, skill=-1; + char *pszP = NULL; + char *pszOption = NULL; + int effect=0, img1=0, img2=0, atk_num=0, skill_level; + + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + skill_type=CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + + //index + attackindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE ) return iRet; + + //طindex + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( defindex ) == FALSE ){ + return iRet; + } + + // Ӷ + if( (CHAR_getInt( defindex, CHAR_HP ) <= 0) && (skill_type != BATTLE_COM_S_PLUNDER) ){ + return iRet; + } + + // սʹü + if( !PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_USE_FLAG) ) return iRet; + + // ȡüܲ + pszOption = PROFESSION_SKILL_getChar( skill, PROFESSION_SKILL_OPTION); + if( pszOption == "\0" ) return iRet; + + // ܵȼ + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + // ʽ 0ԭ㶯 1ƶ㶯 + if( (pszP = strstr( pszOption, "Ч%" ) ) != NULL ) sscanf( pszP+3, "%d", &effect ); + + // ׼ڵĶ + img1 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_1 ); + + // Ķ + img2 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_2 ); + + // Ŀһܣ + if( defNo >= 0 && defNo <= 19 ){ + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ){ + return iRet; + } + } + + // ȡܲ + switch( skill_type){ + case BATTLE_COM_S_BRUST: // + { + int str=0, old_str=0; + + // ӹ + old_str = CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR); + str = old_str * ( skill_level * 3 + 100 ) / 100; + + CHAR_setWorkInt( charaindex, CHAR_WORKFIXSTR, str ); + + break; + } + case BATTLE_COM_S_CHAOS: // ҹ + { + int atk = 0; + // 30% + atk = CHAR_getWorkInt( charaindex, CHAR_WORKATTACKPOWER ); + atk = atk * 70 / 100; + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, atk ); + + if( skill_level >= 10 ) atk_num = 5; + else if( skill_level >= 5 ) atk_num = 4; + else atk_num = 3; + + break; + } + case BATTLE_COM_S_CHAIN_ATK: // + { + int rand_num = RAND(1, 100); + int hit; + + if( skill_level % 10 != 0 ) + skill_level += 1; + hit = skill_level * 5 + 15; + + if( rand_num <= hit ) + atk_num=2; // + else + atk_num=0; + + break; + } + case BATTLE_COM_S_ENRAGE_PET: // ŭ + { +#ifdef _PREVENT_TEAMATTACK + // жǷͬ + if( BATTLE_CheckSameSide( charaindex, defNo) != 1 ) return iRet; + + defNo = attackNo; + + // 1 + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, 0 ); +#endif + break; + } + case BATTLE_COM_S_CHAIN_ATK_2: // ˫ع + { + int atkpower = 0; + int absrob_num = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEABSROB ); // + //int reflec_num = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ); // + int evanish_num = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ); // + int trap_num = CHAR_getWorkInt( defindex, CHAR_WORKTRAP ); // + + if( absrob_num > 0 ) CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEABSROB, max(absrob_num - 1, 0) ); + //if( reflec_num > 0 ) CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max(reflec_num - 1, 0) );//þЧ,Ҫõ + if( evanish_num > 0 ) CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEVANISH, max(evanish_num - 1, 0) ); + if( trap_num > 0 ) CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + + // һ¹ 0 + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, 0 ); + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|", + attackNo, defNo, BCF_NO_DAMAGE, 0, 0, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + + // ӹ + atkpower =(int)( CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR) * (skill_level * 2 + 100) /100 ); + + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, atkpower ); + + if( (CHAR_getInt( charaindex, CHAR_HP ) > 0 ) && + (CHAR_getInt( defindex, CHAR_HP ) > 0 ) ){ + BATTLE_Attack( battleindex, attackNo, defNo ); + } + + snprintf( szCommand, sizeof( szCommand ), "FF|"); + BATTLESTR_ADD( szCommand ); + + return iRet; + } + case BATTLE_COM_S_DEAD_ATTACK: // + { + int hit=0, hp=0, old_hp=0, rate=0; + + rate = skill_level * 2 + 10 ; + old_hp = CHAR_getInt(charaindex, CHAR_HP); + hp = old_hp * rate / 100; + + if( old_hp <= 10 ){ + CHAR_talkToCli( charaindex, -1, "HP㣬޷ʹü", CHAR_COLORYELLOW); + return iRet; + } + + hit = skill_level * 2 + 80; + + CHAR_setWorkInt(charaindex,CHAR_WORKHITRIGHT, CHAR_getWorkInt(charaindex,CHAR_WORKHITRIGHT) + hit ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT, 1); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT_NUM, hit); + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + + sprintf( szCommand, "BD|r%X|0|1|%X|", attackNo, (-1) * (old_hp - hp) ); + BATTLESTR_ADD( szCommand ); + + CHAR_setInt(charaindex, CHAR_HP, hp); + break; + } + case BATTLE_COM_S_ATTACK_WEAK: // 㹥 + { + float str=0.0, dex=0.0; + int whichtype; + + whichtype = CHAR_getInt( defindex, CHAR_WHICHTYPE); + + // ĿΪʱ + if( (whichtype == CHAR_TYPEPET) || (whichtype == CHAR_TYPEENEMY) ){ + str = skill_level * 2 +10 + 100; + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, CHAR_getWorkInt(charaindex,CHAR_WORKATTACKPOWER) * (str/100) ); + } + + // + dex = 100 - ( skill_level + 10 ); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK, CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX) * (dex/100) ); + sprintf( szCommand, "BD|r%X|0|6|%X|", attackNo, (-1) * (skill_level + 10) ); + BATTLESTR_ADD( szCommand ); + + break; + } + case BATTLE_COM_S_PLUNDER: // Ӷ + { + char pBidList[BATTLE_ENTRY_MAX*2+1]; + int item, start = 0; + memset( pBidList, -1, sizeof(pBidList) ); + pBidList[0] = defNo; + + // ӶĿ + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_getInt( defindex, CHAR_WHICHTYPE) != CHAR_TYPEENEMY ) return 1; + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, 0, 0, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + + if( defNo < 10 ) start = 0; + else start = 10; + + for( i = start; i < start+10; i++ ){ + for(item=CHAR_STARTITEMARRAY; item < CHAR_STARTITEMARRAY+10; item++){ + int enemy_index = -1; + int itemindex = -1; + + enemy_index = BATTLE_No2Index( battleindex, i ); + if( !CHAR_CHECKINDEX(enemy_index) ) break; + + itemindex = CHAR_getItemIndex( enemy_index, item ); + + if(ITEM_CHECKINDEX( itemindex ) == TRUE ){ + char msg[64], *item_name; + + CHAR_AddPileItem( charaindex, itemindex); + + item_name = ITEM_getChar( itemindex, ITEM_NAME); + + sprintf( msg, "õ%s", item_name ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + + CHAR_setItemIndex( enemy_index, item, -1 ); + + BATTLE_Exit( defindex, battleindex ); + + return 1; + } + } + } + + BATTLE_Exit( defindex, battleindex ); + + return 1; + } + default: + break; + } + + react = 0; + if( (ReactType=BATTLE_GetDamageReact( defindex)) > 0 ) { //й⾵ + react = ReactType; + if( skill_type != BATTLE_COM_S_CHAIN_ATK ){ + react=0; +// skill_type=-1; + } + } + + + if( defNo >= SIDE_OFFSET ){ + i = defNo - SIDE_OFFSET; + DefSide = 1; + } + + //ȡù״̬ + iWork = BATTLE_AttackSeq( attackindex, defindex, &damage, &Guardian, skill_type ); + if( skill_type == BATTLE_COM_S_ENRAGE_PET ){//üŭ\ܲҪĴ + if( CHAR_getInt( defindex, CHAR_HP ) <= damage ){ + damage = 0; + } + } + if( skill_type == BATTLE_COM_S_CAVALRY) // ﹥ + ultimate = BATTLE_PROFESSION_ATK_PET_DamageSub( attackindex, defindex, &damage, &petdamage, &react, skill_level ); + else + ultimate = BATTLE_DamageSub( attackindex, defindex, &damage, &petdamage, &react); + + if( react == BATTLE_MD_REFLEC ) defindex = attackindex; + if( react == BATTLE_MD_TRAP ) defindex = attackindex; +#ifdef _PETSKILL_ACUPUNCTURE + if( react == BATTLE_MD_ACUPUNCTURE ) defindex = attackindex; +#endif + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + iRet = BATTLE_DefineAttack( attackindex, defindex, iWork, szBuffer, damage, react, &flg); + + // NORMAL CRITICAL flg ij ְҵflg + if( img2 != 0 ){ + if( flg == BCF_NORMAL || flg == BCF_KAISHIN ){ + if( (pszP = strstr( pszOption, "ǰ" ) ) != NULL ) + flg |= BCF_F_SKILLACT; //ǰͼ + else + flg |= BCF_B_SKILLACT; // + } + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ){ + iRet = BATTLE_DefDieType( defindex, iRet, &ultimate, &flg, szBuffer); + } + + if( damage > 0 ){ + if( BATTLE_ItemCrushSeq( attackindex, defindex, damage) == TRUE ) + flg |= BCF_CRUSH; + } + + + memset( szCommand, 0, sizeof( szCommand)); + switch( skill_type){ + case BATTLE_COM_S_BRUST: // + case BATTLE_COM_S_DEAD_ATTACK: // + case BATTLE_COM_S_ATTACK_WEAK: // 㹥 + case BATTLE_COM_S_CAVALRY: // ﹥ + { + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, damage, petdamage, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + break; + } + case BATTLE_COM_S_ENRAGE_PET: // ŭ + { + int str = 0; + int turn = 0; + int pindex = -1; + + + flg |= BCF_NO_DAMAGE; + flg |= BCF_B_SKILLACT; //ͼ + + defNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + + pindex = BATTLE_No2Index( battleindex, defNo ); + + // ǷΪ + if( CHAR_getInt( pindex, CHAR_WHICHTYPE) != CHAR_TYPEPET ) break; + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|FF|", + attackNo, defNo, flg, damage, 0, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + +/* + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|0|d%X|FF|", + attackNo, defNo, damage); + BATTLESTR_ADD( szCommand ); +*/ + // ӹ + str = skill_level * 2 + 10; + sprintf( szCommand, "BD|r%X|0|4|%X|", defNo, str); + BATTLESTR_ADD( szCommand ); + CHAR_setWorkInt( pindex, CHAR_MYSKILLSTRPOWER, str); + + if( skill_level >= 10 ) turn=5; + else if( skill_level >= 5 ) turn=4; + else turn=3; + + CHAR_setWorkInt( pindex, CHAR_MYSKILLSTR, turn ); + + break; + } + case BATTLE_COM_S_CHAOS: // ҹ + { + int i=0, j=0, k=0, f_num=0; + int temp[10], chose_temp[10]; + int defNo_index = BATTLE_No2Index( battleindex, defNo ); + + memset( temp, -1, sizeof( temp ) ); + memset( chose_temp, -1, sizeof( chose_temp ) ); + + if( CHAR_getWorkInt( defNo_index, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ){ + break; + } + + if( defNo >= 10 ) f_num = 10; + else f_num = 0; + + // 30% + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKATTACKPOWER ) * 70 / 100 ); + + //clientЧ + sprintf( szCommand, "BD|r%X|0|4|%X|", attackNo, -30 ); + BATTLESTR_ADD( szCommand ); + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|", + attackNo, defNo, flg, damage, petdamage, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + + // ȡսϴ + for( i=f_num; i 0 ){ + int atk_to_index = -1; + atk_to_index = BATTLE_No2Index( battleindex, chose_temp[k] ); + + if( ( atk_to_index >= 0 ) && + ( BATTLE_TargetCheck(battleindex, chose_temp[k] ) != FALSE ) && + ( CHAR_getWorkInt( atk_to_index, CHAR_WORKBATTLECOM1 ) != BATTLE_COM_S_EARTHROUND0 ) + ){ + + if(CHAR_getInt( BATTLE_No2Index( battleindex, chose_temp[k] ), CHAR_WHICHTYPE) != CHAR_TYPEPET + || CHAR_getWorkInt( BATTLE_No2Index( battleindex, i-5), CHAR_WORKULTIMATE )) + { + BATTLE_Attack( battleindex, attackNo, chose_temp[k] ); + } + k++; + atk_num --; + }else{ + + memset( temp, -1, sizeof( temp ) ); + memset( chose_temp, -1, sizeof( chose_temp ) ); + j = 0; k = 0; + + // ȡսϴ + for( i=f_num; i 0 ) && + (CHAR_getInt( defindex, CHAR_HP ) > 0 ) ){ + BATTLE_Attack( battleindex, attackNo, defNo ); + } + + snprintf( szCommand, sizeof( szCommand ), "FF|"); + BATTLESTR_ADD( szCommand ); + + break; + } + } + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + i = defNo-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + return iRet; +} + + +// ħʽ +int battle_profession_attack_magic_fun(int battleindex, int attackNo, int defNo, int charaindex) +{ + int attr=-1, attIdx=0, skill=-1, toindex; + + // ȡID + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + + // Ŀ + // Robin fix + //toindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ); + toindex = defNo; + + + // Χ 0 1 2һȫ + if( toindex < 20 ){ // + attIdx = 0; + }else if( toindex>=23 && toindex<=26 ){ // + attIdx = 1; + }else if( toindex==20 || toindex==21 ){ // һȫ + attIdx = 2; + } + + // Robin fix ս + attr = BattleArray[battleindex].field_att -1; + + PROFESSION_MAGIC_ATTAIC( battleindex, attackNo, toindex, attIdx, attr, skill); + + return TRUE; +} + +// ϵʽ +int battle_profession_assist_fun(int battleindex, int attackNo, int defNo, int charaindex) +{ + int i, skill, skill_type, skill_level, img1, img2, turn=1; + char *pszP = NULL, *pszOption = NULL, szCommand[256]; + BOOL iRet = FALSE; + int ToList[SIDE_OFFSET*2+1]; + + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3); + skill_type = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + + // սʹü + if( !PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_USE_FLAG) ) return iRet; + + // ܵIJ + pszOption = PROFESSION_SKILL_getChar( skill, PROFESSION_SKILL_OPTION); + if( pszOption == "\0" ) return iRet; + + // ܵȼ + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + + // ׼ڵĶ + img1 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_1 ); + + // Ķ + img2 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_2 ); + + // ʹûغ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &turn ); + if(turn < 1) turn=1; + + switch(skill_type){ + case BATTLE_COM_S_TRANSPOSE: // λλ + { + int defNo2 = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo2, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + for( i = 0; ToList[i] != -1; i ++ ){ + int avoid=0; + int toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( !CHAR_CHECKINDEX( toindex ))continue; + if( charaindex != toindex ) continue; + + // ر + if( skill_level >= 10 ) avoid = 70; + else if( skill_level >= 9 ) avoid = 60; + else if( skill_level >= 8 ) avoid = 50; + else if( skill_level >= 6 ) avoid = 45; + else if( skill_level >= 5 ) avoid = 30; + else if( skill_level >= 3 ) avoid = 25; + else avoid = 10; + + if( skill_level >= 10 ) turn = 5; + else if( skill_level >= 6 ) turn = 4; + else turn = 3; + + if( CHAR_getWorkInt( toindex, CHAR_MYSKILLDUCK) <= 0){ + CHAR_setWorkInt( toindex, CHAR_MYSKILLDUCK, turn+1); + CHAR_setWorkInt( toindex, CHAR_MYSKILLDUCKPOWER, avoid ); + sprintf( szCommand, "BD|r%X|0|3|%X|", ToList[i], avoid); + BATTLESTR_ADD( szCommand ); + iRet = TRUE; + } + } + break; + } + case BATTLE_COM_S_SCAPEGOAT: // Ϊ + { + int tgh=0, old_tgh=0, flg=0, rate=0; + int pos=0, side=0, ownerpos=0; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + pos = BATTLE_Index2No( battleindex, charaindex ); + side = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + + if( skill_level >= 10 ){ // ҷȫ + for(i=0; i<10; i++){ + if(pos != i ) + BattleArray[battleindex].Side[side].Entry[i].guardian = pos; + } + }else if( skill_level >= 5 ){ // ҷг + for(i=5; i<10; i++){ + if(pos != i ) + BattleArray[battleindex].Side[side].Entry[i].guardian = pos; + } + }else{ // ֮ + ownerpos = pos + 5; + if( ownerpos >= 10 ) ownerpos -= 10; + if( ownerpos < 0 || ownerpos > 19 ){ + }else{ + BattleArray[battleindex].Side[side].Entry[ownerpos].guardian = pos; + } + } + + rate = skill_level * 2; + + tgh = 30 - rate; + sprintf( szCommand, "BD|r%X|0|5|%X|", attackNo, (-1) * tgh ); + BATTLESTR_ADD( szCommand ); + + old_tgh = CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + tgh = (int)( old_tgh * (100-tgh) / 100 ); + CHAR_setWorkInt( charaindex, CHAR_WORKFIXTOUGH, tgh); + + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); + flg |= CHAR_BATTLEFLG_GUARDIAN; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + + iRet = TRUE; + + break; + } + case BATTLE_COM_S_ENRAGE: // + { + int str=0, tgh=0; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, attackNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + // + tgh = skill_level * 2 + 10; + sprintf( szCommand, "BD|r%X|0|5|%X|", attackNo, (-1) * tgh ); + BATTLESTR_ADD( szCommand ); + + CHAR_setWorkInt(charaindex,CHAR_MYSKILLTGHPOWER, (-1) * tgh); + + // ӹ + str = skill_level * 2 + 20; + sprintf( szCommand, "BD|r%X|0|4|%X|", attackNo, str); + BATTLESTR_ADD( szCommand ); + + CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTRPOWER, str); + + if( skill_level >= 10 ) turn=5; + else if( skill_level >= 5 ) turn=4; + else turn=3; + + CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTR, turn ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGH, turn ); + + iRet = TRUE; + break; + } + case BATTLE_COM_S_COLLECT: // ۼ + { + int dex=0, tgh=0; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, attackNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + // + dex = (skill_level * 2) + 10; + sprintf( szCommand, "BD|r%X|0|6|%X|", attackNo, (-1) * dex ); + BATTLESTR_ADD( szCommand ); + CHAR_setWorkInt(charaindex,CHAR_MYSKILLDEXPOWER, dex); + + // ӷ + tgh = (skill_level * 2) + 20; + sprintf( szCommand, "BD|r%X|0|5|%X|", attackNo, tgh); + BATTLESTR_ADD( szCommand ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGHPOWER, tgh); + + if( skill_level >= 10 ) turn=5; + else if( skill_level >= 5 ) turn=4; + else turn=3; + + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEX, turn ); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGH, turn ); + + iRet = TRUE; + break; + } + case BATTLE_COM_S_FOCUS: // רעս + { + int ToList[SIDE_OFFSET*2+1]; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, attackNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT, 2); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLHIT_NUM, 100); + + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + + iRet = TRUE; + break; + } + case BATTLE_COM_S_TRAP: // + { + int value; + int ToList[SIDE_OFFSET*2+1]; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + memset( ToList, -1, sizeof(ToList) ); + ToList[0] = attackNo; + + value = skill_level * 30 + 100; + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + if( skill_level >= 10 ) turn=3; + else if( skill_level >= 5 ) turn=2; + else turn=1; + + CHAR_setWorkInt( charaindex, CHAR_WORKTRAP, turn); + CHAR_setWorkInt( charaindex, CHAR_WORKMODTRAP, value); + + iRet = TRUE; + break; + } + case BATTLE_COM_S_DOCILE: // ѱ + { + int rate = 0; + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + rate = skill_level * 2 + 10; + + BATTLE_MultiCaptureUp( battleindex, attackNo, defNo, rate, img1, img2 ); + + iRet = TRUE; + break; + } +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_CALL_NATURE: // Ȼ + { + int ridepet=0,count=0,addhp=0,toindex=-1; + int ToList[SIDE_OFFSET*2+1]; + BATTLE_MultiList( battleindex, defNo, ToList ); + + if( defNo == 20 || defNo == 25 || defNo == 26 )//ҷ + img1 = 101772; + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( CHAR_CHECKINDEX( toindex ) == FALSE ) continue; + ridepet = BATTLE_getRidePet( toindex ); + if( ridepet == -1 ) + ++count; + else + count += 2; + } + if( skill_level >= 100 ) addhp = 5000/count; + else if( skill_level > 95 ) addhp = 4500/count; + else if( skill_level > 90 ) addhp = 4000/count; + else if( skill_level > 85 ) addhp = 3500/count; + else if( skill_level > 80 ) addhp = 3000/count; + else if( skill_level > 60 ) addhp = 2500/count; + else if( skill_level > 40 ) addhp = 2000/count; + else if( skill_level > 20 ) addhp = 1000/count; + else addhp = 500/count; + if( addhp <= 100 ) + img2 = SPR_heal; + else if( addhp <= 300 ) + img2 = SPR_heal2; + else + img2 = SPR_heal3; + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( CHAR_CHECKINDEX( toindex ) == FALSE ) continue; + ridepet = BATTLE_getRidePet( toindex ); + if( ridepet == -1 ){ + CHAR_setInt( toindex, CHAR_HP, + min( addhp+CHAR_getInt( toindex, CHAR_HP ), CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + } + else{ + CHAR_setInt( toindex, CHAR_HP, + min( addhp+CHAR_getInt( toindex, CHAR_HP ), CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + CHAR_setInt( ridepet, CHAR_HP, + min( addhp+CHAR_getInt( ridepet, CHAR_HP ), CHAR_getWorkInt( ridepet, CHAR_WORKMAXHP ) ) ); + } + snprintf( szCommand, sizeof(szCommand),"BD|r%X|%X|%X|d%X|p%X|", ToList[i], BD_KIND_HP, 1, addhp, ridepet?addhp:0 ); + BATTLESTR_ADD( szCommand ); + + + if( BattleArray[battleindex].norisk == 0 + && CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET) + { + int flg = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEFLG ); + if( flg & CHAR_BATTLEFLG_RECOVERY ) + {} + else + { + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRECOVERY ); + CHAR_setWorkInt( toindex, CHAR_WORKBATTLEFLG, flg | CHAR_BATTLEFLG_RECOVERY ); + } + } + } + + iRet = TRUE; + break; + } +#endif + default: + break; + } + + + return iRet; +} + +#ifdef _PROFESSION_ADDSKILL +extern unsigned int GET_PROFESSION_magic_array(int idx); +#endif + +// иı״̬ϵʽ +extern void BATTLE_TargetListSet( int charaindex, int attackNo, int *pList); +extern int BoomerangVsTbl[4][5]; +int battle_profession_status_chang_fun(int battleindex, int attackNo, int defNo, int charaindex) +{ + int i, skill, skill_type, skill_level, img1=0, img2=0, turn=1, j; + char *pszP = NULL, *pszOption = NULL, szCommand[512]; + float rate=0.0; + BOOL iRet = FALSE; + int defindex; + int damage=0, petdamage=0, iWork, Guardian=-1,react; + int flg=0, DefSide=0,ultimate=0; + int ReactType=0, effect=0; + + skill = CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ); + skill_type=CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1 ); + + // սʹü + if( !PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_USE_FLAG) ) return iRet; + + // ܵIJ + pszOption = PROFESSION_SKILL_getChar( skill, PROFESSION_SKILL_OPTION); + if( pszOption == "\0" ) return iRet; + + // ܵȼ + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + // ܵȼ rate + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%f", &rate ); + + // ׼ڵĶ + img1 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_1 ); + + // Ķ + img2 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_2 ); + + // ʹûغ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &turn ); + if(turn < 1) turn=1; + + // ʽ 0ԭ㶯 1ƶ㶯 + if( (pszP = strstr( pszOption, "Ч%" ) ) != NULL ) sscanf( pszP+3, "%d", &effect ); + + // Ŀһܣ + if( defNo >= 0 && defNo <= 19 ){ + defindex = BATTLE_No2Index( battleindex, defNo ); + if( CHAR_CHECKINDEX( defindex ) == FALSE ) return iRet; + if( CHAR_getWorkInt( defindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ){ + return iRet; // Miss + } + } + + switch(skill_type){ + // ƶ + case BATTLE_COM_S_ENTWINE: // + case BATTLE_COM_S_DRAGNET: // ޵ + case BATTLE_COM_S_INSTIGATE: // + case BATTLE_COM_S_OBLIVION: // + case BATTLE_COM_S_RESIST_FIRE: // + case BATTLE_COM_S_RESIST_ICE: // + case BATTLE_COM_S_RESIST_THUNDER: // ׿ +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_RESIST_F_I_T: // Ȼ +#endif + case BATTLE_COM_S_FIRE_ENCLOSE: // + case BATTLE_COM_S_ICE_ENCLOSE: // + case BATTLE_COM_S_THUNDER_ENCLOSE: // ׸ + { + int perStatus=0, toindex=-1, status=-1, Success=0, dex=0, old_dex; + //char szBuffer[256]=""; + int ToList[SIDE_OFFSET*2+1]; + int defNo2 = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + + // ʹö + if( skill_type == BATTLE_COM_S_RESIST_FIRE || // + skill_type == BATTLE_COM_S_RESIST_ICE || // + skill_type == BATTLE_COM_S_RESIST_THUNDER // ׿ +#ifdef _PROFESSION_ADDSKILL + || skill_type == BATTLE_COM_S_RESIST_F_I_T // Ȼ +#endif + ){ +#ifdef _PROFESSION_ADDSKILL + defNo2 = BATTLE_Index2No( battleindex, charaindex ); +#else + if( defNo2 < 10 ){ + if( skill_level >= 10 ) defNo2 = 20; + else if( skill_level >= 5 ) defNo2 = 25; + }else{ + if( skill_level >= 10 ) defNo2 = 21; + else if( skill_level >= 5 ) defNo2 = 24; + } +#endif + } + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo2, ToList ); + + BATTLE_MagicEffect( battleindex, attackNo, ToList, img1, img2 ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return iRet; + + // ı״̬ + if( ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) || + ((pszP = strstr( pszOption, "" ) ) != NULL ) +#ifdef _PROFESSION_ADDSKILL + || ((pszP = strstr( pszOption, "" ) ) != NULL ) +#endif + ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + break; + } + } + } + + // ɹ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &Success ); + Success = Success + skill_level * 5; + if( skill_type == BATTLE_COM_S_DRAGNET ){ + int DRAGNET=0,dragnet_idx=-1; + int PLAYER=0; + //ҳһߵ + if( attackNo > 9 ){// + for(i=0;i<10;i++){//ұж + dragnet_idx = BATTLE_No2Index( battleindex, i ); + if( CHAR_CHECKINDEX( dragnet_idx ) ){ + PLAYER++; + if( CHAR_getWorkInt( dragnet_idx, CHAR_WORKDRAGNET ) > 0 ) { + ++DRAGNET; + } + } + } + } + else{// + for(i=10;i<20;i++){//ж + dragnet_idx = BATTLE_No2Index( battleindex, i ); + if( CHAR_CHECKINDEX( dragnet_idx ) ){ + PLAYER++; + if( CHAR_getWorkInt( BATTLE_No2Index( battleindex, i ), CHAR_WORKDRAGNET ) > 0 ) { + ++DRAGNET; + } + } + } + } + Success *= (float)((PLAYER-DRAGNET)/10.0); +// if( DRAGNET == 1 ){ +// Success *= 0.64; +// }else if( DRAGNET > 1 ){ +// Success *= 0.4; +// } + } + + perStatus = Success; + + // غ + if( (skill_type == BATTLE_COM_S_INSTIGATE) && (skill_level == 10) ){ // + turn = 4; + }else if( (skill_type == BATTLE_COM_S_RESIST_FIRE) || // + (skill_type == BATTLE_COM_S_RESIST_ICE) || // + (skill_type == BATTLE_COM_S_RESIST_THUNDER) ){ // ׿ + + if( skill_level >= 10 ) turn = 5; + else if( skill_level >= 5 ) turn = 4; + else turn = 3; + }else if( skill_type == BATTLE_COM_S_OBLIVION ){ // + if( skill_level >= 10 ){ turn = 4; + }else if( skill_level >= 5 ){ turn = 3; + }else{ turn = 2; } + } +#ifdef _PROFESSION_ADDSKILL + else if( skill_type == BATTLE_COM_S_RESIST_F_I_T ){ // Ȼ + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + if( skill_level >= 100 ) turn = 5; + else if( skill_level > 80 ) turn = 4; + else turn = 3; + } +#endif + + switch( skill_type ){ + case BATTLE_COM_S_RESIST_FIRE: + CHAR_talkToCli( charaindex, -1 , "" , CHAR_COLORYELLOW ); break; + case BATTLE_COM_S_RESIST_ICE: + CHAR_talkToCli( charaindex, -1 , "" , CHAR_COLORYELLOW ); break; + case BATTLE_COM_S_RESIST_THUNDER: + CHAR_talkToCli( charaindex, -1 , "׿" , CHAR_COLORYELLOW ); break; +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_RESIST_F_I_T: + CHAR_talkToCli( charaindex, -1 , "׿" , CHAR_COLORYELLOW ); break; +#endif + } + + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( CHAR_CHECKINDEX( toindex ) == FALSE ) return iRet; + + // ʩ + if( skill_type == BATTLE_COM_S_INSTIGATE ){ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_talkToCli( charaindex, -1, "ʩ", CHAR_COLORYELLOW ); + break; + } + } + + // ״̬м춨 + if( (PROFESSION_BATTLE_StatusAttackCheck( charaindex, toindex, status, Success ) == 0 ) + || (CHAR_getInt( toindex, CHAR_HP ) <= 0 ) ){ + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)޷(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), CHAR_getUseName( toindex ), + // aszStatusFull[status], perStatus ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }else{ +#ifdef _PROFESSION_ADDSKILL + if( status == BATTLE_ST_RESIST_F_I_T ){//Ȼ + CHAR_setWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_F], turn + 1 ); + CHAR_setWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_I], turn + 1 ); + CHAR_setWorkInt( toindex, StatusTbl[BATTLE_ST_RESIST_T], turn + 1 ); + } + else +#endif + CHAR_setWorkInt( toindex, StatusTbl[status], turn + 1 ); + + if( status == BATTLE_ST_PARALYSIS + || status == BATTLE_ST_SLEEP + || status == BATTLE_ST_STONE + || status == BATTLE_ST_BARRIER + || status == BATTLE_ST_DIZZY + || status == BATTLE_ST_ENTWINE + || status == BATTLE_ST_DRAGNET + || status == BATTLE_ST_ICECRACK + || status == BATTLE_ST_ICEARROW ){ + CHAR_setWorkInt( toindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + if( status == BATTLE_ST_DRAGNET ){//޵ + CHAR_setWorkInt( toindex, CHAR_DOOMTIME, 0 );//ĩռ + CHAR_setWorkInt( toindex, CHAR_WORK_com1, 0 ); + CHAR_setWorkInt( toindex, CHAR_WORK_toNo, 0 ); + CHAR_setWorkInt( toindex, CHAR_WORK_mode, 0 ); + CHAR_setWorkInt( toindex, CHAR_WORK_skill_level, 0 ); + CHAR_setWorkInt( toindex, CHAR_WORK_array, 0 ); + } + if( skill_type == BATTLE_COM_S_FIRE_ENCLOSE ){ // + CHAR_setWorkInt( toindex, CHAR_WORKMOD_F_ENCLOSE_2, skill_level ); + // ӻȾֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_FIRE_PRACTICE" ); + }else if(skill_type == BATTLE_COM_S_ICE_ENCLOSE ){ // + CHAR_setWorkInt( toindex, CHAR_WORKMOD_I_ENCLOSE_2, skill_level ); + // ӱȾֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_ICE_PRACTICE" ); + }else if(skill_type == BATTLE_COM_S_THUNDER_ENCLOSE ){ // ׸ + CHAR_setWorkInt( toindex, CHAR_WORKMOD_T_ENCLOSE_2, skill_level ); + // Ⱦֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_THUNDER_PRACTICE" ); + } + + // + if( skill_type == BATTLE_COM_S_OBLIVION ){ + int toNo = -1, toNoindex = -1, pet_no = -1, num = 0; + char msg[20]; + + memset( msg, -1, sizeof(msg) ); + + // index + toNo = ToList[i] - 5; + toNoindex = BATTLE_No2Index( battleindex, toNo ); + + // + pet_no = CHAR_getInt( toNoindex, CHAR_DEFAULTPET ); + + // 輼 + num = skill_level / 2; + if( num < 1 ) num = 1; + CHAR_setWorkInt( toindex, CHAR_WORKMODOBLIVION, num ); + + // client + if( toNoindex != -1 ){ + sprintf( msg, "W%d", pet_no ); + CHAR_sendStatusString( toNoindex, msg ); + + sprintf( msg, "Y%d", pet_no ); + CHAR_sendStatusString( toNoindex, msg ); + + } + } + + // + if(skill_type == BATTLE_COM_S_INSTIGATE ){ + int rate=0; + rate = skill_level * 1 + 10; + CHAR_setWorkInt( toindex, CHAR_WORKMODINSTIGATE, rate); + + sprintf( szCommand, "BD|r%X|0|4|%X|", ToList[i], (-1) * rate); + BATTLESTR_ADD( szCommand ); + sprintf( szCommand, "BD|r%X|0|5|%X|", ToList[i], (-1) * rate); + BATTLESTR_ADD( szCommand ); + sprintf( szCommand, "BD|r%X|0|6|%X|", ToList[i], (-1) * rate ); + BATTLESTR_ADD( szCommand ); + + } + + // + if(skill_type == BATTLE_COM_S_ENTWINE ){ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &dex ); + dex = skill_level * 4 + dex; + old_dex = CHAR_getWorkInt( toindex, CHAR_WORKFIXDEX); + old_dex = old_dex * (100 - dex) / 100; + CHAR_setWorkInt( toindex, CHAR_WORKFIXDEX, old_dex ); + sprintf( szCommand, "BD|r%X|0|6|%X|", ToList[i], (-1) * dex ); + BATTLESTR_ADD( szCommand ); + } + + // + if(skill_type == BATTLE_COM_S_RESIST_FIRE ){ + int old_value = CHAR_getWorkInt( toindex, CHAR_WORK_F_RESIST ); + int up_value = skill_level + 10; + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_F, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_F_RESIST, old_value + up_value ); + + }else + // + if(skill_type == BATTLE_COM_S_RESIST_ICE ){ + int old_value = CHAR_getWorkInt( toindex, CHAR_WORK_I_RESIST ); + int up_value = skill_level + 10; + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_I, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_I_RESIST, old_value + up_value ); + + }else + // ׿ + if(skill_type == BATTLE_COM_S_RESIST_THUNDER ){ + int old_value = CHAR_getWorkInt( toindex, CHAR_WORK_T_RESIST ); + int up_value = skill_level + 10; + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_T, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_T_RESIST, old_value + up_value ); + + } +#ifdef _PROFESSION_ADDSKILL + else + // Ȼ + if(skill_type == BATTLE_COM_S_RESIST_F_I_T ){ + int old_value = CHAR_getWorkInt( toindex, CHAR_WORK_F_RESIST ); + int up_value = 2; //ֵ + + if( skill_level >= 10 ) up_value = 20; + else if( skill_level > 8 ) up_value = 18; + else if( skill_level > 7 ) up_value = 16; + else if( skill_level > 6 ) up_value = 14; + else if( skill_level > 5 ) up_value = 12; + else if( skill_level > 4 ) up_value = 10; + else if( skill_level > 3 ) up_value = 8; + else if( skill_level > 2 ) up_value = 6; + else if( skill_level > 1 ) up_value = 4; + else up_value = 2; + + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_F, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_F_RESIST, old_value + up_value ); + + old_value = CHAR_getWorkInt( toindex, CHAR_WORK_I_RESIST ); + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_I, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_I_RESIST, old_value + up_value ); + + old_value = CHAR_getWorkInt( toindex, CHAR_WORK_T_RESIST ); + CHAR_setWorkInt( toindex, CHAR_WORKMODRESIST_T, up_value ); + CHAR_setWorkInt( toindex, CHAR_WORK_T_RESIST, old_value + up_value ); + + } +#endif + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), aszStatusFull[status], perStatus ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + BATTLE_BadStatusString( ToList[i], status ); + iRet = TRUE; + } + } + break; + } + // ƶ + case BATTLE_COM_S_SHIELD_ATTACK: // ܻ + { + int itmid=-1; + int perStatus, status=-1, Success=-1; + char szBuffer[256]=""; + int ToList[SIDE_OFFSET*2+1]; + int defNo2 = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + + itmid = CHAR_getItemIndex( charaindex, CHAR_EQSHIELD ); + + if( ( itmid < 0 ) || ITEM_WSHIELD != ITEM_getInt( itmid , ITEM_TYPE ) ){ + CHAR_talkToCli( charaindex, -1, "δװƣ޷ʹô˼", CHAR_COLORYELLOW); + iRet = FALSE; + break; + } + + // + if( skill_level != 10 ) + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, (int)(CHAR_getWorkInt(charaindex,CHAR_WORKATTACKPOWER) * 0.5 ) ); + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo2, ToList ); + + // ı״̬ + if( (pszP = strstr( pszOption, "" ) ) != NULL ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + break; + } + } + } + + // ɹ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &Success ); + Success += skill_level * 4; + perStatus = Success; + + if( defNo2 >= SIDE_OFFSET ){ + i = defNo2 - SIDE_OFFSET; + DefSide = 1; + } + + for( i = 0; ToList[i] != -1; i ++ ){ + int hit = -1; + react = 0; + + defindex = BATTLE_No2Index( battleindex, ToList[i] ); //طindex + if( CHAR_CHECKINDEX( defindex ) == FALSE ) continue; + + if( (ReactType=BATTLE_GetDamageReact( defindex)) > 0 ) { //й⾵ + react = ReactType; + skill_type=-1; + } + + //ȡù״̬ + iWork = BATTLE_AttackSeq( charaindex, defindex, &damage, &Guardian, skill_type ); + + ultimate = BATTLE_DamageSub( charaindex, defindex, &damage, &petdamage, &react); + + if( damage > 0 && ( react != BATTLE_MD_ABSROB )&& ( react != BATTLE_MD_VANISH )){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + iRet = BATTLE_DefineAttack( charaindex, defindex, iWork, szBuffer, damage, react, &flg); + + // NORMAL CRITICAL flg ij ְҵflg + if( img2 != 0 ){ + if( flg == BCF_NORMAL || flg == BCF_KAISHIN ){ + hit=1; + if( (pszP = strstr( pszOption, "ǰ" ) ) != NULL ){ + flg |= BCF_F_SKILLACT; //ǰͼ + }else{ + flg |= BCF_B_SKILLACT; //ͼ + } + } + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ) + iRet = BATTLE_DefDieType( defindex, iRet, &ultimate, &flg, szBuffer); + + if( damage > 0 ){ + if( BATTLE_ItemCrushSeq( charaindex, defindex, damage) == TRUE ){ + flg |= BCF_CRUSH; + } + } + + if( hit == 1 ){ + if( (PROFESSION_BATTLE_StatusAttackCheck( charaindex, defindex, status, Success ) == 0 ) + || (CHAR_getInt( defindex, CHAR_HP ) <= 0 ) ){ + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)޷(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), CHAR_getUseName( defindex ), aszStatusFull[status], perStatus ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }else{ + CHAR_setWorkInt( defindex, StatusTbl[status], turn + 1 ); + + if( status == BATTLE_ST_PARALYSIS + || status == BATTLE_ST_SLEEP + || status == BATTLE_ST_STONE + || status == BATTLE_ST_BARRIER + || status == BATTLE_ST_DIZZY + || status == BATTLE_ST_ENTWINE + || status == BATTLE_ST_DRAGNET + || status == BATTLE_ST_ICECRACK + || status == BATTLE_ST_ICEARROW + ){ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( defindex ), + // aszStatusFull[status], + // perStatus + //); + + BATTLE_BadStatusString( ToList[i], status ); + } + } + + snprintf( szCommand, sizeof( szCommand ), "B+|a%X|r%X|f%X|d%X|p%X|e%X|s%X|h%X|FF|", + attackNo, ToList[i], flg, damage, petdamage, effect, img1, img2 ); + BATTLESTR_ADD( szCommand ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + i = defNo2-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[i].flg |= BENT_FLG_ULTIMATE; + } + + iRet = TRUE; + } + break; + + } + case BATTLE_COM_S_TOXIN_WEAPON: // + { + int perStatus, status=-1, Success=-1; + int defNo2 = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return iRet; + + // ı״̬ + if( ((pszP = strstr( pszOption, "" ) ) != NULL ) ){ + + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + break; + } + } + } + + // ɹ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &Success ); + Success += skill_level * 2; + perStatus = Success; + + if( defNo2 >= SIDE_OFFSET ){ + i = defNo2 - SIDE_OFFSET; + DefSide = 1; + } + + { + int gWeponType = BATTLE_GetWepon( charaindex ); + char szCommand[512]; + int i = 0, ReactType = 0, iRet = -1; + int ToList[SIDE_OFFSET*2+1]; + BOOL bChange = FALSE; + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo, ToList ); + + memset( szCommand, -1, sizeof(szCommand) ); + + // ޱ +#ifdef _PETSKILL_BECOMEPIG + if(CHAR_getWorkInt(charaindex, CHAR_WORKFOXROUND) > 0 + || CHAR_getWorkInt(charaindex, CHAR_BECOMEPIG) > 0) bChange = TRUE; +#else + if(CHAR_getWorkInt(charaindex, CHAR_WORKFOXROUND) > 0) bChange = TRUE; +#endif + if(!bChange){ + // ΪԶ + if( gWeponType == ITEM_BOW ){ + sprintf( szCommand, "BB|a%X|w0|", attackNo ); + BATTLESTR_ADD( szCommand ); + memset( ToList, -1, sizeof( ToList)); + BATTLE_TargetListSet(charaindex,attackNo,ToList); + }else if( gWeponType == ITEM_BOUNDTHROW ){ + sprintf( szCommand, "BB|a%X|w1|", attackNo ); + BATTLESTR_ADD( szCommand ); + }else if( gWeponType == ITEM_BREAKTHROW ){ + sprintf( szCommand, "BB|a%X|w2|", attackNo ); + BATTLESTR_ADD( szCommand ); + }else if( gWeponType == ITEM_BOOMERANG){ + sprintf( szCommand, "BO|a%X|", attackNo ); + BATTLESTR_ADD( szCommand ); + memset(ToList,-1,sizeof(ToList)); + for(i=0;i<5;i++) ToList[i] = BoomerangVsTbl[defNo/5][i]; + gBattleDamageModyfy = 0.3; + } + } + + for( i = 0; ToList[i] != -1; i ++ ){ + int defindex = -1, j = -1; + int react = 0; + char szBuffer[256] = ""; + + damage = 0; + petdamage = 0; + flg = 0; + + //memset( szBuffer, 0, sizeof( szBuffer ) ); + + defindex = BATTLE_No2Index( battleindex, ToList[i] ); //طindex + if( CHAR_CHECKINDEX( defindex ) == FALSE ) continue; + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ) continue; + + if( (ReactType=BATTLE_GetDamageReact( defindex)) > 0 ){ //й⾵ + react = ReactType; + skill_type=-1; + } + + //ȡù״̬ + iWork = BATTLE_AttackSeq( charaindex, defindex, &damage, &Guardian, skill_type ); + if(Guardian >= 0) defindex = BATTLE_No2Index( battleindex, Guardian ); + + iRet = BATTLE_DefineAttack( charaindex, defindex, iWork, szBuffer, damage, react, &flg); + + if(damage > 0){ + ultimate = BATTLE_DamageSub( charaindex, defindex, &damage, &petdamage, &react); + + if((react != BATTLE_MD_ABSROB ) && ( react != BATTLE_MD_VANISH ) ){ + BATTLE_DamageWakeUp( battleindex, defindex ); + } + + if( CHAR_getInt( defindex, CHAR_HP ) <= 0 ) + iRet = BATTLE_DefDieType( defindex, iRet, &ultimate, &flg, szBuffer); + + if( BATTLE_ItemCrushSeq( charaindex, defindex, damage) == TRUE ){ + flg |= BCF_CRUSH; + } + + if( (PROFESSION_BATTLE_StatusAttackCheck( charaindex, defindex, status, perStatus ) == 0 ) + || (CHAR_getInt( defindex, CHAR_HP ) <= 0 ) ){ + + //snprintf( szBuffer, sizeof(szBuffer), "(%s)޷(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), CHAR_getUseName( defindex ), aszStatusFull[status], perStatus ); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }else{ + CHAR_setWorkInt( defindex, StatusTbl[status], turn + 1 ); + + if( status == BATTLE_ST_PARALYSIS + || status == BATTLE_ST_SLEEP + || status == BATTLE_ST_STONE + || status == BATTLE_ST_BARRIER + || status == BATTLE_ST_DIZZY + || status == BATTLE_ST_ENTWINE + || status == BATTLE_ST_DRAGNET + || status == BATTLE_ST_ICECRACK + || status == BATTLE_ST_ICEARROW + ){ + CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( defindex ), + // aszStatusFull[status], + // perStatus + //); + + BATTLE_BadStatusString( ToList[i], status ); + } + } + + // ΪԶʱ + + if(((gWeponType == ITEM_BOW) + || (gWeponType == ITEM_BOUNDTHROW) + || (gWeponType == ITEM_BREAKTHROW) + || (gWeponType == ITEM_BOOMERANG)) && !bChange){ + snprintf( szCommand, sizeof( szCommand ), "r%X|f%X|d%X|p%X|", ToList[i], flg, damage, petdamage ); + BATTLESTR_ADD( szCommand ); + }else{ + snprintf( szCommand, sizeof( szCommand ), "BH|a%X|r%X|f%X|d%X|p%X|FF|", attackNo, ToList[i], flg, damage, petdamage); + BATTLESTR_ADD( szCommand ); + } + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + j = ToList[i]-DefSide*SIDE_OFFSET; + if( ultimate > 0 ){ + BattleArray[battleindex].Side[DefSide].Entry[j].flg |= BENT_FLG_ULTIMATE; + } + + iRet = TRUE; + } + + // ΪԶʱ + if((( gWeponType == ITEM_BOW ) || ( gWeponType == ITEM_BOUNDTHROW ) || ( gWeponType == ITEM_BREAKTHROW ) || ( gWeponType == ITEM_BOOMERANG )) && !bChange){ + snprintf( szCommand, sizeof( szCommand ), "FF|" ); + BATTLESTR_ADD( szCommand ); + } + } + if(gWeponType == ITEM_BOOMERANG) gBattleDamageModyfy = 1.0; + break; + } +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_BOUNDARY: // Խ + { + int ToList[SIDE_OFFSET*2+1],status=-1,power=20,toindex=-1,loop=1; + int defNo2 = defNo;//CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM2); + int rand_boundary,rand_boundary2 = RAND( 1, 100 ); + + if( skill_level >= 10 ) turn = 5; + else if( skill_level > 9 ) turn = 4; + else if( skill_level > 8 ) turn = 3; + else if( skill_level > 4 ) turn = 2; + else turn = 1; + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + + if( skill_level >= 100 ) power = 100; + else if( skill_level > 95 ) power = 90; + else if( skill_level > 90 ) power = 80; + else if( skill_level > 85 ) power = 70; + else if( skill_level > 80 ) power = 60; + else if( skill_level > 60 ) power = 50; + else if( skill_level > 40 ) power = 40; + else if( skill_level > 20 ) power = 30; + else power = 20; + + if( ((pszP = strstr( pszOption, "ؽ" ) ) != NULL ) ) + status = CHAR_WORKFIXEARTHAT_BOUNDARY; + else if( ((pszP = strstr( pszOption, "ˮ" ) ) != NULL ) ) + status = CHAR_WORKFIXWATERAT_BOUNDARY; + else if( ((pszP = strstr( pszOption, "" ) ) != NULL ) ) + status = CHAR_WORKFIXFIREAT_BOUNDARY; + else if( ((pszP = strstr( pszOption, "" ) ) != NULL ) ){ + status = CHAR_WORKFIXWINDAT_BOUNDARY; + } + else{//ƽ + status = CHAR_WORKFIXEARTHAT_BOUNDARY; + + if( skill_level >= 100 ) rand_boundary = 100; + else if( skill_level > 80 ) rand_boundary = 80; + else if( skill_level > 40 ) rand_boundary = 70; + else if( skill_level > 20 ) rand_boundary = 60; + else rand_boundary = 50; + if( rand_boundary2 <= rand_boundary ){ + loop = 4; + power=0; + turn=0; + } + else + loop = 0; + } + + if( ((pszP = strstr( pszOption, "ƽ" ) ) != NULL ) ){ + if( defNo2 < 10 )defNo2 = 20; else defNo2 = 21; + } + + memset( ToList, -1, sizeof( ToList)); + BATTLE_MultiList( battleindex, defNo2, ToList ); + + if( ((pszP = strstr( pszOption, "ƽ" ) ) == NULL ) ){//Ȱн + for( j=CHAR_WORKFIXEARTHAT_BOUNDARY; j 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEREFLEC ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEREFLEC, max( work, 0 ) ); + defindex = attackindex; + defpet = attackpet; + + }else + if( *pRefrect == BATTLE_MD_TRAP ){ // + int value=0; + value = CHAR_getWorkInt( defindex, CHAR_WORKMODTRAP ); + damage = value; + + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= damage; + playerdamage = hp; + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= playerdamage; + pethp -= petdamage; + }else + hp -= damage; + } + + CHAR_setWorkInt( defindex, CHAR_WORKTRAP, 0 ); + CHAR_setWorkInt( defindex, CHAR_WORKMODTRAP, 0 ); + defindex = attackindex; + defpet = attackpet; + + }else +#ifdef _PETSKILL_ACUPUNCTURE +/* if( *pRefrect == BATTLE_MD_ACUPUNCTURE ){ + hp = CHAR_getInt( attackindex, CHAR_HP ); + if( attackpet == -1 ) { + hp -= ( damage/2 ? damage/2:1 ); + }else { + pethp = CHAR_getInt( attackpet, CHAR_HP ); + defquick = CHAR_getWorkInt( attackindex, CHAR_WORKDEFENCEPOWER ); + petquick = CHAR_getWorkInt( attackpet, CHAR_WORKDEFENCEPOWER ); + if( pethp > 0 ) { + playerdamage = (damage*petquick)/(defquick+petquick) +1; + petdamage = damage - playerdamage +1 ; + hp -= ( playerdamage/2 ? playerdamage/2:1 ); + pethp -= ( petdamage/2 ? petdamage/2:1 ); + }else + hp -= ( damage/2 ? damage/2:1 ); + } + //work = CHAR_getWorkInt( defindex, CHAR_WORKACUPUNCTURE ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKACUPUNCTURE, 0);//max( work, 0 ) ); + defindex = attackindex; + defpet = attackpet; + }*/ +#endif + if( react == BATTLE_MD_VANISH ){ + hp = CHAR_getInt( defindex, CHAR_HP ); + if( defpet != -1 ) + pethp = CHAR_getInt( defpet, CHAR_HP ); + work = CHAR_getWorkInt( defindex, CHAR_WORKDAMAGEVANISH ) - 1; + CHAR_setWorkInt( defindex, CHAR_WORKDAMAGEVANISH, max( work, 0 ) ); + *pRefrect = BATTLE_MD_VANISH; + }else{ + hp = CHAR_getInt( defindex, CHAR_HP ); + + if( defpet == -1 ) { + hp -= (damage * 0.7); + }else { + pethp = CHAR_getInt( defpet, CHAR_HP ); + if( pethp > 0 ) { + int rate=0; + rate = skill_level * 2 + 60; + + petdamage = damage * rate / 100; + playerdamage = damage - petdamage; + + hp -= playerdamage; + pethp -= petdamage; + + }else + hp -= damage; + } + *pRefrect = 0; + } + if( hp < 0 ){ + addpoint = -hp; + hp = 0; + } + maxhp = CHAR_getWorkInt( defindex, CHAR_WORKMAXHP ); + CHAR_setInt( defindex, CHAR_HP, min( hp, maxhp ) ); + if( defpet != -1 ) { + if( pethp < 0 ) pethp = 0; + petmaxhp = CHAR_getWorkInt( defpet, CHAR_WORKMAXHP ); + CHAR_setInt( defpet, CHAR_HP, min( pethp, petmaxhp ) ); + // Robin 0804 + if( pethp <= 0 ) { + CHAR_setInt( defindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( defindex ); + CHAR_setWorkInt( defindex, CHAR_WORKPETFALL, 1 ); + print(" defpet_die! "); + } + } + + if( (damage) >= maxhp * 1.2 + 20 ){ + IsUltimate = 2; + }else{ + if( addpoint > 0 ){ + addpoint += CHAR_getWorkInt( defindex, CHAR_WORKULTIMATE ); + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, addpoint ); + if( addpoint >= maxhp * 1.2 + 20 )IsUltimate = 1; + } + } + + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P ){ + } +#ifdef _PETSKILL_LER +// ׶ܱ + if(CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(defindex,CHAR_BASEBASEIMAGENUMBER) == 101814) IsUltimate = 0; +#endif + + if( IsUltimate ){ + CHAR_setWorkInt( defindex, CHAR_WORKULTIMATE, 0 ); + } + if( playerdamage < 0 ) playerdamage = 0; + if( petdamage < 0 ) petdamage = 0; + *pDamage = playerdamage; + *pPetDamage = petdamage; + return IsUltimate; +} + + +// ȡû˺ +int BATTLE_PROFESSION_CONVOLUTE_GET_DAMAGE( int attackindex, int defindex, int skill_level ) +{ + int damage = 0, old_atk = 0, atk = 0; + int rand_num = RAND(1, 10000 ); + // һ + int perCri = BATTLE_CriticalCheck( attackindex, defindex ); + + old_atk = CHAR_getWorkInt( attackindex, CHAR_WORKATTACKPOWER ); + atk = old_atk * (100 -( 50 - skill_level )) / 100; + CHAR_setWorkInt( attackindex, CHAR_WORKATTACKPOWER, atk ); + + if( rand_num < perCri ){ + damage = BATTLE_CriDamageCalc( attackindex, defindex ); + }else{ + //profession fix + if( BATTLE_DuckCheck( attackindex, defindex ) ) + return 0; + damage = BATTLE_DamageCalc( attackindex, defindex ); + } + + return damage; +} + +// ȡùᴩ˺ +int BATTLE_PROFESSION_THROUGH_ATTACK_GET_DAMAGE( int attackindex, int defindex ) +{ + int damage = 0; + int rand_num = RAND(1, 10000 ); + // һ + int perCri = BATTLE_CriticalCheck( attackindex, defindex ); + + if( rand_num < perCri ){ + damage = BATTLE_CriDamageCalc( attackindex, defindex ); + }else{ + //profession fix + if( BATTLE_DuckCheck( attackindex, defindex ) ) + return 0; + damage = BATTLE_DamageCalc( attackindex, defindex ); + } + + return damage; +} + +// 𡢱׸帽ӹ +int BATTLE_PROFESSION_RANG_ATTACK_DAMAGE( int charaindex, int attackNo, int defNo, int skill_type, int status, int turn, int perStatus, int effect, int img1, int img2 ) +{ + int ReactType = 0, iRet = -1,defindex = -1,react = 0; + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + //char szBuffer[256]=""; + + //memset( szBuffer, 0, sizeof( szBuffer ) ); + + defindex = BATTLE_No2Index( battleindex, defNo); //طindex + if( defindex == -1 ) return iRet; + + if( (ReactType=BATTLE_GetDamageReact( defindex)) > 0 ){ //й⾵ + react = ReactType; + skill_type=-1; + } + + if( img1 != 0 ){ + if( (PROFESSION_BATTLE_StatusAttackCheck( charaindex, defindex, status, perStatus ) == 0 ) + || (CHAR_getInt( defindex, CHAR_HP ) <= 0 ) ){ + //snprintf( szBuffer, sizeof(szBuffer), "(%s)޷(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), CHAR_getUseName( defindex ), aszStatusFull[status], perStatus ); + //BATTLE_BroadCast( battleindex, szBuffer,(attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + else{ + CHAR_setWorkInt( defindex, StatusTbl[status], turn + 1 ); + + if( status == BATTLE_ST_PARALYSIS + || status == BATTLE_ST_SLEEP + || status == BATTLE_ST_STONE + || status == BATTLE_ST_BARRIER + || status == BATTLE_ST_DIZZY + || status == BATTLE_ST_ENTWINE + || status == BATTLE_ST_DRAGNET + || status == BATTLE_ST_ICECRACK + || status == BATTLE_ST_ICEARROW + ) CHAR_setWorkInt( defindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( defindex ), + // aszStatusFull[status], + // perStatus + // ); + + BATTLE_BadStatusString( defNo, status ); + iRet = TRUE; + } + //BATTLE_BroadCast( battleindex, szBuffer,(attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + + return iRet; +} + +#endif + +#ifdef _PETSKILL_LER +extern ToCallMagic PROFESSION_magic[3]; +// ׶ - ȺĴ +void BATTLE_BatFly( int battleindex, int attackNo,int myside) +{ + int ToList[SIDE_OFFSET*2+1],i,toindex; + int petidx,addhp = 0,charhp,pethp,charaindex; + char szCommand[1024]; + + charaindex = BATTLE_No2Index(battleindex,attackNo); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; + + memset(ToList,-1,sizeof(ToList)); + if(myside) BATTLE_MultiList(battleindex,TARGET_SIDE_0,ToList); // + else BATTLE_MultiList(battleindex,TARGET_SIDE_1,ToList); // +#ifdef _FIX_LER_IMG + PROFESSION_magic[2].uiSpriteNum = myside ? 101859:101860; + PROFESSION_magic[2].siSx = 320; + PROFESSION_magic[2].siSy = 240; + PROFESSION_magic[2].uiPrevMagicNum = myside ? 101861:101862; // ǰö +#else + PROFESSION_magic[2].uiSpriteNum = myside ? 101806:101807; + PROFESSION_magic[2].siSx = 320; + PROFESSION_magic[2].siSy = 240; + PROFESSION_magic[2].uiPrevMagicNum = myside ? 101808:101809; // ǰö +#endif + PROFESSION_magic[2].uiPostMagicNum = 0xffffffff; // ö + PROFESSION_magic[2].uiShowType = 1; + PROFESSION_magic[2].uiShowBehindChar = 1; + PROFESSION_magic[2].siPrevMagicSx = 0; + PROFESSION_magic[2].siPrevMagicSy = 0; + PROFESSION_MAGIC_ATTAIC_Effect(battleindex,attackNo,ToList,2); + sprintf(szCommand,"%X|",0x5711438); + BATTLESTR_ADD(szCommand); + + for(i=0;i CHAR_getWorkInt(charaindex,CHAR_WORKMAXHP)){ + CHAR_setInt(charaindex,CHAR_HP,CHAR_getWorkInt(charaindex,CHAR_WORKMAXHP)); + addhp = 0; + } + else CHAR_setInt(charaindex,CHAR_HP,CHAR_getInt(charaindex,CHAR_HP) + addhp); + sprintf(szCommand,"BD|r%X|%X|1|d%X|p0|",attackNo,BD_KIND_HP,addhp); + BATTLESTR_ADD(szCommand); +} + +// ׶ - +void BATTLE_DivideAttack( int battleindex, int attackNo,int myside) +{ + int ToList[SIDE_OFFSET*2+1],i,toindex; + int petidx,charhp,charmp,pethp,charaindex; + char szCommand[1024]; + + charaindex = BATTLE_No2Index(battleindex,attackNo); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; + + memset(ToList,-1,sizeof(ToList)); + if(myside) BATTLE_MultiList(battleindex,TARGET_SIDE_0,ToList); // + else BATTLE_MultiList(battleindex,TARGET_SIDE_1,ToList); // + + PROFESSION_magic[2].uiSpriteNum = myside ? 101798:101800; + PROFESSION_magic[2].siSx = 320; + PROFESSION_magic[2].siSy = 240; + PROFESSION_magic[2].uiPrevMagicNum = myside ? 101808:101809; // ǰö + PROFESSION_magic[2].uiPostMagicNum = 0xffffffff; // ö + PROFESSION_magic[2].uiShowType = 1; + PROFESSION_magic[2].uiShowBehindChar = 0; + PROFESSION_magic[2].siPrevMagicSx = 0; + PROFESSION_magic[2].siPrevMagicSy = 0; + PROFESSION_MAGIC_ATTAIC_Effect(battleindex,attackNo,ToList,2); + sprintf(szCommand,"%X|",0x5711438); + BATTLESTR_ADD(szCommand); + + // ɿMPĶ + for(i=0;i>1)); + charmp >>= 1; + sprintf(szCommand,"BD|r%X|%X|0|d%X|",ToList[i],BD_KIND_MP,charmp); + BATTLESTR_ADD(szCommand); + } + } + for(i=0;i 10 ? 1:0); + } + else if(CHAR_getInt(charaindex,CHAR_BASEBASEIMAGENUMBER) == 101814){ + array = ENEMY_getEnemyArrayFromId(2510); + if(array == -1) return; + newindex = ENEMY_createEnemy(array,300); + if(newindex == -1) return; +#ifdef _FIX_LER_IMG + CHAR_setWorkInt(newindex,CHAR_WORK_RELIFE,101864); +#else + CHAR_setWorkInt(newindex,CHAR_WORK_RELIFE,101811); +#endif + CHAR_setWorkInt(newindex,CHAR_WORKBATTLESIDE,no > 10 ? 1:0); + } + pBattle = &BattleArray[battleindex]; + pEntry = pBattle->Side[no > 10 ? 1:0].Entry; + pEntry[no > 10 ? no-10:no].charaindex = newindex; + + BATTLE_Exit(charaindex,battleindex); +} +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +typedef struct _tsAttackObject{ + int index; // + int target; // Ŀ + int actionNumber; // ͼ +}AttackObject; +// BATTLE_BattleModel õĹʽ +void BATTLE_BattleModel_ATTACK( + int battleindex, + int charaindex, + AttackObject *pAAttackObject, + int iEffect, + int iTurn, + int iEffectHit, + int iType) +{ + int i,iDefindex,iPetindex,iToindex,iDamage,iPetDamage,iGuardian = -1,iDefState,iUltimate = 0,iTemp = 0,iTemp2 = 0,iFlg = 0; + char szCommand[1024]; + + // Ŀ治ڻû + if(!BATTLE_TargetCheck(battleindex,pAAttackObject->target)) return; + iToindex = iDefindex = BATTLE_No2Index(battleindex,pAAttackObject->target); + // dz,ڲڳ + if(CHAR_getInt(iToindex,CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + if(pAAttackObject->target + 5 >= SIDE_OFFSET) iFlg = 1; + i = pAAttackObject->target + 5 - iFlg * SIDE_OFFSET; + if(BattleArray[battleindex].Side[iFlg].Entry[i].flg & BENT_FLG_ULTIMATE) return; + } + iPetindex = BATTLE_getRidePet(iToindex); + // ˺ + iDefState = BATTLE_AttackSeq(charaindex,iToindex,&iDamage,&iGuardian,-1); + // iType & 0x00000004 Ϊ true ʾΪ + if(iType & 0x00000004){ + // Ȯû,趨Ȯ + if(BATTLE_TargetCheck(battleindex,iGuardian)){ + // Ȯ,ѱ趨ΪʹȮܵĽɫ,򱻹ΪԭĿ + if(iGuardian >= 0) iDefindex = BATTLE_No2Index(battleindex,iGuardian); + } + else iGuardian = -1; + } + // 趨 CHAR_NPCWORKINT1 Ϊ BATTLE_COM_S_BATTLE_MODEL BATTLE_DamageSub õ + iTemp2 = CHAR_getWorkInt(iDefindex,CHAR_NPCWORKINT1); + CHAR_setWorkInt(iDefindex,CHAR_NPCWORKINT1,BATTLE_COM_S_BATTLE_MODEL); + // ֮ iDefindex ˵Ŀ + if(gDamageDiv != 0.0 && iDamage > 0){ + iDamage /= gDamageDiv; + if(iDamage <= 0) iDamage = 1; + } + // ûһ,пѪ + if(!(iDefState == BATTLE_RET_DODGE)){ + // Ѫ + // + if(iType & 0x00000004) iUltimate = BATTLE_DamageSub(charaindex,iDefindex,&iDamage,&iPetDamage,&iTemp); + // + else{ + iTemp = -1; + iUltimate = BATTLE_DamageSub(charaindex,iDefindex,&iDamage,&iPetDamage,&iTemp); + } + } + iFlg = 0; + // ش״̬ + switch(iDefState){ + case BATTLE_RET_ALLGUARD:iFlg |= BCF_GUARD;break; + case BATTLE_RET_MISS:iDamage = 0;break; + case BATTLE_RET_DODGE:iDamage = 0;iFlg |= BCF_DODGE;break; + case BATTLE_RET_NORMAL: + iFlg |= BATTLE_getReactFlg(iDefindex,iTemp); + iFlg |= BCF_NORMAL; + break; + case BATTLE_RET_CRITICAL: + iFlg |= BATTLE_getReactFlg(iDefindex,iTemp); + iFlg |= BCF_KAISHIN; + break; +#ifdef _EQUIT_ARRANGE + case BATTLE_RET_ARRANGE:iFlg |= BCF_B_ARRANGE;break; +#endif + } + + //˯ʱ,״̬(Ҳ״̬) + if(iDamage > 0 && (iTemp != BATTLE_MD_ABSROB) && (iTemp != BATTLE_MD_VANISH)) BATTLE_DamageWakeUp(battleindex,iDefindex); + + // ĿǷ + if(CHAR_getInt(iDefindex,CHAR_HP) <= 0){ + if(CHAR_getWorkInt(iDefindex,CHAR_WORKBATTLEFLG ) & CHAR_BATTLEFLG_ABIO) iUltimate = 1; + else if(CHAR_getInt(iDefindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER && (iFlg & BCF_KAISHIN)){ + if(RAND(1,100) < 50) iUltimate = 1; + } +#ifdef _PETSKILL_LER + // ׶ܱ + if(CHAR_getInt(iDefindex,CHAR_BASEBASEIMAGENUMBER) == 101813 || + CHAR_getInt(iDefindex,CHAR_BASEBASEIMAGENUMBER) == 101814) iUltimate = 0; +#endif + iFlg |= BCF_DEATH; + if(iUltimate == 1) iFlg |= BCF_ULTIMATE_1; + if(iUltimate == 2) iFlg |= BCF_ULTIMATE_2; + } + else{ +#ifdef _TAKE_ITEMDAMAGE + if(BATTLE_ItemCrushSeq(charaindex,iDefindex,iDamage) == TRUE) +#else + if(BATTLE_ItemCrushSeq(iDefindex) == TRUE) +#endif + iFlg |= BCF_CRUSH; + // ״̬ж + if(iDamage > 0 && BATTLE_StatusAttackCheck(charaindex,iDefindex,iEffect,iEffectHit,30,1.0,&iTemp)){ + CHAR_setWorkInt(iDefindex,StatusTbl[iEffect],iTurn); + if(iEffect == BATTLE_ST_DRUNK) CHAR_setWorkInt(iDefindex,CHAR_WORKDRUNK,CHAR_getWorkInt(iDefindex,CHAR_WORKDRUNK) >> 1); + // ״̬Ŀûغ֮᲻ж + if(iEffect == BATTLE_ST_PARALYSIS || iEffect == BATTLE_ST_SLEEP || iEffect == BATTLE_ST_STONE || iEffect == BATTLE_ST_BARRIER) + CHAR_setWorkInt(iDefindex,CHAR_WORKBATTLECOM1,BATTLE_COM_NONE); + // شclientһĿҪִ״̬ı + if(iGuardian >= 0) BATTLE_BadStatusString(iGuardian,iEffect); // iGuardian 춵 0 ʾĿʹȮ,Ŀ״̬ı + else BATTLE_BadStatusString(pAAttackObject->target,iEffect); // ԭĿ״̬ı + } + } + if(iGuardian >= 0){ + iFlg |= BCF_GUARDIAN; + snprintf(szCommand,sizeof(szCommand), + "r%X|i%X|f%X|d%X|p%X|a%X|g%X|", + pAAttackObject->target, + pAAttackObject->index, + iFlg, + iDamage, + iPetDamage, + pAAttackObject->actionNumber, + iGuardian); + }else + snprintf(szCommand,sizeof(szCommand), + "r%X|i%X|f%X|d%X|p%X|a%X|", + pAAttackObject->target, + pAAttackObject->index, + iFlg, + iDamage, + iPetDamage, + pAAttackObject->actionNumber); + + // 봫clientbuffer + BATTLESTR_ADD(szCommand); + + iTemp = BATTLE_Index2No(battleindex,iDefindex); + + // iFlg û,; + iFlg = 0; + if(iTemp >= SIDE_OFFSET) iFlg = 1; + + i = iTemp - iFlg * SIDE_OFFSET; + if(iUltimate > 0) BattleArray[battleindex].Side[iFlg].Entry[i].flg |= BENT_FLG_ULTIMATE; + CHAR_setWorkInt(iDefindex,CHAR_NPCWORKINT1,iTemp2); +} + +void BATTLE_BattleModel(int battleindex,int attackNo,int myside) +{ + int iToList[SIDE_OFFSET*2+1],i,i0,i1,i2,iEffect = -1,iTurn = -1,iEffectHit = 0,iType,iObjectNum,charaindex; + int iActionNumber[4] = {-1,-1,-1,-1},iActionAmount = 0; + char szData[32],szData2[32],*pszOption = NULL; + AttackObject AAttackObject[10]; + + charaindex = BATTLE_No2Index(battleindex,attackNo); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; + + pszOption = PETSKILL_getChar(CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM3),PETSKILL_OPTION); + + if(pszOption == "\0"){ + printf("BATTLE_BattleModel: read PETSKILL_OPTION error!!(array:%d,file:%s,line:%d)\n", + CHAR_getWorkInt(charaindex,CHAR_WORKBATTLECOM3),__FILE__,__LINE__); + return; + } + + // ȡЧ + if(getStringFromIndexWithDelim(pszOption,"|",3,szData,sizeof(szData)) != FALSE){ + for(i=1;i= iActionAmount) i1 = 0; + } + + // 鳡Ŀʣֻ + for(i=0;i= i){ + i0 = i; // ¼Ŀֻ + + for(i=0;i +#include "char.h" +#include "char_base.h" +#include "battle.h" +#include "battle_event.h" +#include "battle_item.h" +#include "battle_magic.h" +#include "item_event.h" +#include "log.h" +#include "anim_tbl.h" +#include "npcutil.h" +#include "magic_base.h" +#include "lssproto_serv.h" +#include "magic.h" + +int BATTLE_ItemUseDelete( + int charaindex, + int haveitemindex +) +{ + int itemindex; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( ITEM_CHECKINDEX( itemindex ) == FALSE ) return 0; + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "BattleUse(սʹõĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); + + return 0; +} + +#ifdef _IMPRECATE_ITEM +void ITEM_useImprecate( int charaindex, int toNo, int haveitemindex ) +{ + int i; + int battleindex, attackNo,itemindex; + char *arg; + char buf[256]; + + struct tagImprecate { + char fun[256]; + int intfun; + }; + struct tagImprecate ImList[3] ={ + {"",BD_KIND_CURSE},{"",BD_KIND_BESTOW},{"ף",BD_KIND_WISHES} }; + + if( !CHAR_CHECKINDEX( charaindex) ) return; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + if( (attackNo = BATTLE_Index2No( battleindex, charaindex )) < 0 ){ + print( "ANDY attackNo=%d\n", attackNo); + return; + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" ){ + print( "ANDY ITEM id:%d=>arg err\n", ITEM_getInt( itemindex, ITEM_ID)); + return; + } + + for( i=0; i<3; i++) { + if( strstr( arg, ImList[i].fun ) != 0 ) { + char buf1[256]; + int kind,powers, rounds, HealedEffect; + + if( NPC_Util_GetStrFromStrWithDelim( arg, ImList[i].fun, buf, sizeof( buf)) == NULL )continue; + kind = ImList[i].intfun; + if( getStringFromIndexWithDelim( buf,"x", 1, buf1, sizeof( buf1)) == FALSE ) continue; + powers = atoi( buf1); + if( getStringFromIndexWithDelim( buf,"x", 2, buf1, sizeof( buf1)) == FALSE ) continue; + rounds = atoi( buf1); + HealedEffect = SPR_hoshi; + BATTLE_ImprecateRecovery( + battleindex, attackNo, toNo, kind, powers, + rounds, SPR_item3, HealedEffect ); + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne( itemindex ); + break; + } + } +} +#endif + +#ifdef _ITEM_MAGICRECOVERY +void ITEM_useMRecovery_Battle( int charaindex, int toNo, int haveitemindex ) +{ + int battleindex, attackNo, itemindex; + int turn=0, magicid, marray; + char buf1[256]; + char *arg=NULL; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return; + if( (attackNo = BATTLE_Index2No( battleindex, charaindex )) == -1 ) return; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar( itemindex, ITEM_ARGUMENT ); + + + if( getStringFromIndexWithDelim( arg, ":", 2, buf1, sizeof(buf1)) ==FALSE ) return; + turn = atoi( buf1); + if( getStringFromIndexWithDelim( arg, ":", 1, buf1, sizeof(buf1)) ==FALSE ) return; + + if( strstr( buf1, "ȫ" ) != NULL ){ + }else{ + } + + magicid = ITEM_getInt( itemindex, ITEM_MAGICID); + marray = MAGIC_getMagicArray( magicid); + if( marray == -1 ) return; + + + if( IsBATTLING( charaindex ) == TRUE ){ + int i, status=-1; + char *magicarg=NULL, *pszP=NULL; +#ifdef _PREVENT_TEAMATTACK //⾵..ʹõз + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + //&& BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P + ){ + if( BATTLE_CheckSameSide( charaindex, toNo) == 0 ){//ͬ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "⾵..ʩҵз", CHAR_COLORYELLOW); + return; + } + } +#endif + + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + pszP = magicarg; + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + if( strncmp( pszP, aszMagicDef[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + if( status == -1 ) return; + + BATTLE_MultiMagicDef( battleindex, attackNo, toNo, + status, turn, MAGIC_EFFECT_USER, SPR_difence ); + + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "BattleUse(սʹõĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + + CHAR_DelItemMess( charaindex, haveitemindex, 0); +} +#endif + +#ifdef _ITEM_USEMAGIC +void ITEM_useMagic_Battle( int charaindex, int toNo, int haveitemindex ) +{ + int itemindex,itemmaxuse; + char *arg=NULL; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar( itemindex, ITEM_ARGUMENT ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_JYUJYUTU ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, atoi(arg) ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + MAGIC_DirectUse( + charaindex, + CHAR_GETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3 ), + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2 ), + CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3 ) + ); + + itemmaxuse = ITEM_getInt( itemindex, ITEM_DAMAGEBREAK); + if( itemmaxuse > 0 ) + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, itemmaxuse-1 ); + else{ + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "BattleUse(սʹõĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + + CHAR_DelItemMess( charaindex, haveitemindex, 0); + } +} +#endif + +void ITEM_useRecovery_Battle( int charaindex, int toNo, int haveitemindex ) +{ + int power = 0, per = 0, HealedEffect=0; + int battleindex, attackNo,itemindex, kind = BD_KIND_HP; + char *p = NULL, *arg; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( (p = strstr( arg, "" )) != NULL ) + { + kind = BD_KIND_HP; + } + else if( (p = strstr( arg, "" )) != NULL ) + { + kind = BD_KIND_MP; + } + else +#ifdef _ITEM_UNBECOMEPIG + if( (p = strstr( arg, "" )) != NULL ){ + kind = BD_KIND_UNBECOMEPIG; + HealedEffect = 100608; //Ч + } + else +#endif +#ifdef _ITEM_LVUPUP + if( (p = strstr( arg, "LVUPUP" )) != NULL ){ + return; + } + else +#endif +#ifdef _ITEM_PROPERTY + if( (p = strstr( arg, "PROPERTY" )) != NULL ){ + kind = BD_KIND_PROPERTY; + HealedEffect = 100608; //Ч + if( strstr( arg, "+" ) ) + power = 1; + else if( strstr( arg, "-" ) ) + power = 2; + } + else +#endif +#ifdef _ITEM_ADDPETEXP + if( (p = strstr( arg, "GETEXP" )) != NULL ){ + return; + } + else +#endif + return; + +#ifdef _ITEM_UNBECOMEPIG + if( HealedEffect != 100608 ){ +#endif + if( sscanf( p+2, "%d", &power ) != 1 ) + power = 0; + if( power <= 100 ) + HealedEffect = SPR_heal;//SPR_hoshi + else if( power <= 300 ) + HealedEffect = SPR_heal2; + else + HealedEffect = SPR_heal3; +#ifdef _ITEM_UNBECOMEPIG + } +#endif + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + if( attackNo < 0 )return; + BATTLE_MultiRecovery( battleindex, attackNo, toNo,kind, power, per, SPR_item3, HealedEffect ); + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "BattleUse(սʹõĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); +} + +void ITEM_useStatusChange_Battle( + int charaindex, + int toNo, + int haveitemindex +){ + int turn = 0, i; + int battleindex, attackNo,itemindex, status = -1, Success = 15; + int ReceveEffect; + char *pszP = NULL, *arg; + char szTurn[] = "turn"; + char szSuccess[] = ""; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + pszP = arg; + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 0; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + if( status == -1 ) return ; + if( ( pszP = strstr( arg, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + if( ( pszP = strstr( arg, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; + }else{ + ReceveEffect = SPR_hoshi; + } + BATTLE_MultiStatusChange( battleindex, attackNo, toNo, + status, turn, SPR_item3, ReceveEffect, Success ); + BATTLE_ItemUseDelete( charaindex, haveitemindex ); +} + +void ITEM_useStatusRecovery_Battle( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +){ + int i; + int battleindex, attackNo,itemindex, status = -1; + int ReceveEffect; + char *pszP = NULL, *arg; + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + // ɷ¶ë + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + pszP = arg; + // ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + // ؤ¼ƥ߾ո + for( i = 0; i < BATTLE_ST_END; i ++ ){ + // + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( status == -1 ) return ; + + //------- ռ ----------- + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + ReceveEffect = SPR_tyusya; // 巴ľ + + // 幻 + BATTLE_MultiStatusRecovery( battleindex, attackNo, toNo, + status, SPR_item3, ReceveEffect ); + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + +} + + + + + + +void ITEM_useMagicDef_Battle( + int charaindex, + int toNo, + int haveitemindex +) +{ + int turn = 0, i; + int battleindex, attackNo,itemindex, status = -1; + char *pszP = NULL, *arg; + + char szTurn[] = "turn"; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + pszP = arg; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + if( strncmp( pszP, aszMagicDef[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return ; + + if( ( pszP = strstr( arg, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + BATTLE_MultiMagicDef( battleindex, attackNo, toNo, + status, turn, SPR_item3, SPR_difence ); + + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + + +} + + + + + + +//-------------------------------------------------------------- +// ɷ¶ ʧ ةë +//-------------------------------------------------------------- +// +void ITEM_useParamChange_Battle( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +) +{ + int i; + int battleindex, attackNo,itemindex; + int pow, par = 0; + int kind = -1; + char *pszP = NULL, *arg; + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + // ɷ¶ë + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + pszP = arg; + // ë + for( ;kind == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + // + if( strncmp( pszP, aszParamChange[i], 2 ) == 0 ){ + kind = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( kind == -1 ) return ; + + + if( strstr( pszP, "%" ) ){ // ѻң + par = 1; + } + + if( sscanf( pszP, "%d", &pow ) != 1 ){ + // Ϻ̼ؤ¾ + pow = 30; + } + + //------- ----------- + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiParamChange( battleindex, attackNo, toNo, + kind, pow, par, SPR_item3, SPR_hoshi ); + + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + + +} + + + + + + +//-------------------------------------------------------------- +// ū ʧ ةë +//-------------------------------------------------------------- +// +void ITEM_useFieldChange_Battle( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +) +{ + int itemindex; + char *pArg; + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + //------- ----------- + // ɷ¶ë + pArg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + // ɷ¶ мƥ + if( pArg == "\0" )return ; + + BATTLE_FieldAttChange( charaindex, pArg ); + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + +} + + +//-------------------------------------------------------------- +// ʧ ةë +//-------------------------------------------------------------- +// +void ITEM_useAttReverse_Battle( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +) +{ + int itemindex, battleindex, attackNo; + + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + //------- ----------- + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiAttReverse( battleindex, attackNo, toNo, + SPR_item3, SPR_kyu ); + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + + +} + + +//-------------------------------------------------------------- +// 姾ë +//-------------------------------------------------------------- +// +void ITEM_useRessurect( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +) +{ + int itemindex, battleindex, attackNo, par = 0, pow = 0, ReceveEffect; + char *pszP = NULL; + + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + //------- ----------- + pszP = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + if( strstr( pszP, "%" ) ){ // ѻң + par = 1; + } + + if( sscanf( pszP, "%d", &pow ) != 1 ){ + // Ϻ̼¾ + pow = 0; // ߼ + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + if( pow <= 0 ){ + ReceveEffect = SPR_fukkatu3; + }else + if( pow <= 100 ){ + ReceveEffect = SPR_fukkatu1; + }else + if( pow <= 300 ){ + ReceveEffect = SPR_fukkatu2; + }else{ + ReceveEffect = SPR_fukkatu3; + } + + // 幻 + BATTLE_MultiRessurect( battleindex, attackNo, toNo, + pow, par, SPR_item3, ReceveEffect ); + + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + +} + + + +//-------------------------------------------------------------- +// Ĥë +//-------------------------------------------------------------- +// +void ITEM_useCaptureUp_Battle( + int charaindex, // м̼͵ + int toNo, // ľм į + int haveitemindex // мʧ ة į +) +{ + int itemindex, battleindex, attackNo, pow = 5, ReceveEffect; + char *pArg; + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + //------- ----------- + // ɷ¶ë + pArg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + // ɷ¶ мƥ + if( pArg == "\0" )return ; + + if( sscanf( pArg, "%d", &pow ) != 1 ){ + // Ϻ̼¾ + pow = 5; + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + ReceveEffect = SPR_hoshi; + + // 幻 + BATTLE_MultiCaptureUp( battleindex, attackNo, toNo, + pow, SPR_item3, ReceveEffect ); + + // ʧ ةɧ + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + +} +#ifdef _ITEM_CRACKER +void ITEM_useCracker_Effect( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,x,y,tofd; + + itemindex = CHAR_getItemIndex(charaindex,haveitemindex); + // Ʒ + if(!ITEM_CHECKINDEX(itemindex)) return; + + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); + + CHAR_setMyPosition( charaindex, x, y, TRUE); + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_CRACKER, 1); + CHAR_sendCrackerEffect( charaindex, 101125); + //to client + tofd = getfdFromCharaIndex( charaindex ); + lssproto_IC_send(tofd, x, y); + // + BATTLE_ItemUseDelete(charaindex,haveitemindex); + CHAR_talkToCli(charaindex,-1,"ʧˡ",CHAR_COLORYELLOW); + +} +#endif +#ifdef _ITEM_REFRESH //vincent 쳣״̬ +void ITEM_useRefresh_Effect( int charaindex, int toindex, int haveitemindex) +{ + int i,itemindex,ReceveEffect; + char *arg; +// char szBuffer[128]=""; + int status = -1,attackNo,index2; + int battleindex; + char *pszP; + +//print("\nvincent--ITEM_useRefresh_Effect"); + // Ʒ + itemindex = CHAR_getItemIndex(charaindex,haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + pszP = arg; + // ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + // ྮո + for( i = 1; i < BATTLE_ST_END; i ++ ){ + // + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } +//print("\nvincent-->status:%d",status); + // ئмƥ + if( status == -1 ) return; + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + index2 = BATTLE_No2Index( battleindex, toindex);//Ŀ֮index + attackNo = BATTLE_Index2No( battleindex, charaindex ); +// defNo = BATTLE_Index2No( battleindex, index2 ); +//print("\nvincent-->charaindex:%d,attackNo:%d,index2:%d,defNo:%d,",charaindex,attackNo,index2,defNo); + + /* ƽҷ ջ */ + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex);/* ʧ ةޥ */ +// if( CHAR_getWorkInt( charaindex, StatusTbl[status] ) > 0 ){ +// ReceveEffect = SPR_tyusya; +// }else{ +// ReceveEffect = SPR_hoshi; +// } + ReceveEffect = SPR_tyusya;// + BATTLE_MultiStatusRecovery( battleindex, attackNo, toindex, + status, MAGIC_EFFECT_USER, ReceveEffect ); + /* */ + ITEM_endExistItemsOne( itemindex ); +////////////////////////// +// BATTLE_MultiList( battleindex, defNo, ToList ); +// for( i = 0; ToList[i] != -1; i ++ ){ +// toindex = BATTLE_No2Index( battleindex, ToList[i] ); +// +// } + + + +//////////////////////////// +} +#endif +#ifdef _ITEM_ADDEXP //vincent +void ITEM_useAddexp_Effect( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,power,vtime; + //,pindex + char *p = NULL, *arg; + char szBuffer[1024]=""; + + itemindex = CHAR_getItemIndex(charaindex,haveitemindex); + + // Ʒ + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + if( (p = strstr( arg, "" )) != NULL ){ + sscanf( p+2, "%d", &power ); + } + if( (p = strstr( arg, "" )) != NULL ){ + sscanf( p+2, "%d", &vtime ); + } + if( p == NULL )return; +#ifdef _FIX_ADD_EXP + if( power == CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXP)){ + vtime += CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXPTIME)/60; + } + if( vtime >= 172800) { + CHAR_talkToCli( charaindex, -1, "ǻ֮ۼʱ估ЧѴޡ", CHAR_COLORYELLOW); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKITEM_ADDEXPTIME, vtime*60 ); + +#else +#ifdef _ITEM_ADDEXP2 // ǹʱۼ + { + int point; + point = CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXP) + * (int)(CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXPTIME)/60); + if( point >= 72000) { + CHAR_talkToCli( charaindex, -1, "ǻ֮ۼʱ估ЧѴޡ", CHAR_COLORYELLOW); + return; + } + point += (power * vtime); + point = min( point, 72000); + vtime = (int)(point / power); + } + CHAR_setWorkInt( toindex, CHAR_WORKITEM_ADDEXPTIME,vtime*60 ); +#endif +#endif + CHAR_setWorkInt( toindex, CHAR_WORKITEM_ADDEXP, power); + + CHAR_setInt( toindex, CHAR_ADDEXPPOWER, + CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXP) ); + CHAR_setInt( toindex, CHAR_ADDEXPTIME, + CHAR_getWorkInt( toindex, CHAR_WORKITEM_ADDEXPTIME) ); + + // + BATTLE_ItemUseDelete(charaindex,haveitemindex); + //sprintf(szBuffer, "ѧϰ%d", power); + sprintf(szBuffer, "%sѧϰ%dʱЧʣ%dӡ", CHAR_getChar( toindex, CHAR_NAME), power, vtime); + CHAR_talkToCli(charaindex,-1,szBuffer,CHAR_COLORYELLOW); + +} +#endif +//Terry add 2001/12/24 +#ifdef _ITEM_FIRECRACKER +void ITEM_useFirecracker_Battle( int charaindex, int toindex, int haveitemindex) +{ + int itemindex, battleindex, masteridx=-1, index2; + + char szWork[128]; +#ifdef _FIX_FIRECRACKER + int petid=-1, i=1; + BOOL FINDPET=FALSE; + char *buff1; + char token[256], buf1[256]; +#else + int PetEscape = 0; +#endif + + itemindex = CHAR_getItemIndex(charaindex,haveitemindex); + // Ʒ + if(!ITEM_CHECKINDEX(itemindex)) return; + + battleindex = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEINDEX); +#ifdef _FIX_FIRECRACKER + index2 = BATTLE_No2Index( battleindex, toindex); + if( !CHAR_CHECKINDEX( index2) ) return; + { + int attackNo = BATTLE_Index2No( battleindex, charaindex ); + int safeSide = 0; + int MySide_start, MySide_end; + if( attackNo >= 10 ) + safeSide = 1; + + MySide_start = safeSide*SIDE_OFFSET; + MySide_end = ((safeSide*SIDE_OFFSET) + SIDE_OFFSET); + + if( (toindex >= MySide_start) && (toindex= 901 && CHAR_getInt(index2,CHAR_PETID) <= 904){ + // ȡĿ᷽Ľɫindex + masteridx = BATTLE_No2Index(battleindex,toindex-5); + // ս + if(CHAR_getInt(masteridx,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) PetEscape = 1; + else print("\nʱ"); + } + } + + // ըԼ + if(BATTLE_Index2No(battleindex,charaindex) != toindex) + { + sprintf(szWork,"BB|a%X|w3|r%X|f0|d0|p0|FF|",BATTLE_Index2No(battleindex,charaindex),toindex); + BATTLESTR_ADD(szWork); + if(PetEscape) + { + BATTLE_Exit(index2,battleindex); + CHAR_setInt(masteridx,CHAR_DEFAULTPET,-1); + sprintf(szWork,"BQ|e%X|",toindex); + BATTLESTR_ADD(szWork); + CHAR_talkToCli(masteridx,-1,"ޱˣ",CHAR_COLORWHITE); + CHAR_talkToCli(charaindex,-1,"ޱˣ",CHAR_COLORWHITE); + } + } + CHAR_talkToCli(charaindex,-1,"ʲ¶û",CHAR_COLORWHITE); + CHAR_talkToCli(charaindex,-1,"ʧˡ",CHAR_COLORWHITE); + // ʹʧ + BATTLE_ItemUseDelete(charaindex,haveitemindex); +#endif +} +#endif + +//Terry end + + + + +//״̬ظ,Ӹ(,,) ͬħ(,,),ֻս֮ʹ,û +// :ֵ turn 1 +#ifdef _FEV_ADD_NEW_ITEM // FEV ADD Ӹؾ +void ITEM_ResAndDef( int charaindex, int toindex, int haveitemindex ) +{ + int itemindex, battleindex = 0, attackNo, par = 0, pow = 0, ReceveEffect; + char *buffer = NULL; + char *magicarg = NULL; + char *magicarg2 = NULL; + char *magicarg3 = NULL; + char magicarg4[200]; + + char *pszP = NULL; + char delim[] = " ";//ЭִֽԪ + + int status = -1, i, turn = 3; + char szTurn[] = "turn"; + + // ʧ ةؤ¾ + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + buffer = ITEM_getChar(itemindex, ITEM_ARGUMENT );//ִ + pszP = strtok(buffer, delim);//һ + magicarg = strtok(NULL, delim);//ڶ + magicarg2 = strtok(NULL, delim);// + magicarg3 = strtok(NULL, delim);//ĸ + sprintf(magicarg4,"%s %s %s",magicarg,magicarg2,magicarg3); + magicarg = (char*)magicarg4; +#ifdef _PREVENT_TEAMATTACK + //⾵..ʹõз + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + //&& BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P + ){ + if( BATTLE_CheckSameSide( charaindex, toindex) == 0 ){//ͬ + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "⾵..ʩҵз", CHAR_COLORYELLOW); + return; + } + } +#endif + //״̬ظ + if( strstr( pszP, "%" ) ){ + par = 1; + } + + if( sscanf( pszP, "%d", &pow ) != 1 ){ + pow = 0; + } + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + //ѡЧ + if( pow <= 0 ){ + ReceveEffect = SPR_fukkatu3; + }else + if( pow <= 100 ){ + ReceveEffect = SPR_fukkatu1; + }else + if( pow <= 300 ){ + ReceveEffect = SPR_fukkatu2; + }else{ + ReceveEffect = SPR_fukkatu3; + } + + BATTLE_MultiRessurect( battleindex, attackNo, toindex, + pow, par, SPR_item3, ReceveEffect ); + + + //(,,) + + // ë + for( ;status == -1 && magicarg[0] != 0; magicarg++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + // + if( strncmp( magicarg, aszMagicDef[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( status == -1 ) return; + + // ϼ ʽ¾ + if( ( magicarg = strstr( magicarg, szTurn ) ) != NULL){ + magicarg += sizeof( szTurn ); + sscanf( magicarg, "%d", &turn ); + } + + //print(":%d",turn); + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiMagicDef( battleindex, attackNo, toindex, + status, turn, MAGIC_EFFECT_USER, SPR_difence ); + + + BATTLE_ItemUseDelete( charaindex, haveitemindex ); + +} + +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_magic.c b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_magic.c new file mode 100644 index 0000000..efa448e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/battle_magic.c @@ -0,0 +1,5446 @@ +#include "version.h" +#include +#include"char.h" +#include"char_base.h" +#include"battle.h" +#include"battle_event.h" +#include"magic_base.h" +#include"battle_magic.h" +#include"item_event.h" +#include"anim_tbl.h" +#include"common.h" +#include"lssproto_serv.h" + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#include "skill.h" +#endif + +#ifdef _ATTACK_MAGIC + +extern AttMagic *ATTMAGIC_magic; +extern int ATTMAGIC_magicnum; + +#define AJ_SAME (1.0) +#define AJ_UP (1.5) +#define AJ_DOWN (0.6) + +#define ATTR_MAX 100 +#define D_ATTR (1.0/(ATTR_MAX*ATTR_MAX)) +#ifdef _FIX_MAGICDAMAGE +static int BATTLE_getMagicAdjustInt( int attackindex, int defindex, int MagicLv, int flg,int damage ); +void Magic_ComputeAttExp( int charindex, int Mnum, int MagicLv, int Expoint); +void Magic_ComputeDefExp( int charindex, int Mnum, int MagicLv, int Damage); +#endif + +#ifdef _MAGIC_TOCALL +/* +typedef struct tagToCallMagic +{ + unsigned int uiSpriteNum; // Spr_x.binı + unsigned int uiAttackType; // ķʽˣ( ) , ( ) , ( ͬʱ ) , ȫ( ) , ȫ( ͬʱ ) + unsigned int uiSliceTime; // ʱʱ + unsigned int uiShowType; // ʾλ÷ʽ롢ָ + int siSx; // ʾλ - X + int siSy; // ʾλ - Y + unsigned int uiShowBehindChar; // ʾǰ· + unsigned int uiShakeScreen; // Ƿ𶯻 + unsigned int uiShakeFrom; // 𶯻ʼʱ( ) + unsigned int uiShakeTo; // 𶯻Ľʱ( _ + unsigned int uiPrevMagicNum; // ǰ( 0XFFFFFFFFFF ʾǰ ) + int siPrevMagicSx; // ǰʾλ - X + int siPrevMagicSy; // ǰʾλ - Y + int siPrevMagicOnChar; // ǰʾǰ· + unsigned int uiPostMagicNum; // ( 0XFFFFFFFF ʾ ) + int siPostMagicSx; // ʾλ - X + int siPostMagicSy; // ʾλ - Y + int siPostMagicOnChar; // ʾǰ· + int isPostDisappear; // һ㹥ʱǷʧ + int ToCallMagicNo; // ٻı +}ToCallMagic; +*/ + +ToCallMagic TOCALL_magic[3] = { {100354,0,0,0,50,25,1,0,0,0,101120,65528,65485,0,-1,0,0,0,1,0}, + {100354,1,0,0,50,25,1,0,0,0,101120,65528,65485,0,-1,0,0,0,1,1}, + {100354,5,0,0,0,0,1,1,1000,4000,101120,65528,65485,0,-1,0,0,0,0,2}, + }; + +#endif + +// ħȼ辭ֵ +int Magic_Level_Table[101] = +{ + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, //lv 1~10 + 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, //lv 11~20 + 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, //lv 21~30 + 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, //lv 31~40 + 861, 903, 946, 990,1035,1081,1128,1176,1225,1275, //lv 41~50 + 1326,1378,1431,1485,1540,1596,1653,1711,1770,1830, //lv 51~60 + 1891,1953,2016,2080,2145,2211,2278,2346,2415,2485, //lv 61~70 + 2556,2628,2701,2775,2850,2926,3003,3081,3160,3240, //lv 71~80 + 3321,3403,3486,3570,3655,3741,3828,3916,4005,4095, //lv 81~90 + 4186,4278,4371,4465,4560,4656,4753,4851,4950,5050, //lv 91~100 + 9999 +}; +#endif + +int BATTLE_MagicEffect( int battleindex, int attackNo, int ToList[], int MyEffect, int ToEffect ) +{ + int i; + char szCommand[256]; + int attackindex; + + attackindex = BATTLE_No2Index( battleindex, attackNo ); + if( CHAR_CHECKINDEX( attackindex ) == FALSE )return 0; + + snprintf( szCommand, sizeof(szCommand), + "BJ|a%X|m%X|e%X|e%X|", + attackNo, + CHAR_getInt( attackindex, CHAR_MP ), + MyEffect, + ToEffect + ); + + + BATTLESTR_ADD( szCommand ); + + for( i = 0; ToList[i] != -1; i ++ ){ + snprintf( szCommand, sizeof(szCommand), "r%X|",ToList[i]); + BATTLESTR_ADD( szCommand ); + } + BATTLESTR_ADD( "FF|" ); + + return 0; +} + +#ifdef _ATTACK_MAGIC + +int BATTLE_AttMagicEffect( int battleindex , int attackNo , int ToList[] , int AttackMgcNo ) +{ + int i; + char szcommand[256]; + int attackindex; + + attackindex = BATTLE_No2Index( battleindex , attackNo ); + if( FALSE == CHAR_CHECKINDEX( attackindex ) ) + return 0; + + if( attackNo >= 10 ) + i = AttackMgcNo * 2; + else + i = AttackMgcNo * 2 + 1; + + snprintf( + szcommand , sizeof( szcommand ) , "BJ|a%X|i%X|m%X|%X|%X|%X|s%X|t%X|l%X|%X|%X|%X|%X|%X|%X|o%X|o%X|o%X|s%X|%X|%X|" , + attackNo , 12345678 , CHAR_getInt( attackindex , CHAR_MP ) , + ATTMAGIC_magic[i].uiPrevMagicNum , + ATTMAGIC_magic[i].uiSpriteNum , + ATTMAGIC_magic[i].uiPostMagicNum , + ATTMAGIC_magic[i].uiAttackType , + ATTMAGIC_magic[i].uiSliceTime , + ATTMAGIC_magic[i].uiShowType , + ATTMAGIC_magic[i].siSx , + ATTMAGIC_magic[i].siSy , + ATTMAGIC_magic[i].siPrevMagicSx , + ATTMAGIC_magic[i].siPrevMagicSy , + ATTMAGIC_magic[i].siPostMagicSx , + ATTMAGIC_magic[i].siPostMagicSy , + ATTMAGIC_magic[i].siPrevMagicOnChar , + ATTMAGIC_magic[i].uiShowBehindChar , + ATTMAGIC_magic[i].siPostMagicOnChar , + ATTMAGIC_magic[i].uiShakeScreen , + ATTMAGIC_magic[i].uiShakeFrom , + ATTMAGIC_magic[i].uiShakeTo + ); + + BATTLESTR_ADD( szcommand ); + + for( i = 0 ; ToList[i] != -1 ; i++ ) + { + snprintf( szcommand , sizeof( szcommand ) , "r%X|" , ToList[i] ); + BATTLESTR_ADD( szcommand ); + } + + BATTLESTR_ADD( "FF|" ); + + return 0; +} + +#endif + + +#ifdef _MAGIC_TOCALL + +int BATTLE_ToCallDragonEffect( int battleindex , int attackNo , int ToList[] , int AttackMgcNo ) +{ + int i; + char szcommand[256]; + int attackindex; + + attackindex = BATTLE_No2Index( battleindex , attackNo ); + if( FALSE == CHAR_CHECKINDEX( attackindex ) ) + return 0; +/* + if( attackNo >= 10 ) + i = AttackMgcNo * 2; + else + i = AttackMgcNo * 2 + 1; +*/ + snprintf( + szcommand , sizeof( szcommand ) , "B$|a%X|i%X|m%X|%X|%X|%X|s%X|t%X|l%X|%X|%X|%X|%X|%X|%X|o%X|o%X|o%X|s%X|%X|%X|%X|%X|" , + attackNo , 5711438 , CHAR_getInt( attackindex , CHAR_MP ) , + TOCALL_magic[AttackMgcNo].uiPrevMagicNum , + TOCALL_magic[AttackMgcNo].uiSpriteNum , + TOCALL_magic[AttackMgcNo].uiPostMagicNum , + TOCALL_magic[AttackMgcNo].uiAttackType , + TOCALL_magic[AttackMgcNo].uiSliceTime , + TOCALL_magic[AttackMgcNo].uiShowType , + TOCALL_magic[AttackMgcNo].siSx , + TOCALL_magic[AttackMgcNo].siSy , + TOCALL_magic[AttackMgcNo].siPrevMagicSx , + TOCALL_magic[AttackMgcNo].siPrevMagicSy , + TOCALL_magic[AttackMgcNo].siPostMagicSx , + TOCALL_magic[AttackMgcNo].siPostMagicSy , + TOCALL_magic[AttackMgcNo].siPrevMagicOnChar , + TOCALL_magic[AttackMgcNo].uiShowBehindChar , + TOCALL_magic[AttackMgcNo].siPostMagicOnChar , + TOCALL_magic[AttackMgcNo].uiShakeScreen , + TOCALL_magic[AttackMgcNo].uiShakeFrom , + TOCALL_magic[AttackMgcNo].uiShakeTo , + TOCALL_magic[AttackMgcNo].isPostDisappear , + TOCALL_magic[AttackMgcNo].ToCallMagicNo + ); + + BATTLESTR_ADD( szcommand ); + + for( i = 0 ; ToList[i] != -1 ; i++ ) + { + snprintf( szcommand , sizeof( szcommand ) , "r%X|" , ToList[i] ); + BATTLESTR_ADD( szcommand ); + } + + BATTLESTR_ADD( "FF|" ); + + return 0; +} + +#endif +#ifdef _IMPRECATE_ITEM +void BATTLE_ImprecateRecovery( + int battleindex, int attackNo, int toNo, int kind, int powers, + int rounds, int UseEffect, int RecevEffect ) +{ + int i, toindex, flg; + int ToList[SIDE_OFFSET*2+1]; + //char szBuffer[256]=""; + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, attackNo, ToList, + UseEffect, RecevEffect ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( CHAR_CHECKINDEX( toindex ) == FALSE )continue; + switch( kind ){ +#ifdef _IMPRECATE_ITEM + case BD_KIND_CURSE: + if( CHAR_getWorkInt( toindex, CHAR_WORKIMPRECATENUM1 ) <= 0 && + CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + CHAR_setWorkInt( toindex, CHAR_WORKHURTMP, powers); //˺ MP + CHAR_setWorkInt( toindex, CHAR_WORKIMPRECATENUM1, rounds); + } + break; + case BD_KIND_BESTOW: + if( CHAR_getWorkInt( toindex, CHAR_WORKIMPRECATENUM2 ) <= 0 ){ +#ifdef _TYPE_TOXICATION + if( CHAR_CanCureFlg( toindex, "HP") == FALSE ) break; +#endif + CHAR_setWorkInt( toindex, CHAR_WORKWISHESHP, powers); //ף hp + CHAR_setWorkInt( toindex, CHAR_WORKIMPRECATENUM2, rounds); + } + break; + case BD_KIND_WISHES: + if( CHAR_getWorkInt( toindex, CHAR_WORKIMPRECATENUM3 ) <= 0 && + CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + CHAR_setWorkInt( toindex, CHAR_WORKWISHESMP, powers); //ף MP + CHAR_setWorkInt( toindex, CHAR_WORKIMPRECATENUM3, rounds); + } + break; +#endif + } + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + if( BattleArray[battleindex].norisk == 0 + && CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + flg = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEFLG ); + if( flg & CHAR_BATTLEFLG_RECOVERY ){ + }else{ + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRECOVERY ); + CHAR_setWorkInt( toindex, CHAR_WORKBATTLEFLG, flg | CHAR_BATTLEFLG_RECOVERY ); + } + } + } + return; +} +#endif + +void BATTLE_MultiRecovery( + int battleindex, + int attackNo, + int toNo, + int kind, + int power, + int per, + int UseEffect, + int RecevEffect +) +{ + int i, toindex, UpPoint = 0, workhp, oldhp, flg; + int ToList[SIDE_OFFSET*2+1]; + + //char szBuffer[256]=""; + char szCommand[256]; + + int ridepet, petUpPoint =0; + + + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( battleindex, attackNo, ToList, UseEffect, RecevEffect ); + + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + if( CHAR_CHECKINDEX( toindex ) == FALSE ) continue; + + ridepet = BATTLE_getRidePet( toindex ); + + switch( kind ){ +#ifdef _ITEM_UNBECOMEPIG + case BD_KIND_UNBECOMEPIG: + if( CHAR_getInt( toindex, CHAR_BECOMEPIG ) > -1 ){ + CHAR_setInt( toindex, CHAR_BECOMEPIG, -1 ); + CHAR_setInt( toindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( toindex, CHAR_BASEBASEIMAGENUMBER)); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( toindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_talkToCli( toindex,-1,"ʧЧˡ",CHAR_COLORWHITE); + } + break; +#endif +#ifdef _ITEM_PROPERTY + case BD_KIND_PROPERTY: + { + if (CHAR_getInt(toindex, CHAR_WHICHTYPE)!=CHAR_TYPEPLAYER) + return; + //print("ˮ:%d %d %d %d", CHAR_getInt( toindex, CHAR_EARTHAT ), CHAR_getInt( toindex, CHAR_WATERAT ), CHAR_getInt( toindex, CHAR_FIREAT ), CHAR_getInt( toindex, CHAR_WINDAT ) ); + if( power == 1 ){//ת ת + if( CHAR_getInt( toindex, CHAR_EARTHAT ) == 100 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) == 100 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 && CHAR_getInt( toindex, CHAR_WATERAT ) > 0 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) > 0 && CHAR_getInt( toindex, CHAR_FIREAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) > 0 && CHAR_getInt( toindex, CHAR_WINDAT ) > 0 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) > 0 && CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + } + if( power == 2 ){//ת ת + if( CHAR_getInt( toindex, CHAR_EARTHAT ) == 100 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) == 100 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 && CHAR_getInt( toindex, CHAR_WATERAT ) > 0 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) > 0 && CHAR_getInt( toindex, CHAR_FIREAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) > 0 && CHAR_getInt( toindex, CHAR_WINDAT ) > 0 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) > 0 && CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ); + } + } +#endif + case BD_KIND_HP: +#ifdef _TYPE_TOXICATION + if( CHAR_CanCureFlg( toindex, "HP") == FALSE ) continue; +#endif + // Robin 0728 ride Pet + if( ridepet == -1 ) { +#ifdef _MAGICPET_SKILL + if( power == -1 ){ + CHAR_setInt( toindex, CHAR_HP, CHAR_getWorkInt(toindex,CHAR_WORKMAXHP)); + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ); + }else +#endif + { + UpPoint = RAND( (power*0.9), (power*1.1) ); +#ifdef _MAGIC_REHPAI +#else + if( per ){ + UpPoint *= CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) * 0.01; + } + UpPoint *= GetRecoveryRate( toindex ); +#endif + workhp = CHAR_getInt( toindex, CHAR_HP ); + oldhp = workhp; + workhp += (int)UpPoint; + CHAR_setInt( toindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + + //snprintf( szBuffer, sizeof(szBuffer), "(%s);ظ(%d)", CHAR_getUseName( toindex ), UpPoint ); + } + }else { +#ifdef _MAGICPET_SKILL + if( power == -1 ){ + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ); + petUpPoint = CHAR_getWorkInt( ridepet, CHAR_WORKMAXHP ); + CHAR_setInt( toindex, CHAR_HP, CHAR_getWorkInt(toindex,CHAR_WORKMAXHP)); + CHAR_setInt( ridepet, CHAR_HP, CHAR_getWorkInt(ridepet,CHAR_WORKMAXHP)); + }else +#endif + { + int allUpPoint; + UpPoint = RAND( (power*0.9), (power*1.1) ); +#ifdef _MAGIC_REHPAI + allUpPoint = UpPoint; + UpPoint = (allUpPoint * Magic_RideGetHP( toindex, ridepet, 1 ))/100; + petUpPoint = allUpPoint - UpPoint; +#else + petUpPoint = UpPoint; + if( per ){ + UpPoint *= CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) * 0.01; + petUpPoint *= CHAR_getWorkInt( ridepet, CHAR_WORKMAXHP ) * 0.01; + + } + UpPoint *= GetRecoveryRate( toindex ); + petUpPoint *= GetRecoveryRate( ridepet ); +#endif + + + allUpPoint = UpPoint + petUpPoint; +#ifdef _MAGIC_REHPAI +#else + UpPoint = (UpPoint * UpPoint) / allUpPoint; + petUpPoint = (petUpPoint * petUpPoint) / allUpPoint; +#endif + workhp = CHAR_getInt( toindex, CHAR_HP ); + oldhp = workhp; + workhp += (int)UpPoint; + CHAR_setInt( toindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + workhp = CHAR_getInt( ridepet, CHAR_HP ); + oldhp = workhp; + workhp += (int)petUpPoint; + CHAR_setInt( ridepet, CHAR_HP, + min( workhp, CHAR_getWorkInt( ridepet, CHAR_WORKMAXHP ) ) ); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s);ظ(%d),(%s);ظ(%d)", + // CHAR_getUseName( toindex ), + // UpPoint, + // CHAR_getUseName( toindex ), + // petUpPoint + // ); + } + } + break; + case BD_KIND_MP: +#ifdef _MAGICPET_SKILL + if( power == 1 ){ + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXMP ); + CHAR_setInt( toindex, CHAR_MP, CHAR_getWorkInt(toindex,CHAR_WORKMAXMP)); + }else +#endif + { + UpPoint = RAND( (power*0.9), (power*1.1) ); + if( per ){ + UpPoint *= CHAR_getWorkInt( toindex, CHAR_WORKMAXMP ) * 0.01; + } + workhp = CHAR_getInt( toindex, CHAR_MP ); + oldhp = workhp; + workhp += (int)UpPoint; + CHAR_setInt( toindex, CHAR_MP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXMP ) ) ); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ظ(%d)", + // CHAR_getUseName( toindex ), + // UpPoint + // ); + } + break; + } + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + { + int Sign, Damage, petDamage; + Sign = (UpPoint >= 0)?(1):(0); + Damage = ABS( UpPoint ); + petDamage = ABS( petUpPoint ); +#ifdef _NOTRIDE_ + snprintf( szCommand, sizeof(szCommand), + "BD|r%X|%X|%X|d%X|", ToList[i], kind, Sign, Damage ); +#else + snprintf( szCommand, sizeof(szCommand), + "BD|r%X|%X|%X|d%X|p%X|", ToList[i], kind, Sign, Damage, petDamage ); +#endif //_NOTRIDE_ + BATTLESTR_ADD( szCommand ); + } + + if( BattleArray[battleindex].norisk == 0 + && CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET){ + flg = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEFLG ); + if( flg & CHAR_BATTLEFLG_RECOVERY ){ + }else{ + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRECOVERY ); + CHAR_setWorkInt( toindex, CHAR_WORKBATTLEFLG, flg | CHAR_BATTLEFLG_RECOVERY ); + } + } + } + return; +} + +#ifdef _MAGIC_REHPAI +int Magic_RideGetHP( int toindex, int petindex, int flg) +{ + int allDHp=1; + int petDHp=1; + int CharDHp=1; + int ISIZE = 100; + + CharDHp = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) - CHAR_getInt( toindex, CHAR_HP); + petDHp = CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) - CHAR_getInt( petindex, CHAR_HP); + allDHp = (CharDHp + petDHp); + + if( allDHp <= 0 ) allDHp=1; + if( flg == 1) + return (int)((CharDHp*ISIZE)/allDHp); + else + return (int)((petDHp*ISIZE)/allDHp); +} +#endif + +int MAGIC_Recovery_Battle( int charaindex, int toNo, int marray, int mp ) +{ + char *magicarg; + float power; + int battleindex, attackNo, HealedEffect = 0, per = 0; + int range; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + +#if 1 // Robin fix MagicΧ + range = MAGIC_getInt( marray, MAGIC_TARGET ); + //print(" MAGIC_TARGET:%d toNo:%d ", range, toNo); + if( range == 0 && toNo != attackNo ) { // ֻܶԼʹ +// print("\n ķ!MAGICֻܶԼʹ!!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + return FALSE; + } + if( range == 1 && toNo >= 20 ) { // ֻܶԵʹ +// print("\n ķ!MAGICֻܶԵʹ!!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + return FALSE; + } +#endif + + // shan(ȫʹħbug)޸jinchao+2001/12/07 + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return FALSE; + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + // shan(ȫʹħbug)޸jinchao+2001/12/07 + if (magicarg == "\0") return FALSE; + + power = atoi( magicarg ); + if( strstr( magicarg, "%" ) ){ + per = 1; + } + + if( power <= 100 ){ + HealedEffect = SPR_heal; + }else + if( power <= 300 ){ + HealedEffect = SPR_heal2; + }else{ + HealedEffect = SPR_heal3; + } + BATTLE_MultiRecovery( battleindex, attackNo, toNo,BD_KIND_HP, (int)power, per, MAGIC_EFFECT_USER, HealedEffect ); + return TRUE; +} + +void BATTLE_MultiResAndDef( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int power, // + int per, // Ѿ + int kind, // ܷ + int count, // ϼ ʲ + int UseEffect, // мް + int RecevEffect // ľмް +) +{ + int i, toindex, charaindex, UpPoint = 0, workhp; + int ToList[SIDE_OFFSET*2+1]; + + //char szBuffer[256]=""; + char szCommand[256]; + + + BATTLE_MultiListDead( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + charaindex = BATTLE_No2Index( battleindex, attackNo ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P + && CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + continue; + } + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == FALSE ){ + continue; + } + UpPoint = power; +#ifdef _MAGIC_REHPAI +#else + if( per ){ + UpPoint *= CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) * 0.01; + } +#endif + if( power == 0 ){ + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ); + }else{ + UpPoint = RAND( (power*0.9), (power*1.1) ); + } + UpPoint = max( 1, UpPoint ); + workhp = CHAR_getInt( toindex, CHAR_HP ) + UpPoint; + CHAR_setInt( toindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + CHAR_setFlg( toindex, CHAR_ISDIE, 0 ); + CHAR_setWorkInt( toindex, MagicDefTbl[kind], count ); + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ָʶ", + // CHAR_getUseName( toindex ) ); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), + // aszMagicDefFull[kind] + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + snprintf( szCommand, sizeof(szCommand), + "BL|r%X|h%X|", ToList[i], CHAR_getInt( toindex, CHAR_HP ) ); + BATTLESTR_ADD( szCommand ); + if( BattleArray[battleindex].norisk == 0 + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E ){ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRESSURECT ); + } + } + } +} + +#ifdef _ATTACK_MAGIC + +static int CharTable[4][5] = +{ + { 13 , 11 , 10 , 12 , 14 } , + { 18 , 16 , 15 , 17 , 19 } , + { 8 , 6 , 5 , 7 , 9 } , + { 3 , 1 , 0 , 2 , 4 } +}; + +static int CharTableIdx[20][2] = +{ + { 3 , 2 } , { 3 , 1 } , { 3 , 3 } , { 3 , 0 } , { 3 , 4 } , + { 2 , 2 } , { 2 , 1 } , { 2 , 3 } , { 2 , 0 } , { 2 , 4 } , + { 0 , 2 } , { 0 , 1 } , { 0 , 3 } , { 0 , 0 } , { 0 , 4 } , + { 1 , 2 } , { 1 , 1 } , { 1 , 3 } , { 1 , 0 } , { 1 , 4 } +}; + + + +typedef int ( *FUNC )( const void* , const void* ); + +static int SortLoc( const int *pEle1 , const int *pEle2 ) +{ + int ele1basex , ele1basey; + int ele2basex , ele2basey; + + ele1basex = CharTableIdx[*pEle1][1]; + ele1basey = CharTableIdx[*pEle1][0]; + ele2basex = CharTableIdx[*pEle2][1]; + ele2basey = CharTableIdx[*pEle2][0]; + + // Ϸ + if( *pEle1 >= 10 ) + { + if( ele1basey != ele2basey ) + return ( ele1basey - ele2basey ); + + return ( ele1basex - ele2basex ); + } + // · + else + { + if( ele1basey != ele2basey ) + return ( ele2basey - ele1basey ); + + return ( ele2basex - ele1basey ); + } + + return 0; +} + + +static void BATTLE_GetAttr( int charaindex , int *pAt_Fire , int *pAt_Water , int *pAt_Earth , int *pAt_Wind , int *pAt_None ) +{ + if( !CHAR_CHECKINDEX( charaindex ) )return; + int petindex = BATTLE_getRidePet( charaindex ); + + if( petindex == -1 ) + { + *pAt_Fire = CHAR_getWorkInt( charaindex , CHAR_WORKFIXFIREAT ); + *pAt_Water = CHAR_getWorkInt( charaindex , CHAR_WORKFIXWATERAT ); + *pAt_Earth = CHAR_getWorkInt( charaindex , CHAR_WORKFIXEARTHAT ); + *pAt_Wind = CHAR_getWorkInt( charaindex , CHAR_WORKFIXWINDAT ); + } + else + { + *pAt_Fire = ( CHAR_getWorkInt( charaindex , CHAR_WORKFIXFIREAT ) + + CHAR_getWorkInt( petindex , CHAR_WORKFIXFIREAT ) ) / 2; + *pAt_Water = ( CHAR_getWorkInt( charaindex , CHAR_WORKFIXWATERAT ) + + CHAR_getWorkInt( petindex , CHAR_WORKFIXWATERAT ) ) / 2; + *pAt_Earth = ( CHAR_getWorkInt( charaindex , CHAR_WORKFIXEARTHAT ) + + CHAR_getWorkInt( petindex , CHAR_WORKFIXEARTHAT ) ) / 2; + *pAt_Wind = ( CHAR_getWorkInt( charaindex , CHAR_WORKFIXWINDAT ) + + CHAR_getWorkInt( petindex , CHAR_WORKFIXWINDAT ) ) / 2; + } + + if( *pAt_Fire < 0 ) *pAt_Fire = 0; + if( *pAt_Water < 0 ) *pAt_Water = 0; + if( *pAt_Earth < 0 ) *pAt_Earth = 0; + if( *pAt_Wind < 0 ) *pAt_Wind = 0; + + *pAt_None = 100 - *pAt_Fire - *pAt_Water - *pAt_Earth - *pAt_Wind; + + if( *pAt_None < 0 ) + *pAt_None = 0; +} + +static void BATTLE_GetPureAttr( int charaindex , int *pAt_Fire , int *pAt_Water, int *pAt_Earth , int *pAt_Wind ) +{ + *pAt_Fire = CHAR_getWorkInt( charaindex , CHAR_WORKFIXFIREAT ); + *pAt_Water = CHAR_getWorkInt( charaindex , CHAR_WORKFIXWATERAT ); + *pAt_Earth = CHAR_getWorkInt( charaindex , CHAR_WORKFIXEARTHAT ); + *pAt_Wind = CHAR_getWorkInt( charaindex , CHAR_WORKFIXWINDAT ); + + if( *pAt_Fire < 0 ) *pAt_Fire = 0; + if( *pAt_Water < 0 ) *pAt_Water = 0; + if( *pAt_Earth < 0 ) *pAt_Earth = 0; + if( *pAt_Wind < 0 ) *pAt_Wind = 0; +} + + + +int BATTLE_CalAttMagicEffect( int AttEle , int DefPosEleValue , int DefNegEleValue ) +{ + int value; + + value = ( 100 * DefPosEleValue - 100 * DefNegEleValue ) / 1000; + + if( value > 10 ) + return 10; + else if( value < -10 ) + return -10; + + return value; +} + + + +int BATTLE_CalcCharaRatio( int AttEle , int charaidx ) +{ + int petidx , charahurt , pethurt; + int charaattr[4] , petattr[4]; + + // ûг + if( -1 == ( petidx = BATTLE_getRidePet( charaidx ) ) ) + return 10; + + // Nuke 20040330: Fix bug + if ( -1 == AttEle ) + return 5; + + BATTLE_GetPureAttr( charaidx , &charaattr[2] , &charaattr[1] , &charaattr[0], &charaattr[3] ); + BATTLE_GetPureAttr( petidx , &petattr[2] , &petattr[1] , &petattr[0] , &petattr[3] ); + + //print("\nAttEle: %d %d %d %d %d ",AttEle, charaattr[( AttEle + 1 ) % 4], charaattr[AttEle],petattr[( AttEle + 1 ) %4] , petattr[AttEle]); + + charahurt = 20 + BATTLE_CalAttMagicEffect( AttEle , charaattr[( AttEle + 1 ) % 4] , charaattr[AttEle] ); + pethurt = 20 + BATTLE_CalAttMagicEffect( AttEle , petattr[( AttEle + 1 ) %4] , petattr[AttEle] ); + + charahurt = 10 * charahurt / ( charahurt + pethurt ); + + if( charahurt < 2 ) + return 2; + else if( charahurt > 8 ) + return 8; + + return charahurt; +} + +static int BATTLE_AttrCalc( + int My_Fire, // д(ĤҰ»õ) + int My_Water, + int My_Earth, + int My_Wind, + int My_None, + int Vs_Fire, // 촡 + int Vs_Water, + int Vs_Earth, + int Vs_Wind, + int Vs_None +) +{ + int iRet = 0; + + // ܼ £ + My_Fire = My_Fire * Vs_None * AJ_UP // + + My_Fire * Vs_Fire * AJ_SAME // Ԫ + + My_Fire * Vs_Water * AJ_DOWN // + + My_Fire * Vs_Earth * AJ_SAME // Ԫ + + My_Fire * Vs_Wind * AJ_UP; // + + // £ + My_Water = My_Water * Vs_None * AJ_UP // + + My_Water * Vs_Fire * AJ_UP // + + My_Water * Vs_Water * AJ_SAME // Ԫ + + My_Water * Vs_Earth * AJ_DOWN // + + My_Water * Vs_Wind * AJ_SAME; // Ԫ + + // + My_Earth = My_Earth * Vs_None * AJ_UP // + + My_Earth * Vs_Fire * AJ_SAME // Ԫ + + My_Earth * Vs_Water * AJ_UP // + + My_Earth * Vs_Earth * AJ_SAME // Ԫ + + My_Earth * Vs_Wind * AJ_DOWN; // + + // + My_Wind = My_Wind * Vs_None * AJ_UP // + + My_Wind * Vs_Fire * AJ_DOWN // + + My_Wind * Vs_Water * AJ_SAME // Ԫ + + My_Wind * Vs_Earth * AJ_UP // + + My_Wind * Vs_Wind * AJ_SAME; // Ԫ + + // + My_None = My_None * Vs_None * AJ_SAME // Ԫ + + My_None * Vs_Fire * AJ_DOWN // + + My_None * Vs_Water * AJ_DOWN // + + My_None * Vs_Earth * AJ_DOWN // + + My_None * Vs_Wind * AJ_DOWN; // + + // + iRet = (My_Fire + My_Water + My_Earth + My_Wind + My_None) ; + + // ңȾԻƥ ئ׼ƥг + return (iRet * D_ATTR); +} + +extern float BATTLE_FieldAttAdjust(int battleindex,int pAt_Fire,int pAt_Water,int pAt_Earth,int pAt_Wind); +#ifndef _FIX_MAGICDAMAGE +static int BATTLE_AttrAdjust( + int attackindex, + int defindex, + int damage +) +{ + int At_Fire, At_Earth, At_Water, At_Wind, At_none; + int Df_Fire, Df_Earth, Df_Water, Df_Wind, Df_none; + float At_FieldPow, Df_FieldPow; + + BATTLE_GetAttr(attackindex,&At_Fire,&At_Water,&At_Earth,&At_Wind,&At_none); + + At_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ), + At_Fire, At_Water, At_Earth, At_Wind ); + + At_Fire *= damage; At_Water *= damage; At_Earth *= damage; + At_Wind *= damage; At_none *= damage; + BATTLE_GetAttr( defindex, &Df_Fire, &Df_Water, + &Df_Earth,&Df_Wind, &Df_none ); + Df_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ), + Df_Fire, Df_Water, Df_Earth, Df_Wind ); + damage = BATTLE_AttrCalc( + At_Fire, At_Water, At_Earth, At_Wind, At_none, + Df_Fire, Df_Water, Df_Earth, Df_Wind, Df_none ); + damage *= (At_FieldPow / Df_FieldPow); + return damage; +} +#endif +// +// return: 0:û 1: +int BATTLE_MagicDodge(int charindex,int nDefKind,int nFieldAttr) +{ + if( !CHAR_CHECKINDEX( charindex ) )return 0; + float fLuck = 0,fResist = 0; +#ifdef _EQUIT_DEFMAGIC + float Dluck=0.0; +#endif + int charType = CHAR_getInt( charindex, CHAR_WHICHTYPE); + // Ƿ + if( charType == CHAR_TYPEPLAYER ){ + fLuck = (float)CHAR_getInt( charindex, CHAR_LUCK) * 3; + fResist = (float)CHAR_getInt( charindex, CHAR_EARTH_RESIST + nFieldAttr) * 0.15; + fLuck += fResist; +#ifdef _EQUIT_DEFMAGIC + Dluck = (float)(CHAR_getWorkInt( charindex, CHAR_EQUITQUIMAGIC)*0.9); + fLuck += Dluck; +#endif + }else {// Ƿdz + fLuck = (float)CHAR_getInt( charindex, CHAR_LV) * 0.2; + if(fLuck > 30) fLuck = 30; + } + if(rand()%100+1 > (int)fLuck) + return 0; + else + return 1; +} + + +#define DEF_MAGIC_NUM 4 + +extern void BATTLE_changeRideImage( int index ); + +#ifdef _FIX_MAGICDAMAGE +void BATTLE_MultiAttMagic( int battleindex, int attackNo, int toNo, + int attIdx ,int FieldAttr ,int Power, int MagicLv) +#else +void BATTLE_MultiAttMagic( int battleindex, int attackNo, int toNo , int attIdx, + int FieldAttr , int Power) +#endif +{ + int list[SIDE_OFFSET * 2 + 1]; + int listidx,i,j,k,z; + int basex , basey , magicattidx,def_is_player[10],def_be_hit[10]; + int att_magic_lv[4]; + int def_magic_resist[DEF_MAGIC_NUM]; + int attvalue , charahp , pethp , charaidx , petidx , charahurt,pet_att_lv = 1,pet_def_lv = 1,charahurt_temp; + char szcommand[256]; + int AttIsPlayer=0,DefIsPlayer=0; + int getexp = 0; + +#ifndef _FIX_MAGICDAMAGE + int att_magic_exp_add,att_magic_exp_sub,def_magic_exp_add,def_magic_exp_sub; + int lv_up_exp,DefFieldAttr = 0; + float temp = 0.0f; +// int attattr[5], defattr[5]; + char msgbuf[64]; + char kind[4][3] = {"","ˮ","",""}; +#else + BOOL TrueMagic=FALSE; +#endif + + // terry + + + if((z = BATTLE_MultiList(battleindex,toNo,list)) == -1) + return; + else + { + if(z != toNo) toNo = z; + } + + BATTLE_AttMagicEffect( battleindex , attackNo , list , attIdx ); + + // 㹥嵥 + if( attackNo < 10 ) + magicattidx = attIdx * 2 + 1; + else + magicattidx = attIdx * 2; + + listidx = 0; + memset(def_is_player,-1,sizeof(def_is_player)); + memset(def_be_hit,-1,sizeof(def_be_hit)); + + // ˹ + if( toNo < 20 ){ + toNo = list[0]; + basex = CharTableIdx[toNo][1]; + basey = CharTableIdx[toNo][0]; + + for( i = 0 , j = basey - 1 ; j <= basey + 1 ; i++ , j++ ){ + if( toNo < 10 && ( j < 2 || j > 3 ) ) + continue; + else if( toNo >= 10 && ( j < 0 || j > 1 ) ) + continue; + // ЩҪ嵥 + for( k = 0 ; k < 5 ; k++ ){ + if( basex - 2 + k < 0 || basex - 2 + k > 4 ) + continue; + + if( ATTMAGIC_magic[magicattidx].siField[i][k] && TRUE == BATTLE_TargetCheck( battleindex , CharTable[j][basex - 2 + k] ) ) + { + list[listidx] = CharTable[j][basex - 2 + k]; + listidx++; + } + } + } + }else if( 20 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if( ATTMAGIC_magic[magicattidx].siField[i][j] && TRUE == BATTLE_TargetCheck( battleindex , CharTable[i + 2][j] ) ){ + list[listidx] = CharTable[i + 2][j]; + listidx++; + } + } + } + }else if( 21 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if( ATTMAGIC_magic[magicattidx].siField[i][j] && TRUE == BATTLE_TargetCheck( battleindex , CharTable[i][j] ) ){ + list[listidx] = CharTable[i][j]; + listidx++; + } + } + } + } + // ϵһ , ϵڶ , µһ , µڶ + else if( 23 == toNo || 24 == toNo || 25 == toNo || 26 == toNo ){ + basey = toNo - 23; + + for( i = 0 , j = basey - 1 ; j <= basey + 1 ; i++ , j++ ){ + if( ( 25 == toNo || 26 == toNo ) && ( j < 2 || j > 3 ) ) + continue; + else if( ( 23 == toNo || 24 == toNo ) && ( j < 0 || j > 1 ) ) + continue; + + // ЩҪ嵥 + for( k = 0 ; k < 5 ; k++ ){ + if( ATTMAGIC_magic[magicattidx].siField[i][k] && TRUE == BATTLE_TargetCheck( battleindex , CharTable[j][k] ) ) + { + list[listidx] = CharTable[j][k]; + listidx++; + } + } + } + } + + + qsort( list , listidx , sizeof( list[0] ) , ( FUNC )SortLoc );// λ + + // ȡ(һdz) + //BATTLE_GetAttr( BATTLE_No2Index( battleindex , attackNo ) , &attattr[2] , &attattr[1] , &attattr[0] , &attattr[3] , &attattr[4] ); + // ,ȡħȼħ + { + int attType = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo),CHAR_WHICHTYPE); + int Check=0; + AttIsPlayer=0; + if( attType == CHAR_TYPEPLAYER) { + AttIsPlayer = 1; + for(i=0;i<4;i++){ // att_magic_lv[i]: i = 0: 1:ˮ 2: 3: + att_magic_lv[i] = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_EXP+i); + } + }else if( attType == CHAR_TYPEENEMY ) { + for(i=0;i<4;i++){ + att_magic_lv[i] = (CHAR_getInt(BATTLE_No2Index(battleindex,attackNo), CHAR_LV)*0.9); + } + }else { +#ifdef _FIX_MAGICDAMAGE + AttIsPlayer = 1; +#endif + for(i=0;i<4;i++){ +#ifdef _FIX_MAGICDAMAGE + att_magic_lv[i] = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_EXP+i); +#else + att_magic_lv[i] = 0; +#endif + } + } + Check = rand()%100; +#ifdef _FIX_MAGICDAMAGE + if( Check > att_magic_lv[ FieldAttr] ) TrueMagic = FALSE; + else TrueMagic = TRUE; +#endif + } + pet_att_lv = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo), CHAR_LV); + + z = 0; + for(i=0;i 0 ){ + float def = (float)(CHAR_getWorkInt( charaidx, CHAR_OTHERSTATUSNUMS )); + def = def/100; + for(j=0;j 0) { + CHAR_setWorkInt(def_be_hit[i],CHAR_WORKSLEEP,0); + z = BATTLE_Index2No(battleindex,def_be_hit[i]); + sprintf(szcommand,"BM|%X|%X|",z,0); + BATTLESTR_ADD(szcommand); + } + } +#else + //TrueMagic == FALSE + // ľֵ----------------------------------------------------------------------------- + if(AttIsPlayer){ + // ˵ħ + DefFieldAttr = (FieldAttr+1)%4; + // ȡõħľֵ + att_magic_exp_add = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_ATTMAGIC_EXP+FieldAttr); + // ȡõħıħֵ + att_magic_exp_sub = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_ATTMAGIC_EXP+DefFieldAttr); + // ʹõħӸԵexp,ֻ㼸exp + att_magic_exp_add += getexp; + // ʹõħ۱Եexp,ֻۼexp + att_magic_exp_sub -= getexp; + lv_up_exp = Magic_Level_Table[att_magic_lv[FieldAttr]]; + while(att_magic_exp_add >= lv_up_exp || att_magic_exp_sub < 0){ + // õħľֵڿ + if(att_magic_exp_add >= lv_up_exp){ + // 100 + if(att_magic_lv[FieldAttr] + 1 > 100){ + att_magic_lv[FieldAttr] = 100; + // ֵΪ0 + att_magic_exp_add = 0; + }else{ + att_magic_lv[FieldAttr]++; + // ڵľֵ۵˼õľֵ + att_magic_exp_add -= lv_up_exp; + snprintf(msgbuf,sizeof(msgbuf)," %s ħΪ %d",kind[FieldAttr],att_magic_lv[FieldAttr]); + CHAR_talkToCli(BATTLE_No2Index(battleindex,attackNo),-1,msgbuf,CHAR_COLORRED); + } + } + // õħħľֵڿԽ + if(att_magic_exp_sub < 0 ){ + // ȼѾ1 + if(att_magic_lv[DefFieldAttr] <= 1){ + att_magic_lv[DefFieldAttr] = 1; + // ֵΪ0 + att_magic_exp_sub = 0; + }else{ + att_magic_lv[DefFieldAttr]--; + // һȼľֵ۵ڵľֵ + att_magic_exp_sub = Magic_Level_Table[att_magic_lv[DefFieldAttr]] + att_magic_exp_sub; + snprintf(msgbuf,sizeof(msgbuf)," %s ħȽΪ %d",kind[DefFieldAttr],att_magic_lv[DefFieldAttr]); + CHAR_talkToCli(BATTLE_No2Index(battleindex,attackNo),-1,msgbuf,CHAR_COLORRED); + } + } + lv_up_exp = Magic_Level_Table[att_magic_lv[FieldAttr]]; + } + CHAR_setInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_EXP+FieldAttr,att_magic_lv[FieldAttr]); + CHAR_setInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_ATTMAGIC_EXP+FieldAttr,att_magic_exp_add); + CHAR_setInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_EXP+DefFieldAttr,att_magic_lv[DefFieldAttr]); + CHAR_setInt(BATTLE_No2Index(battleindex,attackNo),CHAR_EARTH_ATTMAGIC_EXP+DefFieldAttr,att_magic_exp_sub); + } + + // طľֵ----------------------------------------------------------------------------- + for(i=0;i= lv_up_exp || def_magic_exp_sub < 0){ + // طҶԴħĿԵľֵڿ + if(def_magic_exp_add >= lv_up_exp){ + // 100 + if(def_magic_resist[FieldAttr] + 1 > 100) def_magic_resist[FieldAttr] = 100; + else { + def_magic_resist[FieldAttr]++; + snprintf(msgbuf,sizeof(msgbuf)," %s ħΪ %d",kind[FieldAttr],def_magic_resist[FieldAttr]); + CHAR_talkToCli(charaidx,-1,msgbuf,CHAR_COLORRED); + } + // ֵΪ0 + def_magic_exp_add = 0; + } + // طҶԴħĿԵħľֵڿԽ + if(def_magic_exp_sub < 0 ) { + // ȼѾ1 + if(def_magic_resist[DefFieldAttr] <= 1) def_magic_exp_sub = 0; // ֵΪ0 + else { + def_magic_resist[DefFieldAttr]--; + // ֵһȼľֵ + def_magic_exp_sub = Magic_Level_Table[def_magic_resist[DefFieldAttr]]; + snprintf(msgbuf,sizeof(msgbuf)," %s ħԽΪ %d",kind[DefFieldAttr],def_magic_resist[DefFieldAttr]); + CHAR_talkToCli(charaidx,-1,msgbuf,CHAR_COLORRED); + } + } + lv_up_exp = Magic_Level_Table[def_magic_resist[FieldAttr]]; + } + CHAR_setInt(charaidx,CHAR_EARTH_RESIST+FieldAttr,def_magic_resist[FieldAttr]); + CHAR_setInt(charaidx,CHAR_EARTH_DEFMAGIC_EXP+FieldAttr,def_magic_exp_add); + CHAR_setInt(charaidx,CHAR_EARTH_RESIST+DefFieldAttr,def_magic_resist[DefFieldAttr]); + CHAR_setInt(charaidx,CHAR_EARTH_DEFMAGIC_EXP+DefFieldAttr,def_magic_exp_sub); + } + if( CHAR_CHECKINDEX( def_be_hit[i]) ){ + // ˯ + if(CHAR_getWorkInt(def_be_hit[i],CHAR_WORKSLEEP) > 0) { + CHAR_setWorkInt(def_be_hit[i],CHAR_WORKSLEEP,0); + z = BATTLE_Index2No(battleindex,def_be_hit[i]); + sprintf(szcommand,"BM|%X|%X|",z,0); + BATTLESTR_ADD(szcommand); + } + } + } +#endif +} + +#endif + +#ifdef _MAGIC_TOCALL +void BATTLE_MultiToCallDragonMagic( int battleindex, int attackNo, int toNo, + int attIdx ,int FieldAttr ,int Power, int ImageNo) +{ + int list[SIDE_OFFSET * 2 + 1]; + int listidx,i,j,k,z; + int /*basex , */basey , magicattidx,def_is_player[10],def_be_hit[10]; + int attvalue , charahp , pethp , charaidx , petidx , charahurt,charahurt_temp; + char szcommand[256]; + int /*AttIsPlayer = 0,*/DefIsPlayer = 0; + +#ifndef _FIX_MAGICDAMAGE + int att_magic_exp_add,att_magic_exp_sub,def_magic_exp_add,def_magic_exp_sub; + int lv_up_exp,DefFieldAttr = 0; + float temp = 0.0f; + char msgbuf[64]; +#else +#endif + + int icindex, ioindex; + // terry + if((z = BATTLE_MultiList(battleindex,toNo,list)) == -1) + return; + else{ + if(z != toNo) toNo = z; + } + + TOCALL_magic[attIdx].uiSpriteNum = ImageNo; + + BATTLE_ToCallDragonEffect( battleindex , attackNo , list , attIdx); + + // 㹥嵥 + if( attackNo < 10 ) + magicattidx = attIdx * 2 + 1; + else + magicattidx = attIdx * 2; + + + listidx = 0; + memset(def_is_player,-1,sizeof(def_is_player)); + memset(def_be_hit,-1,sizeof(def_be_hit)); + + // ˹ + if( toNo < 20 ){ + toNo = list[0]; + listidx++; + + } else if( 20 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[i + 2][j] ) ){ + list[listidx] = CharTable[i + 2][j]; + listidx++; + } + } + } + } else if( 21 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[i][j] ) ){ + list[listidx] = CharTable[i][j]; + listidx++; + } + } + } + } // ϵһ , ϵڶ , µһ , µڶ + else if( 23 == toNo || 24 == toNo || 25 == toNo || 26 == toNo ){ + basey = toNo - 23; + for( i = 0 , j = basey - 1 ; j <= basey + 1 ; i++ , j++ ){ + if( ( 25 == toNo || 26 == toNo ) && ( j < 2 || j > 3 ) ) + continue; + else if( ( 23 == toNo || 24 == toNo ) && ( j < 0 || j > 1 ) ) + continue; + // ЩҪ嵥 + for( k = 0 ; k < 5 ; k++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[j][k] ) ) + { + list[listidx] = CharTable[j][k]; + listidx++; + } + } + } + } + qsort( list , listidx , sizeof( list[0] ) , ( FUNC )SortLoc );// λ + for( i = 0 ; i < listidx ; i++ ) { + int defType; + charaidx = BATTLE_No2Index( battleindex , list[i] ); + petidx = BATTLE_getRidePet( charaidx ); + defType = CHAR_getInt(charaidx, CHAR_WHICHTYPE); + DefIsPlayer = 0; + if (defType == CHAR_TYPEPLAYER) { + DefIsPlayer = 1; + } + if (CHAR_createCharacter( 100354 /*image no*/, 100, 600, 370, 0, + &icindex, &ioindex, 0) == TRUE) { + +// CHAR_setInt( icindex, CHAR_STR, 100); + CHAR_setInt( icindex, CHAR_LUCK, 1); + CHAR_setWorkInt( icindex, CHAR_WORKATTACKPOWER, + Power ); + CHAR_setWorkInt( icindex, CHAR_WORKOTHERDMAGE, + 0); + + if (BATTLE_MagicDodge(charaidx, DefIsPlayer, FieldAttr)) { +// û + attvalue = 0; + } else { + if( 0 == TOCALL_magic[attIdx].uiAttackType ) {// ˹ + attvalue = BATTLE_DamageCalc(icindex, charaidx); + } + else { + attvalue = BATTLE_DamageCalc(icindex, charaidx); + } + } + CHAR_CharaDelete(icindex); + charahp = CHAR_getInt( charaidx , CHAR_HP ); + if (-1 == petidx || CHAR_getInt(petidx, CHAR_HP) <= 0) { +// û + if( ( charahp -= attvalue ) < 0 ) { + charahp = 0; + } + CHAR_setInt( charaidx , CHAR_HP , charahp ); + pethp = 0; + if( 0 == TOCALL_magic[attIdx].uiAttackType ) {// ˹ + sprintf( szcommand , "%X|%X|%X|%X|" , toNo , list[i] , attvalue , pethp); + } else + sprintf( szcommand , "%X|%X|%X|%X|" , list[i] , list[i] , attvalue , pethp); + }else{ + pethp = CHAR_getInt( petidx , CHAR_HP ); + charahurt = attvalue * BATTLE_CalcCharaRatio( FieldAttr , charaidx ) / 10; + + charahurt_temp = charahurt; + if( ( charahp -= charahurt ) < 0 ) + { + charahurt = charahp; + charahp = 0; + } + + attvalue = attvalue - charahurt; + if( ( pethp -= attvalue ) < 0) + { + pethp = 0; + // ûѪ˳ս + CHAR_setInt(charaidx,CHAR_RIDEPET,-1); + BATTLE_changeRideImage(charaidx); + CHAR_setWorkInt(charaidx,CHAR_WORKPETFALL,1); + } + CHAR_setInt( charaidx , CHAR_HP , charahp ); + CHAR_setInt( petidx , CHAR_HP , pethp ); + + charahurt = charahurt_temp; + + if( 0 == TOCALL_magic[attIdx].uiAttackType ) {// ˹ + sprintf( szcommand , "%X|%X|%X|%X|" , toNo , list[i] , charahurt , attvalue); + } else + sprintf( szcommand , "%X|%X|%X|%X|" , list[i] , list[i] , charahurt , attvalue); + + } + + BATTLESTR_ADD( szcommand ); + } + } + + sprintf( szcommand , "%X|" , 0x5711438 ); + BATTLESTR_ADD( szcommand ); + +} + +#endif + +//*********************************************************** +// +// ܷƥ Ѽƽҷëٽ +// +void BATTLE_MultiRessurect( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int power, // + int per, // Ѿ + int UseEffect, // мް + int RecevEffect // ľмް +) +// +//*********************************************************** +{ + int i, toindex, UpPoint = 0, workhp; + int ToList[SIDE_OFFSET*2+1]; + + //char szBuffer[256]=""; + char szCommand[256]; + + BATTLE_MultiListDead( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + + // ٽ + for( i = 0; ToList[i] != -1; i ++ ){ + // 켰̼͵ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + // Ϸ߯Ի + if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P + && CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ){ + continue; + } + + // ƻئľٽئ + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == FALSE ){ + continue; + } + + // ң + UpPoint = power; + + if( per ){ + // ѻң + UpPoint *= CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) * 0.01; + } +#ifdef _MAGICPET_SKILL + if( power == -1 ){ + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ); + }else +#endif + if( power == 0 ){ + // + UpPoint = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ); + }else{ + // ڱë (ᷴ) + UpPoint = RAND( (power*0.9), (power*1.1) ); + } + // ƥ֨ + UpPoint = max( 1, UpPoint ); + + workhp = CHAR_getInt( toindex, CHAR_HP ) + UpPoint; + + // ëئз + CHAR_setInt( toindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + + // + CHAR_setFlg( toindex, CHAR_ISDIE, 0 ); + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ָʶ", + // CHAR_getUseName( toindex ) ); + + // ú + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + // ()Ѩëľ + snprintf( szCommand, sizeof(szCommand), + "BL|r%X|h%X|", ToList[i], CHAR_getInt( toindex, CHAR_HP ) ); + + // ٯ ܰ + BATTLESTR_ADD( szCommand ); +/* + { int Sign, Damage; + Sign = (UpPoint >= 0)?(1):(0); + Damage = ABS( UpPoint ); + // ( )Ѩëľ + snprintf( szCommand, sizeof(szCommand), + "BD|r%X|%X|%X|d%X|", ToList[i], 0, Sign, Damage ); + } + // ٯ ܰ + BATTLESTR_ADD( szCommand ); +*/ + + // 缰 ƥͻئ + if( BattleArray[battleindex].norisk == 0 + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E + ){ + // ƥʸհëµ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRESSURECT ); + } + } + } + + return; + +} + +#ifdef _Item_ReLifeAct +void BATTLE_MultiReLife( int battleindex, int attackNo, int toNo, + int power, int RecevEffect ) +{ + int i, toindex, UpPoint = 0, workhp; + int ToList[SIDE_OFFSET*2+1]; + //char szBuffer[256]=""; + char szCommand[256]; + char buf1[256]; + + memset(szCommand, 0, sizeof(szCommand)); + BATTLE_MultiListDead( battleindex, toNo, ToList ); + + + //snprintf( szCommand, sizeof(szCommand), "Bj|"); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + //if( BattleArray[battleindex].type == BATTLE_TYPE_P_vs_P + //&& CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + // continue; + //} + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == FALSE ){ + continue; + } + UpPoint = power; + workhp = max( 1, UpPoint ); + + CHAR_setInt( toindex, CHAR_HP, min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + CHAR_setFlg( toindex, CHAR_ISDIE, 0 ); + //snprintf( szBuffer, sizeof(szBuffer), "(%s)ָʶ", CHAR_getUseName( toindex ) ); + snprintf( buf1, sizeof(buf1), + "BJ|a%X|m%X|e%X|e%X|FF|", + ToList[i], + CHAR_getInt( toindex, CHAR_MP ), + RecevEffect, //MyEffect, + 0 //ToEffect + ); + strcat( szCommand, buf1); + + snprintf( buf1, sizeof(buf1), + "BL|r%X|h%X|", ToList[i], CHAR_getInt( toindex, CHAR_HP ) ); + strcat( szCommand, buf1); + + if( BattleArray[battleindex].norisk == 0 + && BattleArray[battleindex].type == BATTLE_TYPE_P_vs_E ){ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + CHAR_PetAddVariableAi( toindex, AI_FIX_PETRESSURECT ); + } + } + } + //strcat( szCommand, "FF|"); + BATTLESTR_ADD( szCommand ); + return; +} +#endif + +void BATTLE_MultiStatusChange( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int status, // + int turn, // + int UseEffect, // мް + int RecevEffect, // ľмް + int Success // +) +{ + int i, toindex, charaindex; + int perStatus; + int ToList[SIDE_OFFSET*2+1]; + //char szBuffer[256]=""; + + BATTLE_MultiList( battleindex, toNo, ToList ); + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BATTLE_StatusAttackCheck( charaindex, + toindex, status, Success, 30, 1.0, &perStatus ) == FALSE ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)޷(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), + // aszStatusFull[status], + // perStatus + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + }else{ + CHAR_setWorkInt( toindex, StatusTbl[status], turn ); + + if( status == BATTLE_ST_PARALYSIS + || status == BATTLE_ST_SLEEP + || status == BATTLE_ST_STONE + || status == BATTLE_ST_BARRIER ){ + CHAR_setWorkInt( toindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)(%d%%)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), + // aszStatusFull[status], + // perStatus + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + BATTLE_BadStatusString( ToList[i], status ); + } + } + return; +} + +#ifdef _OTHER_MAGICSTAUTS +void BATTLE_MultiMagicStatusChange( int battleindex, int attackNo, int toNo, int status, int turn, + int UseEffect, int RecevEffect, int nums ) +{ + int i, j, toindex, charaindex; + int ToList[SIDE_OFFSET*2+1]; + + BATTLE_MultiList( battleindex, toNo, ToList ); + BATTLE_MagicEffect( battleindex, attackNo, ToList, UseEffect, RecevEffect ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + for( j=1; j 0 ){ + tostatus = j; + } + } + //======== ƥ ë ý ========== + if( tostatus == 0 ){// + // +// print("\n vincent--ܽ"); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ܽ", + // CHAR_getUseName( toindex ) ); + }else + // ϶ƥҷ + if( ( status == 0 && tostatus != 0 && tostatus <= CHAR_WORKCONFUSION ) // ϶ƥ//ҵ쳣 + || ( status == tostatus ) // ֻѨ + ){ + // + CHAR_setWorkInt( toindex, StatusTbl[tostatus], 0 ); +#ifdef _MAGIC_NOCAST + if( StatusTbl[tostatus] == CHAR_WORKNOCAST ){ + //print("\nvincent-->lssproto_NC_send"); + lssproto_NC_send( getfdFromCharaIndex( toindex ), 0);//Ĭ + } +#endif +// print("\n vincent--:%d",tostatus); + // + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), + // aszStatusFull[tostatus] + //); + // ƥ ٯ Ѩëľ + BATTLE_BadStatusString( ToList[i], 0 );//쳣 + + }else{ +// print("\n vincent--"); + // +/* snprintf( szBuffer, sizeof(szBuffer), + "(%s)(%s)", + CHAR_getUseName( toindex ), + aszStatusFull[status] + ); +*/ + } + // ú + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + + return; +} + +//*********************************************************** +// +// ܷƥ Ѽƽҷë ܷ +// +void BATTLE_MultiMagicDef( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int kind, // ܷ + int count, // + int UseEffect, // мް + int RecevEffect // ľмް +) +// +//*********************************************************** +{ + + int i, toindex, charaindex; + int ToList[SIDE_OFFSET*2+1]; + + //char szBuffer[256]=""; + + + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + CHAR_setWorkInt( toindex, MagicDefTbl[kind], count ); + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%s)", + // CHAR_getUseName( charaindex ), + // CHAR_getUseName( toindex ), + // aszMagicDefFull[kind] + //); + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + } + + return; + + + +} + + +#if 1 + +//*********************************************************** +// +// ܷƥ Ѽƽҷɷ¶ëƱ +// +void BATTLE_MultiParamChange( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int kind, // ɷ¶ + int power, // ̼ + int par, // ѻң + int UseEffect, // мް + int RecevEffect // ľмް +) +// +//*********************************************************** +{ + + int i, toindex, charaindex; + int ToList[SIDE_OFFSET*2+1]; + int res = 0, work; + //char szBuffer[256]=""; + + + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + + // ɷ¶¾ + for( i = 0; ToList[i] != -1; i ++ ){ + + // 켰̼͵ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + switch( kind ){ + case PC_KIND_ATTACK: + if( par ){ + // ѻңئ׻ߨ߷ئ + work = CHAR_getWorkInt( toindex, CHAR_WORKFIXSTR ); + work = work * power; + }else{ + // ңئ׻ߨ߾ + work = power * 100; + } + CHAR_setWorkInt( toindex, CHAR_WORKMODATTACK, + CHAR_getWorkInt( toindex, CHAR_WORKMODATTACK ) + work ); + res = work * 0.01; + break; + case PC_KIND_DEFENSE: + if( par ){ + // ѻңئ׻ߨ߷ئ + work = CHAR_getWorkInt( toindex, CHAR_WORKFIXTOUGH ); + work = work * power; + }else{ + // ңئ׻ߨ߾ + work = power * 100; + } + CHAR_setWorkInt( toindex, CHAR_WORKMODDEFENCE, + CHAR_getWorkInt( toindex, CHAR_WORKMODDEFENCE ) + work ); + res = work * 0.01; + break; + case PC_KIND_QUICK: + if( par ){ + // ѻңئ׻ߨ߷ئ + work = CHAR_getWorkInt( toindex, CHAR_WORKFIXDEX ); + work = work * power; + }else{ + // ңئ׻ߨ߾ + work = power * 100; + } + CHAR_setWorkInt( toindex, CHAR_WORKMODQUICK, + CHAR_getWorkInt( toindex, CHAR_WORKMODQUICK ) + work ); + res = work * 0.01; + break; + case PC_KIND_CHARM: + if( par ){ + // CHARM 100 ľئ׻100м + work = CHAR_getWorkInt( toindex, CHAR_WORKFIXCHARM ); + work = work * power * 0.01; + }else{ + // ң + work = power; + } + CHAR_setWorkInt( toindex, CHAR_WORKMODCHARM, + CHAR_getWorkInt( toindex, CHAR_WORKMODCHARM ) + work ); + res = work; + break; + case PC_KIND_CAPTURE: + // CAPTURE % + work = power; + CHAR_setWorkInt( toindex, CHAR_WORKMODCAPTURE, + CHAR_getWorkInt( toindex, CHAR_WORKMODCAPTURE ) + work ); + res = work; + break; + } + + // ƥ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)(%s)(%+d)", + // CHAR_getUseName( toindex ), + // aszParamChangeFull[kind], + // res + //); + + // ú + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + } + + return; +} + +#endif + + +//*********************************************************** +// +// ܷƥ Ѽ +// +void BATTLE_MultiAttReverse( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int UseEffect, // мް + int RecevEffect // ľмް +) +// +//*********************************************************** +{ + + int i, toindex, charaindex; + int ToList[SIDE_OFFSET*2+1]; + int flg, OnOff; + char szBuffer[256]=""; + + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, // ̼͵ + attackNo, // į( ) + ToList, // ľ į( ) + UseEffect, // оް + RecevEffect // ľоް + ); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + + // ɷ¶¾ + for( i = 0; ToList[i] != -1; i ++ ){ + + // 켰̼͵ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + flg = CHAR_getWorkInt( toindex, CHAR_WORKBATTLEFLG ); + flg ^= CHAR_BATTLEFLG_REVERSE; // + CHAR_setWorkInt( toindex, CHAR_WORKBATTLEFLG, flg ); + OnOff = ( flg & CHAR_BATTLEFLG_REVERSE )?(1):(0); + + // ƥʾ + BATTLE_AttReverse( toindex ); + + if( OnOff ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)Ա෴", + // CHAR_getUseName( toindex ) ); + }else{ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)ظԭԡ", + // CHAR_getUseName( toindex ) ); + } + + // ú + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + // ƥ  ٯ ë˪ + sprintf( szBuffer, "BR|%X|%X|", ToList[i], OnOff ); + BATTLESTR_ADD( szBuffer ); + } + + return; + +} + +void BATTLE_MultiCaptureUp( + int battleindex, + int attackNo, + int toNo, + int power, + int UseEffect, + int RecevEffect +) +{ + int i, toindex, UpPoint = 0, workhp; + int ToList[SIDE_OFFSET*2+1]; + + //char szBuffer[256]=""; + char szCommand[256]; + + BATTLE_MultiList( battleindex, toNo, ToList ); + + BATTLE_MagicEffect( + battleindex, + attackNo, + ToList, + UseEffect, + RecevEffect + ); + + for( i = 0; ToList[i] != -1; i ++ ){ + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + if( CHAR_getInt( toindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + continue; + } + + if( CHAR_getFlg( toindex, CHAR_ISDIE ) == TRUE ){ + continue; + } + + UpPoint = power; + + UpPoint = RAND( (power*0.9), (power*1.1) ); + + workhp = CHAR_getWorkInt( toindex, CHAR_WORKMODCAPTURE ) + UpPoint; + + CHAR_setWorkInt( toindex, CHAR_WORKMODCAPTURE, workhp ); + + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)IJʱ(%d)", + // CHAR_getUseName( toindex ), UpPoint ); + + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + snprintf( szCommand, sizeof( szCommand ), + "B%%|%X|%X|", ToList[i], BFUKI_CAPTUREUP ); + + BATTLESTR_ADD( szCommand ); + } + return; +} + + + + + +//**************************************************************** +// +// ū +// +int BATTLE_FieldAttChange( + int charaindex, // м̼͵ + char *pArg +) +// +// ľ TRUE +// ئ FALSE +// +//**************************************************************** + +{ + + int attr = -1, i, attackNo, turn = 3; + int battleindex, power = 30; + int FieldAttr[] = { BATTLE_ATTR_NONE, BATTLE_ATTR_EARTH, BATTLE_ATTR_WATER, BATTLE_ATTR_FIRE, BATTLE_ATTR_WIND }; + char szCommand[256], + // Robin 03/20 debug + //*pszP, *aszAttr[] = { "", "", "ˮ", "", "" }; + *pszP, *aszAttr[] = { "", "", "ˮ", "", "" }; + // Robin 03/21 debug + //char szTurn[] = ""; + char szTurn[] = "turn"; + + + pszP = pArg; + // ë + for( ;attr == -1 && pszP[0] != 0; pszP++ ){ + for( i = 0; i < 5; i ++ ){ + // + if( strncmp( pszP, aszAttr[i], 2 ) == 0 ){ + attr = i; + pszP +=2; + break; + } + } + } + // мƥ + if( attr == -1 ) + { + return FALSE; + } + + // ľ ʽ¾ + sscanf( pszP, "%d", &power ); + if( power < 0 || power > 100 )power = 30; + + // ʽ¾ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( BATTLE_CHECKINDEX( battleindex ) == FALSE )return FALSE; + // + BattleArray[battleindex].field_att = FieldAttr[attr]; + // Ĥɷ + BattleArray[battleindex].att_pow = power; + // Ĥ + BattleArray[battleindex].att_count = turn; + + // ƥ + if( attr >= 0 ){ + //snprintf( szBuffer, sizeof(szBuffer), + // "(%s)fieldԸΪ(%s)", + // CHAR_getUseName( charaindex ), + // aszAttr[attr] + //); + } + + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // ú + //BATTLE_BroadCast( battleindex, szBuffer, + // (attackNo >= 10)? CHAR_COLORGRAY : CHAR_COLORPURPLE ) ; + + // ƥ ٯ Ѩëľ + sprintf( szCommand, "BV|%X|%X|",attackNo, attr ); + BATTLESTR_ADD( szCommand ); + + return TRUE; + +} + + + + +//**************************************************************** +// +// ū +// +int MAGIC_FieldAttChange_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵( ) + int marray, // magicindex + int mp // MP +) +// ľ TRUE +// ئ FALSE +// +//**************************************************************** + +{ + char *pArg; + + // ɷ¶ë + pArg = MAGIC_getChar( marray, MAGIC_OPTION ); + // ɷ¶ мƥ + if( pArg == "\0" )return FALSE; + + return BATTLE_FieldAttChange( charaindex, pArg ); + +} +//**************************************************************** +// +// ëܸ +// +int MAGIC_StatusChange_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** + +{ + char *magicarg; + int status = -1, i, attackNo, turn = 3; + int battleindex, ReceveEffect, Success = 15; + char *pszP; + char szTurn[] = "turn"; + char szSuccess[] = ""; + + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + pszP = magicarg; + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + if( status == -1 ) return FALSE; + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; // 巴ľ + }else{ + ReceveEffect = SPR_hoshi; // 巴ľ + } + + BATTLE_MultiStatusChange( battleindex, attackNo, toNo, + status, turn, MAGIC_EFFECT_USER, ReceveEffect, Success ); + + + return TRUE; + +} + +#ifdef _MAGIC_DEEPPOISON +int MAGIC_StatusChange_Battle2( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** + +{ + char *magicarg; + int status = -1, i, attackNo, turn = 3; + int battleindex, ReceveEffect, Success = 15; + char *pszP; + char szTurn[] = "turn"; + char szSuccess[] = ""; + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + // ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + // ྮո + for( i = 1; i < BATTLE_ST_END; i ++ ){ + // + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( status == -1 ) return FALSE; + + // ʽ¾ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + // ɬ + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + if( status == BATTLE_ST_NONE ){ + ReceveEffect = SPR_tyusya; // 巴ľ + }else{ + ReceveEffect = SPR_hoshi; // 巴ľ + } + // 幻 + BATTLE_MultiStatusChange( battleindex, attackNo, toNo, + status, turn+2, MAGIC_EFFECT_USER, ReceveEffect, Success ); + return TRUE; +} +#endif +#ifdef _OTHER_MAGICSTAUTS +int MAGIC_MagicStatusChange_Battle( int charaindex, int toNo, int marray, int mp ) +{ + char *magicarg; + int status = -1, i, attackNo, turn = 3, nums=0; + int battleindex, ReceveEffect; + char buf1[256]; + + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + if( getStringFromIndexWithDelim( magicarg,"|",1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + for( i=0; i= 20 ) + return FALSE; + } + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + //ͼž +#define SPR_mic_def 101411 + ReceveEffect = SPR_heal2; + if( status == 1 ) + ReceveEffect = SPR_mic_def; +#ifdef _MAGICSTAUTS_RESIST + else if( status == 3 ) + ReceveEffect = 101802; + else if( status == 4 ) + ReceveEffect = 101804; + else if( status == 5 ) + ReceveEffect = 101803; +#endif + //else{ + // ReceveEffect = SPR_hoshi; + //} + + BATTLE_MultiMagicStatusChange( + battleindex, attackNo, toNo, status, + turn, MAGIC_EFFECT_USER, ReceveEffect, nums ); + + return TRUE; +} +#endif + + +int MAGIC_MagicDef_Battle( + int charaindex, + int toNo, + int marray, + int mp +) +{ + char *magicarg; + int status = -1, i, attackNo, turn = 3; + int battleindex; + char *pszP; + + char szTurn[] = "turn"; + + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + pszP = magicarg; + + for( ;status == -1 && pszP[0] != '\0'; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + if( strncmp( pszP, aszMagicDef[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return FALSE; + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + BATTLE_MultiMagicDef( battleindex, attackNo, toNo, + status, turn, MAGIC_EFFECT_USER, SPR_difence ); + + + return TRUE; +} + + + + + + + +#if 1 + +//**************************************************************** +// +// ɷ¶ ëܸ +// +int MAGIC_ParamChange_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** + +{ + char *magicarg; + int kind = -1, i, attackNo; + int battleindex, pow, par = 0; + + char *pszP; + + // ɷ¶ë //ħ + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + pszP = magicarg; + // ë //ȡøIJ(,,,,,) + for( ;kind == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + // + if( strncmp( pszP, aszParamChange[i], 2 ) == 0 ){ + kind = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( kind == -1 ) return FALSE; + + if( strstr( pszP, "%" ) ){ // ѻң + par = 1; + } + + if( sscanf( pszP, "%d", &pow ) != 1 ){ + // Ϻ̼ؤ¾ + pow = 30; + } + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiParamChange( battleindex, attackNo, toNo, + kind, pow, par, MAGIC_EFFECT_USER, SPR_hoshi ); + + + return TRUE; +} + + + +#endif + + + + + + + +//**************************************************************** +// +// м ëܸ +// +int MAGIC_AttReverse_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** + +{ + int attackNo; + int battleindex; + + // ɷ¶ἰǷ + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiAttReverse( battleindex, attackNo, toNo, + MAGIC_EFFECT_USER, SPR_kyu ); + + + return TRUE; +} + + + +//**************************************************************** +// +// ë +// +int MAGIC_StatusRecovery_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** +{ + char *magicarg; + int status = -1, i, attackNo; + int battleindex, ReceveEffect; + char *pszP; + + // ɷ¶ë + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + pszP = magicarg; + // ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + // ؤ¼ƥ߾ո + for( i = 0; i < BATTLE_ST_END; i ++ ){ + // + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + // ئмƥ + if( status == -1 ) return FALSE; + + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + ReceveEffect = SPR_tyusya; // 巴ľ + + // 幻 + BATTLE_MultiStatusRecovery( battleindex, attackNo, toNo, + status, MAGIC_EFFECT_USER, ReceveEffect ); + + + return TRUE; + +} + + +//**************************************************************** +// +// 姾 +// +int MAGIC_Ressurect_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** +{ + char *magicarg; + int attackNo, ReceveEffect; + int battleindex, pow = 0, par = 0; + + char *pszP; + + // ɷ¶ë + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + pszP = magicarg; + + if( strstr( pszP, "%" ) ){ // ѻң + par = 1; + } + if( sscanf( pszP, "%d", &pow ) != 1 ){ + // Ϻ̼¾ + pow = 0; // ߼ + } + + if( pow <= 0 ){ + ReceveEffect = SPR_fukkatu3; + }else + if( pow <= 100 ){ + ReceveEffect = SPR_fukkatu1; + }else + if( pow <= 300 ){ + ReceveEffect = SPR_fukkatu2; + }else{ + ReceveEffect = SPR_fukkatu3; + } + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiRessurect( battleindex, attackNo, toNo, + pow, par, MAGIC_EFFECT_USER, ReceveEffect ); + + return TRUE; +} + + +int MAGIC_ResAndDef_Battle( + int charaindex, + int toNo, + int marray, + int mp +) +{ + char *magicarg; + int attackNo, i; + int battleindex, pow = 0, par = 0, turn = 3, status = -1; + // Robin 03/21 debug + //char szTurn[] = ""; + char szTurn[] = "turn"; + + char *pszP; +#ifdef _PREVENT_TEAMATTACK +// Terry add 2004/12/7 + // ..ʹõз + battleindex = CHAR_getWorkInt(charaindex, CHAR_WORKBATTLEINDEX); + if(CHAR_getInt(charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) + { + if(BATTLE_CheckSameSide(charaindex, toNo) == 0) //ͬ + { + battleindex = CHAR_getWorkInt(charaindex, CHAR_WORKBATTLEINDEX); + BATTLE_NoAction(battleindex, BATTLE_Index2No(battleindex, charaindex)); + CHAR_talkToCli(charaindex, -1, "⾵..ʩҵз", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif +// end + // ɷ¶ë + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + pszP = magicarg; + + if( strstr( pszP, "%" ) ){ // ѻң + par = 1; + } + if( sscanf( pszP, "%d", &pow ) != 1 ){ + // Ϻ̼¾ + pow = 0; // ߼ + } + + // ܰ ܷ ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_MD_END; i ++ ){ + char *p; + // + p = strstr( pszP, aszMagicDef[i] ); + if( p != NULL ){ + status = i; + pszP = p; + break; + } + } + } + + // ئмƥ + if( status == -1 ) return FALSE; + + // ϼ ʽ¾ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiResAndDef( battleindex, attackNo, toNo, + pow, par, status, turn, MAGIC_EFFECT_USER, SPR_difence ); + + return TRUE; +} + +#ifdef _ATTACK_MAGIC + +int MAGIC_AttMagic_Battle( int charaindex , int toNo , int marray , int mp ) +{ + int attno , attidx , battleindex; + int attr = -1, i , power; + char aszattr[][32] = { "", "ˮ", "", "" }; + char buf1[256]; + char *magicarg; + int magiclv=0; + magicarg = MAGIC_getChar( marray , MAGIC_OPTION ); + if( magicarg == "\0" ) { + print("\n Magic magicarg == NULL "); + return FALSE; + } + + for( i=0; i<4; i++) { + if( strstr( magicarg, aszattr[i]) != NULL ) { + attr = i; + break; + } + } + if( i == 4 ) { + print("\n not find aszattr !!"); + return FALSE; + } + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( magicarg, "|", 2, buf1, sizeof( buf1)) == FALSE ) return FALSE; + power = atoi( buf1); + + if( getStringFromIndexWithDelim( magicarg, "|", 3, buf1, sizeof( buf1)) == FALSE ) return FALSE; + magiclv = atoi( buf1); + + battleindex = CHAR_getWorkInt( charaindex , CHAR_WORKBATTLEINDEX ); + attno = BATTLE_Index2No( battleindex , charaindex ); + attidx = MAGIC_getInt( marray , MAGIC_IDX ); + if( -1 == attidx || attidx >= ATTMAGIC_magicnum ) + return FALSE; +#ifdef _FIX_MAGICDAMAGE + BATTLE_MultiAttMagic( battleindex , attno , toNo , attidx , attr , power, magiclv); +#else + BATTLE_MultiAttMagic( battleindex , attno , toNo , attidx , attr , power ); +#endif + return TRUE; +} + +#endif + + +#ifdef _MAGIC_TOCALL + +int MAGIC_ToCallDragon_Battle( int charaindex , int toNo , int marray , int mp ) +{ + int attno , attidx , battleindex; + int attr = -1,/* i , */power, imageno; +// char aszattr[][32] = { "", "ˮ", "", "" }; + char buf1[256]; + char *magicarg; + //int magiclv=0; + magicarg = MAGIC_getChar( marray , MAGIC_OPTION ); + + if( magicarg == "\0" ) { + print("\n Magic magicarg == NULL "); + return FALSE; + } +/* + for( i=0; i<4; i++) { + if( strstr( magicarg, aszattr[i]) != NULL ) { + attr = i; + break; + } + } + if( i == 4 ) { + print("\n not find aszattr !!"); + return FALSE; + } +*/ + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( magicarg, "|", 1, buf1, sizeof( buf1)) == FALSE ) return FALSE; + imageno = atoi( buf1); + if( getStringFromIndexWithDelim( magicarg, "|", 2, buf1, sizeof( buf1)) == FALSE ) return FALSE; + power = atoi( buf1); + + battleindex = CHAR_getWorkInt( charaindex , CHAR_WORKBATTLEINDEX ); + attno = BATTLE_Index2No( battleindex , charaindex ); + attidx = MAGIC_getInt( marray , MAGIC_IDX ); + if( -1 == attidx || attidx >= ATTMAGIC_magicnum ) + return FALSE; + + BATTLE_MultiToCallDragonMagic( battleindex , attno , toNo , attidx , attr , power, imageno); + + return TRUE; +} + +#endif + +//**************************************************************** +// +// +// +int MAGIC_CaptureUp_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +) +// TRUE +// FALSE +//**************************************************************** +{ + char *magicarg; + int attackNo, ReceveEffect; + int battleindex, pow = 5; + + // ɷ¶ë + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + if( sscanf( magicarg, "%d", &pow ) != 1 ){ + // Ϻ̼¾ + pow = 5; + } + + ReceveEffect = SPR_hoshi; + + // į + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + + // 幻 + BATTLE_MultiCaptureUp( battleindex, attackNo, toNo, + pow, MAGIC_EFFECT_USER, ReceveEffect ); + + return TRUE; +} +#ifdef _FIX_MAGICDAMAGE +static int BATTLE_getMagicAdjustInt( int attackindex, int defindex, int MagicLv, int flg,int damage ) +{ + int At_Fire, At_Earth, At_Water, At_Wind, At_none; + int Df_Fire, Df_Earth, Df_Water, Df_Wind, Df_none; + float At_FieldPow, Df_FieldPow; + + //ȡʩ + BATTLE_GetAttr(attackindex,&At_Fire,&At_Water,&At_Earth,&At_Wind,&At_none); + MagicLv *=10; + switch( flg) { //ûΪħǣ + case 0: + At_Earth = MagicLv+(MagicLv*(At_Earth/50)); + At_Water=0; At_Fire=0; At_Wind=0; + break; + case 1: + At_Water = MagicLv+(MagicLv*(At_Water/50)); + At_Earth=0; At_Fire=0; At_Wind=0; + break; + case 2: + At_Fire = MagicLv+(MagicLv*(At_Fire/50)); + At_Earth=0; At_Water=0; At_Wind=0; + break; + case 3: + At_Wind = MagicLv+(MagicLv*(At_Wind/50)); + At_Earth=0; At_Water=0; At_Fire=0; + break; + } + //ȡøóԼӳ + At_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( attackindex, CHAR_WORKBATTLEINDEX ), + At_Fire, At_Water, + At_Earth, At_Wind ); + + At_Fire *= damage; At_Water *= damage; At_Earth *= damage; + At_Wind *= damage; At_none *= damage; + + //ȡ÷ط + BATTLE_GetAttr( defindex, &Df_Fire, &Df_Water, + &Df_Earth,&Df_Wind, &Df_none ); + //ȡøóԼӳ + Df_FieldPow = BATTLE_FieldAttAdjust( + CHAR_getWorkInt( defindex, CHAR_WORKBATTLEINDEX ), + Df_Fire, Df_Water, Df_Earth, Df_Wind ); + // + damage = BATTLE_AttrCalc( + At_Fire, At_Water, At_Earth, At_Wind, At_none, + Df_Fire, Df_Water, Df_Earth, Df_Wind, Df_none ); + damage *= (At_FieldPow / Df_FieldPow); + return damage; +} + +void Magic_ComputeAttExp( int charindex, int Mnum, int MagicLv, int Expoint) +{ + int magiclv1, magicex1; + int addEx = (MagicLv * 3) * Expoint; + char MagicStr[][128]={"","ˮ","",""}; + char buf1[256]; + memset( buf1, 0, sizeof( buf1)); + magiclv1 = CHAR_getInt( charindex, CHAR_EARTH_EXP+Mnum); + magicex1 = CHAR_getInt( charindex, CHAR_EARTH_ATTMAGIC_EXP+Mnum); + magicex1 += addEx; + if( magicex1 > 100 ) { + magicex1 = 0; + if( magiclv1 < 100 ) { + magiclv1 += 1; + sprintf( buf1,"%sħΪ%d", MagicStr[Mnum], magiclv1); + CHAR_talkToCli( charindex, -1, buf1, CHAR_COLORYELLOW); + } + } + if( magicex1 < 0 ) magicex1 = 0; + if( magiclv1 < 0 ) magiclv1 = 0; + if( magiclv1 > 100 ) magiclv1 = 100; + CHAR_setInt( charindex, CHAR_EARTH_EXP+Mnum, magiclv1); + CHAR_setInt( charindex, CHAR_EARTH_ATTMAGIC_EXP+Mnum, magicex1); + + Mnum = (Mnum+1)%4; //˵ħ + magiclv1 = CHAR_getInt( charindex, CHAR_EARTH_EXP+Mnum); + magicex1 = CHAR_getInt( charindex, CHAR_EARTH_ATTMAGIC_EXP+Mnum); + if( magiclv1 > 1 ) { + magicex1 -= addEx*0.5; + if( magicex1 < 0 ) { + magicex1 = 0; + magiclv1 -= 1; + if( magiclv1 < 0 ) magiclv1 = 0; + CHAR_setInt( charindex, CHAR_EARTH_EXP+Mnum, magiclv1); + sprintf( buf1,"%sħ½Ϊ%d", MagicStr[Mnum], magiclv1); + CHAR_talkToCli( charindex, -1, buf1, CHAR_COLORYELLOW); + } + CHAR_setInt( charindex, CHAR_EARTH_ATTMAGIC_EXP+Mnum, magicex1); + } + return; +} + +void Magic_ComputeDefExp( int charindex, int Mnum, int MagicLv, int Damage) +{ + if( !CHAR_CHECKINDEX( charindex ) )return; + int magiclv1; + int magicex1; + int addEx; + char buf1[256]; + char MagicStr[][128]={"","ˮ","",""}; + if( Damage < 200 ) return; + memset( buf1, 0, sizeof( buf1)); + magiclv1 = CHAR_getInt( charindex, CHAR_EARTH_RESIST+Mnum); + magicex1 = CHAR_getInt( charindex, CHAR_EARTH_DEFMAGIC_EXP+Mnum); + addEx = (Damage/20)*(MagicLv*2); + magicex1+=addEx; + if( magiclv1 < 0 ) magiclv1 = 0; + if( magicex1 > 100 ) { + magicex1 = 0; + if( magiclv1 < 100 ) { + magiclv1 +=1; + if( magiclv1 < 0 ) magiclv1 = 0; + if( magiclv1 > 100 ) magiclv1 = 100; + CHAR_setInt( charindex, CHAR_EARTH_RESIST+Mnum, magiclv1); + sprintf( buf1,"%sħֵΪ%d", MagicStr[Mnum], magiclv1); + CHAR_talkToCli( charindex, -1, buf1, CHAR_COLORYELLOW); + } + } + if( magicex1 < 0 ) magicex1 = 0; + CHAR_setInt( charindex, CHAR_EARTH_DEFMAGIC_EXP+Mnum, magicex1); + Mnum = (Mnum+1)%4; //˵ħ + magiclv1 = CHAR_getInt( charindex, CHAR_EARTH_RESIST+Mnum); + magicex1 = CHAR_getInt( charindex, CHAR_EARTH_DEFMAGIC_EXP+Mnum); + if( magiclv1 > 1 ) { + magicex1 -=2; + if( magicex1 < 0 ) { + magicex1 = 90; + magiclv1 -=1; + if( magiclv1 < 0 ) + magiclv1 = 0; + sprintf( buf1,"%sħֵ½Ϊ%d", MagicStr[Mnum], magiclv1); + CHAR_talkToCli( charindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_setInt( charindex, CHAR_EARTH_RESIST+Mnum, magiclv1); + } + CHAR_setInt( charindex, CHAR_EARTH_DEFMAGIC_EXP+Mnum, magicex1); + } + return; +} + +#endif + +#ifdef _MAGIC_WEAKEN +int MAGIC_ParamChange_Turn_Battle( + int charaindex, + int toNo, + int marray, + int mp +) +{ + char *magicarg; + int status = -1, i, attackNo, turn = 3; + int battleindex, Success = 15; + char *pszP; + char szTurn[] = "turn"; + char szSuccess[] = ""; + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + // ë + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + // ྮո + for( i = 1; i < BATTLE_ST_END; i ++ ){ + // + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( status == -1 ) return FALSE; + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + BATTLE_MultiParamChangeTurn( battleindex, attackNo, toNo, status, MAGIC_EFFECT_USER, SPR_hoshi, turn, Success ); + return TRUE; +} + +void BATTLE_MultiParamChangeTurn( + int battleindex, + int attackNo, + int toNo, + int status, + int UseEffect, + int RecevEffect, + int turn, + int Success +) +{ + + int i, toindex,perStatus,charaindex; + int ToList[SIDE_OFFSET*2+1]; + charaindex = BATTLE_No2Index( battleindex, attackNo ); //index + BATTLE_MultiList( battleindex, toNo, ToList ); + + //ʩħЧ + BATTLE_MagicEffect(battleindex, attackNo, ToList, UseEffect, RecevEffect); + + for( i = 0; ToList[i] != -1; i ++ ) + { + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + + if( BATTLE_StatusAttackCheck( charaindex, + toindex, status, Success, 30, 1.0, &perStatus ) == TRUE ) + { + CHAR_setWorkInt( toindex, CHAR_WORKWEAKEN, turn+1 ); + } + } + return; + +} +#endif + + +/* +typedef struct tagToCallMagic +{ + unsigned int uiSpriteNum; // Spr_x.binı + unsigned int uiAttackType; // ķʽˣ( ) , ( ) , ( ͬʱ ) , ȫ( ) , ȫ( ͬʱ ) + unsigned int uiSliceTime; // ʱʱ + unsigned int uiShowType; // ʾλ÷ʽ롢ָ + int siSx; // ʾλ - X + int siSy; // ʾλ - Y + unsigned int uiShowBehindChar; // ʾǰ· + unsigned int uiShakeScreen; // Ƿ𶯻 + unsigned int uiShakeFrom; // 𶯻ʼʱ( ) + unsigned int uiShakeTo; // 𶯻Ľʱ( _ + unsigned int uiPrevMagicNum; // ǰ( 0XFFFFFFFFFF ʾǰ ) + int siPrevMagicSx; // ǰʾλ - X + int siPrevMagicSy; // ǰʾλ - Y + int siPrevMagicOnChar; // ǰʾǰ· + unsigned int uiPostMagicNum; // ( 0XFFFFFFFF ʾ ) + int siPostMagicSx; // ʾλ - X + int siPostMagicSy; // ʾλ - Y + int siPostMagicOnChar; // ʾǰ· + int isPostDisappear; // һ㹥ʱǷʧ + int ToCallMagicNo; // ٻı +}ToCallMagic; +*/ + +ToCallMagic PROFESSION_magic[3] = { {0,0,0,1,0,0,1,1,0,0,0,65528,65485,0,-1,0,0,0,1,0}, // + {0,3,0,1,0,0,1,1,0,0,0,65528,65485,0,-1,0,0,0,1,1}, // + {0,5,0,1,0,0,1,1,0,0,0,65528,65485,0,-1,0,0,0,0,2}, // ȫ + }; + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +void PROFESSION_MAGIC_ATTAIC( int battleindex, int attackNo, int toNo, int attIdx ,int FieldAttr, int skill) +{ + int list[SIDE_OFFSET * 2 + 1]; + int listidx,i,j,k,z; + int basey, def_is_player[10],def_be_hit[10]; + int attvalue , charahp , pethp , charaidx , petidx , charahurt,charahurt_temp; + char szcommand[256]; + int DefIsPlayer=0, power=0, skill_level; + float hp_power=0, mp_power=0, add_hp=0, add_mp=0, dec_hp=0, dec_mp=0; + int icindex, ioindex; + int charaindex, command, magic_type=0; +#ifdef _PROFESSION_ADDSKILL + int decmplist[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, decmplistcount=0; +#endif + charaindex = BATTLE_No2Index(battleindex, attackNo); + if( !CHAR_CHECKINDEX(charaindex) ) return; + + if((z = BATTLE_MultiList(battleindex,toNo,list)) == -1) return; + else if(z != toNo){ + toNo = z; +// terry fix for 趨ΪµĿ 2004/02/10 + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM2,toNo); +// end + } + + // + command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1); + + // ܵȼ + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + // ħ붯 + magic_type = analysis_profession_parameter( attIdx, skill, toNo, charaindex ); + PROFESSION_MAGIC_ATTAIC_Effect( battleindex, attackNo, list, attIdx); + + listidx = 0; + memset(def_is_player,-1,sizeof(def_is_player)); + memset(def_be_hit,-1,sizeof(def_be_hit)); + + // ˹ + if( toNo < 20 ){ + toNo = list[0]; + listidx++; + + } else if( 20 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[i + 2][j] ) ){ + list[listidx] = CharTable[i + 2][j]; + listidx++; + } + } + } + } else if( 21 == toNo ){ // ȫ + for( i = 0 ; i < 2 ; i++ ){ + for( j = 0 ; j < 5 ; j++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[i][j] ) ){ + list[listidx] = CharTable[i][j]; + listidx++; + } + } + } + } // ϵһ , ϵڶ , µһ , µڶ + else if( 23 == toNo || 24 == toNo || 25 == toNo || 26 == toNo ){ + basey = toNo - 23; + for( i = 0 , j = basey - 1 ; j <= basey + 1 ; i++ , j++ ){ + if( ( 25 == toNo || 26 == toNo ) && ( j < 2 || j > 3 ) ) + continue; + else if( ( 23 == toNo || 24 == toNo ) && ( j < 0 || j > 1 ) ) + continue; + // ЩҪ嵥 + for( k = 0 ; k < 5 ; k++ ){ + if(TRUE == BATTLE_TargetCheck( battleindex , CharTable[j][k] ) ) + { + list[listidx] = CharTable[j][k]; + listidx++; + } + } + } + } + qsort( list , listidx , sizeof( list[0] ) , ( FUNC )SortLoc );// λ + + // ȡ + PROFESSION_MAGIC_GET_PRACTICE( &hp_power, &mp_power, &dec_hp, &dec_mp, charaindex ); + + + power = hp_power; + + // ȡ list + PROFESSION_MAGIC_TOLIST_SORT( list, &listidx, charaindex ); + + for( i = 0 ; i < listidx ; i++ ) { + int defType; + charaidx = BATTLE_No2Index( battleindex , list[i] ); + petidx = BATTLE_getRidePet( charaidx ); + defType = CHAR_getInt(charaidx, CHAR_WHICHTYPE); + DefIsPlayer = 0; + + if( !CHAR_CHECKINDEX(charaidx) ) continue; + + // ħЧ + if (CHAR_createCharacter( 100354, 777, 45, 45, 0, &icindex, &ioindex, 0) == TRUE){ + + CHAR_setInt( icindex, CHAR_LUCK, 1); + CHAR_setWorkInt( icindex, CHAR_WORKATTACKPOWER, power ); + CHAR_setWorkInt( icindex, CHAR_WORKOTHERDMAGE, 0 ); + + + // ħм춨 + if( PROFESSION_MAGIC_DODGE( charaindex, charaidx, magic_type ) == 1 ){ + // MISS + attvalue = 0; + }else{ + // ȡħ˺ֵ + power = PROFESSION_MAGIC_GET_ICE_MIRROR_DAMAGE( charaindex, charaidx, command, power ); +#ifdef _SUIT_ADDPART4 + if( CHAR_getWorkInt( charaidx, CHAR_WORKUNMPOWER ) > 0 ){//ֿʦħװ + power -= power * (CHAR_getWorkInt( charaidx, CHAR_WORKUNMPOWER )/100.00); +// print("\nWORKUNMPOWER:%d", CHAR_getWorkInt( charaidx, CHAR_WORKUNMPOWER )); + } +#endif + // ȡħ˺ֵ +#ifdef _PROFESSION_ADDSKILL + attvalue = PROFESSION_MAGIC_GET_DAMAGE( charaindex, charaidx, magic_type, power, command ); +#else + attvalue = PROFESSION_MAGIC_GET_DAMAGE( charaindex, charaidx, magic_type, power ); +#endif + // ı״̬ħ + PROFESSION_MAGIC_CHANGE_STATUS( charaindex, attvalue, mp_power, &add_hp, &add_mp ); + + // ⹥ + attvalue = PROFESSION_MAGIC_CHANG_STATUS( command, battleindex, charaindex, charaidx, attvalue, i ); + def_be_hit[i] = charaidx; +#ifdef _PROFESSION_ADDSKILL + if( command == BATTLE_COM_S_STORM ){// ˮ + if( (PROFESSION_BATTLE_StatusAttackCheck( charaindex, charaidx, BATTLE_ST_WATER, 30 ) == 0 )// ״̬м춨 + || (CHAR_getInt( charaidx, CHAR_HP ) <= 0 ) ){ + + }else{ + int bid = BATTLE_Index2No( battleindex, charaidx ); + int watercount=0; + if( skill_level > 8 ) watercount=5; + else if( skill_level > 6 ) watercount=4; + else if( skill_level > 4 ) watercount=3; + else if( skill_level > 3 ) watercount=2; + else watercount=1; + CHAR_setWorkInt( charaidx, CHAR_WORKWATER, watercount ); + BATTLE_BadStatusString( bid, BATTLE_ST_WATER ); + } + } + + //¼idx + decmplist[decmplistcount++] = list[i]; +#endif + } + + // ħЧ + CHAR_CharaDelete(icindex); + + + charahp = CHAR_getInt( charaidx, CHAR_HP ); + + // û + if( -1 == petidx || CHAR_getInt(petidx, CHAR_HP) <= 0 ){ + if( ( charahp -= attvalue ) < 0 ){ + charahp = 0; + } + CHAR_setInt( charaidx , CHAR_HP , charahp ); + pethp = 0; + if( 0 == PROFESSION_magic[attIdx].uiAttackType ) {// ˹ + sprintf( szcommand , "%X|%X|%X|%X|" , toNo , list[i] , attvalue , pethp); + } else + sprintf( szcommand , "%X|%X|%X|%X|" , list[i] , list[i] , attvalue , pethp); + + }else{ + pethp = CHAR_getInt( petidx , CHAR_HP ); + charahurt = attvalue * BATTLE_CalcCharaRatio( FieldAttr , charaidx ) / 10; + + //µļ,ﱻ,Ѫ۵Ļ,Ὣ˺ۼ + charahurt_temp = charahurt; + if( ( charahp -= charahurt ) < 0 ) + { + charahurt = charahp; + charahp = 0; + } + + attvalue = attvalue - charahurt; + if( ( pethp -= attvalue ) < 0) + { + pethp = 0; + // ûѪ˳ս + CHAR_setInt(charaidx,CHAR_RIDEPET,-1); + BATTLE_changeRideImage(charaidx); + CHAR_setWorkInt(charaidx,CHAR_WORKPETFALL,1); + } + CHAR_setInt( charaidx , CHAR_HP , charahp ); + CHAR_setInt( petidx , CHAR_HP , pethp ); + + charahurt = charahurt_temp; + + if( 0 == PROFESSION_magic[attIdx].uiAttackType ) {// ˹ + sprintf( szcommand , "%X|%X|%X|%X|" , toNo , list[i] , charahurt , attvalue); + } else + sprintf( szcommand , "%X|%X|%X|%X|" , list[i] , list[i] , charahurt , attvalue); + } + + + { + //Change fix õDPֵ + int aAttackList[BATTLE_ENTRY_MAX*2+1]; + aAttackList[0] = attackNo; + aAttackList[1] = -1; + BATTLE_AddProfit( battleindex, aAttackList); + } + //change fix ޿ (зְսᶼòDPֵ,õ,ûϵ) + if( CHAR_getInt( charaidx, CHAR_HP ) <= 0 + && CHAR_getInt( charaidx, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + /*&& !BattleArray[battleindex].dpbattle*/ ) + CHAR_setFlg( charaidx, CHAR_ISDIE, 1 ); + + BATTLESTR_ADD( szcommand ); + } + } + + sprintf( szcommand , "%X|" , 0x5711438 ); + BATTLESTR_ADD( szcommand ); + +#ifdef _PROFESSION_ADDSKILL + //۵зmp + if( (int)mp_power != 0 ){ + for( i=0;i 0 ){ + int mp = CHAR_getInt( BATTLE_No2Index( battleindex , decmplist[i] ), CHAR_MP); + if( mp > 0 ){ + mp = mp_power>mp?mp:mp_power; + sprintf( szcommand, "BD|r%X|1|0|m%X|", decmplist[i], mp ); + BATTLESTR_ADD( szcommand ); + CHAR_setInt(BATTLE_No2Index( battleindex , decmplist[i] ), CHAR_MP, CHAR_getInt( BATTLE_No2Index( battleindex , decmplist[i] ), CHAR_MP) - mp); + } + } + } + } + } + if( command == BATTLE_COM_S_DOOM ){ //ĩ Ч + if( skill_level >= 10 ){ + for( i=0;i 0 ){ + CHAR_setWorkInt( BATTLE_No2Index( battleindex , decmplist[i] ), CHAR_WORKFEAR, 4 ); + BATTLE_BadStatusString( decmplist[i], BATTLE_ST_FEAR ); + sprintf( szcommand, "BD|r%X|0|6|%X|", decmplist[i], -20 );//30% + BATTLESTR_ADD( szcommand ); + // + sprintf( szcommand, "BD|r%X|0|4|%X|", decmplist[i], -10 ); + BATTLESTR_ADD( szcommand ); + // + sprintf( szcommand, "BD|r%X|0|5|%X|", decmplist[i], -10 ); + BATTLESTR_ADD( szcommand ); + } + } + } + } +#endif + if( (int)add_hp != 0 ){ + int hp=0; + + hp = CHAR_getInt( charaindex, CHAR_HP) + add_hp; + + if( hp >= CHAR_getWorkInt(charaindex, CHAR_WORKMAXHP) ){ + hp = CHAR_getWorkInt(charaindex, CHAR_WORKMAXHP); + add_hp = hp - CHAR_getInt( charaindex, CHAR_HP); + }else if ( hp <= 1 ){ + hp = 1; + add_hp = 1 - CHAR_getInt( charaindex, CHAR_HP); + } + CHAR_setInt(charaindex, CHAR_HP, hp); + + sprintf( szcommand, "BD|r%X|0|1|%X|", attackNo, (int)add_hp); + BATTLESTR_ADD( szcommand ); + } + + + if( (int)add_mp != 0 ){ + int mp=0; + + mp = CHAR_getInt( charaindex, CHAR_MP) + add_mp; + + if( mp >= CHAR_getWorkInt(charaindex, CHAR_WORKMAXMP) ){ + mp = CHAR_getWorkInt(charaindex, CHAR_WORKMAXMP); + add_mp = mp - CHAR_getInt( charaindex, CHAR_MP); + }else if ( mp <= 1 ){ + mp = 1; + add_mp = 1 - CHAR_getInt( charaindex, CHAR_MP); + } + + CHAR_setInt(charaindex, CHAR_MP, mp); + + sprintf( szcommand, "BD|r%X|1|1|m%X|", attackNo, (int)add_mp); + + BATTLESTR_ADD( szcommand ); + } +// Terry fix 2003/11/17 ˯˹Է + for(i=0; i 0) { + CHAR_setWorkInt(def_be_hit[i],CHAR_WORKSLEEP,0); + sprintf(szcommand,"BM|%X|%X|",BATTLE_Index2No(battleindex,def_be_hit[i]),0); + BATTLESTR_ADD(szcommand); + } + } +// Terry end +} + + +int PROFESSION_MAGIC_ATTAIC_Effect( int battleindex, int attackNo , int ToList[] , int AttackMgcNo ) +{ + int i; + char szcommand[256]; + int attackindex; + + + attackindex = BATTLE_No2Index( battleindex , attackNo ); + if( FALSE == CHAR_CHECKINDEX( attackindex ) ) + return 0; +#ifdef _PROFESSION_ADDSKILL + //if( CHAR_getWorkInt( attackindex, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_ICE_CRACK ) //Ч + // return 0; +#endif + snprintf( szcommand , sizeof( szcommand ) , "B$|a%X|i%X|m%X|%X|%X|%X|s%X|t%X|l%X|%X|%X|%X|%X|%X|%X|o%X|o%X|o%X|s%X|%X|%X|%X|%X|" , + attackNo , 5711438 , CHAR_getInt( attackindex , CHAR_MP ) , + PROFESSION_magic[AttackMgcNo].uiPrevMagicNum , + PROFESSION_magic[AttackMgcNo].uiSpriteNum , + PROFESSION_magic[AttackMgcNo].uiPostMagicNum , + PROFESSION_magic[AttackMgcNo].uiAttackType , + PROFESSION_magic[AttackMgcNo].uiSliceTime , + PROFESSION_magic[AttackMgcNo].uiShowType , + PROFESSION_magic[AttackMgcNo].siSx , + PROFESSION_magic[AttackMgcNo].siSy , + PROFESSION_magic[AttackMgcNo].siPrevMagicSx , + PROFESSION_magic[AttackMgcNo].siPrevMagicSy , + PROFESSION_magic[AttackMgcNo].siPostMagicSx , + PROFESSION_magic[AttackMgcNo].siPostMagicSy , + PROFESSION_magic[AttackMgcNo].siPrevMagicOnChar , + PROFESSION_magic[AttackMgcNo].uiShowBehindChar , + PROFESSION_magic[AttackMgcNo].siPostMagicOnChar , + PROFESSION_magic[AttackMgcNo].uiShakeScreen , + PROFESSION_magic[AttackMgcNo].uiShakeFrom , + PROFESSION_magic[AttackMgcNo].uiShakeTo , + PROFESSION_magic[AttackMgcNo].isPostDisappear , + PROFESSION_magic[AttackMgcNo].ToCallMagicNo + ); + + BATTLESTR_ADD( szcommand ); + + for( i = 0 ; ToList[i] != -1 ; i++ ){ + snprintf( szcommand , sizeof( szcommand ) , "r%X|" , ToList[i] ); + BATTLESTR_ADD( szcommand ); + } + + BATTLESTR_ADD( "FF|" ); + + return 0; +} + +int analysis_profession_parameter( int attIdx, int skill, int toNo, int charaindex ) +{ + int image_1, image_2, place, place2, shake_s_time; + int shake_e_time, disappear, x, y, i; + char temp[64]; + char *pszOption; + // Robin fix profession magic_type + //char magic[3][5]={"","",""}; + char magic[3][5]={"","",""}; + int magic_type=-1; + + + // ȡüܲ + if( (pszOption=PROFESSION_SKILL_getChar(skill,PROFESSION_SKILL_OPTION)) == "\0" ) return -1; + + // ħ + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",1,temp,sizeof(temp)) ) return -1; + + for( i=0; i<3; i++){ + if( (strcmp( magic[i], temp )) == 0 ) + magic_type = i+1; + } + + switch( magic_type ){ + case 1: + // ӻȾֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_FIRE_PRACTICE" ); + break; + case 2: + // ӱȾֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_ICE_PRACTICE" ); + break; + case 3: + // Ⱦֵ + PROFESSION_SKILL_LVEVEL_UP( charaindex, "PROFESSION_THUNDER_PRACTICE" ); + break; + + } + + // ʾλ÷ʽ 0 1 + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",2,temp,sizeof(temp)) ) return -1; + place = atoi(temp); + PROFESSION_magic[attIdx].uiShowType = place; + + // ʾǰ· + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",3,temp,sizeof(temp)) ) return -1; + place2 = atoi(temp); + PROFESSION_magic[attIdx].uiShowBehindChar = place2; + + // ʾλX + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",4,temp,sizeof(temp)) ) return -1; + x = atoi(temp); + + // ʾλY + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",5,temp,sizeof(temp)) ) return -1; + y = atoi(temp); + + // 𶯻Ŀʼ + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",6,temp,sizeof(temp)) ) return -1; + shake_s_time = atoi(temp); + + // 𶯻Ľ + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",7,temp,sizeof(temp)) ) return -1; + shake_e_time = atoi(temp); + + // һ㹥ʱǷʧ + memset( temp, 0, sizeof(temp) ); + if( !getStringFromIndexWithDelim(pszOption,"|",8,temp,sizeof(temp)) ) return -1; + disappear = atoi(temp); + + // ׼ħͼ + image_1 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_1); + PROFESSION_magic[attIdx].uiPrevMagicNum = image_1; // ǰö + + // սħͼ + image_2 = PROFESSION_SKILL_getInt( skill, PROFESSION_SKILL_IMG_2); + PROFESSION_magic[attIdx].uiSpriteNum = image_2; // ö + + // ʾڻ x,y + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + + // ȡùұߵħͼż + PROFESSION_MAGIC_GET_IMG2( toNo, charaindex, attIdx, pszOption ); + + // ʱ + if( (shake_s_time>0) || (shake_e_time>0) ){ + PROFESSION_magic[attIdx].uiShakeScreen = 1; + PROFESSION_magic[attIdx].uiShakeFrom = shake_s_time; + PROFESSION_magic[attIdx].uiShakeTo = shake_e_time; + }else{ + PROFESSION_magic[attIdx].uiShakeScreen = 0; + PROFESSION_magic[attIdx].uiShakeFrom = 0; + PROFESSION_magic[attIdx].uiShakeTo = 0; + } + + + return magic_type; +} + + +// ȡȵ˺ +void PROFESSION_MAGIC_GET_PRACTICE( + float *hp_power, + float *mp_power, + float *dec_hp, + float *dec_mp, + int charaindex +) +{ + int skill_level=0, critical=0, command=0; + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1); + + critical = RAND( 1,100); + + switch( command ){ + case BATTLE_COM_S_VOLCANO_SPRINGS: // ɽȪ + { + *hp_power = skill_level * 10 + 100; + + if( skill_level >= 10 ){ + if( critical <= 25 ) + *hp_power *= 1.5; + }else{ + if( critical <= (skill_level+12) ) + *hp_power *= 1.5; + } + + break; + } + case BATTLE_COM_S_FIRE_BALL: // + { + if( skill_level >= 10 ) + *hp_power = 360; + else if( skill_level >= 9 ) + *hp_power = 320; + else if( skill_level >= 8 ) + *hp_power = 280; + else if( skill_level >= 7) + *hp_power = 260; + else if( skill_level >= 5) + *hp_power = 220; + else if( skill_level >= 3) + *hp_power = 180; + else + *hp_power = 160; + + break; + } + case BATTLE_COM_S_SUMMON_THUNDER: // + { + *hp_power = skill_level*10 + 200; + break; + } + case BATTLE_COM_S_CURRENT: // + { +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ) + *hp_power = 300; + else if( skill_level > 9 ) + *hp_power = 250; + else if( skill_level > 7 ) + *hp_power = 200; + else if( skill_level > 4 ) + *hp_power = 150; + else if( skill_level > 1 ) + *hp_power = 10; + else + *hp_power = 50; +#else + *hp_power = skill_level*50 + 100; +#endif + break; + } + case BATTLE_COM_S_STORM: // + { +#ifdef _PROFESSION_ADDSKILL + if( skill_level > 9 ) + *hp_power = 200; + else if( skill_level > 7 ) + *hp_power = 180; + else if( skill_level > 5 ) + *hp_power = 160; + else if( skill_level > 3 ) + *hp_power = 140; + else + *hp_power = 120; +#else + *hp_power = skill_level*10 + 100; +#endif + break; + } + case BATTLE_COM_S_ICE_ARROW: // + { + if( skill_level >= 10 ) + *hp_power = 250; + else + *hp_power = skill_level*10 + 130; + break; + } + case BATTLE_COM_S_ICE_CRACK: // + { + if( skill_level >= 10 ) + *hp_power = 400; + else if ( skill_level == 9 ) + *hp_power = 300; + else + *hp_power = skill_level*10 + 210; + + break; + } + case BATTLE_COM_S_DOOM: // ĩ + { + if( skill_level >= 10 ) + *hp_power = 550; + else if( skill_level > 9 ) + *hp_power = 500; + else if( skill_level > 8 ) + *hp_power = 450; + else if( skill_level > 7 ) + *hp_power = 400; + else if( skill_level > 6 ) + *hp_power = 350; + else if( skill_level > 4 ) + *hp_power = 300; + else if( skill_level > 2 ) + *hp_power = 250; + else + *hp_power = 200; + break; + } + case BATTLE_COM_S_FIRE_SPEAR: // ǹ + { + if( skill_level > 9 ) + *hp_power = 800; + else if( skill_level > 8 ) + *hp_power = 450; + else if( skill_level > 7 ) + *hp_power = 400; + else if( skill_level > 6 ) + *hp_power = 350; + else if( skill_level > 5 ) + *hp_power = 300; + else if( skill_level > 3 ) + *hp_power = 200; + else + *hp_power = 100; + break; + } + + case BATTLE_COM_S_BLOOD: // Ѫ + { + int hp = CHAR_getInt( charaindex, CHAR_HP); + if( hp > 1 ) + *hp_power = CHAR_getInt( charaindex, CHAR_HP) * (skill_level*5 +10) /100; + else + *hp_power = 0; + + break; + } + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + { + *hp_power = skill_level*10+20; + break; + } + case BATTLE_COM_S_SIGN: // һѪ + { +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ){ + *hp_power = 200; + *mp_power = 30; + }else if( skill_level > 6 ){ + *hp_power = 150; + *mp_power = 20; + }else if( skill_level > 3 ){ + *hp_power = 100; + *mp_power = 15; + }else{ + *hp_power = 50; + *mp_power = 10; + } +#else + if( skill_level >= 10 ){ + *hp_power = 300; + *mp_power = 70; + }else if( skill_level >= 9 ){ + *hp_power = 200; + *mp_power = 50; + }else if( skill_level >= 7 ){ + *hp_power = 150; + *mp_power = 30; + }else if( skill_level >= 4 ){ + *hp_power = 100; + *mp_power = 20; + }else{ + *hp_power = 50; + *mp_power = 10; + } +#endif + break; + } + case BATTLE_COM_S_ENCLOSE: // + { +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ) + *hp_power = 400; + else if( skill_level > 9 ) + *hp_power = 300; + else if( skill_level > 7 ) + *hp_power = 250; + else if( skill_level > 4 ) + *hp_power = 200; + else + *hp_power = 150; + break; +#else + if( skill_level >= 10 ) + *hp_power = 300; + else if( skill_level >= 8 ) + *hp_power = 250; + else if( skill_level >= 5 ) + *hp_power = 200; + else + *hp_power = 150; + break; +#endif + } + default: + break; + } + +#ifdef _SUIT_ADDENDUM + *hp_power += *hp_power * (CHAR_getWorkInt( charaindex, CHAR_WORKMPOWER )/100.00); +#endif +#ifdef _SUIT_ADDPART4 + if( rand()%100 < 30 ) + *hp_power += *hp_power * (CHAR_getWorkInt( charaindex, CHAR_WORKMPOWER2 )/100.00);//ǿʦħװ(޶30%) +#endif + + if( *hp_power > 0 ){ + float rand_num = RAND( 98, 102 ); + *hp_power *= rand_num / 100; + }else{ + *hp_power = 0; + } +} + + +// ѡĻ +void PROFESSION_MAGIC_TOLIST_SORT( int *list, int *listidx, int charaindex ) +{ + int j=0, get_num=0, temp[SIDE_OFFSET * 2 + 1]; + int skill_level=-1, command=-1; + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1); + + switch(command){ + case BATTLE_COM_S_CURRENT: // + { +#ifdef _PROFESSION_ADDSKILL + if( skill_level > 9 ) get_num = 10; + else if( skill_level > 8 ) get_num = 9; + else if( skill_level > 7 ) get_num = 8; + else if( skill_level > 6 ) get_num = 7; + else if( skill_level > 5 ) get_num = 6; + else if( skill_level > 4 ) get_num = 5; + else if( skill_level > 3 ) get_num = 4; + else if( skill_level > 2 ) get_num = 3; + else if( skill_level > 1 ) get_num = 2; + else get_num = 1; +#else + if( skill_level >= 9 ) get_num = 5; + else if( skill_level >= 7 ) get_num = 4; + else if( skill_level >= 5 ) get_num = 3; + else if( skill_level >= 3 ) get_num = 2; + else get_num = 1; +#endif + break; + } + case BATTLE_COM_S_STORM: // + { + get_num = skill_level; + break; + } + case BATTLE_COM_S_DOOM: // ĩ + { + if( skill_level >= 8 ) get_num = 10; + else if( skill_level >= 7 ) get_num = 8; + else if( skill_level >= 5 ) get_num = 6; + else if( skill_level >= 3 ) get_num = 4; + else get_num = 2; + break; + } + case BATTLE_COM_S_FIRE_SPEAR: // ǹ + { + /*int miss_rate=0, rand_num=0; + + miss_rate = skill_level * 2 + 10; + rand_num = RAND(0, 100); + + if( rand_num <= miss_rate ){ + memset(list, -1, sizeof(list)); + *listidx = 0; + return; + }else + get_num = skill_level; + + break;*/ + /* + if( skill_level > 9 ) get_num = 10; + else if( skill_level > 8) get_num = 9; + else if( skill_level > 7 ) get_num = 8; + else if( skill_level > 6 ) get_num = 7; + else if( skill_level > 5 ) get_num = 6; + else if( skill_level > 4 ) get_num = 5; + else if( skill_level > 3 ) get_num = 4; + else if( skill_level > 2 ) get_num = 3; + else if( skill_level > 1 ) get_num = 2; + else get_num = 1; + */ + break; + } + case BATTLE_COM_S_SIGN: // һѪ + { +#ifdef _PROFESSION_ADDSKILL + get_num = 10; +#else + if( skill_level >= 10 ) get_num = 5; + else if( skill_level >= 8 ) get_num = 4; + else if( skill_level >= 6 ) get_num = 3; + else if( skill_level >= 3 ) get_num = 2; + else get_num = 1; +#endif + break; + } + case BATTLE_COM_S_CONVOLUTE: // + case BATTLE_COM_S_FIRE_BALL: // + { + int toNo=-1, toNo2=-1, battleindex=-1, i=0, count=0; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + if(battleindex == -1) return; + + toNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2); + memset( temp, -1, sizeof( temp ) ); + + if( toNo == 24 ) toNo2 = 15; + else if( toNo == 23 ) toNo2 = 10; + else if( toNo == 25 ) toNo2 = 5; + else if( toNo == 26 ) toNo2 = 0; + else return; + + for( i=0; i<5; i++ ){ + if(BATTLE_TargetCheck(battleindex,toNo2+i) != FALSE){ + temp[count] = toNo2+i; + count++; + } + } + + memset(list, -1, sizeof(list)); + memcpy( list, temp, sizeof(temp) ); + + *listidx = count; + + return; + } + case BATTLE_COM_S_THROUGH_ATTACK: // ᴩ + { + int toNo = -1, toNo2 = -1, battleindex = -1; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if(battleindex == -1) return; + + toNo = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM2); + memset( temp, -1, sizeof( temp ) ); + temp[0] = toNo; + + if( toNo < (SIDE_OFFSET/2) ) toNo2= toNo + (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET) ) toNo2= toNo - (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET*1.5) ) toNo2= toNo + (SIDE_OFFSET/2); + else if( toNo < (SIDE_OFFSET*2) ) toNo2= toNo - (SIDE_OFFSET/2); + + if(BATTLE_TargetCheck( battleindex, toNo2 ) != FALSE){ + if( toNo2 > toNo ){ + temp[0] = toNo2; + temp[1] = toNo; + }else + temp[1] = toNo2; + + *listidx = 2; + }else + *listidx = 1; + + memset(list, -1, sizeof(list)); + memcpy( list, temp, sizeof(temp) ); + + } + default: + return; + } + + if( get_num == 0 ) return; + + if( get_num >= 10) get_num=10; + + if( get_num >= *listidx ) return; + + memset(temp, -1, sizeof(temp)); + + while( j < get_num ){ + int rand_num=-1, out_num=-1; + + rand_num = RAND(0, *listidx-1); + out_num = list[rand_num]; + list[rand_num] = -1; + + if(out_num > 0){ + temp[j] = out_num; + j++; + } + } + + memset(list, -1, sizeof(list)); + memcpy( list, temp, sizeof(temp) ); + + *listidx = j; + + return; +} + + +// ı״̬ +void PROFESSION_MAGIC_CHANGE_STATUS( + int charaindex, + int hp_power, + float mp_power, + float *add_hp, + float *add_mp +) +{ + int skill_level=0, command=0, critical=0; + critical = RAND( 1,100); + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1); + + switch( command ){ + case BATTLE_COM_S_BLOOD: // Ѫ + { + int rate = 0; + + if( skill_level >= 10 ) rate = 20; + else if( skill_level >= 7 ) rate = 15; + else if( skill_level >= 5 ) rate = 10; + else if( skill_level >= 3 ) rate = 5; + else rate = 0; + + *add_mp += hp_power * ( rate + 40 ) / 100; + + break; + } + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + { + if( skill_level >= 10 ){ + *add_hp += hp_power * 0.2; + break; + }else{ + *add_hp += hp_power * ((skill_level/4)*5 + 5) / 100; + break; + } + break; + } +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_SIGN: // һѪ + { + int success=10; + /*( skill_level >= 10 ) success = 30;//ɹ + else if( skill_level > 9 ) success = 25; + else if( skill_level > 8 ) success = 20; + else if( skill_level > 7 ) success = 15; + else success = 10; + success = 30;*/ + if( RAND(0,100) < success ){ + if( skill_level > 8 ){ + *add_hp += hp_power; + *add_mp += mp_power; + } + else if( skill_level > 7 ){ + *add_hp += hp_power/2; + *add_mp += 0; + } + } + else + { + *add_hp += 0; + *add_mp += 0; + } + break; + } +#endif + default: + break; + } +} + +// ȡλòĶħͼż +void PROFESSION_MAGIC_GET_IMG2( int toNo, int charaindex, int attIdx, char *pszOption ) +{ + int command=0, img2=0, x=0, y=0; + char temp[64]; + int skill_level=0; + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + command = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLECOM1); + + switch( command ){ + case BATTLE_COM_S_BLOOD: // Ѫ + { + int img=0; + + if( skill_level >= 10 ) img = 101689; + else if( skill_level >= 7 ) img = 101690; + else if( skill_level >= 3 ) img = 101691; + else img = 101692; + + PROFESSION_MAGIC_CHANG_IMG2( img, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_VOLCANO_SPRINGS: // ɽȪ + { + int img=0; + + if( skill_level >= 10 ) img = 101686; + else if( skill_level >= 5 ) img = 101687; + else img = 101688; + + if( toNo >= 0 && toNo < 10 ) + PROFESSION_MAGIC_CHANG_IMG2( img, pszOption, attIdx ); + else{ + int x=0, y=0; + char temp[128]; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",11,temp,sizeof(temp)) ) x = atoi(temp); + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",12,temp,sizeof(temp)) ) y = atoi(temp); + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = img; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + } + + return; + } + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 || + ( toNo >= 0 && toNo < SIDE_OFFSET ) ) + PROFESSION_MAGIC_CHANG_IMG2( 101623, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_ICE_MIRROR: // + { + if( toNo >= 0 && toNo < 10 ) + PROFESSION_MAGIC_CHANG_IMG2( 101652, pszOption, attIdx ); + else{ + int x=0, y=0; + char temp[128]; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",11,temp,sizeof(temp)) ) x = atoi(temp); + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",12,temp,sizeof(temp)) ) y = atoi(temp); + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = 101652; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + } + + return; + } + case BATTLE_COM_S_ENCLOSE: // + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 || + ( toNo >= 0 && toNo < SIDE_OFFSET ) ) + PROFESSION_MAGIC_CHANG_IMG2( 101643, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_FIRE_SPEAR: // ǹ + { + // ҷ + //if( toNo == 20 || toNo == 25 || toNo == 26 ) + if( toNo < 10 ) + PROFESSION_MAGIC_CHANG_IMG2( 101642, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_DOOM: // ĩ + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 ) + PROFESSION_MAGIC_CHANG_IMG2( 101639, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_ICE_CRACK: // + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 ) + PROFESSION_MAGIC_CHANG_IMG2( 101650, pszOption, attIdx ); + return; + } + case BATTLE_COM_S_ICE_ARROW: // + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 || + ( toNo >= 0 && toNo < SIDE_OFFSET ) ) + PROFESSION_MAGIC_CHANG_IMG2( 101649, pszOption, attIdx ); + return; + + } + case BATTLE_COM_S_STORM: // + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 ) + PROFESSION_MAGIC_CHANG_IMG2( 101677, pszOption, attIdx ); + return; + } +#ifdef _PROFESSION_ADDSKILL + case BATTLE_COM_S_BOUNDARY: // Խ + { + // ҷ + if( toNo == 20 || toNo == 25 || toNo == 26 ){ + if( getStringFromIndexWithDelim(pszOption,"|",1,temp,sizeof(temp)) ) + { + if( strcmp( "ؽ", temp ) == 0 ) + PROFESSION_MAGIC_CHANG_IMG2( 101786, pszOption, attIdx ); + else if( strcmp( "ˮ", temp ) == 0 ) + PROFESSION_MAGIC_CHANG_IMG2( 101774, pszOption, attIdx ); + else if( strcmp( "", temp ) == 0 ) + PROFESSION_MAGIC_CHANG_IMG2( 101780, pszOption, attIdx ); + else if( strcmp( "", temp ) == 0 ) + PROFESSION_MAGIC_CHANG_IMG2( 101792, pszOption, attIdx ); + else + PROFESSION_MAGIC_CHANG_IMG2( 101770, pszOption, attIdx ); + } + } + return; + } +#endif + case BATTLE_COM_S_CONVOLUTE: // + { + img2=101656; + if( toNo == 25 ){ // 1 + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",9,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",10,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 26 ){ // 2 + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",11,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",12,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 23 ){ // 1 + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",13,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",14,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 24 ){ // 2 + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",15,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",16,temp,sizeof(temp)) ) y = atoi(temp); + }else + return; + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = img2; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + + break; + } + case BATTLE_COM_S_THROUGH_ATTACK: // ᴩ + { + if( (toNo == 13) || (toNo == 18) ){ // 1 + img2=101676; + x = 50; + y = 240; + }else if( (toNo == 11) || (toNo == 16) ){ // 2 + img2=101675; + x = 120; + y = 200; + }else if( (toNo == 10) || (toNo == 15) ){ // 3 + img2=101674; + x = 140; + y = 160; + }else if( (toNo == 12) || (toNo == 17) ){ // 4 + img2=101673; + x = 160; + y = 120; + }else if( (toNo == 14) || (toNo == 19) ){ // 5 + img2=101672; + x = 180; + y = 80; + }else if( (toNo == 3) || (toNo == 8) ){ // 1 + img2=101665; + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",9,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",10,temp,sizeof(temp)) ) y = atoi(temp); + }else if( (toNo == 1) || (toNo == 6) ){ // 2 + img2=101664; + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",11,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",12,temp,sizeof(temp)) ) y = atoi(temp); + }else if( (toNo == 0) || (toNo == 5) ){ // 3 + img2=101663; + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",13,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",14,temp,sizeof(temp)) ) y = atoi(temp); + }else if( (toNo == 2) || (toNo == 7) ){ // 4 + img2=101662; + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",15,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",16,temp,sizeof(temp)) ) y = atoi(temp); + }else if( (toNo == 4) || (toNo == 9) ){ // 5 + img2=101661; + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",17,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",18,temp,sizeof(temp)) ) y = atoi(temp); + }else + return; + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = img2; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + + // ǰö + if( toNo >= 10 ){ + int img1 = 101671; + PROFESSION_magic[attIdx].uiPrevMagicNum = img1; + } + break; + } + case BATTLE_COM_S_FIRE_BALL: // + { + if( toNo == 25 ){ // 1 + img2=101694; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",9,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",10,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 26 ){ // 2 + img2=101694; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",11,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",12,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 23 ){ // 1 + img2=101693; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",13,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",14,temp,sizeof(temp)) ) y = atoi(temp); + }else if( toNo == 24 ){ // 2 + img2=101693; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",15,temp,sizeof(temp)) ) x = atoi(temp); + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",16,temp,sizeof(temp)) ) y = atoi(temp); + }else + return; + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = img2; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; + + break; + } + default: return; + } + +} + + +#define D_16 (1.0/16) +#define D_8 (1.0/8) +// ȡù˺ +#ifdef _PROFESSION_ADDSKILL +int PROFESSION_MAGIC_GET_DAMAGE( int attackindex, int defindex, int magic_type, int power, int command ) +#else +int PROFESSION_MAGIC_GET_DAMAGE( int attackindex, int defindex, int magic_type, int power ) +#endif +{ + int damage = 0; + +#ifdef _FIX_MAGIC_RESIST // WON ADD ħ + int proficiency=0;// + int resist=0;// + int suit=0;//װ + int spirit=0;//ʹþɵĿ + + if( command == BATTLE_COM_S_DOOM ) + magic_type = 1; + + if( magic_type == 1){ // + proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_F_PROFICIENCY); // + resist = CHAR_getWorkInt( defindex, CHAR_WORK_F_RESIST); // +#ifdef _EQUIT_RESIST + suit = CHAR_getWorkInt( defindex, CHAR_WORK_F_SUIT)+CHAR_getWorkInt( defindex, CHAR_WORKEQUITFIRE ); +#else + suit = CHAR_getWorkInt( defindex, CHAR_WORK_F_SUIT); +#endif +#ifdef _MAGICSTAUTS_RESIST + if( CHAR_getWorkInt( defindex, CHAR_MAGICFIRE) > 0 ) + spirit = CHAR_getWorkInt( defindex, CHAR_OTHERSTATUSNUMS ); +#endif + } + + if( command == BATTLE_COM_S_DOOM ){ + damage = power * (1+proficiency/100.0) * (1-(resist/100.0)) * (1-(suit/100.0)) * (1-(spirit/100.0)); + magic_type = 2; + } + + if( magic_type == 2){ // + proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_T_PROFICIENCY); // + resist = CHAR_getWorkInt( defindex, CHAR_WORK_T_RESIST); // 翹 +#ifdef _EQUIT_RESIST + suit = CHAR_getWorkInt( defindex, CHAR_WORK_I_SUIT)+CHAR_getWorkInt( defindex, CHAR_WORKEQUITTHUNDER ); +#else + suit = CHAR_getWorkInt( defindex, CHAR_WORK_I_SUIT); +#endif +#ifdef _MAGICSTAUTS_RESIST + if( CHAR_getWorkInt( defindex, CHAR_MAGICTHUNDER) > 0 ) + spirit = CHAR_getWorkInt( defindex, CHAR_OTHERSTATUSNUMS ); +#endif + } + + if( command == BATTLE_COM_S_DOOM ){ + damage += power * (1+proficiency/100.0) * (1-(resist/100.0)) * (1-(suit/100.0)) * (1-(spirit/100.0)); + magic_type = 3; + } + + if( magic_type == 3){ // + proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_I_PROFICIENCY); // + resist = CHAR_getWorkInt( defindex, CHAR_WORK_I_RESIST); // +#ifdef _EQUIT_RESIST + suit = CHAR_getWorkInt( defindex, CHAR_WORK_T_SUIT)+CHAR_getWorkInt( defindex, CHAR_WORKEQUITICE ); +#else + suit = CHAR_getWorkInt( defindex, CHAR_WORK_T_SUIT); +#endif +#ifdef _MAGICSTAUTS_RESIST + if( CHAR_getWorkInt( defindex, CHAR_MAGICICE) > 0 ) + spirit = CHAR_getWorkInt( defindex, CHAR_OTHERSTATUSNUMS ); +#endif + } + + if( command == BATTLE_COM_S_DOOM ){ + damage += power * (1+proficiency/100.0) * (1-(resist/100.0)) * (1-(suit/100.0)) * (1-(spirit/100.0)); + damage /= 3.0; + } + else + damage = power * (1+proficiency/100.0) * (1-(resist/100.0)) * (1-(suit/100.0)) * (1-(spirit/100.0)); + +#else //_FIX_MAGIC_RESIST + + fire_proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_F_PROFICIENCY); // + electric_proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_T_PROFICIENCY); // + ice_proficiency = CHAR_getWorkInt( attackindex, CHAR_WORK_I_PROFICIENCY); // + fire_resist = CHAR_getWorkInt( defindex, CHAR_WORK_F_RESIST); // + electric_resist = CHAR_getWorkInt( defindex, CHAR_WORK_T_RESIST); // 翹 + ice_resist = CHAR_getWorkInt( defindex, CHAR_WORK_I_RESIST); // + +// print("\n won test 0.0 ==> f(%d) e(%d) i(%d)", fire_proficiency, electric_proficiency, ice_proficiency ); +// print("\n won test 0.1 ==> f(%d) e(%d) i(%d)", fire_resist, electric_resist, ice_resist ); + + if( magic_type == 1){ // + + attack = power * ( 100 + fire_proficiency ) / 100; // ӳ + + if( rand_num < 40){ // ԭ˺ + attack = attack * ( 100 - fire_resist ) / 100; + }else{ // ȡ˺ + rand_num = RAND(-20, 20); + attack = attack * ( 100 - (rand_num + fire_resist) ) / 100; + } +//print( "\nattack:%d ", attack ); + + }else + if( magic_type == 2){ // + + attack = power * ( 100 + electric_proficiency ) / 100; // ӳ + + if( rand_num < 40){ // ԭ˺ + attack = attack * ( 100 - electric_resist ) / 100; + }else{ // ȡ˺ + rand_num = RAND(-20, 20); + attack = attack * ( 100 - (rand_num + electric_resist) ) / 100; + } + }else + if( magic_type == 3){ // + + attack = power * ( 100 + ice_proficiency ) / 100; // ӳ + + if( rand_num < 40){ // ԭ˺ + attack = attack * ( 100 - ice_resist ) / 100; + }else{ // ȡ˺ + rand_num = RAND(-20, 20); + attack = attack * ( 100 - (rand_num + ice_resist) ) / 100; + } + }else{ // + attack = power; + } + + damage = attack; + +#endif + + if( damage < 0 ) + damage = 0; + + return damage; +} + + +// ȡ⹥˺ +int PROFESSION_MAGIC_GET_ICE_MIRROR_DAMAGE( int attackindex, int defindex, int command, int power ) +{ + int damage = power; + + if( command == BATTLE_COM_S_ICE_MIRROR ){ // + float defense = -1; + int rate=0; + int defpet = BATTLE_getRidePet( defindex ); + int skill_level = CHAR_GETWORKINT_HIGH( attackindex, CHAR_WORKBATTLECOM3); + int base_defense = CHAR_getInt( defindex, CHAR_TOUGH ) / 100; + + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( defpet == -1 ) + defense = CHAR_getWorkInt( defindex, CHAR_WORKDEFENCEPOWER ); + else + defense = BATTLE_adjustRidePet3A( defindex, defpet, CHAR_WORKDEFENCEPOWER, DEFFENCESIDE ); + + if( skill_level >= 10 ){ + rate = 60; + }else{ + rate = skill_level * 5 + 5; + } + + //andy_Edit + damage = 120 + (int)( ( defense * rate / 100 ) + ( ( defense - base_defense ) * rate / 200 ) ); + //ƶnpc˺ + if( CHAR_getInt( defindex , CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ) + damage = damage > 800 ? 800 : damage; + + }else + if( command == BATTLE_COM_S_CONVOLUTE ){ // + int skill_level = CHAR_GETWORKINT_HIGH( attackindex, CHAR_WORKBATTLECOM3); + int hit=0; + + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + hit = skill_level * 2 + 60; + + //if( rand_num <= hit ){ + // ȡû˺ + damage = BATTLE_PROFESSION_CONVOLUTE_GET_DAMAGE( attackindex, defindex, skill_level ); + //}else{ + // damage = 0; + //} + }else + if( command == BATTLE_COM_S_THROUGH_ATTACK ){ // ᴩ + int skill_level = CHAR_GETWORKINT_HIGH( attackindex, CHAR_WORKBATTLECOM3); + + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + if( skill_level != 10 ){ + // ½ + CHAR_setWorkInt( attackindex, CHAR_MYSKILLHIT, 1); + CHAR_setWorkInt( attackindex, CHAR_MYSKILLHIT_NUM, -70); + CHAR_setWorkInt( attackindex, CHAR_WORKHITRIGHT, CHAR_getWorkInt(attackindex,CHAR_WORKHITRIGHT) -50 ); + } + + // ȡùᴩ˺ + damage = BATTLE_PROFESSION_THROUGH_ATTACK_GET_DAMAGE( attackindex, defindex ); + } +#ifdef _PROFESSION_ADDSKILL + else + if( command == BATTLE_COM_S_CURRENT // + || command == BATTLE_COM_S_SUMMON_THUNDER ){// + if( CHAR_getWorkInt( defindex, CHAR_WORKWATER ) > 0 ){//ˮ + if( RAND(1, 100) < 75 ) + damage *= 3; + } + } +#endif + return damage; +} + + + +// +// return: 0:û 1: +int PROFESSION_MAGIC_DODGE( int atk_index, int def_index, int magic_type ) +{ + float fLuck = 0,fResist = 0, proficiency = 0; + float Dluck=0.0; + int charType = CHAR_getInt( def_index, CHAR_WHICHTYPE); + int rand_num = RAND( 1, 100 ); + int command; + + + // Ŀһܣ + if( CHAR_getWorkInt( def_index, CHAR_WORKBATTLECOM1 ) == BATTLE_COM_S_EARTHROUND0 ){ + return 1; // Miss + } + + // Ƿ + if( charType == CHAR_TYPEPLAYER ){ + + // + fLuck = (float)CHAR_getInt( def_index, CHAR_LUCK) * 3; + // + if( magic_type != 0 ){ + fResist = (float)(CHAR_getWorkInt( def_index, CHAR_WORK_F_RESIST + magic_type - 1 )) * 0.5; + } + fLuck += fResist; + // ħװ + Dluck = (float)(CHAR_getWorkInt( def_index, CHAR_EQUITQUIMAGIC)*0.4); + fLuck += Dluck; + }else {// Ƿdz + fLuck = (float)CHAR_getInt( def_index, CHAR_LV) * 0.15; + if(fLuck > 20) fLuck = 20; + } + + // + // Robin fix + //if( magic_type != 0 ){ + if( magic_type > 0 ){ + proficiency = (float)CHAR_getWorkInt( atk_index, (CHAR_WORK_F_PROFICIENCY + magic_type - 1) ) * 0.2; + + fLuck -= proficiency; + } + +/* print("\n PROFESSION_MAGIC_DODGE atk=%s def=%s magic_type(%d)", + CHAR_getChar( atk_index, CHAR_NAME), + CHAR_getChar( def_index, CHAR_NAME), + magic_type ); + print("\n won test 4 ==> rand_num(%d) lucky(%d) fResist(%f) Dluck(%f) proficiency(%f) fLuck(%f)", + rand_num, + CHAR_getInt( def_index, CHAR_LUCK) * 3, + fResist, + Dluck, + proficiency, + fLuck ); +*/ + + if( rand_num > (int)fLuck){ +#ifdef _PROFESSION_ADDSKILL + command = CHAR_getWorkInt( atk_index, CHAR_WORKBATTLECOM1); + switch( command ){ + case BATTLE_COM_S_CURRENT: + case BATTLE_COM_S_STORM: + if( RAND( 1, 100 ) < 75 ) + return 0; + else + return 1; + break; + case BATTLE_COM_S_FIRE_SPEAR: + case BATTLE_COM_S_DOOM: + if( RAND( 1, 100 ) < 90 ) + return 0; + else + return 1; + break; + case BATTLE_COM_S_SIGN: + if( RAND( 1, 100 ) < 50 ) + return 0; + else + return 1; + break; + } +#endif + return 0; // hit + } + else + return 1; // Miss +} + +void PROFESSION_MAGIC_CHANG_IMG2( int img2, char *pszOption, int attIdx ) +{ + int x=0, y=0; + char temp[128]; + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",9,temp,sizeof(temp)) ) x = atoi(temp); + + memset( temp, 0, sizeof(temp) ); + if( getStringFromIndexWithDelim(pszOption,"|",10,temp,sizeof(temp)) ) y = atoi(temp); + + // ö + PROFESSION_magic[attIdx].uiSpriteNum = img2; + + // ö + PROFESSION_magic[attIdx].siSx = x; + PROFESSION_magic[attIdx].siSy = y; +} + + + +int PROFESSION_MAGIC_CHANG_STATUS(int command,int battleindex, int charaindex, int charaidx, int attvalue, int no ) +{ + int i,j; + int skill_level=0; + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + switch( command ){ + case BATTLE_COM_S_THROUGH_ATTACK: // ᴩ + { + int skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + + if( no == 0 ){ // ǰŵ + attvalue = attvalue * (skill_level * 2 + 70) / 100; + }else if( no == 1 ){ // ŵ + attvalue = attvalue * (skill_level * 2 + 50) / 100; + } + + break; + } + case BATTLE_COM_S_ICE_CRACK: // + { + int hit=0, rand_num = RAND( 0, 100 ); + + //for( j = 1; j < BATTLE_ST_END; j++ ){ //쳣״̬return + // if( CHAR_getWorkInt( charaidx, StatusTbl[j] ) > 0 ) return 0; + //} + // + if( skill_level >= 10 ) hit = 80; + else if( skill_level >= 7 ) hit = 70; + else if( skill_level >= 5 ) hit = 80; + else if( skill_level >= 3 ) hit = 90; + else hit = 100; + + hit = 100; + if( rand_num < hit ){ + int damage=0; + + if( skill_level >= 10 ) damage = attvalue * 1.3; + else if( skill_level >= 7 ) damage = attvalue * 1.25; + else if( skill_level >= 4 ) damage = attvalue * 1.2; + else damage = attvalue * 1.1; + + if( damage <= 0 ) break; + + for( i=0; i<10; i++ ){ + if( CHAR_getWorkInt( charaidx, CHAR_WORKICECRACK+i ) <= 0 ){ + CHAR_setWorkInt( charaidx, CHAR_WORKICECRACK+i, 3 ); + CHAR_setWorkInt( charaidx, CHAR_WORKMODICECRACK+i, damage ); + print("\niceidx:%d",charaidx); + break; + } + } + //BATTLE_BadStatusString( bid, BATTLE_ST_ICECRACK ); + + } + + // һ˺ + attvalue = 0; + + break; + } + case BATTLE_COM_S_ENCLOSE: // + { + for( j = 1; j < BATTLE_ST_END; j++ ) //쳣״̬return + if( CHAR_getWorkInt( charaidx, StatusTbl[j] ) > 0 ) return attvalue; + + { + int success=0, rand_num=0, round=1; + int bid = BATTLE_Index2No( battleindex, charaidx ); + + skill_level = CHAR_GETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3); + + if( skill_level >= 100 ) success = 50; + else if( skill_level > 90 ) success = 40; + else if( skill_level > 80 ) success = 30; + else if( skill_level > 60 ) success = 25; + else if( skill_level > 30 ) success = 20; + else success = 10; + + if( skill_level > 80 ) round = 3; + else if( skill_level > 50 ) round = 2; + else round = 1; + + rand_num = RAND(0,100); + + if( rand_num <= success ){ //ɹʱĿ +#ifdef _PROFESSION_ADDSKILL + CHAR_setWorkInt( charaidx, CHAR_WORKANNEX, round ); +#else + CHAR_setWorkInt( charaidx, CHAR_WORKCONFUSION, 4 ); + CHAR_setWorkInt( charaidx, CHAR_WORKMODCONFUSION, 100 ); +#endif + BATTLE_BadStatusString( bid, BATTLE_ST_CONFUSION ); + } + } + break; + } + case BATTLE_COM_S_ICE_ARROW: // + { + for( j = 1; j < BATTLE_ST_END; j++ ){ //쳣״̬return + if( CHAR_getWorkInt( charaidx, StatusTbl[j] ) > 0 ) return attvalue; + } + { + int success=0, rand_num=0; + int bid = BATTLE_Index2No( battleindex, charaidx ); + + if( skill_level >= 8 ) success = 25; + else if( skill_level >= 5 ) success = 20; + else if( skill_level >= 2 ) success = 15; + else success = 10; + rand_num = RAND(0,100); + + if( rand_num <= success ){ //ɹʱĿ꽵 + int dec_dex=0, turn=0; + + if( skill_level >= 8 ) dec_dex = 25; + else if( skill_level >= 5 ) dec_dex = 20; + else dec_dex = 10; + + if( skill_level >= 10 ) turn = 3; + else if( skill_level >= 6 ) turn = 2; + else turn = 1; + + CHAR_setWorkInt( charaidx, CHAR_WORKICEARROW, turn + 1 ); + CHAR_setWorkInt( charaidx, CHAR_WORKMODICEARROW, dec_dex ); + + BATTLE_BadStatusString( bid, BATTLE_ST_ICEARROW ); + } + } + break; + } + case BATTLE_COM_S_BLOOD_WORMS: // Ѫ + { + for( j = 1; j < BATTLE_ST_END; j++ ){ //쳣״̬return + if( CHAR_getWorkInt( charaidx, StatusTbl[j] ) > 0 ) return attvalue; + } + { + int turn=0; + int bid = BATTLE_Index2No( battleindex, charaidx ); + + if( skill_level >= 10 ) turn = 5; + else if( skill_level >= 8 ) turn = 4; + else if( skill_level >= 5 ) turn = 3; + else turn = 2; + + CHAR_setWorkInt( charaidx, CHAR_WORKBLOODWORMS, turn + 1 ); + CHAR_setWorkInt( charaidx, CHAR_WORKMODBLOODWORMS, skill_level ); + CHAR_setWorkInt( charaidx, CHAR_WORKBLOODWORMSID, charaindex ); + + BATTLE_BadStatusString( bid, BATTLE_ST_BLOODWORMS ); + + } + break; + } + case BATTLE_COM_S_SIGN: // һѪ + { +#ifdef _PROFESSION_ADDSKILL +#else + for( j = 1; j < BATTLE_ST_END; j++ ){ //쳣״̬return + if( CHAR_getWorkInt( charaidx, StatusTbl[j] ) > 0 ) return attvalue; + } + { + int turn=0, success=0, rand_num=0; + int bid = BATTLE_Index2No( battleindex, charaidx ); + + // 뿪 +// if( CHAR_getInt( charaidx, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) return attvalue; + + if( skill_level == 10 ) success = 35; + else if( skill_level >= 8 ) success = (skill_level - 3) * 5; + else if( skill_level >= 6 ) success = 20; + else if( skill_level >= 4 ) success = 15; + else if( skill_level >= 2 ) success = 10; + else success = 5; + + rand_num = RAND(0,100); + + if( rand_num <= success ){ //ɹʱĿѪ + if( skill_level >= 10 ) turn = 5; + else if( skill_level >= 7 ) turn = 4; + else if( skill_level >= 4 ) turn = 3; + else turn = 2; + + CHAR_setWorkInt( charaidx, CHAR_WORKSIGN, turn + 1 ); + CHAR_setWorkInt( charaidx, CHAR_WORKMODSIGN, skill_level ); + CHAR_setWorkInt( charaidx, CHAR_WORKSIGNID, charaindex ); + + BATTLE_BadStatusString( bid, BATTLE_ST_SIGN ); + } + } +#endif + break; + } + case BATTLE_COM_S_DOOM: // ĩ + { +/* int rand_num = RAND( 1, 100 ), work, dex; + char szCommand[64]; + int bid = BATTLE_Index2No( battleindex, charaidx ); + + if( skill_level < 10 ) break; +#ifdef _PROFESSION_ADDSKILL + CHAR_setWorkInt( charaidx, CHAR_WORKFEAR, 2 ); + BATTLE_BadStatusString( bid, BATTLE_ST_FEAR ); + work = CHAR_getWorkInt( charaindex, CHAR_WORKQUICK )+20; + dex = work>>1;//50% + sprintf( szCommand, "BD|r%X|0|6|%X|", bid, (-1) * dex ); + BATTLESTR_ADD( szCommand ); +#endif + // + if( rand_num <= 20 ){ + CHAR_setWorkInt( charaidx, CHAR_WORKPARALYSIS, 3 ); + BATTLE_BadStatusString( bid, BATTLE_ST_PARALYSIS ); + }else{ + rand_num = RAND( 1, 100 ); + if( rand_num <= 10 ){ + CHAR_setWorkInt( charaidx, CHAR_WORKCONFUSION, 3 ); + BATTLE_BadStatusString( bid, BATTLE_ST_CONFUSION ); + } + }*/ + + break; + } + } + + + return attvalue; +} + + +#endif + + +#ifdef _PETSKILL_FIREKILL +/* + . ... ... . + *. .. .* . . + . . .. + .. /\_/\_ . + ??̡ ̡??? + ڿ +*/ +void BATTLE_MultiAttMagic_Fire( int battleindex, int attackNo, int defNo, + int FieldAttr , int Power) + +{ + int list[SIDE_OFFSET * 2 + 1]; + int listidx=0,i,j,z,def_be_hit[10],att_magic_lv[4]; + int def_magic_resist[DEF_MAGIC_NUM]; + int attvalue , charahp , pethp , charaidx , petidx , charahurt,pet_att_lv = 1,pet_def_lv = 1,charahurt_temp; + char szcommand[256]; + int AttIsPlayer=0,DefIsPlayer=0; + int getexp = 0; + +#ifndef _FIX_MAGICDAMAGE + int att_magic_exp_add,att_magic_exp_sub,def_magic_exp_add,def_magic_exp_sub; + int lv_up_exp,DefFieldAttr = 0; + float temp = 0.0f; +// int attattr[5], defattr[5]; + char msgbuf[64]; + char kind[4][3] = {"","ˮ","",""}; +#else + BOOL TrueMagic=FALSE; +#endif + int f_num=0; + int MagicLv=4; + + memset(def_be_hit,-1,sizeof(def_be_hit)); + + if(defNo < 5) + f_num = 0; + else if(defNo >=5 && defNo < 10) + f_num = 5; + else if(defNo >=10 && defNo < 15) + f_num = 10; + else + f_num = 15; + + // ȡսϴ + for( i=f_num; i att_magic_lv[ FieldAttr] ) TrueMagic = FALSE; + else TrueMagic = TRUE; +#endif + } + pet_att_lv = CHAR_getInt(BATTLE_No2Index(battleindex,attackNo), CHAR_LV); + + z = 0; + for(i=0;i 0 ){ + float def = (float)(CHAR_getWorkInt( charaidx, CHAR_OTHERSTATUSNUMS )); + def = def/100; + for(j=0;j 0) { + CHAR_setWorkInt(def_be_hit[i],CHAR_WORKSLEEP,0); + z = BATTLE_Index2No(battleindex,def_be_hit[i]); + sprintf(szcommand,"BM|%X|%X|",z,0); + BATTLESTR_ADD(szcommand); + } + } +} +#endif + +#ifdef _PROFESSION_ADDSKILL +unsigned int GET_PROFESSION_magic_array(int idx) +{ + return PROFESSION_magic[idx].uiSpriteNum; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile new file mode 100644 index 0000000..97c9688 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile @@ -0,0 +1,464 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libbattle.a + +SRC=battle.c battle_event.c battle_command.c battle_ai.c battle_magic.c pet_skill.c battle_item.c profession_skill.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +battle.o: battle.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/battle.h \ + ../include/trade.h ../include/battle_event.h \ + ../include/battle_command.h ../include/battle_ai.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/encount.h ../include/enemy.h \ + ../include/handletime.h ../include/readmap.h ../include/pet_skill.h \ + ../include/npcutil.h ../include/magic.h ../include/npc_npcenemy.h \ + ../include/log.h ../include/pet_skillinfo.h ../include/anim_tbl.h \ + ../include/common.h ../include/battle_magic.h ../include/item.h \ + ../include/trade.h ../include/npc_autopk.h ../include/npc_healer.h \ + ../include/profession_skill.h ../include/skill.h \ + ../include/mylua/function.h ../include/mylua/mylua.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h +battle_event.o: battle_event.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_event.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/configfile.h ../include/pet.h \ + ../include/log.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/anim_tbl.h ../include/battle_magic.h \ + ../include/util.h ../include/enemy.h ../include/pet_skill.h \ + ../include/char_base.h ../include/item_event.h ../include/autil.h \ + ../include/profession_skill.h ../include/item.h ../include/skill.h \ + ../include/magic_base.h ../include/mylua/function.h +battle_command.o: battle_command.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/pet_skill.h ../include/battle_event.h \ + ../include/battle_command.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/magic.h ../include/magic_base.h \ + ../include/handletime.h ../include/configfile.h \ + ../include/profession_skill.h +battle_ai.o: battle_ai.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/npcutil.h ../include/pet_skill.h +battle_magic.o: battle_magic.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/magic_base.h \ + ../include/battle_magic.h ../include/item_event.h ../include/anim_tbl.h \ + ../include/common.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/profession_skill.h ../include/skill.h +pet_skill.o: pet_skill.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/buf.h ../include/configfile.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/pet_skill.h \ + ../include/battle.h ../include/trade.h ../include/battle_event.h \ + ../include/battle_magic.h ../include/item.h ../include/item_gen.h \ + ../include/char_talk.h ../include/autil.h +battle_item.o: battle_item.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/battle_item.h \ + ../include/battle_magic.h ../include/item_event.h ../include/log.h \ + ../include/anim_tbl.h ../include/npcutil.h ../include/magic_base.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/magic.h +profession_skill.o: profession_skill.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/buf.h ../include/profession_skill.h \ + ../include/version.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/skill.h ../include/char_base.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/battle.h ../include/trade.h ../include/magic_base.h \ + ../include/configfile.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/skill.h ../include/autil.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile.bak new file mode 100644 index 0000000..97c9688 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/makefile.bak @@ -0,0 +1,464 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libbattle.a + +SRC=battle.c battle_event.c battle_command.c battle_ai.c battle_magic.c pet_skill.c battle_item.c profession_skill.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +battle.o: battle.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/battle.h \ + ../include/trade.h ../include/battle_event.h \ + ../include/battle_command.h ../include/battle_ai.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/encount.h ../include/enemy.h \ + ../include/handletime.h ../include/readmap.h ../include/pet_skill.h \ + ../include/npcutil.h ../include/magic.h ../include/npc_npcenemy.h \ + ../include/log.h ../include/pet_skillinfo.h ../include/anim_tbl.h \ + ../include/common.h ../include/battle_magic.h ../include/item.h \ + ../include/trade.h ../include/npc_autopk.h ../include/npc_healer.h \ + ../include/profession_skill.h ../include/skill.h \ + ../include/mylua/function.h ../include/mylua/mylua.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h +battle_event.o: battle_event.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_event.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/configfile.h ../include/pet.h \ + ../include/log.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/anim_tbl.h ../include/battle_magic.h \ + ../include/util.h ../include/enemy.h ../include/pet_skill.h \ + ../include/char_base.h ../include/item_event.h ../include/autil.h \ + ../include/profession_skill.h ../include/item.h ../include/skill.h \ + ../include/magic_base.h ../include/mylua/function.h +battle_command.o: battle_command.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/pet_skill.h ../include/battle_event.h \ + ../include/battle_command.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/magic.h ../include/magic_base.h \ + ../include/handletime.h ../include/configfile.h \ + ../include/profession_skill.h +battle_ai.o: battle_ai.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/npcutil.h ../include/pet_skill.h +battle_magic.o: battle_magic.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/magic_base.h \ + ../include/battle_magic.h ../include/item_event.h ../include/anim_tbl.h \ + ../include/common.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/profession_skill.h ../include/skill.h +pet_skill.o: pet_skill.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/buf.h ../include/configfile.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/pet_skill.h \ + ../include/battle.h ../include/trade.h ../include/battle_event.h \ + ../include/battle_magic.h ../include/item.h ../include/item_gen.h \ + ../include/char_talk.h ../include/autil.h +battle_item.o: battle_item.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/battle_event.h ../include/battle_item.h \ + ../include/battle_magic.h ../include/item_event.h ../include/log.h \ + ../include/anim_tbl.h ../include/npcutil.h ../include/magic_base.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/magic.h +profession_skill.o: profession_skill.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/buf.h ../include/profession_skill.h \ + ../include/version.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/skill.h ../include/char_base.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/battle.h ../include/trade.h ../include/magic_base.h \ + ../include/configfile.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/skill.h ../include/autil.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/battle/pet_skill.c b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/pet_skill.c new file mode 100644 index 0000000..4725ba6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/battle/pet_skill.c @@ -0,0 +1,2911 @@ +#include "version.h" +#include +#include +#include "common.h" +#include "buf.h" +#include "configfile.h" +#include "char_base.h" +#include "char_data.h" +#include "pet_skill.h" +#include "battle.h" +#include "battle_event.h" +#include "battle_magic.h" +#include "item.h" +#include "item_gen.h" +#include "char_talk.h" +#include "autil.h" + +/*======================================================================== + * ʸ 年лĩ ĸʽ + *========================================================================*/ + +static Petskill *PETSKILL_petskill; +static int PETSKILL_petskillnum; + +typedef struct tagPetskill_PetskillFunctionTable +{ + char *functionname; /* ɬð̻̤Ѽ */ + PETSKILL_CALLFUNC func; /* ˱̫ľ */ + int hash; /* hash */ + int status; /* Ѩëʸ϶ִ */ +}PETSKILL_PetskillFunctionTable; + +/* ë ֧ճ */ +static PETSKILL_PetskillFunctionTable PETSKILL_functbl[] = { + { "PETSKILL_None", PETSKILL_None, 0 }, + { "PETSKILL_NormalAttack", PETSKILL_NormalAttack, 0 }, + { "PETSKILL_NormalGuard", PETSKILL_NormalGuard, 0 }, + { "PETSKILL_ContinuationAttack",PETSKILL_ContinuationAttack, 0 }, + { "PETSKILL_ChargeAttack", PETSKILL_ChargeAttack, 0 }, + { "PETSKILL_Guardian", PETSKILL_Guardian, 0 }, + { "PETSKILL_PowerBalance", PETSKILL_PowerBalance, 0 }, + { "PETSKILL_Mighty", PETSKILL_Mighty, 0 }, + { "PETSKILL_StatusChange", PETSKILL_StatusChange, 0 }, + { "PETSKILL_EarthRound", PETSKILL_EarthRound, 0 }, + { "PETSKILL_GuardBreak", PETSKILL_GuardBreak, 0 }, +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 + { "PETSKILL_GuardBreak2", PETSKILL_GuardBreak2, 0 }, +#endif + { "PETSKILL_Abduct", PETSKILL_Abduct, 0 }, + { "PETSKILL_Steal", PETSKILL_Steal, 0 }, + { "PETSKILL_Merge", PETSKILL_Merge, 0 }, +#ifdef _ALCHEMIST + { "PETSKILL_Alchemist", PETSKILL_Merge, 0 }, +#endif + { "PETSKILL_NoGuard", PETSKILL_NoGuard, 0 }, +#ifdef _ITEM_INSLAY + { "PETSKILL_Inslay", PETSKILL_Inslay, 0 }, +#endif +#ifdef _PETSKILL_FIXITEM + { "PETSKILL_Fixitem", PETSKILL_Fixitem, 0 }, +#endif + +#ifdef _MAGIC_SUPERWALL + { "PETSKILL_MagicStatusChange" , PETSKILL_MagicStatusChange, 0}, +#endif + +// Terry add 2001/11/05 +#ifdef _ATTACK_MAGIC + { "PETSKILL_AttackMagic", PETSKILL_AttackMagic,0}, +#endif + +#ifdef _PSKILL_FALLGROUND + { "PETSKILL_FallGround", PETSKILL_FallGround, 0}, +#endif +#ifdef _PETSKILL_EXPLODE + { "PETSKILL_Explode", PETSKILL_Explode, 0}, +#endif +#ifdef _BATTLESTEAL_FIX + { "PETSKILL_StealMoney", PETSKILL_StealMoney, 0 }, +#endif +#ifdef _PRO_BATTLEENEMYSKILL + { "ENEMYSKILL_ReLife", ENEMYSKILL_ReLife, 0}, + { "ENEMYSKILL_ReHP", ENEMYSKILL_ReHP, 0}, + { "ENEMYSKILL_EnemyHelp", ENEMYSKILL_EnemyHelp, 0}, +#endif +#ifdef _SKILL_DAMAGETOHP + { "PETSKILL_DamageToHp", PETSKILL_DamageToHp, 0}, +#endif + +#ifdef _PETSKILL_TIMID + { "PETSKILL_BattleTimid", PETSKILL_BattleTimid, 0}, +#endif +#ifdef _PETSKILL_2TIMID + { "PETSKILL_2BattleTimid", PETSKILL_2BattleTimid, 0}, +#endif +#ifdef _PETSKILL_ANTINTER + { "PETSKILL_AntInter", PETSKILL_AntInter, 0}, +#endif + +#ifdef _PETSKILL_PROPERTY + { "PETSKILL_BattleProperty", PETSKILL_BattleProperty, 0}, +#endif + +#ifdef _PETSKILL_TEAR + { "PETSKILL_BattleTearDamage", PETSKILL_BattleTearDamage, 0}, +#endif + +#ifdef _BATTLE_LIGHTTAKE + { "PETSKILL_Lighttakeed", PETSKILL_Lighttakeed, 0}, +#endif + +#ifdef _BATTLE_ATTCRAZED + { "PETSKILL_AttackCrazed", PETSKILL_AttackCrazed, 0}, +#endif + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + { "PETSKILL_AttackShoot", PETSKILL_AttackShoot, 0}, +#endif + +#ifdef _Skill_MPDAMAGE + { "PETSKILL_MpDamage", PETSKILL_MpDamage, 0}, +#endif + +#ifdef _SKILL_TOOTH + { "PETSKILL_ToothCrushe", PETSKILL_ToothCrushe, 0}, +#endif + +#ifdef _PETSKILL_SETDUCK + { "PETSKILL_SetDuck", PETSKILL_SetDuck, 0}, +#endif +#ifdef _MAGICPET_SKILL + { "PETSKILL_SetMagicPet", PETSKILL_SetMagicPet, 0}, +#endif +#ifdef _PSKILL_MODIFY + { "PETSKILL_Modifyattack", PETSKILL_Modifyattack, 0}, +#endif + +#ifdef _PSKILL_MDFYATTACK + { "PETSKILL_Mdfyattack", PETSKILL_Mdfyattack, 0}, +#endif +#ifdef _VARY_WOLF + { "PETSKILL_Vary", PETSKILL_Vary, 0}, +#endif +#ifdef _SKILL_WILDVIOLENT_ATT + { "PETSKILL_WildViolentAttack", PETSKILL_WildViolentAttack, 0},//vincent add 2002/05/16 +#endif + +#ifdef _SKILL_SPEEDY_ATT + { "PETSKILL_SpeedyAttack", PETSKILL_SpeedyAttack, 0},//vincent add 2002/05/20 +#endif +#ifdef _SKILL_SACRIFICE + { "PETSKILL_Sacrifice", PETSKILL_Sacrifice, 0},//vincent add 2002/05/30 +#endif +#ifdef _SKILL_REFRESH + { "PETSKILL_Refresh", PETSKILL_Refresh, 0},//vincent add 2002/08/08 +#endif +#ifdef _SKILL_WEAKEN //vincent輼: + { "PETSKILL_Weaken", PETSKILL_Weaken, 0},//vincent add 2002/07/11 +#endif +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 + { "PETSKILL_Deeppoison", PETSKILL_Deeppoison, 0},//vincent add 2002/07/16 +#endif +#ifdef _SKILL_BARRIER //vincent輼:ħ + { "PETSKILL_Barrier", PETSKILL_Barrier, 0},//vincent add 2002/07/16 +#endif +#ifdef _SKILL_NOCAST //vincent輼:Ĭ + { "PETSKILL_Nocast", PETSKILL_Nocast, 0},//vincent add 2002/07/16 +#endif +#ifdef _SKILL_ROAR //vincent輼: + { "PETSKILL_Roar", PETSKILL_Roar, 0},//vincent add 2002/07/11 +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + { "PETSKILL_Sars", PETSKILL_Sars, 0}, +#endif + +#ifdef _SONIC_ATTACK // WON ADD + { "PETSKILL_Sonic", PETSKILL_Sonic, 0}, +#endif +#ifdef _PETSKILL_REGRET + { "PETSKILL_Regret", PETSKILL_Regret, 0}, +#endif + +#ifdef _PETSKILL_GYRATE + { "PETSKILL_Gyrate", PETSKILL_Gyrate, 0}, +#endif + +#ifdef _PETSKILL_ACUPUNCTURE //Ƥ + { "PETSKILL_Acupuncture", PETSKILL_Acupuncture, 0}, +#endif + +#ifdef _PETSKILL_RETRACE + { "PETSKILL_Retrace", PETSKILL_Retrace, 0}, +#endif + +#ifdef _PETSKILL_HECTOR + { "PETSKILL_Hector", PETSKILL_Hector, 0}, +#endif + +#ifdef _PETSKILL_FIREKILL + { "PETSKILL_Firekill", PETSKILL_Firekill, 0}, +#endif + +#ifdef _PETSKILL_DAMAGETOHP + { "PETSKILL_DamageToHp2", PETSKILL_DamageToHp2, 0}, +#endif + +#ifdef _PETSKILL_BECOMEFOX + { "PETSKILL_BecomeFox", PETSKILL_BecomeFox, 0}, +#endif + +#ifdef _PETSKILL_BECOMEPIG + { "PETSKILL_BecomePig", PETSKILL_BecomePig, 0}, +#endif + +#ifdef _PETSKILL_SHOWMERCY + { "PETSKILL_ShowMercy", PETSKILL_ShowMercy, 0}, +#endif + +#ifdef _PETSKILL_COMBINED + { "PETSKILL_Combined", PETSKILL_Combined, 0}, +#endif +#ifdef _PETSKILL_LER + { "PETSKILL_BatFly", PETSKILL_BatFly, 0}, + { "PETSKILL_DivideAttack", PETSKILL_DivideAttack, 0}, +#endif +#ifdef _PETSKILL_BATTLE_MODEL + { "PETSKILL_BattleModel", PETSKILL_BattleModel, 0}, +#endif + +#ifdef _MASSAGE_PETSKILL + { "PETSKILL_Massage", PETSKILL_Massage, 0}, +#endif + +#ifdef _STRENGTH_PETSKILL + { "PETSKILL_Strength", PETSKILL_Strength, 0}, +#endif + +#ifdef _RESURRECTION_PETSKILL + { "PETSKILL_Resurrection", PETSKILL_Resurrection, 0}, +#endif +#ifdef _LOSTLOST_PETSKILL + { "PETSKILL_Lostlost", PETSKILL_Lostlost, 0}, +#endif +#ifdef _GRAPPLING_PETSKILL + { "PETSKILL_Grappling", PETSKILL_Grappling, 0}, +#endif + +#ifdef _PETOUT_PETSKILL + { "PETSKILL_Petout", PETSKILL_Petout, 0}, +#endif +#ifdef _INVERSION_PETSKILL + { "PETSKILL_Inversion", PETSKILL_Inversion, 0}, +#endif +#ifdef _PETSKILL_PASSIVE_PET_MATCH1 + { "PETSKILL_PASSIVE_PET_MATCH1", PETSKILL_PASSIVE_PET_MATCH1, 0}, +#endif + +}; + +/*----------------------------------------------------------------------*/ + + +/* ͣʧͱ */ +/*----------------------------------------------------------------------*/ +INLINE BOOL PETSKILL_CHECKINDEX( int index ) +{ + if( PETSKILL_petskillnum<=index || index<0 )return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +static INLINE BOOL PETSKILL_CHECKINTDATAINDEX( int index) +{ + if( PETSKILL_DATAINTNUM <= index || index < 0 ) return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +static INLINE BOOL PETSKILL_CHECKCHARDATAINDEX( int index) +{ + if( PETSKILL_DATACHARNUM <= index || index < 0 ) return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +INLINE int PETSKILL_getInt( int index, PETSKILL_DATAINT element) +{ + return PETSKILL_petskill[index].data[element]; +} +/*----------------------------------------------------------------------*/ +INLINE int PETSKILL_setInt( int index, PETSKILL_DATAINT element, int data) +{ + int buf; + buf = PETSKILL_petskill[index].data[element]; + PETSKILL_petskill[index].data[element]=data; + return buf; +} +/*----------------------------------------------------------------------*/ +INLINE char* PETSKILL_getChar( int index, PETSKILL_DATACHAR element) +{ + if( !PETSKILL_CHECKINDEX( index)) return "\0"; + if( !PETSKILL_CHECKCHARDATAINDEX( element)) return "\0"; + return PETSKILL_petskill[index].string[element].string; +} + +/*----------------------------------------------------------------------*/ +INLINE BOOL PETSKILL_setChar( int index ,PETSKILL_DATACHAR element, char* new ) +{ + if(!PETSKILL_CHECKINDEX(index))return FALSE; + if(!PETSKILL_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( PETSKILL_petskill[index].string[element].string, + sizeof(PETSKILL_petskill[index].string[element].string), + new ); + return TRUE; +} +/*---------------------------------------------------------------------- + * ʸ ë£ + *---------------------------------------------------------------------*/ +int PETSKILL_getPetskillNum( void) +{ + return PETSKILL_petskillnum; +} + +#ifdef _CFREE_petskill +#define PETSKILL_STARTINTNUM 7 //PETSKILL_DATACHARNUM+1 +#else +#define PETSKILL_STARTINTNUM 5 +#endif + +/*---------------------------------------------------------------------- + * ʸ ɬð̻ë //ʼ輼 + *---------------------------------------------------------------------*/ +BOOL PETSKILL_initPetskill( char *filename) +{ + FILE* f; + char line[256]; + int linenum=0; + int petskill_readlen=0; + int i,j; + int max_skillid =0; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "file open error\n"); + return FALSE; + } + + PETSKILL_petskillnum=0; + + /* ئ滥ϵؤ¾Ʃ *///輼 + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + char token[256]; + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + PETSKILL_petskillnum++; +#ifdef _PETSKILL_OPTIMUM // Robin ȡ輼ID + if( getStringFromIndexWithDelim( line, ",", PETSKILL_STARTINTNUM, token, sizeof(token)) == FALSE ) + continue; + //print("\n 輼ID:%d %s ", atoi( token), line); + max_skillid = max( atoi( token), max_skillid); +#endif + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Ѱʧ\n" ); + fclose(f); + return FALSE; + } + +#ifdef _PETSKILL_OPTIMUM // 輼TableΪ ID +1 + PETSKILL_petskillnum = max_skillid +1; +// print("\n 輼ID = %d\n", max_skillid); +#endif + + PETSKILL_petskill = allocateMemory( sizeof(struct tagPetskill) + * PETSKILL_petskillnum ); + if( PETSKILL_petskill == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(struct tagPetskill)*PETSKILL_petskillnum); + fclose( f ); + return FALSE; + } + + /* */ + for( i = 0; i < PETSKILL_petskillnum; i ++ ) { + for( j = 0; j < PETSKILL_DATAINTNUM; j ++ ) { + PETSKILL_setInt( i,j,-1); + } + for( j = 0; j < PETSKILL_DATACHARNUM; j ++ ) { + PETSKILL_setChar( i,j,""); + } + } + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + +#ifdef _PETSKILL_OPTIMUM // ȡг輼ID, ֱԳ輼IDTable index + ret = getStringFromIndexWithDelim( line, ",", PETSKILL_STARTINTNUM, token, sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + petskill_readlen = atoi( token); +#endif + + for( i = 0; i < PETSKILL_DATACHARNUM; i ++ ) { + /* ٯ ͼëέ */ + ret = getStringFromIndexWithDelim( line,",", i + 1, token,sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + PETSKILL_setChar( petskill_readlen, i, token); + } + + /* 4 ϷѰ */ + for( i = PETSKILL_STARTINTNUM; i < PETSKILL_DATAINTNUM+PETSKILL_STARTINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + if( strlen( token) != 0 ) { + PETSKILL_setInt( petskill_readlen, i - PETSKILL_STARTINTNUM, atoi( token)); + } + } + if( i < PETSKILL_DATAINTNUM+PETSKILL_STARTINTNUM ) continue; + +#ifdef _CFREE_petskill + if(line[0]=='E') PETSKILL_setInt( petskill_readlen, PETSKILL_ILLEGAL, 1); +#else + // Robin 2001/02/26 +1 set_illegal_Skill + if(line[0]=='T') PETSKILL_setInt( petskill_readlen, PETSKILL_ILLEGAL, 1); +#endif + //print("Id:%d illegal:%d\n",PETSKILL_getInt(petskill_readlen,PETSKILL_ID),PETSKILL_getInt(petskill_readlen,PETSKILL_ILLEGAL)); + + petskill_readlen ++; +} + + } + fclose(f); + + PETSKILL_petskillnum = petskill_readlen; + + + print( "Ч\ %d...", PETSKILL_petskillnum ); + + /* hash */ + for( i = 0; i < arraysizeof( PETSKILL_functbl); i ++ ) { + PETSKILL_functbl[i].hash = hashpjw( PETSKILL_functbl[i].functionname); + } +/* +#ifdef _CFREE_petskill + for( i=0; i = 0 && petskillid < PETSKILL_petskillnum ) + return PETSKILL_petskill[petskillid].data[PETSKILL_ID]; +#else + int i; + for( i = 0; i < PETSKILL_petskillnum; i ++ ) { + if( PETSKILL_petskill[i].data[PETSKILL_ID] == petskillid ) { + return i; + } + } +#endif + return -1; +} +/*------------------------------------------------------------ + * ʸ պ̼ë߯ + * ¦ + * name char*  + * ߯Ի + * ѳ߼̼ئ巴NULL + ------------------------------------------------------------*/ +PETSKILL_CALLFUNC PETSKILL_getPetskillFuncPointer(char* name ) +{ + int i; + int hash = hashpjw( name ); + for( i = 0 ; i< arraysizeof( PETSKILL_functbl) ; i++ ) { + if( PETSKILL_functbl[i].hash == hash ) { + if( strcmp( PETSKILL_functbl[i].functionname, name ) == 0 ) { + return PETSKILL_functbl[i].func; + } + } + } + return NULL; +} + +int PETSKILL_Use( + int charaindex, + int havepetskill, + int toindex, + char *data + //BOOL isCLI // Robin 2001/02/26 if owner is player +) +{ + int array, petskillid; + int ret; + PETSKILL_CALLFUNC func; + + petskillid = CHAR_getPetSkill( charaindex, havepetskill); + +#ifdef _FIXWOLF // Syu ADD ˱Bug + if( petskillid == 600 ){ + if ( CHAR_getInt ( charaindex , CHAR_BASEIMAGENUMBER) == 101428 +#ifdef _EXPANSION_VARY_WOLF + || CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==104109 +#endif + ) + petskillid = -1; + } +#endif + + array = PETSKILL_getPetskillArray( petskillid); + if( array == -1 ) return FALSE; +#ifndef _OPEN_E_PETSKILL + if(PETSKILL_getInt(array, PETSKILL_ILLEGAL)){ + if( (CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPET) ){ + return FALSE; + } + } +#endif +#ifdef _PETSKILL_CHECKTYPE +#define _SKILLTYPE_NONE 0x01 +#define _SKILLTYPE_BATTLE 0x02 + if( (CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPET) && + (PETSKILL_getInt( array, PETSKILL_USETYPE) & _SKILLTYPE_BATTLE) > 0){ + int masterindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + if( !CHAR_CHECKINDEX( masterindex) ) return FALSE; + if( CHAR_getWorkInt( masterindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + return FALSE; + } + } +#endif + func = PETSKILL_getPetskillFuncPointer( PETSKILL_getChar( array, PETSKILL_FUNCNAME) ); + if( func ) { +#ifdef _ONE_PET_SKILL + char *buf=PETSKILL_getChar(array, PETSKILL_NAME); + if(strlen(buf) > 0 && buf[0]=='$'){ + CHAR_setPetSkill( charaindex, havepetskill, -1); + } +#endif + ret = func( charaindex, toindex, array, data ); + }else { + ret = FALSE; + } + return ret; +} + + +int _PETSKILL_GetArray( char *file, int line, int charaindex, int havepetskill ) +{ + int petskillid,array; + + petskillid = CHAR_getPetSkill( charaindex, havepetskill); + if( petskillid == -1 ) { + return -1; + } + + array = PETSKILL_getPetskillArray( petskillid); + + return array; +} + + +//---------------------------------------------------------------------- +int PETSKILL_ContinuationAttack( + int charaindex, + int toindex, + int array, + char *data + +) +{ + char *pszOption; + int N = 1; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_RENZOKU ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( sscanf( pszOption, "%d", &N ) == 1 ){ + if( N < 1 || N > 10 )N = 1; + }else{ + N = 1; + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, N ); + + return TRUE; +} + +int PETSKILL_ChargeAttack( + int charaindex, + int toindex, + int array, + char *data +) +{ + char *pszOption, *pszP; + int N = 1, Per = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_CHARGE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( sscanf( pszOption, "%d", &N ) == 1 ){ + if( N < 1 || N > 10 )N = 1; + }else{ + N = 1; + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%d", &Per ); + } + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, N ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, Per ); + return TRUE; +} + +int PETSKILL_Guardian( + int charaindex, + int toNo, + int array, + char *data +) +{ + char *pszOption, *pszP; + int + battleindex, side, pos, ownerpos, + strdef, flg; + float fPer = 0.01; + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_GUARDIAN_ATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + flg = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEFLG ); + flg |= CHAR_BATTLEFLG_GUARDIAN; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEFLG, flg ); + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + + pos = BATTLE_Index2No( battleindex, charaindex ); + + if( (pszP = strstr( pszOption, "COM:" ) ) != NULL + && strstr( pszP+4, "" ) != NULL + ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + + side = ( toNo >= SIDE_OFFSET )?( 1 ):( 0 ); + ownerpos = toNo - side * SIDE_OFFSET; + + if( 0 <= ownerpos && ownerpos < SIDE_OFFSET ){ + BattleArray[battleindex].Side[side].Entry[ownerpos].guardian = pos; + } + + }else{ + side = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + ownerpos = pos - 5; + ownerpos -= side * SIDE_OFFSET; + + if( ownerpos < 0 || ownerpos > 19 ){ + }else{ + BattleArray[battleindex].Side[side].Entry[ownerpos].guardian = pos; + } + } + + return TRUE; +} + +int PETSKILL_Mighty( + int charaindex, + int toindex, + int array, + char *data +) +{ + char *pszOption, *pszP; + int iBai = 0, iDuck = 0; + float fBai = 2.00; + float fPer = 0.01; + int strdef; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_MIGHTY ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( (pszP = strstr( pszOption, "" ) ) != NULL ){ + sscanf( pszP+2, "%f", &fBai ); + iBai = (int)(fBai * 100); + } + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, iBai ); + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( ( pszP = strstr( pszOption, "" ) ) != NULL){ + sscanf( pszP+2, "%d", &iDuck ); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef)); + } + + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, iDuck ); + return TRUE; +} + + + +int PETSKILL_PowerBalance( + int charaindex, + int toindex, + int array, + char *data +) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int strdef; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_POWERBALANCE); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } +#ifdef _POWER_UP + char *buff = CHAR_getChar(charaindex,CHAR_POWER_UP); + char token[256]; + int type = 0; + if(getStringFromIndexWithDelim( buff, "|", 1, token, sizeof( token))){ + type = atoi(token); + } + int value = 0; + if(getStringFromIndexWithDelim( buff, "|", 2, token, sizeof( token))){ + value += atoi(token); + } + if(getStringFromIndexWithDelim( buff, "|", 3, token, sizeof( token))){ + value += atoi(token); + } + if(getStringFromIndexWithDelim( buff, "|", 4, token, sizeof( token))){ + value += atoi(token); + } +#endif + + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); +#ifdef _POWER_UP + if(type == 2){ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR) + value; + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef + value)); + }else +#endif +{ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); +} + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); +#ifdef _POWER_UP + if(type == 3){ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH) + value; + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef + value)); + }else +#endif +{ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); +} + } + +#ifdef _EXPANSION_POWERBALANCE + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); +#ifdef _POWER_UP + if(type == 4){ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX) + value; + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef + value)); + }else +#endif +{ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef)); +} + } +#endif + return TRUE; +} + +//---------------------------------------------------------------------- +int PETSKILL_StatusChange( + int charaindex, + int toindex, + int array, + char *data + +) +{ + char *pszOption, *pszP; + float fPer = 0.01; + int strdef; + int status = -1, i = 0, turn = 3; + char szTurn[] = "turn"; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_STATUSCHANGE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + pszP = pszOption; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, i ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, turn ); + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER, + (CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef) ); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER, + (CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK, + (CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef)); + } + return TRUE; + +} + +#ifdef _VARY_WOLF + +int PETSKILL_Vary( int cindex, int tindex, int id, char* data) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int a_dep; + int d_dep; + +#ifndef _EXPANSION_VARY_WOLF + int i; + int petid[4] = {981,982,983,984}; + + for( i=0; i<4; i++) { + if( CHAR_getInt( cindex, CHAR_PETID) == petid[i] ) break; + } + if( i>= 4 ) return FALSE; +#endif + CHAR_setWorkInt( cindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_VARY); + CHAR_setWorkInt( cindex, CHAR_WORKBATTLECOM2, tindex ); + CHAR_setWorkInt( cindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( id, PETSKILL_OPTION ); + + + if(pszOption=="\0"){ + print("\n pszOption==NULL"); + return FALSE; + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + CHAR_setWorkInt( cindex, CHAR_SKILLSTRPOWER, fPer); + fPer = fPer / 100; + a_dep = CHAR_getWorkInt( cindex, CHAR_WORKFIXSTR); + a_dep = (int)(a_dep * fPer); + CHAR_setWorkInt( cindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( cindex, CHAR_WORKFIXSTR) + a_dep); + + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + CHAR_setWorkInt( cindex, CHAR_SKILLTGHPOWER, fPer); + fPer = fPer / 100; + a_dep = CHAR_getWorkInt( cindex, CHAR_WORKFIXTOUGH); + a_dep = (int)(a_dep * fPer); + CHAR_setWorkInt( cindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( cindex, CHAR_WORKFIXTOUGH) + a_dep); + + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + CHAR_setWorkInt( cindex, CHAR_SKILLDEXPOWER, fPer); + fPer = fPer / 100; + d_dep = CHAR_getWorkInt( cindex, CHAR_WORKFIXDEX); + d_dep = (int)(d_dep * fPer); + CHAR_setWorkInt( cindex, CHAR_WORKQUICK, CHAR_getWorkInt( cindex, CHAR_WORKFIXDEX) + d_dep); + + } +#ifdef _EXPANSION_VARY_WOLF + if( (pszP = strstr( pszOption, "ͼ%" ) ) != NULL ){ + int image=0; + sscanf( pszP+3, "%d", &image ); + + CHAR_setInt( cindex, CHAR_BASEIMAGENUMBER, image); + }else{ + CHAR_setInt( cindex, CHAR_BASEIMAGENUMBER, 101428); + } + CHAR_SETWORKINT_LOW( cindex, CHAR_WORKBATTLECOM3, CHAR_getInt( cindex, CHAR_BASEIMAGENUMBER)); +#else + CHAR_setInt( cindex, CHAR_BASEIMAGENUMBER, 101428); +#endif + + CHAR_setWorkInt( cindex, CHAR_WORKTURN, 0); + + return TRUE; +} +#endif + +#ifdef _SKILL_WILDVIOLENT_ATT + +int PETSKILL_WildViolentAttack( + int charaindex, + int toindex, + int array, + char *data + +) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int strdef=0; + int iDuck = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_WILDVIOLENTATTACK); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + //ȡֵ + if( ( pszP = strstr( pszOption, "" ) ) != NULL){ + sscanf( pszP+2, "%d", &iDuck ); + } + // Ĥë + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, iDuck ); + + return TRUE; +} +#endif + +#ifdef _SKILL_SACRIFICE +int PETSKILL_Sacrifice( + int charaindex, + int toindex, + int array, + char *data + +) +{ + char buf[256]; + + if(CHAR_getInt(charaindex,CHAR_HP) > CHAR_getWorkInt(charaindex,CHAR_WORKMAXHP)*0.2 ) + { + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SACRIFICE); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + } + else + { + + sprintf(buf, "%s; Ԯʧ!!", CHAR_getChar( charaindex, CHAR_NAME )); + CHAR_talkToCli( CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX), -1, buf, CHAR_COLORYELLOW); + return FALSE; + } + return TRUE; +} +#endif +#ifdef _SKILL_REFRESH +int PETSKILL_Refresh( + int charaindex, + int toindex, + int array, + char *data + +) +{ + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_REFRESH); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif +#ifdef _SKILL_WEAKEN //vincent輼: +int PETSKILL_Weaken( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_WEAKEN); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 +int PETSKILL_Deeppoison( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_DEEPPOISON); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif + +#ifdef _SKILL_BARRIER //vincent輼:ħ +int PETSKILL_Barrier( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_BARRIER); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif + +#ifdef _SKILL_NOCAST //vincent輼:Ĭ +int PETSKILL_Nocast( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_NOCAST); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif + +#ifdef _SKILL_ROAR //vincent輼: +int PETSKILL_Roar( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ROAR); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + return TRUE; +} +#endif + +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 +int PETSKILL_GuardBreak2( + int charaindex, + int toNo, + int array, + char *data + +) +{ + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_GBREAK2 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; + +} +#endif + +//******************************************************* +int PETSKILL_NormalAttack( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; + +} + +#ifdef _INVERSION_PETSKILL +int PETSKILL_Inversion( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_INVERSION ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; + +} +#endif + + + +#ifdef _MASSAGE_PETSKILL +int PETSKILL_Massage( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_MASSAGE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; + +} +#endif + +#ifdef _PETOUT_PETSKILL +int PETSKILL_Petout( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_PETOUT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; + +} +#endif + +#ifdef _STRENGTH_PETSKILL +int PETSKILL_Strength( int charaindex, int toNo, int array, char *data ) +{ + int nums=0; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + return FALSE; + nums = CHAR_getWorkInt( charaindex, CHAR_WORK_STRENGTH); + + char *skillarg = PETSKILL_getChar( array, PETSKILL_OPTION ); + char buf1[256]; + + if( getStringFromIndexWithDelim( skillarg,"|",1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + if( nums >= max(1, atoi(buf1)) ){ + int toindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + char buf[256]; + sprintf(buf,"˼ܵ %d Ρ", max(1, atoi(buf1))); + CHAR_talkToCli( toindex, -1, buf, CHAR_COLORYELLOW); + return FALSE; + } + + CHAR_setWorkInt( charaindex, CHAR_WORK_STRENGTH, ++nums ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_STRENGTH); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +int PETSKILL_NormalGuard( + int charaindex, + int toindex, + int array, + char *data + +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_GUARD ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; + +} + + +int PETSKILL_None( + int charaindex, + int toindex, + int array, + char *data +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; +} + + +int PETSKILL_EarthRound( + int charaindex, + int toNo, + int array, + char *data +) +{ + char *pszOption, *pszP; + float fPer = 0.01; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_EARTHROUND1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM3, (int)fPer ); + } + + + return TRUE; + +} + + +int PETSKILL_GuardBreak( + int charaindex, + int toNo, + int array, + char *data + +) +{ + char *pszOption, *pszP; + float fPer = 0.01; + int strdef; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_GBREAK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKQUICK,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef)); + } + + return TRUE; + +} +#ifdef _SKILL_SPEEDY_ATT//ٹ vincent add 2002/05/20 +int PETSKILL_SpeedyAttack( + int charaindex, + int toNo, + int array, + char *data + +) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int strdef=0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SPEEDYATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } + + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + return TRUE; + +} +#endif + +int PETSKILL_Abduct( + int charaindex, + int toNo, + int array, + char *data +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ABDUCT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); + +#ifdef _ABDUCT_NO_PETOUT +{ + int badindex = CHAR_getWorkInt(charaindex, CHAR_WORKPLAYERINDEX); + if(CHAR_getWorkInt( badindex, CHAR_WORKBATTLECOM1) == BATTLE_COM_PETOUT ){ + CHAR_setWorkInt( badindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_talkToCli( badindex, -1,"ʹó̻޷ͬʱ", CHAR_COLORYELLOW ); + } +} +#endif + + + return TRUE; +} + +int PETSKILL_Steal( + int charaindex, + int toNo, + int array, + char *data +) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_STEAL ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return TRUE; +} + +#ifdef _BATTLESTEAL_FIX +int PETSKILL_StealMoney( int charaindex, int toNo, int array, char *data) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_STEALMONEY ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return TRUE; +} +#endif + +//******************************************************* +// -- ʧ ة +// +int PETSKILL_Merge( + int charaindex, + int toNo, + int array, + char *data +) +{ + int ret, ownerindex; + + // Robin 0521 debug + ownerindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + if( CHAR_getWorkInt( ownerindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + print(" Merge_ErrB:fd=%d ", ownerindex); + return FALSE; + } + ret = ITEM_mergeItem_merge( CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX), + CHAR_getInt( charaindex, CHAR_PETID), data, charaindex, 0); +#ifdef _MO_LUA_MERGE_CALLBACK + MergeCallBack(CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX),charaindex,data,ret); +#endif + return ret; +} + +#ifdef _ALCHEMIST +int PETSKILL_Alchemist( + int charaindex, + int toNo, + int array, + char *data +) +{ + int ret, ownerindex; + + // Robin 0521 debug + ownerindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + if( CHAR_getWorkInt( ownerindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + print(" Merge_Alchemist_ErrB:fd=%d ", ownerindex); + return FALSE; + } + ret = ITEM_mergeItem_merge( CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX), + CHAR_getInt( charaindex, CHAR_PETID), data, charaindex, 1); + return ret; +} +#endif + +int PETSKILL_NoGuard( + int charaindex, + int toNo, + int array, + char *data + +) +{ + char *pszOption, *pszP; + int Duck = 0, Counter = 0, Critical = 0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_NOGUARD ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%d", &Duck ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, Duck ); + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%d", &Counter ); + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%d", &Critical ); + } + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, + (Counter << 8) + Critical ); + + return TRUE; +} + +#ifdef _ATTACK_MAGIC + +int PETSKILL_AttackMagic( + int charaindex, + int toindex, + int array, + char *data +) +{ + char *pszP; + char szMagic[] = "magic"; + int magic = 313; // magic idԤΪħȼһ,item indexԤΪ19659 +// int item = 19659; + // ȡó\ + pszP = PETSKILL_getChar( array, PETSKILL_OPTION ); + + // ȡʩŵħmagic id + if((pszP = strstr(pszP,szMagic)) != NULL) + { + pszP += sizeof(szMagic); + sscanf(pszP,"%d",&magic); + } +/* + // ȡдħԵitem index + if((pszP = strstr(pszP,szItem)) != NULL) + { + pszP += sizeof(szItem); + sscanf(pszP,"%d",&item); + } +*/ + // 趨\Ϊħ + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM1,BATTLE_COM_S_ATTACK_MAGIC ); + // Ŀ趨 + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM2,toindex); + // 趨ʹõһħ + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3,magic); + // 趨ʹõħĵ +// CHAR_SETWORKINT_HIGH(charaindex,CHAR_WORKBATTLECOM3,item); + // ´ + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLEMODE,BATTLE_CHARMODE_C_OK ); + + return TRUE; +} + +#endif + +#ifdef _PSKILL_FALLGROUND // +int PETSKILL_FallGround( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption, *pszP; + float fPer = 0.01; + int strdef; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_FALLRIDE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + return TRUE; + +} //BATTLE_COM_S_DAMAGETOHP +#endif +#ifdef _PETSKILL_EXPLODE +int PETSKILL_Explode( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption, *pszP; + float fPer = 0.01; + int strdef; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + if( BattleArray[CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX )].type != BATTLE_TYPE_P_vs_P ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + return TRUE; + } + else + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_EXPLODE ); + + + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKFIXDEX,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXDEX)+strdef)); + } + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + return TRUE; + +} //BATTLE_COM_S_DAMAGETOHP +#endif + +#ifdef _PRO_BATTLEENEMYSKILL +int ENEMYSKILL_ReLife( int enemyindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ENEMYRELIFE ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return TRUE; +} + +int ENEMYSKILL_ReHP( int enemyindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ENEMYREHP ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return TRUE; +} + +int ENEMYSKILL_EnemyHelp( int enemyindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ENEMYHELP ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( enemyindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + return TRUE; +} + +#endif + +#ifdef _SKILL_DAMAGETOHP //Ѫ { "PETSKILL_DamageToHp", PETSKILL_DamageToHp, 0}, +int PETSKILL_DamageToHp( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption; + char buf1[256]; + int strdef; + float def=0.00; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_DAMAGETOHP ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3, array); //¼ + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + strdef = CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + def = (atoi( buf1)/100); + strdef = strdef - (int)(strdef*def); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, strdef); + + return TRUE; + +} +#endif + +#ifdef _Skill_MPDAMAGE +int PETSKILL_MpDamage( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption; + char buf1[256]; + int strdef; + float def=0.00; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_MPDAMAGE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3, array); ////¼ + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + def = (float)(atoi( buf1)/100); + strdef = CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef = strdef - (int)( strdef*def); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, strdef); + + return TRUE; +} +#endif + + +#ifdef _SKILL_TOOTH +int PETSKILL_ToothCrushe( int charaindex, int toNo, int array, char *data ) +{ + //char *pszOption; + //char buf1[256]; + //int strdef; + //float def=0.00; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_TOOTHCRUSHE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ +/* + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + def = (float)(atoi( buf1)/100); + strdef = CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef = strdef - (int)( strdef*def); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, strdef); +*/ + return TRUE; +} +#endif +#ifdef _PSKILL_MODIFY +int PETSKILL_Modifyattack( int charaindex, int toNo, int array, char *data ) +{ + //char *pszOption; + //char buf1[256]; + //int strdef; + //float def=0.00; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_MODIFYATT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ +/* + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + def = (float)(atoi( buf1)/100); + strdef = CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef = strdef - (int)( strdef*def); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, strdef); +*/ + return TRUE; +} +#endif + +#ifdef _PSKILL_MDFYATTACK +int PETSKILL_Mdfyattack( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption; + char buf1[256]; + char MNodify[][36]={"EA","WA","FI","WI"}; + int nums, i; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_MDFYATTACK); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + if( getStringFromIndexWithDelim( pszOption, "|", 1, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + for( i=0; i<4; i++) { + if( strcmp( buf1, MNodify[i]) ) continue; + break; + } + if( i == 4 ) return FALSE; + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM4, i);//¼ + if( getStringFromIndexWithDelim( pszOption, "|", 2, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + nums=atoi( buf1); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM4, nums);//¼ֵ + return TRUE; +} +#endif + +#ifdef _ITEM_INSLAY +int PETSKILL_Inslay( int index, int toNo, int array, char *data) +{ + int charaindex, petid; + + int inslayindex=-1, inslayno=-1; + int i, j, itemno; +#define MAXINSLAY 15 + + int itemindexs[MAXINSLAY]={-1,-1,-1,-1}; + int itemnos[MAXINSLAY]={-1,-1,-1,-1}; + + if( !CHAR_CHECKINDEX( index) ) return FALSE; + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPET ) return FALSE; + charaindex = CHAR_getWorkInt( index, CHAR_WORKPLAYERINDEX); + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) + return FALSE; + petid = CHAR_getInt( charaindex, CHAR_PETID); + + for( i = 0; i < 15; i ++ ) { + char buf[256]; + char *buf1; + int itemindex; + if( getStringFromIndexWithDelim( data , "|", i+1, buf, sizeof( buf ) ) == FALSE ) break; + itemno = atoi( buf); + if( !CHAR_CHECKITEMINDEX( charaindex, itemno) ) continue; + itemindex = CHAR_getItemIndex( charaindex, itemno); + if( !ITEM_CHECKINDEX( itemindex) ) continue; +#ifdef _INSLAY_NOT_PILENUMS + if( ITEM_getInt( itemindex, ITEM_CANBEPILE) == 1 && + ITEM_getInt( itemindex, ITEM_USEPILENUMS) > 1 ){ + CHAR_talkToCli( charaindex, -1, "Ʒ޷о", CHAR_COLORYELLOW); + return FALSE; + } +#endif + + if( i >= MAXINSLAY ) { + CHAR_talkToCli( charaindex, -1, "ÿֻѡĸƷ", CHAR_COLORYELLOW); + return FALSE; + } + for( j=0; j< MAXINSLAY; j++ ) { + if( itemindexs[j] == itemindex ) { + print("Ʒindexͬ ERROR !!\n"); + return FALSE; + } + } + if( (buf1 = ITEM_getChar( itemindex, ITEM_TYPECODE)) == "\0" ) { + print(" ITEM_TYPECODE == NULL !!\n"); + return FALSE; + } + if( !strcmp( buf1, "\0") || !strcmp( buf1, "NULL") ) { + CHAR_talkToCli( charaindex, -1, "ƷʺϾ", CHAR_COLORYELLOW); + return FALSE; + } + if( strstr( buf1, "INSLAY") != 0 ) { + if( !ITEM_CHECKINDEX( inslayindex)) { + inslayindex = itemindex; + inslayno = itemno; + }else { + CHAR_talkToCli( charaindex, -1, "ÿֻѡһߡ", CHAR_COLORYELLOW); + return FALSE; + } + } + itemindexs[i] = itemindex; + itemnos[i] = itemno; + } + + if( !ITEM_CHECKINDEX( inslayindex) ) { + CHAR_talkToCli( charaindex, -1, "ѡһߡ", CHAR_COLORYELLOW); + return FALSE; + } +#ifdef _EXPANSION_ITEM_INSLAY + int maxinslay = max(3, min(atoi(PETSKILL_getChar( array, PETSKILL_OPTION )), 25)); +#endif + for( i=0; i< MAXINSLAY; i++){ + if( !ITEM_CHECKINDEX( itemindexs[i]) )break; + if( inslayindex == itemindexs[i] ) continue; + +#ifdef _EXPANSION_ITEM_INSLAY + if( PETSKILL_ITEM_inslay( charaindex, inslayindex, itemindexs[i], maxinslay ) == FALSE ){ + return FALSE; + } +#else + if( PETSKILL_ITEM_inslay( charaindex, inslayindex, itemindexs[i] ) == FALSE ){ + return FALSE; + } +#endif + CHAR_DelItem( charaindex, itemnos[i]); +/* + CHAR_setItemIndex( charaindex, itemnos[i] ,-1); + CHAR_sendItemDataOne( charaindex, itemnos[i] ); + ITEM_endExistItemsOne( itemindexs[i]); +*/ + } + + CHAR_sendItemDataOne( charaindex, inslayno ); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_ATK | CHAR_P_STRING_DEF + | CHAR_P_STRING_QUICK | CHAR_P_STRING_CHARM ); + + return TRUE; +} + +#endif + +#ifdef _MAGIC_SUPERWALL +int PETSKILL_MagicStatusChange( int charaindex, int toindex, int array, char *data ) +{ + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SUPERWALL); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toindex ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + return TRUE; +} + +#endif + +#ifdef _PETSKILL_SETDUCK +int PETSKILL_SetDuck( int charaindex, int toNo, int array, char *data ) +{ + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + return FALSE; + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SETDUCK); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + + CHAR_setWorkInt( charaindex, CHAR_MAGICPETMP, 0 ); + return TRUE; +} +#endif + +#ifdef _MAGICPET_SKILL +int PETSKILL_SetMagicPet( int charaindex, int toNo, int array, char *data ) +{ + int nums=0; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + return FALSE; + nums = CHAR_getWorkInt( charaindex, CHAR_MAGICPETMP); + if( nums >= 3 ){ + int toindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + CHAR_talkToCli( toindex, -1, "˼ܵΡ", CHAR_COLORYELLOW); + return FALSE; + } + CHAR_setWorkInt( charaindex, CHAR_MAGICPETMP, nums ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SETMAGICPET); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_FIXITEM +int PETSKILL_Fixitem( int index, int toNo, int array, char *data) +{ + int charaindex, petid; + + int fixindex=-1, fixno=-1; + int i, j, itemno; +#define MAXFIXITEM 2 + int itemindexs[MAXFIXITEM]={-1,-1}; + int itemnos[MAXFIXITEM]={-1,-1}; + + if( !CHAR_CHECKINDEX( index) ) return FALSE; + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPET ) return FALSE; + charaindex = CHAR_getWorkInt( index, CHAR_WORKPLAYERINDEX); + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) + return FALSE; + petid = CHAR_getInt( charaindex, CHAR_PETID); + + + for( i = 0; i < 15; i ++ ) { + char buf[256]; + int itemtype=-1; + int itemindex; + if( getStringFromIndexWithDelim( data , "|", i+1, buf, sizeof( buf ) ) == FALSE ) break; + itemno = atoi( buf); + if( !CHAR_CHECKITEMINDEX( charaindex, itemno) ) continue; + itemindex = CHAR_getItemIndex( charaindex, itemno); + if( !ITEM_CHECKINDEX( itemindex) ) continue; + + if( i >= MAXFIXITEM ) { + CHAR_talkToCli( charaindex, -1, "޸ÿֻѡƷ", CHAR_COLORYELLOW); + return FALSE; + } + for( j=0; j< MAXFIXITEM; j++ ) { + if( itemindexs[j] == itemindex ) { + print("޸Ʒindexͬ ERROR !!\n"); + return FALSE; + } + } + itemtype = ITEM_getInt( itemindex, ITEM_TYPE); + if( itemtype == ITEM_DISH ) { + CHAR_talkToCli( charaindex, -1, "޸", CHAR_COLORYELLOW); + return FALSE; + } + + if( (itemtype >= ITEM_FIST && itemtype <= ITEM_AMULET) || + itemtype == ITEM_BOOMERANG || itemtype == ITEM_BOUNDTHROW || itemtype == ITEM_BREAKTHROW +#ifdef _ITEM_EQUITSPACE + || itemtype == ITEM_WBELT + || itemtype == ITEM_WSHIELD + || itemtype == ITEM_WSHOES +#endif +#ifdef _EQUIT_NEWGLOVE + || itemtype == ITEM_WGLOVE +#endif +#ifdef _PET_ITEM +#ifndef _TAKE_ITEMDAMAGE_FOR_PET + || (itemtype >= ITEM_PET_HEAD && itemtype <= ITEM_PET_FEET) +#endif +#endif + ){ + if( !ITEM_CHECKINDEX( fixindex)) { + fixindex = itemindex; + fixno = itemno; + }else { + CHAR_talkToCli( charaindex, -1, "޸ÿֻѡһߡ", CHAR_COLORYELLOW); + return FALSE; + } + } + + itemindexs[i] = itemindex; + itemnos[i] = itemno; + } + + if( !ITEM_CHECKINDEX( fixindex) ) { + CHAR_talkToCli( charaindex, -1, "޸ѡһߡ", CHAR_COLORYELLOW); + return FALSE; + } + + if( PETSKILL_ITEM_FixItem( charaindex, fixindex, itemindexs ) == FALSE ){ + return FALSE; + }else { + for( i=0; i< MAXFIXITEM; i++) { + if( !ITEM_CHECKINDEX( itemindexs[i]) )break; + if( fixindex == itemindexs[i] ) continue; + CHAR_setItemIndex( charaindex, itemnos[i] ,-1); + CHAR_sendItemDataOne( charaindex, itemnos[i] ); + ITEM_endExistItemsOne( itemindexs[i]); + } + } + + CHAR_sendItemDataOne( charaindex, fixno ); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_ATK | CHAR_P_STRING_DEF + | CHAR_P_STRING_QUICK | CHAR_P_STRING_CHARM ); + CHAR_talkToCli( charaindex, -1, "޸ɡ", CHAR_COLORYELLOW); + return TRUE; +} +#endif + +#ifdef _PETSKILL_TIMID +int PETSKILL_BattleTimid( int charaindex, int toNo, int array, char *data ) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_TIMID ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.7) ); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.4) ); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*0.8) ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + return TRUE; +} +#endif +#ifdef _PETSKILL_2TIMID +int PETSKILL_2BattleTimid( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption="\0"; + char *pszP; + float fPer=0; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_2TIMID ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + if( (pszP = strstr( pszOption, "-%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*fPer) ); + } + if( (pszP = strstr( pszOption, "+%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)+(CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*fPer) ); + } + if( (pszP = strstr( pszOption, "-%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*fPer) ); + } + if( (pszP = strstr( pszOption, "+%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)+(CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*fPer) ); + } + if( (pszP = strstr( pszOption, "-%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*fPer) ); + } + if( (pszP = strstr( pszOption, "+%" ) ) != NULL ){ + sscanf( pszP+4, "%f", &fPer ); + fPer=(fPer/100); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)+(CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*fPer) ); + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + return TRUE; +} +#endif +#ifdef _PETSKILL_ANTINTER +int PETSKILL_AntInter( int charaindex, int toNo, int array, char* data) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ANTINTER); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _RESURRECTION_PETSKILL +int PETSKILL_Resurrection( int charaindex, int toNo, int array, char* data) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_RESURRECTION); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _GRAPPLING_PETSKILL +int PETSKILL_Grappling( int charaindex, int toNo, int array, char* data) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_GRAPPLING); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _LOSTLOST_PETSKILL +int PETSKILL_Lostlost( int charaindex, int toNo, int array, char* data) +{ + int nums=0; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) + return FALSE; + nums = CHAR_getWorkInt( charaindex, CHAR_WORK_LOSTLOST); + + char *skillarg = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( nums >= max(1, atoi(skillarg)) ){ + int toindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + char buf[256]; + sprintf(buf,"˼ܵ %d Ρ", max(1, atoi(skillarg))); + CHAR_talkToCli( toindex, -1, buf, CHAR_COLORYELLOW); + return FALSE; + } + + CHAR_setWorkInt( charaindex, CHAR_WORK_LOSTLOST, ++nums); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_LOSTLOST); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_PROPERTY +int PETSKILL_BattleProperty( int charaindex, int toNo, int array, char *data ) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_PROPERTYSKILL ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + +// CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.7) ); +// CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.5) ); +// CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*0.95) ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + + return TRUE; +} +#endif + +#ifdef _PETSKILL_TEAR +int PETSKILL_BattleTearDamage( int charaindex, int toNo, int array, char *data ) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_PETSKILLTEAR ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.9) ); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, ( CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.8) ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + + +#ifdef _BATTLE_LIGHTTAKE +int PETSKILL_Lighttakeed( int charaindex, int toNo, int array, char *data ) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_LIGHTTAKE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.7) ); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.5) ); +// CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX)*0.95) ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + return TRUE; +} +#endif + +#ifdef _BATTLE_ATTCRAZED +int PETSKILL_AttackCrazed( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption="\0"; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ATTCRAZED ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR)*0.8) ); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH)*0.7) ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, atoi(pszOption)); + return TRUE; +} +#endif + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 +int PETSKILL_AttackShoot( int charaindex, int toNo, int array, char *data ) +{ + //int n = RAND ( 3 , 5 ) ; + int n ; + int loyal = CHAR_getWorkInt( charaindex, CHAR_WORKFIXAI ); + char bb1[16] , bb2[16] ; + char *buf = "\0" ; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return FALSE; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ATTSHOOT ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + buf = PETSKILL_getChar( array , PETSKILL_OPTION ) ; + if ( buf == "\0" ) return FALSE; + getStringFromIndexWithDelim( buf , "|", 1 , bb1 , sizeof( bb1 ) ); + getStringFromIndexWithDelim( buf , "|", 2 , bb2 , sizeof( bb2 ) ); + n = RAND ( atoi(bb1) , atoi(bb2) ) ; + if ( loyal >= 100 ) { + if ( RAND ( 1 , 300 ) > 299 ) + n = 8 ; + else if ( (CHAR_getInt( charaindex , CHAR_HP )) < 20 && ( RAND ( 1 , 50 ) > 49 ) ) + n = 8 ; + } +/* + if ( n != 8 ) + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR) * 1.2 / n ) ); + else + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXSTR) * 1.2 / 4 ) ); + CHAR_setWorkInt( charaindex, CHAR_WORKDEFENCEPOWER, (CHAR_getWorkInt( charaindex, CHAR_WORKFIXTOUGH) * 1) ); +*/ + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array);//¼ + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, n); + return TRUE; +} +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ +int PETSKILL_Sars( int charaindex, int toNo, int array, char *data ) +{ + + char *pszOption, *pszP; + int status = -1, i = 0, turn = 3; + char szTurn[] = "turn"; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SARS ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + pszP = pszOption; + + for( ;status == -1 && pszP[0] != 0; pszP++ ){ + for( i = 1; i < BATTLE_ST_END; i ++ ){ + if( strncmp( pszP, aszStatus[i], 2 ) == 0 ){ + status = i; + pszP +=2; + break; + } + } + } + + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, status ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, turn ); + + return TRUE; + + +} +#endif + +#ifdef _SONIC_ATTACK // WON ADD +int PETSKILL_Sonic( int charaindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SONIC ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; + +} +#endif +#ifdef _PETSKILL_REGRET +int PETSKILL_Regret( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption, *pszP; + int strdef; + float fPer = 0.01; + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKDEFENCEPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXTOUGH)+strdef)); + } + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_REGRET ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; + +} +#endif + +#ifdef _PETSKILL_GYRATE +int PETSKILL_Gyrate( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int strdef=0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_GYRATE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); // 23,24,25,26 Ϊ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } + + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_ACUPUNCTURE +int PETSKILL_Acupuncture( int charaindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_ACUPUNCTURE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_RETRACE +int PETSKILL_Retrace( int charaindex, int toNo, int array, char *data ) +{ + //char *pszOption="\0", *pszP; + //float fPer = 0.01; + //int strdef=0; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_RETRACE ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + +/* pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } + + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } +*/ + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_HECTOR +int PETSKILL_Hector( int charaindex, int toNo, int array, char *data ) +{ + char *pszOption="\0", *pszP; + float fPer = 0.01; + int strdef; + //char szTurn[] = "turn"; + int d_dep; + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_HECTOR ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) { + print("\n pszOption == NULL "); + return FALSE; + } + + //ȡֵ + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + fPer=(fPer/100); + + //趨ֵ + strdef=CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + strdef=(int)(strdef * fPer); + CHAR_setWorkInt(charaindex,CHAR_WORKATTACKPOWER,(CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR)+strdef)); + } + + if( (pszP = strstr( pszOption, "%" ) ) != NULL ){ + sscanf( pszP+3, "%f", &fPer ); + CHAR_setWorkInt( charaindex, CHAR_SKILLDEXPOWER, fPer); + fPer = fPer / 100; + d_dep = CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX); + d_dep = (int)(d_dep * fPer); + CHAR_setWorkInt( charaindex, CHAR_WORKQUICK, CHAR_getWorkInt( charaindex, CHAR_WORKFIXDEX) + d_dep); + } + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + + return TRUE; +} +#endif + +#ifdef _PETSKILL_FIREKILL +int PETSKILL_Firekill( int charaindex, int toNo, int array, char *data ) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_FIREKILL ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + + return TRUE; +} +#endif + +#ifdef _PETSKILL_DAMAGETOHP +int PETSKILL_DamageToHp2( int charaindex, int toNo, int array, char *data ) +{ + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_DAMAGETOHP2 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3, array); //¼ +/* pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + + if( pszOption == "\0" ) return FALSE; + + strdef = CHAR_getWorkInt(charaindex,CHAR_WORKFIXSTR); + def = (atoi( pszOption)/100); + strdef = strdef - (int)(strdef*def); + CHAR_setWorkInt( charaindex, CHAR_WORKATTACKPOWER, strdef); +*/ + + return TRUE; + +} +#endif + +#ifdef _PETSKILL_BECOMEFOX +int PETSKILL_BecomeFox( int charaindex, int toNo, int array, char* data) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_BECOMEFOX); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3, array); //¼ + + return TRUE; +} +#endif + +#ifdef _PETSKILL_BECOMEPIG +int PETSKILL_BecomePig( int charaindex, int toNo, int array, char* data) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_BECOMEPIG); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); //¼ + return TRUE; +} +#endif + +#ifdef _PETSKILL_LER +int PETSKILL_BatFly(int charaindex,int toNo,int array,char* data) +{ + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM1,BATTLE_COM_S_BAT_FLY); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM2,toNo); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLEMODE,BATTLE_CHARMODE_C_OK); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3,array); + return TRUE; +} + +int PETSKILL_DivideAttack( int charaindex, int toNo, int array, char* data) +{ + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM1,BATTLE_COM_S_DIVIDE_ATTACK); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM2,toNo); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLEMODE,BATTLE_CHARMODE_C_OK); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM3,array); + return TRUE; +} +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +int PETSKILL_BattleModel(int charaindex, int toindex, int array, char* data) +{ + float fPer; + int i,iType,iObjectNum,iValue; + int iAddPowerType[3] = {CHAR_WORKATTACKPOWER,CHAR_WORKDEFENCEPOWER,CHAR_WORKQUICK}; + char *pszOption="\0",szData[32],szData2[32]; + char szWord[3][3] = {"","",""}; + + pszOption = PETSKILL_getChar(array,PETSKILL_OPTION); + if(pszOption == "\0"){ + printf("PETSKILL_BattleModel: ȡ PETSKILL_OPTION !!(:%d,ļ:%s,%d)\n",array,__FILE__,__LINE__); + return FALSE; + } + + // ȡù + if(getStringFromIndexWithDelim(pszOption,"|",1,szData,sizeof(szData)) == FALSE){ + printf("PETSKILL_BattleModel: no type data!!(ļ:%s,%d)\n",__FILE__,__LINE__); + return FALSE; + } + iType = atoi(szData); + // ȡù + if(getStringFromIndexWithDelim(pszOption,"|",2,szData,sizeof(szData)) == FALSE){ + printf("PETSKILL_BattleModel: no object number data!!(ļ:%s,%d)\n",__FILE__,__LINE__); + return FALSE; + } + iObjectNum = atoi(szData); + if(iObjectNum <= 0) iObjectNum = RAND(1,10); + else if(iObjectNum > 10) iObjectNum = 10; + // ȡ + if(getStringFromIndexWithDelim(pszOption,"|",6,szData,sizeof(szData)) != FALSE){ + for(i=0;i<3;i++){ + if(getStringFromIndexWithDelim(szData," ",i+1,szData2,sizeof(szData2)) != FALSE){ + // 趨 + if(strstr(szData2,szWord[i]) != NULL){ + iValue = CHAR_getWorkInt(charaindex,CHAR_WORKATTACKPOWER); + // д "%" 趨 ex: "%" + if(strstr(szData2,"%") != NULL){ + sscanf(szData2 + 3,"%f",&fPer); + fPer = (fPer/100); + iValue += (int)(iValue * fPer); + } + // û "%" 趨 ex: "" + else{ + sscanf(szData2 + 2,"%f",&fPer); + iValue = (int)fPer; + } + CHAR_setWorkInt(charaindex,iAddPowerType[i],iValue); + } + } + else break; + } + } + + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLEMODE,BATTLE_CHARMODE_C_OK); + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM1,BATTLE_COM_S_BATTLE_MODEL); + CHAR_SETWORKINT_LOW(charaindex,CHAR_WORKBATTLECOM2,iType); // ¼ + CHAR_SETWORKINT_HIGH(charaindex,CHAR_WORKBATTLECOM2,iObjectNum); // ¼ + CHAR_setWorkInt(charaindex,CHAR_WORKBATTLECOM3,array); + return TRUE; +} +#endif + +#ifdef _PETSKILL_SHOWMERCY +int PETSKILL_ShowMercy( int charaindex, int toNo, int array, char* data) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_SHOWMERCY); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return TRUE; +} +#endif + +#ifdef _PETSKILL_COMBINED +int PETSKILL_Combined( int charaindex, int toNo, int array, char* data) +{ + char *pszOption="\0"; + char combined[32]; + int kill[10],count=0,i; + char killstr[32],countstr[32]; + + pszOption = PETSKILL_getChar( array, PETSKILL_OPTION ); + if( pszOption == "\0" ) return FALSE; + + strcpy( combined, " " ); + getStringFromIndexWithDelim( pszOption, "|", 1, combined, sizeof( combined)); + if( strcmp( combined, "ۺϷ" ) == 0 ){ + if( getStringFromIndexWithDelim( pszOption, "|", 2, countstr, sizeof( countstr)) == FALSE ) + return FALSE; + count = atoi(countstr); + if( count > 10 ) + count = 10; + for(i=0;i +#include +#include +#include "buf.h" +#include "profession_skill.h" +#include "char_base.h" +#include "battle.h" +#include "magic_base.h" +#include "configfile.h" +#include "char.h" +#include "lssproto_serv.h" +#include "skill.h" +#include "autil.h" +static Professionskill *PROFESSION_skill; + +typedef struct tagProfessionskill_skillFunctionTable +{ + char *functionname; + PROFESSION_SKILL_CALLFUNC func; + int hash; +// int status; +}PROFESSION_SKILL_skillFunctionTable; + +static PROFESSION_SKILL_skillFunctionTable PROFESSION_SKILL_functbl[] = { + +// ʦ + { "PROFESSION_VOLCANO_SPRINGS", PROFESSION_volcano_springs, 0 }, // ɽȪ + { "PROFESSION_FIRE_BALL", PROFESSION_fire_ball, 0 }, // + { "PROFESSION_FIRE_SPEAR", PROFESSION_fire_spear, 0 }, // ǹ + { "PROFESSION_SUMMON_THUNDER", PROFESSION_summon_thunder, 0 }, // + { "PROFESSION_CURRENT", PROFESSION_current, 0 }, // + { "PROFESSION_STORM", PROFESSION_storm, 0 }, // + { "PROFESSION_ICE_ARROW", PROFESSION_ice_arrow, 0 }, // + { "PROFESSION_ICE_CRACK", PROFESSION_ice_crack, 0 }, // + { "PROFESSION_ICE_MIRROR", PROFESSION_ice_mirror, 0 }, // + { "PROFESSION_DOOM", PROFESSION_doom, 0 }, // ĩ + { "PROFESSION_BLOOD", PROFESSION_blood, 0 }, // Ѫ + { "PROFESSION_BLOOD_WORMS", PROFESSION_blood_worms, 0 }, // Ѫ + { "PROFESSION_SIGN", PROFESSION_sign, 0 }, // һѪ + { "PROFESSION_FIRE_ENCLOSE", PROFESSION_fire_enclose, 0 }, // + { "PROFESSION_ICE_ENCLOSE", PROFESSION_ice_eclose, 0 }, // + { "PROFESSION_THUNDER_ENCLOSE", PROFESSION_thunder_enclose, 0 }, // ׸ + { "PROFESSION_FIRE_PRACTICE", PROFESSION_fire_practice, 0 }, // ħ + { "PROFESSION_ICE_PRACTICE", PROFESSION_ice_practice, 0 }, // ħ + { "PROFESSION_THUNDER_PRACTICE",PROFESSION_thunder_practice,0 }, // ħ + { "PROFESSION_ENCLOSE", PROFESSION_enclose, 0 }, // + { "PROFESSION_TRANSPOSE", PROFESSION_transpose, 0 }, // λλ +// { "PROFESSION_ALCHEMY", PROFESSION_alchemy, 0 }, // + +// ʿ + { "PROFESSION_CHAIN_ATK", PROFESSION_chain_atk, 0 }, // + { "PROFESSION_AVOID", PROFESSION_avoid, 0 }, // ر + { "PROFESSION_WEAPON_FOCUS", PROFESSION_weapon_focus, 0 }, // ר + { "PROFESSION_REBACK", PROFESSION_reback, 0 }, // ״̬ظ + { "PROFESSION_BRUST", PROFESSION_brust, 0 }, // + { "PROFESSION_CHAIN_ATK_2", PROFESSION_chain_atk_2, 0 }, // ˫ع + { "PROFESSION_SCAPEGOAT", PROFESSION_scapegoat, 0 }, // Ϊ + { "PROFESSION_ENRAGE", PROFESSION_enrage, 0 }, // + { "PROFESSION_ENERGY_COLLECT", PROFESSION_energy_collect, 0 }, // ۼ + { "PROFESSION_FOCUS", PROFESSION_focus, 0 }, // רעս + { "PROFESSION_SHIELD_ATTACK", PROFESSION_shield_attack, 0 }, // ܻ + { "PROFESSION_DUAL_WEAPON", PROFESSION_dual_weapon, 0 }, // + { "PROFESSION_DEFLECT", PROFESSION_deflect, 0 }, // + { "PROFESSION_THROUGH_ATTACK", PROFESSION_through_attack, 0 }, // ᴩ + { "PROFESSION_CAVALRY", PROFESSION_cavalry, 0 }, // ﹥ + { "PROFESSION_DEAD_ATTACK", PROFESSION_dead_attack, 0 }, // + { "PROFESSION_CONVOLUTE", PROFESSION_convolute, 0 }, // + { "PROFESSION_CHAOS", PROFESSION_chaos, 0 }, // ҹ + +// + { "PROFESSION_TRACK", PROFESSION_track, 0 }, // ׷Ѱ + { "PROFESSION_ESCAPE", PROFESSION_escape, 0 }, // رս + { "PROFESSION_DOCILE", PROFESSION_docile, 0 }, // ѱ + { "PROFESSION_TRAP", PROFESSION_trap, 0 }, // + { "PROFESSION_ENRAGE_PET", PROFESSION_enrage_pet, 0 }, // ŭ + { "PROFESSION_DRAGNET", PROFESSION_dragnet, 0 }, // ޵ + { "PROFESSION_ENTWINE", PROFESSION_entwine, 0 }, // + { "PROFESSION_AUTARKY", PROFESSION_autarky, 0 }, // Ը + { "PROFESSION_PLUNDER", PROFESSION_plunder, 0 }, // Ӷ + { "PROFESSION_TOXIN_WEAPON", PROFESSION_toxin_weapon, 0 }, // + { "PROFESSION_RESIST_FIRE", PROFESSION_resist_fire, 0 }, // + { "PROFESSION_RESIST_ICE", PROFESSION_resist_ice, 0 }, // + { "PROFESSION_RESIST_THUNDER", PROFESSION_resist_thunder, 0 }, // ׿ +#ifdef _PROFESSION_ADDSKILL + { "PROFESSION_RESIST_F_I_T", PROFESSION_resist_f_i_t, 0 }, // Ȼ + { "PROFESSION_CALL_NATURE", PROFESSION_call_nature, 0 }, // Ȼ + { "PROFESSION_BOUNDARY", PROFESSION_boundary, 0 }, // Խ +#endif + { "PROFESSION_G_RESIST_FIRE", PROFESSION_g_resist_fire, 0 }, // + { "PROFESSION_G_RESIST_ICE", PROFESSION_g_resist_ice, 0 }, // + { "PROFESSION_G_RESIST_THUNDER",PROFESSION_g_resist_thunder,0 }, // ׿ + { "PROFESSION_ATTACK_WEAK", PROFESSION_attack_weak, 0 }, // 㹥 + { "PROFESSION_INSTIGATE", PROFESSION_instigate, 0 }, // + { "PROFESSION_OBLIVION", PROFESSION_oblivion, 0 }, // + +// ͬ + { "PROFESSION_FULL_MP", PROFESSION_full_mp, 0 }, // + { "PROFESSION_STRONG_BACK", PROFESSION_strong_back, 0 }, // + { "PROFESSION_STRENGTHEN", PROFESSION_strengthen, 0 }, // ǿ + +}; + + +static int profession_skill_num; // ְҵ + +// profession.txt +BOOL PROFESSION_initSkill( char *filename) +{ + + FILE* f; + char line[256]; + int linenum=-1; + int skill_readlen=0; + int i, j; + + int max_skillid = 0; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "file open error\n"); + return FALSE; + } + + profession_skill_num=0; + + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + char token[256]; + + linenum ++; + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + profession_skill_num++; +#ifdef _PROSKILL_OPTIMUM // Robin ȡְID + if( getStringFromIndexWithDelim( line, ",", + PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1, + token, sizeof(token)) == FALSE ) + continue; + max_skillid = max( atoi( token), max_skillid); +#endif + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Seek Error\n" ); + fclose(f); + return FALSE; + } + +#ifdef _PROSKILL_OPTIMUM // ְTableΪ ID +1 + profession_skill_num = max_skillid +1; + print("ְID = %d ...", max_skillid); +#endif + + PROFESSION_skill = allocateMemory( sizeof(struct tagProfessionkill) * profession_skill_num + 1 ); + + + if( PROFESSION_skill == NULL ){ + fprint( "޷ڴ %d\n", sizeof(struct tagProfessionkill)*profession_skill_num); + fclose( f ); + return FALSE; + } + + // init skill + for( i = 0; i < profession_skill_num; i ++ ) { + for( j = 0; j < PROFESSION_SKILL_DATAINTNUM; j ++ ) + PROFESSION_SKILL_setInt( i,j,-1); + + for( j = 0; j < PROFESSION_SKILL_DATACHARNUM; j ++ ) + PROFESSION_SKILL_setChar( i,j,""); + } + + linenum = -1; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + + chomp( line ); + + replaceString( line, '\t' , ' ' ); + + { + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + + if( i != 0 ) { + strcpy( line, buf); + } + } + { + char token[256]; + int ret; + +#ifdef _PROSKILL_OPTIMUM // ȡְID, ְֱIDTable index + ret = getStringFromIndexWithDelim( line, ",", PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1, token, sizeof(token)); + if( ret==FALSE ){ + fprint("Syntax Error file:%s line:%d\n",filename,linenum); + break; + } + skill_readlen = atoi( token); +#endif + for( i = 0; i < PROFESSION_SKILL_DATACHARNUM; i ++ ) { + + ret = getStringFromIndexWithDelim( line,",", i + 1, token,sizeof(token)); + if( ret==FALSE ){ + fprint("Syntax Error file:%s line:%d\n",filename,linenum); + break; + } + PROFESSION_SKILL_setChar( skill_readlen, i, token); + } + + for( i = 0; i < PROFESSION_SKILL_DATAINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line, ",", i+PROFESSION_SKILL_DATACHARNUM+1, token, sizeof(token)); + + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + if( strlen( token) != 0 ) { + PROFESSION_SKILL_setInt( skill_readlen, i , atoi( token )); + } + } + skill_readlen ++; + } + } + fclose(f); + + profession_skill_num = skill_readlen; + + for( i = 0; i < arraysizeof( PROFESSION_SKILL_functbl); i ++ ){ + PROFESSION_SKILL_functbl[i].hash = hashpjw( PROFESSION_SKILL_functbl[i].functionname ); + } + + return TRUE; + +} + + +// profession.txt +void rePROFESSION_initSkill() +{ + freeMemory( PROFESSION_skill ); + PROFESSION_initSkill(getProfession()); +} + +INLINE BOOL PROFESSION_SKILL_CHECKINDEX( int index ) +{ + if( profession_skill_num < index || index < 0 )return FALSE; + return TRUE; +} + +static INLINE BOOL PROFESSION_SKILL_CHECKINTDATAINDEX( int index) +{ + if( PROFESSION_SKILL_DATAINTNUM < index || index < 0 ) return FALSE; + return TRUE; +} + +static INLINE BOOL PROFESSION_SKILL_CHECKCHARDATAINDEX( int index) +{ + if( PROFESSION_SKILL_DATACHARNUM < index || index < 0 ) return FALSE; + return TRUE; +} + +INLINE int PROFESSION_SKILL_getInt( int index, PROFESSION_SKILL_DATAINT element) +{ + return PROFESSION_skill[index].data[element]; +} + +INLINE int PROFESSION_SKILL_setInt( int index, PROFESSION_SKILL_DATAINT element, int data) +{ + int buf; + buf = PROFESSION_skill[index].data[element]; + PROFESSION_skill[index].data[element]=data; + return buf; +} + +INLINE char* PROFESSION_SKILL_getChar( int index, PROFESSION_SKILL_DATACHAR element) +{ + if( !PROFESSION_SKILL_CHECKINDEX( index)) return "\0"; + if( !PROFESSION_SKILL_CHECKCHARDATAINDEX( element)) return "\0"; + return PROFESSION_skill[index].string[element].string; +} + +INLINE BOOL PROFESSION_SKILL_setChar( int index ,PROFESSION_SKILL_DATACHAR element, char* new ) +{ + if(!PROFESSION_SKILL_CHECKINDEX(index))return FALSE; + if(!PROFESSION_SKILL_CHECKCHARDATAINDEX(element))return FALSE; + + strcpysafe( PROFESSION_skill[index].string[element].string, + sizeof(PROFESSION_skill[index].string[element].string), + new ); + return TRUE; +} + +int PROFESSION_SKILL_getskillNum( void) +{ + return profession_skill_num; +} + + +/*----------------------------------------------------------------------*/ + +int PROFESSION_SKILL_getskillArray( int skillid) +{ +#ifdef _PROSKILL_OPTIMUM // ѯְIDΪʽ + if( skillid >= 0 && skillid < profession_skill_num ) + return PROFESSION_skill[skillid].data[PROFESSION_SKILL_ID]; +#else + int i; + for( i = 0; i <= profession_skill_num; i ++ ) { // Ż + if( PROFESSION_skill[i].data[PROFESSION_SKILL_ID] == skillid ) + return i; + } +#endif + return -1; +} + +PROFESSION_SKILL_CALLFUNC PROFESSION_SKILL_getskillFuncPointer(char* name ) +{ + int i; + int hash = hashpjw( name ); + + for( i = 0; i< arraysizeof( PROFESSION_SKILL_functbl); i++ ){ + if( PROFESSION_SKILL_functbl[i].hash == hash ){ + if( strcmp( PROFESSION_SKILL_functbl[i].functionname, name ) == 0 ){ + return PROFESSION_SKILL_functbl[i].func; + } + } + } + + return NULL; +} + +int _PROFESSION_SKILL_GetArray( char *file, int line, int charaindex, int skill ) +{ + int skillid,array; + + skillid = CHAR_getCharSkill( charaindex, skill); + + if( skillid < 0 ) return -1; + + array = PROFESSION_SKILL_getskillArray( skillid ); + + return array; +} + + +/*----------------------------------------------------------------------*/ + +// ʹְҵ +int PROFESSION_SKILL_Use( int charaindex, int skill, int toNo, char *data ) +{ + if( !CHAR_CHECKINDEX( charaindex ))return -1; +#ifdef _DISABLE_PROFESSION_SKILL + if(getDisableProfessionSkill(CHAR_getInt( charaindex, CHAR_FLOOR ))==TRUE){ + CHAR_talkToCli( charaindex, -1, "õͼѽֹʹְҵ!", CHAR_COLORYELLOW); + return -1; + } +#endif + int Pskillid, skillid; + int ret=-1, skill_level; + PROFESSION_SKILL_CALLFUNC func; + CHAR_HaveSkill* hskill; + int char_pskill, profession_skill; + + skillid = CHAR_getCharSkill( charaindex, skill); + Pskillid = PROFESSION_SKILL_getskillArray( skillid); + //print("\n skillid:%d Pskillid:%d ", skillid, Pskillid); // Robin log + if( Pskillid == -1 ) { +// printf("\n ķ??Ҳְ! "); + return ret; + } + +#ifdef _PROSKILL_OPTIMUM // Robin fix ְҵǷ + char_pskill = CHAR_getInt( charaindex, PROFESSION_CLASS ); + profession_skill = PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS); + if( (char_pskill <=0) || (char_pskill != profession_skill) ) { +// print("\n ķ??ְְҵȷ!:%d:%d ", char_pskill, profession_skill); + return ret; + } +#endif + + // ѰӦ function + func = PROFESSION_SKILL_getskillFuncPointer( PROFESSION_SKILL_getChar( Pskillid, PROFESSION_SKILL_FUNCNAME) ); + + // жǷΪ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) return ret; + + + if( func ){ + // \ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, skill ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + + // MP + if( PROFESSION_SKILL_DEC_COST_MP( charaindex, skill, Pskillid, skill_level ) != 1 ) { +// print("\n Error:ְMP:%d:%d:%d ", skill, Pskillid, skill_level); + return ret; + } + + // ʹְҵ + ret = func( charaindex, toNo, Pskillid, data, skill_level ); + if( ret == -1 ){ + int rands = rand()%10; + //andy_log +// print("ret = %d, rands:%d \n", ret, rands); + if( rands > 5 ) return ret; + } + + if( Pskillid == 57 //ŭ ѡоֵ + && CHAR_getInt( BATTLE_No2Index( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ), toNo ), CHAR_WHICHTYPE) != CHAR_TYPEPET ) + return ret; + + // һ㼼 + PROFESSION_NORMAL_SKILL_LEVLE_UP( &hskill->skill, Pskillid, charaindex ); + } + else { + print("\n !Ҳְfunc "); + } + + return ret; +} + +// ⼼ +void PROFESSION_SKILL_LVEVEL_UP( int charaindex, char *name ) +{ + int skill=-1; + int skillid=0, Pskillid=0, i; + char *skill_name="\0"; + CHAR_HaveSkill* hskill; + + for( i=0; i CHAR_SKILLMAXHAVE) ) return; + + skillid = CHAR_getCharSkill( charaindex, skill); + Pskillid = PROFESSION_SKILL_getskillArray( skillid); + if( Pskillid == -1 ) return; + + // \ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, skill ); + + // һ㼼 + PROFESSION_NORMAL_SKILL_LEVLE_UP( &hskill->skill, Pskillid, charaindex ); + + return; +} + +// +void PROFESSION_SKILL_DUAL_WEAPON_LVEVEL_UP( int charaindex, char *name ) +{ + int skill=-1, arm = 0, shield = 0; + int skillid=0, Pskillid=0, i; + char *skill_name="\0"; + CHAR_HaveSkill* hskill; + + // װ + for( i = 0 ; i < CHAR_EQUIPPLACENUM ; i ++ ){ + int id = CHAR_getItemIndex(charaindex,i); + if( ITEM_CHECKINDEX(id) ){ + if( i == CHAR_ARM ) arm = 1; + else if( i == CHAR_EQSHIELD ) shield = 1; + } + } + + if( arm != 1 || shield != 1 ) return; + + for( i=0; i CHAR_SKILLMAXHAVE) ) return; + + skillid = CHAR_getCharSkill( charaindex, skill); + Pskillid = PROFESSION_SKILL_getskillArray( skillid); + if( Pskillid == -1 ) return; + + // \ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, skill ); + + // һ㼼 + PROFESSION_NORMAL_SKILL_LEVLE_UP( &hskill->skill, Pskillid, charaindex ); + + return; +} + + +// ר +void PROFESSION_SKILL_WEAPON_FOCUS_LVEVEL_UP( int charaindex, char *name ) +{ + int skill = -1; + int skillid=0, Pskillid = 0, i; + char *skill_name="\0", *pszOption="\0", *pszP, diff[20]; + int WeaponType = -1; + CHAR_HaveSkill* hskill; + + memset( diff, -1, sizeof(diff) ); + // װ + WeaponType = BATTLE_GetWepon( charaindex ); + + switch( WeaponType ){ + case ITEM_AXE: + sprintf( diff, "" ); break; + case ITEM_CLUB: + sprintf( diff, "" ); break; + case ITEM_SPEAR: + sprintf( diff, "ǹ" ); break; + case ITEM_BOW: + sprintf( diff, "" ); break; + case ITEM_BOOMERANG: // + sprintf( diff, "" ); break; + case ITEM_BOUNDTHROW: // Ͷͷ + sprintf( diff, "Ͷ" ); break; + case ITEM_BREAKTHROW: // Ͷʯ + sprintf( diff, "ʯ" ); break; + default: + sprintf( diff, "" ); break; + } + + for( i=0; i CHAR_SKILLMAXHAVE) ) return; + + skillid = CHAR_getCharSkill( charaindex, skill); + Pskillid = PROFESSION_SKILL_getskillArray( skillid); + if( Pskillid == -1 ) return; + + // \ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, skill ); + + // һ㼼 + PROFESSION_NORMAL_SKILL_LEVLE_UP( &hskill->skill, Pskillid, charaindex ); + + return; +} + +// MP +int PROFESSION_SKILL_DEC_COST_MP( int charaindex, int skill, int Pskillid, int skill_level ) +{ + + if(skill_level > 0){ + int dec_mp; + int old_mp = CHAR_getInt( charaindex, CHAR_MP ); + int mp=0; + // ȡ MP + if( (dec_mp = PROFESSION_MAGIC_COST_MP( charaindex, skill )) == -1 ) + dec_mp = PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_COST_MP ); + // MP + if( old_mp < dec_mp ) return -1; + // Ѫ + if( Pskillid != 11 +#ifdef _PROFESSION_ADDSKILL + // && Pskillid != 2 //Բ MP +#endif + ) + if( dec_mp <= 0 ) return -1; + // ۵ MP + mp = old_mp - dec_mp; + if( mp < 0 ) mp = 0; + CHAR_setInt( charaindex , CHAR_MP , mp ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_MP); + return 1; + } + return -1; +} + + + +// һ㼼 +void PROFESSION_NORMAL_SKILL_LEVLE_UP(Skill *skill, int Pskillid, int charaindex ) +{ + int skill_level = 0, up_fix_value = 0; + int rand_num = RAND( 0, 10000 ), rand_num2 = 0; + + // ܵȼ޲ + skill_level = SKILL_getRealInt( skill, SKILL_LEVEL); + if( skill_level >= PROFESSION_SKILL_MAX_LEVEL * 100 ) return; + + // ֵ + up_fix_value = PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_FIX_VALUE) * 100; + rand_num2 = RAND( 0, up_fix_value); + + // 춨 + if( rand_num > skill_level + rand_num2){ + // + skill_level += PROFESSION_SKILL_ADD_POINT; + SKILL_setInt( skill, SKILL_LEVEL, skill_level ); + + if( ( skill_level % 100 ) == 0 ){ + char msg[256]; + sprintf( msg, "%sΪ%d", PROFESSION_SKILL_getChar( Pskillid, PROFESSION_SKILL_NAME), skill_level/100 ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + CHAR_sendStatusString( charaindex , "S"); + + + // ְҵֵ + PROFESSION_LEVEL_CHECK_UP( charaindex ); + } + } + return; +} + + +void PROFESSION_LEVEL_CHECK_UP( int charaindex ) +{ + int skill_level_add = 0, skill_level_sum = 0, i = 0; + int old_level = CHAR_getInt( charaindex, PROFESSION_LEVEL ); + int next_level_need_point = 9999999; + CHAR_HaveSkill* hskill; + + // һְҵ + next_level_need_point = old_level * 70 * 100; + + for( i=0; iskill, SKILL_IDENTITY); + if( skillID <= 0 ) continue; + + // ͨ 50 + if( (skillID == 63) || (skillID == 64) || (skillID == 65) ){ + skill_level_add = 50*100; + }else{ + skill_level_add = SKILL_getRealInt( &hskill->skill, SKILL_LEVEL); + } + + skill_level_sum += skill_level_add; + } + +// print("\n ==> ǰȵ(%d) һ(%d)", skill_level_sum, next_level_need_point ); + + // ȴﵽһְҵʱְҵȼ + if( skill_level_sum >= next_level_need_point ){ + int old_skill_point = CHAR_getInt( charaindex, PROFESSION_SKILL_POINT ); + int next_skill_point = old_skill_point+1; + char msg[64]; + +// print("\nְҵȼ ==> ǰְҵȼ(%d) һְҵȼ(%d)", old_skill_point, next_skill_point ); + + CHAR_setInt( charaindex, PROFESSION_LEVEL, old_level + 1 ); + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, next_skill_point ); + CHAR_sendStatusString( charaindex , "P"); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + + sprintf( msg, "ְҵȼΪ%dܵ", old_level + 1 ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + } +} + +// Ӽ +int PROFESSION_SKILL_ADDSK( int charaindex, int skill, int level ) +{ + int i; + + CHAR_HaveSkill *pSkil; + + if( level > 100 ) level = 100; + else if( level < 1 ) level = 1; + + for( i = 0; i < CHAR_SKILLMAXHAVE; i ++ ){ + int skill_id = -1; + + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + skill_id = SKILL_getInt( &pSkil->skill, SKILL_IDENTITY); + if( skill == skill_id && skill_id != -1 ){ + CHAR_talkToCli(charaindex,-1, "Ѿѧϰ˼", CHAR_COLORYELLOW); + return -1; + } + + if( pSkil == (CHAR_HaveSkill*)NULL )continue; + if( pSkil->use != 0 )continue; + break; + } + if( i >= CHAR_SKILLMAXHAVE ){ + CHAR_talkToCli(charaindex,-1, "Ѵ", CHAR_COLORYELLOW); + return -1; + }else{ + level *= 100; + SKILL_makeSkillData( &pSkil->skill, skill, level); + pSkil->use = TRUE; + } + + CHAR_sendStatusString( charaindex , "S"); + + + return 1; +} + +void profession_common_fun( int charaindex, int toNo, int skill_level, int array, int com1 ) +{ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, com1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + CHAR_SETWORKINT_HIGH( charaindex, CHAR_WORKBATTLECOM3, skill_level); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, array); +#ifdef _PROFESSION_ADDSKILL + if( com1 == BATTLE_COM_S_DOOM + /*&& CHAR_getWorkInt( charaindex, CHAR_DOOMTIME) == 0*/ ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORK_com1, com1 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_toNo, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORK_mode, BATTLE_CHARMODE_C_OK ); + CHAR_setWorkInt( charaindex, CHAR_WORK_skill_level, skill_level ); + CHAR_setWorkInt( charaindex, CHAR_WORK_array, array ); + CHAR_setWorkInt( charaindex, CHAR_DOOMTIME, 3); + } + else if( com1 == BATTLE_COM_S_FIRE_SPEAR + /*&& CHAR_getWorkInt( charaindex, CHAR_DOOMTIME) == 0*/ ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + CHAR_setWorkInt( charaindex, CHAR_WORK_com1, com1 ); + CHAR_setWorkInt( charaindex, CHAR_WORK_toNo, toNo ); + CHAR_setWorkInt( charaindex, CHAR_WORK_mode, BATTLE_CHARMODE_C_OK ); + CHAR_setWorkInt( charaindex, CHAR_WORK_skill_level, skill_level ); + CHAR_setWorkInt( charaindex, CHAR_WORK_array, array ); + CHAR_setWorkInt( charaindex, CHAR_DOOMTIME, 2); + } +#endif +} + +/*----------------------------------------------------------------------*/ +// Ϊְҵ + +// ʦ-ɽȪ +int PROFESSION_volcano_springs( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_VOLCANO_SPRINGS ); + return TRUE; +} + +// ʦ- +int PROFESSION_fire_ball( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo<21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_FIRE_BALL ); + return TRUE; +} + +// ʦ-ǹ +int PROFESSION_fire_spear( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_FIRE_SPEAR ); + return TRUE; +} + +// ʦ- +int PROFESSION_summon_thunder( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_SUMMON_THUNDER ); + return TRUE; +} + +// ʦ- +int PROFESSION_current( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CURRENT ); + return TRUE; +} + +// ʦ- +int PROFESSION_storm( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_STORM ); + return TRUE; +} + +// ʦ- +int PROFESSION_ice_arrow( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ICE_ARROW ); + return TRUE; +} + +// ʦ- +int PROFESSION_ice_crack( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ICE_CRACK ); + return TRUE; +} + +// ʦ- +int PROFESSION_ice_mirror( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ICE_MIRROR ); + return TRUE; +} + +// ʦ-ĩ +int PROFESSION_doom( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_DOOM ); + return TRUE; +} + +// ʦ-Ѫ +int PROFESSION_blood( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_BLOOD ); + return TRUE; +} + +// ʦ-Ѫ +int PROFESSION_blood_worms( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_BLOOD_WORMS ); + return TRUE; +} + +// ʦ-һѪ +int PROFESSION_sign( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_SIGN ); + return TRUE; +} + +// ʦ- +int PROFESSION_fire_enclose( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_FIRE_ENCLOSE ); + return TRUE; +} + +// ʦ- +int PROFESSION_ice_eclose( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ICE_ENCLOSE ); + return TRUE; +} + +// ʦ-׸ +int PROFESSION_thunder_enclose( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_THUNDER_ENCLOSE ); + return TRUE; +} + +// ʦ-ħ +int PROFESSION_fire_practice( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ʦ-ħ +int PROFESSION_ice_practice( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ʦ-ħ +int PROFESSION_thunder_practice( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ʦ- +int PROFESSION_enclose( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ENCLOSE ); + return TRUE; +} + +// ʦ-λλ +int PROFESSION_transpose( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_TRANSPOSE ); + return TRUE; +} + + +/*----------------------------------------------------------------------*/ + +// ʿ- +int PROFESSION_brust( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_BRUST ); + return TRUE; +} + +// ʿ- +int PROFESSION_chain_atk( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CHAIN_ATK ); + return TRUE; +} + +// ʿ-ر +int PROFESSION_avoid( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_AVOID ); + return TRUE; +} + +// ʿ-Ѫ +int PROFESSION_recovery( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_RECOVERY ); + return TRUE; +} + +// ʿ-ר +int PROFESSION_weapon_focus( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ʿ-״̬ظ +int PROFESSION_reback( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_REBACK ); + return TRUE; +} + +// ʿ-˫ع +int PROFESSION_chain_atk_2( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CHAIN_ATK_2 ); + return TRUE; +} + +// ʿ-Ϊ +int PROFESSION_scapegoat( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_SCAPEGOAT ); + return TRUE; +} + +// ʿ- +int PROFESSION_enrage( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ENRAGE ); + return TRUE; +} + +// ʿ-ۼ +int PROFESSION_energy_collect( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_COLLECT ); + return TRUE; +} + +// ʿ-רעս +int PROFESSION_focus( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_FOCUS ); + return TRUE; +} + +// ʿ-ܻ +int PROFESSION_shield_attack( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_SHIELD_ATTACK ); + return TRUE; +} + +// ʿ- +int PROFESSION_dual_weapon( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ʿ- +int PROFESSION_deflect( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_DEFLECT ); + return TRUE; +} + +// ʿ-ᴩ +int PROFESSION_through_attack( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_THROUGH_ATTACK ); + return TRUE; +} + +// ʿ-﹥ +int PROFESSION_cavalry( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CAVALRY ); + return TRUE; +} + +// ʿ- +int PROFESSION_dead_attack( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_DEAD_ATTACK ); + return TRUE; +} + +// ʿ- +int PROFESSION_convolute( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo<21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CONVOLUTE ); + return TRUE; +} + +// ʿ-ҹ +int PROFESSION_chaos( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CHAOS ); + return TRUE; +} + +/*----------------------------------------------------------------------*/ + +// ˼- +int PROFESSION_trap( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_TRAP ); + return TRUE; +} + +// ˼-ѱ +int PROFESSION_docile( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_DOCILE ); + return TRUE; +} + +// ˼-ŭ +int PROFESSION_enrage_pet( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ENRAGE_PET ); + return TRUE; +} + +// ˼-޵ +int PROFESSION_dragnet( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_DRAGNET ); + return TRUE; +} + +// ˼- +int PROFESSION_entwine( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ENTWINE ); + return TRUE; +} + +// ˼-Ը +int PROFESSION_autarky( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +// ˼-Ӷ +int PROFESSION_plunder( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_PLUNDER ); + return TRUE; +} + +// ˼- +int PROFESSION_toxin_weapon( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_TOXIN_WEAPON ); + return TRUE; +} + +// ˼- +int PROFESSION_resist_fire( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_RESIST_FIRE ); + return TRUE; +} + +// ˼- +int PROFESSION_resist_ice( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_RESIST_ICE ); + return TRUE; +} + +// ˼-׿ +int PROFESSION_resist_thunder( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_RESIST_THUNDER ); + return TRUE; +} + +#ifdef _PROFESSION_ADDSKILL +// ˼-Ȼ +int PROFESSION_resist_f_i_t( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_RESIST_F_I_T ); + return TRUE; +} +// ˼-Ȼ +int PROFESSION_call_nature( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_CALL_NATURE ); + return TRUE; +} +// ˼-Խ +int PROFESSION_boundary( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_BOUNDARY ); + return TRUE; +} +#endif + +// ˼- +int PROFESSION_g_resist_fire( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_G_RESIST_FIRE ); + return TRUE; +} + +// ˼- +int PROFESSION_g_resist_ice( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_G_RESIST_ICE ); + return TRUE; +} + +// ˼-׿ +int PROFESSION_g_resist_thunder( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo!=20 && toNo!=21) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_G_RESIST_THUNDER ); + return TRUE; +} + +// ˼-㹥 +int PROFESSION_attack_weak( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_ATTACK_WEAK ); + return TRUE; +} + +// ˼- +int PROFESSION_instigate( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_INSTIGATE ); + return TRUE; +} + +// ˼- +int PROFESSION_oblivion( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + if(toNo>19) + toNo=0; + profession_common_fun( charaindex, toNo, skill_level, array, BATTLE_COM_S_OBLIVION ); + return TRUE; +} + + +/*----------------------------------------------------------------------*/ +// ս + +// ˼-׷Ѱ +int PROFESSION_track( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + char *pszP = NULL, *pszOption = "\0", msg[20]; + int per=0, rate=0, img1, ret = 1; + skill_level /= 10; + + if( CHAR_getWorkInt( charaindex, CHAR_ENCOUNT_NUM) >= (int)time(NULL) ){ + ret = -1; + } + + // ܵIJ + pszOption = PROFESSION_SKILL_getChar( array, PROFESSION_SKILL_OPTION); + + // ܵȼ rate + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &rate ); + per = skill_level * rate; + + // ׼ڵĶ + img1 = PROFESSION_SKILL_getInt( array, PROFESSION_SKILL_IMG_1 ); + + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_FIX, per); + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORRED); + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_NUM, (int)time(NULL) + (60 * 3) ); + + sprintf( msg, "%d", img1); + lssproto_BATTLESKILL_send ( getfdFromCharaIndex(charaindex), msg ) ; + + return ret; +} + +// ˼-رս +int PROFESSION_escape( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + char *pszP = NULL, *pszOption = "\0", msg[20]; + int per=0, rate=0, img1, ret =1; + skill_level /= 10; + + if( CHAR_getWorkInt( charaindex, CHAR_ENCOUNT_NUM) >= (int)time(NULL) ){ + ret = -1; + } + + // ܵIJ + pszOption = PROFESSION_SKILL_getChar( array, PROFESSION_SKILL_OPTION); + + // ܵȼ rate + if( (pszP = strstr( pszOption, "%" ) ) != NULL ) sscanf( pszP+3, "%d", &rate ); + per = skill_level * rate; + + // ׼ڵĶ + img1 = PROFESSION_SKILL_getInt( array, PROFESSION_SKILL_IMG_1 ); + + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_FIX, (-1) * per); + CHAR_talkToCli( charaindex, -1, "½", CHAR_COLORGREEN); + + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_NUM, (int)time(NULL) + (60 * 3) ); + + sprintf( msg, "%d", img1); + lssproto_BATTLESKILL_send ( getfdFromCharaIndex(charaindex), msg ) ; + + return ret; +} + + + +// ͬ- +int PROFESSION_full_mp( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} +// ͬ- +int PROFESSION_strong_back( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} +// ͬ-ǿ +int PROFESSION_strengthen( int charaindex, int toNo, int array, char *data, int skill_level ) +{ + return TRUE; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/buf.c b/石器时代服务器端最新完整源代码/Serv/gmsv/buf.c new file mode 100644 index 0000000..6a81f8b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/buf.c @@ -0,0 +1,192 @@ +#define __BUF_C__ +#include "version.h" +#include +#include +#include + +#include "buf.h" +#include "handletime.h" + +static int UNIT; +static int UNITNUMBER; +static int memconfig; +static int readblock; +static int NowMemory; +static struct timeval AllocOldTime; + +typedef struct tagMemory +{ + char* pointer; + BOOL used; + + unsigned int nsize; +}Memory; +static Memory *mem; + + +void memEnd( void ) +{ + if( mem != NULL && mem[0].pointer != NULL ){ + free(mem[0].pointer); + free(mem); + } +} + +BOOL configmem( int unit , int unitnumber ) +{ + if( memconfig == TRUE ) + return FALSE; + UNIT = unit; + UNITNUMBER = unitnumber; + if( UNIT <= 0 || UNITNUMBER <= 0 ) + return memconfig = FALSE; + return memconfig = TRUE; +} + +BOOL memInit( void ) +{ + int i; + if( memconfig == FALSE ) + return FALSE; + mem = calloc( 1, sizeof( Memory ) * UNITNUMBER ); + if( mem == NULL ){ + print( "memInit: Can't alloc memory: %d\n" , + sizeof(Memory)*UNITNUMBER ); + return FALSE; + } + + memset( mem , 0 , sizeof( Memory )* UNITNUMBER ); + for( i = 0 ; i < UNITNUMBER ; i ++ ){ + mem[i].pointer = NULL; + mem[i].used = FALSE; + mem[i].nsize = 0; + } + mem[0].pointer = calloc( 1, UNIT*UNITNUMBER ); + if( mem[0].pointer == NULL ){ + print( "ɷ %d byte\n" , UNIT*UNITNUMBER ); + free( mem ); + return FALSE; + } + memset( mem[0].pointer , 0 , sizeof( UNIT*UNITNUMBER )); + print( "ڴѷ %.2f MB..." ,UNIT*UNITNUMBER/1024.0/1024.0); +#ifdef DEBUG + print( "Allocate %d byte( %.2fK byte %.2fM byte )\n" , + UNIT*UNITNUMBER, + UNIT*UNITNUMBER/1024.0, + UNIT*UNITNUMBER/1024.0/1024.0 + ); +#endif + readblock = 0; + for( i = 0 ; i < UNITNUMBER ; i ++ ) + mem[i].pointer = mem[0].pointer + i * UNIT; + + NowMemory = 0; + AllocOldTime.tv_sec = NowTime.tv_sec; + AllocOldTime.tv_usec = NowTime.tv_usec; + + return TRUE; +} + +void* allocateMemory( const unsigned int nbyte ) +{ + int i; + int arrayAllocSize; + BOOL flg = FALSE; + void *ret; + int first = 0; + + arrayAllocSize = nbyte/UNIT + ( nbyte%UNIT ? 1 : 0 ); + if( arrayAllocSize == 0 )return NULL; +#ifdef DEBUG + debug( arrayAllocSize , d ); + printf("(%.2f KB)\n",nbyte/1024.0); +#endif + i = readblock; + while( 1 ) { + if( i > UNITNUMBER - arrayAllocSize) { + i = 0; + } + if( mem[i].used != FALSE ){ + i += mem[i].nsize; + }else{ + int j; + BOOL found = TRUE; + for( j = i; j < i + arrayAllocSize; j ++ ) { + if( mem[j].used != FALSE ){ + i = j + mem[j].nsize; + found = FALSE; + if( first == 0 ) first = 1; + break; + } + } + if( found ) { + mem[i].used=TRUE; + mem[i].nsize = arrayAllocSize; + readblock = i + arrayAllocSize; + ret = mem[i].pointer; + break; + } + } + if( ( i >= readblock || i > UNITNUMBER - arrayAllocSize ) + && flg == TRUE ) { + ret = NULL; + break; + } + if( i > UNITNUMBER - arrayAllocSize) { + i = 0; + flg = TRUE; + } + + } + if( ret == NULL ) { + print( "Can't Allocate %d byte .remnants:%4.2f\n" , nbyte, (float)(NowMemory/UNITNUMBER)); + }else { + NowMemory += arrayAllocSize; + + if( NowTime.tv_sec > AllocOldTime.tv_sec +10 ) { + print( "\n"); + if( NowMemory > (double)UNITNUMBER * 0.9) { + print( "Warning!! Memory use rate exceeded 90%% .remnants:%d\n", UNITNUMBER-NowMemory); + }else if( NowMemory > (double)UNITNUMBER * 0.8) { + print( "Warning!! Memory use rate exceeded 80%% .remnants:%d\n", UNITNUMBER-NowMemory); + }else if( NowMemory > (double)UNITNUMBER * 0.7) { + print( "Memory use rate exceeded 70%% .remnants:%d\n", UNITNUMBER-NowMemory); + } + memcpy( &AllocOldTime, &NowTime, sizeof( AllocOldTime)); + } + //print( "NowMemory.remnants:%4.2f\n", (float)(UNITNUMBER-NowMemory)/UNITNUMBER); + } + + return ret; +} + + + +/*------------------------------------------------------------ + * ¦ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void freeMemory( void* freepointer ) +{ + int arrayindex; + char* toppointer; + toppointer = mem[0].pointer; + if( freepointer == NULL )return; + arrayindex = ((int)freepointer-(int)toppointer)/UNIT; + if( arrayindex < readblock) { + readblock = arrayindex; + } + mem[arrayindex].used = FALSE; + + NowMemory -= mem[arrayindex].nsize; + +} + +void showMem( char *buf) +{ + sprintf( buf, "NowMemory.remnants:%d%%", ((UNITNUMBER-NowMemory)*100)/UNITNUMBER); + printf( "\n" ); + printf( buf ); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/callfromac.c b/石器时代服务器端最新完整源代码/Serv/gmsv/callfromac.c new file mode 100644 index 0000000..e1ba1a8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/callfromac.c @@ -0,0 +1,1820 @@ +#include +#include "version.h" +#include "common.h" +#include "saacproto_cli.h" +#include "lssproto_serv.h" +#include "net.h" +#include "char.h" +#include "object.h" +#include "readmap.h" +#include "msignal.h" +#include "map_deal.h" +#include "npc_duelranking.h" +#include "npc_warpman.h" +#include "handletime.h" +#include "npc_scheduleman.h" +#include "configfile.h" +#include "chatroom.h" +#include "npc_eventaction.h" +// CoolFish: Family 2001/5/24 +#include "family.h" +#include "log.h" +#include "buf.h" +#include "enemy.h" +#include "battle.h" +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +#include "npc_alldoman.h" +#endif +#include "longzoro.h" + +time_t initTime =0; + +extern BOOL bNewServer; +extern int i_shutdown_time;//ttom + +#ifdef _ANGEL_SUMMON +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif + +void saacproto_ACGmsvDownRequest_recv( int fd, int min) +{ + char buff[32]; + int i; + int playernum = CHAR_getPlayerMaxNum(); + + snprintf( buff, sizeof( buff),"%s档",getGameservername()); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, buff, CHAR_COLORYELLOW); + } + } + SERVSTATE_setLimittime(min); + SERVSTATE_setShutdown( NowTime.tv_sec ); + SERVSTATE_setDsptime( 0 ); + +} +//Ƿкac,Լ +void saacproto_ACServerLogin_recv (int fd, char* result,char* data) +{ +#ifdef _OTHER_SAAC_LINK + if(CONNECT_getCtype(fd) == SQL ){ + if( strcmp( result , SUCCESSFUL ) != 0 ){ + print( "ʧ!!!\n", result,data ); + CONNECT_endOne_debug( fd ); + osfd = -1; + return; + } + + print( "ӳɹ!!!\n", result,data ); + }else if(CONNECT_getCtype(fd) ==AC ) +#endif +{ + + if( strcmp( result , SUCCESSFUL ) != 0 ){ + print( "ACʧ!˳...[%s][%s]\n", result,data ); + shutdownProgram( ); + exit(1); + } + print("ACӳɹ\n"); + time(&initTime); + +#ifdef _SERVER_NUMS + print(" !\n"); +#endif + + print( "˰汾: <%s>\n" , SERVER_VERSION); + print( "ҳhttp://www.allblues.com.cn\n" ); + print( "̳http://www.allblues.com.cn\n" ); + print( "ע: AllBlue'sڴ˵.ǷѷˡϽҵ;\n" ); + // Robin 0530 + //saacproto_ACShowFMList_send( acfd ); + print("ʼ..."); + FAMILY_Init(); + print("\n"); +#ifdef _ANGEL_SUMMON + print("ʼٻ..."); + saacproto_ACMissionTable_send( acfd, -1, 1, "", ""); + print("\n"); +#endif +} + +} + +void saacproto_ACCharList_recv(int fd, char* result, char* data,int retfd) +{ + int clifd = getfdFromFdid(retfd); + + if( CONNECT_checkfd(clifd) == FALSE ) + return; +#ifdef _ALLBLUES_LUA_1_9 +#ifdef _NEWCLISETMAC + if(FreeLoginCheck( clifd )== 0){ + //lssproto_CharList_send( clifd, FAILED, "Ϸ˺ŵ½ޣ벻ҪϷ" ); + return; + } +#endif +#endif + + lssproto_CharList_send( clifd, result , data ); + CONNECT_setState( clifd, NOTLOGIN ); +} + +void saacproto_ACCharLoad_recv(int fd , char* result,char* data,int retfd,int saveindex) +{ + int clifd = getfdFromFdid(retfd); + if( CONNECT_checkfd( clifd ) == FALSE )return; + if(( strcmp( result , SUCCESSFUL ) == 0 )&&(data[0])) { + CHAR_login( clifd,data,saveindex ); + }else{ + char cdkey[64]; +#ifndef _FIX_MESSAGE // WON ADD ޸WORKER + data = ""; +#endif + CONNECT_getCdkey( clifd, cdkey , sizeof( cdkey )); + print(" (%s)ACCharLoad:%s ", cdkey, data); + lssproto_CharLogin_send( clifd, result ,data ); + CONNECT_setState( clifd, NOTLOGIN ); + } +} + +void saacproto_ACCharSave_recv(int fd ,char* result, char* data,int retfd) +{ + int clifd = getfdFromFdid(retfd) , fdid; + char cdkey[CDKEYLEN], passwd[PASSWDLEN], charname[CHARNAMELEN]; + + if( CONNECT_checkfd( clifd )== FALSE ) return; + + CONNECT_getCdkey( clifd, cdkey, sizeof( cdkey )); + CONNECT_getPasswd( clifd, passwd, sizeof( passwd)); + + CONNECT_getCharname( clifd, charname, sizeof( charname )); + fdid = CONNECT_getFdid( clifd ); + switch( CONNECT_getState( clifd ) ){ + case WHILECREATE: + /* ľëͷʧе( )*/ + if( strcmp(result,FAILED) ==0 ) data =""; + lssproto_CreateNewChar_send( clifd , result , data); + CONNECT_setState( clifd, NOTLOGIN ); + break; + + case WHILELOGOUTSAVE: + if( strcmp( result , SUCCESSFUL ) == 0 ) + lssproto_CharLogout_send( clifd, result , "success" ); + else + /* ޷¡֧ */ + lssproto_CharLogout_send( clifd, result , "Cannot save" ); + CONNECT_setState( clifd, NOTLOGIN ); + CONNECT_setCharaindex( clifd, -1 ); + //CONNECT_setCloseRequest( clifd , 1 ); + break; + + case WHILELOSTCHARSAVE: + saacproto_ACCharDelete_send( acfd, cdkey,passwd,charname,"",fdid ); + CONNECT_setState( clifd, WHILELOSTCHARDELETE ); + CONNECT_setCharaindex( clifd, -1 ); + //CONNECT_setCloseRequest( clifd , 1 ); + break; + + case WHILECLOSEALLSOCKETSSAVE: + CONNECT_setState( clifd, NOTLOGIN ); + // Arminius debug + // CONNECT_endOne_debug(clifd); + CONNECT_setUse( clifd , FALSE); + + SERVSTATE_decrementCloseallsocketnum(); + if( SERVSTATE_getCloseallsocketnum() == 0 ) { + SERVSTATE_SetAcceptMore( -1 ); + print( "浵\n" ); + print("\n رշʱ =%d",i_shutdown_time);//ttom + if(i_shutdown_time==1){ + system( "ر" ); + sigshutdown( 0 ); + } + } + default: + break; + } +} + + +void saacproto_ACCharDelete_recv(int fd,char* result,char* data,int retfd) +{ + int clifd = getfdFromFdid(retfd); + if( CONNECT_checkfd( clifd ) == FALSE )return; + + switch( CONNECT_getState(clifd) ){ + case WHILELOSTCHARDELETE: + /* ئ */ + CONNECT_setState(clifd, NOTLOGIN ); + CONNECT_setCharaindex( clifd, -1 ); + //CONNECT_setCloseRequest( clifd , 1 ); + break; + case WHILECHARDELETE: + /* ˪ */ + if( strcmp(result,FAILED) == 0)data=""; + lssproto_CharDelete_send( clifd, result , data ); + CONNECT_setState( clifd, NOTLOGIN ); + CONNECT_setCharaindex( clifd, -1 ); + //CONNECT_setCloseRequest( clifd , 1 ); + break; + default: + break; + } +} + +/* + */ +void saacproto_ACLock_recv(int fd , char* result, char* data ,int retfd) +{ + int clifd = getfdFromFdid(retfd); + char cdkey[CDKEYLEN]; + int cindex = getCharindexFromFdid(retfd); + + if( CONNECT_checkfd(clifd) == FALSE) return; + + // Arminius 7.25 GM unlock test + if (strncmp(data, "USRLOCKED", 9)==0) { + char buf[4096]; + sprintf(buf, "%s", &data[10]); + CHAR_talkToCli(cindex, -1, buf, CHAR_COLORYELLOW); + return; + } else if (strncmp(data, "USRUNLOCKED", 11)==0) { + CHAR_talkToCli(cindex, -1, "User not locked.", CHAR_COLORYELLOW); + return; + } else if (strncmp(data, "GMUNLOCKSUCCESS", 15)==0) { + CHAR_talkToCli(cindex, -1, "User unlock success", CHAR_COLORYELLOW); + return; + } else if (strncmp(data, "GMUNLOCKFAIL", 12)==0) { + CHAR_talkToCli(cindex, -1, "User unlock failed", CHAR_COLORYELLOW); + return; + } else if (strncmp(data, "GMUNLOCKALL", 11)==0) { + CHAR_talkToCli(cindex, -1, "Server unlocked", CHAR_COLORYELLOW); + return; + } + + CONNECT_getCdkey( clifd, cdkey , sizeof( cdkey )); + + switch( CONNECT_getState( clifd ) ){ + case WHILECANNOTLOGIN: + if( strcmp( result , SUCCESSFUL ) == 0 ){ + CONNECT_setState( clifd, NOTLOGIN ); + + }else{ + /* + * ëέ + */ + char mesg[128]; + snprintf( mesg ,sizeof( mesg ), "%s hasn't been locked" ,cdkey); + if( strcmp( data , mesg ) == 0 ){ + /* + */ + CONNECT_setState( clifd, NOTLOGIN ); + }else{ + /* + * պݩƷ + */ + saacproto_ACLock_send(fd, cdkey , + UNLOCK, CONNECT_getFdid( clifd) ); + } + } + + break; + default: + break; + } +} + +void saacproto_ACUCheck_recv( int fd , char *cd ) +{ + int conind; + int flag = 0; + conind = getfdFromCdkeyWithLogin( cd ); + flag = ( conind >= 0 ) ? 1 : 0; + saacproto_ACUCheck_send( fd , cd , flag ); +} + + +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBUpdateEntryInt_recv( int fd,char* result, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBUpdateEntryInt\n"); + return; + } +} +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBUpdateEntryString_recv( int fd,char* result, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBUpdateEntryString\n"); + return; + } +} + +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBGetEntryRank_recv( int fd,char* result,int rank,int count, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBGetEntryRank\n"); + return; + } + if( strcmp( table, DB_DUELPOINT) == 0 ) { + if( CHAR_getInt( OBJECT_getIndex( msgid2), CHAR_WHICHTYPE) == CHAR_TYPEDUELRANKING){ + NPC_Duelranking_CallMyRanking( count, msgid, msgid2); + }else { + NPC_GetDuelRank( rank, msgid, msgid2); + } + } +} + +void saacproto_DBDeleteEntryInt_recv( int fd,char* result, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBDeleteEntryInt\n"); + return; + } + +} +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBDeleteEntryString_recv( int fd,char* result, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBDeleteEntryString\n"); + return; + } + +} + + +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBGetEntryInt_recv( int fd,char* result,int value, + char* table,char* key,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBGetEntryInt\n"); + return; + } +} +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBGetEntryString_recv( int fd,char* result,char *value, + char* table,char* key,int msgid,int msgid2 ) +{ + char cdkey[32]; + char charaname[32]; + + if( strcmp( table, DB_ADDRESSBOOK) == 0 ){ + int mode = 1; + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + mode = 0; + } + makeStringFromEscaped( key); + if( !getStringFromIndexWithDelim( key, "_", 1, cdkey, sizeof( cdkey)) ){ + return; + } + if( !getStringFromIndexWithDelim( key, "_", 2, charaname, sizeof( charaname)) ){ + return; + } + ADDRESSBOOK_DispatchMessage( cdkey, charaname, value, mode); + }else { + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBGetEntryString\n"); + return; + } + } +} + +void saacproto_DBGetEntryByRank_recv( int fd,char* result,char* list, + char* table,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBGetEntryByRank\n"); + return; + } +} +/* --------------------------------------------- + * --------------------------------------------*/ +void saacproto_DBGetEntryByCount_recv( int fd,char* result,char* list, + char* table,int count_start,int msgid,int msgid2 ) +{ + if( strcmp( result, NET_STRING_FAILED) == 0 ) { + print( "failed: DBGetEntryByCount\n"); + return; + } + if( strcmp( table, DB_DUELPOINT) == 0 ) { + NPC_Duelranking_PrintRanking( list, count_start, msgid, msgid2); + } +} +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +void saacproto_UpdataStele_recv( int fd , char *token) +{ + NPC_AlldomanWriteStele( token ); +} +void saacproto_S_UpdataStele_recv( int i , char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ) +{ + print("\nSyu log յSingle=> %s , %s , %s , %s ",ocdkey , oname , ncdkey , nname); + NPC_Alldoman_S_WriteStele( ocdkey , oname , ncdkey , nname , title , level , trns , floor ) ; +} + +#endif +/* --------------------------------------------- + * ƤƽҵⰾԻ + * --------------------------------------------*/ +void saacproto_Broadcast_recv( int fd,char* id,char* charname,char *message ) +{ + + if( strstr( message, "online") == 0 || + strstr( message, "offline") == 0 || + strstr( message, "param") == 0 || + strstr( message, "chardelete") == 0 ){ + char buff[512]; + char escapebuf[1024]; + + snprintf( buff, sizeof( buff),"%s_%s", id, charname ); + makeEscapeString( buff, escapebuf, sizeof(escapebuf)); + + saacproto_DBGetEntryString_send( acfd, DB_ADDRESSBOOK, escapebuf, 0,0); + } + +} + +void saacproto_Message_recv( int fd,char* id_from,char* charname_from, + char* id_to,char* charname_to, + char* message,int option,int mesgid ) +{ + BOOL ret; + ret = ADDRESSBOOK_sendMessage_FromOther( id_from, charname_from, + id_to, charname_to, + message, option + ); + if( ret == TRUE) { + saacproto_MessageAck_send( acfd, id_to, charname_to, + "successful",mesgid); + } +} + +/* --------------------------------------------- + * CoolFish: Family 2001/5/9 + * --------------------------------------------*/ +void saacproto_ACAddFM_recv(int fd, char *result, int fmindex, int charfdid, + int index) +{ + int ret; + int clifd = getfdFromFdid(charfdid); +// print("ACAddFM_0\n"); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; +// print("ACAddFM_1 clifd:%d ret:%d fmindex:%d index:%d\n", +// clifd, ret, fmindex, index); + ACAddFM(clifd, ret, fmindex, index); +} +void saacproto_ACJoinFM_recv(int fd, char *result, int recv, int charfdid) +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACJoinFM(clifd, ret, recv); +} +void saacproto_ACLeaveFM_recv(int fd, char *result, int resultflag, int charfdid) +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACLeaveFM(clifd, ret, resultflag); + + print(" ACLeaveFM_%d ", ret ); +} +void saacproto_ACChangeFM_recv(int fd, char *result, int charfdid) +{ +} +void saacproto_ACDelFM_recv(int fd, char *result, int charfdid) +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + + ACDelFM(clifd, ret); + + print(" ACDelFM_%d ", ret); +} +void saacproto_ACShowFMList_recv(int fd, char *result, int fmnum, char *data) +{ + int ret; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACShowFMList(ret, fmnum, data); +} + +void saacproto_ACShowMemberList_recv(int fd, char *result, int index, int fmmemnum, + int fmacceptflag, int fmjoinnum, char *data +#ifdef _FAMILYBADGE_ + ,int badge +#endif + ) +{ + int ret; + // fmmemnum -1:޴ֵ, -2:޸ else:ʾ˼ + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACShowMemberList(ret, index, fmmemnum, fmacceptflag, fmjoinnum, data +#ifdef _FAMILYBADGE_ + ,badge +#endif + ); +} +void saacproto_ACFMDetail_recv(int fd, char *result, char *data, int charfdid) +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACFMDetail(ret, data, clifd ); +} +void saacproto_ACMemberJoinFM_recv(int fd, char *result, char *data, int charfdid) +{ + +} +void saacproto_ACMemberLeaveFM_recv(int fd, char *result, char *data, int charfdid) +{ + +} +#ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACFMCharLogin_recv(int fd, char *result, int index, int floor, + int fmdp, int joinflag, int fmsetupflag, int flag, int charindex, + int charfame, int charfdid +#ifdef _NEW_MANOR_LAW + ,int momentum +#endif + ) +#else +void saacproto_ACFMCharLogin_recv(int fd, char *result, int index, int floor, + int fmdp, int joinflag, int fmsetupflag, int flag, int charindex, + int charfdid) +#endif +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if (CONNECT_checkfd(clifd) == FALSE) return; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; +// print("Login fd:%d result:%s index:%d floor:%d fmdp:%d joinflag:%d setup:%d charfdid:%d\n", +// fd, result, index, floor, fmdp, joinflag, fmsetupflag, charfdid); +#ifdef _PERSONAL_FAME // Arminius: +// print("Login charfame:%d\n", charfame); + ACFMCharLogin(clifd, ret, index, floor, fmdp, joinflag, fmsetupflag, + flag, charindex, charfame + #ifdef _NEW_MANOR_LAW + ,momentum + #endif + ); +#else + ACFMCharLogin(clifd, ret, index, floor, fmdp, joinflag, fmsetupflag, + flag, charindex); +#endif +} +void saacproto_ACFMCharLogout_recv(int fd, char *result, int charfdid) +{ +} +void saacproto_ACFMReadMemo_recv(int fd, char *result, int index, int num, + int dataindex, char *data) +{ + int ret; + // index( WORK )num(ϱ35) + // dataindex(µ)data() + // עnum -1:޴ֵ, -2:޸ else:ʾ˼ + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACShowFMMemo(ret, index, num, dataindex, data); +} +void saacproto_ACFMWriteMemo_recv(int fd, char *result, int index) +{ +} +void saacproto_ACFMPointList_recv(int fd, char *result, char *data) +{ + int ret; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACShowPointList(ret, data); +} + + +void saacproto_ACSetFMPoint_recv(int fd, char *result, int r, int charfdid) +{ + int ret; + int clifd = getfdFromFdid(charfdid); + if( CONNECT_checkfd(clifd) == FALSE )return; + if (strcmp(result, SUCCESSFUL) == 0){ + ret = 1; + }else{ + ret = 0; + } + ACSetFMPoint(ret, r, clifd); + +} +void saacproto_ACFixFMPoint_recv(int fd, char *result, int r) +{ +} +void saacproto_ACFMAnnounce_recv(int fd, char *result, char *fmname, + int fmindex, int index, int kindflag, char *data, int color) +{ + int ret; + if (strcmp(result, SUCCESSFUL) == 0){ + ret = 1; + }else{ + ret = 0; + } + ACFMAnnounce(ret, fmname, fmindex, index, kindflag, data, color); +} +//#ifdef _NEW_MANOR_LAW +//extern void SortManorSchedule(); +//#endif +void saacproto_ACShowTopFMList_recv(int fd, char *result, int kindflag, int num, char *data) +{ + int ret; + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + ACShowDpTop(ret, num, data, kindflag); +//#ifdef _NEW_MANOR_LAW +// SortManorSchedule(); +//#endif +} +#ifdef _NEW_MANOR_LAW +extern struct FMS_DPTOP fmdptop; +#endif + +void saacproto_ACFixFMData_recv(int fd, char *result, int kindflag, char *data1, + char *data2, int charfdid) +{ + int ret; + int intdata; + int clifd = getfdFromFdid(charfdid); + if( CONNECT_checkfd(clifd) == FALSE )return; + int charaindex = CONNECT_getCharaindex( clifd ); + + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + if( !CHAR_CHECKINDEX(charaindex) ) return; + if( kindflag == FM_FIX_FMRULE ){ + CHAR_talkToCli( charaindex , -1, "ּ޸ģϣˣ", CHAR_COLORWHITE); + }else if( kindflag == FM_FIX_FMGOLD ) { + intdata = atoi( data1 ); + if( ret == 0 ) { + if( atoi(data1) > 0 ) { + CHAR_setInt( charaindex, CHAR_GOLD, CHAR_getInt( charaindex, CHAR_GOLD ) +atoi(data1) ); + } + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + return; + }else { + if( atoi(data1) < 0 ) { + CHAR_setInt( charaindex, CHAR_GOLD, CHAR_getInt( charaindex, CHAR_GOLD ) -atoi(data1) ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + } + LogStone( + atoi(data2), + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -intdata, + CHAR_getInt( charaindex, CHAR_GOLD ), + "FMBank()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ) + ); + } + }else if( kindflag == FM_FIX_FMLEADERCHANGE ){ + ACFMJob( clifd, ret, data1, data2 ); + } + // CoolFish: 2001/10/03 + else if (kindflag == FM_FIX_FMADV || kindflag == FM_FIX_FMFEED + || kindflag == FM_FIX_FMSYNTHESIZE || kindflag == FM_FIX_FMDEALFOOD) + { + char tmpbuf[1024], flag[128]; +#ifdef _NEW_MANOR_LAW + int i; +#endif + if (kindflag == FM_FIX_FMADV) strcpy(flag, "ADV"); + else if (kindflag == FM_FIX_FMFEED) strcpy(flag, "FEED"); + else if (kindflag == FM_FIX_FMSYNTHESIZE) strcpy(flag, "SYN"); + else if (kindflag == FM_FIX_FMDEALFOOD) strcpy(flag, "FOOD"); + sprintf(tmpbuf, "%s::%d %s %s", flag, + CHAR_getInt(charaindex, CHAR_FMINDEX), + CHAR_getChar(charaindex, CHAR_FMNAME), data1); + // print("ACFixFMData tmpbuf:%s\n", tmpbuf); + LogFMPOP(tmpbuf); +#ifdef _NEW_MANOR_LAW + for(i=0;i= FAMILY_MAXNUM ){ + print(" fmindex:%d if FALSE !!\n", fmindex); + return; + } + familyTax[ fmindex] = data; + sprintf( buf, "B|T|%d", data ); + lssproto_FM_send( clifd, buf ); + } + +} +void saacproto_ACFMClearPK_recv(int fd, char *result, char *fmname, int fmindex, + int index) +{ + int ret, i = 0; + + if (strcmp(result, SUCCESSFUL) == 0) ret = 1; + else ret = 0; + for (i = 0; i < MAX_SCHEDULEMAN * MAX_SCHEDULE; i++) + { + { + if (fmpks[i].flag == -1) continue; + if (fmpks[i].host_index == index + || fmpks[i].guest_index == index) + { + fmpks[i].host_index = -1; + strcpy(fmpks[i].host_name, ""); + fmpks[i].guest_index = -1; + strcpy(fmpks[i].guest_name, ""); + fmpks[i].prepare_time = -1; + fmpks[i].max_player = -1; + fmpks[i].win = -1; + fmpks[i].flag = -1; + } + } + } +} + +#ifdef _ACFMPK_LIST +void saacproto_ACSendFmPk_recv( int fd, int toindex, int flg) +{ + char buf[256]; + if( flg == 0){ + sprintf( buf, "ׯ԰ս¼ʧܣ"); + CHAR_talkToCli( toindex, -1, buf, CHAR_COLORRED); + }else{ + sprintf(buf,"%s սׯ԰ʸ",CHAR_getChar(toindex, CHAR_FMNAME)); + int i; + for(i=0;i FMPOINTNUM) ){ + print("\n err fm_pk_num(%d)", fm_pk_num ); + return; + } + // ʱ + if (getStringFromIndexWithDelim(data,"|",2,token,sizeof(token))) { + fmpks[fmpks_pos+1].dueltime=atoi(token); + } + // familyindex + if (getStringFromIndexWithDelim(data,"|",3,token,sizeof(token))) { + fmpks[fmpks_pos+1].host_index=atoi(token); + } + // + if (getStringFromIndexWithDelim(data,"|",4,token,sizeof(token))) { + strcpy(fmpks[fmpks_pos+1].host_name,makeStringFromEscaped(token)); + } + // Ͷ familyindex + if (getStringFromIndexWithDelim(data,"|",5,token,sizeof(token))) { + fmpks[fmpks_pos+1].guest_index=atoi(token); + } + // Ͷ + if (getStringFromIndexWithDelim(data,"|",6,token,sizeof(token))) { + strcpy(fmpks[fmpks_pos+1].guest_name,makeStringFromEscaped(token)); + } + // ׼ʱ + if (getStringFromIndexWithDelim(data,"|",7,token,sizeof(token))) { + fmpks[fmpks_pos+1].prepare_time=atoi(token); + } + // + if (getStringFromIndexWithDelim(data,"|",8,token,sizeof(token))) { + int maxnum = atoi( token); + if( maxnum < 50 ) maxnum = 50; + fmpks[fmpks_pos+1].max_player = maxnum; + } + // + if (getStringFromIndexWithDelim(data,"|",9,token,sizeof(token))) { + fmpks[fmpks_pos+1].flag=atoi(token); + } + if( fmpks[fmpks_pos+1].flag == FMPKS_FLAG_MANOR_OTHERPLANET ){ + // ս + if (getStringFromIndexWithDelim(data,"|",10,token,sizeof(token))) { + strcpy(fmpks[fmpks_pos+2].host_name,makeStringFromEscaped(token)); + strcpy(skip, makeStringFromEscaped(token)); + if (strcmp(getGameservername(), skip)==0) { + fmpks[fmpks_pos+1].flag=8; + }else if( fmpks[fmpks_pos+1].flag == 8) { + fmpks[fmpks_pos+1].flag=10; + } + } + }else{ + strcpy( fmpks[fmpks_pos+2].host_name, ""); + } +} +#endif + + +void saacproto_ACManorPKAck_recv(int fd, char *data) +{ + // server ׯ԰ pk scheduleman + int i; + char token[256], skip[256]; + int char_max=CHAR_getCharNum(); + + print("ACManorPKAck_recv: %s\n",data); + + for (i=0; iindexOfExistDepotItems = allocateMemory( sizeof( int ) * CHAR_MAXDEPOTITEMHAVE ); + if( ch->indexOfExistDepotItems == NULL ) return; + for( i=0; iindexOfExistDepotItems[i] = -1; + + if( CHAR_makeDepotItemStringToChar( charaindex, data) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ֿ߲϶ȡʧܣ", CHAR_COLORYELLOW); + CHAR_removeDepotItem( charaindex); + return; + } + if( !CHAR_CHECKINDEX( meindex) ) return; + if( clifd != -1 ) { + char message[1024]; + char buf[1024]; + strcpy( message, + "3\n\n" + " ʹõֿ߲\n\n" + " ŵߣ\n" + " ȡصߣ\n" + ); + lssproto_WN_send( clifd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + 311, //CHAR_WINDOWTYPE_DEPOTITEMSHOP_HANDLE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf)) ); + } +#endif +} + +#endif// + + +#ifdef _CHAR_POOLPET +void saacproto_ACCharSavePoolPet_recv(int fd ,char* result, char* data,int retfd) +{ + int charaindex = getCharindexFromFdid( retfd); + if( !CHAR_CHECKINDEX(charaindex) ) return; + if( strstr( result, FAILED ) != NULL ){ + CHAR_talkToCli( charaindex, -1, "ֿϴ浵ʧܣ", CHAR_COLORYELLOW); + return; + + } +} + +void saacproto_ACCharGetPoolPet_recv(int fd ,char* result, char* data,int retfd, int meindex) +{ +#ifdef _NPC_DEPOTPET + Char* ch = NULL; + int i, clifd, charaindex; + + if( strcmp( result , SUCCESSFUL ) != 0 ) return; + charaindex = getCharindexFromFdid(retfd); + if( !CHAR_CHECKINDEX( charaindex) ) return; + clifd = getfdFromCharaIndex( charaindex); + if( CHAR_CheckDepotPet( charaindex) ) return;//ֿѴ + + if( (ch = CHAR_getCharPointer( charaindex)) == NULL ) return; + ch->indexOfExistDepotPets = allocateMemory( sizeof( int ) * CHAR_MAXDEPOTPETHAVE ); + if( ch->indexOfExistDepotPets == NULL ) return; + for( i=0; iindexOfExistDepotPets[i] = -1; + + if( CHAR_makeDepotPetStringToChar( charaindex, data) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ֿ϶ȡʧܣ", CHAR_COLORYELLOW); + CHAR_removeDepotPet( charaindex); + return; + } + if( !CHAR_CHECKINDEX( meindex) ) return; + if( clifd != -1 ) { + char message[1024]; + char buf[1024]; + strcpy( message, + "3\n" + " ʹóֿ\n" + "رע⣺𽫹س빫ֿ\n" + "﹫ֿ⡻\n" + " ų\n" + " ȡس\n" + ); + lssproto_WN_send( clifd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_DEPOTPETSHOP_HANDLE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf)) ); + } +#endif +} + +#endif + +#ifdef _ANGEL_SUMMON +//void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, int charaindex) +void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, char* angelinfo) +{ + char msg[1024]; + + if( type == 1 ) { // get data list + //if( num == -1) // get all data + { + int di, ti; + char onedata[1024], token[1024]; + + if( num == -1 ) { + print("оٻ!!\n"); + memset( missiontable, 0, sizeof(missiontable)); + } + else + print("һ!!:%s\n", data); + + for( di =1; di = MAXMISSIONTABLE) continue; + getStringFromIndexWithDelim( onedata, "|", 2, token, sizeof(token)); + strcpy( missiontable[ti].angelinfo, token); + getStringFromIndexWithDelim( onedata, "|", 3, token, sizeof(token)); + strcpy( missiontable[ti].heroinfo, token); + getStringFromIndexWithDelim( onedata, "|", 4, token, sizeof(token)); + missiontable[ti].mission = atoi( token); + getStringFromIndexWithDelim( onedata, "|", 5, token, sizeof(token)); + missiontable[ti].flag = atoi( token); + getStringFromIndexWithDelim( onedata, "|", 6, token, sizeof(token)); + missiontable[ti].time = atoi( token); + getStringFromIndexWithDelim( onedata, "|", 7, token, sizeof(token)); + missiontable[ti].limittime = atoi( token); + } + } + } + else if( type == 2 ) { // add data return + int angelindex =-1, i, maxChar; + char nameinfo[128], msgbuf[1024]; + + if( num == -1) { + sprintf( msg, "\n"); + print( msg); + LogAngel( msg); + return; + } + + sprintf( msgbuf, "յACӦ(add data) num=%d nameinfo=%s ", num, angelinfo); + print( msgbuf); + LogAngel( msgbuf); + + maxChar = CHAR_getPlayerMaxNum(); + for( i =0; i = MAXMISSIONTABLE) return; + + sprintf( msg, " AC :%d %s %s ", num, missiontable[num].angelinfo, missiontable[num].heroinfo); + print( msg); + LogAngel( msg); + + strcpy( missiontable[num].angelinfo, ""); + strcpy( missiontable[num].heroinfo, ""); + missiontable[num].mission = 0; + missiontable[num].flag = 0; + missiontable[num].time = 0; + missiontable[num].limittime = 0; + + } + +} + +#endif + +#ifdef _TEACHER_SYSTEM +void saacproto_ACCheckCharacterOnLine_recv( int acfd, int charaindex, int iOnline,char *data,int flag) +{ + switch(flag){ + case R_F_TEACHER_SYSTEM: + CHAR_Teacher_system_View(charaindex,iOnline,data); + break; + default:printf("saacproto_ACCheckCharacterOnLine_recv(): error flag type!!(%d)\n",flag); + } +} +#endif + +void saacproto_ACCharLogin_recv(int fd , int clifd, int flag) +{ + lssproto_ClientLogin_send( clifd , "ok" ); + if(flag==0){ + return; + }else if(flag==1){ + lssproto_CharList_send( clifd, FAILED, "˺Ż벻Ϊգ" ); + }else if(flag==2){ + lssproto_CharList_send( clifd, FAILED, "Ϸ˺ű޷½" ); + }else if(flag==3){ + lssproto_CharList_send( clifd, FAILED, "ϷIPѱ޷½" ); + }else if(flag==4){ + lssproto_CharList_send( clifd, FAILED, "Ϸ˺ŵ½ޣ벻ҪϷ" ); + }else if(flag==5){ + lssproto_CharList_send( clifd, FAILED, "˺δעᣬ½www.09sa.comעᣡ" ); + }else if(flag==6){ + lssproto_CharList_send( clifd, FAILED, "˺Ż" ); + } +} + +#ifdef _NEW_VIP_SHOP +void saacproto_QueryPoint_recv(int fd , int point) +{ + int charaindex = CONNECT_getCharaindex(fd); + char token[64]; + sprintf( token, "ĿǰĸػرΪ%d", point); + CHAR_talkToCli(charaindex, -1, token, CHAR_COLORYELLOW); +} + +void saacproto_NewVipShop_recv( int fd, int point, char* buf, int flag) +{ + int charaindex = CONNECT_getCharaindex(fd); + if(point == -1){ + CHAR_talkToCli( charaindex, -1, "ػرҲ㣡", CHAR_COLORYELLOW); + return; + } + if(strcmp(buf, "") == 0){ + CHAR_talkToCli( charaindex, -1, "ûиƷݣ", CHAR_COLORYELLOW); + return; + } + char token[256]; + if(flag==0){ + int itemID=-1,itemindex=-1; + char buff[256]; + int ret; + + if(getStringFromIndexWithDelim(buf , "," , 1, buff, sizeof(buff)) !=FALSE) + itemID = atoi(buf); + + itemindex = CHAR_findEmptyItemBox( charaindex ); + if( itemindex < 0 ) { + CHAR_talkToCli( charaindex, -1, "Ʒռ䲻㣡", CHAR_COLORYELLOW); + return; + } + + itemindex = ITEM_makeItemAndRegist( itemID ); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + if( itemindex != -1 ){ + ret = CHAR_addItemSpecificItemIndex( charaindex, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return; + } + + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_sendItemDataOne( charaindex, ret); + } + +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + "(ʣ)", + point, + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(charaindex, FALSE)){ + CHAR_talkToCli(charaindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + + }else{ + int ret; + char buf1[8]; + int enemynum; + int i,j; + int petindex, petindex2, petid; + + if(getStringFromIndexWithDelim(buf , "," , 1, buf1, sizeof(buf1)) ==FALSE)return; +#ifdef _PET_MM + if(strstr(buf1,"MM1") || strstr(buf1,"MM3")) + petid = 1479; + else if(strstr(buf1,"MM2") || strstr(buf1,"MM4")) + petid = 2547; + else + petid = atoi( buf1 ); +#else + petid = atoi( buf1 ); +#endif + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + //ǷPETABIֶ + if(strstr(buf1,"PETABI")){ + easyGetTokenFromString( buf , 2 , buf1, sizeof(buf1)); + petid = atoi(buf1); + } + } +#endif + + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( charaindex, i); + if( petindex == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ) { + snprintf( token,sizeof( token), ""); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == petid) { + break; + } + } + + if( i == enemynum ) + return; + + ret = ENEMY_createPetFromEnemyIndex( charaindex, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex, i ) == ret ) + break; + } + + if( i == CHAR_MAXPETHAVE ) + CHAR_talkToCli( charaindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ +#ifdef _PET_MM + if(strstr(buf1,"MM1") || strstr(buf1,"MM2")){ + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + }else if(strstr(buf1,"MM3") || strstr(buf1,"MM4")){ + while(CHAR_getInt( ret, CHAR_LV)<79){ // + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + } +#endif + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + if(strstr(buf,"PETABI")){ + int lv, trans, vital, str, tough, dex; + //ȡȼ + easyGetTokenFromString( buf , 3 , buf1, sizeof(buf1)); + lv=atoi(buf1); + //ȡת + easyGetTokenFromString( buf , 4 , buf1, sizeof(buf1)); + trans=atoi(buf1); + //ȡѪ + easyGetTokenFromString( buf , 5 , buf1, sizeof(buf1)); + vital=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 6 , buf1, sizeof(buf1)); + str=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 7 , buf1, sizeof(buf1)); + tough=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 8 , buf1, sizeof(buf1)); + dex=atoi(buf1); + + //õȼ + CHAR_setInt( ret, CHAR_LV, lv); + //ת + CHAR_setInt( ret, CHAR_TRANSMIGRATION, trans); + //Ѫ + CHAR_setInt( ret, CHAR_VITAL, vital*20); + //ù + CHAR_setInt( ret, CHAR_STR, str*80); + //÷ + CHAR_setInt( ret, CHAR_TOUGH, tough*80); + // + CHAR_setInt( ret, CHAR_DEX, dex*100); + //þ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + // + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + + } + } +#endif + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + + petindex2 = CHAR_getCharPet(charaindex, i); + if( !CHAR_CHECKINDEX( petindex2) ) + return; + snprintf( token,sizeof( token), "õ%s", CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(charaindex, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", j ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", j ); + CHAR_sendStatusString( charaindex, token ); + } + +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + "(ʣ)", + point, + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(charaindex, FALSE)){ + CHAR_talkToCli(charaindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + + } + + snprintf( token,sizeof( token), "ǰػرʣ %d", point); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); +} + +#endif + +#ifdef _ITEM_PET_LOCKED +void saacproto_ItemPetLocked_recv(int fd, int flag, char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); + if(flag == 1){ + CHAR_setInt(charaindex,CHAR_LOCKED, 0); + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORYELLOW); + }else if(flag == 0){ + char buf[256]; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED_PASSWD, + -1, + makeEscapeString( data, buf, sizeof(buf))); + }else if(flag == -1){ + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORRED); + } +} + +void saacproto_ItemPetLockedPasswd_recv(int fd, char *data) +{ + char buf[256]; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, + -1, + makeEscapeString( data, buf, sizeof(buf))); +} +#endif + +#ifdef _ONLINE_COST +void saacproto_OnlineCost_recv(int fd, char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); + +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + data, + 0, + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORGREEN); +} +#endif + +#ifdef _SQL_BUY_FUNC +void saacproto_OnlineBuy_recv(int fd, char *data) +{ + char buf[64]; + int charaindex = CONNECT_getCharaindex(fd); + char token[256]; + if(data[0]=='0'){ + int ret; + int enemynum; + int enemyid; + int i; + int vital,str,tough,dex; + getStringFromIndexWithDelim(data,"|", 2, buf, sizeof(buf)); + enemyid=atoi(buf); + getStringFromIndexWithDelim(data,"|", 3, buf, sizeof(buf)); + vital=atoi(buf); + getStringFromIndexWithDelim(data,"|", 4, buf, sizeof(buf)); + str=atoi(buf); + getStringFromIndexWithDelim(data,"|", 5, buf, sizeof(buf)); + tough=atoi(buf); + getStringFromIndexWithDelim(data,"|", 6, buf, sizeof(buf)); + dex=atoi(buf); + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ){ + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum ){ + CHAR_talkToCli( charaindex, -1, "˳ﲻڣ뱾Աϵ", CHAR_COLORGREEN); + return; + } + + ret = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( !CHAR_CHECKINDEX( ret)){ + CHAR_talkToCli( charaindex, -1, "ȡʧ", CHAR_COLORGREEN); + return; + } + snprintf( token,sizeof( token), "ȡ %s ",ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORGREEN); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE ){ + CHAR_talkToCli( charaindex, -1, "ij", CHAR_COLORGREEN); + return; + } + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + if(vital > 0) + CHAR_setInt( ret, CHAR_VITAL, vital); + if(str > 0) + CHAR_setInt( ret, CHAR_STR, str * 80); + if(tough > 0) + CHAR_setInt( ret, CHAR_TOUGH, tough * 80); + if(dex > 0) + CHAR_setInt( ret, CHAR_DEX, dex * 100); + + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret, CHAR_VARIABLEAI, 10000); + } + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_complianceParameter( ret ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); + + + }else if(data[0]=='1'){ + int emptyitemindexinchara, itemindex; + int itemid; + getStringFromIndexWithDelim(data,"|", 2, buf, sizeof(buf)); + itemid = atoi( buf); + emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + + if( emptyitemindexinchara < 0 ){ + CHAR_talkToCli( charaindex, -1, "Ʒ", CHAR_COLORYELLOW); + return; + } + + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex != -1 ){ + CHAR_setItemIndex( charaindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charaindex); + CHAR_sendItemDataOne( charaindex, emptyitemindexinchara); + + snprintf( token, sizeof( token), "ȡƷ %s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORGREEN); + }else{ + CHAR_talkToCli( charaindex, -1, "Ʒڣ뱾Աϵ", CHAR_COLORYELLOW); + } + + }else if(data[0]=='2'){ + getStringFromIndexWithDelim(data,"|", 2, buf, sizeof(buf)); + int gold = atoi(buf); + CHAR_setInt( charaindex , CHAR_GOLD , CHAR_getInt( charaindex , CHAR_GOLD ) + gold); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + sprintf( token, "ȡ %d ʯң", gold); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORGREEN ); + }else{ + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORGREEN); + } +} +#endif + +#ifdef _VIPPOINT_OLD_TO_NEW +void saacproto_OldToNew_recv(int fd, char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -CHAR_getInt( charaindex, CHAR_AMPOINT ), + 0, + "(ת)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + CHAR_setInt(charaindex, CHAR_AMPOINT, 0); + + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORGREEN); +} +#endif + +#ifdef _FORMULATE_AUTO_PK +void saacproto_FormulateAutoPk_recv(int fd, char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); + CHAR_setWorkInt(charaindex, CHAR_WORK_AUTOPK, 0); + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORGREEN); +} +#endif + +#ifdef _LOTTERY_SYSTEM +extern int todayaward[7]; +void saacproto_LotterySystem_recv( char *data) +{ + int i; + char token[256]; + for(i=0;i<7;i++){ + if(getStringFromIndexWithDelim(data,",",i+1,token,sizeof(token))==TRUE){ + todayaward[i]=atoi(token); + }else{ + todayaward[i]=-1; + } + } + struct tm now; + time_t timep; + time(&timep); + memcpy(&now, localtime(&timep), sizeof(now)); + + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + char token[256]; + sprintf(token, "%04d%02d%02dн%0d,%0d,%0d,%0d,%0d,%0d,%0d", now.tm_year+1900, + now.tm_mon+1, + now.tm_mday, + todayaward[0], + todayaward[1], + todayaward[2], + todayaward[3], + todayaward[4], + todayaward[5], + todayaward[6]); + + CHAR_talkToCli( i, -1, token, CHAR_COLORGREEN); + CHAR_talkToCli( i, -1, "нѵNPCϻҽƷ", CHAR_COLORGREEN); + } + } +} +#endif + +#ifdef _ALL_SERV_SEND +void saacproto_AllServSend_recv( char *data) +{ + int i; + int playernum = CHAR_getPlayerMaxNum(); + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, data, rand() % CHAR_COLORNUM); + } + } +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/callfromcli.c b/石器时代服务器端最新完整源代码/Serv/gmsv/callfromcli.c new file mode 100644 index 0000000..4ba7a0d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/callfromcli.c @@ -0,0 +1,3016 @@ +#include "version.h" +#include +#include +#include +#include "common.h" +#include "util.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "net.h" +#include "char.h" +#include "object.h" +#include "readmap.h" +#include "addressbook.h" +#include "handletime.h" +#include "configfile.h" +#include "event.h" +#include "pet.h" +#include "battle.h" +#include "battle_command.h" +#include "magic.h" +#include "petmail.h" +#include "item_gen.h" +#include "pet_skill.h" +#include "log.h" //add this because the second had it +#include "map_deal.h" // CoolFish: 2001/4/18 +#include "trade.h" // CoolFish: Trade 2001/4/18 +#include "family.h" // CoolFish: Family 2001/5/24 +#include "item_event.h" // shan: blackmarket +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#include "npc_healer.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +#include "chatroom.h" +#endif +#ifdef _ONLINE_SHOP +#include "longzoro/newshop.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +extern int player_online; +BOOL checkStringErr( char * ); + +// shan add +extern struct FM_PKFLOOR fmpkflnum[FAMILY_FMPKFLOOR]; + + +/* ----------------------------------------------------------------------- + * 򤷤ɸŪֹ椫饭饤ǥå + * ----------------------------------------------------------------------*/ +static int Callfromcli_Util_getTargetCharaindex( int fd, int toindex) +{ + int to_charaindex = -1; + int fd_charaindex = CONNECT_getCharaindex( fd ); + + /* ʬ */ + if( toindex == 0 ) { + to_charaindex = fd_charaindex; + } + /* ڥå 1 5 */ + else if( toindex > 0 && toindex < 6 ) { + to_charaindex = CHAR_getCharPet( fd_charaindex, toindex-1); + if( !CHAR_CHECKINDEX( to_charaindex)) { + to_charaindex = -1; + } + } + /* 6 10 */ + else if( toindex > 5 && toindex < 11 ) { + to_charaindex = CHAR_getPartyIndex( fd_charaindex, toindex - 6); + } + return to_charaindex; +} +/*---------------------------------------- + * 饤Ȥ󤹤 ǤίʤΤǥåϤʤ + * Ƥ֤ CLI ˤʤ롣 + ----------------------------------------*/ +void lssproto_ClientLogin_recv( int fd,char* cdkey, char* passwd, char* mac, int servid,char *Newip ) +{ + if(CONNECT_getState(fd) == NULLCONNECT){ + CONNECT_setState(fd, NOTLOGIN); + } + /* 2Ťˤ줬ƤФΤϤ */ + /* ѥѹ򤷤äƤӤƤֻ*/ + {//ttom avoid the restore 2001/01/09 + if(CONNECT_isNOTLOGIN(fd)==FALSE){ + print("\n the Client had Logined fd=%d",fd); + return; + } + } + + if( checkStringErr(cdkey) ) return; + if( checkStringErr(passwd) ) return; + //print( "CliLogin cdkey=%s\n" , cdkey ); + /* connect˥ԡ */ + CONNECT_setCdkey( fd, cdkey ); + CONNECT_setPasswd( fd, passwd ); + CONNECT_setCtype( fd, CLI ); + +#ifdef _NEWCLISETSERVID + CONNECT_setServid( fd, servid ); +#endif +#ifdef _NEWCLISETMAC + if( checkStringErr(mac) ){ + strcpy(mac, ""); + } + CONNECT_setMAC( fd , mac); +#endif + + unsigned long tmpip; + int a,b,c,d; + char ip[32]; + tmpip=CONNECT_get_userip(fd); + a=(tmpip % 0x100); tmpip=tmpip / 0x100; + b=(tmpip % 0x100); tmpip=tmpip / 0x100; + c=(tmpip % 0x100); tmpip=tmpip / 0x100; + d=(tmpip % 0x100); + sprintf(ip,"%d.%d.%d.%d",a,b,c,d); + // print( "\n½˺=%s =%s IP=%s MAC=%s SERVID=%d\n",cdkey,passwd,ip,mac,servid); +#ifdef _NO_FULLPLAYER_ATT + { + int res; + + if (strlen(cdkey)==0 || strlen(passwd)==0 || strlen(ip)==0){ + print("½Ϣд\n"); + lssproto_ClientLogin_send( fd , "no" ); + CONNECT_endOne_debug(fd); + return; + } + + res=sasql_query(cdkey,passwd); + // print("res=%d\n",res); + if (res==3){ + if(getNoCdkeyPlayer()>0 && fd-player_online>=getNoCdkeyPlayer() && getNoCdkeyMode()!=0){ + if(strcmp(ip,getNoAttIp(0))!=0 && strcmp(ip,getNoAttIp(1))!=0 && strcmp(ip,getNoAttIp(2))!=0 && strcmp(ip,getNoAttIp(3))!=0 && strcmp(ip,getNoAttIp(4))!=0){ + if(getNoCdkeyType()==0){ + //if(sasql_query_online_ip(ip)==0 && sasql_check_lockip(ip,getFengType())<1){ + if(sasql_query_online_ip(ip)==0){ + //if(sasql_add_lockip(ip,getFengType(),getServernumber(),2)==1){ + print("1\n"); + CONNECT_endOne_debug(fd); + return; + //} + } + }else{ + print("2\n"); + CONNECT_endOne_debug(fd); + return; + } + } + } + }else if (res!=1){ + if(getNoCdkeyPlayer()>0 && fd-player_online>=getNoCdkeyPlayer() && getNoCdkeyMode()==2){ + if(strcmp(ip,getNoAttIp(0))!=0 && strcmp(ip,getNoAttIp(1))!=0 && strcmp(ip,getNoAttIp(2))!=0 && strcmp(ip,getNoAttIp(3))!=0 && strcmp(ip,getNoAttIp(4))!=0){ + if(getNoCdkeyType()==0){ + //if(sasql_query_online_ip(ip)==0 && sasql_check_lockip(ip,getFengType())<1){ + if(sasql_query_online_ip(ip)==0){ + //if(sasql_add_lockip(ip,getFengType(),getServernumber(),2)==1){ + print("3\n"); + CONNECT_endOne_debug(fd); + return; + //} + } + }else{ + print("4\n"); + CONNECT_endOne_debug(fd); + return; + } + } + } + CONNECT_endOne_debug(fd); + return; + } + } +#endif +#ifdef _NEWCLISETMAC + saacproto_ACCharLogin_send( acfd, fd, cdkey, passwd, ip, mac); +#else + saacproto_ACCharLogin_send( acfd, fd, cdkey, passwd, ip); +#endif +} + +void lssproto_CreateNewChar_recv( int fd,int dataplacenum,char* charname, + int imgno,int faceimgno, + int vital,int str,int tgh,int dex, + int earth,int water,int fire,int wind, + int hometown ) +{ + char cdkey[CDKEYLEN]; + + if( CONNECT_isCLI( fd ) == FALSE )return; + + if( CONNECT_isNOTLOGIN(fd) == FALSE ){ + // lssproto_CreateNewChar_send( fd, FAILED, "Not NOTLOGIN State\n" ); + lssproto_CreateNewChar_send( fd, FAILED, "¼״̬쳣\n" ); + + return; + } + if( strlen( charname ) == 0 ){ + // lssproto_CreateNewChar_send(fd,FAILED, "0 length name\n"); + lssproto_CreateNewChar_send(fd,FAILED, "ֲΪգ\n"); + return; + }else if( strlen(charname) >= 32 ){ + // lssproto_CreateNewChar_send(fd,FAILED, "Too long charname\n"); + lssproto_CreateNewChar_send(fd,FAILED, "ֹ\n"); + + return; + // Nuke start 0711: Avoid naming as WAEI + }else if (strstr(charname,"") +// WON ADD + || strstr(charname,"gm") || strstr(charname,"GM") + || strstr(charname,"Gm") || strstr(charname,"gM") + || strstr(charname,"") || strstr(charname,"ǣ") + || strstr(charname,"ǣ") || strstr(charname,"") +#ifdef _UNREG_NEMA + || (strstr(charname,getUnregname(0)) && strlen(getUnregname(0))>0) + || (strstr(charname,getUnregname(1)) && strlen(getUnregname(1))>0) + || (strstr(charname,getUnregname(2)) && strlen(getUnregname(2))>0) + || (strstr(charname,getUnregname(3)) && strlen(getUnregname(3))>0) + || (strstr(charname,getUnregname(4)) && strlen(getUnregname(4))>0) +#endif + || strstr(charname,"") + || strstr(charname,"|") + || strstr(charname,"'") + || strstr(charname,"=") + || strstr(charname,";") +// WON END + ) { + // lssproto_CreateNewChar_send(fd,FAILED, "Invalid charname\n"); + lssproto_CreateNewChar_send(fd,FAILED, "Ƿ֣\n"); + return; + /* + unsigned int ip=CONNECT_get_userip(fd); + int a, b, c, d, ck; + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + + ck= ( + ( (a== 10) && (b==0) && (c==0) ) || + ( (a==211) && (b==76) && (c==176) && (d==21) ) || // ̨wayi + ( (a==210) && (b==64) && (c==97) && ((d>=21)&&(d<=25)) ) || + ( (a==61) && (b==222) && (c==142) && (d==66)) || + ( (a==172) && (b==16) && (c==172) && (d==29) ) + ); + + print(" name_WAEI_IP:%d.%d.%d.%d ck:%d ",a,b,c,d,ck ); + + if( !ck ) { + lssproto_CreateNewChar_send(fd,FAILED, "Invalid charname\n"); + return; + } + */ + } +#ifdef _MO_ILLEGAL_NAME + int j; + for(j=0;j<32;j++){ + if(strstr(charname,getIllegalName(j))&& strlen(getIllegalName(j))>0){ + // lssproto_CreateNewChar_send(fd,FAILED, "Invalid charname\n"); + lssproto_CreateNewChar_send(fd,FAILED, "Ƿ֣\n"); + return; + } + } +#endif + { + // Nuke start 0801,0916: Avoid strange name + int i,ach; + for (i=0,ach=0;i=0x7f)&& + ((unsigned char)charname[i]<=0xa0)) { ach=1; break; } // Force no 0x7f~0xa0 + if ((unsigned char)charname[i]<=0x20) { ach=1; break; } // Force greater than 0x20 + if (ach) { + if ((((unsigned char)charname[i]>=0x40)&&((unsigned char)charname[i]<=0x7e))|| + (((unsigned char)charname[i]>=0xa1)&&((unsigned char)charname[i]<=0xfe))) ach=0; + } else { + if (((unsigned char)charname[i]>=0xa1)&&((unsigned char)charname[i]<=0xfe)) ach=1; + } + } + if (ach) { + // lssproto_CreateNewChar_send(fd,FAILED, "Error in Chinese\n"); + lssproto_CreateNewChar_send(fd,FAILED, "ƣ\n"); + + return; + } + // Nuke end + } + // Nuke end + + CONNECT_getCdkey( fd, cdkey, sizeof( cdkey )); + CHAR_createNewChar( fd, dataplacenum, charname ,imgno, faceimgno, + vital, str, tgh, dex, + earth, water, fire, wind, + hometown , cdkey ); +} + +void lssproto_CharLogin_recv( int fd,char* charname ) +{ + char cdkey[CDKEYLEN], passwd[PASSWDLEN]; + + if( CONNECT_isCLI( fd ) == FALSE )return; + + print( "\nԵ½: =%s\n", charname); + + if( charname[0] == '\0' ){ + lssproto_CharLogin_send( fd, FAILED, "Can't access char have no name\n" ); + return; + } + if( CONNECT_isNOTLOGIN(fd) == FALSE ){ + lssproto_CharLogin_send( fd, FAILED, "Already Logged in\n" ); + return; + } + CONNECT_setCharname( fd, charname ); + CONNECT_getCdkey( fd, cdkey, sizeof( cdkey )); + CONNECT_getPasswd( fd, passwd, sizeof(passwd)); + + + saacproto_ACCharLoad_send( acfd, cdkey,passwd, charname,1,"", + CONNECT_getFdid(fd) ); + CONNECT_setState( fd, WHILELOGIN ); +} +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _ITEM_CHECKDROPATLOGOUT +BOOL CheckDropatLogout(int charaindex ) +{ + int i; + for( i=0 ; i< CheckCharMaxItem(charaindex) ; i++ ){ + int itemindex; + itemindex = CHAR_getItemIndex(charaindex,i); + if( ITEM_CHECKINDEX(itemindex) == FALSE )continue; + if( ITEM_getInt(itemindex,ITEM_DROPATLOGOUT ) == TRUE ) { + return TRUE; + } + } + return FALSE; +} +#endif + + +void lssproto_CharLogout_recv( int fd, int flg) +{ + char cdkey[CDKEYLEN] , charname[CHARNAMELEN]; + int charaindex=CONNECT_getCharaindex(fd); + if( CONNECT_isCLI( fd ) == FALSE )return; + if( CONNECT_isLOGIN(fd) == FALSE ){ + lssproto_CharLogout_send( fd, FAILED, "Not Logged in\n" ); + + return; + } +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) > 0){ + CHAR_setWorkInt( charaindex, CHAR_WORKFD, -1); + }else +#endif + { + + int fl,x,y; + // CoolFish: 2001/10/18 + if (!CHAR_CHECKINDEX(charaindex)) return; + + if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER) >= 0 ) + { + if(CHAR_getElderPosition( CHAR_getInt( charaindex, CHAR_LASTTALKELDER), &fl, &x, &y )==FALSE){ + CHAR_talkToCli( charaindex, -1, "ǰļ¼¼¼", CHAR_COLORYELLOW); + return; + } +#ifdef _NO_TEAMWARP_SKYLAND + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) != CHAR_PARTY_NONE && fl == 30691){ + CHAR_talkToCli( charaindex, -1, "Ŷ޷֮", CHAR_COLORYELLOW); + return; + } +#endif + +#ifdef _CHAR_NEWLOGOUT + if( flg == 1 ){//ؼ¼ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + CHAR_talkToCli( charaindex, -1, "ս޷ؼ¼㣡", CHAR_COLORYELLOW); + return; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "Я޷ʹá", CHAR_COLORYELLOW); + return; + } +#endif + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + CHAR_talkToCli( charaindex, -1, "Ŷ޷ؼ¼㣡", CHAR_COLORYELLOW); + return; + } +#ifdef _ITEM_CHECKDROPATLOGOUT + if( CheckDropatLogout( charaindex ) ){ + CHAR_talkToCli( charaindex, -1, "ЯƷʹ޷ؼ¼㣡", CHAR_COLORYELLOW); + return; + } +#endif +#ifdef _AUTO_PK + if(CHAR_getInt(charaindex,CHAR_FLOOR)==20000 + && CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE + && CHAR_getWorkInt(charaindex,CHAR_WORK_AUTOPK)!=-1 ){ + char buf[64]; + int i,num=0,winindex=-1; + int playernum = CHAR_getPlayerMaxNum(); + sprintf(buf, "С %s ˳ǰ",CHAR_getChar(charaindex,CHAR_NAME)); + AutoPk_PKSystemTalk( buf, buf ); + if(AutoPk_PKTimeGet()<=0){ + for(i=0;i1)||(i_diff_y>1) ){ + // Robin 0518 + //CHAR_talkToCli(fd_charaindex, -1, "·ߡ", CHAR_COLORYELLOW); + + //return; + x = ix; + y = iy; + } + } + if(!(MAP_walkAble(fd_charaindex,CHAR_getInt(fd_charaindex, CHAR_FLOOR),x,y))){ + // Robin 03/14 + x = ix; + y = iy; + }else{ + } + + CHAR_walk_init( fd, x, y, direction, TRUE); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_W2_recv( int fd,int x,int y,char* direction ) +{ + //ttom +3 + int fd_charaindex, ix, iy, i_fl; + //Char *chwk;// CoolFish: Rem 2001/4/18 + fd_charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( fd_charaindex ) )return; + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE )return; + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE)return; + + if(CHAR_getWorkInt(fd_charaindex, CHAR_WORK_X) == x && CHAR_getWorkInt(fd_charaindex, CHAR_WORK_Y) == x ){ + if(strlen(direction) == 1){ + if(direction[0] >= 'a' && direction[0] <= 'h'){ + if(CHAR_getWorkInt(fd_charaindex, CHAR_WORK_DIR) != direction[0] - 'a'){ + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_DIR, direction[0] - 'a'); + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_W, 0); + }else if(CHAR_getWorkInt(fd_charaindex, CHAR_WORK_W) > 30){ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT ){ + if( CONNECT_getBDTime( fd) < time( NULL) ){ + lssproto_EN_recv(fd,CHAR_getInt(fd_charaindex,CHAR_X),CHAR_getInt(fd_charaindex,CHAR_Y)); + CONNECT_setBDTime( fd, (int)time( NULL) + 3); + } + } + return; + }else{ + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_W, CHAR_getWorkInt(fd_charaindex, CHAR_WORK_W) + 1); + } + } + }else{ + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_W, 0); + } + }else{ + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_W, 0); + } + + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_X, x); + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_Y, x); + +#ifdef _FIX_STW_SPEED_ENEMY + if(strstr(direction, "gcgc") != NULL ){ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT ){ + if( CONNECT_getBDTime( fd) < time( NULL) ){ + lssproto_EN_recv(fd,CHAR_getInt(fd_charaindex,CHAR_X),CHAR_getInt(fd_charaindex,CHAR_Y)); + CONNECT_setBDTime( fd, (int)time( NULL) + 3); + } + } + return; + } +#else +#ifdef _NO_STW_ENEMY + if(strstr(direction, "gcgc") != NULL ){ + switch(getNoSTWNenemy()){ + case 0: + break; + case 1: + return; + case 2: + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT ){ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + return; + } + if(getNoSTWNenemyPoint()>0){ + if(CHAR_getInt( fd_charaindex, CHAR_GOLD ) < getNoSTWNenemyPoint()){ + char token[256]; + sprintf(token, "ʯҲ%d޷ԭ", getNoSTWNenemyPoint()); + CHAR_talkToCli(fd_charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + } + if(BATTLE_CreateVsEnemy(fd_charaindex, 0, -1) != BATTLE_ERR_CHARAINDEX){ + if(getNoSTWNenemyPoint()>0){ + CHAR_setInt( fd_charaindex, CHAR_GOLD, CHAR_getInt( fd_charaindex, CHAR_GOLD ) - getNoSTWNenemyPoint()); + CHAR_send_P_StatusString( fd_charaindex , CHAR_P_STRING_GOLD); + } + } + } + return; + } + + } +#endif +#endif + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + i_fl=CHAR_getInt(fd_charaindex, CHAR_FLOOR); + + //ttom avoid the warp at will 11/6 + { + int i_diff_x,i_diff_y; + //ix=CHAR_getInt(fd_charaindex, CHAR_X); + //iy=CHAR_getInt(fd_charaindex, CHAR_Y); + //i_fl=CHAR_getInt(fd_charaindex, CHAR_FLOOR); + i_diff_x=abs(ix-x); + i_diff_y=abs(iy-y); + if( (i_diff_x>1)||(i_diff_y>1) ){//2 + //print("\nWarp Error!!!!!!!!!"); + //print("\nthe origion->fd=%d,x=%d,y=%d",fd,ix,iy); + //print("\nthe modify-->fd=%d,X=%d,Y=%d,dir=%s",fd,x,y,direction); + x=ix; + y=iy; + // Robin 03/14 + //return; + } + //if((i_fl==117)&&(ix==225)&&(iy==13)) goto END_w; + }//ttom + if(!(MAP_walkAble(fd_charaindex,CHAR_getInt(fd_charaindex, CHAR_FLOOR),x,y))){ +// print("\n the map is invaild(f:%d,x:%d,y:%d)",CHAR_getInt(fd_charaindex, CHAR_FLOOR),x,y); + x = ix; + y = iy; + } + CHAR_walk_init( fd, x, y, direction, FALSE); +} + +void lssproto_SKD_recv( int fd,int dir, int index) +{ + CHECKFDANDTIME; +} + +void lssproto_ID_recv( int fd,int x,int y,int haveitemindex,int toindex ) +{ + if( CONNECT_checkfd(fd) == FALSE )return; + int to_charaindex; + int fd_charaindex; + + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + + // CoolFish: Prevent Trade Cheat 2001/4/18 + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; +#ifdef _STREET_VENDOR + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKSTREETVENDOR) != -1) + return; +#endif + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + //ttom avoid the warp at will 12/5 + { + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + x=ix; + y=iy; + } + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + to_charaindex = Callfromcli_Util_getTargetCharaindex( fd, toindex); + CHAR_ItemUse( fd_charaindex, to_charaindex, haveitemindex ); +} + + +/*------------------------------------------------------------ + * įë + ------------------------------------------------------------*/ +void lssproto_ST_recv( int fd,int titleindex ) +{ + CHECKFDANDTIME; + CHAR_selectTitle( CONNECT_getCharaindex( fd) , titleindex ); +} +/*------------------------------------------------------------ + * įë + ------------------------------------------------------------*/ +void lssproto_DT_recv( int fd,int titleindex ) +{ + CHECKFDANDTIME; + CHAR_deleteTitle( CONNECT_getCharaindex(fd) , titleindex ); +} + + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_FT_recv( int fd,char* data ) +{ + CHECKFDANDTIME; + + // Robin 04/23 debug + if( strlen(data) > 12 ) return; + + if( checkStringErr(data) ) return; + + CHAR_inputOwnTitle( CONNECT_getCharaindex(fd) , data); +} + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_PI_recv( int fd,int x, int y, int dir ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + {//ttom avoid warp at will + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + //print("\n--Error!!!!"); + //print("\norigion x=%d,y=%d",ix,iy); + //print("\nmodify X=%d,Y=%d",x,y); + x=ix; + y=iy; + } + }//ttom end + + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + CHAR_PickUpItem( fd_charaindex, dir); +} + +void lssproto_DI_recv( int fd,int x, int y, int itemindex ) +{ + int charaindex; + CHECKFDANDTIME; + charaindex = CONNECT_getCharaindex( fd ); + + if (CHAR_getWorkInt(charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + +#ifdef _STREET_VENDOR + if (CHAR_getWorkInt(charaindex, CHAR_WORKSTREETVENDOR) != -1) + return; +#endif + +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(charaindex,CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + + if( CHAR_getWorkInt(charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) return; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return; + + CHAR_setMyPosition( charaindex , + CHAR_getInt( charaindex, CHAR_X), CHAR_getInt( charaindex, CHAR_Y), TRUE); + + CHAR_DropItem( charaindex, itemindex ); +} + +void lssproto_DP_recv( int fd,int x, int y, int petindex ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(fd_charaindex,CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + { + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + x=ix; + y=iy; + } + CHAR_setMyPosition( fd_charaindex , x,y,TRUE); + if( CHAR_getWorkInt( fd_charaindex , CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + PET_dropPet( fd_charaindex, petindex); +} + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_DG_recv( int fd,int x, int y, int amount ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + //ttom avoid the warp at will 12/15 + { + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + x=ix; + y=iy; + } + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + + // CoolFish: Prevent Trade Cheat 2001/4/18 + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + + + CHAR_DropMoney( fd_charaindex, amount ); +} + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_MI_recv( int fd,int fromid,int toid ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; +#ifdef _STREET_VENDOR + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKSTREETVENDOR) != -1) + return; +#endif + + if(fromid != toid){ + int fromitemindex = CHAR_getItemIndex( fd_charaindex, fromid); + int toitemindex = CHAR_getItemIndex( fd_charaindex, toid); + if( ITEM_CHECKINDEX(fromitemindex) && ITEM_CHECKINDEX(toitemindex)){ + CHAR_setWorkInt(fd_charaindex, CHAR_WORKITEMINDEX, fromitemindex); + CHAR_setWorkInt(fd_charaindex, CHAR_WORKTOITEMINDEX, toitemindex); + +#ifdef _ITEM_COLOER + if(strcmp(ITEM_getChar( fromid, ITEM_USEFUNC), "ITEM_COLOER")==0){ + char *itemarg = ITEM_getChar( fromitemindex, ITEM_ARGUMENT); + ITEM_setInt( toitemindex, ITEM_COLOER, atoi(itemarg) ); + ITEM_setInt( fromitemindex, ITEM_COLOER, atoi(itemarg) ); + CHAR_sendItemDataOne( fd_charaindex, toid); + CHAR_DelItem( fd_charaindex, fromid); + return ; + } +#endif +#ifdef _ITEM_UPLEVEL + if(strcmp(ITEM_getChar( fromitemindex, ITEM_USEFUNC), "ITEM_UPLEVEL")==0){ + char message[256]; + char buf[256]; + + int armtype = ITEM_getInt( toitemindex, ITEM_TYPE ); + + if( armtype == ITEM_FIST + || armtype == ITEM_AXE + || armtype == ITEM_CLUB + || armtype == ITEM_SPEAR + || armtype == ITEM_BOW + || armtype == ITEM_BOOMERANG + || armtype == ITEM_BOUNDTHROW + || armtype == ITEM_BREAKTHROW + || armtype == ITEM_HELM + || armtype == ITEM_ARMOUR + ) { + sprintf( message, "ǷԸƷĶϸ\n\n" + "1Ʒװ˷ʯͷ\n" + "2Ʒɹȼ+1ʧȼ-1\n" + //"3Ʒһװ+10\n" + "3װȼԽߣɹԽ\n" + "4ʹͣǷǸ߼ʯ\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_ITEM_UPLEVEL, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } + } +#endif + +#ifdef _ITEM_OVER_LAP + if(ItemOverlapFunction( fd_charaindex, fromitemindex, toitemindex ) == 0){ + return; + } +#endif + } + } + + + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + CHAR_moveEquipItem( fd_charaindex, fromid, toid ); + +} + +#ifdef _PET_ITEM +void lssproto_PETITEM_recv( int fd,int x,int y,int petindex,int fromindex,int toindex ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(fd_charaindex,CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + + // CoolFish: Prevent Trade Cheat 2001/4/18 + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + + /* ºƥľ¦Ⱦµ ؤԻ */ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + CHAR_movePetItem( fd_charaindex, petindex, fromindex, toindex ); +} +#endif + + + +/*------------------------------------------------------------ + * ƽʧ + ------------------------------------------------------------*/ +void lssproto_SKUP_recv( int fd,int skillid ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex(fd); + + /* ƮϽ ʥ饰Ǥ˰äǽ*/ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + CHAR_SkillUp(fd_charaindex,skillid); +} + +/*------------------------------------------------------------ + * ͥ˥å + ------------------------------------------------------------*/ +void lssproto_MSG_recv( int fd,int index,char* message, int color ) +{ + int fd_charaindex; + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd); + ADDRESSBOOK_sendMessage( fd_charaindex, index,message, color ); + +} + +/*------------------------------------------------------------ + * ɥ쥹֥åƤɤ׵᤬褿 + ------------------------------------------------------------*/ +void lssproto_AB_recv( int fd ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + ADDRESSBOOK_sendAddressbookTable( fd_charaindex ); +} + +/*------------------------------------------------------------ + * ɥ쥹֥åιܤ + ------------------------------------------------------------*/ +void lssproto_DAB_recv( int fd , int index) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + ADDRESSBOOK_deleteEntry( fd_charaindex ,index); +} + +void lssproto_AAB_recv( int fd , int x, int y) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + { + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + x=ix; + y=iy; + } + } + CHAR_setMyPosition( fd_charaindex , x,y,TRUE); + ADDRESSBOOK_addEntry( fd_charaindex ); +} + +void lssproto_L_recv( int fd, int dir ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + CHAR_Look( fd_charaindex ,dir ); +} + + +/*------------------------------------------------------------ + * åѥå + ------------------------------------------------------------*/ +void lssproto_TK_recv( int fd,int x, int y,char* message,int color, int area ) +{ + int fd_charaindex,ix,iy;//ttom+2 + int fmindex, channel; + + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + fmindex = CHAR_getInt( fd_charaindex, CHAR_FMINDEX ); + channel = CHAR_getWorkInt( fd_charaindex, CHAR_WORKFMCHANNEL ); + + {// Robin 0629 silent + int silentSec, talkCount; + silentSec = CHAR_getInt(fd_charaindex,CHAR_SILENT); + if( silentSec > 0 ) { + int loginTime; + char buf[256]; + int leftSec; + loginTime = CHAR_getWorkInt(fd_charaindex, CHAR_WORKLOGINTIME ); + // ֹʱ˷ᡡ쳣 Robin 20040817 + if( (int)NowTime.tv_sec < loginTime) { + CHAR_setInt(fd_charaindex, CHAR_SILENT, 0 ); + return; + } + if( ((int)NowTime.tv_sec -loginTime) > silentSec ) { + CHAR_setInt(fd_charaindex, CHAR_SILENT, 0 ); + return; + } + silentSec += 10; //10 + + leftSec = silentSec - ((int)NowTime.tv_sec - loginTime); + sprintf(buf, "!!%d룬ٽ10ӡ", leftSec ); + CHAR_talkToCli(fd_charaindex, -1, buf, color); + CHAR_setInt(fd_charaindex, CHAR_SILENT, silentSec ); + return; + } + + talkCount = CHAR_getWorkInt(fd_charaindex, CHAR_WORKTALKCOUNT ); + talkCount ++; + CHAR_setWorkInt( fd_charaindex, CHAR_WORKTALKCOUNT, talkCount); + if( talkCount > 8 ) { + int lastTalkTime = CHAR_getWorkInt(fd_charaindex, CHAR_WORKTALKTIME ); + if( (int)NowTime.tv_sec - lastTalkTime < 10 ) { + CHAR_setInt( fd_charaindex,CHAR_SILENT, 60 ); + CHAR_setWorkInt( fd_charaindex, CHAR_WORKLOGINTIME, (int)NowTime.tv_sec ); + CHAR_talkToCli( fd_charaindex, -1, "̫໰ࡣϢһӰɣ", color); + CHAR_setWorkInt(fd_charaindex, CHAR_WORKTALKCOUNT, 0 ); + return; + }else { + CHAR_setWorkInt( fd_charaindex, CHAR_WORKTALKTIME, (int)NowTime.tv_sec ); + CHAR_setWorkInt(fd_charaindex, CHAR_WORKTALKCOUNT, 0 ); + } + } + + } + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + x=ix; + y=iy; + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + + if( CHAR_getInt(fd_charaindex, CHAR_LV) < 5 && message[strlen(message)-1] != ']'){ + CHAR_talkToCli(fd_charaindex, -1, "ĵȼС5,Ŀǰֻ˵hi", CHAR_COLORYELLOW); + CHAR_Talk( fd,fd_charaindex, "P|hi", color, area ); + }else{ + CHAR_Talk( fd,fd_charaindex, message, color, area ); + } + + //} +} + +void lssproto_M_recv( int fd, int fl, int x1, int y1 , int x2, int y2 ) +{ + char* mapdata; + RECT seek={x1,y1,x2-x1,y2-y1},ret; + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); +#ifdef _MASK_ENCOUNTER + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT ){ + if( getStayEncount( fd) ) return; + }else{ + int oyaindex = CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYINDEX1); + if( getStayEncount( getfdFromCharaIndex(oyaindex)) ) return; + } +#endif +#ifdef _MO_MAP_AUTO_UPDATE + mapdata = MAP_getdataFromRECT(fl,&seek,&ret); + if( mapdata != NULL ){ + lssproto_M_send( fd, fl, ret.x, ret.y, + ret.x+ret.width, ret.y+ret.height, mapdata ); + } +#endif +} + +/*------------------------------------------------------------ + * ǡ ׵ᡣ + ------------------------------------------------------------*/ +void lssproto_C_recv( int fd, int index ) +{ + if( CONNECT_checkfd(fd) == FALSE )return; + int fd_charaindex; + + fd_charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX(fd_charaindex)){ + return; + } + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + +#ifdef _STREET_VENDOR + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKSTREETVENDOR) != -1) + return; +#endif + + CHAR_sendCSpecifiedObjindex( fd, index); +} +#ifdef _FAMILYBADGE_ +extern int getFamilyBadge(int index); +#endif +void lssproto_S_recv( int fd, char* category ) +{ + char* string; + int fd_charaindex; + fd_charaindex = CONNECT_getCharaindex( fd ); + string = CHAR_makeStatusString( fd_charaindex, category ); + if( string != NULL ) + lssproto_S_send( fd , string ); + +} + +void lssproto_EV_recv( int fd,int event,int seqno,int x,int y, int dir ) +{ + int rc; + int fx,fy; + int fd_charaindex; + + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + { + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( ( ix != x ) || ( iy != y ) ){ + goto CK1; + } + goto OK; + } +CK1: + { + OBJECT object; + int ix,iy,ifloor,i,j; + int warp_point_x[9]; + int warp_point_y[9]; + int warp_point=0; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + ifloor=CHAR_getInt(fd_charaindex,CHAR_FLOOR); + for(i=iy-1;i<=iy+1;i++){ + for(j=ix-1;j<=ix+1;j++){ + for( object = MAP_getTopObj(ifloor,j,i) ; object ;object = NEXT_OBJECT(object ) ){ + int o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_CHARA ){ + int etype; + int charaindex=OBJECT_getIndex(o); + if( !CHAR_CHECKINDEX(charaindex) ) continue; + etype = CHAR_getWorkInt( charaindex, CHAR_WORKEVENTTYPE); + if( etype != CHAR_EVENT_NONE ) { + if(etype==CHAR_EVENT_WARP){ + warp_point_x[warp_point]=j; + warp_point_y[warp_point]=i; + warp_point++; + } + } + } +#ifdef _MAP_WARPPOINT + else if( OBJECT_getType(o) == OBJTYPE_WARPPOINT ){ + int etype = OBJECT_getchartype( o); + if( etype != CHAR_EVENT_NONE ) { + warp_point_x[warp_point]=j; + warp_point_y[warp_point]=i; + warp_point++; + break; + } + } +#endif + } + } + } + + for(i=0;i 7) { + fx = CHAR_getInt(fd_charaindex, CHAR_X); + fy = CHAR_getInt(fd_charaindex, CHAR_Y); + }else { + CHAR_getCoordinationDir( dir, CHAR_getInt(fd_charaindex, CHAR_X), + CHAR_getInt(fd_charaindex, CHAR_Y),1,&fx,&fy); + } + rc = EVENT_main(fd_charaindex, event,fx,fy); + lssproto_EV_send( fd, seqno, rc); +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"2|%d",CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT )); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char msg[256]; + sprintf(msg,"3|%d",CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT_MANOR )); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif + +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( fd_charaindex, CHAR_TITLE_DEFAULT ) > 0 ){ + char msg[256]; + sprintf(msg,"4|%d",CHAR_getInt( fd_charaindex, CHAR_TITLE_DEFAULT )); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( fd_charaindex, CHAR_TRUMP_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"5|%d",CHAR_getInt( fd_charaindex, CHAR_TRUMP_EFFECT )); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( fd_charaindex) ){ + char msg[256]; + sprintf(msg,"1|%d",getFamilyBadge( fd_charaindex)); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_EN_recv( int fd , int x,int y ) +{ + int ret = FALSE, err = 0; + int fd_charaindex; + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd); + +#ifdef _ALLBLUES_LUA_1_7 +// if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { +// if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ +// if(CharVsEnemyFunction( fd_charaindex ) == TRUE)return; +// } +// } +#endif + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT){ + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + CHAR_setWorkChar( fd_charaindex, CHAR_WORKWALKARRAY,""); + err = BATTLE_CreateVsEnemy( fd_charaindex,0, -1); + if( err != 0 ){ + ret = FALSE; + }else{ + ret = TRUE; + } + } +} +/*------------------------------------------------------------ + * ץ쥤䡼ƱΤǥ󥫥ȡʷƮȯ + ------------------------------------------------------------*/ +void lssproto_DU_recv( int fd , int x,int y ) +{ + OBJECT object; + int fd_charaindex; + int ret = FALSE, charaindex = -1, enemyindex; + int frontx,fronty; + int cnt = 0; + BOOL found = FALSE; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + {//ttom avoid warp at will + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + //print("\n--Error!!!!"); + //print("\norigion x=%d,y=%d",ix,iy); + //print("\nmodify X=%d,Y=%d",x,y); + x=ix; + y=iy; + } + } + + + /* Ҥλ̵뤹 */ + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKPARTYMODE) + != CHAR_PARTY_CLIENT) + { + int i; + // ʬΥǥå + charaindex = fd_charaindex; + CHAR_setMyPosition( charaindex, x,y,TRUE); + /* WALKARRAY򥯥ꥢ */ + CHAR_setWorkChar( charaindex, CHAR_WORKWALKARRAY,""); + + + /* */ + for( i = 0; i < CONNECT_WINDOWBUFSIZE ; i ++ ) { + CONNECT_setDuelcharaindex( fd, i, -1 ); + } + + /* ܤκɸ */ + CHAR_getCoordinationDir( CHAR_getInt( charaindex, CHAR_DIR ) , + CHAR_getInt( charaindex , CHAR_X ), + CHAR_getInt( charaindex , CHAR_Y ) , + 1 , &frontx , &fronty ); + + /*ʬܤΥ */ + for( object = MAP_getTopObj( CHAR_getInt( charaindex, CHAR_FLOOR), + frontx,fronty) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int toindex; + int objindex = GET_OBJINDEX(object); + /* 饯ʤ */ + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) continue; + toindex = OBJECT_getIndex( objindex); + /* ץ쥤䡼ʤ */ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + && CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYERNPC +#endif + ) continue; + found = TRUE; + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE )continue; + +#ifdef _ALLBLUES_LUA_1_5 + int flg = FreeVsPlayer(charaindex, toindex); + if( flg == 1){ + lssproto_EN_send( fd, FALSE, 0 ); + return; + }else if( flg == 2){ + return; + }else +#endif + if(!CHAR_getFlg( toindex, CHAR_ISDUEL)){ + int floor = CHAR_getInt( charaindex, CHAR_FLOOR ); +#ifdef _AUTO_PK + if(floor == 20000){ + if(AutoPk_PKTimeGet()>0){ + CHAR_talkToCli( charaindex, -1, "ȱʼٽPK", CHAR_COLORYELLOW ); + continue; + }else{ + if(!CHAR_getFlg( toindex, CHAR_ISDUEL)){ + if(CHAR_getWorkInt( charaindex, CHAR_WORK_AUTOPK ) == -1)continue; + if(CHAR_getWorkInt( toindex, CHAR_WORK_AUTOPK ) == -1)continue; + } + } + }else +#endif +#ifdef _BATTLE_FLOOR + { + if(strcmp(getBattleFloorCF(),"")!=0){ + int i; + for(i=0;i<32;i++){ + if(floor==getBattleFloor(i)){ + break; + } + } + if(i==32)continue; + } + } +#else + continue; +#endif + } +#ifdef _BATTLE_PK_TYPE + else{ + int oyaindex1; + int oyaindex2; + int workindex; + int type = CHAR_getWorkInt(charaindex, CHAR_WORK_BATTLEPKTYPE); + switch(type){ + case 0: //PK + break; + case 1: //ϵP + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE ){ + CHAR_talkToCli( charaindex, toindex, "ϵP", CHAR_COLORYELLOW ); + continue; + } + break; + case 2: //P + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE ){ + CHAR_talkToCli( charaindex, toindex, "P", CHAR_COLORYELLOW ); + continue; + } + oyaindex1 = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + oyaindex2 = CHAR_getWorkInt( toindex, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex1 ) && CHAR_CHECKINDEX( oyaindex2 )){ + int i; + for( i = 0; i < getPartyNum(oyaindex1); i ++ ){ + workindex = CHAR_getWorkInt( oyaindex1, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE ){ + CHAR_talkToCli( charaindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + workindex = CHAR_getWorkInt( oyaindex2, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE ){ + CHAR_talkToCli( charaindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + } + } + + break; +#ifdef _CHAR_PROFESSION + case 3: //ְҵP + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE + || CHAR_getInt(charaindex, PROFESSION_CLASS) == 0){ + CHAR_talkToCli( charaindex, toindex, "ְҵP", CHAR_COLORYELLOW ); + continue; + } + break; + case 4: //ְҵP + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(charaindex, PROFESSION_CLASS) == 0){ + CHAR_talkToCli( charaindex, toindex, "ְҵP", CHAR_COLORYELLOW ); + continue; + } + oyaindex1 = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + oyaindex2 = CHAR_getWorkInt( toindex, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex1 ) && CHAR_CHECKINDEX( oyaindex2 )){ + int i; + for( i = 0; i < getPartyNum(oyaindex1); i ++ ){ + workindex = CHAR_getWorkInt( oyaindex1, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(charaindex, PROFESSION_CLASS) == 0){ + CHAR_talkToCli( workindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + workindex = CHAR_getWorkInt( oyaindex2, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(workindex, PROFESSION_CLASS) == 0){ + CHAR_talkToCli( charaindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + } + } + break; + case 5: //ְҵP + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)!=CHAR_PARTY_NONE + || CHAR_getInt(charaindex, PROFESSION_CLASS) > 0){ + CHAR_talkToCli( charaindex, toindex, "ְҵP", CHAR_COLORYELLOW ); + continue; + } + break; + case 6: //ְҵP + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getWorkInt(toindex,CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(charaindex, PROFESSION_CLASS) > 0){ + CHAR_talkToCli( charaindex, toindex, "ְҵP", CHAR_COLORYELLOW ); + continue; + } + oyaindex1 = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + oyaindex2 = CHAR_getWorkInt( toindex, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex1 ) && CHAR_CHECKINDEX( oyaindex2 )){ + int i; + for( i = 0; i < getPartyNum(oyaindex1); i ++ ){ + workindex = CHAR_getWorkInt( oyaindex1, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(workindex, PROFESSION_CLASS) > 0){ + CHAR_talkToCli( charaindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + workindex = CHAR_getWorkInt( oyaindex2, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( CHAR_getWorkInt(workindex, CHAR_WORKPARTYMODE)==CHAR_PARTY_NONE + || CHAR_getInt(workindex, PROFESSION_CLASS) > 0){ + CHAR_talkToCli( charaindex, workindex, "P", CHAR_COLORYELLOW ); + continue; + } + } + } + } + break; +#endif + } + } +#endif + // shan begin + { + int i; + for( i=0; i 1 ) { + int strlength; + char msgbuf[1024]; + char escapebuf[2048]; + strcpy( msgbuf, "1\nҪ˭ս\n"); + strlength = strlen( msgbuf); + /* ɥΥå + * ƮΥΰ + */ + for( i = 0; + CONNECT_getDuelcharaindex( fd,i) != -1 + && i< CONNECT_WINDOWBUFSIZE; + i ++ ) + { + char *a = CHAR_getChar( + CONNECT_getDuelcharaindex( fd,i) , CHAR_NAME); + char buf[256]; + snprintf( buf, sizeof( buf),"%s [%s]\n", a, + CHAR_getWorkInt( + CONNECT_getDuelcharaindex(fd,i), + CHAR_WORKPARTYMODE ) + != CHAR_PARTY_NONE ? "": ""); + if( strlength + strlen( buf) > arraysizeof( msgbuf)){ + print( "%s:%dӴѶϢbuffer㡣\n", + __FILE__,__LINE__); + break; + } + strcpy( &msgbuf[strlength], buf); + strlength += strlen(buf); + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SELECTDUEL, + -1, + makeEscapeString( msgbuf, escapebuf, sizeof(escapebuf))); + ret = TRUE; + } + } + + +lssproto_DU_recv_Err:; + if( ret == FALSE ) { + /* ˪ */ + lssproto_EN_send( fd, FALSE, 0 ); + if( cnt > 0 ) return; + else if( found ) CHAR_talkToCli( charaindex, -1, "˿Զս", CHAR_COLORYELLOW); + else CHAR_talkToCli( charaindex, -1, "ûκˡ", CHAR_COLORYELLOW); + } +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_EO_recv( int fd, int dummy ) +{ + int fd_charaindex; + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + BattleEncountOut( fd_charaindex ); +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"2|%d",CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT )); + #ifdef _FAMILYBADGE_ + lssproto_CHAREFFECT_send(getfdFromCharaIndex(fd_charaindex), msg); +#endif + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char msg[256]; + sprintf(msg,"3|%d",CHAR_getWorkInt( fd_charaindex, CHAR_PLAYER_EFFECT_MANOR )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(fd_charaindex), msg); + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( fd_charaindex, CHAR_TRUMP_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"5|%d",CHAR_getInt( fd_charaindex, CHAR_TRUMP_EFFECT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(fd_charaindex), msg); + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( fd_charaindex, CHAR_TITLE_DEFAULT ) > 0 ){ + char msg[256]; + sprintf(msg,"4|%d",CHAR_getInt( fd_charaindex, CHAR_TITLE_DEFAULT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(fd_charaindex), msg); + } +#endif +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( fd_charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( fd_charaindex) ){ + char msg[256]; + sprintf(msg,"1|%d",getFamilyBadge( fd_charaindex)); + lssproto_CHAREFFECT_send(fd, msg); + } +#endif +} + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_BU_recv( int fd, int dummy) +{ + int fd_charaindex; + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + // shan 2001/12/25 + //BATTLE_WatchStop( fd_charaindex ); +} + +void lssproto_B_recv( int fd, char *command ) +{ + int fd_charaindex; + int battle_index;//ttom++ + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + BattleCommandDispach( fd, command ); + // Nuke +1 0827: Battle acceleration + battle_index=CHAR_getWorkInt(fd_charaindex,CHAR_WORKBATTLEINDEX); + if( BATTLE_CHECKINDEX( battle_index ) == FALSE ){ + return; + } +} + +void lssproto_FS_recv( int fd,int flg ) +{ + int fd_charaindex; + CHECKFDANDTIME; + + fd_charaindex = CONNECT_getCharaindex( fd ); + /* ڱ幫׷ºޥ */ + CHAR_setFlg( fd_charaindex, CHAR_ISPARTY, + (flg & CHAR_FS_PARTY )? TRUE:FALSE); +// CHAR_setFlg( fd_charaindex, CHAR_ISBATTLE, +// (flg & CHAR_FS_BATTLE )? TRUE:FALSE); + +#ifdef _BATTLE_PK_TYPE + if((CHAR_getFlg( fd_charaindex, CHAR_ISDUEL) == FALSE) && (flg & CHAR_FS_DUEL)){ + CHAR_setWorkInt(fd_charaindex, CHAR_WORK_BATTLEPKTYPE, 0); + char message[256]; + char buf[256]; + sprintf( message, "ѡϣPK\n" + "PK\n" + "ϵP\n" + "P\n" +#ifdef _CHAR_PROFESSION + "ְҵP\n" + "ְҵP\n" + "ְҵP\n" + "ְҵP\n" +#endif + ); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_BATTLEPKTYPE, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + } +#endif + CHAR_setFlg( fd_charaindex, CHAR_ISDUEL, + (flg & CHAR_FS_DUEL )? TRUE:FALSE); + CHAR_setFlg( fd_charaindex, CHAR_ISPARTYCHAT, + (flg & CHAR_FS_PARTYCHAT )? TRUE:FALSE); + CHAR_setFlg( fd_charaindex, CHAR_ISTRADECARD, + (flg & CHAR_FS_TRADECARD )? TRUE:FALSE); +#ifdef _CHANNEL_MODIFY + //Ƶ + CHAR_setFlg(fd_charaindex,CHAR_ISTELL,(flg & CHAR_FS_TELL )? TRUE:FALSE); + //Ƶ + CHAR_setFlg(fd_charaindex,CHAR_ISFM,(flg & CHAR_FS_FM )? TRUE:FALSE); + //ְҵƵ + CHAR_setFlg(fd_charaindex,CHAR_ISOCC,(flg & CHAR_FS_OCC )? TRUE:FALSE); + // + CHAR_setFlg(fd_charaindex,CHAR_ISCHAT,(flg & CHAR_FS_CHAT )? TRUE:FALSE); + //Ի + CHAR_setFlg(fd_charaindex,CHAR_ISSAVE,(flg & CHAR_FS_SAVE )? TRUE:FALSE); + +#ifdef _THE_WORLD_SEND + //Ƶ + CHAR_setFlg(fd_charaindex,CHAR_ISWORLD,(flg & CHAR_FS_WORLD )? TRUE:FALSE); +#endif +#endif + CHAR_setFlg(fd_charaindex,CHAR_AI_MOD,(flg & CHAR_FS_AI )? TRUE:FALSE); + + CHAR_setFlg( fd_charaindex, CHAR_ISTRADE,(flg & CHAR_FS_TRADE )? TRUE:FALSE); + lssproto_FS_send( fd, flg); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_PR_recv( int fd,int x, int y, int request ) +{ + int result = FALSE; + int fd_charaindex; + CHECKFDANDTIME; + + fd_charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( fd_charaindex ) )return; + + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return; + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + +#if 1 // ֹ + if( request == 1 ) + { + int nowFloor; + nowFloor = CHAR_getInt( fd_charaindex, CHAR_FLOOR); + if( nowFloor == 31706 + || nowFloor == 10204 + || (10601 <= nowFloor && nowFloor <= 10605 ) + || nowFloor == 10919 || nowFloor == 10920 + || nowFloor == 20711 || nowFloor == 20712 + || nowFloor == 1008 || nowFloor == 1021 + || nowFloor == 3008 || nowFloor == 3021 + || ( nowFloor <= 8213 && nowFloor >= 8200 ) + || ( nowFloor >= 30017 && nowFloor <= 30021 ) +#ifdef _TIME_TICKET + || check_TimeTicketMap(nowFloor) +#endif +#ifdef _NPC_MAGICCARD + || nowFloor == 17003 || nowFloor == 17005 +#endif + ){ + // print("\n ķ!ֹ!!:%s ", CHAR_getChar( fd_charaindex, CHAR_CDKEY) ); + return; + } + } +#endif + + {//ttom avoid warp at will + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + //print("\n--Error!!!!"); + //print("\norigion x=%d,y=%d",ix,iy); + //print("\nmodify X=%d,Y=%d",x,y); + x=ix; + y=iy; + } + } + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + + if( request == 0 ) { + /* */ + result = CHAR_DischargeParty(fd_charaindex, 0); + } + else if( request == 1 ) { + result = CHAR_JoinParty(fd_charaindex); + } +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_KS_recv( int fd,int petarray ) +{ + int ret , fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( fd_charaindex ) )return; + if(petarray != -1 && CHAR_getInt( fd_charaindex, CHAR_RIDEPET) == petarray ){ + lssproto_KS_send( fd, petarray, FALSE); + return; + } + ret = PET_SelectBattleEntryPet( fd_charaindex, petarray); + lssproto_KS_send( fd, petarray, ret); +} + +void lssproto_SPET_recv( int fd, int standbypet ) +{ + int fd_charaindex; + int i, s_pet =0, cnt =0; + + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( fd_charaindex ) )return; + //if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE + // && standbypet >= CHAR_getWorkInt( fd_charaindex, CHAR_WORKSTANDBYPET) ) { + // print("\n ķ!??սSPETӴ!!:%s ", CHAR_getChar( fd_charaindex, CHAR_CDKEY) ); + // return; + //} + + //if( CHAR_getInt( fd_charaindex, CHAR_RIDEPET) == petarray ) { + // lssproto_SPET_send( fd, petarray, FALSE); + //} + + for( i =0; i < CHAR_MAXPETHAVE; i++) { + if( standbypet & ( 1 << i ) ) { + + if( CHAR_getInt( fd_charaindex, CHAR_RIDEPET) == i ) + continue; + + cnt++; + //if( cnt > 4 ) { + // print("\n ķ!賬!!:%s ", CHAR_getChar( fd_charaindex, CHAR_CDKEY) ); + //lssproto_SPET_send( fd, s_pet, FALSE); + // break; + //} + + s_pet |= ( 1 << i ); + } + } + CHAR_setWorkInt( fd_charaindex, CHAR_WORKSTANDBYPET, s_pet); + + lssproto_SPET_send( fd, s_pet, TRUE); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_AC_recv( int fd,int x, int y,int actionno ) +{ + if( CONNECT_checkfd(fd) == FALSE )return; + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + + {//ttom avoid the warp at will + Char *ch; + ch = CHAR_getCharPointer( fd_charaindex); + // CoolFish: +1 2001/11/05 + if (!ch) return; + if((ch->data[CHAR_X]!=x)||(ch->data[CHAR_Y]!=y)){ + return; + } + } +#ifdef _ALLBLUES_LUA_1_9 + FreeAction(fd_charaindex, x,y, actionno); +#endif + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + CHAR_sendAction( fd_charaindex, actionno, FALSE); + return; +} + +void lssproto_LOOK_recv( int fd,int x,int y ) +{ + int charaindex, floor; + CHECKFDANDTIME; + charaindex = CONNECT_getCharaindex( fd ); + { + int ix,iy; + ix=CHAR_getInt(charaindex, CHAR_X); + iy=CHAR_getInt(charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + x=ix; + y=iy; + } + } + CHAR_setMyPosition( charaindex, x,y,TRUE); + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + BATTLE_WatchTry( charaindex ); +} + + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_MU_recv( int fd,int x,int y,int array,int toindex ) +{ + int to_charaindex = -1, fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + {//ttom avoid warp at will + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + //print("\n--Error!!!!"); + //print("\norigion x=%d,y=%d",ix,iy); + //print("\nmodify X=%d,Y=%d",x,y); + x=ix; + y=iy; + } + } + + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + to_charaindex = Callfromcli_Util_getTargetCharaindex( fd, toindex); + MAGIC_Use( fd_charaindex, array, to_charaindex); +} + +void lssproto_JB_recv( int fd,int x,int y ) +{ + int charaindex, floor; + + CHECKFDANDTIME; + charaindex = CONNECT_getCharaindex( fd ); + { + int ix,iy; + ix=CHAR_getInt(charaindex, CHAR_X); + iy=CHAR_getInt(charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + x=ix; + y=iy; + } + } + + CHAR_setMyPosition( charaindex, x,y,TRUE); + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; +#ifdef _BATTLE_LOOK_ + BATTLE_RescueTry( charaindex ); +#else + floor = CHAR_getInt( charaindex, CHAR_FLOOR ); + if( floor == 1007 + || floor == 2007 + || floor == 3007 + || floor == 4007 + || floor == 130 +#ifdef _AUTO_PK + || (floor == 20000 && CHAR_getWorkInt( charaindex, CHAR_WORK_AUTOPK ) == -1) +#endif +#ifdef _WATCH_FLOOR + || floor == getWatchFloor(1) + || floor == getWatchFloor(2) + || floor == getWatchFloor(3) + || floor == getWatchFloor(4) + || floor == getWatchFloor(5) + || !strcmp(getWatchFloorCF(),"") +#endif + ){ + BATTLE_WatchTry( charaindex ); + }else{ + if(BATTLE_RescueTry( charaindex ) == FALSE){ + BATTLE_WatchTry( charaindex ); + } + } +#endif +} + +void lssproto_KN_recv( int fd,int havepetindex,char* data ) +{ + int fd_charaindex; + CHECKFD; + fd_charaindex = CONNECT_getCharaindex( fd ); + + // Robin 04/26 debug + if( strlen(data) > 16 ) return; + + // CoolFish: Prevent Trade Cheat 2001/4/18 + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + + if( checkStringErr(data) ) return; +#ifdef _CHANGE_PETNAME_FIX + if(strstr(data,"|")!=NULL&&strstr(data,"'")!=NULL&&strstr(data,"/")!=NULL&&strstr(data,"\\")!=NULL){ + CHAR_talkToCli( fd_charaindex, -1, "벻ҪзǷַ", CHAR_COLORRED); + return; + } +#endif + CHAR_inputUserPetName( fd_charaindex, havepetindex, data); + +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_WN_recv( int fd,int x,int y,int seqno, + int objindex,int select, char* data ) +{ + int fd_charaindex; + + CHECKFDANDTIME; + + if( checkStringErr(data) ) return; + fd_charaindex = CONNECT_getCharaindex( fd ); + // CoolFish: Prevent Trade Cheat 2001/4/18 + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) { + return; + } + // Robin + if( checkStringErr(data) ) return; + +#ifdef _ANGEL_SUMMON + if( seqno == CHAR_WINDOWTYPE_ANGEL_ASK ) + { + print("\n CHAR_WINDOWTYPE_ANGEL_ASK objindex:%d select:%d data:%s ", + objindex, select, data ); + + if(select==WINDOW_BUTTONTYPE_YES ) { + if( AngelCreate( fd_charaindex) == FALSE ) { + sendAngelCleanToCli( fd ); + } + } + else if(select==WINDOW_BUTTONTYPE_NO ) { + int mindex; + char nameinfo[64]; + mindex = checkIfAngel( fd_charaindex); + print(" ====ٻ==== "); + getMissionNameInfo( fd_charaindex, nameinfo); + saacproto_ACMissionTable_send( acfd, mindex, 3, nameinfo, ""); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + "ź\nİħΣ½ˡ" ); + + //CHAR_talkToCli( fd_charaindex, -1, "֮ǿϧѵõĻѽ", CHAR_COLORYELLOW); + + sendAngelCleanToCli( fd ); + } + } +#endif + + {//ttom avoid the warp at will + Char *ch; + ch = CHAR_getCharPointer( fd_charaindex); + // CoolFish: +1 2001/11/05 + if (!ch) return; + if((ch->data[CHAR_X]!=x)||(ch->data[CHAR_Y]!=y)){ + // Robin 04/20 test + return; + x=ch->data[CHAR_X]; + y=ch->data[CHAR_Y]; + } + //ttom avoid WN at will + if(seqno==CHAR_WINDOWTYPE_NPCENEMY_START){ +// Char *ch; + OBJECT object; + int ix,iy,ifloor,i,j; + int whichtype= -1; + int enemy=0; + int enemy_index; + if(!CHECKOBJECT(objindex)){ + goto FIRST; + } + enemy_index=OBJECT_getIndex(objindex);//ttom 11/15/2000 + ix =ch->data[CHAR_X]; + iy =ch->data[CHAR_Y]; + ifloor=ch->data[CHAR_FLOOR]; + for(i=iy-1;i<=iy+1;i++){ + for(j=ix-1;j<=ix+1;j++){ + for( object = MAP_getTopObj(ifloor,j,i) ; object ; + object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + whichtype = CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE); + if( whichtype == CHAR_TYPENPCENEMY){ + int i_ene_temp; + i_ene_temp=OBJECT_getIndex( objindex); + //print("\n--enetemp=%d",i_ene_temp); + if(i_ene_temp== enemy_index){ + goto START_WN; + }else{ + enemy=0; + } + } + break; + case OBJTYPE_ITEM: + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + } + } + } + if(enemy==0){ +FIRST: + + lssproto_EN_send( fd, FALSE, 0 ); + CHAR_talkToCli(fd_charaindex, -1, "¼", CHAR_COLORYELLOW); + goto END_WN; + } + } + } + //ttom end +START_WN: + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(seqno==CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN){ + if(!CONNECT_get_first_warp(fd)){ + select=1; + } + } + CHAR_processWindow( fd_charaindex, seqno, + select, objindex, makeStringFromEscaped(data)); + } +//ttom+1 +END_WN: + return; + //CONNECT_set_pass(fd,TRUE);//ttom +} + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_HL_recv( int fd,int flg ) +{ + char msgbuf[128]; + int i, fd_charaindex; + CHECKFD; + + fd_charaindex = CONNECT_getCharaindex( fd ); + if( CHAR_getWorkInt( fd_charaindex, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE) + { + return; + } +#ifdef _LOCKHELP_OK // (ɿ) Syu ADD ɼս + if((CHAR_getInt(fd_charaindex,CHAR_FLOOR) >= 8200 && CHAR_getInt(fd_charaindex,CHAR_FLOOR) <= 8213) || + (CHAR_getInt(fd_charaindex,CHAR_FLOOR) >= 30017 && CHAR_getInt(fd_charaindex,CHAR_FLOOR) <= 30021) + || CHAR_getInt(fd_charaindex,CHAR_FLOOR) == 20000 + ){ + return ; + } +#endif + +#ifdef _NO_HELP_MAP +{ + int floor=CHAR_getInt(fd_charaindex, CHAR_FLOOR); + if(floor>=33001&&floor<=33101){ + return; + } + int i; + for(i=0;i<32;i++){ + if(floor == getNoHelpMap(i)){ + return; + } + } +} +#endif + if( flg == TRUE ) { + BattleArray[CHAR_getWorkInt( fd_charaindex, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( fd_charaindex, + CHAR_WORKBATTLESIDE)].flg |= BSIDE_FLG_HELP_OK; + + snprintf( msgbuf, sizeof( msgbuf), + "%s ȣ", + CHAR_getChar( fd_charaindex, CHAR_NAME)); + } + else { + BattleArray[CHAR_getWorkInt( fd_charaindex, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( fd_charaindex, + CHAR_WORKBATTLESIDE)].flg &= ~BSIDE_FLG_HELP_OK; + + snprintf( msgbuf, sizeof( msgbuf), + "%s ܾ", + CHAR_getChar( fd_charaindex, CHAR_NAME)); + } + + for( i = 0; i < 5; i ++ ) { + int toindex = BattleArray[CHAR_getWorkInt( + fd_charaindex, CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( fd_charaindex, + CHAR_WORKBATTLESIDE)].Entry[i].charaindex; + if( CHAR_CHECKINDEX( toindex)) { + int tofd = getfdFromCharaIndex( toindex ); + if( tofd != -1 ) { + lssproto_HL_send( tofd, flg); + } + /* ˪ */ + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_sendBattleEffect( toindex, ON); + } + } +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_ProcGet_recv( int fd ) +{ + outputNetProcLog( fd, 1); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_PlayerNumGet_recv( int fd ) +{ +/* + int i; + int clicnt =0; + int playercnt = 0; + for( i = 0; i < ConnectLen; i ++ ) { + if( CONNECT_getUse_debug(i,1017) ){ + if( CONNECT_getCtype(i) == CLI) { + clicnt ++; + if( CONNECT_getCharaindex(i) >= 0 ) playercnt++; + } + } + } + lssproto_PlayerNumGet_send( fd, clicnt * 0.6, playercnt * 0.6); +*/ +} + + +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_LB_recv( int fd,int x,int y ) +{ + int fd_charaindex; + + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + {//ttom avoid warp at will + int ix,iy; + ix=CHAR_getInt(fd_charaindex, CHAR_X); + iy=CHAR_getInt(fd_charaindex, CHAR_Y); + if( (ix!=x)||(iy!=y)){ + //print("\n--Error!!!!"); + //print("\norigion x=%d,y=%d",ix,iy); + //print("\nmodify X=%d,Y=%d",x,y); + x=ix; + y=iy; + } + } + CHAR_setMyPosition( fd_charaindex, x,y,TRUE); + + BATTLE_WatchTry( fd_charaindex ); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_Shutdown_recv( int fd,char* passwd,int min ) +{ + char buff[32]; + if( strcmp( passwd, "hogehoge") == 0 ) { + int i; + int playernum = CHAR_getPlayerMaxNum(); + snprintf( buff, sizeof( buff),"%s档",getGameservername()); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, buff, CHAR_COLORYELLOW); + } + } + SERVSTATE_setLimittime(min); + SERVSTATE_setShutdown( NowTime.tv_sec ); + SERVSTATE_setDsptime( 0 ); + } +} +void lssproto_PMSG_recv( int fd,int index,int petindex,int itemindex, + char* message,int color ) +{ + + // CoolFish: Prevent Trade Cheat 2001/4/18 + int fd_charaindex; + fd_charaindex = CONNECT_getCharaindex(fd); + + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; +#ifdef _STREET_VENDOR + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKSTREETVENDOR) != -1) + return; +#endif +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(fd_charaindex,CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + + if (CHAR_getWorkInt(fd_charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) + return; + PETMAIL_sendPetMail( CONNECT_getCharaindex( fd ), + index, petindex, itemindex, message, color); + +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_PS_recv( int fd, int havepetindex, int havepetskill, int toindex, char* data ) +{ + int charaindex = CONNECT_getCharaindex( fd ); + if(CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) !=BATTLE_CHARMODE_NONE )return; + int to_charaindex = Callfromcli_Util_getTargetCharaindex( fd, toindex); + int petindex; + BOOL ret; + petindex = CHAR_getCharPet( charaindex, havepetindex); + if( !CHAR_CHECKINDEX( petindex)) return; + + ret = PETSKILL_Use( petindex, havepetskill, to_charaindex, data ); + lssproto_PS_send( fd, ret, havepetindex, havepetskill, toindex); +} +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +void lssproto_SP_recv( int fd,int x,int y, int dir ) +{ + int fd_charaindex; + + fd_charaindex = CONNECT_getCharaindex( fd ); + {//ttom avoid the warp at will + int i_x,i_y; + i_x=CHAR_getInt(fd_charaindex, CHAR_X); + i_y=CHAR_getInt(fd_charaindex, CHAR_Y); + + if((i_x!=x)||(i_y!=y)){ + x=i_x; + y=i_y; + } + }//ttom + + CHAR_setMyPosition_main( fd_charaindex, x,y,dir,TRUE); + +} + +/*------------------------------------------------------------ + * CoolFish: Trade Command 2001/4/18 + ------------------------------------------------------------*/ +void lssproto_TD_recv( int fd, char* message ) +{ + int fd_charaindex; + CHECKFDANDTIME; + fd_charaindex = CONNECT_getCharaindex( fd ); + //printf("lssproto_TD_recv fd_charaindex=%d message=%d\n",fd_charaindex,message); + if(CHAR_getWorkInt(fd_charaindex,CHAR_WORKSTREETVENDOR) != -1){ + //printf("lssproto_TD_recv ̯״̬²ܽ\n",fd_charaindex); + + CHAR_talkToCli(fd_charaindex,-1,"̯״̬²ܽ",CHAR_COLORYELLOW); + return; + } + CHAR_Trade(fd, fd_charaindex, message); +} + +/*------------------------------------------------------------ + * CoolFish: Family Command 2001/5/24 + ------------------------------------------------------------*/ +void lssproto_FM_recv( int fd, char* message ) +{ + int fd_charaindex; + /* + struct timeval recvtime; + CHECKFDANDTIME; + + // add code by shan + CONNECT_getLastrecvtime( fd, &recvtime); + if( time_diff( NowTime, recvtime) < 0.5 ){ + return; + } + CONNECT_setLastrecvtime(fd, &NowTime); +*/ + fd_charaindex = CONNECT_getCharaindex( fd ); + + if( checkStringErr( message ) ) return; + + CHAR_Family(fd, fd_charaindex, message); + +} + +// shan 2002/01/10 +void lssproto_PETST_recv( int fd, int nPet, int sPet ) +{ + int charaindex; + int i, nums=0; + CHECKFDANDTIME; + + charaindex = CONNECT_getCharaindex( fd ); + if (!CHAR_CHECKINDEX( charaindex ) ) return; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return ; + + for( i=0; i<5; i++) { + if( CHAR_getWorkInt( charaindex, CHAR_WORK_PET0_STAT+i) == TRUE ) + nums++; + } + + if(nPet<0 )nPet=0; + if(nPet>4 )nPet=4; + + + if( nums <= 3 ){ + CHAR_setWorkInt( charaindex, CHAR_WORK_PET0_STAT+nPet, sPet); + } + + if(nPet != CHAR_getInt( charaindex, CHAR_DEFAULTPET)){ + lssproto_PETS_send(fd, nPet, sPet); + } +} + +#ifdef _MIND_ICON +void lssproto_MA_recv(int fd, int x, int y, int nMind) +{ + int charaindex; + CHECKFDANDTIME; + + charaindex = CONNECT_getCharaindex( fd); + if(!CHAR_CHECKINDEX( charaindex)) return; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; + + { + int i_x, i_y; + i_x = CHAR_getInt( charaindex, CHAR_X); + i_y = CHAR_getInt( charaindex, CHAR_Y); + + if((i_x!=x)||(i_y!=y)){ + x = i_x; + y = i_y; + } + } + + //print("\nshan------------------>mind action->%d x->%d y->%d", nMind, x, y); + CHAR_setMyPosition( charaindex, x, y, TRUE); + CHAR_setWorkInt( charaindex, CHAR_MIND_NUM, nMind); + CHAR_sendMindEffect( charaindex, CHAR_getWorkInt( charaindex, CHAR_MIND_NUM)); + if(CHAR_getWorkInt( charaindex, CHAR_MIND_NUM) != 101290 && + CHAR_getWorkInt( charaindex, CHAR_MIND_NUM) != 101294 && + CHAR_getWorkInt( charaindex, CHAR_MIND_NUM) != 101288 ) + CHAR_setWorkInt( charaindex, CHAR_MIND_NUM, 0); + //print("\nshan------------------>end"); + + return; +} +#endif +BOOL checkStringErr( char *checkstring ) +{ + int i,ach; + for (i=0,ach=0;i=0x40)&&((unsigned char)checkstring[i]<=0x7e))|| + (((unsigned char)checkstring[i]>=0xa1)&&((unsigned char)checkstring[i]<=0xfe))) ach=0; + } else { + if (((unsigned char)checkstring[i]>=0xa1)&&((unsigned char)checkstring[i]<=0xfe)) ach=1; + } + } + if (ach) + { + print(" StringDog! "); + return TRUE; + } + + return FALSE; + +} + +#ifdef _TEAM_KICKPARTY +void lssproto_KTEAM_recv( int fd, int si) +{ + int charaindex=-1, pindex; + if( si < 0 || si > 5 ) return; + charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( charaindex) ) return; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_LEADER ) return; + + pindex = CHAR_getWorkInt( charaindex, si + CHAR_WORKPARTYINDEX1); + if( !CHAR_CHECKINDEX( pindex) ) return; + if( CHAR_getWorkInt( pindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_LEADER ) return; + + if( CHAR_DischargeParty( pindex, 0) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "߳ʧܣ", CHAR_COLORYELLOW); + }else{ + char buf1[256]; + sprintf( buf1, "ӳ[%s]߳", CHAR_getUseName( charaindex )); + CHAR_talkToCli( pindex, -1, buf1, CHAR_COLORYELLOW); + sprintf( buf1, "[%s]߳Ŷӣ", CHAR_getUseName( pindex )); + CHAR_talkToCli( charaindex, -1, buf1, CHAR_COLORYELLOW); + } +} +#endif + +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +void lssproto_CHATROOM_recv (int fd , char *data) +{ + ChatRoom_recvall ( fd , data ) ; +} +#endif + +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +void lssproto_RESIST_recv (int fd ) +{ + int charindex = -1 ; + + char token[256]; + charindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX( charindex) ) return; + sprintf ( token , "%d|%d|%d|%d|%d|%d|%d|%d" , + CHAR_getInt( charindex, CHAR_EARTH_RESIST ) , + CHAR_getInt( charindex, CHAR_WATER_RESIST ) , + CHAR_getInt( charindex, CHAR_FIRE_RESIST ) , + CHAR_getInt( charindex, CHAR_WIND_RESIST ) , + CHAR_getInt( charindex, CHAR_EARTH_EXP ) , + CHAR_getInt( charindex, CHAR_WATER_EXP ) , + CHAR_getInt( charindex, CHAR_FIRE_EXP ) , + CHAR_getInt( charindex, CHAR_WIND_EXP ) + ); + lssproto_RESIST_send ( fd , token ) ; +} +#endif + +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +void lssproto_BATTLESKILL_recv (int fd, int iNum) +{ +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + int charaindex = CONNECT_getCharaindex( fd ); +#ifndef _PROSKILL_OPTIMUM + int skillindex=-1,char_pskill=-1,profession_skill=-1; +#endif + + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) return; + +#ifndef _PROSKILL_OPTIMUM // Robin fix cancel ˴Թְҵ, PROFESSION_SKILL_Use м + // ְҵ + char_pskill = CHAR_getInt( charaindex, PROFESSION_CLASS ); + + skillindex = PROFESSION_SKILL_GetArray( charaindex, iNum); + int Pskillid = skillindex; + // ְܵҵ + profession_skill = PROFESSION_SKILL_getInt( Pskillid, PROFESSION_SKILL_PROFESSION_CLASS); + + if( (char_pskill > 0) && (char_pskill == profession_skill) ){ +#else + if( 1 ){ +#endif + if( PROFESSION_SKILL_Use( charaindex, iNum, 0, NULL ) != 1 ){ + if(CHAR_getWorkInt( charaindex, CHAR_ENCOUNT_NUM)-(int)time(NULL)>0){ +// print("\n (%s)ʹüܴ!", CHAR_getUseName( charaindex ) ); +#ifdef _PROSKILL_ERR_KICK + CONNECT_setCloseRequest( fd , 1 ); +#endif + } + } + } +#endif +} + +#endif + +#ifdef _STREET_VENDOR +void lssproto_STREET_VENDOR_recv(int fd,char *message) +{ + int charaindex = CONNECT_getCharaindex(fd); + + if(!CHAR_CHECKINDEX(charaindex)) return; + +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(charaindex,CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + + if(CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return; + if(CHAR_getWorkInt(charaindex,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + CHAR_talkToCli(charaindex,-1,"״̬²ܽ",CHAR_COLORYELLOW); + return; + } + + CHAR_sendStreetVendor(charaindex,message); +} +#endif + +#ifdef _RIGHTCLICK +void lssproto_RCLICK_recv(int fd, int type, char* data) +{ + print("\n RCLICK_recv( type=%d data=%s) ", type, data); +} +#endif + +#ifdef _JOBDAILY +void lssproto_JOBDAILY_recv(int fd,char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); + if(!CHAR_CHECKINDEX(charaindex)) return; + + CHAR_JobDaily(charaindex,data); +} +#endif + +#ifdef _TEACHER_SYSTEM +void lssproto_TEACHER_SYSTEM_recv(int fd,char *data) +{ + int charaindex = CONNECT_getCharaindex(fd); + + if(!CHAR_CHECKINDEX(charaindex)) return; + CHAR_Teacher_system(charaindex,data); +} +#endif + +#ifdef _ASSESS_ABILITY +void lssproto_ASSESS_ABILITY_recv(int fd) +{ + int charaindex = CONNECT_getCharaindex(fd); + + if(!CHAR_CHECKINDEX(charaindex)) return; + + char data[512]; + char tmp[512]; + memset( data, 0, sizeof( data ) ); + int i; + for(i=0;i < 25; i++){ + sprintf(tmp, "%d|", CHAR_getInt(charaindex, CHAR_MATERIAL01 + i)); + strcat(data, tmp); + } + + lssproto_ASSESS_ABILITY_send(fd, data); +} +#endif + +#ifdef _ONLINE_SHOP +void lssproto_VIP_SHOP_recv(int fd, int type, int page) +{ + int charaindex = CONNECT_getCharaindex(fd); + + if(!CHAR_CHECKINDEX(charaindex)) return; + + OnlineShop_ShowList(fd, charaindex, type, page); +} + +void lssproto_VIP_SHOP_buy_recv(int fd, int type, int page, int id, int num) +{ + int charaindex = CONNECT_getCharaindex(fd); + + if(!CHAR_CHECKINDEX(charaindex)) return; + + + OnlineShop_Buy(fd, charaindex, type, page, id, num); +} +#endif + +void lssproto_SaMenu_recv( int fd, int index ) +{ + int charaindex; + int i, nums=0; + CHECKFDANDTIME; + + charaindex = CONNECT_getCharaindex( fd ); + if (!CHAR_CHECKINDEX( charaindex ) ) return; + FreeSaMenu(charaindex, index); +} + +#ifdef _FAMILYBADGE_ +void lssproto_FamilyBadge_recv(int fd) +{ + int charaindex = CONNECT_getCharaindex(fd); + if(!CHAR_CHECKINDEX(charaindex)) return; + LoadFamilyBadge(fd); +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/addressbook.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/addressbook.c new file mode 100644 index 0000000..bdd8ec1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/addressbook.c @@ -0,0 +1,946 @@ +#define __ADDRESSBOOK_C_ +#include "version.h" + +#include +#include +#include +#include + +#include "addressbook.h" +#include "char.h" +#include "handletime.h" +#include "buf.h" +#include "net.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "object.h" +#include "battle.h" +#include "configfile.h" +#include "npcutil.h" +#include "pet.h" +#include "petmail.h" +#include "log.h" + +/*ö⼰ ӮӮƱƥ ٯ Ӯ + ľƱ³*/ +#define ADDRESSBOOK_FIXEDMESSAGE_MAXLEN 128 + +/* м岾ئ׼ƥʧƤͱܰƥئ + 弰ö */ +#define ADDRESSBOOK_CANTADD "ûκˡ" +#define ADDRESSBOOK_CANTADD2 "޷Ƭ" + +/* ë³绥ƥб˪¶*/ +#define ADDRESSBOOK_ADDED "%sƬ " + +/* ӿëľ */ +#define ADDRESSBOOK_BEINGADDED "%sƬ " + +/* ޼з弰 */ +#define ADDRESSBOOK_MYTABLEFULL "Ƭϻ" + +/* 켰޼з弰 */ +#define ADDRESSBOOK_HISTABLEFULL "ԷƬϻ" + + +/* ë˪¼ */ +#define ADDRESSBOOK_SENT "Ÿ%s " + +/* ë˪¼ */ +#define ADDRESSBOOK_UNSENT "޷Ÿ%s " + +/* ë׻ȱ崴 */ +#define ADDRESSBOOK_ALREADYADDED "Ѿ%sƬˡ " + +/* ͭë */ +#define ADDRESSBOOK_GIVEADDRESS "%sõƬ" + +/* ͭë ؤ */ +#define ADDRESSBOOK_TAKEADDRESS1 "%sԼƬ" +/* ͭë ؤ */ +#define ADDRESSBOOK_TAKEADDRESS2 "Ϊ%sҪƬԽƬˡ" + +#define ADDRESSBOOK_RETURNED1 \ +"%sżû%sƬֽż˻ء" + +#define ADDRESSBOOK_RETURNED2 \ +"ż%s%s ûƬżֱ˻ˡ" + +#define PETMAIL_RETURNED1 \ +"%s޷ż" + + +/* staticƥã а*/ +char ADDRESSBOOK_returnstring[25*128]; + + + +static int ADDRESSBOOK_findBlankEntry( int cindex ); +static BOOL ADDRESSBOOK_makeEntryFromCharaindex( int charaindex, + ADDRESSBOOK_entry* ae); + +/*------------------------------------------------------------ + * ʧƤͼë˪ + * MSGᆴչľ£ + * + * ֧³練connectioncdkeyƥƻƽҷ + * գ MSG_send£۹м + * 켰ئئе֣ + * ¦ + * cindex int ƽҷ¼index + * aindex int ʧƤͼindex + * text char* ˪ ٯ + * color int + * ߯Ի + * ̼ƽҷ±嶪ë˪TRUE , + * ׷̼ FALSEë + ------------------------------------------------------------*/ +BOOL ADDRESSBOOK_sendMessage( int cindex, int aindex, char* text , int color ) +{ + int i ; + char tmpmsg[256]; + char textbuffer[2048]; + char *mycd; + char *mycharaname = CHAR_getChar(cindex,CHAR_NAME ); + struct tm tm1; + ADDRESSBOOK_entry *ae; + int playernum = CHAR_getPlayerMaxNum(); + + if( !CHAR_CHECKINDEX(cindex) )return FALSE; + + ae = CHAR_getAddressbookEntry( cindex , aindex ); + if( ae == NULL )return FALSE; + + //getcdkeyFromCharaIndex(cindex, mycd,sizeof(mycd) ); + mycd = CHAR_getChar( cindex, CHAR_CDKEY); + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + snprintf( textbuffer, sizeof( textbuffer), + "%2d/%02d %2d:%02d|%s|-1", + tm1.tm_mon +1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, + text); + + /* ӡ */ + for( i = 0 ; i < playernum ; i ++){ + if( CHAR_CHECKINDEX( i) && + strcmp( CHAR_getChar( i, CHAR_CDKEY), ae->cdkey) == 0 && + strcmp( CHAR_getChar( i, CHAR_NAME), ae->charname) == 0 ) + { + /* + * CDKEY ƽҷ ף۹ƽҷ + * ʧƤͱм ؤ¾Ʃͻ + * գMSG£ + */ + int index_to_my_info = + ADDRESSBOOK_getIndexInAddressbook( i , + mycd, mycharaname); + + int fd; + if( index_to_my_info < 0 ){ + /* + * 컥ëƻȻ£ + * ɱ бݶﻥ ɧ£ + */ + //snprintf( tmpmsg, sizeof( tmpmsg), + // ADDRESSBOOK_RETURNED1, + // ae->charname + // ); + + //CHAR_talkToCli( CONNECT_getCharaindex(i), -1, + // tmpmsg , CHAR_COLORYELLOW ); + + snprintf( tmpmsg, sizeof( tmpmsg), + ADDRESSBOOK_RETURNED2, + CHAR_getChar( i, CHAR_NAME), + CHAR_getChar( i, CHAR_NAME)); + + /* ˪ԻDZֶ */ + CHAR_talkToCli( cindex, -1, + tmpmsg , CHAR_COLORYELLOW ); + return FALSE; + } + + fd = getfdFromCharaIndex( i); + if( fd != -1 ) { + lssproto_MSG_send( fd , index_to_my_info , textbuffer , color ); + /* Ի */ + printl( LOG_TALK, "CD=%s\tNM=%s\tT=%s" , mycd, mycharaname, textbuffer ); + + } + + snprintf( tmpmsg , sizeof( tmpmsg),ADDRESSBOOK_SENT, + ae->charname ); + CHAR_talkToCli(cindex,-1, tmpmsg , color ); + + // WON ADD snprintfᵼµbug + { + char tmp[1000]; + sprintf( tmp , "ADDRESSBOOK_sendMessage:" + "Send MSG to: %s %s\n", + ae->cdkey , ae->charname ); + // print( tmp ); + } + + CHAR_setInt( cindex, CHAR_SENDMAILCOUNT, + CHAR_getInt( cindex, CHAR_SENDMAILCOUNT)+1); + return TRUE; + } + } + /* έئݷʧӡ˪ */ + saacproto_Message_send( acfd, mycd, mycharaname, + ae->cdkey, ae->charname, textbuffer, color); + CHAR_setInt( cindex, CHAR_SENDMAILCOUNT, + CHAR_getInt( cindex, CHAR_SENDMAILCOUNT)+1); + + + snprintf( tmpmsg , sizeof( tmpmsg),ADDRESSBOOK_SENT,ae->charname ); + CHAR_talkToCli( cindex,-1, tmpmsg , CHAR_COLORWHITE ); + + return FALSE; +} +/*------------------------------------------------------------ + * ʧƤͼë˪ + * saac msg ëȻͷʧ̵£ + * + * ߯Ի + ------------------------------------------------------------*/ +BOOL ADDRESSBOOK_sendMessage_FromOther( char *fromcdkey, char *fromcharaname, + char *tocdkey, char *tocharaname, + char* text , int color ) +{ +#define ADDRESSBOOK_SYSTEM "system" + + int i ; + char tmpmsg[256]; + int playernum = CHAR_getPlayerMaxNum(); + + /* ӡ ë */ + for( i = 0 ; i < playernum ; i ++){ + if( CHAR_CHECKINDEX( i) && + strcmp( CHAR_getChar( i, CHAR_CDKEY), tocdkey) == 0 && + strcmp( CHAR_getChar( i, CHAR_NAME), tocharaname) == 0) + { + int index_to_my_info; + /* + * CDKEY ƽҷ ף۹ƽҷ + * ʧƤͱм ؤ¾Ʃͻ + * գMSG£ + */ + + /* ˵ ة⻥Ȼ */ + if( strcmp( fromcdkey, ADDRESSBOOK_SYSTEM) == 0 && + strcmp( fromcharaname, ADDRESSBOOK_SYSTEM ) == 0 ) + { + /* ˵ ةë */ + CHAR_talkToCli( i, -1, text , color ); + break; + } + + index_to_my_info = + ADDRESSBOOK_getIndexInAddressbook( i , + fromcdkey, fromcharaname); + if( index_to_my_info < 0 ){ + /* + * 컥ëƻȻ£ + */ + + snprintf( tmpmsg, sizeof( tmpmsg), ADDRESSBOOK_RETURNED2, + tocharaname, tocharaname); + + /* ˪ԻDZֶ */ + saacproto_Message_send( acfd, ADDRESSBOOK_SYSTEM , ADDRESSBOOK_SYSTEM, + fromcdkey, fromcharaname, tmpmsg, CHAR_COLORYELLOW); + + } + else { + int fd = getfdFromCharaIndex( i); + if( fd != -1 ) { + lssproto_MSG_send( fd , index_to_my_info , text , color ); + /* Ի */ + printl( LOG_TALK, "CD=%s\tNM=%s\tT=%s" , fromcdkey, + fromcharaname, text ); + } + } + break; + } + } + if( i == playernum ) return FALSE; + return TRUE; +} + +int ADDRESSBOOK_getIndexInAddressbook(int cindex , char *cdkey, + char *charname) +{ + int i ; + + if( !CHAR_CHECKINDEX( cindex ) ) return -1; + + for( i = 0 ; i < ADDRESSBOOK_MAX ; i++){ + ADDRESSBOOK_entry *ae = CHAR_getAddressbookEntry( cindex , i ); + if( ae && ae->use && strcmp( ae->cdkey, cdkey )==0 && + strcmp( ae->charname , charname ) == 0 ){ + return i; + } + } + return -1; +} + +BOOL ADDRESSBOOK_deleteEntry( int meindex ,int index ) +{ + ADDRESSBOOK_entry ent; + BOOL ret; + if( !CHAR_CHECKINDEX( meindex ) ) return FALSE; + + memset( &ent ,0, sizeof( ADDRESSBOOK_entry )); + ret = CHAR_setAddressbookEntry( meindex , index , &ent ); + if( ret == TRUE ){ + ADDRESSBOOK_sendAddressbookTable( meindex ); + return TRUE; + } + return FALSE; +} + +BOOL ADDRESSBOOK_addEntry( int meindex ) +{ + int objbuf[20]; + int found_count; + int front_x , front_y; + int i; + int cnt = 0; + int fd; + char *mycd , *tocd; + BOOL found = FALSE; + + if( !CHAR_CHECKINDEX( meindex ) )return FALSE; + + fd = getfdFromCharaIndex( meindex); + if( fd == -1 ) return FALSE; + + if( ADDRESSBOOK_findBlankEntry( meindex ) < 0) { + CHAR_talkToCli( meindex , -1,ADDRESSBOOK_MYTABLEFULL,CHAR_COLORWHITE ); + return FALSE; + } + + for( i = 0; i < CONNECT_WINDOWBUFSIZE; i ++ ) { + CONNECT_setTradecardcharaindex( fd,i,-1); + } + + CHAR_getCoordinationDir( CHAR_getInt( meindex, CHAR_DIR ) , + CHAR_getInt( meindex , CHAR_X ), + CHAR_getInt( meindex , CHAR_Y ) , + 1 , &front_x , &front_y ); + + found_count = CHAR_getSameCoordinateObjects( objbuf, + arraysizeof( objbuf), + CHAR_getInt(meindex,CHAR_FLOOR), + front_x,front_y ); + if( found_count == 0 ){ + CHAR_talkToCli( meindex, -1, ADDRESSBOOK_CANTADD, CHAR_COLORWHITE); + return FALSE; + } + for( i = 0 ; i < found_count; i++ ){ + int objindex = objbuf[i]; + int index = OBJECT_getIndex( objindex); + if( OBJECT_getType(objindex) != OBJTYPE_CHARA ) { + continue; + } + if( CHAR_getInt( index,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + continue; + } + if( index == meindex ) { + continue; + } + found = TRUE; + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) { + continue; + } + if(!CHAR_getFlg( index, CHAR_ISTRADECARD)) { + continue; + } + if( ADDRESSBOOK_findBlankEntry( index ) < 0 ) { + continue; + } + tocd = CHAR_getChar( index, CHAR_CDKEY); + mycd = CHAR_getChar( meindex, CHAR_CDKEY); + if( ADDRESSBOOK_getIndexInAddressbook( meindex, tocd, + CHAR_getChar( index, CHAR_NAME)) >= 0 && + ADDRESSBOOK_getIndexInAddressbook( index, mycd, + CHAR_getChar(meindex, CHAR_NAME) ) >= 0 ) { + continue; + } + + CONNECT_setTradecardcharaindex( fd,cnt,index); + cnt ++; + if( cnt == CONNECT_WINDOWBUFSIZE ) break; + } + + if( cnt == 0 ) { + if( found ) { + CHAR_talkToCli( meindex, -1, ADDRESSBOOK_CANTADD2, CHAR_COLORWHITE); + }else { + CHAR_talkToCli( meindex, -1, ADDRESSBOOK_CANTADD, CHAR_COLORWHITE); + } + return FALSE; + } + if( cnt == 1 ) { + ADDRESSBOOK_addAddressBook( meindex, + CONNECT_getTradecardcharaindex(fd,0) ); + return TRUE; + }else if( cnt > 1 ) { + int strlength; + char msgbuf[1024]; + char escapebuf[2048]; + strcpy( msgbuf, "1\n˭Ƭأ\n"); + strlength = strlen( msgbuf); + for( i = 0; + CONNECT_getTradecardcharaindex(fd,i) != -1 + && i< CONNECT_WINDOWBUFSIZE; i ++ ){ + char *a = CHAR_getChar( CONNECT_getTradecardcharaindex(fd,i), + CHAR_NAME); + char buf[256]; + snprintf( buf, sizeof( buf),"%s\n", a); + if( strlength + strlen( buf) > arraysizeof( msgbuf)){ + print( "%s:%dӴѶϢbuffer㡣\n", + __FILE__,__LINE__); + break; + } + strcpy( &msgbuf[strlength], buf); + strlength += strlen(buf); + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SELECTTRADECARD, + -1, + makeEscapeString( msgbuf, escapebuf, sizeof(escapebuf))); + return TRUE; + } + + return FALSE; +} + +static int ADDRESSBOOK_findBlankEntry( int cindex ) +{ + int i; + + if( CHAR_CHECKINDEX( cindex ) == FALSE )return -1; + + for( i=0 ; iuse == FALSE ) { + return i; + } + } + return -1; +} + +static BOOL ADDRESSBOOK_makeEntryFromCharaindex( int charaindex, + ADDRESSBOOK_entry* ae) +{ + char *cdkey; + + if( !CHAR_CHECKINDEX(charaindex) ) return FALSE; + + memset( ae,0,sizeof(ADDRESSBOOK_entry) ); + cdkey = CHAR_getChar( charaindex, CHAR_CDKEY); + if( cdkey == "\0" ){ + print( "ADDRESSBOOK_makeEntryFromCharaindex:" + " strange! getcdkeyFromCharaIndex returns NULL!" + " charaindex: %d\n" , charaindex ); + return FALSE; + } + strcpysafe( ae->cdkey , sizeof( ae->cdkey ),cdkey); + + strcpysafe( ae->charname,sizeof( ae->charname), + CHAR_getChar(charaindex,CHAR_NAME) ); + ae->level = CHAR_getInt( charaindex , CHAR_LV ); + ae->duelpoint = CHAR_getInt( charaindex, CHAR_DUELPOINT); + ae->graphicsno = CHAR_getInt( charaindex , CHAR_FACEIMAGENUMBER ); + ae->online = getServernumber(); + ae->use = TRUE; + ae->transmigration = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION); + + return TRUE; +} + +void ADDRESSBOOK_notifyLoginLogout( int cindex , int flg ) +{ + int i; + char *cd=NULL; + char *nm = CHAR_getChar( cindex , CHAR_NAME ); + int playernum = CHAR_getPlayerMaxNum(); + + if( !CHAR_CHECKINDEX( cindex ) )return; + cd = CHAR_getChar( cindex, CHAR_CDKEY); + + CHAR_send_DpDBUpdate_AddressBook( cindex, flg ); + + for( i = 0 ; i < playernum ; i++){ + if( CHAR_CHECKINDEX( i) && i != cindex ) { + int j; + for( j = 0 ; juse == TRUE && + strcmp( ae->cdkey , cd ) == 0 && + strcmp( ae->charname, nm ) == 0 ){ + + ae->online = (flg == 0 ) ? 0: getServernumber(); + ae->level = CHAR_getInt( cindex , CHAR_LV ); + ae->duelpoint = CHAR_getInt( cindex, CHAR_DUELPOINT); + ae->graphicsno = CHAR_getInt( cindex, CHAR_FACEIMAGENUMBER ); + ae->transmigration = CHAR_getInt( cindex, CHAR_TRANSMIGRATION); + + ADDRESSBOOK_sendAddressbookTableOne( i,j ); + + break; + } + } + } + } + + if( flg == 0 ){ + saacproto_Broadcast_send( acfd,cd, nm, "offline", 1); + }else if( flg == 1 ) { + for( i = 0 ; i < ADDRESSBOOK_MAX; i++ ){ + int j; + ADDRESSBOOK_entry* ae; + ae = CHAR_getAddressbookEntry( cindex, i ); + if( ae->use == 0 )continue; + ae->online = 0; + for( j=0 ; j < playernum ; j++ ) { + if( CHAR_CHECKINDEX( j) && + strcmp( ae->cdkey, CHAR_getChar( j, CHAR_CDKEY)) == 0 && + strcmp( ae->charname, CHAR_getChar( j, CHAR_NAME) )== 0){ + ae->level = CHAR_getInt( j, CHAR_LV ); + ae->graphicsno = CHAR_getInt( j, CHAR_FACEIMAGENUMBER ); + ae->online = getServernumber(); + ae->transmigration = CHAR_getInt( j, CHAR_TRANSMIGRATION); + break; + } + } + if( j == playernum) { + char buff[512]; + char escapebuf[1024]; + ae->online = 0; + snprintf( buff, sizeof(buff), "%s_%s", ae->cdkey, ae->charname); + makeEscapeString( buff, escapebuf, sizeof(escapebuf)); + saacproto_DBGetEntryString_send( acfd, DB_ADDRESSBOOK, escapebuf, 0,0); + } + } + ADDRESSBOOK_sendAddressbookTable(cindex); + saacproto_Broadcast_send( acfd,cd, nm, "online", 1); + saacproto_MessageFlush_send( acfd, cd, nm); + } +} + +BOOL ADDRESSBOOK_sendAddressbookTable( int cindex ) +{ + int stringlen=0; + int i; + + if( !CHAR_CHECKINDEX( cindex ) )return FALSE; + + for( i=0 ; iuse ){ + char tmp[CHARNAMELEN+32]; + char charname_escaped[CHARNAMELEN*2]; + makeEscapeString( ae->charname, charname_escaped , + sizeof(charname_escaped )); + /* ð׷º| |ì|̰|׷º */ + snprintf( tmp , sizeof( tmp ), +#ifdef _VERSION_NEW + "%d|%s|%d|%d|%d|%d|%d|0|" , +#else +#ifdef _NEW_SA80 + "%d|%s|%d|%d|%d|%d|%d|0|" , +#else + "%d|%s|%d|%d|%d|%d|%d|" , +#endif +#endif + ae->use, + charname_escaped , ae->level , + ae->duelpoint,ae->online,ae->graphicsno, + ae->transmigration); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); + stringlen += strlen( tmp ); + if( stringlen >= sizeof(ADDRESSBOOK_returnstring) ) { + break; + } + }else{ + /*Ȼئзֳ߼ƥ˪ */ + char tmp[32]; +#ifdef _VERSION_NEW + snprintf( tmp , sizeof( tmp ), "||||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#else +#ifdef _NEW_SA80 + snprintf( tmp , sizeof( tmp ), "||||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#else + snprintf( tmp , sizeof( tmp ), "|||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#endif +#endif + stringlen += strlen( tmp ); + if( stringlen >= sizeof(ADDRESSBOOK_returnstring)) { + break; + } + } + } + + dchop( ADDRESSBOOK_returnstring, "|" ); + + { + int fd; + fd = getfdFromCharaIndex( cindex ); + if( fd == -1 ) return FALSE; + lssproto_AB_send( fd, ADDRESSBOOK_returnstring ); + } + return TRUE; +} + +BOOL ADDRESSBOOK_sendAddressbookTableOne( int cindex, int num ) +{ + int stringlen=0; + ADDRESSBOOK_entry *ae; + + if( !CHAR_CHECKINDEX( cindex ) )return FALSE; + if( num < 0 || num > ADDRESSBOOK_MAX) return FALSE; + + ae = CHAR_getAddressbookEntry( cindex , num ); + + if( ae && ae->use ){ + char tmp[CHARNAMELEN+32]; + char charname_escaped[CHARNAMELEN*2]; + makeEscapeString( ae->charname, charname_escaped , + sizeof(charname_escaped )); + snprintf( tmp , sizeof( tmp ), + "%d|%s|%d|%d|%d|%d|%d|" , + ae->use, + charname_escaped , ae->level , + ae->duelpoint,ae->online,ae->graphicsno, + ae->transmigration); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); + stringlen += strlen( tmp ); + if( stringlen >= sizeof(ADDRESSBOOK_returnstring) ) { + return FALSE; + } + }else{ + char tmp[32]; +#ifdef _NEW_SA80 + snprintf( tmp , sizeof( tmp ), "||||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#else +#ifdef _NEW_SA80 + snprintf( tmp , sizeof( tmp ), "||||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#else + snprintf( tmp , sizeof( tmp ), "|||||||" ); + strcpysafe ( ADDRESSBOOK_returnstring + stringlen , + sizeof(ADDRESSBOOK_returnstring) - stringlen, + tmp ); +#endif +#endif + stringlen += strlen( tmp ); + if( stringlen >= sizeof(ADDRESSBOOK_returnstring)) { + return FALSE; + } + } + + { + int fd; + fd = getfdFromCharaIndex( cindex ); + if( fd == -1 ) return FALSE; + lssproto_ABI_send( fd, num, ADDRESSBOOK_returnstring ); + } + return TRUE; +} + +/*------------------------------------------------------------ + * 繴ʧƤ;޼ë ٯ ئʣ + * ľƽҷئƥͷʧ˪·ԻֿҸ + * ئּƥؤ ۢؤ£ + * ¦ + * a ADDRESSBOOK_entry* ٯ հ ߼̼ + * ߯Ի + * char * + ------------------------------------------------------------*/ +char *ADDRESSBOOK_makeAddressbookString( ADDRESSBOOK_entry *a ) +{ + char work1[256], work2[256]; + + if( a->use == 0 ){ + /* ޼ ٯ */ + ADDRESSBOOK_returnstring[0] = '\0'; + return ADDRESSBOOK_returnstring; + } + + makeEscapeString( a->cdkey, work1, sizeof( work1 )); + makeEscapeString( a->charname , work2 , sizeof( work2 )); + snprintf( ADDRESSBOOK_returnstring, + sizeof( ADDRESSBOOK_returnstring ), + "%s|%s|%d|%d|%d|%d", + work1, work2, a->level, a->duelpoint, a->graphicsno,a->transmigration); + + return ADDRESSBOOK_returnstring; + +} + +/*------------------------------------------------------------ + * ٯ ľʧƤ;޼ëհ ئʣ + * հ use½ ձئ£ + * ¦ + * in char* ٯ + * a ADDRESSBOOK_entry* ë谻 + * ߯Ի + * ѱTRUE + ------------------------------------------------------------*/ +BOOL ADDRESSBOOK_makeAddressbookEntry( char *in , ADDRESSBOOK_entry *a ) +{ + char work1[256], work2[256] , work3[256] , work4[256],work5[256],work6[256]; + int ret; + if( strlen( in ) == 0 ){ + memset( a,0,sizeof(ADDRESSBOOK_entry) ); + a->use = 0; + return TRUE; + } + + getStringFromIndexWithDelim( in, "|" , 1 , work1 , sizeof( work1 )); + getStringFromIndexWithDelim( in, "|" , 2 , work2 , sizeof( work2 )); + getStringFromIndexWithDelim( in, "|" , 3 , work3 , sizeof( work3 )); + getStringFromIndexWithDelim( in, "|" , 4 , work4 , sizeof( work4 )); + getStringFromIndexWithDelim( in, "|" , 5 , work5 , sizeof( work5 )); + work6[0] = '\0'; + ret = getStringFromIndexWithDelim( in, "|" , 6 , work6 , sizeof( work6 )); + if( ret == FALSE ) { + a->transmigration = 0; + } + else { + a->transmigration = atoi( work6); + } + a->use = 1; + + makeStringFromEscaped( work1 ); + makeStringFromEscaped( work2 ); + + strcpysafe( a->cdkey , sizeof(a->cdkey) , work1 ); + strcpysafe( a->charname , sizeof(a->charname), work2 ); + + a->level = atoi( work3 ); + a->duelpoint = atoi( work4 ); + a->graphicsno = atoi( work5 ); + + return FALSE; +} + +void ADDRESSBOOK_addAddressBook( int meindex, int toindex) +{ + char tmpstring[CHARNAMELEN + + ADDRESSBOOK_FIXEDMESSAGE_MAXLEN]; + + int hisblank; + int myblank; + int myaddindex, toaddindex; + int dir; + char *cdkey; + + hisblank = ADDRESSBOOK_findBlankEntry( toindex ); + if( hisblank < 0 ) { + CHAR_talkToCli( meindex, -1, ADDRESSBOOK_HISTABLEFULL, CHAR_COLORWHITE); + return ; + } + myblank = ADDRESSBOOK_findBlankEntry( meindex ); + if( myblank < 0 ){ + CHAR_talkToCli( meindex , -1, ADDRESSBOOK_MYTABLEFULL, CHAR_COLORWHITE ); + return ; + } + + cdkey = CHAR_getChar( toindex, CHAR_CDKEY); + myaddindex = ADDRESSBOOK_getIndexInAddressbook( meindex, cdkey, + CHAR_getChar( toindex, CHAR_NAME)); + cdkey = CHAR_getChar( meindex, CHAR_CDKEY); + toaddindex = ADDRESSBOOK_getIndexInAddressbook( toindex, cdkey, + CHAR_getChar(meindex, CHAR_NAME)); + if( myaddindex < 0 ){ + ADDRESSBOOK_entry hisentry; + + if( ADDRESSBOOK_makeEntryFromCharaindex(toindex,&hisentry) == FALSE ){ + return ; + } + CHAR_setAddressbookEntry( meindex, myblank,&hisentry ); + + snprintf( tmpstring, sizeof( tmpstring), + toaddindex < 0 ? ADDRESSBOOK_ADDED: ADDRESSBOOK_GIVEADDRESS, + hisentry.charname); + CHAR_talkToCli( meindex , -1,tmpstring, CHAR_COLORWHITE ); + ADDRESSBOOK_sendAddressbookTableOne( meindex, myblank); + }else{ + snprintf( tmpstring, sizeof( tmpstring), ADDRESSBOOK_TAKEADDRESS1, + CHAR_getChar( toindex, CHAR_NAME)); + CHAR_talkToCli( meindex, -1, tmpstring, CHAR_COLORWHITE); + + } + if( toaddindex < 0 ) { + ADDRESSBOOK_entry meae; + if( ADDRESSBOOK_makeEntryFromCharaindex(meindex,&meae) == FALSE) { + return; + } + CHAR_setAddressbookEntry( toindex, hisblank,&meae ); + snprintf( tmpstring , sizeof( tmpstring), + myaddindex < 0 ? ADDRESSBOOK_ADDED : ADDRESSBOOK_GIVEADDRESS, + CHAR_getChar( meindex, CHAR_NAME ) ); + CHAR_talkToCli( toindex, -1, tmpstring, CHAR_COLORWHITE); + ADDRESSBOOK_sendAddressbookTableOne( toindex , hisblank); + }else { + if( myaddindex < 0 ) { + snprintf( tmpstring , sizeof( tmpstring), + ADDRESSBOOK_TAKEADDRESS2, + CHAR_getChar( meindex, CHAR_NAME ) ); + CHAR_talkToCli( toindex, -1, tmpstring, CHAR_COLORWHITE); + } + } + dir = NPC_Util_GetDirCharToChar( toindex, meindex, 0); + if( dir != -1) { + + if( CHAR_getInt( toindex, CHAR_DIR) != dir) { + CHAR_setInt( toindex, CHAR_DIR, dir); + } + CHAR_sendWatchEvent( CHAR_getWorkInt( toindex, CHAR_WORKOBJINDEX), + CHAR_ACTNOD,NULL,0,TRUE); + CHAR_setWorkInt( toindex, CHAR_WORKACTION, CHAR_ACTNOD); + CHAR_sendWatchEvent( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + CHAR_ACTNOD,NULL,0,TRUE); + CHAR_setWorkInt( meindex, CHAR_WORKACTION, CHAR_ACTNOD); + } + return; +} + + +void ADDRESSBOOK_DispatchMessage( char *cd, char *nm, char *value, int mode) +{ + int i; + char work[256]; + int online,level,duelpoint, faceimagenumber, transmigration; + int playernum = CHAR_getPlayerMaxNum(); + int ret; + + getStringFromIndexWithDelim( value, "|" , 1 , work , sizeof( work )); + online = atoi( work); + getStringFromIndexWithDelim( value, "|" , 2 , work , sizeof( work )); + level = atoi( work); + getStringFromIndexWithDelim( value, "|" , 3 , work , sizeof( work )); + duelpoint = atoi( work); + getStringFromIndexWithDelim( value, "|" , 4 , work , sizeof( work )); + faceimagenumber = atoi( work); + ret = getStringFromIndexWithDelim( value, "|" , 5 , work , sizeof( work )); + if( ret ) { + transmigration = atoi( work); + } + else { + transmigration = 0; + } +/* + if( online == getServernumber()) { + for( i = 0 ; i < playernum ; i++) { + if( CHAR_CHECKINDEX( i )) { + char *c = CHAR_getChar( i, CHAR_CDKEY); + char *n = CHAR_getChar( i, CHAR_NAME); + if( c == "\0" || n == "\0" ) continue; + if( strcmp( c , cd ) == 0 && strcmp( n, nm ) == 0 ) { + break; + } + } + } + if( i == playernum ) { + online = 0; + saacproto_Broadcast_send( acfd,cd, nm, "offline", 1); + } + } +*/ + for( i = 0 ; i < playernum ; i++) { + if( CHAR_CHECKINDEX( i )) { + int j; + for( j = 0 ; j < ADDRESSBOOK_MAX ; j++) { + ADDRESSBOOK_entry *ae; + ae = CHAR_getAddressbookEntry( i ,j ); + if( ae && ae->use == TRUE && + strcmp( ae->cdkey , cd ) == 0 && + strcmp( ae->charname, nm ) == 0 ) + { + if( mode == 0 ) { + ae->use = FALSE; + }else { + ae->online = online; + ae->level = level; + ae->duelpoint = duelpoint; + ae->graphicsno = faceimagenumber; + ae->transmigration = transmigration; + } + ADDRESSBOOK_sendAddressbookTableOne( i,j ); + + break; + } + } + } + } +} + +#ifdef _ANGLE_EMAIL +BOOL ADDRESSBOOK_AutoaddAddressBook( int meindex, int toindex) +{ + int hisblank; + int myblank; + int myaddindex, toaddindex; + + char *cdkey; + +// myblank = ADDRESSBOOK_findBlankEntry( meindex ); +// hisblank = ADDRESSBOOK_findBlankEntry( toindex ); + + myblank = 79; + hisblank = 79; + + if( hisblank < 0 || myblank < 0) { //"Ƭϻ" + return FALSE; + } + + cdkey = CHAR_getChar( toindex, CHAR_CDKEY); + myaddindex = ADDRESSBOOK_getIndexInAddressbook( meindex, cdkey, + CHAR_getChar( toindex, CHAR_NAME)); + cdkey = CHAR_getChar( meindex, CHAR_CDKEY); + toaddindex = ADDRESSBOOK_getIndexInAddressbook( toindex, cdkey, + CHAR_getChar(meindex, CHAR_NAME)); + if( myaddindex < 0 ){ + ADDRESSBOOK_entry meae; + ADDRESSBOOK_entry hisentry; + if( ADDRESSBOOK_makeEntryFromCharaindex(toindex,&hisentry) == FALSE || + ADDRESSBOOK_makeEntryFromCharaindex(meindex,&meae) == FALSE ){ + return FALSE; + } + CHAR_setAddressbookEntry( meindex, myblank,&hisentry ); + CHAR_setAddressbookEntry( toindex, hisblank,&meae ); + ADDRESSBOOK_sendAddressbookTableOne( meindex, myblank); + ADDRESSBOOK_sendAddressbookTableOne( toindex , hisblank); + } + return TRUE; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char.c new file mode 100644 index 0000000..f2e827c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char.c @@ -0,0 +1,11543 @@ +#include "version.h" +#include +#include +#include +#include // shan +#include +#include +#include +#include +#include "net.h" +#include "common.h" +#include "char_base.h" +#include "char_data.h" +#include "char.h" +#include "lssproto_serv.h" +#include "item.h" +#include "item_event.h" +#include "buf.h" +#include "object.h" +#include "map_deal.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "handletime.h" +#include "char_event.h" +#include "npccreate.h" +#include "addressbook.h" +#include "item_event.h" +#include "magic_base.h" +#include "magic.h" +#include "chatmagic.h" +#include "configfile.h" +#include "log.h" +#include "anim_tbl.h" +#include "encount.h" +#include "battle.h" +#include "pet_skill.h" +#include "util.h" +#include "enemy.h" +#include "npcutil.h" +#include "pet.h" +#include "family.h" +#include "correct_bug.h" +#ifdef _JOBDAILY +#include "npc_checkman.h" +#endif +#include "autil.h" +#ifdef _CHAR_PROFESSION // WON ADD ְҵλ +#include "profession_skill.h" +#endif +#ifdef _CHARADATA_SAVE_SQL +#include "longzoro/characters.h" +#endif +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#include "npc_autopk.h" +#ifdef _SASQL +#include "longzoro/sasql.h" +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +#include "chatroom.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#ifdef _NPC_EVENT_NOTICE +#include "npcutil.h" +#endif +extern int channelMember[FAMILY_MAXNUM][FAMILY_MAXCHANNEL][FAMILY_MAXMEMBER]; +extern int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + +extern tagRidePetTable ridePetTable[296]; +extern int BATTLE_getRidePet( int charaindex ); + +#ifdef _CHANNEL_MODIFY +extern int InitOccChannel(void); +#endif + +#ifdef _ABSOLUTE_DEBUG +extern int debugline; +#endif +#ifdef _OFFLINE_SYSTEM +extern int playeronlinenum; +#endif +#ifdef _ANGEL_SUMMON +extern int checkIfAngelByName( char* nameinfo); +extern char* getMissionNameInfo( int charaindex, char* nameinfo); +extern void CHAR_sendAngelMark( int objindex, int flag); +extern int checkIfOnlyAngel( int charaindex); +extern void selectAngel( int charaindex, int heroindex, int mission, int gm_cmd); +#endif +int CharaData( int sockfd, Char* ch ); +extern void GOLD_DeleteTimeCheckOne( int objindex); + +// WON ADD ߵ趨 +void fix_item_bug(int charaindex, int i); + +#ifdef _RED_MEMOY_ +void CHAR_RedMemoy_WindowResult( int charaindex,char * data); +#endif + +/*====================κ˴ؤؿ====================*/ +/*------------------------------------------------------------ + * Υץͤꤷ褦Ȥ롣 + * + * ch Char* ΥΥǡ + * option char* 饤Ȥ餯ǡ + * ֤ + * TRUE + * FALSE + ------------------------------------------------------------*/ +#ifdef _FAMILYBADGE_ +extern int getFamilyBadge(int index); +#endif +static BOOL CHAR_makeCharFromOptionAtCreate( Char* ch , + int vital, int str, int tgh, int dex, + int earth, int water, int fire, int wind) +{ + + /* ͭθڤԤ */ + int para[4]; + int attr[4]; + int i; + int parasum,attrsum; + int cnt; + + para[0] = vital; + para[1] = str; + para[2] = tgh; + para[3] = dex; + + attr[0] = earth; + attr[1] = water; + attr[2] = fire; + attr[3] = wind; + +#define MAXPARAMETER 20 +#define PKMAXPARAMETER 300 + parasum = 0; + /* + * ٤ƤΥǡ - ϤäƤϤʤʤ + * 夢դλͤƤƺͤĶʤ + */ + + for( i = 0; i < arraysizeof( para); i ++ ) { + if( para[i] < 0 || para[i] > MAXPARAMETER )return FALSE; + parasum += para[i]; + } +#ifdef _NEW_PLAYER_CF //ֳ + if( parasum > MAXPARAMETER ) return FALSE; +#else + if( parasum != MAXPARAMETER ) return FALSE; +#endif + +#undef MAXPARAMETER + + +#define MAXATTRIBUTE 10 + cnt = 0; + attrsum = 0; + /* °Υå򤹤 */ + for( i = 0; i < arraysizeof( para); i ++ ) { + if( attr[i] < 0 || attr[i] > MAXATTRIBUTE )return FALSE; + attrsum += attr[i]; + if( attr[i] > 0 ) cnt ++; + } + /* ͤ10 */ + if( attrsum != MAXATTRIBUTE ) return FALSE; + + /* 2Ĥ¿ƤƤ */ + if( cnt > 2 ) return FALSE; + + /* °ϳƤʤ */ + if( attr[0] > 0 && attr[2] > 0 ) return FALSE; + if( attr[1] > 0 && attr[3] > 0 ) return FALSE; + +#undef MAXATTRIBUTE + + /* */ + ch->data[CHAR_VITAL] = vital*100; + ch->data[CHAR_STR] = str*100; + ch->data[CHAR_TOUGH] = tgh*100; + ch->data[CHAR_DEX] = dex*100; + + ch->data[CHAR_EARTHAT] = attr[0] * 10; + ch->data[CHAR_WATERAT] = attr[1] * 10; + ch->data[CHAR_FIREAT] = attr[2] * 10; + ch->data[CHAR_WINDAT] = attr[3] * 10; +#ifdef _NEWOPEN_MAXEXP + ch->data[CHAR_OLDEXP] = 0; +#endif + ch->data[CHAR_EXP] = 0; + + +#ifdef _NEW_PLAYER_CF //ֳ + ch->data[CHAR_TRANSMIGRATION] = getNewplayertrans(); + ch->data[CHAR_GOLD] = getNewplayergivegold();; + ch->data[CHAR_LV] = getNewplayerlv(); +#ifdef _VIP_SERVER + ch->data[CHAR_AMPOINT] = getNewplayergivevip(); +#endif +// ch->data[CHAR_LEARNRIDE] = 200; +// ch->data[CHAR_LASTTALKELDER] = (rand()%10)>5?35:36;//34; +// ch->data[CHAR_SKILLUPPOINT] = 616;//600; +#ifdef _NEW_RIDEPETS + //ch->data[CHAR_LOWRIDEPETS] = 0xffffffff; +#endif +#endif + +#ifdef _PETSKILL_BECOMEPIG + ch->data[CHAR_BECOMEPIG] = -1; + ch->data[CHAR_BECOMEPIG_BBI] = 100250; +#endif + + ch->data[CHAR_LASTLEAVETIME] = 0; + + return TRUE; +} + +#ifdef _HELP_NEWHAND +void CHAR_loginAddItemForNew( int charindex ) +{ + int emptyitemindexinchara, itemindex; + int i; + char msgbuf[128]; + + for( i = 0; i < 15; i ++ ) { + emptyitemindexinchara = CHAR_findEmptyItemBox( charindex ); + + if( emptyitemindexinchara < 0 ){ + sprintf( msgbuf, "ռλ㡣" ); + + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + return; + } +#ifdef _NEW_PLAYER_CF + if(getNewplayergiveitem(i)==-1)continue; + itemindex = ITEM_makeItemAndRegist( getNewplayergiveitem(i) ); +#endif + if( itemindex != -1 ){ + CHAR_setItemIndex( charindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charindex); + CHAR_sendItemDataOne( charindex, emptyitemindexinchara); + } + } + //print("Get New Hand Item"); +} +#endif + +void CHAR_createNewChar( int clifd, int dataplacenum, char* charname , + int imgno,int faceimgno, + int vital,int str,int tgh,int dex, + int earth,int water,int fire,int wind, + int hometown , char *cdkey ) +{ + + Char ch, *chwk; + int charaindex; + char szKey[256]; + +#ifdef _NEW_PLAYER_CF //ֳ + int add_pet[]={-1,-1,-1,-1,-1}; +#endif + + memset(&ch,0,sizeof(Char)); + + if( !CHAR_checkPlayerImageNumber( imgno)) { + lssproto_CreateNewChar_send( clifd ,FAILED, "" ); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + if( !CHAR_checkFaceImageNumber( imgno, faceimgno)) { + lssproto_CreateNewChar_send( clifd ,FAILED, "" ); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + CHAR_getDefaultChar(&ch,imgno); + ch.data[CHAR_WALKINTERVAL] = getWalksendinterval(); + + if( CHAR_getInitElderPosition( &ch ,hometown) == FALSE ){ + lssproto_CreateNewChar_send( clifd ,FAILED, "" ); + CONNECT_setState( clifd, NOTLOGIN ); + return; + + }else if( MAP_checkCoordinates( ch.data[CHAR_FLOOR], ch.data[CHAR_X], + ch.data[CHAR_Y] ) == FALSE ){ + lssproto_CreateNewChar_send( clifd ,FAILED, ""); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + strcpysafe( ch.string[CHAR_NAME].string , + sizeof(ch.string[CHAR_NAME].string), + charname); + + if( CHAR_getNewImagenumberFromEquip(-1, imgno,0) == -1 ){ + lssproto_CreateNewChar_send( clifd ,FAILED, ""); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + ch.data[CHAR_BASEIMAGENUMBER] = imgno; + ch.data[CHAR_BASEBASEIMAGENUMBER] = imgno; + ch.data[CHAR_FACEIMAGENUMBER] = faceimgno; + ch.data[CHAR_DATAPLACENUMBER] = dataplacenum; + +#ifdef _FM_JOINLIMIT + ch.data[CHAR_FMTIMELIMIT] = 0; +#endif +#ifdef _NEW_ITEM_ + ch.data[CHAR_NEWITEMFLG]=0; +#endif +#ifdef _NEWSAVE + ch.data[CHAR_SAVEINDEXNUMBER] = -1; +#endif + ch.data[CHAR_HP] = 0x7fffffff; + + ch.data[CHAR_CHARM] = 60; + ch.data[CHAR_MAXMP] = ch.data[CHAR_MP] = 100; + strcpysafe( ch.string[CHAR_CDKEY].string, + sizeof( ch.string[CHAR_CDKEY].string), cdkey ); + + // Robin 0724 + ch.data[CHAR_RIDEPET] = -1; +#ifdef _NEW_PLAYER_CF + ch.data[CHAR_LEARNRIDE] = getRidePetLevel(); +#endif +#ifdef _NEW_RIDEPETS + ch.data[CHAR_LOWRIDEPETS] = 0; +#endif + +#ifdef _PERSONAL_FAME // Arminius: + ch.data[CHAR_FAME] = 0; +#endif +#ifdef _NEW_MANOR_LAW + ch.data[CHAR_MOMENTUM] = 0; // +#endif +#ifdef _TEACHER_SYSTEM + ch.data[CHAR_TEACHER_FAME] = 0; // ʦ쵼 +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + ch.data[PROFESSION_CLASS] = 0; + ch.data[PROFESSION_LEVEL] = 0; +// ch.data[PROFESSION_EXP] = 0; + ch.data[PROFESSION_SKILL_POINT] = 0; + ch.data[ATTACHPILE] = 0; +#endif +#ifdef _ITEM_PET_LOCKED + ch.data[CHAR_LOCKED] = -1; +#endif + + +#ifdef _TEACHER_SYSTEM + memset(ch.string[CHAR_TEACHER_ID].string,0,sizeof(STRING128)); + memset(ch.string[CHAR_TEACHER_NAME].string,0,sizeof(STRING128)); +#endif + +#ifdef _ITEM_SETLOVER + memset(ch.string[CHAR_LOVERID].string,0,sizeof(STRING128)); + memset(ch.string[CHAR_LOVERNAME].string,0,sizeof(STRING128)); +#endif + +#ifdef _PETSKILL_BECOMEPIG + ch.data[CHAR_BECOMEPIG] = -1; + ch.data[CHAR_BECOMEPIG_BBI] = 100250; +#endif +#ifdef _NEW_TITLE + ch.data[CHAR_TITLE_DEFAULT] = -1; +#endif + strcpysafe( ch.string[CHAR_FMNAME].string, + sizeof( ch.string[CHAR_FMNAME].string), "\0" ); + ch.data[CHAR_FMINDEX] = -1; + + if( CHAR_makeCharFromOptionAtCreate( &ch, + vital,str,tgh,dex, + earth,water,fire,wind ) == FALSE ) + { + lssproto_CreateNewChar_send( clifd ,FAILED, + "option data is invalid\n"); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + { + int mp=ch.data[CHAR_MAXMP]; + int str=ch.data[CHAR_STR]; + int tough=ch.data[CHAR_TOUGH]; + + ch.data[CHAR_INITDATA] = 2*100*100*100*100 /*+ hp*100*100*100*/ + + mp*100*100 + str* 100 + tough; + } + + charaindex = CHAR_initCharOneArray( &ch ); + if( !CHAR_CHECKINDEX(charaindex) ) { + lssproto_CreateNewChar_send( clifd ,FAILED, ""); + CONNECT_setState( clifd, NOTLOGIN ); + return; + } + +#ifdef _ALLBLUES_LUA_1_5 + FreeCharCreate(charaindex); +#endif +#ifndef _CANCEL_BORN_PET +#ifdef _NEW_PLAYER_CF //ֳ + int petNum=0; + int k=0; + int mylevel,level; + if(getNewplayergivepet(0)==-1){ + if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER) == 1 )//˿ + setNewplayergivepet(0,2); + else if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER) == 2 )//Ӽ + setNewplayergivepet(0,3); + else if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER) == 3 )//³ + setNewplayergivepet(0,4); + else + setNewplayergivepet(0,1); + } +#ifdef _NEW_PLAYER_RIDE + if(!strstr( getPlayerRide(), "")) + CHAR_PlayerRide(charaindex); +#endif + for( petNum=0; petNum<5; petNum++) { + if(getNewplayergivepet(petNum)==0)continue; + int enemyarray = ENEMY_getEnemyArrayFromId( getNewplayergivepet(petNum)); //׻ + int petindex = ENEMY_createPetFromEnemyIndex( charaindex, enemyarray); + if( petindex == -1 ) { + continue; + } + add_pet[petNum]=petindex; + mylevel = CHAR_getInt( petindex, CHAR_LV); + level = getNewplayerpetlv()-mylevel; + if(level<1)level=1; + for( k = 1; k < level; k ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + CHAR_complianceParameter( petindex ); + CHAR_setInt( petindex , CHAR_HP , CHAR_getWorkInt( petindex , CHAR_WORKMAXHP ) ); + } +#endif +#endif +#ifdef _HELP_NEWHAND + CHAR_loginAddItemForNew(charaindex); +#endif + +#if 1 + if( CHAR_makeDBKey( charaindex, szKey, sizeof( szKey ) ) != FALSE ){ + int dp; + char info[512]; + snprintf( info, sizeof( info), + "%d,%d,%d,%d,%d,%d", + CHAR_getInt( charaindex, CHAR_LV), + CHAR_getInt( charaindex, CHAR_DUELBATTLECOUNT), + CHAR_getInt( charaindex, CHAR_DUELWINCOUNT), + CHAR_getInt( charaindex, CHAR_DUELLOSECOUNT), + CHAR_getInt( charaindex, CHAR_DUELSTWINCOUNT), + CHAR_getInt( charaindex, CHAR_DUELMAXSTWINCOUNT)); + dp = CHAR_getInt( charaindex, CHAR_DUELPOINT ); + saacproto_DBUpdateEntryInt_send( + acfd, + DB_DUELPOINT, + szKey, + (max(dp,0)), + info, + CONNECT_getFdid(clifd ),0 ); + } +#endif + chwk = CHAR_getCharPointer( charaindex); + + CHAR_charSaveFromConnectAndChar( clifd,chwk ,FALSE ); + + CHAR_CharaDeleteHavePet( charaindex); + CHAR_CharaDelete( charaindex ); + + //CHAR_endCharData(&ch); + //CHAR_endCharOneArray( charaindex); + +#ifdef _NEW_PLAYER_CF //ֳ + { + int k=0; + for( k=0;kcharfunctable[i].string, + sizeof( ch->charfunctable[i]), + tmp[i]); + } +} + +void CHAR_loginAddItem( int charaindex ) +{ +/* + int emptyindex, itemindex, id; + int itemID[10]={ 20128, 20130, 20171, 20176, 20296, + 20287, 20288, 20289, 20290, 20291}; + + { + int trn_num=0; + trn_num=CHAR_getInt(charaindex,CHAR_TRANSMIGRATION); + CHAR_setInt( charaindex, CHAR_MAXPOOLITEMHAVELIMIT, 10 + (trn_num * 4) ) ; + CHAR_setInt( charaindex, CHAR_MAXPOOLPETHAVELIMIT , 5 + (trn_num * 2) ); + } + while( 1){ + emptyindex = CHAR_findEmptyItemBox( charaindex ); + if( emptyindex == -1 ) break; + id = rand()%10; + itemindex = ITEM_makeItemAndRegist( itemID[id] ); + if( !ITEM_CHECKINDEX( itemindex) ) break; + CHAR_setItemIndex( charaindex, emptyindex, itemindex); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charaindex); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + //andy_log + print("@:%d.", emptyindex); + } + while( 1){ + emptyindex = CHAR_findEmptyPoolItemBox( charaindex ); + if( emptyindex == -1 ) break; + id = rand()%10; + itemindex = ITEM_makeItemAndRegist( itemID[id] ); + if( !ITEM_CHECKINDEX( itemindex) ) break; + + CHAR_setPoolItemIndex( charaindex, emptyindex, itemindex); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charaindex); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + //andy_log + print("&:%d.", emptyindex); + } +*/ +} + +void CHAR_loginCheckUserItem( int charaindex) +{ + typedef void (*ATTACHFUNC)(int,int); + int i, itemindex; + for( i=0; i 0 ){ + if( (ti = CHAR_findEmptyItemBox( charaindex )) != -1 ){ + CHAR_setItemIndex( charaindex , i, -1); + CHAR_setItemIndex( charaindex , ti, itemindex); + } + continue; + } + } + //////////////////////////////////////////// +#endif + + if( (i == ITEM_getEquipPlace( charaindex, itemindex )) || + i == CHAR_DECORATION1 || i == CHAR_DECORATION2 ){ + char category[256]; + ATTACHFUNC atf; + atf=(ATTACHFUNC)ITEM_getFunctionPointer(itemindex,ITEM_ATTACHFUNC); + if( atf ){ + atf( charaindex, itemindex ); + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + RunItemAttachEvent(charaindex, itemindex ); + } +#endif + + if( ITEM_canuseMagic( itemindex)) { + snprintf( category, sizeof( category), "J%d",i); + CHAR_sendStatusString( charaindex, category ); + } + }else{ + if( (ti = CHAR_findEmptyItemBox( charaindex )) == -1 ) continue; + CHAR_setItemIndex( charaindex , i, -1); + CHAR_setItemIndex( charaindex , ti, itemindex); + } + + } + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(charaindex) ; i++ ){ //Я + itemindex = CHAR_getItemIndex( charaindex , i ); + if( !ITEM_CHECKINDEX( itemindex)) continue; + ITEM_reChangeItemName( itemindex); +#ifdef _ITEM_PILENUMS + ITEM_reChangeItemToPile( itemindex); +#endif + +#ifdef _ANGEL_SUMMON + if( ITEM_getInt( itemindex, ITEM_ID) == ANGELITEM + || ITEM_getInt( itemindex, ITEM_ID) == HEROITEM ) { + int mindex, mission; + // Ƿ + mindex = checkIfAngelByName( ITEM_getChar( itemindex, ITEM_ANGELINFO)); + mission = atoi( ITEM_getChar( itemindex, ITEM_ANGELMISSION)); + if( mindex < 0 || mission != missiontable[mindex].mission ) { + CHAR_setItemIndex( charaindex, i, -1 ); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( charaindex, i); + continue; + } + } +#endif + ITEM_setItemUniCode( itemindex); + + } + //ķŵ + for( i = 0 ; i < CHAR_MAXPOOLITEMHAVE ; i++ ){ + itemindex = CHAR_getPoolItemIndex( charaindex , i ); + if( !ITEM_CHECKINDEX( itemindex) ) continue; + +#ifdef _AUTO_DEL_ITEM +{ + int j; + int itemid; + for( j= 0;j 1000000 ) + CHAR_setInt( charaindex, CHAR_SILENT, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKLOGINTIME, (int)NowTime.tv_sec); + CHAR_setWorkInt( charaindex, CHAR_WORKTALKCOUNT, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKTALKTIME, (int)NowTime.tv_sec); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, -1); +#ifdef _PETFOLLOW_NEW_ + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW1, -1); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW2, -1); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW3, -1); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW4, -1); +#endif +#ifdef _ITEM_ADDEXP //vincent + CHAR_setWorkInt(charaindex,CHAR_WORKITEM_ADDEXP, 0); + CHAR_setWorkInt(charaindex,CHAR_WORKITEM_ADDEXPTIME, 0); +#endif +#ifdef _STATUS_WATERWORD //ˮ״̬ + if( MAP_getMapFloorType( CHAR_getInt( charaindex, CHAR_FLOOR)) == 1 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKMAPFLOORTYPE, 1); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKMAPFLOORTYPE, 0); + } +#endif +#ifdef _NEWOPEN_MAXEXP + if( CHAR_getInt( charaindex, CHAR_OLDEXP) > 0 || CHAR_getInt( charaindex, CHAR_OLDEXP) < 0 ){ + CHAR_ChangeExp( charaindex); + } +#endif +#ifdef _PETSKILL_BECOMEFOX + CHAR_setWorkInt( charaindex, CHAR_WORKFOXROUND, -1 ); +#endif +#ifdef _MAP_TIME + CHAR_setWorkInt(charaindex,CHAR_WORK_MAP_TIME,0); +#endif +#ifdef _PETSKILL_LER + CHAR_setWorkInt(charaindex,CHAR_WORK_RELIFE,0); +#endif + +#ifdef _ITEM_ADDEXP2 + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXP, + CHAR_getInt( charaindex, CHAR_ADDEXPPOWER) ); + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME , + CHAR_getInt( charaindex, CHAR_ADDEXPTIME) ); +#ifdef _PET_ADD_EXP + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int petindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXP, + CHAR_getInt( petindex, CHAR_ADDEXPPOWER) ); + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME , + CHAR_getInt( petindex, CHAR_ADDEXPTIME) ); + } +#endif +#endif + +} +#ifdef _CHAR_PROFESSION +void CHAR_CheckProfessionSkill( int charaindex) +{ + int i, Pclass, skpoint=0, mynum=0; + CHAR_HaveSkill *pSkil; + + if( NPC_EventCheckFlg( charaindex, 155) ) return; + + Pclass = CHAR_getInt( charaindex, PROFESSION_CLASS ); + skpoint = CHAR_getInt( charaindex, PROFESSION_SKILL_POINT); + if( Pclass == PROFESSION_CLASS_NONE )return; + + + for( i=0; iskill, 0, 0 ); + pSkil->use = 0; + break; + case 64: + CHAR_setInt( charaindex, CHAR_MAXMP, 100); + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, skpoint+1 ); + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + SKILL_makeSkillData( &pSkil->skill, 0, 0 ); + pSkil->use = 0; + break; + case 65: + CHAR_setInt( charaindex, ATTACHPILE, 0); + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, skpoint+1 ); + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + SKILL_makeSkillData( &pSkil->skill, 0, 0 ); + pSkil->use = 0; + break; + } + } + { + int myskillpoint, myskillnum=0, myskilllevel; + int mysknum=0; + + myskillpoint= CHAR_getInt( charaindex, PROFESSION_SKILL_POINT ); + myskilllevel= CHAR_getInt( charaindex, PROFESSION_LEVEL ); + + for( i=0; i 0 ){ + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, myskillpoint + mysknum ); + }else if( mysknum < 0 ){ + int defsknum = (myskillpoint + myskillnum)-myskilllevel; + while( 1){ + if( defsknum<= 0 || + (myskillpoint= CHAR_getInt( charaindex, PROFESSION_SKILL_POINT )) <= 0 ) break; + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, myskillpoint-1); + defsknum--; + } + } + } + + NPC_EventSetFlg( charaindex, 155); +} +#endif + +#ifdef _PET_FUSION +void CHAR_ResetPoolPetEgg( int charaindex) +{ + int levelup, vital, str, tgh, dex; + int raise, petindex, i; + + + if( NPC_EventCheckFlg( charaindex, 157) ) return; + + for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { + petindex = CHAR_getCharPoolPet( charaindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT) != 1 || + CHAR_getInt( petindex, CHAR_FUSIONRAISE) <= 0 ) continue; + + raise = CHAR_getInt( petindex, CHAR_FUSIONRAISE); + raise--; + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time(NULL)+PETFEEDTIME); + if( raise < 1 ) raise = 1; + if( raise >= 40 ) raise = 30; + CHAR_setInt( petindex, CHAR_FUSIONRAISE, raise); + + levelup = CHAR_getInt( petindex, CHAR_ALLOCPOINT); + vital = ((levelup>>24) & 0xFF) + 4; + str = ((levelup>>16) & 0xFF) + 4; + tgh = ((levelup>> 8) & 0xFF) + 4; + dex = ((levelup>> 0) & 0xFF) + 4; + if( vital < 0 ) vital = 0; + if( str < 0 ) str = 0; + if( tgh < 0 ) tgh = 0; + if( dex < 0 ) dex = 0; + // + levelup = (vital<<24) + (str<<16) + (tgh<<8) + (dex<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, levelup); + } + NPC_EventSetFlg( charaindex, 157); +} + +// Robin add 走ιʱ +void CHAR_ResetPetEggFusionTime(int charaindex) +{ + int i, petindex; + int nowTime =0; + //int leaveTime =0; + //int lastFeedTime =0; + //int anhour = PETFEEDTIME; + + //if( NPC_EventCheckFlg( charaindex, 157) ) return; + + nowTime = (int)time(NULL); + //leaveTime = CHAR_getInt( charaindex, CHAR_LASTLEAVETIME); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + petindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT) != 1 || + CHAR_getInt( petindex, CHAR_FUSIONRAISE) <= 0 ) continue; + + //lastFeedTime = CHAR_getInt( petindex, CHAR_FUSIONTIMELIMIT); + //if( leaveTime > 0) { + // CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, nowTime- (leaveTime-lastFeedTime)); + //} + //else + // CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, nowTime); + + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, nowTime); + + } + + //NPC_EventSetFlg( charaindex, 157); + +} +#endif + +BOOL CHAR_CheckProfessionEquit( int toindex) +{ + int i, j, itemindex, newindex; + int FixItem[16]={ + 2028,2029,2030,2031,2032,2033,2034,2035, + 2036,2037,2038,2039,2040,2041,2042,2043 + }; + + if(!NPC_EventCheckFlg( toindex, 149)){ + for (i = 0; i < CheckCharMaxItem(toindex); i ++) { + itemindex = CHAR_getItemIndex( toindex, i); + if( !ITEM_CHECKINDEX( itemindex)) continue; + + for( j=0; j<16; j++){ + if( ITEM_getInt( itemindex, ITEM_ID) == FixItem[j] ){ + CHAR_setItemIndex( toindex, i, -1 ); + ITEM_endExistItemsOne( itemindex); + newindex = ITEM_makeItemAndRegist( FixItem[j]); + if( !ITEM_CHECKINDEX( newindex) ) break; + CHAR_setItemIndex( toindex , i, newindex); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, toindex); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + + CHAR_sendItemDataOne( toindex, i); + + } + } + } + + for (i = 0; i < CHAR_MAXPOOLITEMHAVE; i++){ + int itemindex = CHAR_getPoolItemIndex(toindex, i); + if( !ITEM_CHECKINDEX( itemindex)) continue; + for( j=0; j<16; j++){ + if( ITEM_getInt( itemindex, ITEM_ID) == FixItem[j] ){ + CHAR_setPoolItemIndex( toindex, i, -1); + ITEM_endExistItemsOne( itemindex); + + newindex = ITEM_makeItemAndRegist( FixItem[j]); + if( !ITEM_CHECKINDEX( newindex) ) break; + CHAR_setPoolItemIndex( toindex , i, newindex); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, toindex); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + + } + } + } + + NPC_EventSetFlg( toindex, 149); + } + + + if( NPC_EventCheckFlg( toindex, 156) ) return TRUE; + +#ifdef _CHAR_PROFESSION + CHAR_HaveSkill *pSkil; + // WON ADD + for( i=0; i 0 ) continue; + + CHAR_HaveSkill *pSkil = CHAR_getCharHaveSkill( toindex, i ); + SKILL_makeSkillData( &pSkil->skill, 0, 0 ); + pSkil->use = 0; + } + { + int myskillpoint= CHAR_getInt( toindex, PROFESSION_SKILL_POINT ); + int myskilllevel= CHAR_getInt( toindex, PROFESSION_LEVEL ); + int myskillnum = 0, mysknum = 0; + + for( i=0; i 0 ){ + CHAR_setInt( toindex, PROFESSION_SKILL_POINT, myskillpoint + mysknum ); + } + } + + { + Skill work1[PROFESSION_MAX_LEVEL]; + int cnt=0; + for( i=0; iuse = 0; + if( work1[i].data[SKILL_IDENTITY] == -1 ) continue; + SKILL_makeSkillData( &pSkil->skill, work1[i].data[SKILL_IDENTITY], work1[i].data[SKILL_LEVEL] ); + pSkil->use = 1; + } + } +#endif + + NPC_EventSetFlg( toindex, 156); + + return TRUE; +} + +static void CHAR_setLuck( int charaindex); + +#ifdef _CHANNEL_MODIFY +extern int *piOccChannelMember; +#endif +void CHAR_login( int clifd, char* data, int saveindex ) +{ + int charaindex,objindex; + Char ch; + int per; +// char c_temp2[4096]; + if( CHAR_makeCharFromStringToArg( data , &ch ) == FALSE ){ + fprint ("\n"); + goto MAKECHARDATAERROR; + } + + char cdkey[16]; + CONNECT_getCdkey( clifd, cdkey, sizeof( cdkey )); + + if(strcmp(cdkey, ch.string[CHAR_CDKEY].string) != 0){ + fprint ("\n˺ź͵½˺ŲӦ%s:%s\n", cdkey, ch.string[CHAR_CDKEY].string); + goto MAKECHARDATAERROR; + } + + CHAR_setCharFuncTable( &ch); + charaindex = CHAR_initCharOneArray( &ch ); + if( charaindex == -1 ){ + fprint ("\n"); + //CHAR_endCharData(&ch); + goto MAKECHARDATAERROR; + } + +#ifdef _NEWSAVE + CHAR_setInt( charaindex, CHAR_SAVEINDEXNUMBER, saveindex); + //print("浵װ:%d\n", CHAR_getInt( charaindex, CHAR_SAVEINDEXNUMBER) ); +#endif + if( CHAR_getFlg( charaindex, CHAR_ISDIE)){ + print( "?data? ISDIE flg is standing.\n"); + CHAR_setFlg( charaindex, CHAR_ISDIE, FALSE); + } + + +#ifdef _NEWCLISETSERVID + CHAR_setWorkInt(charaindex, CHAR_WORK_SERVID, CONNECT_getServid( clifd )); +#endif +#ifdef _NEWCLISETMAC + char mac[128]; + CONNECT_getMAC( clifd, mac, sizeof( mac )); + CHAR_setWorkChar(charaindex, CHAR_WORK_MAC, mac); +#endif + + CHAR_LoginBesideSetWorkInt( charaindex, clifd); + + +#ifndef _FIX_UNNECESSARY + // Arminius 7.9 airplane logout + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT ) { + int oyaindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex)) { + if (CHAR_getInt( oyaindex, CHAR_WHICHTYPE ) == CHAR_TYPEBUS) { + if ((CHAR_getInt( oyaindex, CHAR_BASEIMAGENUMBER) !=100355) && + (CHAR_getInt( oyaindex, CHAR_BASEIMAGENUMBER) !=100461)) { + + if(CHAR_getWorkInt(oyaindex,CHAR_NPCWORKINT5)==1) { + if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER)>=0){ + int fl,x,y; + CHAR_getElderPosition( CHAR_getInt( charaindex, CHAR_LASTTALKELDER), &fl, &x, &y ); + CHAR_setInt(charaindex,CHAR_FLOOR,fl); + CHAR_setInt(charaindex,CHAR_X,x); + CHAR_setInt(charaindex,CHAR_Y,y); + } + } + } + } + } + } +#endif + + +#ifdef _UNLAW_THIS_LOGOUT +{ + int i; + int floor = CHAR_getInt(charaindex,CHAR_FLOOR); + for(i=0;i<32;i++){ + if(floor == getUnlawThisLogout(i)){ + int fl,x,y; + CHAR_getElderPosition( CHAR_getInt( charaindex, CHAR_LASTTALKELDER), &fl, &x, &y ); + CHAR_setInt(charaindex,CHAR_FLOOR,fl); + CHAR_setInt(charaindex,CHAR_X,x); + CHAR_setInt(charaindex,CHAR_Y,y); + break; + } + } +} +#endif + +// Nuke 20040420: CHECK MAX POINT +#if 1 + { + + int lv,vi,str,tou,dx,skup,trn,teq,quest,level,total,max; + float table[]={437,490,521,550,578,620,700}; //תߵ(10) + //float table[]={620,660,700,740,780,820}; //תߵ(10) + lv = CHAR_getInt(charaindex,CHAR_LV); + vi = CHAR_getInt(charaindex,CHAR_VITAL); + str = CHAR_getInt(charaindex,CHAR_STR); + tou = CHAR_getInt(charaindex,CHAR_TOUGH); + dx = CHAR_getInt(charaindex,CHAR_DEX); + trn = CHAR_getInt(charaindex,CHAR_TRANSMIGRATION); + teq = CHAR_getInt(charaindex,CHAR_TRANSEQUATION); + skup = CHAR_getInt(charaindex,CHAR_SKILLUPPOINT); + quest=(teq >> 16) & 0xFF; + level=teq & 0xFFF; + total=(vi+str+tou+dx)/100+skup; +// max=(trn==0)?(lv-1)*3+20+10: // 0ת447 +// (lv-1)*3+table[trn-1]/12.0+quest/4.0+(level-trn*85)/4.0+10+1+10+trn*10; +/* + print(":%d\n",(lv-1)*getSkup()); + print("̳е:%f\n",(table[trn-1]/12.0)); + print("ʷ:%f\n",quest/4.0); + print("ʷȼ:%f\n",(level-trn*85)/4.0); + print("ʷȼ:%d/%d\n",level,trn*85); + print("תǰף:%d\n",getTransPoint(trn)); + print("1:%d\n",1); + print("תף:%d\n",getTransPoint(trn)); + print("ת:%d\n",trn*10); +*/ +#ifdef _REVLEVEL + if (strcmp(getRevLevel(),"")==0){ + if(trn>=getChartrans()){ + if(lv>getMaxLevel()){ + lv=getMaxLevel(); + print("[%s:%s]lv:%d->%d", + CHAR_getChar(charaindex,CHAR_CDKEY), + CHAR_getChar(charaindex,CHAR_NAME), + CHAR_getInt(charaindex,CHAR_LV), + getMaxLevel()); + } + }else if(lv>getYBLevel()){ + lv=getYBLevel(); + print("[%s:%s]lv:%d->%d", + CHAR_getChar(charaindex,CHAR_CDKEY), + CHAR_getChar(charaindex,CHAR_NAME), + CHAR_getInt(charaindex,CHAR_LV), + getMaxLevel()); + } + CHAR_setInt(charaindex,CHAR_LV,lv); + } +#endif + float jxds=(level-trn*85)/4.0; + if(jxds<0)jxds=0; +#ifdef _SKILLUPPOINT_CF + max=(trn==0)?getTransPoint(trn)+(lv-1)*getSkup()+20: + getTransPoint(trn)+(lv-1)*getSkup()+table[trn-1]/12.0+quest/4.0+jxds+getTransPoint(trn)+ trn*10+1; + +#ifdef _TRANS_POINT_UP + if(getTransPoinUP(trn)>-1){ + if(total>getTransPoinUP(trn)){ + max=getTransPoinUP(trn); + } + } +#endif +#else + max=(trn==0)?(lv-1)*3+20+10: // 0ת447 + (lv-1)*3+table[trn-1]/12.0+quest/4.0+(level-trn*85)/4.0+10+1+10+trn*10; +#endif +/* 1ת=+̳е+ʷ+ʷȼ+תǰף+1+תף+ת */ +// if (trn==6) max=max-20; /* תʱûתǰףתף */ +#ifdef _REVLEVEL + if (total>max && strcmp(getPoint(),"")==0) +#else + if (total>max ) +#endif + +#ifdef _SUPER + if(CHAR_getInt(charaindex,CHAR_SUPER)<1) +#endif + { + print("\nص[%s:%s]:%d->%d ", + CHAR_getChar(charaindex,CHAR_CDKEY), + CHAR_getChar(charaindex,CHAR_NAME), + total,max); + CHAR_setInt(charaindex,CHAR_VITAL,1000); + CHAR_setInt(charaindex,CHAR_STR,0); + CHAR_setInt(charaindex,CHAR_TOUGH,0); + CHAR_setInt(charaindex,CHAR_DEX,0); + CHAR_setInt(charaindex,CHAR_SKILLUPPOINT,max-10); + } + + + // ת֮ +/* if ((trn==6) && (total < max)) + { + print("\n[%s:%s]:%d->%d ", + CHAR_getChar(charaindex,CHAR_CDKEY), + CHAR_getChar(charaindex,CHAR_NAME), + total,max); + CHAR_setInt(charaindex,CHAR_SKILLUPPOINT, + CHAR_getInt(charaindex,CHAR_SKILLUPPOINT)+(max-total)); + }*/ + } +#endif + { + int EQ_BBI=-1, EQ_ARM=-1, EQ_NUM=-1, EQ_BI=-1; + int CH_BI = CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER); + + EQ_BBI = CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER); + if(CH_BI != EQ_BBI){ + EQ_ARM = CHAR_getItemIndex(charaindex,CHAR_ARM); + EQ_NUM=ITEM_FIST; + if ( ITEM_CHECKINDEX( EQ_ARM)) { + EQ_NUM=ITEM_getInt(EQ_ARM,ITEM_TYPE); + } + + EQ_BI=CHAR_getNewImagenumberFromEquip(-1, EQ_BBI, EQ_NUM); + + if( CHAR_getInt( charaindex, CHAR_RIDEPET) == -1 ) { // + if( EQ_BI != CH_BI ) { + print("\n %d [%d=>%d]", charaindex, + CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER), + EQ_BI ); + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, EQ_BI); + } + } + } + } + { + int x,y; + if( CHAR_isAppearPosition( CHAR_getInt( charaindex, CHAR_FLOOR),&x, &y )) { + int flelder, xelder, yelder; + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), + &flelder, &xelder, &yelder); + CHAR_setInt(charaindex, CHAR_FLOOR, flelder); + CHAR_setInt(charaindex, CHAR_X, xelder); + CHAR_setInt(charaindex, CHAR_Y, yelder); + } + } + +#ifdef _FIX_GAMBLENUM + { + if( CHAR_getInt(charaindex, CHAR_GAMBLENUM) < 0){ + CHAR_setInt(charaindex, CHAR_GAMBLENUM, 0); + } + } +#endif + +#ifdef _MAP_NOEXIT + { + int exfloor=-1,ex_X=-1,ex_Y=-1; + int map_type=0; + unsigned int point; + point = MAP_getExFloor_XY( CHAR_getInt(charaindex, CHAR_FLOOR) , &map_type); + if( point > 0 ) { + if( CHAR_getInt( charaindex, CHAR_LASTTALKELDER) >= 0 ) { + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), + &exfloor, &ex_X, &ex_Y); + } + if( map_type >= 0 ) { // map_type >= 0 Ȼؼ¼ + if( exfloor == map_type && exfloor >= 0 ) {//ؼ¼ + }else { + exfloor = (point>>16)&0xffffff; + ex_X = (point>>8)&0xff; + ex_Y = (point>>0)&0xff; + } + } + if( CHECKFLOORID( exfloor) ) { //鷿 + CHAR_setInt(charaindex, CHAR_FLOOR, exfloor); + CHAR_setInt(charaindex, CHAR_X, ex_X); + CHAR_setInt(charaindex, CHAR_Y, ex_Y); + } + } + } +#endif + if( CHAR_getInt(charaindex,CHAR_X) < 0 || CHAR_getInt(charaindex,CHAR_Y) < 0 ){ + CHAR_setInt(charaindex,CHAR_X,1); + CHAR_setInt(charaindex,CHAR_Y,1); + } +#ifdef _MAP_TIME + // ĵͼЩŵĻ,ص + if(CHAR_getInt(charaindex,CHAR_FLOOR) >= 30017 && CHAR_getInt(charaindex, CHAR_FLOOR) <= 30021){ + CHAR_setInt(charaindex,CHAR_FLOOR,30008); + CHAR_setInt(charaindex,CHAR_X,39); + CHAR_setInt(charaindex,CHAR_Y,38); + } +#endif +#ifdef _FM_METAMO + if( CHAR_getInt( charaindex , CHAR_BASEIMAGENUMBER)>=100700 && CHAR_getInt( charaindex , CHAR_BASEIMAGENUMBER)<100819 + && (CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) == FMMEMBER_NONE || CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) == FMMEMBER_APPLY)){ + switch( CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) ){ + case 1041: + case 2031: + case 3031: + case 4031: + case 5031: + case 6031: + case 7031: + case 8031: + case 9031: + case 10031: + break; + default: + CHAR_ReMetamo(charaindex); + } + } +#endif +#ifdef _AUTO_PK + int exfloor=-1,ex_X=-1,ex_Y=-1; + if( CHAR_getInt(charaindex, CHAR_FLOOR) == 20000 ){ + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), &exfloor, &ex_X, &ex_Y); + CHAR_setInt(charaindex, CHAR_FLOOR, exfloor); + CHAR_setInt(charaindex, CHAR_X, ex_X); + CHAR_setInt(charaindex, CHAR_Y, ex_Y); + } + CHAR_setWorkInt(charaindex, CHAR_WORK_AUTOPK, 0); +#endif + if( CHAR_getInt(charaindex, CHAR_FLOOR) == 10032 ){ + CHAR_setInt(charaindex, CHAR_FLOOR, 10030); + CHAR_setInt(charaindex, CHAR_X, 52); + CHAR_setInt(charaindex, CHAR_Y, 36); + } + + objindex = initObjectFromObjectMember(OBJTYPE_CHARA,charaindex, + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR)); + if( objindex == -1 ){ + fprint ("ʼ\n"); + goto DELETECHARDATA; + } + + CHAR_setWorkInt( charaindex,CHAR_WORKOBJINDEX,objindex ); + CONNECT_setState( clifd, LOGIN ); + CONNECT_setCharaindex( clifd, charaindex ); + + CHAR_complianceParameter( charaindex ); + // + { + int i; +// char *petstring; + int ID1; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int petindex = CHAR_getCharPet(charaindex,i); + if( CHAR_CHECKINDEX( petindex) ) { + +#ifdef _AUTO_DEL_PET +{ + int j, petid; + char category[12]; + petid =CHAR_getInt( petindex, CHAR_PETID); + for(j=0;j 0 || CHAR_getInt( charaindex, CHAR_OLDEXP) < 0 ){ + CHAR_ChangeExp( petindex); + } +#endif + ID1=CHAR_getInt( petindex, CHAR_PETID); +// petstring = CHAR_makePetStringFromPetIndex( petindex); +#ifdef _REEDIT_PETBBIS + if( ID1 == 1133 ){ + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, 101578); + CHAR_setInt( petindex, CHAR_BASEBASEIMAGENUMBER, 101578); + print("PET:%s fix BBI\n", CHAR_getUseName(petindex)); + } +#endif + // WON ADD ׻߼ + if( ID1 == 777 )CHAR_setInt( petindex, CHAR_SLOT, 7); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + // 輼ֵ-1 Robin 20040803 + if( CHAR_getInt( petindex, CHAR_SLOT) < 0 ) { + int j; + for( j=0; j= 0) + CHAR_setInt( petindex, CHAR_SLOT, j+1); + } + //print(" 輼MAX-16 "); + } + CHAR_complianceParameter( petindex ); +#ifdef _FIX_GP_PET_SKILL // WON ADD gp + if( ID1 == 1133){ + int j; + for( j=0; j 0 || + CHAR_getInt( charaindex, CHAR_OLDEXP) < 0 ){ + CHAR_ChangeExp( petindex); + } +#endif + b_find=FALSE; + ID1=CHAR_getInt( petindex, CHAR_PETID); +#ifdef _REEDIT_PETBBIS + if( ID1 == 1133 ){ + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, 101578); + CHAR_setInt( petindex, CHAR_BASEBASEIMAGENUMBER, 101578); + } +#endif + + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + + CHAR_complianceParameter( petindex ); +#ifdef _AUTO_DEL_PET +{ + int j, petid; + petid =CHAR_getInt( petindex, CHAR_PETID); + for(j=0;juse == TRUE ){ + int skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + if( skill_level < 10 ){ + SKILL_setInt( &hskill->skill, SKILL_LEVEL, 10* 100 ); + } + } + } + } +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _CHANNEL_MODIFY + if(CHAR_getInt(charaindex,PROFESSION_CLASS) > 0){ + int i,pclass = CHAR_getInt(charaindex,PROFESSION_CLASS) - 1,Empty = -1; + // ɵְҵƵ¼м¼ھ,ûмƵ + for(i=0;i MAX_PERSONAL_MOMENTUM) CHAR_setInt(charaindex,CHAR_MOMENTUM,MAX_PERSONAL_MOMENTUM); +#endif + +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 ){ + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BECOMEPIG_BBI ) ); + } + //change fix ܴʱ + else{ + CHAR_setInt( charaindex, CHAR_BECOMEPIG, -1 ); + } +#endif + + lssproto_CharLogin_send( clifd, SUCCESSFUL,"" ); + per = ENCOUNT_getEncountPercentMin( charaindex, + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + if( per != -1) { + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN, per); + } + per = ENCOUNT_getEncountPercentMax( charaindex, + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + if( per != -1) { + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX, per); + } + + CHAR_setLuck( charaindex); + { + int i; + char* statuscat[]={"C","P","I","S","D","E","F"}; + for( i=0 ; i=1 ) + CHAR_Skillupsend(charaindex); + CHAR_checkEffect( charaindex); + // CoolFish: Family 2001/5/30 + if ((CHAR_getChar(charaindex, CHAR_FMNAME)!=NULL) && + (CHAR_getInt(charaindex, CHAR_FMINDEX) >= 0) && + (strcmp(CHAR_getChar(charaindex, CHAR_FMNAME), "") != 0)) + { +#ifdef _FMVER21 + int eventflag = 0; + // Ƿ峤ʸ + if (CheckLeaderQ(charaindex) >= 0) + eventflag = 1; + if (CHAR_getInt(charaindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) + SetFMPetVarInit(charaindex); + saacproto_ACFMCharLogin_send( + acfd, + CHAR_getChar(charaindex, CHAR_FMNAME), + CHAR_getInt(charaindex, CHAR_FMINDEX), + CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), + CHAR_getInt(charaindex, CHAR_LV), eventflag, + CONNECT_getFdid(clifd) +#ifdef _FM_MODIFY + ,getServernumber() +#endif + ); + } +#ifdef _FMVER21 + else{ + SetFMVarInit(charaindex); + } +#endif + +#endif + +#ifdef _VIP_RIDE + if(CHAR_getInt(charaindex, CHAR_VIPTIME) >= 0 ){ + if(CHAR_getInt(charaindex, CHAR_VIPTIME) < time(NULL)){ + CHAR_setInt(charaindex, CHAR_VIPRIDE, 0); + CHAR_setInt(charaindex, CHAR_VIPTIME, 0); + } + } +#endif + +#ifdef _PLAYER_TITLE + if(CHAR_getInt(charaindex, CHAR_TITLE_TIME) > 0 ){ + if(CHAR_getInt(charaindex, CHAR_TITLE_TIME) < time(NULL)){ + CHAR_setInt(charaindex, CHAR_TITLE_LV, 0); + CHAR_setInt(charaindex, CHAR_TITLE_TIME, 0); + } + } +#endif + +#ifdef _LOGIN_DISPLAY + if(getLoginDisplay()==1 || getLoginDisplay()==2){ + AnnounceToPlayerWN( clifd ); + }else if(getLoginDisplay()==3){ + if(CHAR_getInt(charaindex, CHAR_VIPRIDE) == 0){ + AnnounceToPlayerWN( clifd ); + } + } +#else + AnnounceToPlayerWN( clifd ); +#endif +#ifdef _ALLBLUES_LUA_1_5 + if(FreeCharLogin(charaindex)==0){ + return; + } +#endif + +#ifdef _ANGEL_SUMMON + { + int mindex; + mindex = checkIfOnlyAngel( charaindex); + if( mindex != -1 ) { + if( missiontable[mindex].flag == MISSION_WAIT_ANSWER ) { + lssproto_WN_send( clifd, WINDOW_MESSAGETYPE_ANGELMESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_ANGEL_ASK, + -1, + "ĿǰħŰҪİæǰѰЩħ壬ǷԸæ" ); + } + } + } +#endif + +#ifdef _ONLINE_TIME + CHAR_setWorkInt(charaindex, CHAR_WORK_LOGIN_TIME, time( NULL)); +#endif +#ifdef _OFFLINE_SYSTEM + playeronlinenum++; +#endif + //print("\n½:%s ", CHAR_getChar(charaindex, CHAR_NAME ) ); + + { + unsigned long ip; + char ipstr[512]; + + ip=CONNECT_get_userip(clifd); + sprintf(ipstr,"%d.%d.%d.%d", + ((unsigned char *)&ip)[0], + ((unsigned char *)&ip)[1], + ((unsigned char *)&ip)[2], + ((unsigned char *)&ip)[3]); + + +#ifdef _RECORD_IP + CHAR_setWorkInt(charaindex, CHAR_WORK_RECORD_IP, CONNECT_get_userip(clifd)); +#endif + + + LogLogin( + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( charaindex, CHAR_NAME), + saveindex, ipstr +#ifdef _NEWCLISETMAC + ,CHAR_getWorkChar(charaindex, CHAR_WORK_MAC) +#endif + ); + } +{ + int i; + int playernum = CHAR_getPlayerMaxNum(); + +#ifdef _PLAYER_TITLE + char titletoken[256]; + if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 130 ){ + sprintf(titletoken, "%s˹½սʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 125 ){ + sprintf(titletoken, "%s˹½ʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 120 ){ + sprintf(titletoken, "%s˹ӢLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 115 ){ + sprintf(titletoken, "%s˹ʹսʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 110 ){ + sprintf(titletoken, "%sķսʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 100 ){ + sprintf(titletoken, "%s˿սʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 80 ){ + sprintf(titletoken, "%s̹սʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 60 ){ + sprintf(titletoken, "%sضսʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 40 ){ + sprintf(titletoken, "%sħʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + }else if ( CHAR_getInt( charaindex, CHAR_TITLE_LV) >= 20 ){ + sprintf(titletoken, "%sʥʿLv:%d%sˣһӭ", getGameservername(), CHAR_getInt( charaindex, CHAR_TITLE_LV), CHAR_getChar( charaindex,CHAR_NAME )); + } +#endif + +#ifdef _VIP_ONLINE + char viptoken[256]; + if(CHAR_getInt(charaindex, CHAR_VIPRIDE) > 0){ + if ( CHAR_getInt( charaindex, CHAR_FMINDEX) > -1){ + sprintf(viptoken, "%sĻԱ{%s}%sˣһӭ", getGameservername(), CHAR_getChar( charaindex,CHAR_FMNAME ), CHAR_getChar( charaindex,CHAR_NAME )); + }else{ + sprintf(viptoken, "%sĻԱ%sˣһӭ", getGameservername(), CHAR_getChar( charaindex,CHAR_NAME )); + } + } +#endif + + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + char token[256]; +#ifdef _TEACHER_SYSTEM + // ѧ֪ͨʦ + if(strlen(CHAR_getChar(charaindex,CHAR_TEACHER_ID)) > 0 && strlen(CHAR_getChar(charaindex,CHAR_TEACHER_NAME)) > 0){ + if(strcmp(CHAR_getChar(charaindex,CHAR_TEACHER_ID),CHAR_getChar(i,CHAR_CDKEY)) == 0 && + strcmp(CHAR_getChar(charaindex,CHAR_TEACHER_NAME),CHAR_getChar(i,CHAR_NAME)) == 0){ + sprintf(token,"ѧ %s ",CHAR_getChar(charaindex,CHAR_NAME)); + CHAR_talkToCli(i,-1,token,CHAR_COLORYELLOW); + } + } +#endif + +#ifdef _LOGIN_DISPLAY + if(getLoginDisplay()==1 || getLoginDisplay()==3) +#endif + { +#ifdef _VIP_ONLINE + if(CHAR_getInt(charaindex, CHAR_VIPRIDE) > 0){ + CHAR_talkToCli( i, -1, viptoken, CHAR_COLORPURPLE); + } +#endif + +#ifdef _PLAYER_TITLE + if(CHAR_getInt(charaindex, CHAR_TITLE_LV) >= 20){ + CHAR_talkToCli( i, -1, titletoken, CHAR_COLORPURPLE); + } +#endif + +#ifdef _NEW_NAME //Զƺ + char* szNewName = CHAR_getChar( charaindex, CHAR_NEWNAME); + if(szNewName!=0 && strlen(szNewName) > 0){ + sprintf(token, "%s %s ҡ%sˣһӭ", getGameservername(), szNewName, CHAR_getChar( charaindex,CHAR_NAME )); + CHAR_talkToCli( i, -1, token, CHAR_COLORBLUE); + } +#endif + } +#ifdef ITEM_SETLOVER + // ֪ͨԷ + if(strlen( CHAR_getChar( charaindex, CHAR_LOVE)) > 0 && + strlen(CHAR_getChar(charaindex,CHAR_LOVERID))>0 && + strlen(CHAR_getChar(charaindex,CHAR_LOVERNAME))>0){ + if(!strcmp( CHAR_getChar( i, CHAR_LOVE), "YES") && + !strcmp(CHAR_getChar(charaindex,CHAR_LOVERID),CHAR_getChar(i,CHAR_CDKEY)) && + !strcmp(CHAR_getChar(charaindex,CHAR_LOVERNAME),CHAR_getChar(i,CHAR_NAME))){ + sprintf(token,"İ %s ",CHAR_getChar(charaindex,CHAR_NAME)); + CHAR_talkToCli(i,-1,token,CHAR_COLORYELLOW); + } + } +#endif + } + } +} + +#ifdef _PET_ITEM + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 0) ) ){ + CHAR_sendPetItemData(charaindex,0); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 1) ) ){ + CHAR_sendPetItemData(charaindex,1); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 2) ) ){ + CHAR_sendPetItemData(charaindex,2); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 3) ) ){ + CHAR_sendPetItemData(charaindex,3); + } + if( CHAR_CHECKINDEX( CHAR_getCharPet( charaindex, 4) ) ){ + CHAR_sendPetItemData(charaindex,4); + } +#endif + +#ifdef _ITEM_PET_LOCKED + if(getItemPetLocked()==0){ + CHAR_setInt(charaindex,CHAR_LOCKED, 0); + }else if(CHAR_getInt(charaindex,CHAR_LOCKED)!=-1){ + CHAR_setInt(charaindex,CHAR_LOCKED, 1); + } +#endif + return; + +DELETECHARDATA: + CHAR_endCharOneArray( charaindex ); + +MAKECHARDATAERROR: + { + int i; + char cdkey[CDKEYLEN]; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_CHECKINDEX(ch.unionTable.indexOfPet[i] ) ) { + CHAR_endCharOneArray( ch.unionTable.indexOfPet[i] ); + } + } + for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) { + if( ITEM_CHECKINDEX(ch.indexOfExistItems[i])) { + ITEM_endExistItemsOne(ch.indexOfExistItems[i]); + ch.indexOfExistItems[i] = -1; + } + } + CONNECT_getCdkey( clifd, cdkey, sizeof(cdkey )); + saacproto_ACLock_send( acfd, cdkey, UNLOCK, CONNECT_getFdid(clifd) ); + } + CONNECT_setState(clifd, WHILECANNOTLOGIN ); + CONNECT_setCharaindex( clifd, -1 ); + lssproto_CharLogin_send( clifd, FAILED, "Download data ok,but cannot make chara"); +} +extern char* CHAR_setintdata[CHAR_DATAINTNUM]; +extern char* CHAR_setchardata[CHAR_DATACHARNUM]; +BOOL CHAR_charSaveFromConnectAndChar( int fd, Char* ch, BOOL unlock ) +{ + char* chardata; + + chardata = CHAR_makeStringFromCharData( ch ); + + if( chardata == "\0" )return FALSE; + +#ifdef _DBSAVE_CHAR + else{ + if(ch->data[CHAR_SAVEINDEXNUMBER]!=-1) + CharaData( fd, ch ); + } +#endif + +#ifdef _NEWSAVE + //print("saveindex_save:%d\n",ch->data[CHAR_SAVEINDEXNUMBER]); + saacproto_ACCharSave_send( acfd, ch->string[CHAR_CDKEY].string, + ch->string[CHAR_NAME].string, + CHAR_makeOptionString( ch ), chardata, + unlock, CONNECT_getFdid(fd), ch->data[CHAR_SAVEINDEXNUMBER] ); +#else + + saacproto_ACCharSave_send( acfd, cdkey, + ch->string[CHAR_NAME].string, + CHAR_makeOptionString( ch ), chardata, + unlock, CONNECT_getFdid(fd) ); +#endif +#ifdef _CHARADATA_SAVE_SQL +/* + char* list = CHAR_make_list_String( ch ); + char* list_info1 = CHAR_make_list_info1_String( ch ); + saacproto_CharadataSaveSQL_send(acfd, ch->string[CHAR_CDKEY].string, + list, + list_info1, + ch->data[CHAR_SAVEINDEXNUMBER], + 0 ); +*/ + + CHAR_CharadataSaveSQL( ch ); +#endif + return TRUE; +} + +BOOL CHAR_charSaveFromConnect( int charaindex , BOOL unlock) +{ + Char* ch=(Char*)NULL; + + int fd = getfdFromCharaIndex(charaindex); + if( CHAR_CHECKINDEX( charaindex ) == FALSE)return FALSE; + ch = CHAR_getCharPointer( charaindex ); + if( !ch )return FALSE; +#ifdef _CHAR_POOLITEM + if( CHAR_SaveDepotItem( charaindex) == TRUE ){ + ;//print("saveDepotItem:%d \n", charaindex); + } +#endif +#ifdef _CHAR_POOLPET + if( CHAR_SaveDepotPet( charaindex) == TRUE ){ + ;//print("saveDepotPet:%d \n", charaindex); + } +#endif + + return CHAR_charSaveFromConnectAndChar( fd, ch, unlock ); +} + + +/*------------------------------------------------------------ + * ʧݱ ʧƥئʧ ةë + * + * ¦ + * charaindex int ƽҷ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +static void CHAR_dropItemAtLogout( int charaindex ) +{ + int i; + for( i=0 ; i= 0 ){ + BATTLE_EscapeDpSend( battleindex, charindex ); + CHAR_setInt( charindex, CHAR_DUELPOINT, + CHAR_getInt( charindex, CHAR_DUELPOINT ) + + CHAR_getWorkInt( charindex, CHAR_WORKGETEXP ) ); + + CHAR_setWorkInt( charindex, CHAR_WORKDBATTLEESCAPE, 1); + BATTLE_Exit( charindex, battleindex ); + } + + CHAR_dropItemAtLogout( charindex ); + CHAR_DischargeParty( charindex, 0); + if(CHAR_getChar(charindex, CHAR_FMNAME) != NULL ) { + if(strlen(CHAR_getChar(charindex, CHAR_FMNAME)) > 0 && + strlen(CHAR_getChar(charindex, CHAR_FMNAME)) < sizeof( STRING32) ) + if( (CHAR_getInt(charindex, CHAR_FMINDEX) >= 0) && + (strcmp(CHAR_getChar(charindex, CHAR_FMNAME), "") != 0) ) { + saacproto_ACFMCharLogout_send(acfd, + CHAR_getChar(charindex, CHAR_FMNAME), + CHAR_getInt(charindex, CHAR_FMINDEX), + CHAR_getChar(charindex, CHAR_NAME), + CHAR_getChar(charindex, CHAR_CDKEY), + CHAR_getInt(charindex, CHAR_LV), + CHAR_getWorkInt(charindex, CHAR_WORKFMINDEXI), + CONNECT_getFdid(clifd)); + } + } + +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ + if ( CHAR_getWorkInt ( charindex , CHAR_WORKCHATROOMTYPE ) != 0 ) { + ChatRoom_Leave ( charindex ) ; + } +#endif +#ifdef _STREET_VENDOR + // ڽ + if(CHAR_getWorkInt(charindex,CHAR_WORKSTREETVENDOR) == 2){ + // ȡ׵ + toindex = CHAR_getWorkInt(charindex,CHAR_WORKSTREETVENDOR_WHO); + if(toindex > -1 && CHAR_CHECKINDEX(toindex)){ + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,-1); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(toindex),"C|"); + CHAR_talkToCli(toindex,-1,"ȡ",CHAR_COLORYELLOW); + } + } + // + else if(CHAR_getWorkInt(charindex,CHAR_WORKSTREETVENDOR) == 3){ + // ȡ + toindex = CHAR_getWorkInt(charindex,CHAR_WORKSTREETVENDOR_WHO); + if(toindex > -1 && CHAR_CHECKINDEX(toindex)){ + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,1); + } + } +#endif + + // Robin 0606 channel + fmindexi = CHAR_getWorkInt(charindex, CHAR_WORKFMINDEXI); + channel = CHAR_getWorkInt(charindex, CHAR_WORKFMCHANNEL); + i = 0; + if( (fmindexi > 0) && (channel >= 0) && (fmindexi < FAMILY_MAXNUM) && (channel < FAMILY_MAXCHANNEL)) { + while( i < FAMILY_MAXMEMBER ) { + if( channelMember[fmindexi][channel][i] == charindex ) { + channelMember[fmindexi][channel][i] = -1; + break; + } + i++; + } + } +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _CHANNEL_MODIFY + if(CHAR_getInt(charindex,PROFESSION_CLASS) > 0){ + int i,pclass = CHAR_getInt(charindex,PROFESSION_CLASS) - 1; + for(i=0;i 0) && (fmindexi < FAMILY_MAXNUM)){ + if( familyMemberIndex[fmindexi][i] == charindex ) + familyMemberIndex[fmindexi][i] = -1; + } + } + // Robin 0629 silent + if( CHAR_getInt( charindex, CHAR_SILENT) > 0 ){ + int silent_t, login_t; + login_t = CHAR_getWorkInt(charindex, CHAR_WORKLOGINTIME); + silent_t = CHAR_getInt( charindex, CHAR_SILENT); + silent_t = silent_t - ( (int)NowTime.tv_sec-login_t); + if( silent_t<0 ) silent_t = 0; + CHAR_setInt( charindex, CHAR_SILENT, silent_t); + } + + + +#ifdef _ITEM_ADDEXP2 + if( CHAR_getWorkInt( charindex, CHAR_WORKITEM_ADDEXP) > 0 ) { + // ʱǹЧԶ90 + CHAR_setWorkInt( charindex, CHAR_WORKITEM_ADDEXPTIME, + CHAR_getWorkInt( charindex, CHAR_WORKITEM_ADDEXPTIME) - 90 ); + if( CHAR_getWorkInt( charindex, CHAR_WORKITEM_ADDEXPTIME) <= 0 ) { + CHAR_setWorkInt( charindex, CHAR_WORKITEM_ADDEXPTIME, 0); + CHAR_setWorkInt( charindex, CHAR_WORKITEM_ADDEXP, 0); + } + } + CHAR_setInt( charindex, CHAR_ADDEXPPOWER, + CHAR_getWorkInt( charindex, CHAR_WORKITEM_ADDEXP) ); + CHAR_setInt( charindex, CHAR_ADDEXPTIME, + CHAR_getWorkInt( charindex, CHAR_WORKITEM_ADDEXPTIME) ); + +#ifdef _PET_ADD_EXP + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int petindex = CHAR_getCharPet( charindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + if ( CHAR_getWorkInt(petindex, CHAR_WORKITEM_ADDEXP ) > 0 ){ + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME, + CHAR_getWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME) - 90 ); + if( CHAR_getWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME) <= 0 ) { + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME, 0); + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXP, 0); + } + CHAR_setInt( petindex, CHAR_ADDEXPPOWER, + CHAR_getWorkInt( petindex, CHAR_WORKITEM_ADDEXP) ); + CHAR_setInt( petindex, CHAR_ADDEXPTIME, + CHAR_getWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME) ); + } + } +#endif +#endif +#ifdef _TIME_TICKET + if( check_TimeTicketMap( CHAR_getInt( charindex, CHAR_FLOOR)) ) { + CHAR_warpToSpecificPoint( charindex, 7001, 41, 6); + } +#endif + +#ifdef _AUTO_PK + if(CHAR_getInt(charindex,CHAR_FLOOR)==20000 && CHAR_getWorkInt(charindex,CHAR_WORK_AUTOPK)!=-1 ){ + char buf[64]; + int i,num=0,winindex=0; + int playernum = CHAR_getPlayerMaxNum(); + sprintf(buf, "С %s ˳ǰ",CHAR_getChar(charindex,CHAR_NAME)); + AutoPk_PKSystemTalk( buf, buf ); + if(CHAR_getWorkInt( charindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(AutoPk_PKTimeGet()<=0){ + for(i=0;i 0 ){ + char cabuf[128]; + int fd = getfdFromCharaIndex( recvindex ); + if(fd > -1){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_MIND, CHAR_getWorkInt( index, CHAR_PLAYER_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char cabuf[128]; + int fd = getfdFromCharaIndex( recvindex ); + if(fd > -1){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ) > 0 ){ + char cabuf[128]; + int fd = getfdFromCharaIndex( recvindex ); + if(fd > -1){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif + + +#ifdef _NEW_UPDATETITLE + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ) > 0 ){ + char cabuf[128]; + int fd = getfdFromCharaIndex( recvindex ); + if(fd > -1){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif +#ifdef _FAMILYBADGE_ + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( OBJECT_getIndex( objindex))){ + char cabuf[128]; + int fd = getfdFromCharaIndex( recvindex ); + if(fd > -1){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_FAMILYBADGE, getFamilyBadge( OBJECT_getIndex( objindex)))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif + /* watch ìëڳʾְ */ + if( !CHAR_sendWatchEvent_sendCheck( objindex, + index, recvindex , + chac + )) + { + break; + } + + watchfunc =(WATCHF)CHAR_getFunctionPointer( + OBJECT_getIndex(receiveobjindex), + CHAR_WATCHFUNC); + break; + case OBJTYPE_ITEM: + watchfunc = (WATCHF)ITEM_getFunctionPointer( + OBJECT_getIndex(receiveobjindex), + ITEM_WATCHFUNC); + break; + case OBJTYPE_NOUSE: + case OBJTYPE_GOLD: +#ifdef _DEL_DROP_GOLD + GOLD_DeleteTimeCheckOne( receiveobjindex); +#endif + default: + break; + } + + if( watchfunc != NULL ){ + watchfunc( receiveobjindex, objindex, chac, x, y, dir, + watchopt, watchoptlen ); + } + } + } + } +} + + +/*====================ƽ====================*/ +/*------------------------------------------------------------ + * ƽʧƥ·ë£ + * ¦ + * charaindex int ƽҷ̼͵ + * ߯Ի + * TRUE(1) + * ( ˱˪ئվ޷¡ֳľ) FALSE(0) + ------------------------------------------------------------*/ +BOOL CHAR_Skillupsend(int charaindex ) +{ +#if 1 + // ̳ñ ּ + int point; + int fd; + if( !CHAR_CHECKINDEX(charaindex) )return FALSE; + // ʹ̼ʧƥ¾ + point = CHAR_getInt( charaindex, CHAR_SKILLUPPOINT ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1){ + lssproto_SKUP_send(fd, point ); + } + return TRUE; +#else + char sendbuf[128]; + + // շLS2ݼּ + if(SKILL_getUpableSkillID(charaindex,sendbuf,sizeof(sendbuf))){ + int fd; + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 && sendbuf[0] != '\0' ){ + lssproto_SKUP_send(fd,sendbuf); + return TRUE; + } + } +#endif + return FALSE; +} + +/*------------------------------------------------------------ + * ƽʧ + * ¦ + * charaindex int ƽҷ̼͵ + * skillid int ƽID + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_SkillUp( int charaindex, int skillid ) +{ + if( !CHAR_CHECKINDEX(charaindex) )return; + + /*ƥƥئ */ + if( CHAR_getFlg(charaindex,CHAR_ISDIE) )return; + + { + int SkUpTbl[] = { CHAR_VITAL, CHAR_STR, CHAR_TOUGH, CHAR_DEX }; + int SendTbl[] = { CHAR_P_STRING_VITAL|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF, + CHAR_P_STRING_STR|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK, + CHAR_P_STRING_TOUGH|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF, + CHAR_P_STRING_DEX|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK|CHAR_P_STRING_QUICK + }; + int cnt; + // + if( skillid < 0 || skillid >= 4 ){ + return; + } + // ɷ¶ʧƥ¾ + cnt = CHAR_getInt(charaindex,CHAR_SKILLUPPOINT); + if( cnt <= 0 )return; + +#ifdef _CHAR_PROFESSION // WON ADD ְҵλ + { + int p_class = CHAR_getInt( charaindex, PROFESSION_CLASS ); + int fd=-1; + + switch( p_class ){ + case PROFESSION_CLASS_FIGHTER: + // ʿ200 + if( SkUpTbl[skillid] == CHAR_DEX ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 200 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + break; + case PROFESSION_CLASS_WIZARD: + // ʦ200 + if( SkUpTbl[skillid] == CHAR_STR ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 200 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + // ʦ200 + if( SkUpTbl[skillid] == CHAR_TOUGH ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 200 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + break; + case PROFESSION_CLASS_HUNTER: + // 200 + if( SkUpTbl[skillid] == CHAR_STR ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 200 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + // 200 + if( SkUpTbl[skillid] == CHAR_TOUGH ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 200 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + // 400 + if( SkUpTbl[skillid] == CHAR_DEX ){ + if( CHAR_getInt( charaindex, SkUpTbl[skillid] ) >= 400 * 100 ){ + CHAR_talkToCli(charaindex, -1, "ֵѴ", CHAR_COLORYELLOW ); + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt ); + return; + } + } + break; + default: break; + } + + fd = getfdFromCharaIndex(charaindex); + if( fd != -1 ) lssproto_SKUP_send( fd, cnt-1 ); + } +#endif + + CHAR_setInt( charaindex,CHAR_SKILLUPPOINT,cnt-1); + CHAR_setInt( charaindex, SkUpTbl[skillid], CHAR_getInt( charaindex, SkUpTbl[skillid] ) + 1*100 ); + + CHAR_complianceParameter(charaindex); + CHAR_send_P_StatusString( charaindex, SendTbl[skillid]); + CHAR_Skillupsend(charaindex); + +#ifdef _ANGEL_SUMMON // ӵʱʸ + if( cnt-1 == 0 ) + //selectAngel( charaindex); + selectAngel( charaindex, -1, -1 , FALSE); + +#endif + } + CHAR_PartyUpdate( charaindex, CHAR_N_STRING_MAXHP ); + +} + +INLINE void CHAR_getDXDY( int dir , int* dx, int* dy ) +{ + static POINT CHAR_dxdy[8]= + { + { 0,-1}, /* */ + { 1,-1}, /* */ + { 1, 0}, /* */ + { 1, 1}, /* */ + { 0, 1}, /* */ + {-1, 1}, /* */ + {-1, 0}, /* */ + {-1,-1}, /* */ + }; + VALIDATEDIR(dir); + + if( dx )*dx = CHAR_dxdy[dir].x; + if( dy )*dy = CHAR_dxdy[dir].y; +} +INLINE int CHAR_getDX( int dir ) +{ + int tmp; + CHAR_getDXDY( dir,&tmp,NULL); + return tmp; +} +INLINE int CHAR_getDY( int dir ) +{ + int tmp; + CHAR_getDXDY( dir,NULL,&tmp); + return tmp; +} + +/*------------------------------------------------------------ + * ԪѨƽҷë £ + * ¦ + * objbuf int* object ƥ index ëҽ + * + * siz int objbuf + * ff int ׷ʧ + * fx int x + * fy int y + * ߯Ի + * ƽҷ»¾ + ------------------------------------------------------------*/ +int CHAR_getSameCoordinateObjects(int* objbuf, int siz,int ff, int fx, int fy) +{ + OBJECT object; + int findobjnum=0; + + for( object = MAP_getTopObj(ff,fx,fy) ; object ; + object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + + if( siz <= findobjnum )break; + if( OBJECT_getType(objindex) != OBJTYPE_NOUSE ) + objbuf[findobjnum++] = objindex; + } + return findobjnum; +} + + +/*====================ƽҷ¼ ë ̼====================*/ +/* ٯ ë*/ +static char CHAR_optiondataString[STRINGBUFSIZ]; +/*------------------------------------------------------------ + * ü ٯ ë£ + * level, showstring , ۼ , į ϼԷ̼׾ + * ͷµ + * ¦ + * ch Char* ƽҷ· + * ߯Ի + * char* static ئ ë߯ʼƥݼԼ̫Ƽݱ巴 + * ʽľ£¦ëئǣ + ------------------------------------------------------------*/ +char* CHAR_makeOptionString( Char* ch ) +{ + char escapeshowstring[256]; + char *showstr = MAP_getfloorShowstring(ch->data[CHAR_FLOOR]); + if( ! showstr ){ + CHAR_optiondataString[0] = '\0'; + return CHAR_optiondataString; + } else { + /* ƱStoneAge ƥؤ£ + + dataplace|faceimg|level|hp|str|def|dex|charm|dp|earth|water|fire|wind|login|Name|Place + ئ£ + */ + { + snprintf( CHAR_optiondataString, + sizeof( CHAR_optiondataString ), + "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s", + ch->data[CHAR_DATAPLACENUMBER], + ch->data[CHAR_FACEIMAGENUMBER], + ch->data[CHAR_LV], + ch->workint[CHAR_WORKMAXHP], + ch->workint[CHAR_WORKATTACKPOWER], + ch->workint[CHAR_WORKDEFENCEPOWER], + ch->workint[CHAR_WORKQUICK], + ch->workint[CHAR_WORKFIXCHARM], + ch->data[CHAR_DUELPOINT], /* dp, FIXME */ + ch->workint[CHAR_WORKFIXEARTHAT], + ch->workint[CHAR_WORKFIXWATERAT], + ch->workint[CHAR_WORKFIXFIREAT], + ch->workint[CHAR_WORKFIXWINDAT], + ch->data[CHAR_LOGINCOUNT], + ch->string[CHAR_NAME].string, + makeEscapeString( showstr , + escapeshowstring, + sizeof(escapeshowstring) ) + ); + } + } + return CHAR_optiondataString; +} + +static char CHAR_statusSendBuffer[STRINGBUFSIZ]; + +char* CHAR_makeStatusString( int index, char* category ) +{ + char c = tolower( category[0] ); + int strlength=0; + + if( !CHAR_CHECKINDEX( index ) ) return "\0"; + + if( category == "\0" ){ + CHAR_statusSendBuffer[0] = '\0'; + return CHAR_statusSendBuffer; + } + switch( c ){ + case 'p': + { + int i; + int getCharDataArray[]= { + CHAR_NAME, + CHAR_OWNTITLE, + //CHAR_FMNAME, + }; + int exp = CHAR_getInt(index,CHAR_EXP ); + int maxexp = CHAR_GetLevelExp( index, CHAR_getInt( index, CHAR_LV ) + 1); + int attr[4]; + + for( i = 0; i < 4; i ++ ) { + attr[i] = CHAR_getWorkInt( index, CHAR_WORKFIXEARTHAT + i); + if( attr[i] < 0 ) attr[i] = 0; + } +#ifdef _NEW_RIDEPETS +#ifdef _RIDEMODE_20 + int playerlowsride; + if( getRideMode() == 2 ){ + playerlowsride=RIDE_PET8|RIDE_PET9; + }else{ + playerlowsride=CHAR_getInt( index, CHAR_LOWRIDEPETS); + } +#else + int playerlowsride=CHAR_getInt( index, CHAR_LOWRIDEPETS); +#endif +#endif + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), +#ifdef _VERSION_25 + "P1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#else + "P1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#endif + CHAR_getInt(index,CHAR_HP), + CHAR_getWorkInt(index,CHAR_WORKMAXHP), + CHAR_getInt(index,CHAR_MP), + CHAR_getWorkInt(index,CHAR_WORKMAXMP), + CHAR_getInt(index,CHAR_VITAL)/100, + CHAR_getInt(index,CHAR_STR)/100, + CHAR_getInt(index,CHAR_TOUGH)/100, + CHAR_getInt(index,CHAR_DEX)/100, + exp, maxexp, + CHAR_getInt(index,CHAR_LV), + CHAR_getWorkInt(index,CHAR_WORKATTACKPOWER), + CHAR_getWorkInt(index,CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt( index, CHAR_WORKQUICK), + CHAR_getWorkInt( index, CHAR_WORKFIXCHARM), + CHAR_getWorkInt( index, CHAR_WORKFIXLUCK), + attr[0], + attr[1], + attr[2], + attr[3], + CHAR_getInt(index,CHAR_GOLD), + CHAR_getInt(index,CHAR_INDEXOFEQTITLE), + CHAR_getInt(index,CHAR_DUELPOINT), + CHAR_getInt( index, CHAR_TRANSMIGRATION), + CHAR_getInt(index,CHAR_RIDEPET), + CHAR_getInt(index,CHAR_LEARNRIDE), + CHAR_getInt(index,CHAR_BASEBASEIMAGENUMBER) +#ifdef _NEW_RIDEPETS +#ifdef _RIDEMODE_20 + ,playerlowsride +#else + + ,CHAR_getInt( index, CHAR_LOWRIDEPETS) +#endif +#endif + + ); + strlength = strlen( CHAR_statusSendBuffer ); + for( i = 0 ; i < arraysizeof( getCharDataArray ) ; i ++ ){ + char token[256]; + char escapebuffer[128]; + + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( CHAR_getChar(index, getCharDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer ) ) + return CHAR_statusSendBuffer; + } + extern int NPC_StartpointCheck(int meindex,int talker); + strlength = strlen( CHAR_statusSendBuffer ); + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1, +#ifdef _NEW_ITEM_ + "%d" +#endif +#ifdef CHAR_RECORD_POINT + "|%d" +#endif +#ifdef _NEW_ITEM_ + ,CHAR_getInt ( index, CHAR_NEWITEMFLG) +#endif +#ifdef CHAR_RECORD_POINT + ,NPC_StartpointCheck(0,index) +#endif + ); +#ifdef _CHARSIGNDAY_ + strlength = strlen( CHAR_statusSendBuffer ); + int sdate,ret; + sdate = CHAR_getInt( index,CHAR_QIANDAORI); + int nowtime = time(NULL); + struct tm * time = localtime(&nowtime); + int date=time->tm_mday; + if( sdate != date) + ret = 0; + else + ret = 1; + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1,"|%d" ,ret); +#endif +#ifdef _TRUMP_EQUIPMENT +#ifndef _BRAND_NEW_25 + strlength = strlen( CHAR_statusSendBuffer ); + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1, + "|%d" + ,CHAR_getInt ( index, CHAR_TRUMPFLG) + ); +#endif +#endif + return CHAR_statusSendBuffer; + break; + } +#ifdef _NEW_RIDEPETS + case 'x': + { +#ifdef _RIDEMODE_20 + int playerlowsride; + if( getRideMode() == 2 ){ + playerlowsride=RIDE_PET8|RIDE_PET9; + }else{ + playerlowsride=CHAR_getInt( index, CHAR_LOWRIDEPETS); + } +#else + int playerlowsride=CHAR_getInt( index, CHAR_LOWRIDEPETS); +#endif + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), "X0|%d", + playerlowsride); + return CHAR_statusSendBuffer; + break; + } +#endif + case 'f': + { + int big4fm =0; +#ifndef _NEW_RIDEPETS + switch( CHAR_getWorkInt( index, CHAR_WORKFMFLOOR) ) + { + case 1041: + big4fm = 1; + break; + case 2031: + big4fm = 2; + break; + case 3031: + big4fm = 3; + break; + case 4031: + big4fm = 4; + break; + default: + big4fm = 0; + } +#endif +#ifdef _FIX_FMNAME_RULE // WON ADD δʾ + if( CHAR_getWorkInt(index, CHAR_WORKFMSETUPFLAG)==1 ){ + snprintf( CHAR_statusSendBuffer, + sizeof( CHAR_statusSendBuffer ), + "F%s|%d|%d|%d|%d", + "()", + CHAR_getInt( index, CHAR_FMLEADERFLAG), + CHAR_getWorkInt( index, CHAR_WORKFMCHANNEL), + CHAR_getInt( index, CHAR_FMSPRITE), big4fm ); + }else +#endif + snprintf( CHAR_statusSendBuffer, + sizeof( CHAR_statusSendBuffer ), + "F%s|%d|%d|%d|%d", + CHAR_getChar( index, CHAR_FMNAME), + CHAR_getInt( index, CHAR_FMLEADERFLAG), + CHAR_getWorkInt( index, CHAR_WORKFMCHANNEL), + CHAR_getInt( index, CHAR_FMSPRITE), big4fm ); + return CHAR_statusSendBuffer; + break; + } + case 'c': + { + int floor,xsiz,ysiz; + floor = CHAR_getInt(index,CHAR_FLOOR); + xsiz = MAP_getfloorX(floor); + ysiz = MAP_getfloorY(floor); + snprintf( CHAR_statusSendBuffer, + sizeof( CHAR_statusSendBuffer ), + "C%d|%d|%d|%d|%d", + CHAR_getInt(index,CHAR_FLOOR), + xsiz, ysiz, + CHAR_getInt(index,CHAR_X), + CHAR_getInt(index,CHAR_Y) ); + return CHAR_statusSendBuffer; + break; + } + case 'i': + { + int i; + CHAR_statusSendBuffer[0] = 'I'; + strlength = 1; + for( i = 0 ; i < CheckCharMaxItem(index) ; i ++ ){ + char token[512]; + int itemindex; + itemindex = CHAR_getItemIndex( index, i ); + if( itemindex >= 0 ) { + snprintf( token ,sizeof(token),"%s|" ,ITEM_makeItemStatusString( -1, itemindex ) ); + }else { + snprintf( token ,sizeof(token),"%s|" , ITEM_makeItemFalseString() ); + } + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) return CHAR_statusSendBuffer; + } + dchop( CHAR_statusSendBuffer , "|" ); + return CHAR_statusSendBuffer; + break; + } + case 's': + { + int i; + CHAR_statusSendBuffer[0] = 'S'; + strlength = 1; + + for( i = 0 ; i < CHAR_SKILLMAXHAVE ; i ++ ){ + char token[256]; + CHAR_HaveSkill* hskill; + + hskill = CHAR_getCharHaveSkill( index, i ); + + if( hskill != NULL && hskill->use == TRUE ){ +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + snprintf( token , sizeof(token), "%s|", SKILL_makeSkillStatusString(&hskill->skill, index, i) ); +#else + snprintf( token , sizeof(token), "%s|", SKILL_makeSkillStatusString(&hskill->skill) ); +#endif + }else{ + snprintf( token , sizeof(token), "%s|", SKILL_makeSkillFalseString() ); + } + + strcpysafe( CHAR_statusSendBuffer + strlength, sizeof(CHAR_statusSendBuffer)-strlength, token ); + + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) + return CHAR_statusSendBuffer; + } + + dchop( CHAR_statusSendBuffer , "|" ); + return CHAR_statusSendBuffer; + break; + } + case 't': + { + int i; + CHAR_statusSendBuffer[0] = 'T'; + strlength = 1; + for( i = 0 ; i < CHAR_TITLEMAXHAVE ; i ++ ){ + char token[256]; + char escape[256]; + snprintf( token , sizeof(token), "%s|" , + makeEscapeString( TITLE_makeTitleStatusString(index, + i ), + escape,sizeof(escape) ) ); + + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) + return CHAR_statusSendBuffer; + } + dchop( CHAR_statusSendBuffer , "|" ); + return CHAR_statusSendBuffer; + break; + } + case 'd': + snprintf( CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "D%d|%ld",CHAR_getWorkInt(index,CHAR_WORKOBJINDEX), + NowTime.tv_sec ); + return CHAR_statusSendBuffer; + break; + case 'm': + snprintf( CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "M%d|%d|%d", + CHAR_getInt( index,CHAR_HP ), + CHAR_getInt( index,CHAR_MP ), + CHAR_getInt( index,CHAR_EXP ) ); + return CHAR_statusSendBuffer; + break; + case 'e': + return "\0"; + + case 'n': + { + int num; + + int i, nindex = -1; + int getCharDataArray[]= { + CHAR_NAME + }; + num = tolower( category[1] ) - '0'; + + if( num < 0 || num >= getPartyNum(index)){ + print( "1ģʽʧ %d %s\n", num, CHAR_getChar(index,CHAR_NAME) ); + break; + } + + nindex = CHAR_getPartyIndex( index, num); + + if( nindex == -1 ){ + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "N%d|0|", num ); + return CHAR_statusSendBuffer; + }else{ + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "N%d|1|%d|%d|%d|%d|%d|", + num, + CHAR_getWorkInt( nindex, CHAR_WORKOBJINDEX), + CHAR_getInt( nindex, CHAR_LV), + CHAR_getWorkInt( nindex, CHAR_WORKMAXHP), + CHAR_getInt( nindex, CHAR_HP), + CHAR_getInt( nindex, CHAR_MP) + + ); + } + strlength = strlen( CHAR_statusSendBuffer ); + + for( i = 0 ; i < arraysizeof( getCharDataArray ) ; i ++ ){ + char token[256]; + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( CHAR_getChar(nindex, + getCharDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer ) ) + return CHAR_statusSendBuffer; + } + + return CHAR_statusSendBuffer; + break; + } + case 'k': + { + int num; + int i, pindex; + int getCharDataArray[]= { + CHAR_NAME, + CHAR_USERPETNAME, + }; + num = tolower( category[1] ) - '0'; + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ģʽʧ (%c)%d \n", num, num ); + break; + } + pindex = CHAR_getCharPet( index, num ); + if( pindex == -1 ){ + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "K%d|0|", num ); + return CHAR_statusSendBuffer; + }else{ + int attr[4]; + BOOL changenameflg = FALSE; + char *mycdkey; + char *cdkey = NULL; + for( i = 0; i < 4; i ++ ) { + attr[i] = CHAR_getWorkInt( pindex, CHAR_WORKFIXEARTHAT + i); + if( attr[i] < 0 ) attr[i] = 0; + } + mycdkey = CHAR_getChar( index, CHAR_CDKEY); + { + cdkey = CHAR_getChar( pindex, CHAR_CDKEY); + if( cdkey == "\0" ) { + print( "can't get CDKEY\n"); + }else { + + if( strlen( cdkey) == 0 || + strcmp( cdkey, mycdkey) == 0 ){ + changenameflg = TRUE; + } + } + } + + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), +#ifdef _VERSION_NEW + "K%d|1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#else +#ifdef _VERSION_25 + "K%d|1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#else +// Syu ADD ı佻ʱתɫ +#ifdef _SHOW_FUSION + "K%d|1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#else + "K%d|1|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|", +#endif +#endif +#endif + num, + CHAR_getInt(pindex,CHAR_BASEIMAGENUMBER), + CHAR_getInt(pindex,CHAR_HP), + CHAR_getWorkInt(pindex,CHAR_WORKMAXHP), + CHAR_getInt(pindex,CHAR_MP), + CHAR_getWorkInt(pindex,CHAR_WORKMAXMP), + CHAR_getInt(pindex,CHAR_EXP ), + CHAR_GetLevelExp( pindex,CHAR_getInt( pindex, CHAR_LV ) + 1), + CHAR_getInt(pindex,CHAR_LV), + CHAR_getWorkInt(pindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt(pindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt( pindex, CHAR_WORKQUICK), + CHAR_getWorkInt( pindex, CHAR_WORKFIXAI), + attr[0], + attr[1], + attr[2], + attr[3], + CHAR_getInt( pindex, CHAR_SLOT), +// Syu ADD ı佻ʱתɫ + changenameflg, + CHAR_getInt( pindex,CHAR_TRANSMIGRATION) +#ifdef _VERSION_NEW +#ifdef _SHOW_FUSION + ,CHAR_getInt ( pindex, CHAR_FUSIONBEIT) +#else + ,0 +#endif +#endif + ); + + } + strlength = strlen( CHAR_statusSendBuffer ); + for( i = 0 ; i < arraysizeof( getCharDataArray ) ; i ++ ){ + char token[256]; + char escapebuffer[128]; +#ifdef _POWER_UP + if(i == 0){ + char str[][4] = {"", "A", "B", "C", "D"}; + char buff[64]; + int value = 0; + int type = 0; + + if(getStringFromIndexWithDelim( CHAR_getChar(pindex, CHAR_POWER_UP) , "|" , 1, buff , sizeof(buff) ) == TRUE){ + type = atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(pindex, CHAR_POWER_UP) , "|" , 2, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(pindex, CHAR_POWER_UP) , "|" , 3, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(pindex, CHAR_POWER_UP) , "|" , 4, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + + if(type > 0){ + snprintf( token, + sizeof( token ), + "%s %s+%d" STATUSSENDDELIMITER, + makeEscapeString( CHAR_getChar(pindex,getCharDataArray[i]),escapebuffer,sizeof(escapebuffer)), + str[type], + value + ); + }else{ + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( CHAR_getChar(pindex, + getCharDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + } + }else +#endif +{ + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( CHAR_getChar(pindex, + getCharDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); +} + + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer ) ) + return CHAR_statusSendBuffer; + } + +#ifdef _PET_VALIDITY + { + char token[256]; + if(CHAR_getInt ( pindex, CHAR_PETVALIDITY)==0){ + snprintf( token, sizeof( token ), "Ч" STATUSSENDDELIMITER); + }else if(CHAR_getInt ( pindex, CHAR_PETVALIDITY)>time(NULL)){ + time_t petvalidity = (time_t)CHAR_getInt(pindex, CHAR_PETVALIDITY); + struct tm *tm1 = localtime(&petvalidity); + + snprintf( token, sizeof( token ), "%04d-%02d-%02d|", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday); + }else{ + snprintf( token, sizeof( token ), "Ѿ" STATUSSENDDELIMITER); + } + + strcat( CHAR_statusSendBuffer,token ); + } +#endif +#ifdef _PETCOM_ + strlength = strlen( CHAR_statusSendBuffer ); + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1,"%d|%d|%d|%d|%d|" + ,CHAR_getInt ( pindex, CHAR_YHP) + ,CHAR_getInt ( pindex, CHAR_YATK) + ,CHAR_getInt ( pindex, CHAR_YDEF) + ,CHAR_getInt ( pindex, CHAR_YQUICK) + ,CHAR_getInt ( pindex, CHAR_YLV)); +#endif +#ifdef _RIDEFLG_ + strlength = strlen( CHAR_statusSendBuffer ); + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1,"%d|" ,FamilyRideCheck(index,pindex,num)); + +#endif +#ifdef _VISUAL_BEATITUDE + strlength = strlen( CHAR_statusSendBuffer ); + snprintf(CHAR_statusSendBuffer+strlength,sizeof(CHAR_statusSendBuffer)-strlength-1,"%s|" ,BeatitudeCheck(index,pindex,num)); +#endif + return CHAR_statusSendBuffer; + break; + } + + case 'j': +{ + + int num; + int i, itemindex; + int getMagicDataArray[]= { + MAGIC_NAME, + MAGIC_COMMENT, + }; + num = tolower( category[1] ) - '0'; + + if( num < 0 || num >= CHAR_EQUIPPLACENUM ){ + break; + } + + itemindex = CHAR_getItemIndex( index, num ); + if( !ITEM_CHECKINDEX( itemindex) ) { + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "J%d|0|", num ); + return CHAR_statusSendBuffer; + }else{ + int magicindex = MAGIC_getMagicArray( ITEM_getInt( itemindex, ITEM_MAGICID)); + if( magicindex == -1 ) { + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "J%d|0|", num ); + return CHAR_statusSendBuffer; + } + snprintf(CHAR_statusSendBuffer,sizeof(CHAR_statusSendBuffer), + "J%d|1|%d|%d|%d|", + num, + ITEM_getInt( itemindex, ITEM_MAGICUSEMP), + MAGIC_getInt( magicindex, MAGIC_FIELD), + MAGIC_getInt( magicindex, MAGIC_TARGET)); + strlength = strlen( CHAR_statusSendBuffer ); + + for( i = 0 ; i < arraysizeof( getMagicDataArray ) ; i ++ ){ + char token[256]; + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( MAGIC_getChar(magicindex, + getMagicDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer ) ) + return CHAR_statusSendBuffer; + } + return CHAR_statusSendBuffer; + } + } + break; + + case 'w': +{ + int num; + int i,petskillloop, pindex; + char tmp[16]; + int getPetSkillDataArray[]= { + PETSKILL_NAME, + PETSKILL_COMMENT, + }; + + num = tolower( category[1] ) - '0'; + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ؼʧ (%c)%d \n", num, num ); + break; + } + + pindex = CHAR_getCharPet( index, num ); + if( !CHAR_CHECKINDEX(pindex)){ + return "\0"; + } + snprintf( tmp, sizeof( tmp), "W%d|", num); + strcpysafe( CHAR_statusSendBuffer, sizeof( CHAR_statusSendBuffer), + tmp); + strlength += strlen( tmp); + if( strlength >= arraysizeof( CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + for( petskillloop = 0; petskillloop < CHAR_MAXPETSKILLHAVE; petskillloop ++ ) { + int skillid = CHAR_getPetSkill( pindex, petskillloop); + int petskillindex = PETSKILL_getPetskillArray( skillid ); + if( PETSKILL_CHECKINDEX( petskillindex) ) { + char token[256]; + + snprintf( token, sizeof( token), + "%d|%d|%d|", +#ifdef _EXPANSION_ITEM_INSLAY + strcmp(PETSKILL_getChar(petskillindex, PETSKILL_FUNCNAME), "PETSKILL_Inslay")==0?572:PETSKILL_getInt( petskillindex, PETSKILL_ID), +#else + PETSKILL_getInt( petskillindex, PETSKILL_ID), +#endif + PETSKILL_getInt( petskillindex, PETSKILL_FIELD), + PETSKILL_getInt( petskillindex, PETSKILL_TARGET) + ); + + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer)) { + return CHAR_statusSendBuffer; + } + + for( i = 0 ; i < arraysizeof( getPetSkillDataArray ) ; i ++ ){ + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( + PETSKILL_getChar(petskillindex, + getPetSkillDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer )) { + return CHAR_statusSendBuffer; + } + } + } + else { + char token[256]; + snprintf( token, sizeof( token),"|||||"); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + } + } + return CHAR_statusSendBuffer; +} + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + case 'y': +{ + int num = 0, f_num = 0; + int i,petskillloop, pindex; + char tmp[16]; + int getPetSkillDataArray[]= { + PETSKILL_NAME, + PETSKILL_COMMENT, + }; + + num = tolower( category[1] ) - '0'; + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ؼʧ (%c)%d \n", num, num ); + break; + } + + pindex = CHAR_getCharPet( index, num ); + if( !CHAR_CHECKINDEX(pindex)){ + return "\0"; + } + snprintf( tmp, sizeof( tmp), "W%d|", num); + strcpysafe( CHAR_statusSendBuffer, sizeof( CHAR_statusSendBuffer), + tmp); + strlength += strlen( tmp); + if( strlength >= arraysizeof( CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + + if( CHAR_getWorkInt( pindex, CHAR_WORKOBLIVION) > 0 ) + f_num = CHAR_getWorkInt( pindex, CHAR_WORKMODOBLIVION ) + 1;// 輼 + + for( petskillloop = 0; petskillloop < CHAR_MAXPETSKILLHAVE; petskillloop ++ ) { + int skillid = CHAR_getPetSkill( pindex, petskillloop); + int petskillindex = PETSKILL_getPetskillArray( skillid ); + if( PETSKILL_CHECKINDEX( petskillindex) ) { + char token[256]; + int field = -1, target = -1; + int oblivion = CHAR_getWorkInt( pindex, CHAR_WORKOBLIVION ); + int p_id = PETSKILL_getInt( petskillindex, PETSKILL_ID); + int rand_num = RAND( 0, 100 ); + + // + if( (oblivion > 0) && ( f_num > 0 ) && ( rand_num <= 60 ) && ( p_id != 1 ) ){ + field = PETSKILL_FIELD_MAP; + target = PETSKILL_TARGET_NONE; + f_num --; + }else{ + field = PETSKILL_getInt( petskillindex, PETSKILL_FIELD); + target = PETSKILL_getInt( petskillindex, PETSKILL_TARGET); + } + + snprintf( token, sizeof( token),"%d|%d|%d|", +// PETSKILL_getInt( petskillindex, PETSKILL_ID), + p_id, + field, target + ); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer)) { + return CHAR_statusSendBuffer; + } + + for( i = 0 ; i < arraysizeof( getPetSkillDataArray ) ; i ++ ){ + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( + PETSKILL_getChar(petskillindex, + getPetSkillDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer )) { + return CHAR_statusSendBuffer; + } + } + } + else { + char token[256]; + snprintf( token, sizeof( token),"|||||"); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + } + } + return CHAR_statusSendBuffer; +} +#endif + +#ifdef _PETSKILL_DAMAGETOHP + case 'o': +{ + int getPetSkillDataArray[]= { + PETSKILL_NAME, + PETSKILL_COMMENT, + }; + int i,petskillloop, pindex=index; + int num = 0;//, f_num = 0; + char tmp[16]; + + num = tolower( category[1] ) - '0'; + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ؼʧ (%c)%d \n", num, num ); + break; + } + + pindex = CHAR_getCharPet( index, num ); + if( !CHAR_CHECKINDEX(pindex)){ + return "\0"; + } + snprintf( tmp, sizeof( tmp), "W%d|", num); + strcpysafe( CHAR_statusSendBuffer, sizeof( CHAR_statusSendBuffer), + tmp); + strlength += strlen( tmp); + if( strlength >= arraysizeof( CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + + for( petskillloop = 0; petskillloop < CHAR_MAXPETSKILLHAVE; petskillloop ++ ) { + int skillid = CHAR_getPetSkill( pindex, petskillloop); + int petskillindex = PETSKILL_getPetskillArray( skillid ); + if( PETSKILL_CHECKINDEX( petskillindex) ) { + char token[256]; + int field = -1, target = -1; + //int oblivion = CHAR_getWorkInt( pindex, CHAR_WORKOBLIVION ); + int p_id = PETSKILL_getInt( petskillindex, PETSKILL_ID); + + //50%ҼΪ ԡѪϮ ܲѡ + if( ( CHAR_getInt( pindex, CHAR_HP ) > CHAR_getWorkInt( pindex, CHAR_WORKMAXHP )*0.5 + && strcmp(PETSKILL_getChar( petskillindex, PETSKILL_NAME),"ԡѪϮ" ) == 0 ) +#ifdef _PETSKILL_EXPLODE + || ( CHAR_getInt( pindex, CHAR_HP ) < (CHAR_getWorkInt( pindex, CHAR_WORKMAXHP ) >> 1 ) + && strcmp(PETSKILL_getChar( petskillindex, PETSKILL_NAME),"ѹ" ) == 0 ) +#endif + ){ + field = PETSKILL_FIELD_MAP; + target = PETSKILL_TARGET_NONE; + }else{ + field = PETSKILL_getInt( petskillindex, PETSKILL_FIELD); + target = PETSKILL_getInt( petskillindex, PETSKILL_TARGET); + } + + snprintf( token, sizeof( token),"%d|%d|%d|", +// PETSKILL_getInt( petskillindex, PETSKILL_ID), + p_id, + field, target + ); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer)) { + return CHAR_statusSendBuffer; + } + + for( i = 0 ; i < arraysizeof( getPetSkillDataArray ) ; i ++ ){ + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( + PETSKILL_getChar(petskillindex, + getPetSkillDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer )) { + return CHAR_statusSendBuffer; + } + } + } + else { + char token[256]; + snprintf( token, sizeof( token),"|||||"); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + } + } + return CHAR_statusSendBuffer; +} +#endif + +#ifdef _PETSKILL_BECOMEFOX + case 'a': +{ + int getPetSkillDataArray[]= { + PETSKILL_NAME, + PETSKILL_COMMENT, + }; + int i,petskillloop, pindex=index; + int num = 0;//, f_num = 0; + char tmp[16]; + + num = tolower( category[1] ) - '0'; + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ؼʧ (%c)%d \n", num, num ); + break; + } + print( "ؼ" ); + pindex = CHAR_getCharPet( index, num ); + if( !CHAR_CHECKINDEX(pindex)){ + return "\0"; + } + snprintf( tmp, sizeof( tmp), "W%d|", num); + strcpysafe( CHAR_statusSendBuffer, sizeof( CHAR_statusSendBuffer), + tmp); + strlength += strlen( tmp); + if( strlength >= arraysizeof( CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + + for( petskillloop = 0; petskillloop < CHAR_MAXPETSKILLHAVE; petskillloop ++ ) { + int skillid = CHAR_getPetSkill( pindex, petskillloop); + int petskillindex = PETSKILL_getPetskillArray( skillid ); + if( PETSKILL_CHECKINDEX( petskillindex) ) { + char token[256]; + int field = -1, target = -1; + //int oblivion = CHAR_getWorkInt( pindex, CHAR_WORKOBLIVION ); + int p_id = PETSKILL_getInt( petskillindex, PETSKILL_ID); + + //Ϊ ܲѡ + print("\n:%s",PETSKILL_getChar( petskillindex, PETSKILL_NAME)); + if( strcmp(PETSKILL_getChar( petskillindex, PETSKILL_NAME),"" ) == 0 + || strcmp(PETSKILL_getChar( petskillindex, PETSKILL_NAME),"" ) == 0 + || strcmp(PETSKILL_getChar( petskillindex, PETSKILL_NAME),"" ) == 0){ + field = PETSKILL_getInt( petskillindex, PETSKILL_FIELD); + target = PETSKILL_getInt( petskillindex, PETSKILL_TARGET); + }else{ + field = PETSKILL_FIELD_MAP; + target = PETSKILL_TARGET_NONE; + } + + snprintf( token, sizeof( token),"%d|%d|%d|", +// PETSKILL_getInt( petskillindex, PETSKILL_ID), + p_id, + field, target + ); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer)) { + return CHAR_statusSendBuffer; + } + + for( i = 0 ; i < arraysizeof( getPetSkillDataArray ) ; i ++ ){ + char escapebuffer[128]; + snprintf( token, + sizeof( token ), + "%s" STATUSSENDDELIMITER, + makeEscapeString( + PETSKILL_getChar(petskillindex, + getPetSkillDataArray[i]), + escapebuffer,sizeof(escapebuffer) + )); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof( CHAR_statusSendBuffer ) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= sizeof( CHAR_statusSendBuffer )) { + return CHAR_statusSendBuffer; + } + } + } + else { + char token[256]; + snprintf( token, sizeof( token),"|||||"); + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, + token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) { + return CHAR_statusSendBuffer; + } + } + } + return CHAR_statusSendBuffer; +} +#endif + + default: + break; + } + + CHAR_statusSendBuffer[0] = '\0'; + return CHAR_statusSendBuffer; +} + +//BOOL CHAR_sendStatusString( int charaindex, char* category ) +BOOL _CHAR_sendStatusString( int charaindex, char* category, char* file, int line ) +{ + char* string; + + //print("\nsend_S:%s:%d ", file, line); + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ){ + return FALSE; + } + string = CHAR_makeStatusString( charaindex, category ); + if( string != "\0" ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ){ + lssproto_S_send( fd, string ); + return TRUE; + } + } + return FALSE; +} + +void CHAR_inputOwnTitle( int index ,char* name ) +{ + if( !CHAR_CHECKINDEX( index ) ) return; + + if( CHAR_getFlg( index,CHAR_ISDIE ) )return; + + CHAR_setChar( index, CHAR_OWNTITLE ,name); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( index, CHAR_WORKOBJINDEX) ); + + CHAR_send_P_StatusString( index, CHAR_P_STRING_OWNTITLE ); +} + +void CHAR_selectTitle( int index, int titleindex ) +{ + if( !CHAR_CHECKINDEX( index ) )return; + + if( CHAR_getFlg( index,CHAR_ISDIE ) )return; + + if( titleindex == -1 ){ + CHAR_setInt( index, CHAR_INDEXOFEQTITLE, titleindex); + }else if( titleindex < 0 || titleindex >= CHAR_TITLEMAXHAVE ) { + return; + } + else{ + + int title = CHAR_getCharHaveTitle( index,titleindex ); + + if( TITLE_getTitleIndex( title) != -1 ){ + CHAR_setInt( index, CHAR_INDEXOFEQTITLE, titleindex); + } + } + + CHAR_sendStatusString( index, "T" ); + CHAR_send_P_StatusString( index, CHAR_P_STRING_TITLE ); +} + + +void CHAR_deleteTitle( int index, int titleindex ) +{ + int title; + + if( !CHAR_CHECKINDEX( index ) )return; + /* ƥݷֻ */ + if( CHAR_getFlg( index,CHAR_ISDIE ) )return; + + if( titleindex < 0 || titleindex >= CHAR_TITLEMAXHAVE )return; + title = CHAR_getCharHaveTitle( index,titleindex ); + /*if( TITLE_CHECKTABLEINDEX( title ) == FALSE )*/ + if( TITLE_getTitleIndex( title) == -1 ) { + return; + } + CHAR_setCharHaveTitle( index,titleindex,-1 ); + + /* лȻ֧ئɣľئƱ */ + if( CHAR_getInt(index, CHAR_INDEXOFEQTITLE) == titleindex ) + CHAR_setInt(index, CHAR_INDEXOFEQTITLE, -1 ); + + /* + * ë˪£ + */ + CHAR_sendStatusString( index, "T" ); + CHAR_send_P_StatusString( index, CHAR_P_STRING_TITLE ); +} + +static void CHAR_initcharWorkInt( index ) +{ + float hp; + static struct substitutionTable{ + CHAR_WORKDATAINT workindex; + CHAR_DATAINT intindex; + }subtbl[]={ + { CHAR_WORKMAXMP, CHAR_MAXMP },// + { CHAR_WORKFIXFIREAT, CHAR_FIREAT },// + { CHAR_WORKFIXWATERAT, CHAR_WATERAT},//ˮ + { CHAR_WORKFIXEARTHAT, CHAR_EARTHAT},// + { CHAR_WORKFIXWINDAT, CHAR_WINDAT },// + { CHAR_WORKFIXCHARM, CHAR_CHARM },// + { CHAR_WORKFIXLUCK, CHAR_LUCK },// + { CHAR_WORKMODPOISON, CHAR_POISON },//ƶ + { CHAR_WORKMODPARALYSIS,CHAR_PARALYSIS },// + { CHAR_WORKMODSLEEP, CHAR_SLEEP },//˯ + { CHAR_WORKMODSTONE, CHAR_STONE },//ʯ + { CHAR_WORKMODDRUNK, CHAR_DRUNK },//ư + { CHAR_WORKMODCONFUSION, CHAR_CONFUSION }// + }; + int i; + for( i=0 ; i 0 ){ + CHAR_setWorkInt( index, CHAR_WORKFIXEARTHAT + (i + 2) % 4, attr * -1); + } + } + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + { + // 翹 + //for( i=0; i<3; i++) + // CHAR_setWorkInt( index, CHAR_WORK_F_RESIST+i, CHAR_getInt( index, PROFESSION_FIRE_R+i ) ); + } +#endif + + + CHAR_setWorkInt( index, CHAR_WORKFIXDEX,//ٶ + CHAR_getInt( index, CHAR_DEX) * 0.01 ); + CHAR_setWorkInt( index, CHAR_WORKFIXVITAL,// + CHAR_getInt( index, CHAR_VITAL) * 0.01 ); + CHAR_setWorkInt( index, CHAR_WORKFIXSTR,// + CHAR_getInt( index, CHAR_STR) * 0.01 * 1.0 +//#ifdef _BATTLE_NEWPOWER +// + CHAR_getInt( index, CHAR_DEX) * 0.01 * 0.05 +// + CHAR_getInt( index, CHAR_VITAL) * 0.01 * 0.05 ); // +//#else + + CHAR_getInt( index, CHAR_TOUGH) * 0.01 * 0.1 + + CHAR_getInt( index, CHAR_VITAL) * 0.01 * 0.1 + + CHAR_getInt( index, CHAR_DEX) * 0.01 * 0.05 ); +//#endif + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH,// + CHAR_getInt( index, CHAR_TOUGH) * 0.01 * 1.0 +//#ifdef _BATTLE_NEWPOWER +// + CHAR_getInt( index, CHAR_DEX) * 0.01 * 0.05 +// + CHAR_getInt( index, CHAR_VITAL) * 0.01 * 0.05 ); // +//#else + + CHAR_getInt(index,CHAR_STR) * 0.01 * 0.1 + + CHAR_getInt(index,CHAR_VITAL) * 0.01 * 0.1 + + CHAR_getInt(index,CHAR_DEX) * 0.01 * 0.05 ); +//#endif + +#ifdef _ITEMSET5_TXT + { + CHAR_setWorkInt( index, CHAR_WORKFIXARRANGE, 0); + CHAR_setWorkInt( index, CHAR_WORKFIXSEQUENCE, 0); + CHAR_setWorkInt( index, CHAR_WORKATTACHPILE, 0); + CHAR_setWorkInt( index, CHAR_WORKHITRIGHT, 0); + } +#endif + + + +#ifdef _ITEMSET6_TXT + { + CHAR_setWorkInt( index, CHAR_WORKNEGLECTGUARD, 0); + } +#endif + + CHAR_setWorkInt( index, CHAR_WORKATTACKPOWER, + CHAR_getWorkInt(index,CHAR_WORKFIXSTR) ); + CHAR_setWorkInt( index, CHAR_WORKDEFENCEPOWER, + CHAR_getWorkInt(index,CHAR_WORKFIXTOUGH) ); + CHAR_setWorkInt( index, CHAR_WORKQUICK, + CHAR_getWorkInt( index, CHAR_WORKFIXDEX)); + + hp = ( CHAR_getInt(index,CHAR_VITAL) * 4 + + CHAR_getInt(index,CHAR_STR) * 1 + + CHAR_getInt(index,CHAR_TOUGH) * 1 + + CHAR_getInt(index,CHAR_DEX) * 1 ) * 0.01; + + CHAR_setWorkInt( index, CHAR_WORKMAXHP, (int)hp ); + CHAR_setWorkInt( index, CHAR_WORKMAXMP, CHAR_getInt( index, CHAR_MAXMP)); + +#ifdef _ADD_DEAMGEDEFC + CHAR_setWorkInt( index, CHAR_WORKOTHERDMAGE, 0); + CHAR_setWorkInt( index, CHAR_WORKOTHERDEFC, 0); +#endif + +#ifdef _FMPOINT_APPEND_ABI + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + if(CHAR_getInt( index, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE + && CHAR_getInt( index, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY ){ + int floorid = CHAR_getInt( index, CHAR_FLOOR); + if(floorid != 1042 && floorid != 2032 && floorid != 3032 && floorid != 4032){ + switch( CHAR_getWorkInt( index, CHAR_WORKFMFLOOR) ){ + case 1041: + CHAR_setWorkInt( index, CHAR_WORKMAXHP, CHAR_getWorkInt( index, CHAR_WORKMAXHP) + 50); + break; + case 2031: + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, CHAR_getWorkInt( index, CHAR_WORKFIXSTR) + 20); + break; + case 3031: + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH) + 20); + break; + case 4031: + CHAR_setWorkInt( index, CHAR_WORKMAXMP, CHAR_getInt( index, CHAR_MAXMP) + 20); + break; + default: + break; + } + } + } + }else +#endif + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPET){ +#ifdef _NO1_B2_NONO + if(CHAR_getPetSkill(index, 0) == 51){ + CHAR_setWorkInt( index, CHAR_WORKFIXAI, 21); + }else +#endif + { + int hostindex; + CHAR_setWorkInt( index, CHAR_WORKFIXAI, 0); + hostindex = CHAR_getWorkInt( index, CHAR_WORKPLAYERINDEX); + if( CHAR_CHECKINDEX( hostindex)) { + int ai; + int modai = CHAR_getInt( index, CHAR_MODAI); + double R; + + if( modai <= 0 ) modai = 100; + R = 1.10; + ai = ( (CHAR_getInt( hostindex, CHAR_LV) + * CHAR_getWorkInt( hostindex, CHAR_WORKFIXCHARM ) + * R) + / + (CHAR_getInt( index, CHAR_LV)* modai) * 100 ) ; + if( ai > 100 ) ai = 100; + + ai += CHAR_getInt( index, CHAR_VARIABLEAI) * 0.01; + if( CHAR_getInt( hostindex, CHAR_TRANSMIGRATION ) > 0 ){ + // shan 120 -> 140 + ai += ( CHAR_GetLevel() - CHAR_getInt( hostindex, CHAR_LV ) ) / 2; + } + if( ai < 0 ) ai = 0; + if( ai > 100 ) ai = 100; + CHAR_setWorkInt( index, CHAR_WORKFIXAI, ai); + } + } + } +} + +int _CHAR_complianceParameter( int index, char *FILE, int LINE) +{ + if( !CHAR_CHECKINDEX( index)) return 0; + + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER + && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEENEMY + && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPET +#ifdef _ALLBLUES_LUA + && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPELUANPC +#endif +#ifdef _PLAYER_NPC + && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYERNPC + && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYERPETNPC +#endif + ){ + return 0; + } + + CHAR_initcharWorkInt( index ); + ITEM_equipEffect( index ); + + CHAR_setWorkInt(index, CHAR_WORKATTACKPOWER, + CHAR_getWorkInt( index, CHAR_WORKFIXSTR ) ); + CHAR_setWorkInt(index, CHAR_WORKDEFENCEPOWER, + CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH ) ); + CHAR_setWorkInt(index, CHAR_WORKQUICK, + CHAR_getWorkInt( index, CHAR_WORKFIXDEX ) ); + +#ifdef _ITEMSET5_TXT + CHAR_setWorkInt(index, CHAR_WORKARRANGEPOWER, + CHAR_getWorkInt( index, CHAR_WORKFIXARRANGE ) ); + CHAR_setWorkInt(index, CHAR_WORKSEQUENCEPOWER, + CHAR_getWorkInt( index, CHAR_WORKFIXSEQUENCE ) ); +#endif + + Other_DefcharWorkInt( index); +#ifdef _ALLBLUES_LUA_1_9 + FreeComplianceParameter(index); +#endif + CHAR_setInt( index, CHAR_HP, min( CHAR_getInt(index,CHAR_HP), CHAR_getWorkInt( index, CHAR_WORKMAXHP))); + CHAR_setInt( index, CHAR_MP, min( CHAR_getInt(index,CHAR_MP), CHAR_getWorkInt( index, CHAR_WORKMAXMP))); + + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ +#ifdef _PETFOLLOW_NEW_ + int petnum; + petnum=0; + for(;petnum<5;petnum++){ + if( CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW+petnum ) != -1 ){ + int petindex = CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW +petnum); + if( !CHAR_CHECKINDEX( petindex) ){ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW+petnum, -1); + }else{ + if( CHAR_getInt( petindex, CHAR_WHICHTYPE) == CHAR_TYPEPET && + !CHAR_CHECKINDEX( CHAR_getWorkInt( petindex, CHAR_WORKPLAYERINDEX)) ){ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW+petnum, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, index); + } + } + } + } + +#else + + if( CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW ) != -1 ){ + int petindex = CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW ); + if( !CHAR_CHECKINDEX( petindex) ){ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW, -1); + }else{ + if( CHAR_getInt( petindex, CHAR_WHICHTYPE) == CHAR_TYPEPET && + !CHAR_CHECKINDEX( CHAR_getWorkInt( petindex, CHAR_WORKPLAYERINDEX)) ){ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, index); + } + } + } +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + { + int i, add_pile = 0; + int old_pile = CHAR_getWorkInt( index, CHAR_WORKATTACHPILE); + + for( i=0; i NowTime.tv_sec +#ifdef _NPCCHANGE_PLAYERIMG + || CHAR_getWorkInt( index, CHAR_WORKNPCMETAMO) > 0 +#endif +#ifdef _PETSKILL_BECOMEPIG + || CHAR_getInt( index, CHAR_BECOMEPIG) > -1 +#endif + ){ + newimagenumber = oldimagenumber; //ָԭͼ + } +#endif + // Arminius 8.9 airplane + if (oldimagenumber==100259) newimagenumber=100259; + if (oldimagenumber==100362) newimagenumber=100362; +#ifdef _VARY_WOLF + if( (CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPET) && + (CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) && + oldimagenumber == 101428 ){ + newimagenumber = 101428; + } +#endif +#ifdef _ENEMY_FALLGROUND + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEENEMY ) { + return 0; + }else { +#endif + if(CHAR_getInt(index, CHAR_RIDEPET) == -1){ + if( newimagenumber == -1 ){ + CHAR_setInt(index,CHAR_BASEIMAGENUMBER, basebaseimagenumber); + }else { + CHAR_setInt(index,CHAR_BASEIMAGENUMBER,newimagenumber); + } + } +#ifdef _ENEMY_FALLGROUND + } +#endif +#ifdef _NEW_RIDEPETS + if( (CHAR_getWorkInt(index, CHAR_WORKITEMMETAMO)>NowTime.tv_sec) + || (CHAR_getWorkInt(index,CHAR_WORKNPCMETAMO)>0)){ + return 0; + } +#endif + } + + return 1; +} + +/*====================================================================== + ƽҷ¼ʧ ةë + ======================================================================*/ + +/*====================έ====================*/ +/*------------------------------------------------------------ + * ϶ƥ ƽҷέìë Ϸ + * ¦ + * charaindex int ƽҷ̼͵ + * dir int + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_Look( int charaindex, int dir ) +{ + int fl ,x,y; + OBJECT object; + + /* ̼͵ */ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + + if( dir < 0 ) { + dir = CHAR_getInt(charaindex,CHAR_DIR); + } + VALIDATEDIR(dir); + if( CHAR_getInt( charaindex, CHAR_DIR) != dir ) { + CHAR_setInt(charaindex,CHAR_DIR,dir); + /* ʧë˪ */ + CHAR_sendWatchEvent(CHAR_getWorkInt(charaindex,CHAR_WORKOBJINDEX), + CHAR_ACTTURN,NULL,0,TRUE); + } + + fl = CHAR_getInt(charaindex,CHAR_FLOOR); +#if _ATTESTAION_ID == 1 + + int i; + for(i=1; i <=2; i ++) + { + CHAR_getCoordinationDir( CHAR_getInt(charaindex,CHAR_DIR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + i, &x, &y ); + //CHAR_talkToCli( charaindex, -1, "ܻ", CHAR_COLORWHITE ); + for( object=MAP_getTopObj(fl,x,y) ; object ; + object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + if( CHAR_getInt( OBJECT_getIndex(objindex), CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + || CHAR_getInt( OBJECT_getIndex(objindex), CHAR_WHICHTYPE) == CHAR_TYPEPET )continue; + typedef void (*LOOKF)(int,int); + LOOKF lf; + lf = (LOOKF)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex),CHAR_LOOKEDFUNC); + if( lf ){ + lf(OBJECT_getIndex(objindex),charaindex); + }else{ + + { + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer(OBJECT_getIndex(objindex), CHAR_TALKEDFUNC); + if( talkedfunc ) { + talkedfunc(OBJECT_getIndex(objindex),charaindex,"hi", 1, -1); + } +#ifdef _ALLBLUES_LUA + else{ + RunCharTalkedEvent(OBJECT_getIndex(objindex),charaindex,"hi",1, -1); + } +#endif + return; + } + } + } + } + } +#else + CHAR_getCoordinationDir( CHAR_getInt(charaindex,CHAR_DIR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + 1, &x, &y ); + + //CHAR_talkToCli( charaindex, -1, "ܻ", CHAR_COLORWHITE ); + + for( object=MAP_getTopObj(fl,x,y) ; object ; + object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + typedef void (*LOOKF)(int,int); + LOOKF lf; + lf = (LOOKF)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex),CHAR_LOOKEDFUNC); + if( lf ){ + lf(OBJECT_getIndex(objindex),charaindex); + }else{ + + { + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer(OBJECT_getIndex(objindex), CHAR_TALKEDFUNC); + if( talkedfunc ) { + talkedfunc(OBJECT_getIndex(objindex),charaindex,"hi", 1, -1); + } +#ifdef _ALLBLUES_LUA + else{ + RunCharTalkedEvent(OBJECT_getIndex(objindex),charaindex,"hi",1, -1); + } +#endif + } + + } + } + } +#endif +} + +BOOL _CHAR_makeObjectCString( char *file, int line, int objindex,char* buf, int buflen ) +{ + char objindexbuf[64]; + if( CHECKOBJECT(objindex) == FALSE ){ + printf("%s:%d\n", file, line); + return FALSE; + } + + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_NOUSE: + return FALSE; + break; + case OBJTYPE_CHARA: + { + int charaindex = OBJECT_getIndex(objindex); + char escapename[256]; + char escapetitle[256]; + // shan add +1 + char tmp[128]; + int namecolor; +#ifdef _TRANS_6 +#ifdef _TRANS_7_SHOW + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE, CHAR_COLORBLUE2,CHAR_COLORGREEN2};//תɫ +#else + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE, CHAR_COLORBLUE2};//תɫ +#endif +#else + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE}; +#endif + int ridepet = BATTLE_getRidePet( charaindex ); + char petname[64] = ""; + char escapepetname[256]; + char showname[256] = ""; + char szFmPoint[32] = ""; + int petlevel = 0; + + if( !CHAR_getFlg(charaindex,CHAR_ISVISIBLE) )return FALSE; + namecolor = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION); +#ifdef _TRANS_6 +#ifdef _TRANS_7_SHOW + if( namecolor > 7 ) namecolor = 7; +#else + if( namecolor > 6 ) namecolor = 6; +#endif +#else + if( namecolor > 5 ) namecolor = 5; +#endif + if( namecolor < 0 ) namecolor = 0; + + // shan add begin +#ifdef _NEW_NAME //Զƺ + char* szNewName = CHAR_getChar( charaindex, CHAR_NEWNAME); +#endif + +#ifdef _SHOW_VIP_CF + char VipName[32]=""; + if(getShowVip()!=0) + if(CHAR_getInt( charaindex,CHAR_VIPRIDE )>0) + sprintf(VipName, "VIP-"); +#endif + if( (CHAR_getWorkInt(charaindex, CHAR_WORKFMINDEXI) >= 0 + && CHAR_getWorkInt(charaindex, CHAR_WORKFMINDEXI) < FAMILY_MAXNUM + && CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + && CHAR_getWorkInt(charaindex, CHAR_WORKFMSETUPFLAG)==1) +#ifdef _PLAYER_NPC + ||CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYERNPC +#endif + ) +#ifdef _SHOW_VIP_CF + if(getShowVip()==1) + sprintf(tmp, "%s%s",VipName,CHAR_getChar( charaindex, CHAR_FMNAME)); + else +#endif + sprintf(tmp, "%s",CHAR_getChar( charaindex, CHAR_FMNAME)); + else + strcpy(tmp, ""); +#ifdef _SHOW_VIP_CF + char Name[64]; + if(getShowVip()==2) + sprintf(Name, "%s%s",VipName, makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); + else + sprintf(Name, "%s", makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); +#endif +#ifdef _NEW_NAME + char szNewTemp[128]; + if(strlen(szNewName) > 0){ + sprintf( szNewTemp, "%s%s", szNewName, Name) ; + }else{ + sprintf( szNewTemp, "%s", Name); + } +#endif +#ifdef _SHOW_FMPOINT + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + if(CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE + && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY ){ + switch( CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) ){ + case 1041: + sprintf( szFmPoint, "ׯ"); + break; + case 2031: + sprintf( szFmPoint, "ׯ"); + break; + case 3031: + sprintf( szFmPoint, "ڼׯ"); + break; + case 4031: + sprintf( szFmPoint, "ڿׯ"); + break; + case 5031: + sprintf( szFmPoint, "ׯ"); + break; + case 6031: + sprintf( szFmPoint, "ڵׯ"); + break; + case 7031: + sprintf( szFmPoint, "ˮׯ"); + break; + case 8031: + sprintf( szFmPoint, "ڻׯ"); + break; + case 9031: + sprintf( szFmPoint, "ڷׯ"); + break; + case 10031: + sprintf( szFmPoint, "ڱׯ"); + break; + default: + break; + } + } + } + strcat(showname, szFmPoint); +#endif + strcat(showname, makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); + // Robin 0730 + if( ridepet >= 0 ){ + if( ! strcmp( CHAR_getChar( ridepet, CHAR_USERPETNAME), "") ) + strcpy( petname, CHAR_getChar( ridepet, CHAR_NAME )); + else + strcpy( petname, CHAR_getChar( ridepet, CHAR_USERPETNAME )); + petlevel = CHAR_getInt( ridepet, CHAR_LV); + } + + int whichtype = CHAR_getInt( charaindex, CHAR_WHICHTYPE); +#ifdef _PLAYER_NPC + if(whichtype == CHAR_TYPEPLAYERNPC){ + whichtype = CHAR_TYPEPLAYER; + }else{ + + } +#endif + +//#ifdef _VERSION_25 + if(whichtype != CHAR_TYPEPLAYER + && whichtype != CHAR_TYPEBUS + && whichtype != CHAR_TYPEPET + ){ + whichtype = CHAR_TYPEDENGON; + } +//#endif + + + +#ifdef _OBJSEND_C +#ifdef _VERSION_NEW + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d|%d", +#else + #ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d|%d", + #else + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d", + #endif + #else + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d", + #endif +#endif + OBJTYPE_CHARA, +#else + snprintf( buf, buflen, "%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d", +#endif + whichtype, + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), + OBJECT_getY(objindex), + CHAR_getInt( charaindex, CHAR_DIR), + CHAR_getInt( charaindex,CHAR_BASEIMAGENUMBER ), + CHAR_getInt( charaindex,CHAR_LV ), + namecolortbl[namecolor], + showname, + makeEscapeString(CHAR_getChar(charaindex,CHAR_OWNTITLE), escapetitle,sizeof(escapetitle)), + CHAR_getFlg( charaindex,CHAR_ISOVERED ), + CHAR_getFlg( charaindex,CHAR_HAVEHEIGHT ), + CHAR_getInt( charaindex, CHAR_POPUPNAMECOLOR), + tmp, + makeEscapeString( petname, escapepetname, sizeof(escapepetname)), + petlevel +#ifdef _VERSION_NEW +#ifdef _PLAYER_TITLE + ,0 + ,CHAR_getInt( charaindex, CHAR_TITLE_LV) + ,0 + ,CHAR_getInt( charaindex, CHAR_TITLE_LV) +#else + ,0,0,0,0 +#endif + + +#else +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + ,CHAR_getInt( charaindex, PROFESSION_CLASS) // ְҵ + ,CHAR_getInt( charaindex, PROFESSION_LEVEL) // ְҵȼ +// ,CHAR_getInt( charaindex, PROFESSION_EXP) // ְҵֵ + ,CHAR_getInt( charaindex, PROFESSION_SKILL_POINT) // ܵ +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + ,CHAR_getInt( charaindex, CHAR_HEROFLOOR ) // Ӣս¥ +#endif +#endif +#endif + +#ifdef _PETSKILL_BECOMEPIG + // ,CHAR_getInt(charaindex, CHAR_BECOMEPIG) +#endif + + ); + //print("\nC name=%s type=%d",showname,CHAR_getInt( charaindex, CHAR_WHICHTYPE)); + break; + } + case OBJTYPE_ITEM: + { + int itemindex = OBJECT_getIndex(objindex); + int nameint; + int leaklevel; + int color; + char bufbuf[256]; + leaklevel = ITEM_getInt( itemindex,ITEM_LEAKLEVEL ); + + nameint = ITEM_SECRETNAME; +// if( leaklevel >=1 ) { +// nameint = ITEM_SECRETNAME; +// }else { +// nameint = ITEM_NAME; +// } + color = CHAR_COLORWHITE; +#ifndef _PET_AND_ITEM_UP + char *temp; + if (ITEM_getChar( itemindex, ITEM_CDKEY) == "\0"){ + return FALSE; + break; + } + temp=ITEM_getChar( itemindex, ITEM_CDKEY); + if( temp && strlen( temp ) ) { + color = CHAR_COLORGREEN; + }else +#endif + if( ITEM_getInt( itemindex, ITEM_MERGEFLG) ) { + color = CHAR_COLORYELLOW; + } + +#ifdef _OBJSEND_C + snprintf( buf, buflen, "%d|%s|%d|%d|%d|%d|%s", + OBJTYPE_ITEM, +#else + snprintf( buf, buflen, "%s|%d|%d|%d|%d|%s", +#endif + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex), + ITEM_getInt( itemindex,ITEM_BASEIMAGENUMBER ), + color, + makeEscapeString( ITEM_getChar( itemindex,nameint), bufbuf, sizeof(bufbuf)) + ); + break; + } + case OBJTYPE_GOLD: +#ifdef _OBJSEND_C + snprintf( buf, buflen, "%d|%s|%d|%d|%d", + OBJTYPE_GOLD, +#else + snprintf( buf, buflen, "%s|%d|%d|%d", +#endif + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex),OBJECT_getY(objindex), + OBJECT_getIndex(objindex) ); + break; +#ifdef _OBJSEND_C +#endif + default: + return FALSE; + break; + } + return TRUE; +} + +#ifdef _NPC_EVENT_NOTICE +BOOL _CHAR_makeObjectCStringNew( char *file, int line, int objindex, int playerindex, char* buf, int buflen ) +{ + char objindexbuf[64]; + if( CHECKOBJECT(objindex) == FALSE ){ + printf("%s:%d\n", file, line); + return FALSE; + } + + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_NOUSE: + return FALSE; + break; + case OBJTYPE_CHARA: + { + int charaindex = OBJECT_getIndex(objindex); + char escapename[256]; + char escapetitle[256]; + // shan add +1 + char tmp[128]; + int namecolor; + +#ifdef _TRANS_6 +#ifdef _TRANS_7_SHOW + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE, CHAR_COLORBLUE2,CHAR_COLORGREEN2};//תɫ +#else + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE, CHAR_COLORBLUE2};//תɫ +#endif +#else + int namecolortbl[] = { CHAR_COLORWHITE, CHAR_COLORYELLOW, CHAR_COLORGREEN, + CHAR_COLORCYAN, CHAR_COLORRED, CHAR_COLORPURPLE}; +#endif + int ridepet = BATTLE_getRidePet( charaindex ); + char petname[64] = ""; + char escapepetname[256]; + char showname[256] = ""; + char szFmPoint[32] = ""; + int petlevel = 0; + + if( !CHAR_getFlg(charaindex,CHAR_ISVISIBLE) )return FALSE; + namecolor = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION); +#ifdef _TRANS_6 +#ifdef _TRANS_7_SHOW + if( namecolor > 7 ) namecolor = 7; +#else + if( namecolor > 6 ) namecolor = 6; +#endif +#else + if( namecolor > 5 ) namecolor = 5; +#endif + if( namecolor < 0 ) namecolor = 0; + + // shan add begin +#ifdef _NEW_NAME //Զƺ + char* szNewName = CHAR_getChar( charaindex, CHAR_NEWNAME); +#endif + +#ifdef _SHOW_VIP_CF + char VipName[32]=""; + if(getShowVip()!=0) + if(CHAR_getInt( charaindex,CHAR_VIPRIDE )>0) + sprintf(VipName, "VIP-"); +#endif + if( (CHAR_getWorkInt(charaindex, CHAR_WORKFMINDEXI) >= 0 + && CHAR_getWorkInt(charaindex, CHAR_WORKFMINDEXI) < FAMILY_MAXNUM + && CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + && CHAR_getWorkInt(charaindex, CHAR_WORKFMSETUPFLAG)==1) +#ifdef _PLAYER_NPC + ||CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYERNPC +#endif + ) +#ifdef _SHOW_VIP_CF + if(getShowVip()==1) + sprintf(tmp, "%s%s",VipName,CHAR_getChar( charaindex, CHAR_FMNAME)); + else +#endif + sprintf(tmp, "%s",CHAR_getChar( charaindex, CHAR_FMNAME)); + else + strcpy(tmp, ""); +#ifdef _SHOW_VIP_CF + char Name[64]; + if(getShowVip()==2) + sprintf(Name, "%s%s",VipName, makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); + else + sprintf(Name, "%s", makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); +#endif +#ifdef _NEW_NAME + char szNewTemp[128]; + if(strlen(szNewName) > 0){ + sprintf( szNewTemp, "%s%s", szNewName, Name) ; + }else{ + sprintf( szNewTemp, "%s", Name); + } +#endif +#ifdef _SHOW_FMPOINT + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + if(CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_NONE + && CHAR_getInt( charaindex, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY ){ + switch( CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR) ){ + case 1041: + sprintf( szFmPoint, "ׯ"); + break; + case 2031: + sprintf( szFmPoint, "ׯ"); + break; + case 3031: + sprintf( szFmPoint, "ڼׯ"); + break; + case 4031: + sprintf( szFmPoint, "ڿׯ"); + break; + case 5031: + sprintf( szFmPoint, "ׯ"); + break; + case 6031: + sprintf( szFmPoint, "ڵׯ"); + break; + case 7031: + sprintf( szFmPoint, "ˮׯ"); + break; + case 8031: + sprintf( szFmPoint, "ڻׯ"); + break; + case 9031: + sprintf( szFmPoint, "ڷׯ"); + break; + case 10031: + sprintf( szFmPoint, "ڱׯ"); + break; + default: + break; + } + } + } + strcat(showname, szFmPoint); +#endif + strcat(showname, makeEscapeString( CHAR_getChar( charaindex,CHAR_NAME ), escapename, sizeof(escapename))); + // Robin 0730 + if( ridepet >= 0 ){ + if( ! strcmp( CHAR_getChar( ridepet, CHAR_USERPETNAME), "") ) + strcpy( petname, CHAR_getChar( ridepet, CHAR_NAME )); + else + strcpy( petname, CHAR_getChar( ridepet, CHAR_USERPETNAME )); + petlevel = CHAR_getInt( ridepet, CHAR_LV); + } + + int whichtype = CHAR_getInt( charaindex, CHAR_WHICHTYPE); +#ifdef _NPC_EVENT_NOTICE + int noticeNo; + if (whichtype== CHAR_TYPEEVENT){ + noticeNo =getPlayerEventNoticeNo( charaindex, playerindex); + }else if(whichtype==CHAR_TYPELUANPC){ + noticeNo=CHAR_getWorkInt(charaindex,CHAR_WORK_NOTICE); + }else{ + noticeNo=0; + } +#endif +#ifdef _PLAYER_NPC + if(whichtype == CHAR_TYPEPLAYERNPC){ + whichtype = CHAR_TYPEPLAYER; + }else{ + + } +#endif + +//#ifdef _VERSION_25 + if(whichtype != CHAR_TYPEPLAYER + && whichtype != CHAR_TYPEBUS + && whichtype != CHAR_TYPEPET + ){ + whichtype = CHAR_TYPEDENGON; + } +//#endif + + +#ifdef _OBJSEND_C +#ifdef _VERSION_NEW +#ifdef _NPC_EVENT_NOTICE + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d|%d|%d" +#ifdef _CHAR_TITLE_STR_ + "|%d" +#endif + , +#else + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d|%d", +#endif +#else + #ifdef _CHAR_PROFESSION // WON ADD ְҵ + #ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d|%d", + #else + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d|%d|%d|%d", + #endif + #else + snprintf( buf, buflen, "%d|%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d", + #endif +#endif + OBJTYPE_CHARA, +#else + snprintf( buf, buflen, "%d|%s|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%d|%s|%s|%d", +#endif + whichtype, + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), + OBJECT_getY(objindex), + CHAR_getInt( charaindex, CHAR_DIR), + CHAR_getInt( charaindex,CHAR_BASEIMAGENUMBER ), + CHAR_getInt( charaindex,CHAR_LV ), + namecolortbl[namecolor], + showname, + makeEscapeString(CHAR_getChar(charaindex,CHAR_OWNTITLE), escapetitle,sizeof(escapetitle)), + CHAR_getFlg( charaindex,CHAR_ISOVERED ), + CHAR_getFlg( charaindex,CHAR_HAVEHEIGHT ), + CHAR_getInt( charaindex, CHAR_POPUPNAMECOLOR), + tmp, + makeEscapeString( petname, escapepetname, sizeof(escapepetname)), + petlevel +#ifdef _NPC_EVENT_NOTICE + ,noticeNo +#endif +#ifdef _VERSION_NEW +#ifdef _PLAYER_TITLE + ,0 + ,CHAR_getInt( charaindex, CHAR_TITLE_LV) + ,0 + ,CHAR_getInt( charaindex, CHAR_TITLE_LV) +#ifdef _CHAR_TITLE_STR_ + ,CHAR_getInt( charaindex, CHAR_TITLE_) +#endif +#else + ,0,0,0,0 +#endif + + +#else +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + ,CHAR_getInt( charaindex, PROFESSION_CLASS) // ְҵ + ,CHAR_getInt( charaindex, PROFESSION_LEVEL) // ְҵȼ +// ,CHAR_getInt( charaindex, PROFESSION_EXP) // ְҵֵ + ,CHAR_getInt( charaindex, PROFESSION_SKILL_POINT) // ܵ +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + ,CHAR_getInt( charaindex, CHAR_HEROFLOOR ) // Ӣս¥ +#endif +#endif +#endif + +#ifdef _PETSKILL_BECOMEPIG + // ,CHAR_getInt(charaindex, CHAR_BECOMEPIG) +#endif + + ); + break; + } + case OBJTYPE_ITEM: + { + int itemindex = OBJECT_getIndex(objindex); + int nameint; + int leaklevel; + int color; + char bufbuf[256]; + leaklevel = ITEM_getInt( itemindex,ITEM_LEAKLEVEL ); + + nameint = ITEM_SECRETNAME; +// if( leaklevel >=1 ) { +// nameint = ITEM_SECRETNAME; +// }else { +// nameint = ITEM_NAME; +// } + color = CHAR_COLORWHITE; +#ifndef _PET_AND_ITEM_UP + char *temp; + if (ITEM_getChar( itemindex, ITEM_CDKEY) == "\0"){ + return FALSE; + break; + } + temp=ITEM_getChar( itemindex, ITEM_CDKEY); + if( temp && strlen( temp ) ) { + color = CHAR_COLORGREEN; + }else +#endif + if( ITEM_getInt( itemindex, ITEM_MERGEFLG) ) { + color = CHAR_COLORYELLOW; + } + +#ifdef _OBJSEND_C + snprintf( buf, buflen, "%d|%s|%d|%d|%d|%d|%s", + OBJTYPE_ITEM, +#else + snprintf( buf, buflen, "%s|%d|%d|%d|%d|%s", +#endif + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex), + ITEM_getInt( itemindex,ITEM_BASEIMAGENUMBER ), + color, + makeEscapeString( ITEM_getChar( itemindex,nameint), bufbuf, sizeof(bufbuf)) + ); + break; + } + case OBJTYPE_GOLD: +#ifdef _OBJSEND_C + snprintf( buf, buflen, "%d|%s|%d|%d|%d", + OBJTYPE_GOLD, +#else + snprintf( buf, buflen, "%s|%d|%d|%d", +#endif + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex),OBJECT_getY(objindex), + OBJECT_getIndex(objindex) ); + break; +#ifdef _OBJSEND_C +#endif + default: + return FALSE; + break; + } + return TRUE; +} +#endif + +void CHAR_sendCSpecifiedObjindex( int fd, int index) +{ + char introduction[1024*4]; + if( CHECKOBJECTUSE( index ) +#ifdef _NPC_EVENT_NOTICE + && CHAR_makeObjectCStringNew( index, CONNECT_getCharaindex(fd),introduction, + sizeof(introduction) ) +#else + && CHAR_makeObjectCString( index, introduction, + sizeof(introduction) ) +#endif + ){ + + lssproto_C_send( fd,introduction ); + }else{ + char mesg[512]; + cnv10to62( index, mesg, sizeof( mesg)); + + lssproto_C_send( fd, mesg ); + } +} + +void CHAR_sendSpecifiedobjindexCToCharaindex(int charaindex,int objindex) +{ + int fd; + fd = getfdFromCharaIndex(charaindex); + if( fd == -1)return; + + CHAR_sendCSpecifiedObjindex(fd,objindex); +} + +void CHAR_sendCToArroundCharacter( int objindex ) +{ + char introduction[1024*4]; + int x,y,fl; + int i,j; +#ifndef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCString( objindex,introduction, sizeof(introduction) ) == FALSE ) return; +#endif + x = OBJECT_getX(objindex); + y = OBJECT_getY(objindex); + fl =OBJECT_getFloor(objindex); + + for( i = x - CHAR_DEFAULTSEESIZ/2 ; + i <= x +CHAR_DEFAULTSEESIZ/2 ; i ++ ){ + for( j = y - CHAR_DEFAULTSEESIZ/2; + j <= y + CHAR_DEFAULTSEESIZ/2; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj( fl, i,j); + object; + object = NEXT_OBJECT(object) ){ + int objindexwk = GET_OBJINDEX( object); + if( OBJECT_getType(objindexwk) == OBJTYPE_CHARA ){ + int index = OBJECT_getIndex(objindexwk); + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int fd= getfdFromCharaIndex( index); + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) continue; + if( fd == -1 )continue; +#ifdef _MASK_ENCOUNTER + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT ){ + if( getStayEncount( fd) ) continue; + }else{ + int oyaindex = CHAR_getWorkInt( index, CHAR_WORKPARTYINDEX1); + if( getStayEncount( getfdFromCharaIndex(oyaindex)) ) continue; + } +#endif +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_MIND, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( OBJECT_getIndex( objindex))){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_FAMILYBADGE, getFamilyBadge( OBJECT_getIndex( objindex) ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( objindex,CONNECT_getCharaindex(fd),introduction, sizeof(introduction) ) == FALSE ) return; +#endif + lssproto_C_send( fd,introduction ); + } + } + } + } + } +} + +void CHAR_sendCDArroundChar_Main( int fl, int x, int y, int objindex, BOOL mode ) +{ +#define CHAR_CDSEESIZ CHAR_DEFAULTSEESIZ + int i,j; + char cdmsg[64*2]; + cnv10to62( objindex,cdmsg, sizeof(cdmsg)); + for( i = x - CHAR_CDSEESIZ/2 ; i <= x +CHAR_CDSEESIZ/2 ; i ++ ){ + for( j = y - CHAR_CDSEESIZ/2; j <= y + CHAR_CDSEESIZ/2; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj( fl, i,j); object; + object = NEXT_OBJECT(object) ){ + + int objindexwk = GET_OBJINDEX( object); + if( OBJECT_getType(objindexwk) == OBJTYPE_CHARA ){ + int index = OBJECT_getIndex( objindexwk); + if( CHAR_CHECKINDEX( index ) == FALSE )continue; + if( CHAR_getInt( index,CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER) { + if( objindexwk != objindex ) { + int fd; + fd = getfdFromCharaIndex(index); + if( fd == -1 )continue; + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE ) + { + CONNECT_appendCDbuf( fd, cdmsg, strlen( cdmsg)); + CDflush( index); + } +#ifdef _PLAYER_EFFECT + if( CHAR_CHECKINDEX( objindexwk)) { + if( CHAR_getInt( objindexwk, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( objindexwk, CHAR_PLAYER_EFFECT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_MIND, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ) > 0 ){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#endif + + +#ifdef _FAMILYBADGE_ + if( CHAR_CHECKINDEX( OBJECT_getIndex( objindex))) { + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( OBJECT_getIndex( objindex) )){ + char cabuf[128]; + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_FAMILYBADGE, getFamilyBadge(OBJECT_getIndex( objindex)))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#endif + } + } + } + } + } + } +} + +void CHAR_sendCDArroundChar( int fl, int x, int y, int objindex ) +{ + CHAR_sendCDArroundChar_Main( fl,x,y,objindex,FALSE); +} + + +void CHAR_sendArroundCharaData( int charaindex ) +{ + int fd; + int i,j,x, y,fl; + char introduction[512*2]; + char c_msg[1024*4]; + int strpos = 0; + char cabuf[128*2]; + fd = getfdFromCharaIndex( charaindex ); + if( fd == -1 )return; + c_msg[0] = '\0'; + fl = CHAR_getInt( charaindex, CHAR_FLOOR); + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); +#ifdef _MASK_ENCOUNTER + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT ){ + if( getStayEncount( fd) ) return FALSE; + }else{ + int oyaindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + if( getStayEncount( getfdFromCharaIndex(oyaindex)) ) return FALSE; + } +#endif + for( i = x-CHAR_DEFAULTSEESIZ/2 ; i <= x+CHAR_DEFAULTSEESIZ/2 ; i++ ){ + for( j = y-CHAR_DEFAULTSEESIZ/2 ; j <= y+CHAR_DEFAULTSEESIZ/2 ; j ++ ) { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; object ; object = NEXT_OBJECT(object ) ){ + int introlen; + int objindex = GET_OBJINDEX(object); + int c_index = OBJECT_getIndex( objindex); + + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && + !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE) ){ + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ"); + endObjectOne(objindex); + } + continue; + } + + if( OBJECT_getType( objindex) == OBJTYPE_CHARA) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER +#ifdef _ALLBLUES_LUA + || CHAR_getInt( c_index, CHAR_WHICHTYPE ) >= CHAR_TYPELUANPC +#endif + ) + + { + /* έƽҷ»弰ئĸ CAë˪ */ + if( CHAR_getWorkInt( c_index, CHAR_WORKPARTYMODE )== CHAR_PARTY_LEADER ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTLEADER,1 )) { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + // Robin 0611 trade + /* ɫ */ + if( CHAR_getWorkInt( c_index, CHAR_WORKTRADEMODE ) != CHAR_TRADE_FREE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTTRADE,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + +#ifdef _ANGEL_SUMMON + if( CHAR_getWorkInt( c_index, CHAR_WORKANGELMODE ) == TRUE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTANGEL,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _PLAYER_EFFECT + //print("\nshan--->(batlmode)->%d", CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE )); + if(CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT) && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_MIND, CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT))){ + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + //print("\nshan---->(1)cabuf-->%s", cabuf); + } + } +#endif +#ifdef FAMILY_MANOR_ + //print("\nshan--->(batlmode)->%d", CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE )); + if(CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR) && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR))){ + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + //print("\nshan---->(1)cabuf-->%s", cabuf); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if(CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT) && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT))){ + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + } + } +#endif +#ifdef _NEW_UPDATETITLE + //print("\nshan--->(batlmode)->%d", CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE )); + if(CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT) && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT))){ + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + //print("\nshan---->(1)cabuf-->%s", cabuf); + } + } +#endif +#ifdef _FAMILYBADGE_ + //print("\nshan--->(batlmode)->%d", CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE )); + if(getFamilyBadge( OBJECT_getIndex( objindex)) && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_FAMILYBADGE,getFamilyBadge( OBJECT_getIndex( objindex)))){ + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + //print("\nshan---->(1)cabuf-->%s", cabuf); + } + } +#endif + +#ifdef _STREET_VENDOR + if(CHAR_getWorkInt(c_index,CHAR_WORKSTREETVENDOR) == 1 && + CHAR_getWorkInt(c_index,CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(CHAR_makeCAOPTString(objindex,cabuf,sizeof(cabuf), + CHAR_STREETVENDOR_OPEN,CHAR_getWorkChar(c_index,CHAR_STREETVENDOR_NAME))){ + CONNECT_appendCAbuf(fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _ITEM_CRACKER + if(CHAR_getWorkInt( c_index, CHAR_WORKITEM_CRACKER)&& + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ITEM_CRACKER, CHAR_getWorkInt( c_index, CHAR_WORKITEM_CRACKER))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen(cabuf)); + } + } +#endif + if( CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + if( CHAR_getWorkInt( c_index, CHAR_WORKBATTLEWATCH) == TRUE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTBATTLEWATCH, 1)) { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + } + }else { + int battleno = CHAR_getWorkInt( c_index, CHAR_WORKBATTLEINDEX); + int sideno = CHAR_getWorkInt( c_index, CHAR_WORKBATTLESIDE); + int helpno = FALSE; + if( BATTLE_CHECKINDEX( battleno ) == FALSE ){ + }else { + helpno = (BattleArray[ battleno].Side[ + CHAR_getWorkInt( c_index, CHAR_WORKBATTLESIDE)].flg & BSIDE_FLG_HELP_OK)?TRUE:FALSE; + } + if( CHAR_makeCAOPT3String( objindex, cabuf, sizeof( cabuf), CHAR_ACTBATTLE, + battleno,sideno,helpno)){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + + } + } + } + if( CHAR_getWorkInt( c_index, CHAR_WORKACTION ) != -1 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + + } + } + }else if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + if( CHAR_getWorkInt( c_index, CHAR_WORKACTION ) != -1 ){ + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } +#ifdef _ADD_ACTION + else { //npc + if( CHAR_CHECKINDEX( c_index) ) { + if( CHAR_getWorkInt( c_index, CHAR_WORKACTION ) > 0 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))) { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } +#endif + } + + if( c_index == charaindex) continue; +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( objindex,charaindex,introduction, sizeof( introduction))){ +#else + if( CHAR_makeObjectCString( objindex, introduction, sizeof( introduction))){ +#endif + introlen = strlen( introduction); + introduction[introlen] = ','; + introduction[introlen+1] = '\0'; + + if((introlen+strpos)>sizeof( c_msg))break; + + strcpysafe( &c_msg[strpos], sizeof( c_msg) - strpos, + introduction); + strpos += strlen( introduction); + } + } + } + } + + dchop( c_msg, "," ); + if( strlen( c_msg) == 0 ) return; + lssproto_C_send( fd, c_msg); +} + +BOOL _CHAR_warpToSpecificPoint( char *file, int line, int charaindex, int floor, int x, int y) +{ + int objindex; + int per; + clearStayEncount(getfdFromCharaIndex( charaindex)); + objindex = CHAR_getWorkInt(charaindex,CHAR_WORKOBJINDEX); + if( !MAP_IsValidCoordinate( floor, x, y )) { +// print( "error: invalid Coordinate fl[%d] x[%d] y[%d] %s:%d from %s:%d\n", +// floor, x, y, __FILE__, __LINE__, file, line); + return FALSE; + } +#ifdef _ROOKIE_ITEM + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_CheckUserItem( charaindex ); + } +#endif + CHAR_sendCDArroundChar_Main( OBJECT_getFloor(objindex), + OBJECT_getX(objindex), + OBJECT_getY(objindex), + objindex, TRUE ); + + CHAR_setInt( charaindex,CHAR_FLOOR,floor); + CHAR_setInt( charaindex,CHAR_X,x); + CHAR_setInt( charaindex,CHAR_Y,y); + { + int of,ox,oy; + of = OBJECT_setFloor(objindex,floor); + ox = OBJECT_setX(objindex,x); + oy = OBJECT_setY(objindex,y); + if( !MAP_objmove( objindex,of,ox,oy,floor,x,y ) ){ + fprint( "ERROR MAP_OBJMOVE objindex=%d\n",objindex ); + } + } + per = ENCOUNT_getEncountPercentMin( charaindex, floor,x,y); + if( per != -1 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN, per); + } + per = ENCOUNT_getEncountPercentMax( charaindex, floor,x,y); + if( per != -1 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX, per); + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_FIX, 0); +#endif + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + CAflush( charaindex ); + { + int i; + char* statuscat[]={"C","E",}; + for( i=0 ; i -1) && (CHAR_CHECKINDEX( petindex )) ) + CHAR_warpToSpecificPoint( petindex, floor, x, y ); + } +#else + int petindex = CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW ); + if( (petindex > -1) && (CHAR_CHECKINDEX( petindex )) ) + + CHAR_warpToSpecificPoint( petindex, floor, x, y ); +#endif + } +#ifdef _STATUS_WATERWORD //ˮ״̬ + if( MAP_getMapFloorType( floor) == 1 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKMAPFLOORTYPE, 1); + }else { + CHAR_setWorkInt( charaindex, CHAR_WORKMAPFLOORTYPE, 0); + } +#endif +#ifdef _MAP_TIME + // ĵͼЩŵĻ,趨 + if(floor >= 30017 && floor <= 30021){ + if(CHAR_getWorkInt(charaindex,CHAR_WORK_MAP_TIME) <= 0) CHAR_setWorkInt(charaindex,CHAR_WORK_MAP_TIME,60); + } + // ĵͼ + else CHAR_setWorkInt(charaindex,CHAR_WORK_MAP_TIME,0); +#endif + +#ifdef _ANGEL_SUMMON + if( CHAR_getWorkInt( charaindex, CHAR_WORKANGELMODE ) == TRUE ) { + CHAR_sendAngelMark( objindex, 1); + } +#endif + + }else if( OBJECT_getType( objindex) == OBJTYPE_CHARA ){ + MAP_sendArroundChar( charaindex ); + } +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( charaindex, CHAR_PLAYER_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"2|%d",CHAR_getWorkInt( charaindex, CHAR_PLAYER_EFFECT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(charaindex), msg); + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( charaindex, CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + char msg[256]; + sprintf(msg,"3|%d",CHAR_getWorkInt( charaindex, CHAR_PLAYER_EFFECT_MANOR )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(charaindex), msg); + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( charaindex, CHAR_TRUMP_EFFECT ) > 0 ){ + char msg[256]; + sprintf(msg,"5|%d",CHAR_getInt( charaindex, CHAR_TRUMP_EFFECT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(charaindex), msg); + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( charaindex, CHAR_TITLE_DEFAULT ) > 0 ){ + char msg[256]; + sprintf(msg,"4|%d",CHAR_getInt( charaindex, CHAR_TITLE_DEFAULT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(charaindex), msg); + } +#endif + +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( charaindex)){ + char msg[256]; + sprintf(msg,"1|%d",getFamilyBadge( charaindex)); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(charaindex), msg); + } +#endif + return TRUE; +} + +static void CHAR_walk_check( int charaindex ) +{ + if( strlen( CHAR_getWorkChar( charaindex ,CHAR_WORKWALKARRAY ) ) != 0 ){ + struct timeval old; + old.tv_sec = CHAR_getWorkInt(charaindex,CHAR_WORKWALKSTARTSEC); + old.tv_usec = CHAR_getWorkInt(charaindex,CHAR_WORKWALKSTARTMSEC); + +#ifdef _SYSTEM_SPEAD + if( time_diff_us(NowTime,old) >= getWalksendinterval() * 100.0 ) +#else + if( time_diff_us(NowTime,old) >= getWalksendinterval() * 1000.0 ) +#endif + { + CHAR_walkcall( charaindex ); + }else { + } + } +} + +static BOOL CHAR_callLoop( int charaindex ) +{ + unsigned int timediff_us; + struct timeval old; + int loopinterval,loopinterval1, iRet = FALSE; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + loopinterval = CHAR_getInt(charaindex,CHAR_LOOPINTERVAL); + loopinterval1 = CHAR_getInt(charaindex,CHAR_LOOPINTERVALAB); + + if( loopinterval <= 0 && loopinterval1 <= 0 ) return FALSE; + + old.tv_sec = CHAR_getWorkInt(charaindex,CHAR_WORKLOOPSTARTSEC); + old.tv_usec = CHAR_getWorkInt(charaindex,CHAR_WORKLOOPSTARTMSEC); + timediff_us = time_diff_us( NowTime , old ); + //if (CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) + // printf("loopinterval=%d loopinterval1=%d\n",loopinterval,loopinterval1); + if( timediff_us >= loopinterval * 1000.0 && loopinterval >0 ){ + int (*loopfunc)(int)=NULL; + loopfunc =(int(*)(int))CHAR_getFunctionPointer( charaindex, CHAR_LOOPFUNC); + if( loopfunc ){ + loopfunc(charaindex); + iRet = TRUE; + } +#ifdef _USER_CHARLOOPS + loopfunc =(int(*)(int))CHAR_getFunctionPointer( charaindex, CHAR_LOOPFUNCTEMP1); + if( loopfunc ){ + loopfunc(charaindex); + iRet = TRUE; + } +#endif + if( iRet == FALSE ){ + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 0); + } + if( CHAR_CHECKINDEX(charaindex) == FALSE ){ + return FALSE; + } + CHAR_setWorkInt(charaindex,CHAR_WORKLOOPSTARTSEC, NowTime.tv_sec); + CHAR_setWorkInt(charaindex,CHAR_WORKLOOPSTARTMSEC, NowTime.tv_usec); + } + + old.tv_sec = CHAR_getWorkInt(charaindex,CHAR_WORKLOOPSTARTSECAB); + old.tv_usec = CHAR_getWorkInt(charaindex,CHAR_WORKLOOPSTARTMSECAB); + timediff_us = time_diff_us( NowTime , old ); +#ifdef _ALLBLUES_LUA + if( timediff_us >= loopinterval1 * 1000.0 && loopinterval1 >0){ + if(!RunCharLoopEvent(charaindex)) iRet = FALSE; + else iRet = TRUE; + if( iRet == FALSE ){ + CHAR_setInt( charaindex, CHAR_LOOPINTERVALAB, 0); + } + if( CHAR_CHECKINDEX(charaindex) == TRUE ){ + CHAR_setWorkInt(charaindex,CHAR_WORKLOOPSTARTSECAB, NowTime.tv_sec); + CHAR_setWorkInt(charaindex,CHAR_WORKLOOPSTARTMSECAB, NowTime.tv_usec); + } + } +#endif + return iRet; +} + +int EnemyMoveNum = 20; +void CHAR_Loop( void ) +{ + int charnum=CHAR_getCharNum(); + int playernum = CHAR_getPlayerMaxNum(); + int petnum = CHAR_getPetMaxNum(); + static int charcnt = 0; + int i, movecnt=0; + if( charcnt == -1 ) { + charcnt = CHAR_getCharNum(); + } + + // õloop + for( i=0 ; i< playernum ; i++ ){ + if( CHAR_getCharUse(i) == FALSE )continue; + + CHAR_walk_check( i ); + + CHAR_callLoop( i ); +#ifdef _TEACHER_SYSTEM + // лõʦ + if(CHAR_getWorkInt(i,CHAR_WORK_GET_TEACHER_FAME) > 0){ + int iAddTFame = CHAR_getInt(i,CHAR_TEACHER_FAME) + CHAR_getWorkInt(i,CHAR_WORK_GET_TEACHER_FAME); + int iAddFame = CHAR_getInt(i,CHAR_FAME) + CHAR_getWorkInt(i,CHAR_WORK_GET_TEACHER_FAME); + + // ӵʦ(ʦֵ͸ֵһ) + if(iAddTFame > MAX_PERSONALFAME) iAddTFame = MAX_PERSONALFAME; + else if(iAddTFame < 0) iAddTFame = 0; + CHAR_setInt(i,CHAR_TEACHER_FAME,iAddTFame); + + // + if(iAddFame > MAX_PERSONALFAME) iAddFame = MAX_PERSONALFAME; + else if(iAddFame < 0) iAddFame = 0; + CHAR_setInt(i,CHAR_FAME,iAddFame); + + // Ϊ 0 + CHAR_setWorkInt(i,CHAR_WORK_GET_TEACHER_FAME,0); + // м,ϴacֶͬ + if(CHAR_getInt(i,CHAR_FMLEADERFLAG) > 0 && CHAR_getInt(i,CHAR_FMLEADERFLAG) != FMMEMBER_APPLY){ + char tmpbuf1[16]; + + sprintf(tmpbuf1,"%d",iAddFame); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(i,CHAR_FMNAME), + CHAR_getInt(i,CHAR_FMINDEX), + CHAR_getWorkInt(i,CHAR_WORKFMINDEXI), + FM_FIX_FMFEED, + "0", // ֻΪͬ,Ϊ0, + tmpbuf1, // ͬ + CHAR_getWorkInt(i,CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(getfdFromCharaIndex(i)) + ); + } + } +#endif + } + +#ifdef _CHAR_LOOP_TIME + // Objectõloop + struct timeval st, et; + gettimeofday( &st, NULL ); + while( charcnt++ ){ + gettimeofday( &et, NULL ); + if( getCharLoopTime() > 0 && time_diff_us(et,st) > getCharLoopTime() * 1000.0)break; + if( charcnt >= charnum )charcnt = playernum ; + if( CHAR_getCharUse(charcnt) == FALSE )continue; + CHAR_callLoop(charcnt); + } +#else + +#ifdef _FIX_CHAR_LOOP + static int petcnt = 0; + static int othercnt = 0; + for( i = 0, movecnt = 0; i < CHAR_getPetMaxNum() ; i++, petcnt++ ){ + if( petcnt >= petnum )petcnt = playernum ; + if( CHAR_getCharUse(petcnt) == FALSE )continue; + if( CHAR_callLoop(petcnt) == TRUE ){ + if( ++movecnt >= EnemyMoveNum )break; + }else{ + continue; + } + } + for( i = 0, movecnt = 0; i < CHAR_getOthersMaxNum() ; i++, othercnt++ ){ + if( othercnt >= charnum )othercnt = petnum ; + if( CHAR_getCharUse(othercnt) == FALSE )continue; + if( CHAR_callLoop(othercnt) == TRUE ){ + if( ++movecnt >= 50 )break; + }else{ + continue; + } + } +#else + // Objectõloop + for( i = 0, movecnt = 0 ; i < (petnum/2) ; i++, charcnt++ ){ + if( charcnt >= charnum )charcnt = playernum ; + if( CHAR_getCharUse(charcnt) == FALSE )continue; + if( CHAR_callLoop(charcnt) == TRUE ){ + if( ++movecnt >= EnemyMoveNum )break; + }else{ + continue; + } + +#ifdef _NPC_AUTO_MOVE + if( charcnt>=petnum ){ + unsigned int timediff_us; + struct timeval old; + + old.tv_sec = CHAR_getWorkInt(charcnt,CHAR_WORKLOOPSTARTSEC); + old.tv_usec = CHAR_getWorkInt(charcnt,CHAR_WORKLOOPSTARTMSEC); + timediff_us = time_diff_us( NowTime , old ); + + if( timediff_us >= CHAR_getInt(charcnt,CHAR_WALKINTERVAL) * 1000.0 ) { + int lx, ly, rx, ry, nx, ny; + int dir; + POINT start, end; + int npccreateindex = CHAR_getInt( charcnt,CHAR_NPCCREATEINDEX ); + + if( !NPC_CHECKCREATEINDEX(npccreateindex) )continue; + + lx = NPC_create[npccreateindex].intdata[NPC_AUTOMOVELEFTUPX]; + ly = NPC_create[npccreateindex].intdata[NPC_AUTOMOVELEFTUPY]; + rx = NPC_create[npccreateindex].intdata[NPC_AUTOMOVERIGHTDOWNX]; + ry = NPC_create[npccreateindex].intdata[NPC_AUTOMOVERIGHTDOWNY]; + + if(lx==0 || ly==0 || rx==0 || ry==0)continue; + + start.x = CHAR_getInt( charcnt, CHAR_X); + start.y = CHAR_getInt( charcnt, CHAR_Y); + + nx=min(max(lx, start.x + ((rand() % 10) -5)), rx); + ny=min(max(ly, start.y + ((rand() % 10) -5)), ry); + + end.x = nx; + end.y = ny; + + dir = NPC_Util_getDirFromTwoPoint( &start, &end); + + if( dir != - 1 ) { + CHAR_walk( charcnt, dir, 0); + } + CHAR_setWorkInt(charcnt,CHAR_WORKLOOPSTARTSEC, NowTime.tv_sec); + CHAR_setWorkInt(charcnt,CHAR_WORKLOOPSTARTMSEC, NowTime.tv_usec); + } + } +#endif + + } +#endif +#endif +} + +char* CHAR_appendNameAndTitle( int charaindex, char* src, char* buf, + int buflen ) +{ + if( buflen > 0 ){ + if( CHAR_CHECKINDEX(charaindex) == FALSE ) + snprintf( buf,buflen,"%s",src ); + else{ + int titleindex = CHAR_getInt(charaindex,CHAR_INDEXOFEQTITLE); + if( titleindex == -1 ) + snprintf( buf,buflen, "%s%s", + CHAR_getChar(charaindex,CHAR_NAME), src ); + else + snprintf( buf,buflen, "%s(%s)%s", + CHAR_getChar(charaindex,CHAR_NAME), + TITLE_makeTitleStatusString(charaindex, + titleindex), src ); + } + } + return buf; +} + +void CHAR_getCoordinationDir( int dir , int x, int y ,int c, + int *xout , int *yout ) +{ + *xout = x + CHAR_getDX(dir) * c; + *yout = y + CHAR_getDY(dir) * c; +} + +BOOL CHAR_createCharacter( int type, int floor, int x, int y,int dir, + int* charaindex, int* objindex, BOOL seemap ) +{ + Char ch; + Object ob; + if( !CHAR_getDefaultChar( &ch,type ) )return FALSE; + + ch.data[CHAR_FLOOR] = floor; + ch.data[CHAR_X] = x; + ch.data[CHAR_Y] = y; + ch.data[CHAR_DIR] = dir; + + *charaindex = CHAR_initCharOneArray( &ch ); + if( *charaindex == -1 )return FALSE; + + ob.type = OBJTYPE_CHARA; + ob.index = *charaindex; + ob.floor = floor; + ob.x = x; + ob.y = y; + + if( seemap && MAP_walkAble( *charaindex, floor,x,y ) == FALSE ){ + CHAR_endCharOneArray( *charaindex ); + return FALSE; + } + + *objindex = initObjectOne( &ob ); + if( *objindex == -1 ){ + CHAR_endCharOneArray(*charaindex); + return FALSE; + } + CHAR_setWorkInt( *charaindex,CHAR_WORKOBJINDEX,*objindex); + + /* ë浤 */ + + CHAR_sendWatchEvent( *objindex,CHAR_ACTSTAND,NULL,0,TRUE); + + return TRUE; +} + +void CHAR_ObjectDelete( int objindex ) +{ + CHAR_sendCDArroundChar( OBJECT_getFloor(objindex), + OBJECT_getX(objindex), + OBJECT_getY(objindex), + objindex ); +#ifdef _MAP_WARPPOINT + if( OBJECT_getType( objindex) == OBJTYPE_WARPPOINT ){ + print("Delete OBJTYPE_WARPPOINT endObjectOne( %d) [%d,%d,%d] \n ", objindex, + OBJECT_getFloor(objindex), OBJECT_getX(objindex), + OBJECT_getY(objindex) ); + } +#endif + endObjectOne(objindex); +} + +/*------------------------------------------------------------ + * ƽҷë£Ƥִ£ + * ͼ֧Իëئ׻ּ + * ¦ + * charaindex int ƽҷ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_CharaDelete( int charaindex ) +{ + /* Ƥë */ + CHAR_ObjectDelete( CHAR_getWorkInt( charaindex,CHAR_WORKOBJINDEX ) ); + /* ƽҷ¼ */ + CHAR_endCharOneArray( charaindex ); +} +/*------------------------------------------------------------ + * Ȼʸë + ------------------------------------------------------------*/ +void CHAR_CharaDeleteHavePet( int charaindex) +{ + int i; + int pindex; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + pindex = CHAR_getCharPet( charaindex, i); + if( CHAR_CHECKINDEX( pindex)) { + CHAR_endCharOneArray( pindex ); + } + } + for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { + pindex = CHAR_getCharPoolPet( charaindex, i); + if( CHAR_CHECKINDEX( pindex)) { + CHAR_endCharOneArray( pindex ); + } + } +} +/*------------------------------------------------------------ + * ئë £ + * mode int 0: б巴CA˪ئ + * 1: бCA˪ + ------------------------------------------------------------*/ +int CHAR_sendAction( int charaindex, int action, int mode) +{ + /* ˪ľ ʧCAë۽ Ƥ */ + static int table[] = { + CHAR_ACTATTACK,CHAR_ACTDAMAGE,CHAR_ACTDOWN,CHAR_ACTACTIONSTAND, + CHAR_ACTACTIONWALK,CHAR_ACTSIT,CHAR_ACTHAND,CHAR_ACTPLEASURE, + CHAR_ACTANGRY,CHAR_ACTSAD,CHAR_ACTGUARD, CHAR_ACTNOD, CHAR_ACTTHROW + }; + if( action < 0 || action >= arraysizeof( table)) return FALSE; + + /* Իʧë˪ */ + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + table[action], + NULL,0,mode); + + /* ʧ */ + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, table[action]); + + return TRUE; +} +/*------------------------------------------------------------ + * л ƥؤеë˪£ + ------------------------------------------------------------*/ +void CHAR_sendBattleEffect( int charaindex, int onoff) +{ + int opt[3]; +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( charaindex, CHAR_WORK_SHOWBATTLETIME) < (int)time(NULL) + || CHAR_getWorkInt( charaindex, CHAR_WORK_OFFLINE ) == 0) +#endif + { + if( onoff == 1) { + opt[0] = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX); + opt[1] = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE); + opt[2] = (BattleArray[CHAR_getWorkInt( charaindex, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( charaindex, + CHAR_WORKBATTLESIDE)].flg & BSIDE_FLG_HELP_OK) ? TRUE:FALSE; + } + else { + opt[0] = -1; + opt[1] = -1; + opt[2] = 0; + } + + CHAR_sendWatchEvent( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTBATTLE,opt,arraysizeof(opt),TRUE); + CHAR_setWorkInt( charaindex, CHAR_WORK_SHOWBATTLETIME, (int)time(NULL) + 2 ); + } +} + +/*------------------------------------------------------------ + * дѶϢ add code Shan 2001/06/30 + ------------------------------------------------------------*/ +void CHAR_sendTradeEffect( int charaindex, int onoff) +{ + int opt[1]; + + if( onoff == 1) { + opt[0] = 1; + } + else { + opt[0] = -1; + } + CHAR_sendWatchEvent( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTTRADE,opt,arraysizeof(opt),TRUE); +} + +#ifdef _ANGEL_SUMMON +void CHAR_sendAngelEffect( int charaindex, int onoff) +{ + int opt[1]; + + if( onoff == 1) { + opt[0] = 1; + } + else { + opt[0] = -1; + } + CHAR_sendWatchEvent( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ACTANGEL,opt,arraysizeof(opt),TRUE); +} +#endif + +#ifdef _MIND_ICON +void CHAR_sendMindEffect( int charaindex, int onoff) +{ + int opt[1]; + + if(onoff>0){ + opt[0] = onoff; + } + else{ + opt[0] = 0; + } + CHAR_sendWatchEvent( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_MIND, opt, arraysizeof(opt), FALSE); +} +#endif +#ifdef _ITEM_CRACKER +void CHAR_sendCrackerEffect( int charaindex, int onoff) +{ + int opt[1]; + opt[0] = onoff; + CHAR_sendWatchEvent( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + CHAR_ITEM_CRACKER, opt, arraysizeof(opt), FALSE); +} +#endif + +void CHAR_inputUserPetName( int index , int havepetindex, char* name ) +{ + int petindex; + //char category[3]; + char *mycdkey=NULL, *cdkey = NULL; + BOOL changenameflg = FALSE; + + if( !CHAR_CHECKINDEX( index ) ) return; + + petindex = CHAR_getCharPet( index, havepetindex); + if( !CHAR_CHECKINDEX( petindex)) return; + + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(index, -1, "ػ޷޸֣", CHAR_COLORYELLOW); + return; + } + + mycdkey = CHAR_getChar( index, CHAR_CDKEY); + cdkey = CHAR_getChar( petindex, CHAR_CDKEY); + if( cdkey == "\0" ) { + print( "can't get CDKEY\n"); + }else { + if( strlen( cdkey) == 0 || strcmp( cdkey, mycdkey) == 0 ) { + changenameflg = TRUE; + } + } + if( !changenameflg) { + CHAR_talkToCli( index, -1, "޷Ϊ", CHAR_COLORYELLOW ); + return; + } + + CHAR_setChar( petindex, CHAR_USERPETNAME ,name); + + if( strlen( name ) == 0 || + strcmp( CHAR_getChar( petindex, CHAR_NAME), name) == 0 ){ + CHAR_setChar( petindex, CHAR_CDKEY, ""); + }else { + CHAR_setChar( petindex, CHAR_CDKEY, mycdkey); + } + CHAR_send_K_StatusString( index, havepetindex, CHAR_K_STRING_USERPETNAME); +} + +static void CHAR_setLuck( int charaindex) +{ + LSTIME nowlstime; + LSTIME mylstime; + struct { + int prob; + int luck; + }lucktbl[] = { + { 60, 1 }, /* 40% */ + { 30, 2 }, /* 30% */ + { 10, 3 }, /* 20% */ + { 3, 4 }, /* 7% */ + { 0, 5 } /* 3% */ + }; + + if( !CHAR_CHECKINDEX( charaindex)) return; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return; + + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + RealTimeToLSTime( CHAR_getInt( charaindex, CHAR_LASTTIMESETLUCK), &mylstime); + + /* LSƥ ȻľCHAR_LUCKëޥ */ + if( nowlstime.day != mylstime.day || nowlstime.year != mylstime.year ) { + int i,r; + r = RAND( 0, 99); + for( i = 0; i < arraysizeof( lucktbl); i ++ ) { + if( r >= lucktbl[i].prob ) { + CHAR_setInt( charaindex, CHAR_LUCK, lucktbl[i].luck); + CHAR_setInt( charaindex, CHAR_LASTTIMESETLUCK, NowTime.tv_sec); + return; + } + } + } +} +void CHAR_JoinBattle_WindowResult( int charaindex, int select, char *data) +{ + int ret = FALSE; + int fd = getfdFromCharaIndex( charaindex); + +#if 1 // òսظս Robin + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) { + CHAR_talkToCli( charaindex, -1, " ظս! ", CHAR_COLORRED); + print("\n ķ!!ظս!:%s ", CHAR_getChar( charaindex, CHAR_CDKEY) ); + //lssproto_EN_send( fd, FALSE, 0 ); + return; + } +#endif + if( select != WINDOW_BUTTONTYPE_CANCEL && + CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ){ + while( 1 ) { + int selected; + int bcharaindex; + if( fd == -1 ) break; + selected = atoi( data)-1; + + if( !CHAR_CHECKINDEX( CONNECT_getBattlecharaindex(fd,selected))) { + break; + } + if( CHAR_getWorkInt( CONNECT_getBattlecharaindex(fd,selected), + CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + break; + } + if( BattleArray[ CHAR_getWorkInt( + CONNECT_getBattlecharaindex( fd,selected), + CHAR_WORKBATTLEINDEX)].type != BATTLE_TYPE_P_vs_E ){ + break; + } + bcharaindex = CONNECT_getBattlecharaindex( fd,selected); + if( !(BattleArray[CHAR_getWorkInt( bcharaindex, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( bcharaindex, + CHAR_WORKBATTLESIDE)].flg + & BSIDE_FLG_HELP_OK)){ + break; + } + if(NPC_Util_CharDistance( charaindex, + CONNECT_getBattlecharaindex( + fd,selected) )> 1){ + break; + } + if( BATTLE_RescueEntry( charaindex, + CONNECT_getBattlecharaindex(fd,selected) )){ + CHAR_talkToCli( charaindex, -1, "޷ս", + CHAR_COLORYELLOW); + }else { + ret = TRUE; + } + + break; + } + } + if( ret == FALSE ) { + if( fd != -1 ) { + lssproto_EN_send( fd, FALSE, 0 ); + } + } +} +void CHAR_JoinDuel_WindowResult( int charaindex, int select, char *data) +{ + int ret = FALSE; + int fd = getfdFromCharaIndex( charaindex); + /* ֵպ */ + if( select != WINDOW_BUTTONTYPE_CANCEL && + CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT ) + { + /* мƥպë */ + while( 1 ) { + int selected; + int enemyindex; + + if( fd == -1 ) break; + selected = atoi( data)-1; + /* ئindex */ + if( !CHAR_CHECKINDEX( CONNECT_getDuelcharaindex(fd,selected)) ) { + break; + } + /* */ + if( CHAR_getWorkInt( CONNECT_getDuelcharaindex(fd,selected), + CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) + { + break; + } + /* duelھ */ + if( !CHAR_getFlg( CONNECT_getDuelcharaindex(fd,selected), + CHAR_ISDUEL)) + { + break; + } + /* ڶ ¾(ūƥ ƻޱ ¿) */ + if(NPC_Util_CharDistance( charaindex, + CONNECT_getDuelcharaindex(fd,selected) ) + > 1) + { + break; + } + // 󡼰ƽҷ¼̼͵ + enemyindex = CONNECT_getDuelcharaindex( fd,selected); + // 컥ئչ޼» + // Ҽئëƥ + if( CHAR_getWorkInt( enemyindex, CHAR_WORKPARTYMODE ) + == CHAR_PARTY_CLIENT ) + { + enemyindex = CHAR_getWorkInt( enemyindex, CHAR_WORKPARTYINDEX1 ); + // ئ⾮ʻئ + if( enemyindex < 0 ) break; + } + /* 컥ƥئؤ */ + if( CHAR_getInt( enemyindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER + && CHAR_getInt( enemyindex, CHAR_WHICHTYPE) != CHAR_TYPENONE ){ + break; + } + + ret = BATTLE_CreateVsPlayer( charaindex, enemyindex ); + if( ret != 0 ){ + CHAR_talkToCli( charaindex, -1, + "ʧܣ", CHAR_COLORYELLOW); + ret = FALSE; + } + else { + ret = TRUE; + } + break; + } + } + if( ret == FALSE ) { + /* ˪ */ + if( fd != -1 ) { + lssproto_EN_send( fd, FALSE, 0 ); + } + } +} +void CHAR_SelectCard_WindowResult( int charaindex, int select, char *data) +{ + if( select != WINDOW_BUTTONTYPE_CANCEL ){ + while( 1 ) { + int selected; + int fd; + fd = getfdFromCharaIndex( charaindex); + if( fd == -1 ) break; + selected = atoi( data)-1; + + if( !CHAR_CHECKINDEX( + CONNECT_getTradecardcharaindex(fd,selected))) { + break; + } + if( CHAR_getWorkInt( CONNECT_getTradecardcharaindex(fd,selected), + CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + break; + } + if(!CHAR_getFlg( CONNECT_getTradecardcharaindex(fd,selected), + CHAR_ISTRADECARD)){ + break; + } + if( NPC_Util_CharDistance( charaindex, + CONNECT_getTradecardcharaindex + (fd,selected) ) > 1){ + break; + } + ADDRESSBOOK_addAddressBook( charaindex, + CONNECT_getTradecardcharaindex( + fd,selected)); + break; + } + } +} + +void CHAR_JoinParty_WindowResult( int charaindex , int select, char *data) +{ + int ret = FALSE; + int fd = getfdFromCharaIndex( charaindex); + /* ֵպ */ + if( select != WINDOW_BUTTONTYPE_CANCEL && + /* лɡ ū׬ƥ */ + CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) + { + /* мƥպë */ + while( 1 ) { + int parray; + int selected; + int toindex = -1; + if( fd == -1 ) break; + selected = atoi( data)-1; + + /* ئindex + * (ۢūƥ ƻޱ + * ئindexئµ 뻥ؤ) + */ + if( !CHAR_CHECKINDEX( + CONNECT_getJoinpartycharaindex(fd,selected))) { + break; + } + /* ʻ¦ȽԻ */ + if( CHAR_getWorkInt( CONNECT_getJoinpartycharaindex( + fd,selected), CHAR_WORKPARTYMODE) + == CHAR_PARTY_NONE ) + { + toindex = CONNECT_getJoinpartycharaindex( fd,selected ); + } + else { + toindex = CHAR_getPartyIndex( + CONNECT_getJoinpartycharaindex(fd,selected), 0); + if( !CHAR_CHECKINDEX( toindex) ) { + print( " %s:%d err\n", __FILE__, __LINE__); + break; + } + } + /* ڶ ¾(ūƥ ƻޱ ¿) */ + if( NPC_Util_CharDistance( charaindex, toindex ) > 1) { + break; + } + /* ֻ */ + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) + { + break; + } + /* ޸ƹ */ + if( !CHAR_getFlg( toindex, CHAR_ISPARTY)) { + break; + } + + /* ɡ ūѷ */ + parray = CHAR_getEmptyPartyArray( toindex) ; + if( parray == -1 ) break; + /* ɡ ū */ + CHAR_JoinParty_Main( charaindex, toindex); + ret = TRUE; + break; + } + } + if( ret == FALSE ) { + CHAR_talkToCli( charaindex, -1, "޷Ŷӡ", + CHAR_COLORYELLOW); + } + /* ˪ */ + if( fd != -1 ) { + lssproto_PR_send( fd, 1, ret); + } +} +void CHAR_JoinBattleWatch_WindowResult( int charaindex, int select, char *data) +{ + int ret = FALSE; + int fd = getfdFromCharaIndex( charaindex); + /* ֵպ */ + if( select != WINDOW_BUTTONTYPE_CANCEL ) { + /* мƥպë */ + while( 1 ) { + int selected; + if( fd == -1 ) break; + selected = atoi( data)-1; + + /* ئindex + * (ۢūƥ ƻޱ + * ئindexئµ 뻥ؤ) + */ + if( !CHAR_CHECKINDEX( CONNECT_getBattlecharaindex(fd,selected))) { + break; + } + /* */ + if( CHAR_getWorkInt( CONNECT_getBattlecharaindex(fd,selected), + CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE) + { + break; + } + /* ڶ ¾(ūƥ ƻޱ ¿) */ + if(NPC_Util_CharDistance( charaindex, + CONNECT_getBattlecharaindex( + fd,selected) ) + > 1) + { + break; + } + /* ޼ */ + if( BATTLE_WatchEntry( charaindex, + CONNECT_getBattlecharaindex(fd,selected) + )) + { + CHAR_talkToCli( charaindex, -1, "޷ս", + CHAR_COLORYELLOW); + } + else { + ret = TRUE; + } + + break; + } + } + if( ret == FALSE ) { + /* ˪ */ + if( fd != -1 ) { + lssproto_EN_send( fd, FALSE, 0 ); + } + } +} + +#ifdef _FM_MODIFY +extern void NPC_FmDengonWindowTalked( int index, int talker, int seqno, int select, char *data); +#endif + +void CHAR_processWindow(int charaindex, int seqno, int select, + int objindex, char* data ) +{ + if( CHECKOBJECTUSE(objindex)) { + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + typedef void (*WINDF)(int,int,int, int,char*); + WINDF windowtalkedfunc=NULL; + windowtalkedfunc = (WINDF)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex),CHAR_WINDOWTALKEDFUNC); + if( windowtalkedfunc ) { + windowtalkedfunc( OBJECT_getIndex(objindex), charaindex, + seqno, select, data); + } +#ifdef _ALLBLUES_LUA + else{ + RunCharWindowTalked( OBJECT_getIndex(objindex), charaindex, + seqno, select, data); + } +#endif + } + }else { + + if( seqno == CHAR_WINDOWTYPE_SELECTBATTLE) { + CHAR_JoinBattle_WindowResult( charaindex, select, data); + } + +#ifdef _LOCK_PET_ITEM + else if(seqno == CHAR_WINDOWTYPE_DROPITEM){ + if(select == WINDOW_BUTTONTYPE_OK){ + int itemindex = CHAR_getItemIndex( charaindex, CHAR_getWorkInt(charaindex,CHAR_WORK_LOCK_PET_ITEM)); + // print("item=%d itemindex=%d",CHAR_getWorkInt(charaindex,CHAR_WORK_LOCK_PET_ITEM),itemindex); + if( !ITEM_CHECKINDEX( itemindex)) return; + char dropitembuff[96]; + memset(dropitembuff,0,sizeof(dropitembuff)); + sprintf(dropitembuff,"[%s]Ʒʧ",ITEM_getChar(itemindex,ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, dropitembuff, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, CHAR_getWorkInt(charaindex,CHAR_WORK_LOCK_PET_ITEM)); + CHAR_setWorkInt(charaindex,CHAR_WORK_LOCK_PET_ITEM,0); + } + } +#endif + +#ifdef _RED_MEMOY_ + else if(seqno == CHAR_WINDOWTYPE_REDMEMOY){ + CHAR_RedMemoy_WindowResult(charaindex,data); + } +#endif + else if( seqno == CHAR_WINDOWTYPE_SELECTDUEL) { + CHAR_JoinDuel_WindowResult( charaindex, select, data); + }else if( seqno == CHAR_WINDOWTYPE_SELECTTRADECARD) { + CHAR_SelectCard_WindowResult( charaindex, select, data); + }else if( seqno == CHAR_WINDOWTYPE_SELECTPARTY) { + CHAR_JoinParty_WindowResult( charaindex, select, data); + }else if( seqno == CHAR_WINDOWTYPE_SELECTBATTLEWATCH) { + CHAR_JoinBattleWatch_WindowResult( charaindex, select, data); + }else if( seqno >= CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE1 && + seqno <= CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME_ATTENTION ){ + ITEM_useRenameItem_WindowResult( charaindex, seqno, select, data); + } +#ifdef _ITEM_PET_LOCKED + else if( seqno == CHAR_WINDOWTYPE_ITEM_PET_LOCKED ){ + saacproto_ItemPetLocked_send(getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data); + CHAR_talkToCli( charaindex, -1, "ȫУԺ...", CHAR_COLORYELLOW); + }else if( seqno == CHAR_WINDOWTYPE_ITEM_PET_LOCKED_PASSWD ){ + if(strlen(data)>=6){ + saacproto_ItemPetLockedPasswd_send(getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data); + CHAR_talkToCli( charaindex, -1, "ȫ޸УԺ...", CHAR_COLORYELLOW); + }else{ + char message[256]; + char buf[256]; + int fd = getfdFromCharaIndex( charaindex); + + sprintf( message, "λ룡\n"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED_PASSWD, + -1, + makeEscapeString( message, buf, sizeof(buf))); + } + } +#endif +#ifdef _ONLINE_COST + else if( seqno == CHAR_WINDOWTYPE_ONLINE_COST ){ + if(select == 1){ +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( charaindex, -1, "δ,һ!", CHAR_COLORRED ); + return; + } + saacproto_OnlineCost_send(osfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data, CHAR_getInt( charaindex, CHAR_FMINDEX), CHAR_getChar( charaindex, CHAR_FMNAME)); +#else + saacproto_OnlineCost_send(acfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data, CHAR_getInt( charaindex, CHAR_FMINDEX), CHAR_getChar( charaindex, CHAR_FMNAME)); +#endif +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + data, + 0, + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + CHAR_talkToCli( charaindex, -1, "ֵżУԺ...", CHAR_COLORYELLOW); + } + } +#endif +#ifdef _SQL_BUY_FUNC + else if( seqno == CHAR_WINDOWTYPE_ONLINE_BUY ){ + int i; + if(data[0]==0){ + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) )break; + } + if( i == CHAR_MAXPETHAVE ){ + CHAR_talkToCli( charaindex, -1, "ϳԤһλ", CHAR_COLORYELLOW ); + return; + } + }else if(data[0]==1){ + int emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + if( emptyitemindexinchara < 0 ){ + CHAR_talkToCli( charaindex, -1, "ƷԤһλ" , CHAR_COLORYELLOW); + return; + } + }else if(data[0]==2){ + ; + } +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( charaindex, -1, "δ,һ!", CHAR_COLORRED ); + return; + } + saacproto_OnlineBuy_send(osfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data); +#else + saacproto_OnlineBuy_send(acfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), data); +#endif + CHAR_talkToCli( charaindex, -1, "żУԺ...", CHAR_COLORYELLOW); + } +#endif +#ifdef _NULL_CHECK_ITEM + else if( seqno == CHAR_WINDOWTYPE_NULL_CHECK ){ + int value=atoi(data); + if(value<0){ + CHAR_talkToCli( charaindex, -1, "֧ƱֵС,ٷ,װл!", CHAR_COLORYELLOW ); + return; + } + + if(CHAR_getInt( charaindex , CHAR_AMPOINT)0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -value, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(֧Ʊ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } +#endif + + + sprintf(buf, "%d", value); + ITEM_setChar(itemindex, ITEM_ARGUMENT, buf); + + sprintf( buf, "֧Ʊ%8d.00ǩ: %s", value, CHAR_getChar(charaindex, CHAR_NAME)); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf); + CHAR_sendItemDataOne( charaindex, haveitemindex); + + sprintf( buf, "˽˻֧Ʊע%dֵ㣡", value); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + }else{ + CHAR_talkToCli( charaindex, -1, "ʧܣ벻Ҫ֧ƱʱƶϵƷ", CHAR_COLORYELLOW); + } + } + } +#endif +#ifdef _ITEM_UPLEVEL + else if( seqno == CHAR_WINDOWTYPE_ITEM_UPLEVEL ){ + if(select==WINDOW_BUTTONTYPE_YES){ + int haveitemindex; + int itemindex = CHAR_getWorkInt(charaindex, CHAR_WORKITEMINDEX); + int toitemindex = CHAR_getWorkInt(charaindex, CHAR_WORKTOITEMINDEX); + + if(itemindex<0 || toitemindex<0){ + CHAR_talkToCli( charaindex, -1, "ٸķСİţ", CHAR_COLORRED); + CHAR_setWorkInt(charaindex, CHAR_WORKITEMINDEX, -1); + CHAR_setWorkInt(charaindex, CHAR_WORKTOITEMINDEX, -1); + return; + } + + int fromindex=0,toindex=0; + for( haveitemindex = 0; haveitemindex < CheckCharMaxItem(charaindex); haveitemindex ++ ) { + if( itemindex == CHAR_getItemIndex( charaindex, haveitemindex )){ + fromindex=haveitemindex; + } + if( toitemindex == CHAR_getItemIndex( charaindex, haveitemindex )){ + toindex=haveitemindex; + } + } + if(fromindex > 0 && toindex > 0){ + int level = ITEM_getInt(toitemindex, ITEM_LEAKLEVEL); + int itemlevel = atoi(ITEM_getChar( itemindex, ITEM_ARGUMENT)); + char token[64]; + int jl = itemlevel - level; + if(jl < 0 || jl >= 8){ + CHAR_talkToCli( charaindex, -1, "װδﵽҪ", CHAR_COLORRED); + return; + } + + if(jl >= (rand() % 10)){ + ITEM_setInt( toitemindex, ITEM_LEAKLEVEL, level + 1 ); + CHAR_talkToCli( charaindex, -1, "ϲ㣡ɹװɹ+1", CHAR_COLORYELLOW); + }else{ + ITEM_setInt( toitemindex, ITEM_LEAKLEVEL, level - 1 ); + CHAR_talkToCli( charaindex, -1, "Բװʧˣٽ", CHAR_COLORRED); + } + if(ITEM_getInt( toitemindex, ITEM_LEAKLEVEL) > 0 ){ + sprintf(token, "%s [+%d]", ITEM_getChar(toitemindex, ITEM_NAME), ITEM_getInt(toitemindex, ITEM_LEAKLEVEL)); + }else if(ITEM_getInt( toitemindex, ITEM_LEAKLEVEL) < 0 ){ + sprintf(token, "%s [%d]", ITEM_getChar(toitemindex, ITEM_NAME), ITEM_getInt(toitemindex, ITEM_LEAKLEVEL)); + }else{ + sprintf(token, "%s", ITEM_getChar(toitemindex, ITEM_NAME)); + } + ITEM_setChar(toitemindex, ITEM_SECRETNAME, token); + ITEM_setInt( toitemindex, ITEM_COLOER, CHAR_COLORPURPLE ); + CHAR_sendItemDataOne( charaindex, toindex); + + CHAR_DelItem( charaindex, fromindex); + CHAR_setWorkInt(charaindex, CHAR_WORKITEMINDEX, -1); + CHAR_setWorkInt(charaindex, CHAR_WORKTOITEMINDEX, -1); + } + } + } +#endif + +#ifdef _LOTTERY_SYSTEM + else if( seqno == CHAR_WINDOWTYPE_LOTTERYBUY ){ + if(select==WINDOW_BUTTONTYPE_OK){ + CHAR_setChar(charaindex, CHAR_LOTTERY_VALUE, data); + CHAR_setInt(charaindex, CHAR_LOTTERY_DATE, time(NULL)); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -1, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(Ʊ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + CHAR_talkToCli( charaindex, -1, "㹺IJƱΪ", CHAR_COLORBLUE); + CHAR_talkToCli( charaindex, -1, data, CHAR_COLORBLUE); + + int i; + int playernum = CHAR_getPlayerMaxNum(); + char token[256]; + sprintf(token, " %s ͶעվһŲƱ", CHAR_getChar(charaindex, CHAR_NAME)); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, token, CHAR_COLORBLUE); + } + } + } + } +#endif + +#ifdef _NEW_STREET_VENDOR + else if( seqno == CHAR_WINDOWTYPE_STREET_VENDOR_TYPE ){ + if(select!=WINDOW_BUTTONTYPE_CANCEL){ + char szMessage[4]; + int lst = atoi(data)-1; + sprintf(szMessage,"O|"); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(charaindex),szMessage); + CHAR_setWorkInt(charaindex, CHAR_WORKSTREETVENDORTYPE, lst); + if(lst==STREET_VENDOR_GOLD){ + CHAR_talkToCli( charaindex, -1, "ʯҷʽ̯!", CHAR_COLORRED); + }else if(lst==STREET_VENDOR_FAME){ + CHAR_talkToCli( charaindex, -1, "ʽ̯!", CHAR_COLORRED); + } +#ifndef _VERSION_NEW + else if(lst==STREET_VENDOR_AMPOINT){ + CHAR_talkToCli( charaindex, -1, "Իַʽ̯!", CHAR_COLORRED); + } +#endif +/* +#ifdef _NEW_MANOR_LAW + else if(lst==STREET_VENDOR_MOMENTUM){ + CHAR_talkToCli( charaindex, -1, "Ʒʽ̯!", CHAR_COLORRED); + } +#endif + + else if(lst==STREET_VENDOR_DP){ + CHAR_talkToCli( charaindex, -1, "ԣģзʽ̯!", CHAR_COLORRED); +#ifdef _CAMEO_MONEY + }else if(lst==STREET_VENDOR_CAMEO){ + CHAR_talkToCli( charaindex, -1, "Ƿʽ̯!", CHAR_COLORRED); +#endif +} +*/ +#ifdef _ACTIVE_GAME + else if(lst==STREET_VENDOR_ACTIVE){ + CHAR_talkToCli( charaindex, -1, "ʽ̯!", CHAR_COLORRED); +#endif +#ifdef _STREET_VENDOR_MYSQL + }else if(lst==STREET_VENDOR_MYSQL){ + CHAR_talkToCli( charaindex, -1, "ҷʽ̯!", CHAR_COLORRED); +#endif + }else{ + CHAR_setWorkInt(charaindex, CHAR_WORKSTREETVENDORTYPE, 0); + CHAR_talkToCli( charaindex, -1, "ʯҷʽ̯!", CHAR_COLORRED); + } + } + } +#endif +#ifdef _PETSKILL_CANNEDFOOD + else if( seqno == ITEM_WINDOWTYPE_SELECTPETSKILL_SELECT ){ + ITEM_usePetSkillCanned_WindowResult( charaindex, seqno, select, data); + } +#endif + +#ifdef _BATTLE_PK_TYPE + else if( seqno == CHAR_WINDOWTYPE_BATTLEPKTYPE ){ + int type = atoi(data)-1; + CHAR_setWorkInt(charaindex, CHAR_WORK_BATTLEPKTYPE, type); + } +#endif + +#ifdef _FM_MODIFY + else if(seqno >= CHAR_WINDOWTYPE_FM_DENGON && seqno <= CHAR_WINDOWTYPE_FM_DPSELECT){ + NPC_FmDengonWindowTalked(0,charaindex,seqno,select,data); + } +#endif +#ifdef _ITEM_OVER_LAP + else if(seqno >= CHAR_WINDOWTYPE_ITEMOVERLAP){ + int fromitemindex = CHAR_getWorkInt(charaindex, CHAR_WORKITEMINDEX); + int toitemindex = CHAR_getWorkInt(charaindex, CHAR_WORKTOITEMINDEX); + int fromid=-1,toid=-1; + + if(ITEM_CHECKINDEX(fromitemindex) && ITEM_CHECKINDEX(toitemindex)){ + int i; + for( i = 0; i < CheckCharMaxItem(charaindex); i ++ ) { + if( fromitemindex == CHAR_getItemIndex( charaindex, i )){ + fromid=i; + } + if( toitemindex == CHAR_getItemIndex( charaindex, i )){ + toid=i; + } + } + } + if(fromid > -1 && toid > -1){ + ItemOverlapedFunction( charaindex, fromitemindex, fromid, toitemindex, toid ); + } + } +#endif + + } +} + +void CHAR_PartyUpdate( int charaindex, int senddata ){ + int i, ownerindex, mode, pindex, pno; + if( !CHAR_CHECKINDEX(charaindex) )return; + mode = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ); + if( mode == CHAR_PARTY_NONE )return; + if( mode == CHAR_PARTY_LEADER ){ + ownerindex = charaindex; + }else{ + ownerindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1 ); + } + if( !CHAR_CHECKINDEX(ownerindex) )return; + for( pno = 0; pno < getPartyNum(ownerindex); pno ++ ){ + pindex = CHAR_getWorkInt( ownerindex, CHAR_WORKPARTYINDEX1+pno ); + if( pindex == charaindex )break; + } + if( pno == getPartyNum(ownerindex) )return; + for( i = 0; i < getPartyNum(ownerindex); i ++ ){ + pindex = CHAR_getWorkInt( ownerindex, CHAR_WORKPARTYINDEX1+i ); + if( pindex == charaindex )continue; + if( pindex < 0 )continue; + CHAR_send_N_StatusString( pindex, pno, senddata ); + } +} + +static int CHAR_getObjectByPosition( int myobjindex, int fl, int x, int y, + int *objbuf, int objbuflen) +{ + int i,j; + int cnt = 0; + + for( i = x-CHAR_DEFAULTSEESIZ/2 ; i <= x+CHAR_DEFAULTSEESIZ/2 ; i++ ){ + for( j = y-CHAR_DEFAULTSEESIZ/2 ; j <= y+CHAR_DEFAULTSEESIZ/2 ; + j ++ ) + { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType( objindex) == OBJTYPE_CHARA && + !CHAR_getFlg( OBJECT_getIndex( objindex), CHAR_ISVISIBLE)) + { + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ"); + endObjectOne(objindex); + } + continue; + } + /* зз */ + if( objindex == myobjindex) continue; + + objbuf[cnt] = objindex; + cnt ++; + if( cnt >= objbuflen) return cnt; + } + } + } + return cnt; +} +static void CHAR_setMyPosition_sendData( int charaindex,int prev_x, int prev_y, int x, int y) +{ + int CurrentObjCollection[CHAR_DEFAULTSEESIZ*CHAR_DEFAULTSEESIZ*10]; + int PrevObjCollection[CHAR_DEFAULTSEESIZ*CHAR_DEFAULTSEESIZ*10]; + int curcnt,prevcnt; + int objindex; + int fl; + char introduction[512]; + char c_msg[1024*4]; + char buf[64]; + int strpos; + int fd; + int i,j; + char cabuf[128]; + char myintroduction[1024*4]; + char cd_msg[128]; + + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + if( fd == -1 )return; + + objindex = CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX); + fl = CHAR_getInt( charaindex, CHAR_FLOOR); + + curcnt = CHAR_getObjectByPosition( objindex, fl,x,y, CurrentObjCollection, sizeof(CurrentObjCollection)); + prevcnt = CHAR_getObjectByPosition( objindex, fl, prev_x, prev_y, PrevObjCollection, sizeof(PrevObjCollection)); + strpos = 0; + c_msg[0] = '\0'; +#ifdef _NPC_EVENT_NOTICE + if( !CHAR_makeObjectCStringNew( objindex,CONNECT_getCharaindex(fd), myintroduction,sizeof( myintroduction))){ +#else + if( !CHAR_makeObjectCString( objindex, myintroduction,sizeof( myintroduction))){ +#endif + myintroduction[0] = '\0'; + } + + for( i = 0 ; i < curcnt; i ++ ) { + int findflg = FALSE; + for( j = 0; j < prevcnt; j ++ ) { + if( CurrentObjCollection[i] == PrevObjCollection[j] ) { + findflg = TRUE; + break; + } + } + if( !findflg ) { + int introlen; + int c_index = OBJECT_getIndex( CurrentObjCollection[i]); +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( CurrentObjCollection[i],c_index, introduction,sizeof( introduction))) +#else + if( CHAR_makeObjectCString( CurrentObjCollection[i], introduction,sizeof( introduction))) +#endif + { + introlen = strlen( introduction); + introduction[introlen] = ','; + introduction[introlen+1] = '\0'; + + if((introlen+strpos)>sizeof( c_msg))break; + + strcpysafe( &c_msg[strpos], sizeof( c_msg) - strpos, + introduction); + strpos += strlen( introduction); + } + if( strlen( myintroduction) != 0 ) { + if( OBJECT_getType( CurrentObjCollection[i] ) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + int tofd = getfdFromCharaIndex( c_index ); + if( tofd != -1 ){ + CDsend( tofd); + lssproto_C_send( tofd, myintroduction); + } + } + } + } + if( OBJECT_getType( CurrentObjCollection[i]) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKPARTYMODE ) + == CHAR_PARTY_LEADER ){ + if( CHAR_makeCAOPT1String( CurrentObjCollection[i], cabuf, sizeof( cabuf), + CHAR_ACTLEADER,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + + // Robin 0611 trade + /* ɫ */ + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKTRADEMODE ) != CHAR_TRADE_FREE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTTRADE,1 )) + { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + +#ifdef _ANGEL_SUMMON + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKANGELMODE ) == TRUE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTANGEL,1 )) + { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT)) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_MIND, CHAR_getWorkInt( c_index, CHAR_MIND_NUM))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + //print("\nshan---->(2)cabuf-->%s", cabuf); + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR)) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + //print("\nshan---->(2)cabuf-->%s", cabuf); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT)) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + //print("\nshan---->(2)cabuf-->%s", cabuf); + } + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT)) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + //print("\nshan---->(2)cabuf-->%s", cabuf); + } + } +#endif + + +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + getFamilyBadge(OBJECT_getIndex( objindex))) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_FAMILYBADGE, getFamilyBadge(OBJECT_getIndex( objindex)))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + //print("\nshan---->(2)cabuf-->%s", cabuf); + } + } +#endif +#ifdef _STREET_VENDOR + if(CHAR_getWorkInt(c_index,CHAR_WORKSTREETVENDOR) == 1 && + CHAR_getWorkInt(c_index,CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(CHAR_makeCAOPTString(objindex,cabuf,sizeof(cabuf), + CHAR_STREETVENDOR_OPEN,CHAR_getWorkChar(c_index,CHAR_STREETVENDOR_NAME))) + CONNECT_appendCAbuf(fd,cabuf,strlen(cabuf)); + } +#endif +#ifdef _ITEM_CRACKER + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getWorkInt( c_index, CHAR_WORKITEM_CRACKER)) + { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ITEM_CRACKER, CHAR_getWorkInt( c_index, CHAR_WORKITEM_CRACKER))) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + } + } +#endif + /* лƥ컥 ƥئئĸ CAë˪ */ + + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) + == CHAR_PARTY_LEADER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE) + { + int tofd = getfdFromCharaIndex( c_index ); + if( tofd != -1 ) { + if( CHAR_makeCAOPT1String( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + cabuf, sizeof( cabuf), + CHAR_ACTLEADER,1 )) + { + CONNECT_appendCAbuf( tofd,cabuf,strlen(cabuf)); + } + } + } + /* έƽҷ» ئվ ʧ ë˪ */ +#ifdef _ALLBLUES_LUA + if( (CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + || CHAR_getInt( c_index, CHAR_WHICHTYPE ) >= CHAR_TYPELUANPC) + && CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE )!= BATTLE_CHARMODE_NONE ) +#else + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) + != BATTLE_CHARMODE_NONE ) +#endif + { + /* CA */ + if( CHAR_getWorkInt( c_index, CHAR_WORKBATTLEWATCH) == TRUE ) { + if( CHAR_makeCAOPT1String( CurrentObjCollection[i], cabuf, + sizeof( cabuf), + CHAR_ACTBATTLEWATCH, + 1)) + { + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + } + } + else { + int battleno = CHAR_getWorkInt( c_index, + CHAR_WORKBATTLEINDEX); + int sideno = CHAR_getWorkInt( c_index, + CHAR_WORKBATTLESIDE); + int helpno = (BattleArray[CHAR_getWorkInt( c_index, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( c_index, + CHAR_WORKBATTLESIDE)].flg & BSIDE_FLG_HELP_OK) ? TRUE:FALSE; + /* HelpNo = 1 */ + if( CHAR_makeCAOPT3String( CurrentObjCollection[i], cabuf, sizeof( cabuf), + CHAR_ACTBATTLE, + battleno,sideno,helpno + )) + { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + /* έƽҷ»Ͼʧëƻľ˪£ */ + if( ( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER || + CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) && + CHAR_getWorkInt( c_index, CHAR_WORKACTION ) != -1 ) + { + if( CHAR_makeCADefaultString( CurrentObjCollection[i], cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))) + { + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } + } + dchop( c_msg, "," ); + if( strlen( c_msg) != 0 ) { + lssproto_C_send( fd, c_msg); + } + + /* мCD */ + cnv10to62( objindex,cd_msg, sizeof(cd_msg)); + + for( i = 0 ; i < prevcnt; i ++ ) { + int findflg = FALSE; + /* 󡼰 Ƥƥػ ئ + * ƤئƤ + */ + for( j = 0; j < curcnt; j ++ ) { + if( PrevObjCollection[i] == CurrentObjCollection[j] ) { + findflg = TRUE; + break; + } + } + if( !findflg ) { + cnv10to62( PrevObjCollection[i], buf, sizeof( buf)); + CONNECT_appendCDbuf( fd, buf, strlen( buf)); + + /* ˪ */ + if( OBJECT_getType( PrevObjCollection[i]) == OBJTYPE_CHARA ) { + int tocharaindex = OBJECT_getIndex( PrevObjCollection[i]); + if( CHAR_getInt( tocharaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + int tofd = CHAR_getWorkInt( tocharaindex, CHAR_WORKFD); + if( tofd != -1 ) { + CONNECT_appendCDbuf( tofd, cd_msg, strlen( cd_msg)); + CDsend( tofd); + } + } + } + } + } + CDsend( fd); + +} +BOOL CHAR_setMyPosition( int index, int x, int y, BOOL CAFlg) +{ + return CHAR_setMyPosition_main( index,x,y,-1,CAFlg); +} + +BOOL CHAR_setMyPosition_main( int index, int x, int y, int setdir, BOOL CAFlg) +{ + int objindex; + int prev_x,prev_y; + int fl; + + prev_x = CHAR_getInt( index, CHAR_X); + prev_y = CHAR_getInt( index, CHAR_Y); + if( prev_x == x && prev_y == y ) { + return FALSE; + } + + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT) { + return FALSE; + } + + if( CHAR_getFlg( index, CHAR_ISWARP)) return FALSE; + + objindex = CHAR_getWorkInt(index,CHAR_WORKOBJINDEX); + fl = CHAR_getInt( index, CHAR_FLOOR); + + if( !MAP_IsValidCoordinate( fl, x, y )) { + +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CHAR_getWorkInt( index, CHAR_WORKFD ),charname,32); + CONNECT_getCdkey(CHAR_getWorkInt( index, CHAR_WORKFD ),cdkey,16); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,"CHAR_setMyPosition_main"); +#endif + CONNECT_setCloseRequest( CHAR_getWorkInt( index, CHAR_WORKFD), 1); + return FALSE; + } + + if( ABS( x - prev_x) > CHAR_DEFAULTSEESIZ/2 || + ABS( y - prev_y) > CHAR_DEFAULTSEESIZ/2 ) + { + CHAR_sendCDArroundChar( fl,prev_x,prev_y,objindex ); + } + + if( ABS( x - prev_x) <= 1 && ABS( y - prev_y ) <= 1){ + POINT start,end; + int dir; + start.x = CHAR_getInt( index, CHAR_X); + start.y = CHAR_getInt( index, CHAR_Y); + end.x = x; + end.y = y; + dir = NPC_Util_getDirFromTwoPoint( &start, &end); + if( dir != -1 ) { + CHAR_walk( index, dir, 0); + } + } + else { + CHAR_setInt( index, CHAR_X,x); + CHAR_setInt( index, CHAR_Y,y); + if( setdir >= 0 && setdir < 8) CHAR_setInt( index, CHAR_DIR, setdir); + { + int of,ox,oy; + of = OBJECT_setFloor(objindex,fl); + ox = OBJECT_setX(objindex,x); + oy = OBJECT_setY(objindex,y); + + if( !MAP_objmove( objindex,of,ox,oy,fl,x,y ) ){ + fprint( "ERROR MAP_OBJMOVE objindex=%d\n",objindex ); + return FALSE; + } + } + if( ABS( x - prev_x) > CHAR_DEFAULTSEESIZ/2 || + ABS( y - prev_y) > CHAR_DEFAULTSEESIZ/2 ) + { + CHAR_sendWatchEvent(objindex,CHAR_ACTWARP,NULL,0,FALSE); + } + else if( CAFlg == TRUE ) { + CHAR_sendWatchEvent(objindex,CHAR_ACTWARP,NULL,0,FALSE); + } + } + + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_LEADER ) { + if( ABS( x - prev_x) <= 1 && ABS( y - prev_y ) <= 1){ + int i; + int prevparty_x = prev_x; + int prevparty_y = prev_y; + for( i = 1; i < getPartyNum(index); i ++ ) { + int toindex = CHAR_getWorkInt( index, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + int client_x = prevparty_x; + int client_y = prevparty_y; + int dir; + POINT start, end; + + prevparty_x = CHAR_getInt( toindex, CHAR_X); + prevparty_y = CHAR_getInt( toindex, CHAR_Y); + start.x = prevparty_x; + start.y = prevparty_y; + + end.x = client_x; + end.y = client_y; + + dir = NPC_Util_getDirFromTwoPoint( &start, &end); + if( dir != - 1 ) { + CHAR_walk( toindex, dir, 0); + } + } + } + } + + else if( ABS( x - prev_x) > CHAR_DEFAULTSEESIZ/2 || + ABS( y - prev_y) > CHAR_DEFAULTSEESIZ/2 ) + { + int i; + for( i = 1; i < getPartyNum(index); i ++ ) { + int toindex = CHAR_getWorkInt( index, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + CHAR_warpToSpecificPoint( toindex,fl , x,y); + } + } + } + } + + if( ABS( x - prev_x) <= CHAR_DEFAULTSEESIZ/2 && + ABS( y - prev_y) <= CHAR_DEFAULTSEESIZ/2 ) + { + CHAR_setMyPosition_sendData( index, prev_x, prev_y, x, y); + } + + return TRUE; +} + + +static char CHAR_P_statusSendBuffer[STRINGBUFSIZ]; + + + +static char *CHAR_make_P_StatusString( int charaindex, unsigned int indextable ) +{ + int i,j; + int ret = 0; + int strlength; + char buf[64]; + struct { + unsigned int kind; + int intdataindex; + int gettype; + }chk[] = { + { CHAR_P_STRING_HP, CHAR_HP, 0 }, + { CHAR_P_STRING_MAXHP, CHAR_WORKMAXHP, 1 }, + { CHAR_P_STRING_MP, CHAR_MP, 0 }, + { CHAR_P_STRING_MAXMP, CHAR_WORKMAXMP, 1 }, + { CHAR_P_STRING_EXP, CHAR_EXP, 0 }, + { CHAR_P_STRING_LV, CHAR_LV, 0 }, + { CHAR_P_STRING_ATK, CHAR_WORKATTACKPOWER, 1 }, + { CHAR_P_STRING_DEF, CHAR_WORKDEFENCEPOWER, 1 }, + { CHAR_P_STRING_QUICK, CHAR_WORKQUICK, 1 }, + { CHAR_P_STRING_CHARM, CHAR_WORKFIXCHARM, 1 }, + { CHAR_P_STRING_LUCK, CHAR_WORKFIXLUCK, 1 }, + { CHAR_P_STRING_GOLD, CHAR_GOLD, 0 }, + { CHAR_P_STRING_TITLE, CHAR_INDEXOFEQTITLE, 0 }, + { CHAR_P_STRING_NAME, CHAR_NAME, 2 }, + { CHAR_P_STRING_OWNTITLE, CHAR_OWNTITLE, 2 }, + { CHAR_P_STRING_VITAL, CHAR_VITAL, 10 }, + { CHAR_P_STRING_STR, CHAR_STR, 10 }, + { CHAR_P_STRING_TOUGH, CHAR_TOUGH, 10 }, + { CHAR_P_STRING_DEX, CHAR_DEX, 10 }, + { CHAR_P_STRING_EARTH, CHAR_WORKFIXEARTHAT, 11 }, + { CHAR_P_STRING_WATER, CHAR_WORKFIXWATERAT, 11 }, + { CHAR_P_STRING_FIRE, CHAR_WORKFIXFIREAT, 11 }, + { CHAR_P_STRING_WIND, CHAR_WORKFIXWINDAT, 11 }, + { CHAR_P_STRING_DUELPOINT, CHAR_DUELPOINT, 0 }, + { CHAR_P_STRING_TRANSMIGRATION, CHAR_TRANSMIGRATION, 0}, + { CHAR_P_STRING_RIDEPET, CHAR_RIDEPET, 0}, + { CHAR_P_STRING_LEARNRIDE, CHAR_LEARNRIDE, 0}, + { CHAR_P_STRING_BASEBASEIMAGENUMBER, CHAR_BASEBASEIMAGENUMBER, 0}, + { CHAR_P_STRING_SKYWALKER, CHAR_WORKSKYWALKER, 1}, +#ifdef _CHARSIGNDAY_ + { CHAR_P_STRING_DEBUGMODE, CHAR_QIANDAORI, 3}, +#else + { CHAR_P_STRING_DEBUGMODE, CHAR_WORKDEBUGMODE, 1}, +#endif + }; + + snprintf( CHAR_P_statusSendBuffer, sizeof( CHAR_P_statusSendBuffer), + "P%s|", cnv10to62( indextable, buf,sizeof(buf))); + strlength = strlen( CHAR_P_statusSendBuffer ); + + for( i = 1; i < sizeof( int) * 8; i ++ ){ + if( indextable & (1 << i) ) { + char tmp[256]; + BOOL found = FALSE; + for( j = 0; j < arraysizeof( chk); j ++ ) { + if( chk[j].kind == 1 << i ) { + if( chk[j].gettype == 0 ) { + ret = CHAR_getInt( charaindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + }else if( chk[j].gettype == 1 ) { + ret = CHAR_getWorkInt( charaindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + }else if( chk[j].gettype == 10 ) { + ret = CHAR_getInt( charaindex, chk[j].intdataindex)/100; + snprintf( tmp, sizeof( tmp), "%d|", ret); + }else if( chk[j].gettype == 11 ) { + ret = CHAR_getWorkInt( charaindex, chk[j].intdataindex); + if( ret < 0) ret = 0; + snprintf( tmp, sizeof( tmp), "%d|", ret); + }else if( chk[j].gettype == 2 ) { + char escapebuffer[128]; + char *a = CHAR_getChar( charaindex, chk[j].intdataindex); + + snprintf( tmp,sizeof( tmp ), + "%s|", + makeEscapeString( a, escapebuffer, + sizeof(escapebuffer) + )); + } +#ifdef _CHARSIGNDAY_ + else if (chk[j].gettype == 3){ + int sdate; + sdate = CHAR_getInt( charaindex,chk[j].intdataindex); + int nowtime = time(NULL); + struct tm * time = localtime(&nowtime); + int date=time->tm_mday; + if( sdate != date) + ret = 0; + else + ret = 1; + snprintf( tmp, sizeof( tmp), "%d|", ret); + } +#endif + found = TRUE; + break; + } + } + if( !found) { + if( indextable & CHAR_P_STRING_NEXTEXP ) { + ret = CHAR_GetLevelExp( charaindex, CHAR_getInt( charaindex, CHAR_LV ) + 1); + snprintf( tmp, sizeof( tmp), "%d|", ret); + found = TRUE; + } + } + if( !found) { + print( "ҲָIJ[%d]\n",indextable); + }else { + strcpysafe( &CHAR_P_statusSendBuffer[ strlength], + sizeof( CHAR_P_statusSendBuffer) - strlength, + tmp); + + strlength += strlen( tmp ); + if( strlength >= sizeof( CHAR_P_statusSendBuffer ) ) { + return CHAR_P_statusSendBuffer; + } + } + } + } + return CHAR_P_statusSendBuffer; +} + +BOOL CHAR_send_P_StatusString( int charaindex, unsigned int indextable ) +{ + char* string; + //if( indextable >= ( CHAR_P_STRING_BASEBASEIMAGENUMBER << 1)) { + if( indextable > 0xA0000000) { + //if( indextable >= ( CHAR_P_STRING_DEBUGMODE << 1)) { + //print( "send_P invalid index[%d]\n", indextable); + return FALSE; + } + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ){ + return FALSE; + } + + string = CHAR_make_P_StatusString( charaindex, indextable ); + + if( string != NULL ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ){ + lssproto_S_send( fd, string ); + return TRUE; + } + } + return FALSE; +} + +static char CHAR_N_statusSendBuffer[STRINGBUFSIZ]; +/*------------------------------------------------------------ + * ͷʧ˪ ٯ ë£ + * ¦ + * charaindex int ƽҷ̼ + * indextable int P ë˪ɷ¶ + *------------------------------------------------------------*/ +static char *CHAR_make_N_StatusString( int charaindex, int num, unsigned int indextable ) +{ + int i,j; + int nindex = -1; + int ret = 0; + int strlength; + char buf[64]; + struct { + unsigned int kind; + int intdataindex; + int gettype; + }chk[] = { + { CHAR_N_STRING_OBJINDEX, CHAR_WORKOBJINDEX, 1 }, + { CHAR_N_STRING_LV, CHAR_LV, 0 }, + { CHAR_N_STRING_MAXHP, CHAR_WORKMAXHP, 1 }, + { CHAR_N_STRING_HP, CHAR_HP, 0 }, + { CHAR_N_STRING_MP, CHAR_MP, 0 }, + { CHAR_N_STRING_NAME, CHAR_NAME, 2 }, + + + }; + /* ޵ */ + /* */ + if( num < 0 || num >=getPartyNum(charaindex)){ + print( "1ģʽʧ %d %s\n", num, CHAR_getChar(charaindex,CHAR_NAME) ); + return "\0"; + } + /* ޼̼͵ë */ + nindex = CHAR_getPartyIndex( charaindex, num); + + if( nindex == -1 ){ + /* ֧ snprintf */ + snprintf( CHAR_N_statusSendBuffer,sizeof(CHAR_N_statusSendBuffer), + "N%d|0|", num ); + return CHAR_N_statusSendBuffer; + } + + snprintf( CHAR_N_statusSendBuffer, sizeof( CHAR_N_statusSendBuffer), + "N%d|%s|", num,cnv10to62( indextable, buf,sizeof(buf))); + strlength = strlen( CHAR_N_statusSendBuffer ); + + /* indextable ƥ Ȼë Ʃ */ + for( i = 1; i < sizeof( int) * 8; i ++ ){ + if( indextable & (1 << i) ) { + char tmp[256]; + BOOL found = FALSE; + /* Ȼchk¾Ʃ */ + for( j = 0; j < arraysizeof( chk); j ++ ) { + if( chk[j].kind == 1 << i ) { + /* ׼ƥë */ + /* Ѱ̼ */ + if( chk[j].gettype == 0 ) { + ret = CHAR_getInt( nindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 1 ) { + ret = CHAR_getWorkInt( nindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 10 ) { + ret = CHAR_getInt( nindex, chk[j].intdataindex)/100; + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 11 ) { + ret = CHAR_getWorkInt( nindex, chk[j].intdataindex); + if( ret < 0) ret = 0; + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + /* ٯ ̼ */ + else if( chk[j].gettype == 2 ) { + char escapebuffer[128]; + char *a = CHAR_getChar( nindex, chk[j].intdataindex); + + snprintf( tmp,sizeof( tmp ), + "%s|", + makeEscapeString( a, escapebuffer, + sizeof(escapebuffer) + )); + } + found = TRUE; + break; + } + } + /* ְ󼰷ľئ */ + if( !found) { + /* շ๴๴ */ + } + if( !found) { + print( "ҲָIJ[%d]\n",indextable); + } + else { + strcpysafe( &CHAR_N_statusSendBuffer[ strlength], + sizeof( CHAR_N_statusSendBuffer) - strlength, + tmp); + + strlength += strlen( tmp ); + if( strlength >= sizeof( CHAR_N_statusSendBuffer ) ) { + return CHAR_N_statusSendBuffer; + } + } + } + } + return CHAR_N_statusSendBuffer; +} +/*------------------------------------------------------------ + * S P ë˪£¼ƥƥئʻУ + * ¦ + * charaindex int ƽҷ̼ + * num int į + * indextable int P ë˪ɷ¶ + * ߯Ի + * ˪ףTRUE(1) + * ˪ľئףFALSE(0) + *------------------------------------------------------------*/ +BOOL CHAR_send_N_StatusString( int charaindex, int num, unsigned int indextable ) +{ + char* string; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + if( indextable >= (CHAR_N_STRING_NAME << 1)) { + print( "send_N invalid index[%d]\n", indextable); + return FALSE; + } + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ){ + return FALSE; + } + string = CHAR_make_N_StatusString( charaindex, num, indextable ); + if( string != NULL ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ){ + lssproto_S_send( fd, string ); + return TRUE; + } + } + return FALSE; +} + +static char CHAR_K_statusSendBuffer[STRINGBUFSIZ]; +static char *CHAR_make_K_StatusString( int charaindex, int num, unsigned int indextable ) +{ + int i,j; + int ret = 0; + int strlength; + int pindex; + char buf[64]; + struct { + unsigned int kind; + int intdataindex; + int gettype; + }chk[] = { + { CHAR_K_STRING_BASEIMAGENUMBER, CHAR_BASEIMAGENUMBER, 0 }, + { CHAR_K_STRING_HP, CHAR_HP, 0 }, + { CHAR_K_STRING_MAXHP, CHAR_WORKMAXHP, 1 }, + { CHAR_K_STRING_MP, CHAR_MP, 0 }, + { CHAR_K_STRING_MAXHP, CHAR_WORKMAXMP, 1 }, + { CHAR_K_STRING_EXP, CHAR_EXP, 0 }, + { CHAR_K_STRING_LV, CHAR_LV, 0 }, + { CHAR_K_STRING_ATK, CHAR_WORKATTACKPOWER, 1 }, + { CHAR_K_STRING_DEF, CHAR_WORKDEFENCEPOWER, 1 }, + { CHAR_K_STRING_QUICK, CHAR_WORKQUICK, 1 }, + { CHAR_K_STRING_AI, CHAR_WORKFIXAI, 1 }, + { CHAR_K_STRING_EARTH, CHAR_WORKFIXEARTHAT, 11}, + { CHAR_K_STRING_WATER, CHAR_WORKFIXWATERAT, 11}, + { CHAR_K_STRING_FIRE, CHAR_WORKFIXFIREAT, 11}, + { CHAR_K_STRING_WIND, CHAR_WORKFIXWINDAT, 11}, + { CHAR_K_STRING_SLOT, CHAR_SLOT, 0 }, + { CHAR_K_STRING_NAME, CHAR_NAME, 2 }, + { CHAR_K_STRING_USERPETNAME, CHAR_USERPETNAME, 2 }, +#ifdef _PETCOM_ + { CHAR_K_STRING_YHP, CHAR_YHP, 0 }, + { CHAR_K_STRING_YATK, CHAR_YATK, 0 }, + { CHAR_K_STRING_YDEF, CHAR_YDEF, 0 }, + { CHAR_K_STRING_YQUICK, CHAR_YQUICK, 0 }, + { CHAR_K_STRING_YLV, CHAR_YLV, 0 }, +#endif + }; + /* */ + if( num < 0 || num >= CHAR_MAXPETHAVE ){ + print( "ģʽʧ (%c)%d \n", num, num ); + return "\0"; + } + /* ʸ̼͵ë */ + pindex = CHAR_getCharPet( charaindex, num ); + if( pindex == -1 ){ + /* ֧ snprintf */ + snprintf(CHAR_K_statusSendBuffer,sizeof(CHAR_K_statusSendBuffer), + "K%d|0|", num ); + return CHAR_K_statusSendBuffer; + } + + snprintf( CHAR_K_statusSendBuffer, sizeof( CHAR_K_statusSendBuffer), + "K%d|%s|", num, cnv10to62( indextable, buf,sizeof(buf))); + strlength = strlen( CHAR_K_statusSendBuffer ); + + for( i = 1; i < sizeof( int) * 8; i ++ ){ + if( indextable & (1 << i) ) { + char tmp[256]; + BOOL found = FALSE; + for( j = 0; j < arraysizeof( chk); j ++ ) { + if( chk[j].kind == 1 << i ) { + if( chk[j].gettype == 0 ) { + ret = CHAR_getInt( pindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 1 ) { + ret = CHAR_getWorkInt( pindex,chk[j].intdataindex); + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 10 ) { + ret = CHAR_getInt( pindex, chk[j].intdataindex)/100; + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + else if( chk[j].gettype == 11 ) { + ret = CHAR_getWorkInt( pindex, chk[j].intdataindex); + if( ret < 0) ret = 0; + snprintf( tmp, sizeof( tmp), "%d|", ret); + } + /* ٯ ̼ */ + else if( chk[j].gettype == 2 ) { + char escapebuffer[128]; + char *a = CHAR_getChar( pindex, chk[j].intdataindex); + snprintf( tmp,sizeof( tmp ), + "%s|", + makeEscapeString( a, escapebuffer, + sizeof(escapebuffer) + )); + } + found = TRUE; + break; + } + } + if( !found) { + if( indextable & CHAR_K_STRING_NEXTEXP ) { + ret = CHAR_GetLevelExp( pindex, CHAR_getInt( pindex, CHAR_LV ) + 1); + snprintf( tmp, sizeof( tmp), "%d|", ret); + found = TRUE; + } + if( indextable & CHAR_K_STRING_CHANGENAMEFLG ) { + BOOL changenameflg = FALSE; + char *mycdkey, *cdkey = NULL; + mycdkey = CHAR_getChar( charaindex, CHAR_CDKEY); + { + cdkey = CHAR_getChar( pindex, CHAR_CDKEY); + if( cdkey == "\0" ) { + print( "can't get CDKEY\n"); + }else { + if( strlen( cdkey) == 0 || + strcmp( cdkey, mycdkey) == 0 ){ + changenameflg = TRUE; + } + } + } + snprintf( tmp, sizeof( tmp), "%d|", changenameflg); + found = TRUE; + } + } + if( !found) { + print( "ҲָIJ[%d]\n",indextable); + }else { + strcpysafe( &CHAR_K_statusSendBuffer[ strlength], + sizeof( CHAR_K_statusSendBuffer) - strlength, + tmp); + + strlength += strlen( tmp ); + if( strlength >= sizeof( CHAR_K_statusSendBuffer ) ) { + return CHAR_K_statusSendBuffer; + } + } + } + } +#ifdef _VISUAL_BEATITUDE + strlength = strlen( CHAR_K_statusSendBuffer ); + snprintf(CHAR_K_statusSendBuffer+strlength,sizeof(CHAR_K_statusSendBuffer)-strlength-1,"%s|" ,BeatitudeCheck(index,pindex,num)); +#endif + return CHAR_K_statusSendBuffer; +} +/*------------------------------------------------------------ + * S K ë˪£¼ƥƥئʻУ + * ¦ + * charaindex int ƽҷ̼ + * indextable int P ë˪ɷ¶ + * ߯Ի + * ˪ףTRUE(1) + * ˪ľئףFALSE(0) + *------------------------------------------------------------*/ +BOOL CHAR_send_K_StatusString( int charaindex, int num, unsigned int indextable ) +{ + char* string; +#ifdef _PETCOM_ + if( indextable >= (CHAR_K_STRING_YLV << 1)) { +#else + if( indextable >= (CHAR_K_STRING_USERPETNAME << 1)) { +#endif + print( "send_K invalid index[%d]\n", indextable); + return FALSE; + } + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ){ + return FALSE; + } + string = CHAR_make_K_StatusString( charaindex, num, indextable ); + if( string != NULL ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ){ + lssproto_S_send( fd, string ); + return TRUE; + } + } + return FALSE; +} + + + +//------------------------------------------------------------ +// ëң +//------------------------------------------------------------ +void CHAR_AddCharm( int charaindex, int iValue ) +{ + int iWork; + iWork = CHAR_getInt( charaindex, CHAR_CHARM ) + iValue; + iWork = max( 0, iWork ); // + iWork = min( 100, iWork ); // ߨ + CHAR_setInt( charaindex, CHAR_CHARM, iWork ); +} + +//------------------------------------------------------------ +// ʸպ ëң£ +//------------------------------------------------------------ +void CHAR_PetAddVariableAi( int petindex, int iValue ) +{ + int iWork; + iWork = CHAR_getInt( petindex, CHAR_VARIABLEAI ) + iValue; + iWork = min( CHAR_MAXVARIABLEAI, iWork ); + iWork = max( CHAR_MINVARIABLEAI, iWork ); + CHAR_setInt( petindex, CHAR_VARIABLEAI, iWork ); + +} + +//------------------------------------------------------------ +// ì ƽ ë£ +//------------------------------------------------------------ +int CHAR_makeDBKey( int charaindex, char *pszBuffer, int size ){ + + char *cdkey; + char buff[512]; + char escapebuf[1024]; + + pszBuffer[0] = 0; // + cdkey = CHAR_getChar( charaindex, CHAR_CDKEY); + if( cdkey == "\0" )return FALSE; // ƥئ + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + // ƽ cdkey_ + snprintf( buff, sizeof(buff), + "%s_%s", cdkey, CHAR_getChar( charaindex, CHAR_NAME ) ); + makeEscapeString( buff, escapebuf, sizeof(escapebuf)); + strcpysafe( pszBuffer, size, escapebuf); + + return TRUE; +} + + +//------------------------------------------------------------ +// +// ì ëޥ +// +// DuelPoint DBUpdateEntryë˪ +//------------------------------------------------------------ +BOOL CHAR_send_DpDBUpdate( int charaindex ) +{ + int fd,dp; + char szKey[256]; + if( CHAR_makeDBKey( charaindex, szKey, sizeof( szKey ) ) == FALSE ){ + return FALSE; + } + dp = CHAR_getInt( charaindex, CHAR_DUELPOINT ); + fd = getfdFromCharaIndex( charaindex); + if( fd != -1 ) { + char info[512]; + //char escapebuff[1024]; + /* "ȼսʤܣʤʤ" */ + snprintf( info, sizeof( info), + "%d,%d,%d,%d,%d,%d", + CHAR_getInt( charaindex, CHAR_LV), + CHAR_getInt( charaindex, CHAR_DUELBATTLECOUNT), + CHAR_getInt( charaindex, CHAR_DUELWINCOUNT), + CHAR_getInt( charaindex, CHAR_DUELLOSECOUNT), + CHAR_getInt( charaindex, CHAR_DUELSTWINCOUNT), + CHAR_getInt( charaindex, CHAR_DUELMAXSTWINCOUNT)); + saacproto_DBUpdateEntryInt_send( + acfd, DB_DUELPOINT, szKey, max(dp,0), info, + CONNECT_getFdid( fd ) ,0 ); + } + + return TRUE; +} + +char *CHAR_getUseName( int charaindex ) +{ + char *pName=NULL; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pName = CHAR_getChar( charaindex, CHAR_USERPETNAME ); + if( pName[0] == 0 ){ + pName = CHAR_getChar( charaindex, CHAR_NAME ); + } + }else{ +// if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) +// pName = CHAR_getChar( charaindex, CHAR_OWNTITLE ); +// if( pName == "\0" || strlen(pName) <= 0 ) + pName = CHAR_getChar( charaindex, CHAR_NAME ); + } + return pName; +} + +// Robin extend_of_CHAR_getUseName() 2001/02/15 +char *CHAR_getUseID( int charaindex ) +{ + char *pName; + // ʸհة + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + pName = "NO_USER"; + }else{ + pName = CHAR_getChar( charaindex, CHAR_CDKEY ); + } + return pName; +} + +BOOL CHAR_send_DpDBUpdate_AddressBook( int charaindex, int mode ) +{ + int fd; + char szKey[256]; + if( CHAR_makeDBKey( charaindex, szKey, sizeof( szKey ) ) == FALSE ){ + return FALSE; + } + + fd = getfdFromCharaIndex( charaindex); + if( fd != -1 ) { + char msgbuf[512]; + snprintf( msgbuf, sizeof( msgbuf), + "%d|%d|%d|%d|%d|", + (mode == 0 ) ? 0 : getServernumber(), + CHAR_getInt( charaindex, CHAR_LV), + CHAR_getInt( charaindex, CHAR_DUELPOINT), + CHAR_getInt( charaindex, CHAR_FACEIMAGENUMBER), + CHAR_getInt( charaindex, CHAR_TRANSMIGRATION) ); + + saacproto_DBUpdateEntryString_send( + acfd, DB_ADDRESSBOOK, szKey, msgbuf, CONNECT_getFdid( fd ),0 ); + + saacproto_Broadcast_send( acfd, CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( charaindex, CHAR_NAME), "param", 0); + + } + return TRUE; +} + +void CHAR_sendBattleWatch( int objindex, int onoff) +{ + int opt[1]; + opt[0] = onoff; + CHAR_sendWatchEvent( objindex,CHAR_ACTBATTLEWATCH,opt,1,TRUE); +} +/*------------------------------------------------------------ + * ϶ýľ ëĪԻбʸPë£ + * ¦ + * charaindex int chara ƥ̼ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_sendPMEToArroundCharacterFLXY( int petindex, int fl, int x, int y, + int dir, int flg, int no ) +{ + int i,j; + int objindex; + int graphicsno; + char buff[2048]; + + objindex = CHAR_getWorkInt( petindex, CHAR_WORKOBJINDEX); + graphicsno = CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER); +#ifndef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCString( objindex, buff, sizeof( buff)) == FALSE ) { + buff[0] = '\0'; + } +#endif + + for( i = x - CHAR_DEFAULTSEESIZ/2 ; + i <= x +CHAR_DEFAULTSEESIZ/2 ; i ++ ){ + for( j = y - CHAR_DEFAULTSEESIZ/2; + j <= y + CHAR_DEFAULTSEESIZ/2; j ++ ){ + + OBJECT object; + for( object = MAP_getTopObj( fl, i,j); + object; + object = NEXT_OBJECT(object) ){ + int objindexwk = GET_OBJINDEX( object); + if( OBJECT_getType(objindexwk) == OBJTYPE_CHARA ){ + int index = OBJECT_getIndex(objindexwk); + if( CHAR_getInt( index,CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int fd; + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) continue; + fd = getfdFromCharaIndex( index); + if( fd == -1 )continue; +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( objindex,index, buff, sizeof( buff)) == FALSE ) { + buff[0] = '\0'; + } +#endif + lssproto_PME_send( fd, objindex, graphicsno, + x,y, dir,flg,no,buff + ); + } + } + } + } + } +} +/*------------------------------------------------------------ + * charaindex ƥ϶ýľ ëĪԻбʸPë£ + * ¦ + * charaindex int chara ƥ̼ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_sendPMEToArroundCharacter( int charaindex, int petindex, int flg, int no ) +{ + int dirx[9],diry[9]; + int i; + int fl,x,y; + int dir; + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + diry[i+2] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + + fl = CHAR_getInt( charaindex,CHAR_FLOOR ); + dir = CHAR_getInt( charaindex, CHAR_DIR); + + /* */ + for( i = 0 ; i < 9 ; i ++ ){ + int x = CHAR_getInt( charaindex, CHAR_X) + dirx[i]; + int y = CHAR_getInt( charaindex, CHAR_Y) + diry[i]; + /* ʸë Ʃ */ + if( PET_isPutPoint( fl, x, y ) == TRUE ) { + break; + } + } + /* ئľ */ + if( i == 9 ) i = 1; + + x = CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + y = CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + + CHAR_sendPMEToArroundCharacterFLXY( petindex, + fl, x, y, dir, flg, no); +} +/*------------------------------------------------------------ + * SEë ʣ + * ë ұέ ˪ + * ¦ + * fl,x,y 缰 + * senumber įsndcnf.hë徼 + * sw ʾ¾ 0 : 1 : + ------------------------------------------------------------*/ +void CHAR_sendSEoArroundCharacter( int fl, int x, int y, int senumber, int sw ) +{ + int i,j; + + for( i = x - CHAR_DEFAULTSEESIZ/2 ; + i <= x +CHAR_DEFAULTSEESIZ/2 ; i ++ ){ + for( j = y - CHAR_DEFAULTSEESIZ/2; + j <= y + CHAR_DEFAULTSEESIZ/2; j ++ ){ + + OBJECT object; + for( object = MAP_getTopObj( fl, i,j); + object; + object = NEXT_OBJECT(object) ){ + int objindexwk = GET_OBJINDEX( object); + if( OBJECT_getType(objindexwk) == OBJTYPE_CHARA ){ + int index = OBJECT_getIndex(objindexwk); + if( CHAR_getInt( index,CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + int fd; + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) continue; + fd = getfdFromCharaIndex( index); + if( fd == -1 )continue; + lssproto_SE_send( fd,x, y, senumber, sw ); + } + } + } + } + } +} +/*====================ɬ====================*/ + + +#ifndef _SEND_EFFECT // WON ADD ACѩЧ + +#define CHAR_EFFECT_SETTINGBUFFER 256 +typedef struct tagCHAR_effectsetting +{ + int floor; // ׷ʧ + int effect; // į + int level; // 뼰ì ؼ۽ + int sendflg; // ްë˪׾ + char month[CHAR_EFFECT_SETTINGBUFFER]; // » + char day[CHAR_EFFECT_SETTINGBUFFER]; // + char hour[CHAR_EFFECT_SETTINGBUFFER]; // + char min[CHAR_EFFECT_SETTINGBUFFER]; // + char expire[CHAR_EFFECT_SETTINGBUFFER]; // ƻӮ( + +}CHAR_effectsetting; + +CHAR_effectsetting* CHAR_effect; +int CHAR_effectnum; + +#endif + + + +/*------------------------------------------------------------ + * ɬüë£ + * ¦ + * filename char* ɬð̻ + * ߯Ի + * TRUE(1) + * FALSE(0) + *------------------------------------------------------------*/ +BOOL CHAR_initEffectSetting( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + + int effectreadlen=0; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + errorprint; + return FALSE; + } + + CHAR_effectnum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + CHAR_effectnum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Seek Error\n" ); + fclose(f); + return FALSE; + } + + CHAR_effect = allocateMemory( sizeof(CHAR_effectsetting) + * CHAR_effectnum ); + if( CHAR_effect == NULL ){ + fprint( "Can't allocate Memory %d\n" , + sizeof(CHAR_effectsetting)*CHAR_effectnum); + fclose( f ); + return FALSE; + } + /* */ +{ + int i; + for( i = 0; i < CHAR_effectnum; i ++ ) { + CHAR_effect[i].floor = 0; + CHAR_effect[i].effect = 0; + CHAR_effect[i].level = 0; + CHAR_effect[i].sendflg = 0; + CHAR_effect[i].month[0] = '\0'; + CHAR_effect[i].day[0] = '\0'; + CHAR_effect[i].hour[0] = '\0'; + CHAR_effect[i].min[0] = '\0'; + CHAR_effect[i].expire[0] = '\0'; + + } +} + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* " " ë繴 */ + deleteSequentChar( line, " " ); + + /* ƥƻ ʸ */ + /* ئ */ + if( line[0] == ' ' )continue; + + { + char token[256]; + int ret; + + /* 繴ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",1,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + CHAR_effect[effectreadlen].floor = atoi(token); + + /* 2ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",2,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + + CHAR_effect[effectreadlen].effect = atoi( token ); + + /* 3ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",3,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + + CHAR_effect[effectreadlen].level = atoi( token ); + + /* 4ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",4,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + strcpysafe( CHAR_effect[effectreadlen].month, + sizeof( CHAR_effect[effectreadlen].month), + token); + + /* 5ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",5,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + strcpysafe( CHAR_effect[effectreadlen].day, + sizeof( CHAR_effect[effectreadlen].day), + token); + + /* 6ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",6,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + strcpysafe( CHAR_effect[effectreadlen].hour, + sizeof( CHAR_effect[effectreadlen].hour), + token); + + /* 7ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",7,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + strcpysafe( CHAR_effect[effectreadlen].min, + sizeof( CHAR_effect[effectreadlen].min), + token); + + /* 8ͼëέ */ + ret = getStringFromIndexWithDelim( line," ",8,token, + sizeof(token)); + if( ret ==FALSE){ + fprint("ļ:%s %d\n",filename,linenum); + continue; + } + strcpysafe( CHAR_effect[effectreadlen].expire, + sizeof( CHAR_effect[effectreadlen].expire), + token); + + effectreadlen ++; + } + } + fclose(f); + + CHAR_effectnum = effectreadlen; + + print( "Ч %d...", CHAR_effectnum ); +#ifdef DEBUG + + { + int i; + for( i=0; i tim && NowTime.tv_sec < tim+atoi(CHAR_effect[num].expire)) { + flg = TRUE; + break; + } + } + if( !flg ) break; + } + } + // л϶ ƷֵOK + + returnflg = TRUE; + break; + } + return returnflg; +} +//------------------------------------------------------------------------- +// ƽҷ ë +// ްë˪ ۢؤľ˪ +//------------------------------------------------------------------------- +void CHAR_checkEffect( int charaindex) +{ + int i; + int fl = CHAR_getInt( charaindex, CHAR_FLOOR); + int fd = getfdFromCharaIndex( charaindex); + + // ް + lssproto_EF_send( fd, 0, 0, ""); + CHAR_setWorkInt( charaindex, CHAR_WORKEFFECT, 0); + + for( i = 0; i < CHAR_effectnum; i ++){ + // ׷ʧݷ + if( CHAR_effect[i].floor == fl) { + // ëƩʣ + if( CHAR_checkEffectTime( i)){ + // ްë˪ + lssproto_EF_send( fd, CHAR_effect[i].effect, CHAR_effect[i].level, ""); + if( CHAR_effect[i].level == 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKEFFECT, + CHAR_getWorkInt( charaindex, CHAR_WORKEFFECT) & + ~CHAR_effect[i].effect); + } + else { + CHAR_setWorkInt( charaindex, CHAR_WORKEFFECT, + CHAR_getWorkInt( charaindex, CHAR_WORKEFFECT) | + CHAR_effect[i].effect); + } + } + } + } +} + +void CHAR_checkEffectLoop( void) +{ + int i,j; + int playernum = CHAR_getPlayerMaxNum(); + int player; + int efnum = 0; + + struct { + int floor; + int effect; + BOOL on; + BOOL off; + } ef[2048]; + + memset( &ef, 0, sizeof( ef)); + + for( i = 0; i < CHAR_effectnum; i ++){ + + if( CHAR_checkEffectTime( i)){ + if( !CHAR_effect[i].sendflg) { + + for( player = 0 ; player < playernum; player ++ ) { + if( CHAR_getInt( player, CHAR_FLOOR) == CHAR_effect[i].floor ) { + int fd = getfdFromCharaIndex( player); + lssproto_EF_send( fd, CHAR_effect[i].effect, CHAR_effect[i].level, ""); + if( CHAR_effect[i].level == 0 ) { + CHAR_setWorkInt( player, CHAR_WORKEFFECT, + CHAR_getWorkInt( player, CHAR_WORKEFFECT) & + ~CHAR_effect[i].effect); + } + else { + CHAR_setWorkInt( player, CHAR_WORKEFFECT, + CHAR_getWorkInt( player, CHAR_WORKEFFECT) | + CHAR_effect[i].effect); + } + } + } + CHAR_effect[i].sendflg = TRUE; + + } + + for( j = 0; j < efnum; j ++ ) { + if( ef[j].floor == CHAR_effect[i].floor && + ef[j].effect == CHAR_effect[i].effect) + { + ef[j].on = TRUE; + break; + } + } + if( j == efnum ) { + ef[j].floor = CHAR_effect[i].floor; + ef[j].effect = CHAR_effect[i].effect; + ef[j].on = TRUE; + efnum++; + if( efnum >= arraysizeof( ef)) { + print( "err buffer over %s:%d\n", __FILE__, __LINE__); + efnum --; + } + } + } + else { + if( CHAR_effect[i].sendflg) { + + for( j = 0; j < efnum; j ++ ) { + if( ef[j].floor == CHAR_effect[i].floor && + ef[j].effect == CHAR_effect[i].effect) + { + ef[j].off = TRUE; + break; + } + } + if( j == efnum ) { + ef[j].floor = CHAR_effect[i].floor; + ef[j].effect = CHAR_effect[i].effect; + ef[j].off = TRUE; + efnum++; + if( efnum >= arraysizeof( ef)) { + print( "err buffer over %s:%d\n", __FILE__, __LINE__); + efnum --; + } + } + CHAR_effect[i].sendflg = FALSE; + } + } + } + + for( i = 0; i < efnum; i ++ ) { + if( ef[i].on == FALSE && ef[i].off == TRUE ) { + + for( player = 0 ; player < playernum; player ++ ) { + if( CHAR_getInt( player, CHAR_FLOOR) == ef[i].floor ) { + int fd = getfdFromCharaIndex( player); + lssproto_EF_send( fd, 0, 0, ""); + CHAR_setWorkInt( player, CHAR_WORKEFFECT, 0); + } + } + } + } +} + +float GetRecoveryRate( int charaindex ){ + float fBai = 1.0; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + fBai = 1.0 + 0.00010 * CHAR_getInt( charaindex, CHAR_VITAL ); + }else{ + + fBai = 1.0 + 0.00005 * CHAR_getInt( charaindex, CHAR_VITAL ); + } + return fBai; + +} + + +#define CHARDATASIZE (1024*256) +#define SPACESTRING "|" + +static int makeSaveCharString( char *out , int outlen , + char *nm , char *opt , char *info ) +{ + char nmwork[256]; + char optwork[512]; + char infowork[CHARDATASIZE]; + char outwork[CHARDATASIZE]; + char *nmwork_p , *optwork_p , *infowork_p; + int l; + + strncpy( nmwork , nm , sizeof( nmwork )); + nmwork[strlen( nm)]=0; + + strncpy( optwork , opt , sizeof( optwork )); + optwork[strlen(opt)]=0; + + strncpy( infowork , info , sizeof( infowork )); + infowork[strlen(info)]=0; + + nmwork_p = makeEscapeString( nm , nmwork ,sizeof( nmwork )); + optwork_p = makeEscapeString( opt , optwork , sizeof( optwork )); + infowork_p = makeEscapeString( info , infowork , sizeof( infowork )); + + snprintf( outwork ,sizeof( outwork ) , + "%s" SPACESTRING "%s" SPACESTRING "%s" , + nmwork_p , optwork_p , infowork_p ); + + l = strlen( outwork ); + outwork[ strlen( outwork)+1] = 0; + if( l >= (outlen-1)){ + return -1; + } + + memcpy( out , outwork , l + 1 ); + + return 0; +} + +#ifdef _STORECHAR +int storeCharaData( void ){ + int i; + FILE *fp; + struct tm *pLtime; + char szFileName[256], *chardata; + char outbuff[CHARDATASIZE]; + Char* ch; + + print("\nе"); + + pLtime = localtime( &NowTime.tv_sec ); + + for( i = 0; i < CHAR_getPlayerMaxNum(); i ++ ){ + int hash, dir, j; + char charId[32]; + char pathname[128]; + + if( CHAR_getCharUse( i ) == FALSE )continue; + +#ifdef _PETFOLLOW_NEW_ + CHAR_pickupFollowPet( i, -1 ); +#endif +#ifdef _ALLBLUES_LUA_1_4 + RunCharLogOutEvent(i); +#endif + print("."); + strcpy( charId, CHAR_getChar( i, CHAR_CDKEY ) ); +// print("˺:%s", charId); + hash = 0; + for( j=0; jtm_year+1900, + pLtime->tm_mon+1, + pLtime->tm_mday, + pLtime->tm_hour, + pLtime->tm_min + ); + + fp = fopen( szFileName, "w" ); + if( fp == NULL )continue; + + ch = CHAR_getCharPointer( i ); + if( !ch )continue; + + chardata = CHAR_makeStringFromCharData( ch ); + + if( makeSaveCharString( outbuff , sizeof( outbuff ), + CHAR_getChar( i, CHAR_NAME ), + CHAR_makeOptionString( ch ), + chardata ) == 0 + ){ + + fprintf( fp, outbuff ); + }else{ + fprintf( fp, "Ƥ \n" ); + } + + fclose( fp ); + } + return 0; +} + +#endif + + +#ifdef _FIX_METAMORIDE +BOOL CHAR_CHECKJOINENEMY( int index) +{ + int masterindex=-1; + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT ) { + masterindex = CHAR_getWorkInt( index, CHAR_WORKPARTYINDEX1); + if( !CHAR_CHECKINDEX( masterindex) ) { + print( "err masterindex:%d %s:%d !!\n", masterindex,__FILE__, __LINE__); + return FALSE; + } + if( CHAR_getInt( masterindex, CHAR_WHICHTYPE) == CHAR_TYPEBUS) { + return TRUE; //JOIN ENEMY + } + } + + return FALSE; +} +#endif + + // WON ADD ߵ趨 +void fix_item_bug(int charaindex, int itemindex) +{ + + if (ITEM_CHECKINDEX(itemindex)){ + switch( ITEM_getInt(itemindex,ITEM_ID) ){ + case 19700: ITEM_setChar( itemindex, ITEM_ARGUMENT, "KPET:901_902_903_904"); break; // + case 20242: ITEM_setChar( itemindex, ITEM_ARGUMENT, "KPET:957_958_959_960"); break; // ۻƾ +#ifdef _TAKE_ITEMDAMAGE + case 1292: ITEM_setInt( itemindex, ITEM_MAXDAMAGECRUSHE, 0); ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, 0); break; // + case 19646: ITEM_setInt( itemindex, ITEM_MAXDAMAGECRUSHE, 0); ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, 0); break; // +#endif + case 1478: ITEM_setChar( itemindex, ITEM_ARGUMENT, "HP:30"); break; // ˷ + case 20282: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, "+25 +25 -4 +5"); ITEM_setInt( itemindex, ITEM_MODIFYQUICK, -4 ); break; // ǹ1 + case 20283: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, "+50 +50 -10 +10"); ITEM_setInt( itemindex, ITEM_MODIFYQUICK, -10 ); break; // ǹ2 + case 20284: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, "+100 +100 -20 +15"); ITEM_setInt( itemindex, ITEM_MODIFYQUICK, -20 ); break; // ǹ3 + case 1210: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, " +4 -4 +4 +2"); break; // ʯֻ + case 1203: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, " +2 +2 -2 +1"); break; // Ƥֻ() + case 1204: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, " -2 +2 +2 +1"); break; // Ƥֻ() + case 1205: ITEM_setChar( itemindex, ITEM_EFFECTSTRING, " +2 -2 +2 +1"); break; // Ƥֻ() + case 1483: ITEM_setInt( itemindex, ITEM_MODIFYCHARM, 5); break; // ɳŽ + case 20147: ITEM_setChar(itemindex,ITEM_INGNAME0,"ľ"); ITEM_setChar(itemindex,ITEM_INGNAME1,""); ITEM_setInt(itemindex,ITEM_INGVALUE0, 1125 ); ITEM_setInt(itemindex,ITEM_INGVALUE1, 1125 ); break; // ˫ͷ + default: + break; + } + } +} + +#ifdef _PET_LOSTPET +BOOL CHAR_CharSaveLostPet( int petindex, int type)//0 1 2 +{ + int lv, cost=0; + char* CdKey=NULL; + char* Uniquecode; + char* petname; + + char lostpetstring[1024*4]; + char *petstring; + + if( !CHAR_CHECKINDEX( petindex) ) return FALSE; +// + petstring = CHAR_makePetStringFromPetIndex( petindex); + if( petstring == "\0" ) return FALSE; + CdKey = CHAR_getChar( petindex, CHAR_OWNERCDKEY); + if( CdKey == "\0" ) return FALSE; + Uniquecode = CHAR_getChar( petindex, CHAR_UNIQUECODE); + if( Uniquecode == "\0" ) return FALSE; + lv = CHAR_getInt( petindex, CHAR_LV); + petname = CHAR_getChar( petindex, CHAR_NAME); + + if( type == 1 ){ + cost = lv*300; + }else if( type == 2){ + cost = lv*1000; + }else{ + cost = lv*10000; + } + + sprintf( lostpetstring, "%s|%s|%d|%d|%s|%d#%s#%d", + CdKey, petname, lv, cost, Uniquecode, (int)time( NULL), petstring, + type); + +// print(":%s-%d\n", lostpetstring, strlen(lostpetstring)); + { + char buf[10][2048]={"","","","","","","","","",""}; + char line[2048]; + int count=0, i, start=0; + FILE *fp=NULL; + char filename[256]; + +/* + sprintf( filename, "lostpet/%s.txt", CdKey); + if( (fp=fopen( filename, "a+")) != NULL ){ + fprintf( fp, "%s\n", petstring); + fclose( fp); + }else{ + print("Can't Add %s \n", filename); + } + +*/ + + + sprintf( filename, "lostpet/%s.txt", CdKey); + if( (fp=fopen( filename, "r")) != NULL ){ + while( fgets( line , sizeof( line ) , fp ) && count < 7){ + if( strlen(line) <= 0 ) continue; + strcpy( buf[ count++] , line); + } + fclose( fp); + }else{ + print("Can't Read %s \n", filename); + } + + if( (fp=fopen( filename, "w+")) == NULL ){ + print("Can't Write %s \n", filename); + return FALSE; + } + if( strlen( buf[ 6]) > 0 ){ + start=2; + } + for( i=start; i<7; i++){ + if( strlen( buf[i]) > 0 ) { + print("Write %s \n", buf[i]); + fprintf( fp, "%s", buf[i]); + } + } + fprintf( fp, "%s\n", lostpetstring); + + fclose( fp); + } + return TRUE; +} +/* +while( fgets( line , sizeof( line ) , fp ) && count < 7){ +*/ +#endif + +#ifdef _ALLDOMAN +void InitHeroList( void) +{ + saacproto_UpdataStele_send ( acfd , "FirstLoad", "LoadHerolist" , "" , 0 , 0 , 0 , 999 ) ; +} +#endif + +#ifdef _STREET_VENDOR +#ifdef _NEW_STREET_VENDOR +char streetvendor[STREET_VENDOR_NUM][32]={ + "ʯ", + "", +#ifndef _VERSION_NEW + "", +#endif +/* +#ifdef _NEW_MANOR_LAW + "", +#endif +*/ + "DP", +#ifdef _CAMEO_MONEY + "", +#endif +#ifdef _ACTIVE_GAME + "", +#endif +#ifdef _STREET_VENDOR_MYSQL + "", +#endif + }; +#endif +void CHAR_sendStreetVendor(int charaindex,char *message) +{ + char szAction[2],szTemp[21]; + int count = 0,i,j,iItemIndex = 0,iPetIndex = 0,iPileNum = 0,iMaxPileNum = 0; + int ix,iy,iPlayerNum = 0,objbuf[16]; + + if(!getStringFromIndexWithDelim(message,"|",1,szAction,sizeof(szAction))) return; + // ̯ + if(szAction[0] == 'O'){ + CHAR_getCoordinationDir(CHAR_getInt(charaindex,CHAR_DIR),CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y),1,&ix,&iy); + // ȡǰ + iPlayerNum = CHAR_getSameCoordinateObjects(objbuf,arraysizeof(objbuf),CHAR_getInt(charaindex,CHAR_FLOOR),ix,iy); + // û + if(iPlayerNum == 0){ + // ԼվûҲڰ̯ + iPlayerNum = CHAR_getSameCoordinateObjects(objbuf,arraysizeof(objbuf), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y)); + // ֻԼһ + if(iPlayerNum > 1){ + // ûа̯ + for(i=0;i 0){ + if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 1){ + // ޸δ̯ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_sendStreetVendorDataToCli(charaindex,charaindex); + } + // ڽеҪ,رնԷӴ + else if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 2){ + int toindex = CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO); + + if(toindex != -1 && CHAR_CHECKINDEX(toindex)){ + CHAR_send_P_StatusString( toindex, CHAR_P_STRING_GOLD ); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(toindex),"C|"); + CHAR_talkToCli(toindex,-1,"ȡ",CHAR_COLORYELLOW); + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO,-1); + // ͼʾ + CHAR_sendTradeEffect(charaindex,0); + CHAR_sendTradeEffect(toindex,0); + } + // ޸,δ̯ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_sendStreetVendorDataToCli(charaindex,charaindex); + } + return; + } + // ԷǷ + for(j=0;j 0){ + if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 1){ + // ޸δ̯ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_sendStreetVendorDataToCli(charaindex,charaindex); + } + // ڽеҪ,رնԷӴ + else if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 2){ + int toindex = CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO); + + if(toindex != -1 && CHAR_CHECKINDEX(toindex)){ + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD ); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(toindex),"C|"); + CHAR_talkToCli(toindex,-1,"ȡ",CHAR_COLORYELLOW); + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO,-1); + // ͼʾ + CHAR_sendTradeEffect(charaindex,0); + CHAR_sendTradeEffect(toindex,0); + } + // ޸,δ̯ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_sendStreetVendorDataToCli(charaindex,charaindex); + } + } + // 趨ɰ̯ + else{ +#ifdef _NEW_STREET_VENDOR + char message[256]; + char buf[256]; + sprintf( message, "2\n\nѡҪİ̯ģʽ\n" + "ʯҽа̯\n" + "а̯\n" +#ifndef _VERSION_NEW + "Իֽа̯\n" +#endif +/* +#ifdef _NEW_MANOR_LAW + "ƽа̯\n" +#endif + + "ԣģна̯\n" +#ifdef _CAMEO_MONEY + "Աǽа̯\n" +#endif +*/ +#ifdef _ACTIVE_GAME + "Իа̯\n" +#endif +#ifdef _STREET_VENDOR_MYSQL + "ҽа̯\n" +#endif + ); + + lssproto_WN_send( getfdFromCharaIndex(charaindex), WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_STREET_VENDOR_TYPE, + -1, + makeEscapeString( message, buf, sizeof(buf))); + +#else + sprintf(szMessage,"O|"); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(charaindex),szMessage); +#endif + } + return; + } + } + } + } + // ̯ + else if(szAction[0] == 'S'){ + if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 2) return; + int price; + + // о + for(i=0;i20){ + print("\n۸İ̯ʺ=%s",CHAR_getChar(charaindex,CHAR_CDKEY)); + return; + } +#endif + for(i=0;i 10000000) price = 10000000; + else if(price < 0) price = 0; + CHAR_setStreetVendor(charaindex,i,SV_PRICE,price); + } + if(!getStringFromIndexWithDelim(message,"|",6+(i-1)*3,szTemp,sizeof(szTemp))) return; +#ifdef _STREET_VENDOR_CHECK + if (strlen(szTemp)>16){ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_talkToCli(charaindex,-1,"̯λ",CHAR_COLORYELLOW); + return; + } +#endif +#ifdef _NEW_STREET_VENDOR + char streetvendorname[256]; + int lst = CHAR_getWorkInt(charaindex, CHAR_WORKSTREETVENDORTYPE); + if(lst==STREET_VENDOR_GOLD){ + sprintf(streetvendorname, "[ʯ]%s\n", szTemp); + }else if(lst==STREET_VENDOR_FAME){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#ifndef _VERSION_NEW + else if(lst==STREET_VENDOR_AMPOINT){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#endif +/* +#ifdef _NEW_MANOR_LAW + else if(lst==STREET_VENDOR_MOMENTUM){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#endif + + else if(lst==STREET_VENDOR_DP){ + sprintf(streetvendorname, "[DP]%s\n", szTemp); + } +#ifdef _CAMEO_MONEY + else if(lst==STREET_VENDOR_CAMEO){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#endif +*/ +#ifdef _ACTIVE_GAME + else if(lst==STREET_VENDOR_ACTIVE){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#endif +#ifdef _STREET_VENDOR_MYSQL + else if(lst==STREET_VENDOR_MYSQL){ + sprintf(streetvendorname, "[]%s\n", szTemp); + } +#endif + else{ + sprintf(streetvendorname, "[Ƿ]%s\n", szTemp); + } +#endif + + // cli + for(i=0;i20) return; +#endif + for(i=0;i CHAR_getMaxHaveGold(toindex)){ + // ϲ, + if(CHAR_getInt(toindex,CHAR_BANKGOLD) + iPrice > CHAR_MAXBANKGOLDHAVE){ + CHAR_talkToCli(charaindex,-1,"ҷŲʯˣȡ",CHAR_COLORRED); + CHAR_talkToCli(toindex,-1,"ϼд",CHAR_COLORRED); + break; + } + CHAR_talkToCli(toindex,-1,"Ѵ",CHAR_COLORRED); + bPutToBank = TRUE; + } + }else if(lst==STREET_VENDOR_FAME){ + if( CHAR_getInt(charaindex,CHAR_FAME) / 100 < iPrice ) { + CHAR_talkToCli( charaindex, -1, "ϵŶ", CHAR_COLORRED); + break; + } + if(CHAR_getInt(toindex,CHAR_FAME) + iPrice > MAX_PERSONALFAME){ + // Ƿ񳬹 + CHAR_talkToCli(charaindex,-1,"ޣȡ",CHAR_COLORRED); + CHAR_talkToCli(toindex,-1,"ijνΪ޶ȡ",CHAR_COLORRED); + break; + } + } +#ifndef _VERSION_NEW + else if(lst==STREET_VENDOR_AMPOINT){ + if( CHAR_getInt(charaindex,CHAR_AMPOINT) < iPrice ) { + CHAR_talkToCli( charaindex, -1, "ϵĻֵŶ", CHAR_COLORRED); + break; + } + } +#endif +/* +#ifdef _NEW_MANOR_LAW + else if(lst==STREET_VENDOR_MOMENTUM){ + if( CHAR_getInt(charaindex,CHAR_MOMENTUM) / 100 < iPrice ) { + CHAR_talkToCli( charaindex, -1, "ĸֵร", CHAR_COLORRED); + break; + } + } +#endif + + else if(lst==STREET_VENDOR_DP){ + if( CHAR_getInt(charaindex,CHAR_DUELPOINT) < iPrice ) { + CHAR_talkToCli( charaindex, -1, "ĸˣģֵร", CHAR_COLORRED); + break; + } + } +#ifdef _CAMEO_MONEY + else if(lst==STREET_VENDOR_CAMEO){ + if( CHAR_getInt(charaindex,CHAR_CAMEO) < iPrice ){ + CHAR_talkToCli( charaindex, -1, "ĸ˱Dzร", CHAR_COLORRED); + break; + } + } +#endif +*/ +#ifdef _ACTIVE_GAME + else if(lst==STREET_VENDOR_ACTIVE){ + if( CHAR_getInt(charaindex,CHAR_ACTIVE) < iPrice ){ + CHAR_talkToCli( charaindex, -1, "ĸ˻ร", CHAR_COLORRED); + break; + } + } +#endif +#ifdef _STREET_VENDOR_MYSQL + else if(lst==STREET_VENDOR_MYSQL){ + if( sasql_getVipPoint(charaindex) < iPrice ){ + CHAR_talkToCli( charaindex, -1, "ĸ˽Ҳร", CHAR_COLORRED); + break; + } + } +#endif + + else{ + CHAR_talkToCli( charaindex, -1, "Ƿ̯Ŷ~", CHAR_COLORRED); + break; + } +#else + // Ǯ + if(CHAR_getInt(charaindex,CHAR_GOLD) < iPrice){ + CHAR_talkToCli(charaindex,-1,"ʯҲ",CHAR_COLORRED); + break; + } + bPutToBank = FALSE; + // Ǯ + if(CHAR_getInt(toindex,CHAR_GOLD) + iPrice > CHAR_getMaxHaveGold(toindex)){ + // ϲ, + if(CHAR_getInt(toindex,CHAR_BANKGOLD) + iPrice > CHAR_MAXBANKGOLDHAVE){ + CHAR_talkToCli(charaindex,-1,"ҷŲʯˣȡ",CHAR_COLORRED); + CHAR_talkToCli(toindex,-1,"ϼд",CHAR_COLORRED); + break; + } + CHAR_talkToCli(toindex,-1,"Ѵ",CHAR_COLORRED); + bPutToBank = TRUE; + } +#endif + // ǵ + if(iKind == 0){ +#ifdef _STREET_VENDOR_TRANS + if(CHAR_getInt(charaindex,CHAR_TRANSMIGRATION) < getStreetVendorTrans()){ + char buf[256]; + sprintf( buf, "ֻ%dתϲſԹ̯Ʒ", getStreetVendorTrans()); + CHAR_talkToCli(charaindex,-1,buf,CHAR_COLORYELLOW); + return; + } +#endif + iItemIndex = CHAR_getItemIndex(toindex,iFieldIndex); + // ߲ + if(!ITEM_CHECKINDEX(iItemIndex)){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + printf("\nCHAR_sendStreetVendor(B):Ҳ!!!!!!!\n"); + continue; + } + // ڵϻʧĵ߲ɷ + if(ITEM_getInt(iItemIndex,ITEM_VANISHATDROP) == 1){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + CHAR_talkToCli(charaindex,-1,"ڵϻʧĵ߲ɷѡȡ",CHAR_COLORYELLOW); + CHAR_talkToCli(toindex,-1,"⵽жڵϻʧĵڷʺѼ¼",CHAR_COLORRED); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + "", + "", + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + "StreetVendor(ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + -1,-1,-1, + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); + continue; + } + if(FreeStreetVendorItem(charaindex, iItemIndex) == 1){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + "", + "", + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + "StreetVendor(ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + -1,-1,-1, + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); + continue; + } +#ifdef _LOCK_PET_ITEM + char *arg = ITEM_getChar(iItemIndex, ITEM_NAME); + if(arg[0] == '*'){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + CHAR_talkToCli( charaindex, -1, "󶨵Ʒɷѡȡ", CHAR_COLORYELLOW ); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + "", + "", + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + "StreetVendor(ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + -1,-1,-1, + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); + continue; + } +#endif + // Ʒ + if(iPrice <= 0){ + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + "StreetVendor(򷽸ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); + continue; + } + // Ʒѵ + iPileNum = ITEM_getInt(iItemIndex,ITEM_USEPILENUMS); + // ѵ + iMaxPileNum = CHAR_getMyMaxPilenum(charaindex); + // ƷĶѵϵѵ,Ʒ,Ʒ + if(iPileNum - iMaxPileNum <= 0){ + if(!ITEM_CHECKINDEX(iItemIndex)){ + CHAR_talkToCli(charaindex,-1,"ʧ(1)",CHAR_COLORRED); + break; + } +#ifdef _ITEM_PILENUMS + // Ϊ0 + if(ITEM_getInt(iItemIndex,ITEM_USEPILENUMS) <= 0){ + CHAR_talkToCli(charaindex,-1,"ʧ(2)",CHAR_COLORRED); + break; + } +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + // 򷽵 + if((iRet = CHAR_addItemSpecificItemIndex(charaindex,iItemIndex)) >= CheckCharMaxItem(charaindex)){ + CHAR_talkToCli(charaindex,-1,"ˡ",CHAR_COLORRED); + break; + } + CHAR_sendItemDataOne(charaindex,iRet); + // + CHAR_setItemIndex(toindex,iFieldIndex,-1); + CHAR_sendItemDataOne(toindex,iFieldIndex); + CHAR_clearStreetVendor(toindex,iBuyIndex); +#ifdef _NEW_STREET_VENDOR + int lst = CHAR_getWorkInt(toindex, CHAR_WORKSTREETVENDORTYPE); + char token[128]; + int tax; + if(getStreetVendor(lst) > 0){ + tax = max((iPrice * getStreetVendor(lst) / 100), 1); + }else{ + tax = 0; + } + + if(lst==STREET_VENDOR_GOLD){ + // Ǯ + CHAR_setInt(charaindex,CHAR_GOLD,CHAR_getInt(charaindex,CHAR_GOLD) - iPrice); + CHAR_send_P_StatusString(charaindex,CHAR_P_STRING_GOLD); + // Ǯ + if(bPutToBank) CHAR_setInt(toindex,CHAR_BANKGOLD,CHAR_getInt(toindex,CHAR_BANKGOLD) + (iPrice - tax)); + else CHAR_setInt(toindex,CHAR_GOLD,CHAR_getInt(toindex,CHAR_GOLD) + (iPrice - tax)); + CHAR_send_P_StatusString(toindex,CHAR_P_STRING_GOLD); + }else if(lst==STREET_VENDOR_FAME){ + CHAR_setInt(charaindex,CHAR_FAME,CHAR_getInt(charaindex,CHAR_FAME) - iPrice * 100); + int maxfame = (iPrice - tax) * 100; + if(maxfame > MAX_PERSONALFAME)maxfame = MAX_PERSONALFAME; + CHAR_setInt(toindex,CHAR_FAME,CHAR_getInt(toindex,CHAR_FAME) + maxfame); + + sprintf( token, "۳%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + + } +#ifndef _VERSION_NEW + else if(lst==STREET_VENDOR_AMPOINT){ + CHAR_setInt(charaindex,CHAR_AMPOINT,CHAR_getInt(charaindex,CHAR_AMPOINT) - iPrice); + CHAR_setInt(toindex,CHAR_AMPOINT,CHAR_getInt(toindex,CHAR_AMPOINT) + (iPrice - tax)); +#ifdef _AMPOINT_LOG + if(iPrice>0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -iPrice, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(̯)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } + + if((iPrice - tax)>0){ + LogAmPoint(CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + (iPrice - tax), + CHAR_getInt( toindex, CHAR_AMPOINT ), + "(̯)", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y )); + } +#endif + sprintf( token, "۳˻֣%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹ˻֣%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +/* +#ifdef _NEW_MANOR_LAW + else if(lst==STREET_VENDOR_MOMENTUM){ + CHAR_setInt(charaindex,CHAR_MOMENTUM,CHAR_getInt(charaindex,CHAR_MOMENTUM) - iPrice*100); + CHAR_setInt(toindex,CHAR_MOMENTUM,CHAR_getInt(toindex,CHAR_MOMENTUM) + (iPrice - tax)*100); + char buf[64]; + sprintf(buf,"%d", CHAR_getInt(charaindex,CHAR_MOMENTUM)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(charaindex,CHAR_FMNAME),CHAR_getInt(charaindex,CHAR_FMINDEX),CHAR_getWorkInt(charaindex,CHAR_WORKFMINDEXI), + FM_FIX_FMMOMENTUM,buf,"",CHAR_getWorkInt(charaindex,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(getfdFromCharaIndex(charaindex))); + + sprintf(buf,"%d", CHAR_getInt(toindex,CHAR_MOMENTUM)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(toindex,CHAR_FMNAME),CHAR_getInt(toindex,CHAR_FMINDEX),CHAR_getWorkInt(toindex,CHAR_WORKFMINDEXI), + FM_FIX_FMMOMENTUM,buf,"",CHAR_getWorkInt(toindex,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(getfdFromCharaIndex(toindex))); + + sprintf( token, "۳ƣ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹƣ%d", tax, (iPrice - tax)); + + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif + + else if(lst==STREET_VENDOR_DP){ + CHAR_setInt(charaindex,CHAR_DUELPOINT,CHAR_getInt(charaindex,CHAR_DUELPOINT) - iPrice); + CHAR_setInt(toindex,CHAR_DUELPOINT,CHAR_getInt(toindex,CHAR_DUELPOINT) + (iPrice - tax)); + + CHAR_send_P_StatusString( charaindex ,CHAR_P_STRING_DUELPOINT ); + CHAR_send_P_StatusString( toindex ,CHAR_P_STRING_DUELPOINT ); + char szBuffer[64]; + + { + char szAdd[64], szNow[64]; + cnv10to62( iPrice, szAdd, sizeof( szAdd ) ); + cnv10to62( CHAR_getInt(charaindex,CHAR_DUELPOINT), szNow, sizeof( szNow ) ); + snprintf( szBuffer, sizeof( szBuffer ), + "%s|%s|", szAdd, szNow ); + } + + lssproto_RD_send( getfdFromCharaIndex(charaindex), szBuffer ); + + CHAR_send_DpDBUpdate( charaindex ); + +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( charaindex, TRUE ); +#endif + { + char szAdd[64], szNow[64]; + cnv10to62( iPrice, szAdd, sizeof( szAdd ) ); + cnv10to62( CHAR_getInt(toindex,CHAR_DUELPOINT), szNow, sizeof( szNow ) ); + snprintf( szBuffer, sizeof( szBuffer ), + "%s|%s|", szAdd, szNow ); + } + + lssproto_RD_send( getfdFromCharaIndex(toindex), szBuffer ); + + CHAR_send_DpDBUpdate( toindex ); + +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( toindex, TRUE ); +#endif + + sprintf( token, "۳ˣģУ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӸˣģУ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#ifdef _CAMEO_MONEY + else if(lst==STREET_VENDOR_CAMEO){ + CHAR_setInt(charaindex,CHAR_CAMEO,CHAR_getInt(charaindex,CHAR_CAMEO) - iPrice); + CHAR_setInt(toindex,CHAR_CAMEO,CHAR_getInt(toindex,CHAR_CAMEO) + (iPrice - tax)); + + sprintf( token, "۳ǣ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӱǣ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +*/ +#ifdef _ACTIVE_GAME + else if(lst==STREET_VENDOR_ACTIVE){ + CHAR_setInt(charaindex,CHAR_ACTIVE,CHAR_getInt(charaindex,CHAR_ACTIVE) - iPrice); + CHAR_setInt(toindex,CHAR_ACTIVE,CHAR_getInt(toindex,CHAR_ACTIVE) + (iPrice - tax)); + + sprintf( token, "۳%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӻ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +#ifdef _STREET_VENDOR_MYSQL + else if(lst==STREET_VENDOR_MYSQL){ + sasql_setVipPoint(charaindex, sasql_getVipPoint(charaindex) - iPrice); + sasql_setVipPoint(toindex, sasql_getVipPoint(toindex) + (iPrice - tax)); + + sprintf( token, "۳ң%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӽң%d", tax, (iPrice - tax)); + + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif + else{ + CHAR_talkToCli( charaindex, -1, "Ƿ̯Ŷ~", CHAR_COLORRED); + return; + } +#else + // Ǯ + CHAR_setInt(charaindex,CHAR_GOLD,CHAR_getInt(charaindex,CHAR_GOLD) - iPrice); + CHAR_send_P_StatusString(charaindex,CHAR_P_STRING_GOLD); + // Ǯ + if(bPutToBank) CHAR_setInt(toindex,CHAR_BANKGOLD,CHAR_getInt(toindex,CHAR_BANKGOLD) + iPrice); + else CHAR_setInt(toindex,CHAR_GOLD,CHAR_getInt(toindex,CHAR_GOLD) + iPrice); + CHAR_send_P_StatusString(toindex,CHAR_P_STRING_GOLD); +#endif + +#ifdef _FIRST_LOCK_ITEM + FreeFirstLockItem(charaindex, iItemIndex); +/* + { + int i; + for(i = 0; i < 32; i ++){ + if(ITEM_getInt(iItemIndex, ITEM_ID) == getFirstLockItem( i )){ + char *arg = ITEM_getChar(iItemIndex, ITEM_NAME); + if(arg[0] != '*'){ + char newname[256]; + sprintf(newname, "*%s", ITEM_getChar(iItemIndex, ITEM_NAME)); + ITEM_setChar(iItemIndex, ITEM_NAME, newname); + ITEM_setChar(iItemIndex, ITEM_SECRETNAME, newname); + break; + } + } + } + } +*/ +#endif + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(charaindex, FALSE)){ + CHAR_talkToCli(charaindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } + if(CHAR_charSaveFromConnect(toindex, FALSE)){ + CHAR_talkToCli(toindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + sprintf(szMsg," %s ",ITEM_getChar(iItemIndex,ITEM_NAME)); + CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORWHITE); + sprintf(szMsg,"%s ˵ %s",CHAR_getUseName(charaindex),ITEM_getChar(iItemIndex,ITEM_NAME)); + CHAR_talkToCli(toindex,-1,szMsg,CHAR_COLORWHITE); + +#ifdef _NEW_STREET_VENDOR +{ + char tmp[256]; + sprintf(tmp, "()[%s]", streetvendor[lst]); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + tmp, + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); +} +#else + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + ITEM_getChar(iItemIndex,ITEM_NAME), + -1, + iPrice, + "StreetVendor()", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(iItemIndex,ITEM_UNIQUECODE) + ); +#endif + } + else CHAR_talkToCli(charaindex,-1,"϶ѵ޲㡣",CHAR_COLORRED); + } + // dz + else if(iKind == 1){ +#ifdef _STREET_VENDOR_TRANS + if(CHAR_getInt(charaindex,CHAR_TRANSMIGRATION) < getStreetVendorTrans()){ + char buf[256]; + sprintf( buf, "ֻ%dתϲſԹ̯Ʒ", getStreetVendorTrans()); + CHAR_talkToCli(charaindex,-1,buf,CHAR_COLORYELLOW); + return; + } +#endif + int iEmptyPetField; + + iPetIndex = CHAR_getCharPet(toindex,iFieldIndex); + // ﲻ + if(!CHAR_CHECKINDEX(iPetIndex)){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + printf("\nCHAR_sendStreetVendor(B):Ҳ!!!!!!!\n"); + continue; + } + + if(FreeStreetVendorPet(charaindex, iPetIndex) == 1){ + CHAR_clearStreetVendor(toindex,iBuyIndex); + continue; + } +#ifdef _LOCK_PET_ITEM +{ + char *petname = CHAR_getChar( iPetIndex, CHAR_NAME); + if( petname[0] == '*' ){ + CHAR_talkToCli( charaindex, -1, "󶨳޷ѡȡ", CHAR_COLORYELLOW); + CHAR_clearStreetVendor(toindex,iBuyIndex); + continue; + } +} +#endif + if(CHAR_getInt(iPetIndex,CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(charaindex,-1,"ػ޷ѡȡ",CHAR_COLORYELLOW); + CHAR_clearStreetVendor(toindex,iBuyIndex); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + "", + "", + CHAR_getChar(iPetIndex,CHAR_NAME), + -1, + iPrice, + "StreetVendor(ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + -1,-1,-1, + CHAR_getChar(iPetIndex,CHAR_UNIQUECODE) + ); + continue; + } + if(CHAR_getInt(toindex,CHAR_RIDEPET) == CHAR_getStreetVendor(toindex,iBuyIndex,SV_INDEX)){ + CHAR_talkToCli(charaindex,-1,"еij޷ѡȡ",CHAR_COLORYELLOW); + CHAR_clearStreetVendor(toindex,iBuyIndex); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + "", + "", + CHAR_getChar(iPetIndex,CHAR_NAME), + -1, + iPrice, + "StreetVendor(ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + -1,-1,-1, + CHAR_getChar(iPetIndex,CHAR_UNIQUECODE) + ); + continue; + } + + // Ʒ + if(iPrice <= 0){ + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + CHAR_getChar(iPetIndex,CHAR_NAME), + -1, + iPrice, + "StreetVendor(򷽸ķ)", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + CHAR_getChar(iPetIndex,CHAR_UNIQUECODE) + ); + continue; + } + // װѱ޽ָ,ûת + if(CHAR_getWorkInt(charaindex,CHAR_PickAllPet) == FALSE && CHAR_getInt(charaindex,CHAR_TRANSMIGRATION) < 1){ + // ҵȼûбȳ + if(CHAR_getInt(iPetIndex,CHAR_LV) > (CHAR_getInt(charaindex,CHAR_LV) + 20)){ + CHAR_talkToCli(charaindex,-1,"޷չ˸ó",CHAR_COLORRED); + continue; + } + } + // dzサ + iEmptyPetField = CHAR_getCharPetElement(charaindex); + // пλ + if(iEmptyPetField > -1){ + // + CHAR_setCharPet(toindex,iFieldIndex,-1); + CHAR_clearStreetVendor(toindex,iBuyIndex); + sprintf(szMsg,"K%d",iFieldIndex); + CHAR_sendStatusString(toindex,szMsg); + // 趨 +#ifdef _FIRST_LOCK_ITEM + FreeFirstLockPet(charaindex, iPetIndex); +#endif + CHAR_setCharPet(charaindex,iEmptyPetField,iPetIndex); + CHAR_setWorkInt(iPetIndex,CHAR_WORKPLAYERINDEX,charaindex); + CHAR_setChar(iPetIndex,CHAR_OWNERCDKEY,CHAR_getChar(charaindex,CHAR_CDKEY)); + CHAR_setChar(iPetIndex,CHAR_OWNERCHARANAME,CHAR_getChar(charaindex,CHAR_NAME)); + CHAR_complianceParameter(iPetIndex); + sprintf(szMsg,"K%d",iEmptyPetField); + CHAR_sendStatusString(charaindex,szMsg); + sprintf(szMsg,"W%d",iEmptyPetField); + CHAR_sendStatusString(charaindex,szMsg); +#ifdef _NEW_STREET_VENDOR + int lst = CHAR_getWorkInt(toindex, CHAR_WORKSTREETVENDORTYPE); + char token[128]; + int tax; + if(getStreetVendor(lst) > 0){ + tax = max((iPrice * getStreetVendor(lst) / 100), 1); + }else{ + tax = 0; + } + + if(lst==STREET_VENDOR_GOLD){ + // Ǯ + CHAR_setInt(charaindex,CHAR_GOLD,CHAR_getInt(charaindex,CHAR_GOLD) - iPrice); + CHAR_send_P_StatusString(charaindex,CHAR_P_STRING_GOLD); + // Ǯ + if(bPutToBank) CHAR_setInt(toindex,CHAR_BANKGOLD,CHAR_getInt(toindex,CHAR_BANKGOLD) + (iPrice - tax)); + else CHAR_setInt(toindex,CHAR_GOLD,CHAR_getInt(toindex,CHAR_GOLD) + (iPrice - tax)); + CHAR_send_P_StatusString(toindex,CHAR_P_STRING_GOLD); + }else if(lst==STREET_VENDOR_FAME){ + CHAR_setInt(charaindex,CHAR_FAME,CHAR_getInt(charaindex,CHAR_FAME) - iPrice * 100); + int maxfame = (iPrice - tax) * 100; + if(maxfame > MAX_PERSONALFAME)maxfame = MAX_PERSONALFAME; + CHAR_setInt(toindex,CHAR_FAME,CHAR_getInt(toindex,CHAR_FAME) + maxfame); + + sprintf( token, "۳%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#ifndef _VERSION_NEW + else if(lst==STREET_VENDOR_AMPOINT){ + CHAR_setInt(charaindex,CHAR_AMPOINT,CHAR_getInt(charaindex,CHAR_AMPOINT) - iPrice); + CHAR_setInt(toindex,CHAR_AMPOINT,CHAR_getInt(toindex,CHAR_AMPOINT) + (iPrice - tax)); +#ifdef _AMPOINT_LOG + if(iPrice>0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -iPrice, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(̯)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } + + if((iPrice - tax)>0){ + LogAmPoint(CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + (iPrice - tax), + CHAR_getInt( toindex, CHAR_AMPOINT ), + "(̯)", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y )); + } +#endif + sprintf( token, "۳˻֣%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹ˻֣%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +/* +#ifdef _NEW_MANOR_LAW + else if(lst==STREET_VENDOR_MOMENTUM){ + CHAR_setInt(charaindex,CHAR_MOMENTUM,CHAR_getInt(charaindex,CHAR_MOMENTUM) - iPrice*100); + CHAR_setInt(toindex,CHAR_MOMENTUM,CHAR_getInt(toindex,CHAR_MOMENTUM) + (iPrice - tax)*100); + char buf[64]; + sprintf(buf,"%d", CHAR_getInt(charaindex,CHAR_MOMENTUM)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(charaindex,CHAR_FMNAME),CHAR_getInt(charaindex,CHAR_FMINDEX),CHAR_getWorkInt(charaindex,CHAR_WORKFMINDEXI), + FM_FIX_FMMOMENTUM,buf,"",CHAR_getWorkInt(charaindex,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(getfdFromCharaIndex(charaindex))); + + sprintf(buf,"%d", CHAR_getInt(toindex,CHAR_MOMENTUM)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(toindex,CHAR_FMNAME),CHAR_getInt(toindex,CHAR_FMINDEX),CHAR_getWorkInt(toindex,CHAR_WORKFMINDEXI), + FM_FIX_FMMOMENTUM,buf,"",CHAR_getWorkInt(toindex,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(getfdFromCharaIndex(toindex))); + + sprintf( token, "۳ƣ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, Ӹƣ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif + + else if(lst==STREET_VENDOR_DP){ + CHAR_setInt(charaindex,CHAR_DUELPOINT,CHAR_getInt(charaindex,CHAR_DUELPOINT) - iPrice); + CHAR_setInt(toindex,CHAR_DUELPOINT,CHAR_getInt(toindex,CHAR_DUELPOINT) + (iPrice - tax)); + + CHAR_send_P_StatusString( charaindex ,CHAR_P_STRING_DUELPOINT ); + CHAR_send_P_StatusString( toindex ,CHAR_P_STRING_DUELPOINT ); + char szBuffer[64]; + + { + char szAdd[64], szNow[64]; + cnv10to62( iPrice, szAdd, sizeof( szAdd ) ); + cnv10to62( CHAR_getInt(charaindex,CHAR_DUELPOINT), szNow, sizeof( szNow ) ); + snprintf( szBuffer, sizeof( szBuffer ), + "%s|%s|", szAdd, szNow ); + } + + lssproto_RD_send( getfdFromCharaIndex(charaindex), szBuffer ); + + CHAR_send_DpDBUpdate( charaindex ); + +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( charaindex, TRUE ); +#endif + { + char szAdd[64], szNow[64]; + cnv10to62( iPrice, szAdd, sizeof( szAdd ) ); + cnv10to62( CHAR_getInt(toindex,CHAR_DUELPOINT), szNow, sizeof( szNow ) ); + snprintf( szBuffer, sizeof( szBuffer ), + "%s|%s|", szAdd, szNow ); + } + + lssproto_RD_send( getfdFromCharaIndex(toindex), szBuffer ); + + CHAR_send_DpDBUpdate( toindex ); + +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( toindex, TRUE ); +#endif + + sprintf( token, "۳ˣģУ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӸˣģУ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#ifdef _CAMEO_MONEY + else if(lst==STREET_VENDOR_CAMEO){ + CHAR_setInt(charaindex,CHAR_CAMEO,CHAR_getInt(charaindex,CHAR_CAMEO) - iPrice); + CHAR_setInt(toindex,CHAR_CAMEO,CHAR_getInt(toindex,CHAR_CAMEO) + (iPrice - tax)); + + sprintf( token, "۳ǣ%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӱǣ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +*/ +#ifdef _ACTIVE_GAME + else if(lst==STREET_VENDOR_ACTIVE){ + CHAR_setInt(charaindex,CHAR_ACTIVE,CHAR_getInt(charaindex,CHAR_ACTIVE) - iPrice); + CHAR_setInt(toindex,CHAR_ACTIVE,CHAR_getInt(toindex,CHAR_ACTIVE) + (iPrice - tax)); + + sprintf( token, "۳%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӻ%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif +#ifdef _STREET_VENDOR_MYSQL + else if(lst==STREET_VENDOR_MYSQL){ + sasql_setVipPoint(charaindex, sasql_getVipPoint(charaindex) - iPrice); + sasql_setVipPoint(toindex, sasql_getVipPoint(toindex) + (iPrice - tax)); + + sprintf( token, "۳ң%d", iPrice); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + sprintf( token, "˰գ%d, ӽң%d", tax, (iPrice - tax)); + CHAR_talkToCli(toindex,-1,token,CHAR_COLORRED); + } +#endif + else{ + CHAR_talkToCli( charaindex, -1, "Ƿ̯Ŷ~", CHAR_COLORRED); + return; + } +#else + // Ǯ + CHAR_setInt(charaindex,CHAR_GOLD,CHAR_getInt(charaindex,CHAR_GOLD) - iPrice); + CHAR_send_P_StatusString(charaindex,CHAR_P_STRING_GOLD); + // Ǯ + if(bPutToBank) CHAR_setInt(toindex,CHAR_BANKGOLD,CHAR_getInt(toindex,CHAR_BANKGOLD) + iPrice); + else CHAR_setInt(toindex,CHAR_GOLD,CHAR_getInt(toindex,CHAR_GOLD) + iPrice); +#endif + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(charaindex, FALSE)){ + CHAR_talkToCli(charaindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } + if(CHAR_charSaveFromConnect(toindex, FALSE)){ + CHAR_talkToCli(toindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + CHAR_send_P_StatusString(toindex,CHAR_P_STRING_GOLD); + sprintf(szMsg,"%s ˳ %s",CHAR_getUseName(charaindex),CHAR_getChar(iPetIndex,CHAR_NAME)); + CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORWHITE); + sprintf(szMsg," %s ɣ",CHAR_getChar(iPetIndex,CHAR_NAME)); + CHAR_talkToCli(toindex,-1,szMsg,CHAR_COLORWHITE); +#ifdef _NEW_STREET_VENDOR +{ + char tmp[256]; + sprintf(tmp, "()[%s]", streetvendor[lst]); + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + CHAR_getChar(iPetIndex,CHAR_NAME), + CHAR_getInt(iPetIndex,CHAR_LV), + iPrice, + tmp, + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + CHAR_getChar(iPetIndex,CHAR_UNIQUECODE) + ); +} +#else + LogStreetVendor( + CHAR_getUseName(toindex), + CHAR_getUseID(toindex), + CHAR_getUseName(charaindex), + CHAR_getUseID(charaindex), + CHAR_getChar(iPetIndex,CHAR_NAME), + CHAR_getInt(iPetIndex,CHAR_LV), + iPrice, + "StreetVendor()", + CHAR_getInt(toindex,CHAR_FLOOR), + CHAR_getInt(toindex,CHAR_X), + CHAR_getInt(toindex,CHAR_Y), + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + CHAR_getChar(iPetIndex,CHAR_UNIQUECODE) + ); +#endif + } + // ҳλ + else CHAR_talkToCli(charaindex,-1,"ϳλ㣡",CHAR_COLORRED); + } + // + else{ + CHAR_clearStreetVendor(toindex,iBuyIndex); + printf("\nCHAR_sendStreetVendor(B):!!!!!!!\n"); + } + } + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD ); + // 趨Ϊ̯,״̬ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,1); + // ͼʾ + CHAR_sendTradeEffect(charaindex,0); + CHAR_sendTradeEffect(toindex,0); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO,-1); + } + else printf("StreetVendorҲԷ(%s)\n",CHAR_getChar(charaindex,CHAR_NAME)); + } +} + +void CHAR_sendStreetVendorDataToCli(int charaindex,int toindex) +{ + int i,count = 0; + + // ͷݸԼ,Ҫ޸ķ + if(charaindex == toindex){ + char szMsg[512],szTemp[512],szTemp1[16]; + + memset(szTemp,0,sizeof(szTemp)); + for(i=0;i 0){ + sprintf( szName, "%s %s+%d", CHAR_getChar(itempetindex,CHAR_NAME),str[type], value); + }else{ + sprintf(szName,"%s",CHAR_getChar(itempetindex,CHAR_NAME)); + } +} +#else +#ifdef _PET_BEATITUDE + if(CHAR_getInt(itempetindex,CHAR_BEATITUDE) != 0){ + sprintf(szName,"%s",CHAR_getChar(itempetindex,CHAR_NAME)); + }else +#endif + sprintf(szName,"%s",CHAR_getChar(itempetindex,CHAR_NAME)); +#endif + + sprintf(szFreeName,"%s",CHAR_getChar(itempetindex,CHAR_USERPETNAME)); + } + // + else{ + CHAR_clearStreetVendor(toindex,i); + printf("\nCHAR_sendStreetVendorDataToCli():!!!!!!!\n"); + continue; + } + if(firstindex == -1) firstindex = i; + + sprintf(szTemp1,"%d|%d|%s|%s|%d|",kind,CHAR_getStreetVendor(toindex,i,SV_PRICE),szName,szFreeName,i); + strcat(szTemp,szTemp1); + count++; + } + } + sprintf(szMsg,"B|%d|%s",count,szTemp); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(charaindex),szMsg); + if(firstindex == -1) firstindex = 0; + CHAR_sendStreetVendorOneDataToCli(charaindex,toindex,firstindex); + } +} + +void CHAR_sendStreetVendorOneDataToCli(int charaindex,int toindex,int sendindex) +{ + int kind,index,itempetindex,i,count = 0; + char szMsg[1024],szTemp[1000],szTemp1[512]; + + if(CHAR_getStreetVendor(toindex,sendindex,SV_USAGE) == TRUE){ + kind = CHAR_getStreetVendor(toindex,sendindex,SV_KIND); + index = CHAR_getStreetVendor(toindex,sendindex,SV_INDEX); + + memset(szTemp,0,sizeof(szTemp)); + memset(szTemp1,0,sizeof(szTemp1)); + // ǵ + if(kind == 0){ + int crushe,maxcrushe,itemcolor; + + itempetindex = CHAR_getItemIndex(toindex,index); + if(ITEM_CHECKINDEX(itempetindex)){ + +#ifdef _STREET_VENDOR_EFFECT +{ + static struct ITEM_iteminfos + { + char* entryname; + int type; + }ITEM_iteminfo[]={ + {"", ITEM_MODIFYATTACK}, + {"", ITEM_MODIFYDEFENCE}, + {"", ITEM_MODIFYQUICK}, + {"HP", ITEM_MODIFYHP}, + {"MP", ITEM_MODIFYMP}, + {"", ITEM_MODIFYLUCK}, + {"", ITEM_MODIFYAVOID}, + {"", ITEM_CRITICAL}, + {"", ITEM_MODIFYCHARM}, + }; + + int armtype = ITEM_getInt( itempetindex, ITEM_TYPE ); + if( armtype == ITEM_FIST + || armtype == ITEM_AXE + || armtype == ITEM_CLUB + || armtype == ITEM_SPEAR + || armtype == ITEM_BOW + || armtype == ITEM_BOOMERANG + || armtype == ITEM_BOUNDTHROW + || armtype == ITEM_BREAKTHROW + || armtype == ITEM_SHIELD + || armtype == ITEM_HELM + || armtype == ITEM_ARMOUR + || armtype == ITEM_BRACELET + || armtype == ITEM_BRACELET + || armtype == ITEM_MUSIC + || armtype == ITEM_NECKLACE + || armtype == ITEM_RING + || armtype == ITEM_BELT + || armtype == ITEM_EARRING + || armtype == ITEM_NOSERING + || armtype == ITEM_AMULET +#ifdef _ITEM_EQUITSPACE + || armtype == ITEM_WBELT + || armtype == ITEM_WSHIELD + || armtype == ITEM_WSHOES +#endif +#ifdef _EQUIT_NEWGLOVE + || armtype == ITEM_WGLOVE +#endif +#ifdef _ALCHEMIST + || armtype == ITEM_ALCHEMIST +#endif +#ifdef _PET_ITEM + || armtype == ITEM_PET_HEAD + || armtype == ITEM_PET_TOOTH + || armtype == ITEM_PET_CLAW + || armtype == ITEM_PET_BREAST + || armtype == ITEM_PET_BACK + || armtype == ITEM_PET_WING + || armtype == ITEM_PET_FEET +#endif + ){ + // ˵ + sprintf(szTemp1,"%-56sʵ:",ITEM_getChar(itempetindex,ITEM_EFFECTSTRING)); + strcat(szTemp,szTemp1); + int i; + for( i = 0 ; i < arraysizeof( ITEM_iteminfo ); i ++ ){ + if(ITEM_getInt(itempetindex, ITEM_iteminfo[i].type)>0){ + sprintf(szTemp1,"%s+%d ", ITEM_iteminfo[i].entryname, ITEM_getInt(itempetindex,ITEM_iteminfo[i].type)); + strcat(szTemp,szTemp1); + }else if(ITEM_getInt(itempetindex, ITEM_iteminfo[i].type)<0){ + sprintf(szTemp1,"%s%d ", ITEM_iteminfo[i].entryname, ITEM_getInt(itempetindex,ITEM_iteminfo[i].type)); + strcat(szTemp,szTemp1); + } + } + strcat(szTemp,"|"); + }else{ + // ˵ + sprintf(szTemp1,"%s|",ITEM_getChar(itempetindex,ITEM_EFFECTSTRING)); + strcat(szTemp,szTemp1); + } +} +#else + // ˵ + sprintf(szTemp1,"%s|",ITEM_getChar(itempetindex,ITEM_EFFECTSTRING)); + strcat(szTemp,szTemp1); +#endif + + // ;ö + crushe = ITEM_getInt(itempetindex,ITEM_DAMAGECRUSHE); + maxcrushe = ITEM_getInt(itempetindex,ITEM_MAXDAMAGECRUSHE); + + if(crushe < 1) crushe = 1; + if(maxcrushe < 1) sprintf(szTemp1,"|"); + else{ + maxcrushe = maxcrushe/1000; + crushe = crushe/1000; + if(maxcrushe <= 0) maxcrushe = 1; + sprintf(szTemp1,"%d%%|",(int)((crushe*100)/maxcrushe)); + } + strcat(szTemp,szTemp1); + // ɫ + itemcolor = CHAR_COLORWHITE; +#ifndef _PET_AND_ITEM_UP + if(strlen(ITEM_getChar(itempetindex,ITEM_CDKEY)) != 0) itemcolor = CHAR_COLORGREEN; + else +#endif + if(ITEM_getInt(itempetindex,ITEM_MERGEFLG)) itemcolor = CHAR_COLORYELLOW; + sprintf(szTemp1,"%d|",itemcolor); + strcat(szTemp,szTemp1); + // ͼ + sprintf(szTemp1,"%d|",ITEM_getInt(itempetindex,ITEM_BASEIMAGENUMBER)); + strcat(szTemp,szTemp1); + } + // + + else{ + CHAR_clearStreetVendor(toindex,sendindex); + printf("\nCHAR_sendStreetVendorOneDataToCli():Ҳ!!!!!!!\n"); + return; + } + } + // + else if(kind == 1){ + int skillid,petskillindex; + + itempetindex = CHAR_getCharPet(toindex,index); + if(CHAR_CHECKINDEX(itempetindex)){ + // 輼 + for(i=0;i0)workhp = -1*(workhp); + getStringFromIndexWithDelim(CHAR_getChar(itempetindex,CHAR_VB),"|",2,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workatt = -1*(workatt); + getStringFromIndexWithDelim(CHAR_getChar(itempetindex,CHAR_VB),"|",3,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workdef = -1*(workdef); + getStringFromIndexWithDelim(CHAR_getChar(itempetindex,CHAR_VB),"|",4,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workdex = -1*(workdex); + } + // ȼ,Ѫ,,,,,ҳ϶ + sprintf(szTemp1,"%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|" +#ifdef _PETCOM_ + "%d|%d|%d|%d|%d|"//ԭȼ,ԭѪ,ԭ,ԭ,ԭ +#endif + , + CHAR_getInt(itempetindex,CHAR_LV), + workhp, + workatt, + workdef, + workdex, + CHAR_getInt(itempetindex,CHAR_EARTHAT), + CHAR_getInt(itempetindex,CHAR_WATERAT), + CHAR_getInt(itempetindex,CHAR_FIREAT), + CHAR_getInt(itempetindex,CHAR_WINDAT), + CHAR_getWorkInt(itempetindex,CHAR_WORKFIXAI), + CHAR_getInt(itempetindex,CHAR_TRANSMIGRATION), + CHAR_getInt(itempetindex,CHAR_BASEBASEIMAGENUMBER) +#ifdef _PETCOM_ + ,CHAR_getInt(itempetindex,CHAR_YLV), + CHAR_getInt(itempetindex,CHAR_YHP), + CHAR_getInt(itempetindex,CHAR_YATK), + CHAR_getInt(itempetindex,CHAR_YDEF), + CHAR_getInt(itempetindex,CHAR_YQUICK) +#endif + ); + +#else + // ȼ,Ѫ,,,,,ҳ϶ + sprintf(szTemp1,"%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|" +#ifdef _PETCOM_ + "%d|%d|%d|%d|%d|"//ԭȼ,ԭѪ,ԭ,ԭ,ԭ +#endif + , + CHAR_getInt(itempetindex,CHAR_LV), + CHAR_getWorkInt(itempetindex,CHAR_WORKMAXHP), + CHAR_getWorkInt(itempetindex,CHAR_WORKATTACKPOWER), + CHAR_getWorkInt(itempetindex,CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt(itempetindex,CHAR_WORKQUICK), + CHAR_getInt(itempetindex,CHAR_EARTHAT), + CHAR_getInt(itempetindex,CHAR_WATERAT), + CHAR_getInt(itempetindex,CHAR_FIREAT), + CHAR_getInt(itempetindex,CHAR_WINDAT), + CHAR_getWorkInt(itempetindex,CHAR_WORKFIXAI), + CHAR_getInt(itempetindex,CHAR_TRANSMIGRATION), + CHAR_getInt(itempetindex,CHAR_BASEBASEIMAGENUMBER) +#ifdef _PETCOM_ + ,CHAR_getInt(itempetindex,CHAR_YLV), + CHAR_getInt(itempetindex,CHAR_YHP), + CHAR_getInt(itempetindex,CHAR_YATK), + CHAR_getInt(itempetindex,CHAR_YDEF), + CHAR_getInt(itempetindex,CHAR_YQUICK) +#endif + ); + +#endif + strcat(szTemp,szTemp1); + +#ifdef _PET_VALIDITY + { + char token[256]; + if(CHAR_getInt ( itempetindex, CHAR_PETVALIDITY)==0){ + snprintf( token, sizeof( token ), "Ч" STATUSSENDDELIMITER); + }else if(CHAR_getInt ( itempetindex, CHAR_PETVALIDITY)>time(NULL)){ + time_t petvalidity = (time_t)CHAR_getInt(itempetindex, CHAR_PETVALIDITY); + struct tm *tm1 = localtime(&petvalidity); + + snprintf( token, sizeof( token ), "%04d-%02d-%02d|", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday); + }else{ + snprintf( token, sizeof( token ), "Ѿ" STATUSSENDDELIMITER); + } + + strcat( szTemp,token ); + } +#endif + +#ifdef _PET_ITEM + char token[512]=""; + int i; + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ) + strcat(token,ITEM_petmakeItemStatusString(itempetindex, i)); + strcat(szTemp,token); +#else +#ifdef _VERSION_NEW + char token[512]=""; + int i; + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + sprintf(token,"%d||||0|0|0||||0|0|"); + strcat(szTemp,token); + } +#endif +#endif + + + } + // Ҳ + else{ + CHAR_clearStreetVendor(toindex,sendindex); + printf("\nCHAR_sendStreetVendorOneDataToCli():Ҳ!!!!!!!\n"); + return; + } + } + sprintf(szMsg,"D|%d|%s",sendindex,szTemp); + lssproto_STREET_VENDOR_send(getfdFromCharaIndex(charaindex),szMsg); +// printf("\nCHAR_sendStreetVendorOneDataToCli():%s\n",szMsg); + } + else printf("\nCHAR_sendStreetVendorOneDataToCli():յ!!!!!!!\n"); +} +#endif + + +BOOL checkUnlawWarpFloor(int floor) // ֹһഫ͵ +{ + + if( floor == 887 // д + || floor == 117 // + || floor == 1042 || floor == 2032 || floor == 3032 + || floor == 4032 || floor == 5032 || floor == 6032 + || floor == 7032 || floor == 8032 || floor == 9032 // ׯ԰ս + || floor == 8015 || floor == 8027 + || floor == 8028 || floor == 8029 // ֮ + || floor == 154 || floor == 155 || floor == 156 || floor == 157 + || floor == 8519 || floor == 8520 + || floor == 8513 // +#ifdef _TIME_TICKET + || check_TimeTicketMap( floor) +#endif + ){ + return TRUE; + } +#ifdef _UNLAW_WARP_FLOOR + int i; + for(i=0;i<64;i++){ + if(floor == getUnlawwarpfloor(i)){ + return TRUE; + } + } +#endif + + return FALSE; +} + +#ifdef _JOBDAILY +int JobDailyEventCheck( int meindex, int talker, char *buff1); +BOOL JobDailyRuleCheck(int talker, char* buf); +DailyFileType dailyfile[MAXDAILYLIST]; +// +void CHAR_JobDaily(int charaindex,char *data) +{ + int nowflag[MAXMISSIONFLAG]; + int endflag[MAXMISSIONFLAG]; + int i,j=0; + char szMsg[16384]; + char szToken[1024]; + int evch; + char tmpbuf[50],tmpbuf1[50]; + + memset(nowflag,0,sizeof(nowflag)); + memset(endflag,0,sizeof(endflag)); + memset(szMsg,0,sizeof(szMsg)); + memset(tmpbuf,0,sizeof(tmpbuf)); + memset(tmpbuf1,0,sizeof(tmpbuf1)); + + if(strcmp(data,"dyedye")!=0){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + return; + } + + for(i=0;i<1000;i++) + { + if(dailyfile[i].jobid<=0) break; + + evch = JobDailyEventCheck( 0 , charaindex, dailyfile[i].rule ); + if(evch != -1){ + szToken[0] = '\0'; + if(strlen(dailyfile[i].explain)>=36){ + for(j=0;j 0 && strlen(CHAR_getChar(charaindex,CHAR_TEACHER_NAME)) > 0) bHasTeacher = TRUE; + // ǰû + CHAR_getCoordinationDir(CHAR_getInt(charaindex,CHAR_DIR),CHAR_getInt(charaindex,CHAR_X), CHAR_getInt(charaindex,CHAR_Y),1,&ix,&iy); + // ȡǰ + iPlayerNum = CHAR_getSameCoordinateObjects(objbuf,arraysizeof(objbuf),CHAR_getInt(charaindex,CHAR_FLOOR),ix,iy); + // û + if(iPlayerNum == 0){ + // еʦ,ʾʦ + if(bHasTeacher){ + // ac Ҫ + saacproto_ACCheckCharacterOnLine_send(acfd,charaindex,CHAR_getChar(charaindex,CHAR_TEACHER_ID), + CHAR_getChar(charaindex,CHAR_TEACHER_NAME), + R_F_TEACHER_SYSTEM); + } + // ûеʦ,ʾ˵ + else lssproto_TEACHER_SYSTEM_send(getfdFromCharaIndex(charaindex),"M|"); + } + // + else{ + // еʦ + if(bHasTeacher){ + // ȡԭĵʦٽµʦ + CHAR_talkToCli(charaindex,-1,"ȡԭĵʦΪĵʦ",CHAR_COLORRED); + } + else{ + int objindex,index; + char szFindName[256]; + + if(iPlayerNum == 1){ + // ѯǷҪԷĵʦ + objindex = objbuf[0]; + index = OBJECT_getIndex(objindex); + + if(OBJECT_getType(objindex) != OBJTYPE_CHARA) break; + if(CHAR_getInt(index,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) break; + if(index == charaindex) break; + // ԷǷΪԼѧ + if(strcmp(CHAR_getChar(index,CHAR_TEACHER_ID),CHAR_getChar(charaindex,CHAR_CDKEY)) == 0 && + strcmp(CHAR_getChar(index,CHAR_TEACHER_NAME),CHAR_getChar(charaindex,CHAR_NAME)) == 0){ + CHAR_talkToCli(charaindex,-1,"ԷΪѧ޷öԷΪĵʦ",CHAR_COLORRED); + break; + } + sprintf(szMsg,"C|%s|%d",CHAR_getChar(index,CHAR_NAME),index); + lssproto_TEACHER_SYSTEM_send(getfdFromCharaIndex(charaindex),szMsg); + } + // һ,ѯҪ˭ʦ + else{ + int iGetNum = 0; + char szBuf[1024]; + + memset(szBuf,0,sizeof(szBuf)); + for(i=0;i 0 && tickettime > nowtime+20 ) { + continue; + } + // ʱ޲20 + else if( tickettime < nowtime+20 && tickettime >= nowtime ) { + sprintf( msg, "ʱƱʣʱ%d롣", tickettime - nowtime); + CHAR_talkToCli( i, -1, msg, CHAR_COLORYELLOW); + } + + // ʱ + else if( tickettime < nowtime ) { +// int floor, x, y; + int totaltime; + char msg[1024]; + if( CHAR_getWorkInt( i, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE) { + CHAR_talkToCli( i, -1, "ʱѵллˡ", CHAR_COLORYELLOW); + if( CHAR_getWorkInt( i, CHAR_WORKTICKETTIMESTART) > 0 ) { + totaltime = nowtime - CHAR_getWorkInt( i, CHAR_WORKTICKETTIMESTART); + sprintf( msg, "볡ʱ%d%d롣", totaltime/60, totaltime%60); + CHAR_talkToCli( i, -1, msg, CHAR_COLORYELLOW); + } + CHAR_setWorkInt( i, CHAR_WORKTICKETTIME, 0); + CHAR_setWorkInt( i, CHAR_WORKTICKETTIMESTART, 0); + /* + if( CHAR_getElderPosition( CHAR_getInt( i, CHAR_LASTTALKELDER), &floor, &x, &y ) != TRUE ) { + CHAR_warpToSpecificPoint( i, 1006, 15, 15); + } + else { + CHAR_warpToSpecificPoint( i, floor, x, y); + } + */ + CHAR_warpToSpecificPoint( i, 7001, 41, 6); + } + else { + CHAR_talkToCli( i, -1, "ʱѵսʱ뿪", CHAR_COLORYELLOW); + // BATTLE_Exit() + } + } + } + +} +#endif + +int CharaData( int sockfd, Char* ch ){ + FILE *fp; + struct tm *pLtime; + char szFileName[256], *chardata; + char outbuff[CHARDATASIZE]; +// Char* ch; + int charaindex=CONNECT_getCharaindex(sockfd); +// print("\nе\n"); + + pLtime = localtime( &NowTime.tv_sec ); + + int hash, dir, j; + char charId[32]; + char pathname[128]; + +// strcpy( charId, CHAR_getChar( charaindex, CHAR_CDKEY ) ); + CONNECT_getCdkey( sockfd, charId, sizeof(charId)); + print("˺:%s", charId); + + hash = 0; + for( j=0; j NowTime.tv_sec){ + CHAR_talkToCli( charaindex, -1, "ǰʹúƵԺ...", CHAR_COLORRED); + return; + } + char data[128]; + sprintf(data,"%d",sasql_getVipPoint(charaindex)); + int fd = getfdFromCharaIndex( charaindex); + lssproto_WN_send(fd, 1024, 12, CHAR_WINDOWTYPE_REDMEMOY, -1, data); +} + +void CHAR_RedMemoy_Give(int charaindex,char *data) +{ + char szTemp[1024]; + if(RedTime < NowTime.tv_sec){ + CHAR_talkToCli( charaindex, -1, "ٶ̫ˣ....", CHAR_COLORRED); + return; + } + if(atoi(data)==Redkey){ + int i=0; + for(i;i NowTime.tv_sec){ + CHAR_talkToCli( charaindex, -1, "ǰʹúƵԺ...", CHAR_COLORRED); + return; + } + char szTemp[1024]; + int objtype,givtype,num,total,familyindex,poin; + if(!getStringFromIndexWithDelim(data,"|",1,szTemp,sizeof(szTemp))) return; + objtype = atoi(szTemp); + if(objtype<0 || objtype >2)return; + if(!getStringFromIndexWithDelim(data,"|",2,szTemp,sizeof(szTemp))) return; + givtype = atoi(szTemp); + if(givtype<0 || givtype >1)return; + if(!getStringFromIndexWithDelim(data,"|",3,szTemp,sizeof(szTemp))) return; + num = atoi(szTemp); + if(num<1 || num>99)return; + if(!getStringFromIndexWithDelim(data,"|",4,szTemp,sizeof(szTemp))) return; + total = atoi(szTemp); + if(total < num*10)return; + if (objtype == 2){ + if(total < num*100){ + CHAR_talkToCli( charaindex, -1, "űƽСΪ100", CHAR_COLORRED); + return; + } + } + if(objtype==0){ + familyindex = CHAR_getInt(charaindex,CHAR_FMINDEX); + if(familyindex < 0){ + CHAR_talkToCli( charaindex, -1, "δ壡", CHAR_COLORRED); + return; + } + } + poin = sasql_getVipPoint(charaindex); + if(poin >= total){ + sasql_setVipPoint(charaindex,poin-total); + sprintf(szTemp,"ϵͳ۳%d,ʣ%dң",total,poin-total); + CHAR_talkToCli( charaindex, -1, szTemp, CHAR_COLORRED); + RedMemoy_sendlog(charaindex,data); + if(objtype == 2){ + RedMoneyFunction(charaindex,data); + }else{ + memset(&charredmemoy,0,sizeof(struct REDMENOY_T)); + charredmemoy.ObjectType=objtype; + charredmemoy.GiveType=givtype; + charredmemoy.Num=num; + charredmemoy.Total=total; + memset(charredmemoy.index,-1,100*sizeof(int)); + charredmemoy.charaindex=charaindex; + sprintf(charredmemoy.name,"%s",CHAR_getChar(charaindex,CHAR_NAME)); + RedTime= NowTime.tv_sec+35; + Redkey = RAND(9999,100000); + int i=0; + for(i;i +#include +#include +#include // shan +#include +#include +#include +#include +#include "common.h" +#include "char_base.h" +#include "char_data.h" +#include "char.h" +#include "lssproto_serv.h" +#include "item.h" +#include "item_event.h" +#include "buf.h" +#include "object.h" +#include "map_deal.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "handletime.h" +#include "char_event.h" +#include "npccreate.h" +#include "addressbook.h" +#include "item_event.h" +#include "magic_base.h" +#include "magic.h" +#include "chatmagic.h" +#include "configfile.h" +#include "log.h" +#include "anim_tbl.h" +#include "encount.h" +#include "battle.h" +#include "pet_skill.h" +#include "util.h" +#include "enemy.h" +#include "npcutil.h" +#include "pet.h" +#include "family.h" + +struct MissionInfo missionlist[MAXMISSION]; +int mission_num =0; +struct MissionTable missiontable[MAXMISSIONTABLE]; + +//#define ANGELITEM 2884 //20701 //ʹߵ ߱ +//#define HEROITEM 2885 //20702 //ߵ ߱ + +extern int AngelReady; + +char* getMissionNameInfo( int charaindex, char* nameinfo) +{ + sprintf( nameinfo, "%s:%s", CHAR_getChar( charaindex, CHAR_CDKEY), CHAR_getChar( charaindex, CHAR_NAME) ); + return nameinfo; +} + +int checkIfAngel( int charaindex) +{ + int i; + char nameinfo[512]; + + //sprintf( nameinfo, "%s:%s", CHAR_getChar( charaindex, CHAR_CDKEY), CHAR_getChar( charaindex, CHAR_NAME) ); + getMissionNameInfo( charaindex, nameinfo); + for( i =0; i + +// CoolFish: 2001/10/12 _UNIQUE_P_I +#include +#include "net.h" +#include "autil.h" +#include "char_base.h" +#include "char_data.h" +#include "item.h" +#include "buf.h" +#include "magic.h" +#include "function.h" +#include "npccreate.h" +#include "configfile.h" +#include "title.h" +#include "pet.h" +#include "pet_skill.h" +#include "anim_tbl.h" +#include "enemy.h" +#include "saacproto_cli.h" +#include "family.h" +// CoolFish: 2001/10/29 +#include "log.h" +extern int CheckCharMaxItemChar(Char* ch); +Char* CHAR_chara; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static int CHAR_charanum; +static int CHAR_playernum; +static int CHAR_petnum; +static int CHAR_othersnum; + +// CoolFish: 2001/10/11 +#ifdef _UNIQUE_P_I +#define MAX_UNIQUE_P_I 1000 +static int unique_p = 0; +static int unique_i = 0; +#endif + +typedef struct tagINITCHARCOUNTER{ + int startcnt; + int cnt; + int endcnt; +}INITCHARCOUNTER; +static INITCHARCOUNTER initCharCounter[3] = { + {-1,-1,-1},{-1,-1,-1},{-1,-1,-1} +}; + + +tagRidePetTable ridePetTable[296] = +{ + { 101000, 100000, 100352, 331 }, + { 101001, 100005, 100352, 331 }, + { 101002, 100010, 100352, 331 }, + { 101003, 100015, 100352, 331 }, + { 101004, 100000, 100329, 309 }, + { 101005, 100005, 100327, 307 }, + { 101006, 100010, 100330, 310 }, + { 101007, 100015, 100328, 308 }, +// { 101008, 100700, 100372, 351 }, +// { 101009, 100705, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101000, 100700, 100352, 331 }, + { 101001, 100700, 100352, 331 }, + { 101002, 100700, 100352, 331 }, + { 101003, 100700, 100352, 331 }, + { 101004, 100700, 100329, 309 }, + { 101005, 100700, 100327, 307 }, + { 101006, 100700, 100330, 310 }, + { 101007, 100700, 100328, 308 }, + { 101000, 100705, 100352, 331 }, + { 101001, 100705, 100352, 331 }, + { 101002, 100705, 100352, 331 }, + { 101003, 100705, 100352, 331 }, + { 101004, 100705, 100329, 309 }, + { 101005, 100705, 100327, 307 }, + { 101006, 100705, 100330, 310 }, + { 101007, 100705, 100328, 308 }, +#endif + + { 101010, 100020, 100396, 483 }, + { 101011, 100025, 100396, 483 }, + { 101012, 100030, 100396, 483 }, + { 101013, 100035, 100396, 483 }, + { 101014, 100020, 100328, 308 }, + { 101015, 100025, 100329, 309 }, + { 101016, 100030, 100327, 307 }, + { 101017, 100035, 100330, 310 }, +// { 101018, 100710, 100372, 351 }, +// { 101019, 100715, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101010, 100710, 100396, 483 }, + { 101011, 100710, 100396, 483 }, + { 101012, 100710, 100396, 483 }, + { 101013, 100710, 100396, 483 }, + { 101014, 100710, 100328, 308 }, + { 101015, 100710, 100329, 309 }, + { 101016, 100710, 100327, 307 }, + { 101017, 100710, 100330, 310 }, + { 101010, 100715, 100396, 483 }, + { 101011, 100715, 100396, 483 }, + { 101012, 100715, 100396, 483 }, + { 101013, 100715, 100396, 483 }, + { 101014, 100715, 100328, 308 }, + { 101015, 100715, 100329, 309 }, + { 101016, 100715, 100327, 307 }, + { 101017, 100715, 100330, 310 }, +#endif + + { 101020, 100040, 100351, 330 }, + { 101021, 100045, 100351, 330 }, + { 101022, 100050, 100351, 330 }, + { 101023, 100055, 100351, 330 }, + { 101024, 100040, 100328, 308 }, + { 101025, 100045, 100330, 310 }, + { 101026, 100050, 100327, 307 }, + { 101027, 100055, 100329, 309 }, +// { 101028, 100720, 100372, 351 }, +// { 101029, 100725, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101020, 100720, 100351, 330 }, + { 101021, 100720, 100351, 330 }, + { 101022, 100720, 100351, 330 }, + { 101023, 100720, 100351, 330 }, + { 101024, 100720, 100328, 308 }, + { 101025, 100720, 100330, 310 }, + { 101026, 100720, 100327, 307 }, + { 101027, 100720, 100329, 309 }, + { 101020, 100725, 100351, 330 }, + { 101021, 100725, 100351, 330 }, + { 101022, 100725, 100351, 330 }, + { 101023, 100725, 100351, 330 }, + { 101024, 100725, 100328, 308 }, + { 101025, 100725, 100330, 310 }, + { 101026, 100725, 100327, 307 }, + { 101027, 100725, 100329, 309 }, +#endif + + { 101030, 100060, 100353, 332 }, + { 101031, 100065, 100353, 332 }, + { 101032, 100070, 100353, 332 }, + { 101033, 100075, 100353, 332 }, + { 101034, 100060, 100329, 309 }, + { 101035, 100065, 100327, 307 }, + { 101036, 100070, 100330, 310 }, + { 101037, 100075, 100328, 308 }, +// { 101038, 100730, 100372, 351 }, +// { 101039, 100735, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101030, 100730, 100353, 332 }, + { 101031, 100730, 100353, 332 }, + { 101032, 100730, 100353, 332 }, + { 101033, 100730, 100353, 332 }, + { 101034, 100730, 100329, 309 }, + { 101035, 100730, 100327, 307 }, + { 101036, 100730, 100330, 310 }, + { 101037, 100730, 100328, 308 }, + { 101030, 100735, 100353, 332 }, + { 101031, 100735, 100353, 332 }, + { 101032, 100735, 100353, 332 }, + { 101033, 100735, 100353, 332 }, + { 101034, 100735, 100329, 309 }, + { 101035, 100735, 100327, 307 }, + { 101036, 100735, 100330, 310 }, + { 101037, 100735, 100328, 308 }, +#endif + + { 101040, 100080, 100396, 483 }, + { 101041, 100085, 100396, 483 }, + { 101042, 100090, 100396, 483 }, + { 101043, 100095, 100396, 483 }, + { 101044, 100080, 100328, 308 }, + { 101045, 100085, 100327, 307 }, + { 101046, 100090, 100330, 310 }, + { 101047, 100095, 100329, 309 }, +// { 101048, 100740, 100372, 351 }, +// { 101049, 100745, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101040, 100740, 100396, 483 }, + { 101041, 100740, 100396, 483 }, + { 101042, 100740, 100396, 483 }, + { 101043, 100740, 100396, 483 }, + { 101044, 100740, 100328, 308 }, + { 101045, 100740, 100327, 307 }, + { 101046, 100740, 100330, 310 }, + { 101047, 100740, 100329, 309 }, + { 101040, 100745, 100396, 483 }, + { 101041, 100745, 100396, 483 }, + { 101042, 100745, 100396, 483 }, + { 101043, 100745, 100396, 483 }, + { 101044, 100745, 100328, 308 }, + { 101045, 100745, 100327, 307 }, + { 101046, 100745, 100330, 310 }, + { 101047, 100745, 100329, 309 }, +#endif + + { 101050, 100100, 100353, 332 }, + { 101051, 100105, 100353, 332 }, + { 101052, 100110, 100353, 332 }, + { 101053, 100115, 100353, 332 }, + { 101054, 100100, 100329, 309 }, + { 101055, 100105, 100328, 308 }, + { 101056, 100110, 100330, 310 }, + { 101057, 100115, 100327, 307 }, +// { 101058, 100750, 100372, 351 }, +// { 101059, 100755, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101050, 100750, 100353, 332 }, + { 101051, 100750, 100353, 332 }, + { 101052, 100750, 100353, 332 }, + { 101053, 100750, 100353, 332 }, + { 101054, 100750, 100329, 309 }, + { 101055, 100750, 100328, 308 }, + { 101056, 100750, 100330, 310 }, + { 101057, 100750, 100327, 307 }, + { 101050, 100755, 100353, 332 }, + { 101051, 100755, 100353, 332 }, + { 101052, 100755, 100353, 332 }, + { 101053, 100755, 100353, 332 }, + { 101054, 100755, 100329, 309 }, + { 101055, 100755, 100328, 308 }, + { 101056, 100755, 100330, 310 }, + { 101057, 100755, 100327, 307 }, +#endif + + { 101060, 100120, 100354, 333 }, + { 101061, 100125, 100354, 333 }, + { 101062, 100130, 100354, 333 }, + { 101063, 100135, 100354, 333 }, + { 101064, 100120, 100327, 307 }, + { 101065, 100125, 100330, 310 }, + { 101066, 100130, 100328, 308 }, + { 101067, 100135, 100329, 309 }, +// { 101068, 100760, 100372, 351 }, +// { 101069, 100765, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101060, 100760, 100354, 333 }, + { 101061, 100760, 100354, 333 }, + { 101062, 100760, 100354, 333 }, + { 101063, 100760, 100354, 333 }, + { 101064, 100760, 100327, 307 }, + { 101065, 100760, 100330, 310 }, + { 101066, 100760, 100328, 308 }, + { 101067, 100760, 100329, 309 }, + { 101060, 100765, 100354, 333 }, + { 101061, 100765, 100354, 333 }, + { 101062, 100765, 100354, 333 }, + { 101063, 100765, 100354, 333 }, + { 101064, 100765, 100327, 307 }, + { 101065, 100765, 100330, 310 }, + { 101066, 100765, 100328, 308 }, + { 101067, 100765, 100329, 309 }, +#endif + + { 101070, 100140, 100354, 333 }, + { 101071, 100145, 100354, 333 }, + { 101072, 100150, 100354, 333 }, + { 101073, 100155, 100354, 333 }, + { 101074, 100140, 100327, 307 }, + { 101075, 100145, 100329, 309 }, + { 101076, 100150, 100330, 310 }, + { 101077, 100155, 100328, 308 }, +// { 101078, 100770, 100372, 351 }, +// { 101079, 100775, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101070, 100770, 100354, 333 }, + { 101071, 100770, 100354, 333 }, + { 101072, 100770, 100354, 333 }, + { 101073, 100770, 100354, 333 }, + { 101074, 100770, 100327, 307 }, + { 101075, 100770, 100329, 309 }, + { 101076, 100770, 100330, 310 }, + { 101077, 100770, 100328, 308 }, + { 101070, 100775, 100354, 333 }, + { 101071, 100775, 100354, 333 }, + { 101072, 100775, 100354, 333 }, + { 101073, 100775, 100354, 333 }, + { 101074, 100775, 100327, 307 }, + { 101075, 100775, 100329, 309 }, + { 101076, 100775, 100330, 310 }, + { 101077, 100775, 100328, 308 }, +#endif + + { 101080, 100160, 100352, 331 }, + { 101081, 100165, 100352, 331 }, + { 101082, 100170, 100352, 331 }, + { 101083, 100175, 100352, 331 }, + { 101084, 100160, 100330, 310 }, + { 101085, 100165, 100329, 309 }, + { 101086, 100170, 100327, 307 }, + { 101087, 100175, 100328, 308 }, +// { 101088, 100780, 100372, 351 }, +// { 101089, 100785, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101080, 100780, 100352, 331 }, + { 101081, 100780, 100352, 331 }, + { 101082, 100780, 100352, 331 }, + { 101083, 100780, 100352, 331 }, + { 101087, 100780, 100328, 308 }, + { 101086, 100780, 100327, 307 }, + { 101084, 100780, 100330, 310 }, + { 101085, 100780, 100329, 309 }, + { 101080, 100785, 100352, 331 }, + { 101081, 100785, 100352, 331 }, + { 101082, 100785, 100352, 331 }, + { 101083, 100785, 100352, 331 }, + { 101084, 100785, 100330, 310 }, + { 101085, 100785, 100329, 309 }, + { 101086, 100785, 100327, 307 }, + { 101087, 100785, 100328, 308 }, +#endif + + { 101090, 100180, 100351, 330 }, + { 101091, 100185, 100351, 330 }, + { 101092, 100190, 100351, 330 }, + { 101093, 100195, 100351, 330 }, + { 101094, 100180, 100328, 308 }, + { 101095, 100185, 100330, 310 }, + { 101096, 100190, 100329, 309 }, + { 101097, 100195, 100327, 307 }, +// { 101098, 100790, 100372, 351 }, +// { 101099, 100795, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101090, 100790, 100351, 330 }, + { 101091, 100790, 100351, 330 }, + { 101092, 100790, 100351, 330 }, + { 101093, 100790, 100351, 330 }, + { 101094, 100790, 100328, 308 }, + { 101095, 100790, 100330, 310 }, + { 101096, 100790, 100329, 309 }, + { 101097, 100790, 100327, 307 }, + { 101090, 100795, 100351, 330 }, + { 101091, 100795, 100351, 330 }, + { 101092, 100795, 100351, 330 }, + { 101093, 100795, 100351, 330 }, + { 101094, 100795, 100328, 308 }, + { 101095, 100795, 100330, 310 }, + { 101096, 100795, 100329, 309 }, + { 101097, 100795, 100327, 307 }, +#endif + + { 101100, 100200, 100353, 332 }, + { 101101, 100205, 100353, 332 }, + { 101102, 100210, 100353, 332 }, + { 101103, 100215, 100353, 332 }, + { 101104, 100200, 100329, 309 }, + { 101105, 100205, 100328, 308 }, + { 101106, 100210, 100327, 307 }, + { 101107, 100215, 100330, 310 }, +// { 101108, 100800, 100372, 351 }, +// { 101109, 100805, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101100, 100800, 100353, 332 }, + { 101101, 100800, 100353, 332 }, + { 101102, 100800, 100353, 332 }, + { 101103, 100800, 100353, 332 }, + { 101104, 100800, 100329, 309 }, + { 101105, 100800, 100328, 308 }, + { 101106, 100800, 100327, 307 }, + { 101107, 100800, 100330, 310 }, + { 101100, 100805, 100353, 332 }, + { 101101, 100805, 100353, 332 }, + { 101102, 100805, 100353, 332 }, + { 101103, 100805, 100353, 332 }, + { 101104, 100805, 100329, 309 }, + { 101105, 100805, 100328, 308 }, + { 101106, 100805, 100327, 307 }, + { 101107, 100805, 100330, 310 }, +#endif + + { 101110, 100220, 100396, 483 }, + { 101111, 100225, 100396, 483 }, + { 101112, 100230, 100396, 483 }, + { 101113, 100235, 100396, 483 }, + { 101114, 100220, 100330, 310 }, + { 101115, 100225, 100327, 307 }, + { 101116, 100230, 100329, 309 }, + { 101117, 100235, 100328, 308 }, +// { 101118, 100810, 100372, 351 }, +// { 101119, 100815, 100373, 352 }, +#ifdef _GM_METAMO_RIDE + { 101110, 100810, 100396, 483 }, + { 101111, 100810, 100396, 483 }, + { 101112, 100810, 100396, 483 }, + { 101113, 100810, 100396, 483 }, + { 101114, 100810, 100330, 310 }, + { 101115, 100810, 100327, 307 }, + { 101116, 100810, 100329, 309 }, + { 101117, 100810, 100328, 308 }, + { 101110, 100815, 100396, 483 }, + { 101111, 100815, 100396, 483 }, + { 101112, 100815, 100396, 483 }, + { 101113, 100815, 100396, 483 }, + { 101114, 100815, 100330, 310 }, + { 101115, 100815, 100327, 307 }, + { 101116, 100815, 100329, 309 }, + { 101117, 100815, 100328, 308 }, +#endif + + { 101179, 101177, 101178, 1804}, + { 101179, 101178, 101177, 1926}, + +//#ifndef _RIDEMODE_20 +#ifndef _GM_METAMO_RIDE + { 100420, 100710, 100369, 348 }, + { 100425, 100710, 100370, 349 }, + { 100445, 100710, 100904, 1642 }, + + { 100420, 100715, 100369, 348 }, + { 100425, 100715, 100370, 349 }, + { 100445, 100715, 100904, 1642 }, +#endif +//#endif +}; + +#ifdef _FM_LEADER_RIDE +tagFmLeaderRide FmLeaderRide[] = { + { 1041, {-1, -1, -1 }}, + { 2031, {-1, -1, -1 }}, + { 3031, {-1, -1, -1 }}, + { 4031, {-1, -1, -1 }}, + { 5031, {-1, -1, -1 }}, + { 6031, {-1, -1, -1 }}, + { 7031, {-1, -1, -1 }}, + { 8031, {-1, -1, -1 }}, + { 9031, {-1, -1, -1 }}, + { 10031, {-1, -1, -1 }} +}; +#endif + +#ifdef _NEW_RIDEPETS +#ifdef _RIDE_CF +#ifdef _ADD_RIDE_CF +tagRideCodeMode RideCodeMode[] = { + { 100374, -1, -1, RIDE_PET0 }, /**/ + { 100358, -1, -1, RIDE_PET1 }, /*Ħ˹*/ + { 100362, -1, -1, RIDE_PET2 }, /*˹*/ + { 100279, -1, -1, RIDE_PET3 }, /*³*/ + { 100288, -1, -1, RIDE_PET4 }, /*˹*/ + { 100283, -1, -1, RIDE_PET5 }, /*迨³˹*/ + { 100346, -1, -1, RIDE_PET6 }, /*迨*/ + { 100310, -1, -1, RIDE_PET7 }, /**/ + { 100372, -1, -1, RIDE_PET8 }, /*˹*/ + { 100373, -1, -1, RIDE_PET9 }, /*Ͷ*/ + { 101532, -1, -1, RIDE_PET10 }, /*ʷ³*/ + { 101576, -1, -1, RIDE_PET11 }, /*޶*/ + { 100370, -1, -1, RIDE_PET12 }, /*汦*/ + { 100369, -1, -1, RIDE_PET13 }, /**/ + { 100904, -1, -1, RIDE_PET14 }, /**/ + { -1, -1, -1, RIDE_PET15 }, + { -1, -1, -1, RIDE_PET16 }, + { -1, -1, -1, RIDE_PET17 }, + { -1, -1, -1, RIDE_PET18 }, + { -1, -1, -1, RIDE_PET19 }, + { -1, -1, -1, RIDE_PET20 }, + { -1, -1, -1, RIDE_PET21 }, + { -1, -1, -1, RIDE_PET22 }, + { -1, -1, -1, RIDE_PET23 }, + { -1, -1, -1, RIDE_PET24 }, + { -1, -1, -1, RIDE_PET25 }, + { -1, -1, -1, RIDE_PET26 }, + { -1, -1, -1, RIDE_PET27 }, + { -1, -1, -1, RIDE_PET28 }, + { -1, -1, -1, RIDE_PET29 }, + { -1, -1, -1, RIDE_PET30 }, + { -1, -1, -1, RIDE_PET31 } +}; +#else +tagRideCodeMode RideCodeMode[] = { + { 100374, -1, RIDE_PET0 }, /**/ + { 100358, -1, RIDE_PET1 }, /*Ħ˹*/ + { 100362, -1, RIDE_PET2 }, /*˹*/ + { 100279, -1, RIDE_PET3 }, /*³*/ + { 100288, -1, RIDE_PET4 }, /*˹*/ + { 100283, -1, RIDE_PET5 }, /*迨³˹*/ + { 100346, -1, RIDE_PET6 }, /*迨*/ + { 100310, -1, RIDE_PET7 }, /**/ + { 100372, -1, RIDE_PET8 }, /*˹*/ + { 100373, -1, RIDE_PET9 }, /*Ͷ*/ + { 101532, -1, RIDE_PET10 }, /*ʷ³*/ + { 101576, -1, RIDE_PET11 }, /*޶*/ + { 100370, -1, RIDE_PET12 }, /*汦*/ + { 100369, -1, RIDE_PET13 }, /**/ + { 100904, -1, RIDE_PET14 }, /**/ + { -1, -1, RIDE_PET15 }, + { -1, -1, RIDE_PET16 }, + { -1, -1, RIDE_PET17 }, + { -1, -1, RIDE_PET18 }, + { -1, -1, RIDE_PET19 }, + { -1, -1, RIDE_PET20 }, + { -1, -1, RIDE_PET21 }, + { -1, -1, RIDE_PET22 }, + { -1, -1, RIDE_PET23 }, + { -1, -1, RIDE_PET24 }, + { -1, -1, RIDE_PET25 }, + { -1, -1, RIDE_PET26 }, + { -1, -1, RIDE_PET27 }, + { -1, -1, RIDE_PET28 }, + { -1, -1, RIDE_PET29 }, + { -1, -1, RIDE_PET30 }, + { -1, -1, RIDE_PET31 } +}; +#endif +#else +tagRideCodeMode RideCodeMode[] = { + { 100374, RIDE_PET0 }, /**/ + { 100358, RIDE_PET1 }, /*Ħ˹*/ + { 100362, RIDE_PET2 }, /*˹*/ + { 100279, RIDE_PET3 }, /*³*/ + { 100288, RIDE_PET4 }, /*˹*/ + { 100283, RIDE_PET5 }, /*迨³˹*/ + { 100346, RIDE_PET6 }, /*迨*/ + { 100310, RIDE_PET7 }, /**/ + { 100372, RIDE_PET8 }, /*˹*/ + { 100373, RIDE_PET9 }, /*Ͷ*/ + { 101532, RIDE_PET10 }, /*ʷ³*/ + { 101576, RIDE_PET11 }, /*޶*/ + { 100370, RIDE_PET12 }, /*汦*/ + { 100369, RIDE_PET13 }, /**/ + { 100904, RIDE_PET14 }, /**/ +}; +#endif +#ifdef _RIDE_CF +#ifdef _ADD_RIDE_CF +tagRideNoList RideNoList[] = { + {{ 101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009, 101978, 101989,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //С + {{ 101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019, 101986, 101988,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029, 101975, 101965,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //к + {{ 101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039, 101976, 101966,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049, 101984, 101973,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ƥ + {{ 101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059, 101985, 101974,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069, 101977, 101967,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //С + {{ 101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079, 101979, 101968,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ƥ + {{ 101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089, 101981, 101970,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //ñ + {{ 101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099, 101980, 101969,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //̷ + {{ 101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109, 101983, 101972,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ů + {{ 101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119, 101982, 101971,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // +}; +#else +tagRideNoList RideNoList[] = { + {{ 101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009, 101978, 101989,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //С + {{ 101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019, 101986, 101988,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029, 101975, 101965,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //к + {{ 101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039, 101976, 101966,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049, 101984, 101973,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ƥ + {{ 101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059, 101985, 101974,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // + {{ 101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069, 101977, 101967,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //С + {{ 101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079, 101979, 101968,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ƥ + {{ 101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089, 101981, 101970,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //ñ + {{ 101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099, 101980, 101969,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //̷ + {{ 101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109, 101983, 101972,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, //Ů + {{ 101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119, 101982, 101971,100425,100420,100445,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},0}, // +}; +#endif +#else +tagRideNoList RideNoList[] = { + {{ 101305, 101306, 101307, 101308, 101309, 101310, 101311, 101312, 101008, 101009, 101978, 101989,100425,100420,100445},0}, //С + {{ 101313, 101314, 101315, 101316, 101317, 101318, 101319, 101320, 101018, 101019, 101986, 101988,100425,100420,100445},0}, // + {{ 101321, 101322, 101323, 101324, 101325, 101326, 101327, 101328, 101028, 101029, 101975, 101965,100425,100420,100445},0}, //к + {{ 101329, 101330, 101331, 101332, 101333, 101334, 101335, 101336, 101038, 101039, 101976, 101966,100425,100420,100445},0}, // + {{ 101337, 101338, 101339, 101340, 101341, 101342, 101343, 101344, 101048, 101049, 101984, 101973,100425,100420,100445},0}, //Ƥ + {{ 101345, 101346, 101347, 101348, 101349, 101350, 101351, 101352, 101058, 101059, 101985, 101974,100425,100420,100445},0}, // + {{ 101353, 101354, 101355, 101356, 101357, 101358, 101359, 101360, 101068, 101069, 101977, 101967,100425,100420,100445},0}, //С + {{ 101361, 101362, 101363, 101364, 101365, 101366, 101367, 101368, 101078, 101079, 101979, 101968,100425,100420,100445},0}, //Ƥ + {{ 101369, 101370, 101371, 101372, 101373, 101374, 101375, 101376, 101088, 101089, 101981, 101970,100425,100420,100445},0}, //ñ + {{ 101377, 101378, 101379, 101380, 101381, 101382, 101383, 101384, 101098, 101099, 101980, 101969,100425,100420,100445},0}, //̷ + {{ 101385, 101386, 101387, 101388, 101389, 101390, 101391, 101392, 101108, 101109, 101983, 101972,100425,100420,100445},0}, //Ů + {{ 101393, 101394, 101395, 101396, 101397, 101398, 101399, 101400, 101118, 101119, 101982, 101971,100425,100420,100445},0}, // +}; +#endif +tagRidePetList RPlistMode[] = { + { 100000, 0, 1 }, { 100005, 0, 1 }, { 100010, 0, 1 }, { 100015, 0, 1 }, { 100700, 0, 1 }, { 100705, 0, 1 }, // + { 100020, 1, 1 }, { 100025, 1, 1 }, { 100030, 1, 1 }, { 100035, 1, 1 }, { 100710, 1, 1 }, { 100715, 1, 1 },// + { 100040, 2, 1 }, { 100045, 2, 1 }, { 100050, 2, 1 }, { 100055, 2, 1 }, { 100720, 2, 1 }, { 100725, 2, 1 }, //к + { 100060, 3, 1 }, { 100065, 3, 1 }, { 100070, 3, 1 }, { 100075, 3, 1 }, { 100730, 3, 1 }, { 100735, 3, 1 }, // + { 100080, 4, 1 }, { 100085, 4, 1 }, { 100090, 4, 1 }, { 100095, 4, 1 }, { 100740, 4, 1 }, { 100745, 4, 1 }, //Ƥ + { 100100, 5, 1 }, { 100105, 5, 1 }, { 100110, 5, 1 }, { 100115, 5, 1 }, { 100750, 5, 1 }, { 100755, 5, 1 }, // + { 100120, 6, 2 }, { 100125, 6, 2 }, { 100130, 6, 2 }, { 100135, 6, 2 }, { 100760, 6, 2 }, { 100765, 6, 2 }, // + { 100140, 7, 2 }, { 100145, 7, 2 }, { 100150, 7, 2 }, { 100155, 7, 2 }, { 100770, 7, 2 }, { 100775, 7, 2 }, //Ƥ + { 100160, 8, 2 }, { 100165, 8, 2 }, { 100170, 8, 2 }, { 100175, 8, 2 }, { 100780, 8, 2 }, { 100785, 8, 2 }, //ñ + { 100180, 9, 2 }, { 100185, 9, 2 }, { 100190, 9, 2 }, { 100195, 9, 2 }, { 100790, 9, 2 }, { 100795, 9, 2 }, //̷ + { 100200, 10, 2 }, { 100205, 10, 2 }, { 100210, 10, 2 }, { 100215, 10, 2 }, { 100800, 10, 2 }, { 100805, 10, 2 }, //Ů + { 100220, 11, 2 }, { 100225, 11, 2 }, { 100230, 11, 2 }, { 100235, 11, 2 }, { 100810, 11, 2 }, { 100815, 11, 2 }, // +}; + +int RIDEPET_getNOindex( int baseNo) +{ + int i; + for( i=0; i< sizeof(RPlistMode)/sizeof(tagRidePetList); i++ ) { + if( RPlistMode[i].charNo == baseNo ) { + return RPlistMode[i].Noindex; + } + } + return -1; +} + +#ifdef _RIDE_CF +#ifdef _ADD_RIDE_CF +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode, unsigned int learnCode1, unsigned int learnCode2 ) +{ + int i; + for( i=0; i< 32; i++ ){ + if( RideCodeMode[i].petNo == PetNo ) { + if(RideCodeMode[i].learnCode & learnCode) { + return i; + } + } + if( RideCodeMode[i].petNo1 == PetNo ) { + if(RideCodeMode[i].learnCode & learnCode1) { + return i+32; + } + } + if( RideCodeMode[i].petNo2 == PetNo ) { + if(RideCodeMode[i].learnCode & learnCode2) { + return i+64; + } + } + } + return -1; +} +#else +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode, unsigned int learnCode1 ) +{ + int i; + int max=sizeof(RideCodeMode)/sizeof(tagRideCodeMode); + for( i=0; i< 32; i++ ){ + if( RideCodeMode[i].petNo == PetNo ) { + if(RideCodeMode[i].learnCode & learnCode) + return i; + } + if( RideCodeMode[i].petNo1 == PetNo ) { + if(RideCodeMode[i].learnCode & learnCode1) + return i+32; + } + } + return -1; +} +#endif +#else +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode ) +{ + int i; + for( i=0; i< sizeof(RideCodeMode)/sizeof(tagRideCodeMode); i++ ){ + if( RideCodeMode[i].petNo == PetNo && + (RideCodeMode[i].learnCode & learnCode) ) { + return i; + } + + } + return -1; +} +#endif + +int RIDEPET_getRIDEno( int index, int ti) +{ + if( index < 0 || index >= sizeof( RideNoList)/sizeof( tagRideNoList) ) + return -1; + if( ti < 0 || ti >= MAXNOINDEX ) + return -1; + + return RideNoList[index].RideNo[ti]; +} +#endif + +#ifdef _EMENY_CHANCEMAN +int CHAR_getSexInt( int baseNo ) +{ + int i; + for( i=0; i< sizeof(RPlistMode)/sizeof(tagRidePetList); i++ ) { + if( RPlistMode[i].charNo == baseNo ) { + return RPlistMode[i].sex; + } + } + return -1; +} +#endif + + +#ifdef _PET_EVOLUTION +#define MAXTABLE_X 29 +#define MAXTABLE_Y 29 +int PetTable[MAXTABLE_X][MAXTABLE_Y]={ + //0 4 9 14 19 24 + { 1, 2, 5, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 5, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5}, + { 2, 5, 1, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1}, + { 5, 1, 2, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2}, + { 1, 2, 5, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5}, + { 2, 5, 1, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1}, + + { 2, 1, 2, 1, 2, 2, 2, 5, 5, 1, 2, 5, 2, 1, 2, 1, 2, 5, 2, 1, 2, 1, 2, 5, 2, 5, 2, 1, 2}, + { 1, 2, 5, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 1}, + { 2, 5, 1, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 2}, + {10, 3,10, 3,10, 8,10, 8,10, 3,10, 3,10, 8,10, 8,10, 3,10, 3,10, 8,10, 8,10, 8,10, 3,10}, + { 3, 8, 3, 8, 3,10, 3,10, 8, 3, 3, 8, 3, 8, 3,10, 3,10, 3, 8, 3, 8, 3,10, 3,10, 3, 8, 3}, + + { 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8}, + { 5, 1, 5, 1, 5, 2, 5, 2, 5, 1, 5, 5, 5, 1, 5, 2, 5, 2, 5, 1, 5, 1, 5, 2, 5, 2, 5, 1, 5}, + { 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10}, + {10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3}, + { 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8}, + + { 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1}, + { 9, 0, 9, 0, 9, 4, 9, 4, 9, 0, 9, 0, 9, 4, 9, 4, 9, 0, 9, 0, 9, 4, 9, 4, 9, 0, 9, 4, 9}, + { 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2}, + { 6, 0, 6, 0, 6, 9, 6, 9, 6, 0, 6, 0, 6, 9, 6, 9, 6, 0, 6, 0, 6, 9, 6, 9, 6, 0, 6, 9, 6}, + { 4, 6, 4, 6, 4, 9, 4, 9, 4, 6, 4, 6, 4, 9, 4, 9, 4, 6, 4, 6, 4, 9, 4, 9, 4, 6, 4, 9, 4}, + + { 8, 3, 8, 3, 8,10, 8,10, 8, 3, 8, 3, 8,10, 8,10, 8, 3, 8, 3, 8,10, 8,10, 8, 3, 8,10, 8}, + { 8,10, 3, 8,10, 3, 8,10,10, 3, 8,10, 3, 8,10, 3,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10}, + { 1, 2, 5, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5}, + { 0, 4, 0, 4, 0, 6, 0, 6, 0, 4, 0, 4, 0, 6, 0, 6, 0, 4, 0, 4, 0, 6, 0, 4, 0, 6, 0, 4, 0}, + { 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2}, + + { 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8}, + {10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3, 8,10, 3}, + { 2, 1, 2, 1, 5, 1, 5, 1, 2, 1, 2, 1, 5, 1, 5, 1, 2, 1, 2, 1, 5, 1, 5, 1, 2, 1, 2, 5, 1}, + { 6, 9, 6, 9, 6, 0, 6, 0, 6, 9, 6, 9, 6, 0, 6, 0, 6, 9, 6, 9, 6, 0, 6, 0, 6, 9, 6, 0, 6} +}; + +int PropertyTable[4][4]={ + { 0, 4, 5, 6}, + { 7, 1, 8, 9}, + {10,11, 2,12}, + {13,14,15, 3}, +}; +#define MAXFTABLE_X 11 +#define MAXFTABLE_Y 16 +int FusionTable[MAXFTABLE_X][MAXFTABLE_Y]={ + { 989, 990, 991, 992, 989, 992, 989, 990, 990, 990, 991, 991, 991, 992, 989, 992}, + {1001,1002,1003,1004,1001,1001,1004,1001,1002,1002,1003,1003,1003,1004,1004,1003}, + {1005,1006,1007,1008,1005,1005,1005,1006,1006,1006,1007,1006,1007,1008,1008,1008}, + {1021,1025,1023,1024,1025,1021,1021,1022,1022,1022,1023,1023,1023,1021,1024,1024}, + {1030,1031,1032,1033,1030,1030,1030,1031,1031,1031,1032,1031,1032,1030,1033,1033}, + {1017,1018,1019,1020,1018,1017,1017,1018,1019,1018,1019,1019,1020,1017,1020,1020}, + {1009,1010,1011,1012,1010,1009,1009,1010,1010,1010,1011,1011,1011,1012,1012,1011}, + { 993, 994, 995, 996, 994, 993, 993, 994, 995, 994, 995, 993, 996, 993, 996, 996}, + {1026,1027,1028,1029,1026,1026,1026,1026,1028,1027,1028,1028,1029,1029,1029,1029}, + { 997, 998, 999, 999,1000, 997, 997,1000, 998, 998,1000, 998, 999, 999, 999, 999}, + {1013,1014,1015,1016,1013,1013,1016,1013,1015,1014,1015,1015,1015,1016,1016,1016}, +}; + +int EVOLUTION_getPetFusionCode( int petid) +{ + int petarray = ENEMYTEMP_getEnemyTempArrayFromTempNo( petid); + return ENEMYTEMP_getInt( petarray, E_T_FUSIONCODE); +} + +int EVOLUTION_getPetTable( int charaindex, int petindex1, int petindex2) +{ + int table1,table2; + + if( !CHAR_CHECKINDEX( petindex1) ) return -1; + if( !CHAR_CHECKINDEX( petindex2) ) return -1; + + table2 = EVOLUTION_getPetFusionCode( CHAR_getInt( petindex1, CHAR_PETID)); + table1 = EVOLUTION_getPetFusionCode( CHAR_getInt( petindex2, CHAR_PETID)); + + if( table1 < 0 || table1 >= MAXTABLE_X ) return -1; + if( table2 < 0 || table2 >= MAXTABLE_Y ) return -1; + return PetTable[table1][table2]; +} + +int EVOLUTION_getPropertyTable( int charaindex, int petindex1, int petindex2) +{ + int i, k1=0, k2=0; + int table1,table2; + int Property1[4]={-1,-1,-1,-1}; + int Property2[4]={-1,-1,-1,-1}; + + if( !CHAR_CHECKINDEX( petindex1) ) return -1; + if( !CHAR_CHECKINDEX( petindex2) ) return -1; + + for( i=0; i<4; i++) { + if( CHAR_getInt( petindex1, CHAR_EARTHAT+i) > 0 ){ + Property1[k1] = i; + k1++; + } + if( CHAR_getInt( petindex2, CHAR_EARTHAT+i) > 0 ){ + Property2[k2] = i; + k2++; + } + } + if( k1 == 0 || k2 == 0 ) return -1; + + if( k1 <= 1 ) { + table1 = Property1[ 0]; + }else{ + table1 = Property1[ (rand()%(k1-1)) ]; + } + if( k2 <= 1 ) { + table2 = Property2[ 0]; + }else { + table2 = Property2[ (rand()%(k2-1)) ]; + } + + if( table1 < 0 || table1 >= 4 ) return -1; + if( table2 < 0 || table2 >= 4 ) return -1; + + return PropertyTable[table1][table2]; +} + +int EVOLUTION_getFusionTable( int charaindex, int px, int py) +{ + if( px >= MAXFTABLE_X || px < 0 ) return -1; + if( py >= MAXFTABLE_Y || py < 0 ) return -1; + return FusionTable[px][py]; +} +#endif + +#ifdef _CHAR_FIXDATADEF +/* +typedef struct _tagPetSetIntData{ + char com[256]; + int type; +}PetSetIntData; + +PetSetIntData PET_SetIntData[ ]={ +}; +*/ +#endif + +char* CHAR_setintdata[CHAR_DATAINTNUM]={ + /* dci , PLAYER, */ + "pn", /* CHAR_DATAPLACENUMBER */ + "bi", /* CHAR_BASEIMAGENUMBER */ + "bbi", /* CHAR_BASEBASEIMAGENUMBER */ + "fb", /* CHAR_FACEIMAGENUMBER */ + "fl", /* CHAR_FLOOR */ + "x", /* CHAR_X */ + "y", /* CHAR_Y */ + "dir", /* CHAR_DIR 12ë0ݻԻ */ + "lv", /* CHAR_LV */ + "gld", /* CHAR_GOLD */ + + "hp", /* CHAR_HP */ + "mp", /* CHAR_MP */ + "mmp", /* CHAR_MAXMP */ + + "vi", /* CHAR_VITAL */ + "str", /* CHAR_STR */ + "tou", /* CHAR_TOUGH */ + "dx", /* CHAR_DEX */ + + "chr", /* CHAR_CHARM */ + "luc", /* CHAR_LUCK */ + "aea", /* */ + "awa", /* */ + "afi", /* */ + "awi", /* */ + + "slt", /* CHAR_SLOT */ + "cr", /* CHAR_CRITIAL */ + "cou", /* CHAR_COUNTER */ + "rar", /* CHAR_RARE */ + "rst", /* CHAR_RADARSTRLENGTH */ + "cvo", /* CHAR_CHATVOLUME */ + "ml", /* CHAR_MERCHANTLEVEL */ + "hl", /* CHAR_HEALERLEVEL */ + "di", /* CHAR_DETERMINEITEM */ + "ieqt", /* CHAR_INDEXOFEQTITLE */ + "poi", /* CHAR_POISON */ + "par", /* CHAR_PARALYSIS */ + "sil", /* CHAR_SILENCE */ + "sto", /* CHAR_STONE */ + "dar", /* CHAR_DARKNESS */ + "con", /* CHAR_CONFUSION */ + "loc", /* CHAR_LOGINCOUNT */ + "dc", /* CHAR_DEADCOUNT */ + "wc", /* CHAR_WALKCOUNT */ + "tc", /* CHAR_TALKCOUNT */ + "dmc", /* CHAR_DAMAGECOUNT */ + "gpc", /* CHAR_GETPETCOUNT */ + "kpc", /* CHAR_KILLPETCOUNT */ + "dpc", /* CHAR_DEADPETCOUNT */ + "smc", /* CHAR_SENDMAILCOUNT */ + "mic", /* CHAR_MERGEITEMCOUNT */ + "dbc", /* CHAR_DUELBATTLECOUNT */ + "dwc", /* CHAR_DUELWINCOUNT */ + "dlc", /* CHAR_DUELLOSECOUNT */ + "dswc", /* CHAR_DUELSTWINCOUNT */ + "dslc", /* CHAR_DUELSTLOSECOUNT */ + "dmswc", /* CHAR_DUELMAXSTWINCOUNT */ + "wht", /* CHAR_WHICHTYPE */ + "wint", /* CHAR_WALKNTERVAL */ + "lint", /* CHAR_LOOPINTERVAL */ + "lintab", /* CHAR_LOOPINTERVALAB */ +#ifdef _NEWOPEN_MAXEXP + "exp", /* CHAR_OLDEXP */ + "nexp", /* CHAR_EXP */ +#else + "exp", /* CHAR_EXP */ +#endif + "lte", /* CHAR_LASTTALKELDER */ + "skup", /* CHAR_SKILLUPPOINT */ + "lvup", /* CHAR_LEVELUPPOINT */ + "ity", /* CHAR_IMAGETYPE */ + "nc", /* CHAR_NAMECOLOR */ + "pnc", /* CHAR_POPUPNAMECOLOR */ + "llt", /* CHAR_LASTTIMESETLUCK */ + "duel", /* CHAR_DUELPOINT */ + "evt", /* CHAR_EVENT */ + "evt2", /* CHAR_EVENT2 */ + "evt3", /* CHAR_EVENT3 */ +#ifdef _NEWEVENT + "evt4", /* CHAR_EVENT4 */ + "evt5", /* CHAR_EVENT5 */ + "evt6", /* CHAR_EVENT6 */ +#endif +#ifdef _ADD_NEWEVENT // WON + "evt7", /* CHAR_EVENT7 */ + "evt8", // CHAR_EVENT8, 224~255 ٻר +#endif +#ifdef _ADD_NEWEVENT_1024 + "evt9", /* CHAR_EVENT9 */ + "evt10", /* CHAR_EVENT10 */ + "evt11", /* CHAR_EVENT11 */ + "evt12", /* CHAR_EVENT12 */ + "evt13", /* CHAR_EVENT13 */ + "evt14", /* CHAR_EVENT14 */ + "evt15", /* CHAR_EVENT15 */ + "evt16", /* CHAR_EVENT16 */ + "evt17", /* CHAR_EVENT17 */ + "evt18", /* CHAR_EVENT18 */ + "evt19", /* CHAR_EVENT19 */ + "evt20", /* CHAR_EVENT20 */ + "evt21", /* CHAR_EVENT21 */ + "evt22", /* CHAR_EVENT22 */ + "evt23", /* CHAR_EVENT23 */ + "evt24", /* CHAR_EVENT24 */ + "evt25", /* CHAR_EVENT25 */ + "evt26", /* CHAR_EVENT26 */ + "evt27", /* CHAR_EVENT27 */ + "evt28", /* CHAR_EVENT28 */ + "evt29", /* CHAR_EVENT29 */ + "evt30", /* CHAR_EVENT30 */ + "evt31", /* CHAR_EVENT31 */ + "evt32", /* CHAR_EVENT32 */ +#endif + "nev", /* CHAR_NOWEVENT */ + "nev2", /* CHAR_NOWEVENT2 */ + "nev3", /* CHAR_NOWEVENT3 */ +#ifdef _NEWEVENT + "nev4", /* CHAR_NOWEVENT4 */ + "nev5", /* CHAR_NOWEVENT5 */ + "nev6", /* CHAR_NOWEVENT6 */ +#endif +#ifdef _ADD_NEWEVENT // WON + "nev7", /* CHAR_NOWEVENT7 */ + "nev8", // CHAR_NOWEVENT8, 224~255 ٻר +#endif +#ifdef _ADD_NEWEVENT_1024 // WON + "nev9", /* CHAR_NOWEVENT9 */ + "nev10", /* CHAR_NOWEVENT10 */ + "nev11", /* CHAR_NOWEVENT11 */ + "nev12", /* CHAR_NOWEVENT12 */ + "nev13", /* CHAR_NOWEVENT13 */ + "nev14", /* CHAR_NOWEVENT14 */ + "nev15", /* CHAR_NOWEVENT15 */ + "nev16", /* CHAR_NOWEVENT16 */ + "nev17", /* CHAR_NOWEVENT17 */ + "nev18", /* CHAR_NOWEVENT18 */ + "nev19", /* CHAR_NOWEVENT19 */ + "nev20", /* CHAR_NOWEVENT20 */ + "nev21", /* CHAR_NOWEVENT21 */ + "nev22", /* CHAR_NOWEVENT22 */ + "nev23", /* CHAR_NOWEVENT23 */ + "nev24", /* CHAR_NOWEVENT24 */ + "nev25", /* CHAR_NOWEVENT25 */ + "nev26", /* CHAR_NOWEVENT26 */ + "nev27", /* CHAR_NOWEVENT27 */ + "nev28", /* CHAR_NOWEVENT28 */ + "nev29", /* CHAR_NOWEVENT29 */ + "nev30", /* CHAR_NOWEVENT30 */ + "nev31", /* CHAR_NOWEVENT31 */ + "nev32", /* CHAR_NOWEVENT32 */ +#endif + + "trn", /* CHAR_TRANSMIGRATION */ + "teq", /* CHAR_TRANSEQUATION */ + + "ini", /* CHAR_INITDATA */ + "silent", /* CHAR_SILENT */ + "fmi", // CoolFish: Family 2001/5/24 index + "fmlf", // CoolFish: Family 2001/5/24 ǷΪ峤 + "fmspr", // CoolFish: Family 2001/7/13 ػ +//#ifndef _SAEX_TW_25 +// "fmbdg", +//#endif + "bankgld", /* CHAR_BANKGOLD */ + "ridepet", /* CHAR_RIDEPET */ + "learnride", /* CHAR_LEARNRIDE */ +#ifdef _NEW_RIDEPETS + "lowridepet", //CHAR_LOWRIDEPETS +#endif + "limitlv", // Arminius 7.30 pet limit level +#ifdef _PET_FUSION + "fusioncode", //CHAR_FUSIONCODE + "fusionindex", //CHAR_FUSIONINDEX + "fusionraise", //CHAR_FUSIONRAISE + "fusionbe", //CHAR_FUSIONBEIT + "futimelimit", //CHAR_FUSIONTIMELIMIT +#endif + +#ifdef _PERSONAL_FAME // Arminius 8.30: + "fame", +#endif + +#ifdef _NEWSAVE + "sindex", /* CHAR_SAVEINDEXNUMBER */ +#endif + +#ifdef _ATTACK_MAGIC + "earth_exp", // ҵĵħ + "water_exp", // ҵˮħ + "fire_exp", // ҵĻħ + "wind_exp", // ҵķħ + "earth_resist", // ҵĵħ + "water_resist", // ҵˮħ + "fire_resist", // ҵĻħ + "wind_resist", // ҵķħ + "earth_attmagic_exp", // ҵĵħȾֵ + "water_attmagic_exp", // ҵˮħȾֵ + "fire_attmagic_exp", // ҵĻħȾֵ + "wind_attmagic_exp", // ҵķħȾֵ + "earth_defmagic_exp", // ҵĵħԾֵ + "water_defmagic_exp", // ҵˮħԾֵ + "fire_defmagic_exp", // ҵĻħԾֵ + "wind_defmagic_exp", // ҵķħԾֵ +#endif + +#ifdef _GAMBLE_BANK // + "personaglod", //CHAR_PERSONAGOLD, +#endif +#ifdef _DROPSTAKENEW + "gamblenums", //CHAR_GAMBLENUM +#endif +#ifdef _ADD_ACTION //npc + "actsty", //CHAR_ACTIONSTYLE +#endif +#ifdef _PET_EVOLUTION + "evbasevtl",// CHAR_EVOLUTIONBASE, + "evbasestr",// CHAR_EVOLUTIONBASE, + "evbasetgh",// CHAR_EVOLUTIONBASE, + "evbasedex",// CHAR_EVOLUTIONBASE, +#endif + +#ifdef _FM_JOINLIMIT + "fmtimelimit", // CHAR_FMTIMELIMIT, +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + "profession_class", + "profession_level", +// "profession_exp", + "profession_skill_point", + "attachpile", + "profession_fire_p", + "profession_ice_p", + "profession_thunder_p", + "profession_fire_r", + "profession_ice_r", + "profession_thunder_r", +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + "herofloor", +#endif +#ifdef _PETSKILL_BECOMEPIG + "becomepig", + "becomepig_bbi", +#endif + "leavetime", // CHAR_LASTLEAVETIME +#ifdef _NEW_MANOR_LAW + "momentum", // CHAR_MOMENTUM +#endif + +#ifdef _ITEM_ADDEXP2 + "aexp", // CHAR_ADDEXPPOWER + "aexpt", // CHAR_ADDEXPTIME +#endif + +#ifdef _ANGEL_SUMMON + "herocnt", // CHAR_HEROCNT +#endif +#ifdef _TEACHER_SYSTEM + "tsf", // CHAR_TEACHER_FAME, // ʦ쵼 +#endif + +#ifdef _GM_ITEM + "gmtime", // GM +#endif +#ifdef _VIP_SERVER + "memberpoint", // ػر +#endif +#ifdef _VIP_RIDE + "vipride", // Աڼ + "viptime", +#endif + +#ifdef _PET_BEATITUDE + "beatitude", +#endif + +#ifdef _RIDE_CF + "lowridepet1", //CHAR_LOWRIDEPETS1 +#ifdef _ADD_RIDE_CF + "lowridepet2", // + "lowridepet3", // + "lowridepet4", // + "lowridepet5", // + "lowridepet6", // + "lowridepet7", // + "lowridepet8", // +#endif +#endif + +#ifdef _ITEM_PET_LOCKED + "locked", +#endif + +#ifdef _BOUND_TIME + "boundtime", +#endif + +#ifdef _SUPER + "super", +#endif + +#ifdef _ONLINE_SHOP + "bj", +#endif + +#ifdef _LOTTERY_SYSTEM + "lotterydate", + "lotterytime", +#endif + +#ifdef _COMPOUND_EXP + "material01_exp", + "material02_exp", + "material03_exp", + "material04_exp", + "material05_exp", + "material06_exp", + "material07_exp", + "material08_exp", + "material09_exp", + "material10_exp", + "material11_exp", + "material12_exp", + "material13_exp", + "material14_exp", + "material15_exp", + "material16_exp", + "material17_exp", + "material18_exp", + "material19_exp", + "material20_exp", + "material21_exp", + "material22_exp", + "material23_exp", + "material24_exp", + "material25_exp", +#endif +#ifdef _ONLINE_TIME + "onlinetime", +#endif + +#ifdef _CAMEO_MONEY + "cameo", +#endif + +#ifdef _MISSION_TRAIN + "mt", + "mttime", +#endif +#ifdef _PET_EVOLVE + "evolve", +#endif +#ifdef _FLOOR_DIFI_FIELD + "fdt", +#endif +#ifdef _ACTIVE_GAME + "active", +#endif +#ifdef _PLAYER_TITLE + "titlelv", + "titletime", +#endif +#ifdef _MISSION_TIME + "mtime", +#endif +#ifdef _REGISTRATION_TIME + "regtime", + "regcount", + "regoltime", +#endif +#ifdef _SPECIAL_COUNTER + "spcounter" , +#endif +#ifdef _SPECIAL_TIMER + "sptime", +#endif +#ifdef _OFFLINE_TIME + "offtime", +#endif +#ifdef _FAME_REG_TIME + "fmregtime", +#endif +#ifdef _PETCOM_ + "yhp", + "yatk", + "ydef", + "yquick", + "ylv", +#endif +#ifdef _NEW_ITEM_ + "newitemflg", +#endif +#ifdef _MO_PLAYER_EFFECT + "effect", +#endif +#ifdef _JZ_NEWSCRIPT_LUA + "lint1", //CHAR_LUASAVE_INT_1, + "lint2", //CHAR_LUASAVE_INT_1, + "lint3", //CHAR_LUASAVE_INT_1, +#endif +#ifdef _ATTACK_EFFECT + "attckeffect", +#endif +#ifdef _MO_NO_WALK + "nowalk", +#endif +#ifdef _TENSE_FIELD + "tensefield", +#endif +#ifdef _NEW_TITLE + "title_d", + "title_1", + "title_2", + "title_3", +#endif +#ifdef _CHARSIGNDAY_ + "qiandaozt", + "qiandaoyue", + "qiandaori", +#endif +#ifdef _TRUMP_EQUIPMENT + "tpflg", + "tpeffect", +#endif +#ifdef _CHAR_TITLE_STR_ + "titleindex", +#endif +}; + +char* CHAR_setchardata[CHAR_DATACHARNUM]={ + /* dcc , PLAYER */ + "name" , /* CHAR_NAME */ + "ownt" , /* CHAR_OWNTITLE*/ + "arg", /* CHAR_NPCARGUMENT */ + "ocd", /* CHAR_OWNERCDKEY */ + "ocn", /* CHAR_OWNERCHARANAME */ + "fmname", // CoolFish: Family 2001/5/24 CHAR_FMNAME +#ifdef _UNIQUE_P_I + "ucode", // CoolFish: 2001/10/11 UNIQUE_P_I CHAR_UNIQUECODE +#endif + +#ifdef _TEACHER_SYSTEM + "tsi", // ʦʺ + "tsn", // ʦ +#endif + +#ifdef _ITEM_SETLOVER + "love", // ж + "lovrrid", // ʺ + "lovrrneme", // +#endif + +#ifdef _GM_ITEM + "gmfunction", // GM +#endif +#ifdef _NEW_NAME + "newname", //Զƺ +#endif + +#ifdef _LOTTERY_SYSTEM + "lotteryvalue", +#endif +#ifdef _POWER_UP + "powerup", +#endif +#ifdef _VISUAL_BEATITUDE + "vb", +#endif +}; + +INLINE BOOL _CHAR_CHECKINDEX( char *file, int line, int index ) +{ + if( CHAR_charanum<=index || index<0 ) { + return FALSE; + } + if( CHAR_chara[(index)].use == FALSE ) { + return FALSE; + } + return TRUE; +} + +INLINE BOOL CHAR_CHECKINTDATAINDEX(int index) +{ + if( CHAR_DATAINTNUM<=index || index<0 )return FALSE; + return TRUE; +} + +INLINE BOOL CHAR_CHECKCHARDATAINDEX(int index) +{ + if( CHAR_DATACHARNUM<=index || index<0 )return FALSE; + return TRUE; +} + +INLINE BOOL CHAR_CHECKFLGDATAINDEX( int index ) +{ + if( CHAR_FLGNUM<=index || index<0 )return FALSE; + return TRUE; +} + +INLINE BOOL CHAR_CHECKCHARWORKDATAINDEX(int index) +{ + if( CHAR_WORKDATACHARNUM<=index || index<0 )return FALSE; + return TRUE; +} + +INLINE BOOL CHAR_CHECKCHARFUNCTABLEINDEX(int index) +{ + if( CHAR_FUNCTABLENUM <= index || index < 0 )return FALSE; + return TRUE; +} + +INLINE BOOL _CHAR_CHECKITEMINDEX( char *file, int line, int charaindex, int ti ) +{ + if( 0 <= ti && ti < CheckCharMaxItem(charaindex) ) return TRUE; + return FALSE; +} + +INLINE BOOL CHAR_CHECKSKILLINDEX( int skillindex ) +{ + if( skillindex<0 || CHAR_SKILLMAXHAVE <= skillindex )return FALSE; + return TRUE; +} +INLINE BOOL CHAR_CHECKADDRESSBOOKINDEX( int aindex ) +{ + if( aindex < 0 || ADDRESSBOOK_MAX <= aindex ) return FALSE; + return TRUE; +} + +INLINE BOOL CHAR_CHECKTITLEINDEX( int titleindex ) +{ + if( titleindex<0 || CHAR_TITLEMAXHAVE <= titleindex )return FALSE; + return TRUE; +} + +INLINE BOOL _CHAR_CHECKPETINDEX( char *file, int line, int petindex ) +{ + if( petindex < 0 || CHAR_MAXPETHAVE <= petindex ) { + if( petindex != -1 ) { + //print( "err %s:%d \n", file, line); + } + return FALSE; + } + return TRUE; +} + +INLINE BOOL _CHAR_CHECKPOOLPETINDEX( char *file, int line, int petindex ) +{ + if( petindex < 0 || CHAR_MAXPOOLPETHAVE <= petindex ) { + + if( petindex != -1 ) { + print( "err %s:%d :%d \n", file, line, petindex); + } + return FALSE; + } + return TRUE; +} + +INLINE BOOL _CHAR_CHECKPETSKILLINDEX( char *file, int line, int havepetskillindex ) +{ + if( havepetskillindex < 0 || CHAR_MAXPETSKILLHAVE <= havepetskillindex ) { + if( havepetskillindex != -1 ) { + print( "err %s:%d \n", file, line); + } + return FALSE; + } + return TRUE; +} + +INLINE int CHAR_getIntStrict( int index ,CHAR_DATAINT element,int* error) +{ + if(!CHAR_CHECKINDEX(index))return *error=FALSE; + if(!CHAR_CHECKINTDATAINDEX(element))return *error=FALSE; + return CHAR_chara[index].data[element]; +} + +INLINE int _CHAR_getInt( char *file, int line, int index ,CHAR_DATAINT element) +//INLINE int CHAR_getInt( int index , CHAR_DATAINT element) +{ + if( !CHAR_CHECKINDEX( index) ){ + print(" err CHAR_getInt index:%d. !:%s-%d\n", index, file, line); + return -1; + } + if( CHAR_DATAPLACENUMBER > element || element >= CHAR_DATAINTNUM ) { + print(" err CHAR_getInt element:%d.%s :%s-%d\n", element, CHAR_getChar( index, CHAR_CDKEY),file, line); + return -1; + } + return CHAR_chara[index].data[element]; +} + +INLINE int CHAR_setIntStrict( int index ,CHAR_DATAINT element,int data, + int* error) +{ + int buf; + if(!CHAR_CHECKINDEX(index))return *error=FALSE; + if(!CHAR_CHECKINTDATAINDEX(element))return *error=FALSE; + buf = CHAR_chara[index].data[element]; + CHAR_chara[index].data[element] = data; + return buf; +} + +INLINE int _CHAR_setInt( char *file, int line, int index ,CHAR_DATAINT element, int data) +{ + int buf; + if( !CHAR_CHECKINDEX( index) ) { + print(" err CHAR_setInt index:%d. !:%s-%d\n", index, file, line); + return -1; + } + if( CHAR_DATAPLACENUMBER > element || element >= CHAR_DATAINTNUM ) { + print(" err CHAR_setInt element:%d.%s :%s-%d\n", element, CHAR_getChar( index, CHAR_CDKEY),file, line); + return -1; + } + buf = CHAR_chara[index].data[element]; + CHAR_chara[index].data[element] = data; + +#ifdef _SAMETHING_SAVEPOINT + if(element==CHAR_AMPOINT){ + if(CHAR_charSaveFromConnect(index, FALSE)){ + CHAR_talkToCli(index, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } + } +#endif + + return buf; +} + +#ifdef _FIX_SETWORKINT +INLINE int _CHAR_getWorkInt( char *file, int line, int index ,CHAR_WORKDATAINT element) +#else +INLINE int CHAR_getWorkInt( int index ,CHAR_WORKDATAINT element) +#endif +{ + if( !CHAR_CHECKINDEX( index) ) { + print( "err Get WorkInt index:%d:%s[%d].\n", index, file, line); + return -1; + } + if( CHAR_WORKBATTLEMODE > element || element >= CHAR_WORKDATAINTNUM ) { + print("err Get WorkInt element=%d :: file:%s %d!\n", element, file, line); + return -1; + } + return CHAR_chara[index].workint[element]; +} + +#ifdef _FIX_SETWORKINT +INLINE int _CHAR_setWorkInt( char *file, int line, int index ,CHAR_WORKDATAINT element, int data) +#else +INLINE int CHAR_setWorkInt( int index ,CHAR_WORKDATAINT element, int data) +#endif +{ + int buf; + if( !CHAR_CHECKINDEX( index) ) { + print( "err Set WorkInt index:%d:%s[%d].\n", index, file, line); + return -1; + } + + if( CHAR_WORKBATTLEMODE > element || element >= CHAR_WORKDATAINTNUM ) { +#ifdef _FIX_SETWORKINT + print("err Set WorkInt element=%d.%s:%s[%d]!\n", element, CHAR_getChar( index, CHAR_CDKEY), file, line); +#else + print("err Set WorkInt element=%d.%s!\n", element, CHAR_getChar( index, CHAR_CDKEY) ); +#endif + return -1; + } + + buf = CHAR_chara[index].workint[element]; + CHAR_chara[index].workint[element] = data; + return buf; +} + +INLINE char* _CHAR_getChar( char *file, int line, int index ,CHAR_DATACHAR element ) +{ + if(!CHAR_CHECKINDEX(index)) { + print( "err _CHAR_getChar %s:%d index[%d] !!\n", file, line, index); + return "\0"; + } + if(!CHAR_CHECKCHARDATAINDEX(element)) { + print( "err _CHAR_getChar %s:%d element[%d] !!\n", file, line, element); + return "\0"; + } + return CHAR_chara[index].string[element].string; +} + +INLINE BOOL _CHAR_setChar( char *file, int line, int index ,CHAR_DATACHAR element, const char* new ) +{ + if(!CHAR_CHECKINDEX(index)){ + print( "err _CHAR_setChar %s:%d !\n", file, line); + return FALSE; + } + if(!CHAR_CHECKCHARDATAINDEX(element)) { + print( "err _CHAR_setChar %s:%d !\n", file, line); + return FALSE; + } + strcpysafe( CHAR_chara[index].string[element].string, + sizeof(CHAR_chara[index].string[element].string), + new ); + return TRUE; +} + +INLINE char* CHAR_getCharfunctable( int index ,CHAR_FUNCTABLE element ) +{ + if(!CHAR_CHECKINDEX(index))return (char*)NULL; + if(!CHAR_CHECKCHARFUNCTABLEINDEX(element))return (char*)NULL; + + + return CHAR_chara[index].charfunctable[element].string; +} + +INLINE char* _CHAR_getWorkChar( char *file, int line, int index ,CHAR_WORKDATACHAR element ) +{ + if(!CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return "\0"; + } + if(!CHAR_CHECKCHARWORKDATAINDEX(element)) { + print( "err %s:%d \n", file, line); + return "\0"; + } + return CHAR_chara[index].workchar[element].string; +} + +INLINE BOOL _CHAR_setWorkChar( char *file, int line, int index ,CHAR_WORKDATACHAR element, + const char* new ) +{ + if(!CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return FALSE; + } + if(!CHAR_CHECKCHARWORKDATAINDEX(element)) { + print( "err %s:%d \n", file, line); + return FALSE; + } + strcpysafe( CHAR_chara[index].workchar[element].string, + sizeof(CHAR_chara[index].workchar[element].string), + new ); + return TRUE; +} + +static char CHAR_flgbitmaskpattern[]= +{ + 0x01, + 0x02, + 0x04, + 0x08, + 0x10, + 0x20, + 0x40, + 0x80, +}; + +INLINE BOOL _CHAR_getFlg( char *file, int line, int index ,CHAR_DATAFLG element ) +{ + int elementnum; + int bitnum; + if(!CHAR_CHECKINDEX(index)) { + print( "CHAR_getFlg:index %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return FALSE; + } + if(!CHAR_CHECKFLGDATAINDEX(element)) { + print( "CHAR_getFlg:element %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return FALSE; + } + elementnum = element / (sizeof( char )*8); + bitnum = element % (sizeof( char )*8); + + + if( CHAR_chara[index].flg[elementnum] + & CHAR_flgbitmaskpattern[bitnum]) + return TRUE; + else + return FALSE; + +} + +INLINE BOOL _CHAR_setFlg( char *file, int line, int index , CHAR_DATACHAR element, int newdata ) +{ + int buf; + int elementnum; + int bitnum; + char bitpattern; + + if(!CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return FALSE; + } + if(!CHAR_CHECKFLGDATAINDEX(element)) { + print( "err %s:%d \n", file, line); + return FALSE; + } + elementnum = element / (sizeof( char )*8); + bitnum = element % (sizeof( char )*8); + + /* ɼëת */ + buf = CHAR_chara[index].flg[elementnum] + & CHAR_flgbitmaskpattern[bitnum]; + + if( newdata != 0 ){ + bitpattern = CHAR_flgbitmaskpattern[bitnum]; + CHAR_chara[index].flg[elementnum] |= bitpattern; + + }else{ + bitpattern = ~CHAR_flgbitmaskpattern[bitnum]; + CHAR_chara[index].flg[elementnum] &= bitpattern; + } + + if( buf )return TRUE; + else return FALSE; +} + +INLINE int _CHAR_getItemIndex( char *file, int line, int charaindex ,int ti) +{ + if( !CHAR_CHECKINDEX( charaindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + if( !CHAR_CHECKITEMINDEX( charaindex, ti) ){ + print( "err %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return -1; + } + return CHAR_chara[charaindex].indexOfExistItems[ti]; +} + +INLINE int _CHAR_setItemIndex( char *file, int line, int index ,int iindex,int id ) +{ + int buf; + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return -1; + } + if( CheckCharMaxItem(index) <= iindex || iindex < 0 ) { + print( "err %s:%d \n", file, line); + return -1; + } + +// CoolFish: 2001/10/12 +#ifdef _UNIQUE_P_I + if ( (id != -1) && (ITEM_getChar(id, ITEM_UNIQUECODE) != "\0") ) // shan add hjj + ITEM_setItemUniCode(id); +#endif + +#ifdef _ITEM_TIME_LIMIT + if( (id != -1) && ITEM_getWorkInt( id, ITEM_WORKTIMELIMIT) == -1 ){ + char *arg, *p=NULL, tmp[16]=""; + long iTmp; + time_t iTime; + + time(&iTime); + iTmp = iTime; + arg = ITEM_getChar( id, ITEM_ARGUMENT); + if(arg && (p=strstr( arg, "Time")) != NULL ){ + //andy_log + print("%s setTime arg:%s \n", ITEM_getChar( id, ITEM_NAME), arg); + strcpy( tmp, (p+4)); + iTmp += atoi(tmp)*60; + ITEM_setWorkInt( id, ITEM_WORKTIMELIMIT, iTmp); + } + } +#endif + buf = CHAR_chara[index].indexOfExistItems[iindex]; + CHAR_chara[index].indexOfExistItems[iindex] = id; + return buf; +} +INLINE int _CHAR_getPoolItemIndex( char *file, int line, int index ,int iindex) +{ + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + if( CHAR_MAXPOOLITEMHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return -1; + } + return CHAR_chara[index].indexOfExistPoolItems[iindex]; +} +INLINE int _CHAR_setPoolItemIndex( char *file, int line, int index ,int iindex,int id ) +{ + int buf; + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return -1; + } + if( CHAR_MAXPOOLITEMHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d \n", file, line); + return -1; + } + buf = CHAR_chara[index].indexOfExistPoolItems[iindex]; + CHAR_chara[index].indexOfExistPoolItems[iindex] = id; + return buf; +} + +INLINE BOOL CHAR_setAddressbookEntry( int index , int aindex , + ADDRESSBOOK_entry *a ) +{ + if( !CHAR_CHECKINDEX(index))return FALSE; + if( !CHAR_CHECKADDRESSBOOKINDEX( aindex ))return FALSE; + + memcpy( & CHAR_chara[index].addressBook[aindex] , a , + sizeof(ADDRESSBOOK_entry )); + + return TRUE; +} + +INLINE ADDRESSBOOK_entry* CHAR_getAddressbookEntry( int index , + int aindex) +{ + if( !CHAR_CHECKINDEX(index))return (ADDRESSBOOK_entry*)NULL; + if( !CHAR_CHECKADDRESSBOOKINDEX( aindex )) + return (ADDRESSBOOK_entry*) NULL; + + return &CHAR_chara[index].addressBook[aindex]; +} + +INLINE Char* CHAR_getCharPointer( int index ) +{ + if( !CHAR_CHECKINDEX(index) )return (Char*)NULL; + return &CHAR_chara[index]; +} + +INLINE int CHAR_getCharNum( void ) +{ + return CHAR_charanum; +} + +INLINE int CHAR_getPlayerMaxNum( void ) +{ + return CHAR_playernum; +} + +INLINE int CHAR_getPetMaxNum( void ) +{ + return CHAR_petnum; +} +INLINE int CHAR_getOthersMaxNum( void ) +{ + return CHAR_othersnum; +} + +INLINE BOOL CHAR_getCharUse( int index ) +{ + if( !CHAR_CHECKINDEX(index)) + return FALSE; + return CHAR_chara[index].use; +} + +INLINE CHAR_HaveSkill* CHAR_getCharHaveSkill( int index,int sindex ) +{ + if( !CHAR_CHECKINDEX(index))return (CHAR_HaveSkill*)NULL; + if( !CHAR_CHECKSKILLINDEX(sindex))return (CHAR_HaveSkill*)NULL; + return &CHAR_chara[index].haveSkill[sindex]; +} +//------------------------------------------------------------------------ +//index λ +INLINE int _CHAR_getIntPSkill( char *file, int line, int index, int skillti, SKILL_DATAINT ti) +{ + if( !CHAR_CHECKINDEX( index) ) return -1; + if( !CHAR_CHECKSKILLINDEX( skillti) ) return -1; + if( ti >= SKILL_DATAINTNUM || ti < 0 ){ + print(" getIntPSkill() SKILL_DATAINT (%d) err -%s:%d!!\n", ti , file, line); + return -1; + } + if( CHAR_chara[index].haveSkill[skillti].skill.data[ti] <= 0 ) return -1; + return CHAR_chara[index].haveSkill[skillti].skill.data[ti]; +} +//index λ 趨ֵ +INLINE void _CHAR_setIntPSkill( char *file, int line, int index, int skillti, SKILL_DATAINT ti, int data) +{ + if( !CHAR_CHECKINDEX( index) ) return; + if( !CHAR_CHECKSKILLINDEX( skillti) ) return; + if( ti >= SKILL_DATAINTNUM || ti < 0 ){ + print(" getIntPSkill() SKILL_DATAINT (%d) err -%s:%d!!\n", ti , file, line); + return; + } +// if( CHAR_chara[index].haveSkill[sindex].use > 0 ) + CHAR_chara[index].haveSkill[skillti].skill.data[ti] = data; +} +//------------------------------------------------------------------------ + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +int CHAR_getCharSkill( int index,int sindex ) +{ + CHAR_HaveSkill* hskill; + + hskill = CHAR_getCharHaveSkill( index, sindex ); + + if(hskill != NULL) + return SKILL_getInt( &hskill->skill, SKILL_IDENTITY); + else + return -1; + +} + +int CHAR_setCharSkill( int index,int sindex, int new ) +{ + CHAR_HaveSkill* hskill; + + if( !CHAR_CHECKINDEX(index)) return -1; + if( !CHAR_CHECKSKILLINDEX(sindex)) return -1; + + hskill = CHAR_getCharHaveSkill( index, sindex ); + SKILL_setInt( &hskill->skill, SKILL_IDENTITY, new); + return TRUE; +} +#endif + +INLINE int CHAR_getCharHaveTitle( int charaindex,int tindex ) +{ + if( !CHAR_CHECKINDEX(charaindex))return 0; + if( !CHAR_CHECKTITLEINDEX(tindex))return 0; + return CHAR_chara[charaindex].indexOfHaveTitle[tindex]; +} + +INLINE int CHAR_setCharHaveTitle( int charaindex,int tindex, int new ) +{ + int ret; + if( !CHAR_CHECKINDEX(charaindex))return 0; + if( !CHAR_CHECKTITLEINDEX(tindex))return 0; + if( new != -1 ) + if( TITLE_getTitleIndex( new) == -1 ) return 0; + ret = CHAR_getCharHaveTitle( charaindex,tindex); + CHAR_chara[charaindex].indexOfHaveTitle[tindex] = new; + return ret; +} + +INLINE int CHAR_getCharPet( int charaindex,int petindex ) +{ + if( !CHAR_CHECKINDEX(charaindex))return -1; + if( !CHAR_CHECKPETINDEX(petindex))return -1; + return CHAR_chara[charaindex].unionTable.indexOfPet[petindex]; +} + +INLINE int CHAR_setCharPet( int charaindex,int petindex, int new ) +{ + int ret; + if( !CHAR_CHECKINDEX(charaindex))return -1; + if( !CHAR_CHECKPETINDEX(petindex))return -1; + ret = CHAR_getCharPet( charaindex,petindex); + +// CoolFish: 2001/10/12 +#ifdef _UNIQUE_P_I + if (new != -1) + CHAR_setPetUniCode(new); +#endif + + CHAR_chara[charaindex].unionTable.indexOfPet[petindex] = new; + return ret; +} + +INLINE int CHAR_getCharPoolPet( int charaindex,int petindex ) +{ + if( !CHAR_CHECKINDEX(charaindex))return -1; + if( !CHAR_CHECKPOOLPETINDEX(petindex))return -1; + return CHAR_chara[charaindex].indexOfPoolPet[petindex]; +} + +INLINE int CHAR_setCharPoolPet( int charaindex,int petindex, int new ) +{ + int ret; + if( !CHAR_CHECKINDEX(charaindex))return -1; + if( !CHAR_CHECKPOOLPETINDEX(petindex))return -1; + ret = CHAR_getCharPoolPet( charaindex,petindex); + + CHAR_chara[charaindex].indexOfPoolPet[petindex] = new; + return ret; +} +#ifdef _PETFOLLOW_NEW_ +int CHAR_getCharPetElement( int charaindex ) +{ + int i,j,k; + i=0; + j=0; + k=0; + if( !CHAR_CHECKINDEX(charaindex))return -1; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex,i) > -1 ) j++; + } + for( i = 0; i < 5; i ++ ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW +i) > 0 ) k++; + } + + if((j + k)>=CHAR_MAXPETHAVE) return -1; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex,i) == -1 ) break; + } + + return ( i == CHAR_MAXPETHAVE ? -1:i ); + +} + +int CHAR_getCharPetElementOld( int charaindex ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex))return -1; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex,i) == -1 ) break; + } + return ( i == CHAR_MAXPETHAVE ? -1:i ); + +} +#else +int CHAR_getCharPetElement( int charaindex ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex))return -1; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex,i) == -1 ) break; + } + return ( i == CHAR_MAXPETHAVE ? -1:i ); + +} +#endif + +int CHAR_getCharPoolPetElement( int charaindex ) +{ + int i; + int limit; + if( !CHAR_CHECKINDEX(charaindex))return -1; + + //andy_reEdit 2003/09/18 + limit = (CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)*2)+5; + limit = min( limit, CHAR_MAXPOOLPETHAVE); + for( i = 0; i < limit; i ++ ) { + if( CHAR_getCharPoolPet( charaindex,i) == -1 ) break; + } + return ( i == limit ? -1:i ); + +} + +int CHAR_getCharPoolItemIndexElement( int charaindex ) +{ + int i; + int limit; + if( !CHAR_CHECKINDEX(charaindex))return -1; + //andy_reEdit 2003/09/18 + limit = (CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)*4)+10; + limit = min( limit, CHAR_MAXPOOLITEMHAVE); + for( i = 0; i < limit; i ++ ) { + if( CHAR_getPoolItemIndex( charaindex,i) == -1 ) break; + } + // Robin fix + //return ( i == CHAR_MAXPOOLITEMHAVE ? -1:i ); + return ( i >= limit ? -1:i ); + +} + +int CHAR_getEmptyCharPoolItemIndexNum( int charaindex) +{ + int i, cnt = 0; + int limit; + if( !CHAR_CHECKINDEX(charaindex))return 0; + //andy_reEdit 2003/09/18 + limit = (CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)*4)+10; + limit = min( limit, CHAR_MAXPOOLITEMHAVE); + + for( i = 0; i < limit; i ++ ) { + if( CHAR_getPoolItemIndex( charaindex, i) == -1 ) cnt++; + } + return cnt; +} + +INLINE int _CHAR_getPetSkill( char *file, int line, int petindex, int havepetskillindex ) +{ + if( !CHAR_CHECKINDEX(petindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__, file, line); + return -1; + } + if( !CHAR_CHECKPETSKILLINDEX(havepetskillindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__, file, line); + return -1; + } + return CHAR_chara[petindex].unionTable.indexOfPetskill[havepetskillindex]; +} + +INLINE int _CHAR_setPetSkill( char *file, int line, int petindex,int havepetskillindex, int new ) +{ + int ret; + if( !CHAR_CHECKINDEX(petindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__, file, line); + return -1; + } + if( !CHAR_CHECKPETSKILLINDEX(havepetskillindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__, file, line); + return -1; + } + ret = CHAR_getPetSkill( petindex,havepetskillindex); + CHAR_chara[petindex].unionTable.indexOfPetskill[havepetskillindex] = new; + return ret; +} + +int _CHAR_getPetSkillElement( char *file, int line, int petindex ) +{ + int i; + if( !CHAR_CHECKINDEX(petindex)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__, file, line); + return -1; + } + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + if( CHAR_getPetSkill( petindex,i) == -1 ) break; + } + return ( i == CHAR_MAXPETSKILLHAVE ? -1:i ); + +} + +INLINE int CHAR_getCharMakeSequenceNumber( int charaindex ) +{ + if( !CHAR_CHECKINDEX(charaindex))return -1; + return CHAR_chara[charaindex].CharMakeSequenceNumber; +} + +void CHAR_constructFunctable( int charaindex ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex))return; + for( i=CHAR_FIRSTFUNCTION; i < CHAR_LASTFUNCTION ; i++ ) + CHAR_chara[charaindex].functable[i-CHAR_FIRSTFUNCTION] + = getFunctionPointerFromName( CHAR_getCharfunctable( charaindex,i ) ); +} + +void* CHAR_getFunctionPointer( int charaindex, int functype ) +{ + if( !CHAR_CHECKINDEX(charaindex) )return (void*)NULL; + if( functype < CHAR_FIRSTFUNCTION || functype >= CHAR_LASTFUNCTION ) + return (void*)NULL; + + return CHAR_chara[charaindex].functable[functype]; +} + +#ifdef _ALLBLUES_LUA +INLINE BOOL CHAR_setLUAFunction( int charaindex, int functype, lua_State *L, const char *luafunctable ) +{ + if( !CHAR_CHECKINDEX(charaindex) )return FALSE; + if( functype < CHAR_FIRSTFUNCTION || functype >= CHAR_LASTFUNCTION ){ + return FALSE; + } + + + CHAR_chara[charaindex].lua[functype] = L; + CHAR_chara[charaindex].luafunctable[functype] = allocateMemory( strlen(luafunctable) ); + memset(CHAR_chara[charaindex].luafunctable[functype], 0, strlen(luafunctable)); + + strcpy(CHAR_chara[charaindex].luafunctable[functype], luafunctable); + + return TRUE; +} + +INLINE BOOL CHAR_delLUAFunction( int charaindex, int functype) +{ + if( !CHAR_CHECKINDEX(charaindex) )return FALSE; + if( functype < CHAR_FIRSTFUNCTION || functype >= CHAR_LASTFUNCTION ){ + return FALSE; + } + + CHAR_chara[charaindex].lua[functype] = NULL; + freeMemory(CHAR_chara[charaindex].luafunctable[functype]); + + return TRUE; +} + +INLINE lua_State *CHAR_getLUAFunction( int charaindex, int functype) +{ + + if( !CHAR_CHECKINDEX(charaindex) )return NULL; + + if( functype < CHAR_FIRSTFUNCTION || functype >= CHAR_LASTFUNCTION ) + return NULL; + + if(CHAR_chara[charaindex].lua[functype] == NULL){ + return NULL; + } + + lua_getglobal( CHAR_chara[charaindex].lua[functype], CHAR_chara[charaindex].luafunctable[functype]); + return CHAR_chara[charaindex].lua[functype]; +} +#endif + +BOOL CHAR_initCharArray( int pnum, int petnum,int onum ) +{ + int i; + BOOL CHAR_checksetdata( void ); + if( CHAR_checksetdata() == FALSE ){ + print(" err CHAR_checksetdata() FALSE !!\n"); + return FALSE; + } + CHAR_initChatMagic(); + CHAR_charanum = pnum + petnum +onum; + CHAR_chara = allocateMemory( sizeof( Char ) * CHAR_charanum ); + if( CHAR_chara == NULL ){ + print("޷ڴ !!\n"); + return FALSE; + } + //andy_log + print(" %4.2f MB ռ...", ((float)sizeof( Char )*CHAR_charanum)/1024/1024); + + for( i = 0 ; i < CHAR_charanum ; i ++ ){ + memset( &CHAR_chara[i], 0 , sizeof( Char )); + + } + CHAR_playernum = pnum; + CHAR_petnum = petnum; + CHAR_othersnum = onum; + return TRUE; +} + +BOOL CHAR_endCharArray( void ) +{ + freeMemory( CHAR_chara ); + CHAR_charanum = 0; + return TRUE; +} + +BOOL CHAR_getCharOnArrayPercentage( int mode, int *max, int *min, int *cnt) +{ + int po=0, Dnums=0; + po = initCharCounter[0].endcnt; + *cnt = -1; + while( 1){ + if( !CHAR_chara[po].use ){ + }else{ + Dnums++; + } + po++; + if( po >= initCharCounter[mode].endcnt ){ + break; + } + } + *cnt = Dnums; + *max = initCharCounter[mode].endcnt - initCharCounter[mode].startcnt; + *min = 0; + + return TRUE; +} + +int CHAR_initCharOneArray( Char* ch ) +{ + int i; + int mode; + int ret = TRUE; + int first; + static unsigned int CharMakeSequenceNumber = 0; + if( initCharCounter[0].startcnt == -1 ) { + initCharCounter[0].startcnt = 0; + initCharCounter[0].cnt = initCharCounter[0].startcnt; + initCharCounter[0].endcnt = CHAR_playernum; + + initCharCounter[1].startcnt = initCharCounter[0].endcnt; + initCharCounter[1].cnt = initCharCounter[0].endcnt; + initCharCounter[1].endcnt = CHAR_playernum + CHAR_petnum; + + initCharCounter[2].startcnt = initCharCounter[1].endcnt; + initCharCounter[2].cnt = initCharCounter[1].endcnt; + initCharCounter[2].endcnt = CHAR_charanum; + } + if( ch->data[CHAR_WHICHTYPE] == CHAR_TYPEPLAYER ){ + mode = 0; + }else if( CHAR_TYPEPET == ch->data[CHAR_WHICHTYPE] ) { + mode = 1; + }else{ + mode = 2; + } + i = initCharCounter[mode].cnt; + first = TRUE; + while( 1 ){ + if( !first && i >= initCharCounter[mode].cnt ) { + ret = FALSE; + break; + } + if( CHAR_chara[i].use == FALSE ){ + ret = TRUE; + break; + }else{ + i++; + if( i >= initCharCounter[mode].endcnt ){ + i = initCharCounter[mode].startcnt; + first = FALSE; + } + } + } + if( ret ){ + typedef BOOL (*INITFUNC)(int index); + INITFUNC initfunc; + memset( &CHAR_chara[i] , 0, sizeof( Char ) ); + memcpy( &CHAR_chara[i] , ch , sizeof( Char ) ); + + initfunc = (INITFUNC)getFunctionPointerFromName( + ch->charfunctable[CHAR_INITFUNC].string ); + if( initfunc ) { + if( initfunc( i ) == FALSE ){ + CHAR_chara[i].use = FALSE; + ret = FALSE; + } + } + if( ret ){ + CHAR_chara[i].use = TRUE; + CHAR_constructFunctable( i ); + if( i + 1 >= initCharCounter[mode].endcnt ) { + initCharCounter[mode].cnt + = initCharCounter[mode].startcnt; + }else { + initCharCounter[mode].cnt = i+1; + } + CHAR_chara[i].CharMakeSequenceNumber = CharMakeSequenceNumber++; + if( CharMakeSequenceNumber == 0xffffffff) CharMakeSequenceNumber = 0; + } + }else{ + fprint( "Error: Char[%d] full\n", mode ); + } + return ret ? i: -1; +} + +void CHAR_removeHaveItem( Char* ch ) +{ + int i; + if( ch == NULL )return; + int itemMax=CheckCharMaxItemChar(ch); + for( i=0 ; iindexOfExistItems[i]; + ch->indexOfExistItems[i] = -1; + ITEM_endExistItemsOne( itemindex ); + } +} + +void CHAR_removeHavePoolItem( Char* ch ) +{ + int i; + if( ch == NULL )return; + for( i=0 ; iindexOfExistPoolItems[i]; + ch->indexOfExistPoolItems[i] = -1; + ITEM_endExistItemsOne( itemindex ); + } +} + +void CHAR_endCharData( Char* ch ) +{ + if( ch == NULL ){ + return; + } + CHAR_removeHaveItem( ch ); + CHAR_removeHavePoolItem( ch); + +#ifdef _CHAR_POOLITEM +// CHAR_removeHaveDepotItem( ch ); +#endif +#ifdef _CHAR_POOLPET +// CHAR_removeHaveDepotPet( ch ); +#endif + + ch->use = FALSE; +} + +void _CHAR_endCharOneArray( int index, char*file, int line ) +{ + Char* ch = NULL; + if( !CHAR_CHECKINDEX( index) ) return; + ch = CHAR_getCharPointer(index); + + if( ch == NULL ){ + print( "CHAR_endCharOneArray err ch == NULL :%d\n", index); + return; + } + CHAR_endCharData( ch ); +} +static char CHAR_dataString[STRINGBUFSIZ*16*2]; +BOOL CHAR_checksetdata( void ) +{ + int i; + char* strings[CHAR_DATAINTNUM + CHAR_DATACHARNUM]; + int stringnum=0; + for(i = 0; i < CHAR_DATAINTNUM ; i ++ ){ + if( CHAR_setintdata[i][0] != '#' ) + strings[stringnum++] = CHAR_setintdata[i]; + } + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + if( CHAR_setchardata[i][0] != '#' ) + strings[stringnum++] = CHAR_setchardata[i]; + } + if( ! checkStringsUnique( strings, stringnum , 1 ) ){ + fprint( "set????data is overlapped.\nIt is not allowed\n"); + return FALSE; + } + return TRUE; +} + +#define FLGRESERVESTRING "flg" +#define ITEMRESERVESTRING "item" +#define POOLITEMRESERVESTRING "poolitem" +#define SKILLRESERVESTRING "skill" +#define TITLERESERVESTRING "title" +#define ADDRESSBOOKRESERVESTRING "adr" +#define PETSERVERSTRING "pet" +#define PETITEMRESERVESTRING "pitem" +#define PETSKILLSERVERSTRING "psk" +#define POOLPETSERVERSTRING "poolpet" +#define ITEMPOOLRESERVESTRING "itempool" + +#define DATAENDCHECKPOINT "DATAEND" + +#ifdef _CHAR_POOLITEM +#define DEPOTITEMRESERVESTRING "Depotitem" +#endif +#ifdef _CHAR_POOLPET +#define DEPOTPETRESERVESTRING "Depotpet" +#endif + +char* CHAR_makeStringFromCharData( Char* one ) +{ + int i; + int petnum; + int strlength=0; + + if (!one) return "\0"; + + memset( CHAR_dataString, 0, sizeof(CHAR_dataString)); + for( i = 0 ; i < CHAR_DATAINTNUM ; i ++ ){ + char linedata[512]; + snprintf( linedata , sizeof(linedata), + "%s=%d" CHAR_DELIMITER, + CHAR_setintdata[i], + one->data[i] ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + char linedata[512]; + char escapebuffer[512]; + snprintf( linedata , sizeof(linedata), + "%s=%s" CHAR_DELIMITER, + CHAR_setchardata[i], + makeEscapeString( one->string[i].string, escapebuffer, + sizeof( escapebuffer) )); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + for( i = 0 ; i < arraysizeof( one->flg ) ; i ++ ){ + char linedata[512]; + snprintf( linedata , sizeof(linedata), + FLGRESERVESTRING "%d=%d" CHAR_DELIMITER, + i, one->flg[i]); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_SKILLMAXHAVE ; i ++ ){ + char linedata[512]; + char *skillstring="\0"; + if( one->haveSkill[i].use == TRUE) + skillstring = SKILL_makeStringFromSkillData( + &one->haveSkill[i].skill ); + if( skillstring == "\0" ) continue; + snprintf( linedata , sizeof( linedata ), + SKILLRESERVESTRING "%d=%s" CHAR_DELIMITER, + i,skillstring ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + int itemMax=CheckCharMaxItemChar(one); + for( i = 0 ; i < itemMax; i ++ ){ + char linedata[1024*8]; + char *itemstring="\0"; + if( one->indexOfExistItems[i] != -1 ) + itemstring = ITEM_makeStringFromItemIndex( + one->indexOfExistItems[i], 0); + if( itemstring == "\0" )continue; + snprintf( linedata , sizeof( linedata ), + ITEMRESERVESTRING "%d=%s" CHAR_DELIMITER, + i, itemstring); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_MAXPOOLITEMHAVE ; i ++ ){ + char linedata[1024*8]; + char *itemstring="\0"; + if( one->indexOfExistPoolItems[i] != -1 ) + itemstring = ITEM_makeStringFromItemIndex( + one->indexOfExistPoolItems[i], 0); + if( itemstring == "\0" )continue; + snprintf( linedata , sizeof( linedata ), + POOLITEMRESERVESTRING "%d=%s" CHAR_DELIMITER, + i, itemstring); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_TITLEMAXHAVE ; i ++ ){ + char linedata[512]; + if( one->indexOfHaveTitle[i]< 0 || one->indexOfHaveTitle[i] >= CHAR_TITLEMAXHAVE ) { + continue; + } + snprintf( linedata , sizeof( linedata ), + TITLERESERVESTRING "%d=%d" CHAR_DELIMITER, + i, one->indexOfHaveTitle[i] ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + for( i=0 ; i < ADDRESSBOOK_MAX ; i++ ){ + char linedata[1024]; + char *p; + p = ADDRESSBOOK_makeAddressbookString(&one->addressBook[i]); + if( strlen( p) == 0 ) { + continue; + } + snprintf( linedata ,sizeof(linedata), + ADDRESSBOOKRESERVESTRING "%d=%s" CHAR_DELIMITER, + i,p + ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + for( petnum = 0; petnum < CHAR_MAXPETHAVE; petnum ++ ) { + int petindex; + char linedata[1024*8]; + char *petstring="\0"; + petindex = one->unionTable.indexOfPet[petnum]; + if( !CHAR_CHECKINDEX(petindex))continue; + petstring = CHAR_makePetStringFromPetIndex( petindex); + if( petstring == "\0" ) continue; + snprintf( linedata , sizeof(linedata), + PETSERVERSTRING "%d=%s" CHAR_DELIMITER,petnum,petstring ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } + + for( petnum = 0; petnum < CHAR_MAXPOOLPETHAVE; petnum ++ ) { + int petindex; + char linedata[1024*8]; + char *petstring="\0"; + petindex = one->indexOfPoolPet[petnum]; + if( !CHAR_CHECKINDEX(petindex))continue; + petstring = CHAR_makePetStringFromPetIndex( petindex); + if( petstring == "\0" ) continue; + + //andy_log + if( strstr( petstring, "name:") == NULL || + strstr( petstring, "ownt:") == NULL ) { + LodBadPetString( "petstring", "poolpet string buffer err:", petnum); + fprint( "ANDY err poolpet string buffer err:\n%s\n", petstring); + goto RETURN; + } + + snprintf( linedata , sizeof(linedata), + POOLPETSERVERSTRING "%d=%s" CHAR_DELIMITER,petnum,petstring ); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err chardata buffer over\n"); + goto RETURN; + } + } +#ifdef _CHAR_FIXDATADEF + { + char linedata[1024]; + memset( linedata, 0, sizeof(linedata)); + snprintf( linedata , sizeof(linedata), + DATAENDCHECKPOINT "=%d" CHAR_DELIMITER, (int)time(NULL)/1000); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, linedata ); + + if( strlength > sizeof( CHAR_dataString ) ) { + LodBadPetString( "DATAENDCHECKPOINT", "err chardata buffer over", -1); + fprint( "err chardata buffer over:DATAENDCHECKPOINT !\n"); + goto MAKESTRINGERR; + } + } +#endif + +RETURN: + if( strstr( CHAR_dataString, DATAENDCHECKPOINT) == NULL ){ + LodBadPetString( CHAR_dataString, "err mk dataString no end", -1); + } + + return CHAR_dataString; +MAKESTRINGERR: + return "\0"; +} + +char* CHAR_makeStringFromCharIndex( int index ) +{ + if( 0 <= index && index <= CHAR_charanum /* index OK*/ + && CHAR_chara[index].use == TRUE ) + /* OK */; + else + return "\0"; + return CHAR_makeStringFromCharData(&CHAR_chara[index]); + +} + +BOOL CHAR_makeCharFromStringToArg( char* data, Char* one) +{ + int i; + int readindex=1, rightData=0; + + if( data[0] == '\0' ) + return FALSE; + { + char name[1024*8]; + char *sp = strstr( data, "name="); + char *sp2 = strstr( data, "ownt="); + if( sp && sp2 ){ + snprintf( name, sp2-sp-5, "%s", sp+5 ); + //print("\nʼ½:%s ", name ); + }else + ;//print("\nʼ½ƴ! "); + + if( data[strlen(data)-2] != '\n' ){ + ;//print("\n ½!:%s ",data+strlen(data)-20 ); + } + + if( strlen(name) > 16 ){ + ;//print("ƹ!! :%s :%d ", name ,strlen(name) ); + } + } + + memset( one , 0 , sizeof( Char )); + CHAR_getDefaultChar(one, 0); + // Robin 0726 default RidePet + one->data[CHAR_RIDEPET] = -1; + strcpysafe( one->string[CHAR_FMNAME].string, + sizeof( one->string[CHAR_FMNAME].string), "\0" ); + one->data[CHAR_FMINDEX] = -1; +#ifdef _PETSKILL_BECOMEPIG + one->data[CHAR_BECOMEPIG] = -1; + one->data[CHAR_BECOMEPIG_BBI] = 100250; +#endif + + while( 1 ){ + BOOL ret; + char linebuf[1024*8]; + char firstToken[1024]; + char secondToken[1024*8]; + memset( linebuf, 0, sizeof( linebuf)); + memset( firstToken, 0, sizeof( firstToken)); + memset( secondToken, 0, sizeof( secondToken)); + ret = getStringFromIndexWithDelim( data ,CHAR_DELIMITER, + readindex, + linebuf, sizeof( linebuf ) ); + if( ret == FALSE )break; + if( linebuf[0] == '#' || + linebuf[0] == '\n' || + linebuf[0] == '\0' ){ + readindex ++; + continue; + } + ret = getStringFromIndexWithDelim( linebuf , "=" , 1 , + firstToken , + sizeof(firstToken) ); + if( ret == FALSE ) return FALSE; + strcpysafe( secondToken , sizeof( secondToken ), + linebuf + strlen(firstToken) + strlen("=") ); + for( i = 0 ; i < CHAR_DATAINTNUM ; i ++ ){ + if( strcmp(firstToken ,CHAR_setintdata[i] ) == 0 ){ + one->data[i] = atoi( secondToken ); + goto NEXT; + } + } + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + if( strcmp( firstToken ,CHAR_setchardata[i] ) == 0 ){ + strcpysafe( one->string[i].string, + sizeof(one->string[i].string), + makeStringFromEscaped(secondToken) ); + if( strlen( one->string[i].string ) > 128 ){ + //print(" CHARDATA_to_long!!:%s:%d ", one->string[i].string, strlen( one->string[i].string ) ); + one->string[i].string[0]=0; + } + goto NEXT; + } + } + if( strncmp( firstToken , FLGRESERVESTRING, + strlen( FLGRESERVESTRING ) ) == 0 ){ + int flgindex; + flgindex = atoi( firstToken+strlen(FLGRESERVESTRING) ); + if( flgindex < 0 || arraysizeof( one->flg ) <= flgindex ) + ; + else + one->flg[flgindex] = atoi( secondToken ); + + goto NEXT; + } + if( strncmp( firstToken , ITEMRESERVESTRING, + strlen( ITEMRESERVESTRING ) ) == 0 ){ + int itemindex; + if( strcmp( secondToken, NULLITEM) == 0 ) + goto NEXT; + itemindex = atoi( firstToken+strlen(ITEMRESERVESTRING) ); + int itemMax=CheckCharMaxItemChar(one); + if( itemindex < 0 || itemMax <= itemindex + || one->indexOfExistItems[itemindex] != -1 ){ + ; + }else{ + ITEM_Item itmone; + BOOL ret; + + ret = ITEM_makeExistItemsFromStringToArg( secondToken, &itmone, 0); + + if( ret == TRUE ){ + int existitemindex; + existitemindex = ITEM_initExistItemsOne( &itmone ); + one->indexOfExistItems[itemindex] = existitemindex; +#ifdef _ITEM_USE_TIME + if(ITEM_getInt( existitemindex, ITEM_USETIME) > 0){ + if(ITEM_getInt( existitemindex, ITEM_USETIME)<(int)time(NULL)){ + ITEM_endExistItemsOne(existitemindex); + one->indexOfExistItems[itemindex] = -1; + } + } +#endif + } + } + goto NEXT; + } + if( strncmp( firstToken , POOLITEMRESERVESTRING, + strlen( POOLITEMRESERVESTRING ) ) == 0 ){ + int itemindex; + if( strcmp( secondToken, NULLITEM) == 0 ) + goto NEXT; + itemindex = atoi( firstToken+strlen(POOLITEMRESERVESTRING) ); + if( itemindex < 0 || CHAR_MAXPOOLITEMHAVE <= itemindex + || one->indexOfExistPoolItems[itemindex] != -1 ){ + ; + }else{ + ITEM_Item itmone; + BOOL ret; + ret = ITEM_makeExistItemsFromStringToArg( secondToken , &itmone, 0 ); + + if( ret == TRUE ){ + int existitemindex; + existitemindex = ITEM_initExistItemsOne( &itmone ); + one->indexOfExistPoolItems[itemindex] = existitemindex; + } + } + goto NEXT; + } + if( strncmp( firstToken , SKILLRESERVESTRING, + strlen( SKILLRESERVESTRING ) ) == 0 ){ + int skillindex; + if( strcmp( secondToken, NULLSKILL) == 0 ) + goto NEXT; + skillindex =atoi( firstToken+strlen(SKILLRESERVESTRING) ); + if( skillindex < 0 || CHAR_SKILLMAXHAVE <= skillindex + || one->haveSkill[skillindex].use == TRUE ){ + }else{ + BOOL ret; + Skill skillone; + ret=SKILL_makeSkillFromStringToArg(secondToken,&skillone); + + if( ret == TRUE ){ + memcpy( &one->haveSkill[skillindex].skill , &skillone, + sizeof( Skill )); + one->haveSkill[skillindex].use = TRUE; + } + } + goto NEXT; + } + if( strncmp( firstToken , TITLERESERVESTRING, + strlen( TITLERESERVESTRING ) ) == 0 ){ + int titlenumber=atoi(firstToken+strlen(TITLERESERVESTRING)); + if( titlenumber < 0 || CHAR_TITLEMAXHAVE <= titlenumber ){ + }else{ + int titleindex = atoi( secondToken ); + if( TITLE_getTitleIndex( titleindex) != -1) + one->indexOfHaveTitle[titlenumber] = titleindex; + } + goto NEXT; + } + if( strncmp( firstToken , ADDRESSBOOKRESERVESTRING, + strlen( ADDRESSBOOKRESERVESTRING ) ) == 0 ){ + int addressnumber = atoi( firstToken + +strlen(ADDRESSBOOKRESERVESTRING)); + if( addressnumber < 0 || ADDRESSBOOK_MAX <= addressnumber ){ + }else{ + ADDRESSBOOK_makeAddressbookEntry( secondToken, + &one + ->addressBook[ + addressnumber]); + } + goto NEXT; + } + if( strncmp( firstToken , PETSERVERSTRING, + strlen( PETSERVERSTRING ) ) == 0 ){ + Char ch; + int ret; + int petnumber = atoi( firstToken+strlen(PETSERVERSTRING)); + if( !CHAR_CHECKPETINDEX( petnumber)) goto NEXT; + ret = CHAR_makePetFromStringToArg(secondToken,&ch, petnumber); + if( ret == TRUE ){ + int petindex = PET_initCharOneArray( &ch ); + if( petindex < 0 ){ + print( "ʧܡ\n"); + } + one->unionTable.indexOfPet[petnumber] = petindex; + goto NEXT; + }else{ + LodBadPetString( data, "ܼ", petnumber); + + fprint( " ַ ޷\n"); + return FALSE; + } + } + if( strncmp( firstToken , POOLPETSERVERSTRING, strlen( POOLPETSERVERSTRING ) ) == 0 ){ + + Char ch; + int ret; + int petnumber = atoi( firstToken+strlen(POOLPETSERVERSTRING)); + if( !CHAR_CHECKPOOLPETINDEX( petnumber)) goto NEXT; + ret = CHAR_makePetFromStringToArg( secondToken, &ch, petnumber); + if( ret == TRUE ) { + int petindex = PET_initCharOneArray( &ch ); + if( petindex < 0 ) { + fprint( " ޷\n"); + } + one->indexOfPoolPet[petnumber] = petindex; + goto NEXT; + }else{ + LodBadPetString( data, "err *total", petnumber); + fprint( " ϳɳַ ޷\n"); + return FALSE; + } + } + + if( strncmp( firstToken , DATAENDCHECKPOINT, strlen( DATAENDCHECKPOINT ) ) == 0 ){ + rightData=1; + goto NEXT; + } + + + + NEXT: + readindex++; + } + // Robin 0913 bad_chardata + { + char name[1024*8]; + char* sp = strstr( data, "name="); + // shan add + char *sp2 = strstr( data, "ownt="); + if( sp && sp2 ){ + snprintf( name, sp2-sp-5, "%s", sp+5 ); + //print("\n½ɹ :%s ", name ); + } + else + ;//print("\n½ɹ ƴ! "); + + if( data[strlen(data)-2] != '\n' ){ + //print("\nҵ½! "); + return FALSE; + } + } + if( rightData != 1 ){ + return FALSE; + } + return TRUE; +} +static char CHAR_petdataString[1024*8]; + +char* CHAR_makePetStringFromPetIndex( int petindex) +{ + int i; + int strlength = 0; + + memset( CHAR_petdataString, 0, sizeof(CHAR_petdataString)); + + for( i = 0 ; i < CHAR_DATAINTNUM ; i ++ ){ + char linedata[1024]; + +#ifdef _SIMPLIFY_PETSTRING + if( CHAR_getInt( petindex, i) == 0 ) continue; +#endif + snprintf( linedata , sizeof(linedata), + "%s:%d" NONCHAR_DELIMITER, CHAR_setintdata[i], CHAR_getInt( petindex,i) ); + strcpysafe( &CHAR_petdataString[strlength], + sizeof( CHAR_petdataString ) - strlength, linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_petdataString ) ) { + fprint( "err petdata buffer over\n"); + return "\0"; + } + } + + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + char linedata[1024]; + char escapebuffer[1024]; +#ifdef _SIMPLIFY_PETSTRING + if( CHAR_getChar( petindex, i) == "\0" + && strcmp( CHAR_setchardata[i], "name") + && strcmp( CHAR_setchardata[i], "ownt") ) + continue; +#endif + snprintf( linedata , sizeof(linedata), + "%s:%s" NONCHAR_DELIMITER, + CHAR_setchardata[i], + makeEscapeString( CHAR_getChar(petindex, i), escapebuffer, + sizeof( escapebuffer) )); + + strcpysafe( &CHAR_petdataString[strlength], + sizeof( CHAR_petdataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_petdataString ) ) { + fprint( " ݻ岻\n"); + return "\0"; + } + } + + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + int petskillid; + char linedata[1024]; + petskillid = CHAR_getPetSkill( petindex, i); + if( PETSKILL_getPetskillArray( petskillid) == -1 ) continue; + snprintf( linedata , sizeof(linedata), + PETSKILLSERVERSTRING "%d:%d" NONCHAR_DELIMITER,i ,petskillid ); + strcpysafe( &CHAR_petdataString[strlength], + sizeof( CHAR_petdataString ) - strlength, linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_petdataString ) ) { + fprint( " ݻ岻\n"); + return "\0"; + } + } + +#ifdef _PET_ITEM + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + char linedata[1024*8]; + char *itemstring="\0"; + if( CHAR_getItemIndex( petindex, i) != -1 ) + itemstring = ITEM_makeStringFromItemIndex(CHAR_getItemIndex( petindex, i), 1); + if( itemstring == "\0" )continue; + snprintf( linedata , sizeof( linedata ), PETITEMRESERVESTRING "%d:%s" NONCHAR_DELIMITER, i, itemstring); + strcpysafe( &CHAR_petdataString[strlength], sizeof( CHAR_petdataString ) - strlength, linedata ); + + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_petdataString ) ) { + fprint( " ݻ岻\n"); + return "\0"; + } + } +#endif + + if( strstr( CHAR_petdataString, "name:") == NULL || + strstr( CHAR_petdataString, "ownt:") == NULL ){ + LodBadPetString( CHAR_petdataString, "string name err", -1); + } + return CHAR_petdataString; +} +void LodBadPetString( char *data, char *err, int ti) +{ + FILE *fp=NULL; + if( data == NULL || data == "" || strlen( data) <= 0 ) return; + if( (fp=fopen( "badpetstring.txt", "a+")) == NULL ) return; + fprintf( fp, "ti:%d %s:%s\n", ti, err, data); + + fclose( fp); +} +int CHAR_makePetFromStringToArg( char *src, Char *ch, int ti) +{ + int readnum = 1; + int rc; + BOOL found; + char buff[1024*8]; + char petfirstToken[1024]; + char petsecondToken[1024*8]; + int i, findE=0; + + memset( ch, 0, sizeof( Char)); + CHAR_getDefaultChar(ch, 31010); + + if( strstr( src, "name:") == NULL || + strstr( src, "ownt:") == NULL ){//findE + LodBadPetString( src, "make name err", ti); + fprint( "err PetString make name err\n"); + return -1; + } + + while( 1 ) { + rc = getStringFromIndexWithDelim( src, NONCHAR_DELIMITER, readnum, buff, sizeof( buff )); + if( rc == TRUE ) { + if( buff[0] == '#' || buff[0] == '\n' || buff[0] == '\0' ){ + readnum ++; + continue; + } + } + if( rc == TRUE ) { + readnum ++; + rc = getStringFromIndexWithDelim( buff , ":" , 1 , + petfirstToken , + sizeof(petfirstToken) ); + if( rc == FALSE ) break; + strcpysafe( petsecondToken , sizeof( petsecondToken ), + buff + strlen(petfirstToken) + strlen(":") ); +// rc = getStringFromIndexWithDelim( buff , ":" , 2 , +// petsecondToken , +// sizeof(petsecondToken) ); + found = FALSE; + for( i = 0 ; i < CHAR_DATAINTNUM ; i ++ ){ + if( strcmp(petfirstToken ,CHAR_setintdata[i] ) == 0 ){ + ch->data[i] = atoi( petsecondToken ); + found = TRUE; + break; + } + } + if( !found ) { + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + if( strcmp( petfirstToken ,CHAR_setchardata[i] ) == 0 ){ + strcpysafe( ch->string[i].string, + sizeof(ch->string[i].string), + makeStringFromEscaped(petsecondToken) ); + found = TRUE; + findE = 1; + break; + } + } + } + if( !found) { +#ifdef _PET_ITEM + if( strncmp( petfirstToken , PETITEMRESERVESTRING, strlen( PETITEMRESERVESTRING ) ) == 0 ) + { + int itemindex; + itemindex = atoi( petfirstToken+strlen(PETITEMRESERVESTRING) ); + if( itemindex < 0 || CHAR_MAXPETITEMHAVE <= itemindex || ch->indexOfExistItems[itemindex] != -1 ){ + ; + }else{ + ITEM_Item itmone; + BOOL ret; + + ret = ITEM_makeExistItemsFromStringToArg( petsecondToken , &itmone,1); + if( ret == TRUE ){ + int existitemindex; + existitemindex = ITEM_initExistItemsOne( &itmone ); + ch->indexOfExistItems[itemindex] = existitemindex; + found = TRUE; + } + } + } +#endif + + } + if( !found ) { + if( strncmp( petfirstToken , PETSKILLSERVERSTRING, + strlen( PETSKILLSERVERSTRING ) ) == 0 ){ + int petskillnum = atoi( petfirstToken + strlen( PETSKILLSERVERSTRING)); + if( CHAR_CHECKPETSKILLINDEX( petskillnum) ) { + int petskillid = atoi( petsecondToken ); + if( PETSKILL_getPetskillArray(petskillid) != -1) { + ch->unionTable.indexOfPetskill[petskillnum] = petskillid; + found = TRUE; + } + } + } + } + if( !found) { + // fprint( "makePetFromString err?: %s : %s [%s] \n" , src, buff, petfirstToken ); + } + }else { + break; + } + } + + if( findE == 0 ){//findE + LodBadPetString( src, "make charstr err", ti); + fprint( "err PetString make charstr err\n"); + return -1; + } + + return TRUE; +} + +#ifdef _PERSONAL_FAME // Arminius 8.30: + +void CHAR_earnFame(int index, int fame) +{ + int oldfame=CHAR_getInt(index, CHAR_FAME)+fame; +#ifdef _NEW_MANOR_LAW + int momentum = CHAR_getInt(index,CHAR_MOMENTUM) + fame; +#endif + + if (oldfame>MAX_PERSONALFAME) oldfame=MAX_PERSONALFAME; + if (oldfame<0) oldfame=0; + CHAR_setInt(index, CHAR_FAME, oldfame); +#ifdef _NEW_MANOR_LAW + if(momentum > MAX_PERSONAL_MOMENTUM) momentum = MAX_PERSONAL_MOMENTUM; + else if(momentum < 0) momentum = 0; + CHAR_setInt(index,CHAR_MOMENTUM,momentum); +#endif +} +#endif + +// CoolFish: 2001/10/11 Unique Pet Code +#ifdef _UNIQUE_P_I +void CHAR_setPetUniCode(int petindex) +{ + if( strcmp( CHAR_getChar(petindex, CHAR_UNIQUECODE), "" ) == 0 || + strstr( CHAR_getChar(petindex, CHAR_UNIQUECODE), "_" ) != NULL || + strstr( CHAR_getChar(petindex, CHAR_UNIQUECODE), UNIQUE_KEYCODEPET ) == NULL ){ + char petbuf[256]; + time_t t1; + time(&t1); + sprintf(petbuf, "%ld%s%d%d", t1, UNIQUE_KEYCODEPET, getServernumber(), unique_p); + unique_p++; + if (unique_p >= MAX_UNIQUE_P_I) + unique_p = 0; + CHAR_setChar(petindex, CHAR_UNIQUECODE, petbuf); + } +} + +void ITEM_setItemUniCode(int itemindex) +{ + if( strcmp( ITEM_getChar(itemindex, ITEM_UNIQUECODE), "") == 0 || + strstr( ITEM_getChar(itemindex, ITEM_UNIQUECODE), "_") != NULL ){ + char itembuf[256]; + time_t t1; + time(&t1); + + sprintf(itembuf, "%ld%s%d%d%d", t1, "i", unique_i, getServernumber(), UNIQUE_KEYCODEITEM); + + unique_i++; + if (unique_i >= MAX_UNIQUE_P_I) + unique_i = 0; + ITEM_setChar(itemindex, ITEM_UNIQUECODE, itembuf); + } +} + +void CHAR_DetainSameItem( int charaindex, int itemindex) +{ + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, 100000); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + + LogItem( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "SysDeleteSame(ϵͳɾظ)", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); +// ITEM_endExistItemsOne( itemindex); +} + +void CHAR_DetainSamePet( int charaindex, int petindex) +{ + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, 100000); + CHAR_setChar( petindex, CHAR_OWNERCDKEY, "SYS"); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, "SYS"); + CHAR_complianceParameter( petindex ); + LogPet( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "SysDeleteSame(ɾظ)", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); +// CHAR_endCharOneArray( petindex ); +} + +void CHAR_DetainSameUCodePet( int charaindex, int petindex, int Ti) +{ + if( Ti == -1 ){ + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i++ ) { + int pindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( pindex) ) continue; + if( pindex == petindex ) break; + } + if( i >= CHAR_MAXPETHAVE ) return; + CHAR_setCharPet( charaindex, i, -1); + }else{ + CHAR_setCharPet( charaindex, Ti, -1); + } + CHAR_DetainSamePet( charaindex, petindex); +} + +void CHAR_DetainSameUCodePoolPet( int charaindex, int petindex, int Ti) +{ + if( Ti == -1 ){ + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i++ ) { + int pindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( pindex) ) continue; + if( pindex == petindex ) break; + } + if( i >= CHAR_MAXPETHAVE ) return; + CHAR_setCharPoolPet( charaindex, i, -1); + }else{ + CHAR_setCharPoolPet( charaindex, Ti, -1); + } + CHAR_DetainSamePet( charaindex, petindex); +} + +void CHAR_DetainSameUCodeItem( int charaindex, int itemindex, int Ti) +{ + if( Ti == -1 ){ + int i; + for( i = 0; i < CheckCharMaxItem(charaindex); i++ ) { + int iindex = CHAR_getItemIndex( charaindex, i); + if( !ITEM_CHECKINDEX( iindex) ) continue; + if( iindex == itemindex ) break; + } + if( i >= CheckCharMaxItem(charaindex) ) return; + CHAR_setItemIndex( charaindex, i, -1); + }else{ + CHAR_setItemIndex( charaindex, Ti, -1); + } + CHAR_DetainSameItem( charaindex, itemindex); +} + +void CHAR_DetainSameUCodePoolItem( int charaindex, int itemindex, int Ti) +{ + if( Ti == -1 ){ + int i; + for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i++ ) { + int iindex = CHAR_getPoolItemIndex( charaindex, i); + if( !ITEM_CHECKINDEX( iindex) ) continue; + if( iindex == itemindex ) break; + } + if( i >= CHAR_MAXPOOLITEMHAVE ) return; + CHAR_setPoolItemIndex( charaindex, i, -1); + }else{ + CHAR_setPoolItemIndex( charaindex, Ti, -1); + } + CHAR_DetainSameItem( charaindex, itemindex); +} +#endif + +// Arminius 12.15 жǷʿ +int IsMale(int charindex) { + int bbi=CHAR_getInt(charindex, CHAR_BASEBASEIMAGENUMBER); + + if ((bbi==SPR_001em)||(bbi==SPR_002em)||(bbi==SPR_003em)||(bbi==SPR_004em)|| + (bbi==SPR_011em)||(bbi==SPR_012em)||(bbi==SPR_013em)||(bbi==SPR_014em)|| + (bbi==SPR_021em)||(bbi==SPR_022em)||(bbi==SPR_023em)||(bbi==SPR_024em)|| + (bbi==SPR_031em)||(bbi==SPR_032em)||(bbi==SPR_033em)||(bbi==SPR_034em)|| + (bbi==SPR_041em)||(bbi==SPR_042em)||(bbi==SPR_043em)||(bbi==SPR_044em)|| + (bbi==SPR_051em)||(bbi==SPR_052em)||(bbi==SPR_053em)||(bbi==SPR_054em)) + { + return 1; + } + + return 0; +} + +// Arminius 12.15 жǷŮʿ +int IsFemale(int charindex) { + int bbi=CHAR_getInt(charindex, CHAR_BASEBASEIMAGENUMBER); + + if ((bbi==SPR_061em)||(bbi==SPR_062em)||(bbi==SPR_063em)||(bbi==SPR_064em)|| + (bbi==SPR_071em)||(bbi==SPR_072em)||(bbi==SPR_073em)||(bbi==SPR_074em)|| + (bbi==SPR_081em)||(bbi==SPR_082em)||(bbi==SPR_083em)||(bbi==SPR_084em)|| + (bbi==SPR_091em)||(bbi==SPR_092em)||(bbi==SPR_093em)||(bbi==SPR_094em)|| + (bbi==SPR_101em)||(bbi==SPR_102em)||(bbi==SPR_103em)||(bbi==SPR_104em)|| + (bbi==SPR_111em)||(bbi==SPR_112em)||(bbi==SPR_113em)||(bbi==SPR_114em)) + { + return 1; + } + + return 0; +} + +#ifdef _TYPE_TOXICATION +BOOL CHAR_CanCureFlg( int charaindex, char *arg) +{ + int fd = getfdFromCharaIndex( charaindex ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) return TRUE; + if( getToxication( fd) == 1 ){ + if( strstr( arg, "FALSE") == 0 ) { + char buf[256]; + sprintf( buf,"ж޷%s", arg); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + } + return FALSE; + } + return TRUE; +} +#endif + +INLINE int CHAR_AddMaxExp( int charaindex, int addexp) +{ + int Myexp = CHAR_getInt( charaindex, CHAR_EXP); + Myexp = min( Myexp + addexp, 1224160000 ); + CHAR_setInt( charaindex, CHAR_EXP, Myexp ); + return addexp; +} + +INLINE int CHAR_setMaxExpFromLevel( int charaindex, int level) +{ +#ifdef _NEWOPEN_MAXEXP + CHAR_setInt( charaindex, CHAR_EXP, 0); + return 0; +#else + int LVexp; + if( (LVexp = CHAR_GetLevelExp( charaindex, level+1)) < 0 )return -1; + CHAR_setInt( charaindex, CHAR_EXP, LVexp); + return LVexp; +#endif +} + +INLINE int CHAR_setMaxExp( int charaindex, unsigned long int Setexp) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return -1; + CHAR_setInt( charaindex, CHAR_EXP, Setexp); + return Setexp; +} +#ifdef _NEWOPEN_MAXEXP +INLINE int CHAR_ChangeExp( int charaindex ) +{ + int level, defexp, Myexp; + if( !CHAR_CHECKINDEX( charaindex) ) return -1; + + level = CHAR_getInt( charaindex, CHAR_LV); + if( (defexp = CHAR_GetOldLevelExp( level)) < 0 ) return -1; + Myexp = CHAR_getInt( charaindex, CHAR_OLDEXP); + + if( Myexp > CHAR_GetOldLevelExp( level+1) ){ + Myexp = 0; + }else if( Myexp >= defexp ){ + Myexp = Myexp - defexp; + } + if( Myexp < 0 ) Myexp = 0; + + CHAR_setInt( charaindex, CHAR_EXP, Myexp); + CHAR_setInt( charaindex, CHAR_OLDEXP, 0); + + CHAR_send_P_StatusString( charaindex ,CHAR_P_STRING_EXP|CHAR_P_STRING_LV); + return Myexp; +} + +INLINE int CHAR_HandleExp( int charaindex ) +{ + int needexp, level, Myexp; + if( !CHAR_CHECKINDEX( charaindex) ) return -1; + level = CHAR_getInt( charaindex, CHAR_LV); + Myexp = CHAR_getInt( charaindex, CHAR_EXP); + if( (needexp = CHAR_GetLevelExp( charaindex, level+1)) == -1 ) return -1; + Myexp = Myexp - needexp; + if ( Myexp > 0){ + CHAR_earnFame(charaindex, needexp / 20000); + } + if( Myexp < 0 ) Myexp = 0; + CHAR_setInt( charaindex, CHAR_EXP, Myexp); + return Myexp; +} +#endif + +INLINE int _CHAR_AddPileItem( char *file, int line, int charaindex, int itemindex) +{ +#ifdef _ITEM_PILENUMS + int itempile , mypile, surplus, ret=-1; + + surplus = CHAR_findSurplusItemBox( charaindex); + itempile = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + mypile = CHAR_getMyMaxPilenum( charaindex); + + if( itempile > (surplus*mypile) || itempile <= 0 ){ + return -1; + } + + if( mypile >= itempile ){ + ret = CHAR_addItemSpecificItemIndex( charaindex, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( itemindex); + return -1; + } + CHAR_sendItemDataOne( charaindex, ret); + }else{ + int newindex[10]={ -1,-1,-1,-1,-1, + -1,-1,-1,-1,-1}; + int i, ti=0, ItemID, MaxPile; + MaxPile = itempile; + ItemID = ITEM_getInt( itemindex, ITEM_ID); + while( MaxPile > 0 ){ + if( ti >= 10 ) return -1; + newindex[ti] = ITEM_makeItemAndRegist( ItemID); + if( !ITEM_CHECKINDEX( newindex[ti]) ) return -1; + if( mypile > MaxPile ) mypile = MaxPile; + ITEM_setInt( newindex[ti], ITEM_USEPILENUMS, mypile); + ti++; + MaxPile -= mypile; + if( MaxPile < 0 ) return -1; + } + for( i=0; i<10; i++ ){ + if( newindex[i] == -1 ) break; + ret = CHAR_addItemSpecificItemIndex( charaindex, newindex[i]); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( newindex[i]); + return -1; + } + CHAR_sendItemDataOne( charaindex, ret); + } + ITEM_endExistItemsOne( itemindex); + } + return ret; +#endif +} + + +INLINE int _CHAR_DelItem( char *file, int line, int charaindex, int ti, int num, int flg) +{ +// char token[256]; + int pilenum; + int itemindex = CHAR_getItemIndex( charaindex , ti ); + if( !ITEM_CHECKINDEX(itemindex) ) return 0; +#ifdef _ITEM_PILENUMS + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + if( pilenum < num ) return FALSE; + pilenum = pilenum - num; + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + if( pilenum <= 0 ){ +#endif +/* + if( flg == 1 ){ + sprintf( token, "%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + } +*/ + CHAR_setItemIndex( charaindex, ti, -1); + ITEM_endExistItemsOne( itemindex); +#ifdef _ITEM_PILENUMS + } +#endif + CHAR_sendItemDataOne( charaindex, ti); + + return 1; +} + +int CHAR_getMaxHaveGold( int charaindex) +{ + int MaxGold; +#ifdef _FIX_MAX_GOLD // WON ADD Ǯ + int trans = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION); + switch(trans){ + case 0: + MaxGold = 1000000; + break; + case 1: + MaxGold = 2000000; + break; + case 2: + MaxGold = 5000000; + break; + case 3: + MaxGold = 10000000; + break; + case 4: + MaxGold = 50000000; + break; + default: + MaxGold = 100000000; + break; + } +#else + MaxGold = CHAR_MAXGOLDHAVE; +#endif + + return MaxGold; +} + +INLINE int _CHAR_AddGold( char *file, int line, int charaindex, int gold) +{ + char token[256]; + int MyGold, MaxGold; + + MaxGold = CHAR_getMaxHaveGold( charaindex); + MyGold = CHAR_getInt( charaindex, CHAR_GOLD); + MyGold = (MyGold>MaxGold)?MaxGold:MyGold; + gold = (gold>MaxGold)?MaxGold:gold; + sprintf( token, "õ%dʯ", gold); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + MyGold += gold; + + if( MyGold > MaxGold ){ + int reGolds=0; + int MyGBGold = CHAR_getInt( charaindex, CHAR_PERSONAGOLD); + reGolds = MyGold - MaxGold; + MyGBGold += reGolds; + MyGBGold = (MyGBGold > CHAR_MAXPERSONAGOLD)?CHAR_MAXPERSONAGOLD:MyGBGold; + CHAR_setInt( charaindex, CHAR_PERSONAGOLD, MyGBGold); + sprintf( token,"%d ʣࣺ%d ", reGolds, CHAR_getInt( charaindex, CHAR_PERSONAGOLD )); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + LogBankStone( CHAR_getChar( charaindex, CHAR_NAME ), CHAR_getChar( charaindex, CHAR_CDKEY ), + charaindex, reGolds, + "GB_Bank_save()", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X ), CHAR_getInt( charaindex, CHAR_Y ), + CHAR_getInt( charaindex, CHAR_GOLD ), + CHAR_getInt( charaindex, CHAR_PERSONAGOLD ) + ); + MyGold = MaxGold; + } + CHAR_setInt( charaindex, CHAR_GOLD, MyGold); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + + return 1; +} + +INLINE int _CHAR_DelGold( char *file, int line, int charaindex, int gold) +{ + char token[256]; + int MyGold, MaxGold; + + MaxGold = CHAR_getMaxHaveGold( charaindex); + MyGold = CHAR_getInt( charaindex, CHAR_GOLD); + MyGold = (MyGold>MaxGold)?MaxGold:MyGold; + gold = (gold>MaxGold)?MaxGold:gold; + + if( MyGold < gold ){ + sprintf( token, "û㹻ʯң(%dʯ)", gold); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return 0; + } + MyGold -= gold; + MyGold = ( MyGold < 0 )?0:MyGold; + CHAR_setInt( charaindex, CHAR_GOLD, MyGold); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + return 1; +} + + +#ifdef _CHAR_POOLITEM +INLINE int _CHAR_getDepotItemIndex( char *file, int line, int index ,int iindex) +{ + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + if( CHAR_MAXDEPOTITEMHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return -1; + } + + if( !CHAR_CheckDepotItem( index) ){ + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + + return CHAR_chara[index].indexOfExistDepotItems[iindex]; +} + +INLINE int _CHAR_setDepotItemIndex( char *file, int line, int index ,int iindex,int id ) +{ + int buf; + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return -1; + } + if( CHAR_MAXDEPOTITEMHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d \n", file, line); + return -1; + } + if( !CHAR_CheckDepotItem( index) ){ + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + buf = CHAR_chara[index].indexOfExistDepotItems[iindex]; + CHAR_chara[index].indexOfExistDepotItems[iindex] = id; + return buf; +} +void CHAR_removeHaveDepotItem( Char* ch ) +{ + if( ch == NULL )return; + if( ch->indexOfExistDepotItems == NULL ) return; + freeMemory( ch->indexOfExistDepotItems ); + ch->indexOfExistDepotItems = NULL; +} + +void CHAR_removeDepotItem( int charaindex) +{ + int i,itemindex; + Char* ch = NULL; + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( !CHAR_CheckDepotItem( charaindex) ) return; //ֿδ + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ){ + print( "removeDepotItem err ch == NULL :%d\n", charaindex); + return; + } + + for( i=0; iindexOfExistDepotItems[i]; + if( !ITEM_CHECKINDEX( itemindex) ) continue; + itemstring = ITEM_makeStringFromItemIndex( ch->indexOfExistDepotItems[i], 0); + if( itemstring == "\0" )continue; + + snprintf( linedata , sizeof( linedata ), + DEPOTITEMRESERVESTRING "%d=%s" CHAR_DELIMITER, i, itemstring); + + strcpysafe( &CHAR_dataString[strlength], sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + return "\0"; + } + } + return CHAR_dataString; +} + +BOOL CHAR_makeDepotItemStringToChar( int charaindex, char* data) +{ + int readindex=1, itemindex; + Char* ch = NULL; + BOOL ret; + char firstToken[256], secondToken[4096], linebuf[4096]; + + if( data[0] == '\0' ) + return -1; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ){ + print( "makeDepotItem err ch == NULL :%d\n", charaindex); + return FALSE; + } + + while( 1 ){ + memset( linebuf, 0, sizeof( linebuf)); + memset( firstToken, 0, sizeof( firstToken)); + memset( secondToken, 0, sizeof( secondToken)); + ret = getStringFromIndexWithDelim( data ,CHAR_DELIMITER, + readindex, linebuf, sizeof( linebuf ) ); + if( ret == FALSE )break; + if( linebuf[0] == '#' || linebuf[0] == '\n' || linebuf[0] == '\0' ){ + goto NEXT; + } + if( (ret=getStringFromIndexWithDelim( linebuf , "=" , 1 , + firstToken, sizeof(firstToken) )) == FALSE ) return FALSE; + strcpysafe( secondToken , sizeof( secondToken ), + linebuf + strlen( firstToken) + strlen("=") ); + + if( strncmp( firstToken, DEPOTITEMRESERVESTRING, strlen( DEPOTITEMRESERVESTRING)) == 0 ){ + if( strcmp( secondToken, NULLITEM) == 0 ) goto NEXT; + itemindex = atoi( firstToken+strlen(DEPOTITEMRESERVESTRING) ); + if( itemindex < 0 || CHAR_MAXDEPOTITEMHAVE <= itemindex + || ch->indexOfExistDepotItems[itemindex] != -1 ){ + ; + }else{ + ITEM_Item itmone; + ret = ITEM_makeExistItemsFromStringToArg( secondToken , &itmone, 0 ); + if( ret == TRUE ){ + int existitemindex; + existitemindex = ITEM_initExistItemsOne( &itmone ); + ch->indexOfExistDepotItems[itemindex] = existitemindex; + } + } + goto NEXT; + } + print( "2??? : %s[%s]\n" , linebuf, firstToken ); +NEXT: + readindex++; + } + return TRUE; +} + +void CHAR_ShowMyDepotItems( int charaindex) +{ + int i, itemindex; + + print( "\nShowMyDepotItems:\n"); + if( !CHAR_CheckDepotItem( charaindex) ) return; + for( i=0; iindexOfExistDepotItems == NULL ) return FALSE; + return TRUE; +} + +#endif + + +#ifdef _CHAR_POOLPET +INLINE int _CHAR_getDepotPetIndex( char *file, int line, int index ,int iindex) +{ + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + if( CHAR_MAXDEPOTPETHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d from %s:%d \n", __FILE__, __LINE__,file, line); + return -1; + } + + if( !CHAR_CheckDepotPet( index) ){ + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + + return CHAR_chara[index].indexOfExistDepotPets[iindex]; +} + +INLINE int _CHAR_setDepotPetIndex( char *file, int line, int index ,int iindex,int id ) +{ + int buf; + if( !CHAR_CHECKINDEX(index)) { + print( "err %s:%d \n", file, line); + return -1; + } + if( CHAR_MAXDEPOTPETHAVE <= iindex || iindex < 0 ) { + print( "err %s:%d \n", file, line); + return -1; + } + if( !CHAR_CheckDepotPet( index) ){ + print( "err %s:%d from %s:%d\n", __FILE__, __LINE__,file, line); + return -1; + } + buf = CHAR_chara[index].indexOfExistDepotPets[iindex]; + CHAR_chara[index].indexOfExistDepotPets[iindex] = id; + return buf; +} +void CHAR_removeHaveDepotPet( Char* ch ) +{ + if( ch == NULL )return; + if( ch->indexOfExistDepotPets == NULL ) return; + freeMemory( ch->indexOfExistDepotPets ); + ch->indexOfExistDepotPets = NULL; +} + +void CHAR_removeDepotPet( int charaindex) +{ + int i,petindex; + Char* ch = NULL; + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( !CHAR_CheckDepotPet( charaindex) ) return; //ֿδ + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ){ + print( "removeDepotPet err ch == NULL :%d\n", charaindex); + return; + } + + for( i=0; iindexOfExistDepotPets[i]; + if( !CHAR_CHECKINDEX( petindex) ) continue; + petstring = CHAR_makePetStringFromPetIndex( ch->indexOfExistDepotPets[i]); + if( petstring == "\0" )continue; + + snprintf( linedata , sizeof( linedata ), + DEPOTPETRESERVESTRING "%d=%s" CHAR_DELIMITER, i, petstring); + + strcpysafe( &CHAR_dataString[strlength], sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + return "\0"; + } + } + return CHAR_dataString; +} + +BOOL CHAR_makeDepotPetStringToChar( int charaindex, char* data) +{ + int readindex=1, petindex; + Char* ch = NULL; + BOOL ret; + char firstToken[1024], secondToken[1024*8], linebuf[1024*8]; + + if( data[0] == '\0' ) + return -1; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ){ + print( "makeDepotPet err ch == NULL :%d\n", charaindex); + return FALSE; + } + + while( 1 ){ + memset( linebuf, 0, sizeof( linebuf)); + memset( firstToken, 0, sizeof( firstToken)); + memset( secondToken, 0, sizeof( secondToken)); + ret = getStringFromIndexWithDelim( data ,CHAR_DELIMITER, + readindex, linebuf, sizeof( linebuf ) ); + if( ret == FALSE )break; + if( linebuf[0] == '#' || linebuf[0] == '\n' || linebuf[0] == '\0' ){ + goto NEXT; + } + if( (ret=getStringFromIndexWithDelim( linebuf , "=" , 1 , + firstToken, sizeof(firstToken) )) == FALSE ) return FALSE; + strcpysafe( secondToken , sizeof( secondToken ), + linebuf + strlen( firstToken) + strlen("=") ); + + if( strncmp( firstToken, DEPOTPETRESERVESTRING, strlen( DEPOTPETRESERVESTRING)) == 0 ){ + if( strcmp( secondToken, NULLITEM) == 0 ) goto NEXT; + petindex = atoi( firstToken+strlen(DEPOTPETRESERVESTRING) ); + if( petindex < 0 || CHAR_MAXDEPOTPETHAVE <= petindex + || ch->indexOfExistDepotPets[petindex] != -1 ){ + ; + }else{ + Char petone; + ret = CHAR_makePetFromStringToArg( secondToken , &petone, 0 ); + if( ret == TRUE ){ + int existpetindex; + existpetindex = PET_initCharOneArray( &petone ); + ch->indexOfExistDepotPets[petindex] = existpetindex; + CHAR_setWorkInt( existpetindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_complianceParameter( existpetindex); + } + } + goto NEXT; + } + print( "1??? : %s[%s]\n" , linebuf, firstToken ); +NEXT: + readindex++; + } + return TRUE; +} + +void CHAR_ShowMyDepotPets( int charaindex) +{ + int i, petindex; + + print( "\nShowMyDepotPets:\n"); + if( !CHAR_CheckDepotPet( charaindex) ) return; + for( i=0; iindexOfExistDepotPets == NULL ) return FALSE; + return TRUE; +} + +#endif + +#ifdef _STREET_VENDOR +BOOL CHAR_setStreetVendor(int charindex,int index,int set,int num) +{ + if(!CHAR_CHECKINDEX(charindex)) return FALSE; + if(index < 0 || index > MAX_SELL_ITEM) return FALSE; + switch(set){ + case SV_PILE: + CHAR_chara[charindex].StreetVendor[index].pile = num; + break; + case SV_PRICE: + CHAR_chara[charindex].StreetVendor[index].price = num; + break; + case SV_INDEX: + CHAR_chara[charindex].StreetVendor[index].index = num; + break; + case SV_KIND: + CHAR_chara[charindex].StreetVendor[index].kind = num; + break; + } + CHAR_chara[charindex].StreetVendor[index].usage = TRUE; + return TRUE; +} + +INLINE void CHAR_clearStreetVendor(int charindex,int index) +{ + if(!CHAR_CHECKINDEX(charindex)) return; + if(index < 0 || index > MAX_SELL_ITEM) return; + CHAR_chara[charindex].StreetVendor[index].index = -1; + CHAR_chara[charindex].StreetVendor[index].price = 0; + CHAR_chara[charindex].StreetVendor[index].pile = 0; + CHAR_chara[charindex].StreetVendor[index].kind = -1; + CHAR_chara[charindex].StreetVendor[index].usage = FALSE; +} + +int CHAR_getStreetVendor(int charindex,int index,int set) +{ + if(!CHAR_CHECKINDEX(charindex)) return -1; + if(index < 0 || index > MAX_SELL_ITEM) return -1; + switch(set){ + case SV_PILE: + return CHAR_chara[charindex].StreetVendor[index].pile; + case SV_PRICE: + return CHAR_chara[charindex].StreetVendor[index].price; + case SV_INDEX: + return CHAR_chara[charindex].StreetVendor[index].index; + case SV_KIND: + return CHAR_chara[charindex].StreetVendor[index].kind; + case SV_USAGE: + return CHAR_chara[charindex].StreetVendor[index].usage; + } + return -1; +} +#endif + +#ifdef _CHAR_POOLPET +int CHAR_getCharDepotPetElement( int charaindex ) +{ + int i; + int limit; + if( !CHAR_CHECKINDEX(charaindex))return -1; + + //andy_reEdit 2003/09/18 + //limit = (CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)*2)+5; + //limit = min( limit, CHAR_MAXPOOLPETHAVE); + limit = CHAR_MAXDEPOTPETHAVE; + for( i = 0; i < limit; i ++ ) { + if( CHAR_getDepotPetIndex( charaindex,i) == -1 ) break; + } + return ( i == limit ? -1:i ); +} +#endif + +#ifdef _RIDE_CF +int CHAR_Ride_CF_init() +{ + FILE* fp; + int i=0; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/ride.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/ride.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + while(1){ + char line[1024], buf[16]; + if (fgets(line, sizeof(line), fp) == NULL)break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + if(line[0]=='#')continue; + getStringFromIndexWithDelim(line,",", 1, buf, sizeof(buf)); + if(!strcmp(buf, " ")){ + for(i=0;i= 0 ) +#else + if(CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER){ + if(FmLeaderRide[i].ride[0]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[0] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[0] ); + } + if(FmLeaderRide[i].ride[1]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[1] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[1] ); + } + if(FmLeaderRide[i].ride[2]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[2] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[2] ); + } + }else if(CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER){ + if(FmLeaderRide[i].ride[1]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[1] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[1] ); + } + if(FmLeaderRide[i].ride[2]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[2] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[2] ); + } + }else if(CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER){ + if(FmLeaderRide[i].ride[2]<32){ + playerlowsride |= ( 1 << FmLeaderRide[i].ride[2] ); + }else{ + playerlowsride1 |= ( 1 << FmLeaderRide[i].ride[2] ); + } + } + + if( (ti = RIDEPET_getPETindex( petNo,playerlowsride, playerlowsride1 )) >= 0 ) +#endif + { + if( (index = RIDEPET_getNOindex( playerNo)) >= 0 ){ + if( (image = RIDEPET_getRIDEno( index,ti)) >= 0 ){ + CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , image ); + } + } + } + + if(image!=-1){ + CHAR_setInt( meindex , CHAR_RIDEPET, pet ); + CHAR_complianceParameter( meindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( meindex, CHAR_P_STRING_RIDEPET ); + return 1; + } + } + } + return 0; +} +#endif + + +#ifdef _NEW_ITEM_ +int CheckCharMaxItem(int charindex) +{ + int ret = CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM; + if(CHAR_getInt(charindex,CHAR_NEWITEMFLG)&1<<1){ + ret+=CHAR_MAXITEMNUM; + if(CHAR_getInt(charindex,CHAR_NEWITEMFLG)&1<<2){ + ret+=CHAR_MAXITEMNUM; + } + } + return ret; +} +int CheckCharMaxItemChar(Char* ch) +{ + int ret = CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM; + if(ch->data[CHAR_NEWITEMFLG]&1<<1){ + ret+=CHAR_MAXITEMNUM; + if(ch->data[CHAR_NEWITEMFLG]&1<<2){ + ret+=CHAR_MAXITEMNUM; + } + } + return ret; +} +#else +int CheckCharMaxItem(int charindex) +{ + return CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM; +} +int CheckCharMaxItemChar(Char* ch) +{ + return CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM; +} + +#endif + +#ifdef _MO_LNS_CHARSUOXU +int CHAR_getEmptyPetBoxNum(int charaindex) +{ + if( !CHAR_CHECKINDEX(charaindex)) + return -1; + + int i = 0 ; + int EmptyNum = 0; + + for( ; i +#include +#ifdef _REDHAT_V9 +#include +#endif +#include "autil.h" +#include "readmap.h" +#include "common.h" +#include "util.h" +#include "anim_tbl.h" +#include "battle.h" +#include "char.h" +#include "char_data.h" +#include "buf.h" +#include "item.h" +#include "log.h" +#include "pet.h" +#include "enemy.h" +#ifdef _PERSONAL_FAME // Arminius: +#include "char_base.h" +#include "configfile.h" +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + +#include "defaultPlayer.h" + +#include "ls2data.dat" + +// CoolFish: Family 2001/7/28 +#include "family.h" +#include "saacproto_cli.h" + +#ifdef _PET_LIMITLEVEL +void CHAR_CheckPetDoLimitlevel( int petindex , int toindex, int level); +#endif + + +typedef struct tagdefaultCharcterGet +{ + int imagenumber; + Char* initchardata; + LevelUpPattern* lvpattern; + CHAR_ImageType imgtype; +}defaultCharacterGet; + +static defaultCharacterGet CHAR_defaultCharacterGet[]= +{ + /* CHAR_DEFAULTPLAYER */ +//Ҽɨ + {SPR_001em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDBOY}, + {SPR_002em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDBOY}, + {SPR_003em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDBOY}, + {SPR_004em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDBOY}, + +// + {SPR_011em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_012em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_013em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_014em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + +// + {SPR_021em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_022em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_023em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_024em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + +// + {SPR_031em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_032em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_033em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + {SPR_034em,&player,&lvplayer00,CHAR_IMAGETYPE_BOY}, + +// + {SPR_041em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_042em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_043em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_044em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + +// + {SPR_051em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_052em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_053em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPR_054em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + +//ҼԨ + {SPR_061em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDGIRL}, + {SPR_062em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDGIRL}, + {SPR_063em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDGIRL}, + {SPR_064em,&player,&lvplayer00,CHAR_IMAGETYPE_CHILDGIRL}, + +//Ԩ + {SPR_071em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_072em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_073em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_074em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + +//Ԩ + {SPR_081em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_082em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_083em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_084em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + +//Ԩ + {SPR_091em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_092em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_093em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPR_094em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + +// + {SPR_101em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_102em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_103em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_104em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + +// + {SPR_111em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_112em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_113em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + {SPR_114em,&player,&lvplayer00,CHAR_IMAGETYPE_WOMAN}, + + {SPR_pet001,&player,&lvplayer00,CHAR_IMAGETYPE_DOG}, + {SPR_pet002,&player,&lvplayer00,CHAR_IMAGETYPE_DOG}, + {SPR_pet003,&player,&lvplayer00,CHAR_IMAGETYPE_DOG}, + {SPR_pet004,&player,&lvplayer00,CHAR_IMAGETYPE_DOG}, + {SPR_pet011,&player,&lvplayer00,CHAR_IMAGETYPE_DOG}, + +#ifdef _MO_IMAGE_EXTENSION + {SPRNEW_001em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_002em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_003em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_004em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + + {SPRNEW_005em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_006em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_007em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_008em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + + {SPRNEW_009em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_010em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_011em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + {SPRNEW_012em,&player,&lvplayer00,CHAR_IMAGETYPE_GIRL}, + + {SPRNEW_013em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_014em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_015em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_016em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + + {SPRNEW_017em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_018em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_019em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_020em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + + {SPRNEW_021em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_022em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_023em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, + {SPRNEW_024em,&player,&lvplayer00,CHAR_IMAGETYPE_MAN}, +#endif +}; + +BOOL CHAR_getDefaultChar( Char* nc , int imagenumber ) +{ + int i, j; + int defcharaindex; + + Char* defaultchar; + defaultchar = CHAR_defaultCharacterGet[arraysizeof(CHAR_defaultCharacterGet) - 1].initchardata; + + memset( nc,0,sizeof(Char) ); + defcharaindex = 0; + for( i = 0 ; i < arraysizeof( CHAR_defaultCharacterGet ) ; i ++ ){ + if( CHAR_defaultCharacterGet[i].imagenumber == imagenumber ){ + defaultchar = CHAR_defaultCharacterGet[i].initchardata; + defcharaindex = i; + break; + } + } + nc->data[CHAR_IMAGETYPE] = CHAR_defaultCharacterGet[defcharaindex].imgtype; + nc->use = TRUE; + +#ifdef _CHAR_FIXDATADEF + for( j = 0 ; j < CHAR_DATAINTNUM ; j ++ ){ + if( j < CHAR_INITDATA ) nc->data[j] = defaultchar->data[j]; + else nc->data[j] = 0; + } +#else + for( j = 0 ; j < CHAR_DATAINTNUM ; j ++ ) + nc->data[j] = defaultchar->data[j]; +#endif + for( j = 0 ; j < arraysizeof( nc->flg ) ; j ++ ) + nc->flg[j] = defaultchar->flg[j]; + extern int CheckCharMaxItemChar(Char* ch); + for( j = 0 ; j < CHAR_DATACHARNUM ; j ++ ) + nc->string[j].string[0] = '\0'; + + for( j = 0 ; j indexOfExistItems[j] = -1; + for( j = 0 ; j < CHAR_MAXPETHAVE ; j ++ ) + nc->unionTable.indexOfPet[j] = -1; + for( j = 0 ; j < CHAR_MAXPOOLITEMHAVE ; j ++ ) + nc->indexOfExistPoolItems[j] = -1; + for( j = 0 ; j < CHAR_MAXPETSKILLHAVE ; j ++ ) + nc->unionTable.indexOfPetskill[j] = -1; + for( j = 0 ; j < CHAR_MAXPOOLPETHAVE ; j ++ ) + nc->indexOfPoolPet[j] = -1; + for( j = 0 ; j < CHAR_SKILLMAXHAVE ; j ++ ) + nc->haveSkill[j].use = FALSE; + for( j = 0 ; j < CHAR_TITLEMAXHAVE ; j ++ ) + nc->indexOfHaveTitle[j] = -1; + for( j=0 ; jaddressBook[j],0,sizeof(nc->addressBook[j]) ); + for( j = 0 ; j < CHAR_WORKDATAINTNUM ; j ++ ) + nc->workint[j] = 0; + for( j = 0 ; j < CHAR_WORKDATACHARNUM ; j ++ ) + nc->workchar[j].string[0] = '\0'; + nc->workint[CHAR_WORKFD] = -1; +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ + nc->workint[CHAR_WORKCHATROOMNUM] = -1; +#endif + return TRUE; +} + +static int CHAR_playerImageNumber[]= +{ + /* CHAR_DEFAULTPLAYER */ + SPR_001em,SPR_002em,SPR_003em,SPR_004em, + SPR_011em,SPR_012em,SPR_013em,SPR_014em, + SPR_021em,SPR_022em,SPR_023em,SPR_024em, + SPR_031em,SPR_032em,SPR_033em,SPR_034em, + SPR_041em,SPR_042em,SPR_043em,SPR_044em, + SPR_051em,SPR_052em,SPR_053em,SPR_054em, + SPR_061em,SPR_062em,SPR_063em,SPR_064em, + SPR_071em,SPR_072em,SPR_073em,SPR_074em, + SPR_081em,SPR_082em,SPR_083em,SPR_084em, + SPR_091em,SPR_092em,SPR_093em,SPR_094em, + SPR_101em,SPR_102em,SPR_103em,SPR_104em, + SPR_111em,SPR_112em,SPR_113em,SPR_114em +#ifdef _MO_IMAGE_EXTENSION +,SPRNEW_001em,SPRNEW_001ax,SPRNEW_001cl,SPRNEW_001sp,SPRNEW_001bw +,SPRNEW_002em,SPRNEW_002ax,SPRNEW_002cl,SPRNEW_002sp,SPRNEW_002bw +,SPRNEW_003em,SPRNEW_003ax,SPRNEW_003cl,SPRNEW_003sp,SPRNEW_003bw +,SPRNEW_004em,SPRNEW_004ax,SPRNEW_004cl,SPRNEW_004sp,SPRNEW_004bw +,SPRNEW_005em,SPRNEW_005ax,SPRNEW_005cl,SPRNEW_005sp,SPRNEW_005bw +,SPRNEW_006em,SPRNEW_006ax,SPRNEW_006cl,SPRNEW_006sp,SPRNEW_006bw +,SPRNEW_007em,SPRNEW_007ax,SPRNEW_007cl,SPRNEW_007sp,SPRNEW_007bw +,SPRNEW_008em,SPRNEW_008ax,SPRNEW_008cl,SPRNEW_008sp,SPRNEW_008bw +,SPRNEW_009em,SPRNEW_009ax,SPRNEW_009cl,SPRNEW_009sp,SPRNEW_009bw +,SPRNEW_010em,SPRNEW_010ax,SPRNEW_010cl,SPRNEW_010sp,SPRNEW_010bw +,SPRNEW_011em,SPRNEW_011ax,SPRNEW_011cl,SPRNEW_011sp,SPRNEW_011bw +,SPRNEW_012em,SPRNEW_012ax,SPRNEW_012cl,SPRNEW_012sp,SPRNEW_012bw +,SPRNEW_013em,SPRNEW_013ax,SPRNEW_013cl,SPRNEW_013sp,SPRNEW_013bw +,SPRNEW_014em,SPRNEW_014ax,SPRNEW_014cl,SPRNEW_014sp,SPRNEW_014bw +,SPRNEW_015em,SPRNEW_015ax,SPRNEW_015cl,SPRNEW_015sp,SPRNEW_015bw +,SPRNEW_016em,SPRNEW_016ax,SPRNEW_016cl,SPRNEW_016sp,SPRNEW_016bw +,SPRNEW_017em,SPRNEW_017ax,SPRNEW_017cl,SPRNEW_017sp,SPRNEW_017bw +,SPRNEW_018em,SPRNEW_018ax,SPRNEW_018cl,SPRNEW_018sp,SPRNEW_018bw +,SPRNEW_019em,SPRNEW_019ax,SPRNEW_019cl,SPRNEW_019sp,SPRNEW_019bw +,SPRNEW_020em,SPRNEW_020ax,SPRNEW_020cl,SPRNEW_020sp,SPRNEW_020bw +,SPRNEW_021em,SPRNEW_021ax,SPRNEW_021cl,SPRNEW_021sp,SPRNEW_021bw +,SPRNEW_022em,SPRNEW_022ax,SPRNEW_022cl,SPRNEW_022sp,SPRNEW_022bw +,SPRNEW_023em,SPRNEW_023ax,SPRNEW_023cl,SPRNEW_023sp,SPRNEW_023bw +,SPRNEW_024em,SPRNEW_024ax,SPRNEW_024cl,SPRNEW_024sp,SPRNEW_024bw +#endif +}; + +BOOL CHAR_checkPlayerImageNumber( int imagenumber) +{ + int i; + for( i = 0; i < arraysizeof( CHAR_playerImageNumber); i ++ ) { + if( imagenumber == CHAR_playerImageNumber[i] ) break; + } + if( i == arraysizeof( CHAR_playerImageNumber)) return FALSE; + else return TRUE; +} +/*------------------------------------------------------------ + * ӿ į + * + * ӿ įƱɡѨƥȻ + * number = + * CG_CHR_MAKE_FACE + (number*100) + ( number * 25) + ( į * 5 ) + į + * + ------------------------------------------------------------*/ +BOOL CHAR_checkFaceImageNumber( int imagenumber, int faceimagenumber) +{ +#ifdef _MO_IMAGE_EXTENSION + + if (imagenumber>=SPRNEW_001em) { + /* + int image = imagenumber - SPRNEW_001em; + int number; + int color; + number = (faceimagenumber - CG_CHR_MAKE_NEWFACE)/ 100*20; + color = ((faceimagenumber - CG_CHR_MAKE_NEWFACE)% 100) / 25*5; + if( image != number + color ) return FALSE; + */ + return TRUE; + }else +#endif + { + int image = imagenumber - SPR_001em; + int number; + int color; + + number = (faceimagenumber - CG_CHR_MAKE_FACE)/ 100*20; + color = ((faceimagenumber - CG_CHR_MAKE_FACE)% 100) / 25*5; + if( image != number + color ) return FALSE; + return TRUE; + } +} +// ƽҷ Ƥۨ ؤԻ +int CHAR_eqimagetbl[][5]={ + // ƥ + { SPR_001em,SPR_001ax,SPR_001cl,SPR_001sp,SPR_001bw }, + { SPR_002em,SPR_002ax,SPR_002cl,SPR_002sp,SPR_002bw }, + { SPR_003em,SPR_003ax,SPR_003cl,SPR_003sp,SPR_003bw }, + { SPR_004em,SPR_004ax,SPR_004cl,SPR_004sp,SPR_004bw }, + { SPR_011em,SPR_011ax,SPR_011cl,SPR_011sp,SPR_011bw }, + { SPR_012em,SPR_012ax,SPR_012cl,SPR_012sp,SPR_012bw }, + { SPR_013em,SPR_013ax,SPR_013cl,SPR_013sp,SPR_013bw }, + { SPR_014em,SPR_014ax,SPR_014cl,SPR_014sp,SPR_014bw }, + { SPR_021em,SPR_021ax,SPR_021cl,SPR_021sp,SPR_021bw }, + { SPR_022em,SPR_022ax,SPR_022cl,SPR_022sp,SPR_022bw }, + { SPR_023em,SPR_023ax,SPR_023cl,SPR_023sp,SPR_023bw }, + { SPR_024em,SPR_024ax,SPR_024cl,SPR_024sp,SPR_024bw }, + { SPR_021em,SPR_021ax,SPR_021cl,SPR_021sp,SPR_021bw }, + { SPR_031em,SPR_031ax,SPR_031cl,SPR_031sp,SPR_031bw }, + { SPR_032em,SPR_032ax,SPR_032cl,SPR_032sp,SPR_032bw }, + { SPR_033em,SPR_033ax,SPR_033cl,SPR_033sp,SPR_033bw }, + { SPR_034em,SPR_034ax,SPR_034cl,SPR_034sp,SPR_034bw }, + { SPR_041em,SPR_041ax,SPR_041cl,SPR_041sp,SPR_041bw }, + { SPR_042em,SPR_042ax,SPR_042cl,SPR_042sp,SPR_042bw }, + { SPR_043em,SPR_043ax,SPR_043cl,SPR_043sp,SPR_043bw }, + { SPR_044em,SPR_044ax,SPR_044cl,SPR_044sp,SPR_044bw }, + + { SPR_051em,SPR_051ax,SPR_051cl,SPR_051sp,SPR_051bw }, + { SPR_052em,SPR_052ax,SPR_052cl,SPR_052sp,SPR_052bw }, + { SPR_053em,SPR_053ax,SPR_053cl,SPR_053sp,SPR_053bw }, + { SPR_054em,SPR_054ax,SPR_054cl,SPR_054sp,SPR_054bw }, + + { SPR_061em,SPR_061ax,SPR_061cl,SPR_061sp,SPR_061bw }, + { SPR_062em,SPR_062ax,SPR_062cl,SPR_062sp,SPR_062bw }, + { SPR_063em,SPR_063ax,SPR_063cl,SPR_063sp,SPR_063bw }, + { SPR_064em,SPR_064ax,SPR_064cl,SPR_064sp,SPR_064bw }, + + { SPR_071em,SPR_071ax,SPR_071cl,SPR_071sp,SPR_071bw }, + { SPR_072em,SPR_072ax,SPR_072cl,SPR_072sp,SPR_072bw }, + { SPR_073em,SPR_073ax,SPR_073cl,SPR_073sp,SPR_073bw }, + { SPR_074em,SPR_074ax,SPR_074cl,SPR_074sp,SPR_074bw }, + + { SPR_081em,SPR_081ax,SPR_081cl,SPR_081sp,SPR_081bw }, + { SPR_082em,SPR_082ax,SPR_082cl,SPR_082sp,SPR_082bw }, + { SPR_083em,SPR_083ax,SPR_083cl,SPR_083sp,SPR_083bw }, + { SPR_084em,SPR_084ax,SPR_084cl,SPR_084sp,SPR_084bw }, + + { SPR_091em,SPR_091ax,SPR_091cl,SPR_091sp,SPR_091bw }, + { SPR_092em,SPR_092ax,SPR_092cl,SPR_092sp,SPR_092bw }, + { SPR_093em,SPR_093ax,SPR_093cl,SPR_093sp,SPR_093bw }, + { SPR_094em,SPR_094ax,SPR_094cl,SPR_094sp,SPR_094bw }, + + { SPR_101em,SPR_101ax,SPR_101cl,SPR_101sp,SPR_101bw }, + { SPR_102em,SPR_102ax,SPR_102cl,SPR_102sp,SPR_102bw }, + { SPR_103em,SPR_103ax,SPR_103cl,SPR_103sp,SPR_103bw }, + { SPR_104em,SPR_104ax,SPR_104cl,SPR_104sp,SPR_104bw }, + + { SPR_111em,SPR_111ax,SPR_111cl,SPR_111sp,SPR_111bw }, + { SPR_112em,SPR_112ax,SPR_112cl,SPR_112sp,SPR_112bw }, + { SPR_113em,SPR_113ax,SPR_113cl,SPR_113sp,SPR_113bw }, + { SPR_114em,SPR_114ax,SPR_114cl,SPR_114sp,SPR_114bw }, + + { SPR_091em,SPR_091ax,SPR_091cl,SPR_091sp,SPR_091bw }, + { SPR_092em,SPR_092ax,SPR_092cl,SPR_092sp,SPR_092bw }, + + { SPR_pet001,SPR_pet001,SPR_pet001,SPR_pet001,SPR_pet001}, + { SPR_pet002,SPR_pet002,SPR_pet002,SPR_pet002,SPR_pet002}, + { SPR_pet003,SPR_pet003,SPR_pet003,SPR_pet003,SPR_pet003}, + { SPR_pet004,SPR_pet004,SPR_pet004,SPR_pet004,SPR_pet004}, + + { SPR_pet011,SPR_pet011,SPR_pet011,SPR_pet011,SPR_pet011}, + + { SPR_121em,SPR_121ax,SPR_121cl,SPR_121sp,SPR_121bw }, + { SPR_122em,SPR_122ax,SPR_122cl,SPR_122sp,SPR_122bw }, + + { SPR_131em,SPR_131ax,SPR_131cl,SPR_131sp,SPR_131bw }, + { SPR_132em,SPR_132ax,SPR_132cl,SPR_132sp,SPR_132bw }, + { SPR_133em,SPR_133ax,SPR_133cl,SPR_133sp,SPR_133bw }, + + { SPR_141em,SPR_141ax,SPR_141cl,SPR_141sp,SPR_141bw }, + { SPR_142em,SPR_142ax,SPR_142cl,SPR_142sp,SPR_142bw }, + + { SPR_151em,SPR_151ax,SPR_151cl,SPR_151sp,SPR_151bw }, + { SPR_152em,SPR_152ax,SPR_152cl,SPR_152sp,SPR_152bw }, + + { SPR_161em,SPR_161ax,SPR_161cl,SPR_161sp,SPR_161bw }, + { SPR_162em,SPR_162ax,SPR_162cl,SPR_162sp,SPR_162bw }, + + { 100400, 100401, 100402, 100403, 100404 }, + { 100405, 100406, 100407, 100408, 100409 }, + + { 100431, 100432, 100433, 100434, 100435 }, + { 100436, 100437, 100438, 100439, 100440 }, + + { 103000, 103001, 103002, 103003, 103004 }, + { 103005, 103006, 103007, 103008, 103009 }, + { 103010, 103011, 103012, 103013, 103014 }, + { 103015, 103016, 103017, 103018, 103019 }, + { 103020, 103021, 103022, 103023, 103024 }, + +#ifdef _MO_IMAGE_EXTENSION + { SPRNEW_001em,SPRNEW_001ax,SPRNEW_001cl,SPRNEW_001sp,SPRNEW_001bw }, + { SPRNEW_002em,SPRNEW_002ax,SPRNEW_002cl,SPRNEW_002sp,SPRNEW_002bw }, + { SPRNEW_003em,SPRNEW_003ax,SPRNEW_003cl,SPRNEW_003sp,SPRNEW_003bw }, + { SPRNEW_004em,SPRNEW_004ax,SPRNEW_004cl,SPRNEW_004sp,SPRNEW_004bw }, + { SPRNEW_005em,SPRNEW_005ax,SPRNEW_005cl,SPRNEW_005sp,SPRNEW_005bw }, + { SPRNEW_006em,SPRNEW_006ax,SPRNEW_006cl,SPRNEW_006sp,SPRNEW_006bw }, + { SPRNEW_007em,SPRNEW_007ax,SPRNEW_007cl,SPRNEW_007sp,SPRNEW_007bw }, + { SPRNEW_008em,SPRNEW_008ax,SPRNEW_008cl,SPRNEW_008sp,SPRNEW_008bw }, + { SPRNEW_009em,SPRNEW_009ax,SPRNEW_009cl,SPRNEW_009sp,SPRNEW_009bw }, + { SPRNEW_010em,SPRNEW_010ax,SPRNEW_010cl,SPRNEW_010sp,SPRNEW_010bw }, + { SPRNEW_011em,SPRNEW_011ax,SPRNEW_011cl,SPRNEW_011sp,SPRNEW_011bw }, + { SPRNEW_012em,SPRNEW_012ax,SPRNEW_012cl,SPRNEW_012sp,SPRNEW_012bw }, + { SPRNEW_013em,SPRNEW_013ax,SPRNEW_013cl,SPRNEW_013sp,SPRNEW_013bw }, + { SPRNEW_014em,SPRNEW_014ax,SPRNEW_014cl,SPRNEW_014sp,SPRNEW_014bw }, + { SPRNEW_015em,SPRNEW_015ax,SPRNEW_015cl,SPRNEW_015sp,SPRNEW_015bw }, + { SPRNEW_016em,SPRNEW_016ax,SPRNEW_016cl,SPRNEW_016sp,SPRNEW_016bw }, + { SPRNEW_017em,SPRNEW_017ax,SPRNEW_017cl,SPRNEW_017sp,SPRNEW_017bw }, + { SPRNEW_018em,SPRNEW_018ax,SPRNEW_018cl,SPRNEW_018sp,SPRNEW_018bw }, + { SPRNEW_019em,SPRNEW_019ax,SPRNEW_019cl,SPRNEW_019sp,SPRNEW_019bw }, + { SPRNEW_020em,SPRNEW_020ax,SPRNEW_020cl,SPRNEW_020sp,SPRNEW_020bw }, + { SPRNEW_021em,SPRNEW_021ax,SPRNEW_021cl,SPRNEW_021sp,SPRNEW_021bw }, + { SPRNEW_022em,SPRNEW_022ax,SPRNEW_022cl,SPRNEW_022sp,SPRNEW_022bw }, + { SPRNEW_023em,SPRNEW_023ax,SPRNEW_023cl,SPRNEW_023sp,SPRNEW_023bw }, + { SPRNEW_024em,SPRNEW_024ax,SPRNEW_024cl,SPRNEW_024sp,SPRNEW_024bw }, +#endif +}; + +/*------------------------------------------------------------ + * įޥ įë £ + * ¦ + * basebaseimagenumber int ئ į + * category ITEM_CATEGORY ʧ ة + * ߯Ի + * ޥ į۾޷¡ݷ-1 + ------------------------------------------------------------*/ +int CHAR_getNewImagenumberFromEquip(int index, int basebaseimagenumber, ITEM_CATEGORY category ) +{ + if(index == -1){ + int i; + /* ITEM_CATEGORY */ + if( category < 0 || category > arraysizeof(CHAR_eqimagetbl[0]) ) + return -1; + for( i=0 ; i arraysizeof(CHAR_eqimagetbl[0]) ) + return -1; + for( i=0 ; i rx )swap(lx,rx); + if( ly > ry )swap(ly,ry); + + CHAR_invarea[invreadlen].area.x = lx; + CHAR_invarea[invreadlen].area.y = ly; + CHAR_invarea[invreadlen].area.width = rx-lx; + CHAR_invarea[invreadlen].area.height= ry-ly; + invreadlen ++; + } + } + fclose(f); + CHAR_invareanum = invreadlen; + print( "ЧսЧ %d...", CHAR_invareanum ); + +#ifdef DEBUG + { + int i; + for( i=0; i 3 ) { + return FALSE; + } + +#ifdef _UNIFIDE_MALINASI + index=1; +#else + index=hometown; +#endif + if( index >= arraysizeof( elders ) ){ + return FALSE; + } + + ch->data[CHAR_FLOOR] = elders[index].floor; + ch->data[CHAR_X] = elders[index].x; + ch->data[CHAR_Y] = elders[index].y; + ch->data[CHAR_LASTTALKELDER] = index; + point = ch->data[CHAR_SAVEPOINT]; + + point = point | (1<data[CHAR_SAVEPOINT] = point; + + if( MAP_checkCoordinates( ch->data[CHAR_FLOOR], ch->data[CHAR_X], + ch->data[CHAR_Y] ) == FALSE ){ + return FALSE; + } + + return TRUE; +} + +/*------------------------------------------------------------ + * ޻ĸë + * ¦ + * elderindex int ޻ĸ̼͵ + * fl int* ׷ʧë + * x int* xë + * y int* yë + * ¦ + * TRUE(1) + * FALSE(0) + ------------------------------------------------------------*/ +BOOL CHAR_getElderPosition( int elderindex, int* fl, int* x, int* y ) +{ + if( elderindex<0 || arraysizeof(elders)<=elderindex )return FALSE; + + *fl = elders[elderindex].floor; + *x = elders[elderindex].x; + *y = elders[elderindex].y; + return TRUE; +} +/*------------------------------------------------------------ + * Ӯ NPCмӮ ̤꼰֣ + * ׻̵̼ + * ¦ + * index int ƥ FALSE ë + * fl int + * x int + * y int + * NPCľ¼֣ + ------------------------------------------------------------*/ +BOOL CHAR_ElderSetPosition( int elderindex ,int fl,int x ,int y) +{ + if( elderindex < ELDERINDEXSTART || + elderindex >= MAXELDERS ){ + return FALSE; + } + + elders[elderindex].floor = fl; + elders[elderindex].x = x; + elders[elderindex].y = y; + return TRUE; +} + + +void CHAR_setInitValues( Char* ch ) +{ + +#ifndef _PROFESSION_SKILL // WON ADD ְҵ + + static int CHAR_titleindextbl[] ={ 0,1,2,3,4,5,6 }; + int elderindex; + int i; + BOOL magician=FALSE; + BOOL priest=FALSE; + + elderindex = ch->data[CHAR_LASTTALKELDER]; + if( 0 <= elderindex + && elderindex < arraysizeof( CHAR_titleindextbl ) ) + ch->indexOfHaveTitle[0] = CHAR_titleindextbl[elderindex]; + + + for( i=0 ; ihaveSkill[i].use ){ + int j; + int skindex=ch->haveSkill[i].skill.data[SKILL_IDENTITY]; + + for( j=0 ; jdata[CHAR_GOLD] = 20; + + if( skindex == SKILL_MAGICIAN ) + magician = TRUE; + else if( skindex == SKILL_PRIEST ) + priest = TRUE; + + } + } + + if( magician || priest ) CHAR_addItemToChar( ch, 802 ); + +#endif +} + + +#if 1 +static int EnemyExpTbl[]={ +0, // 0 +2, // 1 +4, // 2 +6, // 3 +8, // 4 +10, // 5 +12, // 6 +14, // 7 +16, // 8 +18, // 9 +20, // 10 +26, // 11 +32, // 12 +38, // 13 +44, // 14 +50, // 15 +60, // 16 +70, // 17 +80, // 18 +90, // 19 +100, // 20 +115, // 21 +130, // 22 +145, // 23 +160, // 24 +175, // 25 +190, // 26 +205, // 27 +220, // 28 +235, // 29 +250, // 30 +270, // 31 +290, // 32 +310, // 33 +330, // 34 +350, // 35 +375, // 36 +400, // 37 +425, // 38 +450, // 39 +475, // 40 +500, // 41 +525, // 42 +550, // 43 +575, // 44 +600, // 45 +625, // 46 +650, // 47 +675, // 48 +700, // 49 +725, // 50 +750, // 51 +775, // 52 +800, // 53 +825, // 54 +850, // 55 +875, // 56 +900, // 57 +925, // 58 +950, // 59 +980, // 60 +1010, // 61 +1040, // 62 +1070, // 63 +1100, // 64 +1130, // 65 +1160, // 66 +1190, // 67 +1220, // 68 +1250, // 69 +1280, // 70 +1310, // 71 +1345, // 72 +1380, // 73 +1415, // 74 +1450, // 75 +1485, // 76 +1520, // 77 +1555, // 78 +1590, // 79 +1630, // 80 +1670, // 81 +1710, // 82 +1750, // 83 +1790, // 84 +1830, // 85 +1870, // 86 +1910, // 87 +1950, // 88 +1990 // 89 +}; // 90 + + + + + + + + + + + + + + + + +// öئң +int GetEnemyExp( int level ){ +/* + int exp = 0; + if( level < 5 ){ + exp = 2 * level; + }else + if( level < 10 ){ + exp = 10 * level; + }else + if( level < 20 ){ + exp = 15 * level; + }else + if( level < 30 ){ + exp = 30 * level; + }else + if( level < 40 ){ + exp = 50 * level; + }else + if( level < 50 ){ + exp =60 * level; + }else + if( level < 60 ){ + exp =60 * level; + }else{ + exp =70 * level; + } +*/ + if( level >= arraysizeof( EnemyExpTbl ) )level = arraysizeof( EnemyExpTbl )-1; + return EnemyExpTbl[level]; +} +#endif + +#ifdef _NEWOPEN_MAXEXP +/*static int NeedLevelUpTbls[] = { + 0, 0, + 2, 6, 18, 37, 67, 110, 170, + 246, 344, 464, 610, 782, 986, 1221, + 1491, 1798, 2146, 2534, 2968, 3448, 3978, + 4558, 5194, 5885, 6635, 7446, 8322, 9262, + 10272, 11352, 12506, 13734, 15042, 16429, 17899, + 19454, 21098, 22830, 24656, 26576, 28594, 30710, + 32930, 35253, 37683, 40222, 42874, 45638, 48520, + 51520, 54642, 57886, 61258, 64757, 68387, 72150, + 76050, 80086, 84264, 106110, 113412, 121149, 129352, + 138044, 147256, 157019, 167366, 178334, 189958, 202282, + 215348, 229205, 243901, 259495, 276041, 293606, 312258, + 332071, 353126, 375511, 399318, 424655, 451631, 480370, + 511007, 543686, 578571, 615838, 655680, 698312, 743971, + 792917, 845443, 901868, 962554, 1027899, 1098353, 1174420, + 1256663, 1345723, 1442322, 1547281, 1661531, 1786143, 1922340, + 2071533, 2235351, 2415689, 2614754, 2835137, 3079892, 3352633, + 3657676, 4000195, 4386445, 4824041, 5322323, 5892866, 6550125, + 12326614, 15496114, 20025638, 26821885, 37698249, 56734876, 68097265, + 68290815, 68487425, 68687119, 68889921, 69095855, 69304945, 69517215, + 69732689, 69951391, 70173345, 70398575, 70627105, 70858959, 71244161, + 71342735, 71584705, 71830095, 72078929, 72331231, 72587025, 72846335, + 73109185, 73615599, 73655601, 73929215, 74206465, 74487375, 74771969, + 75060271, 75352305, 75648095, 75947665, 76421039, 76563241, 76874295, + 77189225, 77508055, 77830809, 78157511, 78488185, 78822855, 79161545, + 79724279, 79856081, 80206975, 80561985, 80921135, 81284449, 81651951, + 82023665, 82399615, 82779825, 83434319, 83558121, 83951255, 84348745, + 84750615, 85156889, 85567591, 85982745, 86402375, 86826505, 87575159, + 87693361, 88131135, 88573505, 89020495, 89472129, 89928431, 90389425, + 90855135, 91325585, 91800799 +}; +*/ +#endif +static int LevelUpTbl[] = { // ֵ ȼ +0, // 0 EX=(lv^4)/10 +0, // 1 + 2, 8, 25, 62, 129, + 240, 409, 656, 1000, 1464, // 11 + 2073, 2856, 3841, 5062, 6553, // 16 + 8352, 10497, 13032, 16000, 19448, 23425, // 22 + 27984, 33177, 39062, 45697, 53144, 61465, // 28 + 70728, 81000, 92352, 104857, 118592, 133633, // 34 + 150062, 167961, 187416, 208513, 231344, 256000, // 40 + 282576, 311169, 341880, 374809, 410062, 447745, // 46 + 487968, 530841, 576480, 625000, 676520, 731161, // 52 + 789048, 850305, 915062, 983449, 1055600, 1131649, // 58 + 1211736, 1296000, + 1402110, // 61 EX=(lv^4)/(10-0.125*(lv-60)) + 1515521, 1636671, 1766022, 1904066, 2051322, 2208342, // 67 + 2375708, 2554041, 2744000, 2946281, 3161630, 3390834, // 73 + 3634736, 3894230, 4170272, 4463878, 4776136, 5108207, // 79 + 5461333, 5836843, 6236162, 6660816, 7112448, 7592818, // 85 + 8103824, 8647511, 9226082, 9841920, 10497600, 11195912, // 91 + 11939882, 12732800, 13578242, 14480111, 15442664, 16470563, // 97 + 17568917, 18743336, 20000000, 21345723, 22788045, 24335325, // 103 + 25996856, 27783000, 29705340, 31776872, 34012224, 36427912, // 109 + 39042666, 41877804, 44957696, 48310329, 51968004, 55968200, // 115 + 60354645, 65178685, 70501009, 76393874, 82944000, + + 95270613, // 121 Nuke 0624 EX=(lv^4)/(2.5-0.25*(lv-120)) + 110766728, 130792366, 157614250, 195312500, // 125 + 252047376, // 126 EX=lv^4+60000000*(lv-126)^2 Nuke 0816 + 320144641, 388435456, 456922881, 525610000, 594499921, 663595776, // 132 + 732900721, 802417936, 872150625, 942102016,1012275361,1082673936, // 138 + 1153301041,1224160000 // 140 +}; + +int CHAR_GetLevel() +{ + return arraysizeof( LevelUpTbl )-1; +} +int CHAR_GetLevelExp( int charaindex, int level) +{ +#ifdef _NEWOPEN_MAXEXP +#ifdef _USER_EXP_CF + if(level>getMaxLevel()){ + if(level>CHAR_getInt(charaindex, CHAR_LIMITLEVEL)) + return -1; + }else if(level>getYBLevel()){ + if (CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPET +#ifdef _PET_FUSION + || CHAR_getInt( charaindex, CHAR_FUSIONBEIT ) == 1 +#endif + ) { + + if(getPettrans() != -1 ){ + if(CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)>=getPettrans()) + return getNeedLevelUpTbls(level); + }else{ + if(level<=CHAR_getInt(charaindex, CHAR_LIMITLEVEL)) + return getNeedLevelUpTbls(level); + } + return -1; + } +#ifdef _PLAYER_NPC + else if (CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC){ + return -1; + } +#endif + + else{ + if(CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)= arraysizeof( NeedLevelUpTbls ) ){ + return -1; + } + return NeedLevelUpTbls[level];*/ +#else + if( level >= arraysizeof( LevelUpTbl ) ){ + return -1; + } + return LevelUpTbl[level]; +#endif +} + +int CHAR_GetOldLevelExp( int level) +{ + if( level >= arraysizeof( LevelUpTbl ) ){ + return -1; + } + return LevelUpTbl[level]; +} + +int CHAR_LevelUpCheck( int charaindex , int toindex) +{ + int exp, level, nextexp, iRet = FALSE; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return 0; + exp = CHAR_getInt( charaindex, CHAR_EXP ); + while( 1 ){ + level = CHAR_getInt( charaindex, CHAR_LV ); + nextexp = CHAR_GetLevelExp( charaindex, level+1); + if( nextexp < 0 ) + break; + // Arminius 7.30 pet limit lv + if (CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPET +#ifdef _PLAYER_NPC + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC + || CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERPETNPC +#endif + ) { + if (level >= CHAR_getInt(charaindex, CHAR_LIMITLEVEL) && + CHAR_getInt(charaindex, CHAR_LIMITLEVEL) > 0 ) { +#ifdef _NEWOPEN_MAXEXP + CHAR_setInt( charaindex, CHAR_EXP , 0); +#else +#ifdef _PET_LIMITLEVEL + if( CHAR_getInt( charaindex, CHAR_PETID) == 718 +#ifdef _PET_2LIMITLEVEL + || CHAR_getInt( charaindex, CHAR_PETID) == 401 +#endif + ) { + nextexp = CHAR_GetLevelExp( charaindex, CHAR_getInt(charaindex, CHAR_LIMITLEVEL)); + CHAR_setInt( charaindex, CHAR_EXP , nextexp ); + } +#endif +#endif + break; + } + } + if( exp >= nextexp ){ + iRet ++; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_setInt( charaindex, CHAR_DUELPOINT, + CHAR_getInt( charaindex, CHAR_DUELPOINT) + (level+1)*10 ); + } +#ifdef _PET_LIMITLEVEL + else { + CHAR_CheckPetDoLimitlevel( charaindex, toindex, level ); + } +#endif + +#ifdef _NEWOPEN_MAXEXP + if( level >= CHAR_MAXUPLEVEL ){ + }else{ + if( CHAR_HandleExp( charaindex) != -1 ){ + exp = CHAR_getInt( charaindex, CHAR_EXP ); + CHAR_setInt( charaindex, CHAR_LV, level+1 ); + } + } +#else + CHAR_setInt( charaindex, CHAR_LV, level+1 ); +#endif + }else{ + break; + } + } + return iRet; +} + +#ifdef _PET_LIMITLEVEL +void CHAR_CheckPetDoLimitlevel( int petindex , int toindex, int level) +{ + int LevelUpPoint,vital,str,tgh,dex; + int j,k; + char token[56]; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + + if( CHAR_getInt( petindex, CHAR_PETID) == 718 +#ifdef _PET_2LIMITLEVEL + || CHAR_getInt( petindex, CHAR_PETID) == 401 +#endif + ) { + LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + vital = (int )(( LevelUpPoint >> 24 ) & 0xFF); + str = (int)(( LevelUpPoint >> 16 ) & 0xFF); + tgh = (int)(( LevelUpPoint >> 8 ) & 0xFF); + dex = (int)(( LevelUpPoint >> 0 ) & 0xFF); + + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( toindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( toindex, CHAR_NAME) )){ + sprintf(token,"Ҳʶѽһˣ"); + //andy 1/11 reEdit + vital -= RAND(2,10); if (vital<0) vital=0; + str -= RAND(2,10); if (str<0) str=0; + tgh -= RAND(2,10); if (tgh<0) tgh=0; + dex -= RAND(2,10); if (dex<0) dex=0; + LevelUpPoint = (vital<<24)+(str<<16)+(tgh<<8)+(dex<<0); + + CHAR_setInt( petindex, CHAR_ALLOCPOINT , LevelUpPoint); + CHAR_talkToCli( toindex, petindex, token, CHAR_COLORWHITE); + + LogPetPointChange( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + petindex, 2, + CHAR_getInt( petindex, CHAR_LV), + "No_master(ٲ)", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ) + ); + } + + if( ( level % 20 ) == 0 ) { + for( j=0; j < 3; j++) { + k = RAND( 0, 3); + if( k == 0 ) + vital--; + if( k == 1 ) + str--; + if( k == 2 ) + tgh--; + if( k == 3 ) + dex--; + } + if( vital < 0 ) vital =0; + if( str < 0 ) str =0; + if( tgh < 0 ) tgh =0; + if( dex < 0 ) dex =0; + LevelUpPoint = (vital<<24)+(str<<16)+(tgh<<8)+(dex<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT , LevelUpPoint); + //print("\n << ( level % 20 ) == 0 >> "); + LogPetPointChange( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + petindex,3, + CHAR_getInt( petindex, CHAR_LV), + "level%20", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ) + ); + } + } +} +#endif + +int CHAR_PetTakeDrop( int petindex, int floor, int ox, int oy) //ǿƶ +{ + int x, y, objindex; + + x = rand()%10; + y = rand()%10; + + //³ CHAR_endCharOneArray + objindex = PET_dropPetAbsolute( petindex,floor,x,y, FALSE ); + if( objindex == -1 ) { + return -1; + } + CHAR_setWorkInt( petindex,CHAR_WORKOBJINDEX,objindex ); + CHAR_setInt( petindex, CHAR_FLOOR, floor); + CHAR_setInt( petindex, CHAR_X, x); + CHAR_setInt( petindex, CHAR_Y, y); + CHAR_sendCToArroundCharacter( objindex); + + return floor; +} + +int CHAR_PetTakeLevelUp( int petindex, int lv)//ǿƳ +{ + int k; + for( k = 1; k < lv; k ++ ){ + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + + CHAR_complianceParameter( petindex ); + return k; +} + +#ifdef _NEW_MANOR_LAW +extern struct FM_POINTLIST fmpointlist; +#endif + +int CHAR_PetLevelUp( int petindex ) +{ + struct _RankRandTbl{ + int min; + int max; + }RankRandTbl[] = { + { 450, 500 }, + { 470, 520 }, + { 490, 540 }, + { 510, 560 }, + { 530, 580 }, + { 550, 600 }, + }; + + float Param[4] = { 0.0, 0.0, 0.0, 0.0 }; + int LevelUpPoint, petrank; + float str, vital, dex, tgh, fRand, i; +#ifdef _TEACHER_SYSTEM + int iGetFame = 0; +#endif + + if( CHAR_CHECKINDEX( petindex ) == FALSE ) return -1; + if( CHAR_getInt( petindex, CHAR_WHICHTYPE ) != CHAR_TYPEPET +#ifdef _PLAYER_NPC + && CHAR_getInt( petindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYERNPC + && CHAR_getInt( petindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYERPETNPC +#endif + ){ + return -1; + } + + LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + + // ʸ¼ + petrank = CHAR_getInt( petindex, CHAR_PETRANK ); + if( petrank < 0 || petrank > 5 ) petrank = 0; + + vital = (float)(( LevelUpPoint >> 24 ) & 0xFF); + str = (float)(( LevelUpPoint >> 16 ) & 0xFF); + tgh = (float)(( LevelUpPoint >> 8 ) & 0xFF); + dex = (float)(( LevelUpPoint >> 0 ) & 0xFF); + + // ߼Ԩ ëȻ + for( i = 0; i < 10; i ++ ){ + Param[RAND( 0, 3 )] += 1.0; + } + + // ¼ͱ巽 ¼ĸة + fRand = (float)RAND( RankRandTbl[petrank].min, RankRandTbl[petrank].max ) + * 0.01; + + // ԻԻ̼Իң + vital = (float)vital * fRand + Param[0] * fRand; + str = (float)str * fRand + Param[1] * fRand; + tgh = (float)tgh * fRand + Param[2] * fRand; + dex = (float)dex * fRand + Param[3] * fRand; + + // ң + CHAR_setInt( petindex, CHAR_VITAL, + CHAR_getInt( petindex, CHAR_VITAL ) + max(0, (int)vital) ); + CHAR_setInt( petindex, CHAR_STR, + CHAR_getInt( petindex, CHAR_STR ) + max(0, (int)str) ); + CHAR_setInt( petindex, CHAR_TOUGH, + CHAR_getInt( petindex, CHAR_TOUGH ) + max(0, (int)tgh) ); + CHAR_setInt( petindex, CHAR_DEX, + CHAR_getInt( petindex, CHAR_DEX ) + max(0, (int)dex) ); + + // CoolFish: + { + int level = CHAR_getInt(petindex, CHAR_LV); + int exp1 = 0, exp2 = 0; + if (level > 30){ + char tmpbuf[128]; +#ifdef _NEW_MANOR_LAW + char tmpbuf1[16]; +#endif + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); +#ifdef _FMVER21 +#else + if (CHAR_getInt(ownerindex, CHAR_FMINDEX) < 0) return 0; + if (CHAR_getInt(ownerindex, CHAR_FMLEADERFLAG) <= 0 ) return 0; + if (strcmp(CHAR_getChar(ownerindex, CHAR_FMNAME), "") == 0) return 0; +#endif + if (CHAR_CHECKINDEX(ownerindex)){ + exp1 = CHAR_GetLevelExp( petindex, level); + exp2 = CHAR_GetLevelExp( petindex, level - 1); + +//#ifdef _PERSONAL_FAME // Arminius 8.30: +// feedpoint = (exp1 - exp2) / 20000; // +//#else +// feedpoint = (exp1 - exp2) / 10000; +//#endif + if ( exp1 - exp2 > 0){ + int feedpoint; + // CoolFish: 2001/10/03 + int fd = getfdFromCharaIndex(ownerindex); + + feedpoint=exp2 / 20000; +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( ownerindex, CHAR_WORK_OFFLINE ) > 0){ + feedpoint=feedpoint / 2; + } +#endif +#ifdef _PERSONAL_FAME // Arminius 8.30: + CHAR_earnFame(ownerindex, feedpoint); + sprintf(tmpbuf, "%d", feedpoint); +#endif + +#ifdef _NEW_MANOR_LAW + sprintf(tmpbuf1, "%d", CHAR_getInt(ownerindex,CHAR_FAME)); +#endif +#ifdef _FMVER21 + if (CHAR_getInt(ownerindex, CHAR_FMLEADERFLAG) > 0 + && CHAR_getInt(ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_APPLY){ + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(ownerindex, CHAR_FMNAME), + CHAR_getInt(ownerindex, CHAR_FMINDEX), + CHAR_getWorkInt(ownerindex, CHAR_WORKFMINDEXI), + FM_FIX_FMFEED, tmpbuf, +#ifndef _NEW_MANOR_LAW + "", +#else + tmpbuf1, +#endif + // CoolFish: 2001/10/03 + CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + // CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), 0); +#ifdef _NEW_MANOR_LAW + { + int i; + for(i=0;i 0){ + // ûеʦ + if(strlen(CHAR_getChar(ownerindex,CHAR_TEACHER_ID)) > 0 && strlen(CHAR_getChar(ownerindex,CHAR_TEACHER_NAME)) > 0){ + int iPlayernum = CHAR_getPlayerMaxNum(),i; + char szMsg[128]; + + // 鵼ʦڲ + for(i=0;i 0 )return 0;//ǷΪںϳ + for( i=0; i<4; i++) { + work[i] = 0; + } + if( PET_getBaseAndSkill( charaindex, Subindex1, base, petskill, 0) == FALSE ) + return 0; + if( CHAR_getInt( Subindex1, CHAR_LV) < 120 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.7; + } + }else if( CHAR_getInt( Subindex1, CHAR_LV) < 140 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.8; + } + } + for( i=0; i<4; i++) { + work[i] = base[i]; + } + for( i=0; i<7; i++) { + skill[i] = petskill[i]; + } + if( !CHAR_CHECKINDEX( Subindex2)) return 1; + if( EVOLUTION_getPetFusionCode( CHAR_getInt( Subindex2, CHAR_PETID) ) < 0 ){ + return 0; + } + + if( CHAR_getInt( Subindex2, CHAR_FUSIONBEIT) == 1 || + CHAR_getInt( Subindex2, CHAR_FUSIONRAISE) > 0 )return 0;//ǷΪںϳ + + if( PET_getBaseAndSkill( charaindex, Subindex2, base, NULL, 0) == FALSE ) + return 0; + if( CHAR_getInt( Subindex2, CHAR_LV) < 120 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.7; + } + }else if( CHAR_getInt( Subindex2, CHAR_LV) < 140 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.8; + } + } + for( i=0; i<4; i++) { + work[i] += base[i]; + } + return 2; +} + +BOOL PETFUSION_FusionPetMain( int charaindex, int Mainindex, int *work, int *skill) +{ + int i; + int base[4]={0,0,0,0}; + int petskill[7]={-1,-1,-1,-1,-1,-1,-1}; + if( !CHAR_CHECKINDEX( Mainindex)) return FALSE; + if( EVOLUTION_getPetFusionCode( CHAR_getInt( Mainindex, CHAR_PETID) ) < 0 ){ + return 0; + } + if( CHAR_getInt( Mainindex, CHAR_FUSIONBEIT) == 1 || + CHAR_getInt( Mainindex, CHAR_FUSIONRAISE) > 0 )return FALSE;//ǷΪںϳ + + if( PET_getBaseAndSkill( charaindex, Mainindex, base, petskill, 0) == FALSE ) + return -1; + if( CHAR_getInt( Mainindex, CHAR_LV) < 120 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.7; + } + }else if( CHAR_getInt( Mainindex, CHAR_LV) < 140 ){//ȼ + for( i=0; i<4; i++) { + base[i] = base[i]*0.8; + } + }else + for( i=0; i<4; i++) { + work[i] += base[i]*0.6; + } + for( i=0; i<7; i++) { + skill[i] = petskill[i]; + } + + return TRUE; +} + +BOOL PETFUSION_DelPet( int toindex, int Mainindex, int Subindex1, int Subindex2, int flg) +{ + int i, j, cnt=0; + int petindex[3]; + + + petindex[0] = Mainindex; + petindex[1] = Subindex1; + petindex[2] = Subindex2; + + for( i=0; i<3; i++) { + if( !CHAR_CHECKINDEX( petindex[i] ) ) continue; + for( j=0; j= CHAR_MAXPETHAVE){ + + }else { + char szPet[256]; + char msgbuf[256]; + CHAR_setCharPet( toindex, j, -1); + snprintf( szPet, sizeof( szPet ), "K%d", j); + CHAR_sendStatusString( toindex, szPet ); + + snprintf( msgbuf,sizeof( msgbuf), "%s", CHAR_getChar( petindex[i], CHAR_NAME)); + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORYELLOW); + LogPet( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex[i], CHAR_NAME), + CHAR_getInt( petindex[i], CHAR_LV), + "TenseiDel", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( petindex[i], CHAR_UNIQUECODE) // shan 2001/12/14 + ); + } + CHAR_endCharOneArray( petindex[i] ); + cnt++; + } + if( cnt >= flg ) + return TRUE; + return FALSE; +} + +int PETFUSION_Evolution( int charaindex, int petindex) +{ + char buf[256], buf1[256]; + int newindex=-1; + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, -1); + + sprintf( buf, "%s", CHAR_getChar( petindex, CHAR_NAME)); + newindex = EVOLUTION_createPetFromEnemyIndex( charaindex, petindex, 0); + if( !CHAR_CHECKINDEX( newindex) ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + return -1; + } + sprintf( buf1, "%s", CHAR_getChar( newindex, CHAR_NAME)); + strcat( buf, buf1); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + + LogPetFeed( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( petindex, CHAR_NAME), + petindex, + CHAR_getInt( petindex, CHAR_LV), + buf, // Key + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + CHAR_getChar( petindex, CHAR_UNIQUECODE) ); + + return newindex; +} +#endif + +#ifdef _PET_TRANS +int PETTRANS_getPetBase( int petindex, int *work, int *petrank) +{ + int i, total=-1; + if( !CHAR_CHECKINDEX( petindex) ){ + total = 0; + *petrank = 1; + for( i=0; i<4; i++) { + work[i] = 50; + total += work[i]; + } + }else{ + int LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + *petrank = CHAR_getInt( petindex, CHAR_PETRANK ); + work[0] = (float)(( LevelUpPoint >> 24 ) & 0xFF); + work[1] = (float)(( LevelUpPoint >> 16 ) & 0xFF); + work[2] = (float)(( LevelUpPoint >> 8 ) & 0xFF); + work[3] = (float)(( LevelUpPoint >> 0 ) & 0xFF); + total = ( work[0] + work[1] + work[2] + work[3] ); + if( total > 150 ) total = 150; + if( total < 0 ) total = 0; + } + return total; +} + +#ifdef _PET_2TRANS +int NPC_PetTransManGetAns( int total1, int total2, int LV, int rank, int tran ) +#else +int NPC_PetTransManGetAns( int total1, int total2, int LV, int rank ) +#endif +{ + int ans=0 , TransLV = 100; + float total = 0.00; + int Fx=1; +#if _ATTESTAION_ID == 1 + if( LV > 130 ) LV = 130; +#else + if( LV > 140 ) LV = 140; +#endif + total = ( (float)total1/100 ); // total1=200 + total = total*total*total*total*total; + if( total < 1 ) total = 0; + else total= total*1.3; // total=41.6 С=0 + Fx = (int)((5-rank)*1.2)+5; // rank=0~6 Fx=11(rank=0)С=4(rank=6) + ans = (int)total + total2 + ((LV-TransLV)/Fx); //42+150+30/11=194 + +#ifdef _PET_2TRANS +#ifdef _PET_TRANS_ABILITY + if( tran == 0 ){ + if( ans > getPetTransAbility1() ) + ans = getPetTransAbility1(); + } + else{ + if( ans > getPetTransAbility2() ) + ans = getPetTransAbility2() ; + } +#else + if( tran == 0 ){ + if( ans > 150 ) + ans = 150; + } + else{ + if( ans > 200 ) + ans = 200; + } +#endif +#else + if( ans > 150 ) { + ans = 150; + } +#endif + return ans; +} + +int PETTRANS_PetTransManStatus( int toindex, int petindex1, int petindex2) +{ + int petrank=0,i; + int total1,total2,total,petLV,ans; + int petID,enemynum,ret=-1; + int work[4]={0,0,0,0}; + int base[4]={0,0,0,0}; + +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + total1 = PETTRANS_getPetBase( petindex1, work, &petrank); + total2 = PETTRANS_getPetBase( petindex2, base, &petrank); + petLV = CHAR_getInt( petindex2, CHAR_LV); +#ifdef _PET_2TRANS + ans = NPC_PetTransManGetAns( total1, total2, petLV, petrank, CHAR_getInt( petindex2, CHAR_TRANSMIGRATION ) ); +#else + ans = NPC_PetTransManGetAns( total1, total2, petLV, petrank ); +#endif + total = total1 + (total2*4); + total2 = 0; + for( i=0; i<4; i++) { + work[i] = work[i]*4; + total2 += work[i]; + } + total = total1 + total2; + for( i=0; i<4; i++) { + base[i] = max(1, (ans * (base[i]+work[i])) /total); + } + enemynum = ENEMY_getEnemyNum(); + petID = CHAR_getInt( petindex2, CHAR_PETID); + for( i=0; i CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP) ){ + Myhp = CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP); + } + CHAR_setInt( charaindex, CHAR_HP, Myhp); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_HP); + for( i=0; i CHAR_getWorkInt( petindex, CHAR_WORKMAXHP) ){ + Myhp = CHAR_getWorkInt( petindex, CHAR_WORKMAXHP); + } + CHAR_setInt( petindex, CHAR_HP, Myhp); + CHAR_send_K_StatusString( charaindex, i, CHAR_K_STRING_HP|CHAR_K_STRING_AI); + } + break; + case 2://MP + Myhp = CHAR_getInt( charaindex, CHAR_MP); + dnums = CHAR_getWorkInt( charaindex, CHAR_WORKCHIKULAMP); + Myhp += dnums; + if( Myhp > CHAR_getWorkInt( charaindex, CHAR_WORKMAXMP) ){ + Myhp = CHAR_getWorkInt( charaindex, CHAR_WORKMAXMP); + } + CHAR_setInt( charaindex, CHAR_MP, Myhp); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_MP); + break; + } +} +#endif + +#ifdef _STATUS_WATERWORD //ˮ״̬ +void CHAR_CheckWaterStatus( int charaindex) +{ + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER) == -1 ){ + return; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER) > 0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKSTATUSWATER, + CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER) -1 ); + + if( CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER) != 0 && + CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER)%10 == 0 ){ + char buf1[256]; + sprintf( buf1, "ˮкʱʣ%d֡", + CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER)); + CHAR_talkToCli( charaindex, -1, buf1, CHAR_COLORYELLOW); + } + } + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ){ + return; + } + if( CHAR_getWorkInt( charaindex, CHAR_WORKMAPFLOORTYPE) == 1 && + CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER) <= 0 ){//ˮ + char token[256]; + int defhp=0; + int maxhp = CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP); + int myhp = CHAR_getInt( charaindex, CHAR_HP); + defhp = (maxhp*0.033); + if( defhp <= 0 ) defhp = 1; + myhp = myhp - defhp; + sprintf( token, "޷%d HP", defhp); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + + if( myhp <= 0 ){ + myhp = 1; + if(CHAR_getInt(charaindex,CHAR_FLOOR) == 151 || CHAR_getInt(charaindex,CHAR_FLOOR) == 160 + || CHAR_getInt(charaindex,CHAR_FLOOR) == 161 ) CHAR_warpToSpecificPoint(charaindex,702,213,27); + else CHAR_warpToSpecificPoint( charaindex, 200,102,1021); + } + CHAR_setInt( charaindex, CHAR_HP, myhp); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_HP); + } + +} +#endif + +int CHAR_findSurplusPetBox( int charaindex ) +{ + int i, remnants=0; + for( i=0; i=100700 && oldMetamo<100819){ + int newMetamo; + int hbMetamo[]={ + 100000,100010,100025,100035,100055,100045, + 100060,100070,100095,100090,100100,100110, + 100135,100125,100145,100150,100165,100160, + 100190,100185,100200,100210,100230,100220, + }; + newMetamo=hbMetamo[(oldMetamo-100700)/5]; + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , newMetamo ); + CHAR_setInt( charaindex , CHAR_BASEBASEIMAGENUMBER , newMetamo ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_complianceParameter( charaindex ); + } +} +#endif + +#ifdef _NEW_PLAYER_RIDE +void CHAR_PlayerRide( int charaindex ) +{ + int i,j; + int MetamoList[5][13]={ + /*{ С к Ƥ С Ƥ ñ ̷ Ů }, Ϊ˵ */ + { 100000, 100025, 100055, 100060, 100095, 100100, 100135, 100145, 100165, 100190, 100200, 100230, 2483}, // + { 100005, 100030, 100050, 100065, 100085, 100115, 100120, 100140, 100170, 100195, 100210, 100225, 2481}, // + { 100010, 100035, 100045, 100070, 100090, 100110, 100125, 100150, 100160, 100185, 100215, 100220, 2484}, // + { 100015, 100020, 100040, 100075, 100080, 100105, 100130, 100155, 100175, 100180, 100205, 100235, 2482}, // + { 331 , 483 , 330 , 332 , 483 , 332 , 333 , 333 , 331 , 330 , 332 , 483 , 0 }, // + }; + for(i=0;i<4;i++) + for(j=0;j<12;j++) + if(CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER) == MetamoList[i][j]){ + if(strstr( getPlayerRide(), "ͻ")){ + setNewplayergivepet(3,MetamoList[i][12]); + setNewplayergivepet(4,MetamoList[4][j]); + }else if(strstr( getPlayerRide(), "")){ + setNewplayergivepet(4,MetamoList[4][j]); + }else if(strstr( getPlayerRide(), "ͻ")){ + setNewplayergivepet(4,MetamoList[i][12]); + } + break; + } +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_event.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_event.c new file mode 100644 index 0000000..638a046 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_event.c @@ -0,0 +1,565 @@ +#include "version.h" +#include + +#include "common.h" +#include "char.h" +#include "item_event.h" +#include "net.h" +#include "item.h" +#include "object.h" +#include "lssproto_serv.h" +#include "util.h" +#include "char_data.h" +#include "readmap.h" +#include "map_deal.h" +#include "item.h" +#include "saacproto_cli.h" +#include "npccreate.h" +#include "handletime.h" +#include "anim_tbl.h" +#include "family.h" + +#define SPR_kmydam CG_HIT_MARK_00 +BOOL CHAR_allprewalk( int index,int* dir,int* mode) +{ + int poisonvalue; + poisonvalue = CHAR_getInt(index, CHAR_POISON ); + if( poisonvalue >= 1 ){ + CHAR_setInt(index,CHAR_HP , CHAR_getInt(index,CHAR_HP) + - poisonvalue ); + CHAR_setWorkInt(index,CHAR_WORKLASTATTACKCHARAINDEX,-2); + { + int opt[2] = { SPR_kmydam,poisonvalue}; + CHAR_sendWatchEvent( CHAR_getWorkInt(index,CHAR_WORKOBJINDEX), + CHAR_ACTDAMAGE,opt,2,TRUE); + + CHAR_sendStatusString( index,"M"); + } + poisonvalue--; + if( poisonvalue <= 0)poisonvalue = 1; + CHAR_setInt(index,CHAR_POISON,poisonvalue); + } + if( CHAR_getInt(index,CHAR_CONFUSION) != 0 ) + *dir = RAND(0,7); + if( CHAR_getInt(index,CHAR_STONE) != 0 ) + return FALSE; + return TRUE; +} + +void CHAR_allpostwalk( int index ) +{ + return; +} + +BOOL CHAR_makeCADefaultString( int objindex,char* buf,int buflen, int act ) +{ + char objindexbuf[64]; + /* */ + if( CHECKOBJECT(objindex) == FALSE ) return FALSE; + if( OBJECT_getType(objindex) != OBJTYPE_CHARA ) return FALSE; + snprintf( buf,buflen,"%s|%d|%d|%d|%d", + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex), + act, + CHAR_getInt(OBJECT_getIndex(objindex),CHAR_DIR)); + return TRUE; +} + +static void CHAR_makeCADAMAGEStringFromSpecifiedCoordinate( + int x , int y, char* buf,int buflen,int ef1,int damagevalue ) +{ + snprintf( buf,buflen,"%d|%d|%d|%d|%d|%d|%d", + -1,x,y, CHAR_ACTDAMAGE,0, ef1,damagevalue); +} + +BOOL CHAR_makeCAOPT1String( int objindex,char* buf, int buflen, int act,int opt1 ) +{ + char objindexbuf[64]; + if( CHECKOBJECT(objindex) == FALSE ) return FALSE; + if( OBJECT_getType(objindex) != OBJTYPE_CHARA ) return FALSE; + snprintf( buf,buflen,"%s|%d|%d|%d|%d|%d", + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex), + act, + CHAR_getInt(OBJECT_getIndex(objindex),CHAR_DIR), opt1); + + return TRUE; +} + +#ifdef _STREET_VENDOR +BOOL CHAR_makeCAOPTString(int objindex,char* buf,int buflen,int act,char *string) +{ + char objindexbuf[64]; + + if(CHECKOBJECT(objindex) == FALSE ) return FALSE; + if(OBJECT_getType(objindex) != OBJTYPE_CHARA ) return FALSE; + snprintf( buf,buflen,"%s|%d|%d|%d|%d|%s", + cnv10to62(objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex),act, + CHAR_getInt(OBJECT_getIndex(objindex),CHAR_DIR),string); + return TRUE; +} +#endif + +BOOL CHAR_makeCAOPT3String( int objindex,char* buf, int buflen, int act,int opt1,int opt2,int opt3 ) +{ + char objindexbuf[64]; + + if( CHECKOBJECT(objindex) == FALSE ) return FALSE; + if( OBJECT_getType(objindex) != OBJTYPE_CHARA ) return FALSE; + snprintf( buf,buflen,"%s|%d|%d|%d|%d|%d|%d|%d", + cnv10to62( objindex,objindexbuf, sizeof(objindexbuf)), + OBJECT_getX(objindex), OBJECT_getY(objindex), + act, + CHAR_getInt(OBJECT_getIndex(objindex),CHAR_DIR), + opt1,opt2,opt3); + return TRUE; +} + +void CHAR_playerWatchfunc( int objmeindex, int objmoveindex, + CHAR_ACTION act, int x, int y, int dir, int* opt, int optlen ) +{ + int fd; + int meindex; + if( !CHECKOBJECTUSE(objmeindex) )return; + if( !CHECKOBJECTUSE(objmoveindex))return; + if( OBJECT_getType(objmeindex) != OBJTYPE_CHARA )return; + + meindex = OBJECT_getIndex(objmeindex); + if( CHAR_getInt( meindex,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )return; + + fd = getfdFromCharaIndex( meindex ); + if( fd == -1 )return; + switch( OBJECT_getType(objmoveindex) ){ + case OBJTYPE_CHARA: + { + char buf[128]; + if( !CHAR_getFlg( OBJECT_getIndex(objmoveindex),CHAR_ISVISIBLE) ) + return; + + switch( act ){ + case CHAR_ACTSTAND: + case CHAR_ACTWALK: + case CHAR_ACTATTACK: + case CHAR_ACTDEAD: + case CHAR_ACTMAGIC: + case CHAR_ACTITEM: + case CHAR_ACTDOWN: + case CHAR_ACTSIT: + case CHAR_ACTHAND: + case CHAR_ACTPLEASURE: + case CHAR_ACTANGRY: + case CHAR_ACTSAD: + case CHAR_ACTDAMAGE: + case CHAR_ACTGUARD: + case CHAR_ACTTURN: + case CHAR_ACTWARP: + case CHAR_ACTACTIONWALK: + case CHAR_ACTNOD: + case CHAR_ACTTHROW: + case CHAR_ACTACTIONSTAND: + if( CHAR_makeCADefaultString(objmoveindex,buf,sizeof(buf),act) ) { + CONNECT_appendCAbuf( fd,buf,strlen(buf)); + } + break; + // shan begin + case CHAR_ACTTRADE: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String( objmoveindex, buf, + sizeof( buf), act, opt[0] ) ) + CONNECT_appendCAbuf( fd, buf, strlen(buf)); + break; + +#ifdef _ANGEL_SUMMON + case CHAR_ACTANGEL: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String( objmoveindex, buf, + sizeof( buf), act, opt[0] ) ) + CONNECT_appendCAbuf( fd, buf, strlen(buf)); + break; +#endif + + // shan end +#ifdef _MIND_ICON + case CHAR_MIND: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String( objmoveindex, buf, + sizeof(buf), act, opt[0])) + CONNECT_appendCAbuf( fd, buf, strlen(buf)); + break; +#endif +#ifdef _STREET_VENDOR + case CHAR_STREETVENDOR_OPEN: + if(CHAR_makeCAOPTString(objmoveindex,buf,sizeof(buf), + act,CHAR_getWorkChar(OBJECT_getIndex(objmoveindex),CHAR_STREETVENDOR_NAME))) + CONNECT_appendCAbuf(fd,buf,strlen(buf)); + break; + case CHAR_STREETVENDOR_CLOSE: + if(CHAR_makeCAOPTString(objmoveindex,buf,sizeof(buf), + act,CHAR_getWorkChar(OBJECT_getIndex(objmoveindex),CHAR_STREETVENDOR_NAME))) + CONNECT_appendCAbuf(fd,buf,strlen(buf)); + break; +#endif +#ifdef _ITEM_CRACKER + case CHAR_ITEM_CRACKER: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String( objmoveindex, buf, + sizeof(buf), act, opt[0])) + CONNECT_appendCAbuf( fd, buf, strlen(buf)); + break; +#endif + case CHAR_ACTEFFECT: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String(objmoveindex,buf, + sizeof(buf),act,opt[0] ) ) + CONNECT_appendCAbuf( fd,buf,strlen(buf)); + break; + case CHAR_ACTPOPUPNAME: + case CHAR_ACTLEADER: + case CHAR_ACTBATTLEWATCH: + if( optlen == 1 ) + if( CHAR_makeCAOPT1String(objmoveindex,buf, + sizeof(buf),act,opt[0] ) ) + CONNECT_appendCAbuf( fd,buf,strlen(buf)); + break; + case CHAR_ACTBATTLE: + if( optlen == 3 ) + if( CHAR_makeCAOPT3String( objmoveindex,buf, sizeof(buf), + act,opt[0],opt[1],opt[2] ) ) + CONNECT_appendCAbuf( fd,buf,strlen(buf)); + break; + default: + break; + } + break; + + } + case OBJTYPE_ITEM: + case OBJTYPE_GOLD: + CHAR_sendSpecifiedobjindexCToCharaindex(meindex,objmoveindex); + break; + default: + break; + } + +} + +void CHAR_sendWallDamage( int charaindex,int x, int y, int damage ) +{ + int fd; + char cabuf[256]=""; + + fd = getfdFromCharaIndex(charaindex); + if( fd == -1 )return; + + CHAR_makeCADAMAGEStringFromSpecifiedCoordinate( + x,y,cabuf,sizeof(cabuf),SPR_kmydam,damage ); + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); +} + + + +static struct ParamShow +{ + int paramindex; /* ɷ¶̼͵ */ + char* offmessage; /* ݼ ٯ */ +}pShow[]={ + {CHAR_PARALYSIS, CHAR_RECOVERPARALYSISSTRING}, + {CHAR_SLEEP, CHAR_RECOVERSILENCESTRING}, + {CHAR_STONE, CHAR_RECOVERSTONESTRING}, + {CHAR_DRUNK, CHAR_RECOVERDARKNESSSTRING}, + {CHAR_CONFUSION, CHAR_RECOVERCONFUSIONSTRING}, +}; + +void CHAR_recoveryStatus( int charaindex ) +{ + int i; + int cure=FALSE; + if( !CHAR_CHECKINDEX(charaindex) )return; + + for( i=0 ; i < arraysizeof(pShow) ; i ++ ){ + if( CHAR_getInt(charaindex,pShow[i].paramindex) > 0 ){ + int old; + old = CHAR_setInt(charaindex,pShow[i].paramindex, + CHAR_getInt(charaindex, + pShow[i].paramindex) - 1 ); + if( old == 1 ){ + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + CHAR_talkToCli( charaindex,-1, pShow[i].offmessage, + CHAR_COLORWHITE ); + } + cure = TRUE; + } + } + } + if( cure ){ + CHAR_sendStatusString( charaindex, "P" ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( + charaindex, CHAR_WORKOBJINDEX) ); + } +} + +static BOOL CHAR_clairvoyance_gold(int objindex,char* buf ) +{ + if( OBJECT_getType( objindex ) == OBJTYPE_GOLD ){ + *buf = 'G'; + return TRUE; + } + return FALSE; +} + +static BOOL CHAR_clairvoyance_item(int objindex,char* buf ) +{ + if( OBJECT_getType( objindex ) == OBJTYPE_ITEM){ + *buf = 'I'; + return TRUE; + } + return FALSE; +} + +static BOOL CHAR_clairvoyance_player(int objindex,char* buf ) +{ + if( OBJECT_getType( objindex ) == OBJTYPE_CHARA + && CHAR_getInt(OBJECT_getIndex(objindex),CHAR_WHICHTYPE) + == CHAR_TYPEPLAYER ){ + *buf = 'P'; + return TRUE; + } + return FALSE; +} + +static BOOL CHAR_clairvoyance_enemy(int objindex,char* buf ) +{ + if( OBJECT_getType( objindex ) == OBJTYPE_CHARA + && CHAR_getInt(OBJECT_getIndex(objindex),CHAR_WHICHTYPE) + == CHAR_TYPEENEMY ){ + *buf = 'E'; + return TRUE; + } + return FALSE; +} + +static char CHAR_clairvoyanceString[STRINGBUFSIZ]; + +static void CHAR_clairvoyance( int charaindex ) +{ + char onebuf[128]; + int stringlen=0; + int clairvoyancelevel; + int centerx,centery,fl; + int i,j; + BOOL sendclairvoyance=FALSE; + +#define CHAR_CLAIRVOYANCEWIDTH 81 + BOOL (*clairvoyancefunc[])(int,char*) ={ + CHAR_clairvoyance_gold, + CHAR_clairvoyance_item, + CHAR_clairvoyance_player, + CHAR_clairvoyance_enemy, + }; + if( CHAR_getWorkInt( charaindex, CHAR_WORKLOOPSTARTSEC)%10 != 0 ) + return; + + clairvoyancelevel = CHAR_getInt(charaindex,CHAR_RADARSTRENGTH ); + + if( clairvoyancelevel <= 0 )return; + if( clairvoyancelevel > arraysizeof( clairvoyancefunc ) ) + clairvoyancelevel = arraysizeof( clairvoyancefunc ); + + centerx = CHAR_getInt(charaindex,CHAR_X); + centery = CHAR_getInt(charaindex,CHAR_Y); + fl = CHAR_getInt(charaindex,CHAR_FLOOR); + + + for( i = centerx - CHAR_CLAIRVOYANCEWIDTH/2 ; + i < centerx + CHAR_CLAIRVOYANCEWIDTH/2 ; i ++ ){ + for( j = centery - CHAR_CLAIRVOYANCEWIDTH/2 ; + j < centery + CHAR_CLAIRVOYANCEWIDTH/2 ; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; object ; + object = NEXT_OBJECT( object ) ){ + int objindex = GET_OBJINDEX(object); + int loop; + + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE )continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA + && OBJECT_getIndex(objindex) == charaindex) continue; + for( loop = 0 ; loop < clairvoyancelevel ; loop ++ ){ + BOOL ret; + char id; + ret = clairvoyancefunc[loop](objindex,&id); + if( ret == TRUE ){ + sendclairvoyance=TRUE; + snprintf( onebuf,sizeof(onebuf), + "%d|%d|%c|",i,j,id ); + strcpysafe( CHAR_clairvoyanceString + stringlen, + sizeof(CHAR_clairvoyanceString) + - stringlen, onebuf); + stringlen += strlen(onebuf); + if( stringlen > sizeof(CHAR_clairvoyanceString) ) + goto RETURN; + } + } + } + } + } + +RETURN: + if( stringlen >= 1 ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + dchop( CHAR_clairvoyanceString, "|" ); + if( fd != -1 ) + lssproto_R_send( fd, CHAR_clairvoyanceString ); + }else if( !sendclairvoyance ){ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ) + lssproto_R_send( fd, "" ); + } +} + +void CHAR_loopFunc( int charaindex ) +{ + CHAR_recoveryStatus( charaindex ); + CHAR_clairvoyance( charaindex ); +} + +void CHAR_playerresurrect( int charaindex, int hp ) +{ + CHAR_setInt(charaindex,CHAR_BASEIMAGENUMBER, + CHAR_getInt(charaindex,CHAR_BASEBASEIMAGENUMBER)); + CHAR_setFlg(charaindex,CHAR_ISDIE, 0); + CHAR_setFlg(charaindex,CHAR_ISATTACKED, 1); + CHAR_setFlg(charaindex,CHAR_ISOVERED, 0); + if( hp >= CHAR_getWorkInt(charaindex,CHAR_WORKMAXHP) ) + hp = CHAR_getWorkInt(charaindex,CHAR_WORKMAXHP); + else if( hp <= 0 ) + hp = 1; + CHAR_setInt(charaindex,CHAR_HP, hp); +} + +int CHAR_die( int charaindex ) +{ + CHAR_DischargeParty( charaindex, 0); + { + int bymonster = 0; + int attackindex = CHAR_getWorkInt(charaindex, + CHAR_WORKLASTATTACKCHARAINDEX); + if( attackindex == -2 ) + bymonster = 0; + else if( CHAR_CHECKINDEX(attackindex) == TRUE ){ + if( CHAR_getInt(attackindex,CHAR_WHICHTYPE) + == CHAR_TYPEENEMY ){ + bymonster = 1; + }else{ + bymonster = 2; + } + } + if( bymonster == 0 || bymonster == 1 ){ + int i; + for( i=0 ; i= 1 ){ + int randomindex = RAND(0,itemhavenum-1); + CHAR_DropItem(charaindex,eqindex[randomindex]); + + } + } + + CHAR_DropMoney(charaindex, + CHAR_getInt(charaindex,CHAR_GOLD)/2 ); + CHAR_setInt(charaindex,CHAR_GOLD,0); + } + CHAR_complianceParameter(charaindex); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt(charaindex, CHAR_WORKOBJINDEX) ); + CHAR_setInt(charaindex,CHAR_DEADCOUNT, + CHAR_getInt(charaindex,CHAR_DEADCOUNT)+1); + { + int i; + BOOL old=FALSE; + for( i=0 ; i 0 ){ + old = TRUE; + } + if( CHAR_setInt( charaindex, CHAR_POISON, 0 ) > 0 )old=TRUE; + if( old ) + CHAR_sendCToArroundCharacter( CHAR_getInt(charaindex, CHAR_WORKOBJINDEX)); + } + CHAR_sendStatusString( charaindex, "P"); + CHAR_sendStatusString( charaindex, "I"); + CHAR_setFlg(charaindex,CHAR_ISDIE,1); + CHAR_setFlg(charaindex,CHAR_ISATTACKED,0); + return 0; +} + +void CHAR_playerTalkedfunc( int charaindex, int talkindex,char* message, int color, int channel ) +{ + int fd; + char lastbuf[4096]; + char mesgbuf[4096]; + char escapebuf[4096]; + int fmindex = CHAR_getInt( charaindex, CHAR_FMINDEX ); + fd = getfdFromCharaIndex( charaindex ); + if( fd == -1 )return; + if( (channel>-1) && (fmindex>0) ){ + if( channel == 0 ){ +#ifndef _CHANNEL_MODIFY + snprintf( lastbuf,sizeof(lastbuf),"P|[]%s", +#else + snprintf( lastbuf,sizeof(lastbuf),"P|F|[]%s", +#endif + makeEscapeString( CHAR_appendNameAndTitle(talkindex, message, mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); + } +#ifdef _FMVER21 + else if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( talkindex, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER ){ +#else + else if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( talkindex, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER ){ +#endif +#ifndef _CHANNEL_MODIFY + snprintf( lastbuf,sizeof(lastbuf),"P|[峤㲥]%s", +#else + snprintf( lastbuf,sizeof(lastbuf),"P|F|[峤㲥]%s", +#endif + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); + }else{ + snprintf( lastbuf,sizeof(lastbuf),"P|[%d]%s",channel, + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); + } + }else{ +#ifdef _CHANNEL_MODIFY + if(CHAR_getFlg(talkindex,CHAR_ISPARTYCHAT) && (CHAR_getWorkInt(talkindex,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE)) + snprintf( lastbuf,sizeof(lastbuf),"P|T|[]%s", + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); + else +#ifdef _FONT_SIZE + snprintf( lastbuf,sizeof(lastbuf),"P|P|%s|%d", + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) ), CHAR_getWorkInt( talkindex, CHAR_WORKFONTSIZE) ); +#else + snprintf( lastbuf,sizeof(lastbuf),"P|P|%s", + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); +#endif + +#else + snprintf( lastbuf,sizeof(lastbuf),"P|%s", + makeEscapeString(CHAR_appendNameAndTitle(talkindex, message,mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); +#endif + } + lssproto_TK_send( fd, CHAR_getWorkInt( talkindex, CHAR_WORKOBJINDEX ),lastbuf, color); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_item.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_item.c new file mode 100644 index 0000000..9a3eb12 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_item.c @@ -0,0 +1,2753 @@ +#include "version.h" +#include + +#include "configfile.h" +#include "readmap.h" +#include "map_deal.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "item.h" +#include "lssproto_serv.h" +#include "handletime.h" +#include "log.h" +#include "item_event.h" +#include "battle.h" +#include "petmail.h" +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#ifdef _ANGEL_SUMMON +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +extern int itemLine; + +#ifdef _DROPSTAKENEW +#define CASINOTOKENID 20121 // ֳȯ +#define MAXCASINOMAPNUM 150 // ֳͼ +#define MAXACCUMULATION 1000000 // +typedef struct tagCasinoMapTable +{ + int casinofl; // ֳͼ + int casinox; // ֳ + int casinoy; // ֳ + int casinotype; // ע + int dropflag; // Ƿע flag + char casinoinfo[64]; // ע˵ + int accumulation; // + int stakenum; // ȯ +}CasinoMapTable; +CasinoMapTable casinomap[MAXCASINOMAPNUM] = +{ + { 7008, 13, 13, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 14, 13, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 15, 13, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 16, 13, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 17, 13, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 13, 14, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 14, 14, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 15, 14, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 16, 14, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 17, 14, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 13, 15, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 14, 15, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 15, 15, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 16, 15, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 17, 15, DICE_BIG, 1, "ӣ", 1, 0}, + { 7008, 8, 13, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 9, 13, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 10, 13, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 11, 13, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 12, 13, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 8, 14, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 9, 14, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 10, 14, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 11, 14, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 12, 14, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 8, 15, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 9, 15, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 10, 15, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 11, 15, DICE_SMALL, 1, "ӣС", 1, 0}, + { 7008, 12, 15, DICE_SMALL, 1, "ӣС", 1, 0}, + + { 7005, 22, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 23, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 24, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 25, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 26, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 27, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 28, 21, PET_RACE1, 1, "ٳ", 2, 0}, + { 7005, 22, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 23, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 24, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 25, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 26, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 27, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 28, 24, PET_RACE2, 1, "ٳ", 2, 0}, + { 7005, 22, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 23, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 24, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 25, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 26, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 27, 27, PET_RACE3, 1, "ٳ", 2, 0}, + { 7005, 28, 27, PET_RACE3, 1, "ٳ", 2, 0}, + + { 7003, 21, 15, ROULETTE1, 1, "̺죱", 1, 0}, { 7003, 17, 15, ROULETTE3, 1, "̺죳", 1, 0}, + { 7003, 13, 15, ROULETTE5, 1, "̺죵", 1, 0}, { 7003, 21, 21, ROULETTE6, 1, "̺죶", 1, 0}, + { 7003, 17, 21, ROULETTE8, 1, "̺죸", 1, 0}, { 7003, 15, 21, ROULETTE9, 1, "̺죹", 1, 0}, + { 7003, 13, 21, ROULETTE10, 1, "̺죱", 1, 0}, { 7003, 13, 18, ROULETTE13, 1, "̺죱", 1, 0}, + { 7003, 9, 21, ROULETTE17, 1, "̺죱", 1, 0}, { 7003, 21, 18, ROULETTE18, 1, "̺죱", 1, 0}, + + { 7003, 19, 15, ROULETTE22, 1, "̣", 1, 0}, { 7003, 15, 15, ROULETTE24, 1, "̣", 1, 0}, + { 7003, 19, 21, ROULETTE27, 1, "̣", 1, 0}, { 7003, 11, 15, ROULETTE31, 1, "̣", 1, 0}, + { 7003, 9, 15, ROULETTE32, 1, "̣", 1, 0}, { 7003, 11, 18, ROULETTE34, 1, "̣", 1, 0}, + { 7003, 9, 18, ROULETTE35, 1, "̣", 1, 0}, { 7003, 11, 21, ROULETTE36, 1, "̣", 1, 0}, + { 7003, 19, 18, ROULETTE39, 1, "̣", 1, 0}, { 7003, 17, 18, ROULETTE40, 1, "̣", 1, 0}, + { 7003, 17, 24, ROULETTE41, 1, "̺", 1, 0}, { 7003, 16, 24, ROULETTE41, 1, "̺", 1, 0}, + { 7003, 17, 25, ROULETTE41, 1, "̺", 1, 0}, { 7003, 16, 25, ROULETTE41, 1, "̺", 1, 0}, + { 7003, 14, 24, ROULETTE42, 1, "", 1, 0}, { 7003, 13, 24, ROULETTE42, 1, "", 1, 0}, + { 7003, 14, 25, ROULETTE42, 1, "", 1, 0}, { 7003, 13, 25, ROULETTE42, 1, "", 1, 0}, + + // WON ADD ͼϵ˫Ĵ + { 7003, 11, 24, ROULETTE43, 1, "̵", 1, 0}, { 7003, 10, 24, ROULETTE43, 1, "̵", 1, 0}, + { 7003, 11, 25, ROULETTE43, 1, "̵", 1, 0}, { 7003, 10, 25, ROULETTE43, 1, "̵", 1, 0}, + { 7003, 20, 24, ROULETTE44, 1, "˫", 1, 0}, { 7003, 19, 24, ROULETTE44, 1, "˫", 1, 0}, + { 7003, 20, 25, ROULETTE44, 1, "˫", 1, 0}, { 7003, 19, 25, ROULETTE44, 1, "˫", 1, 0}, + + + + { 7003, 20, 15, (ROULETTE1<<16)+ROULETTE22, 1, "˫ź죱̣", 1, 0}, + { 7003, 18, 15, (ROULETTE3<<16)+ROULETTE22, 1, "˫ź죳̣", 1, 0}, + { 7003, 16, 15, (ROULETTE3<<16)+ROULETTE24, 1, "˫ź죳̣", 1, 0}, + { 7003, 14, 15, (ROULETTE5<<16)+ROULETTE24, 1, "˫ź죵̣", 1, 0}, + { 7003, 12, 15, (ROULETTE5<<16)+ROULETTE31, 1, "˫ź죵̣", 1, 0}, + { 7003, 10, 15, (ROULETTE32<<16)+ROULETTE31, 1, "˫̣̣", 1, 0}, + + { 7003, 20, 18, (ROULETTE18<<16)+ROULETTE39, 1, "˫ź죱̣", 1, 0}, + { 7003, 18, 18, (ROULETTE40<<16)+ROULETTE39, 1, "˫̣̣", 1, 0}, + { 7003, 16, 18, (ROULETTE40<<16)+ROULETTE45, 1, "˫̣ڣ", 1, 0}, + { 7003, 14, 18, (ROULETTE13<<16)+ROULETTE45, 1, "˫ź죱ڣ", 1, 0}, + { 7003, 12, 18, (ROULETTE13<<16)+ROULETTE34, 1, "˫ź죱̣", 1, 0}, + { 7003, 10, 18, (ROULETTE35<<16)+ROULETTE34, 1, "˫̣̣", 1, 0}, + + { 7003, 20, 21, (ROULETTE6<<16) +ROULETTE27, 1, "˫ź죶̣", 1, 0}, + { 7003, 18, 21, (ROULETTE8<<16) +ROULETTE27, 1, "˫ź죸̣", 1, 0}, + { 7003, 16, 21, (ROULETTE8<<16) + ROULETTE9, 1, "˫ź죸죹", 1, 0}, + { 7003, 14, 21, (ROULETTE10<<16)+ ROULETTE9, 1, "˫ź죱죹", 1, 0}, + { 7003, 12, 21, (ROULETTE10<<16)+ROULETTE36, 1, "˫ź죱̣", 1, 0}, + { 7003, 10, 21, (ROULETTE17<<16)+ROULETTE36, 1, "˫ź죱̣", 1, 0}, + { 7003, 8, 15, ROULETTE51, 1, "У", 1, 0}, // + { 7003, 8, 18, ROULETTE52, 1, "У", 1, 0}, + { 7003, 8, 21, ROULETTE53, 1, "У", 1, 0}, + { 7003, 6, 15, ROULETTE61, 1, "룱", 1, 0}, //110 + { 7003, 5, 15, ROULETTE61, 1, "룱", 1, 0}, + { 7003, 6, 16, ROULETTE61, 1, "룱", 1, 0}, + { 7003, 5, 16, ROULETTE61, 1, "룱", 1, 0}, + { 7003, 24, 15, ROULETTE62, 1, "룱", 1, 0}, //1011 + { 7003, 23, 15, ROULETTE62, 1, "룱", 1, 0}, + { 7003, 24, 16, ROULETTE62, 1, "룱", 1, 0}, + { 7003, 23, 16, ROULETTE62, 1, "룱", 1, 0}, + { 7003, 15, 18, ROULETTE45, 1, "()", 1, 0}, + +}; +#endif + + +static char CHAR_sendItemBuffer[STRINGBUFSIZ]; +BOOL CHAR_sendItemDataOne( int charaindex, int haveitemindex) +{ + int itemgrp[1]; + itemgrp[0] = haveitemindex; + return CHAR_sendItemData( charaindex, itemgrp, 1); +} + +BOOL CHAR_sendItemData( int charaindex, int *itemgroup, int num) +{ + int i; + int strlength = 0; + int fd; +#ifdef _NEW_ITEM_ + if( num <= 0 || num > CheckCharMaxItem(charaindex)) return FALSE; +#else + if( num <= 0 || num > CHAR_MAXITEMHAVE) return FALSE; + +#endif + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) { + return FALSE; + } + + for( i = 0; i < num; i ++ ) { + char token[512]; + int itemindex; + if( !CHAR_CHECKITEMINDEX( charaindex, itemgroup[i])) { + continue; + } + itemindex = CHAR_getItemIndex( charaindex, itemgroup[i] ); + if( itemindex >= 0 ) { + + snprintf( token ,sizeof(token),"%d|%s|" ,itemgroup[i], ITEM_makeItemStatusString( -1,itemindex ) ); + } else { + snprintf( token ,sizeof(token),"%s|" , ITEM_makeItemFalseStringWithNum( itemgroup[i]) ); + } + strcpysafe( CHAR_sendItemBuffer + strlength, sizeof(CHAR_sendItemBuffer) - strlength, token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_sendItemBuffer) ) { + break; + } + } + dchop( CHAR_sendItemBuffer , "|" ); + fd = getfdFromCharaIndex( charaindex ); + if( fd != -1 ){ + lssproto_I_send( fd, CHAR_sendItemBuffer ); + return TRUE; + } + return FALSE; +} + +static void CHAR_sendItemDetachEvent( int charaindex,int itemindex ) +{ + char mesg[256]; +#ifdef _ITEM_USE_TIME + if(ITEM_getInt( itemindex, ITEM_USETIME) > 0){ + time_t usetime = ITEM_getInt( itemindex, ITEM_USETIME); + struct tm *tm1 = localtime(&usetime); + snprintf( mesg, sizeof( mesg), "ж%s Чʹ %d%d%d %d:%d:%d", + ITEM_getAppropriateName(itemindex), + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday, + tm1->tm_hour, + tm1->tm_min, + tm1->tm_sec); + + }else +#endif + { + snprintf( mesg, sizeof( mesg), "ж%s ", ITEM_getAppropriateName(itemindex) ); + } + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); +#ifdef _ITEM_METAMO + if( ITEM_getEquipPlace( charaindex, itemindex) == CHAR_BODY + && CHAR_getWorkInt( charaindex, CHAR_WORKITEMMETAMO) != 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, 0); + CHAR_setWorkInt( charaindex, CHAR_WORKNPCMETAMO, 0 ); //npcԻıҲҪ + CHAR_complianceParameter( charaindex); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_talkToCli( charaindex, -1, "ʧЧˣ", CHAR_COLORWHITE); + } +#endif +#ifdef _ITEM_RIDE + if(CHAR_getInt( charaindex , CHAR_RIDEPET ) != -1 ){ + if( !strcmp( ITEM_getChar( itemindex, ITEM_USEFUNC), "ITEM_RIDE") ) { + char ridemetamo[12]; + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + getStringFromIndexWithDelim( itemarg, "|", 2, ridemetamo, sizeof(ridemetamo)); + if(CHAR_getInt( charaindex , CHAR_BASEIMAGENUMBER )==atoi(ridemetamo)){ + CHAR_setInt( charaindex , CHAR_RIDEPET, -1 ); + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , CHAR_getInt( charaindex , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_RIDEPET); + } + } + } +#endif + { + typedef void (*DETACHFUNC)(int,int); + DETACHFUNC def; + def=(DETACHFUNC)ITEM_getFunctionPointer(itemindex,ITEM_DETACHFUNC); + if( def ) { + def( charaindex,itemindex ); + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + RunItemDetachEvent(charaindex,itemindex ); + } +#endif + } +} + +static void CHAR_sendItemAttachEvent( int charaindex,int itemindex ) +{ + char mesg[512]; +#ifdef _ITEM_USE_TIME + if(ITEM_getInt( itemindex, ITEM_USETIME) > 0){ + time_t usetime = ITEM_getInt( itemindex, ITEM_USETIME); + struct tm *tm1 = localtime(&usetime); + snprintf( mesg, sizeof( mesg), "װ%s Чʹ %d%d%d %d:%d:%d", + ITEM_getAppropriateName(itemindex), + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday, + tm1->tm_hour, + tm1->tm_min, + tm1->tm_sec); + + }else +#endif + { + snprintf( mesg, sizeof( mesg), "װ%s ", + ITEM_getAppropriateName(itemindex) ); + } + + + + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); + { + typedef void (*ATTACHFUNC)(int,int); + ATTACHFUNC atf; + atf=(ATTACHFUNC)ITEM_getFunctionPointer(itemindex,ITEM_ATTACHFUNC); + if( atf ){ + atf( charaindex,itemindex ); + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + RunItemAttachEvent(charaindex, itemindex ); + } +#endif + } +} + + +int CHAR_findSurplusItemBox( int charaindex ) +{ + int i, remnants=0, itemindex; + for(i=CHAR_STARTITEMARRAY; i< CheckCharMaxItem(charaindex); i++){ + itemindex = CHAR_getItemIndex( charaindex , i ); + if( itemindex == -1 ) remnants++; + } + return remnants; +} +extern int CheckCharMaxItemChar(Char* ch); + +static int CHAR_findEmptyItemBoxFromChar( Char* ch ) +{ + int i; + int itemMax = CheckCharMaxItemChar(ch); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i ++ ){ + int itemindex; + itemindex = ch->indexOfExistItems[i]; + if( itemindex == -1 )return i; + } + + return -1; +} + +static int CHAR_findEmptyPoolItemBoxFromChar( Char* ch ) +{ + int i; + for( i=0; iindexOfExistPoolItems[i]; + if( itemindex == -1 ) return i; + } + return -1; +} + +int CHAR_findEmptyPoolItemBox( int index ) +{ + Char* ch; + if( !CHAR_CHECKINDEX( index ) )return -1; + ch = CHAR_getCharPointer(index); + if( ch != NULL ) + return CHAR_findEmptyPoolItemBoxFromChar( ch ); + else + return -1; +} + +int CHAR_findEmptyItemBox( int index ) +{ + Char* ch; + + if( !CHAR_CHECKINDEX( index ) )return -1; + ch = CHAR_getCharPointer(index); + if( ch != NULL ) + return CHAR_findEmptyItemBoxFromChar( ch ); + else + return -1; + +} + +#define LACKOFCLASS {CHAR_talkToCli(index,-1,"޷װ",CHAR_COLORWHITE);} +#define CANNOTEQUIP {CHAR_talkToCli(index,-1,"޷װƷ",CHAR_COLORWHITE);} +#define CANNOTEQUIP2 {CHAR_talkToCli(index,-1,"޷ͬʱװͬƷ",CHAR_COLORWHITE);} +#define CANNOTEXCHANGE {CHAR_talkToCli(index,-1,"޷Ʒ",CHAR_COLORWHITE);} +#define CANNOTMOVE {CHAR_talkToCli(index,-1,"޷ƶƷ",CHAR_COLORWHITE);} +#ifdef _ROOKIE_ITEM +#define ROOKIEITEM {CHAR_talkToCli(index,-1,"Ѿ120װѾʺˡ",CHAR_COLORWHITE);} +#endif +#ifdef _TRUMP_EQUIPMENT +#define NOTRUMP {CHAR_talkToCli(index,-1,"ķδ",CHAR_COLORWHITE);} +#endif +static BOOL CHAR_sendSIToCli( int charindex , int from , int to ) +{ + int fd = getfdFromCharaIndex( charindex ); + if( fd != -1 ){ + if(from == -1 && to == -1)return FALSE; + lssproto_SI_send( fd , from, to ); + return TRUE; + } + return FALSE; +} + +static BOOL CHAR_moveItemFromItemBoxToEquip( int index, int fromindex, + int toindex ) +{ + int fromid,toid; + int fromeqplace; + BOOL flg = FALSE; + + if( !CHAR_CHECKINDEX( index ) )return FALSE; + + fromid = CHAR_getItemIndex(index,fromindex); + toid = CHAR_getItemIndex(index,toindex); + if( !ITEM_CHECKINDEX( fromid) ) + return FALSE; +#ifdef _TRUMP_EQUIPMENT +#ifndef _BRAND_NEW_25 + if (toindex == CHAR_EQSHIELD && CHAR_getInt( index, CHAR_TRUMPFLG )<=0){ + NOTRUMP; + return FALSE; + } +#endif +#endif + + if( CHAR_getInt( index, CHAR_TRANSMIGRATION ) <= 0 ){ + if( ITEM_getInt(fromid,ITEM_LEVEL) > CHAR_getInt(index,CHAR_LV) ){ + LACKOFCLASS; + return FALSE; + } + } + +#ifdef _ROOKIE_ITEM + if (CHAR_getInt(index, CHAR_TRANSMIGRATION) > 0||CHAR_getInt(index, CHAR_LV) >= 120) { + if (ITEM_getInt(fromid, ITEM_ID) == getRookieItem(0) + ||ITEM_getInt(fromid, ITEM_ID) == getRookieItem(1) + ||ITEM_getInt(fromid, ITEM_ID) == getRookieItem(2) + ||ITEM_getInt(fromid, ITEM_ID) == getRookieItem(3) + ||ITEM_getInt(fromid, ITEM_ID) == getRookieItem(4)) { + ROOKIEITEM; + return FALSE; + } + } +#endif + +#ifdef _ITEMSET4_TXT + if( CHAR_getInt( index, CHAR_STR) < ITEM_getInt( fromid, ITEM_NEEDSTR) ) return FALSE; + if( CHAR_getInt( index, CHAR_DEX) < ITEM_getInt( fromid, ITEM_NEEDDEX) ) return FALSE; + if( CHAR_getInt( index, CHAR_TRANSMIGRATION) < ITEM_getInt( fromid, ITEM_NEEDTRANS) ) return FALSE; +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + if( ITEM_getInt( fromid, ITEM_NEEDPROFESSION) != 0 ){ + if( CHAR_getInt( index, PROFESSION_CLASS ) != ITEM_getInt( fromid, ITEM_NEEDPROFESSION) ) + return FALSE; + } +#endif +#endif + +#ifdef _FIXBUG_ATTACKBOW + { + if( CHAR_getWorkInt( index, CHAR_WORKITEMMETAMO) > 0 || + CHAR_getWorkInt( index, CHAR_WORKNPCMETAMO) > 0 + || CHAR_getWorkInt( index, CHAR_WORKFOXROUND ) != -1){ //DZС + + int armtype = ITEM_getInt( fromid, ITEM_TYPE ); + + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( index, -1, "޷ʹԶ", CHAR_COLORYELLOW ); + return FALSE; + } + } + } +#endif + +#ifdef _ANGEL_SUMMON + //if( !strcmp( ITEM_getChar( fromid, ITEM_USEFUNC), "ITEM_AngelToken") ) { + if( ITEM_getInt( fromid, ITEM_ID) == ANGELITEM ) { + int mindex; + char nameinfo[64]; + + mindex = checkIfAngel( index); + getMissionNameInfo( index, nameinfo); + if( mindex < 0 || + strcmp( ITEM_getChar( fromid, ITEM_ANGELINFO), missiontable[mindex].angelinfo) || + strcmp( ITEM_getChar( fromid, ITEM_HEROINFO), missiontable[mindex].heroinfo) || + strcmp( ITEM_getChar( fromid, ITEM_ANGELINFO), nameinfo) ) { + + CHAR_talkToCli( index, -1, "Ⲣ޷װ", CHAR_COLORYELLOW ); + return FALSE; + } + } +#endif + + fromeqplace = ITEM_getEquipPlace( index, fromid ); + if( fromeqplace == -1 ){ + CANNOTEQUIP; + return FALSE; + } + //if( BATTLE_GetWepon( charaindex ) != ITEM_BOW ) + + if( fromeqplace == CHAR_DECORATION1 ) { + int checkplace = ( toindex == CHAR_DECORATION1) + ? CHAR_DECORATION2:CHAR_DECORATION1; + int otheritemindex; + + if( toindex == CHAR_DECORATION1 || toindex == CHAR_DECORATION2 ) { + otheritemindex = CHAR_getItemIndex( index, checkplace); + if( ITEM_CHECKINDEX( otheritemindex )) { + int otheritemtype = ITEM_getInt( otheritemindex, ITEM_TYPE); + int myitemtype = ITEM_getInt( CHAR_getItemIndex( index, fromindex) , ITEM_TYPE); + if( otheritemtype == myitemtype) { + if( toid < 0 ) { + CANNOTEQUIP2; + }else { + CANNOTEXCHANGE; + } + return FALSE; + } + } + flg = TRUE; + } + }else { + if( toindex == fromeqplace) flg = TRUE; + } + if( flg ){ + CHAR_setItemIndex(index,toindex,fromid); + CHAR_setItemIndex(index,fromindex,toid); + + if( toid != -1 ) { + CHAR_sendItemDetachEvent( index, toid ); + } + CHAR_sendItemAttachEvent( index, fromid ); + CHAR_sendSIToCli( index, fromindex,toindex ); + }else { + CANNOTEQUIP; + return FALSE; + } + return TRUE; +} + +static BOOL CHAR_moveItemFromEquipToItemBox(int index, int fromindex, + int toindex) +{ + int fromid,toid; + + if( !CHAR_CHECKINDEX( index )) return FALSE; + + fromid = CHAR_getItemIndex(index,fromindex); + toid = CHAR_getItemIndex(index,toindex); + if( fromid < 0 ) + return FALSE; + else if( toid < 0 ){ + CHAR_setItemIndex(index,toindex,fromid); + CHAR_setItemIndex(index,fromindex,-1); + CHAR_sendItemDetachEvent( index,fromid ); + CHAR_sendSIToCli( index,fromindex,toindex); +#ifdef _ALLBLUES_LUA_1_9 + EquipChangeFunction(index,fromindex); +#endif + return TRUE; + } + + return CHAR_moveItemFromItemBoxToEquip(index, toindex,fromindex); +} + +#ifdef _ITEM_PILENUMS +int CHAR_getMyMaxPilenum( int charaindex) +{ + int maxpile; + maxpile = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION) + + (CHAR_getInt( charaindex, CHAR_TRANSMIGRATION)/5) * 2 + 3; + +/* +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + maxpile += CHAR_getInt( charaindex, ATTACHPILE ); +#endif +*/ + +#ifdef _EQUIT_ADDPILE + maxpile += CHAR_getWorkInt( charaindex, CHAR_WORKATTACHPILE); + maxpile = (maxpile<0)?0:maxpile; +#endif + return maxpile; +} + +BOOL CHAR_PileItemFromItemBoxToItemBox( int charaindex, int fromindex, int toindex) +{ + int maxpile, fromid, toid; + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + fromid = CHAR_getItemIndex( charaindex, fromindex); + toid = CHAR_getItemIndex( charaindex, toindex); + + maxpile = CHAR_getMyMaxPilenum( charaindex); + + if( ITEM_CHECKINDEX( toid) && ITEM_CHECKINDEX( fromid) && + (ITEM_getInt( toid, ITEM_ID) == ITEM_getInt( fromid, ITEM_ID)) && + (ITEM_getInt( toid, ITEM_CANBEPILE) == 1) && + (ITEM_getInt( toid, ITEM_USEPILENUMS) < maxpile) && + (ITEM_getInt( fromid, ITEM_USEPILENUMS) < maxpile) ){ + int formpilenum , pilenum, defpilenum; + + pilenum = ITEM_getInt( toid, ITEM_USEPILENUMS); + formpilenum = ITEM_getInt( fromid, ITEM_USEPILENUMS); + defpilenum = ((maxpile-pilenum)>formpilenum)? formpilenum:(maxpile-pilenum); + formpilenum = formpilenum - defpilenum; + pilenum = pilenum + defpilenum; + ITEM_setInt( toid, ITEM_USEPILENUMS, pilenum); + ITEM_setInt( fromid, ITEM_USEPILENUMS, formpilenum); + + if( formpilenum <= 0 ){ + CHAR_setItemIndex( charaindex, fromindex ,-1); + ITEM_endExistItemsOne( fromid); + } + return TRUE; + } + return FALSE; +} +#endif + +static BOOL CHAR_moveItemFromItemBoxToItemBox( int index, int fromindex, int toindex) +{ + int fromid, toid; + + if( !CHAR_CHECKINDEX( index ) ) return FALSE; +#ifdef _ITEM_PILENUMS + if( CHAR_PileItemFromItemBoxToItemBox( index, fromindex, toindex) == TRUE ){ + CHAR_sendItemDataOne( index, toindex); + CHAR_sendItemDataOne( index, fromindex); + return TRUE; + } +#endif + fromid = CHAR_getItemIndex( index, fromindex); + toid = CHAR_getItemIndex( index, toindex); + + CHAR_setItemIndex(index,toindex, CHAR_setItemIndex( index, fromindex, toid)); + CHAR_sendSIToCli( index,fromindex,toindex); + + return TRUE; +} + +void CHAR_moveEquipItem( int index, int fromindex, int toindex ) +{ +#define MOVEITEM_NONE 0 +#define MOVEITEM_EQUIPTOITEM 1 << 0 +#define MOVEITEM_ITEMTOEQUIP 1 << 1 +#define MOVEITEM_ITEMTOITEM 1 << 2 + + int fromid; /* item ƥ̼͵ */ + + + unsigned int moved_any = 0; + while( 1) { + if( !CHAR_CHECKINDEX( index ) )break; + if( CHAR_getFlg( index,CHAR_ISDIE ) )break; + if( fromindex < 0 || fromindex >= CheckCharMaxItem(index) || + toindex < 0 || toindex >= CheckCharMaxItem(index) ) + break; + + fromid = CHAR_getItemIndex(index,fromindex); + if( fromid == -1 || fromid == -2 )break; + if( fromindex == toindex )break; + if( fromindex < CHAR_EQUIPPLACENUM ){ + if( toindex < CHAR_EQUIPPLACENUM ){ + if( CHAR_getItemIndex(index,toindex) < 0 ){ + CANNOTMOVE; + }else{ + CANNOTEXCHANGE; + } + + }else { + moved_any |= CHAR_moveItemFromEquipToItemBox( + index, fromindex, toindex ) + ? MOVEITEM_EQUIPTOITEM : MOVEITEM_NONE; + if( moved_any & MOVEITEM_EQUIPTOITEM) { + char category[3]; + snprintf( category,sizeof( category),"J%d", fromindex); + CHAR_sendStatusString( index , category); + } + } + }else{ + if( toindex < CHAR_EQUIPPLACENUM ) { + moved_any |= CHAR_moveItemFromItemBoxToEquip( + index, fromindex , toindex ) + ? MOVEITEM_ITEMTOEQUIP : MOVEITEM_NONE; + if( moved_any & MOVEITEM_ITEMTOEQUIP) { + char category[3]; + snprintf( category,sizeof( category),"J%d", toindex); + CHAR_sendStatusString( index , category); + } + }else { + moved_any |= CHAR_moveItemFromItemBoxToItemBox( index,fromindex,toindex ) + ? MOVEITEM_ITEMTOITEM : MOVEITEM_NONE; + } + } + CHAR_complianceParameter( index ); + CHAR_sendCToArroundCharacter(CHAR_getWorkInt(index, CHAR_WORKOBJINDEX)); + break; + } + + if( (moved_any & MOVEITEM_EQUIPTOITEM) || (moved_any & MOVEITEM_ITEMTOEQUIP)){ + CHAR_send_P_StatusString( index, + CHAR_P_STRING_HP|CHAR_P_STRING_MAXHP| + CHAR_P_STRING_MP|CHAR_P_STRING_MAXMP| + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_QUICK|CHAR_P_STRING_CHARM| + CHAR_P_STRING_LUCK|CHAR_P_STRING_EARTH| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND + ); + + } + if( !moved_any ) { + CHAR_sendSIToCli( index,-1,-1); + } +} + +int CHAR_addItemToChar( Char* ch, int itemid ) +{ + int itembox; + itembox = CHAR_findEmptyItemBoxFromChar( ch ); + if( itembox == -1 )return -1; + + return ch->indexOfExistItems[itembox]=ITEM_makeItemAndRegist(itemid); +} + +int CHAR_addItem( int charaindex, int itemid ) +{ + Char* ch; + ch = CHAR_getCharPointer(charaindex); + if( ch != NULL ){ + int ret = CHAR_addItemToChar( ch,itemid ); + if( ret == -1 )return ret; + ITEM_setWorkInt(ret,ITEM_WORKCHARAINDEX,charaindex); + ITEM_setWorkInt(ret,ITEM_WORKOBJINDEX,-1); + return ret; + }else + return -1; +} + + +void CHAR_ItemUse( int charaindex, int to_charaindex, int haveitemindex ) +{ + void (*usefunc)(int,int,int)=NULL; + int itemindex; + + if( !CHAR_CHECKINDEX( charaindex ) ){ + print( "ANDY charaindex=%d err\n", charaindex); + return; + } + + if( CHAR_CHECKITEMINDEX( charaindex, haveitemindex) == FALSE ){ + print( "ANDY haveitemindex=%d err\n", haveitemindex); + return; + } +#ifdef _NO_USE_PACKET_MAP + int index; +for(index=0;index<30;index++){ + if(CHAR_getInt(charaindex,CHAR_FLOOR)==getNoPacketMap(index)){ + if (haveitemindex>=CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM){ + char ansmsg[256]; + strcpysafe( ansmsg, sizeof(ansmsg), + "õͼֹʹöİ"); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE ); + return; + } + } +} +#endif + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ){ +// print( "ANDY itemindex=%d err\n", itemindex); + return; + } + if( CHAR_getFlg( charaindex, CHAR_ISDIE ) ){ + print( "ANDY charaindex=%d is CHAR_ISDIE err\n", charaindex); + return; + } +#ifndef _OFFLINE_SYSTEM +#ifdef _STREET_VENDOR + // ̯вʹõ + if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) > -1){ + print("StreetVendor use item charaindex=%d,name=%s\n",charaindex,CHAR_getChar(charaindex,CHAR_NAME)); + return; + } +#endif +#endif + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ) { + if( CHAR_CHECKINDEX( to_charaindex ) ){ + if( CHAR_getInt( to_charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + int action = ITEM_getInt( itemindex, ITEM_USEACTION); + if( action != -1 ) { + CHAR_sendAction( to_charaindex, action, TRUE); + } + } + } + } + // + if( ITEM_getInt( itemindex,ITEM_TYPE) != ITEM_OTHER && + ITEM_getInt( itemindex,ITEM_TYPE) != ITEM_DISH ) { + CHAR_EquipPlace ep; + + ep = ITEM_getEquipPlace( charaindex, itemindex ); + if( ep == -1 )return; + if( ep == CHAR_DECORATION1 ) { + int flg = FALSE; + int toitemindex1 = CHAR_getItemIndex( charaindex, ep); + int toitemindex2 = CHAR_getItemIndex( charaindex, CHAR_DECORATION2); + int searchindex = -1; + int fromitemtype = ITEM_getInt( itemindex, ITEM_TYPE); + + if( !ITEM_CHECKINDEX( toitemindex1)) searchindex = toitemindex2; + else if(!ITEM_CHECKINDEX( toitemindex2)) searchindex = toitemindex1; + if( searchindex != -1 ) { + if( fromitemtype != ITEM_getInt( searchindex, ITEM_TYPE)) { + flg = TRUE; + ep = ( searchindex == toitemindex1) + ? CHAR_DECORATION2:CHAR_DECORATION1; + } + } + if( !flg) { + if( fromitemtype != ITEM_getInt( toitemindex2, ITEM_TYPE)) { + ep = CHAR_DECORATION1; + }else if( fromitemtype != ITEM_getInt( toitemindex1, ITEM_TYPE)) { + ep = CHAR_DECORATION2; + }else { + ep = CHAR_DECORATION1; + } + } + } + CHAR_moveEquipItem( charaindex, haveitemindex,ep ); + return; + } + +#ifdef _ITEM_TALK_CHECK +{ + char *tmp=ITEM_getChar(itemindex, ITEM_NAME); + if(tmp[0]=='@'){ + if(ITEM_getWorkInt(itemindex, ITEM_WORKTALKCHECK)<=0){ + ITEM_setWorkInt(itemindex, ITEM_WORKTALKCHECK, getTalkCheck()); + } + + if(ITEM_getWorkInt(itemindex, ITEM_WORKTALKCHECK)>0){ + if(ITEM_getWorkInt(itemindex, ITEM_WORKTALKCHECK) != CHAR_getWorkInt(charaindex, CHAR_WORK_TALKCHECK)){ + char buf[256]; + ITEM_setWorkInt(itemindex, ITEM_WORKTALKCHECK, getTalkCheck()); + sprintf(buf, "%s֤:%d", ITEM_getChar(itemindex, ITEM_NAME), ITEM_getWorkInt(itemindex, ITEM_WORKTALKCHECK)); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + return; + }else{ + ITEM_setWorkInt(itemindex, ITEM_WORKTALKCHECK, getTalkCheck()); + } + } + } +} +#endif + + + + char *voidname = ITEM_getChar( itemindex, ITEM_USEFUNC); + if(strstr(voidname,"ITEM_USE_LUA")){ + usefunc = (void(*)(int,int,int)) ITEM_Lua; + }else usefunc = (void(*)(int,int,int))ITEM_getFunctionPointer( itemindex,ITEM_USEFUNC ); + if( usefunc ){ + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ’o */ + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ̷ة?į */ +#endif + "Use(ʹõ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + usefunc(charaindex, to_charaindex, haveitemindex); + }else{ +#ifdef _ALLBLUES_LUA_1_2 + if(RunItemUseEvent(itemindex, charaindex, to_charaindex, haveitemindex) == FALSE ) +#endif + { + char ansmsg[256]; + strcpysafe( ansmsg, sizeof(ansmsg), + "ʲҲûз"); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE ); + } + } +} + +BOOL CHAR_DropItemFXY( int charaindex, int itemcharaindex, int fl, + int x, int y, int* objindex ) +{ + int itemindex; + itemindex = CHAR_getItemIndex(charaindex,itemcharaindex); + if( ITEM_CHECKINDEX(itemindex) == FALSE )return -3; + if( MAP_walkAbleFromPoint( fl,x,y, FALSE ) == FALSE ){ + return -2; + } + + { + OBJECT object; + for( object=MAP_getTopObj(fl,x,y) ; object; object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_NOUSE: + break; + case OBJTYPE_ITEM: +#ifdef _DROPSTAKENEW + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID) + { + int i = 0; + int dropflag = 0; + ITEM_Item *itm; + for(i = 0; i < arraysizeof(casinomap); i++){ + if(CHAR_getInt(charaindex, CHAR_FLOOR) == casinomap[i].casinofl){ + if(x == casinomap[i].casinox && y == casinomap[i].casinoy){ + dropflag = 1; + break; + } + } + } + if(dropflag == 1){ + if( (itm = ITEM_getItemPointer( itemindex)) == NULL ) return -1; + strcpysafe( itm->string[ITEM_WATCHFUNC].string, + sizeof(itm->string[ITEM_WATCHFUNC].string), "ITEM_DeleteTimeWatched" ); + + break; + }else{ + + return -1; + } + } +#endif + case OBJTYPE_GOLD: + { + + return -1; + } + case OBJTYPE_CHARA: + { + typedef BOOL (*ITEMPUTFUNC)(int,int); + ITEMPUTFUNC ipfunc; + ipfunc = (ITEMPUTFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex),CHAR_ITEMPUTFUNC) ; + + if( ipfunc && ipfunc(OBJECT_getIndex(objindex), + itemindex) == TRUE) + return -3; + break; + } + default: + break; + } + } + + *objindex = CHAR_DropItemAbsolute( itemindex,fl,x,y, FALSE ); + + if( *objindex == -1 ) + return -3; + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "Drop()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + return 0; + } +} + + +#ifdef _ITEM_PILENUMS //andy_edit 2003/04/01 + +void CHAR_SendDropItem_Stats( int charaindex, int itemindex, int itemcharaindex, int flg) +{ + if( flg == 1 ){ + CHAR_setItemIndex( charaindex, itemcharaindex , -1); + } + CHAR_sendItemDataOne( charaindex, itemcharaindex); + + if( CHAR_complianceParameter( charaindex ) ){ + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX)); + } + + if( 0 <= itemcharaindex && itemcharaindex < CHAR_STARTITEMARRAY && + CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ //Ϊװ + if( ITEM_CHECKINDEX( itemindex) ) + CHAR_sendItemDetachEvent( charaindex, itemindex ); + + CHAR_send_P_StatusString( charaindex, + CHAR_P_STRING_HP|CHAR_P_STRING_MAXHP| + CHAR_P_STRING_MP|CHAR_P_STRING_MAXMP| + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_QUICK|CHAR_P_STRING_CHARM| + CHAR_P_STRING_LUCK|CHAR_P_STRING_EARTH| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND ); + } +} +#ifdef _DROPSTAKENEW +void CHAR_DropStakeByDropItem( int charaindex, int itemcharaindex, int itemindex, int fl, int x, int y) +{ + int j, k, casinoflag = 0, dropflag; + char tmpbuf[256]; + dropflag = CHAR_getWorkInt( charaindex, CHAR_WORKSTAKEFLAG); + if( dropflag >= MAXSTAKENUM){ + snprintf( tmpbuf, sizeof( tmpbuf), "Ѿעˣ޷ע"); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORYELLOW); + return; + } + for (j = 0; j < arraysizeof( casinomap); j++){ + if( CHAR_getInt( charaindex, CHAR_FLOOR) != casinomap[j].casinofl ) continue; + if( x != casinomap[j].casinox || y != casinomap[j].casinoy ) continue; + if( casinomap[j].dropflag == 0 ){ + CHAR_talkToCli( charaindex, -1, "޷ע", CHAR_COLORYELLOW); + return; + }else{ + int objindex; + objindex = CHAR_DropItemAbsolute( itemindex, fl, x, y, FALSE ); + if( objindex == -1 ) return; + ITEM_setInt( itemindex, ITEM_PUTTIME, NowTime.tv_sec+30*60); + CHAR_sendWatchEvent( objindex, CHAR_ACTSTAND, NULL, 0, TRUE); + casinoflag = 1; + snprintf(tmpbuf, sizeof(tmpbuf), " %s עһŲȯ", casinomap[j].casinoinfo); + for(k = 0; k < MAXSTAKENUM; k++){//ע趨 + if(CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + k) != 0) continue; + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + k, casinomap[j].casinotype); + dropflag++; + break; + } + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORYELLOW); +#ifdef _FIX_GAMBLENUM + if (dropflag <= MAXSTAKENUM){ //۵Ķ + int nAcc = CHAR_getInt(charaindex, CHAR_GAMBLENUM); + nAcc -= casinomap[j].accumulation; + CHAR_setInt(charaindex, CHAR_GAMBLENUM, nAcc); + } +#endif + dropflag = ( dropflag >= MAXSTAKENUM )?MAXSTAKENUM:dropflag; + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, dropflag); + break; + } + } + + if( casinoflag == 0) return; + LogItem(CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt(itemindex, ITEM_ID), +#endif + "StakeDrop(ȯ)", + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_SendDropItem_Stats( charaindex, itemindex, itemcharaindex, 1); + +} +#endif + +BOOL CHAR_FindAroundUsabilitySpace( int charaindex, int itemindex, int *fl, int *x, int *y) +{ + int dropx, dropy, i; + BOOL Find = FALSE; + int myfl = CHAR_getInt( charaindex, CHAR_FLOOR); + + for( i = 0 ; i < 8 ; i ++ ){ + OBJECT object; + Find = FALSE; + dropx = CHAR_getInt( charaindex, CHAR_X) + CHAR_getDX( CHAR_getInt( charaindex, CHAR_DIR) + i); + dropy = CHAR_getInt( charaindex, CHAR_Y) + CHAR_getDY( CHAR_getInt( charaindex, CHAR_DIR) + i); + if( MAP_walkAbleFromPoint( myfl, dropx, dropy, FALSE ) == FALSE ) continue; + for( object = MAP_getTopObj( myfl, dropx, dropy) ; object ; object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + if( !CHECKOBJECTUSE( objindex)) continue; + if( OBJECT_getType( objindex) == OBJTYPE_CHARA ){ + typedef BOOL (*ITEMPUTFUNC)(int,int); + ITEMPUTFUNC ipfunc; + ipfunc = (ITEMPUTFUNC)CHAR_getFunctionPointer( OBJECT_getIndex(objindex),CHAR_ITEMPUTFUNC) ; + if( ipfunc && ipfunc( OBJECT_getIndex( objindex), itemindex) == TRUE) + return FALSE; + }else{ + Find = TRUE; + break; + } + } + if( Find == FALSE ){ + *fl = myfl; + *x = dropx; + *y = dropy; + return TRUE; + } + } + return FALSE; +} + +void CHAR_DropItem( int charaindex, int itemcharaindex ) +{ + int itemindex, fl, x, y, ret, objindex, beDropOne = 1; + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex, -1, "ս״̬޷װ", CHAR_COLORYELLOW ); + return; + } +#ifdef _AVID_TRADETRYBUG //װ + if( CHAR_getWorkInt(charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE){ + CHAR_talkToCli( charaindex, -1, "״̬޷װ", CHAR_COLORYELLOW ); + return; + } +#endif + + itemindex = CHAR_getItemIndex( charaindex, itemcharaindex); + if( !ITEM_CHECKINDEX( itemindex)) return; + + +#ifdef _LOCK_PET_ITEM + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*' || FreeDropItem( charaindex, itemindex)==1){ + char dropmsg[256]; + sprintf(dropmsg,"\n%sΪƷ\n\nֱʧ\n\nȷҪôȷ밴[OK]\n",ITEM_getChar(itemindex,ITEM_NAME)); + CHAR_setWorkInt(charaindex,CHAR_WORK_LOCK_PET_ITEM,itemcharaindex); + lssproto_WN_send( getfdFromCharaIndex( charaindex), WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_DROPITEM, + -1, + dropmsg); + return; + } +#endif + + if( ITEM_getInt( itemindex, ITEM_ID) == CASINOTOKENID && + ( CHAR_getInt( charaindex, CHAR_FLOOR ) == 7008 || + CHAR_getInt( charaindex, CHAR_FLOOR ) == 7005 || + CHAR_getInt( charaindex, CHAR_FLOOR ) == 7003 ) ){ + + int dropx, dropy, dropfl; + dropfl = CHAR_getInt( charaindex, CHAR_FLOOR); + dropx = CHAR_getInt( charaindex, CHAR_X) + CHAR_getDX( CHAR_getInt( charaindex, CHAR_DIR)); + dropy = CHAR_getInt( charaindex, CHAR_Y) + CHAR_getDY( CHAR_getInt( charaindex, CHAR_DIR)); + CHAR_DropStakeByDropItem( charaindex, itemcharaindex, itemindex, dropfl, dropx, dropy); + return; + } + //ҳΧռ + if( CHAR_FindAroundUsabilitySpace( charaindex, itemindex, &fl, &x, &y) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ΧĵѾˡ", CHAR_COLORYELLOW ); + return; + } + +#ifdef _ITEM_PILENUMS + if( ITEM_getInt( itemindex, ITEM_CANBEPILE) == 1 && + ITEM_getInt( itemindex, ITEM_USEPILENUMS) > 1 ){ + int ret; + int nums = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + ret = ITEM_makeItemAndRegist( ITEM_getInt( itemindex, ITEM_ID) ); + if( !ITEM_CHECKINDEX( ret)) return; + ITEM_setInt( itemindex, ITEM_USEPILENUMS, nums -1 ); + itemindex = ret; + beDropOne = 0; + } +#endif + //ҵռ + ret = ITEM_eventDrop( itemindex, charaindex, itemcharaindex ); + if( ret == 1 ){ //-1 Ʒ 1 ʧ 0 һƷ + CHAR_SendDropItem_Stats( charaindex, itemindex, itemcharaindex, beDropOne); + return; + }else { + objindex = CHAR_DropItemAbsolute( itemindex, fl, x, y, FALSE ); + if( objindex == -1 ) return; + ITEM_setInt( itemindex, ITEM_PUTTIME, NowTime.tv_sec); +#ifdef _PET_AND_ITEM_UP + ITEM_setChar( itemindex, ITEM_CDKEY, + CHAR_getChar( charaindex, CHAR_CDKEY)); +#endif + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "Drop()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_sendWatchEvent( objindex, CHAR_ACTSTAND, NULL, 0, TRUE); + } + CHAR_SendDropItem_Stats( charaindex, itemindex, itemcharaindex, beDropOne); +} +#else +void CHAR_DropItem( int charaindex, int itemcharaindex ) +{ + int dirx[9],diry[9]; + int i, j; + int floor, objindex=-1; + int droped =0; + int count_item =0, count_chara =0; + int fl, x, y; + int itemindex = CHAR_getItemIndex(charaindex,itemcharaindex); + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !ITEM_CHECKINDEX( itemindex) ) return; +#ifdef _AVID_TRADETRYBUG //װ + if( CHAR_getWorkInt(charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE){ + CHAR_talkToCli( charaindex, -1, "״̬޷װ", CHAR_COLORYELLOW ); + return; + } +#endif +#ifdef _LOCK_PET_ITEM + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + CHAR_talkToCli( charaindex, -1, "󶨵Ʒܶ", CHAR_COLORYELLOW ); + return; + } +#endif +#ifdef _DROPCHECK2 + fl = CHAR_getInt( charaindex, CHAR_FLOOR); + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); + + for( i = x-CHAR_DEFAULTSEESIZ/2 ; i <= x+CHAR_DEFAULTSEESIZ/2 ; i++ ){ + for( j = y-CHAR_DEFAULTSEESIZ/2 ; j <= y+CHAR_DEFAULTSEESIZ/2 ; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj(fl,i,j); object ; object = NEXT_OBJECT(object ) ) { + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_ITEM || OBJECT_getType(objindex) == OBJTYPE_GOLD ) { + count_item++; + } + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + count_chara++; + } + } + } + +#ifdef _DROPSTAKENEW + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID){ + int k = 0; + int casinodropflag = 0; + for(k = 0; k < arraysizeof(casinomap); k++){ + if(fl == casinomap[k].casinofl){ + if(x >= casinomap[k].casinox - 1 && x <= casinomap[k].casinox + 1){ + if(y >= casinomap[k].casinoy - 1 && y <= casinomap[k].casinoy + 1){ + casinodropflag = 1; + break; + } + } + } + } + if(casinodropflag == 0){ +#endif + if( count_item > 80 || count_chara > 80 ) { + CHAR_talkToCli( charaindex, -1, "ƷѾ̫ˣٶˡ", CHAR_COLORYELLOW ); + return; + } +#ifdef _DROPSTAKENEW + } + } +#endif + } +#endif + + for( i = 1 ; i < 8 ; i ++ ){ + dirx[i] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR) + i); + diry[i] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR) + i); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[8] = 0; + diry[8] = 0; + floor = CHAR_getInt( charaindex,CHAR_FLOOR ); + { + int ret; + if( 0 <= itemcharaindex && itemcharaindex < CHAR_STARTITEMARRAY ){ //Ϊװ + CHAR_sendItemDetachEvent( charaindex, itemindex ); + } + ret = ITEM_eventDrop( itemindex, charaindex, itemcharaindex ); + if( ret == 1 ){ //-1 Ʒ 1 ʧ 0 һƷ + itemindex = -1; + goto END; + }else if( ret == -1 ){ + print( "%s:%d err\n", __FILE__,__LINE__); + return; + }else{ + ; + } + } + + droped = 0; + for( i = 0 ; i < 9 ; i ++ ){ + int x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + int y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; +#ifdef _DROPSTAKENEW + // жƷǷΪȯ + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID){ + int j = 0, k = 0; + int bdropstake = 0; + int casinoflag = 0; + for (j = 0; j < arraysizeof(casinomap); j++){ + if (CHAR_getInt(charaindex, CHAR_FLOOR) == casinomap[j].casinofl){ + if (x == casinomap[j].casinox && y == casinomap[j].casinoy){ + char tmpbuf[256]; + int dropflag = CHAR_getWorkInt(charaindex, CHAR_WORKSTAKEFLAG); + casinoflag = 1; + if(casinomap[j].dropflag == 0){ + CHAR_talkToCli(charaindex, -1, "޷ע", CHAR_COLORYELLOW); + return; + }else{ + snprintf(tmpbuf, sizeof(tmpbuf), " %s עһŲȯ", casinomap[j].casinoinfo); + if(dropflag >= MAXSTAKENUM){ + snprintf(tmpbuf, sizeof(tmpbuf), "Ѿעˣ޷ע"); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORYELLOW); + return; + } + for(k = 0; k < MAXSTAKENUM; k++){ + if(CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + k) == 0){ + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + k, casinomap[j].casinotype); + casinomap[j].stakenum = casinomap[j].stakenum + 1; + if(casinomap[j].stakenum >= 100000000) + casinomap[j].stakenum = 100000000; + dropflag++; + if(casinomap[j].stakenum <= 1) + bdropstake = 1; + break; + } + } + } + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORYELLOW); +#ifdef _FIX_GAMBLENUM + //۵Ķ + if (dropflag <= MAXSTAKENUM){ + int nAcc = CHAR_getInt(charaindex, CHAR_GAMBLENUM); + nAcc -= casinomap[j].accumulation; + CHAR_setInt(charaindex, CHAR_GAMBLENUM, nAcc); + } +#endif + if (dropflag >= MAXSTAKENUM){ + dropflag = 0; + for (k = 0; k < MAXSTAKENUM ; k++){ + if (CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + k) > 0) + dropflag++; + } + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, dropflag); + }else{ + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, dropflag); + } + continue; + } + } + } + + // ˵طIJȯһ + if(bdropstake == 0 && casinoflag != 0){ + CHAR_setItemIndex(charaindex, itemcharaindex ,-1); + CHAR_sendItemDataOne(charaindex, itemcharaindex); + LogItem(CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt(itemindex, ITEM_ID), +#endif + "StakeDrop(ȯ)", + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + return; + } + } +#endif + { + int ret = CHAR_DropItemFXY( charaindex,itemcharaindex, + CHAR_getInt(charaindex,CHAR_FLOOR), x, y, &objindex ); + switch( ret ){ + case 0: + droped = 1; +#ifdef _ITEM_ORNAMENTS // WON FIX + if( ITEM_getWorkInt( itemindex, ITEM_CANPICKUP) > 0 ){ + ITEM_setInt( itemindex, ITEM_PUTTIME, NowTime.tv_sec + 60*5); + }else{ + ITEM_setInt( itemindex, ITEM_PUTTIME, NowTime.tv_sec); + } +#else + ITEM_setInt( itemindex, ITEM_PUTTIME, NowTime.tv_sec); +#endif + goto END; + break; + case -1: + case -2: + break; + case -3: + default: + return; + break; + } +#ifdef _DROPSTAKENEW + } +#endif + } +#ifdef _DROPCHECK + if( droped != 1 ) { + CHAR_talkToCli( charaindex, -1, "ΧĵѾˡ", CHAR_COLORYELLOW ); + return; + } +#endif +END: + CHAR_sendWatchEvent( objindex, CHAR_ACTSTAND, NULL, 0, TRUE); + CHAR_setItemIndex( charaindex, itemcharaindex ,-1); +{ + char category[3]; + snprintf( category,sizeof( category),"J%d", itemcharaindex); + CHAR_sendStatusString( charaindex , category); +} + if( CHAR_complianceParameter( charaindex ) ){ + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX) ); + } + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + CHAR_send_P_StatusString( charaindex, + CHAR_P_STRING_HP|CHAR_P_STRING_MAXHP| + CHAR_P_STRING_MP|CHAR_P_STRING_MAXMP| + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_QUICK|CHAR_P_STRING_CHARM| + CHAR_P_STRING_LUCK|CHAR_P_STRING_EARTH| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND + ); + CHAR_sendItemDataOne( charaindex, itemcharaindex); + } + return; +} +#endif + +int CHAR_DropItemAbsolute( int itemindex, int floor, int x, int y, + BOOL net) +{ + Object object; + int objindex; + + if( !ITEM_CHECKINDEX( itemindex) )return FALSE; + + object.type = OBJTYPE_ITEM; + object.index = itemindex; + object.x = x; + object.y = y; + object.floor = floor; + objindex = initObjectOne( &object ); + ITEM_setWorkInt( itemindex,ITEM_WORKOBJINDEX, objindex ); + ITEM_setWorkInt( itemindex,ITEM_WORKCHARAINDEX, -1 ); + if( net ) + CHAR_sendWatchEvent( objindex,CHAR_ACTSTAND,NULL,0,TRUE); + + return objindex; +} + +int CHAR_addItemSpecificItemIndex( int charaindex, int itemindex ) +{ + int emptyindex; + if( CHAR_CHECKINDEX( charaindex) == FALSE) return -1; + if( ITEM_CHECKINDEX( itemindex) == FALSE) return -1; + emptyindex = CHAR_findEmptyItemBox( charaindex ); + if( emptyindex == -1 ){ + return CheckCharMaxItem(charaindex) ; + }else{ + CHAR_setItemIndex( charaindex, emptyindex, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charaindex); + CHAR_sendItemDataOne( charaindex, emptyindex); + } + return emptyindex; +} + +static int CHAR_PickUpItemFXY( int charaindex, int fl ,int x , int y , + int* contents,int* objindex ) +{ + OBJECT object; + + for( object=MAP_getTopObj(fl,x,y) ; object ; object = NEXT_OBJECT(object ) ){ + int index = GET_OBJINDEX(object); + int objtype = OBJECT_getType(index); + if( objtype == OBJTYPE_NOUSE )continue; + else if( objtype == OBJTYPE_ITEM ){ + int ret; + int itemindex = OBJECT_getIndex( index); +#ifdef _ITEM_ORNAMENTS + if( ITEM_getWorkInt( itemindex, ITEM_CANPICKUP) > 0 ){ + return -1; + } +#endif +#ifdef _PET_AND_ITEM_UP + if( strcmp( getItemup(), "" ) == 0 ){ + if(strcmp(ITEM_getChar( itemindex, ITEM_CDKEY), + CHAR_getChar( charaindex, CHAR_CDKEY))!=0){ + if(ITEM_getInt(itemindex, ITEM_ID)!=12808 && ITEM_getInt(itemindex, ITEM_ID)!=2400 && ITEM_getInt(itemindex, ITEM_ID)!=2174){ + return -6; + } + } + } +#endif + +#ifdef _DROPSTAKENEW + // жƷǷΪȯ + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID){ + int i = 0; + int bdropstake = 0, casinoflag = 0, emptyitemindexinchara = -1; + for(i = 0; i < arraysizeof(casinomap); i++){ + if(fl == casinomap[i].casinofl){ + if(x == casinomap[i].casinox && y == casinomap[i].casinoy){ + int j = 0, stakeflag = 0; + int pickupflag = 0; + casinoflag = 1; + if(casinomap[i].dropflag == 0){ + CHAR_talkToCli(charaindex, -1, "Ѿ޷ȡעȯˣ", CHAR_COLORYELLOW); + return -1; + } + stakeflag = CHAR_getWorkInt(charaindex, CHAR_WORKSTAKEFLAG); + if(stakeflag == 0){ + CHAR_talkToCli(charaindex, -1, "ûע޷ȡزȯ", CHAR_COLORYELLOW); + return -1; + } + for(j = 0; j < MAXSTAKENUM; j++){ + if(CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + j) == casinomap[i].casinotype){ + emptyitemindexinchara = CHAR_findEmptyItemBox(charaindex); + if(emptyitemindexinchara < 0) return -2; + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + j, 0); + casinomap[i].stakenum = casinomap[i].stakenum - 1; + stakeflag--; + pickupflag = 1; +#ifdef _FIX_GAMBLENUM + //ӵĶ + { + int nAcc = CHAR_getInt(charaindex, CHAR_GAMBLENUM); + nAcc += casinomap[i].accumulation; + CHAR_setInt(charaindex, CHAR_GAMBLENUM, nAcc); + } +#endif + if(casinomap[i].stakenum <= 0){ + bdropstake = 1; + casinomap[i].stakenum = 0; + } + break; + } + } + if(stakeflag < 0){ + stakeflag = 0; + for(j = 0; j < MAXSTAKENUM; j++){ + if(CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + j) > 0) + stakeflag++; + } + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, stakeflag); + }else + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, stakeflag); + if(pickupflag == 0){ + CHAR_talkToCli(charaindex, -1, "ûڴע޷ȡزȯ", CHAR_COLORYELLOW); + return -1; + } + } + } + } + + if(bdropstake == 0 && casinoflag != 0){// ˵طIJȯһ + char tmpbuf[256]; + if(emptyitemindexinchara != -1){ + int itemid=-1, ret=-1; + itemid = ITEM_makeItemAndRegist(CASINOTOKENID); + if(itemid == -1) return -1; + ret = CHAR_addItemSpecificItemIndex( charaindex, itemid); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( itemid ); + return -1; + } + } + CHAR_sendItemDataOne(charaindex, emptyitemindexinchara); + snprintf(tmpbuf, sizeof(tmpbuf), "ʰ%sѽעȡ", + ITEM_getChar(itemindex, ITEM_NAME)); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORWHITE); + // ¼ؼ¼ + LogItem(CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt(itemindex, ITEM_ID), +#endif + "StakePickUp(ȯ)", + CHAR_getInt(charaindex,CHAR_FLOOR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + ITEM_getChar(itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + return -1; + } + } +#endif + ret = CHAR_addItemSpecificItemIndex( charaindex, itemindex ); + if(ret == CheckCharMaxItem(charaindex) ){ + return -2; + }else if( ret != -1 ) { + typedef void (*PICKUPFUNC)( int, int); + PICKUPFUNC pickupfunc = NULL; + pickupfunc = (PICKUPFUNC)ITEM_getFunctionPointer( + itemindex, ITEM_PICKUPFUNC); + if( pickupfunc){ + pickupfunc( charaindex, itemindex); + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + RunItemPickupEvent(charaindex, itemindex ); + } +#endif + *contents = OBJECT_getIndex(index); + *objindex = index; +// CHAR_sendItemDataOne( charaindex, ret); + return 0; + } + }else if( objtype == OBJTYPE_GOLD ){ + int MaxGold; + long dropgoldamount = 0, newamountgold = 0, Minus = 0, newgold = 0; + long mygold = (long) CHAR_getInt( charaindex, CHAR_GOLD ); + MaxGold = CHAR_getMaxHaveGold( charaindex); + if ((mygold <0) || (mygold > MaxGold))return -2; + dropgoldamount = OBJECT_getIndex(index); + newamountgold = (unsigned int) CHAR_getInt( charaindex,CHAR_GOLD ) + dropgoldamount; + Minus = newamountgold - MaxGold; + if( Minus > 0 ) { + newgold = Minus; + *contents = dropgoldamount - Minus; + }else { + newgold = 0; + *contents = dropgoldamount; + } + OBJECT_setIndex( index, newgold); + CHAR_setInt( charaindex, CHAR_GOLD, min( newamountgold, MaxGold ) ); + *objindex = index; + return 1; + }else if( objtype == OBJTYPE_CHARA ) { + int pindex = OBJECT_getIndex( index); + if( !CHAR_CHECKINDEX( pindex) ) continue; + if( CHAR_getInt( pindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ) { + if( CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOWMODE) == 3 ){ + return -7; + } + int havepetindex = CHAR_getCharPetElement( charaindex); + if( havepetindex == -1 ) { + if( CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOWMODE) != CHAR_PETFOLLOW_NOW ) + return -3; + } + if( CHAR_getWorkInt( charaindex, CHAR_PickAllPet) != TRUE ) { + if( (CHAR_getInt( pindex, CHAR_LV) - CHAR_getInt( charaindex, CHAR_LV) > 20 ) + && (CHAR_getInt( charaindex, CHAR_TRANSMIGRATION ) <= 0 )) { + return -4; + } + } +#ifdef _PET_AND_ITEM_UP + if( strcmp( getPetup(), "" ) == 0 ) +#endif + { + if( !strcmp( CHAR_getChar( pindex, CHAR_OWNERCDKEY), "SYSTEM_WAYI" ) && + !strcmp( CHAR_getChar( pindex, CHAR_OWNERCHARANAME), "SYSTEM_WAYI" ) ){ + }else{ + if( strcmp( CHAR_getChar( pindex, CHAR_OWNERCDKEY), CHAR_getChar( charaindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( pindex, CHAR_OWNERCHARANAME), CHAR_getChar( charaindex, CHAR_NAME) )){ + return -5; + } + } + } + if( CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOWMODE) == CHAR_PETFOLLOW_NOW ){ + CHAR_pickupFollowPet( charaindex, pindex ); + return -1; + } + if( CHAR_getInt( pindex, CHAR_MAILMODE) != CHAR_PETMAIL_NONE){ + if( strcmp( CHAR_getChar( pindex, CHAR_OWNERCDKEY), + CHAR_getChar( charaindex, CHAR_CDKEY)) != 0 || + strcmp( CHAR_getChar( pindex, CHAR_OWNERCHARANAME), + CHAR_getChar( charaindex, CHAR_NAME))!= 0 ){ + return -5; + }else if( CHAR_getInt( pindex, CHAR_MAILMODE) != CHAR_PETMAIL_IDLE5){ + return -5; + } + } + if( CHAR_getInt( pindex, CHAR_MAILMODE) != CHAR_PETMAIL_NONE){ + Char *ch; + CHAR_setInt( pindex, CHAR_MAILMODE, CHAR_PETMAIL_NONE); + CHAR_setInt( pindex, CHAR_PETMAILIDLETIME, 0); + PETMAIL_delPetMailTotalnums( 1); //ֶmail PET + ch = CHAR_getCharPointer( pindex); + if( ch != NULL ) { + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), ""); + CHAR_constructFunctable( pindex); + } + } + CHAR_setWorkInt( pindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetindex, pindex); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + if( CHAR_getInt( pindex, CHAR_PETID) != 718 ) { +#endif +#endif + CHAR_setChar( pindex, CHAR_OWNERCDKEY, + CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( pindex, CHAR_OWNERCHARANAME, + CHAR_getChar( charaindex, CHAR_NAME)); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + } +#endif +#endif +#ifdef _PET_ITEM + CHAR_sendPetItemData( charaindex, havepetindex); +#endif + CHAR_complianceParameter( pindex); +{ + char category[3]; + snprintf( category,sizeof( category),"K%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + snprintf( category,sizeof( category),"W%d",havepetindex); + CHAR_sendStatusString( charaindex, category); +} + CHAR_setInt( pindex, CHAR_PUTPETTIME, 0); + *contents = pindex; + *objindex = index; + return 2; + } + } + } + return -1; +} + +void CHAR_PickUpItem( int charaindex, int dir ) +{ + int i; + int dirx[2],diry[2]; + int searchloopcount=0; + + if( !CHAR_CHECKINDEX(charaindex) )return; + if( CHAR_getFlg( charaindex,CHAR_ISDIE ) )return; + if( CHAR_getWorkInt( charaindex,CHAR_WORKBATTLEMODE ) )return; + if( dir < 0 ){ + searchloopcount = 1; + dirx[0] = 0; + diry[0] = 0; + }else{ + if( dir != CHAR_getInt( charaindex, CHAR_DIR)) { + VALIDATEDIR(dir); + CHAR_setInt(charaindex,CHAR_DIR,dir); + CHAR_sendWatchEvent(CHAR_getWorkInt(charaindex,CHAR_WORKOBJINDEX), + CHAR_ACTSTAND,NULL,0,FALSE); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + searchloopcount=2; + } + for( i = 0 ; i < searchloopcount ; i ++ ){ + int contents,objindex; + int fl = CHAR_getInt(charaindex,CHAR_FLOOR); + + int y = CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + int x = CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + int ret = CHAR_PickUpItemFXY( charaindex,fl,x,y,&contents, &objindex); + switch( ret ){ + case 0: + CHAR_ObjectDelete(objindex); + { + char mesg[256]; +#ifdef _DROPSTAKENEW + int j = 0; + int dropflag = 0; + for(j = 0; j < arraysizeof(casinomap); j++) + { + if(CHAR_getInt(charaindex, CHAR_FLOOR) == casinomap[j].casinofl) + { + if(x == casinomap[j].casinox && y == casinomap[j].casinoy) + { + dropflag = 1; + break; + } + } + } + if(ITEM_getInt(contents, ITEM_ID) == CASINOTOKENID && dropflag == 1) + snprintf( mesg,sizeof(mesg), "ʰ%sѽעȡ", + ITEM_getAppropriateName(contents)); + else +#endif + snprintf( mesg,sizeof(mesg), "ʰ %s", + ITEM_getAppropriateName(contents) ); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); + } + + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + contents, +#else + ITEM_getInt(contents, ITEM_ID), +#endif + "PickUp()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( contents, ITEM_UNIQUECODE), + ITEM_getChar( contents, ITEM_NAME), + ITEM_getInt( contents, ITEM_ID) + ); + } + + return; + break; + case 1: + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + + if( OBJECT_getIndex( objindex) == 0 ) { + CHAR_ObjectDelete(objindex); + }else { + CHAR_sendWatchEvent(objindex,CHAR_ACTSTAND,NULL,0,TRUE); + } + { + char mesg[256]; + if( contents == 0 ) { + snprintf( mesg,sizeof(mesg), "޷ʰStoneˡ" ); + }else { + snprintf( mesg,sizeof(mesg), "ʰ %d Stone",contents ); + } + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); + } + if( contents != 0 ){ + LogStone( + -1, + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + contents, + CHAR_getInt( charaindex, CHAR_GOLD ), + "PickUp(ʰǮ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ) + ); + } + return; + break; + case 2: // + CHAR_ObjectDelete(objindex); + CHAR_setWorkInt( contents, CHAR_WORKOBJINDEX, -1); + { + char mesg[256]; + char *p = NULL; + p = CHAR_getChar( contents, CHAR_USERPETNAME); + if( strlen( p) == 0 ) { + p = CHAR_getChar( contents, CHAR_NAME); + } + + snprintf( mesg,sizeof(mesg), "ʰ %s", p); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); + } + // ʸë׷ + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( contents, CHAR_NAME), + CHAR_getInt( contents, CHAR_LV), + "PickUp()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( contents, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + return; + break; + // Robin 0701 petFollow + case 3: + + /* Իľëе */ + CHAR_ObjectDelete(objindex); + CHAR_setWorkInt( contents, CHAR_WORKOBJINDEX, -1); + { + char mesg[256]; + char *p = NULL; + p = CHAR_getChar( contents, CHAR_USERPETNAME); + if( strlen( p) == 0 ) { + p = CHAR_getChar( contents, CHAR_NAME); + } + + snprintf( mesg,sizeof(mesg), "ʰ %s", p); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORWHITE); + } + // ʸë׷ + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( contents, CHAR_NAME), + CHAR_getInt( contents, CHAR_LV), + "FollowPickUp(ջ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( contents, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + return; + break; + case -1: + break; + case -2: + CHAR_talkToCli( charaindex,-1,"", CHAR_COLORYELLOW); + break; + case -3: + CHAR_talkToCli( charaindex,-1,"", CHAR_COLORYELLOW); + break; + case -4: + CHAR_talkToCli( charaindex,-1,"޷չ˸ó", CHAR_COLORYELLOW); + break; + case -5: + CHAR_talkToCli( charaindex,-1,"޷ʰó", CHAR_COLORYELLOW); + break; + case -6: + CHAR_talkToCli( charaindex,-1,"޷ʰõߡ", CHAR_COLORYELLOW); + break; + default: + return; + } + } + return; +} + +/*------------------------------------------------------------ + * ë ϶ƥ £CHAR_DropMoneyռƥǣ + * ¦ + * charaindex int ƽҷ̼͵ + * itemindex int ʧ ة̼͵(ƽҷ· ƥ) + * fl int ׷ʧ + * x int x + * y int y + * force BOOL 𼰰ҷ + * objindex int* ʧ ة Object ƥ̼ + * ߯Ի + * (ئë Ȼئ) -1 + * (߶ֻ) -2 + * ľ½ -3 + * (巴ڼŷʿ) -4 + * ƥְʧ ة л -5 + * ڻ ƥ -6 + * 0 + ------------------------------------------------------------*/ +static BOOL CHAR_DropMoneyFXY( int charaindex, int amount, int fl , int x, + int y, BOOL force, int* objindex ) +{ + OBJECT object; + int MaxGold; + int mygold = CHAR_getInt( charaindex, CHAR_GOLD ); + if( amount <= 0 )return -6; + if( amount > mygold ) + return -1; + + MaxGold = CHAR_getMaxHaveGold( charaindex); + if ((mygold <0) || (mygold > MaxGold)) return -1; + + if( MAP_walkAbleFromPoint( fl,x,y,FALSE ) == FALSE )return -2; + for( object=MAP_getTopObj(fl,x,y) ; object; + object = NEXT_OBJECT(object) ){ + int index = GET_OBJINDEX(object); + int objtype = OBJECT_getType(index); + + if( objtype == OBJTYPE_NOUSE ) continue; + else if( objtype == OBJTYPE_GOLD ){ + long tmpamount = OBJECT_getIndex(index) + amount; + if( tmpamount > MaxGold ) + return -4; + OBJECT_setIndex(index,tmpamount); + CHAR_setInt(charaindex,CHAR_GOLD, + (unsigned int)CHAR_getInt(charaindex, + CHAR_GOLD ) + - amount ); + *objindex = index; +#ifdef _DEL_DROP_GOLD + OBJECT_setTime( index, NowTime.tv_sec); +#endif + if( amount >= 100 ){ /* ë ׷ */ + LogStone(-1,CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), /* ǡID */ + amount, /* ź */ + CHAR_getInt( charaindex, CHAR_GOLD ), + "Drop(ýǮ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ) + ); + } + return 0; + }else if( objtype == OBJTYPE_ITEM ){ + if( force==TRUE ) + continue; + else + /* ƥʧ ةؤ¼ƥֻ */ + return -5; + } + } + + /* ƥеǷޥ */ + { + Object one; + one.type = OBJTYPE_GOLD; + one.x = x; + one.y = y; + one.floor = fl; + + if( amount > MaxGold ) + return -4; + + one.index = amount; + *objindex = initObjectOne( &one ); + /* Ƥ */ + if( *objindex == -1 ) + /* */ + return -3; + + /*ëӼ*/ + CHAR_setInt(charaindex,CHAR_GOLD, + (unsigned int)CHAR_getInt(charaindex,CHAR_GOLD ) + - amount ); +#ifdef _DEL_DROP_GOLD + OBJECT_setTime( *objindex, NowTime.tv_sec); +#endif + if( amount >= 100 ){ /* ë ׷ */ + LogStone(-1,CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), /* ǡID */ + amount, /* ź */ + CHAR_getInt( charaindex, CHAR_GOLD ), + "Drop(ýǮ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ) + ); + } + return 0; + } +} + +/*------------------------------------------------------------ + * ë ѣ 󡾮 ʣ + * ¦ + * charaindex int ƽҷ̼͵ + * amount int ż + * + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_DropMoney( int charaindex, int amount ) +{ + int dirx[9],diry[9]; + int ret; + int i; + int objindex, MaxGold; + + if( !CHAR_CHECKINDEX( charaindex ) )return; + +#ifdef _AVID_TRADETRYBUG //ʯ + if( CHAR_getWorkInt( charaindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_TRADING ){ + CHAR_talkToCli( charaindex, -1, "״̬޷ʯҡ", CHAR_COLORYELLOW ); + return; + } +#endif + + MaxGold = CHAR_getMaxHaveGold( charaindex); + if( CHAR_getFlg( charaindex,CHAR_ISDIE ) )return; + + //ANDY_ADD 12/28 + { + int money=0; + money = CHAR_getInt( charaindex, CHAR_GOLD ); + if( money < 0 ) { + CHAR_setInt( charaindex, CHAR_GOLD, 0); + return; + } + if( (amount > money) || (money > MaxGold)) { + if( money > MaxGold ) { + CHAR_setInt( charaindex, CHAR_GOLD, 0 ); + print("\n ERR: %s(stone%d) dropMoney%d > CHAR_MAXGOLDHAVE !!", + CHAR_getChar(charaindex, CHAR_CDKEY), money, amount); + }else { + print("\n ERR: %s dropMoney > CHAR_GOLD !!", CHAR_getChar(charaindex, CHAR_CDKEY)); + } + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + return; + } + } + //ANDY_END + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX( CHAR_getInt(charaindex,CHAR_DIR) + i+1 ); + diry[i+2] = CHAR_getDY( CHAR_getInt(charaindex,CHAR_DIR) + i+1 ); + } + + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + + for( i = 0 ; i < 9 ; i ++ ){ + int x = CHAR_getInt(charaindex,CHAR_X) + dirx[i]; + int y = CHAR_getInt(charaindex,CHAR_Y) + diry[i]; + +// CoolFish 2002/04/06 עɶʯ +#ifdef _DROPSTAKENEW + { + int j = 0; + for(j = 0; j < arraysizeof(casinomap); j++) + { + if(CHAR_getInt(charaindex, CHAR_FLOOR) == casinomap[j].casinofl) + { + if (x == casinomap[j].casinox && y == casinomap[j].casinoy) + { + CHAR_talkToCli(charaindex, -1, "ﲻܷʯң", CHAR_COLORYELLOW); + return; + } + } + } + } +#endif + ret = CHAR_DropMoneyFXY( charaindex,amount, + CHAR_getInt(charaindex,CHAR_FLOOR), + x,y, FALSE, &objindex ); + switch( ret ){ + case 0: + goto END; + break; + case -1: + return; + break; + case -3: + return; + break; + case -2: + case -4: + case -5: + case -6: + break; + default: + break; + } + } + + { + int x = CHAR_getInt(charaindex,CHAR_X) + dirx[1]; + int y = CHAR_getInt(charaindex,CHAR_Y) + diry[1]; + + ret = CHAR_DropMoneyFXY( charaindex,amount, + CHAR_getInt(charaindex,CHAR_FLOOR), + x,y, TRUE, &objindex ); + switch( ret ){ + case 0: + goto END; + break; + case -1: + break; + case -3: + return; + break; + case -2: + case -4: + case -5: + break; + default: + break; + } + return; + } + +END: + CHAR_sendWatchEvent(objindex,CHAR_ACTSTAND,NULL,0,TRUE ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + return; +} + +static int CHAR_findEmptyItemBoxNoFromChar( Char* ch ) +{ + int i, j=0;; + int itemMax = CheckCharMaxItemChar(ch); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i ++ ){ + int itemindex; + itemindex = ch->indexOfExistItems[i]; + if( itemindex == -1 ) j++; + } + return j; +} + +int CHAR_findEmptyItemBoxNo( int index ) +{ + Char* ch; + + if( !CHAR_CHECKINDEX( index ) )return -1; + ch = CHAR_getCharPointer(index); + if( ch != NULL ) + return CHAR_findEmptyItemBoxNoFromChar( ch ); + else + return -1; + +} + +// CoolFish: Trade 2001/4/4 +int CHAR_findTotalEmptyItem( int index ) +{ + int i, totaleptitem = 0; + Char* ch; + + if( !CHAR_CHECKINDEX( index ) )return -1; + ch = CHAR_getCharPointer(index); + if( ch != NULL ){ + for (i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(index); i++){ + int itemindex = 0; + itemindex = ch->indexOfExistItems[i]; + if (itemindex == -1) totaleptitem++; + } + return totaleptitem; + } + + return -1; +} + +int CHAR_pickupFollowPet( int charaindex, int pickupindex ) +{ + int petindex; + int objindex; + int havepetindex; + char category[3]; + if( !CHAR_CHECKINDEX( charaindex ) ) return FALSE; + if( pickupindex != -1 ) + petindex = pickupindex; + else{ +#ifdef _PETFOLLOW_NEW_ + int petnum; + petnum=0; + for(;petnum<5;petnum++){ + petindex = CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW +petnum); + if( !CHAR_CHECKINDEX( petindex ) ){ + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW +petnum, -1 ); + }else{ +#ifdef _PETFOLLOW_NEW_ + int havepetindex = CHAR_getCharPetElementOld( charaindex); +#else + int havepetindex = CHAR_getCharPetElement( charaindex); +#endif + if( havepetindex == -1 ) { + CHAR_talkToCli(charaindex,-1,"޷ʰأ",CHAR_COLORYELLOW); + return FALSE; + } + objindex = CHAR_getWorkInt( petindex, CHAR_WORKOBJINDEX ); + if( (pickupindex == -1) || (pickupindex == CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW + petnum) ) ) + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum, -1 ); + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( charaindex, CHAR_CDKEY)) != 0 || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( charaindex, CHAR_NAME)) != 0 ) + { + return FALSE; + } + CHAR_ObjectDelete(objindex); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWMODE, CHAR_PETFOLLOW_NONE ); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetindex, petindex); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + if( CHAR_getInt( petindex, CHAR_PETID) != 718 ) { +#endif +#endif + CHAR_setChar( petindex, CHAR_OWNERCDKEY, CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, CHAR_getChar( charaindex, CHAR_NAME)); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + } +#endif +#endif + snprintf( category,sizeof( category),"K%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + snprintf( category,sizeof( category),"W%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + CHAR_setInt( petindex, CHAR_PUTPETTIME, 0); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_setWorkInt( petindex, CHAR_WORKOBJINDEX, -1); + { + char mesg[256]; + char *p = NULL; + p = CHAR_getChar( petindex, CHAR_USERPETNAME); + if( strlen( p) == 0 ) { + p = CHAR_getChar( petindex, CHAR_NAME); + } + snprintf( mesg,sizeof(mesg), "ʰ %s", p); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORYELLOW); + } + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "FollowPickUp(ջ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + } + } + return TRUE; +#else + petindex = CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW ); +#endif + } + if( !CHAR_CHECKINDEX( petindex ) ) + { + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, -1 ); +#ifdef _PETFOLLOW_NEW_ + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+1, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+2, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+3, -1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+4, -1 ); +#endif + return FALSE; + } +#ifdef _PETFOLLOW_NEW_ + havepetindex = CHAR_getCharPetElementOld( charaindex); +#else + havepetindex = CHAR_getCharPetElement( charaindex); +#endif + if( havepetindex == -1 ) { + CHAR_talkToCli(charaindex,-1,"޷ʰأ",CHAR_COLORYELLOW); + return FALSE; + } + objindex = CHAR_getWorkInt( petindex, CHAR_WORKOBJINDEX ); + + +#ifdef _PETFOLLOW_NEW_ + int petnum; + petnum=0; + for(;petnum<5;petnum++){ + if( (pickupindex == -1) || (pickupindex == CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum ) ) ) + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum, -1 ); + } +#else + if( (pickupindex == -1) || (pickupindex == CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW ) ) ) + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, -1 ); +#endif + /* CDKEY ƽҷ ئ巴ئ */ + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( charaindex, CHAR_CDKEY)) != 0 || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( charaindex, CHAR_NAME)) != 0 ) + { + return FALSE; + } + CHAR_ObjectDelete(objindex); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWMODE, CHAR_PETFOLLOW_NONE ); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetindex, petindex); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + if( CHAR_getInt( petindex, CHAR_PETID) != 718 ) { +#endif +#endif + CHAR_setChar( petindex, CHAR_OWNERCDKEY, CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, CHAR_getChar( charaindex, CHAR_NAME)); +#ifndef _FIX_COPY_MM_BUG +#ifdef _PET_TALK + } +#endif +#endif + snprintf( category,sizeof( category),"K%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + snprintf( category,sizeof( category),"W%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + CHAR_setInt( petindex, CHAR_PUTPETTIME, 0); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_setWorkInt( petindex, CHAR_WORKOBJINDEX, -1); + + char mesg[256]; + char *p = NULL; + p = CHAR_getChar( petindex, CHAR_USERPETNAME); + if( strlen( p) == 0 ) { + p = CHAR_getChar( petindex, CHAR_NAME); + } + snprintf( mesg,sizeof(mesg), "ʰ %s", p); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORYELLOW); + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "FollowPickUp(ջ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + return TRUE; + +} +#ifdef _GAMBLE_ROULETTE +int NPC_MAPCLEANGOLD( int meindex , int floor) +{ + OBJECT object; + int x,y,fl; + int End_type; + fl = floor; + + for( End_type = 0; End_type < arraysizeof(casinomap) ; End_type++ ) { + if( floor != casinomap[ End_type].casinofl ) + continue; + x = casinomap[ End_type].casinox; + y = casinomap[ End_type].casinoy; + + for( object=MAP_getTopObj(fl,x,y) ; object ; object = NEXT_OBJECT(object ) ) { + int index = GET_OBJINDEX(object); + int objtype = OBJECT_getType(index); + int itemindex = OBJECT_getIndex( index); + + if( objtype == OBJTYPE_NOUSE )continue; + if( objtype == OBJTYPE_ITEM ){ + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID) { + ITEM_endExistItemsOne( itemindex); + OBJECT_setIndex( index, 0); + CHAR_ObjectDelete(index); // + print(" clean( %d )", index ); + } + break; + } + } + casinomap[End_type].stakenum = 0; + } + return 1; +} +#endif + +#ifdef _DROPSTAKENEW +// casinotype : flg = 0 typetype趨 +// mapdropflag : TRUE = ע; +int SetCasinoMap(int npcindex, int casinotype, int mapdropflag) +{ + int npcfloor = CHAR_getInt(npcindex, CHAR_FLOOR); + int i = 0; + if (casinotype < 0 || mapdropflag < 0) + return -1; + for (i = 0; i < arraysizeof(casinomap); i++) + { + if (npcfloor == casinomap[i].casinofl) + { + if (casinotype != 0) + { + if (casinomap[i].casinotype == casinotype) + casinomap[i].dropflag = mapdropflag; + } + else + casinomap[i].dropflag = mapdropflag; + } + } + return 1; +} + +// +int CasinoAccumulation(int charindex, int npcindex, int floor, int wincasinotype) +{ + int i = 0; + int accumulation = CHAR_getInt(charindex, CHAR_GAMBLENUM); + char tmpbuf[256]; + for (i = 0; i < MAXSTAKENUM; i++) + { + if (CHAR_getWorkInt(charindex, CHAR_WORKSTAKETYPE1 + i) == wincasinotype) + { + int j = 0; + for (j = 0; j < arraysizeof(casinomap); j++) + { + if (casinomap[j].casinotype == wincasinotype) + { +#ifdef _FIX_GAMBLENUM + // ԭּWIN + accumulation = accumulation + casinomap[j].accumulation * 2; +#else + accumulation += casinomap[j].accumulation; +#endif + CHAR_setWorkInt(charindex, CHAR_WORKSTAKETYPE1 + i, 0); + break; + } + } + } + + else if (CHAR_getWorkInt(charindex, CHAR_WORKSTAKETYPE1 + i) != 0) + { + int j = 0; + for (j = 0; j < arraysizeof(casinomap); j++) + { + if (casinomap[j].casinotype == CHAR_getWorkInt(charindex, CHAR_WORKSTAKETYPE1 + i)) + { +#ifndef _FIX_GAMBLENUM + accumulation -= casinomap[j].accumulation; +#endif + CHAR_setWorkInt(charindex, CHAR_WORKSTAKETYPE1 + i, 0); + break; + } + } + } + } + CHAR_setWorkInt(charindex, CHAR_WORKSTAKEFLAG, 0); + if (accumulation < 0) + accumulation = 0; + else if (accumulation > MAXACCUMULATION) + accumulation = MAXACCUMULATION; + CHAR_setInt(charindex, CHAR_GAMBLENUM, accumulation); + snprintf(tmpbuf, sizeof(tmpbuf), "ܹ%4dֳ", accumulation); + CHAR_talkToCli(charindex, npcindex, tmpbuf, CHAR_COLORWHITE); + return 1; +} + +int CasinoPay(int npcindex, int wincasinotype) +{ + int npcfloor = CHAR_getInt(npcindex, CHAR_FLOOR); + int i = 0; + int playernum = CHAR_getPlayerMaxNum(); + if (wincasinotype < 0) return FALSE; + for (i = 0; i < playernum; i++) + { + if (CHAR_getCharUse(i) == FALSE) continue; + if (!CHAR_CHECKINDEX(i)) continue; + if (CHAR_getInt(i, CHAR_FLOOR) == npcfloor) + { + // ѯǷע + if (CHAR_getWorkInt(i, CHAR_WORKSTAKEFLAG) == 0) + continue; + // + CasinoAccumulation(i, npcindex, npcfloor, wincasinotype); + } + } + // ˲ȯ + for (i = 0; i < arraysizeof(casinomap); i++) + { + OBJECT object; + if (casinomap[i].casinofl != npcfloor) continue; + for (object = MAP_getTopObj(casinomap[i].casinofl, casinomap[i].casinox, + casinomap[i].casinoy); object; object = NEXT_OBJECT(object)) + { + int index = GET_OBJINDEX(object); + int objtype = OBJECT_getType(index); + int itemindex = OBJECT_getIndex( index); + if (objtype == OBJTYPE_NOUSE) continue; + else if (objtype == OBJTYPE_ITEM) + { + if(ITEM_getInt(itemindex, ITEM_ID) == CASINOTOKENID) + { + OBJECT_setIndex(index, 0); + CHAR_ObjectDelete(index); + } + } + } + casinomap[i].stakenum = 0; + } + return TRUE; +} +#endif + +#ifdef _PET_ITEM +void CHAR_sendPetItemData( int charaindex, int petid) +{ + int i; + char CHAR_statusSendBuffer[1024]; + int strlength = 2; + int petindex = CHAR_getCharPet( charaindex, petid); + if(!CHAR_CHECKINDEX(petindex)) return; + int fd = getfdFromCharaIndex( charaindex ); + snprintf( CHAR_statusSendBuffer ,sizeof(CHAR_statusSendBuffer),"B%d" , petid); + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + char token[512]; + int itemindex; + itemindex = CHAR_getItemIndex( petindex, i ); + if( itemindex >= 0 ) { + snprintf( token ,sizeof(token),"%s|" ,ITEM_makeItemStatusString( -1, itemindex ) ); + }else { + snprintf( token ,sizeof(token),"%s|" , ITEM_makeItemFalseString() ); + } + strcpysafe( CHAR_statusSendBuffer + strlength, + sizeof(CHAR_statusSendBuffer) - strlength, token ); + strlength += strlen( token ); + if( strlength >= arraysizeof(CHAR_statusSendBuffer) ) lssproto_S_send(fd, CHAR_statusSendBuffer); + } + dchop( CHAR_statusSendBuffer , "|" ); + lssproto_S_send(fd, CHAR_statusSendBuffer); +} + +void CHAR_movePetItem( int charaindex, int petid, int fromindex, int toindex ) +{ + if( !CHAR_CHECKINDEX( charaindex ) )return; + if( CHAR_getFlg( charaindex,CHAR_ISDIE ) )return; + int petindex = CHAR_getCharPet( charaindex, petid); + char token[512]; + if(toindex == -1 && fromindex >= CHAR_EQUIPPLACENUM && fromindex < CheckCharMaxItem(charaindex)){ + int itemindex = CHAR_getItemIndex( charaindex, fromindex ); + toindex=ITEM_getInt( itemindex, ITEM_TYPE)-ITEM_PET_HEAD; + }else if(toindex == -2){ + if(fromindex=0 && fromindex < CHAR_PETITEMNUM && toindex >= CHAR_EQUIPPLACENUM && toindex < CheckCharMaxItem(charaindex)) + || (toindex >=0 && toindex < CHAR_PETITEMNUM && fromindex >= CHAR_EQUIPPLACENUM && fromindex < CheckCharMaxItem(charaindex))){ + if(fromindex >= CHAR_EQUIPPLACENUM){ + int charitemindex = CHAR_getItemIndex( charaindex, fromindex ); + int petitemindex = CHAR_getItemIndex( petindex, toindex ); + int type=ITEM_getInt( charitemindex, ITEM_TYPE); + if(CHAR_getInt(petindex, CHAR_VARIABLEAI) < 100){ + CHAR_talkToCli( charaindex, -1, "޷ѵװƷ", CHAR_COLORRED ); + return; + } + if(typeITEM_PET_FEET || (type-ITEM_PET_HEAD) != toindex){ + CHAR_talkToCli( charaindex, -1, "޷װƷ", CHAR_COLORWHITE ); + return; + } + if( CHAR_getInt( petindex, CHAR_LV) < ITEM_getInt( charitemindex, ITEM_LEVEL)){ + CHAR_talkToCli( charaindex, -1, "ȼδװƷ", CHAR_COLORYELLOW ); + return; + } + if( ITEM_CHECKINDEX( petitemindex)){ + sprintf( token, "%s ж%s", CHAR_getChar( petindex, CHAR_NAME), ITEM_getChar( petitemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE ); + } + sprintf( token, "%s װ%s", CHAR_getChar( petindex, CHAR_NAME), ITEM_getChar( charitemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE ); + CHAR_setItemIndex( charaindex, fromindex, petitemindex ); + CHAR_setItemIndex( petindex, toindex, charitemindex ); + CHAR_sendItemDataOne( charaindex, fromindex); + CHAR_sendPetItemData( charaindex, petid); + }else{ + int charitemindex = CHAR_getItemIndex( charaindex, toindex ); + int petitemindex = CHAR_getItemIndex( petindex, fromindex ); + int type=ITEM_getInt( charitemindex, ITEM_TYPE); + sprintf( token, "%s ж%s", CHAR_getChar( petindex, CHAR_NAME), ITEM_getChar( petitemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE ); + if( ITEM_CHECKINDEX( charitemindex)){ + if(CHAR_getInt(petindex, CHAR_VARIABLEAI) < 100){ + CHAR_talkToCli( charaindex, -1, "޷ѵװƷ", CHAR_COLORRED ); + return; + } +/* + if (CHAR_getInt( charaindex, CHAR_RIDEPET ) == petid ){ + CHAR_talkToCli( charaindex, -1, "еij޷װƷ", CHAR_COLORRED ); + return; + } +*/ + if(typeITEM_PET_FEET || (type-ITEM_PET_HEAD) != toindex){ + CHAR_talkToCli( charaindex, -1, "޷װƷ", CHAR_COLORWHITE ); + return; + } + if( CHAR_getInt( petindex, CHAR_LV) < ITEM_getInt( charitemindex, ITEM_LEVEL)){ + CHAR_talkToCli( charaindex, -1, "ȼδװƷ", CHAR_COLORYELLOW ); + return; + } + sprintf( token, "%s װ%s", CHAR_getChar( petindex, CHAR_NAME), ITEM_getChar( charitemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE ); + } + CHAR_setItemIndex( charaindex, toindex, petitemindex ); + CHAR_setItemIndex( petindex, fromindex, charitemindex ); + CHAR_sendItemDataOne( charaindex, toindex); + CHAR_sendPetItemData( charaindex, petid); + } + } + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( charaindex, token ); +} + +void CHAR_sendPetItemEmpty( int charaindex, int petid) +{ + int fd = getfdFromCharaIndex( charaindex ); + char CHAR_statusSendBuffer[16]; + sprintf(CHAR_statusSendBuffer,"B%d|",petid); + lssproto_S_send(fd, CHAR_statusSendBuffer); +} + +#endif +#ifdef _ROOKIE_ITEM +void CHAR_CheckUserItem( int charaindex ){ + int i,maxitem; + maxitem = CheckCharMaxItem(charaindex); + if(CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + for( i = 0 ; i < maxitem ; i ++ ){ + int itemindex = CHAR_getItemIndex( charaindex, i ); + + if( itemindex >= 0 ) { + if (CHAR_getInt(charaindex, CHAR_TRANSMIGRATION) > 0||CHAR_getInt(charaindex, CHAR_LV) >= 120) { + if (ITEM_getInt(itemindex, ITEM_ID) == getRookieItem(0) + ||ITEM_getInt(itemindex, ITEM_ID) == getRookieItem(1) + ||ITEM_getInt(itemindex, ITEM_ID) == getRookieItem(2) + ||ITEM_getInt(itemindex, ITEM_ID) == getRookieItem(3) + ||ITEM_getInt(itemindex, ITEM_ID) == getRookieItem(4)) { + char itemname[128]; + sprintf(itemname, "ĵ:%sֽ׶ΣϵͳԶջء", + ITEM_getChar(itemindex, ITEM_NAME)); + CHAR_talkToCli(charaindex, -1, itemname, + CHAR_COLORYELLOW); + CHAR_setItemIndex(charaindex, i, -1); + CHAR_sendItemDataOne(charaindex, i); + ITEM_endExistItemsOne(itemindex); + continue; + } + } +#ifdef _ITEM_USE_TIME + if(ITEM_getInt( itemindex, ITEM_USETIME) > 0){ + if(ITEM_getInt( itemindex, ITEM_USETIME)<(int)time(NULL)){ + char itemname[128]; + sprintf(itemname, "ĵ:%sʹѵϵͳԶջء", + ITEM_getChar(itemindex, ITEM_NAME)); + CHAR_talkToCli(charaindex, -1, itemname, + CHAR_COLORYELLOW); + CHAR_setItemIndex(charaindex, i, -1); + CHAR_sendItemDataOne(charaindex, i); + ITEM_endExistItemsOne(itemindex); + } + } +#endif + + } + } + } +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_party.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_party.c new file mode 100644 index 0000000..85e065b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_party.c @@ -0,0 +1,732 @@ +#include "version.h" +#include + +#include "readmap.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "battle.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "npc_bus.h" +#include "npc_airplane.h" // Arminius 7.10 Airplane +#include "family.h" // shan +#include "configfile.h" +#ifdef _ITEM_QUITPARTY +#include "init.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +// shan add +extern struct FM_PKFLOOR fmpkflnum[FAMILY_FMPKFLOOR]; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +/*------------------------------------------------------------ + * ɡ ū ĩ + ------------------------------------------------------------*/ + +/*------------------------------------------------------------ + * лɡ ū ë + * ئľ-1ë߯ʣ + ------------------------------------------------------------*/ +int CHAR_getEmptyPartyArray( int charaindex) +{ + int i = -1; + int rc = FALSE; + int toindex; + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) { + toindex = charaindex; + } + else { + toindex = CHAR_getPartyIndex( charaindex, 0); + } + if( CHAR_CHECKINDEX( toindex)){ + for( i = 1; i < getPartyNum( toindex ); i ++ ) { + if( CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1) == -1 ) { + rc = TRUE; + break; + } + } + } + return( rc ? i: -1); +} +/*------------------------------------------------------------ + * ˱ɡ ū + * + * charaindex int + * targetindex int 켰 + ------------------------------------------------------------*/ +BOOL CHAR_JoinParty_Main( int charaindex, int targetindex) +{ + int firstflg = FALSE; + int i; + char c[3]; + char buf[64]; + int toindex; + int parray; + + /* ʻ¦ȽԻ */ + if( CHAR_getWorkInt( targetindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) { + toindex = targetindex; + } + else { + toindex = CHAR_getPartyIndex( targetindex, 0); + } + if( !CHAR_CHECKINDEX( toindex) ) { + // print( " %s:%d err\n", __FILE__, __LINE__); + return FALSE; + } +#ifdef _ALLBLUES_LUA_1_5 + if(FreePartyJoin(charaindex, toindex) == FALSE){ + return FALSE; + } +#endif + + /* ɡ ūѷ */ + parray = CHAR_getEmptyPartyArray( toindex) ; + if( parray == -1 ) { + //print( "%s : %d err\n", __FILE__,__LINE__); + return FALSE; + } + /* ʼݷʱئCAë˪ */ + if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) { + CHAR_sendLeader( CHAR_getWorkInt( toindex, CHAR_WORKOBJINDEX), 1); + /* 켰ؼ̤徧 */ + /* ʱئ */ + CHAR_setWorkInt( toindex, CHAR_WORKPARTYMODE, 1); + CHAR_setWorkInt( toindex, CHAR_WORKPARTYINDEX1, toindex); + firstflg = TRUE; + } + CHAR_setWorkInt( toindex, parray + CHAR_WORKPARTYINDEX1, charaindex); + + CHAR_setWorkChar( charaindex, CHAR_WORKWALKARRAY, ""); + + CHAR_setWorkInt( charaindex, CHAR_WORKPARTYMODE, CHAR_PARTY_CLIENT); + + CHAR_setWorkInt( charaindex, CHAR_WORKPARTYINDEX1, toindex); + + if( firstflg ) { + CHAR_sendStatusString( toindex, "N0"); + } + + for( i = 0; i < getPartyNum( toindex ); i ++ ) { + int index = CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index)) { + snprintf( c, sizeof(c), "N%d", i); + CHAR_sendStatusString( charaindex, c); + } + } + + snprintf( buf,sizeof( buf), "%s Ŷӣ", + CHAR_getChar( charaindex, CHAR_NAME)); + + for( i = 0; i < getPartyNum( toindex ); i ++ ) { + int index = CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index)) { + if( index != charaindex ) { + snprintf( c, sizeof(c), "N%d", parray); + CHAR_sendStatusString( index, c); + CHAR_talkToCli( index, -1, buf, CHAR_COLORYELLOW); + } else { + CHAR_talkToCli( index, -1, "Ŷӣ", CHAR_COLORYELLOW); + } + CHAR_complianceParameter( index ); + } + } + return TRUE; +} + +BOOL CHAR_JoinParty_Main_New( int charaindex, int targetindex,int flg) +{ + int firstflg = FALSE; + int i; + char c[3]; + char buf[64]; + int toindex; + int parray; + + /* ʻ¦ȽԻ */ + if( CHAR_getWorkInt( targetindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) { + toindex = targetindex; + } + else { + toindex = CHAR_getPartyIndex( targetindex, 0); + } + if( !CHAR_CHECKINDEX( toindex) ) { + // print( " %s:%d err\n", __FILE__, __LINE__); + return FALSE; + } +#ifdef _ALLBLUES_LUA_1_5 + if(FreePartyJoin(charaindex, toindex) == FALSE){ + return FALSE; + } +#endif + + /* ɡ ūѷ */ + parray = CHAR_getEmptyPartyArray( toindex) ; + if( parray == -1 ) { + //print( "%s : %d err\n", __FILE__,__LINE__); + return FALSE; + } + /* ʼݷʱئCAë˪ */ + if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_NONE ) { + CHAR_sendLeader( CHAR_getWorkInt( toindex, CHAR_WORKOBJINDEX), 1); + /* 켰ؼ̤徧 */ + /* ʱئ */ + CHAR_setWorkInt( toindex, CHAR_WORKPARTYMODE, 1); + CHAR_setWorkInt( toindex, CHAR_WORKPARTYINDEX1, toindex); + firstflg = TRUE; + } + CHAR_setWorkInt( toindex, parray + CHAR_WORKPARTYINDEX1, charaindex); + + CHAR_setWorkChar( charaindex, CHAR_WORKWALKARRAY, ""); + + CHAR_setWorkInt( charaindex, CHAR_WORKPARTYMODE, CHAR_PARTY_CLIENT); + + CHAR_setWorkInt( charaindex, CHAR_WORKPARTYINDEX1, toindex); + + if( firstflg ) { + CHAR_sendStatusString( toindex, "N0"); + } + + for( i = 0; i < getPartyNum( toindex ); i ++ ) { + int index = CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index)) { + snprintf( c, sizeof(c), "N%d", i); + CHAR_sendStatusString( charaindex, c); + } + } + if(flg) snprintf( buf,sizeof( buf), "%s Ŷӣ",CHAR_getChar( charaindex, CHAR_NAME)); + + for( i = 0; i < getPartyNum( toindex ); i ++ ) { + int index = CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index)) { + if( index != charaindex ) { + snprintf( c, sizeof(c), "N%d", parray); + CHAR_sendStatusString( index, c); + if(flg) CHAR_talkToCli( index, -1, buf, CHAR_COLORYELLOW); + }else if(flg) CHAR_talkToCli( index, -1, "Ŷӣ", CHAR_COLORYELLOW); + CHAR_complianceParameter( index ); + } + } + return TRUE; +} + +/*------------------------------------------------------------ + * ɡ ū Ƿ£ + ------------------------------------------------------------*/ +BOOL CHAR_JoinParty( int charaindex ) +{ + + int result = -1; + int x,y; + OBJECT object; + int found = FALSE; + int fd; + int cnt; + int i; + + fd = getfdFromCharaIndex( charaindex ); + if( fd == -1 ) { + print( "%s : %d err\n", __FILE__, __LINE__); + return FALSE; + } + + /* лɡ ū׬ƥ */ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) { + lssproto_PR_send( fd, 1, FALSE); + return FALSE; + } + + /* 󡼰 ë */ + CHAR_getCoordinationDir( CHAR_getInt( charaindex, CHAR_DIR ) , + CHAR_getInt( charaindex , CHAR_X ), + CHAR_getInt( charaindex , CHAR_Y ) , + 1 , &x , &y ); + + /* */ + for( i = 0; i < CONNECT_WINDOWBUFSIZE; i ++ ) { + CONNECT_setJoinpartycharaindex(fd,i,-1); + } + cnt = 0; + + /*м 󡼰ƽҷë */ + + for( object = MAP_getTopObj( CHAR_getInt( charaindex, CHAR_FLOOR),x,y) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int toindex; + int parray; + int objindex = GET_OBJINDEX(object); + int targetindex = -1; + + /* ƽҷԪئ */ + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) continue; + toindex = OBJECT_getIndex( objindex); + + // shan begin + if( CHAR_getInt(charaindex, CHAR_FMINDEX) > 0 && CHAR_getInt(toindex, CHAR_FMINDEX) >0){ + for( i = 0; i < FAMILY_FMPKFLOOR; i++){ + if( fmpkflnum[i].fl == CHAR_getInt( charaindex, CHAR_FLOOR) ) + if( CHAR_getInt(charaindex, CHAR_FMINDEX) != CHAR_getInt(toindex, CHAR_FMINDEX) ){ + lssproto_PR_send( fd, 1, FALSE); + return FALSE; + } + } + } + // shan end + + /* */ + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER +#ifdef _PLAYER_NPC + || CHAR_getInt(toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYERNPC +#endif + ){ + found = TRUE; + /* 컥ҷë¦ȽԻ */ + if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT ) { + targetindex = CHAR_getWorkInt( toindex, CHAR_WORKPARTYINDEX1); + if( !CHAR_CHECKINDEX( targetindex) ) { + print( " %s:%d err\n", __FILE__, __LINE__); + continue; + } + if( CHAR_getInt( targetindex, CHAR_WHICHTYPE) == CHAR_TYPEBUS) { + continue; + } + } + else { + targetindex = toindex; + } + + /* ڶ ¾ */ + if( NPC_Util_CharDistance( charaindex, targetindex ) > 1) { + continue; + } + + /* ƥئǣ*/ + if( CHAR_getWorkInt( targetindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ){ + continue; + } + /* ޸ƹ */ + if( !CHAR_getFlg( targetindex, CHAR_ISPARTY) ) continue; + +#ifdef _NO_JOIN_FLOOR + { + int i; + int floor = CHAR_getInt( charaindex, CHAR_FLOOR); + for(i=0;i<32;i++){ + if(floor == getNoJoinFloor(i)){ + break; + } + } + if(i<32){ + continue; + } + } +#endif + +#ifdef _ANGEL_SUMMON + if( CHAR_getWorkInt( targetindex, CHAR_WORKANGELMODE) == TRUE) { + CHAR_talkToCli( charaindex, -1, "ʹ߲Եӡ", CHAR_COLORYELLOW); + continue; + } +#endif + } + /* Ѩƹﵩݷ޷Ի£ */ + else if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEBUS ) { + targetindex = toindex; + cnt = 0; + if( !NPC_BusCheckJoinParty( toindex, charaindex, TRUE)) { + /* ë ׽ئף ¼δ£޼ ئУ + * ֧֧мƥ + */ + break; + } + { // Arminius 7.10 Airplane + int busimg=CHAR_getInt(toindex, CHAR_BASEIMAGENUMBER); + if ((busimg!=100355) && (busimg!=100461)) { +#ifdef _SHIP_MATEMO + if(busimg==100348){ + int metamo = (CHAR_getInt(charaindex,CHAR_BASEBASEIMAGENUMBER) - 100000) / 20; + if(metamo < 0) metamo = 0; + else if(metamo > 11 ) metamo = 11; + CHAR_setInt(charaindex,CHAR_BASEIMAGENUMBER, 102062 + metamo); + }else +#endif + CHAR_setInt(charaindex,CHAR_BASEIMAGENUMBER,busimg); + CHAR_setInt(charaindex,CHAR_RIDEPET,-1); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , + CHAR_WORKOBJINDEX )); + // Robin debug 01/11/21 + if( CHAR_getInt( charaindex, CHAR_RIDEPET) != -1 ) { + CHAR_setInt( charaindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_RIDEPET); + } + /* + CHAR_sendPMEToArroundCharacterFLXY(charaindex, + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + 0,1,CHAR_getInt( charaindex, CHAR_PETMAILEFFECT) + ); + */ + } + } + } + /* 跴Ѩƹﵩ½ */ + else { + continue; + } + /* ɡ ūѷ */ + parray = CHAR_getEmptyPartyArray( targetindex) ; + if( parray == -1 ) continue; + + /* ƥľ */ + CONNECT_setJoinpartycharaindex( fd,cnt,toindex); + cnt++; + if( cnt == CONNECT_WINDOWBUFSIZE ) break; + + /* Ѩƹﵩ έƷУݻë £ */ + if( CHAR_getInt( targetindex, CHAR_WHICHTYPE) == CHAR_TYPEBUS ) break; + + } + + if( cnt == 0 ) { + if( found == TRUE) { + CHAR_talkToCli( charaindex, -1, "޷Ŷӡ", CHAR_COLORYELLOW); + } + result = FALSE; + }else if( cnt == 1 ) { + { + CHAR_JoinParty_Main( charaindex, CONNECT_getJoinpartycharaindex(fd,0)); + result = TRUE; + } + }else { + int strlength; + char msgbuf[1024]; + char escapebuf[2048]; + strcpy( msgbuf, "1\n˭Ŷأ\n"); + strlength = strlen( msgbuf); + for( i = 0; + CONNECT_getJoinpartycharaindex( fd,i ) != -1 + && i< CONNECT_WINDOWBUFSIZE; + i ++ ){ + char *a = CHAR_getChar( + CONNECT_getJoinpartycharaindex(fd,i) , CHAR_NAME); + char buf[256]; + snprintf( buf, sizeof( buf),"%s\n", a); + if( strlength + strlen( buf) > arraysizeof( msgbuf)){ + print( "%s:%dӴѶϢbuffer㡣\n", + __FILE__,__LINE__); + break; + } + strcpy( &msgbuf[strlength], buf); + strlength += strlen(buf); + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SELECTPARTY, + -1, + makeEscapeString( msgbuf, escapebuf, sizeof(escapebuf))); + + + } + + if( result != -1 ) { + lssproto_PR_send( fd, 1, result); + } + + return result; +} + +static BOOL CHAR_DischargePartySub( int charaindex, int msgflg) +{ + char buf[64], c[3]; + int toindex,flg,i; +#ifdef _ITEM_QUITPARTY + int j = 0,k; +#endif + + if( !CHAR_CHECKINDEX( charaindex) ) return FALSE; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_LEADER ) { + int pindex, airplaneflag=0; + // Arminius 7.10 Airplane + if( CHAR_getInt(charaindex, CHAR_WHICHTYPE) == CHAR_TYPEBUS ) { + if ((CHAR_getInt(charaindex, CHAR_BASEIMAGENUMBER) !=100355) && + (CHAR_getInt(charaindex, CHAR_BASEIMAGENUMBER) !=100461)){ + airplaneflag=1; + } + } + for( i = 0; i < getPartyNum( charaindex ); i ++ ) { + + pindex = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( pindex) ) { + CHAR_setWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1, -1); +#ifdef _PLAYER_NPC + if(CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYERNPC || CHAR_getInt( pindex, CHAR_WHICHTYPE ) == CHAR_TYPELUANPC){ + CHAR_CharaDeleteHavePet( pindex); + CHAR_CharaDelete(pindex); + continue; + } +#endif + CHAR_setWorkInt( pindex, CHAR_WORKPARTYINDEX1, -1); + CHAR_setWorkInt( pindex, CHAR_WORKPARTYMODE, CHAR_PARTY_NONE); + if( msgflg ){ + CHAR_talkToCli( pindex, -1, "Ŷѽɢ", CHAR_COLORYELLOW); +#ifdef _ITEM_QUITPARTY + // won fix + for( j=0;j=0){ + int fl,x,y; + CHAR_getElderPosition( CHAR_getInt( charaindex, CHAR_LASTTALKELDER), + &fl, &x, &y ); + CHAR_warpToSpecificPoint(charaindex, fl, x, y); + } + } + } + } + CHAR_setWorkInt( charaindex, CHAR_WORKPARTYINDEX1, -1); + for( i = 0; i < getPartyNum( toindex ); i ++ ) { + int index = CHAR_getWorkInt( toindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index) ){ + if( index == charaindex) { + myarray = i; + break; + } + } + } + if( myarray == getPartyNum( toindex )) { + print( "DischargeParty(): ֣"); + return FALSE; + } + CHAR_setWorkInt( toindex, CHAR_WORKPARTYINDEX1 + myarray, -1); + snprintf( buf,sizeof( buf), "%s Ŷӣ", + CHAR_getChar( charaindex, CHAR_NAME)); + if( msgflg ){ + CHAR_talkToCli( charaindex, -1, "Ŷӣ", CHAR_COLORYELLOW); +#ifdef _ITEM_QUITPARTY + // won fix + for( i=0;i 1) { + int parent_dir; + start.x = CHAR_getInt( index, CHAR_X); + start.y = CHAR_getInt( index, CHAR_Y); + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + end = start; + if( parent_dir != -1 ) { + CHAR_walk( index, parent_dir, 0); + } + } + previndex = index; + } + } + } + + } + + return TRUE; +} +BOOL CHAR_DischargeParty( int charaindex, int flg) +{ + return CHAR_DischargePartySub( charaindex, 1); +} + +BOOL CHAR_DischargeParty_New( int charaindex, int flg) +{ + return CHAR_DischargePartySub( charaindex, flg); +} + +BOOL CHAR_DischargePartyNoMsg( int charaindex) +{ + return CHAR_DischargePartySub( charaindex, 0); +} + + +/*------------------------------------------------------------ + * лĸë˪£ + ------------------------------------------------------------*/ +void CHAR_sendLeader( int objindex, int leader) +{ + int opt[1]; + opt[0] = leader; + CHAR_sendWatchEvent( objindex,CHAR_ACTLEADER,opt,1,TRUE); +} +/*------------------------------------------------------------ + * ë CHAR_WORKPARTYINDEX)϶ƥƽҷindexë¦Ƚ£ + * лƥֺƥ + ------------------------------------------------------------*/ +int CHAR_getPartyIndex( int index, int num) +{ + int nindex = -1; + + /* ޼̼͵ë */ + /* ʼ */ + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_LEADER ) { + nindex = CHAR_getWorkInt( index, CHAR_WORKPARTYINDEX1 + num ); + } + /* Ҽ */ + else { + int oyaindex = CHAR_getWorkInt( index, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex)) { + nindex = CHAR_getWorkInt( oyaindex, CHAR_WORKPARTYINDEX1+num); + } + } + return nindex; +} +/*------------------------------------------------------------ + * ë˪£ + * ޻ľɹޱֶë˪£ + ------------------------------------------------------------*/ +void CHAR_talkToCliAndParty( int talkedcharaindex,int talkcharaindex, + char* message, CHAR_COLOR color ) +{ + int i; + /* ڷ */ + CHAR_talkToCli( talkedcharaindex, talkcharaindex, message, color); + + for( i = 0; i < getPartyNum( talkedcharaindex ); i ++ ) { + int index = CHAR_getPartyIndex( talkedcharaindex, i); + if( CHAR_CHECKINDEX( index) && + index != talkedcharaindex) + { + CHAR_talkToCli( index, talkcharaindex, message, color); + } + } +} + +int getPartyNum(int charaindex) +{ + return CHAR_PARTYMAX; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_talk.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_talk.c new file mode 100644 index 0000000..5c12d0f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_talk.c @@ -0,0 +1,1960 @@ +#include "version.h" +#include +#include +#include +#include "handletime.h" +#include "autil.h" +#include "readmap.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "item_event.h" +#include "chatmagic.h" +#include "battle.h" +#include "log.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "family.h" +#include "buf.h" +#ifdef _CHAR_PROFESSION +#include "profession_skill.h" +#endif +#include "net.h" +#include "char_talk.h" +#ifdef _TALK_MOVE_FLOOR +#include "longzoro/move.h" +#endif +#ifdef _PLAYER_QUESTION_ONLIEN +#include "longzoro/playerquestion.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif + +extern int channelMember[FAMILY_MAXNUM][FAMILY_MAXCHANNEL][FAMILY_MAXMEMBER]; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _CHANNEL_MODIFY +int *piOccChannelMember = NULL; +#endif + +#ifdef _TALK_ACTION +void TalkAction(int charaindex, char *message); +#endif + +#ifdef _GM_ITEM +static BOOL player_useChatMagic( int charaindex, char* data, BOOL isDebug); +#endif + +/*------------------------------------------------------------ + * ĩ + ------------------------------------------------------------*/ +#define DEBUGCDKEYNUM 100 +struct tagDebugCDKey { + int use; + char cdkey[9]; +}; +static struct tagDebugCDKey DebugCDKey[DEBUGCDKEYNUM]; + +/*==================== ܷ====================*/ + +typedef struct tagCHAR_ChatMagicTable +{ + char magicname[128]; + CHATMAGICFUNC func; + BOOL isdebug; + int hash; + int level; + char* usestring; +}CHAR_ChatMagicTable; + +static CHAR_ChatMagicTable CHAR_cmtbl[]={ + //ʦר + { "programming_engineer", CHAR_CHAT_DEBUG_engineer, TRUE, 0, 3, "" }, + { "petlevelup", CHAR_CHAT_DEBUG_petlevelup, TRUE, 0, 2, " ȼ (˺)" }, + { "petexpup", CHAR_CHAT_DEBUG_petexpup, TRUE, 0, 2, " (˺)" }, + { "help", CHAR_CHAT_DEBUG_help, TRUE, 0, 2, "ָ/all" }, +#ifdef _EQUIT_NEGLECTGUARD + { "setneguard", CHAR_CHAT_DEBUG_setneguard, TRUE, 0, 3, "waei" }, +#endif + // + { "info", CHAR_CHAT_DEBUG_info, TRUE, 0, 2, "ֵ" }, + { "level", CHAR_CHAT_DEBUG_level, TRUE, 0, 2, "ֵ (˺)" }, + { "settrans", CHAR_CHAT_DEBUG_setTrans, TRUE, 0, 2, "ֵ (˺)" }, + { "exp", CHAR_CHAT_DEBUG_exp, TRUE, 0, 2, "ֵ (˺)" }, + { "hp", CHAR_CHAT_DEBUG_hp, TRUE, 0, 2, "ֵ (˺)" }, + { "mp", CHAR_CHAT_DEBUG_mp, TRUE, 0, 2, "ֵ (˺)" }, + { "setmp", CHAR_CHAT_DEBUG_setmp, TRUE, 0, 2, "ֵ (˺)" }, + { "str", CHAR_CHAT_DEBUG_str, TRUE, 0, 2, "ֵ*100 (˺)" }, + { "dex", CHAR_CHAT_DEBUG_dex, TRUE, 0, 2, "ֵ*100 (˺)" }, + { "tgh", CHAR_CHAT_DEBUG_tgh, TRUE, 0, 2, "ֵ*100 (˺)" }, + { "vital", CHAR_CHAT_DEBUG_vital, TRUE, 0, 2, "ֵ*100 (˺)" }, + { "luck", CHAR_CHAT_DEBUG_luck, TRUE, 0, 2, "ֵ (˺)" }, + { "superman", CHAR_CHAT_DEBUG_superman, TRUE, 0, 2, "(˺)" }, + { "dp", CHAR_CHAT_DEBUG_dp, TRUE, 0, 2, "ֵ (˺)" }, +#ifdef _EQUIT_ARRANGE + { "arrange", CHAR_CHAT_DEBUG_arrange, TRUE, 0, 3, "ֵ" }, +#endif + +#ifdef _EQUIT_SEQUENCE + { "sequence", CHAR_CHAT_DEBUG_sequence, TRUE, 0, 3, "ֵ" }, +#endif + + //ϵͳ + { "announce", CHAR_CHAT_DEBUG_announce, TRUE, 0, 2, "" }, + { "loginannounce", CHAR_CHAT_DEBUG_loginannounce, TRUE, 0, 2, "" }, + { "sysinfo", CHAR_CHAT_DEBUG_sysinfo, TRUE, 0, 2, "" }, + { "effect", CHAR_CHAT_DEBUG_effect, TRUE, 0, 2, "alloff/ͼ Ч" }, + { "reset", CHAR_CHAT_DEBUG_reset, TRUE, 0, 3, "enemy/encount/magic/warppoint/petskill/pettalk/npc/all" }, + { "clean_floor", CHAR_CHAT_DEBUG_cleanfloor, TRUE, 0, 3, "ͼ" }, + { "printcount", CHAR_CHAT_printcount, TRUE, 0, 2, "" }, + { "enemyrestart", CHAR_CHAT_DEBUG_enemyrestart, TRUE, 0, 3, "" }, + { "cleanfreepet", CHAR_CHAT_DEBUG_cleanfreepet, TRUE, 0, 3, "" }, + +#ifdef _GMRELOAD + { "gmreload", CHAR_CHAT_DEBUG_gmreload, TRUE, 0, 3, "all/cdkey level" }, +#endif + + { "waeikickall", CHAR_CHAT_DEBUG_waeikickall, TRUE, 0, 3, "" }, + { "checktrade", CHAR_CHAT_DEBUG_checktrade, TRUE, 0, 3, "waei" }, + // GM + { "debug", CHAR_CHAT_DEBUG_debug, TRUE, 0, 1, "on/off" }, + { "metamo", CHAR_CHAT_DEBUG_metamo, TRUE, 0, 1, "ͼ (˺)" }, + { "checklock", CHAR_CHAT_DEBUG_checklock, TRUE, 0, 2, "ʺ" }, + { "shutup", CHAR_CHAT_DEBUG_shutup, TRUE, 0, 2, "ʺ ON/OFF" }, +#ifdef _WAEI_KICK + { "gmkick", CHAR_CHAT_DEBUG_gmkick, TRUE, 0, 1, "ʺ LSLOCK/KICK/DEUNLOCK/UNLOCKALL/LOCK/TYPE/UNLOCK" }, +#endif + { "battlein", CHAR_CHAT_DEBUG_battlein, TRUE, 0, 2, "" }, + { "battleout", CHAR_CHAT_DEBUG_battleout, TRUE, 0, 2, "" }, + { "battlewatch", CHAR_CHAT_DEBUG_battlewatch, TRUE, 0, 2, "" }, + { "getuser", CHAR_CHAT_DEBUG_getuser, TRUE, 0, 2, " ͼ (npc)" }, + { "warp", CHAR_CHAT_DEBUG_warp, TRUE, 0, 2, "ͼ x y" }, + { "waeikick", CHAR_CHAT_DEBUG_waeikick, TRUE, 0, 2, "ʺ" }, + { "jail", CHAR_CHAT_DEBUG_jail, TRUE, 0, 2, "ʺ" }, + { "send", CHAR_CHAT_DEBUG_send, TRUE, 0, 1, "floor x y ʺ" }, +#ifdef _SendTo + { "sendto", CHAR_CHAT_DEBUG_Sendto, TRUE, 0, 1, "ʺ" }, +#endif + { "noenemy", CHAR_CHAT_DEBUG_noenemy, TRUE, 0, 2, "on/off" }, + { "watchevent", CHAR_CHAT_DEBUG_watchevent, TRUE, 0, 2, "" }, +#ifdef _SEND_EFFECT // WON ADD ACѩЧ + { "sendeffect", CHAR_CHAT_DEBUG_sendeffect, TRUE, 0, 2, "" }, +#endif + { "silent", CHAR_CHAT_DEBUG_silent, TRUE, 0, 2, "ʺ " },// + { "unlock", CHAR_CHAT_DEBUG_unlock, TRUE, 0, 2, "ʺ" }, + { "eventclean", CHAR_CHAT_DEBUG_eventclean, TRUE, 0, 2, "all/ ʺ " }, + { "eventsetend", CHAR_CHAT_DEBUG_eventsetend, TRUE, 0, 2, "all/ ʺ " }, + { "eventsetnow", CHAR_CHAT_DEBUG_eventsetnow, TRUE, 0, 2, "all/ ʺ " }, + + { "playerspread", CHAR_CHAT_DEBUG_playerspread, TRUE, 0, 3, "waei" }, + { "shutupall", CHAR_CHAT_DEBUG_shutupall, TRUE, 0, 3, "" }, + { "unlockserver", CHAR_CHAT_DEBUG_unlockserver, TRUE, 0, 3, "" }, + { "shutdown", CHAR_CHAT_DEBUG_shutdown, TRUE, 0, 3, "()" }, + + //Ƴ + { "delitem", CHAR_CHAT_DEBUG_delitem, TRUE, 0, 2, "all/λ" }, + { "delpet", CHAR_CHAT_DEBUG_deletepet, TRUE, 0, 2, "all/λ" }, +#if _ATTESTAION_ID != 3 + { "additem", CHAR_CHAT_DEBUG_additem, TRUE, 0, 3, "ID (() (˺))" }, + { "petmake", CHAR_CHAT_DEBUG_petmake, TRUE, 0, 3, "ID ((ȼ) (˺))" }, +#endif + { "gold", CHAR_CHAT_DEBUG_gold, TRUE, 0, 2, " (˺)" }, + + //幤 + { "manorpk", CHAR_CHAT_DEBUG_manorpk, TRUE, 0, 2, "allpeace/peace ׯ԰" }, + { "fixfmleader", CHAR_CHAT_DEBUG_fixfmleader, TRUE, 0, 2, "ʺ 1" }, + { "fixfmpk", CHAR_CHAT_DEBUG_fixfmpk, TRUE, 0, 2, "" }, + { "fixfmdata", CHAR_CHAT_DEBUG_fixfmdata, TRUE, 0, 2, "" }, + + // + + +#ifdef _CHAR_POOLITEM + { "saveditem", CHAR_CHAT_DEBUG_saveditem, TRUE, 0, 3, "" }, + { "insertditem", CHAR_CHAT_DEBUG_insertditem, TRUE, 0, 3, "" }, + { "showdepot", CHAR_CHAT_DEBUG_ShowMyDepotItems, TRUE, 0, 3, "" }, + { "insidedepot", CHAR_CHAT_DEBUG_InSideMyDepotItems, TRUE, 0, 3, "" }, +#endif + +#ifdef _CHAR_POOLPET + { "savedpet", CHAR_CHAT_DEBUG_savedpet, TRUE, 0, 3, "" }, + { "insertdpet", CHAR_CHAT_DEBUG_insertdpet, TRUE, 0, 3, "" }, + { "showdepotpet", CHAR_CHAT_DEBUG_ShowMyDepotPets, TRUE, 0, 3, "" }, + { "insidedepotpet", CHAR_CHAT_DEBUG_InSideMyDepotPets, TRUE, 0, 3, "" }, +#endif + +#if _ATTESTAION_ID != 3 +#ifdef _TEST_DROPITEMS + { "dropmypet", CHAR_CHAT_DEBUG_dropmypet, TRUE, 0, 3, "" }, + { "dropmyitem", CHAR_CHAT_DEBUG_dropmyitem, TRUE, 0, 2, "߱/(0/1)" }, +#endif +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + { "addsk", CHAR_CHAT_DEBUG_addsk, TRUE, 0, 2, "" }, + { "delsk", CHAR_CHAT_DEBUG_delsk, TRUE, 0, 2, "" }, +#endif + { "checktime", CHAR_CHAT_DEBUG_checktime, TRUE, 0, 3, "" }, + +#ifdef _GAMBLE_BANK + { "setgamblenum", CHAR_CHAT_DEBUG_setgamblenum, TRUE, 0, 3, "ֵ" }, +#endif + // WON ADD ָ + { "crash", CHAR_CHAT_DEBUG_crash, TRUE, 0, 3, "" }, +#ifdef _PETSKILL_SETDUCK + { "setDuck", CHAR_CHAT_DEBUG_SetDuck, TRUE, 0, 3, "" }, +#endif + +#ifdef _TYPE_TOXICATION + { "setTox", CHAR_CHAT_DEBUG_Toxication, TRUE, 0, 3, "" }, +#endif + { "showMem", CHAR_CHAT_DEBUG_showMem, TRUE, 0, 2, "" }, +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + { "profession", CHAR_CHAT_DEBUG_show_profession,TRUE, 0, 2, "" }, + { "set_regist", CHAR_CHAT_DEBUG_set_regist, TRUE, 0, 1, "" }, +#endif + { "samecode", CHAR_CHAT_DEBUG_samecode, TRUE, 0, 3, "pet/item/set " }, + +#ifdef _NEW_MANOR_LAW + // 趨 + { "set_momentum",CHAR_CHAT_DEBUG_set_momentum,TRUE,0,2," ֵ" }, +#endif + // 趨ӵׯ԰ + { "set_manor_owner",CHAR_CHAT_DEBUG_set_manor_owner,TRUE,0,2,"ׯ԰ID 0/1 ID" }, + // 趨ׯ԰սʱ,趨ʱΪĿǰÿսʱڵľʱ(λ:),ex:ս,ҪŻ + // ս,ָ趨Ϊ 5 ,ĵȴڱֻ + { "set_schedule_time",CHAR_CHAT_DEBUG_set_schedule_time,TRUE,0,2,"ׯ԰ID " }, + + +#ifdef _ANGEL_SUMMON + { "angelinfo", CHAR_CHAT_DEBUG_angelinfo, TRUE, 0, 2, "" }, + { "angelclean", CHAR_CHAT_DEBUG_angelclean, TRUE, 0, 2, "" }, + { "angelcreate", CHAR_CHAT_DEBUG_angelcreate, TRUE, 0, 2, "" }, + { "missionreload", CHAR_CHAT_DEBUG_missionreload, TRUE, 0, 2, "" }, +#endif + + { "itemreload", CHAR_CHAT_DEBUG_itemreload, TRUE, 0, 2, "" }, + + { "skywalker", CHAR_CHAT_DEBUG_skywalker, TRUE, 0, 2, "" }, +#ifdef _ITEM_ADDEXP + { "itemaddexp", CHAR_CHAT_DEBUG_itemaddexp, TRUE, 0, 2, "" }, +#endif + +#ifdef _DEF_GETYOU + { "getyou", CHAR_CHAT_DEBUG_getyou, TRUE, 0, 2, " 1~3" }, +#endif +#ifdef _DEF_NEWSEND + { "newsend", CHAR_CHAT_DEBUG_newsend, TRUE, 0, 2, "floor x y ʺ /Ҫ˵Ļ" }, +#endif +#ifdef _DEF_SUPERSEND + { "supersend", CHAR_CHAT_DEBUG_supersend, TRUE, 0, 3, "floor x y /Ҫ˵Ļ" }, +#endif +#ifdef _FONT_SIZE + { "fsize", CHAR_CHAT_DEBUG_fsize, TRUE, 0, 1, "ֺ" }, +#endif +#ifdef _JOBDAILY + { "rejobdaily", CHAR_CHAT_DEBUG_rejobdaily, TRUE, 0, 3, "" }, +#endif +#ifdef _CREATE_MM_1_2 + { "MM", CHAR_CHAT_DEBUG_MM, TRUE, 0, 3, "MM 1/2 (˺)" }, +#endif +#ifdef _GM_ITEM + { "gmfunction", CHAR_CHAT_DEBUG_GMFUNCTION, TRUE, 0, 3, " (˺)" }, +#endif + +#ifdef _GM_RIDE + { "setride", CHAR_CHAT_DEBUG_SETRIDE, TRUE, 0, 3, " (˺)" }, + { "mvride", CHAR_CHAT_DEBUG_MVRIDE, TRUE, 0, 3, " (˺)" }, +#endif + +#ifdef _LOCK_IP + { "addlock", CHAR_CHAT_DEBUG_ADD_LOCK, TRUE, 0, 3, "flag ˺/IP IP" }, + { "dellock", CHAR_CHAT_DEBUG_DEL_LOCK, TRUE, 0, 3, "flag ˺/IP IP" }, + { "showip", CHAR_CHAT_DEBUG_SHOWIP, TRUE, 0, 3, "˺" }, +#endif + { "setfame", CHAR_CHAT_DEBUG_SET_FAME, TRUE, 0, 3, "˺ ֵ" }, + +#ifdef _AUTO_PK + { "pktime", CHAR_CHAT_DEBUG_SET_AUTOPK, TRUE, 0, 3, "" }, +#endif + +#ifdef _PLAYER_NUM + { "playernum", CHAR_CHAT_DEBUG_SET_PLAYERNUM, TRUE, 0, 3, "" }, +#endif + +#ifdef _RELOAD_CF + { "reloadcf", CHAR_CHAT_DEBUG_SET_RELOADCF, TRUE, 0, 3, "" }, +#endif + +#ifdef _TRANS + { "trans", CHAR_CHAT_DEBUG_Trans, TRUE, 0, 3, "(˺)" }, +#endif +#ifdef _FUSIONBEIT_FIX + { "fusionbeit", CHAR_CHAT_DEBUG_fusionbeit, TRUE, 0, 3, " (˺)" }, +#endif +#ifdef _MAKE_PET_CF + { "petmakecf", CHAR_CHAT_DEBUG_petmakecf, TRUE, 0, 3, " ת/ȼ/ɳ" }, +#endif +#ifdef _MAKE_PET_ABILITY + { "petmakeabi", CHAR_CHAT_DEBUG_petmakeabi, TRUE, 0, 3, " ת/ȼ/ɳ" }, +#endif +#ifdef _MAKE_MAP + { "delmap", CHAR_CHAT_DelMap, TRUE, 0, 3, "" }, + { "getmap", CHAR_CHAT_GetMap, TRUE, 0, 3, "" }, + { "map", CHAR_CHAT_Map, TRUE, 0, 3, "" }, + { "tile", CHAR_CHAT_Fixtile, TRUE, 0, 3, "" }, + { "obj", CHAR_CHAT_Fixobj, TRUE, 0, 3, "" }, +// { "fukuwa", CHAR_CHAT_Fukuwa, TRUE, 0, 3, "" }, +#endif +#ifdef _PLAYER_QUESTION_ONLIEN + { "PlayerQuestion", CHAR_CHAT_DEBUG_PlayerQuestion, TRUE, 0, 3, " Ʒ Ʒֵ" }, +#endif +#ifdef _GM_SAVE_ALL_CHAR + { "GmSaveAllChar", CHAR_CHAT_DEBUG_GmSaveAllChar, TRUE, 0, 3, "" }, +#endif +#ifdef _ALLBLUES_LUA + { "reloadlua", CHAR_CHAT_DEBUG_ReLoadLua, TRUE, 0, 3, "" }, + { "newloadlua", CHAR_CHAT_DEBUG_NewLoadLua, TRUE, 0, 3, "" }, +#endif +#ifdef _KEEP_UP_NO_LOGIN + { "keepupnologin", CHAR_CHAT_DEBUG_KeepUpNoLogin, TRUE, 0, 3, "" }, +#endif +#ifdef _NEW_LOAD_NPC + { "newloadnpc", CHAR_CHAT_DEBUG_NewLoadNpc, TRUE, 0, 3, "" }, +#endif +#ifdef _NEW_LOAD_MAP + { "newloadmap", CHAR_CHAT_DEBUG_NewLoadMap, TRUE, 0, 3, "" }, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + { "luainit", CHAR_CHAT_DEBUG_LUA_INIT, TRUE, 0, 3, "LUAλ"}, + { "luaclose", CHAR_CHAT_DEBUG_LUA_CLOSE, TRUE, 0, 3, ""}, +#endif +#ifdef _NO_FULLPLAYER_ATT + { "nofullplayer", CHAR_CHAT_NoFullPlayer, TRUE, 0, 3, ""}, +#endif +#ifdef _PET_MAKE_2_TRANS + { "petmaketrans", CHAR_CHAT_DEBUG_petmake2, TRUE, 0, 2, "ת ID ȼ "}, +#endif +///////////////////////////////////////////////////////////////////////// +}; + +void CHAR_initDebugChatCdkey( void) +{ + int i; + for( i = 0; i < DEBUGCDKEYNUM; i ++ ) { + DebugCDKey[i].use = FALSE; + DebugCDKey[i].cdkey[0] = '\0'; + } +} +/*------------------------------------------------------------ + * ܷ˦بë£ + * ¦ѣ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_initChatMagic(void) +{ + int i; + for( i=0 ; i 8 ) { + return -1; + } + for( i = 0; i < DEBUGCDKEYNUM; i ++ ) { + if( DebugCDKey[i].use == FALSE) { + if( mode == 0 ) { + DebugCDKey[i].use = TRUE; + strcpysafe( DebugCDKey[i].cdkey, sizeof( DebugCDKey[i].cdkey), cdkey); + found = TRUE; + break; + } + } + else { + if( mode == 1 ) { + if( strcmp( DebugCDKey[i].cdkey, cdkey) == 0 ) { + DebugCDKey[i].use = FALSE; + DebugCDKey[i].cdkey[0] = '\0'; + found = TRUE; + } + } + } + + } + if( !found ) return -1; + return i; +} + +CHATMAGICFUNC CHAR_getChatMagicFuncPointer(char* name, BOOL isDebug) +{ + int i; + int hash = hashpjw( name ); + + for( i=0 ; i= arraysizeof( CHAR_cmtbl) ) return -1; + if( CHAR_cmtbl[ ti].isdebug == isDebug && + CHAR_cmtbl[ ti].level <= level ){ + sprintf( name,"%s", CHAR_cmtbl[ ti].magicname ); + sprintf( usestring, "%s", CHAR_cmtbl[ ti].usestring ); + return 1; + } + return 0; +} + +int CHAR_getChatMagicFuncMaxNum( void) +{ + return arraysizeof( CHAR_cmtbl); +} + +#ifdef _ALLBLUES_LUA_1_2 +MAGIC_LuaFunc MAGIC_luaFunc; + +BOOL MAGIC_addLUAListFunction(lua_State *L, const char *luafuncname, const char *luafunctable, int gmlevel, char *usestring ) +{ + MAGIC_LuaFunc *luaFunc = &MAGIC_luaFunc; + + while(luaFunc->next != NULL){ + luaFunc = luaFunc->next; + } + + memset( luaFunc, 0 , sizeof(MAGIC_luaFunc) ); + luaFunc->lua = L; + luaFunc->luafuncname = allocateMemory( strlen(luafuncname) ); + strcpy(luaFunc->luafuncname, luafuncname); + luaFunc->luafunctable = allocateMemory( strlen(luafunctable) ); + strcpy(luaFunc->luafunctable, luafunctable); + luaFunc->usestring = allocateMemory( strlen(usestring) ); + strcpy(luaFunc->usestring, usestring); + + luaFunc->gmlevel = gmlevel; + + luaFunc->next = allocateMemory( sizeof(MAGIC_luaFunc) ); + memset( luaFunc->next, 0 , sizeof(MAGIC_luaFunc) ); + if(luaFunc->next == NULL)return FALSE; + luaFunc = luaFunc->next; + luaFunc->next=NULL; + + return TRUE; +} + +BOOL MAGIC_getLUAListFunction( char *luafuncname, int gmlevel, int charaindex, char *data ) +{ + MAGIC_LuaFunc *luaFunc = &MAGIC_luaFunc; + + while(luaFunc->next != NULL){ + if(strcmp(luaFunc->luafuncname, luafuncname) == 0){ + if( gmlevel >= luaFunc->gmlevel ){ + lua_getglobal( luaFunc->lua, luaFunc->luafunctable); + return RunUseChatMagic(charaindex, data, luaFunc->lua); + }else{ + return FALSE; + } + } + luaFunc = luaFunc->next; + } + return FALSE; +} +#endif +/*------------------------------------------------------------ + * ܷ + * ¦ + * charaindex int ƽҷ̼͵ + * message char* + * isDebug BOOL ܷ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +static BOOL CHAR_useChatMagic( int charaindex, char* data, BOOL isDebug) +{ + char magicname[256]; + int ret; + int i; + int gmLevel = 0, magicLevel; + + CHATMAGICFUNC func; + +#ifdef _GMRELOAD + extern struct GMINFO gminfo[GMMAXNUM]; +#else +#endif + char *p = CHAR_getChar( charaindex, CHAR_CDKEY); + if( !p ) { + fprint( "err nothing cdkey\n"); + return FALSE; + } + + if( getChatMagicCDKeyCheck() == 1 ){ //һȷGMʺ + if( CHAR_getWorkInt( charaindex, CHAR_WORKFLG) & WORKFLG_DEBUGMODE ) { + gmLevel = CHAR_getWorkInt( charaindex, CHAR_WORKGMLEVEL); + }else{ + +#ifdef _GMRELOAD + for (i = 0; i < GMMAXNUM; i++){ + if (strcmp( p, gminfo[i].cdkey) == 0){ + gmLevel = gminfo[i].level; + CHAR_setWorkInt( charaindex, CHAR_WORKGMLEVEL, gmLevel); + break; + } + } +#else +#endif + if( i >= GMMAXNUM ){ + for( i = 0; i < DEBUGCDKEYNUM; i ++ ) { + if( DebugCDKey[i].use && strcmp( p, DebugCDKey[i].cdkey) == 0 ) { + break; + } + } + if( i >= DEBUGCDKEYNUM ){ + return FALSE; + } + } + } + }else { + gmLevel = 3; + CHAR_setWorkInt( charaindex, CHAR_WORKGMLEVEL, gmLevel); + } + ret = getStringFromIndexWithDelim( data, " ", 1, magicname, sizeof( magicname)); + if( ret == FALSE)return FALSE; + // Robin 0618 chaeck GM Level + magicLevel = CHAR_getChatMagicFuncLevel( magicname, isDebug); + if( gmLevel < magicLevel ) + return FALSE; + + func = CHAR_getChatMagicFuncPointer(magicname,isDebug); + if( func ){ + LogGM( CHAR_getUseName( charaindex), CHAR_getChar( charaindex, CHAR_CDKEY), data, + CHAR_getInt( charaindex, CHAR_FLOOR), CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y) ); + func( charaindex, data + strlen( magicname)+1); + return TRUE; + }else{ +#ifdef _ALLBLUES_LUA_1_2 + if(isDebug == TRUE){ + if(MAGIC_getLUAListFunction(magicname, gmLevel, charaindex, data + strlen( magicname)+1)==TRUE){ + LogGM( CHAR_getUseName( charaindex), CHAR_getChar( charaindex, CHAR_CDKEY), data, + CHAR_getInt( charaindex, CHAR_FLOOR), CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y) ); + return TRUE; + } + } +#endif + return FALSE; + } +} + +/*------------------------------------------------------------ + * ھëƻ + * ¦ + * volume int + * ߯Ի + * ѨƥѨ + ------------------------------------------------------------*/ +static int CHAR_getRangeFromVolume( int volume ) +{ + static int chatvol[]={ + 3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 + }; + + if( volume < 0 )return 0; + else if( arraysizeof( chatvol ) <= volume ) { + return chatvol[arraysizeof(chatvol)-1]; + } + return chatvol[volume]; +} +/*------------------------------------------------------------ + * 뢼ʾبةë£ئ֧Իף + * ¦ + * mesg char* ɺ + * ߯Ի + * -1 巴𹫳 + * 0 巴׹ + * 1 Ի깴年л ! + ------------------------------------------------------------*/ +static int CHAR_getVolume( char* mesg ) +{ + int stringlen = strlen( mesg ); + if( stringlen == 0 ) + return 0; + else if( stringlen == 1 ){ + if ( mesg[ 0 ] == '!' ) + return 1; + else + return 0; + } + else if ( stringlen == 2 ) { + if ( mesg[ 1 ] == '!' ) { + if ( mesg[ 0 ] == '!' ) + return 2; + else + return 1; + } + else + return 0; + }else{ + /* 3 */ + if( mesg[stringlen-1] == '.' ){ + /* 𹫳𹫼 ؤԻ */ + if( mesg[stringlen-2] == '.' && mesg[stringlen-3] == '.' ){ + /* 𹫳 */ + return -1; + } + return 0; + }else{ + /* ! ë*/ + int exnum=0; + int i; + for( i=stringlen-1; i>=0 ; i-- ){ + if( mesg[i] != '!' ) + break; + else + exnum++; + } + return exnum; + } + } +} + +/*------------------------------------------------------------ + * ⼰ ն⼰ ëԻ + * ¦ + * message char* + * kind char* p or s or iئ + * kindlen int kind Ӯ + * body char** ̼ɡ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_getMessageBody(char* message,char* kind,int kindlen,char** body) +{ + int firstchar; + + /* 1 ٯ ë֮ʣ1 ٯƥؤ³練lssproto.html */ + // Nuke +1: For invalid message attack + *body = 0; + firstchar = message[0]; + if( firstchar == 'P' || + firstchar == 'S' || + firstchar == 'D' + + // CoolFish: Trade 2001/4/18 + || firstchar == 'C' + || firstchar == 'T' + || firstchar == 'W' + + // CoolFish: Family 2001/5/28 + || firstchar == 'A' + || firstchar == 'J' + || firstchar == 'E' + || firstchar == 'M' + + || firstchar == 'B' + || firstchar == 'X' + || firstchar == 'R' + || firstchar == 'L' + + ){ + if( kindlen >= 2 ){ + kind[0] = firstchar; + kind[1] = '\0'; + } else { + return; + } + } else { + return; + } + + *body = message + 2; +} + + +static BOOL CHAR_Talk_check( int talkerindex, int talkedindex, int micflg ) +{ +#if 1 + if( !CHAR_getFlg( talkerindex, CHAR_ISPARTYCHAT )){ + int talker_b_mode = CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE); + int talked_b_mode = CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEMODE); + if( talker_b_mode != BATTLE_CHARMODE_NONE + && CHAR_getInt( talkedindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER){ + return FALSE; + } + if( micflg != 0 )return TRUE; + if( talker_b_mode != BATTLE_CHARMODE_NONE && talked_b_mode != BATTLE_CHARMODE_NONE){ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEINDEX) + != CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEINDEX)){ + return FALSE; + } + }else if( talker_b_mode != BATTLE_CHARMODE_NONE || talked_b_mode != BATTLE_CHARMODE_NONE){ + return FALSE; + } + return TRUE; + } + if( CHAR_getInt( talkerindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + int talker_b_mode = CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE); + int talked_b_mode = CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEMODE); + + if( talker_b_mode != BATTLE_CHARMODE_NONE && CHAR_getInt( talkedindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER){ + return FALSE; + } + if( micflg != 0 )return TRUE; + if( CHAR_getWorkInt( talkerindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ){ + if( CHAR_getWorkInt( talkedindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKPARTYINDEX1) + == CHAR_getWorkInt( talkedindex, CHAR_WORKPARTYINDEX1) ){ + return TRUE; + } + } + }else { + if( talker_b_mode != BATTLE_CHARMODE_NONE && talked_b_mode != BATTLE_CHARMODE_NONE){ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEINDEX) + != CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEINDEX)){ + return FALSE; + } + }else if( talker_b_mode != BATTLE_CHARMODE_NONE || + talked_b_mode != BATTLE_CHARMODE_NONE){ + return FALSE; + } + return TRUE; + } + } + return FALSE; + +#else + int MyBattleMode; + int ToBattleMode; + + MyBattleMode = CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE); + ToBattleMode = CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEMODE); + + /* */ + if( MyBattleMode == BATTLE_CHARMODE_NONE ) { + if( ToBattleMode == BATTLE_CHARMODE_NONE ) { + return TRUE; + } + else { + return FALSE; + } + } + /* */ + else { + /* ƻئб巴˪ئУ */ + if( ToBattleMode == BATTLE_CHARMODE_NONE) { + return FALSE; + } + /* Ԫ ƥ Ԫбƾ˪ ئ */ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEINDEX) + == CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLEINDEX) && + CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLESIDE) + == CHAR_getWorkInt( talkedindex, CHAR_WORKBATTLESIDE ) ) + { + return TRUE; + } + else { + return FALSE; + } + } + return FALSE; +#endif +} +#ifdef _TELLCHANNEL // (ɿ) Syu ADD Ƶ +static int TalkCount = 0 ; +void OneByOneTkChannel ( int fd , char *tmp1 , char *tmp2 , int color ) +{ + int i ; + int myindex ; + int playernum = CHAR_getPlayerMaxNum(); + char buf[512]; + int IndexList[10] = { 0 } ; + int IndexCount = 0 ; + char *addr; + int target; + myindex = CONNECT_getCharaindex(fd); + + if ( strlen( tmp2 ) > ( sizeof( buf ) - 1 ) ) + return ; + memset ( IndexList , -1 , sizeof( IndexList ) ); + +#ifdef _THE_WORLD_SEND + if(strcmp(tmp1, "" ) == 0){ + int lastTalkTime = CHAR_getWorkInt(myindex, CHAR_WORKWORLDSENDTIME ); + if( (int)NowTime.tv_sec - lastTalkTime > 5 ) { + char token[256]; + if(CHAR_getInt( myindex, CHAR_TRANSMIGRATION) >= getTheWorldTrans() + && CHAR_getInt( myindex, CHAR_LV) >= getTheWorldLevel()){ + if(CHAR_getInt(myindex, CHAR_FAME)>=getTheWorldSend()){ + sprintf(token, "[] %s ˵%s", CHAR_getChar( myindex , CHAR_NAME), tmp2); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + if(CHAR_getFlg(i, CHAR_ISWORLD)==TRUE){ + CHAR_talkToCli( i, -1, token, CHAR_COLORGREEN); + } + } + } + CHAR_setInt(myindex,CHAR_FAME, CHAR_getInt(myindex,CHAR_FAME) - getTheWorldSend()); + CHAR_setWorkInt(myindex, CHAR_WORKWORLDSENDTIME, (int)NowTime.tv_sec ); + }else{ + sprintf(token, "%d޷ʹƵܣ", getTheWorldSend()); + CHAR_talkToCli( i, -1, token, CHAR_COLORRED); + } + return; + }else{ + sprintf(token, "תȼδﵽҪ,ݲʹƵ!"); + CHAR_talkToCli( myindex, -1, token, CHAR_COLORRED); + return; + } + }else{ + CHAR_talkToCli( myindex, -1, "ÿʹƵʹƵ!", CHAR_COLORRED); + return; + } + } +#endif + +#ifdef _ALL_SERV_SEND + if(strcmp(tmp1, "" ) == 0){ + char token[256]; + if(CHAR_getInt( myindex, CHAR_TRANSMIGRATION) >= getAllServTrans() + && CHAR_getInt( myindex, CHAR_LV) >= getAllServLevel()){ + if(CHAR_getInt(myindex, CHAR_FAME)>=getAllServSend()){ + sprintf(token, "[%s] %s ˵%s", getGameservername(), CHAR_getChar( myindex , CHAR_NAME), tmp2); + saacproto_AllServSend_send(token); + + CHAR_setInt(myindex,CHAR_FAME, CHAR_getInt(myindex,CHAR_FAME) - getAllServSend()); + + }else{ + sprintf(token, "%d޷ʹƵܣ", getAllServSend()); + CHAR_talkToCli( myindex, -1, token, CHAR_COLORRED); + } + return; + }else{ + sprintf(token, "תȼδﵽҪ,ݲʹƵ!"); + CHAR_talkToCli( myindex, -1, token, CHAR_COLORRED); + return; + } + } +#endif + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + if (!CHAR_CHECKINDEX(i)) + continue; + if ( strcmp ( tmp1 , CHAR_getChar( i , CHAR_NAME ) ) == 0 ) { + IndexList[ IndexCount ] = i ; + IndexCount ++ ; + if ( IndexCount >= 10 ) + break; + } + } + } + + if ( IndexCount == 1 ) { + if ( myindex == IndexList[0] ) + return; +#ifdef _CHANNEL_MODIFY + if(CHAR_getFlg(IndexList[0],CHAR_ISTELL) == FALSE){ + snprintf(buf,sizeof(buf) - 1,"%s ر˴Ƶ" ,tmp1); + CHAR_talkToCli(myindex,-1,buf,color); + return; + } +#endif +#ifndef _CHANNEL_MODIFY + snprintf( buf, sizeof( buf)-1, "%s%s" , tmp1 , tmp2 ) ; + CHAR_talkToCli( myindex, -1, buf , color); + snprintf( buf , sizeof( buf)-1,"%s㣺%s" , CHAR_getChar ( myindex , CHAR_NAME ) , tmp2 ) ; + CHAR_talkToCli( IndexList[0] , -1, buf , color); +#else + snprintf(buf,sizeof(buf) - 1,"P|M|%s%s",tmp1,tmp2); + lssproto_TK_send(fd,CHAR_getWorkInt(myindex,CHAR_WORKOBJINDEX),buf,color); + snprintf(buf,sizeof(buf) - 1,"P|M|%s㣺%s",CHAR_getChar(myindex,CHAR_NAME),tmp2); + lssproto_TK_send(getfdFromCharaIndex(IndexList[0]),CHAR_getWorkInt(IndexList[0],CHAR_WORKOBJINDEX),buf,color); +#endif + TalkCount ++ ; + }else if ( IndexCount > 1 && IndexCount < 10 ) { + print( "\nSyu log ͬFunc" ); + if ( ( addr = strstr ( tmp2 , "/T" ) ) != NULL ) { + addr = addr + 2 ; + target = atoi ( addr ) ; + print ( "\nSyu log addr => %s , target => %d " , addr , target ) ; + addr = strtok ( tmp2 , "/T" ) ; + if (!CHAR_CHECKINDEX(IndexList[target])) + return; + if ( strcmp ( tmp1 , CHAR_getChar ( IndexList[ target ] , CHAR_NAME ) ) == 0 && + IndexList[ target ] != -1 ) { + if ( myindex == IndexList[ target ] ) + return ; +#ifdef _CHANNEL_MODIFY + if(CHAR_getFlg(IndexList[target],CHAR_ISTELL) == FALSE){ + snprintf(buf,sizeof(buf) - 1,"%s ر˴Ƶ" ,tmp1); + CHAR_talkToCli(myindex,-1,buf,color); + return; + } +#endif +#ifndef _CHANNEL_MODIFY + snprintf( buf , sizeof( buf)-1, "%s%s" , tmp1 , addr ) ; + CHAR_talkToCli( myindex, -1, buf , color); + snprintf( buf , sizeof( buf)-1, "%s㣺%s" , CHAR_getChar ( myindex , CHAR_NAME ) , addr ) ; + CHAR_talkToCli( IndexList[ target ] , -1, buf , color); +#else + snprintf(buf,sizeof(buf) - 1,"P|M|%s%s",tmp1,addr); + lssproto_TK_send(fd,CHAR_getWorkInt(myindex,CHAR_WORKOBJINDEX),buf,color); + snprintf(buf,sizeof(buf) - 1,"P|M|%s㣺%s",CHAR_getChar(myindex,CHAR_NAME),addr); + lssproto_TK_send(getfdFromCharaIndex(IndexList[target]),CHAR_getWorkInt(IndexList[target],CHAR_WORKOBJINDEX),buf,color); +#endif + TalkCount ++ ; + } + }else { + for ( i = 0 ; i < 10 ; i ++ ) { + if ( IndexList[ i ] == -1 ) + break; + + if ( !CHAR_CHECKINDEX( IndexList[ i ] ) ) + break; +#ifndef _CHANNEL_MODIFY + sprintf( buf , "TK|%d|%d|%d|%s|%s" , + i , + CHAR_getInt ( IndexList[ i ] , CHAR_TRANSMIGRATION ) , + CHAR_getInt ( IndexList[ i ] , CHAR_LV ) , + CHAR_getChar ( IndexList[ i ] , CHAR_NAME ) , + CHAR_getChar ( IndexList[ i ] , CHAR_OWNTITLE ) + ) ; + CHAR_talkToCli( myindex , -1, buf , color); +#else + sprintf( buf , "P|TK|%d|%d|%d|%s|%s" , + i , + CHAR_getInt ( IndexList[ i ] , CHAR_TRANSMIGRATION ) , + CHAR_getInt ( IndexList[ i ] , CHAR_LV ) , + CHAR_getChar ( IndexList[ i ] , CHAR_NAME ) , + CHAR_getChar ( IndexList[ i ] , CHAR_OWNTITLE ) + ) ; + lssproto_TK_send(fd,CHAR_getWorkInt(myindex,CHAR_WORKOBJINDEX),buf,color); +#endif + } +#ifndef _CHANNEL_MODIFY + snprintf( buf , sizeof( buf)-1, "TE|%s" , tmp2 ) ; + CHAR_talkToCli ( myindex , -1 , buf , color ) ; +#else + snprintf( buf , sizeof( buf)-1, "P|TE|%s" , tmp2 ) ; + lssproto_TK_send(fd,CHAR_getWorkInt(myindex,CHAR_WORKOBJINDEX),buf,color); +#endif + } + }else if ( IndexCount == 0 ) { + sprintf( buf , "û˻λ" ) ; + CHAR_talkToCli( myindex, -1, buf , color); + } +// print ( "\nSyu log TkChannel use ratio : %d " , TalkCount ) ; +} +#endif + + +void CHAR_Talk( int fd, int index,char* message,int color, int area ) +{ + char firstToken[64]; + char messageeraseescape[512]; + char* messagebody; + int mesgvolume=0; + int lastvolume=0; + int fl,x,y; + int stringlen; + int micflg = 0; +#ifdef _TELLCHANNEL // (ɿ) Syu ADD Ƶ + char tmp1[128] ; + char *tmp2; +#endif + int fmindexi = CHAR_getWorkInt( index, CHAR_WORKFMINDEXI ); + int channel = CHAR_getWorkInt( index, CHAR_WORKFMCHANNEL ); + int quickchannel = CHAR_getWorkInt( index, CHAR_WORKFMCHANNELQUICK ); + { + char *cdkey = CHAR_getChar( index, CHAR_CDKEY); + char *charname = CHAR_getChar( index, CHAR_NAME); + if( strlen(message) > 3 ){ + if( CHAR_getWorkInt( index, CHAR_WORKFLG) & WORKFLG_DEBUGMODE ) { + // shan begin + if(strstr( message, "[")&&strstr( message, "]")){ + }else{ + // original + LogTalk( charname, cdkey, CHAR_getInt( index, CHAR_FLOOR), + CHAR_getInt( index, CHAR_X), CHAR_getInt( index, CHAR_Y), + message ); + } + // end + } + } + } + //bg|0|r0|fc|d4B8|p0|bn|10|bt|10| + // Nuke +1 08/27: For invalid message attack + if ( *message == 0 ) + return ; + CHAR_getMessageBody(message,firstToken,sizeof(firstToken), + &messagebody); + // Nuke +1: For invalid message attack + if ( !messagebody ) + return ; + + strcpysafe( messageeraseescape,sizeof(messageeraseescape), + messagebody ); + makeStringFromEscaped( messageeraseescape ); + stringlen = strlen( messageeraseescape ); + if ( stringlen <= 0 ) + return ; + +#ifdef _FILTER_TALK +{ + int i; + char *p=NULL; + while(1){ + for(i=0;i1 && atoi(token)<200){ + getStringFromIndexWithDelim(messageeraseescape, " ", 2, buff, sizeof(buff)); + lssproto_WN_send( getfdFromCharaIndex(index), atoi(token), + WINDOW_BUTTONTYPE_OKCANCEL, + -1, + -1, + buff); + } + if(atoi(token)== 0){ + getStringFromIndexWithDelim(messageeraseescape, " ", 2, buff, sizeof(buff)); + lssproto_C_send(getfdFromCharaIndex(index), buff); + } +} +#endif +*/ + +#ifdef _ALLBLUES_LUA_1_6 + if(CharTalkFunction( index, messageeraseescape, color ) == TRUE){ + return; + } +#endif +#ifdef _THE_WORLD_SEND + if (messageeraseescape[0]== '/' && messageeraseescape[1]== 'W' && messageeraseescape[2]== 'D'){ + int lastTalkTime = CHAR_getWorkInt(index, CHAR_WORKWORLDSENDTIME ); + + if( (int)NowTime.tv_sec - lastTalkTime > 5 ) { + char token[256]; + char buff[256]; + char buf[64]; + if(CHAR_getInt( index, CHAR_TRANSMIGRATION) >= getTheWorldTrans() + && CHAR_getInt( index, CHAR_LV) >= getTheWorldLevel()){ + if(CHAR_getInt(index, CHAR_FAME)>=getTheWorldSend()){ + // easyGetTokenFromString( messageeraseescape , 2 , buff, sizeof(buff)); + sprintf(token, "[] %s ˵%s", CHAR_getChar( index , CHAR_NAME), messageeraseescape + 4); + int i; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { +#ifdef _CHATROOMPROTOCOL + if(CHAR_getFlg(i, CHAR_ISWORLD)==TRUE) +#endif + CHAR_talkToCli( i, -1, token, CHAR_COLORGREEN); + } + } + CHAR_setInt(index,CHAR_FAME, CHAR_getInt(index,CHAR_FAME) - getTheWorldSend()); + CHAR_setWorkInt(index, CHAR_WORKWORLDSENDTIME, (int)NowTime.tv_sec ); + }else{ + sprintf(token, ",޷ʹƵ!"); + CHAR_talkToCli( index, -1, token, CHAR_COLORRED); + } + return; + }else{ + sprintf(token, "תȼδﵽҪ,ݲʹƵ!"); + CHAR_talkToCli( index, -1, token, CHAR_COLORRED); + return; + } + }else{ + CHAR_talkToCli( index, -1, "ÿʹƵʹƵ!", CHAR_COLORRED); + return; + } + } +#endif + +#ifdef _ONLINE_TALK_IP + if (messageeraseescape[0]== '/' && messageeraseescape[1]== 'I' && messageeraseescape[2]== 'P'){ + char token[256]; + char name[64]; + if(getStringFromIndexWithDelim(messageeraseescape, " ", 2, name, sizeof(name))==TRUE){ + int i; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + if(strcmp(CHAR_getChar(i, CHAR_NAME), name)==0){ + int i; + int itemindex; + for( i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(index); i ++ ) { + itemindex = CHAR_getItemIndex(index, i); + if(strcmp(ITEM_getChar( itemindex, ITEM_USEFUNC), "ITEM_TALKIP")==0){ + char buf[256]; + + int itemmaxuse = ITEM_getInt( itemindex, ITEM_DAMAGEBREAK); + itemmaxuse--; + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, itemmaxuse); + if( itemmaxuse < 1 ) { + sprintf( buf, " %sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli(index, -1, buf, CHAR_COLORYELLOW); + CHAR_DelItem( index, i); + }else{ + sprintf( buf, "%sʹôʣ%dΡ", ITEM_getChar( itemindex, ITEM_NAME), itemmaxuse); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf); + CHAR_sendItemDataOne( index, i); + } + + struct tm now; + time_t timep; + time(&timep); + + memcpy(&now, localtime(&timep), sizeof(now)); + sprintf(buf, "onlinetalkip/%02d-%02d-%02d.txt", 1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday); + + FILE * f1 = fopen(buf,"a+"); + sprintf(token, "[%02d-%02d-%02d %02d:%02d:%02d] %s %s ߾ٱԷ %s %s \n", + 1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday, + now.tm_hour, now.tm_min, now.tm_sec, + CHAR_getChar(index, CHAR_CDKEY), + CHAR_getChar(index, CHAR_NAME), + CHAR_getChar(i, CHAR_CDKEY), + CHAR_getChar(i, CHAR_NAME)); + fputs(token,f1); + fclose(f1); + + CHAR_talkToCli( index, -1, "лľٱǽṩкʵ!", CHAR_COLORYELLOW); + + break; + } + } + if(i == CheckCharMaxItem(index)){ + CHAR_talkToCli( index, -1, "ϳоٱ߲ſԾٱ!", CHAR_COLORYELLOW); + } + } + } + } + } + return; + } +#endif + +#ifdef _ONLINE_TALK_GM + if(messageeraseescape[0]== '|' && messageeraseescape[1]== 'G' && messageeraseescape[2]== 'M' && messageeraseescape[3]== '|'){ + int i, j; + int num=0; + int playernum = CHAR_getPlayerMaxNum(); + char token[256]; + sprintf(token, "յ %s %s Ϣ%s", CHAR_getChar(index, CHAR_CDKEY), + CHAR_getChar(index, CHAR_NAME), + messageeraseescape+4); + for (i = 0; i < GMMAXNUM; i++){ + for( j = 0 ; j < playernum ; j++) { + if( CHAR_getCharUse(j) != FALSE ) { + if(strcmp(CHAR_getChar(j, CHAR_CDKEY), gminfo[i].cdkey)==0){ + CHAR_talkToCli( j, -1, token, CHAR_COLORPURPLE); + num++; + } + } + } + } + if(num==0){ + CHAR_talkToCli( index, -1, "ǰûGM", CHAR_COLORRED); + } + + } +#endif + +#ifdef _TELLCHANNEL // (ɿ) Syu ADD Ƶ + if (messageeraseescape[0]== '/' && messageeraseescape[1]== 't' && + messageeraseescape[2]== 'e' && messageeraseescape[3]== 'l' && + messageeraseescape[4]== 'l'){ + getStringFromIndexWithDelim( message , " ", 2, tmp1, sizeof(tmp1)); + if ( (tmp2 = strstr ( message , tmp1 )) != NULL ) { + //strcpy ( message , tmp2 + strlen ( tmp1 ) + 1 ) ; + message = tmp2 + strlen(tmp1) + 1 ; + if( message == "\0" || strlen( message ) <= 0 ) + return; + } + OneByOneTkChannel ( fd , tmp1 , message , color ) ; + return; + } +#endif +#ifdef _TALK_SAVE + if (messageeraseescape[0]== '/' && messageeraseescape[1]== 's' && + messageeraseescape[2]== 'a' && messageeraseescape[3]== 'v' && + messageeraseescape[4]== 'e'){ + if(CHAR_getInt(index, CHAR_FAME)>=getSaveFame()){ + static int OldTimes = 0; + if( NowTime.tv_sec - OldTimes > 3 ) { + if( fd != -1 ) { + char token[256]; + if(CHAR_charSaveFromConnect(index, FALSE)){ + CHAR_talkToCli(index, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + CHAR_setInt(index,CHAR_FAME, CHAR_getInt(index,CHAR_FAME) - getSaveFame()); + } + OldTimes = NowTime.tv_sec; + } + }else{ + CHAR_talkToCli(index, -1, "3ֻһҴ浵!", CHAR_COLORRED); + } + }else{ + CHAR_talkToCli( index, -1,"Ѿû㹻бˣ", CHAR_COLORRED ); + } + return; + } +#endif + +#ifdef _CHANNEL_MODIFY + // Ƶ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'F' && messageeraseescape[2] == 'M'){ + sprintf(messageeraseescape,"%s",messageeraseescape + 3); + } + else channel = -1; +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + // ְҵƵ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'O' && + messageeraseescape[2] == 'C' && messageeraseescape[3] == 'C'){ + int i,pclass = CHAR_getInt(index,PROFESSION_CLASS) - 1,TalkTo; + char buf[512]; + + sprintf(messageeraseescape,"%s",messageeraseescape + 4); + for(i=0;i -1){ + // ԷпƵ + if(CHAR_getFlg(TalkTo,CHAR_ISOCC) == TRUE){ + char escapebuf[2048]; + //snprintf(buf,sizeof(buf) - 1,"P|O|[ְ]%s",messageeraseescape); + snprintf(buf,sizeof(buf) - 1,"P|O|[ְ]%s", makeEscapeString( messageeraseescape, escapebuf, sizeof(escapebuf)) ); + lssproto_TK_send(getfdFromCharaIndex(TalkTo),CHAR_getWorkInt(TalkTo,CHAR_WORKOBJINDEX),buf,color); + } + } + } + return; + } +#endif +#endif + if( messageeraseescape[0] == '[' + && messageeraseescape[stringlen-1] == ']' ){ + char* pass; + // Arminius: limit ip +2 + unsigned long ip; + int a,b,c,d; + messageeraseescape[stringlen-1] = '\0'; + // Arminius: limit ip + ip=CONNECT_get_userip(fd); + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + //andy_log + + char gm[128]; + pass = strstr( messageeraseescape+1, getChatMagicPasswd()); + if( pass == messageeraseescape+1 ){ + + if(CHAR_useChatMagic( index,messageeraseescape + 1 + + strlen(getChatMagicPasswd()) + 1, TRUE)){ + print( "\n˺:%s :%s\nip:%d.%d.%d.%d\nʹGM%s]\n",CHAR_getChar( index, CHAR_CDKEY), + CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape); + sprintf( gm, "ʹGM%s]ѳɹ", messageeraseescape); + CHAR_talkToCli( index, -1,gm, CHAR_COLORYELLOW ); + } + }else{ + if( CHAR_getWorkInt( index, CHAR_WORKFLG ) & WORKFLG_DEBUGMODE ) { + if(CHAR_useChatMagic( index,messageeraseescape + 1,TRUE)){ + print( "\n˺:%s :%s\nip:%d.%d.%d.%d\nʹGM%s]\n",CHAR_getChar( index, CHAR_CDKEY), + CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape); + sprintf( gm, "ʹGM%s]ѳɹ", messageeraseescape); + CHAR_talkToCli( index, -1,gm, CHAR_COLORYELLOW ); + } + }else{ +#ifdef _GM_ITEM + if(CHAR_getInt( index, CHAR_GMTIME)>0){ + char magicname[32]; + char token[64]; + getStringFromIndexWithDelim( messageeraseescape + 1, " ", 1, magicname, sizeof( magicname)); + if(!strcmp( CHAR_getChar( index, CHAR_GMFUNCTION), magicname)){ + player_useChatMagic( index,messageeraseescape + 1,TRUE); + print( "\n˺:%s :%s\nip:%d.%d.%d.%d\nʹƷ%s]ʣ%d\n", CHAR_getChar( index, CHAR_CDKEY), + CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape, CHAR_getInt( index, CHAR_GMTIME) - 1); + CHAR_setInt( index , CHAR_GMTIME, CHAR_getInt( index, CHAR_GMTIME) - 1 ); + if(CHAR_getInt( index, CHAR_GMTIME) > 0){ + sprintf( token, "㻹ʹ%sȨ%d!", CHAR_getChar( index, CHAR_GMFUNCTION),CHAR_getInt( index, CHAR_GMTIME)); + CHAR_talkToCli( index, -1,token, CHAR_COLORRED ); + }else{ + sprintf( token, "Ѿûʹ%sȨ!", CHAR_getChar( index, CHAR_GMFUNCTION)); + CHAR_talkToCli( index, -1,token, CHAR_COLORRED ); + } + }else if(!strcmp( "help", magicname) || !strcmp( "", magicname)){ + getStringFromIndexWithDelim( messageeraseescape + 1, " ", 2, magicname, sizeof( magicname)); + if(!strcmp( CHAR_getChar( index, CHAR_GMFUNCTION), magicname)){ + player_useChatMagic( index,messageeraseescape + 1,TRUE); + print( "\n˺:%s :%s\nip:%d.%d.%d.%d\nʹð%s]\n", CHAR_getChar( index, CHAR_CDKEY), + CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape); + } + } + }else +#endif + CHAR_useChatMagic( index,messageeraseescape + 1,FALSE); + } + } + messageeraseescape[stringlen-1] = ']'; + return; + }else { + if( CHAR_getWorkInt( index, CHAR_WORKFLG) & WORKFLG_DEBUGMODE ) { + if( strstr( messageeraseescape, "[") != NULL || + strstr( messageeraseescape, "]") != NULL ){ + return; + } + } + } +#ifdef _PLAYER_MOVE + if(getPMove()>-1){ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'g' && messageeraseescape[2] == 'o'){ + int point=CHAR_getInt( index , CHAR_AMPOINT); + if(point>=getPMove() || getPMove()== 0 ){ + char x[4],y[4]; + easyGetTokenFromString( messageeraseescape , 2 , x, sizeof(x)); + easyGetTokenFromString( messageeraseescape , 3 , y, sizeof(y)); + CHAR_warpToSpecificPoint( index, CHAR_getInt( index, CHAR_FLOOR), atoi(x), atoi(y) ); + CHAR_setInt( index , CHAR_AMPOINT, point-getPMove()); +#ifdef _AMPOINT_LOG + if(getPMove()>0){ + LogAmPoint(CHAR_getChar( index, CHAR_NAME ), + CHAR_getChar( index, CHAR_CDKEY ), + -getPMove(), + CHAR_getInt( index, CHAR_AMPOINT ), + "(ƶ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y )); + } +#endif + }else + CHAR_talkToCli( index, -1,"Ѿû㹻Ļֵ˳ˣ", CHAR_COLORRED ); + return; + } + } +#endif + +#ifdef _PLAYER_ANNOUNCE + if(getPAnnounce() > -1){ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'g' && messageeraseescape[2] == 'g'){ + + int point=CHAR_getInt( index , CHAR_AMPOINT); + if(point>=getPAnnounce() && getPAnnounce()>= 0 ){ + int i; + int playernum = CHAR_getPlayerMaxNum(); + char buff[255]; + + easyGetTokenFromString( messageeraseescape , 2 , buff, sizeof(buff)); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ){ + char token[256]; + sprintf(token, "<С> %s ˵%s", CHAR_getChar( index , CHAR_NAME), buff); + CHAR_talkToCli( i, -1, token, CHAR_COLORBLUE); + } + } + CHAR_setInt( index , CHAR_AMPOINT, point-getPAnnounce()); +#ifdef _AMPOINT_LOG + if(getPAnnounce()>0){ + LogAmPoint(CHAR_getChar( index, CHAR_NAME ), + CHAR_getChar( index, CHAR_CDKEY ), + -getPAnnounce(), + CHAR_getInt( index, CHAR_AMPOINT ), + "()", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y )); + } +#endif + + }else{ + CHAR_talkToCli( index, -1,"Ѿû㹻ĻֵСˣ", CHAR_COLORRED ); + } + return; + } + } +#endif + +#ifdef _TALK_MOVE_FLOOR + if(talk_move_map(index, messageeraseescape) == TRUE){ + return; + } +#endif + +#ifdef _PLAYER_QUESTION_ONLIEN + if(PlayQuestionOnline(index, messageeraseescape) == TRUE){ + return; + } +#endif + +#ifdef _SPECIAL_SUIT + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'f' && messageeraseescape[2] == 'l' && messageeraseescape[3] == 'y'){ + char token[255]; + int suit; + easyGetTokenFromString( messageeraseescape , 2 , token, sizeof(token)); + suit = atoi(token); + if(suit < 1 || suit > CHAR_EQUIPPLACENUM){ + sprintf(token, "1 ~ %d֮䣡", CHAR_EQUIPPLACENUM); + CHAR_talkToCli( index, -1, token, CHAR_COLORRED ); + return; + } + int itemindex = CHAR_getItemIndex( index, suit-1); + if( !ITEM_CHECKINDEX( itemindex) ){ + CHAR_talkToCli( index, -1, "λûװװ", CHAR_COLORRED ); + return; + } + int i, num=0; + int defCode = ITEM_getInt( itemindex, ITEM_SUITCODE); + + for( i=0; i=5){ + int ff=0, fx=0, fy=0; + char* arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( sscanf( arg, "%d %d %d", &ff, &fx, &fy) == 3 ){ + if( ITEM_WarpForAny(index, ff, fx, fy, 0) == FALSE )return; + } + }else{ + sprintf(token, "װ%d޷ʹøùܣ", 5); + CHAR_talkToCli( index, -1, token, CHAR_COLORRED ); + } + return; + } +#endif + +#ifdef _TALK_ACTION + TalkAction(index, messageeraseescape); +#endif +#ifdef _TALK_CHECK + CHAR_setWorkInt(index, CHAR_WORK_TALKCHECK, atoi(messageeraseescape)); +#endif + mesgvolume = CHAR_getVolume( messageeraseescape ); + if( area == 0 ) area = 3; + if( mesgvolume == -1 ) lastvolume = -1; + else lastvolume = area - 1 + mesgvolume; + if( CHAR_getWorkInt( index, CHAR_WORKFLG ) & WORKFLG_MICMODE ){ + lastvolume = 15; + micflg = 1; + } + fl = CHAR_getInt( index, CHAR_FLOOR) ; + x = CHAR_getInt( index, CHAR_X) ; + y = CHAR_getInt( index, CHAR_Y) ; + // Robin 0705 channel + if( messageeraseescape[0] == ':'){ + if( (channel == -1) && (quickchannel != -1) ) + channel = quickchannel; + else if( channel != -1 ) + channel = -1; + } + { + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer(index, CHAR_TALKEDFUNC); + if( talkedfunc ) { + CHAR_CHAT_DEBUG_SAVESHH( index,index,messageeraseescape,color, channel ); + talkedfunc(index,index,messageeraseescape,color, channel); + } + } + if( lastvolume == -1 ){ + int j; + int xx[2]={ x, x+CHAR_getDX(CHAR_getInt(index,CHAR_DIR))}; + int yy[2]={ y, y+CHAR_getDY(CHAR_getInt(index,CHAR_DIR))}; + BOOL talk=FALSE; + for( j=0 ; j<2 ; j ++ ){ + OBJECT object; + for( object=MAP_getTopObj(fl,xx[j],yy[j]) ; object ; object = NEXT_OBJECT( object ) ){ + int objindex = GET_OBJINDEX(object); + int toindex = OBJECT_getIndex( objindex); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && toindex != index ){ + if( CHAR_Talk_check( index, toindex, 0 )) { + if( CHAR_getInt(toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + talk = TRUE; + } + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer( toindex, CHAR_TALKEDFUNC); + if( talkedfunc ) { + CHAR_CHAT_DEBUG_SAVESHH( index,index,messageeraseescape,color, channel ); + talkedfunc(toindex, index,messageeraseescape,color,-1); + } +#ifdef _ALLBLUES_LUA + else{ + RunCharTalkedEvent(toindex,index,messageeraseescape,color, -1); + } +#endif + } + } + } + } + if( talk ){ + CHAR_setInt(index,CHAR_TALKCOUNT, CHAR_getInt( index, CHAR_TALKCOUNT) + 1); + } + }else{ + int range = CHAR_getRangeFromVolume( lastvolume ); + int i,j; + BOOL talk=FALSE; + BOOL channelTalk=FALSE; + int partyindex[CHAR_PARTYMAX]; + for( i = 0; i < CHAR_PARTYMAX; i ++ ) { + partyindex[i] = -1; + } +#ifndef _CHANNEL_MODIFY + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) +#else + if(CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE && channel < 0) +#endif + { + for( i = 0; i < CHAR_PARTYMAX; i ++ ) { + int toindex = CHAR_getPartyIndex( index, i); + if( CHAR_CHECKINDEX( toindex) && toindex != index) { + talk = TRUE; + partyindex[i] = toindex; + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer( toindex, CHAR_TALKEDFUNC); + if( talkedfunc ){ + CHAR_CHAT_DEBUG_SAVESHH( index,index,messageeraseescape,color, channel ); + talkedfunc( toindex,index, messageeraseescape, color, -1 ); + } + } + } + } + if( channel > -1 && fmindexi >= 0 ) { + int i, tindex; + + channelTalk = TRUE; + i = 0; +#ifdef _FMVER21 + if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( index, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER) +#else + if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( index, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER) +#endif + { + char buf[512]; + sprintf(buf, "[峤㲥]%s: %s", CHAR_getChar( index, CHAR_NAME ), messageeraseescape); + saacproto_ACFMAnnounce_send( acfd, + CHAR_getChar( index, CHAR_FMNAME), + CHAR_getInt( index, CHAR_FMINDEX), + CHAR_getWorkInt( index, CHAR_WORKFMINDEXI), + buf, + color + ); + return; + } + else + + for(i=0;i= 0 && tindex != index) { + +#ifdef _CHANNEL_MODIFY + if ( CHAR_getFlg( tindex, CHAR_ISFM ) == FALSE ) + continue; +#endif + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talk = TRUE; + talkedfunc = (TALKF)CHAR_getFunctionPointer(tindex,CHAR_TALKEDFUNC); + + if( talkedfunc ){ + CHAR_CHAT_DEBUG_SAVESHH( index,index,messageeraseescape,color, channel ); + talkedfunc( tindex,index, messageeraseescape, color, channel ); + } + } + } + }else { + for( i=x-range/2 ; i<=x+range/2 ; i++ ){ + for( j=y-range/2 ; j<=y+range/2 ; j++ ){ + OBJECT object; + for( object = MAP_getTopObj( fl,i,j ) ; object ; object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); + int toindex = OBJECT_getIndex( objindex); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && toindex != index ){ + int k; + for( k = 0; k < CHAR_PARTYMAX; k ++ ) { + if( toindex == partyindex[k] ) { + break; + } + } + if( k != CHAR_PARTYMAX ) + continue; + if( CHAR_Talk_check( index, toindex, micflg ) ) { + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + talk = TRUE; + } + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer( toindex, CHAR_TALKEDFUNC); + if( talkedfunc ) { + CHAR_CHAT_DEBUG_SAVESHH( index,index,messageeraseescape,color, channel ); + talkedfunc( toindex,index, messageeraseescape, color, -1 ); + } +#ifdef _ALLBLUES_LUA + else{ + RunCharTalkedEvent(toindex,index,messageeraseescape,color, -1); + } +#endif + } + } + } + } + } + } + if( CHAR_getInt( index, CHAR_POPUPNAMECOLOR) != color ) { + CHAR_setInt( index, CHAR_POPUPNAMECOLOR, color); + if( talk) { + int opt[1]; + opt[0] = color; + CHAR_sendWatchEvent( CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), + CHAR_ACTPOPUPNAME,opt,1,FALSE); + } + } + if( talk ) { + CHAR_setInt(index,CHAR_TALKCOUNT, CHAR_getInt(index,CHAR_TALKCOUNT) + 1); + } + } +} + +#ifdef _FONT_SIZE +BOOL CHAR_talkToCliExt( int talkedcharaindex,int talkcharaindex, + char* message, CHAR_COLOR color, int fontsize ) +{ + static char lastbuf[2048]; + static char escapebuf[2048]; + static char mesgbuf[1024]; + int fd; + int talkchar=-1; + + if ( !CHAR_CHECKINDEX( talkedcharaindex ) ) + return FALSE; + if( CHAR_getInt( talkedcharaindex,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER){ +// print("err CHAR_talkToCli CHAR_WHICHTYPE != CHAR_TYPEPLAYER\n"); + return FALSE; + } + + fd = getfdFromCharaIndex( talkedcharaindex ); + if( fd == -1 ){ +// print("err CHAR_talkToCli can't get fd from:%d \n", talkedcharaindex); + return FALSE; + } + + if( color < CHAR_COLORWHITE && color > CHAR_COLORGREEN2 ){ + print("CHAR_talkToCli color err\n"); + return FALSE; + } +#ifndef _CHANNEL_MODIFY + snprintf( lastbuf, sizeof(lastbuf), "P|%s|%d", + makeEscapeString( CHAR_appendNameAndTitle(talkcharaindex, message, mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) ), fontsize); +#else + snprintf( lastbuf, sizeof(lastbuf), "P|P|%s|%d", + makeEscapeString( CHAR_appendNameAndTitle(talkcharaindex, message, mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) ), fontsize); +#endif + if( talkcharaindex == -1 ) + talkchar = -1; + else + talkchar = CHAR_getWorkInt(talkcharaindex,CHAR_WORKOBJINDEX); + lssproto_TK_send( fd, talkchar, lastbuf, color); + return TRUE; +} +BOOL CHAR_talkToCli( int talkedcharaindex,int talkcharaindex, + char* message, CHAR_COLOR color ) +{ + return CHAR_talkToCliExt( talkedcharaindex, talkcharaindex, + message, color, 0 ); + +} +#else +BOOL CHAR_talkToCli( int talkedcharaindex,int talkcharaindex, + char* message, CHAR_COLOR color ) +{ + static char lastbuf[2048]; + static char escapebuf[2048]; + static char mesgbuf[1024]; + int fd; + int talkchar=-1; + + if ( !CHAR_CHECKINDEX( talkedcharaindex ) ) + return FALSE; + if( CHAR_getInt( talkedcharaindex,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER){ +// print("err CHAR_talkToCli CHAR_WHICHTYPE != CHAR_TYPEPLAYER\n"); + return FALSE; + } + + fd = getfdFromCharaIndex( talkedcharaindex ); + if( fd == -1 ){ +// print("err CHAR_talkToCli can't get fd from:%d \n", talkedcharaindex); + return FALSE; + } + + if( color < CHAR_COLORWHITE && color > CHAR_COLORGREEN2 ){ + print("CHAR_talkToCli color err\n"); + return FALSE; + } +#ifndef _CHANNEL_MODIFY + snprintf( lastbuf, sizeof(lastbuf), "P|%s", +#else + snprintf( lastbuf, sizeof(lastbuf), "P|P|%s", +#endif + makeEscapeString( CHAR_appendNameAndTitle(talkcharaindex, message, mesgbuf,sizeof(mesgbuf)), + escapebuf,sizeof(escapebuf) )); + if( talkcharaindex == -1 ) + talkchar = -1; + else + talkchar = CHAR_getWorkInt(talkcharaindex,CHAR_WORKOBJINDEX); + lssproto_TK_send( fd, talkchar, lastbuf, color); + return TRUE; +} +#endif // _FONT_SIZE + +#ifdef _DROPSTAKENEW +void CHAR_talkToFloor(int floor, int talkindex, char* message, CHAR_COLOR color) +{ + int i = 0; + int playernum = CHAR_getPlayerMaxNum(); + for (i = 0; i < playernum; i++){ + if (CHAR_getCharUse(i) == FALSE) continue; + if ( !CHAR_CHECKINDEX( i ) ) + continue; + if ( CHAR_getInt( i, CHAR_FLOOR ) == floor ) { + //if (CHAR_getWorkInt(i, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE) + CHAR_talkToCli(i, talkindex, message, color); + } + } +} +#endif + +void CHAR_talkToAll(int talkindex, char* message, CHAR_COLOR color) +{ + int i = 0; + int playernum = CHAR_getPlayerMaxNum(); + for (i = 0; i < playernum; i++){ + if (CHAR_getCharUse(i) == FALSE) continue; + if ( !CHAR_CHECKINDEX( i ) ) + continue; + CHAR_talkToCli(i, talkindex, message, color); + } +} +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _CHANNEL_MODIFY +// ʼְҵƵ +int InitOccChannel(void) +{ + if(piOccChannelMember == NULL){ + piOccChannelMember = (int*)calloc( 1,(PROFESSION_CLASS_NUM - 1) * getFdnum() * sizeof(int)); + if(piOccChannelMember == NULL){ + printf("Char_talk.c:InitOccChannel() memory allocate failed!\n"); + return 0; + } + memset(piOccChannelMember,-1,(PROFESSION_CLASS_NUM - 1) * getFdnum() * sizeof(int)); + } + return 1; +} +#endif +#endif +#ifdef _TALK_ACTION +void TalkAction(int charaindex, char *message) +{ + int i; + typedef struct{ + char talk[5]; + int action; + }tagTlakAction; + tagTlakAction TlakAction[13]={ + { "", 11},{ "", 12},{ "ͷ", 18}, + { "", 13},{ "", 14},{ "", 15}, + { "վ", 19},{ "߶", 17},{ "ε", 10}, + { "", 2 },{ "", 16},{ "", 4 }, + { "Ͷ", 3 } + }; + for(i=0;i<13;i++) + if(strstr(message,TlakAction[i].talk)) + break; + + if(i<13){ + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, TlakAction[i].action ); + CHAR_sendWatchEvent(CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), TlakAction[i].action, NULL, 0, TRUE); + } +} +#endif +#ifdef _GM_ITEM +static BOOL player_useChatMagic( int charaindex, char* data, BOOL isDebug) +{ + char magicname[256]; + int ret; + + CHATMAGICFUNC func; + + ret = getStringFromIndexWithDelim( data, " ", 1, magicname, sizeof( magicname)); + if( ret == FALSE)return FALSE; + + func = CHAR_getChatMagicFuncPointer(magicname,isDebug); + + if( func ){ + LogGM( CHAR_getUseName( charaindex), CHAR_getChar( charaindex, CHAR_CDKEY), data, + CHAR_getInt( charaindex, CHAR_FLOOR), CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y) ); + func( charaindex, data + strlen( magicname)+1); + return TRUE; + }else{ + return FALSE; + } +} +#endif + +#ifdef _RE_GM_COMMAND +int re_gm_command() +{ + FILE* fp; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/regmcommand.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/regmcommand.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + int i; + while(1){ + char line[1024], buf[128]; + if (fgets(line, sizeof(line), fp) == NULL)break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + if(line[0]=='#')continue; + getStringFromIndexWithDelim(line,"=", 1, buf, sizeof(buf)); + for( i=0 ; i FilterTalkNum)index=FilterTalkNum; + return FilterTalk[index]; +} + +int getFilterTalkNum() +{ + return FilterTalkNum; +} +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_walk.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_walk.c new file mode 100644 index 0000000..115495b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/char_walk.c @@ -0,0 +1,2014 @@ +#include "version.h" +#include +#include +#include +//??? +#include "common.h" +#include "handletime.h" +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "char_event.h" +#include "lssproto_serv.h" +#include "readmap.h" +#include "map_deal.h" +#include "npccreate.h" +#include "encount.h" +#include "npcutil.h" +#include "battle.h" +#include "net.h" +#include "configfile.h" +#include "npc_npcenemy.h" +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +void CHAR_sendCharaAtWalk( int charaindex, int of, int ox, int oy, int xflg, int yflg ); +static void CHAR_sendCDCharaAtWalk( int charaindex, int of, int ox, int oy, int xflg, int yflg ); + +static CHAR_WALKRET CHAR_walk_turn( int index, int dir ) +{ + int fx,fy,ff; + OBJECT object; + + if(!CHAR_CHECKINDEX( index ))return CHAR_WALKSYSTEMERROR; + CHAR_setInt(index,CHAR_DIR,dir); + fx = CHAR_getInt(index,CHAR_X); + fy = CHAR_getInt(index,CHAR_Y); + ff = CHAR_getInt(index,CHAR_FLOOR); + CHAR_sendWatchEvent( CHAR_getWorkInt(index, CHAR_WORKOBJINDEX), + CHAR_ACTTURN,NULL,0,FALSE); + CHAR_setWorkInt( index, CHAR_WORKACTION, CHAR_ACTTURN); + for( object = MAP_getTopObj(ff,fx,fy) ; object ; + object = NEXT_OBJECT(object ) ){ + typedef void (*POSTOFUNC)(int,int); + POSTOFUNC pfunc=NULL; + int objindex = GET_OBJINDEX(object); + + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + pfunc = (POSTOFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex), + CHAR_POSTOVERFUNC); + break; + case OBJTYPE_ITEM: + pfunc = (POSTOFUNC)ITEM_getFunctionPointer( + OBJECT_getIndex(objindex), + ITEM_POSTOVERFUNC); +#ifdef _ALLBLUES_LUA_1_2 + if( !pfunc ){ + RunItemPostOverEvent(OBJECT_getIndex(objindex), index ); + } +#endif + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + if( pfunc )pfunc( OBJECT_getIndex(objindex),index ); + } + return CHAR_WALKSUCCESSED; +} + + +/*------------------------------------------------------------ + * n mapë˪ + * ¦ + * index int ƽҷ¼̼͵ + * fl int ׷ʧID + * ox int 󡼰ؼx + * oy int 󡼰ؼy + * fx int x + * fy int y + * ߯Ի + * ئ + ------------------------------------------------------------*/ +static void CHAR_sendMapAtWalk( int index, int fl ,int ox ,int oy, + int fx, int fy ) +{ + /* + * ػƥëέ + * NPCֿǩ֣ + */ + int vx,vy; + const int seesiz = MAP_CHAR_DEFAULTSEESIZ; + + if( !CHAR_CHECKINDEX( index ) )return; + + vx = fx - ox; + vy = fy - oy; + + if( ABS(vx) >= seesiz/2 || /* */ + ABS(vy) >= seesiz/2 ){ /* */ + return; + + }else{ + RECT send,get; + char* mapdata; + int oldlux = ox - (int)(seesiz/2); + int oldluy = oy - (int)(seesiz/2); + int absx = ABS(vx); + int absy = ABS(vy); + /* + * 繴嵩ë¼vx , vy 1ʼ̼ + * 羮ئئз + * clipRect w,h 0 ë继 + */ + + /* == 0 ݷ˪ئʻ */ + if( vx != 0 ){ + if( vx > 0 ){ + send.x = oldlux + seesiz; + send.width = absx; + }else if( vx < 0 ){ + send.x = oldlux - absx; + send.width = absx; + } + + if( vy >= 0 ){ + send.y = oldluy; + send.height = seesiz + absy; + }else{ + send.y = oldluy - absy; + send.height = seesiz + absy; + } +{ + int tilesum, objsum,eventsum; + mapdata = MAP_getChecksumFromRECT(fl,&send,&get,&tilesum, &objsum,&eventsum ); + if( mapdata != NULL + && !( get.width == 0 && get.height == 0 ) ){ + int fd = getfdFromCharaIndex( index ); + if( fd != -1 ) + lssproto_MC_send( fd,fl,get.x,get.y, + get.x+get.width, + get.y+get.height, + tilesum, + objsum, + eventsum, + mapdata ); + } +} + } + + /* == 0 ݷ˪ئʻ */ + if( vy != 0 ){ + if( vy > 0 ){ + send.y = oldluy + seesiz; + send.height = absy; + }else{ + send.y = oldluy - absy; + send.height = absy; + } + if( vx >= 0 ){ + send.x = oldlux; + send.width = seesiz + absx; + }else if( vx < 0 ){ + send.x = oldlux - absx; + send.width = seesiz + absx; + } +{ + int tilesum, objsum,eventsum; + mapdata = MAP_getChecksumFromRECT(fl,&send,&get, &tilesum, &objsum,&eventsum); + if( mapdata != NULL + && !( get.width == 0 && get.height == 0 ) ){ + int fd = getfdFromCharaIndex( index ); + if( fd != -1 ) + lssproto_MC_send( fd,fl,get.x,get.y, + get.x+get.width, + get.y+get.height, + tilesum, + objsum, + eventsum, + mapdata ); + + } +} + } + } + +} +static CHAR_WALKRET CHAR_walk_move( int charaindex, int dir ); +/*------------------------------------------------------------ + * £ + * ¦ + * index int ƽҷ¼̼͵ + * dir int + * ߯Ի + * CHAR_WALKRET + ------------------------------------------------------------*/ +static CHAR_WALKRET CHAR_walk_move( int charaindex, int dir ) +{ + int i; + int fx,fy,ff; + int ox,oy,of; + int objbuf[128]; + int objbufindex=0; + int notover=FALSE; + int retvalue=CHAR_WALKSUCCESSED; + + if( !CHAR_CHECKINDEX( charaindex )) return CHAR_WALKSYSTEMERROR; + ox = CHAR_getInt(charaindex,CHAR_X); + oy = CHAR_getInt(charaindex,CHAR_Y); + of = CHAR_getInt(charaindex,CHAR_FLOOR); + CHAR_getCoordinationDir( dir,ox,oy,1,&fx,&fy); + ff = of; + + if( CHAR_getInt( charaindex,CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + RECT walkr; + POINT nextp; + int npccreateindex; + npccreateindex = CHAR_getInt( charaindex,CHAR_NPCCREATEINDEX ); + if( CHAR_isInvincibleArea( ff,fx,fy)) { + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKEXTEND; + goto CHAR_AFTERWALK; + } + if( NPC_isBoundarySet( npccreateindex ) && + NPC_createGetRECT( npccreateindex,&walkr ) == TRUE ) + { + nextp.x = fx; + nextp.y = fy; + if( PointInRect( &walkr,&nextp ) == FALSE ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKEXTEND; + goto CHAR_AFTERWALK; + } + }else{ + ; + } + } + + + if( CHAR_getFlg( charaindex, CHAR_ISBIG ) == 1 ){ + static POINT offset[5]={ + { 0,-1}, + {-1, 0}, + { 0, 0}, + { 1, 0}, + { 0, 1}, + }; + int k; + for( k=0 ; k<5; k++ ){ + if( !MAP_walkAble( charaindex, ff, fx+offset[k].x, + fy+offset[k].y )){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + goto CHAR_AFTERWALK; + } + } + + }else{ + if( CHAR_getDX(dir)*CHAR_getDY(dir) == 0 ){ + if( !MAP_walkAble( charaindex,ff, fx, fy ) ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + goto CHAR_AFTERWALK; + } + }else{ + int xflg,yflg; + if( !MAP_walkAble( charaindex,ff, fx, fy ) ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + goto CHAR_AFTERWALK; + } + + xflg = MAP_walkAble( charaindex,of, ox+CHAR_getDX(dir), oy ); + yflg = MAP_walkAble( charaindex,of, ox, oy+CHAR_getDY(dir) ); + + if( !xflg || !yflg ) { + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + goto CHAR_AFTERWALK; + } + } + } + objbufindex = CHAR_getSameCoordinateObjects( objbuf, arraysizeof( objbuf ), ff,fx,fy ); + for( i = 0 ; i < objbufindex ; i ++ ){ + int objindex= objbuf[i]; + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + if(CHAR_CHECKINDEX(OBJECT_getIndex(objindex))==TRUE){ +#ifdef _ALLBLUES_LUA + int meindex=-1, toindex=-1; + if(CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPLAYER){ + if(CHAR_getInt(OBJECT_getIndex(objindex), CHAR_WHICHTYPE)==CHAR_TYPELUANPC){ + meindex = OBJECT_getIndex(objindex); + toindex = charaindex; + } + }else if(CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPELUANPC){ + if(CHAR_getInt(OBJECT_getIndex(objindex), CHAR_WHICHTYPE)==CHAR_TYPEPLAYER){ + meindex = charaindex; + toindex = OBJECT_getIndex(objindex); + } + } + if(CHAR_CHECKINDEX(meindex) == TRUE || CHAR_CHECKINDEX(toindex) == TRUE){ + if( CHAR_getWorkInt( meindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE + && CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ + if(CHAR_getFlg(meindex, CHAR_ISVISIBLE)==TRUE && CHAR_getFlg(meindex, CHAR_ISDIE) == FALSE){ + if( CHAR_getWorkInt( meindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT && CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT ){ + RunCharOverlapEvent(meindex, toindex); + } + } + } + } +#endif +#ifdef _PLAYER_OVERLAP_PK + if(CHAR_getInt(charaindex, CHAR_WHICHTYPE)==CHAR_TYPEPLAYER + && CHAR_getInt(OBJECT_getIndex(objindex), CHAR_WHICHTYPE)==CHAR_TYPEPLAYER ){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_NONE ){ + int i; + for( i = 0; i < getPartyNum(charaindex); i ++ ){ + int subindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1+i ); + if( CHAR_CHECKINDEX( subindex ) == FALSE ) continue; + if(OBJECT_getIndex(objindex) == subindex)break; + } + + if(i == getPartyNum(charaindex)){ + int j; + for(j=0;j<32;j++){ + if(CHAR_getInt(charaindex, CHAR_FLOOR) == getPlayerOverlapPk(j)){ + BATTLE_CreateVsPlayer(charaindex, OBJECT_getIndex(objindex)); + break; + } + } + } + } + } +#endif + } + if( !CHAR_getFlg( OBJECT_getIndex(objindex),CHAR_ISOVERED) ){ + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ\n"); + endObjectOne(objindex); + break; + } + notover= TRUE; + } + break; + case OBJTYPE_ITEM: + if( !ITEM_getInt( OBJECT_getIndex(objindex), ITEM_ISOVERED ) ) + notover= TRUE; + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + } + if( notover == TRUE ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKHITOBJECT; + }else{ + for( i = 0 ; i < objbufindex ; i ++ ){ + typedef void (*PREOFUNC)(int,int); + PREOFUNC pfunc=NULL; + int objindex=objbuf[i]; + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + pfunc = (PREOFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex), + CHAR_PREOVERFUNC); + break; + case OBJTYPE_ITEM: + pfunc = (PREOFUNC)ITEM_getFunctionPointer( + OBJECT_getIndex(objindex), + ITEM_PREOVERFUNC); +#ifdef _ALLBLUES_LUA_1_2 + if( !pfunc ){ + RunItemPreOverEvent(OBJECT_getIndex(objindex), charaindex ); + } +#endif + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + if( pfunc )pfunc( OBJECT_getIndex(objindex),charaindex ); + } + + CHAR_setInt(charaindex,CHAR_X,fx); + CHAR_setInt(charaindex,CHAR_Y,fy); + CHAR_setInt(charaindex,CHAR_FLOOR,ff); + CHAR_setInt(charaindex,CHAR_DIR,dir); + { + int objindex; + int ox,oy,of; + objindex = CHAR_getWorkInt( charaindex,CHAR_WORKOBJINDEX ); + of = OBJECT_setFloor(objindex, + CHAR_getInt(charaindex,CHAR_FLOOR)); + ox = OBJECT_setX(objindex,CHAR_getInt(charaindex,CHAR_X)); + oy = OBJECT_setY(objindex,CHAR_getInt(charaindex,CHAR_Y)); + if( !MAP_objmove( objindex, of,ox,oy,ff,fx,fy ) ){ + /* ئƷئ */ + // fprint( "ERROR MAP_OBJMOVE objindex=%d(%s)\n",objindex, CHAR_getUseName( charaindex ) ); + } + } + + CHAR_setInt(charaindex,CHAR_WALKCOUNT, + CHAR_getInt(charaindex,CHAR_WALKCOUNT) + 1 ); + + + for( i = 0 ; i < objbufindex ; i ++ ){ + typedef void (*POSTOFUNC)(int,int); + POSTOFUNC pfunc=NULL; + int objindex=objbuf[i]; + + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + pfunc = (POSTOFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex), + CHAR_POSTOVERFUNC); + break; + case OBJTYPE_ITEM: + pfunc = (POSTOFUNC)ITEM_getFunctionPointer( OBJECT_getIndex(objindex), ITEM_POSTOVERFUNC); +#ifdef _ALLBLUES_LUA_1_2 + if( !pfunc ){ + RunItemPostOverEvent(OBJECT_getIndex(objindex), charaindex ); + } +#endif + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + if( pfunc )pfunc( OBJECT_getIndex(objindex),charaindex ); + } + objbufindex = CHAR_getSameCoordinateObjects(objbuf, arraysizeof(objbuf), of, ox, oy ); + for( i=0 ;i 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORK_TOHELOS_COUNT, count -1); + if( count -1 == 0 ) { + CHAR_talkToCli( charaindex, -1, "ߵЧѵ", CHAR_COLORWHITE); + } + } + par = ENCOUNT_getEncountPercentMin( charaindex, of,ox,oy); + if( par != -1 ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN) != par ){ + flg = TRUE; + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN, par); + } + } + + par = ENCOUNT_getEncountPercentMax( charaindex, of,ox,oy); + if( par != -1 ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX) != par ){ + flg = TRUE; + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX, par); + } + } +#ifdef _ALLBLUES_LUA_1_9 +// if(WalkFunction( charaindex ) == FALSE) +#endif + { + int enfd = getfdFromCharaIndex( charaindex ); + int eqen = getEqNoenemy( enfd ); // Arminius 7.2: Ra's amulet + int noen = getNoenemy(enfd); + + // Arminius 7.31 cursed stone + if (getStayEncount(enfd)>0) { + clearStayEncount(enfd); + } + //print("\n enfd=%d,eqen=%d,noen=%d", enfd, eqen, noen); + + // Arminius 7.2 Ra's amulet + if (eqen>=200) { + noen=1; + } else if (eqen>=120) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)||(ff==500)) noen=1; + } else if (eqen>=80) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)) noen=1; + } else if (eqen>=40) { + if ((ff==100)||(ff==200)) noen=1; + } + + if (noen>0) { + if ((ff==8252)||(ff==8253)||(ff==8254)||(ff==8256)){ + noen=0; + } + } + //print("\n noen=%d", noen); + if (noen==0) { + int maxep = CHAR_getWorkInt(charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX); + int minep = CHAR_getWorkInt(charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN); + int cep = CONNECT_get_CEP(enfd); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + int temp=0; + int p_cep = CHAR_getWorkInt(charaindex, CHAR_ENCOUNT_FIX); + if( p_cep != 0 ){ + if( CHAR_getWorkInt( charaindex, CHAR_ENCOUNT_NUM) < (int)time(NULL) ){ + CHAR_talkToCli( charaindex, -1, "Чý", CHAR_COLORYELLOW); + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_FIX, 0); + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_NUM, 0); + } + temp = cep * (100 + p_cep ) / 100; + }else{ + temp = cep; + } +#endif + + if (cepmaxep) cep=maxep; + if (CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE)==BATTLE_CHARMODE_NONE) { + int entflag=1; + { + int objindex,index; + OBJECT obj; + for ( obj = MAP_getTopObj( ff, fx, fy); obj; obj = NEXT_OBJECT( obj)) { + objindex = GET_OBJINDEX( obj); + if (OBJECT_getType( objindex) == OBJTYPE_CHARA) { + int etype; + index = OBJECT_getIndex( objindex); + if (!CHAR_CHECKINDEX( index)) continue; + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPENPCENEMY && + CHAR_getWorkInt( index, CHAR_WORKEVENTTYPE) == CHAR_EVENT_ENEMY ) { + CHAR_setInt( charaindex, CHAR_X, ox); + CHAR_setInt( charaindex, CHAR_Y, oy); + lssproto_XYD_send( getfdFromCharaIndex(charaindex), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), + CHAR_getInt( charaindex, CHAR_DIR ) ); + break; + } + etype = CHAR_getWorkInt( index, CHAR_WORKEVENTTYPE); + if (etype!=CHAR_EVENT_NONE) { + if (etype==CHAR_EVENT_WARP) entflag=0; + } + } + } + } + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#ifdef _ENEMY_ACTION + if( rand()%(120*getEnemyAction()) < temp ) +#else + if( rand()%120 < temp ) +#endif +#else +#ifdef _ENEMY_ACTION + if( rand()%(120*getEnemyAction()) < cep ) +#else + if (rand()%120 0 ) { + int Rnum=0; + int RandEnemy = getEqRandenemy( enfd); + Rnum = RAND(0,100); + if( Rnum > RandEnemy ) { +#endif + //encounter!! + cep = minep; + lssproto_EN_recv(enfd, + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y)); +#ifdef _Item_MoonAct + } + }else{ + cep = minep; + lssproto_EN_recv(enfd, + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y)); + } +#endif + } + } else { + if (cep= CHAR_TYPELUANPC +#endif + ) { + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, -1 ); + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ + CHAR_sendCharaAtWalk( charaindex, of,ox,oy,CHAR_getDX(dir), CHAR_getDY(dir)); + } + { + int opt[2] = { ox, oy}; + CHAR_sendWatchEvent( CHAR_getWorkInt(charaindex, + CHAR_WORKOBJINDEX), + CHAR_ACTWALK,opt,2,TRUE ); + } + } + if( retvalue == CHAR_WALKSUCCESSED ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ + CHAR_sendCDCharaAtWalk( charaindex, of,ox,oy, + CHAR_getDX(dir), CHAR_getDY(dir)); + } + } + return retvalue; +} + +/*------------------------------------------------------------ + * ƽҷ»ʣ + * ¦ + * index int Charƥindex + * dir int + * mode int 0ئʣ1ئ  + * ߯Ի + * CHAR_WALKRET + ------------------------------------------------------------*/ +CHAR_WALKRET CHAR_walk( int index, int dir, int mode) +{ + CHAR_WALKRET ret; + BOOL (*prewalk)(int , int* , int* ); + void (*postwalk)(int); + if( !CHAR_CHECKINDEX( index ) )return CHAR_WALKSYSTEMERROR; + + if( CHAR_getFlg(index,CHAR_ISDIE) ) return CHAR_WALKDIE; + +#ifdef _MO_NO_WALK + if( CHAR_getInt(index,CHAR_NO_WALK) > 0 ) return CHAR_WALKSYSTEMERROR; +#endif + VALIDATEDIR(dir); + prewalk = (BOOL(*)(int,int*,int*)) + CHAR_getFunctionPointer(index, CHAR_WALKPREFUNC); + + if( prewalk != NULL ) + if( prewalk(index,&dir,&mode) == FALSE ) { + return CHAR_WALKPREWALK; + } + + if( mode == 0 ) + ret = CHAR_walk_move( index, dir ); + else + ret = CHAR_walk_turn( index, dir ); + postwalk = (void(*)(int)) + CHAR_getFunctionPointer(index,CHAR_WALKPOSTFUNC); + + if( postwalk != NULL ) + postwalk(index); + return ret; +} + +#ifdef _MO_LNS_NLGSUOXU +CHAR_WALKRET CHAR_walk_jjc( int index, int floor, int ox, int oy, int dir) +{ + CHAR_WALKRET ret; + int mode; + BOOL (*prewalk)(int , int* , int* ); + void (*postwalk)(int); + if( !CHAR_CHECKINDEX( index ) )return CHAR_WALKSYSTEMERROR; + + if( CHAR_getFlg(index,CHAR_ISDIE) ) return CHAR_WALKDIE; + + VALIDATEDIR(dir); + prewalk = (BOOL(*)(int,int*,int*)) + CHAR_getFunctionPointer(index, CHAR_WALKPREFUNC); + + if( prewalk != NULL ) + if( prewalk(index,&dir,&mode) == FALSE ) { + return CHAR_WALKPREWALK; + } + + ret = CHAR_walk_jc( index, floor, ox, oy, dir ); + + postwalk = (void(*)(int)) + CHAR_getFunctionPointer(index,CHAR_WALKPOSTFUNC); + + if( postwalk != NULL ) + postwalk(index); + + return ret; +} +#endif + +/*------------------------------------------------------------ + * ھ + * ¦ + * index int ƽҷ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_walkcall( int index ) +{ + char tmp[128]; + int dir,mode; + int ret; + POINT start,end,end1; + + if( !CHAR_CHECKINDEX( index ) ) return; + + strcpysafe( tmp ,sizeof(tmp), + CHAR_getWorkChar(index,CHAR_WORKWALKARRAY)); + + CHAR_ctodirmode( tmp[0], &dir ,&mode ); + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) { + end.x = CHAR_getInt( index, CHAR_X); + end.y = CHAR_getInt( index, CHAR_Y); + } + } + + ret = CHAR_walk( index , dir ,mode ); + + if( mode == 0 && ret == CHAR_WALKSUCCESSED ) { + /* лئëھ */ + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_LEADER ) { + int i; + for( i = 1; i < getPartyNum(index); i ++ ) { + int toindex = CHAR_getWorkInt( index, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + start.x = CHAR_getInt( toindex, CHAR_X); + start.y = CHAR_getInt( toindex, CHAR_Y); + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + /* ·ūë ¿б + * ݼҷ󡼰Ҽ ëܰ + */ + end = start; + if( parent_dir != -1 ) { + CHAR_walk( toindex, parent_dir, 0); +#ifdef _PETFOLLOW_NEW_ + end1 = start; + int flg=FALSE; + int petnum; + petnum=0; + for(;petnum<5;petnum++) + if( CHAR_getWorkInt( toindex, CHAR_WORKPETFOLLOW+petnum) != -1 ) { + int petindex = CHAR_getWorkInt( toindex, CHAR_WORKPETFOLLOW+petnum); + if( CHAR_CHECKINDEX(petindex) ) { + int parent_dir; + start.x = CHAR_getInt( petindex, CHAR_X); + start.y = CHAR_getInt( petindex, CHAR_Y); + if(!flg){ + flg=TRUE; + if( end1.x > start.x ) end1.x --; + else if( end1.x < start.x ) end1.x ++; + if( end1.y > start.y ) end1.y --; + else if( end1.y < start.y ) end1.y ++; + } + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end1 ); + end1 = start; + if( parent_dir != -1 ) { + if( CHAR_walk( petindex, parent_dir, 0) == CHAR_WALKSUCCESSED ) + { + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, + 1 + CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) ); + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 1000 ){ + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_pickupFollowPet( toindex, petindex ); + } + + } + } + }else { + CHAR_setWorkInt( toindex, CHAR_WORKPETFOLLOW+petnum, -1); + } + + } +#else + + // Robin 0702 petFollow + if( CHAR_getWorkInt( toindex, CHAR_WORKPETFOLLOW) != -1 ) { + int petindex = CHAR_getWorkInt( toindex, CHAR_WORKPETFOLLOW); + if( CHAR_CHECKINDEX(petindex) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + end.x = CHAR_getInt( toindex, CHAR_X); + end.y = CHAR_getInt( toindex, CHAR_Y); + start.x = CHAR_getInt( petindex, CHAR_X); + start.y = CHAR_getInt( petindex, CHAR_Y); + + if( end.x > start.x ) end.x --; + else if( end.x < start.x ) end.x ++; + if( end.y > start.y ) end.y --; + else if( end.y < start.y ) end.y ++; + + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + if( parent_dir != -1 ) { + if( CHAR_walk( petindex, parent_dir, 0) == CHAR_WALKSUCCESSED ) + { + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, + 1 + CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) ); + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 1000 ){ + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_pickupFollowPet( toindex, petindex ); + } + + } + } + }else { + CHAR_setWorkInt( toindex, CHAR_WORKPETFOLLOW, -1); + } + + } +#endif + } + } + else { + /* ئ */ + CHAR_setWorkInt( index, i+CHAR_WORKPARTYINDEX1, -1); + } + } + } +#ifdef _PETFOLLOW_NEW_ + int petnum,petindex; + int flg=FALSE; + end.x = CHAR_getInt( index, CHAR_X); + end.y = CHAR_getInt( index, CHAR_Y); + for(petnum=0;petnum<5;petnum++){ + petindex = CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW+petnum); + if(CHAR_CHECKINDEX(petindex)){ + int parent_dir; + start.x = CHAR_getInt( petindex, CHAR_X); + start.y = CHAR_getInt( petindex, CHAR_Y); + if(!flg){ + flg=TRUE; + if( end.x > start.x ) end.x --; + else if( end.x < start.x ) end.x ++; + if( end.y > start.y ) end.y --; + else if( end.y < start.y ) end.y ++; + } + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + end = start; + if( parent_dir != -1 ) { + if( CHAR_walk( petindex, parent_dir, 0) == CHAR_WALKSUCCESSED ){ + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, + 1 + CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) ); +#ifdef _SYSTEM_SPEAD + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 200 ) +#else + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 1000 ) +#endif + { + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_pickupFollowPet( index, petindex ); + } + } + } + }else{ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW+petnum, -1); + } + } +#else + if( CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW) != -1 ) { + int petindex = CHAR_getWorkInt( index, CHAR_WORKPETFOLLOW); + if( CHAR_CHECKINDEX(petindex) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + end.x = CHAR_getInt( index, CHAR_X); + end.y = CHAR_getInt( index, CHAR_Y); + start.x = CHAR_getInt( petindex, CHAR_X); + start.y = CHAR_getInt( petindex, CHAR_Y); + + if( end.x > start.x ) end.x --; + else if( end.x < start.x ) end.x ++; + if( end.y > start.y ) end.y --; + else if( end.y < start.y ) end.y ++; + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + if( parent_dir != -1 ) { + if( CHAR_walk( petindex, parent_dir, 0) == CHAR_WALKSUCCESSED ) + { + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, + 1 + CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) ); +#ifdef _SYSTEM_SPEAD + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 200 ) +#else + if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT) > 1000 ) +#endif + { + /* + CHAR_setInt( petindex, CHAR_VARIABLEAI, + 200 + CHAR_getInt( petindex, CHAR_VARIABLEAI) ); + */ + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_pickupFollowPet( index, petindex ); + } + } + } + } + else { + /* ئ */ + CHAR_setWorkInt( index, CHAR_WORKPETFOLLOW, -1); + } + } +#endif + } + } + + /* 99/03/09 By Kawata */ + /* walkWALKARRAYʧľؤ¼ƥ + * Ի ƻ + */ + strcpysafe( tmp ,sizeof(tmp), + CHAR_getWorkChar(index,CHAR_WORKWALKARRAY)); + if( strlen( tmp) > 0 ) { + CHAR_setWorkChar(index,CHAR_WORKWALKARRAY,&tmp[1]); + } + + /* ë׻ */ + CHAR_setWorkInt( index, CHAR_WORKWALKSTARTSEC , NowTime.tv_sec ); + CHAR_setWorkInt( index, CHAR_WORKWALKSTARTMSEC , NowTime.tv_usec ); +} + + + +/*------------------------------------------------------------ + * 炙ë £ + * ¦ + * index int ƽҷ ƥ̼͵ + * dir char* ٯ + * id int ID + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_walk_start(int index, int x, int y, char* dir, BOOL mapsendmode ) +{ + + if( !CHAR_CHECKINDEX( index ) )return; + + // Nuke 08/27: Stop wap + /* + { + int ox, oy; + const int seesiz = MAP_CHAR_DEFAULTSEESIZ; + ox = CHAR_getInt(index,CHAR_X); + oy = CHAR_getInt(index,CHAR_Y); + if ( ABS(x - ox) > seesiz || ABS(y - oy) > seesiz ) { + CHAR_talkToCli(index, -1, "ߡ", CHAR_COLORYELLOW); + CONNECT_setCloseRequest_debug(getfdFromCharaIndex(index) , 1); + return; + } + } + */ + + + + if( CHAR_getFlg( index,CHAR_ISDIE ) )return; + CHAR_setWorkChar( index,CHAR_WORKWALKARRAY, dir ); + CHAR_setWorkInt( index, CHAR_WORKWALKSTARTSEC , NowTime.tv_sec ); + CHAR_setWorkInt( index, CHAR_WORKWALKSTARTMSEC , NowTime.tv_usec ); + + CHAR_setMyPosition( index, x, y, FALSE); + if( mapsendmode ) { + int ox,oy; + char buf[64]; + int len; + int i; + strcpysafe( buf, sizeof(buf), + CHAR_getWorkChar( index, CHAR_WORKWALKARRAY)); + + len = strlen( buf ); + ox = CHAR_getInt(index,CHAR_X); + oy = CHAR_getInt(index,CHAR_Y); + + for( i = 0; i < len; i ++ ) { + int dir,mode; + int fx,fy; + CHAR_ctodirmode( buf[i], &dir ,&mode ); + if( mode == 0 ) { + CHAR_getCoordinationDir( dir,ox,oy,1,&fx,&fy); + ox = fx; + oy = fy; + } + } +#ifdef _MO_MAP_AUTO_UPDATE + CHAR_sendMapAtWalk(index, + CHAR_getInt( index, CHAR_FLOOR), + CHAR_getInt( index, CHAR_X), + CHAR_getInt( index, CHAR_Y), + ox,oy); + +#endif + } + + if( strlen( dir ) >= 1 ) CHAR_walkcall( index ); +} +/*------------------------------------------------------------ + * 弰 + * ¦ + * index int ƽҷ ƥ̼͵ + * dir char* ٯ + * id int ID + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void CHAR_walk_init( int fd, int x, int y, char *direction, BOOL mapsendmode) +{ + if( strlen( direction) > 32) { + print( "walkarray length over\n"); + return; + } + + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + return ; + } + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKPARTYMODE ) != CHAR_PARTY_CLIENT ){ + CHAR_walk_start( CONNECT_getCharaindex(fd), x, y, direction, mapsendmode ); + }else { + int dir, mode; + CHAR_ctodirmode( direction[0], &dir ,&mode ); + if( mode == 0 ) { + print( "ҲҲǵҡ\n"); + }else { + CHAR_walk_start( CONNECT_getCharaindex(fd), + x,y,direction, FALSE ); + } + } +} + +void CHAR_sendCharaAtWalk( int charaindex, int of,int ox,int oy,int xflg, int yflg ) +{ + int fd = -1; + int i,j,fl, x, y; + char introduction[512]; + char c_msg[1024*64]; + int strpos = 0; + int seesiz = CHAR_DEFAULTSEESIZ/2; + char cabuf[128]; + char myintroduction[1024*4]; + int whichtype; + + whichtype = CHAR_getInt( charaindex, CHAR_WHICHTYPE); + if( whichtype == CHAR_TYPEPLAYER) { + fd = getfdFromCharaIndex( charaindex ); + if( fd == -1 )return; + } + if( xflg > 1 || xflg < -1 ) { + print( "%s:%d: arg err[xflg]\n",__FILE__, __LINE__); + return; + } + if( yflg > 1 || yflg < -1 ) { + print( "%s:%d: arg err[yflg]\n",__FILE__, __LINE__); + return; + } + fl = CHAR_getInt( charaindex, CHAR_FLOOR); + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); + + if( of != fl || ABS(x - ox) > seesiz/2 || ABS(y - oy) > seesiz/2 ) + return; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) { + return; + } + c_msg[0] = '\0'; +#ifndef _NPC_EVENT_NOTICE + if( !CHAR_makeObjectCString( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), myintroduction, sizeof( myintroduction))){ + myintroduction[0] = '\0'; + } +#endif + if( xflg != 0) { + i = x + seesiz * xflg; + for( j = y-seesiz ; j <= y+seesiz ;j ++ ) { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; object ; object = NEXT_OBJECT(object ) ){ + int introlen; + int objindex = GET_OBJINDEX(object); + int c_index = OBJECT_getIndex( objindex); + + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE) ){ + continue; + } + if( strlen( myintroduction) != 0 ) { + if( OBJECT_getType( objindex) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + int tofd = getfdFromCharaIndex( c_index ); + if(tofd != -1){ + CDsend( tofd); +#ifdef _NPC_EVENT_NOTICE + if( !CHAR_makeObjectCStringNew( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX),c_index, myintroduction, sizeof( myintroduction))){ + myintroduction[0] = '\0'; + } +#endif + lssproto_C_send( tofd, myintroduction); + } + } + } + } + if( whichtype == CHAR_TYPEPLAYER) { + /* Make C*/ +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( objindex, charaindex,introduction, sizeof( introduction))){ +#else + if( CHAR_makeObjectCString( objindex, introduction, sizeof( introduction))){ +#endif + introlen = strlen( introduction); + introduction[introlen] = ','; + introduction[introlen+1] = '\0'; + strcpysafe( &c_msg[strpos], sizeof( c_msg) - strpos, introduction); + strpos += strlen( introduction); + } + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTLEADER,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + if( (CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ) && CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + int tofd = getfdFromCharaIndex( c_index ); + if( tofd != -1 ) { + if( CHAR_makeCAOPT1String( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + cabuf, sizeof( cabuf), CHAR_ACTLEADER,1 )){ + CONNECT_appendCAbuf( tofd,cabuf,strlen(cabuf)); + } + } + } + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + if( CHAR_getWorkInt( c_index, CHAR_WORKBATTLEWATCH) == TRUE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTBATTLEWATCH, 1)){ + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + } + }else { + int battleno = CHAR_getWorkInt( c_index, CHAR_WORKBATTLEINDEX); + int sideno = CHAR_getWorkInt( c_index,CHAR_WORKBATTLESIDE); + int helpno; + if( !BATTLE_CHECKINDEX( battleno) ) { + //print(" %s[%d]: BATTLE_CHECKINDEX( %d) err!!\n", __FILE__, __LINE__, battleno); + }else { + helpno = (BattleArray[ battleno].Side[ sideno].flg & BSIDE_FLG_HELP_OK) ? TRUE:FALSE; + /* HelpNo = 1 */ + if( CHAR_makeCAOPT3String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTBATTLE, battleno,sideno,helpno )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + } + if( ( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER || + CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) && + CHAR_getWorkInt( c_index, CHAR_WORKACTION ) != -1 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#ifdef _ADD_ACTION + else if( CHAR_getWorkInt( c_index, CHAR_WORKACTION ) > 0 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _STREET_VENDOR + if(CHAR_getInt(c_index,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + CHAR_getWorkInt(c_index,CHAR_WORKSTREETVENDOR) == 1 && + CHAR_getWorkInt(c_index,CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(CHAR_makeCAOPTString(objindex,cabuf,sizeof(cabuf), + CHAR_STREETVENDOR_OPEN,CHAR_getWorkChar(c_index,CHAR_STREETVENDOR_NAME))){ + CONNECT_appendCAbuf(fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _ANGEL_SUMMON + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKANGELMODE ) == TRUE ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_ACTANGEL,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_MIND, CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _FAMILYBADGE_ + extern int getFamilyBadge(int index); + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge( OBJECT_getIndex( objindex))){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_FAMILYBADGE, getFamilyBadge( OBJECT_getIndex( objindex)))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + } + } + } + } + } + if( yflg != 0) { + j = y + seesiz * yflg; + for( i = x-seesiz ; i <= x+seesiz ;i ++ ) { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; object ; object = NEXT_OBJECT(object ) ){ + int introlen; + int objindex = GET_OBJINDEX(object); + int c_index = OBJECT_getIndex( objindex); + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && + !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE) ){ + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ"); + endObjectOne(objindex); + } + continue; + } + if( strlen( myintroduction) != 0 ) { + if( OBJECT_getType( objindex) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + int tofd = getfdFromCharaIndex( c_index ); + if(tofd != -1){ + CDsend( tofd); + lssproto_C_send( tofd, myintroduction); + } + } + } + } + if( whichtype == CHAR_TYPEPLAYER ) { + /* Make C*/ +#ifdef _NPC_EVENT_NOTICE + if( CHAR_makeObjectCStringNew( objindex, charaindex,introduction, sizeof( introduction))){ +#else + if( CHAR_makeObjectCString( objindex, introduction, sizeof( introduction))){ +#endif + introlen = strlen( introduction); + introduction[introlen] = ','; + introduction[introlen+1] = '\0'; + strcpysafe( &c_msg[strpos], sizeof( c_msg) - strpos, introduction); + strpos += strlen( introduction); + } + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTLEADER,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + if( (CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + ) && CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE)== BATTLE_CHARMODE_NONE){ + int tofd = getfdFromCharaIndex( c_index ); + if( tofd != -1 ) { + if( CHAR_makeCAOPT1String( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + cabuf, sizeof( cabuf), CHAR_ACTLEADER,1 )){ + CONNECT_appendCAbuf( tofd,cabuf,strlen(cabuf)); + } + } + } + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + if( CHAR_getWorkInt( c_index, CHAR_WORKBATTLEWATCH) == TRUE ) { + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTBATTLEWATCH,1)){ + CONNECT_appendCAbuf( fd, cabuf, strlen( cabuf)); + } + }else { + int battleno = CHAR_getWorkInt( c_index, CHAR_WORKBATTLEINDEX); + int sideno = CHAR_getWorkInt( c_index, CHAR_WORKBATTLESIDE); + int helpno = (BattleArray[CHAR_getWorkInt( c_index, + CHAR_WORKBATTLEINDEX)].Side[ + CHAR_getWorkInt( c_index, + CHAR_WORKBATTLESIDE)].flg & BSIDE_FLG_HELP_OK) ? TRUE:FALSE; + + if( CHAR_makeCAOPT3String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTBATTLE, battleno,sideno,helpno )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } + } + if( ( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER || + CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) && + CHAR_getWorkInt( c_index, CHAR_WORKACTION ) != -1 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#ifdef _ADD_ACTION + else if( CHAR_getWorkInt( c_index, CHAR_WORKACTION ) > 0 ) { + if( CHAR_makeCADefaultString( objindex, cabuf, sizeof( cabuf), + CHAR_getWorkInt( c_index, CHAR_WORKACTION))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _STREET_VENDOR + if(CHAR_getInt(c_index,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + CHAR_getWorkInt(c_index,CHAR_WORKSTREETVENDOR) == 1 && + CHAR_getWorkInt(c_index,CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(CHAR_makeCAOPTString(objindex,cabuf,sizeof(cabuf), + CHAR_STREETVENDOR_OPEN,CHAR_getWorkChar(c_index,CHAR_STREETVENDOR_NAME))){ + CONNECT_appendCAbuf(fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _ANGEL_SUMMON + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_WORKANGELMODE ) == TRUE ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), + CHAR_ACTANGEL,1 )){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( c_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_MIND, CHAR_getWorkInt( c_index, CHAR_PLAYER_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 44, CHAR_getWorkInt( OBJECT_getIndex( objindex), CHAR_PLAYER_EFFECT_MANOR ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 46, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TRUMP_EFFECT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ) > 0 ){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), 45, CHAR_getInt( OBJECT_getIndex( objindex), CHAR_TITLE_DEFAULT ))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + + + +#ifdef _FAMILYBADGE_ + extern int getFamilyBadge(int index); + if( CHAR_getInt( OBJECT_getIndex( objindex), CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + getFamilyBadge(OBJECT_getIndex( objindex))){ + if( CHAR_makeCAOPT1String( objindex, cabuf, sizeof( cabuf), CHAR_FAMILYBADGE, getFamilyBadge(OBJECT_getIndex( objindex)))){ + CONNECT_appendCAbuf( fd,cabuf,strlen(cabuf)); + } + } +#endif + + } + } + } + } + } + dchop( c_msg, "," ); + if( strlen( c_msg) != 0 ) { + CDflush( charaindex); + lssproto_C_send( fd, c_msg); + } +} + +static void CHAR_sendCDCharaAtWalk( int charaindex, int of, int ox, int oy, int xflg, int yflg ){ + int i,j,fl, x, y; + int seesiz = CHAR_DEFAULTSEESIZ/2; + int fd, tofd; + if( xflg > 1 || xflg < -1 ) { + print( "%s:%d: arg err[xflg]\n",__FILE__, __LINE__); + return; + } + if( yflg > 1 || yflg < -1 ) { + print( "%s:%d: arg err[yflg]\n",__FILE__, __LINE__); + return; + } + fl = CHAR_getInt( charaindex, CHAR_FLOOR); + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); + + if( of != fl || /* ׷ʧਵ */ + ABS(x - ox) > seesiz/2 || /* */ + ABS(y - oy) > seesiz/2 ) /* */ + return; + + fd = getfdFromCharaIndex( charaindex ); + if( xflg != 0) { + i = x + (seesiz * xflg + xflg)*-1; + for( j = y-seesiz +(yflg*-1) ; j <= y+seesiz +(yflg*-1) ;j ++ ) { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int objindex = GET_OBJINDEX(object); + char buf[64]; + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && + !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE) ){ + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ"); + endObjectOne(objindex); + } + continue; + } + if( fd != -1) { + cnv10to62( objindex, buf, sizeof( buf)); + CONNECT_appendCDbuf( fd, buf, strlen( buf)); + } + if( OBJECT_getType( objindex) == OBJTYPE_CHARA) { + int tocharaindex = OBJECT_getIndex( objindex); + if( CHAR_getInt( tocharaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE ) { + tofd = getfdFromCharaIndex( tocharaindex ); + if( tofd != -1 ) { + cnv10to62( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), + buf, sizeof( buf)); + CONNECT_appendCDbuf( tofd, buf, strlen( buf)); + CAsend( tofd); + CDsend( tofd); + } + } + } + } + } + } + } + if( yflg != 0) { + j = y + (seesiz * yflg + yflg)*-1; + for( i = x-seesiz + (xflg*-1) ; i <= x+seesiz + (xflg*-1) ;i ++ ) { + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; object ; object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + char buf[64]; + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && + !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE) ){ + continue; + } + if( fd != -1 ) { + cnv10to62( objindex, buf, sizeof( buf)); + CONNECT_appendCDbuf( fd, buf, strlen( buf)); + } + if( OBJECT_getType( objindex) == OBJTYPE_CHARA) { + int tocharaindex = OBJECT_getIndex( objindex); + if( CHAR_getInt( tocharaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ + tofd = getfdFromCharaIndex( tocharaindex ); + if( tofd != -1 ) { + cnv10to62( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX), buf, sizeof( buf)); + CONNECT_appendCDbuf( tofd, buf, strlen( buf)); + CAsend( tofd); + CDsend( tofd); + } + } + } + } + } + } + } + if( fd != -1) { + CDsend( fd); + } +} + +void CHAR_ctodirmode(char moji , int* dir , int* mode) +{ + *mode = 1; + if( 'a' <= moji && moji <= 'h' )*mode = 0; + + *dir = tolower(moji) - 'a'; +} +#ifdef _MO_LNS_NLGSUOXU +CHAR_WALKRET CHAR_walk_jc( int charaindex, int of, int ox, int oy, int dir ) +{ + int i; + int fx,fy,ff; + int objbuf[128]; + int objbufindex=0; + int notover=FALSE; + int retvalue=CHAR_WALKSUCCESSED; + + if( !CHAR_CHECKINDEX( charaindex )) return CHAR_WALKSYSTEMERROR; + + CHAR_getCoordinationDir( dir,ox,oy,1,&fx,&fy); + ff = of; + + if( CHAR_getInt( charaindex,CHAR_WHICHTYPE ) == CHAR_TYPEENEMY ){ + RECT walkr; + POINT nextp; + int npccreateindex; + npccreateindex = CHAR_getInt( charaindex,CHAR_NPCCREATEINDEX ); + if( CHAR_isInvincibleArea( ff,fx,fy)) { + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKEXTEND; + return retvalue; + } + if( NPC_isBoundarySet( npccreateindex ) && + NPC_createGetRECT( npccreateindex,&walkr ) == TRUE ) + { + nextp.x = fx; + nextp.y = fy; + if( PointInRect( &walkr,&nextp ) == FALSE ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKEXTEND; + return retvalue; + } + }else{ + ; + } + } + + + if( CHAR_getFlg( charaindex, CHAR_ISBIG ) == 1 ){ + static POINT offset[5]={ + { 0,-1}, + {-1, 0}, + { 0, 0}, + { 1, 0}, + { 0, 1}, + }; + int k; + for( k=0 ; k<5; k++ ){ + if( !MAP_walkAble( charaindex, ff, fx+offset[k].x, + fy+offset[k].y )){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + return retvalue; + } + } + + }else{ + if( CHAR_getDX(dir)*CHAR_getDY(dir) == 0 ){ + if( !MAP_walkAble( charaindex,ff, fx, fy ) ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + return retvalue; + } + }else{ + int xflg,yflg; + if( !MAP_walkAble( charaindex,ff, fx, fy ) ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + return retvalue; + } + + xflg = MAP_walkAble( charaindex,of, ox+CHAR_getDX(dir), oy ); + yflg = MAP_walkAble( charaindex,of, ox, oy+CHAR_getDY(dir) ); + + if( !xflg || !yflg ) { + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALK1357; + return retvalue; + } + } + } + objbufindex = CHAR_getSameCoordinateObjects( objbuf, arraysizeof( objbuf ), ff,fx,fy ); + for( i = 0 ; i < objbufindex ; i ++ ){ + int objindex= objbuf[i]; + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + if( !CHAR_getFlg( OBJECT_getIndex(objindex),CHAR_ISOVERED) ){ + if(!CHAR_CHECKINDEX(OBJECT_getIndex(objindex))){ + printf("Զɾһ"); + endObjectOne(objindex); + break; + } + notover= TRUE; + } + break; + case OBJTYPE_ITEM: + if( !ITEM_getInt( OBJECT_getIndex(objindex), ITEM_ISOVERED ) ) + notover= TRUE; + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + } + if( notover == TRUE ){ + CHAR_setInt(charaindex,CHAR_DIR,dir); + retvalue = CHAR_WALKHITOBJECT; + return retvalue; + }else{ + for( i = 0 ; i < objbufindex ; i ++ ){ + typedef void (*PREOFUNC)(int,int); + PREOFUNC pfunc=NULL; + int objindex=objbuf[i]; + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + pfunc = (PREOFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex), + CHAR_PREOVERFUNC); + break; + case OBJTYPE_ITEM: + pfunc = (PREOFUNC)ITEM_getFunctionPointer( + OBJECT_getIndex(objindex), + ITEM_PREOVERFUNC); + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + if( pfunc )pfunc( OBJECT_getIndex(objindex),charaindex ); + } + + CHAR_setInt(charaindex,CHAR_X,fx); + CHAR_setInt(charaindex,CHAR_Y,fy); + CHAR_setInt(charaindex,CHAR_FLOOR,ff); + CHAR_setInt(charaindex,CHAR_DIR,dir); + + { + int objindex; + int ox,oy,of; + objindex = CHAR_getWorkInt( charaindex,CHAR_WORKOBJINDEX ); + of = OBJECT_setFloor(objindex, + CHAR_getInt(charaindex,CHAR_FLOOR)); + ox = OBJECT_setX(objindex,CHAR_getInt(charaindex,CHAR_X)); + oy = OBJECT_setY(objindex,CHAR_getInt(charaindex,CHAR_Y)); + if( !MAP_objmove( objindex, of,ox,oy,ff,fx,fy ) ){ + /* ئƷئ */ + fprint( "ERROR MAP_OBJMOVE objindex=%d(%s)\n",objindex, + CHAR_getUseName( charaindex ) ); + } + } + + CHAR_setInt(charaindex,CHAR_WALKCOUNT, + CHAR_getInt(charaindex,CHAR_WALKCOUNT) + 1 ); + + + for( i = 0 ; i < objbufindex ; i ++ ){ + typedef void (*POSTOFUNC)(int,int); + POSTOFUNC pfunc=NULL; + int objindex=objbuf[i]; + + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_CHARA: + pfunc = (POSTOFUNC)CHAR_getFunctionPointer( + OBJECT_getIndex(objindex), + CHAR_POSTOVERFUNC); + break; + case OBJTYPE_ITEM: + pfunc = (POSTOFUNC)ITEM_getFunctionPointer( OBJECT_getIndex(objindex), ITEM_POSTOVERFUNC); + break; + case OBJTYPE_GOLD: + break; + default: + break; + } + if( pfunc )pfunc( OBJECT_getIndex(objindex),charaindex ); + } + objbufindex = CHAR_getSameCoordinateObjects(objbuf, arraysizeof(objbuf), of, ox, oy ); + for( i=0 ;i 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORK_TOHELOS_COUNT, count -1); + if( count -1 == 0 ) { + //CHAR_talkToCli( charaindex, -1, "ߵЧѵ", CHAR_COLORWHITE); + } + } + par = ENCOUNT_getEncountPercentMin( charaindex, of,ox,oy); + if( par != -1 ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN) != par ){ + flg = TRUE; + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN, par); + } + } + + par = ENCOUNT_getEncountPercentMax( charaindex, of,ox,oy); + if( par != -1 ) { + if( CHAR_getWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX) != par ){ + flg = TRUE; + CHAR_setWorkInt( charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX, par); + } + } + // Arminius 7.12 login announce + /* + { + int enfd = getfdFromCharaIndex( charaindex ); + if (CONNECT_get_announced(enfd)==0) { + // Robin 0720 + //AnnounceToPlayer(charaindex); + AnnounceToPlayerWN( enfd ); + CONNECT_set_announced(enfd,1); + } + } + */ + // Arminius 6.22 check Encounter + // Nuke 0622: Provide No Enemy function + { + int enfd = getfdFromCharaIndex( charaindex ); + int eqen = getEqNoenemy( enfd ); // Arminius 7.2: Ra's amulet + int noen = getNoenemy(enfd); + + // Arminius 7.31 cursed stone + if (getStayEncount(enfd)>0) { + clearStayEncount(enfd); + } + //print("\n enfd=%d,eqen=%d,noen=%d", enfd, eqen, noen); + + // Arminius 7.2 Ra's amulet + if (eqen>=200) { + noen=1; + } else if (eqen>=120) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)||(ff==500)) noen=1; + } else if (eqen>=80) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)) noen=1; + } else if (eqen>=40) { + if ((ff==100)||(ff==200)) noen=1; + } + + + //print("\n noen=%d", noen); + if (noen==0) { + int maxep = CHAR_getWorkInt(charaindex, CHAR_WORKENCOUNTPROBABILITY_MAX); + int minep = CHAR_getWorkInt(charaindex, CHAR_WORKENCOUNTPROBABILITY_MIN); + int cep = CONNECT_get_CEP(enfd); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + int temp=0; + int p_cep = CHAR_getWorkInt(charaindex, CHAR_ENCOUNT_FIX); + if( p_cep != 0 ){ + if( CHAR_getWorkInt( charaindex, CHAR_ENCOUNT_NUM) < (int)time(NULL) ){ + CHAR_talkToCli( charaindex, -1, "Чý", CHAR_COLORYELLOW); + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_FIX, 0); + CHAR_setWorkInt( charaindex, CHAR_ENCOUNT_NUM, 0); + } + temp = cep * (100 + p_cep ) / 100; + }else{ + temp = cep; + } +#endif + + if (cepmaxep) cep=maxep; + if (CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE)==BATTLE_CHARMODE_NONE) { + int entflag=1; + { + int objindex,index; + OBJECT obj; + for ( obj = MAP_getTopObj( ff, fx, fy); obj; obj = NEXT_OBJECT( obj)) { + objindex = GET_OBJINDEX( obj); + if (OBJECT_getType( objindex) == OBJTYPE_CHARA) { + int etype; + index = OBJECT_getIndex( objindex); + if (!CHAR_CHECKINDEX( index)) continue; + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPENPCENEMY && + CHAR_getWorkInt( index, CHAR_WORKEVENTTYPE) == CHAR_EVENT_ENEMY ) { + CHAR_setInt( charaindex, CHAR_X, ox); + CHAR_setInt( charaindex, CHAR_Y, oy); + lssproto_XYD_send( getfdFromCharaIndex(charaindex), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), + CHAR_getInt( charaindex, CHAR_DIR ) ); + break; + } + etype = CHAR_getWorkInt( index, CHAR_WORKEVENTTYPE); + if (etype!=CHAR_EVENT_NONE) { + if (etype==CHAR_EVENT_WARP) entflag=0; + } + } + } + } + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#ifdef _ENEMY_ACTION + if( rand()%(120*getEnemyAction()) < temp ){ +#else + if( rand()%120 < temp ){ +#endif +#else +#ifdef _ENEMY_ACTION + if( rand()%(120*getEnemyAction()) < cep ){ +#else + if (rand()%120 0 ) { + int Rnum=0; + int RandEnemy = getEqRandenemy( enfd); + Rnum = RAND(0,100); + if( Rnum > RandEnemy ) { +#endif + //encounter!! + cep = minep; + lssproto_EN_recv(enfd, + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y)); +#ifdef _Item_MoonAct + } + }else{ + cep = minep; + lssproto_EN_recv(enfd, + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y)); + } +#endif + } + } else { + if (cep +#include +#include +#include +#include +#include +#include +#include "common.h" +#include "char.h" +#include "util.h" +#include "buf.h" +#include "npcutil.h" +#include "char_base.h" +#include "object.h" +#include "char_data.h" +#include "handletime.h" +#include "chatmagic.h" +#include "configfile.h" +#include "readmap.h" +#include "map_deal.h" +#include "lssproto_serv.h" +#include "log.h" +#include "battle.h" +#include "pet.h" +#include "enemy.h" +#include "encount.h" +#include "magic_base.h" +#include "magic.h" +#include "pet_skill.h" +#include "pet_event.h" +#include "item_gen.h" +#include "mclient.h" +#include "npc_eventaction.h" +#include "map_warppoint.h" +#include "npc_manorsman.h" +#include "net.h" +#include "saacproto_cli.h" +#include "npc_scheduleman.h" +#include "trade.h" +#include "npccreate.h" +#include "npc_transmigration.h" +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#include "profession_skill.h" +#endif +#include "char_talk.h" +#ifdef _PLAYER_QUESTION_ONLIEN +#include "longzoro/playerquestion.h" +#endif +#ifdef _NPC_MAGICCARD +#include "npc_magiccard.h" +#endif +// WON ADD 峤 +#include "family.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#include "petmail.h" + +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/ablua.h" +#endif +// WON ADD ¶ȡITEMSET.TXT +#include "item.h" +#ifdef _MO_RELOAD_NPC +#include "readnpc.h" +#endif +#include "longzoro/sasql.h" + +extern tagRidePetTable ridePetTable[296]; +extern int *pWorkAttackPower; +extern time_t initTime; +int *pWorkAttackPower = NULL; + +struct GMINFO gminfo[GMMAXNUM]; + + +void CHAR_CHAT_DEBUG_warp( int charindex , char *message ) +{ + char token[100]; + int fl,x,y; + easyGetTokenFromString( message , 1 , token, sizeof(token)); + fl = atoi( token ); + easyGetTokenFromString( message , 2 , token , sizeof(token)); + x = atoi( token ); + easyGetTokenFromString( message , 3 , token , sizeof(token)); + y = atoi( token ); + + CHAR_warpToSpecificPoint(charindex, fl, x, y); + +} + + +void CHAR_CHAT_DEBUG_hp( int charindex , char *message ) +{ + CHAR_setInt( charindex , CHAR_HP,atoi( message ) ); + CHAR_complianceParameter( charindex ); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_HP); +} + +void CHAR_CHAT_DEBUG_setmp( int charindex , char *message ) +{ + int i; + char setmp[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , setmp, sizeof(setmp)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_MAXMP, atoi( setmp ) ); + CHAR_setInt( i , CHAR_MP, atoi( setmp ) ); + CHAR_complianceParameter( i ); + CHAR_send_P_StatusString( i , CHAR_P_STRING_MP); + sprintf( token, "[GM]%sMPΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(setmp)/100); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sMPΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(setmp)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_MAXMP, atoi( setmp ) ); + CHAR_setInt( charindex , CHAR_MP, atoi( setmp ) ); + CHAR_complianceParameter( charindex ); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_MP); + sprintf( token, "MPΪ%d!",(int)atoi(setmp)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_mp( int charindex , char *message ) +{ + int Mymp; + CHAR_setInt( charindex , CHAR_MP, atoi( message ) ); + Mymp = CHAR_getWorkInt( charindex , CHAR_WORKMAXMP); + if( Mymp > CHAR_getWorkInt( charindex , CHAR_WORKMAXMP) ) + CHAR_setInt( charindex , CHAR_MP, CHAR_getWorkInt( charindex , CHAR_WORKMAXMP)); + + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_MP); + +} + +void CHAR_CHAT_DEBUG_str( int charindex , char *message ) +{ + int i; + char str[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , str, sizeof(str)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_STR,atoi( str ) ); + CHAR_complianceParameter( i ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( i ,CHAR_P_STRING_STR|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(str)/100); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(str)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_STR,atoi( str ) ); + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex ,CHAR_P_STRING_STR|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK); + sprintf( token, "Ϊ%d!",(int)atoi(str)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_tgh( int charindex , char *message ) +{ + int i; + char tgh[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , tgh, sizeof(tgh)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_TOUGH,atoi( tgh ) ); + CHAR_complianceParameter( i ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( i ,CHAR_P_STRING_TOUGH|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(tgh)/100); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(tgh)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_TOUGH,atoi( tgh ) ); + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex ,CHAR_P_STRING_TOUGH|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF); + sprintf( token, "Ϊ%d!",(int)atoi(tgh)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_dex( int charindex , char *message ) +{ + int i; + char dex[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , dex, sizeof(dex)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_DEX,atoi( dex ) ); + CHAR_complianceParameter( i ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( i ,CHAR_P_STRING_DEX|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK|CHAR_P_STRING_QUICK); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(dex)/100); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(dex)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_DEX,atoi( dex ) ); + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex ,CHAR_P_STRING_DEX|CHAR_P_STRING_MAXHP|CHAR_P_STRING_ATK|CHAR_P_STRING_QUICK); + sprintf( token, "Ϊ%d!",(int)atoi(dex)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} +void CHAR_CHAT_DEBUG_vital( int charindex , char *message ) +{ + int i; + char vital[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , vital, sizeof(vital)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_VITAL,atoi( vital ) ); + CHAR_complianceParameter( i ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( i ,CHAR_P_STRING_VITAL|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(vital)/100); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(vital)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_VITAL,atoi( vital ) ); + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex ,CHAR_P_STRING_VITAL|CHAR_P_STRING_MAXHP|CHAR_P_STRING_DEF); + sprintf( token, "Ϊ%d!",(int)atoi(vital)/100); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} +void CHAR_CHAT_DEBUG_luck( int charindex , char *message ) +{ + int i; + char buf[64]; + int luck; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + luck=atoi(buf); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(luck<1) + luck=1; + else if(luck>5) + luck=5; + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_LUCK,luck); + CHAR_complianceParameter( i ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( i , CHAR_P_STRING_LUCK); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),luck); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),luck); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_LUCK,luck); + CHAR_complianceParameter( charindex ); + //CHAR_sendStatusString( charindex , "P"); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_LUCK); + sprintf( token, "Ϊ%d!",luck); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_gold( int charindex , char *message ) +{ + int i, MaxGold, money; + char cdkey[CDKEYLEN]; + char buf[64]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + money = atoi( buf ); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + MaxGold = CHAR_getMaxHaveGold( charindex); + if( money > MaxGold ) + money = MaxGold; + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_GOLD , money ); + CHAR_complianceParameter( i ); + CHAR_send_P_StatusString( i , CHAR_P_STRING_GOLD); + sprintf( token, "[GM]%sĽǮΪ%d!", CHAR_getChar( charindex, CHAR_NAME),money); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sĽǮΪ%d!", CHAR_getChar( i, CHAR_NAME),money); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_GOLD , money ); + CHAR_complianceParameter( charindex ); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_GOLD); + sprintf( token, "ǮΪ%d!",money); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +#ifdef _TEST_DROPITEMS +void CHAR_CHAT_DEBUG_dropmypet( int charindex, char *message ) +{ + char buf[256]; + int petID, x, y, floor, objindex, petindex, count=0; + int i, j, k, petarray, cLeve=1; + + if( getStringFromIndexWithDelim( message, " ", 1, buf, sizeof( buf)) == FALSE ) return; + petID = atoi( buf); + if( getStringFromIndexWithDelim( message, " ", 2, buf, sizeof( buf)) != FALSE ){ + cLeve = atoi( buf); + } + + floor = CHAR_getInt( charindex, CHAR_FLOOR); + x = CHAR_getInt( charindex, CHAR_X); + y = CHAR_getInt( charindex, CHAR_Y); + if( getStringFromIndexWithDelim( message, " ", 3, buf, sizeof( buf)) != FALSE ){ + floor = atoi( buf); + } + if( getStringFromIndexWithDelim( message, " ", 4, buf, sizeof( buf)) != FALSE ){ + x = atoi( buf); + } + if( getStringFromIndexWithDelim( message, " ", 5, buf, sizeof( buf)) != FALSE ){ + y = atoi( buf); + } + for( i=(x-3); i<(x+3); i++) { + for( j=(y-3); j<(y+3); j++) { + petarray = ENEMY_getEnemyArrayFromId( petID); + petindex = ENEMY_TEST_createPetIndex( petarray ); + if( !CHAR_CHECKINDEX( petindex) ){ + CHAR_talkToCli( charindex, -1, "err Can't create pet", CHAR_COLORYELLOW); + return; + } + CHAR_complianceParameter( petindex ); + objindex = PET_dropPetAbsolute( petindex, floor, i, j, FALSE ); + if( objindex == -1 ){ + CHAR_talkToCli( charindex, -1, "err Can't Drop", CHAR_COLORYELLOW); + return; + } + for( k = 1; k < cLeve; k ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + CHAR_complianceParameter( petindex ); + CHAR_setInt( petindex , CHAR_HP , CHAR_getWorkInt( petindex , CHAR_WORKMAXHP ) ); + + CHAR_setWorkInt( petindex, CHAR_WORKOBJINDEX, objindex ); + CHAR_setInt( petindex, CHAR_FLOOR, floor); + CHAR_setInt( petindex, CHAR_X, i); + CHAR_setInt( petindex, CHAR_Y, j); + CHAR_sendCToArroundCharacter( objindex); + CHAR_setInt( petindex, CHAR_PUTPETTIME, NowTime.tv_sec); + CHAR_setChar( petindex, CHAR_OWNERCDKEY, "SYSTEM_WAYI" ); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, "SYSTEM_WAYI" ); + count++; + } + } + sprintf( buf, "ܹ %dֻ", count); + CHAR_talkToCli( charindex, -1, buf, CHAR_COLORYELLOW); + + +} + +void CHAR_CHAT_DEBUG_dropmyitem( int charindex, char *message ) +{ + char buf[256]; + int itemID, SitemID, maxflg=0,emptyitemindexinchara, i, j; + int floor, x, y, objindex; + + if( getStringFromIndexWithDelim( message, " ", 1, buf, sizeof( buf)) == FALSE ) return; + SitemID = atoi( buf); + if( getStringFromIndexWithDelim( message, " ", 2, buf, sizeof( buf)) != FALSE ){ + maxflg = atoi( buf); + } + floor = CHAR_getInt( charindex, CHAR_FLOOR); + x = CHAR_getInt( charindex, CHAR_X); + y = CHAR_getInt( charindex, CHAR_Y); + if( getStringFromIndexWithDelim( message, " ", 3, buf, sizeof( buf)) != FALSE ){ + floor = atoi( buf); + } + if( getStringFromIndexWithDelim( message, " ", 4, buf, sizeof( buf)) != FALSE ){ + x = atoi( buf); + } + if( getStringFromIndexWithDelim( message, " ", 5, buf, sizeof( buf)) != FALSE ){ + y = atoi( buf); + } + itemID = SitemID; + + + for( i=(x-3); i<(x+3); i++) { + for( j=(y-3); j<(y+3); j++) { + int ret = 0 , count=0; + int itemindex; + while( count < 10 ){ + count++; + itemindex = ITEM_makeItemAndRegist( itemID ); + if( maxflg == 1 ) itemID++; + if( !ITEM_CHECKINDEX( itemindex)) continue; + break; + } + emptyitemindexinchara = CHAR_findEmptyItemBox( charindex ); + + CHAR_setItemIndex( charindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charindex); + CHAR_sendItemDataOne( charindex, emptyitemindexinchara); + //drop + if( (ret = CHAR_DropItemFXY( charindex, emptyitemindexinchara, + floor, i, j, &objindex )) != 0 ){ + char buf[256]; + sprintf( buf, "%d", ret); + CHAR_talkToCli( charindex, -1, buf, CHAR_COLORYELLOW); + } + ITEM_setInt(itemindex,ITEM_PUTTIME,NowTime.tv_sec); + CHAR_sendWatchEvent(objindex,CHAR_ACTSTAND,NULL,0,TRUE); + CHAR_setItemIndex(charindex, emptyitemindexinchara ,-1); + CHAR_sendItemDataOne(charindex, emptyitemindexinchara); + CHAR_sendCToArroundCharacter(CHAR_getWorkInt( charindex, CHAR_WORKOBJINDEX)); + } + } + { + char buf[256]; + sprintf( buf, "ID%d", itemID-1); + CHAR_talkToCli( charindex, -1, buf, CHAR_COLORYELLOW); + } +} +#endif + +void CHAR_CHAT_DEBUG_additem( int charindex , char *message ) +{ + + int emptyitemindexinchara, itemindex; + int i; + int num = 0; + int itemid; + char buf[64]; + char msgbuf[128]; + char cdkey[CDKEYLEN]; + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + itemid = atoi( buf); + easyGetTokenFromString( message , 2 , buf, sizeof(buf)); + num = atoi( buf); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); + + if( num <= 0 ) num = 1; + + if(strlen(cdkey)>0){ + int playernum = CHAR_getPlayerMaxNum(); + int j; + for(j=0;j=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + for( i = 0; i < num; i ++ ) { + emptyitemindexinchara = CHAR_findEmptyItemBox( j ); + + if( emptyitemindexinchara < 0 ){ + sprintf( msgbuf, "%sƷλ㡣", CHAR_getChar( j, CHAR_NAME )); + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + sprintf( msgbuf, "%sƷλ㡣", CHAR_getChar( j, CHAR_NAME )); + CHAR_talkToCli( j, -1, msgbuf, CHAR_COLORYELLOW); + return; + } + + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex != -1 ){ + CHAR_setItemIndex( j, emptyitemindexinchara, itemindex); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,j); + CHAR_sendItemDataOne( j, emptyitemindexinchara); + LogItem( + CHAR_getChar( j, CHAR_NAME ), + CHAR_getChar( j, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + atoi( message), +#endif + "AddItem(GM)", + CHAR_getInt( j,CHAR_FLOOR), + CHAR_getInt( j,CHAR_X ), + CHAR_getInt( j,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + snprintf( msgbuf,sizeof( msgbuf),"[GM]%s%sɹ", + CHAR_getChar( charindex, CHAR_NAME ),ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( j, -1,msgbuf, CHAR_COLORYELLOW); + snprintf( msgbuf, sizeof( msgbuf), "ɹΪ%s %s", + CHAR_getChar( j, CHAR_NAME ),ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charindex, -1,msgbuf, CHAR_COLORYELLOW); + }else{ + sprintf( msgbuf, "ʧܡ" ); + CHAR_talkToCli( charindex, -1,msgbuf, CHAR_COLORYELLOW); + } + } + }else{ + for( i = 0; i < num; i ++ ) { + emptyitemindexinchara = CHAR_findEmptyItemBox( charindex ); + + if( emptyitemindexinchara < 0 ){ + sprintf( msgbuf, "Ʒλ㡣" ); + + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + + return; + } + + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex != -1 ){ + CHAR_setItemIndex( charindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charindex); + CHAR_sendItemDataOne( charindex, emptyitemindexinchara); + LogItem( + CHAR_getChar( charindex, CHAR_NAME ), + CHAR_getChar( charindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + atoi( message), +#endif + "AddItem(GM)", + CHAR_getInt( charindex,CHAR_FLOOR), + CHAR_getInt( charindex,CHAR_X ), + CHAR_getInt( charindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + snprintf( msgbuf, sizeof( msgbuf), "%sɹ", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charindex, -1,msgbuf, CHAR_COLORYELLOW); + }else{ + sprintf( msgbuf, "ʧܡ" ); + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + } + } + } +} + + +void CHAR_CHAT_DEBUG_metamo( int charindex , char *message ) +{ + char metamoid[7]; + char cdkey[CDKEYLEN]; + char token[128]; + int i=0; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , metamoid, sizeof(metamoid)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_BASEIMAGENUMBER , atoi( metamoid ) ); + CHAR_setInt( i , CHAR_BASEBASEIMAGENUMBER , atoi( metamoid ) ); + + CHAR_complianceParameter( i ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( i , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( i , CHAR_P_STRING_BASEBASEIMAGENUMBER); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(metamoid)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(metamoid)); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_BASEIMAGENUMBER , atoi( metamoid ) ); + CHAR_setInt( charindex , CHAR_BASEBASEIMAGENUMBER , atoi( metamoid ) ); + + CHAR_complianceParameter( charindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + sprintf( token, "Ϊ%d!",(int)atoi(metamoid)); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_info( int charindex , char *message ) +{ + char line[256]; + int index; + + if( strlen( message) != 0 ) { + int playernum = CHAR_getPlayerMaxNum(); + for(index=0;index=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + } + else { + index = charindex; + } + if( !CHAR_CHECKINDEX( index)) { + CHAR_talkToCli( charindex, -1 , "index޷ʹá" , CHAR_COLORWHITE ); + return; + } + + snprintf( line, sizeof( line), + "name:%s i:%d B:%d BB:%d LV:%d EXP:%d MakeSeq:%d", + CHAR_getChar( index, CHAR_NAME), + charindex, + CHAR_getInt( index, CHAR_BASEIMAGENUMBER ), + CHAR_getInt( index, CHAR_BASEBASEIMAGENUMBER ), + CHAR_getInt( index, CHAR_LV ), + CHAR_getInt( index, CHAR_EXP ), + CHAR_getCharMakeSequenceNumber( index)); + + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + snprintf( line, sizeof( line), + "Gold:%d HP:%d MP/MHP:%d/%d" , + CHAR_getInt( index, CHAR_GOLD ), + CHAR_getInt( index, CHAR_HP ), + CHAR_getInt( index, CHAR_MP ), + CHAR_getInt( index, CHAR_MAXMP )); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPET ){ + snprintf( line, sizeof(line), + ":%d :%d :%d :%d :%d :%d :%d :%d :%d ұ:%.2f :%s", + CHAR_getInt( index, CHAR_VITAL )/100, + CHAR_getInt( index, CHAR_STR )/100, + CHAR_getInt( index, CHAR_TOUGH )/100, + CHAR_getInt( index, CHAR_DEX )/100, + CHAR_getWorkInt( index, CHAR_WORKFIXVITAL ), + CHAR_getWorkInt( index, CHAR_WORKATTACKPOWER ), + CHAR_getWorkInt( index, CHAR_WORKDEFENCEPOWER ),//CHAR_WORKFIXDEX + CHAR_getWorkInt( index, CHAR_WORKQUICK ), + CHAR_getInt( index, CHAR_MODAI ), + CHAR_getInt( index, CHAR_VARIABLEAI ) * 0.01, + CHAR_getChar( index, CHAR_UNIQUECODE) ); + }else{ + snprintf( line, sizeof(line), + ":%d :%d :%d :%d :%d :%d :%d :%d :%d", + CHAR_getInt( index, CHAR_VITAL )/100, + CHAR_getInt( index, CHAR_STR )/100, + CHAR_getInt( index, CHAR_TOUGH )/100, + CHAR_getInt( index, CHAR_DEX )/100, + CHAR_getWorkInt( index, CHAR_WORKFIXVITAL ), + CHAR_getWorkInt( index, CHAR_WORKATTACKPOWER ), + CHAR_getWorkInt( index, CHAR_WORKDEFENCEPOWER ), + CHAR_getWorkInt( index, CHAR_WORKFIXCHARM ), + CHAR_getWorkInt( index, CHAR_WORKFIXLUCK )); + } + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + + snprintf( line, sizeof(line), + ":%d ˮ:%d :%d :%d", + CHAR_getWorkInt( index, CHAR_WORKFIXEARTHAT ), + CHAR_getWorkInt( index, CHAR_WORKFIXWATERAT ), + CHAR_getWorkInt( index, CHAR_WORKFIXFIREAT ), + CHAR_getWorkInt( index, CHAR_WORKFIXWINDAT )); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + snprintf( line, sizeof( line), + "Sk Itm:%d ChV:%d Rad:%d" , + CheckCharMaxItem(index) , + CHAR_getInt( index, CHAR_CHATVOLUME ), + CHAR_getInt( index, CHAR_RADARSTRENGTH ) ); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + + snprintf( line, sizeof( line), + "Status :%d :%d Ĭ:%d ʯ:%d :%d :%d" , + CHAR_getInt( index , CHAR_POISON ), + CHAR_getInt( index , CHAR_PARALYSIS ), + CHAR_getInt( index , CHAR_SLEEP ), + CHAR_getInt( index , CHAR_STONE ), + CHAR_getInt( index , CHAR_DRUNK ), + CHAR_getInt( index , CHAR_CONFUSION ) ); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + +#ifdef _PERSONAL_FAME // Arminius: + snprintf( line, sizeof( line), +#ifdef _NEW_MANOR_LAW + "TitInd:%d FL:%d X:%d Y:%d DIR:%d FAME:%d MOMENTUM:%d" , +#else + "TitInd:%d FL:%d X:%d Y:%d DIR:%d FAME:%d" , +#endif + CHAR_getInt( index , CHAR_INDEXOFEQTITLE ), + CHAR_getInt( index , CHAR_FLOOR ), + CHAR_getInt( index , CHAR_X ), + CHAR_getInt( index , CHAR_Y ), + CHAR_getInt( index , CHAR_DIR ), + CHAR_getInt( index , CHAR_FAME) +#ifdef _NEW_MANOR_LAW + ,CHAR_getInt( index , CHAR_MOMENTUM) +#endif + ); +#else + snprintf( line, sizeof( line), + "TitInd:%d FL:%d X:%d Y:%d DIR:%d" , + CHAR_getInt( index , CHAR_INDEXOFEQTITLE ), + CHAR_getInt( index , CHAR_FLOOR ), + CHAR_getInt( index , CHAR_X ), + CHAR_getInt( index , CHAR_Y ), + CHAR_getInt( index , CHAR_DIR ) ); +#endif + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + + snprintf( line, sizeof( line), + "walk:%d dead:%d ItemMergecnt:%d" , + CHAR_getInt( index , CHAR_WALKCOUNT ) , + CHAR_getInt( index , CHAR_DEADCOUNT ) , + CHAR_getInt( index, CHAR_MERGEITEMCOUNT) + ); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + snprintf( line, sizeof( line), + "petindex [%d][%d][%d][%d][%d] " , + CHAR_getCharPet( index, 0), + CHAR_getCharPet( index, 1), + CHAR_getCharPet( index, 2), + CHAR_getCharPet( index, 3), + CHAR_getCharPet( index, 4)); + } + else { + snprintf( line, sizeof( line), + "PetskillIndex [%d][%d][%d][%d][%d][%d][%d] " , + CHAR_getPetSkill( index, 0), + CHAR_getPetSkill( index, 1), + CHAR_getPetSkill( index, 2), + CHAR_getPetSkill( index, 3), + CHAR_getPetSkill( index, 4), + CHAR_getPetSkill( index, 5), + CHAR_getPetSkill( index, 6)); + } + + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + snprintf( line, sizeof( line), + "poolpetindex [%d][%d][%d][%d][%d] " , + CHAR_getCharPoolPet( index, 0), + CHAR_getCharPoolPet( index, 1), + CHAR_getCharPoolPet( index, 2), + CHAR_getCharPoolPet( index, 3), + CHAR_getCharPoolPet( index, 4)); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + + snprintf( line, sizeof( line), + "poolpetindex [%d][%d][%d][%d][%d] " , + CHAR_getCharPoolPet( index, 5), + CHAR_getCharPoolPet( index, 6), + CHAR_getCharPoolPet( index, 7), + CHAR_getCharPoolPet( index, 8), + CHAR_getCharPoolPet( index, 9)); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + } + + snprintf( line, sizeof( line), + "levelup [%d], ۻ %d ij[%d]" , + CHAR_getInt( index, CHAR_LEVELUPPOINT), + CHAR_getWorkInt( index, CHAR_WORKULTIMATE), + CHAR_getInt( index, CHAR_GAMBLENUM) ); + CHAR_talkToCli( charindex, -1 , line , CHAR_COLORWHITE ); + +} + +void CHAR_CHAT_DEBUG_sysinfo( int charindex , char *message ) +{ + char msg[1024],name[256]; + int i; + time_t new_t; + int dd,hh,mm,ss; + + int items=0 , chars=0, golds=0, nouses=0; + int players=0,pets=0,others=0; + int whichtype= -1; + int objnum = OBJECT_getNum(); + + + int itemnum = ITEM_getITEM_itemnum(); + int itemuse =0; + + makeEscapeString( getGameservername(), name, sizeof( name)); + sprintf( msg, "GSID:%s GSNAME:%s", getGameservername(), name); + CHAR_talkToCli( charindex, -1, msg, CHAR_COLORYELLOW); + + + for( i=0 ; i0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt(i,CHAR_LV, atoi( message )); + CHAR_send_P_StatusString( i , CHAR_P_STRING_LV|CHAR_P_STRING_NEXTEXP); + sprintf( token, "[GM]%sĵȼΪ%d!", CHAR_getChar( charaindex, CHAR_NAME),level); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sĵȼΪ%d!", CHAR_getChar( i, CHAR_NAME),level); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt(charaindex,CHAR_LV, atoi( message )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_LV|CHAR_P_STRING_NEXTEXP); + sprintf( token, "ȼΪ%d!",level); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } + +} + + +void CHAR_CHAT_DEBUG_exp( int charaindex, char* message ) +{ + int i; + char exp[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , exp, sizeof(exp)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setMaxExp( i, atoi( exp )); + CHAR_send_P_StatusString( i , CHAR_P_STRING_EXP); + sprintf( token, "[GM]%sľΪ%d!", CHAR_getChar( charaindex, CHAR_NAME),(int)atoi(exp)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sľΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(exp)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setMaxExp( charaindex, atoi( exp )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_EXP); + sprintf( token, "Ϊ%d!",(int)atoi(exp)/100); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_delitem( int charindex , char *message ) +{ + int itemid; + + if( strcmp( message, "all") == 0 ) { + int i; + for( i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(charindex) ; i ++ ) { + itemid = CHAR_getItemIndex(charindex, i); + if( itemid != -1 ) { + { + LogItem( + CHAR_getChar( charindex, CHAR_NAME ), + CHAR_getChar( charindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemid, +#else + ITEM_getInt( itemid, ITEM_ID ), +#endif + "DelItem(ɾGM)", + CHAR_getInt( charindex,CHAR_FLOOR), + CHAR_getInt( charindex,CHAR_X ), + CHAR_getInt( charindex,CHAR_Y ), + ITEM_getChar( itemid, ITEM_UNIQUECODE), + ITEM_getChar( itemid, ITEM_NAME), + ITEM_getInt( itemid, ITEM_ID) + ); + } + CHAR_DelItem( charindex, i); + } + } + }else { + int equipplace; + equipplace = atoi( message); + if( equipplace < CHAR_STARTITEMARRAY || equipplace > CheckCharMaxItem(charindex) -1 ) { + CHAR_talkToCli( charindex, -1, "벻ȷ", CHAR_COLORWHITE); + return; + } + itemid = CHAR_getItemIndex(charindex, equipplace); + if( itemid == -1 ) return; + { + LogItem( + CHAR_getChar( charindex, CHAR_NAME ), + CHAR_getChar( charindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemid, +#else + ITEM_getInt( itemid, ITEM_ID ), +#endif + "DelItem(ɾGM)", + CHAR_getInt( charindex,CHAR_FLOOR), + CHAR_getInt( charindex,CHAR_X ), + CHAR_getInt( charindex,CHAR_Y ), + ITEM_getChar( itemid, ITEM_UNIQUECODE), + ITEM_getChar( itemid, ITEM_NAME), + ITEM_getInt( itemid, ITEM_ID) + ); + } + CHAR_DelItem( charindex, equipplace); + } +} + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +void CHAR_CHAT_DEBUG_addsk( int charaindex, char* message ) +{ + + CHAR_HaveSkill *pSkil; + int skill, i, level=1; + + char msg1[20], msg2[20]; + + getStringFromIndexWithDelim( message, " ", 1, msg1, sizeof( msg1)); + getStringFromIndexWithDelim( message, " ", 2, msg2, sizeof( msg2)); + + skill = atoi(msg1); + level = atoi(msg2); + + if( level > 100 ){ + CHAR_talkToCli( charaindex, -1, "ȼȷ", CHAR_COLORWHITE); + return; + } + if( level < 1 ) level = 1; + + for( i = 0; i < CHAR_SKILLMAXHAVE; i ++ ){ + int skill_id = -1; + + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + skill_id = SKILL_getInt( &pSkil->skill, SKILL_IDENTITY); + if( skill == skill_id && skill_id != -1 ){ + CHAR_talkToCli(charaindex,-1, "Ѿѧϰ˼", CHAR_COLORYELLOW); + return; + } + + if( pSkil == NULL ) continue; + if( pSkil->use != 0 ) continue; + + break; + } + + if( i >= CHAR_SKILLMAXHAVE ){ + CHAR_talkToCli(charaindex,-1, "Ѵ", CHAR_COLORYELLOW); + return; + }else{ + level *= 100; + SKILL_makeSkillData( &pSkil->skill, skill, level); + pSkil->use = TRUE; + } + + CHAR_sendStatusString( charaindex , "S"); + + return; +} + +void CHAR_CHAT_DEBUG_delsk( int charaindex, char* message ) +{ + int i; + CHAR_HaveSkill *pSkil; + + if( strcmp( message, "all" ) == 0 ){ + CHAR_talkToCli( charaindex, -1, "м", CHAR_COLORWHITE); + for( i = CHAR_SKILLMAXHAVE-1; i >= 0; i -- ){ + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + if( pSkil == NULL )continue; + if( pSkil->use == 0 )continue; + SKILL_makeSkillData( &pSkil->skill, 0, 0 ); + pSkil->use = 0; + } + } + + for( i = CHAR_SKILLMAXHAVE-1; i >= 0; i -- ){ + pSkil = CHAR_getCharHaveSkill( charaindex, i ); + if( pSkil == NULL )continue; + if( pSkil->use == 0 )continue; + print( "SKILUSE %d\n", pSkil->use ); + break; + } + + if( i < 0 ){ + CHAR_talkToCli( charaindex, -1, "޷ˡ", CHAR_COLORWHITE); + ;; + }else{ + SKILL_makeSkillData( &pSkil->skill, 0, 0 ); + pSkil->use = 0; + } + + CHAR_sendStatusString( charaindex , "S"); +} +#endif + +#ifdef _MAKE_MAP +void CHAR_CHAT_DelMap( int charaindex, char* message ){ + + int ff, x, y, xx, yy; + int tile, obj; + + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + + if( MAP_getFloorXY( ff, &xx, &yy) == FALSE )return; + + for(x=0;x %d", tile, fixtile ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + snprintf( szBuffer, sizeof( szBuffer ), "%d => %d", obj, fixobj ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + } + + MAP_setTileAndObjData( ff, fx, fy, fixtile, fixobj ); + + { + char *stringdata; + RECT seekr , retr; + seekr.x = fx; + seekr.y = fy; + seekr.width = 1; + seekr.height = 1; + stringdata = MAP_getdataFromRECT(ff,&seekr,&retr); + if( stringdata ){ + + if( CHAR_getInt( charaindex , CHAR_WHICHTYPE ) + == CHAR_TYPEPLAYER ){ + int fd = getfdFromCharaIndex( charaindex ); + lssproto_M_send(fd,ff, + retr.x,retr.y, + retr.x+retr.width,retr.y+retr.height, + stringdata ); + } + } else { + } + } + + return ; +} + +void CHAR_CHAT_Fixtile( int charaindex, char* message ){ + + int dir, ff, fx, fy; + int tile, obj; + int fixtile=atoi(message); + + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + fx = CHAR_getInt( charaindex, CHAR_X ); + fy = CHAR_getInt( charaindex, CHAR_Y ); + dir = CHAR_getInt( charaindex, CHAR_DIR ); + + fx += CHAR_getDX(dir); + fy += CHAR_getDY(dir); + + if( MAP_getTileAndObjData( ff, fx, fy, &tile, &obj) == FALSE )return; + + { + char szBuffer[64]; + snprintf( szBuffer, sizeof( szBuffer ), "ͼƬ%d => %d", tile, fixtile ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + snprintf( szBuffer, sizeof( szBuffer ), "%d => %d", obj, obj ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + } + + MAP_setTileAndObjData( ff, fx, fy, fixtile, -1 ); + + { + char *stringdata; + RECT seekr , retr; + seekr.x = fx; + seekr.y = fy; + seekr.width = 1; + seekr.height = 1; + stringdata = MAP_getdataFromRECT(ff,&seekr,&retr); + if( stringdata ){ + + if( CHAR_getInt( charaindex , CHAR_WHICHTYPE ) + == CHAR_TYPEPLAYER ){ + int fd = getfdFromCharaIndex( charaindex ); + lssproto_M_send(fd,ff, + retr.x,retr.y, + retr.x+retr.width,retr.y+retr.height, + stringdata ); + } + } else { + } + } + + return ; +} + +void CHAR_CHAT_Fixobj( int charaindex, char* message ){ + + int dir, ff, fx, fy; + int tile, obj; + int fixobj=atoi(message); + + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + fx = CHAR_getInt( charaindex, CHAR_X ); + fy = CHAR_getInt( charaindex, CHAR_Y ); + dir = CHAR_getInt( charaindex, CHAR_DIR ); + + fx += CHAR_getDX(dir); + fy += CHAR_getDY(dir); + + if( MAP_getTileAndObjData( ff, fx, fy, &tile, &obj) == FALSE )return; + + { + char szBuffer[64]; + snprintf( szBuffer, sizeof( szBuffer ), "ͼƬ%d => %d", tile, tile ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + snprintf( szBuffer, sizeof( szBuffer ), "%d => %d", obj, fixobj ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE); + } + + MAP_setTileAndObjData( ff, fx, fy, -1, fixobj ); + + { + char *stringdata; + RECT seekr , retr; + seekr.x = fx; + seekr.y = fy; + seekr.width = 1; + seekr.height = 1; + stringdata = MAP_getdataFromRECT(ff,&seekr,&retr); + if( stringdata ){ + + if( CHAR_getInt( charaindex , CHAR_WHICHTYPE ) + == CHAR_TYPEPLAYER ){ + int fd = getfdFromCharaIndex( charaindex ); + lssproto_M_send(fd,ff, + retr.x,retr.y, + retr.x+retr.width,retr.y+retr.height, + stringdata ); + } + } else { + } + } + + return ; +} + +void CHAR_CHAT_Fukuwa( int charaindex, char* message ){ + int dir, ff, fx, fy, objindex, vs_index, vs_fd, stringlen; + OBJECT obj; + char szBuffer[2048]; + + stringlen = strlen( message ); + + if( message[0] == '[' && message[stringlen-1] == ']' ){ + CHAR_talkToCli( charaindex, -1, "ûת", CHAR_COLORWHITE); + return ; + } + + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + fx = CHAR_getInt( charaindex, CHAR_X ); + fy = CHAR_getInt( charaindex, CHAR_Y ); + dir = CHAR_getInt( charaindex, CHAR_DIR ); + + fx += CHAR_getDX(dir); + fy += CHAR_getDY(dir); + + stringlen = strlen( message ); + + + snprintf( szBuffer, sizeof( szBuffer ), "P|%s", message ); + + for( obj=MAP_getTopObj( ff, fx, fy ); obj; obj=NEXT_OBJECT(obj) ){ + objindex = GET_OBJINDEX(obj); + if( OBJECT_getType(objindex) != OBJTYPE_CHARA )continue; + vs_index = OBJECT_getIndex(objindex); + vs_fd = getfdFromCharaIndex( vs_index ); + CHAR_Talk( vs_fd, vs_index, + szBuffer, CHAR_COLORWHITE, 3 ); + break; + } + +} +#endif + +void CHAR_CHAT_DEBUG_superman( int charaindex, char* message ) +{ +#define CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF 100000 + int i; + char hp[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , hp, sizeof(hp)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt(charaindex,CHAR_SKILLUPPOINT, 0); + CHAR_Skillupsend(charaindex); + CHAR_setInt( charaindex , CHAR_HP, CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF); + CHAR_setInt( charaindex , CHAR_MP, 1000 ); + CHAR_setInt( charaindex , CHAR_MAXMP,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_VITAL,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_STR,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_TOUGH,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_DEX , CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); +#ifdef _TRANS_LEVEL_CF + CHAR_setInt( charaindex,CHAR_LV, getMaxLevel()); +#else + CHAR_setInt( charaindex,CHAR_LV, 140); +#endif + CHAR_complianceParameter( charaindex ); + CHAR_sendStatusString( charaindex , "P"); + + sprintf( token, "[GM]%sΪ״̬!", CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ״̬!", CHAR_getChar( i, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt(charaindex,CHAR_SKILLUPPOINT, 0); + CHAR_Skillupsend(charaindex); + CHAR_setInt( charaindex , CHAR_HP, CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF); + CHAR_setInt( charaindex , CHAR_MP,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_MAXMP,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_VITAL,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_STR,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_TOUGH,CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); + CHAR_setInt( charaindex , CHAR_DEX , CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF ); +#ifdef _TRANS_LEVEL_CF + CHAR_setInt( charaindex,CHAR_LV, getMaxLevel()); +#else + CHAR_setInt( charaindex,CHAR_LV, 140); +#endif + CHAR_complianceParameter( charaindex ); + CHAR_sendStatusString( charaindex , "P"); + + CHAR_talkToCli( charaindex, -1,"ó״̬!", CHAR_COLORYELLOW ); + } +#undef CHAT_CHAT_DEBUG_SUPERMAN_PARAMDEF + +} + +void CHAR_CHAT_printcount( int charaindex, char* message ) +{ + char msgbuf[512]; + + snprintf( msgbuf,sizeof( msgbuf), + "˵ %d λ, %d ·, %d ", + CHAR_getInt( charaindex, CHAR_TALKCOUNT), + CHAR_getInt( charaindex, CHAR_WALKCOUNT), + CHAR_getInt( charaindex, CHAR_DEADCOUNT) + ); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + +} + +void CHAR_CHAT_DEBUG_battlein( int charaindex, char* message ) +{ + int fd = getfdFromCharaIndex( charaindex ); + if( fd != -1) { + lssproto_EN_recv( fd, + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + } +} + +void CHAR_CHAT_DEBUG_battleout( int charaindex, char* message ) +{ + + BATTLE_WatchStop( charaindex ); +} + +void CHAR_CHAT_DEBUG_petmake( int charaindex, char* message ) +{ + int ret; + int enemynum; + int enemyid; + int i,j; + int level=-1; + char buf[10]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + enemyid=atoi(buf); + easyGetTokenFromString( message , 2 , buf, sizeof(buf)); + level=atoi(buf); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(j=0;j=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + ret = ENEMY_createPetFromEnemyIndex( j, i); + if( !CHAR_CHECKINDEX( ret))return; + + sprintf( token, "[GM]%s%s!", CHAR_getChar( charaindex, CHAR_NAME),ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( j, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%s%sɹ!", CHAR_getChar( j, CHAR_NAME),ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( j, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE )return; + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + if( level != -1 ){ +#ifdef _TRANS_LEVEL_CF + if( level > getMaxLevel() ) level = getMaxLevel(); +#else + if( level > 140 ) level = 140; +#endif + if( level < 0 ) level = 0; + level = level - CHAR_getInt( ret, CHAR_LV ); + if( level > 0 ){ + int k; + for( k = 1; k <= level; k ++ ){ // + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + } + } + LogPet( + CHAR_getChar( j, CHAR_NAME ), + CHAR_getChar( j, CHAR_CDKEY ), + CHAR_getChar( ret, CHAR_NAME), + CHAR_getInt( ret, CHAR_LV), + "GM", + CHAR_getInt( j,CHAR_FLOOR), + CHAR_getInt( j,CHAR_X ), + CHAR_getInt( j,CHAR_Y ), + CHAR_getChar( ret, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + CHAR_complianceParameter( ret ); + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( j, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( j, token ); + }else{ + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + ret = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( !CHAR_CHECKINDEX( ret))return; + + snprintf( token,sizeof( token), "%sɹ!",ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE )return; + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + if( level != -1 ){ + if( level > 200 ) level = 200; + if( level < 0 ) level = 0; + level = level - CHAR_getInt( ret, CHAR_LV ); + if( level > 0 ){ + int k; + for( k = 1; k <= level; k ++ ){ // + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + } + } + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( ret, CHAR_NAME), + CHAR_getInt( ret, CHAR_LV), + "GM", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( ret, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_complianceParameter( ret ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); + } +} + +void CHAR_CHAT_DEBUG_deletepet( int charaindex, char* message ) +{ + int i, pindex; + char category[12]; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + pindex = CHAR_getCharPet( charaindex, i); + if( CHAR_CHECKINDEX( pindex)) { + CHAR_endCharOneArray( pindex ); + CHAR_setCharPet( charaindex, i, -1); + snprintf( category, sizeof( category), "K%d",i); + CHAR_sendStatusString( charaindex, category ); + snprintf( category, sizeof( category), "W%d",i); + CHAR_sendStatusString( charaindex, category ); + } + } + + CHAR_talkToCli( charaindex, -1, "г", CHAR_COLORWHITE); + +} + +#ifdef _MO_RELOAD_NPC + #define MAXMESS_LISTNUM 8 +#else + #define MAXMESS_LISTNUM 7 +#endif +#define ALLRESET (MAXMESS_LISTNUM - 1) + +void CHAR_CHAT_DEBUG_reset( int charaindex, char* message ) +{ + int i; + char mess[MAXMESS_LISTNUM][256]={ "enemy", "encount", "magic", "warppoint", "petskill", "pettalk", +#ifdef _MO_RELOAD_NPC + "npc", +#endif + "all"}; + + for( i=0; i= MAXMESS_LISTNUM ){ + CHAR_talkToCli( charaindex, -1, "ָ", CHAR_COLORRED);//CHAR_COLORYELLOW + return; + } + switch( i){ + case ALLRESET: + case 0: + if( !ENEMYTEMP_reinitEnemy() || !ENEMY_reinitEnemy() ){ + CHAR_talkToCli( charaindex, -1, "¶ȡ˻ʧܡ", CHAR_COLORRED); + return; + } + if( i != ALLRESET ) break; + case 1: + if( !GROUP_reinitGroup() || !ENCOUNT_reinitEncount() ){ + CHAR_talkToCli( charaindex, -1, "¶ȡŶʧܡ", CHAR_COLORRED); + } + if( i != ALLRESET ) break; + case 2: + if( !MAGIC_reinitMagic() || !ATTMAGIC_reinitMagic() ) { + CHAR_talkToCli( charaindex, -1, "¶ȡʧܡ", CHAR_COLORRED); + } + if( i != ALLRESET ) break; + case 3: + MAPPOINT_resetMapWarpPoint( 1); + if( !MAPPOINT_loadMapWarpPoint() ){ + CHAR_talkToCli( charaindex, -1, "¶ȡԾʧܡ", CHAR_COLORRED); + } + if( i != ALLRESET ) break; + case 4: + if( !PETSKILL_reinitPetskill() ) { + CHAR_talkToCli( charaindex, -1, "¶ȡ\ʧܡ", CHAR_COLORRED); + } + if( i != ALLRESET ) break; + case 5: + LoadPetTalk(); + if( i != ALLRESET ) break; +#ifdef _MO_RELOAD_NPC + case 6: + if( !NPC_reloadNPC() ) { + CHAR_talkToCli( charaindex, -1, "NPCʧܡ", CHAR_COLORRED); + } + if( i != ALLRESET ) break; +#endif + break; + } + CHAR_talkToCli( charaindex, -1, "¶ȡϷϡ", CHAR_COLORYELLOW); +} + +void CHAR_CHAT_DEBUG_enemyrestart( int charaindex, char* message ) +{ + if( ENEMYTEMP_reinitEnemy()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡ˻ϡ", CHAR_COLORWHITE); + }else { + CHAR_talkToCli( charaindex, -1, "ٴζȡ˻ʧܡ", CHAR_COLORWHITE); + } + + if( ENEMY_reinitEnemy()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡϡ", CHAR_COLORWHITE); + }else { + CHAR_talkToCli( charaindex, -1, "ٴζȡ˻ʧܡ", CHAR_COLORWHITE); + } + + if( GROUP_reinitGroup()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡŶϡ", CHAR_COLORWHITE); + }else { + CHAR_talkToCli( charaindex, -1, "ٴζȡŶʧܡ", CHAR_COLORWHITE); + } + if( ENCOUNT_reinitEncount()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡϡ", CHAR_COLORWHITE); + } + else { + CHAR_talkToCli( charaindex, -1, "ٴζȡʧܡ", CHAR_COLORWHITE); + } + + if( MAGIC_reinitMagic()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡϡ", CHAR_COLORWHITE); + } + else { + CHAR_talkToCli( charaindex, -1, "ٴζȡʧܡ", CHAR_COLORWHITE); + } + +#ifdef _ATTACK_MAGIC + if( ATTMAGIC_reinitMagic() ) + CHAR_talkToCli( charaindex , -1 , "ٴζȡϡ" , CHAR_COLORWHITE ); + else + CHAR_talkToCli( charaindex , -1 , "ٴζȡʧܡ" , CHAR_COLORWHITE ); +#endif + if( PETSKILL_reinitPetskill()) { + CHAR_talkToCli( charaindex, -1, "ٴζȡ\ϡ", CHAR_COLORWHITE); + } + else { + CHAR_talkToCli( charaindex, -1, "ٴζȡ\ʧܡ", CHAR_COLORWHITE); + } + + LoadPetTalk(); // Arminius 8.15 pet talk + CHAR_talkToCli( charaindex, -1, "ٴζȡイϡ", CHAR_COLORWHITE); + +} + +void CHAR_CHAT_DEBUG_battlewatch( int charaindex, char* message ) +{ + int fd = getfdFromCharaIndex( charaindex ); + if( fd != -1) { + lssproto_LB_recv( fd, + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y)); + } +} + +// shan 2001/12/18 Begin 춸ı࣬ʽԭȵfunctionע +void CHAR_CHAT_DEBUG_eventclean( int charaindex, char* message ) +{ +#ifdef _ADD_NEWEVENT_1024 + int event_num = 32; +#else +#ifdef _ADD_NEWEVENT // WON + int event_num = 8; +#else + int event_num = 6; +#endif +#endif + + int point; + int shiftbit; + int eventno=0; + char token[1024]; + int array; + int shift; + char token_cdkey[256]="", token_name[256]="", cdkey[CDKEYLEN], token_flag[256]=""; + unsigned int max_user = 0; + BOOL find = FALSE; + BOOL ret1, ret2; + int charaindex_tmp = 0; + int i; + + getStringFromIndexWithDelim( message, " ", 1, token_flag, sizeof( token)); + ret1 = getStringFromIndexWithDelim( message, " ", 2, token_cdkey, sizeof( token_cdkey)); + ret2 = getStringFromIndexWithDelim( message, " ", 3, token_name, sizeof( token_name)); + shiftbit = atoi(token_flag); + eventno = atoi(token_flag); + + if( shiftbit!=-1 && ret1==FALSE && ret2==FALSE ){ + charaindex_tmp = charaindex; + find=TRUE; + }else{ + if( shiftbit==-1 || strlen(token_cdkey)==0 || strlen(token_name)==0 ){ + sprintf( token, "%s", "ȷȷʽ[eventsetend ʺ ]"); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + return; + } + max_user = getFdnum(); + for( i=0; i=event_num ){ + sprintf( token, "󣡣ѳ Χ(0~%d)",32*event_num-1); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + return; + } + point = CHAR_getInt( charaindex_tmp, CHAR_ENDEVENT+array); + point = point & ~(1<=event_num ){ + sprintf( token, "󣡣ѳΧ(0~%d)",32*event_num-1); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + return; + } + point = CHAR_getInt( charaindex_tmp, CHAR_NOWEVENT+array); + point = point | (1<=event_num ){ + sprintf( token, "󣡣ѳ Χ(0~%d)",32*event_num-1); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + return; + } + point = CHAR_getInt( charaindex_tmp, CHAR_ENDEVENT+array); + point = point | (1<0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( i , CHAR_DUELPOINT, atoi( dp ) ); + CHAR_send_P_StatusString( i ,CHAR_P_STRING_DUELPOINT ); + sprintf( token, "[GM]%sDPΪ%d!", CHAR_getChar( charindex, CHAR_NAME),(int)atoi(dp)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sDPΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(dp)); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt( charindex , CHAR_DUELPOINT, atoi( dp ) ); + CHAR_send_P_StatusString( charindex ,CHAR_P_STRING_DUELPOINT ); + sprintf( token, "DPΪ%d!",(int)atoi(dp)); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} + +#ifdef _EQUIT_ARRANGE +void CHAR_CHAT_DEBUG_arrange( int charindex , char *message ) +{ + CHAR_setWorkInt( charindex, CHAR_WORKFIXARRANGE, atoi( message) ); + CHAR_complianceParameter( charindex ); + CHAR_talkToCli( charindex, -1, "趨", CHAR_COLORYELLOW); +} +#endif + + +#ifdef _EQUIT_SEQUENCE +void CHAR_CHAT_DEBUG_sequence( int charindex , char *message ) +{ + CHAR_setWorkInt( charindex, CHAR_WORKFIXSEQUENCE, atoi( message) ); + CHAR_complianceParameter( charindex ); + CHAR_talkToCli( charindex, -1, "趨˳", CHAR_COLORYELLOW); +} +#endif + +#define ITEMRESERVESTRING "item" +#define POOLITEMRESERVESTRING "poolitem" + +void CHAR_CHAT_DEBUG_setmerge_main( int charaindex, char* message, int mode ) +{ + int haveitemindex = atoi( message); + int itemindex; + + if( !CHAR_CHECKITEMINDEX( charaindex, haveitemindex) ){ + CHAR_talkToCli( charaindex, -1, "֡", CHAR_COLORWHITE); + return; + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex)) { + CHAR_talkToCli( charaindex, -1, "ôǷûκε,鱨֡", CHAR_COLORWHITE); + return; + } + ITEM_setInt( itemindex, ITEM_MERGEFLG, mode); + + CHAR_talkToCli( charaindex, -1, "׷º뼰ëף", CHAR_COLORWHITE); + + CHAR_sendItemDataOne( charaindex, haveitemindex); +} + +void CHAR_CHAT_DEBUG_effect( int charaindex, char* message ) +{ + int floorid=-1, effectid=-1, level=0; + char buf[ 256]; + int i; + int playernum = CHAR_getPlayerMaxNum(); + BOOL flg = FALSE; + + getStringFromIndexWithDelim( message, " ", 1, buf, sizeof( buf)); + if( strcmp( buf, "alloff" ) == 0 ) { + flg = TRUE; + }else { + floorid = atoi( buf); + if( !getStringFromIndexWithDelim( message, " ", 2, buf, sizeof( buf))) { + return; + } + effectid = atoi( buf); + if( !getStringFromIndexWithDelim( message, " ", 3, buf, sizeof( buf))) { + return; + } + level = atoi( buf); + } + for( i = 0 ; i < playernum; i ++) { + if( CHAR_CHECKINDEX( i)) { + if( CHAR_getInt( i, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + if( flg) { + int ef = CHAR_getWorkInt( i, CHAR_WORKEFFECT); + if( ef != 0 ) { + int fd = getfdFromCharaIndex( i); + lssproto_EF_send( fd, 0, 0, ""); + CHAR_setWorkInt( i, CHAR_WORKEFFECT, 0); + } + } + else if( CHAR_getInt( i, CHAR_FLOOR) == floorid ) { + int fd = getfdFromCharaIndex( i); + lssproto_EF_send( fd, effectid, level, ""); + if( level == 0 ) { + CHAR_setWorkInt( i, CHAR_WORKEFFECT, + CHAR_getWorkInt( i, CHAR_WORKEFFECT) & + ~effectid); + } + else { + CHAR_setWorkInt( i, CHAR_WORKEFFECT, + CHAR_getWorkInt( i, CHAR_WORKEFFECT) | + effectid); + } + } + } + } + } +} + +void CHAR_CHAT_DEBUG_setTrans( int charaindex, char *message) +{ + int i; + char setTrans[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , setTrans, sizeof(setTrans)); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setInt(i, CHAR_TRANSEQUATION, 0); + CHAR_setInt(i, CHAR_TRANSMIGRATION, atoi( setTrans )); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( i, CHAR_WORKOBJINDEX )); + sprintf( token, "[GM]%sתΪ%dת!", CHAR_getChar( charaindex, CHAR_NAME),(int)atoi(setTrans)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sתΪ%dת!", CHAR_getChar( i, CHAR_NAME),(int)atoi(setTrans)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt(charaindex, CHAR_TRANSEQUATION, 0); + CHAR_setInt(charaindex, CHAR_TRANSMIGRATION, atoi( setTrans )); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX )); + sprintf( token, "תΪ%dת!",(int)atoi(setTrans)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } +} + +void CHAR_CHAT_DEBUG_shutup(int charindex ,char *message) +{ + +} + +void CHAR_CHAT_DEBUG_getuser(int charindex ,char *message) //ttom 14/11/2000 +{ // ..NAME|FLOOR| + char buf1[256], name[256], token[256]; + int i, k, MyFloor=-1, colors = CHAR_COLORWHITE; + int user[50]; + int MAXCHARA=0; + BOOL FINDNPC = FALSE; + BOOL MOREs = FALSE; + + memset( name, 0, sizeof( name) ); + MAXCHARA = CHAR_getPlayerMaxNum(); + if( getStringFromIndexWithDelim( message, " ", 1, name, sizeof( name)) == FALSE ) return; + if( getStringFromIndexWithDelim( message, " ", 2, buf1, sizeof( buf1)) != FALSE ){ + MyFloor = atoi( buf1); + } + if( getStringFromIndexWithDelim( message, " ", 3, buf1, sizeof( buf1)) != FALSE ){ + if( strstr( buf1, "npc") != NULL ){ + FINDNPC = TRUE; + MAXCHARA = CHAR_getCharNum(); + } + } + k = 0; + for( i=0; i= 10 )MOREs = TRUE; + } + } + + memset( token, 0, sizeof(token)); + strcpy( token, "MORE:"); + for( i=0; i= sizeof(token) ){ + CHAR_talkToCli( charindex, -1 , token , CHAR_COLORWHITE); + memset( token, 0, sizeof(token)); + strcpy( token, "MORE:"); + } + strcat( token, temp); + continue; + } + } + sprintf( buf1, "NAME:%s UName:%s CDKey:%s Point:[%d,%d,%d]", + CHAR_getChar( userindex, CHAR_NAME), CHAR_getUseName( userindex), + CHAR_getChar( userindex, CHAR_CDKEY), + CHAR_getInt( userindex, CHAR_FLOOR), CHAR_getInt( userindex, CHAR_X), + CHAR_getInt( userindex, CHAR_Y) ); + CHAR_talkToCli( charindex, -1 , buf1 , colors); + } + if( MOREs == TRUE ){ + CHAR_talkToCli( charindex, -1 , token , CHAR_COLORWHITE); + } +} + +void CHAR_CHAT_DEBUG_waeikick( int charindex, char* message ) +{ + char token[256]; + char kcmsg[256],kctalk[256]; + char buf[256]; + BOOL find=FALSE; + int i=0; + unsigned int MAX_USER=0; + int fd_charaindex; + if( strlen(message)==0){ + sprintf(buf,"%s","ȷ-> ʺ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 1 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + + int playernum = CHAR_getPlayerMaxNum(); + for( i=0; i ʺ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 1 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + MAX_USER=getFdnum(); + for(i=0;i FLOOR X Y ʺ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 1 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->ͼ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + fl=atoi( token ); + easyGetTokenFromString( message , 2 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->X "); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + x = atoi( token ); + easyGetTokenFromString( message , 3 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->Y "); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + y = atoi( token ); + easyGetTokenFromString( message , 4 , token, sizeof(token)); + if( strlen(token)==0){ + CHAR_warpToSpecificPoint(charindex, fl, x, y); + return; + } + for(i=0;i clear/add/send Сд"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString(message, 1, cmd, sizeof(cmd)); + if (strcmp(cmd,"clear")==0) { + FILE *f=fopen(ANNOUNCEFILE,"w"); + + strcpy(buf, "ʯʱ\n"); + fwrite(buf, strlen(buf), 1, f); + fclose(f); + LoadAnnounce(); + CHAR_talkToCli(charaindex, -1, "OK", CHAR_COLORWHITE); + } else if (strcmp(cmd,"add")==0) { + FILE *f; + + easyGetTokenFromString(message, 2, say, sizeof(say)); + if (strlen(say)==0) { + sprintf(buf,"%s","ȷ"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + + if (!(f=fopen(ANNOUNCEFILE,"a+"))) { + f=fopen(ANNOUNCEFILE,"w"); + strcpy(buf, "ʯʱ\n"); + fwrite(buf, strlen(buf), 1, f); + } + fwrite(say, strlen(say), 1, f); + fwrite("\n", sizeof(char), 1, f); + fclose(f); + LoadAnnounce(); + CHAR_talkToCli(charaindex, -1, "OK", CHAR_COLORWHITE); + } else if (strcmp(cmd,"send")==0) { + int i; + + for (i=0; i clear/add/send (Сд)"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } +} + +void CHAR_CHAT_DEBUG_checklock( int charaindex, char* message ) +{ + char cmd[256]; + if( strlen(message)==0){ + CHAR_talkToCli(charaindex, -1, "ȷ", CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message, 1, cmd, sizeof(cmd)); + saacproto_ACLock_send( acfd, cmd, 2, getFdidFromCharaIndex( charaindex)); +} + +void CHAR_CHAT_DEBUG_unlock( int charaindex, char* message ) +{ + char cmd[256]; +#ifdef _WAEI_KICK + int act=1; +#endif + + if( strlen(message)==0){ + CHAR_talkToCli(charaindex, -1, "ȷ", CHAR_COLORWHITE); + return; + } + easyGetTokenFromString(message, 1, cmd, sizeof(cmd)); +#ifdef _WAEI_KICK + saacproto_ACKick_send( acfd, cmd, getFdidFromCharaIndex( charaindex), act); +#else + saacproto_ACLock_send( acfd, cmd, 3, getFdidFromCharaIndex( charaindex)); +#endif +} + +void CHAR_CHAT_DEBUG_unlockserver( int charaindex, char* message ) +{ + char cmd[256]; + + if( strlen(message)==0){ + CHAR_talkToCli(charaindex, -1, "ȷ", CHAR_COLORWHITE); + return; + } + easyGetTokenFromString(message, 1, cmd, sizeof(cmd)); + saacproto_ACLock_send( acfd, cmd, 4, getFdidFromCharaIndex( charaindex)); +} + +void CHAR_CHAT_DEBUG_fixfmdata(int charaindex, char *message) +{ + char szCmd[64],szData[64],szFamilyID[8],szID[64]; + int i,index = -1,charindex = -1,iPlayerNum = CHAR_getPlayerMaxNum(); + + if(message == NULL || getStringFromIndexWithDelim(message," ",1,szFamilyID,sizeof(szFamilyID)) == FALSE){ + CHAR_talkToCli(charaindex, -1, "ȷ [fixfmdata <ʺ(or -1)> ]",CHAR_COLORRED); + return; + } + if(message == NULL || getStringFromIndexWithDelim(message," ",2,szID,sizeof(szID)) == FALSE){ + CHAR_talkToCli(charaindex, -1, "ȷ [fixfmdata <ʺ(or -1)> ]",CHAR_COLORRED); + return; + } + if(message == NULL || getStringFromIndexWithDelim(message," ",3,szCmd,sizeof(szCmd)) == FALSE){ + CHAR_talkToCli(charaindex, -1, "ȷ [fixfmdata <ʺ(or -1)> ]",CHAR_COLORRED); + return; + } + if(message == NULL || getStringFromIndexWithDelim(message," ",4,szData,sizeof(szData)) == FALSE){ + CHAR_talkToCli(charaindex, -1, "ȷ [fixfmdata <ʺ(or -1)> ]",CHAR_COLORRED); + return; + } + index = atoi(szFamilyID); + if(index < 1 || index > 1000){ + CHAR_talkToCli(charaindex,-1,"id ֵ", CHAR_COLORRED); + return; + } + index -= 1; + if(szID[0] != '-' && szID[1] != '1'){ + for(i=0;i id]"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + + easyGetTokenFromString(message, 1, cmd, sizeof(cmd)); + if (strcmp(cmd,"allpeace")==0) { +#ifdef _NEW_MANOR_LAW + struct tm tm1; + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); +#endif + CHAR_talkToCli(charaindex, -1, "allpeace", CHAR_COLORWHITE); + easyGetTokenFromString(message, 2, cmd, sizeof(cmd)); + manorid=atoi(cmd); + if ((manorid<1)||(manorid>MANORNUM)) { + sprintf(buf,"%s","ȷ id 1~10 ֮䡣"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + + for (i=0; iMANORNUM)) { + sprintf(buf,"%s","ȷ id 1~9 ֮䡣"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + for (i=0; i id]"); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORWHITE); + } +} + +void CHAR_CHAT_DEBUG_shutdown(int charindex , char *message ) +{ + char token[10]; + int iTime; + easyGetTokenFromString( message , 1 , token, sizeof(token)); + iTime = atoi( token ); + lssproto_Shutdown_recv(0, "hogehoge", iTime); +} + +void CHAR_CHAT_DEBUG_watchevent( int charaindex, char* message ) +{ +#ifdef _ADD_NEWEVENT_1024 + int event_num = 32; +#else +#ifdef _ADD_NEWEVENT // WON + int event_num = 8; +#else + int event_num = 6; +#endif +#endif + + unsigned int max_user = 0; + int charaindex_tmp = 0; + int count = 0, point, ckpoint, i, j; + char token_cdkey[256], token_name[256], cdkey[CDKEYLEN]; + char buf[1024], buf1[64]; + BOOL find = FALSE; + + if( strlen(message)==0 ){ + charaindex_tmp = charaindex; + find=TRUE; + }else{ + getStringFromIndexWithDelim( message, " ", 1, token_cdkey, sizeof( token_cdkey)); + getStringFromIndexWithDelim( message, " ", 2, token_name, sizeof( token_name)); + if( strlen(token_cdkey)==0 || strlen(token_name)==0 ){ + sprintf(buf,"%s","ȷȷʽ[wahctevent ʺ ]"); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORWHITE); + return; + } + max_user = getFdnum(); + for( i=0; i 4 || level < 1 || level > gminfo[i].level) + { + CHAR_talkToCli( charaindex, -1, "޸ʧܣ޷ʺŵȼ޸ĵıԼȼߣlevel(1~3)", CHAR_COLORWHITE); + return; + } + for (i = 0; i < GMMAXNUM; i++) + { + if (strcmp(id, gminfo[i].cdkey) == 0) + { + if (gminfo[i].level > charlevel) + { + snprintf(tmpbuf, sizeof(tmpbuf), "޸ʧܣ޷޸ĵȼԼߵʺţ"); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORWHITE); + return; + } + gminfo[i].level = level; + snprintf(tmpbuf, sizeof(tmpbuf), "޸%sȼΪ%dϣˣ", gminfo[i].cdkey, gminfo[i].level); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORWHITE); + changeflag = 1; + break; + } + } + if (changeflag == 0) + { + snprintf(tmpbuf, sizeof(tmpbuf), "ǣбв޴ʺţ޸ʧܣ"); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORWHITE); + } + } +} +#endif + + +void CHAR_CHAT_DEBUG_checktrade( int charaindex, char*message ) +{ +#ifdef _ITEM_PILEFORTRADE + if( !strcmp( message, "waei" ) ){ + TRADE_CheckTradeListUser(); + } +#endif +} + + +void CHAR_CHAT_DEBUG_cleanfloor( int charaindex, char *message) +{ + char buf[256]; + int floor, objindex, itemnum=0,petnum=0,goldnum=0; + int objmaxnum = OBJECT_getNum(); + + floor = atoi( message); + for( objindex=0; objindex 10000) set_num = 10000; + CHAR_setInt( charaindex, CHAR_GAMBLENUM, set_num); + + sprintf( buf,"ֳΪ%d㡣", CHAR_getInt( charaindex, CHAR_GAMBLENUM)); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + return; +} + +#endif + + +void CHAR_CHAT_DEBUG_petlevelup( int charaindex, char* message ) +{ + int level, petindex, petid, mylevel,i,j; + char buf[10]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + petid=atoi(buf)-1; + easyGetTokenFromString( message , 2 , buf, sizeof(buf)); + level=atoi(buf); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); +#ifdef _TRANS_LEVEL_CF + if(level > getMaxLevel() ) level=getMaxLevel(); +#else + if(level > 140 ) level=140; +#endif + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + petindex = CHAR_getCharPet( i, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "%s%dû!", CHAR_getChar( i, CHAR_NAME),petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + mylevel = CHAR_getInt( petindex, CHAR_LV); + level = level-mylevel; + for( j = 1; j <= level; j ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + CHAR_complianceParameter( petindex ); + CHAR_setInt( petindex , CHAR_HP , CHAR_getWorkInt( petindex , CHAR_WORKMAXHP ) ); + sprintf( token, "[GM]%s%dijΪ%d!", CHAR_getChar( charaindex, CHAR_NAME), + petid+1, CHAR_getInt( petindex, CHAR_LV)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sij%dijΪ%d!", CHAR_getChar( i, CHAR_NAME), + petid+1, CHAR_getInt( petindex, CHAR_LV)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( i, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( i, token ); + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( i, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( i, token ); + }else{ + petindex = CHAR_getCharPet( charaindex, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "ij%dû!", petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + mylevel = CHAR_getInt( petindex, CHAR_LV); + level = level-mylevel; + for( j = 1; j <= level; j ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + CHAR_setInt( petindex , CHAR_HP , CHAR_getWorkInt( petindex , CHAR_WORKMAXHP ) ); + sprintf( token, "ѳ%dijΪ%d!", petid+1, CHAR_getInt( petindex, CHAR_LV)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( charaindex, token ); + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( charaindex, token ); + } +} + +void CHAR_CHAT_DEBUG_petexpup( int charaindex, char* message ) +{ + int petindex, i, petid; + char buf[10]; + char exp[15]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + petid=atoi(buf)-1; + easyGetTokenFromString( message , 2 , exp, sizeof(exp)); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); + + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + petindex = CHAR_getCharPet( i, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "%s%dû!", CHAR_getChar( i, CHAR_NAME),petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + CHAR_setMaxExp( petindex, atoi( exp )); + CHAR_send_P_StatusString( i , CHAR_P_STRING_EXP); + sprintf( token, "[GM]%sľΪ%d!", CHAR_getChar( charaindex, CHAR_NAME),(int)atoi(exp)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sľΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(exp)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + petindex = CHAR_getCharPet( charaindex, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "%s%dû!", CHAR_getChar( i, CHAR_NAME),petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + CHAR_setMaxExp( petindex, atoi( exp )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_EXP); + sprintf( token, "Ϊ%d!",(int)atoi(exp)/100); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } +} + + +void CHAR_CHAT_DEBUG_engineer( int charindex, char *message) +{ + int MaxGold; + if( !CHAR_CHECKINDEX( charindex) ) + return; + if( strstr( message, "waei") == NULL ) + return; +#ifdef _TRANS_6 + if( CHAR_getInt( charindex, CHAR_TRANSMIGRATION) >= 6 ) +#else + if( CHAR_getInt( charindex, CHAR_TRANSMIGRATION) >= 5 ) +#endif + return; + MaxGold = CHAR_getMaxHaveGold( charindex); + CHAR_setInt( charindex, CHAR_LV, 140); + CHAR_setInt( charindex, CHAR_TRANSMIGRATION, 5); + CHAR_setInt( charindex, CHAR_SKILLUPPOINT, 600); + CHAR_setInt( charindex, CHAR_LEARNRIDE, 200); + CHAR_setInt( charindex, CHAR_GOLD, MaxGold); + + CHAR_talkToCli( charindex, -1, message, CHAR_COLORYELLOW); + { + int petTemp[]={1610,-1,-1,-1,-1}; + int add_pet[]={-1,-1,-1,-1,-1}; + int petNum=0; + int i,j; + int k=0, petindex,enemyarray; + j=1; + for( i=0; i< arraysizeof(ridePetTable) ; i++ ){ + if( CHAR_getInt( charindex, CHAR_BASEBASEIMAGENUMBER) == ridePetTable[i].charNo ){ + petTemp[j]= ridePetTable[i].petId; + j++; + if( j >= arraysizeof( petTemp) ) + break; + } + } + j=0; + for( petNum=0; petNum= arraysizeof( gmset) ) { + CHAR_talkToCli(charindex, -1, "ȷ", CHAR_COLORYELLOW); + return; + } + act = i; + // WON FIX 5 --> 6 + if( act < 0 || act > 6 ){ + CHAR_talkToCli(charindex, -1, "ȷ", CHAR_COLORYELLOW); + return; + } + } + saacproto_ACKick_send( acfd, cdkey, getFdidFromCharaIndex( charindex), act); +} +#endif +// WON ADD ָ +void CHAR_CHAT_DEBUG_crash(int charaindex , char *message) +{ + int fd; + + + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + + CHAR_Talk( fd, charaindex, message, 1, 3 ); + +/* + char msg[1]; + printf("\n carsh GMSV !! \n"); + //sprintf( msg, "%s", CHAR_getChar( charaindex, CHAR_NAME ) ); + sprintf( msg, "12345" ); +*/ +} + + +#ifdef _PETSKILL_SETDUCK +void CHAR_CHAT_DEBUG_SetDuck( int charaindex, char *message) +{ + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCK, atoi( message)); + CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER, 100 ); +} +#endif + +#ifdef _TYPE_TOXICATION +void CHAR_CHAT_DEBUG_Toxication( int charaindex, char *message) +{ + int fd = getfdFromCharaIndex( charaindex ); + if( strstr( message, "TRUE") != 0){ + CHAR_talkToCli( charaindex, -1, "ж", CHAR_COLORYELLOW); + setToxication( fd, 1); + }else { + setToxication( fd, 0); + } + +} +#endif + +#ifdef _CHAR_POOLITEM +void CHAR_CHAT_DEBUG_saveditem(int charaindex, char *message) +{ + if( CHAR_SaveDepotItem( charaindex) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ʧܣ", CHAR_COLORYELLOW); + } +} + +void CHAR_CHAT_DEBUG_insertditem(int charaindex, char *message) +{ + if( CHAR_GetDepotItem( -1, charaindex) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + } +} + +void CHAR_CHAT_DEBUG_ShowMyDepotItems( int charaindex, char *message ) +{ + if( !CHAR_CheckDepotItem( charaindex) ){ + char token[256]; + sprintf( token, "δȡòֿ⡣"); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + CHAR_ShowMyDepotItems( charaindex); +} + +void CHAR_CHAT_DEBUG_InSideMyDepotItems( int charaindex, char *message ) +{ + int i, j, itemindex, count=0; + char token[256]; + + if( !CHAR_CheckDepotItem( charaindex) ){ + sprintf( token, "δȡòֿ⡣"); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + + for( i=CHAR_STARTITEMARRAY; i 0 ){ + char buf[256]; + sprintf( buf, "%d ó", delobjnum); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORRED); + } +} + +#ifdef _SEND_EFFECT // WON ADD ACѩЧ +void CHAR_CHAT_DEBUG_sendeffect( int charaindex, char *message) +{ + int i, j, effect, level; + char buf[256]; + struct tm tm1; + int playernum = CHAR_getPlayerMaxNum(); + int player; + int efnum = 0; + + struct { + int floor; + int effect; + BOOL on; + BOOL off; + } ef[2048]; + + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + memset( buf, 0, sizeof( buf)); + + if( getStringFromIndexWithDelim( message, " ", 1, buf, sizeof( buf)) == FALSE ) return; + effect = atoi( buf ); + + if( getStringFromIndexWithDelim( message, " ", 2, buf, sizeof( buf)) == FALSE ) return; + level = atoi( buf ); + + for( i=0; i<=CHAR_effectnum; i++){ + if(CHAR_effect[i].floor){ + CHAR_effect[i].effect = effect; + CHAR_effect[i].level = level; + CHAR_effect[i].sendflg = FALSE; + snprintf( CHAR_effect[i].month , sizeof( CHAR_effect[i].month) , "%d" , tm1.tm_mon+1); + snprintf( CHAR_effect[i].day , sizeof( CHAR_effect[i].day) , "%d" , tm1.tm_mday); + snprintf( CHAR_effect[i].hour , sizeof( CHAR_effect[i].hour) , "%d" , tm1.tm_hour); + snprintf( CHAR_effect[i].min , sizeof( CHAR_effect[i].min) , "%d" , tm1.tm_min); + snprintf( CHAR_effect[i].expire , sizeof( CHAR_effect[i].expire), "300000" ); + }// if + }// for i + + + memset( &ef, 0, sizeof( ef)); + + for( i = 0; i < CHAR_effectnum; i ++){ + if( !CHAR_effect[i].sendflg) { + for( player = 0 ; player < playernum; player ++ ) { + if( !CHAR_CHECKINDEX( player ) ) continue; + if( CHAR_getInt( player, CHAR_FLOOR) == CHAR_effect[i].floor ) { + int fd = getfdFromCharaIndex( player); + lssproto_EF_send( fd, CHAR_effect[i].effect, CHAR_effect[i].level, ""); + if( CHAR_effect[i].level == 0 ) { + CHAR_setWorkInt( player, CHAR_WORKEFFECT, + CHAR_getWorkInt( player, CHAR_WORKEFFECT) & + ~CHAR_effect[i].effect); + }else { + CHAR_setWorkInt( player, CHAR_WORKEFFECT, + CHAR_getWorkInt( player, CHAR_WORKEFFECT) | + CHAR_effect[i].effect); + } + } + } + CHAR_effect[i].sendflg = TRUE; + } + + for( j = 0; j < efnum; j ++ ) { + if( ef[j].floor == CHAR_effect[i].floor && ef[j].effect == CHAR_effect[i].effect) + { + ef[j].on = TRUE; + break; + } + } + if( j == efnum ) { + ef[j].floor = CHAR_effect[i].floor; + ef[j].effect = CHAR_effect[i].effect; + ef[j].on = TRUE; + efnum++; + if( efnum >= arraysizeof( ef)) { + print( "err buffer over %s:%d\n", __FILE__, __LINE__); + efnum --; + } + } + } + + for( i = 0; i < efnum; i ++ ) { + if( ef[i].on == FALSE && ef[i].off == TRUE ) { + for( player = 0 ; player < playernum; player ++ ) { + if( !CHAR_CHECKINDEX( player ) ) continue; + if( CHAR_getInt( player, CHAR_FLOOR) == ef[i].floor ) { + int fd = getfdFromCharaIndex( player); + lssproto_EF_send( fd, 0, 0, ""); + CHAR_setWorkInt( player, CHAR_WORKEFFECT, 0); + } + } + } + } +} +#endif + +void CHAR_CHAT_DEBUG_checktime( int charaindex, char *message) +{ + time_t newsec; + char buf[256]; + char WKday[7][32]={"","һ","","","","",""}; + struct tm *p; + + + newsec = time( NULL); + p = localtime( &newsec); +// newsec = localtime( &newsec); + sprintf( buf, "죺%d%d%d %s %d:%d:%d ...newsec:%ld", + (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, WKday[p->tm_wday], + p->tm_hour, p->tm_min, p->tm_sec, newsec ); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORRED); + //p = (struct tm *)calloc( 1, sizeof( struct tm) ); + //if( p == NULL ) return; + if( getStringFromIndexWithDelim( message, "/", 1, buf, sizeof( buf)) == FALSE ) return; + print("ANDY 1.buf:%s\n", buf); + p->tm_year = atoi( buf)-1900; + if( getStringFromIndexWithDelim( message, "/", 2, buf, sizeof( buf)) == FALSE ) return; + print("ANDY 2.buf:%s\n", buf); + p->tm_mon = atoi( buf)-1; + if( getStringFromIndexWithDelim( message, "/", 3, buf, sizeof( buf)) == FALSE ) return; + print("ANDY 3.buf:%s\n", buf); + p->tm_mday = atoi( buf); + if( getStringFromIndexWithDelim( message, "/", 4, buf, sizeof( buf)) == FALSE ) return; + p->tm_wday = atoi( buf); + if( p->tm_wday < 0 || p->tm_wday >= 7 ) p->tm_wday = 0; + if( getStringFromIndexWithDelim( message, "/", 5, buf, sizeof( buf)) == FALSE ) return; + p->tm_hour = atoi( buf); + if( getStringFromIndexWithDelim( message, "/", 6, buf, sizeof( buf)) == FALSE ) return; + p->tm_min = atoi( buf); + if( getStringFromIndexWithDelim( message, "/", 7, buf, sizeof( buf)) == FALSE ) return; + p->tm_sec = atoi( buf); + + newsec = mktime( p); + sprintf( buf, "ȷ1%d%d%d %s %d:%d:%d ...newsec:%ld", + (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, WKday[p->tm_wday], + p->tm_hour, p->tm_min, p->tm_sec, newsec ); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORRED); + + p = localtime( &newsec); + sprintf( buf, "ȷ2%d%d%d %s %d:%d:%d ...newsec:%ld..time:%d", + (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, WKday[p->tm_wday], + p->tm_hour, p->tm_min, p->tm_sec, newsec, (int)time(NULL)); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORRED); +} + +void CHAR_CHAT_DEBUG_playerspread( int charaindex, char *message) +{ + int i,j; + int playernum = CHAR_getPlayerMaxNum(); +#define CHECKMAPNUMS 100 + struct { + int floor; + int nums; + }MapArray[CHECKMAPNUMS]; + + if(strstr( message, "waei") == NULL ) return; + for( i=0; i 0){ + int i,pclass = CHAR_getInt(charaindex,PROFESSION_CLASS) - 1; + for(i=0;i 0 ){ + array = PROFESSION_SKILL_getskillArray( skillid ); + memset(token, 0, sizeof(token)); + sprintf( token, "P%d(%s) ", i+1, PROFESSION_SKILL_getChar(array, PROFESSION_SKILL_NAME) ); + if( strcmp(token, "") != 0) + strcat( msg, token ); + } + } + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORRED); + } + + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + +} +#endif + +void CHAR_CHAT_DEBUG_samecode( int charaindex, char *message) +{ + char buf1[256], buf2[256]; + char cmd[3][256]={ + "pet", "item", "set" + }; + int type=-1, j, total = 0; + BOOL checkn = FALSE; + int MAXPLAYER = CHAR_getPlayerMaxNum(); + int MAXITEM = ITEM_getITEM_itemnum(); + int MAXPET = CHAR_getPetMaxNum(); + + if( getStringFromIndexWithDelim( message, " ", 1, buf1, sizeof( buf1) ) == FALSE )return; + for( j=0; j<3; j++){ + if( strstr( buf1, cmd[j]) != NULL ){ + type = j; + break; + } + } + if( j >= 3 ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORRED); + return; + } + + switch( type){ + case 0: + if( getStringFromIndexWithDelim( message, " ", 2, buf1, sizeof( buf1) ) == TRUE ){ + checkn = TRUE; + } + for( j=MAXPLAYER; j ʺ "); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + //flg = isstring1or0( token1); + minu = atoi( token1 ); + MAX_USER=getFdnum(); + for(i=0;i--token=%s",token); + if(strcmp(token,cdkey)==0){ + int index = CONNECT_getCharaindex( i ); + //print("\n--find-->cdkey %s",cdkey); + + // Robin + CHAR_setInt(index,CHAR_SILENT, minu*60); + //CHAR_setInt(index,CHAR_SILENT, (int)NowTime.tv_sec +(minu*60) ); + { + CHAR_setWorkInt( index, CHAR_WORKLOGINTIME, (int)NowTime.tv_sec); + } + //print(" set_silent:%s:%dmin ", cdkey, minu); + + //print("\n= 220 ){ + CHAR_talkToCli( charindex, -1, token, CHAR_COLORYELLOW); + strcpy( token, "GMָ:"); + } + strcat( token, buf2); + continue; + }else{ + if( strstr( buf1, buf) != NULL || + strstr( buf2, buf) != NULL ){ + sprintf( token, "GMָ:[%s %s]", buf1, buf2); + CHAR_talkToCli( charindex, -1, token, CHAR_COLORYELLOW); + } + continue; + } + } + if( type == 1 ) + CHAR_talkToCli( charindex, -1, token, CHAR_COLORYELLOW); +} + +#ifdef _EQUIT_NEGLECTGUARD +void CHAR_CHAT_DEBUG_setneguard( int charaindex, char* message ) +{ + int num = atoi( message); + CHAR_setWorkInt( charaindex, CHAR_WORKNEGLECTGUARD, num); +} +#endif + +#ifdef _NEW_MANOR_LAW +void CHAR_CHAT_DEBUG_set_momentum( int charaindex, char* message ) +{ + char szMsg[32],szBuf[16],buf[128],szName[32]; + int i,id,fd,iPlayerNum = CHAR_getPlayerMaxNum(); + + getStringFromIndexWithDelim(message," ",1,szName,sizeof(szName)); + getStringFromIndexWithDelim(message," ",2,szBuf,sizeof(szBuf)); + id = atoi(szBuf); + for(i=0;i= iPlayerNum){ + CHAR_talkToCli(charaindex,-1,"Ҳ",CHAR_COLORYELLOW); + return; + } + CHAR_setInt(i,CHAR_MOMENTUM,id); + sprintf(szMsg,"Ŀǰֵ: %d",CHAR_getInt(i,CHAR_MOMENTUM)/100); + CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORYELLOW); + sprintf(buf,"%d",id); + fd = getfdFromCharaIndex(i); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(i,CHAR_FMNAME),CHAR_getInt(i,CHAR_FMINDEX),CHAR_getWorkInt(i,CHAR_WORKFMINDEXI), + FM_FIX_FMMOMENTUM,buf,"",CHAR_getWorkInt(i,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(fd)); + return; +} +#endif + +void CHAR_CHAT_DEBUG_set_manor_owner( int charindex, char* message ) +{ + int i,index = -1,iUseFlag; + char szId[8],szUseFlag[2],szFamilyNameOrID[64],szToken[4096],szFamilyIndex[8],szGetFamilyName[64]; + + if(message == NULL || getStringFromIndexWithDelim(message," ",1,szId,sizeof(szId)) == FALSE){ + CHAR_talkToCli(charindex,-1, "ȷ [set_manor_owner ׯ԰id(1~10) ʹ(0: 1:id) ƻid]", CHAR_COLORRED); + return; + } + if(atoi(szId) < 1 || atoi(szId) > MANORNUM){ + CHAR_talkToCli(charindex,-1, "ׯ԰IDֵȷ(1~10)", CHAR_COLORRED); + return; + } + if(getStringFromIndexWithDelim(message," ",2,szUseFlag,sizeof(szUseFlag)) == FALSE){ + CHAR_talkToCli(charindex,-1, "ȷ [set_manor_owner ׯ԰id(1~10) ʹ(0: 1:id) ƻid]", CHAR_COLORRED); + return; + } + iUseFlag = atoi(szUseFlag); + if(iUseFlag < 0 || iUseFlag > 1){ + CHAR_talkToCli(charindex,-1, "ʹֵȷ(0: 1:id)", CHAR_COLORRED); + return; + } + if(getStringFromIndexWithDelim(message," ",3,szFamilyNameOrID,sizeof(szFamilyNameOrID)) == FALSE){ + CHAR_talkToCli(charindex,-1, "ȷ [set_manor_owner ׯ԰id(1~10) ʹ(0: 1:id) ƻid]", CHAR_COLORRED); + return; + } + if(iUseFlag == 1){ + // Ƿ + for(i=0;i '9' || szFamilyNameOrID[i] < '0'){ + CHAR_talkToCli(charindex,-1, "idʽ", CHAR_COLORRED); + return; + } + } + for(i=0;;i++){ + if(getStringFromIndexWithDelim(familyListBuf,"|",i,szToken,sizeof(szToken))){ + if((getStringFromIndexWithDelim(szToken," ",1,szFamilyIndex,sizeof(szFamilyIndex))) && + (getStringFromIndexWithDelim(szToken," ",2,szGetFamilyName,sizeof(szGetFamilyName)))){ + if(strcmp(szFamilyNameOrID,szFamilyIndex) == 0){ + index = atoi(szFamilyIndex) - 1; + break; + } + } + } + else break; + } + if(index == -1){ + CHAR_talkToCli(charindex,-1,"Ҳ˼", CHAR_COLORRED); + return; + } + sprintf(szToken,"ׯ԰ %s 趨 %s ",szId,szGetFamilyName); + saacproto_ACFixFMPoint_send(acfd,szGetFamilyName,index+1,index,szGetFamilyName,index+1,index,atoi(szId)); + } + else{ + for(i=0;;i++){ + if(getStringFromIndexWithDelim(familyListBuf,"|",i,szToken,sizeof(szToken))){ + if((getStringFromIndexWithDelim(szToken," ",1,szFamilyIndex,sizeof(szFamilyIndex))) && + (getStringFromIndexWithDelim(szToken," ",2,szGetFamilyName,sizeof(szGetFamilyName)))){ + if(strcmp(szFamilyNameOrID,szGetFamilyName) == 0){ + index = atoi(szFamilyIndex) - 1; + break; + } + } + } + else break; + } + + if(index == -1){ + CHAR_talkToCli(charindex,-1,"Ҳ˼", CHAR_COLORRED); + return; + } + sprintf(szToken,"ׯ԰ %s 趨 %s ",szId,szFamilyNameOrID); + saacproto_ACFixFMPoint_send(acfd,szFamilyNameOrID,index+1,index,szFamilyNameOrID,index+1,index,atoi(szId)); + } + CHAR_talkToCli(charindex,-1,szToken,CHAR_COLORRED); +} + +void CHAR_CHAT_DEBUG_set_schedule_time( int charindex, char* message ) +{ + struct tm tm1; + int i,char_max = CHAR_getCharNum(); + char szId[8],szTime[12],szMsg[128]; + + if(message == NULL || getStringFromIndexWithDelim(message," ",1,szId,sizeof(szId)) == FALSE){ + CHAR_talkToCli(charindex,-1, "ȷ [set_schedule_time ׯ԰id(1~9) ʱ()]", CHAR_COLORRED); + return; + } + if(atoi(szId) < 1 || atoi(szId) > MANORNUM){ + CHAR_talkToCli(charindex,-1, "ׯ԰IDֵȷ", CHAR_COLORRED); + return; + } + if(getStringFromIndexWithDelim(message," ",2,szTime,sizeof(szTime)) == FALSE){ + CHAR_talkToCli(charindex,-1, "ȷ [set_schedule_time ׯ԰id(1~9) ʱ()]", CHAR_COLORRED); + return; + } + for(i=0;i=MAXMISSIONTABLE) { + CHAR_talkToCli( charindex, -1, "Ųȷ", CHAR_COLORYELLOW); + return; + } + if( missiontable[mindex].flag == MISSION_NONE ) { + CHAR_talkToCli( charindex, -1, "޴", CHAR_COLORYELLOW); + return; + } + + saacproto_ACMissionTable_send( acfd, mindex, 3, "", ""); + + sprintf( msg, " GMָ i:%d ʹ:%s :%s m:%d flg:%d time:%d lt:%d ", + mindex, missiontable[mindex].angelinfo, missiontable[mindex].heroinfo, + missiontable[mindex].mission, missiontable[mindex].flag, + missiontable[mindex].time, missiontable[mindex].limittime ); + CHAR_talkToCli( charindex, -1, msg, CHAR_COLORYELLOW); + LogAngel( msg); +} + +void CHAR_CHAT_DEBUG_angelcreate(int charindex ,char *message) // ʹ +{ + char angelid[256], heroid[256], buf[256]; + int i; + int MAXCHARA=0; + int angelindex =-1, heroindex =-1, mission =-1; + + if( getStringFromIndexWithDelim( message, " ", 1, angelid, sizeof(angelid) ) == FALSE ){ + CHAR_talkToCli( charindex, -1, "ȷ [angelcreate ʹʺ ʺ ]", CHAR_COLORRED); + return; + } + if( getStringFromIndexWithDelim( message, " ", 2, heroid, sizeof(heroid) ) == FALSE ){ + CHAR_talkToCli( charindex, -1, "ȷ [angelcreate ʹʺ ʺ ]", CHAR_COLORRED); + return; + } + if( getStringFromIndexWithDelim( message, " ", 3, buf, sizeof(buf) ) == FALSE ){ + CHAR_talkToCli( charindex, -1, "ȷ [angelcreate ʹʺ ʺ ]", CHAR_COLORRED); + return; + } + mission = atoi( buf); + //if( mission <= 0 || mission >= MAXMISSION || missionlist[mission].id <= 0) { + if( mission >= MAXMISSION ) { + CHAR_talkToCli( charindex, -1, "Ųȷ", CHAR_COLORRED); + return; + } + + MAXCHARA = CHAR_getPlayerMaxNum(); + for( i=0; i 3 ){ + sprintf(buf,"%s","û Χ Χƣ1~3"); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + return; + } + floor=CHAR_getInt( charaindex, CHAR_FLOOR ); + x=CHAR_getInt( charaindex, CHAR_X ); + y=CHAR_getInt( charaindex, CHAR_Y ); + for(i=y-area;i<=y+area;i++){ + for(j=x-area;j<=x+area;j++){ + for( object = MAP_getTopObj(floor,j,i) ; object ;object = NEXT_OBJECT(object ) ){ + o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_CHARA ){ + chara_index=OBJECT_getIndex(o); + if(CHAR_CHECKINDEX(chara_index) == FALSE) continue; + if( CHAR_getInt( chara_index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) continue; + if( chara_index == charaindex ) continue; //ҵԼ + getnum++; + snprintf( line, sizeof( line), "%dҵ[%s]ʺ[%s]",getnum,CHAR_getChar(chara_index, CHAR_NAME),CHAR_getChar(chara_index, CHAR_CDKEY)); + CHAR_talkToCli( charaindex, -1,line, CHAR_COLORRED); + } + } + } + } + if(!getnum) CHAR_talkToCli( charaindex, -1, " Χû", CHAR_COLORYELLOW); +} +#endif + +#ifdef _DEF_NEWSEND +void CHAR_CHAT_DEBUG_newsend(int charindex ,char *message) +{ + char buf[256]; + char token[100]; + char szName[256]; + char cdkey[CDKEYLEN]; + char line[256]; + char say[128]; + int fl,x,y,i; + unsigned int MAX_USER=0; + MAX_USER=getFdnum(); + if( strlen(message)==0){ + sprintf(buf,"%s","ȷ-> FLOOR X Y /Ҫ˵Ļ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 1 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->ͼ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + fl=atoi( token ); + easyGetTokenFromString( message , 2 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->X "); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + x = atoi( token ); + easyGetTokenFromString( message , 3 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->Y "); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + y = atoi( token ); + easyGetTokenFromString( message , 4 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->ʺ"); + CHAR_talkToCli( charindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 5 , say , sizeof(say)); + + for(i=0;i FLOOR X Y ʺ /Ҫ˵Ļ"); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 1 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->ͼ"); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + tofl=atoi( token ); + easyGetTokenFromString( message , 2 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->X "); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + toX = atoi( token ); + easyGetTokenFromString( message , 3 , token, sizeof(token)); + if( strlen(token)==0){ + sprintf(buf,"%s","ȷ-->Y "); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + toY = atoi( token ); + easyGetTokenFromString( message , 4 , cdkeytoken , sizeof(cdkeytoken)); + if( strlen(cdkeytoken)==0){ + sprintf(buf,"%s","ȷ-->ʺ"); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 5 , token, sizeof(token)); + area = atoi( token ); + if( strlen(token)==0 || area <= 0 || area > 3 ){ + sprintf(buf,"%s","ȷ-->(1~3)"); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORWHITE); + return; + } + easyGetTokenFromString( message , 6 , say , sizeof(say)); //˵ + + MAX_USER=getFdnum(); + for(k=0;k0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setWorkInt( i, CHAR_WORKFONTSIZE, atoi( fsize )); + //CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_LV); + sprintf( token, "[GM]%sΪ%d!", CHAR_getChar( charaindex, CHAR_NAME),atoi(fsize)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sΪ%d!", CHAR_getChar( i, CHAR_NAME),(int)atoi(fsize)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKFONTSIZE, atoi( fsize )); + sprintf( token, "Ϊ%d!",(int)atoi(fsize)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } +} +#endif + +#ifdef _JOBDAILY +void CHAR_CHAT_DEBUG_rejobdaily(int charaindex ,char *message) +{ + print("Reading Jobdaily File..."); + CHAR_talkToCli( charaindex, -1, "¶ȡ־б...", CHAR_COLORYELLOW); + if(!LoadJobdailyfile()){ + CHAR_talkToCli( charaindex, -1, "ȡʧ", CHAR_COLORYELLOW); + print("fail!!\n"); + return; + } + print("done\n"); + CHAR_talkToCli( charaindex, -1, "ȡ", CHAR_COLORYELLOW); +} +#endif + +#ifdef _CREATE_MM_1_2 +void CHAR_CHAT_DEBUG_MM( int charaindex , char *message ) +{ + int ret; + int enemynum; + int enemyid; + int index; + int i,j; + int work[4]={50,50,50,50}; + int LevelUpPoint; + char buf[10]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + index=atoi(buf); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(index==1)enemyid=1479; + else if(index==2)enemyid=2547; + else{ + CHAR_talkToCli( charaindex, -1, "Ŀǰֻ1/2ٷ!", CHAR_COLORYELLOW ); + return;} + + if(strlen(cdkey)>0){ + for(j=0;j=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + ret = ENEMY_createPetFromEnemyIndex( j, i); + if( !CHAR_CHECKINDEX( ret))return; + snprintf( token,sizeof( token), "Ʒ%dٷųɹ!",index); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + sprintf( token, "[GM]%sֻƷ%dٷŸ!", CHAR_getChar( charaindex, CHAR_NAME),index); + CHAR_talkToCli( j, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sֻƷ%dٷ!", CHAR_getChar( j, CHAR_NAME),index); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( j, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE )return; + + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( j, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( j, token ); + int k; + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + for( k = 1; k < 79; k ++ ){ // + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + CHAR_complianceParameter( ret ); + CHAR_setInt( ret , CHAR_HP ,CHAR_getWorkInt( ret, CHAR_WORKMAXHP ) ); + CHAR_setInt( ret , CHAR_MP ,CHAR_getWorkInt( ret, CHAR_WORKMAXMP ) ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( j, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( j, token ); + }else{ + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + ret = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( !CHAR_CHECKINDEX( ret))return; + snprintf( token,sizeof( token), "Ʒ%dٷųɹ!",index); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE )return; + + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + int k; + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + for( k = 1; k < 79; k ++ ){ // + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + CHAR_complianceParameter( ret ); + CHAR_setInt( ret , CHAR_HP ,CHAR_getWorkInt( ret, CHAR_WORKMAXHP ) ); + CHAR_setInt( ret , CHAR_MP ,CHAR_getWorkInt( ret, CHAR_WORKMAXMP ) ); + CHAR_complianceParameter( ret ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); + } +} +#endif + +#ifdef _SendTo +void CHAR_CHAT_DEBUG_Sendto( int charaindex , char *message ) +{ + char cdkey[CDKEYLEN]; + int i; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + if(!strcmp(CHAR_getChar(i,CHAR_CDKEY),cdkey)) + { + CHAR_DischargePartyNoMsg( charaindex);//ɢŶ + int floor, x, y; + char token[256]; + floor = CHAR_getInt( i, CHAR_FLOOR); + x = CHAR_getInt( i, CHAR_X); + y = CHAR_getInt( i, CHAR_Y); + + CHAR_warpToSpecificPoint( charaindex, floor, x, y ); + sprintf( token, "Ѵ͵%sߣ", CHAR_getChar( i, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + return; + } + } +} +#endif + +#ifdef _GM_ITEM +void CHAR_CHAT_DEBUG_GMFUNCTION( int charindex , char *message ) +{ + int i; + char gmtime[4]; + char gmfunction[16]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , gmfunction, sizeof(gmfunction)); + easyGetTokenFromString( message , 2 , gmtime, sizeof(gmtime)); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + CHAR_setChar( i , CHAR_GMFUNCTION, gmfunction ); + CHAR_setInt( i , CHAR_GMTIME, atoi( gmtime ) ); + sprintf( token, "[GM]%sʹ%sȨ%d!",CHAR_getChar( charindex, CHAR_NAME), gmfunction, atoi( gmtime )); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "ʹ鿴[help %s]GM!",CHAR_getChar( charindex, CHAR_GMFUNCTION)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sʹ%sȨ%d!", CHAR_getChar( i, CHAR_NAME), gmfunction, atoi( gmtime )); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + CHAR_setChar( charindex , CHAR_GMFUNCTION, gmfunction ); + CHAR_setInt( charindex , CHAR_GMTIME, atoi( gmtime ) ); + sprintf( token, "ʹ%sȨ%d!", gmfunction,atoi( gmtime )); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} +#endif + +#ifdef _GM_RIDE +void CHAR_CHAT_DEBUG_SETRIDE( int charindex , char *message ) +{ + int i,rideindex; + char buf[16]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + rideindex=atoi(buf); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(rideindex<1 || rideindex>12) + { + CHAR_talkToCli( charindex, -1,"űΪ1~12", CHAR_COLORRED ); + return; + } + typedef struct{ + char name[CHARNAMELEN]; + int Code; + }tagNewRideCode; + tagNewRideCode NewRides[12]={ + { "", RIDE_PET0}, + { "Ħ˹", RIDE_PET1}, + { "˹", RIDE_PET2}, + { "³", RIDE_PET3}, + { "˹", RIDE_PET4}, + { "³˹", RIDE_PET5}, + { "", RIDE_PET6}, + { "", RIDE_PET7}, + { "˹", RIDE_PET8}, + { "Ͷ", RIDE_PET9}, + { "ʷ³", RIDE_PET10}, + { "޶", RIDE_PET11} + }; + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + int LRCode = CHAR_getInt( i, CHAR_LOWRIDEPETS); + + LRCode = LRCode|NewRides[rideindex-1].Code; + CHAR_setInt( i, CHAR_LOWRIDEPETS, LRCode); + + sprintf( token, "[GM]%s%sʸ!",CHAR_getChar( charindex, CHAR_NAME), NewRides[rideindex-1].name); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%s%sʸ!", CHAR_getChar( i, CHAR_NAME), NewRides[rideindex-1].name); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + int LRCode = CHAR_getInt( charindex, CHAR_LOWRIDEPETS); + LRCode = LRCode|NewRides[rideindex-1].Code; + CHAR_setInt( charindex, CHAR_LOWRIDEPETS, LRCode); + + sprintf( token, "%sʸ!", NewRides[rideindex-1].name); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } + CHAR_sendStatusString( charindex, "x"); +} + +void CHAR_CHAT_DEBUG_MVRIDE( int charindex , char *message ) +{ + int i,rideindex; + char buf[16]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + rideindex=atoi(buf); + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(rideindex<1 || rideindex>12) + { + CHAR_talkToCli( charindex, -1,"űΪ1~12", CHAR_COLORRED ); + return; + } + typedef struct{ + char name[CHARNAMELEN]; + int Code; + }tagNewRideCode; + tagNewRideCode NewRides[]={ + { "", RIDE_PET0}, + { "Ħ˹", RIDE_PET1}, + { "˹", RIDE_PET2}, + { "³", RIDE_PET3}, + { "˹", RIDE_PET4}, + { "³˹", RIDE_PET5}, + { "", RIDE_PET6}, + { "", RIDE_PET7}, + { "˹", RIDE_PET8}, + { "Ͷ", RIDE_PET9}, + { "ʷ³", RIDE_PET10}, + { "޶", RIDE_PET11} + }; + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + int LRCode = CHAR_getInt( i, CHAR_LOWRIDEPETS); + + LRCode = LRCode^NewRides[rideindex-1].Code; + CHAR_setInt( i, CHAR_LOWRIDEPETS, LRCode); + + sprintf( token, "[GM]%sƳ%sʸ!",CHAR_getChar( charindex, CHAR_NAME), NewRides[rideindex-1].name); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "Ƴ%s%sʸ!!", CHAR_getChar( i, CHAR_NAME), NewRides[rideindex-1].name); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + }else{ + int LRCode = CHAR_getInt( charindex, CHAR_LOWRIDEPETS); + LRCode = LRCode^NewRides[rideindex-1].Code; + CHAR_setInt( charindex, CHAR_LOWRIDEPETS, LRCode); + + sprintf( token, "Ƴ%sʸ!", NewRides[rideindex-1].name); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } + CHAR_sendStatusString( charindex, "x"); +} +#endif + +#ifdef _LOCK_IP +void CHAR_CHAT_DEBUG_ADD_LOCK( int charindex , char *message ) +{ + int flag; + char buf[16]; + char cdkey[16]=""; + char IP[16]=""; + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + flag=atoi(buf); + if(flag<=1){ + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + }else if(flag==2){ + easyGetTokenFromString( message , 2 , IP, sizeof(IP)); + }else{ + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + easyGetTokenFromString( message , 3 , IP, sizeof(IP)); + } + saacproto_LockLogin_send(acfd, cdkey, IP, 1); +} + +void CHAR_CHAT_DEBUG_DEL_LOCK( int charindex , char *message ) +{ + int flag; + char buf[16]; + char cdkey[16]=""; + char IP[16]=""; + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + flag=atoi(buf); + if(flag<=1){ + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + }else if(flag==2){ + easyGetTokenFromString( message , 2 , IP, sizeof(IP)); + }else{ + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + easyGetTokenFromString( message , 3 , IP, sizeof(IP)); + } + saacproto_LockLogin_send(acfd, cdkey, IP, 0); +} + +void CHAR_CHAT_DEBUG_SHOWIP( int charindex , char *message ) +{ + int MAX_USER = getFdnum(); + int i; + char token[64]; + char cdkey[CDKEYLEN]; + if(strlen(message)>0){ + for(i=0;i=MAX_USER) + { + CHAR_talkToCli( charindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + + unsigned long ip; + int a,b,c,d; + // Arminius: limit ip + ip=CONNECT_get_userip(i); + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + sprintf( token, "˺%sIP %d.%d.%d.%d",message, a,b,c,d); + CHAR_talkToCli( charindex, -1,token, CHAR_COLORYELLOW ); + } +} +#endif + +void CHAR_CHAT_DEBUG_SET_FAME( int charaindex, char* message ) +{ + char szMsg[32],szBuf[16],buf[128],cdkey[CDKEYLEN]; + int i,id,fd,iPlayerNum = CHAR_getPlayerMaxNum(); + + getStringFromIndexWithDelim(message," ",1,cdkey,sizeof(cdkey)); + getStringFromIndexWithDelim(message," ",2,szBuf,sizeof(szBuf)); + id = atoi(szBuf); + for(i=0;i= iPlayerNum){ + CHAR_talkToCli(charaindex,-1,"Ҳ",CHAR_COLORYELLOW); + return; + } + CHAR_setInt(i,CHAR_FAME,id); + sprintf(szMsg,"Ŀǰֵ: %d",CHAR_getInt(i,CHAR_FAME)/100); + CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORYELLOW); + sprintf(buf,"%d",id); + fd = getfdFromCharaIndex(i); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(i,CHAR_FMNAME),CHAR_getInt(i,CHAR_FMINDEX),CHAR_getWorkInt(i,CHAR_WORKFMINDEXI), + FM_FIX_FMFEED,buf,"",CHAR_getWorkInt(i,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(fd)); + return; +} + +#ifdef _AUTO_PK +void CHAR_CHAT_DEBUG_SET_AUTOPK( int charaindex, char* message ) +{ + char szMsg[256]; + sprintf(szMsg,"PKʱΪ%d!",atoi(message)); + CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORYELLOW); + AutoPk_PKTimeSet(atoi(message)); + AutoPk_GetAwardStr(); +} +#endif + +#ifdef _PLAYER_NUM +void CHAR_CHAT_DEBUG_SET_PLAYERNUM( int charaindex, char* message ) +{ + setPlayerNum(atoi(message)); +} +#endif + +#ifdef _RELOAD_CF +void CHAR_CHAT_DEBUG_SET_RELOADCF( int charaindex, char* message ) +{ + if(readconfigfile(getConfigfilename())) + CHAR_talkToCli(charaindex,-1,"OK",CHAR_COLORYELLOW); +} +#endif + +#ifdef _TRANS +void CHAR_CHAT_DEBUG_Trans( int charaindex, char *message) +{ + int i; + int Trans; + char cdkey[CDKEYLEN]; + char token[128]; + int work[10]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + Trans=CHAR_getInt(i,CHAR_TRANSMIGRATION)+1; + if(Trans>7 || CHAR_getInt(i,CHAR_LV)<80){ + sprintf( token, "תȼС80[GM]%sΪתʧ!", CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%sתȼС80%dתʧ!", CHAR_getChar( i, CHAR_NAME),Trans); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + return; + }else{ + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( i, CHAR_WORKOBJINDEX )); + sprintf( token, "[GM]%sΪת%dת!", CHAR_getChar( charaindex, CHAR_NAME),Trans); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "Ϊ%sתΪ%dת!", CHAR_getChar( i, CHAR_NAME),Trans); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + charaindex=i; + } + }else{ + Trans=CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)+1; + if(Trans>7 || CHAR_getInt(charaindex,CHAR_LV)<80){ + sprintf( token, "תȼС80תʧ!"); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + return; + }else{ + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex, CHAR_WORKOBJINDEX )); + sprintf( token, "ΪԼתΪ%dת!",Trans); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + } + } +#ifdef _ADD_POOL_ITEM // WON ADD ӿɼķŵĵ + int tran_pool_item[5] = { 4, 4, 4, 4, 4 }; // ӵĵ߼ķ + int tran_pool_pet[5] = { 2, 2, 2, 2, 2}; // ӵijķ + int j,item_sum=0, pet_sum=0; + + for(j=0; j<5 ;j++){ + item_sum += tran_pool_item[j] ; + pet_sum += tran_pool_pet[j]; + } + + item_sum += 10; // ļĵ + pet_sum += 5; // ļij + +#endif + NPC_TransmigrationStatus(charaindex, charaindex, work); + NPC_TransmigrationFlg_CLS(charaindex, charaindex); + CHAR_setInt(charaindex ,CHAR_TRANSMIGRATION, Trans); + CHAR_setInt(charaindex, CHAR_LV ,1); + CHAR_setMaxExp( charaindex, 0); + CHAR_setInt( charaindex,CHAR_SKILLUPPOINT,CHAR_getInt( charaindex, CHAR_TRANSMIGRATION)*10); + CHAR_Skillupsend( charaindex ); + CHAR_setInt( charaindex,CHAR_RIDEPET, -1 ); + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , CHAR_getInt( charaindex , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_sendStatusString( charaindex , "P"); +} +#endif + +#ifdef _FUSIONBEIT_FIX +void CHAR_CHAT_DEBUG_fusionbeit( int charaindex, char* message ) +{ + int petindex, petid,i; + char buf[10]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + petid=atoi(buf)-1; + easyGetTokenFromString( message , 2 , cdkey, sizeof(cdkey)); + if(strlen(cdkey)>0){ + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + petindex = CHAR_getCharPet( i, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "%s%dû!", CHAR_getChar( i, CHAR_NAME),petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( petindex, CHAR_FUSIONBEIT ,0); + sprintf( token, "[GM]%sΪϵĵ%dֻȥںϳ!", CHAR_getChar( charaindex, CHAR_NAME),petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "Ϊ%sϵĵ%dֻȥںϳ!", CHAR_getChar( i, CHAR_NAME),petid+1); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( i, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( i, token ); + + }else{ + petindex = CHAR_getCharPet( charaindex, petid); + if( !CHAR_CHECKINDEX( petindex) ){ + sprintf( token, "ij%dû!", petid+1); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + return; + } + CHAR_setInt( petindex, CHAR_FUSIONBEIT ,0); + sprintf( token, "ϵĵ%dֻȥںϳ!", petid+1); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", petid ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", petid ); + CHAR_sendStatusString( charaindex, token ); + } +} +#endif + +#ifdef _MAKE_PET_CF +void CHAR_CHAT_DEBUG_petmakecf( int charaindex, char* message ) +{ + int enemynum; + int enemyid; + int i,j; + int level=-1; + int trans=0; + float chengzhang=0.0; + char buf[10],buf1[10]; + char cdkey[CDKEYLEN]; + char token[128]; + int playernum = CHAR_getPlayerMaxNum(); + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + enemyid=atoi(buf); + easyGetTokenFromString( message , 2 , buf, sizeof(buf)); + getStringFromIndexWithDelim(buf,"/",1,buf1,sizeof(buf1)); + chengzhang=atof(buf1)-1.0; + //if(chengzhang>9.0)chengzhang=9.0; + getStringFromIndexWithDelim(buf,"/",2,buf1,sizeof(buf1)); + level=atoi(buf1); + getStringFromIndexWithDelim(buf,"/",3,buf1,sizeof(buf1)); + trans=atoi(buf1); + easyGetTokenFromString( message , 3 , cdkey, sizeof(cdkey)); + + if(strlen(cdkey)>0){ + for(j=0;j=playernum) + { + CHAR_talkToCli( charaindex, -1, "˺Ų~", CHAR_COLORYELLOW ); + return; + } + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + int petindex = ENEMY_createPetFromEnemyIndex( j, i); + if( !CHAR_CHECKINDEX( petindex))return; + CHAR_setInt(petindex,CHAR_VARIABLEAI,10000); + sprintf( token, "[GM]%s%s!", CHAR_getChar( charaindex, CHAR_NAME),ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( j, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "%s%sɹ!", CHAR_getChar( j, CHAR_NAME),ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORYELLOW ); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( j, i ) == petindex )break; + } + if( i == CHAR_MAXPETHAVE )return; + + if( CHAR_CHECKINDEX( petindex ) == TRUE ){ + CHAR_setMaxExpFromLevel( petindex, CHAR_getInt(petindex, CHAR_LV )); + } + + + { + + int vital=CHAR_getInt( petindex, CHAR_VITAL); + int str=CHAR_getInt( petindex, CHAR_STR); + int tough=CHAR_getInt( petindex, CHAR_TOUGH); + int dex=CHAR_getInt( petindex, CHAR_DEX); + int LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + int work[4]; + float fRand=0.0, cvitl=0.0, cstr=0.0, ctough=0.0, cdex=0.0; + float rnd=(rand()%5+95)/100.0; + float Param[4] = { 0.0, 0.0, 0.0, 0.0 }; + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + struct _RankRandTbl{ + int min; + int max; + }RankRandTbl[] = { + { 450, 500 }, + { 470, 520 }, + { 490, 540 }, + { 510, 560 }, + { 530, 580 }, + { 550, 600 }, + }; + int petrank = CHAR_getInt( petindex, CHAR_PETRANK ); + if( petrank < 0 || petrank > 5 ) petrank = 0; + + int i; + for(i=0;i<160;i++){ + fRand = (float)RAND( RankRandTbl[petrank].min, RankRandTbl[petrank].max ) * 0.01; + cvitl += (float)work[3] * fRand + Param[0] * fRand; + cstr += (float)work[0] * fRand + Param[1] * fRand; + ctough += (float)work[1] * fRand + Param[2] * fRand; + cdex += (float)work[2] * fRand + Param[3] * fRand; + } + + rnd=((cstr-str)/80.0/160.0+(ctough-tough)/80.0/160.0+(cdex-dex)/100.0/160.0); + + work[3]*=(chengzhang/rnd); + work[0]*=(chengzhang/rnd); + work[1]*=(chengzhang/rnd); + work[2]*=(chengzhang/rnd); + + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + + CHAR_setInt( petindex, CHAR_VITAL, vital); + CHAR_setInt( petindex, CHAR_STR, str); + CHAR_setInt( petindex, CHAR_TOUGH, tough); + CHAR_setInt( petindex, CHAR_DEX, dex); + + } + + if( level != -1 ){ +#ifdef _TRANS_LEVEL_CF + if( level > getMaxLevel() ) level = getMaxLevel(); +#else + if( level > 140 ) level = 140; +#endif + if( level < 0 ) level = 0; + level = level - CHAR_getInt( petindex, CHAR_LV ); + if( level > 0 ){ + int k; + for( k = 1; k <= level; k ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + } + } + CHAR_setInt( i, CHAR_HP, CHAR_getWorkInt( i, CHAR_WORKMAXHP )); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( j, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( j, token ); + }else{ + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + int petindex = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( !CHAR_CHECKINDEX( petindex))return; + CHAR_setInt(petindex,CHAR_VARIABLEAI,10000); + snprintf( token,sizeof( token), "%sɹ!",ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == petindex )break; + } + if( i == CHAR_MAXPETHAVE )return; + + if( CHAR_CHECKINDEX( petindex ) == TRUE ){ + CHAR_setMaxExpFromLevel( petindex, CHAR_getInt( petindex, CHAR_LV )); + } + + { + + int vital=CHAR_getInt( petindex, CHAR_VITAL); + int str=CHAR_getInt( petindex, CHAR_STR); + int tough=CHAR_getInt( petindex, CHAR_TOUGH); + int dex=CHAR_getInt( petindex, CHAR_DEX); + int LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + int work[4]; + float fRand=0.0, cvitl=0.0, cstr=0.0, ctough=0.0, cdex=0.0; + float rnd=0.0; + float Param[4] = { 0.0, 0.0, 0.0, 0.0 }; + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + struct _RankRandTbl{ + int min; + int max; + }RankRandTbl[] = { + { 450, 500 }, + { 470, 520 }, + { 490, 540 }, + { 510, 560 }, + { 530, 580 }, + { 550, 600 }, + }; + int petrank = CHAR_getInt( petindex, CHAR_PETRANK ); + if( petrank < 0 || petrank > 5 ) petrank = 0; + + int i; + for(i=0;i<160;i++){ + fRand = (float)RAND( RankRandTbl[petrank].min, RankRandTbl[petrank].max ) * 0.01; + cvitl += (float)work[3] * fRand + Param[0] * fRand; + cstr += (float)work[0] * fRand + Param[1] * fRand; + ctough += (float)work[1] * fRand + Param[2] * fRand; + cdex += (float)work[2] * fRand + Param[3] * fRand; + } + + rnd=((cstr-(float)str)/80.0/160.0+(ctough-(float)tough)/80.0/160.0+(cdex-(float)dex)/100.0/160.0); + + printf("chengzhang:%f,chengzhang:%f\n",chengzhang,rnd); + + work[3]*=(chengzhang/rnd); + work[0]*=(chengzhang/rnd); + work[1]*=(chengzhang/rnd); + work[2]*=(chengzhang/rnd); + + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + + CHAR_setInt( petindex, CHAR_VITAL, vital); + CHAR_setInt( petindex, CHAR_STR, str); + CHAR_setInt( petindex, CHAR_TOUGH, tough); + CHAR_setInt( petindex, CHAR_DEX, dex); + + } + if( level != -1 ){ + if( level > 200 )level = 200; + if( level < 0 ) level = 0; + level = level - CHAR_getInt( petindex, CHAR_LV ); + if( level > 0 ){ + int k; + for( k = 1; k <= level; k ++ ){ // + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, CHAR_getInt( petindex, CHAR_LV) +1 ); + } + } + } + CHAR_setInt( petindex, CHAR_TRANSMIGRATION, trans); + CHAR_setInt( petindex, CHAR_HP, CHAR_getWorkInt( petindex, CHAR_WORKMAXHP )); + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); + } +} +#endif + +#ifdef _MAKE_PET_ABILITY +void CHAR_CHAT_DEBUG_petmakeabi( int charaindex, char* message ) +{ + int ret; + int enemynum; + int enemyid; + int i; + char buf[10]; + int vital,str,tough,dex, level, trans; + char token[128]; + easyGetTokenFromString( message , 1 , buf, sizeof(buf)); + enemyid=atoi(buf); + easyGetTokenFromString( message , 2 , buf, sizeof(buf)); + vital=atoi(buf); + easyGetTokenFromString( message , 3 , buf, sizeof(buf)); + str=atoi(buf); + easyGetTokenFromString( message , 4 , buf, sizeof(buf)); + tough=atoi(buf); + easyGetTokenFromString( message , 5 , buf, sizeof(buf)); + dex=atoi(buf); + easyGetTokenFromString( message , 6 , buf, sizeof(buf)); + level=atoi(buf); + easyGetTokenFromString( message , 7 , buf, sizeof(buf)); + trans=atoi(buf); + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum )return; + + ret = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( !CHAR_CHECKINDEX( ret))return; + + snprintf( token,sizeof( token), "%sɹ!",ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORWHITE); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE )return; + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setInt( ret, CHAR_VITAL, vital); + CHAR_setInt( ret, CHAR_STR, str*80); + CHAR_setInt( ret, CHAR_TOUGH, tough*80); + CHAR_setInt( ret, CHAR_DEX, dex*100); + //õȼ + CHAR_setInt( ret, CHAR_LV, level); + //ת + CHAR_setInt( ret, CHAR_TRANSMIGRATION, trans); + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_complianceParameter( ret ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); +} + +#endif + + +#ifdef _PLAYER_QUESTION_ONLIEN +extern PlayerQuestion_t PlayerQuestion; +void CHAR_CHAT_DEBUG_PlayerQuestion( int charaindex, char* message ) +{ + char tmp[64]; + char token[128]; + char type[5][32]={"ʯ","","","",""}; + if(getStringFromIndexWithDelim(message," ",1, PlayerQuestion.question, sizeof(PlayerQuestion.question))== FALSE){ + CHAR_talkToCli( charaindex, -1, "!", CHAR_COLORRED); + } + if(getStringFromIndexWithDelim(message," ",2, PlayerQuestion.result, sizeof(PlayerQuestion.result))== FALSE){ + CHAR_talkToCli( charaindex, -1, "!", CHAR_COLORRED); + } + if(getStringFromIndexWithDelim(message," ",3, tmp, sizeof(tmp))== FALSE){ + CHAR_talkToCli( charaindex, -1, "ĽƷ(0Ϊʯ,1Ϊ,2Ϊ,3Ϊ,4Ϊ!", CHAR_COLORRED); + }else{ + PlayerQuestion.type = min(max(0, atoi(tmp)), 4); + } + if(getStringFromIndexWithDelim(message," ",4, tmp, sizeof(tmp))== FALSE){ + sprintf(token, "ĽƷ%s!", type[PlayerQuestion.type]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORRED); + }else{ + PlayerQuestion.value = atoi(tmp); + } + + { + int i; + int playernum = CHAR_getPlayerMaxNum(); + char question[128]; + sprintf(question, "[GM]⡪%s", PlayerQuestion.question); + sprintf(token, "һλشȷ߽%s %d", type[PlayerQuestion.type], PlayerQuestion.value); + + + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ){ + CHAR_talkToCli( i, -1, question, CHAR_COLORRED); + CHAR_talkToCli( i, -1, token, CHAR_COLORRED); + } + } + } + + +} + +#endif + +#ifdef _GM_SAVE_ALL_CHAR +void CHAR_CHAT_DEBUG_GmSaveAllChar( int charaindex, char* message ) +{ + int i; + CHAR_talkToCli( charaindex, -1, "ڱ,Ժ~", CHAR_COLORRED); + for( i=0; i MAX_TRANS) + nTrans = 0; + + if (getStringFromIndexWithDelim(message, " ", 2, szBuf1, sizeof(szBuf1)) == FALSE) + { + CHAR_talkToCli(charaindex, -1, "ȷ [petmaketrans ת ID ȼ ]", CHAR_COLORRED); + return; + } + nEnemyid = atoi(szBuf1); + if (getStringFromIndexWithDelim(message, " ", 3, szBuf1, sizeof(szBuf1)) == FALSE) + { + CHAR_talkToCli(charaindex, -1, "ȷ [petmaketrans ת ID ȼ ]", CHAR_COLORRED); + return; + } + nLevel = atoi(szBuf1); + if (getStringFromIndexWithDelim(message, " ", 4, szBuf1, sizeof(szBuf1)) != FALSE) + nMakeNum = atoi(szBuf1); + else + nMakeNum = 0; + nEenemynum = ENEMY_getEnemyNum(); + nEnemyID = -1; + for (i = 0; i < nEenemynum; i ++) + { + if (ENEMY_getInt(i, ENEMY_ID) == nEnemyid) + { + nEnemyID = i; + break; + } + } + if (nEnemyID == -1) + { + CHAR_talkToCli(charaindex, -1, "nEnemyID error", CHAR_COLORRED); + return; + } + + if (nMakeNum == 0) // IJ + { + nPetIndex = ENEMY_createPetFromEnemyIndex(charaindex, nEnemyID); + if (!CHAR_CHECKINDEX(nPetIndex)) + { + sprintf(szMsgbuf, "CHAR_CHECKINDEX(%d) error", nPetIndex); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + return; + } + else + CHAR_setMaxExpFromLevel(nPetIndex, CHAR_getInt(nPetIndex, CHAR_LV)); + for (i = 0; i < CHAR_MAXPETHAVE; i++) + { + if (CHAR_getCharPet(charaindex, i) == nPetIndex) + { + nPetNo = i; + break; + } + } + if (nPetNo == -1) + { + CHAR_talkToCli(charaindex, -1, "óҲ", CHAR_COLORRED); + return; + } + sprintf(szMsgbuf, "%d ת", CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION)); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + // + if (nLevel != -1) + { + if (nLevel > 140) + nLevel = 140; + if (nLevel < 1) + nLevel = 1; + for (j = 1; j < nLevel; j++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + // ת + for (j = 0; j < nTrans; j++) + { + int nLevelUpPoint = 0, nPetrank = 0, nVital, nStr, nTgh, nDex; + int nTotal1, nTotal2, nTotal, nPetLV, nAns, nRet, nPetID; + int work[4] = {0, 0, 0, 0}; + + nTotal1 = 150; // ιΧֵ + nLevelUpPoint = CHAR_getInt(nPetIndex, CHAR_ALLOCPOINT); + nPetrank = CHAR_getInt(nPetIndex, CHAR_PETRANK); + nPetLV = CHAR_getInt(nPetIndex, CHAR_LV); + nVital = (float)((nLevelUpPoint >> 24) & 0xFF); + nStr = (float)((nLevelUpPoint >> 16) & 0xFF); + nTgh = (float)((nLevelUpPoint >> 8) & 0xFF); + nDex = (float)((nLevelUpPoint >> 0) & 0xFF); + nTotal2 = nVital + nStr + nTgh + nDex; + sprintf(szMsgbuf, "%d ת %d ǰVital:%d Str:%d Tgh:%d Dex:%d", + CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION), + CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION) + 1, + nVital, nStr, nTgh, nDex + ); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + +#ifdef _PET_2TRANS + nAns = NPC_PetTransManGetAns(nTotal1, nTotal2, nPetLV, nPetrank, CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION)); +#else + nAns = NPC_PetTransManGetAns(nTotal1, nTotal2, nPetLV, nPetrank); +#endif + nTotal = nTotal1 + (nTotal2 * 4); + + work[0] = (nAns * (50 + (nVital * 4))) / nTotal; + work[1] = (nAns * (50 + (nStr * 4))) / nTotal; + work[2] = (nAns * (50 + (nTgh * 4))) / nTotal; + work[3] = (nAns * (50 + (nDex * 4))) / nTotal; + nPetID = CHAR_getInt(nPetIndex, CHAR_PETID); + for (i = 0; i < nEenemynum; i++) + { + if (ENEMY_getInt(i, ENEMY_TEMPNO) == nPetID) + break; + } + nRet = GetNewPet(charaindex, nPetIndex, i, work); + if (nRet < 0) + { + CHAR_talkToCli(charaindex, -1, "Ƴʧ", CHAR_COLORRED); + return; + } + nLevelUpPoint = CHAR_getInt(nPetIndex, CHAR_ALLOCPOINT); + sprintf(szMsgbuf, "%d ת %d Vital:%d Str:%d Tgh:%d Dex:%d", + CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION), + CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION) + 1, + (nLevelUpPoint >> 24) & 0xFF, + (nLevelUpPoint >> 16) & 0xFF, + (nLevelUpPoint >> 8) & 0xFF, + (nLevelUpPoint >> 0) & 0xFF + ); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + CHAR_send_K_StatusString(charaindex, nPetNo, CHAR_K_STRING_HP | CHAR_K_STRING_AI); + sprintf(szMsgbuf, "%d ת", CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION)); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + // + if (j != nTrans - 1) + { + for (k = 1; k < 140; k++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + else + { + if (nLevel != -1) + { + if (nLevel > 140) + nLevel = 140; + if (nLevel < 1) + nLevel = 1; + for (k = 1; k < nLevel; k++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + } + } + CHAR_complianceParameter(nPetIndex); + snprintf(szMsgbuf, sizeof(szMsgbuf), "K%d", nPetNo); + CHAR_sendStatusString(charaindex, szMsgbuf); +#ifdef _PET_ITEM + snprintf(szMsgbuf, sizeof(szMsgbuf), "B%d", nPetNo); + CHAR_sendStatusString(charaindex, szMsgbuf); +#endif + snprintf(szMsgbuf, sizeof(szMsgbuf), "W%d", nPetNo); + CHAR_sendStatusString(charaindex, szMsgbuf); + snprintf(szMsgbuf, sizeof(szMsgbuf), "%d תɹ\!", nTrans); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORWHITE); + } + else if (nMakeNum > 0 && nMakeNum < MAX_MAKE_PET_NUM) // + { + int nMakeCount = 0, nLevelUpPoint = 0, nMakeLoop; + + for (nMakeLoop = 0; nMakeLoop < nMakeNum; nMakeLoop++) + { + nPetIndex = ENEMY_TEST_createPetIndex(nEnemyID); + if (!CHAR_CHECKINDEX(nPetIndex)) + { + sprintf(szMsgbuf, "CHAR_CHECKINDEX(%d) error:loop %d", nPetIndex, nMakeLoop); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORRED); + return; + } + else + CHAR_setMaxExpFromLevel(nPetIndex, CHAR_getInt(nPetIndex, CHAR_LV)); + // + if (nLevel != -1) + { + if (nLevel > 140) + nLevel = 140; + if (nLevel < 1) + nLevel = 1; + for (j = 1; j < nLevel; j++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + // ת + for (j = 0; j < nTrans; j++) + { + int nPetrank = 0, nVital, nStr, nTgh, nDex; + int nTotal1, nTotal2, nTotal, nPetLV, nAns, nRet, nPetID; + int work[4] = {0, 0, 0, 0}; + + nTotal1 = 150; // ιΧֵ + nLevelUpPoint = CHAR_getInt(nPetIndex, CHAR_ALLOCPOINT); + nPetrank = CHAR_getInt(nPetIndex, CHAR_PETRANK); + nPetLV = CHAR_getInt(nPetIndex, CHAR_LV); + nVital = (float)((nLevelUpPoint >> 24) & 0xFF); + nStr = (float)((nLevelUpPoint >> 16) & 0xFF); + nTgh = (float)((nLevelUpPoint >> 8) & 0xFF); + nDex = (float)((nLevelUpPoint >> 0) & 0xFF); + nTotal2 = nVital + nStr + nTgh + nDex; +#ifdef _PET_2TRANS + nAns = NPC_PetTransManGetAns(nTotal1, nTotal2, nPetLV, nPetrank, CHAR_getInt(nPetIndex, CHAR_TRANSMIGRATION)); +#else + nAns = NPC_PetTransManGetAns(nTotal1, nTotal2, nPetLV, nPetrank); +#endif + nTotal = nTotal1 + (nTotal2 * 4); + + work[0] = (nAns * (50 + (nVital * 4))) / nTotal; + work[1] = (nAns * (50 + (nStr * 4))) / nTotal; + work[2] = (nAns * (50 + (nTgh * 4))) / nTotal; + work[3] = (nAns * (50 + (nDex * 4))) / nTotal; + nPetID = CHAR_getInt(nPetIndex, CHAR_PETID); + for (i = 0; i < nEenemynum; i++) + { + if (ENEMY_getInt(i, ENEMY_TEMPNO) == nPetID) + break; + } + nRet = GetNewPet(charaindex, nPetIndex, i, work); + if (nRet < 0) + { + CHAR_talkToCli(charaindex, -1, "Ƴʧ", CHAR_COLORRED); + return; + } + // + if (j != nTrans - 1) + { + for (k = 1; k < 140; k++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + else + { + if (nLevel != -1) + { + if (nLevel > 140) + nLevel = 140; + if (nLevel < 1) + nLevel = 1; + for (k = 1; k < nLevel; k++) + { + CHAR_PetLevelUp(nPetIndex); + CHAR_PetAddVariableAi(nPetIndex, AI_FIX_PETLEVELUP); + CHAR_setInt(nPetIndex, CHAR_LV, CHAR_getInt(nPetIndex, CHAR_LV) + 1); + } + } + } + } + CHAR_complianceParameter(nPetIndex); + nMakeCount++; + nLevelUpPoint = CHAR_getInt(nPetIndex, CHAR_ALLOCPOINT); + CHAR_endCharOneArray(nPetIndex); + } + snprintf(szMsgbuf, sizeof(szMsgbuf), "תɹ\!(%dֻ)", nMakeCount); + CHAR_talkToCli(charaindex, -1, szMsgbuf, CHAR_COLORWHITE); + } +} +#endif +#ifdef _NPC_MAGICCARD +void CHAR_CHAT_DEBUG_gamerate(int charaindex, char *message) +{ + char buf[64]; + int i; + + if( !CHAR_CHECKINDEX( charaindex) ) + return; + + if(strstr( message , "check" ) != NULL ) + { + for( i=0;i +#include +#include +#include "readmap.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "chatmagic.h" +#include "battle.h" +#include "log.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "family.h" +#include "chatroom.h" +#include "net.h" +#include "util.h" + +#ifdef _CHATROOMPROTOCOL +/* +CHAR_WORKCHATROOMTYPE : + 0 : + 1 : ҳ + 2 : ҳԱ +*/ +typedef struct { + BOOL useFlag ; + int NowPeople; + int Maker; + int MemberList[MAX_PPLINROOM]; + char RoomName[32]; +} CHATROOM_CLASS ; +CHATROOM_CLASS ChatRoom[MAX_CHATROOM]; + + +BOOL ChatCheck_BeMaster( int myindex, int chatnum) +{ + if( !CHAR_CHECKINDEX ( myindex ) ) + return FALSE; + + if( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ) == 0 ) return FALSE; + + if( chatnum != -1 ){ + if( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ) != chatnum ) + return FALSE; + } + if( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) return TRUE; + + return FALSE; +} + +BOOL ChatCheck_Free( int myindex) +{ + int old_gold; + if ( !CHAR_CHECKINDEX ( myindex ) ) + return FALSE; + old_gold = CHAR_getInt( myindex, CHAR_GOLD ); + if( old_gold < 200 ){ + CHAR_talkToCli ( myindex , -1 , "軨ѣʯ" , CHAR_COLORYELLOW ); + return FALSE; + } + if ( CHAR_getInt ( myindex , CHAR_LV ) < 30 && + CHAR_getInt ( myindex , CHAR_TRANSMIGRATION ) < 1 ) { + CHAR_talkToCli ( myindex , -1 , "裰תϣ" , CHAR_COLORYELLOW ); + return FALSE; + } + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) != 0 ) { + CHAR_talkToCli ( myindex , -1 , "ѾУ" , CHAR_COLORYELLOW ); + return FALSE; + } + return TRUE; +} + +void InitChatRoom ( void ) { + int i , j ; + for ( i = 0 ; i < MAX_CHATROOM ; i ++ ) { + ChatRoom[ i ].useFlag = FALSE ; + ChatRoom[ i ].Maker = -1 ; + ChatRoom[ i ].NowPeople = -1 ; + sprintf ( ChatRoom[ i ].RoomName , " " ) ; + for ( j = 0 ; j < MAX_PPLINROOM ; j ++ ) + ChatRoom[ i ].MemberList[ j ] = -1 ; + } +} + +BOOL ChatRoom_Create ( int myindex , char *message ) +{ + int i ; + + if( ChatCheck_Free( myindex) == FALSE ) return FALSE; + + for ( i = 0 ; i < MAX_CHATROOM ; i ++ ) { + if ( !ChatRoom[ i ].useFlag ) { + ChatRoom[ i ].useFlag = TRUE ; + ChatRoom[ i ].Maker = myindex ; + ChatRoom[ i ].NowPeople = 1 ; + ChatRoom[ i ].MemberList[ 0 ] = myindex ; + sprintf ( ChatRoom[ i ].RoomName , "%s" , message ) ; + CHAR_setWorkInt ( myindex , CHAR_WORKCHATROOMTYPE , 1 ) ; + CHAR_setWorkInt ( myindex , CHAR_WORKCHATROOMNUM , i ) ; + ChatRoom_Refresh ( i ) ; + + CHAR_DelGold( myindex, 200); + CHAR_talkToCli ( myindex , -1 , "ҿ۳ʯ" , CHAR_COLORYELLOW ); + return TRUE; + } + } + CHAR_talkToCli ( myindex , -1 , "޷µƵ" , CHAR_COLORYELLOW ); + return FALSE; +} + +BOOL ChatRoom_Destroy ( int myindex ) +{ + int i , j ; + int fd ;/*= getfdFromCharaIndex(myindex);*/ + char buf[16]; + if ( !CHAR_CHECKINDEX ( myindex ) ) + return FALSE; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) { + i = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ) ; + ChatRoom[ i ].useFlag = FALSE ; + ChatRoom[ i ].Maker = -1 ; + ChatRoom[ i ].NowPeople = -1 ; + + // WON FIX + memset( ChatRoom[ i ].RoomName, 0 , sizeof(ChatRoom[ i ].RoomName) ); + //sprintf ( ChatRoom[ i ].RoomName , " " ) ; + + for ( j = 0 ; j < MAX_PPLINROOM ; j ++ ) { + if ( !CHAR_CHECKINDEX ( ChatRoom[ i ].MemberList[ j ] ) ) { + ChatRoom[ i ].MemberList[ j ] = -1 ; + continue; + } + CHAR_setWorkInt ( ChatRoom[ i ].MemberList[ j ] , CHAR_WORKCHATROOMTYPE , 0 ) ; + CHAR_setWorkInt ( ChatRoom[ i ].MemberList[ j ] , CHAR_WORKCHATROOMNUM , 0 ) ; + fd = getfdFromCharaIndex( ChatRoom[ i ].MemberList[ j ] ); + sprintf ( buf , "D|%d" , i ) ; + lssproto_CHATROOM_send ( fd , buf ) ; + ChatRoom[ i ].MemberList[ j ] = -1 ; + } + return TRUE; + } + return FALSE; +} + +void ChatRoom_Message ( int myindex , char *message ) +{ + int i , j , fd ; + char buf[1024]; + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) > 0 ) { + i = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ) ; + + // WON FIX + if( i < 0 ) return; + + for ( j = 0 ; j < MAX_PPLINROOM ; j ++ ) { + if ( !CHAR_CHECKINDEX ( ChatRoom[ i ].MemberList[ j ] ) ) + continue; + snprintf ( buf , sizeof ( buf ) , "T|%s" , message ) ; + fd = getfdFromCharaIndex ( ChatRoom[ i ].MemberList[ j ] ); + lssproto_CHATROOM_send ( fd , buf ) ; + } + } +} + +void ChatRoom_Kick ( int myindex , int toindex ) +{ + int i , fd ; + int Num = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ); + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( !CHAR_CHECKINDEX ( toindex ) ) + return ; + if ( myindex == toindex ) return; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) { + if ( Num != CHAR_getWorkInt ( toindex , CHAR_WORKCHATROOMNUM ) ) + return; + else { + CHAR_setWorkInt ( toindex , CHAR_WORKCHATROOMTYPE , 0 ) ; + CHAR_setWorkInt ( toindex , CHAR_WORKCHATROOMNUM , -1) ; + //CHAR_talkToCli ( toindex , -1 , "ҳ߳ң" , CHAR_COLORRED ) ; + fd = getfdFromCharaIndex( toindex ); + lssproto_CHATROOM_send ( fd , "K|" ) ; + ChatRoom[ Num ].NowPeople --; + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] == toindex ) { + ChatRoom[ Num ].MemberList[ i ] = -1 ; + break; + } + } + } + } + ChatRoom_Refresh ( Num ) ; +} + +void ChatRoom_Make ( int myindex , int toindex ) +{ + int Num = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ); + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( !CHAR_CHECKINDEX ( toindex ) ) + return ; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) { + if ( Num != CHAR_getWorkInt ( toindex , CHAR_WORKCHATROOMNUM ) ) + return; + else if ( CHAR_getInt ( toindex , CHAR_LV ) >= 30 || + CHAR_getInt ( toindex , CHAR_TRANSMIGRATION ) >= 1 ) { + CHAR_setWorkInt ( myindex , CHAR_WORKCHATROOMTYPE , 2 ) ; + CHAR_setWorkInt ( toindex , CHAR_WORKCHATROOMTYPE , 1 ) ; + CHAR_talkToCli ( toindex , -1 , "ҵҳ" , CHAR_COLORRED ) ; + + ChatRoom[ Num ].Maker = toindex ; + } + else { + CHAR_talkToCli ( myindex , -1 , "ѡļȼԵҳ" , CHAR_COLORRED ) ; + } + } + ChatRoom_Refresh ( Num ) ; +} + +void ChatRoom_Leave ( int myindex ) +{ + int i , NextMaker = -1 ; + int Num = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ); + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) { + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] != myindex && + ChatRoom[ Num ].MemberList[ i ] != -1 ) { + if ( CHAR_CHECKINDEX ( ChatRoom[ Num ].MemberList[ i ] ) ) { + if ( CHAR_getInt ( ChatRoom[ Num ].MemberList[ i ] , CHAR_LV ) >= 30 || + CHAR_getInt ( ChatRoom[ Num ].MemberList[ i ] , CHAR_TRANSMIGRATION ) >= 1 ) { + NextMaker = ChatRoom[ Num ].MemberList[ i ] ; + break; + } + } + } + } + if ( NextMaker != -1 ) { + ChatRoom_Make( myindex , NextMaker ) ; + CHAR_setWorkInt ( myindex , CHAR_WORKCHATROOMTYPE , 0) ; + CHAR_setWorkInt ( myindex , CHAR_WORKCHATROOMNUM, -1) ; + ChatRoom[ Num ].NowPeople --; + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] == myindex ) { + ChatRoom[ Num ].MemberList[ i ] = -1 ; + break; + } + } + }else{ + ChatRoom_Destroy( myindex ) ; + return ; + } + + }else if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 2 ) { + CHAR_setWorkInt ( myindex, CHAR_WORKCHATROOMTYPE, 0) ; + CHAR_setWorkInt ( myindex, CHAR_WORKCHATROOMNUM, -1) ; + ChatRoom[ Num ].NowPeople --; + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] == myindex ) { + ChatRoom[ Num ].MemberList[ i ] = -1 ; + break; + } + } + } + ChatRoom_Refresh ( Num ) ; +} + +void ChatRoom_Join ( int myindex , int num ) +{ + int fd ; + char buf[64]; + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) != 0 ) + return ; + if ( ChatRoom[ num ].useFlag == TRUE && ChatRoom[ num ].NowPeople < MAX_PPLINROOM ) { + sprintf ( buf , "J|%s|%d" , CHAR_getChar( myindex , CHAR_NAME ) , myindex ) ; + fd = getfdFromCharaIndex( ChatRoom[ num ].Maker ); + lssproto_CHATROOM_send ( fd , buf ); + }else if ( ChatRoom[ num ].NowPeople >= MAX_PPLINROOM ) + CHAR_talkToCli ( myindex , -1 , "" , CHAR_COLORRED ) ; + +} + +void ChatRoom_Agree ( int myindex , int toindex , int YesNo ) { + int i ; + int Num = CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMNUM ); + if ( !CHAR_CHECKINDEX ( myindex ) ) + return ; + if ( !CHAR_CHECKINDEX ( toindex ) ) + return ; + if ( CHAR_getWorkInt ( toindex , CHAR_WORKCHATROOMTYPE ) != 0 ) + return; + if ( CHAR_getWorkInt ( myindex , CHAR_WORKCHATROOMTYPE ) == 1 ) { + if ( ChatRoom[ Num ].NowPeople < MAX_PPLINROOM && YesNo == 1 ) { + CHAR_setWorkInt ( toindex , CHAR_WORKCHATROOMTYPE , 2 ) ; + CHAR_setWorkInt ( toindex , CHAR_WORKCHATROOMNUM , Num ) ; + ChatRoom[ Num ].NowPeople ++ ; + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] == -1 ) { + ChatRoom[ Num ].MemberList[ i ] = toindex ; + break; + } + } + }else if ( YesNo == 0 ) { + CHAR_talkToCli ( toindex , -1 , "ҳܾļ룡" , CHAR_COLORRED ) ; + }else if ( ChatRoom[ Num ].NowPeople >= MAX_PPLINROOM ) { + CHAR_talkToCli ( toindex , -1 , "" , CHAR_COLORRED ) ; + CHAR_talkToCli ( myindex , -1 , "" , CHAR_COLORRED ) ; + } + } + ChatRoom_Refresh ( Num ) ; +} + +void ChatRoom_List ( int fd ) +{ + int i ; + char buf[128]; + char token[2048] = "B|"; + for ( i = 0 ; i < MAX_CHATROOM ; i ++ ) { + if ( ChatRoom[ i ].useFlag == TRUE ) { + sprintf ( buf , "%2dѶ=>%20s , ҳ=>%16s , =>%2d" , + i , + ChatRoom[ i ].RoomName , + CHAR_getChar ( ChatRoom[ i ].Maker , CHAR_NAME ) , + ChatRoom[ i ].NowPeople ); + + sprintf ( buf , "r%d|%s|%d|%s|p%d|" , + i , + ChatRoom[ i ].RoomName , + ChatRoom[ i ].Maker , + CHAR_getChar ( ChatRoom[ i ].Maker , CHAR_NAME ) , + ChatRoom[ i ].NowPeople ); + strncat ( token , buf , sizeof ( buf ) ) ; + } + } + lssproto_CHATROOM_send ( fd , token ) ; +} + +void ChatRoom_Refresh ( int Num ) +{ + int fd , i , RoomLeader = -1 ; + char token[2048] ; + char token2[2096] ; + char buf[64] ; + if ( ChatRoom[ Num ].useFlag == TRUE ) { + sprintf ( token , "R|r%d|%s|%d|%s|p%d|" , + Num , + ChatRoom[ Num ].RoomName , + ChatRoom[ Num ].Maker , + CHAR_getChar ( ChatRoom[ Num ].Maker , CHAR_NAME ) , + ChatRoom[ Num ].NowPeople ); + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] != -1 ) { + sprintf( buf , "I%d|%s|%s|" , + ChatRoom[ Num ].MemberList[ i ] , + CHAR_getChar ( ChatRoom[ Num ].MemberList[ i ] , CHAR_NAME ) , + CHAR_getChar ( ChatRoom[ Num ].MemberList[ i ] , CHAR_OWNTITLE ) + ); + strncat ( token , buf , sizeof ( buf ) ) ; + } + } + } + for ( i = 0 ; i < MAX_PPLINROOM ; i ++ ) { + if ( ChatRoom[ Num ].MemberList[ i ] != -1 ) { + if ( CHAR_getWorkInt ( ChatRoom[ Num ].MemberList[ i ] , CHAR_WORKCHATROOMTYPE ) == 1 ) RoomLeader = 1; + else RoomLeader = 0 ; + sprintf ( token2 , "%s%d|" , token , RoomLeader ) ; + fd= getfdFromCharaIndex ( ChatRoom[ Num ].MemberList[ i ] ); + lssproto_CHATROOM_send ( fd , token2 ) ; + } + } +} + +void ChatRoom_recvall ( int fd , char *data ) +{ + char Head[4]; + char message[1024]; + char buf[16]; + int myindex ; + + myindex = CONNECT_getCharaindex(fd); + if ( !CHAR_CHECKINDEX ( myindex ) )return ; + getStringFromIndexWithDelim( data , "|", 1, Head, sizeof(Head)); + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + + if ( strcmp ( Head , "C" ) == 0 ) { // Ƶ + if ( !ChatRoom_Create ( myindex , message ) ) + print("\nSyu log Create Channel Error" ); + }else if ( strcmp ( Head , "D" ) == 0 ) { // ɾƵ + if ( !ChatRoom_Destroy ( myindex ) ) + print("\nSyu log Destroy Channel Error" ) ; + }else if ( strcmp ( Head , "A" ) == 0 ) {// ͬƵ + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + getStringFromIndexWithDelim( data , "|", 3, buf, sizeof(buf)); + ChatRoom_Agree ( myindex , atoi( message ) , atoi( buf ) ) ; + }else if ( strcmp ( Head , "J" ) == 0 ) {// Ƶ + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + ChatRoom_Join ( myindex , atoi( message ) ) ; + }else if ( strcmp ( Head , "L" ) == 0 ) {// 뿪Ƶ + ChatRoom_Leave ( myindex ) ; + }else if ( strcmp ( Head , "K" ) == 0 ) {//߳Ƶ + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + ChatRoom_Kick ( myindex , atoi( message ) ); + }else if ( strcmp ( Head , "M" ) == 0 ) { // ҳ + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + ChatRoom_Make ( myindex , atoi( message ) ); + }else if ( strcmp ( Head , "T" ) == 0 ) {// ƵѶϢ + getStringFromIndexWithDelim( data , "|", 2, message, sizeof(message)); + ChatRoom_Message ( myindex , message ) ; + }else if ( strcmp ( Head , "B" ) == 0 ) {// 嵥 + ChatRoom_List ( fd ); + }else + print("\nSyu log None"); +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/encount.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/encount.c new file mode 100644 index 0000000..65ae9d3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/encount.c @@ -0,0 +1,600 @@ +#include "version.h" +#include +#include +#include +#ifdef _REDHAT_V9 +#include +#endif +#include "autil.h" +#include "common.h" +#include "util.h" +#include "buf.h" +#include "char_base.h" +#include "char.h" +#include "configfile.h" +#include "encount.h" +#include "enemy.h" + +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ +#include "encount.h" +#endif + +/* ޼ ĩ */ + +#ifndef _ADD_ENCOUNT // WON ADD ӵ޼ +typedef struct tagENCOUNT_Table +{ + int index; + int floor; + int encountprob_min; /* ޼ */ + int encountprob_max; /* ޼ */ + int enemymaxnum; /* ľë¾ */ + int zorder; + int groupid[ENCOUNT_GROUPMAXNUM]; /* No */ + int createprob[ENCOUNT_GROUPMAXNUM]; /* */ + RECT rect; +}ENCOUNT_Table; +ENCOUNT_Table *ENCOUNT_table; +#endif + +int ENCOUNT_encountnum; +#define ENCOUNT_ENEMYMAXCREATENUM 10 + +static INLINE BOOL ENCOUNT_CHECKENCOUNTTABLEARRAY( int array) +{ + if( array < 0 || array > ENCOUNT_encountnum-1) return FALSE; + return TRUE; +} + +/*------------------------------------------------------------ + * ޼ɬüë£ + * ¦ + * filename char* ɬð̻ + * ߯Ի + * TRUE(1) + * FALSE(0) + *------------------------------------------------------------*/ +BOOL ENCOUNT_initEncount( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + int encount_readlen=0; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + errorprint; + return FALSE; + } + + ENCOUNT_encountnum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + ENCOUNT_encountnum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "ѰҴ\n" ); + fclose(f); + return FALSE; + } + + ENCOUNT_table = allocateMemory( sizeof(struct tagENCOUNT_Table) + * ENCOUNT_encountnum ); + if( ENCOUNT_table == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(ENCOUNT_table)*ENCOUNT_encountnum); + fclose( f ); + return FALSE; + } + + /* */ +{ + int i,j; + for( i = 0; i < ENCOUNT_encountnum; i ++ ) { + ENCOUNT_table[i].index = -1; + ENCOUNT_table[i].floor = 0; + ENCOUNT_table[i].encountprob_min = 1; + ENCOUNT_table[i].encountprob_min = 50; + ENCOUNT_table[i].enemymaxnum = 4; + ENCOUNT_table[i].rect.x = 0; + ENCOUNT_table[i].rect.y = 0; + ENCOUNT_table[i].rect.height = 0; + ENCOUNT_table[i].rect.width = 0; + ENCOUNT_table[i].zorder = 0; + for( j = 0; j < ENCOUNT_GROUPMAXNUM; j ++ ) { + ENCOUNT_table[i].groupid[j] = -1; + ENCOUNT_table[i].createprob[j] = -1; + } +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ + ENCOUNT_table[i].event_now = -1; + ENCOUNT_table[i].event_end = -1; + ENCOUNT_table[i].enemy_group = -1; +#endif + } +} + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ +{ + int i; + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + int x1,x2,y1,y2; + int j; + + /* պ ݼм */ + ENCOUNT_table[encount_readlen].index = -1; + ENCOUNT_table[encount_readlen].floor = 0; + ENCOUNT_table[encount_readlen].encountprob_min = 1; + ENCOUNT_table[encount_readlen].encountprob_min = 50; + ENCOUNT_table[encount_readlen].enemymaxnum = 4; + ENCOUNT_table[encount_readlen].rect.x = 0; + ENCOUNT_table[encount_readlen].rect.y = 0; + ENCOUNT_table[encount_readlen].rect.height = 0; + ENCOUNT_table[encount_readlen].rect.width = 0; + ENCOUNT_table[encount_readlen].zorder = 0; + for( j = 0; j < ENCOUNT_GROUPMAXNUM; j ++ ) { + ENCOUNT_table[encount_readlen].groupid[j] = -1; + ENCOUNT_table[encount_readlen].createprob[j] = -1; + } +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ + ENCOUNT_table[encount_readlen].event_now = -1; + ENCOUNT_table[encount_readlen].event_end = -1; + ENCOUNT_table[encount_readlen].enemy_group = -1; +#endif + + + /* 繴ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",1,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].index = atoi(token); + + /* 2ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",2,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].floor = atoi(token); + + /* 3ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",3,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + x1 = atoi(token); + + /* 4ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",4,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + y1= atoi(token); + + /* 5ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",5,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + + x2 = atoi(token); + + /* 6ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",6,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + y2= atoi(token); + + ENCOUNT_table[encount_readlen].rect.x = min(x1,x2); + ENCOUNT_table[encount_readlen].rect.width = max(x1,x2) - min(x1,x2); + ENCOUNT_table[encount_readlen].rect.y = min(y1,y2); + ENCOUNT_table[encount_readlen].rect.height = max(y1,y2) - min(y1,y2); + + /* 7ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",7,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].encountprob_min = atoi(token); + + /* 8ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",8,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].encountprob_max = atoi(token); + +{ + int a,b; + a = ENCOUNT_table[encount_readlen].encountprob_min; + b = ENCOUNT_table[encount_readlen].encountprob_max; + /* Ʃ */ + ENCOUNT_table[encount_readlen].encountprob_min + = min( a,b); + ENCOUNT_table[encount_readlen].encountprob_max + = max( a,b); +} + /* 9ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",9,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + { + int maxnum = atoi( token); + /* Ѽ뼰 */ + if( maxnum < 1 || maxnum > ENCOUNT_ENEMYMAXCREATENUM ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].enemymaxnum = maxnum; + } + /* 10ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",10,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].zorder = atoi(token); + #define CREATEPROB_TOKEN 11 + + /* 11 31ͼëέ */ + { + int i; + + for( i = CREATEPROB_TOKEN; i < CREATEPROB_TOKEN +ENCOUNT_GROUPMAXNUM*2; i ++) { + ret = getStringFromIndexWithDelim( line,",",i,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + if( strlen( token) != 0 ) { + if( i < CREATEPROB_TOKEN + ENCOUNT_GROUPMAXNUM ) { + ENCOUNT_table[encount_readlen].groupid[i-CREATEPROB_TOKEN] + = atoi(token); + } + else { + ENCOUNT_table[encount_readlen].createprob[i-(CREATEPROB_TOKEN + ENCOUNT_GROUPMAXNUM)] + = atoi(token); + } + } + } + + /* */ + if( checkRedundancy( ENCOUNT_table[encount_readlen].groupid, + arraysizeof( ENCOUNT_table[encount_readlen].groupid))) + { + fprint( "ļ﷨:%s %d\n", + filename,linenum); + continue; + } + } + + +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ + ret = getStringFromIndexWithDelim( line,",",31,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].event_now = atoi(token); + + ret = getStringFromIndexWithDelim( line,",",32,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].event_end = atoi(token); + + ret = getStringFromIndexWithDelim( line,",",33,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENCOUNT_table[encount_readlen].enemy_group = atoi(token); +#endif + + encount_readlen ++; +} + } + fclose(f); + + ENCOUNT_encountnum = encount_readlen; + + print( "Ч %d..", ENCOUNT_encountnum ); + + return TRUE; +} +/*------------------------------------------------------------------------ + * ޼ɬð̻ + *-----------------------------------------------------------------------*/ +BOOL ENCOUNT_reinitEncount( void ) +{ + freeMemory( ENCOUNT_table); + return( ENCOUNT_initEncount( getEncountfile())); +} + +/*------------------------------------------------------------ + * ϶ýľ ENCOUNT_tableٯëƩ£ + * zorderٯëέƴ˼ ë £ + * ¦ + * floor int ׷ʧID + * x int x + * y int y + * ߯Ի + * ٯ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountAreaArray( int floor, int x, int y) +{ + int i; + int index = -1; + for( i=0 ; i0) { + if( index != -1 ) { + /* ƴëƩ */ + /* */ + if( curZorder > ENCOUNT_getZorderFromArray(index)) { + index = i; + } + } + else { + index = i; + } + } + } + } + } + return index; +} + +/*------------------------------------------------------------ + * ϶ýľ ޼ ëƩ£ + * ¦ + * floor int ׷ʧID + * x int x + * y int y + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountPercentMin( int charaindex, int floor , int x, int y ) +{ + int ret; + + ret = ENCOUNT_getEncountAreaArray( floor, x, y); + if( ret != -1 ) { + ret = ENCOUNT_table[ret].encountprob_min; + /* Ŀ򵩶ë */ + if( CHAR_getWorkInt( charaindex, CHAR_WORK_TOHELOS_COUNT) > 0 ) { + ret = ceil( ret * + ((100 + CHAR_getWorkInt( charaindex, CHAR_WORK_TOHELOS_CUTRATE)) + / 100.0)); + } + if( ret < 0 ) ret = 0; + if( ret > 100 ) ret = 100; + } + return ret; +} +/*------------------------------------------------------------ + * ϶ýľ ޼ ëƩ£ + * ¦ + * floor int ׷ʧID + * x int x + * y int y + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountPercentMax( int charaindex, int floor , int x, int y ) +{ + int ret; + + ret = ENCOUNT_getEncountAreaArray( floor, x, y); + if( ret != -1 ) { + ret = ENCOUNT_table[ret].encountprob_max; + /* Ŀ򵩶ë */ + if( CHAR_getWorkInt( charaindex, CHAR_WORK_TOHELOS_COUNT) > 0 ) { + ret = ceil( ret * + ((100 + CHAR_getWorkInt( charaindex, CHAR_WORK_TOHELOS_CUTRATE)) + / 100.0)); + } + if( ret < 0 ) ret = 0; + if( ret > 100 ) ret = 100; + } + return ret; +} +/*------------------------------------------------------------ + * ϶ýľ ϷMAXëƩ£ + * ¦ + * floor int ׷ʧID + * x int x + * y int y + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getCreateEnemyMaxNum( int floor , int x, int y ) +{ + int ret; + + ret = ENCOUNT_getEncountAreaArray( floor, x, y); + if( ret != -1 ) { + ret = ENCOUNT_table[ret].enemymaxnum; + } + return ret; +} +/*------------------------------------------------------------ + * ϶ýľ ޼ūindexëƩ£ + * ¦ + * floor int ׷ʧID + * x int x + * y int y + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountIndex( int floor , int x, int y ) +{ + int ret; + + ret = ENCOUNT_getEncountAreaArray( floor, x, y); + if( ret != -1 ) { + ret = ENCOUNT_table[ret].index; + } + return ret; +} +/*------------------------------------------------------------ + * ϶ýľ ޼ūindexëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountIndexFromArray( int array ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].index; +} +/*------------------------------------------------------------ + * ϶ýľ ޼ ëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getEncountPercentFromArray( int array ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].encountprob_min; +} +/*------------------------------------------------------------ + * ϶ýľ ϷMAXëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getCreateEnemyMaxNumFromArray( int array ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].enemymaxnum; +} +/*------------------------------------------------------------ + * ϶ýľ׽ٯ įëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getGroupIdFromArray( int array, int grouparray ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].groupid[grouparray]; +} +/*------------------------------------------------------------ + * ϶ýľ׽ٯ ëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getGroupProbFromArray( int array, int grouparray ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].createprob[grouparray]; +} +/*------------------------------------------------------------ + * ϶ýľ׽ٯƴëƩ£ + * ¦ + * array int ENCOUNTTABLEٯ + * ߯Ի + * ߶ + * -1 + ------------------------------------------------------------*/ +int ENCOUNT_getZorderFromArray( int array ) +{ + if( !ENCOUNT_CHECKENCOUNTTABLEARRAY( array)) return -1; + return ENCOUNT_table[array].zorder; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/enemy.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/enemy.c new file mode 100644 index 0000000..e9fabb4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/enemy.c @@ -0,0 +1,2793 @@ +/* ɬ */ +#include "version.h" +#include +#include +#include "common.h" +#include "autil.h" +#include "util.h" +#include "buf.h" +#include "char_base.h" +#include "char.h" +#include "configfile.h" +#include "encount.h" +#include "enemy.h" +#include "pet.h" +#include "enemyexptbl.h" +#include "petmail.h" +#include "battle.h" +#include "pet_skillinfo.h" +#include "anim_tbl.h" +#include "log.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ +#include "encount.h" +#include "npcutil.h" +#endif + +#define ENEMY_INDEXTABLEMAXSIZE 16 +static ENEMY_EnemyTable *ENEMY_enemy; +static int ENEMY_enemynum; + +static ENEMYTEMP_Table *ENEMYTEMP_enemy; +static int ENEMYTEMP_enemynum; + +static GROUP_Table *GROUP_group; +static int GROUP_groupnum; + +int ENEMY_indextable[ENEMY_INDEXTABLEMAXSIZE]; + +#ifdef _ENEMY_FALLGROUND +extern tagRidePetTable ridePetTable[296]; +#endif + +INLINE BOOL ENEMY_CHECKINDEX( int index) +{ + if( index < 0 || index >= ENEMY_enemynum) return FALSE; + return TRUE; +} + +static INLINE BOOL ENEMY_CHECKINTDATAINDEX( int index) +{ + if( index< 0 || index >= ENEMY_DATAINTNUM) return FALSE; + return TRUE; +} + +static INLINE BOOL ENEMY_CHECKCHARDATAINDEX( int index) +{ + if( index< 0 || index >= ENEMY_DATACHARNUM) return FALSE; + return TRUE; +} + +INLINE int ENEMY_getInt( int index, ENEMY_DATAINT element) +{ + return ENEMY_enemy[index].intdata[element]; +} + +INLINE int *ENEMY_getIntdata( int index) +{ + return ENEMY_enemy[index].intdata; +} + +INLINE int ENEMY_setInt( int index, ENEMY_DATAINT element, int data) +{ + int buf; + buf = ENEMY_enemy[index].intdata[element]; + ENEMY_enemy[index].intdata[element] = data; + return buf; +} + +INLINE char *ENEMY_getChar( int index, ENEMY_DATACHAR element) +{ + if(!ENEMY_CHECKINDEX(index))return "\0"; + if(!ENEMY_CHECKCHARDATAINDEX(element))return "\0"; + + return ENEMY_enemy[index].chardata[element].string; +} + +INLINE BOOL ENEMY_setChar( int index ,ENEMY_DATACHAR element, char* new ) +{ + if(!ENEMY_CHECKINDEX(index))return FALSE; + if(!ENEMY_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( ENEMY_enemy[index].chardata[element].string, + sizeof(ENEMY_enemy[index].chardata[element].string), + new ); + return TRUE; +} + +int ENEMY_getEnemyNum( void) +{ + return ENEMY_enemynum; +} + +INLINE BOOL ENEMYTEMP_CHECKINDEX( int index) +{ + if( index < 0 || index >= ENEMYTEMP_enemynum) return FALSE; + return TRUE; +} + +static INLINE BOOL ENEMYTEMP_CHECKINTDATAINDEX( int index) +{ + if( index< 0 || index >= E_T_DATAINTNUM) return FALSE; + return TRUE; +} + +static INLINE BOOL ENEMYTEMP_CHECKCHARDATAINDEX( int index) +{ + if( index< 0 || index >= E_T_DATACHARNUM) return FALSE; + return TRUE; +} + +INLINE int ENEMYTEMP_getInt( int index, ENEMYTEMP_DATAINT element) +{ + return ENEMYTEMP_enemy[index].intdata[element]; +} + +INLINE int ENEMYTEMP_setInt( int index, ENEMYTEMP_DATAINT element, int data) +{ + int buf; + buf = ENEMYTEMP_enemy[index].intdata[element]; + ENEMYTEMP_enemy[index].intdata[element] = data; + return buf; +} + +INLINE char *ENEMYTEMP_getChar( int index, ENEMYTEMP_DATACHAR element) +{ + if(!ENEMYTEMP_CHECKINDEX(index))return "\0"; + if(!ENEMYTEMP_CHECKCHARDATAINDEX(element))return "\0"; + + return ENEMYTEMP_enemy[index].chardata[element].string; +} + +INLINE BOOL ENEMYTEMP_setChar( int index ,ENEMYTEMP_DATACHAR element, char* new ) +{ + if(!ENEMYTEMP_CHECKINDEX(index))return FALSE; + if(!ENEMYTEMP_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( ENEMYTEMP_enemy[index].chardata[element].string, + sizeof(ENEMYTEMP_enemy[index].chardata[element].string), + new ); + return TRUE; +} + +int ENEMYTEMP_getEnemyNum( void) +{ + return ENEMYTEMP_enemynum; +} + +INLINE BOOL GROUP_CHECKINDEX( int index) +{ + if( index < 0 || index >= GROUP_groupnum) return FALSE; + return TRUE; +} + +static INLINE BOOL GROUP_CHECKINTDATAINDEX( int index) +{ + if( index< 0 || index >= GROUP_DATAINTNUM) return FALSE; + return TRUE; +} + +static INLINE BOOL GROUP_CHECKCHARDATAINDEX( int index) +{ + if( index< 0 || index >= GROUP_DATACHARNUM) return FALSE; + return TRUE; +} + +INLINE int GROUP_getInt( int index, GROUP_DATAINT element) +{ + return GROUP_group[index].intdata[element]; +} + +INLINE int GROUP_setInt( int index, GROUP_DATAINT element, int data) +{ + int buf; + buf = GROUP_group[index].intdata[element]; + GROUP_group[index].intdata[element] = data; + return buf; +} + +INLINE char *GROUP_getChar( int index, GROUP_DATACHAR element) +{ + if(!GROUP_CHECKINDEX(index))return "\0"; + if(!GROUP_CHECKCHARDATAINDEX(element))return "\0"; + + return GROUP_group[index].chardata[element].string; +} + +INLINE BOOL GROUP_setChar( int index ,GROUP_DATACHAR element, char* new ) +{ + if(!GROUP_CHECKINDEX(index))return FALSE; + if(!GROUP_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( GROUP_group[index].chardata[element].string, + sizeof(GROUP_group[index].chardata[element].string), + new ); + return TRUE; +} + +int GROUP_getEnemyNum( void) +{ + return GROUP_groupnum; +} + +BOOL ENEMYTEMP_initEnemy( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + int enemytemp_readlen=0; + int i,j; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "ļʧ\n"); + return FALSE; + } + + ENEMYTEMP_enemynum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + ENEMYTEMP_enemynum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Seek Error\n" ); + fclose(f); + return FALSE; + } + ENEMYTEMP_enemy = allocateMemory( sizeof(struct tagENEMYTEMP_Table) + * ENEMYTEMP_enemynum ); + if( ENEMYTEMP_enemy == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(struct tagENEMYTEMP_Table)*ENEMYTEMP_enemynum); + fclose( f ); + return FALSE; + } + + /* */ + for( i = 0; i < ENEMYTEMP_enemynum; i ++ ) { + for( j = 0; j < E_T_DATAINTNUM; j ++ ) { + ENEMYTEMP_setInt( i,j,-1); + } + } + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + replaceString( line, '\t' , ' ' ); +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + for( i = 0; i < E_T_DATACHARNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i+1,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENEMYTEMP_setChar( enemytemp_readlen, E_T_NAME + i, token); + + } +#define ENEMYTEMP_STARTINTNUM (E_T_DATACHARNUM+1) + for( i = ENEMYTEMP_STARTINTNUM; i < E_T_DATAINTNUM+ENEMYTEMP_STARTINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + if( strlen( token) != 0 ) { + ENEMYTEMP_setInt( enemytemp_readlen, i - ENEMYTEMP_STARTINTNUM, atoi( token)); + } + } +#ifdef _PET_ENEMY_DEVELOP_UP + if(getPetEnemyDevelopUp() > 0){ + int vital = ENEMYTEMP_getInt( enemytemp_readlen, E_T_BASEVITAL); + int str = ENEMYTEMP_getInt( enemytemp_readlen, E_T_BASESTR); + int tgh = ENEMYTEMP_getInt( enemytemp_readlen, E_T_BASETGH); + int dex = ENEMYTEMP_getInt( enemytemp_readlen, E_T_BASEDEX); + int sum = vital + str + tgh + dex; + + if(sum < getPetEnemyDevelopUp()){ + ENEMYTEMP_setInt( enemytemp_readlen, E_T_BASEVITAL, vital * getPetEnemyDevelopUp() / sum); + ENEMYTEMP_setInt( enemytemp_readlen, E_T_BASESTR, str * getPetEnemyDevelopUp() / sum); + ENEMYTEMP_setInt( enemytemp_readlen, E_T_BASETGH, tgh * getPetEnemyDevelopUp() / sum); + ENEMYTEMP_setInt( enemytemp_readlen, E_T_BASEDEX, dex * getPetEnemyDevelopUp() / sum); + } + } +#endif + if( i < E_T_DATAINTNUM+ENEMYTEMP_STARTINTNUM ) continue; + + + enemytemp_readlen ++; +} + } + fclose(f); + + ENEMYTEMP_enemynum = enemytemp_readlen; + + print( "Ч״̬ %d...", ENEMYTEMP_enemynum ); + + return TRUE; +} + +BOOL ENEMYTEMP_reinitEnemy( void ) +{ + freeMemory( ENEMYTEMP_enemy); + return( ENEMYTEMP_initEnemy( getEnemyBasefile())); +} + +int ENEMYTEMP_getEnemyTempArray( int enemyindex) +{ + if( !ENEMY_CHECKINDEX( enemyindex)) return -1; + return ENEMY_enemy[enemyindex].enemytemparray; +} + +int ENEMYTEMP_getEnemyTempArrayFromTempNo( int EnemyTempNo) +{ + int i; + for( i = 0; i < ENEMYTEMP_enemynum; i ++ ) { + if( ENEMYTEMP_getInt( i, E_T_TEMPNO) == EnemyTempNo) { + return i; + } + } + return -1; +} + +int ENEMYTEMP_getEnemyTempArrayFromInitnum( int EnemyTempNo) +{ + int i; + for( i = 0; i < ENEMYTEMP_enemynum; i ++ ) { + if( ENEMYTEMP_getInt( i, E_T_INITNUM) == EnemyTempNo) { + return i; + } + } + return -1; +} + +BOOL ENEMY_initEnemy( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + int enemy_readlen=0; + int i,j; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "ļʧ\n"); + return FALSE; + } + + ENEMY_enemynum=0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + ENEMY_enemynum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Ѱʧ\n" ); + fclose(f); + return FALSE; + } + + ENEMY_enemy = allocateMemory( sizeof(struct tagENEMY_EnemyTable) + * ENEMY_enemynum ); + if( ENEMY_enemy == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(struct tagENEMY_EnemyTable)*ENEMY_enemynum); + fclose( f ); + return FALSE; + } + for( i = 0; i < ENEMY_enemynum; i ++ ) { + for( j = 0; j < ENEMY_DATAINTNUM; j ++ ) { + ENEMY_setInt( i,j,-1); + } + } + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + replaceString( line, '\t' , ' ' ); +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + + ret = getStringFromIndexWithDelim( line,",",1,token,sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENEMY_setChar( enemy_readlen, ENEMY_NAME, token); + ret = getStringFromIndexWithDelim( line,",",2,token,sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENEMY_setChar( enemy_readlen, ENEMY_TACTICSOPTION, token); +#ifdef _BATTLENPC_WARP_PLAYER + ret = getStringFromIndexWithDelim( line, ",", 3, token, sizeof(token)); + if(ret==FALSE){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENEMY_setChar( enemy_readlen, ENEMY_ACT_CONDITION, token); +#endif + +#ifdef _BATTLENPC_WARP_PLAYER +#define ENEMY_STARTINTNUM 4 +#else +#define ENEMY_STARTINTNUM 3 +#endif + + for( i = ENEMY_STARTINTNUM; i < ENEMY_DATAINTNUM+ENEMY_STARTINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i,token,sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + ENEMY_setInt( enemy_readlen, i - ENEMY_STARTINTNUM, atoi( token)); + } + if( i < ENEMY_DATAINTNUM+ENEMY_STARTINTNUM ) continue; + for( i = 0; i < ENEMYTEMP_enemynum; i ++ ) { + if( ENEMYTEMP_getInt( i, E_T_TEMPNO)== ENEMY_getInt( enemy_readlen, ENEMY_TEMPNO)){ + break; + } + } + if( i == ENEMYTEMP_enemynum) { + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + ENEMY_enemy[enemy_readlen].enemytemparray = i; +{ + int lv_min, lv_max; + lv_min = ENEMY_getInt( enemy_readlen, ENEMY_LV_MIN); + lv_max = ENEMY_getInt( enemy_readlen, ENEMY_LV_MAX); + if( lv_min == 0 ) lv_min = lv_max; + ENEMY_setInt( enemy_readlen, ENEMY_LV_MIN, min( lv_min, lv_max)); + ENEMY_setInt( enemy_readlen, ENEMY_LV_MAX, max( lv_min, lv_max)); + +} + + enemy_readlen ++; +} + } + fclose(f); + ENEMY_enemynum = enemy_readlen; + print( "Ч %d..", ENEMY_enemynum ); + + return TRUE; +} +/*------------------------------------------------------------------------ + * ENEMY_enemyɬð̻ + *-----------------------------------------------------------------------*/ +BOOL ENEMY_reinitEnemy( void ) +{ + freeMemory( ENEMY_enemy); + return( ENEMY_initEnemy( getEnemyfile())); +} + +/*------------------------------------------------------------------------ + ENEMY_Enemyٯë + *-----------------------------------------------------------------------*/ +int ENEMY_getEnemyArrayFromIndex( int groupindex, int index) +{ + if( !GROUP_CHECKINDEX( groupindex)) return -1; + if( index < 0 || index >= CREATEPROB1 - ENEMY_ID1) return -1; + return GROUP_group[groupindex].enemyarray[index]; +} +/*------------------------------------------------------------------------ + * ENEMY_ID ENEMY_Enemyٯë + *-----------------------------------------------------------------------*/ +int ENEMY_getEnemyArrayFromId( int EnemyId) +{ + int i; + for( i = 0; i < ENEMY_enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == EnemyId) { + return i; + } + } + return -1; +} + +int ENEMY_getEnemyArrayFromTempNo( int EnemyTempNo) +{ + int i; + for( i = 0; i < ENEMY_enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_TEMPNO) == EnemyTempNo) { + return i; + } + } + return -1; +} + +int ENEMY_getEnemyIdFromTempNo( int EnemyTempNo) +{ + int i; + for( i = 0; i < ENEMY_enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_TEMPNO) == EnemyTempNo) { + return ENEMY_getInt( i, ENEMY_ID); + } + } + return -1; +} + +int ENEMY_getEnemyTempNoFromId( int EnemyId) +{ + int i; + for( i = 0; i < ENEMY_enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == EnemyId) { + return ENEMY_getInt( i, ENEMY_TEMPNO); + } + } + return -1; +} + +/*------------------------------------------------------------------------ + * ɬð̻ë + *-----------------------------------------------------------------------*/ +BOOL GROUP_initGroup( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + int group_readlen=0; + int i,j; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "ļʧ\n"); + return FALSE; + } + + GROUP_groupnum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + GROUP_groupnum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Ѱʧ\n" ); + fclose(f); + return FALSE; + } + + GROUP_group = allocateMemory( sizeof(struct tagGROUP_Table) + * GROUP_groupnum ); + if( GROUP_group == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(struct tagGROUP_Table)*GROUP_groupnum); + fclose( f ); + return FALSE; + } + /* */ + for( i = 0; i < GROUP_groupnum; i ++ ) { + for( j = 0; j < GROUP_DATAINTNUM; j ++ ) { + GROUP_setInt( i,j,-1); + } + for( j = 0; j < CREATEPROB1 - ENEMY_ID1; j ++ ) { + GROUP_group[i].enemyarray[j] = -1; + } + } + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + int loop; + + /* ֨պ ݼ׻ƻ */ + for( j = 0; j < GROUP_DATAINTNUM; j ++ ) { + GROUP_setInt( group_readlen,j,-1); + } + for( j = 0; j < CREATEPROB1 - ENEMY_ID1; j ++ ) { + GROUP_group[group_readlen].enemyarray[j] = -1; + } + + /* 繴ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",1,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + GROUP_setChar( group_readlen, GROUP_NAME, token); + + /* 2 ϷѰ */ +#define GROUP_STARTINTNUM 2 + for( i = GROUP_STARTINTNUM; i < GROUP_DATAINTNUM+GROUP_STARTINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + if( strlen( token) != 0 ) { + GROUP_setInt( group_readlen, i - GROUP_STARTINTNUM, atoi( token)); + } + } + if( i < GROUP_DATAINTNUM+GROUP_STARTINTNUM ) continue; + + { + int enemycnt = 0; + for( loop = ENEMY_ID1; loop < CREATEPROB1; loop ++ ) { + if( GROUP_getInt( group_readlen, loop) != -1 ) { + for( i = 0; i < ENEMY_enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) + == GROUP_getInt( group_readlen, loop)) + { + break; + } + } + if( i == ENEMY_enemynum) { + i = -1; + GROUP_setInt( group_readlen, loop, -1); + } + else { + enemycnt ++; + } + GROUP_group[group_readlen].enemyarray[loop - ENEMY_ID1] = i; + } + } + if( enemycnt == 0 ) { + fprint("Ŷ趨еδ趨 ļ:%s %d\n",filename,linenum); + continue;; + } + if( checkRedundancy( &GROUP_group[group_readlen].intdata[ENEMY_ID1], + CREATEPROB1 - ENEMY_ID1)) + { + fprint("Ŷ趨еظ趨 ļ:%s %d\n",filename,linenum); + continue;; + } + + } + + + group_readlen ++; +} + } + fclose(f); + + GROUP_groupnum = group_readlen; + + print( "ЧȺ %d...", GROUP_groupnum ); + + return TRUE; +} +/*------------------------------------------------------------------------ + * ɬð̻ + *-----------------------------------------------------------------------*/ +BOOL GROUP_reinitGroup( void ) +{ + freeMemory( GROUP_group); + return( GROUP_initGroup( getGroupfile())); +} +/*------------------------------------------------------------------------ + * GROUP_ID GROUP_Groupٯë + *-----------------------------------------------------------------------*/ +int GROUP_getGroupArray( int groupid) +{ + int i; + for( i = 0; i < GROUP_groupnum; i ++ ) { + if( GROUP_getInt( i, GROUP_ID) == groupid) { + return i; + } + } + return -1; +} +/*------------------------------------------------------------------------ + * ë£ + *-----------------------------------------------------------------------*/ +static int ENEMY_getExp( int array,int tarray, int level, int rank ) +{ + int ret; + int *p; + int *tp; + float ranknum = 0.0; + float alpha; + struct { + int num; + float rank; + }ranktbl[] = { + { 100, 2.5}, + { 95, 2.0}, + { 90, 1.5}, + { 85, 1.0}, + { 80, 0.5}, + { 0, 0.0}, + }; + level --; + if( level < 0 || level >= arraysizeof( enemybaseexptbl)) return 0; + + p = ENEMY_enemy[array].intdata; + tp = ENEMYTEMP_enemy[tarray].intdata; + + // ¼; ë + if( rank < 0 || rank > 5 ) rank = 0; + ranknum = ranktbl[rank].rank; + + alpha = ( *( tp + E_T_CRITICAL) + *( tp + E_T_COUNTER) + *(tp + E_T_GET) + + *( tp + E_T_POISON) + *( tp + E_T_PARALYSIS) + *(tp + E_T_SLEEP) + + *( tp + E_T_STONE) + *( tp + E_T_DRUNK) + *(tp + E_T_CONFUSION) + ) / 100.0 + + *( tp + E_T_RARE); + /* EXP EXP֣ ¼͡ϫ ì*/ + //return enemybaseexptbl[*(p+ENEMY_LV)] + (ranknum + alpha)*(*(tp+ENEMY_LV)); + ret = enemybaseexptbl[level] + (ranknum + alpha)*(level+1); + return ( ret < 1 ) ? 1 : ret; + +} + + +int ENEMY_getRank( int array, int tarray ){ + int *p; + int *tp; + int paramsum; + int i; + int ranknum; + + struct { + int num; + float rank; + }ranktbl[] = { + { 100, 2.5}, //ܳɳ >= 100 petrank=0 + { 95, 2.0}, + { 90, 1.5}, + { 85, 1.0}, + { 80, 0.5}, + { 0, 0.0}, + }; + + p = ENEMY_enemy[array].intdata; + tp = ENEMYTEMP_enemy[tarray].intdata; + /* ¼ëң */ + /* ̤ëټǣ */ + paramsum = *( tp + E_T_BASEVITAL) + + *( tp + E_T_BASESTR) + + *( tp + E_T_BASETGH) + + *( tp + E_T_BASEDEX); + + ranknum = 0; // ɻ + for( i = 0; i < arraysizeof( ranktbl); i ++ ) { + if( paramsum >= ranktbl[i].num ) { + ranknum = i; + break; + } + } + + return ranknum; + +} + + +//********************************************************* +// ¼ĸةئ +//********************************************************* +static int EnemyGymSkill[] = { + PETSKILL_GUARDBREAK, // ⡰(3) + PETSKILL_CONTINUATIONATTACK1, // ߡ (10) + PETSKILL_CONTINUATIONATTACK2, // ࡰ (11) + PETSKILL_CONTINUATIONATTACK3, // ᡰ (12) + PETSKILL_CHARGE1, // ߡҡ(30) + PETSKILL_CHARGE2, // ࡰҡ(31) + PETSKILL_MIGHTY1, // ߡ ڽ(40) + PETSKILL_MIGHTY2, // ࡰ ڽ(41) + PETSKILL_POWERBALANCE1, // ߡ (50) + PETSKILL_POWERBALANCE2, // ࡰ (51) + PETSKILL_POWERBALANCE3, // ᡰ (52) + PETSKILL_POISON_ATTACK1, // ߡ (60) + PETSKILL_POISON_ATTACK2, // ࡰ (61) + PETSKILL_STONE, // ߡ޼ (80) + PETSKILL_CONFUSION_ATTACK, // ߡ (90) + PETSKILL_DRUNK_ATTACK, // ߨߡ (100) + PETSKILL_SLEEP_ATTACK, // ߡԻ (110) + PETSKILL_NOGUARD1, // ߡá(150) + PETSKILL_NOGUARD2, // ࡰá(151) + PETSKILL_NOGUARD3, // ᡰá(152) +#ifdef _PSKILL_FALLGROUND + PETSKILL_FALLGROUND, // +#endif +#ifdef _SKILL_DAMAGETOHP + PETSKILL_DAMAGETOHP, //Ѫ +#endif +#ifdef _Skill_MPDAMAGE + PETSKILL_MPDAMAGE, //MP˺ +#endif + +#ifdef _SKILL_WILDVIOLENT_ATT + PETSKILL_WILDVIOLENTATTACK, //(540)񱩹 vincent add 2002/05/16 +#endif +#ifdef _SKILL_SPEEDY_ATT + PETSKILL_SPEEDYATTACK, //(541)ٹ vincent add 2002/05/16 +#endif +#ifdef _SKILL_GUARDBREAK2 + PETSKILL_GUARDBREAK2, //(542)Ƴ2 vincent add 2002/05/20 +#endif +#ifdef _SKILL_SACRIFICE + PETSKILL_SACRIFICE, //(543)Ԯ vincent add 2002/05/30 +#endif +#ifdef _SKILL_WEAKEN + PETSKILL_WEAKEN, //(544)Ԯ vincent add 2002/07/11 +#endif +#ifdef _SKILL_DEEPPOISON + PETSKILL_DEEPPOISON, //(545)Ԯ vincent add 2002/07/16 +#endif +#ifdef _SKILL_BARRIER + PETSKILL_BARRIER, //(546)ħ vincent add 2002/07/16 +#endif +#ifdef _SKILL_NOCAST + PETSKILL_NOCAST, //(547)Ĭ vincent add 2002/07/16 +#endif +#ifdef _SKILL_ROAR + PETSKILL_ROAR, //(548) vincent add 2002/07/11 +#endif + +#ifdef _SKILL_REFRESH + PETSKILL_REFRESH, //(550)Ԯ vincent add 2002/08/08 +#endif +#ifdef _VARY_WOLF + PETSKILL_VARY, +#endif +#ifdef _PETSKILL_SETDUCK + PETSKILL_SETDUCK, +#endif + +#ifdef _MAGICPET_SKILL + PETSKILL_SETMAGICPET, +#endif +#ifdef _PETSKILL_BECOMEPIG + PETSKILL_BECOMEPIG, +#endif +#ifdef _PETSKILL_LER + PETSKILL_BATFLY, + PETSKILL_DIVIDEATTACK, +#endif +#ifdef _PETSKILL_BATTLE_MODEL + PETSKILL_BATTLE_MODEL, +#endif +}; + +static int gymbody[] = { + SPR_001em,SPR_011em,SPR_021em,SPR_031em,SPR_041em,SPR_051em, + SPR_061em,SPR_071em,SPR_081em,SPR_091em,SPR_101em,SPR_111em, + + SPR_002em,SPR_012em,SPR_022em,SPR_032em,SPR_042em,SPR_052em, + SPR_062em,SPR_072em,SPR_082em,SPR_092em,SPR_102em,SPR_112em, + + SPR_003em,SPR_013em,SPR_023em,SPR_033em,SPR_043em,SPR_053em, + SPR_063em,SPR_073em,SPR_083em,SPR_093em,SPR_103em,SPR_113em, + + SPR_004em,SPR_014em,SPR_024em,SPR_034em,SPR_044em,SPR_054em, + SPR_064em,SPR_074em,SPR_084em,SPR_094em,SPR_104em,SPR_114em, +}; + + +/*------------------------------------------------------------------------ + * ENEMY¼ĸةئ ëܸ + *-----------------------------------------------------------------------*/ +int ENEMY_RandomChange( int enemyindex, int tempno ) +{ + int work, work2, iRet = 0; + + // ¼ĸةƽҷ¾ + if( ( 564 <= tempno && tempno <= 580 ) + || ( 739 <= tempno && tempno <= 750 ) + || ( 895 <= tempno && tempno <= 906 ) + ){ + //******************************************** + // ӿ + //******************************************** + iRet = 1; + }else + // ¼ĸةƽҷ¾ + if( ( 655 <= tempno && tempno <= 720 ) + || ( 859 <= tempno && tempno <= 894 ) + || ( 907 <= tempno && tempno <= 940 ) + ){ + //******************************************** + // ʸӿ + //******************************************** + iRet = 2; + }else{ + return 0; + } + + + if( iRet == 1 ){ + //******************************************** + // + // ӿ׳ئƥַ¼ĸة + // + //******************************************** + // ϳַ¼ĸة + CHAR_setInt( enemyindex, CHAR_BASEBASEIMAGENUMBER, + gymbody[RAND( 0, arraysizeof( gymbody ) - 1)] ); + CHAR_setInt( enemyindex, CHAR_BASEIMAGENUMBER, + CHAR_getInt( enemyindex, CHAR_BASEBASEIMAGENUMBER ) ); + // 뷴 + work = ( RAND( 0, 20 ) - 10 ) * 10; + work2 = 100 - ABS( work ); + CHAR_setInt( enemyindex, CHAR_EARTHAT, work ); + CHAR_setInt( enemyindex, CHAR_FIREAT, -work ); + if( RAND( 0, 1 ) ){ + work2 *= -1; + } + CHAR_setInt( enemyindex, CHAR_WATERAT, work2 ); + CHAR_setInt( enemyindex, CHAR_WINDAT, -work2 ); + + // ¼ĸةئ տë + if( DoujyouRandomWeponSet( enemyindex ) ){ + // տɧ ë + CHAR_setPetSkill( enemyindex, 0, PETSKILL_NORMALATTACK ); + CHAR_setPetSkill( enemyindex, 1, PETSKILL_NORMALATTACK ); + }else{ + // տԪئмƥ + // ë + CHAR_setPetSkill( enemyindex, 0, + EnemyGymSkill[RAND( 0, arraysizeof( EnemyGymSkill ) - 1 )] ); + // ë + CHAR_setPetSkill( enemyindex, 1, + EnemyGymSkill[RAND( 0, arraysizeof( EnemyGymSkill ) - 1 )] ); + } + + }else + if( iRet == 2 ){ + // տԪئмƥ + // ë + CHAR_setPetSkill( enemyindex, 0, + EnemyGymSkill[RAND( 0, arraysizeof( EnemyGymSkill ) - 1 )] ); + // ë + CHAR_setPetSkill( enemyindex, 1, + EnemyGymSkill[RAND( 0, arraysizeof( EnemyGymSkill ) - 1 )] ); + } + + return 1; + +} + + +/*------------------------------------------------------------------------ + * ENEMY_enemyƽҷë£ + *-----------------------------------------------------------------------*/ +int ENEMY_createEnemy( int array, int baselevel ) +{ + Char CharNew; + int newindex; + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + int itemindex,iloop; + int level; + int enemyrank; + + if( !ENEMY_CHECKINDEX( array)) return -1; + + p = ENEMY_enemy[array].intdata; + tarray = ENEMYTEMP_getEnemyTempArray( array); + + if( !ENEMYTEMP_CHECKINDEX( tarray)) return -1; +// tp = ENEMYTEMP_enemy[tarray].intdata; + // + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_enemy[tarray].intdata[i]; + } + + // + memset( &CharNew, 0, sizeof( Char ) ); + + if( !CHAR_getDefaultChar( &CharNew,31010 ) )return -1; + + /* į */ + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = *(tp+E_T_IMGNUMBER); + /* ƥؤɬ */ + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEENEMY; + /* ë */ + CharNew.data[CHAR_DUELPOINT] = 0; + + /* ìë£ */ + if( baselevel > 0 ){ + level = baselevel; // ì + }else{ + level = RAND( (*(p + ENEMY_LV_MIN)), (*(p+ ENEMY_LV_MAX))); + } +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +/* ɷ¶϶Ѿ ˼ ɷ¶߼ңֿ */ +#if 1 +#define PARAM_CAL( l) ( ( level -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#else +#define PARAM_CAL( l) ( (E_PAR(ENEMY_LV) -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#endif + /* ԻԻ̼士ë¼ĸةƥ浤 */ + tp[E_T_BASEVITAL] += RAND( 0, 4 ) - 2; + tp[E_T_BASESTR] += RAND( 0, 4 ) - 2; + tp[E_T_BASETGH] += RAND( 0, 4 ) - 2; + tp[E_T_BASEDEX] += RAND( 0, 4 ) - 2; + /* ƥԻԻ̼ëƻ */ + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + CharNew.data[CHAR_ALLOCPOINT] + = ( tp[E_T_BASEVITAL] << 24 ) + + ( tp[E_T_BASESTR] << 16 ) + + ( tp[E_T_BASETGH] << 8 ) + + ( tp[E_T_BASEDEX] << 0 ); + /* ¼ĸةƥ̼ë𹴵ң۳ľë߼Ի߯ʣ*/ + for( i = 0; i < 10; i ++ ){ + int work = RAND( 0, 3 ); + if( work == 0 )tp[E_T_BASEVITAL]++; + if( work == 1 )tp[E_T_BASESTR]++; + if( work == 2 )tp[E_T_BASETGH]++; + if( work == 3 )tp[E_T_BASEDEX]++; + } + + /* ɷ¶ */ + CharNew.data[CHAR_VITAL] = PARAM_CAL(E_T_BASEVITAL); + CharNew.data[CHAR_STR] = PARAM_CAL(E_T_BASESTR); + CharNew.data[CHAR_TOUGH] = PARAM_CAL(E_T_BASETGH); + CharNew.data[CHAR_DEX] = PARAM_CAL(E_T_BASEDEX); + CharNew.data[CHAR_FIREAT] = *(tp+ E_T_FIREAT); + CharNew.data[CHAR_WATERAT] = *(tp+ E_T_WATERAT); + CharNew.data[CHAR_EARTHAT] = *(tp+ E_T_EARTHAT); + CharNew.data[CHAR_WINDAT] = *(tp+ E_T_WINDAT); + CharNew.data[CHAR_MODAI] = *(tp+ E_T_MODAI); + CharNew.data[CHAR_VARIABLEAI] = 0; + CharNew.data[CHAR_LV] = level; + //CharNew.data[CHAR_LV] = *(p+ ENEMY_LV); + CharNew.data[CHAR_SLOT] = *(tp+ E_T_SLOT); + CharNew.data[CHAR_POISON] = *(tp+ E_T_POISON); + CharNew.data[CHAR_PARALYSIS]= *(tp+ E_T_PARALYSIS); + CharNew.data[CHAR_SLEEP] = *(tp+ E_T_SLEEP); + CharNew.data[CHAR_STONE] = *(tp+ E_T_STONE); + CharNew.data[CHAR_DRUNK] = *(tp+ E_T_DRUNK); + CharNew.data[CHAR_CONFUSION]= *(tp+ E_T_CONFUSION); + CharNew.data[CHAR_RARE] = *(tp+ E_T_RARE); + CharNew.data[CHAR_PETID] = *(tp + E_T_TEMPNO); + CharNew.data[CHAR_CRITIAL] = *(tp + E_T_CRITICAL); + CharNew.data[CHAR_COUNTER] = *(tp + E_T_COUNTER); + CharNew.data[CHAR_PETENEMYID] = ENEMY_getInt( array, ENEMY_ID); + + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + CharNew.unionTable.indexOfPetskill[i] = *(tp + E_T_PETSKILL1 + i); + } + + enemyrank = ENEMY_getRank( array, tarray ); + CharNew.data[CHAR_PETRANK] = enemyrank; +#undef E_PAR +#undef ET_PAR +#undef PARAM_CAL + CharNew.data[CHAR_DUELPOINT] = *( p + ENEMY_DUELPOINT); + if( *( p + ENEMY_DUELPOINT) <= 0 ) { + if( *(p + ENEMY_EXP) != -1 ) { + CharNew.data[CHAR_EXP] = *( p+ENEMY_EXP); + }else { + CharNew.data[CHAR_EXP] = ENEMY_getExp( array,tarray,level, enemyrank); + } + } + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + (char *)ENEMYTEMP_enemy[tarray].chardata[E_T_NAME].string ); + + + newindex = CHAR_initCharOneArray( &CharNew ); + + + if( newindex < 0 ){ + return -1; + } + for( iloop=0; iloop< (ENEMY_ITEMPROB10 - ENEMY_ITEM1+1)/2; iloop++){ + if( *(p+ENEMY_ITEMPROB1+iloop) != 0) { +#ifdef _FIX_ITEMPROB + if( RAND( 0,999) < *(p+ENEMY_ITEMPROB1+iloop)){ +#else + if( RAND( 0,99) < *(p+ENEMY_ITEMPROB1+iloop)){ +#endif + itemindex = ITEM_makeItemAndRegist( *(p+ENEMY_ITEM1+iloop) ); + CHAR_setItemIndex( newindex, CHAR_STARTITEMARRAY +iloop, itemindex); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, newindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX,-1); + + } + } + } + + { int style, wepon = -1; + style = (*(p + ENEMY_STYLE)); + switch( style ){ + case 1: wepon = 0;break; // + case 2: wepon = 100;break; // + case 3: wepon = 200;break; // + case 4: wepon = 400;break; // + case 5: wepon = 500;break; // Ƥ¼ + case 6: wepon = 700;break; // + case 7: wepon = 600;break; // + default:break; + } + if( wepon >= 0 ){ + itemindex = ITEM_makeItemAndRegist( wepon ) ; + CHAR_setItemIndex( newindex, CHAR_ARM, itemindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, newindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX,-1); + } + } + + ENEMY_RandomChange( newindex, *( p+ENEMY_ID) ); + CHAR_complianceParameter( newindex ); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif + CHAR_setInt( newindex, CHAR_HP, CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setWorkInt( newindex, CHAR_WORKTACTICS, *(p+ENEMY_TACTICS)); + CHAR_setWorkChar( newindex, CHAR_WORKBATTLE_TACTICSOPTION, + ENEMY_enemy[array].chardata[ENEMY_TACTICSOPTION].string ); +#ifdef _BATTLENPC_WARP_PLAYER + CHAR_setWorkChar( newindex, CHAR_WORKBATTLE_ACT_CONDITION, + ENEMY_enemy[array].chardata[ENEMY_ACT_CONDITION].string ); +#endif + CHAR_setWorkInt( newindex, CHAR_WORK_PETFLG, *(p+ENEMY_PETFLG)); + CHAR_setWorkInt( newindex, CHAR_WORKMODCAPTUREDEFAULT, *(tp + E_T_GET)); +#ifdef _ENEMY_FALLGROUND + { + int i=0; + for( i=0;i= arraysizeof( RandomEnemyTbl ) ) return 0; + + // ¼ĸةɬ + randwork = RAND( 0, RandomEnemyTbl[i].arraysize - 1 ); + // ޥ įë + work = RandomEnemyTbl[i].pTbl[randwork]; + *pNew = ENEMY_getEnemyArrayFromId( work ); + return 1; + }else{ + // ئ + return 0; + } +} + +int *ENEMY_getEnemy( int charaindex, int x, int y) +{ + int i; + int array; + int g_array; + int e_array; + int found = 0; + int work[ENEMY_INDEXTABLEMAXSIZE]; + int wr[ENEMY_INDEXTABLEMAXSIZE]; + int createenemynum; + int enemyentrymax; + int entrymax; + int r_max; + int groupid; + int bigcnt; + int loopcounter; + array = ENCOUNT_getEncountAreaArray( CHAR_getInt( charaindex, CHAR_FLOOR),x,y); + if( array == -1 ) return NULL; + enemyentrymax = ENCOUNT_getCreateEnemyMaxNumFromArray( array); + if( enemyentrymax == -1 ) { + return NULL; + } + for( i = 0 ; i < ENEMY_INDEXTABLEMAXSIZE; i ++ ) { + work[i] = -1; + wr[i] = -1; + ENEMY_indextable[i] = -1; + } + + r_max= 0; + for( i = 0; i < ENCOUNT_GROUPMAXNUM; i ++ ){ + if( ENCOUNT_getGroupIdFromArray( array, i ) != - 1 ) { + int itemid; + groupid = ENCOUNT_getGroupIdFromArray( array, i); + g_array = GROUP_getGroupArray( groupid); + itemid = GROUP_getInt( g_array, GROUP_APPEARBYITEMID); + if( itemid != -1 ) { + int j; + for( j = 0; j < CheckCharMaxItem(charaindex); j ++ ) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid){ + break; + } + } + } + if( j == CheckCharMaxItem(charaindex) ) continue; + } + itemid = GROUP_getInt( g_array, GROUP_NOTAPPEARBYITEMID); + if( itemid != -1 ) { + int j; + for( j = 0; j < CheckCharMaxItem(charaindex); j ++ ) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid){ + break; + } + } + } + if( j != CheckCharMaxItem(charaindex) ) continue; + } + + work[found] = i; + wr[found] = ENCOUNT_getGroupProbFromArray( array, i); + r_max += wr[found]; + found ++; + } + } + r_max --; + + if( found <= 0 ) return NULL; + { + int aaa = 0; + int r; + r = RAND( 0, r_max); + for( i = 0; i < found-1; i ++ ) { + aaa += wr[i]; + if( wr[i] != 0 && r < aaa ) break; + } + r = i; + + groupid = ENCOUNT_getGroupIdFromArray( array, work[r]); + g_array = GROUP_getGroupArray( groupid); + } + for( i = 0 ; i < ENEMY_INDEXTABLEMAXSIZE; i ++ ) { + work[i] = -1; + wr[i] = -1; + } + createenemynum = 0; + found = 0; + r_max = 0; + for( i = ENEMY_ID1; i < CREATEPROB1; i ++ ) { + int newarray, enemywork; + e_array = ENEMY_getEnemyArrayFromIndex( g_array, i - ENEMY_ID1 ); + +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ + { + int char_event_now = -1, char_event_end = -1; + if(ENCOUNT_table[array].event_now != -1){ + char_event_now = ENCOUNT_table[array].event_now; + } + else if(ENCOUNT_table[array].event_end != -1){ + char_event_end = ENCOUNT_table[array].event_end; + } + if( (char_event_now > 0) || ( char_event_end > 0 ) ) { + if( (NPC_NowEventCheckFlg( charaindex, char_event_now) == TRUE ) || + (NPC_EventCheckFlg( charaindex, char_event_end) == TRUE ) ){ + + e_array = ENEMY_getEnemyArrayFromIndex( + GROUP_getGroupArray( ENCOUNT_table[array].enemy_group ),i - ENEMY_ID1 ); + } + } + } +#endif + enemywork = ENEMY_getInt( e_array, ENEMY_ID ); + if( ENEMY_RandomEnemyArray( enemywork, &newarray ) ){ + e_array = newarray; + } + + if( e_array != -1 ) { + work[found] = e_array; +#ifdef _UP_BBPETPROB + if( ENEMY_getInt( e_array, ENEMY_LV_MAX )==1){ + wr[found] = GROUP_getInt( g_array, i + (CREATEPROB1 - ENEMY_ID1))*getUpBBProb(); + print("\nAFT=%d",wr[found]); + }else{ + wr[found] = GROUP_getInt( g_array, i + (CREATEPROB1 - ENEMY_ID1)); + } +#else + wr[found] = GROUP_getInt( g_array, i + (CREATEPROB1 - ENEMY_ID1)); +#endif + r_max += wr[found]; + found ++; + createenemynum += ENEMY_getInt( e_array, ENEMY_CREATEMAXNUM); + } + } + r_max --; + + if( found <= 0 ) return NULL; + enemyentrymax= min( enemyentrymax, createenemynum ); + entrymax = RAND( 1, enemyentrymax); + bigcnt = 0; + for( i = 0,loopcounter = 0; i < entrymax && loopcounter < 100; loopcounter ++) { + int cnt; + int j,r; + int aaa = 0; + int et_array; + int k,samecount; + r = RAND( 0, r_max); + for( j = 0; j < found-1; j ++ ) { + aaa += wr[j]; + if( wr[j] != 0 && r < aaa ){ + // print("\nj=%d enemyid=%d wr[j]=%d aaa=%d r=%d r_max=%d ",j,work[j],wr[j],aaa,r,r_max); + break; + } + } + r = j; + cnt = 0; + for( j = 0; j < ENEMY_INDEXTABLEMAXSIZE && ENEMY_indextable[j] != -1; j ++ ) { + if( ENEMY_indextable[j] == work[r] ) cnt ++; + } + samecount = 0; + for( k = 0; k < found; k ++ ) { + if( work[r] == work[k] ) samecount ++; + } + if( cnt >= ENEMY_getInt( work[r], ENEMY_CREATEMAXNUM) * samecount ) { + continue; + } + + et_array = ENEMYTEMP_getEnemyTempArray( work[r]); + if( ENEMYTEMP_CHECKINDEX( et_array)) { + if( ENEMYTEMP_getInt( et_array, E_T_SIZE) == E_T_SIZE_BIG ) { + if( bigcnt >= 5 ) { + entrymax --; + continue; + } + if( i > 4 ) { + int target_et_array; + int flg = FALSE; + for( j = 0; j < 5; j ++ ) { + if( !ENEMY_CHECKINDEX( ENEMY_indextable[j])) break; + + target_et_array = ENEMYTEMP_getEnemyTempArray( + ENEMY_indextable[j]); + if( !ENEMYTEMP_CHECKINDEX( target_et_array)) break; + if( ENEMYTEMP_getInt( target_et_array, E_T_SIZE) == E_T_SIZE_NORMAL ){ + flg = TRUE; + break; + } + } + if( !flg) continue; + ENEMY_indextable[i] = ENEMY_indextable[j]; + ENEMY_indextable[j] = work[r]; + } + else { + ENEMY_indextable[i] = work[r]; + } + bigcnt ++; + }else { + ENEMY_indextable[i] = work[r]; + } + + i++; + } + } + return found > 0 ? ENEMY_indextable : NULL; +} +int ENEMY_createPetFromEnemyIndex( int charaindex, int array) +{ + Char CharNew; + int newindex; + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + int havepetelement; + int level; + int enemyrank; + if( !ENEMY_CHECKINDEX( array)) return -1; + havepetelement = CHAR_getCharPetElement( charaindex); + if( havepetelement < 0 ) return -1; + + p = ENEMY_enemy[array].intdata; + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)) return -1; + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_enemy[tarray].intdata[i]; + } + memset( &CharNew, 0, sizeof( Char ) ); + if( !CHAR_getDefaultChar( &CharNew,31010 ) )return -1; + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = *(tp+E_T_IMGNUMBER); + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + level = RAND( (*(p + ENEMY_LV_MIN)), ( *(p+ ENEMY_LV_MAX))); + +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +#if 1 +#define PARAM_CAL( l) (( level -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#else +#define PARAM_CAL( l) ( (E_PAR(ENEMY_LV) -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#endif + + tp[E_T_BASEVITAL] += RAND( 0, 4 ) - 2; + tp[E_T_BASESTR] += RAND( 0, 4 ) - 2; + tp[E_T_BASETGH] += RAND( 0, 4 ) - 2; + tp[E_T_BASEDEX] += RAND( 0, 4 ) - 2; + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + CharNew.data[CHAR_ALLOCPOINT] + = ( tp[E_T_BASEVITAL] << 24 ) + + ( tp[E_T_BASESTR] << 16 ) + + ( tp[E_T_BASETGH] << 8 ) + + ( tp[E_T_BASEDEX] << 0 ); + + for( i = 0; i < 10; i ++ ){ + int work = RAND( 0, 3 ); + if( work == 0 )tp[E_T_BASEVITAL]++; + if( work == 1 )tp[E_T_BASESTR]++; + if( work == 2 )tp[E_T_BASETGH]++; + if( work == 3 )tp[E_T_BASEDEX]++; + } + //ʼֵ + CharNew.data[CHAR_VITAL] = PARAM_CAL(E_T_BASEVITAL); + CharNew.data[CHAR_STR] = PARAM_CAL(E_T_BASESTR); + CharNew.data[CHAR_TOUGH] = PARAM_CAL(E_T_BASETGH); + CharNew.data[CHAR_DEX] = PARAM_CAL(E_T_BASEDEX); + // + CharNew.data[CHAR_FIREAT] = *(tp+ E_T_FIREAT); + CharNew.data[CHAR_WATERAT] = *(tp+ E_T_WATERAT); + CharNew.data[CHAR_EARTHAT] = *(tp+ E_T_EARTHAT); + CharNew.data[CHAR_WINDAT] = *(tp+ E_T_WINDAT); + + CharNew.data[CHAR_SLOT] = *(tp+ E_T_SLOT);//ܸ + CharNew.data[CHAR_MODAI] = *(tp+ E_T_MODAI);//AIģʽ + CharNew.data[CHAR_VARIABLEAI] = 0;// + CharNew.data[CHAR_LV] = level;//ȼ + //CharNew.data[CHAR_LV] = *(p+ ENEMY_LV); + CharNew.data[CHAR_POISON] = *(tp+ E_T_POISON);// + CharNew.data[CHAR_PARALYSIS]= *(tp+ E_T_PARALYSIS);//鿹 + CharNew.data[CHAR_SLEEP] = *(tp+ E_T_SLEEP);//˯ + CharNew.data[CHAR_STONE] = *(tp+ E_T_STONE);//ʯ + CharNew.data[CHAR_DRUNK] = *(tp+ E_T_DRUNK);// + CharNew.data[CHAR_CONFUSION]= *(tp+ E_T_CONFUSION);// + CharNew.data[CHAR_RARE] = *(tp+ E_T_RARE);//ϡ + CharNew.data[CHAR_PETID] = *(tp + E_T_TEMPNO);// + CharNew.data[CHAR_CRITIAL] = *(tp + E_T_CRITICAL);// + CharNew.data[CHAR_COUNTER] = *(tp + E_T_COUNTER);// + CharNew.data[CHAR_PETENEMYID] = ENEMY_getInt( array, ENEMY_ID);//ID + + // Arminius 8.6 limit lv + CharNew.data[CHAR_LIMITLEVEL] = *(tp + E_T_LIMITLEVEL);//޵ȼ +#ifdef _PET_FUSION + CharNew.data[CHAR_FUSIONCODE] = *(tp + E_T_FUSIONCODE);// +#endif + CharNew.data[CHAR_PETMAILEFFECT] = RAND(0, PETMAIL_EFFECTMAX);//Ч + + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) {// + CharNew.unionTable.indexOfPetskill[i] = *(tp + E_T_PETSKILL1 + i); + } + + enemyrank = ENEMY_getRank( array, tarray ); + CharNew.data[CHAR_PETRANK] = enemyrank;//ɳ +#undef E_PAR +#undef ET_PAR +#undef PARAM_CAL + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + (char *)ENEMYTEMP_enemy[tarray].chardata[E_T_NAME].string ); + newindex = PET_initCharOneArray( &CharNew ); + if( newindex < 0 ){ + return -1; + } + + CHAR_complianceParameter( newindex ); + CHAR_setInt( newindex, CHAR_HP, CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif + CHAR_setWorkInt( newindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetelement, newindex); + CHAR_setChar( newindex, CHAR_OWNERCDKEY, + CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( newindex, CHAR_OWNERCHARANAME, + CHAR_getChar( charaindex, CHAR_NAME)); +#ifdef _PETSKILL_NEW_PASSIVE + if (getAutoGetSkill()>0){ + if (isFusionPet(CHAR_getInt(newindex,CHAR_PETID))==0) { + CHAR_setPetSkill(newindex,getSkillPos(),getRandSkill()); + } + } +#endif + return newindex; +} +int ENEMY_createPet( int array, int vital, int str, int tgh, int dex) +{ + Char CharNew; + int newindex; + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + int level; + int enemyrank; + if( !ENEMY_CHECKINDEX( array)) return -1; + + p = ENEMY_enemy[array].intdata; + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)) return -1; +// tp = ENEMYTEMP_enemy[tarray].intdata; + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_enemy[tarray].intdata[i]; + } + memset( &CharNew, 0, sizeof( Char ) ); + if( !CHAR_getDefaultChar( &CharNew,31010 ) )return -1; + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = *(tp+E_T_IMGNUMBER); + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + level = RAND( (*(p + ENEMY_LV_MIN)), ( *(p+ ENEMY_LV_MAX))); + +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +#if 1 +#define PARAM_CAL( l) (( level -1)*ET_PAR( E_T_LVUPPOINT) + ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#else +#define PARAM_CAL( l) ( (E_PAR(ENEMY_LV) -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#endif + tp[E_T_BASEVITAL] += RAND( 0, 4 ) - 2; + tp[E_T_BASESTR] += RAND( 0, 4 ) - 2; + tp[E_T_BASETGH] += RAND( 0, 4 ) - 2; + tp[E_T_BASEDEX] += RAND( 0, 4 ) - 2; + + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + + if(vital > -1){ + tp[E_T_BASEVITAL] = vital; + } + if(str > -1){ + tp[E_T_BASESTR] = str; + } + if(tgh > -1){ + tp[E_T_BASETGH] = tgh; + } + if(dex > -1){ + tp[E_T_BASEDEX] = dex; + } + + CharNew.data[CHAR_ALLOCPOINT] + = ( tp[E_T_BASEVITAL] << 24) + + ( tp[E_T_BASESTR] << 16) + + ( tp[E_T_BASETGH] << 8) + + ( tp[E_T_BASEDEX] << 0); + + + for( i = 0; i < 10; i ++ ){ + int work = RAND( 0, 3 ); + if( work == 0 )tp[E_T_BASEVITAL]++; + if( work == 1 )tp[E_T_BASESTR]++; + if( work == 2 )tp[E_T_BASETGH]++; + if( work == 3 )tp[E_T_BASEDEX]++; + } + /* ɷ¶ */ + CharNew.data[CHAR_VITAL] = PARAM_CAL(E_T_BASEVITAL); + CharNew.data[CHAR_STR] = PARAM_CAL(E_T_BASESTR); + CharNew.data[CHAR_TOUGH] = PARAM_CAL(E_T_BASETGH); + CharNew.data[CHAR_DEX] = PARAM_CAL(E_T_BASEDEX); + + CharNew.data[CHAR_FIREAT] = *(tp+ E_T_FIREAT); + CharNew.data[CHAR_WATERAT] = *(tp+ E_T_WATERAT); + CharNew.data[CHAR_EARTHAT] = *(tp+ E_T_EARTHAT); + CharNew.data[CHAR_WINDAT] = *(tp+ E_T_WINDAT); + + CharNew.data[CHAR_SLOT] = *(tp+ E_T_SLOT); + CharNew.data[CHAR_MODAI] = *(tp+ E_T_MODAI); + CharNew.data[CHAR_VARIABLEAI] = 0; + CharNew.data[CHAR_LV] = level; + //CharNew.data[CHAR_LV] = *(p+ ENEMY_LV); + CharNew.data[CHAR_POISON] = *(tp+ E_T_POISON); + CharNew.data[CHAR_PARALYSIS]= *(tp+ E_T_PARALYSIS); + CharNew.data[CHAR_SLEEP] = *(tp+ E_T_SLEEP); + CharNew.data[CHAR_STONE] = *(tp+ E_T_STONE); + CharNew.data[CHAR_DRUNK] = *(tp+ E_T_DRUNK); + CharNew.data[CHAR_CONFUSION]= *(tp+ E_T_CONFUSION); + CharNew.data[CHAR_RARE] = *(tp+ E_T_RARE); + CharNew.data[CHAR_PETID] = *(tp + E_T_TEMPNO); + CharNew.data[CHAR_CRITIAL] = *(tp + E_T_CRITICAL); + CharNew.data[CHAR_COUNTER] = *(tp + E_T_COUNTER); + // Arminius 8.6 limit lv + CharNew.data[CHAR_LIMITLEVEL] = *(tp + E_T_LIMITLEVEL); +#ifdef _PET_FUSION + CharNew.data[CHAR_FUSIONCODE] = *(tp + E_T_FUSIONCODE); +#endif + CharNew.data[CHAR_PETMAILEFFECT] = RAND(0, PETMAIL_EFFECTMAX); + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + CharNew.unionTable.indexOfPetskill[i] = *(tp + E_T_PETSKILL1 + i); + } + enemyrank = ENEMY_getRank( array, tarray ); + CharNew.data[CHAR_PETRANK] = enemyrank; +#undef E_PAR +#undef ET_PAR +#undef PARAM_CAL + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + (char *)ENEMYTEMP_enemy[tarray].chardata[E_T_NAME].string ); + newindex = PET_initCharOneArray( &CharNew ); + if( newindex < 0 ){ + return -1; + } + CHAR_complianceParameter( newindex ); + CHAR_setInt( newindex, CHAR_HP, CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif + + + CHAR_setWorkInt( newindex, CHAR_WORKPLAYERINDEX, -1); + + return newindex; +} + +#ifdef _TEST_DROPITEMS +int ENEMY_TEST_createPetIndex( int array) +{ + Char CharNew; + int newindex; + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + //int havepetelement; + int level; + int enemyrank; + if( !ENEMY_CHECKINDEX( array)) return -1; + + //havepetelement = CHAR_getCharPetElement( charaindex); + //if( havepetelement < 0 ) return -1; + p = ENEMY_enemy[array].intdata; + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)) return -1; + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_enemy[tarray].intdata[i]; + } + memset( &CharNew, 0, sizeof( Char ) ); + if( !CHAR_getDefaultChar( &CharNew,31010 ) )return -1; + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = *(tp+E_T_IMGNUMBER); + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + level = RAND( (*(p + ENEMY_LV_MIN)), ( *(p+ ENEMY_LV_MAX))); + +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) + +#if 1 +#define PARAM_CAL( l) (( level -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#else +#define PARAM_CAL( l) ( (E_PAR(ENEMY_LV) -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) +#endif + tp[E_T_BASEVITAL] += RAND( 0, 4 ) - 2; + tp[E_T_BASESTR] += RAND( 0, 4 ) - 2; + tp[E_T_BASETGH] += RAND( 0, 4 ) - 2; + tp[E_T_BASEDEX] += RAND( 0, 4 ) - 2; + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + CharNew.data[CHAR_ALLOCPOINT] + = ( tp[E_T_BASEVITAL] << 24 ) + + ( tp[E_T_BASESTR] << 16 ) + + ( tp[E_T_BASETGH] << 8 ) + + ( tp[E_T_BASEDEX] << 0 ); + for( i = 0; i < 10; i ++ ){ + int work = RAND( 0, 3 ); + if( work == 0 )tp[E_T_BASEVITAL]++; + if( work == 1 )tp[E_T_BASESTR]++; + if( work == 2 )tp[E_T_BASETGH]++; + if( work == 3 )tp[E_T_BASEDEX]++; + } + CharNew.data[CHAR_VITAL] = PARAM_CAL(E_T_BASEVITAL); + CharNew.data[CHAR_STR] = PARAM_CAL(E_T_BASESTR); + CharNew.data[CHAR_TOUGH] = PARAM_CAL(E_T_BASETGH); + CharNew.data[CHAR_DEX] = PARAM_CAL(E_T_BASEDEX); + CharNew.data[CHAR_FIREAT] = *(tp+ E_T_FIREAT); + CharNew.data[CHAR_WATERAT] = *(tp+ E_T_WATERAT); + CharNew.data[CHAR_EARTHAT] = *(tp+ E_T_EARTHAT); + CharNew.data[CHAR_WINDAT] = *(tp+ E_T_WINDAT); + + CharNew.data[CHAR_SLOT] = *(tp+ E_T_SLOT); + CharNew.data[CHAR_MODAI] = *(tp+ E_T_MODAI); + CharNew.data[CHAR_VARIABLEAI] = 0; + CharNew.data[CHAR_LV] = level; + CharNew.data[CHAR_POISON] = *(tp+ E_T_POISON); + CharNew.data[CHAR_PARALYSIS]= *(tp+ E_T_PARALYSIS); + CharNew.data[CHAR_SLEEP] = *(tp+ E_T_SLEEP); + CharNew.data[CHAR_STONE] = *(tp+ E_T_STONE); + CharNew.data[CHAR_DRUNK] = *(tp+ E_T_DRUNK); + CharNew.data[CHAR_CONFUSION]= *(tp+ E_T_CONFUSION); + CharNew.data[CHAR_RARE] = *(tp+ E_T_RARE); + CharNew.data[CHAR_PETID] = *(tp + E_T_TEMPNO); + CharNew.data[CHAR_CRITIAL] = *(tp + E_T_CRITICAL); + CharNew.data[CHAR_COUNTER] = *(tp + E_T_COUNTER); + CharNew.data[CHAR_PETENEMYID] = ENEMY_getInt( array, ENEMY_ID); + + // Arminius 8.6 limit lv + CharNew.data[CHAR_LIMITLEVEL] = *(tp + E_T_LIMITLEVEL); +#ifdef _PET_FUSION + CharNew.data[CHAR_FUSIONCODE] = *(tp + E_T_FUSIONCODE); +#endif + CharNew.data[CHAR_PETMAILEFFECT] = RAND(0, PETMAIL_EFFECTMAX); + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + CharNew.unionTable.indexOfPetskill[i] = *(tp + E_T_PETSKILL1 + i); + } + enemyrank = ENEMY_getRank( array, tarray ); + CharNew.data[CHAR_PETRANK] = enemyrank; +#undef E_PAR +#undef ET_PAR +#undef PARAM_CAL + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + (char *)ENEMYTEMP_enemy[tarray].chardata[E_T_NAME].string ); + newindex = PET_initCharOneArray( &CharNew ); + if( newindex < 0 ){ + return -1; + } + CHAR_complianceParameter( newindex ); + CHAR_setInt( newindex, CHAR_HP, CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif +// CHAR_setWorkInt( newindex, CHAR_WORKPLAYERINDEX, charaindex); +// CHAR_setCharPet( charaindex, havepetelement, newindex); +// CHAR_setChar( newindex, CHAR_OWNERCDKEY, +// CHAR_getChar( charaindex, CHAR_CDKEY)); +// CHAR_setChar( newindex, CHAR_OWNERCHARANAME, +// CHAR_getChar( charaindex, CHAR_NAME)); + return newindex; +} +#endif + +#ifdef _PET_EVOLUTION + +BOOL PETFUSION_getIndexForChar( int toindex, int *MainIndex, int *Subindex1, int *Subindex2, char *data) +{ + char buf1[256]; + int pindex[3]={-1,-1,-1}; + int i; + int ridepet=CHAR_getInt( toindex , CHAR_RIDEPET); + int rideindex = CHAR_getCharPet( toindex,ridepet); + if( getStringFromIndexWithDelim( data, "|", 1, buf1, sizeof(buf1)) == FALSE ) + return FALSE; + pindex[0] = atoi( buf1)-1; + if( getStringFromIndexWithDelim( data, "|", 2, buf1, sizeof(buf1)) == FALSE ) + return FALSE; + pindex[1] = atoi( buf1)-1; + if( getStringFromIndexWithDelim( data, "|", 3, buf1, sizeof(buf1)) == FALSE ) + return FALSE; + pindex[2] = atoi( buf1)-1; + for( i=0; i<3; i++) { + int petindex; + if( pindex[i] < 0 ) continue; + petindex = CHAR_getCharPet( toindex, pindex[i]); + if( !CHAR_CHECKINDEX( petindex) ) continue; +#ifdef _PET_2TRANS + if( CHAR_getInt( petindex, CHAR_TRANSMIGRATION ) > 1){ + CHAR_talkToCli( toindex, -1, "תﲻںϡ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + if( rideindex == petindex) { + CHAR_talkToCli( toindex, -1, "еij費ںϡ", CHAR_COLORYELLOW); + return FALSE; + } + if( i == 0 ) { + *MainIndex = petindex; + }else if( i == 1) { + *Subindex1 = petindex; + }else if( i == 2) { + *Subindex2 = petindex; + } + } + return TRUE; +} +int NPC_getPetArrayForNo( int PetCode) +{ + int i; + int enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) {//PetCode + if( ENEMY_getInt( i, ENEMY_TEMPNO ) == PetCode ) + break; + } + + if( i == enemynum ){ + print("ANDY 2.err i == enemynum \n"); + return -1; + } + return i; +} +int NPC_getFusionTableForBase( int charaindex, int petindex1, int petindex2 ) +{ + int base1, base2;// ,PETCODE + if( !CHAR_CHECKINDEX( petindex1) ) return -1; + if( !CHAR_CHECKINDEX( petindex2) ) return -1; +#ifdef _PET_EVOLUTION + if( (base2 = EVOLUTION_getPetTable( charaindex, petindex1, petindex2)) < 0 ){ + print("ANDY err base2=%d\n", base2); + return -1; + } + if( (base1 = EVOLUTION_getPropertyTable( charaindex, petindex1, petindex2)) < 0 ){ + print("ANDY err base1=%d\n", base1); + return -1; + } + return EVOLUTION_getFusionTable( charaindex, base2, base1); // get new pet IDNO +#else + return -1; +#endif +} + +BOOL PET_getEvolutionAns( int petindex, int *base) +{ + int i, total1, total2, total; + int defwork = 50, defbase = 145; + int work[4]={0,0,0,0}; + + work[0] = CHAR_getInt( petindex, CHAR_EVOLUTIONBASEVTL); + work[1] = CHAR_getInt( petindex, CHAR_EVOLUTIONBASESTR); + work[2] = CHAR_getInt( petindex, CHAR_EVOLUTIONBASETGH); + work[3] = CHAR_getInt( petindex, CHAR_EVOLUTIONBASEDEX); + for( i=0; i<4; i++) { + work[i] = (work[i]*0.7)/100; + if( work[i]<0 ) work[i] = 0; + if( work[i]>60 ) work[i] = 60; + } + total1 = work[0] + work[1] + work[2] + work[3]; + for( i=0; i<4; i++) { + if( base[i] < 0 ) base[i] = 5; + if( base[i] > 60 ) base[i] = 60; + } + total2 = base[0] + base[1] + base[2] + base[3]; + if( total1 > defwork ) { + for( i=0; i<4; i++) { + work[i] = ((work[i]*defwork)/total1); + if( work[i]<0 ) work[i] = 0; + if( work[i]>60 ) work[i] = 60; + } + } + + total1 = work[0] + work[1] + work[2] + work[3]; + total = (total1/2) + total2; + + if( total > 0 ){ + for( i=0; i<4; i++) { + float fixwork=0.0; + fixwork = (base[i])+(float)(work[i]/2); + base[i] += (int)((fixwork/total) * total1); + if( base[i] < 1 ) base[i] = 1; + if( base[i] > 60 ) base[i] = 60; + } + } + total2 = base[0] + base[1] + base[2] + base[3]; + if( total2 > defbase ){ + for( i=0; i<4; i++) { + base[i] = (base[i]*defbase)/total2; + if( base[i] < 1 ) base[i] = 1; + if( base[i] > 60 ) base[i] = 60; + } + } + total2 = base[0] + base[1] + base[2] + base[3]; + if( base[0]<0 || base[1]<0 || base[2]<0 || base[3]<0 ){ + print("ANDY err EVOLUTION base someone < 0 !!\n"); + } + return TRUE; +} + +int EVOLUTION_createPetFromEnemyIndex( int charaindex, int baseindex, int flg) +{ + Char CharNew; + int newindex; + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i, havepetelement, enemynum, petID; + int level, enemyrank, array; + int petskill[7]={-1,-1,-1,-1,-1,-1,-1}; + int base[4]={0,0,0,0}; + int illegalpetskill[15] = {41,52,600,601,602,603,604,614,617,628,630,631,635,638,641};//Ŵij輼 +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +#define PARAM_CAL( l) (( level -1)*ET_PAR( E_T_LVUPPOINT)+ ET_PAR(E_T_INITNUM)) * ET_PAR( (l)) + havepetelement=-1; + petID = CHAR_getInt( baseindex, CHAR_FUSIONINDEX); + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_TEMPNO ) == petID ){ + break; + } + } + if( i >= enemynum ) return -1; + array = i; + if( !ENEMY_CHECKINDEX( array)) return -1; +//-------------------------------------------------------------------------- + p = ENEMY_enemy[array].intdata; + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)){ + print( "ANDY !tarray\n"); + return -1; + } + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_enemy[tarray].intdata[i]; + } + memset( &CharNew, 0, sizeof( Char ) ); + if( !CHAR_getDefaultChar( &CharNew,31010 ) ){ + print( "ANDY !CHAR_getDefaultChar( &CharNew,31010 )\n"); + return -1; + } + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = *(tp+E_T_IMGNUMBER); + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + level = RAND( (*(p + ENEMY_LV_MIN)), ( *(p+ ENEMY_LV_MAX))); +//------------------------------------------------------ + { + if( PET_getBaseAndSkill( charaindex, baseindex, base, petskill, 1) == FALSE ){ + print( "ANDY err PET_getBaseAndSkill(%d) == FALSE \n", baseindex); + return -1; + } + if( PET_getEvolutionAns( baseindex, base) == FALSE ) return -1; + for( i=0; i < CHAR_MAXPETSKILLHAVE; i ++ ) {//輼 +#ifdef _PET_FUSION_LUA + if(FreeFusionSkill(petskill[i]) == FALSE){ + CharNew.unionTable.indexOfPetskill[i] = petskill[i]; + }else{ + CharNew.unionTable.indexOfPetskill[i] = -1; + } +#else + int j; + for( j=0; j<15; j++) { //Ƿ + if( illegalpetskill[j] == petskill[i] ){ + petskill[i] = -1; + break; + } + } + CharNew.unionTable.indexOfPetskill[i] = petskill[i]; +#endif + } + if( flg == 1 ){ + if( CHAR_DelPetForIndex( charaindex, baseindex) == FALSE ) return FALSE; + } + } + if( flg == 1 ){ + havepetelement = CHAR_getCharPetElement( charaindex);//ҳλ + if( havepetelement < 0 ) return -1; + } +//------------------------------------------------------ + tp[E_T_BASEVITAL] = base[0]; + tp[E_T_BASESTR] = base[1]; + tp[E_T_BASETGH] = base[2]; + tp[E_T_BASEDEX] = base[3]; + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + CharNew.data[CHAR_ALLOCPOINT] + = (base[0] << 24) + + (base[1] << 16) + + (base[2] << 8) + + (base[3] << 0); + + for( i = 0; i < 10; i ++ ){ + int work = RAND( 0, 3 ); + if( work == 0 )tp[E_T_BASEVITAL]++; + if( work == 1 )tp[E_T_BASESTR]++; + if( work == 2 )tp[E_T_BASETGH]++; + if( work == 3 )tp[E_T_BASEDEX]++; + } +//------------------------------------------------------ + CharNew.data[CHAR_VITAL] = PARAM_CAL(E_T_BASEVITAL); + CharNew.data[CHAR_STR] = PARAM_CAL(E_T_BASESTR); + CharNew.data[CHAR_TOUGH] = PARAM_CAL(E_T_BASETGH); + CharNew.data[CHAR_DEX] = PARAM_CAL(E_T_BASEDEX); + CharNew.data[CHAR_FIREAT] = *(tp+ E_T_FIREAT); + CharNew.data[CHAR_WATERAT] = *(tp+ E_T_WATERAT); + CharNew.data[CHAR_EARTHAT] = *(tp+ E_T_EARTHAT); + CharNew.data[CHAR_WINDAT] = *(tp+ E_T_WINDAT); + CharNew.data[CHAR_SLOT] = *(tp+ E_T_SLOT); + CharNew.data[CHAR_MODAI] = *(tp+ E_T_MODAI); + CharNew.data[CHAR_VARIABLEAI] = 0; + CharNew.data[CHAR_LV] = level; + CharNew.data[CHAR_POISON] = *(tp+ E_T_POISON); + CharNew.data[CHAR_PARALYSIS]= *(tp+ E_T_PARALYSIS); + CharNew.data[CHAR_SLEEP] = *(tp+ E_T_SLEEP); + CharNew.data[CHAR_STONE] = *(tp+ E_T_STONE); + CharNew.data[CHAR_DRUNK] = *(tp+ E_T_DRUNK); + CharNew.data[CHAR_CONFUSION]= *(tp+ E_T_CONFUSION); + CharNew.data[CHAR_RARE] = *(tp+ E_T_RARE); + CharNew.data[CHAR_PETID] = *(tp + E_T_TEMPNO); + CharNew.data[CHAR_CRITIAL] = *(tp + E_T_CRITICAL); + CharNew.data[CHAR_COUNTER] = *(tp + E_T_COUNTER); + CharNew.data[CHAR_LIMITLEVEL] = *(tp + E_T_LIMITLEVEL); + CharNew.data[CHAR_FUSIONCODE] = *(tp + E_T_FUSIONCODE); + CharNew.data[CHAR_PETMAILEFFECT] = RAND(0, PETMAIL_EFFECTMAX); +//------------------------------------------------------ + + enemyrank = ENEMY_getRank( array, tarray ); + CharNew.data[CHAR_PETRANK] = enemyrank; +#undef E_PAR +#undef ET_PAR +#undef PARAM_CAL + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + (char *)ENEMYTEMP_enemy[tarray].chardata[E_T_NAME].string ); + newindex = PET_initCharOneArray( &CharNew ); + if( newindex < 0 ){ + print( "ANDY err newindex=%d\n", newindex); + return -1; + } +//------------------------------------------------------ + CHAR_complianceParameter( newindex ); + CHAR_setInt( newindex, CHAR_HP, CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif + CHAR_setInt ( newindex, CHAR_WHICHTYPE , CHAR_TYPEPET); +#ifdef _PET_2TRANS + CHAR_setInt ( newindex, CHAR_TRANSMIGRATION, 2); +#else + CHAR_setInt ( newindex, CHAR_TRANSMIGRATION, 1); +#endif + CHAR_setInt ( newindex, CHAR_FUSIONBEIT, 1); + CHAR_setInt ( newindex, CHAR_FUSIONRAISE, 0); + if( flg == 1 ){ + CHAR_setWorkInt( newindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetelement, newindex); + CHAR_setChar( newindex, CHAR_OWNERCDKEY, CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( newindex, CHAR_OWNERCHARANAME, CHAR_getChar( charaindex, CHAR_NAME)); + { + char msgbuf[256]; + snprintf( msgbuf, sizeof( msgbuf ), "K%d", havepetelement ); + CHAR_sendStatusString( charaindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", havepetelement ); + CHAR_sendStatusString( charaindex, msgbuf ); + } + } + return newindex; +} + +int PET_CheckIncubate( int charaindex) +{ +#ifndef _USER_CHARLOOPS + int i; + static time_t checkeage; + int anhour = PETFEEDTIME; + checkeage = (int)time( NULL); + if( !CHAR_CHECKINDEX( charaindex) )return 0; + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++) { + int time_l=0; + int petindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT) != 1 || + CHAR_getInt( petindex, CHAR_FUSIONRAISE) <= 0 )return;//ǷΪںϳ + + time_l = CHAR_getInt( petindex, CHAR_FUSIONTIMELIMIT); + if( time_l < 0 || time_l > checkeage ){ + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, checkeage); + continue; + } + + if( (int)checkeage > (time_l+(anhour*2)) ){ + char buf[256]; + int levelup, vital, str, tgh, dex; + int raise = CHAR_getInt( petindex, CHAR_FUSIONRAISE); + //ι + raise++; + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time(NULL)+anhour-1); + if( raise < 0 ) raise = 0; + if( raise >= 40 ) raise = 30; + CHAR_setInt( petindex, CHAR_FUSIONRAISE, raise); + levelup = CHAR_getInt( petindex, CHAR_ALLOCPOINT); + vital = ((levelup>>24) & 0xFF) - 5; + str = ((levelup>>16) & 0xFF) - 5; + tgh = ((levelup>> 8) & 0xFF) - 5; + dex = ((levelup>> 0) & 0xFF) - 5; + if( vital < 0 ) vital = 0; + if( str < 0 ) str = 0; + if( tgh < 0 ) tgh = 0; + if( dex < 0 ) dex = 0; + // + levelup = (vital<<24) + (str<<16) + (tgh<<8) + (dex<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, levelup); + sprintf( buf, "%sƷʱˡ", CHAR_getUseName( petindex )); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + + LogPetFeed( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( petindex, CHAR_NAME), + petindex, + CHAR_getInt( petindex, CHAR_LV), + "Ʒʱ", // Key + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + CHAR_getChar( petindex, CHAR_UNIQUECODE) ); + + }else if( (int)checkeage > (time_l+anhour) ){ + + char buf[256]; + sprintf( buf, "%sֿιʳ״̬", CHAR_getUseName( petindex )); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + } + } + return 1; +#else + int masterindex, time_l=0; + static time_t checkeage; + int anhour = PETFEEDTIME, i; + + if( !CHAR_CHECKINDEX( charaindex) )return 0; + masterindex = CHAR_getWorkInt( charaindex, CHAR_WORKPLAYERINDEX); + if( !CHAR_CHECKINDEX( masterindex) )return 0; + + if( CHAR_getInt( charaindex, CHAR_FUSIONBEIT) != 1 || + CHAR_getInt( charaindex, CHAR_FUSIONRAISE) <= 0 ) return 0;//ǷΪںϳ + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++) { + if( charaindex != CHAR_getCharPet( masterindex, i) ) continue; + break; + } + if( i >= CHAR_MAXPETHAVE ) return 0; + checkeage = (int)time( NULL); + + time_l = CHAR_getInt( charaindex, CHAR_FUSIONTIMELIMIT); + if( time_l < 0 || time_l > checkeage ){ + CHAR_setInt( charaindex, CHAR_FUSIONTIMELIMIT, checkeage); + return 0; + } + if( (int)checkeage > (time_l+(anhour*2.5)) ){ + char buf[256]; + int levelup, vital, str, tgh, dex; + int raise = CHAR_getInt( charaindex, CHAR_FUSIONRAISE); + raise++; + CHAR_setInt( charaindex, CHAR_FUSIONTIMELIMIT, (int)time(NULL)+anhour-1); + if( raise < 0 ) raise = 0; + if( raise >= 40 ) raise = 30; + CHAR_setInt( charaindex, CHAR_FUSIONRAISE, raise); + levelup = CHAR_getInt( charaindex, CHAR_ALLOCPOINT); + vital = ((levelup>>24) & 0xFF) - 6; + str = ((levelup>>16) & 0xFF) - 6; + tgh = ((levelup>> 8) & 0xFF) - 6; + dex = ((levelup>> 0) & 0xFF) - 6; + if( vital < 0 ) vital = 0; + if( str < 0 ) str = 0; + if( tgh < 0 ) tgh = 0; + if( dex < 0 ) dex = 0; + // + levelup = (vital<<24) + (str<<16) + (tgh<<8) + (dex<<0); + CHAR_setInt( charaindex, CHAR_ALLOCPOINT, levelup); + sprintf( buf, "%sƷʱˡ", CHAR_getUseName( charaindex )); + CHAR_talkToCli( masterindex, -1, buf, CHAR_COLORYELLOW); + + LogPetFeed( + CHAR_getChar( masterindex, CHAR_NAME), + CHAR_getChar( masterindex, CHAR_CDKEY), + CHAR_getChar( charaindex, CHAR_NAME), + charaindex, + CHAR_getInt( charaindex, CHAR_LV), + "Ʒʱ", // Key + CHAR_getInt( masterindex, CHAR_FLOOR), + CHAR_getInt( masterindex, CHAR_X), + CHAR_getInt( masterindex, CHAR_Y), + CHAR_getChar( charaindex, CHAR_UNIQUECODE) ); + + }else if( (int)checkeage > (time_l+anhour) ){ + char buf[256]; + sprintf( buf, "%sֿιʳ״̬", CHAR_getUseName( charaindex )); + CHAR_talkToCli( masterindex, -1, buf, CHAR_COLORYELLOW); + } + return 1; +#endif +} +#endif + +#ifdef _NPC_FUSION +int PETFUSION_SetNewEgg( int toindex , int petindex, int array, int *work, int *skill1, int *skill2) +{ + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + int level, workrank, petrank=0; + int LevelUpPoint; + struct { + int num; + float rank; + }ranktbl[] = { + { 130, 2.5}, + { 100, 2.0}, + { 95, 1.5}, + { 85, 1.0}, + { 80, 0.5}, + { 0, 0.0}, + }; + if( !ENEMY_CHECKINDEX( array)) + return -1; + p = ENEMY_getIntdata( array); + if( p == NULL ) { + print("\n p = NULL" ); + return -1; + } + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)) + return -1; + //print( "ANDY tarray/array=%d/%d-->%s \n", tarray, array, + // ENEMYTEMP_getChar( tarray, E_T_NAME)); + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_getInt( tarray, i); + } + level = 1; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +#define PARAM_CAL( l) ( ( level -1) * ET_PAR( E_T_LVUPPOINT) + ET_PAR( E_T_INITNUM) ) + work[0] += ( RAND(0,4) - 2 ); + work[1] += ( RAND(0,4) - 2 ); + work[2] += ( RAND(0,4) - 2 ); + work[3] += ( RAND(0,4) - 2 ); + +#ifdef _BT_PET + tp[E_T_BASEVITAL]*= getBtPet(); + tp[E_T_BASESTR]*= getBtPet(); + tp[E_T_BASETGH]*= getBtPet(); + tp[E_T_BASEDEX]*= getBtPet(); +#endif + + LevelUpPoint + = (work[0] << 24) + + (work[1] << 16) + + (work[2] << 8) + + (work[3] << 0); + + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + workrank = work[0]+work[1]+work[2]+work[3]; + for( i = 0; i < arraysizeof( ranktbl); i ++ ) { + if( workrank >= ranktbl[i].num ) { + petrank = i; + break; + } + } + if( i>= arraysizeof( ranktbl)) i = arraysizeof( ranktbl); + CHAR_setInt( petindex, CHAR_PETRANK, petrank); + for( i = 0; i < 10; i ++ ){ + int rnt = RAND( 0, 3 ); + if( rnt == 0 ) work[0]++; + if( rnt == 1 ) work[1]++; + if( rnt == 2 ) work[2]++; + if( rnt == 3 ) work[3]++; + } + + CHAR_setInt( petindex, CHAR_VITAL, ( PARAM_CAL(E_T_BASEVITAL) * work[0] )); + CHAR_setInt( petindex, CHAR_STR , ( PARAM_CAL(E_T_BASESTR) * work[1] )); + CHAR_setInt( petindex, CHAR_TOUGH , ( PARAM_CAL(E_T_BASETGH) * work[2] )); + CHAR_setInt( petindex, CHAR_DEX , ( PARAM_CAL(E_T_BASEDEX) * work[3] )); + CHAR_setMaxExp( petindex, 0); + CHAR_setInt( petindex, CHAR_LV, level); + + //\Ϊ߼ + CHAR_setInt( petindex, CHAR_SLOT, 7); + { + int j; + int illegalpetskill[15] = {41,52,600,601,602,603,604,614,617,628,630,631,635,638,641}; + for( i=0; i0){ + skill1[i] = -1; + break; + } +#endif + } + } + for( i=0; icharfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "PET_CheckIncubateLoop"); + ch->data[CHAR_LOOPINTERVAL] = 60000; + CHAR_constructFunctable( petindex); + } +#endif + if( CHAR_CHECKINDEX( toindex) ){ + for(i = 0; i < CHAR_MAXPETHAVE; i++){ + char msgbuf[256]; + int pindex = CHAR_getCharPet(toindex, i); + if( !CHAR_CHECKINDEX( pindex) ) + continue; + memset( msgbuf, 0, sizeof( msgbuf)); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( toindex, msgbuf ); + + CHAR_send_K_StatusString(toindex, i,CHAR_K_STRING_HP|CHAR_K_STRING_AI); + } + } + return petindex; +} + +BOOL PETFUSION_AddEgg( int toindex, int petID, int PetCode) +{ + int ret; + char msgbuf[64]; + int enemynum; + int i,j; + int petindex, petindex2; + + //Ƿпλ + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( toindex, i); + if( petindex == -1 ) + break; + } + if( i == CHAR_MAXPETHAVE ) { + snprintf( msgbuf,sizeof( msgbuf), ""); + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORYELLOW); + return -1; + } + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) {//PetCode + if( ENEMY_getInt( i, ENEMY_ID ) == petID ) + //if( ENEMY_getInt( i, ENEMY_TEMPNO ) == PetCode ) + break; + } + if( i == enemynum ){ + print("ANDY err i == enemynum \n"); + return -1; + } + ret = ENEMY_createPetFromEnemyIndex( toindex, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( toindex, i ) == ret ) + break; + } + if( i == CHAR_MAXPETHAVE ) + i = 0; + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + } + petindex2 = CHAR_getCharPet( toindex, i); + if( !CHAR_CHECKINDEX( petindex2) ){ + print("ANDY petindex2=%d\n", petindex2); + return -1; + } + CHAR_setInt( petindex2, CHAR_FUSIONINDEX, PetCode); + snprintf( msgbuf,sizeof( msgbuf), "õ%s", CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORYELLOW); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(toindex, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + } + LogPet( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex2, CHAR_NAME), + CHAR_getInt( petindex2, CHAR_LV), + "TenseiGet", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( petindex2, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + return petindex2; +} +#endif + +#ifdef _PET_TRANS +int GetNewPet( int toindex , int petindex, int array, int *work) +{ + int *p; + int tp[E_T_DATAINTNUM]; + int tarray, i; + int level, workrank, petrank=0; + int LevelUpPoint; + + struct { + int num; + float rank; + }ranktbl[] = { + { 130, 2.5}, + { 100, 2.0}, + { 95, 1.5}, + { 85, 1.0}, + { 80, 0.5}, + { 0, 0.0}, + }; + + if( !ENEMY_CHECKINDEX( array)) + return -1; + p = ENEMY_getIntdata( array); + if( p == NULL ) { + print("\n p = NULL" ); + return -1; + } + tarray = ENEMYTEMP_getEnemyTempArray( array); + if( !ENEMYTEMP_CHECKINDEX( tarray)) + return -1; + for( i = 0; i < E_T_DATAINTNUM; i ++ ){ + tp[i] = ENEMYTEMP_getInt( tarray, i); + } + level = 1; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +#define E_PAR( a) (*(p + (a))) +#define ET_PAR( a) (*(tp + (a))) +#define PARAM_CAL( l) ( ( level -1) * ET_PAR( E_T_LVUPPOINT) + ET_PAR( E_T_INITNUM) ) +#ifdef _CTRL_TRANS_DEVELOP + if(getCtrlTrans()== 1){ + work[0] += FreeCtrlTransDevelop(petindex, 0) - 2; + work[1] += FreeCtrlTransDevelop(petindex, 1) - 2; + work[2] += FreeCtrlTransDevelop(petindex, 2) - 2; + work[3] += FreeCtrlTransDevelop(petindex, 3) - 2; + }else{ + work[0] += ( RAND(0,4) - 2 ); + work[1] += ( RAND(0,4) - 2 ); + work[2] += ( RAND(0,4) - 2 ); + work[3] += ( RAND(0,4) - 2 ); + } +#else + work[0] += ( RAND(0,4) - 2 ); + work[1] += ( RAND(0,4) - 2 ); + work[2] += ( RAND(0,4) - 2 ); + work[3] += ( RAND(0,4) - 2 ); +#endif + + LevelUpPoint + = (work[0] << 24) + + (work[1] << 16) + + (work[2] << 8) + + (work[3] << 0); + + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + workrank = work[0]+work[1]+work[2]+work[3]; + for( i = 0; i < arraysizeof( ranktbl); i ++ ) { + if( workrank >= ranktbl[i].num ) { + petrank = i; + break; + } + } + + if( i>= arraysizeof( ranktbl)) i = arraysizeof( ranktbl); + CHAR_setInt( petindex, CHAR_PETRANK, petrank); + + for( i = 0; i < 10; i ++ ){ + int rnt = RAND( 0, 3 ); + if( rnt == 0 ) work[0]++; + if( rnt == 1 ) work[1]++; + if( rnt == 2 ) work[2]++; + if( rnt == 3 ) work[3]++; + } + + CHAR_setInt( petindex, CHAR_VITAL, ( PARAM_CAL(E_T_BASEVITAL) * work[0] )); + CHAR_setInt( petindex, CHAR_STR , ( PARAM_CAL(E_T_BASESTR) * work[1] )); + CHAR_setInt( petindex, CHAR_TOUGH , ( PARAM_CAL(E_T_BASETGH) * work[2] )); + CHAR_setInt( petindex, CHAR_DEX , ( PARAM_CAL(E_T_BASEDEX) * work[3] )); + CHAR_setMaxExp( petindex, 0); + CHAR_setInt( petindex, CHAR_LV, level); + //\Ϊ߼ + CHAR_setInt( petindex, CHAR_SLOT, 7); +/* + for( i=0; i + +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "readmap.h" +#include "map_warppoint.h" +#include "event.h" +#include "npc_warp.h" +#include "npc_npcenemy.h" + + +static int EVENT_onWarpNPC( int charaindex,int echaraindex,int fl,int x, int y ); +static int EVENY_npcEncount( int charaindex,int echaraindex,int fl,int x, int y ); + + +typedef int (*FUNC)( int charaindex,int echaraindex,int fl,int x, int y ); +static FUNC functbl[] = { + NULL, + NULL, /* NPC */ + EVENY_npcEncount, /* óľ޼ */ + EVENT_onWarpNPC, /* warp*/ + NULL, /* NPC */ + NULL, /* NPC */ + EVENT_onWarpNPC, /* warp*/ + EVENT_onWarpNPC, /* warp*/ + EVENT_onWarpNPC, /* warp*/ +}; + +INLINE BOOL EVENT_CHECKEVENTINDEX( int event) +{ + if( event < 0 || event >= CHAR_EVENTNUM) return FALSE; + return TRUE; +} + +int EVENT_main( int charaindex,int event, int x, int y) +{ + OBJECT object; + BOOL found = FALSE; + int rc = FALSE; + int fl = CHAR_getInt( charaindex, CHAR_FLOOR); + if( !EVENT_CHECKEVENTINDEX( event)) return FALSE; + + for( object = MAP_getTopObj(fl,x,y) ; object ; object = NEXT_OBJECT(object) ){ + int o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_CHARA ){ + int etype; + int echaraindex=OBJECT_getIndex(o); + if( !CHAR_CHECKINDEX(echaraindex) )continue; + if( CHAR_getInt( echaraindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) continue; + etype = CHAR_getWorkInt( echaraindex, CHAR_WORKEVENTTYPE); + if( etype != CHAR_EVENT_NONE ) { + if( etype == event) { + if( functbl[event] != NULL ) { + rc = functbl[event]( charaindex, echaraindex, fl,x,y); + } + found = TRUE; + break; + } + } + } +#ifdef _MAP_WARPPOINT + else if( OBJECT_getType(o) == OBJTYPE_WARPPOINT){ + if( !MAPPOINT_CHECKINDEX( OBJECT_getIndex( o)) ) continue; + if( OBJECT_getchartype( o) != event ) continue; + MAPPOINT_MapWarpHandle( charaindex, OBJECT_getIndex( o), fl, x, y ); + found = TRUE; + rc = TRUE; + break; + } +#endif + } +/* + if( !found ) { + print( "not found eventobject : cind [%d] event [%d] fl[%d] x[%d] y[%d]\n", charaindex, event, fl,x,y); + } +*/ + return rc; +} + +static int EVENT_onWarpNPC( int charaindex,int echaraindex,int fl,int x, int y ) +{ + NPC_WarpWarpCharacter( echaraindex, charaindex); + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) { + int i; + for( i = 1; i < getPartyNum(charaindex ); i ++ ) { + int index = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index) ) { + NPC_WarpWarpCharacter( echaraindex, index); + } + } + } + + return TRUE; +} +static int EVENY_npcEncount( int charaindex,int echaraindex,int fl,int x, int y ) +{ + return NPC_NPCEnemy_Encount( echaraindex, charaindex, 0); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/family.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/family.c new file mode 100644 index 0000000..0fb6620 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/family.c @@ -0,0 +1,3198 @@ +#include "version.h" +#include +#include +#include +#include +#include "configfile.h" +#include "readmap.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npcutil.h" +#include "family.h" +#include "log.h" +#include "handletime.h" +#include "buf.h" +#include "net.h" +#include "char_base.h" +#include "battle.h" +#include "npc_bus.h" +#include "char_talk.h" +#include "npc_scheduleman.h" +#ifdef _FM_MODIFY +#include "npc_fmdengon.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif + +#ifdef _SASQL +#include "longzoro/sasql.h" +#endif + + +#define CHAR_MAXNAME 32 +#define CHAR_MAXID 20 +#define MINFMLEVLEFORPOINT 3 // 3 ׯ԰͵ȼ +#ifdef _FAMILY_MANORNUM_CHANGE +#else +#define MANORNUM 4 +#endif + + +int familyNumTotal = 0; +char familyListBuf[MAXFAMILYLIST]; + +int channelMember[FAMILY_MAXNUM][FAMILY_MAXCHANNEL][FAMILY_MAXMEMBER]; +int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + +int familyTax[FAMILY_MAXNUM]; + +extern tagRidePetTable ridePetTable[296]; + +void LeaveMemberIndex( int charaindex, int fmindexi); + + +// Arminius: ȡü pk dp /ʧֵ +// getFMdpAward +// arg: windp=winner's fmdp losedp=loser's fmdp +// ret: dp award +// +#ifdef _MERGE_NEW_8 +int fmdplevelexp[]={0, // 0 + 150000, // 1 + 500000, // 2 + 1000000, // 3 + 1500000, // 4 + 2000000, // 5 + 2500000, // 6 + 3500000, // 7 + 4500000, // 8 + 5000000, // 9 + 7000000 //10 + }; +#else +#ifdef _REDUCE_MERGE_FAME +int fmdplevelexp[]={0, // 0 + 1000, // 1 + 3000, // 2 + 10000, // 3 + 50000, // 4 + 150000, // 5 + 500000, // 6 + 1000000, // 7 + 2000000, // 8 + 10000000, // 9 + 20000000 //10 + }; +#else +int fmdplevelexp[]={0, // 0 + 10000, // 1 + 30000, // 2 + 100000, // 3 + 500000, // 4 + 1500000, // 5 + 5000000, // 6 + 15000000, // 7 + 50000000, // 8 + 200000000, // 9 + 500000000 //10 + }; +#endif +#endif +// Arminius end + +// shan begin +int getFmLv(int playerindex) // ϳʱר +{ + int i, dp; + dp = CHAR_getWorkInt(playerindex, CHAR_WORKFMDP); + if( dp > fmdplevelexp[10] ){ +// print("\n player DP->%d",dp); + return 10; + } + for(i=0; i<=10; i++) + if( dp <= fmdplevelexp[i+1] ) break; + // Nuke 20040217: Open the merge limit + //if(i>=9) i = 8; + if (i>=10) i=10; + + return i; +} + +struct FMMEMBER_LIST memberlist[FAMILY_MAXNUM]; +struct FMS_MEMO fmsmemo; +struct FM_POINTLIST fmpointlist; +#ifdef _NEW_MANOR_LAW +ManorSchedule_t ManorSchedule[MANORNUM]; +#endif +struct FMS_DPTOP fmdptop; +struct FM_PKFLOOR fmpkflnum[FAMILY_FMPKFLOOR]= +{ + {142}, + {143}, + {144}, + {145}, + {146}, + {1042}, + {2032}, + {3032}, + {4032}, +#ifdef _FAMILY_MANORNUM_CHANGE // CoolFish ޸װ԰ + {5032}, + {6032}, + {7032}, + {8032}, + {9032}, + {10032}, +#endif +}; +int leaderdengonindex = 0; +// shan end ͼ赽 family.h FAMILY_FMPKFLOOR + +void SetFMPetVarInit(int meindex) +{ + int i = 0, petindex = 0; +#ifdef _FMVER21 + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) +#else + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1) +#endif + { + for (i = 0; i < CHAR_MAXPETHAVE; i++) + { + petindex = CHAR_getCharPet(meindex, i); + if (!CHAR_CHECKINDEX(petindex)) continue; + CHAR_setInt(petindex, CHAR_PETFAMILY, -1); + } + } +} + +void SetFMVarInit(int meindex) +{ + SetFMPetVarInit(meindex); // ػ Flag + CHAR_setInt(meindex, CHAR_FMINDEX, -1); + CHAR_setChar(meindex, CHAR_FMNAME, ""); + CHAR_setInt(meindex, CHAR_FMSPRITE, -1); +#ifdef _FMVER21 + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, FMMEMBER_NONE); +#else + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, -1); +#endif + CHAR_setWorkInt(meindex, CHAR_WORKFMSETUPFLAG, -1); + CHAR_setWorkInt(meindex, CHAR_WORKFMINDEXI, -1); + CHAR_setWorkInt(meindex, CHAR_WORKFMCHARINDEX, -1); +} + +void FAMILY_Init( void ) +{ + int i, j ,k; + + for( i=0; i 0) return -1; + if (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") != 0) return -1; +#ifdef _FMVER21 + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER) return -1; +#else + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == 1) return -1; +#endif + return 1; +} + +int CheckFMMember(int meindex) +{ + if (CHAR_getInt(meindex, CHAR_FMINDEX) > 0) return -1; + if (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") != 0) return -1; +#ifdef _FMVER21 + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) > 0 && + CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_APPLY ) return -1; +#else + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) > 0 ) return -1; +#endif + return 1; +} + +int CheckLeaderQ(int meindex) +{ + if (CHAR_getInt(meindex, CHAR_LV) < FMLEADERLV + && CHAR_getInt(meindex, CHAR_TRANSMIGRATION) <= 0) + return -1; + if (!NPC_EventCheckFlg(meindex, 4)) + return -2; + return 0; +} + +void FAMILY_Add(int fd, int meindex, char* message) +{ + char token[128], fmname[128], charname[128], charid[128]; + char petname[128], fmrule[256], petattr[256], buf[1024]; + int charlv, havepetindex, petindex, fmsprite = 0, chargrano; + int gold, tmpflag; +#ifdef _FAMILYBADGE_ + int fmbadge = -1; +#endif + if (!CHAR_CHECKINDEX(meindex)) return; + + if (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return; + if (CHAR_getInt(meindex, CHAR_FMINDEX) >= 0 + && strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") != 0) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nѾޡ޷ٳ壡", buf, sizeof(buf))); + return; + } + tmpflag = CheckLeaderQ(meindex); + if(tmpflag == -1) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nܱǸรĵȼ㣡", buf, sizeof(buf))); + return; + } + + if(tmpflag == -2) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nܱǸรɳУ", buf, sizeof(buf))); + return; + } + + gold = CHAR_getInt(meindex, CHAR_GOLD); + if( gold < 1000 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nܱǸรҪ1000ʯҵѣ", buf, sizeof(buf))); + return; + } + else { + CHAR_setInt( meindex, CHAR_GOLD, gold-1000 ); + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_GOLD); + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + sprintf(fmname, "%s", token); + if ((strstr(fmname, " ")) || (strcmp(fmname, "") == 0) || (strstr(fmname, ""))) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nո", buf, sizeof(buf))); + return; + } + if (getStringFromIndexWithDelim(message, "|", 3, token, + sizeof(token)) == FALSE) return; + havepetindex = atoi(token); + petindex = CHAR_getCharPet(meindex, havepetindex); + if (!CHAR_CHECKINDEX(petindex)) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nѡһֻΪػޣ", buf, sizeof(buf))); + return; + } + if (getStringFromIndexWithDelim(message, "|", 4, token, + sizeof(token)) == FALSE) return; + fmsprite = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 5, token, + sizeof(token)) == FALSE) return; + if (strcmp(token, "") == 0) + sprintf(fmrule, ""); + else + sprintf(fmrule, "%s", token); + +#ifdef _FAMILYBADGE_ + if (getStringFromIndexWithDelim(message, "|", 6, token, + sizeof(token)) == FALSE) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nô", buf, sizeof(buf))); + return; + } + fmbadge = atoi(token); + extern int FamilyBadgeData[]; + extern int FamilyBadgeDataNum; + if(fmbadge <0 || fmbadge>FamilyBadgeDataNum){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nô", buf, sizeof(buf))); + return; + } + fmbadge = FamilyBadgeData[fmbadge]; +#endif + + sprintf(charname, "%s", CHAR_getChar(meindex, CHAR_NAME)); + sprintf(charid, "%s", CHAR_getChar(meindex, CHAR_CDKEY)); + charlv = CHAR_getInt(meindex, CHAR_LV); + chargrano = CHAR_getInt(meindex, CHAR_FACEIMAGENUMBER); + if (strlen(CHAR_getChar(petindex, CHAR_USERPETNAME)) == 0) + sprintf(petname, "%s", CHAR_getChar(petindex, CHAR_NAME)); + else + sprintf(petname, "%s", CHAR_getChar(petindex, CHAR_USERPETNAME)); + sprintf(petattr, "%d %d %d %d", + CHAR_getInt(petindex, CHAR_BASEIMAGENUMBER), + CHAR_getWorkInt(petindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt(petindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt(petindex, CHAR_WORKQUICK)); + CHAR_setInt(petindex, CHAR_PETFAMILY, 1); + CHAR_setChar(meindex, CHAR_FMNAME, fmname); +#ifdef _FMVER21 + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, FMMEMBER_LEADER); +#else + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, 1); +#endif + CHAR_setInt(meindex, CHAR_FMSPRITE, fmsprite); + + // print("%s %s %s %d %s %s %s %d %d\n", fmname, charname, charid, charlv, petname, + // petattr, fmrule, fmsprite, chargrano); +#ifdef _PERSONAL_FAME + saacproto_ACAddFM_send(acfd, fmname, charname, charid, charlv, + petname, petattr, fmrule, fmsprite, chargrano, + CHAR_getInt(meindex, CHAR_FAME), +#ifdef _FAMILYBADGE_ + fmbadge, +#endif + CONNECT_getFdid(fd)); + // print("ACAddFM acfd:%d meindex:%d fmname:%s charname:%s fame:%d Connectfd:%d fd:%d\n", + // acfd, meindex, fmname, charname, CHAR_getInt(meindex, CHAR_FAME), CONNECT_getFdid(fd), fd); +#else + saacproto_ACAddFM_send(acfd, fmname, charname, charid, charlv, + petname, petattr, fmrule, fmsprite, chargrano, CONNECT_getFdid(fd)); +#endif + + // Ҫ¼б + //saacproto_ACShowFMList_send( acfd ); + +} + +/* + qr +qr +r +qةȡ~~r +辶 +tЩs ~~~~~~~~~ + + +*/ + +void ACAddFM(int fd, int result, int fmindex, int index) +{ + int meindex = CONNECT_getCharaindex(fd); + char buf[1024]; + +// print("ACAddFM result:%d fmindex:%d meindex:%d\n", result, fmindex, meindex); // test + + if (!CHAR_CHECKINDEX(meindex)) return; + +// print("ACAddFM_2!\n"); + + if (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return; + +// print("ACAddFM_3!\n"); + + if(result == 1) + { + CHAR_setInt(meindex, CHAR_FMINDEX, fmindex); + CHAR_setWorkInt(meindex, CHAR_WORKFMINDEXI, index); + CHAR_setWorkInt(meindex, CHAR_WORKFMSETUPFLAG, 0); +#ifdef _NEW_MANOR_LAW + CHAR_setInt(meindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(meindex,-1,"ƹ",CHAR_COLORYELLOW); +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nϲµļ壡ڣ֮ټ˼룬Ȼȡʸม", buf, sizeof(buf))); + JoinMemberIndex( meindex, index); + CHAR_charSaveFromConnect(meindex, FALSE); + + // Ҫ¼ + saacproto_ACShowFMList_send( acfd ); + saacproto_ACShowMemberList_send( acfd, index ); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_INTEGRATE); +#ifdef _NEW_MANOR_LAW + saacproto_ACShowTopFMList_send(acfd, FM_TOP_MOMENTUM); +#endif + LogFamily( + CHAR_getChar( meindex, CHAR_FMNAME), + CHAR_getInt( meindex, CHAR_FMINDEX), + CHAR_getChar( meindex, CHAR_NAME), + CHAR_getChar( meindex, CHAR_CDKEY), + "ADDFAMILY()", + "" + ); + } + else + { + int i = 0, petindex = 0; + char tmpbuf[256]; + int gold = CHAR_getInt(meindex, CHAR_GOLD); + CHAR_setInt(meindex, CHAR_GOLD, gold + 10000000); + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_GOLD); + SetFMVarInit(meindex); + + for (i = 0; i < CHAR_MAXPETHAVE; i++) + { + petindex = CHAR_getCharPet(meindex, i); + if (!CHAR_CHECKINDEX(petindex)) continue; + CHAR_setInt(petindex, CHAR_PETFAMILY, -1); + } + if (fmindex == -2) + sprintf(tmpbuf, "\nѾֵͬļˣ"); + else + sprintf(tmpbuf, "\nʧܣ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString(tmpbuf, buf, sizeof(buf))); + } + CHAR_sendStatusString( meindex, "F"); +} + +void FAMILY_Join(int fd, int meindex, char *message) +{ + int fmindex, charlv, index, fmsprite; + char token[128], fmname[128], charname[128], charid[128], buf[1024]; + + if (!CHAR_CHECKINDEX(meindex)) return; + + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + + if (CheckFMMember(meindex) < 0){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nѾร", buf, sizeof(buf))); + return; + } + +#ifdef _FM_JOINLIMIT + if( CHAR_getInt( meindex, CHAR_FMTIMELIMIT ) > (int)time(NULL) ){ + char buff[255]; + sprintf(buff, "\n֮ǰ˳壬\n%dСʱټร",(CHAR_getInt( meindex, CHAR_FMTIMELIMIT )-(int)time(NULL))/3600+1); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( buff, buf, sizeof(buf))); + return; + } +#endif + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + index = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 3, token, + sizeof(token)) == FALSE) return; + fmindex = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 4, token, + sizeof(token)) == FALSE) return; + sprintf(fmname, "%s", token); + if (getStringFromIndexWithDelim(message, "|", 5, token, + sizeof(token)) == FALSE) return; + fmsprite = atoi(token); + + if(memberlist[index].fmnum > FAMILY_MAXMEMBER){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n˼Ŀǰ޷ճԱԱѵޣ", buf, sizeof(buf))); + return; + } + + sprintf(charname, "%s", CHAR_getChar(meindex, CHAR_NAME)); + sprintf(charid, "%s", CHAR_getChar(meindex, CHAR_CDKEY)); + charlv = CHAR_getInt(meindex, CHAR_LV); + CHAR_setInt(meindex, CHAR_FMINDEX, fmindex); + CHAR_setChar(meindex, CHAR_FMNAME, fmname); +#ifdef _FMVER21 + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, FMMEMBER_APPLY); +#else + CHAR_setInt(meindex, CHAR_FMLEADERFLAG, 0); +#endif + CHAR_setInt(meindex, CHAR_FMSPRITE, fmsprite); + CHAR_setWorkInt(meindex, CHAR_WORKFMINDEXI, index); + +// print("JoinFM index:%d fmindex:%d fmname:%s charname:%s charid:%s charlv:%d sprite:%d\n", +// index, fmindex, fmname, charname, charid, charlv, fmsprite); +#ifdef _PERSONAL_FAME // Arminius: +// print("fame:%d charfdid:%d\n", CHAR_getInt(meindex, CHAR_FAME), +// CONNECT_getFdid(fd)); + saacproto_ACJoinFM_send(acfd, fmname, fmindex, charname, charid, charlv, + index, CHAR_getInt(meindex, CHAR_FAME), CONNECT_getFdid(fd)); +#else +// print("charfdid:%d\n", CONNECT_getFdid(fd)); + saacproto_ACJoinFM_send(acfd, fmname, fmindex, charname, charid, charlv, + index, CONNECT_getFdid(fd)); +#endif +} + +void ACJoinFM(int fd, int result, int recv) +{ + int meindex = CONNECT_getCharaindex(fd); + char buf[1024]; + + if(!CHAR_CHECKINDEX(meindex)) return; + + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + + if (result == 1) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nллļ룡ȵ峤֮ͨᣬʽ롣", buf, sizeof(buf))); + + JoinMemberIndex( meindex, CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI) ); +#ifdef _NEW_MANOR_LAW + CHAR_setInt(meindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(meindex,-1,"ƹ",CHAR_COLORYELLOW); +#endif + + sprintf(buf,"fame:%d",CHAR_getInt(meindex,CHAR_FAME)); + + LogFamily( + CHAR_getChar( meindex, CHAR_FMNAME), + CHAR_getInt( meindex, CHAR_FMINDEX), + CHAR_getChar( meindex, CHAR_NAME), + CHAR_getChar( meindex, CHAR_CDKEY), + "JOINFAMILY()", + buf + ); + + } + else + { + SetFMVarInit(meindex); + if (recv == -2) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n˼ĿǰԸճԱ", buf, sizeof(buf))); + } + else if (recv == -3) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n˼Ŀǰ޷ճԱԱѵޣ", buf, sizeof(buf))); + } + else + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nʧܣ", buf, sizeof(buf))); + } + + CHAR_sendStatusString( meindex, "F"); +} + +void FAMILY_Leave(int fd, int meindex, char *message) +{ + int result, fmindex, index; + char token[128], fmname[128], charname[128], charid[128], buf[1024]; + + if (!CHAR_CHECKINDEX(meindex)) return; + + if (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return; + + if ((CHAR_getInt(meindex, CHAR_FMINDEX) == -1) + || (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") == 0) +#ifdef _FMVER21 + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == FMMEMBER_NONE)) +#else + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == -1)) +#endif + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n㲢ûмร", buf, sizeof(buf))); + return; + } + + { + int i, fmpks_pos; + for( i=1; i<=MANORNUM; i++){ // CoolFish 4->MANORNUM 2002/2/25 + fmpks_pos = i * MAX_SCHEDULE; + if(fmpks[fmpks_pos+1].host_index > -1 && fmpks[fmpks_pos+1].guest_index > -1){ +#ifdef _FMVER21 + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER){ +#else + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == 1){ +#endif + if( (fmpks[fmpks_pos+1].host_index+1) == CHAR_getInt(meindex, CHAR_FMINDEX) || + (fmpks[fmpks_pos+1].guest_index+1) == CHAR_getInt(meindex, CHAR_FMINDEX) ){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nĿǰļԼսУ޷ɢ壡", buf, sizeof(buf))); + return; + } + } + } + } + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + result = atoi(token); + if (result == 1) + { + fmindex = CHAR_getInt(meindex, CHAR_FMINDEX); + index = CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI); + sprintf(fmname, "%s", CHAR_getChar(meindex, CHAR_FMNAME)); + sprintf(charname, "%s", CHAR_getChar(meindex, CHAR_NAME)); + sprintf(charid, "%s", CHAR_getChar(meindex, CHAR_CDKEY)); +#ifdef _FMVER21 + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER) +#else + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) == 1) +#endif + { +// print("DelFM index:%d fmindex:%d fmname:%s\n", index, fmindex, fmname); + saacproto_ACDelFM_send(acfd, fmname, fmindex, index, charname, charid,CONNECT_getFdid(fd)); + + // Ҫ¼б + //saacproto_ACShowFMList_send( acfd ); + }else { +// print("LeaveFM index:%d fmindex:%d fmname:%s charname:%s charid:%s\n", +// index, fmindex, fmname, charname, charid); + saacproto_ACLeaveFM_send(acfd, fmname, fmindex, charname, charid, index, CONNECT_getFdid(fd)); + } + } +} + +void ACLeaveFM( int fd, int result, int resultflag) +{ + int meindex = CONNECT_getCharaindex(fd); + char buf[1024]; + + if (!CHAR_CHECKINDEX(meindex)) return; + if (result == 1){ + // won 2002/01/05 + LogFamily( + CHAR_getChar( meindex, CHAR_FMNAME), + CHAR_getInt( meindex, CHAR_FMINDEX), + CHAR_getChar( meindex, CHAR_NAME), + CHAR_getChar( meindex, CHAR_CDKEY), + "LEAVEFAMILY(뿪)", + "" + ); + if( CHAR_getWorkInt( meindex, CHAR_WORKFMCHANNEL) != -1 ) + CHAR_setWorkInt( meindex, CHAR_WORKFMCHANNEL, -1 ); + LeaveMemberIndex( meindex, CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI) ); + SetFMVarInit(meindex); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n˳ϣˣ", buf, sizeof(buf))); + CHAR_setWorkInt( meindex, CHAR_WORKFMFLOOR, -1); +#ifdef _FM_JOINLIMIT + CHAR_setInt( meindex, CHAR_FMTIMELIMIT, (int)time(NULL)+getJoinFamilyTime()*(60*60) ); +#endif +#ifdef _NEW_MANOR_LAW + CHAR_setInt(meindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(meindex,-1,"˳ƹ",CHAR_COLORYELLOW); +#endif + CHAR_setInt( meindex , CHAR_RIDEPET, -1 ); + CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , CHAR_getInt( meindex , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( meindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_RIDEPET); +#ifdef _FM_METAMO + CHAR_ReMetamo(meindex); +#endif + }else + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n˳ʧܣ", buf, sizeof(buf))); + + CHAR_sendStatusString( meindex, "F" ); +} + +void ACDelFM(int fd, int result) +{ + char buf[1024]; + int meindex = CONNECT_getCharaindex(fd); + if (!CHAR_CHECKINDEX(meindex)) return; + + //if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + // || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + // return; + + if (result == 1) + { +// WON ADD + LogFamily( + CHAR_getChar( meindex, CHAR_FMNAME), + CHAR_getInt( meindex, CHAR_FMINDEX), + CHAR_getChar( meindex, CHAR_NAME), + CHAR_getChar( meindex, CHAR_CDKEY), + "DELFAMILY(ɢ)", + "" + ); + + LeaveMemberIndex( meindex, CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI) ); + /* + for( i=0; i FAMILY_MAXMEMBER)break; + if(getStringFromIndexWithDelim(data," ",j,tmpbuf,sizeof(tmpbuf)) == FALSE) + return; + strcpy(memberlist[index].numberlistarray[j-1],tmpbuf); + getStringFromIndexWithDelim(tmpbuf,"|",1,numberid,sizeof(numberid)); + memberlist[index].memberindex[j-1] = atoi(numberid); + } + memberlist[index].fmnum = fmnum; + memberlist[index].fmjoinnum = fmjoinnum; + memberlist[index].accept = fmacceptflag; +#ifdef _FAMILYBADGE_ + memberlist[index].badge = badge; +#endif + return; + } +} + +void ACShowDpTop(int result,int num, char *data, int kindflag) +{ + int i; + char tmpbuf[256],tmpbuf1[64]; + if(result==0){ + return; + }else{ + switch( kindflag ) + { + case FM_TOP_INTEGRATE: + { + for(i=0; i familyNumTotal ) break; + if( getStringFromIndexWithDelim( familyListBuf, "|", i, subbuf, + sizeof(subbuf) ) == FALSE) break; + strcat( buf, "|" ); + strcat( buf, subbuf ); + j++; + + // print(" |%s| ", subbuf); + } + + sprintf( sendbuf, "S|F|%d|%d|%d%s", familyNumTotal, atoi(token2), j, buf ); + lssproto_FM_send( fd, sendbuf ); + + return; + + } + + // shan add + if (strcmp(token, "P") == 0 ){ +#ifdef _DATA_INFO_SHOW + FreeDataInfoShow(meindex); +#else + int personfame; + char sendbuf[512]; +#ifdef _PERSONAL_FAME + personfame = (CHAR_getInt( meindex, CHAR_FAME)/100); +#else + personfame = CHAR_getWorkInt( meindex, CHAR_WORKFMDP); +#endif + sprintf( sendbuf, "ĿǰĸΪ%d", personfame); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); +#ifdef _NEW_MANOR_LAW + sprintf(sendbuf,"ĿǰĸƵΪ%d",CHAR_getInt(meindex,CHAR_MOMENTUM)/100); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORCYAN); +#endif +#ifndef _VERSION_NEW +#ifdef _VIP_SERVER + sprintf( sendbuf, "Ŀǰĸ˻ֵΪ%d",CHAR_getInt(meindex,CHAR_AMPOINT)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); +#endif +#endif +#ifdef _ONLINE_SHOP + sprintf(sendbuf,"Ŀǰĸ˱ҵΪ%d",CHAR_getInt(meindex, CHAR_BJ)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORGRAY); +#endif +#ifdef _BOUND_TIME + time_t boundtime = CHAR_getInt(meindex, CHAR_BOUNDTIME); + if(CHAR_getInt(meindex, CHAR_BOUNDTIME)==0){ + CHAR_talkToCli(meindex, -1, "ĿǰȨδã", CHAR_COLORYELLOW); + }else if(CHAR_getInt(meindex, CHAR_BOUNDTIME) > time(NULL)){ + struct tm *tm1 = localtime(&boundtime); + sprintf( sendbuf, "ĿǰȨΪ%4d%2d%2d %2d:%2d:%2d\n", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday, + tm1->tm_hour, + tm1->tm_min, + tm1->tm_sec); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); + }else{ + CHAR_talkToCli(meindex, -1, "ĿǰȨѹڣ", CHAR_COLORYELLOW); + } +#endif +#ifdef _VIP_RIDE + + if(CHAR_getInt(meindex, CHAR_VIPTIME)==-1){ + CHAR_talkToCli(meindex, -1, "ĿǰĻԱȨã", CHAR_COLORYELLOW); + }else if(CHAR_getInt(meindex, CHAR_VIPTIME)==0){ + CHAR_talkToCli(meindex, -1, "ĿǰĻԱȨδã", CHAR_COLORYELLOW); + }else if(CHAR_getInt(meindex, CHAR_VIPTIME) > time(NULL)){ + time_t viptime = (time_t)CHAR_getInt(meindex, CHAR_VIPTIME); + struct tm *tm1 = localtime(&viptime); + + sprintf( sendbuf, "ĿǰĻԱȨЧڣ%4d%2d%2d %2d:%2d:%2d\n", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday, + tm1->tm_hour, + tm1->tm_min, + tm1->tm_sec); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORPURPLE); + }else{ + CHAR_talkToCli(meindex, -1, "ĿǰĻԱȨѹڣ", CHAR_COLORYELLOW); + } +#endif + +#ifdef _CAMEO_MONEY + sprintf(sendbuf,"Ŀǰĸ˱ĿΪ%d", CHAR_getInt(meindex,CHAR_CAMEO)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); +#endif + +#ifdef _MISSION_TRAIN +{ + int num = CHAR_getInt(meindex, CHAR_MISSIONTRAIN_NUM) - 1; + if(num < 0){ + CHAR_talkToCli(meindex, -1, "Ŀǰδ", CHAR_COLORYELLOW); + }else{ + sprintf(sendbuf,"Ŀǰ%d", num); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); + } +} +#endif + +#ifdef _PLAYER_TITLE + char titletoken[256]; + if ( CHAR_getInt( meindex, CHAR_TITLE_LV) > 0 ){ + if(CHAR_getInt(meindex, CHAR_TITLE_TIME) > time(NULL)){ + time_t titletime = (time_t)CHAR_getInt(meindex, CHAR_TITLE_TIME); + struct tm *tm1 = localtime(&titletime); + + sprintf( sendbuf, "ĿǰӢ۳ƺЧڣ%4d%2d%2d %2d:%2d:%2d\n", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday, + tm1->tm_hour, + tm1->tm_min, + tm1->tm_sec); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORBLUE); + } + } +#endif +#ifdef _MISSION_TIME + if(CHAR_getInt(meindex, CHAR_MISSION_TIME) > time(NULL)){ + sprintf( sendbuf, "Ŀǰʱʣࣺ%d", (CHAR_getInt(meindex, CHAR_MISSION_TIME) - time(NULL)) / 60); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORGREEN); + } +#endif +#ifdef _ACTIVE_GAME + sprintf(sendbuf,"Ŀǰĸ˻ĿΪ%d", CHAR_getInt(meindex,CHAR_ACTIVE)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORCYAN); +#endif +{ + int addexptime = CHAR_getWorkInt( meindex, CHAR_WORKITEM_ADDEXPTIME ); + int lefttime = addexptime; + if(lefttime>0){ + sprintf(sendbuf, "ĿǰľЧΪ %d\% ʣʱ %d %d ", CHAR_getWorkInt( meindex, CHAR_WORKITEM_ADDEXP ), lefttime/60, lefttime%60 ); + CHAR_talkToCli( meindex, -1, sendbuf, CHAR_COLORYELLOW); + } +} +#ifdef _SASQL + sprintf(sendbuf,"Ŀǰĸ˽Ϊ%d",sasql_getVipPoint(meindex)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); +#else +#ifdef _NEW_VIP_SHOP +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( meindex, -1, "δ!", CHAR_COLORRED ); + }else{ + CHAR_talkToCli(meindex, -1, "ȡУԺ...", CHAR_COLORRED); + saacproto_QueryPoint_send( osfd, fd, CHAR_getChar(meindex, CHAR_CDKEY)); + } +#else + CHAR_talkToCli(meindex, -1, "ȡУԺ...", CHAR_COLORRED); + saacproto_QueryPoint_send( acfd, fd, CHAR_getChar(meindex, CHAR_CDKEY)); +#endif +#endif +#endif +#ifdef _OFFLINE_TIME + sprintf(sendbuf,"ĿǰĿʱӣ%d", CHAR_getInt(meindex,CHAR_OFFLINE_TIME)); + CHAR_talkToCli(meindex, -1, sendbuf, CHAR_COLORYELLOW); +#endif +#endif + } + + if(strcmp(token,"D") == 0){ + if(getStringFromIndexWithDelim(message, "|", 3, fmname, sizeof(fmname)) == FALSE) return; + if(getStringFromIndexWithDelim(message, "|", 4, token2, sizeof(token2)) == FALSE) return; + fmindex = atoi( token2 ); + if(getStringFromIndexWithDelim(message, "|", 5, token2, sizeof(token2)) == FALSE) return; + tempindex = atoi( token2 ); + + //print(" send_fmname_ac:%s ", fmname); + saacproto_ACFMDetail_send( acfd, fmname, fmindex, tempindex, CONNECT_getFdid(fd) ); + } + + // shan begin + else if (strcmp(token, "D2") ==0 ) { + char sendbuf[2048], tmpbuf[1024], leadernamebuf[64]; + int h, i = 0; + int meindex = CONNECT_getCharaindex(fd); + int fmindex_wk = CHAR_getWorkInt( meindex, CHAR_WORKFMINDEXI); + if( fmindex_wk < 0 || fmindex_wk >= FAMILY_MAXNUM) return; + + for( h=0; htm_mon + 1, tm1->tm_mday, tm1->tm_hour, tm1->tm_min, + fmpks[fmpks_pos + 2].host_name, + fmpks[fmpks_pos + 1].guest_name, + fmpks[fmpks_pos + 1].host_name); + } + } + } + if (strcmp(tmpbuf, "") == 0) + sprintf(tmpbuf, "սų"); + + getStringFromIndexWithDelim(memberlist[fmindex_wk].numberlistarray[0], + "|",2,leadernamebuf,sizeof(leadernamebuf)); + // sendbuf -> ||峤||||ְλ|徫|PK +#ifdef _VERSION_NEW + sprintf( sendbuf, "%s|%d|%s|%d|%d|%d|%d|%d|%s|%d|%d", +#else +#ifdef _NEW_MANOR_LAW + sprintf( sendbuf, "%s|%d|%s|%d|%d|%d|%d|%d|%s|%d|%d", +#else + sprintf( sendbuf, "%s|%d|%s|%d|%d|%d|%d|%d|%s", +#endif +#endif + CHAR_getChar(meindex, CHAR_FMNAME), + memberlist[fmindex_wk].fmjoinnum, + leadernamebuf, + h+1, +#ifdef _FMVER21 + fmdptop.fmtopdp[h], +#else + (CHAR_getWorkInt( meindex, CHAR_WORKFMDP)/100), +#endif +#ifdef _PERSONAL_FAME + (CHAR_getInt( meindex, CHAR_FAME)/100), +#else + (CHAR_getWorkInt( meindex, CHAR_WORKFMDP)/100), +#endif + CHAR_getInt( meindex, CHAR_FMLEADERFLAG), + CHAR_getInt( meindex, CHAR_FMSPRITE ), + tmpbuf + +#ifdef _NEW_MANOR_LAW + ,fmdptop.fmMomentum[h]/100 // + ,CHAR_getInt(meindex,CHAR_MOMENTUM)/100 // +#endif + ); +#ifdef _FAMILYBADGE_ + sprintf(sendbuf+strlen(sendbuf),"|%d",memberlist[fmindex_wk].badge); +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_FAMILYDETAIL, + WINDOW_BUTTONTYPE_OK, + -1, + -1, + makeEscapeString( sendbuf, buf, sizeof(buf))); + } + // shan end +} + +void ACFMDetail(int ret, char *data, int clifd) +{ + char sendbuf[1024]; + + //print(" Detail:%s ", data); + + if( ret != 1 ) + { + print(" ACFMDetailError!:%d ", clifd ); + return; + } + //print(" ACFMDetail:%d:%s ", clifd, data ); + + /* + len = strlen(data); + strcpy( buf, data ); + + for( i=0 ; i :%s (ΪԱ):%d\n", CHAR_getInt(meindex, CHAR_FMLEADERFLAG), charname, charindex); + LogFamily( + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getChar(meindex, CHAR_NAME), + CHAR_getChar(meindex, CHAR_CDKEY), + "CheckMember", + sbuf + ); + // shan end + + saacproto_ACMemberJoinFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), result, + CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + } +#else + { + saacproto_ACMemberJoinFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), result, + CONNECT_getFdid(fd)); + } +#endif +#ifdef _FMVER21 + else if (result == FMMEMBER_NONE) +#else + else if (result == 4) +#endif + { + for (i = 0 + 1; i < FAMILY_MAXHOME + 1; i++) + { + int fmpks_pos = i * MAX_SCHEDULE; + if ((fmpks[fmpks_pos].host_index == index + && strcmp(fmname, fmpks[fmpks_pos].host_name) == 0) + || (fmpks[fmpks_pos].guest_index == index + && strcmp(fmname, fmpks[fmpks_pos].guest_name) == 0)) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nĿǰսУ޷˳Ա", buf, sizeof(buf))); +// print("fmpks_pos:%d index:%d host:%d guest:%d\n", fmpks_pos, +// index, fmpks[fmpks_pos].host_index, fmpks[fmpks_pos].guest_index); + return; + } + } +#ifdef _FMVER21 + { + // shan begin + char sbuf[1024]; + sprintf( sbuf, "峤:%d -> :%s :%d (˳)\n", CHAR_getInt(meindex, CHAR_FMLEADERFLAG), charname, charindex); + LogFamily( + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getChar(meindex, CHAR_NAME), + CHAR_getChar(meindex, CHAR_CDKEY), + "CheckMember", + sbuf + ); + // shan end + saacproto_ACMemberLeaveFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), + CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + } +#else + { + saacproto_ACMemberLeaveFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), + CONNECT_getFdid(fd)); + } +#endif + } +#ifdef _FMVER21 +// else if (result == FMMEMBER_ELDER || result == FMMEMBER_INVITE +// || result == FMMEMBER_BAILEE || result == FMMEMBER_VICELEADER ) + else if (result == FMMEMBER_ELDER ) + { + if (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) + return; +#ifdef _FMVER21 + { + // shan begin + char sbuf[1024]; + sprintf( sbuf, "峤:%d -> :%s :%d (Ϊ)\n", CHAR_getInt(meindex, CHAR_FMLEADERFLAG), charname, charindex); + LogFamily( + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getChar(meindex, CHAR_NAME), + CHAR_getChar(meindex, CHAR_CDKEY), + "CheckMember", + sbuf + ); + // shan end + saacproto_ACMemberJoinFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), result, + CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + } +#else + { + saacproto_ACMemberJoinFM_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), charname, charindex, + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), result, + CONNECT_getFdid(fd)); + } +#endif + } +#endif + // Ҫ¼б + saacproto_ACShowFMList_send( acfd ); +} + +void FAMILY_Channel(int fd, int meindex, char *message) +{ + char token[128], token2[128]; + char buf[4096], subbuf[4096], sendbuf[4096]; + int i, tempindex, fmindexi, channel, nowchannel, num; + + fmindexi = CHAR_getWorkInt( meindex, CHAR_WORKFMINDEXI); + nowchannel = CHAR_getWorkInt( meindex, CHAR_WORKFMCHANNEL ); + + // print(" channelFM:%d ", fmindexi); + if( fmindexi < 0 ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n㻹ûмκμ壡", buf, sizeof(buf))); + return; + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + + if (getStringFromIndexWithDelim(message, "|", 3, token2, + sizeof(token2)) == FALSE) return; + + channel = atoi( token2 ); + + if( strcmp( token, "J") == 0) { + if( channel < -1 || channel > FAMILY_MAXCHANNEL )return; + if( nowchannel >= 0 && nowchannel < FAMILY_MAXCHANNEL ) { + i = 0; + while( i < FAMILY_MAXMEMBER ) { + if( channelMember[fmindexi][nowchannel][i] == meindex ) { + channelMember[fmindexi][nowchannel][i] = -1; + break; + } + i++; + } + } + + if( channel > 0 && channel < FAMILY_MAXCHANNEL ) { + i = 0; + while( i < FAMILY_MAXCHANNELMEMBER ) { + if( channelMember[fmindexi][channel][i] < 0 ) { + channelMember[fmindexi][channel][i] = meindex; + break; + } + i++; + } + if( i >= FAMILY_MAXCHANNELMEMBER ) { + CHAR_talkToCli( meindex, -1, "Ƶ", CHAR_COLORWHITE); + return; + } + sprintf( buf, "Ƶ [%d]", channel ); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + + if( nowchannel >=0 && nowchannel < FAMILY_MAXCHANNEL ) { + sprintf( buf, "%s ˳Ƶ", CHAR_getChar( meindex, CHAR_NAME) ); + for( i=0; i < FAMILY_MAXCHANNELMEMBER; i++ ) { + if( CHAR_CHECKINDEX(channelMember[fmindexi][nowchannel][i]) + && channelMember[fmindexi][nowchannel][i] != meindex ) { + CHAR_talkToCli( channelMember[fmindexi][nowchannel][i], -1, buf, CHAR_COLORWHITE); + } + } + } + sprintf( buf, "%s Ƶ", CHAR_getChar( meindex, CHAR_NAME) ); + for( i=0; i < FAMILY_MAXCHANNELMEMBER; i++ ) { + if( CHAR_CHECKINDEX(channelMember[fmindexi][channel][i]) + && channelMember[fmindexi][channel][i] != meindex ) { + CHAR_talkToCli( channelMember[fmindexi][channel][i], -1, buf, CHAR_COLORWHITE); + } + } + + } + else if( channel == 0 ) { + i = 0; + while( i < FAMILY_MAXMEMBER ) { + if( channelMember[fmindexi][0][i] < 0 ) { + channelMember[fmindexi][0][i] = meindex; + break; + } + i++; + } + if( i >= FAMILY_MAXMEMBER ) { +#ifndef _CHANNEL_MODIFY + CHAR_talkToCli( meindex, -1, "Ƶ", CHAR_COLORWHITE); +#endif + return; + } +#ifndef _CHANNEL_MODIFY + sprintf( buf, "Ƶ [ȫ]"); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + if( nowchannel >=0 && nowchannel < FAMILY_MAXCHANNEL ) { + sprintf( buf, "%s ˳Ƶ", CHAR_getChar( meindex, CHAR_NAME) ); + for( i=0; i < FAMILY_MAXCHANNELMEMBER; i++ ) { + if( CHAR_CHECKINDEX(channelMember[fmindexi][nowchannel][i]) + && channelMember[fmindexi][nowchannel][i] != meindex ) { + CHAR_talkToCli( channelMember[fmindexi][nowchannel][i], -1, buf, CHAR_COLORWHITE); + } + } + } + sprintf( buf, "%s Ƶ", CHAR_getChar( meindex, CHAR_NAME) ); + for( i=0; i < FAMILY_MAXCHANNELMEMBER; i++ ) { + if( CHAR_CHECKINDEX(channelMember[fmindexi][channel][i]) + && channelMember[fmindexi][channel][i] != meindex ) { + CHAR_talkToCli( channelMember[fmindexi][channel][i], -1, buf, CHAR_COLORWHITE); + } + } +#endif + } +#ifdef _FMVER21 + else if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER ) +#else + else if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) == 1 ) +#endif + { + CHAR_talkToCli( meindex, -1, "峤㲥", CHAR_COLORWHITE); + } + else { + channel = -1; +#ifndef _CHANNEL_MODIFY + CHAR_talkToCli( meindex, -1, "˳Ƶ", CHAR_COLORWHITE); +#else + CHAR_talkToCli( meindex, -1, "ر峤㲥", CHAR_COLORWHITE); + channel = 0; + i = 0; + while(i < FAMILY_MAXMEMBER){ + if( channelMember[fmindexi][0][i] < 0 ) { + channelMember[fmindexi][0][i] = meindex; + break; + } + i++; + } +#endif + + sprintf( buf, "%s ˳Ƶ", CHAR_getChar( meindex, CHAR_NAME) ); + for( i=0; i < FAMILY_MAXCHANNELMEMBER; i++ ) { + if( CHAR_CHECKINDEX(channelMember[fmindexi][nowchannel][i]) + && channelMember[fmindexi][nowchannel][i] != meindex ) { + CHAR_talkToCli( channelMember[fmindexi][nowchannel][i], -1, buf, CHAR_COLORWHITE); + } + } + } + + CHAR_setWorkInt( meindex, CHAR_WORKFMCHANNEL, channel); + if( channel != -1 ) CHAR_setWorkInt( meindex, CHAR_WORKFMCHANNELQUICK, channel); + + sprintf( sendbuf, "C|J|%d", channel); + lssproto_FM_send( fd, sendbuf); + + } + else if( strcmp( token, "L") == 0) { + + int j, membernum, bFind = 0; + if( channel < 0 || channel >= FAMILY_MAXCHANNEL ) return; + + subbuf[0] = '\0'; + num = 0; + if( channel != 0 ) + membernum = FAMILY_MAXCHANNELMEMBER; + else + membernum = FAMILY_MAXMEMBER; + + for( j = 0 ; j < FAMILY_MAXMEMBER ; j++ ) { + bFind = 0; + tempindex = familyMemberIndex[fmindexi][j]; + //if( tempindex >= 0 ) { + if( CHAR_CHECKINDEX(tempindex) ) { + for( i=0; i< membernum ; i++) { + if( tempindex == channelMember[fmindexi][channel][i] ) { + //if( CHAR_getChar( tempindex, CHAR_NAME ) == NULL ) { + // familyMemberIndex[fmindexi][j] = -1; + // channelMember[fmindexi][channel][i] = -1; + // continue; + //} + bFind = 1; + break; + } + } + if( bFind ) + strcat( subbuf, "|1|" ); + else + strcat( subbuf, "|0|" ); + makeEscapeString( CHAR_getChar( tempindex, CHAR_NAME ), buf, sizeof(buf)); + strcat( subbuf, buf ); + num++; + } + } + sprintf( sendbuf, "C|L|%d|%d%s", channel, num, subbuf); + lssproto_FM_send( fd, sendbuf); + //print(" CList:%s ", sendbuf); + } +} + +void FAMILY_Bank(int fd, int meindex, char *message) +{ + char token[128], token2[128], buf[1024]; + int fmindex, cash, bank, toBank; + int MaxGold; + MaxGold = CHAR_getMaxHaveGold( meindex); + fmindex = CHAR_getInt( meindex, CHAR_FMINDEX); + // add shan + if( fmindex <= 0 && CHAR_getInt( meindex, CHAR_BANKGOLD) < 1) { + CHAR_talkToCli( meindex, -1, "ȼ塣", CHAR_COLORWHITE); + return; + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, sizeof(token)) == FALSE) + return; + + if( strcmp(token, "G" )==0 ) { + if (getStringFromIndexWithDelim(message, "|", 3, token2, sizeof(token)) == FALSE) + return; + + toBank = atoi( token2 ); + cash = CHAR_getInt( meindex, CHAR_GOLD); + bank = CHAR_getInt( meindex, CHAR_BANKGOLD); + if( ((cash - toBank) >= 0) && ((cash - toBank) <= MaxGold ) + && ((((bank + toBank) >= 0) && ((bank + toBank) <= CHAR_MAXBANKGOLDHAVE)) + || toBank < 0) ) { + // shan add + if( toBank > 0 && CHAR_getInt( meindex, CHAR_FMINDEX ) < 1 ) { + sprintf(buf, "Ǹûмκμ壬Խȡ"); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + return; + } + if( bank + toBank <0) { + sprintf(buf, "Ǹļиʻûô"); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + return; + } + CHAR_setInt( meindex, CHAR_GOLD, cash - toBank); + CHAR_setInt( meindex, CHAR_BANKGOLD, bank + toBank); + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_GOLD); + + if( toBank >= 0 ) { + sprintf(buf, "%dиʻ", toBank); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + // Syu ADD дȡLog () + LogFamilyBankStone( + CHAR_getChar( meindex, CHAR_NAME ), + CHAR_getChar( meindex, CHAR_CDKEY ), + toBank, + CHAR_getInt( meindex, CHAR_GOLD ), + "myBank()()", + CHAR_getInt( meindex,CHAR_FLOOR), + CHAR_getInt( meindex,CHAR_X ), + CHAR_getInt( meindex,CHAR_Y ), + CHAR_getInt( meindex,CHAR_BANKGOLD) + ); + + } + else { + sprintf(buf, "Ӽиʻȡ%d", -toBank); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORWHITE); + // Syu ADD дȡLog () + LogFamilyBankStone( + CHAR_getChar( meindex, CHAR_NAME ), + CHAR_getChar( meindex, CHAR_CDKEY ), + toBank, + CHAR_getInt( meindex, CHAR_GOLD ), + "myBank()()", + CHAR_getInt( meindex,CHAR_FLOOR), + CHAR_getInt( meindex,CHAR_X ), + CHAR_getInt( meindex,CHAR_Y ), + CHAR_getInt( meindex,CHAR_BANKGOLD) + ); + + } + // Syu ADD дȡLog () + LogStone( + -1, + CHAR_getChar( meindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( meindex, CHAR_CDKEY ), /* ǡID */ + -toBank, /* ź */ + CHAR_getInt( meindex, CHAR_GOLD ), + "myBank()", + CHAR_getInt( meindex,CHAR_FLOOR), + CHAR_getInt( meindex,CHAR_X ), + CHAR_getInt( meindex,CHAR_Y ) + ); + + } +/* + else + print(" bank_error "); +*/ + } + if( strcmp(token, "I" )==0 ) { + + } + if( strcmp(token, "T" )==0 ) { + int toTax; + int mygold; + int FMindex; + + if (getStringFromIndexWithDelim(message, "|", 3, token2, sizeof(token)) == FALSE) + return; + toTax = atoi( token2 ); + +#ifdef _FMVER21 + if( CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) != FMMEMBER_LEADER && + CHAR_getInt( meindex, CHAR_FMLEADERFLAG ) != FMMEMBER_ELDER && toTax < 0 ) + return; +#endif + + + FMindex = CHAR_getWorkInt( meindex, CHAR_WORKFMINDEXI ); + mygold = CHAR_getInt( meindex, CHAR_GOLD); + if( mygold < 0 || mygold > MaxGold || toTax == 0 ) return; + if( toTax > 0 ) {//+ + if( ((mygold-toTax) < 0) || (familyTax[ FMindex] + toTax) > CHAR_MAXFMBANKGOLDHAVE ) { + return; + } + }else if( toTax < 0 ){ //-ȡ + if( ((mygold-toTax)>MaxGold) || (familyTax[ FMindex] + toTax) < 0 ) { + return; + } + } + + + if( toTax>0 ) { //Ԥȿۿ + CHAR_setInt( meindex, CHAR_GOLD, CHAR_getInt( meindex, CHAR_GOLD)-toTax ); + } + sprintf( buf, "%s....", (toTax>0)?"":"ȡ"); + CHAR_talkToCli( meindex , -1, buf, CHAR_COLORYELLOW); + + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_GOLD); + sprintf( buf, "%d", toTax ); + + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_FMGOLD, buf, + "", CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), CONNECT_getFdid(fd)); + //print(" getTax:%s=%d ", CHAR_getChar(meindex, CHAR_FMNAME), toTax ); + } +} + +void ACFMPointList(int ret, char *data) +{ +} + +void FAMILY_SetPoint(int fd, int meindex, char *message) +{ + int i, fmpointindex, fl, x, y, fmdp, fmlevel = 0; + char token[128], buf[1024]; + + if (!CHAR_CHECKINDEX(meindex)) return; + + if (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return; + + if ((CHAR_getInt(meindex, CHAR_FMINDEX) == -1) + || (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") == 0) +#ifdef _FMVER21 + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER)) +#else + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1)) +#endif + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n㲻峤û޸ĵȨࡣ", buf, sizeof(buf))); + return; + } + fmdp = CHAR_getWorkInt(meindex, CHAR_WORKFMDP); +#ifdef _FM_POINT_APPLY_FAME + if(fmdp < 100000){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,-1, -1, + makeEscapeString( "\n1000޷ׯ԰", buf, sizeof(buf))); + return; + } +#endif + for (i = 1; i <= MANORNUM; i++) { + if (((strcmp(fmpks[i * MAX_SCHEDULE + 1].guest_name, + CHAR_getChar(meindex, CHAR_FMNAME)) == 0)) + && ((fmpks[i * MAX_SCHEDULE + 1].flag = FMPKS_FLAG_MANOR_BATTLEBEGIN) + || (fmpks[i * MAX_SCHEDULE + 1].flag == FMPKS_FLAG_MANOR_PREPARE))){ + char tmpbuf[256]; + sprintf(tmpbuf, "\n%sѾԤԼׯ԰ˡ\n޷ׯ԰ร", + fmpks[i * MAX_SCHEDULE + 1].host_name); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString(tmpbuf, buf, sizeof(buf))); + return; + } + } + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + fmpointindex = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 3, token, + sizeof(token)) == FALSE) return; + fl = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 4, token, + sizeof(token)) == FALSE) return; + x = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 5, token, + sizeof(token)) == FALSE) return; + y = atoi(token); +/* + print("SetFMPoint charname:%s fmindex:%d index:%d pointindex:%d fl:%d x:%d y:%d\n", + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), + fmpointindex, fl, x, y); +*/ + saacproto_ACSetFMPoint_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), + fmpointindex, fl, x, y, CONNECT_getFdid(fd)); +} + +void ACSetFMPoint(int ret, int r, int clifd) +{ + int meindex = CONNECT_getCharaindex(clifd); + char message[256], buf[512]; + + if (!CHAR_CHECKINDEX(meindex)) return; + + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + if (ret == 0){ + if (r == -1) + sprintf(message, "ʧܣ"); + else if (r == -2) + sprintf(message, "Ѿмݵˡظ룡"); + else if (r == -3) + sprintf(message, "δݵʸ"); + else if (r == -4) + sprintf(message, "ݵѾмʹޣ"); + else if (r == -5) + sprintf(message, "ļδ׼ࡣ"); + else if (r == -6) + sprintf(message, "ʧׯ԰ʮӺӴ"); + } + else if (ret == 1) + sprintf(message, "ݵϣˣ"); + + lssproto_WN_send( clifd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString(message, buf, sizeof(buf))); +} + +void ACFMAnnounce(int ret, char *fmname, int fmindex, int index, + int kindflag, char *data, int color) +{ + // kindflag 1:峤㲥 2:ϵͳ屻ɾ 3:ϵͳ֪ͨѶϢ + int i, chindex; + if( ret != 1 ) return; +// print("fmname:%s fmindex:%d index:%d kindflag:%d data:%s color:%d\n", +// fmname, fmindex, index, kindflag, data, color); + for( i=0; i < FAMILY_MAXMEMBER; i++) + { + chindex = familyMemberIndex[index][i]; + if( chindex >= 0 ) { + if( CHAR_getCharUse(chindex) ) + { + if (kindflag == 1) + { +#ifdef _FMVER21 + // shan 2001/12/13 + //if( CHAR_getInt( chindex, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER ) + if( CHAR_getInt( chindex, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER || + CHAR_getInt( chindex, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER ) +#else + if( CHAR_getInt( chindex, CHAR_FMLEADERFLAG ) == 2 ) +#endif + CHAR_talkToCli( chindex, -1, data, color ); + } + else if (kindflag == 2) + { + int fd = getfdFromCharaIndex( chindex ); + if (fd == -1) return; + SetFMVarInit( chindex ); + CHAR_talkToCli( chindex , -1, "ļ֮ûյԱԱȽɢˣ", + CHAR_COLORRED); + } + }else + familyMemberIndex[index][i] = -1; + } + } + if (kindflag == 3) + { + int meindex = 0; + int clifd = getfdFromFdid(color); + if (CONNECT_checkfd(clifd) == FALSE) return; + meindex = CONNECT_getCharaindex(clifd); + if (!CHAR_CHECKINDEX(meindex)) return; + CHAR_talkToCli(meindex, -1, data, CHAR_COLORRED); + if(strstr(data,"Ѿļ룡")!=NULL){ + + }else if(strstr(data,"Ѿ߳ˣ")!=NULL){ + CHAR_setInt( meindex , CHAR_RIDEPET, -1 ); + CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , CHAR_getInt( meindex , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( meindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( meindex , CHAR_P_STRING_RIDEPET); +#ifdef _FM_METAMO + CHAR_ReMetamo(meindex); +#endif + } + } + if (kindflag == 4) + { + int meindex = 0; + char buf[1024]; + int clifd = getfdFromFdid(color); +// print("Here1\n"); + if (CONNECT_checkfd(clifd) == FALSE) return; + meindex = CONNECT_getCharaindex(clifd); + if (!CHAR_CHECKINDEX(meindex)) return; +// print("Here2\n"); + lssproto_WN_send(clifd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString(data, buf, sizeof(buf))); + } +} + +void FAMILY_SetAcceptFlag(int fd, int meindex, char *message) +{ + int result; + char token[128], buf[1024]; + + if (!CHAR_CHECKINDEX(meindex)) return; + + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + + if ((CHAR_getInt(meindex, CHAR_FMINDEX) == -1) + || (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") == 0) +#ifdef _FMVER21 +// || ((CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) +// && (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_ELDER) +// && (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_VICELEADER))) + || ((CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) + && (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_ELDER))) +#else + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1)) +#endif + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n㲻峤û޸ĵȨࡣ", buf, sizeof(buf))); + return; + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + result = atoi(token); + if ((result == 0) || (result == 1)) + { + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_ACCEPTFLAG, + token, "", CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + } +} + +void FAMILY_FixRule( int fd, int meindex, char* message ) +{ + char token[1024], buf[1024]; + + if (!CHAR_CHECKINDEX(meindex))return; + + if ((CHAR_getInt(meindex, CHAR_FMINDEX) == -1) + || (strcmp(CHAR_getChar(meindex, CHAR_FMNAME), "") == 0) +#ifdef _FMVER21 + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER)) +#else + || (CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1)) +#endif + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\n㲻峤û޸ĵȨࡣ", buf, sizeof(buf))); + return; + } + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return; + + if( strcmp( token, "R") == 0 ) + { + if (getStringFromIndexWithDelim(message, "|", 3, buf, + sizeof( buf ) ) == FALSE)return; + + if (strcmp( buf, "") == 0) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nּΪհࡣ", buf, sizeof(buf))); + return; + } + +// print(" new_rule:%s ", buf); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_FMRULE, + buf, "", CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + return; + } + + +#ifdef _FAMILYBADGE_ + if( strcmp( token, "B") == 0 ) + { + if (getStringFromIndexWithDelim(message, "|", 3, buf, + sizeof(buf)) == FALSE) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nô", buf, sizeof(buf))); + return; + } + int badgeindex = atoi( buf ); + extern int FamilyBadgeData[]; + extern int FamilyBadgeDataNum; + extern int FamilyBadgePrice; + if(badgeindex <0 || badgeindex>FamilyBadgeDataNum){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nô", buf, sizeof(buf))); + return; + } + int vippoint = sasql_getVipPoint(meindex); + if(vippoint < FamilyBadgePrice){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nĽҲ㣡", buf, sizeof(buf))); + return; + } + sasql_setVipPoint(meindex,vippoint - FamilyBadgePrice); + char token[256]; + sprintf(token, "ϵͳ۳%d",FamilyBadgePrice); + CHAR_talkToCli( meindex, -1, token, CHAR_COLORYELLOW); + badgeindex = FamilyBadgeData[badgeindex]; + sprintf(buf,"%d",badgeindex); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_BADGE, + buf, "", CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + saacproto_ACShowMemberList_send( acfd, CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI)); + return; + } +#endif + if( strcmp( token, "P") == 0 ) + { + int havepetindex, petindex, i; + char petname[20], petattr[512]; + + // Ƿػ + for( i =0; i< CHAR_MAXPETHAVE; i++ ) + { + int petindex = CHAR_getCharPet(meindex, i); + if (!CHAR_CHECKINDEX(petindex)) continue; + if( CHAR_getInt( petindex , CHAR_PETFAMILY ) ==1 ) + { +// lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, +// WINDOW_BUTTONTYPE_OK, +// -1, -1, +// makeEscapeString( "\nԭػ޻ࡡ", buf, sizeof(buf))); +// return; + CHAR_setInt( petindex , CHAR_PETFAMILY,0 ); + } + } + // Ƿػ(ij) + for( i =0; i< CHAR_MAXPOOLPETHAVE; i++ ) + { + int petindex = CHAR_getCharPoolPet(meindex, i); + if (!CHAR_CHECKINDEX(petindex)) continue; + if( CHAR_getInt( petindex , CHAR_PETFAMILY ) ==1 ) + { +// lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, +// WINDOW_BUTTONTYPE_OK, +// -1, -1, +// makeEscapeString( "\nԭػ޻ࡡ", buf, sizeof(buf))); +// return; + CHAR_setInt( petindex , CHAR_PETFAMILY,0 ); + } + } + + if (getStringFromIndexWithDelim(message, "|", 3, buf, + sizeof( buf ) ) == FALSE) return; + havepetindex = atoi( buf ); + + petindex = CHAR_getCharPet(meindex, havepetindex); + + if (!CHAR_CHECKINDEX(petindex)) return; + + if (strlen(CHAR_getChar(petindex, CHAR_USERPETNAME)) == 0) + sprintf(petname, "%s", CHAR_getChar(petindex, CHAR_NAME)); + else + sprintf(petname, "%s", CHAR_getChar(petindex, CHAR_USERPETNAME)); + sprintf(petattr, "%d %d %d %d", + CHAR_getInt(petindex, CHAR_BASEIMAGENUMBER), + CHAR_getWorkInt(petindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt(petindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt(petindex, CHAR_WORKQUICK)); + + CHAR_setInt(petindex, CHAR_PETFAMILY, 1); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_FMPET, + petname, petattr, CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + return; + + } + +} + +void JoinMemberIndex( int meindex, int fmindexi ) +{ + int i; + + for( i = 0 ; i < FAMILY_MAXMEMBER; i++){ + if( familyMemberIndex[fmindexi][i] == meindex ) familyMemberIndex[fmindexi][i] = -1; + } + + for( i = 0 ; i < FAMILY_MAXMEMBER; i++){ + if( familyMemberIndex[fmindexi][i] < 0 ){ + familyMemberIndex[fmindexi][i] = meindex; + break; + } + } +#ifdef _CHANNEL_MODIFY + i = 0; + // ɵƵ¼ + while(i < FAMILY_MAXMEMBER){ + if(channelMember[fmindexi][0][i] == meindex){ + channelMember[fmindexi][0][i] = -1; + } + i++; + } + i = 0; + // Ƶ + while(i < FAMILY_MAXMEMBER){ + if(channelMember[fmindexi][0][i] == -1){ + channelMember[fmindexi][0][i] = meindex; + CHAR_setWorkInt(meindex,CHAR_WORKFMCHANNEL,0); + break; + } + i++; + } +#endif +} + +void LeaveMemberIndex( int meindex, int fmindexi ) +{ + int i; + + for( i = 0 ; i < FAMILY_MAXMEMBER; i++){ + if( familyMemberIndex[fmindexi][i] == meindex ) familyMemberIndex[fmindexi][i] = -1; + } +#ifdef _CHANNEL_MODIFY + i = 0; + // ɵƵ¼ + while(i < FAMILY_MAXMEMBER){ + if(channelMember[fmindexi][0][i] == meindex){ + channelMember[fmindexi][0][i] = -1; + } + i++; + } +#endif +} + +int FAMILY_RidePet( int fd, int meindex, char* message ) +{ + char token[64], token2[64]; + int petindex, rideGraNo = 0, leaderimageNo; + // Arminius 8.25 recover + int i; +#ifndef _NEW_RIDEPETS + int big4fm = 0; +#endif + if (!CHAR_CHECKINDEX(meindex))return 0; + + // Robin fix սв + if( CHAR_getWorkInt( meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) + { + CHAR_talkToCli( meindex, -1, "սв裡", CHAR_COLORYELLOW ); + return 0; + } + // Robin fix в + if( CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE){ + CHAR_talkToCli( meindex, -1, "в裡", CHAR_COLORYELLOW ); + return 0; + } + +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( meindex, CHAR_BECOMEPIG) > -1 ){ //״̬ + CHAR_setInt( meindex, CHAR_RIDEPET, -1 ); + //ѡ״̬ȻΪ"", + CHAR_complianceParameter( meindex ); + CHAR_send_P_StatusString( meindex, CHAR_P_STRING_RIDEPET); + CHAR_talkToCli( meindex, -1, "Ŀǰ㴦״̬˳", CHAR_COLORYELLOW ); + return 0; + } +#endif + if (getStringFromIndexWithDelim(message, "|", 2, token, sizeof(token)) == FALSE) return 0; + if( strcmp( token, "P") == 0) { + if (getStringFromIndexWithDelim(message, "|", 3, token2, sizeof(token2)) == FALSE) + return 0; + + if( atoi(token2) != -1 ) { + petindex = CHAR_getCharPet( meindex, atoi( token2 ) ); + if(!CHAR_CHECKINDEX(petindex))return 0; + //ȡֹս + //if( CHAR_getInt( meindex, CHAR_DEFAULTPET ) == atoi( token2 ) ) return 0; + if( CHAR_getInt( meindex, CHAR_RIDEPET) != -1 ) return 0; + if( CHAR_getInt( meindex, CHAR_LEARNRIDE) < CHAR_getInt( petindex, CHAR_LV ) ) + { + char buff[255]; + sprintf(buff,"Ŀǰֻ˵ȼС%dij衣",CHAR_getInt( meindex, CHAR_LEARNRIDE)); + CHAR_talkToCli( meindex, -1, buff, CHAR_COLORYELLOW ); + return 0; + } + if( CHAR_getWorkInt( petindex, CHAR_WORKFIXAI ) < 100 ) + { + CHAR_talkToCli( meindex, -1, "С100", CHAR_COLORYELLOW ); + return 0; + } + +#ifdef _PET_BEATITUDE + if( CHAR_getInt(petindex, CHAR_BEATITUDE) > 0){ + CHAR_talkToCli( meindex, -1, "ij޷裡", CHAR_COLORYELLOW ); + return 0; + } +#endif + +#ifdef _PET_VALIDITY + if(CHAR_getInt ( petindex, CHAR_PETVALIDITY) > 0 && CHAR_getInt ( petindex, CHAR_PETVALIDITY) < time(NULL) ){ + CHAR_talkToCli(meindex, -1, "óѾʧЧˣ", CHAR_COLORYELLOW); + int s_pet = CHAR_getWorkInt( meindex, CHAR_WORKSTANDBYPET); + s_pet ^= ( 1 << atoi( token2 ) ); + CHAR_setWorkInt( meindex, CHAR_WORKSTANDBYPET, s_pet); + + lssproto_SPET_send( fd, s_pet, TRUE); + return FALSE; + } +#endif + +#ifdef _RIDELEVEL + if( CHAR_getInt( meindex, CHAR_LV)+getRideLevel() < CHAR_getInt( petindex, CHAR_LV ) ) + { + char buff[255]; + sprintf(buff,"ֻȼ%dij衣",getRideLevel()); + CHAR_talkToCli( meindex, -1, buff, CHAR_COLORYELLOW ); + return 0; + } +#else + if( CHAR_getInt( meindex, CHAR_LV)+5 < CHAR_getInt( petindex, CHAR_LV ) ) + { + char buff[255]; + sprintf(buff,"ֻȼ5ij衣"); + CHAR_talkToCli( meindex, -1, buff, CHAR_COLORYELLOW ); + return 0; + } +#endif +#ifdef _PET_2TRANS + if( CHAR_getInt( petindex, CHAR_TRANSMIGRATION) > getRideTrans() ) return 0; +#endif + + rideGraNo = FamilyRideFunction(meindex, petindex, atoi( token2 )); + + if( rideGraNo != 0 ){ +#ifdef _ITEM_METAMO + // CHAR_setWorkInt( meindex, CHAR_WORKITEMMETAMO, 0); +#endif + CHAR_setInt( meindex , CHAR_RIDEPET, atoi( token2 ) ); + CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , rideGraNo ); + CHAR_complianceParameter( meindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( meindex, CHAR_P_STRING_RIDEPET ); + return 1; + } + }else { +// CHAR_setInt( meindex , CHAR_RIDEPET, -1 ); +// CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , CHAR_getInt( meindex , CHAR_BASEBASEIMAGENUMBER) ); +// CHAR_complianceParameter( meindex ); +// CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX )); +// CHAR_send_P_StatusString( meindex , CHAR_P_STRING_RIDEPET); + } + } + return 0; +} + +void ACFixFMPK(int winindex, int loseindex, int data) +{ + int i = 0, charindex = 0; + char msg1[256], msg2[256]; + + sprintf(msg1, "ϲ%8d㣡", (data / 100)); + sprintf(msg2, "%8d㣡", (data / 100)); + for (i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex = familyMemberIndex[winindex][i]; + if( charindex >= 0 ) { + if( CHAR_getCharUse(charindex) ) + CHAR_talkToCli( charindex , -1, msg1, CHAR_COLORYELLOW); + else + familyMemberIndex[winindex][i] = -1; + } + charindex = familyMemberIndex[loseindex][i]; + if( charindex >= 0 ) { + if( CHAR_getCharUse(charindex) ) + CHAR_talkToCli( charindex , -1, msg2, CHAR_COLORRED); + else + familyMemberIndex[loseindex][i] = -1; + } + } +} + +void getNewFMList() +{ + saacproto_ACShowFMList_send( acfd ); +} + +//int channelMember[FAMILY_MAXNUM][FAMILY_MAXCHANNEL][FAMILY_MAXMEMBER]; +//int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + +void checkFamilyIndex( void ) +{ + int i, j, k, charaindex, err1=0, err2=0; +// print(" checkFamilyIndex! "); + + for( i=0; i 0 ){ + if( fmindex_wk < 0 || fmindex_wk >= FAMILY_MAXNUM){ + print("FamilyNumber Data Error!!"); + return; + } + } + saacproto_ACShowMemberList_send( acfd, fmindex_wk); + + sprintf( sendbuf, " ֪\nСĴԱϣһ޸޷ظԭ̬Сġ"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_FM_MESSAGE2, + -1, + makeEscapeString( sendbuf, buf, sizeof(buf))); + } + if( strcmp( token, "L") == 0 ){ + int i, kind, letterNo = 0; + char subtoken[256]; + +#ifdef _FMVER21 +// if( CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER && +// CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_INVITE && +// CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_VICELEADER) return; + if( CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER && + CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_ELDER ) return; +#else + if( CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1) return; +#endif + + if (getStringFromIndexWithDelim(message, "|", 3, token2, sizeof(token2)) == FALSE) return; + kind = atoi( token2 ); + + for( i=0 ; i= 0 && tempindex != meindex ) + { + char tmpbuf[1024]; + sprintf(tmpbuf, "%s", CHAR_getChar(tempindex, CHAR_NAME)); + makeEscapeString( tmpbuf, buf, sizeof(buf)); + sprintf( subsub, "|%d|%s", j, buf ); + strcat( subbuf, subsub ); + num++; + } + } + sprintf( sendbuf, "L|CHANGE|L|%d%s", num, subbuf ); + //lssproto_FM_send( fd, sendbuf); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_LEADERSELECT, + WINDOW_BUTTONTYPE_OK, + -1, -1, + sendbuf ); + + } + // ѯ峤ѡǷԸ + if( strcmp( token2, "Q") == 0 ) + { + char token3[64], token4[64]; + int toindex; + +#ifdef _FMVER21 + if( CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) return; +#else + if( CHAR_getInt(meindex, CHAR_FMLEADERFLAG) != 1) return; +#endif + if (getStringFromIndexWithDelim(message, "|", 4, token3, + sizeof(token3)) == FALSE)return; + if (getStringFromIndexWithDelim(message, "|", 5, token4, + sizeof(token4)) == FALSE)return; + makeStringFromEscaped( token4 ); + + if( atoi(token3) < 0 || atoi(token3) > FAMILY_MAXMEMBER ) return; + + toindex = familyMemberIndex[fmindexi][atoi(token3)]; + if( !CHAR_CHECKINDEX( toindex ) ) return; + if( strcmp( token4, CHAR_getChar( toindex, CHAR_NAME)) != 0 ) return; + if( CheckLeaderQ(toindex) < 0 ) return; + + // ˫λʱCHAR_WORKLEADERCHANGEŶԷcharaindex + CHAR_setWorkInt( toindex, CHAR_WORKLEADERCHANGE, meindex); + CHAR_setWorkInt( meindex, CHAR_WORKLEADERCHANGE, toindex); + + sprintf( sendbuf, "%s|%d", makeEscapeString( CHAR_getChar( meindex, CHAR_NAME ), buf, sizeof(buf)), meindex ); + + lssproto_WN_send( CHAR_getWorkInt( toindex, CHAR_WORKFD ), WINDOW_MESSAGETYPE_LEADERSELECTA, + WINDOW_BUTTONTYPE_OK, + -1, -1, + sendbuf ); + + } + // ѡ˵Ĵ + if( strcmp( token2, "A") == 0 ) + { + int leaderindex, answerflag; + char leadername[64], token3[64], token4[64]; + +// print( "%s", message ); + + if (getStringFromIndexWithDelim(message, "|", 4, token3, + sizeof(token3)) == FALSE) return; + answerflag = atoi( token3 ); + + if (getStringFromIndexWithDelim(message, "|", 5, leadername, + sizeof( leadername )) == FALSE)return; + makeStringFromEscaped( leadername ); + + if (getStringFromIndexWithDelim(message, "|", 6, token4, + sizeof(token4)) == FALSE)return; + + //if( atoi(token4) < 0 || atoi(token4) > FAMILY_MAXMEMBER ) return; + + leaderindex = atoi( token4 ); + + // ˫CHAR_WORKLEADERCHANGEǷ + if( CHAR_getWorkInt( meindex, CHAR_WORKLEADERCHANGE ) != leaderindex ) return; + if( !CHAR_CHECKINDEX(leaderindex) ) return; + if( strcmp( leadername, CHAR_getChar( leaderindex, CHAR_NAME) ) != 0 ) return; + if( CHAR_getWorkInt( leaderindex, CHAR_WORKLEADERCHANGE ) != meindex ) return; + CHAR_setWorkInt( leaderindex, CHAR_WORKLEADERCHANGE, -1 ); +#ifdef _FMVER21 + if( CHAR_getInt(leaderindex, CHAR_FMLEADERFLAG ) != FMMEMBER_LEADER ) return; +#else + if( CHAR_getInt(leaderindex, CHAR_FMLEADERFLAG ) != 1 ) return; +#endif + if( CHAR_getInt(meindex, CHAR_FMINDEX) != CHAR_getInt(leaderindex, CHAR_FMINDEX) ) return; + + if( answerflag == 0 ) + { + CHAR_setWorkInt( meindex, CHAR_WORKLEADERCHANGE, 0); + CHAR_setWorkInt( leaderindex, CHAR_WORKLEADERCHANGE, 0); + lssproto_WN_send( CHAR_getWorkInt( leaderindex, CHAR_WORKFD) , WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nԲ𣡶ԷԸܣ", buf, sizeof(buf)) ); + return; + } + + if( answerflag == 1 ) + { + char tmpbuf[1024]; + sprintf( buf, "%d", CHAR_getInt( meindex, CHAR_FACEIMAGENUMBER ) ); + // CoolFish: add charname 2001/9/27 + sprintf( tmpbuf, "%s", CHAR_getChar( meindex, CHAR_NAME ) ); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(meindex, CHAR_FMNAME), + CHAR_getInt(meindex, CHAR_FMINDEX), + CHAR_getWorkInt(meindex, CHAR_WORKFMINDEXI), FM_FIX_FMLEADERCHANGE , buf, + tmpbuf, CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), CONNECT_getFdid(fd)); + // "", CHAR_getWorkInt(meindex, CHAR_WORKFMCHARINDEX), CONNECT_getFdid(fd)); + return; + } + } + } +} + +void ACFMJob( int fd, int ret, char* data1, char* data2 ) +{ + + int charaindex = CONNECT_getCharaindex( fd ); + if( !CHAR_CHECKINDEX(charaindex) ) return; + + + if( 1 ){ + + int leaderindex = CHAR_getWorkInt( charaindex, CHAR_WORKLEADERCHANGE ); + char buf[256], buf2[256]; + + CHAR_setWorkInt( charaindex, CHAR_WORKLEADERCHANGE, 0 ); + print("leaderindex:%d:%s\n", leaderindex,CHAR_getChar(leaderindex,CHAR_NAME) ); + + if( !CHAR_CHECKINDEX(leaderindex) ) return; + //if( CHAR_getWorkInt( leaderindex, CHAR_WORKLEADERCHANGE ) != charaindex ) return; + CHAR_setWorkInt( leaderindex, CHAR_WORKLEADERCHANGE, 0 ); + + if( ret == 0 ){ + CHAR_talkToCli( charaindex, -1, "峤λʧܣ", CHAR_COLORYELLOW ); + CHAR_talkToCli( leaderindex, -1, "峤λʧܣ", CHAR_COLORYELLOW ); + return; + } + + // Robin 10/02 debug + if( CHAR_getInt( leaderindex, CHAR_FMINDEX) != CHAR_getInt( charaindex, CHAR_FMINDEX) +#ifdef _FMVER21 + // || CHAR_getInt( leaderindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER ) +#else + // || CHAR_getInt( leaderindex, CHAR_FMLEADERFLAG) != 1 +#endif + ) + { + sprintf( buf, "leaderindex:%d:%s\n", leaderindex, CHAR_getChar( leaderindex, CHAR_NAME) ); + LogFamily( + CHAR_getChar(charaindex, CHAR_FMNAME), + CHAR_getInt(charaindex, CHAR_FMINDEX), + CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), + "LEADERCHANGE_ERROR(峤λʧ)", + buf + ); + return; + } + + //CHAR_setInt( leaderindex, CHAR_FMLEADERFLAG, FMMEMBER_MEMBER); + //CHAR_setInt( charaindex, CHAR_FMLEADERFLAG, FMMEMBER_LEADER); + SetFMPetVarInit( leaderindex ); + SetFMPetVarInit( charaindex ); + CHAR_sendStatusString( leaderindex, "F"); + CHAR_sendStatusString( charaindex, "F"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( "\nϲ㣡Ѿε峤ˡ\núõŬɣ\nˡǵȵ峤ҵļԱѡ\nµļػޣ彫ᱻɢࡣ", buf, sizeof(buf))); + + sprintf( buf2, "\nˣѾ峤λӽ%sˡ", CHAR_getChar( charaindex, CHAR_NAME) ); + lssproto_WN_send( CHAR_getWorkInt( leaderindex, CHAR_WORKFD) , WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString( buf2, buf, sizeof(buf))); + +// print(" LeaderChange!! [%s]->[%s] ", CHAR_getChar(leaderindex, CHAR_CDKEY), CHAR_getChar(charaindex, CHAR_CDKEY) ); + + sprintf( buf, "%s\t%s\t%s", + CHAR_getChar(leaderindex, CHAR_FMNAME), + CHAR_getChar(leaderindex, CHAR_NAME), + CHAR_getChar(leaderindex, CHAR_CDKEY) + ); + + LogFamily( + CHAR_getChar(charaindex, CHAR_FMNAME), + CHAR_getInt(charaindex, CHAR_FMINDEX), + CHAR_getChar(charaindex, CHAR_NAME), + CHAR_getChar(charaindex, CHAR_CDKEY), + "LEADERCHANGE(峤λ)", + buf); + } +} +#ifdef _MO_LNS_CHARSUOXU +int Char_GetFm( int id, int x) +{ + + int fd = getfdFromCharaIndex( id); + if (x == 1) //ü + return fmdptop.fmMomentum[id]; + + else if (x == 2)//üfmtopdp + return fmdptop.fmtopdp[id]; + else if (x == 3)//üʽ + { + //saacproto_ACGetFMData_send( fd, CHAR_getChar( id, CHAR_FMNAME), + //CHAR_getInt( id, CHAR_FMINDEX ), + //CHAR_getWorkInt( id, CHAR_WORKFMINDEXI ), + //1, + //CONNECT_getFdid(fd) + //); + return familyTax[CHAR_getWorkInt( id, CHAR_WORKFMINDEXI )]; + } +} + +char * FM_getManorData(int ManorId,int Flg) +{ + char *pointbuf = ""; + if( getStringFromIndexWithDelim(fmpointlist.pointlistarray[ManorId], "|", Flg, pointbuf, sizeof(pointbuf)) == FALSE ) return -1; + return pointbuf; +} +#endif + +#ifdef _FAMILYBADGE_ +int getFamilyBadge(int index) +{ + if(CHAR_CHECKINDEX(index)){ + int fmindex_wk = CHAR_getWorkInt( index, CHAR_WORKFMINDEXI); + if( fmindex_wk < 0 || fmindex_wk >= FAMILY_MAXNUM ) return 0; + return memberlist[fmindex_wk].badge; + }else + return 0; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/ls2data.dat b/石器时代服务器端最新完整源代码/Serv/gmsv/char/ls2data.dat new file mode 100644 index 0000000..54e06f7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/ls2data.dat @@ -0,0 +1,13 @@ +#ifndef LS2DATA_DAT +#define LS2DATA_DAT + +typedef struct { + int hash; + char *name; + int graphicnumber; +} CconvertStringNumber; + +CconvertStringNumber *convertStringNumber; +int cconvertStringNumber; + +#endif // LS2DATA_DAT ///:~ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile new file mode 100755 index 0000000..4a99344 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile @@ -0,0 +1,1175 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libchar.a + +SRC=char_base.c char.c char_event.c char_data.c skill.c title.c\ +addressbook.c chatmagic.c event.c char_walk.c encount.c pet.c \ +enemy.c pet_event.c char_talk.c char_party.c char_item.c \ +chatroom.c petmail.c trade.c family.c char_angel.c + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +char_base.o: char_base.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/net.h ../include/autil.h \ + ../include/version.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/autil.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/alloca.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../lua/lua.h ../lua/luaconf.h \ + ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/buf.h \ + ../include/magic.h ../include/function.h ../include/npccreate.h \ + ../include/configfile.h ../include/title.h ../include/pet.h \ + ../include/pet_skill.h ../include/anim_tbl.h ../include/enemy.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/family.h ../include/log.h +char.o: char.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/sys/stat.h /usr/include/bits/stat.h \ + /usr/include/ctype.h /usr/include/sys/time.h ../include/net.h \ + ../include/autil.h ../include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/common.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/item.h ../include/item_event.h \ + ../include/buf.h ../include/object.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/readmap.h ../include/handletime.h ../include/char_event.h \ + ../include/npccreate.h ../include/addressbook.h ../include/magic_base.h \ + ../include/magic.h ../include/chatmagic.h ../include/configfile.h \ + ../include/log.h ../include/anim_tbl.h ../include/encount.h \ + ../include/battle.h ../include/trade.h ../include/pet_skill.h \ + ../include/util.h ../include/enemy.h ../include/npcutil.h \ + ../include/pet.h ../include/family.h ../include/correct_bug.h \ + ../include/npc_checkman.h ../include/autil.h \ + ../include/profession_skill.h ../include/npc_autopk.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/chatroom.h ../include/mylua/function.h +char_event.o: char_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/item_event.h ../include/net.h ../include/item.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/util.h \ + ../include/char_data.h ../include/readmap.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/npccreate.h ../include/handletime.h ../include/anim_tbl.h \ + ../include/family.h +char_data.o: char_data.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/autil.h ../include/version.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/util.h ../include/anim_tbl.h \ + ../include/battle.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/trade.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char.h ../include/char_base.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/buf.h ../include/item.h \ + ../include/log.h ../include/pet.h ../include/enemy.h \ + ../include/char_base.h ../include/configfile.h \ + ../include/defaultPlayer.h ls2data.dat ../include/family.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +skill.o: skill.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/util.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/battle.h ../include/trade.h ../include/profession_skill.h +title.o: title.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/ctype.h ../include/autil.h \ + ../include/version.h ../include/title.h ../include/util.h \ + /usr/include/sys/time.h ../include/char.h ../include/char_base.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item.h ../include/skill.h \ + ../include/buf.h ../include/util.h ../include/configfile.h +addressbook.o: addressbook.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h ../include/addressbook.h \ + ../include/util.h /usr/include/sys/time.h ../include/net.h \ + ../include/autil.h ../include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/char.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/object.h ../include/battle.h ../include/trade.h \ + ../include/configfile.h ../include/npcutil.h ../include/pet.h \ + ../include/petmail.h ../include/log.h +chatmagic.o: chatmagic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h /usr/include/malloc.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/util.h ../include/buf.h ../include/npcutil.h \ + ../include/char_base.h ../include/object.h ../include/char_data.h \ + ../include/handletime.h ../include/chatmagic.h ../include/configfile.h \ + ../include/readmap.h ../include/map_deal.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/battle.h \ + ../include/trade.h ../include/pet.h ../include/enemy.h \ + ../include/encount.h ../include/magic_base.h ../include/magic.h \ + ../include/pet_skill.h ../include/pet_event.h ../include/item_gen.h \ + ../include/mclient.h ../include/npc_eventaction.h \ + ../include/map_warppoint.h ../include/npc_manorsman.h ../include/net.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/npc_scheduleman.h ../include/trade.h ../include/npccreate.h \ + ../include/npc_transmigration.h ../include/profession_skill.h \ + ../include/char_talk.h ../include/longzoro/playerquestion.h \ + ../include/npc_magiccard.h ../include/family.h ../include/petmail.h \ + ../include/npc_autopk.h ../include/mylua/ablua.h ../include/item.h \ + ../include/readnpc.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h +event.o: event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/readmap.h \ + ../include/map_warppoint.h ../include/event.h ../include/npc_warp.h \ + ../include/npc_npcenemy.h +char_walk.o: char_walk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/time.h /usr/include/bits/time.h \ + ../include/common.h ../include/handletime.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_event.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/readmap.h ../include/map_deal.h \ + ../include/npccreate.h ../include/encount.h ../include/npcutil.h \ + ../include/battle.h ../include/trade.h ../include/net.h \ + ../include/configfile.h ../include/npc_npcenemy.h \ + ../include/mylua/function.h +encount.o: encount.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/autil.h ../include/version.h \ + ../include/common.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/encount.h ../include/enemy.h +pet.o: pet.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/object.h \ + ../include/readmap.h ../include/map_deal.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/handletime.h ../include/pet.h ../include/battle.h \ + ../include/trade.h ../include/petmail.h ../include/log.h \ + ../include/function.h +enemy.o: enemy.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/autil.h ../include/version.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/encount.h ../include/enemy.h ../include/pet.h \ + ../include/enemyexptbl.h ../include/petmail.h ../include/battle.h \ + ../include/trade.h ../include/pet_skillinfo.h ../include/anim_tbl.h \ + ../include/log.h ../include/npcutil.h +pet_event.o: pet_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/handletime.h ../include/pet_event.h ../include/npcutil.h \ + ../include/log.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_exchangeman.h \ + ../include/npc_eventaction.h ../include/mylua/function.h +char_talk.o: char_talk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/string.h \ + ../include/handletime.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + ../include/autil.h ../include/version.h ../include/readmap.h \ + ../include/util.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item_event.h ../include/chatmagic.h \ + ../include/battle.h ../include/trade.h ../include/log.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/family.h ../include/buf.h \ + ../include/profession_skill.h ../include/net.h ../include/char_talk.h \ + ../include/longzoro/move.h ../include/longzoro/playerquestion.h \ + ../include/mylua/function.h +char_party.o: char_party.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h ../include/npc_bus.h \ + ../include/npc_airplane.h ../include/family.h ../include/configfile.h \ + ../include/init.h ../include/mylua/function.h +char_item.o: char_item.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/map_deal.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/handletime.h ../include/log.h ../include/item_event.h \ + ../include/battle.h ../include/trade.h ../include/petmail.h \ + ../include/mylua/function.h +chatroom.o: chatroom.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/string.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/chatmagic.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/configfile.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/family.h ../include/chatroom.h \ + ../include/net.h ../include/util.h +petmail.o: petmail.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h ../include/buf.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/battle.h \ + ../include/trade.h ../include/handletime.h ../include/map_deal.h \ + ../include/addressbook.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/pet.h \ + ../include/petmail.h ../include/npcutil.h ../include/log.h +trade.o: trade.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/correct_bug.h \ + /usr/include/string.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h ../include/trade.h \ + ../include/log.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/battle.h ../include/trade.h \ + ../include/npc_bus.h ../include/char_talk.h ../include/pet_skill.h +family.o: family.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/configfile.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npcutil.h ../include/family.h \ + ../include/log.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/battle.h ../include/trade.h \ + ../include/npc_bus.h ../include/char_talk.h \ + ../include/npc_scheduleman.h ../include/npc_fmdengon.h \ + ../include/mylua/function.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h +char_angel.o: char_angel.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/sys/stat.h /usr/include/bits/stat.h \ + /usr/include/ctype.h /usr/include/sys/time.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/item.h ../include/item_event.h \ + ../include/buf.h ../include/object.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/readmap.h ../include/handletime.h ../include/char_event.h \ + ../include/npccreate.h ../include/addressbook.h ../include/magic_base.h \ + ../include/magic.h ../include/chatmagic.h ../include/configfile.h \ + ../include/log.h ../include/anim_tbl.h ../include/encount.h \ + ../include/battle.h ../include/trade.h ../include/pet_skill.h \ + ../include/util.h ../include/enemy.h ../include/npcutil.h \ + ../include/pet.h ../include/family.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile.bak new file mode 100755 index 0000000..4a99344 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/makefile.bak @@ -0,0 +1,1175 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libchar.a + +SRC=char_base.c char.c char_event.c char_data.c skill.c title.c\ +addressbook.c chatmagic.c event.c char_walk.c encount.c pet.c \ +enemy.c pet_event.c char_talk.c char_party.c char_item.c \ +chatroom.c petmail.c trade.c family.c char_angel.c + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +char_base.o: char_base.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/net.h ../include/autil.h \ + ../include/version.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/autil.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/alloca.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../lua/lua.h ../lua/luaconf.h \ + ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/buf.h \ + ../include/magic.h ../include/function.h ../include/npccreate.h \ + ../include/configfile.h ../include/title.h ../include/pet.h \ + ../include/pet_skill.h ../include/anim_tbl.h ../include/enemy.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/family.h ../include/log.h +char.o: char.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/sys/stat.h /usr/include/bits/stat.h \ + /usr/include/ctype.h /usr/include/sys/time.h ../include/net.h \ + ../include/autil.h ../include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/common.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/item.h ../include/item_event.h \ + ../include/buf.h ../include/object.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/readmap.h ../include/handletime.h ../include/char_event.h \ + ../include/npccreate.h ../include/addressbook.h ../include/magic_base.h \ + ../include/magic.h ../include/chatmagic.h ../include/configfile.h \ + ../include/log.h ../include/anim_tbl.h ../include/encount.h \ + ../include/battle.h ../include/trade.h ../include/pet_skill.h \ + ../include/util.h ../include/enemy.h ../include/npcutil.h \ + ../include/pet.h ../include/family.h ../include/correct_bug.h \ + ../include/npc_checkman.h ../include/autil.h \ + ../include/profession_skill.h ../include/npc_autopk.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/chatroom.h ../include/mylua/function.h +char_event.o: char_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/item_event.h ../include/net.h ../include/item.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/util.h \ + ../include/char_data.h ../include/readmap.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/npccreate.h ../include/handletime.h ../include/anim_tbl.h \ + ../include/family.h +char_data.o: char_data.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/autil.h ../include/version.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/util.h ../include/anim_tbl.h \ + ../include/battle.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/trade.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char.h ../include/char_base.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/buf.h ../include/item.h \ + ../include/log.h ../include/pet.h ../include/enemy.h \ + ../include/char_base.h ../include/configfile.h \ + ../include/defaultPlayer.h ls2data.dat ../include/family.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +skill.o: skill.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/util.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/battle.h ../include/trade.h ../include/profession_skill.h +title.o: title.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/ctype.h ../include/autil.h \ + ../include/version.h ../include/title.h ../include/util.h \ + /usr/include/sys/time.h ../include/char.h ../include/char_base.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item.h ../include/skill.h \ + ../include/buf.h ../include/util.h ../include/configfile.h +addressbook.o: addressbook.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h ../include/addressbook.h \ + ../include/util.h /usr/include/sys/time.h ../include/net.h \ + ../include/autil.h ../include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/char.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/object.h ../include/battle.h ../include/trade.h \ + ../include/configfile.h ../include/npcutil.h ../include/pet.h \ + ../include/petmail.h ../include/log.h +chatmagic.o: chatmagic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h /usr/include/malloc.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/util.h ../include/buf.h ../include/npcutil.h \ + ../include/char_base.h ../include/object.h ../include/char_data.h \ + ../include/handletime.h ../include/chatmagic.h ../include/configfile.h \ + ../include/readmap.h ../include/map_deal.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/battle.h \ + ../include/trade.h ../include/pet.h ../include/enemy.h \ + ../include/encount.h ../include/magic_base.h ../include/magic.h \ + ../include/pet_skill.h ../include/pet_event.h ../include/item_gen.h \ + ../include/mclient.h ../include/npc_eventaction.h \ + ../include/map_warppoint.h ../include/npc_manorsman.h ../include/net.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/npc_scheduleman.h ../include/trade.h ../include/npccreate.h \ + ../include/npc_transmigration.h ../include/profession_skill.h \ + ../include/char_talk.h ../include/longzoro/playerquestion.h \ + ../include/npc_magiccard.h ../include/family.h ../include/petmail.h \ + ../include/npc_autopk.h ../include/mylua/ablua.h ../include/item.h \ + ../include/readnpc.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h +event.o: event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/readmap.h \ + ../include/map_warppoint.h ../include/event.h ../include/npc_warp.h \ + ../include/npc_npcenemy.h +char_walk.o: char_walk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/time.h /usr/include/bits/time.h \ + ../include/common.h ../include/handletime.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_event.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/readmap.h ../include/map_deal.h \ + ../include/npccreate.h ../include/encount.h ../include/npcutil.h \ + ../include/battle.h ../include/trade.h ../include/net.h \ + ../include/configfile.h ../include/npc_npcenemy.h \ + ../include/mylua/function.h +encount.o: encount.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/autil.h ../include/version.h \ + ../include/common.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/encount.h ../include/enemy.h +pet.o: pet.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/object.h \ + ../include/readmap.h ../include/map_deal.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/handletime.h ../include/pet.h ../include/battle.h \ + ../include/trade.h ../include/petmail.h ../include/log.h \ + ../include/function.h +enemy.o: enemy.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/autil.h ../include/version.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/buf.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/encount.h ../include/enemy.h ../include/pet.h \ + ../include/enemyexptbl.h ../include/petmail.h ../include/battle.h \ + ../include/trade.h ../include/pet_skillinfo.h ../include/anim_tbl.h \ + ../include/log.h ../include/npcutil.h +pet_event.o: pet_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/common.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/configfile.h \ + ../include/handletime.h ../include/pet_event.h ../include/npcutil.h \ + ../include/log.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_exchangeman.h \ + ../include/npc_eventaction.h ../include/mylua/function.h +char_talk.o: char_talk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/string.h \ + ../include/handletime.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + ../include/autil.h ../include/version.h ../include/readmap.h \ + ../include/util.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item_event.h ../include/chatmagic.h \ + ../include/battle.h ../include/trade.h ../include/log.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/family.h ../include/buf.h \ + ../include/profession_skill.h ../include/net.h ../include/char_talk.h \ + ../include/longzoro/move.h ../include/longzoro/playerquestion.h \ + ../include/mylua/function.h +char_party.o: char_party.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/battle.h ../include/trade.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h ../include/npc_bus.h \ + ../include/npc_airplane.h ../include/family.h ../include/configfile.h \ + ../include/init.h ../include/mylua/function.h +char_item.o: char_item.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/map_deal.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/item.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/handletime.h ../include/log.h ../include/item_event.h \ + ../include/battle.h ../include/trade.h ../include/petmail.h \ + ../include/mylua/function.h +chatroom.o: chatroom.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/string.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/chatmagic.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/configfile.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/family.h ../include/chatroom.h \ + ../include/net.h ../include/util.h +petmail.o: petmail.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h ../include/buf.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/battle.h \ + ../include/trade.h ../include/handletime.h ../include/map_deal.h \ + ../include/addressbook.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/pet.h \ + ../include/petmail.h ../include/npcutil.h ../include/log.h +trade.o: trade.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/correct_bug.h \ + /usr/include/string.h /usr/include/ctype.h /usr/include/endian.h \ + /usr/include/bits/endian.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h ../include/trade.h \ + ../include/log.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/battle.h ../include/trade.h \ + ../include/npc_bus.h ../include/char_talk.h ../include/pet_skill.h +family.o: family.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/configfile.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npcutil.h ../include/family.h \ + ../include/log.h ../include/handletime.h ../include/buf.h \ + ../include/net.h ../include/battle.h ../include/trade.h \ + ../include/npc_bus.h ../include/char_talk.h \ + ../include/npc_scheduleman.h ../include/npc_fmdengon.h \ + ../include/mylua/function.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h +char_angel.o: char_angel.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/sys/stat.h /usr/include/bits/stat.h \ + /usr/include/ctype.h /usr/include/sys/time.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/item.h ../include/item_event.h \ + ../include/buf.h ../include/object.h ../include/map_deal.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/readmap.h ../include/handletime.h ../include/char_event.h \ + ../include/npccreate.h ../include/addressbook.h ../include/magic_base.h \ + ../include/magic.h ../include/chatmagic.h ../include/configfile.h \ + ../include/log.h ../include/anim_tbl.h ../include/encount.h \ + ../include/battle.h ../include/trade.h ../include/pet_skill.h \ + ../include/util.h ../include/enemy.h ../include/npcutil.h \ + ../include/pet.h ../include/family.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet.c new file mode 100644 index 0000000..1b8d461 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet.c @@ -0,0 +1,677 @@ +#include "version.h" +#include + +#include "char_base.h" +#include "char.h" +#include "object.h" +#include "readmap.h" +#include "map_deal.h" +#include "lssproto_serv.h" +#include "handletime.h" +#include "pet.h" +#include "battle.h" +#include "petmail.h" +#include "log.h" +#include "function.h" +/* + * ʸ ĩ + */ +/*------------------------------------------------------------------------ + * ʸë๴Ի񲻯£۷ã + * CHARհ 弰ľ£ + * Իľƽҷindex -1 + *-----------------------------------------------------------------------*/ +int PET_DEBUG_initPetOne( int charaindex) +{ + Char ch; + int havepetindex; + int index; + /* ʸë ¾Ʃ */ + havepetindex = CHAR_getCharPetElement( charaindex) ; + + memset( &ch, 0, sizeof( ch)); + if( !CHAR_getDefaultChar( &ch,31010 ) )return -1; + + /* į */ + ch.data[CHAR_BASEBASEIMAGENUMBER] + = ch.data[CHAR_BASEIMAGENUMBER] = 30008; + ch.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + /* */ + ch.workint[CHAR_WORKATTACKPOWER] = 100; + /* */ + ch.workint[CHAR_WORKDEFENCEPOWER] = 50; + /* HP */ + ch.data[CHAR_HP] = 100; + /* */ + strcpysafe( ch.string[CHAR_NAME].string, 32, "" ); + + /* CHARԻ񲻯 */ + index = PET_initCharOneArray( &ch); + + if( index < 0 ) return -1; + + /* DZб */ + CHAR_setWorkInt( index, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setWorkInt( index,CHAR_WORKOBJINDEX,-1); + CHAR_setCharPet( charaindex, havepetindex, index); + CHAR_setInt( index, CHAR_SLOT, 2); + return havepetindex; +} + +static int _PET_dropPet( int charaindex, int havepetindex, int tofl, int tox, int toy) +{ + char szPet[128]; + int dirx[9],diry[9]; + int i, j; + int objindex=-1; + int floor,x,y; + int petindex; + int count_chara =0, count_item =0; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return FALSE; + petindex = CHAR_getCharPet(charaindex,havepetindex); + if( !CHAR_CHECKINDEX( petindex )) return FALSE; + if( !CHAR_CHECKINDEX( charaindex ) )return FALSE; + if( CHAR_CHECKINDEX( petindex) == FALSE ) return FALSE; + +#ifdef _AVID_TRADETRYBUG // + if( CHAR_getWorkInt( charaindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_TRADING ){ + CHAR_talkToCli( charaindex, -1, "״̬޷", CHAR_COLORYELLOW ); + return FALSE; + } +#endif + // CoolFish: Family 2001/6/13 + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(charaindex, -1, "ػ޷", CHAR_COLORYELLOW); + return FALSE; + } + if (CHAR_getInt(charaindex, CHAR_RIDEPET) == havepetindex ){ + CHAR_talkToCli(charaindex, -1, "еij޷", CHAR_COLORYELLOW); + return FALSE; + } +#ifdef _LOCK_PET_ITEM +{ + char *name = CHAR_getChar(petindex, CHAR_NAME); + char *owntile = CHAR_getChar(petindex, CHAR_OWNTITLE); + + if(name[0] == '*' || owntile[0] == '*' ){ + CHAR_talkToCli( charaindex, -1, "󶨳޷", CHAR_COLORYELLOW); + return FALSE; + } +} +#endif +#ifdef _DROPCHECK2 + + floor = CHAR_getInt( charaindex, CHAR_FLOOR); + x = CHAR_getInt( charaindex, CHAR_X); + y = CHAR_getInt( charaindex, CHAR_Y); + + for( i = x-CHAR_DEFAULTSEESIZ/2 ; i <= x+CHAR_DEFAULTSEESIZ/2 ; i++ ){ + for( j = y-CHAR_DEFAULTSEESIZ/2 ; j <= y+CHAR_DEFAULTSEESIZ/2 ; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj(floor,i,j); object ; object = NEXT_OBJECT(object ) ) { + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + count_chara++; + } + if( OBJECT_getType(objindex) == OBJTYPE_ITEM || OBJECT_getType(objindex) == OBJTYPE_GOLD ) { + count_item++; + } + } + } + if( count_item > 80 || count_chara > 80 ) { + CHAR_talkToCli( charaindex, -1, "Ѿ̫ӵˣٶˡ", CHAR_COLORYELLOW ); + return FALSE; + } + } + +#endif + if( tofl == -1 ) { + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + diry[i+2] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + floor = CHAR_getInt( charaindex,CHAR_FLOOR ); + for( i = 0 ; i < 9 ; i ++ ){ + int x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + int y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + if( PET_isPutPoint( floor, x, y ) == TRUE ) { + break; + } + } + if( i == 9 ) i = 1; + x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + }else { + if( MAP_walkAbleFromPoint( tofl,tox,toy, FALSE ) == FALSE ) { + print( "map walkable err %s:%d\n", __FILE__,__LINE__); + return FALSE; + } + floor = tofl; + x = tox; + y = toy; + } + objindex = PET_dropPetAbsolute( petindex,floor,x,y, FALSE ); + if( objindex == -1 ) return FALSE; + + CHAR_setWorkInt( petindex,CHAR_WORKOBJINDEX,objindex ); + CHAR_setCharPet( charaindex, havepetindex, -1); + CHAR_setInt( petindex, CHAR_FLOOR, floor); + CHAR_setInt( petindex, CHAR_X, x); + CHAR_setInt( petindex, CHAR_Y, y); + CHAR_setInt( petindex, CHAR_PUTPETTIME, NowTime.tv_sec); + if( havepetindex == CHAR_getInt( charaindex, CHAR_DEFAULTPET)) { + int fd; + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1); + fd = getfdFromCharaIndex( charaindex); + lssproto_KS_send( fd, havepetindex, 0); + + } + CHAR_sendCToArroundCharacter( objindex); + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { +#ifdef _PET_ITEM + CHAR_sendPetItemEmpty(charaindex,havepetindex); +#endif + snprintf( szPet, sizeof( szPet ), "K%d", havepetindex ); + CHAR_sendStatusString( charaindex, szPet ); + } + return TRUE; +} + + +/*------------------------------------------------------------ + * ʸë + * ¦ + * itemindex int ʧ ة̼͵ + * floor int ׷ʧID + * x int x + * y int y + * net BOOL ͼë¾ + * ߯Ի + * objindex + * -1 + ------------------------------------------------------------*/ +int PET_dropPetAbsolute( int petindex, int floor, int x, int y,BOOL net) +{ + Object object; + int objindex; + + if( !CHAR_CHECKINDEX(petindex) )return FALSE; + + object.type = OBJTYPE_CHARA; + object.index = petindex; + object.x = x; + object.y = y; + object.floor = floor; + + objindex = initObjectOne( &object ); + + if( net ) + CHAR_sendWatchEvent( objindex,CHAR_ACTSTAND,NULL,0,TRUE); + + return objindex; +} + +BOOL PET_isPutPoint( int fl,int x, int y) +{ + OBJECT object; + if( MAP_walkAbleFromPoint( fl,x,y, FALSE ) == FALSE ) + return FALSE; + for( object=MAP_getTopObj(fl,x,y) ; + object ; + object = NEXT_OBJECT(object ) ) + { + int objindex = GET_OBJINDEX(object); + switch( OBJECT_getType(objindex) ){ + case OBJTYPE_NOUSE: + break; + case OBJTYPE_ITEM: + case OBJTYPE_GOLD: + case OBJTYPE_CHARA: + return FALSE; + break; + default: + break; + } + } + return TRUE; +} + +int PET_dropPet( int charaindex, int havepetindex) +{ + int petindex; + petindex = CHAR_getCharPet(charaindex,havepetindex); + if( !CHAR_CHECKINDEX( petindex )) return FALSE; + + if( _PET_dropPet( charaindex, havepetindex, -1,-1,-1) == TRUE ){ + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "Drop()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + return 1; + } + return 0; +} + +int PET_dropPetFLXY( int charaindex, int havepetindex, int fl, int x, int y) +{ + return _PET_dropPet( charaindex, havepetindex, fl,x,y); +} + +/*------------------------------------------------------------ + * ʸüìëƻ֧ + ------------------------------------------------------------*/ +int PET_initCharOneArray( Char *ch) +{ + int i; + char *tmp[CHAR_FUNCTABLENUM] = { + "", /* CHAR_INITFUNC */ + "", /* CHAR_WALKPREFUNC */ + "", /* CHAR_WALKPOSTFUNC */ + "", /* CHAR_PREOVERFUNC */ + "", /* CHAR_PREOVERFUNC */ + "core_PetWatch", /* CHAR_WATCHFUNC */ + "", /* CHAR_LOOPFUNC */ + "", /* CHAR_DYINGFUNC */ + "core_PetTalk", /* CHAR_TALKEDFUNC */ + "", /* CHAR_PREATTACKEDFUNC */ + "", /* CHAR_POSTATTACKEDFUNC */ + "", /* CHAR_OFFFUNC */ + "", /* CHAR_LOOKEDFUNC */ + "", /* CHAR_ITEMPUTFUNC */ + "", /* CHAR_SPECIALTALKEDFUNC */ + "", /* CHAR_WINDOWTALKEDFUNC */ +#ifdef _USER_CHARLOOPS + "", // CHAR_LOOPFUNCTEMP1, + "", // CHAR_LOOPFUNCTEMP2, + "", //CHAR_BATTLEPROPERTY, +#endif + }; + for( i = 0; i < CHAR_FUNCTABLENUM; i ++ ) { + strcpysafe( ch->charfunctable[i].string, + sizeof( ch->charfunctable[i]), + tmp[i]); + } + if( ch->data[CHAR_MAILMODE] != CHAR_PETMAIL_NONE ) { + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), "PETMAIL_Loop"); + + } + +#ifdef _PET_FUSION + if( ch->data[CHAR_FUSIONBEIT] == 1 && + ch->data[CHAR_FUSIONRAISE] > 0 ) { + //andy_log +// print("init CHAR_LOOPFUNCTEMP1:%s \n", "PET_CheckIncubateLoop"); + + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "PET_CheckIncubateLoop"); + ch->data[CHAR_LOOPINTERVAL] = 60000; + + ch->functable[CHAR_LOOPFUNCTEMP1] + = getFunctionPointerFromName( "PET_CheckIncubateLoop"); + +// CHAR_constructFunctable( petindex); + } +#endif + int petindex = CHAR_initCharOneArray( ch); + + return petindex; +} + +int PET_createPetFromCharaIndex( int charaindex, int enemyindex) +{ + Char CharNew; + int newindex; + int havepetelement; + char szPet[128]; + int i; + + havepetelement = CHAR_getCharPetElement( charaindex); + if( havepetelement < 0 ) return -1; + memset( &CharNew, 0, sizeof( Char ) ); + if( !CHAR_getDefaultChar( &CharNew,31010 ) )return -1; + CharNew.data[CHAR_BASEBASEIMAGENUMBER] + = CharNew.data[CHAR_BASEIMAGENUMBER] = CHAR_getInt(enemyindex,CHAR_BASEIMAGENUMBER); + CharNew.data[CHAR_WHICHTYPE] = CHAR_TYPEPET; + CharNew.data[CHAR_HP] = CHAR_getInt(enemyindex, CHAR_HP); + CharNew.data[CHAR_MP] = CHAR_getInt(enemyindex, CHAR_MP); + CharNew.data[CHAR_MAXMP] = CHAR_getInt(enemyindex, CHAR_MAXMP); + CharNew.data[CHAR_VITAL] = CHAR_getInt(enemyindex, CHAR_VITAL); + CharNew.data[CHAR_STR] = CHAR_getInt(enemyindex, CHAR_STR); + CharNew.data[CHAR_TOUGH] = CHAR_getInt(enemyindex, CHAR_TOUGH); + CharNew.data[CHAR_DEX] = CHAR_getInt(enemyindex, CHAR_DEX); + CharNew.data[CHAR_LUCK] = CHAR_getInt(enemyindex, CHAR_LUCK); + CharNew.data[CHAR_FIREAT] = CHAR_getInt(enemyindex, CHAR_FIREAT); + CharNew.data[CHAR_WATERAT] = CHAR_getInt(enemyindex, CHAR_WATERAT); + CharNew.data[CHAR_EARTHAT] = CHAR_getInt(enemyindex, CHAR_EARTHAT); + CharNew.data[CHAR_WINDAT] = CHAR_getInt(enemyindex, CHAR_WINDAT); + //CharNew.data[CHAR_EXP] = CHAR_getInt(enemyindex, CHAR_EXP); + + CharNew.data[CHAR_SLOT] = CHAR_getInt(enemyindex, CHAR_SLOT); + CharNew.data[CHAR_MODAI] = CHAR_getInt(enemyindex, CHAR_MODAI); + CharNew.data[CHAR_LV] = CHAR_getInt(enemyindex, CHAR_LV); + CharNew.data[CHAR_POISON] = CHAR_getInt(enemyindex, CHAR_POISON); + CharNew.data[CHAR_PARALYSIS]= CHAR_getInt(enemyindex, CHAR_PARALYSIS); + CharNew.data[CHAR_SLEEP] = CHAR_getInt(enemyindex, CHAR_SLEEP); + CharNew.data[CHAR_STONE] = CHAR_getInt(enemyindex, CHAR_STONE); + CharNew.data[CHAR_DRUNK] = CHAR_getInt(enemyindex, CHAR_DRUNK); + CharNew.data[CHAR_CONFUSION]= CHAR_getInt(enemyindex, CHAR_CONFUSION); + CharNew.data[CHAR_RARE] = CHAR_getInt(enemyindex, CHAR_RARE); + CharNew.data[CHAR_PETRANK] = CHAR_getInt(enemyindex, CHAR_PETRANK); + CharNew.data[CHAR_PETID] = CHAR_getInt(enemyindex, CHAR_PETID); + CharNew.data[CHAR_PETENEMYID] = CHAR_getInt(enemyindex, CHAR_PETENEMYID); + CharNew.data[CHAR_CRITIAL] = CHAR_getInt(enemyindex, CHAR_CRITIAL); + CharNew.data[CHAR_COUNTER] = CHAR_getInt(enemyindex, CHAR_COUNTER); + CharNew.data[CHAR_PETMAILEFFECT] = RAND(0, PETMAIL_EFFECTMAX); + + for( i = 0; i < CHAR_MAXPETSKILLHAVE; i ++ ) { + CharNew.unionTable.indexOfPetskill[i] = CHAR_getPetSkill( enemyindex, i); + } + CharNew.data[CHAR_ALLOCPOINT] = CHAR_getInt(enemyindex, CHAR_ALLOCPOINT); + strcpysafe( CharNew.string[CHAR_NAME].string, + sizeof(CharNew.string[CHAR_NAME].string), + CHAR_getChar( enemyindex, CHAR_NAME) ); + newindex = PET_initCharOneArray( &CharNew ); + if( newindex < 0 ){ + return -1; + } + + CHAR_setMaxExpFromLevel( newindex, CHAR_getInt( enemyindex, CHAR_LV )); + CHAR_complianceParameter( newindex ); +#ifdef _PETCOM_ + CHAR_setInt(newindex,CHAR_YHP,CHAR_getWorkInt( newindex, CHAR_WORKMAXHP)); + CHAR_setInt(newindex,CHAR_YATK,CHAR_getWorkInt( newindex, CHAR_WORKFIXSTR)); + CHAR_setInt(newindex,CHAR_YDEF,CHAR_getWorkInt( newindex, CHAR_WORKFIXTOUGH)); + CHAR_setInt(newindex,CHAR_YQUICK,CHAR_getWorkInt( newindex, CHAR_WORKFIXDEX)); + CHAR_setInt(newindex,CHAR_YLV,CHAR_getInt(newindex,CHAR_LV)); +#endif + CHAR_setWorkInt( newindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetelement, newindex); + CHAR_setChar( newindex, CHAR_OWNERCDKEY, + CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( newindex, CHAR_OWNERCHARANAME, + CHAR_getChar( charaindex, CHAR_NAME)); + snprintf( szPet, sizeof( szPet ), "K%d", havepetelement ); + CHAR_sendStatusString( charaindex, szPet ); + snprintf( szPet, sizeof( szPet ), "W%d", havepetelement ); + CHAR_sendStatusString( charaindex, szPet ); + + return newindex; + +} +BOOL PET_SelectBattleEntryPet( int charaindex, int petarray) +{ + int pindex; + if( !CHAR_CHECKINDEX( charaindex ) )return FALSE; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return FALSE; + + if( petarray == -1 ) { + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1 ); + return TRUE; + } + if( !CHAR_CHECKPETINDEX( petarray)) return FALSE; + pindex = CHAR_getCharPet( charaindex, petarray ); + if( !CHAR_CHECKINDEX( pindex)) return FALSE; + + if( CHAR_getFlg( pindex, CHAR_ISDIE )) return FALSE; + +#ifdef _PET_VALIDITY + if(CHAR_getInt ( pindex, CHAR_PETVALIDITY) > 0 && CHAR_getInt ( pindex, CHAR_PETVALIDITY) < time(NULL) ){ + CHAR_talkToCli(charaindex, -1, "óѾʧЧˣ", CHAR_COLORYELLOW); + int s_pet = CHAR_getWorkInt( charaindex, CHAR_WORKSTANDBYPET); + s_pet ^= ( 1 << petarray ); + CHAR_setWorkInt( charaindex, CHAR_WORKSTANDBYPET, s_pet); + + lssproto_SPET_send( getfdFromCharaIndex(charaindex), s_pet, TRUE); + return FALSE; + } +#endif +#ifdef _MO_LUA_KS_CALLBACK + if(FreeSelectBattlePet(charaindex, petarray) == FALSE){ + return FALSE; + } +#endif + CHAR_setInt( charaindex, CHAR_DEFAULTPET, petarray ); + + return TRUE; +} + +// Robin 0707 petFollow +#if 1 +//,λ,ͼ,X,Y +int PET_dropPetFollow( int charaindex, int havepetindex, int tofl, int tox, int toy) +{ + char szPet[128]; + int dirx[9],diry[9]; + int i; + int objindex=-1; + int floor,x,y; + int petindex; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return FALSE; + petindex = CHAR_getCharPet(charaindex,havepetindex); + if( petindex == -1 ) return FALSE; + if( !CHAR_CHECKINDEX( charaindex ) )return FALSE; + if( CHAR_CHECKINDEX( petindex) == FALSE ) return FALSE; + + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(charaindex, -1, "ػ޷", CHAR_COLORYELLOW); + return FALSE; + } + if (CHAR_getInt(charaindex, CHAR_RIDEPET) == havepetindex){ + CHAR_talkToCli(charaindex, -1, "еij޷棡", CHAR_COLORYELLOW); + return FALSE; + } + if( tofl == -1 ){ + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + diry[i+2] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + + floor = CHAR_getInt( charaindex,CHAR_FLOOR ); + for( i = 0 ; i < 9 ; i ++ ){ + int x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + int y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + if( PET_isPutPoint( floor, x, y ) == TRUE ) { + break; + } + } + if( i == 9 ) i = 1; + + x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + } + else { + if( MAP_walkAbleFromPoint( tofl,tox,toy, FALSE ) == FALSE ) { + print( "map walkable err %s:%d\n", __FILE__,__LINE__); + return FALSE; + } + floor = tofl; + x = tox; + y = toy; + } + + objindex = PET_dropPetAbsolute( petindex,floor,x,y, FALSE ); + if( objindex == -1 ) return FALSE; + + CHAR_setWorkInt( petindex,CHAR_WORKOBJINDEX,objindex ); + CHAR_setCharPet( charaindex, havepetindex, -1); + CHAR_setInt( petindex, CHAR_FLOOR, floor); + CHAR_setInt( petindex, CHAR_X, x); + CHAR_setInt( petindex, CHAR_Y, y); + CHAR_setInt( petindex, CHAR_PUTPETTIME, NowTime.tv_sec); + if( havepetindex == CHAR_getInt( charaindex, CHAR_DEFAULTPET)) { + int fd; + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1); + fd = getfdFromCharaIndex( charaindex); + lssproto_KS_send( fd, havepetindex, 0); + + } + CHAR_sendCToArroundCharacter( objindex); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { +#ifdef _PET_ITEM + CHAR_sendPetItemData( charaindex, havepetindex); +#endif + snprintf( szPet, sizeof( szPet ), "K%d", havepetindex ); + CHAR_sendStatusString( charaindex, szPet ); + } + + +#ifdef _PETFOLLOW_NEW_ + + int petnum; + petnum=0; + for(;petnum<5;petnum++){ + if(CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum)==-1){ + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum, petindex); + break; + } + } +#else + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, petindex); +#endif + + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWMODE, CHAR_PETFOLLOW_NOW); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_setInt( petindex, CHAR_PUTPETTIME, (int)(NowTime.tv_sec)); + CHAR_setInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "Follow()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + return 1; +} +#endif + +BOOL PET_getBaseForAllocpoint( int toindex, int *work) +{ + int LevelUpPoint=0; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET) + return FALSE; + LevelUpPoint = CHAR_getInt( toindex, CHAR_ALLOCPOINT ); + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + return TRUE; +} + +void PET_showEditBaseMsg( int charaindex, int toindex, int itemindex, int *work) +{ + int i, maxnums = 6000; + char buf1[256]; + char buf2[][32]={"ɳ",";ɳ","ٶȳɳ","ɳ",""}; + char buf3[][32]={"","Ϊ","Ϊ"}; + + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET) + return; + memset( buf1, 0, sizeof( buf1)); + + for( i=0; i<4; i++) { + int type = ITEM_getInt( itemindex, (ITEM_MODIFYATTACK + i)); +// print(" ι[%d]%d+%d ", i, work[i], type); + work[i] += type; + strcpy( buf1,"\0"); + if( work[i] > maxnums ) { + sprintf(buf1,"%s Ѿﵽˡ", buf2[i]); + work[i] = maxnums; + }else if( work[i] < 0 ) { + sprintf(buf1,"%s ѾΪˡ", buf2[i]); + work[i] = 0; + }else { + if( type > 0 ) { + if( type > 2 ) { + sprintf(buf1,"%s %s %s", buf2[i], buf3[0], ""); + }else { + sprintf(buf1,"%s %s %s", buf2[i], buf3[1], ""); + } + }else if( type < 0 ){ + sprintf(buf1,"%s %s %s", buf2[i], buf3[2], ""); + } + } + if( strcmp( buf1, "\0")) { + CHAR_talkToCli( charaindex, toindex, buf1, CHAR_COLORYELLOW); + } + } +} + +#ifdef _PET_EVOLUTION +BOOL PET_getBaseAndSkill( int charaindex, int baseindex, int *base, int *skill, int flg) +{ + int i; + if( !CHAR_CHECKINDEX( baseindex)) return FALSE; + if( base != NULL ) { + int levelup = CHAR_getInt( baseindex, CHAR_ALLOCPOINT); + base[0] = ((levelup>>24) & 0xFF); + base[1] = ((levelup>>16) & 0xFF); + base[2] = ((levelup>> 8) & 0xFF); + base[3] = ((levelup>> 0) & 0xFF); + } + + if( skill != NULL ) { + for( i=0; i= CHAR_MAXPETHAVE){ + return FALSE; + }else { + char szPet[256]; + char msgbuf[256]; + CHAR_setCharPet( charaindex, i, -1); + snprintf( szPet, sizeof( szPet ), "K%d", i); + CHAR_sendStatusString( charaindex, szPet ); + + snprintf( msgbuf,sizeof( msgbuf), "%s", CHAR_getChar( petindex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_endCharOneArray( petindex ); + } + return TRUE; +} + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet_event.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet_event.c new file mode 100644 index 0000000..21c768e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/pet_event.c @@ -0,0 +1,1001 @@ +#include "version.h" +#include +#include + +#include "common.h" +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "configfile.h" +#include "handletime.h" +#include "pet_event.h" +#include "npcutil.h" +#include "log.h" +#include "lssproto_serv.h" +// Arminius 8.14 pet talk +#include +#include "npc_exchangeman.h" +#include "npc_eventaction.h" +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#ifdef _PET_TALK +//BOOL PetTalk_CheckFree( int meindex, int toindex, char *buf); +BOOL PetTalk_CheckFree( int meindex, int talker, char *buf); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +BOOL PetTalk_BSCheck(int meindex,int talker,char* buf); +BOOL PetTalk_FreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg, int temp); +BOOL PetTalk_WarpManReduce(int meindex,int talker,char *buf); +BOOL PetTalk_BigSmallLastCheck(int point1,int mypoint,int flg); +BOOL PetTalk_CheckTrans(int meindex,int talker,int trans,int flg); +BOOL PetTalk_LevelCheck(int meindex,int talker,int level,int flg); +BOOL PetTalk_CheckMyPet( int meindex, int talker, int petLv, int flg, int petid); +BOOL PetTalk_ItemCheck(int meindex,int talker,int itemNo,int flg); +BOOL PetTalk_CheckMyType( int meindex, int toindex, int kosuu, int flg, int Type ); +BOOL PetTalk_CheckPetEvent( int meindex, int toindex, char *buf); +void PetTalk_RequestMain(int meindex,int talker,char *buf); +BOOL PetTalk_AddItem(int meindex, int talker, char *buf); +BOOL PetTalk_DelItem(int meindex,int talker,char *buf); +BOOL PetTalk_RunEvent( int meindex, int talker, char *buf); +BOOL PetTalk_CheckMyFloor( int meindex, int talker, char *buf, int flg); +#ifdef _PET_TALKBBI +BOOL PET_CheckPlayerBBI( int meindex, int charindex, int BBI, int flg); +#endif +#ifdef _PET_TALKPRO +#else +char *Pet_TalkGetFunStr( char *temp , char *buf, int len) +{ + char filename[56]; + char pathfile[128]; + char talkfun[ 10240]; + char buf1[256],buf2[256],buf3[256]; + FILE *petarg; + char *cStr=NULL; + int talkNo=1,mark=1; + char line[4096]; + BOOL find=FALSE; + talkfun[0] ='\0'; + + while( getStringFromIndexWithDelim( pettalktext,"&",talkNo, buf1, sizeof( buf1) ) != FALSE){ + talkNo++; + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PETTEMPNO", buf2, sizeof( buf2)) == NULL ) + continue; + mark=2; + strcpy( filename,"\0"); + while( getStringFromIndexWithDelim( buf2,",", mark,buf3,sizeof( buf3)) != FALSE ) { + mark ++; + if( !strcmp( buf3, temp)) { + print("\n buf2=%s",buf2); + if( getStringFromIndexWithDelim( buf2,",", 1,filename,sizeof( filename)) == FALSE ) + return NULL; + find = TRUE; + break; + } + } + if( find == TRUE ) + break; + } + if( !strcmp( filename, "\0") ) + return NULL; + + sprintf( pathfile, "%s/pettalk/%s", getNpcdir(), filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", pathfile); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + petarg = fopen( pathfile , "r" ); +} + if( petarg != NULL ) { + while( fgets( line, sizeof( line), petarg ) ) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( strlen( talkfun) != 0 ) { + if( talkfun[strlen( talkfun) -1] != '|' ) { + strcatsafe( talkfun, sizeof( talkfun), "|"); + } + } + chompex( line); + strcatsafe( talkfun, sizeof( talkfun ), line); + } + fclose( petarg); + }else { + return NULL; + } + talkNo = 1; + while( getStringFromIndexWithDelim( talkfun,"}",talkNo, buf, len) != FALSE) { + talkNo++; + if( NPC_Util_GetStrFromStrWithDelim( buf, "PETTEMPNO", buf2, sizeof( buf2)) == NULL ) + continue; + if( !strcmp( temp, buf2) ) { + cStr = buf; + break; + } + } + return( cStr); +} +#endif +void PET_Talkfunc( int meindex, int talkerindex, char *msg, int color) +{ + char buf2[1024], buf3[256]; + + char TalkType[][16]={"TALKRUN","EVENTRUN","BOTH"}; + char AllTalk[PETTALK_MAXID][1024]; + int Type=0,j,i; + int talkNo=0; + BOOL FREEs=FALSE; + int buttontype = 0; + int windowtype = 0; +#ifdef _PET_TALKPRO + int tPage=-1; +#else + int petid=-1; + char tempNo[32], buf1[10240]; +#endif + int fd = getfdFromCharaIndex( talkerindex); +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_OK; + if( NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if( NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + for( i = 0 ; i < 5 ; i++ ) { + strcpy( AllTalk[i], "\0" ); + } +#ifdef _ALLBLUES_LUA_1_5 + RunCharTalkedEvent( meindex, talkerindex, msg, color, 1); +#endif + +#ifdef _PET_TALKPRO + for( i=0;i=0 && pettalktext[i].ID == CHAR_getInt(meindex, CHAR_PETID) ) { + if( strcmp( pettalktext[i].DATA, "\0") && strlen( pettalktext[i].DATA) > 0 ) { + //snprintf( buf1, sizeof(buf1), pettalktext[i].DATA); + tPage=i; + break; + } + } + } + + if( i == PETTALK_MAXID ) + return; +#else + sprintf(tempNo,"%d", CHAR_getInt(meindex, CHAR_PETID)); + petid = CHAR_getInt(meindex, CHAR_PETID); + if( Pet_TalkGetFunStr( tempNo , buf1 , sizeof( buf1) ) == NULL ) { + return; + } +#endif + if( CHAR_getInt( meindex, CHAR_LV ) >= CHAR_getInt( meindex, CHAR_LIMITLEVEL) ) { + Type = 1; + } + //趨Ϊ˲PET + if( strcmp( CHAR_getChar( meindex, CHAR_OWNERCDKEY), CHAR_getChar( talkerindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( meindex, CHAR_OWNERCHARANAME), CHAR_getChar( talkerindex, CHAR_NAME) )){ +#ifdef _PET_TALKPRO + if( NPC_Util_GetStrFromStrWithDelim( pettalktext[tPage].DATA, "NoPlayerMsg", buf3, sizeof( buf3)) != NULL ) { +#else + if( NPC_Util_GetStrFromStrWithDelim( buf1, "NoPlayerMsg", buf3, sizeof( buf3)) != NULL ) { +#endif + }else { + sprintf(buf3,"İˣҲʶѽǻˣ"); + } + CHAR_talkToCli( talkerindex, meindex, buf3, color); + return; + } + j=0; + +#ifdef _PET_TALKPRO + while( getStringFromIndexWithDelim( pettalktext[tPage].DATA,"OVER",talkNo, buf2, sizeof( buf2) ) != FALSE){ +#else + while( getStringFromIndexWithDelim( buf1,"OVER",talkNo, buf2, sizeof( buf2) ) != FALSE){ +#endif + talkNo++; + if( ( strstr( buf2, TalkType[Type]) == NULL ) && ( strstr( buf2, TalkType[2]) == NULL ) )continue; + if( NPC_Util_GetStrFromStrWithDelim( buf2, "FLOOR", buf3, sizeof( buf3)) != NULL ) {//жϷ + if( PetTalk_CheckMyFloor( meindex, talkerindex, buf3, 0) == FALSE )continue; + } + if( NPC_Util_GetStrFromStrWithDelim( buf2, "PET", buf3, sizeof( buf3)) != NULL ) {//жϳFREE + if( PetTalk_CheckFree( meindex, meindex, buf3) != TRUE ) continue; + } + if( NPC_Util_GetStrFromStrWithDelim( buf2, "FREE", buf3, sizeof( buf3) ) == NULL)continue; + if( NPC_ActionPassCheck( meindex, talkerindex, buf3) == FALSE ) continue;//жFREE +// if( ActionNpc_CheckFree( meindex, talkerindex, buf2, 0) == FALSE ) continue; + if( PetTalk_CheckPetEvent( meindex, talkerindex, buf2) == FALSE )continue; + FREEs = TRUE; // + strcpy( AllTalk[j++], buf2 ); + if( j > PETTALK_MAXID-1 ) break; + } + talkNo = 0; + if( FREEs == FALSE) { //ȫ + j=0; +#ifdef _PET_TALKPRO + while( getStringFromIndexWithDelim( pettalktext[tPage].DATA,"OVER",talkNo, buf2, sizeof( buf2) ) != FALSE ){ +#else + while( getStringFromIndexWithDelim( buf1,"OVER",talkNo, buf2, sizeof( buf2) ) != FALSE ){ +#endif + talkNo ++; + if( strstr( buf2, "OTHER") == NULL ) continue; + if( NPC_Util_GetStrFromStrWithDelim( buf2, "TalkMsg", buf3, sizeof( buf3)) == NULL) continue; + while( getStringFromIndexWithDelim( buf3,",",j+1, AllTalk[j], sizeof( AllTalk[j]) ) != FALSE ){ + j++; + } + break; + } + } + if( j > 0 ) { + strcpy( buf2, AllTalk[ RAND( 0, (j-1) ) ] ); + if( PetTalk_RunEvent( meindex, talkerindex, buf2) == FALSE ) { + sprintf( buf3,""); + CHAR_talkToCli( talkerindex, meindex, buf3, color); + return; + } + if( NPC_Util_GetStrFromStrWithDelim( buf2, "TalkMsg", buf3, sizeof( buf3)) == NULL) { + //sprintf( buf3,"ˣȥɣ"); + strcpy( buf3, buf2); + } + + lssproto_WN_send( fd, windowtype, buttontype, 0, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), buf3 ); + } + +} + +BOOL PetTalk_CheckMyFloor( int meindex, int talker, char *buf, int flg) { + char buf1[16]; + int Myfloor=-1; + Myfloor = CHAR_getInt( talker, CHAR_FLOOR); + if( strstr( buf, "!") != NULL ) { + getStringFromIndexWithDelim( buf,"!", 2, buf1, sizeof( buf1) ); + if( Myfloor == atoi( buf1) ) { + return FALSE; + } + }else { + if( Myfloor != atoi( buf) ) { + return FALSE; + } + } + return TRUE; +} + +BOOL PetTalk_RunEvent( int meindex, int talker, char *buf) +{ + char buf1[256]; + int LimitLevel = -1; + + if( Action_RunDoEventAction( meindex, talker, buf) == FALSE ) + return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( buf, "RandItem", buf1, sizeof( buf1)) != NULL ){ + if( RAND( 0, 10) > 9 ) { + PetTalk_AddItem( meindex, talker, buf1); + }else { + return FALSE; + } + } + if( NPC_Util_GetStrFromStrWithDelim( buf, "LimitLevel", buf1, sizeof( buf1)) != NULL ){ + LimitLevel = atoi( buf1); + CHAR_setInt( meindex, CHAR_LIMITLEVEL, LimitLevel); + + } + return TRUE; + +} + +BOOL PetTalk_DelItem(int meindex,int talker,char *buf) +{ + + int i = 1, j = 1,k = 1; + char buff3[128]; + char buf2[32]; + int itemindex; + + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ) { + k++; + if(strstr(buff3,"*")!=NULL){ + int itemno; + int kosuu; + int id; + int cnt=0; + + getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); + itemno = atoi(buf2); + getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); + kosuu = atoi(buf2); +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); +#endif + for( i =0 ; +#ifdef _NEW_ITEM_ + i < itemMax +#else + i < CHAR_MAXITEMHAVE +#endif + ; i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id=ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno==id){ + cnt++; + + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "WarpManDelItem(NPCյᴫij)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + + CHAR_DelItem( talker, i); + if(cnt == kosuu){ + break; + } + } + } + } + }else{ +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); +#endif + /*--Ϸ įʧ ةë---*/ + for( j = 0 ; +#ifdef _NEW_ITEM_ + j < itemMax +#else + j < CHAR_MAXITEMHAVE +#endif + ; j++){ + itemindex = CHAR_getItemIndex( talker ,j); + + if( ITEM_CHECKINDEX(itemindex) ){ + if( atoi( buff3) == ITEM_getInt(itemindex,ITEM_ID)){ + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "WarpManDelItem(NPCյᴫij)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_DelItem( talker, j); + } + } + } + } + } + + return TRUE; +} + +BOOL PetTalk_AddItem(int meindex, int talker, char *buf) +{ + int itemID,k=1,itemindex=-1; + int spaceNum=5,i; + char buff3[256], msgbuf[64], token[256]; + int ret; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); +#endif + + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + for( i = spaceNum ; +#ifdef _NEW_ITEM_ + i = CheckCharMaxItem(talker) +#else + ret >= CHAR_MAXITEMHAVE +#endif + ) { + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return FALSE; + } + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1,token,CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + + } + return TRUE; +} + +BOOL PetTalk_CheckPetEvent( int meindex, int toindex, char *buf) +{ + char buf1[256],buf2[256]; + int k = 0; + + if( NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", buf1,sizeof( buf1) ) != NULL ) { + k=1; + while( getStringFromIndexWithDelim(buf1 , "," ,k, buf2, sizeof(buf2) ) != FALSE ){ + k++; + NPC_EventSetFlg( toindex, atoi( buf2)); + } + } + if( NPC_Util_GetStrFromStrWithDelim( buf, "NowSetFlg", buf1, sizeof( buf1)) != NULL) { + k=1 ; + while(getStringFromIndexWithDelim(buf1 , "," , k, buf2, sizeof(buf2))!= FALSE ){ + k++; + NPC_NowEventSetFlg( toindex, atoi( buf2)); + } + } + return TRUE; +} + +void PetTalk_RequestMain(int meindex,int talker,char *buf) +{ + int shiftbit; + char buf2[128]; + if( NPC_Util_GetStrFromStrWithDelim( buf,"EventNo", buf2,sizeof( buf2) ) == NULL ) { + print("\n pet_event.c err:NOT FIND [EventNo] !!"); + return; + } + shiftbit = atoi( buf2); + if( NPC_NowEventCheckFlg( talker, shiftbit) != TRUE ) { + NPC_NowEventSetFlg( talker, shiftbit); + } +} + +BOOL PetTalk_CheckFree( int meindex, int talker, char *buf) +{ + char buff2[256]; + char buff3[128]; + int i=1,j=1; + int loop=0; + while( getStringFromIndexWithDelim(buf,",",i,buff2,sizeof(buff2)) !=FALSE ) { + i++; + if(strstr(buff2,"&")!=NULL){ + j=1; + loop=0; + while( getStringFromIndexWithDelim(buff2,"&",j,buff3,sizeof(buff3)) !=FALSE ) { + j++; + if(PetTalk_BSCheck(meindex,talker,buff3)==FALSE) { + loop=1; + break; + } + } + if(loop==0) { + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + } + }else{ + if( PetTalk_BSCheck( meindex, talker, buff2) == TRUE ){ + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + } + } + } + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, FALSE ); + return FALSE; +} + +BOOL PetTalk_BSCheck(int meindex,int talker,char* buf) +{ + char buff2[128]; + int kosuu,temp=-1,flg=0; + char buff1[128],buff3[128]; + if(strstr( buf, "-") != NULL) { + //buff3ΪץID + getStringFromIndexWithDelim( buf, "-", 2, buff3, sizeof(buff3)); + temp = atoi( buff3); + getStringFromIndexWithDelim( buf, "-", 1, buff1, sizeof(buff1)); + strcpy( buf, buff1); + } + if(strstr( buf, "<") != NULL){ + getStringFromIndexWithDelim( buf, "<", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "<", 1, buff2, sizeof(buff2)); + + if(PetTalk_FreeIfCheck( meindex, talker, buff2, kosuu, 1, temp)==TRUE){ + return TRUE; + } + }else if(strstr( buf, ">") != NULL){ + getStringFromIndexWithDelim( buf, ">", 2, buff2, sizeof(buff2)); + kosuu = atoi(buff2); + getStringFromIndexWithDelim( buf, ">" ,1, buff2, sizeof(buff2)); + + if(PetTalk_FreeIfCheck( meindex, talker, buff2, kosuu, 2, temp)==TRUE){ + return TRUE; + } + }else if(strstr( buf, "!" ) != NULL){ + getStringFromIndexWithDelim( buf, "!=", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "!=", 1, buff2, sizeof(buff2)); + if(PetTalk_FreeIfCheck( meindex, talker, buff2, kosuu, 0, temp) == TRUE){ + return FALSE; + }else{ + return TRUE; + } + + }else if(strstr( buf, "=") != NULL){ + getStringFromIndexWithDelim( buf, "=", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "=", 1, buff2, sizeof(buff2)); + + if( strstr( buf, "PET")) { + flg = 3; + } + if(strstr( buf, "*") != NULL){ + if( PetTalk_WarpManReduce( meindex, talker, buf)==TRUE){ + return TRUE; + } + }else if(PetTalk_FreeIfCheck( meindex, talker, buff2, kosuu, flg, temp)==TRUE){ + return TRUE; + } + } + return FALSE; +} + +BOOL PetTalk_FreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg, int temp) +{ + int Type = -1; + if(strcmp(buf,"LV")==0){ + if(PetTalk_LevelCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } + + if( strcmp( buf, "TRANS") == 0 ) { + if( PetTalk_CheckTrans( meindex, talker, kosuu, flg) == TRUE ) + return TRUE; + } +#ifdef _GLORY_POINT + if(strcmp(buf,"GLORY")==0){ + if(NPC_ActionGloryCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif + if( strcmp( buf, "PET") == 0 ) { + if( temp > 0 ) { + if( PetTalk_CheckMyPet( meindex, talker, kosuu, flg, temp) == TRUE ) + return TRUE; + }else + return FALSE; + } + if(strcmp( buf, "ITEM")==0){ + if(PetTalk_ItemCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } + if(strcmp( buf, "ENDEV")==0){ + if(NPC_EventCheckFlg( talker, kosuu)==TRUE){ + return TRUE; + } + } + if(strcmp( buf, "NOWEV")==0){ + if(NPC_NowEventCheckFlg( talker, kosuu)==TRUE){ + return TRUE; + } + } + if(strcmp( buf, "HP" ) == 0 ) { + Type = 0; + if( PetTalk_CheckMyType( meindex, talker, kosuu, flg, Type ) == TRUE ) { + return TRUE; + } + } +#ifdef _PET_TALKBBI + if(strcmp( buf, "BBI" ) == 0 ) { + if( PET_CheckPlayerBBI( meindex, talker, kosuu, flg)== TRUE) { + return TRUE; + } + } +#endif + return FALSE; +} +BOOL PetTalk_CheckMyType( int meindex, int toindex, int kosuu, int flg, int Type ) { + int MyType=0,MyMaxType=0; + switch( Type ) { + case 0: //HP + MyType = CHAR_getInt( toindex, CHAR_HP); + MyMaxType = CHAR_getWorkInt( toindex, CHAR_WORKMAXHP); + MyMaxType = (MyMaxType * kosuu )/ 100; + if( PetTalk_BigSmallLastCheck( MyMaxType, MyType , flg ) == TRUE ) { + return TRUE; + } + break; + } + return FALSE; +} + +BOOL PetTalk_WarpManReduce(int meindex,int talker,char *buf) +{ + char buf2[512]; + char buf3[256]; + int id=0; + int i; + int itemindex; + int itemno; + int kosuu; + int cnt=0; + + getStringFromIndexWithDelim(buf,"=",2,buf2,sizeof(buf2)); + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemno = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); +#endif + for( i=0 ; +#ifdef _NEW_ITEM_ + i point1) { + return TRUE; + } + } + return FALSE; +} +#else +void PET_Talkfunc( int meindex, int talkerindex, char *msg, int color) +{ + print("\n PET_Talkfunc(...) return; "); + return; +} +#endif + +void PET_CleanFreePetAll() +{ + int objindex; + int objmaxnum = OBJECT_getNum(); + + for( objindex=0; objindex= 100 ) { + int workpindex = CHAR_getWorkInt( petindex, CHAR_WORKPLAYERINDEX); + if( act == CHAR_ACTWALK && CHAR_CHECKINDEX( workpindex) && workpindex == pindex ){ + dir = NPC_Util_GetDirCharToChar( petindex, pindex, 0); + if( dir != -1 ) { + if( CHAR_getInt( petindex, CHAR_DIR) != dir ) { + CHAR_setInt( petindex, CHAR_DIR, dir); + CHAR_sendWatchEvent( CHAR_getWorkInt( petindex, CHAR_WORKOBJINDEX), + CHAR_ACTTURN,NULL,0,TRUE); + } + } + }else if( NPC_Util_isFaceToFace( petindex, pindex, 2 ) == TRUE +#ifdef _PETFOLLOW_NEW_ + || CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOW)==petindex + || CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOW1)==petindex + || CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOW2)==petindex + || CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOW3)==petindex + || CHAR_getWorkInt( pindex, CHAR_WORKPETFOLLOW4)==petindex +#endif + ) { + switch( act) { + case CHAR_ACTATTACK: + case CHAR_ACTDAMAGE: + case CHAR_ACTDOWN: + case CHAR_ACTSTAND: + case CHAR_ACTACTIONWALK: + case CHAR_ACTGUARD: + case CHAR_ACTACTIONSTAND: + CHAR_sendWatchEvent( objmeindex, act, NULL,0,FALSE); + CHAR_setWorkInt( petindex, CHAR_WORKACTION, act); + break; + default: + break; + } + } + }else { + + } + + if( CHAR_getInt( petindex, CHAR_MAILMODE) != CHAR_PETMAIL_NONE) { + //ʲ + }else if( CHAR_getWorkInt( petindex, CHAR_WORKPETFOLLOWMODE) == CHAR_PETFOLLOW_NOW ){ + if( NowTime.tv_sec >= (petputtime + 6000*6000) ) { + int ownerindex = CHAR_getWorkInt( petindex, CHAR_WORKPLAYERINDEX); + if( CHAR_CHECKINDEX( ownerindex) ){ + if( CHAR_pickupFollowPet( ownerindex, petindex ) ) { + return; + } + CHAR_talkToCli( ownerindex, -1, "̫ãʧˣ", CHAR_COLORYELLOW ); + } +#ifdef _PET_LOSTPET + CHAR_CharSaveLostPet( petindex, 1); + LogPet( + "ϵͳ", + "Watchfunc", + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "timeout_lost(ϵͳ-ɳ)", + CHAR_getInt( petindex, CHAR_FLOOR), + CHAR_getInt( petindex,CHAR_X ), + CHAR_getInt( petindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + print("ϵͳ-ɳ:%s\n", CHAR_getUseName( petindex)); + CHAR_CharaDelete( petindex); +#else + CHAR_setInt( petindex, CHAR_PUTPETTIME, NowTime.tv_sec); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWMODE, CHAR_PETFOLLOW_NONE); + LogPet( + CHAR_getChar( pindex, CHAR_NAME ), + CHAR_getChar( pindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "timeout_lost(̫ãʧ))", + CHAR_getInt( pindex,CHAR_FLOOR), + CHAR_getInt( pindex,CHAR_X ), + CHAR_getInt( pindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + + ); +#endif + return; + } + + }else{ + PET_CHECKFreePetIsIt( petindex); + } + + + return; +} + +#ifdef _PET_TALKBBI +BOOL PET_CheckPlayerBBI( int meindex, int charindex, int BBI, int flg) +{ + int MyBBI; + if( !CHAR_CHECKINDEX( charindex)) + return FALSE; + if( BBI < 0 ) + return FALSE; + MyBBI = CHAR_getInt( charindex, CHAR_BASEIMAGENUMBER); + + if(flg==0){ + if(BBI==MyBBI) + return TRUE; + }else if(flg==1){ + if(BBI < MyBBI) + return TRUE; + }else if(flg==2){ + if(BBI > MyBBI) + return TRUE; + } + + return FALSE; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/petmail.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/petmail.c new file mode 100644 index 0000000..a8b50e5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/petmail.c @@ -0,0 +1,1162 @@ +#include "version.h" +#include + +#include "configfile.h" +#include "buf.h" +#include "char_base.h" +#include "char.h" +#include "battle.h" +#include "handletime.h" +#include "map_deal.h" +#include "addressbook.h" +#include "lssproto_serv.h" +#include "pet.h" +#include "petmail.h" +#include "npcutil.h" +#include "log.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#define PETMAIL_BATTLETIMEOUT 660 +#define PETMAIL_IDLETIMEOUT 10 +#define PETMAIL_IDLETIME 1 + +#define PETMAIL_IDLE_RETURNOWNER (60*30) +//andy_edit +//#define PETMAIL_IDLEDISCARD (60*60) //Syu ʵȴʱΪһСʱ +#define PETMAIL_IDLEDISCARD (60*3) + +/* petmail ϵĵȴʱ shan add */ +#define PETMAIL_JS_TIMEOUT (2*60) + +static int PETMAIL_getIdleTime( int index); +static void PETMAIL_sendPetmail( int index, int tocharaindex); +static void PETMAIL_IdleProc1( int index); +static void PETMAIL_IdleProc2( int index); +static void PETMAIL_IdleProc3( int index); +static void PETMAIL_IdleProc4( int index); +static void PETMAIL_IdleProc5( int index); + +static void PETMAIL_ReturnWait( int index); +static void PETMAIL_returnMail( int index, int tocharaindex); +static int PETMAIL_offmsg_max; +#define PETMAILOFFMSGFILE "petmail.txt" + +#define PETMAIL_DEFTOTALNUM 1000 +static int PetMailTotalnums = 0; + +BOOL PETMAIL_sendPetMail( int cindex, int aindex, + int havepetindex, int haveitemindex, char* text , int color ) +{ + struct tm tm1; + Char *ch; + ADDRESSBOOK_entry *ae; + int petindex; + int itemindex =-1; + int tocharaindex,playernum,i; + + //ж Ƭ + if( !CHAR_CHECKINDEX( cindex) )return FALSE; + if( haveitemindex != -1 ) { + itemindex = CHAR_getItemIndex( cindex, haveitemindex); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_CANPETMAIL) == 0 ) { + print( "err? crack?\n"); + return FALSE; + } + } + } + petindex = CHAR_getCharPet( cindex, havepetindex); + if( petindex == -1 ) return FALSE; + ch = CHAR_getCharPointer( petindex); + if( ch == NULL ) return FALSE; + ae = CHAR_getAddressbookEntry( cindex , aindex ); + if( ae == NULL )return FALSE; + +#ifdef _AVID_TRADETRYBUG //ʼ + if( CHAR_getWorkInt( cindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE ){ + CHAR_talkToCli( cindex, -1, "״̬޷ݳʼ", CHAR_COLORYELLOW ); + return FALSE; + } +#endif + // + if (CHAR_getInt( cindex, CHAR_RIDEPET) == havepetindex ){ + CHAR_talkToCli(cindex, -1, "еij޷ݳʼ", CHAR_COLORYELLOW); + return FALSE; + } + if( CHAR_getWorkInt( cindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + CHAR_talkToCli( cindex, -1, "ս״̬޷ݳʼ", CHAR_COLORYELLOW ); + return FALSE; + } + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(cindex, -1, "ػ޷ʼร", CHAR_COLORYELLOW); + return FALSE; + } +#ifdef _LOCK_PET_ITEM +{ + char *petname = CHAR_getChar( petindex, CHAR_NAME); + if( petname[0] == '*' ){ + CHAR_talkToCli(cindex, -1, "󶨳޷ʼ", CHAR_COLORYELLOW); + return FALSE; + } +} +#endif +#ifdef _SOME_PETMAIL +if (getPetMailFlg()==1){ + int flg = 0; + for (i = 0; i < 30; i++) { + if (CHAR_getInt(petindex, CHAR_PETID) == getPetMailPetid(i)) { + flg = 1; + break; + } + } + if (flg == 0) { + CHAR_talkToCli(cindex, -1, "ó޷ͳʼ", CHAR_COLORYELLOW); + return FALSE; + } +} +#endif +#ifdef _LOCK_PET_ITEM + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + CHAR_talkToCli( cindex, -1, "Ʒ޷", CHAR_COLORYELLOW ); + return FALSE; + } +#endif +// Terry add fix can send mail to offline character 2004/2/5 + if(ae->online == 0){ + CHAR_talkToCli(cindex, -1, "Ҳϣ", CHAR_COLORYELLOW); + return FALSE; + } + playernum = CHAR_getPlayerMaxNum(); + int recvindex = -1; + for(i = 0;icdkey) == 0 && + strcmp(CHAR_getChar(i,CHAR_NAME),ae->charname) == 0 ) { + recvindex=i; + break; + } + } + if(i == playernum){ + CHAR_talkToCli(cindex, -1, "Ҳڴϣ", CHAR_COLORYELLOW); + return FALSE; + } +// end +#ifdef _MAP_TIME + if((CHAR_getInt(cindex,CHAR_FLOOR) >= 30017 && CHAR_getInt(cindex,CHAR_FLOOR) <= 30021)){ + char msgbuf[512]; + snprintf(msgbuf,sizeof(msgbuf),"˵ü͵ߣ"); + CHAR_talkToCli(cindex,-1,msgbuf,CHAR_COLORWHITE); + return FALSE; + } + if((CHAR_getInt(i,CHAR_FLOOR) >= 30017 && CHAR_getInt(i,CHAR_FLOOR) <= 30021)){ + char msgbuf[512]; + snprintf(msgbuf,sizeof(msgbuf),"Էڵռ͵ߣ"); + CHAR_talkToCli(cindex,-1,msgbuf,CHAR_COLORWHITE); + return FALSE; + } +#endif + + // Syu Add 2003/05/30 + if( ( CHAR_getInt(cindex,CHAR_FLOOR) >= 8200 && CHAR_getInt(cindex,CHAR_FLOOR) <= 8213 ) ) + { + char msgbuf[512]; + snprintf( msgbuf, sizeof( msgbuf), "Ӣսü͵ߣ"); + CHAR_talkToCli( cindex, -1, msgbuf, CHAR_COLORWHITE); + return FALSE; + } + + if( ( CHAR_getInt(recvindex,CHAR_FLOOR) == 1042 + || CHAR_getInt(recvindex,CHAR_FLOOR) == 2032 + || CHAR_getInt(recvindex,CHAR_FLOOR) == 3032 + || CHAR_getInt(recvindex,CHAR_FLOOR) == 4032) ) + { + char msgbuf[512]; + snprintf( msgbuf, sizeof( msgbuf), "Էսսü͵ߣ"); + CHAR_talkToCli( cindex, -1, msgbuf, CHAR_COLORRED); + return FALSE; + } + +#ifdef _PET_LIMITLEVEL + if( CHAR_getInt( petindex, CHAR_LIMITLEVEL) > 0 ) { + CHAR_talkToCli(cindex, -1, "ﲻܴʼร", CHAR_COLORYELLOW); + return FALSE; + } +#endif + +#ifdef _PETMAIL_DEFNUMS + if( CHAR_getWorkInt( cindex, CHAR_PETMAILNUMS) > 6 ){ + CHAR_talkToCli(cindex, -1, "ʼг࣬ʱ޷ݳʼ", CHAR_COLORYELLOW); + return FALSE; + }else if( PETMAIL_CheckIsMyOffmsg( cindex, ae->cdkey, ae->charname) > 5 ){ + CHAR_talkToCli(cindex, -1, "ռĿǰʼﳬ5⣬ʱ޷ݳʼ", CHAR_COLORYELLOW); + return FALSE; + }else if( CHAR_getWorkInt( cindex, CHAR_PETMAILSENDTIME) > (int)time( NULL)){ + char Mess1[256]; + sprintf( Mess1,"ȴ%dٴμͳʼ", + (int)time( NULL) - CHAR_getWorkInt( cindex, CHAR_PETMAILSENDTIME)); + CHAR_talkToCli( cindex, -1, Mess1, CHAR_COLORYELLOW); + return FALSE; + }else if( PetMailTotalnums >= PETMAIL_DEFTOTALNUM ){ + CHAR_talkToCli(cindex, -1, "Ŀǰϵͳʼ࣬ټġ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + { +#ifdef _FIX_PETMAIL2 // WON ADD 2 + if( !PET_dropPetFLXY( cindex, havepetindex, PETMAIL_SPOOLFLOOR, PETMAIL_SPOOLX,PETMAIL_SPOOLY) ){ + CHAR_talkToCli( cindex, -1, "ʼʧ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + int offmsgindex; + offmsgindex = PETMAIL_addOffmsg( cindex, ae->cdkey, ae->charname, text, color); + if( offmsgindex == -1 ) { + print( "offmsg buffer over\n"); + return FALSE; + } + + int nums = CHAR_getWorkInt( cindex, CHAR_PETMAILNUMS); + nums ++; + CHAR_setWorkInt( cindex, CHAR_PETMAILNUMS, nums); + CHAR_setWorkInt( cindex, CHAR_PETMAILSENDTIME, (int)time( NULL)+2); + PetMailTotalnums ++; + + CHAR_setInt( petindex, CHAR_FLOOR, CHAR_getInt( cindex, CHAR_FLOOR)); + CHAR_setInt( petindex, CHAR_X, CHAR_getInt( cindex, CHAR_X)); + CHAR_setInt( petindex, CHAR_Y, CHAR_getInt( cindex, CHAR_Y)); + CHAR_sendPMEToArroundCharacter( cindex, petindex, 0, CHAR_getInt( petindex, CHAR_PETMAILEFFECT)); + CHAR_setInt( petindex, CHAR_MAILMODE,CHAR_PETMAIL_IDLE2); + CHAR_setInt( petindex, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), "PETMAIL_Loop"); + CHAR_constructFunctable( petindex); + CHAR_setInt( petindex, CHAR_PETMAILBUFINDEX, offmsgindex); + CHAR_setInt( petindex, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( petindex, CHAR_PETMAILFROMFLOOR, CHAR_getInt( cindex, CHAR_FLOOR)); + CHAR_setInt( petindex, CHAR_PETMAILFROMX, CHAR_getInt( cindex, CHAR_X)); + CHAR_setInt( petindex, CHAR_PETMAILFROMY,CHAR_getInt( cindex, CHAR_Y)); + +#ifdef _WON_PET_MAIL_LOG // WON ADD Ӽijʵ LOG + LogPet( + CHAR_getChar( cindex, CHAR_NAME ), + CHAR_getChar( cindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "Pet_Send_Mail(ij)", + CHAR_getInt( cindex,CHAR_FLOOR), + CHAR_getInt( cindex,CHAR_X ), + CHAR_getInt( cindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); +#endif + if( haveitemindex != -1 ) { + CHAR_setItemIndex( cindex, haveitemindex, -1); + CHAR_setItemIndex( petindex, CHAR_STARTITEMARRAY, itemindex); + CHAR_sendItemDataOne( cindex, haveitemindex); + LogItem( + CHAR_getChar( cindex, CHAR_NAME ), + CHAR_getChar( cindex, CHAR_CDKEY ), + itemindex, + "pm_have(->͵ĵ)", + CHAR_getInt( cindex,CHAR_FLOOR), + CHAR_getInt( cindex,CHAR_X ), + CHAR_getInt( cindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(cindex, FALSE)){ + CHAR_talkToCli(cindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + } + { + char token[256]; + tocharaindex = PETMAIL_CheckPlayerExist( petindex, 0); + sprintf( token, "ͳʼ(%s)%s", + CHAR_getUseName( petindex), CHAR_getUseName( tocharaindex) ); + CHAR_talkToCli( cindex, -1, token, CHAR_COLORYELLOW); + } + return TRUE; + } + return FALSE; +} + +static PETMAIL_offmsg * PETMAIL_offmsgbuf; +BOOL PETMAIL_initOffmsgBuffer( int count ) +{ + int size = sizeof( PETMAIL_offmsg )*count ; + FILE *fp; + char filename[256]; + char line[2048]; + int linenum = 0; + + PETMAIL_offmsgbuf = (PETMAIL_offmsg*)allocateMemory( size ); + + if( PETMAIL_offmsgbuf == NULL ) return FALSE; + + PetMailTotalnums = 0; + + memset( PETMAIL_offmsgbuf, 0,size ); + + PETMAIL_offmsg_max = count; + snprintf( filename ,sizeof( filename ) ,"%s/%s", getStoredir(), PETMAILOFFMSGFILE); + fp = fopen( filename , "rt" ); + if( fp == NULL ) return TRUE; + + while( fgets( line, sizeof( line ), fp ) != NULL ){ + char buf[1024]; + int index; + if( !getStringFromIndexWithDelim( line, "|", 1, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + index = atoi( buf); + if( index >= PETMAIL_offmsg_max ) { + print( "index over offmsg_max [%d]\n", index); + continue; + } + if( PETMAIL_offmsgbuf[index].use == TRUE) { + print( "offmsg already use index[%d]\n", index); + continue; + } + + if( !getStringFromIndexWithDelim( line, "|", 2, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + PETMAIL_offmsgbuf[index].send_tm = atoi( buf); + + if( !getStringFromIndexWithDelim( line, "|", 3, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + PETMAIL_offmsgbuf[index].color = atoi( buf); + + if( !getStringFromIndexWithDelim( line, "|", 4, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + strcpysafe( PETMAIL_offmsgbuf[index].text, + sizeof( PETMAIL_offmsgbuf[index].text), + buf); + + if( !getStringFromIndexWithDelim( line, "|", 5, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + strcpysafe( PETMAIL_offmsgbuf[index].destcd, + sizeof( PETMAIL_offmsgbuf[index].destcd), + buf); + + if( !getStringFromIndexWithDelim( line, "|", 6, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + makeStringFromEscaped(buf); + strcpysafe( PETMAIL_offmsgbuf[index].destcharname, + sizeof( PETMAIL_offmsgbuf[index].destcharname), + buf); + if( !getStringFromIndexWithDelim( line, "|", 7, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + strcpysafe( PETMAIL_offmsgbuf[index].srccd, + sizeof( PETMAIL_offmsgbuf[index].srccd), + buf); + if( !getStringFromIndexWithDelim( line, "|", 8, buf, sizeof( buf))) { + print( "read error line[%d]\n", linenum); + continue; + } + makeStringFromEscaped(buf); + strcpysafe( PETMAIL_offmsgbuf[index].srccharname, + sizeof( PETMAIL_offmsgbuf[index].srccharname), + buf); + linenum ++; + } + fclose( fp); + return TRUE; + +} + +BOOL PETMAIL_addOffmsg( int fromindex, char *tocdkey, char *tocharaname, + char *text , int color ) +{ + + int i; + + for( i = 0 ; i < PETMAIL_offmsg_max; i++ ) { + if( PETMAIL_offmsgbuf[i].use == 0 ) { + PETMAIL_offmsg *om = & PETMAIL_offmsgbuf[i]; + om->use = 1; + time( & om->send_tm ); + + strcpysafe( om->srccd , sizeof( om->srccd ), + CHAR_getChar( fromindex, CHAR_CDKEY)); + strcpysafe( om->srccharname , sizeof( om->srccharname ), + CHAR_getChar( fromindex, CHAR_NAME)); + strcpysafe( om->destcd , sizeof( om->destcd ), tocdkey ); + strcpysafe( om->destcharname , sizeof(om->destcharname), tocharaname); + strcpysafe( om->text , sizeof(om->text), text ); + om->color = color; + return i; + } + } + return -1; +} + +PETMAIL_offmsg *PETMAIL_getOffmsg( int offmsgindex) +{ + if( offmsgindex < 0 || offmsgindex >= PETMAIL_offmsg_max ) return NULL; + return &PETMAIL_offmsgbuf[offmsgindex]; +} + +BOOL PETMAIL_deleteOffmsg( int offmsgindex) +{ + if( offmsgindex < 0 || offmsgindex >= PETMAIL_offmsg_max ) return FALSE; + PETMAIL_offmsgbuf[offmsgindex].use = FALSE; + return TRUE; +} + +void PETMAIL_proc( void ) +{ + int i; + static time_t PETMAIL_check_time_store = 0; + time_t t; + time( &t ); + if( t < PETMAIL_check_time_store) return; + PETMAIL_check_time_store = t + PETMAIL_CHECK_OFFMSG_EXPIRE_INTERVAL; + for(i = 0; i < PETMAIL_offmsg_max ; i++){ + if( PETMAIL_offmsgbuf[i].use && PETMAIL_offmsgbuf[i].send_tm < ( t - PETMAIL_OFFMSG_TIMEOUT )){ + PETMAIL_offmsgbuf[i].use = FALSE; + } + } +} + +BOOL storePetmail( void) +{ + FILE *fp; + char filename[256]; + char escapebuf1[ 64],escapebuf2[ 64]; + int i; + + /* ̻ ëƻ */ + snprintf( filename ,sizeof( filename ) ,"%s/%s" , + getStoredir(), PETMAILOFFMSGFILE); + fp = fopen( filename , "wt" ); + if( fp == NULL ) return FALSE; + for(i = 0; i < PETMAIL_offmsg_max ; i++){ + if( PETMAIL_offmsgbuf[i].use ){ + fprintf( fp, "%d|%ud|%d|%s|%s|%s|%s|%s|", + i, (unsigned int)PETMAIL_offmsgbuf[i].send_tm, + PETMAIL_offmsgbuf[i].color, + PETMAIL_offmsgbuf[i].text, + PETMAIL_offmsgbuf[i].destcd, + makeEscapeString( PETMAIL_offmsgbuf[i].destcharname, + escapebuf1, sizeof( escapebuf1)), + PETMAIL_offmsgbuf[i].srccd, + makeEscapeString( PETMAIL_offmsgbuf[i].srccharname, + escapebuf2, sizeof( escapebuf2))); + } + } + fclose( fp); + return TRUE; +} + +BOOL PETMAIL_CheckPlayerExist( int index, int mode) +{ + int i; + char *searchcd = NULL; + char *searchname = NULL; + PETMAIL_offmsg *adof; + int playernum = CHAR_getPlayerMaxNum(); + + if( mode == 0 ) { + adof = PETMAIL_getOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + if( adof == NULL ) return FALSE; + searchcd = adof->destcd; + searchname = adof->destcharname; + } + else if( mode == 1 ) { + searchcd = CHAR_getChar( index, CHAR_OWNERCDKEY); + searchname = CHAR_getChar( index, CHAR_OWNERCHARANAME); + if( searchcd == "\0" || searchname == "\0" ) return FALSE; + } + for( i = 0 ; i < playernum ; i ++) { + if( CHAR_CHECKINDEX( i) && + strcmp( CHAR_getChar( i, CHAR_CDKEY), searchcd ) == 0 && + strcmp( CHAR_getChar( i, CHAR_NAME), searchname) == 0 ) { + return i; + } + } + return -1; +} + +void PETMAIL_Loopfunc( int index) +{ + int mode = CHAR_getInt( index, CHAR_MAILMODE); + switch( mode ){ + case CHAR_PETMAIL_IDLE1: + PETMAIL_IdleProc1( index); + break; + case CHAR_PETMAIL_IDLE2: + PETMAIL_IdleProc2( index); + break; + case CHAR_PETMAIL_RETURNWAIT://ȴ + PETMAIL_ReturnWait( index); + break; + case CHAR_PETMAIL_IDLE3: + PETMAIL_IdleProc3( index); + break; + case CHAR_PETMAIL_IDLE4://Ѱ + PETMAIL_IdleProc4( index); + break; + case CHAR_PETMAIL_IDLE5: //ʱ޷ҵ + PETMAIL_IdleProc5( index); + break; + default: + break; + } +} + +static int PETMAIL_getIdleTime( int index) +{ +#define PETMAIL_DIVRANGE 25 // r +#define PETMAIL_IDLELEVELRANGE 10 // ? +#define PETMAIL_IDLEUNITTIME 3 // + int d; +#ifdef _PETMAIL_TIME + int dex; + if(getPetMailTime()>0) + dex = getPetMailTime(); + else + dex = CHAR_getWorkInt( index, CHAR_WORKQUICK); +#else + int dex = CHAR_getWorkInt( index, CHAR_WORKQUICK) ; +#endif + + d = dex / PETMAIL_DIVRANGE; + if( d < 0 ) d = 0; + if( d > PETMAIL_IDLELEVELRANGE ) d = PETMAIL_IDLELEVELRANGE; + d = PETMAIL_IDLELEVELRANGE - d ; + + return d * PETMAIL_IDLEUNITTIME; + +#undef PETMAIL_DIVRANGE +#undef PETMAIL_IDLELEVELRANGE +#undef PETMAIL_IDLEUNITTIME +} + +static void PETMAIL_sendPetmail( int index, int tocharaindex) +{ + int index_to_my_info; + int itemindex,ret; + index_to_my_info = ADDRESSBOOK_getIndexInAddressbook( tocharaindex, + CHAR_getChar( index, CHAR_OWNERCDKEY), + CHAR_getChar( index, CHAR_OWNERCHARANAME)); + + if( index_to_my_info < 0 ) { + char msgbuf[512]; + + snprintf( msgbuf, sizeof( msgbuf), + "%s%s ˣ" + "춶ԷûƬż˻ˡ", + CHAR_getChar( index, CHAR_OWNERCHARANAME), + CHAR_getUseName( index)); + CHAR_talkToCli( tocharaindex, -1, msgbuf, CHAR_COLORWHITE); + } + //Syu Add 06/16 + else if( CHAR_getInt(tocharaindex,CHAR_FLOOR) >=8200 && + CHAR_getInt(tocharaindex,CHAR_FLOOR) <= 8213 ){ + char msgbuf[512]; + snprintf( msgbuf, sizeof( msgbuf), + "Ӣսü͵ߣ" ); + CHAR_talkToCli( tocharaindex, -1, msgbuf, CHAR_COLORWHITE); + } + else { + struct tm tm1; + char textbuffer[2048]; + char escapebuf[128]; + int fd; + PETMAIL_offmsg *offmsg; + itemindex = CHAR_getItemIndex( index, CHAR_STARTITEMARRAY); + ret = CHAR_addItemSpecificItemIndex( tocharaindex, itemindex); + if( ret < 0 || +#ifdef _NEW_ITEM_ + ret >= CheckCharMaxItem(tocharaindex) +#else + ret >= CHAR_MAXITEMHAVE +#endif + ){ + CHAR_DropItem( index, CHAR_STARTITEMARRAY); + LogItem( + CHAR_getChar( tocharaindex, CHAR_NAME ), + CHAR_getChar( tocharaindex, CHAR_CDKEY ), + itemindex, + "pm_putground(->õ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + else { + CHAR_setItemIndex( index, CHAR_STARTITEMARRAY, -1); + CHAR_sendItemDataOne( tocharaindex, ret); + LogItem( + CHAR_getChar( tocharaindex, CHAR_NAME ), + CHAR_getChar( tocharaindex, CHAR_CDKEY ), + itemindex, + "pm_getitem(->յĵ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + offmsg = PETMAIL_getOffmsg( + CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), + sizeof( tm1)); + snprintf( textbuffer, sizeof( textbuffer), + "%2d/%02d %2d:%02d|%s|%d|%d|%s|%d", + tm1.tm_mon +1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, + offmsg->text, + CHAR_getInt( index, CHAR_BASEIMAGENUMBER), + CHAR_getInt( index, CHAR_LV), + makeEscapeString( CHAR_getUseName( index), escapebuf, + sizeof( escapebuf)), + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER) + ); + fd = getfdFromCharaIndex( tocharaindex); + if( fd != -1 ) lssproto_MSG_send( fd , index_to_my_info , + textbuffer , offmsg->color ); + PETMAIL_deleteOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + CHAR_setInt( index, CHAR_PETMAILBUFINDEX, -1); + CHAR_setInt( index, CHAR_PETSENDMAILCOUNT, + CHAR_getInt( index, CHAR_PETSENDMAILCOUNT) +1); + { + char *cdkey = CHAR_getChar( index, CHAR_CDKEY); + if( cdkey) printl( LOG_TALK, "CDKEY=%s\tTEXT=%s" , cdkey, offmsg->text ); + else printl( LOG_TALK, "CDKEY=(null)\tTEXT=%s" , offmsg->text ); + } + } +} + +static void PETMAIL_IdleProc1( int index) +{ + + int tocharaindex; + int warp = FALSE; + + tocharaindex = PETMAIL_CheckPlayerExist( index, 0); + if( !CHAR_CHECKINDEX( tocharaindex) ) { + warp = TRUE; + }else { + if( CHAR_getInt( tocharaindex, CHAR_FLOOR) == 8215 ){//ͷ andy + warp = TRUE; + }else if( CHAR_getWorkInt( tocharaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE ){//вʼ + warp = TRUE; + }else if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ){ + int battleindex = CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEINDEX ); + if( !BATTLE_CHECKINDEX( battleindex ) +#ifdef _BATTLE_TIMESPEED + || BattleArray[battleindex].flgTime > 30 +#endif + ){ + warp = TRUE; + } + }else { + int ret; + int distance; + distance = NPC_Util_CharDistance( tocharaindex, index); + if( distance > CHAR_DEFAULTSEESIZ /2 ) { + warp = TRUE; + }else if( distance > 1 ){ + int dir = NPC_Util_GetDirCharToChar( index, tocharaindex, 0); + if( dir != -1 ) { + dir = NPC_Util_SuberiWalk( index, dir); + } + if( dir != -1 ) { + ret = CHAR_walk( index, dir, 0); + if( ret != CHAR_WALKSUCCESSED) { + dir = -1; + } + } + if( dir == -1 ) { + warp = TRUE; + } + }else { + PETMAIL_sendPetmail( index, tocharaindex); + CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_RETURNWAIT); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + } + } + } + if( warp) { + if( CHAR_getInt( index, CHAR_FLOOR) != PETMAIL_SPOOLFLOOR) { + CHAR_warpToSpecificPoint( index, + PETMAIL_SPOOLFLOOR, + PETMAIL_SPOOLX,PETMAIL_SPOOLX); + CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_IDLE2); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + } + } +} + +static void PETMAIL_IdleProc2( int index) +{ + unsigned int t = CHAR_getInt( index, CHAR_PETMAILIDLETIME); + if( NowTime.tv_sec > t + PETMAIL_getIdleTime( index)) { + int tocharaindex; + int cnt; + tocharaindex = PETMAIL_CheckPlayerExist( index, 0); + if( tocharaindex != -1 ) { + if( CHAR_getInt( tocharaindex, CHAR_FLOOR) == 8215 ){//ͷ andy + }else if( CHAR_getWorkInt( tocharaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE ){//вʼ + }else if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + }else { + int fl, x, y, ch_x, ch_y; + fl = CHAR_getInt( tocharaindex, CHAR_FLOOR); + ch_x = CHAR_getInt( tocharaindex, CHAR_X); + ch_y = CHAR_getInt( tocharaindex, CHAR_Y); + for( cnt = 0; cnt < 10; cnt ++ ) { + x = RAND( ch_x -1, ch_x + 1); + y = RAND( ch_y -1, ch_y + 1); + if( MAP_walkAble( tocharaindex, fl,x,y)) { + break; + } + } + if( cnt == 10 ) { + x = ch_x; y = ch_y; + } + CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_RETURNWAIT); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_warpToSpecificPoint( index,fl, x,y); + PETMAIL_sendPetmail( index, tocharaindex); + return; + } + }else{ + if( NowTime.tv_sec > t + PETMAIL_IDLETIMEOUT ) { + PETMAIL_deleteOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + CHAR_setInt( index, CHAR_MAILMODE, CHAR_PETMAIL_IDLE3); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL1); + } + return; + } + if( NowTime.tv_sec > t + PETMAIL_BATTLETIMEOUT ) { + PETMAIL_deleteOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + CHAR_setInt( index, CHAR_MAILMODE, CHAR_PETMAIL_IDLE3); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL1); + } + } +} + +static void PETMAIL_ReturnWait( int index) +{ + unsigned int t = CHAR_getInt( index, CHAR_PETMAILIDLETIME); + if( NowTime.tv_sec > t + PETMAIL_IDLETIME) { + CHAR_setInt( index, CHAR_MAILMODE, CHAR_PETMAIL_IDLE3); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL1); + } +} + +static void PETMAIL_IdleProc3( int index) +{ + + int tocharaindex; + int warp = FALSE; + + tocharaindex = PETMAIL_CheckPlayerExist( index, 1); + if( tocharaindex == -1 ) { + warp = TRUE; + }else { + if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE) { + int ret ; + int distance; + distance = NPC_Util_CharDistance( tocharaindex, index); + if( distance > CHAR_DEFAULTSEESIZ /2 ) { + warp = TRUE; + + }else if( distance > 1 ){ + int dir = NPC_Util_GetDirCharToChar( index, tocharaindex, 0); + if( dir != -1 ) { + dir = NPC_Util_SuberiWalk( index, dir); + } + if( dir != -1 ) { + ret = CHAR_walk( index, dir, 0); + if( ret != CHAR_WALKSUCCESSED) { + dir = -1; + } + } + if( dir == -1 ) { + warp = TRUE; + } + }else { + //andy_reEdit 2003/05/30 + warp = TRUE; +/* CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_IDLE5); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + PETMAIL_returnMail( index, tocharaindex); +*/ + } + } + } + if( warp) { + CHAR_warpToSpecificPoint( index, + PETMAIL_SPOOLFLOOR, + PETMAIL_SPOOLX,PETMAIL_SPOOLX); + CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_IDLE4); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + } +} +static void PETMAIL_IdleProc4( int index) +{ + unsigned int t = CHAR_getInt( index, CHAR_PETMAILIDLETIME); + { + int tocharaindex; + int cnt; + tocharaindex = PETMAIL_CheckPlayerExist( index, 1);//Ѱ + if( tocharaindex != -1 ) { + if( CHAR_getWorkInt( tocharaindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE && + CHAR_getWorkInt( tocharaindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_FREE ){ + + int fl, x, y, ch_x, ch_y;//ص + + fl = CHAR_getInt( tocharaindex, CHAR_FLOOR); + ch_x = CHAR_getInt( tocharaindex, CHAR_X); + ch_y = CHAR_getInt( tocharaindex, CHAR_Y); + for( cnt = 0; cnt < 10; cnt ++ ) { + x = RAND( ch_x -1, ch_x + 1); + y = RAND( ch_y -1, ch_y + 1); + if( MAP_walkAble( index, fl,x,y)) { + break; + } + } + if( cnt == 10 ) { + x = ch_x; y = ch_y; + } + CHAR_setInt( index, CHAR_MAILMODE,CHAR_PETMAIL_IDLE5); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + CHAR_warpToSpecificPoint( index,fl, x,y); + PETMAIL_returnMail( index, tocharaindex); + } + }else { + if( NowTime.tv_sec > t + PETMAIL_IDLE_RETURNOWNER ) {//ȴʱ + int itemindex; + CHAR_warpToSpecificPoint( index, //صԭ + CHAR_getInt( index, CHAR_PETMAILFROMFLOOR), + CHAR_getInt( index, CHAR_PETMAILFROMX), + CHAR_getInt( index, CHAR_PETMAILFROMY)); + + CHAR_setInt( index, CHAR_MAILMODE, CHAR_PETMAIL_IDLE5);//ı״̬ + CHAR_setInt( index, CHAR_LOOPINTERVAL, PETMAIL_LOOPINTERVAL2); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, NowTime.tv_sec); + if( CHAR_getInt( index, CHAR_PETMAILIDLETIME) != -1 ) { + PETMAIL_deleteOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + } + itemindex = CHAR_getItemIndex( index, CHAR_STARTITEMARRAY);//ɾ + if( ITEM_CHECKINDEX( itemindex ) ) { + CHAR_DropItem( index, CHAR_STARTITEMARRAY); + + LogItem( + CHAR_getChar( index, CHAR_OWNERCHARANAME ), + CHAR_getChar( index, CHAR_OWNERCDKEY ), + itemindex, + "pm_returntimeout(->ʱɾ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + } + } + } + +} + +static void PETMAIL_IdleProc5( int index) +{ + unsigned int t = CHAR_getInt( index, CHAR_PETMAILIDLETIME); + if( NowTime.tv_sec > t + PETMAIL_IDLEDISCARD) { + Char *ch; + CHAR_setInt( index, CHAR_MAILMODE, CHAR_PETMAIL_NONE); + CHAR_setInt( index, CHAR_PETMAILIDLETIME, 0); + +#ifdef _FIX_PETMAIL // WON ADD + CHAR_setInt( index, CHAR_PUTPETTIME, NowTime.tv_sec ); +#endif +#ifdef _PETMAIL_DEFNUMS + PETMAIL_delPetMailTotalnums( 1); //M PET ɳ + if( PetMailTotalnums < 0 ) PetMailTotalnums = 0; +#endif + ch = CHAR_getCharPointer( index); + if( ch != NULL ) { + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), "" ); + CHAR_constructFunctable( index); + } +#ifdef _PET_LOSTPET + CHAR_CharSaveLostPet( index, 2); + LogPet( + "ϵͳ", + "Watchfunc", + CHAR_getChar( index, CHAR_NAME), + CHAR_getInt( index, CHAR_LV), + "timeout_lost(ϵͳ-ɳ)", + CHAR_getInt( index, CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + CHAR_getChar( index, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + print("ϵͳ-ɳ:%s\n", CHAR_getUseName( index)); + CHAR_CharaDelete( index); +#else + LogPet( + CHAR_getChar( index, CHAR_OWNERCHARANAME ), + CHAR_getChar( index, CHAR_OWNERCDKEY ), + CHAR_getChar( index, CHAR_NAME), + CHAR_getInt( index, CHAR_LV), + "FreePet(ʱɳ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + CHAR_getChar( index, CHAR_UNIQUECODE) + ); +#endif + + }else { + int tocharaindex = PETMAIL_CheckPlayerExist( index, 1); + if( tocharaindex != -1 ) { + if( NPC_Util_CharDistance( tocharaindex, index ) > CHAR_DEFAULTSEESIZ/2) { + int fl, x, y, ch_x, ch_y; + int cnt; + fl = CHAR_getInt( tocharaindex, CHAR_FLOOR); + ch_x = CHAR_getInt( tocharaindex, CHAR_X); + ch_y = CHAR_getInt( tocharaindex, CHAR_Y); + for( cnt = 0; cnt < 10; cnt ++ ) { + x = RAND( ch_x -1, ch_x + 1); + y = RAND( ch_y -1, ch_y + 1); + if( MAP_walkAble( index, fl,x,y)) { + break; + } + } + if( cnt == 10 ) { + x = ch_x; y = ch_y; + } + CHAR_warpToSpecificPoint( index,fl, x,y); + } + } + } +} + +static void PETMAIL_returnMail( int index, int tocharaindex) +{ + char msgbuf[512]; + int itemindex = CHAR_getItemIndex( index, CHAR_STARTITEMARRAY); + if( ITEM_CHECKINDEX( itemindex ) ) { + int ret = CHAR_addItemSpecificItemIndex( tocharaindex, itemindex); + + if( ret < 0 || +#ifdef _NEW_ITEM_ + ret >= CheckCharMaxItem(tocharaindex) +#else + ret >= CHAR_MAXITEMHAVE +#endif + ){ + CHAR_DropItem( index, CHAR_STARTITEMARRAY); + + LogItem( + CHAR_getChar( tocharaindex, CHAR_NAME ), + CHAR_getChar( tocharaindex, CHAR_CDKEY ), + itemindex, + "pm_returnputground(->߷õ)", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + }else { + CHAR_setItemIndex( index, CHAR_STARTITEMARRAY, -1); + CHAR_sendItemDataOne( tocharaindex, ret); + } + } + +#ifdef _PETMAIL_DEFNUMS + { + int petmailnums = CHAR_getWorkInt( tocharaindex, CHAR_PETMAILNUMS); + petmailnums--; + if( petmailnums < 0 ) petmailnums = 0; + CHAR_setWorkInt( tocharaindex, CHAR_PETMAILNUMS, petmailnums); + } +#endif + if( CHAR_getInt( index, CHAR_PETMAILBUFINDEX) != -1 ) { + snprintf( msgbuf, sizeof( msgbuf), + "%s ˣ" + "ƺ޷ż", + CHAR_getUseName( index)); + CHAR_talkToCli( tocharaindex, -1, msgbuf, CHAR_COLORWHITE); + PETMAIL_deleteOffmsg( CHAR_getInt( index, CHAR_PETMAILBUFINDEX)); + }else { + snprintf( msgbuf, sizeof( msgbuf), + "%s ˣ", CHAR_getUseName( index)); + CHAR_talkToCli( tocharaindex, -1, msgbuf, CHAR_COLORWHITE); + } + +#ifdef _PETMAIL_DEFNUMS + CHAR_AutoPickupMailPet( tocharaindex, index); +#endif + +} + + +#ifdef _PETMAIL_DEFNUMS +void CHAR_AutoPickupMailPet( int charaindex, int petindex ) +{ + int objindex; + int havepetindex; + char category[3]; + Char *ch; + if( !CHAR_CHECKINDEX( charaindex ) ) return; +#ifdef _AVID_TRADETRYBUG // + if( CHAR_getWorkInt( charaindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE ){ + CHAR_talkToCli( charaindex, -1, "״̬޷Զʰʼ", CHAR_COLORYELLOW ); + return; + } +#endif + if( !CHAR_CHECKINDEX( petindex ) ) return; + havepetindex = CHAR_getCharPetElement( charaindex); + if( havepetindex == -1 ) { + + CHAR_talkToCli(charaindex,-1,"޷Զʰʼ",CHAR_COLORYELLOW); + // WON ADD + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "Pet_Full(޷ʰ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + return; + } + ch = CHAR_getCharPointer( petindex); + if( ch == NULL ) return; + + objindex = CHAR_getWorkInt( petindex, CHAR_WORKOBJINDEX ); + CHAR_ObjectDelete(objindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setCharPet( charaindex, havepetindex, petindex); + + CHAR_setChar( petindex, CHAR_OWNERCDKEY, CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, CHAR_getChar( charaindex, CHAR_NAME)); + + snprintf( category,sizeof( category),"K%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + snprintf( category,sizeof( category),"W%d",havepetindex); + CHAR_sendStatusString( charaindex, category); + + CHAR_setInt( petindex, CHAR_PUTPETTIME, 0); + CHAR_setWorkInt( petindex, CHAR_WORKOBJINDEX, -1); + CHAR_setInt( petindex, CHAR_MAILMODE, CHAR_PETMAIL_NONE); + PETMAIL_delPetMailTotalnums( 1); // M PET Զ + + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]),""); + CHAR_setInt( petindex, CHAR_LOOPINTERVAL, 0); + CHAR_constructFunctable( petindex); + CHAR_complianceParameter( petindex ); + + if( PetMailTotalnums < 0 ) PetMailTotalnums = 0; + { + char mesg[256]; + char *p = NULL; + p = CHAR_getChar( petindex, CHAR_USERPETNAME); + if( strlen( p) == 0 ) { + p = CHAR_getChar( petindex, CHAR_NAME); + } + snprintf( mesg,sizeof(mesg), "ʰʼ %s", p); + CHAR_talkToCli(charaindex,-1,mesg,CHAR_COLORYELLOW); + } + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "PickupMailPet(Զջʳ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + return; +} +#endif + +int PETMAIL_getPetMailTotalnums() +{ +#ifdef _PETMAIL_DEFNUMS + if( PetMailTotalnums < 0 ) PetMailTotalnums = 0; + if( PetMailTotalnums >= PETMAIL_DEFTOTALNUM ) PetMailTotalnums = PETMAIL_DEFTOTALNUM; + return PetMailTotalnums; +#else + return 0; +#endif +} + +void PETMAIL_delPetMailTotalnums( int numflg) +{ +#ifdef _PETMAIL_DEFNUMS + PetMailTotalnums = PetMailTotalnums - numflg; + if( PetMailTotalnums < 0 ) PetMailTotalnums = 0; +#endif +} + +void PETMAIL_setPetMailTotalnums( int numflg) +{ + PetMailTotalnums = numflg; + if( PetMailTotalnums < 0 ) PetMailTotalnums = 0; + if( PetMailTotalnums > PETMAIL_DEFTOTALNUM+10 ) PetMailTotalnums = PETMAIL_DEFTOTALNUM + 5; +} + + +int PETMAIL_CheckIsMyOffmsg( int fromindex, char *tocdkey, char *tocharaname) +{ + int i, nums=0; + for( i = 0 ; i < PETMAIL_offmsg_max; i++ ) { + if( PETMAIL_offmsgbuf[i].use == 0 ) continue; + if( !strcmp( tocdkey, PETMAIL_offmsgbuf[i].destcd) && + !strcmp( tocharaname, PETMAIL_offmsgbuf[i].destcharname) ){ + nums++; + } + } + return nums; +} + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/skill.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/skill.c new file mode 100644 index 0000000..dd97a96 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/skill.c @@ -0,0 +1,644 @@ +#include "version.h" +#include +#include +#include + +#include "skill.h" +#include "util.h" +#include "char.h" + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#include "battle.h" +#include "profession_skill.h" +#endif + + +static SKILL_intDataSetting SKILL_setint[SKILL_DATAINTNUM]={ + {"lv"}, /* SKILL_LEVEL */ + {"id"}, /* SKILL_ID */ +}; + +static SKILL_charDataSetting SKILL_setchar[SKILL_DATACHARNUM]={ +}; + + + + +static char SKILL_dataString[STRINGBUFSIZ]; + +char* SKILL_makeStringFromSkillData( Skill* sk ) +{ + int i; + int strlength=0; + + for( i = 0 ; i < SKILL_DATAINTNUM ; i ++ ){ + char linedata[128]; + snprintf( linedata , sizeof(linedata), + "%s=%d" NONCHAR_DELIMITER, + SKILL_setint[i].dumpskill, sk->data[i] ); + + strcpysafe( &SKILL_dataString[strlength], + sizeof( SKILL_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( SKILL_dataString ) )goto RETURN; + } + + for( i = 0 ; i < SKILL_DATACHARNUM ; i ++ ){ + char linedata[128]; + char escapebuffer[128]; + snprintf( linedata, sizeof(linedata), + "%s=%s" NONCHAR_DELIMITER, + SKILL_setchar[i].dumpskill, + makeEscapeString(sk->string[i].string,escapebuffer, + sizeof(escapebuffer))); + + strcpysafe( &SKILL_dataString[strlength], + sizeof( SKILL_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( SKILL_dataString ) )goto RETURN; + } + +RETURN: + dchop( SKILL_dataString , NONCHAR_DELIMITER ); + + return SKILL_dataString; +} + + +BOOL SKILL_makeSkillFromStringToArg( char* src, Skill* sk ) +{ + int readindex=1; + while( 1 ){ + BOOL ret; + char linebuf[512]; + char first[256]; + char second[256]; + int i; + + + ret = getStringFromIndexWithDelim( src ,NONCHAR_DELIMITER , + readindex, + linebuf, sizeof( linebuf ) ); + if( ret == FALSE ) + break; + + ret = getStringFromIndexWithDelim( linebuf ,"=", 1, + first, sizeof( first ) ); + if( ret == FALSE ) return FALSE; + strcpysafe( second , sizeof( second ), + linebuf + strlen(first) + strlen("=") ); + + for( i = 0 ; i < SKILL_DATAINTNUM ; i ++ ){ + if( strcmp(first ,SKILL_setint[i].dumpskill) == 0 ){ + sk->data[i] = atoi( second ); + goto NEXT; + } + } + + for( i = 0 ; i < SKILL_DATACHARNUM ; i ++ ){ + if( strcmp(first ,SKILL_setchar[i].dumpskill) == 0 ){ + strcpysafe( sk->string[i].string, + sizeof(sk->string[i].string), + makeStringFromEscaped(second) ); + goto NEXT; + } + } + + fprint( "3??? : %s[%s]\n" , linebuf, first ); + + NEXT: + readindex++; + } + + return TRUE; +} + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +INLINE int SKILL_getRealInt( Skill* skill, int element) +{ + return skill->data[element]; +} +#endif + +INLINE int SKILL_getInt( Skill* skill, int element) +{ + int value = skill->data[element]; + + if( element == SKILL_LEVEL ) value /= 100; + + return value; +} + + +INLINE int SKILL_setInt( Skill* skill, int element, int new) +{ + int buf = SKILL_getInt( skill, element ); + skill->data[element] = new; + return buf; +} + +#ifndef _PROFESSION_SKILL // WON ADD ְҵ +static void SKILL_setitemlimit( int charaindex, Skill* sk ); +static void SKILL_setmerchant( int charaindex, Skill* sk ); +static void SKILL_setlevel( int charaindex, Skill* sk ); +#endif + +static SKILL_table SKILL_tbl[]={ + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + { 100, NULL}, // 1 + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, + { 100, NULL}, // 16 +#else + {8,SKILL_setlevel}, /* SKILL_FIRE */ + {4,NULL}, /* SKILL_MAGICIAN */ + {4,NULL}, /* SKILL_PREIST */ + {8,SKILL_setitemlimit}, /* SKILL_ALOTOFTHINGS */ + {8,NULL}, /* SKILL_AVOIDRATEUP */ + {4,SKILL_setlevel}, /* SKILL_DETERMINEITEM */ + {5,SKILL_setlevel}, /* SKILL_DETERMINEOTHERS */ + {8,SKILL_setmerchant}, /* SKILL_MERCHANT */ + {8,SKILL_setlevel}, /* SKILL_HEALER */ + {8,SKILL_setlevel}, /* SKILL_LARGEVOICE */ +#endif +}; + + +#ifndef _PROFESSION_SKILL // WON ADD ְҵ +static void SKILL_setitemlimit( int charaindex, Skill* sk ) +{ + static int itemlimit[9]={ + 7 + 8 + 4*0, + 7 + 8 + 4*1, + 7 + 8 + 4*2, + 7 + 8 + 4*3, + 7 + 8 + 4*4, + 7 + 8 + 4*5, + 7 + 8 + 4*6, + 7 + 8 + 4*7, + 7 + 8 + 4*8, + }; + int level; + if( !CHAR_CHECKINDEX(charaindex) )return; + if( sk->data[SKILL_IDENTITY] != SKILL_ALOTOFTHINGS )return; + level = sk->data[SKILL_LEVEL]; + if( level < 0 )level = 0; + if( level>=arraysizeof(itemlimit) ) level=arraysizeof(itemlimit) - 1; +} + + +static void SKILL_setmerchant( int charaindex, Skill* sk ) +{ + int level; + int merchantlevel=0; + + if( !CHAR_CHECKINDEX(charaindex) )return; + if( sk->data[SKILL_IDENTITY] != SKILL_MERCHANT )return; + + level = sk->data[SKILL_LEVEL]; + if( level < 0 )level = 0; + if( level >= SKILL_tbl[sk->data[SKILL_IDENTITY]].maxlevel ) + level = SKILL_tbl[sk->data[SKILL_IDENTITY]].maxlevel; + + SETHIGHVALUE(merchantlevel,(100 - level*5)); + SETLOWVALUE(merchantlevel,(20 + level*5)); + + CHAR_setInt( charaindex,CHAR_MERCHANTLEVEL,merchantlevel ); +} + + +static void SKILL_setlevel( int charaindex, Skill* sk ) +{ + static struct skillvalset + { + SKILL_ID id; + CHAR_DATAINT charadataindex; + } skvalset[] = { + { SKILL_DETERMINEITEM, CHAR_DETERMINEITEM }, + { SKILL_DETERMINEOTHERS, CHAR_RADARSTRENGTH }, + { SKILL_HEALER, CHAR_HEALERLEVEL }, + { SKILL_LARGEVOICE, CHAR_CHATVOLUME }, + }; + int id; + int i; + int index=-1; + int level; + + if( !CHAR_CHECKINDEX(charaindex) )return; + id = sk->data[SKILL_IDENTITY]; + for( i=0 ; idata[SKILL_LEVEL]; + if( level < 0 )level = 0; + if( level >= SKILL_tbl[id].maxlevel ) + level = SKILL_tbl[id].maxlevel; + + CHAR_setInt(charaindex,skvalset[index].charadataindex,level ); +} +#endif + + + + + +#define SKILLSTRINGBUFSIZ 256 + +static char ITEM_statusStringBuffer[SKILLSTRINGBUFSIZ]; + + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +char* SKILL_makeSkillStatusString( Skill* skill, int charaindex, int skill_num ) +{ + int skillindex=SKILL_getInt( skill,SKILL_IDENTITY); + int Pskill=PROFESSION_SKILL_getskillArray( skillindex); + int skill_level=0, cost_mp=0; + + // \ܵȼ + skill_level = SKILL_getInt( skill, SKILL_LEVEL); + + // ķMP + if( (cost_mp = PROFESSION_MAGIC_COST_MP( charaindex, skill_num )) == -1 ) + cost_mp = PROFESSION_SKILL_getInt( Pskill, PROFESSION_SKILL_COST_MP); + + snprintf( ITEM_statusStringBuffer, sizeof( ITEM_statusStringBuffer ), + "%d|%d|%d|%d|%d|%d|%d|%s|%s", + PROFESSION_SKILL_getInt( Pskill, PROFESSION_SKILL_USE_FLAG), + SKILL_getInt(skill,SKILL_IDENTITY), + PROFESSION_SKILL_getInt( Pskill, PROFESSION_SKILL_TARGET), + PROFESSION_SKILL_getInt( Pskill, PROFESSION_SKILL_KIND), + PROFESSION_SKILL_getInt( Pskill, PROFESSION_SKILL_ICON), + cost_mp, + skill_level, + PROFESSION_SKILL_getChar( Pskill, PROFESSION_SKILL_NAME), + PROFESSION_SKILL_getChar( Pskill, PROFESSION_SKILL_TXT) ); + + return ITEM_statusStringBuffer; +} +#else +char* SKILL_makeSkillStatusString( Skill* skill ) +{ + snprintf( ITEM_statusStringBuffer, + sizeof( ITEM_statusStringBuffer ), + "%d|%d", + SKILL_getInt(skill,SKILL_IDENTITY), + SKILL_getInt(skill,SKILL_LEVEL) ); + + + return ITEM_statusStringBuffer; +} +#endif + + + +char* SKILL_makeSkillFalseString( void ) +{ + snprintf( ITEM_statusStringBuffer, + sizeof( ITEM_statusStringBuffer ), + "|" ); + return ITEM_statusStringBuffer; +} + + +BOOL SKILL_CHECKID( int skillid ) +{ + if( SKILL_NUM <= skillid && skillid > 0 )return FALSE; + return TRUE; +} + +BOOL SKILL_makeSkillData( Skill* sk ,int skid, int lev ) +{ + sk->data[SKILL_LEVEL] = lev; + sk->data[SKILL_IDENTITY] = skid; + + return TRUE; +} + +int SKILL_levelup( Skill* sk ) +{ + int id = sk->data[SKILL_IDENTITY]; + if( !SKILL_CHECKID(id) )return -1; + sk->data[SKILL_LEVEL] ++; + sk->data[SKILL_LEVEL] = min( sk->data[SKILL_LEVEL], + SKILL_tbl[id].maxlevel ); + return TRUE; +} + +int SKILL_getLevelFromSkillID( int charaindex, SKILL_ID id ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex) )return -1; + for( i=0 ; iuse && sk->skill.data[SKILL_IDENTITY] == id ) + return sk->skill.data[SKILL_LEVEL]; + + } + return -1; +} + +BOOL SKILL_getUpableSkillID( int charaindex,char* buf, int buflen ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex)) return FALSE; + if( buflen <= 0 )return FALSE; + buf[0] = '\0'; + for( i=0 ; iuse + && SKILL_CHECKID(chsk->skill.data[SKILL_IDENTITY]) + && chsk->skill.data[SKILL_LEVEL] + < SKILL_tbl[chsk->skill.data[SKILL_IDENTITY]].maxlevel ){ + char tmpbuf[512]; + snprintf( tmpbuf,sizeof(tmpbuf),"%d|", + chsk->skill.data[SKILL_IDENTITY] ); + strcatsafe( buf, buflen,tmpbuf ); + } + } + dchop(buf,"|"); + return TRUE; +} + +void SKILL_skillEffect( int charaindex ) +{ + int i; + if( !CHAR_CHECKINDEX(charaindex) )return; + + if( CHAR_getInt(charaindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) + return; + + for( i=0 ; iuse == FALSE )continue; + + skill = &cskill->skill; + id = skill->data[SKILL_IDENTITY]; + if( !SKILL_CHECKID(id) )continue; + + skfunc = (SKILLEFFECTFUNC)SKILL_tbl[id].effectfunc; + if( skfunc )skfunc(charaindex,skill); + } +} + + + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +// ȡʹħķMP +int PROFESSION_MAGIC_COST_MP( int charaindex, int skill_num ) +{ + int skill_level=0, dec_mp=0; + int Pskillid, skillid; + char *skill_name; + CHAR_HaveSkill* hskill; + + // \ + skillid = CHAR_getCharSkill( charaindex, skill_num); + Pskillid = PROFESSION_SKILL_getskillArray( skillid); + if( Pskillid == -1 ) return FALSE; + + // + skill_name = PROFESSION_SKILL_getChar( Pskillid, PROFESSION_SKILL_FUNCNAME); + + // ܵȼ + hskill = CHAR_getCharHaveSkill( charaindex, skill_num ); + skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_M( skill_level ); + + if( (strcmp( skill_name, "PROFESSION_VOLCANO_SPRINGS" )) == 0 ){ // ɽȪ + if( skill_level >= 10 ) dec_mp = 35; + else if( skill_level >= 7 ) dec_mp = 30; + else if( skill_level >= 5 ) dec_mp = 20; + else if( skill_level >= 3 ) dec_mp = 15; + else dec_mp = 10; + }else + if( (strcmp( skill_name, "PROFESSION_FIRE_BALL" )) == 0 ){ // + if( skill_level >= 9 ) dec_mp = 50; + else if( skill_level >= 7 ) dec_mp = 45; + else if( skill_level >= 5 ) dec_mp = 40; + else if( skill_level >= 3 ) dec_mp = 35; + else dec_mp = 30; + }else + if( (strcmp( skill_name, "PROFESSION_SUMMON_THUNDER" )) == 0 ){ // + if( skill_level >= 8 ) dec_mp = 30; + else if( skill_level >= 5 ) dec_mp = 25; + else if( skill_level >= 3) dec_mp = 20; + else dec_mp = 10; + }else + if( (strcmp( skill_name, "PROFESSION_CURRENT" )) == 0 ){ // +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ) dec_mp = 100; + else if( skill_level > 9 ) dec_mp = 90; + else if( skill_level > 8 ) dec_mp = 80; + else if( skill_level > 7 ) dec_mp = 70; + else if( skill_level > 6 ) dec_mp = 60; + else if( skill_level > 4 ) dec_mp = 50; + else if( skill_level > 2 ) dec_mp = 40; + else dec_mp = 30; +#else + if( skill_level >= 9 ) dec_mp = 80; + else if( skill_level >= 7 ) dec_mp = 60; + else if( skill_level >= 5 ) dec_mp = 50; + else if( skill_level >= 3 ) dec_mp = 40; + else dec_mp = 30; +#endif + }else + if( (strcmp( skill_name, "PROFESSION_STORM" )) == 0 ){ // +#ifdef _PROFESSION_ADDSKILL + if( skill_level > 8 ) dec_mp = 50; + else if( skill_level > 6 ) dec_mp = 45; + else if( skill_level > 4 ) dec_mp = 40; + else if( skill_level > 2 ) dec_mp = 35; + else dec_mp = 30; +#else + if( skill_level >= 10 ) dec_mp = 80; + else if( skill_level >= 6 ) dec_mp = 70; + else if( skill_level >= 5 ) dec_mp = 60; + else dec_mp = 50; +#endif + }else + if( (strcmp( skill_name, "PROFESSION_ICE_ARROW" )) == 0 ){ // + if( skill_level >= 8) dec_mp = 20; + else if( skill_level >= 4 ) dec_mp = 15; + else dec_mp = 10; + }else + if( (strcmp( skill_name, "PROFESSION_ICE_CRACK" )) == 0 ){ // +#ifdef _PROFESSION_ADDSKILL + if( skill_level >= 10 ) dec_mp = 80; + else if( skill_level > 8 ) dec_mp = 70; + else if( skill_level > 6 ) dec_mp = 60; + else if( skill_level > 4 ) dec_mp = 50; + else if( skill_level > 2 ) dec_mp = 40; + else dec_mp = 30; +#else + if( skill_level >= 9 ) dec_mp = 70; + else if( skill_level >= 7 ) dec_mp = 60; + else if( skill_level >= 5 ) dec_mp = 50; + else if( skill_level >= 3 ) dec_mp = 40; + else dec_mp = 30; +#endif + }else + if( (strcmp( skill_name, "PROFESSION_DOOM" )) == 0 ){ // ĩ + if( skill_level > 8 ) dec_mp = 150; + else if( skill_level > 4 ) dec_mp = 100; + else dec_mp = 50; + }else + if( (strcmp( skill_name, "PROFESSION_FIRE_SPEAR" )) == 0 ){ // ǹ + if( skill_level > 8 ) dec_mp = 80; + else if( skill_level > 6 ) dec_mp = 70; + else if( skill_level > 4 ) dec_mp = 60; + else if( skill_level > 2 ) dec_mp = 40; + else dec_mp = 30; + }else + if( (strcmp( skill_name, "PROFESSION_BLOOD_WORMS" )) == 0 ){ // Ѫ + if( skill_level >= 10 ) dec_mp = 15; + else if( skill_level >= 5 ) dec_mp = 10; + else dec_mp = 5; + }else + if( (strcmp( skill_name, "PROFESSION_SIGN" )) == 0 ){ // һѪ + + if( skill_level >= 8 ) dec_mp = 10; + else dec_mp = 5; + + }else + if( (strcmp( skill_name, "PROFESSION_ENCLOSE" )) == 0 ){ // + if( skill_level >= 10 ) dec_mp = 80; + else if( skill_level >= 8 ) dec_mp = 70; + else if( skill_level >= 5) dec_mp = 60; + else dec_mp = 50; + }else + if( (strcmp( skill_name, "PROFESSION_ICE_MIRROR" )) == 0 ){ // + if( skill_level >= 9 ) dec_mp = 40; + else if( skill_level >= 7 ) dec_mp = 35; + else if( skill_level >= 5 ) dec_mp = 30; + else if( skill_level >= 3 ) dec_mp = 25; + else dec_mp = 20; + }else + if( (strcmp( skill_name, "PROFESSION_FIRE_ENCLOSE" )) == 0 ){ // + if( skill_level >= 10 ) dec_mp = 50; + else if( skill_level >= 7 ) dec_mp = 40; + else if( skill_level >= 4 ) dec_mp = 30; + else dec_mp = 20; + }else + if( (strcmp( skill_name, "PROFESSION_ICE_ENCLOSE" )) == 0 ){ // + if( skill_level >= 10 ) dec_mp = 50; + else if( skill_level >= 7 ) dec_mp = 40; + else if( skill_level >= 4 ) dec_mp = 30; + else dec_mp = 20; + }else + if( (strcmp( skill_name, "PROFESSION_THUNDER_ENCLOSE" )) == 0 ){ // ׸ + if( skill_level >= 10 ) dec_mp = 50; + else if( skill_level >= 7 ) dec_mp = 40; + else if( skill_level >= 4 ) dec_mp = 30; + else dec_mp = 20; + }else + if( (strcmp( skill_name, "PROFESSION_TRANSPOSE" )) == 0 ){ // λλ + if( skill_level >= 10 ) dec_mp = 50; + else if( skill_level >= 9 ) dec_mp = 40; + else if( skill_level >= 7 ) dec_mp = 30; + else if( skill_level >= 4 ) dec_mp = 20; + else dec_mp = 10; + }else +#ifdef _PROFESSION_ADDSKILL + if( (strcmp( skill_name, "PROFESSION_RESIST_F_I_T" )) == 0 ){ // Ȼ + if( skill_level >= 10 ) dec_mp = 20; + else if( skill_level >= 9 ) dec_mp = 15; + else if( skill_level >= 6 ) dec_mp = 10; + else dec_mp = 5; + }else + if( (strcmp( skill_name, "PROFESSION_CALL_NATURE" )) == 0 ){ // Ȼ + + /*skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL); + if( skill_level >= 100 ) dec_mp = 50; + else if( skill_level > 95 ) dec_mp = 50; + else if( skill_level > 90 ) dec_mp = 50; + else if( skill_level > 85 ) dec_mp = 50; + else if( skill_level > 80 ) dec_mp = 50; + else if( skill_level > 60 ) dec_mp = 50; + else if( skill_level > 40 ) dec_mp = 50; + else if( skill_level > 20 ) dec_mp = 50; + else dec_mp = 50;*/ + dec_mp = 50; + }else + if( (strcmp( skill_name, "PROFESSION_BOUNDARY" )) == 0 ){ // Խ + char *pszP=NULL; + if( skill_level > 9 ) dec_mp = 20; + else if( skill_level > 6 ) dec_mp = 15; + else dec_mp = 10; + //Ƴmp粻ͬ + if( (pszP = strstr( PROFESSION_SKILL_getChar( Pskillid, PROFESSION_SKILL_OPTION), "ƽ" ) ) != NULL ){// ܵIJ + if( skill_level >= 9 ) dec_mp = 20; + else if( skill_level > 4 ) dec_mp = 15; + else if( skill_level > 2 ) dec_mp = 10; + else dec_mp = 5; + } + }else +#endif + { + return -1; + } + + return dec_mp; +} + + +INLINE int PROFESSION_CHANGE_SKILL_LEVEL_M( int skill_level ) +{ + if( skill_level > 90 )skill_level = 10; + else if( skill_level > 80 ) skill_level = 9; + else if( skill_level > 70 ) skill_level = 8; + else if( skill_level > 60 ) skill_level = 7; + else if( skill_level > 50 ) skill_level = 6; + else if( skill_level > 40 ) skill_level = 5; + else if( skill_level > 30 ) skill_level = 4; + else if( skill_level > 20 ) skill_level = 3; + else if( skill_level > 10 ) skill_level = 2; + else skill_level = 1; + + return skill_level; +} + + +INLINE int PROFESSION_CHANGE_SKILL_LEVEL_A( int skill_level ) +{ + if( skill_level >= 100 ) skill_level = 10; + else if( skill_level > 90 ) skill_level = 9; + else if( skill_level > 80 ) skill_level = 8; + else if( skill_level > 70 ) skill_level = 7; + else if( skill_level > 60 ) skill_level = 6; + else if( skill_level > 50 ) skill_level = 5; + else if( skill_level > 40 ) skill_level = 4; + else if( skill_level > 30 ) skill_level = 3; + else if( skill_level > 20 ) skill_level = 2; + else if( skill_level > 10 ) skill_level = 1; + else skill_level = 0; + + return skill_level; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/title.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/title.c new file mode 100644 index 0000000..d9ed7ca --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/title.c @@ -0,0 +1,1111 @@ +#include "version.h" +#include +#include +#include +#include +#ifdef _REDHAT_V9 +#include +#endif +#include "autil.h" +#include "title.h" +#include "char.h" +#include "char_base.h" +#include "item.h" +#include "skill.h" +#include "buf.h" +#include "util.h" +#include "configfile.h" + + +/*====================į ====================*/ +static int TITLE_IntCheck( int charaindex,int elem, int *data, int flg); +static int TITLE_WorkIntCheck( int charaindex,int elem, int *data, int flg); +static int TITLE_ItemCheck( int charaindex,int elem, int *data, int flg); +static int TITLE_ItemEquipCheck( int charaindex,int elem, int *data, int flg); +static int TITLE_SkillCheck( int charaindex,int elem, int *data, int flg); +static int TITLE_SexCheck( int charaindex,int elem, int *data, int flg); + +typedef enum +{ + TITLE_FUNCTYPENONE, /* Ϸئ */ + TITLE_FUNCTYPEUSERFUNC, /* definefunction ëȻ ë + * Ѽ¦ѷ + * int ƽҷ̼͵ + * buf ߼ + * buflen 뼰Ӯ + */ + TITLE_USEFUNCTYPENUM +}TITLE_USEFUNCTYPE; + +typedef struct tagTITLE_Table +{ + int index; /* ܷѯë׻ + * įƥȻaddtitle羮֧ + */ + char name[32]; + TITLE_USEFUNCTYPE functype; + void (*definefunction)(int,char* buf,int buflen); +}TITLE_Table; + +/* ɷ¶ + * STR,TGH,MAXMPATK,DEF + * LEVEL,CLASS,SKILL,ITEM,FIREREG,ICEREG,THUNDERREG + * KANJILV,TALKCNT,WALKCNT,DEADCNT,LOGINCNT,BASEIMAGENUMBER + * GOLD +*/ +typedef struct tagTITLE_Compare { + char compare[8];; +} TITLE_COMPARE; + +TITLE_COMPARE TITLE_compare[] = { {"<="}, {">="},{"<>"}, {">"},{"<"},{"="}}; + +typedef struct tagTITLE_PARAM +{ + int element; + int (*checkfunc)( int charaindex,int elem, int *data, int flg ); + char *paramname; +}TITLE_PARAM; + +TITLE_PARAM TITLE_param[] = +{ + /**** ****/ + { -1, TITLE_ItemCheck, "ITEM" }, + { -1, TITLE_ItemEquipCheck,"EQUIPITEM" }, + { -1, NULL, "EQUIPEVENT" }, + /**** ƥ ئƥʷֽУ ****/ + { -1, TITLE_SkillCheck, "SKILL" }, + { CHAR_STR, TITLE_IntCheck, "STR" }, + { CHAR_TOUGH, TITLE_IntCheck, "TGH" }, + { CHAR_MAXMP, TITLE_IntCheck, "MAXMP" }, + { CHAR_WORKFIXSTR, TITLE_WorkIntCheck, "ATK" }, + { CHAR_WORKFIXTOUGH, TITLE_WorkIntCheck, "DEF" }, + { CHAR_LV, TITLE_IntCheck, "LEVEL" }, + { CHAR_TALKCOUNT, TITLE_IntCheck, "TALKCNT" }, + { CHAR_WALKCOUNT, TITLE_IntCheck, "WALKCNT" }, + { CHAR_DEADCOUNT, TITLE_IntCheck, "DEADCNT" }, + { CHAR_LOGINCOUNT, TITLE_IntCheck, "LOGINCNT" }, + { CHAR_BASEBASEIMAGENUMBER,TITLE_IntCheck, "BASEIMAGENUMBER" }, + { CHAR_GOLD, TITLE_IntCheck, "GOLD" }, + { -1, TITLE_SexCheck, "SEX" }, +}; + +#define TITLE_PARAMSIZE 20 +typedef struct tagTITLE_configTable +{ + int paramindex[20]; /* TITLE_param߼ٯ */ + int param[20][TITLE_PARAMSIZE]; /* Ұ */ + int compareflg[20]; /* ><=¾ */ + int title; + BOOL equipcheckflg; /* + * ʧ ة ìƥ𼰰׷º뼰 Ȼ + * ּƾئУ + */ +}TITLE_CONFIGTABLE; + +typedef struct tagTITLE_configbuf +{ + int title; + int flg; +}TITLE_CONFIGBUF; + +static TITLE_CONFIGTABLE *TITLE_ConfigTable; +static TITLE_Table *TITLE_table; +static TITLE_CONFIGBUF *TITLE_configbuf; +static int TITLE_titlenum; +static int TITLE_titlecfgnum; + +/*------------------------------------------------------------ + * index įTITLE_tableٯë + ------------------------------------------------------------*/ +int TITLE_getTitleIndex( int index) +{ + int i; + if( index < 0 ) return -1; + for( i = 0; i < TITLE_titlenum; i ++ ) { + if( TITLE_table[i].index == index ) { + return( i); + } + } + return -1; +} + +/* 뼰 */ +#define TITLESTRINGBUFSIZ 256 +/* ͷʧέµƽﷸ ٯ */ +static char TITLE_statusStringBuffer[TITLESTRINGBUFSIZ]; +/*------------------------------------------------------------ + * ͷʧέ±į ٯ ë + * ¦ + * title Title* ƽ + * charaindex int 𼰱įë Ȼƽҷ¼̼͵ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* TITLE_makeTitleStatusString( int charaindex,int havetitleindex ) +{ + int attach; + int index; + /* ߼̼͵շë */ + index = CHAR_getCharHaveTitle( charaindex,havetitleindex ); + + attach = TITLE_getTitleIndex( index); + if( attach == -1 ) { + TITLE_statusStringBuffer[0] = '\0'; + return TITLE_statusStringBuffer; + } + switch( TITLE_table[attach].functype ){ + case TITLE_FUNCTYPENONE: + snprintf( TITLE_statusStringBuffer, + sizeof(TITLE_statusStringBuffer ),"%s" , + TITLE_table[attach].name ); + break; + + case TITLE_FUNCTYPEUSERFUNC: + { + char string[256]={""}; + void (*function)(int,char* buf,int buflen); + function = TITLE_table[attach].definefunction; + if( function ) + function( charaindex,string,sizeof(string) ); + + strcpysafe( TITLE_statusStringBuffer, + sizeof(TITLE_statusStringBuffer ),string ); + } + break; + default: + TITLE_statusStringBuffer[0] = '\0'; + return TITLE_statusStringBuffer; + break; + } + return TITLE_statusStringBuffer; +} + +/*------------------------------------------------------------ + * ئбį ٯ ë߯ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* TITLE_makeSkillFalseString( void ) +{ + TITLE_statusStringBuffer[0]= '\0'; + return TITLE_statusStringBuffer; +} + + +/*------------------------------------------------------------ + * ϶ýľ įįëܰ£ۺֽئȻգܰئ + * ¦ + * charaindex int ƽҷ̼͵ + * titleindex int į̼͵ + * ߯Ի + * ܰindex + * ܰئ FALSE(0) + ------------------------------------------------------------*/ +BOOL TITLE_addtitle( int charaindex, int titleindex ) +{ + int i; + int firstfindempty=-1; + + if( CHAR_CHECKINDEX(charaindex) == FALSE )return FALSE; + /*if( TITLE_CHECKTABLEINDEX(titleindex) == FALSE )return FALSE;*/ + if( TITLE_getTitleIndex( titleindex) == -1 ) return FALSE; + + for( i=0 ; i < CHAR_TITLEMAXHAVE ; i++ ){ + if( CHAR_getCharHaveTitle( charaindex,i ) == titleindex ) + /* ƥ Ȼ¾ئ */ + return FALSE; + if( firstfindempty == -1 + && CHAR_getCharHaveTitle(charaindex,i) == -1 ){ + firstfindempty = i; + } + } + return CHAR_setCharHaveTitle( charaindex,firstfindempty,titleindex ); +} + + +/*------------------------------------------------------------ + * ϶ýľ įįؤմ£ئئУ + * ؤ ʣ + * ¦ + * charaindex int ƽҷ̼͵ + * titleindex int į̼͵ + * ߯Ի + * TRUE(1) + * ئ FALSE(0) + ------------------------------------------------------------*/ +BOOL TITLE_deltitle( int charaindex, int titleindex ) +{ + int i; + BOOL del=FALSE; + int index; + if( CHAR_CHECKINDEX(charaindex) == FALSE )return FALSE; + /*if( TITLE_CHECKTABLEINDEX(titleindex) == FALSE )return FALSE;*/ + index = TITLE_getTitleIndex( titleindex); + if( index == -1 ) return FALSE; + + for( i=0 ; i < CHAR_TITLEMAXHAVE ; i++ ) + if( CHAR_getCharHaveTitle( charaindex,i ) == titleindex ){ + /* лȻ֧ئɣľئƱ */ + if( CHAR_getInt(charaindex, CHAR_INDEXOFEQTITLE) == i ){ + CHAR_setInt(charaindex, CHAR_INDEXOFEQTITLE, -1 ); + } + /* Ȼ¾ */ + CHAR_setCharHaveTitle( charaindex,i,-1); + + del = TRUE; + } + + return del; +} +/*------------------------------------------------------------ + * įë£ + * ¦ + * filename char* ɬð̻ + * ߯Ի + * TRUE(1) + * FALSE(0) + *------------------------------------------------------------*/ +BOOL TITLE_initTitleName( char* filename ) +{ + FILE* f; + char line[256]; + int linenum=0; + int title_readlen=0; + +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + errorprint; + return FALSE; + } + + TITLE_titlenum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + TITLE_titlenum++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "ѰҴ\n" ); + fclose(f); + return FALSE; + } + + TITLE_table = allocateMemory( sizeof(struct tagTITLE_Table) + * TITLE_titlenum ); + if( TITLE_table == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(TITLE_table)*TITLE_titlenum); + fclose( f ); + return FALSE; + } + /* */ +{ + int i; + for( i = 0; i < TITLE_titlenum; i ++ ) { + TITLE_table[i].index = -1; + TITLE_table[i].name[0] = '\0'; + TITLE_table[i].functype = TITLE_FUNCTYPENONE; + TITLE_table[i].definefunction = NULL; + } + +} + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ +{ + int i; + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + + /* 繴ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",1,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + TITLE_table[title_readlen].index = atoi(token); + + /* 2ͼëέ */ + ret = getStringFromIndexWithDelim( line,",",2,token, + sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + continue; + } + if( strlen( token) > sizeof( TITLE_table[title_readlen].name)-1) { + fprint("! ͷƽļ:%s %d\n", + filename, linenum); + } + strcpysafe( TITLE_table[title_readlen].name, + sizeof( TITLE_table[title_readlen].name), + token); + + title_readlen ++; +} + } + fclose(f); + + TITLE_titlenum = title_readlen; + + print( "Чͷ %d...", TITLE_titlenum ); + +#ifdef DEBUG + + { + int i; + for( i=0; i ="); + if( comppos == -1 ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + TITLE_initTitleData( titlecfg_readlen); + errflg = TRUE; + break;; + } + /* įįṴ */ + if( charInclude( &token[comppos+1], "<>=") != -1 ) { + /* ئ ʤë */ + for( j = 0; j < 3; j ++ ) { + if( memcmp( TITLE_compare[j].compare, &token[comppos], 2 ) == 0 ) { + break; + } + } + if( j == 3 ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + TITLE_initTitleData( titlecfg_readlen); + errflg = TRUE; + break; + } + else { + ret = TITLE_getParamData( titlecfg_readlen,i-1,&token[comppos+2]); + if( !ret ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + TITLE_initTitleData( titlecfg_readlen); + errflg = TRUE; + break; + } + + /*TITLE_ConfigTable[titlecfg_readlen].param[i-1] + = atoi( &token[comppos+2]);*/ + TITLE_ConfigTable[titlecfg_readlen].compareflg[i-1] = j; + } + } + else { + ret = TITLE_getParamData( titlecfg_readlen,i-1,&token[comppos+1]); + if( !ret ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + TITLE_initTitleData( titlecfg_readlen); + errflg = TRUE; + break; + } + /*TITLE_ConfigTable[titlecfg_readlen].param[i-1] + = atoi( &token[comppos+1]);*/ + /* ئ ʤë */ + for( j = 3; j < 6; j ++ ) { + if( memcmp( TITLE_compare[j].compare, &token[comppos], 1 ) == 0 ) { + TITLE_ConfigTable[titlecfg_readlen].compareflg[i-1] = j; + break; + } + } + } + } + } + /* į ϶û or ئϾռ޷¡*/ + if( errflg || TITLE_ConfigTable[titlecfg_readlen].title == -1 ) { + fprint("ļ﷨:%s %d\n",filename,linenum); + TITLE_initTitleData( titlecfg_readlen); + } + else { + titlecfg_readlen ++; + } +} + } + fclose(f); + + TITLE_titlecfgnum = titlecfg_readlen; + + print( "Чͷ %d...", TITLE_titlecfgnum ); + + return TRUE; +} +/*------------------------------------------------------------ + * įɬñƩͻįëܸ£ + * ¦ + * charaindex int ƽҷ̼͵ + * mode BOOL TRUE:item=ּƩ FALSE: + * ߯Ի + * TRUE: į Ի + * FALSE: ף + *------------------------------------------------------------*/ +static BOOL TITLE_TitleCheck_Main( int charaindex, BOOL mode, int *addcnt, int *delcnt) +{ + int i, j,k, ret; + + /* */ +{ + int i; + for( i = 0; i < TITLE_titlecfgnum && TITLE_configbuf[i].title != -1; i ++ ) { + TITLE_configbuf[i].title = -1; + TITLE_configbuf[i].flg = 0; + } +} + *addcnt = 0; + *delcnt = 0; + + for( i = 0; i < TITLE_titlecfgnum; i ++ ) { + int rc = TRUE; + int title = TITLE_ConfigTable[i].title; + if( mode == TRUE ) { + if( TITLE_ConfigTable[i].equipcheckflg != TRUE ) { + continue; + } + } + for( j = 0; + j < arraysizeof( TITLE_ConfigTable[i].param) && + TITLE_ConfigTable[i].param[j][0] != -1 ; + j ++ ) + { + int index = TITLE_ConfigTable[i].paramindex[j]; + if( TITLE_param[index].checkfunc != NULL ) { + rc = TITLE_param[index].checkfunc( + charaindex, + TITLE_param[index].element, + TITLE_ConfigTable[i].param[j], + TITLE_ConfigTable[i].compareflg[j] + ); + if( rc != TRUE ) break; + } + } + /* ԪįԻ񲻯ľݼб + * add,deltile + */ + for( k = 0; k < TITLE_titlecfgnum; k ++ ) { + if( TITLE_configbuf[k].title == title ) { + if( rc ) { + TITLE_configbuf[k].flg = 1; + } + break; + } + else if( TITLE_configbuf[k].title == -1 ) { + TITLE_configbuf[k].title = title; + TITLE_configbuf[k].flg = rc ? 1: -1; + break; + } + } + } + ret = FALSE; + for( i = 0; i < TITLE_titlecfgnum && TITLE_configbuf[i].title != -1; i ++ ) { + if( TITLE_configbuf[i].flg == -1 ) { + *delcnt += TITLE_deltitle( charaindex, TITLE_configbuf[i].title); + } + else { + *addcnt += TITLE_addtitle( charaindex, TITLE_configbuf[i].title) ? 1:0; + } + } + if( *delcnt > 0 || *addcnt > 0) { + ret = TRUE; + } + return ret; + +} +/*------------------------------------------------------------ + * įɬñƩͻįëܸ£ + * ¦ + * charaindex int ƽҷ̼͵ + * mode BOOL TRUE:item=ּƩ FALSE: + * ߯Ի + * TRUE: į Ի + * FALSE: ף + *------------------------------------------------------------*/ +BOOL TITLE_TitleCheck( int charaindex, BOOL mode) +{ +#define TITLE_MSGUNIT1 "TSU" +#define TITLE_MSGUNIT2 "KO" + int addcnt,delcnt; + BOOL rc; + char msgbuf[64]; + rc = TITLE_TitleCheck_Main( charaindex, mode, &addcnt,&delcnt); + if( rc ) { + if( delcnt > 0 ) { + snprintf( msgbuf, sizeof( msgbuf), + "ʧȥ%d%s ƺţ", delcnt, + delcnt < 10 ? TITLE_MSGUNIT1:TITLE_MSGUNIT2); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + } + if( addcnt > 0 ) { + snprintf( msgbuf, sizeof( msgbuf), + "%d%s ƺţ", addcnt, + addcnt < 10 ? TITLE_MSGUNIT1:TITLE_MSGUNIT2); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + } + } + return rc; +} +/*------------------------------------------------------------ + * įɬñƩͻįëܸ£ + * ¦ + * charaindex int ƽҷ̼͵ + * mode BOOL TRUE:item=ּƩ FALSE: + * ߯Ի + * TRUE: į Ի + * FALSE: ף + *------------------------------------------------------------*/ +BOOL TITLE_TitleCheck_Nomsg( int charaindex, BOOL mode, int *addcnt, int *delcnt) +{ + return( TITLE_TitleCheck_Main( charaindex, mode, addcnt,delcnt)); +} + + +static int TITLE_IntCheck( int charaindex, int elem, int *data, int flg) +{ + int rc = FALSE; + int i; + for( i = 0; i < TITLE_PARAMSIZE && *(data+i) != -1; i ++ ) { + switch( flg) { + case 0: /* "<=" */ + if( CHAR_getInt( charaindex, elem) <= *(data+i) ) rc = TRUE; + break; + case 1: /* ">=" */ + if( CHAR_getInt( charaindex, elem) >= *(data+i) ) rc = TRUE; + break; + case 2: /* "<>" */ + if( CHAR_getInt( charaindex, elem) != *(data+i) ) rc = TRUE; + break; + case 3: /* ">" */ + if( CHAR_getInt( charaindex, elem) > *(data+i) ) rc = TRUE; + break; + case 4: /* "<" */ + if( CHAR_getInt( charaindex, elem) < *(data+i) ) rc = TRUE; + break; + case 5: /* "=" */ + if( CHAR_getInt( charaindex, elem) == *(data+i) ) rc = TRUE; + break; + default: + rc= FALSE; + break; + } + if( rc) break; + } + return rc; +} +static int TITLE_WorkIntCheck( int charaindex,int elem, int *data, int flg) +{ + int rc = FALSE; + int i; + for( i = 0; i < TITLE_PARAMSIZE && *(data+i) != -1; i ++ ) { + switch( flg) { + case 0: /* "<=" */ + if( CHAR_getWorkInt( charaindex, elem) <= *(data+i) ) rc = TRUE; + break; + case 1: /* ">=" */ + if( CHAR_getWorkInt( charaindex, elem) >= *(data+i) ) rc = TRUE; + break; + case 2: /* "<>" */ + if( CHAR_getWorkInt( charaindex, elem) != *(data+i) ) rc = TRUE; + break; + case 3: /* ">" */ + if( CHAR_getWorkInt( charaindex, elem) > *(data +i)) rc = TRUE; + break; + case 4: /* "<" */ + if( CHAR_getWorkInt( charaindex, elem) < *(data+i) ) rc = TRUE; + break; + case 5: /* "=" */ + if( CHAR_getWorkInt( charaindex, elem) == *(data+i) ) rc = TRUE; + break; + default: + rc= FALSE; + break; + } + if( rc ) break; + } + return rc; +} +/* -------------------------------------- + * ϶ýľdata Ȼʧ ةë ʤ£ + * -------------------------------------*/ +static int TITLE_ItemCheckMain( int charaindex, int itemhaveindex, int *data, int flg) +{ + int i,j; + int rc = FALSE; + + if( flg == 2 ) rc = TRUE; + + for( j = 0; j < TITLE_PARAMSIZE && *(data+j) != -1; j ++ ) { + for( i =0; i < itemhaveindex; i ++ ) { + int itemindex = CHAR_getItemIndex(charaindex,i); + if( ITEM_CHECKINDEX(itemindex) ) { + switch( flg) { + case 0: /* "<=" */ + if( ITEM_getInt( itemindex, ITEM_ID) <= *(data+j) ) rc = TRUE; + break; + case 1: /* ">=" */ + if( ITEM_getInt( itemindex, ITEM_ID) >= *(data+j) ) rc = TRUE; + break; + case 3: /* ">" */ + if( ITEM_getInt( itemindex, ITEM_ID) > *(data +j)) rc = TRUE; + break; + case 4: /* "<" */ + if( ITEM_getInt( itemindex, ITEM_ID) < *(data +j)) rc = TRUE; + break; + case 5: /* "=" */ + if( ITEM_getInt( itemindex, ITEM_ID) == *(data +j)) rc = TRUE; + break; + /* ľ У + * ʧ ة ëέľë Ȼئީ£ + * ƥ Ȼëƻ + */ + case 2: /* "<>" */ + if( ITEM_getInt( itemindex, ITEM_ID) == *(data +j)) rc = FALSE; + break; + default: + rc= FALSE; + break; + } + if( rc && flg != 2) break; + } + } + if( rc) break; + } + return rc; +} + +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static int TITLE_ItemCheck( int charaindex,int elem, int *data, int flg) +{ + return( TITLE_ItemCheckMain( charaindex +#ifdef _NEW_ITEM_ + ,CheckCharMaxItem(charaindex) +#else + ,CHAR_MAXITEMHAVE +#endif + ,data,flg)); +} + +static int TITLE_ItemEquipCheck( int charaindex,int elem, int *data, int flg) +{ + return( TITLE_ItemCheckMain( charaindex, CHAR_EQUIPPLACENUM,data,flg)); +} + +static int TITLE_SkillCheck( int charaindex,int elem, int *data, int flg) +{ + int i; + int rc = FALSE; + CHAR_HaveSkill* hskill; + + for( i = 0 ; i < CHAR_SKILLMAXHAVE ; i ++ ){ + hskill = CHAR_getCharHaveSkill( charaindex, i ); + if( hskill != NULL && hskill->use == TRUE ) { + + if( *(data + 1) != -2 ) { + if( SKILL_getInt( &hskill->skill, SKILL_IDENTITY) == *data) { + rc = TRUE; + break; + } + } + + else { + if( SKILL_getInt( &hskill->skill, SKILL_IDENTITY) == *data) { + rc = FALSE; + break; + } + else { + rc = TRUE; + } + } + } + } + if( rc ) { + + if( *(data+1) != -1 && *(data+1) != -2) { + rc = FALSE; + switch( flg) { + case 0: /* "<=" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) <= *(data+1) ) rc = TRUE; + break; + case 1: /* ">=" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) >= *(data+1) ) rc = TRUE; + break; + case 2: /* "<>" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) != *(data+1) ) rc = TRUE; + break; + case 3: /* ">" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) > *(data +1)) rc = TRUE; + break; + case 4: /* "<" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) < *(data+1) ) rc = TRUE; + break; + case 5: /* "=" */ + if( SKILL_getInt( &hskill->skill, SKILL_LEVEL) == *(data+1) ) rc = TRUE; + break; + default: + rc= FALSE; + break; + } + } + } + return rc; +} +/* -------------------------------------- + * ƽҷ¾ƽҷ¾£ + * -------------------------------------*/ +static int TITLE_SexCheck( int charaindex,int elem, int *data, int flg) +{ + int i,j; + struct { + int sex[25]; + }s_sex[] = + { { { 30008,30009,30010,30011,30012,30013,30014,30015, + 30020,30021,30022,30023,30024,30025,30026,30027, + 30028,30029,30030,30031,30032,30033,30034,30035,-1} + }, + { {30000,30001,30002,30003,30004,30005,30006,30007, + 30016,30017,30018,30019,30036,30037,30038,30039, + -1, -1, -1, -1, -1, -1, -1, -1, -1} + } + }; + for( i = 0; i < 2; i ++ ) { + for( j = 0; s_sex[i].sex[j] != -1 ; j ++ ) { + if( CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER ) + == s_sex[i].sex[j] ) + { + if( i == *data ) return TRUE; + else return FALSE; + } + } + } + return FALSE; +} + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/char/trade.c b/石器时代服务器端最新完整源代码/Serv/gmsv/char/trade.c new file mode 100644 index 0000000..4fd0dc5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/char/trade.c @@ -0,0 +1,2322 @@ +#include "version.h" +#include "correct_bug.h" +#include +#include +#include + +#include "readmap.h" +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "trade.h" +#include "log.h" +#include "handletime.h" +#include "buf.h" +#include "net.h" +#include "char_base.h" +#include "battle.h" +#include "npc_bus.h" +#include "char_talk.h" +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ +#include "pet_skill.h" +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#define TRADE_WAIT "Ժ%sС" +#define TRADE_REFUSE "%sܾĽ" +#define TRADE_NONE "ǰʲҲûУ" +#define TRADE_OVERPLAYER "ǰֻһλร" +#define TRADE_NOWILL "DZǸԷԸ㽻ף" +#define TRADE_TRADING "%s˽ס" +#define TRADE_VANISHITEM "ڵϻʧƷ޷ף" +#define TRADE_PETFULL "%sȡ" +#define TRADE_ITEMFULL "%sƷٽס" +#define TRADE_CANCEL "%sȡˣ" +#define TRADE_POOR "%sǮ޷ף" +#define TRADE_RICH "%sǮ𳬹һ" +#define TRADE_TOORICH "%sǮᳬһ" +#define TRADE_POORLV "%sȼ޷չ˽ij" +#define TRADE_LOCK "" +#define TRADE_SUCCESS "ףϣˣ" +#define TRADE_FAILED "ʧܣ" +#define TRADE_FMPET "ػ޷ף" +#ifdef _LOCK_PET_ITEM +#define TRADE_LOCKPET "󶨵ij޷ף" +#define TRADE_LOCKITEM "󶨵ĵ޷ף" +#define TRADE_LOCKPETITEM "а󶨵ĵ޷ף" +#endif +#define TRADE_NOITEM "޷׵Ʒ" +#define TRADE_NOPET "޷׵ij" +#define TRADE_RDCANCEL "ȡ" + + + +#ifdef _ITEM_PILEFORTRADE +enum{ + TRADE_ITEM=0, + TRADE_PET, + TRADE_GOLD, +}; + +#define MAX_TRADELISTNUM 100 + +STradeList TradeList[MAX_TRADELISTNUM][2]; + +void TRADE_ResetTradeList( int ti); +int TRADE_getTradeListIndex( void); +int TRADE_getMyTarget( int meindex ); +BOOL TRADE_setTradeListIndex( int ti, int meindex, int toindex); +BOOL TRADE_addSomeTradeList( int meindex, int usTi, int *num, int type); +BOOL TRADE_getSomeTradeList( int meindex, STradeList *temp); + +void TRADE_InitTradeList( void) +{ + int i; + print("ʼϵͳ..."); + for( i=0; i= MAX_TRADELISTNUM )return; + for( i=0; i<5; i++){ + TradeList[ti][0].PetTi[i] = -1; + TradeList[ti][1].PetTi[i] = -1; + } + for( i=0; i<15; i++){ + TradeList[ti][0].ItemTi[i] = -1; + TradeList[ti][0].ItemNum[i] = -1; + TradeList[ti][1].ItemTi[i] = -1; + TradeList[ti][1].ItemNum[i] = -1; + } + + TradeList[ti][0].Golds = 0; + TradeList[ti][1].Golds = 0; + + + if( CHAR_CHECKINDEX(TradeList[ti][0].charaindex)){ + fd = getfdFromCharaIndex( TradeList[ti][0].charaindex); + CONNECT_setTradeList( fd, -1); + } + if( CHAR_CHECKINDEX(TradeList[ti][1].charaindex)){ + fd = getfdFromCharaIndex( TradeList[ti][1].charaindex); + CONNECT_setTradeList( fd, -1); + } + + TradeList[ti][0].charaindex = -1; + TradeList[ti][1].charaindex = -1; + TradeList[ti][0].fd = -1; + TradeList[ti][1].fd = -1; + + TradeList[ti][0].use = 0; + TradeList[ti][1].use = 0; + +} + +int TRADE_getTradeListIndex( void) +{ + int i; + static int tradeTi=0; + if( tradeTi < 0 ) tradeTi = 0; + for( i=0; i= MAX_TRADELISTNUM ) tradeTi = 0; + + } + return -1; +} + +BOOL TRADE_setTradeListIndex( int ti, int meindex, int toindex) +{ + int fd; + if( ti<0 || ti >= MAX_TRADELISTNUM ) return FALSE; + if( TradeList[ti][0].use == 1 || TradeList[ti][1].use == 1 ) return FALSE; + TRADE_ResetTradeList( ti); + TradeList[ti][0].charaindex = meindex; + TradeList[ti][1].charaindex = toindex; + TradeList[ti][0].use = 1; + TradeList[ti][1].use = 1; + + fd = getfdFromCharaIndex( meindex); + TradeList[ti][0].fd = fd; + CONNECT_setTradeList( fd, ti); + + fd = getfdFromCharaIndex( toindex); + TradeList[ti][1].fd = fd; + CONNECT_setTradeList( fd, ti); + return TRUE; +} + +void TRADE_CheckTradeListUser( void) +{ + int i, usenum=0, replace=0, freenum=0; + for( i=0; i= MAX_TRADELISTNUM ) return -1; + if( TradeList[ti][0].use == 0 || TradeList[ti][1].use == 0 ) return -1; + + for( i=0; i<2; i++){ + if( TradeList[ti][i].charaindex == meindex && + TradeList[ti][i].fd == fd ){ + side = (i+1)%2; + if( !CHAR_CHECKINDEX( TradeList[ti][side].charaindex) ) return -1; + if( TradeList[ti][side].charaindex == meindex ) return -1; + if( TradeList[ti][side].fd != getfdFromCharaIndex( TradeList[ti][side].charaindex) ) return -1; + + return TradeList[ti][side].charaindex; + } + } + return -1; +} + +BOOL TRADE_addSomeTradeList( int meindex, int usTi, int *num, int type) +{ + int i, fd, ti, side=-1, toindex=-1; + fd = getfdFromCharaIndex( meindex); + ti = CONNECT_getTradeList( fd); + if( ti <0 || ti >= MAX_TRADELISTNUM ) return FALSE; + toindex =-1; + if( TradeList[ti][0].use != 1 || TradeList[ti][1].use != 1 ) return FALSE; + for( i=0; i<2; i++){ + if( TradeList[ti][i].charaindex != meindex ){ + continue; + } + side = i; + toindex = TradeList[ti][((side+1)%2)].charaindex; + if( !CHAR_CHECKINDEX( toindex) ) return FALSE; + break; + } + if( side == -1 ) return FALSE; + switch( type){ + case TRADE_ITEM: + { + int itemindex, MeMaxPile; + MeMaxPile = CHAR_getMyMaxPilenum( meindex);//ѵ + if( usTi < CHAR_STARTITEMARRAY || +#ifdef _NEW_ITEM_ + usTi >= CheckCharMaxItem(meindex) +#else + usTi >= CHAR_MAXITEMHAVE +#endif + ) return FALSE; + itemindex = CHAR_getItemIndex( meindex, usTi ); + if( !ITEM_CHECKINDEX( itemindex)) return FALSE; + + if( ITEM_getInt( itemindex, ITEM_VANISHATDROP) == 1 ){ + char buf[256]; + sprintf( buf, "%s޷ס", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORYELLOW); + return FALSE; + } + + if(FreeTradeItem(meindex, itemindex)){ + return FALSE; + } +#ifdef _LOCK_PET_ITEM + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + char buf[256]; + sprintf( buf, "%s޷ס", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli( meindex, -1, buf, CHAR_COLORYELLOW); + return FALSE; + } +#endif + if( ITEM_getInt( itemindex, ITEM_CANBEPILE) == 1 ){//ɶѵ + int itemMaxPile = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + if( itemMaxPile < 0 ) return FALSE; + //ITEM_USEPILENUMS + for( i=0; i<15; i++){ + if( TradeList[ti][side].ItemTi[i] != usTi ) continue; + if( TradeList[ti][side].ItemNum[i] >= MeMaxPile || + TradeList[ti][side].ItemNum[i] >= itemMaxPile ) return FALSE; + + TradeList[ti][side].ItemNum[i] += 1; + if( num != NULL ) *num = TradeList[ti][side].ItemNum[i]; + return TRUE; + } + } + for( i=0; i<15; i++){ + if( TradeList[ti][side].ItemTi[i] != -1 ) continue; + TradeList[ti][side].ItemTi[i] = usTi; + TradeList[ti][side].ItemNum[i] = 1; + if( num != NULL ) *num = TradeList[ti][side].ItemNum[i]; + return TRUE; + } + } + break; + case TRADE_PET: + { + int petindex; + if( usTi < 0 || usTi >= CHAR_MAXPETHAVE ) return FALSE; + petindex = CHAR_getCharPet( meindex, usTi ); + if( !CHAR_CHECKINDEX(petindex)) return FALSE; + if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 ){ + CHAR_talkToCli( meindex, -1, "ػ޷ס", CHAR_COLORYELLOW); + return FALSE;//ػ + } + if(FreeTradePet(meindex, petindex) == 1){ + return FALSE;//ػ + } + +#ifdef _LOCK_PET_ITEM +{ + char *petname = CHAR_getChar( petindex, CHAR_NAME); + if( petname[0] == '*' ){ + CHAR_talkToCli( meindex, -1, "󶨳޷ף", CHAR_COLORYELLOW); + return FALSE; + } +#ifdef _PET_ITEM +{ + int i; + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + int itemindex = CHAR_getItemIndex( petindex, i ); + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + CHAR_talkToCli( meindex, -1, "а󶨵ĵ޷ף", CHAR_COLORYELLOW); + return FALSE; + } + } +} +#endif +} +#endif + if( CHAR_getWorkInt( toindex, CHAR_PickAllPet) != TRUE ){ + if( CHAR_getInt( petindex, CHAR_LV) > (CHAR_getInt( toindex, CHAR_LV)+20) && + (CHAR_getInt( toindex, CHAR_TRANSMIGRATION ) <= 0 ) ){ + CHAR_talkToCli( meindex, -1, "Է޷չ˸ó", CHAR_COLORYELLOW); + return FALSE; + } + } + + for( i=0; i<5; i++){ + if( TradeList[ti][side].PetTi[i] == usTi ) return FALSE; + } + for( i=0; i<5; i++){ + if( TradeList[ti][side].PetTi[i] != -1 ) continue; + TradeList[ti][side].PetTi[i] = usTi; + return TRUE; + } + } + break; + case TRADE_GOLD: + TradeList[ti][side].Golds = usTi; + return TRUE; + break; + } + + return FALSE; +} + +BOOL TRADE_getSomeTradeList( int meindex, STradeList *temp) +{ + int i, fd, ti, side=-1; + fd = getfdFromCharaIndex( meindex); + ti = CONNECT_getTradeList( fd); + if( ti <0 || ti >= MAX_TRADELISTNUM ) return FALSE; + if( TradeList[ti][0].use != 1 || TradeList[ti][1].use != 1 ) return FALSE; + for( i=0; i<2; i++){ + if( TradeList[ti][i].charaindex != meindex ) continue; + side = i; + break; + } + if( side == -1 ) return FALSE; + + memcpy( temp, &TradeList[ti][side], sizeof( STradeList) ); + return TRUE; +} +BOOL TRADE_CheckTradeList( int meindex, STradeList *temp1, int toindex, STradeList *temp2); +#endif + +void TRADE_Will(int fd, int meindex, char* message); +void TRADE_ShowItem(int fd, int meindex, char* message); +void TRADE_Close(int fd, int meindex, char* message); + +void TRADE_SwapItem(int meindex, int toindex, char* message, int fd, char* mycharaname, int tofd, char* tocharaname); + +int TRADE_CheckItembuf(int fd, int meindex, int toindex, int tofd, char* mycharaname, char* tocharaname); +//BOOL TRADE_ChangeItem(int meindex, int toindex, char *a, char *b, int item1, int item2, int itemindex1, int itemindex2); +BOOL TRADE_HandleItem( int meindex, int showindex, char *message, char *outmess); +BOOL TRADE_HandleGold( int meindex, int showindex, char *message, char *outmess); +BOOL TRADE_HandlePet( int meindex, int showindex, char *message, char *outmess); + + + +void CHAR_Trade(int fd, int index, char* message) +{ + char firstToken[64]; + // shan עDzҪĶ 2002/03/05 + //char messageeraseescape[512]; + char* messagebody; + + { + if (*message == 0) return; + if (!CHAR_CHECKINDEX(index)) return; + + CHAR_getMessageBody( message, firstToken, sizeof(firstToken), &messagebody); + + switch( tolower( firstToken[0]) ){ + case 'd': // Ѱǰ + TRADE_Search(fd, index, message); + break; +#ifdef _COMFIRM_TRADE_REQUEST + case 'c': + TRADE_Will(fd, index, message); + break; +#endif + case 't': // ʾ׵ƷǮ + TRADE_ShowItem(fd, index, message); + break; + case 'w': // رս + TRADE_Close(fd, index, message); + break; + default: + break; + } + } +} + +BOOL TRADE_Search(int fd, int meindex, char* message) +{ + int objbuf[16]; + int front_x, front_y, i, found_count; + BOOL found = FALSE, searchflg = FALSE; + int cnt = 0, tofd = -1, checkfd = -1; + char msgbuf[1024], mycharaname[256], tocharaname[256]; + char token[256]; + + if (!CHAR_CHECKINDEX(meindex)) return FALSE; + + // ״̬Ϊл账 + if (CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_TRADING + || CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK) + return FALSE; + + // ״̬Ϊӻս账 + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return FALSE; + +#ifdef _STREET_VENDOR + // ڰ̯в + if(CHAR_getWorkInt(meindex,CHAR_WORKSTREETVENDOR) > -1) return FALSE; +#endif + + strcpy(mycharaname, CHAR_getChar(meindex, CHAR_NAME)); + + if (getStringFromIndexWithDelim(message, "|", 2, token, + sizeof(token)) == FALSE) return FALSE; + // 趨״̬ +// CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_SENDING); + +#ifndef _ITEM_PILEFORTRADE + for (i = 0; i < CONNECT_WINDOWBUFSIZE; i++) + CONNECT_setTradecharaindex(fd, i, -1); +#endif + CHAR_getCoordinationDir(CHAR_getInt(meindex, CHAR_DIR), + CHAR_getInt(meindex, CHAR_X), + CHAR_getInt(meindex, CHAR_Y), + 1, &front_x, &front_y); + + found_count = CHAR_getSameCoordinateObjects( objbuf, arraysizeof(objbuf), + CHAR_getInt(meindex, CHAR_FLOOR),front_x, front_y); + // ǰûһԷرսѡ + if (found_count == 0){ + CHAR_talkToCli(meindex, -1, TRADE_NONE, CHAR_COLORYELLOW); + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + return FALSE; + } + + for (i = 0; i < found_count; i++){ + int objindex = objbuf[i]; + int index = OBJECT_getIndex(objindex); + + if (OBJECT_getType(objindex) != OBJTYPE_CHARA) continue; + if (CHAR_getInt(index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) continue; + if (index == meindex) continue; + found = TRUE; + if (CHAR_getWorkInt(index, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) continue; + if (CHAR_getWorkInt(index, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) continue; + if (CHAR_getFlg(index, CHAR_ISTRADE) == FALSE) continue; + if (CHAR_getWorkInt(index, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE) continue; + strcpy(tocharaname, CHAR_getChar(index, CHAR_NAME)); + tofd = getfdFromCharaIndex(index); + if (tofd == -1){ + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + return FALSE; + } + if (searchflg){ + if (tofd != checkfd) continue; + if (strcmp(token, tocharaname) != 0) continue; + } +#ifndef _ITEM_PILEFORTRADE + CONNECT_setTradecharaindex(fd, cnt, index); +#endif + cnt ++; + if (cnt == CONNECT_WINDOWBUFSIZE) break; + } + + if (cnt == 0){ + // ǰûһԷرսѡ + if (found){ + CHAR_talkToCli(meindex, -1, TRADE_NOWILL, CHAR_COLORYELLOW); + }else + CHAR_talkToCli(meindex, -1, TRADE_NONE, CHAR_COLORYELLOW); + + sprintf(msgbuf, "C|%d|%s|0", tofd, tocharaname); + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + return FALSE; + } + // ǰһλ + if (cnt == 1){ + int toindex; + toindex = CONNECT_getCharaindex(tofd); + if( !CHAR_CHECKINDEX(toindex)) return FALSE; +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(meindex, CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( getfdFromCharaIndex(meindex), WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return FALSE; + }else if(CHAR_getInt(toindex, CHAR_LOCKED)==1){ + char message[256]; + sprintf( message, "Է %s ȫ޷㽻ף\n", CHAR_getChar(toindex, CHAR_NAME)); + CHAR_talkToCli(meindex, -1, message, CHAR_COLORYELLOW); + return FALSE; + } +#endif + +#ifdef _ITEM_PILEFORTRADE + int ti; + + if( (ti = TRADE_getTradeListIndex()) < 0 || + TRADE_setTradeListIndex( ti, meindex, toindex) == FALSE ){ + + CHAR_talkToCli( meindex, -1, "ϵͳæµС", CHAR_COLORYELLOW); + CHAR_setWorkInt( meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + TRADE_CheckTradeListUser(); + + return FALSE; + } + + //TRADE_setTradeListIndex( ti, meindex, toindex); //ظдȥ +#endif + snprintf(msgbuf, sizeof(msgbuf), TRADE_WAIT, tocharaname); + CHAR_talkToCli(meindex, -1, msgbuf, CHAR_COLORYELLOW); //׷,xx + +#ifdef _COMFIRM_TRADE_REQUEST + sprintf(msgbuf, "C|%d|%s|2", tofd, tocharaname); + lssproto_TD_send(fd, msgbuf); +#else + sprintf(msgbuf, "C|%d|%s|1", fd, mycharaname); + lssproto_TD_send( tofd, msgbuf); + sprintf(msgbuf, "C|%d|%s|1", tofd, tocharaname); + lssproto_TD_send(fd, msgbuf); + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_TRADING); + CHAR_setWorkInt(toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_TRADING); + + CONNECT_set_confirm(fd, FALSE); + CONNECT_set_confirm(tofd, FALSE); + + CHAR_sendTradeEffect(meindex, 1); + CHAR_sendTradeEffect(toindex, 1); +#endif + return TRUE; + }else if (cnt > 1){ // ǰֻһλ + CHAR_talkToCli(meindex, -1, TRADE_OVERPLAYER, CHAR_COLORYELLOW); +// sprintf(msgbuf, "C|%d|%s|0", tofd, tocharaname); + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + return FALSE; + } + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + return FALSE; +} + +void TRADE_Will(int fd, int meindex, char* message) +{ + char msg[128], msgbuf[1024], mycharaname[256], tocharaname[256]; + int tofd=-1, toindex=-1; + if (!CHAR_CHECKINDEX(meindex)) return; + if (*message == 0) return; + strcpy(mycharaname, CHAR_getChar(meindex, CHAR_NAME)); + toindex = TRADE_getMyTarget( meindex);//ȡԼ׵Ķ + if( CHAR_CHECKINDEX( toindex) ){ + strcpy(tocharaname, CHAR_getChar(toindex, CHAR_NAME)); + if( getStringFromIndexWithDelim( message, "|", 4, msg, sizeof(msg)) == FALSE) return; + + if(strcmp( msg, "0" )==0) + { + snprintf(msgbuf, sizeof(msgbuf), TRADE_REFUSE, tocharaname); + CHAR_talkToCli(toindex, -1, msgbuf, CHAR_COLORYELLOW); //ܾ + int ti = CONNECT_getTradeList(fd); + if(ti !=-1) + { + TRADE_ResetTradeList(ti); + } + } + else if(strcmp( msg, "1" )==0) + { + sprintf(msgbuf, "C|%d|%s|1", tofd, tocharaname); + lssproto_TD_send(fd, msgbuf); + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_TRADING); + CHAR_setWorkInt(toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_TRADING); + + CONNECT_set_confirm(fd, FALSE); + CONNECT_set_confirm(tofd, FALSE); + + CHAR_sendTradeEffect(meindex, 1); + CHAR_sendTradeEffect(toindex, 1); + } + } +} + +void TRADE_Close(int fd, int meindex, char* message) +{ + char msg[128], mycharaname[256]; + int tofd=-1, toindex=-1; + int j; + + if (!CHAR_CHECKINDEX(meindex)) return; + if (*message == 0) return; + strcpy(mycharaname, CHAR_getChar(meindex, CHAR_NAME)); +#ifdef _ITEM_PILEFORTRADE + toindex = TRADE_getMyTarget( meindex);//ȡԼ׵Ķ + + if( CHAR_CHECKINDEX( toindex) ){ + tofd = getfdFromCharaIndex( toindex); + snprintf( msg, sizeof(msg), TRADE_CANCEL, mycharaname); + CHAR_talkToCli(toindex, -1, msg, CHAR_COLORYELLOW); + snprintf( msg, sizeof(msg), "W|%d|%s", fd, mycharaname); + lssproto_TD_send( tofd, msg); + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CHAR_setWorkInt( toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CONNECT_setTradeTmp( tofd, ""); + CHAR_sendStatusString( toindex, "i"); + CHAR_sendStatusString( toindex, "P"); + CHAR_sendTradeEffect( toindex, 0); + CONNECT_set_confirm( tofd, FALSE); + + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + char msgbuf[256]; + int petindex = CHAR_getCharPet( toindex, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + } + } + +#else + char token[256]; + if (getStringFromIndexWithDelim(message, "|", 2, token, sizeof(token)) == FALSE) return; + tofd = atoi(token); + toindex = CONNECT_getCharaindex(tofd); + if (!CHAR_CHECKINDEX(toindex)) return; + if (getStringFromIndexWithDelim(message, "|", 3, token, sizeof(token)) == FALSE) return; + + + snprintf(msg, sizeof(msg), TRADE_CANCEL, mycharaname); + CHAR_talkToCli(toindex, -1, msg, CHAR_COLORYELLOW); + snprintf( msg, sizeof(msg), "W|%d|%s", fd, mycharaname); + lssproto_TD_send( tofd, msg); + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CHAR_setWorkInt(toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CONNECT_setTradeTmp(tofd, ""); + CHAR_sendStatusString( CONNECT_getCharaindex(tofd), "i"); + CHAR_sendStatusString( CONNECT_getCharaindex(tofd), "P"); + CHAR_sendTradeEffect( toindex, 0); + CONNECT_set_confirm(tofd, FALSE); +#endif + + if( !CHAR_CHECKINDEX( toindex) ){ + char buf[256]; + if( getStringFromIndexWithDelim( message, "|", 2, buf, sizeof(buf)) == FALSE) return; + tofd = atoi( buf); + toindex = CONNECT_getCharaindex( tofd); + if (!CHAR_CHECKINDEX(toindex) ) + { + snprintf( msg, sizeof(msg), TRADE_RDCANCEL); + CHAR_talkToCli(meindex, -1, msg, CHAR_COLORYELLOW); + + CHAR_setWorkInt( meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CONNECT_setTradeTmp(fd, ""); + CHAR_sendStatusString(meindex, "i"); + CHAR_sendStatusString(meindex, "P"); + CHAR_sendTradeEffect( meindex, 0); + CONNECT_set_confirm(fd, FALSE); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + char msgbuf[256]; + int petindex = CHAR_getCharPet( meindex, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + } +#ifdef _ITEM_PILEFORTRADE + { + int ti=0; + ti = CONNECT_getTradeList( fd); + if( ti <0 || ti >= MAX_TRADELISTNUM ) return; + TRADE_ResetTradeList( ti); + } +#endif + return; + } + } + + snprintf( msg, sizeof(msg), TRADE_RDCANCEL); + CHAR_talkToCli(meindex, -1, msg, CHAR_COLORYELLOW); + snprintf( msg, sizeof(msg), "W|%d|%s", tofd, CHAR_getChar( toindex, CHAR_NAME) ); + lssproto_TD_send( fd, msg); + + CHAR_setWorkInt( meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CHAR_setWorkInt( toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CONNECT_setTradeTmp(fd, ""); + CHAR_sendStatusString(meindex, "i"); + CHAR_sendStatusString(meindex, "P"); + CHAR_sendTradeEffect( meindex, 0); + CONNECT_set_confirm(fd, FALSE); +// end + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + char msgbuf[256]; + int petindex = CHAR_getCharPet( meindex, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + } + +#ifdef _ITEM_PILEFORTRADE + { + int ti=0; + ti = CONNECT_getTradeList( fd); + if( ti <0 || ti >= MAX_TRADELISTNUM ) return; + TRADE_ResetTradeList( ti); + } +#endif + +} + +void TRADE_ShowItem(int fd, int meindex, char* message) +{ + char token[128], mycharaname[256], tocharaname[256], msg[2048]; + int tofd, showindex, toindex;// itemindex, gold, tmpgold, item; + + int MaxGold; + + MaxGold = CHAR_getMaxHaveGold( meindex); + strcpy( mycharaname, CHAR_getChar(meindex, CHAR_NAME)); +#ifdef _ITEM_PILEFORTRADE + toindex = TRADE_getMyTarget( meindex); + if( !CHAR_CHECKINDEX( toindex) ){ + print(" TRADE_Close_Err1:%d ", toindex); + TRADE_Close(fd, meindex, message); + return; + } + if( meindex != TRADE_getMyTarget( toindex) ){ + print(" TRADE_Close_Err2:%d->%d ", meindex, toindex); + TRADE_Close(fd, meindex, message); + return; + } + tofd = getfdFromCharaIndex(toindex); +#else + if (getStringFromIndexWithDelim(message, "|", 2, token, sizeof(token)) == FALSE) return; + tofd = atoi(token); + toindex = CONNECT_getCharaindex(tofd); +#endif + + if (!CHAR_CHECKINDEX(toindex))return; + // ״̬Ϊӻս账 + if ((CHAR_getWorkInt(meindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(meindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + + if ((CHAR_getWorkInt(toindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + || (CHAR_getWorkInt(toindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + return; + + if (getStringFromIndexWithDelim(message, "|", 3, tocharaname, sizeof(tocharaname)) == FALSE) return; + if (getStringFromIndexWithDelim(message, "|", 5, token, sizeof(token)) == FALSE) return; + showindex = atoi(token); + if (getStringFromIndexWithDelim(message, "|", 4, token, sizeof(token)) == FALSE) return; + +#ifdef _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + showindex = toindex; +#endif + strcpy( tocharaname, CHAR_getChar(toindex, CHAR_NAME)); + + switch(tolower(token[0])){ + case 'i': + { + char buf1[2048]; + if( TRADE_HandleItem( meindex, showindex, message, buf1) == FALSE ){ + print(" TRADE_Close_Err3:%d,%d,%s,%s ", meindex, showindex, message, buf1); + TRADE_Close(fd, meindex, message); + return; + }else{ + snprintf(msg, sizeof(msg), "T|%d|%s|I|%d|%s", fd, mycharaname, showindex, buf1 ); + lssproto_TD_send(tofd, msg); + } + } + break; + case 'g': + { + char buf1[2048]; + if( TRADE_HandleGold( meindex, showindex, message, buf1) == FALSE ){ + print(" TRADE_Close_Err4:%d,%d,%s,%s ", meindex, showindex, message, buf1); + TRADE_Close(fd, meindex, message); + return; + }else{// ֮ǮԷ + snprintf(msg, sizeof(msg), "T|%d|%s|G|%d|%s", fd, mycharaname, showindex, buf1); + lssproto_TD_send( tofd, msg); + } + } + break; + case 'p': + { + char buf1[2048]; + if( TRADE_HandlePet( meindex, showindex, message, buf1) == FALSE ){ + print(" TRADE_Close_Err5:%d,%d,%s,%s ", meindex, showindex, message, buf1); + TRADE_Close(fd, meindex, message); + return; + }else{ + snprintf(msg, sizeof(msg), "T|%d|%s|P|%d|%s", + fd, mycharaname, showindex, buf1); + lssproto_TD_send(tofd, msg); + } + } + break; + case 'k': + { + if((CONNECT_get_confirm(fd)==TRUE) && + (CONNECT_get_confirm(tofd)==TRUE) ){//˫ lock + if( CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK ){ + //andy_log + print("ANDY err ֹڶν!!\n"); + return;//ֹڶν + } + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_LOCK); + //ԷǷ ok +#ifdef _TRADESYSTEM2 + if( CHAR_getWorkInt( toindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_LOCK )return; +#endif + snprintf(msg, sizeof(msg), "T|%d|%s|A", fd, mycharaname); + lssproto_TD_send( tofd, msg); + TRADE_SwapItem(meindex, toindex, message, fd, mycharaname, tofd, tocharaname); + } +#ifndef _TRADESYSTEM2 + else{ + if( CONNECT_get_confirm( fd) == TRUE ) return; + CONNECT_set_confirm(fd, TRUE); + snprintf( msg, sizeof(msg), "T|%d|%s|C", fd, mycharaname); + lssproto_TD_send( tofd, msg); + } +#endif + } + break; + case 'c': + if( CONNECT_get_confirm( fd) == TRUE ) return; + CONNECT_set_confirm(fd, TRUE); + snprintf( msg, sizeof(msg), "T|%d|%s|C", fd, mycharaname); + lssproto_TD_send( tofd, msg); + break; + } + return; +} + +void TRADE_SwapItem( int meindex, int toindex, char* message, int fd, char* mycharaname, int tofd, char* tocharaname) +{ + int result; + char msg[128], tmpmsg[128]; + +#ifndef _ITEM_PILEFORTRADE + CONNECT_setTradeTmp(fd, message); +#endif + + result = TRADE_CheckItembuf(fd, meindex, toindex, tofd, mycharaname, tocharaname); +#ifndef _ITEM_PILEFORTRADE + toindex = CONNECT_getCharaindex(tofd); +#endif + + if (!CHAR_CHECKINDEX(toindex)) return; + if (result == -1) + strcpy(msg, TRADE_FAILED); + else if (result == -2) + sprintf(msg, TRADE_ITEMFULL, mycharaname); + else if (result == -3) + sprintf(msg, TRADE_ITEMFULL, tocharaname); + else if (result == -4) + sprintf(msg, TRADE_RICH, mycharaname); + else if (result == -5) + sprintf(msg, TRADE_POOR, mycharaname); + else if (result == -6) + sprintf(msg, TRADE_RICH, tocharaname); + else if (result == -7) + sprintf(msg, TRADE_POOR, tocharaname); + else if (result == -8) + sprintf(msg, TRADE_TOORICH, mycharaname); + else if (result == -9) + sprintf(msg, TRADE_TOORICH, tocharaname); + else if (result == -10) + sprintf(msg, TRADE_PETFULL, mycharaname); + else if (result == -11) + sprintf(msg, TRADE_PETFULL, tocharaname); + else if (result == -12) + strcpy(msg, TRADE_VANISHITEM); + else if (result == -13) + sprintf(msg, TRADE_POORLV, mycharaname); + else if (result == -14) + sprintf(msg, TRADE_POORLV, tocharaname); + else if (result == -15) + strcpy(msg, TRADE_FMPET); +#ifdef _LOCK_PET_ITEM + else if (result == -16) + strcpy(msg, TRADE_LOCKPET); + else if (result == -17) + strcpy(msg, TRADE_LOCKITEM); + else if (result == -18) + strcpy(msg, TRADE_LOCKPETITEM); +#endif + else if (result == -19) + strcpy(msg, TRADE_NOITEM); + else if (result == -20) + strcpy(msg, TRADE_NOPET); + + else if (result == 1) + strcpy(msg, TRADE_SUCCESS); + else if (result == 2) + strcpy(msg, TRADE_LOCK); +#ifdef _TRADESYSTEM2 + else if (result == 3) + strcpy(msg, "ʼPK"); +#endif + + if (result != 2){ + snprintf(tmpmsg, sizeof(tmpmsg), "W|%d|%s", fd, mycharaname); + lssproto_TD_send(tofd, tmpmsg); + snprintf(tmpmsg, sizeof(tmpmsg), "W|%d|%s", tofd, tocharaname); + lssproto_TD_send(fd, tmpmsg); + + CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CHAR_setWorkInt(toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE); + CONNECT_setTradeTmp(fd, ""); + CONNECT_setTradeTmp(tofd, ""); + CHAR_sendTradeEffect( meindex, 0); + CHAR_sendTradeEffect( toindex, 0); + } + CHAR_sendStatusString(meindex, "i"); + CHAR_sendStatusString(toindex, "i"); + CHAR_sendStatusString(meindex, "P"); + CHAR_sendStatusString(toindex, "P"); + { + int j, petindex; + char msgbuf[256]; + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet( meindex, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( meindex, msgbuf ); + } + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet( toindex, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( toindex, msgbuf ); + } + } + + CHAR_talkToCli(meindex, -1, msg, CHAR_COLORYELLOW); + CHAR_talkToCli(toindex, -1, msg, CHAR_COLORYELLOW); + +#ifdef _SAMETHING_SAVEPOINT + if (result == 1){ + if(CHAR_charSaveFromConnect(meindex, FALSE)){ + CHAR_talkToCli(meindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } + + if(CHAR_charSaveFromConnect(toindex, FALSE)){ + CHAR_talkToCli(toindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } + } +#endif +} + +#ifdef _ITEM_PILEFORTRADE + +int TRADE_HandleTrade_DelItem( int charaindex, int MyMaxPile, int MaxPile, int *Item, int *nums, int *indexlist) +{ + int i, k; + + for( i=0; i<50; i++){ + indexlist[i] = -1; + } + k=0; + for( i=0; i<15; i++ ){ + int pilenum, itemindex, totalnums, newindex; + if( Item[i] == -1 ) continue; + itemindex = CHAR_getItemIndex( charaindex, Item[i] ); + if( !ITEM_CHECKINDEX( itemindex)) return -1; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + pilenum -= nums[i]; + if( pilenum < 0 ) return -1; + if( pilenum == 0 ){ + CHAR_setItemIndex( charaindex, Item[i], -1); + CHAR_sendItemDataOne( charaindex, Item[i]); + indexlist[k] = itemindex; + k++; + totalnums = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + newindex = itemindex; + }else{ + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + newindex = ITEM_makeItemAndRegist( ITEM_getInt( itemindex, ITEM_ID)); + if( !ITEM_CHECKINDEX( newindex) ) return -1; + indexlist[k] = newindex; + k++; + totalnums = nums[i]; + } + if( totalnums > MaxPile ){ + totalnums -= MaxPile; + ITEM_setInt( newindex, ITEM_USEPILENUMS, MaxPile); + }else{ + ITEM_setInt( newindex, ITEM_USEPILENUMS, totalnums); + totalnums = 0; + } + + while( totalnums > 0 ){ + newindex = ITEM_makeItemAndRegist( ITEM_getInt( itemindex, ITEM_ID)); + if( !ITEM_CHECKINDEX( newindex) ) return -1; + indexlist[k] = newindex; + k++; + if( totalnums > MaxPile ){ + totalnums -= MaxPile; + ITEM_setInt( newindex, ITEM_USEPILENUMS, MaxPile); + }else{ + ITEM_setInt( newindex, ITEM_USEPILENUMS, totalnums); + totalnums = 0; + } + } + } + return k; +} + +int TRADE_HandleTrade_DelPet( int charaindex, int *Pet, int *indexlist) +{ + int i, k, petindex; + k=0; + char category[8]; + + for( i=0; i<5; i++){ + indexlist[i] = -1; + } + for( i=0; i<5; i++ ){ + if( Pet[i] == -1 ) continue; + petindex = CHAR_getCharPet( charaindex, Pet[i] ); + if( !CHAR_CHECKINDEX( petindex)) return -1; + CHAR_setCharPet( charaindex, Pet[i], -1); + + snprintf( category, sizeof( category ), "K%d", Pet[i] ); + CHAR_sendStatusString( charaindex, category ); + snprintf( category, sizeof( category ), "W%d", Pet[i] ); + CHAR_sendStatusString( charaindex, category ); + + indexlist[k] = petindex; + k++; + } + return k; +} + +BOOL TRADE_HandleTrade_DelGold( int charaindex, int sGold, int *Gold) +{ + int MyGold, MyMaxGold; + + MyGold = CHAR_getInt( charaindex, CHAR_GOLD); + MyMaxGold = CHAR_getMaxHaveGold( charaindex); + + MyGold -= sGold; + if( MyGold < 0 || MyGold > MyMaxGold ){ + MyGold = (MyGold<0)?0:MyGold; + MyGold = (MyGold>MyMaxGold)?MyMaxGold:MyGold; + CHAR_setInt( charaindex, CHAR_GOLD, MyGold); + return FALSE; + } + CHAR_setInt( charaindex, CHAR_GOLD, MyGold); + *Gold = sGold; + + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + return TRUE; +} + +BOOL TRADE_HandleTrade_AddItem( int charaindex, int *Item) +{ + int ret, i; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charaindex); +#endif + for( i=0; i<50; i++){ + if( Item[i] == -1 )break; + ret = CHAR_addItemSpecificItemIndex( charaindex, Item[i]); +#ifdef _NEW_ITEM_ + if( ret < 0 || ret >= itemMax ) { +#else + if( ret < 0 || ret >= CHAR_MAXITEMHAVE ) { +#endif + int j; + for( j=i; j< 50; j++) + ITEM_endExistItemsOne( Item[j]); + return FALSE; + } +#ifdef _FIRST_LOCK_ITEM + else{ + FreeFirstLockItem(charaindex, Item[i]); +/* + int i; + for(i = 0; i < 32; i ++){ + if(ITEM_getInt(Item[i], ITEM_ID) == getFirstLockItem( i )){ + char *arg = ITEM_getChar(Item[i], ITEM_NAME); + if(arg[0] != '*'){ + char newname[256]; + sprintf(newname, "*%s", ITEM_getChar(Item[i], ITEM_NAME)); + ITEM_setChar(Item[i], ITEM_NAME, newname); + ITEM_setChar(Item[i], ITEM_SECRETNAME, newname); + break; + } + } + } +*/ + } +#endif + } + return TRUE; +} + +BOOL TRADE_HandleTrade_AddPet( int charaindex, int *Pet) +{ + int havepetelement, i; + char category[8]; + for( i=0; i<5; i++){ +#ifdef _PETFOLLOW_NEW_ + havepetelement = CHAR_getCharPetElementOld( charaindex); +#else + havepetelement = CHAR_getCharPetElement( charaindex); +#endif + if( Pet[i] == -1 ) break; + if( havepetelement < 0 ){ + int j; + for( j=i; j<5; j++){ + CHAR_endCharOneArray( Pet[j] ); + } + return FALSE; + } + +#ifdef _PET_ITEM + CHAR_sendPetItemData(charaindex,havepetelement); +#endif + +#ifdef _FIRST_LOCK_ITEM + FreeFirstLockPet(charaindex, Pet[i]); +#endif + + CHAR_setCharPet( charaindex, havepetelement, Pet[i]); + CHAR_setWorkInt( Pet[i], CHAR_WORKPLAYERINDEX, charaindex); + CHAR_setChar( Pet[i], CHAR_OWNERCDKEY, CHAR_getChar( charaindex, CHAR_CDKEY)); + CHAR_setChar( Pet[i], CHAR_OWNERCHARANAME, CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_complianceParameter( Pet[i]); + + snprintf( category, sizeof( category ), "K%d", havepetelement ); + CHAR_sendStatusString( charaindex, category ); + snprintf( category, sizeof( category ), "W%d", havepetelement ); + CHAR_sendStatusString( charaindex, category ); + } + return TRUE; +} + +BOOL TRADE_HandleTrade_AddGold( int charaindex, int sGold) +{ + int MyGold, MyMaxGold; + MyGold = CHAR_getInt( charaindex, CHAR_GOLD); + MyMaxGold = CHAR_getMaxHaveGold( charaindex); + + MyGold += sGold; + + MyGold = (MyGold<0)?0:MyGold; + MyGold = (MyGold>MyMaxGold)?MyMaxGold:MyGold; + + CHAR_setInt( charaindex, CHAR_GOLD, MyGold); + + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + return TRUE; +} + +BOOL TRADE_HandleTrade( int meindex, STradeList *temp1, int toindex, STradeList *temp2 ) +{ + int MeMaxPile, ToMaxPile, ret; + int MeItem[50], ToItem[50]; + int MePet[5], ToPet[5]; + int MeGold=0, ToGold=0; + + MeMaxPile = CHAR_getMyMaxPilenum( meindex);//ѵ + ToMaxPile = CHAR_getMyMaxPilenum( toindex); + //Ƴmeindex + //Ƴtoindex + { + char buf[256]; + + memset( buf, 0, sizeof( buf)); + sprintf( buf, "A.%s[%s] trade B.%s[%s] FXY[%d,%d,%d]", + CHAR_getChar( meindex, CHAR_NAME), CHAR_getChar(meindex, CHAR_CDKEY), + CHAR_getChar( toindex, CHAR_NAME), CHAR_getChar(toindex, CHAR_CDKEY), + CHAR_getInt( meindex, CHAR_FLOOR), CHAR_getInt( meindex, CHAR_X), CHAR_getInt( meindex, CHAR_Y) ); + LogTrade(buf); + } + + //Ƴ + if( (ret=TRADE_HandleTrade_DelItem( meindex, MeMaxPile, ToMaxPile, temp1->ItemTi, temp1->ItemNum, ToItem ))== -1 ) return FALSE; + if( (ret=TRADE_HandleTrade_DelItem( toindex, ToMaxPile, MeMaxPile, temp2->ItemTi, temp2->ItemNum, MeItem ))== -1 ) return FALSE; + + if( (ret=TRADE_HandleTrade_DelPet( meindex, temp1->PetTi, ToPet)) == -1 ) return FALSE; + if( (ret=TRADE_HandleTrade_DelPet( toindex, temp2->PetTi, MePet)) == -1 ) return FALSE; + if( TRADE_HandleTrade_DelGold( meindex, temp1->Golds, &ToGold) == FALSE ) return FALSE; + if( TRADE_HandleTrade_DelGold( toindex, temp2->Golds, &MeGold) == FALSE ) return FALSE; + // + if( TRADE_HandleTrade_AddItem( meindex, MeItem) == FALSE ) return FALSE; + if( TRADE_HandleTrade_AddItem( toindex, ToItem) == FALSE ) return FALSE; + if( TRADE_HandleTrade_AddPet( meindex, MePet) == FALSE) return FALSE; + if( TRADE_HandleTrade_AddPet( toindex, ToPet) == FALSE) return FALSE; + + TRADE_HandleTrade_AddGold( meindex, MeGold); + TRADE_HandleTrade_AddGold( toindex, ToGold); + + { + char buf1[4096], buf2[4096], buf[256]; + int i; + + sprintf( buf1, "A.ITEM.%s:%s" + , CHAR_getChar( meindex, CHAR_NAME), CHAR_getChar(meindex, CHAR_CDKEY) + , CHAR_getChar( toindex, CHAR_NAME), CHAR_getChar(toindex, CHAR_CDKEY)); + sprintf( buf2, "B.ITEM.%s:%s" + , CHAR_getChar( meindex, CHAR_NAME), CHAR_getChar(meindex, CHAR_CDKEY) + , CHAR_getChar( toindex, CHAR_NAME), CHAR_getChar(toindex, CHAR_CDKEY)); + for( i=0; i<50; i++){ + if( ITEM_CHECKINDEX( ToItem[i]) ){ + sprintf( buf, "%s[%s]*%d,", + ITEM_getChar( ToItem[i], ITEM_NAME), ITEM_getChar( ToItem[i], ITEM_UNIQUECODE), + ITEM_getInt( ToItem[i], ITEM_USEPILENUMS) ); + strcat( buf1, buf); + } + if( ITEM_CHECKINDEX( MeItem[i]) ){ + sprintf( buf, "%s[%s]*%d,", + ITEM_getChar( MeItem[i], ITEM_NAME), ITEM_getChar( MeItem[i], ITEM_UNIQUECODE), + ITEM_getInt( MeItem[i], ITEM_USEPILENUMS) ); + strcat( buf2, buf); + } + } + strcat( buf1, "PET."); + strcat( buf2, "PET."); + for( i=0; i<5; i++){ + if( CHAR_CHECKINDEX( ToPet[i]) ){ + sprintf( buf, "%s[%s]%s-%d", + CHAR_getUseName( ToPet[i]), CHAR_getChar( ToPet[i], CHAR_UNIQUECODE), + CHAR_getChar( ToPet[i], CHAR_NAME), CHAR_getInt( ToPet[i], CHAR_LV) ); + strcat( buf1, buf); + } + if( CHAR_CHECKINDEX( MePet[i]) ){ + sprintf( buf, "%s[%s]%s-%d", + CHAR_getUseName( MePet[i]), CHAR_getChar( MePet[i], CHAR_UNIQUECODE), + CHAR_getChar( MePet[i], CHAR_NAME), CHAR_getInt( MePet[i], CHAR_LV) ); + strcat( buf2, buf); + } + } + + + sprintf( buf, "GOLD:%s:%s:%d" + , CHAR_getChar( meindex, CHAR_NAME), CHAR_getChar(meindex, CHAR_CDKEY) + , ToGold); + strcat( buf1, buf); + sprintf( buf, "GOLD:%s:%s:%d" + ,CHAR_getChar( toindex, CHAR_NAME), CHAR_getChar(toindex, CHAR_CDKEY) + , MeGold); + strcat( buf2, buf); + LogTrade( buf1); + LogTrade( buf2); + } + + return TRUE; +} + +#ifdef _TRADE_PK +BOOL TRADE_HandleTradeForPK( STradeList *temp1, STradeList *temp2 ) +{ + int MeMaxPile, ToMaxPile, ret; + int MeItem[50]; + int MePet[5]; + int MeGold=0; + int meindex = temp1->charaindex; + int toindex = temp2->charaindex; + + MeMaxPile = CHAR_getMyMaxPilenum( meindex);//ѵ + ToMaxPile = CHAR_getMyMaxPilenum( toindex); + //Ƴ + + if( (ret=TRADE_HandleTrade_DelItem( toindex, ToMaxPile, MeMaxPile, temp2->ItemTi, temp2->ItemNum, MeItem ))== -1 ) return FALSE; + if( (ret=TRADE_HandleTrade_DelPet( toindex, temp2->PetTi, MePet)) == -1 ) return FALSE; + if( TRADE_HandleTrade_DelGold( toindex, temp2->Golds, &MeGold) == FALSE ) return FALSE; + + // + if( TRADE_HandleTrade_AddItem( meindex, MeItem) == FALSE ) return FALSE; + if( TRADE_HandleTrade_AddPet( meindex, MePet) == FALSE) return FALSE; + TRADE_HandleTrade_AddGold( meindex, MeGold); + + CHAR_talkToCli( meindex, -1, "ϲӮöԷƷ", CHAR_COLORWHITE); + CHAR_talkToCli( toindex, -1, "źԷӮƷ", CHAR_COLORWHITE); + + return TRUE; +} +#endif + +int TRADE_CheckItembuf(int fd, int meindex, int toindex, int tofd, char* mycharaname, char* tocharaname) +{ + int Tradeti; + STradeList TradeListTemp[2]; + if( TRADE_getMyTarget( meindex) != toindex ) return -1; + Tradeti = CONNECT_getTradeList( fd); + if( Tradeti <0 || Tradeti >= MAX_TRADELISTNUM ) return -1; + if( TradeList[Tradeti][0].use != 1 || TradeList[Tradeti][1].use != 1 ) return -1; + if( TRADE_getSomeTradeList( meindex, &TradeListTemp[0]) == FALSE ) return -1; + if( TRADE_getSomeTradeList( toindex, &TradeListTemp[1]) == FALSE ) return -1; + //ȷλ + if( TRADE_CheckTradeList( meindex, &TradeListTemp[0], toindex, &TradeListTemp[1]) == FALSE ) return -1; + //Ƴ + // + +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)==50000 && CHAR_getInt(toindex, CHAR_FLOOR)==50000 ){ + BATTLE_CreateVsPlayerForTrade(TradeListTemp[0], TradeListTemp[1]); + //PK׽ + return 3; + } +#endif + if( TRADE_HandleTrade( meindex, &TradeListTemp[0], toindex, &TradeListTemp[1] ) == FALSE ) return -1; + //׽ + return 1; +} + +#else +int TRADE_CheckItembuf(int fd, int meindex, int toindex, int tofd, char* mycharaname, char* tocharaname) +{ + char a[16], b[16], c[16], d[16], e[16], f[16]; + char g[16], h[16], i[16], j[16], k[16], l[16], token[16]; + int itemindex1 = 0, itemindex2 = 0, itemindex3 = 0; + int itemindex4 = 0, itemindex5 = 0, itemindex6 = 0; + int toitemindex1 = 0, toitemindex2 = 0, toitemindex3 = 0; + int toitemindex4 = 0, toitemindex5 = 0, toitemindex6 = 0; + int item1 = 0, item2 = 0, item4 = 0, item5 = 0, pet3 = 0, pet6 = 0; + int pet1 = 0, pet2 = 0; + int swapitem1 = 0, swapitem2 = 0, gold1 = 0, gold2 = 0; + char itembuf[256], toitembuf[256], buf[4048]; + + CONNECT_getTradeTmp(fd, itembuf, sizeof(itembuf)); + CONNECT_getTradeTmp(tofd, toitembuf, sizeof(toitembuf)); + + // ȶ˫֮ύЭ + if (getStringFromIndexWithDelim(itembuf, "|", 5, token, sizeof(token)) == TRUE) + strcpy(a, token); + if (getStringFromIndexWithDelim(itembuf, "|", 6, token, sizeof(token)) == TRUE) + itemindex1 = atoi(token); + if (getStringFromIndexWithDelim(itembuf, "|", 7, token, sizeof(token)) == TRUE) + strcpy(b, token); + if (getStringFromIndexWithDelim(itembuf, "|", 8, token, sizeof(token)) == TRUE) + itemindex2 = atoi(token); + if (getStringFromIndexWithDelim(itembuf, "|", 9, token, sizeof(token)) == TRUE) + strcpy(c, token); + if (getStringFromIndexWithDelim(itembuf, "|", 10, token, sizeof(token)) == TRUE) + itemindex3 = atoi(token); + if (getStringFromIndexWithDelim(itembuf, "|", 11, token, sizeof(token)) == TRUE) + strcpy(d, token); + if (getStringFromIndexWithDelim(itembuf, "|", 12, token, sizeof(token)) == TRUE) + itemindex4 = atoi(token); + if (getStringFromIndexWithDelim(itembuf, "|", 13, token, sizeof(token)) == TRUE) + strcpy(e, token); + if (getStringFromIndexWithDelim(itembuf, "|", 14, token, sizeof(token)) == TRUE) + itemindex5 = atoi(token); + if (getStringFromIndexWithDelim(itembuf, "|", 15, token, sizeof(token)) == TRUE) + strcpy(f, token); + if (getStringFromIndexWithDelim(itembuf, "|", 16, token, sizeof(token)) == TRUE) + itemindex6 = atoi(token); + + if (getStringFromIndexWithDelim(toitembuf, "|", 5, token, sizeof(token)) == TRUE) + strcpy(g, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 6, token, sizeof(token)) == TRUE) + toitemindex1 = atoi(token); + if (getStringFromIndexWithDelim(toitembuf, "|", 7, token, sizeof(token)) == TRUE) + strcpy(h, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 8, token, sizeof(token)) == TRUE) + toitemindex2 = atoi(token); + if (getStringFromIndexWithDelim(toitembuf, "|", 9, token, sizeof(token)) == TRUE) + strcpy(i, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 10, token, sizeof(token)) == TRUE) + toitemindex3 = atoi(token); + if (getStringFromIndexWithDelim(toitembuf, "|", 11, token, sizeof(token)) == TRUE) + strcpy(j, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 12, token, sizeof(token)) == TRUE) + toitemindex4 = atoi(token); + if (getStringFromIndexWithDelim(toitembuf, "|", 13, token, sizeof(token)) == TRUE) + strcpy(k, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 14, token, sizeof(token)) == TRUE) + toitemindex5 = atoi(token); + if (getStringFromIndexWithDelim(toitembuf, "|", 15, token, sizeof(token)) == TRUE) + strcpy(l, token); + if (getStringFromIndexWithDelim(toitembuf, "|", 16, token, sizeof(token)) == TRUE) + toitemindex6 = atoi(token); + + // shan hjj add ϴ + if (itemindex1==itemindex2){ + if (itemindex1!=-1){ + return -1; + } + } + if (itemindex4==itemindex5){ + if (itemindex4!=-1){ + return -1; + } + } + // End + + if ((strcmp(a, j) == 0) && (strcmp(b, k) == 0) && (strcmp(c,l) == 0) + && (strcmp(d, g) == 0) && (strcmp(e, h) == 0) && (strcmp(f, i) == 0) + && (itemindex1 == toitemindex4) && (itemindex2 == toitemindex5) + && (itemindex3 == toitemindex6) && (itemindex4 == toitemindex1) + && (itemindex5 == toitemindex2) && (itemindex6 == toitemindex3)) + { + // ˫ƷǷпλ + if ((strcmp(a, "I") == 0) && (itemindex1 != -1)){ + swapitem1--; + swapitem2++; + } + if ((strcmp(b, "I") == 0) && (itemindex2 != -1)){ + swapitem1--; + swapitem2++; + } + if ((strcmp(d, "I") == 0) && (itemindex4 != -1)){ + swapitem1++; + swapitem2--; + } + if ((strcmp(e, "I") == 0) && (itemindex5 != -1)){ + swapitem1++; + swapitem2--; + } + if (swapitem1 > CHAR_findTotalEmptyItem(meindex)) + return -2; + toindex = CONNECT_getCharaindex(tofd); + if (!CHAR_CHECKINDEX(toindex)) return -1; + if (swapitem2 > CHAR_findTotalEmptyItem(toindex)) + return -3; + // ˫Ǯ + if ((strcmp(a, "G") == 0) && (itemindex1 != -1)) gold1 += itemindex1; + if ((strcmp(b, "G") == 0) && (itemindex2 != -1)) gold1 += itemindex2; + if ((strcmp(d, "G") == 0) && (itemindex4 != -1)) gold2 += itemindex4; + if ((strcmp(e, "G") == 0) && (itemindex5 != -1)) gold2 += itemindex5; + if (gold1 > CHAR_getMaxHaveGold( meindex) ) return -4; + if (gold1 > CHAR_getInt(meindex, CHAR_GOLD)) return -5; + if (gold2 > CHAR_getMaxHaveGold( toindex)) return -6; + if (gold2 > CHAR_getInt(toindex, CHAR_GOLD)) return -7; + if ((gold2 + CHAR_getInt(meindex, CHAR_GOLD) - gold1) > CHAR_getMaxHaveGold( meindex) ) return -8; + if ((gold1 + CHAR_getInt(toindex, CHAR_GOLD) - gold2) > CHAR_getMaxHaveGold( toindex)) return -9; + // ˫ + if ((strcmp(c, "P") == 0) && (itemindex3 != -1)) + { + pet1--; pet2++; + } + if ((strcmp(f, "P") == 0) && (itemindex6 != -1)) + { + pet1++; pet2--; + } + if ((pet1 > 1) || (pet2 > 1)) return -10; + if ((pet1 == 1) && (CHAR_getCharPetElement( meindex) == -1)) return -10; + if ((pet2 == 1) && (CHAR_getCharPetElement( toindex) == -1)) return -11; + if ((strcmp(a, "I") == 0) && (itemindex1 != -1)) + item1 = CHAR_getItemIndex(meindex, itemindex1); + else item1 = -1; + if ((strcmp(b, "I") == 0) && (itemindex2 != -1)) + item2 = CHAR_getItemIndex(meindex, itemindex2); + else item2 = -1; + if ((strcmp(d, "I") == 0) && (itemindex4 != -1)) + item4 = CHAR_getItemIndex(toindex, itemindex4); + else item4 = -1; + if ((strcmp(e, "I") == 0) && (itemindex5 != -1)) + item5 = CHAR_getItemIndex(toindex, itemindex5); + else item5 = -1; + if (itemindex3 != -1) + { + if( CHAR_getInt( meindex, CHAR_RIDEPET) == itemindex3 ) + return -1; + pet3 = CHAR_getCharPet(meindex, itemindex3); + } + else pet3 = -1; + if (itemindex6 != -1) + { + if( CHAR_getInt( toindex, CHAR_RIDEPET) == itemindex6 ) + return -1; + pet6 = CHAR_getCharPet(toindex, itemindex6); + } + else pet6 = -1; + if ((ITEM_getInt(item1, ITEM_VANISHATDROP) == 1)|| + (ITEM_getInt(item2, ITEM_VANISHATDROP) == 1)|| + (ITEM_getInt(item4, ITEM_VANISHATDROP) == 1)|| + (ITEM_getInt(item5, ITEM_VANISHATDROP) ==1)) + return -12; +#ifdef _LOCK_PET_ITEM + char *arg; + arg = ITEM_getChar(item1, ITEM_NAME); + if(arg[0] == '*'){ + return -17; + } + arg = ITEM_getChar(item2, ITEM_NAME); + if(arg[0] == '*'){ + return -17; + } + arg = ITEM_getChar(item4, ITEM_NAME); + if(arg[0] == '*'){ + return -17; + } + arg = ITEM_getChar(item5, ITEM_NAME); + if(arg[0] == '*'){ + return -17; + } +#endif + + if(FreeTradeItem(meindex, item1) == 1 + || FreeTradeItem(meindex, item2) == 1 + || FreeTradeItem(meindex, item3) == 1 + || FreeTradeItem(meindex, item4) == 1 + || FreeTradeItem(meindex, item5) == 1 ){ + return -19; + } + if( CHAR_getWorkInt( meindex, CHAR_PickAllPet) != TRUE ) { + if ((pet6 != -1) && (CHAR_getInt(pet6, CHAR_LV) + - CHAR_getInt(meindex, CHAR_LV) > 20) + && (CHAR_getInt(meindex,CHAR_TRANSMIGRATION) <= 0)) + return -13; + + } + if( CHAR_getWorkInt( toindex, CHAR_PickAllPet) != TRUE ) { + + if ((pet3 != -1) && (CHAR_getInt(pet3, CHAR_LV) + - CHAR_getInt(toindex, CHAR_LV) > 5) + && (CHAR_getInt(toindex,CHAR_TRANSMIGRATION) <= 0)) + return -14; + } + if ((pet6 != -1) && (CHAR_getInt(pet6, CHAR_PETFAMILY) == 1)) + return -15; + if ((pet3 != -1) && (CHAR_getInt(pet3, CHAR_PETFAMILY) == 1)) + return -15; +#ifdef _LOCK_PET_ITEM +{ + if (pet6 != -1) { + char *petname = CHAR_getChar( pet6, CHAR_NAME); + if( petname[0] == '*' ){ + return -16; + } +#ifdef _PET_ITEM +{ + int i; + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + int itemindex = CHAR_getItemIndex( pet6, i ); + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + return -18; + } + } +} +#endif + } + if (pet3 != -1) { + char *petname = CHAR_getChar( pet3, CHAR_NAME); + if( petname[0] == '*' ){ + return -16; + } +#ifdef _PET_ITEM +{ + int i; + for( i = 0 ; i < CHAR_MAXPETITEMHAVE ; i ++ ){ + int itemindex = CHAR_getItemIndex( pet3, i ); + char *arg = ITEM_getChar(itemindex, ITEM_NAME); + if(arg[0] == '*'){ + return -18; + } + } +} +#endif + } +} +#endif + if (pet6 != -1) { + if(FreeTradePet(meindex, pet6) == 1){ + return -20; + } + } + if (pet3 != -1) { + if(FreeTradePet(meindex, pet3) == 1){ + return -20; + } + } + + TRADE_ChangeItem(meindex, toindex, a, d, item1, item4, + itemindex1, itemindex4); + TRADE_ChangeItem(meindex, toindex, b, e, item2, item5, + itemindex2, itemindex5); + TRADE_ChangeItem(meindex, toindex, c, f, pet3, pet6, + itemindex3, itemindex6); + + // д trade.log + { + char petname1[256], petname2[256]; + int pet1lv, pet2lv; + int logitem1 = 0, logitem2 = 0, logitem4 = 0, logitem5 = 0; + + if ((strcmp(a, "I") == 0) && (item1 != -1)) logitem1 = ITEM_getInt(item1, ITEM_ID); + if ((strcmp(b, "I") == 0) && (item2 != -1)) logitem2 = ITEM_getInt(item2, ITEM_ID); + if ((strcmp(a, "G") == 0) && (item1 == -1)) logitem1 = itemindex1; + if ((strcmp(b, "G") == 0) && (item2 == -1)) logitem2 = itemindex2; + if ((strcmp(c, "P") == 0) && (pet3 == -1)) + { + sprintf(petname1, "NONE"); + pet1lv = 0; + } + else + { + sprintf(petname1, "%s", CHAR_getChar(pet3, CHAR_NAME)); + pet1lv = CHAR_getInt(pet3, CHAR_LV); + } + if ((strcmp(f, "P") == 0) && (pet6 == -1)) + { + sprintf(petname2, "NONE"); + pet2lv = 0; + } + else + { + sprintf(petname2, "%s", CHAR_getChar(pet6, CHAR_NAME)); + pet2lv = CHAR_getInt(pet6, CHAR_LV); + } + if ((strcmp(d, "I") == 0) && (item4 != -1)) logitem4 = ITEM_getInt(item4, ITEM_ID); + if ((strcmp(e, "I") == 0) && (item5 != -1)) logitem5 = ITEM_getInt(item5, ITEM_ID); + if ((strcmp(d, "G") == 0) && (item4 == -1)) logitem4 = itemindex4; + if ((strcmp(e, "G") == 0) && (item5 == -1)) logitem5 = itemindex5; + sprintf(buf, "%s\t%s\t(%s[%d,%s],%s[%d,%s],%s[%s,%d,%s]) <-> %s\t%s\t(%s[%d,%s],%s[%d,%s],%s[%s,%d,%s])", + CHAR_getChar(meindex, CHAR_CDKEY), mycharaname, + a, logitem1, ITEM_getChar( item1, ITEM_UNIQUECODE), b, logitem2, ITEM_getChar( item2, ITEM_UNIQUECODE), + c, petname1, pet1lv, CHAR_getChar( pet3, CHAR_UNIQUECODE), + CHAR_getChar(toindex, CHAR_CDKEY), tocharaname, + d, logitem4, ITEM_getChar( item4, ITEM_UNIQUECODE), e, logitem5, ITEM_getChar( item5, ITEM_UNIQUECODE), + f, petname2, pet2lv, CHAR_getChar( pet6, CHAR_UNIQUECODE)); + LogTrade(buf); + } + + return 1; + } + return 2; +} + +#endif +BOOL TRADE_ChangeItem(int meindex, int toindex, char *a, char *b, + int item1, int item2, int itemindex1, int itemindex2) +{ + int gold1 = 0, gold2 = 0, eptitem = -1; + if (CHAR_CHECKINDEX(meindex) == FALSE) return FALSE; + if (CHAR_CHECKINDEX(toindex) == FALSE) return FALSE; + // <-> + if ((strcmp(a, "I") == 0) && (strcmp(b, "I") == 0)) + { + // <-> + if ((itemindex1 == -1) && (itemindex2 > 0)) + { + if (ITEM_CHECKINDEX(item2) == FALSE) return FALSE; + eptitem = CHAR_findEmptyItemBox(meindex); + if (eptitem < 0) return FALSE; + CHAR_setItemIndex(meindex, eptitem, item2); + ITEM_setWorkInt(item2, ITEM_WORKCHARAINDEX, meindex); + ITEM_setWorkInt(item2, ITEM_WORKOBJINDEX, -1); + CHAR_setItemIndex(toindex, itemindex2, -1); + } + // <-> + else if ((itemindex1 > 0) && (itemindex2 == -1)) + { + if (ITEM_CHECKINDEX(item1) == FALSE) return FALSE; + eptitem = CHAR_findEmptyItemBox(toindex); + if (eptitem < 0) return FALSE; + CHAR_setItemIndex(toindex, eptitem, item1); + ITEM_setWorkInt(item1, ITEM_WORKCHARAINDEX, toindex); + ITEM_setWorkInt(item1, ITEM_WORKOBJINDEX, -1); + CHAR_setItemIndex(meindex, itemindex1, -1); + } + // <-> + else if (itemindex1 > 0 && itemindex2 > 0) + { + if (ITEM_CHECKINDEX(item1) == FALSE) return FALSE; + if (ITEM_CHECKINDEX(item2) == FALSE) return FALSE; + ITEM_setWorkInt(item1, ITEM_WORKCHARAINDEX, toindex); + ITEM_setWorkInt(item1, ITEM_WORKOBJINDEX, -1); + ITEM_setWorkInt(item2, ITEM_WORKCHARAINDEX, meindex); + ITEM_setWorkInt(item2, ITEM_WORKOBJINDEX, -1); + CHAR_setItemIndex(toindex, itemindex2, item1); + CHAR_setItemIndex(meindex, itemindex1, item2); + } + } + // <-> Ǯ + else if ((strcmp(a, "I") == 0) && (strcmp(b, "G") == 0)) + { + if (itemindex1 > 0) + { + if (ITEM_CHECKINDEX(item1) == FALSE) return FALSE; + eptitem = CHAR_findEmptyItemBox(toindex); + if (eptitem < 0) return FALSE; + ITEM_setWorkInt(item1, ITEM_WORKCHARAINDEX, toindex); + ITEM_setWorkInt(item1, ITEM_WORKOBJINDEX, -1); + CHAR_setItemIndex(toindex, eptitem, item1); + CHAR_setItemIndex(meindex, itemindex1, -1); + } + if (itemindex2 < 0) itemindex2 = 0; + gold1 = CHAR_getInt(meindex, CHAR_GOLD); + gold1 += itemindex2; + CHAR_setInt(meindex, CHAR_GOLD, gold1); + gold2 = CHAR_getInt(toindex, CHAR_GOLD); + gold2 -= itemindex2; + CHAR_setInt(toindex, CHAR_GOLD, gold2); + } + // Ǯ <-> + else if ((strcmp(a, "G") == 0) && (strcmp(b, "I") == 0)) + { + if (itemindex2 > 0) + { + if (ITEM_CHECKINDEX(item2) == FALSE) return FALSE; + eptitem = CHAR_findEmptyItemBox(meindex); + if (eptitem < 0) return FALSE; + ITEM_setWorkInt(item2, ITEM_WORKCHARAINDEX, meindex); + ITEM_setWorkInt(item2, ITEM_WORKOBJINDEX, -1); + CHAR_setItemIndex(meindex, eptitem, item2); + CHAR_setItemIndex(toindex, itemindex2, -1); + } + if (itemindex1 < 0) itemindex1 = 0; + gold1 = CHAR_getInt(meindex, CHAR_GOLD); + gold1 -= itemindex1; + CHAR_setInt(meindex, CHAR_GOLD, gold1); + gold2 = CHAR_getInt(toindex, CHAR_GOLD); + gold2 += itemindex1; + CHAR_setInt(toindex, CHAR_GOLD, gold2); + } + // Ǯ <-> Ǯ + else if ((strcmp(a, "G") == 0) && (strcmp(b, "G") == 0)) + { + if (itemindex1 < 0) itemindex1 = 0; + if (itemindex2 < 0) itemindex2 = 0; + gold1 = CHAR_getInt(toindex, CHAR_GOLD); + gold1 = gold1 + itemindex1 - itemindex2; + CHAR_setInt(toindex, CHAR_GOLD, gold1); + gold2 = CHAR_getInt(meindex, CHAR_GOLD); + gold2 = gold2 + itemindex2 - itemindex1; + CHAR_setInt(meindex, CHAR_GOLD, gold2); + } + // <-> + else if ((strcmp(a, "P") == 0) && (strcmp(b, "P") == 0)) + { + char category[8]; + if ((item1 != -1) && (CHAR_CHECKINDEX(item1) == FALSE)) return FALSE; + if ((item2 != -1) && (CHAR_CHECKINDEX(item2) == FALSE)) return FALSE; + + if ((itemindex1 != -1) && (itemindex1 == CHAR_getInt(meindex, CHAR_DEFAULTPET))) + { + int fd; + CHAR_setInt(meindex, CHAR_DEFAULTPET, -1); + fd = getfdFromCharaIndex(meindex); + if (fd != -1){ + CHAR_setWorkInt( meindex, CHAR_WORK_PET0_STAT+itemindex1-1, 0); + lssproto_KS_send(fd, itemindex1, 0); + } + } + if ((itemindex2 != -1)&& (itemindex2 == CHAR_getInt(toindex, CHAR_DEFAULTPET))) + { + int tofd; + CHAR_setInt(toindex, CHAR_DEFAULTPET, -1); + tofd = getfdFromCharaIndex(toindex); + if (tofd != -1){ + CHAR_setWorkInt( toindex, CHAR_WORK_PET0_STAT+itemindex1-1, 0); + lssproto_KS_send(tofd, itemindex2, 0); + } + } + + if (item1 != -1) + CHAR_setWorkInt(item1, CHAR_WORKPLAYERINDEX, toindex); + if (item2 != -1) + CHAR_setWorkInt(item2, CHAR_WORKPLAYERINDEX, meindex); + if (itemindex1 == -1) + itemindex1 = CHAR_getCharPetElement( meindex); + if (itemindex2 == -1) + itemindex2 = CHAR_getCharPetElement( toindex); + CHAR_setCharPet(meindex, itemindex1, item2); + CHAR_setCharPet(toindex, itemindex2, item1); + if ((itemindex1 != -1) && (item1 != -1)) { + + CHAR_setChar(item1, CHAR_OWNERCDKEY, + CHAR_getChar(toindex, CHAR_CDKEY)); + CHAR_setChar(item1, CHAR_OWNERCHARANAME, + CHAR_getChar(toindex, CHAR_NAME)); + + CHAR_complianceParameter(item1); + CHAR_setInt(item1, CHAR_PUTPETTIME, 0); + } + if ((itemindex2 != -1) && (item2 != -1)) { + + CHAR_setChar(item2, CHAR_OWNERCDKEY, + CHAR_getChar(meindex, CHAR_CDKEY)); + CHAR_setChar(item2, CHAR_OWNERCHARANAME, + CHAR_getChar(meindex, CHAR_NAME)); + + CHAR_complianceParameter(item2); + CHAR_setInt(item2, CHAR_PUTPETTIME, 0); + } + snprintf(category, sizeof(category), "K%d", itemindex1); + CHAR_sendStatusString(meindex, category); + snprintf(category, sizeof(category), "W%d", itemindex1); + CHAR_sendStatusString(meindex, category); + snprintf(category, sizeof(category), "K%d", itemindex2); + CHAR_sendStatusString(toindex, category); + snprintf(category, sizeof(category), "W%d", itemindex2); + CHAR_sendStatusString(toindex, category); + } + return TRUE; +} + +BOOL TRADE_HandleItem( int meindex, int showindex, char *message, char *outmess) +{ + char token[256]; + int item, itemindex; + int fd = getfdFromCharaIndex( meindex ); + + if( CONNECT_get_confirm( fd) == TRUE ) return FALSE; + + if( CHAR_getWorkInt( meindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_TRADING + || CHAR_getWorkInt( meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK ) + return FALSE; + + if( getStringFromIndexWithDelim( message, "|", 6, token, sizeof( token)) == FALSE) return FALSE; + item = atoi( token); + +#ifdef _NEW_ITEM_ + if( item < CHAR_STARTITEMARRAY || item > CheckCharMaxItem(meindex) ){ +#else + if( item < CHAR_STARTITEMARRAY || item > CHAR_MAXITEMHAVE ){ +#endif + return FALSE; + } + itemindex = CHAR_getItemIndex(meindex, item); + if( !ITEM_CHECKINDEX( itemindex)) return FALSE; + + { + char itemname[256], tmpbuf[256], tmpbuf1[256]; + +#ifdef _ITEM_PILEFORTRADE + int nums = 0; + if( TRADE_addSomeTradeList( meindex, item, &nums, TRADE_ITEM) == FALSE ){ + return FALSE; + } +#endif + strcpy( itemname, ITEM_getChar(itemindex, ITEM_SECRETNAME));//ITEM_NAME + + // if(strstr(itemname,"֧Ʊ")!=NULL){ +// strcat(itemname,ITEM_getChar(itemindex, ITEM_EFFECTSTRING)); +// } + sprintf( token, ""); +#ifdef _TAKE_ITEMDAMAGE + int crushe = ITEM_getItemDamageCrusheED( itemindex); + if( crushe >= 0 ) snprintf( token, sizeof(token), "%d%%", crushe ); +#endif +#ifdef _ITEM_PILENUMS + sprintf( outmess, "%d|%s|%s|%s|%d|%s|%d", +#else + sprintf( outmess, "%d|%s|%s|%d|%s", +#endif + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + makeEscapeString( ITEM_getChar( itemindex, ITEM_NAME), tmpbuf1, sizeof(tmpbuf1)), +#ifdef _ITEM_PILENUMS + makeEscapeString( itemname, tmpbuf, sizeof(tmpbuf)), +#endif + ITEM_getChar(itemindex,ITEM_EFFECTSTRING), item, token +#ifdef _ITEM_PILEFORTRADE + ,nums +#endif + ); + } + return TRUE; +} + +BOOL TRADE_HandleGold( int meindex, int showindex, char *message, char *outmess) +{ + int gold, tmpgold; + char token[256]; + int fd = getfdFromCharaIndex( meindex ); + if(CONNECT_get_confirm( fd)==TRUE)return FALSE; + if (CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_TRADING + || CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK) + return FALSE; + tmpgold = CHAR_getInt(meindex, CHAR_GOLD); + if (getStringFromIndexWithDelim(message, "|", 6, token, sizeof(token)) == FALSE) return FALSE; + if( (gold = atoi(token)) < 0 ) return FALSE; + if( gold > tmpgold )return FALSE; +#ifdef _ITEM_PILEFORTRADE + if( TRADE_addSomeTradeList( meindex, gold, NULL, TRADE_GOLD) == FALSE ) return FALSE; +#endif + sprintf( outmess, "%d", gold); + return TRUE; +} + +BOOL TRADE_HandlePet( int meindex, int showindex, char *message, char *outmess) +{ + int havepetindex, petindex; + char token[256], buf[256]; + int fd = getfdFromCharaIndex( meindex ); + if(CONNECT_get_confirm( fd)==TRUE)return FALSE; + if (CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_TRADING + || CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK) + return FALSE; + if (getStringFromIndexWithDelim(message, "|", 6, token, sizeof(token)) == FALSE) return FALSE; + if( (havepetindex = atoi(token)) < 0 ) return FALSE; + petindex = CHAR_getCharPet(meindex, havepetindex); + if( !CHAR_CHECKINDEX(petindex)) return FALSE; + +#ifdef _ITEM_PILEFORTRADE + if( TRADE_addSomeTradeList( meindex, havepetindex, NULL, TRADE_PET) == FALSE ) return FALSE; +#endif +#ifdef _POWER_UP +{ + char str[][4] = {"", "A", "B", "C", "D"}; + char buff[64]; + int value = 0; + int type = 0; + + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 1, buff , sizeof(buff) ) == TRUE){ + type = atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 2, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 3, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 4, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + + if(type > 0){ + sprintf( token, "%d|%s %s+%d|%d|%d|%d|%d|%d|%d", + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + makeEscapeString( CHAR_getUseName(petindex), buf, sizeof(buf)),str[type], value, + CHAR_getInt( petindex, CHAR_LV), + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKQUICK), + havepetindex, + CHAR_getInt( petindex , CHAR_TRANSMIGRATION)); + }else{ +#ifdef _SHOW_VISUAL_BEATITUDE + char buff2[256]; + int workatt,workdef,workdex; + workatt = CHAR_getWorkInt(petindex,CHAR_WORKATTACKPOWER); + workdef = CHAR_getWorkInt(petindex,CHAR_WORKDEFENCEPOWER); + workdex = CHAR_getWorkInt(petindex,CHAR_WORKQUICK); + if (CHAR_getChar(petindex,CHAR_VB) != NULL){ + getStringFromIndexWithDelim(CHAR_getChar(petindex,CHAR_VB),"|",2,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workatt = -1*(workatt); + getStringFromIndexWithDelim(CHAR_getChar(petindex,CHAR_VB),"|",3,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workdef = -1*(workdef); + getStringFromIndexWithDelim(CHAR_getChar(petindex,CHAR_VB),"|",4,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workdex = -1*(workdex); + } + sprintf( token, "%d|%s|%d|%d|%d|%d|%d|%d", + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + makeEscapeString( CHAR_getUseName(petindex), buf, sizeof(buf)), + CHAR_getInt( petindex, CHAR_LV), + workatt, + workdef, + workdex, + havepetindex, + CHAR_getInt( petindex , CHAR_TRANSMIGRATION)); + +#else + sprintf( token, "%d|%s|%d|%d|%d|%d|%d|%d", + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + makeEscapeString( CHAR_getUseName(petindex), buf, sizeof(buf)), + CHAR_getInt( petindex, CHAR_LV), + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKQUICK), + havepetindex, + CHAR_getInt( petindex , CHAR_TRANSMIGRATION)); +#endif + } +} +#else + sprintf( token, "%d|%s|%d|%d|%d|%d|%d|%d", + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER), + makeEscapeString( CHAR_getUseName(petindex), buf, sizeof(buf)), + CHAR_getInt( petindex, CHAR_LV), + CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKDEFENCEPOWER), + CHAR_getWorkInt( petindex, CHAR_WORKQUICK), + havepetindex, + CHAR_getInt( petindex , CHAR_TRANSMIGRATION)); +#endif + +#ifdef _TRADESYSTEM2 + { + int i; + char skillname[7][256]; + char buf1[256],buf2[256]; + for( i=0; i<7; i++){ + int skillarray, skillID; + memset( skillname[i], 0, sizeof(skillname[i])); + skillID = CHAR_getPetSkill( petindex, i); + skillarray = PETSKILL_getPetskillArray( skillID); + if( !PETSKILL_CHECKINDEX( skillarray)) continue; + sprintf( skillname[i], "%s", PETSKILL_getChar( skillarray, PETSKILL_NAME) ); + } +#ifdef _POWER_UP +{ + char str[][4] = {"", "A", "B", "C", "D"}; + char buff[64]; + int value = 0; + int type = 0; + + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 1, buff , sizeof(buff) ) == TRUE){ + type = atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 2, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 3, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + if(getStringFromIndexWithDelim( CHAR_getChar(petindex, CHAR_POWER_UP) , "|" , 4, buff , sizeof(buff) ) == TRUE){ + value += atoi(buff); + } + + if(type > 0){ + sprintf( outmess , "%s|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s %s+%d|%s %s+%d|" +#ifdef _SHOW_FUSION + "%d|" +#endif + ,token , CHAR_getWorkInt(petindex , CHAR_WORKMAXHP) , CHAR_getInt(petindex , CHAR_SLOT) + ,skillname[0] , skillname[1] , skillname[2] , skillname[3] + ,skillname[4] , skillname[5] , skillname[6] + ,makeEscapeString( CHAR_getChar( petindex, CHAR_NAME ), buf1, sizeof(buf1)),str[type], value + ,makeEscapeString( CHAR_getUseName( petindex), buf2, sizeof(buf2)),str[type], value +#ifdef _SHOW_FUSION + ,CHAR_getInt ( petindex, CHAR_FUSIONBEIT) +#endif + ); + + }else{ +#ifdef _SHOW_VISUAL_BEATITUDE + char buff2[256]; + int workhp; + workhp = CHAR_getWorkInt(petindex,CHAR_WORKMAXHP); + if (CHAR_getChar(petindex,CHAR_VB) != NULL){ + getStringFromIndexWithDelim(CHAR_getChar(petindex,CHAR_VB),"|",1,buff2,sizeof(buff2)); + if (atoi(buff2)>0)workhp = -1*(workhp); + } + sprintf( outmess , "%s|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%s|" +#ifdef _SHOW_FUSION + "%d|" +#endif + ,token , workhp , CHAR_getInt(petindex , CHAR_SLOT) + ,skillname[0] , skillname[1] , skillname[2] , skillname[3] + ,skillname[4] , skillname[5] , skillname[6] + ,makeEscapeString( CHAR_getChar( petindex, CHAR_NAME ), buf1, sizeof(buf1)) + ,makeEscapeString( CHAR_getUseName( petindex), buf2, sizeof(buf2)) +#ifdef _SHOW_FUSION + ,CHAR_getInt ( petindex, CHAR_FUSIONBEIT) +#endif + ); +#else + + sprintf( outmess , "%s|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%s|" +#ifdef _SHOW_FUSION + "%d|" +#endif + ,token , CHAR_getWorkInt(petindex , CHAR_WORKMAXHP) , CHAR_getInt(petindex , CHAR_SLOT) + ,skillname[0] , skillname[1] , skillname[2] , skillname[3] + ,skillname[4] , skillname[5] , skillname[6] + ,makeEscapeString( CHAR_getChar( petindex, CHAR_NAME ), buf1, sizeof(buf1)) + ,makeEscapeString( CHAR_getUseName( petindex), buf2, sizeof(buf2)) +#ifdef _SHOW_FUSION + ,CHAR_getInt ( petindex, CHAR_FUSIONBEIT) +#endif + ); +#endif + } +} +#else + sprintf( outmess , "%s|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%s|" +#ifdef _SHOW_FUSION + "%d|", +#endif + ,token , CHAR_getWorkInt(petindex , CHAR_WORKMAXHP) , CHAR_getInt(petindex , CHAR_SLOT) + ,skillname[0] , skillname[1] , skillname[2] , skillname[3] + ,skillname[4] , skillname[5] , skillname[6] + ,makeEscapeString( CHAR_getChar( petindex, CHAR_NAME ), buf1, sizeof(buf1)) + ,makeEscapeString( CHAR_getUseName( petindex), buf2, sizeof(buf2)) +#ifdef _SHOW_FUSION + ,CHAR_getInt ( petindex, CHAR_FUSIONBEIT) +#endif + ); +#endif + +#ifdef _PET_VALIDITY + { + char token[256]; + if(CHAR_getInt ( petindex, CHAR_PETVALIDITY)==0){ + snprintf( token, sizeof( token ), "Ч" STATUSSENDDELIMITER); + }else if(CHAR_getInt ( petindex, CHAR_PETVALIDITY)>time(NULL)){ + time_t petvalidity = (time_t)CHAR_getInt(petindex, CHAR_PETVALIDITY); + struct tm *tm1 = localtime(&petvalidity); + + snprintf( token, sizeof( token ), "%04d-%02d-%02d|", + tm1->tm_year + 1900, + tm1->tm_mon + 1, + tm1->tm_mday); + }else{ + snprintf( token, sizeof( token ), "Ѿ" STATUSSENDDELIMITER); + } + + strcat( outmess,token ); + } +#endif + +#ifdef _PET_ITEM + char token[512]=""; + int j; + for( j = 0 ; j < CHAR_MAXPETITEMHAVE ; j ++ ) + strcat(token,ITEM_petmakeItemStatusString(petindex, j)); + strcat(outmess,token); +#endif + } +#else + sprintf( outmess , "%s|%d", token , CHAR_getWorkInt(petindex , CHAR_WORKMAXHP) ); +#endif //_TRADESYSTEM2 + return TRUE; +} + +#ifdef _ITEM_PILEFORTRADE +BOOL TRADE_CheckTradeList( int meindex, STradeList *temp1, int toindex, STradeList *temp2) +{ + int i; + int MeSurplus=0, MeNeeds=0, MeMaxPile; + int ToSurplus=0, ToNeeds=0, ToMaxPile; + + + MeMaxPile = CHAR_getMyMaxPilenum( meindex);//ѵ + ToMaxPile = CHAR_getMyMaxPilenum( toindex); + + MeSurplus = CHAR_findSurplusItemBox( meindex); + ToSurplus = CHAR_findSurplusItemBox( toindex); + + // + ToNeeds=0; MeNeeds=0; + for( i=0; i<15; i++ ){ + int pilenum, itemindex; + if( temp1->ItemTi[i] == -1 ) continue; + itemindex = CHAR_getItemIndex( meindex, temp1->ItemTi[i] ); + if( !ITEM_CHECKINDEX( itemindex)) return FALSE; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)!=50000 || CHAR_getInt(toindex, CHAR_FLOOR)!=50000){ + if( temp1->ItemNum[i] == pilenum ){ + MeSurplus++; + } + } +#else + if( temp1->ItemNum[i] == pilenum ){ + MeSurplus++; + } +#endif + if( temp1->ItemNum[i] > ToMaxPile ){ + ToNeeds += (temp1->ItemNum[i]/ToMaxPile) + 1; + }else{ + ToNeeds++; + } + } + for( i=0; i<15; i++ ){ + int pilenum, itemindex; + if( temp2->ItemTi[i] == -1 ) continue; + itemindex = CHAR_getItemIndex( toindex, temp2->ItemTi[i] ); + if( !ITEM_CHECKINDEX( itemindex)) return FALSE; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)!=50000 || CHAR_getInt(toindex, CHAR_FLOOR)!=50000){ + if( temp2->ItemNum[i] == pilenum){ + ToSurplus++; + } + } +#else + if( temp2->ItemNum[i] == pilenum){ + ToSurplus++; + } +#endif + + + if( temp2->ItemNum[i] > MeMaxPile ){ + MeNeeds += (temp2->ItemNum[i]/MeMaxPile) + 1; + }else { + MeNeeds++; + } + } + + if( MeSurplus < MeNeeds ){ + CHAR_talkToCli( meindex, -1, "Ʒλ㡣", CHAR_COLORYELLOW); + CHAR_talkToCli( toindex, -1, "ԷƷλ㡣", CHAR_COLORYELLOW); + return FALSE; + } + if( ToSurplus < ToNeeds ){ + CHAR_talkToCli( toindex, -1, "Ʒλ㡣", CHAR_COLORYELLOW); + CHAR_talkToCli( meindex, -1, "ԷƷλ㡣", CHAR_COLORYELLOW); + return FALSE; + } + + // + MeSurplus = CHAR_findSurplusPetBox( meindex); + ToSurplus = CHAR_findSurplusPetBox( toindex); + ToNeeds=0; MeNeeds=0; + + + for( i=0; i<5; i++ ){ + int petindex; + if( temp1->PetTi[i] == -1 ) continue; + petindex = CHAR_getCharPet( meindex, temp1->PetTi[i] ); + if( !CHAR_CHECKINDEX( petindex)) return FALSE; +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)!=50000 || CHAR_getInt(toindex, CHAR_FLOOR)!=50000){ + MeSurplus++; + } +#else + MeSurplus++; +#endif + ToNeeds++; + } + for( i=0; i<5; i++ ){ + int petindex; + if( temp2->PetTi[i] == -1 ) continue; + petindex = CHAR_getCharPet( toindex, temp2->PetTi[i] ); + if( !CHAR_CHECKINDEX( petindex)) return FALSE; +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)!=50000 || CHAR_getInt(toindex, CHAR_FLOOR)!=50000){ + ToSurplus++; + } +#else + ToSurplus++; +#endif + MeNeeds++; + } + + + if( MeSurplus < MeNeeds ){ + CHAR_talkToCli( meindex, -1, "λ㡣", CHAR_COLORYELLOW); + CHAR_talkToCli( toindex, -1, "Էλ㡣", CHAR_COLORYELLOW); + return FALSE; + } + if( ToSurplus < ToNeeds ){ + CHAR_talkToCli( meindex, -1, "Էλ㡣", CHAR_COLORYELLOW); + CHAR_talkToCli( toindex, -1, "λ㡣", CHAR_COLORYELLOW); + return FALSE; + } + + //Ǯ + MeMaxPile = CHAR_getMaxHaveGold( meindex); + ToMaxPile = CHAR_getMaxHaveGold( toindex); + +#ifdef _TRADE_PK + if(CHAR_getInt(meindex, CHAR_FLOOR)!=50000 || CHAR_getInt(toindex, CHAR_FLOOR)!=50000){ + MeSurplus = MeMaxPile - CHAR_getInt( meindex, CHAR_GOLD); + ToSurplus = ToMaxPile - CHAR_getInt( toindex, CHAR_GOLD); + } +#else + MeSurplus = MeMaxPile - CHAR_getInt( meindex, CHAR_GOLD); + ToSurplus = ToMaxPile - CHAR_getInt( toindex, CHAR_GOLD); +#endif + + + ToNeeds=0; MeNeeds=0; + MeSurplus += temp1->Golds; + ToSurplus += temp2->Golds; + ToNeeds = temp1->Golds; + MeNeeds = temp2->Golds; + if( MeSurplus < MeNeeds ){ + CHAR_talkToCli( meindex, -1, "ʯҳޡ", CHAR_COLORYELLOW); + CHAR_talkToCli( toindex, -1, "Էʯҳޡ", CHAR_COLORYELLOW); + return FALSE; + } + if( ToSurplus < ToNeeds ){ + CHAR_talkToCli( meindex, -1, "Էʯҳޡ", CHAR_COLORYELLOW); + CHAR_talkToCli( toindex, -1, "ʯҳޡ", CHAR_COLORYELLOW); + return FALSE; + } + return TRUE; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/configfile.c b/石器时代服务器端最新完整源代码/Serv/gmsv/configfile.c new file mode 100644 index 0000000..ff34203 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/configfile.c @@ -0,0 +1,4356 @@ +#define __CONFIGFILE_C__ +#include "version.h" +#include +#include +#include +#include + +#include "util.h" +//#include "configfile.h" +//ttom +#include "lssproto_util.h" +#include "configfile.h" +#include "net.h" +//ttom end +#include "npcutil.h" +// Arminius 7.12 login announce +#include "char.h" +#include "char_data.h" +// CoolFish: add +#include "lssproto_serv.h" +#include "autil.h" + +#ifdef _ANGEL_SUMMON +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif + +extern char* CHAR_setintdata[CHAR_DATAINTNUM]; +extern char* CHAR_setchardata[CHAR_DATACHARNUM]; + +/* ɬë հ */ +typedef struct tagConfig +{ + /*ة ( ƻ */ + char progname[8]; + char configfilename[32]; /* config̻ */ + unsigned char debuglevel; /* ì */ + unsigned int usememoryunit; /*ƹ */ + unsigned int usememoryunitnum; /*ƹ */ + char asname[32]; /*ʧӡP */ + unsigned short acservport; /*ʧӡP̡ */ + char acpasswd[32]; /*ʧӡ߼ɵ*/ + char gsnamefromas[32]; /* + * ʧӡᆴέ + * ءةӡƻ + */ + + // Arminius 7.24 manor pk + char gsid[32]; // game server chinese id + unsigned short allowmanorpk; // is this server allow manor pk + unsigned short port; /* ӡPа̡ */ + int servernumber; /* ءةӡP į */ + int reuseaddr; /* Address already used... ئݼ׻ */ + int do_nodelay; /* TCP_NODELAY ¾ */ + int log_write_time; /* ̤ķë¾ */ + int log_io_time; /* I/O ޷¾ */ + int log_game_time; /* ءة ë */ + int log_netloop_faster; /* netloop_faster */ + int saacwritenum; /* ʧӡ߼ write¾ */ + int saacreadnum; /* ʧӡᆴռdispatch ëϼ¾ */ + unsigned short fdnum; /*ľë ¾ */ + unsigned short charnum; /*ľë ¾ */ + unsigned int othercharnum; /* ְƽҷ¼ */ + unsigned int objnum; /* Ƥ */ + unsigned int petcharnum; /* ʸ */ + unsigned int itemnum; /* ʧ ة */ + unsigned int battlenum; /* P */ +#ifdef _GET_BATTLE_EXP + unsigned int battleexp; /* P */ +#endif + char topdir[64]; /* ū */ + + char mapdir[64]; /* Ѩū */ + char maptilefile[64]; /* Ѩɬð̻ */ + char battlemapfile[64]; /* Ѩɬð̻ */ + char itemfile[64]; /* ʧ ةɬð̻ */ + char invfile[64]; /* ɬð̻ */ + char appearfile[64]; /* ɬð̻ */ + char titlenamefile[64]; /* į̻ */ + char titleconfigfile[64]; /* įɬð̻ */ + char encountfile[64]; /* ޼ɬð̻ */ + char enemybasefile[64]; /* ɬð̻ */ + char enemyfile[64]; /* ɬð̻ */ + char groupfile[64]; /* ɬð̻ */ + char magicfile[64]; /* ɬð̻ */ +#ifdef _ATTACK_MAGIC + char attmagicfile[64]; // +#endif + + char petskillfile[64]; /* ʸ ɬð̻ */ + char itematomfile[64]; /* ʧ ة ̻ */ + char effectfile[64]; /* ɬð̻ */ + char quizfile[64]; /* ɬð̻ */ + + + char lsgenlog[64]; /*ӡPlsgen ʧ̻ */ + + char storedir[64]; /*ʧū */ + char npcdir[64]; /*NPCɬð̻ë ʷū */ + + char logdir[64]; /* + * 뷸ū + */ + char logconfname[64]; /* + * ɬð̻ + */ + char chatmagicpasswd[64]; /* ܷɵ */ + +#ifdef _STORECHAR + char storechar[64]; +#endif + unsigned int chatmagiccdkeycheck; /* ܷƥCDKEYë¾ */ + unsigned int filesearchnum; /*̻ëƥ°̻P*/ + unsigned int npctemplatenum; /*NPC ̻P*/ + unsigned int npccreatenum; /*NPCϷDz̻P*/ + unsigned int walksendinterval; /* ʼë˪ */ + unsigned int CAsendinterval_ms; /* CAë˪ (ms)*/ + unsigned int CDsendinterval_ms; /* CDë˪ (ms)*/ + unsigned int Onelooptime_ms; /* 1微 */ + unsigned int Petdeletetime; /* ʸ */ + unsigned int Itemdeletetime; /* ʧ ة */ + /* ̼ ƽҷ¼Ƥë */ + unsigned int CharSavesendinterval; + unsigned int addressbookoffmsgnum; /* + * ʧƤͱ׷̼ + * ë + * ϶¾ + */ + unsigned int protocolreadfrequency; /* + * ë + * 꾮 + */ + unsigned int allowerrornum; /* + * ޷¡ëƥʾ + */ + unsigned int loghour; /* + * ëݶ + */ + unsigned int battledebugmsg; /* + * 붪ëʾۨئئ + */ + //ttom add this because the second had this + unsigned int encodekey; + unsigned int acwbsize; + unsigned int acwritesize; + unsigned int ErrUserDownFlg; + //ttom end +#ifdef _GMRELOAD + char gmsetfile[64]; /* GMʺšȨ趨 */ +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + char profession[32]; +#endif +#ifdef _ITEM_QUITPARTY + char itemquitparty[32]; +#endif + +#ifdef _DEL_DROP_GOLD + unsigned int Golddeletetime; +#endif +#ifdef _NEW_PLAYER_CF + int newplayertrans; + int newplayerlv; + int newplayergivepet[5]; + int newplayergiveitem[15]; + int newplayerpetlv; + int newplayergivegold; + int ridepetlevel; +#ifdef _VIP_SERVER + int newplayerpetvip; +#endif +#endif +#ifdef _USER_EXP_CF + char expfile[64]; +#endif +#ifdef _UNLAW_WARP_FLOOR + char unlawwarpfloor[512]; +#endif +#ifdef _NO_JOIN_FLOOR + char nojoinfloor[512]; +#endif +#ifdef _WATCH_FLOOR + int watchfloor[6]; +#endif +#ifdef _BATTLE_FLOOR + int battlefloor; + char battlefloorcf[512]; +#endif +#ifdef _UNREG_NEMA + char unregname[5][16]; +#endif +#ifdef _TRANS_LEVEL_CF + int chartrans; + int pettrans; + int yblevel; + int maxlevel; +#endif +#ifdef _POINT +int point; + int transpoint[8]; +#endif +#ifdef _VIP_SERVER + int vippoint; +#endif +#ifdef _PET_AND_ITEM_UP + int petup; + int itemup; +#endif +#ifdef _LOOP_ANNOUNCE + char loopannouncepath[32]; + int loopannouncetime; + char loopannounce[10][1024]; + int loopannouncemax; +#endif +#ifdef _SKILLUPPOINT_CF + int skup; +#endif +#ifdef _RIDELEVEL + int ridelevel; + int ridetrans; +#endif +#ifdef _REVLEVEL + int revlevel; +#endif +#ifdef _NEW_PLAYER_RIDE + int npride; +#endif +#ifdef _FIX_CHARLOOPS + int charloops; +#endif +#ifdef _PLAYER_ANNOUNCE + int pannounce; +#endif +#ifdef _PLAYER_MOVE + int pmove; +#endif + int recvbuffer; + int sendbuffer; + int recvlowatbuffer; + int runlevel; +#ifdef _SHOW_VIP_CF + int showvip; +#endif +#ifdef _PLAYER_NUM + int playernum; +#endif +#ifdef _BATTLE_GOLD + int battlegold; +#endif +#ifdef _ANGEL_TIME + int angelplayertime; + int angelplayermun; +#endif +#ifdef _RIDEMODE_20 + int ridemode; +#endif +#ifdef _FM_POINT_PK + int fmpointpk; +#endif +#ifdef _ENEMY_ACTION + int enemyact; +#endif +#ifdef _FUSIONBEIT_TRANS + char fusionbeittrans; +#endif +#ifdef _CHECK_PEPEAT + int CheckRepeat; +#endif + int cpuuse; +#ifdef _FM_JOINLIMIT + int joinfamilytime; +#endif +#ifdef _MAP_HEALERALLHEAL + char mapheal[256]; +#endif +#ifdef _THE_WORLD_SEND + int thewordtrans; + int thewordlevel; + int thewordsend; +#endif +#ifdef _LOGIN_DISPLAY + int logindisplay; +#endif +#ifdef _VIP_POINT_PK + char vippointpk[256]; + int vippointpkcost; +#endif +#ifdef _SPECIAL_MAP + char specialmap[256]; +#endif +#ifdef _NEW_AUTO_PK + int autopk; + int autopktrans; + int autopklv; +#ifdef _FORMULATE_AUTO_PK + int autopkpoint; + int killpoint; +#endif +#endif +#ifdef _AUTO_DEL_PET + char autodelpet[256]; +#endif +#ifdef _AUTO_DEL_ITEM + char autodelitem[256]; +#endif +#ifdef _BT_PET + int btpet; +#endif +#ifdef _BT_ITEM + int btitem; +#endif +#ifdef _LUCK_STAR + int luckstartime; + int luckstarchances; +#endif +#ifdef _BATTLE_GETITEM_RATE + char battlegetitemrate[256]; + int battlegetitemratemap; +#endif +#ifdef _BOUND_TIME_EXPANSION + char unboundtimemap[64]; + int unboundtimelevel; + int unboundtimetrans; +#endif + +#ifdef _UNLAW_THIS_LOGOUT + char unlawthislogout[256]; +#endif + +#ifdef _TRANS_POINT_UP + char transpointup[256]; +#endif +#ifdef _OPEN_STW_SEND + int stwsendtype; + int stwsendpoint; +#endif +#ifdef _POOL_ITEM_BUG + int poolitembug; + char poolitem[256]; +#endif +#ifdef _NO_STW_ENEMY + int nostwenemy; + int nostwenemypoint; +#endif +#ifdef _NEW_STREET_VENDOR + char streetvendorpoint[256]; +#endif +#ifdef _ITEM_PET_LOCKED + int itampetlocked; +#endif +#ifdef _TALK_SAVE + int savefame; +#endif +#ifdef _TALK_CHECK + int talkcheckmax; + int talkcheckmin; +#endif +#ifdef _DISABLE_PROFESSION_SKILL + char disableprofessionskill[256]; +#endif +#ifdef _ALL_SERV_SEND + int allservtrans; + int allservlevel; + int allservsend; +#endif +#ifdef _PET_TRANS_ABILITY + int pettransability; + int pettransability1; + int pettransability2; +#endif +#ifdef _NEED_ITEM_ENEMY + int delneeditem; +#endif +#ifdef _NOT_ESCAPE + char notescape[256]; +#endif +#ifdef _PLAYER_OVERLAP_PK + char playeroverlappk[256]; +#endif +#ifdef _FIMALY_PK_TIME + int fimalypktime; +#endif +#ifdef _PETSKILL_SHOP_LUA + char freepetskillshoppath[256]; +#endif +#ifdef _CANCEL_ANGLE_TRANS + int cancelanlgetrans; +#endif +#ifdef _VIP_BATTLE_EXP + int vipbattleexp; +#endif +#ifdef _NO_HELP_MAP + char nohelpmap[256]; +#endif +#ifdef _BATTLE_TIME + int battletime; +#endif +#ifdef _SAME_IP_ONLINE_NUM + int sameiponlinenum; +#endif +#ifdef _STREET_VENDOR_TRANS + int streetvendortrans; +#endif +#ifdef _CHECK_SEVER_IP + char serverip[256]; +#endif +#ifdef _DAMMAGE_CALC + int dammagecalc; +#endif +#ifdef _PET_ENEMY_DEVELOP_UP + int PetEnemyDevelopUp; +#endif +#ifdef _FIRST_LOCK_ITEM + char FirstLockItem[256]; +#endif + int Connectnum; +#ifdef _PETSKILL_NEW_PASSIVE +int autogetskill; +int getskillpos; +char skillinfolv[5][100]; +int skillfusion; +char fusionrange[50]; +int skillcount; +#endif +#ifdef _SHARE_EXP + int expshare; +#endif +#ifdef _DEFEND_BIGBAO + int bigbao; + int bigbao2; +#endif +#ifdef _MO_SHOW_DEBUG + int isdebug; +#endif +#ifdef _CHAR_LOOP_TIME + int charlooptime; +#endif +#ifdef _MO_RELOAD_NPC + int reloadnpctime; + int reloadnpctype; +#endif +#ifdef _JZ_NEWSCRIPT_LUA + char luafile[256]; +#endif +#ifdef _ITEM_LUA +char itemluafile[256]; +#endif +#ifdef _MO_LNS_NLSUOXU + int mapstart; +#endif +#ifdef _ROOKIE_ITEM + unsigned int rookieitem[5]; +#endif +#ifdef _NO_TRANS_ITEM + unsigned int notransitem; +#endif + +#ifdef _MAX_MERGE_LEVEL + unsigned int maxmergelevel; +#endif + +#ifdef _NO_ATTACK + int atttime; + int attsafetime; + int attcnt; + int latetime; + int attdmetime; + int attdmecnt; +#endif + char noattip[5][18]; +#ifdef _NO_FULLPLAYER_ATT + int nofullplayer; + int nofull2player; + int nocdkeyplayer; + int nocdkeymode; + int nocdkeytype; + int nofulltime; + int fengtype; + int nofullendplayer; + int nofullendtime; + int manrennum; +#endif + int locktype; +#ifdef _NEW_FUNC_DECRYPT + int allowerrornum2; +#endif +#ifdef _MO_LOGIN_NO_KICK + int loginnokick; +#endif +#ifdef _MO_ILLEGAL_NAME + char illegalname[256]; +#endif +#ifdef _NO_USE_PACKET_MAP + char nousepacketmap[256]; +#endif +#ifdef _NO_USE_MAGIC_MAP + char nousemagicmap[256]; +#endif +#ifdef _SOME_PETMAIL + int petmailflg; + char somepetmail[256]; +#endif +#ifdef _CTRL_TRANS_DEVELOP + int ctrltrans; +#endif +#ifdef _PETMAIL_TIME + int petmailtime; +#endif + +#ifdef _UP_BBPETPROB + int upbbprob; +#endif +}Config; + +Config config; + +#ifdef _USER_EXP_CF +int NeedLevelUpTbls[200]; +#endif + +/* + * ū̻ë ݱհ + * xxxx=yyyy ئë + */ + +typedef struct tagReadConf +{ + char name[32]; /*xxxxؤ°*/ + + /*ݼ2NULLë ľ ئ*/ + char *charvalue; /*yyyyëҽ ݼҽ */ + size_t charsize; /*charvalue*/ + + /* + * ƻ= "ON" intvalue 巴1ëҽ + * ľ½ atoi + */ + void* value; /*yyyyë ҽ ݼҽ */ + CTYPE valuetype; +}ReadConf; + +ReadConf readconf[]= +{ + { "debuglevel" , NULL ,0 , (void*)&config.debuglevel ,CHAR}, + + { "usememoryunit" , NULL ,0 , (void*)&config.usememoryunit ,INT}, + { "usememoryunitnum", NULL ,0 , (void*)&config.usememoryunitnum,INT}, + + { "acserv", config.asname,sizeof(config.asname) ,NULL , 0}, + { "acservport", NULL ,0 , (void*)&config.acservport ,SHORT}, + { "acpasswd", config.acpasswd,sizeof( config.acpasswd),NULL,0}, + { "gameservname", config.gsnamefromas,sizeof(config.gsnamefromas), + NULL,0}, + + // Arminius 7.24 manor pk + { "gameservid", config.gsid, sizeof(config.gsid), NULL, 0}, + { "allowmanorpk", NULL, 0, (void*)&config.allowmanorpk, SHORT}, + + { "port", NULL ,0 , (void*)&config.port ,SHORT}, + { "servernumber", NULL ,0 , (void*)&config.servernumber ,INT}, + + { "reuseaddr", NULL ,0 , (void*)&config.reuseaddr , INT}, + { "nodelay", NULL , 0 , (void*)&config.do_nodelay , INT}, + { "log_write_time", NULL, 0 , (void*)&config.log_write_time, INT}, + { "log_io_time", NULL, 0 , (void*)&config.log_io_time, INT}, + { "log_game_time", NULL, 0 , (void*)&config.log_game_time, INT}, + { "log_netloop_faster", NULL,0,(void*)&config.log_netloop_faster, INT}, + { "saacwritenum", NULL,0,(void*)&config.saacwritenum, INT}, + { "saacreadnum", NULL,0,(void*)&config.saacreadnum, INT}, + { "fdnum", NULL ,0 , (void*)&config.fdnum, SHORT}, + { "charnum", NULL ,0 , (void*)&config.charnum, SHORT}, + { "petnum", NULL ,0 , (void*)&config.petcharnum, INT}, + { "othercharnum", NULL ,0 , (void*)&config.othercharnum, INT}, + + { "objnum", NULL ,0 , (void*)&config.objnum, INT}, + { "itemnum", NULL ,0 , (void*)&config.itemnum, INT}, + { "battlenum", NULL ,0 , (void*)&config.battlenum, INT}, +#ifdef _GET_BATTLE_EXP + { "battleexp", NULL ,0 , (void*)&config.battleexp, INT}, +#endif + { "topdir" , config.topdir,sizeof(config.topdir),NULL,0}, + { "mapdir" , config.mapdir,sizeof(config.mapdir),NULL,0}, + { "maptilefile" , config.maptilefile,sizeof(config.maptilefile),NULL,0}, + { "battlemapfile" , config.battlemapfile,sizeof(config.battlemapfile),NULL,0}, + +#ifdef _ITEMSET6_TXT + { "itemset6file", config.itemfile, sizeof(config.invfile), NULL, 0}, +#else +#ifdef _ITEMSET5_TXT + { "itemset5file", config.itemfile, sizeof(config.invfile), NULL, 0}, +#else +#ifdef _ITEMSET4_TXT + { "itemset4file" , config.itemfile,sizeof(config.invfile),NULL,0}, +#else +#ifdef _ITEMSET3_ITEM + { "itemset3file" , config.itemfile,sizeof(config.invfile),NULL,0}, +#endif +#endif +#endif +#endif + { "invinciblefile" , config.invfile,sizeof(config.invfile),NULL,0}, + { "appearpositionfile" , config.appearfile,sizeof(config.appearfile),NULL,0}, + { "titlenamefile", config.titlenamefile, sizeof( config.titlenamefile),NULL,0}, + { "titleconfigfile", config.titleconfigfile, sizeof( config.titleconfigfile),NULL,0}, + { "encountfile", config.encountfile, sizeof( config.encountfile),NULL,0}, + { "enemyfile", config.enemyfile, sizeof( config.enemyfile),NULL,0}, + { "enemybasefile", config.enemybasefile, sizeof( config.enemybasefile),NULL,0}, + { "groupfile", config.groupfile, sizeof( config.groupfile),NULL,0}, + { "magicfile", config.magicfile, sizeof( config.magicfile),NULL,0}, +#ifdef _ATTACK_MAGIC + { "attmagicfile" , config.attmagicfile , sizeof( config.attmagicfile ) , NULL , 0 }, +#endif + +#ifdef _PETSKILL2_TXT + { "petskillfile2", config.petskillfile, sizeof( config.petskillfile),NULL,0}, +#else + { "petskillfile1", config.petskillfile, sizeof( config.petskillfile),NULL,0}, +#endif + + { "itematomfile" , config.itematomfile, sizeof( config.itematomfile),NULL,0}, + { "effectfile" , config.effectfile,sizeof(config.effectfile),NULL,0}, + { "quizfile" , config.quizfile,sizeof(config.quizfile),NULL,0}, + + { "lsgenlogfilename", config.lsgenlog,sizeof(config.lsgenlog),NULL,0}, +#ifdef _GMRELOAD + { "gmsetfile", config.gmsetfile, sizeof( config.gmsetfile),NULL,0}, +#endif + + { "storedir" ,config.storedir,sizeof(config.storedir),NULL,0}, + { "npcdir" ,config.npcdir,sizeof(config.npcdir),NULL,0}, + { "logdir" ,config.logdir,sizeof(config.logdir),NULL,0}, + { "logconfname" ,config.logconfname,sizeof(config.logconfname),NULL,0}, + { "chatmagicpasswd", config.chatmagicpasswd, sizeof( config.chatmagicpasswd),NULL,0}, +#ifdef _STORECHAR + { "storechar", config.storechar, sizeof( config.storechar),NULL,0}, +#endif + { "chatmagiccdkeycheck", NULL,0, &config.chatmagiccdkeycheck,INT}, + { "filesearchnum", NULL,0, &config.filesearchnum,INT}, + { "npctemplatenum", NULL,0, &config.npctemplatenum,INT}, + { "npccreatenum", NULL,0, &config.npccreatenum,INT}, + { "walkinterval" ,NULL,0,(void*)&config.walksendinterval,INT}, + { "CAinterval" ,NULL,0,(void*)&config.CAsendinterval_ms,INT}, + { "CDinterval" ,NULL,0,(void*)&config.CDsendinterval_ms,INT}, + { "CharSaveinterval" ,NULL,0,(void*)&config.CharSavesendinterval,INT}, + { "Onelooptime" ,NULL,0,(void*)&config.Onelooptime_ms,INT}, + { "Petdeletetime" ,NULL,0,(void*)&config.Petdeletetime,INT}, + { "Itemdeletetime" ,NULL,0,(void*)&config.Itemdeletetime,INT}, + { "addressbookoffmesgnum" ,NULL,0, + (void*)&config.addressbookoffmsgnum,INT}, + + { "protocolreadfrequency" ,NULL,0, + (void*)&config.protocolreadfrequency,INT}, + + { "allowerrornum" ,NULL,0,(void*)&config.allowerrornum,INT}, + { "loghour" ,NULL,0,(void*)&config.loghour,INT}, + { "battledebugmsg" ,NULL,0,(void*)&config.battledebugmsg,INT}, + //ttom add because the second had + { "encodekey" ,NULL,0,(void*)&config.encodekey,INT}, + { "acwritesize" ,NULL,0,(void*)&config.acwritesize,INT}, + { "acwbsize" ,NULL,0,(void*)&config.acwbsize,INT}, + { "erruser_down" ,NULL,0,(void*)&config.ErrUserDownFlg,INT}, + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + { "profession", config.profession, sizeof(config.profession) ,NULL , 0}, +#endif + +#ifdef _ITEM_QUITPARTY + { "itemquitparty", config.itemquitparty, sizeof(config.itemquitparty) ,NULL , 0}, +#endif + +#ifdef _DEL_DROP_GOLD + { "Golddeletetime" ,NULL,0,(void*)&config.Golddeletetime, INT}, +#endif + +#ifdef _NEW_PLAYER_CF + { "TRANS" ,NULL,0,(void*)&config.newplayertrans, INT}, + { "LV" ,NULL,0,(void*)&config.newplayerlv, INT}, + { "PET1" ,NULL,0,(void*)&config.newplayergivepet[1], INT}, + { "PET2" ,NULL,0,(void*)&config.newplayergivepet[2], INT}, + { "PET3" ,NULL,0,(void*)&config.newplayergivepet[3], INT}, + { "PET4" ,NULL,0,(void*)&config.newplayergivepet[4], INT}, + { "ITEM1" ,NULL,0,(void*)&config.newplayergiveitem[0], INT}, + { "ITEM2" ,NULL,0,(void*)&config.newplayergiveitem[1], INT}, + { "ITEM3" ,NULL,0,(void*)&config.newplayergiveitem[2], INT}, + { "ITEM4" ,NULL,0,(void*)&config.newplayergiveitem[3], INT}, + { "ITEM5" ,NULL,0,(void*)&config.newplayergiveitem[4], INT}, + { "ITEM6" ,NULL,0,(void*)&config.newplayergiveitem[5], INT}, + { "ITEM7" ,NULL,0,(void*)&config.newplayergiveitem[6], INT}, + { "ITEM8" ,NULL,0,(void*)&config.newplayergiveitem[7], INT}, + { "ITEM9" ,NULL,0,(void*)&config.newplayergiveitem[8], INT}, + { "ITEM10" ,NULL,0,(void*)&config.newplayergiveitem[9], INT}, + { "ITEM11" ,NULL,0,(void*)&config.newplayergiveitem[10], INT}, + { "ITEM12" ,NULL,0,(void*)&config.newplayergiveitem[11], INT}, + { "ITEM13" ,NULL,0,(void*)&config.newplayergiveitem[12], INT}, + { "ITEM14" ,NULL,0,(void*)&config.newplayergiveitem[13], INT}, + { "ITEM15" ,NULL,0,(void*)&config.newplayergiveitem[14], INT}, + { "PETLV" ,NULL,0,(void*)&config.newplayerpetlv, INT}, + { "GOLD" ,NULL,0,(void*)&config.newplayergivegold, INT}, + { "RIDEPETLEVEL" ,NULL,0,(void*)&config.ridepetlevel, INT}, +#ifdef _VIP_SERVER + { "GIVEVIPPOINT" ,NULL,0,(void*)&config.newplayerpetvip, INT}, +#endif +#endif + +#ifdef _USER_EXP_CF + { "USEREXP", config.expfile, sizeof( config.expfile),NULL,0}, +#endif + +#ifdef _UNLAW_WARP_FLOOR + { "UNLAWWARPFLOOR" ,config.unlawwarpfloor, sizeof( config.unlawwarpfloor),NULL,0}, +#endif + +#ifdef _NO_JOIN_FLOOR + { "NOJOINFLOOR" ,config.nojoinfloor, sizeof( config.nojoinfloor),NULL,0}, +#endif + +#ifdef _WATCH_FLOOR + { "WATCHFLOOR" ,NULL,0,(void*)&config.watchfloor[0], INT}, + { "WATCHFLOOR1" ,NULL,0,(void*)&config.watchfloor[1], INT}, + { "WATCHFLOOR2" ,NULL,0,(void*)&config.watchfloor[2], INT}, + { "WATCHFLOOR3" ,NULL,0,(void*)&config.watchfloor[3], INT}, + { "WATCHFLOOR4" ,NULL,0,(void*)&config.watchfloor[4], INT}, + { "WATCHFLOOR5" ,NULL,0,(void*)&config.watchfloor[5], INT}, +#endif + +#ifdef _BATTLE_FLOOR + { "BATTLEFLOOR" ,NULL,0,(void*)&config.battlefloor, INT}, + { "BATTLEFLOORCF" ,config.battlefloorcf, sizeof( config.battlefloorcf),NULL,0}, +#endif + +#ifdef _UNREG_NEMA + { "NAME1" ,config.unregname[0], sizeof( config.unregname[0]),NULL,0}, + { "NAME2" ,config.unregname[1], sizeof( config.unregname[1]),NULL,0}, + { "NAME3" ,config.unregname[2], sizeof( config.unregname[2]),NULL,0}, + { "NAME4" ,config.unregname[3], sizeof( config.unregname[3]),NULL,0}, + { "NAME5" ,config.unregname[4], sizeof( config.unregname[4]),NULL,0}, +#endif +#ifdef _TRANS_LEVEL_CF + { "CHARTRANS" ,NULL,0,(void*)&config.chartrans, INT}, + { "PETTRANS" ,NULL,0,(void*)&config.pettrans, INT}, + { "LEVEL" ,NULL,0,(void*)&config.yblevel, INT}, + { "MAXLEVEL" ,NULL,0,(void*)&config.maxlevel, INT}, +#endif +#ifdef _POINT + { "POINT" ,NULL,0,(void*)&config.point, INT}, + { "TRANS0" ,NULL,0,(void*)&config.transpoint[0], INT}, + { "TRANS1" ,NULL,0,(void*)&config.transpoint[1], INT}, + { "TRANS2" ,NULL,0,(void*)&config.transpoint[2], INT}, + { "TRANS3" ,NULL,0,(void*)&config.transpoint[3], INT}, + { "TRANS4" ,NULL,0,(void*)&config.transpoint[4], INT}, + { "TRANS5" ,NULL,0,(void*)&config.transpoint[5], INT}, + { "TRANS6" ,NULL,0,(void*)&config.transpoint[6], INT}, + { "TRANS7" ,NULL,0,(void*)&config.transpoint[7], INT}, +#endif + +#ifdef _PET_AND_ITEM_UP + { "PETUP" ,NULL,0,(void*)&config.petup, INT}, + { "ITEMUP" ,NULL,0,(void*)&config.itemup, INT}, +#endif +#ifdef _LOOP_ANNOUNCE + { "ANNOUNCEPATH" ,config.loopannouncepath, sizeof( config.loopannouncepath),NULL,0}, + { "ANNOUNCETIME" ,NULL,0,(void*)&config.loopannouncetime, INT}, +#endif +#ifdef _SKILLUPPOINT_CF + { "SKILLUPPOINT" ,NULL,0,(void*)&config.skup, INT}, +#endif +#ifdef _RIDELEVEL + { "RIDELEVEL" ,NULL,0,(void*)&config.ridelevel, INT}, + { "RIDETRANS" ,NULL,0,(void*)&config.ridetrans, INT}, +#endif + +#ifdef _REVLEVEL + { "REVLEVEL" ,NULL,0,(void*)&config.revlevel, INT}, +#endif +#ifdef _NEW_PLAYER_RIDE + { "NPRIDE" ,NULL,0,(void*)&config.npride, INT}, +#endif +#ifdef _FIX_CHARLOOPS + { "CHARLOOPS" ,NULL,0,(void*)&config.charloops, INT}, +#endif +#ifdef _PLAYER_ANNOUNCE + { "PANNOUNCE" ,NULL,0,(void*)&config.pannounce, INT}, +#endif +#ifdef _PLAYER_MOVE + { "PMOVE" ,NULL,0,(void*)&config.pmove, INT}, +#endif + + { "recvbuffer" ,NULL,0,(void*)&config.recvbuffer, INT}, + { "sendbuffer" ,NULL,0,(void*)&config.sendbuffer, INT}, + { "recvlowatbuffer" ,NULL,0,(void*)&config.recvlowatbuffer, INT}, + { "runlevel" ,NULL,0,(void*)&config.runlevel, INT}, + +#ifdef _SHOW_VIP_CF + { "SHOWVIP" ,NULL,0,(void*)&config.showvip, INT}, +#endif + +#ifdef _PLAYER_NUM + { "PLAYERNUM" ,NULL,0,(void*)&config.playernum, INT}, +#endif + +#ifdef _BATTLE_GOLD + { "BATTLEGOLD" ,NULL,0,(void*)&config.battlegold, INT}, +#endif +#ifdef _ANGEL_TIME + { "ANGELPLAYERTIME" ,NULL,0,(void*)&config.angelplayertime, INT}, + { "ANGELPLAYERMUN" ,NULL,0,(void*)&config.angelplayermun, INT}, +#endif +#ifdef _RIDEMODE_20 + { "RIDEMODE" ,NULL,0,(void*)&config.ridemode, INT}, +#endif +#ifdef _FM_POINT_PK + { "FMPOINTPK" ,NULL,0,(void*)&config.fmpointpk, INT}, +#endif +#ifdef _ENEMY_ACTION + { "ENEMYACTION" ,NULL,0,(void*)&config.enemyact, INT}, +#endif +#ifdef _FUSIONBEIT_TRANS + { "FUSIONBEIT" ,NULL,0,(void*)&config.fusionbeittrans, INT}, +#endif +#ifdef _CHECK_PEPEAT + { "CHECKPEPEAT" ,NULL,0,(void*)&config.CheckRepeat, INT}, +#endif + { "CPUUSE" ,NULL,0,(void*)&config.cpuuse, INT}, +#ifdef _FM_JOINLIMIT + { "JOINFAMILYTIME" ,NULL,0,(void*)&config.joinfamilytime, INT}, +#endif +#ifdef _MAP_HEALERALLHEAL + { "MAPHEAL" ,config.mapheal, sizeof( config.mapheal),NULL,0}, +#endif + +#ifdef _THE_WORLD_SEND + { "THEWORLDTRANS" ,NULL,0,(void*)&config.thewordtrans, INT}, + { "THEWORLDLEVEL" ,NULL,0,(void*)&config.thewordlevel, INT}, + { "THEWORLDSNED" ,NULL,0,(void*)&config.thewordsend, INT}, +#endif +#ifdef _LOGIN_DISPLAY + { "LOGINDISPLAY" ,NULL,0,(void*)&config.logindisplay, INT}, +#endif +#ifdef _VIP_POINT_PK + { "PKMAP" ,config.vippointpk, sizeof( config.vippointpk),NULL,0}, + { "PKMAPCOST" ,NULL,0,(void*)&config.vippointpkcost, INT}, +#endif +#ifdef _SPECIAL_MAP + { "SPECIALMAP" ,config.specialmap, sizeof( config.specialmap),NULL,0}, +#endif +#ifdef _NEW_AUTO_PK + { "AUTOPK" ,NULL,0,(void*)&config.autopk, INT}, + { "AUTOPKTRANS" ,NULL,0,(void*)&config.autopktrans, INT}, + { "AUTOPKLV" ,NULL,0,(void*)&config.autopklv, INT}, +#ifdef _FORMULATE_AUTO_PK + { "AUTOPKPOINT" ,NULL,0,(void*)&config.autopkpoint, INT}, + { "KILLPOINT" ,NULL,0,(void*)&config.killpoint, INT}, +#endif +#endif +#ifdef _AUTO_DEL_PET + { "AUTODELPET" ,config.autodelpet, sizeof( config.autodelpet),NULL,0}, +#endif +#ifdef _AUTO_DEL_ITEM + { "AUTODELITEM" ,config.autodelitem, sizeof( config.autodelitem),NULL,0}, +#endif +#ifdef _BT_PET + { "BTPET" ,NULL,0,(void*)&config.btpet, INT}, +#endif +#ifdef _BT_ITEM + { "BTITEM" ,NULL,0,(void*)&config.btitem, INT}, +#endif +#ifdef _LUCK_STAR + { "LUCKSTARTIME" ,NULL,0,(void*)&config.luckstartime, INT}, + { "LUCKSTARCHANCES" ,NULL,0,(void*)&config.luckstarchances, INT}, +#endif +#ifdef _BATTLE_GETITEM_RATE + { "BATTLEGETITEMRATE" ,config.battlegetitemrate, sizeof( config.battlegetitemrate),NULL,0}, + { "BATTLEGETITEMRATEMAP" ,NULL,0,(void*)&config.battlegetitemratemap, INT}, +#endif +#ifdef _UNLAW_THIS_LOGOUT + { "UNLAWTHISLOGOUT" ,config.unlawthislogout, sizeof( config.unlawthislogout),NULL,0}, +#endif +#ifdef _TRANS_POINT_UP + { "TRANSPOINTUP" ,config.transpointup, sizeof( config.transpointup),NULL,0}, +#endif +#ifdef _OPEN_STW_SEND + { "STWSENDTYPE" ,NULL,0,(void*)&config.stwsendtype, INT}, + { "STWSENDPOINT" ,NULL,0,(void*)&config.stwsendpoint, INT}, +#endif +#ifdef _POOL_ITEM_BUG + { "POOLITEMBUG" ,NULL,0,(void*)&config.poolitembug, INT}, + { "POOLITEM" ,config.poolitem, sizeof( config.poolitem),NULL,0}, +#endif +#ifdef _NO_STW_ENEMY + { "NOSTWENEMY" ,NULL,0,(void*)&config.nostwenemy, INT}, + { "NOSTWENEMYGOLD" ,NULL,0,(void*)&config.nostwenemypoint, INT}, +#endif +#ifdef _NEW_STREET_VENDOR + { "STREETVENDORPOINT" ,config.streetvendorpoint, sizeof( config.streetvendorpoint),NULL,0}, +#endif +#ifdef _ITEM_PET_LOCKED + { "ITEMPETLOCKED" ,NULL,0,(void*)&config.itampetlocked, INT}, +#endif +#ifdef _TALK_SAVE + { "SAVEFAME" ,NULL,0,(void*)&config.savefame, INT}, +#endif +#ifdef _TALK_CHECK + { "TALKCHECKMAX" ,NULL,0,(void*)&config.talkcheckmax, INT}, + { "TALKCHECKMIN" ,NULL,0,(void*)&config.talkcheckmin, INT}, +#endif +#ifdef _DISABLE_PROFESSION_SKILL + { "DISABLEPROFESSION" ,config.disableprofessionskill, sizeof( config.disableprofessionskill),NULL,0}, +#endif +#ifdef _ALL_SERV_SEND + { "ALLSERVTRANS" ,NULL,0,(void*)&config.allservtrans, INT}, + { "ALLSERVLEVEL" ,NULL,0,(void*)&config.allservlevel, INT}, + { "ALLSERVSNED" ,NULL,0,(void*)&config.allservsend, INT}, +#endif +#ifdef _PET_TRANS_ABILITY + { "PETTRANSABILITY" ,NULL,0,(void*)&config.pettransability, INT}, + { "PETTRANSABILITY1" ,NULL,0,(void*)&config.pettransability1, INT}, + { "PETTRANSABILITY2" ,NULL,0,(void*)&config.pettransability2, INT}, +#endif +#ifdef _NEED_ITEM_ENEMY + { "DELNEEDITEM" ,NULL,0,(void*)&config.delneeditem, INT}, +#endif +#ifdef _NOT_ESCAPE + { "NOTESCAPE" ,config.notescape, sizeof( config.notescape),NULL,0}, +#endif +#ifdef _PLAYER_OVERLAP_PK + { "PLAYEROVERLAPPK" ,config.playeroverlappk, sizeof( config.playeroverlappk),NULL,0}, +#endif +#ifdef _FIMALY_PK_TIME + { "FIMALYPKTIME" ,NULL,0,(void*)&config.fimalypktime, INT}, +#endif +#ifdef _PETSKILL_SHOP_LUA + { "PETSKILLSHOPPATH" ,config.freepetskillshoppath, sizeof( config.freepetskillshoppath),NULL,0}, +#endif +#ifdef _CANCEL_ANGLE_TRANS + { "CANCELANGLETRANS" ,NULL,0,(void*)&config.cancelanlgetrans, INT}, +#endif +#ifdef _VIP_BATTLE_EXP + { "vipbattleexp" ,NULL,0,(void*)&config.vipbattleexp, INT}, +#endif +#ifdef _NO_HELP_MAP + { "nohelpmap" ,config.nohelpmap, sizeof( config.nohelpmap),NULL,0}, +#endif +#ifdef _BATTLE_TIME + { "battletime" ,NULL,0,(void*)&config.battletime, INT}, +#endif +#ifdef _SAME_IP_ONLINE_NUM + { "sameiponlinenum" ,NULL,0,(void*)&config.sameiponlinenum, INT}, +#endif +#ifdef _STREET_VENDOR_TRANS + { "streetvendortrans" ,NULL,0,(void*)&config.streetvendortrans, INT}, +#endif +#ifdef _CHECK_SEVER_IP + { "serverip" ,config.serverip, sizeof( config.serverip),NULL,0}, +#endif +#ifdef _DAMMAGE_CALC + { "dammagecalc" ,NULL,0,(void*)&config.dammagecalc, INT}, +#endif +#ifdef _PET_ENEMY_DEVELOP_UP + { "PetEnemyDevelopUp" ,NULL,0,(void*)&config.PetEnemyDevelopUp, INT}, +#endif +#ifdef _FIRST_LOCK_ITEM + { "FirstLockItem" ,config.FirstLockItem, sizeof( config.FirstLockItem),NULL,0}, +#endif + { "Connectnum" ,NULL,0,(void*)&config.Connectnum, INT}, +#ifdef _PETSKILL_NEW_PASSIVE + { "AUTUGETSKILL", NULL ,0 , (void*)&config.autogetskill, INT}, + { "GETSKILLPOS", NULL ,0 , (void*)&config.getskillpos, INT}, + { "SKILLINFOLV1", config.skillinfolv[0], sizeof( config.skillinfolv[0]),NULL,0}, + { "SKILLINFOLV2", config.skillinfolv[1], sizeof( config.skillinfolv[1]),NULL,0}, + { "SKILLINFOLV3", config.skillinfolv[2], sizeof( config.skillinfolv[2]),NULL,0}, + { "SKILLINFOLV4", config.skillinfolv[3], sizeof( config.skillinfolv[3]),NULL,0}, + { "SKILLINFOLV5", config.skillinfolv[4], sizeof( config.skillinfolv[4]),NULL,0}, + { "FUSIONRANGE", config.fusionrange, sizeof( config.fusionrange),NULL,0}, + { "SKILLFUSION", NULL ,0 , (void*)&config.skillfusion, INT}, + { "SKILLCOUNT", NULL ,0 , (void*)&config.skillcount, INT}, +#endif +#ifdef _SHARE_EXP + { "EXPSHARE" , NULL ,0 , (void*)&config.expshare ,INT}, +#endif +#ifdef _DEFEND_BIGBAO + { "BIGBAO" ,NULL,0,(void*)&config.bigbao, INT}, + { "BIGBAO2" ,NULL,0,(void*)&config.bigbao2, INT}, +#endif +#ifdef _MO_SHOW_DEBUG + { "ISDEBUG", NULL ,0 , (void*)&config.isdebug, INT}, +#endif +#ifdef _CHAR_LOOP_TIME + { "charlooptime" ,NULL,0,(void*)&config.charlooptime, INT}, +#endif +#ifdef _MO_RELOAD_NPC + { "RELOADNPCTIME" ,NULL,0,(void*)&config.reloadnpctime, INT}, + { "RELOADNPCTYPE" ,NULL,0,(void*)&config.reloadnpctype, INT}, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + { "LUAFILE" , config.luafile,sizeof(config.luafile),NULL,0}, +#endif +#ifdef _ITEM_LUA + { "ITEMLUAFILE" , config.itemluafile,sizeof(config.itemluafile),NULL,0}, +#endif +#ifdef _ROOKIE_ITEM + { "ROOKIEITEM", NULL ,0 , (void*)&config.rookieitem[0], INT}, + { "ROOKIEITEM2", NULL ,0 , (void*)&config.rookieitem[1], INT}, + { "ROOKIEITEM3", NULL ,0 , (void*)&config.rookieitem[2], INT}, + { "ROOKIEITEM4", NULL ,0 , (void*)&config.rookieitem[3], INT}, + { "ROOKIEITEM5", NULL ,0 , (void*)&config.rookieitem[4], INT}, +#endif +#ifdef _NO_TRANS_ITEM + { "NOTRANSITEM", NULL ,0 , (void*)&config.notransitem, INT}, +#endif +#ifdef _MAX_MERGE_LEVEL + { "MAXMERGELEVEL", NULL ,0 , (void*)&config.maxmergelevel, INT}, +#endif +#ifdef _NO_ATTACK + { "ATTTIME" ,NULL,0,(void*)&config.atttime, INT}, + { "ATTSAFETIME" ,NULL,0,(void*)&config.attsafetime, INT}, + { "ATTCNT" ,NULL,0,(void*)&config.attcnt, INT}, + { "LATETIME" ,NULL,0,(void*)&config.latetime, INT}, + { "ATTDMETIME" ,NULL,0,(void*)&config.attdmetime, INT}, + { "ATTDMECNT" ,NULL,0,(void*)&config.attdmecnt, INT}, +#endif + { "NOATTIP1" ,config.noattip[0], sizeof( config.noattip[0]),NULL,0}, + { "NOATTIP2" ,config.noattip[1], sizeof( config.noattip[1]),NULL,0}, + { "NOATTIP3" ,config.noattip[2], sizeof( config.noattip[2]),NULL,0}, + { "NOATTIP4" ,config.noattip[3], sizeof( config.noattip[3]),NULL,0}, + { "NOATTIP5" ,config.noattip[4], sizeof( config.noattip[4]),NULL,0}, +#ifdef _NO_FULLPLAYER_ATT + { "NOFULLPLAYER" ,NULL,0,(void*)&config.nofullplayer, INT}, + { "NOFULL2PLAYER" ,NULL,0,(void*)&config.nofull2player, INT}, + { "NOCDKEYPLAYER" ,NULL,0,(void*)&config.nocdkeyplayer, INT}, + { "NOCDKEYMODE" ,NULL,0,(void*)&config.nocdkeymode, INT}, + { "NOCDKEYTYPE" ,NULL,0,(void*)&config.nocdkeytype, INT}, + { "NOFULLTIME" ,NULL,0,(void*)&config.nofulltime, INT}, + { "FENGTYPE" ,NULL,0,(void*)&config.fengtype, INT}, + { "NOFULLENDPLAYER" ,NULL,0,(void*)&config.nofullendplayer, INT}, + { "NOFULLENDTIME" ,NULL,0,(void*)&config.nofullendtime, INT}, + { "MANRENNUM" ,NULL,0,(void*)&config.manrennum, INT}, +#endif + { "LOCKTYPE" ,NULL,0,(void*)&config.locktype, INT}, +#ifdef _NEW_FUNC_DECRYPT + { "ALLOWERRORNUM2" ,NULL,0,(void*)&config.allowerrornum2, INT}, +#endif +#ifdef _MO_LOGIN_NO_KICK + { "LOGINNOKICK", NULL ,0 , (void*)&config.loginnokick, INT}, +#endif +#ifdef _MO_ILLEGAL_NAME + { "ILLEGALNAME" ,config.illegalname, sizeof( config.illegalname),NULL,0}, +#endif +#ifdef _NO_USE_PACKET_MAP + { "NOPACKETMAP" ,config.nousepacketmap, sizeof( config.nousepacketmap),NULL,0}, +#endif +#ifdef _NO_USE_MAGIC_MAP + { "NOMAGICMAP" ,config.nousemagicmap, sizeof( config.nousemagicmap),NULL,0}, +#endif +#ifdef _SOME_PETMAIL + { "PETMAILFLG", NULL ,0 , (void*)&config.petmailflg, INT}, + { "SOMEPETMAIL" ,config.somepetmail, sizeof( config.somepetmail),NULL,0}, +#endif +#ifdef _CTRL_TRANS_DEVELOP + { "CTRLTRANS", NULL ,0 , (void*)&config.ctrltrans, INT}, +#endif +#ifdef _PETMAIL_TIME + { "PETMAILTIME" ,NULL,0,(void*)&config.petmailtime, INT}, +#endif +#ifdef _UP_BBPETPROB + { "UPBBPROB" ,NULL,0,(void*)&config.upbbprob, INT}, +#endif + +}; + +// Arminius 7.12 login announce +char announcetext[8192]; +void AnnounceToPlayer(int charaindex) +{ + char *ptr,*qtr; + + ptr=announcetext; + while ((qtr=strstr(ptr,"\n"))!=NULL) { + qtr[0]='\0'; +// printf("ptr=%s\n",ptr); + CHAR_talkToCli(charaindex, -1, ptr, CHAR_COLORYELLOW); + qtr[0]='\n'; + ptr=qtr+1; + } + CHAR_talkToCli(charaindex, -1, ptr, CHAR_COLORYELLOW); + +} + +// Robin 0720 +void AnnounceToPlayerWN(int fd) +{ + char buf[8192]; +#ifdef _VIP_LOGOUT + char token[8192]; + int charaindex = CONNECT_getCharaindex( fd ); + long lastleavetime = CHAR_getInt( charaindex , CHAR_LASTLEAVETIME); + struct tm *p; + p=localtime(&lastleavetime); + + sprintf( token , "ʱ %d%d%d %d:%d:%d\n\n%s",p->tm_year + 1900, + p->tm_mon + 1, + p->tm_mday, + p->tm_hour, + p->tm_min, + p->tm_sec, + announcetext); + lssproto_WN_send( fd , WINDOW_MESSAGETYPE_LOGINMESSAGE, + WINDOW_BUTTONTYPE_OK, + -1,-1, + makeEscapeString( token, buf, sizeof(buf))); +#else + lssproto_WN_send( fd , WINDOW_MESSAGETYPE_LOGINMESSAGE, + WINDOW_BUTTONTYPE_OK, + -1,-1, + makeEscapeString( announcetext, buf, sizeof(buf))); +#endif +} + + +void LoadAnnounce(void) +{ + FILE *f; + + memset(announcetext, 0, sizeof(announcetext)); + if ((f=fopen("./announce.txt","r"))!=NULL) { + fread(announcetext, sizeof(announcetext), 1, f); + announcetext[sizeof(announcetext)-1]='\0'; + fclose(f); + } +} +#ifdef _PET_TALKPRO +PTALK pettalktext[PETTALK_MAXID]; + +void LoadPetTalk(void) +{ + FILE *fp; + char fn[256]; + char line[ 4096]; + char talkmem[4096]; + int maxid=0; + char buf1[256], buf2[256], buf3[256]; + int talkNO=-1, mark=-1, i; + int len = sizeof( talkmem); + + memset(talkmem, 0, sizeof(talkmem)); + sprintf(fn, "%s/pettalk/pettalk.menu", getNpcdir()); + + for( i=0;i= PETTALK_MAXID ) + break; + } + print("ID=%d...", maxid); + { + int haveid=0; + for( i=0;i= 0 ) { + haveid++; + } + } + print("=%d", haveid); + } + +} + +#else +char pettalktext[4096]; +void LoadPetTalk(void) +{ + FILE *fp; + char fn[256]; + char line[ 4096]; + int len = sizeof( pettalktext); + + memset(pettalktext, 0, sizeof(pettalktext)); + sprintf(fn, "%s/pettalk/pettalk.mem", getNpcdir()); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", fn); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( fn, "r"); +} + if( fp != NULL ) { + print("\n\n ȡ pettalk.mem"); + while( fgets( line, sizeof( line), fp)) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( strlen( pettalktext) != 0 ) { + if( pettalktext[strlen( pettalktext) -1] != '|' ) { + strcatsafe( pettalktext, len, "|"); + } + } + chompex( line); + strcatsafe( pettalktext,len, line); + } + fclose( fp); + print("\n %s", pettalktext); + }else { + print("\n ҵ pettalk.mem"); + } +} +#endif + +#ifdef _GAMBLE_BANK +GAMBLEBANK_ITEMS GB_ITEMS[GAMBLEBANK_ITEMSMAX]; + +void Load_GambleBankItems( void) +{ + + FILE *fp; + char filename[256]; + char buf1[256]; + char name[128]; + int num,ID,type; + int i=0; + sprintf(filename, "./data/gambleitems.txt" ); + print("\nضIJƷļ %s ...", filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( filename, "r"); +} + if( fp != NULL ) { + while( fgets( buf1, sizeof( buf1), fp) != NULL ) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(buf1); + } +#endif + if( strstr( buf1, "#") != 0 ) continue; + sscanf( buf1,"%s %d %d %d", name, &ID, &num , &type); + strcpy( GB_ITEMS[i].name, name); + GB_ITEMS[i].Gnum = num; + GB_ITEMS[i].ItemId = ID; + GB_ITEMS[i].type = type; + i++; + } + print("ID: %d ", i); + fclose( fp); + }else { + print(" Ҳļ %s", filename); + } + +} +#endif + + +#ifdef _CFREE_petskill +PETSKILL_CODES Code_skill[PETSKILL_CODE]; +void Load_PetSkillCodes( void) +{ + FILE *fp; + char filename[256]; + char buf1[256]; + char name[128]; + char type[256]; + int num,ID; + int i=0; + sprintf(filename, "./data/skillcode.txt" ); + print("\nس\ܱļ:%s...", filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( filename, "r"); +} + if( fp != NULL ) { + while( fgets( buf1, sizeof( buf1), fp) != NULL ) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(buf1); + } +#endif + sscanf( buf1,"%s %d %d %s", name, &num, &ID, type); + strcpy( Code_skill[i].name, name); + Code_skill[i].TempNo = num; + Code_skill[i].PetId = ID; + strcpy( Code_skill[i].Code, type); + //print("\n %s|%d|%d|%s|", Code_skill[i].name, Code_skill[i].TempNo, + // Code_skill[i].PetId, Code_skill[i].Code); + i++; + if( i >= PETSKILL_CODE ) break; + } + fclose( fp); + }else { + print("򲻵ļ %s", filename); + } + print("\n"); +} +#endif + +#ifdef _GMRELOAD +BOOL LoadGMSet( char* filename ) +{ + FILE* fp; + int i = 0, gm_num = 0; + +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen(filename,"r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + for (i = 0; i < GMMAXNUM; i++) + { + strcpy(gminfo[i].cdkey, ""); + gminfo[i].level = 0; + } + while(1){ + char line[64], cdkey[64], level[64]; + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + //change ʹgmset.txtע******* + if( line[0] == '#' ) + continue; + for( i=0; i GMMAXNUM) break; + easyGetTokenFromString(line, 1, cdkey, sizeof(cdkey)); + if (strcmp(cdkey, "") == 0) break; + strncpy(gminfo[gm_num].cdkey, cdkey, sizeof(gminfo[gm_num].cdkey)); + easyGetTokenFromString(line, 2, level, sizeof(level)); + if (strcmp(level, "") == 0) break; + gminfo[gm_num].level = atoi(level); +// print("\ncdkey:%s, level:%d", gminfo[gm_num].cdkey, gminfo[gm_num].level); + } + fclose(fp); + return TRUE; +} +#endif + +/*------------------------------------------------------------ + * ة ë + * ¦ + * ئ + * ߯Ի + * cahr* + ------------------------------------------------------------*/ +char* getProgname( void ) +{ + return config.progname; +} +/*------------------------------------------------------------ + * configfilename ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getConfigfilename( void ) +{ + return config.configfilename; +} +/*------------------------------------------------------------ + * configfilename ëɬ£ + * ¦ + * newv char* ޥа + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void setConfigfilename( char* newv ) +{ + strcpysafe( config.configfilename, sizeof( config.configfilename ), + newv ); +} + +/*------------------------------------------------------------ + * ìë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getDebuglevel( void ) +{ + return config.debuglevel; +} +/*------------------------------------------------------------ + * ìëɬ + * ¦ + * newv int ޥа + * ߯Ի + * unsigned int ɼ + ------------------------------------------------------------*/ +unsigned int setDebuglevel( unsigned int newv ) +{ + int old; + old = config.debuglevel; + config.debuglevel = newv; + return old; +} +/*------------------------------------------------------------ + * memoryunit ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getMemoryunit( void ) +{ + return config.usememoryunit; +} +/*------------------------------------------------------------ + * memoryunitnum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getMemoryunitnum( void ) +{ + return config.usememoryunitnum; +} + +/*------------------------------------------------------------ + * ʧӡPʧë + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getAccountservername( void ) +{ + return config.asname; +} +/*------------------------------------------------------------ + * ʧӡP̡ë + * ¦ + * ئ + * ߯Ի + * unsigned short + ------------------------------------------------------------*/ +unsigned short getAccountserverport( void ) +{ + return config.acservport; +} +/*------------------------------------------------------------ + * ʧӡ߼ɵë £ + * ¦ + * ئ + * ߯Ի + * unsigned short + ------------------------------------------------------------*/ +char* getAccountserverpasswd( void ) +{ + return config.acpasswd; +} +/*------------------------------------------------------------ + * ʧӡᆴέ±ءةӡƻ ë £ + * ¦ + * ئ + * ߯Ի + * unsigned short + ------------------------------------------------------------*/ +char* getGameservername( void ) +{ + return config.gsnamefromas; +} + +// Arminius 7.24 manor pk +char* getGameserverID( void ) +{ + if (config.gsid[strlen(config.gsid)-1]=='\n') + config.gsid[strlen(config.gsid)-1]='\0'; + + return config.gsid; +} + +unsigned short getAllowManorPK( void ) +{ + return config.allowmanorpk; +} + +unsigned short getPortnumber( void ) +{ + return config.port; +} +/*------------------------------------------------------------ + * ءةӡP į įë + * ¦ + * ئ + * ߯Ի + * unsigned short + ------------------------------------------------------------*/ +int getServernumber( void ) +{ + return config.servernumber; +} +/*------------------------------------------------------------ + * reuseaddr ë + * ¦ + * ئ + * ߯Ի + * unsigned short + ------------------------------------------------------------*/ +int getReuseaddr( void ) +{ + return config.reuseaddr; +} + +int getNodelay( void ) +{ + return config.do_nodelay; +} +int getLogWriteTime(void) +{ + return config.log_write_time; +} +int getLogIOTime( void) +{ + return config.log_io_time; +} +int getLogGameTime(void) +{ + return config.log_game_time; +} +int getLogNetloopFaster(void) +{ + return config.log_netloop_faster; +} + +/*------------------------------------------------------------ + * saacwritenum ë £ + * ¦ + * ئ + * ߯Ի + * int + ------------------------------------------------------------*/ +int getSaacwritenum( void ) +{ + return config.saacwritenum; +} +/*------------------------------------------------------------ + * saacwritenum ëɬ£ + * ¦ + * ئ + * ߯Ի + * int + ------------------------------------------------------------*/ +void setSaacwritenum( int num ) +{ + config.saacwritenum = num; +} +/*------------------------------------------------------------ + * saacreadnum ë £ + * ¦ + * ئ + * ߯Ի + * int + ------------------------------------------------------------*/ +int getSaacreadnum( void ) +{ + return config.saacreadnum; +} +/*------------------------------------------------------------ + * saacreadnum ëɬ£ + * ¦ + * ئ + * ߯Ի + * int + ------------------------------------------------------------*/ +void setSaacreadnum( int num ) +{ + config.saacreadnum = num; +} +/*------------------------------------------------------------ + * fdnum ë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ + +unsigned int getFdnum( void ) +{ + return config.fdnum; +} + +unsigned int getPlayercharnum( void ) +{ + return config.charnum; +} + +/*------------------------------------------------------------ + * petcharanum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getPetcharnum( void ) +{ + return config.petcharnum; +} + + +/*------------------------------------------------------------ + * othercharnum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getOtherscharnum( void ) +{ + return config.othercharnum; +} + +/*------------------------------------------------------------ + * objnum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getObjnum( void ) +{ + return config.objnum; +} + +/*------------------------------------------------------------ + * itemnum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getItemnum( void ) +{ + return config.itemnum; +} + + +/*------------------------------------------------------------ + * battlenum ë + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getBattlenum( void ) +{ + return config.battlenum; +} + +#ifdef _GET_BATTLE_EXP +unsigned int getBattleexp( void ) +{ + return config.battleexp; +} +void setBattleexp( int exp ) +{ + config.battleexp = exp; + return; +} +#endif +/*------------------------------------------------------------ + * topdir ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getTopdir( void ) +{ + return config.topdir; +} +/*------------------------------------------------------------ + * mapdir ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getMapdir( void ) +{ + return config.mapdir; +} +/*------------------------------------------------------------ + * maptilefile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getMaptilefile( void ) +{ + return config.maptilefile; +} +/*------------------------------------------------------------ + * battlemapfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getBattleMapfile( void ) +{ + return config.battlemapfile; +} +/*------------------------------------------------------------ + * itemfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getItemfile( void ) +{ + return config.itemfile; +} +/*------------------------------------------------------------ + * invfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getInvfile( void ) +{ + return config.invfile; +} +/*------------------------------------------------------------ + * appearfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getAppearfile( void ) +{ + return config.appearfile; +} +/*------------------------------------------------------------ + * effectfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getEffectfile( void ) +{ + return config.effectfile; +} +/*------------------------------------------------------------ + * titlenamefile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getTitleNamefile( void ) +{ + return config.titlenamefile; +} +/*------------------------------------------------------------ + * titleconfigfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getTitleConfigfile( void ) +{ + return config.titleconfigfile; +} +/*------------------------------------------------------------ + * encountfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getEncountfile( void ) +{ + return config.encountfile; +} +/*------------------------------------------------------------ + * enemyfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getEnemyfile( void ) +{ + return config.enemyfile; +} +/*------------------------------------------------------------ + * enemybasefile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getEnemyBasefile( void ) +{ + return config.enemybasefile; +} +/*------------------------------------------------------------ + * groupfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getGroupfile( void ) +{ + return config.groupfile; +} +/*------------------------------------------------------------ + * magicfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getMagicfile( void ) +{ + return config.magicfile; +} + +#ifdef _ATTACK_MAGIC + +/*------------------------------------------------------------ + * ȡùԵ + * + * None + * ֵ + * char* + ------------------------------------------------------------*/ +char* getAttMagicfileName( void ) +{ + return config.attmagicfile; +} + +#endif + + +char* getPetskillfile( void ) +{ + return config.petskillfile; +} + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +char* getProfession( void ) +{ + return config.profession; +} +#endif + +#ifdef _ITEM_QUITPARTY +char* getitemquitparty( void ) +{ + return config.itemquitparty; +} +#endif + +char *getItematomfile( void ) +{ + return config.itematomfile; +} + + +char* getQuizfile( void ) +{ + return config.quizfile; +} + +/*------------------------------------------------------------ + * lsgenlogfile ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getLsgenlogfilename( void ) +{ + return config.lsgenlog; +} + +#ifdef _GMRELOAD +char* getGMSetfile( void ) +{ + return config.gmsetfile; +} +#endif + +/*------------------------------------------------------------ + * storedir ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getStoredir( void ) +{ + return config.storedir; +} +#ifdef _STORECHAR +/*------------------------------------------------------------ + ------------------------------------------------------------*/ +char* getStorechar( void ) +{ + return config.storechar; +} +#endif + +/*------------------------------------------------------------ + * NPC üūë + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getNpcdir( void ) +{ + return config.npcdir; +} +/*------------------------------------------------------------ + * 뷸ūë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getLogdir( void ) +{ + return config.logdir; +} + +/*------------------------------------------------------------ + * ɬð̻ ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getLogconffile( void ) +{ + return config.logconfname; +} +/*------------------------------------------------------------ + * ܷɵ ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +char* getChatMagicPasswd( void ) +{ + return config.chatmagicpasswd; +} + +void setChatMagicPasswd( void ) +{ + sprintf(config.chatmagicpasswd,"gm"); +} +/*------------------------------------------------------------ + * ܷƥCDKEYë¾ë £ + * ¦ + * ئ + * ߯Ի + * char* + ------------------------------------------------------------*/ +unsigned getChatMagicCDKeyCheck( void ) +{ + return config.chatmagiccdkeycheck; +} + +void setChatMagicCDKeyCheck( void ) +{ + config.chatmagiccdkeycheck = 0; +} +/*------------------------------------------------------------ + * filesearchnumë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getFilesearchnum( void ) +{ + return config.filesearchnum; +} +/*------------------------------------------------------------ + * npctemplatenumë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getNpctemplatenum( void ) +{ + return config.npctemplatenum; +} +/*------------------------------------------------------------ + * npccreatenumë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getNpccreatenum( void ) +{ + return config.npccreatenum; +} + +/*------------------------------------------------------------ + * walksendintervalë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getWalksendinterval( void ) +{ + return config.walksendinterval; +} +/*------------------------------------------------------------ + * walksendintervalë£ + * ¦ + * unsigned int interval + * ߯Ի + * void + ------------------------------------------------------------*/ +void setWalksendinterval( unsigned int interval ) +{ + config.walksendinterval = interval; +} +/*------------------------------------------------------------ + * CAsendintervalë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getCAsendinterval_ms( void ) +{ + return config.CAsendinterval_ms; +} +/*------------------------------------------------------------ + * CAsendintervalë£ + * ¦ + * unsigned int interval + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +void setCAsendinterval_ms( unsigned int interval_ms ) +{ + config.CAsendinterval_ms = interval_ms; +} +/*------------------------------------------------------------ + * CDsendintervalë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getCDsendinterval_ms( void ) +{ + return config.CDsendinterval_ms; +} +/*------------------------------------------------------------ + * CDsendintervalë£ + * ¦ + * interval unsigned int + * ߯Ի + * void + ------------------------------------------------------------*/ +void setCDsendinterval_ms( unsigned int interval_ms ) +{ + config.CDsendinterval_ms = interval_ms; +} +/*------------------------------------------------------------ + * Onelooptimeë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getOnelooptime_ms( void ) +{ + return config.Onelooptime_ms; +} +/*------------------------------------------------------------ + * Onelooptimeë£ + * ¦ + * interval unsigned int + * ߯Ի + * void + ------------------------------------------------------------*/ +void setOnelooptime_ms( unsigned int interval_ms ) +{ + config.Onelooptime_ms = interval_ms; +} +/*------------------------------------------------------------ + * Petdeletetimeë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getPetdeletetime( void ) +{ + return config.Petdeletetime; +} +/*------------------------------------------------------------ + * Petdeletetimeë£ + * ¦ + * interval unsigned int + * ߯Ի + * void + ------------------------------------------------------------*/ +void setPetdeletetime( unsigned int interval ) +{ + config.Petdeletetime = interval; +} +/*------------------------------------------------------------ + * Itemdeletetimeë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getItemdeletetime( void ) +{ + return config.Itemdeletetime; +} +/*------------------------------------------------------------ + * Itemdeletetimeë£ + * ¦ + * interval unsigned int + * ߯Ի + * void + ------------------------------------------------------------*/ +void setItemdeletetime( unsigned int interval ) +{ + config.Itemdeletetime = interval; +} + +/*------------------------------------------------------------ + * CharSavesendintervalë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getCharSavesendinterval( void ) +{ + return config.CharSavesendinterval; +} +/*------------------------------------------------------------ + * CharSavesendintervalë£ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +void setCharSavesendinterval( unsigned int interval) +{ + config.CharSavesendinterval = interval; +} + +/*------------------------------------------------------------ + * Addressbookoffmsgnum ë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getAddressbookoffmsgnum( void ) +{ + return config.addressbookoffmsgnum; +} +/*------------------------------------------------------------ + * Protocolreadfrequency ë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getProtocolreadfrequency( void ) +{ + return config.protocolreadfrequency; +} + +/*------------------------------------------------------------ + * Allowerrornum ë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getAllowerrornum( void ) +{ + return config.allowerrornum; +} + +/*------------------------------------------------------------ + * ë ݶë £ + * ¦ + * ئ + * ߯Ի + * unsigned int + ------------------------------------------------------------*/ +unsigned int getLogHour( void ) +{ + return config.loghour; +} + +/*------------------------------------------------------------ + * 붪ëʾ + * ¦ + * ئ + * ߯Ի + * unsigned int 1ئ + ------------------------------------------------------------*/ +unsigned int getBattleDebugMsg( void ) +{ + return config.battledebugmsg; +} +/*------------------------------------------------------------ + * 붪ëʾ + * ¦ + * ئ + * ߯Ի + * unsigned int 1ئ + ------------------------------------------------------------*/ +void setBattleDebugMsg( unsigned int num ) +{ + config.battledebugmsg = num; +} + + + +/* + * Configɻë裻 + * ¦ + * argv0 char* Ѩ̼¦Ѽ + */ +void defaultConfig( char* argv0 ) +{ + char* program; /* program ëƻ¼ */ + + /* ɻë ľ */ + + /*ة */ + program = rindex(argv0, '/'); + if (program == NULL) + program = argv0; + else + program++; /* "/"ݾձмƥ++*/ + strcpysafe( config.progname , sizeof( config.progname ) ,program ); + + /*ɬð̻ */ + strcpysafe( config.configfilename, + sizeof( config.configfilename ),"setup.cf" ); + +} + +/* + * ɬð̻ ë Ϸ ƥ ë浤 + * ¦ + * ئ + * ߯Ի + * ئ + */ +void lastConfig( void ) +{ + char entry[256]; + /* Ѩūɬ */ + snprintf(entry, sizeof(entry), "%s/%s", config.topdir, config.mapdir); + strcpysafe(config.mapdir, sizeof(config.mapdir), entry); + + /* Ѩɬð̻ ɬ */ + snprintf(entry,sizeof(entry),"%s/%s", + config.topdir,config.maptilefile); + strcpysafe(config.maptilefile, sizeof(config.maptilefile), entry); + + /* Ѩɬð̻ ɬ */ + snprintf(entry,sizeof(entry),"%s/%s", + config.topdir,config.battlemapfile); + strcpysafe(config.battlemapfile, sizeof(config.battlemapfile), entry); + + /* ʧ ةɬð̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.itemfile); + strcpysafe(config.itemfile, sizeof(config.itemfile), entry); + + /* ɬð̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.invfile); + strcpysafe(config.invfile, sizeof(config.invfile), entry); + + /* ɬð̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.appearfile); + strcpysafe(config.appearfile, sizeof(config.appearfile), entry); + + /* ɬð̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.effectfile); + strcpysafe(config.effectfile, sizeof(config.effectfile), entry); + + /* ɬð̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.quizfile); + strcpysafe(config.quizfile, sizeof(config.quizfile), entry); + + /* į ̻ ɬ */ + snprintf(entry,sizeof(entry), "%s/%s", config.topdir,config.titlenamefile); + strcpysafe(config.titlenamefile, sizeof(config.titlenamefile), entry); + + /* lsgen ʧ̻ */ + snprintf(entry,sizeof(entry),"%s/%s", config.topdir,config.lsgenlog); + strcpysafe(config.lsgenlog, sizeof(config.lsgenlog), entry); + + /* ʧūɬ */ +/* + snprintf(entry,sizeof(entry), "%s/%s",config.topdir,config.storedir); + strcpysafe(config.storedir, sizeof(config.storedir), entry); +*/ + /* NPCɬūɬ */ + snprintf(entry,sizeof(entry), "%s/%s",config.topdir,config.npcdir); + strcpysafe(config.npcdir, sizeof(config.npcdir), entry); + +#ifdef _STORECHAR + /* */ + snprintf(entry,sizeof(entry), "%s/%s",config.topdir,config.storechar); + strcpysafe(config.storechar, sizeof(config.storechar), entry); +#endif + +} + + +/* + * ̼ئ ë Ȼҽ ë + * ¦ + * to void* ëҽ º̼ + * type CTYPE toë裻 + * value double toҽ ° + * ߯Ի + * ئ + */ +void substitutePointerFromType( void* to , CTYPE type ,double value) +{ + switch( type ){ + case CHAR: + *(char*)to = (char)value; + break; + case SHORT: + *(short*)to = (short)value; + break; + case INT: + *(int*)to = (int)value; + break; + case DOUBLE: + *(double*)to = (double)value; + break; + } +} + +BOOL luareadconfigfile( char* data ) +{ + char firstToken[256]; + int ret = getStringFromIndexWithDelim( data , "=", 1, firstToken, sizeof(firstToken) ); + if( ret == FALSE ){ + return FALSE; + } + int i; + for( i = 0 ; i < arraysizeof( readconf ) ; i ++ ){ + if( strcmp( readconf[i].name ,firstToken ) == 0 ){ + /* match */ + char secondToken[256]; /*2 ٯ */ + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( data , "=" , 2 + , secondToken , + sizeof(secondToken) ); + + /* NULL ٯëƩ */ + if( ret == FALSE ){ + break; + } + + if( readconf[i].charvalue != NULL ) + strcpysafe( readconf[i].charvalue + ,readconf[i].charsize, secondToken); + if( readconf[i].value != NULL ) { + if( strcmp( "ON" ,secondToken ) == 0 ) { + + substitutePointerFromType( readconf[i].value, + readconf[i].valuetype, + 1.0); + + }else if( strcmp( "OFF" ,secondToken ) == 0 ) { + + substitutePointerFromType( readconf[i].value, + readconf[i].valuetype, + 1.0); + }else { + strtolchecknum(secondToken, + (int*)readconf[i].value, + 10, readconf[i].valuetype); + } + } + break; + } + } + return TRUE; +} + + +/*------------------------------------------------------------ + * ɬð̻ë + * ¦ + * filename ̻ + * ߯Ի + * TRUE(1) + * FALSE(0) -> ̻P + ------------------------------------------------------------*/ +BOOL readconfigfile( char* filename ) +{ + FILE* f=NULL; + char linebuf[256]; /* */ + int linenum=0; /* ë */ + char realopenfilename[256]; /* ˱open °̻ */ + + char hostname[128]; + + /* ʯ ëƻ */ + if( gethostname( hostname, sizeof(hostname) ) != -1 ){ + char* initdot; + initdot = index( hostname, '.' ); + if( initdot != NULL ) + *initdot = '\0'; + snprintf( realopenfilename, sizeof(realopenfilename), + "%s.%s" , filename, hostname); + + /* ̻P */ + f=fopen( realopenfilename, "r" ); + + // if( f == NULL ) + // print( "Can't open %s. use %s instead\n", realopenfilename, filename ); + } + if( f == NULL ){ + f=fopen( filename , "r" ); /* ̻P */ + if( f == NULL ){ + print( "Can't open %s\n", filename ); + return FALSE; + } + } + + /* */ + while( fgets( linebuf , sizeof( linebuf ), f ) ){ + char firstToken[256]; /*1 ٯ */ + int i; /* */ + int ret; /**/ + + linenum ++; + + deleteWhiteSpace(linebuf); /* remove whitespace */ + + if( linebuf[0] == '#' )continue; /* comment */ + if( linebuf[0] == '\n' )continue; /* none */ + + chomp( linebuf ); /* remove tail newline */ + + /* delim "=" ƥ (1)ͼë */ + ret = getStringFromIndexWithDelim( linebuf , "=", 1, firstToken, + sizeof(firstToken) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + + /* readconf ƥ */ + for( i = 0 ; i < arraysizeof( readconf ) ; i ++ ){ + if( strcmp( readconf[i].name ,firstToken ) == 0 ){ + /* match */ + char secondToken[256]; /*2 ٯ */ + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( linebuf , "=" , 2 + , secondToken , + sizeof(secondToken) ); + + /* NULL ٯëƩ */ + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore", + filename , linenum); + break; + } + + + /*NULLҽ ئ*/ + if( readconf[i].charvalue != NULL ) + strcpysafe( readconf[i].charvalue + ,readconf[i].charsize, secondToken); + + /*NULLҽ ئ*/ + if( readconf[i].value != NULL ) { + if( strcmp( "ON" ,secondToken ) == 0 ) { + /*ON1ë ľ*/ + substitutePointerFromType( readconf[i].value, + readconf[i].valuetype, + 1.0); + + }else if( strcmp( "OFF" ,secondToken ) == 0 ) { + /*OFF1ë ľ*/ + substitutePointerFromType( readconf[i].value, + readconf[i].valuetype, + 1.0); + }else { + strtolchecknum(secondToken, + (int*)readconf[i].value, + 10, readconf[i].valuetype); + } + } + break; + } + } + } + fclose( f ); + lastConfig(); + return TRUE; +} +//ttom add this becaus the second had this function +/*------------------------------------------------------------ + * ޼ƽëɬ + * ¦ + * ئ + * ߯Ի + * unsigned int ƽë߯ +------------------------------------------------------------*/ +unsigned int setEncodeKey( void ) +{ + JENCODE_KEY = config.encodekey; + return JENCODE_KEY; +} +/*------------------------------------------------------------ +* ʧӡ̤ 뼰ëɬ +* ¦ +* ئ +* ߯Ի +* unsigned int ƽë߯ +------------------------------------------------------------*/ +unsigned int setAcWBSize( void ) +{ + AC_WBSIZE = config.acwbsize; + return AC_WBSIZE; +} +unsigned int getAcwriteSize( void ) +{ + return config.acwritesize; +} +unsigned int getErrUserDownFlg( void ) +{ + return config.ErrUserDownFlg; +} + + +#ifdef _DEL_DROP_GOLD +unsigned int getGolddeletetime( void ) +{ + if( config.Golddeletetime > 0 ) + return config.Golddeletetime; + else + return config.Itemdeletetime; +} +void setIGolddeletetime( unsigned int interval ) +{ + config.Golddeletetime = interval; +} +#endif + +#ifdef _NEW_PLAYER_CF +int getNewplayertrans( void ) +{ + if(config.newplayertrans > 7) + return 7; + else if(config.newplayertrans >= 0) + return config.newplayertrans; + else + return 0; +} +int getNewplayerlv( void ) +{ + if(config.newplayerlv > 160) + return 160; + else if(config.newplayerlv >0) + return config.newplayerlv; + else + return 0; +} +int getNewplayerpetlv( void ) +{ + if(config.newplayerpetlv > 160) + return 160; + else if(config.newplayerpetlv > 0) + return config.newplayerpetlv; + else + return 0; +} + +int getNewplayergivepet( int index ) +{ + if(config.newplayergivepet[index] > 0 ) + return config.newplayergivepet[index]; + else + return -1; +} + +int getNewplayergiveitem( int index ) +{ + if(config.newplayergiveitem[index] > 0 ) + return config.newplayergiveitem[index]; + else + return -1; +} + +void setNewplayergivepet( unsigned int index ,unsigned int interval) +{ + config.newplayergivepet[index] = interval; +} + +int getNewplayergivegold( void ) +{ + if(config.newplayergivegold > 1000000) + return 1000000; + else if(config.newplayergivegold < 0) + return 0; + else + return config.newplayergivegold; +} +int getRidePetLevel( void ) +{ + if(config.ridepetlevel > 0 ) + return config.ridepetlevel; + else + return -1; +} +#ifdef _VIP_SERVER +int getNewplayergivevip( void ) +{ + return config.newplayerpetvip < 0?0:config.newplayerpetvip; +} +#endif +#endif + +#ifdef _UNLAW_WARP_FLOOR +int getUnlawwarpfloor( unsigned int index ) +{ + char unlawwarpfloor[256]; + getStringFromIndexWithDelim(config.unlawwarpfloor,",", index+1, unlawwarpfloor, sizeof(unlawwarpfloor)); + return atoi(unlawwarpfloor); +} +#endif + +#ifdef _NO_JOIN_FLOOR +int getNoJoinFloor( unsigned int index ) +{ + char nojoinfloor[256]; + getStringFromIndexWithDelim(config.nojoinfloor,",", index+1, nojoinfloor, sizeof(nojoinfloor)); + return atoi(nojoinfloor); +} +#endif + +#ifdef _WATCH_FLOOR +int getWatchFloor( unsigned int index ) +{ + if(config.watchfloor[index] > 0 ) + return config.watchfloor[index]; + else + return -1; +} +char* getWatchFloorCF( void ) +{ + return (config.watchfloor[0]>0)? "":""; +} +#endif + +#ifdef _BATTLE_FLOOR +int getBattleFloor( unsigned int index ) +{ + + char battlefloor[256]; + if(getStringFromIndexWithDelim(config.battlefloorcf,",", index+1, battlefloor, sizeof(battlefloor))==TRUE) + return atoi(battlefloor); + else + return -1; +} +char* getBattleFloorCF( void ) +{ + return (config.battlefloor>0)? "":""; +} +#endif + +#ifdef _ANGEL_SUMMON + +extern int mission_num; + +BOOL LoadMissionList( void ) +{ + FILE* fp; + int i = 0; + + mission_num = 0; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "./data/mission.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("./data/mission.txt", "r"); +} + if (fp == NULL) + { + print("ļ򿪴\n"); + return FALSE; + } + + memset( missionlist, 0, sizeof(missionlist)); + + while(1){ + char line[1024]; + char token[1024]; + int mindex; + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + // #Ϊע******* + if( line[0] == '#' ) + continue; + for( i=0; i= MAXMISSION) + break; + + missionlist[mindex].id = mindex; + + getStringFromIndexWithDelim(line, ",", 2, token, sizeof(token)); + if (strcmp(token, "") == 0) break; + missionlist[mindex].level = atoi( token); + + getStringFromIndexWithDelim(line, ",", 3, token, sizeof(token)); + if (strcmp(token, "") == 0) break; + strcpy( missionlist[mindex].eventflag, token); + + getStringFromIndexWithDelim(line, ",", 4, token, sizeof(token)); + if (strcmp(token, "") == 0) break; + strcpy( missionlist[mindex].detail, token); + + //getStringFromIndexWithDelim(line, ",", 4, token, sizeof(token)); + //if (strcmp(token, "") == 0) break; + //strcpy( missionlist[mindex].bonus, token); + + getStringFromIndexWithDelim(line, ",", 5, token, sizeof(token)); + if (strcmp(token, "") == 0) break; + missionlist[mindex].limittime = atoi( token); +/* + print("\nMISSION[%d] lv:%d ef:%s detail:%s limit:%d ", mindex, + missionlist[mindex].level, missionlist[mindex].eventflag, + missionlist[mindex].detail, missionlist[mindex].limittime ); +*/ + mission_num++; + //if (mission_num > MAXMISSION) break; + } + fclose(fp); + return TRUE; +} + + + +BOOL LoadMissionCleanList( ) +{ + // ʽ... ʹ,,, + FILE* fp; + int listindex =0; + int i = 0; + + memset( missiontable, 0, sizeof(missiontable)); + +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "./data/missionclean.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("./data/missionclean.txt", "r"); +} + + if (fp == NULL) + { + print("ļ򿪴\n"); + return FALSE; + } + + while(1){ + char line[1024]; + char token[1024]; + + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + // #Ϊע******* + if( line[0] == '#' ) + continue; + for( i=0; i= MAXMISSIONTABLE) break; + } + fclose(fp); + return TRUE; +} + + +#endif + +#ifdef _JOBDAILY +extern DailyFileType dailyfile[MAXDAILYLIST]; +BOOL LoadJobdailyfile(void) +{ + char line[20000]; + char token[16384]; + int listindex =0; + int i; + FILE* fp; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "./data/jobdaily.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("./data/jobdaily.txt", "r"); +} + if (fp == NULL) + { + print("ճļ򿪴\n"); + return FALSE; + } + + memset( dailyfile, 0, sizeof(dailyfile)); + + while(1){ + line[0]='\0'; + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + //print("\n %s ", line); + chop(line); + + // #Ϊע + if( line[0] == '#' ) + continue; + for( i=0; i64){ + print("\n˵:%d\n",strlen(token)); + return FALSE; + } + strcpy( dailyfile[listindex].explain, token); + + getStringFromIndexWithDelim(line, "|", 4, token, sizeof(token)); + if (strcmp(token, "") == 0) break; + strcpy( dailyfile[listindex].state, token); + + /*print("\ndailyfile[%d] %s %s %s %s", listindex, + dailyfile[listindex].jobid, + dailyfile[listindex].rule, + dailyfile[listindex].explain, + dailyfile[listindex].state); + */ + listindex++; + if ( listindex >= MAXDAILYLIST) break; + } + fclose(fp); + return TRUE; +} +#endif + +#ifdef _USER_EXP_CF +BOOL LoadEXP( char* filename ) +{ + FILE* fp; + int i = 0; + int MaxLevel=0; + +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen(filename, "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + + while(1){ + char line[64], exp[64]; + if (fgets(line, sizeof(line), fp) == NULL) break; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + chop(line); + + if( line[0] == '#' ) + continue; + for( i=0; i= 200) break; + easyGetTokenFromString(line, 2, exp, sizeof(exp)); + NeedLevelUpTbls[MaxLevel]=atoi(exp); + } + fclose(fp); + return TRUE; +} + +char* getEXPfile( void ) +{ + return config.expfile; +} + +int getNeedLevelUpTbls( int level ) +{ + return NeedLevelUpTbls[level]; +} + +#endif + +#ifdef _UNREG_NEMA +char* getUnregname( int index ) +{ + return config.unregname[index]; +} +#endif + +#ifdef _TRANS_LEVEL_CF +int getChartrans( void ) +{ + if(config.chartrans>6) + config.chartrans=5; + return config.chartrans; +} +int getPettrans( void ) +{ + if(config.pettrans>2) + return 2; + else if(config.pettrans<-1) + return -1; + return config.pettrans; +} +int getYBLevel( void ) +{ + if(config.yblevel>config.maxlevel) + config.yblevel=config.maxlevel; + return config.yblevel; +} +int getMaxLevel( void ) +{ + return config.maxlevel; +} +#endif + +#ifdef _POINT +char* getPoint( void ) +{ + return (config.point>0)? "":""; +} +int getTransPoint( int index ) +{ + return config.transpoint[index]; +} +#endif + +#ifdef _PET_AND_ITEM_UP +char* getPetup( void ) +{ + return (config.petup>0)? "":""; +} +char* getItemup( void ) +{ + return (config.itemup>0)? "":""; +} +#endif +#ifdef _LOOP_ANNOUNCE +char* getLoopAnnouncePath( void ) +{ + return config.loopannouncepath; +} +int loadLoopAnnounce( void ) +{ + FILE* fp; + int i = 0; + config.loopannouncemax=0; + fp = fopen(config.loopannouncepath, "r"); + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + while(1){ + char line[1024]; + if (fgets(line, sizeof(line), fp) == NULL) break; + chop(line); + + if( line[0] == '#' ) + continue; + for( i=0; i<10; i++ ){ + if( line[i] == '#' ){ + line[i] = '\0'; + break; + } + } + //************************************* + strcpy(config.loopannounce[config.loopannouncemax],line); + config.loopannouncemax++; + } + fclose(fp); + return TRUE; +} +int getLoopAnnounceTime( void ) +{ + return (config.loopannouncetime<0)?-1:config.loopannouncetime; +} +int getLoopAnnounceMax( void ) +{ + return (config.loopannouncemax>0)?config.loopannouncemax:0; +} +char* getLoopAnnounce( int index ) +{ + return config.loopannounce[index]; +} +#endif + +#ifdef _SKILLUPPOINT_CF +int getSkup( void ) +{ + return (config.skup>0)?config.skup:0; +} +#endif +#ifdef _RIDELEVEL +int getRideLevel( void ) +{ + return config.ridelevel; +} +int getRideTrans( void ) +{ + return config.ridetrans; +} +#endif +#ifdef _REVLEVEL +char* getRevLevel( void ) +{ + return (config.revlevel>0)?"":""; +} +#endif +#ifdef _NEW_PLAYER_RIDE +char* getPlayerRide( void ) +{ + if(config.npride>2) + return "ͻ"; + else if(config.npride==2) + return ""; + else if(config.npride==1) + return "ͻ"; + else + return ""; +} +#endif + +#ifdef _FIX_CHARLOOPS +int getCharloops( void ) +{ + return config.charloops-1; +} +#endif + +#ifdef _PLAYER_ANNOUNCE +int getPAnnounce( void ) +{ + return max(-1, config.pannounce); +} +#endif +#ifdef _PLAYER_MOVE +int getPMove( void ) +{ + return max(-1, config.pmove); +} +#endif + +int getrecvbuffer( void ) +{ + if(config.recvbuffer<0) + return 0; + else if(config.recvbuffer>128) + return 128; + else + return config.recvbuffer; +} + +int getsendbuffer( void ) +{ + if(config.sendbuffer<0) + return 0; + else if(config.sendbuffer>128) + return 128; + else + return config.sendbuffer; +} + +int getrecvlowatbuffer( void ) +{ + if(config.recvlowatbuffer<0) + return 0; + else if(config.recvlowatbuffer>1024) + return 1024; + else + return config.recvlowatbuffer; +} + +int getrunlevel( void ) +{ + if(config.runlevel<-20) + return -20; + else if(config.runlevel>19) + return 19; + else + return config.runlevel; + +} + +#ifdef _SHOW_VIP_CF +int getShowVip( void ) +{ + if(config.showvip>2) + return 2; + else if(config.showvip<0) + return 0; + else + return config.showvip; +} +#endif + +#ifdef _PLAYER_NUM +int getPlayerNum( void ) +{ + return config.playernum; +} +void setPlayerNum( int num ) +{ + config.playernum=num; +} +#endif + +#ifdef _BATTLE_GOLD +int getBattleGold( void ) +{ + if(config.battlegold<0) + return 0; + else if(config.battlegold>100) + return 100; + else + return config.battlegold; + +} +#endif + +#ifdef _ANGEL_TIME +int getAngelPlayerTime( void ) +{ + return (config.angelplayertime>1)?config.angelplayertime:1; +} +int getAngelPlayerMun( void ) +{ + return (config.angelplayermun>2)?config.angelplayermun:2; +} +#endif + +#ifdef _RIDEMODE_20 +int getRideMode( void ) +{ + if(config.ridemode<0) + config.ridemode=0; + return config.ridemode; +} +#endif +#ifdef _FM_POINT_PK +char *getFmPointPK( void ) +{ + return (config.fmpointpk>0)?"":""; +} +#endif +#ifdef _ENEMY_ACTION +int getEnemyAction( void ) +{ + if(config.enemyact>100) + return 100; + else if(config.enemyact<1) + return 1; + else + return config.enemyact; +} +#endif + +#ifdef _FUSIONBEIT_TRANS +int getFusionbeitTrans( void ) +{ + if(config.fusionbeittrans>2) + return 2; + else if(config.fusionbeittrans<0) + return 0; + else + return config.fusionbeittrans; +} +#endif +int getCpuUse( void ) +{ + return config.cpuuse; +} +#ifdef _CHECK_PEPEAT +int getCheckRepeat( void ) +{ + return (config.CheckRepeat>0)?1:0; +} +#endif + +#ifdef _FM_JOINLIMIT +int getJoinFamilyTime( void ) +{ + return config.joinfamilytime; +} +#endif + +#ifdef _MAP_HEALERALLHEAL +int getMapHeal( int index ) +{ + char mapheal[256]; + getStringFromIndexWithDelim(config.mapheal,",", index+1, mapheal, sizeof(mapheal)); + return atoi(mapheal); +} +#endif + +#ifdef _THE_WORLD_SEND +int getTheWorldTrans() +{ + return config.thewordtrans; +} +int getTheWorldLevel() +{ + return config.thewordlevel; +} +int getTheWorldSend() +{ + return config.thewordsend; +} +#endif + +#ifdef _LOGIN_DISPLAY +int getLoginDisplay() +{ + return config.logindisplay; +} +#endif + +#ifdef _VIP_POINT_PK +int getVipPointPK( int index ) +{ + char vippointpk[256]; + if(getStringFromIndexWithDelim(config.vippointpk,",", index+1, vippointpk, sizeof(vippointpk))==TRUE){ + return atoi(vippointpk); + }else{ + return -1; + } +} +float getVipPointPKCost(void) +{ + return config.vippointpkcost / 100.00; +} +#endif + +#ifdef _SPECIAL_MAP +int getSpecialMap( int index ) +{ + char specialmap[256]; + if(getStringFromIndexWithDelim(config.specialmap,",", index+1, specialmap, sizeof(specialmap))==TRUE){ + return atoi(specialmap); + }else{ + return -1; + } +} +#endif + +#ifdef _NEW_AUTO_PK +int getAutoPkTime() +{ + if(config.autopk>23)config.autopk=23; + if(config.autopk<0)config.autopk=-1; + return config.autopk; +} +int getAutoPkTrans() +{ + return config.autopktrans; +} + +int getAutoPkLv() +{ + return config.autopklv; +} +#ifdef _FORMULATE_AUTO_PK +int getAutoPkPoint() +{ + return config.autopkpoint; +} +int getKillPoint() +{ + return config.killpoint; +} +#endif +#endif + +#ifdef _AUTO_DEL_PET +int getAutoDelPet( int index ) +{ + char autodelpet[256]; + getStringFromIndexWithDelim(config.autodelpet,",", index+1, autodelpet, sizeof(autodelpet)); + return atoi(autodelpet); +} +#endif + +#ifdef _AUTO_DEL_ITEM +int getAutoDelItem( int index ) +{ + char autodelitem[256]; + getStringFromIndexWithDelim(config.autodelitem,",", index+1, autodelitem, sizeof(autodelitem)); + return atoi(autodelitem); +} +#endif + +#ifdef _BT_PET +int getBtPet() +{ + return config.btpet; +} +#endif + +#ifdef _BT_ITEM +int getBtItem() +{ + return config.btitem; +} +#endif + +#ifdef _LUCK_STAR +int getLuckStarTime() +{ + if(config.luckstartime < 1)config.luckstartime=1; + return config.luckstartime; +} +int getLuckStarChances() +{ + return config.luckstarchances; +} +#endif + +#ifdef _BATTLE_GETITEM_RATE +int getBattleGetItemRate( int index ) +{ + char battlegetitemrate[256]; + getStringFromIndexWithDelim(config.battlegetitemrate,",", index+1, battlegetitemrate, sizeof(battlegetitemrate)); + return atoi(battlegetitemrate); +} +int getBattleGetItemRateMap() +{ + return config.battlegetitemratemap; +} +#endif + +#ifdef _UNLAW_THIS_LOGOUT +int getUnlawThisLogout( int index ) +{ + char unlawthislogout[256]; + getStringFromIndexWithDelim(config.unlawthislogout,",", index+1, unlawthislogout, sizeof(unlawthislogout)); + return atoi(unlawthislogout); +} +#endif + +#ifdef _TRANS_POINT_UP +int getTransPoinUP( int index ) +{ + char transpointup[256]; + getStringFromIndexWithDelim(config.transpointup,",", index+1, transpointup, sizeof(transpointup)); + return atoi(transpointup); +} +#endif + +#ifdef _OPEN_STW_SEND +int getOpenStwSendType( void ) +{ + if(config.stwsendtype<-1){ + config.stwsendtype=-1; + }else if(config.stwsendtype>5){ + config.stwsendtype=5; + } + return config.stwsendtype; +} +int getOpenStwSendPoint( void ) +{ + return max(1, config.stwsendpoint); +} + +#endif + +#ifdef _POOL_ITEM_BUG +int getPoolItemBug( void ) +{ + return config.poolitembug; +} +int getPoolItem( int id ) +{ + if(id<0)id = 0; + char poolitem[256]; + if(getStringFromIndexWithDelim(config.poolitem,",", id + 1, poolitem, sizeof(poolitem))==TRUE){ + return atoi(poolitem); + }else{ + return -1; + } +} + +#endif + +#ifdef _NO_STW_ENEMY +int getNoSTWNenemy( void ) +{ + return config.nostwenemy; +} + +int getNoSTWNenemyPoint( void ) +{ + return config.nostwenemypoint; +} +#endif + +#ifdef _NEW_STREET_VENDOR +int getStreetVendor( int id ) +{ + if(id<0)id = 0; + char streetvendorpoint[256]; + if(getStringFromIndexWithDelim(config.streetvendorpoint,",", id + 1, streetvendorpoint, sizeof(streetvendorpoint))==TRUE){ + return atoi(streetvendorpoint); + }else{ + return -1; + } +} + +#endif + +#ifdef _ITEM_PET_LOCKED +int getItemPetLocked( void ) +{ + return config.itampetlocked; +} +#endif + + +#ifdef _TALK_SAVE +int getSaveFame( void ) +{ + return max(0, config.savefame*100); +} +#endif + +#ifdef _TALK_CHECK +int getTalkCheck( void ) +{ + return (rand() % max(10, config.talkcheckmax)) + max(10, config.talkcheckmin); +} +#endif + +#ifdef _DISABLE_PROFESSION_SKILL +BOOL getDisableProfessionSkill( int floor ) +{ + int i=1; + char buff[64]; + while(getStringFromIndexWithDelim(config.disableprofessionskill,",", i, buff, sizeof(buff))){ + if(atoi(buff) == floor)return TRUE; + i++; + } + return FALSE; +} +#endif +#ifdef _ALL_SERV_SEND +int getAllServTrans() +{ + return config.allservtrans; +} +int getAllServLevel() +{ + return config.allservlevel; +} +int getAllServSend() +{ + return config.allservsend; +} +#endif +#ifdef _PET_TRANS_ABILITY +int getPetTransAbility() +{ + if(config.pettransability<=0)config.pettransability=0; + return config.pettransability; +} +int getPetTransAbility1() +{ + if(config.pettransability1<=0)config.pettransability1=150; + return config.pettransability1; +} +int getPetTransAbility2() +{ + if(config.pettransability2<=0)config.pettransability2=200; + return config.pettransability2; +} +#endif + +#ifdef _NEED_ITEM_ENEMY +int getDelNeedItem() +{ + return config.delneeditem; +} +#endif + +#ifdef _NOT_ESCAPE +int getNotEscape( int index) +{ + char notescape[256]; + if(getStringFromIndexWithDelim(config.notescape,",", index+1, notescape, sizeof(notescape))==TRUE){ + return atoi(notescape); + }else{ + return -1; + } +} +#endif + +#ifdef _PLAYER_OVERLAP_PK +int getPlayerOverlapPk( int index ) +{ + char playeroverlappk[256]; + if(getStringFromIndexWithDelim(config.playeroverlappk,",", index+1, playeroverlappk, sizeof(playeroverlappk))==TRUE){ + return atoi(playeroverlappk); + }else{ + return -1; + } +} +#endif + +#ifdef _FIMALY_PK_TIME +int getFimalyPkTime() +{ + return config.fimalypktime; +} +#endif + +#ifdef _PETSKILL_SHOP_LUA +char *getFreePetSkillShopPath() +{ + return config.freepetskillshoppath; +} +#endif + + +#ifdef _CANCEL_ANGLE_TRANS +int getCancelAngleTrans() +{ + return config.cancelanlgetrans; +} +#endif + +#ifdef _VIP_BATTLE_EXP +int getVipBattleexp() +{ + return config.vipbattleexp; +} +#endif + +#ifdef _NO_HELP_MAP +int getNoHelpMap( int index ) +{ + char nohelpmap[256]; + if(getStringFromIndexWithDelim(config.nohelpmap,",", index+1, nohelpmap, sizeof(nohelpmap))==TRUE){ + return atoi(nohelpmap); + }else{ + return -1; + } +} +#endif + +#ifdef _BATTLE_TIME +int getBattleTime() +{ + return config.battletime; +} +#endif + +#ifdef _SAME_IP_ONLINE_NUM +int getSameIpOnlineNum() +{ + return config.sameiponlinenum; +} +#endif + +#ifdef _STREET_VENDOR_TRANS +int getStreetVendorTrans() +{ + return config.streetvendortrans; +} +#endif + +#ifdef _CHECK_SEVER_IP +int checkServerIp( unsigned int ip ) +{ + char serverip[64]; + char cliip[64]; + int i = 1; + + int a, b, c, d; + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + + sprintf(cliip, "%d.%d.%d.%d", a, b, c, d); + + while(getStringFromIndexWithDelim(config.serverip,",", i++, serverip, sizeof(serverip))==TRUE){ + if(strcmp(cliip, serverip) == 0){ + return TRUE; + } + } + + return FALSE; +} +#endif + +#ifdef _DAMMAGE_CALC +int getDamageCalc() +{ + if(config.dammagecalc > 0){ + return config.dammagecalc; + }else{ + return 70; + } +} +#endif + + +#ifdef _PET_ENEMY_DEVELOP_UP +int getPetEnemyDevelopUp() +{ + return config.PetEnemyDevelopUp; +} +#endif + + +#ifdef _FIRST_LOCK_ITEM +int getFirstLockItem( int index ) +{ + char FirstLockItem[256]; + if(getStringFromIndexWithDelim(config.FirstLockItem,",", index+1, FirstLockItem, sizeof(FirstLockItem))==TRUE){ + return atoi(FirstLockItem); + }else{ + return -1; + } +} +#endif +int getConnectnum() +{ + return config.Connectnum; +} + +#ifdef _PETSKILL_NEW_PASSIVE +int getAutoGetSkill(void) +{ + if (config.autogetskill==1) return 1; + + return 0; +} + +int getSkillFusion(void) +{ + return config.skillfusion; +} + +int getSkillCount(void) +{ + if (config.skillcount<1|| config.skillcount>6) return 1; + return config.skillcount; +} + +//üɵλ +int getSkillPos(void) +{ + if (config.getskillpos<1 || config.getskillpos>7) return 6; + return config.getskillpos-1; +} + +//ݼܵȼϰø +int getSkillProb(int skillLevel){ + char prob[20]; + if(getStringFromIndexWithDelim(config.skillinfolv[skillLevel-1],"|", 1, prob, sizeof(prob)) == FALSE) + return 0; + return atoi(prob); +} + +//ݼܵĵȼóʼ߽βļ skillLevelܵȼ start 1ʼ2 +int getSkillRange(int skillLevel,int start){ + char index[20]; + if(getStringFromIndexWithDelim(config.skillinfolv[skillLevel-1],"|", start+1, index, sizeof(index)) == FALSE) + return -1; + return atoi(index); + +} + +//ںϳķΧ PETID +int getFusionRange(int start){ + char index[20]; + if(getStringFromIndexWithDelim(config.fusionrange,"|", start, index, sizeof(index)) == FALSE) + return -1; + return atoi(index); + +} +//Ƿںϳ +int isFusionPet(int petId){ + if ((petId>=getFusionRange(1)&& petId<=getFusionRange(2))|| petId==1045) return 1; + return 0; +} + +//DZֵܷΪ Ϊ +int isPassiveSkill(int skillId){ + if (skillId<0) return -1; + char start[20]; + char end[20]; + int i; + for (i=0;i<5;i++){ + if(getStringFromIndexWithDelim(config.skillinfolv[i],"|", 2, start, sizeof(start)) == FALSE) + return -1; + if(getStringFromIndexWithDelim(config.skillinfolv[i],"|", 3, end, sizeof(end)) == FALSE) + return -1; + if (skillId>=atoi(start) && skillId<=atoi(end)) + return 1; + } + return -1; +} +//DZֵܷΪܵĵȼ Ϊ +int getSkillLevel(int skillId){ + if (skillId<0) return -1; + char start[20]; + char end[20]; + int i; + for (i=0;i<5;i++){ + if(getStringFromIndexWithDelim(config.skillinfolv[i],"|", 2, start, sizeof(start)) == FALSE) + return -1; + if(getStringFromIndexWithDelim(config.skillinfolv[i],"|", 3, end, sizeof(end)) == FALSE) + return -1; + if (skillId>=atoi(start) && skillId<=atoi(end)) + return i+1; + } + return -1; +} +//ݵȼñ +int getRandSkillByLevel(int skillLevel){ + if (skillLevel<0||skillLevel>5) return -1; + return RAND(getSkillRange(skillLevel,1),getSkillRange(skillLevel,2)); +} + +//һö +int getRandSkill(void){ + int i,k; + int prob[5]; + for (i=1;i<=5;i++){ + prob[i-1]=getSkillProb(i); + } + k=RAND(0,10000); + if (k<=prob[0]){ + return getRandSkillByLevel(1); + }else if(k<=(prob[0]+prob[1])){ + return getRandSkillByLevel(2); + }else if(k<=(prob[0]+prob[1]+prob[2])){ + return getRandSkillByLevel(3); + }else if(k<=(prob[0]+prob[1]+prob[2]+prob[3])){ + return getRandSkillByLevel(4); + }else if(k<=(prob[0]+prob[1]+prob[2]+prob[3]+prob[4])){ + return getRandSkillByLevel(5); + }else{ + return -1; + } +} +#endif +#ifdef _SHARE_EXP +int getExpShare(void){ + if (config.expshare ==1) + return 1; + else + return 0; +} +#endif +#ifdef _DEFEND_BIGBAO +int getBigBao(void){ + if(config.bigbao<=0) return 1024; + return config.bigbao; +} +int getBigBao2(void){ + if(config.bigbao2<=0) return 1024; + return config.bigbao2; +} +#endif + +#ifdef _MO_SHOW_DEBUG +int isDebug(void){ + return config.isdebug; +} +#endif +#ifdef _CHAR_LOOP_TIME +int getCharLoopTime() +{ + return config.charlooptime; +} +#endif +#ifdef _MO_RELOAD_NPC +int getReloadNpcTime(void){ + if(config.reloadnpctime<=0) return 0; + return config.reloadnpctime; +} + +int getReloadNpcType(void){ + if(config.reloadnpctype<=0) return 0; + return 1; +} +#endif +#ifdef _JZ_NEWSCRIPT_LUA +char *getLuaFile(void) +{ + return config.luafile; +} +BOOL ITEM_LuaInit(const char * _FileName){ + if (strlen( _FileName) != 0) return TRUE; + return FALSE; +} +#endif + +#ifdef _ITEM_LUA +const char *getitemluafile(void){ + return config.itemluafile; +} +#endif +#ifdef _MO_LNS_NLSUOXU +int GetConfigLineType(char *TM_ConfigName) +{ + int i; + + for( i = 0 ; i < arraysizeof( readconf ) ; i ++ ){ + if (strcmp(readconf[i].name,TM_ConfigName) == 0) break; + } + if (i == arraysizeof( readconf )) return -1; + switch( readconf[i].valuetype ){ + case CHAR: + return 0; + break; + case SHORT: + return 1; + break; + case INT: + return 2; + break; + case DOUBLE: + return 3; + break; + } +} + +char* GetConfigLineVal( char* TM_ConfigName ) +{ + char* filename = getConfigfilename(); + FILE* f=NULL; + char linebuf[256]; /* */ + int linenum=0; /* ë */ + char realopenfilename[256]; /* ˱open °̻ */ + char secondToken[256]; + char hostname[128]; + + + if( f == NULL ){ + f=fopen( filename , "r" ); /* ̻P */ + if( f == NULL ){ + print( "Can't open %s\n", filename ); + return FALSE; + } + } + + /* */ + while( fgets( linebuf , sizeof( linebuf ), f ) ){ + char firstToken[256]; /*1 ٯ */ + int i; /* */ + int ret; /**/ + + linenum ++; + + deleteWhiteSpace(linebuf); /* remove whitespace */ + + if( linebuf[0] == '#' )continue; /* comment */ + if( linebuf[0] == '\n' )continue; /* none */ + + chomp( linebuf ); /* remove tail newline */ + + /* delim "=" ƥ (1)ͼë */ + ret = getStringFromIndexWithDelim( linebuf , "=", 1, firstToken, + sizeof(firstToken) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + if (strcmp(firstToken,TM_ConfigName) != 0) continue; + /* readconf ƥ */ + for( i = 0 ; i < arraysizeof( readconf ) ; i ++ ){ + if( strcmp( readconf[i].name ,firstToken ) == 0 ){ + /* match */ + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( linebuf , "=" , 2 + , secondToken , + sizeof(secondToken) ); + + /* NULL ٯëƩ */ + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore", + filename , linenum); + break; + } + return secondToken; + break; + } + } + break; + } + fclose( f ); + lastConfig(); + return NULL; +} + +int getCopymapstartingID( void ) +{ + return config.mapstart; +} +#endif +#ifdef _ROOKIE_ITEM +unsigned int getRookieItem(int index) +{ + if (config.rookieitem[index]>0) return config.rookieitem[index]; + return 0; +} +#endif +#ifdef _NO_TRANS_ITEM +unsigned int getNoTransItem(void) +{ + return config.notransitem; +} +#endif +#ifdef _MAX_MERGE_LEVEL +unsigned int getMaxMergeLevel(void) +{ + return config.maxmergelevel; +} +#endif +#ifdef _NO_ATTACK +int getAttTime(void) +{ + return config.atttime; +} +int getAttSafeTime(void) +{ + return config.attsafetime; +} +int getAttCnt(void) +{ + return config.attcnt; +} +int getLateTime(void) +{ + return config.latetime; +} +int getAttDmeTime(void) +{ + return config.attdmetime; +} +int getAttDmeCnt(void) +{ + return config.attdmecnt; +} +#endif +char* getNoAttIp(int num) +{ + if(num<0) num=0; + else if(num>4) num=4; + return config.noattip[num]; +} +#ifdef _NO_FULLPLAYER_ATT +int getNoFullPlayer(void){ + return config.nofullplayer; +} +int getNoFull2Player(void){ + return config.nofull2player; +} +int getNoCdkeyPlayer(void){ + if(config.nocdkeyplayer<0 || config.nocdkeyplayer>2000) + return 0; + return config.nocdkeyplayer; +} +int getNoCdkeyMode(void){ + if(config.nocdkeymode<0 || config.nocdkeymode>2) + return 0; + return config.nocdkeymode; +} +int getNoCdkeyType(void){ + if(config.nocdkeytype<0 || config.nocdkeytype>2) + return 0; + return config.nocdkeytype; +} +int getNoFullTime(void){ + return config.nofulltime; +} +int getFengType(void){ + return config.fengtype; +} +int getNoFullEndPlayer(void){ + return config.nofullendplayer; +} +int getNoFullEndTime(void){ + return config.nofullendtime; +} +int getManRenNum(void){ + return config.manrennum; +} +#endif + +int getLockType(void){ + if(config.locktype<=0) return 0; + return config.locktype; +} + +#ifdef _NEW_FUNC_DECRYPT +unsigned int getAllowerrornum2( void ) +{ + return config.allowerrornum2; +} +#endif +#ifdef _MO_LOGIN_NO_KICK +int getLoginNoKick(void){ + if (config.loginnokick==1) return 1; + return 0; +} +#endif + +#ifdef _MO_ILLEGAL_NAME +char* getIllegalName( int index ) +{ + char illegalname[256]; + if(getStringFromIndexWithDelim(config.illegalname,",", index+1, illegalname, sizeof(illegalname))==TRUE){ + return illegalname; + }else{ + return "\0"; + } +} +#endif + + +#ifdef _NO_USE_PACKET_MAP +int getNoPacketMap( int index ) +{ + char NoPacketMap[256]; + if(getStringFromIndexWithDelim(config.nousepacketmap,",", index+1, NoPacketMap, sizeof(NoPacketMap))==TRUE){ + return atoi(NoPacketMap); + }else{ + return -1; + } +} +#endif +#ifdef _NO_USE_MAGIC_MAP +int getNoMagicMap( int index ) +{ + char NoMagicMap[256]; + if(getStringFromIndexWithDelim(config.nousemagicmap,",", index+1, NoMagicMap, sizeof(NoMagicMap))==TRUE){ + return atoi(NoMagicMap); + }else{ + return -1; + } +} +#endif + + +#ifdef _SOME_PETMAIL +int getPetMailFlg(void){ + if(config.petmailflg==1){ + return config.petmailflg; + } + return 0; + } +int getPetMailPetid(unsigned int index ) +{ + char petid[256]; + if(getStringFromIndexWithDelim(config.somepetmail,",", index+1, petid, sizeof(petid))==TRUE){ + return atoi(petid); + }else{ + return -1; + } +} +#endif +#ifdef _CTRL_TRANS_DEVELOP +int getCtrlTrans(void){ + if(config.ctrltrans==1){ + return config.ctrltrans; + } + return 0; +} +#endif + +#ifdef _PETMAIL_TIME +int getPetMailTime(void){ + if(config.petmailtime<=0) return 0; + return config.petmailtime; +} +#endif +#ifdef _UP_BBPETPROB +int getUpBBProb(void){ + if(config.upbbprob==1) return 1; + return 0; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/const.c b/石器时代服务器端最新完整源代码/Serv/gmsv/const.c new file mode 100644 index 0000000..9413277 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/const.c @@ -0,0 +1,794 @@ +#include "version.h" +#include "common.h" + +#include "char.h" +#include "char_data.h" +#include "item.h" +#include "battle.h" +#include "object.h" +#include "magic_base.h" +#ifdef _MO_ADD_LUADX +#include "enemy.h" +#endif +//0-1999 CHAR_getInt +//2000-3999 CHAR_getChar +//4000-5999 CHAR_getWorkInt +//6000-7999 CHAR_getWorkChar +//8000-9999 CHAR_getFlg +#define LUA_DATALINE0 0 +#define LUA_DATALINE1 2000 +#define LUA_DATALINE2 4000 +#define LUA_DATALINE3 6000 +#define LUA_DATALINE4 8000 +#define LUA_DATALINE5 10000 +#ifdef _JZ_NEWSCRIPT_LUA + +lua_const M_Lua_RegConstList[] = { + {"_VIP%", sizeof("_VIP%"), LUA_DATALINE5 + 1}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_DATAPLACENUMBER}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_BASEIMAGENUMBER}, + {"_ԭ%", sizeof("_ԭ%"), LUA_DATALINE0 + CHAR_BASEBASEIMAGENUMBER}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FACEIMAGENUMBER}, + {"_ͼ%", sizeof("_ͼ%"), LUA_DATALINE0 + CHAR_FLOOR}, + {"_X%", sizeof("_X%"), LUA_DATALINE0 + CHAR_X}, + {"_Y%", sizeof("_Y%"), LUA_DATALINE0 + CHAR_Y}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_DIR}, + {"_ȼ%", sizeof("_ȼ%"), LUA_DATALINE0 + CHAR_LV}, + {"_ʯ%", sizeof("_ʯ%"), LUA_DATALINE0 + CHAR_GOLD}, + {"_Ѫ%", sizeof("_Ѫ%"), LUA_DATALINE0 + CHAR_HP}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_MP}, + {"_M%", sizeof("_M%"), LUA_DATALINE0 + CHAR_MAXMP}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_VITAL}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_STR}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_TOUGH}, + {"_ٶ%", sizeof("_ٶ%"), LUA_DATALINE0 + CHAR_DEX}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_CHARM}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LUCK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_EARTHAT}, + {"_ˮ%", sizeof("_ˮ%"), LUA_DATALINE0 + CHAR_WATERAT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FIREAT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_WINDAT}, + {"_ս%", sizeof("_ս%"), LUA_DATALINE0 + CHAR_DEFAULTPET}, + {"_CL%", sizeof("_CL%"), LUA_DATALINE0 + CHAR_CRITIAL}, + {"_CR%", sizeof("_CR%"), LUA_DATALINE0 + CHAR_COUNTER}, + {"_ϡ%", sizeof("_ϡ%"), LUA_DATALINE0 + CHAR_RARE}, + {"_RH%", sizeof("_RH%"), LUA_DATALINE0 + CHAR_RADARSTRENGTH}, + {"_CE%", sizeof("_CE%"), LUA_DATALINE0 + CHAR_CHATVOLUME}, + {"_ML%", sizeof("_ML%"), LUA_DATALINE0 + CHAR_MERCHANTLEVEL}, + {"_¼%", sizeof("_¼%"), LUA_DATALINE0 + CHAR_SAVEPOINT}, + {"_DM%", sizeof("_DM%"), LUA_DATALINE0 + CHAR_DETERMINEITEM}, + {"_ƺ%", sizeof("_ƺ%"), LUA_DATALINE0 + CHAR_INDEXOFEQTITLE}, + {"_ƶ%", sizeof("_ƶ%"), LUA_DATALINE0 + CHAR_POISON}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_PARALYSIS}, + {"_Ĭ%", sizeof("_Ĭ%"), LUA_DATALINE0 + CHAR_SLEEP}, + {"_ʯ%", sizeof("_ʯ%"), LUA_DATALINE0 + CHAR_STONE}, + {"_ư%", sizeof("_ư%"), LUA_DATALINE0 + CHAR_DRUNK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_CONFUSION}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LOGINCOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_DEADCOUNT}, + {"_ߴ%", sizeof("_ߴ%"), LUA_DATALINE0 + CHAR_WALKCOUNT}, + {"_˵%", sizeof("_˵%"), LUA_DATALINE0 + CHAR_TALKCOUNT}, + {"_˴%", sizeof("_˴%"), LUA_DATALINE0 + CHAR_DAMAGECOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_GETPETCOUNT}, + {"_ɱ%", sizeof("_ɱ%"), LUA_DATALINE0 + CHAR_KILLPETCOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_DEADPETCOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_SENDMAILCOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_MERGEITEMCOUNT}, + {"_PK%", sizeof("_PK%"), LUA_DATALINE0 + CHAR_DUELBATTLECOUNT}, + {"_PӮ%", sizeof("_PӮ%"), LUA_DATALINE0 + CHAR_DUELWINCOUNT}, + {"_P%", sizeof("_P%"), LUA_DATALINE0 + CHAR_DUELLOSECOUNT}, + {"_P%", sizeof("_P%"), LUA_DATALINE0 + CHAR_DUELSTWINCOUNT}, + {"_P%", sizeof("_P%"), LUA_DATALINE0 + CHAR_DUELMAXSTWINCOUNT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_WHICHTYPE}, + {"_Ƽ%", sizeof("_Ƽ%"), LUA_DATALINE0 + CHAR_WALKINTERVAL}, + {"_ѭʱ%", sizeof("_ѭʱ%"), LUA_DATALINE0 + CHAR_LOOPINTERVAL}, +#ifdef _NEWOPEN_MAXEXP + {"_ɾ%", sizeof("_ɾ%"), LUA_DATALINE0 + CHAR_OLDEXP}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_EXP}, +#else + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_EXP}, +#endif + +#ifdef _MO_ADD_LUADX + {"_ѪMAX%", sizeof("_ѪMAX%"), LUA_DATALINE2 + CHAR_WORKMAXHP}, + {"_MAX%", sizeof("_MAX%"), LUA_DATALINE2 + CHAR_WORKMAXMP}, + {"_ɳ%", sizeof("_ɳ%"), LUA_DATALINE0 + CHAR_ALLOCPOINT}, + {"_PETRANK%", sizeof("_PETRANK%"), LUA_DATALINE0 + CHAR_PETRANK}, + {"_ENEMYBASE%", sizeof("_ENEMYBASE%"), LUA_DATALINE0 + CHAR_PETID}, + {"_̯%", sizeof("_̯%"), LUA_DATALINE2 + CHAR_WORKSTREETVENDOR}, + {"_̯%", sizeof("_̯%"), LUA_DATALINE2 + CHAR_WORKSTREETVENDOR_WHO}, + {"_̯%", sizeof("_̯%"), LUA_DATALINE0 + CHAR_STREETVENDOR_NAME}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LOVE}, + {"_ż%", sizeof("_ż%"), LUA_DATALINE0 + CHAR_LOVERID}, + {"_ż%", sizeof("_ż%"), LUA_DATALINE0 + CHAR_LOVERNAME}, + {"ɳ_ٶ%", sizeof("ɳ_ٶ%"), 0}, + {"ɳ_%", sizeof("ɳ_%"), 1}, + {"ɳ_%", sizeof("ɳ_%"), 2}, + {"ɳ_%", sizeof("ɳ_%"), 3}, + {"_ٶȳɳ%", sizeof("_ٶȳɳ%"), 0}, + {"_ɳ%", sizeof("_ɳ%"), 1}, + {"_ɳ%", sizeof("_ɳ%"), 2}, + {"_ɳ%", sizeof("_ɳ%"), 3}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_TEMPNO}, + {"ģ_ʼ%", sizeof("ģ_ʼ%"), LUA_DATALINE0 + E_T_INITNUM}, + {"ģ_%", sizeof("ģ_%"), E_T_LVUPPOINT}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_BASEVITAL}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_BASESTR}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_BASETGH}, + {"ģ_ٶ%", sizeof("ģ_ٶ%"), LUA_DATALINE0 + E_T_BASEDEX}, + {"ģ_AI%", sizeof("ģ_AI%"), LUA_DATALINE0 + E_T_MODAI}, + {"ģ_GET%", sizeof("ģ_GET%"), LUA_DATALINE0 + E_T_GET}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_EARTHAT}, + {"ģ_ˮ%", sizeof("ģ_ˮ%"), LUA_DATALINE0 + E_T_WATERAT}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_FIREAT}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_WINDAT}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_POISON}, + {"ģ_鿹%", sizeof("ģ_鿹%"), LUA_DATALINE0 + E_T_PARALYSIS}, + {"ģ_Ĭ%", sizeof("ģ_Ĭ%"), LUA_DATALINE0 + E_T_SLEEP}, + {"ģ_ʯ%", sizeof("ģ_ʯ%"), LUA_DATALINE0 + E_T_STONE}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_DRUNK}, + {"ģ_ҿ%", sizeof("ģ_ҿ%"), LUA_DATALINE0 + E_T_CONFUSION}, + {"ģ_輼1%", sizeof("ģ_輼1%"), LUA_DATALINE0 + E_T_PETSKILL1}, + {"ģ_輼2%", sizeof("ģ_輼2%"), LUA_DATALINE0 + E_T_PETSKILL2}, + {"ģ_輼3%", sizeof("ģ_輼3%"), LUA_DATALINE0 + E_T_PETSKILL3}, + {"ģ_輼4%", sizeof("ģ_輼4%"), LUA_DATALINE0 + E_T_PETSKILL4}, + {"ģ_輼5%", sizeof("ģ_輼5%"), LUA_DATALINE0 + E_T_PETSKILL5}, + {"ģ_輼6%", sizeof("ģ_輼6%"), LUA_DATALINE0 + E_T_PETSKILL6}, + {"ģ_輼7%", sizeof("ģ_輼7%"), LUA_DATALINE0 + E_T_PETSKILL7}, + {"ģ_ϡ%", sizeof("ģ_ϡ%"), LUA_DATALINE0 + E_T_RARE}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_CRITICAL}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_COUNTER}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_SLOT}, + {"ģ_ͼ%", sizeof("ģ_ͼ%"), LUA_DATALINE0 + E_T_IMGNUMBER}, + {"ģ_FLG%", sizeof("ģ_FLG%"), LUA_DATALINE0 + E_T_PETFLG}, + {"ģ_ߴ%", sizeof("ģ_ߴ%"), LUA_DATALINE0 + E_T_SIZE}, + {"ģ_%", sizeof("ģ_%"), LUA_DATALINE0 + E_T_LIMITLEVEL}, +#ifdef _PET_FUSION + {"ģ_ں%", sizeof("ģ_ں%"), LUA_DATALINE0 + E_T_FUSIONCODE}, +#endif + {"ģ_ԭ%", sizeof("ģ_ԭ%"), LUA_DATALINE1 + E_T_NAME}, +#endif + + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LASTTALKELDER}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_SKILLUPPOINT}, + {"_LT%", sizeof("_LT%"), LUA_DATALINE0 + CHAR_LEVELUPPOINT}, + {"_ͼ%", sizeof("_ͼ%"), LUA_DATALINE0 + CHAR_IMAGETYPE}, + {"_CLR%", sizeof("_CLR%"), LUA_DATALINE0 + CHAR_NAMECOLOR}, + {"_ɫ%", sizeof("_ɫ%"), LUA_DATALINE0 + CHAR_POPUPNAMECOLOR}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LASTTIMESETLUCK}, + {"_DP%", sizeof("_DP%"), LUA_DATALINE0 + CHAR_DUELPOINT}, + {"_ת%", sizeof("_ת%"), LUA_DATALINE0 + CHAR_TRANSMIGRATION}, + {"_ת%", sizeof("_ת%"), LUA_DATALINE0 + CHAR_TRANSEQUATION}, + {"_IA%", sizeof("_IA%"), LUA_DATALINE0 + CHAR_INITDATA}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_SILENT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FMINDEX}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + CHAR_FMLEADERFLAG}, + {"_ؾ%", sizeof("_ؾ%"), LUA_DATALINE0 + CHAR_FMSPRITE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_BANKGOLD}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_RIDEPET}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LEARNRIDE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_LIMITLEVEL}, +#ifdef _PET_FUSION + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FUSIONCODE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FUSIONINDEX}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FUSIONRAISE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FUSIONBEIT}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_FUSIONTIMELIMIT}, +#endif +#ifdef _DEATH_CONTEND + {"_ӱ%", sizeof("_ӱ%"), LUA_DATALINE0 + CHAR_PKLISTTEAMNUM}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_PKLISTLEADER}, +#endif +#ifdef _PERSONAL_FAME + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FAME}, +#endif +#ifdef _MO_Mercenary + {"_Ӷ%", sizeof("_Ӷ%"), LUA_DATALINE0 + CHAR_MERCENARY}, //Ӷ +#endif +#ifdef _VIP_RIDE + {"_VIP%", sizeof("_VIP%"), LUA_DATALINE0 + CHAR_VIPRIDE}, + {"_VIPʱ%", sizeof("_VIPʱ%"), LUA_DATALINE0 + CHAR_VIPTIME}, +#endif +#ifdef _VIP_SERVER + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_AMPOINT}, +#endif +#ifdef _EV_NUM + {"_ܻ%", sizeof("_ܻ%"), LUA_DATALINE0 + CHAR_EVNUM}, +#endif + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_MISSIONTRAIN_NUM}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_MISSIONTRAIN_TIME}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_MISSIONTRAIN_NUM}, // ܻ + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_EVOLVE}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_ONLINE_TIME}, + {"_¥ʱ%", sizeof("_¥ʱ%"), LUA_DATALINE0 + CHAR_FLOORDIFI_TIME}, + {"_Ʒ%", sizeof("_Ʒ%"), LUA_DATALINE0 + CHAR_SUPER}, + {"_ƺŵȼ%", sizeof("_ƺŵȼ%"), LUA_DATALINE0 + CHAR_TITLE_LV}, + {"_ƺʱ%", sizeof("_ƺʱ%"), LUA_DATALINE0 + CHAR_TITLE_TIME}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_MISSION_TIME}, + +#ifdef _ATTACK_MAGIC + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_EARTH_EXP}, + {"_ˮħ%", sizeof("_ˮħ%"), LUA_DATALINE0 + CHAR_WATER_EXP}, + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_FIRE_EXP}, + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_WIND_EXP}, + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_EARTH_RESIST}, + {"_ˮħ%", sizeof("_ˮħ%"), LUA_DATALINE0 + CHAR_WATER_RESIST}, + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_FIRE_RESIST}, + {"_ħ%", sizeof("_ħ%"), LUA_DATALINE0 + CHAR_WIND_RESIST}, + {"_쾭%", sizeof("_쾭%"), LUA_DATALINE0 + CHAR_EARTH_ATTMAGIC_EXP}, + {"_ˮ쾭%", sizeof("_ˮ쾭%"), LUA_DATALINE0 + CHAR_WATER_ATTMAGIC_EXP}, + {"_쾭%", sizeof("_쾭%"), LUA_DATALINE0 + CHAR_FIRE_ATTMAGIC_EXP}, + {"_쾭%", sizeof("_쾭%"), LUA_DATALINE0 + CHAR_WIND_ATTMAGIC_EXP}, + {"_ؿ%", sizeof("_ؿ%"), LUA_DATALINE0 + CHAR_EARTH_DEFMAGIC_EXP}, + {"_ˮ%", sizeof("_ˮ%"), LUA_DATALINE0 + CHAR_WATER_DEFMAGIC_EXP}, + {"_𿹾%", sizeof("_𿹾%"), LUA_DATALINE0 + CHAR_FIRE_DEFMAGIC_EXP}, + {"_翹%", sizeof("_翹%"), LUA_DATALINE0 + CHAR_WIND_DEFMAGIC_EXP}, +#endif +#ifdef _GAMBLE_BANK + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_PERSONAGOLD}, +#endif +#ifdef _DROPSTAKENEW + {"_ķ%", sizeof("_ķ%"), LUA_DATALINE0 + CHAR_GAMBLENUM}, +#endif +#ifdef _AUCTIONEER + {"_ĵ%", sizeof("_ĵ%"), LUA_DATALINE0 + CHAR_AUCGOLD}, +#endif +#ifdef _PET_EVOLUTION + {"_Ѫҩ%", sizeof("_Ѫҩ%"), LUA_DATALINE0 + CHAR_EVOLUTIONBASEVTL}, + {"_ҩ%", sizeof("_ҩ%"), LUA_DATALINE0 + CHAR_EVOLUTIONBASESTR}, + {"_ҩ%", sizeof("_ҩ%"), LUA_DATALINE0 + CHAR_EVOLUTIONBASETGH}, + {"_ҩ%", sizeof("_ҩ%"), LUA_DATALINE0 + CHAR_EVOLUTIONBASEDEX}, +#endif +#ifdef _FAMILYBANKSTONELOG + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FMBANKGOLD}, +#endif +#ifdef _FM_JOINLIMIT + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_FMTIMELIMIT}, +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + {"_ְҵ%", sizeof("_ְҵ%"), LUA_DATALINE0 + PROFESSION_CLASS}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_LEVEL}, + //{"_ְ", sizeof("_ְ"), LUA_DATALINE0 + PROFESSION_EXP}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_SKILL_POINT}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + ATTACHPILE}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_FIRE_P}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_ICE_P}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_THUNDER_P}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_FIRE_R}, + {"_ְ%", sizeof("_ְ%"), LUA_DATALINE0 + PROFESSION_ICE_R}, + {"_ְ׿%", sizeof("_ְ׿%"), LUA_DATALINE0 + PROFESSION_THUNDER_R}, +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + {"_ս%", sizeof("_ս%"), LUA_DATALINE0 + CHAR_HEROFLOOR}, +#endif +#ifdef _PETSKILL_BECOMEPIG + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_BECOMEPIG}, + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_BECOMEPIG_BBI}, +#endif + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + CHAR_LASTLEAVETIME}, +#ifdef _NEW_MANOR_LAW + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_MOMENTUM}, +#endif +#ifdef _ANGEL_SUMMON + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_HEROCNT}, +#endif +#ifdef _TEACHER_SYSTEM + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_TEACHER_FAME}, +#endif +#ifdef _MO_ESC_REPORT + {"_ǩ%", sizeof("_ǩ%"), LUA_DATALINE0 + CHAR_REPORT}, +#endif +#ifdef _RACEMAN + {"_CKN%", sizeof("_CKN%"), LUA_DATALINE0 + CHAR_CHECKIN}, + {"_CN1%", sizeof("_CN1%"), LUA_DATALINE0 + CHAR_CATCHCNT1}, + {"_CN2%", sizeof("_CN2%"), LUA_DATALINE0 + CHAR_CATCHCNT2}, + {"_CN3%", sizeof("_CN3%"), LUA_DATALINE0 + CHAR_CATCHCNT3}, + {"_CN4%", sizeof("_CN4%"), LUA_DATALINE0 + CHAR_CATCHCNT4}, + {"_CN5%", sizeof("_CN5%"), LUA_DATALINE0 + CHAR_CATCHCNT5}, + {"_KN1%", sizeof("_KN1%"), LUA_DATALINE0 + CHAR_KINDCNT1}, + {"_KN2%", sizeof("_KN2%"), LUA_DATALINE0 + CHAR_KINDCNT2}, + {"_KN3%", sizeof("_KN3%"), LUA_DATALINE0 + CHAR_KINDCNT3}, + {"_KN4%", sizeof("_KN4%"), LUA_DATALINE0 + CHAR_KINDCNT4}, + {"_KN5%", sizeof("_KN5%"), LUA_DATALINE0 + CHAR_KINDCNT5}, + {"_KN6%", sizeof("_KN6%"), LUA_DATALINE0 + CHAR_KINDCNT6}, + {"_KN7%", sizeof("_KN7%"), LUA_DATALINE0 + CHAR_KINDCNT7}, + {"_KN8%", sizeof("_KN8%"), LUA_DATALINE0 + CHAR_KINDCNT8}, + {"_KN9%", sizeof("_KN9%"), LUA_DATALINE0 + CHAR_KINDCNT9}, + {"_KN10%", sizeof("_KN10%"), LUA_DATALINE0 + CHAR_KINDCNT10}, +#endif + {"_ף%", sizeof("_ף%"), LUA_DATALINE0 + CHAR_BEATITUDE}, +#ifdef _ACTIVE_GAME + {"_%", sizeof("_%"), LUA_DATALINE0 + CHAR_ACTIVE}, +#endif + {"_1%", sizeof("_1%"), LUA_DATALINE0 + CHAR_LUASAVE_WORKINT_1}, //lua洢 + {"_2%", sizeof("_2%"), LUA_DATALINE0 + CHAR_LUASAVE_WORKINT_2}, //lua洢 + {"_3%", sizeof("_3%"), LUA_DATALINE0 + CHAR_LUASAVE_WORKINT_3}, //lua洢 + {"_洢1%", sizeof("_洢1%"), LUA_DATALINE0 + CHAR_LUASAVE_INT_1}, //洢浵 + {"_洢2%", sizeof("_洢2%"), LUA_DATALINE0 + CHAR_LUASAVE_INT_2}, //洢浵 + {"_洢3%", sizeof("_洢3%"), LUA_DATALINE0 + CHAR_LUASAVE_INT_3}, //洢浵 + // {"_IP%",sizeof("_IP%"),LUA_DATALINE1 + CHAR_CHARPLAYIP}, + + {"_Աȼ%", sizeof("_Աȼ%"), LUA_DATALINE0 + CHAR_VIPRIDE}, + {"_Աʱ%", sizeof("_Աʱ%"), LUA_DATALINE0 + CHAR_VIPTIME}, + +// {"_NPCʱ%", sizeof("_NPCʱ%"), LUA_DATALINE0 + CHAR_NPCTIME}, + + {"_ԭ%", sizeof("_ԭ%"), LUA_DATALINE1 + CHAR_NAME}, + {"_%", sizeof("_%"), LUA_DATALINE1 + CHAR_USERPETNAME}, + {"_ʺ%", sizeof("_ʺ%"), LUA_DATALINE1 + CHAR_CDKEY}, + {"_%", sizeof("_%"), LUA_DATALINE1 + CHAR_OWNERCDKEY}, + {"_%", sizeof("_%"), LUA_DATALINE1 + CHAR_OWNERCHARANAME}, + {"_%", sizeof("_%"), LUA_DATALINE1 + CHAR_FMNAME}, +#ifdef _TEACHER_SYSTEM + {"_ʦ%", sizeof("_ʦ%"), LUA_DATALINE1 + CHAR_TEACHER_ID}, + {"_ʦ%", sizeof("_ʦ%"), LUA_DATALINE1 + CHAR_TEACHER_NAME}, +#endif +#ifdef _MO_LUA_BETT01 + {"_ս1%", sizeof("_ս1%"), LUA_DATALINE2 + CHAR_WORKBATTLECOM1}, + {"_ս2%", sizeof("_ս2%"), LUA_DATALINE2 + CHAR_WORKBATTLECOM2}, + {"_սģ%", sizeof("_սģ%"), LUA_DATALINE2 + CHAR_WORKBATTLEMODE}, +#endif + {"_ģʽ%", sizeof("_ģʽ%"), LUA_DATALINE2 + CHAR_WORKPARTYMODE}, +#ifdef _ATTACK_EFFECT + {"_Ч%", sizeof("_Ч%"), LUA_DATALINE0 + CHAR_ATTACK_EFFECT}, +#endif + {"_%", sizeof("_%"), LUA_DATALINE2 + CHAR_WORKOBJINDEX}, +#ifdef _ADD_ACTION //npc + {"_%", sizeof("_%"), LUA_DATALINE2 + CHAR_WORKACTION}, +#endif +// {"_LUA%", sizeof("_LUA%"), LUA_DATALINE2 + CHAR_WORKLUANPCINT}, +// {"_1LUA%", sizeof("_1LUA%"), LUA_DATALINE2 + CHAR_WORKLUANPCINT1}, + +#ifdef _CHARSIGNDAY_ + {"_ǩ״̬%", sizeof("_ǩ״̬%"), LUA_DATALINE0 + CHAR_QIANDAOZT}, + {"_ǩ%", sizeof("_ǩ%"), LUA_DATALINE0 + CHAR_QIANDAOYUE}, + {"_ǩ%", sizeof("_ǩ%"), LUA_DATALINE0 + CHAR_QIANDAORI}, +#endif + {"_IAK%", sizeof("_IAK%"), LUA_DATALINE4 + CHAR_ISATTACK}, + {"_ս%", sizeof("_ս%"), LUA_DATALINE4 + CHAR_ISATTACKED}, + {"_IOR%", sizeof("_IOR%"), LUA_DATALINE4 + CHAR_ISOVER}, + {"_·%", sizeof("_·%"), LUA_DATALINE4 + CHAR_ISOVERED}, + {"_HHT%", sizeof("_HHT%"), LUA_DATALINE4 + CHAR_HAVEHEIGHT}, + {"_%", sizeof("_%"), LUA_DATALINE4 + CHAR_ISVISIBLE}, + {"_ITP%", sizeof("_ITP%"), LUA_DATALINE4 + CHAR_ISTRANSPARENT}, + {"_IFG%", sizeof("_IFG%"), LUA_DATALINE4 + CHAR_ISFLYING}, + {"_%", sizeof("_%"), LUA_DATALINE4 + CHAR_ISDIE}, + {"_IBIG%", sizeof("_IBIG%"), LUA_DATALINE4 + CHAR_ISBIG}, + {"_ս%", sizeof("_ս%"), LUA_DATALINE4 + CHAR_ISSHOWBATTLEMSG}, + {"_ӱ%", sizeof("_ӱ%"), LUA_DATALINE4 + CHAR_ISPARTY}, + {"_%", sizeof("_%"), LUA_DATALINE4 + CHAR_ISWARP}, + {"_ս%", sizeof("_ս%"), LUA_DATALINE4 + CHAR_ISDUEL}, + {"_ı%", sizeof("_ı%"), LUA_DATALINE4 + CHAR_ISPARTYCHAT}, + {"_Ƭ%", sizeof("_Ƭ%"), LUA_DATALINE4 + CHAR_ISTRADECARD}, + {"_ױ%", sizeof("_ױ%"), LUA_DATALINE4 + CHAR_ISTRADE}, +#ifdef _CHANNEL_MODIFY + {"_Ƶ%", sizeof("_Ƶ%"), LUA_DATALINE4 + CHAR_ISTELL}, + {"_Ƶ%", sizeof("_Ƶ%"), LUA_DATALINE4 + CHAR_ISFM}, + {"_ְƵ%", sizeof("_ְƵ%"), LUA_DATALINE4 + CHAR_ISOCC}, + {"_Ի%", sizeof("_Ի%"), LUA_DATALINE4 + CHAR_ISSAVE}, + {"_Ƶ%", sizeof("_Ƶ%"), LUA_DATALINE4 + CHAR_ISCHAT}, +#endif + + {"_ID%", sizeof("_ID%"), LUA_DATALINE0 + ITEM_ID}, + {"_ͼ%", sizeof("_ͼ%"), LUA_DATALINE0 + ITEM_BASEIMAGENUMBER}, + {"_ɱ%", sizeof("_ɱ%"), LUA_DATALINE0 + ITEM_COST}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_TYPE}, + {"_AUF%", sizeof("_AUF%"), LUA_DATALINE0 + ITEM_ABLEUSEFIELD}, + {"_TARGET%", sizeof("_TARGET%"), LUA_DATALINE0 + ITEM_TARGET}, + {"_ȼ%", sizeof("_ȼ%"), LUA_DATALINE0 + ITEM_LEVEL}, +#ifdef _ITEM_MAXUSERNUM + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_DAMAGEBREAK}, +#endif +#ifdef _ITEMSET4_TXT + {"_ѵ%", sizeof("_ѵ%"), LUA_DATALINE0 + ITEM_USEPILENUMS}, + {"_ɵ%", sizeof("_ɵ%"), LUA_DATALINE0 + ITEM_CANBEPILE}, + {"_STR%", sizeof("_STR%"), LUA_DATALINE0 + ITEM_NEEDSTR}, + {"_DEX%", sizeof("_DEX%"), LUA_DATALINE0 + ITEM_NEEDDEX}, + {"_ת%", sizeof("_ת%"), LUA_DATALINE0 + ITEM_NEEDTRANS}, + {"_ְҵ%", sizeof("_ְҵ%"), LUA_DATALINE0 + ITEM_NEEDPROFESSION}, +#endif +#ifdef _TAKE_ITEMDAMAGE + {"_;%", sizeof("_;%"), LUA_DATALINE0 + ITEM_DAMAGECRUSHE}, + {"_MAX;%", sizeof("_MAX;%"), LUA_DATALINE0 + ITEM_MAXDAMAGECRUSHE}, +#endif +#ifdef _ADD_DEAMGEDEFC + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_OTHERDAMAGE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_OTHERDEFC}, +#endif +#ifdef _SUIT_ITEM + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_SUITCODE}, +#endif + {"_AKMIN%", sizeof("_AKMIN%"), LUA_DATALINE0 + ITEM_ATTACKNUM_MIN}, + {"_AKMAX%", sizeof("_AKMAX%"), LUA_DATALINE0 + ITEM_ATTACKNUM_MAX}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYATTACK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYDEFENCE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYQUICK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYHP}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYMP}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYLUCK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYCHARM}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYAVOID}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYATTRIB}, + {"_ֵ%", sizeof("_ֵ%"), LUA_DATALINE0 + ITEM_MODIFYATTRIBVALUE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MAGICID}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MAGICPROB}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MAGICUSEMP}, +#ifdef _ITEMSET5_TXT + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYARRANGE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MODIFYSEQUENCE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_ATTACHPILE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_HITRIGHT}, +#endif +#ifdef _ITEMSET6_TXT + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_NEGLECTGUARD}, +#endif + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_POISON}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_PARALYSIS}, + {"_˯%", sizeof("_˯%"), LUA_DATALINE0 + ITEM_SLEEP}, + {"_ʯ%", sizeof("_ʯ%"), LUA_DATALINE0 + ITEM_STONE}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_DRUNK}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_CONFUSION}, + {"_һ%", sizeof("_һ%"), LUA_DATALINE0 + ITEM_CRITICAL}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_USEACTION}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_DROPATLOGOUT}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_VANISHATDROP}, + {"_·%", sizeof("_·%"), LUA_DATALINE0 + ITEM_ISOVERED}, + {"_ʼ%", sizeof("_ʼ%"), LUA_DATALINE0 + ITEM_CANPETMAIL}, + {"_Ӻϳ%", sizeof("_Ӻϳ%"), LUA_DATALINE0 + ITEM_CANMERGEFROM}, + {"_ϳɵ%", sizeof("_ϳɵ%"), LUA_DATALINE0 + ITEM_CANMERGETO}, + {"_0%", sizeof("_0%"), LUA_DATALINE0 + ITEM_INGVALUE0}, + {"_1%", sizeof("_1%"), LUA_DATALINE0 + ITEM_INGVALUE1}, + {"_2%", sizeof("_2%"), LUA_DATALINE0 + ITEM_INGVALUE2}, + {"_3%", sizeof("_3%"), LUA_DATALINE0 + ITEM_INGVALUE3}, + {"_4%", sizeof("_4%"), LUA_DATALINE0 + ITEM_INGVALUE4}, + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + ITEM_PUTTIME}, + {"_LL%", sizeof("_LL%"), LUA_DATALINE0 + ITEM_LEAKLEVEL}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_MERGEFLG}, + {"_%", sizeof("_%"), LUA_DATALINE0 + ITEM_CRUSHLEVEL}, +// {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE0 + ITEM_TIME}, + {"_VAR1%", sizeof("_VAR1%"), LUA_DATALINE0 + ITEM_VAR1}, + {"_VAR2%", sizeof("_VAR2%"), LUA_DATALINE0 + ITEM_VAR2}, + {"_VAR3%", sizeof("_VAR3%"), LUA_DATALINE0 + ITEM_VAR3}, + {"_VAR4%", sizeof("_VAR4%"), LUA_DATALINE0 + ITEM_VAR4}, + + {"_%", sizeof("_%"), LUA_DATALINE2 + ITEM_WORKOBJINDEX}, + {"_%", sizeof("_%"), LUA_DATALINE2 + ITEM_WORKCHARAINDEX}, +#ifdef _ITEM_TIME_LIMIT + {"_ʱ%", sizeof("_ʱ%"), LUA_DATALINE2 + ITEM_WORKTIMELIMIT}, +#endif + + {"_ԭ%", sizeof("_ԭ%"), LUA_DATALINE1 + ITEM_NAME}, + {"_%", sizeof("_%"), LUA_DATALINE1 + ITEM_SECRETNAME}, + {"_˵%", sizeof("_˵%"), LUA_DATALINE1 + ITEM_EFFECTSTRING}, + {"_%", sizeof("_%"), LUA_DATALINE1 + ITEM_ARGUMENT}, + {"_%", sizeof("_%"), LUA_DATALINE1 + ITEM_CDKEY}, + {"_%", sizeof("_%"), LUA_DATALINE1 + ITEM_FORUSERCDKEY}, + {"_0%", sizeof("_0%"), LUA_DATALINE1 + ITEM_INGNAME0}, + {"_1%", sizeof("_1%"), LUA_DATALINE1 + ITEM_INGNAME1}, + {"_2%", sizeof("_2%"), LUA_DATALINE1 + ITEM_INGNAME2}, + {"_3%", sizeof("_3%"), LUA_DATALINE1 + ITEM_INGNAME3}, + {"_4%", sizeof("_4%"), LUA_DATALINE1 + ITEM_INGNAME4}, + + {"_ͷλ%", sizeof("_ͷλ%"), CHAR_HEAD}, + {"_λ%", sizeof("_λ%"), CHAR_BODY}, + {"_%", sizeof("_%"), CHAR_ARM}, + {"_1%", sizeof("_1%"), CHAR_DECORATION1}, + {"_2%", sizeof("_2%"), CHAR_DECORATION2}, +#ifdef _ITEM_EQUITSPACE + {"_%", sizeof("_%"), CHAR_EQSHIELD}, + {"_λ%", sizeof("_λ%"), CHAR_EQBELT}, + {"_λ%", sizeof("_λ%"), CHAR_EQSHOES}, +#endif +#ifdef _EQUIT_NEWGLOVE + {"_%", sizeof("_%"), CHAR_EQGLOVE}, +#endif + {"_1%", sizeof("_1%"), CHAR_STARTITEMARRAY + 0}, + {"_2%", sizeof("_2%"), CHAR_STARTITEMARRAY + 1}, + {"_3%", sizeof("_3%"), CHAR_STARTITEMARRAY + 2}, + {"_4%", sizeof("_4%"), CHAR_STARTITEMARRAY + 3}, + {"_5%", sizeof("_5%"), CHAR_STARTITEMARRAY + 4}, + {"_6%", sizeof("_6%"), CHAR_STARTITEMARRAY + 5}, + {"_7%", sizeof("_7%"), CHAR_STARTITEMARRAY + 6}, + {"_8%", sizeof("_8%"), CHAR_STARTITEMARRAY + 7}, + {"_9%", sizeof("_9%"), CHAR_STARTITEMARRAY + 8}, + {"_10%", sizeof("_10%"), CHAR_STARTITEMARRAY + 9}, + {"_11%", sizeof("_11%"), CHAR_STARTITEMARRAY + 10}, + {"_12%", sizeof("_12%"), CHAR_STARTITEMARRAY + 11}, + {"_13%", sizeof("_13%"), CHAR_STARTITEMARRAY + 12}, + {"_14%", sizeof("_14%"), CHAR_STARTITEMARRAY + 13}, + {"_15%", sizeof("_15%"), CHAR_STARTITEMARRAY + 14}, + + {"_1%", sizeof("_1%"), 0}, + {"_2%", sizeof("_2%"), 1}, + {"_3%", sizeof("_3%"), 2}, + {"_4%", sizeof("_4%"), 3}, + {"_5%", sizeof("_5%"), 4}, + + {"Ա_1%", sizeof("Ա_1%"), 1}, + {"Ա_2%", sizeof("Ա_2%"), 2}, + {"Ա_3%", sizeof("Ա_3%"), 3}, + {"Ա_4%", sizeof("Ա_4%"), 4}, + + {"IT_צ%", sizeof("IT_צ%"), ITEM_FIST}, + {"IT_ͷ%", sizeof("IT_ͷ%"), ITEM_AXE}, + {"IT_%", sizeof("IT_%"), ITEM_CLUB}, + {"IT_ǹ%", sizeof("IT_ǹ%"), ITEM_SPEAR}, + {"IT_%", sizeof("IT_%"), ITEM_BOW}, + {"IT_SHIELD%", sizeof("IT_SHIELD%"), ITEM_SHIELD}, + {"IT_HELM%", sizeof("IT_HELM%"), ITEM_HELM}, + {"IT_ARMOUR%", sizeof("IT_ARMOUR%"), ITEM_ARMOUR}, + {"IT_ֻ%", sizeof("IT_ֻ%"), ITEM_BRACELET}, + {"IT_%", sizeof("IT_%"), ITEM_MUSIC}, + {"IT_%", sizeof("IT_%"), ITEM_NECKLACE}, + {"IT_%", sizeof("IT_%"), ITEM_RING}, + {"IT_BELT%", sizeof("IT_BELT%"), ITEM_BELT}, + {"IT_%", sizeof("IT_%"), ITEM_EARRING}, + {"IT_ǻ%", sizeof("IT_ǻ%"), ITEM_NOSERING}, + {"IT_%", sizeof("IT_%"), ITEM_AMULET}, + {"IT_%", sizeof("IT_%"), ITEM_OTHER}, + {"IT_%", sizeof("IT_%"), ITEM_BOOMERANG}, + {"IT_Ͷ%", sizeof("IT_Ͷ%"), ITEM_BOUNDTHROW}, + {"IT_Ͷʯ%", sizeof("IT_Ͷʯ%"), ITEM_BREAKTHROW}, + {"IT_DISH%", sizeof("IT_DISH%"), ITEM_DISH}, +#ifdef _ITEM_INSLAY + {"IT_%", sizeof("IT_%"), ITEM_METAL}, + {"IT_%", sizeof("IT_%"), ITEM_JEWEL}, +#endif +#ifdef _ITEM_CHECKWARES + {"IT_%", sizeof("IT_%"), ITEM_WARES}, +#endif +#ifdef _ITEM_EQUITSPACE + {"IT_%", sizeof("IT_%"), ITEM_WBELT}, + {"IT_%", sizeof("IT_%"), ITEM_WSHIELD}, + {"IT_Ь%", sizeof("IT_Ь%"), ITEM_WSHOES}, +#endif +#ifdef _EQUIT_NEWGLOVE + {"IT_%", sizeof("IT_%"), ITEM_WGLOVE}, +#endif +#ifdef _JZ_PETEQU + {"IT_ͷ%", sizeof("IT_ͷ%"), ITEM_PET_HEAD}, + {"IT_%", sizeof("IT_%"), ITEM_PET_WING}, + {"IT_%", sizeof("IT_%"), ITEM_PET_TOOTH}, + {"IT_ؼ%", sizeof("IT_ؼ%"), ITEM_PET_BREAST}, + {"IT_豳%", sizeof("IT_豳%"), ITEM_PET_BACK}, + {"IT_צ%", sizeof("IT_צ%"), ITEM_PET_CLAW}, + {"IT_軤2%", sizeof("IT_軤2%"), ITEM_PET_FEET}, + {"IT_軤4%", sizeof("IT_軤4%"), ITEM_PET_FEET4}, + {"IT_%", sizeof("IT_%"), ITEM_PET_FIN}, +#endif + + {"_û%", sizeof("_û%"), FMMEMBER_NONE}, + {"_һ%", sizeof("_һ%"), FMMEMBER_MEMBER}, + {"_%", sizeof("_%"), FMMEMBER_APPLY}, + {"_峤%", sizeof("_峤%"), FMMEMBER_LEADER}, + {"_%", sizeof("_%"), FMMEMBER_ELDER}, + //{"_˾", sizeof("_˾"), FMMEMBER_INVITE}, + //{"_", sizeof("_"), FMMEMBER_BAILEE}, + //{"_", sizeof("_"), FMMEMBER_VICELEADER}, + + {"ս_%", sizeof("ս_%"), BATTLE_TYPE_NONE}, + {"ս_˹%", sizeof("ս_˹%"), BATTLE_TYPE_P_vs_E}, + {"ս_%", sizeof("ս_%"), BATTLE_TYPE_P_vs_P}, + {"ս_ֹ%", sizeof("ս_ֹ%"), BATTLE_TYPE_E_vs_E}, + {"ս_%", sizeof("ս_%"), BATTLE_TYPE_WATCH}, + {"ս_DP%", sizeof("ս_DP%"), BATTLE_TYPE_DP_BATTLE}, + {"ս_BOSS%", sizeof("ս_BOSS%"), BATTLE_TYPE_BOSS_BATTLE}, + + {"ս_%", sizeof("ս_%"), BATTLE_MODE_NONE}, + {"ս_%", sizeof("ս_%"), BATTLE_MODE_INIT}, + {"ս_%", sizeof("ս_%"), BATTLE_MODE_BATTLE}, + {"ս_%", sizeof("ս_%"), BATTLE_MODE_FINISH}, + {"ս_%", sizeof("ս_%"), BATTLE_MODE_STOP}, + {"ս_۳%", sizeof("ս_۳%"), BATTLE_MODE_WATCHBC}, + {"ս_1%", sizeof("ս_1%"), BATTLE_MODE_WATCHPRE}, + {"ս_2%", sizeof("ս_2%"), BATTLE_MODE_WATCHWAIT}, + {"ս_3%", sizeof("ս_3%"), BATTLE_MODE_WATCHMOVIE}, + {"ս_4%", sizeof("ս_4%"), BATTLE_MODE_WATCHAFTER}, + + {"Ů%", sizeof("Ů%"), CHAR_IMAGETYPE_GIRL}, + {"к%", sizeof("к%"), CHAR_IMAGETYPE_BOY}, + {"ͯ%", sizeof("ͯ%"), CHAR_IMAGETYPE_CHILDBOY}, + {"Ůͯ%", sizeof("Ůͯ%"), CHAR_IMAGETYPE_CHILDGIRL}, + {"%", sizeof("%"), CHAR_IMAGETYPE_MAN}, + {"Ů%", sizeof("Ů%"), CHAR_IMAGETYPE_WOMAN}, + {"%", sizeof("%"), CHAR_IMAGETYPE_OLDMAN}, + {"%", sizeof("%"), CHAR_IMAGETYPE_DOG}, + + {"_%", sizeof("_%"), CHAR_TYPEPLAYER}, + {"_%", sizeof("_%"), CHAR_TYPEENEMY}, + {"_%", sizeof("_%"), CHAR_TYPEPET}, + {"_NPC1%", sizeof("_NPC1%"), CHAR_TYPEDOOR}, + {"_NPC2%", sizeof("_NPC2%"), CHAR_TYPEBOX}, + {"_NPC3%", sizeof("_NPC3%"), CHAR_TYPEMSG}, + {"_NPC4%", sizeof("_NPC4%"), CHAR_TYPEWARP}, + {"_NPC5%", sizeof("_NPC5%"), CHAR_TYPESHOP}, + {"_NPC6%", sizeof("_NPC6%"), CHAR_TYPEHEALER}, + {"_NPC7%", sizeof("_NPC7%"), CHAR_TYPEOLDMAN}, + {"_NPC8%", sizeof("_NPC8%"), CHAR_TYPEROOMADMIN}, + {"_NPC9%", sizeof("_NPC9%"), CHAR_TYPETOWNPEOPLE}, + {"_NPC10%", sizeof("_NPC10%"), CHAR_TYPEDENGON}, + {"_NPC11%", sizeof("_NPC11%"), CHAR_TYPEADM}, + {"_NPC12%", sizeof("_NPC12%"), CHAR_TYPETEMPLE}, + {"_NPC13%", sizeof("_NPC13%"), CHAR_TYPESTORYTELLER}, + {"_NPC14%", sizeof("_NPC14%"), CHAR_TYPERANKING}, + {"_NPC15%", sizeof("_NPC15%"), CHAR_TYPEOTHERNPC}, + {"_NPC16%", sizeof("_NPC16%"), CHAR_TYPEPRINTPASSMAN}, + {"_NPC17%", sizeof("_NPC17%"), CHAR_TYPENPCENEMY}, + {"_NPC18%", sizeof("_NPC18%"), CHAR_TYPEACTION}, + {"_NPC19%", sizeof("_NPC19%"), CHAR_TYPEWINDOWMAN}, + {"_NPC20%", sizeof("_NPC20%"), CHAR_TYPESAVEPOINT}, + {"_NPC21%", sizeof("_NPC21%"), CHAR_TYPEWINDOWHEALER}, + {"_NPC22%", sizeof("_NPC22%"), CHAR_TYPEITEMSHOP}, + {"_NPC23%", sizeof("_NPC23%"), CHAR_TYPESTONESHOP}, + {"_NPC24%", sizeof("_NPC24%"), CHAR_TYPEDUELRANKING}, + {"_NPC25%", sizeof("_NPC25%"), CHAR_TYPEWARPMAN}, + {"_NPC26%", sizeof("_NPC26%"), CHAR_TYPEEVENT}, + {"_NPC27%", sizeof("_NPC27%"), CHAR_TYPEMIC}, + {"_NPC28%", sizeof("_NPC28%"), CHAR_TYPELUCKYMAN}, + {"_NPC29%", sizeof("_NPC29%"), CHAR_TYPEBUS}, + {"_NPC30%", sizeof("_NPC30%"), CHAR_TYPECHARM}, + {"_NPC31%", sizeof("_NPC31%"), CHAR_TYPECHECKMAN}, + {"_NPC32%", sizeof("_NPC32%"), CHAR_TYPEJANKEN}, + {"_NPC33%", sizeof("_NPC33%"), CHAR_TYPETRANSMIGRATION}, + {"_NPC34%", sizeof("_NPC34%"), CHAR_TYPEFMWARPMAN}, + {"_NPC35%", sizeof("_NPC35%"), CHAR_TYPEFMSCHEDULEMAN}, + {"_NPC36%", sizeof("_NPC36%"), CHAR_TYPEMANORSCHEDULEMAN}, +#ifdef _SERVICE + {"_NPC37%", sizeof("_NPC37%"), CHAR_TYPESTONESERVICEMAN}, +#endif +#ifdef _GAMBLE_BANK + {"_NPC38%", sizeof("_NPC38%"), CHAR_GAMBLEBANK}, +#endif +#ifdef _NEW_WARPMAN + {"_NPC39%", sizeof("_NPC39%"), CHAR_NEWNPCMAN}, +#endif +#ifdef _MARKET_TRADE + {"_NPC40%", sizeof("_NPC40%"), CHAR_MAPTRADEMAN}, +#endif +#ifdef _GAMBLE_ROULETTE + {"_NPC41%", sizeof("_NPC41%"), CHAR_GAMBLEROULETTE}, + {"_NPC42%", sizeof("_NPC42%"), CHAR_GAMBLEMASTER}, +#endif +#ifdef _TRANSER_MAN + {"_NPC43%", sizeof("_NPC43%"), CHAR_TRANSERMANS}, +#endif +#ifdef _JZ_NEW_ADDMEMBERPOINT + {"_NPC44%", sizeof("_NPC44%"), CHAR_MEMBERMANS}, +#endif +#ifdef _NPC_SELLSTH + {"_NPC45%", sizeof("_NPC45%"), CHAR_SELLSTHMAN}, +#endif +#ifdef _NPC_MAKEPAIR + {"_NPC46%", sizeof("_NPC46%"), CHAR_MAKEPAIR}, +#endif +#ifdef _NPC_FUSION + {"_NPC47%", sizeof("_NPC47%"), CHAR_PETFUSIONMAN}, +#endif +#ifdef _PAUCTION_MAN +// {"_NPC48%", sizeof("_NPC48%"), CHAR_PAUCTIONMAN}, +#endif +#ifdef _ITEM_NPCCHANGE + {"_NPC49%", sizeof("_NPC49%"), CHAR_ITEMCHANGENPC}, +#endif +#ifdef _CFREE_petskill + {"_NPC50%", sizeof("_NPC50%"), CHAR_FREESKILLSHOP}, +#endif +#ifdef _PETRACE + {"_NPC51%", sizeof("_NPC51%"), CHAR_PETRACEMASTER}, + {"_NPC52%", sizeof("_NPC52%"), CHAR_PETRACEPET}, +#endif +#ifdef _AUCTIONEER + {"_NPC53%", sizeof("_NPC53%"), CHAR_TYPEAUCTIONEER}, +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + {"_NPC54%", sizeof("_NPC54%"), CHAR_TYPEALLDOMAN}, +#endif + {"_NPC55%", sizeof("_NPC55%"), CHAR_TYPEPETMAKER}, +#ifdef _NPC_WELFARE + {"_NPC56%", sizeof("_NPC56%"), CHAR_TYPEWELFARE}, +#endif +#ifdef _NPC_VERYWELFARE + {"_NPC57%", sizeof("_NPC57%"), CHAR_TYPEVERYWELFARE}, +#endif +#ifdef _NPC_WELFARE_2 // WON ADD ְҵNPC-2 + {"_NPC58%", sizeof("_NPC58%"), CHAR_TYPEWELFARE2}, +#endif +#ifdef _RACEMAN + {"_NPC59%", sizeof("_NPC59%"), CHAR_RACEMAN}, +#endif + + {"_û%", sizeof("_û%"), OBJTYPE_NOUSE}, + {"_%", sizeof("_%"), OBJTYPE_CHARA}, + {"_%", sizeof("_%"), OBJTYPE_ITEM}, + {"_%", sizeof("_%"), OBJTYPE_GOLD}, +#ifdef _NPCSERVER_NEW + {"_NPC%", sizeof("_NPC%"), OBJTYPE_NPCSCHARA}, +#endif +#ifdef _MAP_WARPPOINT + {"_%", sizeof("_%"), OBJTYPE_WARPPOINT}, +#endif + + {"ť_û%", sizeof("ť_û%"), WINDOW_BUTTONTYPE_NONE}, + {"ť_ȷ%", sizeof("ť_ȷ%"), WINDOW_BUTTONTYPE_OK}, + {"ť_ر%", sizeof("ť_ر%"), WINDOW_BUTTONTYPE_CANCEL}, + {"ť_%", sizeof("ť_%"), WINDOW_BUTTONTYPE_YES}, + {"ť_%", sizeof("ť_%"), WINDOW_BUTTONTYPE_NO}, + {"ť_һҳ%", sizeof("ť_һҳ%"), WINDOW_BUTTONTYPE_PREV}, + {"ť_һҳ%", sizeof("ť_һҳ%"), WINDOW_BUTTONTYPE_NEXT}, + + {"_û%", sizeof("_û%"), CHAR_PARTY_NONE}, + {"_ӳ%", sizeof("_ӳ%"), CHAR_PARTY_LEADER}, + {"_Ա%", sizeof("_Ա%"), CHAR_PARTY_CLIENT}, + + {"%", sizeof("%"), 0}, + {"%", sizeof("%"), 1}, + {"%", sizeof("%"), 2}, + {"%", sizeof("%"), 3}, + {"%", sizeof("%"), 4}, + {"%", sizeof("%"), 5}, + {"%", sizeof("%"), 6}, + {"%", sizeof("%"), 7}, + + {"ɫ%", sizeof("ɫ%"), CHAR_COLORWHITE}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORCYAN}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORPURPLE}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORBLUE}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORYELLOW}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORGREEN}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORRED}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORGRAY}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORBLUE2}, + {"ɫ%", sizeof("ɫ%"), CHAR_COLORGREEN2}, +// {"ɫ%", sizeof("ɫ%"), CHAR_COLORBLACK}, + + {"Ӹ_OBJ%", sizeof("Ӹ_OBJ%"), CHAR_N_STRING_OBJINDEX}, + {"Ӹ_LV%", sizeof("Ӹ_LV%"), CHAR_N_STRING_LV}, + {"Ӹ_MAXHP%", sizeof("Ӹ_MAXHP%"), CHAR_N_STRING_MAXHP}, + {"Ӹ_HP%", sizeof("Ӹ_HP%"), CHAR_N_STRING_HP}, + {"Ӹ_MP%", sizeof("Ӹ_MP%"), CHAR_N_STRING_MP}, + {"Ӹ_%", sizeof("Ӹ_%"), CHAR_N_STRING_NAME}, + + {"3_HP%", sizeof("3_HP%"), CHAR_P_STRING_HP}, + {"3_MAXHP%", sizeof("3_MAXHP%"), CHAR_P_STRING_MAXHP}, + {"3_MP%", sizeof("3_MP%"), CHAR_P_STRING_MP}, + {"3_MAXMP%", sizeof("3_MAXMP%"), CHAR_P_STRING_MAXMP}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_VITAL}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_STR}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_TOUGH}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_DEX}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_EXP}, + {"3_һ%", sizeof("3_һ%"), CHAR_P_STRING_NEXTEXP}, + {"3_ȼ%", sizeof("3_ȼ%"), CHAR_P_STRING_LV}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_ATK}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_DEF}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_QUICK}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_CHARM}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_LUCK}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_EARTH}, + {"3_ˮ%", sizeof("3_ˮ%"), CHAR_P_STRING_WATER}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_FIRE}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_WIND}, + {"3_ʯ%", sizeof("3_ʯ%"), CHAR_P_STRING_GOLD}, + {"3_ƺ%", sizeof("3_ƺ%"), CHAR_P_STRING_TITLE}, + {"3_DP%", sizeof("3_DP%"), CHAR_P_STRING_DUELPOINT}, + {"3_ת%", sizeof("3_ת%"), CHAR_P_STRING_TRANSMIGRATION}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_NAME}, + {"3_dz%", sizeof("3_dz%"), CHAR_P_STRING_OWNTITLE}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_RIDEPET}, + {"3_ѧȼ%", sizeof("3_ѧȼ%"), CHAR_P_STRING_LEARNRIDE}, + {"3_%", sizeof("3_%"), CHAR_P_STRING_BASEBASEIMAGENUMBER}, + {"3_ģʽ%", sizeof("3_ģʽ%"), CHAR_P_STRING_SKYWALKER}, + {"3_ģʽ%", sizeof("3_ģʽ%"), CHAR_P_STRING_DEBUGMODE}, + {"_%", sizeof("_%"), LUA_DATALINE1 + MAGIC_NAME}, + {"_%", sizeof("_%"), LUA_DATALINE1 + MAGIC_COMMENT}, + {"_%", sizeof("_%"), LUA_DATALINE1 + MAGIC_FUNCNAME}, + {"_ѡ%", sizeof("_ѡ%"), LUA_DATALINE1 + MAGIC_OPTION}, + {"_ID%", sizeof("_ID%"), LUA_DATALINE0 + MAGIC_ID}, + {"_FIELD%", sizeof("_FIELD%"), LUA_DATALINE0 + MAGIC_FIELD}, + {"_Ŀ%", sizeof("_Ŀ%"), LUA_DATALINE0 + MAGIC_TARGET}, + {"_Ŀ%", sizeof("_Ŀ%"), LUA_DATALINE0 + MAGIC_TARGET_DEADFLG}, + {"_IDX%", sizeof("_IDX%"), LUA_DATALINE0 + MAGIC_IDX}, + {NULL, 0, 0}, +}; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.c b/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.c new file mode 100644 index 0000000..e52f46e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.c @@ -0,0 +1,1596 @@ +/* + * ecb_crypt, cbc_crypt, des_setparity - DES encryption/decryption routine + * + * Written by Koichiro Mori (kmori@lsi-j.co.jp) + */ +#include +#include "descrypt.h" + +#define YES 1 +#define NO 0 +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; + + + + +void des_setparity(char *key) +{ + int n; + + for (n = 8; n > 0; n--) { + char c; + + c = *key &= 0x7f; + c ^= c << 4; + c ^= c << 2; + c ^= c << 1; + *key++ ^= ~c & 0x80; + } +} + + +ulong Keys[16][2]; + +void des_setkey(char *key) +{ + static char nshifts[] + = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; +#define C 28 +#define D 0 + static uchar pc1[] = { + C + 20, C + 12, C + 4, D + 0, D + 4, D + 12, D + 20, + C + 21, C + 13, C + 5, D + 1, D + 5, D + 13, D + 21, + C + 22, C + 14, C + 6, D + 2, D + 6, D + 14, D + 22, + C + 23, C + 15, C + 7, D + 3, D + 7, D + 15, D + 23, + C + 24, C + 16, C + 8, C + 0, D + 8, D + 16, D + 24, + C + 25, C + 17, C + 9, C + 1, D + 9, D + 17, D + 25, + C + 26, C + 18, C +10, C + 2, D +10, D + 18, D + 26, + C + 27, C + 19, C +11, C + 3, D +11, D + 19, D + 27 + }; + static uchar pc2_c[] = { + 14, 11, 17, 4, 27, 23, + 25, 0, 13, 22, 7, 18, + 5, 9, 16, 24, 2, 20, + 12, 21, 1, 8, 15, 26 + }; + static uchar pc2_d[] = { + 15, 4, 25, 19, 9, 1, + 26, 16, 5, 11, 23, 8, + 12, 7, 17, 0, 22, 3, + 10, 14, 6, 20, 27, 24, + }; + ulong c, d; + uchar b, *p; + int i, j; + + /* PC-1 (Permuted Choice 1) */ + c = d = 0; + p = pc1; + for (i = 0; i < 8; i++) { + b = *key++; + for (j = 0; j < 7; j++) { + if (b & 0x80) { + if (*p >= C) + c |= 1L << (*p - C); + else + d |= 1L << *p; + } + p++; + b <<= 1; + } + } + + for (i = 0; i < 16; i++) { + uchar *k, mask, w[8]; + uint n = nshifts[i]; + + c = (c << n | c >> (28 - n)) & 0x0fffffff; + d = (d << n | d >> (28 - n)) & 0x0fffffff; + /* PC-2 (Permuted Choice 2) */ + k = w; + p = pc2_c; + for (j = 0; j < 4; j++) { + *k = 0; + for (mask = 0x20; mask > 0; mask >>= 1) { + if ((c >> *p++) & 1) + *k |= mask; + } + k++; + } + p = pc2_d; + for (j = 0; j < 4; j++) { + *k = 0; + for (mask = 0x20; mask > 0; mask >>= 1) { + if ((d >> *p++) & 1) + *k |= mask; + } + k++; + } + + Keys[i][0] = ((ulong)w[0] << 24) | ((ulong)w[2] << 16) + | ((ulong)w[4] << 8) | (ulong)w[6]; + Keys[i][1] = ((ulong)w[1] << 24) | ((ulong)w[3] << 16) + | ((ulong)w[5] << 8) | (ulong)w[7]; + + } +} + + + + + +#if MSC +#define ror4(x) _lrotr(x, 4) +#define rol1(x) _lrotl(x, 1) + +#else +#define ror4(x) ((x) >> 4 | (x) << 28) +#define rol1(x) ((x) << 1 | (x) >> 31) + +#endif + + +#if SMALL +uchar Sboxes[8][64] = { + { + 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, + 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, + 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, + 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, + }, + { + 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, + 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, + 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, + 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, + }, + { + 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, + 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, + 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, + 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, + }, + { + 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, + 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, + 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, + 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, + }, + { + 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, + 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, + 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, + 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, + }, + { + 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, + 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, + 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, + 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, + }, + { + 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, + 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, + 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, + 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, + }, + { + 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, + 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, + 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, + 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11, + }, +}; + +ulong Ptbl[8][16] = { + { + 0x00000000, 0x00000002, 0x00000200, 0x00000202, + 0x00008000, 0x00008002, 0x00008200, 0x00008202, + 0x00800000, 0x00800002, 0x00800200, 0x00800202, + 0x00808000, 0x00808002, 0x00808200, 0x00808202, + }, + { + 0x00000000, 0x00004000, 0x40000000, 0x40004000, + 0x00000010, 0x00004010, 0x40000010, 0x40004010, + 0x00080000, 0x00084000, 0x40080000, 0x40084000, + 0x00080010, 0x00084010, 0x40080010, 0x40084010, + }, + { + 0x00000000, 0x04000000, 0x00000004, 0x04000004, + 0x00010000, 0x04010000, 0x00010004, 0x04010004, + 0x00000100, 0x04000100, 0x00000104, 0x04000104, + 0x00010100, 0x04010100, 0x00010104, 0x04010104, + }, + { + 0x00000000, 0x80000000, 0x00400000, 0x80400000, + 0x00001000, 0x80001000, 0x00401000, 0x80401000, + 0x00000040, 0x80000040, 0x00400040, 0x80400040, + 0x00001040, 0x80001040, 0x00401040, 0x80401040, + }, + { + 0x00000000, 0x20000000, 0x00000080, 0x20000080, + 0x00040000, 0x20040000, 0x00040080, 0x20040080, + 0x01000000, 0x21000000, 0x01000080, 0x21000080, + 0x01040000, 0x21040000, 0x01040080, 0x21040080, + }, + { + 0x00000000, 0x00002000, 0x00200000, 0x00202000, + 0x00000008, 0x00002008, 0x00200008, 0x00202008, + 0x10000000, 0x10002000, 0x10200000, 0x10202000, + 0x10000008, 0x10002008, 0x10200008, 0x10202008, + }, + { + 0x00000000, 0x02000000, 0x00000400, 0x02000400, + 0x00100000, 0x02100000, 0x00100400, 0x02100400, + 0x00000001, 0x02000001, 0x00000401, 0x02000401, + 0x00100001, 0x02100001, 0x00100401, 0x02100401, + }, + { + 0x00000000, 0x00000800, 0x00020000, 0x00020800, + 0x00000020, 0x00000820, 0x00020020, 0x00020820, + 0x08000000, 0x08000800, 0x08020000, 0x08020800, + 0x08000020, 0x08000820, 0x08020020, 0x08020820, + }, +}; + +#define ps(i, j) Ptbl[i][Sboxes[i][j]] + +#else /* MIDDLE */ + +ulong Psboxes[8][64] = { + { + 0x00808200, 0x00000000, 0x00008000, 0x00808202, + 0x00808002, 0x00008202, 0x00000002, 0x00008000, + 0x00000200, 0x00808200, 0x00808202, 0x00000200, + 0x00800202, 0x00808002, 0x00800000, 0x00000002, + 0x00000202, 0x00800200, 0x00800200, 0x00008200, + 0x00008200, 0x00808000, 0x00808000, 0x00800202, + 0x00008002, 0x00800002, 0x00800002, 0x00008002, + 0x00000000, 0x00000202, 0x00008202, 0x00800000, + 0x00008000, 0x00808202, 0x00000002, 0x00808000, + 0x00808200, 0x00800000, 0x00800000, 0x00000200, + 0x00808002, 0x00008000, 0x00008200, 0x00800002, + 0x00000200, 0x00000002, 0x00800202, 0x00008202, + 0x00808202, 0x00008002, 0x00808000, 0x00800202, + 0x00800002, 0x00000202, 0x00008202, 0x00808200, + 0x00000202, 0x00800200, 0x00800200, 0x00000000, + 0x00008002, 0x00008200, 0x00000000, 0x00808002, + }, + { + 0x40084010, 0x40004000, 0x00004000, 0x00084010, + 0x00080000, 0x00000010, 0x40080010, 0x40004010, + 0x40000010, 0x40084010, 0x40084000, 0x40000000, + 0x40004000, 0x00080000, 0x00000010, 0x40080010, + 0x00084000, 0x00080010, 0x40004010, 0x00000000, + 0x40000000, 0x00004000, 0x00084010, 0x40080000, + 0x00080010, 0x40000010, 0x00000000, 0x00084000, + 0x00004010, 0x40084000, 0x40080000, 0x00004010, + 0x00000000, 0x00084010, 0x40080010, 0x00080000, + 0x40004010, 0x40080000, 0x40084000, 0x00004000, + 0x40080000, 0x40004000, 0x00000010, 0x40084010, + 0x00084010, 0x00000010, 0x00004000, 0x40000000, + 0x00004010, 0x40084000, 0x00080000, 0x40000010, + 0x00080010, 0x40004010, 0x40000010, 0x00080010, + 0x00084000, 0x00000000, 0x40004000, 0x00004010, + 0x40000000, 0x40080010, 0x40084010, 0x00084000, + }, + { + 0x00000104, 0x04010100, 0x00000000, 0x04010004, + 0x04000100, 0x00000000, 0x00010104, 0x04000100, + 0x00010004, 0x04000004, 0x04000004, 0x00010000, + 0x04010104, 0x00010004, 0x04010000, 0x00000104, + 0x04000000, 0x00000004, 0x04010100, 0x00000100, + 0x00010100, 0x04010000, 0x04010004, 0x00010104, + 0x04000104, 0x00010100, 0x00010000, 0x04000104, + 0x00000004, 0x04010104, 0x00000100, 0x04000000, + 0x04010100, 0x04000000, 0x00010004, 0x00000104, + 0x00010000, 0x04010100, 0x04000100, 0x00000000, + 0x00000100, 0x00010004, 0x04010104, 0x04000100, + 0x04000004, 0x00000100, 0x00000000, 0x04010004, + 0x04000104, 0x00010000, 0x04000000, 0x04010104, + 0x00000004, 0x00010104, 0x00010100, 0x04000004, + 0x04010000, 0x04000104, 0x00000104, 0x04010000, + 0x00010104, 0x00000004, 0x04010004, 0x00010100, + }, + { + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x00401040, 0x80400040, 0x80400000, 0x80001000, + 0x00000000, 0x00401000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00400040, 0x80400000, + 0x80000000, 0x00001000, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x80001000, 0x00001040, + 0x80400040, 0x80000000, 0x00001040, 0x00400040, + 0x00001000, 0x00401040, 0x80401040, 0x80000040, + 0x00400040, 0x80400000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00000000, 0x00401000, + 0x00001040, 0x00400040, 0x80400040, 0x80000000, + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x80401040, 0x80000040, 0x80000000, 0x00001000, + 0x80400000, 0x80001000, 0x00401040, 0x80400040, + 0x80001000, 0x00001040, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x00001000, 0x00401040, + }, + { + 0x00000080, 0x01040080, 0x01040000, 0x21000080, + 0x00040000, 0x00000080, 0x20000000, 0x01040000, + 0x20040080, 0x00040000, 0x01000080, 0x20040080, + 0x21000080, 0x21040000, 0x00040080, 0x20000000, + 0x01000000, 0x20040000, 0x20040000, 0x00000000, + 0x20000080, 0x21040080, 0x21040080, 0x01000080, + 0x21040000, 0x20000080, 0x00000000, 0x21000000, + 0x01040080, 0x01000000, 0x21000000, 0x00040080, + 0x00040000, 0x21000080, 0x00000080, 0x01000000, + 0x20000000, 0x01040000, 0x21000080, 0x20040080, + 0x01000080, 0x20000000, 0x21040000, 0x01040080, + 0x20040080, 0x00000080, 0x01000000, 0x21040000, + 0x21040080, 0x00040080, 0x21000000, 0x21040080, + 0x01040000, 0x00000000, 0x20040000, 0x21000000, + 0x00040080, 0x01000080, 0x20000080, 0x00040000, + 0x00000000, 0x20040000, 0x01040080, 0x20000080, + }, + { + 0x10000008, 0x10200000, 0x00002000, 0x10202008, + 0x10200000, 0x00000008, 0x10202008, 0x00200000, + 0x10002000, 0x00202008, 0x00200000, 0x10000008, + 0x00200008, 0x10002000, 0x10000000, 0x00002008, + 0x00000000, 0x00200008, 0x10002008, 0x00002000, + 0x00202000, 0x10002008, 0x00000008, 0x10200008, + 0x10200008, 0x00000000, 0x00202008, 0x10202000, + 0x00002008, 0x00202000, 0x10202000, 0x10000000, + 0x10002000, 0x00000008, 0x10200008, 0x00202000, + 0x10202008, 0x00200000, 0x00002008, 0x10000008, + 0x00200000, 0x10002000, 0x10000000, 0x00002008, + 0x10000008, 0x10202008, 0x00202000, 0x10200000, + 0x00202008, 0x10202000, 0x00000000, 0x10200008, + 0x00000008, 0x00002000, 0x10200000, 0x00202008, + 0x00002000, 0x00200008, 0x10002008, 0x00000000, + 0x10202000, 0x10000000, 0x00200008, 0x10002008, + }, + { + 0x00100000, 0x02100001, 0x02000401, 0x00000000, + 0x00000400, 0x02000401, 0x00100401, 0x02100400, + 0x02100401, 0x00100000, 0x00000000, 0x02000001, + 0x00000001, 0x02000000, 0x02100001, 0x00000401, + 0x02000400, 0x00100401, 0x00100001, 0x02000400, + 0x02000001, 0x02100000, 0x02100400, 0x00100001, + 0x02100000, 0x00000400, 0x00000401, 0x02100401, + 0x00100400, 0x00000001, 0x02000000, 0x00100400, + 0x02000000, 0x00100400, 0x00100000, 0x02000401, + 0x02000401, 0x02100001, 0x02100001, 0x00000001, + 0x00100001, 0x02000000, 0x02000400, 0x00100000, + 0x02100400, 0x00000401, 0x00100401, 0x02100400, + 0x00000401, 0x02000001, 0x02100401, 0x02100000, + 0x00100400, 0x00000000, 0x00000001, 0x02100401, + 0x00000000, 0x00100401, 0x02100000, 0x00000400, + 0x02000001, 0x02000400, 0x00000400, 0x00100001, + }, + { + 0x08000820, 0x00000800, 0x00020000, 0x08020820, + 0x08000000, 0x08000820, 0x00000020, 0x08000000, + 0x00020020, 0x08020000, 0x08020820, 0x00020800, + 0x08020800, 0x00020820, 0x00000800, 0x00000020, + 0x08020000, 0x08000020, 0x08000800, 0x00000820, + 0x00020800, 0x00020020, 0x08020020, 0x08020800, + 0x00000820, 0x00000000, 0x00000000, 0x08020020, + 0x08000020, 0x08000800, 0x00020820, 0x00020000, + 0x00020820, 0x00020000, 0x08020800, 0x00000800, + 0x00000020, 0x08020020, 0x00000800, 0x00020820, + 0x08000800, 0x00000020, 0x08000020, 0x08020000, + 0x08020020, 0x08000000, 0x00020000, 0x08000820, + 0x00000000, 0x08020820, 0x00020020, 0x08000020, + 0x08020000, 0x08000800, 0x08000820, 0x00000000, + 0x08020820, 0x00020800, 0x00020800, 0x00000820, + 0x00000820, 0x00020020, 0x08000000, 0x08020800, + }, +}; + +#define ps(i, j) Psboxes[i][j] + +#endif /* SMALL */ + +#if ASSEMBLY + +extern void des_crypt(); + +#else + +unsigned long Ip_l[] = { + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00000000, + 0x00000080, + 0x00000000, + 0x00000080, + 0x00008000, + 0x00008080, + 0x00008000, + 0x00008080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x00800000, + 0x00800080, + 0x00800000, + 0x00800080, + 0x00808000, + 0x00808080, + 0x00808000, + 0x00808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80000000, + 0x80000080, + 0x80000000, + 0x80000080, + 0x80008000, + 0x80008080, + 0x80008000, + 0x80008080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, + 0x80800000, + 0x80800080, + 0x80800000, + 0x80800080, + 0x80808000, + 0x80808080, + 0x80808000, + 0x80808080, +}; +unsigned long Ip_r[] = { + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00000000, + 0x00000000, + 0x00000080, + 0x00000080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00008000, + 0x00008000, + 0x00008080, + 0x00008080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00800000, + 0x00800000, + 0x00800080, + 0x00800080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x00808000, + 0x00808000, + 0x00808080, + 0x00808080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80000000, + 0x80000000, + 0x80000080, + 0x80000080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80008000, + 0x80008000, + 0x80008080, + 0x80008080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80800000, + 0x80800000, + 0x80800080, + 0x80800080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, + 0x80808000, + 0x80808000, + 0x80808080, + 0x80808080, +}; +unsigned long Ip_inv_l[] = { + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, + 0x00000000, + 0x80000000, + 0x00800000, + 0x80800000, + 0x00008000, + 0x80008000, + 0x00808000, + 0x80808000, + 0x00000080, + 0x80000080, + 0x00800080, + 0x80800080, + 0x00008080, + 0x80008080, + 0x00808080, + 0x80808080, +}; +unsigned long Ip_inv_r[] = { + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x80000000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x00800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x80800000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x00008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x80008000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x00808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x80808000, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x00000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x80000080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x00800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x80800080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x00008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x80008080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x00808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, + 0x80808080, +}; + + +void des_crypt(char *block, int dflag) +{ + ulong l, r, l2, r2; + uchar *s; + int i; + + /* Initial Transpose */ + s = (uchar *)block; + l = (((((((Ip_l[s[0]] >> 1 + | Ip_l[s[1]]) >> 1 + | Ip_l[s[2]]) >> 1 + | Ip_l[s[3]]) >> 1 + | Ip_l[s[4]]) >> 1 + | Ip_l[s[5]]) >> 1 + | Ip_l[s[6]]) >> 1 + | Ip_l[s[7]]); + r = (((((((Ip_r[s[0]] >> 1 + | Ip_r[s[1]]) >> 1 + | Ip_r[s[2]]) >> 1 + | Ip_r[s[3]]) >> 1 + | Ip_r[s[4]]) >> 1 + | Ip_r[s[5]]) >> 1 + | Ip_r[s[6]]) >> 1 + | Ip_r[s[7]]); + + if (dflag == 0) { + for (i = 0; i < 16; i++) { + ulong v, x1, x2; + + /* E-transpose, Xor, S-box and P-transpose */ + x1 = rol1(r); + x2 = ror4(x1) ^ Keys[i][0]; + x1 ^= Keys[i][1]; + v = l ^ ps(7, x1 & 0x3f) + ^ ps(5, (x1 >> 8) & 0x3f) + ^ ps(3, (x1 >> 16) & 0x3f) + ^ ps(1, (x1 >> 24) & 0x3f) + ^ ps(6, x2 & 0x3f) + ^ ps(4, (x2 >> 8) & 0x3f) + ^ ps(2, (x2 >> 16) & 0x3f) + ^ ps(0, (x2 >> 24) & 0x3f); + l = r; + r = v; + } + } else { + for (i = 16; --i >= 0; ) { + ulong v, x1, x2; + + /* E-transpose, Xor, S-box and P-transpose */ + x1 = rol1(r); + x2 = ror4(x1) ^ Keys[i][0]; + x1 ^= Keys[i][1]; + v = l ^ ps(7, x1 & 0x3f) + ^ ps(5, (x1 >> 8) & 0x3f) + ^ ps(3, (x1 >> 16) & 0x3f) + ^ ps(1, (x1 >> 24) & 0x3f) + ^ ps(6, x2 & 0x3f) + ^ ps(4, (x2 >> 8) & 0x3f) + ^ ps(2, (x2 >> 16) & 0x3f) + ^ ps(0, (x2 >> 24) & 0x3f); + l = r; + r = v; + } + } + /* Final transpose */ + l2 = (((((((Ip_inv_l[r & 0xff] >> 1 + | Ip_inv_l[l & 0xff]) >> 1 + | Ip_inv_l[r>>8 & 0xff]) >> 1 + | Ip_inv_l[l>>8 & 0xff]) >> 1 + | Ip_inv_l[r>>16 & 0xff]) >> 1 + | Ip_inv_l[l>>16 & 0xff]) >> 1 + | Ip_inv_l[r>>24 & 0xff]) >> 1 + | Ip_inv_l[l>>24 & 0xff]); + r2 = (((((((Ip_inv_r[r & 0xff] >> 1 + | Ip_inv_r[l & 0xff]) >> 1 + | Ip_inv_r[r>>8 & 0xff]) >> 1 + | Ip_inv_r[l>>8 & 0xff]) >> 1 + | Ip_inv_r[r>>16 & 0xff]) >> 1 + | Ip_inv_r[l>>16 & 0xff]) >> 1 + | Ip_inv_r[r>>24 & 0xff]) >> 1 + | Ip_inv_r[l>>24 & 0xff]); + *block++ = (char)(l2 >> 24); + *block++ = (char)(l2 >> 16); + *block++ = (char)(l2 >> 8); + *block++ = (char)l2; + *block++ = (char)(r2 >> 24); + *block++ = (char)(r2 >> 16); + *block++ = (char)(r2 >> 8); + *block++ = (char)r2; +} +#endif /* ASSEMBLY */ + + +int ecb_crypt(char *key, char *buf, unsigned len, unsigned mode) +{ + des_setkey(key); + for (len = (len + 7) & ~7; len != 0; buf += 8, len -= 8) + des_crypt(buf, mode & DES_DIRMASK); + return ((mode & DES_DEVMASK) == DES_SW ? DESERR_NONE + : DESERR_NOHWDEVICE); +} + + +int cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec) +{ + char nvec[8]; + + des_setkey(key); + switch (mode & DES_DIRMASK) { + case DES_ENCRYPT: + for (len = (len + 7) & ~7; len != 0; len -= 8) { + buf[0] ^= ivec[0]; + buf[1] ^= ivec[1]; + buf[2] ^= ivec[2]; + buf[3] ^= ivec[3]; + buf[4] ^= ivec[4]; + buf[5] ^= ivec[5]; + buf[6] ^= ivec[6]; + buf[7] ^= ivec[7]; + des_crypt(buf, DES_ENCRYPT); + ivec[0] = *buf++; + ivec[1] = *buf++; + ivec[2] = *buf++; + ivec[3] = *buf++; + ivec[4] = *buf++; + ivec[5] = *buf++; + ivec[6] = *buf++; + ivec[7] = *buf++; + } + break; + case DES_DECRYPT: + for (len = (len + 7) & ~7; len != 0; len -= 8) { + nvec[0] = buf[0]; + nvec[1] = buf[1]; + nvec[2] = buf[2]; + nvec[3] = buf[3]; + nvec[4] = buf[4]; + nvec[5] = buf[5]; + nvec[6] = buf[6]; + nvec[7] = buf[7]; + des_crypt(buf, DES_DECRYPT); + *buf++ ^= ivec[0]; + *buf++ ^= ivec[1]; + *buf++ ^= ivec[2]; + *buf++ ^= ivec[3]; + *buf++ ^= ivec[4]; + *buf++ ^= ivec[5]; + *buf++ ^= ivec[6]; + *buf++ ^= ivec[7]; + ivec[0] = nvec[0]; + ivec[1] = nvec[1]; + ivec[2] = nvec[2]; + ivec[3] = nvec[3]; + ivec[4] = nvec[4]; + ivec[5] = nvec[5]; + ivec[6] = nvec[6]; + ivec[7] = nvec[7]; + } + break; + } + return ((mode & DES_DEVMASK) == DES_SW ? DESERR_NONE + : DESERR_NOHWDEVICE); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.h b/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.h new file mode 100644 index 0000000..5b9ca13 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/descrypt.h @@ -0,0 +1,43 @@ +/* + * DES encryption/decryption library interface + * + * Written by Koichiro Mori (kmori@lsi-j.co.jp) + */ + +#define DES_DIRMASK 001 +#define DES_ENCRYPT (0 * DES_DIRMASK) +#define DES_DECRYPT (1 * DES_DIRMASK) + +#define DES_DEVMASK 002 +#define DES_HW (0 * DES_DEVMASK) +#define DES_SW (1 * DES_DEVMASK) + +#define DESERR_NONE 0 +#define DESERR_NOHWDEVICE 1 +#define DESERR_HWERROR 2 +#define DESERR_BADPARAM 3 + +#define DES_FAILED(err) ((err) > DESERR_NOHWDEVICE) + +//#if __STDC__ || LSI_C + +int ecb_crypt(char *key, char *buf, unsigned len, unsigned mode); +int cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec); +void des_setparity(char *key); + +/* Not defined by Sun Microsystems - internally used by desbench program */ +void des_setkey(char *key); +void des_crypt(char *buf, int dflag); +/* +#else + + int ecb_crypt(); + int cbc_crypt(); + void des_setparity(); + +// Not defined by Sun Microsystems - internally used by desbench program + void des_setkey(); + void des_crypt(); + +#endif // __STDC__ || LSI_C +*/ \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.h new file mode 100644 index 0000000..435bbf5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.h @@ -0,0 +1,456 @@ +/* +** DynASM ARM encoding engine. +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** Released under the MIT license. See dynasm.lua for full copyright notice. +*/ + +#include +#include +#include +#include + +#define DASM_ARCH "arm" + +#ifndef DASM_EXTERN +#define DASM_EXTERN(a,b,c,d) 0 +#endif + +/* Action definitions. */ +enum { + DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT, + /* The following actions need a buffer position. */ + DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG, + /* The following actions also have an argument. */ + DASM_REL_PC, DASM_LABEL_PC, + DASM_IMM, DASM_IMM12, DASM_IMM16, DASM_IMML8, DASM_IMML12, DASM_IMMV8, + DASM__MAX +}; + +/* Maximum number of section buffer positions for a single dasm_put() call. */ +#define DASM_MAXSECPOS 25 + +/* DynASM encoder status codes. Action list offset or number are or'ed in. */ +#define DASM_S_OK 0x00000000 +#define DASM_S_NOMEM 0x01000000 +#define DASM_S_PHASE 0x02000000 +#define DASM_S_MATCH_SEC 0x03000000 +#define DASM_S_RANGE_I 0x11000000 +#define DASM_S_RANGE_SEC 0x12000000 +#define DASM_S_RANGE_LG 0x13000000 +#define DASM_S_RANGE_PC 0x14000000 +#define DASM_S_RANGE_REL 0x15000000 +#define DASM_S_UNDEF_LG 0x21000000 +#define DASM_S_UNDEF_PC 0x22000000 + +/* Macros to convert positions (8 bit section + 24 bit index). */ +#define DASM_POS2IDX(pos) ((pos)&0x00ffffff) +#define DASM_POS2BIAS(pos) ((pos)&0xff000000) +#define DASM_SEC2POS(sec) ((sec)<<24) +#define DASM_POS2SEC(pos) ((pos)>>24) +#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos)) + +/* Action list type. */ +typedef const unsigned int *dasm_ActList; + +/* Per-section structure. */ +typedef struct dasm_Section { + int *rbuf; /* Biased buffer pointer (negative section bias). */ + int *buf; /* True buffer pointer. */ + size_t bsize; /* Buffer size in bytes. */ + int pos; /* Biased buffer position. */ + int epos; /* End of biased buffer position - max single put. */ + int ofs; /* Byte offset into section. */ +} dasm_Section; + +/* Core structure holding the DynASM encoding state. */ +struct dasm_State { + size_t psize; /* Allocated size of this structure. */ + dasm_ActList actionlist; /* Current actionlist pointer. */ + int *lglabels; /* Local/global chain/pos ptrs. */ + size_t lgsize; + int *pclabels; /* PC label chains/pos ptrs. */ + size_t pcsize; + void **globals; /* Array of globals (bias -10). */ + dasm_Section *section; /* Pointer to active section. */ + size_t codesize; /* Total size of all code sections. */ + int maxsection; /* 0 <= sectionidx < maxsection. */ + int status; /* Status code. */ + dasm_Section sections[1]; /* All sections. Alloc-extended. */ +}; + +/* The size of the core structure depends on the max. number of sections. */ +#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section)) + + +/* Initialize DynASM state. */ +void dasm_init(Dst_DECL, int maxsection) +{ + dasm_State *D; + size_t psz = 0; + int i; + Dst_REF = NULL; + DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); + D = Dst_REF; + D->psize = psz; + D->lglabels = NULL; + D->lgsize = 0; + D->pclabels = NULL; + D->pcsize = 0; + D->globals = NULL; + D->maxsection = maxsection; + for (i = 0; i < maxsection; i++) { + D->sections[i].buf = NULL; /* Need this for pass3. */ + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); + D->sections[i].bsize = 0; + D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ + } +} + +/* Free DynASM state. */ +void dasm_free(Dst_DECL) +{ + dasm_State *D = Dst_REF; + int i; + for (i = 0; i < D->maxsection; i++) + if (D->sections[i].buf) + DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); + if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); + if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); + DASM_M_FREE(Dst, D, D->psize); +} + +/* Setup global label array. Must be called before dasm_setup(). */ +void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) +{ + dasm_State *D = Dst_REF; + D->globals = gl - 10; /* Negative bias to compensate for locals. */ + DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); +} + +/* Grow PC label array. Can be called after dasm_setup(), too. */ +void dasm_growpc(Dst_DECL, unsigned int maxpc) +{ + dasm_State *D = Dst_REF; + size_t osz = D->pcsize; + DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); + memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz); +} + +/* Setup encoder. */ +void dasm_setup(Dst_DECL, const void *actionlist) +{ + dasm_State *D = Dst_REF; + int i; + D->actionlist = (dasm_ActList)actionlist; + D->status = DASM_S_OK; + D->section = &D->sections[0]; + memset((void *)D->lglabels, 0, D->lgsize); + if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); + for (i = 0; i < D->maxsection; i++) { + D->sections[i].pos = DASM_SEC2POS(i); + D->sections[i].ofs = 0; + } +} + + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) { \ + D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0) +#define CKPL(kind, st) \ + do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \ + D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0) +#else +#define CK(x, st) ((void)0) +#define CKPL(kind, st) ((void)0) +#endif + +static int dasm_imm12(unsigned int n) +{ + int i; + for (i = 0; i < 16; i++, n = (n << 2) | (n >> 30)) + if (n <= 255) return (int)(n + (i << 8)); + return -1; +} + +/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */ +void dasm_put(Dst_DECL, int start, ...) +{ + va_list ap; + dasm_State *D = Dst_REF; + dasm_ActList p = D->actionlist + start; + dasm_Section *sec = D->section; + int pos = sec->pos, ofs = sec->ofs; + int *b; + + if (pos >= sec->epos) { + DASM_M_GROW(Dst, int, sec->buf, sec->bsize, + sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); + sec->rbuf = sec->buf - DASM_POS2BIAS(pos); + sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos); + } + + b = sec->rbuf; + b[pos++] = start; + + va_start(ap, start); + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + if (action >= DASM__MAX) { + ofs += 4; + } else { + int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0; + switch (action) { + case DASM_STOP: goto stop; + case DASM_SECTION: + n = (ins & 255); CK(n < D->maxsection, RANGE_SEC); + D->section = &D->sections[n]; goto stop; + case DASM_ESC: p++; ofs += 4; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break; + case DASM_REL_LG: + n = (ins & 2047) - 10; pl = D->lglabels + n; + /* Bkwd rel or global. */ + if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; } + pl += 10; n = *pl; + if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ + goto linkrel; + case DASM_REL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putrel: + n = *pl; + if (n < 0) { /* Label exists. Get label pos and store it. */ + b[pos] = -n; + } else { + linkrel: + b[pos] = n; /* Else link to rel chain, anchored at label. */ + *pl = pos; + } + pos++; + break; + case DASM_LABEL_LG: + pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel; + case DASM_LABEL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putlabel: + n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; + } + *pl = -pos; /* Label exists now. */ + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_IMM: + case DASM_IMM16: +#ifdef DASM_CHECKS + CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I); + if ((ins & 0x8000)) + CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I); + else + CK((n>>((ins>>5)&31)) == 0, RANGE_I); +#endif + b[pos++] = n; + break; + case DASM_IMMV8: + CK((n & 3) == 0, RANGE_I); + n >>= 2; + case DASM_IMML8: + case DASM_IMML12: + CK(n >= 0 ? ((n>>((ins>>5)&31)) == 0) : + (((-n)>>((ins>>5)&31)) == 0), RANGE_I); + b[pos++] = n; + break; + case DASM_IMM12: + CK(dasm_imm12((unsigned int)n) != -1, RANGE_I); + b[pos++] = n; + break; + } + } + } +stop: + va_end(ap); + sec->pos = pos; + sec->ofs = ofs; +} +#undef CK + +/* Pass 2: Link sections, shrink aligns, fix label offsets. */ +int dasm_link(Dst_DECL, size_t *szp) +{ + dasm_State *D = Dst_REF; + int secnum; + int ofs = 0; + +#ifdef DASM_CHECKS + *szp = 0; + if (D->status != DASM_S_OK) return D->status; + { + int pc; + for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) + if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc; + } +#endif + + { /* Handle globals not defined in this translation unit. */ + int idx; + for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { + int n = D->lglabels[idx]; + /* Undefined label: Collapse rel chain and replace with marker (< 0). */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } + } + } + + /* Combine all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->rbuf; + int pos = DASM_SEC2POS(secnum); + int lastpos = sec->pos; + + while (pos != lastpos) { + dasm_ActList p = D->actionlist + b[pos++]; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: p++; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break; + case DASM_REL_LG: case DASM_REL_PC: pos++; break; + case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break; + case DASM_IMM: case DASM_IMM12: case DASM_IMM16: + case DASM_IMML8: case DASM_IMML12: case DASM_IMMV8: pos++; break; + } + } + stop: (void)0; + } + ofs += sec->ofs; /* Next section starts right after current section. */ + } + + D->codesize = ofs; /* Total size of all code sections */ + *szp = ofs; + return DASM_S_OK; +} + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0) +#else +#define CK(x, st) ((void)0) +#endif + +/* Pass 3: Encode sections. */ +int dasm_encode(Dst_DECL, void *buffer) +{ + dasm_State *D = Dst_REF; + char *base = (char *)buffer; + unsigned int *cp = (unsigned int *)buffer; + int secnum; + + /* Encode all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->buf; + int *endb = sec->rbuf + sec->pos; + + while (b != endb) { + dasm_ActList p = D->actionlist + *b++; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0; + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: *cp++ = *p++; break; + case DASM_REL_EXT: + n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048)); + goto patchrel; + case DASM_ALIGN: + ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000; + break; + case DASM_REL_LG: + CK(n >= 0, UNDEF_LG); + case DASM_REL_PC: + CK(n >= 0, UNDEF_PC); + n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) - 4; + patchrel: + if ((ins & 0x800) == 0) { + CK((n & 3) == 0 && ((n+0x02000000) >> 26) == 0, RANGE_REL); + cp[-1] |= ((n >> 2) & 0x00ffffff); + } else if ((ins & 0x1000)) { + CK((n & 3) == 0 && -256 <= n && n <= 256, RANGE_REL); + goto patchimml8; + } else if ((ins & 0x2000) == 0) { + CK((n & 3) == 0 && -4096 <= n && n <= 4096, RANGE_REL); + goto patchimml; + } else { + CK((n & 3) == 0 && -1020 <= n && n <= 1020, RANGE_REL); + n >>= 2; + goto patchimml; + } + break; + case DASM_LABEL_LG: + ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + break; + case DASM_LABEL_PC: break; + case DASM_IMM: + cp[-1] |= ((n>>((ins>>10)&31)) & ((1<<((ins>>5)&31))-1)) << (ins&31); + break; + case DASM_IMM12: + cp[-1] |= dasm_imm12((unsigned int)n); + break; + case DASM_IMM16: + cp[-1] |= ((n & 0xf000) << 4) | (n & 0x0fff); + break; + case DASM_IMML8: patchimml8: + cp[-1] |= n >= 0 ? (0x00800000 | (n & 0x0f) | ((n & 0xf0) << 4)) : + ((-n & 0x0f) | ((-n & 0xf0) << 4)); + break; + case DASM_IMML12: case DASM_IMMV8: patchimml: + cp[-1] |= n >= 0 ? (0x00800000 | n) : (-n); + break; + default: *cp++ = ins; break; + } + } + stop: (void)0; + } + } + + if (base + D->codesize != (char *)cp) /* Check for phase errors. */ + return DASM_S_PHASE; + return DASM_S_OK; +} +#undef CK + +/* Get PC label offset. */ +int dasm_getpclabel(Dst_DECL, unsigned int pc) +{ + dasm_State *D = Dst_REF; + if (pc*sizeof(int) < D->pcsize) { + int pos = D->pclabels[pc]; + if (pos < 0) return *DASM_POS2PTR(D, -pos); + if (pos > 0) return -1; /* Undefined. */ + } + return -2; /* Unused or out of range. */ +} + +#ifdef DASM_CHECKS +/* Optional sanity checker to call between isolated encoding steps. */ +int dasm_checkstep(Dst_DECL, int secmatch) +{ + dasm_State *D = Dst_REF; + if (D->status == DASM_S_OK) { + int i; + for (i = 1; i <= 9; i++) { + if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; } + D->lglabels[i] = 0; + } + } + if (D->status == DASM_S_OK && secmatch >= 0 && + D->section != &D->sections[secmatch]) + D->status = DASM_S_MATCH_SEC|(D->section-D->sections); + return D->status; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.lua new file mode 100644 index 0000000..b3a8827 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_arm.lua @@ -0,0 +1,1122 @@ +------------------------------------------------------------------------------ +-- DynASM ARM module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See dynasm.lua for full copyright notice. +------------------------------------------------------------------------------ + +-- Module information: +local _info = { + arch = "arm", + description = "DynASM ARM module", + version = "1.3.0", + vernum = 10300, + release = "2011-05-05", + author = "Mike Pall", + license = "MIT", +} + +-- Exported glue functions for the arch-specific module. +local _M = { _info = _info } + +-- Cache library functions. +local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs +local assert, setmetatable, rawget = assert, setmetatable, rawget +local _s = string +local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char +local match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub +local concat, sort, insert = table.concat, table.sort, table.insert +local bit = bit or require("bit") +local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift +local ror, tohex = bit.ror, bit.tohex + +-- Inherited tables and callbacks. +local g_opt, g_arch +local wline, werror, wfatal, wwarn + +-- Action name list. +-- CHECK: Keep this in sync with the C code! +local action_names = { + "STOP", "SECTION", "ESC", "REL_EXT", + "ALIGN", "REL_LG", "LABEL_LG", + "REL_PC", "LABEL_PC", "IMM", "IMM12", "IMM16", "IMML8", "IMML12", "IMMV8", +} + +-- Maximum number of section buffer positions for dasm_put(). +-- CHECK: Keep this in sync with the C code! +local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines. + +-- Action name -> action number. +local map_action = {} +for n,name in ipairs(action_names) do + map_action[name] = n-1 +end + +-- Action list buffer. +local actlist = {} + +-- Argument list for next dasm_put(). Start with offset 0 into action list. +local actargs = { 0 } + +-- Current number of section buffer positions for dasm_put(). +local secpos = 1 + +------------------------------------------------------------------------------ + +-- Dump action names and numbers. +local function dumpactions(out) + out:write("DynASM encoding engine action codes:\n") + for n,name in ipairs(action_names) do + local num = map_action[name] + out:write(format(" %-10s %02X %d\n", name, num, num)) + end + out:write("\n") +end + +-- Write action list buffer as a huge static C array. +local function writeactions(out, name) + local nn = #actlist + if nn == 0 then nn = 1; actlist[0] = map_action.STOP end + out:write("static const unsigned int ", name, "[", nn, "] = {\n") + for i = 1,nn-1 do + assert(out:write("0x", tohex(actlist[i]), ",\n")) + end + assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n")) +end + +------------------------------------------------------------------------------ + +-- Add word to action list. +local function wputxw(n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + actlist[#actlist+1] = n +end + +-- Add action to list with optional arg. Advance buffer pos, too. +local function waction(action, val, a, num) + local w = assert(map_action[action], "bad action name `"..action.."'") + wputxw(w * 0x10000 + (val or 0)) + if a then actargs[#actargs+1] = a end + if a or num then secpos = secpos + (num or 1) end +end + +-- Flush action list (intervening C code or buffer pos overflow). +local function wflush(term) + if #actlist == actargs[1] then return end -- Nothing to flush. + if not term then waction("STOP") end -- Terminate action list. + wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true) + actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put(). + secpos = 1 -- The actionlist offset occupies a buffer position, too. +end + +-- Put escaped word. +local function wputw(n) + if n <= 0x000fffff then waction("ESC") end + wputxw(n) +end + +-- Reserve position for word. +local function wpos() + local pos = #actlist+1 + actlist[pos] = "" + return pos +end + +-- Store word to reserved position. +local function wputpos(pos, n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + if n <= 0x000fffff then + insert(actlist, pos+1, n) + n = map_action.ESC * 0x10000 + end + actlist[pos] = n +end + +------------------------------------------------------------------------------ + +-- Global label name -> global label number. With auto assignment on 1st use. +local next_global = 20 +local map_global = setmetatable({}, { __index = function(t, name) + if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end + local n = next_global + if n > 2047 then werror("too many global labels") end + next_global = n + 1 + t[name] = n + return n +end}) + +-- Dump global labels. +local function dumpglobals(out, lvl) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("Global labels:\n") + for i=20,next_global-1 do + out:write(format(" %s\n", t[i])) + end + out:write("\n") +end + +-- Write global label enum. +local function writeglobals(out, prefix) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("enum {\n") + for i=20,next_global-1 do + out:write(" ", prefix, t[i], ",\n") + end + out:write(" ", prefix, "_MAX\n};\n") +end + +-- Write global label names. +local function writeglobalnames(out, name) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("static const char *const ", name, "[] = {\n") + for i=20,next_global-1 do + out:write(" \"", t[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Extern label name -> extern label number. With auto assignment on 1st use. +local next_extern = 0 +local map_extern_ = {} +local map_extern = setmetatable({}, { __index = function(t, name) + -- No restrictions on the name for now. + local n = next_extern + if n > 2047 then werror("too many extern labels") end + next_extern = n + 1 + t[name] = n + map_extern_[n] = name + return n +end}) + +-- Dump extern labels. +local function dumpexterns(out, lvl) + out:write("Extern labels:\n") + for i=0,next_extern-1 do + out:write(format(" %s\n", map_extern_[i])) + end + out:write("\n") +end + +-- Write extern label names. +local function writeexternnames(out, name) + out:write("static const char *const ", name, "[] = {\n") + for i=0,next_extern-1 do + out:write(" \"", map_extern_[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Arch-specific maps. + +-- Ext. register name -> int. name. +local map_archdef = { sp = "r13", lr = "r14", pc = "r15", } + +-- Int. register name -> ext. name. +local map_reg_rev = { r13 = "sp", r14 = "lr", r15 = "pc", } + +local map_type = {} -- Type name -> { ctype, reg } +local ctypenum = 0 -- Type number (for Dt... macros). + +-- Reverse defines for registers. +function _M.revdef(s) + return map_reg_rev[s] or s +end + +local map_shift = { lsl = 0, lsr = 1, asr = 2, ror = 3, } + +local map_cond = { + eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7, + hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14, + hs = 2, lo = 3, +} + +------------------------------------------------------------------------------ + +-- Template strings for ARM instructions. +local map_op = { + -- Basic data processing instructions. + and_3 = "e0000000DNPs", + eor_3 = "e0200000DNPs", + sub_3 = "e0400000DNPs", + rsb_3 = "e0600000DNPs", + add_3 = "e0800000DNPs", + adc_3 = "e0a00000DNPs", + sbc_3 = "e0c00000DNPs", + rsc_3 = "e0e00000DNPs", + tst_2 = "e1100000NP", + teq_2 = "e1300000NP", + cmp_2 = "e1500000NP", + cmn_2 = "e1700000NP", + orr_3 = "e1800000DNPs", + mov_2 = "e1a00000DPs", + bic_3 = "e1c00000DNPs", + mvn_2 = "e1e00000DPs", + + and_4 = "e0000000DNMps", + eor_4 = "e0200000DNMps", + sub_4 = "e0400000DNMps", + rsb_4 = "e0600000DNMps", + add_4 = "e0800000DNMps", + adc_4 = "e0a00000DNMps", + sbc_4 = "e0c00000DNMps", + rsc_4 = "e0e00000DNMps", + tst_3 = "e1100000NMp", + teq_3 = "e1300000NMp", + cmp_3 = "e1500000NMp", + cmn_3 = "e1700000NMp", + orr_4 = "e1800000DNMps", + mov_3 = "e1a00000DMps", + bic_4 = "e1c00000DNMps", + mvn_3 = "e1e00000DMps", + + lsl_3 = "e1a00000DMws", + lsr_3 = "e1a00020DMws", + asr_3 = "e1a00040DMws", + ror_3 = "e1a00060DMws", + rrx_2 = "e1a00060DMs", + + -- Multiply and multiply-accumulate. + mul_3 = "e0000090NMSs", + mla_4 = "e0200090NMSDs", + umaal_4 = "e0400090DNMSs", -- v6 + mls_4 = "e0600090DNMSs", -- v6T2 + umull_4 = "e0800090DNMSs", + umlal_4 = "e0a00090DNMSs", + smull_4 = "e0c00090DNMSs", + smlal_4 = "e0e00090DNMSs", + + -- Halfword multiply and multiply-accumulate. + smlabb_4 = "e1000080NMSD", -- v5TE + smlatb_4 = "e10000a0NMSD", -- v5TE + smlabt_4 = "e10000c0NMSD", -- v5TE + smlatt_4 = "e10000e0NMSD", -- v5TE + smlawb_4 = "e1200080NMSD", -- v5TE + smulwb_3 = "e12000a0NMS", -- v5TE + smlawt_4 = "e12000c0NMSD", -- v5TE + smulwt_3 = "e12000e0NMS", -- v5TE + smlalbb_4 = "e1400080NMSD", -- v5TE + smlaltb_4 = "e14000a0NMSD", -- v5TE + smlalbt_4 = "e14000c0NMSD", -- v5TE + smlaltt_4 = "e14000e0NMSD", -- v5TE + smulbb_3 = "e1600080NMS", -- v5TE + smultb_3 = "e16000a0NMS", -- v5TE + smulbt_3 = "e16000c0NMS", -- v5TE + smultt_3 = "e16000e0NMS", -- v5TE + + -- Miscellaneous data processing instructions. + clz_2 = "e16f0f10DM", -- v5T + rev_2 = "e6bf0f30DM", -- v6 + rev16_2 = "e6bf0fb0DM", -- v6 + revsh_2 = "e6ff0fb0DM", -- v6 + sel_3 = "e6800fb0DNM", -- v6 + usad8_3 = "e780f010NMS", -- v6 + usada8_4 = "e7800010NMSD", -- v6 + rbit_2 = "e6ff0f30DM", -- v6T2 + movw_2 = "e3000000DW", -- v6T2 + movt_2 = "e3400000DW", -- v6T2 + -- Note: the X encodes width-1, not width. + sbfx_4 = "e7a00050DMvX", -- v6T2 + ubfx_4 = "e7e00050DMvX", -- v6T2 + -- Note: the X encodes the msb field, not the width. + bfc_3 = "e7c0001fDvX", -- v6T2 + bfi_4 = "e7c00010DMvX", -- v6T2 + + -- Packing and unpacking instructions. + pkhbt_3 = "e6800010DNM", pkhbt_4 = "e6800010DNMv", -- v6 + pkhtb_3 = "e6800050DNM", pkhtb_4 = "e6800050DNMv", -- v6 + sxtab_3 = "e6a00070DNM", sxtab_4 = "e6a00070DNMv", -- v6 + sxtab16_3 = "e6800070DNM", sxtab16_4 = "e6800070DNMv", -- v6 + sxtah_3 = "e6b00070DNM", sxtah_4 = "e6b00070DNMv", -- v6 + sxtb_2 = "e6af0070DM", sxtb_3 = "e6af0070DMv", -- v6 + sxtb16_2 = "e68f0070DM", sxtb16_3 = "e68f0070DMv", -- v6 + sxth_2 = "e6bf0070DM", sxth_3 = "e6bf0070DMv", -- v6 + uxtab_3 = "e6e00070DNM", uxtab_4 = "e6e00070DNMv", -- v6 + uxtab16_3 = "e6c00070DNM", uxtab16_4 = "e6c00070DNMv", -- v6 + uxtah_3 = "e6f00070DNM", uxtah_4 = "e6f00070DNMv", -- v6 + uxtb_2 = "e6ef0070DM", uxtb_3 = "e6ef0070DMv", -- v6 + uxtb16_2 = "e6cf0070DM", uxtb16_3 = "e6cf0070DMv", -- v6 + uxth_2 = "e6ff0070DM", uxth_3 = "e6ff0070DMv", -- v6 + + -- Saturating instructions. + qadd_3 = "e1000050DMN", -- v5TE + qsub_3 = "e1200050DMN", -- v5TE + qdadd_3 = "e1400050DMN", -- v5TE + qdsub_3 = "e1600050DMN", -- v5TE + -- Note: the X for ssat* encodes sat_imm-1, not sat_imm. + ssat_3 = "e6a00010DXM", ssat_4 = "e6a00010DXMp", -- v6 + usat_3 = "e6e00010DXM", usat_4 = "e6e00010DXMp", -- v6 + ssat16_3 = "e6a00f30DXM", -- v6 + usat16_3 = "e6e00f30DXM", -- v6 + + -- Parallel addition and subtraction. + sadd16_3 = "e6100f10DNM", -- v6 + sasx_3 = "e6100f30DNM", -- v6 + ssax_3 = "e6100f50DNM", -- v6 + ssub16_3 = "e6100f70DNM", -- v6 + sadd8_3 = "e6100f90DNM", -- v6 + ssub8_3 = "e6100ff0DNM", -- v6 + qadd16_3 = "e6200f10DNM", -- v6 + qasx_3 = "e6200f30DNM", -- v6 + qsax_3 = "e6200f50DNM", -- v6 + qsub16_3 = "e6200f70DNM", -- v6 + qadd8_3 = "e6200f90DNM", -- v6 + qsub8_3 = "e6200ff0DNM", -- v6 + shadd16_3 = "e6300f10DNM", -- v6 + shasx_3 = "e6300f30DNM", -- v6 + shsax_3 = "e6300f50DNM", -- v6 + shsub16_3 = "e6300f70DNM", -- v6 + shadd8_3 = "e6300f90DNM", -- v6 + shsub8_3 = "e6300ff0DNM", -- v6 + uadd16_3 = "e6500f10DNM", -- v6 + uasx_3 = "e6500f30DNM", -- v6 + usax_3 = "e6500f50DNM", -- v6 + usub16_3 = "e6500f70DNM", -- v6 + uadd8_3 = "e6500f90DNM", -- v6 + usub8_3 = "e6500ff0DNM", -- v6 + uqadd16_3 = "e6600f10DNM", -- v6 + uqasx_3 = "e6600f30DNM", -- v6 + uqsax_3 = "e6600f50DNM", -- v6 + uqsub16_3 = "e6600f70DNM", -- v6 + uqadd8_3 = "e6600f90DNM", -- v6 + uqsub8_3 = "e6600ff0DNM", -- v6 + uhadd16_3 = "e6700f10DNM", -- v6 + uhasx_3 = "e6700f30DNM", -- v6 + uhsax_3 = "e6700f50DNM", -- v6 + uhsub16_3 = "e6700f70DNM", -- v6 + uhadd8_3 = "e6700f90DNM", -- v6 + uhsub8_3 = "e6700ff0DNM", -- v6 + + -- Load/store instructions. + str_2 = "e4000000DL", str_3 = "e4000000DL", str_4 = "e4000000DL", + strb_2 = "e4400000DL", strb_3 = "e4400000DL", strb_4 = "e4400000DL", + ldr_2 = "e4100000DL", ldr_3 = "e4100000DL", ldr_4 = "e4100000DL", + ldrb_2 = "e4500000DL", ldrb_3 = "e4500000DL", ldrb_4 = "e4500000DL", + strh_2 = "e00000b0DL", strh_3 = "e00000b0DL", + ldrh_2 = "e01000b0DL", ldrh_3 = "e01000b0DL", + ldrd_2 = "e00000d0DL", ldrd_3 = "e00000d0DL", -- v5TE + ldrsb_2 = "e01000d0DL", ldrsb_3 = "e01000d0DL", + strd_2 = "e00000f0DL", strd_3 = "e00000f0DL", -- v5TE + ldrsh_2 = "e01000f0DL", ldrsh_3 = "e01000f0DL", + + ldm_2 = "e8900000oR", ldmia_2 = "e8900000oR", ldmfd_2 = "e8900000oR", + ldmda_2 = "e8100000oR", ldmfa_2 = "e8100000oR", + ldmdb_2 = "e9100000oR", ldmea_2 = "e9100000oR", + ldmib_2 = "e9900000oR", ldmed_2 = "e9900000oR", + stm_2 = "e8800000oR", stmia_2 = "e8800000oR", stmfd_2 = "e8800000oR", + stmda_2 = "e8000000oR", stmfa_2 = "e8000000oR", + stmdb_2 = "e9000000oR", stmea_2 = "e9000000oR", + stmib_2 = "e9800000oR", stmed_2 = "e9800000oR", + pop_1 = "e8bd0000R", push_1 = "e92d0000R", + + -- Branch instructions. + b_1 = "ea000000B", + bl_1 = "eb000000B", + blx_1 = "e12fff30C", + bx_1 = "e12fff10M", + + -- Miscellaneous instructions. + nop_0 = "e1a00000", + mrs_1 = "e10f0000D", + bkpt_1 = "e1200070K", -- v5T + svc_1 = "ef000000T", swi_1 = "ef000000T", + ud_0 = "e7f001f0", + + -- VFP instructions. + ["vadd.f32_3"] = "ee300a00dnm", + ["vadd.f64_3"] = "ee300b00Gdnm", + ["vsub.f32_3"] = "ee300a40dnm", + ["vsub.f64_3"] = "ee300b40Gdnm", + ["vmul.f32_3"] = "ee200a00dnm", + ["vmul.f64_3"] = "ee200b00Gdnm", + ["vnmul.f32_3"] = "ee200a40dnm", + ["vnmul.f64_3"] = "ee200b40Gdnm", + ["vmla.f32_3"] = "ee000a00dnm", + ["vmla.f64_3"] = "ee000b00Gdnm", + ["vmls.f32_3"] = "ee000a40dnm", + ["vmls.f64_3"] = "ee000b40Gdnm", + ["vnmla.f32_3"] = "ee100a40dnm", + ["vnmla.f64_3"] = "ee100b40Gdnm", + ["vnmls.f32_3"] = "ee100a00dnm", + ["vnmls.f64_3"] = "ee100b00Gdnm", + ["vdiv.f32_3"] = "ee800a00dnm", + ["vdiv.f64_3"] = "ee800b00Gdnm", + + ["vabs.f32_2"] = "eeb00ac0dm", + ["vabs.f64_2"] = "eeb00bc0Gdm", + ["vneg.f32_2"] = "eeb10a40dm", + ["vneg.f64_2"] = "eeb10b40Gdm", + ["vsqrt.f32_2"] = "eeb10ac0dm", + ["vsqrt.f64_2"] = "eeb10bc0Gdm", + ["vcmp.f32_2"] = "eeb40a40dm", + ["vcmp.f64_2"] = "eeb40b40Gdm", + ["vcmpe.f32_2"] = "eeb40ac0dm", + ["vcmpe.f64_2"] = "eeb40bc0Gdm", + ["vcmpz.f32_1"] = "eeb50a40d", + ["vcmpz.f64_1"] = "eeb50b40Gd", + ["vcmpze.f32_1"] = "eeb50ac0d", + ["vcmpze.f64_1"] = "eeb50bc0Gd", + + vldr_2 = "ed100a00dl|ed100b00Gdl", + vstr_2 = "ed000a00dl|ed000b00Gdl", + vldm_2 = "ec900a00or", + vldmia_2 = "ec900a00or", + vldmdb_2 = "ed100a00or", + vpop_1 = "ecbd0a00r", + vstm_2 = "ec800a00or", + vstmia_2 = "ec800a00or", + vstmdb_2 = "ed000a00or", + vpush_1 = "ed2d0a00r", + + ["vmov.f32_2"] = "eeb00a40dm|eeb00a00dY", -- #imm is VFPv3 only + ["vmov.f64_2"] = "eeb00b40Gdm|eeb00b00GdY", -- #imm is VFPv3 only + vmov_2 = "ee100a10Dn|ee000a10nD", + vmov_3 = "ec500a10DNm|ec400a10mDN|ec500b10GDNm|ec400b10GmDN", + + vmrs_0 = "eef1fa10", + vmrs_1 = "eef10a10D", + vmsr_1 = "eee10a10D", + + ["vcvt.s32.f32_2"] = "eebd0ac0dm", + ["vcvt.s32.f64_2"] = "eebd0bc0dGm", + ["vcvt.u32.f32_2"] = "eebc0ac0dm", + ["vcvt.u32.f64_2"] = "eebc0bc0dGm", + ["vcvtr.s32.f32_2"] = "eebd0a40dm", + ["vcvtr.s32.f64_2"] = "eebd0b40dGm", + ["vcvtr.u32.f32_2"] = "eebc0a40dm", + ["vcvtr.u32.f64_2"] = "eebc0b40dGm", + ["vcvt.f32.s32_2"] = "eeb80ac0dm", + ["vcvt.f64.s32_2"] = "eeb80bc0GdFm", + ["vcvt.f32.u32_2"] = "eeb80a40dm", + ["vcvt.f64.u32_2"] = "eeb80b40GdFm", + ["vcvt.f32.f64_2"] = "eeb70bc0dGm", + ["vcvt.f64.f32_2"] = "eeb70ac0GdFm", + + -- VFPv4 only: + ["vfma.f32_3"] = "eea00a00dnm", + ["vfma.f64_3"] = "eea00b00Gdnm", + ["vfms.f32_3"] = "eea00a40dnm", + ["vfms.f64_3"] = "eea00b40Gdnm", + ["vfnma.f32_3"] = "ee900a40dnm", + ["vfnma.f64_3"] = "ee900b40Gdnm", + ["vfnms.f32_3"] = "ee900a00dnm", + ["vfnms.f64_3"] = "ee900b00Gdnm", + + -- NYI: Advanced SIMD instructions. + + -- NYI: I have no need for these instructions right now: + -- swp, swpb, strex, ldrex, strexd, ldrexd, strexb, ldrexb, strexh, ldrexh + -- msr, nopv6, yield, wfe, wfi, sev, dbg, bxj, smc, srs, rfe + -- cps, setend, pli, pld, pldw, clrex, dsb, dmb, isb + -- stc, ldc, mcr, mcr2, mrc, mrc2, mcrr, mcrr2, mrrc, mrrc2, cdp, cdp2 +} + +-- Add mnemonics for "s" variants. +do + local t = {} + for k,v in pairs(map_op) do + if sub(v, -1) == "s" then + local v2 = sub(v, 1, 2)..char(byte(v, 3)+1)..sub(v, 4, -2) + t[sub(k, 1, -3).."s"..sub(k, -2)] = v2 + end + end + for k,v in pairs(t) do + map_op[k] = v + end +end + +------------------------------------------------------------------------------ + +local function parse_gpr(expr) + local tname, ovreg = match(expr, "^([%w_]+):(r1?[0-9])$") + local tp = map_type[tname or expr] + if tp then + local reg = ovreg or tp.reg + if not reg then + werror("type `"..(tname or expr).."' needs a register override") + end + expr = reg + end + local r = match(expr, "^r(1?[0-9])$") + if r then + r = tonumber(r) + if r <= 15 then return r, tp end + end + werror("bad register name `"..expr.."'") +end + +local function parse_gpr_pm(expr) + local pm, expr2 = match(expr, "^([+-]?)(.*)$") + return parse_gpr(expr2), (pm == "-") +end + +local function parse_vr(expr, tp) + local t, r = match(expr, "^([sd])([0-9]+)$") + if t == tp then + r = tonumber(r) + if r <= 31 then + if t == "s" then return shr(r, 1), band(r, 1) end + return band(r, 15), shr(r, 4) + end + end + werror("bad register name `"..expr.."'") +end + +local function parse_reglist(reglist) + reglist = match(reglist, "^{%s*([^}]*)}$") + if not reglist then werror("register list expected") end + local rr = 0 + for p in gmatch(reglist..",", "%s*([^,]*),") do + local rbit = shl(1, parse_gpr(gsub(p, "%s+$", ""))) + if band(rr, rbit) ~= 0 then + werror("duplicate register `"..p.."'") + end + rr = rr + rbit + end + return rr +end + +local function parse_vrlist(reglist) + local ta, ra, tb, rb = match(reglist, + "^{%s*([sd])([0-9]+)%s*%-%s*([sd])([0-9]+)%s*}$") + ra, rb = tonumber(ra), tonumber(rb) + if ta and ta == tb and ra and rb and ra <= 31 and rb <= 31 and ra <= rb then + local nr = rb+1 - ra + if ta == "s" then + return shl(shr(ra,1),12)+shl(band(ra,1),22) + nr + else + return shl(band(ra,15),12)+shl(shr(ra,4),22) + nr*2 + 0x100 + end + end + werror("register list expected") +end + +local function parse_imm(imm, bits, shift, scale, signed) + imm = match(imm, "^#(.*)$") + if not imm then werror("expected immediate operand") end + local n = tonumber(imm) + if n then + local m = sar(n, scale) + if shl(m, scale) == n then + if signed then + local s = sar(m, bits-1) + if s == 0 then return shl(m, shift) + elseif s == -1 then return shl(m + shl(1, bits), shift) end + else + if sar(m, bits) == 0 then return shl(m, shift) end + end + end + werror("out of range immediate `"..imm.."'") + else + waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm) + return 0 + end +end + +local function parse_imm12(imm) + local n = tonumber(imm) + if n then + local m = band(n) + for i=0,-15,-1 do + if shr(m, 8) == 0 then return m + shl(band(i, 15), 8) end + m = ror(m, 2) + end + werror("out of range immediate `"..imm.."'") + else + waction("IMM12", 0, imm) + return 0 + end +end + +local function parse_imm16(imm) + imm = match(imm, "^#(.*)$") + if not imm then werror("expected immediate operand") end + local n = tonumber(imm) + if n then + if shr(n, 16) == 0 then return band(n, 0x0fff) + shl(band(n, 0xf000), 4) end + werror("out of range immediate `"..imm.."'") + else + waction("IMM16", 32*16, imm) + return 0 + end +end + +local function parse_imm_load(imm, ext) + local n = tonumber(imm) + if n then + if ext then + if n >= -255 and n <= 255 then + local up = 0x00800000 + if n < 0 then n = -n; up = 0 end + return shl(band(n, 0xf0), 4) + band(n, 0x0f) + up + end + else + if n >= -4095 and n <= 4095 then + if n >= 0 then return n+0x00800000 end + return -n + end + end + werror("out of range immediate `"..imm.."'") + else + waction(ext and "IMML8" or "IMML12", 32768 + shl(ext and 8 or 12, 5), imm) + return 0 + end +end + +local function parse_shift(shift, gprok) + if shift == "rrx" then + return 3 * 32 + else + local s, s2 = match(shift, "^(%S+)%s*(.*)$") + s = map_shift[s] + if not s then werror("expected shift operand") end + if sub(s2, 1, 1) == "#" then + return parse_imm(s2, 5, 7, 0, false) + shl(s, 5) + else + if not gprok then werror("expected immediate shift operand") end + return shl(parse_gpr(s2), 8) + shl(s, 5) + 16 + end + end +end + +local function parse_label(label, def) + local prefix = sub(label, 1, 2) + -- =>label (pc label reference) + if prefix == "=>" then + return "PC", 0, sub(label, 3) + end + -- ->name (global label reference) + if prefix == "->" then + return "LG", map_global[sub(label, 3)] + end + if def then + -- [1-9] (local label definition) + if match(label, "^[1-9]$") then + return "LG", 10+tonumber(label) + end + else + -- [<>][1-9] (local label reference) + local dir, lnum = match(label, "^([<>])([1-9])$") + if dir then -- Fwd: 1-9, Bkwd: 11-19. + return "LG", lnum + (dir == ">" and 0 or 10) + end + -- extern label (extern label reference) + local extname = match(label, "^extern%s+(%S+)$") + if extname then + return "EXT", map_extern[extname] + end + end + werror("bad label `"..label.."'") +end + +local function parse_load(params, nparams, n, op) + local oplo = band(op, 255) + local ext, ldrd = (oplo ~= 0), (oplo == 208) + local d + if (ldrd or oplo == 240) then + d = band(shr(op, 12), 15) + if band(d, 1) ~= 0 then werror("odd destination register") end + end + local pn = params[n] + local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$") + local p2 = params[n+1] + if not p1 then + if not p2 then + if match(pn, "^[<>=%-]") or match(pn, "^extern%s+") then + local mode, n, s = parse_label(pn, false) + waction("REL_"..mode, n + (ext and 0x1800 or 0x0800), s, 1) + return op + 15 * 65536 + 0x01000000 + (ext and 0x00400000 or 0) + end + local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$") + if reg and tailr ~= "" then + local d, tp = parse_gpr(reg) + if tp then + waction(ext and "IMML8" or "IMML12", 32768 + 32*(ext and 8 or 12), + format(tp.ctypefmt, tailr)) + return op + shl(d, 16) + 0x01000000 + (ext and 0x00400000 or 0) + end + end + end + werror("expected address operand") + end + if wb == "!" then op = op + 0x00200000 end + if p2 then + if wb == "!" then werror("bad use of '!'") end + local p3 = params[n+2] + op = op + shl(parse_gpr(p1), 16) + local imm = match(p2, "^#(.*)$") + if imm then + local m = parse_imm_load(imm, ext) + if p3 then werror("too many parameters") end + op = op + m + (ext and 0x00400000 or 0) + else + local m, neg = parse_gpr_pm(p2) + if ldrd and (m == d or m-1 == d) then werror("register conflict") end + op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000) + if p3 then op = op + parse_shift(p3) end + end + else + local p1a, p2 = match(p1, "^([^,%s]*)%s*(.*)$") + op = op + shl(parse_gpr(p1a), 16) + 0x01000000 + if p2 ~= "" then + local imm = match(p2, "^,%s*#(.*)$") + if imm then + local m = parse_imm_load(imm, ext) + op = op + m + (ext and 0x00400000 or 0) + else + local p2a, p3 = match(p2, "^,%s*([^,%s]*)%s*,?%s*(.*)$") + local m, neg = parse_gpr_pm(p2a) + if ldrd and (m == d or m-1 == d) then werror("register conflict") end + op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000) + if p3 ~= "" then + if ext then werror("too many parameters") end + op = op + parse_shift(p3) + end + end + else + if wb == "!" then werror("bad use of '!'") end + op = op + (ext and 0x00c00000 or 0x00800000) + end + end + return op +end + +local function parse_vload(q) + local reg, imm = match(q, "^%[%s*([^,%s]*)%s*(.*)%]$") + if reg then + local d = shl(parse_gpr(reg), 16) + if imm == "" then return d end + imm = match(imm, "^,%s*#(.*)$") + if imm then + local n = tonumber(imm) + if n then + if n >= -1020 and n <= 1020 and n%4 == 0 then + return d + (n >= 0 and n/4+0x00800000 or -n/4) + end + werror("out of range immediate `"..imm.."'") + else + waction("IMMV8", 32768 + 32*8, imm) + return d + end + end + else + if match(q, "^[<>=%-]") or match(q, "^extern%s+") then + local mode, n, s = parse_label(q, false) + waction("REL_"..mode, n + 0x2800, s, 1) + return 15 * 65536 + end + local reg, tailr = match(q, "^([%w_:]+)%s*(.*)$") + if reg and tailr ~= "" then + local d, tp = parse_gpr(reg) + if tp then + waction("IMMV8", 32768 + 32*8, format(tp.ctypefmt, tailr)) + return shl(d, 16) + end + end + end + werror("expected address operand") +end + +------------------------------------------------------------------------------ + +-- Handle opcodes defined with template strings. +local function parse_template(params, template, nparams, pos) + local op = tonumber(sub(template, 1, 8), 16) + local n = 1 + local vr = "s" + + -- Process each character. + for p in gmatch(sub(template, 9), ".") do + local q = params[n] + if p == "D" then + op = op + shl(parse_gpr(q), 12); n = n + 1 + elseif p == "N" then + op = op + shl(parse_gpr(q), 16); n = n + 1 + elseif p == "S" then + op = op + shl(parse_gpr(q), 8); n = n + 1 + elseif p == "M" then + op = op + parse_gpr(q); n = n + 1 + elseif p == "d" then + local r,h = parse_vr(q, vr); op = op+shl(r,12)+shl(h,22); n = n + 1 + elseif p == "n" then + local r,h = parse_vr(q, vr); op = op+shl(r,16)+shl(h,7); n = n + 1 + elseif p == "m" then + local r,h = parse_vr(q, vr); op = op+r+shl(h,5); n = n + 1 + elseif p == "P" then + local imm = match(q, "^#(.*)$") + if imm then + op = op + parse_imm12(imm) + 0x02000000 + else + op = op + parse_gpr(q) + end + n = n + 1 + elseif p == "p" then + op = op + parse_shift(q, true); n = n + 1 + elseif p == "L" then + op = parse_load(params, nparams, n, op) + elseif p == "l" then + op = op + parse_vload(q) + elseif p == "B" then + local mode, n, s = parse_label(q, false) + waction("REL_"..mode, n, s, 1) + elseif p == "C" then -- blx gpr vs. blx label. + if match(q, "^([%w_]+):(r1?[0-9])$") or match(q, "^r(1?[0-9])$") then + op = op + parse_gpr(q) + else + if op < 0xe0000000 then werror("unconditional instruction") end + local mode, n, s = parse_label(q, false) + waction("REL_"..mode, n, s, 1) + op = 0xfa000000 + end + elseif p == "F" then + vr = "s" + elseif p == "G" then + vr = "d" + elseif p == "o" then + local r, wb = match(q, "^([^!]*)(!?)$") + op = op + shl(parse_gpr(r), 16) + (wb == "!" and 0x00200000 or 0) + n = n + 1 + elseif p == "R" then + op = op + parse_reglist(q); n = n + 1 + elseif p == "r" then + op = op + parse_vrlist(q); n = n + 1 + elseif p == "W" then + op = op + parse_imm16(q); n = n + 1 + elseif p == "v" then + op = op + parse_imm(q, 5, 7, 0, false); n = n + 1 + elseif p == "w" then + local imm = match(q, "^#(.*)$") + if imm then + op = op + parse_imm(q, 5, 7, 0, false); n = n + 1 + else + op = op + shl(parse_gpr(q), 8) + 16 + end + elseif p == "X" then + op = op + parse_imm(q, 5, 16, 0, false); n = n + 1 + elseif p == "Y" then + local imm = tonumber(match(q, "^#(.*)$")); n = n + 1 + if not imm or shr(imm, 8) ~= 0 then + werror("bad immediate operand") + end + op = op + shl(band(imm, 0xf0), 12) + band(imm, 0x0f) + elseif p == "K" then + local imm = tonumber(match(q, "^#(.*)$")); n = n + 1 + if not imm or shr(imm, 16) ~= 0 then + werror("bad immediate operand") + end + op = op + shl(band(imm, 0xfff0), 4) + band(imm, 0x000f) + elseif p == "T" then + op = op + parse_imm(q, 24, 0, 0, false); n = n + 1 + elseif p == "s" then + -- Ignored. + else + assert(false) + end + end + wputpos(pos, op) +end + +map_op[".template__"] = function(params, template, nparams) + if not params then return sub(template, 9) end + + -- Limit number of section buffer positions used by a single dasm_put(). + -- A single opcode needs a maximum of 3 positions. + if secpos+3 > maxsecpos then wflush() end + local pos = wpos() + local apos, spos = #actargs, secpos + + local ok, err + for t in gmatch(template, "[^|]+") do + ok, err = pcall(parse_template, params, t, nparams, pos) + if ok then return end + secpos = spos + actargs[apos+1] = nil + actargs[apos+2] = nil + actargs[apos+3] = nil + end + error(err, 0) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode to mark the position where the action list is to be emitted. +map_op[".actionlist_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeactions(out, name) end) +end + +-- Pseudo-opcode to mark the position where the global enum is to be emitted. +map_op[".globals_1"] = function(params) + if not params then return "prefix" end + local prefix = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobals(out, prefix) end) +end + +-- Pseudo-opcode to mark the position where the global names are to be emitted. +map_op[".globalnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobalnames(out, name) end) +end + +-- Pseudo-opcode to mark the position where the extern names are to be emitted. +map_op[".externnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeexternnames(out, name) end) +end + +------------------------------------------------------------------------------ + +-- Label pseudo-opcode (converted from trailing colon form). +map_op[".label_1"] = function(params) + if not params then return "[1-9] | ->global | =>pcexpr" end + if secpos+1 > maxsecpos then wflush() end + local mode, n, s = parse_label(params[1], true) + if mode == "EXT" then werror("bad label definition") end + waction("LABEL_"..mode, n, s, 1) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcodes for data storage. +map_op[".long_*"] = function(params) + if not params then return "imm..." end + for _,p in ipairs(params) do + local n = tonumber(p) + if not n then werror("bad immediate `"..p.."'") end + if n < 0 then n = n + 2^32 end + wputw(n) + if secpos+2 > maxsecpos then wflush() end + end +end + +-- Alignment pseudo-opcode. +map_op[".align_1"] = function(params) + if not params then return "numpow2" end + if secpos+1 > maxsecpos then wflush() end + local align = tonumber(params[1]) + if align then + local x = align + -- Must be a power of 2 in the range (2 ... 256). + for i=1,8 do + x = x / 2 + if x == 1 then + waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1. + return + end + end + end + werror("bad alignment") +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode for (primitive) type definitions (map to C types). +map_op[".type_3"] = function(params, nparams) + if not params then + return nparams == 2 and "name, ctype" or "name, ctype, reg" + end + local name, ctype, reg = params[1], params[2], params[3] + if not match(name, "^[%a_][%w_]*$") then + werror("bad type name `"..name.."'") + end + local tp = map_type[name] + if tp then + werror("duplicate type `"..name.."'") + end + -- Add #type to defines. A bit unclean to put it in map_archdef. + map_archdef["#"..name] = "sizeof("..ctype..")" + -- Add new type and emit shortcut define. + local num = ctypenum + 1 + map_type[name] = { + ctype = ctype, + ctypefmt = format("Dt%X(%%s)", num), + reg = reg, + } + wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype)) + ctypenum = num +end +map_op[".type_2"] = map_op[".type_3"] + +-- Dump type definitions. +local function dumptypes(out, lvl) + local t = {} + for name in pairs(map_type) do t[#t+1] = name end + sort(t) + out:write("Type definitions:\n") + for _,name in ipairs(t) do + local tp = map_type[name] + local reg = tp.reg or "" + out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Set the current section. +function _M.section(num) + waction("SECTION", num) + wflush(true) -- SECTION is a terminal action. +end + +------------------------------------------------------------------------------ + +-- Dump architecture description. +function _M.dumparch(out) + out:write(format("DynASM %s version %s, released %s\n\n", + _info.arch, _info.version, _info.release)) + dumpactions(out) +end + +-- Dump all user defined elements. +function _M.dumpdef(out, lvl) + dumptypes(out, lvl) + dumpglobals(out, lvl) + dumpexterns(out, lvl) +end + +------------------------------------------------------------------------------ + +-- Pass callbacks from/to the DynASM core. +function _M.passcb(wl, we, wf, ww) + wline, werror, wfatal, wwarn = wl, we, wf, ww + return wflush +end + +-- Setup the arch-specific module. +function _M.setup(arch, opt) + g_arch, g_opt = arch, opt +end + +-- Merge the core maps and the arch-specific maps. +function _M.mergemaps(map_coreop, map_def) + setmetatable(map_op, { __index = function(t, k) + local v = map_coreop[k] + if v then return v end + local k1, cc, k2 = match(k, "^(.-)(..)([._].*)$") + local cv = map_cond[cc] + if cv then + local v = rawget(t, k1..k2) + if type(v) == "string" then + local scv = format("%x", cv) + return gsub(scv..sub(v, 2), "|e", "|"..scv) + end + end + end }) + setmetatable(map_def, { __index = map_archdef }) + return map_op, map_def +end + +return _M + +------------------------------------------------------------------------------ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.h b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.h new file mode 100644 index 0000000..4359588 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.h @@ -0,0 +1,416 @@ +/* +** DynASM MIPS encoding engine. +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** Released under the MIT license. See dynasm.lua for full copyright notice. +*/ + +#include +#include +#include +#include + +#define DASM_ARCH "mips" + +#ifndef DASM_EXTERN +#define DASM_EXTERN(a,b,c,d) 0 +#endif + +/* Action definitions. */ +enum { + DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT, + /* The following actions need a buffer position. */ + DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG, + /* The following actions also have an argument. */ + DASM_REL_PC, DASM_LABEL_PC, DASM_IMM, + DASM__MAX +}; + +/* Maximum number of section buffer positions for a single dasm_put() call. */ +#define DASM_MAXSECPOS 25 + +/* DynASM encoder status codes. Action list offset or number are or'ed in. */ +#define DASM_S_OK 0x00000000 +#define DASM_S_NOMEM 0x01000000 +#define DASM_S_PHASE 0x02000000 +#define DASM_S_MATCH_SEC 0x03000000 +#define DASM_S_RANGE_I 0x11000000 +#define DASM_S_RANGE_SEC 0x12000000 +#define DASM_S_RANGE_LG 0x13000000 +#define DASM_S_RANGE_PC 0x14000000 +#define DASM_S_RANGE_REL 0x15000000 +#define DASM_S_UNDEF_LG 0x21000000 +#define DASM_S_UNDEF_PC 0x22000000 + +/* Macros to convert positions (8 bit section + 24 bit index). */ +#define DASM_POS2IDX(pos) ((pos)&0x00ffffff) +#define DASM_POS2BIAS(pos) ((pos)&0xff000000) +#define DASM_SEC2POS(sec) ((sec)<<24) +#define DASM_POS2SEC(pos) ((pos)>>24) +#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos)) + +/* Action list type. */ +typedef const unsigned int *dasm_ActList; + +/* Per-section structure. */ +typedef struct dasm_Section { + int *rbuf; /* Biased buffer pointer (negative section bias). */ + int *buf; /* True buffer pointer. */ + size_t bsize; /* Buffer size in bytes. */ + int pos; /* Biased buffer position. */ + int epos; /* End of biased buffer position - max single put. */ + int ofs; /* Byte offset into section. */ +} dasm_Section; + +/* Core structure holding the DynASM encoding state. */ +struct dasm_State { + size_t psize; /* Allocated size of this structure. */ + dasm_ActList actionlist; /* Current actionlist pointer. */ + int *lglabels; /* Local/global chain/pos ptrs. */ + size_t lgsize; + int *pclabels; /* PC label chains/pos ptrs. */ + size_t pcsize; + void **globals; /* Array of globals (bias -10). */ + dasm_Section *section; /* Pointer to active section. */ + size_t codesize; /* Total size of all code sections. */ + int maxsection; /* 0 <= sectionidx < maxsection. */ + int status; /* Status code. */ + dasm_Section sections[1]; /* All sections. Alloc-extended. */ +}; + +/* The size of the core structure depends on the max. number of sections. */ +#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section)) + + +/* Initialize DynASM state. */ +void dasm_init(Dst_DECL, int maxsection) +{ + dasm_State *D; + size_t psz = 0; + int i; + Dst_REF = NULL; + DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); + D = Dst_REF; + D->psize = psz; + D->lglabels = NULL; + D->lgsize = 0; + D->pclabels = NULL; + D->pcsize = 0; + D->globals = NULL; + D->maxsection = maxsection; + for (i = 0; i < maxsection; i++) { + D->sections[i].buf = NULL; /* Need this for pass3. */ + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); + D->sections[i].bsize = 0; + D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ + } +} + +/* Free DynASM state. */ +void dasm_free(Dst_DECL) +{ + dasm_State *D = Dst_REF; + int i; + for (i = 0; i < D->maxsection; i++) + if (D->sections[i].buf) + DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); + if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); + if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); + DASM_M_FREE(Dst, D, D->psize); +} + +/* Setup global label array. Must be called before dasm_setup(). */ +void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) +{ + dasm_State *D = Dst_REF; + D->globals = gl - 10; /* Negative bias to compensate for locals. */ + DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); +} + +/* Grow PC label array. Can be called after dasm_setup(), too. */ +void dasm_growpc(Dst_DECL, unsigned int maxpc) +{ + dasm_State *D = Dst_REF; + size_t osz = D->pcsize; + DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); + memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz); +} + +/* Setup encoder. */ +void dasm_setup(Dst_DECL, const void *actionlist) +{ + dasm_State *D = Dst_REF; + int i; + D->actionlist = (dasm_ActList)actionlist; + D->status = DASM_S_OK; + D->section = &D->sections[0]; + memset((void *)D->lglabels, 0, D->lgsize); + if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); + for (i = 0; i < D->maxsection; i++) { + D->sections[i].pos = DASM_SEC2POS(i); + D->sections[i].ofs = 0; + } +} + + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) { \ + D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0) +#define CKPL(kind, st) \ + do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \ + D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0) +#else +#define CK(x, st) ((void)0) +#define CKPL(kind, st) ((void)0) +#endif + +/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */ +void dasm_put(Dst_DECL, int start, ...) +{ + va_list ap; + dasm_State *D = Dst_REF; + dasm_ActList p = D->actionlist + start; + dasm_Section *sec = D->section; + int pos = sec->pos, ofs = sec->ofs; + int *b; + + if (pos >= sec->epos) { + DASM_M_GROW(Dst, int, sec->buf, sec->bsize, + sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); + sec->rbuf = sec->buf - DASM_POS2BIAS(pos); + sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos); + } + + b = sec->rbuf; + b[pos++] = start; + + va_start(ap, start); + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16) - 0xff00; + if (action >= DASM__MAX) { + ofs += 4; + } else { + int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0; + switch (action) { + case DASM_STOP: goto stop; + case DASM_SECTION: + n = (ins & 255); CK(n < D->maxsection, RANGE_SEC); + D->section = &D->sections[n]; goto stop; + case DASM_ESC: p++; ofs += 4; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break; + case DASM_REL_LG: + n = (ins & 2047) - 10; pl = D->lglabels + n; + /* Bkwd rel or global. */ + if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; } + pl += 10; n = *pl; + if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ + goto linkrel; + case DASM_REL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putrel: + n = *pl; + if (n < 0) { /* Label exists. Get label pos and store it. */ + b[pos] = -n; + } else { + linkrel: + b[pos] = n; /* Else link to rel chain, anchored at label. */ + *pl = pos; + } + pos++; + break; + case DASM_LABEL_LG: + pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel; + case DASM_LABEL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putlabel: + n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; + } + *pl = -pos; /* Label exists now. */ + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_IMM: +#ifdef DASM_CHECKS + CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I); +#endif + n >>= ((ins>>10)&31); +#ifdef DASM_CHECKS + if (ins & 0x8000) + CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I); + else + CK((n>>((ins>>5)&31)) == 0, RANGE_I); +#endif + b[pos++] = n; + break; + } + } + } +stop: + va_end(ap); + sec->pos = pos; + sec->ofs = ofs; +} +#undef CK + +/* Pass 2: Link sections, shrink aligns, fix label offsets. */ +int dasm_link(Dst_DECL, size_t *szp) +{ + dasm_State *D = Dst_REF; + int secnum; + int ofs = 0; + +#ifdef DASM_CHECKS + *szp = 0; + if (D->status != DASM_S_OK) return D->status; + { + int pc; + for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) + if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc; + } +#endif + + { /* Handle globals not defined in this translation unit. */ + int idx; + for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { + int n = D->lglabels[idx]; + /* Undefined label: Collapse rel chain and replace with marker (< 0). */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } + } + } + + /* Combine all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->rbuf; + int pos = DASM_SEC2POS(secnum); + int lastpos = sec->pos; + + while (pos != lastpos) { + dasm_ActList p = D->actionlist + b[pos++]; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16) - 0xff00; + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: p++; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break; + case DASM_REL_LG: case DASM_REL_PC: pos++; break; + case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break; + case DASM_IMM: pos++; break; + } + } + stop: (void)0; + } + ofs += sec->ofs; /* Next section starts right after current section. */ + } + + D->codesize = ofs; /* Total size of all code sections */ + *szp = ofs; + return DASM_S_OK; +} + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0) +#else +#define CK(x, st) ((void)0) +#endif + +/* Pass 3: Encode sections. */ +int dasm_encode(Dst_DECL, void *buffer) +{ + dasm_State *D = Dst_REF; + char *base = (char *)buffer; + unsigned int *cp = (unsigned int *)buffer; + int secnum; + + /* Encode all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->buf; + int *endb = sec->rbuf + sec->pos; + + while (b != endb) { + dasm_ActList p = D->actionlist + *b++; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16) - 0xff00; + int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0; + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: *cp++ = *p++; break; + case DASM_REL_EXT: + n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1); + goto patchrel; + case DASM_ALIGN: + ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000; + break; + case DASM_REL_LG: + CK(n >= 0, UNDEF_LG); + case DASM_REL_PC: + CK(n >= 0, UNDEF_PC); + n = *DASM_POS2PTR(D, n); + if (ins & 2048) + n = n - (int)((char *)cp - base); + else + n = (n + (int)base) & 0x0fffffff; + patchrel: + CK((n & 3) == 0 && + ((n + ((ins & 2048) ? 0x00020000 : 0)) >> + ((ins & 2048) ? 18 : 28)) == 0, RANGE_REL); + cp[-1] |= ((n>>2) & ((ins & 2048) ? 0x0000ffff: 0x03ffffff)); + break; + case DASM_LABEL_LG: + ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + break; + case DASM_LABEL_PC: break; + case DASM_IMM: + cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31); + break; + default: *cp++ = ins; break; + } + } + stop: (void)0; + } + } + + if (base + D->codesize != (char *)cp) /* Check for phase errors. */ + return DASM_S_PHASE; + return DASM_S_OK; +} +#undef CK + +/* Get PC label offset. */ +int dasm_getpclabel(Dst_DECL, unsigned int pc) +{ + dasm_State *D = Dst_REF; + if (pc*sizeof(int) < D->pcsize) { + int pos = D->pclabels[pc]; + if (pos < 0) return *DASM_POS2PTR(D, -pos); + if (pos > 0) return -1; /* Undefined. */ + } + return -2; /* Unused or out of range. */ +} + +#ifdef DASM_CHECKS +/* Optional sanity checker to call between isolated encoding steps. */ +int dasm_checkstep(Dst_DECL, int secmatch) +{ + dasm_State *D = Dst_REF; + if (D->status == DASM_S_OK) { + int i; + for (i = 1; i <= 9; i++) { + if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; } + D->lglabels[i] = 0; + } + } + if (D->status == DASM_S_OK && secmatch >= 0 && + D->section != &D->sections[secmatch]) + D->status = DASM_S_MATCH_SEC|(D->section-D->sections); + return D->status; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.lua new file mode 100644 index 0000000..82942cb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_mips.lua @@ -0,0 +1,953 @@ +------------------------------------------------------------------------------ +-- DynASM MIPS module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See dynasm.lua for full copyright notice. +------------------------------------------------------------------------------ + +-- Module information: +local _info = { + arch = "mips", + description = "DynASM MIPS module", + version = "1.3.0", + vernum = 10300, + release = "2012-01-23", + author = "Mike Pall", + license = "MIT", +} + +-- Exported glue functions for the arch-specific module. +local _M = { _info = _info } + +-- Cache library functions. +local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs +local assert, setmetatable = assert, setmetatable +local _s = string +local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char +local match, gmatch = _s.match, _s.gmatch +local concat, sort = table.concat, table.sort +local bit = bit or require("bit") +local band, shl, sar, tohex = bit.band, bit.lshift, bit.arshift, bit.tohex + +-- Inherited tables and callbacks. +local g_opt, g_arch +local wline, werror, wfatal, wwarn + +-- Action name list. +-- CHECK: Keep this in sync with the C code! +local action_names = { + "STOP", "SECTION", "ESC", "REL_EXT", + "ALIGN", "REL_LG", "LABEL_LG", + "REL_PC", "LABEL_PC", "IMM", +} + +-- Maximum number of section buffer positions for dasm_put(). +-- CHECK: Keep this in sync with the C code! +local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines. + +-- Action name -> action number. +local map_action = {} +for n,name in ipairs(action_names) do + map_action[name] = n-1 +end + +-- Action list buffer. +local actlist = {} + +-- Argument list for next dasm_put(). Start with offset 0 into action list. +local actargs = { 0 } + +-- Current number of section buffer positions for dasm_put(). +local secpos = 1 + +------------------------------------------------------------------------------ + +-- Dump action names and numbers. +local function dumpactions(out) + out:write("DynASM encoding engine action codes:\n") + for n,name in ipairs(action_names) do + local num = map_action[name] + out:write(format(" %-10s %02X %d\n", name, num, num)) + end + out:write("\n") +end + +-- Write action list buffer as a huge static C array. +local function writeactions(out, name) + local nn = #actlist + if nn == 0 then nn = 1; actlist[0] = map_action.STOP end + out:write("static const unsigned int ", name, "[", nn, "] = {\n") + for i = 1,nn-1 do + assert(out:write("0x", tohex(actlist[i]), ",\n")) + end + assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n")) +end + +------------------------------------------------------------------------------ + +-- Add word to action list. +local function wputxw(n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + actlist[#actlist+1] = n +end + +-- Add action to list with optional arg. Advance buffer pos, too. +local function waction(action, val, a, num) + local w = assert(map_action[action], "bad action name `"..action.."'") + wputxw(0xff000000 + w * 0x10000 + (val or 0)) + if a then actargs[#actargs+1] = a end + if a or num then secpos = secpos + (num or 1) end +end + +-- Flush action list (intervening C code or buffer pos overflow). +local function wflush(term) + if #actlist == actargs[1] then return end -- Nothing to flush. + if not term then waction("STOP") end -- Terminate action list. + wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true) + actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put(). + secpos = 1 -- The actionlist offset occupies a buffer position, too. +end + +-- Put escaped word. +local function wputw(n) + if n >= 0xff000000 then waction("ESC") end + wputxw(n) +end + +-- Reserve position for word. +local function wpos() + local pos = #actlist+1 + actlist[pos] = "" + return pos +end + +-- Store word to reserved position. +local function wputpos(pos, n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + actlist[pos] = n +end + +------------------------------------------------------------------------------ + +-- Global label name -> global label number. With auto assignment on 1st use. +local next_global = 20 +local map_global = setmetatable({}, { __index = function(t, name) + if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end + local n = next_global + if n > 2047 then werror("too many global labels") end + next_global = n + 1 + t[name] = n + return n +end}) + +-- Dump global labels. +local function dumpglobals(out, lvl) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("Global labels:\n") + for i=20,next_global-1 do + out:write(format(" %s\n", t[i])) + end + out:write("\n") +end + +-- Write global label enum. +local function writeglobals(out, prefix) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("enum {\n") + for i=20,next_global-1 do + out:write(" ", prefix, t[i], ",\n") + end + out:write(" ", prefix, "_MAX\n};\n") +end + +-- Write global label names. +local function writeglobalnames(out, name) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("static const char *const ", name, "[] = {\n") + for i=20,next_global-1 do + out:write(" \"", t[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Extern label name -> extern label number. With auto assignment on 1st use. +local next_extern = 0 +local map_extern_ = {} +local map_extern = setmetatable({}, { __index = function(t, name) + -- No restrictions on the name for now. + local n = next_extern + if n > 2047 then werror("too many extern labels") end + next_extern = n + 1 + t[name] = n + map_extern_[n] = name + return n +end}) + +-- Dump extern labels. +local function dumpexterns(out, lvl) + out:write("Extern labels:\n") + for i=0,next_extern-1 do + out:write(format(" %s\n", map_extern_[i])) + end + out:write("\n") +end + +-- Write extern label names. +local function writeexternnames(out, name) + out:write("static const char *const ", name, "[] = {\n") + for i=0,next_extern-1 do + out:write(" \"", map_extern_[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Arch-specific maps. +local map_archdef = { sp="r29", ra="r31" } -- Ext. register name -> int. name. + +local map_type = {} -- Type name -> { ctype, reg } +local ctypenum = 0 -- Type number (for Dt... macros). + +-- Reverse defines for registers. +function _M.revdef(s) + if s == "r29" then return "sp" + elseif s == "r31" then return "ra" end + return s +end + +------------------------------------------------------------------------------ + +-- Template strings for MIPS instructions. +local map_op = { + -- First-level opcodes. + j_1 = "08000000J", + jal_1 = "0c000000J", + b_1 = "10000000B", + beqz_2 = "10000000SB", + beq_3 = "10000000STB", + bnez_2 = "14000000SB", + bne_3 = "14000000STB", + blez_2 = "18000000SB", + bgtz_2 = "1c000000SB", + addi_3 = "20000000TSI", + li_2 = "24000000TI", + addiu_3 = "24000000TSI", + slti_3 = "28000000TSI", + sltiu_3 = "2c000000TSI", + andi_3 = "30000000TSU", + lu_2 = "34000000TU", + ori_3 = "34000000TSU", + xori_3 = "38000000TSU", + lui_2 = "3c000000TU", + beqzl_2 = "50000000SB", + beql_3 = "50000000STB", + bnezl_2 = "54000000SB", + bnel_3 = "54000000STB", + blezl_2 = "58000000SB", + bgtzl_2 = "5c000000SB", + lb_2 = "80000000TO", + lh_2 = "84000000TO", + lwl_2 = "88000000TO", + lw_2 = "8c000000TO", + lbu_2 = "90000000TO", + lhu_2 = "94000000TO", + lwr_2 = "98000000TO", + sb_2 = "a0000000TO", + sh_2 = "a4000000TO", + swl_2 = "a8000000TO", + sw_2 = "ac000000TO", + swr_2 = "b8000000TO", + cache_2 = "bc000000NO", + ll_2 = "c0000000TO", + lwc1_2 = "c4000000HO", + pref_2 = "cc000000NO", + ldc1_2 = "d4000000HO", + sc_2 = "e0000000TO", + swc1_2 = "e4000000HO", + sdc1_2 = "f4000000HO", + + -- Opcode SPECIAL. + nop_0 = "00000000", + sll_3 = "00000000DTA", + movf_2 = "00000001DS", + movf_3 = "00000001DSC", + movt_2 = "00010001DS", + movt_3 = "00010001DSC", + srl_3 = "00000002DTA", + rotr_3 = "00200002DTA", + sra_3 = "00000003DTA", + sllv_3 = "00000004DTS", + srlv_3 = "00000006DTS", + rotrv_3 = "00000046DTS", + srav_3 = "00000007DTS", + jr_1 = "00000008S", + jalr_1 = "0000f809S", + jalr_2 = "00000009DS", + movz_3 = "0000000aDST", + movn_3 = "0000000bDST", + syscall_0 = "0000000c", + syscall_1 = "0000000cY", + break_0 = "0000000d", + break_1 = "0000000dY", + sync_0 = "0000000f", + mfhi_1 = "00000010D", + mthi_1 = "00000011S", + mflo_1 = "00000012D", + mtlo_1 = "00000013S", + mult_2 = "00000018ST", + multu_2 = "00000019ST", + div_2 = "0000001aST", + divu_2 = "0000001bST", + add_3 = "00000020DST", + move_2 = "00000021DS", + addu_3 = "00000021DST", + sub_3 = "00000022DST", + negu_2 = "00000023DT", + subu_3 = "00000023DST", + and_3 = "00000024DST", + or_3 = "00000025DST", + xor_3 = "00000026DST", + not_2 = "00000027DS", + nor_3 = "00000027DST", + slt_3 = "0000002aDST", + sltu_3 = "0000002bDST", + tge_2 = "00000030ST", + tge_3 = "00000030STZ", + tgeu_2 = "00000031ST", + tgeu_3 = "00000031STZ", + tlt_2 = "00000032ST", + tlt_3 = "00000032STZ", + tltu_2 = "00000033ST", + tltu_3 = "00000033STZ", + teq_2 = "00000034ST", + teq_3 = "00000034STZ", + tne_2 = "00000036ST", + tne_3 = "00000036STZ", + + -- Opcode REGIMM. + bltz_2 = "04000000SB", + bgez_2 = "04010000SB", + bltzl_2 = "04020000SB", + bgezl_2 = "04030000SB", + tgei_2 = "04080000SI", + tgeiu_2 = "04090000SI", + tlti_2 = "040a0000SI", + tltiu_2 = "040b0000SI", + teqi_2 = "040c0000SI", + tnei_2 = "040e0000SI", + bltzal_2 = "04100000SB", + bal_1 = "04110000B", + bgezal_2 = "04110000SB", + bltzall_2 = "04120000SB", + bgezall_2 = "04130000SB", + synci_1 = "041f0000O", + + -- Opcode SPECIAL2. + madd_2 = "70000000ST", + maddu_2 = "70000001ST", + mul_3 = "70000002DST", + msub_2 = "70000004ST", + msubu_2 = "70000005ST", + clz_2 = "70000020DS=", + clo_2 = "70000021DS=", + sdbbp_0 = "7000003f", + sdbbp_1 = "7000003fY", + + -- Opcode SPECIAL3. + ext_4 = "7c000000TSAM", -- Note: last arg is msbd = size-1 + ins_4 = "7c000004TSAM", -- Note: last arg is msb = pos+size-1 + wsbh_2 = "7c0000a0DT", + seb_2 = "7c000420DT", + seh_2 = "7c000620DT", + rdhwr_2 = "7c00003bTD", + + -- Opcode COP0. + mfc0_2 = "40000000TD", + mfc0_3 = "40000000TDW", + mtc0_2 = "40800000TD", + mtc0_3 = "40800000TDW", + rdpgpr_2 = "41400000DT", + di_0 = "41606000", + di_1 = "41606000T", + ei_0 = "41606020", + ei_1 = "41606020T", + wrpgpr_2 = "41c00000DT", + tlbr_0 = "42000001", + tlbwi_0 = "42000002", + tlbwr_0 = "42000006", + tlbp_0 = "42000008", + eret_0 = "42000018", + deret_0 = "4200001f", + wait_0 = "42000020", + + -- Opcode COP1. + mfc1_2 = "44000000TG", + cfc1_2 = "44400000TG", + mfhc1_2 = "44600000TG", + mtc1_2 = "44800000TG", + ctc1_2 = "44c00000TG", + mthc1_2 = "44e00000TG", + + bc1f_1 = "45000000B", + bc1f_2 = "45000000CB", + bc1t_1 = "45010000B", + bc1t_2 = "45010000CB", + bc1fl_1 = "45020000B", + bc1fl_2 = "45020000CB", + bc1tl_1 = "45030000B", + bc1tl_2 = "45030000CB", + + ["add.s_3"] = "46000000FGH", + ["sub.s_3"] = "46000001FGH", + ["mul.s_3"] = "46000002FGH", + ["div.s_3"] = "46000003FGH", + ["sqrt.s_2"] = "46000004FG", + ["abs.s_2"] = "46000005FG", + ["mov.s_2"] = "46000006FG", + ["neg.s_2"] = "46000007FG", + ["round.l.s_2"] = "46000008FG", + ["trunc.l.s_2"] = "46000009FG", + ["ceil.l.s_2"] = "4600000aFG", + ["floor.l.s_2"] = "4600000bFG", + ["round.w.s_2"] = "4600000cFG", + ["trunc.w.s_2"] = "4600000dFG", + ["ceil.w.s_2"] = "4600000eFG", + ["floor.w.s_2"] = "4600000fFG", + ["movf.s_2"] = "46000011FG", + ["movf.s_3"] = "46000011FGC", + ["movt.s_2"] = "46010011FG", + ["movt.s_3"] = "46010011FGC", + ["movz.s_3"] = "46000012FGT", + ["movn.s_3"] = "46000013FGT", + ["recip.s_2"] = "46000015FG", + ["rsqrt.s_2"] = "46000016FG", + ["cvt.d.s_2"] = "46000021FG", + ["cvt.w.s_2"] = "46000024FG", + ["cvt.l.s_2"] = "46000025FG", + ["cvt.ps.s_3"] = "46000026FGH", + ["c.f.s_2"] = "46000030GH", + ["c.f.s_3"] = "46000030VGH", + ["c.un.s_2"] = "46000031GH", + ["c.un.s_3"] = "46000031VGH", + ["c.eq.s_2"] = "46000032GH", + ["c.eq.s_3"] = "46000032VGH", + ["c.ueq.s_2"] = "46000033GH", + ["c.ueq.s_3"] = "46000033VGH", + ["c.olt.s_2"] = "46000034GH", + ["c.olt.s_3"] = "46000034VGH", + ["c.ult.s_2"] = "46000035GH", + ["c.ult.s_3"] = "46000035VGH", + ["c.ole.s_2"] = "46000036GH", + ["c.ole.s_3"] = "46000036VGH", + ["c.ule.s_2"] = "46000037GH", + ["c.ule.s_3"] = "46000037VGH", + ["c.sf.s_2"] = "46000038GH", + ["c.sf.s_3"] = "46000038VGH", + ["c.ngle.s_2"] = "46000039GH", + ["c.ngle.s_3"] = "46000039VGH", + ["c.seq.s_2"] = "4600003aGH", + ["c.seq.s_3"] = "4600003aVGH", + ["c.ngl.s_2"] = "4600003bGH", + ["c.ngl.s_3"] = "4600003bVGH", + ["c.lt.s_2"] = "4600003cGH", + ["c.lt.s_3"] = "4600003cVGH", + ["c.nge.s_2"] = "4600003dGH", + ["c.nge.s_3"] = "4600003dVGH", + ["c.le.s_2"] = "4600003eGH", + ["c.le.s_3"] = "4600003eVGH", + ["c.ngt.s_2"] = "4600003fGH", + ["c.ngt.s_3"] = "4600003fVGH", + + ["add.d_3"] = "46200000FGH", + ["sub.d_3"] = "46200001FGH", + ["mul.d_3"] = "46200002FGH", + ["div.d_3"] = "46200003FGH", + ["sqrt.d_2"] = "46200004FG", + ["abs.d_2"] = "46200005FG", + ["mov.d_2"] = "46200006FG", + ["neg.d_2"] = "46200007FG", + ["round.l.d_2"] = "46200008FG", + ["trunc.l.d_2"] = "46200009FG", + ["ceil.l.d_2"] = "4620000aFG", + ["floor.l.d_2"] = "4620000bFG", + ["round.w.d_2"] = "4620000cFG", + ["trunc.w.d_2"] = "4620000dFG", + ["ceil.w.d_2"] = "4620000eFG", + ["floor.w.d_2"] = "4620000fFG", + ["movf.d_2"] = "46200011FG", + ["movf.d_3"] = "46200011FGC", + ["movt.d_2"] = "46210011FG", + ["movt.d_3"] = "46210011FGC", + ["movz.d_3"] = "46200012FGT", + ["movn.d_3"] = "46200013FGT", + ["recip.d_2"] = "46200015FG", + ["rsqrt.d_2"] = "46200016FG", + ["cvt.s.d_2"] = "46200020FG", + ["cvt.w.d_2"] = "46200024FG", + ["cvt.l.d_2"] = "46200025FG", + ["c.f.d_2"] = "46200030GH", + ["c.f.d_3"] = "46200030VGH", + ["c.un.d_2"] = "46200031GH", + ["c.un.d_3"] = "46200031VGH", + ["c.eq.d_2"] = "46200032GH", + ["c.eq.d_3"] = "46200032VGH", + ["c.ueq.d_2"] = "46200033GH", + ["c.ueq.d_3"] = "46200033VGH", + ["c.olt.d_2"] = "46200034GH", + ["c.olt.d_3"] = "46200034VGH", + ["c.ult.d_2"] = "46200035GH", + ["c.ult.d_3"] = "46200035VGH", + ["c.ole.d_2"] = "46200036GH", + ["c.ole.d_3"] = "46200036VGH", + ["c.ule.d_2"] = "46200037GH", + ["c.ule.d_3"] = "46200037VGH", + ["c.sf.d_2"] = "46200038GH", + ["c.sf.d_3"] = "46200038VGH", + ["c.ngle.d_2"] = "46200039GH", + ["c.ngle.d_3"] = "46200039VGH", + ["c.seq.d_2"] = "4620003aGH", + ["c.seq.d_3"] = "4620003aVGH", + ["c.ngl.d_2"] = "4620003bGH", + ["c.ngl.d_3"] = "4620003bVGH", + ["c.lt.d_2"] = "4620003cGH", + ["c.lt.d_3"] = "4620003cVGH", + ["c.nge.d_2"] = "4620003dGH", + ["c.nge.d_3"] = "4620003dVGH", + ["c.le.d_2"] = "4620003eGH", + ["c.le.d_3"] = "4620003eVGH", + ["c.ngt.d_2"] = "4620003fGH", + ["c.ngt.d_3"] = "4620003fVGH", + + ["add.ps_3"] = "46c00000FGH", + ["sub.ps_3"] = "46c00001FGH", + ["mul.ps_3"] = "46c00002FGH", + ["abs.ps_2"] = "46c00005FG", + ["mov.ps_2"] = "46c00006FG", + ["neg.ps_2"] = "46c00007FG", + ["movf.ps_2"] = "46c00011FG", + ["movf.ps_3"] = "46c00011FGC", + ["movt.ps_2"] = "46c10011FG", + ["movt.ps_3"] = "46c10011FGC", + ["movz.ps_3"] = "46c00012FGT", + ["movn.ps_3"] = "46c00013FGT", + ["cvt.s.pu_2"] = "46c00020FG", + ["cvt.s.pl_2"] = "46c00028FG", + ["pll.ps_3"] = "46c0002cFGH", + ["plu.ps_3"] = "46c0002dFGH", + ["pul.ps_3"] = "46c0002eFGH", + ["puu.ps_3"] = "46c0002fFGH", + ["c.f.ps_2"] = "46c00030GH", + ["c.f.ps_3"] = "46c00030VGH", + ["c.un.ps_2"] = "46c00031GH", + ["c.un.ps_3"] = "46c00031VGH", + ["c.eq.ps_2"] = "46c00032GH", + ["c.eq.ps_3"] = "46c00032VGH", + ["c.ueq.ps_2"] = "46c00033GH", + ["c.ueq.ps_3"] = "46c00033VGH", + ["c.olt.ps_2"] = "46c00034GH", + ["c.olt.ps_3"] = "46c00034VGH", + ["c.ult.ps_2"] = "46c00035GH", + ["c.ult.ps_3"] = "46c00035VGH", + ["c.ole.ps_2"] = "46c00036GH", + ["c.ole.ps_3"] = "46c00036VGH", + ["c.ule.ps_2"] = "46c00037GH", + ["c.ule.ps_3"] = "46c00037VGH", + ["c.sf.ps_2"] = "46c00038GH", + ["c.sf.ps_3"] = "46c00038VGH", + ["c.ngle.ps_2"] = "46c00039GH", + ["c.ngle.ps_3"] = "46c00039VGH", + ["c.seq.ps_2"] = "46c0003aGH", + ["c.seq.ps_3"] = "46c0003aVGH", + ["c.ngl.ps_2"] = "46c0003bGH", + ["c.ngl.ps_3"] = "46c0003bVGH", + ["c.lt.ps_2"] = "46c0003cGH", + ["c.lt.ps_3"] = "46c0003cVGH", + ["c.nge.ps_2"] = "46c0003dGH", + ["c.nge.ps_3"] = "46c0003dVGH", + ["c.le.ps_2"] = "46c0003eGH", + ["c.le.ps_3"] = "46c0003eVGH", + ["c.ngt.ps_2"] = "46c0003fGH", + ["c.ngt.ps_3"] = "46c0003fVGH", + + ["cvt.s.w_2"] = "46800020FG", + ["cvt.d.w_2"] = "46800021FG", + + ["cvt.s.l_2"] = "46a00020FG", + ["cvt.d.l_2"] = "46a00021FG", + + -- Opcode COP1X. + lwxc1_2 = "4c000000FX", + ldxc1_2 = "4c000001FX", + luxc1_2 = "4c000005FX", + swxc1_2 = "4c000008FX", + sdxc1_2 = "4c000009FX", + suxc1_2 = "4c00000dFX", + prefx_2 = "4c00000fMX", + ["alnv.ps_4"] = "4c00001eFGHS", + ["madd.s_4"] = "4c000020FRGH", + ["madd.d_4"] = "4c000021FRGH", + ["madd.ps_4"] = "4c000026FRGH", + ["msub.s_4"] = "4c000028FRGH", + ["msub.d_4"] = "4c000029FRGH", + ["msub.ps_4"] = "4c00002eFRGH", + ["nmadd.s_4"] = "4c000030FRGH", + ["nmadd.d_4"] = "4c000031FRGH", + ["nmadd.ps_4"] = "4c000036FRGH", + ["nmsub.s_4"] = "4c000038FRGH", + ["nmsub.d_4"] = "4c000039FRGH", + ["nmsub.ps_4"] = "4c00003eFRGH", +} + +------------------------------------------------------------------------------ + +local function parse_gpr(expr) + local tname, ovreg = match(expr, "^([%w_]+):(r[1-3]?[0-9])$") + local tp = map_type[tname or expr] + if tp then + local reg = ovreg or tp.reg + if not reg then + werror("type `"..(tname or expr).."' needs a register override") + end + expr = reg + end + local r = match(expr, "^r([1-3]?[0-9])$") + if r then + r = tonumber(r) + if r <= 31 then return r, tp end + end + werror("bad register name `"..expr.."'") +end + +local function parse_fpr(expr) + local r = match(expr, "^f([1-3]?[0-9])$") + if r then + r = tonumber(r) + if r <= 31 then return r end + end + werror("bad register name `"..expr.."'") +end + +local function parse_imm(imm, bits, shift, scale, signed) + local n = tonumber(imm) + if n then + local m = sar(n, scale) + if shl(m, scale) == n then + if signed then + local s = sar(m, bits-1) + if s == 0 then return shl(m, shift) + elseif s == -1 then return shl(m + shl(1, bits), shift) end + else + if sar(m, bits) == 0 then return shl(m, shift) end + end + end + werror("out of range immediate `"..imm.."'") + elseif match(imm, "^[rf]([1-3]?[0-9])$") or + match(imm, "^([%w_]+):([rf][1-3]?[0-9])$") then + werror("expected immediate operand, got register") + else + waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm) + return 0 + end +end + +local function parse_disp(disp) + local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$") + if imm then + local r = shl(parse_gpr(reg), 21) + local extname = match(imm, "^extern%s+(%S+)$") + if extname then + waction("REL_EXT", map_extern[extname], nil, 1) + return r + else + return r + parse_imm(imm, 16, 0, 0, true) + end + end + local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$") + if reg and tailr ~= "" then + local r, tp = parse_gpr(reg) + if tp then + waction("IMM", 32768+16*32, format(tp.ctypefmt, tailr)) + return shl(r, 21) + end + end + werror("bad displacement `"..disp.."'") +end + +local function parse_index(idx) + local rt, rs = match(idx, "^(.*)%(([%w_:]+)%)$") + if rt then + rt = parse_gpr(rt) + rs = parse_gpr(rs) + return shl(rt, 16) + shl(rs, 21) + end + werror("bad index `"..idx.."'") +end + +local function parse_label(label, def) + local prefix = sub(label, 1, 2) + -- =>label (pc label reference) + if prefix == "=>" then + return "PC", 0, sub(label, 3) + end + -- ->name (global label reference) + if prefix == "->" then + return "LG", map_global[sub(label, 3)] + end + if def then + -- [1-9] (local label definition) + if match(label, "^[1-9]$") then + return "LG", 10+tonumber(label) + end + else + -- [<>][1-9] (local label reference) + local dir, lnum = match(label, "^([<>])([1-9])$") + if dir then -- Fwd: 1-9, Bkwd: 11-19. + return "LG", lnum + (dir == ">" and 0 or 10) + end + -- extern label (extern label reference) + local extname = match(label, "^extern%s+(%S+)$") + if extname then + return "EXT", map_extern[extname] + end + end + werror("bad label `"..label.."'") +end + +------------------------------------------------------------------------------ + +-- Handle opcodes defined with template strings. +map_op[".template__"] = function(params, template, nparams) + if not params then return sub(template, 9) end + local op = tonumber(sub(template, 1, 8), 16) + local n = 1 + + -- Limit number of section buffer positions used by a single dasm_put(). + -- A single opcode needs a maximum of 2 positions (ins/ext). + if secpos+2 > maxsecpos then wflush() end + local pos = wpos() + + -- Process each character. + for p in gmatch(sub(template, 9), ".") do + if p == "D" then + op = op + shl(parse_gpr(params[n]), 11); n = n + 1 + elseif p == "T" then + op = op + shl(parse_gpr(params[n]), 16); n = n + 1 + elseif p == "S" then + op = op + shl(parse_gpr(params[n]), 21); n = n + 1 + elseif p == "F" then + op = op + shl(parse_fpr(params[n]), 6); n = n + 1 + elseif p == "G" then + op = op + shl(parse_fpr(params[n]), 11); n = n + 1 + elseif p == "H" then + op = op + shl(parse_fpr(params[n]), 16); n = n + 1 + elseif p == "R" then + op = op + shl(parse_fpr(params[n]), 21); n = n + 1 + elseif p == "I" then + op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1 + elseif p == "U" then + op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1 + elseif p == "O" then + op = op + parse_disp(params[n]); n = n + 1 + elseif p == "X" then + op = op + parse_index(params[n]); n = n + 1 + elseif p == "B" or p == "J" then + local mode, n, s = parse_label(params[n], false) + if p == "B" then n = n + 2048 end + waction("REL_"..mode, n, s, 1) + n = n + 1 + elseif p == "A" then + op = op + parse_imm(params[n], 5, 6, 0, false); n = n + 1 + elseif p == "M" then + op = op + parse_imm(params[n], 5, 11, 0, false); n = n + 1 + elseif p == "N" then + op = op + parse_imm(params[n], 5, 16, 0, false); n = n + 1 + elseif p == "C" then + op = op + parse_imm(params[n], 3, 18, 0, false); n = n + 1 + elseif p == "V" then + op = op + parse_imm(params[n], 3, 8, 0, false); n = n + 1 + elseif p == "W" then + op = op + parse_imm(params[n], 3, 0, 0, false); n = n + 1 + elseif p == "Y" then + op = op + parse_imm(params[n], 20, 6, 0, false); n = n + 1 + elseif p == "Z" then + op = op + parse_imm(params[n], 10, 6, 0, false); n = n + 1 + elseif p == "=" then + op = op + shl(band(op, 0xf800), 5) -- Copy D to T for clz, clo. + else + assert(false) + end + end + wputpos(pos, op) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode to mark the position where the action list is to be emitted. +map_op[".actionlist_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeactions(out, name) end) +end + +-- Pseudo-opcode to mark the position where the global enum is to be emitted. +map_op[".globals_1"] = function(params) + if not params then return "prefix" end + local prefix = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobals(out, prefix) end) +end + +-- Pseudo-opcode to mark the position where the global names are to be emitted. +map_op[".globalnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobalnames(out, name) end) +end + +-- Pseudo-opcode to mark the position where the extern names are to be emitted. +map_op[".externnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeexternnames(out, name) end) +end + +------------------------------------------------------------------------------ + +-- Label pseudo-opcode (converted from trailing colon form). +map_op[".label_1"] = function(params) + if not params then return "[1-9] | ->global | =>pcexpr" end + if secpos+1 > maxsecpos then wflush() end + local mode, n, s = parse_label(params[1], true) + if mode == "EXT" then werror("bad label definition") end + waction("LABEL_"..mode, n, s, 1) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcodes for data storage. +map_op[".long_*"] = function(params) + if not params then return "imm..." end + for _,p in ipairs(params) do + local n = tonumber(p) + if not n then werror("bad immediate `"..p.."'") end + if n < 0 then n = n + 2^32 end + wputw(n) + if secpos+2 > maxsecpos then wflush() end + end +end + +-- Alignment pseudo-opcode. +map_op[".align_1"] = function(params) + if not params then return "numpow2" end + if secpos+1 > maxsecpos then wflush() end + local align = tonumber(params[1]) + if align then + local x = align + -- Must be a power of 2 in the range (2 ... 256). + for i=1,8 do + x = x / 2 + if x == 1 then + waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1. + return + end + end + end + werror("bad alignment") +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode for (primitive) type definitions (map to C types). +map_op[".type_3"] = function(params, nparams) + if not params then + return nparams == 2 and "name, ctype" or "name, ctype, reg" + end + local name, ctype, reg = params[1], params[2], params[3] + if not match(name, "^[%a_][%w_]*$") then + werror("bad type name `"..name.."'") + end + local tp = map_type[name] + if tp then + werror("duplicate type `"..name.."'") + end + -- Add #type to defines. A bit unclean to put it in map_archdef. + map_archdef["#"..name] = "sizeof("..ctype..")" + -- Add new type and emit shortcut define. + local num = ctypenum + 1 + map_type[name] = { + ctype = ctype, + ctypefmt = format("Dt%X(%%s)", num), + reg = reg, + } + wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype)) + ctypenum = num +end +map_op[".type_2"] = map_op[".type_3"] + +-- Dump type definitions. +local function dumptypes(out, lvl) + local t = {} + for name in pairs(map_type) do t[#t+1] = name end + sort(t) + out:write("Type definitions:\n") + for _,name in ipairs(t) do + local tp = map_type[name] + local reg = tp.reg or "" + out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Set the current section. +function _M.section(num) + waction("SECTION", num) + wflush(true) -- SECTION is a terminal action. +end + +------------------------------------------------------------------------------ + +-- Dump architecture description. +function _M.dumparch(out) + out:write(format("DynASM %s version %s, released %s\n\n", + _info.arch, _info.version, _info.release)) + dumpactions(out) +end + +-- Dump all user defined elements. +function _M.dumpdef(out, lvl) + dumptypes(out, lvl) + dumpglobals(out, lvl) + dumpexterns(out, lvl) +end + +------------------------------------------------------------------------------ + +-- Pass callbacks from/to the DynASM core. +function _M.passcb(wl, we, wf, ww) + wline, werror, wfatal, wwarn = wl, we, wf, ww + return wflush +end + +-- Setup the arch-specific module. +function _M.setup(arch, opt) + g_arch, g_opt = arch, opt +end + +-- Merge the core maps and the arch-specific maps. +function _M.mergemaps(map_coreop, map_def) + setmetatable(map_op, { __index = map_coreop }) + setmetatable(map_def, { __index = map_archdef }) + return map_op, map_def +end + +return _M + +------------------------------------------------------------------------------ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.h new file mode 100644 index 0000000..5ccff25 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.h @@ -0,0 +1,412 @@ +/* +** DynASM PPC encoding engine. +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** Released under the MIT license. See dynasm.lua for full copyright notice. +*/ + +#include +#include +#include +#include + +#define DASM_ARCH "ppc" + +#ifndef DASM_EXTERN +#define DASM_EXTERN(a,b,c,d) 0 +#endif + +/* Action definitions. */ +enum { + DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT, + /* The following actions need a buffer position. */ + DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG, + /* The following actions also have an argument. */ + DASM_REL_PC, DASM_LABEL_PC, DASM_IMM, + DASM__MAX +}; + +/* Maximum number of section buffer positions for a single dasm_put() call. */ +#define DASM_MAXSECPOS 25 + +/* DynASM encoder status codes. Action list offset or number are or'ed in. */ +#define DASM_S_OK 0x00000000 +#define DASM_S_NOMEM 0x01000000 +#define DASM_S_PHASE 0x02000000 +#define DASM_S_MATCH_SEC 0x03000000 +#define DASM_S_RANGE_I 0x11000000 +#define DASM_S_RANGE_SEC 0x12000000 +#define DASM_S_RANGE_LG 0x13000000 +#define DASM_S_RANGE_PC 0x14000000 +#define DASM_S_RANGE_REL 0x15000000 +#define DASM_S_UNDEF_LG 0x21000000 +#define DASM_S_UNDEF_PC 0x22000000 + +/* Macros to convert positions (8 bit section + 24 bit index). */ +#define DASM_POS2IDX(pos) ((pos)&0x00ffffff) +#define DASM_POS2BIAS(pos) ((pos)&0xff000000) +#define DASM_SEC2POS(sec) ((sec)<<24) +#define DASM_POS2SEC(pos) ((pos)>>24) +#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos)) + +/* Action list type. */ +typedef const unsigned int *dasm_ActList; + +/* Per-section structure. */ +typedef struct dasm_Section { + int *rbuf; /* Biased buffer pointer (negative section bias). */ + int *buf; /* True buffer pointer. */ + size_t bsize; /* Buffer size in bytes. */ + int pos; /* Biased buffer position. */ + int epos; /* End of biased buffer position - max single put. */ + int ofs; /* Byte offset into section. */ +} dasm_Section; + +/* Core structure holding the DynASM encoding state. */ +struct dasm_State { + size_t psize; /* Allocated size of this structure. */ + dasm_ActList actionlist; /* Current actionlist pointer. */ + int *lglabels; /* Local/global chain/pos ptrs. */ + size_t lgsize; + int *pclabels; /* PC label chains/pos ptrs. */ + size_t pcsize; + void **globals; /* Array of globals (bias -10). */ + dasm_Section *section; /* Pointer to active section. */ + size_t codesize; /* Total size of all code sections. */ + int maxsection; /* 0 <= sectionidx < maxsection. */ + int status; /* Status code. */ + dasm_Section sections[1]; /* All sections. Alloc-extended. */ +}; + +/* The size of the core structure depends on the max. number of sections. */ +#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section)) + + +/* Initialize DynASM state. */ +void dasm_init(Dst_DECL, int maxsection) +{ + dasm_State *D; + size_t psz = 0; + int i; + Dst_REF = NULL; + DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); + D = Dst_REF; + D->psize = psz; + D->lglabels = NULL; + D->lgsize = 0; + D->pclabels = NULL; + D->pcsize = 0; + D->globals = NULL; + D->maxsection = maxsection; + for (i = 0; i < maxsection; i++) { + D->sections[i].buf = NULL; /* Need this for pass3. */ + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); + D->sections[i].bsize = 0; + D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ + } +} + +/* Free DynASM state. */ +void dasm_free(Dst_DECL) +{ + dasm_State *D = Dst_REF; + int i; + for (i = 0; i < D->maxsection; i++) + if (D->sections[i].buf) + DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); + if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); + if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); + DASM_M_FREE(Dst, D, D->psize); +} + +/* Setup global label array. Must be called before dasm_setup(). */ +void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) +{ + dasm_State *D = Dst_REF; + D->globals = gl - 10; /* Negative bias to compensate for locals. */ + DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); +} + +/* Grow PC label array. Can be called after dasm_setup(), too. */ +void dasm_growpc(Dst_DECL, unsigned int maxpc) +{ + dasm_State *D = Dst_REF; + size_t osz = D->pcsize; + DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); + memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz); +} + +/* Setup encoder. */ +void dasm_setup(Dst_DECL, const void *actionlist) +{ + dasm_State *D = Dst_REF; + int i; + D->actionlist = (dasm_ActList)actionlist; + D->status = DASM_S_OK; + D->section = &D->sections[0]; + memset((void *)D->lglabels, 0, D->lgsize); + if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); + for (i = 0; i < D->maxsection; i++) { + D->sections[i].pos = DASM_SEC2POS(i); + D->sections[i].ofs = 0; + } +} + + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) { \ + D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0) +#define CKPL(kind, st) \ + do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \ + D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0) +#else +#define CK(x, st) ((void)0) +#define CKPL(kind, st) ((void)0) +#endif + +/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */ +void dasm_put(Dst_DECL, int start, ...) +{ + va_list ap; + dasm_State *D = Dst_REF; + dasm_ActList p = D->actionlist + start; + dasm_Section *sec = D->section; + int pos = sec->pos, ofs = sec->ofs; + int *b; + + if (pos >= sec->epos) { + DASM_M_GROW(Dst, int, sec->buf, sec->bsize, + sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); + sec->rbuf = sec->buf - DASM_POS2BIAS(pos); + sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos); + } + + b = sec->rbuf; + b[pos++] = start; + + va_start(ap, start); + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + if (action >= DASM__MAX) { + ofs += 4; + } else { + int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0; + switch (action) { + case DASM_STOP: goto stop; + case DASM_SECTION: + n = (ins & 255); CK(n < D->maxsection, RANGE_SEC); + D->section = &D->sections[n]; goto stop; + case DASM_ESC: p++; ofs += 4; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break; + case DASM_REL_LG: + n = (ins & 2047) - 10; pl = D->lglabels + n; + /* Bkwd rel or global. */ + if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; } + pl += 10; n = *pl; + if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ + goto linkrel; + case DASM_REL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putrel: + n = *pl; + if (n < 0) { /* Label exists. Get label pos and store it. */ + b[pos] = -n; + } else { + linkrel: + b[pos] = n; /* Else link to rel chain, anchored at label. */ + *pl = pos; + } + pos++; + break; + case DASM_LABEL_LG: + pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel; + case DASM_LABEL_PC: + pl = D->pclabels + n; CKPL(pc, PC); + putlabel: + n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; + } + *pl = -pos; /* Label exists now. */ + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_IMM: +#ifdef DASM_CHECKS + CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I); +#endif + n >>= ((ins>>10)&31); +#ifdef DASM_CHECKS + if (ins & 0x8000) + CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I); + else + CK((n>>((ins>>5)&31)) == 0, RANGE_I); +#endif + b[pos++] = n; + break; + } + } + } +stop: + va_end(ap); + sec->pos = pos; + sec->ofs = ofs; +} +#undef CK + +/* Pass 2: Link sections, shrink aligns, fix label offsets. */ +int dasm_link(Dst_DECL, size_t *szp) +{ + dasm_State *D = Dst_REF; + int secnum; + int ofs = 0; + +#ifdef DASM_CHECKS + *szp = 0; + if (D->status != DASM_S_OK) return D->status; + { + int pc; + for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) + if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc; + } +#endif + + { /* Handle globals not defined in this translation unit. */ + int idx; + for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { + int n = D->lglabels[idx]; + /* Undefined label: Collapse rel chain and replace with marker (< 0). */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } + } + } + + /* Combine all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->rbuf; + int pos = DASM_SEC2POS(secnum); + int lastpos = sec->pos; + + while (pos != lastpos) { + dasm_ActList p = D->actionlist + b[pos++]; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: p++; break; + case DASM_REL_EXT: break; + case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break; + case DASM_REL_LG: case DASM_REL_PC: pos++; break; + case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break; + case DASM_IMM: pos++; break; + } + } + stop: (void)0; + } + ofs += sec->ofs; /* Next section starts right after current section. */ + } + + D->codesize = ofs; /* Total size of all code sections */ + *szp = ofs; + return DASM_S_OK; +} + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0) +#else +#define CK(x, st) ((void)0) +#endif + +/* Pass 3: Encode sections. */ +int dasm_encode(Dst_DECL, void *buffer) +{ + dasm_State *D = Dst_REF; + char *base = (char *)buffer; + unsigned int *cp = (unsigned int *)buffer; + int secnum; + + /* Encode all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->buf; + int *endb = sec->rbuf + sec->pos; + + while (b != endb) { + dasm_ActList p = D->actionlist + *b++; + while (1) { + unsigned int ins = *p++; + unsigned int action = (ins >> 16); + int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0; + switch (action) { + case DASM_STOP: case DASM_SECTION: goto stop; + case DASM_ESC: *cp++ = *p++; break; + case DASM_REL_EXT: + n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4; + goto patchrel; + case DASM_ALIGN: + ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000; + break; + case DASM_REL_LG: + CK(n >= 0, UNDEF_LG); + case DASM_REL_PC: + CK(n >= 0, UNDEF_PC); + n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base); + patchrel: + CK((n & 3) == 0 && + (((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >> + ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL); + cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc)); + break; + case DASM_LABEL_LG: + ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + break; + case DASM_LABEL_PC: break; + case DASM_IMM: + cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31); + break; + default: *cp++ = ins; break; + } + } + stop: (void)0; + } + } + + if (base + D->codesize != (char *)cp) /* Check for phase errors. */ + return DASM_S_PHASE; + return DASM_S_OK; +} +#undef CK + +/* Get PC label offset. */ +int dasm_getpclabel(Dst_DECL, unsigned int pc) +{ + dasm_State *D = Dst_REF; + if (pc*sizeof(int) < D->pcsize) { + int pos = D->pclabels[pc]; + if (pos < 0) return *DASM_POS2PTR(D, -pos); + if (pos > 0) return -1; /* Undefined. */ + } + return -2; /* Unused or out of range. */ +} + +#ifdef DASM_CHECKS +/* Optional sanity checker to call between isolated encoding steps. */ +int dasm_checkstep(Dst_DECL, int secmatch) +{ + dasm_State *D = Dst_REF; + if (D->status == DASM_S_OK) { + int i; + for (i = 1; i <= 9; i++) { + if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; } + D->lglabels[i] = 0; + } + } + if (D->status == DASM_S_OK && secmatch >= 0 && + D->section != &D->sections[secmatch]) + D->status = DASM_S_MATCH_SEC|(D->section-D->sections); + return D->status; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.lua new file mode 100644 index 0000000..61da50e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_ppc.lua @@ -0,0 +1,1249 @@ +------------------------------------------------------------------------------ +-- DynASM PPC module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See dynasm.lua for full copyright notice. +------------------------------------------------------------------------------ + +-- Module information: +local _info = { + arch = "ppc", + description = "DynASM PPC module", + version = "1.3.0", + vernum = 10300, + release = "2011-05-05", + author = "Mike Pall", + license = "MIT", +} + +-- Exported glue functions for the arch-specific module. +local _M = { _info = _info } + +-- Cache library functions. +local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs +local assert, setmetatable = assert, setmetatable +local _s = string +local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char +local match, gmatch = _s.match, _s.gmatch +local concat, sort = table.concat, table.sort +local bit = bit or require("bit") +local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift +local tohex = bit.tohex + +-- Inherited tables and callbacks. +local g_opt, g_arch +local wline, werror, wfatal, wwarn + +-- Action name list. +-- CHECK: Keep this in sync with the C code! +local action_names = { + "STOP", "SECTION", "ESC", "REL_EXT", + "ALIGN", "REL_LG", "LABEL_LG", + "REL_PC", "LABEL_PC", "IMM", +} + +-- Maximum number of section buffer positions for dasm_put(). +-- CHECK: Keep this in sync with the C code! +local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines. + +-- Action name -> action number. +local map_action = {} +for n,name in ipairs(action_names) do + map_action[name] = n-1 +end + +-- Action list buffer. +local actlist = {} + +-- Argument list for next dasm_put(). Start with offset 0 into action list. +local actargs = { 0 } + +-- Current number of section buffer positions for dasm_put(). +local secpos = 1 + +------------------------------------------------------------------------------ + +-- Dump action names and numbers. +local function dumpactions(out) + out:write("DynASM encoding engine action codes:\n") + for n,name in ipairs(action_names) do + local num = map_action[name] + out:write(format(" %-10s %02X %d\n", name, num, num)) + end + out:write("\n") +end + +-- Write action list buffer as a huge static C array. +local function writeactions(out, name) + local nn = #actlist + if nn == 0 then nn = 1; actlist[0] = map_action.STOP end + out:write("static const unsigned int ", name, "[", nn, "] = {\n") + for i = 1,nn-1 do + assert(out:write("0x", tohex(actlist[i]), ",\n")) + end + assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n")) +end + +------------------------------------------------------------------------------ + +-- Add word to action list. +local function wputxw(n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + actlist[#actlist+1] = n +end + +-- Add action to list with optional arg. Advance buffer pos, too. +local function waction(action, val, a, num) + local w = assert(map_action[action], "bad action name `"..action.."'") + wputxw(w * 0x10000 + (val or 0)) + if a then actargs[#actargs+1] = a end + if a or num then secpos = secpos + (num or 1) end +end + +-- Flush action list (intervening C code or buffer pos overflow). +local function wflush(term) + if #actlist == actargs[1] then return end -- Nothing to flush. + if not term then waction("STOP") end -- Terminate action list. + wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true) + actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put(). + secpos = 1 -- The actionlist offset occupies a buffer position, too. +end + +-- Put escaped word. +local function wputw(n) + if n <= 0xffffff then waction("ESC") end + wputxw(n) +end + +-- Reserve position for word. +local function wpos() + local pos = #actlist+1 + actlist[pos] = "" + return pos +end + +-- Store word to reserved position. +local function wputpos(pos, n) + assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") + actlist[pos] = n +end + +------------------------------------------------------------------------------ + +-- Global label name -> global label number. With auto assignment on 1st use. +local next_global = 20 +local map_global = setmetatable({}, { __index = function(t, name) + if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end + local n = next_global + if n > 2047 then werror("too many global labels") end + next_global = n + 1 + t[name] = n + return n +end}) + +-- Dump global labels. +local function dumpglobals(out, lvl) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("Global labels:\n") + for i=20,next_global-1 do + out:write(format(" %s\n", t[i])) + end + out:write("\n") +end + +-- Write global label enum. +local function writeglobals(out, prefix) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("enum {\n") + for i=20,next_global-1 do + out:write(" ", prefix, t[i], ",\n") + end + out:write(" ", prefix, "_MAX\n};\n") +end + +-- Write global label names. +local function writeglobalnames(out, name) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("static const char *const ", name, "[] = {\n") + for i=20,next_global-1 do + out:write(" \"", t[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Extern label name -> extern label number. With auto assignment on 1st use. +local next_extern = 0 +local map_extern_ = {} +local map_extern = setmetatable({}, { __index = function(t, name) + -- No restrictions on the name for now. + local n = next_extern + if n > 2047 then werror("too many extern labels") end + next_extern = n + 1 + t[name] = n + map_extern_[n] = name + return n +end}) + +-- Dump extern labels. +local function dumpexterns(out, lvl) + out:write("Extern labels:\n") + for i=0,next_extern-1 do + out:write(format(" %s\n", map_extern_[i])) + end + out:write("\n") +end + +-- Write extern label names. +local function writeexternnames(out, name) + out:write("static const char *const ", name, "[] = {\n") + for i=0,next_extern-1 do + out:write(" \"", map_extern_[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Arch-specific maps. +local map_archdef = { sp = "r1" } -- Ext. register name -> int. name. + +local map_type = {} -- Type name -> { ctype, reg } +local ctypenum = 0 -- Type number (for Dt... macros). + +-- Reverse defines for registers. +function _M.revdef(s) + if s == "r1" then return "sp" end + return s +end + +local map_cond = { + lt = 0, gt = 1, eq = 2, so = 3, + ge = 4, le = 5, ne = 6, ns = 7, +} + +------------------------------------------------------------------------------ + +-- Template strings for PPC instructions. +local map_op = { + tdi_3 = "08000000ARI", + twi_3 = "0c000000ARI", + mulli_3 = "1c000000RRI", + subfic_3 = "20000000RRI", + cmplwi_3 = "28000000XRU", + cmplwi_2 = "28000000-RU", + cmpldi_3 = "28200000XRU", + cmpldi_2 = "28200000-RU", + cmpwi_3 = "2c000000XRI", + cmpwi_2 = "2c000000-RI", + cmpdi_3 = "2c200000XRI", + cmpdi_2 = "2c200000-RI", + addic_3 = "30000000RRI", + ["addic._3"] = "34000000RRI", + addi_3 = "38000000RR0I", + li_2 = "38000000RI", + la_2 = "38000000RD", + addis_3 = "3c000000RR0I", + lis_2 = "3c000000RI", + lus_2 = "3c000000RU", + bc_3 = "40000000AAK", + bcl_3 = "40000001AAK", + bdnz_1 = "42000000K", + bdz_1 = "42400000K", + sc_0 = "44000000", + b_1 = "48000000J", + bl_1 = "48000001J", + rlwimi_5 = "50000000RR~AAA.", + rlwinm_5 = "54000000RR~AAA.", + rlwnm_5 = "5c000000RR~RAA.", + ori_3 = "60000000RR~U", + nop_0 = "60000000", + oris_3 = "64000000RR~U", + xori_3 = "68000000RR~U", + xoris_3 = "6c000000RR~U", + ["andi._3"] = "70000000RR~U", + ["andis._3"] = "74000000RR~U", + lwz_2 = "80000000RD", + lwzu_2 = "84000000RD", + lbz_2 = "88000000RD", + lbzu_2 = "8c000000RD", + stw_2 = "90000000RD", + stwu_2 = "94000000RD", + stb_2 = "98000000RD", + stbu_2 = "9c000000RD", + lhz_2 = "a0000000RD", + lhzu_2 = "a4000000RD", + lha_2 = "a8000000RD", + lhau_2 = "ac000000RD", + sth_2 = "b0000000RD", + sthu_2 = "b4000000RD", + lmw_2 = "b8000000RD", + stmw_2 = "bc000000RD", + lfs_2 = "c0000000FD", + lfsu_2 = "c4000000FD", + lfd_2 = "c8000000FD", + lfdu_2 = "cc000000FD", + stfs_2 = "d0000000FD", + stfsu_2 = "d4000000FD", + stfd_2 = "d8000000FD", + stfdu_2 = "dc000000FD", + ld_2 = "e8000000RD", -- NYI: displacement must be divisible by 4. + ldu_2 = "e8000001RD", + lwa_2 = "e8000002RD", + std_2 = "f8000000RD", + stdu_2 = "f8000001RD", + + -- Primary opcode 19: + mcrf_2 = "4c000000XX", + isync_0 = "4c00012c", + crnor_3 = "4c000042CCC", + crnot_2 = "4c000042CC=", + crandc_3 = "4c000102CCC", + crxor_3 = "4c000182CCC", + crclr_1 = "4c000182C==", + crnand_3 = "4c0001c2CCC", + crand_3 = "4c000202CCC", + creqv_3 = "4c000242CCC", + crset_1 = "4c000242C==", + crorc_3 = "4c000342CCC", + cror_3 = "4c000382CCC", + crmove_2 = "4c000382CC=", + bclr_2 = "4c000020AA", + bclrl_2 = "4c000021AA", + bcctr_2 = "4c000420AA", + bcctrl_2 = "4c000421AA", + blr_0 = "4e800020", + blrl_0 = "4e800021", + bctr_0 = "4e800420", + bctrl_0 = "4e800421", + + -- Primary opcode 31: + cmpw_3 = "7c000000XRR", + cmpw_2 = "7c000000-RR", + cmpd_3 = "7c200000XRR", + cmpd_2 = "7c200000-RR", + tw_3 = "7c000008ARR", + subfc_3 = "7c000010RRR.", + subc_3 = "7c000010RRR~.", + mulhdu_3 = "7c000012RRR.", + addc_3 = "7c000014RRR.", + mulhwu_3 = "7c000016RRR.", + isel_4 = "7c00001eRRRC", + isellt_3 = "7c00001eRRR", + iselgt_3 = "7c00005eRRR", + iseleq_3 = "7c00009eRRR", + mfcr_1 = "7c000026R", + mfocrf_2 = "7c100026RG", + mtcrf_2 = "7c000120GR", + mtocrf_2 = "7c100120GR", + lwarx_3 = "7c000028RR0R", + ldx_3 = "7c00002aRR0R", + lwzx_3 = "7c00002eRR0R", + slw_3 = "7c000030RR~R.", + cntlzw_2 = "7c000034RR~", + sld_3 = "7c000036RR~R.", + and_3 = "7c000038RR~R.", + cmplw_3 = "7c000040XRR", + cmplw_2 = "7c000040-RR", + cmpld_3 = "7c200040XRR", + cmpld_2 = "7c200040-RR", + subf_3 = "7c000050RRR.", + sub_3 = "7c000050RRR~.", + ldux_3 = "7c00006aRR0R", + dcbst_2 = "7c00006c-RR", + lwzux_3 = "7c00006eRR0R", + cntlzd_2 = "7c000074RR~", + andc_3 = "7c000078RR~R.", + td_3 = "7c000088ARR", + mulhd_3 = "7c000092RRR.", + mulhw_3 = "7c000096RRR.", + ldarx_3 = "7c0000a8RR0R", + dcbf_2 = "7c0000ac-RR", + lbzx_3 = "7c0000aeRR0R", + neg_2 = "7c0000d0RR.", + lbzux_3 = "7c0000eeRR0R", + popcntb_2 = "7c0000f4RR~", + not_2 = "7c0000f8RR~%.", + nor_3 = "7c0000f8RR~R.", + subfe_3 = "7c000110RRR.", + sube_3 = "7c000110RRR~.", + adde_3 = "7c000114RRR.", + stdx_3 = "7c00012aRR0R", + stwcx_3 = "7c00012cRR0R.", + stwx_3 = "7c00012eRR0R", + prtyw_2 = "7c000134RR~", + stdux_3 = "7c00016aRR0R", + stwux_3 = "7c00016eRR0R", + prtyd_2 = "7c000174RR~", + subfze_2 = "7c000190RR.", + addze_2 = "7c000194RR.", + stdcx_3 = "7c0001acRR0R.", + stbx_3 = "7c0001aeRR0R", + subfme_2 = "7c0001d0RR.", + mulld_3 = "7c0001d2RRR.", + addme_2 = "7c0001d4RR.", + mullw_3 = "7c0001d6RRR.", + dcbtst_2 = "7c0001ec-RR", + stbux_3 = "7c0001eeRR0R", + add_3 = "7c000214RRR.", + dcbt_2 = "7c00022c-RR", + lhzx_3 = "7c00022eRR0R", + eqv_3 = "7c000238RR~R.", + eciwx_3 = "7c00026cRR0R", + lhzux_3 = "7c00026eRR0R", + xor_3 = "7c000278RR~R.", + mfspefscr_1 = "7c0082a6R", + mfxer_1 = "7c0102a6R", + mflr_1 = "7c0802a6R", + mfctr_1 = "7c0902a6R", + lwax_3 = "7c0002aaRR0R", + lhax_3 = "7c0002aeRR0R", + mftb_1 = "7c0c42e6R", + mftbu_1 = "7c0d42e6R", + lwaux_3 = "7c0002eaRR0R", + lhaux_3 = "7c0002eeRR0R", + sthx_3 = "7c00032eRR0R", + orc_3 = "7c000338RR~R.", + ecowx_3 = "7c00036cRR0R", + sthux_3 = "7c00036eRR0R", + or_3 = "7c000378RR~R.", + mr_2 = "7c000378RR~%.", + divdu_3 = "7c000392RRR.", + divwu_3 = "7c000396RRR.", + mtspefscr_1 = "7c0083a6R", + mtxer_1 = "7c0103a6R", + mtlr_1 = "7c0803a6R", + mtctr_1 = "7c0903a6R", + dcbi_2 = "7c0003ac-RR", + nand_3 = "7c0003b8RR~R.", + divd_3 = "7c0003d2RRR.", + divw_3 = "7c0003d6RRR.", + cmpb_3 = "7c0003f8RR~R.", + mcrxr_1 = "7c000400X", + subfco_3 = "7c000410RRR.", + subco_3 = "7c000410RRR~.", + addco_3 = "7c000414RRR.", + ldbrx_3 = "7c000428RR0R", + lswx_3 = "7c00042aRR0R", + lwbrx_3 = "7c00042cRR0R", + lfsx_3 = "7c00042eFR0R", + srw_3 = "7c000430RR~R.", + srd_3 = "7c000436RR~R.", + subfo_3 = "7c000450RRR.", + subo_3 = "7c000450RRR~.", + lfsux_3 = "7c00046eFR0R", + lswi_3 = "7c0004aaRR0A", + sync_0 = "7c0004ac", + lwsync_0 = "7c2004ac", + ptesync_0 = "7c4004ac", + lfdx_3 = "7c0004aeFR0R", + nego_2 = "7c0004d0RR.", + lfdux_3 = "7c0004eeFR0R", + subfeo_3 = "7c000510RRR.", + subeo_3 = "7c000510RRR~.", + addeo_3 = "7c000514RRR.", + stdbrx_3 = "7c000528RR0R", + stswx_3 = "7c00052aRR0R", + stwbrx_3 = "7c00052cRR0R", + stfsx_3 = "7c00052eFR0R", + stfsux_3 = "7c00056eFR0R", + subfzeo_2 = "7c000590RR.", + addzeo_2 = "7c000594RR.", + stswi_3 = "7c0005aaRR0A", + stfdx_3 = "7c0005aeFR0R", + subfmeo_2 = "7c0005d0RR.", + mulldo_3 = "7c0005d2RRR.", + addmeo_2 = "7c0005d4RR.", + mullwo_3 = "7c0005d6RRR.", + dcba_2 = "7c0005ec-RR", + stfdux_3 = "7c0005eeFR0R", + addo_3 = "7c000614RRR.", + lhbrx_3 = "7c00062cRR0R", + sraw_3 = "7c000630RR~R.", + srad_3 = "7c000634RR~R.", + srawi_3 = "7c000670RR~A.", + sradi_3 = "7c000674RR~H.", + eieio_0 = "7c0006ac", + lfiwax_3 = "7c0006aeFR0R", + sthbrx_3 = "7c00072cRR0R", + extsh_2 = "7c000734RR~.", + extsb_2 = "7c000774RR~.", + divduo_3 = "7c000792RRR.", + divwou_3 = "7c000796RRR.", + icbi_2 = "7c0007ac-RR", + stfiwx_3 = "7c0007aeFR0R", + extsw_2 = "7c0007b4RR~.", + divdo_3 = "7c0007d2RRR.", + divwo_3 = "7c0007d6RRR.", + dcbz_2 = "7c0007ec-RR", + + -- Primary opcode 30: + rldicl_4 = "78000000RR~HM.", + rldicr_4 = "78000004RR~HM.", + rldic_4 = "78000008RR~HM.", + rldimi_4 = "7800000cRR~HM.", + rldcl_4 = "78000010RR~RM.", + rldcr_4 = "78000012RR~RM.", + + -- Primary opcode 59: + fdivs_3 = "ec000024FFF.", + fsubs_3 = "ec000028FFF.", + fadds_3 = "ec00002aFFF.", + fsqrts_2 = "ec00002cF-F.", + fres_2 = "ec000030F-F.", + fmuls_3 = "ec000032FF-F.", + frsqrtes_2 = "ec000034F-F.", + fmsubs_4 = "ec000038FFFF~.", + fmadds_4 = "ec00003aFFFF~.", + fnmsubs_4 = "ec00003cFFFF~.", + fnmadds_4 = "ec00003eFFFF~.", + + -- Primary opcode 63: + fdiv_3 = "fc000024FFF.", + fsub_3 = "fc000028FFF.", + fadd_3 = "fc00002aFFF.", + fsqrt_2 = "fc00002cF-F.", + fsel_4 = "fc00002eFFFF~.", + fre_2 = "fc000030F-F.", + fmul_3 = "fc000032FF-F.", + frsqrte_2 = "fc000034F-F.", + fmsub_4 = "fc000038FFFF~.", + fmadd_4 = "fc00003aFFFF~.", + fnmsub_4 = "fc00003cFFFF~.", + fnmadd_4 = "fc00003eFFFF~.", + fcmpu_3 = "fc000000XFF", + fcpsgn_3 = "fc000010FFF.", + fcmpo_3 = "fc000040XFF", + mtfsb1_1 = "fc00004cA", + fneg_2 = "fc000050F-F.", + mcrfs_2 = "fc000080XX", + mtfsb0_1 = "fc00008cA", + fmr_2 = "fc000090F-F.", + frsp_2 = "fc000018F-F.", + fctiw_2 = "fc00001cF-F.", + fctiwz_2 = "fc00001eF-F.", + mtfsfi_2 = "fc00010cAA", -- NYI: upshift. + fnabs_2 = "fc000110F-F.", + fabs_2 = "fc000210F-F.", + frin_2 = "fc000310F-F.", + friz_2 = "fc000350F-F.", + frip_2 = "fc000390F-F.", + frim_2 = "fc0003d0F-F.", + mffs_1 = "fc00048eF.", + -- NYI: mtfsf, mtfsb0, mtfsb1. + fctid_2 = "fc00065cF-F.", + fctidz_2 = "fc00065eF-F.", + fcfid_2 = "fc00069cF-F.", + + -- Primary opcode 4, SPE APU extension: + evaddw_3 = "10000200RRR", + evaddiw_3 = "10000202RAR~", + evsubw_3 = "10000204RRR~", + evsubiw_3 = "10000206RAR~", + evabs_2 = "10000208RR", + evneg_2 = "10000209RR", + evextsb_2 = "1000020aRR", + evextsh_2 = "1000020bRR", + evrndw_2 = "1000020cRR", + evcntlzw_2 = "1000020dRR", + evcntlsw_2 = "1000020eRR", + brinc_3 = "1000020fRRR", + evand_3 = "10000211RRR", + evandc_3 = "10000212RRR", + evxor_3 = "10000216RRR", + evor_3 = "10000217RRR", + evmr_2 = "10000217RR=", + evnor_3 = "10000218RRR", + evnot_2 = "10000218RR=", + eveqv_3 = "10000219RRR", + evorc_3 = "1000021bRRR", + evnand_3 = "1000021eRRR", + evsrwu_3 = "10000220RRR", + evsrws_3 = "10000221RRR", + evsrwiu_3 = "10000222RRA", + evsrwis_3 = "10000223RRA", + evslw_3 = "10000224RRR", + evslwi_3 = "10000226RRA", + evrlw_3 = "10000228RRR", + evsplati_2 = "10000229RS", + evrlwi_3 = "1000022aRRA", + evsplatfi_2 = "1000022bRS", + evmergehi_3 = "1000022cRRR", + evmergelo_3 = "1000022dRRR", + evcmpgtu_3 = "10000230XRR", + evcmpgtu_2 = "10000230-RR", + evcmpgts_3 = "10000231XRR", + evcmpgts_2 = "10000231-RR", + evcmpltu_3 = "10000232XRR", + evcmpltu_2 = "10000232-RR", + evcmplts_3 = "10000233XRR", + evcmplts_2 = "10000233-RR", + evcmpeq_3 = "10000234XRR", + evcmpeq_2 = "10000234-RR", + evsel_4 = "10000278RRRW", + evsel_3 = "10000278RRR", + evfsadd_3 = "10000280RRR", + evfssub_3 = "10000281RRR", + evfsabs_2 = "10000284RR", + evfsnabs_2 = "10000285RR", + evfsneg_2 = "10000286RR", + evfsmul_3 = "10000288RRR", + evfsdiv_3 = "10000289RRR", + evfscmpgt_3 = "1000028cXRR", + evfscmpgt_2 = "1000028c-RR", + evfscmplt_3 = "1000028dXRR", + evfscmplt_2 = "1000028d-RR", + evfscmpeq_3 = "1000028eXRR", + evfscmpeq_2 = "1000028e-RR", + evfscfui_2 = "10000290R-R", + evfscfsi_2 = "10000291R-R", + evfscfuf_2 = "10000292R-R", + evfscfsf_2 = "10000293R-R", + evfsctui_2 = "10000294R-R", + evfsctsi_2 = "10000295R-R", + evfsctuf_2 = "10000296R-R", + evfsctsf_2 = "10000297R-R", + evfsctuiz_2 = "10000298R-R", + evfsctsiz_2 = "1000029aR-R", + evfststgt_3 = "1000029cXRR", + evfststgt_2 = "1000029c-RR", + evfststlt_3 = "1000029dXRR", + evfststlt_2 = "1000029d-RR", + evfststeq_3 = "1000029eXRR", + evfststeq_2 = "1000029e-RR", + efsadd_3 = "100002c0RRR", + efssub_3 = "100002c1RRR", + efsabs_2 = "100002c4RR", + efsnabs_2 = "100002c5RR", + efsneg_2 = "100002c6RR", + efsmul_3 = "100002c8RRR", + efsdiv_3 = "100002c9RRR", + efscmpgt_3 = "100002ccXRR", + efscmpgt_2 = "100002cc-RR", + efscmplt_3 = "100002cdXRR", + efscmplt_2 = "100002cd-RR", + efscmpeq_3 = "100002ceXRR", + efscmpeq_2 = "100002ce-RR", + efscfd_2 = "100002cfR-R", + efscfui_2 = "100002d0R-R", + efscfsi_2 = "100002d1R-R", + efscfuf_2 = "100002d2R-R", + efscfsf_2 = "100002d3R-R", + efsctui_2 = "100002d4R-R", + efsctsi_2 = "100002d5R-R", + efsctuf_2 = "100002d6R-R", + efsctsf_2 = "100002d7R-R", + efsctuiz_2 = "100002d8R-R", + efsctsiz_2 = "100002daR-R", + efststgt_3 = "100002dcXRR", + efststgt_2 = "100002dc-RR", + efststlt_3 = "100002ddXRR", + efststlt_2 = "100002dd-RR", + efststeq_3 = "100002deXRR", + efststeq_2 = "100002de-RR", + efdadd_3 = "100002e0RRR", + efdsub_3 = "100002e1RRR", + efdcfuid_2 = "100002e2R-R", + efdcfsid_2 = "100002e3R-R", + efdabs_2 = "100002e4RR", + efdnabs_2 = "100002e5RR", + efdneg_2 = "100002e6RR", + efdmul_3 = "100002e8RRR", + efddiv_3 = "100002e9RRR", + efdctuidz_2 = "100002eaR-R", + efdctsidz_2 = "100002ebR-R", + efdcmpgt_3 = "100002ecXRR", + efdcmpgt_2 = "100002ec-RR", + efdcmplt_3 = "100002edXRR", + efdcmplt_2 = "100002ed-RR", + efdcmpeq_3 = "100002eeXRR", + efdcmpeq_2 = "100002ee-RR", + efdcfs_2 = "100002efR-R", + efdcfui_2 = "100002f0R-R", + efdcfsi_2 = "100002f1R-R", + efdcfuf_2 = "100002f2R-R", + efdcfsf_2 = "100002f3R-R", + efdctui_2 = "100002f4R-R", + efdctsi_2 = "100002f5R-R", + efdctuf_2 = "100002f6R-R", + efdctsf_2 = "100002f7R-R", + efdctuiz_2 = "100002f8R-R", + efdctsiz_2 = "100002faR-R", + efdtstgt_3 = "100002fcXRR", + efdtstgt_2 = "100002fc-RR", + efdtstlt_3 = "100002fdXRR", + efdtstlt_2 = "100002fd-RR", + efdtsteq_3 = "100002feXRR", + efdtsteq_2 = "100002fe-RR", + evlddx_3 = "10000300RR0R", + evldd_2 = "10000301R8", + evldwx_3 = "10000302RR0R", + evldw_2 = "10000303R8", + evldhx_3 = "10000304RR0R", + evldh_2 = "10000305R8", + evlwhex_3 = "10000310RR0R", + evlwhe_2 = "10000311R4", + evlwhoux_3 = "10000314RR0R", + evlwhou_2 = "10000315R4", + evlwhosx_3 = "10000316RR0R", + evlwhos_2 = "10000317R4", + evstddx_3 = "10000320RR0R", + evstdd_2 = "10000321R8", + evstdwx_3 = "10000322RR0R", + evstdw_2 = "10000323R8", + evstdhx_3 = "10000324RR0R", + evstdh_2 = "10000325R8", + evstwhex_3 = "10000330RR0R", + evstwhe_2 = "10000331R4", + evstwhox_3 = "10000334RR0R", + evstwho_2 = "10000335R4", + evstwwex_3 = "10000338RR0R", + evstwwe_2 = "10000339R4", + evstwwox_3 = "1000033cRR0R", + evstwwo_2 = "1000033dR4", + evmhessf_3 = "10000403RRR", + evmhossf_3 = "10000407RRR", + evmheumi_3 = "10000408RRR", + evmhesmi_3 = "10000409RRR", + evmhesmf_3 = "1000040bRRR", + evmhoumi_3 = "1000040cRRR", + evmhosmi_3 = "1000040dRRR", + evmhosmf_3 = "1000040fRRR", + evmhessfa_3 = "10000423RRR", + evmhossfa_3 = "10000427RRR", + evmheumia_3 = "10000428RRR", + evmhesmia_3 = "10000429RRR", + evmhesmfa_3 = "1000042bRRR", + evmhoumia_3 = "1000042cRRR", + evmhosmia_3 = "1000042dRRR", + evmhosmfa_3 = "1000042fRRR", + evmwhssf_3 = "10000447RRR", + evmwlumi_3 = "10000448RRR", + evmwhumi_3 = "1000044cRRR", + evmwhsmi_3 = "1000044dRRR", + evmwhsmf_3 = "1000044fRRR", + evmwssf_3 = "10000453RRR", + evmwumi_3 = "10000458RRR", + evmwsmi_3 = "10000459RRR", + evmwsmf_3 = "1000045bRRR", + evmwhssfa_3 = "10000467RRR", + evmwlumia_3 = "10000468RRR", + evmwhumia_3 = "1000046cRRR", + evmwhsmia_3 = "1000046dRRR", + evmwhsmfa_3 = "1000046fRRR", + evmwssfa_3 = "10000473RRR", + evmwumia_3 = "10000478RRR", + evmwsmia_3 = "10000479RRR", + evmwsmfa_3 = "1000047bRRR", + evmra_2 = "100004c4RR", + evdivws_3 = "100004c6RRR", + evdivwu_3 = "100004c7RRR", + evmwssfaa_3 = "10000553RRR", + evmwumiaa_3 = "10000558RRR", + evmwsmiaa_3 = "10000559RRR", + evmwsmfaa_3 = "1000055bRRR", + evmwssfan_3 = "100005d3RRR", + evmwumian_3 = "100005d8RRR", + evmwsmian_3 = "100005d9RRR", + evmwsmfan_3 = "100005dbRRR", + evmergehilo_3 = "1000022eRRR", + evmergelohi_3 = "1000022fRRR", + evlhhesplatx_3 = "10000308RR0R", + evlhhesplat_2 = "10000309R2", + evlhhousplatx_3 = "1000030cRR0R", + evlhhousplat_2 = "1000030dR2", + evlhhossplatx_3 = "1000030eRR0R", + evlhhossplat_2 = "1000030fR2", + evlwwsplatx_3 = "10000318RR0R", + evlwwsplat_2 = "10000319R4", + evlwhsplatx_3 = "1000031cRR0R", + evlwhsplat_2 = "1000031dR4", + evaddusiaaw_2 = "100004c0RR", + evaddssiaaw_2 = "100004c1RR", + evsubfusiaaw_2 = "100004c2RR", + evsubfssiaaw_2 = "100004c3RR", + evaddumiaaw_2 = "100004c8RR", + evaddsmiaaw_2 = "100004c9RR", + evsubfumiaaw_2 = "100004caRR", + evsubfsmiaaw_2 = "100004cbRR", + evmheusiaaw_3 = "10000500RRR", + evmhessiaaw_3 = "10000501RRR", + evmhessfaaw_3 = "10000503RRR", + evmhousiaaw_3 = "10000504RRR", + evmhossiaaw_3 = "10000505RRR", + evmhossfaaw_3 = "10000507RRR", + evmheumiaaw_3 = "10000508RRR", + evmhesmiaaw_3 = "10000509RRR", + evmhesmfaaw_3 = "1000050bRRR", + evmhoumiaaw_3 = "1000050cRRR", + evmhosmiaaw_3 = "1000050dRRR", + evmhosmfaaw_3 = "1000050fRRR", + evmhegumiaa_3 = "10000528RRR", + evmhegsmiaa_3 = "10000529RRR", + evmhegsmfaa_3 = "1000052bRRR", + evmhogumiaa_3 = "1000052cRRR", + evmhogsmiaa_3 = "1000052dRRR", + evmhogsmfaa_3 = "1000052fRRR", + evmwlusiaaw_3 = "10000540RRR", + evmwlssiaaw_3 = "10000541RRR", + evmwlumiaaw_3 = "10000548RRR", + evmwlsmiaaw_3 = "10000549RRR", + evmheusianw_3 = "10000580RRR", + evmhessianw_3 = "10000581RRR", + evmhessfanw_3 = "10000583RRR", + evmhousianw_3 = "10000584RRR", + evmhossianw_3 = "10000585RRR", + evmhossfanw_3 = "10000587RRR", + evmheumianw_3 = "10000588RRR", + evmhesmianw_3 = "10000589RRR", + evmhesmfanw_3 = "1000058bRRR", + evmhoumianw_3 = "1000058cRRR", + evmhosmianw_3 = "1000058dRRR", + evmhosmfanw_3 = "1000058fRRR", + evmhegumian_3 = "100005a8RRR", + evmhegsmian_3 = "100005a9RRR", + evmhegsmfan_3 = "100005abRRR", + evmhogumian_3 = "100005acRRR", + evmhogsmian_3 = "100005adRRR", + evmhogsmfan_3 = "100005afRRR", + evmwlusianw_3 = "100005c0RRR", + evmwlssianw_3 = "100005c1RRR", + evmwlumianw_3 = "100005c8RRR", + evmwlsmianw_3 = "100005c9RRR", + + -- NYI: Book E instructions. +} + +-- Add mnemonics for "." variants. +do + local t = {} + for k,v in pairs(map_op) do + if sub(v, -1) == "." then + local v2 = sub(v, 1, 7)..char(byte(v, 8)+1)..sub(v, 9, -2) + t[sub(k, 1, -3).."."..sub(k, -2)] = v2 + end + end + for k,v in pairs(t) do + map_op[k] = v + end +end + +-- Add more branch mnemonics. +for cond,c in pairs(map_cond) do + local b1 = "b"..cond + local c1 = shl(band(c, 3), 16) + (c < 4 and 0x01000000 or 0) + -- bX[l] + map_op[b1.."_1"] = tohex(0x40800000 + c1).."K" + map_op[b1.."y_1"] = tohex(0x40a00000 + c1).."K" + map_op[b1.."l_1"] = tohex(0x40800001 + c1).."K" + map_op[b1.."_2"] = tohex(0x40800000 + c1).."-XK" + map_op[b1.."y_2"] = tohex(0x40a00000 + c1).."-XK" + map_op[b1.."l_2"] = tohex(0x40800001 + c1).."-XK" + -- bXlr[l] + map_op[b1.."lr_0"] = tohex(0x4c800020 + c1) + map_op[b1.."lrl_0"] = tohex(0x4c800021 + c1) + map_op[b1.."ctr_0"] = tohex(0x4c800420 + c1) + map_op[b1.."ctrl_0"] = tohex(0x4c800421 + c1) + -- bXctr[l] + map_op[b1.."lr_1"] = tohex(0x4c800020 + c1).."-X" + map_op[b1.."lrl_1"] = tohex(0x4c800021 + c1).."-X" + map_op[b1.."ctr_1"] = tohex(0x4c800420 + c1).."-X" + map_op[b1.."ctrl_1"] = tohex(0x4c800421 + c1).."-X" +end + +------------------------------------------------------------------------------ + +local function parse_gpr(expr) + local tname, ovreg = match(expr, "^([%w_]+):(r[1-3]?[0-9])$") + local tp = map_type[tname or expr] + if tp then + local reg = ovreg or tp.reg + if not reg then + werror("type `"..(tname or expr).."' needs a register override") + end + expr = reg + end + local r = match(expr, "^r([1-3]?[0-9])$") + if r then + r = tonumber(r) + if r <= 31 then return r, tp end + end + werror("bad register name `"..expr.."'") +end + +local function parse_fpr(expr) + local r = match(expr, "^f([1-3]?[0-9])$") + if r then + r = tonumber(r) + if r <= 31 then return r end + end + werror("bad register name `"..expr.."'") +end + +local function parse_cr(expr) + local r = match(expr, "^cr([0-7])$") + if r then return tonumber(r) end + werror("bad condition register name `"..expr.."'") +end + +local function parse_cond(expr) + local r, cond = match(expr, "^4%*cr([0-7])%+(%w%w)$") + if r then + r = tonumber(r) + local c = map_cond[cond] + if c and c < 4 then return r*4+c end + end + werror("bad condition bit name `"..expr.."'") +end + +local function parse_imm(imm, bits, shift, scale, signed) + local n = tonumber(imm) + if n then + local m = sar(n, scale) + if shl(m, scale) == n then + if signed then + local s = sar(m, bits-1) + if s == 0 then return shl(m, shift) + elseif s == -1 then return shl(m + shl(1, bits), shift) end + else + if sar(m, bits) == 0 then return shl(m, shift) end + end + end + werror("out of range immediate `"..imm.."'") + elseif match(imm, "^r([1-3]?[0-9])$") or + match(imm, "^([%w_]+):(r[1-3]?[0-9])$") then + werror("expected immediate operand, got register") + else + waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm) + return 0 + end +end + +local function parse_shiftmask(imm, isshift) + local n = tonumber(imm) + if n then + if shr(n, 6) == 0 then + local lsb = band(imm, 31) + local msb = imm - lsb + return isshift and (shl(lsb, 11)+shr(msb, 4)) or (shl(lsb, 6)+msb) + end + werror("out of range immediate `"..imm.."'") + elseif match(imm, "^r([1-3]?[0-9])$") or + match(imm, "^([%w_]+):(r[1-3]?[0-9])$") then + werror("expected immediate operand, got register") + else + werror("NYI: parameterized 64 bit shift/mask") + end +end + +local function parse_disp(disp) + local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$") + if imm then + local r = parse_gpr(reg) + if r == 0 then werror("cannot use r0 in displacement") end + return shl(r, 16) + parse_imm(imm, 16, 0, 0, true) + end + local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$") + if reg and tailr ~= "" then + local r, tp = parse_gpr(reg) + if r == 0 then werror("cannot use r0 in displacement") end + if tp then + waction("IMM", 32768+16*32, format(tp.ctypefmt, tailr)) + return shl(r, 16) + end + end + werror("bad displacement `"..disp.."'") +end + +local function parse_u5disp(disp, scale) + local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$") + if imm then + local r = parse_gpr(reg) + if r == 0 then werror("cannot use r0 in displacement") end + return shl(r, 16) + parse_imm(imm, 5, 11, scale, false) + end + local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$") + if reg and tailr ~= "" then + local r, tp = parse_gpr(reg) + if r == 0 then werror("cannot use r0 in displacement") end + if tp then + waction("IMM", scale*1024+5*32+11, format(tp.ctypefmt, tailr)) + return shl(r, 16) + end + end + werror("bad displacement `"..disp.."'") +end + +local function parse_label(label, def) + local prefix = sub(label, 1, 2) + -- =>label (pc label reference) + if prefix == "=>" then + return "PC", 0, sub(label, 3) + end + -- ->name (global label reference) + if prefix == "->" then + return "LG", map_global[sub(label, 3)] + end + if def then + -- [1-9] (local label definition) + if match(label, "^[1-9]$") then + return "LG", 10+tonumber(label) + end + else + -- [<>][1-9] (local label reference) + local dir, lnum = match(label, "^([<>])([1-9])$") + if dir then -- Fwd: 1-9, Bkwd: 11-19. + return "LG", lnum + (dir == ">" and 0 or 10) + end + -- extern label (extern label reference) + local extname = match(label, "^extern%s+(%S+)$") + if extname then + return "EXT", map_extern[extname] + end + end + werror("bad label `"..label.."'") +end + +------------------------------------------------------------------------------ + +-- Handle opcodes defined with template strings. +map_op[".template__"] = function(params, template, nparams) + if not params then return sub(template, 9) end + local op = tonumber(sub(template, 1, 8), 16) + local n, rs = 1, 26 + + -- Limit number of section buffer positions used by a single dasm_put(). + -- A single opcode needs a maximum of 3 positions (rlwinm). + if secpos+3 > maxsecpos then wflush() end + local pos = wpos() + + -- Process each character. + for p in gmatch(sub(template, 9), ".") do + if p == "R" then + rs = rs - 5; op = op + shl(parse_gpr(params[n]), rs); n = n + 1 + elseif p == "F" then + rs = rs - 5; op = op + shl(parse_fpr(params[n]), rs); n = n + 1 + elseif p == "A" then + rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, false); n = n + 1 + elseif p == "S" then + rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, true); n = n + 1 + elseif p == "I" then + op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1 + elseif p == "U" then + op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1 + elseif p == "D" then + op = op + parse_disp(params[n]); n = n + 1 + elseif p == "2" then + op = op + parse_u5disp(params[n], 1); n = n + 1 + elseif p == "4" then + op = op + parse_u5disp(params[n], 2); n = n + 1 + elseif p == "8" then + op = op + parse_u5disp(params[n], 3); n = n + 1 + elseif p == "C" then + rs = rs - 5; op = op + shl(parse_cond(params[n]), rs); n = n + 1 + elseif p == "X" then + rs = rs - 5; op = op + shl(parse_cr(params[n]), rs+2); n = n + 1 + elseif p == "W" then + op = op + parse_cr(params[n]); n = n + 1 + elseif p == "G" then + op = op + parse_imm(params[n], 8, 12, 0, false); n = n + 1 + elseif p == "H" then + op = op + parse_shiftmask(params[n], true); n = n + 1 + elseif p == "M" then + op = op + parse_shiftmask(params[n], false); n = n + 1 + elseif p == "J" or p == "K" then + local mode, n, s = parse_label(params[n], false) + if p == "K" then n = n + 2048 end + waction("REL_"..mode, n, s, 1) + n = n + 1 + elseif p == "0" then + if band(shr(op, rs), 31) == 0 then werror("cannot use r0") end + elseif p == "=" or p == "%" then + local t = band(shr(op, p == "%" and rs+5 or rs), 31) + rs = rs - 5 + op = op + shl(t, rs) + elseif p == "~" then + local mm = shl(31, rs) + local lo = band(op, mm) + local hi = band(op, shl(mm, 5)) + op = op - lo - hi + shl(lo, 5) + shr(hi, 5) + elseif p == "-" then + rs = rs - 5 + elseif p == "." then + -- Ignored. + else + assert(false) + end + end + wputpos(pos, op) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode to mark the position where the action list is to be emitted. +map_op[".actionlist_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeactions(out, name) end) +end + +-- Pseudo-opcode to mark the position where the global enum is to be emitted. +map_op[".globals_1"] = function(params) + if not params then return "prefix" end + local prefix = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobals(out, prefix) end) +end + +-- Pseudo-opcode to mark the position where the global names are to be emitted. +map_op[".globalnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobalnames(out, name) end) +end + +-- Pseudo-opcode to mark the position where the extern names are to be emitted. +map_op[".externnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeexternnames(out, name) end) +end + +------------------------------------------------------------------------------ + +-- Label pseudo-opcode (converted from trailing colon form). +map_op[".label_1"] = function(params) + if not params then return "[1-9] | ->global | =>pcexpr" end + if secpos+1 > maxsecpos then wflush() end + local mode, n, s = parse_label(params[1], true) + if mode == "EXT" then werror("bad label definition") end + waction("LABEL_"..mode, n, s, 1) +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcodes for data storage. +map_op[".long_*"] = function(params) + if not params then return "imm..." end + for _,p in ipairs(params) do + local n = tonumber(p) + if not n then werror("bad immediate `"..p.."'") end + if n < 0 then n = n + 2^32 end + wputw(n) + if secpos+2 > maxsecpos then wflush() end + end +end + +-- Alignment pseudo-opcode. +map_op[".align_1"] = function(params) + if not params then return "numpow2" end + if secpos+1 > maxsecpos then wflush() end + local align = tonumber(params[1]) + if align then + local x = align + -- Must be a power of 2 in the range (2 ... 256). + for i=1,8 do + x = x / 2 + if x == 1 then + waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1. + return + end + end + end + werror("bad alignment") +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcode for (primitive) type definitions (map to C types). +map_op[".type_3"] = function(params, nparams) + if not params then + return nparams == 2 and "name, ctype" or "name, ctype, reg" + end + local name, ctype, reg = params[1], params[2], params[3] + if not match(name, "^[%a_][%w_]*$") then + werror("bad type name `"..name.."'") + end + local tp = map_type[name] + if tp then + werror("duplicate type `"..name.."'") + end + -- Add #type to defines. A bit unclean to put it in map_archdef. + map_archdef["#"..name] = "sizeof("..ctype..")" + -- Add new type and emit shortcut define. + local num = ctypenum + 1 + map_type[name] = { + ctype = ctype, + ctypefmt = format("Dt%X(%%s)", num), + reg = reg, + } + wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype)) + ctypenum = num +end +map_op[".type_2"] = map_op[".type_3"] + +-- Dump type definitions. +local function dumptypes(out, lvl) + local t = {} + for name in pairs(map_type) do t[#t+1] = name end + sort(t) + out:write("Type definitions:\n") + for _,name in ipairs(t) do + local tp = map_type[name] + local reg = tp.reg or "" + out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Set the current section. +function _M.section(num) + waction("SECTION", num) + wflush(true) -- SECTION is a terminal action. +end + +------------------------------------------------------------------------------ + +-- Dump architecture description. +function _M.dumparch(out) + out:write(format("DynASM %s version %s, released %s\n\n", + _info.arch, _info.version, _info.release)) + dumpactions(out) +end + +-- Dump all user defined elements. +function _M.dumpdef(out, lvl) + dumptypes(out, lvl) + dumpglobals(out, lvl) + dumpexterns(out, lvl) +end + +------------------------------------------------------------------------------ + +-- Pass callbacks from/to the DynASM core. +function _M.passcb(wl, we, wf, ww) + wline, werror, wfatal, wwarn = wl, we, wf, ww + return wflush +end + +-- Setup the arch-specific module. +function _M.setup(arch, opt) + g_arch, g_opt = arch, opt +end + +-- Merge the core maps and the arch-specific maps. +function _M.mergemaps(map_coreop, map_def) + setmetatable(map_op, { __index = map_coreop }) + setmetatable(map_def, { __index = map_archdef }) + return map_op, map_def +end + +return _M + +------------------------------------------------------------------------------ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_proto.h b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_proto.h new file mode 100644 index 0000000..e77bb84 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_proto.h @@ -0,0 +1,83 @@ +/* +** DynASM encoding engine prototypes. +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** Released under the MIT license. See dynasm.lua for full copyright notice. +*/ + +#ifndef _DASM_PROTO_H +#define _DASM_PROTO_H + +#include +#include + +#define DASM_IDENT "DynASM 1.3.0" +#define DASM_VERSION 10300 /* 1.3.0 */ + +#ifndef Dst_DECL +#define Dst_DECL dasm_State **Dst +#endif + +#ifndef Dst_REF +#define Dst_REF (*Dst) +#endif + +#ifndef DASM_FDEF +#define DASM_FDEF extern +#endif + +#ifndef DASM_M_GROW +#define DASM_M_GROW(ctx, t, p, sz, need) \ + do { \ + size_t _sz = (sz), _need = (need); \ + if (_sz < _need) { \ + if (_sz < 16) _sz = 16; \ + while (_sz < _need) _sz += _sz; \ + (p) = (t *)realloc((p), _sz); \ + if ((p) == NULL) exit(1); \ + (sz) = _sz; \ + } \ + } while(0) +#endif + +#ifndef DASM_M_FREE +#define DASM_M_FREE(ctx, p, sz) free(p) +#endif + +/* Internal DynASM encoder state. */ +typedef struct dasm_State dasm_State; + + +/* Initialize and free DynASM state. */ +DASM_FDEF void dasm_init(Dst_DECL, int maxsection); +DASM_FDEF void dasm_free(Dst_DECL); + +/* Setup global array. Must be called before dasm_setup(). */ +DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl); + +/* Grow PC label array. Can be called after dasm_setup(), too. */ +DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc); + +/* Setup encoder. */ +DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist); + +/* Feed encoder with actions. Calls are generated by pre-processor. */ +DASM_FDEF void dasm_put(Dst_DECL, int start, ...); + +/* Link sections and return the resulting size. */ +DASM_FDEF int dasm_link(Dst_DECL, size_t *szp); + +/* Encode sections into buffer. */ +DASM_FDEF int dasm_encode(Dst_DECL, void *buffer); + +/* Get PC label offset. */ +DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc); + +#ifdef DASM_CHECKS +/* Optional sanity checker to call between isolated encoding steps. */ +DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch); +#else +#define dasm_checkstep(a, b) 0 +#endif + + +#endif /* _DASM_PROTO_H */ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x64.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x64.lua new file mode 100644 index 0000000..91d676d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x64.lua @@ -0,0 +1,12 @@ +------------------------------------------------------------------------------ +-- DynASM x64 module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See dynasm.lua for full copyright notice. +------------------------------------------------------------------------------ +-- This module just sets 64 bit mode for the combined x86/x64 module. +-- All the interesting stuff is there. +------------------------------------------------------------------------------ + +x64 = true -- Using a global is an ugly, but effective solution. +return require("dasm_x86") diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.h b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.h new file mode 100644 index 0000000..97cbbea --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.h @@ -0,0 +1,471 @@ +/* +** DynASM x86 encoding engine. +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** Released under the MIT license. See dynasm.lua for full copyright notice. +*/ + +#include +#include +#include +#include + +#define DASM_ARCH "x86" + +#ifndef DASM_EXTERN +#define DASM_EXTERN(a,b,c,d) 0 +#endif + +/* Action definitions. DASM_STOP must be 255. */ +enum { + DASM_DISP = 233, + DASM_IMM_S, DASM_IMM_B, DASM_IMM_W, DASM_IMM_D, DASM_IMM_WB, DASM_IMM_DB, + DASM_VREG, DASM_SPACE, DASM_SETLABEL, DASM_REL_A, DASM_REL_LG, DASM_REL_PC, + DASM_IMM_LG, DASM_IMM_PC, DASM_LABEL_LG, DASM_LABEL_PC, DASM_ALIGN, + DASM_EXTERN, DASM_ESC, DASM_MARK, DASM_SECTION, DASM_STOP +}; + +/* Maximum number of section buffer positions for a single dasm_put() call. */ +#define DASM_MAXSECPOS 25 + +/* DynASM encoder status codes. Action list offset or number are or'ed in. */ +#define DASM_S_OK 0x00000000 +#define DASM_S_NOMEM 0x01000000 +#define DASM_S_PHASE 0x02000000 +#define DASM_S_MATCH_SEC 0x03000000 +#define DASM_S_RANGE_I 0x11000000 +#define DASM_S_RANGE_SEC 0x12000000 +#define DASM_S_RANGE_LG 0x13000000 +#define DASM_S_RANGE_PC 0x14000000 +#define DASM_S_RANGE_VREG 0x15000000 +#define DASM_S_UNDEF_L 0x21000000 +#define DASM_S_UNDEF_PC 0x22000000 + +/* Macros to convert positions (8 bit section + 24 bit index). */ +#define DASM_POS2IDX(pos) ((pos)&0x00ffffff) +#define DASM_POS2BIAS(pos) ((pos)&0xff000000) +#define DASM_SEC2POS(sec) ((sec)<<24) +#define DASM_POS2SEC(pos) ((pos)>>24) +#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos)) + +/* Action list type. */ +typedef const unsigned char *dasm_ActList; + +/* Per-section structure. */ +typedef struct dasm_Section { + int *rbuf; /* Biased buffer pointer (negative section bias). */ + int *buf; /* True buffer pointer. */ + size_t bsize; /* Buffer size in bytes. */ + int pos; /* Biased buffer position. */ + int epos; /* End of biased buffer position - max single put. */ + int ofs; /* Byte offset into section. */ +} dasm_Section; + +/* Core structure holding the DynASM encoding state. */ +struct dasm_State { + size_t psize; /* Allocated size of this structure. */ + dasm_ActList actionlist; /* Current actionlist pointer. */ + int *lglabels; /* Local/global chain/pos ptrs. */ + size_t lgsize; + int *pclabels; /* PC label chains/pos ptrs. */ + size_t pcsize; + void **globals; /* Array of globals (bias -10). */ + dasm_Section *section; /* Pointer to active section. */ + size_t codesize; /* Total size of all code sections. */ + int maxsection; /* 0 <= sectionidx < maxsection. */ + int status; /* Status code. */ + dasm_Section sections[1]; /* All sections. Alloc-extended. */ +}; + +/* The size of the core structure depends on the max. number of sections. */ +#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section)) + + +/* Initialize DynASM state. */ +void dasm_init(Dst_DECL, int maxsection) +{ + dasm_State *D; + size_t psz = 0; + int i; + Dst_REF = NULL; + DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); + D = Dst_REF; + D->psize = psz; + D->lglabels = NULL; + D->lgsize = 0; + D->pclabels = NULL; + D->pcsize = 0; + D->globals = NULL; + D->maxsection = maxsection; + for (i = 0; i < maxsection; i++) { + D->sections[i].buf = NULL; /* Need this for pass3. */ + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); + D->sections[i].bsize = 0; + D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ + } +} + +/* Free DynASM state. */ +void dasm_free(Dst_DECL) +{ + dasm_State *D = Dst_REF; + int i; + for (i = 0; i < D->maxsection; i++) + if (D->sections[i].buf) + DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); + if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); + if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); + DASM_M_FREE(Dst, D, D->psize); +} + +/* Setup global label array. Must be called before dasm_setup(). */ +void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) +{ + dasm_State *D = Dst_REF; + D->globals = gl - 10; /* Negative bias to compensate for locals. */ + DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); +} + +/* Grow PC label array. Can be called after dasm_setup(), too. */ +void dasm_growpc(Dst_DECL, unsigned int maxpc) +{ + dasm_State *D = Dst_REF; + size_t osz = D->pcsize; + DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); + memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz); +} + +/* Setup encoder. */ +void dasm_setup(Dst_DECL, const void *actionlist) +{ + dasm_State *D = Dst_REF; + int i; + D->actionlist = (dasm_ActList)actionlist; + D->status = DASM_S_OK; + D->section = &D->sections[0]; + memset((void *)D->lglabels, 0, D->lgsize); + if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); + for (i = 0; i < D->maxsection; i++) { + D->sections[i].pos = DASM_SEC2POS(i); + D->sections[i].ofs = 0; + } +} + + +#ifdef DASM_CHECKS +#define CK(x, st) \ + do { if (!(x)) { \ + D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0) +#define CKPL(kind, st) \ + do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \ + D->status=DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0) +#else +#define CK(x, st) ((void)0) +#define CKPL(kind, st) ((void)0) +#endif + +/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */ +void dasm_put(Dst_DECL, int start, ...) +{ + va_list ap; + dasm_State *D = Dst_REF; + dasm_ActList p = D->actionlist + start; + dasm_Section *sec = D->section; + int pos = sec->pos, ofs = sec->ofs, mrm = 4; + int *b; + + if (pos >= sec->epos) { + DASM_M_GROW(Dst, int, sec->buf, sec->bsize, + sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); + sec->rbuf = sec->buf - DASM_POS2BIAS(pos); + sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos); + } + + b = sec->rbuf; + b[pos++] = start; + + va_start(ap, start); + while (1) { + int action = *p++; + if (action < DASM_DISP) { + ofs++; + } else if (action <= DASM_REL_A) { + int n = va_arg(ap, int); + b[pos++] = n; + switch (action) { + case DASM_DISP: + if (n == 0) { if ((mrm&7) == 4) mrm = p[-2]; if ((mrm&7) != 5) break; } + case DASM_IMM_DB: if (((n+128)&-256) == 0) goto ob; + case DASM_REL_A: /* Assumes ptrdiff_t is int. !x64 */ + case DASM_IMM_D: ofs += 4; break; + case DASM_IMM_S: CK(((n+128)&-256) == 0, RANGE_I); goto ob; + case DASM_IMM_B: CK((n&-256) == 0, RANGE_I); ob: ofs++; break; + case DASM_IMM_WB: if (((n+128)&-256) == 0) goto ob; + case DASM_IMM_W: CK((n&-65536) == 0, RANGE_I); ofs += 2; break; + case DASM_SPACE: p++; ofs += n; break; + case DASM_SETLABEL: b[pos-2] = -0x40000000; break; /* Neg. label ofs. */ + case DASM_VREG: CK((n&-8) == 0 && (n != 4 || (*p&1) == 0), RANGE_VREG); + if (*p++ == 1 && *p == DASM_DISP) mrm = n; continue; + } + mrm = 4; + } else { + int *pl, n; + switch (action) { + case DASM_REL_LG: + case DASM_IMM_LG: + n = *p++; pl = D->lglabels + n; + /* Bkwd rel or global. */ + if (n <= 246) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; } + pl -= 246; n = *pl; + if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ + goto linkrel; + case DASM_REL_PC: + case DASM_IMM_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC); + putrel: + n = *pl; + if (n < 0) { /* Label exists. Get label pos and store it. */ + b[pos] = -n; + } else { + linkrel: + b[pos] = n; /* Else link to rel chain, anchored at label. */ + *pl = pos; + } + pos++; + ofs += 4; /* Maximum offset needed. */ + if (action == DASM_REL_LG || action == DASM_REL_PC) + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel; + case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC); + putlabel: + n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; } + *pl = -pos; /* Label exists now. */ + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_ALIGN: + ofs += *p++; /* Maximum alignment needed (arg is 2**n-1). */ + b[pos++] = ofs; /* Store pass1 offset estimate. */ + break; + case DASM_EXTERN: p += 2; ofs += 4; break; + case DASM_ESC: p++; ofs++; break; + case DASM_MARK: mrm = p[-2]; break; + case DASM_SECTION: + n = *p; CK(n < D->maxsection, RANGE_SEC); D->section = &D->sections[n]; + case DASM_STOP: goto stop; + } + } + } +stop: + va_end(ap); + sec->pos = pos; + sec->ofs = ofs; +} +#undef CK + +/* Pass 2: Link sections, shrink branches/aligns, fix label offsets. */ +int dasm_link(Dst_DECL, size_t *szp) +{ + dasm_State *D = Dst_REF; + int secnum; + int ofs = 0; + +#ifdef DASM_CHECKS + *szp = 0; + if (D->status != DASM_S_OK) return D->status; + { + int pc; + for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) + if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc; + } +#endif + + { /* Handle globals not defined in this translation unit. */ + int idx; + for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) { + int n = D->lglabels[idx]; + /* Undefined label: Collapse rel chain and replace with marker (< 0). */ + while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } + } + } + + /* Combine all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->rbuf; + int pos = DASM_SEC2POS(secnum); + int lastpos = sec->pos; + + while (pos != lastpos) { + dasm_ActList p = D->actionlist + b[pos++]; + while (1) { + int op, action = *p++; + switch (action) { + case DASM_REL_LG: p++; op = p[-3]; goto rel_pc; + case DASM_REL_PC: op = p[-2]; rel_pc: { + int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0); + if (shrink) { /* Shrinkable branch opcode? */ + int lofs, lpos = b[pos]; + if (lpos < 0) goto noshrink; /* Ext global? */ + lofs = *DASM_POS2PTR(D, lpos); + if (lpos > pos) { /* Fwd label: add cumulative section offsets. */ + int i; + for (i = secnum; i < DASM_POS2SEC(lpos); i++) + lofs += D->sections[i].ofs; + } else { + lofs -= ofs; /* Bkwd label: unfix offset. */ + } + lofs -= b[pos+1]; /* Short branch ok? */ + if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink; /* Yes. */ + else { noshrink: shrink = 0; } /* No, cannot shrink op. */ + } + b[pos+1] = shrink; + pos += 2; + break; + } + case DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++; + case DASM_DISP: case DASM_IMM_S: case DASM_IMM_B: case DASM_IMM_W: + case DASM_IMM_D: case DASM_IMM_WB: case DASM_IMM_DB: + case DASM_SETLABEL: case DASM_REL_A: case DASM_IMM_PC: pos++; break; + case DASM_LABEL_LG: p++; + case DASM_LABEL_PC: b[pos++] += ofs; break; /* Fix label offset. */ + case DASM_ALIGN: ofs -= (b[pos++]+ofs)&*p++; break; /* Adjust ofs. */ + case DASM_EXTERN: p += 2; break; + case DASM_ESC: p++; break; + case DASM_MARK: break; + case DASM_SECTION: case DASM_STOP: goto stop; + } + } + stop: (void)0; + } + ofs += sec->ofs; /* Next section starts right after current section. */ + } + + D->codesize = ofs; /* Total size of all code sections */ + *szp = ofs; + return DASM_S_OK; +} + +#define dasmb(x) *cp++ = (unsigned char)(x) +#ifndef DASM_ALIGNED_WRITES +#define dasmw(x) \ + do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0) +#define dasmd(x) \ + do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0) +#else +#define dasmw(x) do { dasmb(x); dasmb((x)>>8); } while (0) +#define dasmd(x) do { dasmw(x); dasmw((x)>>16); } while (0) +#endif + +/* Pass 3: Encode sections. */ +int dasm_encode(Dst_DECL, void *buffer) +{ + dasm_State *D = Dst_REF; + unsigned char *base = (unsigned char *)buffer; + unsigned char *cp = base; + int secnum; + + /* Encode all code sections. No support for data sections (yet). */ + for (secnum = 0; secnum < D->maxsection; secnum++) { + dasm_Section *sec = D->sections + secnum; + int *b = sec->buf; + int *endb = sec->rbuf + sec->pos; + + while (b != endb) { + dasm_ActList p = D->actionlist + *b++; + unsigned char *mark = NULL; + while (1) { + int action = *p++; + int n = (action >= DASM_DISP && action <= DASM_ALIGN) ? *b++ : 0; + switch (action) { + case DASM_DISP: if (!mark) mark = cp; { + unsigned char *mm = mark; + if (*p != DASM_IMM_DB && *p != DASM_IMM_WB) mark = NULL; + if (n == 0) { int mrm = mm[-1]&7; if (mrm == 4) mrm = mm[0]&7; + if (mrm != 5) { mm[-1] -= 0x80; break; } } + if (((n+128) & -256) != 0) goto wd; else mm[-1] -= 0x40; + } + case DASM_IMM_S: case DASM_IMM_B: wb: dasmb(n); break; + case DASM_IMM_DB: if (((n+128)&-256) == 0) { + db: if (!mark) mark = cp; mark[-2] += 2; mark = NULL; goto wb; + } else mark = NULL; + case DASM_IMM_D: wd: dasmd(n); break; + case DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL; + case DASM_IMM_W: dasmw(n); break; + case DASM_VREG: { int t = *p++; if (t >= 2) n<<=3; cp[-1] |= n; break; } + case DASM_REL_LG: p++; if (n >= 0) goto rel_pc; + b++; n = (int)(ptrdiff_t)D->globals[-n]; + case DASM_REL_A: rel_a: n -= (int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */ + case DASM_REL_PC: rel_pc: { + int shrink = *b++; + int *pb = DASM_POS2PTR(D, n); if (*pb < 0) { n = pb[1]; goto rel_a; } + n = *pb - ((int)(cp-base) + 4-shrink); + if (shrink == 0) goto wd; + if (shrink == 4) { cp--; cp[-1] = *cp-0x10; } else cp[-1] = 0xeb; + goto wb; + } + case DASM_IMM_LG: + p++; if (n < 0) { n = (int)(ptrdiff_t)D->globals[-n]; goto wd; } + case DASM_IMM_PC: { + int *pb = DASM_POS2PTR(D, n); + n = *pb < 0 ? pb[1] : (*pb + (int)(ptrdiff_t)base); + goto wd; + } + case DASM_LABEL_LG: { + int idx = *p++; + if (idx >= 10) + D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n)); + break; + } + case DASM_LABEL_PC: case DASM_SETLABEL: break; + case DASM_SPACE: { int fill = *p++; while (n--) *cp++ = fill; break; } + case DASM_ALIGN: + n = *p++; + while (((cp-base) & n)) *cp++ = 0x90; /* nop */ + break; + case DASM_EXTERN: n = DASM_EXTERN(Dst, cp, p[1], *p); p += 2; goto wd; + case DASM_MARK: mark = cp; break; + case DASM_ESC: action = *p++; + default: *cp++ = action; break; + case DASM_SECTION: case DASM_STOP: goto stop; + } + } + stop: (void)0; + } + } + + if (base + D->codesize != cp) /* Check for phase errors. */ + return DASM_S_PHASE; + return DASM_S_OK; +} + +/* Get PC label offset. */ +int dasm_getpclabel(Dst_DECL, unsigned int pc) +{ + dasm_State *D = Dst_REF; + if (pc*sizeof(int) < D->pcsize) { + int pos = D->pclabels[pc]; + if (pos < 0) return *DASM_POS2PTR(D, -pos); + if (pos > 0) return -1; /* Undefined. */ + } + return -2; /* Unused or out of range. */ +} + +#ifdef DASM_CHECKS +/* Optional sanity checker to call between isolated encoding steps. */ +int dasm_checkstep(Dst_DECL, int secmatch) +{ + dasm_State *D = Dst_REF; + if (D->status == DASM_S_OK) { + int i; + for (i = 1; i <= 9; i++) { + if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_L|i; break; } + D->lglabels[i] = 0; + } + } + if (D->status == DASM_S_OK && secmatch >= 0 && + D->section != &D->sections[secmatch]) + D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections); + return D->status; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.lua new file mode 100644 index 0000000..f3859e3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dasm_x86.lua @@ -0,0 +1,1937 @@ +------------------------------------------------------------------------------ +-- DynASM x86/x64 module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See dynasm.lua for full copyright notice. +------------------------------------------------------------------------------ + +local x64 = x64 + +-- Module information: +local _info = { + arch = x64 and "x64" or "x86", + description = "DynASM x86/x64 module", + version = "1.3.0", + vernum = 10300, + release = "2011-05-05", + author = "Mike Pall", + license = "MIT", +} + +-- Exported glue functions for the arch-specific module. +local _M = { _info = _info } + +-- Cache library functions. +local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs +local assert, unpack, setmetatable = assert, unpack or table.unpack, setmetatable +local _s = string +local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char +local find, match, gmatch, gsub = _s.find, _s.match, _s.gmatch, _s.gsub +local concat, sort = table.concat, table.sort +local bit = bit or require("bit") +local band, shl, shr = bit.band, bit.lshift, bit.rshift + +-- Inherited tables and callbacks. +local g_opt, g_arch +local wline, werror, wfatal, wwarn + +-- Action name list. +-- CHECK: Keep this in sync with the C code! +local action_names = { + -- int arg, 1 buffer pos: + "DISP", "IMM_S", "IMM_B", "IMM_W", "IMM_D", "IMM_WB", "IMM_DB", + -- action arg (1 byte), int arg, 1 buffer pos (reg/num): + "VREG", "SPACE", -- !x64: VREG support NYI. + -- ptrdiff_t arg, 1 buffer pos (address): !x64 + "SETLABEL", "REL_A", + -- action arg (1 byte) or int arg, 2 buffer pos (link, offset): + "REL_LG", "REL_PC", + -- action arg (1 byte) or int arg, 1 buffer pos (link): + "IMM_LG", "IMM_PC", + -- action arg (1 byte) or int arg, 1 buffer pos (offset): + "LABEL_LG", "LABEL_PC", + -- action arg (1 byte), 1 buffer pos (offset): + "ALIGN", + -- action args (2 bytes), no buffer pos. + "EXTERN", + -- action arg (1 byte), no buffer pos. + "ESC", + -- no action arg, no buffer pos. + "MARK", + -- action arg (1 byte), no buffer pos, terminal action: + "SECTION", + -- no args, no buffer pos, terminal action: + "STOP" +} + +-- Maximum number of section buffer positions for dasm_put(). +-- CHECK: Keep this in sync with the C code! +local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines. + +-- Action name -> action number (dynamically generated below). +local map_action = {} +-- First action number. Everything below does not need to be escaped. +local actfirst = 256-#action_names + +-- Action list buffer and string (only used to remove dupes). +local actlist = {} +local actstr = "" + +-- Argument list for next dasm_put(). Start with offset 0 into action list. +local actargs = { 0 } + +-- Current number of section buffer positions for dasm_put(). +local secpos = 1 + +------------------------------------------------------------------------------ + +-- Compute action numbers for action names. +for n,name in ipairs(action_names) do + local num = actfirst + n - 1 + map_action[name] = num +end + +-- Dump action names and numbers. +local function dumpactions(out) + out:write("DynASM encoding engine action codes:\n") + for n,name in ipairs(action_names) do + local num = map_action[name] + out:write(format(" %-10s %02X %d\n", name, num, num)) + end + out:write("\n") +end + +-- Write action list buffer as a huge static C array. +local function writeactions(out, name) + local nn = #actlist + local last = actlist[nn] or 255 + actlist[nn] = nil -- Remove last byte. + if nn == 0 then nn = 1 end + out:write("static const unsigned char ", name, "[", nn, "] = {\n") + local s = " " + for n,b in ipairs(actlist) do + s = s..b.."," + if #s >= 75 then + assert(out:write(s, "\n")) + s = " " + end + end + out:write(s, last, "\n};\n\n") -- Add last byte back. +end + +------------------------------------------------------------------------------ + +-- Add byte to action list. +local function wputxb(n) + assert(n >= 0 and n <= 255 and n % 1 == 0, "byte out of range") + actlist[#actlist+1] = n +end + +-- Add action to list with optional arg. Advance buffer pos, too. +local function waction(action, a, num) + wputxb(assert(map_action[action], "bad action name `"..action.."'")) + if a then actargs[#actargs+1] = a end + if a or num then secpos = secpos + (num or 1) end +end + +-- Add call to embedded DynASM C code. +local function wcall(func, args) + wline(format("dasm_%s(Dst, %s);", func, concat(args, ", ")), true) +end + +-- Delete duplicate action list chunks. A tad slow, but so what. +local function dedupechunk(offset) + local al, as = actlist, actstr + local chunk = char(unpack(al, offset+1, #al)) + local orig = find(as, chunk, 1, true) + if orig then + actargs[1] = orig-1 -- Replace with original offset. + for i=offset+1,#al do al[i] = nil end -- Kill dupe. + else + actstr = as..chunk + end +end + +-- Flush action list (intervening C code or buffer pos overflow). +local function wflush(term) + local offset = actargs[1] + if #actlist == offset then return end -- Nothing to flush. + if not term then waction("STOP") end -- Terminate action list. + dedupechunk(offset) + wcall("put", actargs) -- Add call to dasm_put(). + actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put(). + secpos = 1 -- The actionlist offset occupies a buffer position, too. +end + +-- Put escaped byte. +local function wputb(n) + if n >= actfirst then waction("ESC") end -- Need to escape byte. + wputxb(n) +end + +------------------------------------------------------------------------------ + +-- Global label name -> global label number. With auto assignment on 1st use. +local next_global = 10 +local map_global = setmetatable({}, { __index = function(t, name) + if not match(name, "^[%a_][%w_@]*$") then werror("bad global label") end + local n = next_global + if n > 246 then werror("too many global labels") end + next_global = n + 1 + t[name] = n + return n +end}) + +-- Dump global labels. +local function dumpglobals(out, lvl) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("Global labels:\n") + for i=10,next_global-1 do + out:write(format(" %s\n", t[i])) + end + out:write("\n") +end + +-- Write global label enum. +local function writeglobals(out, prefix) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("enum {\n") + for i=10,next_global-1 do + out:write(" ", prefix, gsub(t[i], "@.*", ""), ",\n") + end + out:write(" ", prefix, "_MAX\n};\n") +end + +-- Write global label names. +local function writeglobalnames(out, name) + local t = {} + for name, n in pairs(map_global) do t[n] = name end + out:write("static const char *const ", name, "[] = {\n") + for i=10,next_global-1 do + out:write(" \"", t[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Extern label name -> extern label number. With auto assignment on 1st use. +local next_extern = -1 +local map_extern = setmetatable({}, { __index = function(t, name) + -- No restrictions on the name for now. + local n = next_extern + if n < -256 then werror("too many extern labels") end + next_extern = n - 1 + t[name] = n + return n +end}) + +-- Dump extern labels. +local function dumpexterns(out, lvl) + local t = {} + for name, n in pairs(map_extern) do t[-n] = name end + out:write("Extern labels:\n") + for i=1,-next_extern-1 do + out:write(format(" %s\n", t[i])) + end + out:write("\n") +end + +-- Write extern label names. +local function writeexternnames(out, name) + local t = {} + for name, n in pairs(map_extern) do t[-n] = name end + out:write("static const char *const ", name, "[] = {\n") + for i=1,-next_extern-1 do + out:write(" \"", t[i], "\",\n") + end + out:write(" (const char *)0\n};\n") +end + +------------------------------------------------------------------------------ + +-- Arch-specific maps. +local map_archdef = {} -- Ext. register name -> int. name. +local map_reg_rev = {} -- Int. register name -> ext. name. +local map_reg_num = {} -- Int. register name -> register number. +local map_reg_opsize = {} -- Int. register name -> operand size. +local map_reg_valid_base = {} -- Int. register name -> valid base register? +local map_reg_valid_index = {} -- Int. register name -> valid index register? +local map_reg_needrex = {} -- Int. register name -> need rex vs. no rex. +local reg_list = {} -- Canonical list of int. register names. + +local map_type = {} -- Type name -> { ctype, reg } +local ctypenum = 0 -- Type number (for _PTx macros). + +local addrsize = x64 and "q" or "d" -- Size for address operands. + +-- Helper functions to fill register maps. +local function mkrmap(sz, cl, names) + local cname = format("@%s", sz) + reg_list[#reg_list+1] = cname + map_archdef[cl] = cname + map_reg_rev[cname] = cl + map_reg_num[cname] = -1 + map_reg_opsize[cname] = sz + if sz == addrsize or sz == "d" then + map_reg_valid_base[cname] = true + map_reg_valid_index[cname] = true + end + if names then + for n,name in ipairs(names) do + local iname = format("@%s%x", sz, n-1) + reg_list[#reg_list+1] = iname + map_archdef[name] = iname + map_reg_rev[iname] = name + map_reg_num[iname] = n-1 + map_reg_opsize[iname] = sz + if sz == "b" and n > 4 then map_reg_needrex[iname] = false end + if sz == addrsize or sz == "d" then + map_reg_valid_base[iname] = true + map_reg_valid_index[iname] = true + end + end + end + for i=0,(x64 and sz ~= "f") and 15 or 7 do + local needrex = sz == "b" and i > 3 + local iname = format("@%s%x%s", sz, i, needrex and "R" or "") + if needrex then map_reg_needrex[iname] = true end + local name + if sz == "o" then name = format("xmm%d", i) + elseif sz == "f" then name = format("st%d", i) + else name = format("r%d%s", i, sz == addrsize and "" or sz) end + map_archdef[name] = iname + if not map_reg_rev[iname] then + reg_list[#reg_list+1] = iname + map_reg_rev[iname] = name + map_reg_num[iname] = i + map_reg_opsize[iname] = sz + if sz == addrsize or sz == "d" then + map_reg_valid_base[iname] = true + map_reg_valid_index[iname] = true + end + end + end + reg_list[#reg_list+1] = "" +end + +-- Integer registers (qword, dword, word and byte sized). +if x64 then + mkrmap("q", "Rq", {"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi"}) +end +mkrmap("d", "Rd", {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"}) +mkrmap("w", "Rw", {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"}) +mkrmap("b", "Rb", {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"}) +map_reg_valid_index[map_archdef.esp] = false +if x64 then map_reg_valid_index[map_archdef.rsp] = false end +map_archdef["Ra"] = "@"..addrsize + +-- FP registers (internally tword sized, but use "f" as operand size). +mkrmap("f", "Rf") + +-- SSE registers (oword sized, but qword and dword accessible). +mkrmap("o", "xmm") + +-- Operand size prefixes to codes. +local map_opsize = { + byte = "b", word = "w", dword = "d", qword = "q", oword = "o", tword = "t", + aword = addrsize, +} + +-- Operand size code to number. +local map_opsizenum = { + b = 1, w = 2, d = 4, q = 8, o = 16, t = 10, +} + +-- Operand size code to name. +local map_opsizename = { + b = "byte", w = "word", d = "dword", q = "qword", o = "oword", t = "tword", + f = "fpword", +} + +-- Valid index register scale factors. +local map_xsc = { + ["1"] = 0, ["2"] = 1, ["4"] = 2, ["8"] = 3, +} + +-- Condition codes. +local map_cc = { + o = 0, no = 1, b = 2, nb = 3, e = 4, ne = 5, be = 6, nbe = 7, + s = 8, ns = 9, p = 10, np = 11, l = 12, nl = 13, le = 14, nle = 15, + c = 2, nae = 2, nc = 3, ae = 3, z = 4, nz = 5, na = 6, a = 7, + pe = 10, po = 11, nge = 12, ge = 13, ng = 14, g = 15, +} + + +-- Reverse defines for registers. +function _M.revdef(s) + return gsub(s, "@%w+", map_reg_rev) +end + +-- Dump register names and numbers +local function dumpregs(out) + out:write("Register names, sizes and internal numbers:\n") + for _,reg in ipairs(reg_list) do + if reg == "" then + out:write("\n") + else + local name = map_reg_rev[reg] + local num = map_reg_num[reg] + local opsize = map_opsizename[map_reg_opsize[reg]] + out:write(format(" %-5s %-8s %s\n", name, opsize, + num < 0 and "(variable)" or num)) + end + end +end + +------------------------------------------------------------------------------ + +-- Put action for label arg (IMM_LG, IMM_PC, REL_LG, REL_PC). +local function wputlabel(aprefix, imm, num) + if type(imm) == "number" then + if imm < 0 then + waction("EXTERN") + wputxb(aprefix == "IMM_" and 0 or 1) + imm = -imm-1 + else + waction(aprefix.."LG", nil, num); + end + wputxb(imm) + else + waction(aprefix.."PC", imm, num) + end +end + +-- Put signed byte or arg. +local function wputsbarg(n) + if type(n) == "number" then + if n < -128 or n > 127 then + werror("signed immediate byte out of range") + end + if n < 0 then n = n + 256 end + wputb(n) + else waction("IMM_S", n) end +end + +-- Put unsigned byte or arg. +local function wputbarg(n) + if type(n) == "number" then + if n < 0 or n > 255 then + werror("unsigned immediate byte out of range") + end + wputb(n) + else waction("IMM_B", n) end +end + +-- Put unsigned word or arg. +local function wputwarg(n) + if type(n) == "number" then + if shr(n, 16) ~= 0 then + werror("unsigned immediate word out of range") + end + wputb(band(n, 255)); wputb(shr(n, 8)); + else waction("IMM_W", n) end +end + +-- Put signed or unsigned dword or arg. +local function wputdarg(n) + local tn = type(n) + if tn == "number" then + wputb(band(n, 255)) + wputb(band(shr(n, 8), 255)) + wputb(band(shr(n, 16), 255)) + wputb(shr(n, 24)) + elseif tn == "table" then + wputlabel("IMM_", n[1], 1) + else + waction("IMM_D", n) + end +end + +-- Put operand-size dependent number or arg (defaults to dword). +local function wputszarg(sz, n) + if not sz or sz == "d" or sz == "q" then wputdarg(n) + elseif sz == "w" then wputwarg(n) + elseif sz == "b" then wputbarg(n) + elseif sz == "s" then wputsbarg(n) + else werror("bad operand size") end +end + +-- Put multi-byte opcode with operand-size dependent modifications. +local function wputop(sz, op, rex) + local r + if rex ~= 0 and not x64 then werror("bad operand size") end + if sz == "w" then wputb(102) end + -- Needs >32 bit numbers, but only for crc32 eax, word [ebx] + if op >= 4294967296 then r = op%4294967296 wputb((op-r)/4294967296) op = r end + if op >= 16777216 then wputb(shr(op, 24)); op = band(op, 0xffffff) end + if op >= 65536 then + if rex ~= 0 then + local opc3 = band(op, 0xffff00) + if opc3 == 0x0f3a00 or opc3 == 0x0f3800 then + wputb(64 + band(rex, 15)); rex = 0 + end + end + wputb(shr(op, 16)); op = band(op, 0xffff) + end + if op >= 256 then + local b = shr(op, 8) + if b == 15 and rex ~= 0 then wputb(64 + band(rex, 15)); rex = 0 end + wputb(b) + op = band(op, 255) + end + if rex ~= 0 then wputb(64 + band(rex, 15)) end + if sz == "b" then op = op - 1 end + wputb(op) +end + +-- Put ModRM or SIB formatted byte. +local function wputmodrm(m, s, rm, vs, vrm) + assert(m < 4 and s < 16 and rm < 16, "bad modrm operands") + wputb(shl(m, 6) + shl(band(s, 7), 3) + band(rm, 7)) +end + +-- Put ModRM/SIB plus optional displacement. +local function wputmrmsib(t, imark, s, vsreg) + local vreg, vxreg + local reg, xreg = t.reg, t.xreg + if reg and reg < 0 then reg = 0; vreg = t.vreg end + if xreg and xreg < 0 then xreg = 0; vxreg = t.vxreg end + if s < 0 then s = 0 end + + -- Register mode. + if sub(t.mode, 1, 1) == "r" then + wputmodrm(3, s, reg) + if vsreg then waction("VREG", vsreg); wputxb(2) end + if vreg then waction("VREG", vreg); wputxb(0) end + return + end + + local disp = t.disp + local tdisp = type(disp) + -- No base register? + if not reg then + local riprel = false + if xreg then + -- Indexed mode with index register only. + -- [xreg*xsc+disp] -> (0, s, esp) (xsc, xreg, ebp) + wputmodrm(0, s, 4) + if imark == "I" then waction("MARK") end + if vsreg then waction("VREG", vsreg); wputxb(2) end + wputmodrm(t.xsc, xreg, 5) + if vxreg then waction("VREG", vxreg); wputxb(3) end + else + -- Pure 32 bit displacement. + if x64 and tdisp ~= "table" then + wputmodrm(0, s, 4) -- [disp] -> (0, s, esp) (0, esp, ebp) + if imark == "I" then waction("MARK") end + wputmodrm(0, 4, 5) + else + riprel = x64 + wputmodrm(0, s, 5) -- [disp|rip-label] -> (0, s, ebp) + if imark == "I" then waction("MARK") end + end + if vsreg then waction("VREG", vsreg); wputxb(2) end + end + if riprel then -- Emit rip-relative displacement. + if match("UWSiI", imark) then + werror("NYI: rip-relative displacement followed by immediate") + end + -- The previous byte in the action buffer cannot be 0xe9 or 0x80-0x8f. + wputlabel("REL_", disp[1], 2) + else + wputdarg(disp) + end + return + end + + local m + if tdisp == "number" then -- Check displacement size at assembly time. + if disp == 0 and band(reg, 7) ~= 5 then -- [ebp] -> [ebp+0] (in SIB, too) + if not vreg then m = 0 end -- Force DISP to allow [Rd(5)] -> [ebp+0] + elseif disp >= -128 and disp <= 127 then m = 1 + else m = 2 end + elseif tdisp == "table" then + m = 2 + end + + -- Index register present or esp as base register: need SIB encoding. + if xreg or band(reg, 7) == 4 then + wputmodrm(m or 2, s, 4) -- ModRM. + if m == nil or imark == "I" then waction("MARK") end + if vsreg then waction("VREG", vsreg); wputxb(2) end + wputmodrm(t.xsc or 0, xreg or 4, reg) -- SIB. + if vxreg then waction("VREG", vxreg); wputxb(3) end + if vreg then waction("VREG", vreg); wputxb(1) end + else + wputmodrm(m or 2, s, reg) -- ModRM. + if (imark == "I" and (m == 1 or m == 2)) or + (m == nil and (vsreg or vreg)) then waction("MARK") end + if vsreg then waction("VREG", vsreg); wputxb(2) end + if vreg then waction("VREG", vreg); wputxb(1) end + end + + -- Put displacement. + if m == 1 then wputsbarg(disp) + elseif m == 2 then wputdarg(disp) + elseif m == nil then waction("DISP", disp) end +end + +------------------------------------------------------------------------------ + +-- Return human-readable operand mode string. +local function opmodestr(op, args) + local m = {} + for i=1,#args do + local a = args[i] + m[#m+1] = sub(a.mode, 1, 1)..(a.opsize or "?") + end + return op.." "..concat(m, ",") +end + +-- Convert number to valid integer or nil. +local function toint(expr) + local n = tonumber(expr) + if n then + if n % 1 ~= 0 or n < -2147483648 or n > 4294967295 then + werror("bad integer number `"..expr.."'") + end + return n + end +end + +-- Parse immediate expression. +local function immexpr(expr) + -- &expr (pointer) + if sub(expr, 1, 1) == "&" then + return "iPJ", format("(ptrdiff_t)(%s)", sub(expr,2)) + end + + local prefix = sub(expr, 1, 2) + -- =>expr (pc label reference) + if prefix == "=>" then + return "iJ", sub(expr, 3) + end + -- ->name (global label reference) + if prefix == "->" then + return "iJ", map_global[sub(expr, 3)] + end + + -- [<>][1-9] (local label reference) + local dir, lnum = match(expr, "^([<>])([1-9])$") + if dir then -- Fwd: 247-255, Bkwd: 1-9. + return "iJ", lnum + (dir == ">" and 246 or 0) + end + + local extname = match(expr, "^extern%s+(%S+)$") + if extname then + return "iJ", map_extern[extname] + end + + -- expr (interpreted as immediate) + return "iI", expr +end + +-- Parse displacement expression: +-num, +-expr, +-opsize*num +local function dispexpr(expr) + local disp = expr == "" and 0 or toint(expr) + if disp then return disp end + local c, dispt = match(expr, "^([+-])%s*(.+)$") + if c == "+" then + expr = dispt + elseif not c then + werror("bad displacement expression `"..expr.."'") + end + local opsize, tailops = match(dispt, "^(%w+)%s*%*%s*(.+)$") + local ops, imm = map_opsize[opsize], toint(tailops) + if ops and imm then + if c == "-" then imm = -imm end + return imm*map_opsizenum[ops] + end + local mode, iexpr = immexpr(dispt) + if mode == "iJ" then + if c == "-" then werror("cannot invert label reference") end + return { iexpr } + end + return expr -- Need to return original signed expression. +end + +-- Parse register or type expression. +local function rtexpr(expr) + if not expr then return end + local tname, ovreg = match(expr, "^([%w_]+):(@[%w_]+)$") + local tp = map_type[tname or expr] + if tp then + local reg = ovreg or tp.reg + local rnum = map_reg_num[reg] + if not rnum then + werror("type `"..(tname or expr).."' needs a register override") + end + if not map_reg_valid_base[reg] then + werror("bad base register override `"..(map_reg_rev[reg] or reg).."'") + end + return reg, rnum, tp + end + return expr, map_reg_num[expr] +end + +-- Parse operand and return { mode, opsize, reg, xreg, xsc, disp, imm }. +local function parseoperand(param) + local t = {} + + local expr = param + local opsize, tailops = match(param, "^(%w+)%s*(.+)$") + if opsize then + t.opsize = map_opsize[opsize] + if t.opsize then expr = tailops end + end + + local br = match(expr, "^%[%s*(.-)%s*%]$") + repeat + if br then + t.mode = "xm" + + -- [disp] + t.disp = toint(br) + if t.disp then + t.mode = x64 and "xm" or "xmO" + break + end + + -- [reg...] + local tp + local reg, tailr = match(br, "^([@%w_:]+)%s*(.*)$") + reg, t.reg, tp = rtexpr(reg) + if not t.reg then + -- [expr] + t.mode = x64 and "xm" or "xmO" + t.disp = dispexpr("+"..br) + break + end + + if t.reg == -1 then + t.vreg, tailr = match(tailr, "^(%b())(.*)$") + if not t.vreg then werror("bad variable register expression") end + end + + -- [xreg*xsc] or [xreg*xsc+-disp] or [xreg*xsc+-expr] + local xsc, tailsc = match(tailr, "^%*%s*([1248])%s*(.*)$") + if xsc then + if not map_reg_valid_index[reg] then + werror("bad index register `"..map_reg_rev[reg].."'") + end + t.xsc = map_xsc[xsc] + t.xreg = t.reg + t.vxreg = t.vreg + t.reg = nil + t.vreg = nil + t.disp = dispexpr(tailsc) + break + end + if not map_reg_valid_base[reg] then + werror("bad base register `"..map_reg_rev[reg].."'") + end + + -- [reg] or [reg+-disp] + t.disp = toint(tailr) or (tailr == "" and 0) + if t.disp then break end + + -- [reg+xreg...] + local xreg, tailx = match(tailr, "^+%s*([@%w_:]+)%s*(.*)$") + xreg, t.xreg, tp = rtexpr(xreg) + if not t.xreg then + -- [reg+-expr] + t.disp = dispexpr(tailr) + break + end + if not map_reg_valid_index[xreg] then + werror("bad index register `"..map_reg_rev[xreg].."'") + end + + if t.xreg == -1 then + t.vxreg, tailx = match(tailx, "^(%b())(.*)$") + if not t.vxreg then werror("bad variable register expression") end + end + + -- [reg+xreg*xsc...] + local xsc, tailsc = match(tailx, "^%*%s*([1248])%s*(.*)$") + if xsc then + t.xsc = map_xsc[xsc] + tailx = tailsc + end + + -- [...] or [...+-disp] or [...+-expr] + t.disp = dispexpr(tailx) + else + -- imm or opsize*imm + local imm = toint(expr) + if not imm and sub(expr, 1, 1) == "*" and t.opsize then + imm = toint(sub(expr, 2)) + if imm then + imm = imm * map_opsizenum[t.opsize] + t.opsize = nil + end + end + if imm then + if t.opsize then werror("bad operand size override") end + local m = "i" + if imm == 1 then m = m.."1" end + if imm >= 4294967168 and imm <= 4294967295 then imm = imm-4294967296 end + if imm >= -128 and imm <= 127 then m = m.."S" end + t.imm = imm + t.mode = m + break + end + + local tp + local reg, tailr = match(expr, "^([@%w_:]+)%s*(.*)$") + reg, t.reg, tp = rtexpr(reg) + if t.reg then + if t.reg == -1 then + t.vreg, tailr = match(tailr, "^(%b())(.*)$") + if not t.vreg then werror("bad variable register expression") end + end + -- reg + if tailr == "" then + if t.opsize then werror("bad operand size override") end + t.opsize = map_reg_opsize[reg] + if t.opsize == "f" then + t.mode = t.reg == 0 and "fF" or "f" + else + if reg == "@w4" or (x64 and reg == "@d4") then + wwarn("bad idea, try again with `"..(x64 and "rsp'" or "esp'")) + end + t.mode = t.reg == 0 and "rmR" or (reg == "@b1" and "rmC" or "rm") + end + t.needrex = map_reg_needrex[reg] + break + end + + -- type[idx], type[idx].field, type->field -> [reg+offset_expr] + if not tp then werror("bad operand `"..param.."'") end + t.mode = "xm" + t.disp = format(tp.ctypefmt, tailr) + else + t.mode, t.imm = immexpr(expr) + if sub(t.mode, -1) == "J" then + if t.opsize and t.opsize ~= addrsize then + werror("bad operand size override") + end + t.opsize = addrsize + end + end + end + until true + return t +end + +------------------------------------------------------------------------------ +-- x86 Template String Description +-- =============================== +-- +-- Each template string is a list of [match:]pattern pairs, +-- separated by "|". The first match wins. No match means a +-- bad or unsupported combination of operand modes or sizes. +-- +-- The match part and the ":" is omitted if the operation has +-- no operands. Otherwise the first N characters are matched +-- against the mode strings of each of the N operands. +-- +-- The mode string for each operand type is (see parseoperand()): +-- Integer register: "rm", +"R" for eax, ax, al, +"C" for cl +-- FP register: "f", +"F" for st0 +-- Index operand: "xm", +"O" for [disp] (pure offset) +-- Immediate: "i", +"S" for signed 8 bit, +"1" for 1, +-- +"I" for arg, +"P" for pointer +-- Any: +"J" for valid jump targets +-- +-- So a match character "m" (mixed) matches both an integer register +-- and an index operand (to be encoded with the ModRM/SIB scheme). +-- But "r" matches only a register and "x" only an index operand +-- (e.g. for FP memory access operations). +-- +-- The operand size match string starts right after the mode match +-- characters and ends before the ":". "dwb" or "qdwb" is assumed, if empty. +-- The effective data size of the operation is matched against this list. +-- +-- If only the regular "b", "w", "d", "q", "t" operand sizes are +-- present, then all operands must be the same size. Unspecified sizes +-- are ignored, but at least one operand must have a size or the pattern +-- won't match (use the "byte", "word", "dword", "qword", "tword" +-- operand size overrides. E.g.: mov dword [eax], 1). +-- +-- If the list has a "1" or "2" prefix, the operand size is taken +-- from the respective operand and any other operand sizes are ignored. +-- If the list contains only ".", all operand sizes are ignored. +-- If the list has a "/" prefix, the concatenated (mixed) operand sizes +-- are compared to the match. +-- +-- E.g. "rrdw" matches for either two dword registers or two word +-- registers. "Fx2dq" matches an st0 operand plus an index operand +-- pointing to a dword (float) or qword (double). +-- +-- Every character after the ":" is part of the pattern string: +-- Hex chars are accumulated to form the opcode (left to right). +-- "n" disables the standard opcode mods +-- (otherwise: -1 for "b", o16 prefix for "w", rex.w for "q") +-- "X" Force REX.W. +-- "r"/"R" adds the reg. number from the 1st/2nd operand to the opcode. +-- "m"/"M" generates ModRM/SIB from the 1st/2nd operand. +-- The spare 3 bits are either filled with the last hex digit or +-- the result from a previous "r"/"R". The opcode is restored. +-- +-- All of the following characters force a flush of the opcode: +-- "o"/"O" stores a pure 32 bit disp (offset) from the 1st/2nd operand. +-- "S" stores a signed 8 bit immediate from the last operand. +-- "U" stores an unsigned 8 bit immediate from the last operand. +-- "W" stores an unsigned 16 bit immediate from the last operand. +-- "i" stores an operand sized immediate from the last operand. +-- "I" dito, but generates an action code to optionally modify +-- the opcode (+2) for a signed 8 bit immediate. +-- "J" generates one of the REL action codes from the last operand. +-- +------------------------------------------------------------------------------ + +-- Template strings for x86 instructions. Ordered by first opcode byte. +-- Unimplemented opcodes (deliberate omissions) are marked with *. +local map_op = { + -- 00-05: add... + -- 06: *push es + -- 07: *pop es + -- 08-0D: or... + -- 0E: *push cs + -- 0F: two byte opcode prefix + -- 10-15: adc... + -- 16: *push ss + -- 17: *pop ss + -- 18-1D: sbb... + -- 1E: *push ds + -- 1F: *pop ds + -- 20-25: and... + es_0 = "26", + -- 27: *daa + -- 28-2D: sub... + cs_0 = "2E", + -- 2F: *das + -- 30-35: xor... + ss_0 = "36", + -- 37: *aaa + -- 38-3D: cmp... + ds_0 = "3E", + -- 3F: *aas + inc_1 = x64 and "m:FF0m" or "rdw:40r|m:FF0m", + dec_1 = x64 and "m:FF1m" or "rdw:48r|m:FF1m", + push_1 = (x64 and "rq:n50r|rw:50r|mq:nFF6m|mw:FF6m" or + "rdw:50r|mdw:FF6m").."|S.:6AS|ib:n6Ai|i.:68i", + pop_1 = x64 and "rq:n58r|rw:58r|mq:n8F0m|mw:8F0m" or "rdw:58r|mdw:8F0m", + -- 60: *pusha, *pushad, *pushaw + -- 61: *popa, *popad, *popaw + -- 62: *bound rdw,x + -- 63: x86: *arpl mw,rw + movsxd_2 = x64 and "rm/qd:63rM", + fs_0 = "64", + gs_0 = "65", + o16_0 = "66", + a16_0 = not x64 and "67" or nil, + a32_0 = x64 and "67", + -- 68: push idw + -- 69: imul rdw,mdw,idw + -- 6A: push ib + -- 6B: imul rdw,mdw,S + -- 6C: *insb + -- 6D: *insd, *insw + -- 6E: *outsb + -- 6F: *outsd, *outsw + -- 70-7F: jcc lb + -- 80: add... mb,i + -- 81: add... mdw,i + -- 82: *undefined + -- 83: add... mdw,S + test_2 = "mr:85Rm|rm:85rM|Ri:A9ri|mi:F70mi", + -- 86: xchg rb,mb + -- 87: xchg rdw,mdw + -- 88: mov mb,r + -- 89: mov mdw,r + -- 8A: mov r,mb + -- 8B: mov r,mdw + -- 8C: *mov mdw,seg + lea_2 = "rx1dq:8DrM", + -- 8E: *mov seg,mdw + -- 8F: pop mdw + nop_0 = "90", + xchg_2 = "Rrqdw:90R|rRqdw:90r|rm:87rM|mr:87Rm", + cbw_0 = "6698", + cwde_0 = "98", + cdqe_0 = "4898", + cwd_0 = "6699", + cdq_0 = "99", + cqo_0 = "4899", + -- 9A: *call iw:idw + wait_0 = "9B", + fwait_0 = "9B", + pushf_0 = "9C", + pushfd_0 = not x64 and "9C", + pushfq_0 = x64 and "9C", + popf_0 = "9D", + popfd_0 = not x64 and "9D", + popfq_0 = x64 and "9D", + sahf_0 = "9E", + lahf_0 = "9F", + mov_2 = "OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi", + movsb_0 = "A4", + movsw_0 = "66A5", + movsd_0 = "A5", + cmpsb_0 = "A6", + cmpsw_0 = "66A7", + cmpsd_0 = "A7", + -- A8: test Rb,i + -- A9: test Rdw,i + stosb_0 = "AA", + stosw_0 = "66AB", + stosd_0 = "AB", + lodsb_0 = "AC", + lodsw_0 = "66AD", + lodsd_0 = "AD", + scasb_0 = "AE", + scasw_0 = "66AF", + scasd_0 = "AF", + -- B0-B7: mov rb,i + -- B8-BF: mov rdw,i + -- C0: rol... mb,i + -- C1: rol... mdw,i + ret_1 = "i.:nC2W", + ret_0 = "C3", + -- C4: *les rdw,mq + -- C5: *lds rdw,mq + -- C6: mov mb,i + -- C7: mov mdw,i + -- C8: *enter iw,ib + leave_0 = "C9", + -- CA: *retf iw + -- CB: *retf + int3_0 = "CC", + int_1 = "i.:nCDU", + into_0 = "CE", + -- CF: *iret + -- D0: rol... mb,1 + -- D1: rol... mdw,1 + -- D2: rol... mb,cl + -- D3: rol... mb,cl + -- D4: *aam ib + -- D5: *aad ib + -- D6: *salc + -- D7: *xlat + -- D8-DF: floating point ops + -- E0: *loopne + -- E1: *loope + -- E2: *loop + -- E3: *jcxz, *jecxz + -- E4: *in Rb,ib + -- E5: *in Rdw,ib + -- E6: *out ib,Rb + -- E7: *out ib,Rdw + call_1 = x64 and "mq:nFF2m|J.:E8nJ" or "md:FF2m|J.:E8J", + jmp_1 = x64 and "mq:nFF4m|J.:E9nJ" or "md:FF4m|J.:E9J", -- short: EB + -- EA: *jmp iw:idw + -- EB: jmp ib + -- EC: *in Rb,dx + -- ED: *in Rdw,dx + -- EE: *out dx,Rb + -- EF: *out dx,Rdw + lock_0 = "F0", + int1_0 = "F1", + repne_0 = "F2", + repnz_0 = "F2", + rep_0 = "F3", + repe_0 = "F3", + repz_0 = "F3", + -- F4: *hlt + cmc_0 = "F5", + -- F6: test... mb,i; div... mb + -- F7: test... mdw,i; div... mdw + clc_0 = "F8", + stc_0 = "F9", + -- FA: *cli + cld_0 = "FC", + std_0 = "FD", + -- FE: inc... mb + -- FF: inc... mdw + + -- misc ops + not_1 = "m:F72m", + neg_1 = "m:F73m", + mul_1 = "m:F74m", + imul_1 = "m:F75m", + div_1 = "m:F76m", + idiv_1 = "m:F77m", + + imul_2 = "rmqdw:0FAFrM|rIqdw:69rmI|rSqdw:6BrmS|riqdw:69rmi", + imul_3 = "rmIqdw:69rMI|rmSqdw:6BrMS|rmiqdw:69rMi", + + movzx_2 = "rm/db:0FB6rM|rm/qb:|rm/wb:0FB6rM|rm/dw:0FB7rM|rm/qw:", + movsx_2 = "rm/db:0FBErM|rm/qb:|rm/wb:0FBErM|rm/dw:0FBFrM|rm/qw:", + + bswap_1 = "rqd:0FC8r", + bsf_2 = "rmqdw:0FBCrM", + bsr_2 = "rmqdw:0FBDrM", + bt_2 = "mrqdw:0FA3Rm|miqdw:0FBA4mU", + btc_2 = "mrqdw:0FBBRm|miqdw:0FBA7mU", + btr_2 = "mrqdw:0FB3Rm|miqdw:0FBA6mU", + bts_2 = "mrqdw:0FABRm|miqdw:0FBA5mU", + + rdtsc_0 = "0F31", -- P1+ + cpuid_0 = "0FA2", -- P1+ + + -- floating point ops + fst_1 = "ff:DDD0r|xd:D92m|xq:nDD2m", + fstp_1 = "ff:DDD8r|xd:D93m|xq:nDD3m|xt:DB7m", + fld_1 = "ff:D9C0r|xd:D90m|xq:nDD0m|xt:DB5m", + + fpop_0 = "DDD8", -- Alias for fstp st0. + + fist_1 = "xw:nDF2m|xd:DB2m", + fistp_1 = "xw:nDF3m|xd:DB3m|xq:nDF7m", + fild_1 = "xw:nDF0m|xd:DB0m|xq:nDF5m", + + fxch_0 = "D9C9", + fxch_1 = "ff:D9C8r", + fxch_2 = "fFf:D9C8r|Fff:D9C8R", + + fucom_1 = "ff:DDE0r", + fucom_2 = "Fff:DDE0R", + fucomp_1 = "ff:DDE8r", + fucomp_2 = "Fff:DDE8R", + fucomi_1 = "ff:DBE8r", -- P6+ + fucomi_2 = "Fff:DBE8R", -- P6+ + fucomip_1 = "ff:DFE8r", -- P6+ + fucomip_2 = "Fff:DFE8R", -- P6+ + fcomi_1 = "ff:DBF0r", -- P6+ + fcomi_2 = "Fff:DBF0R", -- P6+ + fcomip_1 = "ff:DFF0r", -- P6+ + fcomip_2 = "Fff:DFF0R", -- P6+ + fucompp_0 = "DAE9", + fcompp_0 = "DED9", + + fldcw_1 = "xw:nD95m", + fstcw_1 = "xw:n9BD97m", + fnstcw_1 = "xw:nD97m", + fstsw_1 = "Rw:n9BDFE0|xw:n9BDD7m", + fnstsw_1 = "Rw:nDFE0|xw:nDD7m", + fclex_0 = "9BDBE2", + fnclex_0 = "DBE2", + + fnop_0 = "D9D0", + -- D9D1-D9DF: unassigned + + fchs_0 = "D9E0", + fabs_0 = "D9E1", + -- D9E2: unassigned + -- D9E3: unassigned + ftst_0 = "D9E4", + fxam_0 = "D9E5", + -- D9E6: unassigned + -- D9E7: unassigned + fld1_0 = "D9E8", + fldl2t_0 = "D9E9", + fldl2e_0 = "D9EA", + fldpi_0 = "D9EB", + fldlg2_0 = "D9EC", + fldln2_0 = "D9ED", + fldz_0 = "D9EE", + -- D9EF: unassigned + + f2xm1_0 = "D9F0", + fyl2x_0 = "D9F1", + fptan_0 = "D9F2", + fpatan_0 = "D9F3", + fxtract_0 = "D9F4", + fprem1_0 = "D9F5", + fdecstp_0 = "D9F6", + fincstp_0 = "D9F7", + fprem_0 = "D9F8", + fyl2xp1_0 = "D9F9", + fsqrt_0 = "D9FA", + fsincos_0 = "D9FB", + frndint_0 = "D9FC", + fscale_0 = "D9FD", + fsin_0 = "D9FE", + fcos_0 = "D9FF", + + -- SSE, SSE2 + andnpd_2 = "rmo:660F55rM", + andnps_2 = "rmo:0F55rM", + andpd_2 = "rmo:660F54rM", + andps_2 = "rmo:0F54rM", + clflush_1 = "x.:0FAE7m", + cmppd_3 = "rmio:660FC2rMU", + cmpps_3 = "rmio:0FC2rMU", + cmpsd_3 = "rrio:F20FC2rMU|rxi/oq:", + cmpss_3 = "rrio:F30FC2rMU|rxi/od:", + comisd_2 = "rro:660F2FrM|rx/oq:", + comiss_2 = "rro:0F2FrM|rx/od:", + cvtdq2pd_2 = "rro:F30FE6rM|rx/oq:", + cvtdq2ps_2 = "rmo:0F5BrM", + cvtpd2dq_2 = "rmo:F20FE6rM", + cvtpd2ps_2 = "rmo:660F5ArM", + cvtpi2pd_2 = "rx/oq:660F2ArM", + cvtpi2ps_2 = "rx/oq:0F2ArM", + cvtps2dq_2 = "rmo:660F5BrM", + cvtps2pd_2 = "rro:0F5ArM|rx/oq:", + cvtsd2si_2 = "rr/do:F20F2DrM|rr/qo:|rx/dq:|rxq:", + cvtsd2ss_2 = "rro:F20F5ArM|rx/oq:", + cvtsi2sd_2 = "rm/od:F20F2ArM|rm/oq:F20F2ArXM", + cvtsi2ss_2 = "rm/od:F30F2ArM|rm/oq:F30F2ArXM", + cvtss2sd_2 = "rro:F30F5ArM|rx/od:", + cvtss2si_2 = "rr/do:F20F2CrM|rr/qo:|rxd:|rx/qd:", + cvttpd2dq_2 = "rmo:660FE6rM", + cvttps2dq_2 = "rmo:F30F5BrM", + cvttsd2si_2 = "rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:", + cvttss2si_2 = "rr/do:F30F2CrM|rr/qo:|rxd:|rx/qd:", + ldmxcsr_1 = "xd:0FAE2m", + lfence_0 = "0FAEE8", + maskmovdqu_2 = "rro:660FF7rM", + mfence_0 = "0FAEF0", + movapd_2 = "rmo:660F28rM|mro:660F29Rm", + movaps_2 = "rmo:0F28rM|mro:0F29Rm", + movd_2 = "rm/od:660F6ErM|rm/oq:660F6ErXM|mr/do:660F7ERm|mr/qo:", + movdqa_2 = "rmo:660F6FrM|mro:660F7FRm", + movdqu_2 = "rmo:F30F6FrM|mro:F30F7FRm", + movhlps_2 = "rro:0F12rM", + movhpd_2 = "rx/oq:660F16rM|xr/qo:n660F17Rm", + movhps_2 = "rx/oq:0F16rM|xr/qo:n0F17Rm", + movlhps_2 = "rro:0F16rM", + movlpd_2 = "rx/oq:660F12rM|xr/qo:n660F13Rm", + movlps_2 = "rx/oq:0F12rM|xr/qo:n0F13Rm", + movmskpd_2 = "rr/do:660F50rM", + movmskps_2 = "rr/do:0F50rM", + movntdq_2 = "xro:660FE7Rm", + movnti_2 = "xrqd:0FC3Rm", + movntpd_2 = "xro:660F2BRm", + movntps_2 = "xro:0F2BRm", + movq_2 = "rro:F30F7ErM|rx/oq:|xr/qo:n660FD6Rm", + movsd_2 = "rro:F20F10rM|rx/oq:|xr/qo:nF20F11Rm", + movss_2 = "rro:F30F10rM|rx/od:|xr/do:F30F11Rm", + movupd_2 = "rmo:660F10rM|mro:660F11Rm", + movups_2 = "rmo:0F10rM|mro:0F11Rm", + orpd_2 = "rmo:660F56rM", + orps_2 = "rmo:0F56rM", + packssdw_2 = "rmo:660F6BrM", + packsswb_2 = "rmo:660F63rM", + packuswb_2 = "rmo:660F67rM", + paddb_2 = "rmo:660FFCrM", + paddd_2 = "rmo:660FFErM", + paddq_2 = "rmo:660FD4rM", + paddsb_2 = "rmo:660FECrM", + paddsw_2 = "rmo:660FEDrM", + paddusb_2 = "rmo:660FDCrM", + paddusw_2 = "rmo:660FDDrM", + paddw_2 = "rmo:660FFDrM", + pand_2 = "rmo:660FDBrM", + pandn_2 = "rmo:660FDFrM", + pause_0 = "F390", + pavgb_2 = "rmo:660FE0rM", + pavgw_2 = "rmo:660FE3rM", + pcmpeqb_2 = "rmo:660F74rM", + pcmpeqd_2 = "rmo:660F76rM", + pcmpeqw_2 = "rmo:660F75rM", + pcmpgtb_2 = "rmo:660F64rM", + pcmpgtd_2 = "rmo:660F66rM", + pcmpgtw_2 = "rmo:660F65rM", + pextrw_3 = "rri/do:660FC5rMU|xri/wo:660F3A15nrMU", -- Mem op: SSE4.1 only. + pinsrw_3 = "rri/od:660FC4rMU|rxi/ow:", + pmaddwd_2 = "rmo:660FF5rM", + pmaxsw_2 = "rmo:660FEErM", + pmaxub_2 = "rmo:660FDErM", + pminsw_2 = "rmo:660FEArM", + pminub_2 = "rmo:660FDArM", + pmovmskb_2 = "rr/do:660FD7rM", + pmulhuw_2 = "rmo:660FE4rM", + pmulhw_2 = "rmo:660FE5rM", + pmullw_2 = "rmo:660FD5rM", + pmuludq_2 = "rmo:660FF4rM", + por_2 = "rmo:660FEBrM", + prefetchnta_1 = "xb:n0F180m", + prefetcht0_1 = "xb:n0F181m", + prefetcht1_1 = "xb:n0F182m", + prefetcht2_1 = "xb:n0F183m", + psadbw_2 = "rmo:660FF6rM", + pshufd_3 = "rmio:660F70rMU", + pshufhw_3 = "rmio:F30F70rMU", + pshuflw_3 = "rmio:F20F70rMU", + pslld_2 = "rmo:660FF2rM|rio:660F726mU", + pslldq_2 = "rio:660F737mU", + psllq_2 = "rmo:660FF3rM|rio:660F736mU", + psllw_2 = "rmo:660FF1rM|rio:660F716mU", + psrad_2 = "rmo:660FE2rM|rio:660F724mU", + psraw_2 = "rmo:660FE1rM|rio:660F714mU", + psrld_2 = "rmo:660FD2rM|rio:660F722mU", + psrldq_2 = "rio:660F733mU", + psrlq_2 = "rmo:660FD3rM|rio:660F732mU", + psrlw_2 = "rmo:660FD1rM|rio:660F712mU", + psubb_2 = "rmo:660FF8rM", + psubd_2 = "rmo:660FFArM", + psubq_2 = "rmo:660FFBrM", + psubsb_2 = "rmo:660FE8rM", + psubsw_2 = "rmo:660FE9rM", + psubusb_2 = "rmo:660FD8rM", + psubusw_2 = "rmo:660FD9rM", + psubw_2 = "rmo:660FF9rM", + punpckhbw_2 = "rmo:660F68rM", + punpckhdq_2 = "rmo:660F6ArM", + punpckhqdq_2 = "rmo:660F6DrM", + punpckhwd_2 = "rmo:660F69rM", + punpcklbw_2 = "rmo:660F60rM", + punpckldq_2 = "rmo:660F62rM", + punpcklqdq_2 = "rmo:660F6CrM", + punpcklwd_2 = "rmo:660F61rM", + pxor_2 = "rmo:660FEFrM", + rcpps_2 = "rmo:0F53rM", + rcpss_2 = "rro:F30F53rM|rx/od:", + rsqrtps_2 = "rmo:0F52rM", + rsqrtss_2 = "rmo:F30F52rM", + sfence_0 = "0FAEF8", + shufpd_3 = "rmio:660FC6rMU", + shufps_3 = "rmio:0FC6rMU", + stmxcsr_1 = "xd:0FAE3m", + ucomisd_2 = "rro:660F2ErM|rx/oq:", + ucomiss_2 = "rro:0F2ErM|rx/od:", + unpckhpd_2 = "rmo:660F15rM", + unpckhps_2 = "rmo:0F15rM", + unpcklpd_2 = "rmo:660F14rM", + unpcklps_2 = "rmo:0F14rM", + xorpd_2 = "rmo:660F57rM", + xorps_2 = "rmo:0F57rM", + + -- SSE3 ops + fisttp_1 = "xw:nDF1m|xd:DB1m|xq:nDD1m", + addsubpd_2 = "rmo:660FD0rM", + addsubps_2 = "rmo:F20FD0rM", + haddpd_2 = "rmo:660F7CrM", + haddps_2 = "rmo:F20F7CrM", + hsubpd_2 = "rmo:660F7DrM", + hsubps_2 = "rmo:F20F7DrM", + lddqu_2 = "rxo:F20FF0rM", + movddup_2 = "rmo:F20F12rM", + movshdup_2 = "rmo:F30F16rM", + movsldup_2 = "rmo:F30F12rM", + + -- SSSE3 ops + pabsb_2 = "rmo:660F381CrM", + pabsd_2 = "rmo:660F381ErM", + pabsw_2 = "rmo:660F381DrM", + palignr_3 = "rmio:660F3A0FrMU", + phaddd_2 = "rmo:660F3802rM", + phaddsw_2 = "rmo:660F3803rM", + phaddw_2 = "rmo:660F3801rM", + phsubd_2 = "rmo:660F3806rM", + phsubsw_2 = "rmo:660F3807rM", + phsubw_2 = "rmo:660F3805rM", + pmaddubsw_2 = "rmo:660F3804rM", + pmulhrsw_2 = "rmo:660F380BrM", + pshufb_2 = "rmo:660F3800rM", + psignb_2 = "rmo:660F3808rM", + psignd_2 = "rmo:660F380ArM", + psignw_2 = "rmo:660F3809rM", + + -- SSE4.1 ops + blendpd_3 = "rmio:660F3A0DrMU", + blendps_3 = "rmio:660F3A0CrMU", + blendvpd_3 = "rmRo:660F3815rM", + blendvps_3 = "rmRo:660F3814rM", + dppd_3 = "rmio:660F3A41rMU", + dpps_3 = "rmio:660F3A40rMU", + extractps_3 = "mri/do:660F3A17RmU|rri/qo:660F3A17RXmU", + insertps_3 = "rrio:660F3A41rMU|rxi/od:", + movntdqa_2 = "rmo:660F382ArM", + mpsadbw_3 = "rmio:660F3A42rMU", + packusdw_2 = "rmo:660F382BrM", + pblendvb_3 = "rmRo:660F3810rM", + pblendw_3 = "rmio:660F3A0ErMU", + pcmpeqq_2 = "rmo:660F3829rM", + pextrb_3 = "rri/do:660F3A14nRmU|rri/qo:|xri/bo:", + pextrd_3 = "mri/do:660F3A16RmU", + pextrq_3 = "mri/qo:660F3A16RmU", + -- pextrw is SSE2, mem operand is SSE4.1 only + phminposuw_2 = "rmo:660F3841rM", + pinsrb_3 = "rri/od:660F3A20nrMU|rxi/ob:", + pinsrd_3 = "rmi/od:660F3A22rMU", + pinsrq_3 = "rmi/oq:660F3A22rXMU", + pmaxsb_2 = "rmo:660F383CrM", + pmaxsd_2 = "rmo:660F383DrM", + pmaxud_2 = "rmo:660F383FrM", + pmaxuw_2 = "rmo:660F383ErM", + pminsb_2 = "rmo:660F3838rM", + pminsd_2 = "rmo:660F3839rM", + pminud_2 = "rmo:660F383BrM", + pminuw_2 = "rmo:660F383ArM", + pmovsxbd_2 = "rro:660F3821rM|rx/od:", + pmovsxbq_2 = "rro:660F3822rM|rx/ow:", + pmovsxbw_2 = "rro:660F3820rM|rx/oq:", + pmovsxdq_2 = "rro:660F3825rM|rx/oq:", + pmovsxwd_2 = "rro:660F3823rM|rx/oq:", + pmovsxwq_2 = "rro:660F3824rM|rx/od:", + pmovzxbd_2 = "rro:660F3831rM|rx/od:", + pmovzxbq_2 = "rro:660F3832rM|rx/ow:", + pmovzxbw_2 = "rro:660F3830rM|rx/oq:", + pmovzxdq_2 = "rro:660F3835rM|rx/oq:", + pmovzxwd_2 = "rro:660F3833rM|rx/oq:", + pmovzxwq_2 = "rro:660F3834rM|rx/od:", + pmuldq_2 = "rmo:660F3828rM", + pmulld_2 = "rmo:660F3840rM", + ptest_2 = "rmo:660F3817rM", + roundpd_3 = "rmio:660F3A09rMU", + roundps_3 = "rmio:660F3A08rMU", + roundsd_3 = "rrio:660F3A0BrMU|rxi/oq:", + roundss_3 = "rrio:660F3A0ArMU|rxi/od:", + + -- SSE4.2 ops + crc32_2 = "rmqd:F20F38F1rM|rm/dw:66F20F38F1rM|rm/db:F20F38F0rM|rm/qb:", + pcmpestri_3 = "rmio:660F3A61rMU", + pcmpestrm_3 = "rmio:660F3A60rMU", + pcmpgtq_2 = "rmo:660F3837rM", + pcmpistri_3 = "rmio:660F3A63rMU", + pcmpistrm_3 = "rmio:660F3A62rMU", + popcnt_2 = "rmqdw:F30FB8rM", + + -- SSE4a + extrq_2 = "rro:660F79rM", + extrq_3 = "riio:660F780mUU", + insertq_2 = "rro:F20F79rM", + insertq_4 = "rriio:F20F78rMUU", + lzcnt_2 = "rmqdw:F30FBDrM", + movntsd_2 = "xr/qo:nF20F2BRm", + movntss_2 = "xr/do:F30F2BRm", + -- popcnt is also in SSE4.2 +} + +------------------------------------------------------------------------------ + +-- Arithmetic ops. +for name,n in pairs{ add = 0, ["or"] = 1, adc = 2, sbb = 3, + ["and"] = 4, sub = 5, xor = 6, cmp = 7 } do + local n8 = shl(n, 3) + map_op[name.."_2"] = format( + "mr:%02XRm|rm:%02XrM|mI1qdw:81%XmI|mS1qdw:83%XmS|Ri1qdwb:%02Xri|mi1qdwb:81%Xmi", + 1+n8, 3+n8, n, n, 5+n8, n) +end + +-- Shift ops. +for name,n in pairs{ rol = 0, ror = 1, rcl = 2, rcr = 3, + shl = 4, shr = 5, sar = 7, sal = 4 } do + map_op[name.."_2"] = format("m1:D1%Xm|mC1qdwb:D3%Xm|mi:C1%XmU", n, n, n) +end + +-- Conditional ops. +for cc,n in pairs(map_cc) do + map_op["j"..cc.."_1"] = format("J.:n0F8%XJ", n) -- short: 7%X + map_op["set"..cc.."_1"] = format("mb:n0F9%X2m", n) + map_op["cmov"..cc.."_2"] = format("rmqdw:0F4%XrM", n) -- P6+ +end + +-- FP arithmetic ops. +for name,n in pairs{ add = 0, mul = 1, com = 2, comp = 3, + sub = 4, subr = 5, div = 6, divr = 7 } do + local nc = 0xc0 + shl(n, 3) + local nr = nc + (n < 4 and 0 or (n % 2 == 0 and 8 or -8)) + local fn = "f"..name + map_op[fn.."_1"] = format("ff:D8%02Xr|xd:D8%Xm|xq:nDC%Xm", nc, n, n) + if n == 2 or n == 3 then + map_op[fn.."_2"] = format("Fff:D8%02XR|Fx2d:D8%XM|Fx2q:nDC%XM", nc, n, n) + else + map_op[fn.."_2"] = format("Fff:D8%02XR|fFf:DC%02Xr|Fx2d:D8%XM|Fx2q:nDC%XM", nc, nr, n, n) + map_op[fn.."p_1"] = format("ff:DE%02Xr", nr) + map_op[fn.."p_2"] = format("fFf:DE%02Xr", nr) + end + map_op["fi"..name.."_1"] = format("xd:DA%Xm|xw:nDE%Xm", n, n) +end + +-- FP conditional moves. +for cc,n in pairs{ b=0, e=1, be=2, u=3, nb=4, ne=5, nbe=6, nu=7 } do + local nc = 0xdac0 + shl(band(n, 3), 3) + shl(band(n, 4), 6) + map_op["fcmov"..cc.."_1"] = format("ff:%04Xr", nc) -- P6+ + map_op["fcmov"..cc.."_2"] = format("Fff:%04XR", nc) -- P6+ +end + +-- SSE FP arithmetic ops. +for name,n in pairs{ sqrt = 1, add = 8, mul = 9, + sub = 12, min = 13, div = 14, max = 15 } do + map_op[name.."ps_2"] = format("rmo:0F5%XrM", n) + map_op[name.."ss_2"] = format("rro:F30F5%XrM|rx/od:", n) + map_op[name.."pd_2"] = format("rmo:660F5%XrM", n) + map_op[name.."sd_2"] = format("rro:F20F5%XrM|rx/oq:", n) +end + +------------------------------------------------------------------------------ + +-- Process pattern string. +local function dopattern(pat, args, sz, op, needrex) + local digit, addin + local opcode = 0 + local szov = sz + local narg = 1 + local rex = 0 + + -- Limit number of section buffer positions used by a single dasm_put(). + -- A single opcode needs a maximum of 5 positions. + if secpos+5 > maxsecpos then wflush() end + + -- Process each character. + for c in gmatch(pat.."|", ".") do + if match(c, "%x") then -- Hex digit. + digit = byte(c) - 48 + if digit > 48 then digit = digit - 39 + elseif digit > 16 then digit = digit - 7 end + opcode = opcode*16 + digit + addin = nil + elseif c == "n" then -- Disable operand size mods for opcode. + szov = nil + elseif c == "X" then -- Force REX.W. + rex = 8 + elseif c == "r" then -- Merge 1st operand regno. into opcode. + addin = args[1]; opcode = opcode + (addin.reg % 8) + if narg < 2 then narg = 2 end + elseif c == "R" then -- Merge 2nd operand regno. into opcode. + addin = args[2]; opcode = opcode + (addin.reg % 8) + narg = 3 + elseif c == "m" or c == "M" then -- Encode ModRM/SIB. + local s + if addin then + s = addin.reg + opcode = opcode - band(s, 7) -- Undo regno opcode merge. + else + s = band(opcode, 15) -- Undo last digit. + opcode = shr(opcode, 4) + end + local nn = c == "m" and 1 or 2 + local t = args[nn] + if narg <= nn then narg = nn + 1 end + if szov == "q" and rex == 0 then rex = rex + 8 end + if t.reg and t.reg > 7 then rex = rex + 1 end + if t.xreg and t.xreg > 7 then rex = rex + 2 end + if s > 7 then rex = rex + 4 end + if needrex then rex = rex + 16 end + wputop(szov, opcode, rex); opcode = nil + local imark = sub(pat, -1) -- Force a mark (ugly). + -- Put ModRM/SIB with regno/last digit as spare. + wputmrmsib(t, imark, s, addin and addin.vreg) + addin = nil + else + if opcode then -- Flush opcode. + if szov == "q" and rex == 0 then rex = rex + 8 end + if needrex then rex = rex + 16 end + if addin and addin.reg == -1 then + wputop(szov, opcode - 7, rex) + waction("VREG", addin.vreg); wputxb(0) + else + if addin and addin.reg > 7 then rex = rex + 1 end + wputop(szov, opcode, rex) + end + opcode = nil + end + if c == "|" then break end + if c == "o" then -- Offset (pure 32 bit displacement). + wputdarg(args[1].disp); if narg < 2 then narg = 2 end + elseif c == "O" then + wputdarg(args[2].disp); narg = 3 + else + -- Anything else is an immediate operand. + local a = args[narg] + narg = narg + 1 + local mode, imm = a.mode, a.imm + if mode == "iJ" and not match("iIJ", c) then + werror("bad operand size for label") + end + if c == "S" then + wputsbarg(imm) + elseif c == "U" then + wputbarg(imm) + elseif c == "W" then + wputwarg(imm) + elseif c == "i" or c == "I" then + if mode == "iJ" then + wputlabel("IMM_", imm, 1) + elseif mode == "iI" and c == "I" then + waction(sz == "w" and "IMM_WB" or "IMM_DB", imm) + else + wputszarg(sz, imm) + end + elseif c == "J" then + if mode == "iPJ" then + waction("REL_A", imm) -- !x64 (secpos) + else + wputlabel("REL_", imm, 2) + end + else + werror("bad char `"..c.."' in pattern `"..pat.."' for `"..op.."'") + end + end + end + end +end + +------------------------------------------------------------------------------ + +-- Mapping of operand modes to short names. Suppress output with '#'. +local map_modename = { + r = "reg", R = "eax", C = "cl", x = "mem", m = "mrm", i = "imm", + f = "stx", F = "st0", J = "lbl", ["1"] = "1", + I = "#", S = "#", O = "#", +} + +-- Return a table/string showing all possible operand modes. +local function templatehelp(template, nparams) + if nparams == 0 then return "" end + local t = {} + for tm in gmatch(template, "[^%|]+") do + local s = map_modename[sub(tm, 1, 1)] + s = s..gsub(sub(tm, 2, nparams), ".", function(c) + return ", "..map_modename[c] + end) + if not match(s, "#") then t[#t+1] = s end + end + return t +end + +-- Match operand modes against mode match part of template. +local function matchtm(tm, args) + for i=1,#args do + if not match(args[i].mode, sub(tm, i, i)) then return end + end + return true +end + +-- Handle opcodes defined with template strings. +map_op[".template__"] = function(params, template, nparams) + if not params then return templatehelp(template, nparams) end + local args = {} + + -- Zero-operand opcodes have no match part. + if #params == 0 then + dopattern(template, args, "d", params.op, nil) + return + end + + -- Determine common operand size (coerce undefined size) or flag as mixed. + local sz, szmix, needrex + for i,p in ipairs(params) do + args[i] = parseoperand(p) + local nsz = args[i].opsize + if nsz then + if sz and sz ~= nsz then szmix = true else sz = nsz end + end + local nrex = args[i].needrex + if nrex ~= nil then + if needrex == nil then + needrex = nrex + elseif needrex ~= nrex then + werror("bad mix of byte-addressable registers") + end + end + end + + -- Try all match:pattern pairs (separated by '|'). + local gotmatch, lastpat + for tm in gmatch(template, "[^%|]+") do + -- Split off size match (starts after mode match) and pattern string. + local szm, pat = match(tm, "^(.-):(.*)$", #args+1) + if pat == "" then pat = lastpat else lastpat = pat end + if matchtm(tm, args) then + local prefix = sub(szm, 1, 1) + if prefix == "/" then -- Match both operand sizes. + if args[1].opsize == sub(szm, 2, 2) and + args[2].opsize == sub(szm, 3, 3) then + dopattern(pat, args, sz, params.op, needrex) -- Process pattern. + return + end + else -- Match common operand size. + local szp = sz + if szm == "" then szm = x64 and "qdwb" or "dwb" end -- Default sizes. + if prefix == "1" then szp = args[1].opsize; szmix = nil + elseif prefix == "2" then szp = args[2].opsize; szmix = nil end + if not szmix and (prefix == "." or match(szm, szp or "#")) then + dopattern(pat, args, szp, params.op, needrex) -- Process pattern. + return + end + end + gotmatch = true + end + end + + local msg = "bad operand mode" + if gotmatch then + if szmix then + msg = "mixed operand size" + else + msg = sz and "bad operand size" or "missing operand size" + end + end + + werror(msg.." in `"..opmodestr(params.op, args).."'") +end + +------------------------------------------------------------------------------ + +-- x64-specific opcode for 64 bit immediates and displacements. +if x64 then + function map_op.mov64_2(params) + if not params then return { "reg, imm", "reg, [disp]", "[disp], reg" } end + if secpos+2 > maxsecpos then wflush() end + local opcode, op64, sz, rex, vreg + local op64 = match(params[1], "^%[%s*(.-)%s*%]$") + if op64 then + local a = parseoperand(params[2]) + if a.mode ~= "rmR" then werror("bad operand mode") end + sz = a.opsize + rex = sz == "q" and 8 or 0 + opcode = 0xa3 + else + op64 = match(params[2], "^%[%s*(.-)%s*%]$") + local a = parseoperand(params[1]) + if op64 then + if a.mode ~= "rmR" then werror("bad operand mode") end + sz = a.opsize + rex = sz == "q" and 8 or 0 + opcode = 0xa1 + else + if sub(a.mode, 1, 1) ~= "r" or a.opsize ~= "q" then + werror("bad operand mode") + end + op64 = params[2] + if a.reg == -1 then + vreg = a.vreg + opcode = 0xb8 + else + opcode = 0xb8 + band(a.reg, 7) + end + rex = a.reg > 7 and 9 or 8 + end + end + wputop(sz, opcode, rex) + if vreg then waction("VREG", vreg); wputxb(0) end + waction("IMM_D", format("(unsigned int)(%s)", op64)) + waction("IMM_D", format("(unsigned int)((%s)>>32)", op64)) + end +end + +------------------------------------------------------------------------------ + +-- Pseudo-opcodes for data storage. +local function op_data(params) + if not params then return "imm..." end + local sz = sub(params.op, 2, 2) + if sz == "a" then sz = addrsize end + for _,p in ipairs(params) do + local a = parseoperand(p) + if sub(a.mode, 1, 1) ~= "i" or (a.opsize and a.opsize ~= sz) then + werror("bad mode or size in `"..p.."'") + end + if a.mode == "iJ" then + wputlabel("IMM_", a.imm, 1) + else + wputszarg(sz, a.imm) + end + if secpos+2 > maxsecpos then wflush() end + end +end + +map_op[".byte_*"] = op_data +map_op[".sbyte_*"] = op_data +map_op[".word_*"] = op_data +map_op[".dword_*"] = op_data +map_op[".aword_*"] = op_data + +------------------------------------------------------------------------------ + +-- Pseudo-opcode to mark the position where the action list is to be emitted. +map_op[".actionlist_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeactions(out, name) end) +end + +-- Pseudo-opcode to mark the position where the global enum is to be emitted. +map_op[".globals_1"] = function(params) + if not params then return "prefix" end + local prefix = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobals(out, prefix) end) +end + +-- Pseudo-opcode to mark the position where the global names are to be emitted. +map_op[".globalnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeglobalnames(out, name) end) +end + +-- Pseudo-opcode to mark the position where the extern names are to be emitted. +map_op[".externnames_1"] = function(params) + if not params then return "cvar" end + local name = params[1] -- No syntax check. You get to keep the pieces. + wline(function(out) writeexternnames(out, name) end) +end + +------------------------------------------------------------------------------ + +-- Label pseudo-opcode (converted from trailing colon form). +map_op[".label_2"] = function(params) + if not params then return "[1-9] | ->global | =>pcexpr [, addr]" end + if secpos+2 > maxsecpos then wflush() end + local a = parseoperand(params[1]) + local mode, imm = a.mode, a.imm + if type(imm) == "number" and (mode == "iJ" or (imm >= 1 and imm <= 9)) then + -- Local label (1: ... 9:) or global label (->global:). + waction("LABEL_LG", nil, 1) + wputxb(imm) + elseif mode == "iJ" then + -- PC label (=>pcexpr:). + waction("LABEL_PC", imm) + else + werror("bad label definition") + end + -- SETLABEL must immediately follow LABEL_LG/LABEL_PC. + local addr = params[2] + if addr then + local a = parseoperand(addr) + if a.mode == "iPJ" then + waction("SETLABEL", a.imm) + else + werror("bad label assignment") + end + end +end +map_op[".label_1"] = map_op[".label_2"] + +------------------------------------------------------------------------------ + +-- Alignment pseudo-opcode. +map_op[".align_1"] = function(params) + if not params then return "numpow2" end + if secpos+1 > maxsecpos then wflush() end + local align = tonumber(params[1]) or map_opsizenum[map_opsize[params[1]]] + if align then + local x = align + -- Must be a power of 2 in the range (2 ... 256). + for i=1,8 do + x = x / 2 + if x == 1 then + waction("ALIGN", nil, 1) + wputxb(align-1) -- Action byte is 2**n-1. + return + end + end + end + werror("bad alignment") +end + +-- Spacing pseudo-opcode. +map_op[".space_2"] = function(params) + if not params then return "num [, filler]" end + if secpos+1 > maxsecpos then wflush() end + waction("SPACE", params[1]) + local fill = params[2] + if fill then + fill = tonumber(fill) + if not fill or fill < 0 or fill > 255 then werror("bad filler") end + end + wputxb(fill or 0) +end +map_op[".space_1"] = map_op[".space_2"] + +------------------------------------------------------------------------------ + +-- Pseudo-opcode for (primitive) type definitions (map to C types). +map_op[".type_3"] = function(params, nparams) + if not params then + return nparams == 2 and "name, ctype" or "name, ctype, reg" + end + local name, ctype, reg = params[1], params[2], params[3] + if not match(name, "^[%a_][%w_]*$") then + werror("bad type name `"..name.."'") + end + local tp = map_type[name] + if tp then + werror("duplicate type `"..name.."'") + end + if reg and not map_reg_valid_base[reg] then + werror("bad base register `"..(map_reg_rev[reg] or reg).."'") + end + -- Add #type to defines. A bit unclean to put it in map_archdef. + map_archdef["#"..name] = "sizeof("..ctype..")" + -- Add new type and emit shortcut define. + local num = ctypenum + 1 + map_type[name] = { + ctype = ctype, + ctypefmt = format("Dt%X(%%s)", num), + reg = reg, + } + wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype)) + ctypenum = num +end +map_op[".type_2"] = map_op[".type_3"] + +-- Dump type definitions. +local function dumptypes(out, lvl) + local t = {} + for name in pairs(map_type) do t[#t+1] = name end + sort(t) + out:write("Type definitions:\n") + for _,name in ipairs(t) do + local tp = map_type[name] + local reg = tp.reg and map_reg_rev[tp.reg] or "" + out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Set the current section. +function _M.section(num) + waction("SECTION") + wputxb(num) + wflush(true) -- SECTION is a terminal action. +end + +------------------------------------------------------------------------------ + +-- Dump architecture description. +function _M.dumparch(out) + out:write(format("DynASM %s version %s, released %s\n\n", + _info.arch, _info.version, _info.release)) + dumpregs(out) + dumpactions(out) +end + +-- Dump all user defined elements. +function _M.dumpdef(out, lvl) + dumptypes(out, lvl) + dumpglobals(out, lvl) + dumpexterns(out, lvl) +end + +------------------------------------------------------------------------------ + +-- Pass callbacks from/to the DynASM core. +function _M.passcb(wl, we, wf, ww) + wline, werror, wfatal, wwarn = wl, we, wf, ww + return wflush +end + +-- Setup the arch-specific module. +function _M.setup(arch, opt) + g_arch, g_opt = arch, opt +end + +-- Merge the core maps and the arch-specific maps. +function _M.mergemaps(map_coreop, map_def) + setmetatable(map_op, { __index = map_coreop }) + setmetatable(map_def, { __index = map_archdef }) + return map_op, map_def +end + +return _M + +------------------------------------------------------------------------------ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dynasm.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dynasm.lua new file mode 100644 index 0000000..0ea8697 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/dynasm/dynasm.lua @@ -0,0 +1,1094 @@ +------------------------------------------------------------------------------ +-- DynASM. A dynamic assembler for code generation engines. +-- Originally designed and implemented for LuaJIT. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- See below for full copyright notice. +------------------------------------------------------------------------------ + +-- Application information. +local _info = { + name = "DynASM", + description = "A dynamic assembler for code generation engines", + version = "1.3.0", + vernum = 10300, + release = "2011-05-05", + author = "Mike Pall", + url = "http://luajit.org/dynasm.html", + license = "MIT", + copyright = [[ +Copyright (C) 2005-2014 Mike Pall. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[ MIT license: http://www.opensource.org/licenses/mit-license.php ] +]], +} + +-- Cache library functions. +local type, pairs, ipairs = type, pairs, ipairs +local pcall, error, assert = pcall, error, assert +local _s = string +local sub, match, gmatch, gsub = _s.sub, _s.match, _s.gmatch, _s.gsub +local format, rep, upper = _s.format, _s.rep, _s.upper +local _t = table +local insert, remove, concat, sort = _t.insert, _t.remove, _t.concat, _t.sort +local exit = os.exit +local io = io +local stdin, stdout, stderr = io.stdin, io.stdout, io.stderr + +------------------------------------------------------------------------------ + +-- Program options. +local g_opt = {} + +-- Global state for current file. +local g_fname, g_curline, g_indent, g_lineno, g_synclineno, g_arch +local g_errcount = 0 + +-- Write buffer for output file. +local g_wbuffer, g_capbuffer + +------------------------------------------------------------------------------ + +-- Write an output line (or callback function) to the buffer. +local function wline(line, needindent) + local buf = g_capbuffer or g_wbuffer + buf[#buf+1] = needindent and g_indent..line or line + g_synclineno = g_synclineno + 1 +end + +-- Write assembler line as a comment, if requestd. +local function wcomment(aline) + if g_opt.comment then + wline(g_opt.comment..aline..g_opt.endcomment, true) + end +end + +-- Resync CPP line numbers. +local function wsync() + if g_synclineno ~= g_lineno and g_opt.cpp then + wline("#line "..g_lineno..' "'..g_fname..'"') + g_synclineno = g_lineno + end +end + +-- Dummy action flush function. Replaced with arch-specific function later. +local function wflush(term) +end + +-- Dump all buffered output lines. +local function wdumplines(out, buf) + for _,line in ipairs(buf) do + if type(line) == "string" then + assert(out:write(line, "\n")) + else + -- Special callback to dynamically insert lines after end of processing. + line(out) + end + end +end + +------------------------------------------------------------------------------ + +-- Emit an error. Processing continues with next statement. +local function werror(msg) + error(format("%s:%s: error: %s:\n%s", g_fname, g_lineno, msg, g_curline), 0) +end + +-- Emit a fatal error. Processing stops. +local function wfatal(msg) + g_errcount = "fatal" + werror(msg) +end + +-- Print a warning. Processing continues. +local function wwarn(msg) + stderr:write(format("%s:%s: warning: %s:\n%s\n", + g_fname, g_lineno, msg, g_curline)) +end + +-- Print caught error message. But suppress excessive errors. +local function wprinterr(...) + if type(g_errcount) == "number" then + -- Regular error. + g_errcount = g_errcount + 1 + if g_errcount < 21 then -- Seems to be a reasonable limit. + stderr:write(...) + elseif g_errcount == 21 then + stderr:write(g_fname, + ":*: warning: too many errors (suppressed further messages).\n") + end + else + -- Fatal error. + stderr:write(...) + return true -- Stop processing. + end +end + +------------------------------------------------------------------------------ + +-- Map holding all option handlers. +local opt_map = {} +local opt_current + +-- Print error and exit with error status. +local function opterror(...) + stderr:write("dynasm.lua: ERROR: ", ...) + stderr:write("\n") + exit(1) +end + +-- Get option parameter. +local function optparam(args) + local argn = args.argn + local p = args[argn] + if not p then + opterror("missing parameter for option `", opt_current, "'.") + end + args.argn = argn + 1 + return p +end + +------------------------------------------------------------------------------ + +-- Core pseudo-opcodes. +local map_coreop = {} +-- Dummy opcode map. Replaced by arch-specific map. +local map_op = {} + +-- Forward declarations. +local dostmt +local readfile + +------------------------------------------------------------------------------ + +-- Map for defines (initially empty, chains to arch-specific map). +local map_def = {} + +-- Pseudo-opcode to define a substitution. +map_coreop[".define_2"] = function(params, nparams) + if not params then return nparams == 1 and "name" or "name, subst" end + local name, def = params[1], params[2] or "1" + if not match(name, "^[%a_][%w_]*$") then werror("bad or duplicate define") end + map_def[name] = def +end +map_coreop[".define_1"] = map_coreop[".define_2"] + +-- Define a substitution on the command line. +function opt_map.D(args) + local namesubst = optparam(args) + local name, subst = match(namesubst, "^([%a_][%w_]*)=(.*)$") + if name then + map_def[name] = subst + elseif match(namesubst, "^[%a_][%w_]*$") then + map_def[namesubst] = "1" + else + opterror("bad define") + end +end + +-- Undefine a substitution on the command line. +function opt_map.U(args) + local name = optparam(args) + if match(name, "^[%a_][%w_]*$") then + map_def[name] = nil + else + opterror("bad define") + end +end + +-- Helper for definesubst. +local gotsubst + +local function definesubst_one(word) + local subst = map_def[word] + if subst then gotsubst = word; return subst else return word end +end + +-- Iteratively substitute defines. +local function definesubst(stmt) + -- Limit number of iterations. + for i=1,100 do + gotsubst = false + stmt = gsub(stmt, "#?[%w_]+", definesubst_one) + if not gotsubst then break end + end + if gotsubst then wfatal("recursive define involving `"..gotsubst.."'") end + return stmt +end + +-- Dump all defines. +local function dumpdefines(out, lvl) + local t = {} + for name in pairs(map_def) do + t[#t+1] = name + end + sort(t) + out:write("Defines:\n") + for _,name in ipairs(t) do + local subst = map_def[name] + if g_arch then subst = g_arch.revdef(subst) end + out:write(format(" %-20s %s\n", name, subst)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Support variables for conditional assembly. +local condlevel = 0 +local condstack = {} + +-- Evaluate condition with a Lua expression. Substitutions already performed. +local function cond_eval(cond) + local func, err + if setfenv then + func, err = loadstring("return "..cond, "=expr") + else + -- No globals. All unknown identifiers evaluate to nil. + func, err = load("return "..cond, "=expr", "t", {}) + end + if func then + if setfenv then + setfenv(func, {}) -- No globals. All unknown identifiers evaluate to nil. + end + local ok, res = pcall(func) + if ok then + if res == 0 then return false end -- Oh well. + return not not res + end + err = res + end + wfatal("bad condition: "..err) +end + +-- Skip statements until next conditional pseudo-opcode at the same level. +local function stmtskip() + local dostmt_save = dostmt + local lvl = 0 + dostmt = function(stmt) + local op = match(stmt, "^%s*(%S+)") + if op == ".if" then + lvl = lvl + 1 + elseif lvl ~= 0 then + if op == ".endif" then lvl = lvl - 1 end + elseif op == ".elif" or op == ".else" or op == ".endif" then + dostmt = dostmt_save + dostmt(stmt) + end + end +end + +-- Pseudo-opcodes for conditional assembly. +map_coreop[".if_1"] = function(params) + if not params then return "condition" end + local lvl = condlevel + 1 + local res = cond_eval(params[1]) + condlevel = lvl + condstack[lvl] = res + if not res then stmtskip() end +end + +map_coreop[".elif_1"] = function(params) + if not params then return "condition" end + if condlevel == 0 then wfatal(".elif without .if") end + local lvl = condlevel + local res = condstack[lvl] + if res then + if res == "else" then wfatal(".elif after .else") end + else + res = cond_eval(params[1]) + if res then + condstack[lvl] = res + return + end + end + stmtskip() +end + +map_coreop[".else_0"] = function(params) + if condlevel == 0 then wfatal(".else without .if") end + local lvl = condlevel + local res = condstack[lvl] + condstack[lvl] = "else" + if res then + if res == "else" then wfatal(".else after .else") end + stmtskip() + end +end + +map_coreop[".endif_0"] = function(params) + local lvl = condlevel + if lvl == 0 then wfatal(".endif without .if") end + condlevel = lvl - 1 +end + +-- Check for unfinished conditionals. +local function checkconds() + if g_errcount ~= "fatal" and condlevel ~= 0 then + wprinterr(g_fname, ":*: error: unbalanced conditional\n") + end +end + +------------------------------------------------------------------------------ + +-- Search for a file in the given path and open it for reading. +local function pathopen(path, name) + local dirsep = package and match(package.path, "\\") and "\\" or "/" + for _,p in ipairs(path) do + local fullname = p == "" and name or p..dirsep..name + local fin = io.open(fullname, "r") + if fin then + g_fname = fullname + return fin + end + end +end + +-- Include a file. +map_coreop[".include_1"] = function(params) + if not params then return "filename" end + local name = params[1] + -- Save state. Ugly, I know. but upvalues are fast. + local gf, gl, gcl, gi = g_fname, g_lineno, g_curline, g_indent + -- Read the included file. + local fatal = readfile(pathopen(g_opt.include, name) or + wfatal("include file `"..name.."' not found")) + -- Restore state. + g_synclineno = -1 + g_fname, g_lineno, g_curline, g_indent = gf, gl, gcl, gi + if fatal then wfatal("in include file") end +end + +-- Make .include and conditionals initially available, too. +map_op[".include_1"] = map_coreop[".include_1"] +map_op[".if_1"] = map_coreop[".if_1"] +map_op[".elif_1"] = map_coreop[".elif_1"] +map_op[".else_0"] = map_coreop[".else_0"] +map_op[".endif_0"] = map_coreop[".endif_0"] + +------------------------------------------------------------------------------ + +-- Support variables for macros. +local mac_capture, mac_lineno, mac_name +local mac_active = {} +local mac_list = {} + +-- Pseudo-opcode to define a macro. +map_coreop[".macro_*"] = function(mparams) + if not mparams then return "name [, params...]" end + -- Split off and validate macro name. + local name = remove(mparams, 1) + if not name then werror("missing macro name") end + if not (match(name, "^[%a_][%w_%.]*$") or match(name, "^%.[%w_%.]*$")) then + wfatal("bad macro name `"..name.."'") + end + -- Validate macro parameter names. + local mdup = {} + for _,mp in ipairs(mparams) do + if not match(mp, "^[%a_][%w_]*$") then + wfatal("bad macro parameter name `"..mp.."'") + end + if mdup[mp] then wfatal("duplicate macro parameter name `"..mp.."'") end + mdup[mp] = true + end + -- Check for duplicate or recursive macro definitions. + local opname = name.."_"..#mparams + if map_op[opname] or map_op[name.."_*"] then + wfatal("duplicate macro `"..name.."' ("..#mparams.." parameters)") + end + if mac_capture then wfatal("recursive macro definition") end + + -- Enable statement capture. + local lines = {} + mac_lineno = g_lineno + mac_name = name + mac_capture = function(stmt) -- Statement capture function. + -- Stop macro definition with .endmacro pseudo-opcode. + if not match(stmt, "^%s*.endmacro%s*$") then + lines[#lines+1] = stmt + return + end + mac_capture = nil + mac_lineno = nil + mac_name = nil + mac_list[#mac_list+1] = opname + -- Add macro-op definition. + map_op[opname] = function(params) + if not params then return mparams, lines end + -- Protect against recursive macro invocation. + if mac_active[opname] then wfatal("recursive macro invocation") end + mac_active[opname] = true + -- Setup substitution map. + local subst = {} + for i,mp in ipairs(mparams) do subst[mp] = params[i] end + local mcom + if g_opt.maccomment and g_opt.comment then + mcom = " MACRO "..name.." ("..#mparams..")" + wcomment("{"..mcom) + end + -- Loop through all captured statements + for _,stmt in ipairs(lines) do + -- Substitute macro parameters. + local st = gsub(stmt, "[%w_]+", subst) + st = definesubst(st) + st = gsub(st, "%s*%.%.%s*", "") -- Token paste a..b. + if mcom and sub(st, 1, 1) ~= "|" then wcomment(st) end + -- Emit statement. Use a protected call for better diagnostics. + local ok, err = pcall(dostmt, st) + if not ok then + -- Add the captured statement to the error. + wprinterr(err, "\n", g_indent, "| ", stmt, + "\t[MACRO ", name, " (", #mparams, ")]\n") + end + end + if mcom then wcomment("}"..mcom) end + mac_active[opname] = nil + end + end +end + +-- An .endmacro pseudo-opcode outside of a macro definition is an error. +map_coreop[".endmacro_0"] = function(params) + wfatal(".endmacro without .macro") +end + +-- Dump all macros and their contents (with -PP only). +local function dumpmacros(out, lvl) + sort(mac_list) + out:write("Macros:\n") + for _,opname in ipairs(mac_list) do + local name = sub(opname, 1, -3) + local params, lines = map_op[opname]() + out:write(format(" %-20s %s\n", name, concat(params, ", "))) + if lvl > 1 then + for _,line in ipairs(lines) do + out:write(" |", line, "\n") + end + out:write("\n") + end + end + out:write("\n") +end + +-- Check for unfinished macro definitions. +local function checkmacros() + if mac_capture then + wprinterr(g_fname, ":", mac_lineno, + ": error: unfinished .macro `", mac_name ,"'\n") + end +end + +------------------------------------------------------------------------------ + +-- Support variables for captures. +local cap_lineno, cap_name +local cap_buffers = {} +local cap_used = {} + +-- Start a capture. +map_coreop[".capture_1"] = function(params) + if not params then return "name" end + wflush() + local name = params[1] + if not match(name, "^[%a_][%w_]*$") then + wfatal("bad capture name `"..name.."'") + end + if cap_name then + wfatal("already capturing to `"..cap_name.."' since line "..cap_lineno) + end + cap_name = name + cap_lineno = g_lineno + -- Create or continue a capture buffer and start the output line capture. + local buf = cap_buffers[name] + if not buf then buf = {}; cap_buffers[name] = buf end + g_capbuffer = buf + g_synclineno = 0 +end + +-- Stop a capture. +map_coreop[".endcapture_0"] = function(params) + wflush() + if not cap_name then wfatal(".endcapture without a valid .capture") end + cap_name = nil + cap_lineno = nil + g_capbuffer = nil + g_synclineno = 0 +end + +-- Dump a capture buffer. +map_coreop[".dumpcapture_1"] = function(params) + if not params then return "name" end + wflush() + local name = params[1] + if not match(name, "^[%a_][%w_]*$") then + wfatal("bad capture name `"..name.."'") + end + cap_used[name] = true + wline(function(out) + local buf = cap_buffers[name] + if buf then wdumplines(out, buf) end + end) + g_synclineno = 0 +end + +-- Dump all captures and their buffers (with -PP only). +local function dumpcaptures(out, lvl) + out:write("Captures:\n") + for name,buf in pairs(cap_buffers) do + out:write(format(" %-20s %4s)\n", name, "("..#buf)) + if lvl > 1 then + local bar = rep("=", 76) + out:write(" ", bar, "\n") + for _,line in ipairs(buf) do + out:write(" ", line, "\n") + end + out:write(" ", bar, "\n\n") + end + end + out:write("\n") +end + +-- Check for unfinished or unused captures. +local function checkcaptures() + if cap_name then + wprinterr(g_fname, ":", cap_lineno, + ": error: unfinished .capture `", cap_name,"'\n") + return + end + for name in pairs(cap_buffers) do + if not cap_used[name] then + wprinterr(g_fname, ":*: error: missing .dumpcapture ", name ,"\n") + end + end +end + +------------------------------------------------------------------------------ + +-- Sections names. +local map_sections = {} + +-- Pseudo-opcode to define code sections. +-- TODO: Data sections, BSS sections. Needs extra C code and API. +map_coreop[".section_*"] = function(params) + if not params then return "name..." end + if #map_sections > 0 then werror("duplicate section definition") end + wflush() + for sn,name in ipairs(params) do + local opname = "."..name.."_0" + if not match(name, "^[%a][%w_]*$") or + map_op[opname] or map_op["."..name.."_*"] then + werror("bad section name `"..name.."'") + end + map_sections[#map_sections+1] = name + wline(format("#define DASM_SECTION_%s\t%d", upper(name), sn-1)) + map_op[opname] = function(params) g_arch.section(sn-1) end + end + wline(format("#define DASM_MAXSECTION\t\t%d", #map_sections)) +end + +-- Dump all sections. +local function dumpsections(out, lvl) + out:write("Sections:\n") + for _,name in ipairs(map_sections) do + out:write(format(" %s\n", name)) + end + out:write("\n") +end + +------------------------------------------------------------------------------ + +-- Replacement for customized Lua, which lacks the package library. +local prefix = "" +if not require then + function require(name) + local fp = assert(io.open(prefix..name..".lua")) + local s = fp:read("*a") + assert(fp:close()) + return assert(loadstring(s, "@"..name..".lua"))() + end +end + +-- Load architecture-specific module. +local function loadarch(arch) + if not match(arch, "^[%w_]+$") then return "bad arch name" end + local ok, m_arch = pcall(require, "dasm_"..arch) + if not ok then return "cannot load module: "..m_arch end + g_arch = m_arch + wflush = m_arch.passcb(wline, werror, wfatal, wwarn) + m_arch.setup(arch, g_opt) + map_op, map_def = m_arch.mergemaps(map_coreop, map_def) +end + +-- Dump architecture description. +function opt_map.dumparch(args) + local name = optparam(args) + if not g_arch then + local err = loadarch(name) + if err then opterror(err) end + end + + local t = {} + for name in pairs(map_coreop) do t[#t+1] = name end + for name in pairs(map_op) do t[#t+1] = name end + sort(t) + + local out = stdout + local _arch = g_arch._info + out:write(format("%s version %s, released %s, %s\n", + _info.name, _info.version, _info.release, _info.url)) + g_arch.dumparch(out) + + local pseudo = true + out:write("Pseudo-Opcodes:\n") + for _,sname in ipairs(t) do + local name, nparam = match(sname, "^(.+)_([0-9%*])$") + if name then + if pseudo and sub(name, 1, 1) ~= "." then + out:write("\nOpcodes:\n") + pseudo = false + end + local f = map_op[sname] + local s + if nparam ~= "*" then nparam = nparam + 0 end + if nparam == 0 then + s = "" + elseif type(f) == "string" then + s = map_op[".template__"](nil, f, nparam) + else + s = f(nil, nparam) + end + if type(s) == "table" then + for _,s2 in ipairs(s) do + out:write(format(" %-12s %s\n", name, s2)) + end + else + out:write(format(" %-12s %s\n", name, s)) + end + end + end + out:write("\n") + exit(0) +end + +-- Pseudo-opcode to set the architecture. +-- Only initially available (map_op is replaced when called). +map_op[".arch_1"] = function(params) + if not params then return "name" end + local err = loadarch(params[1]) + if err then wfatal(err) end + wline(format("#if DASM_VERSION != %d", _info.vernum)) + wline('#error "Version mismatch between DynASM and included encoding engine"') + wline("#endif") +end + +-- Dummy .arch pseudo-opcode to improve the error report. +map_coreop[".arch_1"] = function(params) + if not params then return "name" end + wfatal("duplicate .arch statement") +end + +------------------------------------------------------------------------------ + +-- Dummy pseudo-opcode. Don't confuse '.nop' with 'nop'. +map_coreop[".nop_*"] = function(params) + if not params then return "[ignored...]" end +end + +-- Pseudo-opcodes to raise errors. +map_coreop[".error_1"] = function(params) + if not params then return "message" end + werror(params[1]) +end + +map_coreop[".fatal_1"] = function(params) + if not params then return "message" end + wfatal(params[1]) +end + +-- Dump all user defined elements. +local function dumpdef(out) + local lvl = g_opt.dumpdef + if lvl == 0 then return end + dumpsections(out, lvl) + dumpdefines(out, lvl) + if g_arch then g_arch.dumpdef(out, lvl) end + dumpmacros(out, lvl) + dumpcaptures(out, lvl) +end + +------------------------------------------------------------------------------ + +-- Helper for splitstmt. +local splitlvl + +local function splitstmt_one(c) + if c == "(" then + splitlvl = ")"..splitlvl + elseif c == "[" then + splitlvl = "]"..splitlvl + elseif c == "{" then + splitlvl = "}"..splitlvl + elseif c == ")" or c == "]" or c == "}" then + if sub(splitlvl, 1, 1) ~= c then werror("unbalanced (), [] or {}") end + splitlvl = sub(splitlvl, 2) + elseif splitlvl == "" then + return " \0 " + end + return c +end + +-- Split statement into (pseudo-)opcode and params. +local function splitstmt(stmt) + -- Convert label with trailing-colon into .label statement. + local label = match(stmt, "^%s*(.+):%s*$") + if label then return ".label", {label} end + + -- Split at commas and equal signs, but obey parentheses and brackets. + splitlvl = "" + stmt = gsub(stmt, "[,%(%)%[%]{}]", splitstmt_one) + if splitlvl ~= "" then werror("unbalanced () or []") end + + -- Split off opcode. + local op, other = match(stmt, "^%s*([^%s%z]+)%s*(.*)$") + if not op then werror("bad statement syntax") end + + -- Split parameters. + local params = {} + for p in gmatch(other, "%s*(%Z+)%z?") do + params[#params+1] = gsub(p, "%s+$", "") + end + if #params > 16 then werror("too many parameters") end + + params.op = op + return op, params +end + +-- Process a single statement. +dostmt = function(stmt) + -- Ignore empty statements. + if match(stmt, "^%s*$") then return end + + -- Capture macro defs before substitution. + if mac_capture then return mac_capture(stmt) end + stmt = definesubst(stmt) + + -- Emit C code without parsing the line. + if sub(stmt, 1, 1) == "|" then + local tail = sub(stmt, 2) + wflush() + if sub(tail, 1, 2) == "//" then wcomment(tail) else wline(tail, true) end + return + end + + -- Split into (pseudo-)opcode and params. + local op, params = splitstmt(stmt) + + -- Get opcode handler (matching # of parameters or generic handler). + local f = map_op[op.."_"..#params] or map_op[op.."_*"] + if not f then + if not g_arch then wfatal("first statement must be .arch") end + -- Improve error report. + for i=0,9 do + if map_op[op.."_"..i] then + werror("wrong number of parameters for `"..op.."'") + end + end + werror("unknown statement `"..op.."'") + end + + -- Call opcode handler or special handler for template strings. + if type(f) == "string" then + map_op[".template__"](params, f) + else + f(params) + end +end + +-- Process a single line. +local function doline(line) + if g_opt.flushline then wflush() end + + -- Assembler line? + local indent, aline = match(line, "^(%s*)%|(.*)$") + if not aline then + -- No, plain C code line, need to flush first. + wflush() + wsync() + wline(line, false) + return + end + + g_indent = indent -- Remember current line indentation. + + -- Emit C code (even from macros). Avoids echo and line parsing. + if sub(aline, 1, 1) == "|" then + if not mac_capture then + wsync() + elseif g_opt.comment then + wsync() + wcomment(aline) + end + dostmt(aline) + return + end + + -- Echo assembler line as a comment. + if g_opt.comment then + wsync() + wcomment(aline) + end + + -- Strip assembler comments. + aline = gsub(aline, "//.*$", "") + + -- Split line into statements at semicolons. + if match(aline, ";") then + for stmt in gmatch(aline, "[^;]+") do dostmt(stmt) end + else + dostmt(aline) + end +end + +------------------------------------------------------------------------------ + +-- Write DynASM header. +local function dasmhead(out) + out:write(format([[ +/* +** This file has been pre-processed with DynASM. +** %s +** DynASM version %s, DynASM %s version %s +** DO NOT EDIT! The original file is in "%s". +*/ + +]], _info.url, + _info.version, g_arch._info.arch, g_arch._info.version, + g_fname)) +end + +-- Read input file. +readfile = function(fin) + g_indent = "" + g_lineno = 0 + g_synclineno = -1 + + -- Process all lines. + for line in fin:lines() do + g_lineno = g_lineno + 1 + g_curline = line + local ok, err = pcall(doline, line) + if not ok and wprinterr(err, "\n") then return true end + end + wflush() + + -- Close input file. + assert(fin == stdin or fin:close()) +end + +-- Write output file. +local function writefile(outfile) + local fout + + -- Open output file. + if outfile == nil or outfile == "-" then + fout = stdout + else + fout = assert(io.open(outfile, "w")) + end + + -- Write all buffered lines + wdumplines(fout, g_wbuffer) + + -- Close output file. + assert(fout == stdout or fout:close()) + + -- Optionally dump definitions. + dumpdef(fout == stdout and stderr or stdout) +end + +-- Translate an input file to an output file. +local function translate(infile, outfile) + g_wbuffer = {} + g_indent = "" + g_lineno = 0 + g_synclineno = -1 + + -- Put header. + wline(dasmhead) + + -- Read input file. + local fin + if infile == "-" then + g_fname = "(stdin)" + fin = stdin + else + g_fname = infile + fin = assert(io.open(infile, "r")) + end + readfile(fin) + + -- Check for errors. + if not g_arch then + wprinterr(g_fname, ":*: error: missing .arch directive\n") + end + checkconds() + checkmacros() + checkcaptures() + + if g_errcount ~= 0 then + stderr:write(g_fname, ":*: info: ", g_errcount, " error", + (type(g_errcount) == "number" and g_errcount > 1) and "s" or "", + " in input file -- no output file generated.\n") + dumpdef(stderr) + exit(1) + end + + -- Write output file. + writefile(outfile) +end + +------------------------------------------------------------------------------ + +-- Print help text. +function opt_map.help() + stdout:write("DynASM -- ", _info.description, ".\n") + stdout:write("DynASM ", _info.version, " ", _info.release, " ", _info.url, "\n") + stdout:write[[ + +Usage: dynasm [OPTION]... INFILE.dasc|- + + -h, --help Display this help text. + -V, --version Display version and copyright information. + + -o, --outfile FILE Output file name (default is stdout). + -I, --include DIR Add directory to the include search path. + + -c, --ccomment Use /* */ comments for assembler lines. + -C, --cppcomment Use // comments for assembler lines (default). + -N, --nocomment Suppress assembler lines in output. + -M, --maccomment Show macro expansions as comments (default off). + + -L, --nolineno Suppress CPP line number information in output. + -F, --flushline Flush action list for every line. + + -D NAME[=SUBST] Define a substitution. + -U NAME Undefine a substitution. + + -P, --dumpdef Dump defines, macros, etc. Repeat for more output. + -A, --dumparch ARCH Load architecture ARCH and dump description. +]] + exit(0) +end + +-- Print version information. +function opt_map.version() + stdout:write(format("%s version %s, released %s\n%s\n\n%s", + _info.name, _info.version, _info.release, _info.url, _info.copyright)) + exit(0) +end + +-- Misc. options. +function opt_map.outfile(args) g_opt.outfile = optparam(args) end +function opt_map.include(args) insert(g_opt.include, 1, optparam(args)) end +function opt_map.ccomment() g_opt.comment = "/*|"; g_opt.endcomment = " */" end +function opt_map.cppcomment() g_opt.comment = "//|"; g_opt.endcomment = "" end +function opt_map.nocomment() g_opt.comment = false end +function opt_map.maccomment() g_opt.maccomment = true end +function opt_map.nolineno() g_opt.cpp = false end +function opt_map.flushline() g_opt.flushline = true end +function opt_map.dumpdef() g_opt.dumpdef = g_opt.dumpdef + 1 end + +------------------------------------------------------------------------------ + +-- Short aliases for long options. +local opt_alias = { + h = "help", ["?"] = "help", V = "version", + o = "outfile", I = "include", + c = "ccomment", C = "cppcomment", N = "nocomment", M = "maccomment", + L = "nolineno", F = "flushline", + P = "dumpdef", A = "dumparch", +} + +-- Parse single option. +local function parseopt(opt, args) + opt_current = #opt == 1 and "-"..opt or "--"..opt + local f = opt_map[opt] or opt_map[opt_alias[opt]] + if not f then + opterror("unrecognized option `", opt_current, "'. Try `--help'.\n") + end + f(args) +end + +-- Parse arguments. +local function parseargs(args) + -- Default options. + g_opt.comment = "//|" + g_opt.endcomment = "" + g_opt.cpp = true + g_opt.dumpdef = 0 + g_opt.include = { "" } + + -- Process all option arguments. + args.argn = 1 + repeat + local a = args[args.argn] + if not a then break end + local lopt, opt = match(a, "^%-(%-?)(.+)") + if not opt then break end + args.argn = args.argn + 1 + if lopt == "" then + -- Loop through short options. + for o in gmatch(opt, ".") do parseopt(o, args) end + else + -- Long option. + parseopt(opt, args) + end + until false + + -- Check for proper number of arguments. + local nargs = #args - args.argn + 1 + if nargs ~= 1 then + if nargs == 0 then + if g_opt.dumpdef > 0 then return dumpdef(stdout) end + end + opt_map.help() + end + + -- Translate a single input file to a single output file + -- TODO: Handle multiple files? + translate(args[args.argn], g_opt.outfile) +end + +------------------------------------------------------------------------------ + +-- Add the directory dynasm.lua resides in to the Lua module search path. +local arg = arg +if arg and arg[0] then + prefix = match(arg[0], "^(.*[/\\])") + if package and prefix then package.path = prefix.."?.lua;"..package.path end +end + +-- Start DynASM. +parseargs{...} + +------------------------------------------------------------------------------ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/epollnet.c b/石器时代服务器端最新完整源代码/Serv/gmsv/epollnet.c new file mode 100644 index 0000000..05a5f69 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/epollnet.c @@ -0,0 +1,261 @@ +/* + * epollnet.c + * + * Created on: 20151022 + * Author: hult + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "net.h" +#include "epollnet.h" +#include "configfile.h" +#include "version.h" + +#ifdef _EPOLL_ET_MODE +struct epoll_event *events = NULL; +int epollFd = -1; + +int epoll_init(); +int epoll_socket(int domain, int type, int protocol); +int epoll_cleanup(); + +//󶨼˿ +int epoll_bind(int port) { + + struct sockaddr_in listenAddr; + int sfd = -1; + + if (-1 == epoll_init()) { + printf("epoll_init err\n"); + return -1; + } + + if ((sfd = epoll_socket(AF_INET, SOCK_STREAM, 0)) == -1) { + printf("epoll_socket err\n"); + epoll_cleanup(); + return -1; + } + + listenAddr.sin_family = AF_INET; + listenAddr.sin_port = htons(port); + listenAddr.sin_addr.s_addr = htonl(INADDR_ANY); + + if (-1 == bind(sfd, (struct sockaddr*) &listenAddr, sizeof(listenAddr))) { + printf("bind err %d\n", errno); + epoll_cleanup(); + return -1; + } + + if (-1 == listen(sfd, 1024)) { + printf("listen err\n"); + epoll_cleanup(); + return -1; + } + + //Add bindedfd into epoll + if (-1 == epoll_new_conn(sfd)) { + printf("eph_new_conn err\n"); + close(sfd); + epoll_cleanup(); + return -1; + } + + return sfd; +} + +int epoll_init() { + if (!(events = (struct epoll_event*) malloc( + ConnectLen * sizeof(struct epoll_event)))) { + return -1; + } + + if ((epollFd = epoll_create(ConnectLen)) < 0) { + return -1; + } + + return 0; +} + +int epoll_socket(int domain, int type, int protocol) { + int sockFd = -1; + + if ((sockFd = socket(domain, type, protocol)) < 0) { + return -1; + } + //˿ڸ + if (getReuseaddr()) { + int sendbuff; + setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, (char *) &sendbuff, + sizeof(sendbuff)); + } + // + if (epoll_set_nonblock(sockFd) < 0) { + return -1; + } + + return sockFd; +} + +int epoll_set_nonblock(int fd) { + int flag = -1; + //Set Socket to non-block + if ((flag = fcntl(fd, F_GETFL, 0)) < 0 + || fcntl(fd, F_SETFL, flag | O_NONBLOCK) < 0) { + close(fd); + return -1; + } + return 0; +} + +int epoll_new_conn(int sfd) { + struct epoll_event epollEvent; + memset(&epollEvent, 0, sizeof(struct epoll_event)); + epollEvent.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLET; + epollEvent.data.fd = sfd; + + if (epoll_ctl(epollFd, EPOLL_CTL_ADD, sfd, &epollEvent) < 0) { + return -1; + } + return 0; +} + +int epoll_close_conn(int sfd) { + struct epoll_event epollEvent; + memset(&epollEvent, 0, sizeof(struct epoll_event)); + epollEvent.events = NULL; + epollEvent.data.fd = sfd; + + if (epoll_ctl(epollFd, EPOLL_CTL_DEL, sfd, &epollEvent) < 0) { + return -1; + } + return 0; +} + +int epoll_mod_read(int sfd) { + struct epoll_event epollEvent; + memset(&epollEvent, 0, sizeof(struct epoll_event)); + epollEvent.events = EPOLLIN | EPOLLHUP | EPOLLERR; + epollEvent.data.fd = sfd; + + if (epoll_ctl(epollFd, EPOLL_CTL_MOD, sfd, &epollEvent) < 0) { + return -1; + } + return 0; +} + +int epoll_mod_write(int sfd) { + struct epoll_event epollEvent; + memset(&epollEvent, 0, sizeof(struct epoll_event)); + epollEvent.events = EPOLLOUT | EPOLLHUP | EPOLLERR; + epollEvent.data.fd = sfd; + + if (epoll_ctl(epollFd, EPOLL_CTL_MOD, sfd, &epollEvent) < 0) { + return -1; + } + return 0; +} + +int epoll_cleanup() { + free(events); + close(epollFd); + return 0; +} + +//acfdӵepoll +int epoll_add_acfd(int acfd) { + if (epoll_set_nonblock(acfd) == -1) { + return -1; + } + + if (epoll_new_conn(acfd) == -1) { + return -1; + } + return 0; +} + +// +void PacketWrap_Thread(int state) { + pthread_detach(pthread_self()); + printf("Thread %d Start\n", state); + while (1) { + int i; + for (i = state; i < ConnectLen; i += _EPOLL_POOL_COUNT) { + Dispatch_read_buffer(i, state); + usleep(1); + } + } +} +//߳ +int Start_PacketWrapper() { + int i, ret; + pthread_t thread; + for (i = 0; i < _EPOLL_POOL_COUNT; i++) { + ret = pthread_create(&thread, NULL, PacketWrap_Thread, (void *) i); + if (ret != 0) { + return ret; + } + } + return 0; +} +//ѭ +void EpollLoop_Thread() { + pthread_detach(pthread_self()); + //LOOP + while (1) { + int n, i; + n = epoll_wait(epollFd, events, ConnectLen, -1); + for (i = 0; i < n; i++) { + if ((events[i].events & EPOLLERR) + || (events[i].events & EPOLLHUP)) { + CONNECT_endOne_debug(events[i].data.fd); + continue; + } else if (events[i].data.fd == bindedfd) { + while (1) { + if (doSocketAccept() == -1) { + break; + } + } + } else if (events[i].events & EPOLLIN) { + // + doSocketRecv(events[i]); + } else if (events[i].events & EPOLLOUT) { + // + doSocketSend(events[i]); + } + } + usleep(1); + } + epoll_cleanup(); +} + +//epollѭ߳ +int Start_Epoll_Loop() { + pthread_t thread; + int ret = pthread_create(&thread, NULL, EpollLoop_Thread, NULL); + return ret; +} + +//void EpollSendLoop_Thread() { +// pthread_detach(pthread_self()); +// while (1) { +// doSocketSend(); +// } +//} +// +////epoll߳ +//int Start_Epoll_SendLoop() { +// pthread_t thread; +// int ret = pthread_create(&thread, NULL, EpollSendLoop_Thread, NULL); +// return ret; +//} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/function.c b/石器时代服务器端最新完整源代码/Serv/gmsv/function.c new file mode 100644 index 0000000..f742757 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/function.c @@ -0,0 +1,881 @@ +#include "version.h" +#include +#include "common.h" +#include "util.h" +#include "char_event.h" +#include "char.h" +#include "item_event.h" +#include "magic.h" +#include "pet_event.h" +#include "npc_townpeople.h" +#include "npc_Dengon.h" +#include "npc_door.h" +#include "npc_healer.h" +#include "npc_oldman.h" +#include "npc_warp.h" +#include "npc_storyteller.h" +#include "npc_msg.h" +#include "npc_npcenemy.h" +#include "npc_action.h" +#include "npc_windowman.h" +#include "npc_savepoint.h" +#include "npc_windowhealer.h" +#include "npc_itemshop.h" +#include "npc_sysinfo.h" +#include "npc_duelranking.h" +#include "npc_petskillshop.h" +#include "npc_petshop.h" +#include "npc_signboard.h" +#include "npc_warpman.h" +#include "npc_exchangeman.h" +#include "petmail.h" +#include "npc_timeman.h" +#include "npc_bodylan.h" +#include "npc_mic.h" +#include "npc_luckyman.h" +#include "npc_bus.h" +#include "npc_charm.h" +#include "npc_poolitemshop.h" +#include "npc_quiz.h" +#include "npc_checkman.h" +#include "npc_janken.h" +#include "npc_transmigration.h" +#include "battle_event.h" +#include "enemy.h" +// Robin 0517 +#include "npc_familyman.h" +#include "npc_bankman.h" +// add code by shan +#include "npc_fmdengon.h" +#include "npc_fmhealer.h" +#include "npc_petmaker.h" + +// CoolFish: Family 2001/6/4 +#include "npc_fmwarpman.h" +#include "npc_fmpkman.h" +#include "npc_fmpkcallman.h" + +// Arminius 7.7 Airplane +#include "npc_airplane.h" + +// Arminius 7.13 Scheduleman +#include "npc_scheduleman.h" + +// Arminius 7.24 manor scheduleman +#include "npc_manorsman.h" + +// Robin 0725 +#include "npc_riderman.h" +#include "npc_fmletter.h" + +#ifdef _GAMBLE_BANK +#include "npc_gamblebank.h" +#endif +#ifdef _NEW_WARPMAN +#include "npc_newnpcman.h" +#endif + +#ifdef _GAMBLE_ROULETTE +#include "npc_gambleroulette.h" +#include "npc_gamblemaster.h" +#endif + +#ifdef _TRANSER_MAN +#include "npc_transerman.h" +#endif + +#ifdef _VIP_SHOP +#include "npc_vipshop.h" +#endif + +#ifdef _NEW_VIP_SHOP +#include "npc_newvipshop.h" +#endif + +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#ifdef _PAUCTION_MAN +#include "npc_pauctionman.h" +#endif + +#ifdef _CFREE_petskill +#include "npc_freepetskillshop.h" +#endif + +#ifdef _PETRACE +#include "npc_petracemaster.h" +#include "npc_petracepet.h" +#endif + +#ifdef _ITEM_NPCCHANGE +#include "npc_itemchange.h" +#endif + +#ifdef _NPC_MAKEPAIR +#include "npc_makepair.h" +#endif + +#ifdef _NPC_FUSION +#include "npc_petfusion.h" +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +#include "npc_alldoman.h" +#endif + +#ifdef _NPC_WELFARE +#include "npc_welfare.h" +#endif +#ifdef _NPC_MAGICCARD +#include "npc_magiccard.h" +#endif +//#define DEBUG +#ifdef _JZ_NEWSCRIPT_LUA +#include "npc_lua_interface.h" +#endif +typedef struct tagCorrespondStringAndFunctionTable +{ + STRING32 functionName; + void* functionPointer; + int hashcode; +}CorrespondStringAndFunctionTable; + +static CorrespondStringAndFunctionTable +correspondStringAndFunctionTable[]= +{ + { {"core_PreWalk"}, CHAR_allprewalk, 0 }, + { {"core_PostWalk"}, CHAR_allpostwalk, 0 }, + { {"core_Loop"}, CHAR_loopFunc, 0 }, + { {"core_Dying"}, CHAR_die, 0 }, + { {"core_PlayerWatch"}, CHAR_playerWatchfunc, 0 }, + { {"core_PlayerTalked"}, CHAR_playerTalkedfunc, 0 }, + + + { {"MedicineInit"}, ITEM_MedicineInit, 0 }, + { {"MedicineUsed"}, ITEM_MedicineUsed, 0 }, + { {"SandClockDetach"}, ITEM_SandClockDetach, 0 }, + { {"addTitleAttach"}, ITEM_addTitleAttach, 0 }, + { {"delTitleDetach"}, ITEM_delTitleDetach, 0 }, + { {"ITEM_DeleteByWatched"}, ITEM_DeleteByWatched, 0 }, + { {"ITEM_DeleteTimeWatched"}, ITEM_DeleteTimeWatched, 0 }, + { {"ITEM_useEffectTohelos"}, ITEM_useEffectTohelos, 0 }, + +// { {"ITEM_useHpRecovery"}, ITEM_useHpRecovery, 0 }, + { {"ITEM_useRecovery"}, ITEM_useRecovery, 0 }, +#ifdef _ITEM_MAGICRECOVERY + { {"ITEM_useMRecovery"}, ITEM_useMRecovery, 0 }, +#endif +#ifdef _ITEM_USEMAGIC + { {"ITEM_useMagic"}, ITEM_useMagic, 0 }, +#endif + { {"ITEM_useStatusChange"}, ITEM_useStatusChange, 0 }, + { {"ITEM_useStatusRecovery"}, ITEM_useStatusRecovery, 0 }, + { {"ITEM_useMagicDef"}, ITEM_useMagicDef, 0 }, + { {"ITEM_useParamChange"}, ITEM_useParamChange, 0 }, + { {"ITEM_useFieldChange"}, ITEM_useFieldChange, 0 }, + { {"ITEM_useAttReverse"}, ITEM_useAttReverse, 0 }, + { {"ITEM_useRessurect"}, ITEM_useRessurect, 0 }, + { {"ITEM_useMic"}, ITEM_useMic, 0 }, + { {"ITEM_dropMic"}, ITEM_dropMic, 0 }, + { {"ITEM_useCaptureUp"}, ITEM_useCaptureUp, 0 }, + { {"ITEM_useRenameItem"}, ITEM_useRenameItem, 0 }, + { {"ITEM_pickupDice"}, ITEM_pickupDice, 0 }, + { {"ITEM_dropDice"}, ITEM_dropDice, 0 }, + { {"ITEM_initLottery"}, ITEM_initLottery, 0 }, + { {"ITEM_useLottery"}, ITEM_useLottery, 0 }, + { {"ITEM_useWarp"}, ITEM_useWarp, 0 }, + { {"ITEM_petFollow"}, ITEM_petFollow, 0 }, +#ifdef _PETFOLLOW_NEW_ + { {"ITEM_petFollowNew"}, ITEM_petFollowNew, 0 }, +#endif + { {"ITEM_useSkup"}, ITEM_useSkup, 0 }, // Nuke 0624: Hero's bless + { {"ITEM_useNoenemy"}, ITEM_useNoenemy, 0 }, // Nuke 0626: Dragon's help + { {"ITEM_equipNoenemy"},ITEM_equipNoenemy, 0 }, // Arminius 7.2 Ra's amulet + { {"ITEM_remNoenemy"}, ITEM_remNoenemy, 0 }, // Arminius 7.2 Ra's amulet + { {"ITEM_useEncounter"}, ITEM_useEncounter, 0}, // Arminius 7.31 cursed stone + + { {"ITEM_AddPRSkillPoint"}, ITEM_AddPRSkillPoint, 0}, + { {"ITEM_AddPRSkillPercent"}, ITEM_AddPRSkillPercent, 0}, + +#ifdef _ITEM_METAMO + { {"ITEM_metamo"}, ITEM_metamo, 0 }, + { {"ITEM_ColorMetamo"}, ITEM_ColorMetamo, 0 }, + { {"ITEM_CharaMetamo"}, ITEM_CharaMetamo, 0 }, + { {"ITEM_SexMetamo"}, ITEM_SexMetamo, 0 }, +#endif + +#ifdef _USEWARP_FORNUM + { {"ITEM_useWarpForNum"}, ITEM_useWarpForNum, 0 }, +#endif + +#ifdef _IMPRECATE_ITEM + { {"ITEM_useImprecate"}, ITEM_useImprecate, 0 }, +#endif +#ifdef _ITEM_FIRECRACKER //Terry add 2001/12/21 + { {"ITEM_firecracker"}, ITEM_firecracker, 0 }, +#endif +#ifdef _ITEM_CRACKER //vincent + { {"ITEM_Cracker"}, ITEM_Cracker, 0 }, +#endif +#ifdef _ITEM_ADDEXP //vincent + { {"ITEM_Addexp"}, ITEM_Addexp, 0 }, +#endif +#ifdef _ITEM_REFRESH //vincent 쳣״̬ + { {"ITEM_Refresh"}, ITEM_Refresh, 0 }, +#endif + + { {"ITEM_WearEquip"}, ITEM_WearEquip, 0 }, + { {"ITEM_ReWearEquip"}, ITEM_ReWearEquip, 0 }, + +#ifdef _ITEM_CONSTITUTION + { {"ITEM_Constitution"}, ITEM_Constitution, 0 }, +#endif + +#ifdef _Item_ReLifeAct + { {"ITEM_DIErelife"}, ITEM_DIErelife, 0 }, +#endif + +#ifdef _ITEM_ORNAMENTS + { {"ITEM_PutOrnaments"}, ITEM_PutOrnaments, 0}, +#endif +#ifdef _CHIKULA_STONE + { {"ITEM_ChikulaStone"}, ITEM_ChikulaStone, 0}, +#endif + +#ifdef _THROWITEM_ITEMS + { {"ITEM_ThrowItemBox"}, ITEM_ThrowItemBox, 0}, +#endif + +#ifdef _ITEM_WATERWORDSTATUS + { {"ITEM_WaterWordStatus"}, ITEM_WaterWordStatus, 0}, +#endif + +#ifdef _ITEM_LOVERPARTY + { {"ITEM_LoverSelectUser"}, ITEM_LoverSelectUser, 0}, +#endif + +#ifdef _Item_MoonAct + { {"ITEM_randEnemyEquipOne"}, ITEM_randEnemyEquipOne, 0 }, + + { {"ITEM_randEnemyEquip"}, ITEM_randEnemyEquip, 0 }, + { {"ITEM_RerandEnemyEquip"}, ITEM_RerandEnemyEquip, 0}, +#endif + +#ifdef _SUIT_ITEM + { {"ITEM_suitEquip"}, ITEM_suitEquip, 0 }, + { {"ITEM_ResuitEquip"}, ITEM_ResuitEquip, 0 }, +#endif + +#ifdef _Item_DeathAct + { {"ITEM_useDeathcounter"}, ITEM_UseDeathCounter, 0 }, +#endif +#ifdef _FEV_ADD_NEW_ITEM // FEV ADD Ӹؾ + { {"ITEM_ResAndDef"} , ITEM_ResAndDef, 0 }, +#endif + +#ifdef _CHRISTMAS_REDSOCKS + { {"ITEM_useMaxRedSocks"}, ITEM_useMaxRedSocks, 0 }, +#endif + +#ifdef _CHRISTMAS_REDSOCKS_NEW + { {"ITEM_useMaxRedSocksNew"}, ITEM_useMaxRedSocksNew, 0 }, +#endif + +#ifdef _PETSKILL_CANNEDFOOD + { {"ITEM_useSkillCanned"}, ITEM_useSkillCanned, 0}, +#endif + +#ifdef _NEW_RIDEPETS + { {"ITEM_useLearnRideCode"}, ITEM_useLearnRideCode, 0 }, +#endif + +#ifdef _EQUIT_DEFMAGIC + { {"ITEM_MagicEquitWear"}, ITEM_MagicEquitWear, 0 }, + { {"ITEM_MagicEquitReWear"}, ITEM_MagicEquitReWear, 0 }, +#endif +#ifdef _EQUIT_RESIST + { {"ITEM_MagicResist"}, ITEM_MagicResist, 0 }, + { {"ITEM_MagicReResist"}, ITEM_MagicReResist, 0 }, +#endif + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + { {"ITEM_P_MagicEquitWear"}, ITEM_P_MagicEquitWear, 0 }, + { {"ITEM_P_MagicEquitReWear"}, ITEM_P_MagicEquitReWear, 0 }, +#endif + +#ifdef _ANGEL_SUMMON + { {"ITEM_AngelToken"}, ITEM_AngelToken, 0 }, + { {"ITEM_HeroToken"}, ITEM_HeroToken, 0 }, +#endif +#ifdef _HALLOWEEN_EFFECT + { {"ITEM_MapEffect"}, ITEM_MapEffect, 0 }, +#endif + { {"ITEM_USE_LUA"},ITEM_Lua,0}, + { {"ITEM_changePetOwner"}, ITEM_changePetOwner, 0 }, + + { {"core_PetWatch"}, PET_Watchfunc, 0 }, + { {"PETMAIL_Loop"}, PETMAIL_Loopfunc, 0 }, +#ifdef _USER_CHARLOOPS + { {"CHAR_BattleStayLoop"}, CHAR_BattleStayLoop, 0 }, +#ifdef _PET_EVOLUTION + { {"PET_CheckIncubateLoop"}, PET_CheckIncubate, 0 }, +#endif +#endif + +#ifdef _PETSKILL_PROPERTY + { {"PET_PetskillPropertyEvent"}, PET_PetskillPropertyEvent, 0 }, +#endif + { {"core_PetTalk"}, PET_Talkfunc, 0}, // Arminius 8.14 pet talk + + + /* warp */ + { {"WarpInit"}, NPC_WarpInit, 0 }, + { {"WarpPostOver"}, NPC_WarpPostOver, 0 }, + { {"WarpWatch"}, NPC_WarpWatch, 0 }, + + /* Dengon */ + { {"DengonInit"}, NPC_DengonInit, 0 }, + { {"DengonWindowTalked"}, NPC_DengonWindowTalked, 0 }, + { {"DengonLooked"}, NPC_DengonLooked, 0 }, + + /* FmDengon add code by shan */ + { {"FmDengonInit"}, NPC_FmDengonInit, 0 }, + { {"FmDengonWindowTalked"}, NPC_FmDengonWindowTalked, 0 }, + { {"FmDengonLooked"}, NPC_FmDengonLooked, 0 }, + + /* Healer */ + { {"HealerInit"} , NPC_HealerInit, 0 }, + { {"HealerTalked"} , NPC_HealerTalked , 0 }, + + /* FMHealer add code by shan */ + { {"FmHealerInit"} , NPC_FmHealerInit, 0 }, + { {"FmHealerTalked"} , NPC_FmHealerTalked , 0 }, + + /* petmaker add code by shan */ + { {"PetMakerInit"} , NPC_PetMakerInit, 0 }, + { {"PetMakerTalked"} , NPC_PetMakerTalked , 0 }, + + /* TownPeople */ + { {"TownPeopleTalked"}, NPC_TownPeopleTalked, 0 }, + { {"TownPeopleInit"}, NPC_TownPeopleInit, 0 }, + + /* TownPeople */ + { {"MsgLooked"}, NPC_MsgLooked , 0 }, + { {"MsgInit"}, NPC_MsgInit, 0 }, + + /* Oldman */ + { {"OldmanInit"} , NPC_OldmanInit , 0 }, + { {"OldmanTalked"} , NPC_OldmanTalked , 0 }, + + /* SavePOint */ + { {"SavePointInit"} , NPC_SavePointInit , 0 }, + { {"SavePointTalked"} , NPC_SavePointTalked , 0 }, + { {"SavePointWindowTalked"}, NPC_SavePointWindowTalked, 0 }, + + /* StoryTeller */ + { {"StoryTellerInit"} , NPC_StoryTellerInit , 0 }, + { {"StoryTellerTalked"} , NPC_StoryTellerTalked , 0 }, + + /* NPCEnemy */ + { {"NPCEnemyInit"} , NPC_NPCEnemyInit , 0 }, + { {"NPCEnemyTalked"} , NPC_NPCEnemyTalked , 0 }, + { {"NPCEnemyWatch"} , NPC_NPCEnemyWatch , 0 }, + { {"NPCEnemyLoop"}, NPC_NPCEnemyLoop, 0 }, + { {"NPCEnemyWindowTalked"}, NPC_NPCEnemyWindowTalked, 0 }, + + /* ʧ */ + { {"ActionInit"} , NPC_ActionInit , 0 }, + { {"ActionTalked"} , NPC_ActionTalked , 0 }, + { {"ActionWatch"} , NPC_ActionWatch , 0 }, + + /* ū */ + { {"WindowmanInit"} , NPC_WindowmanInit , 0 }, + { {"WindowmanTalked"} , NPC_WindowmanTalked , 0 }, + { {"WindowmanLooked"}, NPC_WindowmanLooked, 0 }, + { {"WindowmanWindowTalked"}, NPC_WindowmanWindowTalked, 0 }, + + /* ūס¡ */ + { {"WindowHealerInit"} , NPC_WindowHealerInit , 0 }, + { {"WindowHealerTalked"} , NPC_WindowHealerTalked, 0 }, + { {"WindowHealerLooked"} , NPC_WindowHealerLooked, 0 }, + { {"WindowHealerWindowTalked"}, NPC_WindowHealerWindowTalked, 0 }, + + { {"ItemShopInit"} , NPC_ItemShopInit , 0 }, + { {"ItemShopTalked"} , NPC_ItemShopTalked , 0 }, + { {"ItemShopWindowTalked"}, NPC_ItemShopWindowTalked, 0 }, + + /* Sysinfo */ + { {"SysinfoInit"}, NPC_SysinfoInit, 0 }, + { {"SysinfoLoop"}, NPC_SysinfoLoop, 0 }, + { {"SysinfoTalked"} , NPC_SysinfoTalked , 0 }, + + { {"DuelrankingInit"} , NPC_DuelrankingInit , 0 }, + { {"DuelrankingLooked"}, NPC_DuelrankingLooked, 0 }, + { {"DuelrankingWindowTalked"}, NPC_DuelrankingWindowTalked, 0 }, + + { {"PetSkillShopInit"} , NPC_PetSkillShopInit , 0 }, + { {"PetSkillShopTalked"} , NPC_PetSkillShopTalked, 0 }, + { {"PetSkillShopLooked"} , NPC_PetSkillShopLooked, 0 }, + { {"PetSkillShopWindowTalked"}, NPC_PetSkillShopWindowTalked, 0 }, + + { {"PetShopInit"} , NPC_PetShopInit, 0 }, + { {"PetShopTalked"} , NPC_PetShopTalked, 0 }, + { {"PetShopLooked"} , NPC_PetShopLooked, 0 }, + { {"PetShopWindowTalked"}, NPC_PetShopWindowTalked,0 }, + + { {"SignBoardInit"} , NPC_SignBoardInit, 0 }, + { {"SignBoardLooked"} , NPC_SignBoardLooked, 0 }, + { {"SignBoardWindowTalked"}, NPC_SignBoardWindowTalked, 0 }, + + /*Ѩ */ + { {"WarpManInit"}, NPC_WarpManInit, 0 }, + { {"WarpManTalked"}, NPC_WarpManTalked, 0 }, + { {"WarpManWatch"}, NPC_WarpManWatch, 0 }, + { {"WarpManLoop"} , NPC_WarpManLoop, 0 }, + { {"WarpManWindowTalked"}, NPC_WarpManWindowTalked,0 }, + + + { {"ExChangeManInit"}, NPC_ExChangeManInit, 0 }, + { {"ExChangeManTalked"}, NPC_ExChangeManTalked, 0 }, + { {"ExChangeManWindowTalked"}, NPC_ExChangeManWindowTalked,0 }, + + /*ةѨ */ + { {"TimeManInit"}, NPC_TimeManInit, 0 }, + { {"TimeManTalked"}, NPC_TimeManTalked, 0 }, + { {"TimeManWatch"} , NPC_TimeManWatch , 0 }, + + /* ʾū¼ء */ + { {"BodyLanInit"}, NPC_BodyLanInit, 0 }, + { {"BodyLanTalked"}, NPC_BodyLanTalked, 0 }, + { {"BodyLanWatch"} , NPC_BodyLanWatch , 0 }, + { {"BodyLanWindowTalked"} , NPC_BodyLanWindowTalked,0 }, + + /* Ѩ */ + { {"MicInit"}, NPC_MicInit, 0 }, + { {"MicTalked"}, NPC_MicTalked, 0 }, + + /* ƽѨ */ + { {"LuckyManInit"} , NPC_LuckyManInit , 0 }, + { {"LuckyManTalked"} , NPC_LuckyManTalked, 0 }, + { {"LuckyManWindowTalked"}, NPC_LuckyManWindowTalked, 0 }, + + /* */ + { {"BusInit"} , NPC_BusInit , 0 }, + { {"BusTalked"} , NPC_BusTalked , 0 }, + { {"BusLoop"} , NPC_BusLoop , 0 }, + + /* */ // Arminius 7.7 Airplane + { {"AirInit"} , NPC_AirInit , 0 }, + { {"AirTalked"} , NPC_AirTalked , 0 }, + { {"AirLoop"} , NPC_AirLoop , 0 }, + + { {"CharmInit"} , NPC_CharmInit , 0 }, + { {"CharmTalked"} , NPC_CharmTalked, 0 }, + { {"CharmWindowTalked"}, NPC_CharmWindowTalked, 0 }, + + { {"PoolItemShopInit"} , NPC_PoolItemShopInit , 0 }, + { {"PoolItemShopTalked"} , NPC_PoolItemShopTalked , 0 }, + { {"PoolItemShopWindowTalked"}, NPC_PoolItemShopWindowTalked, 0 }, + + { {"QuizInit"} , NPC_QuizInit , 0 }, + { {"QuizTalked"} , NPC_QuizTalked, 0 }, + { {"QuizWindowTalked"}, NPC_QuizWindowTalked, 0 }, + + + /* ֮ */ + { {"CheckManInit"} , NPC_CheckManInit , 0 }, + { {"CheckManTalked"} , NPC_CheckManTalked, 0 }, + { {"CheckManWindowTalked"}, NPC_CheckManWindowTalked, 0 }, + + /* Ԫ */ + { {"JankenInit"} , NPC_JankenInit , 0 }, + { {"JankenTalked"} , NPC_JankenTalked, 0 }, + { {"JankenWindowTalked"}, NPC_JankenWindowTalked, 0 }, + + /* Ϸ */ + { {"TransmigrationInit"} , NPC_TransmigrationInit , 0 }, + { {"TransmigrationTalked"} , NPC_TransmigrationTalked, 0 }, + { {"TransmigrationWindowTalked"}, NPC_TransmigrationWindowTalked, 0 }, + + /* Family man */ + { {"FamilymanInit"} , NPC_FamilymanInit , 0 }, + { {"FamilymanTalked"} , NPC_FamilymanTalked, 0 }, + { {"FamilymanLooked"}, NPC_FamilymanLooked,0 }, + { {"FamilymanWindowTalked"}, NPC_FamilymanWindowTalked, 0 }, + + /* CoolFish: Family WarpMan 2001/6/6 */ + { {"FMWarpManInit"}, NPC_FMWarpManInit, 0 }, + { {"FMWarpManTalked"}, NPC_FMWarpManTalked, 0 }, + { {"FMWarpManLoop"} , NPC_FMWarpManLoop, 0 }, + { {"FMWarpManWindowTalked"}, NPC_FMWarpManWindowTalked, 0 }, + + /* CoolFish: Family PKMan 2001/7/4 */ + { {"FMPKManInit"}, NPC_FMPKManInit, 0 }, + { {"FMPKManTalked"}, NPC_FMPKManTalked, 0 }, + { {"FMPKManWindowTalked"}, NPC_FMPKManWindowTalked, 0 }, + + /* CoolFish: Family PKCallMan 2001/7/13 */ + { {"FMPKCallManInit"}, NPC_FMPKCallManInit, 0 }, + { {"FMPKCallManTalked"}, NPC_FMPKCallManTalked, 0 }, + { {"FMPKCallManWindowTalked"}, NPC_FMPKCallManWindowTalked, 0 }, + + /* Bank man */ + { {"BankmanInit"} , NPC_BankmanInit , 0 }, + { {"BankmanTalked"} , NPC_BankmanTalked, 0 }, + { {"BankmanLooked"}, NPC_BankmanLooked,0 }, + { {"BankmanWindowTalked"}, NPC_BankmanWindowTalked, 0 }, + + /* Arminius 7.13 scheduleman */ + { {"SchedulemanInit"}, NPC_SchedulemanInit, 0}, + { {"SchedulemanTalked"}, NPC_SchedulemanTalked, 0}, + { {"SchedulemanWindowTalked"}, NPC_SchedulemanWindowTalked, 0}, + { {"SchedulemanLoop"}, NPC_SchedulemanLoop, 0}, + + /* Arminius 7.24 manor scheduleman */ + { {"ManorSmanInit"}, NPC_ManorSmanInit, 0}, + { {"ManorSmanTalked"}, NPC_ManorSmanTalked, 0}, + { {"ManorSmanWindowTalked"}, NPC_ManorSmanWindowTalked, 0}, + { {"ManorSmanLoop"}, NPC_ManorSmanLoop, 0}, + + /* Rider man */ + { {"RidermanInit"} , NPC_RidermanInit , 0 }, + { {"RidermanTalked"} , NPC_RidermanTalked, 0 }, + { {"RidermanLooked"}, NPC_RidermanLooked,0 }, + { {"RidermanWindowTalked"}, NPC_RidermanWindowTalked, 0 }, + + /* FmLetter man */ + { {"FmLetterInit"} , NPC_FmLetterInit , 0 }, + { {"FmLetterTalked"} , NPC_FmLetterTalked, 0 }, + { {"FmLetterLooked"}, NPC_FmLetterLooked,0 }, + { {"FmLetterWindowTalked"}, NPC_FmLetterWindowTalked, 0 }, + + +#ifdef _GAMBLE_BANK // + { {"GambleBankInit"}, NPC_GambleBankInit, 0}, + { {"GambleBankLoop"}, NPC_GambleBankLoop,0}, + { {"GambleBankTalked"}, NPC_GambleBankTalked,0}, + { {"GambleBankWindowTalked"}, NPC_GambleBankWindowTalked,0}, +#endif + + +#ifdef _PET_LIMITLEVEL + { {"ITEM_useOtherEditBase"}, ITEM_useOtherEditBase, 0}, +#endif +#ifdef _ITEM_EDITBASES + { {"ITEM_useFusionEditBase"}, ITEM_useFusionEditBase, 0}, +#endif +#ifdef _GAMBLE_ROULETTE //ij + { {"GambleRouletteInit"}, NPC_Gamble_RouletteInit, 0}, + { {"GambleRouletteLoop"}, NPC_Gamble_RouletteLoop, 0}, + { {"GambleRouletteTalked"}, NPC_Gamble_RouletteTalked, 0}, + { {"GambleRouletteWindowTalked"}, NPC_Gamble_RouletteWindowTalked, 0}, + + { {"GambleMasterInit"}, NPC_Gamble_MasterInit, 0}, + { {"GambleMasterLoop"}, NPC_Gamble_MasterLoop, 0}, + { {"GambleMasterTalked"}, NPC_Gamble_MasterTalked, 0}, + { {"GambleMasterWindowTalked"}, NPC_Gamble_MasterWindowTalked, 0}, +#endif + +#ifdef _TRANSER_MAN + { {"TranserManInit"}, NPC_TranserManInit, 0 }, + { {"TranserManTalked"}, NPC_TranserManTalked, 0 }, + { {"TranserManWindowTalked"}, NPC_TranserManWindowTalked, 0 }, +#endif + +#ifdef _VIP_SHOP + { {"VipShopInit"}, NPC_VipshopInit, 0 }, + { {"VipShopTalked"}, NPC_VipshopTalked, 0 }, + { {"VipShopWindowTalked"}, NPC_VipshopWindowTalked, 0 }, +#endif + +#ifdef _NEW_VIP_SHOP + { {"NewVipShopInit"}, NPC_NewVipShopInit, 0 }, + { {"NewVipShopTalked"}, NPC_NewVipShopTalked, 0 }, + { {"NewVipShopWindowTalked"}, NPC_NewVipShopWindowTalked, 0 }, +#endif + +#ifdef _AUTO_PK + { {"AutoPkInit"}, NPC_AutoPkInit, 0 }, + { {"AutoPkTalked"}, NPC_AutoPkTalked, 0 }, + { {"AutoPkWindowTalked"}, NPC_AutoPkWindowTalked, 0 }, +#endif + +#ifdef _PAUCTION_MAN + { {"PauctionInit"}, NPC_PauctionInit, 0 }, + { {"PauctionTalked"}, NPC_PauctionTalked, 0 }, + { {"PauctionWindowTalked"}, NPC_PauctionWindowTalked, 0 }, +#endif + +#ifdef _NPC_MAKEPAIR + { {"MakePairManInit"}, NPC_MakePairManInit, 0 }, + { {"MakePairManTalked"}, NPC_MakePairManTalked, 0 }, + { {"MakePairManLoop"} , NPC_MakePairManLoop, 0 }, + { {"MakePairManWindowTalked"}, NPC_MakePairManWindowTalked,0 }, +#endif +#ifdef _NPC_FUSION + { {"PetFusionManInit"}, NPC_PetFusionManInit, 0 }, + { {"PetFusionManTalked"}, NPC_PetFusionManTalked, 0 }, + { {"PetFusionManWindowTalked"}, NPC_PetFusionManWindowTalked,0 }, +#endif +#ifdef _ITEM_NPCCHANGE + { {"ItemchangeManInit"}, NPC_ItemchangeManInit, 0 }, + { {"ItemchangeManTalked"}, NPC_ItemchangeManTalked, 0 }, + { {"ItemchangeManWindowTalked"}, NPC_ItemchangeManWindowTalked, 0 }, +#endif + +#ifdef _CFREE_petskill + { {"FreePetSkillInit"} , NPC_FreePetSkillShopInit, 0 }, + { {"FreePetSkillTalked"} , NPC_FreePetSkillShopTalked, 0 }, + { {"FreePetSkillWindowTalked"}, NPC_FreePetSkillShopWindowTalked, 0 }, +#endif + +#ifdef _PETRACE // ᄎ + { {"PetRaceMasterInit"}, NPC_PetRaceMasterInit, 0}, + { {"PetRaceMasterLoop"}, NPC_PetRaceMasterLoop, 0}, + { {"PetRaceMasterTalked"}, NPC_PetRaceMasterTalked, 0}, + { {"PetRaceMasterWindowTalked"}, NPC_PetRaceMasterWindowTalked, 0}, + + { {"PetRacePetInit"}, NPC_PetRacePetInit, 0}, + { {"PetRacePetLoop"}, NPC_PetRacePetLoop, 0}, + { {"PetRacePetTalked"}, NPC_PetRacePetTalked, 0}, +#endif + +#ifdef _NEW_WARPMAN + { {"NewNpcManInit"}, NPC_NewNpcManInit, 0}, + { {"NewNpcManLoop"}, NPC_NewNpcManLoop, 0}, + { {"NewNpcManTalked"}, NPC_NewNpcManTalked, 0}, + { {"NewNpcManWindowTalked"}, NPC_NewNpcManWindowTalked, 0}, +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + { {"AlldomanInit"} , NPC_AlldomanInit, 0 }, + { {"AlldomanTalked"} , NPC_AlldomanTalked , 0 }, + { {"AlldomanWindowTalked"}, NPC_AlldomanWindowTalked , 0}, +#endif + +#ifdef _NPC_WELFARE + { {"WelfareInit"} , NPC_WelfareInit, 0 }, + { {"WelfareTalked"} , NPC_WelfareTalked , 0 }, + { {"WelfareWindowTalked"}, NPC_WelfareWindowTalked , 0}, +#endif +#ifdef _NPC_MAGICCARD + { {"MagiccardInit"}, NPC_Magiccard_Init, 0 }, + { {"MagiccardTalked"}, NPC_Magiccard_Talked, 0 }, + { {"MagiccardWindowTalked"}, NPC_Magiccard_WindowTalked, 0 }, + { {"MagiccardLoop"}, NPC_Magiccard_Loop, 0 }, +#endif +#ifdef _TIME_TICKET + { {"ITEM_timeticket"}, ITEM_timeticket, 0}, +#endif + +#ifdef _ITEM_SETLOVER // Ʒ + { {"ITEM_SetLoverUser"}, ITEM_SetLoverUser, 0 }, + { {"ITEM_LoverWarp"}, ITEM_LoverWarp, 0 }, + { {"ITEM_LoverUnmarry"}, ITEM_LoverUnmarry, 0 }, +#endif + +#ifdef _GM_ITEM // GMƷ + { {"ITEM_GMFUNCTION"}, ITEM_GMFUNCTION, 0 }, +#endif + +#ifdef _VIP_SERVER // Ա + { {"ITEM_AddMemberPoint"}, ITEM_AddMemberPoint, 0 }, +#endif +#ifdef _VIP_RIDE + { {"ITEM_VipRide"}, ITEM_VipRide, 0 }, +#endif +#ifdef _FM_ITEM + { {"ITEM_AddFame"}, ITEM_AddFame, 0 }, +#endif +#ifdef _LUCK_ITEM + { {"ITEM_Luck"}, ITEM_Luck, 0 }, +#endif +#ifdef _FM_METAMO + { {"ITEM_MetamoTime"}, ITEM_MetamoTime, 0 }, +#endif +#ifdef _ITEM_GOLD + { {"ITEM_Gold"}, ITEM_Gold, 0 }, +#endif +#ifdef _MYSTERIOUS_GIFT + { {"ITEM_MysteriousGift"}, ITEM_MysteriousGift, 0 }, +#endif +#ifdef _BATTLE_PK + { {"ITEM_BattlePK"}, ITEM_BattlePK, 0 }, +#endif +#ifdef _SILENTZERO + { {"ITEM_SetSilentZero"}, ITEM_SetSilentZero, 0 }, +#endif +#ifdef _PET_LEVEL_ITEM + { {"ITEM_PetLevelItem"}, ITEM_PetLevelItem, 0 }, +#endif + +#ifdef _ITEM_EFMETAMO + { {"ITEM_efMetamo"}, ITEM_efMetamo, 0 }, +#endif +#ifdef _PET_BEATITUDE + { {"PET_BEATITUDE"}, PET_BEATITUDE, 0 }, +#endif +#ifdef _GET_MULTI_ITEM + { {"ITEM_GetMultiItem"}, ITEM_GetMultiItem, 0 }, +#endif +#ifdef _SUPER_FLOOR_MIC + { {"ITEM_useSuperMic"}, ITEM_useSuperMic, 0 }, +#endif +#ifdef _ITEM_PET_LOCKED + { {"ITEM_ItemPetLocked"}, ITEM_ItemPetLocked, 0 }, +#endif +#ifdef _ONLINE_COST + { {"ITEM_OnlineCost"}, ITEM_OnlineCost, 0 }, +#endif +#ifdef _VIPPOINT_OLD_TO_NEW + { {"ITEM_OldToNew"}, ITEM_OldToNew, 0 }, +#endif +#ifdef _TALK_SIZE_ITEM + { {"ITEM_TalkSize"}, ITEM_TalkSize, 0 }, +#endif +#ifdef _BOUND_TIME + { {"ITEM_BoundTime"}, ITEM_BoundTime, 0 }, +#endif +#ifdef _NEW_NAME + { {"ITEM_NewName"}, ITEM_NewName, 0 }, +#endif +#ifdef _FORMULATE_AUTO_PK + { {"ITEM_PointToSQLPkPoint"}, ITEM_PointToSQLPkPoint, 0 }, +#endif +#ifdef _SUPER_MAN_ITEM + { {"ITEM_SuperManItem"}, ITEM_SuperManItem, 0 }, +#endif +#ifdef _COST_ITEM + { {"ITEM_CostItem"}, ITEM_CostItem, 0 }, +#endif +#ifdef _ITEM_EXP + { {"ITEM_EXP"}, ITEM_EXP, 0 }, +#endif +#ifdef _MEMORY_ITEM + { {"ITEM_WarpItem"}, ITEM_WarpItem, 0 }, +#endif +#ifdef _NULL_CHECK_ITEM + { {"ITEM_NullCheck"}, ITEM_NullCheck, 0 }, +#endif +#ifdef _SPECIAL_SUIT + { {"ITEM_SpecialSuitEquip"}, ITEM_SpecialSuitEquip, 0 }, + { {"ITEM_SpecialResuitEquip"}, ITEM_SpecialResuitEquip, 0 }, +#endif +#ifdef _MANOR_EQUIP + { {"ITEM_ManorEquip"}, ITEM_ManorEquip, 0 }, + { {"ITEM_ReManorEquip"}, ITEM_ReManorEquip, 0 }, +#endif +#ifdef _FIND_TREASURES + { {"ITEM_FindTreasures"}, ITEM_FindTreasures, 0 }, +#endif +#ifdef _ITEM_POOLITEM + { {"ITEM_PoolItem"}, ITEM_PoolItem, 0 }, +#endif +#ifdef _ITEM_POOLPET + { {"ITEM_PoolPet"}, ITEM_PoolPet, 0 }, +#endif +#ifdef _NEW_GM_ITEM + { {"ITEM_NewGMItem"}, ITEM_NewGMItem, 0 }, +#endif +#ifdef _SHOW_PET_ABL + { {"ITEM_ShowPetAbl"}, ITEM_ShowPetAbl, 0 }, +#endif +#ifdef _NEWEVENT_ITEM + { {"ITEM_NeweventItem"}, ITEM_NeweventItem, 0 }, +#endif +#ifdef _NEW_PET_BEATITUDE + { {"ITEM_NewPetBeatitude"}, ITEM_NewPetBeatitude, 0 }, +#endif +#ifdef _OLYMPIC_TORCH + { {"ITEM_OlympicTorck"}, ITEM_OlympicTorck, 0 }, +#endif +#ifdef _PLAYER_DIY_MAP + { {"ITEM_PlayerDiyMapObj"}, ITEM_PlayerDiyMapObj, 0 }, + { {"ITEM_PlayerDiyMapTile"}, ITEM_PlayerDiyMapTile, 0 }, +#endif +#ifdef _SHOW_ITEM + { {"ITEM_ShowItem"}, ITEM_ShowItem, 0 }, +#endif +#ifdef _ITEM_LUA + { {"ITEM_Lua"}, ITEM_Lua, 0 }, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + { {FUNCNAME_INITCALLBACK} , NPC_Lua_InitCallBack, 0 }, + { {FUNCNAME_WALKPRECALLBACK} , NPC_Lua_WalkPreCallBack, 0 }, + { {FUNCNAME_WALKPOSTCALLBACK} , NPC_Lua_WalkPostCallBack, 0 }, + { {FUNCNAME_PREOVERCALLBACK} , NPC_Lua_PreOverCallBack, 0 }, + { {FUNCNAME_POSTOVERCALLBACK} , NPC_Lua_PostOverCallBack, 0 }, + { {FUNCNAME_WATCHCALLBACK} , NPC_Lua_WatchCallBack, 0 }, + { {FUNCNAME_LOOPCALLBACK} , NPC_Lua_LoopCallBack, 0 }, + { {FUNCNAME_TALKEDCALLBACK} , NPC_Lua_TalkedCallBack, 0 }, + { {FUNCNAME_OFFCALLBACK} , NPC_Lua_OFFCallBack, 0 }, + { {FUNCNAME_LOOKEDCALLBACK} , NPC_Lua_LookedCallBack, 0 }, + { {FUNCNAME_ITEMPUTCALLBACK} , NPC_Lua_ItemPutCallBack, 0 }, + { {FUNCNAME_WINDOWTALKEDCALLBACK} , NPC_Lua_WindowTalkedCallBack, 0 }, +#ifdef _USER_CHARLOOPS + { {FUNCNAME_CHARLOOPSCALLBACK} , NPC_Lua_CharLoopsCallBack, 0 }, + { {FUNCNAME_BATTLEPROPERTYCALLBACK} , NPC_Lua_BattleProPertyCallBack, 0 }, +#endif + + { {FUNCNAME_ITEMPEROVERCALLBACK} , NPC_Lua_ItemPerOverCallBack, 0 }, + { {FUNCNAME_ITEMPOSTOVERCALLBACK} , NPC_Lua_ItemPostOverCallBack, 0 }, + { {FUNCNAME_ITEMWATCHCALLBACK} , NPC_Lua_ItemWatchCallBack, 0 }, + { {FUNCNAME_ITEMUSECALLBACK} , NPC_Lua_ItemUseCallBack, 0 }, + { {FUNCNAME_ITEMATTACHCALLBACK} , NPC_Lua_ItemAttachCallBack, 0 }, + { {FUNCNAME_ITEMDETACHCALLBACK} , NPC_Lua_ItemDetachCallBack, 0 }, + { {FUNCNAME_ITEMDROPCALLBACK} , NPC_Lua_ItemDropCallBack, 0 }, + { {FUNCNAME_ITEMPICKUPCALLBACK} , NPC_Lua_ItemPickUPCallBack, 0 }, +#ifdef _Item_ReLifeAct + { {FUNCNAME_ITEMDIERELIFECALLBACK} , NPC_Lua_ItemDieReLifeCallBack, 0 }, +#endif + + { {FUNCNAME_BATTLEWINCALLBACK} , NPC_Lua_BattleWinCallBack, 0 }, + { {FUNCNAME_BATTLEENDCALLBACK} , NPC_Lua_BattleEndCallBack, 0 }, +#endif //_JZ_NEWSCRIPT_LUA +}; + +BOOL initFunctionTable( void ) +{ + + int i; + { + char* strings[arraysizeof(correspondStringAndFunctionTable)]; + int stringnum=0; + for( i=0 ; i +#include + +#include "common.h" +#include "handletime.h" + +#define LSTIME_SECONDS_PER_DAY 5400 /* LSTIME ϼ */ + + +#define LSTIME_HOURS_PER_DAY 1024 /* LSTIME ϼLSTIME */ +#define LSTIME_DAYS_PER_YEAR 100 /* LSTIME ϼLSTIME */ + + +/* +// Nuke 0701: localtime + + struct timeval NowTime; +#ifdef localtime +#undef localtime +#endif + +struct tm *localtime(const time_t *timep) +{ + static struct tm lt; + memset(<,0,sizeof(lt)); + lt.tm_sec=*timep %60; + lt.tm_min=(*timep %3600) / 60; + lt.tm_hour=(*timep % 86400) / 3600; + return < +} +*/ + +/*------------------------------------------------------------ + * ¦ + * ئ + * ߯Ի + ------------------------------------------------------------*/ +BOOL setNewTime( void ) +{ + if( gettimeofday( &NowTime, (struct timezone*)NULL) != 0 ) { + NowTime.tv_sec = time(0); + // Nuke 0701: Localtime down + print("\n time err !! \n"); + return FALSE; + } + NowTime.tv_sec += DEBUG_ADJUSTTIME; + return TRUE; +} + + +/******************************************************************* +*******************************************************************/ +static long era = (long)912766409 + 5400; + /* SAб */ +void RealTimeToLSTime(long t , LSTIME *lstime) +{ + long lsseconds = t - era; /* LS ռ */ + long lsdays; /* LS ռ */ + + lstime->year = (int)( lsseconds/(LSTIME_SECONDS_PER_DAY*LSTIME_DAYS_PER_YEAR) ); + + lsdays = lsseconds/LSTIME_SECONDS_PER_DAY;/* ռ ëңƻ */ + lstime->day = lsdays % LSTIME_DAYS_PER_YEAR;/* Ի ƥؤԻ */ + + + lstime->hour = (int)(lsseconds % LSTIME_SECONDS_PER_DAY ) + * LSTIME_HOURS_PER_DAY / LSTIME_SECONDS_PER_DAY; + + return; +} + +/******************************************************************* + LS޾Ѩ˼ޱ +*******************************************************************/ +void LSTimeToRealTime( LSTIME *lstime, long *t) +{ + *t=(long)( + ( lstime->hour*LSTIME_DAYS_PER_YEAR+lstime->day) /* */ + *LSTIME_HOURS_PER_DAY + + + lstime->year) + + + *450; + return; +} + +/******************************************************************* +*******************************************************************/ +LSTIME_SECTION getLSTime (LSTIME *lstime) +{ + if (NIGHT_TO_MORNING < lstime->hour + && lstime->hour <= MORNING_TO_NOON) + return LS_MORNING; + else if(NOON_TO_EVENING < lstime->hour + && lstime->hour <= EVENING_TO_NIGHT) + return LS_EVENING; + else if(EVENING_TO_NIGHT < lstime->hour + && lstime->hour <= NIGHT_TO_MORNING) + return LS_NIGHT; + else + return LS_NOON; +} + + +#ifdef _ASSESS_SYSEFFICACY +static clock_t TotalClock = 0; +static clock_t StartClock = 0; +//static int EndClock = 0; +//static float SysTime=0.0; +static clock_t EndClock = 0; +static double SysTime=0.0; +static int Cnum = 0; + +#ifdef _ASSESS_SYSEFFICACY_SUB +static clock_t Net_TotalClock = 0; +static clock_t NPCGEN_TotalClock = 0; +static clock_t Battle_TotalClock = 0; +static clock_t Char_TotalClock = 0; +static clock_t Petmail_TotalClock = 0; +static clock_t Family_TotalClock = 0; +static clock_t SaveCheck_TotalClock = 0; +static clock_t GMBroadCast_TotalClock = 0; +static double Net_SysTime=0.0; +static double NPCGEN_SysTime=0.0; +static double Battle_SysTime=0.0; +static double Char_SysTime=0.0; +static double Petmail_SysTime=0.0; +static double Family_SysTime=0.0; +static double SaveCheck_SysTime=0.0; +static double GMBroadCast_SysTime=0.0; +static clock_t SubStartClock = 0; +#endif + +void Assess_InitSysEfficacy() +{ + TotalClock = 0; + StartClock = 0; + EndClock = 0; +#ifdef _ASSESS_SYSEFFICACY_SUB + Net_TotalClock = 0; + NPCGEN_TotalClock = 0; + Battle_TotalClock = 0; + Char_TotalClock = 0; + Petmail_TotalClock = 0; + Family_TotalClock = 0; + SaveCheck_TotalClock = 0; + GMBroadCast_TotalClock = 0; + + SubStartClock = 0; +#endif +} + +void Assess_SysEfficacy( int flg) +{ + if( flg == 0 ){ + StartClock=clock(); + }else if( flg == 1 ){ + EndClock = clock(); + if( EndClock < StartClock ) return; + TotalClock += (int)(EndClock-StartClock); + Cnum++; + if( Cnum%500 == 0 ){ + SysTime = (float)(TotalClock/Cnum)/CLOCKS_PER_SEC; + TotalClock = 0; +#ifdef _ASSESS_SYSEFFICACY_SUB + Net_SysTime = (float)(Net_TotalClock/Cnum)/CLOCKS_PER_SEC; + Net_TotalClock = 0; + NPCGEN_SysTime = (float)(NPCGEN_TotalClock/Cnum)/CLOCKS_PER_SEC; + NPCGEN_TotalClock = 0; + Battle_SysTime = (float)(Battle_TotalClock/Cnum)/CLOCKS_PER_SEC; + Battle_TotalClock = 0; + Char_SysTime = (float)(Char_TotalClock/Cnum)/CLOCKS_PER_SEC; + Char_TotalClock = 0; + Petmail_SysTime = (float)(Petmail_TotalClock/Cnum)/CLOCKS_PER_SEC; + Petmail_TotalClock = 0; + Family_SysTime = (float)(Family_TotalClock/Cnum)/CLOCKS_PER_SEC; + Family_TotalClock = 0; + SaveCheck_SysTime = (float)(SaveCheck_TotalClock/Cnum)/CLOCKS_PER_SEC; + SaveCheck_TotalClock = 0; + GMBroadCast_SysTime = (float)(GMBroadCast_TotalClock/Cnum)/CLOCKS_PER_SEC; + GMBroadCast_TotalClock = 0; +#endif + Cnum = 0; + } + } + /* + EndClock = clock(); + if( StartClock != 0 ){ + if( EndClock < StartClock ) return; + TotalClock += (int)(EndClock-StartClock); + Cnum++; + if( Cnum%500 == 0 ){ + SysTime = (float)TotalClock/Cnum; + TotalClock = 0; + } + } + StartClock = EndClock; + */ +} + +void ASSESS_getSysEfficacy( float *TVsec) +{ + *TVsec = SysTime; +} + +#ifdef _ASSESS_SYSEFFICACY_SUB +void Assess_SysEfficacy_sub( int flg, int loop) +{ + + if( flg == 0 ){ + SubStartClock = clock(); + }else if( flg == 1 ){ + EndClock = clock(); + if( EndClock < SubStartClock ) return; + + switch( loop) { + case 1: // Net_TotalClock + Net_TotalClock += (int)(EndClock-SubStartClock); + break; + case 2: // NPCGEN_TotalClock + NPCGEN_TotalClock += (int)(EndClock-SubStartClock); + break; + case 3: // Battle_TotalClock + Battle_TotalClock += (int)(EndClock-SubStartClock); + break; + case 4: // Char_TotalClock + Char_TotalClock += (int)(EndClock-SubStartClock); + break; + case 5: // Petmail_TotalClock + Petmail_TotalClock += (int)(EndClock-SubStartClock); + break; + case 6: // Family_TotalClock + Family_TotalClock += (int)(EndClock-SubStartClock); + break; + case 7: // SaveCheck_TotalClock + SaveCheck_TotalClock += (int)(EndClock-SubStartClock); + break; + case 8: // GMBroadCast_TotalClock + GMBroadCast_TotalClock += (int)(EndClock-SubStartClock); + break; + } + } +} + +void ASSESS_getSysEfficacy_sub( float *TVsec, int loop_index) +{ + switch( loop_index) { + case 1: + *TVsec = Net_SysTime; + break; + case 2: + *TVsec = NPCGEN_SysTime; + break; + case 3: + *TVsec = Battle_SysTime; + break; + case 4: + *TVsec = Char_SysTime; + break; + case 5: + *TVsec = Petmail_SysTime; + break; + case 6: + *TVsec = Family_SysTime; + break; + case 7: + *TVsec = SaveCheck_SysTime; + break; + case 8: + *TVsec = GMBroadCast_SysTime; + break; + } +} + +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/addressbook.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/addressbook.h new file mode 100644 index 0000000..0723cf7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/addressbook.h @@ -0,0 +1,45 @@ +#ifndef __ADDRESSBOOK_H__ +#define __ADDRESSBOOK_H__ + +#include "common.h" +#include "util.h" +#include "net.h" + +#define ADDRESSBOOK_MAX 80 + +typedef struct +{ + int use; + BOOL online; /* ƽҷ»ӡ TRUE, + ƥئFALSE */ + int level; /* ƽҷ¼ì */ + int duelpoint; /* duelpoint*/ + int graphicsno; /* ƽҷ¼ į */ + char cdkey[CDKEYLEN]; /* CD ϼ */ + char charname[CHARNAMELEN]; /* ƽҷ¼ */ + int transmigration; /* Ϸ */ + +} ADDRESSBOOK_entry; + + + + +char *ADDRESSBOOK_makeAddressbookString( ADDRESSBOOK_entry *a ); +BOOL ADDRESSBOOK_makeAddressbookEntry( char *in , ADDRESSBOOK_entry *a ); +BOOL ADDRESSBOOK_deleteEntry( int meindex ,int index ); +BOOL ADDRESSBOOK_addEntry( int meindex ); +BOOL ADDRESSBOOK_sendAddressbookTable( int cindex ); +BOOL ADDRESSBOOK_sendAddressbookTableOne( int cindex, int num ); +BOOL ADDRESSBOOK_sendMessage( int cindex, int aindex , char *text , + int color ); +BOOL ADDRESSBOOK_sendMessage_FromOther( char *fromcdkey, char *fromcharaname, + char *tocdkey, char *tocharaname, + char* text , int color ); + +void ADDRESSBOOK_notifyLoginLogout( int cindex , int flg ); +void ADDRESSBOOK_addAddressBook( int meindex, int toindex); +void ADDRESSBOOK_DispatchMessage( char *cd, char *nm, char *value, int mode); +int ADDRESSBOOK_getIndexInAddressbook(int cindex , char *cdkey, char *charname); +BOOL ADDRESSBOOK_AutoaddAddressBook( int meindex, int toindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/anim_tbl.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/anim_tbl.h new file mode 100644 index 0000000..39a7b8f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/anim_tbl.h @@ -0,0 +1,1156 @@ +#ifndef _ANIM_TBL_H_ +#define _ANIM_TBL_H_ + +#define SPRSTART 100000 // SPRԻ į + +// ƽҷ +#define SPR_001em 100000 // Ҽɨ +#define SPR_001ax 100001 // +#define SPR_001cl 100002 // +#define SPR_001sp 100003 // +#define SPR_001bw 100004 // + +#define SPR_002em 100005 // Ҽɨ +#define SPR_002ax 100006 // +#define SPR_002cl 100007 // +#define SPR_002sp 100008 // +#define SPR_002bw 100009 // + +#define SPR_003em 100010 // Ҽɨ +#define SPR_003ax 100011 // +#define SPR_003cl 100012 // +#define SPR_003sp 100013 // +#define SPR_003bw 100014 // + +#define SPR_004em 100015 // Ҽɨ +#define SPR_004ax 100016 // +#define SPR_004cl 100017 // +#define SPR_004sp 100018 // +#define SPR_004bw 100019 // + +#define SPR_011em 100020 // +#define SPR_011ax 100021 // +#define SPR_011cl 100022 // +#define SPR_011sp 100023 // +#define SPR_011bw 100024 // + +#define SPR_012em 100025 // +#define SPR_012ax 100026 // +#define SPR_012cl 100027 // +#define SPR_012sp 100028 // +#define SPR_012bw 100029 // + +#define SPR_013em 100030 // +#define SPR_013ax 100031 // +#define SPR_013cl 100032 // +#define SPR_013sp 100033 // +#define SPR_013bw 100034 // + +#define SPR_014em 100035 // +#define SPR_014ax 100036 // +#define SPR_014cl 100037 // +#define SPR_014sp 100038 // +#define SPR_014bw 100039 // + +#define SPR_021em 100040 // +#define SPR_021ax 100041 // +#define SPR_021cl 100042 // +#define SPR_021sp 100043 // +#define SPR_021bw 100044 // + +#define SPR_022em 100045 +#define SPR_022ax 100046 +#define SPR_022cl 100047 +#define SPR_022sp 100048 +#define SPR_022bw 100049 + +#define SPR_023em 100050 +#define SPR_023ax 100051 +#define SPR_023cl 100052 +#define SPR_023sp 100053 +#define SPR_023bw 100054 + +#define SPR_024em 100055 +#define SPR_024ax 100056 +#define SPR_024cl 100057 +#define SPR_024sp 100058 +#define SPR_024bw 100059 + +#define SPR_031em 100060 // +#define SPR_031ax 100061 // +#define SPR_031cl 100062 // +#define SPR_031sp 100063 // +#define SPR_031bw 100064 // + +#define SPR_032em 100065 +#define SPR_032ax 100066 +#define SPR_032cl 100067 +#define SPR_032sp 100068 +#define SPR_032bw 100069 + +#define SPR_033em 100070 +#define SPR_033ax 100071 +#define SPR_033cl 100072 +#define SPR_033sp 100073 +#define SPR_033bw 100074 + +#define SPR_034em 100075 +#define SPR_034ax 100076 +#define SPR_034cl 100077 +#define SPR_034sp 100078 +#define SPR_034bw 100079 + +#define SPR_041em 100080 // +#define SPR_041ax 100081 // +#define SPR_041cl 100082 // +#define SPR_041sp 100083 // +#define SPR_041bw 100084 // + +#define SPR_042em 100085 +#define SPR_042ax 100086 +#define SPR_042cl 100087 +#define SPR_042sp 100088 +#define SPR_042bw 100089 + +#define SPR_043em 100090 +#define SPR_043ax 100091 +#define SPR_043cl 100092 +#define SPR_043sp 100093 +#define SPR_043bw 100094 + +#define SPR_044em 100095 +#define SPR_044ax 100096 +#define SPR_044cl 100097 +#define SPR_044sp 100098 +#define SPR_044bw 100099 + +#define SPR_051em 100100 // +#define SPR_051ax 100101 // +#define SPR_051cl 100102 // +#define SPR_051sp 100103 // +#define SPR_051bw 100104 // + +#define SPR_052em 100105 +#define SPR_052ax 100106 +#define SPR_052cl 100107 +#define SPR_052sp 100108 +#define SPR_052bw 100109 + +#define SPR_053em 100110 +#define SPR_053ax 100111 +#define SPR_053cl 100112 +#define SPR_053sp 100113 +#define SPR_053bw 100114 + +#define SPR_054em 100115 +#define SPR_054ax 100116 +#define SPR_054cl 100117 +#define SPR_054sp 100118 +#define SPR_054bw 100119 + +#define SPR_061em 100120 // ҼԨ +#define SPR_061ax 100121 // +#define SPR_061cl 100122 // +#define SPR_061sp 100123 // +#define SPR_061bw 100124 // + +#define SPR_062em 100125 +#define SPR_062ax 100126 +#define SPR_062cl 100127 +#define SPR_062sp 100128 +#define SPR_062bw 100129 + +#define SPR_063em 100130 +#define SPR_063ax 100131 +#define SPR_063cl 100132 +#define SPR_063sp 100133 +#define SPR_063bw 100134 + +#define SPR_064em 100135 +#define SPR_064ax 100136 +#define SPR_064cl 100137 +#define SPR_064sp 100138 +#define SPR_064bw 100139 + +#define SPR_071em 100140 // Ԩ +#define SPR_071ax 100141 // +#define SPR_071cl 100142 // +#define SPR_071sp 100143 // +#define SPR_071bw 100144 // + +#define SPR_072em 100145 +#define SPR_072ax 100146 +#define SPR_072cl 100147 +#define SPR_072sp 100148 +#define SPR_072bw 100149 + +#define SPR_073em 100150 +#define SPR_073ax 100151 +#define SPR_073cl 100152 +#define SPR_073sp 100153 +#define SPR_073bw 100154 + +#define SPR_074em 100155 +#define SPR_074ax 100156 +#define SPR_074cl 100157 +#define SPR_074sp 100158 +#define SPR_074bw 100159 + +#define SPR_081em 100160 // Ԩ +#define SPR_081ax 100161 // +#define SPR_081cl 100162 // +#define SPR_081sp 100163 // +#define SPR_081bw 100164 // + +#define SPR_082em 100165 +#define SPR_082ax 100166 +#define SPR_082cl 100167 +#define SPR_082sp 100168 +#define SPR_082bw 100169 + +#define SPR_083em 100170 +#define SPR_083ax 100171 +#define SPR_083cl 100172 +#define SPR_083sp 100173 +#define SPR_083bw 100174 + +#define SPR_084em 100175 +#define SPR_084ax 100176 +#define SPR_084cl 100177 +#define SPR_084sp 100178 +#define SPR_084bw 100179 + +#define SPR_091em 100180 // Ԩ +#define SPR_091ax 100181 // +#define SPR_091cl 100182 // +#define SPR_091sp 100183 // +#define SPR_091bw 100184 // + +#define SPR_092em 100185 +#define SPR_092ax 100186 +#define SPR_092cl 100187 +#define SPR_092sp 100188 +#define SPR_092bw 100189 + +#define SPR_093em 100190 +#define SPR_093ax 100191 +#define SPR_093cl 100192 +#define SPR_093sp 100193 +#define SPR_093bw 100194 + +#define SPR_094em 100195 +#define SPR_094ax 100196 +#define SPR_094cl 100197 +#define SPR_094sp 100198 +#define SPR_094bw 100199 + +#define SPR_101em 100200 // +#define SPR_101ax 100201 // +#define SPR_101cl 100202 // +#define SPR_101sp 100203 // +#define SPR_101bw 100204 // + +#define SPR_102em 100205 +#define SPR_102ax 100206 +#define SPR_102cl 100207 +#define SPR_102sp 100208 +#define SPR_102bw 100209 + +#define SPR_103em 100210 +#define SPR_103ax 100211 +#define SPR_103cl 100212 +#define SPR_103sp 100213 +#define SPR_103bw 100214 + +#define SPR_104em 100215 +#define SPR_104ax 100216 +#define SPR_104cl 100217 +#define SPR_104sp 100218 +#define SPR_104bw 100219 + +#define SPR_111em 100220 // +#define SPR_111ax 100221 // +#define SPR_111cl 100222 // +#define SPR_111sp 100223 // +#define SPR_111bw 100224 // + +#define SPR_112em 100225 +#define SPR_112ax 100226 +#define SPR_112cl 100227 +#define SPR_112sp 100228 +#define SPR_112bw 100229 + +#define SPR_113em 100230 +#define SPR_113ax 100231 +#define SPR_113cl 100232 +#define SPR_113sp 100233 +#define SPR_113bw 100234 + +#define SPR_114em 100235 +#define SPR_114ax 100236 +#define SPR_114cl 100237 +#define SPR_114sp 100238 +#define SPR_114bw 100239 + + +// ʸ ƽҷ +#define SPR_pet001 100250 // +#define SPR_pet002 100251 // +#define SPR_pet003 100252 // ̼ +#define SPR_pet004 100253 // Ƥ + +#define SPR_pet011 100254 // Ƥū +#define SPR_pet012 100255 // Ƥ +#define SPR_pet013 100256 // Ƥ +#define SPR_pet014 100257 // Ƥ̡ +#define SPR_pet015 100258 // СƤ + +#define SPR_pet021 100259 // +#define SPR_pet022 100260 // +#define SPR_pet023 100261 // +#define SPR_pet024 100262 // ҡ + +#define SPR_pet031 100263 // ̺ +#define SPR_pet032 100264 // ūū +#define SPR_pet033 100265 // +#define SPR_pet034 100266 // ū + +#define SPR_pet041 100267 // ì +#define SPR_pet042 100268 // ì +#define SPR_pet043 100269 // ìͻ +#define SPR_pet044 100270 // ì + +#define SPR_pet051 100271 // ж +#define SPR_pet052 100272 // з´ +#define SPR_pet053 100273 // ж +#define SPR_pet054 100274 // з´ + +#define SPR_pet061 100275 // +#define SPR_pet062 100276 // ҵ +#define SPR_pet063 100277 // +#define SPR_pet064 100278 // ĸͻ + +#define SPR_pet071 100279 // ׻ +#define SPR_pet072 100280 // +#define SPR_pet073 100281 // ƽ +#define SPR_pet074 100282 // + +#define SPR_pet081 100283 // +#define SPR_pet082 100284 // е +#define SPR_pet083 100285 // +#define SPR_pet084 100286 // ҵ + +#define SPR_pet091 100287 // δ +#define SPR_pet092 100288 // ׷ +#define SPR_pet093 100289 // ʾ +#define SPR_pet094 100290 // ס + +#define SPR_pet101 100291 // +#define SPR_pet102 100292 // ͻ +#define SPR_pet103 100293 // ƽ +#define SPR_pet104 100294 // ƽ + +#define SPR_pet111 100295 // +#define SPR_pet112 100296 // +#define SPR_pet113 100297 // ƽب +#define SPR_pet114 100298 // ƽ + +#define SPR_pet121 100299 // ئ +#define SPR_pet122 100300 // ئ +#define SPR_pet123 100301 // ئ +#define SPR_pet124 100302 // ئ + +#define SPR_pet131 100303 // ئ +#define SPR_pet132 100304 // ئ +#define SPR_pet133 100305 // ئ +#define SPR_pet134 100306 // ئ + +#define SPR_pet141 100307 // +#define SPR_pet142 100308 // ׷ +#define SPR_pet143 100309 // ׷´ +#define SPR_pet144 100310 // + +#define SPR_pet151 100311 // ئ +#define SPR_pet152 100312 // ئ +#define SPR_pet153 100313 // ئ +#define SPR_pet154 100314 // ئ + +#define SPR_pet161 100315 // ئ +#define SPR_pet162 100316 // ئ +#define SPR_pet163 100317 // ئ +#define SPR_pet164 100318 // ئ + +#define SPR_pet171 100319 // بʾ +#define SPR_pet172 100320 // ʾ +#define SPR_pet173 100321 // +#define SPR_pet174 100322 // + +#define SPR_pet181 100323 // ʯ +#define SPR_pet182 100324 // ͡ +#define SPR_pet183 100325 // +#define SPR_pet184 100326 // ͻ + +#define SPR_pet191 100327 // ìﲼ +#define SPR_pet192 100328 // ì̲ +#define SPR_pet193 100329 // ˵ +#define SPR_pet194 100330 // ƽӡì + +#define SPR_pet201 100331 // ئ +#define SPR_pet202 100332 // ئ +#define SPR_pet203 100333 // ئ +#define SPR_pet204 100334 // ئ + +#define SPR_pet211 100335 // +#define SPR_pet212 100336 // ʸ +#define SPR_pet213 100337 // ¡ +#define SPR_pet214 100338 // + +#define SPR_pet221 100339 // +#define SPR_pet222 100340 // Һ +#define SPR_pet223 100341 // ҡ +#define SPR_pet224 100342 // + +#define SPR_pet231 100343 // ײ +#define SPR_pet232 100344 // ס +#define SPR_pet233 100345 // ײʾ +#define SPR_pet234 100346 // ׼ʾ + +#define SPR_pet241 100347 // ɡƽ +#define SPR_pet242 100348 // ة̡ +#define SPR_pet243 100349 // ʾ +#define SPR_pet244 100350 // ̡ + +#define SPR_pet251 100351 // Ƥ +#define SPR_pet252 100352 // Ƥ +#define SPR_pet253 100353 // Ƥƽ +#define SPR_pet254 100354 // + +#define SPR_pet261 100355 // Ѩƹ +#define SPR_pet262 100356 // ƹƹ +#define SPR_pet263 100357 // Ѩƹϵ +#define SPR_pet264 100358 // Ѩƹ + +#define SPR_pet271 100359 // ´ +#define SPR_pet272 100360 // ò +#define SPR_pet273 100361 // +#define SPR_pet274 100362 // ⵩ + +#define SPR_pet281 100363 // ئ +#define SPR_pet282 100364 // ئ +#define SPR_pet283 100365 // ئ +#define SPR_pet284 100366 // ئ + +#define SPR_pet291 100367 // ƽ +#define SPR_pet292 100368 // ͷ +#define SPR_pet293 100369 // ʯ +#define SPR_pet294 100370 // ƽūʾ + +#define SPR_pet301 100371 // 󲼷 +#define SPR_pet302 100372 // ūõ +#define SPR_pet303 100373 // ¼ +#define SPR_pet304 100374 // + +#define SPR_pet311 100375 // +#define SPR_pet312 100376 // ƹˡ +#define SPR_pet313 100377 // ʯ +#define SPR_pet314 100378 // ʯ + +#define SPR_pet321 100379 // ³ +#define SPR_pet322 100380 // Ƕ +#define SPR_pet323 100381 // ʧõ +#define SPR_pet324 100382 // ĸ÷ +#define SPR_pet325 100383 // + +#define SPR_pet331 100384 // ͵ +#define SPR_pet332 100385 // ¼ìﵩ +#define SPR_pet333 100386 // +#define SPR_pet334 100387 // á + +// ޥܰʸ +#define SPR_pet005 100388 // Ļ +#define SPR_pet085 100389 // е +#define SPR_pet086 100390 // +#define SPR_pet087 100391 // Ƥҵ +#define SPR_pet088 100392 // ʧʧ +#define SPR_pet065 100393 // +#define SPR_pet095 100394 // δ +#define SPR_pet175 100395 // بʾ +#define SPR_pet255 100396 // Ƥ + +// ޥܰƽҷ +#define SPR_121em 100400 // ʧ׷ +#define SPR_121ax 100401 // +#define SPR_121cl 100402 // +#define SPR_121sp 100403 // +#define SPR_121bw 100404 // + +#define SPR_122em 100405 // ʧ׷ +#define SPR_122ax 100406 // +#define SPR_122cl 100407 // +#define SPR_122sp 100408 // +#define SPR_122bw 100409 // + +#define SPR_123em 100410 // ʧ׷ +#define SPR_123ax 100411 // +#define SPR_123cl 100412 // +#define SPR_123sp 100413 // +#define SPR_123bw 100414 // + +#define SPR_124em 100415 // ʧ׷ +#define SPR_124ax 100416 // +#define SPR_124cl 100417 // +#define SPR_124sp 100418 // +#define SPR_124bw 100419 // + +#define SPR_131em 100420 // +#define SPR_131ax 100421 // +#define SPR_131cl 100422 // +#define SPR_131sp 100423 // +#define SPR_131bw 100424 // + +#define SPR_132em 100425 // +#define SPR_132ax 100426 // +#define SPR_132cl 100427 // +#define SPR_132sp 100428 // +#define SPR_132bw 100429 // + +#define SPR_pet315 100430 // ɼĸʯ + +#define SPR_141em 100431 // ؼϨ +#define SPR_141ax 100432 // +#define SPR_141cl 100433 // +#define SPR_141sp 100434 // +#define SPR_141bw 100435 // + +#define SPR_142em 100436 // ؼϨ +#define SPR_142ax 100437 // +#define SPR_142cl 100438 // +#define SPR_142sp 100439 // +#define SPR_142bw 100440 // + +#define SPR_133em 100441 // +#define SPR_133ax 100442 // +#define SPR_133cl 100443 // +#define SPR_133sp 100444 // +#define SPR_133bw 100445 // + +#define SPR_151em 100446 // Ԩ +#define SPR_151ax 100447 // +#define SPR_151cl 100448 // +#define SPR_151sp 100449 // +#define SPR_151bw 100450 // + +#define SPR_152em 100451 +#define SPR_152ax 100452 +#define SPR_152cl 100453 +#define SPR_152sp 100454 +#define SPR_152bw 100455 + +#define SPR_161em 100456 // Ԩ +#define SPR_161ax 100457 // +#define SPR_161cl 100458 // +#define SPR_161sp 100459 // +#define SPR_161bw 100460 // + +#define SPR_162em 100461 +#define SPR_162ax 100462 +#define SPR_162cl 100463 +#define SPR_162sp 100464 +#define SPR_162bw 100465 + +//ʧ߶ +#define SPR_leader 100500 // ĸѨʧ߶ +#define SPR_star 100501 // ززѨʧ߶ +#define SPR_boomerang 100502 // Ƥ¼ʧ߶ +#define SPR_stornbomb 100503 // ޼ʧ߶ +#define SPR_ono 100504 // ʧ߶ +#define SPR_onokage 100505 // ʧ߶ +#define SPR_isiware 100506 // ľʧ߶ +#define SPR_mail 100507 // ʧ߶ +//ʧ߶ +#define SPR_stone 100550 // ޼ʧ߶ +#define SPR_shock 100551 // ʧ߶ +#define SPR_drunk 100552 // жʧ߶ +#define SPR_sleep 100553 // Իʧ߶ +#define SPR_conf 100554 // ٶʧ߶ +#define SPR_poison 100555 // ʧ߶ +#define SPR_zokusei 100556 // ʧ߶ +//ްʧ߶ +#define SPR_effect01 100600 // ʧ߶ +#define SPR_heal 100601 // ʧ߶ +#define SPR_heal2 100602 // ʧ߶ +#define SPR_heal3 100603 // ʧ߶ +#define SPR_tyusya 100604 // ʧ߶ ټ +#define SPR_hoshi 100605 // ëľ弰ʧ߶ +#define SPR_kyu 100606 // ëľ弰ʧ߶ +#define SPR_fukkatu1 100607 // ëľ弰ʧ߶ +#define SPR_fukkatu2 100608 // ëľ弰ʧ߶ +#define SPR_fukkatu3 100609 // ëľ弰ʧ߶ +#define SPR_difence 100610 // ëľ弰ʧ߶ +#define SPR_item 100611 // ʧ ةë弰ʧ߶ +#define SPR_item3 100612 // ʧ ةë弰ʧ߶ +// ʧ߶ +#define SPR_mirror 100650 // ʧ߶ +#define SPR_barrior 100651 // ʧʧ߶ + +// շ ƥئ ****************************************************/ +#define CG_INVISIBLE 99 // ľƱ ľئ +//#define CG_GRID_CURSOR 99 +#define CG_MOUSE_CURSOR 25000 +#define CG_GRID_CURSOR 25001 + +// ʾ +#define CG_BTL_BUTTON_ATTACK_UP 25100 +#define CG_BTL_BUTTON_ATTACK_DOWN 25101 +#define CG_BTL_BUTTON_JUJUTU_UP 25102 +#define CG_BTL_BUTTON_JUJUTU_DOWN 25103 +#define CG_BTL_BUTTON_CAPTURE_UP 25104 +#define CG_BTL_BUTTON_CAPTURE_DOWN 25105 +#define CG_BTL_BUTTON_HELP_UP 25106 +#define CG_BTL_BUTTON_HELP_DOWN 25107 +#define CG_BTL_BUTTON_GUARD_UP 25108 +#define CG_BTL_BUTTON_GUARD_DOWN 25109 +#define CG_BTL_BUTTON_ITEM_UP 25110 +#define CG_BTL_BUTTON_ITEM_DOWN 25111 +#define CG_BTL_BUTTON_PET_UP 25112 +#define CG_BTL_BUTTON_PET_DOWN 25113 +#define CG_BTL_BUTTON_ESCAPE_UP 25114 +#define CG_BTL_BUTTON_ESCAPE_DOWN 25115 +#define CG_BTL_BUTTON_BASE 25116 // ʾܽ +#define CG_BTL_BUTTON_CROSS 25117 // ʾ + +// ʧ +#define CG_ATR_ICON_EARTH_BIG 25120 // +#define CG_ATR_ICON_EARTH_MDL 25121 // +#define CG_ATR_ICON_EARTH_SML 25122 // +#define CG_ATR_ICON_WATER_BIG 25123 // +#define CG_ATR_ICON_WATER_MDL 25124 // +#define CG_ATR_ICON_WATER_SML 25125 // +#define CG_ATR_ICON_FIRE_BIG 25126 // ܣ +#define CG_ATR_ICON_FIRE_MDL 25127 // ܣ +#define CG_ATR_ICON_FIRE_SML 25128 // ܣ +#define CG_ATR_ICON_WIND_BIG 25129 // 뮣 +#define CG_ATR_ICON_WIND_MDL 25130 // 뮣 +#define CG_ATR_ICON_WIND_SML 25131 // 뮣 + +// ʧ +#define CG_ATR_ICON_EARTH_BATTLE 25132 // +#define CG_ATR_ICON_WATER_BATTLE 25133 // +#define CG_ATR_ICON_FIRE_BATTLE 25134 // ܣ +#define CG_ATR_ICON_WIND_BATTLE 25135 // 뮣 + +// ʸʾ +#define CG_PET_BTL_BUTTON_BASE 25140 // ʾܽ +#define CG_PET_BTL_BUTTON_WAZA_UP 25141 // ʾ +#define CG_PET_BTL_BUTTON_WAZA_DOWN 25142 // ʾ +#define CG_PET_BTL_BUTTON_CANCEL_UP 25143 // ƽҼʾ + +// Ѩ +#define CG_HIT_MARK_00 25500 // +#define CG_HIT_MARK_01 25501 // + +#define CG_HIT_MARK_10 25502 // +#define CG_HIT_MARK_11 25503 +#define CG_HIT_MARK_12 25504 + +#define CG_HIT_MARK_20 25505 // ձ +#define CG_HIT_MARK_21 25506 +#define CG_HIT_MARK_22 25507 + +#define CG_HIT_MARK_30 25508 // +#define CG_HIT_MARK_31 25509 +#define CG_HIT_MARK_32 25510 + +#define CG_HIT_MARK_40 25511 // +#define CG_HIT_MARK_41 25512 +#define CG_HIT_MARK_42 25513 + +// +#define CG_SPEECH_BTL_OK 25520 +#define CG_SPEECH_CHANGE 25521 +#define CG_SPEECH_GROUP 25522 +#define CG_SPEECH_SUCCESS 25523 +#define CG_SPEECH_YATTA 25524 +#define CG_SPEECH_HELP 25525 + +// ޼Ѩ +#define CG_VS_MARK_1A 25610 +#define CG_VS_MARK_1B 25611 +#define CG_VS_MARK_2A 25612 +#define CG_VS_MARK_2B 25613 +#define CG_VS_MARK_3A 25614 +#define CG_VS_MARK_3B 25615 +#define CG_VS_MARK_4A 25616 +#define CG_VS_MARK_4B 25617 +#define CG_VS_MARK_5A 25618 +#define CG_VS_MARK_5B 25619 +#define CG_VS_MARK_6A 25620 +#define CG_VS_MARK_6B 25621 +#define CG_VS_MARK_7A 25622 +#define CG_VS_MARK_7B 25623 +#define CG_VS_MARK_8A 25624 +#define CG_VS_MARK_8B 25625 +#define CG_VS_MARK_9A 25626 +#define CG_VS_MARK_9B 25627 +#define CG_VS_MARK_10A 25628 +#define CG_VS_MARK_10B 25629 + +// +#define CG_ARROW_00 25630 +#define CG_ARROW_01 25631 +#define CG_ARROW_02 25632 +#define CG_ARROW_03 25633 +#define CG_ARROW_04 25634 +#define CG_ARROW_05 25635 +#define CG_ARROW_06 25636 +#define CG_ARROW_07 25637 +#define CG_ARROW_08 25638 +#define CG_ARROW_09 25639 +#define CG_ARROW_10 25640 +#define CG_ARROW_11 25641 +#define CG_ARROW_12 25642 +#define CG_ARROW_13 25643 +#define CG_ARROW_14 25644 +#define CG_ARROW_15 25645 + +// ĸٯ +#define CG_CNT_DOWN_0 25900 +#define CG_CNT_DOWN_1 25901 +#define CG_CNT_DOWN_2 25902 +#define CG_CNT_DOWN_3 25903 +#define CG_CNT_DOWN_4 25904 +#define CG_CNT_DOWN_5 25905 +#define CG_CNT_DOWN_6 25906 +#define CG_CNT_DOWN_7 25907 +#define CG_CNT_DOWN_8 25908 +#define CG_CNT_DOWN_9 25909 + +// ū +#define CG_WND_G_0 26001 +#define CG_WND_G_1 26002 +#define CG_WND_G_2 26003 +#define CG_WND_G_3 26004 +#define CG_WND_G_4 26005 +#define CG_WND_G_5 26006 +#define CG_WND_G_6 26007 +#define CG_WND_G_7 26008 +#define CG_WND_G_8 26009 + +// ū +#define CG_WND_TITLE_SYSTEM 26010 +#define CG_WND_TITLE_LOGOUT 26011 +#define CG_WND_TITLE_CHAT 26015 +#define CG_WND_TITLE_BGM 26016 +#define CG_WND_TITLE_SE 26017 +#define CG_WND_TITLE_RESULT 26018 + +// +#define CG_TASK_BAR_BACK 26012 + +// ݼ +#define CG_BATTLE_BAR_PLAYER 26013 // +#define CG_BATTLE_BAR_PLAYER_2 26019 // +#define CG_BATTLE_BAR_PET 26014 // ְ +#define CG_BATTLE_BAR_PET_2 26020 // ʸ + +// ū +#define CG_WND2_G_0 26021 +#define CG_WND2_G_1 26022 +#define CG_WND2_G_2 26023 +#define CG_WND2_G_3 26024 +#define CG_WND2_G_4 26025 +#define CG_WND2_G_5 26026 +#define CG_WND2_G_6 26027 +#define CG_WND2_G_7 26028 +#define CG_WND2_G_8 26029 + +// ū +#define CG_WND3_G_7 26037 // Ʊģ ٯë +#define CG_WND3_G_8 26038 +#define CG_WND3_G_9 26039 + +// ū +#define CG_BTL_PET_CHANGE_WND 26040 // ݼʸ ľ׸ū +#define CG_BTL_PET_RETURN_BTN 26041 // ݼʸ ʾ + +// ʾ +#define CG_CLOSE_BTN 26042 // Ԫʾ +#define CG_RETURN_BTN 26043 // ʾ +#define CG_OK_BTN 26093 // ʾ +#define CG_CANCEL_BTN 26050 // ƽҼʾ + +#define CG_YES_BTN 26094 // ""ʾ +#define CG_NO_BTN 26095 // ""ʾ +#define CG_EXIT_BTN 26096 // ""ʾ +#define CG_SEAL_BTN 26097 // ""ʾ +#define CG_BUY_BTN 26098 // ""ʾ + +// ʸū +#define CG_PET_WND_VIEW 26044 // ʸ ū +#define CG_PET_WND_DETAIL 26045 // ʸū + +#define CG_PET_WND_WAZA_BTN 26046 // ʾ +//#define CG_PREV_BTN 26047 // Ի׸ʾ +//#define CG_NEXT_BTN 26048 // ݱԻ׸ʾ +#define CG_NAME_CHANGE_WND 26049 // ū +//#define CG_NAME_CHANGE_BTN 26051 // ʾ +#define CG_NAME_CHANGE_BTN 26058 // ʾ +#define CG_NAME_CHANGE_BTN_DOWN 26059 // ʾ + +#define CG_PET_WND_REST_BTN 26052 // ʸʾ +#define CG_PET_WND_STANDBY_BTN 26053 // ʸʾ +#define CG_PET_WND_BTL_BTN 26054 // ʸʾ +#define CG_PET_WND_MAIL_BTN 26055 // ʸʾ +#define CG_PET_WND_STATUS_BTN 26056 // ʸʾ + + +// ʧ ةū +#define CG_ITEM_WND_0 26060 // ʧ ةū +#define CG_ITEM_WND_1 26061 // ʧ ةūƱ +#define CG_ITEM_WND_GOLD_DROP_BTN_UP 26062 // ʾ +#define CG_ITEM_WND_GOLD_DROP_BTN_DOWN 26063 // ʾ +#define CG_ITEM_WND_GOLD_INC_BTN_UP 26064 // ֧ʾ +#define CG_ITEM_WND_GOLD_INC_BTN_DOWN 26065 // ֧ʾ +#define CG_ITEM_WND_GOLD_DEC_BTN_UP 26066 // Ӽʾ +#define CG_ITEM_WND_GOLD_DEC_BTN_DOWN 26067 // Ӽʾ +#define CG_JUJUTU_WND 26068 // ū +#define CG_ITEM_WND_JUJUTU_BTN 26069 // ʧ ةūʾ +#define CG_ITEM_WND_SELECT_WND 26070 // ū +#define CG_STATUS_WND_GROUP_WND 26071 // ū +#define CG_BTL_ITEM_WND_TITLE 26072 // ݼʧ ةū + +// ū +#define CG_STATUS_WND 26073 // ū +#define CG_STATUS_WND_VICTORY_MARK 26074 // Ѩ +#define CG_STATUS_WND_LV_UP_POINT 26075 // ìʧ ٯ +#define CG_STATUS_WND_UP_BTN_UP 26076 // ʧʾ +#define CG_STATUS_WND_UP_BTN_DOWN 26077 // ʧʾ +#define CG_STATUS_WND_SHOUGOU_BTN_UP 26078 // įʾ +#define CG_STATUS_WND_SHOUGOU_BTN_DOWN 26079 // įʾ +#define CG_STATUS_WND_GROUP_BTN 26080 // ʾ + +// Ѩū +#define CG_MAP_WND 26081 // Ѩū + +// ū +#define CG_MAIL_WND 26082 // ū +#define CG_MAIL_WND_SEND_WND 26200 // ˪ū +#define CG_MAIL_WND_PET_SEND_WND 26201 // ʸ˪ū +#define CG_MAIL_WND_ITEM_BTN 26202 // ʧ ةʾ +#define CG_MAIL_WND_HISTORY_WND 26203 // ū + +//#define CG_MAIL_WND_MAIL_BTN 26083 // ʾ +#define CG_MAIL_WND_ON_LINE_SUN_BTN 26084 // ̼ʾ +#define CG_MAIL_WND_ON_LINE_MOON_BTN 26088 // ̼ʾ +#define CG_MAIL_WND_OFF_LINE_BTN 26085 // ̼ʾ +#define CG_MAIL_WND_MAIL_BTN 26086 // ʾ +#define CG_MAIL_WND_DELETE_BTN 26087 // ʾ +#define CG_MAIL_WND_CLEAR_BTN_UP 26172 // ʧʾ +#define CG_MAIL_WND_CLEAR_BTN_DOWN 26173 // ʧʾ +#define CG_SEND_BTN 26099 // ""ʾ +#define CG_SEND_BTN_DOWN 26174 // ""ʾ + +// ʧةū +#define CG_ALBUM_WND 26230 // ʧةū +#define CG_ALBUM_WND_NEW_ICON 26231 // ޥʧ +#define CG_ALBUM_WND_SNAP_BTN_UP 26170 // ީë +#define CG_ALBUM_WND_SNAP_BTN_DOWN 26171 // ީë + +// ٯ ū +#define CG_CHAT_REGISTY_WND 26232 + +// ٯ Ի ū +#define CG_COMMON_WIN_YORO 26090 // ""̤ľū +#define CG_COMMON_YES_BTN 26091 // ʾ +#define CG_COMMON_NO_BTN 26092 // ʾ + +// ū ʾ +#define CG_FIELD_MENU_LEFT 26100 // +#define CG_FIELD_MENU_BTN_OFF 26101 // بʾ +#define CG_FIELD_MENU_BTN_ON 26102 // بʾ +#define CG_FIELD_CARD_BTN_OFF 26103 // ͭʾ +#define CG_FIELD_CARD_BTN_ON 26104 // ͭʾ +#define CG_FIELD_GROUP_BTN_OFF 26105 // ʾ +#define CG_FIELD_GROUP_BTN_ON 26106 // ʾ +#define CG_FIELD_MAIL_LAMP 26107 // ﰾ¼ +#define CG_FIELD_MENU_RIGHT 26110 // +#define CG_FIELD_JOIN_BTL_BTN_OFF 26111 // ʾ +#define CG_FIELD_JOIN_BTL_BTN_ON 26112 // ʾ +#define CG_FIELD_DUEL_BTN_OFF 26113 // ʾ +#define CG_FIELD_DUEL_BTN_ON 26114 // ʾ +#define CG_FIELD_ACT_BTN_OFF 26115 // ʧʾ +#define CG_FIELD_ACT_BTN_ON 26116 // ʧʾ +#define CG_FIELD_AM_PM_00 26117 // ƻ °ū +#define CG_FIELD_AM_PM_01 26118 // ƻ °ū +#define CG_FIELD_AM_PM_02 26119 // ƻ °ū +#define CG_FIELD_AM_PM_03 26120 // ƻ °ū +#define CG_FIELD_MENU_RIGHT_BACK 26121 // 缰 + +// ʸ ū +#define CG_PET_WAZA_WND 26130 +#define CG_PET_WAZA_BAR_1 26131 +#define CG_PET_WAZA_BAR_2 26132 +#define CG_PET_WAZA_BAR_3 26133 +#define CG_PET_WAZA_BAR_4 26134 +#define CG_PET_WAZA_BAR_5 26135 +#define CG_PET_WAZA_BAR_6 26136 +#define CG_PET_WAZA_BAR_7 26137 + +// ʧ ةū +#define CG_ITEMSHOP_WIN 26138 + +// ū +#define CG_SKILLSHOP_WIN 26139 + +// 继 ū +#define CG_ITEMSHOP_KOSU_WIN 26140 + +// ʾ +#define CG_TASK_BAR_MAP_UP 26150 +#define CG_TASK_BAR_MAP_DOWM 26151 +#define CG_TASK_BAR_STATUS_UP 26152 +#define CG_TASK_BAR_STATUS_DOWN 26153 +#define CG_TASK_BAR_PET_UP 26154 +#define CG_TASK_BAR_PET_DOWN 26155 +#define CG_TASK_BAR_ITEM_UP 26156 +#define CG_TASK_BAR_ITEM_DOWN 26157 +#define CG_TASK_BAR_MAIL_UP 26158 +#define CG_TASK_BAR_MAIL_DOWN 26159 +#define CG_TASK_BAR_ALBUM_UP 26160 +#define CG_TASK_BAR_ALBUM_DOWN 26161 +#define CG_TASK_BAR_SYSTEM_UP 26162 +#define CG_TASK_BAR_SYSTEM_DOWN 26163 + +// ʾ +#define CG_PREV_BTN 26180 // ʾ +#define CG_PREV_BTN_DOWN 26181 // ʾ +#define CG_NEXT_BTN 26182 // ʾ +#define CG_NEXT_BTN_DOWN 26183 // ʾ + +#define CG_PREV_BTN2 26184 // ʾ +#define CG_PREV_BTN2_DOWN 26185 // ʾ +#define CG_NEXT_BTN2 26186 // ʾ +#define CG_NEXT_BTN2_DOWN 26187 // ʾ + +#define CG_UP_BTN 26188 // ʾ +#define CG_UP_BTN_DOWN 26189 // ʾ +#define CG_DOWN_BTN 26190 // ʾ +#define CG_DOWN_BTN_DOWN 26191 // ʾ + + +// ʧ +#define CG_ICON_FUKIDASI 26500 // +#define CG_ICON_COME_ON 26501 // Come On! +#define CG_ICON_GO 26502 // Go! +#define CG_ICON_WATCHING 26503 // Watching +#define CG_ICON_MISS 26504 // Miss... +#define CG_ICON_FAIL 26505 // Fail... +#define CG_ICON_GET 26506 // Get!! +#define CG_ICON_COUNTER 26507 // Counter! +#define CG_ICON_DANGER 26508 // Danger! +#define CG_ICON_NO 26509 // No! +#define CG_ICON_GUARD 26510 // Guard! +#define CG_ICON_ESCAPE 26511 // Escape! +#define CG_ICON_CAPTURE 26512 // Capture! +#define CG_ICON_LEAVE 26513 // Leave! +#define CG_ICON_GUARD_BREAK 26514 // Guard Break! + +// ʸӿ ƺ°ū +#define CG_NOW_PAINTING 28999 + +// +#define CG_LOGO 29000 +#define CG_TITLE 29001 +#define CG_TITLE_NAME_S 29002 +#define CG_TITLE_NAME_T 29003 +#define CG_TITLE_NAME_O 29004 +#define CG_TITLE_NAME_N 29005 +#define CG_TITLE_NAME_E 29006 +#define CG_TITLE_NAME_A 29007 +#define CG_TITLE_NAME_G 29008 +#define CG_TITLE_NAME_E2 29009 +#define CG_TITLE_NAME 29010 +#define CG_TITLE_NAME_FLASH 29011 +#define CG_TITLE_NAME_FLASH1 29012 +#define CG_TITLE_NAME_FLASH2 29013 +#define CG_TITLE_NAME_FLASH3 29014 +#define CG_TITLE_NAME_FLASH4 29015 +#define CG_TITLE_NAME_FLASH5 29016 +#define CG_TITLE_JSS_LOGO 29017 +#define CG_TITLE_DREAM_LOGO 29018 +#define CG_TITLE_NOW_LOADING 29019 +#define CG_TITLE_ID_PASS 29020 +#define CG_TITLE_ID_PASS_OK 29021 +#define CG_TITLE_ID_PASS_QUIT 29022 + +// ƽҷ +#define CG_CHR_MAKE_SEL_BG 29030 // ޥƽҷ¼ +#define CG_CHR_MAKE_BG 29031 // ޥƽҷɷ¶Ի +#define CG_CHR_SEL_BG 29032 // ƽҷ +#define CG_CHR_SEL_LOGIN_BTN 29033 // ̼ʾ +#define CG_CHR_SEL_NEW_BTN 29034 // ޥʾ +#define CG_CHR_SEL_DEL_BTN 29035 // ʾ +#define CG_CHR_SEL_BACK_BTN 29036 // ʾ +#define CG_CHR_MAKE_OK_BTN 29037 // ޥƽҷ ʾ +#define CG_CHR_MAKE_BACK_BTN 29038 // ޥƽҷ ʾ +#define CG_CHR_MAKE_SEL2_BG 29039 // 컩 +#define CG_CHR_MAKE_HOME_NAME0 29040 // 컩 ة׻P̣ +#define CG_CHR_MAKE_HOME_NAME1 29041 // 컩 Ѩϵ̣ +#define CG_CHR_MAKE_HOME_NAME2 29042 // 컩 ҳҼ̣ +#define CG_CHR_MAKE_HOME_NAME3 29043 // 컩 лϼ̣ +#define CG_CHR_MAKE_EYE_SEL 29044 // ޥƽҷ +#define CG_CHR_MAKE_NOSE_SEL 29045 // ޥƽҷ +#define CG_CHR_MAKE_FACE 30000 // ƽҷӿ 쫷 + +#ifdef _MO_IMAGE_EXTENSION +#define CG_CHR_MAKE_NEWFACE 44500 + +#define SPRNEW_001em 102003 // +#define SPRNEW_001ax 102004 //ͷ ? +#define SPRNEW_001cl 102005 //ľ ??S +#define SPRNEW_001sp 102006 //ì ? +#define SPRNEW_001bw 102007 // ? + +#define SPRNEW_002em 102008 //ˮ +#define SPRNEW_002ax 102009 //ͷ ? +#define SPRNEW_002cl 102010 //ľ ??S +#define SPRNEW_002sp 102011 //ì ? +#define SPRNEW_002bw 102012 // + +#define SPRNEW_003em 102013 // +#define SPRNEW_003ax 102014 //ͷ ? +#define SPRNEW_003cl 102015 //ľ ??S +#define SPRNEW_003sp 102016 //ì ? +#define SPRNEW_003bw 102017 // + +#define SPRNEW_004em 102018 // +#define SPRNEW_004ax 102019 //ͷ ? +#define SPRNEW_004cl 102020 //ľ ??S +#define SPRNEW_004sp 102021 //ì ? +#define SPRNEW_004bw 102022 // + + +#define SPRNEW_005em 102023 // +#define SPRNEW_005ax 102024 //ͷ ? +#define SPRNEW_005cl 102025 //ľ ??S +#define SPRNEW_005sp 102026 //ì ? +#define SPRNEW_005bw 102027 // ? + +#define SPRNEW_006em 102028 //ˮ +#define SPRNEW_006ax 102029 //ͷ ? +#define SPRNEW_006cl 102030 //ľ ??S +#define SPRNEW_006sp 102031 //ì ? +#define SPRNEW_006bw 102032 // + +#define SPRNEW_007em 102033 // +#define SPRNEW_007ax 102034 //ͷ ? +#define SPRNEW_007cl 102035 //ľ ??S +#define SPRNEW_007sp 102036 //ì ? +#define SPRNEW_007bw 102037 // + +#define SPRNEW_008em 102038 // +#define SPRNEW_008ax 102039 //ͷ ? +#define SPRNEW_008cl 102040 //ľ ??S +#define SPRNEW_008sp 102041 //ì ? +#define SPRNEW_008bw 102042 // + +#define SPRNEW_009em 102043 // +#define SPRNEW_009ax 102044 //ͷ ? +#define SPRNEW_009cl 102045 //ľ ??S +#define SPRNEW_009sp 102046 //ì ? +#define SPRNEW_009bw 102047 // ? + +#define SPRNEW_010em 102048 //ˮ +#define SPRNEW_010ax 102049 //ͷ ? +#define SPRNEW_010cl 102050 //ľ ??S +#define SPRNEW_010sp 102051 //ì ? +#define SPRNEW_010bw 102052 // + +#define SPRNEW_011em 102053 // +#define SPRNEW_011ax 102054 //ͷ ? +#define SPRNEW_011cl 102055 //ľ ??S +#define SPRNEW_011sp 102056 //ì ? +#define SPRNEW_011bw 102057 // + +#define SPRNEW_012em 102058 // +#define SPRNEW_012ax 102059 //ͷ ? +#define SPRNEW_012cl 102060 //ľ ??S +#define SPRNEW_012sp 102061 //ì ? +#define SPRNEW_012bw 102062 // + + +#define SPRNEW_013em 102063 // +#define SPRNEW_013ax 102064 //ͷ ? +#define SPRNEW_013cl 102065 //ľ ??S +#define SPRNEW_013sp 102066 //ì ? +#define SPRNEW_013bw 102067 // ? + +#define SPRNEW_014em 102068 //ˮ +#define SPRNEW_014ax 102069 //ͷ ? +#define SPRNEW_014cl 102070 //ľ ??S +#define SPRNEW_014sp 102071 //ì ? +#define SPRNEW_014bw 102072 // + +#define SPRNEW_015em 102073 // +#define SPRNEW_015ax 102074 //ͷ ? +#define SPRNEW_015cl 102075 //ľ ??S +#define SPRNEW_015sp 102076 //ì ? +#define SPRNEW_015bw 102077 // + +#define SPRNEW_016em 102078 // +#define SPRNEW_016ax 102079 //ͷ ? +#define SPRNEW_016cl 102080 //ľ ??S +#define SPRNEW_016sp 102081 //ì ? +#define SPRNEW_016bw 102082 // + +#define SPRNEW_017em 102089 // +#define SPRNEW_017ax 102090 //ͷ ? +#define SPRNEW_017cl 102091 //ľ ??S +#define SPRNEW_017sp 102092 //ì ? +#define SPRNEW_017bw 102093 // + +#define SPRNEW_018em 102094 // +#define SPRNEW_018ax 102095 //ͷ ? +#define SPRNEW_018cl 102096 //ľ ??S +#define SPRNEW_018sp 102097 //ì ? +#define SPRNEW_018bw 102098 // + +#define SPRNEW_019em 102099 // +#define SPRNEW_019ax 102100 //ͷ ? +#define SPRNEW_019cl 102101 //ľ ??S +#define SPRNEW_019sp 102102 //ì ? +#define SPRNEW_019bw 102103 // + +#define SPRNEW_020em 102104 // +#define SPRNEW_020ax 102105 //ͷ ? +#define SPRNEW_020cl 102106 //ľ ??S +#define SPRNEW_020sp 102107 //ì ? +#define SPRNEW_020bw 102108 // + +#define SPRNEW_021em 102109 // +#define SPRNEW_021ax 102110 //ͷ ? +#define SPRNEW_021cl 102111 //ľ ??S +#define SPRNEW_021sp 102112 //ì ? +#define SPRNEW_021bw 102113 // + +#define SPRNEW_022em 102114 // +#define SPRNEW_022ax 102115 //ͷ ? +#define SPRNEW_022cl 102116 //ľ ??S +#define SPRNEW_022sp 102117 //ì ? +#define SPRNEW_022bw 102118 // + +#define SPRNEW_023em 102119 // +#define SPRNEW_023ax 102120 //ͷ ? +#define SPRNEW_023cl 102121 //ľ ??S +#define SPRNEW_023sp 102122 //ì ? +#define SPRNEW_023bw 102123 // + +#define SPRNEW_024em 102124 // +#define SPRNEW_024ax 102125 //ͷ ? +#define SPRNEW_024cl 102126 //ľ ??S +#define SPRNEW_024sp 102127 //ì ? +#define SPRNEW_024bw 102128 // +#endif + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/autil.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/autil.h new file mode 100644 index 0000000..4cb08be --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/autil.h @@ -0,0 +1,63 @@ +#include "version.h" +#include "common.h" + +#ifndef __UTIL_H_ +#define __UTIL_H_ + + +#define SLICE_MAX 20 +#define SLICE_SIZE 1024*96 + +extern char *MesgSlice[SLICE_MAX]; +extern int SliceCount; // count slices in MesgSlice + +extern char PersonalKey[4096]; + +#define DEFAULTTABLE \ + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}" +#define DEFAULTFUNCBEGIN "&" +#define DEFAULTFUNCEND "#" + +BOOL util_Init(void); + +// WON ADD +//void util_SplitMessage(char *source, char *separator); +BOOL util_SplitMessage(char *source, char *separator); +#ifdef _NEW_FUNC_DECRYPT +BOOL util_DecodeMessageTea(char *dst,char *sac); +#endif +void util_EncodeMessage(char *dst, char *src); +void util_DecodeMessage(char *dst, char *src); +int util_GetFunctionFromSlice(int *func, int *fieldcount); +void util_DiscardMessage(void); +#define util_SendMesg( fd, func, buffer) _util_SendMesg( __FILE__, __LINE__, fd, func, buffer) +void _util_SendMesg(char *file, int line, int fd, int func, char *buffer); + +// ------------------------------------------------------------------- +// Encoding function units. Use in Encrypting functions. +int util_256to64(char *dst, char *src, int len, char *table); +int util_64to256(char *dst, char *src, char *table); +int util_256to64_shr(char *dst, char *src, int len, char *table, char *key); +int util_shl_64to256(char *dst, char *src, char *table, char *key); +int util_256to64_shl(char *dst, char *src, int len, char *table, char *key); +int util_shr_64to256(char *dst, char *src, char *table, char *key); + +void util_swapint(int *dst, int *src, char *rule); +void util_xorstring(char *dst, char *src); +void util_shrstring(char *dst, char *src, int offs); +void util_shlstring(char *dst, char *src, int offs); +// ------------------------------------------------------------------- +// Encrypting functions +int util_deint(int sliceno, int *value); +int util_mkint(char *buffer, int value); +int util_destring(int sliceno, char *value); +int util_mkstring(char *buffer, char *value); + + +#ifdef _CRYPTO_DATA +void CryptoKey(char* usrkey); +void DecryptKey(char* usrkey); +void List(char *path); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle.h new file mode 100644 index 0000000..819a71e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle.h @@ -0,0 +1,765 @@ +#ifndef __BATTLE_H__ +#define __BATTLE_H__ +#include "net.h" +#ifdef _TRADE_PK +#include "trade.h" +#endif +#ifdef _ALLBLUES_LUA_1_4 +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#endif +#ifdef _MULTIPLAYER_ +#define BATTLE_ENTRY_MAX 12 +#define BATTLE_PLAYER_MAX 6 +#define SIDE_OFFSET 12 +#else +#define BATTLE_ENTRY_MAX 10 +#define BATTLE_PLAYER_MAX 5 +#define SIDE_OFFSET 10 +#endif +#define BATTLE_STRING_MAX 4096 +#define BATTLE_TIME_LIMIT (60*60) + + +#define DUELPOINT_RATE (0.1) + +enum{ + BATTLE_MODE_NONE = 0, // ս״̬ + BATTLE_MODE_INIT, // սʼ + BATTLE_MODE_BATTLE, // ս + BATTLE_MODE_FINISH, // ս + BATTLE_MODE_STOP, // ս(δʹ) + BATTLE_MODE_WATCHBC, // սʼ + BATTLE_MODE_WATCHPRE, // ս(û) + BATTLE_MODE_WATCHWAIT, // ս(û) + BATTLE_MODE_WATCHMOVIE, // ս(û) + BATTLE_MODE_WATCHAFTER, // ս(û) + BATTLE_MODE_END +}; + + +enum{ + BATTLE_TYPE_NONE = 0, + BATTLE_TYPE_P_vs_E = 1, + BATTLE_TYPE_P_vs_P = 2, + BATTLE_TYPE_E_vs_E = 3, + BATTLE_TYPE_WATCH = 4, + BATTLE_TYPE_DP_BATTLE = 5, + BATTLE_TYPE_BOSS_BATTLE = 6, + BATTLE_TYPE_END +}; + + +enum{ + BATTLE_CHARMODE_NONE = 0, // ս״̬ + BATTLE_CHARMODE_INIT, // սʼ + BATTLE_CHARMODE_C_WAIT, // ȴսָ + BATTLE_CHARMODE_C_OK, // սָ + BATTLE_CHARMODE_BATTLE, // δʹ + BATTLE_CHARMODE_RESCUE, // help״̬ + BATTLE_CHARMODE_FINAL, // ս + BATTLE_CHARMODE_WATCHINIT, // սʼ + BATTLE_CHARMODE_COMMAND, // δʹ + BATTLE_CHARMODE_END +}; + + + + +typedef enum{ + BATTLE_ERR_NONE = 0, + BATTLE_ERR_NOTASK, + BATTLE_ERR_NOUSE, + BATTLE_ERR_PARAM, + BATTLE_ERR_ENTRYMAX, + BATTLE_ERR_TYPE, + BATTLE_ERR_CHARAINDEX, + BATTLE_ERR_BATTLEINDEX, + BATTLE_ERR_NOENEMY, + BATTLE_ERR_ALREADYBATTLE, + BATTLE_ERR_SAMEPARTY, + BATTLE_ERR_END +}BATTLE_ERR; + + +enum{ + BATTLE_S_TYPE_PLAYER = 0, + BATTLE_S_TYPE_ENEMY, + BATTLE_S_TYPE_END +}; + + +typedef enum{ + BATTLE_COM_NONE, + BATTLE_COM_ATTACK, + BATTLE_COM_GUARD, + BATTLE_COM_CAPTURE, + BATTLE_COM_ESCAPE, + BATTLE_COM_PETIN, + BATTLE_COM_PETOUT, + BATTLE_COM_ITEM, + BATTLE_COM_BOOMERANG, + BATTLE_COM_COMBO, + BATTLE_COM_COMBOEND, + BATTLE_COM_WAIT, + + BATTLE_COM_SEKIBAN = 1000, + BATTLE_COM_S_RENZOKU, + BATTLE_COM_S_GBREAK, + BATTLE_COM_S_GUARDIAN_ATTACK, + BATTLE_COM_S_GUARDIAN_GUARD, + BATTLE_COM_S_CHARGE, + BATTLE_COM_S_MIGHTY, + BATTLE_COM_S_POWERBALANCE, + BATTLE_COM_S_STATUSCHANGE, + BATTLE_COM_S_EARTHROUND0, + BATTLE_COM_S_EARTHROUND1, + BATTLE_COM_S_LOSTESCAPE, + BATTLE_COM_S_ABDUCT, + BATTLE_COM_S_STEAL, + BATTLE_COM_S_NOGUARD, + BATTLE_COM_S_CHARGE_OK, + BATTLE_COM_JYUJYUTU = 2000, + + BATTLE_COM_COMPELESCAPE, //ǿ뿪 + +#ifdef _ATTACK_MAGIC + BATTLE_COM_S_ATTACK_MAGIC, // ħ +#endif + +#ifdef _PSKILL_FALLGROUND + BATTLE_COM_S_FALLRIDE, // +#endif +#ifdef _PETSKILL_EXPLODE + BATTLE_COM_S_EXPLODE, +#endif +#ifdef _PETSKILL_TIMID + BATTLE_COM_S_TIMID, +#endif +#ifdef _PETSKILL_2TIMID + BATTLE_COM_S_2TIMID, +#endif +#ifdef _PETSKILL_ANTINTER + BATTLE_COM_S_ANTINTER, +#endif +#ifdef _PETSKILL_PROPERTY + BATTLE_COM_S_PROPERTYSKILL, +#endif +#ifdef _PETSKILL_TEAR + BATTLE_COM_S_PETSKILLTEAR, +#endif +#ifdef _BATTLE_LIGHTTAKE + BATTLE_COM_S_LIGHTTAKE, +#endif +#ifdef _BATTLE_ATTCRAZED // ANDY + BATTLE_COM_S_ATTCRAZED, +#endif +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 + BATTLE_COM_S_ATTSHOOT, +#endif +#ifdef _BATTLESTEAL_FIX + BATTLE_COM_S_STEALMONEY, +#endif +#ifdef _PRO_BATTLEENEMYSKILL + BATTLE_COM_S_ENEMYRELIFE, //NPC ENEMY  + BATTLE_COM_S_ENEMYREHP, //NPC ENEMY Ѫ + BATTLE_COM_S_ENEMYHELP, //NPC ENEMY +#endif +#ifdef _SKILL_DAMAGETOHP + BATTLE_COM_S_DAMAGETOHP, //Ѫ +#endif +#ifdef _Skill_MPDAMAGE + BATTLE_COM_S_MPDAMAGE, //MP˺ +#endif +#ifdef _SKILL_WILDVIOLENT_ATT + BATTLE_COM_S_WILDVIOLENTATTACK, //񱩹 vincent add 2002/05/16 +#endif + +#ifdef _SKILL_SPEEDY_ATT + BATTLE_COM_S_SPEEDYATTACK, //ٹ vincent add 2002/05/20 +#endif +#ifdef _SKILL_GUARDBREAK2 + BATTLE_COM_S_GBREAK2, //Ƴ2 vincent add 2002/05/20 +#endif +#ifdef _SKILL_SACRIFICE + BATTLE_COM_S_SACRIFICE, //Ԯ vincent add 2002/05/30 +#endif +#ifdef _SKILL_WEAKEN + BATTLE_COM_S_WEAKEN, // vincent add 2002/07/11 +#endif +#ifdef _SKILL_DEEPPOISON + BATTLE_COM_S_DEEPPOISON, //綾 vincent add 2002/07/16 +#endif +#ifdef _SKILL_BARRIER + BATTLE_COM_S_BARRIER, //ħ vincent add 2002/07/16 +#endif +#ifdef _SKILL_NOCAST + BATTLE_COM_S_NOCAST, //Ĭ vincent add 2002/07/16 +#endif +#ifdef _SKILL_ROAR + BATTLE_COM_S_ROAR, // vincent add 2002/07/11 +#endif +#ifdef _BATTLENPC_WARP_PLAYER + BATTLE_COM_WARP, // npc warp player +#endif +#ifdef _SKILL_TOOTH + BATTLE_COM_S_TOOTHCRUSHE, +#endif +#ifdef _PSKILL_MODIFY + BATTLE_COM_S_MODIFYATT, +#endif +#ifdef _PSKILL_MDFYATTACK + BATTLE_COM_S_MDFYATTACK, +#endif +#ifdef _MAGIC_SUPERWALL + BATTLE_COM_S_SUPERWALL, +#endif +#ifdef _SKILL_REFRESH + BATTLE_COM_S_REFRESH, +#endif +#ifdef _VARY_WOLF + BATTLE_COM_S_VARY, +#endif +#ifdef _PETSKILL_SETDUCK + BATTLE_COM_S_SETDUCK, +#endif +#ifdef _MAGICPET_SKILL + BATTLE_COM_S_SETMAGICPET, +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + +// ʦ + BATTLE_COM_S_VOLCANO_SPRINGS, // ɽȪ + BATTLE_COM_S_FIRE_BALL, // + BATTLE_COM_S_FIRE_SPEAR, // ǹ + BATTLE_COM_S_SUMMON_THUNDER, // + BATTLE_COM_S_CURRENT, // + BATTLE_COM_S_STORM, // + BATTLE_COM_S_ICE_ARROW, // + BATTLE_COM_S_ICE_CRACK, // + BATTLE_COM_S_ICE_MIRROR, // + BATTLE_COM_S_DOOM, // ĩ + BATTLE_COM_S_BLOOD, // Ѫ + BATTLE_COM_S_BLOOD_WORMS, // Ѫ + BATTLE_COM_S_SIGN, // һѪ + BATTLE_COM_S_FIRE_ENCLOSE, // + BATTLE_COM_S_ICE_ENCLOSE, // + BATTLE_COM_S_THUNDER_ENCLOSE, // ׸ + BATTLE_COM_S_ENCLOSE, // + BATTLE_COM_S_TRANSPOSE, // λλ +// ʿ + BATTLE_COM_S_BRUST, // + BATTLE_COM_S_CHAIN_ATK, // + BATTLE_COM_S_AVOID, // ر + BATTLE_COM_S_RECOVERY, // Ѫ + BATTLE_COM_S_WEAPON_FOCUS, // ר + BATTLE_COM_S_REBACK, // ״̬ظ + BATTLE_COM_S_CHAIN_ATK_2, // ˫ع + BATTLE_COM_S_SCAPEGOAT, // Ϊ + BATTLE_COM_S_ENRAGE, // + BATTLE_COM_S_COLLECT, // ۼ + BATTLE_COM_S_FOCUS, // רעս + BATTLE_COM_S_SHIELD_ATTACK, // ܻ + BATTLE_COM_S_DUAL_WEAPON, // + BATTLE_COM_S_DEFLECT, // + BATTLE_COM_S_THROUGH_ATTACK, // ᴩ + BATTLE_COM_S_CAVALRY, // ﹥ + BATTLE_COM_S_DEAD_ATTACK, // + BATTLE_COM_S_CONVOLUTE, // + BATTLE_COM_S_CHAOS, // ҹ +// + BATTLE_COM_S_TRAP, // + BATTLE_COM_S_TRACK, // ׷Ѱ + BATTLE_COM_S_DOCILE, // ѱ + BATTLE_COM_S_ENRAGE_PET, // ŭ + BATTLE_COM_S_DRAGNET, // ޵ + BATTLE_COM_S_ENTWINE, // + BATTLE_COM_S_AUTARKY, // Ը + BATTLE_COM_S_PLUNDER, // Ӷ + BATTLE_COM_S_TOXIN_WEAPON, // + BATTLE_COM_S_RESIST_FIRE, // + BATTLE_COM_S_RESIST_ICE, // + BATTLE_COM_S_RESIST_THUNDER, // ׿ + BATTLE_COM_S_G_RESIST_FIRE, // + BATTLE_COM_S_G_RESIST_ICE, // + BATTLE_COM_S_G_RESIST_THUNDER, // ׿ + BATTLE_COM_S_ATTACK_WEAK, // 㹥 + BATTLE_COM_S_INSTIGATE, // + BATTLE_COM_S_OBLIVION, // +#ifdef _PROFESSION_ADDSKILL + BATTLE_COM_S_RESIST_F_I_T, // Ȼ + BATTLE_COM_S_CALL_NATURE, // Ȼ + BATTLE_COM_S_BOUNDARY, // Խ +#endif +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + BATTLE_COM_S_SARS, +#endif +#ifdef _SONIC_ATTACK // WON ADD + BATTLE_COM_S_SONIC, + BATTLE_COM_S_SONIC2, +#endif +#ifdef _PETSKILL_REGRET + BATTLE_COM_S_REGRET, + BATTLE_COM_S_REGRET2, +#endif +#ifdef _PETSKILL_GYRATE + BATTLE_COM_S_GYRATE, +#endif +#ifdef _PETSKILL_ACUPUNCTURE + BATTLE_COM_S_ACUPUNCTURE, +#endif +#ifdef _PETSKILL_RETRACE + BATTLE_COM_S_RETRACE, +#endif +#ifdef _PETSKILL_HECTOR + BATTLE_COM_S_HECTOR, +#endif +#ifdef _PETSKILL_FIREKILL + BATTLE_COM_S_FIREKILL, +#endif +#ifdef _PETSKILL_DAMAGETOHP + BATTLE_COM_S_DAMAGETOHP2, //¿(Ѫı) +#endif +#ifdef _PETSKILL_BECOMEFOX + BATTLE_COM_S_BECOMEFOX, +#endif +#ifdef _PETSKILL_BECOMEPIG + BATTLE_COM_S_BECOMEPIG, +#endif +#ifdef _PETSKILL_SHOWMERCY + BATTLE_COM_S_SHOWMERCY, +#endif +#ifdef _PETSKILL_LER + BATTLE_COM_S_BAT_FLY, // ׶ - ȺĴ + BATTLE_COM_S_DIVIDE_ATTACK, // ׶ - +#endif +#ifdef _PETSKILL_BATTLE_MODEL + BATTLE_COM_S_BATTLE_MODEL, // \սģ +#endif + +#ifdef _MASSAGE_PETSKILL + BATTLE_COM_S_MASSAGE, // ɱ +#endif + +#ifdef _STRENGTH_PETSKILL + BATTLE_COM_S_STRENGTH, // Ԫ +#endif +#ifdef _RESURRECTION_PETSKILL + BATTLE_COM_S_RESURRECTION, +#endif +#ifdef _LOSTLOST_PETSKILL + BATTLE_COM_S_LOSTLOST, +#endif +#ifdef _GRAPPLING_PETSKILL + BATTLE_COM_S_GRAPPLING, +#endif +#ifdef _PETOUT_PETSKILL + BATTLE_COM_S_PETOUT, +#endif +#ifdef _OFFLINE_SYSTEM + BATTLE_COM_S_OFFLINE_RECOVERY, +#endif +#ifdef _INVERSION_PETSKILL + BATTLE_COM_S_INVERSION, // ת +#endif +#ifdef _PETSKILL_NEW_PASSIVE + BATTLE_COM_S_PASSIVE_PET_MATCH1, //ﵥϱ + BATTLE_COM_S_PASSIVE_PET_MATCH2, //˫ϱ + BATTLE_COM_S_PASSIVE_PET_MATCH3, //ϱ + BATTLE_COM_S_PASSIVE_PET_MATCH4, //ϱ + BATTLE_COM_S_PASSIVE_PET_MATCH5, //ϱ +#endif + BATTLE_COM_END +}BATTLE_COM; + + +enum{ + BATTLE_RET_NORMAL, + BATTLE_RET_CRITICAL, + BATTLE_RET_MISS, + BATTLE_RET_DODGE, + BATTLE_RET_ALLGUARD, +#ifdef _EQUIT_ARRANGE + BATTLE_RET_ARRANGE, +#endif + BATTLE_RET_END +}BATTLE_RET; + + +#define BC_FLG_NEW (1<<0) +#define BC_FLG_DEAD (1<<1) +#define BC_FLG_PLAYER (1<<2) +#define BC_FLG_POISON (1<<3) +#define BC_FLG_PARALYSIS (1<<4) +#define BC_FLG_SLEEP (1<<5) +#define BC_FLG_STONE (1<<6) +#define BC_FLG_DRUNK (1<<7) +#define BC_FLG_CONFUSION (1<<8) +#define BC_FLG_HIDE (1<<9) +#define BC_FLG_REVERSE (1<<10) +#ifdef _MAGIC_WEAKEN +#define BC_FLG_WEAKEN (1<<11) // +#endif +#ifdef _MAGIC_DEEPPOISON +#define BC_FLG_DEEPPOISON (1<<12) // 綾 +#endif +#ifdef _MAGIC_BARRIER +#define BC_FLG_BARRIER (1<<13) // ħ +#endif +#ifdef _MAGIC_NOCAST +#define BC_FLG_NOCAST (1<<14) // Ĭ +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ +#define BC_FLG_SARS (1<<15) // ɷ +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#define BC_FLG_DIZZY (1<<16) // ѣ +#define BC_FLG_ENTWINE (1<<17) // +#define BC_FLG_DRAGNET (1<<18) // ޵ +#define BC_FLG_ICECRACK (1<<19) // +#define BC_FLG_OBLIVION (1<<20) // +#define BC_FLG_ICEARROW (1<<21) // +#define BC_FLG_BLOODWORMS (1<<22) // Ѫ +#define BC_FLG_SIGN (1<<23) // һѪ +#define BC_FLG_CARY (1<<24) // +#define BC_FLG_F_ENCLOSE (1<<25) // +#define BC_FLG_I_ENCLOSE (1<<26) // +#define BC_FLG_T_ENCLOSE (1<<27) // ׸ +#ifdef _PROFESSION_ADDSKILL +#define BC_FLG_WATER (1<<28) // ˮ +#define BC_FLG_FEAR (1<<29) // ־ +#endif +#ifdef _PETSKILL_LER +#define BC_FLG_CHANGE (1<<30) // ׶ +#endif +#endif + + + + +#define BP_FLG_JOIN (1<<0) +#define BP_FLG_PLAYER_MENU_OFF (1<<1) +#define BP_FLG_BOOMERANG (1<<2) +#define BP_FLG_PET_MENU_OFF (1<<3) +#define BP_FLG_ENEMY_SURPRISAL (1<<4) +#define BP_FLG_PLAYER_SURPRISAL (1<<5) + + +#define CHAR_BATTLEFLG_ULTIMATE (1<<0) +#define CHAR_BATTLEFLG_AIBAD (1<<1) +#define CHAR_BATTLEFLG_REVERSE (1<<2) +#define CHAR_BATTLEFLG_GUARDIAN (1<<3) +#define CHAR_BATTLEFLG_NORETURN (1<<4) +#define CHAR_BATTLEFLG_RECOVERY (1<<5) +#define CHAR_BATTLEFLG_ABIO (1<<6) +#define CHAR_BATTLEFLG_NODUCK (1<<7) + +#define GETITEM_MAX 3 +typedef struct +{ + int attacker; +}INVADER; + +typedef struct +{ + int charaindex; + int bid; + int escape; + int flg; + int guardian; + int duelpoint; + int getitem[GETITEM_MAX]; +}BATTLE_ENTRY; +#define BENT_FLG_ULTIMATE (1<<0) + +typedef struct +{ + int type; + int flg; + int common_dp; + BATTLE_ENTRY Entry[BATTLE_ENTRY_MAX]; +}BATTLE_SIDE; + +#define BSIDE_FLG_SURPRISE ( 1 << 0 ) +#define BSIDE_FLG_HELP_OK ( 1 << 1 ) + + + +#ifdef _ALLBLUES_LUA_1_4 +typedef enum +{ + BATTLE_FINISH, + BATTLE_ESCAPE, + BATTLE_FUNCTABLENUM, +}BATTLE_FUNCTABLE; +#endif + + +typedef struct _Battle +{ + BOOL use; /* Ȼ¾ */ + int battleindex; /* į */ + int mode; /* ػ ƹ */ + int type; /* (0:ɧ)(1:DUEL)(2:ʾ) */ + int dpbattle; /* DPᆴ */ + int norisk; /* ƥͼ ᆴ */ + int turn; /* */ + int timer; /* Ѩ */ + int leaderindex; /* ޼ëڳƽҷ¼̼͵ */ +#ifdef _AUTO_PK + char leadercdkey[CDKEYLEN]; + char leadername[CHARNAMELEN]; + int rivalindex; + char rivalcdkey[CDKEYLEN]; + char rivalname[CHARNAMELEN]; +#endif + +#ifdef _TRADE_PK + STradeList TradeList[2]; +#endif + int BattleFloor; /* */ + int winside; /* */ + int field_att; /* ū */ + int att_count; /* ū Ѩ */ + int att_pow; /* ū ɷ */ + int field_no; + int flg; /* ˰׷º */ + BATTLE_SIDE Side[2]; +#ifdef _BATTLE_TIMESPEED + unsigned int CreateTime; + unsigned int EndTime; + unsigned int PartTime; + int flgTime; +#endif + +#ifdef _PROFESSION_ADDSKILL + // + int ice_count;//ݴ + int ice_bout[20];//غϼ + BOOL ice_use[20];//Ƿʹ + int ice_toNo[20];// + int ice_level[20];// + int ice_array[20]; + int ice_charaindex[20]; + int ice_attackNo[20]; +#endif + + int iEntryBack[BATTLE_ENTRY_MAX*2]; // ľ׶ + int iEntryBack2[BATTLE_ENTRY_MAX*2]; // ľ׶ + int createindex; /* 𼰾 ëԻƽҷ̼͵(NPCئ) */ + int (*WinFunc)( int battleindex, int charaindex ); +#ifdef _ALLBLUES_LUA_1_4 + lua_State *lua[BATTLE_FUNCTABLENUM]; + char *luafunctable[BATTLE_FUNCTABLENUM]; +#endif + struct _Battle *pNext; // ݼ + struct _Battle *pBefore; // 󡼰 +#ifdef _BATTLE_TIME + unsigned int tv_sec; + unsigned int tv_usec; +#endif +#ifdef _JZ_NEWSCRIPT_LUA + int (*BakFunc)(int battleindex , int charaindex); + int (*EndFunc)( int battleindex ); + char BakLuaFuncName[32]; + char EndLuaFuncName[32]; + int EndLuaIndex; + int floor; + int battletime; +#endif +}BATTLE; + +#define BATTLE_FLG_FREEDP ( 1 << 0 ) // ͻ Ӽئ +#define BATTLE_FLG_CHARALOST ( 1 << 1 ) // ƽҷ»ϷԻ Իƻ + +enum{ // field_att ľ° + BATTLE_ATTR_NONE = 0, // + BATTLE_ATTR_EARTH, // + BATTLE_ATTR_WATER, // + BATTLE_ATTR_FIRE, // + BATTLE_ATTR_WIND, // + BATTLE_ATTR_END +}; + + +//krynn 2001/12/28 +enum +{ + BATTLE_SIDE_RIGHT, // սҲ right side of battle + BATTLE_SIDE_LEFT, // ս left side of battle + BATTLE_SIDE_WATCH, // ս watch battle player +}; +//krynn end + +#define TARGET_SIDE_0 20 // +#define TARGET_SIDE_1 21 // +#define TARGET_ALL 22 // ȫ + +#ifdef _ATTACK_MAGIC + +#define TARGET_SIDE_0_B_ROW 26 // һ +#define TARGET_SIDE_0_F_ROW 25 // ǰһ +#define TARGET_SIDE_1_F_ROW 24 // ǰһ +#define TARGET_SIDE_1_B_ROW 23 // һ + +// won add +#define TARGER_THROUGH 27 + +#endif + +extern int gItemCrushRate; // ç ɻ +extern BATTLE *BattleArray; /* */ +extern int BATTLE_battlenum; /* */ +extern char szAllBattleString[BATTLE_STRING_MAX]; /* Ѩ ٯ */ +extern char *pszBattleTop, *pszBattleLast; /* ٯ */ +extern char szBadStatusString[]; // ٯ +extern int gWeponType; // ػ տ +extern float gDamageDiv; // ĸ + +BOOL BATTLE_CHECKINDEX( int battleindex ); +#define BATTLE_CHECKSIDE( a ) ( ((a)>=2 || (a)<0)?(FALSE):( TRUE) ) +#define BATTLE_CHECKNO( a ) ( ((a)>=20 || (a)<0 )?(FALSE):(TRUE) ) +#define BATTLE_CHECKADDRESS( a ) ((&BattleArray[0])<=(a) && (a)<=(&BattleArray[BATTLE_battlenum-1] )?(TRUE):(FALSE) ) + +#define IsBATTLING( a ) (CHAR_getWorkInt((a),CHAR_WORKBATTLEMODE)?(TRUE):(FALSE)) + +#define STRCPY_TAIL( _pszTop, _pszLast, _szBuffer) { int _len = strlen( _szBuffer ); ( _pszTop + _len < (_pszLast)-1 )?( memcpy( _pszTop, _szBuffer, _len ), _pszTop += _len, _pszTop[0] = 0):(0); } + +#define BATTLESTR_ADD(_szBuffer) _BATTLESTR_ADD(_szBuffer,__FILE__,__LINE__) +#define _BATTLESTR_ADD( _szBuffer,file,line ){ /*printf("ļ=%s =%d =%s\n",file,line,_szBuffer);*/int _len = strlen( _szBuffer ); ( pszBattleTop + _len < ( pszBattleLast)-1 )?( memcpy( pszBattleTop, _szBuffer, _len ), pszBattleTop += _len, pszBattleTop[0] = 0):(0); } + +#define BATTLE_MAP_MAX 219 + +#define CH_FIX_PLAYERLEVELUP (+2) // ìﻥʧ +#define CH_FIX_PLAYERDEAD (-2) // ɧ +#define CH_FIX_PLAYEULTIMATE (-4) // ʧ ū +#define CH_FIX_PETESCAPE (-1) // ʸ + +#define AI_FIX_PETLEVELUP (+5*100) // ʸìʧ +#define AI_FIX_PETWIN (+1) // ʸë +#define AI_FIX_PETGOLDWIN (+2*10) // ʸìPгë +#define AI_FIX_PETRECOVERY (+10) // ƻ +#define AI_FIX_PETRESSURECT (+3*100) // ƻ +//#define AI_FIX_PETRECOVERY (+50) // ƻ + +#define AI_FIX_SEKKAN (-2*100) // мʸë +#define AI_FIX_PLAYERULTIMATE (-10*100) // мDZлʧ ū +#define AI_FIX_PETULTIMATE (-10*100) // ʸʧ ū +#define AI_FIX_PLAYERDEAD (-1*100) // мDZл +#define AI_FIX_PETDEAD (-5*100) // ʸ + + +#ifdef _Item_ReLifeAct +int BATTLE_getBattleDieIndex( int battleindex, int bid ); +#endif +int BATTLE_AddProfit( int battleindex, int *pBidList); +int BATTLE_No2Index( int battleindex, int No); + +int BATTLE_Index2No( int battleindex, int charaindex); + +BOOL BATTLE_initBattleArray( int battlenum); + +int BATTLE_CreateBattle( void ); +int BATTLE_DeleteBattle( int battleindex); + +int BATTLE_NewEntry( int charaindex, int battleindex, int side); + +#define BATTLE_Exit( charaindex, battleindex) _BATTLE_Exit( __FILE__, __LINE__, charaindex, battleindex) +INLINE int _BATTLE_Exit( char *file, int line, int charaindex ,int battleindex); + +#define BATTLE_ExitAll( battleindex) _BATTLE_ExitAll( __FILE__, __LINE__, battleindex) +INLINE void _BATTLE_ExitAll( char *file, int line, int battleindex); + +int BATTLE_CreateVsPlayer( int charaindex0, int charaindex1); + +int BATTLE_CreateVsEnemy( int charaindex, int mode, int npcindex); +int BATTLE_CreateVsEnemyLvNew( int charaindex, int npcindex, int *table, int *lvtable ); +int BATTLE_CreateVsEnemyNew( int charaindex, int npcindex, int *enemytable ); + +int BATTLE_CountEntry( int battleindex, int side); + +int BATTLE_Loop( void ); + +int BATTLE_FinishSet( int battleindex ); +int BATTLE_StopSet( int battleindex ); +int BATTLE_RescueEntry( int charaindex, int toindex); + +int BATTLE_PetDefaultExit( int charaindex, int battleindex); + +int BATTLE_PetDefaultEntry( + int charaindex, // ʸë Ȼ + int battleindex,// ̼͵ + int side +); + +BOOL BATTLE_RescueTry( int charaindex); + +BOOL BATTLE_RescueParentTry( + int charaindex, + int pindex + ); + +int BATTLE_DefaultAttacker( int battleindex, int side); + +BOOL BATTLE_IsThrowWepon( int itemindex); + +void BATTLE_BadStatusString( int defNo, int status ); +int BATTLE_MultiList( int battleindex, int toNo, int ToList[] ); +BOOL BATTLE_IsCharge( int com ); +BOOL BATTLE_CanMoveCheck( int charaindex ); +int BATTLE_TargetCheck( int battleindex, int defNo); +char *BATTLE_CharTitle( int charaindex ); +void BATTLE_EscapeDpSend( int battleindex, int charaindex ); +int BATTLE_GetDuelPoint( int battleindex, int side, int num); +int BATTLE_TargetCheckDead( int battleindex, int defNo); + +void BATTLE_MultiListDead( int battleindex, int toNo, int ToList[] ); +BOOL BATTLE_WatchTry( int charaindex); +int BATTLE_WatchEntry( int charaindex, int toindex); +void BATTLE_WatchStop( int charaindex ); +int BATTLE_WatchUnLink( int battleindex ); +void BATTLE_BpSendToWatch( BATTLE *pBattle, char *pszBcString); + +int BATTLE_GetWepon( int charaindex ); + +#ifdef _ITEM_EQUITSPACE +int BATTLE_GetEqShield( int charaindex ); +#endif + +int BATTLE_GetAttackCount( int charaindex ); +int DoujyouRandomWeponSet( int charaindex ); +void BATTLE_AttReverse( int charaindex ); +void BATTLE_BadStatusAllClr( int charaindex ); +#define CHAR_GETWORKINT_HIGH( index, pos ) ( CHAR_getWorkInt( (index), (pos) ) >> 16 ) +#define CHAR_SETWORKINT_HIGH( index, pos, set ) { int iTmp = CHAR_getWorkInt( (index), (pos) ) & 0xFFFF, work = (set); CHAR_setWorkInt( (index), (pos), (work << 16)|iTmp ); } +#define CHAR_GETWORKINT_LOW( index, pos ) ( CHAR_getWorkInt( (index), (pos) ) & 0xFFFF ) +#define CHAR_SETWORKINT_LOW( index, pos, set ) { int iTmp = CHAR_getWorkInt( index, pos ) & 0xFFFF0000, work = (set); CHAR_setWorkInt( (index), (pos), (work & 0x0000FFFF) | iTmp ); } + +int Battle_getTotalBattleNum(); + +#ifdef _TYPE_TOXICATION +void CHAR_ComToxicationHp( int charaindex); +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +void BATTLE_ProfessionStatus_init( int battleindex, int charaindex ); +void BATTLE_ProfessionStatusSeq( int battleindex, int charaindex); +#endif +#ifdef _TRADE_PK +int BATTLE_CreateVsPlayerForTrade( STradeList TradeList1, STradeList TradeList2 ); +#endif + +#ifdef _ALLBLUES_LUA_1_4 +INLINE BOOL BATTLE_setLUAFunction( int battleindex, int functype, lua_State *L, const char *luafunctable); +INLINE lua_State *BATTLE_getLUAFunction( int battle, int functype); +#endif +#ifdef _PETSKILL_NEW_PASSIVE + void BATTLE_PassiveSkill(int charaindex); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_ai.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_ai.h new file mode 100644 index 0000000..a7fc394 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_ai.h @@ -0,0 +1,10 @@ +#ifndef __BATTLE_AI_H__ +#define __BATTLE_AI_H__ + +/* Ի */ +int BATTLE_ai_all( int battleindex, int side, int turn); +int BATTLE_ai_one( int charaindex, int battleindex, int side, int turn); +#ifdef _ENEMY_ATTACK_AI +int GetSubdueAtt(int index); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_command.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_command.h new file mode 100644 index 0000000..ae81f2e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_command.h @@ -0,0 +1,30 @@ +#ifndef __BATTLE_COMMAND_H__ +#define __BATTLE_COMMAND_H__ + +void BattleCommandDispach( + int fd, + char *command +); + +void BattleEncountOut( + int charaindex +); + + +#define BATTLE_CommandSend( charaindex, pszCommand) _BATTLE_CommandSend( charaindex, pszCommand,__FILE__, __LINE__) +BOOL _BATTLE_CommandSend( int charaindex, char *pszCommand,char *file ,int line ); + +BOOL BATTLE_MakeCharaString( + int battleindex, + char *pszCommand, // ƽҷ + int size // +); + +void BATTLE_CharSendAll( int battleindex ); +void BATTLE_CharSendOne( int battleindex,int mycharaindex ); + +BOOL BATTLE_PetDefaultCommand( int petindex ); + +void BATTLE_ActSettingSend( int battleindex ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_event.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_event.h new file mode 100644 index 0000000..c037b45 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_event.h @@ -0,0 +1,398 @@ +#ifndef __BATTLE_EVENT_H__ +#define __BATTLE_EVENT_H__ + +#define BCC_HIT 'H' +#define BCC_FIRE 'F' + +#define BCF_DEATH (1 << 0) +#define BCF_NORMAL (1 << 1) +#define BCF_KAISHIN (1 << 2) +#define BCF_GUARD (1 << 3) +#define BCF_COUNTER (1 << 4) +#define BCF_DODGE (1 << 5) +#define BCF_ULTIMATE_1 (1 << 6) +#define BCF_ULTIMATE_2 (1 << 7) +#define BCF_GBREAK (1 << 8) +#define BCF_GUARDIAN (1 << 9) +#define BCF_REFRECT (1 << 10) +#define BCF_ABSORB (1 << 11) +#define BCF_VANISH (1 << 12) +#define BCF_CRUSH (1 << 13) +#define BCF_FALL (1 << 14) // +#ifdef _SKILL_TOOTH +#define BCF_TOOTH (1 << 15) //ܳ +#endif +#ifdef _PSKILL_MODIFY +#define BCF_ATTDOUBLE (1 << 16) //ǿ +#endif +#ifdef _SKILL_ROAR +#define BCF_ROAR (1 << 17) //輼:() +#endif + +#ifdef _MAGIC_DEFMAGICATT +#define BCF_DEFMAGICATT (1 << 19) +#endif +#ifdef _MAGIC_SUPERWALL +#define BCF_SUPERWALL (1 << 20) +#endif +#ifdef _PSKILL_MDFYATTACK +#define BCF_MODIFY (1 << 21) +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#define BCF_F_SKILLACT (1 << 22) //ǰͼ +#define BCF_TRAP (1 << 25) // +#define BCF_NO_DAMAGE (1 << 26) //˫ع +#endif +#define BCF_B_SKILLACT (1 << 23) //ͼ + + + +#ifdef _EQUIT_ARRANGE +#define BCF_B_ARRANGE (1 << 24) //ͼ +#endif + +#ifdef _PETSKILL_ACUPUNCTURE +#define BCF_ACUPUNCTURE (1 << 27) +#endif + +#ifdef _PETSKILL_ANTINTER +#define BCF_ANTINTER (1 << 28) +#endif +#ifdef _PETSKILL_EXPLODE +#define BCF_EXPLODE (1 << 29) +#endif + +#ifdef _OTHER_MAGICSTAUTS +#ifdef _MAGICSTAUTS_RESIST +#define MAXSTATUSTYPE 6 +#else +#define MAXSTATUSTYPE 3 +#endif //_MAGICSTAUTS_RESIST +extern char MagicStatus[MAXSTATUSTYPE][36]; +extern int MagicTbl[]; +extern int MagicTypeTbl[]; +#endif + +extern char *aszStatus[]; +extern char *aszStatusFull[]; +extern int StatusTbl[]; +extern int RegTbl[]; +extern int MagicDefTbl[]; +extern char *aszMagicDefFull[]; +extern char *aszMagicDef[]; + +extern char *aszParamChange[]; +extern char *aszParamChangeFull[]; +extern int aParamChangeTbl[]; + +extern float gBattleDamageModyfy; +extern int gBattleDuckModyfy; +extern int gBattleStausChange; +extern int gBattleStausTurn; + +enum{ + BATTLE_ST_NONE, // 0 "", + BATTLE_ST_POISON, // 1 "", + BATTLE_ST_PARALYSIS, // 2 "", + BATTLE_ST_SLEEP, // 3 "", + BATTLE_ST_STONE, // 4 "ʯ", + BATTLE_ST_DRUNK, // 5 "", + BATTLE_ST_CONFUSION, // 6 "", + BATTLE_ST_WEAKEN, // 7 "" + BATTLE_ST_DEEPPOISON,// 8 "綾" + BATTLE_ST_BARRIER, // 9 "ħ" + BATTLE_ST_NOCAST, // 10 "Ĭ" +#ifdef _PET_SKILL_SARS // WON ADD ɷ + BATTLE_ST_SARS, // 11 "ɷ" +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + BATTLE_ST_DIZZY, // 12 "" + BATTLE_ST_ENTWINE, // 13 "" + BATTLE_ST_DRAGNET, // 14 "޵" + BATTLE_ST_ICECRACK, // 15 "" + BATTLE_ST_OBLIVION, // 16 "" + BATTLE_ST_ICEARROW, // 17 "" + BATTLE_ST_BLOODWORMS,// 18 "Ѫ" + BATTLE_ST_SIGN, // 19 "һѪ" + BATTLE_ST_INSTIGATE, // 20 "" + BATTLE_ST_F_ENCLOSE, // 21 "" + BATTLE_ST_I_ENCLOSE, // 22 "" + BATTLE_ST_T_ENCLOSE, // 23 "׸" + BATTLE_ST_FOCUS, // 24 "רעս" + BATTLE_ST_RESIST_F, // 25 "" + BATTLE_ST_RESIST_I, // 26 "" + BATTLE_ST_RESIST_T, // 27 "׿" + BATTLE_ST_F_ENCLOSE2, // 28 "" + BATTLE_ST_I_ENCLOSE2, // 29 "" + BATTLE_ST_T_ENCLOSE2, // 30 "׸" +#ifdef _PROFESSION_ADDSKILL + BATTLE_ST_RESIST_F_I_T, //31 "׿" + //BATTLE_ST_BOUNDARY_F, //32 " + BATTLE_ST_WATER, //32 "ˮ" + BATTLE_ST_WORKANNEX, //33 "" + BATTLE_ST_FEAR, //34 "־" + BATTLE_ST_ICECRACK2, // 35 "" + BATTLE_ST_ICECRACK3, // 36 + BATTLE_ST_ICECRACK4, // 37 + BATTLE_ST_ICECRACK5, // 38 + BATTLE_ST_ICECRACK6, // 39 + BATTLE_ST_ICECRACK7, // 40 + BATTLE_ST_ICECRACK8, // 41 + BATTLE_ST_ICECRACK9, // 42 + BATTLE_ST_ICECRACK10, // 43 +#endif + +#endif + + BATTLE_ST_END +}; + +#ifdef _OTHER_MAGICSTAUTS +enum{ + BATTLE_MST_NONE, + BATTLE_MST_DEFMAGIC, + BATTLE_MST_SUPERWALL, +#ifdef _MAGICSTAUTS_RESIST + BATTLE_MST_MAGICFIRE, + BATTLE_MST_MAGICTHUNDER, + BATTLE_MST_MAGICICE, +#endif + BATTLE_MST_END +}; +#endif + +enum{ + BATTLE_MD_NONE, + BATTLE_MD_ABSROB, + BATTLE_MD_REFLEC, + BATTLE_MD_VANISH, + BATTLE_MD_TRAP, +#ifdef _PETSKILL_ACUPUNCTURE + BATTLE_MD_ACUPUNCTURE, //Ƥ +#endif + BATTLE_MD_END +}; + +#ifdef _PETSKILL_RETRACE + //BATTLE_AttackʽִĹģʽ +typedef struct tagBattle_Attack_ReturnData_x1 +{ + int Battle_Attack_ReturnData; +}Battle_Attack_ReturnData_x1; +Battle_Attack_ReturnData_x1 Battle_Attack_ReturnData_x; + +#endif + +int BATTLE_DamageCalc( int attackindex, int defindex ); + +BOOL BATTLE_Attack( int battleindex, int attackNo, int defNo ); + +BOOL BATTLE_Counter( int battleindex, int attackNo, int defNo ); + +BOOL BATTLE_Capture( int battleindex, int attackNo, int defNo ); + +void BATTLE_Guard( int battleindex, int attackNo ); + +// Nuke 20040112 fix for performance +#define BATTLE_BroadCast(A,B,C) 0 +#define BATTLE_BroadCastOn(A,B,C) 0 +//int BATTLE_BroadCast( int battleindex, char *pszBuffer, int color ); +//int BATTLE_BroadCastOn( int battleindex, char *pszBuffer, int color ); + +BOOL BATTLE_Escape( int battleindex, int attackNo, int flag); + +int BATTLE_NoAction( int battleindex, int attackNo ); + +int BATTLE_PetIn( int battleindex, int attackNo ); + +int BATTLE_PetOut( int battleindex, int attackNo ); + +int BATTLE_SurpriseCheck( int battleindex ); + +int BATTLE_Magic( int battleindex, int attackNo ); + +int BATTLE_S_GBreak( int battleindex, int attackNo, int defNo ); + +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 +int BATTLE_S_GBreak2( int battleindex, int attackNo, int defNo ); +#endif + +#ifdef _SKILL_SACRIFICE +int BATTLE_S_Sacrifice( int battleindex, int attackNo, int defNo ); +#endif + +#ifdef _SKILL_REFRESH +int BATTLE_S_Refresh( int battleindex, int attackNo, int defNo, int marray ); +#endif + +#ifdef _SKILL_WEAKEN //vincent輼: +int BATTLE_S_Weaken( int battleindex, int attackNo, int defNo, int marray ); +#endif + +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 +int BATTLE_S_Deeppoison( int battleindex, int attackNo, int defNo, int marray ); +#endif + +#ifdef _SKILL_BARRIER //vincent輼:ħ +int BATTLE_S_Barrier( int battleindex, int attackNo, int defNo, int marray ); +#endif + +#ifdef _SKILL_NOCAST //vincent輼:Ĭ +int BATTLE_S_Nocast( int battleindex, int attackNo, int defNo, int marray ); +#endif + +#ifdef _SKILL_ROAR //vincent輼: +int BATTLE_S_Roar( int battleindex, int attackNo, int defNo, int marray ); +#endif + +int BATTLE_Charge( int battleindex, int attackNo ); + + +int BATTLE_StatusAttackCheck( + + int attackindex, + int defindex, + int status, + //BATTLE_ST_POISON, 1 "", + //BATTLE_ST_PARALYSIS, 2 "", + //BATTLE_ST_SLEEP, 3 "", + //BATTLE_ST_STONE, 4 "ʯ", + //BATTLE_ST_DRUNK, 5 "", + //BATTLE_ST_CONFUSION, 6 "" + int PerOffset, + int Range, + float Bai, + int *pPer +); + +int BATTLE_Combo( int battleindex, int *pAttackList, int defNo ); + +int BATTLE_EarthRoundHide( int battleindex, int attackNo ); + +int BATTLE_GetDamageReact( int charaindex ); + +void BATTLE_talkToCli( int charaindex, char *pszBuffer, int color ); + +#ifdef _PETSKILL_SETDUCK +BOOL BATTLE_CheckMySkillDuck( int charaindex ); +#endif + +BOOL BATTLE_LostEscape( int battleindex, int attackNo ); + +BOOL BATTLE_Abduct( int battleindex, int attackNo, int defNo, int array ); + +void BATTLE_Steal( int battleindex, int attackNo, int defNo ); + +int BATTLE_getReactFlg( int index, int react); + +#ifdef _BATTLESTEAL_FIX +void BATTLE_StealMoney( int battleindex, int attackNo, int defNo) ; +#endif +#ifdef _PETOUT_PETSKILL +int BATTLE_S_PetOut( int battleindex, int attackNo, int petNo ); +#endif + +#ifdef _PETSKILL_LER +void BATTLE_BatFly(int battleindex,int attackNo,int myside); +void BATTLE_DivideAttack(int battleindex,int attackNo,int myside); +void BATTLE_LerChange(int battleindex,int charaindex,int no); +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +void BATTLE_BattleModel(int battleindex,int attackNo,int myside); +#endif + +// Robin 0727 Ride Pet +#define ATTACKSIDE 1 +#define DEFFENCESIDE 2 + +float BATTLE_adjustRidePet3A( int charaindex, int petindex, int workindex, int action ); + +int BATTLE_getRidePet( int charaindex ); + +#ifdef _PSKILL_FALLGROUND // +int BATTLE_S_FallGround( int battleindex, int attackNo, int defNo, int skill_type ); +#endif +#ifdef _PETSKILL_EXPLODE +int BATTLE_S_Explode( int battleindex, int attackNo, int defNo, int skill_type ); +#endif + +#ifdef _PETSKILL_PROPERTY +int BATTLE_S_PetSkillProperty( int battleindex, int attackNo, int skill_type, int skill); +#endif + +int BATTLE_S_AttackDamage( int battleindex, int attackNo, int defNo, int skill_type, int skill); + +#ifdef _MAGIC_SUPERWALL +int PETSKILL_MagicStatusChange_Battle( int battleindex, int attackNo, int toNo, int marray); +#endif + +#ifdef _PETSKILL_SETDUCK +int PETSKILL_SetDuckChange_Battle( int battleindex, int attackNo, int toNo, int marray); +#endif + +#ifdef _MAGICPET_SKILL +int PETSKILL_SetMagicPet_Battle( int battleindex, int attackNo, int toNo, int marray); +#endif + +#ifdef _TAKE_ITEMDAMAGE +int BATTLE_ItemCrushCheck( int charaindex , int flg); +int BATTLE_ItemCrush( int charaindex, int ItemEquip, int Damages, int flg); +#endif + +#ifdef _PRO_BATTLEENEMYSKILL +int BATTLE_E_ENEMYREFILE( int battleindex, int attackNo, int defNo, int skill_type ); + +int BATTLE_E_ENEMYREHP( int battleindex, int attackNo, int defNo, int skill_type ); + +int BATTLE_E_ENEMYHELP( int battleindex, int attackNo, int defNo, int skill_type ); +#endif + + +#ifdef _PREVENT_TEAMATTACK +int BATTLE_CheckSameSide( int charaindex, int toNo); +#endif + +#ifdef _USER_CHARLOOPS +int CHAR_BattleStayLoop( int charaindex);//ԭ +#endif + +#ifdef _PETSKILL_PROPERTY +int PET_PetskillPropertyEvent( int Myindex, int defindex, int *damage, int *T_Pow, int size); +#endif + +#ifdef _STRENGTH_PETSKILL +int PETSKILL_SetStrength_Battle( int battleindex, int attackNo, int toNo, int marray); +#endif +#ifdef _OFFLINE_SYSTEM +int OFFLINE_MultiRessurect( int battleindex, int attackNo, int toNo, int HP, int flg); +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +int battle_profession_attack_fun(int battleindex, int attackNo, int defNo, int charaindex); +int battle_profession_attack_magic_fun(int battleindex, int attackNo, int defNo, int charaindex); +int battle_profession_assist_fun(int battleindex, int attackNo, int defNo, int charaindex); +int battle_profession_status_chang_fun(int battleindex, int attackNo, int defNo, int charaindex); +int BATTLE_check_profession_duck( int charaindex, int per ); +int BATTLE_PROFESSION_ATK_PET_DamageSub( int attackindex, int defindex, int *pDamage, int *pPetDamage, int *pRefrect, int skill_level ); +int PROFESSION_BATTLE_StatusAttackCheck( int charaindex, int toindex, int status, int Success ); +int BATTLE_PROFESSION_CONVOLUTE_GET_DAMAGE( int attackindex, int defindex, int skill_level ); +int BATTLE_PROFESSION_THROUGH_ATTACK_GET_DAMAGE( int attackindex, int defindex ); +int BATTLE_PROFESSION_RANG_ATTACK_DAMAGE( int charaindex, int attackNo, int defNo, int skill_type, int status, int turn, int perStatus, int effect, int img1, int img2 ); + +#endif + +#ifdef _PETSKILL_FIREKILL //ɱר +int BATTLE_Attack_FIREKILL( int battleindex, int attackNo, int defNo ); +#endif +#ifdef _PROFESSION_ADDSKILL +BOOL BATTLE_BattleUltimate( int battleindex, int bid ); //λDǷ񱻴 +#endif + + + +#ifdef _NEED_ITEM_ENEMY +int need_item_eneny_init(); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_item.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_item.h new file mode 100644 index 0000000..483fa73 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_item.h @@ -0,0 +1,36 @@ +#ifndef _BATTLE_ITEM_H_ +#define _BATTLE_ITEM_H_ +//-------------------------------------------------------------- +// ʧ ةë +//-------------------------------------------------------------- +// +void ITEM_useRecovery_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useStatusChange_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useMagicDef_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useParamChange_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useFieldChange_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useAttReverse_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useStatusRecovery_Battle( int charaindex, int toindex, int itemindex ); +void ITEM_useCaptureUp_Battle( int charaindex, int toindex, int itemindex ); +#ifdef _ITEM_CRACKER +void ITEM_useCracker_Effect( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_ADDEXP //vincent +void ITEM_useAddexp_Effect( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_REFRESH //vincent 쳣״̬ +void ITEM_useRefresh_Effect( int charaindex, int toindex, int haveitemindex); +#endif +//Terry add 2001/12/24 +#ifdef _ITEM_FIRECRACKER +void ITEM_useFirecracker_Battle(int charaindex,int toindex,int itemindex); +#endif +//Terry end + +#ifdef _ITEM_MAGICRECOVERY +void ITEM_useMRecovery_Battle( int charaindex, int toNo, int haveitemindex ); +#endif +#ifdef _ITEM_USEMAGIC +void ITEM_useMagic_Battle( int charaindex, int toNo, int haveitemindex ); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_magic.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_magic.h new file mode 100644 index 0000000..0483a25 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/battle_magic.h @@ -0,0 +1,336 @@ +#ifndef _BATTLE_MAGIC_H_ +#define _BATTLE_MAGIC_H_ + +#define MAGIC_EFFECT_USER 100600 +#define SPR_heal 100601 +#define SPR_heal2 100602 +#define SPR_heal3 100603 +#define SPR_tyusya 100604 +#define SPR_hoshi 100605 + + +#define MAGIC_ID_RECOVERY 1 +#define MAGIC_ID_STATUS_RECOVERY 3 +#define MAGIC_ID_FIELD_CHANGE 4 +#define MAGIC_ID_BADSTATUS 5 + +enum{ + BFUKI_CAPTUREUP, + BFUKI_END +}; + + +enum{ + PC_KIND_NONE, + PC_KIND_ATTACK, + PC_KIND_DEFENSE, + PC_KIND_QUICK, + PC_KIND_CHARM, + PC_KIND_CAPTURE, + PC_KIND_END +}; + +int MAGIC_Recovery_Battle( + int charaindex, + int toindex, + int magicindex, + int mp +); + +int MAGIC_FieldAttChange_Battle( + int charaindex, + int toindex, + int marray, + int mp +); + +int MAGIC_StatusChange_Battle( + int charaindex, + int toindex, + int marray, + int mp +); + +#ifdef _MAGIC_DEEPPOISON +int MAGIC_StatusChange_Battle2( + int charaindex, + int toindex, + int marray, + int mp +); +#endif + +#ifdef _OTHER_MAGICSTAUTS +int MAGIC_MagicStatusChange_Battle( int charaindex, int toNo, int marray, int mp ); + +#endif + +int MAGIC_MagicDef_Battle( + int charaindex, + int toNo, + int marray, + int mp +); + +void BATTLE_MultiRecovery( + int battleindex, + int attackNo, + int toNo, + int kind, + int power, + int per, + int UseEffect, + int RecevEffect + +); + +#ifdef _IMPRECATE_ITEM +void BATTLE_ImprecateRecovery( + int battleindex, + int attackNo, + int toNo, + int kind, + int powers, + int rounds, + int UseEffect, + int RecevEffect +); +#endif +void BATTLE_MultiStatusChange( + int battleindex, + int attackNo, + int toNo, + int status, + int turn, + int UseEffect, + int RecevEffect, + int Success +); + +#ifdef _OTHER_MAGICSTAUTS +void BATTLE_MultiMagicStatusChange( + int battleindex, + int attackNo, + int toNo, + int status, + int turn, + int UseEffect, + int RecevEffect, + int nums +); +#endif + +void BATTLE_MultiMagicDef( + int battleindex, + int attackNo, + int toNo, + int kind, + int count, + int UseEffect, + int RecevEffect +); + +void BATTLE_MultiParamChange( + int battleindex, + int attackNo, + int toNo, + int kind, + int power, + int par, + int UseEffect, + int RecevEffect +); + +int MAGIC_FieldAttChange_Battle( + int charaindex, + int toNo, + int marray, + int mp +); + +int BATTLE_FieldAttChange( + int charaindex, + char *pArg +); + +void BATTLE_MultiAttReverse( + int battleindex, + int attackNo, + int toNo, + int UseEffect, + int RecevEffect +); + + +void BATTLE_MultiStatusRecovery( + int battleindex, + int attackNo, + int toNo, + int status, + int UseEffect, + int RecevEffect +); + +int MAGIC_StatusRecovery_Battle( + int charaindex, + int toNo, + int marray, + int mp +); + +void BATTLE_MultiRessurect( + int battleindex, + int attackNo, + int toNo, + int power, + int per, + int UseEffect, + int RecevEffect +); + +void BATTLE_MultiCaptureUp( + int battleindex, + int attackNo, + int toNo, + int power, + int UseEffect, + int RecevEffect +); +// +//*********************************************************** + +//**************************************************************** +// +// 姾 +// +int MAGIC_Ressurect_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +); +// TRUE +// FALSE +//**************************************************************** + +//**************************************************************** +// +// 뼰 ë +// +int MAGIC_AttReverse_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +); +// TRUE +// FALSE +//**************************************************************** +//**************************************************************** +// +// +// +int MAGIC_CaptureUp_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +); +// TRUE +// FALSE +//**************************************************************** + +//*********************************************************** +// +// ܷƥ Ѽƽҷëٽ½ձ ܷ ëܰ +// +void BATTLE_MultiResAndDef( + int battleindex, // ̼͵ + int attackNo, // į + int toNo, // ľ į + int power, // + int per, // Ѿ + int kind, // ܷ + int count, // ϼ ʲ + int UseEffect, // мް + int RecevEffect // ľмް +); +// +//*********************************************************** +//**************************************************************** +// +// ١ ܷ ëܸ +// +int MAGIC_ResAndDef_Battle( + int charaindex, // м̼͵ + int toNo, // ľм̼͵ + int marray, // magicindex + int mp // MP +); +// TRUE +// FALSE +//**************************************************************** + +#ifdef _ATTACK_MAGIC +int MAGIC_AttMagic_Battle( int charaindex , int toNo , int marray , int mp ); +#ifdef _FIX_MAGICDAMAGE +void BATTLE_MultiAttMagic( int battleindex, int attackNo, int toNo, + int attIdx ,int FieldAttr ,int Power, int MagicLv); + +#else +void BATTLE_MultiAttMagic( int battleindex , int attackNo , int toNo , int attIdx , int FieldAttr , int Power ); +#endif +int MAGIC_AttMagic_Battle( int charaindex , int toNo , int marray , int mp ); + +#endif + + + +#ifdef _MAGIC_TOCALL +int MAGIC_ToCallDragon_Battle( int charaindex , int toNo , int marray , int mp ); + +void BATTLE_MultiToCallDragonMagic( int battleindex, int attackNo, int toNo, + int attIdx ,int FieldAttr ,int Power, int ImageNo); + +#endif + +#ifdef _Item_ReLifeAct +void BATTLE_MultiReLife( int battleindex, int attackNo, int toNo, int power, int RecevEffect ); +#endif +#ifdef _MAGIC_WEAKEN +int MAGIC_ParamChange_Turn_Battle(int charaindex,int toNo,int marray,int mp); +void BATTLE_MultiParamChangeTurn( int battleindex,int attackNo,int toNo,int status,int UseEffect,int RecevEffect,int turn, int Success); +#endif +int BATTLE_MagicEffect( int battleindex,int attackNo,int ToList[],int MyEffect,int ToEffect ); + + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +void PROFESSION_MAGIC_ATTAIC( int battleindex, int attackNo, int toNo, int attIdx, int FieldAttr, int skill); +int PROFESSION_MAGIC_ATTAIC_Effect( int battleindex, int attackNo, int ToList[], int AttackMgcNo ); +int analysis_profession_parameter( int attIdx, int skill, int toNo, int charaindex ); +void PROFESSION_MAGIC_GET_PRACTICE( float *hp_power, float *mp_power, float *dec_hp, float *dec_mp, int charaindex ); +void PROFESSION_MAGIC_TOLIST_SORT( int *list, int *listidx, int charaindex ); +void PROFESSION_MAGIC_CHANGE_STATUS( int charaindex, int hp_power, float mp_power, float *add_hp, float *add_mp ); +void PROFESSION_MAGIC_GET_IMG2( int toNo, int charaindex, int attIdx, char *pszOption ); +#ifdef _PROFESSION_ADDSKILL +int PROFESSION_MAGIC_GET_DAMAGE( int attackindex, int defindex, int magic_type, int power, int command ); +#else +int PROFESSION_MAGIC_GET_DAMAGE( int attackindex, int defindex, int magic_type, int power ); +#endif +int PROFESSION_MAGIC_DODGE( int atk_index, int def_index, int magic_type ); +void PROFESSION_MAGIC_CHANG_IMG2( int img2, char *pszOption, int attIdx ); +int PROFESSION_MAGIC_CHANG_STATUS(int command,int battleindex, int charaindex, int charaidx, int power, int no); +int PROFESSION_MAGIC_GET_ICE_MIRROR_DAMAGE( int attackindex, int defindex, int command, int power ); +#endif + +#ifdef _PETSKILL_FIREKILL +void BATTLE_MultiAttMagic_Fire( int battleindex, int attackNo, int defNo, + int FieldAttr , int Power); +#endif + +#ifdef _PROFESSION_ADDSKILL +unsigned int GET_PROFESSION_magic_uiSpriteNum(int idx); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/buf.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/buf.h new file mode 100644 index 0000000..78665f0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/buf.h @@ -0,0 +1,11 @@ +#ifndef __BUF_H__ +#define __BUF_H__ + +#include "common.h" +void memEnd( void ); +BOOL configmem( int unit , int unitnumber ); +BOOL memInit( void ); +void* allocateMemory( const unsigned int nbyte ); +void freeMemory( void* freepointer ); +void showMem( char *buf); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/char.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char.h new file mode 100644 index 0000000..182862b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char.h @@ -0,0 +1,800 @@ +#ifndef __CHAR_H__ +#define __CHAR_H__ + +#include "common.h" +#include "char_base.h" +#include "net.h" +#include "char_data.h" + +/*------------------------------------------------------------ + *ɼƼ + *------------------------------------------------------------*/ +#ifdef _NEW_STREET_VENDOR +typedef enum +{ + STREET_VENDOR_GOLD, + STREET_VENDOR_FAME, +#ifndef _VERSION_NEW + STREET_VENDOR_AMPOINT, +#endif +/* +#ifdef _NEW_MANOR_LAW + STREET_VENDOR_MOMENTUM, +#endif + + STREET_VENDOR_DP, +#ifdef _CAMEO_MONEY + STREET_VENDOR_CAMEO, +#endif +*/ +#ifdef _ACTIVE_GAME + STREET_VENDOR_ACTIVE, +#endif +#ifdef _STREET_VENDOR_MYSQL + STREET_VENDOR_MYSQL, +#endif + STREET_VENDOR_NUM, +}STREET_VENDOR; +#endif + +typedef enum +{ + CHAR_COLORWHITE, + CHAR_COLORCYAN, + CHAR_COLORPURPLE, + CHAR_COLORBLUE, + CHAR_COLORYELLOW, + CHAR_COLORGREEN, + CHAR_COLORRED, + CHAR_COLORGRAY, + CHAR_COLORBLUE2, + CHAR_COLORGREEN2, + CHAR_COLORNUM +}CHAR_COLOR; +/*====================ƽҷ¼====================*/ +void CHAR_createNewChar( int clifd, int dataplacenum,char* charname , + int imgno,int faceimgno, + int vital,int str,int tgh,int dex, + int earth,int water,int fire,int wind, + int hometown , char *cdkey ); + +/*====================ƽҷ¼̼====================*/ + +void CHAR_login( int clifd, char* data, int saveindex ); + +#define CHAR_warpToSpecificPoint( cindex, fl, x, y) _CHAR_warpToSpecificPoint( __FILE__, __LINE__, cindex, fl, x, y) +BOOL _CHAR_warpToSpecificPoint( char *file, int line, + int charaindex, int fl, int x, int y); + + +/*====================ƽҷ¼Ƥ====================*/ +/*====================ƽҷ¼ʧ====================*/ +BOOL CHAR_charSaveFromConnectAndChar( int fd,Char* ch, int unlock ); +BOOL CHAR_charSaveFromConnect( int charaindex,int unlock ); +#define CHAR_logout( charaindex, save) _CHAR_logout( __FILE__, __LINE__, charaindex, save) +BOOL _CHAR_logout( char *file, int line, int charaindex, BOOL save); + +/*====================watch event ====================*/ +void CHAR_sendWatchEvent( int objindex, int chac, int* opt,int optlen,BOOL myflg ); + +/*====================ƽ====================*/ +BOOL CHAR_Skillupsend(int charaindex ); +void CHAR_SkillUp( int charaindex, int skillid ); +void CHAR_useSkill( int charaindex, int dir ,int skindex ); + +typedef enum +{ + CHAR_WALKSUCCESSED, /* */ + CHAR_WALKSYSTEMERROR, /* ˵ ة޷¡ indexͱ + * Ⱦ羮 */ + CHAR_WALKEXTEND, /* ƻڳףNPC弰*/ + CHAR_WALKHITOBJECT, /* Ͼ Ȼئ */ + CHAR_WALKPREWALK, /* prewalkìƥئ( ޼ ) */ + CHAR_WALKDIE, /* ƥлئ */ + CHAR_WALK1357, /* 껧 ڳƻئ */ +}CHAR_WALKRET; + +/*====================ƽҷ¼ ====================*/ +void CHAR_ctodirmode(char moji , int* dir , int* mode); +INLINE void CHAR_getDXDY( int dir , int* dx, int* dy ); +INLINE int CHAR_getDX( int dir ); +INLINE int CHAR_getDY( int dir ); +int CHAR_getSameCoordinateObjects(int* objbuf, int siz,int ff, int fx, int fy); +void CHAR_walkcall( int index ); +void CHAR_walk_start(int index, int x, int y, char* dir, BOOL mapsendmode); +void CHAR_walk_init( int fd, int x, int y, char *direction, BOOL mapsendmode); + +CHAR_WALKRET CHAR_walk(int index, int dir, int mode); +#ifdef _MO_LNS_NLGSUOXU +CHAR_WALKRET CHAR_walk_jjc( int index, int floor, int ox, int oy, int dir); +CHAR_WALKRET CHAR_walk_jc( int charaindex, int of, int ox, int oy, int dir );//ǰϰ +#endif +char* CHAR_makeOptionString( Char* ch ); +char* CHAR_makeStatusString( int index, char* category ); +void CHAR_LoginBesideSetWorkInt( int charaindex, int clifd); +#define CHAR_makeObjectCString( objindex, buf, buflen) _CHAR_makeObjectCString( __FILE__, __LINE__, objindex, buf, buflen) +BOOL _CHAR_makeObjectCString( char *file, int line, int objindex, char* buf, int buflen ); + +#ifdef _NPC_EVENT_NOTICE +#define CHAR_makeObjectCStringNew( objindex, playerindex, buf, buflen) _CHAR_makeObjectCStringNew( __FILE__, __LINE__, objindex, playerindex, buf, buflen) +BOOL _CHAR_makeObjectCStringNew( char *file, int line, int objindex, int playerindex, char* buf, int buflen ); +#endif + +//BOOL CHAR_sendStatusString( int charaindex, char* category ); +#define CHAR_sendStatusString( A, B) _CHAR_sendStatusString( A, B, __FILE__, __LINE__ ) +BOOL _CHAR_sendStatusString( int charaindex, char* category, char* file, int line ); +BOOL CHAR_sendItemData( int charaindex, int *itemgroup, int num); +BOOL CHAR_sendItemDataOne( int charaindex, int haveitemindex); +BOOL CHAR_send_P_StatusString( int charaindex, unsigned int indextable ); +BOOL CHAR_send_N_StatusString( int charaindex, int num, unsigned int indextable ); +BOOL CHAR_send_K_StatusString( int charaindex, int num, unsigned int indextable ); + +void CHAR_inputOwnTitle( int index ,char* name ); + +void CHAR_selectTitle( int index, int titleindex ); +void CHAR_deleteTitle( int index, int titleindex ); + +#define CHAR_complianceParameter( index) _CHAR_complianceParameter( index, __FILE__, __LINE__) +int _CHAR_complianceParameter( int index, char *FILE, int LINE); + +int CHAR_findSurplusItemBox( int index ); +int CHAR_findEmptyItemBox( int index ); +int CHAR_findEmptyPoolItemBox( int index ); +int CHAR_findEmptyItemBoxNo( int index ); + +void CHAR_moveEquipItem( int index, int fromindex, int toindex ); +#ifdef _PET_ITEM +void CHAR_movePetItem( int index, int petid, int fromindex, int toindex ); +void CHAR_sendPetItemData( int charaindex, int petid); +#endif +void CHAR_ItemUse( int charaindex, int to_charaindex, int haveitemindex ); +void CHAR_DropItem( int charaindex, int itemindex ); +int CHAR_DropItemAbsolute( int itemindex, int floor, int x, int y,BOOL net); +BOOL CHAR_DropItemFXY( int charaindex, int itemcharaindex, int fl, + int x, int y, int* objindex ); +int CHAR_addItemSpecificItemIndex( int charaindex, int itemindex ); + +void CHAR_PickUpItem( int charaindex, int dir ); +void CHAR_DropMoney( int charaindex, int amount ); +int CHAR_addItem( int charaindex, int itemid ); +int CHAR_addItemToChar( Char* ch, int itemid ); + +int CHAR_pickupFollowPet( int charaindex, int petindex ); + +#ifdef _GAMBLE_ROULETTE +int NPC_MAPCLEANGOLD( int meindex , int floor); +#endif + +#ifdef _DROPSTAKENEW +#define MAXSTAKENUM 5 +int CasinoAccumulation(int charindex, int npcindex, int floor, int wincasinotype); +void CHAR_talkToFloor(int floor, int talkindex, char* message, CHAR_COLOR color); +int SetCasinoMap(int npcindex, int casinotype, int mapdropflag); +int CasinoPay(int npcindex, int wincasinotype); +#endif +void CHAR_sendCSpecifiedObjindex( int fd, int index); +void CHAR_sendSpecifiedobjindexCToCharaindex(int charaindex,int objindex); + +void CHAR_sendCToArroundCharacter( int charaindex ); + +void CHAR_sendArroundCharaData( int charaindex ); + +void CHAR_sendCDArroundChar( int fl, int x, int y, int objindex ); +void CHAR_sendCDArroundChar_Main( int fl, int x, int y, int objindex, BOOL mode ); + + +void CHAR_Look( int charaindex, int dir ); + +void CHAR_initChatMagic(void); + +char* CHAR_appendNameAndTitle( int charaindex, char* src, char* buf, + int buflen ); +void CHAR_Talk( int fd, int index,char* message,int color, int area ); + +void CHAR_Loop( void ); + +#ifdef _PET_ITEM +void CHAR_sendPetItemData( int charaindex, int petid); +void CHAR_sendPetItemEmpty( int charaindex, int petid); +#endif + +#define WINDOW_BUTTONTYPE_NONE (0) +#define WINDOW_BUTTONTYPE_OK (1 << 0) +#define WINDOW_BUTTONTYPE_CANCEL (1 << 1) +#define WINDOW_BUTTONTYPE_YES (1 << 2) +#define WINDOW_BUTTONTYPE_NO (1 << 3) +#define WINDOW_BUTTONTYPE_PREV (1 << 4) +#define WINDOW_BUTTONTYPE_NEXT (1 << 5) + +#define WINDOW_BUTTONTYPE_OKCANCEL (WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL) +#define WINDOW_BUTTONTYPE_YESNO (WINDOW_BUTTONTYPE_YES | WINDOW_BUTTONTYPE_NO) + + +typedef enum +{ + WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_MESSAGETYPE_SELECT, + WINDOW_MESSAGETYPE_PETSELECT, + WINDOW_MESSAGETYPE_PARTYSELECT, + WINDOW_MESSAGETYPE_PETANDPARTYSELECT, + WINDOW_MESSAGETYPE_ITEMSHOPMENU, + WINDOW_MESSAGETYPE_ITEMSHOPMAIN, + WINDOW_MESSAGETYPE_LIMITITEMSHOPMAIN, + WINDOW_MESSAGETYPE_PETSKILLSHOP, + WINDOW_MESSAGETYPE_WIDEMESSAGE, + WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, + WINDOW_MESSAGETYPE_POOLITEMSHOPMENU, + WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN, + + WINDOW_MESSAGETYPE_FAMILYADD, + WINDOW_MESSAGETYPE_FAMILYJOIN, + WINDOW_MESSAGETYPE_FAMILYOUT, + WINDOW_MESSAGETYPE_FAMILYEND, +//======================================= + // shan add + WINDOW_FMMESSAGETYPE_SELECT, + WINDOW_FMMESSAGETYPE_DENGON, + WINDOW_FMMESSAGETYPE_FMSDENGON, + WINDOW_FMMESSAGETYPE_POINTLIST, +#ifdef _FMVER21 + WINDOW_FMMESSAGETYPE_TOP30DP, +#endif + WINDOW_FMMESSAGETYPE_DP, + WINDOW_MESSAGETYPE_BANK, + + // Arminius 7.12 scheduleman + WINDOW_MESSAGETYPE_PKSCHEDULELIST, + WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + + // Robin + WINDOW_MESSAGETYPE_LOGINMESSAGE, + WINDOW_MESSAGETYPE_FAMILYTAX, + WINDOW_MESSAGETYPE_SHOWRIDEPET, + WINDOW_MESSAGETYPE_FAMILYDETAIL, + + WINDOW_MESSAGETYPE_LEADERSELECT, + WINDOW_MESSAGETYPE_LEADERSELECTQ, + WINDOW_MESSAGETYPE_LEADERSELECTA, + + // Arminius 1.3 Auctioneer + WINDOW_MESSAGETYPE_AUCTIONNEW, + WINDOW_MESSAGETYPE_AUCTIONLIST_BUY, + WINDOW_MESSAGETYPE_AUCTIONSURVEY, + WINDOW_MESSAGETYPE_AUCTIONMODIFY, + WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY, + +//#ifdef _NPC_FUSION + WINDOWS_MESSAGETYPE_PETFUSION, +//#endif + +//#ifdef _PETSKILL_CANNEDFOOD + WINDOWS_MESSAGETYPE_PETSKILLSHOW, +//#endif + +//#ifdef _PROFESSION_SKILL // WON ADD ְҵ + WINDOW_MESSAGETYPE_PROFESSIONSHOP, +//#endif + +//#ifdef _NEW_MANOR_LAW + WINDOW_FMMESSAGETYPE_10_MEMONTUM, // ʮƼ + WINDOW_FMMESSAGETYPE_FM_MEMONTUM, // Լ + WINDOW_FMMESSAGETYPE_MANOR_SCHEDULE, // սׯ԰ +//#endif + +//#ifdef _ANGEL_SUMMON + WINDOW_MESSAGETYPE_ANGELMESSAGE = 101, + WINDOW_MESSAGETYPE_ANGELASK, +//#endif + +//#ifdef _MOUSE_DBL_CLICK + WINDOW_MESSAGETYPE_MOUSEGETNAME, +//#endif + +//#ifdef _RACEMAN + WINDOW_MESSAGETYPE_RACEMAN_RANK, +//#endif + +}WINDOW_MESSAGETYPE; + +typedef enum +{ + CHAR_WINDOWTYPE_RETURNTOELDER=-1, /* Ӯ ū */ + CHAR_WINDOWTYPE_RESURRECTION=-2, /* ū */ + + CHAR_WINDOWTYPE_SELECTBATTLE = 1, /* ¾ ë ū */ + CHAR_WINDOWTYPE_SELECTDUEL = 2, /* DUELë ū */ + CHAR_WINDOWTYPE_SELECTTRADECARD = 3, /* ͭë ū */ + CHAR_WINDOWTYPE_SELECTPARTY = 4, /* ɡ ūë ū */ + CHAR_WINDOWTYPE_SELECTBATTLEWATCH = 5, /* ë ū */ + CHAR_WINDOWTYPE_MICMESSAGE = 6, /* MICNPCëȻū */ + + // CoolFish: Trade 2001/4/18 + CHAR_WINDOWTYPE_SELECTTRADE = 7, /* Window */ + + CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE1 = 10, /* ë ʧ ةë ū */ + CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE2 = 11, /* ë ʧ ةë ū */ + CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE3 = 12, /* ë ʧ ةë ū */ + CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE4 = 13, /* ë ʧ ةë ū */ + CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME = 14, /* ë ū */ + CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME_ATTENTION = 15, /* ë ū */ + + CHAR_WINDOWTYPE_DENGON = 50, /* */ + + CHAR_WINDOWTYPE_WINDOWMAN_START = 100, + CHAR_WINDOWTYPE_WINDOWMAN_STARTMSG = CHAR_WINDOWTYPE_WINDOWMAN_START, + CHAR_WINDOWTYPE_WINDOWMAN_END = 200, + + CHAR_WINDOWTYPE_JANKEN_START = 210, + CHAR_WINDOWTYPE_JANKEN_MAIN = 211, + CHAR_WINDOWTYPE_JANKEN_END = 212, + + CHAR_WINDOWTYPE_TRANSMIGRATION_START = 213, + CHAR_WINDOWTYPE_TRANSMIGRATION_MAIN = 214, + CHAR_WINDOWTYPE_TRANSMIGRATION_END = 215, + CHAR_WINDOWTYPE_TRANSMIGRATION_NONE = 216, + + + CHAR_WINDOWTYPE_WINDOWHEALER_START = 220, + CHAR_WINDOWTYPE_WINDOWHEALER_STARTMSG = CHAR_WINDOWTYPE_WINDOWHEALER_START, + CHAR_WINDOWTYPE_WINDOWHEALER_HPMSG = 221, + CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG = 222, + CHAR_WINDOWTYPE_WINDOWHEALER_SPIRITMSG = 223, + CHAR_WINDOWTYPE_WINDOWHEALER_OKSPIRITMSG = 224, + CHAR_WINDOWTYPE_WINDOWHEALER_ALLMSG = 225, + CHAR_WINDOWTYPE_WINDOWHEALER_OKALLMSG = 226, + CHAR_WINDOWTYPE_WINDOWHEALER_END = 227, + + CHAR_WINDOWTYPE_WINDOWSAVEPOINT_START = 230, + + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG = 231, + CHAR_WINDOWTYPE_WINDOWEVENT_NOWEVENT = 232, + CHAR_WINDOWTYPE_WINDOWEVENT_ENDEVENT = 233, + CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG = 234, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG = 235, + CHAR_WINDOWTYPE_WINDOWEVENT_NOMALMSG = 236, + CHAR_WINDOWTYPE_WINDOWEVENT_CLEANMSG = 237, + CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK = 238, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCTHANK = 239, + + + CHAR_WINDOWTYPE_WINDOWITEMSHOP_START = 240, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG = CHAR_WINDOWTYPE_WINDOWITEMSHOP_START, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_MENU = 241, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_BUY_MSG = 242, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_SELL_MSG = 243, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_END = 244, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_LIMIT = 245, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_EXPRESS = 246, + + CHAR_WINDOWTYPE_DUELRANKING_START = 250, + CHAR_WINDOWTYPE_DUELRANKING_TOPRANKING = 251, + CHAR_WINDOWTYPE_DUELRANKING_MYRANKING = 252, + CHAR_WINDOWTYPE_DUELRANKING_WAIT = 253, + CHAR_WINDOWTYPE_DEFEND_BILLDBOARD = 254, + + CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP = 260, + + CHAR_WINDOWTYPE_WINDOWPETSHOP_START = 261, + CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT = 262, + CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN = 263, + CHAR_WINDOWTYPE_WINDOWPETSHOP_GOLDOVER = 264, + CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT2 = 265, + CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN2 = 266, + CHAR_WINDOWTYPE_WINDOWPETSHOP_DRAWSELECT = 267, + CHAR_WINDOWTYPE_WINDOWPETSHOP_ASKDRAW = 268, + CHAR_WINDOWTYPE_WINDOWPETSHOP_END = 269, + + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN = 271, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR = 272, + CHAR_WINDOWTYPE_WINDOWWARPMAN_END = 273, + + CHAR_WINDOWTYPE_NPCENEMY_START = 281, + + CHAR_WINDOWTYPE_CHARM_START = 282, + CHAR_WINDOWTYPE_CHARM_END = 283, + + CHAR_WINDOWTYPE_QUIZ_START = 284, + CHAR_WINDOWTYPE_QUIZ_MAIN = 285, + CHAR_WINDOWTYPE_QUIZ_END = 286, + + CHAR_WINDOWTYPE_CHECKMAN_START = 287, + CHAR_WINDOWTYPE_CHECKMAN_MAIN = 288, + CHAR_WINDOWTYPE_CHECKMAN_END = 289, + + CHAR_WINDOWTYPE_FAMILYMAN_START = 320, + CHAR_WINDOWTYPE_FAMILYMAN_ADD = 321, + CHAR_WINDOWTYPE_FAMILYMAN_JOIN = 322, + CHAR_WINDOWTYPE_FAMILYMAN_OUT = 323, + CHAR_WINDOWTYPE_FAMILYMAN_BROKEN = 324, +#ifdef _FMPOINT_PKTIME_SELECT + CHAR_WINDOWTYPE_FAMILYMAN_PKTIME = 325, // ѡPKʱ +#endif + CHAR_WINDOWTYPE_BANKMAN = 330, + + // CoolFish: FMPKMan 2001/7/4 + CHAR_WINDOWTYPE_FMPKMAN_START = 340, + CHAR_WINDOWTYPE_FMPKMAN_VIEW = 341, + CHAR_WINDOWTYPE_FMPKMAN_LEAVEPK = 342, + CHAR_WINDOWTYPE_FMPKCALLMAN_START = 345, + CHAR_WINDOWTYPE_FMPKCALLMAN_CALL = 346, + CHAR_WINDOWTYPE_FMPKCALLMAN_COME = 347, + CHAR_WINDOWTYPE_FMPKCALLMAN_LEAVE = 348, + + // Arminius 7.13 scheduleman + CHAR_WINDOWTYPE_SCHEDULEMAN_START = 350, + CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT = 351, + CHAR_WINDOWTYPE_SCHEDULEMAN_DETAIL = 352, + + // Arminius 7.27 + CHAR_WINDOWTYPE_MANORPK_START = 360, + CHAR_WINDOWTYPE_MANORPK_ASK = 361, + CHAR_WINDOWTYPE_MANORPK_END = 362, + + // shan + CHAR_WINDOWTYPE_FM_DENGON = 370, // ԰ + CHAR_WINDOWTYPE_FM_FMSDENGON = 371, // ֮԰ + CHAR_WINDOWTYPE_FM_MESSAGE1 = 372, // ˵Ӵ(ݵ) + CHAR_WINDOWTYPE_FM_MESSAGE2 = 373, // ˵Ӵ(Ա) + CHAR_WINDOWTYPE_FM_SELECT = 374, // ѡӴ + CHAR_WINDOWTYPE_FM_MEMBERLIST = 375, // Աб + CHAR_WINDOWTYPE_FM_POINTLIST = 376, // ݵб + CHAR_WINDOWTYPE_FM_DPTOP = 377, // ǿ߱(ǰʮа) + CHAR_WINDOWTYPE_FM_DPME = 378, // ǿ߱(Լа) + CHAR_WINDOWTYPE_FM_DPSELECT = 379, // ǿ߱ѡӴ + +#ifdef _PET_TRANS + CHAR_WINDOWTYPE_PETTRANS_START = 384, + CHAR_WINDOWTYPE_PETTRANS_SELECT = 385, + CHAR_WINDOWTYPE_PETTRANS_SELPET = 386, + CHAR_WINDOWTYPE_PETTRANS_MAIN1 = 387, + CHAR_WINDOWTYPE_PETTRANS_END = 389, +#endif + +#ifdef _GAMBLE_BANK + NPC_GambleBank_START = 390, + NPC_GambleBank_SELECT, + NPC_GambleBank_BANK, + NPC_GambleBank_CHANG1, + NPC_GambleBank_CHANG2, + NPC_GambleBank_END, +#endif + +#ifdef _PETRACE + CHAR_WINDOWTYPE_PETRACEMASTER_START = 410, + CHAR_WINDOWTYPE_PETRACEMASTER_RULE, + CHAR_WINDOWTYPE_PETRACEMASTER_PET, + CHAR_WINDOWTYPE_PETRACEMASTER_LEAVE, +#endif + +#ifdef _GAMBLE_ROULETTE + WINDOWTYPE_GAMBLEROULETTE_START = 415, + WINDOWTYPE_GAMBLEROULETTE_SELECT, + WINDOWTYPE_GAMBLEROULETTE_END, +#endif + +#ifdef _NEWEVENT + CHAR_WINDOWTYPE_WINDOWEVENT_ACCTHANKNEW = 430, +#endif + +#ifdef _TRANSER_MAN + NPC_TRANSERMAN_START = 440, + NPC_TRANSERMAN_SELECT, + NPC_TRANSERMAN_WARP, + NPC_TRANSERMAN_END, +#endif +#ifdef _ITEM_NPCCHANGE + NPC_ITEMCHANGE_START = 445, + NPC_ITEMCHANGE_SELECT, + NPC_ITEMCHANGE_MESSAGE, + NPC_ITEMCHANGE_END, +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + NPC_ALLDOMAN_START = 460, + NPC_ALLDOMAN_START2, + NPC_ALLDOMAN_START3, + NPC_ALLDOMAN_HEAL, + NPC_ALLDOMAN_GIVEMONEY, + NPC_ALLDOMAN_MAIN_WND , + NPC_ALLDOMAN_SELECT_WND , + NPC_ALLDOMAN_LIST_WND , +#endif + +#ifdef _PETSKILL_CANNEDFOOD + ITEM_WINDOWTYPE_SELECTPETSKILL_SELECT = 470, + ITEM_WINDOWTYPE_SELECTPETSKILL_END, +#endif + +#ifdef _NPC_WELFARE + NPC_WELFARE_START = 480, + NPC_WELFARE_END, +#endif + +#ifdef _NPC_DEPOTPET + CHAR_WINDOWTYPE_DEPOTPETSHOP_MENU = 510, + CHAR_WINDOWTYPE_DEPOTPETSHOP_HANDLE, + CHAR_WINDOWTYPE_DEPOTPETSHOP_ADD, + CHAR_WINDOWTYPE_DEPOTPETSHOP_GET, + CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKADD, + CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKGET, +#endif + +#ifdef _ANGEL_SUMMON + CHAR_WINDOWTYPE_ANGEL_ASK = 520, + CHAR_WINDOWTYPE_ANGEL_CLEAN, +#endif + +#ifdef _ITEM_PET_LOCKED + CHAR_WINDOWTYPE_ITEM_PET_LOCKED = 530, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED_PASSWD, +#endif +#ifdef _NPC_MAGICCARD //ħ + CHAR_WINDOWTYPE_MAGIC_START = 570, //ħ + CHAR_WINDOWTYPE_MAGIC_RULES, + CHAR_WINDOWTYPE_MAGIC_NORMAL, + CHAR_WINDOWTYPE_MAGIC_SELECT, +#endif +#ifdef _ONLINE_COST + CHAR_WINDOWTYPE_ONLINE_COST, +#endif + +#ifdef _SQL_BUY_FUNC + CHAR_WINDOWTYPE_ONLINE_BUY, +#endif + +#ifdef _NULL_CHECK_ITEM + CHAR_WINDOWTYPE_NULL_CHECK, +#endif + +#ifdef _ITEM_UPLEVEL + CHAR_WINDOWTYPE_ITEM_UPLEVEL, +#endif + +#ifdef _NEW_STREET_VENDOR + CHAR_WINDOWTYPE_STREET_VENDOR_TYPE, // ̯ +#endif + +#ifdef _LOTTERY_SYSTEM + CHAR_WINDOWTYPE_LOTTERYBUY, +#endif + +#ifdef _BATTLE_PK_TYPE + CHAR_WINDOWTYPE_BATTLEPKTYPE, +#endif + +#ifdef _PAUCTION_MAN + NPC_PAUCTION_START, + NPC_PAUCTION_SELECT, + NPC_PAUCTION_NEW, + NPC_PAUCTION_AUCTIONSURVEY, + NPC_PAUCTION_LIST_BUY_ALL, + NPC_PAUCTION_LIST_BUY_PET, + NPC_PAUCTION_LIST_BUY_ITEM, + NPC_PAUCTION_LIST_MODIFY, +#endif + +#ifdef _ITEM_OVER_LAP + CHAR_WINDOWTYPE_ITEMOVERLAP, +#endif +#ifdef _LOCK_PET_ITEM + CHAR_WINDOWTYPE_DROPITEM, +#endif +#ifdef _RED_MEMOY_ + CHAR_WINDOWTYPE_REDMEMOY, +#endif +}CHAR_WINDOWTYPE; + +#ifdef _GMRELOAD +typedef struct tagGMInfo +{ + char cdkey[24]; + int level; +}GMInfo; +#endif + + +#ifdef _ANGEL_SUMMON + +#define MAXMISSION 100 +#define MAXMISSIONTABLE 200 + +struct MissionInfo +{ + int id; + char detail[1024]; + int level; + char eventflag[1024]; + //char bonus[1024]; + int limittime; +}; + +struct MissionTable +{ + char angelinfo[128]; + char heroinfo[128]; + int mission; + int flag; + int time; + int limittime; +}; + +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; + +#endif + +#ifdef _JOBDAILY + +#define MAXDAILYLIST 1000 +#define MAXMISSIONFLAG 1000 +typedef struct _DailyFileType +{ + int jobid; // + char rule[64]; //ж + char explain[64]; //˵ + char state[64]; //״̬˵ +}DailyFileType; +//extern struct DailyFileType dailyfile[MAXDAILYLIST]; + +#endif +int getPartyNum(int charaindex); +BOOL CHAR_talkToCli( int talkedcharaindex,int talkcharaindex, char* message, CHAR_COLOR color ); +void CHAR_talkToCliAndParty( int talkedcharaindex,int talkcharaindex,char* message, CHAR_COLOR color ); +void CHAR_talkToAll(int talkindex, char* message, CHAR_COLOR color); +void CHAR_getCoordinationDir( int dir , int x, int y ,int c, + int *xout , int *yout ); +BOOL CHAR_createCharacter( int type, int floor, int x, int y, int dir, + int* charaindex, int* objindex, BOOL seemap ); +void CHAR_CharaDelete( int charaindex ); +void CHAR_ObjectDelete( int objindex ); +int CHAR_makeDBKey( int charaindex, char *pszBuffer, int size ); +int CHAR_getEmptyPartyArray( int charaindex); +BOOL CHAR_JoinParty( int charaindex ); +BOOL CHAR_JoinParty_Main( int charaindex, int targetindex); +BOOL CHAR_JoinParty_Main_New( int charaindex, int targetindex,int flg); +BOOL CHAR_DischargeParty( int charaindex, int flg); +BOOL CHAR_DischargeParty_New( int charaindex, int flg); +BOOL CHAR_DischargePartyNoMsg( int charaindex); +BOOL CHAR_setMyPosition_main( int index, int x, int y, int setdir, BOOL CAFlg); +BOOL CHAR_setMyPosition( int index, int x, int y, BOOL CAFlg); + +void CHAR_CharaDeleteHavePet( int charaindex); +int CHAR_sendAction( int charaindex, int action, int mode); +void CHAR_sendLeader( int objindex, int leader); +void CHAR_sendBattleWatch( int objindex, int onoff); +void CHAR_sendBattleEffect( int charaindex, int onoff); + +// shan +void CHAR_sendTradeEffect( int charaindex, int onoff); +#ifdef _MIND_ICON +void CHAR_sendMindEffect( int charaindex, int onoff); +#endif +#ifdef _ITEM_CRACKER +void CHAR_sendCrackerEffect( int charaindex, int onoff); +#endif + +void CHAR_inputUserPetName( int index , int havepetindex, char* name ); +int CHAR_getPartyIndex( int index, int num); +void CHAR_processWindow(int charaindex, int seqno, int select, + int objindex, char* data ); +void CHAR_AddCharm( int charaindex, int iValue ); +void CHAR_PetAddVariableAi( int petindex, int iValue ); +void CHAR_PartyUpdate( int charaindex, int senddata ); +char *CHAR_getUseName( int charaindex ); +char *CHAR_getUseID( int charaindex ); +EXTERN int EnemyMoveNum; /* ݱ ³ļ */ + +#define DB_DUELPOINT "db_duel" // ب޻̼ì +#define DB_ADDRESSBOOK "db_addressbook" // ʧƤͷì + +BOOL CHAR_send_DpDBUpdate( int charaindex ); +BOOL CHAR_send_DpDBUpdate_AddressBook( int charaindex, int mode ); + + +void CHAR_sendPMEToArroundCharacter( int charaindex, int petindex, int flg, int no ); +void CHAR_sendPMEToArroundCharacterFLXY( int petindex, + int fl, int x, int y, int dir, int flg, int no ); + +void CHAR_sendSEoArroundCharacter( int fl, int x, int y, int senumber, int sw ); + +BOOL CHAR_initEffectSetting( char* filename ); +void CHAR_checkEffect( int charaindex); +void CHAR_checkEffectLoop( void); +void CHAR_initDebugChatCdkey( void); +int CHAR_setChatMagicCDKey( int mode, char *cdkey); + + +float GetRecoveryRate( int charaindex ); +int storeCharaData( void ); +#ifdef _MAGIC_REHPAI //ѪAI +int Magic_RideGetHP( int toindex, int petindex, int flg); +#endif +// CoolFish: Trade 2001/4/18 +int CHAR_findTotalEmptyItem(int index); + + +#ifdef _FIX_METAMORIDE +int CHAR_CHECKJOINENEMY( int index); +#endif + +#ifdef _SEND_EFFECT // WON ADD ACѩЧ +#define CHAR_EFFECT_SETTINGBUFFER 256 +typedef struct tagCHAR_effectsetting +{ + int floor; // ׷ʧ + int effect; // į + int level; // 뼰ì ؼ۽ + int sendflg; // ްë˪׾ + char month[CHAR_EFFECT_SETTINGBUFFER]; // » + char day[CHAR_EFFECT_SETTINGBUFFER]; // + char hour[CHAR_EFFECT_SETTINGBUFFER]; // + char min[CHAR_EFFECT_SETTINGBUFFER]; // + char expire[CHAR_EFFECT_SETTINGBUFFER]; // ƻӮ( + +}CHAR_effectsetting; + +CHAR_effectsetting* CHAR_effect; +int CHAR_effectnum; +#endif + +#ifdef _ITEM_PILENUMS +int CHAR_getMyMaxPilenum( int charaindex); +#endif + +#ifdef _PET_LOSTPET +BOOL CHAR_CharSaveLostPet( int petindex, int type); +#endif +#ifdef _ALLDOMAN +void InitHeroList( void); +#endif + + +#ifdef _STREET_VENDOR +void CHAR_sendStreetVendor(int charaindex,char *message); +void CHAR_sendStreetVendorDataToCli(int charaindex,int toindex); +void CHAR_sendStreetVendorOneDataToCli(int charaindex,int toindex,int sendindex); +#endif + +BOOL checkUnlawWarpFloor( int floor); + +#ifdef _HELP_NEWHAND +void CHAR_loginAddItemForNew( int charaindex ); +#endif + +#ifdef _JOBDAILY +void CHAR_JobDaily(int charaindex,char *data); +#endif + +#ifdef _TEACHER_SYSTEM +void CHAR_Teacher_system(int charaindex,char *data); +void CHAR_Teacher_system_View(int charaindex,int iOnLine,char *data); +#endif + +#ifdef _TIME_TICKET +void check_TimeTicket(); +int check_TimeTicketMap(int floor); +#endif + +#ifdef _ANGEL_SUMMON +int checkIfAngel( int charaindex); +int checkIfOnlyAngel( int charaindex); +void selectAngel( int charaindex, int heroindex, int mission, int gm_cmd); +char* getMissionNameInfo( int charaindex, char* nameinfo); +void CHAR_sendAngelMark( int objindex, int flag); +void Use_AngelToken( int charaindex, int toindex, int haveitemindex ); +void Use_HeroToken( int charaindex, int toindex, int haveitemindex ); +int AngelCreate( int angelindex); +void sendAngelCleanToCli( int fd); +#endif +#ifdef _ITEM_CHECKDROPATLOGOUT +BOOL CheckDropatLogout(int charaindex ); +#endif +#ifdef _ROOKIE_ITEM +void CHAR_CheckUserItem( int charaindex ); +#endif +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_base.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_base.h new file mode 100644 index 0000000..521682f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_base.h @@ -0,0 +1,2254 @@ +#ifndef __CHAR_BASE_H__ +#define __CHAR_BASE_H__ + +#include "version.h" +#include "skill.h" +#include "title.h" +/*#include "magicinfo.h"*/ +#include "addressbook.h" +#ifdef _ALLBLUES_LUA +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#endif +#define CHAR_DELIMITER "\n" + +#define NONCHAR_DELIMITER "|" + +#define STATUSSENDDELIMITER "|" + +#define CHAR_MAXGOLDHAVE (10000*10000) +#define CHAR_MAXBANKGOLDHAVE (10000*10000) +#define CHAR_MAXFMBANKGOLDHAVE (10000*100000) + +#ifdef _NEW_MANOR_LAW +#define MAX_PERSONAL_MOMENTUM 10000000 +#endif +#ifdef _PERSONAL_FAME // Arminius 8.30: +#define MAX_PERSONALFAME 100000000 +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#define CHAR_SKILLMAXHAVE 26 // ְҵ +#else +#define CHAR_SKILLMAXHAVE 5 +#endif + +#ifdef _STREET_VENDOR +#define MAX_SELL_ITEM 20 // ߼ӳﹲʮ +#endif +#define CHAR_TITLEMAXHAVE 30 + +#define NULLSKILL "0" + +#define CHAR_MAXPETHAVE 5 +#define CHAR_MAXPERSONAGOLD 50000000 + +#ifdef _ADD_POOL_ITEM // WON ADD ӿɼķŵĵ +#define CHAR_MAXPOOLPETHAVE 15 +#else +#define CHAR_MAXPOOLPETHAVE 10 +#endif + +#define CHAR_MAXPETSKILLHAVE 7 +#ifdef _MULTIPLAYER_ +#define CHAR_PARTYMAX 6 +#else +#define CHAR_PARTYMAX 5 +#endif +#ifdef _PLAYER_NPC +#define CHAR_PLAYERNPCMAX 4 +#endif +#define CHAR_MAXATTRIB 100 +#define CHAR_MAXUPLEVEL 200 +#define CHAR_MAXDUELPOINT 100000000 +#define CHAR_DEFAULTMAXAI (60) +#define CHAR_MAXVARIABLEAI (100*100) +#define CHAR_MINVARIABLEAI (-100*100) +#define CHAR_POISONSTRING "ж" +#define CHAR_RECOVERPOISONSTRING "ⶾ" +#define CHAR_PARALYSISSTRING "" +#define CHAR_RECOVERPARALYSISSTRING "" +#define CHAR_SILENCESTRING "޷ħ" +#define CHAR_RECOVERSILENCESTRING "ħ" +#define CHAR_STONESTRING "ʯ" +#define CHAR_RECOVERSTONESTRING "" +#define CHAR_DARKNESSSTRING "ܲ" +#define CHAR_RECOVERDARKNESSSTRING "ܳ" +#define CHAR_CONFUSIONSTRING "ֻ" +#define CHAR_RECOVERCONFUSIONSTRING "ָ" + +#define CHAR_DEFAULTSEESIZ 20 +#define MAP_CHAR_DEFAULTSEESIZ (CHAR_DEFAULTSEESIZ+4) + +typedef enum +{ + CHAR_HEAD, + CHAR_BODY, + CHAR_ARM, + CHAR_DECORATION1, + CHAR_DECORATION2, +#ifdef _ITEM_EQUITSPACE + CHAR_EQBELT, // + CHAR_EQSHIELD, // + CHAR_EQSHOES, //Ь +#endif +#ifdef _EQUIT_NEWGLOVE + CHAR_EQGLOVE, +#endif + CHAR_EQUIPPLACENUM, +}CHAR_EquipPlace; + + +typedef enum +{ + CHAR_PET_HEAD, //ͷ + CHAR_PET_TOOTH, // + CHAR_PET_CLAW, //צ + CHAR_PET_BREAST, // + CHAR_PET_BACK, // + CHAR_PET_WING, // + CHAR_PET_FEET, // + + CHAR_PETITEMNUM, +}CHAR_petitem; + + +typedef struct tagCharHaveSkill +{ + int use; + Skill skill; +}CHAR_HaveSkill; + +#ifdef _STREET_VENDOR +typedef struct STREET_VENDDOR_t{ + int pile; // + int price; // ۸ + int index; // + int kind; // ߻dz 0: 1: + BOOL usage; // Ƿʹ +}StreetVendor_t; + +enum{ + SV_PILE, + SV_PRICE, + SV_INDEX, + SV_KIND, + SV_USAGE, + MAX_SV +}; +#endif + +typedef enum +{ + CHAR_ACTSTAND, + CHAR_ACTWALK, + CHAR_ACTATTACK, + CHAR_ACTTHROW, + CHAR_ACTDAMAGE, + CHAR_ACTDEAD, + CHAR_ACTMAGIC, + CHAR_ACTITEM, + CHAR_ACTEFFECT, + CHAR_ACTDOWN = 10, + CHAR_ACTSIT, + CHAR_ACTHAND, + CHAR_ACTPLEASURE, + CHAR_ACTANGRY, + CHAR_ACTSAD, + CHAR_ACTGUARD, + CHAR_ACTACTIONWALK, + CHAR_ACTNOD, + CHAR_ACTACTIONSTAND, + CHAR_ACTBATTLE = 20, + CHAR_ACTLEADER, + CHAR_ACTBATTLEWATCH, + CHAR_ACTPOPUPNAME, + CHAR_ACTTURN = 30, + CHAR_ACTWARP, + CHAR_ACTTRADE, +#ifdef _ANGEL_SUMMON + CHAR_ACTANGEL = 34, +#endif + +#ifdef _MIND_ICON + CHAR_MIND = 40, +#endif +#ifdef _STREET_VENDOR + CHAR_STREETVENDOR_OPEN, + CHAR_STREETVENDOR_CLOSE, +#endif +#ifdef _FAMILYBADGE_ + CHAR_FAMILYBADGE, +#endif +#ifdef _ITEM_CRACKER + CHAR_ITEM_CRACKER = 50, +#endif + +}CHAR_ACTION; + +typedef enum +{ + CHAR_CLIACTATTACK, + CHAR_CLIACTDAMAGE, + CHAR_CLIACTDOWN, + CHAR_CLIACTSTAND, + CHAR_CLIACTWALK, + CHAR_CLIACTSIT, + CHAR_CLIACTHAND, + CHAR_CLIACTPLEASURE, + CHAR_CLIACTANGRY, + CHAR_CLIACTSAD, + CHAR_CLIACTGUARD, + CHAR_CLIACTNOD, + CHAR_CLIACTTHROW, + +}CHAR_CLIENTACTION; + +typedef enum +{ + CHAR_TYPENONE, + CHAR_TYPEPLAYER, + CHAR_TYPEENEMY, + CHAR_TYPEPET, + CHAR_TYPEDOOR, + CHAR_TYPEBOX, + CHAR_TYPEMSG, + CHAR_TYPEWARP, + CHAR_TYPESHOP, + CHAR_TYPEHEALER, + CHAR_TYPEOLDMAN, + CHAR_TYPEROOMADMIN, + CHAR_TYPETOWNPEOPLE, + CHAR_TYPEDENGON, + CHAR_TYPEADM, + CHAR_TYPETEMPLE, + CHAR_TYPESTORYTELLER, + CHAR_TYPERANKING, + CHAR_TYPEOTHERNPC, + CHAR_TYPEPRINTPASSMAN, + CHAR_TYPENPCENEMY, + CHAR_TYPEACTION, + CHAR_TYPEWINDOWMAN, + CHAR_TYPESAVEPOINT, + CHAR_TYPEWINDOWHEALER, + CHAR_TYPEITEMSHOP, + CHAR_TYPESTONESHOP, + CHAR_TYPEDUELRANKING, + CHAR_TYPEWARPMAN, + CHAR_TYPEEVENT, + CHAR_TYPEMIC, + CHAR_TYPELUCKYMAN, + CHAR_TYPEBUS, + CHAR_TYPECHARM, + CHAR_TYPECHECKMAN, + CHAR_TYPEJANKEN, + CHAR_TYPETRANSMIGRATION, + CHAR_TYPEFMWARPMAN, // У˳Ա + CHAR_TYPEFMSCHEDULEMAN, // У˳ǼԱ + CHAR_TYPEMANORSCHEDULEMAN, // ׯ԰У˳ԤԼ +#ifdef _GAMBLE_BANK + CHAR_GAMBLEBANK, +#endif +#ifdef _NEW_WARPMAN + CHAR_NEWNPCMAN, +#endif + +#ifdef _GAMBLE_ROULETTE + CHAR_GAMBLEROULETTE, + CHAR_GAMBLEMASTER, +#endif +#ifdef _TRANSER_MAN + CHAR_TRANSERMANS, +#endif + +#ifdef _NPC_MAKEPAIR + CHAR_MAKEPAIR, +#endif +#ifdef _NPC_FUSION + CHAR_PETFUSIONMAN, +#endif + +#ifdef _ITEM_NPCCHANGE + CHAR_ITEMCHANGENPC, +#endif +#ifdef _CFREE_petskill + CHAR_FREESKILLSHOP, +#endif +#ifdef _PETRACE + CHAR_PETRACEMASTER, // ᄎ + CHAR_PETRACEPET, +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + CHAR_TYPEALLDOMAN, +#endif + + CHAR_TYPEPETMAKER, // petmaker + +#ifdef _NPC_WELFARE + CHAR_TYPEWELFARE, +#endif +#ifdef _ALLBLUES_LUA + CHAR_TYPELUANPC, +#endif +#ifdef _PLAYER_NPC + CHAR_TYPEPLAYERNPC, + CHAR_TYPEPLAYERPETNPC, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + CHAR_LUANPC, +#endif + + CHAR_TYPENUM, +}CHAR_TYPE; + +typedef enum +{ + CHAR_EVENT_NONE, + CHAR_EVENT_NPC, + CHAR_EVENT_ENEMY, + CHAR_EVENT_WARP, + CHAR_EVENT_DOOR, + CHAR_EVENT_ALTERRATIVE, + CHAR_EVENT_WARP_MORNING, + CHAR_EVENT_WARP_NOON, + CHAR_EVENT_WARP_NIGHT, + CHAR_EVENTNUM, +}CHAR_EVENT; + +typedef enum +{ + CHAR_PARTY_NONE, + CHAR_PARTY_LEADER, + CHAR_PARTY_CLIENT, +}CHAR_PARTY_MODE; + +typedef enum +{ + CHAR_TRADE_FREE, /* ɽ */ + CHAR_TRADE_SENDING, /* */ + CHAR_TRADE_TRADING, /* */ + CHAR_TRADE_LOCK, /* */ +}CHAR_TRADE_MODE; + +typedef enum +{ + CHAR_PETMAIL_NONE, + CHAR_PETMAIL_IDLE1, + CHAR_PETMAIL_IDLE2, + CHAR_PETMAIL_RETURNWAIT, + CHAR_PETMAIL_IDLE3, + CHAR_PETMAIL_IDLE4, + CHAR_PETMAIL_IDLE5, +}CHAR_PETMAIL_MODE; + +typedef enum +{ + CHAR_PETFOLLOW_NONE, + CHAR_PETFOLLOW_NOW, +}CHAR_PETFOLLOW_MODE; + +#ifdef _DROPSTAKENEW +typedef enum +{ + DICE_BIG = 1, // _ + DICE_SMALL, // _С + DICE_ALLEAT, // _ͨ + PET_RACE1 = 5, // ٳ_1 + PET_RACE2, // ٳ_2 + PET_RACE3, // ٳ_3 + ROULETTE1 = 11, ROULETTE2, ROULETTE3, ROULETTE4, ROULETTE5, ROULETTE6, ROULETTE7, + ROULETTE8, ROULETTE9, ROULETTE10, ROULETTE11, ROULETTE12, ROULETTE13, ROULETTE14, + ROULETTE15, ROULETTE16, ROULETTE17, ROULETTE18, ROULETTE19, ROULETTE20, + ROULETTE21 = 41, ROULETTE22, ROULETTE23, ROULETTE24, ROULETTE25, ROULETTE26, + ROULETTE27, ROULETTE28, ROULETTE29, ROULETTE30, ROULETTE31, ROULETTE32, + ROULETTE33, ROULETTE34, ROULETTE35, ROULETTE36, ROULETTE37, ROULETTE38, + ROULETTE39, ROULETTE40, + ROULETTE41 = 71, ROULETTE42, ROULETTE43, ROULETTE44, ROULETTE45, + ROULETTE51 = 101, ROULETTE52, ROULETTE53, // + ROULETTE61 = 111, ROULETTE62, //110 1011 + PETFIGHT_WIN1 = 120, + PETFIGHT_WIN2, + PETFIGHT_DUEL, +}GAMBLE_TYPE; +#endif +#if _ATTESTAION_ID == 1 +#define CHAR_MAXDEPOTITEMHAVE 50 +#define CHAR_MAXDEPOTPETHAVE 30 +#define CHAR_MAXPOOLITEMHAVE 30 + +#else +#ifdef _CHAR_POOLITEM +#ifdef _NPC_DEPOTPET // ųֿͬʱӵֿ߲ +#define CHAR_MAXDEPOTITEMHAVE 80 +#else +#define CHAR_MAXDEPOTITEMHAVE 60 +#endif +#endif + +#ifdef _CHAR_POOLPET +#define CHAR_MAXDEPOTPETHAVE 30 +#endif + + +#ifdef _ADD_POOL_ITEM // (ɿ) WON ADD ӿɼķŵĵ +#define CHAR_MAXPOOLITEMHAVE 30 +#else +#define CHAR_MAXPOOLITEMHAVE 20 +#endif +#endif + +#define CHAR_MAXITEMNUM 15 +#define CHAR_STARTITEMARRAY CHAR_EQUIPPLACENUM +#ifdef _NEW_ITEM_ +#define CHAR_MAXITEMHAVE (CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM*3) +#else +#define CHAR_MAXITEMHAVE (CHAR_STARTITEMARRAY+CHAR_MAXITEMNUM) +#endif +#define CHAR_MAXPETITEMHAVE CHAR_PETITEMNUM + +typedef enum +{ + CHAR_DATAPLACENUMBER, + CHAR_BASEIMAGENUMBER, + CHAR_BASEBASEIMAGENUMBER, + CHAR_FACEIMAGENUMBER, + CHAR_FLOOR, + CHAR_X, + CHAR_Y, + CHAR_DIR, + CHAR_LV, + CHAR_GOLD, + CHAR_HP, + CHAR_MP, + CHAR_MAXMP, + CHAR_VITAL, + CHAR_STR, + CHAR_TOUGH, + CHAR_DEX, + CHAR_CHARM, + CHAR_LUCK, + CHAR_EARTHAT, + CHAR_WATERAT, + CHAR_FIREAT, + CHAR_WINDAT, + CHAR_DEFAULTPET, + CHAR_CRITIAL, + CHAR_COUNTER, + CHAR_RARE, + CHAR_RADARSTRENGTH, + CHAR_CHATVOLUME, + CHAR_MERCHANTLEVEL, + CHAR_HEALERLEVEL, + CHAR_SAVEPOINT = CHAR_HEALERLEVEL, + CHAR_DETERMINEITEM, + CHAR_INDEXOFEQTITLE, + CHAR_POISON, + CHAR_PARALYSIS, + CHAR_SLEEP, + CHAR_STONE, + CHAR_DRUNK, + CHAR_CONFUSION, + CHAR_LOGINCOUNT, + CHAR_NPCCREATEINDEX=CHAR_LOGINCOUNT, + CHAR_DEADCOUNT, + CHAR_WALKCOUNT, + CHAR_TALKCOUNT, + CHAR_DAMAGECOUNT, + CHAR_GETPETCOUNT, + CHAR_KILLPETCOUNT, + CHAR_DEADPETCOUNT, + CHAR_SENDMAILCOUNT, + CHAR_MERGEITEMCOUNT, + CHAR_DUELBATTLECOUNT, + CHAR_DUELWINCOUNT, + CHAR_DUELLOSECOUNT, + CHAR_DUELSTWINCOUNT, + CHAR_DUELSTLOSECOUNT, + CHAR_DUELMAXSTWINCOUNT, + CHAR_WHICHTYPE, + CHAR_WALKINTERVAL, + CHAR_LOOPINTERVAL, + CHAR_LOOPINTERVALAB, +#ifdef _NEWOPEN_MAXEXP + CHAR_OLDEXP, +#endif + CHAR_EXP, + + CHAR_LASTTALKELDER, + CHAR_SKILLUPPOINT, + CHAR_LEVELUPPOINT, + CHAR_IMAGETYPE, + CHAR_NAMECOLOR, + CHAR_POPUPNAMECOLOR, + CHAR_LASTTIMESETLUCK, + CHAR_DUELPOINT, + CHAR_ENDEVENT, /* (0~31) */ + CHAR_ENDEVENT2, /* (32~63) */ + CHAR_ENDEVENT3, /* (64~96) */ +#ifdef _NEWEVENT + CHAR_ENDEVENT4, /* (96~127) */ + CHAR_ENDEVENT5, /* (128~159) */ + CHAR_ENDEVENT6, /* (160~191) */ +#endif +#ifdef _ADD_NEWEVENT // WON + CHAR_ENDEVENT7, + CHAR_ENDEVENT8, +#endif +#ifdef _ADD_NEWEVENT_1024 + CHAR_ENDEVENT9, + CHAR_ENDEVENT10, + CHAR_ENDEVENT11, + CHAR_ENDEVENT12, + CHAR_ENDEVENT13, + CHAR_ENDEVENT14, + CHAR_ENDEVENT15, + CHAR_ENDEVENT16, + CHAR_ENDEVENT17, + CHAR_ENDEVENT18, + CHAR_ENDEVENT19, + CHAR_ENDEVENT20, + CHAR_ENDEVENT21, + CHAR_ENDEVENT22, + CHAR_ENDEVENT23, + CHAR_ENDEVENT24, + CHAR_ENDEVENT25, + CHAR_ENDEVENT26, + CHAR_ENDEVENT27, + CHAR_ENDEVENT28, + CHAR_ENDEVENT29, + CHAR_ENDEVENT30, + CHAR_ENDEVENT31, + CHAR_ENDEVENT32, +#endif + CHAR_NOWEVENT, /* (0~31) */ + CHAR_NOWEVENT2, /* (32~63) */ + CHAR_NOWEVENT3, /* (64~96) */ +#ifdef _NEWEVENT + CHAR_NOWEVENT4, /* (96~127) */ + CHAR_NOWEVENT5, /* (128~159) */ + CHAR_NOWEVENT6, /* (160~191) */ +#endif +#ifdef _ADD_NEWEVENT // WON + CHAR_NOWEVENT7, + CHAR_NOWEVENT8, // 224~255 ٻר +#endif +#ifdef _ADD_NEWEVENT_1024 + CHAR_NOWEVENT9, + CHAR_NOWEVENT10, + CHAR_NOWEVENT11, + CHAR_NOWEVENT12, + CHAR_NOWEVENT13, + CHAR_NOWEVENT14, + CHAR_NOWEVENT15, + CHAR_NOWEVENT16, + CHAR_NOWEVENT17, + CHAR_NOWEVENT18, + CHAR_NOWEVENT19, + CHAR_NOWEVENT20, + CHAR_NOWEVENT21, + CHAR_NOWEVENT22, + CHAR_NOWEVENT23, + CHAR_NOWEVENT24, + CHAR_NOWEVENT25, + CHAR_NOWEVENT26, + CHAR_NOWEVENT27, + CHAR_NOWEVENT28, + CHAR_NOWEVENT29, + CHAR_NOWEVENT30, + CHAR_NOWEVENT31, + CHAR_NOWEVENT32, +#endif + CHAR_TRANSMIGRATION, + CHAR_TRANSEQUATION, + CHAR_INITDATA, + CHAR_SILENT, /* char shutup time */ + CHAR_FMINDEX, // index + CHAR_FMLEADERFLAG, /* Ա + * FMMEMBER_NONE :ûмκμ + * FMMEMBER_APPLY : + * FMMEMBER_LEADER :峤 + * FMMEMBER_MEMBER :һԱ + * FMMEMBER_ELDER : + * FMMEMBER_INVITE :˾ // ʱ + * FMMEMBER_BAILEE : // ʱ + * FMMEMBER_VICELEADER :峤 // ʱ + */ + CHAR_FMSPRITE, // ػ + + + CHAR_BANKGOLD, + CHAR_RIDEPET, + CHAR_LEARNRIDE, +#ifdef _NEW_RIDEPETS + CHAR_LOWRIDEPETS, +#endif + CHAR_LIMITLEVEL, +#ifdef _PET_FUSION + CHAR_FUSIONCODE, //ֱ + CHAR_FUSIONINDEX, // + CHAR_FUSIONRAISE, // + CHAR_FUSIONBEIT, //走 + CHAR_FUSIONTIMELIMIT, // ʱ +#endif + +#ifdef _PERSONAL_FAME // Arminius 8.30: + CHAR_FAME, +#endif + +#ifdef _NEWSAVE + CHAR_SAVEINDEXNUMBER, /* SaveFile .0.char or .1.char */ +#endif + +#ifdef _ATTACK_MAGIC + CHAR_EARTH_EXP, // ҵĵħ + CHAR_WATER_EXP, // ҵˮħ + CHAR_FIRE_EXP, // ҵĻħ + CHAR_WIND_EXP, // ҵķħ + CHAR_EARTH_RESIST, // ҵĵħ + CHAR_WATER_RESIST, // ҵˮħ + CHAR_FIRE_RESIST, // ҵĻħ + CHAR_WIND_RESIST, // ҵķħ + CHAR_EARTH_ATTMAGIC_EXP, // ҵĵħȾֵ + CHAR_WATER_ATTMAGIC_EXP, // ҵˮħȾֵ + CHAR_FIRE_ATTMAGIC_EXP, // ҵĻħȾֵ + CHAR_WIND_ATTMAGIC_EXP, // ҵķħȾֵ + CHAR_EARTH_DEFMAGIC_EXP, // ҵĵħԾֵ + CHAR_WATER_DEFMAGIC_EXP, // ҵˮħԾֵ + CHAR_FIRE_DEFMAGIC_EXP, // ҵĻħԾֵ + CHAR_WIND_DEFMAGIC_EXP, // ҵķħԾֵ +#endif + + +#ifdef _GAMBLE_BANK + CHAR_PERSONAGOLD, //ij +#endif +#ifdef _DROPSTAKENEW + CHAR_GAMBLENUM, //ij +#endif +#ifdef _ADD_ACTION //npc + CHAR_ACTIONSTYLE, +#endif +#ifdef _PET_EVOLUTION + CHAR_EVOLUTIONBASEVTL, + CHAR_EVOLUTIONBASESTR, + CHAR_EVOLUTIONBASETGH, + CHAR_EVOLUTIONBASEDEX, +#endif + +#ifdef _FM_JOINLIMIT + CHAR_FMTIMELIMIT, +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + PROFESSION_CLASS, // ְҵ + PROFESSION_LEVEL, // ְҵȼ +// PROFESSION_EXP, // ְҵֵ + PROFESSION_SKILL_POINT, // ܵ + ATTACHPILE, // Ӷѵ + PROFESSION_FIRE_P, // + PROFESSION_ICE_P, // + PROFESSION_THUNDER_P, // + PROFESSION_FIRE_R, // + PROFESSION_ICE_R, // + PROFESSION_THUNDER_R, // ׿ +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + CHAR_HEROFLOOR, +#endif +#ifdef _PETSKILL_BECOMEPIG + CHAR_BECOMEPIG, + CHAR_BECOMEPIG_BBI,//Ҫɵͼ +#endif + CHAR_LASTLEAVETIME, // Robin add ʱ + +#ifdef _NEW_MANOR_LAW + CHAR_MOMENTUM, +#endif + +#ifdef _ITEM_ADDEXP2 + CHAR_ADDEXPPOWER, + CHAR_ADDEXPTIME, +#endif + +#ifdef _ANGEL_SUMMON + CHAR_HEROCNT, // Ĵ +#endif + +#ifdef _TEACHER_SYSTEM + CHAR_TEACHER_FAME, // ʦ쵼 +#endif + +#ifdef _GM_ITEM + CHAR_GMTIME, // GM +#endif + +#ifdef _VIP_SERVER + CHAR_AMPOINT, // ػر +#endif + +#ifdef _VIP_RIDE + CHAR_VIPRIDE, // Աڼ + CHAR_VIPTIME, // Աڼ +#endif + +#ifdef _PET_BEATITUDE + CHAR_BEATITUDE, +#endif + +#ifdef _RIDE_CF + CHAR_LOWRIDEPETS1, +#ifdef _ADD_RIDE_CF + CHAR_LOWRIDEPETS2, + CHAR_LOWRIDEPETS3, + CHAR_LOWRIDEPETS4, + CHAR_LOWRIDEPETS5, + CHAR_LOWRIDEPETS6, + CHAR_LOWRIDEPETS7, + CHAR_LOWRIDEPETS8, +#endif +#endif + +#ifdef _ITEM_PET_LOCKED + CHAR_LOCKED, +#endif + +#ifdef _BOUND_TIME + CHAR_BOUNDTIME, +#endif + +#ifdef _SUPER + CHAR_SUPER, +#endif + +#ifdef _ONLINE_SHOP + CHAR_BJ, +#endif + +#ifdef _LOTTERY_SYSTEM + CHAR_LOTTERY_DATE, + CHAR_LOTTERY_TIME, +#endif + +#ifdef _COMPOUND_EXP + CHAR_MATERIAL01, + CHAR_MATERIAL02, + CHAR_MATERIAL03, + CHAR_MATERIAL04, + CHAR_MATERIAL05, + CHAR_MATERIAL06, + CHAR_MATERIAL07, + CHAR_MATERIAL08, + CHAR_MATERIAL09, + CHAR_MATERIAL10, + CHAR_MATERIAL11, + CHAR_MATERIAL12, + CHAR_MATERIAL13, + CHAR_MATERIAL14, + CHAR_MATERIAL15, + CHAR_MATERIAL16, + CHAR_MATERIAL17, + CHAR_MATERIAL18, + CHAR_MATERIAL19, + CHAR_MATERIAL20, + CHAR_MATERIAL21, + CHAR_MATERIAL22, + CHAR_MATERIAL23, + CHAR_MATERIAL24, + CHAR_MATERIAL25, +#endif + +#ifdef _ONLINE_TIME + CHAR_ONLINE_TIME, +#endif + +#ifdef _CAMEO_MONEY + CHAR_CAMEO, +#endif + +#ifdef _MISSION_TRAIN + CHAR_MISSIONTRAIN_NUM, + CHAR_MISSIONTRAIN_TIME, +#endif +#ifdef _PET_EVOLVE + CHAR_EVOLVE, +#endif +#ifdef _FLOOR_DIFI_FIELD + CHAR_FLOORDIFI_TIME, +#endif + +#ifdef _ACTIVE_GAME + CHAR_ACTIVE, +#endif + +#ifdef _PLAYER_TITLE + CHAR_TITLE_LV, + CHAR_TITLE_TIME, +#endif +#ifdef _MISSION_TIME + CHAR_MISSION_TIME, +#endif +#ifdef _REGISTRATION_TIME + CHAR_REGISTRATION_TIME, + CHAR_REGISTRATION_COUNT, + CHAR_REGISTRATION_ONLINE_TIME, +#endif +#ifdef _SPECIAL_COUNTER + CHAR_SPCOUNTER, +#endif +#ifdef _SPECIAL_TIMER + CHAR_SPTIMER, +#endif +#ifdef _OFFLINE_TIME + CHAR_OFFLINE_TIME, +#endif +#ifdef _FAME_REG_TIME + CHAR_FAME_REG_TIME, +#endif +#ifdef _PETCOM_ + CHAR_YHP, + CHAR_YATK, + CHAR_YDEF, + CHAR_YQUICK, + CHAR_YLV, +#endif +#ifdef _NEW_ITEM_ + CHAR_NEWITEMFLG, +#endif +#ifdef _MO_PLAYER_EFFECT + CHAR_PLAYER_EFFECT_DEFAULT, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + CHAR_LUASAVE_INT_1, + CHAR_LUASAVE_INT_2, + CHAR_LUASAVE_INT_3, +#endif +#ifdef _ATTACK_EFFECT + CHAR_ATTACK_EFFECT, +#endif +#ifdef _MO_NO_WALK + CHAR_NO_WALK, +#endif +#ifdef _TENSE_FIELD + CHAR_TENSE_FIELD, +#endif +#ifdef _NEW_TITLE + CHAR_TITLE_DEFAULT, + CHAR_TITLE1, + CHAR_TITLE2, + CHAR_TITLE3, +#endif +#ifdef _CHARSIGNDAY_ + CHAR_QIANDAOZT, + CHAR_QIANDAOYUE, + CHAR_QIANDAORI, +#endif +#ifdef _TRUMP_EQUIPMENT + CHAR_TRUMPFLG, + CHAR_TRUMP_EFFECT, +#endif +#ifdef _CHAR_TITLE_STR_ + CHAR_TITLE_, +#endif + CHAR_DATAINTNUM, + +}CHAR_DATAINT; + +typedef enum { + CHAR_MODAI = CHAR_CHARM, /* ʸ ĤҰ */ + CHAR_VARIABLEAI = CHAR_LUCK, /* ʸ ߨ װƥ Ȼ */ + CHAR_SLOT = CHAR_DEFAULTPET, /* ë µ ʸ */ + CHAR_PETGETLV = CHAR_CHATVOLUME, /* ľì ʸ */ + CHAR_PUTPETTIME = CHAR_LOGINCOUNT, /* ʸ ľ */ + CHAR_MAILMODE = CHAR_RADARSTRENGTH, /* ʸ ˪ */ + CHAR_ALLOCPOINT = CHAR_LEVELUPPOINT, /* ìʧݼԻԻ̼(ʸ) */ + CHAR_PETMAILBUFINDEX = CHAR_GETPETCOUNT, /* ʸ(offmsg)߼index */ + CHAR_PETMAILIDLETIME = CHAR_SENDMAILCOUNT, /* ʸPмئ */ + CHAR_PETMAILFROMFLOOR = CHAR_DUELBATTLECOUNT, /* ë˪ݼ׷ʧ */ + CHAR_PETMAILFROMX = CHAR_DUELWINCOUNT, /* ë˪ݼ */ + CHAR_PETMAILFROMY = CHAR_DUELLOSECOUNT, /* ë˪ݼ */ + CHAR_PETMAILEFFECT = CHAR_DUELSTWINCOUNT, /* ʸPؼް į */ + CHAR_PETSENDMAILCOUNT = CHAR_TALKCOUNT, /* ʸëϷּ */ + CHAR_PETRANK = CHAR_LASTTIMESETLUCK, /* ʸ¼(ʸ ۨ߷޷¡ */ + CHAR_PETID = CHAR_DUELMAXSTWINCOUNT,/* ʸ */ + CHAR_PETFAMILY = CHAR_FMLEADERFLAG, // CoolFish: Family жǷΪػ + CHAR_PETENEMYID = CHAR_GAMBLENUM, +#ifdef _PET_VALIDITY + CHAR_PETVALIDITY = CHAR_VIPTIME, +#endif +}CHAR_PET; + + +typedef enum +{ + CHAR_NAME, + CHAR_OWNTITLE, + CHAR_USERPETNAME = CHAR_OWNTITLE, + CHAR_NPCARGUMENT, + CHAR_CDKEY = CHAR_NPCARGUMENT, + CHAR_OWNERCDKEY, + CHAR_OWNERCHARANAME, + CHAR_FMNAME, +#ifdef _UNIQUE_P_I + CHAR_UNIQUECODE, +#endif + +#ifdef _TEACHER_SYSTEM + CHAR_TEACHER_ID, // ʦʺ + CHAR_TEACHER_NAME, // ʦ +#endif +#ifdef _ITEM_SETLOVER + CHAR_LOVE, // ж + CHAR_LOVERID, // ʺ + CHAR_LOVERNAME, // +#endif + +#ifdef _GM_ITEM + CHAR_GMFUNCTION, // GM +#endif +#ifdef _NEW_NAME //Զƺ + CHAR_NEWNAME, +#endif + +#ifdef _LOTTERY_SYSTEM + CHAR_LOTTERY_VALUE, +#endif +#ifdef _POWER_UP + CHAR_POWER_UP, +#endif +#ifdef _VISUAL_BEATITUDE + CHAR_VB, +#endif + CHAR_DATACHARNUM, +}CHAR_DATACHAR; + +typedef enum +{ + CHAR_ISATTACK, + CHAR_ISATTACKED, + CHAR_ISOVER, + CHAR_ISOVERED, + CHAR_HAVEHEIGHT, + CHAR_ISVISIBLE, + CHAR_ISTRANSPARENT, + CHAR_ISFLYING, + CHAR_ISDIE, + CHAR_ISBIG, + CHAR_ISSHOWBATTLEMSG, + CHAR_ISPARTY, + CHAR_ISWARP, + CHAR_ISDUEL, + CHAR_ISPARTYCHAT, + CHAR_ISTRADECARD, + CHAR_ISTRADE, +#ifdef _CHANNEL_MODIFY + CHAR_ISTELL, //Ƶ + CHAR_ISFM, //Ƶ + CHAR_ISOCC, //ְҵƵ + CHAR_ISSAVE, //Ի濪 + CHAR_ISCHAT, // +#ifdef _THE_WORLD_SEND + CHAR_ISWORLD, //Ƶ +#endif +#ifdef _ONLINE_TALK_IP + CHAR_ISTALKIP, //ٱƵ +#endif + CHAR_AI_MOD, +#endif + CHAR_FLGNUM, +}CHAR_DATAFLG; + +#define CHAR_FS_PARTY (1 << 0) +#define CHAR_FS_DUEL (1 << 1) +#define CHAR_FS_PARTYCHAT (1 << 2) //Ƶ +#define CHAR_FS_TRADECARD (1 << 3) +#define CHAR_FS_TRADE (1 << 4) +#ifdef _CHANNEL_MODIFY +#define CHAR_FS_TELL (1 << 5) //Ƶ +#define CHAR_FS_FM (1 << 6) //Ƶ +#ifdef _VERSION_NEW +#define CHAR_FS_OCC (1 << 7) //ְҵƵ +#endif +#define CHAR_FS_SAVE (1 << 8) //Ի濪 +#define CHAR_FS_CHAT (1 << 9) //ҿ +#ifdef _THE_WORLD_SEND +#define CHAR_FS_WORLD (1 << 10) //Ƶ +#endif + +#ifdef _ONLINE_TALK_IP +#define CHAR_FS_TALKIP (1 << 12) //ٱƵ +#endif +#define CHAR_FS_AI (1 << 12) +#endif +typedef enum +{ + CHAR_WORKBATTLEMODE, + CHAR_WORKBATTLEINDEX, + CHAR_WORKBATTLESIDE, + CHAR_WORKBATTLECOM1, + CHAR_WORKBATTLECOM2, + CHAR_WORKBATTLECOM3, +#ifdef _PSKILL_MDFYATTACK + CHAR_WORKBATTLECOM4, +#endif + CHAR_WORKBATTLEFLG, + CHAR_WORKBATTLEWATCH, + + CHAR_WORKFIXEARTHAT, + CHAR_WORKFIXWATERAT, + CHAR_WORKFIXFIREAT, + CHAR_WORKFIXWINDAT, +#ifdef _PROFESSION_ADDSKILL + CHAR_WORKFIXEARTHAT_BOUNDARY, //ؽ 16λԪżǿٷֱ 16λԪŻغ + CHAR_WORKFIXWATERAT_BOUNDARY, //ˮ + CHAR_WORKFIXFIREAT_BOUNDARY, // + CHAR_WORKFIXWINDAT_BOUNDARY, // +#endif + CHAR_WORKMAXHP, + CHAR_WORKMAXMP, + + CHAR_WORKATTACKPOWER, + CHAR_WORKDEFENCEPOWER, + CHAR_WORKQUICK, + + CHAR_WORKFIXVITAL, + CHAR_WORKFIXSTR, + CHAR_WORKFIXTOUGH, + CHAR_WORKFIXDEX, + +#ifdef _ITEMSET5_TXT + CHAR_WORKFIXARRANGE, + CHAR_WORKARRANGEPOWER, + CHAR_WORKFIXSEQUENCE, + CHAR_WORKSEQUENCEPOWER, + CHAR_WORKATTACHPILE, + CHAR_WORKHITRIGHT, // +#endif +#ifdef _ITEMSET6_TXT + CHAR_WORKNEGLECTGUARD, +#endif + CHAR_WORKMODATTACK, + CHAR_WORKMODDEFENCE, + CHAR_WORKMODQUICK, + + CHAR_WORKMODCAPTURE, + CHAR_WORKMODCHARM, + + CHAR_WORKFIXCHARM, + CHAR_WORKFIXLUCK, + CHAR_WORKFIXAI, + CHAR_WORKFIXAVOID, + + CHAR_WORKDAMAGEABSROB, + CHAR_WORKDAMAGEREFLEC, + CHAR_WORKDAMAGEVANISH, + CHAR_WORKPOISON, + CHAR_WORKPARALYSIS, + CHAR_WORKSLEEP, + CHAR_WORKSTONE, + CHAR_WORKDRUNK, + CHAR_WORKCONFUSION, + CHAR_WORKWEAKEN, // vincent add _MAGIC_WEAKEN + CHAR_WORKDEEPPOISON, //綾 vincent add _MAGIC_DEEPPOISON + CHAR_WORKBARRIER, //ħ vincent add _MAGIC_BARRIER + CHAR_WORKNOCAST, //Ĭ vincent add _MAGIC_NOCAST + CHAR_WORKMODPOISON, + CHAR_WORKMODPARALYSIS, + CHAR_WORKMODSLEEP, + CHAR_WORKMODSTONE, + CHAR_WORKMODDRUNK, + CHAR_WORKMODCONFUSION, + CHAR_WORKMODWEAKEN, + CHAR_WORKMODDEEPPOISON, + CHAR_WORKMODBARRIER, //ħ + CHAR_WORKMODNOCAST, //Ĭ + CHAR_WORKMODCRITICAL, //һɱ + CHAR_WORKULTIMATE, + CHAR_WORKPARTYMODE, + CHAR_WORKTRADEMODE, /* ģʽ + * 0: CHAR_TRADE_FREE :ɽ + * 1: CHAR_TRADE_SENDING: + * 2: CHAR_TRADE_TRADING: + * 3: CHAR_TRADE_LOCK : + */ + CHAR_WORKPARTYINDEX1, + CHAR_WORKPARTYINDEX2, + CHAR_WORKPARTYINDEX3, + CHAR_WORKPARTYINDEX4, + CHAR_WORKPARTYINDEX5, + CHAR_WORKOBJINDEX, + CHAR_WORKWALKSTARTSEC, + CHAR_WORKWALKSTARTMSEC, + CHAR_WORKLOOPSTARTSEC, + CHAR_WORKLOOPSTARTMSEC, + CHAR_WORKLOOPSTARTSECAB, + CHAR_WORKLOOPSTARTMSECAB, + CHAR_WORKLASTATTACKCHARAINDEX, + CHAR_WORKEVENTTYPE, + CHAR_WORKGETEXP, + CHAR_WORKMODCAPTUREDEFAULT, + CHAR_WORKACTION, + CHAR_WORKFD, + CHAR_WORKFLG, + CHAR_WORKGMLEVEL, + CHAR_NPCWORKINT1, + CHAR_NPCWORKINT2, + CHAR_NPCWORKINT3, + CHAR_NPCWORKINT4, + CHAR_NPCWORKINT5, + CHAR_NPCWORKINT6, + CHAR_NPCWORKINT7, + CHAR_NPCWORKINT8, + CHAR_NPCWORKINT9, + CHAR_NPCWORKINT10, + CHAR_NPCWORKINT11, +#ifdef _PETRACE + CHAR_NPCWORKINT12, +#endif + CHAR_NPCWORKINT13, + CHAR_WORKWARPCHECK, + CHAR_TENSEICHECKED, + CHAR_WORKFMINDEXI, // index + CHAR_WORKFMCHANNEL, // Ƶ + CHAR_WORKFMCHANNELQUICK, + CHAR_WORKFMFLOOR, // ݵͼ + CHAR_WORKFMDP, // ģֵ + CHAR_WORKFMPKFLAG, // ǷУ 1:Yes + CHAR_WORKFMSETUPFLAG, // Ƿʽ + CHAR_WORKFMMANINDEX, // FMWARPMAN Index + CHAR_WORKFMCHARINDEX, // Ա index + CHAR_WORKBATTLEFLAG, // -1(ս)1(ս) + + CHAR_WORK_PET0_STAT, + CHAR_WORK_PET1_STAT, + CHAR_WORK_PET2_STAT, + CHAR_WORK_PET3_STAT, + CHAR_WORK_PET4_STAT, + + CHAR_WORKLOGINTIME, // ҵʱ + CHAR_WORKTALKCOUNT, + CHAR_WORKTALKTIME, + CHAR_WORKPETFOLLOW, // +#ifdef _PETFOLLOW_NEW_ + CHAR_WORKPETFOLLOW1, + CHAR_WORKPETFOLLOW2, + CHAR_WORKPETFOLLOW3, + CHAR_WORKPETFOLLOW4, +#endif + CHAR_WORKPETFALL, // ս + CHAR_WORKLEADERCHANGE, // 峤λindex +#ifdef _EQUIT_DEFMAGIC + CHAR_EQUITDEFMAGIC_E, + CHAR_EQUITDEFMAGIC_WA, + CHAR_EQUITDEFMAGIC_F, + CHAR_EQUITDEFMAGIC_WI, + CHAR_EQUITQUIMAGIC, +#endif +#ifdef _EQUIT_RESIST + CHAR_WORKEQUITFIRE, //װ + CHAR_WORKEQUITTHUNDER,//װ + CHAR_WORKEQUITICE,//װ + CHAR_WORKEQUITWEAKEN,//װ + CHAR_WORKEQUITBARRIER,//װħ + CHAR_WORKEQUITNOCAST,//װĬ + CHAR_WORKEQUITFALLRIDE,//װ +#endif +#ifdef _PETMAIL_DEFNUMS + CHAR_PETMAILNUMS, + CHAR_PETMAILSENDTIME, +#endif +#ifdef _ITEM_METAMO + CHAR_WORKITEMMETAMO, +#endif +#ifdef _ADD_DEAMGEDEFC + CHAR_WORKOTHERDMAGE, + CHAR_WORKOTHERDEFC, +#endif + +#ifdef _LOSE_FINCH_ + CHAR_WORKSPETRELIFE, //︴ +#endif + +#ifdef _CHIKULA_STONE + CHAR_WORKCHIKULAHP, + CHAR_WORKCHIKULAMP, +#endif +#ifdef _PETSKILL_SETDUCK + CHAR_MYSKILLDUCKPOWER, + CHAR_MYSKILLDUCK, + CHAR_MYSKILLSTRPOWER, + CHAR_MYSKILLSTR, + CHAR_MYSKILLTGHPOWER, + CHAR_MYSKILLTGH, + CHAR_MYSKILLDEXPOWER, + CHAR_MYSKILLDEX, + CHAR_MAGICPETMP, +#endif + CHAR_SKILLSTRPOWER, + CHAR_SKILLTGHPOWER, + CHAR_SKILLDEXPOWER, +#ifdef _NPC_MAKEPAIR + CHAR_MYPAIRINDEX, + CHAR_MYPAIRFLG, + CHAR_MYPAIRCODE, +#endif +#ifdef _OTHER_MAGICSTAUTS + CHAR_DEFMAGICSTATUS, +#ifdef _MAGIC_SUPERWALL + CHAR_MAGICSUPERWALL, +#endif + CHAR_OTHERSTATUSNUMS, +#endif +#ifdef _NPCCHANGE_PLAYERIMG + CHAR_WORKNPCMETAMO, +#endif + CHAR_PickAllPet, +#ifdef _DROPSTAKENEW + CHAR_WORKSTAKEFLAG, + CHAR_WORKSTAKETYPE1, + CHAR_WORKSTAKETYPE2, + CHAR_WORKSTAKETYPE3, + CHAR_WORKSTAKETYPE4, + CHAR_WORKSTAKETYPE5, +#endif + + CHAR_WORKTOXICATION, + +#ifdef _SUIT_ITEM + CHAR_WORKSUITITEM, + CHAR_WORKROUNDHP, + CHAR_WORKROUNDMP, + CHAR_WORKSUITVIT, + CHAR_WORKSUITSTR, + CHAR_WORKSUITTGH, + CHAR_WORKSUITDEX, + CHAR_WORKSUITMODSTR, +#ifdef _SUIT_ADDENDUM + CHAR_WORKRESIST, //쳣 + CHAR_WORKCOUNTER,// + CHAR_WORKMPOWER, //ǿʦħ( Ӱķ:ɽȪ ĩ ǹ Ѫ Ѫ һѪ ) +#endif +#ifdef _SUIT_TWFWENDUM + CHAR_WORK_EA,// + CHAR_WORK_WR,//ˮ + CHAR_WORK_FI,// + CHAR_WORK_WI,// +#endif +#ifdef _SUIT_ADDPART3 + CHAR_WORKDUCKPOWER,//װر + CHAR_WORKRENOCAST, //Ĭ + CHAR_WORKSUITSTR_P,// λΪ% + CHAR_WORKSUITTGH_P,// λΪ% + CHAR_WORKSUITDEX_P,// λΪ% +#endif +#ifdef _SUIT_ADDPART4 + CHAR_SUITPOISON, //װ + CHAR_WORKMPOWER2, //CHAR_WORKMPOWERͬ + CHAR_WORKUNMPOWER, //ֿʦħ( Ӱķ:ɽȪ ĩ ǹ Ѫ Ѫ һѪ ) +#endif +#endif//_SUIT_ITEM + +#ifdef _IMPRECATE_ITEM + CHAR_WORKHURTMP, //˺ MP + CHAR_WORKWISHESHP, //ף hp + CHAR_WORKWISHESMP, //ף MP + CHAR_WORKIMPRECATENUM1, + CHAR_WORKIMPRECATENUM2, + CHAR_WORKIMPRECATENUM3, +#endif +#ifdef _STATUS_WATERWORD + CHAR_WORKMAPFLOORTYPE, + CHAR_WORKSTATUSWATER, +#endif +#ifdef _BATTLENPC_WARP_PLAYER + CHAR_WORKTURN, +#endif +#ifdef _MIND_ICON + CHAR_MIND_NUM, +#endif +#ifdef _PLAYER_EFFECT + CHAR_PLAYER_EFFECT, +#endif +#ifdef _MO_PLAYER_EFFECT + CHAR_PLAYER_EFFECT_PRIORITY, + CHAR_PLAYER_EFFECT_PET, + CHAR_PLAYER_EFFECT_ITEM, +#endif +#ifdef FAMILY_MANOR_ + CHAR_PLAYER_EFFECT_MANOR, +#endif +#ifdef _ITEM_CRACKER + CHAR_WORKITEM_CRACKER, +#endif +#ifdef _ITEM_ADDEXP //vincent + CHAR_WORKITEM_ADDEXP, + CHAR_WORKITEM_ADDEXPTIME, +#endif +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + CHAR_WORKHEROFLOOR, +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + CHAR_ENCOUNT_FIX, // + CHAR_ENCOUNT_NUM, + CHAR_WORK_F_PROFICIENCY,// + CHAR_WORK_I_PROFICIENCY,// + CHAR_WORK_T_PROFICIENCY,// + CHAR_WORK_F_RESIST, // + CHAR_WORK_I_RESIST, // + CHAR_WORK_T_RESIST, // 翹 + CHAR_MYSKILLHIT, // + CHAR_MYSKILLHIT_NUM, + CHAR_WORKDIZZY, // ѣ + CHAR_WORKMODDIZZY, + CHAR_WORKENTWINE, // + CHAR_WORKMODENTWINE, + CHAR_WORKTRAP, // + CHAR_WORKMODTRAP, + CHAR_WORKDRAGNET, // ޵ + CHAR_WORKMODDRAGNET, +#ifdef _PROFESSION_ADDSKILL + //***********ע:λòɸ************* + CHAR_WORKICECRACK, // + CHAR_WORKICECRACK2, // Ŵ2 + CHAR_WORKICECRACK3, // Ŵ3 + CHAR_WORKICECRACK4, // Ŵ4 + CHAR_WORKICECRACK5, // Ŵ5 + CHAR_WORKICECRACK6, // Ŵ6 + CHAR_WORKICECRACK7, // Ŵ7 + CHAR_WORKICECRACK8, // Ŵ8 + CHAR_WORKICECRACK9, // Ŵ9 + CHAR_WORKICECRACK10, // Ŵ10 + CHAR_WORKMODICECRACK, + CHAR_WORKMODICECRACK2, + CHAR_WORKMODICECRACK3, + CHAR_WORKMODICECRACK4, + CHAR_WORKMODICECRACK5, + CHAR_WORKMODICECRACK6, + CHAR_WORKMODICECRACK7, + CHAR_WORKMODICECRACK8, + CHAR_WORKMODICECRACK9, + CHAR_WORKMODICECRACK10, + //***************************************** +#else + CHAR_WORKICECRACK, // + CHAR_WORKMODICECRACK, +#endif //_PROFESSION_ADDSKILL + + CHAR_WORKOBLIVION, // + CHAR_WORKMODOBLIVION, + CHAR_WORKICEARROW, // + CHAR_WORKMODICEARROW, + CHAR_WORKBLOODWORMS, // Ѫ + CHAR_WORKMODBLOODWORMS, + CHAR_WORKBLOODWORMSID, + CHAR_WORKSIGN, // һѪ + CHAR_WORKMODSIGN, + CHAR_WORKSIGNID, + CHAR_WORK_P_DUCK, // ر + CHAR_WORKMOD_P_DUCK, + CHAR_WORK_WEAPON, // ר + CHAR_WORKMOD_WEAPON, + CHAR_WORK_FOCUS, // רעս + CHAR_WORKMOD_FOCUS, + CHAR_WORKINSTIGATE, // + CHAR_WORKMODINSTIGATE, + CHAR_WORK_F_ENCLOSE, // + CHAR_WORK_I_ENCLOSE, // + CHAR_WORK_T_ENCLOSE, // ׸ + CHAR_WORKMOD_F_ENCLOSE, + CHAR_WORKMOD_I_ENCLOSE, + CHAR_WORKMOD_T_ENCLOSE, + CHAR_WORK_F_ENCLOSE_2, // + CHAR_WORK_I_ENCLOSE_2, // + CHAR_WORK_T_ENCLOSE_2, // ׸ + CHAR_WORKMOD_F_ENCLOSE_2, + CHAR_WORKMOD_I_ENCLOSE_2, + CHAR_WORKMOD_T_ENCLOSE_2, + CHAR_WORKRESIST_F, // + CHAR_WORKRESIST_I, // + CHAR_WORKRESIST_T, // ׿ +#ifdef _PROFESSION_ADDSKILL + CHAR_WORKERSIST_F_I_T, // ׿ + CHAR_WORKANNEX, // + CHAR_WORKWATER, //ˮ + CHAR_WORKFEAR, //־ + CHAR_DOOMTIME, //ĩռ(ǹ) + CHAR_WORK_com1, + CHAR_WORK_toNo, + CHAR_WORK_mode, + CHAR_WORK_skill_level, + CHAR_WORK_array, +#endif + CHAR_WORKMODRESIST_F, // ԰ٷֱֵ + CHAR_WORKMODRESIST_I, // ԰ٷֱֵ + CHAR_WORKMODRESIST_T, // ׿԰ٷֱֵ +#endif + +#ifdef _MAGICSTAUTS_RESIST + CHAR_MAGICFIRE, //𿹾 + CHAR_MAGICTHUNDER,//翹 + CHAR_MAGICICE,// +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ + CHAR_WORKSARS, + CHAR_WORKMODSARS, +#endif + +#ifdef _PETSKILL_ACUPUNCTURE + CHAR_WORKACUPUNCTURE, +#endif +#ifdef _PETSKILL_RETRACE + CHAR_WORKRETRACE, +#endif + +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ + CHAR_WORKCHATROOMTYPE , + CHAR_WORKCHATROOMNUM , +#endif + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + CHAR_WORK_F_SUIT, + CHAR_WORK_I_SUIT, + CHAR_WORK_T_SUIT, +#endif + +#ifdef _PETSKILL_BECOMEFOX + CHAR_WORKFOXROUND, //غ +#endif + + CHAR_WORKSTANDBYPET, // Robin add +#ifdef _STREET_VENDOR + CHAR_WORKSTREETVENDOR, // ̯״̬ -1:ûڰ̯,Ҳûڰ̯;1:̯;2:ڽ;3:̯ + CHAR_WORKSTREETVENDOR_WHO, // ˭ҽ +#endif + +#ifdef _ANGEL_SUMMON + CHAR_WORKMISSION, + CHAR_WORKANGELMODE, +#endif +#ifdef _MAP_TIME + CHAR_WORK_MAP_TIME, // ͼ +#endif +#ifdef _PETSKILL_LER + CHAR_WORK_RELIFE, // ׶ +#endif +#ifdef _TEACHER_SYSTEM + CHAR_WORK_GET_TEACHER_FAME, // ʦ쵼 +#endif + + CHAR_WORKSKYWALKER, // GM?? + + CHAR_WORKLASTMERGETIME, // ϳʱ + +#ifdef _FONT_SIZE + CHAR_WORKFONTSIZE, // +#endif + +#ifdef _TIME_TICKET + CHAR_WORKTICKETTIME, + CHAR_WORKTICKETTIMESTART, +#endif + CHAR_WORK_TEMP_FLOOR, // ťҡš + CHAR_WORK_TEMP_X_Y, // ťҡXYб (w X б, w Y б) + + CHAR_WORKDEBUGMODE, // ģʽ + + CHAR_WORKITEMINDEX, // Ʒ + + CHAR_WORKTOITEMINDEX, // Ʒ + +#ifdef _NEW_STREET_VENDOR + CHAR_WORKSTREETVENDORTYPE, // ̯ +#endif + +#ifdef _TALK_CHECK + CHAR_WORK_TALKCHECK, // ˵֤ +#endif +#ifdef _STRENGTH_PETSKILL + CHAR_WORK_STRENGTH, +#endif +#ifdef _LOSTLOST_PETSKILL + CHAR_WORK_LOSTLOST, +#endif +#ifdef _BATTLE_PK_TYPE + CHAR_WORK_BATTLEPKTYPE, +#endif +#ifdef _THE_WORLD_SEND + CHAR_WORKWORLDSENDTIME, +#endif + CHAR_WORK_LISTPAGE, +#ifdef _AUTO_PK + CHAR_WORK_AUTOPK, // ԶPK + CHAR_WORK_AUTOPK_DEAD, // +#endif + +#ifdef _BATTLE_PK + CHAR_WORK_BATTLEPK, +#endif +#ifdef _ONLINE_TIME + CHAR_WORK_LOGIN_TIME, +#endif +#ifdef _JZ_NEWSCRIPT_LUA + CHAR_WORKNPCTYPE, +#endif +#ifdef _OFFLINE_SYSTEM + CHAR_WORK_OFFLINE, +#endif +#ifdef _SPECIAL_COUNTER + CHAR_WORK_COUNTER , +#endif +#ifdef _SPECIAL_TIMER + CHAR_WORK_TIMER, +#endif +#ifdef _RECORD_IP + CHAR_WORK_RECORD_IP, +#endif + CHAR_WORK_SHOWBATTLETIME, + +#ifdef _BATTLE_BOUT_TIME + CHAR_BATTLE_BOUT_TIME, +#endif + + +#ifdef _FIX_SAVE_CHAR + CHAR_WORK_SAVE_CHAR, +#endif +#ifdef _BATTLE_OVER_STAR_TIME + CHAR_WORKDBATTLETIME, +#endif + CHAR_WORKDBATTLEESCAPE, + +#ifdef _NEWCLISETSERVID + CHAR_WORK_SERVID, +#endif + + CHAR_WORK_X, + CHAR_WORK_Y, + CHAR_WORK_W, + CHAR_WORK_DIR, +#ifdef _CANCEL_STREET_VENDOR + CHAR_WORK_STREET_VENDOR_TIME, +#endif +#ifdef _SINGLE_ONLINE + CHAR_WORK_SINGLE_ONLINE, +#endif +#ifdef _PETSKILL_NEW_PASSIVE + CHAR_WORKPASSIVE_DUCK, // + CHAR_WORKPASSIVE_ACURATE, // + CHAR_WORKPASSIVE_CRITICAL, // + CHAR_WORKPASSIVE_COUNTER, // + CHAR_WORKPASSIVE_MULTIPLE, // +#endif +#ifdef _JZ_NEWSCRIPT_LUA + CHAR_LUASAVE_WORKINT_1, + CHAR_LUASAVE_WORKINT_2, + CHAR_LUASAVE_WORKINT_3, +#endif +#ifdef _NPC_EVENT_NOTICE + CHAR_WORK_NOTICE, +#endif +#ifdef _MO_LUA_RESIST + CHAR_WORK_RESIST_POISON, + CHAR_WORK_RESIST_PARALYSIS, + CHAR_WORK_RESIST_SLEEP, + CHAR_WORK_RESIST_STONE, + CHAR_WORK_RESIST_DRUNK, + CHAR_WORK_RESIST_CONFUSION, + CHAR_WORK_RESIST_WEAKEN, + CHAR_WORK_RESIST_DEEPPOISON, + CHAR_WORK_RESIST_BARRIER, + CHAR_WORK_RESIST_NOCAST, +#endif + CHAR_WATCHBATTLETYPE, +#ifdef _LOCK_PET_ITEM + CHAR_WORK_LOCK_PET_ITEM, +#endif + CHAR_WORKDATAINTNUM, + + CHAR_WORKENCOUNTPROBABILITY_MIN = CHAR_NPCWORKINT1, + CHAR_WORKENCOUNTPROBABILITY_MAX = CHAR_NPCWORKINT2, + CHAR_WORK_TOHELOS_CUTRATE = CHAR_NPCWORKINT3, + CHAR_WORK_TOHELOS_COUNT = CHAR_NPCWORKINT4, + CHAR_WORKSHOPRELEVANT = CHAR_NPCWORKINT5, + CHAR_WORKSHOPRELEVANTSEC = CHAR_NPCWORKINT6, + CHAR_WORKSHOPRELEVANTTRD = CHAR_NPCWORKINT7, + CHAR_WORKTRADER = CHAR_NPCWORKINT8, + CHAR_WORKEFFECT = CHAR_NPCWORKINT9, + CHAR_WORKRENAMEITEMNUM = CHAR_NPCWORKINT10, + CHAR_WORKRENAMEITEMINDEX = CHAR_NPCWORKINT5, + CHAR_WORKPLAYERINDEX = CHAR_NPCWORKINT1, + CHAR_WORKTACTICS = CHAR_NPCWORKINT2, + CHAR_WORKPETFOLLOWMODE = CHAR_NPCWORKINT3, + CHAR_WORKPETFOLLOWCOUNT = CHAR_NPCWORKINT4, + CHAR_WORK_PETFLG = CHAR_NPCWORKINT1, + CHAR_WORKGENERATEINDEX = CHAR_NPCWORKINT1, + CHAR_WORKDOORCLOSETIME = CHAR_NPCWORKINT1, + CHAR_WORKDOORSWITCHCOUNT = CHAR_NPCWORKINT2, + CHAR_WORKDOOROPENG = CHAR_NPCWORKINT3, + CHAR_WORKDOORCLOSEG = CHAR_NPCWORKINT4, + CHAR_WORKDOORSOONFLG = CHAR_NPCWORKINT5, + CHAR_WORKDOORPASSFLG = CHAR_NPCWORKINT6, + CHAR_WORKDOORKEYITEMID = CHAR_NPCWORKINT7, + CHAR_WORKDOORSWITCHCURRENT = CHAR_NPCWORKINT8, + CHAR_WORKDOORORIGINALGRAPHIC = CHAR_NPCWORKINT9, + CHAR_WORKDOOREXPIRETIME = CHAR_NPCWORKINT10, + CHAR_WORKOLDMANID = CHAR_NPCWORKINT1, + CHAR_WORKSHOPCLIENTINDEX = CHAR_NPCWORKINT1, + CHAR_WORKDENGONMAXID = CHAR_NPCWORKINT1, + +}CHAR_WORKDATAINT; + + +enum{ + WORKFLG_DEBUGMODE = ( 1 << 0 ), + WORKFLG_MICMODE = ( 2 << 0 ), +#ifdef _SUPER_FLOOR_MIC + WORKFLG_SUPERMICMODE = ( 3 << 0 ) +#endif +}; + +typedef enum +{ + CHAR_INITFUNC, + CHAR_FIRSTFUNCTION = CHAR_INITFUNC, + CHAR_WALKPREFUNC, + CHAR_WALKPOSTFUNC, + CHAR_PREOVERFUNC, + CHAR_POSTOVERFUNC, + CHAR_WATCHFUNC, + CHAR_LOOPFUNC, + CHAR_DYINGFUNC, + CHAR_TALKEDFUNC, + CHAR_PREATTACKEDFUNC, + CHAR_POSTATTACKEDFUNC, + CHAR_OFFFUNC, + CHAR_LOOKEDFUNC, + CHAR_ITEMPUTFUNC, + CHAR_SPECIALTALKEDFUNC, + CHAR_WINDOWTALKEDFUNC, +#ifdef _USER_CHARLOOPS + CHAR_LOOPFUNCTEMP1, + CHAR_LOOPFUNCTEMP2, + CHAR_BATTLEPROPERTY, +#endif +#ifdef _ALLBLUES_LUA + CHAR_OVERLAPEDFUNC, + CHAR_BATTLEOVERDFUNC, +#ifdef _ALLBLUES_LUA_1_4 + CHAR_LOGINOUTFUNC, +#endif +#ifdef _ALLBLUES_LUA_1_9 + CHAR_BATTLESETFUNC, +#endif +#endif + CHAR_LASTFUNCTION, + CHAR_FUNCTABLENUM = CHAR_LASTFUNCTION, +}CHAR_FUNCTABLE; + +typedef enum +{ + CHAR_WORKWALKARRAY, + CHAR_NPCWORKCHAR1, + CHAR_NPCWORKCHAR2, + CHAR_NPCWORKCHAR3, + CHAR_NPCWORKCHAR4, + CHAR_NPCWORKCHAR5, + CHAR_NPCWORKCHAR6, +#ifdef _ANGEL_SUMMON + CHAR_WORKHEROINFO, +#endif +#ifdef _STREET_VENDOR + CHAR_STREETVENDOR_NAME, +#endif + +#ifdef _NEWCLISETMAC + CHAR_WORK_MAC, +#endif + + CHAR_WORKDATACHARNUM, + CHAR_WORKBATTLE_TACTICSOPTION = CHAR_NPCWORKCHAR1, +#ifdef _BATTLENPC_WARP_PLAYER + CHAR_WORKBATTLE_ACT_CONDITION = CHAR_NPCWORKCHAR2, +#endif + CHAR_WORKDOORPASSWD = CHAR_NPCWORKCHAR1, + CHAR_WORKDOORNAME = CHAR_NPCWORKCHAR2, + CHAR_WORKDOORGOLDLIMIT = CHAR_NPCWORKCHAR3, + CHAR_WORKDOORWEEK = CHAR_NPCWORKCHAR4, + CHAR_WORKDOORHOUR = CHAR_NPCWORKCHAR5, + CHAR_WORKDOORMINUTE = CHAR_NPCWORKCHAR6, + CHAR_WORKDOORTITLE = CHAR_NPCWORKCHAR6, + CHAR_WORKDOORMANDOORNAME = CHAR_NPCWORKCHAR1, + CHAR_TIME1, + CHAR_TIME2 = CHAR_NPCWORKCHAR6, + +}CHAR_WORKDATACHAR; + + +typedef enum +{ + CHAR_IMAGETYPE_GIRL, + CHAR_IMAGETYPE_BOY, + CHAR_IMAGETYPE_CHILDBOY, + CHAR_IMAGETYPE_CHILDGIRL, + CHAR_IMAGETYPE_MAN, + CHAR_IMAGETYPE_WOMAN, + CHAR_IMAGETYPE_OLDMAN, + CHAR_IMAGETYPE_DOG, + CHAR_IMAGETYPENUM +}CHAR_ImageType; + + +#define CHAR_P_STRING_HP ( 1 << 1 ) // 0x00000002 +#define CHAR_P_STRING_MAXHP ( 1 << 2 ) // 0x00000004 +#define CHAR_P_STRING_MP ( 1 << 3 ) // 0x00000008 +#define CHAR_P_STRING_MAXMP ( 1 << 4 ) // 0x00000010 +#define CHAR_P_STRING_VITAL ( 1 << 5 ) +#define CHAR_P_STRING_STR ( 1 << 6 ) +#define CHAR_P_STRING_TOUGH ( 1 << 7 ) +#define CHAR_P_STRING_DEX ( 1 << 8 ) +#define CHAR_P_STRING_EXP ( 1 << 9 ) +#define CHAR_P_STRING_NEXTEXP ( 1 << 10 ) +#define CHAR_P_STRING_LV ( 1 << 11 ) +#define CHAR_P_STRING_ATK ( 1 << 12 ) +#define CHAR_P_STRING_DEF ( 1 << 13 ) +#define CHAR_P_STRING_QUICK ( 1 << 14 ) +#define CHAR_P_STRING_CHARM ( 1 << 15 ) +#define CHAR_P_STRING_LUCK ( 1 << 16 ) +#define CHAR_P_STRING_EARTH ( 1 << 17 ) +#define CHAR_P_STRING_WATER ( 1 << 18 ) +#define CHAR_P_STRING_FIRE ( 1 << 19 ) +#define CHAR_P_STRING_WIND ( 1 << 20 ) +#define CHAR_P_STRING_GOLD ( 1 << 21 ) +#define CHAR_P_STRING_TITLE ( 1 << 22 ) +#define CHAR_P_STRING_DUELPOINT ( 1 << 23 ) +#define CHAR_P_STRING_TRANSMIGRATION ( 1 << 24 ) +#define CHAR_P_STRING_NAME ( 1 << 25 ) +#define CHAR_P_STRING_OWNTITLE ( 1 << 26 ) +#define CHAR_P_STRING_RIDEPET ( 1 << 27 ) // 0x08000000 +#define CHAR_P_STRING_LEARNRIDE ( 1 << 28 ) // 0x10000000 +#define CHAR_P_STRING_BASEBASEIMAGENUMBER ( 1 << 29 ) // 0x20000000 +//#define CHAR_P_STRING_PKDP ( 1 << 30 ) +//#ifdef _CHAR_PROFESSION +//#define CHAR_P_STRING_PROFESSION ( 1 << 30 ) +//#endif +#define CHAR_P_STRING_SKYWALKER ( 1 << 30 ) // 0x40000000 +#define CHAR_P_STRING_DEBUGMODE ( 1 << 31 ) // 0x80000000 +#define CHAR_P_STRING_CHARSINGMODE ( 1 << 31 ) // 0x80000000 + + + +#define CHAR_N_STRING_OBJINDEX ( 1 << 1 ) +#define CHAR_N_STRING_LV ( 1 << 2 ) +#define CHAR_N_STRING_MAXHP ( 1 << 3 ) +#define CHAR_N_STRING_HP ( 1 << 4 ) +#define CHAR_N_STRING_MP ( 1 << 5 ) +#define CHAR_N_STRING_NAME ( 1 << 6 ) + +#define CHAR_K_STRING_BASEIMAGENUMBER ( 1 << 1 ) +#define CHAR_K_STRING_HP ( 1 << 2 ) +#define CHAR_K_STRING_MAXHP ( 1 << 3 ) +#define CHAR_K_STRING_MP ( 1 << 4 ) +#define CHAR_K_STRING_MAXMP ( 1 << 5 ) +#define CHAR_K_STRING_EXP ( 1 << 6 ) +#define CHAR_K_STRING_NEXTEXP ( 1 << 7 ) +#define CHAR_K_STRING_LV ( 1 << 8 ) +#define CHAR_K_STRING_ATK ( 1 << 9 ) +#define CHAR_K_STRING_DEF ( 1 << 10 ) +#define CHAR_K_STRING_QUICK ( 1 << 11 ) +#define CHAR_K_STRING_AI ( 1 << 12 ) +#define CHAR_K_STRING_EARTH ( 1 << 13 ) +#define CHAR_K_STRING_WATER ( 1 << 14 ) +#define CHAR_K_STRING_FIRE ( 1 << 15 ) +#define CHAR_K_STRING_WIND ( 1 << 16 ) +#define CHAR_K_STRING_SLOT ( 1 << 17 ) +#define CHAR_K_STRING_CHANGENAMEFLG ( 1 << 18 ) +#define CHAR_K_STRING_NAME ( 1 << 19 ) +#define CHAR_K_STRING_USERPETNAME ( 1 << 20 ) +#ifdef _PETCOM_ +#define CHAR_K_STRING_YHP ( 1 << 21 ) +#define CHAR_K_STRING_YATK ( 1 << 22 ) +#define CHAR_K_STRING_YDEF ( 1 << 23 ) +#define CHAR_K_STRING_YQUICK ( 1 << 24 ) +#define CHAR_K_STRING_YLV ( 1 << 25 ) +#endif + +typedef struct { + int indexOfPet[CHAR_MAXPETHAVE]; + int indexOfPetskill[CHAR_MAXPETSKILLHAVE]; +}CHAR_UNIONTABLE; + +typedef struct tagChar +{ + BOOL use; + + int data[CHAR_DATAINTNUM]; + STRING128 string[CHAR_DATACHARNUM]; + char flg[(CHAR_FLGNUM%(sizeof(char)*8)) + ? (CHAR_FLGNUM/(sizeof(char)*8))+1 + : (CHAR_FLGNUM/(sizeof(char)*8))]; + int indexOfExistItems[CHAR_MAXITEMHAVE]; + int indexOfExistPoolItems[CHAR_MAXPOOLITEMHAVE]; + +#ifdef _CHAR_POOLITEM + int *indexOfExistDepotItems; +#endif +#ifdef _CHAR_POOLPET + int *indexOfExistDepotPets; +#endif + + CHAR_HaveSkill haveSkill[CHAR_SKILLMAXHAVE]; + int indexOfHaveTitle[CHAR_TITLEMAXHAVE]; + ADDRESSBOOK_entry addressBook[ADDRESSBOOK_MAX]; + CHAR_UNIONTABLE unionTable; + int indexOfPoolPet[CHAR_MAXPOOLPETHAVE]; + STRING32 charfunctable[CHAR_FUNCTABLENUM]; + int workint[CHAR_WORKDATAINTNUM]; + STRING64 workchar[CHAR_WORKDATACHARNUM]; + int CharMakeSequenceNumber; + void* functable[CHAR_FUNCTABLENUM]; +#ifdef _STREET_VENDOR + StreetVendor_t StreetVendor[MAX_SELL_ITEM]; +#endif +#ifdef _ALLBLUES_LUA + lua_State *lua[CHAR_FUNCTABLENUM]; + char *luafunctable[CHAR_FUNCTABLENUM]; +#endif +#ifdef _JZ_NEWSCRIPT_LUA + STRING32 lua_charfunctable[CHAR_FUNCTABLENUM]; + + void* sur_functable[CHAR_FUNCTABLENUM]; + STRING32 sur_charfunctable[CHAR_FUNCTABLENUM]; +#endif +}Char; + + +#define CHAR_CHECKINDEX( index) _CHAR_CHECKINDEX( __FILE__, __LINE__, index) +INLINE BOOL _CHAR_CHECKINDEX( char *file, int line, int index); +#define CHAR_CHECKITEMINDEX( charaindex, iindex) _CHAR_CHECKITEMINDEX( __FILE__, __LINE__, charaindex, iindex) +INLINE BOOL _CHAR_CHECKITEMINDEX( char *file, int line, int charaindex, int iindex ); +#define CHAR_CHECKPETINDEX( petindex) _CHAR_CHECKPETINDEX( __FILE__, __LINE__, petindex ) +INLINE BOOL _CHAR_CHECKPETINDEX( char *file, int line, int petindex ); +#define CHAR_CHECKPOOLPETINDEX( petindex) _CHAR_CHECKPOOLPETINDEX( __FILE__, __LINE__, petindex ) +INLINE BOOL _CHAR_CHECKPOOLPETINDEX( char *file, int line, int petindex ); +#define CHAR_CHECKPETSKILLINDEX( havepetskillindex) _CHAR_CHECKPETSKILLINDEX( __FILE__, __LINE__, havepetskillindex) +INLINE BOOL _CHAR_CHECKPETSKILLINDEX( char *file, int line, int havepetskillindex ); + +//INLINE int CHAR_getInt( int index , CHAR_DATAINT element); + +#define CHAR_getInt( index , element) _CHAR_getInt( __FILE__, __LINE__, index , element) +INLINE int _CHAR_getInt( char *file, int line, int index ,CHAR_DATAINT element); +#define CHAR_setInt( index , element, data) _CHAR_setInt( __FILE__, __LINE__, index , element, data) +INLINE int _CHAR_setInt( char *file, int line, int index ,CHAR_DATAINT element, int data); +#ifdef _FIX_SETWORKINT +#define CHAR_getWorkInt( index , element) _CHAR_getWorkInt( __FILE__, __LINE__, index , element) +INLINE int _CHAR_getWorkInt( char *file, int line, int index ,CHAR_WORKDATAINT element); +#define CHAR_setWorkInt( index, element, data) _CHAR_setWorkInt( __FILE__, __LINE__, index , element, data) +INLINE int _CHAR_setWorkInt( char *file, int line, int index ,CHAR_WORKDATAINT element, int data); +#else +INLINE int CHAR_setWorkInt( int index ,CHAR_WORKDATAINT element, int data); +#endif +#define CHAR_getChar( index, elem) _CHAR_getChar( __FILE__, __LINE__, index, elem) +INLINE char* _CHAR_getChar( char *file, int line, int index ,CHAR_DATACHAR element ); +#define CHAR_setChar( index, elem, n) _CHAR_setChar( __FILE__, __LINE__, index, elem, n) +INLINE BOOL _CHAR_setChar( char *file, int line, int index ,CHAR_DATACHAR element, const char* new ); +#define CHAR_getFlg( index, elem) _CHAR_getFlg( __FILE__, __LINE__, index, elem) +INLINE BOOL _CHAR_getFlg( char *file, int line, int index ,CHAR_DATAFLG element ); +#define CHAR_setFlg( index, elem, n) _CHAR_setFlg( __FILE__, __LINE__, index, elem, n) +INLINE BOOL _CHAR_setFlg( char *file, int line, int index , CHAR_DATACHAR element, int newdata ); +#define CHAR_getWorkChar( index, elem) _CHAR_getWorkChar( __FILE__, __LINE__, index, elem) +INLINE char * _CHAR_getWorkChar( char *file, int line, int index, CHAR_WORKDATACHAR element ); +#define CHAR_setWorkChar( index, elem, n) _CHAR_setWorkChar( __FILE__, __LINE__, index, elem, n) +INLINE BOOL _CHAR_setWorkChar( char *file, int line, int index, CHAR_WORKDATACHAR element, const char * new); + +#define CHAR_getItemIndex( index, iindex) _CHAR_getItemIndex( __FILE__, __LINE__, index, iindex) +INLINE int _CHAR_getItemIndex( char *file, int line, int charaindex, int ti); +#define CHAR_setItemIndex( index, iindex,id) _CHAR_setItemIndex( __FILE__, __LINE__, index, iindex, id) +INLINE int _CHAR_setItemIndex( char *file, int line, int index ,int iindex,int id ); +#define CHAR_getPoolItemIndex( index, iindex) _CHAR_getPoolItemIndex( __FILE__, __LINE__, index, iindex) +INLINE int _CHAR_getPoolItemIndex( char *file, int line, int index, int iindex); +#define CHAR_setPoolItemIndex( index, iindex,id) _CHAR_setPoolItemIndex( __FILE__, __LINE__, index, iindex, id) +INLINE int _CHAR_setPoolItemIndex( char *file, int line, int index ,int iindex,int id ); +INLINE BOOL CHAR_setAddressbookEntry( int index , int aindex , ADDRESSBOOK_entry *a ); +INLINE ADDRESSBOOK_entry* CHAR_getAddressbookEntry( int index , int aindex); +INLINE Char* CHAR_getCharPointer( int index ); +INLINE int CHAR_getCharNum( void ); +INLINE int CHAR_getPlayerMaxNum( void ); +INLINE int CHAR_getPetMaxNum( void ); +INLINE int CHAR_getOthersMaxNum( void ); +INLINE BOOL CHAR_getCharUse( int index ); +INLINE CHAR_HaveSkill* CHAR_getCharHaveSkill( int index,int sindex ); +INLINE int CHAR_getCharHaveTitle( int index,int tindex ); +INLINE int CHAR_setCharHaveTitle( int charaindex,int tindex, int new ); +INLINE int CHAR_getCharPet( int charaindex,int petindex ); +INLINE int CHAR_setCharPet( int charaindex,int petindex, int new ); +INLINE int CHAR_getCharPoolPet( int charaindex,int petindex ); +INLINE int CHAR_setCharPoolPet( int charaindex,int petindex, int new ); +int CHAR_getCharPetElement( int charaindex ); +#ifdef _PETFOLLOW_NEW_ +int CHAR_getCharPetElementOld( int charaindex ); +#endif +int CHAR_getCharPoolPetElement( int charaindex ); +int CHAR_getCharPoolItemIndexElement( int charaindex ); +int CHAR_getEmptyCharPoolItemIndexNum( int charaindex); +#ifdef _CHAR_POOLPET +int CHAR_getCharDepotPetElement( int charaindex ); +#endif +#define CHAR_getIntPSkill( index, skillti, ti) _CHAR_getIntPSkill( __FILE__, __LINE__, index, skillti, ti) +INLINE int _CHAR_getIntPSkill( char *file, int line, int index, int skillti, SKILL_DATAINT ti); + +#define CHAR_setIntPSkill( index, skillti, ti, data) _CHAR_setIntPSkill( __FILE__, __LINE__, index, skillti, ti, data) +INLINE void _CHAR_setIntPSkill( char *file, int line, int index, int skillti, SKILL_DATAINT ti, int data); + + +extern Char *CHAR_chara; + + +INLINE int CHAR_getCharMakeSequenceNumber( int charaindex ); +void CHAR_constructFunctable( int charaindex ); +void* CHAR_getFunctionPointer( int charaindex, int functype ); +#ifdef _ALLBLUES_LUA + +INLINE BOOL CHAR_setLUAFunction( int charaindex, int functype, lua_State *L, const char *luafunctable ); +INLINE BOOL CHAR_delLUAFunction( int charaindex, int functype); +INLINE lua_State *CHAR_getLUAFunction( int charaindex, int functype); +#endif +BOOL CHAR_initCharArray( int pnum, int petnum,int onum ); +BOOL CHAR_endCharArray( void ); +int CHAR_initCharOneArray( Char* ch ); +void _CHAR_endCharOneArray( int index, char*file, int line ); +#define CHAR_endCharOneArray( index) _CHAR_endCharOneArray( index, __FILE__, __LINE__) +void CHAR_removeHaveItem( Char* ch ); +void CHAR_endCharData( Char* ch ); +char* CHAR_makeStringFromCharData( Char* one ); +char* CHAR_makeStringFromCharIndex( int index ); +BOOL CHAR_makeCharFromStringToArg( char* data, Char* one); +int CHAR_makePetFromStringToArg( char *src, Char *ch, int ti); +char *CHAR_makePetStringFromPetIndex( int petindex); +#define CHAR_getPetSkillElement( petindex) _CHAR_getPetSkillElement( __FILE__, __LINE__, petindex) +int _CHAR_getPetSkillElement( char *file, int line, int petindex ); +#define CHAR_setPetSkill( petindex, havepetskillindex, n) _CHAR_setPetSkill( __FILE__, __LINE__, petindex, havepetskillindex, n) +INLINE int _CHAR_setPetSkill( char *file, int line, int petindex,int havepetskillindex, int new ); +#define CHAR_getPetSkill( petindex, havepetskillindex) _CHAR_getPetSkill( __FILE__, __LINE__, petindex, havepetskillindex) +INLINE int _CHAR_getPetSkill( char *file, int line, int petindex,int havepetskillindex ); +#define SETFLG(a,b,c,d,e,f,g,h) (((a)<<0)+((b)<<1)+((c)<<2)+((d)<<3)+((e)<<4)+((f)<<5)+((g)<<6)+((h)<<7)) + +INLINE int CHAR_AddMaxExp( int charaindex, int addexp); +INLINE int CHAR_setMaxExpFromLevel( int charaindex, int level); +INLINE int CHAR_setMaxExp( int charaindex, unsigned long int Setexp); +#ifdef _NEWOPEN_MAXEXP +INLINE int CHAR_ChangeExp( int charaindex ); +INLINE int CHAR_HandleExp( int charaindex ); + +#endif + +// ride Pet table +typedef struct tagtagRidePetTable +{ + int rideNo; + int charNo; + int petNo; + int petId; + +} tagRidePetTable; + + +// CoolFish: Family Member Kind 2001/8/28 +typedef enum +{ + FMMEMBER_NONE = -1, + FMMEMBER_MEMBER = 1, + FMMEMBER_APPLY, + FMMEMBER_LEADER, + FMMEMBER_ELDER, +} CHAR_FM_MEMBERKIND; + +// shan 2002/01/10 +typedef enum +{ + PET_STAT_NONE = 0, + PET_STAT_SELECT, + PET_STAT_MAIL = 4, +} CHAR_PET_STAT; + + +#ifdef _PERSONAL_FAME // Arminius: +void CHAR_earnFame(int index, int fame); +#endif + +// CoolFish: 2001/10/11 +#ifdef _UNIQUE_P_I +void CHAR_setPetUniCode(int petindex); +void ITEM_setItemUniCode(int itemindex); +void Check_P_I_UniCode(int charindex); +#endif + +// Arminius 12.15 жǷʿ +int IsMale(int charindex); + +// Arminius 12.15 жǷŮʿ +int IsFemale(int charindex); + + +#ifdef _NEW_RIDEPETS + #define RIDE_PET0 1 + #define RIDE_PET1 ( 1 << 1 ) + #define RIDE_PET2 ( 1 << 2 ) + #define RIDE_PET3 ( 1 << 3 ) + #define RIDE_PET4 ( 1 << 4 ) + #define RIDE_PET5 ( 1 << 5 ) + #define RIDE_PET6 ( 1 << 6 ) + #define RIDE_PET7 ( 1 << 7 ) + #define RIDE_PET8 ( 1 << 8 ) + #define RIDE_PET9 ( 1 << 9 ) + #define RIDE_PET10 ( 1 << 11 ) + #define RIDE_PET11 ( 1 << 10 ) + #define RIDE_PET12 ( 1 << 12 ) + #define RIDE_PET13 ( 1 << 13 ) + #define RIDE_PET14 ( 1 << 14 ) + #ifdef _RIDE_CF + #define RIDE_PET15 ( 1 << 15 ) + #define RIDE_PET16 ( 1 << 16 ) + #define RIDE_PET17 ( 1 << 17 ) + #define RIDE_PET19 ( 1 << 19 ) + #define RIDE_PET18 ( 1 << 18 ) + #define RIDE_PET20 ( 1 << 20 ) + #define RIDE_PET21 ( 1 << 21 ) + #define RIDE_PET22 ( 1 << 22 ) + #define RIDE_PET23 ( 1 << 23 ) + #define RIDE_PET24 ( 1 << 24 ) + #define RIDE_PET25 ( 1 << 25 ) + #define RIDE_PET26 ( 1 << 26 ) + #define RIDE_PET27 ( 1 << 27 ) + #define RIDE_PET28 ( 1 << 28 ) + #define RIDE_PET29 ( 1 << 29 ) + #define RIDE_PET30 ( 1 << 30 ) + #define RIDE_PET31 ( 1 << 31 ) + #endif + #define RIDE_TPYE1 1 + #define RIDE_TPYE2 ( 1 << 1 ) + + #define RIDE_PET_ALL ( 0xFFFFFFFF ) + #define RIDE_TPYE_ALL ( 0xFFFFFFFF ) + + #ifdef _ADD_RIDE_CF + #define MAXNOINDEX 32*3 + #else + #define MAXNOINDEX 32*2 + #endif +#else + #define RIDE_PET_ALL ( RIDE_PET0|RIDE_PET1|RIDE_PET2|RIDE_PET3|RIDE_PET4|RIDE_PET5|RIDE_PET6|RIDE_PET7|RIDE_PET8|RIDE_PET9|RIDE_PET10|RIDE_PET11 ) + #define MAXNOINDEX 15 +#endif + + +#ifdef _PET_BEATITUDE + #define BEATITUDE_VITAL ( 1 << 0 ) + #define BEATITUDE_STR ( 1 << 1 ) + #define BEATITUDE_TOUGH ( 1 << 2 ) + #define BEATITUDE_DEX ( 1 << 3 ) +#endif + +#ifdef _FM_LEADER_RIDE +typedef struct { + int fmfloor; + int ride[3]; +}tagFmLeaderRide; +#endif + +#ifdef _FM_LEADER_RIDE +int CHAR_FmLeaderRide(int meindex,int pet); +#endif + +typedef struct { + int petNo; +#ifdef _RIDE_CF + int petNo1; +#ifdef _ADD_RIDE_CF + int petNo2; +#endif +#endif + unsigned int learnCode; +}tagRideCodeMode; + +typedef struct { + int RideNo[MAXNOINDEX]; + int flg; +}tagRideNoList; + +typedef struct { + int charNo; + int Noindex; + int sex; +}tagRidePetList; + +int RIDEPET_getNOindex( int baseNo); +#ifdef _RIDE_CF +#ifdef _ADD_RIDE_CF +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode, int unsigned learnCode1, int unsigned learnCode2 ); +#else +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode, int unsigned learnCode1 ); +#endif +#else +int RIDEPET_getPETindex( int PetNo, unsigned int learnCode); +#endif +int RIDEPET_getRIDEno( int index, int ti); + +#ifdef _FUSION_TWO +int CHAR_OldFusion_init(); +#endif + +#ifdef _PET_EVOLUTION +int EVOLUTION_getPetTable( int charaindex, int petindex1, int petindex2); +int EVOLUTION_getPropertyTable( int charaindex, int petindex1, int petindex2); +int EVOLUTION_getFusionTable( int charaindex, int px, int py); +int EVOLUTION_getPetFusionCode( int petid); +#endif + +#ifdef _EMENY_CHANCEMAN +int CHAR_getSexInt( int baseNo ); +#endif +#ifdef _TYPE_TOXICATION +BOOL CHAR_CanCureFlg( int charaindex, char *arg); +#endif + +BOOL CHAR_getCharOnArrayPercentage( int mode, int *max, int *min, int *cnt); + + +#define CHAR_DelItemMess( index, ti, flg) _CHAR_DelItem( __FILE__, __LINE__, index, ti, 1, flg) +#define CHAR_DelItem( index, ti) _CHAR_DelItem( __FILE__, __LINE__, index, ti, 1, 1) +#define CHAR_DelPileItemMess( index, ti, num, flg) _CHAR_DelItem( __FILE__, __LINE__, index, ti, num, flg) + +#define CHAR_AddPileItem( index, itemindex) _CHAR_AddPileItem( __FILE__, __LINE__, index, itemindex) +INLINE int _CHAR_AddPileItem( char *file, int line, int charaindex, int itemindex); + +INLINE int _CHAR_DelItem( char *file, int line, int charaindex, int ti, int num, int flg); + +#define CHAR_AddGold( index, ti) _CHAR_AddGold( __FILE__, __LINE__, index, ti) +INLINE int _CHAR_AddGold( char *file, int line, int charaindex, int gold); +#define CHAR_DelGold( index, ti) _CHAR_DelGold( __FILE__, __LINE__, index, ti) +INLINE int _CHAR_DelGold( char *file, int line, int charaindex, int gold); +int CHAR_getMaxHaveGold( int charaindex); + + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + +int CHAR_getCharSkill( int index,int sindex ); +int CHAR_setCharSkill( int index,int sindex,int new ); +#define CHAR_CHECK_PROFESSION_SKILLINDEX( skillindex) _CHAR_CHECK_PROFESSION_SKILLINDEX( __FILE__, __LINE__, skillindex) +INLINE BOOL _CHAR_CHECK_PROFESSION_SKILLINDEX( char *file, int line, int skillindex ); +#define PROFESSION_SKILL_getSkill( charaindex, skillindex) _PROFESSION_SKILL_getSkill( __FILE__, __LINE__, charaindex, skillindex) +INLINE int _PROFESSION_SKILL_getSkill( char *file, int line, int charaindex, int skillindex ); +#define PROFESSION_SKILL_setSkill( charaindex, skillindex, n) _PROFESSION_SKILL_setSkill( __FILE__, __LINE__, charaindex, skillindex, n) +INLINE int _PROFESSION_SKILL_setSkill( char *file, int line, int charaindex,int skillindex, int new ); +#define PROFESSION_SKILL_getSkillElement(charaindex) _PROFESSION_SKILL_getSkillElement( __FILE__, __LINE__, charaindex) +int _PROFESSION_SKILL_getSkillElement( char *file, int line, int charaindex ); + +#endif + +#ifdef _NPC_SEPARATEDATA +void CHAR_showTempInt( int index); +BOOL CHAR_InitCharTempNum( Char* ch ); +void CHAR_EndCharTempNum( void); +void CHAR_getDefaultCharTempNum( Char* ch ); +#endif + +#ifdef _CHAR_POOLITEM + +#define CHAR_getDepotItemIndex( index, iindex) _CHAR_getDepotItemIndex( __FILE__, __LINE__, index, iindex) +INLINE int _CHAR_getDepotItemIndex( char *file, int line, int index ,int iindex); +#define CHAR_setDepotItemIndex( index, iindex,id) _CHAR_setDepotItemIndex( __FILE__, __LINE__, index, iindex, id) +INLINE int _CHAR_setDepotItemIndex( char *file, int line, int index ,int iindex,int id ); + +void CHAR_removeHaveDepotItem( Char* ch); +void CHAR_removeDepotItem( int charaindex); + +char *CHAR_makeDepotItemFromCharIndex( int charaindex); +BOOL CHAR_makeDepotItemStringToChar( int charaindex, char* data); + +BOOL CHAR_SaveDepotItem( int charaindex); +BOOL CHAR_GetDepotItem( int meindex, int charaindex); +void CHAR_ShowMyDepotItems( int charaindex); + +int CHAR_findEmptyDepotItem( int charaindex); +int CHAR_getfindEmptyDepotItem( int charaindex); +BOOL CHAR_CheckDepotItem( int charaindex); +#endif + +#ifdef _CHAR_POOLPET + +#define CHAR_getDepotPetIndex( index, iindex) _CHAR_getDepotPetIndex( __FILE__, __LINE__, index, iindex) +INLINE int _CHAR_getDepotPetIndex( char *file, int line, int index ,int iindex); +#define CHAR_setDepotPetIndex( index, iindex,id) _CHAR_setDepotPetIndex( __FILE__, __LINE__, index, iindex, id) +INLINE int _CHAR_setDepotPetIndex( char *file, int line, int index ,int iindex,int id ); + +void CHAR_removeHaveDepotPet( Char* ch); +void CHAR_removeDepotPet( int charaindex); + +char *CHAR_makeDepotPetFromCharIndex( int charaindex); +BOOL CHAR_makeDepotPetStringToChar( int charaindex, char* data); + +BOOL CHAR_SaveDepotPet( int charaindex); +BOOL CHAR_GetDepotPet( int meindex, int charaindex); +void CHAR_ShowMyDepotPets( int charaindex); + +int CHAR_findEmptyDepotPet( int charaindex); +int CHAR_getfindEmptyDepotPet( int charaindex); +BOOL CHAR_CheckDepotPet( int charaindex); +#endif + +#ifdef _RIDE_CF +int CHAR_Ride_CF_init(); +#endif + +void LodBadPetString( char *data, char *err, int ti); + +#ifdef _STREET_VENDOR +BOOL CHAR_setStreetVendor(int charindex,int index,int set,int num); +INLINE void CHAR_clearStreetVendor(int charindex,int index); +int CHAR_getStreetVendor(int charindex,int index,int set); +#endif + +#ifdef _FM_LEADER_RIDE +int CHAR_FmLeaderRide_init(); +#endif + +#ifdef _ANGEL_SUMMON + +#define ANGELITEM 2884 //20701 //ʹߵ ߱ +#define HEROITEM 2885 //20702 //ߵ ߱ + +typedef enum +{ + ANGEL_NONE =0, + ANGEL_ANGEL, + ANGEL_HERO, +}ANGEL_TYPE; + +typedef enum +{ + MISSION_NONE =0, + MISSION_WAIT_ANSWER, + MISSION_DOING, + MISSION_HERO_COMPLETE, + MISSION_TIMEOVER, +}ANGEL_MISSIONFLAG; +#endif + +#ifdef _MO_LNS_CHARSUOXU +int CHAR_getEmptyItemBoxNum(int charaindex); +int CHAR_getEmptyPetBoxNum(int charaindex); +int CHAR_getPlayerPetNum(int charaindex,int petid); +int CHAR_getPlayerItemNum(int charaindex,int itemid,BOOL IsContainEquip,BOOL IsContainPile); +#endif +int CHAR_CheckLearnCode(int charindex, int ridno); +#ifdef _NEW_TITLE +void CHAR_SetNewTitleUse(int charaindex,int id); +void CHAR_CancelNewTitle(int charaindex); +#endif +#endif + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_data.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_data.h new file mode 100644 index 0000000..769145a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_data.h @@ -0,0 +1,127 @@ +#ifndef __CHAR_DATA_H__ +#define __CHAR_DATA_H__ + +#include "item.h" +#include "char.h" + + +#define CHAR_CLASS01_PASSLV 20 + +#define BATEBAN 2 +#define FIRSTPOSITIONMAXINDEX 1 +#define ELDERINDEXSTART FIRSTPOSITIONMAXINDEX+BATEBAN+1 + +typedef struct tagLevelUpPattern +{ +#if 1 + struct Exptbl{ + int origin; + int multi; + }exptbl[3]; + int hpupminpoint; /* hp ؤ 쵰*/ + int hpupmaxpoint; /* hp ؤ 쵰*/ + + int needexp; /* ۢئ */ +#else + int uppoint[5]; +#endif +}LevelUpPattern; + +/*====================Ƥʧ====================*/ +BOOL CHAR_getDefaultChar( Char* nc, int imagenumber ); + +/*==================== į׸====================*/ +int CHAR_getNewImagenumberFromEquip(int index, int basebaseimagenumber,ITEM_CATEGORY category ); +/*==================== į ٯ -> į====================*/ +//void CHAR_initSeekGraphicNumberFromString(); +int CHAR_seekGraphicNumberFromString( char* string ); + + + +/*====================ƽҷ¼====================*/ +BOOL CHAR_getInitElderPosition( Char* ch,int hometown); +BOOL CHAR_getElderPosition( int elderindex, int* fl, int* x, int* y ); + +void CHAR_setInitValues( Char* ch ); + + +/*==================== ====================*/ +typedef enum +{ + CHAR_INVAREA, + CHAR_CANNOTDROPAREA, + CHAR_CANNOTMAGICAREA, + CHAR_AREAKIND_NONE, +}CHAR_AREAKIND; + +BOOL CHAR_initInvinciblePlace( char* filename ); +BOOL CHAR_isCannotMagicArea( int floor , int x, int y, int magicnum ); +BOOL CHAR_initAppearPosition( char* filename ); +BOOL CHAR_isInvincibleArea( int floor , int x, int y ); +BOOL CHAR_isAppearPosition( int floor, int *x, int *y); +BOOL CHAR_isCannotDropArea( int floor , int x, int y ); + + +/* Ӯ */ +BOOL CHAR_ElderSetPosition( int elderindex ,int fl,int x ,int y); + + + +/************************************************* +ìʧ +*************************************************/ + + +int GetEnemyExp( int level ); + +int CHAR_GetLevel(); +int CHAR_GetLevelExp( int charaindex, int level ); +int CHAR_GetOldLevelExp( int level); + +int CHAR_LevelUpCheck( int charaindex , int toindex); + +int CHAR_PetLevelUp( int petindex ); + +BOOL CHAR_checkFaceImageNumber( int imagenumber, int faceimagenumber); +BOOL CHAR_checkPlayerImageNumber( int imagenumber); + +int CHAR_PetTakeLevelUp( int petindex, int lv); //ǿƳ +int CHAR_PetTakeDrop( int petindex, int floor, int ox, int oy); //ǿƶ + +#ifdef _NPC_FUSION +int PETFUSION_FusionPetSub( int charaindex, int Subindex1, int Subindex2, int *work, int *skill); +BOOL PETFUSION_FusionPetMain( int charaindex, int Mainindex, int *work, int *skill); +BOOL PETFUSION_DelPet( int toindex, int Mainindex, int Subindex1, int Subindex2, int flg); +int PETFUSION_Evolution( int charaindex, int petindex); +#endif +int PETTRANS_PetTransManStatus( int toindex, int petindex1, int petindex2); +#ifdef _PET_2TRANS +int NPC_PetTransManGetAns( int total1, int total2, int LV, int rank, int tran); +#else +int NPC_PetTransManGetAns( int total1, int total2, int LV, int rank); +#endif //_PET_2TRANS + +#ifdef _CHIKULA_STONE +void CHAR_AutoChikulaStone( int charaindex, int Dflg); +#endif + +#ifdef _STATUS_WATERWORD //ˮ״̬ +void CHAR_CheckWaterStatus( int charaindex); +#endif + +int CHAR_findSurplusPetBox( int charaindex ); + +#ifdef _USER_EXP_CF +void setNeedLevelUpTbls(int level,int exp); +void setMaxLevel(int level); +#endif +#ifdef _FM_METAMO +void CHAR_ReMetamo( int charaindex ); +#endif +#ifdef _NEW_PLAYER_RIDE +void CHAR_PlayerRide( int charaindex ); +#endif +#ifdef _JZ_NEWSCRIPT_LUA +#define CHAR_PetLevelUpExInfc(petindex, lv) CHAR_PetLevelUp(petindex ); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_event.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_event.h new file mode 100644 index 0000000..e48e1d3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_event.h @@ -0,0 +1,31 @@ +#ifndef __CHAR_EVENT_H__ +#define __CHAR_EVENT_H__ + +#include "char_base.h" + +void CHAR_allpostwalk( int index ); +BOOL CHAR_allprewalk( int index,int* dir,int* mode); + +void CHAR_recoveryStatus( int charaindex ); +void CHAR_loopFunc( int index ); +void CHAR_playerWatchfunc( int meindex, int moveindex, CHAR_ACTION act, + int x, int y, int dir, int* opt, int optlen ); + +void CHAR_sendWallDamage( int charaindex,int x, int y, int damage ); +void CHAR_playerresurrect( int charaindex, int hp ); + +int CHAR_die( int charaindex ); +void CHAR_playerTalkedfunc( int charaindex, int talkindex,char* message, + int color, int channel ); + +void CHAR_recoveryStatus( int charaindex ); +BOOL CHAR_makeCADefaultString( int objindex,char* buf,int buflen, int act ); +BOOL CHAR_makeCAOPT1String( int objindex,char* buf, + int buflen, int act,int opt1 ); +BOOL CHAR_makeCAOPT3String( int objindex,char* buf, + int buflen, int act,int opt1,int opt2,int opt3 ); +#ifdef _STREET_VENDOR +BOOL CHAR_makeCAOPTString(int objindex,char* buf,int buflen,int act,char *string); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_talk.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_talk.h new file mode 100644 index 0000000..801dee2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/char_talk.h @@ -0,0 +1,52 @@ +#ifndef __CHAR_TALK_H__ +#define __CHAR_TALK_H__ + +#include "common.h" +#include "util.h" +#include "net.h" +#ifdef _ALLBLUES_LUA +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#endif +void CHAR_getMessageBody(char* message, char* kind, int kindlen, + char** body); + +int CHAR_getChatMagicFuncLevel(char* name,BOOL isDebug); +int CHAR_getChatMagicFuncNameAndString( int ti, char* name, char *usestring, int level, BOOL isDebug); +int CHAR_getChatMagicFuncMaxNum( void); + +void OneByOneTkChannel ( int fd , char *tmp1 , char *tmp2 , int color) ; + +typedef void (*CHATMAGICFUNC)(int,char*); +CHATMAGICFUNC CHAR_getChatMagicFuncPointer(char* name, BOOL isDebug); + + +#ifdef _RE_GM_COMMAND +int re_gm_command(); +#endif + + +#ifdef _FILTER_TALK +int ReadFilterTalk(); +char *getFilterTalk(int index); +int getFilterTalkNum(); +#endif + +#ifdef _ALLBLUES_LUA_1_2 +typedef struct tagMAGIC_LuaFunc +{ + lua_State *lua; + char *luafuncname; + char *luafunctable; + int gmlevel; + char *usestring; + struct tagMAGIC_LuaFunc *next; +}MAGIC_LuaFunc; + +BOOL MAGIC_addLUAListFunction( lua_State *L, const char *luafuncname, const char *luafunctable, int gmlevel, char *usestring ); +BOOL MAGIC_getLUAListFunction( char *luafuncname, int gmlevel, int charaindex, char *data ); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatmagic.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatmagic.h new file mode 100644 index 0000000..e76865e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatmagic.h @@ -0,0 +1,284 @@ +#ifndef __CHATMAGIC_H__ +#define __CHATMAGIC_H__ +#include "version.h" + +void CHAR_CHAT_DEBUG_hp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_mp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_setmp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_str( int charindex , char *message ); +void CHAR_CHAT_DEBUG_dex( int charindex , char *message ); +void CHAR_CHAT_DEBUG_tgh( int charindex , char *message ); +void CHAR_CHAT_DEBUG_vital( int charindex , char *message ); +void CHAR_CHAT_DEBUG_luck( int charindex , char *message ); +void CHAR_CHAT_DEBUG_gold( int charindex , char *message ); +void CHAR_CHAT_DEBUG_additem( int charindex , char *message ); +void CHAR_CHAT_DEBUG_metamo( int charindex , char *message ); +void CHAR_CHAT_DEBUG_warp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_info( int charindex , char *message ); +void CHAR_CHAT_DEBUG_sysinfo( int charindex , char *message ); +void CHAR_CHAT_DEBUG_announce(int charindex , char *message ); +void CHAR_CHAT_DEBUG_level( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_delitem( int charindex , char *message ); +void CHAR_CHAT_DEBUG_superman( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_battlein( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_battleout( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_petmake( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_enemyrestart( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_gb( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_gu( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_tame( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_fieldatt( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_ren( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_geki( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_s_hai( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_j_state( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_battlewatch( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_eventclean( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_eventsetend( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_eventsetnow( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_debug( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_exp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_dp( int charindex , char *message ); +void CHAR_CHAT_DEBUG_setTrans( int charaindex, char *message); +void CHAR_CHAT_DEBUG_getuser(int charindex ,char *message);//ttom +1 14/11/2000 +void CHAR_CHAT_DEBUG_shutup(int charindex ,char *message);//ttom 22/11/2000 +void CHAR_CHAT_DEBUG_waeikick( int charindex, char* message );//ttom 12/02/2000 +void CHAR_CHAT_DEBUG_effect( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_jail( int charindex, char* message );//ttom 01/11/2001 +void CHAR_CHAT_DEBUG_shutupall(int charindex ,char *message);//ttom 02/01/2001 +void CHAR_CHAT_DEBUG_send(int charindex ,char *message);//ttom 02/01/2001 +void CHAR_CHAT_DEBUG_noenemy(int charaindex, char *message); +void CHAR_CHAT_DEBUG_loginannounce(int charaindex, char* message); // Arminius 7.12 login announce +void CHAR_CHAT_DEBUG_deletepet(int charaindex, char* message); // Robin 0720 +void CHAR_CHAT_DEBUG_deleteitem(int charaindex, char* message); // Robin 0720 +void CHAR_CHAT_DEBUG_checklock(int charaindex, char* message); // Arminius 7.25 +void CHAR_CHAT_DEBUG_unlock(int charaindex, char* message); +void CHAR_CHAT_DEBUG_unlockserver(int charaindex, char* message); +void CHAR_CHAT_DEBUG_fixfmdata(int charaindex, char* message); // CoolFish: GM Family 2001/7/31 +void CHAR_CHAT_DEBUG_shutdown(int charaindex, char* message); // Robin 1008 +void CHAR_CHAT_DEBUG_manorpk(int charaindex, char *message); + +void CHAR_CHAT_DEBUG_watchevent( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_fixfmpk(int charaindex, char *message); +void CHAR_CHAT_DEBUG_reloadmsip( int charaindex, char *message); +void CHAR_CHAT_DEBUG_cleanfreepet(int charaindex, char *message); +void CHAR_CHAT_DEBUG_engineer( int charindex, char *message); +void CHAR_CHAT_DEBUG_waeikickall( int charindex, char* message ); +void CHAR_CHAT_DEBUG_showMem(int charaindex, char *message); +void CHAR_CHAT_DEBUG_playerspread( int charaindex, char *message); +void CHAR_CHAT_DEBUG_reset( int charaindex, char* message ); + +#ifdef _MAKE_MAP +void CHAR_CHAT_DelMap( int charaindex, char* message ); +void CHAR_CHAT_GetMap( int charaindex, char* message ); +void CHAR_CHAT_Map( int charaindex, char* message ); +void CHAR_CHAT_Fixtile( int charaindex, char* message ); +void CHAR_CHAT_Fixobj( int charaindex, char* message ); +void CHAR_CHAT_Fukuwa( int charaindex, char* message ); +#endif + +#ifdef _GMRELOAD +void CHAR_CHAT_DEBUG_gmreload(int charaindex, char *message); +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +void CHAR_CHAT_DEBUG_addsk( int charaindex, char *message ); +void CHAR_CHAT_DEBUG_delsk( int charaindex, char *message ); +#endif +void CHAR_CHAT_DEBUG_cleanfloor( int charaindex, char *message); + +#ifdef _GAMBLE_BANK +void CHAR_CHAT_DEBUG_setgamblenum( int charaindex, char *message ); +#endif +#ifdef _WAEI_KICK +void CHAR_CHAT_DEBUG_gmkick( int charindex, char* message); +#endif +// WON ADD 峤 +void CHAR_CHAT_DEBUG_fixfmleader(int charaindex, char *message); + +// WON ADD ָ +void CHAR_CHAT_DEBUG_crash(int charaindex, char *message); + +#ifdef _PETSKILL_SETDUCK +void CHAR_CHAT_DEBUG_SetDuck( int charaindex, char *message); +#endif +#ifdef _TYPE_TOXICATION +void CHAR_CHAT_DEBUG_Toxication( int charaindex, char *message); +#endif + +#ifdef _SEND_EFFECT // WON ADD ACѩЧ +void CHAR_CHAT_DEBUG_sendeffect(int charaindex, char *message); +#endif +#ifdef _TEST_DROPITEMS +void CHAR_CHAT_DEBUG_dropmypet( int charindex, char *message ); +void CHAR_CHAT_DEBUG_dropmyitem( int charindex , char *message ); +#endif + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +void CHAR_CHAT_DEBUG_show_profession( int charaindex, char*message ); +void CHAR_CHAT_DEBUG_set_regist( int charaindex, char*message ); +#endif + +void CHAR_CHAT_DEBUG_checktrade( int charaindex, char*message); + +void CHAR_CHAT_DEBUG_checktime( int charaindex, char *message); +void CHAR_CHAT_DEBUG_samecode( int charaindex, char *message); +void CHAR_CHAT_DEBUG_silent(int charindex ,char *message); +void CHAR_CHAT_DEBUG_help( int charindex, char *message); +#ifdef _EQUIT_ARRANGE +void CHAR_CHAT_DEBUG_arrange( int charindex , char *message ); +#endif + +#ifdef _EQUIT_SEQUENCE +void CHAR_CHAT_DEBUG_sequence( int charindex , char *message ); +#endif + +#ifdef _EQUIT_NEGLECTGUARD +void CHAR_CHAT_DEBUG_setneguard( int charaindex, char* message ); +#endif + +void CHAR_CHAT_DEBUG_petlevelup( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_petexpup( int charaindex, char* message ); + +void CHAR_CHAT_DEBUG_reloadpkteamlist( int charaindex, char *message); +void CHAR_CHAT_DEBUG_setBattle( int charaindex, char *message ); + + +#ifdef _CHAR_POOLITEM +void CHAR_CHAT_DEBUG_saveditem(int charaindex, char *message); +void CHAR_CHAT_DEBUG_insertditem(int charaindex, char *message); +void CHAR_CHAT_DEBUG_ShowMyDepotItems( int charaindex, char *message ); +void CHAR_CHAT_DEBUG_InSideMyDepotItems( int charaindex, char *message ); +#endif + +#ifdef _CHAR_POOLPET +void CHAR_CHAT_DEBUG_savedpet(int charaindex, char *message); +void CHAR_CHAT_DEBUG_insertdpet(int charaindex, char *message); +void CHAR_CHAT_DEBUG_ShowMyDepotPets( int charaindex, char *message ); +void CHAR_CHAT_DEBUG_InSideMyDepotPets( int charaindex, char *message ); +#endif + +#ifdef _NEW_MANOR_LAW +void CHAR_CHAT_DEBUG_set_momentum( int charaindex, char* message ); +#endif +void CHAR_CHAT_DEBUG_set_manor_owner( int charindex, char* message ); +void CHAR_CHAT_DEBUG_set_schedule_time( int charindex, char* message ); + + +#ifdef _ANGEL_SUMMON +void CHAR_CHAT_DEBUG_angelinfo(int charindex ,char *message); +void CHAR_CHAT_DEBUG_angelclean(int charindex ,char *message); +void CHAR_CHAT_DEBUG_angelcreate(int charindex ,char *message); +void CHAR_CHAT_DEBUG_missionreload(int charindex ,char *message); +#endif + +void CHAR_CHAT_DEBUG_itemreload(int charindex ,char *message); + +void CHAR_CHAT_DEBUG_skywalker(int charaindex ,char *message); + +#ifdef _ITEM_ADDEXP +void CHAR_CHAT_DEBUG_itemaddexp(int charaindex ,char *message); +#endif + +#ifdef _DEF_GETYOU +void CHAR_CHAT_DEBUG_getyou(int charaindex,char *message); +#endif + +#ifdef _DEF_NEWSEND +void CHAR_CHAT_DEBUG_newsend(int charindex ,char *message); +#endif + +#ifdef _DEF_SUPERSEND +void CHAR_CHAT_DEBUG_supersend(int charindex ,char *message); +#endif + +#ifdef _FONT_SIZE +void CHAR_CHAT_DEBUG_fsize(int charindex ,char *message); +#endif + +#ifdef _JOBDAILY +void CHAR_CHAT_DEBUG_rejobdaily(int charindex ,char *message); +#endif + +#ifdef _CREATE_MM_1_2 +void CHAR_CHAT_DEBUG_MM(int charaindex , char *message ); +#endif + +#ifdef _SendTo +void CHAR_CHAT_DEBUG_Sendto( int charaindex , char *message ); +#endif + +void CHAR_CHAT_printcount( int charaindex, char* message ); + +#ifdef _GM_ITEM +void CHAR_CHAT_DEBUG_GMFUNCTION( int charindex , char *message ); +#endif + +#ifdef _GM_RIDE +void CHAR_CHAT_DEBUG_SETRIDE( int charindex , char *message ); +void CHAR_CHAT_DEBUG_MVRIDE( int charindex , char *message ); +#endif + +#ifdef _LOCK_IP +void CHAR_CHAT_DEBUG_ADD_LOCK( int charindex , char *message ); +void CHAR_CHAT_DEBUG_DEL_LOCK( int charindex , char *message ); +void CHAR_CHAT_DEBUG_SHOWIP( int charindex , char *message ); +#endif +void CHAR_CHAT_DEBUG_SET_FAME( int charaindex, char* message ); +#ifdef _AUTO_PK +void CHAR_CHAT_DEBUG_SET_AUTOPK( int charaindex, char* message ); +#endif + +#ifdef _PLAYER_NUM +void CHAR_CHAT_DEBUG_SET_PLAYERNUM( int charaindex, char* message ); +#endif +#ifdef _RELOAD_CF +void CHAR_CHAT_DEBUG_SET_RELOADCF( int charaindex, char* message ); +#endif +#ifdef _TRANS +void CHAR_CHAT_DEBUG_Trans( int charaindex, char *message); +#endif +#ifdef _FUSIONBEIT_FIX +void CHAR_CHAT_DEBUG_fusionbeit( int charaindex, char* message ); +#endif +#ifdef _MAKE_PET_CF +void CHAR_CHAT_DEBUG_petmakecf( int charaindex, char* message ); +#endif +#ifdef _MAKE_PET_ABILITY +void CHAR_CHAT_DEBUG_petmakeabi( int charaindex, char* message ); +#endif +#ifdef _PLAYER_QUESTION_ONLIEN +void CHAR_CHAT_DEBUG_PlayerQuestion( int charaindex, char* message ); +#endif +#ifdef _GM_SAVE_ALL_CHAR +void CHAR_CHAT_DEBUG_GmSaveAllChar( int charaindex, char* message ); +#endif +#ifdef _ALLBLUES_LUA +void CHAR_CHAT_DEBUG_ReLoadLua( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_NewLoadLua( int charaindex, char* message ); +#endif +#ifdef _KEEP_UP_NO_LOGIN +void CHAR_CHAT_DEBUG_KeepUpNoLogin( int charaindex, char* message ); +#endif +#ifdef _NEW_LOAD_NPC +void CHAR_CHAT_DEBUG_NewLoadNpc( int charaindex, char* message ); +#endif +#ifdef _NEW_LOAD_MAP +void CHAR_CHAT_DEBUG_NewLoadMap( int charaindex, char* message ); +#endif +#ifdef _JZ_NEWSCRIPT_LUA +void CHAR_CHAT_DEBUG_LUA_INIT( int charaindex, char* message ); +void CHAR_CHAT_DEBUG_LUA_CLOSE( int charaindex, char* message ); +#endif +#ifdef _NO_FULLPLAYER_ATT +void CHAR_CHAT_NoFullPlayer( int charaindex, char* message ); +#endif +#ifdef _PET_MAKE_2_TRANS +void CHAR_CHAT_DEBUG_petmake2( int charaindex, char* message ); +#endif +#ifdef _NPC_MAGICCARD +void CHAR_CHAT_DEBUG_gamerate(int charindex, char *message); +#endif +void CHAR_CHAT_DEBUG_SAVESHH( int fd, int charaindex,char* message,int color, int area ); +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatroom.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatroom.h new file mode 100644 index 0000000..012abf2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/chatroom.h @@ -0,0 +1,22 @@ +#ifndef __CHATROOM_H__ +#define __CHATROOM_H__ +#include "version.h" + +#define MAX_CHATROOM 10 +#define MAX_PPLINROOM 100 + +void InitChatRoom ( void ) ; +void ChatRoom_List ( int fd ); +BOOL ChatCheck_BeMaster( int myindex, int chatnum); +BOOL ChatCheck_Free( int myindex); +BOOL ChatRoom_Create ( int myindex , char *message); +BOOL ChatRoom_Destroy ( int myindex ) ; +void ChatRoom_Kick ( int myindex , int toindex ) ; +void ChatRoom_Make ( int myindex , int toindex ) ; +void ChatRoom_Leave ( int myindex ) ; +void ChatRoom_Join ( int myindex , int num ) ; +void ChatRoom_Agree ( int myindex , int toindex , int YesNo ) ; +void ChatRoom_Message ( int myindex , char *message ) ; +void ChatRoom_Refresh ( int Num ) ; +void ChatRoom_recvall ( int fd , char *data ) ; +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/common.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/common.h new file mode 100644 index 0000000..e038c8e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/common.h @@ -0,0 +1,64 @@ +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include +#include + +/* MACROS */ +#define RETURNFALSEIFFALSE(x) if(!x)return FALSE; +#define EXITWITHEXITCODEIFFALSE(x,code) if(!x)exit(code); +#ifdef __GNUC__ +#define print(format,arg...) fprintf( stderr, format ,##arg) +#define fprint(format,arg...) fprintf( stderr, "%s:%d " format , __FILE__ , __LINE__ , ##arg) +#endif + +#define mj_sprintf(format,arg...) ((sizeof(format)==4)?sprintf(format,##arg):snprintf(format,sizeof(format),##arg)) + + +#define debug(x,y) fprintf( stderr, #x " = %" #y "\n" , x) +#define arraysizeof( x ) (sizeof(x)/sizeof(x[0])) + +#define errorprint {extern int errno;fprint( "%s\n" ,strerror(errno));} + +#define BACKSLASH '\\' +#define NEWLINE '\n' +#define TAB '\t' +#define SPACE ' ' + + +/*#define min( x,y ) ((x)>(y)?(y):(x)) + #define max( x,y ) ((x)>(y)?(x):(y))*/ +#define min( x,y ) ({typeof(x) __x=(x),__y=(y);(__x < __y) ? __x : __y; }) +#define max( x,y ) ({typeof(x) __x=(x),__y=(y);(__x < __y) ? __y : __x; }) +#define swap( x,y )({typeof(x) __x=(y);(y)=(x);(x)=__x;}) +#define SUCCESSFUL "successful" +#define FAILED "failed" + +#define LOCK 1 +#define UNLOCK 0 + +#define STRINGBUFSIZ 4096*4 + +#define OPEN {FILE* f;f=fopen("a.txt","a"); +#define CLOSE fclose(f);} + +#define time_diff_us(new,old) ((unsigned)( (new.tv_sec - old.tv_sec)*1000000 + ( new.tv_usec - old.tv_usec ) )) + + + + +extern int snprintf (char* , size_t, const char* , ...) +#ifdef __GNUC__ + __attribute__ ((format (printf,3,4))); +#else + ; +#endif + +#define ON 1 +#define OFF 0 +#define BOOL int +#define FALSE 0 +#define TRUE 1 +#define INLINE inline + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/configfile.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/configfile.h new file mode 100644 index 0000000..e3d9195 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/configfile.h @@ -0,0 +1,611 @@ +#ifndef __CONFIGFILE_H__ +#define __CONFIGFILE_H__ + +#include "common.h" + +#undef EXTERN +#ifdef __CONFIGFILE_C__ +#define EXTERN +#else /* __CONFIGFILE_C__ */ +#define EXTERN extern +#endif /* __CONFIGFILE_C__ */ + +// Arminius 7.12 login announce +extern char announcetext[8192]; +void AnnounceToPlayer(int charaindex); +// Robin 0720 +void AnnounceToPlayerWN(int fd); +void LoadAnnounce(void); + +#ifdef _PET_TALKPRO + #define PETTALK_MAXID 8 + typedef struct { + int ID; + char DATA[1024*64]; //1M + }PTALK; + extern PTALK pettalktext[PETTALK_MAXID]; + void LoadPetTalk(void); +#else + +extern char pettalktext[4096]; +void LoadPetTalk(void); +#endif + +#ifdef _GAMBLE_BANK +#define GAMBLEBANK_ITEMSMAX 100 +#define DEFEND_ITEMSMAX 40 +typedef struct REGAMBLEBANKITEMS { + char name[128]; + int Gnum; + int ItemId; + int type; +}GAMBLEBANK_ITEMS; + +extern GAMBLEBANK_ITEMS GB_ITEMS[GAMBLEBANK_ITEMSMAX]; + +void Load_GambleBankItems( void); +#endif + +#ifdef _CFREE_petskill +#define PETSKILL_CODE 500 +typedef struct REPETSKILL_CODES { + char name[128]; + int TempNo; + int PetId; + char Code[256]; +}PETSKILL_CODES; + +extern PETSKILL_CODES Code_skill[PETSKILL_CODE]; +void Load_PetSkillCodes( void); +#endif + +#ifdef _GMRELOAD +#define GMMAXNUM 100 +struct GMINFO +{ + char cdkey[24]; + int level; +}; +extern struct GMINFO gminfo[GMMAXNUM]; +#endif + +BOOL luareadconfigfile( char* data ); + +BOOL readconfigfile( char* filename ); + +void defaultConfig( char* argv0 ); +char* getProgname( void ); +char* getConfigfilename( void ); +void setConfigfilename( char* newv ); + +unsigned int getDebuglevel( void ); +unsigned int setDebuglevel( unsigned int newv ); +unsigned int getMemoryunit( void ); +unsigned int getMemoryunitnum( void ); +char* getAccountservername( void ); +unsigned short getAccountserverport( void ); +char* getAccountserverpasswd( void ); +char* getGameservername( void ); + +unsigned short getPortnumber( void ); + +int getServernumber( void ); +int getReuseaddr( void ); +int getNodelay( void ); +int getLogWriteTime(void); +int getLogIOTime( void); +int getLogGameTime(void); +int getLogNetloopFaster(void); +int getSaacwritenum( void ); +void setSaacwritenum( int num ); +int getSaacreadnum( void ); +void setSaacreadnum( int num ); + +unsigned int getFdnum( void ); +unsigned int setFdnum(int temp_fdnum); +unsigned int getPlayercharnum( void ); +unsigned int getPetcharnum( void ); +unsigned int getOtherscharnum( void ); +unsigned int getObjnum( void ); +unsigned int getItemnum( void ); +unsigned int getBattlenum( void ); + +char* getTopdir( void ); +char* getMapdir( void ); +char* getMaptilefile( void ); +char* getBattleMapfile( void ); +char* getItemfile( void ); +char* getInvfile( void ); +char* getAppearfile( void ); +char* getEffectfile( void ); +char* getTitleNamefile( void ); +char* getTitleConfigfile( void ); +char* getLsgenlogfilename( void ); +char* getStoredir( void ); +#ifdef _STORECHAR +char* getStorechar( void ); +#endif +char* getNpcdir( void ); +char* getLogdir( void ); +char* getLogconffile( void ); +char* getChatMagicPasswd( void ); +unsigned int getChatMagicCDKeyCheck( void ); +void setChatMagicPasswd( void ); +void setChatMagicCDKeyCheck( void ); + +unsigned int getFilesearchnum( void ); +unsigned int getNpctemplatenum( void ); +unsigned int getNpccreatenum( void ); +unsigned int getWalksendinterval( void ); +void setWalksendinterval( unsigned int ); +unsigned int getCAsendinterval_ms( void ); +void setCAsendinterval_ms( unsigned int ); +unsigned int getCDsendinterval_ms( void ); +void setCDsendinterval_ms( unsigned int ); +unsigned int getOnelooptime_ms( void ); +void setOnelooptime_ms( unsigned int ); +unsigned int getCharSavesendinterval( void ); +void setCharSavesendinterval( unsigned int interval); +unsigned int getAddressbookoffmsgnum( void ); +unsigned int getProtocolreadfrequency( void ); +unsigned int getAllowerrornum( void ); +unsigned int getLogHour( void ); +unsigned int getBattleDebugMsg( void ); +void setBattleDebugMsg( unsigned int ); + +char* getEncountfile( void ); +char* getEnemyfile( void ); +char* getGroupfile( void ); +char* getEnemyBasefile( void ); +char* getMagicfile( void ); +#ifdef _ATTACK_MAGIC + +char* getAttMagicfileName( void ); + +#endif + +char* getPetskillfile( void ); +char *getItematomfile( void ); +char *getQuizfile( void ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +char* getProfession( void ); +#endif + +unsigned int getPetdeletetime( void ); +void setPetdeletetime( unsigned int interval ); + +unsigned int getItemdeletetime( void ); +void setItemdeletetime( unsigned int interval ); +//ttom add this because the second have this function +//unsigned int getAcwriteSize( void ); + +#ifdef _DEL_DROP_GOLD +unsigned int getGolddeletetime( void ); +void setGolddeletetime( unsigned int interval ); +#endif + +unsigned int setEncodeKey( void ); +unsigned int setAcWBSize( void ); +//ttom end + +// CoolFish: +2 2001/4/18 +unsigned int getAcwriteSize( void ); +unsigned int getErrUserDownFlg( void ); + +// Arminius 7.24 manor pk +char* getGameserverID( void ); +unsigned short getAllowManorPK( void ); + +// Terry 2001/10/03 service ap +char* getApID(void); +unsigned short getApPort(void); +int getLoopTime(void); +int getEnableService(void); + +#ifdef _ANGEL_SUMMON +BOOL LoadMissionList( void ); +#endif +#ifdef _JOBDAILY +BOOL LoadJobdailyfile(void); +#endif +#ifdef _GMRELOAD +char* getGMSetfile(void); +BOOL LoadGMSet(char *filename); +#endif + +#ifdef _ITEM_QUITPARTY +char* getitemquitparty( void ); +#endif + +#ifdef _NEW_PLAYER_CF +int getNewplayertrans( void ); +int getNewplayerlv( void ); +int getNewplayergivepet( int index ); +int getNewplayergiveitem( int index ); +void setNewplayergivepet( unsigned int index ,unsigned int interval); +int getNewplayerpetlv( void ); +int getNewplayergivegold( void ); +int getRidePetLevel( void ); +#endif +#ifdef _VIP_SERVER +int getNewplayergivevip( void ); +#endif +#ifdef _UNLAW_WARP_FLOOR +int getUnlawwarpfloor( unsigned int index ); +#endif +#ifdef _NO_JOIN_FLOOR +int getNoJoinFloor( unsigned int index ); +#endif +#ifdef _USER_EXP_CF +BOOL LoadEXP( char* filename ); +char* getEXPfile( void ); +int getNeedLevelUpTbls( int level ); +#endif + +#ifdef _UNREG_NEMA +char* getUnregname( int index ); +#endif + +#ifdef _TRANS_LEVEL_CF +int getChartrans( void ); +int getPettrans( void ); +int getYBLevel( void ); +int getMaxLevel( void ); +#endif + +#ifdef _GET_BATTLE_EXP +unsigned int getBattleexp( void ); +void setBattleexp( int exp ); +#endif + +#ifdef _POINT +char* getPoint( void ); +int getTransPoint( int index ); +#endif + +#ifdef _PET_AND_ITEM_UP +char* getPetup( void ); +char* getItemup( void ); +#endif +#ifdef _WATCH_FLOOR +int getWatchFloor( unsigned int index ); +char* getWatchFloorCF( void ); +#endif + +#ifdef _BATTLE_FLOOR +int getBattleFloor( unsigned int index ); +char* getBattleFloorCF( void ); +#endif + +#ifdef _LOOP_ANNOUNCE +char* getLoopAnnouncePath( void ); +int loadLoopAnnounce( void ); +int getLoopAnnounceTime( void ); +char* getLoopAnnounce( int index ); +int getLoopAnnounceMax( void ); +#endif + +#ifdef _SKILLUPPOINT_CF +int getSkup( void ); +#endif +#ifdef _RIDELEVEL +int getRideLevel( void ); +int getRideTrans( void ); +#endif +#ifdef _REVLEVEL +char* getRevLevel( void ); +#endif +#ifdef _NEW_PLAYER_RIDE +char* getPlayerRide( void ); +#endif +#ifdef _FIX_CHARLOOPS +int getCharloops( void ); +#endif +#ifdef _PLAYER_ANNOUNCE +int getPAnnounce( void ); +#endif +#ifdef _PLAYER_MOVE +int getPMove( void ); +#endif + +int getrecvbuffer( void ); +int getsendbuffer( void ); +int getrecvlowatbuffer( void ); +int getrunlevel( void ); + +#ifdef _SHOW_VIP_CF +int getShowVip( void ); +#endif + +#ifdef _PLAYER_NUM +int getPlayerNum( void ); +void setPlayerNum( int num ); +#endif +#ifdef _BATTLE_GOLD +int getBattleGold( void ); +#endif + +#ifdef _ANGEL_TIME +int getAngelPlayerTime( void ); +int getAngelPlayerMun( void ); +#endif + +#ifdef _RIDEMODE_20 +int getRideMode( void ); +#endif + +#ifdef _FM_POINT_PK +char *getFmPointPK( void ); +#endif + +#ifdef _ENEMY_ACTION +int getEnemyAction( void ); +#endif + +#ifdef _FUSIONBEIT_TRANS +int getFusionbeitTrans( void ); +#endif + +char *getMacCheck( void ); +int getCpuUse( void ); + +#ifdef _CHECK_PEPEAT +int getCheckRepeat( void ); +#endif + +#ifdef _FM_JOINLIMIT +int getJoinFamilyTime( void ); +#endif + +#ifdef _MAP_HEALERALLHEAL +int getMapHeal( int index ); +#endif + +#ifdef _THE_WORLD_SEND +int getTheWorldTrans(); +int getTheWorldLevel(); +int getTheWorldSend(); +#endif + +#ifdef _LOGIN_DISPLAY +int getLoginDisplay(); +#endif + +#ifdef _VIP_POINT_PK +int getVipPointPK( int index ); +float getVipPointPKCost(void); +#endif + +#ifdef _SPECIAL_MAP +int getSpecialMap( int index ); +#endif + +#ifdef _NEW_AUTO_PK +int getAutoPkTime(); +int getAutoPkTrans(); +int getAutoPkLv(); +#ifdef _FORMULATE_AUTO_PK +int getAutoPkPoint(); +#endif +#endif + +#ifdef _AUTO_DEL_PET +#define AUTODELPETNUM 30 +int getAutoDelPet( int index ); +#endif + +#ifdef _AUTO_DEL_ITEM +#define AUTODELITEMNUM 30 +int getAutoDelItem( int index ); +#endif + +#ifdef _BT_PET +int getBtPet(); +#endif +#ifdef _BT_ITEM +int getBtItem(); +#endif + +#ifdef _LUCK_STAR +int getLuckStarTime(); +int getLuckStarChances(); +#endif +#ifdef _BATTLE_GETITEM_RATE +int getBattleGetItemRate( int index ); +int getBattleGetItemRateMap(); +#endif +#ifdef _UNLAW_THIS_LOGOUT +int getUnlawThisLogout( int index ); +#endif +#ifdef _TRANS_POINT_UP +int getTransPoinUP( int index ); +#endif +#ifdef _OPEN_STW_SEND +int getOpenStwSendType( void ); +int getOpenStwSendPoint( void ); +#endif +#ifdef _POOL_ITEM_BUG +int getPoolItemBug( void ); +int getPoolItem( int id ); +#endif +#ifdef _NO_STW_ENEMY +int getNoSTWNenemy( void ); +int getNoSTWNenemyPoint( void ); +#endif +#ifdef _NEW_STREET_VENDOR +int getStreetVendor( int id ); +#endif +#ifdef _ITEM_PET_LOCKED +int getItemPetLocked( void ); +#endif +#ifdef _TALK_SAVE +int getSaveFame( void ); +#endif +#ifdef _TALK_CHECK +int getTalkCheck( void ); +#endif +#ifdef _DISABLE_PROFESSION_SKILL +BOOL getDisableProfessionSkill( int floor ); +#endif +#ifdef _ALL_SERV_SEND +int getAllServTrans(); +int getAllServLevel(); +int getAllServSend(); +#endif +#ifdef _PET_TRANS_ABILITY +int getPetTransAbility(); +int getPetTransAbility1(); +int getPetTransAbility2(); +#endif +#ifdef _NEED_ITEM_ENEMY +int getDelNeedItem(); +#endif +#ifdef _NOT_ESCAPE +int getNotEscape( int index ); +#endif +#ifdef _PLAYER_OVERLAP_PK +int getPlayerOverlapPk( int index ); +#endif +#ifdef _FIMALY_PK_TIME +int getFimalyPkTime(); +#endif +#ifdef _PETSKILL_SHOP_LUA +char *getFreePetSkillShopPath(); +#endif +#ifdef _CANCEL_ANGLE_TRANS +int getCancelAngleTrans(); +#endif + +#ifdef _VIP_BATTLE_EXP +int getVipBattleexp( void ); +#endif + +#ifdef _NO_HELP_MAP +int getNoHelpMap( int index ); +#endif + +#ifdef _BATTLE_TIME +int getBattleTime(); +#endif +#ifdef _SAME_IP_ONLINE_NUM +int getSameIpOnlineNum(); +#endif +#ifdef _STREET_VENDOR_TRANS +int getStreetVendorTrans(); +#endif +#ifdef _CHECK_SEVER_IP +int checkServerIp( unsigned int ip ); +#endif +#ifdef _FIRST_LOCK_ITEM +int getFirstLockItem( int index ); +#endif +#ifdef _PET_ENEMY_DEVELOP_UP +int getPetEnemyDevelopUp(); +#endif +#ifdef _PETSKILL_NEW_PASSIVE +int getAutoGetSkill(void);//Ƿ񿪷ñ +int getSkillFusion(void);//ǷŴ +int getSkillCount(void);// +int getSkillPos(void); //ϰλ +int getRandSkill(void); //ü +int getFusionRange(int start); +int isFusionPet(int petId); +int getSkillProb(int skillLevel); +int getSkillRange(int skillLevel,int start); +int isPassiveSkill(int skillId); +int getSkillLevel(int skillId); +int getRandSkillByLevel(int skillLevel); +#endif + +#ifdef _SHARE_EXP +int getExpShare(void); +#endif +#ifdef _DEFEND_BIGBAO +int getBigBao(void); +int getBigBao2(void); +#endif +#ifdef _MO_SHOW_DEBUG +int isDebug(void); +#endif +#ifdef _CHAR_LOOP_TIME +int getCharLoopTime(); +#endif +#ifdef _MO_RELOAD_NPC +int getReloadNpcTime(void); +int getReloadNpcType(void); +#endif +#ifdef _JZ_NEWSCRIPT_LUA +char *getLuaFile(void); +#endif +#ifdef _MO_LNS_NLSUOXU +int GetConfigLineType(char *TM_ConfigName); +char* GetConfigLineVal(char *TM_ConfigName); +int getCopymapstartingID( void ); +#endif +#ifdef _ITEM_LUA +const char *getitemluafile(void); +BOOL ITEM_LuaInit(const char * _FileName); +#endif +#ifdef _ROOKIE_ITEM +unsigned int getRookieItem(int index); +#endif +#ifdef _NO_TRANS_ITEM +unsigned int getNoTransItem(void); +#endif +#ifdef _MAX_MERGE_LEVEL +unsigned int getMaxMergeLevel(void); +#endif +#ifdef _NO_ATTACK +int getAttTime(void); +int getAttSafeTime(void); +int getAttCnt(void); +int getLateTime(void); +int getAttDmeTime(void); +int getAttDmeCnt(void); +#endif + +char* getNoAttIp(int num); + +#ifdef _NO_FULLPLAYER_ATT +int getNoFullPlayer(void); +int getNoFull2Player(void); +int getNoCdkeyPlayer(void); +int getNoCdkeyMode(void); +int getNoCdkeyType(void); +int getNoFullTime(void); +int getFengType(void); +int getNoFullEndPlayer(void); +int getNoFullEndTime(void); +int getManRenNum(void); +#endif +int getLockType(void); +#ifdef _NEW_FUNC_DECRYPT +unsigned int getAllowerrornum2( void ); +#endif +#ifdef _MO_LOGIN_NO_KICK +int getLoginNoKick(void); +#endif +#ifdef _MO_ILLEGAL_NAME +char* getIllegalName( int index ); +#endif +#ifdef _NO_USE_PACKET_MAP +int getNoPacketMap( int index ); +#endif +#ifdef _NO_USE_MAGIC_MAP +int getNoMagicMap( int index ); +#endif +#ifdef _SOME_PETMAIL +int getPetMailFlg(void); +int getPetMailPetid( unsigned int index ); +#endif +#ifdef _CTRL_TRANS_DEVELOP +int getCtrlTrans(void); +#endif +#ifdef _PETMAIL_TIME +int getPetMailTime(void); +#endif +#ifdef _UP_BBPETPROB +int getUpBBProb(void); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/correct_bug.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/correct_bug.h new file mode 100644 index 0000000..c9d6eb2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/correct_bug.h @@ -0,0 +1,20 @@ +#ifndef __CORRECT_BUG_H__ +#define __CORRECT_BUG_H__ + +/* ----------------------- () ---------------------------*/ +#define _add_item_log_name // WON ADD itemlogitem +#define _PETSKILLBUG // Syu ADD +#define _FIXWOLF // Syu ADD ˱Bug +#define _FIXMAGICBUG // Syu ADD ħԱ +#define _FIXPETFALL // Syu ADD +#define _FIX_ITEMRELIFE // WON ADD +#define _FIX_SPEED_UPLEVEL // WON ADD +#define _FIX_PETMAIL // WON ADD +#define _FIX_EQUIP_ITEM // WON ADD װ +#define _ADD_PETMAIL_NUM // WON ADD GMָ +#define _FIX_equipNoenemy // WON ADD ̫ +#define _FIX_PETMAIL2 // WON ADD 2 +#define _FIXITEMANISHOW // Syu ADD غԲѪװʱﲻʾ +#define _kr_ip // WON ADD gmָip + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultGroundEnemy.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultGroundEnemy.h new file mode 100644 index 0000000..8dba339 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultGroundEnemy.h @@ -0,0 +1,158 @@ +#if 0 +static Char slime= +{ + FALSE, /* use ɤǤ⤤*/ + + /* data */ + { + 0, /* CHAR_DATAPLACENUMBER */ + 0, /* CHAR_BASEIMAGENUMBER */ + 0, /* CHAR_BASEBASEIMAGENUMBER */ + 0, /* CHAR_FACEIMAGENUMBER */ + 0, /* CHAR_FLOOR */ + 0, /* CHAR_X */ + 0, /* CHAR_Y */ + 0, /* CHAR_DIR 120˻׼ */ + 0, /* CHAR_LV */ + 0, /* CHAR_GOLD */ + 1, /* CHAR_HP */ + 0, /* CHAR_MP */ + 0, /* CHAR_MAXMP */ + + 0, /* CHAR_VITAL */ + 0, /* CHAR_STR */ + 0, /* CHAR_TOUGH */ + 0, /* CHAR_DEX */ + + 0, /* CHAR_CHARM */ + 0, /* CHAR_LUCK */ + + 0, /* ° */ + 0, /* ° */ + 0, /* ° */ + 0, /* ° */ + + 0, /* CHAR_SLOT */ + 0, /* CHAR_CRITIAL */ + 0, /* CHAR_COUNTER */ + 0, /* CHAR_RARE */ + 0, /* CHAR_RADARSTRLENGTH */ + 0, /* CHAR_CHATVOLUME */ + MAKE2VALUE(100,20), /* CHAR_MERCHANTLEVEL */ + 0, /* CHAR_HEALERLEVEL */ + 0, /* CHAR_DETERMINEITEM */ + + -1, /* CHAR_INDEXOFEQTITLE */ + + 0, /* CHAR_POISON */ + 0, /* CHAR_PARALYSIS */ + 0, /* CHAR_SILENCE */ + 0, /* CHAR_STONE */ + 0, /* CHAR_DARKNESS */ + 0, /* CHAR_CONFUSION */ + + 0, /* CHAR_LOGINCOUNT */ + 0, /* CHAR_DEADCOUNT */ + 0, /* CHAR_WALKCOUNT */ + 0, /* CHAR_TALKCOUNT */ + 0, /* CHAR_DAMAGECOUNT */ + 0, /* CHAR_GETPETCOUNT */ + 0, /* CHAR_KILLPETCOUNT */ + 0, /* CHAR_DEADPETCOUNT */ + 0, /* CHAR_SENDMAILCOUNT */ + 0, /* CHAR_MERGEITEMCOUNT */ + 0, /* CHAR_DUELBATTLECOUNT */ + 0, /* CHAR_DUELWINCOUNT */ + 0, /* CHAR_DUELLOSECOUNT */ + 0, /* CHAR_DUELSTWINCOUNT */ + 0, /* CHAR_DUELMAXSTWINCOUNT */ + + CHAR_TYPEENEMY, /* CHAR_WHICHPLAYER */ + 1000, /* CHAR_WALKINTERVAL */ + 1000, /* CHAR_LOOPINTERVAL */ + + 0, /* CHAR_LEVELEXP */ + + -1, /*CHAR_LASTTALKELDER*/ + 0, /*CHAR_SKILLUPPOINT */ + 0, /* CHAR_LEVELUPPOINT */ + + 0, /*CHAR_IMAGETYPE */ + CHAR_COLORYELLOW, /* CHAR_NAMECOLOR */ + CHAR_COLORYELLOW, /* CHAR_POPUPNAMECOLOR */ + 0, /* CHAR_LASTTIMESETLUCK */ + 0, /* CHAR_DUELPOINT */ + 0, /* CHAR_EVENT */ + 0, /* CHAR_EVENT2 */ + 0, /* CHAR_EVENT3 */ +#ifdef _NEWEVENT + 0, /* CHAR_EVENT4 */ + 0, /* CHAR_EVENT5 */ + 0, /* CHAR_EVENT6 */ +#endif + 0, /* CHAR_NOWEVENT */ + 0, /* CHAR_NOWEVENT2 */ + 0, /* CHAR_NOWEVENT3 */ +#ifdef _NEWEVENT + 0, /* CHAR_NOWEVENT4 */ + 0, /* CHAR_NOWEVENT5 */ + 0, /* CHAR_NOWEVENT6 */ +#endif + 0, /* CHAR_TRANSMIGRATION */ + 0, /* CHAR_TRANSEQUATION */ + + 0, /*CHAR_INITDATA */ + }, + { + {""}, /* CHAR_NAME */ + {""}, /* CHAR_OWNTITLE */ + {""}, /* CHAR_ARGUMENT */ + {""}, /* CHAR_OWNERCDKEY */ + {""}, /* CHAR_OWNERCHARANAME */ +#if 0 + {""}, /* CHAR_INITFUNC */ + {""}, /* CHAR_WALKPREFUNC */ + {""}, /* CHAR_WALKPOSTFUNC */ + {""}, /* CHAR_PREOVERFUNC */ + {""}, /* CHAR_PREOVERFUNC */ + {""}, /* CHAR_WATCHFUNC */ + {""}, /* CHAR_LOOPFUNC */ + {""}, /* CHAR_DYINGFUNC */ + {""}, /* CHAR_TALKEDFUNC */ + {""}, /* CHAR_PREATTACKEDFUNC */ + {""}, /* CHAR_POSTATTACKEDFUNC */ + {""}, /* CHAR_OFFFUNC */ + {""}, /* CHAR_LOOKEDFUNC */ + {""}, /* CHAR_ITEMPUTFUNC */ + {""}, /* CHAR_SPECIALTALKEDFUNC */ + {""}, /* CHAR_WINDOWTALKEDFUNC */ +#endif + }, + { + /* CHAR_ISATTACK */ + /* CHAR_ISATTACKED */ + /* CHAR_ISOVER */ + /* CHAR_ISOVERED */ + /* CHAR_HAVEHEIGHT */ + /* CHAR_ISVISIBLE */ + /* CHAR_ISTRANSPARENT */ + /* CHAR_ISFLYING */ + + SETFLG(1,1,1,1,1,1,0,0 ), + + /* CHAR_ISDIE */ + /* CHAR_ISBIG */ + /* CHAR_ISSHOWDAMAGE */ + /* CHAR_ISPARTY */ + /* CHAR_ISWARP */ + /* CHAR_ISDUEL */ + /* CHAR_ISPARTYCHAT */ + /* CHAR_ISTRADECARD */ + + SETFLG(0,0,1,0,0,0,0,0 ), + } +}; +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultPlayer.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultPlayer.h new file mode 100644 index 0000000..f0162cd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/defaultPlayer.h @@ -0,0 +1,496 @@ +#include "version.h" + +static Char player= +{ + FALSE, /* use ɤǤ⤤*/ + { + 0, /* CHAR_DATAPLACENUMBER */ + 0, /* CHAR_BASEIMAGENUMBER */ + 0, /* CHAR_BASEBASEIMAGENUMBER */ + 0, /* CHAR_FACEIMAGENUMBER */ + 0, /* CHAR_FLOOR */ + 0, /* CHAR_X */ + 0, /* CHAR_Y */ + 5, /* CHAR_DIR 120˻׼ */ + 1, /* CHAR_LV */ + 0, /* CHAR_GOLD */ + 1, /* CHAR_HP */ + 0, /* CHAR_MP */ + + 0, /* CHAR_MAXMP */ + + 0, /* CHAR_VITAL */ + 0, /* CHAR_STR */ + 0, /* CHAR_TOUGH */ + 0, /* CHAR_DEX */ + + 0, /* CHAR_CHARM */ + 0, /* CHAR_LUCK */ + 0, /* ° */ + 0, /* ° */ + 0, /* ° */ + 0, /* ° */ + + 0, /* CHAR_SLOT*/ + 0, /* CHAR_CRITIAL */ + 0, /* CHAR_COUNTER */ + 0, /* CHAR_RARE */ + 0, /* CHAR_RADARSTRLENGTH */ + 0, /* CHAR_CHATVOLUME */ + MAKE2VALUE(100,20), /* CHAR_MERCHANTLEVEL */ + 0, /* CHAR_HEALERLEVEL */ + 0, /* CHAR_DETERMINEITEM */ + + -1, /* CHAR_INDEXOFEQTITLE */ + + + 0, /* CHAR_POISON */ + 0, /* CHAR_PARALYSIS */ + 0, /* CHAR_SILENCE */ + 0, /* CHAR_STONE */ + 0, /* CHAR_DARKNESS */ + 0, /* CHAR_CONFUSION */ + + 0, /* CHAR_LOGINCOUNT */ + 0, /* CHAR_DEADCOUNT */ + 0, /* CHAR_WALKCOUNT */ + 0, /* CHAR_TALKCOUNT */ + + 0, /* CHAR_DAMAGECOUNT */ + 0, /* CHAR_GETPETCOUNT */ + 0, /* CHAR_KILLPETCOUNT */ + 0, /* CHAR_DEADPETCOUNT */ + 0, /* CHAR_SENDMAILCOUNT */ + 0, /* CHAR_MERGEITEMCOUNT */ + + 0, /* CHAR_DUELBATTLECOUNT */ + 0, /* CHAR_DUELWINCOUNT */ + 0, /* CHAR_DUELLOSECOUNT */ + 0, /* CHAR_DUELSTWINCOUNT */ + 0, /* CHAR_DUELMAXSTWINCOUNT */ + 0, /* CHAR_DUELMAXSTWINCOUNT */ + + CHAR_TYPEPLAYER, /* CHAR_WHICHTYPE */ + 1000, /* CHAR_WALKINTERVAL */ + 1000, /* CHAR_LOOPINTERVAL */ +#ifdef _NEWOPEN_MAXEXP + 0, // CHAR_OLDEXP, +#endif + 0, // CHAR_EXP, + -1, /* CHAR_LASTTALKELDER*/ + 0, /* CHAR_SKILLUPPOINT */ + 0, /* CHAR_LEVELUPPOINT */ + + 0, /* CHAR_IMAGETYPE */ + CHAR_COLORWHITE, /* CHAR_NAMECOLOR */ + CHAR_COLORWHITE, /* CHAR_POPUPNAMECOLOR */ + 0, /* CHAR_LASTTIMESETLUCK */ + 0, /* CHAR_DUELPOINT */ + 0, /* CHAR_EVENT */ + 0, /* CHAR_EVENT2 */ + 0, /* CHAR_EVENT3 */ +#ifdef _NEWEVENT + 0, /* CHAR_EVENT4 */ + 0, /* CHAR_EVENT5 */ + 0, /* CHAR_EVENT6 */ +#endif +#ifdef _ADD_NEWEVENT // WON + 0, /* CHAR_EVENT7 */ + 0, // CHAR_EVENT8, 224~255 ٻר +#endif +#ifdef _ADD_NEWEVENT_1024 + 0, /* CHAR_EVENT9 */ + 0, /* CHAR_EVENT10 */ + 0, /* CHAR_EVENT11 */ + 0, /* CHAR_EVENT12 */ + 0, /* CHAR_EVENT13 */ + 0, /* CHAR_EVENT14 */ + 0, /* CHAR_EVENT15 */ + 0, /* CHAR_EVENT16 */ + 0, /* CHAR_EVENT17 */ + 0, /* CHAR_EVENT18 */ + 0, /* CHAR_EVENT19 */ + 0, /* CHAR_EVENT20 */ + 0, /* CHAR_EVENT21 */ + 0, /* CHAR_EVENT22 */ + 0, /* CHAR_EVENT23 */ + 0, /* CHAR_EVENT24 */ + 0, /* CHAR_EVENT25 */ + 0, /* CHAR_EVENT26 */ + 0, /* CHAR_EVENT27 */ + 0, /* CHAR_EVENT28 */ + 0, /* CHAR_EVENT29 */ + 0, /* CHAR_EVENT30 */ + 0, /* CHAR_EVENT31 */ + 0, /* CHAR_EVENT32 */ +#endif + 0, /* CHAR_NOWEVENT */ + 0, /* CHAR_NOWEVENT2 */ + 0, /* CHAR_NOWEVENT3 */ +#ifdef _NEWEVENT + 0, /* CHAR_NOWEVENT4 */ + 0, /* CHAR_NOWEVENT5 */ + 0, /* CHAR_NOWEVENT6 */ +#endif +#ifdef _ADD_NEWEVENT // WON + 0, /* CHAR_NOWEVENT7 */ + 0, // CHAR_NOWEVENT8, 224~255 ٻר +#endif +#ifdef _ADD_NEWEVENT_1024 // WON + 0, /* CHAR_NOWEVENT9 */ + 0, /* CHAR_NOWEVENT10 */ + 0, /* CHAR_NOWEVENT11 */ + 0, /* CHAR_NOWEVENT12 */ + 0, /* CHAR_NOWEVENT13 */ + 0, /* CHAR_NOWEVENT14 */ + 0, /* CHAR_NOWEVENT15 */ + 0, /* CHAR_NOWEVENT16 */ + 0, /* CHAR_NOWEVENT17 */ + 0, /* CHAR_NOWEVENT18 */ + 0, /* CHAR_NOWEVENT19 */ + 0, /* CHAR_NOWEVENT20 */ + 0, /* CHAR_NOWEVENT21 */ + 0, /* CHAR_NOWEVENT22 */ + 0, /* CHAR_NOWEVENT23 */ + 0, /* CHAR_NOWEVENT24 */ + 0, /* CHAR_NOWEVENT25 */ + 0, /* CHAR_NOWEVENT26 */ + 0, /* CHAR_NOWEVENT27 */ + 0, /* CHAR_NOWEVENT28 */ + 0, /* CHAR_NOWEVENT29 */ + 0, /* CHAR_NOWEVENT30 */ + 0, /* CHAR_NOWEVENT31 */ + 0, /* CHAR_NOWEVENT32 */ +#endif + 0, /* CHAR_TRANSMIGRATION */ + 0, /* CHAR_TRANSEQUATION */ + + 0, /* CHAR_INITDATA */ + +//#ifdef _PETSKILL_BECOMEPIG +// -1, +//#endif + + 0, //CHAR_SILENT, /* char shutup time */ + 0, // CHAR_FMINDEX, // a index + 0, // CHAR_FMLEADERFLAG, + /* aڦ + * FMMEMBER_NONE :S[Ja + * FMMEMBER_APPLY :ӽХ[Jaڤ + * FMMEMBER_LEADER :ڪ + * FMMEMBER_MEMBER :@릨 + * FMMEMBER_ELDER : + * FMMEMBER_INVITE :q // Ȯɤ + * FMMEMBER_BAILEE :]Ȫ // Ȯɤ + * FMMEMBER_VICELEADER :Ʊڪ // Ȯɤ + */ + 0, // CHAR_FMSPRITE, // aڦu@F + + 0, // CHAR_BANKGOLD, + 0, // CHAR_RIDEPET, + 0, // CHAR_LEARNRIDE, +#ifdef _NEW_RIDEPETS + 0, // CHAR_LOWRIDEPETS, +#endif + 0, // CHAR_LIMITLEVEL, +#ifdef _PET_FUSION + 0, // CHAR_FUSIONCODE, //ؽsX + 0, // CHAR_FUSIONINDEX, //ds + 0, // CHAR_FUSIONRAISE, //i + 0, // CHAR_FUSIONBEIT, //dJX + 0, // CHAR_FUSIONTIMELIMIT, //iɶ +#endif +#ifdef _PERSONAL_FAME // Arminius 8.30: aڭӤHn + 0, // CHAR_FAME, +#endif + +#ifdef _NEWSAVE + 0, // CHAR_SAVEINDEXNUMBER, /* SaveFile .0.char or .1.char */ +#endif + +#ifdef _ATTACK_MAGIC + 0, // CHAR_EARTH_EXP, // aa]km + 0, // CHAR_WATER_EXP, // a]km + 0, // CHAR_FIRE_EXP, // a]km + 0, // CHAR_WIND_EXP, // a]km + 0, // CHAR_EARTH_RESIST, // aa]kܩ + 0, // CHAR_WATER_RESIST, // a]kܩ + 0, // CHAR_FIRE_RESIST, // a]kܩ + 0, // CHAR_WIND_RESIST, // a]kܩ + 0, // CHAR_EARTH_ATTMAGIC_EXP, // aa]km׸g + 0, // CHAR_WATER_ATTMAGIC_EXP, // a]km׸g + 0, // CHAR_FIRE_ATTMAGIC_EXP, // a]km׸g + 0, // CHAR_WIND_ATTMAGIC_EXP, // a]km׸g + 0, // CHAR_EARTH_DEFMAGIC_EXP, // aa]kܩʸg + 0, // CHAR_WATER_DEFMAGIC_EXP, // a]kܩʸg + 0, // CHAR_FIRE_DEFMAGIC_EXP, // a]kܩʸg + 0, // CHAR_WIND_DEFMAGIC_EXP, // a]kܩʸg +#endif + + +#ifdef _GAMBLE_BANK + 0, // CHAR_PERSONAGOLD, //ӤHȦ +#endif +#ifdef _DROPSTAKENEW + 0, // CHAR_GAMBLENUM, //n +#endif +#ifdef _ADD_ACTION //npcʧ@ + 0, // CHAR_ACTIONSTYLE, +#endif +#ifdef _PET_EVOLUTION + 0, // CHAR_EVOLUTIONBASEVTL, + 0, // CHAR_EVOLUTIONBASESTR, + 0, // CHAR_EVOLUTIONBASETGH, + 0, // CHAR_EVOLUTIONBASEDEX, +#endif + +#ifdef _FM_JOINLIMIT + 0, // CHAR_FMTIMELIMIT, +#endif + +#ifdef _CHAR_PROFESSION // WON ADD H¾~ + 0, // PROFESSION_CLASS, // ¾~O + 0, // PROFESSION_LEVEL, // ¾~ +// 0, // PROFESSION_EXP, // ¾~g + 0, // PROFESSION_SKILL_POINT, // ޯI + 0, // ATTACHPILE, // W[| + 0, // PROFESSION_FIRE_P, // m + 0, // PROFESSION_ICE_P, // Bm + 0, // PROFESSION_THUNDER_P, // pm + 0, // PROFESSION_FIRE_R, // ܩ + 0, // PROFESSION_ICE_R, // Bܩ + 0, // PROFESSION_THUNDER_R, // pܩ +#endif +#ifdef _ALLDOMAN // (i}) Syu ADD Ʀ]NPC + 0, // CHAR_HEROFLOOR, +#endif +#ifdef _PETSKILL_BECOMEPIG + -1, // CHAR_BECOMEPIG, + 100250, //CHAR_BECOMEPIG_BBI +#endif + 0, // CHAR_LASTLEAVETIME, // Robin add ̫uɶ + +#ifdef _NEW_MANOR_LAW + 0, // CHAR_MOMENTUM, +#endif + +#ifdef _ITEM_ADDEXP2 + 0, // CHAR_ADDEXPPOWER, + 0, // CHAR_ADDEXPTIME, +#endif + +#ifdef _ANGEL_SUMMON + 0, // CHAR_HEROCNT, // i̥Ȫ +#endif + +#ifdef _TEACHER_SYSTEM + 0, // CHAR_TEACHER_FAME, // ʦ쵼 +#endif + +#ifdef _GM_ITEM + 0, // GM +#endif +#ifdef _VIP_SERVER + 0, // ػر +#endif +#ifdef _VIP_RIDE + 0, // Աڼ + 0, +#endif +#ifdef _PET_BEATITUDE + 0, +#endif +#ifdef _RIDE_CF + 0, +#ifdef _ADD_RIDE_CF + 0, +#endif +#endif + +#ifdef _ITEM_PET_LOCKED + 0, +#endif + +#ifdef _BOUND_TIME + 0, +#endif + +#ifdef _SUPER + 0, +#endif + +#ifdef _ONLINE_SHOP + 0, +#endif + + +#ifdef _LOTTERY_SYSTEM + 0, + 0, +#endif + +#ifdef _COMPOUND_EXP + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#endif + +#ifdef _ONLINE_TIME + 0, +#endif + +#ifdef _CAMEO_MONEY + 0, +#endif + +#ifdef _MISSION_TRAIN + 0, + 0, +#endif +#ifdef _PET_EVOLVE + 0, +#endif +#ifdef _FLOOR_DIFI_FIELD + 0, +#endif + +#ifdef _ACTIVE_GAME + 0, +#endif + +#ifdef _PLAYER_TITLE + 0, + 0, +#endif +#ifdef _MISSION_TIME + 0, +#endif +#ifdef _REGISTRATION_TIME + 0, + 0, +#endif +#ifdef _SPECIAL_COUNTER + 0 , +#endif +#ifdef _SPECIAL_TIMER + 0, +#endif +#ifdef _OFFLINE_TIME + 0, +#endif + }, + + { + {""}, /* CHAR_NAME */ + {""}, /* CHAR_OWNTITLE */ + {""}, /* CHAR_ARGUMENT */ + {""}, /* CHAR_OWNERCDKEY */ + {""}, /* CHAR_OWNERCHARANAME */ + + {""}, +#ifdef _UNIQUE_P_I + {""}, +#endif + +#ifdef _TEACHER_SYSTEM + {""}, // ʦʺ + {""}, // ʦ +#endif +#ifdef _ITEM_SETLOVER + {""}, // ж + {""}, // ʺ + {""}, // +#endif + +#ifdef _GM_ITEM + {""}, // GM +#endif +#ifdef _NEW_NAME //Զƺ + {""}, +#endif + +#ifdef _LOTTERY_SYSTEM + {""}, +#endif + + + }, + { + SETFLG(1,1,1,1,1,1,0,0 ), + SETFLG(0,0,0,0,0,0,0,1 ), + } +}; + +LevelUpPattern lvplayer00={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer10={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer20={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer30={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer01={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer11={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer21={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer31={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer02={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer12={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer22={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer32={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer03={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer13={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer23={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer33={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer04={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer14={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer24={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer34={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer05={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer15={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer25={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer35={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer06={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer16={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer26={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer36={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer07={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer17={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer27={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer37={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer08={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer18={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer28={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer38={ {{100,10},{200,10},{50,8}},9,11,10}; + +LevelUpPattern lvplayer09={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer19={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer29={ {{100,10},{200,10},{50,8}},9,11,10}; +LevelUpPattern lvplayer39={ {{100,10},{200,10},{50,8}},9,11,10}; + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/encount.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/encount.h new file mode 100644 index 0000000..e3762f8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/encount.h @@ -0,0 +1,40 @@ +#ifndef __ENCOUNT_H__ +#define __ENCOUNT_H__ + +#define ENCOUNT_GROUPMAXNUM 10 + +BOOL ENCOUNT_initEncount( char* filename ); +BOOL ENCOUNT_reinitEncount( void ); +int ENCOUNT_getEncountAreaArray( int floor, int x, int y); +int ENCOUNT_getEncountPercentMin( int charaindex, int floor , int x, int y ); +int ENCOUNT_getEncountPercentMax( int charaindex, int floor , int x, int y ); +int ENCOUNT_getCreateEnemyMaxNum( int floor , int x, int y ); +int ENCOUNT_getEncountIndex( int floor , int x, int y ); +int ENCOUNT_getEncountIndexFromArray( int array ); +int ENCOUNT_getEncountPercentFromArray( int array ); +int ENCOUNT_getCreateEnemyMaxNumFromArray( int array ); +int ENCOUNT_getGroupIdFromArray( int array, int grouparray ); +int ENCOUNT_getGroupProbFromArray( int array, int grouparray ); +int ENCOUNT_getZorderFromArray( int array ); + +#ifdef _ADD_ENCOUNT // WON ADD ӵ޼ +typedef struct tagENCOUNT_Table +{ + int index; + int floor; + int encountprob_min; /* ޼ */ + int encountprob_max; /* ޼ */ + int enemymaxnum; /* ľë¾ */ + int zorder; + int groupid[ENCOUNT_GROUPMAXNUM]; /* No */ + int createprob[ENCOUNT_GROUPMAXNUM]; /* */ + int event_now; + int event_end; + int enemy_group; // group + RECT rect; +}ENCOUNT_Table; + +ENCOUNT_Table *ENCOUNT_table; +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemy.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemy.h new file mode 100644 index 0000000..9f5b9ee --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemy.h @@ -0,0 +1,253 @@ +#ifndef __ENEMY_H__ +#define __ENEMY_H__ + +enum +{ + E_T_SIZE_NORMAL, + E_T_SIZE_BIG, +}; + +typedef enum +{ + E_T_TEMPNO, + E_T_INITNUM, + E_T_LVUPPOINT, + E_T_BASEVITAL, + E_T_BASESTR, + E_T_BASETGH, + E_T_BASEDEX, + E_T_MODAI, + E_T_GET, + E_T_EARTHAT, + E_T_WATERAT, + E_T_FIREAT, + E_T_WINDAT, + E_T_POISON, /* ̫ĸ */ + E_T_PARALYSIS, /* ̫ľ1 ƥئУ */ + E_T_SLEEP, /* Ի۵ ƥئ */ + E_T_STONE, /* ޣ۵ ƥئ */ + E_T_DRUNK, /* 쵤 Ʊ */ + E_T_CONFUSION, /* ٣ ë */ + E_T_PETSKILL1, + E_T_PETSKILL2, + E_T_PETSKILL3, + E_T_PETSKILL4, + E_T_PETSKILL5, + E_T_PETSKILL6, + E_T_PETSKILL7, + E_T_RARE, + E_T_CRITICAL, + E_T_COUNTER, + E_T_SLOT, + E_T_IMGNUMBER, + E_T_PETFLG, + E_T_SIZE, + E_T_ATOMBASEADD1, + E_T_ATOMFIXMIN1, + E_T_ATOMFIXMAX1, + E_T_ATOMBASEADD2, + E_T_ATOMFIXMIN2, + E_T_ATOMFIXMAX2, + E_T_ATOMBASEADD3, + E_T_ATOMFIXMIN3, + E_T_ATOMFIXMAX3, + E_T_ATOMBASEADD4, + E_T_ATOMFIXMIN4, + E_T_ATOMFIXMAX4, + E_T_ATOMBASEADD5, + E_T_ATOMFIXMIN5, + E_T_ATOMFIXMAX5, + E_T_LIMITLEVEL, // Arminius 7.30 limit level +#ifdef _PET_FUSION + E_T_FUSIONCODE, +#endif + E_T_DATAINTNUM, +}ENEMYTEMP_DATAINT; + +typedef enum +{ + E_T_NAME, + E_T_ATOMFIXNAME1, + E_T_ATOMFIXNAME2, + E_T_ATOMFIXNAME3, + E_T_ATOMFIXNAME4, + E_T_ATOMFIXNAME5, + E_T_DATACHARNUM, + +}ENEMYTEMP_DATACHAR; + +typedef enum +{ + ENEMY_ID, + ENEMY_TEMPNO, + ENEMY_LV_MIN, + ENEMY_LV_MAX, + ENEMY_CREATEMAXNUM, + ENEMY_CREATEMINNUM, + ENEMY_TACTICS, + ENEMY_EXP, + ENEMY_DUELPOINT, + ENEMY_STYLE, + ENEMY_PETFLG, /* ʸئ¾ */ + + ENEMY_ITEM1, + ENEMY_ITEM2, + ENEMY_ITEM3, + ENEMY_ITEM4, + ENEMY_ITEM5, + ENEMY_ITEM6, + ENEMY_ITEM7, + ENEMY_ITEM8, + ENEMY_ITEM9, + ENEMY_ITEM10, + ENEMY_ITEMPROB1, + ENEMY_ITEMPROB2, + ENEMY_ITEMPROB3, + ENEMY_ITEMPROB4, + ENEMY_ITEMPROB5, + ENEMY_ITEMPROB6, + ENEMY_ITEMPROB7, + ENEMY_ITEMPROB8, + ENEMY_ITEMPROB9, + ENEMY_ITEMPROB10, + + ENEMY_DATAINTNUM, + +}ENEMY_DATAINT; + +typedef enum +{ + ENEMY_NAME, + ENEMY_TACTICSOPTION, +#ifdef _BATTLENPC_WARP_PLAYER + ENEMY_ACT_CONDITION, +#endif + ENEMY_DATACHARNUM, +}ENEMY_DATACHAR; + +typedef enum +{ + GROUP_ID, + GROUP_APPEARBYITEMID, /* ʧ ةë Ȼ -1 */ + GROUP_NOTAPPEARBYITEMID, /* ʧ ةë Ȼئ -1 */ + ENEMY_ID1, + ENEMY_ID2, + ENEMY_ID3, + ENEMY_ID4, + ENEMY_ID5, + ENEMY_ID6, + ENEMY_ID7, + ENEMY_ID8, + ENEMY_ID9, + ENEMY_ID10, + CREATEPROB1, + CREATEPROB2, + CREATEPROB3, + CREATEPROB4, + CREATEPROB5, + CREATEPROB6, + CREATEPROB7, + CREATEPROB8, + CREATEPROB9, + CREATEPROB10, + GROUP_DATAINTNUM, +}GROUP_DATAINT; + +typedef enum +{ + GROUP_NAME, + GROUP_DATACHARNUM, + +}GROUP_DATACHAR; + + +typedef struct tagENEMY_EnemyTable +{ + int intdata[ENEMY_DATAINTNUM]; + STRING64 chardata[ENEMY_DATACHARNUM]; + int enemytemparray; +}ENEMY_EnemyTable; + +typedef struct tagENEMYTEMP_Table +{ + int intdata[E_T_DATAINTNUM]; + //ANDY_EDIT + STRING64 chardata[E_T_DATACHARNUM]; + +}ENEMYTEMP_Table; + +typedef struct tagGROUP_Table +{ + int intdata[GROUP_DATAINTNUM]; + STRING32 chardata[GROUP_DATACHARNUM]; + int enemyarray[CREATEPROB1 - ENEMY_ID1]; +}GROUP_Table; + + + +INLINE BOOL ENEMY_CHECKINDEX( int index); +INLINE int ENEMY_setInt( int index, ENEMY_DATAINT element, int data); +INLINE int ENEMY_getInt( int index, ENEMY_DATAINT element); + +INLINE int *ENEMY_getIntdata( int index); + +INLINE BOOL ENEMY_setChar( int index ,ENEMY_DATACHAR element, char* new ); +INLINE char *ENEMY_getChar( int index, ENEMY_DATACHAR element); +int ENEMY_getEnemyNum( void); +BOOL ENEMY_initEnemy( char* filename ); +BOOL ENEMY_reinitEnemy( void ); +int ENEMY_createEnemy( int array, int baselevel ); +int *ENEMY_getEnemy( int charaindex, int x, int y); +int ENEMY_createPetFromEnemyIndex( int charaindex, int array); +int ENEMY_createPet( int array, int vital, int str, int tgh, int dex); +int ENEMY_getEnemyArrayFromId( int EnemyId); +int ENEMY_getEnemyArrayFromTempNo( int EnemyTempNo); +int ENEMY_getEnemyIdFromTempNo( int EnemyTempNo); +int ENEMY_getEnemyTempNoFromId( int EnemyId); + +#ifdef _TEST_DROPITEMS +int ENEMY_TEST_createPetIndex( int array); +#endif + +int ENEMYTEMP_getEnemyNum( void);//krynn 2001/12/13 +INLINE BOOL ENEMYTEMP_CHECKINDEX( int index); +INLINE int ENEMYTEMP_setInt( int index, ENEMYTEMP_DATAINT element, int data); +INLINE int ENEMYTEMP_getInt( int index, ENEMYTEMP_DATAINT element); +INLINE char *ENEMYTEMP_getChar( int index, ENEMYTEMP_DATACHAR element); +INLINE BOOL ENEMYTEMP_getInt_setChar( int index ,ENEMYTEMP_DATACHAR element, char* new ); +INLINE char *ENEMYTEMP_getInt_getChar( int index, ENEMYTEMP_DATACHAR element); +int ENEMYTEMP_getInt_getEnemyNum( void); +BOOL ENEMYTEMP_getInt_initEnemy( char* filename ); +BOOL ENEMYTEMP_getInt_reinitEnemy( void ); +int ENEMYTEMP_getEnemyTempArray( int enemyindex); +int ENEMYTEMP_getEnemyTempArrayFromTempNo( int EnemyTempNo); +int ENEMYTEMP_getEnemyTempArrayFromInitnum( int EnemyTempNo); + +INLINE int GROUP_setInt( int index, GROUP_DATAINT element, int data); +INLINE int GROUP_getInt( int index, GROUP_DATAINT element); +INLINE BOOL GROUP_setChar( int index ,GROUP_DATACHAR element, char* new ); +INLINE char *GROUP_getChar( int index, GROUP_DATACHAR element); +int GROUP_getEnemyNum( void); + +BOOL ENEMYTEMP_initEnemy( char* filename ); +BOOL ENEMYTEMP_reinitEnemy( void ); +BOOL GROUP_initGroup( char* filename ); +BOOL GROUP_reinitGroup( void ); + +#ifdef _PET_EVOLUTION +int EVOLUTION_createPetFromEnemyIndex( int charaindex, int baseindex, int flg); +int PET_CheckIncubate( int charaindex); +BOOL PETFUSION_getIndexForChar( int toindex, int *MainIndex, int *Subindex1,int *Subindex2, char *data); +int NPC_getFusionTableForBase( int charaindex, int petindex1, int petindex2 ); +int NPC_getPetArrayForNo( int PetCode); +BOOL PET_getEvolutionAns( int petindex, int *base); +#endif + +int PETFUSION_SetNewEgg( int toindex , int petindex, int array, int *work, int *skill1, int *skill2); +BOOL PETFUSION_AddEgg(int toindex, int petID, int PetCode); + +#ifdef _PET_TRANS +int GetNewPet( int toindex , int petindex, int array, int *work); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemyexptbl.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemyexptbl.h new file mode 100644 index 0000000..5113dd4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/enemyexptbl.h @@ -0,0 +1,207 @@ +#ifndef __ENEMY_EXPTBL_H__ +#define __ENEMY_EXPTBL_H__ + + +static int enemybaseexptbl[] = { +1, +2, +3, +4, +5, +6, +9, +12, +15, +18, +22, +26, +30, +35, +40, +46, +52, +58, +65, +72, +79, +87, +95, +104, +113, +122, +131, +141, +151, +162, +173, +184, +196, +208, +220, +233, +246, +260, +274, +288, +303, +318, +333, +348, +365, +381, +398, +415, +432, +450, +468, +486, +506, +525, +545, +564, +585, +606, +627, +648, +670, +692, +714, +737, +760, +784, +808, +832, +857, +882, +907, +933, +959, +956, +1012, +1040, +1067, +1095, +1123, +1152, +1181, +1210, +1240, +1270, +1300, +1331, +1362, +1394, +1426, +1458, +1490, +1524, +1557, +1590, +1625, +1659, +1694, +1729, +1764, +1800, // level 100 +1836, +1872, +1909, +1946, +1983, +2021, +2059, +2097, +2136, +2175, // level 110 +2214, +2254, +2294, +2334, +2374, +2414, +2455, +2496, +2537, +2578, // level 120 +2619, +2661, +2703, +2745, +2787, +2829, +2872, +2915, +2958, +3000, // level 130 +3043, +3088, +3132, +3176, +3220, +3264, +3309, +3354, +3399, +3444, // level 140 +3489, +3535, +3581, +3627, +3673, +3719, +3765, +3812, +3859, +3906, // level 150 +3953, +4000, +4047, +4095, +4143, +4191, +4239, +4287, +4335, +4384, // level 160 +4433, +4482, +4531, +4580, +4629, +4679, +4729, +4779, +4829, +4879, // level 170 +4929, +4980, +5031, +5082, +5133, +5184, +5235, +5287, +5339, +5391, // level 180 +5443, +5495, +5547, +5599, +5652, +5705, +5758, +5811, +5864, +5917, // level 190 +5970, +6024, +6078, +6132, +6186, +6240, +6295, +6350, +6405, +6460, // level 200 +}; +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/epollnet.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/epollnet.h new file mode 100644 index 0000000..8312248 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/epollnet.h @@ -0,0 +1,32 @@ +/* + * epollnet.h + * + * Created on: 20151023 + * Author: hult + */ + +#ifndef EPOLLNET_H_ +#define EPOLLNET_H_ +#ifdef _EPOLL_ET_MODE +//epoll˿ +int epoll_bind(int port); +//acfdӵepoll +int epoll_add_acfd(int acfd); +// +int epoll_set_nonblock(int fd) ; +//עᵽepoll +int epoll_new_conn(int sfd) ; +//epollƳ +int epoll_close_conn(int sfd); +//epoll +int epoll_mod_read(int sfd) ; +//дepoll +int epoll_mod_write(int sfd) ; + +//߳ +int Start_PacketWrapper(); +//epollѭ߳ +int Start_Epoll_Loop(); +//int Start_Epoll_SendLoop(); +#endif +#endif /* EPOLLNET_H_ */ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/event.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/event.h new file mode 100644 index 0000000..17dec66 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/event.h @@ -0,0 +1,9 @@ +#ifndef __EVENT_H__ +#define __EVENT_H__ + +INLINE BOOL EVENT_CHECKEVENTINDEX( int event); +int EVENT_main( int charaindex,int event, int x, int y); + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/family.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/family.h new file mode 100644 index 0000000..460b596 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/family.h @@ -0,0 +1,231 @@ +#ifndef __FAMILY_H__ +#define __FAMILY_H__ + +#include "version.h" +#include "common.h" +#include "util.h" +#include "net.h" +#include "time.h" + +#define FAMILY_MAXNUM 1000 // +#ifdef _FMVER21 +#define FAMILY_MAXMEMBER FAMILY_MAX_MEMBER // +#define FAMILY_MAXCHANNELMEMBER 50 // Ƶ +#else +#define FAMILY_MAXMEMBER 50 // +#define FAMILY_MAXCHANNELMEMBER 10 // Ƶ +#endif +#define FAMILY_MAXCHANNEL 5 // Ƶ + +#define CHAR_MAXNAME 32 +#define CHAR_MAXID 20 +#define MINFMLEVLEFORPOINT 3 // 3 ׯ԰͵ȼ +#define FMLEADERLV 30 // 峤ȼ + +#ifdef _FAMILY_MANORNUM_CHANGE +#define FAMILY_FMPKFLOOR 15 // Уͼ +#else +#define FAMILY_FMPKFLOOR 9 // Уͼ +#define FMPOINTNUM 4 // оݵ +#define MANORNUM 4 +#define FAMILY_MAXHOME 4 // ݵ +#endif + +enum +{ + FM_TOP_INTEGRATE = 1, // DPTOP ۺ + FM_TOP_ADV, // DPTOP ð + FM_TOP_FEED, // DPTOP + FM_TOP_SYNTHESIZE, // DPTOP ϳ + FM_TOP_DEALFOOD, // DPTOP + FM_TOP_PK, // DPTOP У +#ifdef _NEW_MANOR_LAW + FM_TOP_MOMENTUM = 8, // DPTOP +#endif + FM_TOP_NUM, // DPTOP +}; + +enum +{ + FM_FIX_ACCEPTFLAG = 1, + FM_FIX_FMPK, + FM_FIX_FMPET, + FM_FIX_FMRULE, + FM_FIX_DELFMTIME, + FM_FIX_FMGOLD, + FM_FIX_FMADV, + FM_FIX_FMFEED, + FM_FIX_FMSYNTHESIZE, + FM_FIX_FMDEALFOOD, + FM_FIX_FMLEADERCHANGE, +#ifdef _NEW_MANOR_LAW + FM_FIX_FMMOMENTUM, +#endif + FM_FIX_FAME = 13, +#ifdef _FAMILYBADGE_ + FM_FIX_BADGE, +#endif +}; + +/* + * ӡ ְ缰 cdkey charname Ӯë׻ + * CHEKEYLEN, CHARNAMELEN + * ë ʣ + */ + +void CHAR_Family(int fd, int index, char* message); +void ACAddFM(int fd, int result, int fmindex, int index); +void ACJoinFM(int fd, int result, int recv); +void ACLeaveFM(int fd, int result, int resultflag); +void ACDelFM(int fd, int result); +void ACShowFMList(int ret, int fmnum, char *data); +void ACFMDetail(int ret, char *data, int charfdid); +void ACShowMemberList(int result, int index, int fmnumm, +int fmacceptflag, int fmjoinnum, char *data +#ifdef _FAMILYBADGE_ +,int badge +#endif +); + + +void ACShowDpTop(int result,int num, char *data, int kindflag); +void ACShowPointList(int result, char *data); +void ACShowFMMemo(int result, int index, int num, int dataindex, char *data); + +#ifdef _PERSONAL_FAME // Arminius: +void ACFMCharLogin(int fd, int ret, int index, int floor, int fmdp, + int joinflag, int fmsetupflag, int flag, int charindex, int charfame + #ifdef _NEW_MANOR_LAW + ,int momentum + #endif + ); +#else +void ACFMCharLogin(int fd, int ret, int index, int floor, int fmdp, + int joinflag, int fmsetupflag, int flag, int charindex); +#endif + +void ACFMPointList(int ret, char *data); +void ACSetFMPoint(int ret, int r, int clifd); +void ACFMAnnounce(int ret, char *fmname, int fmindex, int index, int kindflag, + char *data, int color); +void ACFixFMPK(int winindex, int loseindex, int data); +void ACFMJob( int fd, int ret, char* data1, char* data2 ); + +void FAMILY_Add(int fd, int meindex, char *message); +void FAMILY_Join(int fd, int meindex, char *message); +void FAMILY_Leave(int fd, int meindex, char *message); +void FAMILY_Detail(int fd, int meindex, char *message); +void FAMILY_CheckMember(int fd, int meindex, char *message); +void FAMILY_Channel(int fd, int meindex, char *message); +void FAMILY_Bank(int fd, int meindex, char *message); +void FAMILY_SetPoint(int fd, int meindex, char *message); +void FAMILY_Init(void); +void FAMILY_SetAcceptFlag(int fd, int meindex, char *message); +void FAMILY_FixRule( int fd, int meindex, char* message ); +int FAMILY_RidePet( int fd, int meindex, char* message ); +void FAMILY_LeaderFunc( int fd, int meindex, char* message ); + +void SetFMPetVarInit(int meindex); +void SetFMVarInit(int meindex); + + +int CheckFMLeader(int meindex); +int getFmLv(int playerindex); + +void getNewFMList( void ); +void checkFamilyIndex( void ); + +int CheckLeaderQ(int meindex); + + +// shan add Begin +struct FMMEMBER_LIST +{ +// int fmindex; + int fmnum; + int fmjoinnum; +// BOOL use; // 0->ûʹ 1->ʹ + int memberindex[FAMILY_MAXMEMBER]; + char numberlistarray[FAMILY_MAXMEMBER][64]; + char memo[35][220]; // family dengon + int accept; // ļԱ + int memonum; + int memoindex; +#ifdef _FAMILYBADGE_ + int badge; +#endif +}; +// ֮԰ +struct FMS_MEMO +{ + char memo[140][220]; + int memonum; + int memoindex; +}; +// ǿ߱ +struct FMS_DPTOP +{ + int num; // ¼жٸ(ۺ) + char topmemo[FAMILY_MAXNUM][128]; + int fmtopid[FAMILY_MAXNUM]; // +#ifdef _FMVER21 + int fmtopdp[FAMILY_MAXNUM]; // ۺ +#endif +#ifdef _NEW_MANOR_LAW + int fmMomentum[FAMILY_MAXNUM]; // + char momentum_topmemo[FAMILY_MAXNUM][96]; // top + int momentum_topid[FAMILY_MAXNUM]; // top id +#endif + int adv_num; // ð + char adv_topmemo[30][96]; + int feed_num; // + char feed_topmemo[30][96]; + int syn_num; // ϳ + char syn_topmemo[30][96]; + int food_num; // + char food_topmemo[30][96]; + int pk_num; // У + char pk_topmemo[30][96]; +}; +// ݵ +struct FM_POINTLIST +{ + char pointlistarray[FAMILY_MAXHOME][1024]; // Arminius: 32->1024 +#ifdef _NEW_MANOR_LAW + int fm_momentum[FAMILY_MAXHOME]; // ¼սʱڿʼʱׯֵ + BOOL fm_inwar[FAMILY_MAXHOME]; // ׯ԰Ƿׯ԰ų +#endif +}; +// PKͼ +struct FM_PKFLOOR +{ + int fl; +}; +// End + +#ifdef _NEW_MANOR_LAW +typedef struct _ManorSchedule_t{ + int iFmIndex[10]; // սų̵ļ + int iFmMomentum[10]; // + int iSort[10]; // + char szMemo[10][256]; // ¼: |Լսʱ| + char szFmName[10][32]; // + struct tm tm1[10]; // ¼սʱ +}ManorSchedule_t; + +extern ManorSchedule_t ManorSchedule[MANORNUM]; +#endif + +#define MAXFAMILYLIST 128*1024 +extern char familyListBuf[MAXFAMILYLIST]; + +void JoinMemberIndex( int charaindex, int fmindexi); + +int channelMember[FAMILY_MAXNUM][FAMILY_MAXCHANNEL][FAMILY_MAXMEMBER]; +int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + +#ifdef _MO_LNS_CHARSUOXU +int Char_GetFm( int id, int x); +char * FM_getManorData(int ManorId,int Flg); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/function.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/function.h new file mode 100644 index 0000000..cd8d34d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/function.h @@ -0,0 +1,5 @@ +#ifndef __FUNCTION_H__ +#define __FUNCTION_H__ +BOOL initFunctionTable( void ); +void* getFunctionPointerFromName( char* funcname ); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/handletime.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/handletime.h new file mode 100644 index 0000000..048ab78 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/handletime.h @@ -0,0 +1,59 @@ +#ifndef __HANDLETIME_H__ +#define __HANDLETIME_H__ + +#include + +#include "common.h" + +#undef EXTERN +#ifdef __HANDLETIME_C__ +#define EXTERN +#else /*__HANDLETIME_C__*/ +#define EXTERN extern +#endif + +EXTERN struct timeval NowTime; +EXTERN int DEBUG_ADJUSTTIME; + +BOOL setNewTime( void ); +#ifdef _ASSESS_SYSEFFICACY +void Assess_InitSysEfficacy( void); +void Assess_SysEfficacy( int flg); +void ASSESS_getSysEfficacy( float *TVsec); +#ifdef _ASSESS_SYSEFFICACY_SUB +void Assess_SysEfficacy_sub( int flg, int loop); +void ASSESS_getSysEfficacy_sub( float *TVsec, int loop); +#endif +#endif +// WON REM +//struct tm *localtime(const time_t *timep); + +/*ƱHiOLS*/ +/* 150()*60=9000 =750*12 ƥ LS1 */ +/* LS1200 LS1 */ +/* LS100 ƥ LS1 */ +typedef struct tagLSTIME +{ + int year; + int day; + int hour; +}LSTIME; + +#define NIGHT_TO_MORNING 700 +#define MORNING_TO_NOON 930 +#define NOON_TO_EVENING 200 +#define EVENING_TO_NIGHT 300 + +typedef enum +{ + LS_NIGHT = 0, + LS_MORNING , + LS_NOON , + LS_EVENING , +}LSTIME_SECTION; + +void RealTimeToLSTime(long t , LSTIME *lstime); +/*void LSTimeToRealTime( LSTIME *lstime, long *t);*/ +LSTIME_SECTION getLSTime (LSTIME *lstime); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/init.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/init.h new file mode 100644 index 0000000..bb786b5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/init.h @@ -0,0 +1,17 @@ +#ifndef __INIT_H__ +#define __INIT_H__ +#include "common.h" +BOOL init( int argc , char** argv, char** env ); + +#ifdef _ITEM_QUITPARTY + +typedef struct tagDisappearItem +{ + char string[64]; +}DisappearItem; +DisappearItem *Disappear_Item; +int itemquitparty_num; + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/item.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item.h new file mode 100644 index 0000000..c34ded5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item.h @@ -0,0 +1,498 @@ + +#ifndef __ITEM_H__ +#define __ITEM_H__ + +//#include "char.h" + +#define NULLITEM "0" + +#ifdef _SIMPLIFY_ITEMSTRING +typedef struct ITEM_tag_intDataSetting +{ + char* dumpchar; + int defaults; + int table; + char* string; +}ITEM_intDataSetting; + +typedef struct ITEM_tag_charDataSetting +{ + char* dumpchar; + char* defaults; + int table; + char* string; +}ITEM_charDataSetting; +#endif + +typedef enum +{ + ITEM_FIST =0,// + ITEM_AXE, // + ITEM_CLUB, // + ITEM_SPEAR,//ǹ + ITEM_BOW, // + ITEM_SHIELD,// + ITEM_HELM, //ͷ + ITEM_ARMOUR, // + + ITEM_BRACELET =8, + ITEM_MUSIC, + ITEM_NECKLACE, + ITEM_RING, + ITEM_BELT, + ITEM_EARRING, + ITEM_NOSERING, + ITEM_AMULET, + /* ****** */ + ITEM_OTHER =16, + ITEM_BOOMERANG, // + ITEM_BOUNDTHROW, // Ͷͷ + ITEM_BREAKTHROW, // Ͷʯ + ITEM_DISH =20, +#ifdef _ITEM_INSLAY + ITEM_METAL, + ITEM_JEWEL, +#endif +#ifdef _ITEM_CHECKWARES + ITEM_WARES, // +#endif + +#ifdef _ITEM_EQUITSPACE + ITEM_WBELT, // + ITEM_WSHIELD, // + ITEM_WSHOES, //Ь +#endif +#ifdef _EQUIT_NEWGLOVE + ITEM_WGLOVE, // +#endif + +#ifdef _ALCHEMIST + ITEM_ALCHEMIST =30, +#endif + +#ifdef _PET_ITEM + ITEM_PET_HEAD, + ITEM_PET_TOOTH, + ITEM_PET_CLAW, + ITEM_PET_BREAST, + ITEM_PET_BACK, + ITEM_PET_WING, + ITEM_PET_FEET, +#endif + +#ifdef _ANGEL_SUMMON + //ITEM_ANGELTOKEN, + //ITEM_HEROTOKEN, +#endif + + ITEM_CATEGORYNUM, + +}ITEM_CATEGORY; + +typedef enum +{ + ITEM_FIELD_ALL, + ITEM_FIELD_BATTLE, + ITEM_FIELD_MAP, +}ITEM_FIELDTYPE; + +typedef enum +{ + ITEM_TARGET_MYSELF, + ITEM_TARGET_OTHER, + ITEM_TARGET_ALLMYSIDE, + ITEM_TARGET_ALLOTHERSIDE, + ITEM_TARGET_ALL, +}ITEM_TARGETTYPE; + +typedef enum +{ + ITEM_ID, + ITEM_BASEIMAGENUMBER, + ITEM_COST, + ITEM_TYPE, + ITEM_ABLEUSEFIELD, + ITEM_TARGET, + ITEM_LEVEL, /* LEVEL */ +#ifdef _ITEM_MAXUSERNUM + ITEM_DAMAGEBREAK, //Ʒʹô +#endif + +#ifdef _ITEMSET4_TXT + ITEM_USEPILENUMS, //Ʒѵ + ITEM_CANBEPILE, //Ƿɶѵ + + ITEM_NEEDSTR, + ITEM_NEEDDEX, + ITEM_NEEDTRANS, + ITEM_NEEDPROFESSION, +#endif + + ITEM_DAMAGECRUSHE, + ITEM_MAXDAMAGECRUSHE, + +#ifdef _ADD_DEAMGEDEFC + ITEM_OTHERDAMAGE, + ITEM_OTHERDEFC, +#endif + +#ifdef _SUIT_ITEM + ITEM_SUITCODE, +#endif + + ITEM_ATTACKNUM_MIN, /* */ + ITEM_ATTACKNUM_MAX, /* */ + ITEM_MODIFYATTACK, /* */ + ITEM_MODIFYDEFENCE, /* */ + ITEM_MODIFYQUICK, /* QUICK */ + + ITEM_MODIFYHP, /* HP */ + ITEM_MODIFYMP, /* MP */ + ITEM_MODIFYLUCK, /* LUCK */ + ITEM_MODIFYCHARM, /* CHARM */ + ITEM_MODIFYAVOID, /* Ĥ */ + ITEM_MODIFYATTRIB, /* Ĥ */ + ITEM_MODIFYATTRIBVALUE, /* ĤҰ */ + ITEM_MAGICID, /* į */ + ITEM_MAGICPROB, /* */ + ITEM_MAGICUSEMP, /* MP */ + +#ifdef _ITEMSET5_TXT + ITEM_MODIFYARRANGE, + ITEM_MODIFYSEQUENCE, + + ITEM_ATTACHPILE, + ITEM_HITRIGHT, // +#endif +#ifdef _ITEMSET6_TXT + ITEM_NEGLECTGUARD, +// ITEM_BEMERGE, +#endif + /* ĤҰ*/ + ITEM_POISON, /* ̫ĸ */ + ITEM_PARALYSIS, /* ̫ľ1 ƥئУ */ + ITEM_SLEEP, /* Ի۵ ƥئ */ + ITEM_STONE, /* ޣ۵ ƥئ */ + ITEM_DRUNK, /* 쵤 Ʊ */ + ITEM_CONFUSION, /* ٣ ë */ + + ITEM_CRITICAL, /* ūл Ĥ */ + + ITEM_USEACTION, /* ݼʧ */ + ITEM_DROPATLOGOUT, /* ʧݱ ʾ */ + ITEM_VANISHATDROP, /* ݱ¾ */ + ITEM_ISOVERED, /* Ⱦľ¾*/ + ITEM_CANPETMAIL, /* ʸƥ˪ľ¾ */ + ITEM_CANMERGEFROM, /* ئľ¾ */ + ITEM_CANMERGETO, /* Ʊئľ¾ */ + + ITEM_INGVALUE0, /* (5) */ + ITEM_INGVALUE1, + ITEM_INGVALUE2, + ITEM_INGVALUE3, + ITEM_INGVALUE4, + + ITEM_PUTTIME, /* ʧ ة ľ */ + ITEM_LEAKLEVEL, /* ľľ׾ */ + ITEM_MERGEFLG, /* ľʧ ة */ + ITEM_CRUSHLEVEL, /* çľպ 0 2 ߷çľئ 2ç */ + + ITEM_VAR1, /* ۽ */ + ITEM_VAR2, /* ۽ */ + ITEM_VAR3, /* ۽ */ + ITEM_VAR4, /* ۽ */ + +#ifdef _ITEM_COLOER + ITEM_COLOER, +#endif + +#ifdef _VERSION_GF + ITEM_UNKNOWN1, + ITEM_UNKNOWN2, + ITEM_UNKNOWN3, + ITEM_UNKNOWN4, + ITEM_UNKNOWN5, + ITEM_UNKNOWN6, + ITEM_UNKNOWN7, + ITEM_UNKNOWN8, + ITEM_UNKNOWN9, +#endif +#ifdef _ITEM_USE_TIME + ITEM_USETIME, +#endif + ITEM_DATAINTNUM, + +}ITEM_DATAINT; + +typedef enum +{ + ITEM_NAME, /* 񲼰 */ + ITEM_SECRETNAME, /* ʽľµ Ի */ + ITEM_EFFECTSTRING, /* ٯ */ + ITEM_ARGUMENT, /* ʧ ة¦ */ +#ifdef _ITEM_INSLAY + ITEM_TYPECODE, + ITEM_INLAYCODE, +#endif + ITEM_CDKEY, /* ʧ ة ë ٱ м */ +#ifdef _ITEM_FORUSERNAMES + ITEM_FORUSERNAME, + ITEM_FORUSERCDKEY, +#endif +// CoolFish: 2001/10/11 +#ifdef _UNIQUE_P_I + ITEM_UNIQUECODE, /* Ʒ */ +#endif + + ITEM_INGNAME0, /* м (5) */ + ITEM_INGNAME1, + ITEM_INGNAME2, + ITEM_INGNAME3, + ITEM_INGNAME4, + + + ITEM_INITFUNC, /* ¦ + * ITEM_Item* + * ߯Ի BOOL + * ߯Ի CHAR_INITFUNC + * Ԫ */ + ITEM_FIRSTFUNCTION = ITEM_INITFUNC, + ITEM_PREOVERFUNC, /* CHAR_PREOVERFUNC ë */ + ITEM_POSTOVERFUNC, /* CHAR_POSTOVERFUNC ë*/ + ITEM_WATCHFUNC, /* CHAR_WATCHFUNC ë */ + ITEM_USEFUNC, /* ¦ѷ + * int charaindex ƽҷ̼͵ + * int charitemindex м + * ʧ ة + * ë׾ + */ + ITEM_ATTACHFUNC, /* ¦ѷ + * int charaindex ƽҷ̼͵ + * int itemindex ʧ ة̼͵ + * ƽҷ Ȼʧ ة + * ʧ ة ƥ̼͵ + * ƥئDZ + */ + ITEM_DETACHFUNC, /* ¦ѷ + * int charaindex ƽҷ̼͵ + * int itemindex ʧ ة̼͵ + * ƽҷ Ȼʧ ة + * ʧ ة ƥ̼͵ + * ƥئDZ + */ + ITEM_DROPFUNC, /* + * ¦ѷ + * int charaindex ƽҷ + * int itemindex ʧ ة̼͵ + */ + ITEM_PICKUPFUNC, /* ʧ ةë + * ¦ѷ + * int charaindex ƽҷindex + * int itemindex ʧ ة̼͵ + */ +#ifdef _Item_ReLifeAct + ITEM_DIERELIFEFUNC, /*ANDY_ADD */ +#endif + + ITEM_LASTFUNCTION, + + ITEM_DATACHARNUM = ITEM_LASTFUNCTION, + +#ifdef _ANGEL_SUMMON + ITEM_ANGELMISSION = ITEM_INGNAME0, + ITEM_ANGELINFO = ITEM_INGNAME1, + ITEM_HEROINFO = ITEM_INGNAME2, +#endif +#ifdef _VERSION_GF + ITEM_UNKNOWN10, +#endif +}ITEM_DATACHAR; + +typedef enum +{ + ITEM_WORKOBJINDEX, + ITEM_WORKCHARAINDEX, +#ifdef _ITEM_ORNAMENTS + ITEM_CANPICKUP, +#endif +#ifdef _ITEM_TIME_LIMIT + ITEM_WORKTIMELIMIT, +#endif + +#ifdef _ITEM_TALK_CHECK + ITEM_WORKTALKCHECK, +#endif +#ifdef _PET_AND_ITEM_UP + ITEM_WORKCDKEY, +#endif + + ITEM_WORKDATAINTNUM, +}ITEM_WORKDATAINT; + + + +typedef struct tagItem +{ + int data[ITEM_DATAINTNUM]; + STRING64 string[ITEM_DATACHARNUM]; + int workint[ITEM_WORKDATAINTNUM]; + + void* functable[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; +#ifdef _ALLBLUES_LUA_1_2 + lua_State *lua[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; + char *luafunctable[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; +#endif +#ifdef _JZ_NEWSCRIPT_LUA + STRING32 lua_charfunctable[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; + + void* sur_functable[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; + STRING32 sur_charfunctable[ITEM_LASTFUNCTION-ITEM_FIRSTFUNCTION]; +#endif +}ITEM_Item; + +typedef struct tagITEM_table +{ + int use; + ITEM_Item itm; + int randomdata[ITEM_DATAINTNUM]; +}ITEM_table; + +typedef struct tagITEM_index +{ + BOOL use; + int index; +}ITEM_index; + +typedef struct tagITEM_exists +{ + BOOL use; + ITEM_Item itm; +}ITEM_exists; + +#define ITEM_CHECKINDEX(index) \ + _ITEM_CHECKINDEX( __FILE__, __LINE__, index) +INLINE BOOL _ITEM_CHECKINDEX( char *file, int line, int index); + + +BOOL ITEM_initExistItemsArray( int num ); +BOOL ITEM_endExistItemsArray( ITEM_table* ITEM_item ); +#define ITEM_initExistItemsOne( itm) \ + _ITEM_initExistItemsOne( __FILE__, __LINE__, itm) +int _ITEM_initExistItemsOne( char *file, int line, ITEM_Item* itm ); + +#define ITEM_endExistItemsOne( index ) \ + _ITEM_endExistItemsOne( index, __FILE__, __LINE__) + +void _ITEM_endExistItemsOne( int index , char *file, int line); + +#define ITEM_getInt( Index, element) _ITEM_getInt( __FILE__, __LINE__, Index, element ) +INLINE int _ITEM_getInt( char *file, int line, int index ,ITEM_DATAINT element); + + +#define ITEM_setInt( Index, element, data) _ITEM_setInt( __FILE__, __LINE__, Index, element, data) +INLINE int _ITEM_setInt( char *file, int line, int index ,ITEM_DATAINT element, int data); + + +INLINE char* ITEM_getChar( int index ,ITEM_DATACHAR element ); +INLINE BOOL ITEM_setChar( int index ,ITEM_DATACHAR element , char* new); + +INLINE int ITEM_getWorkInt( int index ,ITEM_WORKDATAINT element); +INLINE int ITEM_setWorkInt( int index ,ITEM_WORKDATAINT element, int data); +INLINE int ITEM_getITEM_itemnum( void ); +INLINE int ITEM_getITEM_UseItemnum( void ); +INLINE BOOL ITEM_getITEM_use( int index ); +void ITEM_constructFunctable( int itemindex ); +#define ITEM_getFunctionPointer( itemindex, functype) _ITEM_getFunctionPointer( itemindex, functype, __FILE__, __LINE__) +void* _ITEM_getFunctionPointer( int itemindex, int functype, char *file, int line ); +#ifdef _ALLBLUES_LUA_1_2 +typedef struct tagITEM_LuaFunc +{ + lua_State *lua; + char luafuncname[128]; + char luafunctable[128]; + struct tagITEM_LuaFunc *next; +}ITEM_LuaFunc; + + +INLINE BOOL ITEM_setLUAFunction( int itemindex, int functype, const char *luafuncname); +INLINE lua_State *ITEM_getLUAFunction( int itemindex, int functype); + +BOOL ITEM_addLUAListFunction( lua_State *L, const char *luafuncname, const char *luafunctable ); +#endif +INLINE ITEM_Item *ITEM_getItemPointer( int index ); +int ITEM_getItemMaxIdNum( void); + + +char* ITEM_makeStringFromItemData( ITEM_Item* one, int mode ); +char* ITEM_makeStringFromItemIndex( int index, int mode ); + +BOOL ITEM_makeExistItemsFromStringToArg( char* src , ITEM_Item* item, int mode ); +void ITEM_getDefaultItemSetting( ITEM_Item* itm); + + +INLINE BOOL ITEM_CHECKITEMTABLE( int number ); +BOOL ITEM_readItemConfFile( char* filename ); + + +CHAR_EquipPlace ITEM_getEquipPlace( int charaindex, int itmid ); + + +char* ITEM_makeItemStatusString( int haveitemindex, int itemindex ); +char* ITEM_makeItemFalseString( void ); +char* ITEM_makeItemFalseStringWithNum( int haveitemindex ); + + +BOOL ITEM_makeItem( ITEM_Item* itm, int number ); +int ITEM_makeItemAndRegist( int number ); + + +void ITEM_equipEffect( int index ); + +void Other_DefcharWorkInt( int index); + +char* ITEM_getAppropriateName(int itemindex); +char* ITEM_getEffectString( int itemindex ); + +int ITEM_getcostFromITEMtabl( int itemid ); + +#define ITEM_getNameFromNumber( id) _ITEM_getNameFromNumber( __FILE__, __LINE__, id) +INLINE char* _ITEM_getNameFromNumber( char *file, int line, int itemid ); + +#define ITEM_getArgumentString( id) _ITEM_getArgumentString( __FILE__, __LINE__, id) +INLINE char* _ITEM_getArgumentString( char *file, int line, int itemid ); + + +int ITEM_getlevelFromITEMtabl( int itemid ); +int ITEM_getgraNoFromITEMtabl( int itemid ); +char *ITEM_getItemInfoFromNumber( int itemid ); + +int ITEM_getdropatlogoutFromITEMtabl( int itemid ); +int ITEM_getvanishatdropFromITEMtabl( int itemid ); +int ITEM_getcanpetmailFromITEMtabl( int itemid ); +int ITEM_getmergeItemFromFromITEMtabl( int itemid ); + +#ifdef _ITEM_CHECKWARES +BOOL CHAR_CheckInItemForWares( int charaindex, int flg); +#endif + +BOOL ITEM_canuseMagic( int itemindex); +// Nuke +1 08/23 : For checking the validity of item target +int ITEM_isTargetValid( int charaindex, int itemindex, int toindex); + +int ITEMTBL_getInt( int ItemID, ITEM_DATAINT datatype); +char *ITEMTBL_getChar( int ItemID, ITEM_DATACHAR datatype); + +int ITEM_getItemDamageCrusheED( int itemindex); +void ITEM_RsetEquit( int charaindex);//Զжװλô֮Ʒ +void ITEM_reChangeItemToPile( int itemindex); +void ITEM_reChangeItemName( int itemindex); + +#ifdef _SIMPLIFY_ITEMSTRING +void ITEM_getDefaultItemData( int itemID, ITEM_Item* itm); +#endif + +#ifdef _PET_ITEM +char* ITEM_petmakeItemStatusString( int petindex, int itemid ); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_event.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_event.h new file mode 100644 index 0000000..4dd625f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_event.h @@ -0,0 +1,358 @@ +#ifndef __ITEM_EVENT_H__ +#define __ITEM_EVENT_H__ +#include "item.h" +int ITEM_eventDrop( int itemindex, int charaindex, int itemcharaindex ); +BOOL ITEM_MedicineInit( ITEM_Item* itm ); +void ITEM_MedicineUsed( int charaindex, int to_charaindex, int itemindex ); +void ITEM_SandClockDetach( int charindex , int itemindex ); +void ITEM_SandClockLogin( int charaindex ); +void ITEM_SandClockLogout( int charaindex ); +void ITEM_chantMagicAttack( int charaindex, int itemindex, int toindex, float* damage ); +void ITEM_addTitleAttach( int charaindex, int itemindex ); +void ITEM_delTitleDetach( int charaindex, int itemindex ); +void ITEM_DeleteByWatched( int myobjindex, int moveobjindex, CHAR_ACTION act, + int x, int y, int dir, int* opt, int optlen ); +void ITEM_DeleteTimeWatched( int myobjindex, int moveobjindex, CHAR_ACTION act, + int x, int y, int dir, int* opt, int optlen ); +void ITEM_useEffectTohelos( int charaindex, int to_charaindex, int haveitemindex); +void ITEM_useRecovery( int charaindex, int toindex, int haveitemindex); +void ITEM_WarpDelErrorItem( int charaindex ); +void ITEM_useStatusChange( int charaindex, int toindex, int haveitemindex); +void ITEM_useMagicDef( int charaindex, int toindex, int haveitemindex); +void ITEM_useParamChange( int charaindex, int toindex, int haveitemindex); +void ITEM_useFieldChange( int charaindex, int toindex, int haveitemindex); +void ITEM_useAttReverse( int charaindex, int toindex, int haveitemindex); +void ITEM_useStatusRecovery( int charaindex, int toindex, int haveitemindex); +void ITEM_useRessurect( int charaindex, int toindex, int haveitemindex); +void ITEM_useMic( int charaindex, int to_charaindex, int haveitemindex ); +void ITEM_dropMic( int charaindex, int itemindex ); +void ITEM_useCaptureUp( int charaindex, int toindex, int haveitemindex); +void ITEM_useRenameItem( int charaindex, int toindex, int haveitemindex); +void ITEM_useRenameItem_WindowResult( int charaindex, int seqno, int select, char *data); +void ITEM_dropDice( int charaindex, int itemindex); +void ITEM_pickupDice( int charaindex, int itemindex); +void ITEM_useLottery( int charaindex, int toindex, int haveitemindex); +BOOL ITEM_WarpForAny(int charaindex, int ff, int fx, int fy,int flg); +void ITEM_useWarp( int charaindex, int toindex, int haveitemindex ); +void ITEM_petFollow( int charaindex, int toindex, int haveitemindex ); + +#ifdef _PETFOLLOW_NEW_ +void ITEM_petFollowNew( int charaindex, int toindex, int haveitemindex ); +#endif + +BOOL ITEM_initLottery(ITEM_Item* itm); +void ITEM_useSkup( int charaindex, int toindex, int haveitemindex ); // Nuke 0624 +void ITEM_useNoenemy( int charaindex, int toindex, int haveitemindex ); // Nuke 0626 +void ITEM_equipNoenemy( int charaindex, int itemindex ); // Arminius 7.2: Ra's amulet +void ITEM_remNoenemy( int charaindex, int itemindex ); // Arminius 7.2: Ra's amulet +BOOL ITEM_getArgument( char* argument , char* entryname , char* buf , int buflen ); // Arminius 7.2: Ra's amulet +void ITEM_useEncounter( int charaindex, int toindex, int haveitemindex); // Arminius 7.31 cursed stone +#ifdef _ITEM_METAMO +void ITEM_metamo( int charaindex, int toindex, int haveitemindex ); +void ITEM_ColorMetamo( int charaindex, int toindex, int haveitemindex); +void ITEM_CharaMetamo( int charaindex, int toindex, int haveitemindex); +void ITEM_SexMetamo( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_CRACKER +void ITEM_Cracker(int charaindex,int toindex,int haveitemindex); +#endif +#ifdef _DEL_DROP_GOLD +void GOLD_DeleteTimeCheckLoop( void); +#endif +#ifdef _ITEM_ADDEXP //vincent +void ITEM_Addexp(int charaindex,int toindex,int haveitemindex); +#endif +#ifdef _ITEM_REFRESH //vincent 쳣״̬ +void ITEM_Refresh(int charaindex,int toindex,int haveitemindex); +#endif +//Terry 2001/12/21 +#ifdef _ITEM_FIRECRACKER +void ITEM_firecracker(int charaindex,int toindex,int haveitemindex); +#endif +//Terry end + +#ifdef _PET_LIMITLEVEL +void ITEM_useOtherEditBase( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_EDITBASES +void ITEM_useFusionEditBase( int charaindex, int toindex, int haveitemindex); +#endif + +void ITEM_WearEquip( int charaindex, int itemindex); +void ITEM_ReWearEquip( int charaindex, int itemindex); + + +#ifdef _ITEM_CONSTITUTION +void ITEM_Constitution( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _Item_ReLifeAct +void ITEM_DIErelife( int charaindex, int itemindex, int eqw ); +#endif + +#ifdef _Item_MoonAct +void ITEM_randEnemyEquipOne( int charaindex, int toindex, int haveitemindex); +void ITEM_randEnemyEquip( int charaindex, int itemindex); +void ITEM_RerandEnemyEquip( int charaindex, int itemindex); +#endif + +#ifdef _ITEM_ORNAMENTS +void ITEM_PutOrnaments( int charaindex, int itemindex); +#endif + +#ifdef _CHIKULA_STONE +void ITEM_ChikulaStone( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _SUIT_ITEM +void ITEM_suitEquip( int charaindex, int itemindex); +void ITEM_ResuitEquip( int charaindex, int itemindex); +#endif + +#ifdef _EQUIT_DEFMAGIC +void ITEM_MagicEquitWear( int charaindex, int itemindex); +void ITEM_MagicEquitReWear( int charaindex, int itemindex); +#endif + +#ifdef _EQUIT_RESIST +void ITEM_MagicResist( int charaindex, int itemindex); +void ITEM_MagicReResist( int charaindex, int itemindex); +#endif + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ +void ITEM_P_MagicEquitWear( int charaindex, int itemindex ); +void ITEM_P_MagicEquitReWear( int charaindex, int itemindex ); +#endif + + +#ifdef _Item_DeathAct +void ITEM_UseDeathCounter( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _FEV_ADD_NEW_ITEM // FEV ADD Ӹؾ +void ITEM_ResAndDef( int charaindex, int toindex, int haveitemindex ); +#endif + +#ifdef _CHRISTMAS_REDSOCKS +void ITEM_useMaxRedSocks( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _CHRISTMAS_REDSOCKS_NEW +void ITEM_useMaxRedSocksNew( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _PETSKILL_CANNEDFOOD +void ITEM_useSkillCanned( int charaindex, int toindex, int itemNo); +#endif + +#ifdef _NEW_RIDEPETS +void ITEM_useLearnRideCode( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_WARP_FIX_BI +void recoverbi(int index); +#endif + +#ifdef _ITEM_TIME_LIMIT +void ITEM_TimeLimit( int charaindex); +#endif + +#ifdef _USEWARP_FORNUM +void ITEM_useWarpForNum( int charaindex, int toindex, int haveitemindex ); +#endif + +#ifdef _IMPRECATE_ITEM +void ITEM_useImprecate( int charaindex, int toNo, int haveitemindex ); +#endif + +#ifdef _THROWITEM_ITEMS +void ITEM_ThrowItemBox( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_WATERWORDSTATUS +void ITEM_WaterWordStatus( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_LOVERPARTY +void ITEM_LoverSelectUser( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_MAGICRECOVERY +void ITEM_useMRecovery( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_USEMAGIC +void ITEM_useMagic( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _PETSKILL_CANNEDFOOD +void ITEM_usePetSkillCanned_WindowResult( int charaindex, int seqno, int select, char *data); +#endif + +void ITEM_AddPRSkillPoint(int charaindex,int toindex,int haveitemindex); +void ITEM_AddPRSkillPercent( int charaindex,int toindex,int haveitemindex); + +#ifdef _ANGEL_SUMMON +void ITEM_AngelToken( int charaindex, int toindex, int haveitemindex ); +void ITEM_HeroToken( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _HALLOWEEN_EFFECT +void ITEM_MapEffect(int charaindex,int toindex,int haveitemindex); +#endif +void ITEM_changePetOwner( int charaindex, int toindex, int haveitemindex); + +#ifdef _TIME_TICKET +void ITEM_timeticketEx( int charaindex, int toindex, int haveitemindex, int flag); +void ITEM_timeticket( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _ITEM_SETLOVER +void ITEM_SetLoverUser( int charaindex, int toindex, int haveitemindex); +void ITEM_LoverWarp( int charaindex, int toindex, int haveitemindex); +void ITEM_LoverUnmarry( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _GM_ITEM +void ITEM_GMFUNCTION( int charaindex, int toindex, int haveitemindex); +#endif + +#ifdef _VIP_SERVER +void ITEM_AddMemberPoint( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _VIP_RIDE +void ITEM_VipRide( int charaindex, int toindex, int haveitemindex); +#ifdef _NEW_NAME //Զƺ +void ITEM_NewName( int charaindex, int toindex, int haveitemindex); +#endif +#endif +#ifdef _FM_ITEM +void ITEM_AddFame( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _LUCK_ITEM +void ITEM_Luck( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_METAMO_TIME +void ITEM_MetamoTime( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _ITEM_GOLD +void ITEM_Gold( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _MYSTERIOUS_GIFT +void ITEM_MysteriousGift( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _BATTLE_PK +void ITEM_BattlePK( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _SILENTZERO +void ITEM_SetSilentZero( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _PET_LEVEL_ITEM +void ITEM_PetLevelItem( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_EFMETAMO +void ITEM_efMetamo( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _PET_BEATITUDE +void PET_BEATITUDE( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _GET_MULTI_ITEM +void ITEM_GetMultiItem( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _SUPER_FLOOR_MIC +void ITEM_useSuperMic( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_PET_LOCKED +void ITEM_ItemPetLocked( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ONLINE_COST +void ITEM_OnlineCost( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _VIPPOINT_OLD_TO_NEW +void ITEM_OldToNew( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _BOUND_TIME +void ITEM_BoundTime( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _TALK_SIZE_ITEM +void ITEM_TalkSize( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _FORMULATE_AUTO_PK +void ITEM_PointToSQLPkPoint( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _SUPER_MAN_ITEM +void ITEM_SuperManItem( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _COST_ITEM +void ITEM_CostItem( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _ITEM_EXP +void ITEM_EXP( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _MEMORY_ITEM +void ITEM_WarpItem( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _NULL_CHECK_ITEM +void ITEM_NullCheck( int charaindex, int toindex, int haveitemindex); +#endif +#ifdef _SPECIAL_SUIT +void ITEM_SpecialSuitEquip( int charaindex, int itemindex); +void ITEM_SpecialResuitEquip( int charaindex, int itemindex); +#endif +#ifdef _MANOR_EQUIP +void ITEM_ManorEquip( int charaindex, int itemindex); +void ITEM_ReManorEquip( int charaindex, int itemindex); +#endif +#ifdef _FIND_TREASURES +void ITEM_FindTreasures( int charaindex, int toindex, int haveitemindex ); +BOOL FindTreasures_init(); +#endif +#ifdef _ITEM_POOLITEM +void ITEM_PoolItem( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _ITEM_POOLPET +void ITEM_PoolPet( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _NEW_GM_ITEM +void ITEM_NewGMItem( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _SHOW_PET_ABL +void ITEM_ShowPetAbl( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _NEWEVENT_ITEM +void ITEM_NeweventItem( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _NEW_PET_BEATITUDE +void ITEM_NewPetBeatitude( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _OLYMPIC_TORCH +void ITEM_OlympicTorck( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _PLAYER_DIY_MAP +void ITEM_PlayerDiyMapObj( int charaindex, int toindex, int haveitemindex ); +void ITEM_PlayerDiyMapTile( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _SHOW_ITEM +void ITEM_ShowItem( int charaindex, int toindex, int haveitemindex ); +#endif +#ifdef _ITEM_LUA +void ITEM_Lua(int charaindex, int toindex, int haveitemindex); +#endif +enum{ + BD_KIND_HP, + BD_KIND_MP, + BD_KIND_CHARM, + BD_KIND_AI, + BD_KIND_CURSE, + BD_KIND_BESTOW, + BD_KIND_WISHES, +#ifdef _ITEM_UNBECOMEPIG + BD_KIND_UNBECOMEPIG, +#endif +#ifdef _ITEM_PROPERTY + BD_KIND_PROPERTY, +#endif + BD_KIND_END +}; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_gen.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_gen.h new file mode 100644 index 0000000..961b10d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_gen.h @@ -0,0 +1,26 @@ +#ifndef __ITEM_GEN_H__ +#define __ITEM_GEN_H__ + + +int ITEM_initItemIngCache( void ); +int ITEM_initItemAtom( char *fn ); +int ITEM_initRandTable( void); +int ITEM_mergeItem( int charaindex, ITEM_Item *items, int num , int money, int petid, int searchtable, int petindex, int alchemist); +int ITEM_canDigest( ITEM_Item *t ); +int ITEM_mergeItem_merge( int charaindex,int petid, char *data, int petindex, int alchemist); + +#ifdef _ITEM_INSLAY +#ifdef _EXPANSION_ITEM_INSLAY +int PETSKILL_ITEM_inslay( int charindex, int inslayindex, int itemindex, int num); +#else +int PETSKILL_ITEM_inslay( int charindex, int inslayindex, int itemindex); +#endif +#endif + +#ifdef _PETSKILL_FIXITEM +int PETSKILL_ITEM_FixItem( int charindex, int fixindex, int *itemindex); +#endif + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_trade.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_trade.h new file mode 100644 index 0000000..b389cdb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/item_trade.h @@ -0,0 +1,52 @@ +#ifndef __MAPTRADE_H__ +#define __MAPTRADE_H__ +#include "char.h" + +typedef struct tagMapTrade { + int masterindex; + int x; + int y; + int Ttime; + int Goodindex; + char Goodname[256]; +}MapTrade; + +#define TRADEMAP 1090 +#define TRADEXSIZE 4 +#define TRADEYSIZE 4 + +BOOL CHECKMAP_TRADE( int charindex, int floor, int x, int y); +int CHECKMAP_TRADEXY( int charindex, int floor, int x, int y); +BOOL MAP_TRADEDROP( int charindex, int itemindex,int floor, int x, int y); +BOOL MAP_TRADEPICKUP( int charindex, int itemindex, int floor, int x, int y, int flg); + +void InitMapTradeData( int index, int Stime); + +int TRADE_getMasterInt( int index); +int TRADE_getTimeInt( int index); +BOOL TRADE_setMasterInt( int index, int Num); +BOOL TRADE_setTimeInt( int index, int Num); +int TRADE_AddMasrerTrade( int toindex); //趨̯λ +int TRADE_getMaxNumInt(); +void MAPTRADE_CLEANGOLD( int floor, int num); +BOOL MAPTRADE_CHECKMASTERIN( int masterindex , int toindex, int num); +BOOL MAPTRADE_CHECKMAPFULL(int fl, int x, int y); +BOOL MAP_TRADEPETDROP( int charindex, int petindex,int floor, int x, int y); +int MAPTRADE_getItemSpace( int meindex, int itemindex); +int MAPTRADE_getPetSpace( int masterindex, int petindex); + +int MAPTRADE_getSellIndex( int index); +BOOL MAPTRADE_setSellIndex( int index, int num); +void MAPTRADE_setCharSellName( int index, char *buf); +char* MAPTRADE_getCharSellName( int index ); + +#define TRADESTARTNUM 1 +#define TRADETYPE_SELL (1<<3) +#define TRADEITEMID 0 +#define TRADEPETID 0 +#define TRADEPETUPLV ((1<<24)+(1<<16)+(1<<8)+1) +#define TRADEPETTYPE (1<<4) +#define TRADEITEMTYPE (1<<8) +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/levelup.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/levelup.h new file mode 100644 index 0000000..eb4b161 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/levelup.h @@ -0,0 +1,17 @@ +#ifndef _LEVELUP_H +#define _LEVELUP_H + +int GetEnemyExp( int level ); + +int BATTLE_GetLevelExp( + int charaindex, + int level +); + +int BATTLE_LevelUpCheck( + int charaindex +); + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/link.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/link.h new file mode 100644 index 0000000..f9f6ba2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/link.h @@ -0,0 +1,22 @@ +#ifndef __LINK_H__ +#define __LINK_H__ + +#include "common.h" + +/* + * հë + * val 巴ئУ۹Ի̼ + * 浤 + */ +typedef struct tagNode +{ + struct tagNode* next; /*ݼá߼̼*/ + char* val; /* ٯ */ + int size; /*val*/ +}Node; + +BOOL Nodeappendhead( Node** top , Node* add ); +BOOL Nodeappendtail( Node** top , Node* add ); +BOOL Noderemovehead( Node** top , Node* ret); +BOOL Noderemovetail( Node** top , Node* ret); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/log.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/log.h new file mode 100644 index 0000000..5f65f03 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/log.h @@ -0,0 +1,361 @@ +#ifndef __LOG_H__ +#define __LOG_H__ +#include +typedef enum +{ + LOG_TALK, + LOG_PROC, + LOG_ITEM, + LOG_STONE, + LOG_PET, + LOG_TENSEI, + LOG_KILL, //ttom 12/26/2000 kill the pet & items + LOG_TRADE, // CoolFish: 2001/4/19 + LOG_HACK, // Arminius 2001/6/14 + LOG_SPEED, // Nuke 0626 + LOG_FMPOP, // CoolFish: 2001/9/12 + LOG_FAMILY, // Robin 10/02 + LOG_GM, // Shan +#ifdef _GAMBLE_ROULETTE + LOG_GAMBLE, +#endif + + LOG_LOGIN, + PETTRANS, +//Syu ׯ԰սʤLog + LOG_FMPKRESULT, + +// Syu ADD дȡLog () + LOG_BANKSTONELOG, + + LOG_ACMESS, + LOG_PKCONTEND, +#ifdef _STREET_VENDOR + LOG_STREET_VENDOR, +#endif + +#ifdef _ANGEL_SUMMON + LOG_ANGEL, +#endif + +#ifdef _NEW_MANOR_LAW + LOG_FMPK_GETMONEY, +#endif + + LOG_FM_FAME_SHOP, + +#ifdef _AMPOINT_LOG + LOG_AMPOINT, +#endif + +#ifdef _SQL_VIPPOINT_LOG + LOG_SQLVIPOINT, +#endif +#ifdef _NETLOG_ + LOG_LOGOUT, +#endif + LOG_TYPE_NUM, +}LOG_TYPE; + +void closeAllLogFile( void ); +BOOL initLog( char* filename ); +void printl( LOG_TYPE logtype, char* format , ... ); + + +void LogAcMess( int fd, char *type, char *mess ); + +void LogItem( + char *CharName, /* ƽҷ */ + char *CharID, + int ItemNo, /* ʧ ة į */ + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + char *uniquecode, // shan 2001/12/14 + char *itemname, int itemID +); +void LogPkContend( char *teamname1, char *teamname2, + int floor, int x, int y, int flg ); + +void LogPetTrans( + char *cdkey, char *uniwuecde, char *uniwuecde2, char *CharName, int floor, int x, int y, + int petID1, char *PetName1, int petLV, int petrank, int vital1, int str1, int tgh1, int dex1, int total1, + int petID2, char *PetName2, int vital2, int str2, int tgh2, int dex2, int total2, + int work0, int work1, int work2, int work3, int ans, int trans +); + +void LogPet( + char *CharName, /* ƽҷ */ + char *CharID, + char *PetName, + int PetLv, + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + char *uniquecode // shan 2001/12/14 +); + +#ifdef _STREET_VENDOR +void LogStreetVendor( + char *SellName, + char *SellID, + char *BuyName, + char *BuyID, + char *ItemPetName, + int PetLv, //ǵߴֵΪ -1 + int iPrice, + char *Key, + int Sfloor, + int Sx, + int Sy, + int Bfloor, + int Bx, + int By, + char *uniquecode +); +#endif + +void LogTensei( + char *CharName, /* ƽҷ */ + char *CharID, + char *Key, /* ƽ */ + int level, //ì + int transNum, //Ϸ + int quest, //;޵ + int home, //컩 + int item, // ʧ ة Ի + int pet, // ʸ Ի + int vital, // Vital + int b_vital, // vital + int str, // str + int b_str, // str + int tgh, // + int b_tgh, // + int dex, // + int b_dex // +); +// Syu ADD дȡLog () +void LogFamilyBankStone( + char *CharName, + char *CharId, + int Gold, + int MyGold, + char *Key, + int floor, + int x, + int y, + int banksum +); + +void LogStone( + int TotalGold, + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + int Gold, /* ź */ + int MyGold, + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y +); + +void LogTalk( + char *CharName, /* ƽҷ */ + char *CharID, + int floor, /* */ + int x, + int y, + char *message +); +//ttom 12/26/2000 kill pet & items +void LogKill( + char *CharName, + char *CharId, + char *CharPet_Item +); +//ttom + +// CoolFish: 2001/4/19 +void LogTrade(char *message); +// CoolFish: 2001/9/12 +void LogFMPOP(char *message); + +// Arminius 2001/6/14 +enum +{ + HACK_NOTHING, + HACK_GETFUNCFAIL, + HACK_NOTDISPATCHED, + HACK_CHECKSUMERROR, + HACK_HP, + HACK_TYPE_NUM, +}HACK_TYPE; +void logHack(int fd, int errcode); +// Nuke 0626 +void logSpeed(int fd); + +void closeAllLogFile( void ); +int openAllLogFile( void ); + +// Robin 10/02 +void LogFamily( + char *FMName, + int fmindex, + char *charName, + char *charId, + char *keyWord, + char *data +); + +// Shan 11/02 +void LogGM( + char *CharName, //ɫ + char *CharID, //ID + char *Message, //ָ + int floor, + int x, + int y +); + +void LogLogin( + char *CharID, //ID + char *CharName, //ɫ + int saveIndex, + char *ipadress +#ifdef _NEWCLISETMAC + ,char *mac +#endif +); + +void LogCreatFUPet( + char *PetName, int petid, int lv, int hp, + int vital, int str, int tgh, int dex, + int fixstr, int fixtgh, int fixdex, int trans, int flg); + +#ifdef _GAMBLE_ROULETTE + +void LogGamble( + char *CharName, //ɫ + char *CharID, //ID + char *Key, //˵ + int floor, + int x, + int y, + int player_stone, //ӵнǮ + int Gamble_stone, //ע + int get_stone, // + int Gamble_num, + int flg //flg = 1 2 ׯ +); +#endif + +void LogBankStone( + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + int meindex, + int Gold, /* ź */ + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + int my_gold, + int my_personagold +); + +//Syu ׯ԰սʤLog +void Logfmpk( + char *winner, int winnerindex, int num1, + char *loser, int loserindex, int num2, char *date, char *buf1, char *buf2, int flg); + +#ifdef _NEW_MANOR_LAW +void LogFMPKGetMomey( + char *szFMName, + char *szID, + char *szCharName, + int iMomentum, + int iGetMoney, + int iDest +); +#endif + +void LogFMFameShop( + char *szFMName, + char *szID, + char *szCharName, + int iFame, + int iCostFame +); + +void backupAllLogFile( struct tm *ptm ); + +void LogPetPointChange( + char * CharName, char *CharID, char *PetName, int petindex, int errtype, + int PetLv, char *Key,int floor, int x, int y); + +void LogPetFeed( + char * CharName, char *CharID, char *PetName, int petindex, + int PetLv, char *Key,int floor, int x, int y, char *ucode); + +#ifdef _ANGEL_SUMMON +void LogAngel( char *msg); +#endif + +void warplog_to_file( void ); +void warplog_from_file( void ); + +typedef struct { + int floor; + int incount; + int outcount; +}tagWarplog; +#define MAXMAPNUM 700 +extern tagWarplog warplog[MAXMAPNUM]; + +typedef struct { + int floor1; + int floor2; + int count; +}tagWarpCount; +#define MAXMAPLINK 1000 +extern tagWarpCount warpCount[MAXMAPLINK]; + + + +#ifdef _AMPOINT_LOG +void LogAmPoint( + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + int Gold, /* ź */ + int MyAmPoint, + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y); +#endif + +#ifdef _SQL_VIPPOINT_LOG +void LogSqlVipPoint( + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + char *Key, /* ƽ */ + int VipPoint, /* ź */ + int floor, /* */ + int x, + int y); +#endif + + + +#endif +#ifdef _NETLOG_ +void LogCharOut( + char *CharName, + char *CharId, + char *file, + char *fun, + int ilne, + char *yuanyin +); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/allblues.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/allblues.h new file mode 100644 index 0000000..e69de29 diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/attestation.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/attestation.h new file mode 100644 index 0000000..7d521b4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/attestation.h @@ -0,0 +1,6 @@ +#ifndef __ATTESTATION_H__ +#define __ATTESTATION_H__ + +int attestation( void ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/characters.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/characters.h new file mode 100644 index 0000000..e33a9f3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/characters.h @@ -0,0 +1,29 @@ +#ifndef __CHARACTERS_H__ +#define __CHARACTERS_H__ +#ifdef _CHARADATA_SAVE_SQL +#include "char_base.h" + +typedef struct tagChardata +{ + char CHAR_list_String[STRINGBUFSIZ]; + char CHAR_list_info1_String[STRINGBUFSIZ]; + char CHAR_list_info2_String[STRINGBUFSIZ]; + char CHAR_list_count_String[STRINGBUFSIZ]; + char CHAR_list_info3_String[STRINGBUFSIZ]; + char CHAR_list_event_String[STRINGBUFSIZ]; + char CHAR_list_info4_String[STRINGBUFSIZ]; + char CHAR_list_attackmagic_String[STRINGBUFSIZ]; + char CHAR_list_info5_String[STRINGBUFSIZ]; + char CHAR_list_profession_String[STRINGBUFSIZ]; + char CHAR_list_info6_String[STRINGBUFSIZ]; + char CHAR_list_info_String[STRINGBUFSIZ]; + char CHAR_list_flg_String[STRINGBUFSIZ]; + char CHAR_list_skill_String[STRINGBUFSIZ]; + char CHAR_list_item_String[STRINGBUFSIZ*4]; + char CHAR_list_title_String[STRINGBUFSIZ]; + char CHAR_list_mail_String[STRINGBUFSIZ]; +}Charadata; + +void CHAR_CharadataSaveSQL(Char* ch); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/debug.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/debug.h new file mode 100644 index 0000000..c75e24e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/debug.h @@ -0,0 +1,13 @@ +/* +#ifdef __DEBUG_H__ +#define __DEBUG_H__ +#ifdef _DEBUG_ALL +//#define _DEBUG // +#define _DEBUG_RET // տͻݵ +#define _DEBUG_RET_CLI // տͻݵ +#define _DEBUG_SEND_CLI // Ϳͻݵ +#endif +#endif + +*/ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/longzoro.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/longzoro.h new file mode 100644 index 0000000..71aaa83 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/longzoro.h @@ -0,0 +1,7 @@ +#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 1 + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/luckstar.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/luckstar.h new file mode 100644 index 0000000..57c8bdc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/luckstar.h @@ -0,0 +1,19 @@ +#ifndef __LUCK_STAR_H__ +#define __LUCK_STAR_H__ + +#ifdef _LUCK_STAR +#define MAXLUCKSTAR 128 +typedef struct LUCK_STAR_t{ + int pet; + int item; +// int gold; +// int vippoint; +}Luck_Star_t; + +BOOL LuckStar_init(); + +void LuckStar(); + + +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/move.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/move.h new file mode 100644 index 0000000..97e7dfe --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/move.h @@ -0,0 +1,19 @@ +#ifndef __MOVE_H__ +#define __MOVE_H__ + +#ifdef _TALK_MOVE_FLOOR +#define MAXTALKMOVEFLOOR 64 +typedef struct TALK_MOVE_FLOOR_t{ + char name[32]; + int id; + int x; + int y; + int trans; + int level; +}Talk_Move_Floor_t; + +BOOL MoveMap_init(); +BOOL talk_move_map(int charaindex, char *messageeraseescape); + +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/newshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/newshop.h new file mode 100644 index 0000000..a372afd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/newshop.h @@ -0,0 +1,39 @@ +#ifndef _NEW_SHOP_H_ +#define _NEW_SHOP_H_ + +#ifdef _ONLINE_SHOP +#define SHOPLISTMAX 100 +#define SHOPPAGEMAX 8 + +//#ͼ##ɫ#ۿ##˵ +typedef struct ONLINE_SHOP_t{ + BOOL use; + int id; + int picid; + char name[64]; + int color; + int percentage; + int price; + char readme[256]; +}Online_Shop_t; + + +typedef enum +{ + ONLINESHOP_PET, + ONLINESHOP_ITEM, + ONLINESHOP_HEALER, + ONLINESHOP_COMPOSE, + ONLINESHOP_MISSION, + ONLINESHOP_OTHER, + ONLINESHOP_AMPOINT, + ONLINESHOP_NUM +}CHAR_ONLINESHOP; + +BOOL OnlineShop_init(); +void OnlineShop_ShowList(int fd, int charaindex, int type, int page); +void OnlineShop_Buy(int fd, int charaindex, int type, int page, int id, int num); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/playerquestion.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/playerquestion.h new file mode 100644 index 0000000..5706055 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/playerquestion.h @@ -0,0 +1,18 @@ +#ifndef __PLAYER_QUESTION_ONLIEN_H__ +#define __PLAYER_QUESTION_ONLIEN_H__ + +#ifdef _PLAYER_QUESTION_ONLIEN +typedef struct PLAYER_QUESTION_t{ + char question[128]; + char result[128]; + int type; + int value; +}PlayerQuestion_t; +BOOL PlayQuestionOnline(int charaindex, char *messageeraseescape); + +#endif + + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/sasql.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/sasql.h new file mode 100644 index 0000000..2cd48c7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/sasql.h @@ -0,0 +1,80 @@ +#ifndef _SASQL_H_ +#define _SASQL_H_ + +#include "version.h" +#ifdef _SASQL + +#define BOOL int +#define FALSE 0 +#define TRUE 1 + +void sasql_close( void ); +BOOL sasql_init( void ); + +int sasql_getVipPoint( int charaindex ); +int sasql_setVipPoint( int charaindex, int point ); +int sasql_getVipPointForCdkey( char *id ); +int sasql_setVipPointForCdkey( char *id, int point ); +BOOL sasql_addPauctionInfo( char *cdkey, char *name, char *effect, int cost, int type, char *info, char *string ); +int sasql_getPauctionList( char *List, int start, int type, char *cdkey ); +BOOL sasql_getPauctionSurvey( char *token, int id ); +int sasql_getMyPauction( char *token, int id, char *cdkey ); +BOOL sasql_delPauctionBuy( int id, char *cdkey ); +int sasql_PauctionOK( int id, char *cdkey ); + +int sasql_getPayPoint( int charaindex ); +int sasql_setPayPoint( int charaindex, int point ); + +#ifdef _GAMBLE_POINT +int sasql_getGamblePoint( int charaindex ); +int sasql_setGamblePoint( int charaindex, int point ); +#endif +#ifdef _TRIAL_POINT +int sasql_getTrialPoint( int charaindex ); +int sasql_setTrialPoint( int charaindex, int point ); +#endif + +#ifdef _NEW_SQL_MONEY +int sasql_getSQLPoint( int charaindex ); +int sasql_setSQLPoint( int charaindex, int point ); +int sasql_getGoldPoint( int charaindex ); +int sasql_setGoldPoint( int charaindex, int point ); +int sasql_setSQLPointByCdkey( char* cdkey, int point ); +int sasql_getSQLPointByCdkey( char* cdkey ); +int sasql_setGoldPointByCdkey( char* cdkey, int point ); +int sasql_getGoldPointByCdkey( char* cdkey ); +#endif + +int sasql_getPayPointForCdkey( char *id ); +int sasql_setPayPointForCdkey( char *id, int point ); +enum{ + INSERT, + SELECT, + UPDATE, + DELETE, +}; + +#endif + +#ifdef _JZ_NEWSCRIPT_LUA +int sasql_vippoint( char *ID, int point, int flag ); +int sasql_rmbpoint( char *ID, int point, int flag ); +int sasql_ampoint( char *ID, int point, int flag ); + +#endif +#ifdef _MO_LNS_MYSQLSUOXU +void sasql_LUASQLAdv(char* sqlstr,char* filepath,char* function,int npcindex ,int charaindex,char* msg,int flg); +void sasql_LUASQL(char* sqlstr,int row,char* filepath,char* function,int npcindex ,int charaindex,char* msg); + +char* sasql_Lua_QueryR(int row,char *sqlstr); +char* sasql_LuaAdv_QueryR(char *sqlstr,int flg); +#endif +int sasql_check_iponline( char *IP ); +int sasql_query_online_ip(char *IP); +int sasql_query(char *nm, char *pas); +#ifdef _MO_LOGIN_NO_KICK +BOOL sasql_CheckPasswd(char *id, char *passwd); +#endif +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/version.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/version.h new file mode 100644 index 0000000..fd32893 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/longzoro/version.h @@ -0,0 +1,897 @@ +#ifndef __ALLBLUES_H__ +#define __ALLBLUES_H__ + +#include "longzoro.h" + + +//˽汾---------------------------------------- + +#if _ATTESTAION_ID == 1 + #define _VERSION_NEW + #define _VERSION_NEW60 +//#define _VERSION_GF +#define _VERSION_60 +#define _VERSION_80 +//#define _NEW_SA80 // ʯ8.0 +#else +#if _ATTESTAION_ID == 2 + #define _VERSION_25 +#else + #define _VERSION_80 +#endif +#endif + + +#ifdef _VERSION_80 + #if _ATTESTAION_ID == 0 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 23 || _ATTESTAION_ID == 28 || _ATTESTAION_ID == 29 || _ATTESTAION_ID == 30 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 32 || _ATTESTAION_ID == 33 || _ATTESTAION_ID == 34 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 36 || _ATTESTAION_ID == 37 || _ATTESTAION_ID >= 39 + #if _ATTESTAION_ID != 49 + #define _NEW_SA80 // ʯ8.0 + #endif + #endif + + #ifdef _NEW_SA80 + #if _ATTESTAION_ID != 43 + #define _ONLINE_SHOP // 8.0̳ + #endif + #define _ONLINE_TALK_IP // Ҿٱ + #define _ONLINE_TALK_GM // ϵGM + #define _NEW_ONLINE_SHOP // ̳ + #endif + #define _ANGLE_EMAIL // ٺԶƬ +#endif + +#ifdef _VERSION_NEW + #define _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ 8/27 + #define _OBJSEND_C // (ɿ) ANDY _OBJSEND_C + #define _ADD_SHOW_ITEMDAMAGE // (ɿ) WON ʾƷ;ö + #define _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + #define _TRADE_SHOWHP // (ɿ) Syu ADD ʾѪ + #define _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + #define _NPC_MAKEPAIR // (ɿ) ANDY NPC + #define _ITEM_PILENUMS // (ɿ) ANDY زĶѵ itemset4 + #define _ITEM_PILEFORTRADE // (ɿ) ANDY ׶ѵ + #define _ITEM_EQUITSPACE // (ɿ) ANDY װλ + #define _EQUIT_ARRANGE // (ɿ) ANDY Ҫ itemset5.txt + #define _EQUIT_ADDPILE // (ɿ) ANDY ӿɶѵ Ҫ itemset5.txt + #define _EQUIT_NEWGLOVE // (ɿ) ANDY λ + // ¹ܣְҵ + #define _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ + #define _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + #define _NPC_ADDLEVELUP // (ɿ) ANDY NPCҵȼ + #define _CHAR_NEWLOGOUT // (ɿ) ANDY dz» + #define _NPC_ProfessionTrans // (ɿ) Change ְҵNPCжת + #define _CHANNEL_MODIFY // Ƶ() + //-------------------------------------------------------------------------- + #define _STREET_VENDOR // ̯() + #define _WATCH_EVENT // ѯ() + #define _ADD_DUNGEON // (ɿ) Change ׷ӵ + #define _ADD_STATUS_2 // ״̬ڶ + #define _ALCHEMIST // Robin + #define _JOBDAILY // cyg ־ + #define _FONT_SIZE // (ɿ) Robin ʹС + #define _PETSKILL_FIXITEM // (ɿ) ANDY ޸ && ͬ + #define _CHECK_ITEMDAMAGE // (ɿ) 7/26 + #define _TEAM_KICKPARTY // (ɿ) ANDY ӳ(ս״̬) + #define _TELLCHANNEL // (ɿ) Syu ADD Ƶ + #define _EMENY_CHANCEMAN // (ɿ) ANDY EMENY ѡ + #define _STANDBYPET // Robin + #define _CHAR_POOLITEM // (ɿ) ANDY ֿ߲⹲ + #define _CHAR_POOLPET // (ɿ) Robin ֿ⹲ + #define _NPC_DEPOTPET // (ɿ) Robin ֿ⹲ + #define _NPC_DEPOTITEM // (ɿ) ANDY ֿ߲⹲ + #define _NEW_MANOR_LAW // ׯ԰() + #define _CHANNEL_MODIFY // Ƶ() + #define _TAKE_ITEMDAMAGE // (ɿ) ANDY ITEMSET2 +#ifdef _VERSION_NEW60 + #define _SKILL_NOCAST // (ɿ) vincent 輼:Ĭ //Ҫ#define _MAGIC_NOCAST + #define _PET_FUSION // (ɿ) ANDY ں enemybase1.txt + #define _NPC_FUSION // (ɿ) ANDY NPCں + #define _ITEM_EDITBASES // (ɿ) ANDY Ӫ + #define _PET_EVOLUTION // (ɿ) ANDY + #define _STATUS_WATERWORD // (ɿ) ANDY ˮ״̬ + #define _ITEM_WATERWORDSTATUS // (ɿ) ANDY ˮ״̬ + #define _PETSKILL_ACUPUNCTURE // (ɿ) Change 輼:Ƥ (client˵_PETSKILL_ACUPUNCTUREҲҪ) + #define _SHOW_FUSION // (ɿ) Change ںϳCLIENTֻʾת,޸ΪںϳʾΪں(clientҲҪ) + #define _TREASURE_BOX // (ɿ) ANDY + #define _SHOOTCHESTNUT // (ɿ) Syu ADD 輼 +#endif + +#endif + +#ifdef _VERSION_60 + #define _PETSKILL_FIXITEM // (ɿ) ANDY ޸ && ͬ + #define _CHECK_ITEMDAMAGE // (ɿ) 7/26 + #define _TAKE_ITEMDAMAGE // (ɿ) ANDY ITEMSET2 + #define _SKILL_NOCAST // (ɿ) vincent 輼:Ĭ //Ҫ#define _MAGIC_NOCAST + #define _EMENY_CHANCEMAN // (ɿ) ANDY EMENY ѡ + #define _PET_FUSION // (ɿ) ANDY ں enemybase1.txt + #define _NPC_FUSION // (ɿ) ANDY NPCں + #define _ITEM_EDITBASES // (ɿ) ANDY Ӫ + #define _PET_EVOLUTION // (ɿ) ANDY + #define _TEAM_KICKPARTY // (ɿ) ANDY ӳ(ս״̬) + #define _STATUS_WATERWORD // (ɿ) ANDY ˮ״̬ + #define _ITEM_WATERWORDSTATUS // (ɿ) ANDY ˮ״̬ + #define _TELLCHANNEL // (ɿ) Syu ADD Ƶ + #define _PETSKILL_ACUPUNCTURE // (ɿ) Change 輼:Ƥ (client˵_PETSKILL_ACUPUNCTUREҲҪ) + #define _SHOW_FUSION // (ɿ) Change ںϳCLIENTֻʾת,޸ΪںϳʾΪں(clientҲҪ) + #define _FONT_SIZE // (ɿ) Robin ʹС + #define _TREASURE_BOX // (ɿ) ANDY + #define _DP_NPC // DPű + #define _SHOOTCHESTNUT // (ɿ) Syu ADD 輼 +#endif + +#ifdef _VERSION_80 + #define _PETSKILL_FIXITEM // (ɿ) ANDY ޸ && ͬ + #define _CHECK_ITEMDAMAGE // (ɿ) 7/26 + #define _TAKE_ITEMDAMAGE // (ɿ) ANDY ITEMSET2 + #define _SKILL_NOCAST // (ɿ) vincent 輼:Ĭ //Ҫ#define _MAGIC_NOCAST + #define _EMENY_CHANCEMAN // (ɿ) ANDY EMENY ѡ + #define _PET_FUSION // (ɿ) ANDY ں enemybase1.txt + #define _NPC_FUSION // (ɿ) ANDY NPCں + #define _ITEM_EDITBASES // (ɿ) ANDY Ӫ + #define _PET_EVOLUTION // (ɿ) ANDY + #define _TEAM_KICKPARTY // (ɿ) ANDY ӳ(ս״̬) + #define _STATUS_WATERWORD // (ɿ) ANDY ˮ״̬ + #define _ITEM_WATERWORDSTATUS // (ɿ) ANDY ˮ״̬ + #define _TELLCHANNEL // (ɿ) Syu ADD Ƶ + #define _PETSKILL_ACUPUNCTURE // (ɿ) Change 輼:Ƥ (client˵_PETSKILL_ACUPUNCTUREҲҪ) + #define _SHOW_FUSION // (ɿ) Change ںϳCLIENTֻʾת,޸ΪںϳʾΪں(clientҲҪ) + #define _FONT_SIZE // (ɿ) Robin ʹС + #define _TREASURE_BOX // (ɿ) ANDY + #define _DP_NPC // DPű + + //#define _PREVENT_TEAMATTACK // (ɿ) ANDY ֹͬӻ 12/04 + #define _OBJSEND_C // (ɿ) ANDY _OBJSEND_C + #define _ADD_SHOW_ITEMDAMAGE // (ɿ) WON ʾƷ;ö + #define _CHANGETRADERULE // (ɿ) Syu ADD ׹޶ + #define _TRADE_SHOWHP // (ɿ) Syu ADD ʾѪ + #define _SHOOTCHESTNUT // (ɿ) Syu ADD 輼 + #define _SKILLLIMIT // (ɿ) Syu ADD ùҷ + #define _TRADESYSTEM2 // (ɿ) Syu ADD ½ϵͳ + #define _NPC_MAKEPAIR // (ɿ) ANDY NPC + #define _ITEM_PILENUMS // (ɿ) ANDY زĶѵ itemset4 + #define _ITEM_PILEFORTRADE // (ɿ) ANDY ׶ѵ + #define _ITEM_EQUITSPACE // (ɿ) ANDY װλ + #define _EQUIT_ARRANGE // (ɿ) ANDY Ҫ itemset5.txt + #define _EQUIT_ADDPILE // (ɿ) ANDY ӿɶѵ Ҫ itemset5.txt + #define _EQUIT_NEWGLOVE // (ɿ) ANDY λ + // ¹ܣְҵ + #define _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ + #define _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol + #define _CHAR_PROFESSION // (ɿ) WON ADD ְҵλ + #define _PROFESSION_SKILL // (ɿ) WON ADD ְҵ + #define _NPC_WELFARE // (ɿ) WON ADD ְҵNPC + #define _NPC_ADDLEVELUP // (ɿ) ANDY NPCҵȼ + #define _CHAR_NEWLOGOUT // (ɿ) ANDY dz» + #define _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ 8/27 + #define _CHAR_POOLITEM // (ɿ) ANDY ֿ߲⹲ + #define _CHAR_POOLPET // (ɿ) Robin ֿ⹲ + #define _NPC_DEPOTPET // (ɿ) Robin ֿ⹲ + #define _NPC_DEPOTITEM // (ɿ) ANDY ֿ߲⹲ + #define _NPC_ProfessionTrans // (ɿ) Change ְҵNPCжת + #define _CHANNEL_MODIFY // Ƶ() + #define _STANDBYPET // Robin + #define _PROSKILL_OPTIMUM // Robin ְҵܴѻ + //2004/05/12 + + #define _MAGIC_RESIST_EQUIT // (ɿ) WON ADD ְҵװ + #define _ALLDOMAN // (ɿ) Syu ADD аNPC + #define _ALLDOMAN_DEBUG // (ɿ) Change serverаʧbug + // ------------------------------------------------------------------- + // ¹ܣGMƵ + //̰ + #define _REDHAT_V9 //(ɿ) Change REDHAT9.0İ汾±ʱ + //-------------------------------------------------------------------------- + #define _NPC_EXCHANGEMANTRANS // (ɿ) Change exchangemanжת + #define _ANGEL_SUMMON // Robin ʹٻ + #define _STREET_VENDOR // ̯() + #define _WATCH_EVENT // ѯ() + #define _NEW_MANOR_LAW // ׯ԰() + #define _PETSKILL_LER // ׶() + #define _FIX_MAGIC_RESIST // (ɿ) Change ְҵħ + #define _ADD_DUNGEON // (ɿ) Change ׷ӵ + #define _PROFESSION_ADDSKILL // (ɿ) Change ׷ְҵ + #define _EQUIT_RESIST // (ɿ) Change һװ(ɿһ쳣״̬)п ħ Ĭ + #define _PROSK99 // (ɿ) Change ְȼͰ + #define _ADD_STATUS_2 // ״̬ڶ + #define _SUIT_ADDPART4 // (ɿ) Change װܵĵ ж% ǿʦħ(30%) ֿʦħ + + + #define _ITEM_TYPETABLE // (ɿ) Change ׷typetable + #define _RIGHTCLICK // Robin Ҽ + #define _JOBDAILY // cyg ־ + #define _ALCHEMIST // Robin + #define _TEACHER_SYSTEM // ʦϵͳ() + #define _PET_ITEM // װ +#endif + + +//ͨ------------------------------------- +#define _PUB_ALL +#ifdef _PUB_ALL + //#define _PROSKILL_ERR_KICK // ǷԶT + #define _ITEM_SETLOVER // 鹦 + #define _CREATE_MM_1_2 // Ʒٷ + #define _SendTo // ͵ + #define _GET_BATTLE_EXP // + #define _NEW_PLAYER_CF // ״̬ + #define _USER_EXP_CF // ûԶ徭 + #define _TRANS_LEVEL_CF // תԽ160 + #define _UNLAW_WARP_FLOOR // ֹ͵ + #define _UNREG_NEMA // ֹ + #if _ATTESTAION_ID != 1 + #define _GM_ITEM // GMƷ + #endif + #define _GM_METAMO_RIDE // GMг + #ifdef _NEW_RIDEPETS + #define _GM_RIDE // GMȨ + #endif + #define _LOCK_IP // IP + #define _POINT // + #define _VIP_SERVER // Ա + #define _WATCH_FLOOR // Զɹսͼ + #define _BATTLE_FLOOR // Զǿսͼ + #define _VIP_SHOP // Ա̵ + #if _ATTESTAION_ID != 1 + #define _LOOP_ANNOUNCE // ѭ + #endif + #define _SKILLUPPOINT_CF // Զ + #define _RIDELEVEL // Զȼ + #define _REVLEVEL // Զԭȼ + #define _FM_ITEM // + #define _LUCK_ITEM // + #define _NEW_PLAYER_RIDE // + #define _FIX_CHARLOOPS // ħʯʱ + #if _ATTESTAION_ID != 1 + #define _PLAYER_ANNOUNCE // + #endif + #define _BATTLE_GOLD // ȡͬʱýǮ + #define _ITEM_GOLD // ǮƷ + #define _PLAYER_NUM // + #define _PET_MM // ʯMM + #define _MYSTERIOUS_GIFT // + #define _RELOAD_CF // ضCF + #define _PET_AND_ITEM_UP // ɼ˶ij + #define _TRANS // ת + #ifdef _NEW_RIDEPETS + #define _RIDEMODE_20 // 2.0ģʽ + #endif + #define _TALK_ACTION // ˵ + #define _ENEMY_ACTION // Ҳл + #define _CHAR_CDKEY // ֹ +// #define _GMSV_DEBUG // GMSVϢ + #define _CHECK_PEPEAT // Ƿ + #define _SILENTZERO // Ʒ + #define _SAVE_GAME_ID // ʾķ +#endif + +//Ա׷ӹ-------------------------------------- +#define _VIP_ALL +#ifdef _VIP_ALL + #define _NEW_RIDEPETS // (ɿ) ANDY + #define _RIDEMODE_20 // 2.0ģʽ + #define _VIP_RIDE // Աڼ + #define _AUTO_PK // ԶPKϵͳ + //#define _FM_METAMO // רñָ + #define _ITEM_METAMO_TIME // ԶĽָ + #define _SHOW_VIP_CF // ԶVIPˣ壬ʾʽ + #define _GM_KING // GMħ + #define _ANGEL_TIME // Զ徫ٻʱ + #define _FM_POINT_PK // ׯ԰廥ׯ԰ + #if _ATTESTAION_ID != 1 + #define _PLAYER_MOVE // ˳ƹ + #endif + #define _BATTLE_PK // ǿPKߣ˻ؼ¼ + #ifdef _PET_FUSION + #define _FUSIONBEIT_TRANS // ںϳת + #define _FUSIONBEIT_FIX // ȡںϳ + #endif + #define _TRANS_7_NPC // תNPC + #ifdef _NEW_MANOR_LAW + #define _MOMENTUM_NPC // ƽű + #endif + + #ifdef _NEW_RIDEPETS + #define _RIDE_CF // Զ + #define _FM_LEADER_RIDE // 峤ר + #endif + #define _PET_LEVEL_ITEM // ȼƷ + //#define _DBSAVE_CHAR // ˫浵 + #define _FM_JOINLIMIT // ٴμʱ + #define _PET_BEATITUDE // ף + #define _ITEM_EFMETAMO // ñָ + #define _ITEM_RIDE // ѱװ + #define _MAKE_MAP // ͼ + #define _MAKE_PET_CF // Զɳ + #define _MAKE_PET_ABILITY // ԶΧ + #define _GET_MULTI_ITEM // һθƷ + #define _RE_GM_COMMAND // ԶGM + #define _ONLINE_TIME // ʱ + #define _NPC_INT_SET // NPC + #define _VIP_ONLINE // Աʾ + +#endif + +#if _ATTESTAION_ID != 9 && _ATTESTAION_ID != 11 + #define _LOGNZORO_FUNC_ALL // zoro +#else + #define _NEW_VIP_SHOP // Ա̵(SAAC) + #define _ONLINE_COST // ֵ߳(SAAC) + #define _NULL_CHECK_ITEM // ͷ֧Ʊ + #define _COST_ITEM // ֵ + #define _CRYPTO_DATA // ݼϵͳ +#endif +#ifdef _LOGNZORO_FUNC_ALL + #if _ATTESTAION_ID != 1 + #define _TRANS_7_SHOW // 7תʾ + #endif + #define _ITEM_COLOER // Ʒɫ + #define _TALK_MOVE_FLOOR // ˵ƶ + #ifdef _TRADESYSTEM2 + #define _TRADE_PK // PK + #endif + #if _ATTESTAION_ID != 1 + #define _VIP_POINT_PK // ֵPK + #endif + #define _MAP_HEALERALLHEAL // ָͼսԶظ + #if _ATTESTAION_ID != 1 + #define _NEW_AUTO_PK // µԶPKϵͳ + #endif + #define _OPEN_E_PETSKILL // ųE + #if _ATTESTAION_ID != 1 + #define _VIP_ONLINE // Աʾ + #endif + #define _VIP_LOGOUT // Աʱʾ + #if _ATTESTAION_ID != 1 + #define _THE_WORLD_SEND // ˵Ƶ + #endif +#define _THE_WORLD_SEND // ˵Ƶ + #define _SUPER_FLOOR_MIC // ͼ˷ + #define _NPC_GET_PETABI // NPCԶɳij + #define _SAMETHING_SAVEPOINT // ijЩ¼Զ浵 + #define _NEW_VIP_SHOP // Ա̵(SAAC) + #if _ATTESTAION_ID != 8 && _ATTESTAION_ID != 10 && _ATTESTAION_ID != 21 + #define _ITEM_PET_LOCKED // Ʒ(SAAC) + #endif + #define _ONLINE_COST // ֵ߳(SAAC) + #if _ATTESTAION_ID != 3 + #define _VIPPOINT_OLD_TO_NEW // ֵת(SAAC) + #endif + #define _LOGIN_DISPLAY // ʾ + //#define _NEED_ITEM_ENEMY // ץƷԶ + #define _SUPER_MAN_ITEM // Ʒ˵ + #define _AUTO_DEL_PET // Զɾ + #define _AUTO_DEL_ITEM // ԶɾƷ + #define _POOL_ITEM_BUG // ֹǿBUG + + #if _ATTESTAION_ID != 5 + #if _ATTESTAION_ID != 1 + #define _BOUND_TIME // Ұʱ + #endif + #define _SPECIAL_MAP // ͼ + #ifdef _FONT_SIZE + #define _TALK_SIZE_ITEM // + #endif + #define _NEW_NAME // Զƺ + #define _CRYPTO_DATA // ݼϵͳ + #ifdef _NEW_VIP_SHOP + #define _COST_ITEM // ֵ + #endif + #define _ITEM_EXP // ҩˮ() + #define _NULL_CHECK_ITEM // ͷ֧Ʊ + #define _MEMORY_ITEM // ָ + #define _NPC_SCRIPT // NPCű + //#define _BT_PET // BTﱶ + #define _BT_ITEM // BTƷ + #define _NO_JOIN_FLOOR // ֹ͵ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 4 || _ATTESTAION_ID == 6 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 10 || _ATTESTAION_ID == 14 || _ATTESTAION_ID == 15 || _ATTESTAION_ID == 17 || _ATTESTAION_ID >= 19 + #ifdef _STREET_VENDOR + #define _NEW_STREET_VENDOR // °̯ + #endif + #endif + + #if _ATTESTAION_ID != 1 && _ATTESTAION_ID != 18 + #define _LUCK_STAR // (ʱƷ) + #endif + #if _ATTESTAION_ID != 1 + #define _BT_ITEM // BTƷ + #endif + #ifdef _CHATROOMPROTOCOL + #define _NPC_SAVEPOINT // ¼ + #endif + #define _SPECIAL_SUIT // װ + #define _MANOR_EQUIP // ׯ԰רװ + #define _ITEM_UPLEVEL // װ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 4 || _ATTESTAION_ID == 6 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 10 || _ATTESTAION_ID == 14 || _ATTESTAION_ID == 15 || _ATTESTAION_ID >= 17 + //#define _TRANS_POINT_UP // ÿת + #if _ATTESTAION_ID != 8 + #if _ATTESTAION_ID != 1 + #define _FIND_TREASURES // Ѱұ + #endif + #define _UNLAW_THIS_LOGOUT // ֹԭ + #define _ITEM_PERCENTAGE // Ʒٷֱ + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 4 || _ATTESTAION_ID == 6 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 10 || _ATTESTAION_ID == 14 || _ATTESTAION_ID == 17 || _ATTESTAION_ID >= 20 + #define _ITEM_POOLITEM // ֿ߲ + #define _ITEM_POOLPET // ֿ + #define _ADD_NEWEVENT_1024 // 1024 + #define _SUPER // ƶ˵֧ + #define _NEW_SKILL // ¼ܿ + #if _ATTESTAION_ID != 1 + #define _NEW_GM_ITEM // GMƷ + #endif + #define _SHOW_PET_ABL // ʾ + #define _NEWEVENT_ITEM // + #ifdef _NEW_RIDEPETS + #define _ADD_RIDE_CF // Զ + #endif + #define _NO_STW_ENEMY // ֹҿ + #define _NEW_PET_BEATITUDE // һף + #define _BATTLE_GETITEM_RATE // սƷ + #define _INSLAY_NOT_PILENUMS // ܾƷ + #if _ATTESTAION_ID == 14 || _ATTESTAION_ID == 28 + #define _ONLINE_TIME // ʱ + #define _NPC_INT_SET // NPC + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 4 || _ATTESTAION_ID == 6 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 14 || _ATTESTAION_ID == 20 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 23 || _ATTESTAION_ID >= 25 + #if _ATTESTAION_ID != 1 || _ATTESTAION_ID != 25 + #define _TALK_SAVE // ˵浵 + #define _PLAYER_QUESTION_ONLIEN // ߴ + #endif + #endif + #if _ATTESTAION_ID == 28 + #define _LOTTERY_SYSTEM // Ʊϵͳ + #define _NPC_CHECK_SCRIPT // жϽű + #endif + #if _ATTESTAION_ID == 38 + //#define _PET_TRANS_ABILITY // ת + #endif + #if _ATTESTAION_ID != 38 && _ATTESTAION_ID != 49 + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 8 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 23 || _ATTESTAION_ID >= 30 + #define _OLYMPIC_TORCH // ƥ˻ + #if _ATTESTAION_ID != 1 + #define _LOTTERY_SYSTEM // Ʊϵͳ + #define _PLAYER_DIY_MAP // DIYͼ + #endif + #define _AMPOINT_LOG // ֵ¼ + #define _SQL_VIPPOINT_LOG // ػرҼ¼ + #define _NPC_CHECK_SCRIPT // жϽű + #define _TALK_CHECK // ˵֤ + #define _ONE_PET_SKILL // һԳ輼 + #define _MAGIC_SPECIAL // ħ + #if _ATTESTAION_ID != 1 + #define _BATTLE_PK_TYPE // PKѡ + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 23 || _ATTESTAION_ID >= 31 + #if _ATTESTAION_ID != 1 + #define _NPC_AUTO_MOVE // ܹƶNPC + #endif + #define _SYSTEM_SPEAD // ϵͳ ݲţӰսһ + #define _FILTER_TALK // ˵ + #if _ATTESTAION_ID != 34 + #define _ALL_SERV_SEND // Ƶ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 32 || _ATTESTAION_ID == 33 || _ATTESTAION_ID >= 35 || _ATTESTAION_ID != 39 + #define _PET_TRANS_ABILITY // ת + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 32 || _ATTESTAION_ID == 35 || _ATTESTAION_ID >= 45 + #define _CANCEL_ANGLE_TRANS // ȡٻ + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 33 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 36 || _ATTESTAION_ID == 37 || _ATTESTAION_ID == 40 || _ATTESTAION_ID >= 43 + #define _COMPOUND_EXP // ϳɾ + #define _ASSESS_ABILITY // + #define _ONLINE_TIME // ʱ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 37 || _ATTESTAION_ID >= 43 + #ifndef _VERSION_25 + #define _PAUCTION_MAN // ϵͳ + #endif + #endif + #define _NOT_ESCAPE // ֹ + #define _PLAYER_OVERLAP_PK // صʱPK + #define _FIMALY_PK_TIME // 忪Ƭʱ趨 + #endif + #endif + #endif + #endif + #endif + #endif + #endif + #endif + #else + #define _FORMULATE_AUTO_PK // ƶԶPKϵͳ(SAAC) + #endif + + #ifdef _MAGIC_SPECIAL +// #define _MAGIC_FEATHERS // ħë + #endif + + #ifdef _TALK_CHECK + #define _NPC_TALK_CHECK // NPC˵֤ + #define _ITEM_TALK_CHECK // ˵֤ + #endif + + #ifdef _NPC_SCRIPT + #define _NPC_CHECKTIME // NPCʱж + #define _FAME_CHECK_NPC // NPCж + #define _SQL_BUY_FUNC // SQL + #define _DEL_FAME // ۼ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 36 || _ATTESTAION_ID == 37 || _ATTESTAION_ID == 40 || _ATTESTAION_ID >= 43 + #define _NPC_INT_SET // NPC + #endif + #endif + + #ifdef _NEW_SKILL + #define _ITEM_ATTSKILLMAGIC // (ɿ) ANDY ߼ + #define _MASSAGE_PETSKILL // ɱ + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 23 || _ATTESTAION_ID >= 30 + #define _EXPANSION_ITEM_INSLAY // չⱦʯ + #define _STRENGTH_PETSKILL // Ԫ輼 + #define _EXPANSION_POWERBALANCE // չPETSKILL_PowerBalance + #define _RESURRECTION_PETSKILL // 輼 + #define _LOSTLOST_PETSKILL // ܾ + #define _GRAPPLING_PETSKILL // + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 23 || _ATTESTAION_ID >= 31 + #define _PETSKILL_EXPLODE // (ɿ) Change 輼:ѹ + #define _PETOUT_PETSKILL // Ϣ輼 + #define _FIX_PETSKILL_HECTOR // ޸ü޷turn + #endif + #endif + #endif +#endif + +#if _ATTESTAION_ID == 1 && _ATTESTAION_ID != 2 && _ATTESTAION_ID != 3 && _ATTESTAION_ID != 5 && _ATTESTAION_ID != 6 && _ATTESTAION_ID != 9 && _ATTESTAION_ID != 10 && _ATTESTAION_ID != 11 && _ATTESTAION_ID != 14 && _ATTESTAION_ID != 15 && _ATTESTAION_ID != 19 && _ATTESTAION_ID != 26 && _ATTESTAION_ID != 27 && _ATTESTAION_ID != 28 && _ATTESTAION_ID != 31 && _ATTESTAION_ID != 33 && _ATTESTAION_ID != 34 && _ATTESTAION_ID != 36 && _ATTESTAION_ID != 38 && _ATTESTAION_ID != 39 && _ATTESTAION_ID != 45 +// #define MANOR_MAX_NUM 2 // (4.0) ݵ +#else + #define MANOR_MAX_NUM 4 // (4.0) ׯ԰ +#endif + +#if _ATTESTAION_ID != 5 && _ATTESTAION_ID != 11 + //#define FAMILY_MAX_MEMBER 50 // +#else + #define FAMILY_MAX_MEMBER 50 // +#endif + +#define _FIX_COPY_MM_BUG //޸MMBUG +#define _FIX_PETSKILL_BUG //޸\صʹ + +#if _ATTESTAION_ID != 3 && _ATTESTAION_ID != 5 && _ATTESTAION_ID != 11 +//#define _CHARADATA_SAVE_SQL //дSQL +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 23 || _ATTESTAION_ID == 28 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 33 || _ATTESTAION_ID == 34 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 36 || _ATTESTAION_ID == 37 || _ATTESTAION_ID >= 40 + #if _ATTESTAION_ID != 49 + #define _SASQL // MYSQL + #endif +#endif +#ifdef _SASQL +#ifdef _STREET_VENDOR + #if _ATTESTAION_ID != 43 + #if _ATTESTAION_ID != 28 && _ATTESTAION_ID != 34 + #define _ONLINE_SHOP_MYSQL // ̳ǸijMYSQLػر + #endif + #define _STREET_VENDOR_MYSQL // MYSQLػرҰ̯ + #endif +#endif +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 23 || _ATTESTAION_ID == 33 + #define _EXPANSION_VARY_WOLF // չ± +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 21 + #define _SHOW_ITEM // װ + #define _SHOW_ITEM_NAME // װ +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 +#ifdef _VERSION_80 + #define _DISABLE_PROFESSION_SKILL // ֹʹְҵܼ + #define _TAKE_ITEMDAMAGE_FIX // װ + #define _TAKE_ITEMDAMAGE_FOR_PET // װװ +#endif +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 35 + #define _GM_SAVE_ALL_CHAR // GM浵 +#endif + +#if _ATTESTAION_ID == 35 + //#define _SHOW_FMPOINT //ʾׯ԰ + #define _NOT_FMPK_WAIT //սս +#endif + +#if _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 16 || _ATTESTAION_ID == 33 || _ATTESTAION_ID == 34 || _ATTESTAION_ID == 41 + #ifdef _BOUND_TIME + #define _VIP_BOUND_TIME + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 41 + #define _BOUND_TIME_EXPANSION // ʱչ + #endif + #endif +#endif + +//#define _ABSOLUTE_DEBUG // Ե + + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 14 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 28 || _ATTESTAION_ID == 30 || _ATTESTAION_ID == 31 || _ATTESTAION_ID == 32 || _ATTESTAION_ID == 33 || _ATTESTAION_ID == 35 || _ATTESTAION_ID == 36 || _ATTESTAION_ID == 37 || _ATTESTAION_ID == 40 || _ATTESTAION_ID == 44 || _ATTESTAION_ID == 45 || _ATTESTAION_ID == 46 + #define _ALLBLUES_LUA // ʹLUAű +#endif + +#ifdef _ALLBLUES_LUA + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 + #define _ALLBLUES_LUA_1_1 // LUA1.1 + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 + #define _ALLBLUES_LUA_1_2 // LUA1.2 + #define _ALLBLUES_LUA_1_3 // LUA1.3 + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 32 + #define _ALLBLUES_LUA_1_4 // LUA1.4 + #endif + + #if _ATTESTAION_ID == 1 + #define _ALLBLUES_LUA_1_5 // LUA1.5 + #endif + + #if _ATTESTAION_ID == 1 + #define _ALLBLUES_LUA_1_6 // LUA1.6 + #endif + #if _ATTESTAION_ID == 1 + #define _ALLBLUES_LUA_1_7 // LUA1.7 + #endif + #if _ATTESTAION_ID == 1 + #define _ALLBLUES_LUA_1_8 // LUA1.8 + #endif + + #if _ATTESTAION_ID == 1 + #define _ALLBLUES_LUA_1_9 // LUA1.9 + #endif + + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 + #define _PETSKILL_SHOP_LUA // \̵LUA + #endif + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 + #define _OFFLINE_SYSTEM // ϵͳ + #endif +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 1 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 32 + #define _PLAYER_NPC // +#endif + +#if _ATTESTAION_ID == 0 || _ATTESTAION_ID == 3 + #define _OTHER_SAAC_LINK // һSAAC +#endif + +#if _ATTESTAION_ID == 1 + #define _ONE_SERVER // +#endif + +#if _ATTESTAION_ID == 32 + #define _NOT_NOCRYPTO_LUA // öȡǼLUAű +#endif + +#if _ATTESTAION_ID == 1 + #define _CRYPTO_LUA // luaű +#endif + +#if _ATTESTAION_ID == 1 + #define _CAMEO_MONEY // ǻ + #define _MISSION_TRAIN // + #define _DEL_DROP_PET // ɾϳ + #define _PET_EVOLVE // + //#define _PET_ADD_EXP // ᆳ + #define _FIX_ADD_EXP // ޸Ӿ + #define _FMRIDE_NOT_FMSPRITE // 費ֹڰ + #define _NOT_SHOW_ONLINE_NUM // ʾ + #define _ITEM_COLOER_DIFFER // ɫͬ + #define _SPECIAL_COUNTER // + #define _SPECIAL_TIMER // ʱ + #define _RECORD_IP // ¼IP + #define _FIX_STW_SPEED_ENEMY // ޸ҿ + //#define _DEL_NOT_25_NEED_ITEM // ɾ2.5ץ + #define _LOCK_PET_ITEM // 󶨳 + #define _ULTIMATE_ANNOUNCE // ֪ͨ + #define _SHIP_MATEMO // ı + #define _FIX_CORE_LOOP // ޸CORE_LOOP + #define _VIP_BATTLE_EXP // Աս + #define _FLOOR_DIFI_FIELD // ¥ֶ + #define _FM_FMPOINTPK_LIST // ׯ԰սб + //#define _BATTLE_BOUT_TIME // սغʱ + #define _ACTIVE_GAME // ֵ + #define _INVERSION_PETSKILL // ת + #define _NO_HELP_MAP // ֹHELP + #define _BATTLE_TIME // սʱ + //#define _SAME_IP_ONLINE_NUM // ͬIP½ + #define _VIP_TRANS // VIPת + #define _STREET_VENDOR_TRANS // ̯ת + #define _KEEP_UP_NO_LOGIN // άֹ½ + #define _FIX_CHAR_LOOP // ѭ + #define _FIX_SAVE_CHAR // 浵 + #define _FIX_P_VS_P_PARENT // PVPս + #define _FMPOINT_PKTIME_SELECT// ѡսʱ + #define _CHECK_SEVER_IP // жϷIP + #define _DAMMAGE_CALC // Զ˺ + #define _PLAYER_TITLE // ҳƺ + #define _VIP_PET_TRANS // Աת + //#define _UNIFIDE_MALINASI // ͳһ˿ + //#define _FIX_PET_SKILL // ޸\ + //#define _NO1_B2_NONO // B2ѧڵһλʱԶ21 + //#define _FMPOINT_APPEND_ABI // ׯ԰Ա + #define _ITEM_OVER_LAP // ظ + #define _NEW_LOAD_NPC // ȡNPC + #define _NEW_LOAD_MAP // ȡͼ + #define _NO_CLS_EVENT_255 // 255 + #define _MISSION_TIME // ʱ + #define _MVP_LOCK_JP // MVPƷ + //#define _FMPOINTPK_FOR_TWO // ÿսΪ + #define _BURST_LOG // ֶ־ + #define _STREET_VENDOR_EFFECT // ̯ʾ + //#define _MASK_ENCOUNTER // ԭط + #define _NEWCLISETMAC // ¼ͻ˵MACַ + #define _NEWCLISETSERVID // ¼ͻ˷ID + //#define _FMPOINT_PK_MESSAGE // սȫͨ + //#define _FMPOINT_WELFARE // ׯ԰ + #define _REGISTRATION_TIME // ǩʱ + #define _FAME_REG_TIME // ǩʱ +#ifdef _OFFLINE_SYSTEM + #define _OFFLINE_TIME // ʱ +#endif + #define _DATA_INFO_SHOW // Ϣʾ + #define _ITEM_USE_TIME // ʹʱ +// #define _PET_VALIDITY // Ч + //#define _PET_FUSION_LUA // ںϳLUA + //#define _PET_ENEMY_DEVELOP_UP //ȫɳ + #define _FIRST_LOCK_ITEM //һν׺ԶƷ + #define _CTRL_TRANS_DEVELOP //Ƴɳ + #define _CANCEL_STREET_VENDOR //ֹ̯ + //#define _ABDUCT_NO_PETOUT //óֱ̻ͬʱ + //#define _SUPER_FMPOINT //ׯ԰ + #define _ATTACK_RAND_SORT //˳ + #define _POWER_UP // + #define _FM_POINT_APPLY_FAME //ׯ԰ + #define _PET_MAKE_2_TRANS // Terry ˥͡GM + +#endif +#if _ATTESTAION_ID == 0 + #define _DEBUG_ALL +#endif + +#if _ATTESTAION_ID == 35 + #define _DAMMAGE_CALC // Զ˺ +#endif + +#endif + +// SA_REVERSION NEW ADD +//====================================================================================== +#define _BRAND_NEW_25 //2.5汾ܿ ֮󽫴2.5еĹ +//====================================================================================== + +//############### Ϣ #################### +#define _SA_VERSION 'N' +#define _DEFAULT_PKEY "starttwneo" // ĬϵԿ +#define _RUNNING_KEY "runtwtrinity" // Կ +//############### Ϣ #################### + +//############### ͨð汾ܶ #################### +#define _JZ_NEWSCRIPT_LUA // LUAű +#ifdef _JZ_NEWSCRIPT_LUA + #define _MO_LNS_NLSUOXU // LNS-NL + #define _MO_LNS_CHARSUOXU // LNS-CHAR + #define _MO_LNS_NLGSUOXU // LNS-NLG + #define _MO_LNS_MAPSUOXU // LNS-MAP + #define _MO_LNS_MYSQLSUOXU // LNS-MYSQL + #define _MO_LUA_BETT01 // LUAӽӿ + #define _LUA_Debug // LUA + #define _MO_ADD_LUADX // LUAһЩչ + #define _ITEM_LUA // LUA֧ +#endif +//#define _MO_SHOW_DEBUG //ʾϢ +//#define _NO_ATTACK // CC +//#define _NO_FULLPLAYER_ATT // ˹ +//#define _NEW_VERIFICAITON //ĭ޸µLUA֤㷨 +#define _SHARE_EXP // 鹲 +#define EXPGET_MAXLEVEL 5 //鲻˥ȼ +#define EXPGET_DIV 15 //ָȼ +#ifdef _SHARE_EXP +#define _COMBO_EXP // ϻӳ +#endif +#define _GAMBLE_POINT //SQLIJ +#define _TRIAL_POINT //SQL +#define _MO_LUA_FMPOINT //ݵصluaӿ +#define _DEFEND_BIGBAO // +#define _SERVER_DEF // ȫ +//#define _DEBUG_RET_CLI +#define _NOT_FMPK_WAIT //սս +#define _SINGLE_ONLINE // +#define _CHAR_LOOP_TIME //charʱ +#define _MO_IMAGE_EXTENSION //չ + +#define _CHANGE_PETNAME_FIX //ֹǷ +#define _MO_RELOAD_NPC //ضNPC +#define _ROOKIE_ITEM //ֵ 1ת֮ɾ ޷װ +#define _NO_TRANS_ITEM //ֹתЯĵ +#define _MAX_MERGE_LEVEL //ߺϳɵߵȼ +#define _MO_MAP_AUTO_UPDATE //Զµͼ +#define _NEW_FUNC_DECRYPT //½ܻ + +#define _PLAYER_EFFECT //Ч +#define _MO_PLAYER_EFFECT //Чֶ +#define _MO_LUA_KS_CALLBACK //KSӿLUAص սѡ¼ +#define _MO_LOGIN_NO_KICK //¼ +#define _ATTACK_EFFECT // Terry Ч +#define _STREET_VENDOR_CHECK //̯ⳤ +#define _MO_LUA_TALK_EX //ablua˵չ +#define _MO_LUA_ENCOUNTER_CONTROL //abluaп +#define _MO_ILLEGAL_NAME // ֹ +//#define _MO_NO_WALK //ֹ· +#define _MO_FIX_ULTIMATE //޸ж +#define _TENSE_FIELD //ʱֶ + +#define _CHAR_NANOR_ //¹⻷ +#define FAMILY_MANOR_ //ׯ԰⻷ +#define _NETLOG_ //T־ +#define _PETCOM_ // +#define _MORECHARACTERS_ //ҳ +#define _FAMILYBADGE_ // +#define _SECONDARY_WINDOW_DATA_ //ݷ +#define _TRUNTABLE_ //ת̸· עҪӸ꣬÷ҪΪݸ +#define _PETFOLLOW_NEW_ //5ֻȦ +#define _TRUMP_EQUIPMENT //װ +#define _FIX_SUPERPERSON_STRANS //޸6תBUG +#define _PETMAIL_TIME // ʼԶʱ䣨Ҳdzݣ +#define _MO_LUA_RESIST //⿹Եluaӿڼֶ +#define _MO_FIX_STREET_VENDOR //̯ӿڹµĿ +#define _MO_LUA_BATTLE_START //սʼӿڻص +#define _REDUCE_MERGE_FAME //޹ҷļϳȼ +#define _ALLDOMAN // (ɿ) Syu ADD аNPC +#define _ALLDOMAN_DEBUG // (ɿ) Change serverаʧbug +#define _MO_LUA_MERGE_CALLBACK //ϳluaص +#define _ALWAYS_TEAM_OPEN //¼ĬϿ +#define _FIX_LER_IMG //޸׶ +#define _NPC_MAGICCARD // ħNPC +#define _MOVE_SCREEN //ƶĻ +#define _BATTLE_OVER_STAR_TIME// ս¿ʼʱ + +#define _NEW_SQL_MONEY //SQL + +//############### ͨð汾ܶ #################### + +//############### 2.5йܶ #################### +#ifdef _BRAND_NEW_25 +#define _DEFAULT_PKEY "shiqi" // ĬϵԿ +#define _RUNNING_KEY "shiqi.hk" // Կ +#define DENGLUKEY1 "6D27AEB8326A2A8E7D04B9F9B44C59C7" + +#define _NEW_TITLE //³ƺϵͳ +#define _NEW_UPDATETITLE //³ƺŷ +#define CHAR_RECORD_POINT //¼ͻ˶ȡ +#define _FREE_SAVE // ¼ +#define FAMILY_MAX_MEMBER 50 // +#define MANOR_MAX_NUM 2 // (4.0) ݵ +#define _LEVELUP_RECOVERY //Ѫ +#define _NEW_ITEM_ //µ + +#define _VISUAL_BEATITUDE //¿ӻף +#define _RIDEFLG_ //迪 +#define _RIDEQUERY_ //ѯ +#define _PREVENT_TEAMATTACK //ֹͬӻ +#define _SHOW_VISUAL_BEATITUDE //װ̯ʾӻף +#define _MO_REDUCE_PVP_COMBO //PVPϻ +#define _BATTLE_OVER_STAR_TIME// ս¿ʼʱ +//#define _CANCEL_BORN_PET // ȡ + +#define _NPC_EVENT_NOTICE //ĭNPC״̬ʾܣͻ˿ú깦 +#ifdef _NPC_EVENT_NOTICE + #define EVENT_NOT_RESPOND 120138 //ɫ̾ ɻδﵽ + #define EVENT_CAN_ACCECPT 120137 //ɫ̾ Խ + #define EVENT_READY_TO_START 120139 //ɫʺ Խ + #define EVENT_CANNOT_START 120140 //ɫʺ ܽ +#endif +#define _CHAR_TITLE_STR_ //ֳƺ +#define _NEW_UPDATETITLE //³ƺŷ + +#define _NO_TEAMWARP_SKYLAND //ֹ +#define _GLORY_POINT //SQL +#define _MO_LUA_GOLRYCALLBACK //ص +#define _RED_MEMOY_ // +#endif +//############### 2.5йܶ #################### diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_serv.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_serv.h new file mode 100644 index 0000000..15efbd0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_serv.h @@ -0,0 +1,473 @@ +#ifndef _PROTOCOL_H_ +#define _PROTOCOL_H_ + +#include "lssproto_util.h" // for StoneAge + +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 13 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 13 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 13 + 1 ) +#endif + +int lssproto_InitServer(int (*writefunc)(int,char*,int) , int worksiz ); +void lssproto_SetServerLogFiles( char *read , char *write ); +void lssproto_CleanupServer( void ); +int lssproto_ServerDispatchMessage(int fd, char *encoded); + +#define SEPARATOR ";" + +#define LSSPROTO_W_RECV 0 +#define LSSPROTO_W2_RECV 1 +#define LSSPROTO_XYD_SEND 2 +#define LSSPROTO_EV_RECV 3 +#define LSSPROTO_EV_SEND 4 +#define LSSPROTO_EN_RECV 5 +#define LSSPROTO_DU_RECV 6 +#define LSSPROTO_EN_SEND 7 +#define LSSPROTO_EO_RECV 8 +#define LSSPROTO_BU_RECV 9 +#define LSSPROTO_JB_RECV 10 +#define LSSPROTO_LB_RECV 11 +#define LSSPROTO_RS_SEND 12 +#define LSSPROTO_RD_SEND 13 +#define LSSPROTO_B_RECV 14 +#define LSSPROTO_B_SEND 15 +#define LSSPROTO_SKD_RECV 16 +#define LSSPROTO_ID_RECV 17 +#define LSSPROTO_PI_RECV 18 +#define LSSPROTO_DI_RECV 19 +#define LSSPROTO_DG_RECV 20 +#define LSSPROTO_DP_RECV 21 +#define LSSPROTO_I_SEND 22 +#define LSSPROTO_MI_RECV 23 +#define LSSPROTO_SI_SEND 24 +#define LSSPROTO_MSG_RECV 25 +#define LSSPROTO_MSG_SEND 26 +#define LSSPROTO_PMSG_RECV 27 +#define LSSPROTO_PME_SEND 28 +#define LSSPROTO_AB_RECV 29 +#define LSSPROTO_AB_SEND 30 +#define LSSPROTO_ABI_SEND 31 +#define LSSPROTO_DAB_RECV 32 +#define LSSPROTO_AAB_RECV 33 +#define LSSPROTO_L_RECV 34 +#define LSSPROTO_TK_RECV 35 +#define LSSPROTO_TK_SEND 36 +#define LSSPROTO_MC_SEND 37 +#define LSSPROTO_M_RECV 38 +#define LSSPROTO_M_SEND 39 +#define LSSPROTO_C_RECV 40 +#define LSSPROTO_C_SEND 41 +#define LSSPROTO_CA_SEND 42 +#define LSSPROTO_CD_SEND 43 +#define LSSPROTO_R_SEND 44 +#define LSSPROTO_S_RECV 45 +#define LSSPROTO_S_SEND 46 +#define LSSPROTO_D_SEND 47 +#define LSSPROTO_FS_RECV 48 +#define LSSPROTO_FS_SEND 49 +#define LSSPROTO_HL_RECV 50 +#define LSSPROTO_HL_SEND 51 +#define LSSPROTO_PR_RECV 52 +#define LSSPROTO_PR_SEND 53 +#define LSSPROTO_KS_RECV 54 +#define LSSPROTO_KS_SEND 55 +#define LSSPROTO_AC_RECV 56 +#define LSSPROTO_MU_RECV 57 +#define LSSPROTO_PS_RECV 58 +#define LSSPROTO_PS_SEND 59 +#define LSSPROTO_ST_RECV 60 +#define LSSPROTO_DT_RECV 61 +#define LSSPROTO_FT_RECV 62 +#define LSSPROTO_SKUP_SEND 63 +#define LSSPROTO_SKUP_RECV 64 +#define LSSPROTO_KN_RECV 65 +#define LSSPROTO_WN_SEND 66 +#define LSSPROTO_WN_RECV 67 +#define LSSPROTO_EF_SEND 68 +#define LSSPROTO_SE_SEND 69 +#define LSSPROTO_SP_RECV 70 +#define LSSPROTO_CLIENTLOGIN_RECV 71 +#define LSSPROTO_CLIENTLOGIN_SEND 72 +#define LSSPROTO_CREATENEWCHAR_RECV 73 +#define LSSPROTO_CREATENEWCHAR_SEND 74 +#define LSSPROTO_CHARDELETE_RECV 75 +#define LSSPROTO_CHARDELETE_SEND 76 +#define LSSPROTO_CHARLOGIN_RECV 77 +#define LSSPROTO_CHARLOGIN_SEND 78 +#define LSSPROTO_CHARLIST_RECV 79 +#define LSSPROTO_CHARLIST_SEND 80 +#define LSSPROTO_CHARLOGOUT_RECV 81 +#define LSSPROTO_CHARLOGOUT_SEND 82 +#define LSSPROTO_PROCGET_RECV 83 +#define LSSPROTO_PROCGET_SEND 84 +#define LSSPROTO_PLAYERNUMGET_RECV 85 +#define LSSPROTO_PLAYERNUMGET_SEND 86 +#define LSSPROTO_ECHO_RECV 87 +#define LSSPROTO_ECHO_SEND 88 +#define LSSPROTO_SHUTDOWN_RECV 89 +#define LSSPROTO_NU_SEND 90 +#define LSSPROTO_TD_RECV 91 +#define LSSPROTO_TD_SEND 92 +#define LSSPROTO_FM_SEND 93 +#define LSSPROTO_FM_RECV 94 +#define LSSPROTO_WO_SEND 95 +#define LSSPROTO_PETST_RECV 96 + +#ifdef _MIND_ICON +#define LSSPROTO_MA_RECV 98 +#endif + +#ifdef _ITEM_CRACKER +#define LSSPROTO_IC_SEND 100 +#endif + +#ifdef _MAGIC_NOCAST // :Ĭ +#define LSSPROTO_NC_SEND 101 +#endif + +#ifdef _TEAM_KICKPARTY +#define LSSPROTO_KTEAM_RECV 106 +#endif +#ifdef _PETS_SELECTCON +#define LSSPROTO_PETST_SEND 107 +#endif +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +#define LSSPROTO_RESIST_RECV 108 +#define LSSPROTO_RESIST_SEND 109 +#endif +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +#define LSSPROTO_BATTLESKILL_RECV 110 +#define LSSPROTO_BATTLESKILL_SEND 111 +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +#define LSSPROTO_CHATROOM_RECV 112 +#define LSSPROTO_CHATROOM_SEND 113 +#endif + +#define LSSPROTO_SPET_RECV 114 // Robin +#define LSSPROTO_SPET_SEND 115 + +#ifdef _STREET_VENDOR +#define LSSPROTO_STREET_VENDOR_RECV 116 // ̯ +#define LSSPROTO_STREET_VENDOR_SEND 117 +#endif + +#ifdef _RIGHTCLICK +#define LSSPROTO_RCLICK_RECV 118 +#define LSSPROTO_RCLICK_SEND 119 +#endif + +#ifdef _JOBDAILY +#define LSSPROTO_JOBDAILY_SEND 120 // CYG־ +#define LSSPROTO_JOBDAILY_RECV 121 +#endif + +#ifdef _TEACHER_SYSTEM +#define LSSPROTO_TEACHER_SYSTEM_RECV 122 // ʦ +#define LSSPROTO_TEACHER_SYSTEM_SEND 123 +#endif + +#ifdef _ADD_STATUS_2 +#define LSSPROTO_S2_RECV 124 +#define LSSPROTO_S2_SEND 125 +#endif + +#ifdef _PET_ITEM +#define LSSPROTO_PET_ITEM_RECV 127 +#endif + +#ifdef _MOVE_SCREEN +#define LSSPROTO_MOVE_SCREEN_SEND 128 +#endif +#ifdef _THEATER +#define LSSPROTO_THEATER_DATA_SEND 131 +#define LSSPROTO_THEATER_DATA_RECV 132 +#endif + +#ifdef _NPC_MAGICCARD +#define LSSPROTO_MAGICCARD_ACTION_SEND 133 +#define LSSPROTO_MAGICCARD_DAMAGE_SEND 134 +#endif + + +#ifdef _FAMILYBADGE_ +#define LSSPROTO_CHAREFFECT_SEND 146 +#endif + + +#ifdef _ASSESS_ABILITY +#define LSSPROTO_ASSESS_ABILITY_RECV 135 +#define LSSPROTO_ASSESS_ABILITY_SEND 136 +#endif + +#ifdef _SECONDARY_WINDOW_DATA_ +#define LSSPROTO_SECONDARY_WINDOW_SEND 137 +#endif + +#ifdef _TRUNTABLE_ +#define LSSPROTO_TRUNTABLE_SEND 138 +#endif + + +#ifdef _ONLINE_SHOP +#define LSSPROTO_VIP_SHOP_RECV 140 +#define LSSPROTO_VIP_SHOP_SEND 141 +#define LSSPROTO_VIP_SHOP_BUY_RECV 143 +#define LSSPROTO_VIP_SHOP_AMPOINT_BUY_RECV 145 +#endif + + +#ifdef _CHARSIGNDAY_ +#define LSSPROTO_SIGNDAY_RECV 141 +#endif + +#ifdef _RED_MEMOY_ +#define LSSPROTO_REDMEMOY_RECV 147 +#define LSSPROTO_REDMEMOY_SEND 148 +#endif + +#define LSSPROTO_DENGON_SEND 200 +#define LSSPROTO_SAMENU_SEND 201 +#define LSSPROTO_SAMENU_RECV 202 +#define LSSPROTO_UPSHOP_RECV 203 //̳ + + +#define LSSPROTO_SHOPOK_SEND 209 +#define LSSPROTO_SHOPOK_RECV 208 + +#ifdef _FAMILYBADGE_ +#define LSSPROTO_FAMILYBADGE_RECV 210 +#define LSSPROTO_FAMILYBADGE_SEND 211 +#endif +#ifdef _NEW_TITLE +#define LSSPROTO_CHARTITLE_RECV 212 +#define LSSPROTO_CHARTITLE_SEND 213 +#endif + +#ifdef _VISUAL_BEATITUDE +#define LSSPROTO_VB_RECV 218 +#define LSSPROTO_VB_SEND 219 +#endif + +#ifdef _RIDEQUERY_ +#define LSSPROTO_RIDEQUERY_RECV 220 +#endif + +void lssproto_W_recv(int fd,int x,int y,char* direction); +void lssproto_UpShopData_send(int fd,char *data,char * md5,int id); +void lssproto_ShopOK_send(int fd); +void lssproto_W2_recv(int fd,int x,int y,char* direction); +void lssproto_XYD_send(int fd,int x,int y,int dir); +void lssproto_EV_recv(int fd,int event,int seqno,int x,int y,int dir); +void lssproto_EV_send(int fd,int seqno,int result); +void lssproto_EN_recv(int fd,int x,int y); +void lssproto_DU_recv(int fd,int x,int y); +void lssproto_EN_send(int fd,int result,int field); +void lssproto_EO_recv(int fd,int dummy); +void lssproto_BU_recv(int fd,int dummy); +void lssproto_JB_recv(int fd,int x,int y); +void lssproto_LB_recv(int fd,int x,int y); +void lssproto_RS_send(int fd,char* data); +void lssproto_RD_send(int fd,char* data); +void lssproto_B_recv(int fd,char* command); +void lssproto_B_send(int fd,char* command); +void lssproto_SKD_recv(int fd,int dir,int index); +void lssproto_ID_recv(int fd,int x,int y,int haveitemindex,int toindex); +void lssproto_PI_recv(int fd,int x,int y,int dir); +void lssproto_DI_recv(int fd,int x,int y,int itemindex); +void lssproto_DG_recv(int fd,int x,int y,int amount); +void lssproto_DP_recv(int fd,int x,int y,int petindex); +void lssproto_I_send(int fd,char* data); +void lssproto_MI_recv(int fd,int fromindex,int toindex); +void lssproto_SI_send(int fd,int fromindex,int toindex); +void lssproto_MSG_recv(int fd,int index,char* message,int color); +void lssproto_MSG_send(int fd,int aindex,char* text,int color); +void lssproto_PMSG_recv(int fd,int index,int petindex,int itemindex,char* message,int color); +void lssproto_PME_send(int fd,int objindex,int graphicsno,int x,int y,int dir,int flg,int no,char* cdata); +void lssproto_AB_recv(int fd); +void lssproto_AB_send(int fd,char* data); +void lssproto_ABI_send(int fd,int num,char* data); +void lssproto_DAB_recv(int fd,int index); +void lssproto_AAB_recv(int fd,int x,int y); +void lssproto_L_recv(int fd,int dir); +void lssproto_TK_recv(int fd,int x,int y,char* message,int color,int area); +void lssproto_TK_send(int fd,int index,char* message,int color); +void lssproto_MC_send(int fd,int fl,int x1,int y1,int x2,int y2,int tilesum,int objsum,int eventsum,char* data); +void lssproto_M_recv(int fd,int fl,int x1,int y1,int x2,int y2); +void lssproto_M_send(int fd,int fl,int x1,int y1,int x2,int y2,char* data); +void lssproto_C_recv(int fd,int index); +void lssproto_C_send(int fd,char* data); +void lssproto_CA_send(int fd,char* data); +void lssproto_CD_send(int fd,char* data); +void lssproto_R_send(int fd,char* data); +void lssproto_S_recv(int fd,char* category); +void lssproto_S_send(int fd,char* data); +void lssproto_D_send(int fd,int category,int dx,int dy,char* data); +void lssproto_FS_recv(int fd,int flg); +void lssproto_FS_send(int fd,int flg); +void lssproto_HL_recv(int fd,int flg); +void lssproto_HL_send(int fd,int flg); +void lssproto_PR_recv(int fd,int x,int y,int request); +void lssproto_PR_send(int fd,int request,int result); +void lssproto_KS_recv(int fd,int petarray); +void lssproto_KS_send(int fd,int petarray,int result); + +#ifdef _STANDBYPET +void lssproto_SPET_recv(int fd,int standbypet); +void lssproto_SPET_send(int fd,int standbypet,int result); +#endif + +void lssproto_AC_recv(int fd,int x,int y,int actionno); +void lssproto_MU_recv(int fd,int x,int y,int array,int toindex); +void lssproto_PS_recv(int fd,int havepetindex,int havepetskill,int toindex,char* data); +void lssproto_SPET_send(int fd, int standbypet, int result); +void lssproto_PS_send(int fd,int result,int havepetindex,int havepetskill,int toindex); +void lssproto_ST_recv(int fd,int titleindex); +void lssproto_DT_recv(int fd,int titleindex); +void lssproto_FT_recv(int fd,char* data); +void lssproto_SKUP_send(int fd,int point); +void lssproto_SKUP_recv(int fd,int skillid); +void lssproto_KN_recv(int fd,int havepetindex,char* data); +void lssproto_WN_send(int fd,int windowtype,int buttontype,int seqno,int objindex,char* data); +void lssproto_WN_recv(int fd,int x,int y,int seqno,int objindex,int select,char* data); +void lssproto_EF_send(int fd,int effect,int level,char* option); +void lssproto_SE_send(int fd,int x,int y,int senumber,int sw); +void lssproto_SP_recv(int fd,int x,int y,int dir); +void lssproto_ClientLogin_recv(int fd,char* cdkey,char* passwd, char* mac, int servid ,char *Newip); +void lssproto_ClientLogin_send(int fd,char* result); +void lssproto_CreateNewChar_recv(int fd,int dataplacenum,char* charname,int imgno,int faceimgno,int vital,int str,int tgh,int dex,int earth,int water,int fire,int wind,int hometown); + +#define lssproto_CreateNewChar_send(fd,result,data) _lssproto_CreateNewChar_send(fd,result,data,__FILE__, __LINE__) +void _lssproto_CreateNewChar_send(int fd,char* result,char* data,char *file ,int line); +void lssproto_CharDelete_recv(int fd,char* charname,char * a); +void lssproto_NewCharDelete_recv(int fd,char* charname, char *passwd); +void lssproto_CharDelete_send(int fd,char* result,char* data); +void lssproto_CharLogin_recv(int fd,char* charname); +void lssproto_CharLogin_send(int fd,char* result,char* data); + +#ifdef _PKSEVER_VER +void lssproto_CharList_recv( int fd, int star); +#else +void lssproto_CharList_recv(int fd); +#endif + +void lssproto_CharList_send(int fd,char* result,char* data); +void lssproto_CharLogout_recv(int fd, int flg); +void lssproto_CharLogout_send(int fd,char* result,char* data); +void lssproto_ProcGet_recv(int fd); +void lssproto_ProcGet_send(int fd,char* data); +void lssproto_PlayerNumGet_recv(int fd); +void lssproto_PlayerNumGet_send(int fd,int logincount,int player); +void lssproto_Echo_recv(int fd,char* test); +void lssproto_Echo_send(int fd,char* test); +void lssproto_Shutdown_recv(int fd,char* passwd,int min); + +void lssproto_TD_send(int fd, char* message); +void lssproto_TD_recv(int fd, char* message); + +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +void lssproto_CHATROOM_recv(int fd , char *data) ; +void lssproto_CHATROOM_send(int fd , char* message ) ; +#endif + +#ifdef _NEWREQUESTPROTOCOL // (ɿ) Syu ADD ProtocolҪϸ +void lssproto_RESIST_recv(int fd ) ; +void lssproto_RESIST_send(int fd , char* message ) ; +#endif +#ifdef _OUTOFBATTLESKILL // (ɿ) Syu ADD սʱProtocol +void lssproto_BATTLESKILL_recv(int fd, int iNum) ; +void lssproto_BATTLESKILL_send(int fd , char* message ) ; +#endif + +void lssproto_CHAREFFECT_send ( int fd , char* message ); +void lssproto_NU_send(int fd, int nu); + +void lssproto_FM_send(int fd, char* message); +void lssproto_FM_recv(int fd, char* message); + +void lssproto_WO_send(int fd,int effect); +void lssproto_PETST_recv( int fd, int nPet, int sPet); +void lssproto_BM_recv(int fd, int iindex); + +#ifdef _MIND_ICON +void lssproto_MA_recv(int fd, int x, int y, int nMind); +#endif + +#ifdef _ITEM_CRACKER +void lssproto_IC_send(int fd, int x, int y); +#endif + +#ifdef _ITEM_CRACKER +void lssproto_NC_send(int fd,int flg); +#endif + +#ifdef _TEAM_KICKPARTY +void lssproto_KTEAM_recv( int fd, int si); +#endif + +#ifdef _PETS_SELECTCON +void lssproto_PETS_send(int fd,int petarray,int result); +//#define LSSPROTO_PETST_SEND 107 +#endif + +#ifdef _STREET_VENDOR +void lssproto_STREET_VENDOR_recv(int fd,char *message); +void lssproto_STREET_VENDOR_send(int fd,char *message); +#endif + +#ifdef _RIGHTCLICK +void lssproto_RCLICK_recv(int fd, int type, char* data); +void lssproto_RCLICK_send(int fd, int type, char* data); +#endif + +#ifdef _JOBDAILY +void lssproto_JOBDAILY_recv(int fd,char *data); +void lssproto_JOBDAILY_send(int fd,char *data); +#endif + +#ifdef _TEACHER_SYSTEM +void lssproto_TEACHER_SYSTEM_recv(int fd,char *data); +void lssproto_TEACHER_SYSTEM_send(int fd,char *data); +#endif + +#ifdef _ADD_STATUS_2 +void lssproto_S2_recv(int fd,char *data); +void lssproto_S2_send(int fd,char *data); +#endif + +#ifdef _PET_ITEM +void lssproto_PETITEM_recv( int fd,int x,int y,int petindex,int fromindex,int toindex ); +#endif + +#ifdef _ASSESS_ABILITY +void lssproto_ASSESS_ABILITY_recv(int fd); +void lssproto_ASSESS_ABILITY_send(int fd, char *data); +#endif + + +#ifdef _ONLINE_SHOP +void lssproto_VIP_SHOP_recv(int fd, int type, int page); +void lssproto_VIP_SHOP_send(int fd, int num,int BJ,int type, int shoppage, int page, char *data); +void lssproto_VIP_SHOP_buy_recv(int fd, int type, int page, int id, int num); +#endif +void lssproto_DENGON_send(int fd, char *data, int color, int num); + +void lssproto_SaMenu_recv(int fd, int index); +void lssproto_SAMENU_send(int fd, int index, char* data); + +#ifdef _FAMILYBADGE_ +void lssproto_FamilyBadge_recv(int fd); +void lssproto_FamilyBadge_send(int fd, char *data); +#endif +#ifdef _NEW_TITLE +void lssproto_CharTitle_send(int fd,char* data);// +#endif +#endif + +#ifdef _VISUAL_BEATITUDE +void lssproto_VisualBeatitude_send(int fd,char* data); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_util.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_util.h new file mode 100644 index 0000000..c06730c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/lssproto_util.h @@ -0,0 +1,110 @@ +#ifndef _LSSPROTOUTIL_H_ +#define _LSSPROTOUTIL_H_ +#include +#include +#ifndef WIN32 +#include +#include +#endif +//#define lssproto__ENCRYPT +#define lssproto__NODEBUG +struct lssproto_ { + int (*write_func)(int,char*,int) ; /* write function */ + size_t workbufsize; /* size of work area */ + char *work,*arraywork,*escapework,*val_str,*ret_work; /* work areas which have same size */ + char *cryptwork,*jencodecopy,*jencodeout,*compresswork; /* these work has bigger size (3times)*/ + char** token_list; /* token list */ + unsigned long message_id; /*= 1, */ /* for generating message IDs */ +}; +#ifdef _LSSPROTOUTIL_C_ +struct lssproto_ lssproto = { + NULL, + 0, + NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL, + NULL, + 1, +}; +char **lssproto_stringwrapper; +char lssproto_readlogfilename[1024]; +char lssproto_writelogfilename[1024]; +#else +extern char **lssproto_stringwrapper; +extern struct lssproto_ lssproto; +extern char lssproto_readlogfilename[1024]; +extern char lssproto_writelogfilename[1024]; +#endif + +char* lssproto_escapeString( char*a ); +char* lssproto_descapeString( char*a ); +void lssproto_splitString( char *src ); +void lssproto_strcpysafe( char *dest, char *src, int len ); +void lssproto_strcatsafe( char *dest , char *src , int maxlen ); +char*lssproto_mkstr_int( int i ); +char*lssproto_mkstr_u_int( unsigned int i ); +char*lssproto_mkstr_long( long l ); +char*lssproto_mkstr_u_long( unsigned long l ); +char*lssproto_mkstr_short( short s ); +char*lssproto_mkstr_u_short( short s ); +char*lssproto_mkstr_char( char c ); +char*lssproto_mkstr_u_char( char c); +char*lssproto_mkstr_string( char*a ); +char*lssproto_mkstr_float( float f ); +char*lssproto_mkstr_double( double d ); +char*lssproto_mkstr_int_array( int size , int *array ); +char*lssproto_mkstr_u_int_array( int size , int *array ); +char*lssproto_mkstr_short_array( int size , short *array ); +char*lssproto_mkstr_u_short_array(int size , short *array ); +char *lssproto_mkstr_char_array( int size , char *array ); +char *lssproto_mkstr_u_char_array( int size , unsigned char *array ); +char *lssproto_mkstr_float_array( int size , float *array ); +char *lssproto_mkstr_double_array( int size , double *array ); +int lssproto_demkstr_int( char*a ); +unsigned int lssproto_demkstr_u_int( char*a ); +long lssproto_demkstr_long( char*a ); +unsigned long lssproto_demkstr_u_long(char*a ); +short lssproto_demkstr_short( char*a ); +unsigned short lssproto_demkstr_u_short( char*a ); +char lssproto_demkstr_char( char*a ); +unsigned char lssproto_demkstr_u_char( char*a ); +float lssproto_demkstr_float( char*a ); +double lssproto_demkstr_double(char*a ); +char* lssproto_demkstr_string( char*a); +int *lssproto_demkstr_int_array( char**tk ,int *buf ,int start , int size ); +int *lssproto_demkstr_u_int_array( char **tk , int *buf , int start , int size ); +unsigned int *lssproto_demkstr_long_array( + char **tk , unsigned int *buf , int start , int size ); +unsigned long *lssproto_demkstr_u_long_array( + char **tk , unsigned long *buf , int start , int size ); +short *lssproto_demkstr_short_array( char **tk , short *buf , int start , int size ); +unsigned short*lssproto_demkstr_u_short_array( + char **tk , unsigned short *buf , int start , int size ); +char *lssproto_demkstr_char_array( char **tk , char *buf , int start , int size ); +unsigned char *lssproto_demkstr_u_char_array( + char **tk , unsigned char*buf , int start , int size ); +float *lssproto_demkstr_float_array( char **tk , float *buf , int start , int size ); +double *lssproto_demkstr_u_double_array( char **tk , double *buf , int start , int size ); +char *lssproto_wrapStringAddr( char *copy , int maxcopylen , char*src ); + +void lssproto_GetMessageInfo( int *id , char *funcname , int len,char **tk ); +int lssproto_ClientRead(void); +void lssproto_consumeLine(char *buf , int ofs ); +void lssproto_copyLine( char*src , char *out , int maxoutlen ); +void lssproto_Send( int fd , char *msg ); +int lssproto_AllocateCommonWork(int bufsiz); +unsigned int lssproto_GetNewMessageID(void); +void lssproto_CreateHeader(char*out, char *fname ); +void lssproto_CreateHeaderID( char *out,unsigned long msgid , char *fname ); +int lssproto_default_write_wrap( int fd , char *buf , int size ); +void lssproto_bzero( char *b , int siz ); +void lssproto_bcopy(char*s , char *d , int siz ); +char *lssproto_Ltoa( long v ); +char *lssproto_Ultoa( unsigned long v ); +void lssproto_DebugSend( int fd , char *msg ); +/* Modified by ringo to fasten int type transfer */ +char *lssproto_cnv10to62( int a, char *out, int outlen ); +int lssproto_a62toi( char *a ); +extern int JENCODE_KEY; +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic.h new file mode 100644 index 0000000..860fbf6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic.h @@ -0,0 +1,71 @@ +#ifndef __MAGIC_H__ +#define __MAGIC_H__ + +/* */ +int MAGIC_Use( int charaindex, int haveitemindex, int toindex); +#ifdef _MAGIC_FEATHERS +int MAGIC_Feathers( int charaindex, int toindex, int marray, int mp ); +#endif + +int MAGIC_Recovery( int charaindex, int toindex,int marray, int mp ); +int MAGIC_OtherRecovery( int charaindex, int toindex, int marray, int mp ); +int MAGIC_FieldAttChange( int charaindex, int toindex, int marray, int mp ); +int MAGIC_StatusChange( int charaindex, int toindex, int marray, int mp ); +#ifdef _MAGIC_DEEPPOISON +int MAGIC_StatusChange2( int charaindex, int toindex, int marray, int mp ); +#endif +int MAGIC_StatusRecovery( int charaindex, int toindex, int marray, int mp ); +int MAGIC_MagicDef( int charaindex, int toindex, int marray, int mp ); +int MAGIC_Ressurect( int charaindex, int toindex, int marray, int mp ); +int MAGIC_AttReverse( int charaindex, int toindex, int marray, int mp ); +int MAGIC_ResAndDef( int charaindex, int toindex, int marray, int mp ); +#ifdef _OTHER_MAGICSTAUTS +int MAGIC_MagicStatusChange( int charaindex, int toindex, int marray, int mp ); +#endif +#ifdef _ATTACK_MAGIC +int MAGIC_AttMagic( int charaindex , int toindex , int marray , int mp ); +#endif +#ifdef _ITEM_METAMO +int MAGIC_Metamo( int charaindex, int toindex,int marray, int mp ); +#endif + +#ifdef _ITEM_ATTSKILLMAGIC +int MAGIC_AttSkill( int charaindex, int toindex,int marray, int mp ); +#endif +#ifdef _MAGIC_WEAKEN// vincent : +int MAGIC_Weaken( int charaindex, int toindex, int marray, int mp ); +#endif +#ifdef _MAGIC_BARRIER// vincent :ħ +int MAGIC_Barrier( int charaindex, int toindex, int marray, int mp ); +#endif +#ifdef _MAGIC_NOCAST// vincent :Ĭ +int MAGIC_Nocast( int charaindex, int toindex, int marray, int mp ); +#endif +#ifdef _MAGIC_TOCALL +int MAGIC_ToCallDragon( int charaindex, int toindex,int marray, int mp ); +#endif + +//---------------------------------------------------------------------- +// ʧ ة įë߯ +// +int MAGIC_GetArrayNo( + int charaindex, // ƽҷ̼͵ + int haveitemindex // Ȼʧ ة +); +// +//---------------------------------------------------------------------- +//------------------------------------------------------------------- +// +// ë +// +int MAGIC_DirectUse( + int charaindex, // ƽҷ¼̼͵ + int marray, // ̼͵ + int toindex, // + int itemnum +); +// +//------------------------------------------------------------------- + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_base.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_base.h new file mode 100644 index 0000000..a8d4f36 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_base.h @@ -0,0 +1,142 @@ +#ifndef __MAGIC_BASE_H__ +#define __MAGIC_BASE_H__ + +#include "util.h" + +typedef enum +{ + MAGIC_FIELD_ALL, /* ͻƥ */ + MAGIC_FIELD_BATTLE, /* */ + MAGIC_FIELD_MAP, /* ɧѨ */ + +}MAGIC_FIELDTYPE; + +typedef enum +{ + MAGIC_TARGET_MYSELF, /* м */ + MAGIC_TARGET_OTHER, /* ְ ֳ) */ + MAGIC_TARGET_ALLMYSIDE, /* */ + MAGIC_TARGET_ALLOTHERSIDE, /* 촡 */ + MAGIC_TARGET_ALL, /* 廯 */ + MAGIC_TARGET_NONE, /* ּ ئУ ֧׻ */ + MAGIC_TARGET_OTHERWITHOUTMYSELF,/* ְ ֳئ) */ + MAGIC_TARGET_WITHOUTMYSELFANDPET, /* ʸ½ */ + MAGIC_TARGET_WHOLEOTHERSIDE,/* */ + +#ifdef _ATTACK_MAGIC + + MAGIC_TARGET_SINGLE, // Եзijһ + MAGIC_TARGET_ONE_ROW, // Եзijһ + MAGIC_TARGET_ALL_ROWS, // Եз + +#endif +}MAGIC_TARGETTYPE; + +typedef enum +{ + MAGIC_ID, /* į */ + MAGIC_FIELD, /* */ + MAGIC_TARGET, /* */ + MAGIC_TARGET_DEADFLG, /* Ϸַָޱֳ¾ */ +#ifdef _ATTACK_MAGIC + MAGIC_IDX , +#endif + MAGIC_DATAINTNUM, +}MAGIC_DATAINT; + +typedef enum +{ + MAGIC_NAME, /* */ + MAGIC_COMMENT, /* 춪*/ + MAGIC_FUNCNAME, /* */ + MAGIC_OPTION, /* */ + MAGIC_DATACHARNUM, +}MAGIC_DATACHAR; + +typedef struct tagMagic +{ + int data[MAGIC_DATAINTNUM]; + STRING64 string[MAGIC_DATACHARNUM]; + +}Magic; + +#ifdef _ATTACK_MAGIC + +typedef struct tagAttMagic +{ + unsigned int uiSpriteNum;// Spr_x.binı + unsigned int uiAttackType;// ķʽˣ( ) , ( ) , ( ͬʱ ) , ȫ( ) , ȫ( ͬʱ ) + unsigned int uiSliceTime;// ʱʱ + unsigned int uiShowType; // ʾλ÷ʽ롢ָ + int siSx; // ʾλ - X + int siSy; // ʾλ - Y + unsigned int uiShowBehindChar; // ʾǰ· + unsigned int uiShakeScreen; // Ƿ𶯻 + unsigned int uiShakeFrom; // 𶯻ʼʱ( ) + unsigned int uiShakeTo; // 𶯻Ľʱ( _ + unsigned int uiPrevMagicNum; // ǰ( 0XFFFFFFFFFF ʾǰ ) + int siPrevMagicSx; // ǰʾλ - X + int siPrevMagicSy; // ǰʾλ - Y + int siPrevMagicOnChar; // ǰʾǰ· + unsigned int uiPostMagicNum; // ( 0XFFFFFFFF ʾ ) + int siPostMagicSx; // ʾλ - X + int siPostMagicSy; // ʾλ - Y + int siPostMagicOnChar; // ʾǰ· + int siField[3][5]; // +}AttMagic; + +#endif + +#ifdef _MAGIC_TOCALL + +typedef struct tagToCallMagic +{ + unsigned int uiSpriteNum;// Spr_x.binı + unsigned int uiAttackType;// ķʽˣ( ) , ( ) , ( ͬʱ ) , ȫ( ) , ȫ( ͬʱ ) + unsigned int uiSliceTime;// ʱʱ + unsigned int uiShowType; // ʾλ÷ʽ롢ָ + int siSx; // ʾλ - X + int siSy; // ʾλ - Y + unsigned int uiShowBehindChar; // ʾǰ· + unsigned int uiShakeScreen; // Ƿ𶯻 + unsigned int uiShakeFrom; // 𶯻ʼʱ( ) + unsigned int uiShakeTo; // 𶯻Ľʱ( _ + unsigned int uiPrevMagicNum; // ǰ( 0XFFFFFFFFFF ʾǰ ) + int siPrevMagicSx; // ǰʾλ - X + int siPrevMagicSy; // ǰʾλ - Y + int siPrevMagicOnChar; // ǰʾǰ· + unsigned int uiPostMagicNum; // ( 0XFFFFFFFF ʾ ) + int siPostMagicSx; // ʾλ - X + int siPostMagicSy; // ʾλ - Y + int siPostMagicOnChar; // ʾǰ· + int isPostDisappear; // һ㹥ʱǷʧ + int ToCallMagicNo; // ٻı +}ToCallMagic; + +#endif + +typedef int (*MAGIC_CALLFUNC)( int, int, int, int ); + +INLINE BOOL MAGIC_CHECKINDEX( int index ); +INLINE int MAGIC_getInt( int index, MAGIC_DATAINT element); +INLINE int MAGIC_setInt( int index, MAGIC_DATAINT element, int data); +INLINE char* MAGIC_getChar( int index, MAGIC_DATACHAR element); +INLINE BOOL MAGIC_setChar( int index ,MAGIC_DATACHAR element, char* new ); +int MAGIC_getMagicNum( void); +BOOL MAGIC_initMagic( char *filename); +BOOL MAGIC_reinitMagic( void ); + +#ifdef _ATTACK_MAGIC + +BOOL ATTMAGIC_initMagic( char *filename ); +BOOL ATTMAGIC_reinitMagic( void ); + +#endif + +int MAGIC_getMagicArray( int magicid); +MAGIC_CALLFUNC MAGIC_getMagicFuncPointer(char* name); +// Nuke +1 08/23 : For checking the validity of magic target +int MAGIC_isTargetValid( int magicid, int toindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_field.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_field.h new file mode 100644 index 0000000..414195f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/magic_field.h @@ -0,0 +1,10 @@ +#ifndef __MAGIC_FIELD_H__ +#define __MAGIC_FIELD_H__ + +/* ūƥ */ + +int MAGIC_Recovery_Field( int charaindex, int magicindex); +int MAGIC_OtherRecovery_Field( int charaindex, int toindex, int magicindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_deal.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_deal.h new file mode 100644 index 0000000..8405012 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_deal.h @@ -0,0 +1,13 @@ +#ifndef __MAP_DEAL_H__ +#define __MAP_DEAL_H__ +BOOL MAP_walkAbleFromPoint( int ff, int fx, int fy, BOOL isfly ); +BOOL MAP_walkAble( int index,int ff, int fx, int fy); +void MAP_preovered( int index ); +void MAP_postovered( int index ); +BOOL MAP_sendArroundCharNeedFD( int fd,int charaindex ); +BOOL MAP_sendArroundChar(int charaindex); +#ifdef _MO_LNS_NLGSUOXU +int QuBiao (int MapId); +#endif +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_util.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_util.h new file mode 100644 index 0000000..77e4b7a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_util.h @@ -0,0 +1,7 @@ +#ifndef __MAP_UTIL_H__ +#define __MAP_UTIL_H__ + +BOOL MAP_getMapDataFromCharIndex( int index , int* map ); +BOOL MAP_getMapDataFromFXY( int f , int x , int y, int* map ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_warppoint.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_warppoint.h new file mode 100644 index 0000000..5bea5f6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/map_warppoint.h @@ -0,0 +1,24 @@ +#ifndef __MAPWARPPOINT_H__ +#define __MAPWARPPOINT_H__ + +#include "common.h" +#include "util.h" + +int MAPPOINT_InitMapWarpPoint( void); +void MAPPOINT_resetMapWarpPoint( int flg); +int MAPPOINT_loadMapWarpPoint( void); + +BOOL MAPPOINT_CHECKINDEX( int ps); +int MAPPOINT_getMPointEVType( int ps); + +int MAPPOINT_creatMapWarpObj( int pointindex, char *buf, int objtype); +int MAPPOINT_setMapWarpGoal( int ps, char *buf); +int MAPPOINT_setMapWarpFrom( int ps, char *buf); +int MAPPOINT_getMapWarpGoal( int ps, int ofl, int ox, int oy, int *fl, int *x, int *y); + +void MAPPOINT_MapWarpHandle( int charaindex, int ps, int ofl, int ox, int oy ); +#ifdef _MO_LNS_MAPSUOXU +int DelMapPoint( int ps); +int SetMapPoint( char* buf); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/mclient.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mclient.h new file mode 100644 index 0000000..553de42 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mclient.h @@ -0,0 +1,51 @@ +#ifndef __MCLIENT_H__ +#define __MCLIENT_H__ + +#define MSPERSIONALKEY "20020729" + + +#define MPROTO_QUE_SEND 1001 +#define MPROTO_QUE_RECV 1002 + +#define MPROTO_NOTALK_RECV 1004 +#define MPROTO_GMTALK_SEND 1005 +#define MPROTO_GMTALK_RECV 1006 +#define MPROTO_HELLO_SEND 1007 +#define MPROTO_HELLO_RECV 1008 +#define MPROTO_WAEIKICK_SEND 1009 +#define MPROTO_WAEIKICK_RECV 1010 + +#define MPROTO_JAIL_RECV 1012 +#define MPROTO_MESSAGE_RECV 1014 + +#define MPROTO_TYPE_SEND 1016 + +#ifdef _GSERVER_RUNTIME //GSERVERִжʱMSERVER +#define MPROTO_RECALL_GSERVER_RUNTIME 1026 +#endif + +int mproto_ClientDispatchMessage(int fd,char* data); + +void mproto_Que_Recv(int fd,char* uid,int userfdid,char* ans); +void mproto_Que_Send( int fd, int uid, int index, char* question); + +void mproto_NoTalk_Recv(int fd,char* uid,int userfdid,int nTime); +void mproto_GMTalk_Recv(int fd,char* uid,int ntime,char* data); +void mproto_WaeiKick_Recv(int fd,char* uid,int userfdid); +void mproto_Jail_Recv(int fd,char* uid,int userfdid); + +void mproto_Message_Recv(int fd,char* uid,int userfdid,char* ans); + +int connectmServer(char* hostname,unsigned short port); +void mproto_Type_Send( int fd, int playernum, int itemuse); + +#ifdef _RECAL_ASK_PLAYER // WON Ҫ +void mproto_RECALL_ASK_PLAYER_Recv(int fd, char *uid, int userfdid, int GmCliId, char *id, int char_num, int date, int backup_flag); +void mproto_RECALL_BACKUP_PLAYER_Recv(int fd, char *uid, int userfdid, int GmCliId, char *id, int char_num, int date, char *char_data, int backup_flag); +#endif + +#ifdef _GSERVER_RUNTIME +void gserver_runtime(); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/md5.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/md5.h new file mode 100644 index 0000000..f595537 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/md5.h @@ -0,0 +1 @@ +void MD5Digest(char *pszInput, unsigned long nInputSize, char *pszOutPut); diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/msignal.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/msignal.h new file mode 100644 index 0000000..452994b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/msignal.h @@ -0,0 +1,8 @@ +#ifndef __SIGNAL_H__ +#define __SIGNAL_H__ + +void signalset( void ); +void shutdownProgram( void ); +void sigshutdown( int number ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/ablua.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/ablua.h new file mode 100644 index 0000000..d5e85a6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/ablua.h @@ -0,0 +1,8 @@ +#ifndef __ABLUA_H__ +#define __ABLUA_H__ + +void LoadAllbluesLUA(char *path); +void ReLoadAllbluesLUA(); +void NewLoadAllbluesLUA(char *filename); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/base.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/base.h new file mode 100644 index 0000000..5c84239 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/base.h @@ -0,0 +1,51 @@ +#ifndef __CHARBASE_H__ +#define __CHARBASE_H__ +#include "char_base.h" +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + +typedef struct tagCharBase +{ + char field[128]; + int element; +}CharBase; + +const int getCharBaseValue(lua_State *L, int narg, CharBase *charbase, int num); + +LUALIB_API int luaopen_Char (lua_State *L); +LUALIB_API int luaopen_NPC (lua_State *L); +LUALIB_API int luaopen_Lssproto (lua_State *L); +LUALIB_API int luaopen_Battle (lua_State *L); +LUALIB_API int luaopen_Object (lua_State *L); + +#ifdef _ALLBLUES_LUA_1_1 +LUALIB_API int luaopen_Map (lua_State *L); +LUALIB_API int luaopen_Other (lua_State *L); +LUALIB_API int luaopen_Config (lua_State *L); +#endif +#ifdef _ALLBLUES_LUA_1_2 +LUALIB_API int luaopen_Item (lua_State *L); +LUALIB_API int luaopen_Magic (lua_State *L); +#endif +#ifdef _ALLBLUES_LUA_1_2 +LUALIB_API int luaopen_Offline (lua_State *L); +#endif +#ifdef _ALLBLUES_LUA_1_4 +LUALIB_API int luaopen_Enemytemp (lua_State *L); +LUALIB_API int luaopen_Sasql (lua_State *L); +#endif + +LUALIB_API int luaopen_Net (lua_State *L); + +LUALIB_API int luaopen_Saacproto (lua_State *L); + +#ifdef _ALLBLUES_LUA_1_8 +LUALIB_API int luaopen_Family (lua_State *L); +LUALIB_API int luaopen_PetSkill (lua_State *L); +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +LUALIB_API int luaopen_ProfessionSkill (lua_State *L); +#endif +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/function.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/function.h new file mode 100644 index 0000000..2e2c98e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/function.h @@ -0,0 +1,63 @@ + +#ifndef __MYLUA_FUNCTION_H__ +#define __MYLUA_FUNCTION_H__ + +BOOL RunCharTalkedEvent(int meindex, int toindex, char *messageeraseescape, int color, int channel); +BOOL RunCharLoopEvent(int meindex); +BOOL RunCharOverlapEvent( int meindex, int toindex); +BOOL RunCharBattleOverEvent( int meindex, int toindex, int iswin); +BOOL RunCharWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#ifdef _ALLBLUES_LUA_1_2 +BOOL RunItemUseEvent( int itemindex, int charaindex, int toindex, int haveitemindex ); +BOOL RunItemDieReLifeEvent( int toindex, int itemindex, int haveitemindex ); +BOOL RunItemDetachEvent( int charaindex, int itemindex ); +BOOL RunItemAttachEvent( int charaindex, int itemindex ); +BOOL RunItemPickupEvent( int charaindex, int itemindex ); +BOOL RunItemPostOverEvent( int itemindex, int charaindex ); +BOOL RunItemPreOverEvent( int itemindex, int charaindex ); +BOOL RunItemDropEvent( int charaindex, int itemindex ); +BOOL RunUseChatMagic( int charaindex, char *data, lua_State *lua); +#endif +#ifdef _PETSKILL_SHOP_LUA +BOOL FreePetSkillShop( int talkerindex, int petindex, int oldSkillID, int newSkillID); +#endif +void ABNPC_Lua_NEWSHOP_Recv( int charaindex); +#ifdef _PETSKILL_SHOP_LUA +BOOL OffLineCommand( int battleindex, int charindex, int side); +#endif +#ifdef _ALLBLUES_LUA_1_4 +BOOL BattleFinish( int battleindex, int charaindex); +BOOL BattleEscape( int battleindex, int charaindex); +BOOL RunCharLogOutEvent( int charaindex); +#endif +#ifdef _ALLBLUES_LUA_1_5 +BOOL FreePartyJoin( int charaindex, int toindex ); +BOOL FreeVsPlayer( int charaindex, int toindex ); +BOOL FreeCharLogin( int charaindex ); +BOOL FreeCharCreate( int charaindex ); +BOOL NetLoopFunction( void ); +#endif +#ifdef _ALLBLUES_LUA_1_6 +BOOL FamilyRideFunction( int meindex, int petindex, int petid ); +BOOL CharTalkFunction( int charaindex, char *message, int color ); +#endif +#ifdef _ALLBLUES_LUA_1_7 +BOOL CharVsEnemyFunction( int charaindex ); +#endif +#ifdef _ALLBLUES_LUA_1_8 +BOOL CaptureOkFunction( int attackindex, int defindex ); +BOOL CaptureCheckFunction( int attackindex, int defindex ); +#endif +#ifdef _ALLBLUES_LUA_1_9 +BOOL SetBattleEnmeyFunction(int meindex, int enemyindex, int id ); +BOOL BattleFinishFunction( int charaindex, int battletime, int battleturn, int battletype ); +void FreeCharExpSave( int charindex, int exp ); +BOOL BattleCommand( int charaindex, int battleindex ); +#endif +#endif + +#ifdef _RIDEQUERY_ +void FreeRideQuery( int charaindex); +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/mylua.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/mylua.h new file mode 100644 index 0000000..bb4e5d9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/mylua/mylua.h @@ -0,0 +1,28 @@ +#define __MYLUA__H__ +#ifdef __MYLUA__H__ + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" +int myluaload (char *filename); +int remyluaload (char *filename); +int closemyluaload(); +void CryptoAllbluesLUA(char *path, int flg, int id); +int dofile (lua_State *L, const char *name); + +#define docall(L,narg,clear) _docall(L,narg,clear,__func__) +int _docall(lua_State *L, int narg, int clear,char *name); +int getArrayInt(lua_State *L, int idx); +LUALIB_API void luaAB_openlibs (lua_State *L); + +typedef struct tagMYLua +{ + lua_State *lua; + char *luapath; + struct tagMYLua *next; +}MY_Lua; + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/net.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/net.h new file mode 100644 index 0000000..cb39f24 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/net.h @@ -0,0 +1,320 @@ +#ifndef __NET_H__ +#define __NET_H__ + +#include "common.h" +#include "autil.h" + +#include +#include +// Nuke +1 0902: For queuing control +#include + +#include + +#include "link.h" + + +#undef EXTERN +#ifdef __NET_C__ +#define EXTERN +#else +#define EXTERN extern +#endif + + +#define LSGENWORKINGBUFFER SLICE_SIZE + + +/* + * ̼ƻئУ ̼ƻ£ ̼ ƽҷԻ + * ʧ ( Ƥ ) , ʧ ( ʧ ) + * N NOT W WHILE , UL UNLOCK + */ +typedef enum +{ + NULLCONNECT, + NOTLOGIN, /* ̼ƻئ */ + LOGIN, /* ̼ */ + WHILELOGIN, /* ̼ƻ */ + WHILECREATE, /* Ȼ */ + WHILELOGOUTSAVE, /* ʧƤ */ + WHILECANNOTLOGIN, /* ̼ƥئݼʧ */ + WHILECHARDELETE, /* ƽҷ´ */ + WHILEDOWNLOADCHARLIST, /* ƽҷĸ */ + WHILECHANGEPASSWD, /* ɵ */ + + WHILELOSTCHARSAVE, /* ƥƽҷ±Ƥ */ + WHILELOSTCHARDELETE,/* ƥƽҷ */ + + WHILECLOSEALLSOCKETSSAVE, /* closeallsockets ƥƽҷ±Ƥ */ + WHILESAVEWAIT, /* ʧƤ󡼰 */ +}LoginType; + +/* ƻئУʧӡͷʧʧة */ +typedef enum +{ + NOTDETECTED, + AC, + CLI, +#ifdef _OTHER_SAAC_LINK + SQL, +#endif + ADM +}ConnectType; + + +/* ӡﻥƻӮ */ +#define CDKEYLEN 16 +#define PASSWDLEN 33 +/* ľ ʷص(ئ Char STRING64 ئԻ³*/ +#define CHARNAMELEN 32 + +#define CLITIMEOUT_SEC 120 /* ͷʧreadئգ + ƥةʧʧ */ + +#define NET_STRING_SUCCESSFULL "successful" +#define NET_STRING_FAILED "failed" + +// ׹ ݷ +#define RBSIZE (1024*64) +#define WBSIZE (1024*256) +// ʧӡ + +//#define AC_RBSIZE (65536*48) +//#define AC_RBSIZE (65536*32) +#define AC_RBSIZE (1024*1024*6) +//ttom modify because the second version had this +//#define AC_WBSIZE (65536*16) +extern int AC_WBSIZE; + + +EXTERN int epfd; +EXTERN int nfds; +EXTERN int bindedfd; +EXTERN int acfd; +EXTERN int svfd; +#ifdef _OTHER_SAAC_LINK +EXTERN int osfd; +#endif +EXTERN int ConnectLen; /*ƱӮ*/ +#define CONNECT_WINDOWBUFSIZE 7 + +/* */ +BOOL initConnect( int size ); +void endConnect( void ); +#define CONNECT_endOne( sockfd, lin) \ + _CONNECT_endOne( __FILE__, __LINE__, sockfd, lin) +BOOL _CONNECT_endOne( char *file, int fromline, int sockfd , int lin); +BOOL netloop_faster( void ); +int lsrpcClientWriteFunc( int fd , char* buf , int size ); +char* GetOneLine( int fd ); +BOOL initConnectOne( int sockfd, struct sockaddr_in* sin ,int len ); + +#ifdef _MO_LNS_NLSUOXU +void SetTimerLua( void ); +BOOL DelTimer_net(int ID); +#endif + +/* CA , CD */ +void CAcheck( void ); +void CAflush( int charaindex ); +void CAsend( int fd ); +void CDcheck( void ); +void CDflush( int charaindex ); +void CDsend( int fd ); +BOOL CONNECT_appendCAbuf( int fd , char* data, int size ); +BOOL CONNECT_appendCDbuf( int fd , char* data, int size ); + +/* Serverstate */ +void SERVSTATE_decrementCloseallsocketnum(void); +int SERVSTATE_getCloseallsocketnum( void ); +int SERVSTATE_SetAcceptMore( int nvalue ); +int SERVSTATE_getShutdown(void); +void SERVSTATE_setShutdown(int a); +int SERVSTATE_getLimittime(void); +int SERVSTATE_getDsptime(void); +void SERVSTATE_setDsptime(int a); +void SERVSTATE_setLimittime(int a); + + +/* þ */ +void outputNetProcLog( int fd, int mode); +void chardatasavecheck( void ); +void closeAllConnectionandSaveData( void ); +BOOL SetShutdown( BOOL nvalue ); +int GetShutdown( void ); + +/* ƻ */ +int getfdFromCdkey( char* cd ); +int getfdFromCharaIndex( int charaindex ); +int getcdkeyFromCharaIndex( int charaindex , char *out, int outlen ); +int getCharindexFromFdid( int fdid ); +int getFdidFromCharaIndex( int charind ); +int getfdFromFdid( int fdid ); +int getfdFromCdkeyWithLogin( char* cd ); + + +/* */ +INLINE int CONNECT_checkfd( int fd ); +BOOL CONNECT_isCLI( int fd ); +BOOL CONNECT_isAC( int fd ); +BOOL CONNECT_isUnderLogin( int fd ); +BOOL CONNECT_isWhileLogout( int fd ); +BOOL CONNECT_isWhileLogin( int fd ); +BOOL CONNECT_isNOTLOGIN( int fd ); +BOOL CONNECT_isLOGIN( int fd ); + +int CONNECT_getUse( int fd ); +int CONNECT_getUse_debug( int fd, int i ); + +void CONNECT_setCharaindex( int fd, int a ); +int CONNECT_getCharaindex( int fd ); +void CONNECT_getCdkey( int fd , char *out, int outlen ); +void CONNECT_setCdkey( int fd , char *in); +#ifdef _NEWCLISETSERVID +void CONNECT_setServid( int fd, int a ); +int CONNECT_getServid( int fd ); +#endif +#ifdef _NEWCLISETMAC +void CONNECT_getMAC( int fd , char *out, int outlen ); +void CONNECT_setMAC( int fd , char *in); +#endif +void CONNECT_getPasswd( int fd , char *out, int outlen ); +void CONNECT_setPasswd( int fd, char *in ); +void CONNECT_getCharname( int fd , char *out, int outlen ); +void CONNECT_setCharname( int fd, char *in ); +int CONNECT_getFdid( int fd ); +int CONNECT_getCtype( int fd ); +void CONNECT_setCtype( int fd , int a ); +void CONNECT_setDuelcharaindex( int fd, int i , int a ); +int CONNECT_getDuelcharaindex( int fd, int i ); +void CONNECT_setBattlecharaindex( int fd, int i , int a ); +int CONNECT_getBattlecharaindex( int fd, int i ); +void CONNECT_setJoinpartycharaindex( int fd, int i , int a); +int CONNECT_getJoinpartycharaindex( int fd, int i ); +void CONNECT_setTradecardcharaindex( int fd, int i , int a ); +int CONNECT_getTradecardcharaindex( int fd, int i ); +/* MTѨͷ */ +#define CONNECT_endOne_debug(a) CONNECT_endOne( (a) , __LINE__ ) + +/* (ľɱ) */ +void CONNECT_setCDKEY( int sockfd, char *cd ); +void CONNECT_getCDKEY( int sockfd , char *out, int outlen ); +void CONNECT_setState( int fd, int s ); +int CONNECT_getState( int fd ); +void CONNECT_checkStatecount( int a ); + +BOOL CONNECT_acfdInitRB( int fd ); +BOOL CONNECT_acfdInitWB( int fd ); + +#ifdef _BATTLE_TIMESPEED +//void setDefBTime( int fd, unsigned int times); +//unsigned int getDefBTime( int fd); +BOOL CheckDefBTime( int charaindex, int fd, unsigned int lowTime, unsigned int battletime, unsigned int addTime); +#endif + +#ifdef _TYPE_TOXICATION +void setToxication( int fd, int flg); +int getToxication( int fd); +#endif +void sigusr1(int i); +void sigusr2(int i); // Arminius 6.26 signal + +unsigned long CONNECT_get_userip(int fd); +void CONNECT_set_pass(int fd,BOOL b_ps); +BOOL CONNECT_get_pass(int fd); +void CONNECT_set_state_trans(int fd,int a); +int CONNECT_get_state_trans(int fd); +//ttom end + +// CoolFish: +9 2001/4/18 +void CONNECT_setCloseRequest( int fd, int count); +void CONNECT_set_first_warp(int fd, BOOL b_ps); +BOOL CONNECT_get_first_warp(int fd); +int isDie(int fd); +void setDie(int fd); + +// Arminius 6/22 encounter +int CONNECT_get_CEP(int fd); +void CONNECT_set_CEP(int fd, int cep); + +// Arminius 7.12 login announce +int CONNECT_get_announced(int fd); +void CONNECT_set_announced(int fd, int a); + +// shan trade(DoubleCheck) begin +int CONNECT_get_confirm(int fd); +void CONNECT_set_confirm(int fd, BOOL b); +// end + +void CONNECT_setTradecharaindex( int fd, int i , int a); + +void CONNECT_setLastrecvtime( int fd, struct timeval *a ); +void CONNECT_getLastrecvtime( int fd, struct timeval *a ); +void CONNECT_setLastrecvtime_D( int fd, struct timeval *a ); +void CONNECT_getLastrecvtime_D( int fd, struct timeval *a ); +void CONNECT_SetBattleRecvTime( int fd, struct timeval *a ); +void CONNECT_GetBattleRecvTime( int fd, struct timeval *a ); +void CONNECT_setTradeTmp(int fd, char* a); +void CONNECT_getTradeTmp(int fd, char *trademsg, int trademsglen); +int checkNu(int fd); + +// Arminius 7.2 Ra's amulet +void setNoenemy(int fd); +void clearNoenemy(int fd); +int getNoenemy(int fd); +void setEqNoenemy(int fd, int level); +void clearEqNoenemy(int fd); +int getEqNoenemy(int fd); + +#ifdef _Item_MoonAct +void setEqRandenemy(int fd, int level); +void clearEqRandenemy(int fd); +int getEqRandenemy(int fd); +#endif + +#ifdef _CHIKULA_STONE +void setChiStone(int fd, int nums); +int getChiStone(int fd); +#endif + +// Arminius 7.31 cursed stone +void setStayEncount(int fd); +void clearStayEncount(int fd); +int getStayEncount(int fd); +void CONNECT_setBDTime( int fd, int nums); +int CONNECT_getBDTime( int fd); + +// Arminius debug +void CONNECT_setUse( int fd , int a); + +#ifdef _ITEM_PILEFORTRADE +void CONNECT_setTradeList( int fd, int num); +int CONNECT_getTradeList(int fd); +#endif + +#define QUEUE_LENGTH1 10 +#define QUEUE_LENGTH2 10 + +BOOL MSBUF_CHECKbuflen( int size, float defp); + +void SetTcpBuf( int fd, fd_set *fds); + +#ifdef _OTHER_SAAC_LINK +BOOL OtherSaacConnect( void ); +#endif + +#ifdef _EPOLL_ET_MODE +int doSocketAccept(); +// +void doSocketRecv(struct epoll_event ev); +// +void doSocketSend(struct epoll_event ev); +//void doSocketSend(); +BOOL CONNECT_checkthreadflag( int fd, int flag ); +int CONNECT_getversionpass( int fd ); +void Dispatch_read_buffer(int fdremember, int threadflag ); +void System_Loop(); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_Dengon.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_Dengon.h new file mode 100644 index 0000000..b8835a1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_Dengon.h @@ -0,0 +1,10 @@ +#ifndef __NPC_DENGON_H__ +#define __NPC_DENGON_H__ +BOOL NPC_DengonInit( int meindex ); +//void NPC_DengonSpecialTalked( int index, int talker, char *msg, int color ); +void NPC_DengonLooked( int meindex, int lookedindex ); +void NPC_DengonWindowTalked( int index, int talker, + int seqno, int select, char *data); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_action.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_action.h new file mode 100644 index 0000000..f19d6df --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_action.h @@ -0,0 +1,12 @@ +#ifndef __NPC_ACTION_H__ +#define __NPC_ACTION_H__ + +void NPC_ActionTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_ActionInit( int meindex ); +void NPC_ActionWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_airplane.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_airplane.h new file mode 100644 index 0000000..6e02872 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_airplane.h @@ -0,0 +1,12 @@ +#ifndef __NPC_AIRPLANE_H__ +#define __NPC_AIRPLANE_H__ + +BOOL NPC_AirInit( int meindex ); +void NPC_AirLoop( int meindex ); +void NPC_AirTalked( int meindex , int talkerindex , char *szMes , + int color ); +BOOL NPC_AirCheckAllowItem( int meindex, int charaindex, BOOL pickupmode); +BOOL NPC_AirCheckJoinParty( int meindex, int charaindex, BOOL msgflg); + +#endif +/*__NPC_AIRPLANE_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_alldoman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_alldoman.h new file mode 100644 index 0000000..bc879a1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_alldoman.h @@ -0,0 +1,10 @@ +#ifndef __NPC_ALLDOMAN_H__ +#define __NPC_ALLDOMAN_H__ + +BOOL NPC_AlldomanInit( int meindex ); +void NPC_AlldomanTalked( int meindex , int talker , char *msg ,int color ); +void NPC_AlldomanWindowTalked(int meindex, int talkerindex, int seqno, int select,char *data); +void NPC_AlldomanWriteStele( char *token ) ; +void NPC_Alldoman_S_WriteStele( char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ) ; +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_autopk.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_autopk.h new file mode 100644 index 0000000..3707fd9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_autopk.h @@ -0,0 +1,19 @@ +#ifndef _AUTO_PK_H +#define _AUTO_PK_H + +void NPC_AutoPkTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_AutoPkInit( int meindex ); +void NPC_AutoPkWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_AutoPkLoop( void ); +void AutoPk_PKSystemTalk( char *token1, char *token2 ); +void AutoPk_PKSystemInfo(); +void AutoPk_PKTimeSet( int pktime ); +int AutoPk_PKTimeGet( void ); +void AutoPk_AwardSet( int petid, char *pet, int itemid, char *item ); +void AutoPk_ChampionShipSet( int charaindex, int winnum, int win ); +void AutoPk_SetHistoryStr( void ); +void AutoPk_SetAwardStr( char *token ); +BOOL AutoPk_GetAwardStr( void ); +void AutoPk_GetChampionShip( void ); +BOOL getBAward(); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bankman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bankman.h new file mode 100644 index 0000000..8cd40c7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bankman.h @@ -0,0 +1,12 @@ +#ifndef __NPC_BANKMAN_H__ +#define __NPC_BANKMAN_H__ + +void NPC_BankmanTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_BankmanInit( int meindex ); +void NPC_BankmanLooked( int meindex, int lookedindex ); +void NPC_BankmanWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bodylan.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bodylan.h new file mode 100644 index 0000000..57f2e30 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bodylan.h @@ -0,0 +1,16 @@ +#ifndef __NPC_BODYLAN_H__ +#define __NPC_BODYLAN_H__ + +void NPC_BodyLanTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_BodyLanInit( int meindex ); +void NPC_BodyLanWatch( int meindex , int lookedindex); +void NPC_BodyLanWindowTalked( + int meindex, + int talkerindex, + int seqno, + int select, + char *data +); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bus.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bus.h new file mode 100644 index 0000000..98d5d6a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_bus.h @@ -0,0 +1,12 @@ +#ifndef __NPC_BUS_H__ +#define __NPC_BUS_H__ + +BOOL NPC_BusInit( int meindex ); +void NPC_BusLoop( int meindex ); +void NPC_BusTalked( int meindex , int talkerindex , char *szMes , + int color ); +BOOL NPC_BusCheckAllowItem( int meindex, int charaindex, BOOL pickupmode); +BOOL NPC_BusCheckJoinParty( int meindex, int charaindex, BOOL msgflg); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_charm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_charm.h new file mode 100644 index 0000000..73785a7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_charm.h @@ -0,0 +1,11 @@ +#ifndef __NPC_CHARM_H__ +#define __NPC_CHARM_H__ + +void NPC_CharmTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_CharmInit( int meindex ); +void NPC_CharmWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_CharmLooked( int meindex , int lookedindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_checkman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_checkman.h new file mode 100644 index 0000000..77fbf31 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_checkman.h @@ -0,0 +1,11 @@ +#ifndef __NPC_CHECKMAN_H__ +#define __NPC_CHECKMAN_H__ + +void NPC_CheckManTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_CheckManInit( int meindex ); +void NPC_CheckManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_CheckManLooked( int meindex , int lookedindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_door.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_door.h new file mode 100644 index 0000000..003c71a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_door.h @@ -0,0 +1,31 @@ +#ifndef __NPC_DOOR_H__ +#define __NPC_DOOR_H__ + +BOOL NPC_DoorInit(int meindex ); +void NPC_DoorTalked( int meindex , int talkerindex , char *msg , int color ); +void NPC_DoorPreAttacked(int meindex , int attacker , float *dm); +void NPC_DoorPostOver( int meindex , int movedindex ); +void NPC_DoorOff( int meindex , int movedindex ); +void NPC_DoorWatch( int meindex, int moveindex, CHAR_ACTION act, + int x, int y, int dir, int* opt, int optlen ); +int NPC_DoorSearchByName( char *name ); +int NPC_DoorSearchByPosition( int fl , int x, int y ); +void NPC_DoorLooked( int meindex , int lookedindex ); +BOOL NPC_DoorRefreshOverFlg( int meind ); + + +/* ְNPCճ۽ľãNPC年л npc_stepswitch.cëǷ */ +int NPC_DoorSetPasswd( int meindex, char *pas ); +int NPC_DoorGetPasswd( int meindex, char *out , int len ); +void NPC_DoorFlip(int meindex , int doindex); +void NPC_DoorClose(int meindex , int doindex); +void NPC_DoorOpen(int meindex , int doindex ); +void NPC_DoorAddSwitchCounter( int meindex , int i , int talker ); +void NPC_DoorSetSwitchCounter( int meindex, int i , int doindex ); + +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_doorman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_doorman.h new file mode 100644 index 0000000..52e32de --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_doorman.h @@ -0,0 +1,9 @@ +#ifndef __NPC_DOORMAN_H__ +#define __NPC_DOORMAN_H__ + +BOOL NPC_DoormanInit( int meindex ); +void NPC_DoormanTalked( int meindex , int talkerindex , char *msg , + int color ); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_duelranking.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_duelranking.h new file mode 100644 index 0000000..74dbe35 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_duelranking.h @@ -0,0 +1,11 @@ +#ifndef __NPC_DUELRANKING_H__ +#define __NPC_DUELRANKING_H__ + +BOOL NPC_DuelrankingInit( int meindex ); +void NPC_DuelrankingLooked( int meindex, int lookedindex ); +void NPC_DuelrankingWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_Duelranking_PrintRanking( char *data, int count_start, int fdid, int msgid2); +void NPC_Duelranking_CallMyRanking( int count, int msgid, int msgid2); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_eventaction.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_eventaction.h new file mode 100644 index 0000000..068f048 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_eventaction.h @@ -0,0 +1,193 @@ +#ifndef _PRO_NPCFIX_H +#define _PRO_NPCFIX_H +//ANDY_Edit +BOOL ActionNpc_CheckMenuFree( int meindex, int toindex, char *npcarg, int nums); +BOOL ActionNpc_CheckFree( int meindex, int toindex, char *npcarg); +BOOL Action_RunDoEventAction( int meindex, int toindex, char *buf1); +BOOL ActionNpc_WarpPoint(int meindex,int talker,char *npcarg); +BOOL Action_PartyCheck( int meindex, int talker); +BOOL NPC_ActionAddGold( int talker, int Golds); +BOOL NPC_ActionDelGold( int talker,char *buf); +#ifdef _MOMENTUM_NPC +BOOL NPC_ActionMomentum( int talker,char *buf); +#endif +#ifdef _DEL_FAME +BOOL NPC_ActionDelFame( int talker,char *buf); +#endif +#ifdef _DP_NPC +BOOL NPC_ActionDP( int talker,char *buf); +#endif +#ifdef _SQL_BUY_FUNC +BOOL NPC_ActionOnlineBuy( int talker ); +#endif +#ifdef _ONLINE_COST +BOOL NPC_ActionOnlineCost( int talker ); +#endif +#ifdef _VIP_SHOP +BOOL NPC_ActionDelVipPoint( int talker,char *buf); +#endif +#ifdef _TRANS_7_NPC +BOOL NPC_ActionTrans7( int talker, char *buf); +#endif + +#ifdef _VIP_SHOP +BOOL NPC_ActionVipItem( int talker, char *buf); +BOOL NPC_ActionVipPet( int talker, char *buf); +#endif + +#ifdef _NEW_VIP_SHOP +BOOL NPC_ActionNewVipItem( int talker, char *buf); +BOOL NPC_ActionNewVipPet( int talker, char *buf); +#endif + + +// WON ADD +BOOL NPC_ActionAddGold2( int talker,char *buf); +BOOL NPC_ActionDelPet( int toindex,char *buf); +#ifdef _NPC_NewDelPet +BOOL NPC_ActionNewDelPet( int talker,char *msg); +#endif +BOOL NPC_ActionAddPet( int talker, char *buf); +BOOL NPC_ActionDelItem( int talker,char *buf); +BOOL NPC_ActionAddItem( int talker, char *buf); +BOOL NPC_ActionSetEend( int talkerindex, char * buf); +BOOL NPC_ActionSetNow( int toindex, char * buf); +BOOL NPC_ActionClearEvent( int toindex, char * buf); + +BOOL NPC_ActionCheckTrans(int meindex,int talker,int trans,int flg); +#ifdef _NPC_CHECKTIME +BOOL NPC_ActionTimeCheck(int meindex, int talker, char *buf, int date,int flg); +#endif +#ifdef _MISSION_TRAIN +BOOL NPC_ActionMissionTrainCheck(int meindex,int talker,int mt,int flg); +#endif +#ifdef _FAME_CHECK_NPC +BOOL NPC_ActionFameCheck(int meindex,int talker,int fame,int flg); +#endif + +#ifdef _VIP_SHOP +BOOL NPC_ActionVipPointCheck(int meindex,int talker,int point,int flg); +#endif +#ifdef _VIP_RIDE +BOOL NPC_ActionVipCheck(int meindex,int talker,int vip,int flg); +#endif +#ifdef _MOMENTUM_NPC +BOOL NPC_ActionMomentumCheck(int meindex,int talker,int Momentum,int flg); +#endif +#ifdef _DP_NPC +BOOL NPC_ActionDPCheck(int meindex,int talker,int DP,int flg); +#endif +BOOL NPC_ActionLevelCheck(int meindex,int talker,int level,int flg); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +BOOL NPC_ActionClassCheck( int meindex,int talker,int p_class,int flg); + +BOOL NPC_ActionSkillCheck( int meindex,int talker,int skillId,int flg); +BOOL NPC_ActionSkillNumCheck( int meindex,int talker,int sknum,int flg); + +BOOL NPC_ActionSkillPointAndSkillCheck( int meindex,int talker,int sknum,int flg); + + +BOOL NPC_ActionCleanProfession( int toindex, char *buf); +BOOL NPC_ActionAddProfessionSkillPoint( int toindex, char *buf ); +#endif + +BOOL NPC_ActionGoldCheck(int meindex,int talker,int Golds,int flg); +BOOL NPC_ActionPartyCheck( int toindex, int nums, int flg); +BOOL NPC_ActionReItemCheck( int toindex, int nums, int flg); +BOOL NPC_ActionRePetCheck( int toindex, int nums, int flg); +BOOL ActionCheckMyPet( int meindex, int talker, int petLv, int flg, int petid); +BOOL NPC_ActionBigSmallLastCheck(int point1,int mypoint,int flg); + +BOOL NPC_ActionItemCheck(int meindex,int talker,int itemNo, int flg); +BOOL NPC_ActioneEquitCheck(int meindex,int talker,int itemNo, int flg); + +BOOL NPC_ActionFreeIfCheck(int meindex,int talker, char* buf, char *opt, int kosuu,int flg, int temp); + +BOOL NPC_ActionBigSmallCheck(int meindex,int talker,char* buf); +BOOL NPC_ActionPassCheck( int meindex, int talker, char *buf); +BOOL NPC_ActionWarpManReduce(int meindex,int talker,char *buf); +#ifdef _NPC_ActionFreeCmp +BOOL NPC_ActionWarpManReduce2(int meindex,int talker,char *buf); +#endif +#ifdef _NPCCHANGE_PLAYERIMG //andy +BOOL NPC_ActionChangePlayerBBI( int meindex, int charindex, char *Img); +BOOL NPC_CheckPlayerBBI( int meindex, int charindex, int BBI, int flg); +#endif + +BOOL showString( int meindex, char *showstr,int flg); +BOOL NPC_getTimeXYPoint( int meindex, int Mode); +BOOL NPC_getTimeData( int meindex, char *npcarg, int *born, int *dead, int loopspeed); +void NPC_TimeDefineDo( int meindex, int born, int dead, int typeMode); +BOOL NPC_CheckTimeDefine( char *timetype); + +void GetRand_WarpPoint( char *buf, int *fl, int *x, int *y ); +#ifdef _EMENY_CHANCEMAN +int NPC_EmenyChanceCheck( int meindex, int charaindex, char *arg); +int NPC_DischargePartyForSex( int meindex, int charaindex, int fl, int x, int y, int fsex); +#endif + +BOOL NPC_ActionDuelRankCheck(int meindex,int talker,int rank,int flg); +BOOL NPC_ActionDuelPointCheck(int meindex,int talker,int rank,int flg); + +#ifdef _TREASURE_BOX +BOOL NPC_ActionTreasureTypeCheck( int meindex, int level, int type, int flg); +#endif +BOOL NPC_ActionTreasureRandItemGet(int meidex,int talker,int rand_j,char *buf); +void NPC_ActionLevelAndTransUp( int meindex, int charindex, int level, + int skillpoint, int exp, int ridepet); +#ifdef _ITEM_PILENUMS +BOOL NPC_ActionDoPileDelItem( int toindex, int itemID, int num); +BOOL NPC_DelItem( int toindex, int ti, int num); +#endif +void NPC_ActionDoPileClearItem( int toindex, int itemID); + + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +int PROFESSION_RESTORE_POINT( int charaindex ); +#endif + + +#ifdef _NPC_ADDWARPMAN1 +BOOL NPC_ActionPartyCountCheck( int toindex, int nums, int flg); +BOOL NPC_ActionManCountCheck( int toindex, int nums, int flg);// +BOOL NPC_ActionWomanCountCheck( int toindex, int nums, int flg);//Ů +#endif + +#ifdef _ANGEL_SUMMON +BOOL NPC_ActionMissionAngelCheck(int meindex,int talker,int mission,int flg,int checkitem); +BOOL NPC_ActionMissionHeroCheck(int meindex,int talker,int mission,int flg,int checkitem); +BOOL NPC_HeroCompleteCountCheck(int meindex,int talker,int count,int flg); +#endif + + +#ifdef _PLAYER_DIY_MAP +BOOL NPC_ActionDiyMapCheck(int meindex,int talker,int diymap,int flg); +BOOL NPC_ActionPlayerDiyMap( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapBuy( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapLetter( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapSend( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapAddNum( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapAddExp( int talker, char *buf); +BOOL NPC_ActionPlayerDiyMapAddDay( int talker, char *buf); +#endif + +#ifdef _LOTTERY_SYSTEM +BOOL NPC_ActionLotteryChange( int talker, char *buf); +BOOL NPC_ActionLotteryBuy( int talker, char *buf); +BOOL NPC_ActionLotteryAddTime( int talker, char *buf); +BOOL NPC_ActionLotteryShow( int talker); +BOOL NPC_ActionLotteryPlayerShow( int talker); +#endif +#ifdef _SHOW_ITEM_NAME +BOOL NPC_ActionShowItemName( int talker ,char *buf); +#endif +#ifdef _NPC_INT_SET +BOOL NPC_ActionIntSet( int talker,char *buf); +BOOL NPC_ActionIntChange( int talker,char *buf); +BOOL NPC_ActionIntShow( int talker,char *buf); +#endif +#ifdef _GLORY_POINT +BOOL NPC_ActionGloryCheck(int meindex,int talker,int Golds,int flg); +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_exchangeman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_exchangeman.h new file mode 100644 index 0000000..81153d9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_exchangeman.h @@ -0,0 +1,67 @@ +#ifndef __NPC_EXCHANGEMAN_H__ +#define __NPC_EXCHANGEMAN_H__ +BOOL NPC_EventAddShowItem(int meindex,int talker,char *buf); +BOOL NPC_EventAddEgg(int meindex, int talker, char *buff2,int mode); +BOOL NPC_RandItemGet(int meidex,int talker,int rand_j,char *buf); +BOOL NPC_EventAddItem(int meindex,int talker,char *buf); +#ifdef _TRANS_7_NPC +BOOL NPC_EventTRANS(int meindex, int talker, char *buff2,int mode); +#endif +void NPC_ExChangeMan_selectWindow( int meindex, int talker,int num); +BOOL NPC_TypeCheck(int meindex,int talker,char *szMes); +int NPC_ExChangeManEventCheck( int meindex, int talker, char *buff1); +BOOL NPC_EventItemCheck(int meindex,int talker,int itemNo,int flg); +BOOL NPC_EventLevelCheck(int meindex,int talker,int level,int flg); +// Arminius 8.14 move to .h (for pet talk) +//BOOL NPC_EventBigSmallCheck(int meindex,int talker,char* buf); +BOOL NPC_EventFreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg); +BOOL NPC_EventBigSmallLastCheck(int point1,int mypoint,int flg); +BOOL NPC_ENDEventNoCheck(int meindex,int talker,int shiftbit,int flg); +BOOL NPC_NOWEventNoCheck(int meindex,int talker,int shiftbit,int flg); +BOOL NPC_TiemCheck(int meindex,int talker,int time,int flg); +BOOL NPC_EventAddPet(int meindex, int talker, char *buff2,int mode); +BOOL NPC_RandItemGet(int meindex, int talker,int rand_j,char *buf); + +BOOL NPC_PetLvCheckType2(int petindex,int meindex,int talker,char *buf,int mode); +BOOL NPC_PetLvCheck(int meindex,int talker,char *buf,int mode); +void NPC_RequestMain(int meindex,int talker,char *buf); +void NPC_AcceptMain(int meindex,int talker ,char*buf); +void NPC_MsgDisp(int meindex,int talker,int num); +BOOL NPC_EventAdd(int meindex,int talker,int mode); +BOOL NPC_AcceptDel(int meindex,int talker,int mode); +BOOL NPC_SavePointCheck(int meindex,int talker,int shiftbit,int flg); + +BOOL NPC_EventReduce(int meindex,int talker,char *buf); +BOOL NPC_EventDelItem(int meindex,int talker,char *buf,int breakflg); +BOOL NPC_EventDelItemEVDEL(int meindex,int talker,char *buf,char *nbuf,int breakflg); +int NPC_EventFile(int meindex,int talker,char *buf); +BOOL NPC_EventDelPet(int meindex,int talker, int petsel); +void NPC_PetSkillMakeStr(int meindex,int toindex,int select); +void NPC_CleanMain(int meindex,int talker,char *buf); +void NPC_EventPetSkill( int meindex, int talker, char *data); +BOOL NPC_ItemFullCheck(int meindex,int talker,char *buf,int mode,int evcnt); +void NPC_CharmStatus(int meindex,int talker); +BOOL NPC_ImageCheck(int meindex,int talker,int kosuu,int flg); +int NPC_EventGetCost(int meindex,int talker,char *arg); + +BOOL NPC_EventWarpNpc(int meindex,char *buf); + +void NPC_ExChangeManTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_ExChangeManInit( int meindex ); +void NPC_ExChangeManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + + + +BOOL NPC_EventCheckFlg( int talker, int shiftbit); +BOOL NPC_NowEventCheckFlg( int talker, int shiftbit); + +// Arminius 8.14 move from .c (for pet talk) +BOOL NPC_EventBigSmallCheck(int meindex,int talker,char* buf); + +#endif + + + /*__NPC_EXCHANGEMAN_H__*/ + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_familyman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_familyman.h new file mode 100644 index 0000000..57e08d4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_familyman.h @@ -0,0 +1,13 @@ +#ifndef __NPC_FAMILYMAN_H__ +#define __NPC_FAMILYMAN_H__ + +void NPC_FamilymanTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_FamilymanInit( int meindex ); +void NPC_FamilymanLooked( int meindex, int lookedindex ); +void NPC_FamilymanWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + +/*__NPC_FAMILYMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmdengon.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmdengon.h new file mode 100644 index 0000000..858f170 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmdengon.h @@ -0,0 +1,10 @@ +#ifndef __NPC_FMDENGON_H__ +#define __NPC_FMDENGON_H__ + +BOOL NPC_FmDengonInit( int meindex ); +void NPC_FmDengonLooked( int meindex, int lookedindex ); +void NPC_FmDengonWindowTalked( int index, int talker, int seqno, int select, char *data); + +#endif + +/*__NPC_FMDENGON_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmhealer.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmhealer.h new file mode 100644 index 0000000..2c62fce --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmhealer.h @@ -0,0 +1,9 @@ +#ifndef __NPC_FMHEALER_H__ +#define __NPC_FMHEALER_H__ + +void NPC_FmHealerTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_FmHealerInit( int meindex ); + +#endif +/*__NPC_FMHEALER_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmletter.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmletter.h new file mode 100644 index 0000000..f60aef5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmletter.h @@ -0,0 +1,13 @@ +#ifndef __NPC_FMLETTER_H__ +#define __NPC_FMLETTER_H__ + +void NPC_FmLetterTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_FmLetterInit( int meindex ); +void NPC_FmLetterLooked( int meindex, int lookedindex ); +void NPC_FmLetterWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + +/*__NPC_FMLETTER_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkcallman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkcallman.h new file mode 100644 index 0000000..8702b1c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkcallman.h @@ -0,0 +1,10 @@ +#ifndef __NPC_FMPKCALLMAN_H__ +#define __NPC_FMPKCALLMAN_H__ + +void NPC_FMPKCallManTalked(int meindex, int talkerindex, char *msg, int color); +BOOL NPC_FMPKCallManInit(int meindex); +void NPC_FMPKCallManWindowTalked(int meindex, int talkerindex, int seqno, + int select, char *data); + +#endif +/*__NPC_FMPKCALLMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkman.h new file mode 100644 index 0000000..2053f02 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmpkman.h @@ -0,0 +1,10 @@ +#ifndef __NPC_FMPKMAN_H__ +#define __NPC_FMPKMAN_H__ + +void NPC_FMPKManTalked(int meindex, int talkerindex, char *msg, int color); +BOOL NPC_FMPKManInit(int meindex); +void NPC_FMPKManWindowTalked(int meindex, int talkerindex, int seqno, + int select, char *data); + +#endif +/*__NPC_FMPKMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmwarpman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmwarpman.h new file mode 100644 index 0000000..5b8e4ac --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_fmwarpman.h @@ -0,0 +1,12 @@ +#ifndef __NPC_FMWARPMAN_H__ +#define __NPC_FMWARPMAN_H__ + +void NPC_FMWarpManTalked(int meindex, int talkerindex, char *msg, int color); +BOOL NPC_FMWarpManInit(int meindex); +void NPC_FMWarpManWindowTalked(int meindex, int talkerindex, int seqno, + int select, char *data); +void NPC_FMWarpManLoop(int meindex); +void NPC_GetPKFMNum(int floor, int fmindex1, int fmindex2, int *num1, int *num2); + +#endif +/*__NPC_FMWARPMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_freepetskillshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_freepetskillshop.h new file mode 100644 index 0000000..73bc822 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_freepetskillshop.h @@ -0,0 +1,10 @@ +#ifndef __NPC_FREEPETSKILLSHOP_H__ +#define __NPC_FREEPETSKILLSHOP_H__ + +BOOL NPC_FreePetSkillShopInit( int meindex ); +void NPC_FreePetSkillShopTalked( int meindex , int talkerindex , char *msg , int color ); +void NPC_FreePetSkillShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +//void NPC_PetSkillShopLooked( int meindex , int lookedindex); +BOOL NPC_CHECKFREEPETSKILL( int toindex, int petindex, int skillID); +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblebank.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblebank.h new file mode 100644 index 0000000..017f2c1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblebank.h @@ -0,0 +1,9 @@ +#ifndef __NPC_GAMBLEBANK_H__ +#define __NPC_GAMBLEBANK_H__ +BOOL NPC_GambleBankInit( int meindex ); +void NPC_GambleBankLoop( int meindex); +void NPC_GambleBankTalked( int meindex , int talkerindex , char *msg , int color ); +void NPC_GambleBankWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblemaster.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblemaster.h new file mode 100644 index 0000000..9c28474 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gamblemaster.h @@ -0,0 +1,9 @@ +#ifndef NPC_Gamble_Master_ +#define NPC_Gamble_Master_ + +BOOL NPC_Gamble_MasterInit( int meindex ); +void NPC_Gamble_MasterLoop( int meindex ); +void NPC_Gamble_MasterWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_Gamble_MasterTalked( int meindex , int talkerindex , char *szMes , int color ); +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gambleroulette.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gambleroulette.h new file mode 100644 index 0000000..0dacc59 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_gambleroulette.h @@ -0,0 +1,9 @@ +#ifndef NPC_Gamble_Roulette_ +#define NPC_Gamble_Roulette_ + +BOOL NPC_Gamble_RouletteInit( int meindex ); +void NPC_Gamble_RouletteLoop( int meindex ); +void NPC_Gamble_RouletteWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_Gamble_RouletteTalked( int meindex , int talkerindex , char *szMes , int color ); +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_healer.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_healer.h new file mode 100644 index 0000000..bab4c9c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_healer.h @@ -0,0 +1,10 @@ +#ifndef __NPC_HEALER_H__ +#define __NPC_HEALER_H__ + +void NPC_HealerTalked( int meindex , int talkerindex , char *msg , + int color ); +void NPC_HealerAllHeal( int talker ); +BOOL NPC_HealerInit( int meindex ); + +#endif + /*__NPC_HEALER_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemchange.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemchange.h new file mode 100644 index 0000000..63ac849 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemchange.h @@ -0,0 +1,12 @@ +#ifndef _ITEM_CHANGE_ +#define _ITEM_CHANGE_ + +//#ifdef _CFREE_petskill +BOOL NPC_ItemchangeManInit( int meindex ); +void NPC_ItemchangeManTalked( int meindex, int talkerindex, char *msg, int color ); +void NPC_ItemchangeManWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data); +void NPC_ItemchangeManLoop( int meindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemshop.h new file mode 100644 index 0000000..f6d757b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_itemshop.h @@ -0,0 +1,12 @@ +#ifndef __NPC_ITEMSHOP_H__ +#define __NPC_ITEMSHOP_H__ + +void NPC_ItemShopTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_ItemShopInit( int meindex ); +void NPC_ItemShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_ItemShopLooked( int meindex , int lookedindex); + + +#endif + /*__NPC_ITEMSHOP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_janken.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_janken.h new file mode 100644 index 0000000..411abb8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_janken.h @@ -0,0 +1,10 @@ +#ifndef __NPC_JANKEN_H__ +#define __NPC_JANKEN_H__ + +void NPC_JankenTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_JankenInit( int meindex ); +void NPC_JankenWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + /*__NPC_JANKEN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua.h new file mode 100644 index 0000000..9150419 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua.h @@ -0,0 +1,547 @@ +#ifndef __NPC_LUA__ +#define __NPC_LUA__ + +#include "npc_lua_interface.h" +#include "../lua/lua.h" +#include "../lua/lauxlib.h" +#include +#include +#include +#include + +#define LUA_DATALINE0 0 +#define LUA_DATALINE1 2000 +#define LUA_DATALINE2 4000 +#define LUA_DATALINE3 6000 +#define LUA_DATALINE4 8000 +#define LUA_DATALINE5 10000 +#define LUA_DATALINE6 10100 +typedef struct __CREATEENEMY +{ + int EnemyId; + int BaseLevel; + int SkillType; +}CREATEENEMY,*PCREATEENEMY; + +typedef struct __SCRIPTREGLIB +{ + const char *LibName; // + luaL_reg *FuncRegList; //Ҫעĺ⺯б +}SCRIPTREGLIB,*PSCRIPTREGLIB; + +typedef struct __SCRIPTREGCLASS +{ + const char *ClassName; // + PSCRIPTREGLIB NewLib; //ʵ SCRIPTREGLIB + luaL_reg *FuncRegList; //Ҫעຯб +}SCRIPTREGCLASS,*PSCRIPTREGCLASS; + +typedef struct __SCRIPTREGARRAY +{ + const char *ArrayName; // + const char **SetMetaTable; //Ӧ + const char **SetFuncName; //Ӧĺ + PSCRIPTREGLIB FuncList; //ӦӦ SetMetaTable Ĵб +}SCRIPTREGARRAY,*PSCRIPTREGARRAY; + +typedef struct __ARRAY_NTINT +{ + size_t Size; + int Num[1]; +}ARRAY_NTINT,*PARRAY_NTINT; + +//NPC-NPCΨһ +int NPC_Lua_Create(const char *_DoFile, const char *_InitFuncName, char *_seek, BOOL _IsFly); + +//ɾNPC NPCΨһ +int NPC_Lua_Del(int _index); + +//ս +int NPC_Lua_CreateVsEnemy(lua_State *_NLL, int _CharaIndex, int _NpcIndex, const char *_DoFunc, PCREATEENEMY _CreateEnemy, int _ARLen, int _Flg); + +const char *NPC_Lua_SetErrorStr(const char *ErrStr); + +//עչýӿ +int NPC_Lua_RegCallEx(lua_State * _NLL, luaL_Reg *_RegList); +//עչӿ +int NPC_Lua_RegLibEx(lua_State * _NLL, PSCRIPTREGLIB _RegLib); +//עչӿ +int NPC_Lua_RegClassEx(lua_State * _NLL, PSCRIPTREGCLASS _RegClass); +//עչӿ +int NPC_Lua_RegArrayEx(lua_State * _NLL, PSCRIPTREGARRAY _RegArray); + +//չͽӿں +//NTInt +int NPC_Lua_NTInt_New(lua_State *_NLL); +int NPC_Lua_NTInt_Get(lua_State *_NLL); +int NPC_Lua_NTInt_Set(lua_State *_NLL); +int NPC_Lua_NTInt_Len(lua_State *_NLL); + +//ӿں +////////////////////////////////////////////////NL///////////////////////////////////////////////// +int NPC_Lua_NL_GetErrorStr(lua_State *_NLL); //شϢ +int NPC_Lua_NL_CreateNpc(lua_State *_NLL); //NPC +int NPC_Lua_NL_CreateSpecialNpc(lua_State *L); +extern int copyChar(lua_State *L); +extern int createPet(lua_State *L); +extern int setCharPet(lua_State *L); +extern int getCharPet(lua_State *L); +extern int ToAroundChar(lua_State *L); +extern int Attack(lua_State *L); +extern int Recovery(lua_State *L); +extern int CreateVsEnemy (lua_State *L); +extern int talkToAllServer(lua_State *L); +extern int dengon(lua_State *L); +extern int RandRandWalk(lua_State *L); + +int NPC_Lua_NL_DelNpc(lua_State *_NLL); //ɾNPC +int NPC_Lua_NL_Mod(lua_State *_NLL); // +int NPC_Lua_NL_GetStringFromIndexWithDelim(lua_State *_NLL); //ʹַַָָصָindexλõַ +//int NPC_Lua_NL_ANSI_PlayerLoop(lua_State *_NLL); //д +int NPC_Lua_NL_PetLoopGetNext(lua_State *_NLL); //дڳس дƶʱ +int NPC_Lua_NL_ItemLoopGetNext(lua_State *_NLL); //дڵߣص +int NPC_Lua_NL_PlayerLoopGetNext(lua_State *_NLL); //д +int NPC_Lua_NL_GetConfigLineType(lua_State *_NLL); //0ΪַΡ1ΪSHORTΡ2ΪINT͡3ΪDOUBLE͡ڸֶΣ-1. +int NPC_Lua_NL_GetConfigLineVal(lua_State *_NLL); //Ƿ[ַ]ҪתΪ֣tonumber()Ҳֶηnil +int NPC_Lua_NL_getGameservername(lua_State *_NLL); +BOOL NPC_Lua_CheckNpcEventFree(lua_State *_NLL); //Ƿij +int NPC_Lua_DoNpcEventAction(lua_State *_NLL); //ִNPCű +int NPC_Lua_NL_SetTimer(lua_State *_NLL); //趨һʱĺ趨ļʱڵá +int NPC_Lua_NL_DelTimer(lua_State *_NLL); //ɾһʱһʱɾͲٱڵã +int NPC_Lua_NL_RunSaFuncII(lua_State *_NLL); //һڶõ2INTĺ +int NPC_Lua_NL_RunSaFuncIII(lua_State *_NLL); //һڶõ3INTĺ(ITEM_USEʹõߺĻص +int NPC_Lua_NL_ANSI_PlayerLoop(lua_State *_NLL); //д +int NPC_Lua_NL_ANSI_PetLoop(lua_State *_NLL); //дڳ +int NPC_Lua_NL_ANSI_ItemLoop(lua_State *_NLL); //дڵߣ +int NPC_Lua_NL_ClsMk(lua_State *_NLL); +int NPC_Lua_NL_AddCheckNum(lua_State *_NLL); +int NPC_Lua_NL_Mkstring(lua_State *_NLL); +int NPC_Lua_NL_Mkint(lua_State *_NLL); +int NPC_Lua_NL_SendMesg(lua_State *_NLL); +int NPC_Lua_NL_WriteShopData(lua_State *_NLL); +////////////////////////////////////////////////NLG//////////////////////////////////////////////// +//ܽӿ +int NPC_Lua_NLG_UpItem(lua_State *_NLL); +int NPC_Lua_NLG_GiveItemOne(lua_State *_NLL); +int NPC_Lua_NLG_GivePetOne(lua_State *_NLL); +int NPC_Lua_NLG_DelItemByIndex(lua_State *_NLL); +int NPC_Lua_NLG_FindPet(lua_State *_NLL); //ҳλ +int NPC_Lua_NLG_GetMap(lua_State *_NLL); //õǰλõĽ +int NPC_Lua_NLG_PetUp(lua_State *_NLL); // +int NPC_Lua_NLG_AddSk(lua_State *_NLL); //ְҵ +int NPC_Lua_NLG_SetZy(lua_State *_NLL); //趨ְҵ +int NPC_Lua_Char_GetPlayerMaxNum(lua_State *_NLL); //ȡ +int NPC_Lua_NLG_GetXY(lua_State *_NLL); //ȡһͼ +int NPC_Lua_NLG_WalkJc(lua_State *_NLL); //ϰ +int NPC_Lua_NLG_KickPlayer(lua_State *_NLL); //Tָ +int NPC_Lua_NLG_HealOne(lua_State *_NLL); //ָһ ظHP MP +int NPC_Lua_NLG_HealAll(lua_State *_NLL); //ָһMP ظаHP +int NPC_Lua_NLG_LevelUpTo(lua_State *_NLL); //ĵȼ +int NPC_Lua_NLG_AddExp(lua_State *_NLL); //һ顣 +int NPC_Lua_NLG_UpPet(lua_State *_NLL); //¶ijڸ¡ͻˡݣijЩ̨Ա޸ĵ²ܰѸݷ͵ǰ̨ +int NPC_Lua_NLG_DelPetByPos(lua_State *_NLL); //ɾ ָλij +int NPC_Lua_NLG_DelPetByIndex(lua_State *_NLL); //ɾ ָţIDij +int NPC_Lua_NLG_GivePetByIndex(lua_State *_NLL); //һָֻŵijָ سλ +int NPC_Lua_NLG_GiveItemByIndex(lua_State *_NLL); //һindexָ صλ +int NPC_Lua_NLG_WarpToSpecificPoint(lua_State *_NLL); //ƶNPC ƶ +BOOL NPC_Lua_NLG_UpSkillupPoint(lua_State *_NLL); // +int NPC_Lua_NLG_StayEncount(lua_State *_NLL); //ԭ + +int NPC_Lua_NLG_CheckInFront(lua_State *_NLL); //ڼijǷijǰ +int NPC_Lua_NLG_CheckObj(lua_State *_NLL); //ijͼλǷж +int NPC_Lua_NLG_CharLook(lua_State *_NLL); //﷽(͸·) +int NPC_Lua_NLG_CreateBattle(lua_State *_NLL); //ս +int NPC_Lua_NLG_CreateVsEnemyAB (lua_State *L); +int NPC_Lua_NLG_InputCard(lua_State *_NLL); //һԻ⿨ +int NPC_Lua_NLG_CreateBattlePvP(lua_State *_NLL); + +int NPC_Lua_NLG_SearchWatchBattleRandIndex(lua_State *_NLL); + +int NPC_Lua_NLG_DelPet(lua_State *_NLL); //ɾָҳһ +int NPC_Lua_NLG_DelHaveIndexPet(lua_State *_NLL); +int NPC_Lua_NLG_DelItem(lua_State *_NLL); //ɾָҵһ +int NPC_Lua_NLG_DelItemByPos(lua_State *_NLL); //ɾָҵһ +int NPC_Lua_NLG_DischargeParty(lua_State *_NLL); //ɢ Ŷ + +int NPC_Lua_NLG_GivePet(lua_State *_NLL); //ָһ +int NPC_Lua_NLG_GiveOnePet(lua_State *_NLL); //ָһ +int NPC_Lua_NLG_GiveItem(lua_State *_NLL); //ָһ +int NPC_Lua_NLG_GiveOneItem(lua_State *_NLL); //ָһ +int NPC_Lua_NLG_GiveRandItem(lua_State *_NLL); +int NPC_Lua_Char_GetOnLinePlayer(lua_State *_NLL); //ȡǰ + +int NPC_Lua_NLG_ShowWindowTalked(lua_State *_NLL); //ָҿͻʾָݡ͵ĶԻ +int NPC_Lua_NLG_SetAction(lua_State *_NLL); //öĶ + +int NPC_Lua_NLG_TalkToCli(lua_State *_NLL); //ͨ˵Զȫ˵ +int NPC_Lua_NLG_TalkToFloor(lua_State *_NLL); //ijһָͼڵ˵ + +int NPC_Lua_NLG_UpChar(lua_State *_NLL); //NPCΧҷNPCݸ· +int NPC_Lua_NLG_UpStateBySecond(lua_State *_NLL); //ָҷ͵2״̬· +int NPC_Lua_NLG_UpStateByThird(lua_State *_NLL); //ָҷ͵3״̬· +int NPC_Lua_NLG_Update_Party(lua_State *_NLL); //ڵŶӳԱҵ״̬· + +int NPC_Lua_NLG_Warp(lua_State *_NLL); //һ +int NPC_Lua_NLG_WalkMove(lua_State *_NLL); //ƶһ +int NPC_Lua_NLG_WatchEntry(lua_State *_NLL); //ս +int NPC_Lua_NLG_HealerAllHeal(lua_State *_NLL); //Ѫ +int NPC_Lua_NLG_GetMaxPlayNum(lua_State *_NLL); //ȡ +int NPC_Lua_NLG_CheckPlayIndex(lua_State *_NLL); //Ƿ +int NPC_Lua_NLG_Save(lua_State *_NLL); +////add by mo +int NPC_Lua_NLG_SetExp(lua_State *_NLL); //÷鱶 +int NPC_Lua_NLG_GetExp(lua_State *_NLL); //ȡ鱶 +int NPC_Lua_NLG_SetPetTransRange(lua_State *_NLL); //óתΧ +int NPC_Lua_NLG_GetPetTransRange(lua_State *_NLL); //óתΧ +///////////////////////////////////////////////Char//////////////////////////////////////////////// +//ݵĽӿ +int NPC_Lua_Char_ClrEvtEnd(lua_State *_NLL); //־ +int NPC_Lua_Char_ClrEvtNow(lua_State *_NLL); //־ +int NPC_Lua_Char_ClrEvt(lua_State *_NLL); //־ +int NPC_Lua_Char_GetAllocPoint(lua_State *_NLL); //ȡCharIndexάɳ +int NPC_Lua_Char_GetDataFromEnemyBase(lua_State *_NLL); //ȡӦ ־ ijģݣenemybaseX.txt +int NPC_Lua_Char_GetPlayerIndex(lua_State *_NLL); // +int NPC_Lua_Char_FindItemIndex(lua_State *_NLL); //ָǷӵijΪָ +int NPC_Lua_Char_FindPetIndex(lua_State *_NLL); //ָǷӵгΪָ +int NPC_Lua_CHAR_CHECKINDEX(lua_State *_NLL); // +int NPC_Lua_Char_GetPetSkill(lua_State *_NLL); //ȡóָļܱ +int NPC_Lua_Char_GetPetSkillNo(lua_State *_NLL); //ȡChar +int NPC_Lua_Char_RidNo(lua_State *_NLL); //־ +int NPC_Lua_Char_GetEmptyItemBoxNum(lua_State *_NLL); //ָϵλ +int NPC_Lua_Char_GetEmptyPetBoxNum(lua_State *_NLL); //ָϳλ +int NPC_Lua_Char_GetPlayerItemNum(lua_State *_NLL); //ָΪijIDĵߵ +int NPC_Lua_Char_GetPlayerPetNum(lua_State *_NLL); //ָΪijIDij +int NPC_ABLua_char_getPlayerMaxNum(lua_State *_NLL); // +int NPC_ABLua_char_getBattleexp(lua_State *_NLL); //ս鱶 +int NPC_Lua_Char_SetPetSkill(lua_State *_NLL); //óָļܱ +int NPC_Lua_Char_SetPetSkillNo(lua_State *_NLL); +int NPC_Lua_Char_ComplianceParameter(lua_State *_NLL); //ݶ¼㲢WORKԣԴﵽЧĿġ +int NPC_Lua_Char_HcItemId(lua_State *_NLL); //ϳõϷƷ +int NPC_Lua_Char_DelHcItem(lua_State *_NLL); //ɾijλõƷ +int NPC_Lua_Char_GETFM(lua_State *_NLL); //ȡ ʽ +int NPC_Lua_Char_FindPetEnemyBaseId(lua_State *_NLL); //ָǷӵгEnemyBaseļĶӦID +int NPC_Lua_Char_ITEMID_NAME(lua_State *_NLL); //ָID +int NPC_Lua_Char_ITEMID_NAME2(lua_State *_NLL); //ָID˵ +int NPC_Lua_Char_ITEMID_LEVEL(lua_State *_NLL); //ָIDĵȼ +int NPC_Lua_Char_ITEMID_GOLD(lua_State *_NLL); //ָIDļ۸ +int NPC_Lua_Char_ITEMID_RANO(lua_State *_NLL); //ָIDͼ +int NPC_Lua_Char_CharRidNo(lua_State *_NLL); //ǷѾij֤ +int NPC_Lua_Char_GetPetOwner(lua_State *_NLL); //ó˵ +int NPC_Lua_Char_GetEnemyBaseIdFromEnemyId(lua_State *_NLL); //ͨenemy.txtõijenemybase.txt趨ijš +int NPC_Lua_Char_GetEnemyIdFromEnemyBaseId(lua_State *_NLL); //ͨenemybase.txtõijenemy.txt趨ijš +int NPC_Lua_Char_GetIp(lua_State *_NLL); //ȡָIPַ +int NPC_Lua_Char_SetAllocPoint(lua_State *_NLL); //óCharIndexάɳ +int NPC_Lua_Char_GetMaxPetIndex(lua_State *_NLL); //ȡ +int NPC_Lua_Char_GetMaxPlayerIndex(lua_State *_NLL); //ȡ +int NPC_Lua_Char_SavePetToString(lua_State *_NLL); //һַ +int NPC_Lua_Char_LoadPetFromString(lua_State *_NLL); //һַһ +int NPC_Lua_Char_GetPlayerFromAccAndName(lua_State *_NLL);//ҵʺźѰҡʺźҲɲҡɶ +int NPC_Lua_Char_CheckPet(lua_State *_NLL); //ǷЧ +int NPC_Lua_Char_CheckPlayer(lua_State *_NLL); //ǷЧ +int NPC_Lua_Char_CheckItemIndex(lua_State *_NLL); //ǷЧ +int NPC_Lua_Char_GetfdFromCharaIndex(lua_State *_NLL); + +BOOL NPC_Lua_Char_JoinParty(lua_State *_NLL); //Ŷ +int NPC_Lua_Char_getFamilyPlayIndex(lua_State *_NLL); //ü + +int NPC_Lua_Char_SetEvtEnd(lua_State *_NLL); //־Ϊ״̬ +int NPC_Lua_Char_SetEvtNow(lua_State *_NLL); //־Ϊ״̬ +int NPC_Lua_Char_SetData(lua_State *_NLL); //Char +int NPC_Lua_Char_logout(lua_State *_NLL); + +int NPC_Lua_Char_getVipPoint(lua_State *_NLL); //Ҹ +int NPC_Lua_Char_getjfPoint(lua_State *_NLL); //ָ +int NPC_Lua_Char_getxjPoint(lua_State *_NLL); //ֽ +int NPC_Lua_Char_setVipPoint(lua_State *_NLL); //Ҳ +int NPC_Lua_Char_setjfPoint(lua_State *_NLL); //ֲ +int NPC_Lua_Char_setxjPoint(lua_State *_NLL); //ֽ + +int NPC_Lua_Char_GetVipPoint(lua_State *_NLL); +int NPC_Lua_Char_SetVipPoint(lua_State *_NLL); +int NPC_Lua_Char_GetAmPoint(lua_State *_NLL); +int NPC_Lua_Char_SetAmPoint(lua_State *_NLL); +int NPC_Lua_Char_GetRmbPoint(lua_State *_NLL); +int NPC_Lua_Char_SetRmbPoint(lua_State *_NLL); + +//¼õĽӿ +int NPC_Lua_Char_SetWalkPreEvent(lua_State *_NLL); //WalkPre¼Ӧ +int NPC_Lua_Char_SetWalkPostEvent(lua_State *_NLL); //WalkPost¼Ӧ +int NPC_Lua_Char_SetPreOverEvent(lua_State *_NLL); //PreOver¼Ӧ +int NPC_Lua_Char_SetPostOverEvent(lua_State *_NLL); //PostOver¼Ӧ +int NPC_Lua_Char_SetWatchEvent(lua_State *_NLL); //Watch¼Ӧ +int NPC_Lua_Char_SetLoopEvent(lua_State *_NLL); //Loop¼Ӧ +int NPC_Lua_Char_SetTalkedEvent(lua_State *_NLL); //Talked¼Ӧ +int NPC_Lua_Char_SetOFFEvent(lua_State *_NLL); //OFF¼Ӧ +int NPC_Lua_Char_SetLookedEvent(lua_State *_NLL); //Looked¼Ӧ +int NPC_Lua_Char_SetItemPutEvent(lua_State *_NLL); //ItemPut¼Ӧ +int NPC_Lua_Char_SetWindowTalkedEvent(lua_State *_NLL); //WindowTalked¼Ӧ +#ifdef _USER_CHARLOOPS +int NPC_Lua_Char_SetCharLoopsEvent(lua_State *_NLL); //CharLoops¼Ӧ +int NPC_Lua_Char_SetBattleProPertyEvent(lua_State *_NLL);//BattleProPerty¼Ӧ +#endif + +//ȡݵĽӿ +int NPC_Lua_Char_IsEventEnd(lua_State *_NLL); //Ƿ־ +int NPC_Lua_Char_IsEventNow(lua_State *_NLL); //Ƿ־ + +int NPC_Lua_Char_FindItemId(lua_State *_NLL); //ָǷӵijID +int NPC_Lua_Char_FindPetEnemyId(lua_State *_NLL); //ָǷӵгEnemyļĶӦID + +int NPC_Lua_Char_GetData(lua_State *_NLL); //ȡChar +int NPC_Lua_Char_GetItemId(lua_State *_NLL); //ȡָָλõĵID +int NPC_Lua_Char_GetPetEnemyId(lua_State *_NLL); //ȡָָλõijEnemyļĶӦID +int NPC_Lua_Char_GetItemIndex(lua_State *_NLL); //ȡָָλõĵ +int NPC_Lua_Char_GetPetIndex(lua_State *_NLL); //ȡָָλõij +int NPC_Lua_Char_GetTeamIndex(lua_State *_NLL); //ȡԱĶ +int NPC_Lua_Char_GetPlayerIndexByCdkey(lua_State *_NLL); //ͨʺŲѯ +int NPC_Lua_Char_VipPoint(lua_State *_NLL); +int NPC_Lua_Char_HealAll(lua_State *_NLL); +int NPC_Lua_Char_GetPetSkillId(lua_State *_NLL); +int NPC_Lua_Char_GetPetSkillName(lua_State *_NLL); +int NPC_Lua_Char_GetPetSkillMsg(lua_State *_NLL); +int NPC_Lua_Char_SetPetSkill(lua_State *_NLL); +int NPC_Lua_Char_RandMsg(lua_State *_NLL); +int NPC_Lua_Char_GetBeatitudeNum(lua_State *_NLL); +///////////////////////////////////////////////GAME//////////////////////////////////////////////// +int NPC_Lua_Game_FMPOINT_GetData(lua_State *_NLL); //ׯ԰ݵϢ +int NPC_Lua_Game_FMPOINT_ACSetFMPoint(lua_State *_NLL); //趨ݵϢݵδռʱЧ +int NPC_Lua_Game_FMPOINT_ACFixFMPoint(lua_State *_NLL); //޸ļݵϢơһս +int NPC_Lua_Game_FMPOINT_ACCleanFMPoint(lua_State *_NLL); //ݵ㡣 +///////////////////////////////////////////////Item//////////////////////////////////////////////// +//ȡݵĽӿ +int NPC_Lua_Item_GetData(lua_State *_NLL); //ȡ +int NPC_Lua_Item_GetDataFromItemSet(lua_State *_NLL); //ȡITEMSETXļ +int NPC_Lua_Item_GetValidity(lua_State *_NLL); //ȡָߵĹʱ +int NPC_Lua_Item_GetItemOwner(lua_State *_NLL); //ȡָ˵ +int NPC_Lua_Item_GetMaxItemIndex(lua_State *_NLL); //ȡ +int NPC_Lua_Item_SaveItemToString(lua_State *_NLL); //һƷַ +int NPC_Lua_Item_SetValidity(lua_State *_NLL); //ָߵĹʱ䡣 +int NPC_Lua_Item_LoadItemFromString(lua_State *_NLL); //һƷַһƷ + +//ݵĽӿ +int NPC_Lua_Item_SetData(lua_State *_NLL); //ȡ + +//¼õĽӿ +int NPC_Lua_Item_SetPreOverEvent(lua_State *_NLL); //PreOver¼Ӧ +int NPC_Lua_Item_SetPostOverEvent(lua_State *_NLL); //PostOver¼Ӧ +int NPC_Lua_Item_SetWatchEvent(lua_State *_NLL); //Watch¼Ӧ +int NPC_Lua_Item_SetUseEvent(lua_State *_NLL); //Use¼Ӧ +int NPC_Lua_Item_SetAttachEvent(lua_State *_NLL); //Attach¼Ӧ +int NPC_Lua_Item_SetDetachEvent(lua_State *_NLL); //Detach¼Ӧ +int NPC_Lua_Item_SetDropEvent(lua_State *_NLL); //Drop¼Ӧ +int NPC_Lua_Item_SetPickUPEvent(lua_State *_NLL); //PickUP¼Ӧ +#ifdef _Item_ReLifeAct +int NPC_Lua_Item_SetDieReLifeEvent(lua_State *_NLL); //DieReLife¼Ӧ +#endif +///////////////////////////////////////////////BIT/////////////////////////////////////////////// +int NPC_Lua_Bit_band(lua_State *_NLL); +int NPC_Lua_Bit_bor(lua_State *_NLL); +int NPC_Lua_Bit_bxor(lua_State *_NLL); +int NPC_Lua_Bit_lshift(lua_State *_NLL); +int NPC_Lua_Bit_rshift(lua_State *_NLL); +///////////////////////////////////////////////Obj//////////////////////////////////////////////// +//ȡݵĽӿ +int NPC_Lua_Obj_GetType(lua_State *_NLL); //ȡOBJ +/* +int NPC_Lua_Obj_GetName(lua_State *_NLL); //ȡOBJ +int NPC_Lua_Obj_GetDIR(lua_State *_NLL); //ȡOBJķ +int NPC_Lua_Obj_GetImageNum(lua_State *_NLL); //ȡOBJ +*/ +int NPC_Lua_Obj_GetCharType(lua_State *_NLL); //ȡOBJӦCharݽṹ +int NPC_Lua_Obj_GetCharIndex(lua_State *_NLL); //ȡOBJӦCharݽṹ +int NPC_Lua_Obj_GetX(lua_State *_NLL); //ȡOBJX +int NPC_Lua_Obj_GetY(lua_State *_NLL); //ȡOBJY +int NPC_Lua_Obj_GetFloor(lua_State *_NLL); //ȡOBJڵĵͼ +//int NPC_Lua_Obj_GetDelTime(lua_State *_NLL); //ȡOBJɾʱ + +int NPC_Lua_Obj_SetType(lua_State *_NLL); //ȡOBJ +/* +int NPC_Lua_Obj_SetName(lua_State *_NLL); //ȡOBJ +int NPC_Lua_Obj_SetDIR(lua_State *_NLL); //ȡOBJķ +int NPC_Lua_Obj_SetImageNum(lua_State *_NLL); //ȡOBJ +*/ +int NPC_Lua_Obj_SetCharType(lua_State *_NLL); //ȡOBJӦCharݽṹ +int NPC_Lua_Obj_SetX(lua_State *_NLL); //ȡOBJX +int NPC_Lua_Obj_SetY(lua_State *_NLL); //ȡOBJY +int NPC_Lua_Obj_SetFloor(lua_State *_NLL); //ȡOBJڵĵͼ +//int NPC_Lua_Obj_SetDelTime(lua_State *_NLL); //ȡOBJɾʱ + +//////////////////////////////////////////////Battle/////////////////////////////////////////////// +//ȡݵĽӿ +int NPC_Lua_Battle_GetPlayIndex(lua_State *_NLL); //ȡսе +int NPC_Lua_Battle_GetData(lua_State *_NLL); //ȡս +int NPC_Lua_Battle_SetData(lua_State *_NLL); //ս +int NPC_Lua_Battle_IndexToNo(lua_State *_NLL); //ͨȡڵս +int NPC_Lua_Battle_NoToIndex(lua_State *_NLL); //ͨսŻȡ +int NPC_Lua_Battle_CheckIndex(lua_State *_NLL); //սǷЧ +//ݵĽӿ +int NPC_Lua_Battle_SetNORisk(lua_State *_NLL); //Ƿ޷ģʽ +int NPC_Lua_Battle_SetMod(lua_State *_NLL); //սģʽ־ +int NPC_Lua_Battle_SetType(lua_State *_NLL); //ս +int NPC_Lua_Battle_Exit(lua_State *_NLL); //˳ս +//¼õĽӿ +int NPC_Lua_Battle_SetWinEvent(lua_State *_NLL); //Win¼Ӧ +int NPC_Lua_Battle_SetEndEvent(lua_State *_NLL); //Win¼Ӧ +///////////////////////////////////////////////Other/////////////////////////////////////////////// +int NPC_Lua_GetFuncPoint(lua_State *_NLL); //ȡָ + +////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////MAP//////////////////////////////////////////////// +int NPC_Lua_Map_CheckCoordinates(lua_State *_NLL); //ijǷڵͼΧڡ +int NPC_Lua_Map_GetExitFloorXY(lua_State *_NLL); //ͼǷֵ֧dz +int NPC_Lua_Map_GetfloorX(lua_State *_NLL); //ȡͼX +int NPC_Lua_Map_GetfloorY(lua_State *_NLL); //ȡͼY +int NPC_Lua_Map_GetTileAndObjId(lua_State *_NLL); //ȡͼijĵذװβ +int NPC_Lua_Map_SetTileAndObjId(lua_State *_NLL); //õͼijĵذװβ +int NPC_Lua_Map_GetWalkAbleFromPoint(lua_State *_NLL); //ȡijǷ +int NPC_Lua_Map_GetImageData(lua_State *_NLL); //ȡͼƬ +int NPC_Lua_Map_SetImageData(lua_State *_NLL); //ͼƬ +int NPC_Lua_Map_GetTopObj(lua_State *_NLL); //ȡͼij϶ +int NPC_Lua_Map_GetNextObj(lua_State *_NLL); //ȡһ +int NPC_Lua_Map_CheckImageIndex(lua_State *_NLL); //ijͼͼƬǷ +int NPC_Lua_Map_CheckIndex(lua_State *_NLL); //ijͼŵͼǷ +int NPC_Lua_Map_MakeNewMap(lua_State *_NLL); //һµĵͼ صͼID +int NPC_Lua_Map_DelNewMap(lua_State *_NLL); //ɾһͼ +int NPC_Lua_Map_SetExWarp(lua_State *_NLL); //dzͼĴ͵ +int NPC_Lua_Map_SetMapPoint(lua_State *_NLL); //ӵͼ͵ +int NPC_Lua_Map_DelMapPoint(lua_State *_NLL); //ɾͼ͵ +int NPC_Lua_Map_getFloorName(lua_State *_NLL); //õͼ +int NPC_Lua_Map_Upmap(lua_State *_NLL); //µͼ +///////////////////////////////////////////////MAP//////////////////////////////////////////////// +///////////////////////////////////////////////Spell//////////////////////////////////////////////// +int NPC_Lua_Spell_PETSKILL_GetData(lua_State *_NLL); //ȡ\ID +int NPC_Lua_Spell_PROFESSION_GetData(lua_State *_NLL); //ȡְҵID +int NPC_Lua_Spell_MAGIC_GetData(lua_State *_NLL); //ȡ鼼ID +int NPC_Lua_Spell_PETSKILL_SetData(lua_State *_NLL); //öӦIDļݣ +int NPC_Lua_Spell_PROFESSION_SetData(lua_State *_NLL); //öӦIDļݣ +int NPC_Lua_Spell_MAGIC_SetData(lua_State *_NLL); //öӦIDļݣ +///////////////////////////////////////////////Spell//////////////////////////////////////////////// +///////////////////////////////////////////////SQL///////////////////////////////////////////////// +int NPC_Lua_SQL_Push(lua_State *_NLL); //MySQLָ +int NPC_Lua_SQL_PushPop(lua_State *_NLL); //MySQLָӦ +int NPC_Lua_SQL_PushPopAdv(lua_State *_NLL); //SAACһSQLѯ󣬲ָSAACشʱԽдĻص,úصһнͷŽ +int NPC_Lua_SQL_QueryFirstRow(lua_State *_NLL); //ص,úصһнͷŽ +int NPC_Lua_SQL_FetchRow(lua_State *_NLL); //һ +int NPC_Lua_SQL_FreeResult(lua_State *_NLL); //ͷŽ +///////////////////////////////////////////////SQL/////////////////////////////////////////////// +#define LRet(r) \ +{ \ + NPC_Lua_SetErrorStr(NULL); \ + return r; \ +} + +#define LRetErr(c,r) \ +{ \ + NPC_Lua_SetErrorStr(c); \ + return r; \ +} + +////////////////////////////////////////////////////////////////////// +//һnil +#define LRetNull(L) \ +{ \ + lua_pushnil(L); \ + LRet(1); \ +} + +//һBOOLLUA +#define LRetBool(L, b) \ +{ \ + lua_pushboolean(L, b); \ + LRet(1); \ +} + +//һintLUA +#define LRetInt(L, i) \ +{ \ + lua_pushinteger(L, i); \ + LRet(1); \ +} + +#define LRetMsg(L, c) \ +{ \ + lua_pushstring(L, c); \ + LRet(1); \ +} +//////////////////////////////////////////////////////////////////// +//һ״̬һϢ +#define LRetErrInt(L, i, c) \ +{ \ + lua_pushinteger(L, i); \ + LRetErr(c,1); \ +} + +//һַLUA +#define LRetErrNull(L, c) \ +{ \ + lua_pushnil(L); \ + LRetErr(c,1); \ +} + +//һַLUA +#define LRetErrMsg(L, c) \ +{ \ + lua_pushstring(L, c); \ + LRetErr(c,1); \ +} + +//ڼǷ㹻 +#define CheckEx(L, n) \ +{ \ + if(lua_gettop(L) != n) \ + { \ + luaL_argerror(L, 1, ""); \ + } \ +} + +#define CheckEx2(L, t, n) \ +{ \ + if(lua_gettop(L) < (t) || lua_gettop(L) > n) \ + { \ + luaL_argerror(L, 1, ""); \ + } \ +} + +#define CheckIndexNull(L, n) \ +{ \ + if(lua_isnil((L), (n))) \ + { \ + luaL_argerror((L), 1, "Ϊnil"); \ + } \ +} + +#define CheckBattleIndexNull(L, n) \ +{ \ + if(lua_isnil((L), (n))) \ + { \ + luaL_argerror((L), 1, "սΪnil"); \ + } \ +} + +#define CheckItemIndexNull(L, n) \ +{ \ + if(lua_isnil((L), (n))) \ + { \ + luaL_argerror((L), 1, "Ϊnil"); \ + } \ +} + +#define CheckObjIndexNull(L, n) \ +{ \ + if(lua_isnil((L), (n))) \ + { \ + luaL_argerror((L), 1, "Ϊnil"); \ + } \ +} + +#define LRetArray(L, Array, num) \ +{ \ + Lua_ReturnArray(L, Array, num); \ + LRet(1); \ +} + +#ifdef _LUA_Debug +int pcall_callback_err_fun(lua_State* L,const char *_InitFuncName); //LUAűϢ +#endif + +#endif //#ifndef __NPC_LUA__ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua_interface.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua_interface.h new file mode 100644 index 0000000..9a01eae --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_lua_interface.h @@ -0,0 +1,130 @@ +#ifndef __NPC_LUA_INTERFACE__ +#define __NPC_LUA_INTERFACE__ + +#include "version.h" +#include "common.h" + +/////////////////////////////////////////ⲿӿ///////////////////////////////////////////////////////////////// +#define FUNCNAME_INITCALLBACK "NPC_Lua_InitCallBack" //CHAR_INITFUNC +#define FUNCNAME_WALKPRECALLBACK "NPC_Lua_WalkPreCallBack" //CHAR_WALKPREFUNC +#define FUNCNAME_WALKPOSTCALLBACK "NPC_Lua_WalkPostCallBack" //CHAR_WALKPOSTFUNC +#define FUNCNAME_PREOVERCALLBACK "NPC_Lua_PreOverCallBack" //CHAR_PREOVERFUNC +#define FUNCNAME_POSTOVERCALLBACK "NPC_Lua_PostOverCallBack" //CHAR_POSTOVERFUNC +#define FUNCNAME_WATCHCALLBACK "NPC_Lua_WatchCallBack" //CHAR_WATCHFUNC +#define FUNCNAME_LOOPCALLBACK "NPC_Lua_LoopCallBack" //CHAR_LOOPFUNC +#define FUNCNAME_TALKEDCALLBACK "NPC_Lua_TalkedCallBack" //CHAR_TALKEDFUNC +#define FUNCNAME_OFFCALLBACK "NPC_Lua_OFFCallBack" //CHAR_OFFFUNC +#define FUNCNAME_LOOKEDCALLBACK "NPC_Lua_LookedCallBack" //CHAR_LOOKEDFUNC +#define FUNCNAME_ITEMPUTCALLBACK "NPC_Lua_ItemPutCallBack" //CHAR_ITEMPUTFUNC +#define FUNCNAME_WINDOWTALKEDCALLBACK "NPC_Lua_WindowTalkedCallBack" //CHAR_WINDOWTALKEDFUNC +#ifdef _USER_CHARLOOPS +#define FUNCNAME_CHARLOOPSCALLBACK "NPC_Lua_CharLoopsCallBack" //CHAR_LOOPFUNCTEMP1 ﵰιҩԭеLOOP +#define FUNCNAME_BATTLEPROPERTYCALLBACK "NPC_Lua_BattleProPertyCallBack" //CHAR_BATTLEPROPERTY +#endif +/* + CHAR_DYINGFUNC, + , + CHAR_PREATTACKEDFUNC, + CHAR_POSTATTACKEDFUNC, + + CHAR_SPECIALTALKEDFUNC, + , +#ifdef _USER_CHARLOOPS + , + CHAR_LOOPFUNCTEMP2, + , +#endif +*/ +#define FUNCNAME_ITEMPEROVERCALLBACK "NPC_Lua_ItemPerOverCallBack" //LUAITEM_PREOVERFUNC = ITEM_PREOVERFUNC +#define FUNCNAME_ITEMPOSTOVERCALLBACK "NPC_Lua_ItemPostOverCallBack" //LUAITEM_POSTOVERFUNC = ITEM_POSTOVERFUNC +#define FUNCNAME_ITEMWATCHCALLBACK "NPC_Lua_ItemWatchCallBack" //LUAITEM_WATCHFUNC = ITEM_WATCHFUNC +#define FUNCNAME_ITEMUSECALLBACK "NPC_Lua_ItemUseCallBack" //LUAITEM_USEFUNC = ITEM_USEFUNC +#define FUNCNAME_ITEMATTACHCALLBACK "NPC_Lua_ItemAttachCallBack" //LUAITEM_ATTACHFUNC = ITEM_ATTACHFUNC +#define FUNCNAME_ITEMDETACHCALLBACK "NPC_Lua_ItemDetachCallBack" //LUAITEM_DETACHFUNC = ITEM_DETACHFUNC +#define FUNCNAME_ITEMDROPCALLBACK "NPC_Lua_ItemDropCallBack" //LUAITEM_DROPFUNC = ITEM_DROPFUNC +#define FUNCNAME_ITEMPICKUPCALLBACK "NPC_Lua_ItemPickUPCallBack" //LUAITEM_PICKUPFUNC = ITEM_PICKUPFUNC +#ifdef _Item_ReLifeAct +#define FUNCNAME_ITEMDIERELIFECALLBACK "NPC_Lua_ItemDieReLifeCallBack" //LUAITEM_DIERELIFEFUNC = ITEM_DIERELIFEFUNC +#endif + +#define FUNCNAME_BATTLEWINCALLBACK "NPC_Lua_BattleWinCallBack" //BATTLE WinFunc +#define FUNCNAME_BATTLEENDCALLBACK "NPC_Lua_BattleEndCallBack" //BATTLE WinFunc +//ʼLUA +int NPC_Lua_Init(const char *_DoFile); + +//رLUA +int NPC_Lua_Close(void); + +//̬ؽűļ +int NPC_Lua_DoFile(const char *_DoFile); + +//LUAűջһ +const char *NPC_Lua_popstring(int _ArgNum); + +//ָĽű +const char *NPC_Lua_CallFunc(const char *_FuncName, char *_RetBuff, size_t _n, int index); + +//ս +int NPC_Lua_getBattleFieldNo(int _Floor, int _X, int _Y); + +//ȡ +int NPC_GivePet(int charaindex, int lv, int enemyid); +//ȡ +int NPC_GiveItem(int charaindex, int itemid); +//ɾ +int NPC_DelPet(int charaindex, int petsel); + +//ص +BOOL NPC_Lua_InitCallBack(int _meindex); +BOOL NPC_Lua_WalkPreCallBack(int _meindex, int *_dir, int *_mode); +void NPC_Lua_WalkPostCallBack(int _meindex); +void NPC_Lua_PreOverCallBack(int _meindex, int _desindex); +void NPC_Lua_PostOverCallBack(int _meindex, int _desindex); +void NPC_Lua_WatchCallBack(int _meindex, int _objindex, int _chac, int _x, int _y, int _dir, int *_watchopt, int _watchoptlen); +int NPC_Lua_LoopCallBack(int _meindex); +void NPC_Lua_TalkedCallBack(int _meindex, int _tomeindex,const char *_messageeraseescape, int _color, int _channel); +void NPC_Lua_OFFCallBack(int _meindex, int _desindex); +void NPC_Lua_LookedCallBack(int _meindex, int _desindex); +BOOL NPC_Lua_ItemPutCallBack(int _meindex, int _itemindex); +void NPC_Lua_WindowTalkedCallBack(int _meindex, int _talkindex, int _seqno, int _select,const char *_data); +#ifdef _USER_CHARLOOPS +int NPC_Lua_CharLoopsCallBack( int _meindex); +int NPC_Lua_BattleProPertyCallBack(int _attackindex, int _defindex, int *_damage, int *_powarray, int _arraynum); +#endif + +/* ʱδʹõ¼ +int NPC_Lua_DyingCallBack(int meindex); +NPC_Lua_PreAttackedCallBack +NPC_Lua_PostAttackedCallBack +NPC_Lua_SpecialTalkedCallBack +*/ + +void NPC_Lua_ItemPerOverCallBack(int _itemindex, int _playindex); +void NPC_Lua_ItemPostOverCallBack(int _itemindex, int _playindex); +void NPC_Lua_ItemWatchCallBack(int _meindex, int _objindex, int _chac, int _x, int _y, int _dir, int *_watchopt, int _watchoptlen); +void NPC_Lua_ItemUseCallBack(int _playindex, int _to_charindex, int _haveitemindex); +void NPC_Lua_ItemAttachCallBack(int _playindex, int _itemindex); +void NPC_Lua_ItemDetachCallBack(int _playindex, int _itemindex); +void NPC_Lua_ItemDropCallBack(int _playindex, int _itemindex); +void NPC_Lua_ItemPickUPCallBack(int _playindex, int _itemindex); +#ifdef _Item_ReLifeAct +void NPC_Lua_ItemDieReLifeCallBack(int _playindex, int _itemindex, int _haveitem); +#endif + +void NPC_Lua_BattleWinCallBack(int _battleindex, int _createindex); +void NPC_Lua_BattleEndCallBack(int _battleindex); +#ifdef _MO_LNS_MYSQLSUOXU +void NPC_Lua_SQLPushCallBack(char* _result,char* _filename,char* _function,int _npcindex,int _playerindex, char* _msg); +void NPC_Lua_SQLPushAdvCallBack(int luaresult,int luaflg,int luaerrnono,char* luaerrstr,int luafileCount,int rowCount,int rowAt,char* row,char* _filename,char* _function,int npcindex,int charaindex,char* msg); +#endif +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#endif //#ifndef __NPC_LUA_INTERFACE__ +void NPC_Lua_NEWSHOP_Recv(char* function, int charaindex); +#ifdef _CHARSIGNDAY_ +void NPC_Lua_CharSignDay_Recv(char* function,int charaindex); +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_luckyman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_luckyman.h new file mode 100644 index 0000000..36c4db4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_luckyman.h @@ -0,0 +1,10 @@ +#ifndef __NPC_LUCKYMAN_H__ +#define __NPC_LUCKYMAN_H__ + +void NPC_LuckyManTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_LuckyManInit( int meindex ); +void NPC_LuckyManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif +/*__NPC_LUCKYMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_magiccard.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_magiccard.h new file mode 100644 index 0000000..09bc925 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_magiccard.h @@ -0,0 +1,36 @@ +#ifndef __NPC_MAGICCARD_H__ +#define __NPC_MAGICCARD_H__ + + +#define BANKERTOTAL 2 // J֡ + +struct BANKER +{ + short starttotal; + short playertotal; + short state; + int waittime; // + int turntime; //ޡ + short turn; + int hp[7]; + char cdkey[6][CDKEYLEN]; + char name[6][CHARNAMELEN]; + unsigned int hand; + unsigned int history; + short select; + short action; + short process; + short pauseflag[7]; +}; + +extern struct BANKER banker[]; +extern int Bettotal[BANKERTOTAL]; +extern int Wintotal[BANKERTOTAL]; +extern int tickettotal[BANKERTOTAL]; + +BOOL NPC_Magiccard_Init( int meindex ); +void NPC_Magiccard_Loop( int meindex ); +void NPC_Magiccard_WindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_Magiccard_Talked( int meindex , int talkerindex , char *szMes , int color ); + +#endif \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_makepair.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_makepair.h new file mode 100644 index 0000000..f0d775d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_makepair.h @@ -0,0 +1,22 @@ +#ifndef _MAKEPAIR_MAN_H +#define _MAKEPAIR_MAN_H + +void NPC_MakePairManTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_MakePairManInit( int meindex ); +void NPC_MakePairManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_MakePairManLoop( int meindex); + +typedef struct _tagPairMenu{ + char cdKey[256]; + char name[256]; + int pindex; + int forindex; + int code; + int use; +}PairMenu; + + + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_manorsman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_manorsman.h new file mode 100644 index 0000000..ef860b4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_manorsman.h @@ -0,0 +1,19 @@ +#ifndef __NPC_MANORSMAN_H__ +#define __NPC_MANORSMAN_H__ +#include +BOOL NPC_ManorSmanInit(int meindex); +void NPC_ManorSmanTalked(int meindex, int talkerindex, char *msg, int color); +void NPC_ManorSmanWindowTalked(int meindex, int talkerindex, + int seqno, int select, char *data); +void NPC_ManorSmanLoop(int meindex); +//andy_123 +int NPC_getManorsmanListIndex( int ID); +#ifndef _NEW_MANOR_LAW +void NPC_ManorSavePKSchedule(int meindex, int toindex, int flg); +#else +void NPC_ManorSavePKSchedule(int meindex, int toindex, int flg,int setTime,struct tm tm1); +void NPC_ManorAddToSchedule(int meindex,int charaindex, int dueltime); +#endif + +#endif +/*__NPC_MANORSMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mic.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mic.h new file mode 100644 index 0000000..501e0d4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mic.h @@ -0,0 +1,9 @@ +#ifndef __NPC_MIC_H__ +#define __NPC_MIC_H__ + +BOOL NPC_MicInit(int meindex ); +void NPC_MicTalked( int meindex , int talkerindex , char *msg , int color ); + +#endif + /*__NPC_MIC_H__*/ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_msg.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_msg.h new file mode 100644 index 0000000..f0f875b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_msg.h @@ -0,0 +1,9 @@ +#ifndef _NPC_MSG_H_ +#define _NPC_MSG_H_ + +BOOL NPC_MsgInit( int meindex ); +void NPC_MsgLooked( int meindex , int lookedindex ); + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mtradenpcman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mtradenpcman.h new file mode 100644 index 0000000..93135bf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_mtradenpcman.h @@ -0,0 +1,10 @@ +#ifndef __NPC_MAPTRADEMAN_H__ +#define __NPC_MAPTRADEMAN_H__ + +BOOL MapTradeManInit( int meindex ); +void MapTradeManLoop( int meindex); +void MapTradeManTalked( int meindex , int talkerindex , char *msg , int color ); +void MapTradeManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newnpcman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newnpcman.h new file mode 100644 index 0000000..9ad31b7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newnpcman.h @@ -0,0 +1,8 @@ +#ifndef __NPC_NEWNPCMAN_H__ +#define __NPC_NEWNPCMAN_H__ +BOOL NPC_NewNpcManInit( int meindex ); +void NPC_NewNpcManLoop( int meindex); +void NPC_NewNpcManTalked( int meindex , int talkerindex , char *msg , int color ); +void NPC_NewNpcManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newvipshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newvipshop.h new file mode 100644 index 0000000..2d3c7b6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_newvipshop.h @@ -0,0 +1,9 @@ +#ifndef _NEW_VIP_SHOP_H +#define _NEW_VIP_SHOP_H + +void NPC_NewVipShopTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_NewVipShopInit( int meindex ); +void NPC_NewVipShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_NewVipShopLoop( int meindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_npcenemy.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_npcenemy.h new file mode 100644 index 0000000..62134e4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_npcenemy.h @@ -0,0 +1,17 @@ +#ifndef __NPC_NPCENEMY_H__ +#define __NPC_NPCENEMY_H__ + +void NPC_NPCEnemyTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_NPCEnemyInit( int meindex ); +int NPC_NPCEnemy_Dying( int battleindex, int meindex ); +int NPC_NPCEnemy_Encount( int meindex, int charaindex, int mode); +void NPC_NPCEnemyWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ); +void NPC_NPCEnemyLoop( int meindex ); +BOOL NPC_NPCEnemy_BattleIn( int meindex, int charaindex); +void NPC_NPCEnemyWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + /*__NPC_NPCENEMY_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_oldman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_oldman.h new file mode 100644 index 0000000..2b457b9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_oldman.h @@ -0,0 +1,12 @@ +#ifndef __NPC_OLDMAN_H__ +#define __NPC_OLDMAN_H__ + + +void NPC_OldmanTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_OldmanInit( int meindex ); + + +#endif +/*__NPC_OLDMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pauctionman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pauctionman.h new file mode 100644 index 0000000..ca94846 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pauctionman.h @@ -0,0 +1,8 @@ +#ifndef _PAUCTION_H +#define _PAUCTION_H + +BOOL NPC_PauctionInit( int meindex ); +void NPC_PauctionLoop( int meindex); +void NPC_PauctionTalked( int meindex, int talkerindex, char *msg, int color ); +void NPC_PauctionWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petfusion.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petfusion.h new file mode 100644 index 0000000..3fbe665 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petfusion.h @@ -0,0 +1,11 @@ +#ifndef __NPC_PETFUSION_H__ +#define __NPC_PETFUSION_H__ + + +void NPC_PetFusionManTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_PetFusionManInit( int meindex ); +void NPC_PetFusionManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_PetFusionManLoop( int meindex); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petmaker.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petmaker.h new file mode 100644 index 0000000..2754e9b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petmaker.h @@ -0,0 +1,9 @@ +#ifndef __NPC_PETMAKER_H__ +#define __NPC_PETMAKER_H__ + +void NPC_PetMakerTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_PetMakerInit( int meindex ); + +#endif + /*__NPC_PETMAKER_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracemaster.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracemaster.h new file mode 100644 index 0000000..c8caa27 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracemaster.h @@ -0,0 +1,10 @@ +#ifndef NPC_PetRace_Master_ +#define NPC_PetRace_Master_ + +BOOL NPC_PetRaceMasterInit( int meindex ); +void NPC_PetRaceMasterLoop( int meindex ); +void NPC_PetRaceMasterTalked( int meindex , int talkerindex , char *szMes , int color ); +void NPC_PetRaceMasterWindowTalked(int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracepet.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracepet.h new file mode 100644 index 0000000..f421126 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petracepet.h @@ -0,0 +1,9 @@ +#ifndef NPC_PetRace_Pet_ +#define NPC_PetRace_Pet_ + +BOOL NPC_PetRacePetInit( int meindex ); +void NPC_PetRacePetLoop( int meindex ); +void NPC_PetRacePetTalked( int meindex , int talkerindex , char *szMes , int color ); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petshop.h new file mode 100644 index 0000000..dca3230 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petshop.h @@ -0,0 +1,12 @@ +#ifndef __NPC_PETSHOP_H__ +#define __NPC_PETSHOP_H__ + +void NPC_PetShopTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_PetShopInit( int meindex ); +void NPC_PetShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_PetShopLooked( int meindex , int lookedindex); +void NPC_PetShop_selectWindow( int meindex, int toindex, int num,int select); + +#endif +/*__NPC_PETSHOP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petskillshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petskillshop.h new file mode 100644 index 0000000..ca603bb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_petskillshop.h @@ -0,0 +1,13 @@ +#ifndef __NPC_PETSKILLSHOP_H__ +#define __NPC_PETSKILLSHOP_H__ + +void NPC_PetSkillShopTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_PetSkillShopInit( int meindex ); +void NPC_PetSkillShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_PetSkillShopLooked( int meindex , int lookedindex); + +void NPC_PetSkillMakeStr(int meindex,int toindex,int select); + +#endif + /*__NPC_WINDOWPETSKILLSHOP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pettransman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pettransman.h new file mode 100644 index 0000000..c840706 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_pettransman.h @@ -0,0 +1,11 @@ +#ifndef __NPC_PETTRANSMAN_H__ +#define __NPC_PETTRANSMAN_H__ + +BOOL NPC_PetTransManInit(int meindex); +void NPC_PetTransMan_selectWindow(int meindex,int toindex,int num,int select); +void NPC_PetTransManWindowTalked(int meindex,int talkerindex,int seqno,int select,char *data); +void NPC_PetTransManTalked(int meindex,int talkerindex,char *szMes,int color); +int NPC_PetTransManCheck( int meindex, int toindex, int select); +BOOL NPC_PetTransManStatus( int meindex, int toindex, int petNo); +#endif + /*__NPC_PETTRANSMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_poolitemshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_poolitemshop.h new file mode 100644 index 0000000..6859d16 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_poolitemshop.h @@ -0,0 +1,14 @@ +#ifndef __NPC_POOLITEMSHOP_H__ +#define __NPC_POOLITEMSHOP_H__ + + +void NPC_PoolItemShopLoop( int meindex); +BOOL NPC_PoolItemShopInit( int meindex); +void NPC_PoolItemShopTalked( int meindex , int talkerindex , + char *szMes ,int color ); +void NPC_PoolItemShopWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data); +void NPC_PoolItemShop_printWindow_Start( int meindex, int talkerindex); + +#endif + /*__NPC_POOLITEMSHOP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_quiz.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_quiz.h new file mode 100644 index 0000000..31290c1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_quiz.h @@ -0,0 +1,29 @@ +#ifndef __NPC_QUIZ_H__ +#define __NPC_QUIZ_H__ + +typedef struct NPC_Quiz{ + + int no; // į + int type; // ءة ̡֭) + int level; // ì + int answertype; //̫( ǩѨ + int answerNo; // + char question[512]; // + char select1[128]; // 1 + char select2[128]; // 2 + char select3[128]; // 3 + +}NPC_QUIZ; + + +void NPC_QuizTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_QuizInit( int meindex ); +void NPC_QuizWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +BOOL QUIZ_initQuiz( char *filename); + + +#endif + +/*__NPC_QUIZ_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_riderman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_riderman.h new file mode 100644 index 0000000..bfaa48f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_riderman.h @@ -0,0 +1,12 @@ +#ifndef __NPC_RIDERMAN_H__ +#define __NPC_RIDERMAN_H__ + +void NPC_RidermanTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_RidermanInit( int meindex ); +void NPC_RidermanLooked( int meindex, int lookedindex ); +void NPC_RidermanWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +#endif + /*__NPC_RIDERMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_roomadminnew.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_roomadminnew.h new file mode 100644 index 0000000..a89c700 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_roomadminnew.h @@ -0,0 +1,33 @@ +#ifndef __NPC_ROOMADMINNEW_H__ +#define __NPC_ROOMADMINNEW_H__ + + +void NPC_RoomAdminNewTalked( int meindex , int talkerindex , char *msg , int color ); +void NPC_RoomAdminNewLoop( int meindex ); +BOOL NPC_RoomAdminNewInit( int meindex ); + +BOOL NPC_RankingInit( int meindex ); +void NPC_RankingTalked( int meindex , int talkerindex , char *msg ,int color ); + +BOOL NPC_PrintpassmanInit( int meindex ); +void NPC_PrintpassmanTalked( int meindex , int talkerindex , char *msg ,int color ); + +typedef struct npc_roomadminnew_tag { + int expire; + char cdkey[CDKEYLEN]; + char charaname[32]; + char passwd[9]; +}NPC_ROOMINFO; + +typedef struct npc_roomadminnew_ranking_tag { + int gold; /* ڿź */ + int biddate; /* ڿ */ + char cdkey[CDKEYLEN]; /* м ƽ */ + char charaname[32]; /* м */ + char owntitle[32]; /* į*/ + +}NPC_RANKING_INFO; + +#endif /*__NPC_ROOMADMINNEW_H__*/ + +BOOL NPC_RoomAdminNew_ReadFile( char *roomname, NPC_ROOMINFO *data); diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sample.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sample.h new file mode 100644 index 0000000..b648598 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sample.h @@ -0,0 +1,8 @@ +#ifndef __NPC_SAMPLE_H__ +#define __NPC_SAMPLE_H__ + +void NPC_SampleLoop( int index ); + +#endif + + /*__NPC_SAMPLE_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_savepoint.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_savepoint.h new file mode 100644 index 0000000..80edab6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_savepoint.h @@ -0,0 +1,14 @@ +#ifndef __NPC_SAVEPOINT_H__ +#define __NPC_SAVEPOINT_H__ + + +void NPC_SavePointTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_SavePointInit( int meindex ); +void NPC_SavePointWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + + +#endif + +/*__NPC_SAVEPOINT_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_scheduleman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_scheduleman.h new file mode 100644 index 0000000..80efe38 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_scheduleman.h @@ -0,0 +1,83 @@ +#ifndef __NPC_SCHEDULEMAN_H__ +#define __NPC_SCHEDULEMAN_H__ + +#define CHARNAME_MAX 32 + +// scheduleman +#ifdef _FAMILY_MANORNUM_CHANGE +#define MAX_SCHEDULEMAN 20 +#else +#define MAX_SCHEDULEMAN 12 +#endif + +// ÿһ scheduleman عܵ schedule +#define MAX_SCHEDULE 24 + +// schedule бһҳг +#define MAXSCHEDULEINONEWINDOW 10 + +// family бһҳг +#define MAXFAMILYINONEWINDOW 8 + +// ÿһ scheduleman ʹõ schedule λ +// Ӧ fmpks ID*MAX_SCHEDULE (ID=0~MAX_SCHEDULEMAN-1) +// ID д data/npc ָ "id:" ֵ + +// dueltime = (?10000:0) + (Сʱ*100) + +typedef struct tagFamilyPKSchedule { + int dueltime; // ʱ + int host_index; // Ӽ + char host_name[CHARNAME_MAX]; // Ӽ + int guest_index; // ͶӼ + char guest_name[CHARNAME_MAX]; // ͶӼ + int prepare_time; // ׼ʱ (1~40 ) + int max_player; // (1~) + int flag; // ״̬ + int win; // ʤ趨 + int challenge_timeout; // սʱ + int setting_timeout; // 趨״̬ timeout + char gmsv_name[256]; +} FamilyPKSchedule; + +// ¼ FamilyPKSchedule (fmpks) flag ֵ +#define FMPKS_FLAG_NONE -1 // ûκų +#define FMPKS_FLAG_CHALLENGE 0 // ȴͶͬ +#define FMPKS_FLAG_SETTING 1 // 趨ų (ȡʱ NONE) +#define FMPKS_FLAG_CONFIRMING 2 // Ͷͬ +#define FMPKS_FLAG_SCHEDULED 3 // Ѿźų̣δ +#define FMPKS_FLAG_DUEL 4 // +#define FMPKS_FLAG_HOSTWIN 5 // ʤ +#define FMPKS_FLAG_GUESTWIN 6 // Ͷʤ +#define FMPKS_FLAG_MANOR_BATTLEBEGIN 7 // ׯ԰ս ս +#define FMPKS_FLAG_MANOR_PREPARE 8 // ׯ԰ս ׼ +#define FMPKS_FLAG_MANOR_PEACE 9 // ׯ԰ս ս +#define FMPKS_FLAG_MANOR_OTHERPLANET 10 // ׯ԰ս ڱս +#define FMPKS_FLAG_MANOR_BATTLEEND 11 // ׯ԰ս ս +#define FMPKS_FLAG_MANOR_PEACE_SAVE 12 // ׯ԰ս浵 +#define FMPKS_FLAG_MANOR_READYTOFIGHT 13 // (GM: manorpk) ȫϵɿԼս״̬ +#define FMPKS_FLAG_MANOR_CLEANFLAG 14 // (GM: manorpk) ״̬ +#ifdef _NEW_MANOR_LAW +#define FMPKS_FLAG_WAIT 15 // ս,Ѽ¼,ȴսų +#endif + + +// client flag +#define FLAG_NONE -1 +#define FLAG_MODIFY 0 +#define FLAG_ACCEPT 1 +#define FLAG_SETTING 2 +#define FLAG_CONFIRM 3 +#define FLAG_SCHEDULED 4 + +extern FamilyPKSchedule fmpks[MAX_SCHEDULE*MAX_SCHEDULEMAN]; + +BOOL NPC_SchedulemanInit(int meindex); +void NPC_SchedulemanTalked(int meindex, int talkerindex, char *msg, int color); +void NPC_SchedulemanWindowTalked(int meindex, int talkerindex, + int seqno, int select, char *data); +void NPC_SchedulemanLoop(int meindex); + +#endif + +/*__NPC_SCHEDULEMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sellsthman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sellsthman.h new file mode 100644 index 0000000..6ce6165 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sellsthman.h @@ -0,0 +1,9 @@ +#ifndef _SELLSTH_MAN_H +#define _SELLSTH_MAN_H + +void NPC_SellsthManTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_SellsthManInit( int meindex ); +void NPC_SellsthManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_SellsthManLoop( int meindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_signboard.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_signboard.h new file mode 100644 index 0000000..ed96680 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_signboard.h @@ -0,0 +1,11 @@ +#ifndef __NPC_SIGNBOARD_H__ +#define __NPC_SIGNBOARD_H__ + + +BOOL NPC_SignBoardInit( int meindex ); +void NPC_SignBoardWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_SignBoardLooked( int meindex , int lookedindex); + + +#endif + /*__NPC_WINDOWSIGNBOAD_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_simpleshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_simpleshop.h new file mode 100644 index 0000000..3b0da80 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_simpleshop.h @@ -0,0 +1,10 @@ +#ifndef __NPC_SIMPLESHOP_H__ +#define __NPC_SIMPLESHOP_H__ + +void NPC_SimpleShopTalked( int index, int talker, char *msg, int color ); +void NPC_SimpleShopSpecialTalked( int index, int talker, char *msg, int color ); +void NPC_LimitBuyInShopSpecialTalked( int index, int talker, char *msg, int color ); +void NPC_SimpleShopInit( int meindex ); + +#endif + /*__NPC_SIMPLESHOP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_stoneserviceman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_stoneserviceman.h new file mode 100644 index 0000000..9d9feb1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_stoneserviceman.h @@ -0,0 +1,20 @@ +#ifndef __NPC_STONESERVICEMAN_H__ +#define __NPC_STONESERVICEMAN_H__ + +// ϴ +typedef struct _List +{ + char Data[32]; // + struct _List *Next; // ָһList +}List,*LPList; + +BOOL NPC_StoneServiceManInit(int meindex); +void NPC_StoneServiceManLoop(int meindex); +void NPC_StoneServiceManTalked(int meindex,int talkerindex,char *msg,int color); +void NPC_StoneServiceManWindowTalked(int meindex,int talkerindex,int seqno, + int select,char *data); +int SendToAP(int nAid,int nIndex,int nLen,void *Data1,void *Data2); +int RecvFromAP(int *nAid,int nIndex,int *nLen,LPList *Data); +int GetMsg(int meindex); +int ConnectToAP(void); +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_storyteller.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_storyteller.h new file mode 100644 index 0000000..a8a17cf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_storyteller.h @@ -0,0 +1,8 @@ +#ifndef _NPC_STORYTELLER_H_ +#define _NPC_STORYTELLER_H_ + +BOOL NPC_StoryTellerInit( int meindex ); +void NPC_StoryTellerTalked( int meindex , int talker , char *msg , int col ); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sysinfo.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sysinfo.h new file mode 100644 index 0000000..37b6b4b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_sysinfo.h @@ -0,0 +1,7 @@ +#ifndef __NPC_SYSINFO_H__ +#define __NPC_SYSINFO_H__ + +BOOL NPC_SysinfoInit( int meindex ); +void NPC_SysinfoLoop( int meindex ); +void NPC_SysinfoTalked( int meindex, int tindex, char *msg, int color); +#endif /*__NPC_SYSINFO_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_timeman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_timeman.h new file mode 100644 index 0000000..0611141 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_timeman.h @@ -0,0 +1,13 @@ +#ifndef __NPC_TIMEMAN_H__ +#define __NPC_TIMEMAN_H__ + + +void NPC_TimeManTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_TimeManInit( int meindex ); + +void NPC_TimeManWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ); + +#endif /*__NPC_TIMEMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_townpeople.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_townpeople.h new file mode 100644 index 0000000..745317b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_townpeople.h @@ -0,0 +1,7 @@ +#ifndef __NPC_TOWNPEOPLE_H__ +#define __NPC_TOWNPEOPLE_H__ + +void NPC_TownPeopleTalked( int index, int talker, char *msg, int color ); +void NPC_TownPeopleInit( int meindex ); + +#endif /* __NPC_TOWNPEOPLE_H__ */ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transerman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transerman.h new file mode 100644 index 0000000..2acca4e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transerman.h @@ -0,0 +1,9 @@ +#ifndef _TRANSER_MAN_H +#define _TRANSER_MAN_H + +void NPC_TranserManTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_TranserManInit( int meindex ); +void NPC_TranserManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_TranserManLoop( int meindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transmigration.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transmigration.h new file mode 100644 index 0000000..506d171 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_transmigration.h @@ -0,0 +1,12 @@ +#ifndef __NPC_TRANSMIGRATION_H__ +#define __NPC_TRANSMIGRATION_H__ + +void NPC_TransmigrationTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_TransmigrationInit( int meindex ); +void NPC_TransmigrationWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +BOOL NPC_TransmigrationStatus(int meindex, int toindex,int *work); +int NPC_TransmigrationFlg_CLS(int meindex, int toindex); +#endif + +/*__NPC_TRANSMIGRATION_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_vipshop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_vipshop.h new file mode 100644 index 0000000..01133ff --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_vipshop.h @@ -0,0 +1,9 @@ +#ifndef _VIP_SHOP_H +#define _VIP_SHOP_H + +void NPC_VipshopTalked( int meindex, int talkerindex, char *msg, int color ); +BOOL NPC_VipshopInit( int meindex ); +void NPC_VipshopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_VipshopLoop( int meindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warp.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warp.h new file mode 100644 index 0000000..4caafbc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warp.h @@ -0,0 +1,10 @@ +#ifndef __NPC_WARP_H__ +#define __NPC_WARP_H__ +BOOL NPC_WarpInit( int charaindex ); +void NPC_WarpPostOver( int meindex,int charaindex ); +void NPC_WarpWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ); +int NPC_WarpSearchByPosition( int fl , int x, int y); +void NPC_WarpWarpCharacter( int warpnpcindex, int charaindex ); +#endif + /*__NPC_WARP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warpman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warpman.h new file mode 100644 index 0000000..ee48e0a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_warpman.h @@ -0,0 +1,13 @@ +#ifndef __NPC_WARPMAN_H__ +#define __NPC_WARPMAN_H__ + +void NPC_WarpManTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_WarpManInit( int meindex ); +void NPC_WarpManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_GetDuelRank(int rank,int msgid,int msgid2); +void NPC_WarpManLoop( int meindex); +void NPC_WarpManWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ); +#endif +/*__NPC_WARPMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare.h new file mode 100644 index 0000000..4aa9037 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare.h @@ -0,0 +1,10 @@ +#ifndef __NPC_WELFARE_H__ +#define __NPC_WELFARE_H__ + +BOOL NPC_WelfareInit( int meindex ); +void NPC_WelfareTalked( int meindex , int talker , char *msg ,int color ); +void NPC_WelfareWindowTalked(int meindex, int talkerindex, int seqno, int select,char *data); +void NPC_WelfareMakeStr(int meindex,int toindex,int select); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare2.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare2.h new file mode 100644 index 0000000..0bbb309 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_welfare2.h @@ -0,0 +1,9 @@ +#ifndef __NPC_WELFARE2_H__ +#define __NPC_WELFARE2_H__ + +BOOL NPC_WelfareInit2( int meindex ); +void NPC_WelfareTalked2( int meindex , int talker , char *msg ,int color ); +void NPC_WelfareWindowTalked2(int meindex, int talkerindex, int seqno, int select,char *data); +void NPC_WelfareMakeStr2(int meindex,int toindex,int select); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowhealer.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowhealer.h new file mode 100644 index 0000000..2c8f62a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowhealer.h @@ -0,0 +1,11 @@ +#ifndef __NPC_WINDOWHEALER_H__ +#define __NPC_WINDOWHEALER_H__ + +void NPC_WindowHealerTalked( int meindex , int talkerindex , char *msg , + int color ); +BOOL NPC_WindowHealerInit( int meindex ); +void NPC_WindowHealerWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); +void NPC_WindowHealerLooked( int meindex , int lookedindex); + +#endif + /*__NPC_WINDOWHEALER_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowman.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowman.h new file mode 100644 index 0000000..3cf1dde --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npc_windowman.h @@ -0,0 +1,16 @@ +#ifndef __NPC_WINDOWMAN_H__ +#define __NPC_WINDOWMAN_H__ + +void NPC_WindowmanTalked( int meindex , int talkerindex , char *msg , + int color ); + +BOOL NPC_WindowmanInit( int meindex ); +void NPC_WindowmanLooked( int meindex, int lookedindex ); +void NPC_WindowmanWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data); + +void NPC_Windowman_selectWindow( int meindex, int toindex, int num); +BOOL NPC_Windowman_readData( int meindex, int windowno, BOOL chkflg); +int NPC_Windowman_restoreButtontype( char *data ); + +#endif +/*__NPC_WINDOWMAN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npccreate.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npccreate.h new file mode 100644 index 0000000..a5aec6f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npccreate.h @@ -0,0 +1,102 @@ +#ifndef __READNPCCREATE_H__ +#define __READNPCCREATE_H__ + +#include "util.h" + +#define NPC_CREATEFILEMAGIC "NPCCREATE\n" + + +#undef EXTERN +#ifdef __NPCCREATE__ +#define EXTERN +#else +#define EXTERN extern +#endif /*__NPCCREATE__*/ + + +typedef enum +{ + NPC_CREATEFLOORID, /* ׷ʧID */ + NPC_CREATEBORNLEFTUPX, /* X */ + NPC_CREATEBORNLEFTUPY, /* Y */ + NPC_CREATEBORNRIGHTDOWNX, /* ƱX */ + NPC_CREATEBORNRIGHTDOWNY, /* ƱY */ + + NPC_CREATEMOVELEFTUPX, /* X */ + NPC_CREATEMOVELEFTUPY, /* Y */ + NPC_CREATEMOVERIGHTDOWNX, /* ƱX */ + NPC_CREATEMOVERIGHTDOWNY, /* ƱY */ + + NPC_CREATEDIR, /* ݼ */ + NPC_CREATEBASEIMAGENUMBER, /* template ɬë̤ + į */ + NPC_CREATETIME, /* */ + NPC_CREATEBORNNUM, /* ؽ */ + + NPC_CREATEENEMYNUM, /* ļ */ + NPC_CREATEBOUNDARY, + NPC_CREATEDATE, + NPC_CREATEIGNOREINVINCIBLE, + NPC_CREATEFAMILY, // Robin 0731 Family + +#ifdef _ADD_ACTION //jeffrey 1231 npcaction + NPC_CREATEACTION, +#endif + +#ifdef _NPC_AUTO_MOVE + NPC_AUTOMOVELEFTUPX, + NPC_AUTOMOVELEFTUPY, + NPC_AUTOMOVERIGHTDOWNX, + NPC_AUTOMOVERIGHTDOWNY, +#endif + + NPC_CREATEINTNUM, + +}NPC_CREATEINT; + +typedef enum +{ + NPC_CREATENAME, /* templateë̤¾ľئ */ + NPC_CREATECHARNUM, +}NPC_CREATECHAR; + + +typedef enum +{ + NPC_CREATEWORKENEMYNUM, + NPC_CREATEWORKMAKESTARTSEC, + NPC_CREATEWORKMAKESTARTUSEC, + NPC_CREATEWORKNEVERMAKE, + NPC_CREATEWORKNUM, + +}NPC_CREATEWORK; + +typedef struct tagNPC_Create +{ + int intdata[NPC_CREATEINTNUM]; + STRING64 chardata[NPC_CREATECHARNUM]; + int workdata[NPC_CREATEWORKNUM]; + int templateindex[8]; + STRING64 arg[8]; +}NPC_Create; + + +EXTERN NPC_Create* NPC_create; +EXTERN int NPC_createnum; +EXTERN int NPC_create_readindex; + +INLINE int NPC_CHECKCREATEINDEX(int index); + +BOOL NPC_isBoundarySet( int createindex ); +BOOL NPC_createGetRECT( int createindex,RECT* r ); +BOOL NPC_readNPCCreateFiles( char* topdirectory ,int createsize); +int NPC_getCreateInt( int index , NPC_CREATEINT element ); +int NPC_readCreateFile( char* filename ); +BOOL NPC_createCheckGenerateFromTime( int tindex ); +void NPC_createInitTime( int index ); +void NPC_createIncreaseEnemynum( int index ); +void NPC_createDecreaseEnemynum( int index ); +BOOL NPC_createCheckMaxEnemynum( int index ); + +#endif +/*__READNPCCREATE_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcgen.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcgen.h new file mode 100644 index 0000000..f7ab71a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcgen.h @@ -0,0 +1,13 @@ +#ifndef __NPCGEN_H__ +#define __NPCGEN_H__ + + +void NPC_generateLoop( BOOL FlgInit ); + +EXTERN int all_nosee; /* ༰ݣ廯ë no_see */ +EXTERN int all_nobody; /* ༰ݣ廯ë no_body */ +EXTERN int one_loop_born; /* ƥ Ϸ oneloop_born */ + + +#endif +/*__NPCGEN_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcserver.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcserver.h new file mode 100644 index 0000000..2798a55 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcserver.h @@ -0,0 +1,38 @@ +#ifndef _NPCSERVER_H +#define _NPCSERVER_H + + +int NSproto_DispatchMessage(int fd,char* encoded); +int connectNpcServer(char* hostname,unsigned short port); +void NPCS_SendProbe( int fd); + +typedef struct _NPCMessCommand +{ + char buf[4096]; + int len; + struct _NPCMessCommand *next; +}NPCMessC; + +BOOL NPCMESS_setChar( char *buf); +BOOL NPCMESS_getChar( char *buf, int len); +NPCMessC *MESS_getNew(); + + +void NPCS_AskNpcList_recv( int fd, char *Nlist); +void NPCS_AskNpcList_send( int fd); + +void NPCS_NpcSLogin_recv( int fd, char *Mess); +void NPCS_NpcSLogin_send( int fd); + +void NPCS_AskNpcTalk_send( int objindex, int npcsindex, int charaindex, char *Nlist); + +void NPCS_NpcTalkMess_recv( int npcobjindex, int charaindex, int charobjindex, char *TalkMess, int Color); +void NPCS_NpcWinMess_recv( int npcobjindex, int charaindex, int charobjindex, char *WinMess, + int seqno, int windowtype, int buttontype, int page); +void NPCS_NpcWinMess_send( int npcobjindex, int npcindex, int charaindex, char *WinMess, + int seqno, int select); +void NPCS_NpcCheckFreeMess_recv( int npcobjindex, int charaindex, int charobjindex, + char *CheckfreeMess); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npctemplate.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npctemplate.h new file mode 100644 index 0000000..48aa0f8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npctemplate.h @@ -0,0 +1,111 @@ +#ifndef __READNPCTEMPLATE_H__ +#define __READNPCTEMPLATE_H__ + +#include "util.h" +#include "char_base.h" + +#define NPC_TEMPLATEFILEMAGIC "NPCTEMPLATE\n" + +#undef EXTERN +#ifdef __NPCTEMPLATE__ +#define EXTERN +#else +#define EXTERN extern +#endif /*__NPCTEMPLATE__*/ + + + +typedef struct tagNPC_haveItem +{ + int itemnumber; + int haverate; + int havenum; +}NPC_haveItem; + +typedef enum +{ + NPC_TEMPLATENAME, /* */ + NPC_TEMPLATECHARNAME, /* */ + + NPC_TEMPLATEINITFUNC, /* CHAR_INITFUNC */ + NPC_TEMPLATEWALKPREFUNC, /* CHAR_WALKPREFUNC */ + NPC_TEMPLATEWALKPOSTFUNC, /* CHAR_WALKPOSTFUNC */ + NPC_TEMPLATEPREOVERFUNC, /* CHAR_PREOVERFUNC */ + NPC_TEMPLATEPOSTOVERFUNC, /* CHAR_POSTOVERFUNC */ + NPC_TEMPLATEWATCHFUNC, /* CHAR_WATCHFUNC */ + NPC_TEMPLATELOOPFUNC, /* CHAR_LOOPFUNC */ + NPC_TEMPLATEDYINGFUNC, /* CHAR_DYINGFUNC */ + NPC_TEMPLATETALKEDFUNC, /* CHAR_TALKEDFUNC */ + + NPC_TEMPLATEPREATTACKEDFUNC, /* CHAR_PREATTACKEDFUNC */ + NPC_TEMPLATEPOSTATTACKEDFUNC, /* CHAR_POSTATTACKEDFUNC */ + + NPC_TEMPLATEOFFFUNC, /* CHAR_OFFFUNC */ + NPC_TEMPLATELOOKEDFUNC, /* CHAR_LOOKEDFUNC */ + NPC_TEMPLATEITEMPUTFUNC, /* CHAR_ITEMPUTFUNC */ + + NPC_TEMPLATESPECIALTALKEDFUNC, /* CHAR_SPECIALTALKEDFUNC */ + NPC_TEMPLATEWINDOWTALKEDFUNC, /* CHAR_WINDOWTALKEDFUNC */ +#ifdef _USER_CHARLOOPS + NPC_TEMPLATELOOPFUNCTEMP1, //CHAR_LOOPFUNCTEMP1, + NPC_TEMPLATELOOPFUNCTEMP2, //CHAR_LOOPFUNCTEMP2, + NPC_TEMPLATEBATTLEPROPERTY, //CHAR_BATTLEPROPERTY, +#endif + NPC_TEMPLATECHARNUM, +}NPC_TEMPLATECHAR; + +typedef enum +{ + NPC_TEMPLATEMAKEATNOBODY, /* ئݱ¾ */ + NPC_TEMPLATEMAKEATNOSEE, /* έئƥ¾ */ + NPC_TEMPLATEIMAGENUMBER, /* į */ + NPC_TEMPLATETYPE, /* 裻ݱ裻 */ + + NPC_TEMPLATEMINHP, /* HP */ + + NPC_TEMPLATEMINMP, /* MP */ + + NPC_TEMPLATEMINSTR, /* STR */ + + NPC_TEMPLATEMINTOUGH, /* TOUGH */ + + NPC_TEMPLATEISFLYING, /* ƥ¾ */ + + NPC_TEMPLATEITEMNUM, /* еʧ ة */ + + NPC_TEMPLATELOOPFUNCTIME, /* + * + * ëپ + */ + NPC_TEMPLATEFUNCTIONINDEX, /* + * fucntionSet + * ̼͵ + */ + + NPC_TEMPLATEINTNUM, +}NPC_TEMPLATEINT; + +typedef struct tagNPC_Template +{ + STRING64 chardata[NPC_TEMPLATECHARNUM]; + int intdata[NPC_TEMPLATEINTNUM]; + int randomdata[NPC_TEMPLATEINTNUM]; /* ¼ĸة + Ȼ */ + int hash; + NPC_haveItem* haveitem; +}NPC_Template; + + +EXTERN NPC_Template* NPC_template; +EXTERN int NPC_templatenum; +EXTERN int NPC_template_readindex; + +INLINE int NPC_CHECKTEMPLATEINDEX(int index); + +BOOL NPC_copyFunctionSetToChar( int id, Char* ch ); + +BOOL NPC_readNPCTemplateFiles( char* topdirectory ,int templatesize); +int NPC_templateGetTemplateIndex( char* templatename ); + +#endif + /*__READNPCTEMPLATE_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcutil.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcutil.h new file mode 100644 index 0000000..1775907 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/npcutil.h @@ -0,0 +1,90 @@ +#ifndef _NPCUTIL_H_ +#define _NPCUTIL_H_ + +BOOL NPC_Util_AddOneTitle( int charindex, int titleindex ); +BOOL NPC_Util_HaveTitle( int charindex , int titleindex ); +BOOL NPC_Util_Nearby( int x1 , int y1, int x2 , int y2 ); +BOOL NPC_Util_CharNearby(int ind1,int ind2); +int NPC_Util_YN(char *input ); +int NPC_Util_getDirFromTwoPoint( POINT* pstart, POINT* pend ); +int NPC_Util_countHaveItem( int meindex , int itemid ); +BOOL NPC_Util_isBackContact( int frontindex , int backindex ); + +void NPC_Util_AnnounceFloor( int floorid , char *msg ); + + +BOOL NPC_Util_moveItemToChar( int charindex, int itemindex,BOOL net ); +BOOL NPC_Util_createItemToChar( int charindex, int itemid , BOOL net); +int NPC_Util_CharDistance( int index1, int index2 ); +int NPC_Util_SearchNear( int meindex, int maxlen, int type ); +int NPC_Util_SearchNearPlayer( int meindex, int maxlen ); +int NPC_Util_SearchNearEnemy( int meindex, int maxlen ); +int NPC_Util_SuberiWalk( int index, int dir ); +int NPC_Util_GetNumFromArg( int meindex, char* in); + +int NPC_Util_GetDirCharToChar( int fromindex, int toindex, int mode); +int NPC_Util_WalkCharToChar( int fromindex, int toindex, int mode, int suberi); +BOOL NPC_Util_isFaceToFace( int index1, int index2, int distance ); +BOOL NPC_Util_isFaceToChara( int index1, int index2, int distance ); +BOOL NPC_Util_charIsInFrontOfChar( int index1, int index2, int distance ); + +int NPC_Util_SearchItemInChar( int charindex , int itemindex); +int NPC_Util_GiveAllItemToChar( int give , int take ); +/* +int NPC_Util_ControlOtherNPC( CHAR_TYPE chartype , + char *npcname, + char *command ); +*/ +void NPC_Util_NPCDelete( int srcindex ); +BOOL NPC_Util_moveItemToMap( int itemindex , int fl , int x , int y, + BOOL net ); +char *NPC_Util_GetArgStr( int index, char *argstr, int len); +int NPC_Util_GetNumFromStrWithDelim( char *srcstr, char* in); +char *NPC_Util_GetStrFromStrWithDelim( char *srcstr, char *srhstr, + char *buf, int len); +inline double NPC_Util_sellRate( int seller ); +inline double NPC_Util_buyRate( int buyer ); +BOOL NPC_Util_IsVisiblePlayer( int meindex); +BOOL NPC_Util_WordInclude( char *text , char *word ); +void NPC_Util_RandomToken(char *in, char *out, int outbufsize ); + +void cutDotsTail( char *s ); +int NPC_Util_FrontItem( int meindex ); +void NPC_Util_Boss2KingStart( int bossindex ); +int NPC_Util_FrontChar( int meindex ); +int *NPC_Util_getEnemy( int meindex, int charaindex); + +void NPC_NowEndEventSetFlgCls(int talker,int shiftbit); +void NPC_EventSetFlg(int talker,int shiftbit); +BOOL NPC_EventCheckFlg(int point,int shiftbit); +void NPC_NowEventSetFlg(int talker,int shiftbit); +void NPC_NowEventSetFlgCls(int talker,int shiftbit); +BOOL NPC_NowEventCheckFlg(int point,int shiftbit); +char *NPC_Util_CheckAssignArgFile( int index, char *filename); + +// CoolFish: Family Adv 2001/8/4 +void AddFMAdv(int talker, int shiftbit); + +// Robin 0817 family income +int addNpcFamilyTax( int meindex, int talkerindex, int income ); +#ifdef _JZ_NEWSCRIPT_LUA +void NPC_EndEventSetFlgCls(int talker,int shiftbit); +#endif +#define NPC_ENEMY_ENEMYNUMBER 10 /* س */ + +/* ¦Ѱ̻ ļ漰 ٯ */ +#define NPC_UTIL_GETARGSTR_LINEMAX 4096 +/* ¦Ѱ̻P */ +#ifdef _NEWEVENT +//#define NPC_UTIL_GETARGSTR_BUFSIZE 1024*1200 +#define NPC_UTIL_GETARGSTR_BUFSIZE 1024*128 +#else +#define NPC_UTIL_GETARGSTR_BUFSIZE 1024*32 +#endif +#ifdef _NPC_EVENT_NOTICE +int getPlayerEventNoticeNo(int meindex,int talker); +#endif +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/object.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/object.h new file mode 100644 index 0000000..9718358 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/object.h @@ -0,0 +1,78 @@ +#ifndef __OBJECT_h__ +#define __OBJECT_h__ + +#include "common.h" + +typedef enum +{ + OBJTYPE_NOUSE, /* ̼͵Ȼئеë*/ + OBJTYPE_CHARA, /* ƽҷ CHAR_chara߼̼͵ */ + OBJTYPE_ITEM, /* ʧ ة ITEM_item ߼̼͵ */ + OBJTYPE_GOLD, /* żڻindex Ȼ */ +#ifdef _MAP_WARPPOINT + OBJTYPE_WARPPOINT, +#endif + OBJTYPE_NUM +}OBJTYPE; + +typedef struct tagObject +{ + OBJTYPE type; + + char objname[256]; + int npcsindex; + int dir; + int imagenum; + + int chartype; + int index; + int x; + int y; + int floor; +#ifdef _DEL_DROP_GOLD + int time; +#endif +}Object; + +BOOL CHECKOBJECT( int index ); +BOOL CHECKOBJECTUSE( int index ); +BOOL initObjectArray( int num ); +BOOL endObjectArray( void ); + +INLINE int _initObjectOne( char *file, int line, Object* ob ); +#define initObjectOne( ob ) _initObjectOne( __FILE__, __LINE__, ob) + +void endObjectOne( int index ); +int initObjectFromObjectMember(OBJTYPE type, int index, int x, int y , int floor ); + +INLINE int OBJECT_getType( int index ); +INLINE int OBJECT_setType( int index, int newvalue ); +INLINE int OBJECT_getFloor( int index ); +INLINE int OBJECT_setFloor( int index, int newvalue ); +INLINE int OBJECT_getX( int index ); +INLINE int OBJECT_setX( int index, int newvalue ); +INLINE int OBJECT_getY( int index ); +INLINE int OBJECT_setY( int index, int newvalue ); +INLINE int OBJECT_getIndex( int index ); +INLINE int OBJECT_setIndex( int index, int newvalue ); +INLINE int OBJECT_getNum( void ); + +INLINE int OBJECT_getchartype( int index ); +INLINE void OBJECT_setchartype( int index, int flg); + +#ifdef _PET_ITEM +BOOL storeObjects( char* dirname ); +BOOL restoreObjects( char* dirname ); +#endif + +#ifdef _DEL_DROP_GOLD +INLINE int OBJECT_setTime( int index, int newvalue ); +INLINE int OBJECT_getTime( int index ); +#endif + +int searchObjectFromCharaIndex( int index ); +#ifdef _MO_LNS_MAPSUOXU +INLINE int get_mappointindex( int fl, int x,int y ); +#endif +#endif +/*__OBJECT_h__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet.h new file mode 100644 index 0000000..d61c548 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet.h @@ -0,0 +1,32 @@ +#ifndef __PET_H__ +#define __PET_H__ + +/* + * ʸ ɬƥʣ + */ +#include "version.h" +#include "common.h" + +#define PETFEEDTIME 60*60 // ﵰιʱ() +//#define PETFEEDTIME 5 // ﵰιʱ() + +int PET_DEBUG_initPetOne( int charaindex); +int PET_dropPet( int charaindex, int havepetindex); +int PET_dropPetFollow( int charaindex, int havepetindex, int fl, int x, int y); +int PET_dropPetFLXY( int charaindex, int havepetindex, int fl, int x, int y); +int PET_dropPetAbsolute( int petindex, int floor, int x, int y,BOOL net); +int PET_createPetFromCharaIndex( int charaindex, int enemyindex); +BOOL PET_SelectBattleEntryPet( int charaindex, int petarray); +int PET_initCharOneArray( Char *ch); +BOOL PET_isPutPoint( int fl,int x, int y); + + +BOOL PET_getBaseForAllocpoint( int toindex, int *work); +void PET_showEditBaseMsg( int charaindex, int toindex, int itemindex, int *work); + +#ifdef _PET_EVOLUTION +BOOL PET_getBaseAndSkill( int charaindex, int baseindex, int *base, int *skill, int flg); +#endif +BOOL CHAR_DelPetForIndex( int charaindex, int petindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_event.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_event.h new file mode 100644 index 0000000..884320e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_event.h @@ -0,0 +1,18 @@ +#ifndef __PET_EVENT_H__ +#define __PET_EVENT_H__ + +/* + * ʸ ɬƥʣ + * ʸì + */ + +void PET_Talkfunc( int meindex, int talkerindex, char *msg, int color); + +void PET_Watchfunc( int objmeindex, int objmoveindex, + CHAR_ACTION act, int x, int y, int dir, + int* opt, int optlen ); +int PET_CleanPetdeletetime( int objmeindex); +void PET_CleanFreePetAll(); +void PET_CHECKFreePetIsIt( int petindex); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skill.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skill.h new file mode 100644 index 0000000..39ff88c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skill.h @@ -0,0 +1,596 @@ +#ifndef __PET_SKILL_H__ +#define __PET_SKILL_H__ + +#include "util.h" + +typedef enum +{ + PETSKILL_FIELD_ALL, /* ͻƥ */ + PETSKILL_FIELD_BATTLE, /* */ + PETSKILL_FIELD_MAP, /* ɧѨ */ + +}PETSKILL_FIELDTYPE; + +typedef enum +{ + PETSKILL_TARGET_MYSELF, /* м */ + PETSKILL_TARGET_OTHER, /* ְ ֳ) */ + PETSKILL_TARGET_ALLMYSIDE, /* */ + PETSKILL_TARGET_ALLOTHERSIDE, /* 촡 */ + PETSKILL_TARGET_ALL, /* 廯 */ + PETSKILL_TARGET_NONE, /* ּ ئУ ֧׻ */ + PETSKILL_TARGET_OTHERWITHOUTMYSELF,/* ְ ֳئ) */ + PETSKILL_TARGET_WITHOUTMYSELFANDPET, /* ʸ½ */ +}PETSKILL_TARGETTYPE; + +typedef enum +{ + PETSKILL_ID, + PETSKILL_FIELD, + PETSKILL_TARGET, +#ifdef _PETSKILL2_TXT + PETSKILL_USETYPE, +#endif + PETSKILL_COST, + PETSKILL_ILLEGAL, + PETSKILL_DATAINTNUM, +}PETSKILL_DATAINT; + +typedef enum +{ + PETSKILL_NAME, /* */ + PETSKILL_COMMENT, /* 춪*/ + PETSKILL_FUNCNAME, /* */ + PETSKILL_OPTION, /* */ +#ifdef _CFREE_petskill + PETSKILL_FREE, /**/ + PETSKILL_KINDCODE, /**/ +#endif + + PETSKILL_DATACHARNUM, +}PETSKILL_DATACHAR; + +typedef struct tagPetskill +{ + int data[PETSKILL_DATAINTNUM]; + STRING64 string[PETSKILL_DATACHARNUM]; + +}Petskill; + +typedef int (*PETSKILL_CALLFUNC)( int, int, int, char * ); + +INLINE BOOL PETSKILL_CHECKINDEX( int index ); +INLINE int PETSKILL_getInt( int index, PETSKILL_DATAINT element); +INLINE int PETSKILL_setInt( int index, PETSKILL_DATAINT element, int data); +INLINE char* PETSKILL_getChar( int index, PETSKILL_DATACHAR element); +INLINE BOOL PETSKILL_setChar( int index ,PETSKILL_DATACHAR element, char* new ); +int PETSKILL_getPetskillNum( void); + +#define PETSKILL_GetArray( charaindex, havepetskill) _PETSKILL_GetArray( __FILE__, __LINE__, charaindex, havepetskill) +int _PETSKILL_GetArray( char *file, int line, int charaindex, int havepetskill ); + +BOOL PETSKILL_initPetskill( char *filename); +BOOL PETSKILL_reinitPetskill( void ); +int PETSKILL_getPetskillArray( int petskillid); +PETSKILL_CALLFUNC PETSKILL_getPetskillFuncPointer(char* name); + +int PETSKILL_Use( + int charaindex, + int toindex, + int array, + char *data + //BOOL isCLI // Robin 2001/02/26 if owner is player +); + +int PETSKILL_ContinuationAttack( + int charaindex, + int toindex, + int array, + char *data +); +int PETSKILL_ChargeAttack( + int charaindex, + int toindex, + int array, + char *data +); + + +#define PETSKILL_ID_GBREAK 0 // Ƥ +#define PETSKILL_ID_RENZOKU 1 // +#define PETSKILL_ID_GUARDIAN 2 // ˦ +#define PETSKILL_ID_CHARGE 3 // ҡ +#define PETSKILL_ID_ICHIGEKI 100 // ڽ +#define PETSKILL_ID_POWERBALANCE 110 // + +//********************************************************************** +// +// -- ְëԻئ +// +int PETSKILL_Guardian( + int charaindex, + int toindex, + int array, + char *data +); +// +//********************************************************************** + +int PETSKILL_PowerBalance( + int charaindex, + int toindex, + int array, + char *data +); + +//********************************************************************** +// +// -- ֻ ľ¸ +// +int PETSKILL_Mighty( + int charaindex, + int toindex, + int array, + char *data +); +// +//********************************************************************** + + +//********************************************************************** +// +// -- +// +int PETSKILL_StatusChange( + int charaindex, + int toindex, + int array, + char *data + +); +// +//********************************************************************** + + +//******************************************************* +// +// -- ɧ +// +int PETSKILL_NormalAttack( + int charaindex, + int toindex, + int array, + char *data + +); + + +#ifdef _INVERSION_PETSKILL +int PETSKILL_Inversion( + int charaindex, + int toindex, + int array, + char *data + +); +#endif + +#ifdef _MASSAGE_PETSKILL +int PETSKILL_Massage( + int charaindex, + int toindex, + int array, + char *data + +); +#endif + +#ifdef _PETOUT_PETSKILL +int PETSKILL_Petout( + int charaindex, + int toindex, + int array, + char *data + +); +#endif + +// +//******************************************************* + +//******************************************************* +// +// -- ɧ +// +int PETSKILL_NormalGuard( + int charaindex, + int toindex, + int array, + char *data + +); +// +//******************************************************* + +//******************************************************* +// -- (ئ) +// +int PETSKILL_None( + int charaindex, + int toindex, + int array, + char *data + +); +// +//******************************************************* + +//******************************************************* +// -- (ľ 켰 ) +// +int PETSKILL_EarthRound( + int charaindex, + int toNo, + int array, + char *data + +); +// +//******************************************************* + +//******************************************************* +// -- Ƥ +// +int PETSKILL_GuardBreak( + int charaindex, + int toNo, + int array, + char *data + +); +/////////////////////////////////////////// +#ifdef _SKILL_GUARDBREAK2//Ƴ2 vincent add 2002/05/20 +int PETSKILL_GuardBreak2( + int charaindex, + int toNo, + int array, + char *data + +); +#endif +// +//******************************************************* +//******************************************************* +// -- ľ +// +int PETSKILL_Abduct( + int charaindex, + int toNo, + int array, + char *data + +); +// +//******************************************************* +//******************************************************* +// -- +int PETSKILL_Steal( + int charaindex, + int toNo, + int array, + char *data + +); +//******************************************************* +#ifdef _BATTLESTEAL_FIX +int PETSKILL_StealMoney( + int charaindex, + int toNo, + int array, + char *data + +); +#endif + +#ifdef _ITEM_INSLAY +int PETSKILL_Inslay( + int index, + int toNo, + int array, + char *data + +); +#endif + +#ifdef _PETSKILL_FIXITEM +int PETSKILL_Fixitem( + int index, + int toNo, + int array, + char *data + +); +#endif + +// -- ʧ ة +// +int PETSKILL_Merge( + int charaindex, + int toNo, + int array, + char *data + +); +// +//******************************************************* + +//******************************************************* +// -- á +// +int PETSKILL_NoGuard( + int charaindex, + int toNo, + int array, + char *data + +); +// +//******************************************************* + + + +// Terry add 2001/11/05 +#ifdef _ATTACK_MAGIC +int PETSKILL_AttackMagic( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _VARY_WOLF +int PETSKILL_Vary( int cindex, int tindex, int id, char* data); +#endif + +#ifdef _SKILL_WILDVIOLENT_ATT +//vincent add 2002/05/16 +int PETSKILL_WildViolentAttack( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_SPEEDY_ATT +//vincent add 2002/05/16 +int PETSKILL_SpeedyAttack( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_SACRIFICE +//vincent add 2002/05/30 +int PETSKILL_Sacrifice( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_REFRESH +//vincent add 2002/08/08 +int PETSKILL_Refresh( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_WEAKEN //vincent輼: +int PETSKILL_Weaken( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_DEEPPOISON //vincent輼:綾 +int PETSKILL_Deeppoison( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_BARRIER //vincent輼:ħ +int PETSKILL_Barrier( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_NOCAST //vincent輼:Ĭ +int PETSKILL_Nocast( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _SKILL_ROAR //vincent輼: +int PETSKILL_Roar( + int charaindex, + int toindex, + int array, + char *data +); +#endif + +#ifdef _PSKILL_FALLGROUND +int PETSKILL_FallGround( int charaindex, int toNo, int array, char *data ); +#endif +#ifdef _PETSKILL_EXPLODE +int PETSKILL_Explode( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PRO_BATTLEENEMYSKILL +int ENEMYSKILL_ReLife( int enemyindex, int toNo, int array, char *data ); +int ENEMYSKILL_ReHP( int enemyindex, int toNo, int array, char *data ); + +int ENEMYSKILL_EnemyHelp( int enemyindex, int toNo, int array, char *data ); +#endif + +#ifdef _SKILL_DAMAGETOHP +int PETSKILL_DamageToHp( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_TIMID +int PETSKILL_BattleTimid( int charaindex, int toNo, int array, char *data ); +#endif +#ifdef _PETSKILL_2TIMID +int PETSKILL_2BattleTimid( int charaindex, int toNo, int array, char *data ); +#endif +#ifdef _PETSKILL_ANTINTER +int PETSKILL_AntInter(int charaindex, int toindex, int array, char* data); // \սģ +#endif + +#ifdef _RESURRECTION_PETSKILL +int PETSKILL_Resurrection( int charaindex, int toNo, int array, char* data); +#endif +#ifdef _LOSTLOST_PETSKILL +int PETSKILL_Lostlost( int charaindex, int toNo, int array, char* data); +#endif + + +#ifdef _PETSKILL_PROPERTY +int PETSKILL_BattleProperty( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_TEAR +int PETSKILL_BattleTearDamage( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _BATTLE_LIGHTTAKE +int PETSKILL_Lighttakeed( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _BATTLE_ATTCRAZED +int PETSKILL_AttackCrazed( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 +int PETSKILL_AttackShoot( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _Skill_MPDAMAGE +int PETSKILL_MpDamage( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_SETDUCK +int PETSKILL_SetDuck( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _MAGICPET_SKILL +int PETSKILL_SetMagicPet( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _SKILL_TOOTH +int PETSKILL_ToothCrushe( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PSKILL_MODIFY +int PETSKILL_Modifyattack( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PSKILL_MDFYATTACK +int PETSKILL_Mdfyattack( int charaindex, int toNo, int array, char *data ); +#endif + + +#ifdef _MAGIC_SUPERWALL +int PETSKILL_MagicStatusChange( int charaindex, int toindex, int array, char *data ); +#endif + +#ifdef _PET_SKILL_SARS // WON ADD ɷ +int PETSKILL_Sars( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _SONIC_ATTACK // WON ADD +int PETSKILL_Sonic( int charaindex, int toNo, int array, char *data ); +#endif +#ifdef _PETSKILL_REGRET +int PETSKILL_Regret( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_GYRATE +int PETSKILL_Gyrate( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_ACUPUNCTURE //Ƥ +int PETSKILL_Acupuncture( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_RETRACE +int PETSKILL_Retrace( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_HECTOR +int PETSKILL_Hector( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_FIREKILL +int PETSKILL_Firekill( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_DAMAGETOHP //¿(Ѫı) +int PETSKILL_DamageToHp2( int charaindex, int toNo, int array, char *data ); +#endif + +#ifdef _PETSKILL_BECOMEFOX +int PETSKILL_BecomeFox( int charaindex, int toNo, int array, char* data); +#endif + +#ifdef _PETSKILL_BECOMEPIG +int PETSKILL_BecomePig( int charaindex, int toNo, int array, char* data); +#endif + +#ifdef _PETSKILL_SHOWMERCY +int PETSKILL_ShowMercy(int charaindex, int toNo, int array, char* data); +#endif + +#ifdef _PETSKILL_COMBINED +int PETSKILL_Combined(int charaindex, int toNo, int array, char* data); +#endif + +#ifdef _PETSKILL_LER +int PETSKILL_BatFly(int charaindex, int toNo, int array, char* data); // ׶ - ȺĴ +int PETSKILL_DivideAttack(int charaindex, int toNo, int array, char* data); // ׶ - +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +int PETSKILL_BattleModel(int charaindex, int toindex, int array, char* data); // \սģ +#endif + +#ifdef _STRENGTH_PETSKILL +int PETSKILL_Strength( int charaindex, int toNo, int array, char *data ); +#endif +#ifdef _GRAPPLING_PETSKILL +int PETSKILL_Grappling( int charaindex, int toNo, int array, char* data); +#endif +#ifdef _PETSKILL_PASSIVE_PET_MATCH1 //ﵥϱ +int PETSKILL_PASSIVE_PET_MATCH1( int charaindex, int toNo, int array, char *data ); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skillinfo.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skillinfo.h new file mode 100644 index 0000000..db735e1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/pet_skillinfo.h @@ -0,0 +1,139 @@ +/* generated by makedefs.perl */ +#include "version.h" + +#define PETSKILL_NONE ( 0 ) +#define PETSKILL_NORMALATTACK ( 1 ) +#define PETSKILL_NORMALGUARD ( 2 ) +#define PETSKILL_GUARDBREAK ( 3 ) +#define PETSKILL_CONTINUATIONATTACK1 ( 10 ) +#define PETSKILL_CONTINUATIONATTACK2 ( 11 ) +#define PETSKILL_CONTINUATIONATTACK3 ( 12 ) +#define PETSKILL_CONTINUATIONATTACK4 ( 13 ) +#define PETSKILL_GUARDIAN ( 25 ) +#define PETSKILL_CHARGE1 ( 30 ) +#define PETSKILL_CHARGE2 ( 31 ) +#define PETSKILL_MIGHTY1 ( 40 ) +#define PETSKILL_MIGHTY2 ( 41 ) +#define PETSKILL_POWERBALANCE1 ( 50 ) +#define PETSKILL_POWERBALANCE2 ( 51 ) +#define PETSKILL_POWERBALANCE3 ( 52 ) +#define PETSKILL_POISON_ATTACK1 ( 60 ) +#define PETSKILL_POISON_ATTACK2 ( 61 ) +#define PETSKILL_STONE ( 80 ) +#define PETSKILL_CONFUSION_ATTACK ( 90 ) +#define PETSKILL_DRUNK_ATTACK ( 100 ) +#define PETSKILL_SLEEP_ATTACK ( 110 ) +#define PETSKILL_EARTHROUND1 ( 120 ) +#define PETSKILL_Abduct ( 130 ) +#define PETSKILL_STEAL ( 140 ) +#define PETSKILL_NOGUARD1 ( 150 ) +#define PETSKILL_NOGUARD2 ( 151 ) +#define PETSKILL_NOGUARD3 ( 152 ) +#define PETSKILL_MERGE ( 200 ) +#define PETSKILL_MERGE2 ( 201 ) +#ifdef _ALCHEMIST +#define PETSKILL_ALCHEMIST ( 202 ) +#endif +#ifdef _PSKILL_FALLGROUND +#define PETSKILL_FALLGROUND ( 210 ) +#endif +#ifdef _BATTLESTEAL_FIX +#define PETSKILL_STEALMONEY ( 211 ) +#endif +#ifdef _PRO_BATTLEENEMYSKILL +#define ENEMYSKILL_RELIFES ( 500 ) +#define ENEMYSKILL_RELIFHP ( 501 ) +#define ENEMYSKILL_HELP ( 502 ) +#endif +#ifdef _SKILL_DAMAGETOHP +#define PETSKILL_DAMAGETOHP ( 503) +#endif +#ifdef _Skill_MPDAMAGE +#define PETSKILL_MPDAMAGE ( 504) +#endif +#ifdef _SKILL_WILDVIOLENT_ATT +#define PETSKILL_WILDVIOLENTATTACK ( 540)// vincent add 2002/05/16 +#endif +#ifdef _SKILL_SPEEDY_ATT +#define PETSKILL_SPEEDYATTACK ( 541) // vincent add 2002/05/16 +#endif +#ifdef _SKILL_GUARDBREAK2 +#define PETSKILL_GUARDBREAK2 ( 542) //Ƴ2 vincent add 2002/05/20 +#endif +#ifdef _SKILL_SACRIFICE +#define PETSKILL_SACRIFICE ( 543) //Ԯ vincent add 2002/05/30 +#endif + +#ifdef _SKILL_WEAKEN +#define PETSKILL_WEAKEN ( 544) // vincent add 2002/07/11 +#endif + +#ifdef _SKILL_DEEPPOISON +#define PETSKILL_DEEPPOISON ( 545) //綾 vincent add 2002/07/16 +#endif + +#ifdef _SKILL_BARRIER +#define PETSKILL_BARRIER ( 546) //ħ vincent add 2002/07/16 +#endif + +#ifdef _SKILL_NOCAST +#define PETSKILL_NOCAST ( 547) //Ĭ vincent add 2002/07/16 +#endif + + +#ifdef _SKILL_ROAR +#define PETSKILL_ROAR ( 548) // vincent add 2002/07/11 +#endif + +#ifdef _ITEM_INSLAY +#define PETSKILL_INSLAY (572) +#endif + +#ifdef _PETSKILL_FIXITEM +#define PETSKILL_FIXITEM (573) +#endif + +#ifdef _SKILL_TOOTH +#define PETSKILL_TOOTHCRUSHE (574) +#endif + +#ifdef _SKILL_REFRESH +#define PETSKILL_REFRESH ( 575) //vincent add 2002/08/08 +#endif + +#ifdef _VARY_WOLF +#define PETSKILL_VARY ( 600 ) +#endif + +#ifdef _PETSKILL_SETDUCK +#define PETSKILL_SETDUCK ( 600 ) +#endif + +#ifdef _MAGICPET_SKILL +#define PETSKILL_SETMAGICPET ( 601 ) +#endif + +#ifdef _BATTLE_LIGHTTAKE +#define PETSKILL_Light ( 608) +#endif + +#ifdef _BATTLE_ATTCRAZED +#define PETSKILL_AttCrazed ( 608) +#endif + +#ifdef _SHOOTCHESTNUT // Syu ADD 輼 +#define PETSKILL_AttShoot ( 609 ) +#endif + +#ifdef _PETSKILL_BECOMEPIG +#define PETSKILL_BECOMEPIG ( 628 ) +#endif + +#ifdef _PETSKILL_LER +#define PETSKILL_BATFLY ( 633 ) +#define PETSKILL_DIVIDEATTACK ( 634 ) +#endif + +#ifdef _PETSKILL_BATTLE_MODEL +#define PETSKILL_BATTLE_MODEL ( 635 ) +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/petmail.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/petmail.h new file mode 100644 index 0000000..abf6026 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/petmail.h @@ -0,0 +1,57 @@ +#ifndef __PETMAIL_H__ +#define __PETMAIL_H__ +#include "version.h" +/* + * ʸ ɬƥʣ + */ +#define PETMAIL_OFFMSG_MAX 10000 +#define PETMAIL_OFFMSG_TIMEOUT ( 3 * 24 * 3600 ) +#define PETMAIL_CHECK_OFFMSG_EXPIRE_INTERVAL 3600 +#define PETMAIL_OFFMSG_TEXTLEN 512 + +/* ʸPضѣ ˼ѷԻئ³ */ +#define PETMAIL_EFFECTMAX 1 + +#define PETMAIL_SPOOLFLOOR 777 +#define PETMAIL_SPOOLX 30 +#define PETMAIL_SPOOLY 30 + +#define PETMAIL_LOOPINTERVAL1 500 +#define PETMAIL_LOOPINTERVAL2 2000 + +/* ׷̼ƽҷ³߼ë */ +typedef struct +{ + int use; + time_t send_tm; /* ǻë˪+TIMEOUT */ + int color; /* ƽ */ + char text[PETMAIL_OFFMSG_TEXTLEN]; /* ƽ */ + char destcd[CDKEYLEN]; /* ˪CDKEY */ + char destcharname[CHARNAMELEN]; /* ˪Ƽƽҷ */ + char srccd[CDKEYLEN]; /* ˪缰cdkey */ + char srccharname[CHARNAMELEN]; /* ˪缰ƽҷ */ + +} PETMAIL_offmsg; + +void PETMAIL_Loopfunc( int index); +BOOL PETMAIL_CheckPlayerExist( int index, int mode); + +BOOL PETMAIL_initOffmsgBuffer( int count ); +BOOL PETMAIL_addOffmsg( int fromindex, char *tocdkey, char *tocharaname, + char *text, int color ); +PETMAIL_offmsg *PETMAIL_getOffmsg( int offmsgindex); +BOOL PETMAIL_deleteOffmsg( int offmsgindex); +void PETMAIL_proc( void ); +BOOL storePetmail( void); +BOOL PETMAIL_sendPetMail( int cindex, int aindex, + int havepetindex, int haveitemindex, char* text , int color ); + +#ifdef _PETMAIL_DEFNUMS +void CHAR_AutoPickupMailPet( int charaindex, int petindex ); +#endif +int PETMAIL_getPetMailTotalnums( void); +void PETMAIL_delPetMailTotalnums( int numflg); +void PETMAIL_setPetMailTotalnums( int numflg); +int PETMAIL_CheckIsMyOffmsg( int fromindex, char *tocdkey, char *tocharaname); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/profession_skill.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/profession_skill.h new file mode 100644 index 0000000..3606c73 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/profession_skill.h @@ -0,0 +1,165 @@ +#include "version.h" + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "common.h" +#include "util.h" +#include "skill.h" + +#define PROFESSION_MAX_LEVEL 26 // ְҵȼ 26 +#define PROFESSION_SKILL_MAX_LEVEL 100 // ܵȼ 100 +#define PROFESSION_SKILL_ADD_POINT 1 // 춨ͨӾֵ +// ְҵ +typedef enum +{ + PROFESSION_CLASS_NONE=0, // ְҵ + PROFESSION_CLASS_FIGHTER, // ʿ + PROFESSION_CLASS_WIZARD, // ʦ + PROFESSION_CLASS_HUNTER, // + PROFESSION_CLASS_NUM, +}PROFESSION_CLASS_TYPE; + +typedef enum +{ + PROFESSION_SKILL_NAME, // + PROFESSION_SKILL_TXT, // ˵ + PROFESSION_SKILL_FUNCNAME, // ʹú + PROFESSION_SKILL_OPTION, // + PROFESSION_SKILL_DATACHARNUM, +}PROFESSION_SKILL_DATACHAR; + + +typedef enum +{ + PROFESSION_SKILL_ID, // ܱ + PROFESSION_SKILL_PROFESSION_CLASS, // ְҵ + PROFESSION_SKILL_TARGET, // Ŀ + PROFESSION_SKILL_COST_MP, // ķMP + PROFESSION_SKILL_USE_FLAG, // ʹ + PROFESSION_SKILL_KIND, // + PROFESSION_SKILL_ICON, // ICONͼ + PROFESSION_SKILL_IMG_1, // ǰͼ(״̬) + PROFESSION_SKILL_IMG_2, // ͼ() + PROFESSION_SKILL_COST, // + PROFESSION_SKILL_FIX_VALUE, // ֵ + + //ɫѧϰ趨Ⱦﵽʱſѧϰ + PROFESSION_SKILL_LIMIT1, // ޼ 1 + PROFESSION_SKILL_PERCENT1, // ޼Ӧ% 1 + PROFESSION_SKILL_LIMIT2, // ޼ 2 + PROFESSION_SKILL_PERCENT2, // ޼Ӧ% 2 + PROFESSION_SKILL_LIMIT3, // ޼ 3 + PROFESSION_SKILL_PERCENT3, // ޼Ӧ% 3 + PROFESSION_SKILL_LIMIT4, // ޼ 4 + PROFESSION_SKILL_PERCENT4, // ޼Ӧ% 4 + PROFESSION_SKILL_DATAINTNUM, +}PROFESSION_SKILL_DATAINT; + + +typedef struct tagProfessionkill +{ + STRING64 string[PROFESSION_SKILL_DATACHARNUM]; + int data[PROFESSION_SKILL_DATAINTNUM]; +}Professionskill; + + +//---------------------------------------------------------------------------- +typedef int (*PROFESSION_SKILL_CALLFUNC)( int, int, int, char *, int ); +BOOL PROFESSION_initSkill( char *filename); +void rePROFESSION_initSkill(); + +//---------------------------------------------------------------------------- +INLINE BOOL PROFESSION_SKILL_CHECKINDEX( int index ); +INLINE int PROFESSION_SKILL_getInt( int index, PROFESSION_SKILL_DATAINT element); +INLINE int PROFESSION_SKILL_setInt( int index, PROFESSION_SKILL_DATAINT element, int data); +INLINE char* PROFESSION_SKILL_getChar( int index, PROFESSION_SKILL_DATACHAR element); +INLINE BOOL PROFESSION_SKILL_setChar( int index ,PROFESSION_SKILL_DATACHAR element, char* new ); +int PROFESSION_SKILL_getskillNum( void ); + +//---------------------------------------------------------------------------- +int PROFESSION_SKILL_getskillArray( int skillid); +PROFESSION_SKILL_CALLFUNC PROFESSION_SKILL_getskillFuncPointer(char* name ); +#define PROFESSION_SKILL_GetArray( charaindex, skill) _PROFESSION_SKILL_GetArray( __FILE__, __LINE__, charaindex, skill) +int _PROFESSION_SKILL_GetArray( char *file, int line, int charaindex, int skill ); +int PROFESSION_SKILL_Use( int charaindex, int skill, int toNo, char *data ); +void PROFESSION_SKILL_LVEVEL_UP( int charaindex, char *name ); +void PROFESSION_LEVEL_CHECK_UP( int charaindex ); +void PROFESSION_NORMAL_SKILL_LEVLE_UP(Skill* skill, int Pskillid, int charaindex ); +void PROFESSION_SKILL_WEAPON_FOCUS_LVEVEL_UP( int charaindex, char *name ); +void PROFESSION_SKILL_DUAL_WEAPON_LVEVEL_UP( int charaindex, char *name ); +int PROFESSION_SKILL_DEC_COST_MP( int charaindex, int skill, int Pskillid, int skill_level ); +int PROFESSION_SKILL_ADDSK( int charaindex, int skill, int level ); + +//---------------------------------------------------------------------------- +// ְҵ +void profession_common_fun( int charaindex, int toNo, int skill_level, int array, int com1 ); +int PROFESSION_brust( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_chain_atk( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_avoid( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_recovery( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_weapon_focus( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_volcano_springs( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_fire_ball( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_fire_spear( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_summon_thunder( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_current( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_storm( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_ice_arrow( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_ice_crack( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_ice_mirror( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_doom( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_blood( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_blood_worms( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_sign( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_fire_enclose( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_ice_eclose( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_thunder_enclose( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_fire_practice( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_ice_practice( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_thunder_practice( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_enclose( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_transpose( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_reback( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_chain_atk_2( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_scapegoat( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_enrage( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_energy_collect( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_focus( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_shield_attack( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_dual_weapon( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_deflect( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_through_attack( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_cavalry( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_dead_attack( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_convolute( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_chaos( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_docile( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_trap( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_enrage_pet( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_dragnet( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_entwine( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_autarky( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_plunder( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_toxin_weapon( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_resist_fire( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_resist_ice( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_resist_thunder( int charaindex, int toindex, int array, char *data, int skill_level ); +#ifdef _PROFESSION_ADDSKILL +int PROFESSION_resist_f_i_t( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_call_nature( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_boundary( int charaindex, int toindex, int array, char *data, int skill_level ); +#endif +int PROFESSION_attack_weak( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_instigate( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_track( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_oblivion( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_full_mp( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_strong_back( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_strengthen( int charaindex, int toindex, int array, char *data, int skill_level ); +int PROFESSION_escape( int charaindex, int toNo, int array, char *data, int skill_level ); +int PROFESSION_g_resist_fire( int charaindex, int toNo, int array, char *data, int skill_level ); +int PROFESSION_g_resist_ice( int charaindex, int toNo, int array, char *data, int skill_level ); +int PROFESSION_g_resist_thunder( int charaindex, int toNo, int array, char *data, int skill_level ); + +//---------------------------------------------------------------------------- + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/readmap.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/readmap.h new file mode 100644 index 0000000..851ca74 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/readmap.h @@ -0,0 +1,171 @@ +#ifndef __MAP_H__ +#define __MAP_H__ +#include "common.h" +#include "util.h" + +typedef struct tagMAP_Objlink +{ + int objindex; + struct tagMAP_Objlink* next; +}MAP_Objlink, *OBJECT; + +#define GET_OBJINDEX(x) ((x)->objindex) +#define NEXT_OBJECT(x) ((x)->next) + +typedef struct tagMAP_Map +{ + int id; /* ID */ + int xsiz,ysiz; /* */ + char string[64]; /* ʾ */ + unsigned short* tile; /* */ + unsigned short* obj; /* */ + MAP_Objlink** olink; +#ifdef _MAP_NOEXIT + unsigned int startpoint; + int MapType; +#endif +}MAP_Map; + +typedef enum +{ + MAP_WALKABLE, /* + * + * ? Q 0 + * ? M 1 + * ? M 2 + */ + MAP_HAVEHEIGHT, /* 0 0 */ + MAP_DEFENCE, /* \ ر0 \ */ + + MAP_INTODAMAGE, /* ʱ HP ? */ + MAP_OUTOFDAMAGE, /* ʱ HP ? */ + + MAP_SETED_BATTLEMAP, /* 趨? */ + MAP_BATTLEMAP, /* A */ + MAP_BATTLEMAP2, /* A */ + MAP_BATTLEMAP3, /* A */ + +/* ̣ӣ ʹ ӣ ʹ (? X ? @) */ + + MAP_INTODARKNESS, /* ʱ */ + MAP_INTOCONFUSION, /* ʱ ? */ + + MAP_OUTOFPOISON, /* ʱ */ + MAP_OUTOFPARALYSIS, /* ʱ */ + MAP_OUTOFSILENCE, /* ʱ ? */ + MAP_OUTOFSTONE, /* ʱ ʯ */ + MAP_OUTOFDARKNESS, /* ʱ */ + MAP_OUTOFCONFUSION, /* ʱ ? */ + + MAP_DATAINT_NUM, +}MAP_DATAINT; +typedef enum +{ + MAP_DATACHAR_NUM, +}MAP_DATACHAR; +typedef struct tagMAP_ImageData +{ + int data[MAP_DATAINT_NUM]; + STRING32 string[MAP_DATACHAR_NUM]; +}MAP_ImageData; + +typedef enum +{ + MAP_KINDWALKABLE, /* ? F 1 */ + + MAP_KINDNUM, +}MAP_kind; + + +INLINE int MAP_getfloorIndex( int floorid ); +int MAP_getfloorX( int floorid ); +int MAP_getfloorY( int floorid ); + +BOOL MAP_initReadMap( char* maptilefile , char* mapdir ); +BOOL MAP_initMapArray( int num ); +void MAP_endMapArray( void ); + +char* MAP_getdataFromRECT( int floor, RECT* seekr, RECT* realr ); +char *MAP_getChecksumFromRECT( int floor, RECT* seekr, RECT* realr, + int *tilesum, int *objsum, int *eventsum ); + +BOOL MAP_checkCoordinates( int mapid, int x, int y ); + +BOOL MAP_setTileAndObjData( int ff ,int fx, int fy, int tile, int obj); +BOOL MAP_getTileAndObjData( int ff ,int fx, int fy, int* tile, int* obj); +void MAP_sendAroundMapdata( int fl, int x, int y); +int MAP_getImageInt( int imagenumber, int element ); +BOOL MAP_setImageInt( int imagenumber, int element, int value ); +BOOL IsValidImagenumber( int imagenumber ); + +char* MAP_getfloorShowstring( int floorid ); +BOOL MAP_makeVariousMap(char* atile, char* aobj, int floor, int startx, int starty, int xsiz, int ysiz, MAP_kind kind ); +BOOL MAP_makeWalkableMap( char* data, int floor, int startx, int starty,int xsiz, int ysiz ); +BOOL MAP_IsThereSpecificFloorid( int floorid ); +BOOL MAP_IsValidCoordinate( int floorid, int x, int y ); + +BOOL MAP_addNewObj( int floor, int x, int y, int objindex ); +BOOL MAP_removeObj( int floor, int x, int y, int objindex ); +#define MAP_getTopObj( fl, x, y) _MAP_getTopObj( __FILE__, __LINE__, fl, x, y) +MAP_Objlink* _MAP_getTopObj( char *file, int line, int floor, int x, int y ); +#define MAP_objmove( objindex, of, ox, oy, nfl, nx, ny) _MAP_objmove( __FILE__, __LINE__, objindex, of, ox, oy, nfl, nx, ny) +BOOL _MAP_objmove( char *file, int line, int objindex, int ofloor, int ox, int oy, int nfloor, + int nx, int ny ); +char *MAP_getFloorName( int floor); +BOOL MAP_setObjData( int ff ,int fx, int fy, int obj, int objhp ); + +#ifdef _MAKE_MAP +int MAP_getFloorXY( int floor, int *x, int *y); +#endif + +#ifdef _STATUS_WATERWORD //ˮ״̬ +int MAP_getMapFloorType( int floor); +#endif + +#ifdef _MAP_NOEXIT +unsigned int MAP_getExFloor_XY( int floor , int *map_type); +BOOL CHECKFLOORID( int id); +#endif + +int MAP_getMapMaxNum( void ); + + +#ifdef _PLAYER_DIY_MAP + +#define Player_Diy_Map_SIZE 80144 +#define Player_Diy_Map_X 100 +#define Player_Diy_Map_Y 100 +#define Player_Diy_Map_NUM 20 + +typedef struct tagMAP_PIC +{ + int tile; + int obj; +}Map_Pic; + +typedef struct tagPLAYER_DIY_MAP +{ + int ff; + char mapname[64]; + Map_Pic MapPic[Player_Diy_Map_X][Player_Diy_Map_Y]; + char cdkey[64]; + int datetime; + int playernum; + int exp; +}Player_Diy_Map; + +int MAP_savePlayerMap( int charaindex, int ff ,int fx, int fy, int tile, int obj); +int MAP_intPlayerMap( void ); +#endif + +int MAP_getMapNum(); +int MAP_getfloorId(int index); +BOOL MAP_IsMapFile( char* filename ); +BOOL MAP_readMapOne( char* filename ); +#ifdef _MO_LNS_MAPSUOXU +BOOL MAP_SetExWarp(int mapid , int fl, int x, int y, int type); +BOOL MAP_DelMap(int mapid ); +int MAP_makenew( int mapid ,char* map_name); +#endif +#endif +/*__MAP_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/readnpc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/readnpc.h new file mode 100644 index 0000000..c96f9c5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/readnpc.h @@ -0,0 +1,8 @@ +#ifndef __READNPC_H__ +#define __READNPC_H__ +BOOL NPC_readNPCSettingFiles( char* topdirectory ,int templatesize,int createsize); +#ifdef _MO_RELOAD_NPC +BOOL NPC_reloadNPC(void); +#endif +#endif + /*__READNPC_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_cli.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_cli.h new file mode 100644 index 0000000..54580a4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_cli.h @@ -0,0 +1,367 @@ +/* output by ../../bin/lsgen.perl 0.41 ( 1998 May) + * made Mon Oct 9 10:21:40 2000 + * user ttom + * host proxy1 + * file /home/ttom/gmsv2/src/gmsv/include/saacproto_cli.h + * util ./saacproto_util.c , include/saacproto_util.h + * src /home/ttom/gmsv2/src/gmsv/../../doc/saacproto.html + */ +#ifndef _SAACPROTOCLI_H_ +#define _SAACPROTOCLI_H_ +#include "version.h" +#include "saacproto_util.h" +#ifdef _CHARADATA_SAVE_SQL +#include "longzoro/characters.h" +#endif +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 7 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 7 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 7 + 1 ) +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +void saacproto_UpdataStele_send( int fd , char *cdkey , char *name , char *title , int level , int trns , int time , int floor) ; +void saacproto_UpdataStele_recv( int fd , char *token) ; +void saacproto_S_UpdataStele_recv( int i , char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ); +#endif + +void saacproto_ACGmsvDownRequest_recv( int fd,int min ) ; /* ../../doc/saacproto.html line 80 */ +#if _ATTESTAION_ID == 1 +void saacproto_ACServerLogin_send( int fd, int id, char* servername,char* serverpas ) ; /* ../../doc/saacproto.html line 90 */ +#else +void saacproto_ACServerLogin_send( int fd,char* servername,char* serverpas ) ; /* ../../doc/saacproto.html line 90 */ +#endif +void saacproto_ACServerLogin_recv( int fd,char* result,char* data ) ; /* ../../doc/saacproto.html line 101 */ +void saacproto_ACServerLogout_send( int fd ) ; /* ../../doc/saacproto.html line 114 */ + +#ifdef _PKSEVER_VER +void saacproto_ACCharList_send( int fd,char* id,char* pas,int mesgid, int star); +#else +void saacproto_ACCharList_send( int fd,char* id,char* pas,char* ip,char* mac,int mesgid,int charlistflg ) ; /* ../../doc/saacproto.html line 123 */ +#endif + +void saacproto_ACCharList_recv( int fd,char* result,char* output,int id ) ; /* ../../doc/saacproto.html line 135 */ +void saacproto_ACCharLoad_send( int fd,char* id,char* pas,char* charname,int lock,char* opt,int mesgid ) ; /* ../../doc/saacproto.html line 158 */ +void saacproto_ACCharLoad_recv( int fd,char* result,char* data,int id,int saveindex ) ; /* ../../doc/saacproto.html line 185 */ +#ifdef _NEWSAVE +void saacproto_ACCharSave_send( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid,int saveindex ) ; /* ../../doc/saacproto.html line 201 */ +#else +void saacproto_ACCharSave_send( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid ) ; /* ../../doc/saacproto.html line 201 */ +#endif +void saacproto_ACCharSave_recv( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 224 */ +void saacproto_ACCharDelete_send( int fd,char* id,char* passwd,char* charname,char* option,int mesgid ) ; /* ../../doc/saacproto.html line 241 */ +void saacproto_ACCharDelete_recv( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 266 */ +void saacproto_ACLock_send( int fd,char* id,int lock,int mesgid ) ; /* ../../doc/saacproto.html line 281 */ +void saacproto_ACLock_recv( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 300 */ +void saacproto_ACUCheck_send( int fd,char* mem_id,int status ) ; /* ../../doc/saacproto.html line 314 */ +void saacproto_ACUCheck_recv( int fd,char* mem_id ) ; /* ../../doc/saacproto.html line 328 */ +void saacproto_DBUpdateEntryString_send( int fd,char* table,char* key,char* value,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 339 */ +void saacproto_DBUpdateEntryString_recv( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 354 */ +void saacproto_DBDeleteEntryString_send( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 367 */ +void saacproto_DBDeleteEntryString_recv( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 379 */ +void saacproto_DBGetEntryString_send( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 394 */ +void saacproto_DBGetEntryString_recv( int fd,char* result,char* value,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 406 */ +void saacproto_DBUpdateEntryInt_send( int fd,char* table,char* key,int value,char* info,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 423 */ +void saacproto_DBUpdateEntryInt_recv( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 445 */ +void saacproto_DBGetEntryRank_send( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 459 */ +void saacproto_DBGetEntryRank_recv( int fd,char* result,int rank,int count,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 473 */ +void saacproto_DBDeleteEntryInt_send( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 492 */ +void saacproto_DBDeleteEntryInt_recv( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 504 */ +void saacproto_DBGetEntryInt_send( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 518 */ +void saacproto_DBGetEntryInt_recv( int fd,char* result,int value,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 530 */ +void saacproto_DBGetEntryByRank_send( int fd,char* table,int rank_start,int rank_end,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 547 */ +void saacproto_DBGetEntryByRank_recv( int fd,char* result,char* list,char* table,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 562 */ +void saacproto_DBGetEntryByCount_send( int fd,char* table,int count_start,int num,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 581 */ +void saacproto_DBGetEntryByCount_recv( int fd,char* result,char* list,char* table,int count_start,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 593 */ +void saacproto_Broadcast_send( int fd,char* id,char* charname,char* message,int flag ) ; /* ../../doc/saacproto.html line 608 */ +void saacproto_Broadcast_recv( int fd,char* id,char* charname,char* message ) ; /* ../../doc/saacproto.html line 621 */ +void saacproto_Message_send( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option ) ; /* ../../doc/saacproto.html line 634 */ +void saacproto_Message_recv( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option,int mesgid ) ; /* ../../doc/saacproto.html line 652 */ +void saacproto_MessageAck_send( int fd,char* id,char* charname,char* result,int mesgid ) ; /* ../../doc/saacproto.html line 671 */ +void saacproto_MessageFlush_send( int fd,char* id,char* charname ) ; /* ../../doc/saacproto.html line 690 */ +int saacproto_InitClient( int(*)(int,char*,int) , int bufsiz , int fd); +void saacproto_SetClientLogFiles( char *read , char *write); +void saacproto_CleanupClient(void); +int saacproto_ClientDispatchMessage(int fd ,char*line); + +// +#ifdef _PERSONAL_FAME +void saacproto_ACAddFM_send(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petarrt, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid); +#else +void saacproto_ACAddFM_send(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petarrt, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid); +#endif +void saacproto_ACAddFM_recv(int fd, char *result, int fmindex, int index, + int charfdid); +// +// #ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACJoinFM_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int index, int fame, int charfdid); +// #else +// void saacproto_ACJoinFM_send(int fd, char *fmname, int fmindex, char *charname, +// char *charid, int charlv, int index, int charfdid); +// #endif +void saacproto_ACJoinFM_recv(int fd, char *result, int recv, int charfdid); +// ˳ +void saacproto_ACLeaveFM_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int index, int charfdid); +void saacproto_ACLeaveFM_recv(int fd, char *result, int resultflag, int charfdid); +// ɢ +void saacproto_ACDelFM_send(int fd, char *fmname, int fmindex, int index, + char *charname, char *charid, int charfdid); + +void saacproto_ACDelFM_recv(int fd, char *result, int charfdid); +// гб +void saacproto_ACShowFMList_send(int fd); +void saacproto_ACShowFMList_recv(int fd, char *result, int num, char *data); +// гԱб +void saacproto_ACShowMemberList_send(int fd, int index); +void saacproto_ACShowMemberList_recv(int fd, char *result, int index, int num, + int fmacceptflag, int fmjoinnum, char *data +#ifdef _FAMILYBADGE_ + ,int badge +#endif + ); +// гϸ +void saacproto_ACFMDetail_send(int fd, char *fmname, int fmindex, + int index, int charfdid); +void saacproto_ACFMDetail_recv(int fd, char *result, char *data, int charfdid); +//峤˳Ա塢޸ļԱְλ +#ifdef _FMVER21 +void saacproto_ACMemberJoinFM_send(int fd, char *fmname, int fmindex, char *charname, + int charindex, int index, int result, int meindex, int charfdid); +#else +void saacproto_ACMemberJoinFM_send(int fd, char *fmname, int fmindex, char *charname, + int charindex, int index, int result, int charfdid); +#endif +void saacproto_ACMemberJoinFM_recv(int fd, char *result, char *data, int charfdid); +//峤˳Ա뿪 +#ifdef _FMVER21 +void saacproto_ACMemberLeaveFM_send(int fd, char *fmname, int fmindex, char *charname, + int charindex, int index, int meindex, int charfdid); +#else +void saacproto_ACMemberLeaveFM_send(int fd, char *fmname, int fmindex, char *charname, + int charindex, int index, int charfdid); +#endif +void saacproto_ACMemberLeaveFM_recv(int fd, char *result, char *data, int charfdid); +// Login +#ifdef _FM_MODIFY +void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int eventflag, int charfdid,int gsnum); +#else + #ifdef _FMVER21 + void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int result, int eventflag, int charfdid); + #else + void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int result, int charfdid); + #endif +#endif +#ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACFMCharLogin_recv(int fd, char *result, int index, int floor, + int fmdp, int joinflag, int fmsetupflag, int flag, int charindex, + int charfame, int charfdid +#ifdef _NEW_MANOR_LAW + ,int momentum +#endif + ); +#else +void saacproto_ACFMCharLogin_recv(int fd, char *result, int index, int floor, + int fmdp, int joinflag, int fmsetupflag, int flag, int charindex, + int charfdid); +#endif +// Logout +void saacproto_ACFMCharLogout_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int result, int index, int charfdid); +void saacproto_ACFMCharLogout_recv(int fd, char *result, int charfdid); +// г԰ +void saacproto_ACFMReadMemo_send(int fd, int index); +void saacproto_ACFMReadMemo_recv(int fd, char *result, int index, int num, + int dataindex, char *data); +// д԰ +void saacproto_ACFMWriteMemo_send(int fd, char *fmname, int fmindex, + char *data, int index); +void saacproto_ACFMWriteMemo_recv(int fd, char *result, int index); +// гݵ +void saacproto_ACFMPointList_send(int fd); +void saacproto_ACFMPointList_recv(int fd, char *result, char *data); + +// ݵ +void saacproto_ACSetFMPoint_send(int fd, char* fmname, int fmindex, int index, + int fmpointindex, int fl, int x, int y, int charfdid); +void saacproto_ACSetFMPoint_recv(int fd, char *result, int r, int charfdid); +// 趨ݵ +void saacproto_ACFixFMPoint_send(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex, + int village); +void saacproto_ACFixFMPoint_recv(int fd, char *result, int r); +// 峤ϵԱ㲥 +// kindflag 1:峤㲥 2:屻ϵͳɾ 3:ϵͳ֪ͨѶϢ +void saacproto_ACFMAnnounce_send(int fd, char *fmname, int fmindex, int index, + char *data, int color); +void saacproto_ACFMAnnounce_recv(int fd, char *result, char *fmname, + int fmindex, int index, int kindflag, char *data, int color); +// г TOP 50 б +void saacproto_ACShowTopFMList_send(int fd, int kindflag); +void saacproto_ACShowTopFMList_recv(int fd, char *result, int kindflag, + int num, char *data); +// (ǷճԱ) +// flag 1:acceptjoinflag 2:dpchanged 3:change fmpet 4:change fminfo 5:predel FM Time +void saacproto_ACFixFMData_send(int fd, char *fmname, int fmindex, int index, + int kindflag,char *data1,char *data2,int charindex, int charfdid); + +void saacproto_ACFixFMData_recv(int fd, char *result, int kindflag, char *data1, + char *data2, int charfdid); + +// У¼ +void saacproto_ACFixFMPK_send(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex); +void saacproto_ACFixFMPK_recv(int fd, char *result, int data, int winindex, + int loseindex); +// ȡü +// kindflag 1: +void saacproto_ACGetFMData_send(int fd, char *fmname, int fmindex, int index, + int kindflag, int charfdid); +void saacproto_ACGetFMData_recv(int fd, char *result, int kindflag, int data, + int charfdid); +// ǣ +void saacproto_ACGMFixFMData_send(int fd, int index, char *charid, char *cmd, + char *data, int charfdid); +void saacproto_ACGMFixFMData_recv(int fd, char *result, char *fmindex, int charfdid); +// ɾսų +void saacproto_ACFMClearPK_recv(int fd, char *result, char *fmname, int fmindex, + int index); + +// Arminius 7.26 manor pk acknowledge +void saacproto_ACManorPKAck_send(int fd, char *data); +void saacproto_ACManorPKAck_recv(int fd, char *data); + +void saacproto_ACreLoadFmData_send( int fd, int type, int data); + +#ifdef _ACFMPK_LIST +void saacproto_ACLoadFmPk_recv(int fd, char *data); +void saacproto_ACLoadFmPk_send(int fd, int fmpks_pos); +void saacproto_ACSendFmPk_recv( int fd, int toindex, int flg); +void saacproto_ACSendFmPk_send(int fd, int toindex, int PkFlg, int fmpks_pos, char *msg); +#endif + +void saacproto_ACAuctionSold_send(int fd, char *data); +void saacproto_ACAuctionSold_recv(int fd, char *data); + +#ifdef _WAEI_KICK // +void saacproto_ACKick_send( int fd, char* kickid,int kickfd, int flg); +void saacproto_ACKick_recv(int fd , int act, char* data ,int retfd); +#endif + +#ifdef _CHAR_POOLITEM +void saacproto_ACCharInsertPoolItem_send( int acfd, int charaindex, int clifdid, char *CdKey, char *Pooldataarg, int TYPE); + +void saacproto_ACCharSavePoolItem_recv(int fd ,char* result, char* data,int retfd); +void saacproto_ACCharSavePoolItem_send( int acfd, int charaindex, int clifdid, char *CdKey, char *Pooldataarg); + +void saacproto_ACCharGetPoolItem_recv(int fd ,char* result, char* data,int retfd, int meindex); +void saacproto_ACCharGetPoolItem_send( int acfd, int meindex, int charaindex, int clifdid, char * CdKey); +#endif + +#ifdef _CHAR_POOLPET +void saacproto_ACCharInsertPoolPet_send( int acfd, int charaindex, int clifdid, char *CdKey, char *Pooldataarg, int TYPE); + +void saacproto_ACCharSavePoolPet_recv(int fd ,char* result, char* data,int retfd); +void saacproto_ACCharSavePoolPet_send( int acfd, int charaindex, int clifdid, char *CdKey, char *Pooldataarg); + +void saacproto_ACCharGetPoolPet_recv(int fd ,char* result, char* data,int retfd, int meindex); +void saacproto_ACCharGetPoolPet_send( int acfd, int meindex, int charaindex, int clifdid, char * CdKey); +#endif + +#ifdef _ANGEL_SUMMON +void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, char* angelinfo); +void saacproto_ACMissionTable_send( int fd, int num, int type, char *data, char* angelinfo); +#endif + +#ifdef _TEACHER_SYSTEM +// RETURN_FUNCTION -> R_F_XXXXXXX +enum{ + R_F_TEACHER_SYSTEM, + R_F_END +}; +void saacproto_ACCheckCharacterOnLine_recv( int acfd, int charaindex, int iOnline,char *data,int flag); +void saacproto_ACCheckCharacterOnLine_send( int acfd, int charaindex, char *id, char *name, int flag); +#endif + +void saacproto_ACCharLogin_send( int fd, int clifd, char* id,char* pas,char* ip +#ifdef _NEWCLISETMAC +,char* mac +#endif +); +void saacproto_ACCharLogin_recv(int fd , int clifd, int flag); + +void saacproto_LockLogin_send( int fd, char* id, char* ip, int flag ); + + +#ifdef _NEW_VIP_SHOP +void saacproto_QueryPoint_send( int acfd, int fd, char* id ); +void saacproto_QueryPoint_recv( int fd , int point); +#ifdef _COST_ITEM +void saacproto_CostItem_send( int acfd, int fd, char* id, int point); +#endif + +void saacproto_NewVipShop_send( int acfd, int fd, char* id, int point, char* buf, int flag); +void saacproto_NewVipShop_recv( int fd, int point, char* buf, int flag); +#endif + +#ifdef _ITEM_PET_LOCKED +void saacproto_ItemPetLocked_send( int fd, char* id, char *safepasswd ); +void saacproto_ItemPetLocked_recv( int fd, int flag, char *data); +void saacproto_ItemPetLockedPasswd_send( int fd, char* id, char *safepasswd ); +void saacproto_ItemPetLockedPasswd_recv( int fd, char *data); +#endif + +#ifdef _ONLINE_COST +void saacproto_OnlineCost_send( int acfd, int fd, char* id, char *costpasswd, int fmindex, char *fmname ); +void saacproto_OnlineCost_recv(int fd, char *data); +#endif +#ifdef _SQL_BUY_FUNC +void saacproto_OnlineBuy_send( int acfd, int fd, char* id, char *costpasswd ); +void saacproto_OnlineBuy_recv(int fd, char *data); +#endif +#ifdef _VIPPOINT_OLD_TO_NEW +void saacproto_OldToNew_send( int acfd, int fd, char* id, int point ); +void saacproto_OldToNew_recv(int fd, char *data); +#endif + +#ifdef _CHARADATA_SAVE_SQL +void saacproto_CharadataSaveSQL_send( int fd, char* id, Charadata charadata, int saveindex, int flag ); +#endif + +#ifdef _LOTTERY_SYSTEM +void saacproto_LotterySystem_send(); +void saacproto_LotterySystem_recv( char *data); +#endif + +#ifdef _ALL_SERV_SEND +void saacproto_AllServSend_recv(char *data); +void saacproto_AllServSend_send(char *data); +#endif + +#ifdef _OTHER_SAAC_LINK +void saacproto_OtherSaacLink_send( int acfd, char* filename, char* data ); +#endif + + +void saacproto_ACServerKey_recv( int acfd, int key); + +#endif +/* end of the generated client header code */ + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_util.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_util.h new file mode 100644 index 0000000..e65a2e2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/saacproto_util.h @@ -0,0 +1,114 @@ +#ifndef _SAACPROTOUTIL_H_ +#define _SAACPROTOUTIL_H_ +#include +#include +#ifndef WIN32 +#include +#include +#endif +#define saacproto__NOENCRYPT +#define saacproto__NODEBUG +struct saacproto_ { + int (*write_func)(int,char*,int) ; /* write function */ + size_t workbufsize; /* size of work area */ + char *work,*arraywork,*escapework,*val_str,*ret_work; /* work areas which have same size */ + char *cryptwork,*jencodecopy,*jencodeout,*compresswork; /* these work has bigger size (3times)*/ + char** token_list; /* token list */ + unsigned long message_id; /*= 1, */ /* for generating message IDs */ + +}; +#ifdef _SAACPROTOUTIL_C_ +struct saacproto_ saacproto = { + NULL, + 0, + NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL, + NULL, + 1, +}; +char **saacproto_stringwrapper; +char saacproto_readlogfilename[1024]; +char saacproto_writelogfilename[1024]; +#else +extern char **saacproto_stringwrapper; +extern struct saacproto_ saacproto; +extern char saacproto_readlogfilename[1024]; +extern char saacproto_writelogfilename[1024]; +#endif +char* saacproto_escapeString( char*a ); +char* saacproto_descapeString( char*a ); +void saacproto_splitString( char *src ); +void saacproto_strcpysafe( char *dest, char *src, int len ); +void saacproto_strcatsafe( char *dest , char *src , int maxlen ); +char*saacproto_mkstr_int( int i ); +char*saacproto_mkstr_u_int( unsigned int i ); +char*saacproto_mkstr_long( long l ); +char*saacproto_mkstr_u_long( unsigned long l ); +char*saacproto_mkstr_short( short s ); +char*saacproto_mkstr_u_short( short s ); +char*saacproto_mkstr_char( char c ); +char*saacproto_mkstr_u_char( char c); +char*saacproto_mkstr_string( char*a ); +char*saacproto_mkstr_float( float f ); +char*saacproto_mkstr_double( double d ); +char*saacproto_mkstr_int_array( int size , int *array ); +char*saacproto_mkstr_u_int_array( int size , int *array ); +char*saacproto_mkstr_short_array( int size , short *array ); +char*saacproto_mkstr_u_short_array(int size , short *array ); +char *saacproto_mkstr_char_array( int size , char *array ); +char *saacproto_mkstr_u_char_array( int size , unsigned char *array ); +char *saacproto_mkstr_float_array( int size , float *array ); +char *saacproto_mkstr_double_array( int size , double *array ); +int saacproto_demkstr_int( char*a ); +unsigned int saacproto_demkstr_u_int( char*a ); +long saacproto_demkstr_long( char*a ); +unsigned long saacproto_demkstr_u_long(char*a ); +short saacproto_demkstr_short( char*a ); +unsigned short saacproto_demkstr_u_short( char*a ); +char saacproto_demkstr_char( char*a ); +unsigned char saacproto_demkstr_u_char( char*a ); +float saacproto_demkstr_float( char*a ); +double saacproto_demkstr_double(char*a ); +char* saacproto_demkstr_string( char*a); +int *saacproto_demkstr_int_array( char**tk ,int *buf ,int start , int size ); +int *saacproto_demkstr_u_int_array( char **tk , int *buf , int start , int size ); +unsigned int *saacproto_demkstr_long_array( + char **tk , unsigned int *buf , int start , int size ); +unsigned long *saacproto_demkstr_u_long_array( + char **tk , unsigned long *buf , int start , int size ); +short *saacproto_demkstr_short_array( char **tk , short *buf , int start , int size ); +unsigned short*saacproto_demkstr_u_short_array( + char **tk , unsigned short *buf , int start , int size ); +char *saacproto_demkstr_char_array( char **tk , char *buf , int start , int size ); +unsigned char *saacproto_demkstr_u_char_array( + char **tk , unsigned char*buf , int start , int size ); +float *saacproto_demkstr_float_array( char **tk , float *buf , int start , int size ); +double *saacproto_demkstr_u_double_array( char **tk , double *buf , int start , int size ); +char *saacproto_wrapStringAddr( char *copy , int maxcopylen , char*src ); + +void saacproto_GetMessageInfo( int *id , char *funcname , int len,char **tk ); +int saacproto_ClientRead(void); +void saacproto_consumeLine(char *buf , int ofs ); +void saacproto_copyLine( char*src , char *out , int maxoutlen ); +void saacproto_Send( int fd , char *msg ); +int saacproto_AllocateCommonWork(int bufsiz); +int saacproto_StringRest(); + +// WON ADD +unsigned long saacproto_GetNewMessageID(void); + + +void saacproto_CreateHeader(char*out, char *fname ); +void saacproto_CreateHeaderID( char *out,unsigned long msgid , char *fname ); +int saacproto_default_write_wrap( int fd , char *buf , int size ); +void saacproto_bzero( char *b , int siz ); +void saacproto_bcopy(char*s , char *d , int siz ); +char *saacproto_Ltoa( long v ); +char *saacproto_Ultoa( unsigned long v ); +void saacproto_DebugSend( int fd , char *msg ); +/* Modified by ringo to fasten int type transfer */ +char *saacproto_cnv10to62( int a, char *out, int outlen ); +int saacproto_a62toi( char *a ); +extern int JENCODE_KEY; +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/shop.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/shop.h new file mode 100644 index 0000000..cf528b5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/shop.h @@ -0,0 +1,5 @@ + +void ShopData_Init(); +void lssproto_upshopdata_recv(int fd,char shop[5][1024]); +void WriteShopData(char *data,int id); + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/skill.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/skill.h new file mode 100644 index 0000000..9d41159 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/skill.h @@ -0,0 +1,121 @@ +#ifndef __SKILL_H__ +#define __SKILL_H__ + +#include "common.h" +#include "util.h" + +typedef struct tagSKILL_intDataSetting +{ + char *dumpskill; +}SKILL_intDataSetting; + +typedef struct tagSKILL_charDataSetting +{ + char *dumpskill; +}SKILL_charDataSetting; + + +typedef enum +{ +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + SKILL_1, + SKILL_2, + SKILL_3, + SKILL_4, + SKILL_5, + SKILL_6, + SKILL_7, + SKILL_8, + SKILL_9, + SKILL_10, + SKILL_11, + SKILL_12, + SKILL_13, + SKILL_14, + SKILL_15, + SKILL_16, + SKILL_NUM +#else + SKILL_FIRE, + SKILL_MAGICIAN, + SKILL_PRIEST, + SKILL_ALOTOFTHINGS, + SKILL_AVOIDRATEUP, + SKILL_DETERMINEITEM, + SKILL_DETERMINEOTHERS, + SKILL_FIRECUT, + SKILL_THUNDERCUT, + SKILL_ICECUT, + SKILL_MERCHANT, + SKILL_HEALER, + SKILL_FIST, + SKILL_SWORD, + SKILL_AXE, + SKILL_SPEAR, + SKILL_BOW, + SKILL_CANE, + SKILL_LARGEVOICE, + SKILL_NUM +#endif +}SKILL_ID; + + +typedef struct tagSkillTable +{ + const int maxlevel; + void* effectfunc; +}SKILL_table; + + +typedef enum +{ + SKILL_LEVEL, // ܵȼ + SKILL_IDENTITY, // ܱ + SKILL_DATAINTNUM, +}SKILL_DATAINT; + +typedef enum +{ + SKILL_DATACHARNUM, +}SKILL_DATACHAR; + + +typedef struct tagSkill +{ + int data[SKILL_DATAINTNUM]; + STRING32 string[SKILL_DATACHARNUM]; +}Skill; + +char* SKILL_makeStringFromSkillData( Skill* sk ); +BOOL SKILL_makeSkillFromStringToArg( char* src, Skill* sk ); + +int SKILL_getInt( Skill* skill, int element); +int SKILL_setInt( Skill* skill, int element, int new); + +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +char* SKILL_makeSkillStatusString( Skill* skill, int charaindex, int skill_num ); +#else +char* SKILL_makeSkillStatusString( Skill* skill ); +#endif + +char* SKILL_makeSkillFalseString( void ); + +BOOL SKILL_makeSkillData( Skill* sk ,int skid, int lev ); + +int SKILL_levelup( Skill* sk ); +int SKILL_getLevelFromSkillID( int charaindex, SKILL_ID id ); +BOOL SKILL_getUpableSkillID( int charaindex,char* buf, int buflen ); +void SKILL_skillEffect( int charaindex ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +int PROFESSION_MAGIC_COST_MP( int charaindex, int skill_num ); +INLINE int PROFESSION_CHANGE_SKILL_LEVEL_M( int skill_level ); +INLINE int PROFESSION_CHANGE_SKILL_LEVEL_A( int skill_level ); +INLINE int SKILL_getRealInt( Skill* skill, int element); +#endif + + +#endif +/*__SKILL_H__*/ + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/sndcnf.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/sndcnf.h new file mode 100644 index 0000000..449efd4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/sndcnf.h @@ -0,0 +1,147 @@ +// į̻ ʾبة ǩ ׷º Ѩ޷ūƥέ춪 +// SA Serverƥƻϣ +// SE įñߣ + +SNDCONFIG sndconfig[] = +{ + // + { 1, "data\\se\\sap_01.wav", 85, 0, 0 /*, "aֿȭ"*/ }, + { 2, "data\\se\\sap_02.wav", 85, 0, 0 /*, "a"*/ }, + { 3, "data\\se\\sap_03.wav", 85, 0, 0 /*, "a"*/ }, + { 4, "data\\se\\sap_04.wav", 100, 0, 0 /*, "a"*/ }, + { 5, "data\\se\\sap_05.wav", 85, 0, 0 /*, "a"*/ }, + { 6, "data\\se\\sap_06.wav", 60, 0, 0 /*, "a"*/ }, + { 7, "data\\se\\sap_07.wav", 123, 0, 0 /*, "aͿռ"*/ }, + { 8, "data\\se\\sap_08.wav", 80, 0, 0 /*, ""*/ }, + { 9, "data\\se\\sap_09.wav", 80, 0, 0 /*, "aǹ"*/ }, + { 10, "data\\se\\sap_10.wav", 80, 0, 0 /*, "aʸ"*/ }, +//x { 11, "data\\se\\sap_11.wav", 105, 7, 0 /*, ""*/ }, + { 11, "data\\se\\sap_11.wav", 105, 0, 0 /*, ""*/ }, + { 12, "data\\se\\sap_14.wav", 100, 0, 0 /*, ""*/ }, + { 13, "data\\se\\sap_12.wav", 90, 0, 0 /*, ""*/ }, + { 14, "data\\se\\sap_13.wav", 105, 0, 0 /*, ""*/ }, + + // ƹ + { 51, "data\\se\\sae_01.wav", 123, 0, 0 /*, ""*/ }, + { 52, "data\\se\\sae_02.wav", 123, 0, 0 /*, ""*/ }, + { 53, "data\\se\\sae_03.wav", 123, 0, 0 /*, ""*/ }, + { 54, "data\\se\\sae_04.wav", 123, 0, 0 /*, ""*/ }, + { 55, "data\\se\\sae_05.wav", 123, 0, 0 /*, ""*/ }, + { 56, "data\\se\\sae_06.wav", 105, 0, 0 /*, "˹"*/ }, + { 57, "data\\se\\sae_07.wav", 80, 0, 0 /*, "˹ɫ"*/ }, + { 58, "data\\se\\sae_08.wav", 123, 0, 0 /*, ""*/ }, + { 59, "data\\se\\sae_09.wav", 123, 0, 0 /*, ""*/ }, + { 60, "data\\se\\sae_10.wav", 80, 0, 0 /*, "Ħ˹"*/ }, + { 61, "data\\se\\sae_11.wav", 123, 0, 0 /*, ""*/ }, + { 62, "data\\se\\sae_12.wav", 95, 0, 0 /*, "濨˹"*/ }, + { 63, "data\\se\\sae_13.wav", 80, 0, 0 /*, "˹̹˹"*/ }, + { 64, "data\\se\\sae_14.wav", 90, 0, 0 /*, ""*/ }, + { 65, "data\\se\\sae_15.wav", 95, 0, 0 /*, "³"*/ }, + { 66, "data\\se\\sae_16.wav", 95, 0, 0 /*, "ص"*/ }, + { 67, "data\\se\\sae_17.wav", 123, 0, 0 /*, ""*/ }, + { 68, "data\\se\\sae_18.wav", 123, 0, 0 /*, ""*/ }, + { 69, "data\\se\\sae_19.wav", 123, 0, 0 /*, ""*/ }, + { 70, "data\\se\\sae_20.wav", 123, 0, 0 /*, ""*/ }, + { 71, "data\\se\\sae_21.wav", 123, 0, 0 /*, ""*/ }, + { 72, "data\\se\\sae_22.wav", 123, 0, 0 /*, ""*/ }, + { 73, "data\\se\\sae_23.wav", 90, 0, 0 /*, ""*/ }, + { 74, "data\\se\\sae_24.wav", 90, 0, 0 /*, "Ұ"*/ }, + { 75, "data\\se\\sae_25.wav", 100, 0, 0 /*, "Ը"*/ }, + { 76, "data\\se\\sae_26.wav", 123, 0, 0 /*, ""*/ }, + { 77, "data\\se\\sae_27.wav", 123, 0, 0 /*, ""*/ }, + { 78, "data\\se\\sae_28.wav", 90, 0, 0 /*, ""*/ }, + { 79, "data\\se\\sae_29.wav", 123, 0, 0 /*, ""*/ }, + { 80, "data\\se\\sae_30.wav", 100, 0, 0 /*, "֮"*/ }, + { 81, "data\\se\\sae_31.wav", 123, 0, 0 /*, ""*/ }, + { 82, "data\\se\\sae_32.wav", 123, 0, 0 /*, ""*/ }, + + // ܷ + { 100, "data\\se\\sam_01.wav", 75, 0, 0 /*, "ʹ"*/ }, + { 101, "data\\se\\sam_02.wav", 75, 0, 0 /*, "ż"*/ }, + { 102, "data\\se\\sam_03.wav", 75, 0, 0 /*, "ָ"*/ }, + { 103, "data\\se\\sam_04.wav", 123, 0, 0 /*, "棨С"*/ }, + { 104, "data\\se\\sam_05.wav", 123, 0, 0 /*, "棨У"*/ }, + { 105, "data\\se\\sam_06.wav", 123, 0, 0 /*, "棨"*/ }, + { 106, "data\\se\\sam_07.wav", 123, 0, 0 /*, "С"*/ }, + { 107, "data\\se\\sam_08.wav", 123, 0, 0 /*, "У"*/ }, + { 108, "data\\se\\sam_09.wav", 123, 0, 0 /*, ""*/ }, + { 109, "data\\se\\sam_10.wav", 123, 0, 0 /*, "С"*/ }, + { 110, "data\\se\\sam_11.wav", 123, 0, 0 /*, "У"*/ }, + { 111, "data\\se\\sam_12.wav", 123, 0, 0 /*, ""*/ }, + { 112, "data\\se\\sam_13.wav", 123, 0, 0 /*, "׻С"*/ }, + { 113, "data\\se\\sam_14.wav", 123, 0, 0 /*, "׻У"*/ }, + { 114, "data\\se\\sam_15.wav", 85, 0, 0 /*, "׻ɱ"*/ }, + { 115, "data\\se\\sam_16.wav", 123, 0, 0 /*, ""*/ }, + { 116, "data\\se\\sam_17.wav", 123, 0, 0 /*, ""*/ }, + { 117, "data\\se\\sam_18.wav", 123, 0, 0 /*, ""*/ }, + { 118, "data\\se\\sam_19.wav", 123, 0, 0 /*, "Ѫ"*/ }, + { 119, "data\\se\\sam_20.wav", 123, 0, 0 /*, ""*/ }, + { 120, "data\\se\\sam_21.wav", 123, 0, 0 /*, "ʯ"*/ }, + { 121, "data\\se\\sam_22.wav", 123, 0, 0 /*, ""*/ }, + { 122, "data\\se\\sam_23.wav", 123, 0, 0 /*, "ħ"*/ }, + { 123, "data\\se\\sam_24.wav", 123, 0, 0 /*, ""*/ }, + + // +// { 151, "data\\se\\sak_01.wav", 121, 0, 1 /*, ""*/ }, +// { 152, "data\\se\\sak_02.wav", 121, 0, 1 /*, "Ǻ"*/ }, + { 151, "data\\se\\sak_01.wav", 127, 0, 1 /*, ""*/ }, +//x { 152, "data\\se\\sak_02.wav", 127, 4, 1 /*, ""*/ }, + { 152, "data\\se\\sak_02.wav", 127, 0, 1 /*, ""*/ }, + { 153, "data\\se\\sak_03.wav", 121, 0, 1 /*, ""*/ }, + { 154, "data\\se\\sak_04.wav", 90, 0, 1 /*, ""*/ }, + { 155, "data\\se\\sak_05.wav", 95, 0, 1 /*, "Ʈѩ"*/ }, + { 156, "data\\se\\sak_06.wav", 127, 0, 1 /*, ""*/ }, + { 157, "data\\se\\sak_07.wav", 125, 0, 1 /*, "ˮ"*/ }, + { 158, "data\\se\\sak_08.wav", 125, 0, 1 /*, ""*/ }, + { 159, "data\\se\\sak_09a.wav", 120, 0, 1 /*, ""*/ }, + { 160, "data\\se\\sak_10.wav", 115, 0, 1 /*, ""*/ }, + { 161, "data\\se\\sak_11.wav", 85, 0, 1 /*, "ˮ"*/ }, + { 162, "data\\se\\sak_12.wav", 120, 0, 1 /*, "糵"*/ }, + { 163, "data\\se\\sak_13.wav", 100, 0, 1 /*, "ˮ"*/ }, + { 164, "data\\se\\sak_14.wav", 127, 0, 1 /*, "ԭ"*/ }, + { 165, "data\\se\\sak_15.wav", 120, 0, 1 /*, ""*/ }, + { 166, "data\\se\\sak_16.wav", 120, 0, 1 /*, "ʯӵˮ"*/ }, + { 167, "data\\se\\sak_17.wav", 110, 0, 1 /*, "Ҷȡů"*/ }, + { 168, "data\\se\\sak_09b.wav", 120, 0, 1 /*, "ɭ֣"*/ }, + + // ˵ ة + { 201, "data\\se\\sas_01.wav", 90, 0, 0 /*, ""*/ }, + { 202, "data\\se\\sas_02.wav", 80, 0, 0 /*, "Ӵ"*/ }, + { 203, "data\\se\\sas_03.wav", 75, 0, 0 /*, "رӴ"*/ }, + { 204, "data\\se\\sas_04.wav", 80, 0, 0 /*, "Ӵ"*/ }, + { 205, "data\\se\\sas_05.wav", 80, 0, 0 /*, "رӴ"*/ }, + { 206, "data\\se\\sas_06.wav", 80, 0, 0 /*, ""*/ }, + { 207, "data\\se\\sas_07.wav", 123, 0, 0 /*, ""*/ }, + { 208, "data\\se\\sas_08.wav", 123, 0, 0 /*, ""*/ }, + { 209, "data\\se\\sas_09.wav", 123, 0, 0 /*, ""*/ }, + { 210, "data\\se\\sas_10.wav", 123, 0, 0 /*, ""*/ }, + { 211, "data\\se\\sas_11.wav", 65, 0, 0 /*, ìʧ""*/ }, + { 212, "data\\se\\sas_12.wav", 80, 0, 0 /*, "ʹĿ"*/ }, + { 213, "data\\se\\sas_13.wav", 123, 0, 0 /*, "Σdz"*/ }, +// { 214, "data\\se\\sas_14.wav", 127, 0, 0 /*, "ʤ"*/ }, + { 215, "data\\se\\sas_15.wav", 82, 0, 0 /*, ""*/ }, + { 216, "data\\se\\sas_16.wav", 110, 0, 0 /*, ""*/ }, + { 217, "data\\se\\sas_17.wav", 85, 0, 0 /*, "㻬"*/ }, + { 218, "data\\se\\sas_18.wav", 123, 0, 0 /*, ""*/ }, + { 219, "data\\se\\sas_19.wav", 82, 0, 0 /*, ""*/ }, + { 220, "data\\se\\sas_20.wav", 60, 0, 0 /*, "ΣǶ"*/ }, + { 221, "data\\se\\sas_21.wav", 123, 0, 0 /*, ""*/ }, + + // ĸ + { 250, "data\\se\\sad_01.wav", 85, 0, 0 /*, "𺦣ֿȭ"*/ }, + { 251, "data\\se\\sad_02.wav", 80, 0, 0 /*, "𺦣"*/ }, +//x { 252, "data\\se\\sad_03.wav", 95, -3, 0 /*, "𺦣ǹ"*/ }, + { 252, "data\\se\\sad_03.wav", 95, 0, 0 /*, "𺦣ǹ"*/ }, + { 253, "data\\se\\sad_04.wav", 85, 0, 0 /*, "𺦣"*/ }, + { 254, "data\\se\\sad_05.wav", 90, 0, 0 /*, "𺦣צ"*/ }, + + // BGM +// { 401, "data\\bgm\\ls2b_01.wav", 5 /*, "ģʽ֮"*/ }, +// { 402, "data\\bgm\\ls2b_02.wav", 5 /*, "Ϸе"*/ }, +// { 403, "data\\bgm\\ls2b_03.wav", 5 /*, "֮"*/ }, +// { 404, "data\\bgm\\ls2b_04.wav", 5 /*, "ͷĿ֮"*/ }, + + { -1 } // θį սئз +}; + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/title.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/title.h new file mode 100644 index 0000000..2f2248f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/title.h @@ -0,0 +1,21 @@ +#ifndef __TITLE_H__ +#define __TITLE_H__ + +#include "common.h" +#include "util.h" + +INLINE BOOL TITLE_CHECKTABLEINDEX( int index ); +int TITLE_getTitleIndex( int index); + +char* TITLE_makeTitleStatusString( int charaindex, int havetitleindex ); +char* TITLE_makeSkillFalseString( void ); + +BOOL TITLE_addtitle( int charaindex, int titleindex ); +BOOL TITLE_deltitle( int charaindex, int titleindex ); +BOOL TITLE_initTitleName( char* filename ); +BOOL TITLE_reinitTitleName( void); +BOOL TITLE_initTitleConfig( char* filename ); +BOOL TITLE_TitleCheck( int charaindex, BOOL mode); +BOOL TITLE_TitleCheck_Nomsg( int charaindex, BOOL mode, int *addcnt, int *delcnt); +#endif + /*__TITLE_H__*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/trade.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/trade.h new file mode 100644 index 0000000..55843a9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/trade.h @@ -0,0 +1,31 @@ +#ifndef __TRADE_H__ +#define __TRADE_H__ +#include "version.h" +#include "common.h" +#include "util.h" +#include "net.h" +#ifdef _TRADE_PK +typedef struct _tagTradeList{ + int charaindex; + int fd; + int PetTi[5]; + int ItemTi[15]; + int ItemNum[15]; + int Golds; + int use; +}STradeList; +#endif +BOOL TRADE_Search(int fd, int meindex, char* message); + +void CHAR_Trade(int fd, int index, char* message); + +#ifdef _ITEM_PILEFORTRADE +void TRADE_InitTradeList( void); +#endif + +#ifdef _TRADE_PK +BOOL TRADE_HandleTradeForPK( STradeList *temp1, STradeList *temp2 ); +#endif +void TRADE_CheckTradeListUser( void); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/util.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/util.h new file mode 100644 index 0000000..064ec17 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/util.h @@ -0,0 +1,140 @@ +#ifndef __UTIL_H__ +#define __UTIL_H__ + +#include +#include +#include + +#include "common.h" + + +typedef struct tagSTRING32 +{ + char string[32]; +}STRING32; +typedef struct tagSTRING64 +{ + char string[64]; +}STRING64; +typedef struct tagSTRING128 +{ + char string[128]; +}STRING128; + +typedef struct tagRECT +{ + int x; + int y; + int width; + int height; +}RECT; +typedef struct tagPOINT +{ + int x; + int y; +}POINT; + +/* strtol ɡñ */ +typedef enum +{ + CHAR,SHORT,INT,DOUBLE +}CTYPE; + +void chop( char* src ); +void dchop( char* src , char* del); +#define chomp(src) dchop(src,"\n"); +void chompex( char *buf ); +void pohcd( char* src , char* del); +void strcpysafe( char* dest ,size_t n,const char* src ); +void strncpysafe( char* dest ,const size_t n , + const char* src ,const int length ); +char* strcatsafe( char* src, int size, char* ap ); +BOOL strtolchecknum( char* arg , void* number,int base ,CTYPE type); +int strcmptail( char *s1 , char *s2 ); +int texttoiTail( char *hoge); +int textToInt( char *str ); +void deleteCharFromString( char* src , char* dels ); +void deleteCharFromStringNoEscape( char* src , char* dels ); +#define deleteWhiteSpace( src ) deleteCharFromStringNoEscape( src," \t" ) +char* replaceString( char* src, char oldc ,char newc ); + +char* escapeStrStr( char* src, char* needle ); +BOOL getStringFromIndexWithDelim_body( char* src ,char* delim ,int index, char* buf , int buflen, char *file, int line ); +#define getStringFromIndexWithDelim( src, delim, index, buf, buflen ) getStringFromIndexWithDelim_body( src, delim, index, buf, buflen, __FILE__, __LINE__ ) + +void getFourIntsFromString(char* src,int* int1,int* int2,int* int3, + int* int4); +void deleteSequentChar( char* src , char* dels ); +int hashpjw ( char* s ); +double gettimemillis( void ); +double gettimemicros( void ); + +int bindlocalhost( int port ); +int connectHost( char* hostname , unsigned short port ); +int existsNewLineCharacter( char* line ); +int hashpjw ( char* s ); +int charInclude( char* src, char* include ); +char* nindex( char* string, int c , int number ); +int rgetFileName( char* dirname , STRING64* string, int size); +#define RAND(x,y) ((x-1)+1+ \ + (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +/*#define RAND(x,y) (x+(int)( (double)(y)*rand() / (RAND_MAX+1.0)) )*/ +void makeRandomString( char *cand , char *out , int len ); +BOOL checkStringsUnique( char** strings, int num ,int verbose); + +char* makeEscapeString( char* src , char* dest, int sizeofdest); +char* makeStringFromEscaped( char* src ); +INLINE double time_diff(struct timeval subtrahend,struct timeval subtractor); +BOOL PointInRect( RECT* rect, POINT* p ); +BOOL CoordinateInRect( RECT* rect, int x, int y); +int clipRect( RECT *rect1, RECT *rect2, RECT *ret ); +BOOL isstring1or0( char* string ); +void easyGetTokenFromString( char *src , int count , char*output , int len ); + +float linearDiv( float val1 , float val2 , float d ); +BOOL isExistFile( char* filename ); +char *cnv10to62( int a, char *out, int outlen ); +BOOL checkRedundancy( int *src, int srclen); +void shuffle_ints( int num, int *a, int t ); +unsigned short CheckCRC( unsigned char *p , int size ); +// Shan Add +INLINE double time_diff(struct timeval subtrahend,struct timeval subtractor); +char *strcpy_s(char *des, size_t n, const char *src); +char * itoa(long n, int base); + + +/* ѨͷئԻ */ +#define ABS(x) ((x)>=0 ? (x) : -(x)) + +/* ë 0 - 7 姸 */ +#define VALIDATEDIR(x) ({(x)%=8;(x)=((x)+8)%8;}) + +/* 4ë2ƻ */ +#define GETLOWVALUE(x) ( (x)&0x0000ffff) +#define GETHIGHVALUE(x) ((((x)&0xffff0000)>>16)&0x0000ffff) +#define SETLOWVALUE(x,y) ((x)=((x)&0xffff0000)|( (y) &0x0000ffff)) +#define SETHIGHVALUE(x,y) ((x)=((x)&0x0000ffff)|(((y)<<16)&0xffff0000)) +#define MAKE2VALUE(x,y) ((((x)<<16)&0xffff0000)|((y)&0x0000ffff)) + +/* 4ë1*4ƻؤѨͷ */ +#define GETFIRSTVALUE(x) ( (x)&0x000000ff ) +#define GETSECONDVALUE(x) ((((x)&0x0000ff00)>>8 )&0x000000ff) +#define GETTHIRDVALUE(x) ((((x)&0x00ff0000)>>16)&0x000000ff) +#define GETFOURTHVALUE(x) ((((x)&0xff000000)>>24)&0x000000ff) + +#define SETFIRSTVALUE(x,y) ((x)=(((x)&0xffffff00)\ + |( y &0x000000ff))) +#define SETSECONDVALUE(x,y) ((x)=(((x)&0xffff00ff)\ + |(((y)<<8 )&0x0000ff00))) +#define SETTHIRDVALUE(x,y) ((x)=(((x)&0xff00ffff)\ + |(((y)<<16)&0x00ff0000))) +#define SETFOURTHVALUE(x,y) ((x)=(((x)&0x00ffffff)\ + |(((y)<<24)&0xff000000))) + +#define MAKE4VALUE(a,b,c,d) ( (((a)<<24)&0xff000000)\ + |(((b)<<16)&0x00ff0000)\ + |(((c)<< 8)&0x0000ff00)\ + |( (d) &0x000000ff)) + +#endif + /* __UTIL_H__ */ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/version.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/version.h new file mode 100644 index 0000000..c46a6e1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/version.h @@ -0,0 +1,305 @@ +#ifndef __VERSION_H__ +#define __VERSION_H__ +#include "correct_bug.h" //BUG FIX +#include "common.h" +#include "longzoro/version.h" +#include "longzoro/debug.h" + +/* ģ */ +//#define _EPOLL_ET_MODE //EPOLL ETģ +//#define _EPOLL_POOL_COUNT 5 //̳߳ + +/*Server 汾*/ +#define _NEW_SERVER_ +#define _SERVER_NUMS + +#define UNIQUE_KEYCODEITEM 100 +#define UNIQUE_KEYCODEPET "i" + +#define _FAMILY_MANORNUM_CHANGE // CoolFish ޸װ԰(4.0) +#ifdef _FAMILY_MANORNUM_CHANGE +#define FAMILY_MAXHOME MANOR_MAX_NUM // (4.0) ݵ +#define MANORNUM MANOR_MAX_NUM // (4.0) ׯ԰ +#define FMPOINTNUM MANOR_MAX_NUM // (4.0) оݵ +#endif +#define _FMVER21 // (ɿ) ְƹ +#define _PERSONAL_FAME // (ɿ) Arminius 8.30 +// ------------------------------------------------------------------- +//רʯԶ Ա + +//#define _COMFIRM_TRADE_REQUEST //սȷ + +#define _EVERYONE_RIDE // (ɿ) Robin 0924 ƽ +// ------------------------------------------------------------------- +//ר Ա־ +#define _ATTACK_MAGIC // (ɿ) ṩսеĹ +#define _ADD_ACTION // (ɿ) һNPC״趨 + +// ------------------------------------------------------------------- +//ר߱ ԱС +#define _UNIQUE_P_I // (ɿ) CoolFish 2001/10/11 + +// ------------------------------------------------------------------- +//ר°ﴢpn ˷ 1018 Աѫ +#define _NEWSAVE // (ɿ) Robin +#define _STORECHAR // (ɿ) Robin +#define _DROPCHECK // (ɿ) Robin ֹظ +#define _DROPCHECK2 // (ɿ) Robin ֹظ +// ------------------------------------------------------------------- +//ר : Ա : +#define _PET_TRANS // (ɿ) ת +#define _NEW_WARPMAN // (ɿ) NPCWARP +#define _PET_TALK // (ɿ) Ի +#define _PET_LIMITLEVEL // (ɿ) () +#define _MAP_NOEXIT // (ɿ) ͼԭ&ԭǻָ +// ------------------------------------------------------------------- +// רGMָ㼶Reload ԱС +#define _GMRELOAD // (ɿ) CoolFish: 2001/11/12 +// ------------------------------------------------------------------- +// ר½ ԱС +#define _GAMBLE_ROULETTE // (ɿ) ij С +#define _FIX_GAMBLENUM // (ɿ) : ߿ۻ +#define _GAMBLE_BANK // (ɿ) ij +#define _DROPSTAKENEW // (ɿ) CoolFish: ijע +#define _PETRACE // (ɿ) CoolFish: 2001/12/3 ᄎٳ +#define _NEWEVENT // (ɿ) CoolFish: 2001/12/5 µ +// ------------------------------------------------------------------- +//ר Ա +#define _ITEM_FIRECRACKER // (ɿ) սʹñڿ԰ +// ------------------------------------------------------------------- +//¹ܣׯ԰PK(綨) Ա־ΰ־ +#define _MANOR_PKRULE // (ɿ) +// ------------------------------------------------------------------- +// ¹ܣ¹&\ Ա +#define _PSKILL_FALLGROUND // (ɿ) \ () +#define _ENEMY_FALLGROUND // (ɿ) NPC +#define _Item_MoonAct // (ɿ) ػ +#define _Item_DeathAct // (ɿ) ħ +#define _Item_PetAct // (ɿ) ѱ޽ָ +#define _Item_ReLifeAct // (ɿ) Ҫitemset1.txt ܿ) +#define _BATTLESTEAL_FIX // (ɿ) ͵ +#define _CFREE_petskill // (ɿ) Ҫpetskill1.txt ܿ) ѧϰ\ܼ +#define _data_newreadfile // (ɿ) µserver setup.cf itemset1.txt petskill1.txt µ +#define _ITEM_MAXUSERNUM // (ɿ) itemset1.txt ITEM ʹô +// ------------------------------------------------------------------- +//¹ܣ Ա +#define _PET_TALKPRO // (ɿ) Իǿ & END +#define _PRO_NPCFIX // (ɿ) NPCܼǿ +#define _PRO_BATTLEENEMYSKILL // (ɿ) սǿ NPCAI +#define _NEW_WARPPOINT // (ɿ) ͵жWARP +#define _FIX_CHECKITEM // (ɿ) ߲Ƿ +// ------------------------------------------------------------------- +//¹ܣ ԱС,WON +#define _ADD_ENCOUNT // (ɿ) WON ӵ޼ +#define _WON_PET_MAIL_LOG // (ɿ) WON Ҽij LOG +// ------------------------------------------------------------------- +// ¹ܣ 4.0 Ա, ־ΰ , , ־ +//#define _LOSE_FINCH_ // (ɿ) ANDY ȸ +#define _ADD_POOL_ITEM // (ɿ) WON ӿɼķŵĵ +#define _ITEM_METAMO // (ɿ) shan metamo sprite. code:robin->shan +#define _ENEMY_ATTACK_AI // (ɿ) shan enemy attack mode. code:shan +#define _ITEM_TIME_LIMIT // (ɿ) shan time limit of item. code:shan +#define _MIND_ICON // (ɿ) shan show icon from char mind. code:shan +#define _BATTLENPC_WARP_PLAYER // (ɿ) shan npc warp player when n round. code:shan +#define _ITEM_WARP_FIX_BI // (ɿ) shan fix bbi to bi. code:shan +#define _SKILL_DAMAGETOHP // (ɿ) ANDY Ѫ +#define _Skill_MPDAMAGE // (ɿ) ANDY MP˺ +#define _WAEI_KICK // (ɿ) ANDY +#define _BATTLE_TIMESPEED // (ɿ) ANDY սʱ (ؿٹ) +#define _FIXBUG_ATTACKBOW // (ɿ) ANDY ʹͶbug +#define _NPCCHANGE_PLAYERIMG // (ɿ) ANDY NPCıͼ, ǿ,ͼ () +#define _EQUIT_DEFMAGIC // (ɿ) ANDY ħװ +#define _FIX_MAGICDAMAGE // (ɿ) ANDY ħʽ ڿ +#define _ITEM_CONSTITUTION // (ɿ) ANDY +#define _MAGIC_REHPAI // (ɿ) ANDY ѪAI +#define _TRANSER_MAN // (ɿ) ANDY ʦ +#define _FIX_FIRECRACKER // (ɿ) ANDY +#define _FIX_ITEMPROB // (ɿ) ANDY +#define _ADD_DEAMGEDEFC // (ɿ) ANDY ˺ & ӹ ITEMSET2 +#define _FIX_MAXCHARMP // (ɿ) ANDY MP +#define _ITEM_INSLAY // (ɿ) ANDY ⱦʯ +#define _ITEMSET2_ITEM // (ɿ) ANDY ITEMSET2 +#define _ITEM_NPCCHANGE // (ɿ) ANDY (, ) +#define _FIX_SETWORKINT // (ɿ) ANDY (FIXWORKINT) +#define _ITEM_ADDEXP // (ɿ) vincent :ָʱӾֵ +#define _ITEM_ADDEXP2 // ǹʱۼ Robin +#define _FIX_METAMORIDE // (ɿ) ANDY +#define _SKILL_WILDVIOLENT_ATT // (ɿ) vincent 輼:񱩹 +#define _MAGIC_WEAKEN // (ɿ) vincent : +#define _SKILL_WEAKEN // (ɿ) vincent 輼://Ҫ#define _MAGIC_WEAKEN +#define _SKILL_SPEEDY_ATT // (ɿ) vincent 輼:ٹ +#define _SKILL_GUARDBREAK2 // (ɿ) vincent 輼:Ƴ2 +#define _SKILL_SACRIFICE // (ɿ) vincent 輼:Ԯ +#define _PSKILL_MODIFY // (ɿ) ANDY ǿ +#define _PSKILL_MDFYATTACK // (ɿ) ANDY ת +#define _MAGIC_DEFMAGICATT // (ɿ) ANDY ħ +#define _MAGIC_SUPERWALL // (ɿ) ANDY ڷ +#define _OTHER_MAGICSTAUTS // (ɿ) ANDY +#define _SKILL_TOOTH // (ɿ) ANDY +#define _MAGIC_DEEPPOISON // (ɿ) vincent :綾 +#define _MAGIC_BARRIER // (ɿ) vincent :ħ +#define _MAGIC_NOCAST // (ɿ) vincent :Ĭ +#define _ITEM_CRACKER // (ɿ) vincent : //Ҫ#define _MIND_ICON +#define _SKILL_DEEPPOISON // (ɿ) vincent 輼:綾 //Ҫ#define _MAGIC_DEEPPOISON +#define _SKILL_BARRIER // (ɿ) vincent 輼:ħ //Ҫ#define _MAGIC_BARRIER +#define _SKILL_ROAR // (ɿ) vincent 輼:() +#define _SKILL_REFRESH // (ɿ) vincent 輼:쳣״̬ +#define _ITEM_REFRESH // (ɿ) vincent 쳣״̬ +#define _MAGIC_TOCALL // (ɿ) kjl ٻ 02/06/20 kjl + +// ------------------------------------------------------------------- +// ¹ܣ Ա +#define _ITEMSET3_ITEM // (ɿ) ANDY itemset3.txt +#define _SUIT_ITEM // (ɿ) ANDY (װ) itemset3.txt +#define _PETSKILL_SETDUCK // (ɿ) ANDY 漼 +#define _VARY_WOLF // (ɿ) pet skill : vary wolf. code:shan +// ------------------------------------------------------------------- +// ¹ܣר5.0 Ա +#define _USEWARP_FORNUM // (ɿ) ANDY ë +#define _IMPRECATE_ITEM // (ɿ) ANDY +#define _MAGICPET_SKILL // (ɿ) ANDY ħ輼 +#define _ITEM_CHECKWARES // (ɿ) ANDY Ͳ +#define _NPC_REPLACEMENT // (ɿ) ANDY ûսnpc +#define _TYPE_TOXICATION // (ɿ) ANDY ж޷Ѫ + +// ------------------------------------------------------------------- +// ¹ܣ5.0׷Ӳ Ա +#define _AVID_TRADETRYBUG // (ɿ) ANDY ֹж/ ()ʼ ʯ +#define _ASSESS_SYSEFFICACY // (ɿ) ANDY ϵͳЧ 12/04 +#define _ASSESS_SYSEFFICACY_SUB // (ɿ) Robin ϵͳЧ ӼڻȦ +#define _ITEM_ORNAMENTS // (ɿ) ANDY װε 12/04 //沿 +#define _CHIKULA_STONE // (ɿ) ANDY ֮ʯ 12/04 // +#define _SEND_EFFECT // (ɿ) WON ACѩЧ 12/04 +#define _PETMAIL_DEFNUMS // (ɿ) ANDY ʼ +#define _PETSKILL_TIMID // (ɿ) ANDY 輼-ս +#define _PETS_SELECTCON // (ɿ) ANDY ﲻɵѡս +#define _CHRISTMAS_REDSOCKS // (ɿ) ANDY ʥ +#define _FIX_ARRAYBUG // (ɿ) ANDY array λ +#define _USER_CHARLOOPS // (ɿ) ANDY LOOP +#define _BATTLE_PROPERTY // (ɿ) ANDY ս +#define _PETSKILL_PROPERTY // (ɿ) ANDY ħ޳輼 +#define _ITEM_FIXALLBASE // (ɿ) ANDY ޸֮ʯ +#define _ITEM_LOVERPARTY // (ɿ) ANDY ˽ڵ +#define _ITEM_FORUSERNAMES // (ɿ) ANDY +#define _BATTLECOMMAND_TIME // (ɿ) ANDY ֹҿ(غսʱ) +#define _NPCENEMY_ADDPOWER // (ɿ) ANDY ޸Ĺֵ + + +// ------------------------------------------------------------------- +// ¹ܣר6.0 Ա +// +#define _PETSKILL_CANNEDFOOD // (ɿ) ANDY \ܹͷ for 6.0 +#define _TEST_DROPITEMS // (ɿ) ANDY Զ +#define _MAP_WARPPOINT // (ɿ) ANDY Map WarpPoint +#define _BENEMY_EVENTRUN // (ɿ) ANDY սnpc +#define _BATTLE_ABDUCTII // (ɿ) ANDY ;ⷰ2 +#define _BATTLE_LIGHTTAKE // (ɿ) ANDY ɹ +#define _BATTLE_ATTCRAZED // (ɿ) ANDY +#define _CAPTURE_FREES // (ɿ) ANDY ץ +#define _THROWITEM_ITEMS // (ɿ) нƷ +//-------------------------------------------------------------------------- +//ר 7.0 ְҵϵͳ Ա ־ +#define _ACFMPK_LIST // (ɿ) ANDY սб +#define _PETSKILL2_TXT // (ɿ) ANDY petskill2.txt +#define _PETSKILL_CHECKTYPE // (ɿ) ANDY \ʹʱ +#define _PETSKILL_TEAR // (ɿ) ANDY 輼 ˺˿ +#define _ITEMSET4_TXT // (ɿ) ANDY itemset4.txt +#define _PET_LOSTPET // (ɿ) ANDY ʧѰƻ +#define _ITEMSET5_TXT // (ɿ) ANDY itemset5.txt +#define _ITEMSET6_TXT // (ɿ) ANDY itemset6.txt +#define _EQUIT_SEQUENCE // (ɿ) ANDY ˳ Ҫ itemset5.txt +#define _EQUIT_HITRIGHT // (ɿ) ANDY Ҫ itemset5.txt +#define _EQUIT_NEGLECTGUARD // (ɿ) ANDY Ŀ% Ҫ itemset6.txt +#define _FIX_MAX_GOLD // (ɿ) WON ADD Ǯ +#define _PET_SKILL_SARS // (ɿ) WON ADD ɷ +#define _SONIC_ATTACK // (ɿ) WON ADD +#define _NET_REDUCESEND // (ɿ) ANDY DBϴ +#define _FEV_ADD_NEW_ITEM // (ɿ) Change Ӹؾ +#define _LOCKHELP_OK // (ɿ) Syu ADD ɼս +//ϵͳ +#define _SIMPLIFY_ITEMSTRING // (ɿ) ANDY 򻯵ִ + +#define _SIMPLIFY_PETSTRING // (ɿ) ANDY 򻯳浵ִ +#define _SIMPLIFY_ITEMSTRING2 // (ɿ) ANDY 򻯵ִ2 +#define _WOLF_TAKE_AXE // (ɿ) WON ADD ץ˫ͷǵ +#define _FIX_UNNECESSARY // (ɿ) ANDY Ҫж +#define _ITEM_MAGICRECOVERY // (ɿ) ANDY ¹⾵ +//9/17 +#define _PETSKILL_GYRATE // (ɿ) Change 輼: +#define _PETSKILL_RETRACE // (ɿ) Change 輼:׷ +#define _PETSKILL_HECTOR // (ɿ) Change 輼: +//10/13 +#define _PETSKILL_FIREKILL // (ɿ) Change 輼:ɱ +#define _PETSKILL_DAMAGETOHP // (ɿ) Change 輼:¿(Ѫı) +#define _PETSKILL_BECOMEFOX // (ɿ) Change 輼:Ļ + +//11/12 +#define _PETSKILL_SHOWMERCY // (ɿ) Change 輼: +#define _NPC_ActionFreeCmp // (ɿ) Change NPCµıȽϷʽ +//-------------------------------------------------------------------------- + + +//11/26 +#define _NPC_NewDelPet // (ɿ) Change NPCɾ(ԭ,ֻwarpmanʹʱɹ,һһ) + +//20031217 +#define _CHRISTMAS_REDSOCKS_NEW // (ɿ) Change ʥ +#define _PETSKILL_COMBINED // (ɿ) Change 輼:ѵúͿ [ۺħ(ȡħ)] +//˽ڻ +#define _NPC_ADDWARPMAN1 // (ɿ) Change npcgen_warpmanӹ(趨趨Ů) +#define _ITEM_QUITPARTY // (ɿ) Change ɢʱض߼ʧ +#define _ITEM_ADDEQUIPEXP // (ɿ) Change װᾭֵ +//2004/2/18 +#define _ITEM_LVUPUP // (ɿ) Change ͻƳȼƵҩ(ר) +//2004/02/25 +#define _PETSKILL_BECOMEPIG // (ɿ) Change 輼: +#define _ITEM_UNBECOMEPIG // (ɿ) Change Ľҩ +#define _PET_TALKBBI // (ɿ) Change жbbi +#define _ITEM_USEMAGIC // (ɿ) Change ɵʹħ +//2004/04/07 +#define _ITEM_PROPERTY // (ɿ) Change ıԵ +#define _SUIT_ADDENDUM // (ɿ) Change װӹ (_SUIT_ITEMҪ) +//2004/05/05 +#define _ITEM_CHECKDROPATLOGOUT // (ɿ) Change ؼ¼ʱ޵dzʧ,,ɻؼ¼ +#define _FM_MODIFY // 幦޸() +#define _PETSKILL_OPTIMUM // Robin \ܴѻ +#define _MAGIC_OPTIMUM // Robin Magic table ѻ +#define _AC_PIORITY // Nuke ACȨ(ɿ) +// ------------------------------------------------------------------- +//ר 7.5 л Աѫ С +// Terry define start ------------------------------------------------------------------- +#define _MAP_TIME // ͼ,ᵹ() + +// Terry define end ------------------------------------------------------------------- +#define _ITEM_ADDPETEXP // (ɿ) Change ӳᆳֵ(ɳԴ˵߳,ƽɻþֵ) +#define _TRANS_6 // (ɿ) Change 6ת +#define _PET_2TRANS // (ɿ) Change 2ת +#define _PET_2LIMITLEVEL // (ɿ) Change 2ת +#define _MAGICSTAUTS_RESIST // (ɿ) Change ()Ծ +#define _SUIT_TWFWENDUM // (ɿ) Change װ (_SUIT_ITEMҪ) +#define _EXCHANGEMAN_REQUEST_DELPET // (ɿ) Change exchangemanTYPE:REQUESTɾ +//-------------------------------------------------------------------------- +#define _DEL_DROP_GOLD // ɾϹʱʯ Robin +#define _ITEM_STONE // cyg ֵʯͷ +#define _HELP_NEWHAND // cyg ´ɫֵ) +#define _DEF_GETYOU // cyg GMָ ѯԼ Χڵʺ +#define _DEF_NEWSEND // cyg GMָ ʱɼӾҲɲ +#define _DEF_SUPERSEND // cyg GMָ ɴijʺΪĸ3 +#define _SUIT_ADDPART3 // (ɿ) Change װܵ ر% Ĭ% % % % +#define _PETSKILL_2TIMID // (ɿ) Change սڶ(ʨŭ) +#define _TIME_TICKET // Robin ʱ볡 ɭ׽ +#define _HALLOWEEN_EFFECT // ʥЧ +#define _ADD_reITEM // (ɿ) Change λո +#define _ADD_NOITEM_BATTLE // NPCû߻ս +#define _PETSKILL_BATTLE_MODEL // \սģ +#define _PETSKILL_ANTINTER // (ɿ) Change 輼:֮ ο_PETSKILL_2TIMID +#define _PETSKILL_REGRET // (ɿ) Change 輼:һ ο_SONIC_ATTACK +#define _FIX_FAMILY_PK_LIMIT // (ɿ) WON սׯ԰ǰʮΪǰʮ +// +#define _NEWOPEN_MAXEXP // (ɿ) ANDY MAXֵ +#define _CHAR_FIXDATADEF // (ɿ) ANDY ϳʼ +#define _NPC_EXCHANGEMANTRANS // (ɿ) Change exchangemanжת +#define _ADD_NEWEVENT +#define _BATTLE_NEWPOWER // (ɿ) +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/version_pk.h b/石器时代服务器端最新完整源代码/Serv/gmsv/include/version_pk.h new file mode 100644 index 0000000..dd5b101 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/include/version_pk.h @@ -0,0 +1,9 @@ +#ifndef _PKSERVER_VERSION_H_ +#define _PKSERVER_VERSION_H_ + +//#define _PKSEVER_VER // (ɿ) ϵpkŷ + +// +// +//ּ +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/include/vssver.scc b/石器时代服务器端最新完整源代码/Serv/gmsv/include/vssver.scc new file mode 100644 index 0000000..2902d88 Binary files /dev/null and b/石器时代服务器端最新完整源代码/Serv/gmsv/include/vssver.scc differ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/init.c b/石器时代服务器端最新完整源代码/Serv/gmsv/init.c new file mode 100644 index 0000000..2d60ba3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/init.c @@ -0,0 +1,886 @@ +#include "version.h" +#include +#include +#include +#include +#include +#include +#include + +#include "configfile.h" +#include "util.h" +#include "net.h" +#include "msignal.h" +#include "buf.h" +#include "object.h" +#include "char.h" +#include "char_data.h" +#include "item.h" +#include "readmap.h" +#include "function.h" +#include "saacproto_cli.h" +#include "lssproto_serv.h" +#include "readnpc.h" +#include "log.h" +#include "handletime.h" +#include "title.h" +#include "encount.h" +#include "enemy.h" +#include "battle.h" +#include "magic_base.h" +#include "pet_skill.h" +#include "item_gen.h" +#include "petmail.h" +#include "npc_quiz.h" +#include "char_talk.h" +#ifdef _TALK_MOVE_FLOOR +#include "longzoro/move.h" +#endif +#ifdef _LUCK_STAR +#include "longzoro/luckstar.h" +#endif +#include "autil.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/mylua.h" +#endif +#ifdef _ONLINE_SHOP +#include "longzoro/newshop.h" +#endif + +#ifdef _ITEM_QUITPARTY +#include "init.h" +//int itemquitparty_num = 0; +//static DisappearItem *Disappear_Item; +#endif + +#ifdef _EPOLL_ET_MODE +#include "epollnet.h" +#endif + + +#define MESSAGEFILE "hoge.txt" + +#define OPTIONSTRING "d:f:hcl" +#define usage() print( "Usage: %s ["OPTIONSTRING"]\n", getProgname() ); + +void printUsage( void ) +{ + usage(); + /*print( "Usage: %s ["OPTIONSTRING"]\n", progname );*/ + print( " [-d debuglevel] default value is 0\n" ); + print( " [-f configfilename] default value is setup.cf\n" + ); +} + +/* + * + * ¦ + * ߯Ի + * TRUE(1) ئѨ̼¦ѷ + * FALSE(0) ئѨ̼¦ѷ + */ +BOOL parseCommandLine( int argc , char** argv ) +{ + int c; /* getopt ƥ */ + extern char* optarg; /* getopt ƥ */ + + + while( ( c = getopt( argc, argv ,OPTIONSTRING )) != -1 ){ + switch( c ){ + case 'd': + { + int debuglevel; + if( !strtolchecknum( optarg, (int*)&debuglevel, 10, + INT)){ + print( "Specify digit number\n" ); + return FALSE; + } + setDebuglevel( debuglevel ); + break; + } + case 'f': + setConfigfilename( optarg ); + break; + case 'h': + printUsage(); + return FALSE; + break; + case 'c': +#ifdef _CRYPTO_DATA + if(opendir("allblues")==NULL){ + if (mkdir("allblues", 0777) == 0){ + printf("ļ allblues\n"); + } + } + if(opendir("allblues/data")==NULL){ + if (mkdir("allblues/data", 0777) == 0){ + printf("ļ data\n"); + } + } + List("data"); + printf("dataɣallbluesļ\n"); + return FALSE; +#endif + break; +#ifdef _CRYPTO_LUA + case 'l': + { + int flg = 0,id = 0; + printf("Ҫܻǽܣ(0Ϊ, 1Ϊ):"); + scanf("%d", &flg); + printf("IDǶ:"); + scanf("%d", &id); + CryptoAllbluesLUA("allblues", flg, id); + if(flg == 0){ + printf("ɽܹ\n"); + }else{ + printf("ɼܹ\n"); + } + return FALSE; + } + break; +#endif + default: + printUsage(); + return FALSE; + break; + + } + } + return TRUE; +} + + +/* + * ¦ + * + * ἰئ + */ +BOOL parseEnvironment( char** env ) +{ + if( getDebuglevel() >= 3 ){ + int index=0; + while( env[index] != NULL )print( "%s " , env[index++] ); + print( "\n" ); + } + return TRUE; +} + +extern int backdoor; + +#define GOTORETURNFALSEIFFALSE(x) if(!(x))goto RETURNFALSE +/* + * + * ¦ + * argc argv + * argv Ѩ̼¦ + * ߯Ի + */ +BOOL init(int argc , char** argv , char** env ) +{ +#ifdef _ITEM_QUITPARTY + FILE *f; + int i; + char line[256]; +#endif + srand( getpid()); + print( "This Program is compiled at %s %s by gcc %s\n", + __DATE__ , __TIME__ , __VERSION__ ); + + defaultConfig( argv[0] ); + GOTORETURNFALSEIFFALSE(parseCommandLine( argc , argv )); + GOTORETURNFALSEIFFALSE(parseEnvironment( env )); + + signalset(); + + + { + Char aho; + debug( sizeof( aho ), d); + debug( sizeof( aho.data ), d); + debug( sizeof( aho.string ), d); + debug( sizeof( aho.flg ),d); + debug( sizeof( aho.indexOfExistItems ), d); + debug( sizeof( aho.haveSkill ), d); + debug( sizeof( aho.indexOfHaveTitle ), d); + debug( sizeof( aho.addressBook ),d); + debug( sizeof( aho.workint ),d); + debug( sizeof( aho.workchar ),d); + } + + print( "ļ: %s\n" , getConfigfilename() ); + + GOTORETURNFALSEIFFALSE(readconfigfile( getConfigfilename() ) ); + + nice(getrunlevel()); + //ttom start + { int iWork = setEncodeKey(); + if( iWork == 0 ){ + // ޼ƽëɬ + printf( "----------------------------------------\n" ); + printf( "-------------[] ޷ %s\n", getConfigfilename() ); + printf( "----------------------------------------\n" ); + exit( 1 ); + }else{ + // ޼ƽëɬ + printf( " = %d\n", iWork ); + } + } + // AcWBuffëɬ + { int iWork = setAcWBSize(); + if( iWork == 0 ){ + printf( "----------------------------------------\n" ); + printf( "-------------[AC] ޷ %s\n", getConfigfilename() ); + printf( "----------------------------------------\n" ); + exit( 1 ); + }else{ + printf( "AC = %d\n", iWork ); + } + } + //ttom end + + if( getDebuglevel() >= 1 ){ +// print("ServerType: %d\n", getServerType() ); + print("Եȼ: %d\n", getDebuglevel() ); + print("еȼ: %d\n", getrunlevel() ); + print("ջ: %d\n", getrecvbuffer()*1024); + print("ͻ: %d\n", getsendbuffer()*1024); + print("ջ: %d\n", getrecvlowatbuffer()); + print("ڴ浥ԪС: %d\n", getMemoryunit() ); + print("ڴ浥Ԫ: %d\n", getMemoryunitnum() ); + + print("˺ŷַ: %s\n", getAccountservername() ); + print("˺ŷ˿: %d\n", getAccountserverport() ); + print("½: %s\n", getGameservername()); + print("½: %s\n", getAccountserverpasswd()); + + print("ȴӶ˿: %d\n", getPortnumber() ); + + print("к: %d\n", getServernumber() ); + + print("ظַʹ: %d\n", getReuseaddr() ); + + + print(": %d\n", getFdnum() ); + print("߳: %d\n", getPetcharnum() ); + print("Ŀ: %d\n", getOtherscharnum() ); + print("Ŀ: %d\n", getObjnum() ); + print("ƷĿ: %d\n", getItemnum() ); + print("սĿ: %d\n", getBattlenum() ); + print("ļĿ¼: %s\n", getTopdir()); + print("ͼļĿ¼: %s\n", getMapdir()); + print("ͼʶļ: %s\n", getMaptilefile()); + print("Ʒļ: %s\n", getItemfile()); + print("սļ: %s\n", getInvfile()); + print("ʾλļ: %s\n", getAppearfile()); + print("ļ: %s\n", getEffectfile()); + print("ͷļ: %s\n", getTitleNamefile()); + print("ͷļ: %s\n", getTitleConfigfile()); + print("ļ: %s\n", getEncountfile()); + print("Ⱥļ: %s\n", getGroupfile()); + print("ļ: %s\n", getEnemyBasefile()); + print("ļ: %s\n", getEnemyfile()); + print("ħļ: %s\n", getMagicfile()); + +#ifdef _ATTACK_MAGIC + print("ħļ: %s\n", getAttMagicfileName() ); +#endif + + print("\ļ: %s\n", getPetskillfile()); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + print("ְҵļ: %s\n", getProfession()); +#endif + + print("Ʒɷļ: %s\n", getItematomfile()); + print("ļ: %s\n", getQuizfile()); +#ifdef _GMRELOAD + print("G M ļ: %s\n", getGMSetfile()); +#endif + print("־¼ļ: %s\n", getLsgenlogfilename() ); + print("ԭĿ¼: %s\n", getStoredir()); + print("NPC Ŀ¼: %s\n", getNpcdir()); + print("־ļ: %s\n", getLogdir()); + print("־ļ: %s\n", getLogconffile() ); + print("GMָ: %s\n", getChatMagicPasswd() ); + print("ʹGMȨ: %d\n", getChatMagicCDKeyCheck() ); + + print("NPC ģĿ: %d\n", getNpctemplatenum() ); + print("NPC Ŀ: %d\n", getNpccreatenum() ); + + print("·ʱ: %d\n", getWalksendinterval()); + print("м: %d\n", getCAsendinterval_ms()); + print("Ŀ: %d\n", getCDsendinterval_ms()); + print("ִһʱ: %d\n", getOnelooptime_ms()); + print("ʱ: %d\n", getPetdeletetime()); + print("ʱ: %d\n", getItemdeletetime()); +#ifdef _DEL_DROP_GOLD + print("ʯʱ: %d\n", getGolddeletetime()); +#endif + print("ݱ: %d\n", getCharSavesendinterval()); + + print("ƬĿ: %d\n", getAddressbookoffmsgnum()); + print("ȡƵЭ: %d\n" ,getProtocolreadfrequency()); + + print("Ӵ: %d\n", getAllowerrornum()); +#ifdef _GET_BATTLE_EXP + print("ս鱶: %d\n", getBattleexp() ); +#endif +#ifdef _NEW_PLAYER_CF + print("ת: %dת\n", getNewplayertrans()); + print("ȼ: %d\n", getNewplayerlv()); + print("Ǯ: %d S\n", getNewplayergivegold()); + print("ȼ: %d\n", getNewplayerpetlv()); +#ifdef _VIP_SERVER + print("ӵе: %d\n", getNewplayergivevip()); +#endif + print("ȼ: %d\n", getRidePetLevel()); +#ifdef _NEW_PLAYER_RIDE + print(": %s\n", getPlayerRide()); +#endif + print("ӵг: NO1:%d NO2:%d NO3:%d NO4:%d NO5:%d\n",getNewplayergivepet(0), + getNewplayergivepet(1), + getNewplayergivepet(2), + getNewplayergivepet(3), + getNewplayergivepet(4)); + print("ӵƷ: ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n" + "ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n" + "ITEM1:%d ITEM2:%d ITEM3:%d ITEM4:%d ITEM5:%d\n" + ,getNewplayergiveitem(0) + ,getNewplayergiveitem(1) + ,getNewplayergiveitem(2) + ,getNewplayergiveitem(3) + ,getNewplayergiveitem(4) + ,getNewplayergiveitem(5) + ,getNewplayergiveitem(6) + ,getNewplayergiveitem(7) + ,getNewplayergiveitem(8) + ,getNewplayergiveitem(9) + ,getNewplayergiveitem(10) + ,getNewplayergiveitem(11) + ,getNewplayergiveitem(12) + ,getNewplayergiveitem(13) + ,getNewplayergiveitem(14)); +#endif +#ifdef _UNREG_NEMA + print("ֹ: 1:%s 2:%s 3:%s 4:%s 5:%s\n",getUnregname(0), + getUnregname(1), + getUnregname(2), + getUnregname(3), + getUnregname(4)); +#endif + +#ifdef _WATCH_FLOOR + print("Ƿȫͼս: %s\n",getWatchFloorCF()); + if(strcmp(getWatchFloorCF(),"")) + print("սͼ: ͼ1:%d ͼ2:%d ͼ3:%d ͼ4:%d ͼ5:%d\n",getWatchFloor(1), + getWatchFloor(2), + getWatchFloor(3), + getWatchFloor(4), + getWatchFloor(5)); +#endif + +#ifdef _BATTLE_FLOOR + print("Ƿǿս: %s\n",getBattleFloorCF()); + if(strcmp(getBattleFloorCF(),"")) + print("ǿսͼ: ͼ1:%d ͼ2:%d ͼ3:%d ͼ4:%d ͼ5:%d\n",getBattleFloor(1), + getBattleFloor(2), + getBattleFloor(3), + getBattleFloor(4), + getBattleFloor(5)); +#endif + +#ifdef _TRANS_LEVEL_CF + print("ȼת: %d\n",getChartrans()); + print("ȼת: %d\n",getPettrans()); +#endif + +#ifdef _POINT + print("ֹ: %s\n",getPoint()); + if(strcmp(getPoint(),"")) + print("ÿת: 0ת:%d 1ת:%d 2ת:%d 3ת:%d 4ת:%d 5ת:%d 6ת:%d\n",getTransPoint(0), + getTransPoint(1), + getTransPoint(2), + getTransPoint(3), + getTransPoint(4), + getTransPoint(5), + getTransPoint(6)); +#endif + +#ifdef _PET_AND_ITEM_UP + print("ܷ: %s\n",getPetup()); + print("ܷ: %s\n",getItemup()); +#endif +#ifdef _LOOP_ANNOUNCE + print("ѭ·: %s\n",getLoopAnnouncePath()); + print("ѭʱ: %d\n",getLoopAnnounceTime()); +#endif +#ifdef _SKILLUPPOINT_CF + print("ÿ: %d\n",getSkup()); +#endif + +#ifdef _RIDELEVEL + print("ȼ: %d\n",getRideLevel()); +#endif +#ifdef _REVLEVEL + print("ԭ޵ȼ: %s\n",getRevLevel()); +#endif +#ifdef _TRANS_LEVEL_CF + print("һȼ: %d\n",getYBLevel()); + print("ߵȼ: %d\n",getMaxLevel()); +#endif +#ifdef _FIX_CHARLOOPS + print("ħʱ䱶: %d\n",getCharloops()); +#endif +#ifdef _PLAYER_ANNOUNCE + if(getPAnnounce()==-1) + print("ĵ: رʹ\n"); + else + print("ĵ: %d\n",getPAnnounce()); +#endif +#ifdef _PLAYER_MOVE + if(getPMove()==-1) + print("˳ĵ: رʹ\n"); + else + print("˳ĵ: %d\n",getPMove()); +#endif +#ifdef _BATTLE_GOLD + print("սýǮ: %d\n",getBattleGold()); +#endif +#ifdef _ANGEL_TIME + print("ٻʱ: (%d/)\n",getAngelPlayerTime()); + print("ٻ: %d\n",getAngelPlayerMun()); +#endif +#ifdef _RIDEMODE_20 + print("2.0 ģʽ: %d\n",getRideMode()); +#endif +#ifdef _FM_POINT_PK + print("ׯ԰ģʽ: %s\n",getFmPointPK()); +#endif + } + + { //andy_add 2003/05/05 check GameServer Name + char *GameServerName; + GameServerName = getGameserverID(); + if( GameServerName == NULL || strlen( GameServerName) <= 0 ) + return FALSE; + print("\nϷID: %s\n", GameServerName ); + } + + print("ʼʼ\n" ); + +//#define DEBUG1( arg... ) if( getDebuglevel()>1 ){##arg} + print( "ڴռ..." ); + GOTORETURNFALSEIFFALSE(configmem( getMemoryunit(), + getMemoryunitnum() ) ); + GOTORETURNFALSEIFFALSE(memInit()); + print( "\n" ); + + print( "ʼջӿռ..." ); + if( !initConnect(getFdnum()) ) + goto MEMEND; + print( "\n" ); + while( 1 ){ + print( "԰󶨱ض˿ %d... " , getPortnumber()); +#ifdef _EPOLL_ET_MODE + bindedfd = epoll_bind( getPortnumber() ); +#else + bindedfd = bindlocalhost( getPortnumber() ); +#endif + if( bindedfd == -1 ) + sleep( 10 ); + else + break; + } + print( "\n" ); + print( "..." ); + if( !initObjectArray( getObjnum()) ) + goto CLOSEBIND; + print( "\n" ); + + print( "..." ); +#ifdef _OFFLINE_SYSTEM + if(!CHAR_initCharArray( getPlayercharnum(), getPetcharnum(),getOtherscharnum()) ) +#else + if(!CHAR_initCharArray( getFdnum(), getPetcharnum(),getOtherscharnum()) ) +#endif + goto CLOSEBIND; + print( "\n" ); + print( "Ʒ..."); + if(!ITEM_readItemConfFile( getItemfile()) ) + goto CLOSEBIND; + if(!ITEM_initExistItemsArray( getItemnum() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ս..." ); + if(!BATTLE_initBattleArray( getBattlenum() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ģ..." ); + if( !initFunctionTable() ) + goto CLOSEBIND; + print( "\n" ); + + print( "ʼʼ..." ); + if( !PETMAIL_initOffmsgBuffer( getAddressbookoffmsgnum() )) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡսļ..." ); + if( !CHAR_initInvinciblePlace( getInvfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡʾλļ..." ); + if( !CHAR_initAppearPosition( getAppearfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡͷļ..." ); + if( !TITLE_initTitleName( getTitleNamefile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡͷļ..." ); + if( !TITLE_initTitleConfig( getTitleConfigfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡļ..." ); + if( !ENCOUNT_initEncount( getEncountfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡļ..." ); + if( !ENEMYTEMP_initEnemy( getEnemyBasefile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡļ..." ); + if( !ENEMY_initEnemy( getEnemyfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + print( "ȡȺļ..." ); + if( !GROUP_initGroup( getGroupfile() ) ) + goto CLOSEBIND; + print( "\n" ); + print( "ȡħļ..." ); + if( !MAGIC_initMagic( getMagicfile() ) ) + goto CLOSEBIND; + print( "\n" ); + + #ifdef _ATTACK_MAGIC + + print( "ȡħļ..." ); + + if( !ATTMAGIC_initMagic( getAttMagicfileName() ) ) +// if( !ATTMAGIC_initMagic( getMagicfile() ) ) + goto CLOSEBIND; + + print( "ħļ -->%s..." , getAttMagicfileName()); + print( "\n" ); + + #endif + + print( "ȡ\ļ..." ); + if( !PETSKILL_initPetskill( getPetskillfile() ) ) + goto CLOSEBIND; + print( "\n" ); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + print( "ȡְҵļ..." ); + if( !PROFESSION_initSkill( getProfession() ) ){ + goto CLOSEBIND; + } + print( "\n" ); +#endif + + /* ʧ ة ë */ + print( "ȡƷɷļ..." ); + if( !ITEM_initItemAtom( getItematomfile()) ) + goto CLOSEBIND; + print("\n" ); + + print( "ʼϳƷ..." ); + if( !ITEM_initItemIngCache() ) + goto CLOSEBIND; + print("\n" ); + + print( "ʼϳ趨..." ); + if( !ITEM_initRandTable() ) + goto CLOSEBIND; + print("\n" ); + + print( "ȡļ..." ); + if( !CHAR_initEffectSetting( getEffectfile() ) ) + goto CLOSEBIND; + print( "\n" ); + print( "ȡļ..." ); + if( !QUIZ_initQuiz( getQuizfile() ) ) + goto CLOSEBIND; + print( "\n" ); +#ifdef _GMRELOAD + print( "ȡGMļ..." ); + if ( !LoadGMSet( getGMSetfile() ) ) + goto CLOSEBIND; + print( "\n" ); +#endif + +#ifdef _USER_EXP_CF + print( "ȡļ..." ); + if ( !LoadEXP( getEXPfile() ) ) + goto CLOSEBIND; + print("ߵȼ: %d...",getMaxLevel()); + print("һȼ: %d...",getYBLevel()); + print( "\n" ); +#endif + +#ifdef _ANGEL_SUMMON + print("ȡٻбļ..."); + if( !LoadMissionList( ) ) + goto CLOSEBIND; + print("\n"); +#endif + +#ifdef _JOBDAILY + print("ȡ־ļ..."); + if(!LoadJobdailyfile()) + print("...ʧ\n"); + else + print("\n"); +#endif + +#ifdef _LOOP_ANNOUNCE + print("ȡѭļ..."); + if(!loadLoopAnnounce()) + print("...ʧ\n"); + else + print("\n"); +#endif +#ifdef _RIDE_CF + print( "ȡԶļ..." ); + if(!CHAR_Ride_CF_init()) + print("...ʧ\n"); + print("\n"); +#endif +#ifdef _FM_LEADER_RIDE + print( "ȡׯ԰峤רļ..." ); + if(!CHAR_FmLeaderRide_init()) + print("...ʧ\n"); + print("\n"); +#endif +#ifdef _RE_GM_COMMAND + print( "ԶGMļ..." ); + if(!re_gm_command()) + print("...ʧ\n"); + print("\n"); +#endif + +#ifdef _FIND_TREASURES + print( "ȡѰƷļ..." ); + if(!FindTreasures_init()) + print("...ʧ\n"); + print("\n"); +#endif + print( "ͼ..." ); + if( !MAP_initReadMap( getMaptilefile() , getMapdir() )) + goto CLOSEBIND; + print( "\n" ); + print( "ȡNPCļ..." ); + if( !NPC_readNPCSettingFiles( getNpcdir(), getNpctemplatenum(), + getNpccreatenum() ) ) + goto CLOSEBIND; + print( "\n" ); + +#ifdef _TALK_MOVE_FLOOR + print( "ȡ˵ƶͼļ..." ); + if(!MoveMap_init()) + print("...ʧ\n"); + print("\n"); +#endif + +#ifdef _LUCK_STAR + print( "ȡļ..." ); + if(!LuckStar_init()) + print("...ʧ\n"); + print("\n"); +#endif + +#ifdef _ONLINE_SHOP + print( "ȡ̳ļ..." ); + if(!OnlineShop_init()) + print("...ʧ\n"); + print("\n"); +#endif + +#ifdef _PLAYER_DIY_MAP + print( "ʼDIYͼ..." ); + if(!MAP_intPlayerMap()) + print("...ʧ\n"); + print("\n"); +#endif + +#ifdef _FILTER_TALK + print( "ȡ˵ļ..." ); + if(!ReadFilterTalk()) + print("...ʧ\n"); + print("\n"); +#endif + + print( "ʼ NPC ... " ); + if( lssproto_InitServer( lsrpcClientWriteFunc, LSGENWORKINGBUFFER ) < 0 ) + goto CLOSEBIND; + print( "\n" ); + print( "˺ŷ... " ); + acfd = connectHost( getAccountservername(), getAccountserverport()); + if(acfd == -1) + goto CLOSEBIND; + +#ifdef _EPOLL_ET_MODE + if(epoll_add_acfd(acfd) == -1) + goto CLOSEBIND; +#endif + +/* + { + int errorcode; + int errorcodelen; + int qs; + + errorcodelen = sizeof(errorcode); + qs = getsockopt( acfd, SOL_SOCKET, SO_RCVBUF , &errorcode, &errorcodelen); + //andy_log + print("\n\n GETSOCKOPT SO_RCVBUF: [ %d, %d, %d] \n", qs, errorcode, errorcodelen); + } +*/ + + print( "\n" ); + initConnectOne( acfd, NULL , 0 ); + if( !CONNECT_acfdInitRB( acfd)) goto CLOSEAC; + if( !CONNECT_acfdInitWB( acfd)) goto CLOSEAC; + CONNECT_setCtype( acfd, AC ); + + print( "ʼ ˺ ͻ ... " ); + if( saacproto_InitClient( lsrpcClientWriteFunc,LSGENWORKINGBUFFER, acfd) < 0 ) + goto CLOSEAC; + print( "\n" ); + + print( "˺ŷ͵½... " ); + /* ̼ۢë */ + { +#if _ATTESTAION_ID == 1 + saacproto_ACServerLogin_send(acfd, _ATTESTAION_ID, getGameservername(), getAccountserverpasswd()); +#else + saacproto_ACServerLogin_send(acfd, getGameservername(), getAccountserverpasswd()); +#endif + } + print( "\n" ); +#ifdef _OTHER_SAAC_LINK + OtherSaacConnect(); +#endif + + if( isExistFile( getLsgenlogfilename() ) ){ + lssproto_SetServerLogFiles( getLsgenlogfilename(), + getLsgenlogfilename() ); + saacproto_SetClientLogFiles( getLsgenlogfilename(), + getLsgenlogfilename() ); + } + + + print( "ʼ\n" ); + +#ifdef _LOTTERY_SYSTEM + saacproto_LotterySystem_send(); +#endif + print( "ʼѰµ־ ... " ); + { + char logconffile[512]; + snprintf( logconffile, sizeof( logconffile), "%s/%s" , + getLogdir(), getLogconffile() ); + if( !initLog( logconffile ) ) + goto CLOSEAC; + } + print( "\n" ); +#ifdef _PET_ITEM + restoreObjects( getStoredir() ); +#endif +#ifdef _ITEM_QUITPARTY + print( "ȡɢƷʧļ..." ); + + //ȡ +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", getitemquitparty()); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen( getitemquitparty(), "r" ); +} + if( f != NULL ){ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + itemquitparty_num++; + } + if( fseek( f, 0, SEEK_SET ) == -1 ){ + print( "Ʒ¼Ҵ\n" ); + fclose(f); + goto CLOSEAC; + } + // + Disappear_Item = allocateMemory( sizeof(struct tagDisappearItem) * itemquitparty_num ); + if( Disappear_Item == NULL ){ + print( "޷ڴ %d\n", sizeof(struct tagDisappearItem) * itemquitparty_num ); + fclose( f ); + goto CLOSEAC; + } + + i = 0; + //߱Ŵ Disappear_Item.string + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + sprintf( Disappear_Item[i].string,"%s",line ); + print("\n߱:%s", Disappear_Item[i].string ); + i++; + } + fclose(f); + } +#endif + + DEBUG_ADJUSTTIME = 0; + print( "\n" ); + return TRUE; + +CLOSEAC: + close( acfd ); +CLOSEBIND: + close( bindedfd ); + endConnect(); +MEMEND: + memEnd(); +RETURNFALSE: + return FALSE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/item/item.c b/石器时代服务器端最新完整源代码/Serv/gmsv/item/item.c new file mode 100644 index 0000000..0b22fa7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/item/item.c @@ -0,0 +1,2502 @@ +#include "version.h" +#include +#include +#include +#include +#include +#include "common.h" +#include "char.h" +#include "char_data.h" +#include "battle.h" +#include "item.h" +#include "buf.h" +#include "function.h" +#include "configfile.h" +#include "magic_base.h" +#include "autil.h" +#include "longzoro/version.h" +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#endif +#ifdef _ALLBLUES_LUA_1_2 +ITEM_LuaFunc ITEM_luaFunc; +#endif +static int ITEM_tblen = 0; +static int ITEM_idxlen = 0; +ITEM_exists* ITEM_item; +static int ITEM_itemnum; +static int ITEM_UseItemnum=0; +static char* ITEM_checkString( char* string ); +static int ITEM_getRandomValue( char* string,int* randomwidth, int num ); +static int ITEM_isstring1or0( char* string,int* randomwidth, int num ); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _SIMPLIFY_ITEMSTRING + +ITEM_intDataSetting ITEM_setintdata[]={ + {"id", 0, ITEM_ID }, + {"bi", 0, ITEM_BASEIMAGENUMBER }, + {"tg", 0, ITEM_TARGET }, +#ifdef _ITEM_MAXUSERNUM + {"dib", -1, ITEM_DAMAGEBREAK }, +#endif +#ifdef _ITEMSET4_TXT + {"upin", 1, ITEM_USEPILENUMS }, + //{"canpile", 0, ITEM_CANBEPILE }, +#endif + {"dmce", 0, ITEM_DAMAGECRUSHE }, + {"mdmce", 0, ITEM_MAXDAMAGECRUSHE }, +#ifdef _ADD_DEAMGEDEFC +#endif + {"ann", 0, ITEM_ATTACKNUM_MIN }, + {"anx", 0, ITEM_ATTACKNUM_MAX }, + {"ma", 0, ITEM_MODIFYATTACK }, + {"md", 0, ITEM_MODIFYDEFENCE }, + {"mh", 0, ITEM_MODIFYQUICK}, //ITEM_MODIFYHP }, ITEM_MODIFYQUICK + {"mm", 0, ITEM_MODIFYHP}, //ITEM_MODIFYMP }, ITEM_MODIFYHP + {"mq", 0, ITEM_MODIFYMP}, //ITEM_MODIFYQUICK }, ITEM_MODIFYMP + {"ml", 0, ITEM_MODIFYLUCK }, + {"mc", 0, ITEM_MODIFYCHARM }, + {"mv", 0, ITEM_MODIFYAVOID }, + {"mat", 0, ITEM_MODIFYATTRIB }, + {"mav", 0, ITEM_MODIFYATTRIBVALUE }, + {"mid", -1, ITEM_MAGICID }, + {"mpr", 0, ITEM_MAGICPROB }, + {"mu", 0, ITEM_MAGICUSEMP }, + {"ll", 0, ITEM_LEAKLEVEL }, + {"mrf", 0, ITEM_MERGEFLG }, + {"npo", 0, ITEM_POISON }, + {"npa", 0, ITEM_PARALYSIS }, + {"nsl", 0, ITEM_SLEEP }, + {"nst", 0, ITEM_STONE }, + {"ndr", 0, ITEM_DRUNK }, + {"nco", 0, ITEM_CONFUSION }, +#ifdef _ITEM_COLOER + {"coloer", 0, ITEM_COLOER }, /* ITEM_COLOER */ +#endif +#ifdef _ITEM_USE_TIME + {"usetime", 0, ITEM_USETIME }, /* ITEM_USETIME */ +#endif +}; + +ITEM_charDataSetting ITEM_setchardata[]={ + {"na", "", ITEM_NAME }, /* ITEM_NAME */ + {"sn", "", ITEM_SECRETNAME }, /* ITEM_SCRETNAME */ + {"en", "", ITEM_EFFECTSTRING }, /* ITEM_EFFECTSTRING */ + {"ar", "", ITEM_ARGUMENT }, /* ITEM_ARGUMENT */ +#ifdef _ITEM_INSLAY + {"acode", "", ITEM_TYPECODE }, /*ITEM_TYPECODE,*/ + {"inlaycode", "", ITEM_INLAYCODE }, /*ITEM_INLAYCODE,*/ +#endif + {"cdk", "", ITEM_CDKEY }, /* ITEM_CDKEY */ +#ifdef _ITEM_FORUSERNAMES + {"forname", "", ITEM_FORUSERNAME }, //ITEM_FORUSERNAME, + {"forcdkey", "", ITEM_FORUSERCDKEY }, //ITEM_FORUSERCDKEY +#endif + +#ifdef _ANGEL_SUMMON + {"mindex", "", ITEM_ANGELMISSION }, + {"angel", "", ITEM_ANGELINFO }, + {"hero", "", ITEM_HEROINFO }, +#endif + +#ifdef _UNIQUE_P_I + {"ucode", "", ITEM_UNIQUECODE }, /* ITEM_UNIQUECODE */ +#endif +}; + +static ITEM_charDataSetting ITEM_setmemdata={ + "", "", -1 /* ITEM_MEMO */ +}; + + +#else +typedef struct ITEM_tag_intDataSetting +{ + char* dumpchar; + int defaults; +}ITEM_intDataSetting; + +typedef struct ITEM_tag_charDataSetting +{ + char* dumpchar; + char* defaults; +}ITEM_charDataSetting; + +ITEM_intDataSetting ITEM_setintdata[ITEM_DATAINTNUM]={ + {"id", 0}, /* ITEM_ID */ + {"bi", 0}, /* ITEM_ITEMBASEIMAGENUMBER */ + {"cs", 0}, /* ITEM_COST */ + {"ep", ITEM_OTHER}, /* ITEM_TYPE */ + {"ft", 0}, /* ITEM_ABLEUSEFIELD */ + {"tg", 0}, /* ITEM_TARGET */ + {"lv", 0}, /* ITEM_LEVEL */ + +#ifdef _ITEM_MAXUSERNUM + {"dib", -1}, /*ITEM_DAMAGEBREAK*/ +#endif + +#ifdef _ITEMSET4_TXT + {"upin", 1}, //ITEM_USEPILENUMS, + {"canpile", 0}, //ITEM_CANBEPILE + {"nestr", 0}, //ITEM_NEEDSTR, + {"nedex", 0}, //ITEM_NEEDDEX, + {"netra", 0}, //ITEM_NEEDTRANS, + {"neprof", 0}, //ITEM_NEEDPROFESSION, +#endif + + {"dmce", 0}, /*ITEM_DAMAGECRUSHE*/ + {"mdmce",0}, //ITEM_MAXDAMAGECRUSHE + +#ifdef _ADD_DEAMGEDEFC + {"otdmag", 0}, //ITEM_OTHERDAMAGE, + {"otdefc", 0}, //ITEM_OTHERDEFC, +#endif + +#ifdef _SUIT_ITEM + {"nsuit", 0}, //ITEM_SUITCODE, +#endif + {"ann", 0}, /* ITEM_ATTACKNUM_MIN */ + {"anx", 0}, /* ITEM_ATTACKNUM_MAX */ + {"ma", 0}, /* ITEM_MODIFYATTACK */ + {"md", 0}, /* ITEM_MODIFYDEFENCE */ + {"mh", 0}, /* ITEM_MODIFYHP */ + {"mm", 0}, /* ITEM_MODIFYMP */ + + {"mq", 0}, /* ITEM_MODIFYQUICK */ + + {"ml", 0}, /* ITEM_MODIFYLUCK */ + {"mc", 0}, /* ITEM_MODIFYCHARM */ + {"mv", 0}, /* ITEM_MODIFYAVOID */ + {"mat", 0}, /* ITEM_MODIFYATTRIB */ + {"mav", 0}, /* ITEM_MODIFYATTRIBVALUE */ + + {"mid", -1}, /* ITEM_MAGICID */ + {"mpr", 0}, /* ITEM_MAGICPROB */ + {"mu", 0}, /* ITEM_MAGICUSEMP */ +#ifdef _ITEMSET5_TXT + {"arr", 0}, /*ITEM_MODIFYARRANGE*/ + {"seqce", 0}, //ITEM_MODIFYSEQUENCE, + {"iapi", 0}, //ITEM_ATTACHPILE + {"hirt", 0}, //ITEM_HITRIGHT // +#endif + +#ifdef _ITEMSET6_TXT + {"neguard", 0}, //ITEM_NEGLECTGUARD +// {"bemerge", 0}, //ITEM_BEMERGE +#endif + {"mpo", 0}, /* ITEM_POISON */ + {"mpa", 0}, /* ITEM_PARALYSIS */ + {"msl", 0}, /* ITEM_SLEEP */ + {"mst", 0}, /* ITEM_STONE */ + {"mdr", 0}, /* ITEM_DRUNK */ + {"mco", 0}, /* ITEM_CONFUSION */ + + {"mcr", 0}, /* ITEM_CRITICAL */ + + {"ua", -1}, /* ITEM_USEACTION */ + {"drlo",FALSE}, /* ITEM_DROPATLOGOUT */ + {"valo",FALSE}, /* ITEM_VANISHATLOGOUT */ + {"ioed",TRUE}, /* ITEM_ISOVERED */ + {"cpm", TRUE}, /* ITEM_CANPETMAIL */ + {"cmf", TRUE}, /* ITEM_CANMERGEFROM */ + {"cmt", TRUE}, /* ITEM_CANMERGETO */ + + {"ingv0",0}, /* ITEM_INGVALUE0 */ + {"ingv1",0}, + {"ingv2",0}, + {"ingv3",0}, + {"ingv4",0}, + + {"ipt", 0}, /* ITEM_PUTTIME */ + {"ll", 0}, /* ITEM_LEAKLEVEL */ + {"mrf", 0}, /* ITEM_MERGEFLG */ + {"clv", 0}, /* ITEM_CRUSHLEVEL */ + + {"v1", 0}, /* ITEM_VAR1 */ + {"v2", 0}, /* ITEM_VAR2 */ + {"v3", 0}, /* ITEM_VAR3 */ + {"v4", 0}, /* ITEM_VAR4 */ +}; + +ITEM_charDataSetting ITEM_setchardata[ITEM_DATACHARNUM]={ + {"na", ""}, /* ITEM_NAME */ + {"sn", ""}, /* ITEM_SCRETNAME */ + {"en", ""}, /* ITEM_EFFECTSTRING */ + {"ar", ""}, /* ITEM_ARGUMENT */ +#ifdef _ITEM_INSLAY + {"acode", ""}, /*ITEM_TYPECODE,*/ + {"inlaycode", ""}, /*ITEM_INLAYCODE,*/ +#endif + {"cdk", ""}, /* ITEM_CDKEY */ +#ifdef _ITEM_FORUSERNAMES + {"forname", ""}, //ITEM_FORUSERNAME, + {"forcdkey", ""}, //ITEM_FORUSERCDKEY +#endif +// CoolFish: 2001/10/11 +#ifdef _UNIQUE_P_I + {"ucode", ""}, /* ITEM_UNIQUECODE */ +#endif + {"ingn0", ""}, /* ITEM_INGNAME0 */ + {"ingn1", ""}, + {"ingn2", ""}, + {"ingn3", ""}, + {"ingn4", ""}, + + {"inif", ""}, /* ITEM_PREOVERFUNC */ + {"preof", ""}, /* ITEM_PREOVERFUNC */ + {"posof", ""}, /* ITEM_POSTOVERFUNC */ + {"wf", "ITEM_DeleteTimeWatched"}, /* ITEM_WATCHFUNC */ + {"usef", ""}, /* ITEM_USEFUNC */ + {"atchf", ""}, /* ITEM_ATTACH */ + {"dtchf", ""}, /* ITEM_DETACH */ + {"attaf", ""}, /* ITEM_ATTACHFUNC */ + {"pickupf", ""}, /* ITEM_PICKUPFUNC */ +#ifdef _Item_ReLifeAct + {"relifes", ""}, /*ITEM_DIERELIFEFUNC*/ +#endif +}; + +static ITEM_charDataSetting ITEM_setmemdata={ + "", "" /* ITEM_MEMO */ +}; +#endif + +typedef enum +{ + ITEM_INTENTRY=0, + ITEM_CHARENTRY=1, + ITEM_INTFUNC=2, + ITEM_CHARFUNC=3, +}ITEM_DATATYPECATEGORY; + +static struct ITEM_itemconfentry +{ + char* entryname; + ITEM_DATATYPECATEGORY type; + int index; + void* func; +}ITEM_itemconfentries[]={ + {"name", ITEM_CHARFUNC, ITEM_NAME, ITEM_checkString}, + {"secretname", ITEM_CHARFUNC, ITEM_SECRETNAME, ITEM_checkString}, + {"effectstring",ITEM_CHARFUNC, ITEM_EFFECTSTRING, ITEM_checkString}, + {"argument", ITEM_CHARENTRY, ITEM_ARGUMENT, NULL}, +#ifdef _ITEM_INSLAY + {"acode", ITEM_CHARENTRY, ITEM_TYPECODE, NULL}, + {"inlaycode", ITEM_CHARENTRY, ITEM_INLAYCODE, NULL}, +#endif + {"initfunc", ITEM_CHARENTRY, ITEM_INITFUNC, NULL}, + {"preoverfunc", ITEM_CHARENTRY, ITEM_PREOVERFUNC, NULL}, + {"postoverfunc",ITEM_CHARENTRY, ITEM_POSTOVERFUNC, NULL}, + {"watchfunc", ITEM_CHARENTRY, ITEM_WATCHFUNC, NULL}, + {"usefunc", ITEM_CHARENTRY, ITEM_USEFUNC, NULL}, + {"attachfunc", ITEM_CHARENTRY, ITEM_ATTACHFUNC, NULL}, + {"detachfunc", ITEM_CHARENTRY, ITEM_DETACHFUNC, NULL}, + {"dropfunc", ITEM_CHARENTRY, ITEM_DROPFUNC, NULL}, + {"pickupfunc", ITEM_CHARENTRY, ITEM_PICKUPFUNC, NULL}, +#ifdef _Item_ReLifeAct + {"relifefunc", ITEM_CHARENTRY, ITEM_DIERELIFEFUNC, NULL}, +#endif + {"id", ITEM_INTENTRY, ITEM_ID, NULL}, + {"imagenumber", ITEM_INTENTRY, ITEM_BASEIMAGENUMBER, NULL}, + {"cost", ITEM_INTENTRY, ITEM_COST, NULL}, + {"type", ITEM_INTENTRY, ITEM_TYPE, NULL}, + {"fieldtype", ITEM_INTENTRY, ITEM_ABLEUSEFIELD, NULL}, + {"target", ITEM_INTENTRY, ITEM_TARGET, NULL}, + + {"level", ITEM_INTENTRY, ITEM_LEVEL, NULL}, +#ifdef _ITEM_MAXUSERNUM + {"dambreak", ITEM_INTENTRY, ITEM_DAMAGEBREAK, NULL}, +#endif + +#ifdef _ITEMSET4_TXT + {"upinums", ITEM_INTENTRY, ITEM_USEPILENUMS, NULL}, + {"campile", ITEM_INTENTRY, ITEM_CANBEPILE, NULL}, + {"nestr", ITEM_INTENTRY, ITEM_NEEDSTR, NULL}, + {"nedex", ITEM_INTENTRY, ITEM_NEEDDEX, NULL}, + {"netra", ITEM_INTENTRY, ITEM_NEEDTRANS, NULL}, + {"neprof", ITEM_INTENTRY, ITEM_NEEDPROFESSION, NULL}, +#endif + + {"damcrushe", ITEM_INTENTRY, ITEM_DAMAGECRUSHE, NULL}, + {"maxdmce", ITEM_INTENTRY, ITEM_MAXDAMAGECRUSHE, NULL}, + +#ifdef _ADD_DEAMGEDEFC + {"otdmags", ITEM_INTENTRY, ITEM_OTHERDAMAGE, NULL}, + {"otdefcs", ITEM_INTENTRY, ITEM_OTHERDEFC, NULL}, +#endif +#ifdef _SUIT_ITEM + {"nsuit", ITEM_INTENTRY, ITEM_SUITCODE, NULL}, //ITEM_SUITCODE, +#endif + {"attacknum_min",ITEM_INTENTRY, ITEM_ATTACKNUM_MIN, NULL}, + {"attacknum_max",ITEM_INTENTRY, ITEM_ATTACKNUM_MAX, NULL}, + {"attack", ITEM_INTFUNC, ITEM_MODIFYATTACK, ITEM_getRandomValue}, + {"defence", ITEM_INTFUNC, ITEM_MODIFYDEFENCE, ITEM_getRandomValue}, + {"quick", ITEM_INTFUNC, ITEM_MODIFYQUICK, ITEM_getRandomValue}, + + {"hp", ITEM_INTFUNC, ITEM_MODIFYHP, ITEM_getRandomValue}, + {"mp", ITEM_INTFUNC, ITEM_MODIFYMP, ITEM_getRandomValue}, + {"luck", ITEM_INTFUNC, ITEM_MODIFYLUCK, ITEM_getRandomValue}, + {"charm", ITEM_INTFUNC, ITEM_MODIFYCHARM, ITEM_getRandomValue}, + {"avoid", ITEM_INTFUNC, ITEM_MODIFYAVOID, ITEM_getRandomValue}, + {"attrib", ITEM_INTENTRY, ITEM_MODIFYATTRIB, NULL}, + {"attribvalue", ITEM_INTENTRY, ITEM_MODIFYATTRIBVALUE,NULL}, + + {"magicid", ITEM_INTENTRY, ITEM_MAGICID, NULL}, + {"magicprob", ITEM_INTENTRY, ITEM_MAGICPROB, NULL}, + {"magicusemp", ITEM_INTENTRY, ITEM_MAGICUSEMP, NULL}, +#ifdef _ITEMSET5_TXT + {"arr", ITEM_INTENTRY, ITEM_MODIFYARRANGE, NULL}, + {"seqce", ITEM_INTENTRY, ITEM_MODIFYSEQUENCE, NULL}, + {"iapi", ITEM_INTENTRY, ITEM_ATTACHPILE, NULL}, + {"hirt", ITEM_INTENTRY, ITEM_HITRIGHT, NULL}, +#endif +#ifdef _ITEMSET6_TXT + {"neguard", ITEM_INTENTRY, ITEM_NEGLECTGUARD, NULL}, +// {"bemerge", ITEM_INTENTRY, ITEM_BEMERGE, NULL}, +#endif + +#ifdef _VERSION_GF + {"unkown1", ITEM_INTENTRY, ITEM_UNKNOWN1, NULL}, + {"unkown2", ITEM_INTENTRY, ITEM_UNKNOWN2, NULL}, + {"unkown3", ITEM_INTENTRY, ITEM_UNKNOWN3, NULL}, + {"unkown4", ITEM_INTENTRY, ITEM_UNKNOWN4, NULL}, + {"unkown5", ITEM_INTENTRY, ITEM_UNKNOWN5, NULL}, + {"unkown6", ITEM_INTENTRY, ITEM_UNKNOWN6, NULL}, + {"unkown7", ITEM_INTENTRY, ITEM_UNKNOWN7, NULL}, + {"unkown8", ITEM_INTENTRY, ITEM_UNKNOWN8, NULL}, + {"unkown9", ITEM_INTENTRY, ITEM_UNKNOWN9, NULL}, + {"unkown10", ITEM_CHARENTRY, ITEM_UNKNOWN10, NULL}, +#endif + + {"poison", ITEM_INTFUNC, ITEM_POISON, ITEM_getRandomValue}, + {"paralysis", ITEM_INTFUNC, ITEM_PARALYSIS, ITEM_getRandomValue}, + {"sleep", ITEM_INTFUNC, ITEM_SLEEP, ITEM_getRandomValue}, + {"stone", ITEM_INTFUNC, ITEM_STONE, ITEM_getRandomValue}, + {"drunk", ITEM_INTFUNC, ITEM_DRUNK, ITEM_getRandomValue}, + {"confusion", ITEM_INTFUNC, ITEM_CONFUSION, ITEM_getRandomValue}, + + {"critical", ITEM_INTFUNC, ITEM_CRITICAL, ITEM_getRandomValue}, + + {"useaction", ITEM_INTENTRY, ITEM_USEACTION, NULL}, + + {"dropatlogout",ITEM_INTFUNC, ITEM_DROPATLOGOUT, ITEM_isstring1or0}, + {"vanishatdrop",ITEM_INTFUNC, ITEM_VANISHATDROP, ITEM_isstring1or0}, + {"isovered", ITEM_INTFUNC, ITEM_ISOVERED, ITEM_isstring1or0}, + {"canpetmail", ITEM_INTFUNC, ITEM_CANPETMAIL, ITEM_isstring1or0}, + {"canmergefrom",ITEM_INTFUNC, ITEM_CANMERGEFROM, ITEM_isstring1or0}, + {"canmergeto", ITEM_INTFUNC, ITEM_CANMERGETO, ITEM_isstring1or0}, + + {"ingname0", ITEM_CHARENTRY, ITEM_INGNAME0, NULL}, + {"ingvalue0", ITEM_INTENTRY, ITEM_INGVALUE0, NULL}, + {"ingname1", ITEM_CHARENTRY, ITEM_INGNAME1, NULL}, + {"ingvalue1", ITEM_INTENTRY, ITEM_INGVALUE1, NULL}, + {"ingname2", ITEM_CHARENTRY, ITEM_INGNAME2, NULL}, + {"ingvalue2", ITEM_INTENTRY, ITEM_INGVALUE2, NULL}, + {"ingname3", ITEM_CHARENTRY, ITEM_INGNAME3, NULL}, + {"ingvalue3", ITEM_INTENTRY, ITEM_INGVALUE3, NULL}, + {"ingname4", ITEM_CHARENTRY, ITEM_INGNAME4, NULL}, + {"ingvalue4", ITEM_INTENTRY, ITEM_INGVALUE4, NULL}, +}; + + +ITEM_table* ITEM_tbl=NULL; +ITEM_index* ITEM_idx=NULL; + +static INLINE BOOL ITEM_CHECKARRAYINDEX(int index) +{ + if( ITEM_itemnum<=(index) || (index)<0 )return FALSE; + return TRUE; +} + +INLINE BOOL _ITEM_CHECKINDEX( char *file, int line, int index) +{ + if( !ITEM_CHECKARRAYINDEX(index) ) { + if( index != -1 ) { + print( "err %s:%d \n", file, line); + } + return FALSE; + } + if( ITEM_item[index].use == FALSE ) { + return FALSE; + } + return TRUE; +} + +static INLINE int ITEM_CHECKINTDATAINDEX(int index) +{ + if( ITEM_DATAINTNUM <= index || index < 0 )return FALSE; + return TRUE; +} + +static INLINE int ITEM_CHECKCHARDATAINDEX(int index) +{ + if( ITEM_DATACHARNUM<=index || index<0 )return FALSE; + return TRUE; +} + +BOOL ITEM_initExistItemsArray( int num ) +{ + int i; + + BOOL ITEM_checksetdata( void ); + if( ITEM_checksetdata() == FALSE )return FALSE; + + ITEM_itemnum = num; + + ITEM_item = allocateMemory( sizeof( ITEM_exists ) * num ); + if( ITEM_item == NULL ) return FALSE; + +#ifdef _ALLBLUES_LUA_1_2 + memset( &ITEM_luaFunc, 0 , sizeof( ITEM_LuaFunc )); +#endif + + for( i = 0 ; i < num ; i ++ ){ + memset( &ITEM_item[i], 0 , sizeof( ITEM_exists )); + ITEM_item[i].use = FALSE; + } + + print("ڶη %4.2f MB ռ...", sizeof( ITEM_exists ) * num /1024.0/1024.0); + return TRUE; +} + +BOOL ITEM_endExistItemsArray( ITEM_table* ITEM_item ) +{ + freeMemory( ITEM_item ); + return TRUE; +} + +BOOL ITEM_endExistItemsIndexArray( ITEM_index* ITEM_item ) +{ + freeMemory( ITEM_item ); + return TRUE; +} + +int _ITEM_initExistItemsOne( char *file, int line, ITEM_Item* itm ) +{ + int i; + int itemID=-1; + static int Sindex=1; + itemID = itm->data[ITEM_ID]; + if( ITEM_CHECKITEMTABLE(itm->data[ITEM_ID] ) == FALSE){ + print("CHAR itemData err Item_id:%d=%s%d!!\n", itm->data[ITEM_ID], file, line); + return -1; + } + for( i = 0 ; i < ITEM_itemnum ; i ++ ) { + Sindex++; + if( Sindex >= ITEM_itemnum ) Sindex = 1; + if( Sindex < 1 ) Sindex = 1; + if( !ITEM_item[Sindex].use){ + int charaindex; + charaindex = ITEM_item[Sindex].itm.workint[ITEM_WORKCHARAINDEX]; + if( CHAR_CHECKINDEX( charaindex) && + CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + int j; + for( j = 0; j < CheckCharMaxItem(charaindex); j ++ ) { + if( CHAR_getItemIndex( charaindex, j) == Sindex) { + print( "item.c: error! chara have this item charaindex[%d] " + "itemindex[%d] Name(%s)POS(%d)NAME(%s)\n", + charaindex, Sindex, + CHAR_getUseName( charaindex ), j, + ITEM_item[Sindex].itm.string[ITEM_NAME].string ); + print( "from %s:%d\n", file, line); + ITEM_item[Sindex].use = TRUE; + break; + } + } + if( j != CheckCharMaxItem(charaindex) ) continue; + } + memcpy( &ITEM_item[Sindex].itm , itm , sizeof( ITEM_Item ) ); + ITEM_item[Sindex].use = TRUE; + { + BOOL (*initfunc)(ITEM_Item*)=NULL; + initfunc = (BOOL(*)(ITEM_Item*)) getFunctionPointerFromName( itm->string[ITEM_INITFUNC].string ); + if( initfunc ){ + if( initfunc( &ITEM_item[Sindex].itm ) == FALSE ){ + ITEM_item[Sindex].use = FALSE; + fprint( "Error:Can't init item\n" ); + return -1; + } + } + } + ITEM_UseItemnum++; + ITEM_constructFunctable( Sindex); + return Sindex; + } + } + fprint( "Ʒ\n" ); + return -1; +} + +void _ITEM_endExistItemsOne( int index , char *file, int line) +{ + int i,j; + int hitcnt = 0; + int playernum = CHAR_getPlayerMaxNum(); + + if( !ITEM_CHECKINDEX(index)) return; + + for( i = 0; i < playernum; i ++ ) { + if( CHAR_CHECKINDEX( i)) { + for( j = 0; j < CheckCharMaxItem(i); j ++ ) { + if( CHAR_getItemIndex( i, j) == index) { + print( "warning !! player have this item:%d call from [%s:%d](%s)(%s)\n", + index, file,line, CHAR_getUseName(i),ITEM_item[index].itm.string[ITEM_NAME].string ); + hitcnt ++; + if( hitcnt > 1 ) { + print( "ITEM_INDEX(%d) duplicate!!\n", index); + } + } + } + } + } + + if( hitcnt < 1 ){ + ITEM_item[index].use = FALSE; + ITEM_item[index].itm.workint[ITEM_WORKCHARAINDEX] = -1; + ITEM_UseItemnum--; + } +} + +INLINE int ITEM_getIntStrict( int index ,ITEM_DATAINT element,int* error) +{ + if(!ITEM_CHECKINDEX(index))return *error=FALSE; + if(!ITEM_CHECKINTDATAINDEX(element))return *error=FALSE; + return ITEM_item[index].itm.data[element]; +} + +INLINE int _ITEM_getInt( char *file, int line, int index ,ITEM_DATAINT element) +{ + if(!ITEM_CHECKINDEX(index)){ + return -1; + } + if(!ITEM_CHECKINTDATAINDEX(element)) { + return -1; + } + return ITEM_item[index].itm.data[element]; +} + +INLINE int ITEM_setIntStrict( int index ,ITEM_DATAINT element,int data, + int* error) +{ + int buf; + if(!ITEM_CHECKINDEX(index)) + return *error=FALSE; + if(!ITEM_CHECKINTDATAINDEX(element)) + return *error=FALSE; + buf = ITEM_item[index].itm.data[element]; + ITEM_item[index].itm.data[element] = data; + return buf; +} + +INLINE int _ITEM_setInt( char *file, int line, int index ,ITEM_DATAINT element, int data) +{ + int buf; + if( !ITEM_CHECKINDEX( index) ){ + return -1; + } + + if( !ITEM_CHECKINTDATAINDEX( element) ){ + return -1; + } + + buf = ITEM_item[ index].itm.data[ element]; + ITEM_item[ index].itm.data[ element] = data; + return buf; +} + +INLINE char* ITEM_getChar( int index ,ITEM_DATACHAR element ) +{ + if(!ITEM_CHECKINDEX(index))return "\0"; + if(!ITEM_CHECKCHARDATAINDEX(element))return "\0"; + return ITEM_item[index].itm.string[element].string; +} + +INLINE BOOL ITEM_setChar( int index ,ITEM_DATACHAR element , char* new) +{ + if(!ITEM_CHECKINDEX(index))return FALSE; + if(!ITEM_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( ITEM_item[index].itm.string[element].string, + sizeof( ITEM_item[index].itm.string[element].string ), + new ); + return TRUE; +} + +INLINE int ITEM_getWorkInt( int index ,ITEM_WORKDATAINT element) +{ + if( !ITEM_CHECKINDEX(index) ) return -1; + if( element >= ITEM_WORKDATAINTNUM || element < 0 ) return -1; + return ITEM_item[index].itm.workint[element]; +} + +INLINE int ITEM_setWorkInt( int index ,ITEM_WORKDATAINT element, int data) +{ + int buf; + if( !ITEM_CHECKINDEX( index) ) return -1; + if( element >= ITEM_WORKDATAINTNUM || element < 0 ) return -1; + + buf = ITEM_item[index].itm.workint[element]; + ITEM_item[index].itm.workint[element] = data; + return buf; +} + +INLINE int ITEM_getITEM_itemnum( void ) +{ + return ITEM_itemnum; +} + +INLINE int ITEM_getITEM_UseItemnum( void ) +{ + return ITEM_UseItemnum; +} + + +INLINE BOOL ITEM_getITEM_use( int index ) +{ + if( !ITEM_CHECKINDEX(index))return FALSE; + return ITEM_item[index].use; +} + +void ITEM_constructFunctable( int itemindex ) +{ + int i; + if( !ITEM_CHECKINDEX(itemindex))return; + + for( i=ITEM_FIRSTFUNCTION; i < ITEM_LASTFUNCTION ; i++ ) { + ITEM_item[itemindex].itm.functable[i-ITEM_FIRSTFUNCTION] = getFunctionPointerFromName( ITEM_getChar( itemindex,i ) ); +#ifdef _ALLBLUES_LUA_1_2 + if(ITEM_item[itemindex].itm.functable[i-ITEM_FIRSTFUNCTION] == NULL){ + ITEM_setLUAFunction(itemindex, i, ITEM_getChar( itemindex,i )); + } +#endif + } +} + +void* _ITEM_getFunctionPointer( int itemindex, int functype, char *file, int line ) +{ + if( !ITEM_CHECKINDEX(itemindex) )return NULL; + if( functype < ITEM_FIRSTFUNCTION || functype >= ITEM_LASTFUNCTION ){ + print( "ʹ:%d, ļ:%s,%d\n", functype, file, line); + return NULL; + } + return ITEM_item[itemindex].itm.functable[functype-ITEM_FIRSTFUNCTION]; +} + +#ifdef _ALLBLUES_LUA_1_2 +INLINE BOOL ITEM_setLUAFunction( int itemindex, int functype, const char *luafuncname) +{ + if( !ITEM_CHECKINDEX(itemindex) )return FALSE; + if( functype < ITEM_FIRSTFUNCTION || functype >= ITEM_LASTFUNCTION ){ + print( "ʹ1:%d\n", functype); + return FALSE; + } + ITEM_LuaFunc *luaFunc = &ITEM_luaFunc; + + while(luaFunc->next != NULL){ + if(strcmp(luaFunc->luafuncname, luafuncname) == 0){ + ITEM_item[itemindex].itm.lua[functype-ITEM_FIRSTFUNCTION] = luaFunc->lua; + ITEM_item[itemindex].itm.luafunctable[functype-ITEM_FIRSTFUNCTION] = allocateMemory( strlen(luaFunc->luafunctable) ); + memset(ITEM_item[itemindex].itm.luafunctable[functype-ITEM_FIRSTFUNCTION], 0, strlen(luaFunc->luafunctable)); + strcpy(ITEM_item[itemindex].itm.luafunctable[functype-ITEM_FIRSTFUNCTION], luaFunc->luafunctable); + return TRUE; + } + luaFunc = luaFunc->next; + } + + ITEM_item[itemindex].itm.lua[functype-ITEM_FIRSTFUNCTION] = NULL; + ITEM_item[itemindex].itm.luafunctable[functype-ITEM_FIRSTFUNCTION] = NULL; + + return FALSE; +} + +BOOL ITEM_addLUAListFunction( lua_State *L, const char *luafuncname, const char *luafunctable ) +{ + ITEM_LuaFunc *luaFunc = &ITEM_luaFunc; + + while(luaFunc->next != NULL){ + luaFunc = luaFunc->next; + } + + luaFunc->next = allocateMemory( sizeof(ITEM_LuaFunc) ); + memset( luaFunc->next, 0 , sizeof(ITEM_luaFunc) ); + if(luaFunc->next == NULL)return FALSE; + + luaFunc->lua = L; + strcpysafe( luaFunc->luafuncname, 128, luafuncname ); + strcpysafe( luaFunc->luafunctable, 128, luafunctable ); + + return TRUE; +} + + +INLINE lua_State *ITEM_getLUAFunction( int itemindex, int functype) +{ + if( !ITEM_CHECKINDEX(itemindex) )return NULL; + if( functype < ITEM_FIRSTFUNCTION || functype >= ITEM_LASTFUNCTION ){ + print( "ʹ2:%d\n", functype); + return NULL; + } + + if(ITEM_item[itemindex].itm.lua[functype-ITEM_FIRSTFUNCTION] == NULL){ + return NULL; + } + + lua_getglobal( ITEM_item[itemindex].itm.lua[functype-ITEM_FIRSTFUNCTION], ITEM_item[itemindex].itm.luafunctable[functype-ITEM_FIRSTFUNCTION]); + + return ITEM_item[itemindex].itm.lua[functype-ITEM_FIRSTFUNCTION]; +} + +#endif + + +int ITEM_getItemMaxIdNum( void) +{ + return ITEM_idxlen; +} + +BOOL ITEM_checksetdata( void ) +{ + int i; + char* strings[ITEM_DATAINTNUM + ITEM_DATACHARNUM + 1]; +#ifdef _SIMPLIFY_ITEMSTRING + int num=0; + for(i = 0; i < arraysizeof( ITEM_setintdata) ; i ++ ){ + strings[ num++ ] = ITEM_setintdata[i].dumpchar; + } + for( i = 0 ; i < arraysizeof( ITEM_setchardata) ; i ++ ){ + strings[ num++ ] = ITEM_setchardata[i].dumpchar; + } + strings[ITEM_DATAINTNUM+ITEM_DATACHARNUM] = ITEM_setmemdata.dumpchar; + + if( ! checkStringsUnique( strings, num,1 ) ){ + fprint( "ITEM_set????data is overlapped.\nIt is not allowed\n"); + return FALSE; + } +#else + for(i = 0; i < ITEM_DATAINTNUM ; i ++ ) + strings[i] = ITEM_setintdata[i].dumpchar; + for( i = 0 ; i < ITEM_DATACHARNUM ; i ++ ) + strings[ITEM_DATAINTNUM+i] = ITEM_setchardata[i].dumpchar; + + + strings[ITEM_DATAINTNUM+ITEM_DATACHARNUM] = ITEM_setmemdata.dumpchar; + + if( ! checkStringsUnique( strings, arraysizeof( strings ),1 ) ){ + fprint( "ITEM_set????data is overlapped.\nIt is not allowed\n"); + return FALSE; + } +#endif + return TRUE; +} + +static char ITEM_dataString[STRINGBUFSIZ]; +char* ITEM_makeStringFromItemIndex( int index, int mode ) +{ + if( 0 <= index && index < ITEM_itemnum && ITEM_item[index].use == TRUE) + ; + else + return "\0"; + return ITEM_makeStringFromItemData( &ITEM_item[index].itm, mode ); +} + +#ifdef _SIMPLIFY_ITEMSTRING2 +BOOL CHECK_HaveBeSave( int itemID, int oneNum, int type ) +{ + if( ITEM_ID == type ) return TRUE; + if( ITEMTBL_getInt( itemID, type) == oneNum ) return FALSE; + return TRUE; +} +#endif + +char* ITEM_makeStringFromItemData( ITEM_Item* one, int mode ) +{ + int i; + char delim1 = '\0'; + char delim2 = '\0'; + int strlength=0; + +#ifdef _SIMPLIFY_ITEMSTRING2 + int itemID = one->data[ ITEM_ID]; + if( !ITEM_CHECKITEMTABLE( itemID) ) return "\0"; +#endif + if( mode == 0 ) { + delim1 = '='; delim2 = '|'; + }else { + delim1 = ':'; delim2 = ','; + } + +#ifdef _SIMPLIFY_ITEMSTRING + for(i = 0; i < arraysizeof( ITEM_setintdata) ; i ++ ){ + char linedata[128]; +#ifdef _SIMPLIFY_ITEMSTRING2 + if( !CHECK_HaveBeSave( itemID, one->data[ ITEM_setintdata[i].table], ITEM_setintdata[i].table) ) continue; +#endif + snprintf( linedata , sizeof(linedata), + "%s%c%d%c", ITEM_setintdata[i].dumpchar, delim1, + one->data[ ITEM_setintdata[i].table], delim2 ); + strcpysafe( &ITEM_dataString[strlength], sizeof( ITEM_dataString ) - strlength, linedata ); + strlength += strlen( linedata ); + } + + for( i = 0 ; i < arraysizeof( ITEM_setchardata) ; i ++ ){ + char linedata[128]; + char escapebuffer[128]; + if( strlen( one->string[ ITEM_setchardata[i].table].string) == 0 ) continue; + + snprintf( linedata , sizeof(linedata), + "%s%c%s%c", ITEM_setchardata[i].dumpchar,delim1, + makeEscapeString( one->string[ITEM_setchardata[i].table].string, escapebuffer, + sizeof(escapebuffer)), delim2); + strcpysafe( &ITEM_dataString[strlength], sizeof( ITEM_dataString ) - strlength, linedata ); + strlength += strlen( linedata ); + } +#else + for( i = 0 ; i < ITEM_DATAINTNUM ; i ++ ) { + char linedata[128]; + snprintf( linedata , sizeof(linedata), + "%s%c%d%c", ITEM_setintdata[i].dumpchar, delim1, one->data[i], delim2 ); + strcpysafe( &ITEM_dataString[strlength], sizeof( ITEM_dataString ) - strlength, linedata ); + strlength += strlen( linedata ); + } + + for( i = 0 ; i < ITEM_DATACHARNUM ; i ++ ){ + char linedata[128]; + char escapebuffer[128]; + if( strlen( one->string[i].string) != 0 ) { + snprintf( linedata , sizeof(linedata), + "%s%c%s%c", ITEM_setchardata[i].dumpchar,delim1, + makeEscapeString(one->string[i].string,escapebuffer, + sizeof(escapebuffer)), delim2); + strcpysafe( &ITEM_dataString[strlength], sizeof( ITEM_dataString ) - strlength, linedata ); + strlength += strlen( linedata ); + } + } +#endif + dchop( ITEM_dataString, (mode == 0 ) ? "|" : ","); + return ITEM_dataString; +} + +BOOL ITEM_makeExistItemsFromStringToArg( char* src , ITEM_Item* item, int mode ) +{ + int readindex=1; + char delim1[2]; + char delim2[2]; + + if( mode == 0 ) { + strcpy( delim1, "="); + strcpy( delim2, "|"); + } + else { + strcpy( delim1, ":"); + strcpy( delim2, ","); + } +#ifdef _SIMPLIFY_ITEMSTRING + { + + int itemID=-1; + while( 1 ){ + char linebuf[512]; + char firstToken[256]; + char secondToken[256]; + if( getStringFromIndexWithDelim( src ,delim2 , readindex, linebuf, sizeof( linebuf)) == FALSE ) break; + + readindex++; + if( getStringFromIndexWithDelim( linebuf, delim1, 1, firstToken, sizeof( firstToken )) == FALSE )return FALSE; + if( strcmp( firstToken, "id" ) ) continue; + strcpysafe( secondToken , sizeof( secondToken ), linebuf + strlen( firstToken) + strlen( delim1) ); + itemID = atoi( secondToken); + if( !ITEM_CHECKITEMTABLE( itemID) ) return FALSE; + ITEM_getDefaultItemData( itemID, item); + break; + } + readindex =1; + } +#else + ITEM_getDefaultItemSetting(item); +#endif + + while( 1 ){ + BOOL ret; + char linebuf[512]; + + char firstToken[256]; + char secondToken[256]; + int i; + + ret = getStringFromIndexWithDelim( src ,delim2 , readindex,linebuf, sizeof(linebuf) ); + if( ret == FALSE ) + break; + ret = getStringFromIndexWithDelim( linebuf, delim1, 1, firstToken, sizeof( firstToken ) ); + if( ret == FALSE ) return FALSE; + strcpysafe( secondToken , sizeof( secondToken ), + linebuf + strlen(firstToken) + strlen(delim1) ); +#ifdef _SIMPLIFY_ITEMSTRING + for(i = 0; i < arraysizeof( ITEM_setintdata) ; i ++ ){ + if( strcmp( firstToken , ITEM_setintdata[i].dumpchar) ) continue; + item->data[ITEM_setintdata[i].table] = atoi( secondToken ); + goto NEXT; + } + + for(i = 0; i < arraysizeof( ITEM_setchardata) ; i ++ ){ + if( strcmp(firstToken ,ITEM_setchardata[i].dumpchar ) ) continue; + strcpysafe( item->string[ ITEM_setchardata[i].table].string, + sizeof(item->string[ITEM_setchardata[i].table].string), + makeStringFromEscaped(secondToken)); + goto NEXT; + } +#else + for( i = 0 ; i < ITEM_DATAINTNUM ; i ++ ){ + if( strcmp(firstToken ,ITEM_setintdata[i].dumpchar) == 0 ){ + item->data[i] = atoi( secondToken ); + goto NEXT; + } + } + + for( i = 0 ; i < ITEM_DATACHARNUM ; i ++ ){ + if( strcmp(firstToken ,ITEM_setchardata[i].dumpchar ) == 0 ){ + strcpysafe( item->string[i].string, + sizeof(item->string[i].string), + makeStringFromEscaped(secondToken)); + goto NEXT; + } + } +#endif + + + NEXT: + readindex++; + } + + if(item->data[ITEM_CANBEPILE] == 0){ + item->data[ITEM_USEPILENUMS]=1; + } + return TRUE; +} + +void ITEM_getDefaultItemSetting(ITEM_Item* itm) +{ + int i; + memset( itm, 0 , sizeof( ITEM_Item )); +#ifdef _SIMPLIFY_ITEMSTRING + for(i = 0; i < arraysizeof( ITEM_setintdata) ; i ++ ){ + itm->data[ITEM_setintdata[i].table] = ITEM_setintdata[i].defaults; + } + for(i = 0; i < arraysizeof( ITEM_setchardata) ; i ++ ){ + strcpysafe( itm->string[ITEM_setchardata[i].table].string, + sizeof( itm->string[ITEM_setchardata[i].table].string), + ITEM_setchardata[i].defaults); + } +#else + for(i=0;idata[i] = ITEM_setintdata[i].defaults; + for(i=0;istring[i].string, + sizeof(itm->string[i].string), + ITEM_setchardata[i].defaults); +#endif + + strcpysafe( itm->string[ITEM_WATCHFUNC].string, + sizeof(itm->string[ITEM_WATCHFUNC].string), "ITEM_DeleteTimeWatched" ); + + + for(i=0;iworkint[i] = -1; + } + +} + +#ifdef _SIMPLIFY_ITEMSTRING +void ITEM_getDefaultItemData( int itemID, ITEM_Item* itm) +{ + int i; +// memset( itm, 0 , sizeof( ITEM_Item )); + + for(i=0;idata[i] = ITEMTBL_getInt( itemID, i); + } + for(i=0;istring[i].string, sizeof( itm->string[i].string), + ITEMTBL_getChar( itemID, i) ); + } + for(i=0;iworkint[i] = -1; + } + + strcpysafe( itm->string[ITEM_WATCHFUNC].string, sizeof( itm->string[ITEM_WATCHFUNC].string), + "ITEM_DeleteTimeWatched" ); + +} +#endif + +static int ITEM_getRandomValue( char* string,int* randomwidth, int num ) +{ + int minvalue; + int maxvalue; + char token[64]; + int ret; +#if 1 + *randomwidth = 0; + + ret = getStringFromIndexWithDelim( string,",",num -1,token, sizeof( token)); + if( ret == FALSE ) { + return 0; + } + minvalue = atoi( token); + ret = getStringFromIndexWithDelim( string,",",num ,token, sizeof( token)); + if( ret == FALSE ) { + return minvalue; + } + maxvalue = atoi( token); + *randomwidth = ABS( maxvalue - minvalue); + return min( minvalue, maxvalue); + +#else + minvalue = atoi( string ); + startmax = index( string,',' ); + if( startmax != NULL ){ + maxvalue = atoi(startmax+1); + *randomwidth = ABS(maxvalue - minvalue); + return min(minvalue,maxvalue); + } + *randomwidth = 0; + return minvalue; +#endif +} +static int ITEM_isstring1or0( char* string,int* randomwidth, int num ) +{ + char token[64]; + int ret; + + ret = getStringFromIndexWithDelim( string,",",num -1,token, sizeof( token)); + if( ret == FALSE ) { + return FALSE; + } + + return isstring1or0( token); +} + +static char* ITEM_checkString( char* string ) +{ +#define ITEM_STRINGLEN 64 + if( strlen(string) >= ITEM_STRINGLEN ) + print( "Over %d:[%s]\n",ITEM_STRINGLEN ,string ); + return string; +#undef ITEM_STRINGLEN +} + +BOOL ITEM_readItemConfFile( char* filename ) +{ + FILE* f; + char line[512]; + char token[64]; + int linenum=0; + int itemnum=0; + int i; + int maxid=0, itemid; + int ret; + int intdata[ITEM_DATAINTNUM]; + +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "ܴļ\n"); + return FALSE; + } +#ifdef _ITEMSET2_ITEM + +#define ITEM_ID_TOKEN_INDEX 17 + +#else + +#ifdef _ITEM_MAXUSERNUM +#define ITEM_ID_TOKEN_INDEX 15 +#endif + +#endif + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + ret = getStringFromIndexWithDelim( line, ",", ITEM_ID_TOKEN_INDEX, token, sizeof(token)); + if( ret == FALSE ){ + fprint("ļ:%s :%d\n",filename,linenum); + continue; + } + itemid = atoi( token); + if( itemid > maxid ){ + maxid = itemid; + } + itemnum ++; + } + + if( maxid <=0 ) { + print( "ID\n"); + fclose(f); + return FALSE; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "\n" ); + fclose(f); + return FALSE; + } + print( "ƷID %d...", maxid); + ITEM_tblen = itemnum + 1; + ITEM_idxlen = maxid + 1; + if( ITEM_tbl != NULL ) + ITEM_endExistItemsArray( ITEM_tbl); + ITEM_tbl = allocateMemory( sizeof(ITEM_table) * ITEM_tblen ); + if( ITEM_idx != NULL ) + ITEM_endExistItemsIndexArray( ITEM_idx); + ITEM_idx = allocateMemory( sizeof(ITEM_index) * ITEM_idxlen ); + + if( ITEM_tbl == NULL ){ + fprint( "޷ڴ %d\n" , sizeof(ITEM_table)*ITEM_tblen ); + fclose( f ); + return FALSE; + } + if( ITEM_idx == NULL ){ + fprint( "޷ڴ %d\n" , sizeof(ITEM_index)*ITEM_idxlen ); + fclose( f ); + return FALSE; + } + print("ITEM_tbl %4.2f MB ռ...", sizeof(ITEM_table) * ITEM_tblen /1024.0/1024.0); + print("ITEM_idx %4.2f MB ռ...", sizeof(ITEM_index) * ITEM_idxlen /1024.0/1024.0); + + for( i = 0 ; i < ITEM_idxlen ; i ++ ) { + ITEM_idx[i].use = FALSE; + } + linenum = 0; + itemnum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + + linenum ++; + + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + replaceString( line, '\t' , ' ' ); + itemnum ++; +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + int readpos = 1; + BOOL dataerror = FALSE; + ITEM_Item itm; + + ITEM_getDefaultItemSetting(&itm); + + for( i=0 ; i< ITEM_DATAINTNUM ; i++ ) { + intdata[i] = 0; + } + itemid = 0; + for( i = 0 ; i < arraysizeof( ITEM_itemconfentries) ; i ++ ){ + ret = getStringFromIndexWithDelim( line,",",readpos,token, sizeof(token)); + if( ret == FALSE ) { +#ifdef _Item_ReLifeAct + { + char buf[256]; + char buf1[256]; + sscanf( line,"%s,%s", buf, buf1); + print("[ITEM data Error] tbl=%d:%s line:%d[%s]\n", + readpos, ITEM_itemconfentries[i].entryname, linenum, line); + } +#else + fprint("Syntax Error tki:%d file:%s line:%d[%s]\n", + i , filename,linenum,line); +#endif + dataerror = TRUE; + break; + } + + if( readpos == ITEM_ID_TOKEN_INDEX ) + itemid = atoi( token); + + readpos ++; + + if( strlen( token ) != 0 ) { + switch(ITEM_itemconfentries[i].type){ + case ITEM_INTENTRY: + itm.data[ITEM_itemconfentries[i].index] = atoi( token ); + break; + case ITEM_CHARENTRY: + strcpysafe( itm.string[ITEM_itemconfentries[i].index].string, + sizeof(itm.string[ITEM_itemconfentries[i].index].string), + token); + break; + case ITEM_INTFUNC: + { + int (*intfunction)(char*,int*, int ); + intfunction = ITEM_itemconfentries[i].func; + itm.data[ITEM_itemconfentries[i].index] + = intfunction(line, + &intdata[ITEM_itemconfentries[i].index],readpos); + if( intfunction == ITEM_getRandomValue) readpos ++; + + } + break; + case ITEM_CHARFUNC: + { + char* (*charfunction)(char* ); + charfunction = ITEM_itemconfentries[i].func; + strcpysafe( itm.string[ITEM_itemconfentries[i].index].string, + sizeof(itm.string[ITEM_itemconfentries[i].index].string), + charfunction( token)); + break; + } + default: + break; + } + } + } + if( !dataerror) { + if( itemid >= ITEM_idxlen ){ + print( "ITEM_tbl full:%d err !!\n" , itemid ); + }else if( ITEM_idx[itemid].use == TRUE ) { + fprint( "Duplicate Itemid %d.ignore\n" , itemid ); + }else{ + if( itm.string[ITEM_SECRETNAME].string[0] == '\0') { + fprint( "ERROR: ID %d item doesn't have secretname\n" + ,itemid ); + memcpy( &itm.string[ITEM_SECRETNAME].string, + &itm.string[ITEM_NAME].string, + sizeof(itm.string[ITEM_NAME].string)); + } +{ + int attacknum_min, attacknum_max; + attacknum_min = itm.data[ITEM_ATTACKNUM_MIN]; + attacknum_max = itm.data[ITEM_ATTACKNUM_MAX]; + if( attacknum_min == 0 ) attacknum_min = attacknum_max; + itm.data[ITEM_ATTACKNUM_MIN] = min( attacknum_min, + attacknum_max); + itm.data[ITEM_ATTACKNUM_MAX] = max( attacknum_min, + attacknum_max); +} + memcpy( &ITEM_tbl[itemnum].itm, &itm, sizeof(ITEM_Item)); + ITEM_idx[itemid].use = TRUE; + ITEM_idx[itemid].index = itemnum; + for( i=0 ; i< ITEM_DATAINTNUM ; i++ ){ + ITEM_tbl[itemnum].randomdata[i] = intdata[i]; + } + } + } +} + + } + + fclose(f); + return TRUE; +} + +CHAR_EquipPlace ITEM_getEquipPlace( int charaindex, int itmid ) +{ + ITEM_CATEGORY cat; + cat = ITEM_getInt( itmid , ITEM_TYPE ); + switch( cat ){ + case ITEM_FIST: + case ITEM_SPEAR: + case ITEM_AXE: + case ITEM_CLUB: +// case ITEM_SHIELD: + case ITEM_BOOMERANG: + case ITEM_BREAKTHROW: + case ITEM_BOUNDTHROW: + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + { + int i=0; + + // ʿְҵܶ + for( i=0; i 0 ) return -1; +#endif +#endif + return CHAR_ARM; + break; + +#ifdef _ITEM_EQUITSPACE + case ITEM_WBELT: + return CHAR_EQBELT; + break; + case ITEM_WSHIELD: +#ifndef _TRUMP_EQUIPMENT + if( BATTLE_GetWepon( charaindex ) != ITEM_BOW ) +#endif + return CHAR_EQSHIELD; + break; + case ITEM_WSHOES: + return CHAR_EQSHOES; + break; +#endif + +#ifdef _EQUIT_NEWGLOVE + case ITEM_WGLOVE: + return CHAR_EQGLOVE; + break; +#endif + default: + break; + } + return -1; +} +#define ITEMSTRINGBUFSIZ 512 +static char ITEM_itemStatusStringBuffer[ITEMSTRINGBUFSIZ]; +char* ITEM_makeItemStatusString( int haveitemindex, int itemindex ) +{ + char escapename[256]; + char escapeeffectstring[256]; + char paramshow[256]; + int leaklevel; + int itemcolor = 0; + int flg; + + if( !ITEM_CHECKINDEX(itemindex) ) return "\0"; + leaklevel = ITEM_getInt(itemindex,ITEM_LEAKLEVEL); + + //if( leaklevel >= 1 ) // Nuke debug + { + makeEscapeString( ITEM_getChar(itemindex, ITEM_SECRETNAME), + escapename, sizeof(escapename) ); + + /*if( leaklevel >= 2 ) + { + static struct Showparamint{ + char* name; + int intindex; + }showparamint[]={ + { "ATK" , ITEM_MODIFYATTACK }, + { "DEF" , ITEM_MODIFYDEFENCE }, + { "HP" , ITEM_MODIFYHP }, + { "MP" , ITEM_MODIFYMP }, + { "QUICK" , ITEM_MODIFYQUICK }, + { "LUCK" , ITEM_MODIFYLUCK }, + { "CHARM" , ITEM_MODIFYCHARM }, + }; + int i; + int stringlen=0; + + paramshow[0] = '\0'; + + for( i = 0 ; i < arraysizeof( showparamint ); i ++ ){ + int value; + char sign; + char tmpbuf[128]; + value = ITEM_getInt(itemindex,showparamint[i].intindex); + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + + + +#endif + + if( value == 0 )continue; + else if( value > 0 ) sign = '+'; + else sign = '-'; + + snprintf( tmpbuf,sizeof( tmpbuf ), "%s%c%d ", + showparamint[i].name,sign,ABS(value) ); + + strcpysafe( paramshow + stringlen , + sizeof(paramshow) - stringlen, tmpbuf ); + stringlen +=strlen(tmpbuf); + if( stringlen >= arraysizeof( paramshow )) + break; + } + dchop( paramshow , " " ); + } + else*/ + paramshow[0] = '\0'; + + } + /*else{ + if(strlen(ITEM_getChar(itemindex,ITEM_SECRETNAME)) > 0){ + makeEscapeString(ITEM_getChar(itemindex,ITEM_SECRETNAME),escapename,sizeof(escapename)); + } + else makeEscapeString( ITEM_getChar(itemindex,ITEM_NAME),escapename,sizeof(escapename)); + paramshow[0] = '\0'; + }*/ + + makeEscapeString( ITEM_getChar( itemindex, ITEM_EFFECTSTRING), + escapeeffectstring, + sizeof(escapeeffectstring)); +#ifdef _ITEM_COLOER + itemcolor = ITEM_getInt( itemindex, ITEM_COLOER); +#else + itemcolor = CHAR_COLORWHITE; +#endif + if( ITEM_getInt( itemindex, ITEM_MERGEFLG) ) { + itemcolor = CHAR_COLORYELLOW; + } +#ifndef _PET_AND_ITEM_UP + else if( strlen( ITEM_getChar( itemindex, ITEM_CDKEY)) != 0 ) { + itemcolor = CHAR_COLORGREEN; + }else +#endif +#ifdef _ITEM_COLOER_DIFFER + else if( ITEM_getInt( itemindex, ITEM_VANISHATDROP) > 0 ) { + itemcolor = CHAR_COLORCYAN; + } +#endif + flg = 0; + if( ITEM_getInt( itemindex, ITEM_CANPETMAIL)) { + flg |= 1 << 0; + } + if( ITEM_getInt( itemindex, ITEM_CANMERGEFROM)) { + flg |= 1 << 1; + } + if( ITEM_getInt( itemindex, ITEM_TYPE) == ITEM_DISH ) { + flg |= 1 << 2; + } +#ifdef _ITEM_INSLAY + if( ITEM_getInt( itemindex, ITEM_TYPE) == ITEM_METAL ) { + flg |= 1 << 3; + }else if( ITEM_getInt( itemindex, ITEM_TYPE) == ITEM_JEWEL ) { + flg |= 1 << 4; + } +#endif +#ifdef _PETSKILL_FIXITEM + if( ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE) + != ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE) ){ + flg |= 1 << 5; + } +#endif + +#ifdef _ALCHEMIST + char INGNAME0[16]; + char INGNAME1[16]; + strcpy( INGNAME0, ITEM_getChar( itemindex, ITEM_INGNAME0) ); + strcpy( INGNAME1, ITEM_getChar( itemindex, ITEM_INGNAME1) ); + if( (INGNAME0[0] != '\0' && INGNAME1[0] != '\0') || (INGNAME0[0] == '\0') ) { + strcpy( INGNAME0, "" ); + } +#endif + + if( haveitemindex == -1 ) { +#ifdef _ADD_SHOW_ITEMDAMAGE // WON ADD ʾƷ;ö + char buff1[256]; + int crushe = ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE); + int maxcrushe = ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE); + if(crushe < 1) crushe = 1; + if(maxcrushe < 1){ + sprintf(buff1, ""); + }else{ + maxcrushe = maxcrushe/1000; + crushe = crushe/1000; + if( maxcrushe <= 0 ) maxcrushe = 1; + snprintf(buff1, sizeof(buff1), "%d%%", (int)((crushe*100)/maxcrushe) ); + } + + snprintf(ITEM_itemStatusStringBuffer, + sizeof( ITEM_itemStatusStringBuffer), + +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s|%d|%s|%d|", +#else + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s|%d|%s", +#endif +#else + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s", +#endif + escapename, paramshow, + itemcolor, escapeeffectstring , + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getInt( itemindex, ITEM_ABLEUSEFIELD), + ITEM_getInt( itemindex, ITEM_TARGET), + ITEM_getInt( itemindex, ITEM_LEVEL), + flg, + buff1 +#ifdef _ITEM_PILENUMS + ,ITEM_getInt( itemindex, ITEM_USEPILENUMS) +#ifdef _ALCHEMIST + ,INGNAME0 //,ITEM_getInt( itemindex, ITEM_ALCHEMIST) + , ITEM_getInt( itemindex, ITEM_TYPE) +#endif +#endif + ); +#else + snprintf(ITEM_itemStatusStringBuffer, + sizeof( ITEM_itemStatusStringBuffer), + "%s|%s|%d|%s|%d|%d|%d|%d|%d", + escapename, paramshow, + itemcolor, escapeeffectstring , + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getInt( itemindex, ITEM_ABLEUSEFIELD), + ITEM_getInt( itemindex, ITEM_TARGET), + ITEM_getInt( itemindex, ITEM_LEVEL), + flg + ); +#endif + }else { +#ifdef _ADD_SHOW_ITEMDAMAGE // WON ADD ʾƷ;ö + char buff1[256]; + int crushe = ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE); + int maxcrushe = ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE); + if(crushe < 1) crushe = 1; + if(maxcrushe < 1){ + sprintf(buff1, ""); + }else{ + maxcrushe = maxcrushe/1000; + crushe = crushe/1000; + if( maxcrushe <= 0 ) maxcrushe = 1; + snprintf(buff1, sizeof(buff1), "%d%%", (int)((crushe*100)/maxcrushe) ); + } + snprintf(ITEM_itemStatusStringBuffer, sizeof( ITEM_itemStatusStringBuffer), + +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s|%d|%s|%d|", +#else + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s|%d", +#endif +#else + "%s|%s|%d|%s|%d|%d|%d|%d|%d|%s", +#endif + escapename, paramshow, + itemcolor, escapeeffectstring , + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getInt( itemindex, ITEM_ABLEUSEFIELD), + ITEM_getInt( itemindex, ITEM_TARGET), + ITEM_getInt( itemindex, ITEM_LEVEL), + flg, + buff1 +#ifdef _ITEM_PILENUMS + ,ITEM_getInt( itemindex, ITEM_USEPILENUMS) +#ifdef _ALCHEMIST + ,INGNAME0 //,ITEM_getInt( itemindex, ITEM_ALCHEMIST) + , ITEM_getInt( itemindex, ITEM_TYPE) +#endif +#endif + ); +#else + snprintf(ITEM_itemStatusStringBuffer, + sizeof( ITEM_itemStatusStringBuffer), + "%d|%s|%s|%d|%s|%d|%d|%d|%d|%d", + haveitemindex, + escapename, paramshow, + itemcolor, escapeeffectstring , + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getInt( itemindex, ITEM_ABLEUSEFIELD), + ITEM_getInt( itemindex, ITEM_TARGET), + ITEM_getInt( itemindex, ITEM_LEVEL), + flg + ); +#endif + } + return ITEM_itemStatusStringBuffer; +} + +char* ITEM_makeItemFalseString( void ) +{ + +#ifdef _ADD_SHOW_ITEMDAMAGE // WON ADD ʾƷ;ö + strcpysafe( ITEM_itemStatusStringBuffer, + sizeof( ITEM_itemStatusStringBuffer), +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST + "||||||||||||||" +#else + "|||||||||||" +#endif +#else + "||||||||||" +#endif + ); + +#else + strcpysafe( ITEM_itemStatusStringBuffer, + sizeof( ITEM_itemStatusStringBuffer), + "||||||||" ); +#endif + return ITEM_itemStatusStringBuffer; +} + +char* ITEM_makeItemFalseStringWithNum( int haveitemindex ) +{ +#ifdef _ADD_SHOW_ITEMDAMAGE // WON ADD ʾƷ;ö + snprintf( ITEM_itemStatusStringBuffer, sizeof( ITEM_itemStatusStringBuffer), + +#ifdef _ITEM_PILENUMS +#ifdef _ALCHEMIST + "%d||||||||||||||", +#else + "%d||||||||||", +#endif +#else + "%d|||||||||", +#endif + haveitemindex ); +#else + snprintf( ITEM_itemStatusStringBuffer, sizeof( ITEM_itemStatusStringBuffer), + "%d|||||||||", haveitemindex); +#endif + return ITEM_itemStatusStringBuffer; +} + +BOOL ITEM_makeItem( ITEM_Item* itm, int number ) +{ + int i; + if( ITEM_CHECKITEMTABLE(number) == FALSE ){ + //print(" Can't makeItem for itemid:%d!!\n", number); + return FALSE; + } + memcpy( itm, &ITEM_tbl[ITEM_idx[number].index].itm , sizeof( ITEM_Item ) ); //new + for( i=0 ; idata[i] = ITEM_tbl[ITEM_idx[number].index].itm.data[i] + randomvalue; //new + } + itm->data[ITEM_LEAKLEVEL] = 0; + return TRUE; +} + +int ITEM_makeItemAndRegist( int number ) +{ + ITEM_Item itm; + memset( &itm, 0, sizeof( itm)); + if( ITEM_makeItem( &itm, number ) == FALSE ) + return -1; + return ITEM_initExistItemsOne( &itm ); +} + +#define EQUIP_FIX_MAX 10000000 +void ITEM_equipEffect( int index ) +{ + int i; + int attribaccum[4] = { 0,0,0,0}; +#ifdef _ANGEL_SUMMON + int angelmode, angelequip =0; +#endif + static struct itmeffectstruct{ + int itemdataintindex; + int charmodifyparamindex; + int accumulation; + int min; + int max; + int type; + }itemEffect[]={ + { ITEM_MODIFYATTACK, CHAR_WORKATTACKPOWER, 0, 0, EQUIP_FIX_MAX, 0}, + { ITEM_MODIFYDEFENCE, CHAR_WORKDEFENCEPOWER, -100, 0, EQUIP_FIX_MAX, 0}, + { ITEM_MODIFYQUICK, CHAR_WORKQUICK, -100, 0, EQUIP_FIX_MAX, 0}, + { ITEM_MODIFYHP, CHAR_WORKMAXHP, 0, 0, EQUIP_FIX_MAX, 0}, + { ITEM_MODIFYMP, CHAR_WORKMAXMP, 0, 0, 1000, 0}, // MP 100ƥ + + { ITEM_MODIFYLUCK, CHAR_WORKFIXLUCK, 0, 1, 5, 0}, + { ITEM_MODIFYCHARM, CHAR_WORKFIXCHARM, 0, 0, 100, 0}, + { ITEM_MODIFYAVOID, CHAR_WORKFIXAVOID, 0, 0, EQUIP_FIX_MAX, 0}, + { ITEM_POISON, CHAR_WORKMODPOISON, 0, -100, 100, 0}, + { ITEM_PARALYSIS, CHAR_WORKMODPARALYSIS, 0, -100, 100, 0}, + { ITEM_SLEEP, CHAR_WORKMODSLEEP, 0, -100, 100, 0}, + { ITEM_STONE, CHAR_WORKMODSTONE, 0, -100, 100, 0}, + { ITEM_DRUNK, CHAR_WORKMODDRUNK, 0, -100, 100, 0}, + { ITEM_CONFUSION, CHAR_WORKMODCONFUSION, 0, -100, 100, 0}, + { ITEM_CRITICAL, CHAR_WORKMODCRITICAL, 0, -100, 100, 0}, +#ifdef _ADD_DEAMGEDEFC + { ITEM_OTHERDAMAGE, CHAR_WORKOTHERDMAGE, 0, -100, 100, 0}, + { ITEM_OTHERDEFC, CHAR_WORKOTHERDEFC, 0, -100, 100, 0}, +#endif + +#ifdef _ITEMSET5_TXT + { ITEM_MODIFYARRANGE, CHAR_WORKFIXARRANGE, 0, 0, 1000, 0}, + { ITEM_MODIFYSEQUENCE, CHAR_WORKFIXSEQUENCE, 0, 0, 100, 1}, + { ITEM_ATTACHPILE, CHAR_WORKATTACHPILE, 0, 0, 10, 1}, + { ITEM_HITRIGHT, CHAR_WORKHITRIGHT, 0, 0, 40, 1}, +#endif +#ifdef _ITEMSET6_TXT + { ITEM_NEGLECTGUARD, CHAR_WORKNEGLECTGUARD, 0, 0, 30, 1}, +#endif + }; + + for( i = 0 ; i < arraysizeof( itemEffect ); i ++ ) + itemEffect[i].accumulation = 0; + + if( !CHAR_CHECKINDEX(index) )return; + +#ifdef _ANGEL_SUMMON + angelmode = CHAR_getWorkInt( index, CHAR_WORKANGELMODE); +#endif + + for( i = 0 ; i < CHAR_EQUIPPLACENUM ; i ++ ){ +#ifdef _ALLBLUES_LUA_1_9 + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + if(EquipEffectFunction(index, i) == FALSE){ + continue; + } + } + +#endif + + int id = CHAR_getItemIndex(index,i); + if( ITEM_CHECKINDEX(id) ){ + int j; + int attrib = 0; + char *arg = ITEM_getChar( id, ITEM_ARGUMENT); +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( i == CHAR_ARM ) + CHAR_sendStatusString( index , "S"); +#endif + + for( j=0; j < arraysizeof( itemEffect ); j ++ ) { +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + + if( i == CHAR_EQSHIELD && CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPET){ + int item_type = ITEM_FIST; + item_type = ITEM_getInt( id, ITEM_TYPE ); + + // װʱ + if( item_type != ITEM_WSHIELD ){ + int k; + // ʿְҵܶ + for( k=0; kskill, SKILL_LEVEL); + skill_level = PROFESSION_CHANGE_SKILL_LEVEL_A( skill_level ); + rate = (skill_level * 3 + 20); + value = ITEM_getInt( id, itemEffect[j].itemdataintindex ) * rate / 100; + itemEffect[j].accumulation += value; + } + } + }else + itemEffect[j].accumulation += ITEM_getInt( id, itemEffect[j].itemdataintindex ); + }else +#endif +#ifdef _ITEM_PERCENTAGE + if( (ITEM_MODIFYATTACK==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYDEFENCE==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYQUICK==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYHP==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYMP==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYLUCK==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYCHARM==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL ) + || ( ITEM_MODIFYAVOID==itemEffect[j].itemdataintindex && strstr( arg, "" ) != NULL )){ + + itemEffect[j].accumulation += CHAR_getWorkInt(index,itemEffect[j].charmodifyparamindex) * ITEM_getInt( id, itemEffect[j].itemdataintindex ) / 100; + }else +#endif + itemEffect[j].accumulation += ITEM_getInt( id, itemEffect[j].itemdataintindex ); + } + + attrib = ITEM_getInt( id, ITEM_MODIFYATTRIB); + if( attrib > 0 && attrib < 5) { + attribaccum[attrib - 1] += ITEM_getInt( id, ITEM_MODIFYATTRIBVALUE); + } + +#ifdef _ANGEL_SUMMON + //if( !strcmp( ITEM_getChar( id, ITEM_USEFUNC), "ITEM_AngelToken") ) { + if( ITEM_getInt( id, ITEM_ID) == ANGELITEM ) { + //print(" ʹװ "); + angelequip = TRUE; + } +#endif + +#ifdef _ITEM_UPLEVEL + int level = ITEM_getInt(id, ITEM_LEAKLEVEL); + + if(ITEM_getInt( id, ITEM_MODIFYATTACK )>0){ + CHAR_setWorkInt(index,CHAR_WORKFIXSTR, CHAR_getWorkInt(index,CHAR_WORKFIXSTR) + level*1 ); + } + if(ITEM_getInt( id, ITEM_MODIFYDEFENCE )>0){ + CHAR_setWorkInt(index,CHAR_WORKFIXTOUGH, CHAR_getWorkInt(index,CHAR_WORKFIXTOUGH) + level*1 ); + } + if(ITEM_getInt( id, ITEM_MODIFYQUICK )>0){ + CHAR_setWorkInt(index,CHAR_WORKFIXDEX, CHAR_getWorkInt(index,CHAR_WORKFIXDEX) + level*1 ); + } + if(ITEM_getInt( id, ITEM_MODIFYHP )>0){ + CHAR_setWorkInt(index,CHAR_WORKMAXHP, CHAR_getWorkInt(index,CHAR_WORKMAXHP) + level*5 ); + } + if(ITEM_getInt( id, ITEM_MODIFYMP )>0){ + CHAR_setWorkInt(index,CHAR_WORKMAXMP, CHAR_getWorkInt(index,CHAR_WORKMAXMP) + level*2 ); + } + + if(level == 20){ + int armtype = ITEM_getInt( id, ITEM_TYPE ); + if( armtype == ITEM_FIST + || armtype == ITEM_AXE + || armtype == ITEM_CLUB + || armtype == ITEM_SPEAR + || armtype == ITEM_BOW + || armtype == ITEM_BOOMERANG + || armtype == ITEM_BOUNDTHROW + || armtype == ITEM_BREAKTHROW +#ifdef _PET_ITEM + || armtype == ITEM_PET_HEAD + || armtype == ITEM_PET_TOOTH + || armtype == ITEM_PET_CLAW + || armtype == ITEM_PET_BREAST + || armtype == ITEM_PET_BACK + || armtype == ITEM_PET_WING + || armtype == ITEM_PET_FEET +#endif + ){ + CHAR_setWorkInt(index,CHAR_WORKMAXMP, CHAR_getWorkInt(index,CHAR_WORKMAXMP) + 20 ); + }else if( armtype == ITEM_HELM + || armtype == ITEM_ARMOUR){ + CHAR_setWorkInt(index,CHAR_WORKMAXHP, CHAR_getWorkInt(index,CHAR_WORKMAXHP) + 30 ); + } + } + +#endif + + } + } +#ifdef _PLAYER_EFFECT + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + if(CHAR_getWorkInt( index, CHAR_PLAYER_EFFECT )>0){ + char msg[256]; + sprintf(msg,"2|%d",CHAR_getWorkInt( index, CHAR_PLAYER_EFFECT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(index), msg); + } + } +#endif +#ifdef FAMILY_MANOR_ + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + if(CHAR_getWorkInt( index, CHAR_PLAYER_EFFECT_MANOR ) > 0){ + char msg[256]; + sprintf(msg,"3|%d",CHAR_getWorkInt( index, CHAR_PLAYER_EFFECT_MANOR )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(index), msg); + } + } +#endif +#ifdef _TRUMP_EQUIPMENT + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + if(CHAR_getInt( index, CHAR_TRUMP_EFFECT ) > 0){ + char msg[256]; + sprintf(msg,"5|%d",CHAR_getInt( index, CHAR_TRUMP_EFFECT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(index), msg); + } + } +#endif + +#ifdef _NEW_UPDATETITLE + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + if(CHAR_getInt( index, CHAR_TITLE_DEFAULT ) > 0){ + char msg[256]; + sprintf(msg,"4|%d",CHAR_getInt( index, CHAR_TITLE_DEFAULT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(index), msg); + } + } +#endif + +#ifdef _FAMILYBADGE_ + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER){ + extern int getFamilyBadge(int index); + int badge = getFamilyBadge(index); + if(badge){ + char msg[256]; + sprintf(msg,"1|%d",badge); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(index), msg); + } + } +#endif + + + +#ifdef _ANGEL_SUMMON + if( angelmode == TRUE && angelequip == FALSE ) { + CHAR_setWorkInt( index, CHAR_WORKANGELMODE, FALSE); + CHAR_sendAngelMark( CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), 0); + print(" жʹ "); + } + if( angelmode == FALSE && angelequip == TRUE ) { + CHAR_setWorkInt( index, CHAR_WORKANGELMODE, TRUE); + CHAR_sendAngelMark( CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), 1); + CHAR_talkToCli( index, -1, "ܵ˾鱣ᱻ˹", CHAR_COLORYELLOW ); + print(" װʹ "); + } +#endif + +#ifdef _FIX_MAXCHARMP + for(i = 3 ; i < arraysizeof( itemEffect ) ; i ++ ){ +#else + for(i = 5 ; i < arraysizeof( itemEffect ) ; i ++ ){ +#endif + int work=0; + if( itemEffect[i].type == 1 ){ + work = itemEffect[i].accumulation; + }else{ + work = CHAR_getWorkInt(index,itemEffect[i].charmodifyparamindex) + itemEffect[i].accumulation; + work = min( itemEffect[i].max, work ); + work = max( itemEffect[i].min, work ); + } + + CHAR_setWorkInt( index, itemEffect[i].charmodifyparamindex, work ); + } + + + for( i = 0; i < 4; i ++ ) { + CHAR_setWorkInt( index, CHAR_WORKFIXEARTHAT + i, + CHAR_getWorkInt( index, CHAR_WORKFIXEARTHAT + i) + + attribaccum[i]); + } + for( i = 0; i < 4; i ++ ) { + int j; + for( j = 0; j < 4; j ++ ) { + if( i != j ) { + CHAR_setWorkInt( index, CHAR_WORKFIXEARTHAT + j, + CHAR_getWorkInt(index, CHAR_WORKFIXEARTHAT + j) - attribaccum[i]); + } + } + } + for( i = 0; i < 4; i ++ ) { + if( CHAR_getWorkInt( index, CHAR_WORKFIXEARTHAT + i) > CHAR_MAXATTRIB) { + CHAR_setWorkInt( index, CHAR_WORKFIXEARTHAT + i, CHAR_MAXATTRIB); + } + } + + { + int work; +#ifdef _BT_ITEM + work = CHAR_getWorkInt(index,CHAR_WORKFIXSTR)+ itemEffect[0].accumulation*getBtItem(); +#else + work = CHAR_getWorkInt(index,CHAR_WORKFIXSTR)+ itemEffect[0].accumulation; +#endif + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, max( 0, work ) ); +#ifdef _BT_ITEM + work = CHAR_getWorkInt(index,CHAR_WORKFIXTOUGH)+ itemEffect[1].accumulation*getBtItem(); +#else + work = CHAR_getWorkInt(index,CHAR_WORKFIXTOUGH)+ itemEffect[1].accumulation; +#endif + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, max( -100, work ) ); +#ifdef _BT_ITEM + work = CHAR_getWorkInt(index,CHAR_WORKFIXDEX)+ itemEffect[2].accumulation*getBtItem(); +#else + work = CHAR_getWorkInt(index,CHAR_WORKFIXDEX)+ itemEffect[2].accumulation; +#endif + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, max( -100, work ) ); + } +} + +void Other_DefcharWorkInt( int index) +{ + +#ifdef _SUIT_ITEM + int mfix,mtgh,mdex,mods,maxhp; + mfix = CHAR_getWorkInt( index, CHAR_WORKFIXSTR); + mtgh = CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH); + mdex = CHAR_getWorkInt( index, CHAR_WORKFIXDEX); + maxhp = CHAR_getWorkInt( index, CHAR_WORKMAXHP); + + mods = CHAR_getWorkInt( index, CHAR_WORKSUITMODSTR); + mfix = mfix+((mfix*mods)/100); + + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, mfix+CHAR_getWorkInt( index, CHAR_WORKSUITSTR)); + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, mtgh+CHAR_getWorkInt( index, CHAR_WORKSUITTGH)); + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, mdex+CHAR_getWorkInt( index, CHAR_WORKSUITDEX)); + CHAR_setWorkInt( index, CHAR_WORKMAXHP, maxhp+ CHAR_getWorkInt( index, CHAR_WORKSUITVIT)); + +#ifdef _SUIT_ADDPART3 + if( mfix > 0 ) + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, CHAR_getWorkInt( index, CHAR_WORKFIXSTR)+mfix*CHAR_getWorkInt( index, CHAR_WORKSUITSTR_P)/100.0); + if( mtgh > 0 ) + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH)+mtgh*CHAR_getWorkInt( index, CHAR_WORKSUITTGH_P)/100.0); + if( mdex > 0) + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, CHAR_getWorkInt( index, CHAR_WORKFIXDEX)+mdex*CHAR_getWorkInt( index, CHAR_WORKSUITDEX_P)/100.0); +#endif +#endif//_SUIT_ITEM + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + /*{ + int f_res = -1, i_res = -1, t_res = -1; + f_res = CHAR_getWorkInt( index, CHAR_WORK_F_RESIST ); + i_res = CHAR_getWorkInt( index, CHAR_WORK_I_RESIST ); + t_res = CHAR_getWorkInt( index, CHAR_WORK_T_RESIST ); + + CHAR_setWorkInt( index, CHAR_WORK_F_RESIST, f_res+CHAR_getWorkInt( index, CHAR_WORK_F_SUIT ) ); + CHAR_setWorkInt( index, CHAR_WORK_I_RESIST, i_res+CHAR_getWorkInt( index, CHAR_WORK_I_SUIT ) ); + CHAR_setWorkInt( index, CHAR_WORK_T_RESIST, t_res+CHAR_getWorkInt( index, CHAR_WORK_T_SUIT ) ); + }*/ +#endif + + +#ifdef _PETSKILL_SETDUCK + //profession fix + //ʹûرʽʱ,Ὣֵȥ30%Ȼ趨ɻرֵ,ֵ趨,Ҳԭ趨Ļرֵûһ,(Change)Ȱõ + /*if( CHAR_getWorkInt( index, CHAR_MYSKILLDUCK) > 0 ){ + int mtgh = CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH); + mtgh -= (mtgh*30)/100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_MYSKILLDUCKPOWER, mtgh); + }*/ +#endif +#ifdef _MAGICPET_SKILL + if( CHAR_getWorkInt( index, CHAR_MYSKILLSTR) > 0 ){ + int mpower, mdef; + mpower = CHAR_getWorkInt( index, CHAR_WORKFIXSTR); + mdef = CHAR_getWorkInt( index, CHAR_MYSKILLSTRPOWER); + mpower += (mtgh*mdef)/100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, mpower); + } + if( CHAR_getWorkInt( index, CHAR_MYSKILLTGH) > 0 ){ + int mpower, mdef; + mpower = CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH); + mdef = CHAR_getWorkInt( index, CHAR_MYSKILLTGHPOWER); + mpower += (mtgh*mdef)/100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, mpower); + } + if( CHAR_getWorkInt( index, CHAR_MYSKILLDEX) > 0 ){ + int mpower, mdef; + mpower = CHAR_getWorkInt( index, CHAR_WORKFIXDEX); + mdef = CHAR_getWorkInt( index, CHAR_MYSKILLDEXPOWER); + mpower += (mtgh*mdef)/100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, mpower); + } +#endif + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( CHAR_getWorkInt( index, CHAR_MYSKILLHIT) > 0 ){ + int mpower, mdef; + mpower = CHAR_getWorkInt( index, CHAR_MYSKILLHIT); + mdef = CHAR_getWorkInt( index, CHAR_WORKHITRIGHT); + mpower += (mtgh*mdef)/100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_MYSKILLHIT, mpower); + } + if( CHAR_getWorkInt( index, CHAR_WORK_WEAPON) > 0 ){ // ר + int mpower, mdef; + mpower = CHAR_getWorkInt( index, CHAR_WORKFIXSTR); + mdef = CHAR_getWorkInt( index, CHAR_WORKMOD_WEAPON); + mpower = mpower * ( 100 + mdef ) /100; + if( mtgh < 0 ) mtgh=0; + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, mpower); + } +#endif + +#ifdef _VARY_WOLF + if(CHAR_getInt( index, CHAR_BASEIMAGENUMBER)==101428 +#ifdef _EXPANSION_VARY_WOLF + || CHAR_getInt( index, CHAR_BASEIMAGENUMBER)==104109 +#endif + ){ + int Rands=0, power; + Rands = CHAR_getWorkInt( index, CHAR_SKILLSTRPOWER); + power = CHAR_getWorkInt( index, CHAR_WORKFIXSTR); + power = power + (power*Rands)/100; + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, power); + + Rands = CHAR_getWorkInt( index, CHAR_SKILLTGHPOWER); + power = CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH); + power = power + (power*Rands)/100; + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, power); + + Rands = CHAR_getWorkInt( index, CHAR_SKILLDEXPOWER); + power = CHAR_getWorkInt( index, CHAR_WORKFIXDEX); + power = power + (power*Rands)/100; + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, power); + } +#endif + +#ifdef _PROFESSION_ADDSKILL + if( CHAR_getWorkInt( index, CHAR_WORKFEAR ) > 0 ){ + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, CHAR_getWorkInt( index, CHAR_WORKFIXSTR ) - mfix*0.1 ); + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH ) - mtgh*0.1 ); + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, CHAR_getWorkInt( index, CHAR_WORKFIXDEX ) - mdex*0.2 ); + } +#endif + +#ifdef _MAGIC_WEAKEN + if(CHAR_getWorkInt(index,CHAR_WORKWEAKEN)>0){ + CHAR_setWorkInt( index, CHAR_WORKFIXSTR, CHAR_getWorkInt( index, CHAR_WORKFIXSTR)*0.8); + CHAR_setWorkInt( index, CHAR_WORKFIXTOUGH, CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH)*0.8); + CHAR_setWorkInt( index, CHAR_WORKFIXDEX, CHAR_getWorkInt( index, CHAR_WORKFIXDEX)*0.8); + CHAR_setWorkInt( index, CHAR_WORKWEAKEN, CHAR_getWorkInt( index, CHAR_WORKWEAKEN)-1); + } +#endif +#ifdef _MAGIC_BARRIER// vincent :ħ + if( CHAR_getWorkInt( index, CHAR_WORKBARRIER) > 0){ + CHAR_setWorkInt( index, CHAR_WORKBARRIER, CHAR_getWorkInt( index, CHAR_WORKBARRIER) - 1); + } +#endif + + CHAR_setWorkInt(index, CHAR_WORKATTACKPOWER, CHAR_getWorkInt( index, CHAR_WORKFIXSTR ) ); + CHAR_setWorkInt(index, CHAR_WORKDEFENCEPOWER, CHAR_getWorkInt( index, CHAR_WORKFIXTOUGH ) ); + CHAR_setWorkInt(index, CHAR_WORKQUICK, CHAR_getWorkInt( index, CHAR_WORKFIXDEX ) ); +} + +char* ITEM_getAppropriateName(int itemindex) +{ + int nameindex; + if( !ITEM_CHECKINDEX(itemindex ) )return "\0"; + if( ITEM_getInt(itemindex,ITEM_LEAKLEVEL) <= 0 ) + nameindex = ITEM_NAME; + else + nameindex = ITEM_SECRETNAME; + return ITEM_getChar(itemindex,nameindex); + +} + +char* ITEM_getEffectString( int itemindex ) +{ + if( !ITEM_CHECKINDEX(itemindex))return "\0"; + return ITEM_item[itemindex].itm.string[ITEM_EFFECTSTRING].string; +} + +char *ITEM_getItemInfoFromNumber( int itemid ) +{ + return ITEMTBL_getChar( itemid, ITEM_EFFECTSTRING); +} + +INLINE char* _ITEM_getArgumentString( char *file, int line, int itemid ) +{ + if( ITEM_CHECKITEMTABLE(itemid) == FALSE ){ + print("Can't Get ItemTable for:%d! - %s:%d\n",itemid, file, line); + return "\0"; + } + return ITEMTBL_getChar( itemid, ITEM_ARGUMENT); +} + +INLINE char* _ITEM_getNameFromNumber( char *file, int line, int itemid ) +{ + if( ITEM_CHECKITEMTABLE(itemid) == FALSE ){ + print("Can't Get ItemTable for:%d! - %s:%d\n",itemid, file, line); + return "\0"; + } + return ITEMTBL_getChar( itemid, ITEM_NAME); +} + +int ITEM_getcostFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_COST); +} + +int ITEM_getlevelFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_LEVEL); +} + +int ITEM_getgraNoFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_BASEIMAGENUMBER); +} + +int ITEM_getcanpetmailFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_CANPETMAIL); +} + +int ITEM_getvanishatdropFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_VANISHATDROP); +} + +int ITEM_getdropatlogoutFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_DROPATLOGOUT); +} + +int ITEM_getmergeItemFromFromITEMtabl( int itemid ) +{ + return ITEMTBL_getInt( itemid, ITEM_CANMERGEFROM); +} + +BOOL ITEM_canuseMagic( int itemindex) +{ + if( !ITEM_CHECKINDEX(itemindex))return FALSE; + if( MAGIC_getMagicArray( ITEM_item[itemindex].itm.data[ITEM_MAGICID]) != -1 ) { + return TRUE; + } + return FALSE; +} + +INLINE ITEM_Item *ITEM_getItemPointer( int index ) +{ + if(!ITEM_CHECKINDEX(index))return NULL; + return &ITEM_item[index].itm; +} + +int ITEM_isTargetValid( int charaindex, int itemindex, int toindex) +{ + int itemtarget; + int Myside; + itemtarget = ITEM_getInt( itemindex, ITEM_TARGET ); + + Myside = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLESIDE ); + if ((toindex >= 0x0) && (toindex <= 0x13)) return 0; + + if (toindex == 0x14) {//20 ȫ 0 + if (itemtarget == ITEM_TARGET_ALLMYSIDE){ + if( Myside == 0 )return 0; + }else if(itemtarget == ITEM_TARGET_ALLOTHERSIDE ){ + if( Myside == 1 )return 0; + } + }else if (toindex == 0x15) {//21 ȫ 1 + if (itemtarget == ITEM_TARGET_ALLMYSIDE){ + if( Myside == 1 )return 0; + }else if( itemtarget == ITEM_TARGET_ALLOTHERSIDE ){ + if( Myside == 0 )return 0; + } + }else if (toindex == 0x16) { + if (itemtarget == ITEM_TARGET_ALL) + return 0; + } + return -1; +} +// Nuke end + + +#ifdef _ITEM_CHECKWARES +BOOL CHAR_CheckInItemForWares( int charaindex, int flg) +{ + int itemindex, i; + char token[256]; + + for( i=0; i= ITEM_DATAINTNUM || datatype < 0 ) return -1; + if( ITEM_CHECKITEMTABLE(ItemID) == FALSE )return -1; + return ITEM_tbl[ITEM_idx[ItemID].index].itm.data[datatype]; //new +} + +char *ITEMTBL_getChar( int ItemID, ITEM_DATACHAR datatype) +{ + if( datatype >= ITEM_DATACHARNUM || datatype < 0 ) return "\0"; + if( ITEM_CHECKITEMTABLE(ItemID) == FALSE )return "\0"; + return ITEM_tbl[ITEM_idx[ItemID].index].itm.string[datatype].string; //new +} + +INLINE BOOL ITEM_CHECKITEMTABLE( int number ) +{ + if( number < 0 || number >= ITEM_idxlen ){ + //andy_log + print("ITEM_CHECKITEMTABLE() number:%d ITEM_tblen:%d !!\n", number, ITEM_idxlen ); + return FALSE; + } + return ITEM_idx[number].use; //new +} +#ifdef _TAKE_ITEMDAMAGE +int ITEM_getItemDamageCrusheED( int itemindex) +{ + int crushe = ITEM_getInt( itemindex, ITEM_DAMAGECRUSHE); + int maxcrushe = ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE); + if(maxcrushe < 1)return -1; + if( maxcrushe > 1000000) maxcrushe = 1000000; + if( crushe > 1000000) crushe = 1000000; + + return ((int) (crushe*100)/maxcrushe); +} +#endif +void ITEM_RsetEquit( int charaindex) +{ + int i, itemindex, ti=-1; + for( i=0; i /* strstr */ +#include /* isdigit, isalnum */ +#include "common.h" +#include "configfile.h" +#include "char.h" +#include "char_base.h" +#include "char_data.h" +#include "battle_event.h" +#include "configfile.h" +#include "item.h" +#include "item_event.h" +#include "object.h" +#include "anim_tbl.h" +#include "magic.h" +#include "chatmagic.h" +#include "handletime.h" +#include "log.h" +#include "family.h" +#include "util.h" +#include "encount.h" +#include "battle.h" +#include "battle_item.h" +#include "lssproto_serv.h" +#include "net.h" +#include "pet.h" +#include "readmap.h" +#include "npcutil.h" +#include "enemy.h" +#include "saacproto_cli.h" +#include "char_talk.h" +#ifdef _Item_ReLifeAct +#include "battle_magic.h" +#endif +#ifdef _ITEM_WARP_FIX_BI +extern tagRidePetTable ridePetTable[296]; +#endif +#include "pet_skill.h" +#include "npc_poolitemshop.h" +#ifdef _CFREE_petskill +#include "npc_freepetskillshop.h" +#endif +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#endif +#include "npc_petshop.h" +#ifdef _ITEM_LUA +#include "npc_lua.h" +#include "npc_lua_interface.h" +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +int ITEM_TimeDelCheck( int itemindex ) +{ + int icnt, jcnt, playernum; + playernum = CHAR_getPlayerMaxNum(); + for( icnt = 0; icnt < playernum; icnt ++ ) { + if( CHAR_CHECKINDEX( icnt ) ) { + for( jcnt = 0; jcnt < CheckCharMaxItem(icnt); jcnt ++ ) { + if( CHAR_getItemIndex( icnt, jcnt ) == itemindex ) { + print( "Чʱѵֵߴ(%s)(%s)\n", + CHAR_getUseName(icnt),ITEM_getAppropriateName(itemindex) ); + return FALSE; + } + } + } + } + return TRUE; +} + +int ITEM_eventDrop( int itemindex, int charaindex, int itemcharaindex ) +{ + typedef void (*DROPF)(int,int); + char szBuffer[256]=""; + DROPF dropfunc=NULL; + + if( ITEM_CHECKINDEX(itemindex) == FALSE )return -1; + + dropfunc=(DROPF)ITEM_getFunctionPointer( itemindex, ITEM_DROPFUNC ); + if( dropfunc ){ + dropfunc( charaindex, itemindex ); + } +#ifdef _ALLBLUES_LUA_1_2 + else{ + RunItemDropEvent(charaindex, itemindex ); + } +#endif + if( ITEM_getInt( itemindex, ITEM_VANISHATDROP) != 1 )return 0; + snprintf( szBuffer, sizeof( szBuffer), "%s ˡ", + ITEM_getAppropriateName(itemindex) ); + CHAR_talkToCli( charaindex, -1, szBuffer, CHAR_COLORWHITE ); + + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "Drop&Delete(ʧ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_setItemIndex( charaindex, itemcharaindex, -1); + ITEM_endExistItemsOne( itemindex ); + return 1; +} + +#undef UNDEF +#define UNDEF (-1) + +typedef struct { + char* cmd; /* ġ ٯ */ + char* onmessage; /* ٯ */ + char* offmessage; /* ٯ */ + int element; /* ޱئۢ */ + int maxElement; /* elementƥ϶ýľۢټ ëֹۢ */ +} ITEM_EFFECTPARAM; +static ITEM_EFFECTPARAM ITEM_restorableParam[] = { + {"hp", "HPظˡ", "HPˡ",CHAR_HP, CHAR_WORKMAXHP}, + {"mp", "MPظˡ", "MPˡ",CHAR_MP, CHAR_WORKMAXMP}, +}; +static ITEM_EFFECTPARAM ITEM_statusParam[] = { + {"po", CHAR_POISONSTRING, CHAR_RECOVERPOISONSTRING, + CHAR_POISON, UNDEF}, + + {"pa", CHAR_PARALYSISSTRING, CHAR_RECOVERPARALYSISSTRING, + CHAR_PARALYSIS, UNDEF}, + + {"si", CHAR_SILENCESTRING, CHAR_RECOVERSILENCESTRING, + CHAR_SLEEP,UNDEF}, + + {"st", CHAR_STONESTRING, CHAR_RECOVERSTONESTRING, CHAR_STONE, UNDEF}, + + {"da", CHAR_DARKNESSSTRING, CHAR_RECOVERDARKNESSSTRING, + CHAR_DRUNK,UNDEF}, + + {"co", CHAR_CONFUSIONSTRING,CHAR_RECOVERCONFUSIONSTRING, + CHAR_CONFUSION, UNDEF}, +}; + +/*#define LOCAL_DEBUG*/ +#ifdef LOCAL_DEBUG +#define DOUTFILE "doutfile" +#include +#include +static int eprintf(char* format, ...){ + va_list arg; + long len; + FILE* fp; + fp = fopen(DOUTFILE, "a"); + va_start(arg, format); + len = vfprintf(stderr, format, arg); + if(fp){ vfprintf(fp, format, arg); fclose(fp); } + va_end(arg); + return len; +} + +#define fprint eprintf +#endif + +static BOOL ITEM_isValidEffect(char* cmd, int value){ + int i; + + for(i=0; istring[ITEM_ARGUMENT].string; + if(* effectarg == '\0') return TRUE; + for(p=effectarg; *p != '\0'; ){ + int i; + if(*p == SEPARATORI) p++; + for(q=cmd, i=0; isalnum(*p) && i 0 ) + onoroff=ITEM_restorableParam[i].onmessage; + else if( amount < 0 ) + onoroff=ITEM_restorableParam[i].offmessage; + else + return FALSE; + strcpysafe( ansmsg, sizeof(ansmsg), onoroff ); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE); + return TRUE; +#else + if(value == ITEM_EFFECT_RESTORE_NORMAL){ + int maxv, curv, amount; + maxv =CHAR_getWorkInt(charaindex, ITEM_restorableParam[i].maxElement); + curv =CHAR_getInt(charaindex, ITEM_restorableParam[i].element); + amount = 30; + if(curv + amount < 0) amount = -curv; + CHAR_setInt(charaindex, ITEM_restorableParam[i].element, min((curv+amount), maxv)); + snprintf( ansmsg, sizeof(ansmsg), "%sظˡ", + ITEM_restorableParam[i].onmessage ); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE); + return TRUE; + }else if(value == ITEM_EFFECT_RESTORE_COMPLETE){ + int maxv; + maxv =CHAR_getWorkInt(charaindex, ITEM_restorableParam[i].maxElement); + CHAR_setInt(charaindex, ITEM_restorableParam[i].element, maxv); + snprintf( ansmsg, sizeof(ansmsg), "%sȫظ", ITEM_restorableParam[i].onmessage ); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE ); + return TRUE; + }else + return FALSE; +#endif + + } + } + if( value >= 0 ){ + int found = 0; + for(i=0; i (int)( itemputtime + getItemdeletetime() ) ) { + if( ITEM_TimeDelCheck( itemindex ) == FALSE ){ + return ; + } + { + LogItem( + "NULL", + "NULL", +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "TiemDelete", + OBJECT_getFloor( objindex ), + OBJECT_getX( objindex ), + OBJECT_getY( objindex ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + ITEM_endExistItemsOne(itemindex); + CHAR_ObjectDelete(objindex); + } +} + +void ITEM_useEffectTohelos( int charaindex, int to_charaindex, int haveitemindex) +{ + char buf[64]; + char msgbuf[64]; + int ret; + int itemindex; + int cutrate, limitcount; + int per; + int sendcharaindex = charaindex; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ret = getStringFromIndexWithDelim( ITEM_getChar(itemindex, ITEM_ARGUMENT) , + "|", 1, buf, sizeof( buf)); + if( ret != TRUE ) { + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "FieldErrorUse", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + ITEM_endExistItemsOne( itemindex); + return; + } + cutrate = atoi( buf); + if( cutrate < 0 ) cutrate = 0; + ret = getStringFromIndexWithDelim( ITEM_getChar(itemindex, ITEM_ARGUMENT) , + "|", 2, buf, sizeof( buf)); + if( ret != TRUE ) { + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "FieldUse", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + ITEM_endExistItemsOne( itemindex); + return; + } + limitcount = atoi( buf); + if( limitcount < 0) limitcount = 0; + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT) { + sendcharaindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + } + CHAR_setWorkInt( sendcharaindex, CHAR_WORK_TOHELOS_CUTRATE, cutrate); + CHAR_setWorkInt( sendcharaindex, CHAR_WORK_TOHELOS_COUNT, limitcount); + + snprintf( msgbuf, sizeof(msgbuf), + "ץ%s ", ITEM_getChar(itemindex, ITEM_NAME) ); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE ); + + if( sendcharaindex != charaindex ) { + snprintf( msgbuf, sizeof(msgbuf), + "%s ץ %s ", + CHAR_getChar( charaindex, CHAR_NAME), + ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli( sendcharaindex, -1, msgbuf, CHAR_COLORWHITE ); + } + + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "FieldUse", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + ITEM_endExistItemsOne( itemindex); + per = ENCOUNT_getEncountPercentMin( sendcharaindex, + CHAR_getInt( sendcharaindex, CHAR_FLOOR), + CHAR_getInt( sendcharaindex, CHAR_X), + CHAR_getInt( sendcharaindex, CHAR_Y)); + if( per != -1) { + CHAR_setWorkInt( sendcharaindex, CHAR_WORKENCOUNTPROBABILITY_MIN, per); + } + per = ENCOUNT_getEncountPercentMax( sendcharaindex, + CHAR_getInt( sendcharaindex, CHAR_FLOOR), + CHAR_getInt( sendcharaindex, CHAR_X), + CHAR_getInt( sendcharaindex, CHAR_Y)); + if( per != -1) { + CHAR_setWorkInt( sendcharaindex, CHAR_WORKENCOUNTPROBABILITY_MAX, per); + } + CHAR_sendStatusString( sendcharaindex, "E" ); +} + +void ITEM_dropMic( int charaindex , int itemindex ) +{ + if( !ITEM_CHECKINDEX( itemindex )) return; + + CHAR_setWorkInt( charaindex, CHAR_WORKFLG, + CHAR_getWorkInt( charaindex, CHAR_WORKFLG ) & ~WORKFLG_MICMODE ); +} + +void ITEM_useMic_Field( int charaindex, int to_charaindex, int haveitemindex ) +{ + if( CHAR_getWorkInt( charaindex, CHAR_WORKFLG ) & WORKFLG_MICMODE ){ + CHAR_setWorkInt( charaindex, CHAR_WORKFLG, + CHAR_getWorkInt( charaindex, CHAR_WORKFLG ) & ~WORKFLG_MICMODE ); + CHAR_talkToCli( charaindex, -1, "˷趨ΪOFF", CHAR_COLORWHITE); + }else{ + CHAR_setWorkInt( charaindex, CHAR_WORKFLG, + CHAR_getWorkInt( charaindex, CHAR_WORKFLG ) | WORKFLG_MICMODE ); + CHAR_talkToCli( charaindex, -1, "˷趨ΪON", CHAR_COLORWHITE); + } +} +#if 1 +char *aszHealStringByOwn[] = { + "%s;ظ%d", + "%sظ%d", + "%s%d", + "%sҳ϶%d", + "" +}; + +char *aszDownStringByOwn[] = { + "%s;%d", + "%s%d", + "%s½%d", + "%sҳ϶½%d", + "" +}; + +char *aszHealStringByOther[] = { + "%s%s;ظ%d", + "%s%sظ%d", + "%s%s%d", + "%s%sҳ϶%d", + "" +}; + +char *aszDownStringByOther[] = { + "%s%s;%d", + "%s%s%d", + "%s%s%d", + "%s%sҳ϶ȼ%d", + "" +}; + +char *aszKeyString[] = {"", "", "", "", ""}; +int aHealInt[] = { CHAR_HP, CHAR_MP, CHAR_CHARM, CHAR_VARIABLEAI, -1 }; +int aHealMaxWork[] = { CHAR_WORKMAXHP, CHAR_WORKMAXMP, -1, -1, -1 }; + +void ITEM_useRecovery_Field( + int charaindex, + int toindex, + int haveitemindex +){ + int work, workmax, workmin; + int power[BD_KIND_END] = {0,0,0}, + prevhp = 0, + workhp = 0, + recovery[BD_KIND_END] = {0,0,0}; + int itemindex, kind = BD_KIND_HP, HealFlg = 0, j; + char *p = NULL, *arg, msgbuf[256]; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + if( CHAR_CHECKINDEX( toindex ) == FALSE )return ; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" ) return; + +#ifdef _ITEM_UNBECOMEPIG + if( (p = strstr( arg, "" )) != NULL ){ + if( CHAR_getInt( toindex, CHAR_BECOMEPIG ) > -1 ){ + CHAR_setInt( toindex, CHAR_BECOMEPIG, -1 ); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( toindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_talkToCli( toindex,-1,"ʧЧˡ",CHAR_COLORWHITE); + CHAR_DelItemMess( charaindex, haveitemindex, 0); + } + return; + } +#endif +#ifdef _ITEM_LVUPUP + if( (p = strstr( arg, "LVUPUP" ) ) != NULL ){ + if (CHAR_getInt(toindex, CHAR_WHICHTYPE)==CHAR_TYPEPET){ + int pidx=0,lvup=0,lv=0; + sprintf( msgbuf, "%s", p+7 ); + pidx = atoi( strtok( msgbuf, " " ) ); + if( pidx != CHAR_getInt( toindex, CHAR_PETID) || CHAR_getInt(toindex, CHAR_LIMITLEVEL) == 0 ){ + CHAR_talkToCli( charaindex,-1,"޷ʹ",CHAR_COLORWHITE); + return; + } + lv = CHAR_getInt( toindex, CHAR_LV ); + if( lv < 10 || lv >= 140 ){ + CHAR_talkToCli( charaindex,-1,"Ŀǰȼ޷ʹ",CHAR_COLORWHITE); + return; + } + if( (p = strstr( arg, "" )) != NULL ) + lvup=2; + if( (p = strstr( arg, "ˮ" )) != NULL ) + lvup=3; + if( (p = strstr( arg, "" )) != NULL ) + lvup=0; + if( (p = strstr( arg, "" )) != NULL ) + lvup=1; + if( lv%4 != lvup || CHAR_getInt(toindex, CHAR_LIMITLEVEL)-lv >= 1 ){// + CHAR_talkToCli( charaindex,-1,"Ƴӡʧ",CHAR_COLORWHITE); + CHAR_DelItemMess( charaindex, haveitemindex, 0); + return; + } + CHAR_setInt(toindex, CHAR_LIMITLEVEL, CHAR_getInt(toindex, CHAR_LIMITLEVEL)+1); + CHAR_talkToCli( charaindex,-1,"ӡħߵȼ",CHAR_COLORWHITE); + if( CHAR_getInt(toindex, CHAR_LIMITLEVEL) == 140 ){ + CHAR_setInt(toindex, CHAR_LIMITLEVEL, 0); + CHAR_talkToCli( charaindex,-1,"ӡħ",CHAR_COLORWHITE); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + } + return; + } + if( (p = strstr( arg, "UPUPLV" ) ) != NULL ){ + if (CHAR_getInt(toindex, CHAR_WHICHTYPE)==CHAR_TYPEPET){ + int pidx=0,lv=0; + sprintf( msgbuf, "%s", p+7 ); + pidx = atoi( strtok( msgbuf, " " ) ); + if( pidx != CHAR_getInt( toindex, CHAR_PETID) || CHAR_getInt(toindex, CHAR_LIMITLEVEL) == 0 ){ + CHAR_talkToCli( charaindex,-1,"޷ʹ",CHAR_COLORWHITE); + return; + } + lv = CHAR_getInt( toindex, CHAR_LV ); + if( lv < 125 || lv > 140 ){ + CHAR_talkToCli( charaindex,-1,"Ŀǰȼ޷ʹ",CHAR_COLORWHITE); + return; + } + CHAR_setInt(toindex, CHAR_LIMITLEVEL, 0); + CHAR_talkToCli( charaindex,-1,"ӡħ",CHAR_COLORWHITE); + CHAR_DelItemMess( charaindex, haveitemindex, 0); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + } + return; + } +#endif +#ifdef _ITEM_PROPERTY + if( (p = strstr( arg, "PROPERTY" ) ) != NULL ){ + //print("ˮ:%s", arg ); + if (CHAR_getInt(toindex, CHAR_WHICHTYPE)!=CHAR_TYPEPLAYER) + return; + if( (p = strstr( arg, "+" ) ) != NULL ){//ת ת + if( CHAR_getInt( toindex, CHAR_EARTHAT ) == 100 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) == 100 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 && CHAR_getInt( toindex, CHAR_WATERAT ) > 0 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) > 0 && CHAR_getInt( toindex, CHAR_FIREAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) > 0 && CHAR_getInt( toindex, CHAR_WINDAT ) > 0 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) > 0 && CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + } + if( (p = strstr( arg, "-" ) ) != NULL ){//ת ת + if( CHAR_getInt( toindex, CHAR_EARTHAT ) == 100 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) == 100 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) == 100 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ); + else if( CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 && CHAR_getInt( toindex, CHAR_WATERAT ) > 0 ) + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )+10 ), + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_WATERAT ) > 0 && CHAR_getInt( toindex, CHAR_FIREAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WATERAT, CHAR_getInt( toindex, CHAR_WATERAT )+10 ), + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_FIREAT ) > 0 && CHAR_getInt( toindex, CHAR_WINDAT ) > 0 ) + CHAR_setInt( toindex, CHAR_FIREAT, CHAR_getInt( toindex, CHAR_FIREAT )+10 ), + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )-10 ); + else if( CHAR_getInt( toindex, CHAR_WINDAT ) > 0 && CHAR_getInt( toindex, CHAR_EARTHAT ) > 0 ) + CHAR_setInt( toindex, CHAR_WINDAT, CHAR_getInt( toindex, CHAR_WINDAT )+10 ), + CHAR_setInt( toindex, CHAR_EARTHAT, CHAR_getInt( toindex, CHAR_EARTHAT )-10 ); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( toindex , + CHAR_P_STRING_EARTH | + CHAR_P_STRING_WATER | + CHAR_P_STRING_FIRE | + CHAR_P_STRING_WIND + ); + return; + } +#endif +#ifdef _ITEM_ADDPETEXP + if( (p = strstr( arg, "GETEXP" )) != NULL ){ + if (CHAR_getInt(toindex, CHAR_WHICHTYPE)==CHAR_TYPEPET){ + getStringFromIndexWithDelim( arg, "|", 2, msgbuf,sizeof( msgbuf));// + if( atoi(msgbuf) == CHAR_getInt( toindex, CHAR_PETID) ){ + getStringFromIndexWithDelim( arg, "|", 3, msgbuf,sizeof( msgbuf));//ȼ(ȼſ) + if( CHAR_getInt( toindex, CHAR_LV ) >= atoi(msgbuf) ){ + getStringFromIndexWithDelim( arg, "|", 4, msgbuf,sizeof( msgbuf));//ֵ + if( CHAR_getInt( toindex, CHAR_LV) < CHAR_MAXUPLEVEL ){ + int UpLevel = 0; + CHAR_setWorkInt( toindex, CHAR_WORKGETEXP, atoi(msgbuf) );//شCHAR_WORKGETEXP + CHAR_AddMaxExp( toindex, CHAR_getWorkInt( toindex, CHAR_WORKGETEXP ) ); + sprintf( msgbuf,"ʯͷ治֪ʲĿҿ(Ӿ%d)", CHAR_getWorkInt( toindex, CHAR_WORKGETEXP ) ); + CHAR_talkToCli( charaindex,-1,msgbuf,CHAR_COLORWHITE); + UpLevel = CHAR_LevelUpCheck( toindex , charaindex); + if( UpLevel > 0 ){ + if( getBattleDebugMsg( ) != 0 ){ + snprintf( msgbuf, sizeof(msgbuf), + "(%s) %d", + CHAR_getUseName( toindex ), + CHAR_getInt( toindex, CHAR_LV ) ); + BATTLE_talkToCli( charaindex, msgbuf, CHAR_COLORYELLOW ); + } + } + for( j = 0; j < UpLevel; j ++ ){ + CHAR_PetLevelUp( toindex ); + CHAR_PetAddVariableAi( toindex, AI_FIX_PETLEVELUP ); + } + CHAR_complianceParameter( toindex ); + } + else{ + CHAR_talkToCli( charaindex,-1,"ʹ",CHAR_COLORWHITE); + } + /*CHAR_send_P_StatusString( charindex, CHAR_P_STRING_DUELPOINT| + CHAR_P_STRING_TRANSMIGRATION| CHAR_P_STRING_RIDEPET| + CHAR_P_STRING_BASEBASEIMAGENUMBER| CHAR_P_STRING_GOLD| + CHAR_P_STRING_EXP| CHAR_P_STRING_LV| CHAR_P_STRING_HP|CHAR_P_STRING_LEARNRIDE); + */ + } + else + CHAR_talkToCli( charaindex,-1,"ʯͷ....(޷б޷Ӿ)",CHAR_COLORWHITE); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + return; + } + else{ + CHAR_talkToCli( charaindex,-1,"ʹ",CHAR_COLORWHITE); + } + } +#endif + for( j = 0; j < BD_KIND_END; j ++ ){ + power[j] = 0; + recovery[j] = 0; + } + if( (p = strstr( arg, "ȫ" )) != NULL ){ + HealFlg = ( 1 << BD_KIND_HP ); + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ){ + }else{ + HealFlg |= ( 1 << BD_KIND_MP ); + } + power[BD_KIND_HP] = 10000000; + power[BD_KIND_MP] = 100; + } + kind = BD_KIND_HP; + if( (p = strstr( arg, aszKeyString[kind] )) != NULL ){ + HealFlg |= ( 1 << kind ); + if( sscanf( p+2, "%d", &work ) != 1 ){ + power[kind] = 1; + }else{ + power[kind] = RAND( (work*0.9), (work*1.1) ); + } +#ifndef _MAGIC_REHPAI + power[kind] *= GetRecoveryRate( toindex ); +#endif + } + kind = BD_KIND_MP; + if( (p = strstr( arg, aszKeyString[kind] )) != NULL + && CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + HealFlg |= ( 1 << kind ); + if( sscanf( p+2, "%d", &work ) != 1 ){ + power[kind] = 1; + }else{ + power[kind] = RAND( (work*0.9), (work*1.1) ); + } + } + kind = BD_KIND_AI; + if( (p = strstr( arg, aszKeyString[kind] )) != NULL + && CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPET){ + HealFlg |= ( 1 << kind ); + if( sscanf( p+2, "%d", &work ) != 1 ){ + power[kind] = 1; + }else{ + power[kind] = RAND( (work*0.9), (work*1.1) ); + } + power[kind] *= 100; + } + kind = BD_KIND_CHARM; + if( (p = strstr( arg, aszKeyString[kind] )) != NULL + && CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){ + HealFlg |= ( 1 << kind ); + if( sscanf( p+2, "%d", &work ) != 1 ){ + power[kind] = 1; + }else{ + power[kind] = RAND( (work*0.9), (work*1.1) ); + } + } + if( HealFlg == 0 )return; +#ifdef _TYPE_TOXICATION + if( CHAR_CanCureFlg( toindex, "HP") == FALSE )return; +#endif + + for( j = 0; j < BD_KIND_END; j ++ ){ + if( ( HealFlg & ( 1 << j ) ) == 0 )continue; + prevhp = CHAR_getInt( toindex, aHealInt[j] ); + workhp = prevhp + (int)power[j]; + + if( j == BD_KIND_CHARM ){ + workmax = 100; + workmin = 0; + }else + if( j == BD_KIND_AI ){ + workmax = 10000; + workmin = -10000; + }else{ + workmax = CHAR_getWorkInt( toindex, aHealMaxWork[j] ); + workmin = 1; + } + workhp = min( workhp, workmax ); + workhp = max( workhp, workmin ); + CHAR_setInt( toindex, aHealInt[j], workhp ); + recovery[j] = workhp - prevhp; + if( j == BD_KIND_AI ){ + recovery[j] *= 0.01; + } + } + CHAR_complianceParameter( toindex ); + + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + if( charaindex != toindex ) { + CHAR_send_P_StatusString( toindex, CHAR_P_STRING_HP|CHAR_P_STRING_MP|CHAR_P_STRING_CHARM); + } + } + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_HP|CHAR_P_STRING_MP|CHAR_P_STRING_CHARM); + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ){ + CHAR_PartyUpdate( toindex, CHAR_N_STRING_HP|CHAR_N_STRING_MP ); + } + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ){ + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int workindex = CHAR_getCharPet( charaindex, i ); + if( workindex == toindex ){ + CHAR_send_K_StatusString( charaindex, i, CHAR_K_STRING_HP|CHAR_K_STRING_AI); + } + } + } + + + for( j = 0; j < BD_KIND_END; j ++ ){ + if( ( HealFlg & ( 1 << j ) ) == 0 )continue; + if( charaindex != toindex) { + if( power[j] >= 0 ){ + snprintf( msgbuf, sizeof( msgbuf), + aszHealStringByOwn[j], + CHAR_getUseName( toindex ), recovery[j] ); + }else{ + snprintf( msgbuf, sizeof( msgbuf), + aszDownStringByOwn[j], + CHAR_getUseName( toindex ), -recovery[j] ); + } + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + if( power[j] >= 0 ){ + snprintf( msgbuf, sizeof( msgbuf), + aszHealStringByOther[j], + CHAR_getUseName( charaindex ), + CHAR_getUseName( toindex ), recovery[j] ); + }else{ + snprintf( msgbuf, sizeof( msgbuf), + aszDownStringByOther[j], + CHAR_getUseName( charaindex ), + CHAR_getUseName( toindex ), -recovery[j] ); + } + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORWHITE); + } + }else { + if( power[j] >= 0 ){ + snprintf( msgbuf, sizeof( msgbuf), + aszHealStringByOwn[j], + CHAR_getUseName( charaindex ), recovery[j] ); + }else{ + snprintf( msgbuf, sizeof( msgbuf), + aszDownStringByOwn[j], + CHAR_getUseName( charaindex ), -recovery[j] ); + } + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + } + } + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "FieldUse", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + CHAR_DelItemMess( charaindex, haveitemindex, 0); + +} + +#endif + +void ITEM_useRecovery( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useRecovery_Battle( charaindex, toindex, haveitemindex ); + }else{ + ITEM_useRecovery_Field( charaindex, toindex, haveitemindex ); + } + +} + +#ifdef _ITEM_MAGICRECOVERY +void ITEM_useMRecovery( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useMRecovery_Battle( charaindex, toindex, haveitemindex ); + }else{ +// ITEM_useRecovery_Field( charaindex, toindex, haveitemindex ); + } + +} + +#endif + +#ifdef _ITEM_USEMAGIC +void ITEM_useMagic( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useMagic_Battle( charaindex, toindex, haveitemindex ); + } +} +#endif + +#ifdef _PET_LIMITLEVEL +void ITEM_useOtherEditBase( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,i; + int work[4]; + int num=-1,type; + int LevelUpPoint,petrank; + char buf1[256]; + char buf2[][32]={"ɳ",";ɳ","ٶȳɳ","ɳ",""}; + char buf3[][32]={"","Ϊ","Ϊ"}; + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( toindex ) ) return; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + if( CHAR_getInt( toindex, CHAR_PETID) == 718 +#ifdef _PET_2LIMITLEVEL + || CHAR_getInt( toindex, CHAR_PETID) == 401 +#endif + ) { + + int maxnums=50; + + if( CHAR_getInt( toindex,CHAR_LV ) < 74 ) { + sprintf(buf1,"ҵ𣿺ร˱仯"); + CHAR_talkToCli( charaindex, toindex, buf1, CHAR_COLORWHITE); + num = ITEM_MODIFYATTACK; + LevelUpPoint = CHAR_getInt( toindex, CHAR_ALLOCPOINT ); + petrank = CHAR_getInt( toindex, CHAR_PETRANK ); + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + for( i=0; i<4; i++) { + type = ITEM_getInt( itemindex, (num + i)); + work[i] += type; + strcpy( buf1,"\0"); + if( work[i] > maxnums ) { + sprintf(buf1,"%s Ѿﵽˡ", buf2[i]); + work[i] = maxnums; + }else if( work[i] < 0 ) { + sprintf(buf1,"%s ѾΪˡ", buf2[i]); + work[i] = 0; + }else { + if( type > 0 ) { + if( type > 2 ) + sprintf(buf1,"%s %s %s", buf2[i], buf3[0], ""); + else + sprintf(buf1,"%s %s %s", buf2[i], buf3[1], ""); + }else if( type < 0 ){ + sprintf(buf1,"%s %s %s", buf2[i], buf3[2], ""); + } + } + if( strcmp( buf1, "\0")) { + CHAR_talkToCli( charaindex, toindex, buf1, CHAR_COLORWHITE); + } + } + + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( toindex, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_setInt( toindex, CHAR_PETRANK, petrank); + LogPetPointChange( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( charaindex, CHAR_NAME), + toindex, 4, + CHAR_getInt( toindex, CHAR_LV), + "item_use", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ) + ); + } + + }else { + sprintf(buf1,""); + } + CHAR_DelItem( charaindex, haveitemindex); + return; +} +#endif + +void ITEM_useStatusChange( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; // + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useStatusChange_Battle( charaindex, toindex, haveitemindex ); + }else{ + } + +} + +void ITEM_useStatusRecovery( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; // + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useStatusRecovery_Battle( charaindex, toindex, haveitemindex ); + }else{ + } +} + +void ITEM_useMagicDef( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useMagicDef_Battle( charaindex, toindex, haveitemindex ); + }else{ + } + +} + +void ITEM_useParamChange( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useParamChange_Battle( charaindex, toindex, haveitemindex ); + } +} + +void ITEM_useFieldChange( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useFieldChange_Battle( charaindex, toindex, haveitemindex ); + } +} + +void ITEM_useAttReverse( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useAttReverse_Battle( charaindex, toindex, haveitemindex ); + }else{ + } +} + +void ITEM_useMic( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + }else{ + ITEM_useMic_Field( charaindex, toindex, haveitemindex ); + } + +} + +void ITEM_useCaptureUp( int charaindex, int toindex, int haveitemindex) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return ; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + }else + if( battlemode ){ + ITEM_useCaptureUp_Battle( charaindex, toindex, haveitemindex ); + }else{ + } + +} + +#ifdef _PETSKILL_CANNEDFOOD +static void ITEM_usePetSkillCanned_PrintWindow( int charaindex, int flg) +{ + int fd; + char message[256], buf[2048]; + if( !CHAR_CHECKINDEX( charaindex )) return; + fd = getfdFromCharaIndex( charaindex); + if( fd == - 1 ) return; + + sprintf( message, "%d", flg); + lssproto_WN_send( fd, WINDOWS_MESSAGETYPE_PETSKILLSHOW, + WINDOW_BUTTONTYPE_NONE, + ITEM_WINDOWTYPE_SELECTPETSKILL_SELECT, + -1, + makeEscapeString( message, buf, sizeof( buf))); +} + +void ITEM_usePetSkillCanned_WindowResult( int charaindex, int seqno, int select, char * data) +{ + int itemindex=-1, itemNo, petindex=-1, petNo; + int SkillNo, SkillID; + char buf1[256]; + char *skillarg=NULL; + + petNo = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM); + itemNo = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMINDEX); + + + itemindex = CHAR_getItemIndex( charaindex, itemNo); + if( !ITEM_CHECKINDEX( itemindex) ) return; + petindex = CHAR_getCharPet( charaindex, petNo); + if( !CHAR_CHECKINDEX(petindex) ) return; + SkillNo = atoi( data); + if( SkillNo < 0 || SkillNo >= CHAR_MAXPETSKILLHAVE ) return; + + if(strcmp(ITEM_getChar( itemindex, ITEM_USEFUNC),"ITEM_useSkillCanned")){ + CHAR_talkToCli( charaindex, -1, "ֹǷѧϰ\ܣ", CHAR_COLORRED); + return; + } + + skillarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + +#ifdef _PETSKILL_NEW_PASSIVE + if (strstr(skillarg, "RAND") != NULL) { + SkillID = getRandSkill(); + } else +#endif + { + SkillID = atoi(skillarg); + } + +#ifdef _PETSKILL_SHOP_LUA + if(FreePetSkillShop(charaindex, petindex, CHAR_getPetSkill(petindex, SkillNo), SkillID) == FALSE ) { + return; + } +#endif + +#ifdef _CFREE_petskill + if( NPC_CHECKFREEPETSKILL( charaindex, petindex, SkillID) == FALSE ){ + CHAR_talkToCli( charaindex, -1, "ó޷ѧϰܣ", CHAR_COLORYELLOW); + return; + } +#endif + +#ifdef _PETSKILL_NEW_PASSIVE + if (isPassiveSkill(SkillID) == 1) { + int i, j = 0; + char msg[100]; + for (i = 0; i < CHAR_MAXPETSKILLHAVE; i++) { + if (isPassiveSkill(CHAR_getPetSkill(petindex, i)) == 1) { + j++; + } + } + + if (isPassiveSkill(SkillID) == 1) { + j++; + } + + if (isPassiveSkill(SkillID) == 1 && getSkillPos() == SkillNo) { + j = j - 2; + } + + if (j <= 0 && getSkillCount() == 1 && SkillNo != getSkillPos()) { + sprintf(msg, "ֻѧڵ%dܸ", getSkillPos() + 1); + CHAR_talkToCli(charaindex, -1, msg, CHAR_COLORYELLOW); + return; + } + + if (j >= getSkillCount()) { + sprintf(msg, "ܲɳ%d", getSkillCount()); + CHAR_talkToCli(charaindex, -1, msg, CHAR_COLORYELLOW); + return; + } + } +#endif + + CHAR_setPetSkill( petindex, SkillNo, SkillID); + snprintf( buf1, sizeof( buf1 ), "W%d", petNo); + CHAR_sendStatusString( charaindex, buf1 ); + CHAR_sendStatusString( charaindex, "P"); + { + int skillarray = PETSKILL_getPetskillArray( SkillID); + sprintf( buf1, "%sѧϰ%s %sʧˡ", + CHAR_getUseName( petindex), PETSKILL_getChar( skillarray, PETSKILL_NAME), + ITEM_getChar( itemindex, ITEM_NAME) ); + } + + CHAR_talkToCli( charaindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_setItemIndex( charaindex, itemNo ,-1); + CHAR_sendItemDataOne( charaindex, itemNo); + ITEM_endExistItemsOne( itemindex); +} + +#endif + +static void ITEM_useRenameItem_PrintWindow( int charaindex, int page) +{ + int fd; + int pos = 0; + int i; + int btntype = WINDOW_BUTTONTYPE_CANCEL; + char message[1024]; + char msgwk[1024]; + char buf[2048]; + + if( !CHAR_CHECKINDEX( charaindex )) return; + if( page < 0 || page > 3 ) { + print( "%s:%d err\n", __FILE__, __LINE__); + return; + } + fd = getfdFromCharaIndex( charaindex); + if( fd == - 1 ) return; + + snprintf( message, sizeof( message), + "2\n ҪǸĿ\n" + " Page:%d\n", page +1); + + for( i = page *5; i < page *5 +5; i ++ ) { + int itemindex = CHAR_getItemIndex( charaindex, i); + BOOL flg = FALSE; + while( 1 ) { + char *cdkey; + if( !ITEM_CHECKINDEX( itemindex)) break; + cdkey = ITEM_getChar( itemindex, ITEM_CDKEY); + if( !cdkey) { + print( "%s:%d err\n", __FILE__, __LINE__); + break; + } + if( ITEM_getInt( itemindex, ITEM_MERGEFLG) != 1) break; + if( ITEM_getInt( itemindex, ITEM_TYPE) == ITEM_DISH) break; + if( ITEM_getInt( itemindex, ITEM_CRUSHLEVEL) != 0 ) break; + if( strlen( cdkey) != 0 ) { + if( strcmp( cdkey, CHAR_getChar( charaindex, CHAR_CDKEY)) != 0 ) { + break; + } + } + flg = TRUE; + break; + } + if( flg ) { + char *nm = ITEM_getChar( itemindex, ITEM_SECRETNAME); + char wk[256]; + if( pos +strlen( nm) +1 > sizeof( msgwk)) { + print( "buffer over error %s:%d\n", __FILE__, __LINE__); + break; + } + snprintf( wk, sizeof( wk), "%s\n", nm); + strncpy( &msgwk[pos], wk, sizeof( msgwk) -pos -1); + pos += strlen( wk); + } + else { + if( pos +2 > sizeof( msgwk)) { + print( "buffer over error %s:%d\n", __FILE__, __LINE__); + break; + } + strncpy( &msgwk[pos], "\n", sizeof( msgwk) -pos -1 ); + pos += 1; + } + } + strcat( message, msgwk); + switch( page){ + case 0: + btntype |= WINDOW_BUTTONTYPE_NEXT; + break; + case 3: + btntype |= WINDOW_BUTTONTYPE_PREV; + break; + case 1: + case 2: + btntype |= WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_NEXT; + break; + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + btntype, + CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE1+page, + -1, + makeEscapeString( message, buf, sizeof(buf))); +} + +void ITEM_useRenameItem( int charaindex, int toindex, int haveitemindex) +{ + + ITEM_useRenameItem_PrintWindow( charaindex, 0); + + CHAR_setWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM, -1); + CHAR_setWorkInt( charaindex, CHAR_WORKRENAMEITEMINDEX, haveitemindex); +/* + char buf[256]; + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ) return; + sprintf( buf, "%sѱȡ", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, "ѱȡ", CHAR_COLORRED ); + + { + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + itemindex, + "ħDEL", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + + CHAR_setItemIndex( charaindex, haveitemindex, -1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne( itemindex ); +*/ +} + +void ITEM_useRenameItem_WindowResult( int charaindex, int seqno, int select, char * data) +{ + int page = 0; + int fd; + if( select == WINDOW_BUTTONTYPE_CANCEL) return; + + fd = getfdFromCharaIndex( charaindex); + if( fd == - 1 ) return; + if( seqno != CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME ) { + if( select == WINDOW_BUTTONTYPE_NEXT ) page = 1; + else if( select == WINDOW_BUTTONTYPE_PREV ) page = -1; + if( select == WINDOW_BUTTONTYPE_NEXT || select == WINDOW_BUTTONTYPE_PREV ) { + int winno = seqno - CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE1; + winno += page; + if( winno < 0 ) winno = 0; + if( winno > 3 ) winno = 3; + ITEM_useRenameItem_PrintWindow( charaindex, winno); + }else { + char message[1024]; + char buf[2048]; + char haveitemindex = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM); + int itemindex; + if( haveitemindex == -1 ) { + haveitemindex = (seqno - CHAR_WINDOWTYPE_SELECTRENAMEITEM_PAGE1) * 5 + + ( atoi(data)-1); + CHAR_setWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM, haveitemindex); + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + + snprintf( message, sizeof( message), + "%s Ҫ\n" + "\n" + "ȫ13, 26", + ITEM_getChar( itemindex, ITEM_NAME)); + + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + } + } + else { + BOOL flg = FALSE; + char message[1024]; + char buf[2048]; + while( 1 ) { + char *p; + if( strlen( data) > 26 || strlen( data) < 1) { + if( strlen( data) > 26 ) { + strcpy( message, ""); + }else { + strcpy( message, "һ"); + } + break; + } + + // WON ADD ħʸ + flg = TRUE; + + for( p = data; *p ; p ++) { + if( *p == ' '){ + strcpy( message, "ɿհ"); + flg = FALSE; + break; + } + if( strncmp( p, "",2) == 0 ) { + strcpy( message, "ɿհ"); + flg = FALSE; + break; + } + if( *p == '|'){ + strcpy( message, ""); + flg = FALSE; + break; + } + } + + break; + } + + + if( !flg ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_SELECTRENAMEITEM_RENAME_ATTENTION, + -1, + makeEscapeString( message, buf, sizeof(buf))); + } + else { + char haveitemindex = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM); + int itemindex; + int renameitemindex; + int renameitemhaveindex; + int remain; + char msgbuf[128]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex)) { + print( "%s %d err\n", __FILE__, __LINE__); + return; + } + ITEM_setChar( itemindex, ITEM_SECRETNAME, data); +#ifndef _PET_AND_ITEM_UP + ITEM_setChar( itemindex, ITEM_CDKEY, + CHAR_getChar( charaindex, CHAR_CDKEY)); +#endif + CHAR_sendItemDataOne( charaindex, haveitemindex); + snprintf( msgbuf, sizeof(msgbuf)," %s %s ", + ITEM_getChar( itemindex, ITEM_NAME), data); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + renameitemhaveindex = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMINDEX); + renameitemindex = CHAR_getItemIndex( charaindex, renameitemhaveindex); + if( !ITEM_CHECKINDEX( renameitemindex)) { + print( "%s %d err\n", __FILE__, __LINE__); + return; + } + remain = atoi( ITEM_getChar( renameitemindex, ITEM_ARGUMENT)); + if( remain != 0 ) { + remain --; + if( remain <= 0 ) { + snprintf( msgbuf, sizeof(msgbuf),"%s ʧ", + ITEM_getChar( renameitemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_setItemIndex( charaindex, renameitemhaveindex, -1); + CHAR_sendItemDataOne( charaindex, renameitemhaveindex); + ITEM_endExistItemsOne( renameitemindex ); + }else { + char buf[32]; + snprintf( buf, sizeof( buf),"%d", remain); + ITEM_setChar( renameitemindex, ITEM_ARGUMENT, buf); + } + } + } + } +} + +//------------------------------------------------------------------------- +// гǷë ѣ +// ݱݷ¼ĸة ë̫ įë £ +//------------------------------------------------------------------------- +void ITEM_dropDice( int charaindex, int itemindex) +{ + char *dicename[] = { "һ", "", "", "", "", ""}; + int diceimagenumber[] = { 24298,24299,24300,24301,24302,24303}; + int r = RAND( 0,5); + + // įë + ITEM_setInt( itemindex, ITEM_VAR1, ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER)); + // įޥ + ITEM_setInt( itemindex, ITEM_BASEIMAGENUMBER, diceimagenumber[r]); + // ޥ + ITEM_setChar( itemindex, ITEM_SECRETNAME, dicename[r]); + + // ͷʧ߼˪ƥ浤ƥݳƥ֧ئУ +} +//------------------------------------------------------------------------- +// гǷë ѣ +// ݱ įë ʣ +//------------------------------------------------------------------------- +void ITEM_pickupDice( int charaindex, int itemindex) +{ + // įë ʣ + ITEM_setInt( itemindex, ITEM_BASEIMAGENUMBER, ITEM_getInt( itemindex, ITEM_VAR1)); + // + ITEM_setChar( itemindex, ITEM_SECRETNAME, ITEM_getChar( itemindex, ITEM_NAME)); +} +enum { + ITEM_LOTTERY_1ST, // 1 + ITEM_LOTTERY_2ND, + ITEM_LOTTERY_3RD, + ITEM_LOTTERY_4TH, + ITEM_LOTTERY_5TH, // 5 + ITEM_LOTTERY_6TH, // 6 + ITEM_LOTTERY_NONE, // ½ľ + ITEM_LOTTERY_NUM, +}; +//------------------------------------------------------------------------- +// Ԫľݼѣ +// ƥٱئ¾ë裻£ +// ƱɧԻ + +#define PRE_6 (10000) +#define PRE_5 (1300 + PRE_6) +#define PRE_4 (600 + PRE_5) +#define PRE_3 (300 + PRE_4) +#define PRE_2 (8 + PRE_3) +#define PRE_1 (1 + PRE_2) + + +//#define PRE_5 (13000) +//#define PRE_4 (2300 + PRE_5) +//#define PRE_3 (540 + PRE_4) +//#define PRE_2 (8 + PRE_3) +//#define PRE_1 (1 + PRE_2) + + +//#define PRE_5 (16000) +//#define PRE_4 (2500 + PRE_5) +//#define PRE_3 (400 + PRE_4) +//#define PRE_2 (10 + PRE_3) +//#define PRE_1 (1 + PRE_2) +//#define PRE_5 (27000) +//#define PRE_4 (4000 + PRE_5) +//#define PRE_3 (400 + PRE_4) +//#define PRE_2 (10 + PRE_3) +//#define PRE_1 (1 + PRE_2) +// +//------------------------------------------------------------------------- +BOOL ITEM_initLottery(ITEM_Item* itm) +{ + int r = RAND( 0, 49999); + int hit = ITEM_LOTTERY_NONE; // + char result[7]; // + int countnum[6]; + int count; + int i; + int len; + // Ȼ¼ƥ۷ 羮Իئƽľئз + if( itm->data[ITEM_VAR3] == 1 ) return TRUE; + + // £ + if( r < PRE_6 ) hit = ITEM_LOTTERY_6TH; + else if( r < PRE_5 ) hit = ITEM_LOTTERY_5TH; + else if( r < PRE_4 ) hit = ITEM_LOTTERY_4TH; + else if( r < PRE_3 ) hit = ITEM_LOTTERY_3RD; + else if( r < PRE_2 ) hit = ITEM_LOTTERY_2ND; + else if( r < PRE_1 ) hit = ITEM_LOTTERY_1ST; + else hit = ITEM_LOTTERY_NONE; + + // ë£ + count = 0; + if( hit != ITEM_LOTTERY_NONE ) { + // Իë + result[0] = result[1] = result[2] = hit+1; + count = 3; + countnum[hit] = 3; + } + while( count < 6 ) { + int r = RAND( ITEM_LOTTERY_1ST, ITEM_LOTTERY_6TH); + if( countnum[r] >= 2 ) continue; + // 2/3м ƥְ½ľ ë֧£ + // + if( ( hit != ITEM_LOTTERY_NONE && count == 3 ) + || ( hit == ITEM_LOTTERY_NONE && count == 0 ) ) + { + if( RAND( 0,2)) { + result[count] = result[count+1] = r+1; + countnum[r] += 2; + count += 2; + continue; + } + } + countnum[r] ++; + result[count] = r+1; + count++; + } + // ë׻£ + // Իݷ2/3 ƥԻٯë Ƿ£ + // ƽƽëѵУ + len = sizeof( result)-2; + if( hit != ITEM_LOTTERY_NONE ) { + if( RAND( 0,2) ) { + // Իٯë Ƿ + char s = result[0]; + result[0] = result[5]; + result[5] = s; + len = sizeof( result)-3; + } + } + for( i = 0; i < 10; i ++) { + int x = RAND( 0, len); + int y = RAND( 0, len); + int s; + s = result[x]; + result[x] = result[y]; + result[y] = s; + } + // ׻ ٯ бƻʣ + result[sizeof(result)-1] = '\0'; + itm->data[ITEM_VAR1] = hit; + // + itm->data[ITEM_VAR2] = 0; + itm->data[ITEM_VAR3] = 1; + memcpy( itm->string[ITEM_ARGUMENT].string, result, sizeof( result)); + + return TRUE; +} +//------------------------------------------------------------------------- +// Ԫëݼѣ +// پʧ ة £ +//------------------------------------------------------------------------- +void ITEM_useLottery( int charaindex, int toindex, int haveitemindex) +{ + int i,j; + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + int count = ITEM_getInt( itemindex, ITEM_VAR2); + int hit = ITEM_getInt( itemindex, ITEM_VAR1); + char buff[1024]; + char num[6][3] = { {"A"},{"B"},{"C"},{"D"},{"E"}, {"F"}}; + char numbuff[128]; + char *n; + int result; + BOOL flg; + if( !ITEM_CHECKINDEX( itemindex) ) return; + if( count == 0 ) { + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, ""); + } + else if( count == 6 ) { + CHAR_setItemIndex( charaindex , haveitemindex, -1 ); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne( itemindex ); + return; + } + n = ITEM_getChar( itemindex, ITEM_ARGUMENT); + result = (int)n[count]-1; + + flg = FALSE; + for( i = 0; i < count+1 && flg == FALSE; i ++ ) { + for( j = i+1; j < count+1 && flg == FALSE; j ++ ) { + if( i != j ) { + if( n[i] == n[j] ) { + flg = TRUE; + } + } + } + } + memcpy( numbuff, ITEM_getChar( itemindex, ITEM_EFFECTSTRING), (count)*2); + snprintf( buff, sizeof( buff), "%s%s", numbuff, num[result]); + count ++; + ITEM_setInt( itemindex, ITEM_VAR2, count); + if( count >= 6 ) { + if( hit != ITEM_LOTTERY_NONE ) { + int newitemindex; + char strbuff[1024]; + char msgbuff[1024]; + CHAR_setItemIndex( charaindex , haveitemindex, -1 ); + ITEM_endExistItemsOne( itemindex ); + newitemindex = ITEM_makeItemAndRegist( 2729 + hit); + CHAR_setItemIndex( charaindex , haveitemindex, newitemindex ); + snprintf( strbuff, sizeof( strbuff), "%s %s", buff, + ITEM_getChar( newitemindex, ITEM_EFFECTSTRING)); + ITEM_setChar( newitemindex, ITEM_EFFECTSTRING, strbuff); + CHAR_sendItemDataOne( charaindex, haveitemindex); + snprintf( msgbuff, sizeof( msgbuff), "˵%d", hit+1 ); + CHAR_talkToCli( charaindex, -1, + msgbuff, + CHAR_COLORYELLOW ); + } + else { +// CHAR_setItemIndex( charaindex , haveitemindex, -1 ); + char strbuff[1024]; + snprintf( strbuff, sizeof( strbuff), "%s û,´", buff); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, strbuff); + CHAR_sendItemDataOne( charaindex, haveitemindex); +// ITEM_endExistItemsOne( itemindex ); +// CHAR_talkToCli( charaindex, -1, +// "ľ", +// CHAR_COLORWHITE ); + } + } + else { + char strbuff[1024]; + if( flg) { + int spc = 16 + ( 6-count)*2; + char space[17]; + space[spc] = '\0'; + snprintf( strbuff, sizeof( strbuff), "%s%s", buff, space); + } + else { + strcpy( strbuff, buff); + } + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, strbuff); + CHAR_sendItemDataOne( charaindex, haveitemindex); + } +} + +void ITEM_WarpDelErrorItem( int charaindex ) +{ + int j; + for(j=0; j= 12 ){ + CHAR_talkToCli(charaindex, -1, "˴޷ʹá", CHAR_COLORYELLOW); + return; + } + sprintf( buf, "%d %d %d %d", flg, Mf, Mx, My); + ITEM_setChar(itemindex, ITEM_ARGUMENT, buf); + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, usenum); + sprintf( buf, "м¼(%s,%d,%d)", MapString[i], Mx, My); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORYELLOW); + CHAR_sendItemDataOne( charaindex, haveitemindex); + } + + // WON ADD + if( ITEM_WarpForAny(charaindex, ff, fx, fy, flg) == FALSE ) + return; +} +#endif + +// Robin 0707 petFollow +void ITEM_petFollow( int charaindex, int toindex, int haveitemindex ) +{ + char *arg; + int itemindex, followLv, haveindex, i; + if( CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW ) != -1 ){ + if( CHAR_CHECKINDEX( CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW ) ) ){ + CHAR_talkToCli( charaindex, -1, "ջطųij", CHAR_COLORWHITE ); + return; + } + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, -1); + } +#ifdef _FIX_METAMORIDE + if( CHAR_CHECKJOINENEMY( charaindex) == TRUE ){ + CHAR_talkToCli( charaindex, -1, "޷ʹã", CHAR_COLORWHITE ); + return; + } +#endif + + if( CHAR_CHECKINDEX( toindex ) == FALSE ) return; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" )return; + + if( sscanf( arg, "%d", &followLv) != 1 ) + return; + if( CHAR_getInt( toindex, CHAR_LV ) > followLv ){ + CHAR_talkToCli( charaindex, -1, "ߵĵȼ㣡", CHAR_COLORWHITE ); + return; + } + haveindex = -1; + for( i = 0; i < 5; i++ ) + { + if( CHAR_getCharPet( charaindex, i) == toindex ) { + haveindex = i; + break; + } + } + if( haveindex == -1) return; + + + if( !PET_dropPetFollow( charaindex, haveindex, -1, -1, -1 ) ) { + CHAR_talkToCli( charaindex, -1, "ʧܣ", CHAR_COLORWHITE ); + return; + } + +} + + + +#ifdef _PETFOLLOW_NEW_ +void ITEM_petFollowNew( int charaindex, int toindex, int haveitemindex ) +{ + char *arg; + int itemindex, followLv, haveindex, i; + int petnum; + petnum=0; + int c=0; + for(;petnum<5;petnum++){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW +petnum) != -1 ){ + if( CHAR_CHECKINDEX( CHAR_getWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum) ) ){ + //CHAR_talkToCli( charaindex, -1, "ջطųij", CHAR_COLORWHITE ); + //return; + c++; + }else + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW+petnum, -1); + } + } + if(c==5){ + CHAR_talkToCli( charaindex, -1, "ջطųij", CHAR_COLORWHITE ); + return; + } + +#ifdef _FIX_METAMORIDE + if( CHAR_CHECKJOINENEMY( charaindex) == TRUE ){ + CHAR_talkToCli( charaindex, -1, "޷ʹã", CHAR_COLORWHITE ); + return; + } +#endif + + if( CHAR_CHECKINDEX( toindex ) == FALSE ) return; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" )return; + + if( sscanf( arg, "%d", &followLv) != 1 ) + return; + if( CHAR_getInt( toindex, CHAR_LV ) > followLv ){ + CHAR_talkToCli( charaindex, -1, "ߵĵȼ㣡", CHAR_COLORWHITE ); + return; + } + haveindex = -1; + for( i = 0; i < 5; i++ ) + { + if( CHAR_getCharPet( charaindex, i) == toindex ) { + haveindex = i; + break; + } + } + if( haveindex == -1) return; + + + if( !PET_dropPetFollow( charaindex, haveindex, -1, -1, -1 ) ) { + CHAR_talkToCli( charaindex, -1, "ʧܣ", CHAR_COLORWHITE ); + return; + } + +} +#endif +// Nuke start 0624: Hero's bless +void ITEM_useSkup( int charaindex, int toindex, int haveitemindex) +{ + int itemindex; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; +#ifdef _SUPER + if(CHAR_getInt(charaindex,CHAR_SUPER)>=1){ + CHAR_talkToCli(charaindex, -1, "ѾǼƷˡٳף", CHAR_COLORYELLOW); + return; + } +#endif + CHAR_setInt(charaindex,CHAR_SKILLUPPOINT, + CHAR_getInt(charaindex,CHAR_SKILLUPPOINT)+1); + CHAR_Skillupsend(charaindex); + CHAR_talkToCli(charaindex, -1, "ܵԼˡ", CHAR_COLORWHITE); + + CHAR_DelItem( charaindex, haveitemindex); +} +// Nuke end +extern void setNoenemy(); +// Nuke start 0626: Dragon's bless +void ITEM_useNoenemy( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,fd; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setNoenemy(fd); + CHAR_talkToCli(charaindex, -1, "ܱܵߵɱʧˡ", CHAR_COLORWHITE); + CHAR_DelItem( charaindex, haveitemindex); + +} +// Nuke end + +// Arminius 7.2: Ra's amulet +void ITEM_equipNoenemy( int charaindex, int itemindex ) +{ + char buf[4096]; + int evadelevel; + int fl,fd; + + if( ITEM_CHECKINDEX(itemindex) == FALSE )return; + + if( ITEM_getArgument( ITEM_getChar(itemindex,ITEM_ARGUMENT),"noen", buf, sizeof(buf) ) + == FALSE ){ + return; + } + evadelevel = atoi(buf); + fl=CHAR_getInt(charaindex, CHAR_FLOOR); + fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + if (evadelevel>=200) { + setEqNoenemy(fd, 200); + CHAR_talkToCli(charaindex, -1, "һĹâ١", CHAR_COLORWHITE); + return; + } else if (evadelevel>=120) { + setEqNoenemy(fd, 120); + + if ( (fl==100)||(fl==200)||(fl==300)||(fl==400)||(fl==500) ){ + CHAR_talkToCli(charaindex, -1, "һĹâ١", CHAR_COLORWHITE); + return; + } + } else if (evadelevel>=80) { + setEqNoenemy(fd, 80); + if ( (fl==100)||(fl==200)||(fl==300)||(fl==400) ){ + + CHAR_talkToCli(charaindex, -1, "һĹâ١", CHAR_COLORWHITE); + return; + } + } else if (evadelevel>=40) { + setEqNoenemy(fd, 40); + if ( (fl==100)||(fl==200) ) { + CHAR_talkToCli(charaindex, -1, "һĹâ١", CHAR_COLORWHITE); + return; + } + } + CHAR_talkToCli(charaindex, -1, "ʲҲûз", CHAR_COLORWHITE); +} + +#ifdef _Item_MoonAct +void ITEM_randEnemyEquipOne( int charaindex, int toindex, int haveitemindex) +{ + int itemindex, RandNum=0; + char buf[256]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex)) return; + + if( ITEM_getArgument( ITEM_getChar( itemindex,ITEM_ARGUMENT), "rand", buf, sizeof(buf) ) == FALSE ){ + return; + } + + if( (RandNum=atoi( buf)) > 0 ){ + int fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setEqRandenemy(fd, RandNum); + CHAR_talkToCli(charaindex, -1, "ʽˡ", CHAR_COLORWHITE); + sprintf( buf, " %sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + return; + } + + +} + +void ITEM_randEnemyEquip( int charaindex, int itemindex) +{ + char buf[4096]; + int RandNum=0; + int fd; + + if( ITEM_CHECKINDEX(itemindex) == FALSE )return; + if( ITEM_getArgument( ITEM_getChar(itemindex,ITEM_ARGUMENT),"rand", buf, sizeof(buf) ) + == FALSE ){ + return; + } + + RandNum=atoi( buf); + fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + if (RandNum > 0 ) { + setEqRandenemy(fd, RandNum); + CHAR_talkToCli(charaindex, -1, "ʽˡ", CHAR_COLORWHITE); + return; + } + +} +void ITEM_RerandEnemyEquip( int charaindex, int itemindex) +{ + int RandNum=0; + int fd; + + if( ITEM_CHECKINDEX(itemindex) == FALSE )return; + + fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + RandNum = getEqRandenemy( fd); + + if (RandNum > 0 ) { + clearEqRandenemy( fd); + CHAR_talkToCli(charaindex, -1, "ʻظ", CHAR_COLORWHITE); + return; + } +} +#endif + +#ifdef _ITEM_WATERWORDSTATUS +void ITEM_WaterWordStatus( int charaindex, int toindex, int haveitemindex) +{ + int itemindex; + char itemarg[256]; + + if( !CHAR_CHECKINDEX( charaindex) ){ + return; + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ){ + return; + } + + if( ITEM_getArgument( ITEM_getChar( itemindex, ITEM_ARGUMENT),"time", itemarg, sizeof(itemarg) ) != FALSE ){ + char token[256]; + int nums = CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER); + if( nums < 0 ) nums = 0; + if( nums > 0 ){ + CHAR_talkToCli( charaindex, -1, "ˮкʱ䲻ۻ", CHAR_COLORYELLOW); + return; + } + CHAR_setWorkInt( charaindex, CHAR_WORKSTATUSWATER, nums+atoi(itemarg)); + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne(itemindex); + + sprintf( token, "ˮкʱ%d֣ܼ%d֡", atoi(itemarg), + CHAR_getWorkInt( charaindex, CHAR_WORKSTATUSWATER)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + }else{ + CHAR_talkToCli(charaindex, -1, "ʲҲû", CHAR_COLORYELLOW); + } +} +#endif + +#ifdef _CHIKULA_STONE +void ITEM_ChikulaStone( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,fd; + char itemarg[256]; + + if( !CHAR_CHECKINDEX( charaindex) ) return; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ) return; + + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + CHAR_setWorkInt( charaindex, CHAR_WORKCHIKULAHP, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKCHIKULAMP, 0 ); + setChiStone( fd, 0); //1hp 2mp + + if( ITEM_getArgument( ITEM_getChar( itemindex, ITEM_ARGUMENT),"hp", itemarg, sizeof(itemarg) ) != FALSE ){ + setChiStone( fd, 1); + CHAR_setWorkInt( charaindex, CHAR_WORKCHIKULAHP, atoi( itemarg) ); + }else if( ITEM_getArgument( ITEM_getChar( itemindex, ITEM_ARGUMENT),"mp", itemarg, sizeof(itemarg) ) != FALSE ){ + setChiStone( fd, 2); + CHAR_setWorkInt( charaindex, CHAR_WORKCHIKULAMP, atoi( itemarg) ); + }else{ + } + + CHAR_talkToCli(charaindex, -1, "ף", CHAR_COLORWHITE); + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne(itemindex); +} +#endif + +#ifdef _ITEM_ORNAMENTS +void ITEM_PutOrnaments( int charaindex, int itemindex) +{ + char *arg=NULL; + char itemname[256]; + int bbnums=0; + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( !ITEM_CHECKINDEX( itemindex) ) return; + arg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( arg == "\0" ) return;//ITEM_BASEIMAGENUMBER + bbnums = atoi( arg); + ITEM_setInt( itemindex, ITEM_BASEIMAGENUMBER, bbnums); + ITEM_setWorkInt( itemindex, ITEM_CANPICKUP, 1); + + sprintf( itemname,"%s%s%s",CHAR_getChar( charaindex, CHAR_NAME), "", ITEM_getChar( itemindex, ITEM_SECRETNAME)); + ITEM_setChar( itemindex, ITEM_SECRETNAME, itemname); +} +#endif + +#ifdef _SUIT_ITEM + +/* +#ifdef _SUIT_TWFWENDUM + #define MAX_SUITTYPE 18 +#else + #ifdef _SUIT_ADDENDUM + #define MAX_SUITTYPE 14 + #else + #ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + #define MAX_SUITTYPE 11 + #else + #define MAX_SUITTYPE 8 + #endif//_MAGIC_RESIST_EQUIT + #endif//_SUIT_ADDENDUM +#endif//_SUIT_TWFWENDUM +*/ +void ITEM_CheckSuitEquip( int charaindex) +{ + int i, j, itemindex, defCode=-1, same=0; + int nItem[CHAR_STARTITEMARRAY]; + int maxitem; + struct tagIntSuit{ + char fun[256]; + int intfun; //CHAR_getInt + }; + struct tagIntSuit ListSuit[]={ + {"VIT",CHAR_WORKSUITVIT}, + {"FSTR",CHAR_WORKSUITMODSTR}, + {"MSTR",CHAR_WORKSUITSTR}, + {"MTGH",CHAR_WORKSUITTGH}, + {"MDEX",CHAR_WORKSUITDEX}, +#ifdef _STATUS_WATERWORD + {"WAST",CHAR_WORKSTATUSWATER}, +#endif + {"HP", CHAR_WORKROUNDHP}, + {"MP", CHAR_WORKROUNDMP} +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ + ,{"FRES", CHAR_WORK_F_SUIT}, + {"IRES", CHAR_WORK_I_SUIT}, + {"TRES", CHAR_WORK_T_SUIT} +#endif +#ifdef _SUIT_ADDENDUM + ,{"RESIST",CHAR_WORKRESIST}, //쳣 + {"COUNTER",CHAR_WORKCOUNTER}, // + {"M_POW",CHAR_WORKMPOWER} //ǿʦħ +#endif +#ifdef _SUIT_TWFWENDUM + ,{"EARTH",CHAR_WORK_EA}, // + {"WRITER",CHAR_WORK_WR}, //ˮ + {"FIRE",CHAR_WORK_FI}, // + {"WIND",CHAR_WORK_WI} // +#endif +#ifdef _SUIT_ADDPART3 + ,{"WDUCKPOWER",CHAR_WORKDUCKPOWER},//װر + {"RENOCASE",CHAR_WORKRENOCAST}, //Ĭ + {"SUITSTRP",CHAR_WORKSUITSTR_P},// λΪ% + {"SUITTGH_P",CHAR_WORKSUITTGH_P},// λΪ% + {"SUITDEXP",CHAR_WORKSUITDEX_P}// λΪ% +#endif +#ifdef _SUIT_ADDPART4 + ,{"SUITPOISON",CHAR_SUITPOISON},//װ + {"M2_POW",CHAR_WORKMPOWER2}, //ǿʦħ,M_POWͬ(30%) + {"UN_POW_M",CHAR_WORKUNMPOWER} //ֿʦħ +#endif + }; + maxitem = sizeof(ListSuit)/sizeof(ListSuit[0]); + CHAR_setWorkInt( charaindex, CHAR_WORKSUITITEM, 0); + for( i=0; i=0; k-- ){ + if( nItem[i] == nItem[k] ) same++; + } + if( same >= 3 && nItem[i] != 0 )defCode = nItem[i]; + } + if( defCode == -1 ) return; + CHAR_setWorkInt( charaindex, CHAR_WORKSUITITEM, defCode); + for( i=0; i=200) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + return; + } else if (el>=120) { + if ( (fl==100)||(fl==200)||(fl==300)||(fl==400)||(fl==500) ) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + return; + } + } else if (el>=80) { + if ( (fl==100)||(fl==200)||(fl==300)||(fl==400) ) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + return; + } + } else if (el>=40) { + if ( (fl==100)||(fl==200) ) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + return; + } + } + CHAR_talkToCli(charaindex, -1, "ʲҲûз", CHAR_COLORWHITE); +} + +extern void setStayEncount(int fd); +void ITEM_useEncounter( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,fd; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); +#ifdef _USER_CHARLOOPS + { + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return; + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "CHAR_BattleStayLoop");//ս + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 2500); + CHAR_constructFunctable( charaindex); + } +#endif + CHAR_talkToCli(charaindex, -1, "ܱܵͻȻɱ", CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} + +#ifdef _Item_DeathAct +void ITEM_UseDeathCounter( int charaindex, int toindex, int haveitemindex) +{ + int itemindex,fd; + int itemmaxuse=-1; + char buf1[256]; + char *itemarg; + char itemnumstr[32]; + int okfloor = 0; + BOOL Useflag=FALSE; + int i = 1; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + +#ifdef _ITEM_STONE + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + while(1){ + if( getStringFromIndexWithDelim( itemarg, "|", i , itemnumstr, sizeof( itemnumstr)) == FALSE ) + break; + okfloor = atoi(itemnumstr); + if( CHAR_getInt( charaindex, CHAR_FLOOR ) == okfloor ){ + Useflag = TRUE; + break; + } + i++; + } + if(okfloor != 0){ // ֵʯͷ + itemmaxuse = ITEM_getInt( itemindex, ITEM_DAMAGEBREAK); + if( itemmaxuse != -1 ) { + itemmaxuse--; + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, itemmaxuse); + if( itemmaxuse < 1 ) { + sprintf( buf1, "%sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli(charaindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + if(Useflag==FALSE) { + CHAR_talkToCli(charaindex, -1, "ûзκ飡", CHAR_COLORYELLOW); + return; + } + }else{ + sprintf( buf1, "ԭУʹôʣ%dΡ", itemmaxuse); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + if(Useflag==FALSE) { + CHAR_talkToCli(charaindex, -1, "ûзκ飡", CHAR_COLORYELLOW); + return; + } + } + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); + CHAR_talkToCli(charaindex, -1, "Ϣ", CHAR_COLORYELLOW); + }else{ + sprintf( buf1, "%sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli(charaindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + if(Useflag==FALSE) { + CHAR_talkToCli(charaindex, -1, "ûзκ飡", CHAR_COLORYELLOW); + return; + } + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); + CHAR_talkToCli(charaindex, -1, "Ϣ", CHAR_COLORYELLOW); + } + }else{ //ħʯ +#endif +#ifdef _ITEM_MAXUSERNUM + itemmaxuse = ITEM_getInt( itemindex, ITEM_DAMAGEBREAK); + if( itemmaxuse != -1 ) { + itemmaxuse--; + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, itemmaxuse); + if( itemmaxuse < 1 ) { + sprintf( buf1, " %sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli(charaindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + }else{ + sprintf( buf1, "ԭУʹôʣ%dΡ", itemmaxuse); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + } + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); + CHAR_talkToCli(charaindex, -1, "ܱܵͻȻɱ", CHAR_COLORYELLOW); + }else{ + CHAR_DelItem( charaindex, haveitemindex); + return; + } +#else + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); + sprintf( buf1, " %sʧˡ", ITEM_getChar( itemindex, ITEM_NAME) ); + CHAR_talkToCli(charaindex, -1, buf1, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +#endif +#ifdef _ITEM_STONE + } +#endif +#ifdef _USER_CHARLOOPS + { + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return; + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "CHAR_BattleStayLoop");//ս + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 2500); + CHAR_constructFunctable( charaindex); + } +#endif +} +#endif + +#ifdef _CHRISTMAS_REDSOCKS +void ITEM_useMaxRedSocks( int charaindex, int toindex, int haveitemindex) +{ + int itemtimes = -1, itemindex; + char *itemarg=NULL; + int present[13]={ 13061, 13062, 13063, 13064, 13088, 13089, 13090, 13091, //1. + 14756, 17256, + 13092,19692,20594}; + int nowtimes = time( NULL); + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "\0" ) { + CHAR_talkToCli(charaindex, -1, "Ч!", CHAR_COLORYELLOW); + return; + } + itemtimes = atoi( itemarg); + if( nowtimes >= itemtimes && nowtimes <= itemtimes+(60*60*24) ){ //ʱڿɻ + int si=0, ret; + char token[256]; + //ɾ + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne(itemindex); + itemindex = -1; + // + si = rand()%100; + if( si > 70 ){ + si = rand()%3+10; + }else if( si > 60 ){ + si = rand()%2+8; + }else { + si = rand()%8; + } + itemindex = ITEM_makeItemAndRegist( present[ si]); + if( !ITEM_CHECKINDEX( itemindex)){ + CHAR_talkToCli(charaindex, -1, "Ч!", CHAR_COLORYELLOW); + return; + } + ret = CHAR_addItemSpecificItemIndex( charaindex, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( itemindex); + CHAR_talkToCli(charaindex, -1, "÷λ!", CHAR_COLORYELLOW); + return; + } + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( charaindex, ret); + }else{ + char token[256]; + if( nowtimes < itemtimes ){ + int days, hours, minute, second; + int defTimes = itemtimes - nowtimes; + + days = defTimes/(24*60*60); + defTimes = defTimes-( days*(24*60*60)); + hours = defTimes/(60*60); + defTimes = defTimes-( hours*(60*60)); + minute = defTimes/60; + defTimes = defTimes-( minute*60); + second = defTimes; + sprintf( token,"%s%d%dСʱ%d%dſʹ!", + ITEM_getChar( itemindex, ITEM_NAME), days, hours, minute, second); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + }else if( nowtimes > itemtimes+(60*60*24) ){ + sprintf( token,"%sʹѹ!", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + } + } +} +#endif + +#ifdef _CHRISTMAS_REDSOCKS_NEW +void ITEM_useMaxRedSocksNew( int charaindex, int toindex, int haveitemindex) +{ + int itemindex; + char *itemarg=NULL; + char itemnumstr[32]; + int itemnum=0; + int present[20]; + int si=0, ret,i; + char token[256]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "\0" ){ + CHAR_talkToCli(charaindex, -1, "Ǹʥ!", CHAR_COLORYELLOW); + return; + } + + // + if( getStringFromIndexWithDelim( itemarg, "|", 1, itemnumstr, sizeof( itemnumstr)) == FALSE ) + return; + itemnum = atoi(itemnumstr); + if( itemnum > 20 ) + itemnum = 20; + for(i=0;i= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( itemindex); + CHAR_talkToCli(charaindex, -1, "÷λ!", CHAR_COLORYELLOW); + return; + } + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( charaindex, ret); + +} +#endif + +#ifdef _PETSKILL_CANNEDFOOD +void ITEM_useSkillCanned( int charaindex, int toindex, int itemNo) +{ + int itemindex; + char buf1[256]; + itemindex = CHAR_getItemIndex( charaindex, itemNo); + if(!ITEM_CHECKINDEX( itemindex)) return; + if( !CHAR_CHECKINDEX( toindex) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPET) { + int i, petNo=-1; + for( i=0; i -1 ){// + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return; + } +#endif + + +#ifdef _FIXBUG_ATTACKBOW + { + int armindex = CHAR_getItemIndex( charaindex, CHAR_ARM); + if( ITEM_CHECKINDEX( armindex) == TRUE ) { + int armtype = BATTLE_GetWepon( charaindex); + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( charaindex, -1, "ʹԶ޷", CHAR_COLORYELLOW ); + return; + } + } + } +#endif + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return; + } + // + if( IsBATTLING( charaindex ) == TRUE ){ + toindex = BATTLE_No2Index(CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ), toindex ); + + } + + if( CHAR_CHECKINDEX( toindex ) == FALSE ) return; + + haveindex = -1; + for( i = 0; i < 5; i++ ){ + if( CHAR_getCharPet( charaindex, i) == toindex ) { + haveindex = i; + break; + } + } + if( haveindex == -1 && charaindex != toindex ){ + CHAR_talkToCli( charaindex, -1, "޷ֻܱԼij", CHAR_COLORYELLOW ); + return; + } + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" )return; + if( sscanf( arg, "%d", &metamoTime) != 1 ) + return; + + + if( toindex != charaindex ){ + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, NowTime.tv_sec +metamoTime); + sprintf( msg, "%s", CHAR_getChar( toindex, CHAR_NAME) ); + } + else { + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, 0); + sprintf( msg, "Լ"); + } + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW ); + + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( toindex, CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( charaindex); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + + CHAR_DelItem( charaindex, haveitemindex); + +} +#endif +#ifdef _ITEM_CRACKER +void ITEM_Cracker(int charaindex,int toindex,int haveitemindex) +{ + int battlemode; + // ǷЧ + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; //ʧ + battlemode = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE); + // սʹЧ + if(!battlemode) ITEM_useCracker_Effect(charaindex,toindex,haveitemindex); + else CHAR_talkToCli(charaindex,-1,"ʲҲû",CHAR_COLORWHITE); +} +#endif + +void ITEM_AddPRSkillPercent( int charaindex,int toindex,int haveitemindex) +{ +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + int level; + char token[64]; + int MySKPercent=0, itemindex=-1, i; + + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( CHAR_getInt( charaindex, PROFESSION_CLASS ) == 0 ) return; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) )return; + level=atoi(ITEM_getChar(itemindex,ITEM_ARGUMENT)); + + for( i=0; i 10000 ) MySKPercent = 10000; + CHAR_setIntPSkill( charaindex, i, SKILL_LEVEL, MySKPercent); + } + + CHAR_setItemIndex( charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne( itemindex ); + CHAR_sendStatusString( charaindex , "S"); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + sprintf( token, "ְҵ%d", level); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); +#endif +} + +void ITEM_AddPRSkillPoint( int charaindex,int toindex,int haveitemindex) +{ +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + int point; + char token[64]; + int MyPRpoint=0, itemindex=-1; + if( !CHAR_CHECKINDEX( charaindex) ) return; + if( CHAR_getInt( charaindex, PROFESSION_CLASS ) == 0 ) return; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) )return; + point=atoi(ITEM_getChar(itemindex,ITEM_ARGUMENT)); + + MyPRpoint = CHAR_getInt( charaindex, PROFESSION_SKILL_POINT); + CHAR_setInt( charaindex, PROFESSION_SKILL_POINT, MyPRpoint+point ); + + + CHAR_setItemIndex( charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex); + ITEM_endExistItemsOne( itemindex ); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + + CHAR_talkToCli( charaindex, -1, "һְҵܵ", CHAR_COLORYELLOW); + sprintf( token, "%dְҵܵ", point); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); +#endif +} + +#ifdef _ITEM_ADDEXP //vincent +void ITEM_Addexp(int charaindex,int toindex,int haveitemindex) +{ + // ǷЧ + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; //ʧ + if(CHAR_CHECKINDEX(toindex) == FALSE) return; //ʧ + int i; + for( i =0; i < CHAR_MAXPETHAVE; i++){ + if( CHAR_getCharPet( charaindex, i) == toindex ){ + break; + } + } + if(i == CHAR_MAXPETHAVE){ + if(charaindex != toindex){ + CHAR_talkToCli(charaindex,-1,"ֻΪԼԼijʹã",CHAR_COLORYELLOW); + return; + } + } +#if 1 + ITEM_useAddexp_Effect(charaindex,toindex,haveitemindex); +#else + if( !CHAR_getWorkInt(charaindex,CHAR_WORKITEM_ADDEXP)){ + ITEM_useAddexp_Effect(charaindex,toindex,haveitemindex); + }else{ + CHAR_talkToCli(charaindex,-1,"ǰʹ֮ҩЧȻ",CHAR_COLORYELLOW); + } +#endif +} +#endif + +#ifdef _ITEM_REFRESH //vincent 쳣״̬ +void ITEM_Refresh(int charaindex,int toindex,int haveitemindex) +{ + int battlemode,itemindex; +print("\nvincent--ITEM_Refresh"); + // ǷЧ + if(CHAR_CHECKINDEX(charaindex) == FALSE) + { +print("\nvincent--(charaindex) == FALSE"); + return; //ʧ + } + itemindex = CHAR_getItemIndex(charaindex,haveitemindex); + + battlemode = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE); + if(battlemode) + { +print("\nvincent--enter ITEM_useAddexp_Effect"); +print("\nvincent-->charaindex:%d,toindex:%d",charaindex,toindex); + ITEM_useRefresh_Effect(charaindex,toindex,haveitemindex); + } + else CHAR_talkToCli(charaindex,-1,"ʲҲû",CHAR_COLORWHITE); + + /* ƽҷ ջ */ + CHAR_setItemIndex(charaindex, haveitemindex ,-1); + CHAR_sendItemDataOne( charaindex, haveitemindex);/* ʧ ةޥ */ + /* */ + ITEM_endExistItemsOne( itemindex ); +} +#endif +//Terry 2001/12/21 +#ifdef _ITEM_FIRECRACKER +void ITEM_firecracker(int charaindex,int toindex,int haveitemindex) +{ + int battlemode; + + // ǷЧ + if(CHAR_CHECKINDEX(charaindex) == FALSE) return; //ʧ + + battlemode = CHAR_getWorkInt(charaindex,CHAR_WORKBATTLEMODE); + + if( battlemode // Ƿս +#ifdef _PETSKILL_BECOMEPIG + && CHAR_getInt( charaindex, CHAR_BECOMEPIG) == -1 +#endif + ) + ITEM_useFirecracker_Battle(charaindex,toindex,haveitemindex); + else + CHAR_talkToCli(charaindex,-1,"ʲҲû",CHAR_COLORWHITE); +} +#endif +//Terry end + + +void ITEM_WearEquip( int charaindex, int itemindex) +{ + // WON ADD +// if( ITEM_getInt(itemindex,ITEM_ID) == 20130 ){ + CHAR_setWorkInt( charaindex, CHAR_PickAllPet, TRUE); +/// } + return; +} +void ITEM_ReWearEquip( int charaindex, int itemindex) +{ + CHAR_setWorkInt( charaindex, CHAR_PickAllPet, FALSE); + return; +} + + +#ifdef _Item_ReLifeAct +void ITEM_DIErelife( int charaindex, int itemindex, int eqw) +{ + int ReceveEffect=-1; + int toNo; + int battleindex=-1; + int attackNo=-1; + int WORK_HP=1; + char buf[256]; + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) { + print("\n battleindex =%d return", battleindex); + return; + } + + if( CHAR_CHECKINDEX( charaindex) == FALSE ) + return; + if( ITEM_CHECKINDEX( itemindex) == FALSE ) + return; +#ifdef _DUMMYDIE + if( CHAR_getFlg( charaindex, CHAR_ISDUMMYDIE) == FALSE ) +#else + if( CHAR_getFlg( charaindex, CHAR_ISDIE) == FALSE ) +#endif + { + print("\n [ %d, CHAR_ISDIE DUMMY FALSE] return !", charaindex); + return; + } + + if( ITEM_getArgument( ITEM_getChar(itemindex,ITEM_ARGUMENT),"HP", buf, sizeof(buf) ) + == FALSE ){ + WORK_HP = 1; + }else { + if( !strcmp( buf, "FULL") ) { + WORK_HP = CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP ); + }else { + WORK_HP=atoi( buf); + } + } + + ReceveEffect = SPR_fukkatu3; + toNo = BATTLE_Index2No( battleindex, charaindex ); + attackNo = -1; + + BATTLE_MultiReLife( battleindex, attackNo, toNo, WORK_HP, ReceveEffect ); + CHAR_setItemIndex( charaindex, eqw ,-1); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( charaindex, eqw); + return; +} +#endif + +#ifdef _EQUIT_DEFMAGIC +void ITEM_MagicEquitWear( int charaindex, int itemindex) +{ + char buf[256]; + char *itemarg; + char Free[][128]={"EA","WA","FI","WI","QU"}; + int index=0; + int dMagic=0; + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + while( index < arraysizeof( Free) ) { + if( ITEM_getArgument( itemarg, Free[ index], buf, sizeof(buf)) == TRUE ) { + dMagic = atoi( buf); + if( dMagic <= 100 && dMagic >= -100 ) { + int def_magic = CHAR_getWorkInt( charaindex, CHAR_EQUITDEFMAGIC_E+index); + CHAR_setWorkInt( charaindex, CHAR_EQUITDEFMAGIC_E+index, def_magic + dMagic); + } + dMagic = 0; + } + index++; + if( (CHAR_EQUITDEFMAGIC_E+index) > CHAR_EQUITQUIMAGIC ) + break; + } + + return; +} + +void ITEM_MagicEquitReWear( int charaindex, int itemindex){ + char buf[256]; + char *itemarg; + char Free[][128]={"EA","WA","FI","WI","QU"}; + int index=0; + int dMagic=0; + + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + while( index < arraysizeof( Free) ) { + if( ITEM_getArgument( itemarg, Free[ index], buf, sizeof(buf)) == TRUE ) { + dMagic = atoi( buf); + if( dMagic <= 100 && dMagic >= -100 ) { + int def_magic = CHAR_getWorkInt( charaindex, CHAR_EQUITDEFMAGIC_E+index); + CHAR_setWorkInt( charaindex, CHAR_EQUITDEFMAGIC_E+index, def_magic - dMagic); + } + dMagic = 0; + } + index++; + if( (CHAR_EQUITDEFMAGIC_E+index) > CHAR_EQUITQUIMAGIC ) + break; + } + + return; +} +#endif + +#ifdef _EQUIT_RESIST +void ITEM_MagicResist( int charaindex, int itemindex) +{ + char *itemarg,*p=NULL; + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, atoi( p+4 ) ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITTHUNDER, atoi( p+4 ) ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITICE, atoi( p+4 ) ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITWEAKEN, atoi( p+4 ) ); + } + else if( strstr( itemarg, "ħ" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITBARRIER, atoi( p+4 ) ); + } + else if( strstr( itemarg, "Ĭ" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITNOCAST, atoi( p+4 ) ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFALLRIDE, atoi( p+4 ) ); + } + +} + +void ITEM_MagicReResist( int charaindex, int itemindex) +{ + char *itemarg,*p=NULL; + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "ħ" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "Ĭ" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } + else if( strstr( itemarg, "" ) ){ + p = itemarg; + CHAR_setWorkInt( charaindex, CHAR_WORKEQUITFIRE, 0 ); + } +} +#endif + +#ifdef _MAGIC_RESIST_EQUIT // WON ADD ְҵװ +void ITEM_P_MagicEquitWear( int charaindex, int itemindex ) +{ + char buf[256] = {0}; + char *itemarg; + char Free[][128]={"FR","IR","TR"}; + int dMagic=0; + int i; + + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + +// print("\n won test 10.0 ==> itemarg(%s)", itemarg ); + + for( i=0; i<3; i++ ){ + if( ITEM_getArgument( itemarg, Free[ i ], buf, sizeof(buf)) == TRUE ) { + dMagic = atoi( buf); +// print("\n won test 10.1 ==> i(%d) dMagic(%d)", i, dMagic ); + + if( dMagic <= 100 && dMagic >= -100 ){ + int def_magic = CHAR_getWorkInt( charaindex, CHAR_WORK_F_SUIT+i ); + CHAR_setWorkInt( charaindex, CHAR_WORK_F_SUIT+i, def_magic + dMagic); + +// print("\n won test 10.2 ==> i(%d)(%d)", i, CHAR_getWorkInt( charaindex, CHAR_WORK_F_SUIT+i ) ); + } + dMagic = 0; + } + } + + return; +} + + +void ITEM_P_MagicEquitReWear( int charaindex, int itemindex ) +{ + char buf[256] = {0}; + char *itemarg; + char Free[][128]={"FR","IR","TR"}; + int dMagic=0; + int i; + + itemarg = ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + +// print("\n won test 10.0 ==> itemarg(%s)", itemarg ); + + for( i=0; i<3; i++ ){ + if( ITEM_getArgument( itemarg, Free[ i ], buf, sizeof(buf)) == TRUE ) { + dMagic = atoi( buf); +// print("\n won test 10.1 ==> i(%d) dMagic(%d)", i, dMagic ); + + if( dMagic <= 100 && dMagic >= -100 ){ + int def_magic = CHAR_getWorkInt( charaindex, CHAR_WORK_F_SUIT+i ); + CHAR_setWorkInt( charaindex, CHAR_WORK_F_SUIT+i, def_magic - dMagic); + +// print("\n won test 10.2 ==> i(%d)(%d)", i, CHAR_getWorkInt( charaindex, CHAR_WORK_F_SUIT+i ) ); + } + dMagic = 0; + } + } + + return; + +} +#endif + + + +#ifdef _ITEM_WARP_FIX_BI +void recoverbi(int index) +{ + + int eBbi=-1, eArm=-1, eNum=-1, eBi=-1, bi=-1; + + bi = CHAR_getInt( index, CHAR_BASEIMAGENUMBER); + eBbi = CHAR_getInt( index, CHAR_BASEBASEIMAGENUMBER); + eArm = CHAR_getItemIndex( index, CHAR_ARM); + eNum = ITEM_FIST; + if(ITEM_CHECKINDEX(eArm)) + eNum = ITEM_getInt( eArm, ITEM_TYPE); + + eBi = CHAR_getNewImagenumberFromEquip( index,eBbi, eNum); + + if(CHAR_getInt( index, CHAR_RIDEPET)!=-1) // + CHAR_complianceParameter(index); + else // + if((eBi!=-1)&&(eBi!=bi)) + CHAR_setInt( index, CHAR_BASEIMAGENUMBER, eBi); + +} +#endif + +#ifdef _ITEM_TIME_LIMIT +void ITEM_TimeLimit( int charaindex) +{ + int i = 0; + int iid = 0; + long lTime = 0; + char buff[256]; + + if( !CHAR_CHECKINDEX( charaindex) ) return; + for( i=0; i < CheckCharMaxItem(charaindex) ; i++ ){ + int itemindex = CHAR_getItemIndex( charaindex , i ); + if( !ITEM_CHECKINDEX( itemindex ) ) continue; + lTime = ITEM_getWorkInt( itemindex, ITEM_WORKTIMELIMIT); + if( ITEM_getInt( itemindex, ITEM_ID) == 20173 //ȼջ + || ITEM_getInt( itemindex, ITEM_ID) == 20704 ){ + if( lTime > 0 && NowTime.tv_sec > lTime ){ + iid = ITEM_getInt( itemindex, ITEM_ID) + 1; + snprintf( buff, sizeof( buff), "%sЧʧ..", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, buff, CHAR_COLORGREEN); + CHAR_DelItemMess( charaindex, i, 0); + itemindex = ITEM_makeItemAndRegist( iid); + if(itemindex!=-1){ + CHAR_setItemIndex( charaindex, i, itemindex); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charaindex); + CHAR_sendItemDataOne( charaindex, i); + } + } + } + } + +} +#endif + +#ifdef _ITEM_CONSTITUTION +void ITEM_Constitution( int charaindex, int toindex, int haveitemindex) +{ + char buf[256]; + char *itemarg; + char Free[][128]={"VI","ST","TG","DE"}; + int index=0, FixPoint=0, itemindex; + BOOL FIXs=FALSE; + int AllPoint=0; + + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) + return; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + + AllPoint = CHAR_getInt( charaindex, CHAR_VITAL) + +CHAR_getInt( charaindex, CHAR_VITAL+1) + +CHAR_getInt( charaindex, CHAR_VITAL+2) + +CHAR_getInt( charaindex, CHAR_VITAL+3); + + while( index < arraysizeof( Free) ) { + if( ITEM_getArgument( itemarg, Free[ index], buf, sizeof(buf)) == TRUE ) { + FixPoint = atoi( buf); + if( FixPoint <= 100 && FixPoint > 0 ) { + int points = CHAR_getInt( charaindex, CHAR_VITAL+index); + //Change Fix + //if( points < (FixPoint*100) ) break; + if( points < (FixPoint*100) || AllPoint-(FixPoint*100) <= 0 ) + { + CHAR_talkToCli( charaindex, -1, "ƷЧ", CHAR_COLORYELLOW); + return; + } + CHAR_setInt( charaindex, CHAR_VITAL+index, (points-(FixPoint*100))); + CHAR_setInt( charaindex, CHAR_SKILLUPPOINT, CHAR_getInt( charaindex, CHAR_SKILLUPPOINT) + FixPoint); + FIXs = TRUE; + } + FixPoint = 0; + } + index++; + if( (CHAR_VITAL+index) > CHAR_DEX ) + break; + } + CHAR_complianceParameter( charaindex); + CHAR_send_P_StatusString( charaindex, + CHAR_P_STRING_MAXHP|CHAR_P_STRING_HP|CHAR_P_STRING_LV|CHAR_P_STRING_EXP| + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF|CHAR_P_STRING_QUICK| + CHAR_P_STRING_VITAL|CHAR_P_STRING_STR|CHAR_P_STRING_TOUGH|CHAR_P_STRING_DEX); + + CHAR_Skillupsend( charaindex); + if( FIXs == TRUE ) { + sprintf( buf, "%s", "е仯"); + }else { + sprintf( buf, "%s", "ƷЧ"); + } + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _NEW_RIDEPETS +void ITEM_useLearnRideCode( int charaindex, int toindex, int haveitemindex) +{//CHAR_LOWRIDEPETS +#ifdef _RIDEMODE_20 + if(getRideMode()==2 || getRideMode()==4){ + CHAR_talkToCli( charaindex, -1, "Ϊ2.0֤ģʽ޷ʹøƷ", CHAR_COLORYELLOW); + return; + } +#endif + int itemindex, i; + char buf1[256]; + char *itemarg=NULL; + int ridetrans; + typedef struct{ + char arg[32]; + int Code; + }tagNewRideCode; + tagNewRideCode NewRides[]={ + { "RIDE_PET0", RIDE_PET0}, { "RIDE_PET1", RIDE_PET1}, { "RIDE_PET2", RIDE_PET2}, + { "RIDE_PET3", RIDE_PET3}, { "RIDE_PET4", RIDE_PET4}, { "RIDE_PET5", RIDE_PET5}, + { "RIDE_PET6", RIDE_PET6}, { "RIDE_PET7", RIDE_PET7}, { "RIDE_PET8", RIDE_PET8}, + { "RIDE_PET9", RIDE_PET9}, { "RIDE_PET10", RIDE_PET10}, { "RIDE_PET11", RIDE_PET11}, + { "RIDE_PET12", RIDE_PET12}, { "RIDE_PET13", RIDE_PET13}, { "RIDE_PET14", RIDE_PET14}, +#ifdef _RIDE_CF + { "RIDE_PET15", RIDE_PET15}, { "RIDE_PET16", RIDE_PET16}, { "RIDE_PET17", RIDE_PET17}, + { "RIDE_PET18", RIDE_PET18}, { "RIDE_PET19", RIDE_PET19}, { "RIDE_PET20", RIDE_PET20}, + { "RIDE_PET21", RIDE_PET21}, { "RIDE_PET22", RIDE_PET22}, { "RIDE_PET23", RIDE_PET23}, + { "RIDE_PET24", RIDE_PET24}, { "RIDE_PET25", RIDE_PET25}, { "RIDE_PET26", RIDE_PET26}, + { "RIDE_PET27", RIDE_PET27}, { "RIDE_PET28", RIDE_PET28}, { "RIDE_PET29", RIDE_PET29}, + { "RIDE_PET30", RIDE_PET30}, { "RIDE_PET31", RIDE_PET31}, + { "RIDE_PET32", RIDE_PET0 }, { "RIDE_PET33", RIDE_PET1 }, { "RIDE_PET34", RIDE_PET2 }, + { "RIDE_PET35", RIDE_PET3 }, { "RIDE_PET36", RIDE_PET4 }, { "RIDE_PET37", RIDE_PET5 }, + { "RIDE_PET38", RIDE_PET6 }, { "RIDE_PET39", RIDE_PET7 }, { "RIDE_PET40", RIDE_PET8 }, + { "RIDE_PET41", RIDE_PET9 }, { "RIDE_PET42", RIDE_PET10}, { "RIDE_PET43", RIDE_PET11}, + { "RIDE_PET44", RIDE_PET12}, { "RIDE_PET45", RIDE_PET13}, { "RIDE_PET46", RIDE_PET14}, + { "RIDE_PET47", RIDE_PET15}, { "RIDE_PET48", RIDE_PET16}, { "RIDE_PET49", RIDE_PET17}, + { "RIDE_PET50", RIDE_PET18}, { "RIDE_PET51", RIDE_PET19}, { "RIDE_PET52", RIDE_PET20}, + { "RIDE_PET53", RIDE_PET21}, { "RIDE_PET54", RIDE_PET22}, { "RIDE_PET55", RIDE_PET23}, + { "RIDE_PET56", RIDE_PET24}, { "RIDE_PET57", RIDE_PET25}, { "RIDE_PET58", RIDE_PET26}, + { "RIDE_PET59", RIDE_PET27}, { "RIDE_PET60", RIDE_PET28}, { "RIDE_PET61", RIDE_PET29}, + { "RIDE_PET62", RIDE_PET30}, { "RIDE_PET63", RIDE_PET31}, +#ifdef _ADD_RIDE_CF + { "RIDE_PET64", RIDE_PET0 }, { "RIDE_PET65", RIDE_PET1 }, { "RIDE_PET66", RIDE_PET2 }, + { "RIDE_PET67", RIDE_PET3 }, { "RIDE_PET68", RIDE_PET4 }, { "RIDE_PET69", RIDE_PET5 }, + { "RIDE_PET70", RIDE_PET6 }, { "RIDE_PET71", RIDE_PET7 }, { "RIDE_PET72", RIDE_PET8 }, + { "RIDE_PET73", RIDE_PET9 }, { "RIDE_PET74", RIDE_PET10}, { "RIDE_PET75", RIDE_PET11}, + { "RIDE_PET76", RIDE_PET12}, { "RIDE_PET77", RIDE_PET13}, { "RIDE_PET78", RIDE_PET14}, + { "RIDE_PET79", RIDE_PET15}, { "RIDE_PET80", RIDE_PET16}, { "RIDE_PET81", RIDE_PET17}, + { "RIDE_PET82", RIDE_PET18}, { "RIDE_PET83", RIDE_PET19}, { "RIDE_PET84", RIDE_PET20}, + { "RIDE_PET85", RIDE_PET21}, { "RIDE_PET86", RIDE_PET22}, { "RIDE_PET87", RIDE_PET23}, + { "RIDE_PET88", RIDE_PET24}, { "RIDE_PET89", RIDE_PET25}, { "RIDE_PET90", RIDE_PET26}, + { "RIDE_PET91", RIDE_PET27}, { "RIDE_PET92", RIDE_PET28}, { "RIDE_PET93", RIDE_PET29}, + { "RIDE_PET94", RIDE_PET30}, { "RIDE_PET95", RIDE_PET31}, +#endif +#endif + }; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + + if( getStringFromIndexWithDelim(itemarg,"|", 3, buf1, sizeof(buf1)) == FALSE ) + ridetrans=0; + else + ridetrans=atoi(buf1); + if( getStringFromIndexWithDelim(itemarg,"|", 1, buf1, sizeof(buf1)) == FALSE ) + return; + for( i=0; i=1 && + CHAR_getInt( toindex, CHAR_FUSIONRAISE) > 0 ){//ǷΪںϳ + int time_l; + int nowTime; // Robin fix + time_l = CHAR_getInt( toindex, CHAR_FUSIONTIMELIMIT); + nowTime = (int)time(NULL); +#if 1 // ҩ + { + char *arg = NULL; + char deltime[8]; + char msg[1024]; + arg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( arg != "\0" && !strncmp( arg, "", 2) ) { +// sscanf( arg, " %d", &deltime); + getStringFromIndexWithDelim( arg, "|", 2, deltime, sizeof( deltime)); + time_l -= (atoi(deltime)*60); + CHAR_setInt( toindex, CHAR_FUSIONTIMELIMIT, time_l); + CHAR_DelItem( charaindex, haveitemindex); + sprintf( msg, "ӿﵰٶ %s ӡ", deltime); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + if( (time_l + anhour) <= nowTime ) { + int min, sec, deftime; + deftime = nowTime - (time_l + anhour); + min = deftime/60; + sec = deftime%60; + sprintf( msg, "ﵰѾιʳˣιʳʱ%d%d롣", min, sec); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + return; + } + } + } +#endif + if( (time_l + anhour) > nowTime ){ //ڵʱҪ(time_l+anhour)ſ ʳ + char Mess1[256]; + int min, sec, deftime; + //int nowTime = (int)time(NULL); + deftime = (time_l + anhour) - nowTime; + min = deftime/60; + sec = deftime%60; + sprintf( Mess1, "ﵰ%d%dſιʳ", min, sec); + CHAR_talkToCli( charaindex, -1, Mess1, CHAR_COLORYELLOW); + return; + } +//--------------------------------------------- + work[3] = CHAR_getInt( toindex, CHAR_EVOLUTIONBASEVTL); + work[0] = CHAR_getInt( toindex, CHAR_EVOLUTIONBASESTR); + work[1] = CHAR_getInt( toindex, CHAR_EVOLUTIONBASETGH); + work[2] = CHAR_getInt( toindex, CHAR_EVOLUTIONBASEDEX); + PET_showEditBaseMsg( charaindex, toindex, itemindex, work); + CHAR_setInt( toindex, CHAR_EVOLUTIONBASEVTL, work[3]); + CHAR_setInt( toindex, CHAR_EVOLUTIONBASESTR, work[0]); + CHAR_setInt( toindex, CHAR_EVOLUTIONBASETGH, work[1]); + CHAR_setInt( toindex, CHAR_EVOLUTIONBASEDEX, work[2]); +//--------------------------------------------- + LogPetPointChange( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( charaindex, CHAR_NAME), + toindex, 4, + CHAR_getInt( toindex, CHAR_LV), + "item_use", + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ) + ); + + LogPetFeed( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( toindex, CHAR_NAME), + toindex, + CHAR_getInt( toindex, CHAR_LV), + ITEM_getChar( itemindex, CHAR_NAME), // Key + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + CHAR_getChar( toindex, CHAR_UNIQUECODE) ); + +#ifdef _PET_EVOLUTION + { + int raise = CHAR_getInt( toindex, CHAR_FUSIONRAISE); + CHAR_setInt( toindex, CHAR_FUSIONRAISE, --raise); + CHAR_setInt( toindex, CHAR_FUSIONTIMELIMIT, nowTime); + if(CHAR_getInt( toindex, CHAR_FUSIONRAISE) <= 0 ){// + char buf[256], buf1[256]; + int newindex; + sprintf( buf, "%s", CHAR_getUseName( toindex )); + + newindex = EVOLUTION_createPetFromEnemyIndex( charaindex, toindex, 1); + if( !CHAR_CHECKINDEX( newindex) ){ + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + return; + } + sprintf( buf1, "%s", CHAR_getChar( newindex, CHAR_NAME)); + strcat( buf, buf1); + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); +#ifdef _PET_VALIDITY + CHAR_setInt ( newindex, CHAR_PETVALIDITY, time(NULL) + 60 * 24 * 3600); +#endif + LogPetFeed( + CHAR_getChar( charaindex, CHAR_NAME), + CHAR_getChar( charaindex, CHAR_CDKEY), + CHAR_getChar( newindex, CHAR_NAME), + toindex, + CHAR_getInt( newindex, CHAR_LV), + buf, // Key + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + CHAR_getChar( newindex, CHAR_UNIQUECODE) ); + + } + } +#endif + }else { + CHAR_talkToCli( charaindex, -1, "", CHAR_COLORYELLOW); + } + CHAR_DelItem( charaindex, haveitemindex); + return; +} +#endif + +#ifdef _THROWITEM_ITEMS +static int Niceitem = 0; + int golds[3]={ 10000, 20000, 50000}; + int items1[18] = { 13092, 13091, 20439, 20417, 1284, 20172, 18210, 19014, 18360, 18362, 18364, + 18359, 18356, 18357, 18510, 20418, 20419, 1452}; + int items2[11] = { 15842, 16136, 14334, 14034, 14634, 14934, 15534, 14934, 16432, 17057, 19695}; + + int items3[10] = { 16014, 16314, 14515, 14215, 14815, 15115, 15715, 15295, 16552, 17157}; + + int items4[18] = { 14516, 14513, 14216, 14213, 14816, 14813, 15116, 15716, 15415, 17360, 20279, + 20282, 20276, 20270, 20288, 20290, 20291, 20289}; + int items5[5] = { 20280, 20283, 20277, 20271, 20274}; + int items6[5] = { 20284, 20272, 20275, 20281, 20278}; +void ITEM_ThrowItemBox( int charaindex, int toindex, int haveitemindex) +{ + int i, ret, Iindex, ItemID=-1, itemindex; + char token[256]; + + if( !CHAR_CHECKINDEX(charaindex) ) return; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + + if( Niceitem > 10 ) ret = rand()%920; + else ret = rand()%1000; + + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(charaindex) ; i++ ){ + Iindex = CHAR_getItemIndex( charaindex , i ); + if( !ITEM_CHECKINDEX(itemindex) ) continue; + if( itemindex == Iindex ){ + CHAR_DelItem( charaindex, i); + + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "WarpManDelItem", + CHAR_getInt( charaindex, CHAR_FLOOR), CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + break; + } + } + if( i >= CheckCharMaxItem(charaindex) ){ + return; + } + + if( ret <= 774 ){ + int Golds=0; + Golds = golds[ RAND(0,2)]; + CHAR_AddGold( charaindex, Golds); + }else { + if( ret < 924 ){ + ItemID = items1[RAND(0,17)]; + }else if( ret < 964 ){ + ItemID = items2[RAND(0,10)]; + }else if( ret < 984 ){ + ItemID = items3[RAND(0,9)]; + Niceitem++; + }else if( ret < 994 ){ + ItemID = items4[RAND(0,17)]; + Niceitem++; + }else if( ret < 999 ){ + ItemID = items5[RAND(0,4)]; + Niceitem++; + }else { + ItemID = items6[RAND(0,4)]; + Niceitem++; + } + + Iindex = ITEM_makeItemAndRegist( ItemID); + if( !ITEM_CHECKINDEX( Iindex) ){ + return; + } + ret = CHAR_addItemSpecificItemIndex( charaindex, Iindex); + if( ret < 0 || ret >= CheckCharMaxItem(charaindex) ) { + ITEM_endExistItemsOne( Iindex); + return; + } + sprintf( token,"õ%s", ITEM_getChar( Iindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( charaindex, ret); + } +} +#endif + +#ifdef _ITEM_LOVERPARTY +void ITEM_LoverSelectUser( int charaindex, int toindex, int haveitemindex) +{ + int itemindex, i; + int playernum = CHAR_getPlayerMaxNum(); + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( toindex ) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER){ + CHAR_talkToCli( charaindex, -1, "Ʒʹá", CHAR_COLORYELLOW); + return; + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + if( ITEM_getInt( itemindex, ITEM_TYPE) != 16 ){ + ITEM_setInt( itemindex, ITEM_TYPE, 16); + return; + } + if( !strcmp( ITEM_getChar( itemindex, ITEM_FORUSERNAME), "") || + !strcmp( ITEM_getChar( itemindex, ITEM_FORUSERCDKEY), "") ){//Ѱ趨 + if( charaindex == toindex ){ + CHAR_talkToCli( charaindex, -1, "ѡԼʹá", CHAR_COLORYELLOW); + return; + } + ITEM_setChar( itemindex, ITEM_FORUSERNAME, CHAR_getChar( toindex, CHAR_NAME) ); + ITEM_setChar( itemindex, ITEM_FORUSERCDKEY, CHAR_getChar( toindex, CHAR_CDKEY) ); + ITEM_setInt( itemindex, ITEM_TARGET, 0); + { + char token[256]; + sprintf( token, "%s(%s)", + ITEM_getChar( itemindex, ITEM_SECRETNAME), CHAR_getChar( toindex, CHAR_NAME)); + ITEM_setChar( itemindex, ITEM_SECRETNAME, token); + sprintf( token, "Ͷ趨Ϊ%s", CHAR_getChar( toindex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + } + CHAR_sendItemDataOne( charaindex, haveitemindex); + }else{ + char buf1[256]; + //if( CHAR_getInt( charaindex, CHAR_FLOOR) == 117 || CHAR_getInt( charaindex, CHAR_FLOOR) == 887 || + //CHAR_getInt( charaindex, CHAR_FLOOR) == 1042 || CHAR_getInt( charaindex, CHAR_FLOOR) == 2032 || + //CHAR_getInt( charaindex, CHAR_FLOOR) == 3032 || CHAR_getInt( charaindex, CHAR_FLOOR) == 4032 || + //CHAR_getInt( charaindex, CHAR_FLOOR) == 5032 || CHAR_getInt( charaindex, CHAR_FLOOR) == 6032 || + //CHAR_getInt( charaindex, CHAR_FLOOR) == 7032 || CHAR_getInt( charaindex, CHAR_FLOOR) == 8032 || + //CHAR_getInt( charaindex, CHAR_FLOOR) == 9032 ){ + if( checkUnlawWarpFloor( CHAR_getInt( charaindex, CHAR_FLOOR) ) ) { + CHAR_talkToCli( charaindex, -1, "λ޷͡", CHAR_COLORYELLOW ); + return; + } + + for( i=0; i= 10000) continue; + + if( (int)NowTime.tv_sec > (int)( OBJECT_getTime( objindex) + getGolddeletetime() ) ) { + + LogStone( + -1, + "NULL", + "NULL", + amount, + 0, + "Del(ɾʱǮ)", + OBJECT_getFloor( objindex ), + OBJECT_getX( objindex ), + OBJECT_getY( objindex ) + ); + + CHAR_ObjectDelete(objindex); + } + } +} + +void GOLD_DeleteTimeCheckOne( int objindex) +{ + int amount=0; + + if( CHECKOBJECT( objindex ) == FALSE ) return; + if( OBJECT_getType( objindex) != OBJTYPE_GOLD) return; + +// amount = OBJECT_getIndex( objindex); +// if( amount >= 10000) return; + + if( (int)NowTime.tv_sec > (int)( OBJECT_getTime( objindex) + getGolddeletetime() ) ) { + + LogStone( + -1, + "NULL", + "NULL", + amount, + 0, + "Del(ɾʱǮ)", + OBJECT_getFloor( objindex ), + OBJECT_getX( objindex ), + OBJECT_getY( objindex ) + ); + + CHAR_ObjectDelete(objindex); + } + +} + +#endif + +#ifdef _TIME_TICKET +void ITEM_timeticketEx( int charaindex, int toindex, int haveitemindex, int flag); +void ITEM_timeticket( int charaindex, int toindex, int haveitemindex) +{ + ITEM_timeticketEx( charaindex, toindex, haveitemindex, 0); +} + +void ITEM_timeticketEx( int charaindex, int toindex, int haveitemindex, int flag) +{ + int itemindex; + int addtime; + int nowtime = time(NULL); + int tickettime; + int lefttime; + char msg[1024]; + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + + if( check_TimeTicketMap( CHAR_getInt( charaindex, CHAR_FLOOR)) == FALSE + && flag == 0 ) { + CHAR_talkToCli( charaindex, -1, "ص㲻ʹá", CHAR_COLORYELLOW); + return; + } + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + + tickettime = CHAR_getWorkInt( charaindex, CHAR_WORKTICKETTIME); + if( tickettime > nowtime+20 ) { + CHAR_talkToCli( charaindex, -1, "ʱʣ£ڲſʹá", CHAR_COLORYELLOW); + return; + } + // һʹõĻ + if( tickettime == 0 ) { + tickettime = nowtime; + CHAR_setWorkInt( charaindex, CHAR_WORKTICKETTIMESTART, nowtime); + } + // սҳʱʱʹ + //if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE + // && tickettime < nowtime ) { + //tickettime = nowtime; + // sprintf(msg, "ʱ䲻%d롣", nowtime - tickettime ); + // CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + //} + + addtime = atoi( ITEM_getChar( itemindex, ITEM_ARGUMENT)); + tickettime += addtime; + CHAR_setWorkInt( charaindex, CHAR_WORKTICKETTIME, tickettime ); + lefttime = tickettime - nowtime; + if( lefttime > 0 ) + sprintf(msg, "ʱ%d룬ʣ%d%d롣", addtime, lefttime/60, lefttime%60 ); + else + sprintf(msg, "ʱ%d룬%d%d롣", addtime, (-lefttime)/60, (-lefttime)%60 ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif +#ifdef _ITEM_SETLOVER +void ITEM_SetLoverUser( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + int playernum = CHAR_getPlayerMaxNum(); + char token[256], szMsg[128]; + int floor = CHAR_getInt(charaindex,CHAR_FLOOR); + + if( !strcmp( CHAR_getChar( charaindex, CHAR_LOVE), "YES")) + { + CHAR_talkToCli( charaindex, -1, "ػΥģѾŶ~", CHAR_COLORYELLOW); + return; + } + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( toindex ) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) + { + CHAR_talkToCli( charaindex, -1, "ֻܺҽŶ", CHAR_COLORYELLOW); + return; + } + if( CHAR_getInt(charaindex,CHAR_TRANSMIGRATION)<3 ||CHAR_getInt(toindex,CHAR_TRANSMIGRATION)<3) + { + CHAR_talkToCli( charaindex, -1, "Ļ˫3תŶ~", CHAR_COLORYELLOW); + return; + } + if( charaindex == toindex ) + { + CHAR_talkToCli( charaindex, -1, "ѵԼ", CHAR_COLORYELLOW); + return; + } + if ( IsMale(charaindex)==IsMale(toindex)) + { + CHAR_talkToCli( charaindex, -1, "ͬôأ", CHAR_COLORYELLOW); + return; + } + if( !ITEM_CHECKINDEX(itemindex) ) return; + int id = ITEM_getInt( itemindex, ITEM_ID); + itemindex = ITEM_makeItemAndRegist( id ); + + if( strcmp( CHAR_getChar( charaindex, CHAR_LOVE), "YES") && + strcmp( CHAR_getChar( toindex, CHAR_LOVE), "YES"))//ڶж˫ǷѾ + { + if( itemindex != -1 ){ + CHAR_setChar( charaindex, CHAR_LOVERID, CHAR_getChar( toindex, CHAR_CDKEY) ); + CHAR_setChar( charaindex, CHAR_LOVERNAME, CHAR_getChar( toindex, CHAR_NAME) ); + if (strcmp(CHAR_getChar( toindex, CHAR_LOVERID), CHAR_getChar( charaindex, CHAR_CDKEY))==0 && + strcmp(CHAR_getChar( toindex, CHAR_LOVERNAME), CHAR_getChar( charaindex, CHAR_NAME))==0){ + int i; + sprintf( token, "ѾӦ%s", CHAR_getChar( toindex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf( token, "%sѾӦ", CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + CHAR_setChar( toindex, CHAR_LOVE,"YES"); + CHAR_setChar( charaindex, CHAR_LOVE,"YES"); + CHAR_setChar( charaindex, CHAR_LOVERID, CHAR_getChar( toindex, CHAR_CDKEY) ); + CHAR_setChar( charaindex, CHAR_LOVERNAME, CHAR_getChar( toindex, CHAR_NAME) ); + CHAR_setChar( toindex, CHAR_LOVERID, CHAR_getChar( charaindex, CHAR_CDKEY) ); + CHAR_setChar( toindex, CHAR_LOVERNAME, CHAR_getChar( charaindex, CHAR_NAME) ); + sprintf(szMsg,"%d 8 101883",floor); + CHAR_CHAT_DEBUG_effect(charaindex,szMsg); + CHAR_DelItem( charaindex, haveitemindex); + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "ܱǸİ˲Ŷ~", CHAR_COLORYELLOW ); + return; + } + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( i ) ) return; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX(itemindex) ) return; + + if( checkUnlawWarpFloor( CHAR_getInt( charaindex, CHAR_FLOOR) ) ) { + CHAR_talkToCli( charaindex, -1, "ܱǸİңԶط޷͡", CHAR_COLORYELLOW ); + return; + }//UNWARPͼֹʹ + if( checkUnlawWarpFloor( CHAR_getInt( i, CHAR_FLOOR) ) ) { + CHAR_talkToCli( charaindex, -1, "ܱǸİңԶط޷͡", CHAR_COLORYELLOW ); + return; + }//UNWARPͼֹʹ + if(strcmp(CHAR_getChar(i,CHAR_LOVERID),CHAR_getChar(charaindex,CHAR_CDKEY)) == 0 && + strcmp(CHAR_getChar(i,CHAR_LOVERNAME),CHAR_getChar(charaindex,CHAR_NAME)) == 0) + { + CHAR_DischargePartyNoMsg( charaindex);//ɢŶ + int floor, x, y; + char token[256]; + floor = CHAR_getInt( i, CHAR_FLOOR); + x = CHAR_getInt( i, CHAR_X); + y = CHAR_getInt( i, CHAR_Y); + + CHAR_warpToSpecificPoint( charaindex, floor, x, y ); + sprintf( token, "%s:װģˣ", CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW ); + sprintf( token, "Ѵ͵%sߣ", CHAR_getChar( i, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + print("\n%s ͵%s", CHAR_getChar( charaindex, CHAR_NAME),CHAR_getChar(i, CHAR_NAME)); + return; + } + }else + CHAR_talkToCli( charaindex, -1, "ûнŶ~", CHAR_COLORYELLOW ); +} + +void ITEM_LoverUnmarry( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + int i; + char token[256]; + int playernum = CHAR_getPlayerMaxNum(); + //Ƿ + if( !strcmp( CHAR_getChar( charaindex, CHAR_LOVE), "YES")) + { + for(i=0;i=playernum) + { + CHAR_talkToCli( charaindex, -1, "ܱǸİ˲Ŷ~", CHAR_COLORYELLOW ); + return; + } + + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( i ) ) return; + if( !ITEM_CHECKINDEX(itemindex) ) return; + + if(strcmp(ITEM_getChar( itemindex, ITEM_SECRETNAME), "ָͬ")){ + int id = ITEM_getInt( itemindex, ITEM_ID); + itemindex = ITEM_makeItemAndRegist( id ); + + if( itemindex != -1 ){ + + int emptyitemindexinchara = CHAR_findEmptyItemBox( i ); + + if( emptyitemindexinchara < 0 ){ + sprintf( token, "%sƷʧ" , CHAR_getChar( i, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf( token, "%s飬Ʒ" , CHAR_getChar( charaindex, CHAR_NAME)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW);} + else{ + CHAR_setItemIndex( i, emptyitemindexinchara, itemindex); + ITEM_setChar( itemindex, ITEM_NAME, "ָͬ"); + ITEM_setChar( itemindex, ITEM_SECRETNAME, "ָͬ"); + sprintf( token, "%s飬ͬʹøýָ!", CHAR_getChar( charaindex, CHAR_NAME)); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, token); + CHAR_sendItemDataOne( i, emptyitemindexinchara); + ITEM_endExistItemsOne(itemindex); + sprintf( token, " %s鲢 %s 㣡", CHAR_getChar( charaindex, CHAR_NAME),ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW); + sprintf( token, "Ѿ%s", CHAR_getChar( i, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + return;}} + }else{ + CHAR_setChar( i, CHAR_LOVE,""); + CHAR_setChar( i, CHAR_LOVERID,""); + CHAR_setChar( i, CHAR_LOVERNAME,""); + CHAR_setChar( charaindex, CHAR_LOVE,""); + CHAR_setChar( charaindex, CHAR_LOVERID,""); + CHAR_setChar( charaindex, CHAR_LOVERNAME,""); + CHAR_talkToCli( i, -1, "˫ɹ", CHAR_COLORYELLOW); + CHAR_talkToCli( charaindex, -1, "˫ɹ", CHAR_COLORYELLOW);} + CHAR_DelItem( charaindex, haveitemindex); + }else + CHAR_talkToCli( charaindex, -1, "ûнŶ~", CHAR_COLORYELLOW ); +} + + +#endif + +#ifdef _ITEM_METAMO +void ITEM_ColorMetamo( int charaindex, int toindex, int haveitemindex) +{ + if(CHAR_getInt( charaindex , CHAR_RIDEPET) !=1 ){ + CHAR_talkToCli( charaindex, -1, "޷ʹøõ~", CHAR_COLORYELLOW); + } + int MetamoList[13][7]={ + /*{ , , , , , , }, //Ϊ˵*/ + { 100000, 100000, 100005, 100010, 100015, 100700, 100705}, //С + { 100020, 100025, 100030, 100035, 100020, 100710, 100715}, // + { 100040, 100055, 100050, 100045, 100040, 100720, 100725}, //к + { 100060, 100060, 100065, 100070, 100075, 100730, 100735}, // + { 100080, 100095, 100085, 100090, 100080, 100740, 100745}, //Ƥ + { 100100, 100100, 100115, 100110, 100105, 100750, 100755}, // + { 100120, 100135, 100120, 100125, 100130, 100760, 100765}, //С + { 100140, 100145, 100140, 100150, 100155, 100770, 100775}, //Ƥ + { 100160, 100165, 100170, 100160, 100175, 100780, 100785}, //ñ + { 100180, 100190, 100195, 100185, 100180, 100790, 100795}, //̷ + { 100200, 100200, 100210, 100210, 100205, 100800, 100805}, //Ů + { 100220, 100230, 100225, 100220, 100235, 100810, 100815}, // + { 100240, 0 , 0 , 0 , 0 , 100820, 0 }, // + }; + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + int OldMetamoId, NewMetamoId, i; + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + OldMetamoId=CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER); + for(i=0;i<12;i++) + if((OldMetamoId>=MetamoList[i][0] && OldMetamoId=MetamoList[i][5] && OldMetamoId= 100000 && OldMetamoId < 100240 ) + || (OldMetamoId >= 100700 && OldMetamoId < 100820)){ + if( strstr( itemarg, "" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[0][rand()%4+1]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[1][rand()%4+1]; + }else if( strstr( itemarg, "к" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "Ϊк", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[2][rand()%4+1]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[3][rand()%4+1]; + }else if( strstr( itemarg, "Ƥ" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "ΪƤ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[4][rand()%4+1]; + }else if( strstr( itemarg, "ֻ" ) && OldMetamoId >= 100000 && OldMetamoId < 100120){ + CHAR_talkToCli( charaindex, -1, "Ϊֻ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[5][rand()%4+1]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[6][rand()%4+1]; + }else if( strstr( itemarg, "Ƥ" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "ΪƤ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[7][rand()%4+1]; + }else if( strstr( itemarg, "ñ" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "Ϊñ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[8][rand()%4+1]; + }else if( strstr( itemarg, "̷" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "Ϊ̷", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[9][rand()%4+1]; + }else if( strstr( itemarg, "Ů" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "ΪŮ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[10][rand()%4+1]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + NewMetamoId=MetamoList[11][rand()%4+1]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[0][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[0][6]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[1][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[1][6]; + }else if( strstr( itemarg, "к" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "Ϊк", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[2][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[2][6]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[3][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[3][6]; + }else if( strstr( itemarg, "Ƥ" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "ΪƤ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[4][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[4][6]; + }else if( strstr( itemarg, "ֻ" ) && OldMetamoId >= 100700 && OldMetamoId < 100760){ + CHAR_talkToCli( charaindex, -1, "Ϊֻ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[5][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[5][6]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[6][6]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[6][6]; + }else if( strstr( itemarg, "Ƥ" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "ΪƤ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[7][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[7][6]; + }else if( strstr( itemarg, "ñ" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "Ϊñ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[8][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[8][6]; + }else if( strstr( itemarg, "̷" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "Ϊ̷", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[9][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[9][6]; + }else if( strstr( itemarg, "Ů" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "ΪŮ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[10][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[10][6]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100760 && OldMetamoId < 100820){ + CHAR_talkToCli( charaindex, -1, "Ϊ", CHAR_COLORYELLOW); + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[11][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[11][6]; + }else if( strstr( itemarg, "" ) && OldMetamoId >= 100120 && OldMetamoId < 100240){ + do + if( OldMetamoId >= 100000 && OldMetamoId < 100120 ){ + NewMetamoId=MetamoList[rand()%6][rand()%4+1]; + }else if( OldMetamoId >= 100120 && OldMetamoId < 100240 ){ + NewMetamoId=MetamoList[rand()%6+6][rand()%4+1]; + }else if( OldMetamoId >= 100700 && OldMetamoId < 100760 ){ + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[rand()%6][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[rand()%6][6]; + }else if( OldMetamoId >= 100760 && OldMetamoId < 100820 ){ + if( ( OldMetamoId - 100700 ) % 10 == 0 ) + NewMetamoId=MetamoList[rand()%6+6][5]; + else if( ( OldMetamoId - 100700 ) % 10 == 5 ) + NewMetamoId=MetamoList[rand()%6+6][6]; + } + while(NewMetamoId==OldMetamoId); + CHAR_talkToCli( charaindex, -1, "ͳɹ", CHAR_COLORYELLOW); + } + }else{ + CHAR_talkToCli( charaindex, -1, "㲢!", CHAR_COLORYELLOW); + return; + } + if(NewMetamoId==0){ + CHAR_talkToCli( charaindex, -1, "ԱͬûĴ!", CHAR_COLORYELLOW); + return;} + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , NewMetamoId ); + CHAR_setInt( charaindex , CHAR_BASEBASEIMAGENUMBER , NewMetamoId ); + + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_DelItem( charaindex, haveitemindex); +} + +void ITEM_SexMetamo( int charaindex, int toindex, int haveitemindex) +{ + int OldMetamoId, NewMetamoId; + OldMetamoId=CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER); + if(OldMetamoId >=100000 && OldMetamoId <100020){ // + NewMetamoId=OldMetamoId+120; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100020 && OldMetamoId <100040){ // + NewMetamoId=OldMetamoId+160; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ̷!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100040 && OldMetamoId <100060){ //к + NewMetamoId=OldMetamoId+120; + CHAR_talkToCli( charaindex, -1, "ϲԳñ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100060 && OldMetamoId <100080){ // + NewMetamoId=OldMetamoId+160; + CHAR_talkToCli( charaindex, -1, "ϲԳ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100080 && OldMetamoId <100100){ //Ƥ + NewMetamoId=OldMetamoId+60; + CHAR_talkToCli( charaindex, -1, "ϲԳƤ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100100 && OldMetamoId <100120){ //ֻ + NewMetamoId=OldMetamoId+100; + CHAR_talkToCli( charaindex, -1, "ϲԳŮ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100120 && OldMetamoId <100140){ // + NewMetamoId=OldMetamoId-120; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100140 && OldMetamoId <100160){ //Ƥ + NewMetamoId=OldMetamoId-60; + CHAR_talkToCli( charaindex, -1, "ϲԳƤ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100160 && OldMetamoId <100180){ //ñ + NewMetamoId=OldMetamoId-120; + CHAR_talkToCli( charaindex, -1, "ϲԳɱк!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100180 && OldMetamoId <100200){ //̷ + NewMetamoId=OldMetamoId-160; + CHAR_talkToCli( charaindex, -1, "ϲԳ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100200 && OldMetamoId <100220){ //Ů + NewMetamoId=OldMetamoId-100; + CHAR_talkToCli( charaindex, -1, "ϲԳɴֻ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100220 && OldMetamoId <100240){ // + NewMetamoId=OldMetamoId-160; + CHAR_talkToCli( charaindex, -1, "ϲԳɿ!", CHAR_COLORYELLOW); + }else if(OldMetamoId >=100700 && OldMetamoId <100710){ // + NewMetamoId=OldMetamoId+60; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100710 && OldMetamoId <100720){ // + NewMetamoId=OldMetamoId+80; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ̷!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100720 && OldMetamoId <100730){ //к + NewMetamoId=OldMetamoId+60; + CHAR_talkToCli( charaindex, -1, "ϲԳñ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100730 && OldMetamoId <100740){ // + NewMetamoId=OldMetamoId+80; + CHAR_talkToCli( charaindex, -1, "ϲԳ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100740 && OldMetamoId <100750){ //Ƥ + NewMetamoId=OldMetamoId+30; + CHAR_talkToCli( charaindex, -1, "ϲԳƤ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100750 && OldMetamoId <100760){ //ֻ + NewMetamoId=OldMetamoId+50; + CHAR_talkToCli( charaindex, -1, "ϲԳŮ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100760 && OldMetamoId <100770){ // + NewMetamoId=OldMetamoId-60; + CHAR_talkToCli( charaindex, -1, "ϲԳɶ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100770 && OldMetamoId <100780){ //Ƥ + NewMetamoId=OldMetamoId-30; + CHAR_talkToCli( charaindex, -1, "ϲԳƤ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100780 && OldMetamoId <100790){ //ñ + NewMetamoId=OldMetamoId-60; + CHAR_talkToCli( charaindex, -1, "ϲԳɱк!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100790 && OldMetamoId <100800){ //̷ + NewMetamoId=OldMetamoId-80; + CHAR_talkToCli( charaindex, -1, "ϲԳ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100810 && OldMetamoId <100820){ //Ů + NewMetamoId=OldMetamoId-50; + CHAR_talkToCli( charaindex, -1, "ϲԳɴֻ!", CHAR_COLORYELLOW); + }else if(OldMetamoId>=100820 && OldMetamoId <100830){ // + NewMetamoId=OldMetamoId-80; + CHAR_talkToCli( charaindex, -1, "ϲԳɿ!", CHAR_COLORYELLOW); + }else{ + CHAR_talkToCli( charaindex, -1, "㲢ͣ޷!", CHAR_COLORYELLOW); + return;} + if(NewMetamoId==0)return; + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , NewMetamoId ); + CHAR_setInt( charaindex , CHAR_BASEBASEIMAGENUMBER , NewMetamoId ); + + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _GM_ITEM +void ITEM_GMFUNCTION( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + char gmtime[16]; + char gmfunction[16]; + char token[64]; + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + + getStringFromIndexWithDelim(itemarg,"|", 1, gmfunction, sizeof(gmfunction)); + getStringFromIndexWithDelim(itemarg,"|", 2, gmtime, sizeof(gmtime)); + CHAR_setChar( charaindex , CHAR_GMFUNCTION, gmfunction ); + CHAR_setInt( charaindex , CHAR_GMTIME, atoi(gmtime) ); + sprintf( token, "ʹ%sȨ%d!", gmfunction, atoi(gmtime)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf( token, "ʹ鿴[help %s]GM!",CHAR_getChar( charaindex, CHAR_GMFUNCTION)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _VIP_SERVER +void ITEM_AddMemberPoint( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + char token[64]; + int point=CHAR_getInt( charaindex , CHAR_AMPOINT); + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + CHAR_setInt( charaindex , CHAR_AMPOINT, point+atoi(itemarg)); +#ifdef _AMPOINT_LOG + if(atoi(itemarg)>0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + atoi(itemarg), + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(ֵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } +#endif + + sprintf( token, "ûֵ%d,ĿǰӵлֵΪ%d!", atoi(itemarg),point+atoi(itemarg)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); + +} +#endif + + +#ifdef _NEW_NAME //Զƺ +void ITEM_NewName( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + char token[64]; + //char MyNewName=CHAR_getChar( charaindex , CHAR_NEWNAME); + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + CHAR_setChar( charaindex , CHAR_NEWNAME, itemarg); + sprintf( token, "ϲ,ѻá%s³ƺ!", itemarg); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + int i; + int playernum = CHAR_getPlayerMaxNum(); + char NameMsg[256]; + char *MyName = CHAR_getChar( charaindex,CHAR_NAME ); + for( i = 0 ; i < playernum ; i++) + { + sprintf( NameMsg, "ϲ %s á%s۳ƺ!", MyName, itemarg ); + CHAR_talkToCli( i, -1, NameMsg, CHAR_COLORBLUE2); + } + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _VIP_RIDE +void ITEM_VipRide( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + char token[256]; + int viplevel, viptime; + getStringFromIndexWithDelim(itemarg,"|", 1, token, sizeof(token)); + viplevel=atoi(token); + getStringFromIndexWithDelim(itemarg,"|", 2, token, sizeof(token)); + + int myviptime = CHAR_getInt(charaindex, CHAR_VIPTIME); + + if(atoi(token)>0){ + if(myviptime > 0){ + viptime = myviptime + atoi(token) * 24 * 60 * 60; + }else{ + viptime = time(NULL) + atoi(token) * 24 * 60 * 60; + } + CHAR_setInt(charaindex, CHAR_VIPTIME, viptime); + + struct tm tm1; + memcpy(&tm1, localtime((time_t *)&viptime), sizeof(tm1)); + + sprintf( token, "ĻԱЧʹ %d%d%d %d:%d:%d\n", + tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + }else{ + CHAR_setInt(charaindex, CHAR_VIPTIME, -1); + CHAR_talkToCli( charaindex, -1, "ĻԱЧʹΪã", CHAR_COLORYELLOW ); + } +#ifdef _NEW_RIDEPETS + int LRCode = CHAR_getInt( charaindex, CHAR_LOWRIDEPETS); + LRCode = LRCode|RIDE_PET14; + CHAR_setInt( charaindex, CHAR_LOWRIDEPETS, LRCode); + CHAR_sendStatusString( charaindex, "x"); +#endif + CHAR_setInt( charaindex , CHAR_VIPRIDE, viplevel); + int i; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) + { + sprintf( token, "ϲ %s Ϊ %s ʽ %d Ա", CHAR_getChar( charaindex,CHAR_NAME ), getGameservername(), CHAR_getInt( charaindex , CHAR_VIPRIDE)); + CHAR_talkToCli( i, -1, token, CHAR_COLORBLUE2); + } + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _FM_ITEM +void ITEM_AddFame( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + char token[64]; + int fame=CHAR_getInt( charaindex , CHAR_FAME); + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; + CHAR_setInt( charaindex , CHAR_FAME, min(MAX_PERSONALFAME, fame+atoi(itemarg)*100)); + sprintf( token, "%d,Ŀǰ%d!", atoi(itemarg),fame/100+atoi(itemarg)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _LUCK_ITEM +void ITEM_Luck( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + int i; + char *itemarg="\0"; + char token[64]; + char luck[][5]={"","һ","С","м",""}; + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + for(i=0;i<5;i++) + if(strstr( itemarg, luck[i])) + break; + if(i==6)i=0; + CHAR_setInt( charaindex , CHAR_LUCK, i+1); + sprintf( token, "ڵΪ%s", luck[i]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _ITEM_METAMO_TIME +void ITEM_MetamoTime( int charaindex, int toindex, int haveitemindex ) +{ + char *itemarg="\0", msg[128], buff[32]; + int itemindex, metamoTime=0, battlemode, metamoNo=0; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return; + //print(" PetMetamo_toindex:%d ", toindex); + + if( CHAR_getInt( charaindex, CHAR_RIDEPET ) != -1 ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return; + } +#ifdef _FIX_METAMORIDE + if( CHAR_CHECKJOINENEMY( charaindex) == TRUE ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return; + } +#else + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER) == 100259 ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return; + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 ){// + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return; + } +#endif + +#ifdef _FIXBUG_ATTACKBOW + { + int armindex = CHAR_getItemIndex( charaindex, CHAR_ARM); + if( ITEM_CHECKINDEX( armindex) == TRUE ) { + int armtype = BATTLE_GetWepon( charaindex); + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( charaindex, -1, "ʹԶ޷", CHAR_COLORYELLOW ); + return; + } + } + } +#endif + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return; + } + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + itemarg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( itemarg == "\0" )return; + if( getStringFromIndexWithDelim(itemarg,"|", 1, buff, sizeof(buff)) ) + metamoNo=atoi(buff); + if( getStringFromIndexWithDelim(itemarg,"|", 2, buff, sizeof(buff)) ) + metamoTime=atoi(buff); + getStringFromIndexWithDelim(itemarg,"|", 3, buff, sizeof(buff)); + + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, NowTime.tv_sec + metamoTime); + if(metamoTime>60) + sprintf( msg, "%sɳ%dСʱ", buff, metamoTime / 60 ); + else + sprintf( msg, "%sɳ%dӣ", buff, metamoTime ); + + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW ); + + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, metamoNo ); + CHAR_complianceParameter( charaindex); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); +} +#endif + +#ifdef _ITEM_GOLD +void ITEM_Gold( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char itemarg[10]; + char token[64]; + int gold=CHAR_getInt( charaindex , CHAR_GOLD); + strcpy(itemarg,ITEM_getChar(itemindex,ITEM_ARGUMENT)); + gold+=atoi(itemarg); + if(gold>CHAR_getMaxHaveGold(charaindex)) + gold=CHAR_getMaxHaveGold(charaindex); + CHAR_setInt( charaindex , CHAR_GOLD, gold); + CHAR_complianceParameter( charaindex); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + sprintf( token, "ʯ%dS", atoi(itemarg)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _MYSTERIOUS_GIFT +void ITEM_MysteriousGift( int charaindex, int toindex, int haveitemindex) +{ + int itemindex; + char *itemarg=NULL; + char petnumstr[32]; + int petnum=0; + int present[20]={0}; + int si=0, ret,i; + char token[256]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "" ){ + CHAR_talkToCli(charaindex, -1, "Ǹ!", CHAR_COLORYELLOW); + return; + } + + if( getStringFromIndexWithDelim( itemarg, "|", 1, petnumstr, sizeof( petnumstr)) == FALSE ) + return; + petnum = atoi(petnumstr); + if( petnum > 20 ) + petnum = 20; + for(i=0;i0 && CHAR_getInt(toindex, CHAR_LIMITLEVEL)=atoi(hight) && CHAR_getInt(toindex, CHAR_LIMITLEVEL)>=atoi(hight)){ + CHAR_talkToCli( charaindex, -1, "ĿǰijﲻʹøƷ", CHAR_COLORYELLOW); + return; + } + CHAR_setInt(toindex, CHAR_LIMITLEVEL, atoi(hight)); + if(CHAR_getInt( toindex, CHAR_EXP)<0){ + int nextexp = CHAR_GetLevelExp( toindex, CHAR_getInt(toindex, CHAR_LV)); + CHAR_setInt( charaindex, CHAR_EXP , nextexp ); + } + + char token[256]; + sprintf(token, "%sȼͻ%d",CHAR_getChar( toindex, CHAR_NAME), atoi(hight)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _ITEM_EFMETAMO +void ITEM_efMetamo( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "" ){ + CHAR_talkToCli(charaindex, -1, "Ǹñָ!", CHAR_COLORYELLOW); + return; + } + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , atoi(itemarg) ); + CHAR_setInt( charaindex , CHAR_BASEBASEIMAGENUMBER , atoi(itemarg)); + + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _PET_BEATITUDE +void PET_BEATITUDE( int charaindex, int toindex, int haveitemindex) +{ + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( toindex ) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) + { + CHAR_talkToCli( charaindex, -1, "Ʒֻܸʹã", CHAR_COLORYELLOW); + return; + } + if( CHAR_getInt( toindex, CHAR_PETID) == 718 || CHAR_getInt( toindex, CHAR_PETID) == 401 ) + { + CHAR_talkToCli( charaindex, -1, "ƷܸMMʹã", CHAR_COLORYELLOW); + return; + } + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + char beatitude[12],mun[12]; + getStringFromIndexWithDelim( itemarg, "|", 1, beatitude, sizeof(beatitude)); + getStringFromIndexWithDelim( itemarg, "|", 2, mun, sizeof(mun)); + char token[256]; + int beat=CHAR_getInt( toindex, CHAR_BEATITUDE); + if(strcmp( beatitude, "")==0){ + if(CHAR_getInt( toindex, CHAR_BEATITUDE)&BEATITUDE_VITAL){ + CHAR_talkToCli( charaindex, -1, "ijˣ", CHAR_COLORYELLOW); + return; + }else{ + sprintf(token, "%s%d", CHAR_getChar( toindex, CHAR_NAME),atoi(mun)); + CHAR_setInt( toindex, CHAR_VITAL,(CHAR_getInt( toindex, CHAR_VITAL)+atoi(mun))); + beat|=BEATITUDE_VITAL; + } + }else if(strcmp( beatitude, "")==0){ + if(CHAR_getInt( toindex, CHAR_BEATITUDE)&BEATITUDE_STR){ + CHAR_talkToCli( charaindex, -1, "ijˣ", CHAR_COLORYELLOW); + return; + }else{ + sprintf(token, "%s%d", CHAR_getChar( toindex, CHAR_NAME),atoi(mun)); + CHAR_setInt( toindex, CHAR_STR, (CHAR_getInt( toindex, CHAR_STR)+atoi(mun))); + beat|=BEATITUDE_STR; + } + }else if(strcmp( beatitude, "")==0){ + if(CHAR_getInt( toindex, CHAR_BEATITUDE)&BEATITUDE_TOUGH){ + CHAR_talkToCli( charaindex, -1, "ijˣ", CHAR_COLORYELLOW); + return; + }else{ + sprintf(token, "%s%d", CHAR_getChar( toindex, CHAR_NAME),atoi(mun)); + CHAR_setInt( toindex, CHAR_TOUGH, (CHAR_getInt( toindex, CHAR_TOUGH)+atoi(mun))); + beat|=BEATITUDE_TOUGH; + } + }else if(strcmp( beatitude, "")==0){ + if(CHAR_getInt( toindex, CHAR_BEATITUDE)&BEATITUDE_DEX){ + CHAR_talkToCli( charaindex, -1, "ijˣ", CHAR_COLORYELLOW); + return; + }else{ + sprintf(token, "%s%d", CHAR_getChar( toindex, CHAR_NAME),atoi(mun)); + CHAR_setInt( toindex, CHAR_DEX, (CHAR_getInt( toindex, CHAR_DEX)+atoi(mun))); + beat|=BEATITUDE_DEX; + } + }else{ + sprintf(token, "%sǰΪ:%d,:%d,:%d,:%d", CHAR_getChar( toindex, CHAR_NAME), + CHAR_getInt( toindex, CHAR_VITAL), + CHAR_getInt( toindex, CHAR_STR), + CHAR_getInt( toindex, CHAR_TOUGH), + CHAR_getInt( toindex, CHAR_DEX)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + CHAR_talkToCli( charaindex, -1, "ˣⶫ̫ˣѳˣ", CHAR_COLORYELLOW); + CHAR_setInt( toindex, CHAR_BEATITUDE,beat); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( charaindex, i ) == toindex )break; + } + if( i == CHAR_MAXPETHAVE )return; + CHAR_complianceParameter( toindex ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( charaindex, token ); + + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _GET_MULTI_ITEM +void ITEM_GetMultiItem( int charaindex, int toindex, int haveitemindex) +{ + int itemindex; + char *itemarg=NULL; + char buf[32]; + int itemnum=0; + int itemid={-1}; + char itemname[512]=""; + int i; + char token[256]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + if( itemarg == "" ){ + CHAR_talkToCli(charaindex, -1, "Ǹպ!", CHAR_COLORYELLOW); + return; + } + + if( getStringFromIndexWithDelim( itemarg, "|", 1, buf, sizeof( buf)) == FALSE ){ + CHAR_talkToCli(charaindex, -1, "!", CHAR_COLORYELLOW); + return; + } + itemnum = atoi(buf); + if( itemnum > 10 ){ + itemnum = 10; + }else if( itemnum < 0 ){ + CHAR_talkToCli(charaindex, -1, "Ǹպ!", CHAR_COLORYELLOW); + return; + } + if( (itemnum - 1) <= CHAR_findSurplusItemBox( charaindex )){ + CHAR_DelItem( charaindex, haveitemindex); + }else{ + sprintf( token, "%dƷƷλ㡣", itemnum); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + + for(i=0;i0){ + +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( charaindex, -1, "δ!", CHAR_COLORRED ); + return; + }else{ + saacproto_OldToNew_send(osfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), CHAR_getInt(charaindex, CHAR_AMPOINT)); + } +#else + saacproto_OldToNew_send(acfd, getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), CHAR_getInt(charaindex, CHAR_AMPOINT)); +#endif + CHAR_talkToCli( charaindex, -1, "תԺ", CHAR_COLORYELLOW ); +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + "(ת)", + CHAR_getInt(charaindex, CHAR_AMPOINT), + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + CHAR_setInt(charaindex, CHAR_AMPOINT, 0); + + }else{ + CHAR_talkToCli( charaindex, -1, "϶ûֵ㣬ת", CHAR_COLORYELLOW ); + } + + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _BOUND_TIME +void ITEM_BoundTime( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + + int myboundtime = CHAR_getInt(charaindex, CHAR_BOUNDTIME); + + int boundtime=0; + char token[256]; + + if(myboundtime > 0 && myboundtime > time(NULL)){ + boundtime = myboundtime + atoi(itemarg) * 24 * 60 * 60; + }else{ + boundtime = time(NULL) + atoi(itemarg) * 24 * 60 * 60; + } + + CHAR_setInt(charaindex, CHAR_BOUNDTIME, boundtime); + + struct tm tm1; + memcpy(&tm1, localtime((time_t *)&boundtime), sizeof(tm1)); + + sprintf( token, "ȨЧʹ %d%d%d %d:%d:%d\n", + tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _TALK_SIZE_ITEM +void ITEM_TalkSize( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + char token[256]; + + CHAR_setWorkInt( charaindex, CHAR_WORKFONTSIZE, atoi( itemarg )); + sprintf( token, "ֺΪ%d", atoi(itemarg)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _FORMULATE_AUTO_PK +void ITEM_PointToSQLPkPoint( int charaindex, int toindex, int haveitemindex) +{ + if(CHAR_getInt(charaindex, CHAR_AMPOINT)>0){ + CHAR_talkToCli( charaindex, -1, "תԺ", CHAR_COLORYELLOW ); + saacproto_FormulateAutoPk_send(getfdFromCharaIndex( charaindex), CHAR_getChar(charaindex, CHAR_CDKEY), CHAR_getInt(charaindex, CHAR_AMPOINT)); +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + "(ת)", + CHAR_getInt(charaindex, CHAR_AMPOINT), + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + + CHAR_setInt(charaindex, CHAR_AMPOINT, 0); + }else{ + CHAR_talkToCli( charaindex, -1, "϶ûֵ㣬ת", CHAR_COLORYELLOW ); + } + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _SUPER_MAN_ITEM +void ITEM_SuperManItem( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + + char *itemarg = ITEM_getChar( itemindex, ITEM_ARGUMENT); + char token[256]; + float table[]={437,490,521,550,578,620,700}; //תߵ(10) + int trans, lv, point; + + getStringFromIndexWithDelim( itemarg, "|", 1, token, sizeof( token)); + trans = atoi(token); + getStringFromIndexWithDelim( itemarg, "|", 2, token, sizeof( token)); + lv = atoi(token); + getStringFromIndexWithDelim( itemarg, "|", 3, token, sizeof( token)); + point = atoi(token); + + int quest=(0xFFFF0000 >> 16)& 0xFF; + + float jxds = point - (getTransPoint(trans)+(lv-1)*getSkup()+table[trans-1]/12.0+quest/4.0+getTransPoint(trans)+ trans*10); + + int teq = jxds * 4.0 + trans * 85; + + CHAR_setInt(charaindex,CHAR_TRANSEQUATION, teq|0xFFFF0000); + + CHAR_setInt(charaindex,CHAR_TRANSMIGRATION, trans); + CHAR_setInt(charaindex,CHAR_LV, lv); + CHAR_setInt(charaindex, CHAR_VITAL,1000); + CHAR_setInt(charaindex, CHAR_STR,0); + CHAR_setInt(charaindex, CHAR_TOUGH,0); + CHAR_setInt(charaindex, CHAR_DEX,0); + CHAR_setInt(charaindex, CHAR_SKILLUPPOINT, point-10); +#ifdef _SUPER + CHAR_setInt(charaindex, CHAR_SUPER, 1); +#endif + CHAR_Skillupsend( charaindex); + CHAR_complianceParameter( charaindex ); + CHAR_sendStatusString( charaindex , "P"); + + sprintf(token, "ϲ㣡µļƷ˵~㽫%dţˣ", point); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _COST_ITEM +void ITEM_CostItem( int charaindex, int toindex, int haveitemindex) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *itemarg="\0"; + char token[64]; + itemarg=ITEM_getChar(itemindex,ITEM_ARGUMENT); + if( itemarg == "\0" ) return; +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + "(ҵ)", + atoi(itemarg), + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( charaindex, -1, "δ!", CHAR_COLORRED ); + return; + }else{ + saacproto_CostItem_send(osfd, getfdFromCharaIndex( charaindex), CHAR_getChar( charaindex , CHAR_CDKEY), atoi(itemarg)); + } +#else + saacproto_CostItem_send(acfd, getfdFromCharaIndex( charaindex), CHAR_getChar( charaindex , CHAR_CDKEY), atoi(itemarg)); +#endif + sprintf( token, "ػر%dȡǰػر...", atoi(itemarg)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _ITEM_EXP +void ITEM_EXP( int charaindex, int toindex, int haveitemindex) +{ + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( !CHAR_CHECKINDEX( toindex ) ) return; + char token[256]; + + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) return; + char *exp = ITEM_getChar( itemindex, ITEM_ARGUMENT); + + CHAR_setMaxExp( toindex, CHAR_getInt( toindex, CHAR_EXP) + atoi(exp)); + + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + CHAR_sendStatusString( toindex, "P" ); + }else{ + int i; + for(i=0;i0){ + CHAR_setInt( charaindex , CHAR_AMPOINT, CHAR_getInt( charaindex , CHAR_AMPOINT)+atoi(itemarg)); + +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + atoi(itemarg), + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(֧Ʊ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + + sprintf( token, "ûֵ%d,ĿǰӵлֵΪ%d!", atoi(itemarg), CHAR_getInt( charaindex , CHAR_AMPOINT)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_DelItem( charaindex, haveitemindex); + }else{ + char buf[256]; + int fd = getfdFromCharaIndex(charaindex); + + CHAR_setWorkInt(charaindex, CHAR_WORKITEMINDEX, itemindex); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_NULL_CHECK, + -1, + makeEscapeString( "ҪдĻ֧Ʊ(ַֹ֣)\n", buf, sizeof(buf))); + } +} +#endif + + +#ifdef _MEMORY_ITEM +void ITEM_WarpItem( int charaindex, int toindex, int haveitemindex ) +{ + char *arg; + int flg=0, ff=0, fx=0, fy=0, itemindex=0, usenum=0; + int Mf, Mx, My; + char buf[256]; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ) return; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if( arg == "\0" ) return; + + if( sscanf( arg, "%d %d %d %d", &flg, &ff, &fx, &fy) != 4 ){ + Mf = CHAR_getInt( charaindex, CHAR_FLOOR ); + Mx = CHAR_getInt( charaindex, CHAR_X ); + My = CHAR_getInt( charaindex, CHAR_Y ); + + + // WON ADD + if( checkUnlawWarpFloor( Mf) ) { + CHAR_talkToCli(charaindex, -1, "˴޷ʹá", CHAR_COLORYELLOW); + return; + } + char escapeshowstring[64]; + char *showstr = MAP_getfloorShowstring(CHAR_getInt(charaindex, CHAR_FLOOR)); + + getStringFromIndexWithDelim( showstr, "|", 1, escapeshowstring, sizeof( escapeshowstring)); + + if( sscanf( arg, "%d %d", &usenum, &flg) != 2 ){ + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, usenum); + }else{ + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, atoi(arg)); + } + sprintf( buf, "%d %d %d %d", flg, Mf, Mx, My); + ITEM_setChar(itemindex, ITEM_ARGUMENT, buf); + + sprintf( buf, "¼λ(%s,%d,%d)", escapeshowstring, Mx, My); + ITEM_setChar( itemindex, ITEM_EFFECTSTRING, buf); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORYELLOW); + CHAR_sendItemDataOne( charaindex, haveitemindex); + }else{ + usenum = ITEM_getInt( itemindex, ITEM_DAMAGEBREAK); + +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ){ + CHAR_talkToCli(charaindex, -1, "Я޷ʹá", CHAR_COLORYELLOW); + return; + } +#endif + + if( --usenum <= 0 ) { + CHAR_talkToCli(charaindex, -1, "õѾûʹôˣʧ", CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + }else{ + sprintf( buf, "õʹôʣ%d", usenum); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORYELLOW); + } + ITEM_setInt( itemindex, ITEM_DAMAGEBREAK, usenum); + if( ITEM_WarpForAny(charaindex, ff, fx, fy, flg) == FALSE )return; + } +} +#endif + +#ifdef _SPECIAL_SUIT +void ITEM_SpecialCheckSuitEquip( int charaindex, int itemindex) +{ + int i, num=0; + int defCode = ITEM_getInt( itemindex, ITEM_SUITCODE); + + for( i=0; i=5){ + if(defCode>=100000){ + CHAR_setInt( charaindex , CHAR_BASEIMAGENUMBER , defCode ); + + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + } + }else{ + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER) ); + + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + } + } +} + +void ITEM_SpecialSuitEquip( int charaindex, int itemindex) +{ + int ff=0, fx=0, fy=0; + char buf[256]; + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + if( sscanf( arg, "%d %d %d", &ff, &fx, &fy) != 3 ){ + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + fx = CHAR_getInt( charaindex, CHAR_X ); + fy = CHAR_getInt( charaindex, CHAR_Y ); + // WON ADD + if( checkUnlawWarpFloor( ff) ) { + CHAR_talkToCli(charaindex, -1, "˴޷ʹá", CHAR_COLORYELLOW); + return; + } + + sprintf( buf, "%d %d %d", ff, fx, fy); + ITEM_setChar(itemindex, ITEM_ARGUMENT, buf); + + } + char escapeshowstring[64]; + char *showstr = MAP_getfloorShowstring(ff); + if( checkUnlawWarpFloor( ff) ) { + CHAR_talkToCli(charaindex, -1, "˴޷ʹá", CHAR_COLORYELLOW); + return; + } + getStringFromIndexWithDelim( showstr, "|", 1, escapeshowstring, sizeof( escapeshowstring)); + sprintf( buf, "װ¼λ(%s,%d,%d)", escapeshowstring, fx, fy); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORYELLOW); + + ITEM_SpecialCheckSuitEquip( charaindex, itemindex); +} + +void ITEM_SpecialResuitEquip( int charaindex, int itemindex) +{ + ITEM_SpecialCheckSuitEquip( charaindex, itemindex); +} +#endif + +#ifdef _MANOR_EQUIP +void ITEM_CheckManorEquip( int charaindex, int itemindex) +{ + int floor = CHAR_getWorkInt( charaindex, CHAR_WORKFMFLOOR); + + if(floor == ITEM_getInt( itemindex, ITEM_SUITCODE)){ + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + ITEM_setInt( itemindex, ITEM_MAGICID, atoi(arg)); + }else{ + ITEM_setInt( itemindex, ITEM_MAGICID, -1); + } + int i; + for(i=0;i0){ + int i; + for(i=rate;i<0;i--){ + if(findtreasures[i]>-1){ + rate=i; + break; + } + } + if(i==-1){ + for(i=rate;i-1){ + rate=i; + break; + } + } + } + } + } + + if(findtreasures[rate]>-1){ + int itemindex = ITEM_makeItemAndRegist( findtreasures[rate] ); + if( ITEM_CHECKINDEX( itemindex) ){ + int emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + if( emptyitemindexinchara >= 0 ){ + if( itemindex != -1 ){ + CHAR_setItemIndex( charaindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charaindex); + CHAR_sendItemDataOne( charaindex, emptyitemindexinchara); + + sprintf( buf, "ϲ㣬ѰҵƷ %s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1,buf, CHAR_COLORGREEN); + } + }else{ + CHAR_talkToCli( charaindex, -1, "ܱǸƷ", CHAR_COLORYELLOW); + return; + } + } + } + CHAR_DelItem( charaindex, haveitemindex); + return; + } +} + +BOOL FindTreasures_init() +{ + FILE* fp; + int i; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/findtreasures.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/findtreasures.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + for(i=0;i0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -atoi(arg), + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(ֿ߲)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } +#endif + +} +#endif + +#ifdef _ITEM_POOLPET +extern int petshophanlde; +void ITEM_PoolPet( int charaindex, int toindex, int haveitemindex ) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + if(CHAR_getInt(charaindex, CHAR_AMPOINT)0){ + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + -atoi(arg), + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "(ֿ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); + } +#endif +} +#endif + +#ifdef _NEW_GM_ITEM +void ITEM_NewGMItem( int charaindex, int toindex, int haveitemindex ) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex ) ) return; + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + + char token[256]; + char magicname[256]; + int ret; + + CHATMAGICFUNC func; + + ret = getStringFromIndexWithDelim( arg, " ", 1, magicname, sizeof( magicname)); + if( ret == FALSE)return; + + func = CHAR_getChatMagicFuncPointer(magicname,TRUE); + + if( func ){ + LogGM( CHAR_getUseName( charaindex), CHAR_getChar( charaindex, CHAR_CDKEY), arg, + CHAR_getInt( charaindex, CHAR_FLOOR), CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y) ); + func( charaindex, arg + strlen( magicname)+1); + sprintf(token, "ʹѳɹ! %s\n", ITEM_getChar(itemindex, ITEM_NAME )); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); + } +} +#endif + +#ifdef _SHOW_PET_ABL +void ITEM_ShowPetAbl( int charaindex, int toindex, int haveitemindex ) +{ + if( !CHAR_CHECKINDEX( toindex ) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET){ + CHAR_talkToCli( charaindex, -1, "ѡij!", CHAR_COLORRED); + return; + } + int work[4]; + int LevelUpPoint; + char token[128]; + char buf[][32]={"ɳ",";ɳ","ٶȳɳ","ɳ"}; + + LevelUpPoint = CHAR_getInt( toindex, CHAR_ALLOCPOINT ); + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + + sprintf(token, "%s ɳ:", CHAR_getChar( toindex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORGREEN); + sprintf(token, "%s %d", buf[0], work[0]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf(token, "%s %d", buf[1], work[1]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf(token, "%s %d", buf[2], work[2]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + sprintf(token, "%s %d", buf[3], work[3]); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _NEWEVENT_ITEM +void ITEM_NeweventItem( int charaindex, int toindex, int haveitemindex ) +{ + if( !CHAR_CHECKINDEX( charaindex ) ) return; + + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex ) ) return; + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + char token[128]; + int i=0; + while(getStringFromIndexWithDelim( arg, "|", i, token, sizeof( token))){ + NPC_NowEndEventSetFlgCls(charaindex, atoi(token)); + NPC_EventSetFlg(charaindex, atoi(token)); + i++; + if(i>30)break; + } + sprintf(token, "ϲ %s", arg); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORGREEN); + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + +#ifdef _NEW_PET_BEATITUDE +void ITEM_NewPetBeatitude( int charaindex, int toindex, int haveitemindex ) +{ + if( !CHAR_CHECKINDEX( charaindex ) ) return; + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET){ + CHAR_talkToCli( charaindex, -1, "ѡij!", CHAR_COLORRED); + return; + } + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex ) ) return; + char *arg = ITEM_getChar(itemindex, ITEM_ARGUMENT ); + char token[128]; + int abi[4]; + int flg; + int i; + int work[4]; + int LevelUpPoint; + char buf[][32]={"ɳ",";ɳ","ٶȳɳ","ɳ"}; + if(getStringFromIndexWithDelim( arg, "|", 1, token, sizeof( token))==TRUE){ + if( CHAR_getInt( toindex, CHAR_PETID) != atoi(token) ){ + CHAR_talkToCli( charaindex, -1, "ѡijﲻ!", CHAR_COLORRED); + return; + } + }else{ + return; + } + + if(getStringFromIndexWithDelim( arg, "|", 2, token, sizeof( token))==TRUE){ + flg = atoi(token); + if(NPC_EventCheckFlg(toindex, flg)==TRUE){ + CHAR_talkToCli( charaindex, -1, "óѾ޷ٴʹøƷ!", CHAR_COLORRED); + return; + } + }else{ + return; + } + + if(getStringFromIndexWithDelim( arg, "|", 3, token, sizeof( token))==TRUE){ + char tmp[16]; + if(getStringFromIndexWithDelim( token, ":", 1, tmp, sizeof( tmp))==TRUE){ + abi[3] = atoi(tmp); + }else{ + abi[3] = 0; + } + if(getStringFromIndexWithDelim( token, ":", 2, tmp, sizeof( tmp))==TRUE){ + abi[0] = atoi(tmp); + }else{ + abi[0] = 0; + } + if(getStringFromIndexWithDelim( token, ":", 3, tmp, sizeof( tmp))==TRUE){ + abi[1] = atoi(tmp); + }else{ + abi[1] = 0; + } + if(getStringFromIndexWithDelim( token, ":", 4, tmp, sizeof( tmp))==TRUE){ + abi[2] = atoi(tmp); + }else{ + abi[2] = 0; + } + }else{ + return; + } + + LevelUpPoint = CHAR_getInt( toindex, CHAR_ALLOCPOINT ); + work[3] =(( LevelUpPoint >> 24 ) & 0xFF); + work[0] = (( LevelUpPoint >> 16 ) & 0xFF); + work[1] = (( LevelUpPoint >> 8 ) & 0xFF); + work[2] = (( LevelUpPoint >> 0 ) & 0xFF); + + sprintf(token, "%s ɳʱ仯:", CHAR_getChar( toindex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORGREEN); + for(i=0;i<4;i++){ + work[i] += abi[i]; + if(abi[i]>0){ + sprintf(token, "%s %d", buf[i], abi[i]); + }else if(abi[i]<0){ + sprintf(token, "%s ½ %d", buf[i], abi[i]); + }else{ + sprintf(token, "%s δ仯", buf[i]); + } + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + + } + + LevelUpPoint = ( work[3]<< 24) + ( work[0]<< 16) + ( work[1]<< 8) + ( work[2]<< 0); + CHAR_setInt( toindex, CHAR_ALLOCPOINT, LevelUpPoint); + + NPC_EventSetFlg(toindex, flg); + + CHAR_DelItem( charaindex, haveitemindex); +} +#endif + + +#ifdef _OLYMPIC_TORCH +void ITEM_OlympicTorck( int charaindex, int toindex, int haveitemindex ) +{ + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + char token[128]; + int i; + int findindex; + if( !ITEM_CHECKINDEX( itemindex ) ) return; + if(strlen(ITEM_getChar(itemindex, ITEM_FORUSERNAME)) == 0 || strlen(ITEM_getChar(itemindex, ITEM_FORUSERCDKEY)) == 0){ + for(i=0;i<3;i++){ + findindex = rand() % CHAR_getPlayerMaxNum(); + if(CHAR_CHECKINDEX(findindex) == TRUE){ + if(findindex!=charaindex){ + ITEM_setChar(itemindex, ITEM_FORUSERNAME, CHAR_getChar(findindex, CHAR_NAME)); + ITEM_setChar(itemindex, ITEM_FORUSERCDKEY, CHAR_getChar(findindex, CHAR_CDKEY)); + + sprintf(token, "ѰҵʵĽӰ %s,ǰڵͼ:%d X:%d Y:%d", CHAR_getChar(findindex, CHAR_NAME) + ,CHAR_getInt(findindex, CHAR_FLOOR) + ,CHAR_getInt(findindex, CHAR_X) + ,CHAR_getInt(findindex, CHAR_Y)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return; + } + } + } + CHAR_talkToCli( charaindex, -1, "ܱǸ,ҲʵĽӰ!", CHAR_COLORYELLOW); + }else{ + int playernum = CHAR_getPlayerMaxNum(); + for(findindex=0;findindexfunctable[LUAITEM_USEFUNC] != (void *)NPC_Lua_ItemUseCallBack) + { + if(TM_Item->functable[LUAITEM_USEFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_USEFUNC] = TM_Item->functable[LUAITEM_USEFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string), itemname2); + }else + { + TM_Item->sur_functable[LUAITEM_USEFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string[0] = '\0'; + } + TM_Item->functable[LUAITEM_USEFUNC] = (void *)NPC_Lua_ItemUseCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string), itemname2); + strcpy_s(TM_Item->string[ITEM_USEFUNC].string, sizeof(TM_Item->string[ITEM_USEFUNC].string), FUNCNAME_ITEMUSECALLBACK); + } + + NPC_Lua_ItemUseCallBack(charaindex, toindex, haveitemindex); +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/item/item_gen.c b/石器时代服务器端最新完整源代码/Serv/gmsv/item/item_gen.c new file mode 100644 index 0000000..b648a59 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/item/item_gen.c @@ -0,0 +1,1561 @@ +/*********************************************** + * ʧ ة + **********************************************/ +#include "version.h" +#include +#include +#include +#include +#include +#include +#include +#include "autil.h" +#include "configfile.h" +#include "util.h" +#include "buf.h" + +#include "char.h" +#include "item.h" +#include "item_gen.h" +#include "enemy.h" +#include "log.h" +#include "saacproto_cli.h" +#include "family.h" +#include "magic_base.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#define DEBUGPRINT 0 +#define DEBUGPRINT_DETAIL 0 + +// shan begin +#define FOOD_HP_RATE 200 +#define FOOD_MP_RATE 200 +#define FOOD_SUCCESS_RATE 150 +#define FOOD_TURN_ADDPOINT 1 +// shan end + +static int ITEM_getTableNum( int num); + +/* ټ㼰MAX */ +#define ITEM_ATOMIND_MAX 1000 +// shan add +#define ITEM_ATOMIND_FM_MAX 4000 + +#define ITEM_RANDRANGEDOM 1000 +#define ITEM_RANDRANGEDOM_BASE 0 +// shan add +#define ITEM_FM_RANDRANGEDOM 4000 + +/*********************************************** + * (ITEM_GEN_RAND_MIN/1000) * ITEN_GEN_SEARCH_MIN + * - (ITEM_GEN_RAND_MAX/1000) * ITEN_GEN_SEARCH_MAX + * ľ꼰༰ټ㼰 ëԻDZئ£ + **********************************************/ + +/* ټ㼰 ¼ĸة༰ ߨߨ */ +#define ITEM_GEN_RAND_MIN 700 +#define ITEM_GEN_RAND_MAX 1200 + +/* ʧ ةëټ㼰༰ (double) */ +#define ITEN_GEN_SEARCH_MIN (0.7) +#define ITEN_GEN_SEARCH_MAX (1.10) + +static struct tagItemSearchRangeTable { + double searchmin; + double searchmax; +}ItemSearchTable[2] = { +// { 0.7, 1.1}, +// shan add +// { 0.7, 1.3}, +// { 0.5, 1.5} + { 0.8, 1.2}, + { 0.7, 1.3} +}; + +static struct tagItemRandRangeTable { + int randmin; + int randmax; +}ItemRandTable[2] = { +// { 700, 1200}, + { 700, 1300}, + { 900, 1100} +}; + +#define ITEM_GEN_RATE 0.7 + +static struct _tagItemRandRangeTableForItem { + int num; /* ټ㼰¼ͼ */ + int minnum; /* ¼ Ի°Min */ + int maxnum; /* ¼ Ի°MAX num +ݼ¼ͼ*ITEM_GEN_RATE) */ + double rate; /* maxnum / num*/ +}ItemRandTableForItem[] = { + { 10, 0,0,0 }, + { 30, 0,0,0 }, + { 65, 0,0,0 }, + { 125, 0,0,0 }, + { 205, 0,0,0 }, + { 305, 0,0,0 }, + { 425, 0,0,0 }, + { 565, 0,0,0 }, + { 725, 0,0,0 }, + { 905, 0,0,0 }, + { 1125, 0,0,0 }, // shan add + { 1354, 0,0,0 }, + { 1594, 0,0,0 }, + { 1825, 0,0,0 }, + { 2105, 0,0,0 }, + { 2405, 0,0,0 }, + { 2725, 0,0,0 }, + { 3065, 0,0,0 }, + { 3425, 0,0,0 }, + { 3805, 0,0,0 } +}; + +#define ATOM_LEVEL_MAX 16 +struct item_atom +{ + char name[32]; + unsigned int name_hash; + int magicflg; +}; + + +struct item_atom *item_atoms; +int item_atoms_size; +#define MAX_ITEM_ATOMS_SIZE 256 + +struct item_ingindtable { + double data[MAX_ITEM_ATOMS_SIZE]; + int index; + int num; +}; + +static int ITEM_getAtomIndexByName( char *nm ) // زȡزindex +{ + int i; + unsigned int h = hashpjw( nm ); + for( i = 0; i < item_atoms_size; i ++ ){ + if( item_atoms[i].name_hash == h && + strcmp( item_atoms[i].name, nm) == 0 ){ + return i; + } + } + return -1; +} + +extern ITEM_table *ITEM_tbl; +extern ITEM_index* ITEM_idx; + +struct ingcache +{ + int use; +#define MAXING_ONE 5 + int inguse; + int canmergefrom; + int canmergeto; + int hitnum; + int ingind[MAXING_ONE]; + int ingval[MAXING_ONE]; +}; + +int ITEM_initRandTable( void) +{ + int i; + for( i = 0; i < arraysizeof( ItemRandTableForItem); i ++) { + if( i == 0 ) ItemRandTableForItem[i].minnum = 0; + else { + ItemRandTableForItem[i].minnum = ItemRandTableForItem[i-1].maxnum+1; + } + if( i + 1 != arraysizeof( ItemRandTableForItem)) { + ItemRandTableForItem[i].maxnum = + ItemRandTableForItem[i].num + + (ItemRandTableForItem[i+1].num - ItemRandTableForItem[i].num) + *ITEM_GEN_RATE; + + } + else { + // shan add + ItemRandTableForItem[i].maxnum = 4000; + //ItemRandTableForItem[i].maxnum = 1000; + } + ItemRandTableForItem[i].rate = ItemRandTableForItem[i].maxnum + / (double)ItemRandTableForItem[i].num; + } + /*for( i = 0; i < arraysizeof( ItemRandTableForItem); i ++) { + print( "\ntable num:[%d] min:[%d] max:[%d] rate:[%3.3f] ", + ItemRandTableForItem[i].num, + ItemRandTableForItem[i].minnum, + ItemRandTableForItem[i].maxnum, + ItemRandTableForItem[i].rate); + }*/ + return TRUE; +} + +static struct ingcache *icache; +int icache_num; + +int ITEM_initItemIngCache( void ) +{ + int i; +// print ( "\nʼƷ: Ʒ:%d ", ITEM_getItemMaxIdNum() ); + icache_num = ITEM_getItemMaxIdNum( ); + print(" :%d ", icache_num); + icache = calloc(1, sizeof( struct ingcache ) * icache_num ); + if( icache == NULL ){ + print( "ʼƷ: ûƷ\n" ); + return FALSE; + } + + print(" %4.2f MB ռ...", sizeof( struct ingcache ) * icache_num /1024.0/1024.0); + + remove( "old_icache.txt"); + memset( icache, 0, icache_num * sizeof( struct ingcache) ); + for( i=0; i= MAX_ITEM_ATOMS_SIZE ){ + print( "ʼƷɷ: Ʒɷ̫\n" ); + return FALSE; + } + + item_atoms_size = count; + print( "ʼƷɷ: ȡ %d Ʒɷ...", count ); + + return TRUE; +} + +/* + + Ѽ + + base 100 ƥ min 0.7 ƥ max 1.3 գ + 70 ~ 130 £Իؤ + ԪئԻ¾ľئмƥ + ʧ ةûƻ by ringo 1999Oct1 + 1000мmin_rate,max_rateƥ + double ֧float ֧֧мƥئУ + */ +static int +ITEM_randRange( int base, int min_rate , int max_rate ) +{ + int minnum; + int maxnum; + int range; + + if( min_rate > max_rate) { + int tmp; + tmp = min_rate; + min_rate = max_rate; + max_rate = tmp; + } + minnum = rint((double)base / ITEM_RANDRANGEDOM * min_rate); + maxnum = rint((double)base / ITEM_RANDRANGEDOM * max_rate); + range = ( maxnum - minnum ); + + if( min_rate == max_rate && min_rate == 0 ) return 0; + if( range == 0 ) return base; + if( range < 0 ) return 0; + return minnum + RAND( 0, range); +} + +typedef int (*FUNC)( const void *, const void * ); + +static int cmprutine( double *p1, double *p2) +{ + if( *p1 < *p2 ) return -1; + if( *p1 > *p2 ) return 1; + return 0; +} +/* + * мؤ + * ߯Ի ʹئ׾ + * ĩƻͻ + * table Уƻʣ + */ + +static void ITEM_simplify_atoms( struct item_ingindtable *inds, int num, + int *retinds, int *retvals, int petindex, int alchemist) +{ + //int newinds[MAX_ITEM_ATOMS_SIZE]; + //int newvals[MAX_ITEM_ATOMS_SIZE]; + int i; + double oddstable[] = { + 0.1, + 0.25, + 0.35, + 0.4, + 0.42, + 0.44, + 0.46, + 0.47, + 0.48, + 0.49, + 0.5, + 0.51, + 0.52, + 0.53 + }; + + for( i = 0; i < num; i ++ ) { + int datacnt = (inds + i)->num; + if( datacnt > 1 ) { + int j; + qsort( (inds + i)->data, datacnt, + sizeof( double ), (FUNC)cmprutine); + for( j = 1; j < datacnt; j ++ ) { + int tablenum; + double rate; + tablenum = ITEM_getTableNum( (inds + i)->data[j-1]); + rate = ItemRandTableForItem[tablenum].rate / ItemRandTableForItem[0].rate; + (inds + i)->data[j] += (inds + i)->data[j-1] * oddstable[j-1] * rate; + } + } + *(retinds + i) = ( inds + i)->index; + *(retvals + i) = (int)( inds + i)->data[ datacnt-1]; + // shan add begin + if( petindex != -1 ){ + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + if( *( retvals + i) > ITEM_ATOMIND_FM_MAX ){ + *( retvals + i) = ITEM_ATOMIND_FM_MAX; + } + }else{ + if( *( retvals + i) > ITEM_ATOMIND_MAX ){ + *( retvals + i) = ITEM_ATOMIND_MAX; + } + } + } + // shan end + } +} + +/* +PET_ADD_INGRED( nm,vl1,vl2,vl3) +{ + if( strlen( ENEMYTEMP_getChar( petarray, nm)) != 0 ) + { + fixatom[ingnum] =ITEM_getAtomIndexByName( ENEMYTEMP_getChar( petarray, nm) ); + if( fixatom[ingnum] < 0 ) + { + print( "\nfucking atom:[%s] for pet id %d", ENEMYTEMP_getChar( petarray, nm), petid ); + continue; + } + + baseup[ingnum] = ENEMYTEMP_getInt( petarray, vl1); + minadd[ingnum] = ENEMYTEMP_getInt( petarray, vl2); + maxadd[ingnum] = ENEMYTEMP_getInt( petarray, vl3); + + if( petindex != -1) + { + if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ) + { + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + if (!CHAR_CHECKINDEX(ownerindex)) + { + print("ownerindex err!\n"); + return; + } + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) + { + print("\n Pet Ownerindex Error"); + return; + } + baseup[ingnum] = PetLv[getFmLv(ownerindex)]; + } + } + + if( minadd[ingnum] > maxadd[ingnum] ) + { + int tmp = minadd[ingnum]; + minadd[ingnum] = maxadd[ingnum];maxadd[ingnum] = tmp; + } + + if( CHAR_getInt(petid, CHAR_PETFAMILY) == 1 ) + { + if( minadd[ingnum]<0 ) + minadd[ingnum] = ITEM_FM_RANDRANGEDOM; + if( maxadd[ingnum]<0 ) + maxadd[ingnum] = ITEM_FM_RANDRANGEDOM; + } + else + { + if( minadd[ingnum]<0 ) + minadd[ingnum] = ITEM_RANDRANGEDOM; + if( maxadd[ingnum]<0 ) + maxadd[ingnum] = ITEM_RANDRANGEDOM; + } + ingnum++; + } +} +*/ + +/* + ʸIDգѼĤɬëԻʣ + + int *fixuse : ¦ѣ ëԻëľ + + int *fixatom : ټ帲Ĥئ + int *baseup : µң + int *minadd : ң µң + int *maxadd : ң µң + + */ + +static void +ITEM_merge_getPetFix( int petid, int *fixuse, int *fixatom, + int *baseup, + int *minadd, + int *maxadd, + int petindex, + int *fm_fix) +{ + int i; + int ingnum = 0; + int petarray; + +// shan begin +#define FamilyLv 11 + //int PetLv[FamilyLv]; + //for(i=0; i maxadd[ingnum] ) { int tmp = minadd[ingnum];minadd[ingnum] = maxadd[ingnum];maxadd[ingnum] = tmp;}if( CHAR_getInt(petid, CHAR_PETFAMILY) == 1 ){if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_FM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_FM_RANDRANGEDOM;}else{if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_RANDRANGEDOM;}ingnum++;} +#define PET_ADD_INGRED( nm,vl1,vl2,vl3) if( strlen( ENEMYTEMP_getChar( petarray, nm)) != 0 ){fixatom[ingnum] =ITEM_getAtomIndexByName( ENEMYTEMP_getChar( petarray, nm) ); if( fixatom[ingnum] < 0 ){print( "\nfucking atom:[%s] for pet id %d", ENEMYTEMP_getChar( petarray, nm), petid );continue;} baseup[ingnum] = ENEMYTEMP_getInt( petarray, vl1); minadd[ingnum] = ITEM_RANDRANGEDOM_BASE + ENEMYTEMP_getInt( petarray, vl2); maxadd[ingnum] = ITEM_RANDRANGEDOM_BASE + ENEMYTEMP_getInt( petarray, vl3); if(CHAR_CHECKINDEX(petindex)){ if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){ int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); if (!CHAR_CHECKINDEX(ownerindex)){print("ownerindex err!\n");return;}if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER){print("\n Pet Ownerindex Error");return;}baseup[ingnum] = PetLv[getFmLv(ownerindex)];}}if( minadd[ingnum] > maxadd[ingnum] ) {int tmp = minadd[ingnum];minadd[ingnum] = maxadd[ingnum];maxadd[ingnum] = tmp;}if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_FM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_FM_RANDRANGEDOM;}else{if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_RANDRANGEDOM;}ingnum++;} +#else +#define PET_ADD_INGRED( nm,vl1,vl2,vl3) if( strlen( ENEMYTEMP_getChar( petarray, nm)) != 0 ) { fixatom[ingnum] =ITEM_getAtomIndexByName( ENEMYTEMP_getChar( petarray, nm) ); if( fixatom[ingnum] < 0 ){ print( "\nfucking atom:[%s] for pet id %d", ENEMYTEMP_getChar( petarray, nm), petid ); continue;} baseup[ingnum] = ENEMYTEMP_getInt( petarray, vl1); minadd[ingnum] = ENEMYTEMP_getInt( petarray, vl2); maxadd[ingnum] = ENEMYTEMP_getInt( petarray, vl3); if( petindex != -1){ if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){ int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); if (!CHAR_CHECKINDEX(ownerindex)){print("ownerindex err!\n");return;}if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_MEMBER){print("\n Pet Ownerindex Error");return;}baseup[ingnum] = PetLv[getFmLv(ownerindex)];}}if( minadd[ingnum] > maxadd[ingnum] ) {int tmp = minadd[ingnum];minadd[ingnum] = maxadd[ingnum];maxadd[ingnum] = tmp;}if( CHAR_getInt(petid, CHAR_PETFAMILY) == 1 ){if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_FM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_FM_RANDRANGEDOM;}else{if( minadd[ingnum]<0 ) minadd[ingnum] = ITEM_RANDRANGEDOM;if( maxadd[ingnum]<0 ) maxadd[ingnum] = ITEM_RANDRANGEDOM;}ingnum++;} +#endif + + PET_ADD_INGRED( E_T_ATOMFIXNAME1, E_T_ATOMBASEADD1, E_T_ATOMFIXMIN1, E_T_ATOMFIXMAX1); + PET_ADD_INGRED( E_T_ATOMFIXNAME2, E_T_ATOMBASEADD2, E_T_ATOMFIXMIN2, E_T_ATOMFIXMAX2); + PET_ADD_INGRED( E_T_ATOMFIXNAME3, E_T_ATOMBASEADD3, E_T_ATOMFIXMIN3, E_T_ATOMFIXMAX3); + PET_ADD_INGRED( E_T_ATOMFIXNAME4, E_T_ATOMBASEADD4, E_T_ATOMFIXMIN4, E_T_ATOMFIXMAX4); + PET_ADD_INGRED( E_T_ATOMFIXNAME5, E_T_ATOMBASEADD5, E_T_ATOMFIXMIN5, E_T_ATOMFIXMAX5); + } + + if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ) { + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + if( CHAR_CHECKINDEX(ownerindex) ) { + *fm_fix = PetLv[getFmLv(ownerindex)]; + } + } + + *fixuse = ingnum; + return; +} + +/* + * ʧ ةؤFALSEë߯ + */ + +static BOOL ITEM_merge_checkitem( ITEM_Item *items, int itemsnum, int id) +{ + int loop; + for( loop = 0; loop < itemsnum; loop ++ ) { + if( items[loop].data[ITEM_ID] == id ) break; + } + if( loop == itemsnum ) return TRUE; + return FALSE; +} + +static int ITEM_merge_with_retry( ITEM_Item *items,int itemsnum, + int *ingindtable, int ingnum, + int *ingtable, int searchtable, int petindex ) +{ + + int ideal; + int idel_num[5][5] = { { 0}, + { 250,0 }, + { 400,150,0}, + { 700,260,70,0}, + { 740,500,200,40,0} + }; + int endflg[5]; + BOOL first = TRUE; + int extractcnt = 0; +#define MAXMATCH 2048 + int matchid[MAXMATCH]; + int i,j,k; + if( ingnum > 5 ) ideal = 5; + else ideal = ingnum; + memset( endflg, 0, sizeof( endflg)); + while( 1 ) { + int r = RAND( 0, 999); + int extractnum; + int match = 0; + if( extractcnt >= ideal ) break; + // ϳɵߵı + for( extractnum = 0; extractnum < ideal; extractnum ++ ) { + if( r >= idel_num[ideal-1][extractnum] ) { + break; + } + } + if( endflg[extractnum] == TRUE ) continue; + endflg[extractnum] = TRUE; + extractcnt++; + extractnum = ideal - ( extractnum ); + + if( first ) { + for( i = 0; i < icache_num; i++ ){ // ѰȫITEM + if( icache[i].use && icache[i].canmergeto) { // ǿɺϳɵITEM + icache[i].hitnum = 0; + for( j = 0; j < icache[i].inguse; j ++ ) { // ITEMIJ + for( k = 0; k < ingnum ; k ++){ // ϳɵIJ + if( icache[i].ingind[j] == ingindtable[k] ) { // Ϸ + if( searchtable == 0 ) { // ߺϳɵĻ + int tablenum = ITEM_getTableNum( ingtable[k]); // ϵȼ + // shan begin + if( petindex != -1){ + if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){ // ػ޵Ļ + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + int familyLevel = getFmLv(ownerindex); + if (!CHAR_CHECKINDEX(ownerindex)){ + print("!\n"); + return -1; + } +#ifdef _FMVER21 + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER){ +#else + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_MEMBER){ +#endif + print("\n "); + return -1; + } + // + if( icache[i].ingval[j] <= ingtable[k]*ItemRandTableForItem[tablenum].rate && + icache[i].ingval[j] >= ingtable[k]*(1/ItemRandTableForItem[tablenum].rate) && + icache[i].ingval[j] <= ItemRandTableForItem[familyLevel+9].maxnum) { + icache[i].hitnum++; + break; + } + }else{ // ػ޵Ļ + float toplimit = ingtable[k]*ItemRandTableForItem[tablenum].rate; + if( toplimit > 2500) toplimit = 2500; + // + if( icache[i].ingval[j] <= toplimit && + icache[i].ingval[j] >= ingtable[k]*(1/ItemRandTableForItem[tablenum].rate)){ + icache[i].hitnum++; + break; + } + } + } + // shan end + }else { // ʳϳɵĻ + // shan begin + if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){ + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + int familyLevel = getFmLv(ownerindex); + if (!CHAR_CHECKINDEX(ownerindex)){ + print("!\n"); + return -1; + } +#ifdef _FMVER21 + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER){ +#else + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_MEMBER){ +#endif + print("\n "); + return -1; + } + if( ingtable[k] > ItemRandTableForItem[familyLevel+9].maxnum / + ItemSearchTable[searchtable].searchmax ){ + ingtable[k] = ItemRandTableForItem[familyLevel+9].maxnum / + ItemSearchTable[searchtable].searchmax; + } + }else{ + if( ingtable[k] > ItemRandTableForItem[9].maxnum / + ItemSearchTable[searchtable].searchmax ){ + ingtable[k] = ItemRandTableForItem[9].maxnum / + ItemSearchTable[searchtable].searchmax; + } + } + // shan end + + if( icache[i].ingval[j] <= ingtable[k]*ItemSearchTable[searchtable].searchmax && + icache[i].ingval[j] >= ingtable[k]*ItemSearchTable[searchtable].searchmin){ + icache[i].hitnum++; + break; + } + } + } + } + } + // ϵIJͬ + if( icache[i].hitnum == icache[i].inguse && icache[i].hitnum == extractnum ){ + if( ITEM_merge_checkitem(items,itemsnum,i)) { + matchid[match++] = i; + } + } + } + } + first = FALSE; + }else { + for( i = 0; i < icache_num; i++ ){ + if( icache[i].use && icache[i].canmergeto) { + if( icache[i].hitnum == icache[i].inguse && icache[i].hitnum == extractnum ){ + if( ITEM_merge_checkitem(items,itemsnum,i)) { + matchid[match++] = i; + } + } + } + } + } + if( match > 0 ) { + return matchid[ random() % match ]; + }else { + + } + } + return -1; + +} + +#ifdef _NEW_MANOR_LAW +extern struct FM_POINTLIST fmpointlist; +#endif + +#ifdef _COMPOUND_EXP +char mergech[][16] = {"ʯ", "ľ", "", "", "Ƥ", "" , "", "צ", "", "Ҷ", "", "", "", "", "ʯ", "", "", "˯", "ظ", "", "ˮ", "", "ˮ", "", ""}; +#endif + +int ITEM_mergeItem( int charaindex, ITEM_Item *items, int num , int money, int petid, int searchtable, int petindex, int alchemist) +{ + int i; + // shan add + int item_type = -1; + int ingnum =0; + struct item_ingindtable ingindtable[MAX_ITEM_ATOMS_SIZE]; + int sortedingindtable[MAX_ITEM_ATOMS_SIZE]; + int sortedingtable[MAX_ITEM_ATOMS_SIZE]; + /* ʸ巽Ĥ */ + int pet_fixatom[MAX_ITEM_ATOMS_SIZE]; + int pet_baseup[MAX_ITEM_ATOMS_SIZE]; + int pet_minadd[MAX_ITEM_ATOMS_SIZE]; + int pet_maxadd[MAX_ITEM_ATOMS_SIZE]; + int pet_fixuse = MAX_ITEM_ATOMS_SIZE; + int fm_fix; + int nowtime = time( NULL); + +//#ifdef _VERSION_80 + // ϳɷƵ... + if( nowtime - CHAR_getWorkInt( charaindex, CHAR_WORKLASTMERGETIME) < 1 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKLASTMERGETIME, nowtime); + CHAR_talkToCli( charaindex, -1 ,"ϳƵϢһ±ȽϺӴ", CHAR_COLORRED); + //print(" ϳƵ "); + return items[RAND( 0, (num-1))].data[ITEM_ID]; + } +//#endif + + CHAR_setWorkInt( charaindex, CHAR_WORKLASTMERGETIME, nowtime); + for( i = 0; i < arraysizeof( ingindtable); i ++ ) { + int j; + for( j = 0; j < MAX_ITEM_ATOMS_SIZE; j ++ ) { + ingindtable[i].data[j] = 0.0; + } + ingindtable[i].num = 0; + ingindtable[i].index = -1; + } + for(i=0; i100000)value=100000; + CHAR_setInt(charaindex, CHAR_MATERIAL01 + k, value); + } + if(strcmp(items[i].string[ITEM_INGNAME1].string, mergech[k])==0){ + int value = CHAR_getInt(charaindex, CHAR_MATERIAL01 + k) + (items[i].data[ITEM_INGVALUE1]/(150- (rand() % 100))); + if(value>100000)value=100000; + CHAR_setInt(charaindex, CHAR_MATERIAL01 + k, value); + } + if(strcmp(items[i].string[ITEM_INGNAME2].string, mergech[k])==0){ + int value = CHAR_getInt(charaindex, CHAR_MATERIAL01 + k) + (items[i].data[ITEM_INGVALUE2]/(150- (rand() % 100))); + if(value>100000)value=100000; + CHAR_setInt(charaindex, CHAR_MATERIAL01 + k, value); + } + if(strcmp(items[i].string[ITEM_INGNAME3].string, mergech[k])==0){ + int value = CHAR_getInt(charaindex, CHAR_MATERIAL01 + k) + (items[i].data[ITEM_INGVALUE3]/(150- (rand() % 100))); + if(value>100000)value=100000; + CHAR_setInt(charaindex, CHAR_MATERIAL01 + k, value); + } + if(strcmp(items[i].string[ITEM_INGNAME4].string, mergech[k])==0){ + int value = CHAR_getInt(charaindex, CHAR_MATERIAL01 + k) + (items[i].data[ITEM_INGVALUE4]/(150- (rand() % 100))); + if(value>100000)value=100000; + CHAR_setInt(charaindex, CHAR_MATERIAL01 + k, value); + } + } +#endif + +#define ADD_INGRED( nm,vl) if( items[i].string[nm].string[0] ){ int j; int index = ITEM_getAtomIndexByName( items[i].string[nm].string ); if( index < 0 ){ print( "\nfucking atom:[%s] for item id %d", items[i].string[nm].string, items[i].data[ITEM_ID] ); continue;}for( j = 0; j < ingnum; j ++ ) {if( ingindtable[j].index == index ){break;}}if( j == ingnum ) ingnum++; ingindtable[j].data[ingindtable[j].num] = items[i].data[vl]; ingindtable[j].index = index; ingindtable[j].num++;} + ADD_INGRED( ITEM_INGNAME0, ITEM_INGVALUE0 ); + ADD_INGRED( ITEM_INGNAME1, ITEM_INGVALUE1 ); + ADD_INGRED( ITEM_INGNAME2, ITEM_INGVALUE2 ); + ADD_INGRED( ITEM_INGNAME3, ITEM_INGVALUE3 ); + ADD_INGRED( ITEM_INGNAME4, ITEM_INGVALUE4 ); + } + ITEM_simplify_atoms( ingindtable, ingnum, sortedingindtable, sortedingtable, petindex, alchemist); + for(i=0;i ItemRandTableForItem[familyLevel+9].maxnum ){ + sortedingtable[i] = RAND(ItemRandTableForItem[familyLevel+9].minnum, + ItemRandTableForItem[familyLevel+9].maxnum); + } + }else{ + sortedingtable[i] = ITEM_randRange( sortedingtable[i], + ItemRandTable[searchtable].randmin , + ItemRandTable[searchtable].randmax); + } + } + else{ + if( searchtable == 0 ) { + sortedingtable[i] = ITEM_randRange( sortedingtable[i], + ((1/ItemRandTableForItem[tablenum].rate)*ITEM_MERGE_RANGEWIDTH_FORMIN) + * ITEM_RANDRANGEDOM, + ItemRandTableForItem[tablenum].rate * ITEM_MERGE_RANGEWIDTH_FORMAX + * ITEM_RANDRANGEDOM); + if(sortedingtable[i] > 905) sortedingtable[i] = 905; + } + else { + sortedingtable[i] = ITEM_randRange( sortedingtable[i], + ItemRandTable[searchtable].randmin , + ItemRandTable[searchtable].randmax); + } + } + } + // shan end + } + } + + if( ingnum == 0 ) + return -1; + { + int created; + for( i = 0 ; i < 5; i++ ) { + created = ITEM_merge_with_retry( items, num, sortedingindtable,ingnum, + sortedingtable, searchtable, petindex); + if( created >= 0 ) { + // shan begin + if( petindex != -1){ +#ifdef _FMVER21 +#else + if( CHAR_getInt( CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX), CHAR_FMLEADERFLAG ) > 0 ){ +#endif + int kind_num = 0; + int syndp = 0; + int fooddp = 0; + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + if (!CHAR_CHECKINDEX(ownerindex)){ + print("ownerindex err!\n"); + return -1; + } + if( searchtable == 1 ){ + + if( ITEMTBL_getInt( created, ITEM_INGVALUE0) != 0 ) kind_num++; + if( ITEMTBL_getInt( created, ITEM_INGVALUE1) != 0 ) kind_num++; + if( ITEMTBL_getInt( created, ITEM_INGVALUE2) != 0 ) kind_num++; + if( ITEMTBL_getInt( created, ITEM_INGVALUE3) != 0 ) kind_num++; + if( ITEMTBL_getInt( created, ITEM_INGVALUE4) != 0 ) kind_num++; + + fooddp = ITEMTBL_getInt( created, ITEM_INGVALUE0) + + ITEMTBL_getInt( created, ITEM_INGVALUE1) + + ITEMTBL_getInt( created, ITEM_INGVALUE2) + + ITEMTBL_getInt( created, ITEM_INGVALUE3) + + ITEMTBL_getInt( created, ITEM_INGVALUE4); +#ifndef _NEW_MANOR_LAW + #ifdef _PERSONAL_FAME // Arminius: + fooddp = sqrt(fooddp) * pow(2,kind_num-2) * RAND(0,6) / 200; + #else + fooddp = sqrt(fooddp) * pow(2,kind_num-2) * RAND(0,6) / 100; + #endif + char buf[64]; + //print("FoodDP: num->%d sumdp->%d", kind_num, fooddp); + sprintf(buf, "%d", fooddp); + + #ifdef _PERSONAL_FAME // Arminius 8.30: + CHAR_earnFame(ownerindex, fooddp); + #endif + + #ifdef _FMVER21 + if( CHAR_getInt( CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX), CHAR_FMLEADERFLAG ) > 0 && + CHAR_getInt( CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX), CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY ) + { + // CoolFish: 2001/10/03 + int fd = getfdFromCharaIndex(ownerindex); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(ownerindex, CHAR_FMNAME), + CHAR_getInt(ownerindex, CHAR_FMINDEX), + CHAR_getWorkInt(ownerindex, CHAR_WORKFMINDEXI), + FM_FIX_FMDEALFOOD, buf, "", + // CoolFish: 2001/10/03 + CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + // CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), 0); + } + #else + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(ownerindex, CHAR_FMNAME), + CHAR_getInt(ownerindex, CHAR_FMINDEX), + CHAR_getWorkInt(ownerindex, CHAR_WORKFMINDEXI), + FM_FIX_FMDEALFOOD, buf, "", + CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), 0); + #endif +#endif + }else{ + syndp = ITEMTBL_getInt( created, ITEM_INGVALUE0) + + ITEMTBL_getInt( created, ITEM_INGVALUE1) + + ITEMTBL_getInt( created, ITEM_INGVALUE2) + + ITEMTBL_getInt( created, ITEM_INGVALUE3) + + ITEMTBL_getInt( created, ITEM_INGVALUE4); +#ifndef _NEW_MANOR_LAW + #ifdef _PERSONAL_FAME // Arminius: + syndp = syndp / 400; + #else + syndp = syndp / 200; + #endif + char buf[64]; + + sprintf(buf, "%d", syndp); + + #ifdef _PERSONAL_FAME // Arminius 8.30: + CHAR_earnFame(ownerindex, syndp); + #endif + + #ifdef _FMVER21 + if( CHAR_getInt( CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX), CHAR_FMLEADERFLAG ) > 0 && + CHAR_getInt( CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX), CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY ) + { + // CoolFish: 2001/10/03 + int fd = getfdFromCharaIndex(ownerindex); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(ownerindex, CHAR_FMNAME), + CHAR_getInt(ownerindex, CHAR_FMINDEX), + CHAR_getWorkInt(ownerindex, CHAR_WORKFMINDEXI), + FM_FIX_FMSYNTHESIZE, buf, "", + // CoolFish: 2001/10/03 + CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + } + #else + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(ownerindex, CHAR_FMNAME), + CHAR_getInt(ownerindex, CHAR_FMINDEX), + CHAR_getWorkInt(ownerindex, CHAR_WORKFMINDEXI), + FM_FIX_FMSYNTHESIZE, buf, "", + CHAR_getWorkInt(ownerindex, CHAR_WORKFMCHARINDEX), 0); + #endif +#endif + } +#ifdef _FMVER21 +#else + } +#endif + } +#ifdef _MAX_MERGE_LEVEL + if (ITEMTBL_getInt( created, ITEM_LEVEL)>= getMaxMergeLevel()){ + CHAR_talkToCli( charaindex, -1 ,"޷ϳɳԽ趨װŶ", CHAR_COLORRED); + return items[RAND( 0, (num-1))].data[ITEM_ID]; + }else{ + return created; + } +#else + return created; +#endif + } + } + return items[RAND( 0, (num-1))].data[ITEM_ID]; + } + return -3; +} + +int ITEM_canDigest( ITEM_Item *itm ) +{ + /* 1 󡻥ɬýľ1 + ƥئئ0 */ + if( itm->string[ITEM_INGNAME0].string[0] ) return 1; else return 0; +} + + + +int ITEM_merge_test(void) +{ + int iid,i,k; + ITEM_Item itm[1]; + + for( k = 0 ; k < 10 ; k ++ ){ + iid = 1; + for( i = 0 ; i < 20 ; i ++ ){ + ITEM_makeItem( &itm[0] , iid ); + print( "%d RETURN: %d\n", i, + // shan + iid = ITEM_mergeItem( -1, itm, 1 , 0, -1,0,-1,0) ); + } + print( "------\n" ); + } + return 0; +} + +int ITEM_mergeItem_merge( int charaindex, int petid, char *data, int petindex, int alchemist) +{ + BOOL result = FALSE; + int i; + int ret; + int cnt = 0; + int itemindexs[CHAR_MAXITEMHAVE - CHAR_STARTITEMARRAY]; + int haveitemindexs[CHAR_MAXITEMHAVE - CHAR_STARTITEMARRAY]; + // Nuke +2 1026: Avoid merge cheat + int itemflag[CHAR_MAXITEMHAVE - CHAR_STARTITEMARRAY]; + int j,collision=0; + + char buff[64]; + + ITEM_Item items[CHAR_MAXITEMHAVE - CHAR_STARTITEMARRAY]; + // Nuke +1 1026 + memset(itemflag,0,sizeof(itemflag)); + + { + int emptyindex = CHAR_findEmptyItemBox( charaindex ); + if( emptyindex == -1 ){ + CHAR_talkToCli( charaindex, -1, "ϳʱһƷλ", CHAR_COLORYELLOW); + return -1; + } + } + + for( i = CHAR_STARTITEMARRAY; i < CheckCharMaxItem(charaindex); i ++ ) { + int haveitemindex; + ret = getStringFromIndexWithDelim( data , "|", + i - CHAR_STARTITEMARRAY+1, + buff, sizeof( buff ) ); + if( ret == FALSE ) break; + haveitemindex = atoi( buff); + if( CHAR_CHECKITEMINDEX( charaindex, haveitemindex) ) { + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( ITEM_CHECKINDEX( itemindex)) { +#ifdef _ITEM_INSLAY + char *code; + if( (code = ITEM_getChar( itemindex, ITEM_TYPECODE)) == "\0" ) { + if( strcmp( code, "\0") ) { + char token[256]; + snprintf( token, sizeof( token), "ƺ%sûȤ", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + if( ITEM_getmergeItemFromFromITEMtabl( ITEM_getInt( itemindex, ITEM_ID)) == TRUE ){ //Ƿɺϳ + ITEM_Item *itm; + itm = ITEM_getItemPointer(itemindex); + if( itm != NULL ) { + ITEM_makeItem( &items[cnt], ITEM_getInt( itemindex, ITEM_ID)); + itemindexs[cnt] = itemindex; + haveitemindexs[cnt] = haveitemindex; + // Nuke start 1026 + for (j=0;j 1 ) { + int randtable = 0; + if( items[0].data[ITEM_TYPE] == ITEM_DISH ) { + randtable = 1; + } + ret = ITEM_mergeItem( charaindex, items, cnt, 0, petid, randtable, petindex, alchemist); + if( ret == -10) + CHAR_talkToCli( charaindex, -1, "Ƿĺϳɷ", CHAR_COLORWHITE); + CHAR_setInt( charaindex, CHAR_MERGEITEMCOUNT, + CHAR_getInt( charaindex, CHAR_MERGEITEMCOUNT)+1); + for( i = 0; i < cnt; i ++ ) { +#ifdef _ITEM_PILENUMS + int pilenum=0; + int itemindex = CHAR_getItemIndex( charaindex, haveitemindexs[i]); + if( !ITEM_CHECKINDEX( itemindex) ) continue; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + pilenum -= 1; + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + if( pilenum <= 0 ){ +#endif + CHAR_setItemIndex( charaindex, haveitemindexs[i], -1); + CHAR_sendItemDataOne( charaindex, haveitemindexs[i]); + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindexs[i], +#else + ITEM_getInt( itemindexs[i], ITEM_ID), /* ʧ ة į */ +#endif + "mergedel(ϳɾĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindexs[i], ITEM_UNIQUECODE), + ITEM_getChar( itemindexs[i], ITEM_NAME), + ITEM_getInt( itemindexs[i], ITEM_ID) + ); + ITEM_endExistItemsOne( itemindexs[i]); +#ifdef _ITEM_PILENUMS + } +#endif + } + CHAR_sendItemData( charaindex, haveitemindexs, cnt); + if( ret >= 0 ) { + int rc; + int createitemindex = ITEM_makeItemAndRegist( ret); + // shan begin + if( createitemindex != -1 ){ + if( petindex != -1){ + if( CHAR_getInt(petindex, CHAR_PETFAMILY) == 1 ){ + int ownerindex = CHAR_getWorkInt(petindex, CHAR_WORKPLAYERINDEX); + if (!CHAR_CHECKINDEX(ownerindex)){ + print("ownerindex err!\n"); + return -1; + } +#ifdef _FMVER21 + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER) +#else + if( CHAR_getInt( ownerindex, CHAR_FMLEADERFLAG) != FMMEMBER_MEMBER) +#endif + { + print("\n Pet Ownerindex Error"); + return -1; + } + if( randtable == 1){ + char *p; + char charbuf1[512]="",charbuf2[1024]="",charbuf[128]=""; + char argbuf[256]; + int arg1 = 0, arg2 = 0; + if( ITEM_getInt( createitemindex, ITEM_TYPE) == 20){ + if( (p = strstr( ITEM_getChar(createitemindex, ITEM_ARGUMENT), "")) ){ + strcpy( argbuf, (p+2)); + arg1 = atoi(argbuf); + arg1 = arg1 * FOOD_MP_RATE / 100; + } + if( (p = strstr( ITEM_getChar(createitemindex, ITEM_ARGUMENT), "")) ){ + strcpy( argbuf, (p+2)); + arg2 = atoi(argbuf); + arg2 = arg2 * FOOD_HP_RATE / 100; + } + if( arg1 != 0 && arg2 != 0 ){ + sprintf( charbuf1, "%d%d", arg1, arg2); + } + else if( arg1 != 0){ + sprintf( charbuf1, "%d", arg1); + } + else if( arg2 != 0){ + sprintf( charbuf1, "%d", arg2); + } + sprintf( charbuf, "()"); + strcpy( charbuf2, ITEM_getChar( createitemindex, ITEM_EFFECTSTRING)); + strncat( charbuf2, charbuf, 10); + ITEM_setChar( createitemindex, ITEM_ARGUMENT, charbuf1); + ITEM_setChar( createitemindex, ITEM_EFFECTSTRING, charbuf2); + } + } + } + } + } + // shan end + ITEM_setInt( createitemindex, ITEM_MERGEFLG, TRUE); + if( createitemindex != -1 ) { + rc = CHAR_addItemSpecificItemIndex( charaindex, createitemindex); + if( rc >= 0 && rc < CheckCharMaxItem(charaindex)) { + CHAR_sendItemDataOne( charaindex, rc); + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + createitemindex, +#else + ITEM_getInt( createitemindex, ITEM_ID), +#endif + "mergeadd(ϳɳĵ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( createitemindex, ITEM_UNIQUECODE), + ITEM_getChar( createitemindex, ITEM_NAME), + ITEM_getInt( createitemindex, ITEM_ID) + ); + result = TRUE; + } + else { + ITEM_endExistItemsOne( createitemindex); + } + } + } + } + int MAX = 27; + for ( i = 0; i <= MAX; i++){ + CHAR_sendItemDataOne( charaindex, i); + } + return result; +} + +static int ITEM_getTableNum( int num) +{ + int i; + for( i = 0; i < arraysizeof( ItemRandTableForItem); i ++) { + if( num <= ItemRandTableForItem[i].maxnum ) { + break; + } + } + if( i == arraysizeof( ItemRandTableForItem)) i--; + return i; +} + +#ifdef _ITEM_INSLAY +#ifdef _EXPANSION_ITEM_INSLAY +int PETSKILL_ITEM_inslay( int charindex, int inslayindex, int itemindex, int num) +#else +int PETSKILL_ITEM_inslay( int charindex, int inslayindex, int itemindex) +#endif +{ + char *inslaystr , *code=NULL; + char buf1[256], buf2[256]; + char codeTemp[][32]={ "NULL", "NULL", "NULL", "NULL", "NULL" + , "NULL", "NULL", "NULL", "NULL", "NULL" + , "NULL", "NULL", "NULL", "NULL", "NULL" + , "NULL", "NULL", "NULL", "NULL", "NULL" + , "NULL", "NULL", "NULL", "NULL", "NULL"}; + char TypeName[][256]={ + "", "", "", "HP", "MP", "", "", "", "ħID" + }; + int worktyp[] = { + ITEM_MODIFYATTACK, ITEM_MODIFYDEFENCE, ITEM_MODIFYQUICK, + ITEM_MODIFYHP, ITEM_MODIFYMP, ITEM_MODIFYLUCK, + ITEM_OTHERDAMAGE, ITEM_OTHERDEFC, ITEM_MAGICID + }; + int worknum[ arraysizeof(worktyp)]; + + int i; +#ifdef _EXPANSION_ITEM_INSLAY + int MAXCANINSLAY = num; +#else +#define MAXCANINSLAY 3 +#endif + memset( worknum, 0, sizeof( worknum)); + if( !CHAR_CHECKINDEX( charindex) ) return FALSE; + if( !ITEM_CHECKINDEX( inslayindex) ) return FALSE; + if( !ITEM_CHECKINDEX( itemindex) ) return FALSE; + if( itemindex == inslayindex ) return FALSE; + if( (code = ITEM_getChar( itemindex, ITEM_TYPECODE)) == "\0" ) { + print(" ITEM_TYPECODE == NULL error !!\n"); + return FALSE; + } + if( !strcmp( code, "NULL" ) ) return FALSE; + if( (inslaystr = ITEM_getChar( inslayindex, ITEM_INLAYCODE)) == "\0" ) { + print(" ITEM_INLAYCODE == NULL error !!\n"); + return FALSE; + } + + for( i = 0; i < MAXCANINSLAY; i ++ ) { + if( getStringFromIndexWithDelim( inslaystr , "|", i+1, buf1, sizeof( buf1 ) ) == TRUE ){ + if( strcmp( buf1, "\0")){ + sprintf( codeTemp[i], "%s", buf1); + } + continue; + } + break; + } + + for( i = 0; i < MAXCANINSLAY; i ++ ) { + if( strcmp( codeTemp[i], "NULL") ) continue; + sprintf( codeTemp[i], "%s", code); + break; + } + if( i == MAXCANINSLAY ) { + char token[256]; + sprintf( token, "Ѿ%dŻ%dϡ", MAXCANINSLAY, MAXCANINSLAY); + + CHAR_talkToCli( charindex, -1, token, CHAR_COLORYELLOW); + return FALSE; + } + + memset( buf2, 0, sizeof( buf2)); + sprintf( buf2, "%s|%s|%s|%s|%s|" + "%s|%s|%s|%s|%s|" + "%s|%s|%s|%s|%s|" + "%s|%s|%s|%s|%s|" + "%s|%s|%s|%s|%s" + , codeTemp[0], codeTemp[1], codeTemp[2], codeTemp[3], codeTemp[4] + , codeTemp[5], codeTemp[6], codeTemp[7], codeTemp[8], codeTemp[9] + , codeTemp[10], codeTemp[11], codeTemp[12], codeTemp[13], codeTemp[14] + , codeTemp[15], codeTemp[16], codeTemp[17], codeTemp[18], codeTemp[19] + , codeTemp[20], codeTemp[21], codeTemp[22], codeTemp[23], codeTemp[24]); +// print("buf2:%s\n", buf2); + ITEM_setChar( inslayindex, ITEM_INLAYCODE, buf2); + + for( i=0; i 0 ) { //ħ ID + int magicid,mp; + magicid = ITEM_getInt( itemindex, ITEM_MAGICID); + ITEM_setInt( inslayindex, ITEM_MAGICID, magicid); + mp = ITEM_getInt( itemindex, ITEM_MAGICUSEMP ); + ITEM_setInt( inslayindex, ITEM_MAGICUSEMP, mp); + } + for( i=ITEM_FIRSTFUNCTION; i 0 ) { //ȡħ + int marray = MAGIC_getMagicArray( ITEM_getInt( inslayindex, ITEM_MAGICID)); + if( marray != -1 ){ + if( (magicname = MAGIC_getChar( marray, MAGIC_NAME)) != NULL ){ + sprintf( Mname, "%s", magicname); + } + } + ITEM_setInt( inslayindex, ITEM_MAGICID, ITEM_getInt( inslayindex, ITEM_MAGICID)); + } + sprintf( secretname, "%s%s%d %s%s%d %s%s%d %s%s%d %s%s%d %s%s%d %s%s%d %s", + TypeName[0],(worknum[0]>=0)?"+":"",worknum[0], + TypeName[1],(worknum[1]>=0)?"+":"",worknum[1], + TypeName[2],(worknum[2]>=0)?"+":"",worknum[2], + TypeName[3],(worknum[3]>=0)?"+":"",worknum[3], + TypeName[4],(worknum[4]>=0)?"+":"",worknum[4], + TypeName[6],(worknum[6]>=0)?"+":"",worknum[6], + TypeName[7],(worknum[7]>=0)?"+":"",worknum[7], Mname); + ITEM_setChar( inslayindex, ITEM_EFFECTSTRING, secretname); + } + + return TRUE; +} + +#endif + +#ifdef _PETSKILL_FIXITEM +int PETSKILL_ITEM_FixItem( int charindex, int fixindex, int *itemindex) +{ + int index, i; + char *buf2; + int crushes, maxcrushes; +#define MAXFIXNUM 2 + index = 0; + for( i=0; i= 5 ){ +#ifdef _ITEM_FIXALLBASE + char *ITEM_ARG = ITEM_getChar( index, ITEM_ARGUMENT); + if( ITEM_ARG != "\0" && !strcmp( ITEM_ARG, "FIXITEMALL") ){ + }else{ +#endif + CHAR_talkToCli( charindex, -1, "ϲ", CHAR_COLORYELLOW); + return FALSE; +#ifdef _ITEM_FIXALLBASE + } +#endif + } + + crushes = ITEM_getInt( fixindex, ITEM_DAMAGECRUSHE); + maxcrushes = ITEM_getInt( fixindex, ITEM_MAXDAMAGECRUSHE); + if( crushes >= (maxcrushes*0.80) ) { + char buff[256]; + sprintf( buff, "%sû𻵵Ҫ޸", ITEM_getChar( fixindex, ITEM_NAME)); + CHAR_talkToCli( charindex, -1, buff, CHAR_COLORYELLOW); + return FALSE; + }else { + char *buf1; + if( maxcrushes < 500 ){ + CHAR_talkToCli( charindex, -1, "ƷѲ޸", CHAR_COLORYELLOW); + return FALSE; + } + if( crushes <= 0 ) return FALSE; + //maxcrushes = maxcrushes*0.99; + crushes = maxcrushes; + ITEM_setInt( fixindex, ITEM_DAMAGECRUSHE, crushes); + //ITEM_setInt( fixindex, ITEM_MAXDAMAGECRUSHE, maxcrushes); + + // + buf1 = ITEM_getChar( fixindex, ITEM_SECRETNAME); + if( strstr( buf1, "(") != 0 ) { + char buf5[256]; + if( getStringFromIndexWithDelim( buf1,"(",1, buf5, sizeof( buf5)) != FALSE ) { + sprintf( buf1, buf5); + } + } + ITEM_setChar( fixindex, ITEM_SECRETNAME, buf1); + ITEM_setInt( fixindex, ITEM_CRUSHLEVEL, 0); + } + return TRUE; +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile new file mode 100755 index 0000000..1f4584b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile @@ -0,0 +1,224 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libitem.a + +SRC=item.c item_event.c item_gen.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +item.o: item.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/battle.h ../include/trade.h \ + ../include/item.h ../include/buf.h ../include/function.h \ + ../include/configfile.h ../include/magic_base.h ../include/autil.h \ + ../include/longzoro/version.h ../include/profession_skill.h +item_event.o: item_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/common.h \ + ../include/configfile.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/battle_event.h \ + ../include/item.h ../include/item_event.h ../include/object.h \ + ../include/anim_tbl.h ../include/magic.h ../include/chatmagic.h \ + ../include/handletime.h ../include/log.h ../include/family.h \ + ../include/util.h ../include/encount.h ../include/battle.h \ + ../include/trade.h ../include/battle_item.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/net.h ../include/pet.h \ + ../include/readmap.h ../include/npcutil.h ../include/enemy.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/char_talk.h ../include/battle_magic.h ../include/pet_skill.h \ + ../include/npc_poolitemshop.h ../include/npc_freepetskillshop.h \ + ../include/mylua/function.h ../include/profession_skill.h \ + ../include/npc_petshop.h ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/../lua/lua.h \ + ../include/../lua/lauxlib.h /usr/include/assert.h \ + ../include/npc_lua_interface.h +item_gen.o: item_gen.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/ctype.h \ + /usr/include/math.h /usr/include/bits/huge_val.h \ + /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \ + ../include/autil.h ../include/version.h ../include/configfile.h \ + ../include/util.h /usr/include/sys/time.h ../include/buf.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/item.h ../include/item_gen.h ../include/enemy.h \ + ../include/log.h ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/family.h \ + ../include/magic_base.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile.bak new file mode 100755 index 0000000..1f4584b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/item/makefile.bak @@ -0,0 +1,224 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libitem.a + +SRC=item.c item_event.c item_gen.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +item.o: item.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/battle.h ../include/trade.h \ + ../include/item.h ../include/buf.h ../include/function.h \ + ../include/configfile.h ../include/magic_base.h ../include/autil.h \ + ../include/longzoro/version.h ../include/profession_skill.h +item_event.o: item_event.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/common.h \ + ../include/configfile.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/battle_event.h \ + ../include/item.h ../include/item_event.h ../include/object.h \ + ../include/anim_tbl.h ../include/magic.h ../include/chatmagic.h \ + ../include/handletime.h ../include/log.h ../include/family.h \ + ../include/util.h ../include/encount.h ../include/battle.h \ + ../include/trade.h ../include/battle_item.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/net.h ../include/pet.h \ + ../include/readmap.h ../include/npcutil.h ../include/enemy.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + ../include/char_talk.h ../include/battle_magic.h ../include/pet_skill.h \ + ../include/npc_poolitemshop.h ../include/npc_freepetskillshop.h \ + ../include/mylua/function.h ../include/profession_skill.h \ + ../include/npc_petshop.h ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/../lua/lua.h \ + ../include/../lua/lauxlib.h /usr/include/assert.h \ + ../include/npc_lua_interface.h +item_gen.o: item_gen.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/ctype.h \ + /usr/include/math.h /usr/include/bits/huge_val.h \ + /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \ + ../include/autil.h ../include/version.h ../include/configfile.h \ + ../include/util.h /usr/include/sys/time.h ../include/buf.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/item.h ../include/item_gen.h ../include/enemy.h \ + ../include/log.h ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/family.h \ + ../include/magic_base.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/link.c b/石器时代服务器端最新完整源代码/Serv/gmsv/link.c new file mode 100644 index 0000000..8bd2066 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/link.c @@ -0,0 +1,135 @@ +#include +#include "version.h" +#include "link.h" +#include "buf.h" + +/* + * ¦ + * top á + * ߯Ի + */ +BOOL Nodeappendtail( Node** top , Node* add ) +{ + Node* c; /**/ + Node* next; /*ޥá*/ + + /*NULL*/ + if( *top == NULL ){ + *top = allocateMemory( sizeof( Node ) ); + if( *top== NULL ) return FALSE; + (*top)->next = NULL; /*巴 */ + (*top)->size = add->size; /*Ӯ綰*/ + (*top)->val = add->val; /*̼*/ + return TRUE; + } + + for( c = *top ; c->next ; c = c->next ); /* c ë */ + next = allocateMemory( sizeof(Node) ); + if( next == NULL )return FALSE; + c->next = next; /* nextëɬ */ + next->next = NULL; /*巴 */ + next->val = add->val; /*̼*/ + next->size = add->size; /*Ӯ綰*/ + return TRUE; +} + + + + +/* + * ͼ年 + * ¦ + * top á + * ߯Ի + */ +BOOL Nodeappendhead( Node** nowtop , Node* add ) +{ + Node* newtop; /*ޥ */ + + /*NULL*/ + if( *nowtop == NULL ){ + *nowtop = allocateMemory( sizeof( Node ) ); + if( *nowtop == NULL ) return FALSE; + (*nowtop)->next = NULL; /*巴 */ + (*nowtop)->size = add->size; /*Ӯ綰*/ + (*nowtop)->val = add->val; /*̼*/ + return TRUE; + } + + /* + * ޥáë + */ + newtop = allocateMemory( sizeof(Node) ); + newtop->next = *nowtop; + newtop->val = add->val; + newtop->size = add->size; + *nowtop = newtop; + return TRUE; +} + + + + +/* + * ¦ + * ret Իá + * ߯Ի + */ +BOOL Noderemovehead( Node** top , Node* ret) +{ + Node* newtop; /*ޥ ئá*/ + + if( *top == NULL )return FALSE; + + ret->val = (*top)->val; + ret->size = (*top)->size; + newtop = (*top)->next; + freeMemory( *top ); + *top = newtop; + + return TRUE; +} + + + + + +/* + * ¦ + * ret Իá + * ߯Ի + */ +BOOL Noderemovetail( Node** top , Node* ret) +{ + Node* c; /**/ + Node* c1; /* йƥ c->nextë϶*/ + + if( *top == NULL )return FALSE; + + c = *top; /*ɬ*/ + c1 = c->next; /*ɬ*/ + while(1){ + if( c1->next == NULL ) + /* + * ƥ c1 + * | + * | next |---->+------+ + * |------| | next |---->NULL + * | | +------+ + * +------+ | | + * +------+ + *ئȻ + */ + break; + c=c->next; + c1=c->next; + } + c->next = NULL; /*c1ؤּë¼ƥnextNULL*/ + /**/ + ret->val = c1->val; + ret->size = c1->size; + + freeMemory( c1 ); + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/log.c b/石器时代服务器端最新完整源代码/Serv/gmsv/log.c new file mode 100644 index 0000000..83bbc93 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/log.c @@ -0,0 +1,1224 @@ +#include "version.h" +#include +#include +#include +#include + +#include "common.h" +#include "util.h" +#include "log.h" +#include "handletime.h" +#include "net.h" +#include "char_base.h" + +/* + * + * ƥئּ̤ļ̫fopen(..,"w") + * by ringo + */ + +struct tagLogconf{ + char* label; + char* entry; + char filename[256]; + FILE* f; + BOOL append; /* append ¾̤ļ̫SEEK_SET¾ */ +}LogConf[LOG_TYPE_NUM]={ + { "TALK: ", "talklog" ,"", NULL , TRUE}, + { "PROC: ", "proc" , "" , NULL , FALSE}, + { "ITEM: ", "itemlog" ,"", NULL , TRUE}, + { "STONE: ", "stonelog" ,"", NULL , TRUE}, + { "PET: ", "petlog" ,"", NULL , TRUE}, + { "TENSEI: ", "tenseilog" ,"", NULL , TRUE}, + { "KILL: ", "killlog","",NULL,TRUE}, + // CoolFish: 2001/4/19 + { "TRADE: ", "tradelog", "", NULL, TRUE}, + // Arminius: 2001/6/14 + { "HACK: ", "hacklog", "", NULL, TRUE}, + // Nuke: 0626 Speed + { "SPEED: ", "speedlog", "", NULL, TRUE}, + // CoolFish: FMPopular 2001/9/12 + { "FMPOP: ", "fmpoplog", "", NULL, TRUE}, + // Robin 10/02 + { "FAMILY: ", "familylog", "", NULL, TRUE}, + // Shan 11/02 + { "GM: ", "gmlog", "", NULL, TRUE}, + +#ifdef _GAMBLE_ROULETTE + { "", "gamblelog", "", NULL, TRUE}, +#endif + { "LOGIN: ", "loginlog", "", NULL, TRUE}, + { "", "pettranslog", "", NULL, TRUE}, +//Syu ׯ԰սʤLog + { "FMPKRESULT: ", "fmpkresultlog" ,"", NULL , TRUE}, + +// Syu ADD дȡLog () + { "BANKSTONELOG: ", "bankstonelog" ,"", NULL , TRUE}, + + { "ACMESSAGE: ", "acmessagelog" ,"", NULL , TRUE}, + { "PKCONTEND:", "pkcontendlog", "", NULL, TRUE}, +#ifdef _STREET_VENDOR + { "STREETVENDOR: ", "StreetVendorlog" ,"", NULL , TRUE}, +#endif +#ifdef _ANGEL_SUMMON + { "ANGEL: ", "angellog" ,"", NULL , TRUE}, +#endif +#ifdef _NEW_MANOR_LAW + { "FMPKGETMONEY: ","FMPKGetMoneylog","",NULL,TRUE}, +#endif + { "FMFAMESHOP: ","FMFameShoplog","",NULL,TRUE}, +#ifdef _AMPOINT_LOG + { "AMPOINT: ", "ampoint" ,"", NULL , TRUE}, +#endif +#ifdef _SQL_VIPPOINT_LOG + { "SQLVIPOINT: ", "sqlvippoint" ,"", NULL , TRUE}, +#endif +#ifdef _NETLOG_ + { "LOGOUT: ", "Tplaylog" ,"", NULL , TRUE}, +#endif +}; + + +tagWarplog warplog[MAXMAPNUM]; +tagWarpCount warpCount[MAXMAPLINK]; + +/*------------------------------------------------------------ + * ¦ + * ߯Ի + ------------------------------------------------------------*/ +static BOOL readLogConfFile( char* filename ) +{ + FILE* f; + char line[256]; + char basedir[256]; + int linenum=0; + + { + char* r; + r = rindex( filename, '/' ); + if( r == NULL )snprintf(basedir,sizeof(basedir),"." ); + else{ + memcpy( basedir,filename,r-filename ); + basedir[r-filename] = '\0'; + } + } + + f = fopen( filename , "r"); + if( f == NULL ){ + print( "Can't open %s\n" , filename ); + return FALSE; + } + while( fgets( line, sizeof( line ) ,f ) ){ + char firstToken[256]; + int i; + BOOL ret; + + linenum++; + deleteWhiteSpace(line); /* remove whitespace */ + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); /* remove tail newline */ + ret = getStringFromIndexWithDelim( line , "=", 1, firstToken, sizeof(firstToken) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + for( i=0 ; i= LOG_TYPE_NUM )return; + if( LogConf[logtype].append ){ + if( !LogConf[logtype].f )return; + fputs( LogConf[logtype].label, LogConf[logtype].f); + va_start(arg,format); + vfprintf( LogConf[logtype].f,format,arg ); + va_end( arg ); + fputc( '\n', LogConf[logtype].f ); + } else { + FILE *f = fopen( LogConf[logtype].filename ,"w" ); + if( !f ) return; + fputs(LogConf[logtype].label , f ); + va_start(arg,format); + vfprintf( f , format,arg); + va_end(arg); + fputc( '\n' , f); + fclose(f); + } +} + +BOOL initLog( char* filename ) +{ + if( readLogConfFile( filename ) == FALSE )return FALSE; + openAllLogFile(); + return TRUE; +} + +//Syu ׯ԰սʤLog +void Logfmpk( + char *winner, int winnerindex, int num1, + char *loser, int loserindex, int num2, + char *date, char *buf1, char *buf2, int flg) +{ + switch( flg){ + case 1: + { + struct tm tm1; + char buf[256]; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + printl( LOG_FMPKRESULT, "\nFMPK: [%s]ص:%s %s(%d) ԼսҪ %s(%d) time:%s", + buf1, buf2, + winner, winnerindex, loser, loserindex, buf); + } + break; + case 2: + printl( LOG_FMPKRESULT, "\nFMPK: Winner %s(%d)=>%d Loser %s(%d)=>%d time:%s", + winner, winnerindex, num1, + loser, loserindex, num2 ,date); + break; + } +} + +#ifdef _NEW_MANOR_LAW +void LogFMPKGetMomey(char *szFMName,char *szID,char *szCharName,int iMomentum,int iGetMoney,int iDest) +{ + struct tm tm1; + char szDest[3][6] = {"","",""}; + + if(iDest < 0 || iDest > 1) iDest = 2; + memcpy(&tm1,localtime((time_t*)&NowTime.tv_sec),sizeof(tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl(LOG_FMPK_GETMONEY,"FMName:%s\tID:%s\tName:%s\tMomentum:%d\tGetMoney:%d\tAddTo:%s\t%s", + szFMName,szID,szCharName,iMomentum,iGetMoney,szDest[iDest],buf); +} +#endif + + +void LogFMFameShop(char *szFMName,char *szID,char *szCharName,int iFame,int iCostFame) +{ + struct tm tm1; + + memcpy(&tm1,localtime((time_t*)&NowTime.tv_sec),sizeof(tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl(LOG_FM_FAME_SHOP,"FMName:%s\tID:%s\tName:%s\tFame:%d\tCostFame:%d\t%s", + szFMName,szID,szCharName,iFame,iCostFame,buf); +} + +void LogAcMess( int fd, char *type, char *mess ) +{ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + if( strstr( mess, "Broadcast") != NULL ) return; + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_ACMESS, "%d %s [%s] %s" , fd, type, mess, buf); +} + +void LogItem( + char *CharName, /* ƽҷ */ + char *CharID, /* ƽҷID */ + int ItemNo, /* ʧ ة į */ + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + char *uniquecode, // shan 2001/12/14 + char *itemname, int itemID +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_ITEM, "%s\t%s\t%d(%s)=%s,(%d,%d,%d)%s,%s" , CharName, CharID, + itemID, itemname, + Key, floor, x, y, buf, uniquecode ); + +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + }else{ + char token[1024]; + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + sprintf( token, "%s\t%s\t%d(%s)=%s,(%d,%d,%d)%s,%s" , CharName, CharID, itemID, itemname, Key, floor, x, y, buf, uniquecode ); + + saacproto_OtherSaacLink_send(osfd, LogConf[LOG_ITEM].filename, token); + } +#endif + +} +void LogPkContend( char *teamname1, char *teamname2, + int floor, + int x, + int y, + int flg +) +{ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + if( flg == 0 ) { + printl( LOG_PKCONTEND, "[%32s ʤ %32s],(%5d,%4d,%4d)%s" , + teamname1, teamname2, + floor, x, y, buf); + }else{ + printl( LOG_PKCONTEND, "Msg:[%s],(%5d,%4d,%4d)%s" , + teamname1, floor, x, y, buf); + } + +} + +void LogPetTrans( + char *cdkey, char *uniwuecde, char *uniwuecde2, + char *CharName, int floor, int x, int y, + int petID1, char *PetName1, int petLV, int petrank, int vital1, int str1, int tgh1, int dex1, int total1, + int petID2, char *PetName2, int vital2, int str2, int tgh2, int dex2, int total2, + int work0, int work1, int work2, int work3, int ans, int trans + ){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( PETTRANS, "\n*PETTRANS cdkey=%s unid=%s munid=%s %s %s %d=%s LV:%d rand:%d trans:%d :[ %d, %d, %d, %d]=%d %d=%s :[ %d, %d, %d, %d]=%d [ %d, %d, %d, %d]=%d\n", + cdkey, uniwuecde, uniwuecde2, + CharName, buf, + petID1, PetName1, petLV, petrank, trans, vital1, str1, tgh1, dex1, total1, + petID2, PetName2, vital2, str2, tgh2, dex2, total2, + work0, work1, work2, work3, ans ); +} +/*------------------------------------------------------------ + * + * ʸë + * +-------------------------------------------------------------*/ +void LogPet( + char *CharName, /* ƽҷ */ + char *CharID, + char *PetName, + int PetLv, + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + char *uniquecode // shan 2001/12/14 +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + // shan 2001/12/14 + //printl( LOG_PET, "%s\t%s\t%s:%d=%s,(%d,%d,%d)%s" , CharName, CharID, + // PetName, PetLv, + // Key, + // floor, x, y, buf ); + + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_PET, "%s\t%s\t%s:%d=%s,(%d,%d,%d)%s,%s" , CharName, CharID, + PetName, PetLv, + Key, + floor, x, y, buf, uniquecode); + +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + }else{ + char token[1024]; + sprintf( token, "%s\t%s\t%s:%d=%s,(%d,%d,%d)%s,%s" , CharName, CharID, PetName, PetLv, Key, floor, x, y, buf, uniquecode); + + saacproto_OtherSaacLink_send(osfd, LogConf[LOG_PET].filename, token); + } +#endif +} + +#ifdef _STREET_VENDOR +void LogStreetVendor( + char *SellName, + char *SellID, + char *BuyName, + char *BuyID, + char *ItemPetName, + int PetLv, //ǵߴֵΪ -1 + int iPrice, + char *Key, + int Sfloor, + int Sx, + int Sy, + int Bfloor, + int Bx, + int By, + char *uniquecode +){ + struct tm tm1; + memcpy(&tm1,localtime((time_t *)&NowTime.tv_sec),sizeof(tm1)); + + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl(LOG_STREET_VENDOR,"Sell:%s\t%s\tBuy:%s\t%s\tName=%s:Lv=%d|Price:%d,%s,SXY(%d,%d,%d)BXY(%d,%d,%d)%s,%s",SellName,SellID,BuyName,BuyID, + ItemPetName,PetLv,iPrice,Key,Sfloor,Sx,Sy,Bfloor,Bx,By,buf,uniquecode); + + +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + }else{ + char token[1024]; + sprintf( token, "Sell:%s\t%s\tBuy:%s\t%s\tName=%s:Lv=%d|Price:%d,%s,SXY(%d,%d,%d)BXY(%d,%d,%d)%s,%s", + SellName,SellID,BuyName,BuyID,ItemPetName,PetLv,iPrice,Key,Sfloor,Sx,Sy,Bfloor,Bx,By,buf,uniquecode); + + saacproto_OtherSaacLink_send(osfd, LogConf[LOG_STREET_VENDOR].filename, token); + } +#endif + +} +#endif + +void LogBankStone( + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + int meindex, + int Gold, /* ź */ + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y, + int my_gold, + int my_personagold + +){ + struct tm tm1; + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + + printl( LOG_STONE, "%s:%s\ts:%d=%s,(%d,%d,%d)%s <>" , + CharId, CharName, Gold, Key, + floor, x, y, buf , my_gold, my_personagold ); +} + +void LogPetPointChange( + char * CharName, char *CharID, char *PetName, int petindex, int errtype, + int PetLv, char *Key,int floor, int x, int y) { + + struct tm tm1; + int vit,str,tgh,dex; + int l_vit,l_str,l_tgh,l_dex; + int pet_ID, levellvup; + + pet_ID = CHAR_getInt( petindex, CHAR_PETID ); + vit = CHAR_getInt( petindex, CHAR_VITAL ); + str = CHAR_getInt( petindex, CHAR_STR ); + tgh = CHAR_getInt( petindex, CHAR_TOUGH ); + dex = CHAR_getInt( petindex, CHAR_DEX ); + levellvup = CHAR_getInt( petindex, CHAR_ALLOCPOINT); + + l_vit = (levellvup >> 24); + l_str = (levellvup >> 16)&0xff; + l_tgh = (levellvup >> 8 )&0xff; + l_dex = (levellvup >> 0 )&0xff; + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_PET, "%s\t%s\t%s:%d=%s,(%d,%d,%d)%s,err:%d %d<<%d,%d,%d,%d>>lvup<<%d,%d,%d,%d>>" , + CharName, CharID, PetName, PetLv, Key, floor, x, y, buf , errtype, + pet_ID ,vit,str,tgh,dex,l_vit,l_str,l_tgh,l_dex); +} + +/*------------------------------------------------------------ + * + * Ϸë + * +-------------------------------------------------------------*/ +void LogTensei( + char *CharName, /* ƽҷ */ + char *CharID, + char *Key, /* ƽ */ + int level, //ì + int transNum, //Ϸ + int quest, //;޵ + int home, //컩 + int item, // ʧ ة Ի + int pet, // ʸ Ի + int vital, // Vital + int b_vital, // vital + int str, // str + int b_str, // str + int tgh, // + int b_tgh, // + int dex, // + int b_dex // +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_TENSEI, "%s\t%s\t%s=(%d,%d,%d,%d,%d,%d),(vi=%d->%d,str=%d->%d,tgh=%d->%d,dex=%d->%d),(%d,%d)" + ,CharName, + CharID, + Key, + level, + transNum, + quest, + home, + item, + pet, + vital, + b_vital, + str, + b_str, + tgh, + b_tgh, + dex, + b_dex, + buf + ); +} + +// LOG_TALK +void LogTalk( + char *CharName, /* ƽҷ */ + char *CharID, + int floor, /* */ + int x, + int y, + char *message +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_TALK, "%2d:%2d\t%s\t%s\t%d_%d_%d\tT=%s" , + buf, + (CharID==NULL) ? "(null)" :CharID, + (CharName==NULL) ? "(null)" :CharName, + floor, x, y, + message ); + + +} +/*------------------------------------------------------------ + * ɬñ׻Ȼͻ̻ëʧ + * ̻ﷴͷľئľͷ + * ¦ struct tm + * ئ + * ߯Ի + * װ̻P + ------------------------------------------------------------*/ +void backupAllLogFile( struct tm *ptm ) +{ + int i; + char szBuffer[256]; + + for( i=0 ; itm_year+1900, ptm->tm_mon+1, ptm->tm_mday ); + + if( LogConf[i].f != NULL ){ + /* ľͷ */ + fclose( LogConf[i].f ); + /* ة */ + rename( LogConf[i].filename, szBuffer ); + /* ̫ */ + LogConf[i].f = fopen( LogConf[i].filename , "a" ); + + }else{ + /* ة */ + rename( LogConf[i].filename, szBuffer ); + /* ̫ */ + LogConf[i].f = fopen( LogConf[i].filename , "a" ); + + } + } +} +/*------------------------------------------------------------ +* +* ë +* +-------------------------------------------------------------*/ +// Syu ADD дȡLog () +void LogFamilyBankStone( + char *CharName, + char *CharId, + int Gold, + int MyGold, + char *Key, + int floor, + int x, + int y, + int banksum +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_BANKSTONELOG, "%s:%s\t%d=%s [%d] CHAR_GOLD(%d),(%d,%d,%d)%s" , CharId, CharName, Gold, Key,banksum, + MyGold, floor, x, y, buf ); + print("\n%s:%s\t%d=%s [%d] CHAR_GOLD(%d),(%d,%d,%d)%s\n" , CharId, CharName, Gold, Key,banksum, + MyGold, floor, x, y, buf ); +} + +void LogStone( + int TotalGold, + char *CharName, /* ƽҷ */ + char *CharId, /* ǡID */ + int Gold, /* ź */ + int MyGold, + char *Key, /* ƽ */ + int floor, /* */ + int x, + int y +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + + if(TotalGold == -1){ + printl( LOG_STONE, "%s:%s\t%d=%s TOTAL_GOLD(%d),CHAR_GOLD(%d),(%d,%d,%d)%s" , CharId, CharName, Gold, Key,TotalGold, + MyGold, floor, x, y, buf ); + } + else{ + printl( LOG_STONE, "%s:%s\t%d=%s CHAR_GOLD(%d),(%d,%d,%d)%s" , CharId, CharName, Gold, Key, + MyGold, floor, x, y, buf ); + } +} + +//ttom 12/26/2000 print the kill log +void LogKill( + char *CharName, + char *CharId, + char *CharPet_Item +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec, + tm1.tm_sec); + + printl( LOG_KILL, "Name=%s:ID=%s\t%s %s" ,CharName,CharId, CharPet_Item, + buf ); +} +//ttom + +// CoolFish: Trade 2001/4/19 +void LogTrade(char *message) +{ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl( LOG_TRADE, "%s %s" , message, buf ); +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + }else{ + char token[1024]; + sprintf( token, "%s %s" , message, buf ); + + saacproto_OtherSaacLink_send(osfd, LogConf[LOG_TRADE].filename, token); + } +#endif +} + +// CoolFish: Family Popular 2001/9/12 +void LogFMPOP(char *message) +{ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min); + + printl( LOG_FMPOP, "%s %s" , message, buf ); +} + +// Arminius 2001/6/14 +char hackmsg[HACK_TYPE_NUM][4096]= + { "??? ʲҲûз", + "޷ȡͨѶЭ", + "յ޷ʶͨѶЭ", + "", + "HPΪ", + }; + +void logHack(int fd, int errcode) +{ + struct tm tm1; + char cdkey[4096]; + char charname[4096]; + unsigned long ip; + char ipstr[4096]; + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + CONNECT_getCdkey( fd, cdkey, 4096); + CONNECT_getCharname( fd, charname, 4096); + ip=CONNECT_get_userip(fd); + sprintf(ipstr,"%d.%d.%d.%d", + ((unsigned char *)&ip)[0], + ((unsigned char *)&ip)[1], + ((unsigned char *)&ip)[2], + ((unsigned char *)&ip)[3]); + if ((errcode<0) || (errcode>=HACK_TYPE_NUM)) errcode=HACK_NOTHING; + + printl( LOG_HACK, "%s %s ip=%s cdkey=%s charname=%s", + buf, hackmsg[errcode], ipstr, cdkey, charname); +} + +// Nuke 0626 +void logSpeed(int fd) +{ + struct tm tm1; + char cdkey[4096]; + char charname[4096]; + unsigned long ip; + char ipstr[4096]; + + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + CONNECT_getCdkey( fd, cdkey, 4096); + CONNECT_getCharname( fd, charname, 4096); + ip=CONNECT_get_userip(fd); + sprintf(ipstr,"%d.%d.%d.%d", + ((unsigned char *)&ip)[0], + ((unsigned char *)&ip)[1], + ((unsigned char *)&ip)[2], + ((unsigned char *)&ip)[3]); + printl( LOG_SPEED, "%s ip=%s cdkey=%s charname=%s", + buf, ipstr, cdkey, charname); +} + +// Shan +void LogGM( + char *CharName, //ɫ + char *CharID, //ID + char *Message, //ָ + int floor, + int x, + int y +) +{ + struct tm tm1; + + memcpy(&tm1,localtime((time_t *)&NowTime.tv_sec),sizeof(tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + printl(LOG_GM,"%s\t%s\t%s\t(%d,%d,%d)\t%s", + CharName,CharID,Message,floor,x,y,buf); + +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + }else{ + char token[1024]; + sprintf( token, "%s\t%s\t%s\t(%d,%d,%d)\t%s", CharName,CharID,Message,floor,x,y,buf); + + saacproto_OtherSaacLink_send(osfd, LogConf[LOG_GM].filename, token); + } +#endif + +} + +// Robin 10/02 +void LogFamily( + char *FMName, + int fmindex, + char *charName, + char *charID, + char *keyWord, + char *data +){ + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + // CoolFish: 2001/10/11 log time + printl( LOG_FAMILY, "%s\t%d\t%s\t%s\t= %s, %s %s", + FMName, fmindex, charName, charID, + keyWord, data, buf ); +} + +#ifdef _GAMBLE_ROULETTE +void LogGamble( + char *CharName, //ɫ + char *CharID, //ID + char *Key, //˵ + int floor, + int x, + int y, + int player_stone, //ӵнǮ + int Gamble_stone, //ע + int get_stone, // + int Gamble_num, + int flg //flg = 1 2 ׯ +) +{ + struct tm tm1; + memcpy(&tm1,localtime((time_t *)&NowTime.tv_sec),sizeof(tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + + if( flg == 1 ) { + printl(LOG_GAMBLE,"%s\t%s\t TYPE:%s <>\t(%d,%d,%d)-%s GAMBLENUM=%d", + CharName,CharID,Key, player_stone, Gamble_stone, get_stone, floor,x,y,buf, Gamble_num); + }else if( flg == 2 ) { + printl(LOG_GAMBLE,"%s\tROULETTE MASTER\t TYPE:%s <>\t(%d,%d,%d)-%s", + CharName,Key, player_stone, floor,x,y,buf); + } +} + +#endif + +void LogLogin( + char *CharID, //ID + char *CharName, //ɫ + int saveIndex, + char *ipadress +#ifdef _NEWCLISETMAC + ,char *mac +#endif +) +{ + struct tm tm1; + + memcpy(&tm1,localtime((time_t *)&NowTime.tv_sec),sizeof(tm1)); + char buf[256]; + sprintf( buf, " (%d-%d-%d %d:%d:%d) " , tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + +#ifdef _NEWCLISETMAC + printl(LOG_LOGIN,"%s\t%s\ti=%d\t%s\t%s\t%s\t%s", + CharID,CharName,saveIndex,getGameservername(),ipadress,mac,buf); +#else + printl(LOG_LOGIN,"%s\t%s\ti=%d\t%s\t%s\t%s", + CharID,CharName,saveIndex,getGameservername(),ipadress,buf); +#endif +} + + +void warplog_to_file() +{ + int i =0; + char outbuf[128]; + FILE *f; + f = fopen("log/warp1.log" ,"w" ); + if( !f ) return; + + for( i=0; i $OUT +echo "#define SERVER_VERSION \"ʯʱر "$(date +%Y%m%d%H:%M:%S)"\"" >> $OUT +echo "#else" >> $OUT +echo "#ifdef _VERSION_25" >> $OUT +echo "#define SERVER_VERSION \"All Blue's Saserver 2.5 "$(date +%Y%m%d%H:%M:%S)"\"" >> $OUT +echo "#else" >> $OUT +echo "#define SERVER_VERSION \"All Blue's Saserver 8.0 "$(date +%Y%m%d%H:%M:%S)"\"" >> $OUT +echo "#endif" >> $OUT +echo "#endif" >> $OUT diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/characters.c b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/characters.c new file mode 100644 index 0000000..ee5e6e9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/characters.c @@ -0,0 +1,927 @@ +#include +#include "version.h" +#include "common.h" +#include "longzoro/characters.h" +#include "readmap.h" +#include "saacproto_cli.h" +#include "char_base.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +extern int CheckCharMaxItemChar(Char* ch); +#ifdef _CHARADATA_SAVE_SQL +#include "item.h" +char CHAR_list_info1_int[][64]={ + "CHAR_DATAPLACENUMBER", + "CHAR_BASEIMAGENUMBER", + "CHAR_BASEBASEIMAGENUMBER", + "CHAR_FACEIMAGENUMBER", + "CHAR_FLOOR", + "CHAR_X", + "CHAR_Y", + "CHAR_DIR", + "CHAR_LV", + "CHAR_GOLD", + + "CHAR_HP", + "CHAR_MP", + "CHAR_MAXMP", + + "CHAR_VITAL", + "CHAR_STR", + "CHAR_TOUGH", + "CHAR_DEX", + + "CHAR_CHARM", + "CHAR_LUCK", + "CHAR_EARTHAT", + "CHAR_WATERAT", + "CHAR_FIREAT", + "CHAR_WINDAT" +}; + +char CHAR_list_info2_int[][64]={ + "CHAR_SLOT", + "CHAR_CRITIAL", + "CHAR_COUNTER", + "CHAR_RARE", + "CHAR_RADARSTRLENGTH", + "CHAR_CHATVOLUME", + "CHAR_MERCHANTLEVEL", + "CHAR_HEALERLEVEL", + "CHAR_DETERMINEITEM", + "CHAR_INDEXOFEQTITLE", + "CHAR_POISON", + "CHAR_PARALYSIS", + "CHAR_SILENCE", + "CHAR_STONE", + "CHAR_DARKNESS", + "CHAR_CONFUSION" +}; + +char CHAR_list_count_int[][64]={ + "CHAR_LOGINCOUNT", + "CHAR_DEADCOUNT", + "CHAR_WALKCOUNT", + "CHAR_TALKCOUNT", + "CHAR_DAMAGECOUNT", + "CHAR_GETPETCOUNT", + "CHAR_KILLPETCOUNT", + "CHAR_DEADPETCOUNT", + "CHAR_SENDMAILCOUNT", + "CHAR_MERGEITEMCOUNT", + "CHAR_DUELBATTLECOUNT", + "CHAR_DUELWINCOUNT", + "CHAR_DUELLOSECOUNT", + "CHAR_DUELSTWINCOUNT", + "CHAR_DUELMAXSTWINCOUNT" +}; + +char CHAR_list_info3_int[][64]={ + "CHAR_WHICHTYPE", + "CHAR_WALKNTERVAL", + "CHAR_LOOPINTERVAL", +#ifdef _NEWOPEN_MAXEXP + "CHAR_OLDEXP", + "CHAR_EXP", +#else + "CHAR_EXP", +#endif + "CHAR_LASTTALKELDER", + "CHAR_SKILLUPPOINT", + "CHAR_LEVELUPPOINT", + "CHAR_IMAGETYPE", + "CHAR_NAMECOLOR", + "CHAR_POPUPNAMECOLOR", + "CHAR_LASTTIMESETLUCK", + "CHAR_DUELPOINT" +}; + +char CHAR_list_event_int[][64]={ + "CHAR_EVENT1", + "CHAR_EVENT2", + "CHAR_EVENT3", +#ifdef _NEWEVENT + "CHAR_EVENT4", + "CHAR_EVENT5", + "CHAR_EVENT6", +#endif +#ifdef _ADD_NEWEVENT + "CHAR_EVENT7", + "CHAR_ENDEVENT8", +#endif + + "CHAR_NOWEVENT1", + "CHAR_NOWEVENT2", + "CHAR_NOWEVENT3", +#ifdef _NEWEVENT + "CHAR_NOWEVENT4", + "CHAR_NOWEVENT5", + "CHAR_NOWEVENT6", +#endif +#ifdef _ADD_NEWEVENT + "CHAR_NOWEVENT7", + "CHAR_NOWEVENT8" +#endif +}; + +char CHAR_list_info4_int[][64]={ + "CHAR_TRANSMIGRATION", + "CHAR_TRANSEQUATION", + + "CHAR_INITDATA", + "CHAR_SILENT", + "CHAR_FMINDEX", + "CHAR_FMLEADERFLAG", + "CHAR_FMSPRITE", + "CHAR_BANKGOLD", + "CHAR_RIDEPET", + "CHAR_LEARNRIDE", +#ifdef _NEW_RIDEPETS + "CHAR_LOWRIDEPETS", +#endif + "CHAR_LIMITLEVEL", +#ifdef _PET_FUSION + "CHAR_FUSIONCODE", + "CHAR_FUSIONINDEX", + "CHAR_FUSIONRAISE", + "CHAR_FUSIONBEIT", + "CHAR_FUSIONTIMELIMIT", +#endif + +#ifdef _PERSONAL_FAME + "CHAR_FAME", +#endif + +#ifdef _NEWSAVE + "CHAR_SAVEINDEXNUMBER" +#endif +}; + +char CHAR_list_attackmagic_int[][64]={ +#ifdef _ATTACK_MAGIC + "CHAR_EARTH_EXP", + "CHAR_WATER_EXP", + "CHAR_FIRE_EXP", + "CHAR_WIND_EXP", + "CHAR_EARTH_RESIST", + "CHAR_WATER_RESIST", + "CHAR_FIRE_RESIST", + "CHAR_WIND_RESIST", + "CHAR_EARTH_ATTMAGIC_EXP", + "CHAR_WATER_ATTMAGIC_EXP", + "CHAR_FIRE_ATTMAGIC_EXP", + "CHAR_WIND_ATTMAGIC_EXP", + "CHAR_EARTH_DEFMAGIC_EXP", + "CHAR_WATER_DEFMAGIC_EXP", + "CHAR_FIRE_DEFMAGIC_EXP", + "CHAR_WIND_DEFMAGIC_EXP" +#endif +}; + +char CHAR_list_info5_int[][64]={ +#ifdef _GAMBLE_BANK + "CHAR_PERSONAGOLD", +#endif +#ifdef _DROPSTAKENEW + "CHAR_GAMBLENUM", +#endif +#ifdef _ADD_ACTION + "CHAR_ACTIONSTYLE", +#endif +#ifdef _PET_EVOLUTION + "CHAR_EVOLUTIONBASE1", + "CHAR_EVOLUTIONBASE2", + "CHAR_EVOLUTIONBASE3", + "CHAR_EVOLUTIONBASE4", +#endif + +#ifdef _FM_JOINLIMIT + "CHAR_FMTIMELIMIT" +#endif +}; + +char CHAR_list_profession_int[][64]={ +#ifdef _CHAR_PROFESSION + "PROFESSION_CLASS", + "PROFESSION_LEVEL", +// "PROFESSION_EXP", + "PROFESSION_SKILL_POINT", + "ATTACHPILE", + "PROFESSION_FIRE_P", + "PROFESSION_ICE_P", + "PROFESSION_THUNDER_P", + "PROFESSION_FIRE_R", + "PROFESSION_ICE_R", + "PROFESSION_THUNDER_R" +#endif +}; + +char CHAR_list_info6_int[][64]={ +#ifdef _ALLDOMAN + "CHAR_HEROFLOOR", +#endif +#ifdef _PETSKILL_BECOMEPIG + "CHAR_BECOMEPIG", + "CHAR_BECOMEPIG_BBI", +#endif + "CHAR_LASTLEAVETIME", +#ifdef _NEW_MANOR_LAW + "CHAR_MOMENTUM", +#endif + +#ifdef _ITEM_ADDEXP2 + "CHAR_ADDEXPPOWER", + "CHAR_ADDEXPTIME", +#endif + +#ifdef _ANGEL_SUMMON + "CHAR_HEROCNT", +#endif +#ifdef _TEACHER_SYSTEM + "CHAR_TEACHER_FAME", +#endif + +#ifdef _GM_ITEM + "CHAR_GMTIME", +#endif +#ifdef _VIP_SERVER + "CHAR_AMPOINT", +#endif +#ifdef _VIP_RIDE + "CHAR_VIPRIDE", +#endif + + "CHAR_LISTPAGE", + +#ifdef _AUTO_PK + "CHAR_AUTOPK", +#endif +#ifdef _BATTLE_PK + "CHAR_BATTLEPK", +#endif + +#ifdef _PET_BEATITUDE + "CHAR_BEATITUDE", +#endif + +#ifdef _RIDE_CF + "CHAR_LOWRIDEPETS1", +#endif + +#ifdef _ITEM_PET_LOCKED + "CHAR_LOCKED", +#endif + +#ifdef _BOUND_TIME + "CHAR_BOUNDTIME" +#endif +}; + +char CHAR_list_info_char[][64]={ + "CHAR_NAME" , + "CHAR_OWNTITLE" , + "CHAR_NPCARGUMENT", + "CHAR_OWNERCDKEY", + "CHAR_OWNERCHARANAME", + "CHAR_FMNAME", +#ifdef _UNIQUE_P_I + "CHAR_UNIQUECODE", +#endif + +#ifdef _TEACHER_SYSTEM + "CHAR_TEACHER_ID", + "CHAR_TEACHER_NAME", +#endif + +#ifdef _ITEM_SETLOVER + "CHAR_LOVE", + "CHAR_LOVERID", + "CHAR_LOVERNAME", +#endif + +#ifdef _GM_ITEM + "CHAR_GMFUNCTION", +#endif +#ifdef _NEW_NAME + "CHAR_NEWNAME" +#endif +}; + + +char CHAR_list[][64]={ + "CHAR_DATAPLACENUMBER" , + "CHAR_FACEIMAGENUMBER" , + "CHAR_LV", + "CHAR_WORKMAXHP", + "CHAR_WORKATTACKPOWER", + "CHAR_WORKDEFENCEPOWER", + "CHAR_WORKQUICK", + "CHAR_WORKFIXCHARM", + "CHAR_DUELPOINT", + "CHAR_WORKFIXEARTHAT", + "CHAR_WORKFIXWATERAT", + "CHAR_WORKFIXFIREAT", + "CHAR_WORKFIXWINDAT", + "CHAR_LOGINCOUNT", + "CHAR_NAME", + "MAP_NAME" +}; + + +char CHAR_list_item_int[][64]={ + "ITEM_ID", + "ITEM_BASEIMAGENUMBER", +// "ITEM_COST", +// "ITEM_TYPE", +// "ITEM_ABLEUSEFIELD" + "ITEM_TARGET", +// "ITEM_LEVEL", +#ifdef _ITEM_MAXUSERNUM + "ITEM_DAMAGEBREAK", +#endif +#ifdef _ITEMSET4_TXT + "ITEM_USEPILENUMS", + "ITEM_CANBEPILE", +// "ITEM_NEEDSTR", +// "ITEM_NEEDDEX", +// "ITEM_NEEDTRANS", +// "ITEM_NEEDPROFESSION", +#endif +#ifdef _TAKE_ITEMDAMAGE + "ITEM_DAMAGECRUSHE", + "ITEM_MAXDAMAGECRUSHE", +#endif +#ifdef _ADD_DEAMGEDEFC +// "ITEM_OTHERDAMAGE", +// "ITEM_OTHERDEFC", +#endif +#ifdef _SUIT_ITEM +// "ITEM_SUITCODE", +#endif +// "ITEM_ATTACKNUM_MIN", +// "ITEM_ATTACKNUM_MAX", +// "ITEM_MODIFYATTACK", +// "ITEM_MODIFYDEFENCE", + + "ITEM_MODIFYQUICK", +// "ITEM_MODIFYHP", +// "ITEM_MODIFYMP", +// "ITEM_MODIFYLUCK", + "ITEM_MODIFYCHARM", + "ITEM_MODIFYAVOID", +// "ITEM_MODIFYATTRIB", +// "ITEM_MODIFYATTRIBVALUE", + "ITEM_MAGICID", +// "ITEM_MAGICPROB", + "ITEM_MAGICUSEMP", +#ifdef _ITEMSET5_TXT +// "ITEM_MODIFYARRANGE", +// "ITEM_MODIFYSEQUENCE", +// "ITEM_ATTACHPILE", +// "ITEM_HITRIGHT", +#endif + +#ifdef _ITEMSET6_TXT +// "ITEM_NEGLECTGUARD", +#endif + "ITEM_MERGEFLG", + +#ifdef _ITEM_COLOER + "ITEM_COLOER" +#endif +}; + +char CHAR_list_item_char[][64]={ + "ITEM_NAME", + "ITEM_SECRETNAME", + "ITEM_EFFECTSTRING", + "ITEM_ARGUMENT", + "ITEM_TYPECODE" + "ITEM_INLAYCODE", + "ITEM_CDKEY", + "ITEM_FORUSERNAME", + "ITEM_FORUSERCDKEY", + "ITEM_ANGELMISSION", + "ITEM_ANGELINFO", + "ITEM_HEROINFO", + "ITEM_UNIQUECODE" +}; + +void CHAR_make_list_String( Char* ch, char *buf ) +{ + + char escapeshowstring[256]=""; + char *showstr = MAP_getfloorShowstring(ch->data[CHAR_FLOOR]); + sprintf( buf, "('%s',%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,'%s','%s')", + ch->string[CHAR_CDKEY].string, + ch->data[CHAR_SAVEINDEXNUMBER], + ch->data[CHAR_DATAPLACENUMBER], + ch->data[CHAR_FACEIMAGENUMBER], + ch->data[CHAR_LV], + ch->workint[CHAR_WORKMAXHP], + ch->workint[CHAR_WORKATTACKPOWER], + ch->workint[CHAR_WORKDEFENCEPOWER], + ch->workint[CHAR_WORKQUICK], + ch->workint[CHAR_WORKFIXCHARM], + ch->data[CHAR_DUELPOINT], + ch->workint[CHAR_WORKFIXEARTHAT], + ch->workint[CHAR_WORKFIXWATERAT], + ch->workint[CHAR_WORKFIXFIREAT], + ch->workint[CHAR_WORKFIXWINDAT], + ch->data[CHAR_AMPOINT], + ch->string[CHAR_NAME].string, + makeEscapeString( showstr , + escapeshowstring, + sizeof(escapeshowstring) ) + ); +} + +Charadata charadata; + + +int list_info1 = arraysizeof(CHAR_list_info1_int); +int list_info2 = arraysizeof(CHAR_list_info2_int); +int list_count = arraysizeof(CHAR_list_count_int); +int list_info3 = arraysizeof(CHAR_list_info3_int); +int list_event = arraysizeof(CHAR_list_event_int); +int list_info4 = arraysizeof(CHAR_list_info4_int); +int list_attackmagic = arraysizeof(CHAR_list_attackmagic_int); +int list_info5 = arraysizeof(CHAR_list_info5_int); +int list_profession = arraysizeof(CHAR_list_profession_int); +int list_info6 = arraysizeof(CHAR_list_info6_int); + +int list_info = arraysizeof(CHAR_list_info_char); + +void CHAR_make_list_int_String( Char* ch, char (*data)[64], char *buf, int start, int end ) +{ + if (!ch) return; + int i; + char token[1024]=""; + for( i = start ; i < end ; i ++ ){ + char linedata[256]=""; + sprintf( linedata, "%d", + ch->data[i] ); + if(i < end - 1){ + strcat(linedata, ","); + } + strcat( token, linedata ); + } + sprintf(buf, "('%s', %d, %s)", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], token); +} + +void CHAR_make_list_char_String( Char* ch, char (*data)[64], char *buf, int start, int end ) +{ + if (!ch) return; + int i; + char token[1024]=""; + for( i = start ; i < end ; i ++ ){ + char linedata[256]=""; + sprintf( linedata, "'%s'", + ch->string[i].string ); + if(i < end - 1){ + strcat(linedata, ","); + } + strcat( token, linedata ); + } + sprintf(buf, "('%s',%d, %s)", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], token); +} + +void CHAR_make_list_flg_String( Char* ch, char *buf) +{ + if (!ch) return; + int i; + int len = arraysizeof( ch->flg ); + char token[1024]=""; + for( i = 0 ; i < len ; i ++ ){ + char linedata[128]=""; + sprintf( linedata, "%d", ch->flg[i]); + + if(i < len - 1){ + strcat(linedata, ","); + } + + strcat( token, linedata ); + } + sprintf( buf, "('%s', %d, '%s')", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], token); +} + +void CHAR_make_list_skill_String( Char* ch, char *buf) +{ + if (!ch) return; + int i; + char lv[1024]=""; + char id[1024]=""; + for( i = 0 ; i < CHAR_SKILLMAXHAVE ; i ++ ){ + char lvtmp[128]=""; + char idtmp[128]=""; + sprintf( lvtmp, "%d", ch->haveSkill[i].skill.data[SKILL_LEVEL]); + + sprintf( idtmp, "%d", ch->haveSkill[i].skill.data[SKILL_IDENTITY]); + + if(i < CHAR_SKILLMAXHAVE - 1){ + strcat(lvtmp, ","); + strcat(idtmp, ","); + } + strcat( lv, lvtmp ); + strcat( id, idtmp ); + } + sprintf( buf, "('%s', %d, '%s', '%s')", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], lv, id); +} +extern ITEM_intDataSetting ITEM_setintdata[26]; +extern ITEM_intDataSetting ITEM_setchardata[13]; +extern ITEM_exists* ITEM_item; + +void CHAR_make_list_item_String( Char* ch, char *buf) +{ + if (!ch) return; + int i, j; + char token[STRINGBUFSIZ]=""; + int lenint=arraysizeof( ITEM_setintdata); + int lenchar=arraysizeof( ITEM_setchardata); + for( i = 0 ; i < CheckCharMaxItemChar(ch) && i < CHAR_MAXPOOLITEMHAVE ; i ++ ){ + if(i < CheckCharMaxItemChar(ch)){ + if( ch->indexOfExistItems[i] != -1 ){ + char linedata[256]=""; + char itemint[STRINGBUFSIZ]=""; + char itemchar[STRINGBUFSIZ]=""; + for(j = 0; j < lenint ; j ++ ){ + sprintf(linedata, "%d", + ITEM_item[ch->indexOfExistItems[i]].itm.data[ITEM_setintdata[j].table]); + if(j < lenint - 1){ + strcat(linedata, ","); + } + strcat(itemint, linedata); + } + for(j = 0; j < lenchar ; j ++ ){ + sprintf(linedata, "'%s'", + ITEM_item[ch->indexOfExistItems[i]].itm.string[ITEM_setchardata[j].table].string); + if(j < lenchar - 1){ + strcat(linedata, ","); + } + strcat(itemchar, linedata); + } + sprintf(token, "('%s', %d, %d, 0, %s, %s),", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], i, itemint, itemchar); + strcat(buf, token); + } + } + if(i < CHAR_MAXPOOLITEMHAVE){ + if( ch->indexOfExistPoolItems[i] != -1 ){ + char linedata[256]=""; + char itemint[STRINGBUFSIZ]=""; + char itemchar[STRINGBUFSIZ]=""; + for(j = 0; j < lenint ; j ++ ){ + sprintf(linedata, "%d", + ITEM_item[ch->indexOfExistPoolItems[i]].itm.data[ITEM_setintdata[j].table]); + if(j < lenint - 1){ + strcat(linedata, ","); + } + strcat(itemint, linedata); + } + for(j = 0; j < lenchar ; j ++ ){ + sprintf(linedata, "'%s'", + ITEM_item[ch->indexOfExistPoolItems[i]].itm.string[ITEM_setchardata[j].table].string); + if(j < lenchar - 1){ + strcat(linedata, ","); + } + strcat(itemchar, linedata); + } + sprintf(token, "('%s', %d, %d, 1, %s, %s),", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], i, itemint, itemchar); + strcat(buf, token); + } + } + } + buf[strlen(buf)-1]='\0'; +} + +void CHAR_make_list_title_String( Char* ch, char *buf) +{ + if (!ch) return; + int i; + int len = arraysizeof( ch->flg ); + char token[1024]=""; + for( i = 0 ; i < len ; i ++ ){ + char linedata[128]=""; + sprintf( linedata, "%d", ch->indexOfHaveTitle[i]); + + if(i < len - 1){ + strcat(linedata, ","); + } + + strcat( token, linedata ); + } + sprintf( buf, "('%s', %d, '%s')", ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], token); +} + +void CHAR_make_list_mail_String( Char* ch, char *buf) +{ + if (!ch) return; + int i; + for( i = 0 ; i < ADDRESSBOOK_MAX ; i ++ ){ + char token[1024]=""; + ADDRESSBOOK_entry *mail = &ch->addressBook[i]; + if( mail->use == 0 )continue; + sprintf( token, + "('%s',%d,'%s','%s',%d,%d,%d,%d),", + ch->string[CHAR_CDKEY].string, ch->data[CHAR_SAVEINDEXNUMBER], mail->cdkey, mail->charname, mail->level, mail->duelpoint, mail->graphicsno,mail->transmigration); + strcat( buf, token ); + } + buf[strlen(buf)-1]='\0'; +} + +void CHAR_CharadataSaveSQL(Char* ch) +{ + if (!ch) return; + int start=0, end=0; + memset(&charadata, 0, sizeof(charadata)); + CHAR_make_list_String(ch, charadata.CHAR_list_String); + start=end; + end=list_info1; + CHAR_make_list_int_String(ch, CHAR_list_info1_int, charadata.CHAR_list_info1_String, start, end); + start=end; + end+=list_info2; + CHAR_make_list_int_String(ch, CHAR_list_info2_int, charadata.CHAR_list_info2_String, start, end); + start=end; + end+=list_count; + CHAR_make_list_int_String(ch, CHAR_list_count_int, charadata.CHAR_list_count_String, start, end); + start=end; + end+=list_info3; + CHAR_make_list_int_String(ch, CHAR_list_info3_int, charadata.CHAR_list_info3_String, start, end); + start=end; + end+=list_event; + CHAR_make_list_int_String(ch, CHAR_list_event_int, charadata.CHAR_list_event_String, start, end); + start=end; + end+=list_info4; + CHAR_make_list_int_String(ch, CHAR_list_info4_int, charadata.CHAR_list_info4_String, start, end); + start=end; + end+=list_attackmagic; + CHAR_make_list_int_String(ch, CHAR_list_attackmagic_int, charadata.CHAR_list_attackmagic_String, start, end); + start=end; + end+=list_info5; + CHAR_make_list_int_String(ch, CHAR_list_info5_int, charadata.CHAR_list_info5_String, start, end); + start=end; + end+=list_profession; + CHAR_make_list_int_String(ch, CHAR_list_profession_int, charadata.CHAR_list_profession_String, start, end); + start=end; + end+=list_info6; + CHAR_make_list_int_String(ch, CHAR_list_info6_int, charadata.CHAR_list_info6_String, start, end); + CHAR_make_list_char_String(ch, CHAR_list_info_char, charadata.CHAR_list_info_String, 0, list_info); + + CHAR_make_list_flg_String(ch, charadata.CHAR_list_flg_String); + CHAR_make_list_skill_String(ch, charadata.CHAR_list_skill_String); + CHAR_make_list_item_String(ch, charadata.CHAR_list_item_String); + CHAR_make_list_title_String(ch, charadata.CHAR_list_title_String); + CHAR_make_list_mail_String(ch, charadata.CHAR_list_mail_String); + + saacproto_CharadataSaveSQL_send(acfd, ch->string[CHAR_CDKEY].string, charadata, ch->data[CHAR_SAVEINDEXNUMBER], 0); +} + +/* +char* CHAR_makeStringFromCharSQL( Char* one ) +{ + int i; + int petnum; + int strlength=0; + + if (!one) return "\0"; + + memset( CHAR_dataString, 0, sizeof(CHAR_dataString)); + for( i = 0 ; i < CHAR_DATAINTNUM ; i ++ ){ + char linedata[256]; + snprintf( linedata , sizeof(linedata), + "%s=%d", + CHAR_setintdata[i], + one->data[i] ); + + strcat(linedata, ","); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + for( i = 0 ; i < CHAR_DATACHARNUM ; i ++ ){ + char linedata[256]; + char escapebuffer[256]; + snprintf( linedata , sizeof(linedata), + "%s='%s'", + CHAR_setchardata[i], + makeEscapeString( one->string[i].string, escapebuffer, + sizeof( escapebuffer) )); + + if(i < CHAR_DATACHARNUM - 1){ + strcat(linedata, ","); + } + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < arraysizeof( one->flg ) ; i ++ ){ + char linedata[128]; + snprintf( linedata , sizeof(linedata), + FLGRESERVESTRING "%d=%d" CHAR_DELIMITER, + i, one->flg[i]); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_SKILLMAXHAVE ; i ++ ){ + char linedata[128]; + char *skillstring="\0"; + if( one->haveSkill[i].use == TRUE) + skillstring = SKILL_makeStringFromSkillData( + &one->haveSkill[i].skill ); + if( skillstring == "\0" ) continue; + snprintf( linedata , sizeof( linedata ), + SKILLRESERVESTRING "%d=%s" CHAR_DELIMITER, + i,skillstring ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CheckCharMaxItemChar(one) ; i ++ ){ + char linedata[2048]; + char *itemstring="\0"; + if( one->indexOfExistItems[i] != -1 ) + itemstring = ITEM_makeStringFromItemIndex( + one->indexOfExistItems[i], 0); + if( itemstring == "\0" )continue; + snprintf( linedata , sizeof( linedata ), + ITEMRESERVESTRING "%d=%s" CHAR_DELIMITER, + i, itemstring); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_MAXPOOLITEMHAVE ; i ++ ){ + char linedata[2048]; + char *itemstring="\0"; + if( one->indexOfExistPoolItems[i] != -1 ) + itemstring = ITEM_makeStringFromItemIndex( + one->indexOfExistPoolItems[i], 0); + if( itemstring == "\0" )continue; + snprintf( linedata , sizeof( linedata ), + POOLITEMRESERVESTRING "%d=%s" CHAR_DELIMITER, + i, itemstring); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( i = 0 ; i < CHAR_TITLEMAXHAVE ; i ++ ){ + char linedata[128]; + if( one->indexOfHaveTitle[i]< 0 || one->indexOfHaveTitle[i] >= CHAR_TITLEMAXHAVE ) { + continue; + } + snprintf( linedata , sizeof( linedata ), + TITLERESERVESTRING "%d=%d" CHAR_DELIMITER, + i, one->indexOfHaveTitle[i] ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + for( i=0 ; i < ADDRESSBOOK_MAX ; i++ ){ + char linedata[512]; + char *p; + p = ADDRESSBOOK_makeAddressbookString(&one->addressBook[i]); + if( strlen( p) == 0 ) { + continue; + } + snprintf( linedata ,sizeof(linedata), + ADDRESSBOOKRESERVESTRING "%d=%s" CHAR_DELIMITER, + i,p + ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + for( petnum = 0; petnum < CHAR_MAXPETHAVE; petnum ++ ) { + int petindex; + char linedata[4096*2]; + char *petstring="\0"; + petindex = one->unionTable.indexOfPet[petnum]; + if( !CHAR_CHECKINDEX(petindex))continue; + petstring = CHAR_makePetStringFromPetIndex( petindex); + if( petstring == "\0" ) continue; + snprintf( linedata , sizeof(linedata), + PETSERVERSTRING "%d=%s" CHAR_DELIMITER,petnum,petstring ); + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } + + for( petnum = 0; petnum < CHAR_MAXPOOLPETHAVE; petnum ++ ) { + int petindex; + char linedata[4096*2]; + char *petstring="\0"; + petindex = one->indexOfPoolPet[petnum]; + if( !CHAR_CHECKINDEX(petindex))continue; + petstring = CHAR_makePetStringFromPetIndex( petindex); + if( petstring == "\0" ) continue; + + //andy_log + if( strstr( petstring, "name:") == NULL || + strstr( petstring, "ownt:") == NULL ) { + LodBadPetString( "petstring", "poolpet string buffer err:", petnum); + fprint( "ANDY err poolpet string buffer err:\n%s\n", petstring); + goto RETURN; + } + + snprintf( linedata , sizeof(linedata), + POOLPETSERVERSTRING "%d=%s" CHAR_DELIMITER,petnum,petstring ); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, + linedata ); + strlength += strlen( linedata ); + if( strlength > sizeof( CHAR_dataString ) ) { + fprint( "err charadata buffer over\n"); + goto RETURN; + } + } +#ifdef _CHAR_FIXDATADEF + { + char linedata[1024]; + memset( linedata, 0, sizeof(linedata)); + snprintf( linedata , sizeof(linedata), + DATAENDCHECKPOINT "=%d" CHAR_DELIMITER, (int)time(NULL)/1000); + + strcpysafe( &CHAR_dataString[strlength], + sizeof( CHAR_dataString ) - strlength, linedata ); + + if( strlength > sizeof( CHAR_dataString ) ) { + LodBadPetString( "DATAENDCHECKPOINT", "err charadata buffer over", -1); + fprint( "err charadata buffer over:DATAENDCHECKPOINT !\n"); + goto MAKESTRINGERR; + } + } +#endif + +RETURN: + if( strstr( CHAR_dataString, DATAENDCHECKPOINT) == NULL ){ + LodBadPetString( CHAR_dataString, "err mk dataString no end", -1); + } + + return CHAR_dataString; +MAKESTRINGERR: + return "\0"; +} +*/ + + + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/crypto.c b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/crypto.c new file mode 100644 index 0000000..74a0090 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/crypto.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include "autil.h" +#include "util.h" + +//char cryptokey[]=DEFAULTTABLE; +char cryptokey[]="aBcDeFgHiJkLmNoPqRsTuVwXyZ"; + +void CryptoKey(char* usrkey) +{ + int cryptokeylen = strlen(cryptokey); + int i; + + for(i=0;id_name[0] == '.')continue; + if (ent->d_type==8){ + char line[1024]; + if( ent->d_name == NULL + ||strlen( ent->d_name ) < 1 + ||ent->d_name[strlen(ent->d_name)-1] == '~' + ||ent->d_name[0] == '#' + ||strcmptail( ent->d_name, ".bak" ) == 0 + ||strcmp( path, "attmagic.bin" ) == 0)continue; + + sprintf(filename, "%s/%s", path, ent->d_name); + FILE * f1 = fopen(filename,"r"); + + sprintf(filename, "allblues/%s/%s.allblues", path, ent->d_name); + remove( filename); + FILE * f2 = fopen(filename,"a+"); + while( fgets( line, sizeof( line ), f1 ) ){ + CryptoKey(line); + fputs(line,f2); + } + fclose(f1); + fclose(f2); + }else{ + if( strcmp( path, "data" ) == 0 + && (strcmp( ent->d_name, "autopk" ) == 0 + || strcmp( ent->d_name, "map" ) == 0))continue; + sprintf(filename, "allblues/%s/%s", path, ent->d_name); + if(opendir(filename)==NULL){ + if(mkdir(filename, 0x777) == 0){ + printf("ļ %s\n", filename); + } + } + sprintf(filename, "%s/%s", path, ent->d_name); + List(filename); + } + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/luckstar.c b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/luckstar.c new file mode 100644 index 0000000..207a00f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/luckstar.c @@ -0,0 +1,208 @@ +#include +#include "version.h" +#include "longzoro/luckstar.h" +#include "char_base.h" +#include "char.h" +#include "autil.h" +#include "enemy.h" +#include "item.h" + +#ifdef _LUCK_STAR + +Luck_Star_t luckstar[MAXLUCKSTAR]; + +static int lucknum=0; +BOOL LuckStar_init() +{ + FILE* fp; + int i; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/luckstar.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/luckstar.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + memset( &luckstar, 0, sizeof( luckstar ) ); + lucknum = 0; + for(i=0;i 0){ + int ret; + int enemynum; + int i; + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ){ + if( ENEMY_getInt( i, ENEMY_ID) == luckstar[luckid].pet) { + break; + } + } + if( i != enemynum ){ + ret = ENEMY_createPetFromEnemyIndex(charaindex, i); + if( CHAR_CHECKINDEX( ret)){ + snprintf( token,sizeof( token), "ϲ㣬ñͳ %s ",ENEMY_getChar( i, ENEMY_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORGREEN); + int j; + for( j = 0; j < CHAR_MAXPETHAVE; j ++ ){ + if( CHAR_getCharPet( charaindex, j ) == ret )break; + } + if( j != CHAR_MAXPETHAVE ){ + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret, CHAR_VARIABLEAI, 10000); + } + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_complianceParameter( ret ); + snprintf( token, sizeof( token ), "K%d", j ); + CHAR_sendStatusString( charaindex, token ); + snprintf( token, sizeof( token ), "W%d", j ); + CHAR_sendStatusString( charaindex, token ); + } + }else{ + CHAR_talkToCli( charaindex, -1, "ܱǸϳѴͳ", CHAR_COLORYELLOW); + } + snprintf( strPet,sizeof( strPet), "%s", ENEMY_getChar( i, ENEMY_NAME)); + }else{ + snprintf( strPet,sizeof( strPet), " %d ", luckstar[luckid].pet); + } + } + if(luckstar[luckid].item > 0){ + int itemindex = ITEM_makeItemAndRegist( luckstar[luckid].item ); + if( ITEM_CHECKINDEX( itemindex) ){ + int emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + if( emptyitemindexinchara >= 0 ){ + if( itemindex != -1 ){ + CHAR_setItemIndex( charaindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,charaindex); + CHAR_sendItemDataOne( charaindex, emptyitemindexinchara); + + snprintf( token, sizeof( token), "ϲ㣬ñƷ %s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORGREEN); + } + }else{ + CHAR_talkToCli( charaindex, -1, "ܱǸƷѴƷ", CHAR_COLORYELLOW); + } + snprintf( strItem,sizeof( strItem), "Ʒ%s", ITEM_getChar( itemindex, ITEM_NAME)); + }else{ + snprintf( strPet,sizeof( strPet), "Ʒ %d ", luckstar[luckid].item); + } + } +/* + if(luckstar[luckid].gold > 0){ + CHAR_setInt( charaindex , CHAR_GOLD , CHAR_getInt( charaindex , CHAR_GOLD ) + luckstar[luckid].gold); + CHAR_complianceParameter( charaindex ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_GOLD); + snprintf( strGold,sizeof( strGold), "ʯң%d", luckstar[luckid].gold); + sprintf( token, "ϲ㣬ñ %d ʯң", luckstar[luckid].gold); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORPURPLE ); + } + if(luckstar[luckid].vippoint > 0){ + CHAR_setInt( charaindex , CHAR_AMPOINT , CHAR_getInt( charaindex , CHAR_AMPOINT ) + luckstar[luckid].vippoint); + snprintf( strVippoint,sizeof( strVippoint), "ֵ㣺%d", luckstar[luckid].vippoint); + sprintf( token, "ϲ㣬ñ %d ֵ㣡", luckstar[luckid].vippoint); + CHAR_talkToCli( charaindex, -1,token, CHAR_COLORPURPLE ); + } +*/ + break; + } + } + + int playernum = CHAR_getPlayerMaxNum(); + + if(k < 3){ + sprintf(token, "һף %s Ϊ~½Ʒ", CHAR_getChar( charaindex, CHAR_NAME)); + }else{ + sprintf(token, "źδ~ףԸΪһǻߣ"); + } + + for(k=0;k 0){ + CHAR_talkToCli( k, -1, strPet, CHAR_COLORPURPLE ); + } + if(strlen(strItem) > 0){ + CHAR_talkToCli( k, -1, strItem, CHAR_COLORPURPLE ); + } +/* + if(strlen(strGold) > 0){ + CHAR_talkToCli( k, -1, strGold, CHAR_COLORPURPLE ); + } + if(strlen(strVippoint)> 0){ + CHAR_talkToCli( k, -1, strVippoint, CHAR_COLORPURPLE ); + } +*/ + } + } +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile new file mode 100755 index 0000000..21c2364 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile @@ -0,0 +1,376 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQLSRC=sasql_cygwin.c + SQL=-lodbc32 -lz +endif +ifeq ($(shell uname),Linux) + SQLSRC=sasql_linux.c + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz +endif + + +PROG=liblongzoro.a + +SRC=move.c crypto.c characters.c luckstar.c newshop.c playerquestion.c $(SQLSRC) +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +move.o: move.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/move.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h +crypto.o: crypto.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/string.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h ../include/autil.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/stdlib.h \ + /usr/include/alloca.h +characters.o: characters.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h \ + ../include/longzoro/characters.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/saacproto_cli.h ../include/version.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h +luckstar.o: luckstar.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/luckstar.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h \ + ../include/enemy.h ../include/item.h +newshop.o: newshop.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/newshop.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/autil.h ../include/enemy.h ../include/item.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +playerquestion.o: playerquestion.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/playerquestion.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h \ + ../include/enemy.h ../include/family.h ../include/log.h +sasql_linux.o: sasql_linux.c ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/configfile.h /usr/include/mysql/mysql.h \ + /usr/include/mysql/mysql_version.h /usr/include/mysql/mysql_com.h \ + /usr/include/mysql/mysql_time.h /usr/include/mysql/typelib.h \ + /usr/include/mysql/my_alloc.h /usr/include/mysql/my_list.h \ + /usr/include/string.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile.bak new file mode 100755 index 0000000..21c2364 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/makefile.bak @@ -0,0 +1,376 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQLSRC=sasql_cygwin.c + SQL=-lodbc32 -lz +endif +ifeq ($(shell uname),Linux) + SQLSRC=sasql_linux.c + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz +endif + + +PROG=liblongzoro.a + +SRC=move.c crypto.c characters.c luckstar.c newshop.c playerquestion.c $(SQLSRC) +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +move.o: move.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/move.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h +crypto.o: crypto.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/string.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h ../include/autil.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/stdlib.h \ + /usr/include/alloca.h +characters.o: characters.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h \ + ../include/longzoro/characters.h ../include/readmap.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/saacproto_cli.h ../include/version.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/char_base.h ../include/skill.h ../include/title.h \ + ../include/addressbook.h ../include/net.h ../include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h +luckstar.o: luckstar.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/luckstar.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h \ + ../include/enemy.h ../include/item.h +newshop.o: newshop.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/newshop.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/autil.h ../include/enemy.h ../include/item.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +playerquestion.o: playerquestion.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/longzoro/playerquestion.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/autil.h \ + ../include/enemy.h ../include/family.h ../include/log.h +sasql_linux.o: sasql_linux.c ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/configfile.h /usr/include/mysql/mysql.h \ + /usr/include/mysql/mysql_version.h /usr/include/mysql/mysql_com.h \ + /usr/include/mysql/mysql_time.h /usr/include/mysql/typelib.h \ + /usr/include/mysql/my_alloc.h /usr/include/mysql/my_list.h \ + /usr/include/string.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/move.c b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/move.c new file mode 100644 index 0000000..c423cf3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/move.c @@ -0,0 +1,110 @@ +#include +#include "version.h" +#include "longzoro/move.h" +#include "char_base.h" +#include "char.h" +#include "autil.h" + +#ifdef _TALK_MOVE_FLOOR + +Talk_Move_Floor_t talkmovefloor[MAXTALKMOVEFLOOR]; + +BOOL talk_move_map(int charaindex, char *messageeraseescape) +{ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'm' && messageeraseescape[2] == 'o' && messageeraseescape[3] == 'v' && messageeraseescape[4] == 'e'){ + char token[32]; + char buf[256]=""; + int i; + easyGetTokenFromString( messageeraseescape , 2 , token, sizeof(token)); + + if(strcmp( token, "?") == 0){ + strcpy( buf, "˳Ƶط:"); + for(i=0;i= 220 ){ + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + strcpy( buf, "˳Ƶط:"); + } + if( CHAR_getInt(charaindex, CHAR_TRANSMIGRATION) > talkmovefloor[i].trans + || ( CHAR_getInt(charaindex, CHAR_TRANSMIGRATION) == talkmovefloor[i].trans + && CHAR_getInt(charaindex, CHAR_LV) >= talkmovefloor[i].level ) ) { + strcat( buf, talkmovefloor[i].name); + strcat( buf, " "); + } + } + CHAR_talkToCli( charaindex, -1, buf, CHAR_COLORYELLOW); + return TRUE; + } + + BOOL isMove = FALSE; + for(i=0;i talkmovefloor[i].trans + || ( CHAR_getInt(charaindex, CHAR_TRANSMIGRATION) == talkmovefloor[i].trans + && CHAR_getInt(charaindex, CHAR_LV) >= talkmovefloor[i].level ) ) { + CHAR_warpToSpecificPoint(charaindex, talkmovefloor[i].id, talkmovefloor[i].x, talkmovefloor[i].y ); + return TRUE; + } + } + } + return FALSE; +} + +BOOL MoveMap_init() +{ + FILE* fp; + int i; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/talkmovefloor.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/talkmovefloor.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + for(i=0;i +#include "version.h" +#include "longzoro/newshop.h" +#include "longzoro/sasql.h" +#include "char.h" +#include "autil.h" +#include "enemy.h" +#include "item.h" +#include "lssproto_serv.h" + +#ifdef _ONLINE_SHOP + +Online_Shop_t onlineshop[ONLINESHOP_NUM][SHOPLISTMAX]; +int max[ONLINESHOP_NUM]={0}; + +BOOL OnlineShop_init() +{ + FILE* fp; + int shoplist=0; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "data/onlineshop.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen("data/onlineshop.txt", "r"); +} + if (fp == NULL) + { + print("޷ļ\n"); + return FALSE; + } + memset( &onlineshop, 0, sizeof( onlineshop ) ); + memset( &max, 0, sizeof( max ) ); + char line[64],buf[64]; + while( fgets( line , sizeof( line ), fp ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + if( strlen(line)== 0 )continue; + + chop(line); + + if(strcmp(line, "ONLINESHOP_PET")==0){ + shoplist=ONLINESHOP_PET; + continue; + }else if(strcmp(line, "ONLINESHOP_ITEM")==0){ + shoplist=ONLINESHOP_ITEM; + continue; + }else if(strcmp(line, "ONLINESHOP_HEALER")==0){ + shoplist=ONLINESHOP_HEALER; + continue; + }else if(strcmp(line, "ONLINESHOP_COMPOSE")==0){ + shoplist=ONLINESHOP_COMPOSE; + continue; + }else if(strcmp(line, "ONLINESHOP_MISSION")==0){ + shoplist=ONLINESHOP_MISSION; + continue; + }else if(strcmp(line, "ONLINESHOP_OTHER")==0){ + shoplist=ONLINESHOP_OTHER; + continue; + }else if(strcmp(line, "ONLINESHOP_AMPOINT")==0){ + shoplist=ONLINESHOP_AMPOINT; + continue; + } + int list=max[shoplist]; + + if(getStringFromIndexWithDelim(line,",", 1, onlineshop[shoplist][list].name, sizeof(onlineshop[shoplist][list].name))==FALSE){ + onlineshop[shoplist][list].use=FALSE; + continue; + } + if(getStringFromIndexWithDelim(line,",", 2, buf, sizeof(buf))==TRUE){ + onlineshop[shoplist][list].id=atoi(buf); + }else{ + onlineshop[shoplist][list].use=FALSE; + continue; + } + if(getStringFromIndexWithDelim(line,",", 3, buf, sizeof(buf))==TRUE){ + onlineshop[shoplist][list].picid=atoi(buf); + }else{ + onlineshop[shoplist][list].use=FALSE; + continue; + } + if(getStringFromIndexWithDelim(line,",", 4, buf, sizeof(buf))==TRUE){ + onlineshop[shoplist][list].price=atoi(buf); + }else{ + onlineshop[shoplist][list].use=FALSE; + continue; + } + if(getStringFromIndexWithDelim(line,",", 5, onlineshop[shoplist][list].readme, sizeof(onlineshop[shoplist][list].readme))==FALSE){ + strcmp(onlineshop[shoplist][list].readme,onlineshop[shoplist][list].name); + } + if(getStringFromIndexWithDelim(line,",", 6, buf, sizeof(buf))==TRUE){ + onlineshop[shoplist][list].percentage=atoi(buf); + }else{ + onlineshop[shoplist][list].percentage=100; + } + if(getStringFromIndexWithDelim(line,",", 7, buf, sizeof(buf))==TRUE){ + onlineshop[shoplist][list].color=atoi(buf); + }else{ + onlineshop[shoplist][list].color=CHAR_COLORWHITE; + } + onlineshop[shoplist][list].use=TRUE; + max[shoplist]++; + } + fclose(fp); + return TRUE; +} + +void OnlineShop_ShowList(int fd, int charaindex, int type, int page) +{ + if(type>ONLINESHOP_NUM)return; + int pagemax=(max[type-1]-1)/SHOPPAGEMAX+1; + if(page>pagemax)return; + char token[4096]=""; + char buf[1024]; + int i; + int availability=0; + int startpage=(page-1)*SHOPPAGEMAX; + if(startpage<=0)startpage=0; + + for(i=startpage;iSHOPLISTMAX)break; + if(onlineshop[type-1][i].use==TRUE){ + sprintf(buf,"%d#%d#%s#%d#%d#%d#%s|",i, + onlineshop[type-1][i].picid, + onlineshop[type-1][i].name, + onlineshop[type-1][i].color, + onlineshop[type-1][i].percentage, + onlineshop[type-1][i].price, + onlineshop[type-1][i].readme); + strcat(token, buf); + availability++; + } + } + + + if((type-1) == ONLINESHOP_AMPOINT){ + lssproto_VIP_SHOP_send( fd, availability,CHAR_getInt(charaindex, CHAR_AMPOINT), type, page, pagemax ,token); + }else{ +#ifdef _ONLINE_SHOP_MYSQL + lssproto_VIP_SHOP_send( fd, availability,sasql_getVipPoint(charaindex), type, page, pagemax ,token); +#else + lssproto_VIP_SHOP_send( fd, availability,CHAR_getInt(charaindex, CHAR_BJ), type, page, pagemax ,token); +#endif + } +} + +void OnlineShop_Buy(int fd, int charaindex, int type, int page, int id, int num) +{ + switch(type-1){ + case ONLINESHOP_PET: + { +#ifdef _ONLINE_SHOP_MYSQL + int bj = sasql_getVipPoint(charaindex); +#else + int bj = CHAR_getInt(charaindex, CHAR_BJ); +#endif + int price = onlineshop[type-1][id].price * onlineshop[type-1][id].percentage / 100; + if(bj >= price * num){ + char token[64]; + int i, j; + int enemynum = ENEMY_getEnemyNum(); + for(j=0;j= price * num){ + int i; + for(i=0;i= price){ +#ifdef _ONLINE_SHOP_MYSQL + sasql_setVipPoint(charaindex, bj - price); +#else + CHAR_setInt(charaindex, CHAR_BJ, bj - price); +#endif + CHAR_setInt(charaindex, CHAR_AMPOINT, CHAR_getInt(charaindex, CHAR_AMPOINT) + onlineshop[type-1][id].id * num); + } + + } + break; + + case ONLINESHOP_AMPOINT: + { + int ampoint = CHAR_getInt(charaindex, CHAR_AMPOINT); + int price = onlineshop[type-1][id].price * onlineshop[type-1][id].percentage / 100 * num; + if(ampoint >= price){ + CHAR_setInt(charaindex, CHAR_AMPOINT, ampoint - price); +#ifdef _ONLINE_SHOP_MYSQL + sasql_setVipPoint(charaindex, sasql_getVipPoint(charaindex) + onlineshop[type-1][id].id * num); +#else + CHAR_setInt(charaindex, CHAR_BJ, CHAR_getInt(charaindex, CHAR_BJ) + onlineshop[type-1][id].id * num); +#endif + + } + } + break; + + } + int i; + int pagemax=(max[type-1]-1)/SHOPPAGEMAX+1; + for(i=0;i +#include "version.h" +#include "longzoro/playerquestion.h" +#include "char_base.h" +#include "char.h" +#include "autil.h" +#include "enemy.h" +#include "family.h" +#include "log.h" + +#ifdef _PLAYER_QUESTION_ONLIEN +PlayerQuestion_t PlayerQuestion; + +BOOL PlayQuestionOnline(int charaindex, char *messageeraseescape) +{ + if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'h' && messageeraseescape[2] == 'd'){ + + if(strlen(PlayerQuestion.question)==0 || strlen(PlayerQuestion.result)==0){ + CHAR_talkToCli(charaindex,-1,"GMδ߷!",CHAR_COLORRED); + return FALSE; + } + + char token[32]; + easyGetTokenFromString( messageeraseescape , 2 , token, sizeof(token)); + + if(strcmp( token, PlayerQuestion.result) == 0){ + switch(PlayerQuestion.type){ + case 0: + // Ǯ + CHAR_setInt(charaindex,CHAR_GOLD, CHAR_getInt(charaindex,CHAR_GOLD) + PlayerQuestion.value); + CHAR_send_P_StatusString(charaindex,CHAR_P_STRING_GOLD); + + break; + case 1: + { + int itemindex=-1; + char token[256]; + int ret; + + itemindex = CHAR_findEmptyItemBox( charaindex ); + if( itemindex < 0 ) { + CHAR_talkToCli( charaindex, -1, "ܱǸ,Ʒ!", CHAR_COLORYELLOW); + break; + } + + itemindex = ITEM_makeItemAndRegist( PlayerQuestion.value ); + if( itemindex != -1 ){ + ret = CHAR_addItemSpecificItemIndex( charaindex, itemindex); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + if( ret < 0 || +#ifdef _NEW_ITEM_ + ret >= CheckCharMaxItem(charaindex) +#else + ret >= CHAR_MAXITEMHAVE +#endif + ) { + ITEM_endExistItemsOne( itemindex); + CHAR_talkToCli( charaindex, -1, "ܱǸ,޷Ʒ!", CHAR_COLORYELLOW); + break; + } + + sprintf( token,"ϲ:%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW ); + + CHAR_sendItemDataOne( charaindex, ret); + } + } + break; + case 2: + { + char msgbuf[64]; + int enemynum; + int i,j; + int petindex; + + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + if( CHAR_getCharPet( charaindex, i) == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ){ + CHAR_talkToCli( charaindex, -1, "ܱǸ,ϳ!", CHAR_COLORYELLOW); + break; + } + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == PlayerQuestion.value) { + break; + } + } + + if( i == enemynum ){ + CHAR_talkToCli( charaindex, -1, "ܱǸ,óﲻ", CHAR_COLORYELLOW); + break; + } + + petindex = ENEMY_createPetFromEnemyIndex( charaindex, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charaindex, i ) == petindex ) + break; + } + + if( !CHAR_CHECKINDEX( petindex) ){ + CHAR_talkToCli( charaindex, -1, "ܱǸ,óﲻ", CHAR_COLORYELLOW); + } + snprintf( msgbuf,sizeof( msgbuf), "ϲó:%s", CHAR_getChar(petindex,CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_setInt(petindex,CHAR_VARIABLEAI,10000); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(charaindex, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( charaindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( charaindex, msgbuf ); + } + } + break; + case 3: + CHAR_setInt(charaindex,CHAR_FAME,CHAR_getInt(charaindex,CHAR_FAME) + PlayerQuestion.value * 100); +/* + char buf[64]; + sprintf(buf,"%d", CHAR_getInt(charaindex,CHAR_FAME)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(charaindex,CHAR_FMNAME),CHAR_getInt(charaindex,CHAR_FMINDEX),CHAR_getWorkInt(charaindex,CHAR_WORKFMINDEXI), + FM_FIX_FMFEED,buf,"",CHAR_getWorkInt(charaindex,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(getfdFromCharaIndex(charaindex))); +*/ + sprintf( token, "ϲø%d", PlayerQuestion.value); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + break; + case 4: + CHAR_setInt(charaindex,CHAR_AMPOINT,CHAR_getInt(charaindex,CHAR_AMPOINT) + PlayerQuestion.value); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + PlayerQuestion.value, + CHAR_getInt( charaindex, CHAR_AMPOINT ), + "()", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y )); +#endif + sprintf( token, "ϲø˻֣%d", PlayerQuestion.value); + CHAR_talkToCli(charaindex,-1,token,CHAR_COLORRED); + break; + } + { + char type[5][32]={"ʯ","߱Ϊ","Ϊ","",""}; + + int i; + int playernum = CHAR_getPlayerMaxNum(); + char token1[128]; + char token2[128]; + sprintf(token1, "ϲ %s شȷ,:%s", CHAR_getChar(charaindex, CHAR_NAME), PlayerQuestion.result); + sprintf(token2, "ǹϲ%s %d", type[PlayerQuestion.type], PlayerQuestion.value); + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ){ + CHAR_talkToCli( i, -1, token1, CHAR_COLORRED); + CHAR_talkToCli( i, -1, token2, CHAR_COLORRED); + } + } + } + strcpy(PlayerQuestion.question,""); + strcpy(PlayerQuestion.result,""); + }else{ + CHAR_talkToCli(charaindex,-1,"ܱǸ,شȷ!",CHAR_COLORRED); + return FALSE; + } + } + return FALSE; +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/sasql_linux.c b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/sasql_linux.c new file mode 100644 index 0000000..a046292 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/longzoro/sasql_linux.c @@ -0,0 +1,1142 @@ +#include "longzoro/version.h" + +#ifdef _SASQL// + +#include "longzoro/sasql.h" +#include "char_base.h" +#include "configfile.h" +#include +#include +#include +MYSQL mysql; +MYSQL_RES *mysql_result; +MYSQL_ROW mysql_row; +MYSQL_FIELD *fields; + +typedef struct tagSQLConfig +{ + char sql_IP[32]; + + int sql_Port; + + char sql_Port1[16]; + + char sql_ID[16]; + + char sql_PS[32]; + + char sql_DataBase[16]; + + char sql_Table[16]; + + char sql_LOCK[16]; + + char sql_NAME[16]; + + char sql_PASS[16]; +}SQLConfig; + +SQLConfig sqlconfig; + +int AutoReg; +int openbackground; + +static int readSqlConfig( char *path ) +{ + char buf[255]; + FILE *fp; + + fp = fopen( path , "r" ); + if( fp == NULL ){ return -2; } + + while( fgets( buf , sizeof( buf ) , fp )){ + char command[255]; + char param[255]; + chop(buf); + + easyGetTokenFromString( buf , 1 , command , sizeof( command )); + easyGetTokenFromString( buf , 2 , param , sizeof( param )); + + if( strcmp( command , "sql_IP" ) == 0 ){ + strcmp( sqlconfig.sql_IP , param ) ; + snprintf( sqlconfig.sql_IP , sizeof( sqlconfig.sql_IP) , param ); + printf("ݿַ %s\n",sqlconfig.sql_IP); + } else if( strcmp( command , "sql_Port" ) == 0 ){ + sqlconfig.sql_Port = atoi( param ); + snprintf( sqlconfig.sql_Port1 , sizeof( sqlconfig.sql_Port1) , param ); + printf("ݿ˿ڣ %d\n",sqlconfig.sql_Port); + } else if( strcmp( command , "sql_ID" ) == 0 ){ + strcmp( sqlconfig.sql_ID , param ) ; + snprintf( sqlconfig.sql_ID , sizeof( sqlconfig.sql_ID) , param ); + printf("ݿû %s\n",sqlconfig.sql_ID); + } else if( strcmp( command , "sql_PS" ) == 0 ){ + strcmp( sqlconfig.sql_PS , param ) ; + snprintf( sqlconfig.sql_PS , sizeof( sqlconfig.sql_PS) , param ); + printf("ݿ룺 %s\n",sqlconfig.sql_PS); + } else if( strcmp( command , "sql_DataBase" ) == 0 ){ + strcmp( sqlconfig.sql_DataBase , param ) ; + snprintf( sqlconfig.sql_DataBase , sizeof( sqlconfig.sql_DataBase) , param ); + printf("½ݿ%s\n",sqlconfig.sql_DataBase); + } else if( strcmp( command , "sql_Table" ) == 0 ){ + strcmp( sqlconfig.sql_Table , param ) ; + snprintf( sqlconfig.sql_Table , sizeof( sqlconfig.sql_Table) , param ); + printf("ûϢ %s\n",sqlconfig.sql_Table); + } else if( strcmp( command , "sql_NAME" ) == 0 ){ + strcmp( sqlconfig.sql_NAME , param ) ; + snprintf( sqlconfig.sql_NAME , sizeof( sqlconfig.sql_NAME) , param ); + printf("˺ֶƣ %s\n",sqlconfig.sql_NAME); + } else if( strcmp( command , "sql_PASS" ) == 0 ){ + strcmp( sqlconfig.sql_PASS , param ) ; + snprintf( sqlconfig.sql_PASS , sizeof( sqlconfig.sql_PASS) , param ); + printf("ֶƣ %s\n",sqlconfig.sql_PASS); + } + } + fclose(fp); + return 0; +} + +BOOL sasql_init( void ) +{ + if((mysql_init(&mysql) == NULL) & readSqlConfig("sql.cf")) + { + printf("\nݿʼʧܣ\n"); + exit(1); + return FALSE; + } + + if( !mysql_real_connect( &mysql, + sqlconfig.sql_IP, + sqlconfig.sql_ID,//ʺ + sqlconfig.sql_PS,// + sqlconfig.sql_DataBase,//ѡϿ + sqlconfig.sql_Port, + NULL, + 0 ) ) + { + printf("\nݿʧܣ\n"); + return FALSE; + } + + mysql_query(&mysql,"set names 'gbk'"); + printf("\nݿӳɹ\n"); + return TRUE; +} + +int sasql_mysql_query( char *sqlstr ) +{ + mysql_query(&mysql,"set names 'gbk'"); + return mysql_query(&mysql,sqlstr); +} + +void sasql_close( void ) +{ + mysql_close( &mysql ); +} + +BOOL sasql_ckeckStrint( char *str ) +{ + int i; + for(i=0;i 'z') && (str[i] < 'A' || str[i] > 'Z') && (str[i] < '0' || str[i] > '9') && (str[i] != '.')){ + return FALSE; + } + } + return TRUE; +} + +int sasql_getVipPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setVipPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + //printf("û%sǰػر%d\n",id,point); + return point; + } + return -1; +} + +int sasql_getVipPointForCdkey( char *id ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַû%s\n",id); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setVipPointForCdkey( char *id, int point ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַû%s\n",id); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + //printf("û%sǰػر%d\n",id,point); + return point; + } + return -1; +} + + +int sasql_getPayPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select PayPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setPayPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set PayPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + //printf("û%sǰػر%d\n",id,point); + return point; + } + return -1; +} + +#ifdef _GAMBLE_POINT +int sasql_getGamblePoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select GamblePoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setGamblePoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set GamblePoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + return point; + } + return -1; +} + +#endif + +#ifdef _TRIAL_POINT +int sasql_getTrialPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select TrialPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setTrialPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set TrialPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + return point; + } + return -1; +} + +#endif + +#ifdef _GLORY_POINT +int sasql_getGloryPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select GloryPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setGloryPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set GloryPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + return point; + } + return -1; +} + +#endif +int sasql_getPayPointForCdkey( char *id ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַû%s\n",id); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select PayPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if (mysql_row!=NULL) { + return atoi(mysql_row[0]); + }else{ + return 0; + } + } + } + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setPayPointForCdkey( char *id, int point ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַû%s\n",id); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"update %s set PayPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + //printf("û%sǰػر%d\n",id,point); + return point; + } + return -1; +} + +#ifdef _PAUCTION_MAN +BOOL sasql_addPauctionInfo( char *cdkey, char *name, char *effect, int cost, int type, char *info, char *string ) +{ + char sqlstr[1024]; + sprintf(sqlstr,"INSERT INTO `PauctionInfo` ( `cdkey` , `name` , `effect` , `cost` , `type` , `info` , `string` , `day` ) " + "VALUES ( '%s', '%s', '%s', %d, %d, '%s', '%s', NOW())", + cdkey, name, effect, cost, type, info, string ); + + if(!sasql_mysql_query(sqlstr)){ + printf("ɹһϢ\n"); + return TRUE; + } + return FALSE; +} + +int sasql_getPauctionList( char *List, int start, int type, char *cdkey ) +{ + char sqlstr[1024]; + char tmp[256]; + char buf[256]; + int num_row=0; + if(type == 0){ + if(strlen(cdkey)>0){ + sprintf(sqlstr, "select `id` , `cdkey` , `effect` from `PauctionInfo` where `cdkey` = BINARY'%s'", cdkey); + }else{ + sprintf(sqlstr, "select `id` , `cdkey` , `effect` from `PauctionInfo` where TO_DAYS( NOW( ) ) - TO_DAYS( day ) < 30"); + } + }else{ + sprintf(sqlstr, "select `id` , `cdkey` , `effect` from `PauctionInfo` where `type` = %d AND TO_DAYS( NOW( ) ) - TO_DAYS( day ) < 30", type); + } + if(!sasql_mysql_query(sqlstr)){ + int line = 0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row > 0){ + while((mysql_row = mysql_fetch_row(mysql_result))){ + if(line >=start){ + sprintf(tmp, "%s|%s|%s", mysql_row[0], mysql_row[1], mysql_row[2]); + strcat(List, makeEscapeString(tmp, buf, sizeof( buf))); + strcat(List, "|"); + + if(line > start + 10)break; + } + line ++; + } + } + + return num_row; + } + + return 0; +} + +BOOL sasql_getPauctionSurvey( char *token, int id ) +{ + char sqlstr[1024]; + char buf[1024]; + sprintf(sqlstr, "select `id` , `name` , `effect`, `cost`, `type`, `info` from `PauctionInfo` where `id` = %d AND TO_DAYS( NOW( ) ) - TO_DAYS( day ) < 30", id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row > 0){ + mysql_row = mysql_fetch_row(mysql_result); + sprintf(token, "%s|%s|%s|%s|%s|%s", mysql_row[0], mysql_row[1], mysql_row[2],mysql_row[3], mysql_row[4], makeEscapeString(mysql_row[5], buf, sizeof( buf) )); + } + + return TRUE; + } + + return FALSE; +} + +int sasql_getMyPauction( char *token, int id, char *cdkey ) +{ + char sqlstr[1024]; + + if(strlen(cdkey)>0){ + sprintf(sqlstr, "select `string` ,`type` from `PauctionInfo` where `id` = %d AND `cdkey` = BINARY'%s'", id, cdkey); + }else{ + sprintf(sqlstr, "select `string` ,`type` from `PauctionInfo` where `id` = %d ", id); + } + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row > 0){ + mysql_row = mysql_fetch_row(mysql_result); + sprintf(token, "%s", mysql_row[0]); + } + + return atoi(mysql_row[1]); + } + + return -1; +} + +int sasql_PauctionOK( int id, char *cdkey ) +{ + char sqlstr[1024]; + sprintf(sqlstr, "select `cdkey`, `cost` from `PauctionInfo` where `id` = %d", id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row > 0){ + mysql_row = mysql_fetch_row(mysql_result); + char tocdkey[64]; + sprintf(tocdkey, "%s", mysql_row[0]); + int cost = atoi(mysql_row[1]); + sprintf(sqlstr, "select * from `%s` where %s = BINARY'%s' AND VipPoint>%d", sqlconfig.sql_Table, sqlconfig.sql_NAME, cdkey, cost); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row > 0){ + sprintf(sqlstr,"update %s set VipPoint=VipPoint + %d where %s=BINARY'%s' " + , sqlconfig.sql_Table, cost, sqlconfig.sql_NAME, tocdkey); + if(!sasql_mysql_query(sqlstr)){ + sprintf(sqlstr,"update %s set VipPoint=VipPoint - %d where %s=BINARY'%s' " + , sqlconfig.sql_Table, cost, sqlconfig.sql_NAME, cdkey); + if(!sasql_mysql_query(sqlstr)){ + return 1; + } + } + }else{ + return -2; + } + } + }else{ + return -1; + } + } + return 0; +} + +BOOL sasql_delPauctionBuy( int id, char *cdkey ) +{ + char sqlstr[1024]; + + if(strlen(cdkey)>0){ + sprintf(sqlstr, "delete from `PauctionInfo` where `id` = %d AND `cdkey` = BINARY'%s'", id, cdkey); + }else{ + sprintf(sqlstr, "delete from `PauctionInfo` where `id` = %d", id); + } + + if(!sasql_mysql_query(sqlstr)){ + return TRUE; + } + + return FALSE; +} +#endif +#ifdef _JZ_NEWSCRIPT_LUA +int sasql_vippoint( char *ID, int point, int flag ) +{ + char sqlstr[256]; +// print("\NVIPpoint1=%d\n",point); + if(strstr(ID,"'")!=NULL) return -1; + sprintf(sqlstr,"select `VipPoint` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID); +// printf("22222222:%s\n",sqlstr); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(flag==0){ + return atoi(mysql_row[0]); + } + if(flag==520){ + sprintf(sqlstr,"update `%s` set `VipPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID); + }else{ + point+=atoi(mysql_row[0]); + sprintf(sqlstr,"update `%s` set `VipPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID); + } + if(!mysql_query(&mysql,sqlstr)){ + return point; + }else{ + return atoi(mysql_row[0]); + } + }else{ + //mysql_free_result(mysql_result); + } + } + printf("½ʧܣ-- %s\n",sqlstr); + return -1; +} + +int sasql_ampoint( char *ID, int point, int flag ) +{ + char sqlstr[256]; + mj_sprintf(sqlstr,"select `AmPoint` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(flag==0){ + return atoi(mysql_row[0]); + } + point+=atoi(mysql_row[0]); + mj_sprintf(sqlstr,"update `%s` set `AmPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID); + if(!mysql_query(&mysql,sqlstr)){ + return point; + }else{ + return atoi(mysql_row[0]); + } + }else{ +// mysql_free_result(mysql_result); + } + } + print("%sʧܣ\n",ID); + return -1; +} + +int sasql_rmbpoint( char *ID, int point, int flag ) +{ + char sqlstr[256]; + mj_sprintf(sqlstr,"select `RMBPOINT` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(flag==0){ + return atoi(mysql_row[0]); + } + point+=atoi(mysql_row[0]); + mj_sprintf(sqlstr,"update `%s` set `RMBPOINT`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID); + if(!mysql_query(&mysql,sqlstr)){ + return point; + }else{ + return atoi(mysql_row[0]); + } + }else{ + // mysql_free_result(mysql_result); + } + } + print("%sRMBʧܣ\n",ID); + return -1; +} + +#endif + +#ifdef _MO_LNS_MYSQLSUOXU + +struct youx{ + int result; + int flg; + int errnono; + char* errstr; + int fieldCount; + int rowCount; + int rowAt; +}retlua; + +void sasql_LUASQLAdv(char* sqlstr,char* filepath,char* function,int npcindex ,int charaindex,char* msg,int flg) +{ + char* data = sasql_LuaAdv_QueryR(sqlstr,flg); + NPC_Lua_SQLPushAdvCallBack(retlua.result,retlua.flg,retlua.errnono,retlua.errstr,retlua.fieldCount ,retlua.rowCount ,retlua.rowAt, data,filepath,function,npcindex,charaindex,msg ); +} +char* sasql_LuaAdv_QueryR(char *sqlstr,int flg) +{ + int rowAtt = 0; + static char buff[1024] = ""; + snprintf(buff,1024, ""); + buff[1023]='\0'; + /*ʼϢ*/ + retlua.result = 0;//ERROR + retlua.flg = flg;// + retlua.errnono = 0;//MYSQL + retlua.errstr = "";//MYSQLϢ + retlua.fieldCount = 0;//ѯĿ + retlua.rowCount = 0;//ѯ + retlua.rowAt = 0;//ǰ¼ + + + if (flg == 1 || flg == 2){ + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result);// + if (mysql_result == NULL) + { + retlua.result = -2; + }else if (mysql_eof(mysql_result)) + { + retlua.result = -3; + } + + if(num_row>0){ + + mysql_row = mysql_fetch_row(mysql_result);//Ӳѯȡһ + + retlua.errnono = mysql_errno(&mysql);// + retlua.errstr = mysql_error(&mysql);//Ϣ + retlua.fieldCount = mysql_field_count(&mysql);// + + retlua.rowCount = num_row;// + rowAtt++; + retlua.rowAt = rowAtt;//ǰ + if (flg == 1){ + mysql_free_result(mysql_result);//ͷŽ + mysql_result = NULL; + rowAtt = 0; + } + + int i; + for (i=0;i 15) retlua.result = -1; + return buff; + }else { + retlua.errnono = mysql_errno(&mysql); + retlua.errstr = mysql_error(&mysql); + } + } + }else if (flg == 3){ + + + int num_row=0; + if (mysql_result == NULL) { + retlua.result = -2; + return "Ѿͷš"; + } + num_row=mysql_num_rows(mysql_result);// + if (mysql_eof(mysql_result)) + { + retlua.result = -3;//Ѵﵽβˣȸѣѯ潫Զͷš + } + if (num_row == rowAtt) { + mysql_free_result(mysql_result);//ͷŽ + mysql_result = NULL; + rowAtt = 0; + retlua.result = -3; + return "ѵβУԶͷŽ"; + } + if(num_row>0){ + mysql_row = mysql_fetch_row(mysql_result);//Ӳѯȡһ + retlua.errnono = mysql_errno(&mysql);// + retlua.errstr = mysql_error(&mysql);//Ϣ + rowAtt++; + retlua.rowAt = rowAtt;//ǰ + retlua.fieldCount = mysql_field_count(&mysql);// + retlua.rowCount = num_row;// + if (num_row > 15) retlua.result = -1; + int i; + for (i=0;i0){ + mysql_row = mysql_fetch_row(mysql_result); + return (char*)mysql_row[row]; + } + }else + return "SQL Query ERROR"; +} +#endif + +#endif + +int sasql_check_iponline( char *IP ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select * from `%s` where `IP`='%s'",sqlconfig.sql_Table,IP); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + return 1; + }else{ + return 0; + } + } + return -1; +} + +int sasql_query_online_ip(char *IP){ + char sqlstr[256]; + sprintf(sqlstr,"select * from `OnlineIP` where `IP`='%s'",IP); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + return 1; + }else{ + return 0; + } + } + return -1; +} + +int sasql_query(char *nm, char *pas){ + char sqlstr[256]; + sprintf(sqlstr,"select `%s`,`Password`,`SafePasswd`,`Lock` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_NAME,sqlconfig.sql_Table,sqlconfig.sql_NAME,nm); + //print(sqlstr); + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + + if(mysql_row[2]!=NULL){ + if((strcmp(pas,mysql_row[1]) == 0) && (atoi(mysql_row[3])==0 || atoi(mysql_row[3])==getLockType())){ + return 1; + }else{ + //printf("û%s\n",nm); + return 2; + } + }else + { + if(strcmp(pas,mysql_row[1]) == 0 && atoi(mysql_row[3])==0){ + return 1; + }else{ + //printf("û%s\n",nm); + return 2; + } + } + }else{ + //printf("û%sδעᣡ\n",nm); + return 3; + } + }else{ + //printf("\nݿʧܣ\n"); + return 0; + } +} +#ifdef _MO_LOGIN_NO_KICK +BOOL sasql_CheckPasswd( char *id, char *passwd ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַ%s\n",id); + return FALSE; } + if(sasql_ckeckStrint(passwd) == FALSE){ + printf("쳣ַ%s\n",passwd); + return FALSE; + } + char sqlstr[256]; + sprintf(sqlstr,"select `PassWord` from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + if(strcmp(passwd, mysql_row[0])==0){ + return TRUE; + }else{ + return FALSE; + } + }else{ + return FALSE; + } + } + } + return FALSE; +} +#endif +#ifdef _NEW_SQL_MONEY +int sasql_setSQLPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set SQLPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!mysql_query(&mysql,sqlstr)){ + return point; + } + return -1; +} + +int sasql_getSQLPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select SQLPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + // mysql_free_result(mysql_result); + + return atoi(mysql_row[0]); + } + } + printf("\nݿʧ[20]\n"); + printf("ݿ[3]..."); +// sasql_close(); +// sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setGoldPoint( int charaindex, int point ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"update %s set GoldPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id); + + if(!mysql_query(&mysql,sqlstr)){ + return point; + } + return -1; +} + +int sasql_getGoldPoint( int charaindex ) +{ + char sqlstr[256]; + char *id = CHAR_getChar(charaindex, CHAR_CDKEY); + sprintf(sqlstr,"select GoldPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + // mysql_free_result(mysql_result); + + return atoi(mysql_row[0]); + } + } + printf("\nݿʧ[21]\n"); + printf("ݿ[3]..."); +// sasql_close(); +// sasql_init(); + printf("\n"); + return -1; +} +int sasql_setSQLPointByCdkey( char* cdkey, int point ) +{ + char sqlstr[256]; + sprintf(sqlstr,"update %s set SQLPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, cdkey); + + if(!mysql_query(&mysql,sqlstr)){ + return point; + } + return -1; +} + +int sasql_getSQLPointByCdkey( char* cdkey ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select SQLPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, cdkey); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + // mysql_free_result(mysql_result); + + return atoi(mysql_row[0]); + } + } + printf("\nݿʧ[22]\n"); + printf("ݿ[3]..."); +// sasql_close(); +// sasql_init(); + printf("\n"); + return -1; +} + +int sasql_setGoldPointByCdkey( char* cdkey, int point ) +{ + char sqlstr[256]; + sprintf(sqlstr,"update %s set GoldPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, cdkey); + + if(!mysql_query(&mysql,sqlstr)){ + return point; + } + return -1; +} + +int sasql_getGoldPointByCdkey( char* cdkey ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select GoldPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, cdkey); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + // mysql_free_result(mysql_result); + + return atoi(mysql_row[0]); + } + } + printf("\nݿʧ[23]\n"); + printf("ݿ[3]..."); +// sasql_close(); +// sasql_init(); + printf("\n"); + return -1; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.dat b/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.dat new file mode 100644 index 0000000..54e06f7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.dat @@ -0,0 +1,13 @@ +#ifndef LS2DATA_DAT +#define LS2DATA_DAT + +typedef struct { + int hash; + char *name; + int graphicnumber; +} CconvertStringNumber; + +CconvertStringNumber *convertStringNumber; +int cconvertStringNumber; + +#endif // LS2DATA_DAT ///:~ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.h b/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.h new file mode 100644 index 0000000..dbc6254 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/ls2data.h @@ -0,0 +1,13 @@ +#ifndef LS2DATA_DAT +#define LS2DATA_DAT + +typedef struct { + int hash; + char *name; + int graphicnumber; +} CconvertStringNumber; + +CconvertStringNumber *convertStringNumber; +int cconvertStringNumber; + +#endif // LS2DATA_DAT ///:~ \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_serv.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_serv.c new file mode 100644 index 0000000..88018d6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_serv.c @@ -0,0 +1,3894 @@ +#include "version.h" +#include "autil.h" +#include "lssproto_serv.h" +#include "common.h" // for StoneAge +#include "log.h" // for StoneAge +#include "char.h" +#include "battle.h" +#include "descrypt.h" +#include "configfile.h" +#include +#include +#include +#include +#include "shop.h" +#include "npc_lua_interface.h" +#ifdef _ABSOLUTE_DEBUG +extern char charId[32]; +extern char errordata[256]; +extern int lastfunctime; +#endif + +void lssproto_SetServerLogFiles( char *r , char *w ) +{ + lssproto_strcpysafe( lssproto_writelogfilename , w , sizeof(lssproto_writelogfilename )); + lssproto_strcpysafe( lssproto_readlogfilename , r , sizeof(lssproto_readlogfilename )); +} +int lssproto_InitServer( int (*writefunc)(int,char*,int) , int worksiz ) +{ + int i; + if( (void*)writefunc == NULL) { + lssproto.write_func = lssproto_default_write_wrap; + } else { + lssproto.write_func = writefunc; + } + lssproto_AllocateCommonWork(worksiz); + lssproto_stringwrapper = (char**)calloc( 1,sizeof(char*) * MAXLSRPCARGS); + if(lssproto_stringwrapper ==NULL) + return -1; + memset( lssproto_stringwrapper , 0, sizeof(char*)*MAXLSRPCARGS); + for(i=0;i",fd,__LINE__,func) +extern int cliretfunc; +int lssproto_ServerDispatchMessage(int fd, char *encoded) +{ +#ifdef _DEFEND_BIGBAO + if(CONNECT_getState(fd) == NOTLOGIN){ + if (strlen(encoded)>getBigBao()){ + close(fd); + return -1; + } + }else{ + if(strlen(encoded)>getBigBao2()){ + close(fd); + return -1; + } + } +#endif + + int func,fieldcount; + char raw[1024 * 64]; +#ifdef _SERVER_DEF + util_DiscardMessage(); +#endif + CONNECT_getCdkey( fd, PersonalKey, 4096); + strcat(PersonalKey, _RUNNING_KEY); +#ifdef _NEW_FUNC_DECRYPT + if(!util_DecodeMessageTea(raw,encoded)) { + return -2; + } +#else + util_DecodeMessage(raw,encoded); +#endif +#ifdef _DEBUG_RET + print("\nraw=%s\n",raw); +#endif + if( !util_SplitMessage(raw,SEPARATOR) ){ + //print("\nDME1:package=%s\n",raw); + DME(); return -2; + } + if (!util_GetFunctionFromSlice(&func, &fieldcount)) { + logHack(fd,HACK_GETFUNCFAIL); + DME(); return -1; + } + +#ifdef _MO_SHOW_DEBUG + if (isDebug()==1) { + printf("\nͻ˽ӿ=%d\n",func); + } + if (func 0 && FD_ISSET( fd , &wfds ) ) { + ret=send(fd,compr,comprLen+55,0); + if ( ret == -1 && errno != EINTR ) { +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CONNECT_getCharaindex( fd ),charname,32); + CONNECT_getCdkey(CONNECT_getCharaindex( fd ),cdkey,16); + char token[128]; + sprintf(token, "̳ send T ret=%d errno=%s",ret, strerror(errno)); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + + CONNECT_endOne_debug( fd ); + } + }else if( ret < 0 && errno != EINTR ){ +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CONNECT_getCharaindex( fd ),charname,32); + CONNECT_getCdkey(CONNECT_getCharaindex( fd ),cdkey,16); + char token[128]; + sprintf(token, "̳ select T ret=%d errno=%s",ret, strerror(errno)); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + + CONNECT_endOne_debug(fd ); + } +} + +void lssproto_ShopOK_send(int fd) +{ + char buffer[1024 * 64]; + strcpy(buffer, ""); + int checksum = 0; + checksum += util_mkint(buffer, 0); + util_mkint(buffer, checksum); + util_SendMesg(fd, LSSPROTO_SHOPOK_SEND, buffer); +} + +#ifdef _FAMILYBADGE_ +void lssproto_FamilyBadge_send(int fd, char *data) +{ + if( CONNECT_checkfd(fd) == FALSE )return; +#ifdef _DEBUG_SEND_CLI + printf("[]lssproto_FamilyBadge_send-data:%s\n", data); +#endif + char buffer[65500]; + int checksum=0; + + strcpy(buffer,""); + + CONNECT_getCdkey( fd, PersonalKey, 4096); + strcat(PersonalKey, _RUNNING_KEY); + + checksum += util_mkstring(buffer, data); + + util_mkint(buffer, checksum); + util_SendMesg(fd, LSSPROTO_FAMILYBADGE_SEND, buffer); +} +#endif +#ifdef _NEW_TITLE +void lssproto_CharTitle_send(int fd,char* data)// +{ + char buffer[1024 * 64]; + int checksum=0; + strcpy(buffer,""); + CONNECT_getCdkey( fd, PersonalKey, 4096); + strcat(PersonalKey, _RUNNING_KEY); + + checksum += util_mkstring(buffer, data); + util_mkint(buffer, checksum); + util_SendMesg(fd, LSSPROTO_CHARTITLE_SEND, buffer); + char msg[256]; + int fd_charaindex = CONNECT_getCharaindex(fd); + sprintf(msg,"4|%d",CHAR_getInt( fd_charaindex, CHAR_TITLE_DEFAULT )); + lssproto_CHAREFFECT_send(getfdFromCharaIndex(fd_charaindex), msg); +} +#endif + +#ifdef _VISUAL_BEATITUDE +void lssproto_VisualBeatitude_send(int fd,char* data) +{ + char buffer[1024 * 64]; + int checksum=0; + strcpy(buffer,""); + CONNECT_getCdkey( fd, PersonalKey, 4096); + strcat(PersonalKey, _RUNNING_KEY); + + checksum += util_mkstring(buffer, data); + util_mkint(buffer, checksum); + util_SendMesg(fd, LSSPROTO_VB_SEND, buffer); +} +#endif + + +#ifdef _RED_MEMOY_ +void lssproto_RedMemoy_send(int fd,int type,int time,int vip,char *name,int index) +{ + if( CONNECT_checkfd(fd) == FALSE )return; + char buffer[65500]; + int checksum=0; + strcpy(buffer,""); + CONNECT_getCdkey( fd, PersonalKey, 4096); + strcat(PersonalKey, _RUNNING_KEY); + + checksum += util_mkint(buffer, type); + checksum += util_mkint(buffer, time); + checksum += util_mkint(buffer, vip); + checksum += util_mkstring(buffer, name); + checksum += util_mkint(buffer, index); + util_mkint(buffer, checksum); + util_SendMesg(fd, LSSPROTO_REDMEMOY_SEND, buffer); +} +#endif + +#ifdef _MOVE_SCREEN +void lssproto_MoveScreen_send(int fd, BOOL bMoveScreenMove, int iXY) +{ + char szBuffer[65500]; + int iChecksum = 0; +#ifdef _DEBUG_SEND_CLI + printf("[]LSSPROTO_MOVESCREEN_SEND-fd:%d,bMoveScreenMove:%d,iXY:%d\n",fd,bMoveScreenMove,iXY); +#endif + szBuffer[0] = '\0'; + + CONNECT_getCdkey(fd, PersonalKey, 4096); +#ifdef _NEW_ENCRYT + CONNECT_catRunKey(fd, PersonalKey); +#else + strcat(PersonalKey, _RUNNING_KEY); +#endif + iChecksum += util_mkint(szBuffer, bMoveScreenMove); + iChecksum += util_mkint(szBuffer, iXY); + util_mkint(szBuffer, iChecksum); + util_SendMesg(fd, LSSPROTO_MOVE_SCREEN_SEND, szBuffer); +} +#endif + +#ifdef _THEATER +void lssproto_TheaterData_send(int fd, char *pData) +{ + int iChecksum = 0; + char szBuffer[65500]; +#ifdef _DEBUG_SEND_CLI + printf("[]LSSPROTO_TheaterData_SEND-fd:%d,pData:%s\n",fd,pData); +#endif + strcpy(szBuffer,""); + + CONNECT_getCdkey(fd, PersonalKey, 4096); +#ifdef _NEW_ENCRYT + CONNECT_catRunKey(fd, PersonalKey); +#else + strcat(PersonalKey, _RUNNING_KEY); +#endif + iChecksum += util_mkstring(szBuffer, pData); + util_mkint(szBuffer, iChecksum); + util_SendMesg(fd, LSSPROTO_THEATER_DATA_SEND, szBuffer); +} +#endif + +#ifdef _NPC_MAGICCARD +void lssproto_MagiccardAction_send(int fd, char *data) +{ + char buffer[65500]; + int checksum = 0; +#ifdef _DEBUG_SEND_CLI + printf("[]LSSPROTO_MagiccardAction_SEND-fd:%d,data:%s\n",fd,data); +#endif + strcpy(buffer,""); + + CONNECT_getCdkey(fd,PersonalKey,4096); +#ifdef _NEW_ENCRYT + CONNECT_catRunKey(fd, PersonalKey); +#else + strcat(PersonalKey, _RUNNING_KEY); +#endif + checksum += util_mkstring(buffer,data); + util_mkint(buffer,checksum); + util_SendMesg(fd,LSSPROTO_MAGICCARD_ACTION_SEND,buffer); +} + +void lssproto_MagiccardDamage_send(int fd, int position ,int damage ,int offsetx,int offsety ) +{ + char buffer[65500]; + int checksum = 0; +#ifdef _DEBUG_SEND_CLI + printf("[]LSSPROTOMagiccardDamage_SEND-fd:%d,position:%d,damage:%d,offsetx:%d,offsety:%d\n",fd,position,damage,offsetx,offsety); +#endif + strcpy(buffer,""); + + CONNECT_getCdkey(fd,PersonalKey,4096); +#ifdef _NEW_ENCRYT + CONNECT_catRunKey(fd, PersonalKey); +#else + strcat(PersonalKey, _RUNNING_KEY); +#endif + checksum += util_mkint(buffer, position ); + checksum += util_mkint(buffer, damage ); + checksum += util_mkint(buffer, offsetx ); + checksum += util_mkint(buffer, offsety ); + util_mkint(buffer,checksum); + util_SendMesg(fd,LSSPROTO_MAGICCARD_DAMAGE_SEND,buffer); +} +#endif + +#ifdef _NPC_DANCE +void lssproto_DancemanOption_send(int fd, int option ) +{ + char buffer[65500]; + int checksum = 0; +#ifdef _DEBUG_SEND_CLI + printf("[]lssproto_DancemanOption_send-fd:%d,option:%d\n", fd, option); +#endif + strcpy(buffer,""); + + CONNECT_getCdkey(fd,PersonalKey,4096); +#ifdef _NEW_ENCRYT + CONNECT_catRunKey(fd, PersonalKey); +#else + strcat(PersonalKey, _RUNNING_KEY); +#endif + checksum += util_mkint(buffer, option ); + util_mkint(buffer,checksum); + util_SendMesg(fd,LSSPROTO_DANCEMAN_OPTION_SEND,buffer); +} +#endif + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_util.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_util.c new file mode 100644 index 0000000..ca66441 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lssproto_util.c @@ -0,0 +1,1475 @@ +#define _LSSPROTOUTIL_C_ +#include "version.h" +#include +#include +#include +#ifndef WIN32 +#include +#include +#endif +#include "lssproto_util.h" +//ttom +2 for degug +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + +#include "common.h" +#ifdef lssproto__ENCRYPT +long lssproto_ringoCompressor( unsigned char *code , long codelen , unsigned char *text , long textlen); +long lssproto_ringoDecompressor( unsigned char *text , long textlen , unsigned char *code , long codelen); +#endif +/* + lsrpc routines +*/ +int lssproto_AllocateCommonWork(int bufsiz) +{ + lssproto.workbufsize = bufsiz; + lssproto.work = NULL; + lssproto.arraywork = NULL; + lssproto.escapework = NULL; + lssproto.val_str = NULL; + lssproto.token_list = NULL; + lssproto.cryptwork = NULL; + lssproto.jencodecopy = NULL; + lssproto.jencodeout = NULL; + lssproto.compresswork = NULL; + lssproto.work = (char*)calloc( 1, lssproto.workbufsize ); + lssproto.arraywork = (char*)calloc( 1, lssproto.workbufsize ); + lssproto.escapework = (char*)calloc( 1, lssproto.workbufsize ); + lssproto.val_str = (char*)calloc( 1, lssproto.workbufsize ); + lssproto.token_list = (char**)calloc( 1, lssproto.workbufsize *sizeof( char** ) ); + lssproto.cryptwork = (char*)calloc( 1, lssproto.workbufsize * 3 ); + lssproto.jencodecopy = (char*)calloc( 1, lssproto.workbufsize * 3 ); + lssproto.jencodeout = (char*)calloc( 1, lssproto.workbufsize * 3 ); + lssproto.compresswork = (char*)calloc( 1, lssproto.workbufsize * 3 ); + memset( lssproto.work , 0, lssproto.workbufsize ); + memset( lssproto.arraywork , 0, lssproto.workbufsize ); + memset( lssproto.escapework , 0, lssproto.workbufsize ); + memset( lssproto.val_str , 0, lssproto.workbufsize ); + memset( (char*)lssproto.token_list ,0, lssproto.workbufsize*sizeof(char**) ); + memset( lssproto.cryptwork , 0, lssproto.workbufsize*3 ); + memset( lssproto.jencodecopy , 0, lssproto.workbufsize*3 ); + memset( lssproto.jencodeout , 0, lssproto.workbufsize*3 ); + memset( lssproto.compresswork , 0, lssproto.workbufsize*3 ); + if( lssproto.work == NULL || + lssproto.arraywork == NULL || + lssproto.escapework == NULL || + lssproto.val_str == NULL || + lssproto.token_list == NULL || + lssproto.cryptwork == NULL || + lssproto.jencodecopy == NULL || + lssproto.jencodeout == NULL || + lssproto.compresswork == NULL ){ + free( lssproto.work);free( lssproto.val_str); + free( lssproto.escapework);free( lssproto.arraywork ); + free( lssproto.token_list);free( lssproto.cryptwork ); + free( lssproto.jencodecopy);free( lssproto.jencodeout ); + free( lssproto.compresswork ); + return -1; + } + return 0; +} +/********** + Get message information from a network input +**********/ +void lssproto_GetMessageInfo( int *id , char *funcname , int len, char **tk ) +{ + if( tk[0] == NULL || tk[1] == NULL ){ + *id = 0; + lssproto_strcpysafe( funcname , "" , len ); + return; + } + *id = strtoul( tk[0] ,NULL,10); + lssproto_strcpysafe( funcname , tk[1] , len ); + return; +} +/******************************************** + string utilities +*********************************************/ +void lssproto_strcpysafe( char *dest, char *src, int maxlen ) +{ + int i; + for(i=0;i (int)( lssproto.workbufsize*3-2) ){ + fprintf( stderr, "lsgen: badly configured work buflen\n" ); + exit(1); + } + if( (flag%2) == 1 ) flag ++; + lssproto.compresswork[0] = flag; + memcpy( lssproto.compresswork+1,src,srclen ); + compressed_l = srclen + 1; + } else { + if((flag%2)==0)flag++; + lssproto.compresswork[0] = flag; + compressed_l = lssproto_ringoCompressor( + (unsigned char*)lssproto.compresswork + 1 , + (long)lssproto.workbufsize*3 - 1, + (unsigned char*)src , + (long)strlen(src) ) + 1; /* be careful! */ + } + /* return empty line if error or buffer excess */ + if( compressed_l <= 0 ){ + lssproto_strcpysafe( out , "\n" , maxoutlen ); + return; + } + memcpy( lssproto.jencodecopy ,lssproto.compresswork ,compressed_l ); + lssproto_jEncode( lssproto.jencodecopy , compressed_l , JENCODE_KEY , + lssproto.jencodeout, &jencodedlen , lssproto.workbufsize*3 -1 ); + lssproto_encode64( (unsigned char*)lssproto.jencodeout , jencodedlen, (unsigned char*)out ); +} +/* translate code64 text to original lsrpc text */ +static void lssproto_decodeString( char *src , char *out ) +{ + int compressed_l =0, outlen64; + int l; + long decompressed_l = 0; + /* copy src to copybuffer because jencoder modifies the input buffer */ + l = strlen( src ); + if( src[l-1]=='\n' || src[l-1]=='\r' )src[l-1]=0; + if( src[l-2]=='\n' || src[l-2]=='\r' )src[l-2]=0; + outlen64 = lssproto_decode64( (unsigned char*)src , (unsigned char*)lssproto.jencodecopy ); + lssproto_jDecode( lssproto.jencodecopy , outlen64 , JENCODE_KEY, + lssproto.compresswork , &compressed_l); + /*out[outlen]=0; PENDING*/ + if( (lssproto.compresswork[0] % 2 ) == 0 ){ + if( compressed_l <= 0 ){ + decompressed_l = 0; + fprintf( stderr, "LSRPC: too short:[%s]\n", src ); + } else { + memcpy( out, lssproto.compresswork+1, compressed_l -1 ); + decompressed_l = compressed_l -1; + } + } else { + decompressed_l = + lssproto_ringoDecompressor( (unsigned char*)out , + (long)lssproto.workbufsize , + (unsigned char*)lssproto.compresswork+1 , + (long)compressed_l -1 ); + } + out[decompressed_l] = 0; +} +/* followings are taken from code64.c */ +char lssproto_charset[64]={ + 'A','B','C','D', 'E','F','G','H', + 'I','J','K','L', 'M','N','O','P', + 'Q','R','S','T', 'U','V','W','X', + 'Y','Z','a','b', 'c','d','e','f', + 'g','h','i','j', 'k','l','m','n', + 'o','p','q','r', 's','t','u','v', + 'w','x','y','z', '0','1','2','3', + '4','5','6','7', '8','9','+','-' +}; +char lssproto_reversecharset[256]={ + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,62, 0,63,0,0, + 52,53,54,55, 56,57,58,59, + 60,61,0,0, 0,0,0,0, + 0,0,1,2, 3,4,5,6, + 7,8,9,10, 11,12,13,14, + 15,16,17,18, 19,20,21,22, + 23,24,25,0, 0,0,0,0, + 0,26,27,28, 29,30,31,32, + 33,34,35,36, 37,38,39,40, + 41,42,43,44, 45,46,47,48, + 49,50,51,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0 +}; + +static void lssproto_encode64( unsigned char *in , int len , unsigned char *out ) +{ + int i; + int use_bytes; + int address = 0; + out[0] = 0; + for(i=0;;i+=3){ + unsigned char in1 , in2 , in3; + unsigned char out1 ,out2 , out3 , out4; + if( i >= len ) break; + if( i >= (len-1)){ /* the last letter ( to be thrown away ) */ + in1 = in[i] & 0xff; + in2 = in3 = 0; + use_bytes = 2; + } else if( i >= (len-2)){ /* the last 2 letters ( process only 1 byte)*/ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = 0; + use_bytes = 3; + } else { /* there are more or equal than 3 letters */ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = in[i+2] & 0xff; + use_bytes = 4; + } + out1 = ((in1 & 0xfc)>>2) & 0x3f; + out2 = ((in1 & 0x03)<<4) | ((( in2 & 0xf0)>>4)&0x0f); + out3 = ((in2 & 0x0f)<<2) | ((( in3 & 0xc0)>>6)&0x03); + out4 = (in3 & 0x3f ); + if( use_bytes >= 2 ){ + out[address++] = lssproto_charset[out1]; + out[address++] = lssproto_charset[out2]; + out[address]=0; + } + if( use_bytes >= 3 ){ + out[address++] = lssproto_charset[out3]; + out[address]=0; + } + if( use_bytes >= 4 ){ + out[address++] = lssproto_charset[out4]; + out[address]=0; + } + } +} +/* + * Decode it + * char *in : encoded ascii chars + * char *out : decoded( output) + * return value : output byte count + * + * note: no need to have bigger buffer. because output is to + * be smaller than input string size + */ +static int lssproto_decode64( unsigned char *in , unsigned char *out ) +{ + unsigned char in1 , in2 , in3 , in4; + unsigned char out1 , out2 , out3; + int use_bytes; + int address= 0; + int i; + for(i=0;;i+=4 ){ + if( in[i] == 0 ){ + break; + } else if( in[i+1] == 0 ){ /* the last letter */ + break; + } else if( in[i+2] == 0 ){ /* the last 2 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = in4 = 0; + use_bytes = 1; + } else if( in[i+3] == 0 ){ /* the last 3 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = lssproto_reversecharset[in[i+2]]; + in4 = 0; + use_bytes = 2; + } else { /* process 4 letters */ + in1 = lssproto_reversecharset[in[i]]; + in2 = lssproto_reversecharset[in[i+1]]; + in3 = lssproto_reversecharset[in[i+2]]; + in4 = lssproto_reversecharset[in[i+3]]; + use_bytes = 3; + } + out1 = (in1<<2) | (((in2 & 0x30)>>4)&0x0f) ; + out2 = ((in2 & 0x0f )<<4) | ((( in3 & 0x3c)>>2)&0x0f); + out3 = ( (in3 &0x03)<<6) | ( in4 & 0x3f ); + if( use_bytes >= 1 ){ + out[address++] = out1; + } + if( use_bytes >= 2 ){ + out[address++] = out2; + } + if( use_bytes >= 3 ){ + out[address++] = out3; + } + if( use_bytes != 3 ){ + break; + } + } + return address; +} + +/* followings are taken from Jencode.c by jun */ +static void lssproto_jEncode(char *src,int srclen,int key,char *encoded,int *encodedlen,int maxencodedlen) +{ + char sum=0; + int i; + if(srclen+1 > maxencodedlen){ + *encodedlen = maxencodedlen; + for(i=0;i<(*encodedlen);i++)encoded[i] = src[i]; + } + if(srclen+1 <= maxencodedlen){ + *encodedlen=srclen+1; + for(i=0;i i) encoded[i] = src[i] + sum*((i*i)%3); + if(abs((key%srclen)) == i) encoded[i] = sum; + if(abs((key%srclen)) < i) encoded[i] = src[i-1] + sum*((i*i)%7); + } + } +} +static void lssproto_jDecode(char *src,int srclen,int key,char *decoded,int *decodedlen) +{ + char sum=0; + int i; + *decodedlen=srclen-1; + if( *decodedlen == 0 ){ + return; /* return error if length is 0 */ + } + sum = src[abs(key%(*decodedlen))]; + for(i=0;i i) decoded[i] = src[i] - sum*((i*i)%3); + if(abs((key%(*decodedlen))) < i) decoded[i-1] = src[i] - sum*((i*i)%7); + } + for(i=0;i<(*decodedlen);i++){ + if(((key%7) == (i%5))||((key%2) == (i%2)))decoded[i] = ~decoded[i]; + } +} + +/*****************************************************************/ +/* Compress / Decompress routine */ +/*****************************************************************/ +#define B00000000 0 +#define B00000001 1 +#define B00000010 2 +#define B00000011 3 +#define B00000100 4 +#define B00000101 5 +#define B00000110 6 +#define B00000111 7 +#define B00001000 8 +#define B00001001 9 +#define B00001010 10 +#define B00001011 11 +#define B00001100 12 +#define B00001101 13 +#define B00001110 14 +#define B00001111 15 +#define B00010000 16 +#define B00010001 17 +#define B00010010 18 +#define B00010011 19 +#define B00010100 20 +#define B00010101 21 +#define B00010110 22 +#define B00010111 23 +#define B00011000 24 +#define B00011001 25 +#define B00011010 26 +#define B00011011 27 +#define B00011100 28 +#define B00011101 29 +#define B00011110 30 +#define B00011111 31 +#define B00100000 32 +#define B00100001 33 +#define B00100010 34 +#define B00100011 35 +#define B00100100 36 +#define B00100101 37 +#define B00100110 38 +#define B00100111 39 +#define B00101000 40 +#define B00101001 41 +#define B00101010 42 +#define B00101011 43 +#define B00101100 44 +#define B00101101 45 +#define B00101110 46 +#define B00101111 47 +#define B00110000 48 +#define B00110001 49 +#define B00110010 50 +#define B00110011 51 +#define B00110100 52 +#define B00110101 53 +#define B00110110 54 +#define B00110111 55 +#define B00111000 56 +#define B00111001 57 +#define B00111010 58 +#define B00111011 59 +#define B00111100 60 +#define B00111101 61 +#define B00111110 62 +#define B00111111 63 +#define B01000000 64 +#define B01000001 65 +#define B01000010 66 +#define B01000011 67 +#define B01000100 68 +#define B01000101 69 +#define B01000110 70 +#define B01000111 71 +#define B01001000 72 +#define B01001001 73 +#define B01001010 74 +#define B01001011 75 +#define B01001100 76 +#define B01001101 77 +#define B01001110 78 +#define B01001111 79 +#define B01010000 80 +#define B01010001 81 +#define B01010010 82 +#define B01010011 83 +#define B01010100 84 +#define B01010101 85 +#define B01010110 86 +#define B01010111 87 +#define B01011000 88 +#define B01011001 89 +#define B01011010 90 +#define B01011011 91 +#define B01011100 92 +#define B01011101 93 +#define B01011110 94 +#define B01011111 95 +#define B01100000 96 +#define B01100001 97 +#define B01100010 98 +#define B01100011 99 +#define B01100100 100 +#define B01100101 101 +#define B01100110 102 +#define B01100111 103 +#define B01101000 104 +#define B01101001 105 +#define B01101010 106 +#define B01101011 107 +#define B01101100 108 +#define B01101101 109 +#define B01101110 110 +#define B01101111 111 +#define B01110000 112 +#define B01110001 113 +#define B01110010 114 +#define B01110011 115 +#define B01110100 116 +#define B01110101 117 +#define B01110110 118 +#define B01110111 119 +#define B01111000 120 +#define B01111001 121 +#define B01111010 122 +#define B01111011 123 +#define B01111100 124 +#define B01111101 125 +#define B01111110 126 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 +/* masks for first byte ( write )*/ +int lssproto_modifymask_first[8][9]={ + {0, B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111},/* mod 0*/ + {0, B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111},/* mod 1*/ + {0, B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111},/* mod 2*/ + {0, B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111},/* mod 3*/ + {0, B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 4*/ + {0, B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 5*/ + {0, B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 6*/ + {0, B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 7*/ +}; +/* masks for second byte ( write ) */ +int lssproto_modifymask_second[8][9]={ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},/* mod 0 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001},/* mod 1 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011},/* mod 2 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111},/* mod 3 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111},/* mod 4 */ + {0, B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111},/* mod 5 */ + {0, B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111},/* mod 6 */ + {0, B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111},/* mod 7 */ +}; +/* + * used by bitstream routines + */ +int bitstream_maxbyte, bitstream_bitaddr ; +char *bitstream_buf; +/* initialize bitstream for output */ +static int initOutputBitStream( char *buf ,int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + memset( buf,0, buflen); + return 0; +} +/* initialize bitstream for input */ +static int initInputBitStream( char *buf , int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + return 0; +} +/* + * read from bit stream. used only from 1 bit to 8 bits + * this is a base routine + */ +static unsigned int readInputBitStreamBody( int bwidth ) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return if excess */ + if( byteaddr >= bitstream_maxbyte)return 0; + if( bwidth >= 1 && bwidth <= 8){ + int b1 = (( bitstream_buf[byteaddr] & lssproto_modifymask_first[mod][bwidth] )>>mod); + int b2 = (( bitstream_buf[byteaddr+1] & lssproto_modifymask_second[mod][bwidth])<<(8-mod)); + bitstream_bitaddr += bwidth; + return b1 | b2; + } else { + return 0; + } +} +/* + * read from bit stream. used from 1 bit to 32 bits + * + */ +static unsigned int readInputBitStream( int bwidth ) +{ + if( bwidth <= 0 ){ + return 0; + } else if( bwidth >= 1 && bwidth <= 8 ){ + return readInputBitStreamBody( bwidth ); + } else if( bwidth >= 9 && bwidth <= 16 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody( bwidth-8); + return first + (second << 8 ); + } else if( bwidth >= 17 && bwidth <= 24 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ); + } else if( bwidth >= 25 && bwidth <= 32 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(8); + unsigned int forth = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ) + ( forth << 24 ); + } + return 0; +} +/* + * write to a bitstream. only used from 1 bit to 8 bits + * this is a base routine. + */ +static int writeOutputBitStreamBody( int bwidth , unsigned char b) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return error if excess */ + if( bitstream_maxbyte <= (byteaddr+1)) return -1; + bitstream_buf[byteaddr] &= lssproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr] |= (b << mod) & lssproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr+1] &= lssproto_modifymask_second[mod][bwidth]; + bitstream_buf[byteaddr+1] |= (b>>(8-mod))& lssproto_modifymask_second[mod][bwidth]; + bitstream_bitaddr += bwidth; + return byteaddr+1; +} +/* + * write to a bitstream. used from 1 bits to 32 bits + * returns -1 if error or buffer excession + */ +static int writeOutputBitStream( int bwidth, unsigned int dat) +{ + int ret; + if( bwidth <= 0){ + return -1; + } else if( bwidth >= 1 && bwidth <= 8 ){ + if((ret=writeOutputBitStreamBody( bwidth , (unsigned char)dat))<0)return -1; + } else if( bwidth > 8 && bwidth <= 16 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth - 8 , ( unsigned char)((dat>>8)&0xff)))<0)return -1; + } else if( bwidth > 16 && bwidth <= 24 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-16,(unsigned char)((dat>>16)&0xff)))<0)return -1; + } else if( bwidth > 24 && bwidth <= 32 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>16)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-24,(unsigned char)((dat>>24)&0xff)))<0)return -1; + } else { + return -1; + } + return ret; +} +#define CHAR_SIZE 256 +#define NODE_SIZE 512 +#define BITS_LEN 9 /* 9 bit lzw compression */ +typedef struct { + unsigned char chr; + int parent; + int brother; + int child; +}NODE; +long lssproto_ringoCompressor( unsigned char *code , long codelen , + unsigned char *text , long textlen) +{ + NODE node[NODE_SIZE]; + int freeNode; + int w,k; /* used in this algo */ + int textind; /* index to text buffer */ + int i; + int position = 0; /* indicates the last byte of code buffer */ + if( textlen <= 0 ) return -1; + initOutputBitStream((char*) code,codelen); + /* fill characters ( 0 ~ 255 ) in the beggining part of + Node list */ + for(i=0; i<= CHAR_SIZE; i++){ + node[i].chr = (unsigned char)i; + node[i].brother = i + 1; + node[i].parent = 0; + node[i].child = 0; + } + node[CHAR_SIZE].brother = 0; + freeNode = CHAR_SIZE + 1; + w = text[0]; + textind = 1; + while(1){ + int rv; + if( textind >= textlen ){ + k = CHAR_SIZE; /* indicates EOF */ + } else { + k = text[textind]; + } + /* search if pattern 'wk' is registered or not. */ + rv = node[w].child; + while(1){ + if( rv <= 0 ) break; + if( node[rv].chr == k ) break; + rv = node[rv].brother; + } + if( rv > 0 ){ + /* found it */ + w = rv; + } else { + position = writeOutputBitStream( BITS_LEN ,w ); + /* return if buffer excession */ + if( position > codelen ) return -1; + /* register pattern 'wk' in the dictionary */ + if( freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = k; + } + if( textind == ( textlen + 1 ) ) break; + textind++; + } + return position; +} + +/* + * Decoder. + * return -1 if buffer excession. Notice buffer text + * is modified . + */ +long lssproto_ringoDecompressor( unsigned char *text , long textlen , + unsigned char *code , long codelen) +{ + NODE node[NODE_SIZE]; + int stack[NODE_SIZE]; + int sp; + int freeNode; + int len; + int i; + int k = 0; + int w = 0; + if( codelen <= 0 ) return -1; + initInputBitStream( (char*)code , codelen ); + for(i=0;i= freeNode ){ + stack[sp++] = k; /* exception */ + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) )return -1; + k = w; + } else { + k = rv; + } + while(k> CHAR_SIZE ){ + if( k >= (sizeof(node)/sizeof(node[0]))) return -1; + stack[sp++] = node[k].chr; + k = node[k].parent; + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + } + stack[sp++] = k; + if( sp >= ( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + /* output to text buffer from stack.*/ + while(sp){ + if( ++len > textlen ) return -1; + *text++ = stack[--sp]; + } + /* register the pattern 'wk'*/ + if( len > 1 && freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + if( w >= (sizeof(node)/sizeof(node[0])))return -1; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = rv; + } + return len; +} +#endif /* ifdef lssproto__ENCRYPT */ + +/* Convert 62-base digits to 10 digits */ +int lssproto_a62toi( char *a ) +{ + int ret = 0; + int minus ; + if( a[0] == '-' ){ + minus = -1; + a++; + } else { + minus = 1; + } + + while( *a != '\0' ) + { + ret *= 62; + if( '0' <= (*a) && (*a) <= '9' ) + ret += (*a)-'0'; + else + if( 'a' <= (*a) && (*a) <= 'z' ) + ret += (*a)-'a'+10; + else + if( 'A' <= (*a) && (*a) <= 'Z' ) + ret += (*a)-'A'+36; + else + return 0; + a++; + } + return ret * minus; +} + +/* Convert 10-base digits into 62-base digits. */ +char *lssproto_cnv10to62( int a, char *out, int outlen ) +{ + int i, j; + char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + int tmp[64]; + int src; + int minus; + int baselen = sizeof( base)-1; + if( a < 0 ){ + minus = 1; + a *= -1; + } else { + minus = 0; + } + /* special case */ + if( a < baselen) { + if( minus ){ + *(out) = '-'; + *(out+1) = base[a]; + *(out+2) = '\0'; + return (out); + } else { + *out = base[a]; + *(out+1) = '\0'; + return( out); + } + } + src = a; + for( i = 0; src >= baselen; i ++ ) { + tmp[i] = src % baselen; + src /= baselen; + } + i--; + if( minus ){ + *out = '-'; + *(out+1) = base[src]; + for( j = 2; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } else { + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } + *(out+j) = '\0'; + return( out); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile new file mode 100644 index 0000000..d19ea7f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile @@ -0,0 +1,686 @@ +############################################################################## +# LuaJIT Makefile. Requires GNU Make. +# +# Please read doc/install.html before changing any variables! +# +# Suitable for POSIX platforms (Linux, *BSD, OSX etc.). +# Also works with MinGW and Cygwin on Windows. +# Please check msvcbuild.bat for building with MSVC on Windows. +# +# Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +############################################################################## + +MAJVER= 2 +MINVER= 0 +RELVER= 3 +ABIVER= 5.1 +NODOTABIVER= 51 + +############################################################################## +############################# COMPILER OPTIONS ############################# +############################################################################## +# These options mainly affect the speed of the JIT compiler itself, not the +# speed of the JIT-compiled code. Turn any of the optional settings on by +# removing the '#' in front of them. Make sure you force a full recompile +# with "make clean", followed by "make" if you change any options. +# +# LuaJIT builds as a native 32 or 64 bit binary by default. +CC= gcc +# +# Use this if you want to force a 32 bit build on a 64 bit multilib OS. +#CC= gcc -m32 +# +# Since the assembler part does NOT maintain a frame pointer, it's pointless +# to slow down the C part by not omitting it. Debugging, tracebacks and +# unwinding are not affected -- the assembler part has frame unwind +# information and GCC emits it where needed (x64) or with -g (see CCDEBUG). +CCOPT= -O2 -fomit-frame-pointer +# Use this if you want to generate a smaller binary (but it's slower): +#CCOPT= -Os -fomit-frame-pointer +# Note: it's no longer recommended to use -O3 with GCC 4.x. +# The I-Cache bloat usually outweighs the benefits from aggressive inlining. +# +# Target-specific compiler options: +# +# x86 only: it's recommended to compile at least for i686. Better yet, +# compile for an architecture that has SSE2, too (-msse -msse2). +# +# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute +# the binaries to a different machine you could also use: -march=native +# +CCOPT_x86= -march=i686 +CCOPT_x64= +CCOPT_arm= +CCOPT_ppc= +CCOPT_ppcspe= +CCOPT_mips= +# +CCDEBUG= +# Uncomment the next line to generate debug information: +#CCDEBUG= -g +# +CCWARN= -Wall +# Uncomment the next line to enable more warnings: +#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith +# +############################################################################## + +############################################################################## +################################ BUILD MODE ################################ +############################################################################## +# The default build mode is mixed mode on POSIX. On Windows this is the same +# as dynamic mode. +# +# Mixed mode creates a static + dynamic library and a statically linked luajit. +BUILDMODE= mixed +# +# Static mode creates a static library and a statically linked luajit. +#BUILDMODE= static +# +# Dynamic mode creates a dynamic library and a dynamically linked luajit. +# Note: this executable will only run when the library is installed! +#BUILDMODE= dynamic +# +############################################################################## + +############################################################################## +################################# FEATURES ################################# +############################################################################## +# Enable/disable these features as needed, but make sure you force a full +# recompile with "make clean", followed by "make". +XCFLAGS= +# +# Permanently disable the FFI extension to reduce the size of the LuaJIT +# executable. But please consider that the FFI library is compiled-in, +# but NOT loaded by default. It only allocates any memory, if you actually +# make use of it. +#XCFLAGS+= -DLUAJIT_DISABLE_FFI +# +# Features from Lua 5.2 that are unlikely to break existing code are +# enabled by default. Some other features that *might* break some existing +# code (e.g. __pairs or os.execute() return values) can be enabled here. +# Note: this does not provide full compatibility with Lua 5.2 at this time. +#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT +# +# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter. +#XCFLAGS+= -DLUAJIT_DISABLE_JIT +# +# Some architectures (e.g. PPC) can use either single-number (1) or +# dual-number (2) mode. Uncomment one of these lines to override the +# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details. +#XCFLAGS+= -DLUAJIT_NUMMODE=1 +#XCFLAGS+= -DLUAJIT_NUMMODE=2 +# +############################################################################## + +############################################################################## +############################ DEBUGGING SUPPORT ############################# +############################################################################## +# Enable these options as needed, but make sure you force a full recompile +# with "make clean", followed by "make". +# Note that most of these are NOT suitable for benchmarking or release mode! +# +# Use the system provided memory allocator (realloc) instead of the +# bundled memory allocator. This is slower, but sometimes helpful for +# debugging. It's helpful for Valgrind's memcheck tool, too. This option +# cannot be enabled on x64, since the built-in allocator is mandatory. +#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC +# +# This define is required to run LuaJIT under Valgrind. The Valgrind +# header files must be installed. You should enable debug information, too. +# Use --suppressions=lj.supp to avoid some false positives. +#XCFLAGS+= -DLUAJIT_USE_VALGRIND +# +# This is the client for the GDB JIT API. GDB 7.0 or higher is required +# to make use of it. See lj_gdbjit.c for details. Enabling this causes +# a non-negligible overhead, even when not running under GDB. +#XCFLAGS+= -DLUAJIT_USE_GDBJIT +# +# Turn on assertions for the Lua/C API to debug problems with lua_* calls. +# This is rather slow -- use only while developing C libraries/embeddings. +#XCFLAGS+= -DLUA_USE_APICHECK +# +# Turn on assertions for the whole LuaJIT VM. This significantly slows down +# everything. Use only if you suspect a problem with LuaJIT itself. +#XCFLAGS+= -DLUA_USE_ASSERT +# +############################################################################## +# You probably don't need to change anything below this line! +############################################################################## + +############################################################################## +# Flags and options for host and target. +############################################################################## + +# You can override the following variables at the make command line: +# CC HOST_CC STATIC_CC DYNAMIC_CC +# CFLAGS HOST_CFLAGS TARGET_CFLAGS +# LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS +# LIBS HOST_LIBS TARGET_LIBS +# CROSS HOST_SYS TARGET_SYS TARGET_FLAGS +# +# Cross-compilation examples: +# make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows +# make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- + +CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS) +LDOPTIONS= $(CCDEBUG) $(LDFLAGS) + +HOST_CC= $(CC) +HOST_RM= rm -f +# If left blank, minilua is built and used. You can supply an installed +# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua +HOST_LUA= + +HOST_XCFLAGS= -I. +HOST_XLDFLAGS= +HOST_XLIBS= +HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS) +HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS) +HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS) + +STATIC_CC = $(CROSS)$(CC) +DYNAMIC_CC = $(CROSS)$(CC) -fPIC +TARGET_CC= $(STATIC_CC) +TARGET_STCC= $(STATIC_CC) +TARGET_DYNCC= $(DYNAMIC_CC) +TARGET_LD= $(CROSS)$(CC) +TARGET_AR= $(CROSS)ar rcus +TARGET_STRIP= $(CROSS)strip + +TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib) +TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER) +TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib +TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME) +TARGET_DLLNAME= lua$(NODOTABIVER).dll +TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME) +TARGET_DYNXLDOPTS= + +TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE +TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE +TARGET_XLDFLAGS= +TARGET_XLIBS=-lm +TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) +TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) +TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS) +TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS) +TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS) + +TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM) +ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH))) + TARGET_LJARCH= x64 +else +ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH))) + TARGET_LJARCH= x86 +else +ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH))) + TARGET_LJARCH= arm +else +ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH))) + TARGET_LJARCH= ppc +else +ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH))) + TARGET_LJARCH= ppcspe +else +ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH))) + ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH))) + TARGET_ARCH= -D__MIPSEL__=1 + endif + TARGET_LJARCH= mips +else + $(error Unsupported target architecture) +endif +endif +endif +endif +endif +endif + +ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) + TARGET_SYS= PS3 + TARGET_ARCH+= -D__CELLOS_LV2__ + TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC +endif +ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) + TARGET_ARCH+= -DLUAJIT_NO_UNWIND +endif + +TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH)) +TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH)) + +ifneq (,$(PREFIX)) +ifneq (/usr/local,$(PREFIX)) + TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\" + ifneq (/usr,$(PREFIX)) + TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH) + endif +endif +endif +ifneq (,$(MULTILIB)) + TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\" +endif +ifneq (,$(LMULTILIB)) + TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\" +endif + +############################################################################## +# System detection. +############################################################################## + +ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM)) + HOST_SYS= Windows + HOST_RM= del +else + HOST_SYS:= $(shell uname -s) + ifneq (,$(findstring MINGW,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= mingw + endif + ifneq (,$(findstring CYGWIN,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= cygwin + endif +endif + +TARGET_SYS?= $(HOST_SYS) +ifeq (Windows,$(TARGET_SYS)) + TARGET_STRIP+= --strip-unneeded + TARGET_XSHLDFLAGS= -shared + TARGET_DYNXLDOPTS= +else +ifeq (Darwin,$(TARGET_SYS)) + ifeq (,$(MACOSX_DEPLOYMENT_TARGET)) + export MACOSX_DEPLOYMENT_TARGET=10.4 + endif + TARGET_STRIP+= -x + TARGET_AR+= 2>/dev/null + ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1)) + TARGET_XCFLAGS+= -fno-stack-protector + endif + TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC + TARGET_DYNXLDOPTS= + TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER) + ifeq (x64,$(TARGET_LJARCH)) + TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000 + TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000 + endif +else +ifeq (iOS,$(TARGET_SYS)) + TARGET_STRIP+= -x + TARGET_AR+= 2>/dev/null + TARGET_XCFLAGS+= -fno-stack-protector + TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC + TARGET_DYNXLDOPTS= + TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER) +else + ifneq (,$(findstring stack-protector,$(shell $(TARGET_CC) -dumpspecs))) + TARGET_XCFLAGS+= -fno-stack-protector + endif + ifneq (SunOS,$(TARGET_SYS)) + ifneq (PS3,$(TARGET_SYS)) + TARGET_XLDFLAGS+= -Wl,-E + endif + endif + ifeq (Linux,$(TARGET_SYS)) + TARGET_XLIBS+= -ldl + endif + ifeq (GNU/kFreeBSD,$(TARGET_SYS)) + TARGET_XLIBS+= -ldl + endif +endif +endif +endif + +ifneq ($(HOST_SYS),$(TARGET_SYS)) + ifeq (Windows,$(TARGET_SYS)) + HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS + else + ifeq (Linux,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX + else + ifeq (Darwin,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX + else + ifeq (iOS,$(TARGET_SYS)) + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX + else + HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER + endif + endif + endif + endif +endif + +ifneq (,$(CCDEBUG)) + TARGET_STRIP= @: +endif + +############################################################################## +# Files and pathnames. +############################################################################## + +MINILUA_O= host/minilua.o +MINILUA_LIBS=-lm +MINILUA_T= host/minilua +MINILUA_X= $(MINILUA_T) + +ifeq (,$(HOST_LUA)) + HOST_LUA= $(MINILUA_X) + DASM_DEP= $(MINILUA_T) +endif + +DASM_DIR= ../dynasm +DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua +DASM_XFLAGS= +DASM_AFLAGS= +DASM_ARCH= $(TARGET_LJARCH) + +ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D P64 +endif +ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D JIT +endif +ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D FFI +endif +ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D DUALNUM +endif +ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D FPU + TARGET_ARCH+= -DLJ_ARCH_HASFPU=1 +else + TARGET_ARCH+= -DLJ_ARCH_HASFPU=0 +endif +ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D HFABI + TARGET_ARCH+= -DLJ_ABI_SOFTFP=0 +else + TARGET_ARCH+= -DLJ_ABI_SOFTFP=1 +endif +DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH)))) +ifeq (Windows,$(TARGET_SYS)) + DASM_AFLAGS+= -D WIN +endif +ifeq (x86,$(TARGET_LJARCH)) + ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D SSE + endif +else +ifeq (x64,$(TARGET_LJARCH)) + DASM_ARCH= x86 +else +ifeq (arm,$(TARGET_LJARCH)) + ifeq (iOS,$(TARGET_SYS)) + DASM_AFLAGS+= -D IOS + endif +else +ifeq (ppc,$(TARGET_LJARCH)) + ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D SQRT + endif + ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D ROUND + endif + ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D GPR64 + endif + ifeq (PS3,$(TARGET_SYS)) + DASM_AFLAGS+= -D PPE -D TOC + endif +endif +endif +endif +endif + +DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS) +DASM_DASC= vm_$(DASM_ARCH).dasc + +BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \ + host/buildvm_lib.o host/buildvm_fold.o +BUILDVM_T= host/buildvm +BUILDVM_X= $(BUILDVM_T) + +HOST_O= $(MINILUA_O) $(BUILDVM_O) +HOST_T= $(MINILUA_T) $(BUILDVM_T) + +LJVM_S= lj_vm.s +LJVM_O= lj_vm.o +LJVM_BOUT= $(LJVM_S) +LJVM_MODE= elfasm + +LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \ + lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o +LJLIB_C= $(LJLIB_O:.o=.c) + +LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \ + lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \ + lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \ + lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \ + lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \ + lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \ + lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \ + lj_asm.o lj_trace.o lj_gdbjit.o \ + lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \ + lj_carith.o lj_clib.o lj_cparse.o \ + lj_lib.o lj_alloc.o lib_aux.o \ + $(LJLIB_O) lib_init.o + +LJVMCORE_O= $(LJVM_O) $(LJCORE_O) +LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o) + +LIB_VMDEF= jit/vmdef.lua +LIB_VMDEFP= $(LIB_VMDEF) + +LUAJIT_O= luajit.o +LUAJIT_A= libluajit.a +LUAJIT_SO= libluajit.so +LUAJIT_T= luajit + +ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T) +ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \ + host/buildvm_arch.h +ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP) +WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk +ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM) + +############################################################################## +# Build mode handling. +############################################################################## + +# Mixed mode defaults. +TARGET_O= $(LUAJIT_A) +TARGET_T= $(LUAJIT_T) $(LUAJIT_SO) +TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO) + +ifeq (Windows,$(TARGET_SYS)) + TARGET_DYNCC= $(STATIC_CC) + LJVM_MODE= peobj + LJVM_BOUT= $(LJVM_O) + LUAJIT_T= luajit.exe + ifeq (cygwin,$(HOST_MSYS)) + LUAJIT_SO= cyg$(TARGET_DLLNAME) + else + LUAJIT_SO= $(TARGET_DLLNAME) + endif + # Mixed mode is not supported on Windows. And static mode doesn't work well. + # C modules cannot be loaded, because they bind to lua51.dll. + ifneq (static,$(BUILDMODE)) + BUILDMODE= dynamic + TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL + endif +endif +ifeq (Darwin,$(TARGET_SYS)) + LJVM_MODE= machasm +endif +ifeq (iOS,$(TARGET_SYS)) + LJVM_MODE= machasm +endif +ifeq (SunOS,$(TARGET_SYS)) + BUILDMODE= static +endif +ifeq (PS3,$(TARGET_SYS)) + BUILDMODE= static +endif + +ifeq (Windows,$(HOST_SYS)) + MINILUA_T= host/minilua.exe + BUILDVM_T= host/buildvm.exe + ifeq (,$(HOST_MSYS)) + MINILUA_X= host\minilua + BUILDVM_X= host\buildvm + ALL_RM:= $(subst /,\,$(ALL_RM)) + endif +endif + +ifeq (static,$(BUILDMODE)) + TARGET_DYNCC= @: + TARGET_T= $(LUAJIT_T) + TARGET_DEP= $(LIB_VMDEF) +else +ifeq (dynamic,$(BUILDMODE)) + ifneq (Windows,$(TARGET_SYS)) + TARGET_CC= $(DYNAMIC_CC) + endif + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) + TARGET_O= $(LUAJIT_SO) + TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS) +else +ifeq (Darwin,$(TARGET_SYS)) + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) +endif +ifeq (iOS,$(TARGET_SYS)) + TARGET_DYNCC= @: + LJVMCORE_DYNO= $(LJVMCORE_O) +endif +endif +endif + +Q= @ +E= @echo +#Q= +#E= @: + +############################################################################## +# Make targets. +############################################################################## + +default all: $(TARGET_T) + +amalg: + @grep "^[+|]" ljamalg.c + $(MAKE) all "LJCORE_O=ljamalg.o" + +clean: + $(HOST_RM) $(ALL_RM) + +depend: + @for file in $(ALL_HDRGEN); do \ + test -f $$file || touch $$file; \ + done + @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \ + sed -e "s| [^ ]*/dasm_\S*\.h||g" \ + -e "s|^\([^l ]\)|host/\1|" \ + -e "s| lj_target_\S*\.h| lj_target_*.h|g" \ + -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \ + -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep + @for file in $(ALL_HDRGEN); do \ + test -s $$file || $(HOST_RM) $$file; \ + done + +.PHONY: default all amalg clean depend + +############################################################################## +# Rules for generated files. +############################################################################## + +$(MINILUA_T): $(MINILUA_O) + $(E) "HOSTLINK $@" + $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS) + +host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) + $(E) "DYNASM $@" + $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC) + +host/buildvm.o: $(DASM_DIR)/dasm_*.h + +$(BUILDVM_T): $(BUILDVM_O) + $(E) "HOSTLINK $@" + $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS) + +$(LJVM_BOUT): $(BUILDVM_T) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@ + +lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C) + +lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C) + +lj_libdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C) + +lj_recdef.h: $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C) + +$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C) + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C) + +lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c + $(E) "BUILDVM $@" + $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c + +############################################################################## +# Object file rules. +############################################################################## + +%.o: %.c + $(E) "CC $@" + $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $< + $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $< + +%.o: %.s + $(E) "ASM $@" + $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $< + $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $< + +$(LUAJIT_O): + $(E) "CC $@" + $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $< + +$(HOST_O): %.o: %.c + $(E) "HOSTCC $@" + $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $< + +include Makefile.dep + +############################################################################## +# Target file rules. +############################################################################## + +$(LUAJIT_A): $(LJVMCORE_O) + $(E) "AR $@" + $(Q)$(TARGET_AR) $@ $(LJVMCORE_O) + +# The dependency on _O, but linking with _DYNO is intentional. +$(LUAJIT_SO): $(LJVMCORE_O) + $(E) "DYNLINK $@" + $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS) + $(Q)$(TARGET_STRIP) $@ + +$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP) + $(E) "LINK $@" + $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS) + $(Q)$(TARGET_STRIP) $@ + $(E) "OK Successfully built LuaJIT" + +############################################################################## diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile.dep b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile.dep new file mode 100644 index 0000000..29b3db8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/Makefile.dep @@ -0,0 +1,286 @@ +lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ + lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \ + lundump.h lvm.h +lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h +lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h +lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ + lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ + ltable.h +ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h +ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ + llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ + lfunc.h lstring.h lgc.h ltable.h lvm.h +ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \ + ltable.h lundump.h lvm.h +ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ + lzio.h lmem.h lundump.h +lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ + lstate.h ltm.h lzio.h +lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h +lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_state.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_lib.h lj_alloc.h +lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h \ + lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \ + lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \ + lj_lib.h lj_libdef.h +lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h +lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \ + lj_libdef.h +lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \ + lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \ + lj_ccallback.h lj_clib.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h +lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h +lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \ + lj_ffdef.h lj_lib.h lj_libdef.h +lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \ + lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ + lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \ + lj_target_*.h lj_dispatch.h lj_vm.h lj_vmevent.h lj_lib.h luajit.h \ + lj_libdef.h +lib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_libdef.h +lib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_lib.h lj_libdef.h +lib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h +lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \ + lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h lj_char.h \ + lj_lib.h lj_libdef.h +lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ + lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \ + lj_libdef.h +linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h +liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h +lj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h +ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \ + lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h \ + lj_cdata.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h \ + lj_vm.h lj_err.c lj_debug.h lj_ff.h lj_ffdef.h lj_char.c lj_char.h \ + lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c lj_udata.c \ + lj_meta.c lj_strscan.h lj_debug.c lj_state.c lj_lex.h lj_alloc.h \ + lj_dispatch.c lj_ccallback.h luajit.h lj_vmevent.c lj_vmevent.h \ + lj_vmmath.c lj_strscan.c lj_api.c lj_lex.c lualib.h lj_parse.h \ + lj_parse.c lj_bcread.c lj_bcdump.h lj_bcwrite.c lj_load.c lj_ctype.c \ + lj_cdata.c lj_cconv.h lj_cconv.c lj_ccall.c lj_ccall.h lj_ccallback.c \ + lj_target.h lj_target_*.h lj_mcode.h lj_carith.c lj_carith.h \ + lj_clib.c lj_clib.h lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c \ + lj_ircall.h lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h \ + lj_opt_narrow.c lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_opt_split.c \ + lj_opt_sink.c lj_mcode.c lj_snap.c lj_record.c lj_record.h \ + lj_ffrecord.h lj_crecord.c lj_crecord.h lj_ffrecord.c lj_recdef.h \ + lj_asm.c lj_asm.h lj_emit_*.h lj_asm_*.h lj_trace.c lj_gdbjit.h \ + lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lj_libdef.h lib_math.c \ + lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c \ + lib_bit.c lib_jit.c lib_ffi.c lib_init.c +lj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \ + lj_meta.h lj_state.h lj_bc.h lj_frame.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_traceerr.h lj_vm.h lj_strscan.h +lj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h \ + lj_ircall.h lj_iropt.h lj_mcode.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_snap.h lj_asm.h lj_vm.h lj_target.h lj_target_*.h \ + lj_emit_*.h lj_asm_*.h +lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \ + lj_bcdef.h +lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \ + lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h +lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \ + lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h +lj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_carith.h +lj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \ + lj_bc.h lj_ctype.h lj_cconv.h lj_ccall.h lj_ccallback.h lj_target.h \ + lj_target_*.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h +lj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ + lj_traceerr.h +lj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \ + lj_ccallback.h +lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \ + lj_cdata.h +lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h +lj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \ + lj_cdata.h lj_clib.h +lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \ + lj_bc.h lj_vm.h lj_char.h lj_strscan.h +lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \ + lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \ + lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ + lj_crecord.h +lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h \ + lj_ccallback.h +lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_state.h lj_frame.h \ + lj_bc.h lj_jit.h lj_ir.h +lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_func.h lj_str.h lj_tab.h lj_meta.h lj_debug.h \ + lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h lj_jit.h lj_ir.h \ + lj_ccallback.h lj_ctype.h lj_gc.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h luajit.h +lj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \ + lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \ + lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h +lj_ffrecord.o: lj_ffrecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \ + lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_crecord.h \ + lj_vm.h lj_strscan.h lj_recdef.h +lj_func.o: lj_func.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_func.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \ + lj_traceerr.h lj_vm.h +lj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_udata.h lj_meta.h \ + lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h lj_jit.h \ + lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h +lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_jit.h \ + lj_ir.h lj_dispatch.h +lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h lj_carith.h \ + lj_vm.h lj_strscan.h lj_lib.h +lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h lualib.h \ + lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h +lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ + lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_lib.h +lj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \ + lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_func.h lj_frame.h \ + lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h +lj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_jit.h lj_ir.h lj_mcode.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_vm.h +lj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \ + lj_vm.h lj_strscan.h +lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h +lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_jit.h lj_iropt.h +lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ + lj_bc.h lj_traceerr.h lj_ctype.h lj_gc.h lj_carith.h lj_vm.h \ + lj_strscan.h lj_folddef.h +lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \ + lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h +lj_opt_mem.o: lj_opt_mem.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_tab.h lj_ir.h lj_jit.h lj_iropt.h +lj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ + lj_traceerr.h lj_vm.h lj_strscan.h +lj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h +lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \ + lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_ircall.h \ + lj_iropt.h lj_vm.h +lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h \ + lj_state.h lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h +lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \ + lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h \ + lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h \ + lj_ffrecord.h lj_snap.h lj_vm.h +lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \ + lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \ + lj_target_*.h lj_ctype.h lj_cdata.h +lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \ + lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h lj_ir.h \ + lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h +lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_char.h +lj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_char.h lj_strscan.h +lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ + lj_err.h lj_errmsg.h lj_tab.h +lj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_frame.h lj_bc.h \ + lj_state.h lj_ir.h lj_jit.h lj_iropt.h lj_mcode.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_snap.h lj_gdbjit.h lj_record.h lj_asm.h \ + lj_vm.h lj_vmevent.h lj_target.h lj_target_*.h +lj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_gc.h lj_udata.h +lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \ + lj_vm.h lj_vmevent.h +lj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ + lj_ir.h lj_vm.h +llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ + lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h +lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h +lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h +loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h +lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ + ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h +lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h +loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h +lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ + lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ + lfunc.h lstring.h lgc.h ltable.h +lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h +lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \ + ltm.h lzio.h lstring.h lgc.h +lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h +ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h +ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h +ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \ + lmem.h lstring.h lgc.h ltable.h +lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h +luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ + lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \ + lundump.h +luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h +lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ + llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h +lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h +lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ + lzio.h +host/print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h lopcodes.h lundump.h +host/buildvm_asm.o: host/buildvm_asm.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_bc.h lj_def.h lj_arch.h +host/buildvm.o: host/buildvm.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_gc.h lj_obj.h lj_bc.h lj_ir.h \ + lj_ircall.h lj_ir.h lj_jit.h lj_frame.h lj_bc.h lj_dispatch.h \ + lj_ctype.h lj_gc.h lj_ccall.h lj_ctype.h luajit.h \ + host/buildvm_arch.h \ + lj_traceerr.h +host/buildvm_fold.o: host/buildvm_fold.c host/buildvm.h lj_def.h lua.h \ + luaconf.h lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_ir.h lj_obj.h +host/buildvm_lib.o: host/buildvm_lib.c host/buildvm.h lj_def.h lua.h luaconf.h \ + lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_lib.h lj_obj.h +host/buildvm_peobj.o: host/buildvm_peobj.c host/buildvm.h lj_def.h lua.h \ + luaconf.h lj_arch.h lj_bc.h lj_def.h lj_arch.h +host/minilua.o: host/minilua.c diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/README b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/README new file mode 100644 index 0000000..abfcdaa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/README @@ -0,0 +1,4 @@ +The files in this directory are only used during the build process of LuaJIT. +For cross-compilation, they must be executed on the host, not on the target. + +These files should NOT be installed! diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.c new file mode 100644 index 0000000..7687ad7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.c @@ -0,0 +1,516 @@ +/* +** LuaJIT VM builder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** This is a tool to build the hand-tuned assembler code required for +** LuaJIT's bytecode interpreter. It supports a variety of output formats +** to feed different toolchains (see usage() below). +** +** This tool is not particularly optimized because it's only used while +** _building_ LuaJIT. There's no point in distributing or installing it. +** Only the object code generated by this tool is linked into LuaJIT. +** +** Caveat: some memory is not free'd, error handling is lazy. +** It's a one-shot tool -- any effort fixing this would be wasted. +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_ircall.h" +#include "lj_frame.h" +#include "lj_dispatch.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_ccall.h" +#endif +#include "luajit.h" + +#if defined(_WIN32) +#include +#include +#endif + +/* ------------------------------------------------------------------------ */ + +/* DynASM glue definitions. */ +#define Dst ctx +#define Dst_DECL BuildCtx *ctx +#define Dst_REF (ctx->D) +#define DASM_CHECKS 1 + +#include "../dynasm/dasm_proto.h" + +/* Glue macros for DynASM. */ +static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type); + +#define DASM_EXTERN(ctx, addr, idx, type) \ + collect_reloc(ctx, addr, idx, type) + +/* ------------------------------------------------------------------------ */ + +/* Avoid trouble if cross-compiling for an x86 target. Speed doesn't matter. */ +#define DASM_ALIGNED_WRITES 1 + +/* Embed architecture-specific DynASM encoder. */ +#if LJ_TARGET_X86ORX64 +#include "../dynasm/dasm_x86.h" +#elif LJ_TARGET_ARM +#include "../dynasm/dasm_arm.h" +#elif LJ_TARGET_PPC +#include "../dynasm/dasm_ppc.h" +#elif LJ_TARGET_PPCSPE +#include "../dynasm/dasm_ppc.h" +#elif LJ_TARGET_MIPS +#include "../dynasm/dasm_mips.h" +#else +#error "No support for this architecture (yet)" +#endif + +/* Embed generated architecture-specific backend. */ +#include "buildvm_arch.h" + +/* ------------------------------------------------------------------------ */ + +void owrite(BuildCtx *ctx, const void *ptr, size_t sz) +{ + if (fwrite(ptr, 1, sz, ctx->fp) != sz) { + fprintf(stderr, "Error: cannot write to output file: %s\n", + strerror(errno)); + exit(1); + } +} + +/* ------------------------------------------------------------------------ */ + +/* Emit code as raw bytes. Only used for DynASM debugging. */ +static void emit_raw(BuildCtx *ctx) +{ + owrite(ctx, ctx->code, ctx->codesz); +} + +/* -- Build machine code -------------------------------------------------- */ + +static const char *sym_decorate(BuildCtx *ctx, + const char *prefix, const char *suffix) +{ + char name[256]; + char *p; +#if LJ_64 + const char *symprefix = ctx->mode == BUILD_machasm ? "_" : ""; +#elif LJ_TARGET_XBOX360 + const char *symprefix = ""; +#else + const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : ""; +#endif + sprintf(name, "%s%s%s", symprefix, prefix, suffix); + p = strchr(name, '@'); + if (p) { +#if LJ_TARGET_X86ORX64 + if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj)) + name[0] = '@'; + else + *p = '\0'; +#elif (LJ_TARGET_PPC || LJ_TARGET_PPCSPE) && !LJ_TARGET_CONSOLE + /* Keep @plt. */ +#else + *p = '\0'; +#endif + } + p = (char *)malloc(strlen(name)+1); /* MSVC doesn't like strdup. */ + strcpy(p, name); + return p; +} + +#define NRELOCSYM (sizeof(extnames)/sizeof(extnames[0])-1) + +static int relocmap[NRELOCSYM]; + +/* Collect external relocations. */ +static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) +{ + if (ctx->nreloc >= BUILD_MAX_RELOC) { + fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n"); + exit(1); + } + if (relocmap[idx] < 0) { + relocmap[idx] = ctx->nrelocsym; + ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, "", extnames[idx]); + ctx->nrelocsym++; + } + ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code); + ctx->reloc[ctx->nreloc].sym = relocmap[idx]; + ctx->reloc[ctx->nreloc].type = type; + ctx->nreloc++; +#if LJ_TARGET_XBOX360 + return (int)(ctx->code - addr) + 4; /* Encode symbol offset of .text. */ +#else + return 0; /* Encode symbol offset of 0. */ +#endif +} + +/* Naive insertion sort. Performance doesn't matter here. */ +static void sym_insert(BuildCtx *ctx, int32_t ofs, + const char *prefix, const char *suffix) +{ + ptrdiff_t i = ctx->nsym++; + while (i > 0) { + if (ctx->sym[i-1].ofs <= ofs) + break; + ctx->sym[i] = ctx->sym[i-1]; + i--; + } + ctx->sym[i].ofs = ofs; + ctx->sym[i].name = sym_decorate(ctx, prefix, suffix); +} + +/* Build the machine code. */ +static int build_code(BuildCtx *ctx) +{ + int status; + int i; + + /* Initialize DynASM structures. */ + ctx->nglob = GLOB__MAX; + ctx->glob = (void **)malloc(ctx->nglob*sizeof(void *)); + memset(ctx->glob, 0, ctx->nglob*sizeof(void *)); + ctx->nreloc = 0; + + ctx->globnames = globnames; + ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); + ctx->nrelocsym = 0; + for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; + + ctx->dasm_ident = DASM_IDENT; + ctx->dasm_arch = DASM_ARCH; + + dasm_init(Dst, DASM_MAXSECTION); + dasm_setupglobal(Dst, ctx->glob, ctx->nglob); + dasm_setup(Dst, build_actionlist); + + /* Call arch-specific backend to emit the code. */ + ctx->npc = build_backend(ctx); + + /* Finalize the code. */ + (void)dasm_checkstep(Dst, -1); + if ((status = dasm_link(Dst, &ctx->codesz))) return status; + ctx->code = (uint8_t *)malloc(ctx->codesz); + if ((status = dasm_encode(Dst, (void *)ctx->code))) return status; + + /* Allocate symbol table and bytecode offsets. */ + ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin"); + ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym)); + ctx->nsym = 0; + ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t)); + + /* Collect the opcodes (PC labels). */ + for (i = 0; i < ctx->npc; i++) { + int32_t ofs = dasm_getpclabel(Dst, i); + if (ofs < 0) return 0x22000000|i; + ctx->bc_ofs[i] = ofs; + if ((LJ_HASJIT || + !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP || + i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) && + (LJ_HASFFI || i != BC_KCDATA)) + sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]); + } + + /* Collect the globals (named labels). */ + for (i = 0; i < ctx->nglob; i++) { + const char *gl = globnames[i]; + int len = (int)strlen(gl); + if (!ctx->glob[i]) { + fprintf(stderr, "Error: undefined global %s\n", gl); + exit(2); + } + /* Skip the _Z symbols. */ + if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z')) + sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code), + LABEL_PREFIX, globnames[i]); + } + + /* Close the address range. */ + sym_insert(ctx, (int32_t)ctx->codesz, "", ""); + ctx->nsym--; + + dasm_free(Dst); + + return 0; +} + +/* -- Generate VM enums --------------------------------------------------- */ + +const char *const bc_names[] = { +#define BCNAME(name, ma, mb, mc, mt) #name, +BCDEF(BCNAME) +#undef BCNAME + NULL +}; + +const char *const ir_names[] = { +#define IRNAME(name, m, m1, m2) #name, +IRDEF(IRNAME) +#undef IRNAME + NULL +}; + +const char *const irt_names[] = { +#define IRTNAME(name, size) #name, +IRTDEF(IRTNAME) +#undef IRTNAME + NULL +}; + +const char *const irfpm_names[] = { +#define FPMNAME(name) #name, +IRFPMDEF(FPMNAME) +#undef FPMNAME + NULL +}; + +const char *const irfield_names[] = { +#define FLNAME(name, ofs) #name, +IRFLDEF(FLNAME) +#undef FLNAME + NULL +}; + +const char *const ircall_names[] = { +#define IRCALLNAME(cond, name, nargs, kind, type, flags) #name, +IRCALLDEF(IRCALLNAME) +#undef IRCALLNAME + NULL +}; + +static const char *const trace_errors[] = { +#define TREDEF(name, msg) msg, +#include "lj_traceerr.h" + NULL +}; + +static const char *lower(char *buf, const char *s) +{ + char *p = buf; + while (*s) { + *p++ = (*s >= 'A' && *s <= 'Z') ? *s+0x20 : *s; + s++; + } + *p = '\0'; + return buf; +} + +/* Emit C source code for bytecode-related definitions. */ +static void emit_bcdef(BuildCtx *ctx) +{ + int i; + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_ofs[] = {\n"); + for (i = 0; i < ctx->npc; i++) { + if (i != 0) + fprintf(ctx->fp, ",\n"); + fprintf(ctx->fp, "%d", ctx->bc_ofs[i]); + } +} + +/* Emit VM definitions as Lua code for debug modules. */ +static void emit_vmdef(BuildCtx *ctx) +{ + char buf[80]; + int i; + fprintf(ctx->fp, "-- This is a generated file. DO NOT EDIT!\n\n"); + fprintf(ctx->fp, "module(...)\n\n"); + + fprintf(ctx->fp, "bcnames = \""); + for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, "%-6s", bc_names[i]); + fprintf(ctx->fp, "\"\n\n"); + + fprintf(ctx->fp, "irnames = \""); + for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, "%-6s", ir_names[i]); + fprintf(ctx->fp, "\"\n\n"); + + fprintf(ctx->fp, "irfpm = { [0]="); + for (i = 0; irfpm_names[i]; i++) + fprintf(ctx->fp, "\"%s\", ", lower(buf, irfpm_names[i])); + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "irfield = { [0]="); + for (i = 0; irfield_names[i]; i++) { + char *p; + lower(buf, irfield_names[i]); + p = strchr(buf, '_'); + if (p) *p = '.'; + fprintf(ctx->fp, "\"%s\", ", buf); + } + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "ircall = {\n[0]="); + for (i = 0; ircall_names[i]; i++) + fprintf(ctx->fp, "\"%s\",\n", ircall_names[i]); + fprintf(ctx->fp, "}\n\n"); + + fprintf(ctx->fp, "traceerr = {\n[0]="); + for (i = 0; trace_errors[i]; i++) + fprintf(ctx->fp, "\"%s\",\n", trace_errors[i]); + fprintf(ctx->fp, "}\n\n"); +} + +/* -- Argument parsing ---------------------------------------------------- */ + +/* Build mode names. */ +static const char *const modenames[] = { +#define BUILDNAME(name) #name, +BUILDDEF(BUILDNAME) +#undef BUILDNAME + NULL +}; + +/* Print usage information and exit. */ +static void usage(void) +{ + int i; + fprintf(stderr, LUAJIT_VERSION " VM builder.\n"); + fprintf(stderr, LUAJIT_COPYRIGHT ", " LUAJIT_URL "\n"); + fprintf(stderr, "Target architecture: " LJ_ARCH_NAME "\n\n"); + fprintf(stderr, "Usage: buildvm -m mode [-o outfile] [infiles...]\n\n"); + fprintf(stderr, "Available modes:\n"); + for (i = 0; i < BUILD__MAX; i++) + fprintf(stderr, " %s\n", modenames[i]); + exit(1); +} + +/* Parse the output mode name. */ +static BuildMode parsemode(const char *mode) +{ + int i; + for (i = 0; modenames[i]; i++) + if (!strcmp(mode, modenames[i])) + return (BuildMode)i; + usage(); + return (BuildMode)-1; +} + +/* Parse arguments. */ +static void parseargs(BuildCtx *ctx, char **argv) +{ + const char *a; + int i; + ctx->mode = (BuildMode)-1; + ctx->outname = "-"; + for (i = 1; (a = argv[i]) != NULL; i++) { + if (a[0] != '-') + break; + switch (a[1]) { + case '-': + if (a[2]) goto err; + i++; + goto ok; + case '\0': + goto ok; + case 'm': + i++; + if (a[2] || argv[i] == NULL) goto err; + ctx->mode = parsemode(argv[i]); + break; + case 'o': + i++; + if (a[2] || argv[i] == NULL) goto err; + ctx->outname = argv[i]; + break; + default: err: + usage(); + break; + } + } +ok: + ctx->args = argv+i; + if (ctx->mode == (BuildMode)-1) goto err; +} + +int main(int argc, char **argv) +{ + BuildCtx ctx_; + BuildCtx *ctx = &ctx_; + int status, binmode; + + if (sizeof(void *) != 4*LJ_32+8*LJ_64) { + fprintf(stderr,"Error: pointer size mismatch in cross-build.\n"); + fprintf(stderr,"Try: make HOST_CC=\"gcc -m32\" CROSS=...\n\n"); + return 1; + } + + UNUSED(argc); + parseargs(ctx, argv); + + if ((status = build_code(ctx))) { + fprintf(stderr,"Error: DASM error %08x\n", status); + return 1; + } + + switch (ctx->mode) { + case BUILD_peobj: + case BUILD_raw: + binmode = 1; + break; + default: + binmode = 0; + break; + } + + if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') { + ctx->fp = stdout; +#if defined(_WIN32) + if (binmode) + _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */ +#endif + } else if (!(ctx->fp = fopen(ctx->outname, binmode ? "wb" : "w"))) { + fprintf(stderr, "Error: cannot open output file '%s': %s\n", + ctx->outname, strerror(errno)); + exit(1); + } + + switch (ctx->mode) { + case BUILD_elfasm: + case BUILD_coffasm: + case BUILD_machasm: + emit_asm(ctx); + emit_asm_debug(ctx); + break; + case BUILD_peobj: + emit_peobj(ctx); + break; + case BUILD_raw: + emit_raw(ctx); + break; + case BUILD_bcdef: + emit_bcdef(ctx); + emit_lib(ctx); + break; + case BUILD_vmdef: + emit_vmdef(ctx); + emit_lib(ctx); + break; + case BUILD_ffdef: + case BUILD_libdef: + case BUILD_recdef: + emit_lib(ctx); + break; + case BUILD_folddef: + emit_fold(ctx); + break; + default: + break; + } + + fflush(ctx->fp); + if (ferror(ctx->fp)) { + fprintf(stderr, "Error: cannot write to output file: %s\n", + strerror(errno)); + exit(1); + } + fclose(ctx->fp); + + return 0; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.exe b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.exe new file mode 100644 index 0000000..b2243e1 Binary files /dev/null and b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.exe differ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.h new file mode 100644 index 0000000..f9dc8c4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm.h @@ -0,0 +1,104 @@ +/* +** LuaJIT VM builder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _BUILDVM_H +#define _BUILDVM_H + +#include +#include +#include +#include +#include + +#include "lj_def.h" +#include "lj_arch.h" + +/* Hardcoded limits. Increase as needed. */ +#define BUILD_MAX_RELOC 200 /* Max. number of relocations. */ +#define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */ + +/* Prefix for scanned library definitions. */ +#define LIBDEF_PREFIX "LJLIB_" + +/* Prefix for scanned fold definitions. */ +#define FOLDDEF_PREFIX "LJFOLD" + +/* Prefixes for generated labels. */ +#define LABEL_PREFIX "lj_" +#define LABEL_PREFIX_BC LABEL_PREFIX "BC_" +#define LABEL_PREFIX_FF LABEL_PREFIX "ff_" +#define LABEL_PREFIX_CF LABEL_PREFIX "cf_" +#define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_" +#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_" +#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" + +/* Forward declaration. */ +struct dasm_State; + +/* Build modes. */ +#define BUILDDEF(_) \ + _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \ + _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \ + _(folddef) + +typedef enum { +#define BUILDENUM(name) BUILD_##name, +BUILDDEF(BUILDENUM) +#undef BUILDENUM + BUILD__MAX +} BuildMode; + +/* Code relocation. */ +typedef struct BuildReloc { + int32_t ofs; + int sym; + int type; +} BuildReloc; + +typedef struct BuildSym { + const char *name; + int32_t ofs; +} BuildSym; + +/* Build context structure. */ +typedef struct BuildCtx { + /* DynASM state pointer. Should be first member. */ + struct dasm_State *D; + /* Parsed command line. */ + BuildMode mode; + FILE *fp; + const char *outname; + char **args; + /* Code and symbols generated by DynASM. */ + uint8_t *code; + size_t codesz; + int npc, nglob, nsym, nreloc, nrelocsym; + void **glob; + BuildSym *sym; + const char **relocsym; + int32_t *bc_ofs; + const char *beginsym; + /* Strings generated by DynASM. */ + const char *const *globnames; + const char *dasm_ident; + const char *dasm_arch; + /* Relocations. */ + BuildReloc reloc[BUILD_MAX_RELOC]; +} BuildCtx; + +extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz); +extern void emit_asm(BuildCtx *ctx); +extern void emit_peobj(BuildCtx *ctx); +extern void emit_lib(BuildCtx *ctx); +extern void emit_fold(BuildCtx *ctx); + +extern const char *const bc_names[]; +extern const char *const ir_names[]; +extern const char *const irt_names[]; +extern const char *const irfpm_names[]; +extern const char *const irfield_names[]; +extern const char *const ircall_names[]; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_asm.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_asm.c new file mode 100644 index 0000000..9b28b3b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_asm.c @@ -0,0 +1,313 @@ +/* +** LuaJIT VM builder: Assembler source code emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_bc.h" + +/* ------------------------------------------------------------------------ */ + +#if LJ_TARGET_X86ORX64 +/* Emit bytes piecewise as assembler text. */ +static void emit_asm_bytes(BuildCtx *ctx, uint8_t *p, int n) +{ + int i; + for (i = 0; i < n; i++) { + if ((i & 15) == 0) + fprintf(ctx->fp, "\t.byte %d", p[i]); + else + fprintf(ctx->fp, ",%d", p[i]); + if ((i & 15) == 15) putc('\n', ctx->fp); + } + if ((n & 15) != 0) putc('\n', ctx->fp); +} + +/* Emit relocation */ +static void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym) +{ + switch (ctx->mode) { + case BUILD_elfasm: + if (type) + fprintf(ctx->fp, "\t.long %s-.-4\n", sym); + else + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + case BUILD_coffasm: + fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", sym); + if (type) + fprintf(ctx->fp, "\t.long %s-.-4\n", sym); + else + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + default: /* BUILD_machasm for relative relocations handled below. */ + fprintf(ctx->fp, "\t.long %s\n", sym); + break; + } +} + +static const char *const jccnames[] = { + "jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "ja", + "js", "jns", "jpe", "jpo", "jl", "jge", "jle", "jg" +}; + +/* Emit relocation for the incredibly stupid OSX assembler. */ +static void emit_asm_reloc_mach(BuildCtx *ctx, uint8_t *cp, int n, + const char *sym) +{ + const char *opname = NULL; + if (--n < 0) goto err; + if (cp[n] == 0xe8) { + opname = "call"; + } else if (cp[n] == 0xe9) { + opname = "jmp"; + } else if (cp[n] >= 0x80 && cp[n] <= 0x8f && n > 0 && cp[n-1] == 0x0f) { + opname = jccnames[cp[n]-0x80]; + n--; + } else { +err: + fprintf(stderr, "Error: unsupported opcode for %s symbol relocation.\n", + sym); + exit(1); + } + emit_asm_bytes(ctx, cp, n); + fprintf(ctx->fp, "\t%s %s\n", opname, sym); +} +#else +/* Emit words piecewise as assembler text. */ +static void emit_asm_words(BuildCtx *ctx, uint8_t *p, int n) +{ + int i; + for (i = 0; i < n; i += 4) { + if ((i & 15) == 0) + fprintf(ctx->fp, "\t.long 0x%08x", *(uint32_t *)(p+i)); + else + fprintf(ctx->fp, ",0x%08x", *(uint32_t *)(p+i)); + if ((i & 15) == 12) putc('\n', ctx->fp); + } + if ((n & 15) != 0) putc('\n', ctx->fp); +} + +/* Emit relocation as part of an instruction. */ +static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n, + const char *sym) +{ + uint32_t ins; + emit_asm_words(ctx, p, n-4); + ins = *(uint32_t *)(p+n-4); +#if LJ_TARGET_ARM + if ((ins & 0xff000000u) == 0xfa000000u) { + fprintf(ctx->fp, "\tblx %s\n", sym); + } else if ((ins & 0x0e000000u) == 0x0a000000u) { + fprintf(ctx->fp, "\t%s%.2s %s\n", (ins & 0x01000000u) ? "bl" : "b", + &"eqnecsccmiplvsvchilsgeltgtle"[2*(ins >> 28)], sym); + } else { + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); + } +#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE +#if LJ_TARGET_PS3 +#define TOCPREFIX "." +#else +#define TOCPREFIX "" +#endif + if ((ins >> 26) == 16) { + fprintf(ctx->fp, "\t%s %d, %d, " TOCPREFIX "%s\n", + (ins & 1) ? "bcl" : "bc", (ins >> 21) & 31, (ins >> 16) & 31, sym); + } else if ((ins >> 26) == 18) { + fprintf(ctx->fp, "\t%s " TOCPREFIX "%s\n", (ins & 1) ? "bl" : "b", sym); + } else { + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); + } +#elif LJ_TARGET_MIPS + fprintf(stderr, + "Error: unsupported opcode %08x for %s symbol relocation.\n", + ins, sym); + exit(1); +#else +#error "missing relocation support for this architecture" +#endif +} +#endif + +#if LJ_TARGET_ARM +#define ELFASM_PX "%%" +#else +#define ELFASM_PX "@" +#endif + +/* Emit an assembler label. */ +static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc) +{ + switch (ctx->mode) { + case BUILD_elfasm: +#if LJ_TARGET_PS3 + if (!strncmp(name, "lj_vm_", 6) && + strcmp(name, ctx->beginsym) && + !strstr(name, "hook")) { + fprintf(ctx->fp, + "\n\t.globl %s\n" + "\t.section \".opd\",\"aw\"\n" + "%s:\n" + "\t.long .%s,.TOC.@tocbase32\n" + "\t.size %s,8\n" + "\t.previous\n" + "\t.globl .%s\n" + "\t.hidden .%s\n" + "\t.type .%s, " ELFASM_PX "function\n" + "\t.size .%s, %d\n" + ".%s:\n", + name, name, name, name, name, name, name, name, size, name); + break; + } +#endif + fprintf(ctx->fp, + "\n\t.globl %s\n" + "\t.hidden %s\n" + "\t.type %s, " ELFASM_PX "%s\n" + "\t.size %s, %d\n" + "%s:\n", + name, name, name, isfunc ? "function" : "object", name, size, name); + break; + case BUILD_coffasm: + fprintf(ctx->fp, "\n\t.globl %s\n", name); + if (isfunc) + fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", name); + fprintf(ctx->fp, "%s:\n", name); + break; + case BUILD_machasm: + fprintf(ctx->fp, + "\n\t.private_extern %s\n" + "%s:\n", name, name); + break; + default: + break; + } +} + +/* Emit alignment. */ +static void emit_asm_align(BuildCtx *ctx, int bits) +{ + switch (ctx->mode) { + case BUILD_elfasm: + case BUILD_coffasm: + fprintf(ctx->fp, "\t.p2align %d\n", bits); + break; + case BUILD_machasm: + fprintf(ctx->fp, "\t.align %d\n", bits); + break; + default: + break; + } +} + +/* ------------------------------------------------------------------------ */ + +/* Emit assembler source code. */ +void emit_asm(BuildCtx *ctx) +{ + int i, rel; + + fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); + fprintf(ctx->fp, "\t.text\n"); + emit_asm_align(ctx, 4); + +#if LJ_TARGET_PS3 + emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0); +#else + emit_asm_label(ctx, ctx->beginsym, 0, 0); +#endif + if (ctx->mode != BUILD_machasm) + fprintf(ctx->fp, ".Lbegin:\n"); + +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND + /* This should really be moved into buildvm_arm.dasc. */ + fprintf(ctx->fp, + ".fnstart\n" + ".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n" + ".pad #28\n"); +#endif +#if LJ_TARGET_MIPS + fprintf(ctx->fp, ".set nomips16\n.abicalls\n.set noreorder\n.set nomacro\n"); +#endif + + for (i = rel = 0; i < ctx->nsym; i++) { + int32_t ofs = ctx->sym[i].ofs; + int32_t next = ctx->sym[i+1].ofs; +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI + if (!strcmp(ctx->sym[i].name, "lj_vm_ffi_call")) + fprintf(ctx->fp, + ".globl lj_err_unwind_arm\n" + ".personality lj_err_unwind_arm\n" + ".fnend\n" + ".fnstart\n" + ".save {r4, r5, r11, lr}\n" + ".setfp r11, sp\n"); +#endif + emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1); + while (rel < ctx->nreloc && ctx->reloc[rel].ofs <= next) { + BuildReloc *r = &ctx->reloc[rel]; + int n = r->ofs - ofs; +#if LJ_TARGET_X86ORX64 + if (ctx->mode == BUILD_machasm && r->type != 0) { + emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); + } else { + emit_asm_bytes(ctx, ctx->code+ofs, n); + emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]); + } + ofs += n+4; +#else + emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); + ofs += n; +#endif + rel++; + } +#if LJ_TARGET_X86ORX64 + emit_asm_bytes(ctx, ctx->code+ofs, next-ofs); +#else + emit_asm_words(ctx, ctx->code+ofs, next-ofs); +#endif + } + +#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND + fprintf(ctx->fp, +#if !LJ_HASFFI + ".globl lj_err_unwind_arm\n" + ".personality lj_err_unwind_arm\n" +#endif + ".fnend\n"); +#endif + + fprintf(ctx->fp, "\n"); + switch (ctx->mode) { + case BUILD_elfasm: +#if !LJ_TARGET_PS3 + fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n"); +#endif +#if LJ_TARGET_PPCSPE + /* Soft-float ABI + SPE. */ + fprintf(ctx->fp, "\t.gnu_attribute 4, 2\n\t.gnu_attribute 8, 3\n"); +#elif LJ_TARGET_PPC && !LJ_TARGET_PS3 + /* Hard-float ABI. */ + fprintf(ctx->fp, "\t.gnu_attribute 4, 1\n"); +#endif + /* fallthrough */ + case BUILD_coffasm: + fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident); + break; + case BUILD_machasm: + fprintf(ctx->fp, + "\t.cstring\n" + "\t.ascii \"%s\\0\"\n", ctx->dasm_ident); + break; + default: + break; + } + fprintf(ctx->fp, "\n"); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_fold.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_fold.c new file mode 100644 index 0000000..7f5d9f2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_fold.c @@ -0,0 +1,229 @@ +/* +** LuaJIT VM builder: IR folding hash table generator. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_ir.h" + +/* Context for the folding hash table generator. */ +static int lineno; +static int funcidx; +static uint32_t foldkeys[BUILD_MAX_FOLD]; +static uint32_t nkeys; + +/* Try to fill the hash table with keys using the hash parameters. */ +static int tryhash(uint32_t *htab, uint32_t sz, uint32_t r, int dorol) +{ + uint32_t i; + if (dorol && ((r & 31) == 0 || (r>>5) == 0)) + return 0; /* Avoid zero rotates. */ + memset(htab, 0xff, (sz+1)*sizeof(uint32_t)); + for (i = 0; i < nkeys; i++) { + uint32_t key = foldkeys[i]; + uint32_t k = key & 0xffffff; + uint32_t h = (dorol ? lj_rol(lj_rol(k, r>>5) - k, r&31) : + (((k << (r>>5)) - k) << (r&31))) % sz; + if (htab[h] != 0xffffffff) { /* Collision on primary slot. */ + if (htab[h+1] != 0xffffffff) { /* Collision on secondary slot. */ + /* Try to move the colliding key, if possible. */ + if (h < sz-1 && htab[h+2] == 0xffffffff) { + uint32_t k2 = htab[h+1] & 0xffffff; + uint32_t h2 = (dorol ? lj_rol(lj_rol(k2, r>>5) - k2, r&31) : + (((k2 << (r>>5)) - k2) << (r&31))) % sz; + if (h2 != h+1) return 0; /* Cannot resolve collision. */ + htab[h+2] = htab[h+1]; /* Move colliding key to secondary slot. */ + } else { + return 0; /* Collision. */ + } + } + htab[h+1] = key; + } else { + htab[h] = key; + } + } + return 1; /* Success, all keys could be stored. */ +} + +/* Print the generated hash table. */ +static void printhash(BuildCtx *ctx, uint32_t *htab, uint32_t sz) +{ + uint32_t i; + fprintf(ctx->fp, "static const uint32_t fold_hash[%d] = {\n0x%08x", + sz+1, htab[0]); + for (i = 1; i < sz+1; i++) + fprintf(ctx->fp, ",\n0x%08x", htab[i]); + fprintf(ctx->fp, "\n};\n\n"); +} + +/* Exhaustive search for the shortest semi-perfect hash table. */ +static void makehash(BuildCtx *ctx) +{ + uint32_t htab[BUILD_MAX_FOLD*2+1]; + uint32_t sz, r; + /* Search for the smallest hash table with an odd size. */ + for (sz = (nkeys|1); sz < BUILD_MAX_FOLD*2; sz += 2) { + /* First try all shift hash combinations. */ + for (r = 0; r < 32*32; r++) { + if (tryhash(htab, sz, r, 0)) { + printhash(ctx, htab, sz); + fprintf(ctx->fp, + "#define fold_hashkey(k)\t(((((k)<<%u)-(k))<<%u)%%%u)\n\n", + r>>5, r&31, sz); + return; + } + } + /* Then try all rotate hash combinations. */ + for (r = 0; r < 32*32; r++) { + if (tryhash(htab, sz, r, 1)) { + printhash(ctx, htab, sz); + fprintf(ctx->fp, + "#define fold_hashkey(k)\t(lj_rol(lj_rol((k),%u)-(k),%u)%%%u)\n\n", + r>>5, r&31, sz); + return; + } + } + } + fprintf(stderr, "Error: search for perfect hash failed\n"); + exit(1); +} + +/* Parse one token of a fold rule. */ +static uint32_t nexttoken(char **pp, int allowlit, int allowany) +{ + char *p = *pp; + if (p) { + uint32_t i; + char *q = strchr(p, ' '); + if (q) *q++ = '\0'; + *pp = q; + if (allowlit && !strncmp(p, "IRFPM_", 6)) { + for (i = 0; irfpm_names[i]; i++) + if (!strcmp(irfpm_names[i], p+6)) + return i; + } else if (allowlit && !strncmp(p, "IRFL_", 5)) { + for (i = 0; irfield_names[i]; i++) + if (!strcmp(irfield_names[i], p+5)) + return i; + } else if (allowlit && !strncmp(p, "IRCALL_", 7)) { + for (i = 0; ircall_names[i]; i++) + if (!strcmp(ircall_names[i], p+7)) + return i; + } else if (allowlit && !strncmp(p, "IRCONV_", 7)) { + for (i = 0; irt_names[i]; i++) { + const char *r = strchr(p+7, '_'); + if (r && !strncmp(irt_names[i], p+7, r-(p+7))) { + uint32_t j; + for (j = 0; irt_names[j]; j++) + if (!strcmp(irt_names[j], r+1)) + return (i << 5) + j; + } + } + } else if (allowlit && *p >= '0' && *p <= '9') { + for (i = 0; *p >= '0' && *p <= '9'; p++) + i = i*10 + (*p - '0'); + if (*p == '\0') + return i; + } else if (allowany && !strcmp("any", p)) { + return allowany; + } else { + for (i = 0; ir_names[i]; i++) + if (!strcmp(ir_names[i], p)) + return i; + } + fprintf(stderr, "Error: bad fold definition token \"%s\" at line %d\n", p, lineno); + exit(1); + } + return 0; +} + +/* Parse a fold rule. */ +static void foldrule(char *p) +{ + uint32_t op = nexttoken(&p, 0, 0); + uint32_t left = nexttoken(&p, 0, 0x7f); + uint32_t right = nexttoken(&p, 1, 0x3ff); + uint32_t key = (funcidx << 24) | (op << 17) | (left << 10) | right; + uint32_t i; + if (nkeys >= BUILD_MAX_FOLD) { + fprintf(stderr, "Error: too many fold rules, increase BUILD_MAX_FOLD.\n"); + exit(1); + } + /* Simple insertion sort to detect duplicates. */ + for (i = nkeys; i > 0; i--) { + if ((foldkeys[i-1]&0xffffff) < (key & 0xffffff)) + break; + if ((foldkeys[i-1]&0xffffff) == (key & 0xffffff)) { + fprintf(stderr, "Error: duplicate fold definition at line %d\n", lineno); + exit(1); + } + foldkeys[i] = foldkeys[i-1]; + } + foldkeys[i] = key; + nkeys++; +} + +/* Emit C source code for IR folding hash table. */ +void emit_fold(BuildCtx *ctx) +{ + char buf[256]; /* We don't care about analyzing lines longer than that. */ + const char *fname = ctx->args[0]; + FILE *fp; + + if (fname == NULL) { + fprintf(stderr, "Error: missing input filename\n"); + exit(1); + } + + if (fname[0] == '-' && fname[1] == '\0') { + fp = stdin; + } else { + fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "Error: cannot open input file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } + } + + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + fprintf(ctx->fp, "static const FoldFunc fold_func[] = {\n"); + + lineno = 0; + funcidx = 0; + nkeys = 0; + while (fgets(buf, sizeof(buf), fp) != NULL) { + lineno++; + /* The prefix must be at the start of a line, otherwise it's ignored. */ + if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) { + char *p = buf+sizeof(FOLDDEF_PREFIX)-1; + char *q = strchr(p, ')'); + if (p[0] == '(' && q) { + p++; + *q = '\0'; + foldrule(p); + } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) { + p += 2; + *q = '\0'; + if (funcidx) + fprintf(ctx->fp, ",\n"); + if (p[-2] == 'X') + fprintf(ctx->fp, " %s", p); + else + fprintf(ctx->fp, " fold_%s", p); + funcidx++; + } else { + buf[strlen(buf)-1] = '\0'; + fprintf(stderr, "Error: unknown fold definition tag %s%s at line %d\n", + FOLDDEF_PREFIX, p, lineno); + exit(1); + } + } + } + fclose(fp); + fprintf(ctx->fp, "\n};\n\n"); + + makehash(ctx); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_lib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_lib.c new file mode 100644 index 0000000..eafdab9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_lib.c @@ -0,0 +1,398 @@ +/* +** LuaJIT VM builder: library definition compiler. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "buildvm.h" +#include "lj_obj.h" +#include "lj_lib.h" + +/* Context for library definitions. */ +static uint8_t obuf[8192]; +static uint8_t *optr; +static char modname[80]; +static size_t modnamelen; +static char funcname[80]; +static int modstate, regfunc; +static int ffid, recffid, ffasmfunc; + +enum { + REGFUNC_OK, + REGFUNC_NOREG, + REGFUNC_NOREGUV +}; + +static void libdef_name(const char *p, int kind) +{ + size_t n = strlen(p); + if (kind != LIBINIT_STRING) { + if (n > modnamelen && p[modnamelen] == '_' && + !strncmp(p, modname, modnamelen)) { + p += modnamelen+1; + n -= modnamelen+1; + } + } + if (n > LIBINIT_MAXSTR) { + fprintf(stderr, "Error: string too long: '%s'\n", p); + exit(1); + } + if (optr+1+n+2 > obuf+sizeof(obuf)) { /* +2 for caller. */ + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = (uint8_t)(n | kind); + memcpy(optr, p, n); + optr += n; +} + +static void libdef_endmodule(BuildCtx *ctx) +{ + if (modstate != 0) { + char line[80]; + const uint8_t *p; + int n; + if (modstate == 1) + fprintf(ctx->fp, " (lua_CFunction)0"); + fprintf(ctx->fp, "\n};\n"); + fprintf(ctx->fp, "static const uint8_t %s%s[] = {\n", + LABEL_PREFIX_LIBINIT, modname); + line[0] = '\0'; + for (n = 0, p = obuf; p < optr; p++) { + n += sprintf(line+n, "%d,", *p); + if (n >= 75) { + fprintf(ctx->fp, "%s\n", line); + n = 0; + line[0] = '\0'; + } + } + fprintf(ctx->fp, "%s%d\n};\n#endif\n\n", line, LIBINIT_END); + } +} + +static void libdef_module(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + libdef_endmodule(ctx); + optr = obuf; + *optr++ = (uint8_t)ffid; + *optr++ = (uint8_t)ffasmfunc; + *optr++ = 0; /* Hash table size. */ + modstate = 1; + fprintf(ctx->fp, "#ifdef %sMODULE_%s\n", LIBDEF_PREFIX, p); + fprintf(ctx->fp, "#undef %sMODULE_%s\n", LIBDEF_PREFIX, p); + fprintf(ctx->fp, "static const lua_CFunction %s%s[] = {\n", + LABEL_PREFIX_LIBCF, p); + } + modnamelen = strlen(p); + if (modnamelen > sizeof(modname)-1) { + fprintf(stderr, "Error: module name too long: '%s'\n", p); + exit(1); + } + strcpy(modname, p); +} + +static int find_ffofs(BuildCtx *ctx, const char *name) +{ + int i; + for (i = 0; i < ctx->nglob; i++) { + const char *gl = ctx->globnames[i]; + if (gl[0] == 'f' && gl[1] == 'f' && gl[2] == '_' && !strcmp(gl+3, name)) { + return (int)((uint8_t *)ctx->glob[i] - ctx->code); + } + } + fprintf(stderr, "Error: undefined fast function %s%s\n", + LABEL_PREFIX_FF, name); + exit(1); +} + +static void libdef_func(BuildCtx *ctx, char *p, int arg) +{ + if (arg != LIBINIT_CF) + ffasmfunc++; + if (ctx->mode == BUILD_libdef) { + if (modstate == 0) { + fprintf(stderr, "Error: no module for function definition %s\n", p); + exit(1); + } + if (regfunc == REGFUNC_NOREG) { + if (optr+1 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_FFID; + } else { + if (arg != LIBINIT_ASM_) { + if (modstate != 1) fprintf(ctx->fp, ",\n"); + modstate = 2; + fprintf(ctx->fp, " %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p); + } + if (regfunc != REGFUNC_NOREGUV) obuf[2]++; /* Bump hash table size. */ + libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg); + } + } else if (ctx->mode == BUILD_ffdef) { + fprintf(ctx->fp, "FFDEF(%s)\n", p); + } else if (ctx->mode == BUILD_recdef) { + if (strlen(p) > sizeof(funcname)-1) { + fprintf(stderr, "Error: function name too long: '%s'\n", p); + exit(1); + } + strcpy(funcname, p); + } else if (ctx->mode == BUILD_vmdef) { + int i; + for (i = 1; p[i] && modname[i-1]; i++) + if (p[i] == '_') p[i] = '.'; + fprintf(ctx->fp, "\"%s\",\n", p); + } else if (ctx->mode == BUILD_bcdef) { + if (arg != LIBINIT_CF) + fprintf(ctx->fp, ",\n%d", find_ffofs(ctx, p)); + } + ffid++; + regfunc = REGFUNC_OK; +} + +static uint32_t find_rec(char *name) +{ + char *p = (char *)obuf; + uint32_t n; + for (n = 2; *p; n++) { + if (strcmp(p, name) == 0) + return n; + p += strlen(p)+1; + } + if (p+strlen(name)+1 >= (char *)obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + strcpy(p, name); + return n; +} + +static void libdef_rec(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_recdef) { + char *q; + uint32_t n; + for (; recffid+1 < ffid; recffid++) + fprintf(ctx->fp, ",\n0"); + recffid = ffid; + if (*p == '.') p = funcname; + q = strchr(p, ' '); + if (q) *q++ = '\0'; + n = find_rec(p); + if (q) + fprintf(ctx->fp, ",\n0x%02x00+(%s)", n, q); + else + fprintf(ctx->fp, ",\n0x%02x00", n); + } +} + +static void memcpy_endian(void *dst, void *src, size_t n) +{ + union { uint8_t b; uint32_t u; } host_endian; + host_endian.u = 1; + if (host_endian.b == LJ_ENDIAN_SELECT(1, 0)) { + memcpy(dst, src, n); + } else { + size_t i; + for (i = 0; i < n; i++) + ((uint8_t *)dst)[i] = ((uint8_t *)src)[n-i-1]; + } +} + +static void libdef_push(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + int len = (int)strlen(p); + if (*p == '"') { + if (len > 1 && p[len-1] == '"') { + p[len-1] = '\0'; + libdef_name(p+1, LIBINIT_STRING); + return; + } + } else if (*p >= '0' && *p <= '9') { + char *ep; + double d = strtod(p, &ep); + if (*ep == '\0') { + if (optr+1+sizeof(double) > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_NUMBER; + memcpy_endian(optr, &d, sizeof(double)); + optr += sizeof(double); + return; + } + } else if (!strcmp(p, "lastcl")) { + if (optr+1 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_LASTCL; + return; + } else if (len > 4 && !strncmp(p, "top-", 4)) { + if (optr+2 > obuf+sizeof(obuf)) { + fprintf(stderr, "Error: output buffer overflow\n"); + exit(1); + } + *optr++ = LIBINIT_COPY; + *optr++ = (uint8_t)atoi(p+4); + return; + } + fprintf(stderr, "Error: bad value for %sPUSH(%s)\n", LIBDEF_PREFIX, p); + exit(1); + } +} + +static void libdef_set(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(arg); + if (ctx->mode == BUILD_libdef) { + if (p[0] == '!' && p[1] == '\0') p[0] = '\0'; /* Set env. */ + libdef_name(p, LIBINIT_STRING); + *optr++ = LIBINIT_SET; + obuf[2]++; /* Bump hash table size. */ + } +} + +static void libdef_regfunc(BuildCtx *ctx, char *p, int arg) +{ + UNUSED(ctx); UNUSED(p); + regfunc = arg; +} + +typedef void (*LibDefFunc)(BuildCtx *ctx, char *p, int arg); + +typedef struct LibDefHandler { + const char *suffix; + const char *stop; + const LibDefFunc func; + const int arg; +} LibDefHandler; + +static const LibDefHandler libdef_handlers[] = { + { "MODULE_", " \t\r\n", libdef_module, 0 }, + { "CF(", ")", libdef_func, LIBINIT_CF }, + { "ASM(", ")", libdef_func, LIBINIT_ASM }, + { "ASM_(", ")", libdef_func, LIBINIT_ASM_ }, + { "REC(", ")", libdef_rec, 0 }, + { "PUSH(", ")", libdef_push, 0 }, + { "SET(", ")", libdef_set, 0 }, + { "NOREGUV", NULL, libdef_regfunc, REGFUNC_NOREGUV }, + { "NOREG", NULL, libdef_regfunc, REGFUNC_NOREG }, + { NULL, NULL, (LibDefFunc)0, 0 } +}; + +/* Emit C source code for library function definitions. */ +void emit_lib(BuildCtx *ctx) +{ + const char *fname; + + if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef || + ctx->mode == BUILD_recdef) + fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n"); + else if (ctx->mode == BUILD_vmdef) + fprintf(ctx->fp, "ffnames = {\n[0]=\"Lua\",\n\"C\",\n"); + if (ctx->mode == BUILD_recdef) + fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100"); + recffid = ffid = FF_C+1; + ffasmfunc = 0; + + while ((fname = *ctx->args++)) { + char buf[256]; /* We don't care about analyzing lines longer than that. */ + FILE *fp; + if (fname[0] == '-' && fname[1] == '\0') { + fp = stdin; + } else { + fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "Error: cannot open input file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } + } + modstate = 0; + regfunc = REGFUNC_OK; + while (fgets(buf, sizeof(buf), fp) != NULL) { + char *p; + /* Simplistic pre-processor. Only handles top-level #if/#endif. */ + if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') { + int ok = 1; + if (!strcmp(buf, "#if LJ_52\n")) + ok = LJ_52; + else if (!strcmp(buf, "#if LJ_HASJIT\n")) + ok = LJ_HASJIT; + else if (!strcmp(buf, "#if LJ_HASFFI\n")) + ok = LJ_HASFFI; + if (!ok) { + int lvl = 1; + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') { + if (--lvl == 0) break; + } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') { + lvl++; + } + } + continue; + } + } + for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) { + const LibDefHandler *ldh; + p += sizeof(LIBDEF_PREFIX)-1; + for (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) { + size_t n, len = strlen(ldh->suffix); + if (!strncmp(p, ldh->suffix, len)) { + p += len; + n = ldh->stop ? strcspn(p, ldh->stop) : 0; + if (!p[n]) break; + p[n] = '\0'; + ldh->func(ctx, p, ldh->arg); + p += n+1; + break; + } + } + if (ldh->suffix == NULL) { + buf[strlen(buf)-1] = '\0'; + fprintf(stderr, "Error: unknown library definition tag %s%s\n", + LIBDEF_PREFIX, p); + exit(1); + } + } + } + fclose(fp); + if (ctx->mode == BUILD_libdef) { + libdef_endmodule(ctx); + } + } + + if (ctx->mode == BUILD_ffdef) { + fprintf(ctx->fp, "\n#undef FFDEF\n\n"); + fprintf(ctx->fp, + "#ifndef FF_NUM_ASMFUNC\n#define FF_NUM_ASMFUNC %d\n#endif\n\n", + ffasmfunc); + } else if (ctx->mode == BUILD_vmdef) { + fprintf(ctx->fp, "}\n\n"); + } else if (ctx->mode == BUILD_bcdef) { + int i; + fprintf(ctx->fp, "\n};\n\n"); + fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_mode[] = {\n"); + fprintf(ctx->fp, "BCDEF(BCMODE)\n"); + for (i = ffasmfunc-1; i > 0; i--) + fprintf(ctx->fp, "BCMODE_FF,\n"); + fprintf(ctx->fp, "BCMODE_FF\n};\n\n"); + } else if (ctx->mode == BUILD_recdef) { + char *p = (char *)obuf; + fprintf(ctx->fp, "\n};\n\n"); + fprintf(ctx->fp, "static const RecordFunc recff_func[] = {\n" + "recff_nyi,\n" + "recff_c"); + while (*p) { + fprintf(ctx->fp, ",\nrecff_%s", p); + p += strlen(p)+1; + } + fprintf(ctx->fp, "\n};\n\n"); + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_peobj.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_peobj.c new file mode 100644 index 0000000..138b042 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/buildvm_peobj.c @@ -0,0 +1,368 @@ +/* +** LuaJIT VM builder: PE object emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Only used for building on Windows, since we cannot assume the presence +** of a suitable assembler. The host and target byte order must match. +*/ + +#include "buildvm.h" +#include "lj_bc.h" + +#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC + +/* Context for PE object emitter. */ +static char *strtab; +static size_t strtabofs; + +/* -- PE object definitions ----------------------------------------------- */ + +/* PE header. */ +typedef struct PEheader { + uint16_t arch; + uint16_t nsects; + uint32_t time; + uint32_t symtabofs; + uint32_t nsyms; + uint16_t opthdrsz; + uint16_t flags; +} PEheader; + +/* PE section. */ +typedef struct PEsection { + char name[8]; + uint32_t vsize; + uint32_t vaddr; + uint32_t size; + uint32_t ofs; + uint32_t relocofs; + uint32_t lineofs; + uint16_t nreloc; + uint16_t nline; + uint32_t flags; +} PEsection; + +/* PE relocation. */ +typedef struct PEreloc { + uint32_t vaddr; + uint32_t symidx; + uint16_t type; +} PEreloc; + +/* Cannot use sizeof, because it pads up to the max. alignment. */ +#define PEOBJ_RELOC_SIZE (4+4+2) + +/* PE symbol table entry. */ +typedef struct PEsym { + union { + char name[8]; + uint32_t nameref[2]; + } n; + uint32_t value; + int16_t sect; + uint16_t type; + uint8_t scl; + uint8_t naux; +} PEsym; + +/* PE symbol table auxiliary entry for a section. */ +typedef struct PEsymaux { + uint32_t size; + uint16_t nreloc; + uint16_t nline; + uint32_t cksum; + uint16_t assoc; + uint8_t comdatsel; + uint8_t unused[3]; +} PEsymaux; + +/* Cannot use sizeof, because it pads up to the max. alignment. */ +#define PEOBJ_SYM_SIZE (8+4+2+2+1+1) + +/* PE object CPU specific defines. */ +#if LJ_TARGET_X86 +#define PEOBJ_ARCH_TARGET 0x014c +#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ +#define PEOBJ_RELOC_DIR32 0x06 +#define PEOBJ_RELOC_OFS 0 +#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */ +#elif LJ_TARGET_X64 +#define PEOBJ_ARCH_TARGET 0x8664 +#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ +#define PEOBJ_RELOC_DIR32 0x02 +#define PEOBJ_RELOC_ADDR32NB 0x03 +#define PEOBJ_RELOC_OFS 0 +#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */ +#elif LJ_TARGET_PPC +#define PEOBJ_ARCH_TARGET 0x01f2 +#define PEOBJ_RELOC_REL32 0x06 +#define PEOBJ_RELOC_DIR32 0x02 +#define PEOBJ_RELOC_OFS (-4) +#define PEOBJ_TEXT_FLAGS 0x60400020 /* 60=r+x, 40=align8, 20=code. */ +#endif + +/* Section numbers (0-based). */ +enum { + PEOBJ_SECT_ABS = -2, + PEOBJ_SECT_UNDEF = -1, + PEOBJ_SECT_TEXT, +#if LJ_TARGET_X64 + PEOBJ_SECT_PDATA, + PEOBJ_SECT_XDATA, +#endif + PEOBJ_SECT_RDATA_Z, + PEOBJ_NSECTIONS +}; + +/* Symbol types. */ +#define PEOBJ_TYPE_NULL 0 +#define PEOBJ_TYPE_FUNC 0x20 + +/* Symbol storage class. */ +#define PEOBJ_SCL_EXTERN 2 +#define PEOBJ_SCL_STATIC 3 + +/* -- PE object emitter --------------------------------------------------- */ + +/* Emit PE object symbol. */ +static void emit_peobj_sym(BuildCtx *ctx, const char *name, uint32_t value, + int sect, int type, int scl) +{ + PEsym sym; + size_t len = strlen(name); + if (!strtab) { /* Pass 1: only calculate string table length. */ + if (len > 8) strtabofs += len+1; + return; + } + if (len <= 8) { + memcpy(sym.n.name, name, len); + memset(sym.n.name+len, 0, 8-len); + } else { + sym.n.nameref[0] = 0; + sym.n.nameref[1] = (uint32_t)strtabofs; + memcpy(strtab + strtabofs, name, len); + strtab[strtabofs+len] = 0; + strtabofs += len+1; + } + sym.value = value; + sym.sect = (int16_t)(sect+1); /* 1-based section number. */ + sym.type = (uint16_t)type; + sym.scl = (uint8_t)scl; + sym.naux = 0; + owrite(ctx, &sym, PEOBJ_SYM_SIZE); +} + +/* Emit PE object section symbol. */ +static void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect) +{ + PEsym sym; + PEsymaux aux; + if (!strtab) return; /* Pass 1: no output. */ + memcpy(sym.n.name, pesect[sect].name, 8); + sym.value = 0; + sym.sect = (int16_t)(sect+1); /* 1-based section number. */ + sym.type = PEOBJ_TYPE_NULL; + sym.scl = PEOBJ_SCL_STATIC; + sym.naux = 1; + owrite(ctx, &sym, PEOBJ_SYM_SIZE); + memset(&aux, 0, sizeof(PEsymaux)); + aux.size = pesect[sect].size; + aux.nreloc = pesect[sect].nreloc; + owrite(ctx, &aux, PEOBJ_SYM_SIZE); +} + +/* Emit Windows PE object file. */ +void emit_peobj(BuildCtx *ctx) +{ + PEheader pehdr; + PEsection pesect[PEOBJ_NSECTIONS]; + uint32_t sofs; + int i, nrsym; + union { uint8_t b; uint32_t u; } host_endian; + + sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection); + + /* Fill in PE sections. */ + memset(&pesect, 0, PEOBJ_NSECTIONS*sizeof(PEsection)); + memcpy(pesect[PEOBJ_SECT_TEXT].name, ".text", sizeof(".text")-1); + pesect[PEOBJ_SECT_TEXT].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_TEXT].size = (uint32_t)ctx->codesz); + pesect[PEOBJ_SECT_TEXT].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE; + /* Flags: 60 = read+execute, 50 = align16, 20 = code. */ + pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS; + +#if LJ_TARGET_X64 + memcpy(pesect[PEOBJ_SECT_PDATA].name, ".pdata", sizeof(".pdata")-1); + pesect[PEOBJ_SECT_PDATA].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_PDATA].size = 6*4); + pesect[PEOBJ_SECT_PDATA].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_PDATA].nreloc = 6) * PEOBJ_RELOC_SIZE; + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_PDATA].flags = 0x40300040; + + memcpy(pesect[PEOBJ_SECT_XDATA].name, ".xdata", sizeof(".xdata")-1); + pesect[PEOBJ_SECT_XDATA].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_XDATA].size = 8*2+4+6*2); /* See below. */ + pesect[PEOBJ_SECT_XDATA].relocofs = sofs; + sofs += (pesect[PEOBJ_SECT_XDATA].nreloc = 1) * PEOBJ_RELOC_SIZE; + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_XDATA].flags = 0x40300040; +#endif + + memcpy(pesect[PEOBJ_SECT_RDATA_Z].name, ".rdata$Z", sizeof(".rdata$Z")-1); + pesect[PEOBJ_SECT_RDATA_Z].ofs = sofs; + sofs += (pesect[PEOBJ_SECT_RDATA_Z].size = (uint32_t)strlen(ctx->dasm_ident)+1); + /* Flags: 40 = read, 30 = align4, 40 = initialized data. */ + pesect[PEOBJ_SECT_RDATA_Z].flags = 0x40300040; + + /* Fill in PE header. */ + pehdr.arch = PEOBJ_ARCH_TARGET; + pehdr.nsects = PEOBJ_NSECTIONS; + pehdr.time = 0; /* Timestamp is optional. */ + pehdr.symtabofs = sofs; + pehdr.opthdrsz = 0; + pehdr.flags = 0; + + /* Compute the size of the symbol table: + ** @feat.00 + nsections*2 + ** + asm_start + nsym + ** + nrsym + */ + nrsym = ctx->nrelocsym; + pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym; +#if LJ_TARGET_X64 + pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */ +#endif + + /* Write PE object header and all sections. */ + owrite(ctx, &pehdr, sizeof(PEheader)); + owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS); + + /* Write .text section. */ + host_endian.u = 1; + if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) { +#if LJ_TARGET_PPC + uint32_t *p = (uint32_t *)ctx->code; + int n = (int)(ctx->codesz >> 2); + for (i = 0; i < n; i++, p++) + *p = lj_bswap(*p); /* Byteswap .text section. */ +#else + fprintf(stderr, "Error: different byte order for host and target\n"); + exit(1); +#endif + } + owrite(ctx, ctx->code, ctx->codesz); + for (i = 0; i < ctx->nreloc; i++) { + PEreloc reloc; + reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS; + reloc.symidx = 1+2+ctx->reloc[i].sym; /* Reloc syms are after .text sym. */ + reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } + +#if LJ_TARGET_X64 + { /* Write .pdata section. */ + uint32_t fcofs = (uint32_t)ctx->sym[ctx->nsym-1].ofs; + uint32_t pdata[3]; /* Start of .text, end of .text and .xdata. */ + PEreloc reloc; + pdata[0] = 0; pdata[1] = fcofs; pdata[2] = 0; + owrite(ctx, &pdata, sizeof(pdata)); + pdata[0] = fcofs; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 20; + owrite(ctx, &pdata, sizeof(pdata)); + reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 12; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 16; reloc.symidx = 1+2+nrsym+2+2+1; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + reloc.vaddr = 20; reloc.symidx = 1+2+nrsym+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } + { /* Write .xdata section. */ + uint16_t xdata[8+2+6]; + PEreloc reloc; + xdata[0] = 0x01|0x08|0x10; /* Ver. 1, uhandler/ehandler, prolog size 0. */ + xdata[1] = 0x0005; /* Number of unwind codes, no frame pointer. */ + xdata[2] = 0x4200; /* Stack offset 4*8+8 = aword*5. */ + xdata[3] = 0x3000; /* Push rbx. */ + xdata[4] = 0x6000; /* Push rsi. */ + xdata[5] = 0x7000; /* Push rdi. */ + xdata[6] = 0x5000; /* Push rbp. */ + xdata[7] = 0; /* Alignment. */ + xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */ + xdata[10] = 0x01; /* Ver. 1, no handler, prolog size 0. */ + xdata[11] = 0x1504; /* Number of unwind codes, fp = rbp, fpofs = 16. */ + xdata[12] = 0x0300; /* set_fpreg. */ + xdata[13] = 0x0200; /* stack offset 0*8+8 = aword*1. */ + xdata[14] = 0x3000; /* Push rbx. */ + xdata[15] = 0x5000; /* Push rbp. */ + owrite(ctx, &xdata, sizeof(xdata)); + reloc.vaddr = 2*8; reloc.symidx = 1+2+nrsym+2+2; + reloc.type = PEOBJ_RELOC_ADDR32NB; + owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); + } +#endif + + /* Write .rdata$Z section. */ + owrite(ctx, ctx->dasm_ident, strlen(ctx->dasm_ident)+1); + + /* Write symbol table. */ + strtab = NULL; /* 1st pass: collect string sizes. */ + for (;;) { + strtabofs = 4; + /* Mark as SafeSEH compliant. */ + emit_peobj_sym(ctx, "@feat.00", 1, + PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC); + + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT); + for (i = 0; i < nrsym; i++) + emit_peobj_sym(ctx, ctx->relocsym[i], 0, + PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); + +#if LJ_TARGET_X64 + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA); + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA); + emit_peobj_sym(ctx, "lj_err_unwind_win64", 0, + PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); +#endif + + emit_peobj_sym(ctx, ctx->beginsym, 0, + PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN); + for (i = 0; i < ctx->nsym; i++) + emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs, + PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); + + emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z); + + if (strtab) + break; + /* 2nd pass: alloc strtab, write syms and copy strings. */ + strtab = (char *)malloc(strtabofs); + *(uint32_t *)strtab = (uint32_t)strtabofs; + } + + /* Write string table. */ + owrite(ctx, strtab, strtabofs); +} + +#else + +void emit_peobj(BuildCtx *ctx) +{ + UNUSED(ctx); + fprintf(stderr, "Error: no PE object support for this target\n"); + exit(1); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/genminilua.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/genminilua.lua new file mode 100644 index 0000000..04c5518 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/host/genminilua.lua @@ -0,0 +1,428 @@ +---------------------------------------------------------------------------- +-- Lua script to generate a customized, minified version of Lua. +-- The resulting 'minilua' is used for the build process of LuaJIT. +---------------------------------------------------------------------------- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- + +local sub, match, gsub = string.sub, string.match, string.gsub + +local LUA_VERSION = "5.1.5" +local LUA_SOURCE + +local function usage() + io.stderr:write("Usage: ", arg and arg[0] or "genminilua", + " lua-", LUA_VERSION, "-source-dir\n") + os.exit(1) +end + +local function find_sources() + LUA_SOURCE = arg and arg[1] + if not LUA_SOURCE then usage() end + if sub(LUA_SOURCE, -1) ~= "/" then LUA_SOURCE = LUA_SOURCE.."/" end + local fp = io.open(LUA_SOURCE .. "lua.h") + if not fp then + LUA_SOURCE = LUA_SOURCE.."src/" + fp = io.open(LUA_SOURCE .. "lua.h") + if not fp then usage() end + end + local all = fp:read("*a") + fp:close() + if not match(all, 'LUA_RELEASE%s*"Lua '..LUA_VERSION..'"') then + io.stderr:write("Error: version mismatch\n") + usage() + end +end + +local LUA_FILES = { +"lmem.c", "lobject.c", "ltm.c", "lfunc.c", "ldo.c", "lstring.c", "ltable.c", +"lgc.c", "lstate.c", "ldebug.c", "lzio.c", "lopcodes.c", +"llex.c", "lcode.c", "lparser.c", "lvm.c", "lapi.c", "lauxlib.c", +"lbaselib.c", "ltablib.c", "liolib.c", "loslib.c", "lstrlib.c", "linit.c", +} + +local REMOVE_LIB = {} +gsub([[ +collectgarbage dofile gcinfo getfenv getmetatable load print rawequal rawset +select tostring xpcall +foreach foreachi getn maxn setn +popen tmpfile seek setvbuf __tostring +clock date difftime execute getenv rename setlocale time tmpname +dump gfind len reverse +LUA_LOADLIBNAME LUA_MATHLIBNAME LUA_DBLIBNAME +]], "%S+", function(name) + REMOVE_LIB[name] = true +end) + +local REMOVE_EXTINC = { [""] = true, [""] = true, } + +local CUSTOM_MAIN = [[ +typedef unsigned int UB; +static UB barg(lua_State *L,int idx){ +union{lua_Number n;U64 b;}bn; +bn.n=lua_tonumber(L,idx)+6755399441055744.0; +if (bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number"); +return(UB)bn.b; +} +#define BRET(b) lua_pushnumber(L,(lua_Number)(int)(b));return 1; +static int tobit(lua_State *L){ +BRET(barg(L,1))} +static int bnot(lua_State *L){ +BRET(~barg(L,1))} +static int band(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)} +static int bor(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)} +static int bxor(lua_State *L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)} +static int lshift(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET(b<>n)} +static int arshift(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)} +static int rol(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b<>(32-n)))} +static int ror(lua_State *L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))} +static int bswap(lua_State *L){ +UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} +static int tohex(lua_State *L){ +UB b=barg(L,1); +int n=lua_isnone(L,2)?8:(int)barg(L,2); +const char *hexdigits="0123456789abcdef"; +char buf[8]; +int i; +if(n<0){n=-n;hexdigits="0123456789ABCDEF";} +if(n>8)n=8; +for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} +lua_pushlstring(L,buf,(size_t)n); +return 1; +} +static const struct luaL_Reg bitlib[] = { +{"tobit",tobit}, +{"bnot",bnot}, +{"band",band}, +{"bor",bor}, +{"bxor",bxor}, +{"lshift",lshift}, +{"rshift",rshift}, +{"arshift",arshift}, +{"rol",rol}, +{"ror",ror}, +{"bswap",bswap}, +{"tohex",tohex}, +{NULL,NULL} +}; +int main(int argc, char **argv){ + lua_State *L = luaL_newstate(); + int i; + luaL_openlibs(L); + luaL_register(L, "bit", bitlib); + if (argc < 2) return sizeof(void *); + lua_createtable(L, 0, 1); + lua_pushstring(L, argv[1]); + lua_rawseti(L, -2, 0); + lua_setglobal(L, "arg"); + if (luaL_loadfile(L, argv[1])) + goto err; + for (i = 2; i < argc; i++) + lua_pushstring(L, argv[i]); + if (lua_pcall(L, argc - 2, 0, 0)) { + err: + fprintf(stderr, "Error: %s\n", lua_tostring(L, -1)); + return 1; + } + lua_close(L); + return 0; +} +]] + +local function read_sources() + local t = {} + for i, name in ipairs(LUA_FILES) do + local fp = assert(io.open(LUA_SOURCE..name, "r")) + t[i] = fp:read("*a") + assert(fp:close()) + end + t[#t+1] = CUSTOM_MAIN + return table.concat(t) +end + +local includes = {} + +local function merge_includes(src) + return gsub(src, '#include%s*"([^"]*)"%s*\n', function(name) + if includes[name] then return "" end + includes[name] = true + local fp = assert(io.open(LUA_SOURCE..name, "r")) + local src = fp:read("*a") + assert(fp:close()) + src = gsub(src, "#ifndef%s+%w+_h\n#define%s+%w+_h\n", "") + src = gsub(src, "#endif%s*$", "") + return merge_includes(src) + end) +end + +local function get_license(src) + return match(src, "/%*+\n%* Copyright %(.-%*/\n") +end + +local function fold_lines(src) + return gsub(src, "\\\n", " ") +end + +local strings = {} + +local function save_str(str) + local n = #strings+1 + strings[n] = str + return "\1"..n.."\2" +end + +local function save_strings(src) + src = gsub(src, '"[^"\n]*"', save_str) + return gsub(src, "'[^'\n]*'", save_str) +end + +local function restore_strings(src) + return gsub(src, "\1(%d+)\2", function(numstr) + return strings[tonumber(numstr)] + end) +end + +local function def_istrue(def) + return def == "INT_MAX > 2147483640L" or + def == "LUAI_BITSINT >= 32" or + def == "SIZE_Bx < LUAI_BITSINT-1" or + def == "cast" or + def == "defined(LUA_CORE)" or + def == "MINSTRTABSIZE" or + def == "LUA_MINBUFFER" or + def == "HARDSTACKTESTS" or + def == "UNUSED" +end + +local head, defs = {[[ +#ifdef _MSC_VER +typedef unsigned __int64 U64; +#else +typedef unsigned long long U64; +#endif +int _CRT_glob = 0; +]]}, {} + +local function preprocess(src) + local t = { match(src, "^(.-)#") } + local lvl, on, oldon = 0, true, {} + for pp, def, txt in string.gmatch(src, "#(%w+) *([^\n]*)\n([^#]*)") do + if pp == "if" or pp == "ifdef" or pp == "ifndef" then + lvl = lvl + 1 + oldon[lvl] = on + on = def_istrue(def) + elseif pp == "else" then + if oldon[lvl] then + if on == false then on = true else on = false end + end + elseif pp == "elif" then + if oldon[lvl] then + on = def_istrue(def) + end + elseif pp == "endif" then + on = oldon[lvl] + lvl = lvl - 1 + elseif on then + if pp == "include" then + if not head[def] and not REMOVE_EXTINC[def] then + head[def] = true + head[#head+1] = "#include "..def.."\n" + end + elseif pp == "define" then + local k, sp, v = match(def, "([%w_]+)(%s*)(.*)") + if k and not (sp == "" and sub(v, 1, 1) == "(") then + defs[k] = gsub(v, "%a[%w_]*", function(tok) + return defs[tok] or tok + end) + else + t[#t+1] = "#define "..def.."\n" + end + elseif pp ~= "undef" then + error("unexpected directive: "..pp.." "..def) + end + end + if on then t[#t+1] = txt end + end + return gsub(table.concat(t), "%a[%w_]*", function(tok) + return defs[tok] or tok + end) +end + +local function merge_header(src, license) + local hdr = string.format([[ +/* This is a heavily customized and minimized copy of Lua %s. */ +/* It's only used to build LuaJIT. It does NOT have all standard functions! */ +]], LUA_VERSION) + return hdr..license..table.concat(head)..src +end + +local function strip_unused1(src) + return gsub(src, '( {"?([%w_]+)"?,%s+%a[%w_]*},\n)', function(line, func) + return REMOVE_LIB[func] and "" or line + end) +end + +local function strip_unused2(src) + return gsub(src, "Symbolic Execution.-}=", "") +end + +local function strip_unused3(src) + src = gsub(src, "extern", "static") + src = gsub(src, "\nstatic([^\n]-)%(([^)]*)%)%(", "\nstatic%1 %2(") + src = gsub(src, "#define lua_assert[^\n]*\n", "") + src = gsub(src, "lua_assert%b();?", "") + src = gsub(src, "default:\n}", "default:;\n}") + src = gsub(src, "lua_lock%b();", "") + src = gsub(src, "lua_unlock%b();", "") + src = gsub(src, "luai_threadyield%b();", "") + src = gsub(src, "luai_userstateopen%b();", "{}") + src = gsub(src, "luai_userstate%w+%b();", "") + src = gsub(src, "%(%(c==.*luaY_parser%)", "luaY_parser") + src = gsub(src, "trydecpoint%(ls,seminfo%)", + "luaX_lexerror(ls,\"malformed number\",TK_NUMBER)") + src = gsub(src, "int c=luaZ_lookahead%b();", "") + src = gsub(src, "luaL_register%(L,[^,]*,co_funcs%);\nreturn 2;", + "return 1;") + src = gsub(src, "getfuncname%b():", "NULL:") + src = gsub(src, "getobjname%b():", "NULL:") + src = gsub(src, "if%([^\n]*hookmask[^\n]*%)\n[^\n]*\n", "") + src = gsub(src, "if%([^\n]*hookmask[^\n]*%)%b{}\n", "") + src = gsub(src, "if%([^\n]*hookmask[^\n]*&&\n[^\n]*%b{}\n", "") + src = gsub(src, "(twoto%b()%()", "%1(size_t)") + src = gsub(src, "i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +typedef enum{ +TM_INDEX, +TM_NEWINDEX, +TM_GC, +TM_MODE, +TM_EQ, +TM_ADD, +TM_SUB, +TM_MUL, +TM_DIV, +TM_MOD, +TM_POW, +TM_UNM, +TM_LEN, +TM_LT, +TM_LE, +TM_CONCAT, +TM_CALL, +TM_N +}TMS; +enum OpMode{iABC,iABx,iAsBx}; +typedef enum{ +OP_MOVE, +OP_LOADK, +OP_LOADBOOL, +OP_LOADNIL, +OP_GETUPVAL, +OP_GETGLOBAL, +OP_GETTABLE, +OP_SETGLOBAL, +OP_SETUPVAL, +OP_SETTABLE, +OP_NEWTABLE, +OP_SELF, +OP_ADD, +OP_SUB, +OP_MUL, +OP_DIV, +OP_MOD, +OP_POW, +OP_UNM, +OP_NOT, +OP_LEN, +OP_CONCAT, +OP_JMP, +OP_EQ, +OP_LT, +OP_LE, +OP_TEST, +OP_TESTSET, +OP_CALL, +OP_TAILCALL, +OP_RETURN, +OP_FORLOOP, +OP_FORPREP, +OP_TFORLOOP, +OP_SETLIST, +OP_CLOSE, +OP_CLOSURE, +OP_VARARG +}OpCode; +enum OpArgMask{ +OpArgN, +OpArgU, +OpArgR, +OpArgK +}; +typedef enum{ +VVOID, +VNIL, +VTRUE, +VFALSE, +VK, +VKNUM, +VLOCAL, +VUPVAL, +VGLOBAL, +VINDEXED, +VJMP, +VRELOCABLE, +VNONRELOC, +VCALL, +VVARARG +}expkind; +enum RESERVED{ +TK_AND=257,TK_BREAK, +TK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION, +TK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT, +TK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE, +TK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER, +TK_NAME,TK_STRING,TK_EOS +}; +typedef enum BinOpr{ +OPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW, +OPR_CONCAT, +OPR_NE,OPR_EQ, +OPR_LT,OPR_LE,OPR_GT,OPR_GE, +OPR_AND,OPR_OR, +OPR_NOBINOPR +}BinOpr; +typedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr; +#define LUA_QL(x)"'"x"'" +#define luai_apicheck(L,o){(void)L;} +#define lua_number2str(s,n)sprintf((s),"%.14g",(n)) +#define lua_str2number(s,p)strtod((s),(p)) +#define luai_numadd(a,b)((a)+(b)) +#define luai_numsub(a,b)((a)-(b)) +#define luai_nummul(a,b)((a)*(b)) +#define luai_numdiv(a,b)((a)/(b)) +#define luai_nummod(a,b)((a)-floor((a)/(b))*(b)) +#define luai_numpow(a,b)(pow(a,b)) +#define luai_numunm(a)(-(a)) +#define luai_numeq(a,b)((a)==(b)) +#define luai_numlt(a,b)((a)<(b)) +#define luai_numle(a,b)((a)<=(b)) +#define luai_numisnan(a)(!luai_numeq((a),(a))) +#define lua_number2int(i,d)((i)=(int)(d)) +#define lua_number2integer(i,d)((i)=(lua_Integer)(d)) +#define LUAI_THROW(L,c)longjmp((c)->b,1) +#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a} +#define lua_pclose(L,file)((void)((void)L,file),0) +#define lua_upvalueindex(i)((-10002)-(i)) +typedef struct lua_State lua_State; +typedef int(*lua_CFunction)(lua_State*L); +typedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz); +typedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize); +typedef double lua_Number; +typedef ptrdiff_t lua_Integer; +static void lua_settop(lua_State*L,int idx); +static int lua_type(lua_State*L,int idx); +static const char* lua_tolstring(lua_State*L,int idx,size_t*len); +static size_t lua_objlen(lua_State*L,int idx); +static void lua_pushlstring(lua_State*L,const char*s,size_t l); +static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n); +static void lua_createtable(lua_State*L,int narr,int nrec); +static void lua_setfield(lua_State*L,int idx,const char*k); +#define lua_pop(L,n)lua_settop(L,-(n)-1) +#define lua_newtable(L)lua_createtable(L,0,0) +#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0) +#define lua_strlen(L,i)lua_objlen(L,(i)) +#define lua_isfunction(L,n)(lua_type(L,(n))==6) +#define lua_istable(L,n)(lua_type(L,(n))==5) +#define lua_isnil(L,n)(lua_type(L,(n))==0) +#define lua_isboolean(L,n)(lua_type(L,(n))==1) +#define lua_isnone(L,n)(lua_type(L,(n))==(-1)) +#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0) +#define lua_pushliteral(L,s)lua_pushlstring(L,""s,(sizeof(s)/sizeof(char))-1) +#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s)) +#define lua_tostring(L,i)lua_tolstring(L,(i),NULL) +typedef struct lua_Debug lua_Debug; +typedef void(*lua_Hook)(lua_State*L,lua_Debug*ar); +struct lua_Debug{ +int event; +const char*name; +const char*namewhat; +const char*what; +const char*source; +int currentline; +int nups; +int linedefined; +int lastlinedefined; +char short_src[60]; +int i_ci; +}; +typedef unsigned int lu_int32; +typedef size_t lu_mem; +typedef ptrdiff_t l_mem; +typedef unsigned char lu_byte; +#define IntPoint(p)((unsigned int)(lu_mem)(p)) +typedef union{double u;void*s;long l;}L_Umaxalign; +typedef double l_uacNumber; +#define check_exp(c,e)(e) +#define UNUSED(x)((void)(x)) +#define cast(t,exp)((t)(exp)) +#define cast_byte(i)cast(lu_byte,(i)) +#define cast_num(i)cast(lua_Number,(i)) +#define cast_int(i)cast(int,(i)) +typedef lu_int32 Instruction; +#define condhardstacktests(x)((void)0) +typedef union GCObject GCObject; +typedef struct GCheader{ +GCObject*next;lu_byte tt;lu_byte marked; +}GCheader; +typedef union{ +GCObject*gc; +void*p; +lua_Number n; +int b; +}Value; +typedef struct lua_TValue{ +Value value;int tt; +}TValue; +#define ttisnil(o)(ttype(o)==0) +#define ttisnumber(o)(ttype(o)==3) +#define ttisstring(o)(ttype(o)==4) +#define ttistable(o)(ttype(o)==5) +#define ttisfunction(o)(ttype(o)==6) +#define ttisboolean(o)(ttype(o)==1) +#define ttisuserdata(o)(ttype(o)==7) +#define ttisthread(o)(ttype(o)==8) +#define ttislightuserdata(o)(ttype(o)==2) +#define ttype(o)((o)->tt) +#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc) +#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p) +#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n) +#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts) +#define tsvalue(o)(&rawtsvalue(o)->tsv) +#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u) +#define uvalue(o)(&rawuvalue(o)->uv) +#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl) +#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h) +#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b) +#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th) +#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0)) +#define checkconsistency(obj) +#define checkliveness(g,obj) +#define setnilvalue(obj)((obj)->tt=0) +#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;} +#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;} +#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);} +#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);} +#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);} +#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);} +#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);} +#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);} +#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);} +#define setttype(obj,tt)(ttype(obj)=(tt)) +#define iscollectable(o)(ttype(o)>=4) +typedef TValue*StkId; +typedef union TString{ +L_Umaxalign dummy; +struct{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte reserved; +unsigned int hash; +size_t len; +}tsv; +}TString; +#define getstr(ts)cast(const char*,(ts)+1) +#define svalue(o)getstr(rawtsvalue(o)) +typedef union Udata{ +L_Umaxalign dummy; +struct{ +GCObject*next;lu_byte tt;lu_byte marked; +struct Table*metatable; +struct Table*env; +size_t len; +}uv; +}Udata; +typedef struct Proto{ +GCObject*next;lu_byte tt;lu_byte marked; +TValue*k; +Instruction*code; +struct Proto**p; +int*lineinfo; +struct LocVar*locvars; +TString**upvalues; +TString*source; +int sizeupvalues; +int sizek; +int sizecode; +int sizelineinfo; +int sizep; +int sizelocvars; +int linedefined; +int lastlinedefined; +GCObject*gclist; +lu_byte nups; +lu_byte numparams; +lu_byte is_vararg; +lu_byte maxstacksize; +}Proto; +typedef struct LocVar{ +TString*varname; +int startpc; +int endpc; +}LocVar; +typedef struct UpVal{ +GCObject*next;lu_byte tt;lu_byte marked; +TValue*v; +union{ +TValue value; +struct{ +struct UpVal*prev; +struct UpVal*next; +}l; +}u; +}UpVal; +typedef struct CClosure{ +GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; +lua_CFunction f; +TValue upvalue[1]; +}CClosure; +typedef struct LClosure{ +GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; +struct Proto*p; +UpVal*upvals[1]; +}LClosure; +typedef union Closure{ +CClosure c; +LClosure l; +}Closure; +#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC) +typedef union TKey{ +struct{ +Value value;int tt; +struct Node*next; +}nk; +TValue tvk; +}TKey; +typedef struct Node{ +TValue i_val; +TKey i_key; +}Node; +typedef struct Table{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte flags; +lu_byte lsizenode; +struct Table*metatable; +TValue*array; +Node*node; +Node*lastfree; +GCObject*gclist; +int sizearray; +}Table; +#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1))))) +#define twoto(x)((size_t)1<<(x)) +#define sizenode(t)(twoto((t)->lsizenode)) +static const TValue luaO_nilobject_; +#define ceillog2(x)(luaO_log2((x)-1)+1) +static int luaO_log2(unsigned int x); +#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e])) +#define fasttm(l,et,e)gfasttm(G(l),et,e) +static const TValue*luaT_gettm(Table*events,TMS event,TString*ename); +#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L)) +#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0) +#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0) +#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t)) +#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t)) +#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t))) +#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t))) +#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) +#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t)))) +static void*luaM_realloc_(lua_State*L,void*block,size_t oldsize, +size_t size); +static void*luaM_toobig(lua_State*L); +static void*luaM_growaux_(lua_State*L,void*block,int*size, +size_t size_elem,int limit, +const char*errormsg); +typedef struct Zio ZIO; +#define char2int(c)cast(int,cast(unsigned char,(c))) +#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z)) +typedef struct Mbuffer{ +char*buffer; +size_t n; +size_t buffsize; +}Mbuffer; +#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0) +#define luaZ_buffer(buff)((buff)->buffer) +#define luaZ_sizebuffer(buff)((buff)->buffsize) +#define luaZ_bufflen(buff)((buff)->n) +#define luaZ_resetbuffer(buff)((buff)->n=0) +#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size) +#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0) +struct Zio{ +size_t n; +const char*p; +lua_Reader reader; +void*data; +lua_State*L; +}; +static int luaZ_fill(ZIO*z); +struct lua_longjmp; +#define gt(L)(&L->l_gt) +#define registry(L)(&G(L)->l_registry) +typedef struct stringtable{ +GCObject**hash; +lu_int32 nuse; +int size; +}stringtable; +typedef struct CallInfo{ +StkId base; +StkId func; +StkId top; +const Instruction*savedpc; +int nresults; +int tailcalls; +}CallInfo; +#define curr_func(L)(clvalue(L->ci->func)) +#define ci_func(ci)(clvalue((ci)->func)) +#define f_isLua(ci)(!ci_func(ci)->c.isC) +#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci)) +typedef struct global_State{ +stringtable strt; +lua_Alloc frealloc; +void*ud; +lu_byte currentwhite; +lu_byte gcstate; +int sweepstrgc; +GCObject*rootgc; +GCObject**sweepgc; +GCObject*gray; +GCObject*grayagain; +GCObject*weak; +GCObject*tmudata; +Mbuffer buff; +lu_mem GCthreshold; +lu_mem totalbytes; +lu_mem estimate; +lu_mem gcdept; +int gcpause; +int gcstepmul; +lua_CFunction panic; +TValue l_registry; +struct lua_State*mainthread; +UpVal uvhead; +struct Table*mt[(8+1)]; +TString*tmname[TM_N]; +}global_State; +struct lua_State{ +GCObject*next;lu_byte tt;lu_byte marked; +lu_byte status; +StkId top; +StkId base; +global_State*l_G; +CallInfo*ci; +const Instruction*savedpc; +StkId stack_last; +StkId stack; +CallInfo*end_ci; +CallInfo*base_ci; +int stacksize; +int size_ci; +unsigned short nCcalls; +unsigned short baseCcalls; +lu_byte hookmask; +lu_byte allowhook; +int basehookcount; +int hookcount; +lua_Hook hook; +TValue l_gt; +TValue env; +GCObject*openupval; +GCObject*gclist; +struct lua_longjmp*errorJmp; +ptrdiff_t errfunc; +}; +#define G(L)(L->l_G) +union GCObject{ +GCheader gch; +union TString ts; +union Udata u; +union Closure cl; +struct Table h; +struct Proto p; +struct UpVal uv; +struct lua_State th; +}; +#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts)) +#define gco2ts(o)(&rawgco2ts(o)->tsv) +#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u)) +#define gco2u(o)(&rawgco2u(o)->uv) +#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl)) +#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h)) +#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p)) +#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv)) +#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv)) +#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th)) +#define obj2gco(v)(cast(GCObject*,(v))) +static void luaE_freethread(lua_State*L,lua_State*L1); +#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1) +#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0) +#define resethookcount(L)(L->hookcount=L->basehookcount) +static void luaG_typeerror(lua_State*L,const TValue*o, +const char*opname); +static void luaG_runerror(lua_State*L,const char*fmt,...); +#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1)); +#define incr_top(L){luaD_checkstack(L,1);L->top++;} +#define savestack(L,p)((char*)(p)-(char*)L->stack) +#define restorestack(L,n)((TValue*)((char*)L->stack+(n))) +#define saveci(L,p)((char*)(p)-(char*)L->base_ci) +#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n))) +typedef void(*Pfunc)(lua_State*L,void*ud); +static int luaD_poscall(lua_State*L,StkId firstResult); +static void luaD_reallocCI(lua_State*L,int newsize); +static void luaD_reallocstack(lua_State*L,int newsize); +static void luaD_growstack(lua_State*L,int n); +static void luaD_throw(lua_State*L,int errcode); +static void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems, +int limit,const char*errormsg){ +void*newblock; +int newsize; +if(*size>=limit/2){ +if(*size>=limit) +luaG_runerror(L,errormsg); +newsize=limit; +} +else{ +newsize=(*size)*2; +if(newsize<4) +newsize=4; +} +newblock=luaM_reallocv(L,block,*size,newsize,size_elems); +*size=newsize; +return newblock; +} +static void*luaM_toobig(lua_State*L){ +luaG_runerror(L,"memory allocation error: block too big"); +return NULL; +} +static void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){ +global_State*g=G(L); +block=(*g->frealloc)(g->ud,block,osize,nsize); +if(block==NULL&&nsize>0) +luaD_throw(L,4); +g->totalbytes=(g->totalbytes-osize)+nsize; +return block; +} +#define resetbits(x,m)((x)&=cast(lu_byte,~(m))) +#define setbits(x,m)((x)|=(m)) +#define testbits(x,m)((x)&(m)) +#define bitmask(b)(1<<(b)) +#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2)) +#define l_setbit(x,b)setbits(x,bitmask(b)) +#define resetbit(x,b)resetbits(x,bitmask(b)) +#define testbit(x,b)testbits(x,bitmask(b)) +#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2))) +#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2))) +#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2))) +#define iswhite(x)test2bits((x)->gch.marked,0,1) +#define isblack(x)testbit((x)->gch.marked,2) +#define isgray(x)(!isblack(x)&&!iswhite(x)) +#define otherwhite(g)(g->currentwhite^bit2mask(0,1)) +#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1)) +#define changewhite(x)((x)->gch.marked^=bit2mask(0,1)) +#define gray2black(x)l_setbit((x)->gch.marked,2) +#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x))) +#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1)) +#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);} +#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));} +#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);} +#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));} +#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);} +static void luaC_step(lua_State*L); +static void luaC_link(lua_State*L,GCObject*o,lu_byte tt); +static void luaC_linkupval(lua_State*L,UpVal*uv); +static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v); +static void luaC_barrierback(lua_State*L,Table*t); +#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char)) +#define sizeudata(u)(sizeof(union Udata)+(u)->len) +#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s))) +#define luaS_newliteral(L,s)(luaS_newlstr(L,""s,(sizeof(s)/sizeof(char))-1)) +#define luaS_fix(s)l_setbit((s)->tsv.marked,5) +static TString*luaS_newlstr(lua_State*L,const char*str,size_t l); +#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o))) +#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL)) +#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2)) +static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2); +static const TValue*luaV_tonumber(const TValue*obj,TValue*n); +static int luaV_tostring(lua_State*L,StkId obj); +static void luaV_execute(lua_State*L,int nexeccalls); +static void luaV_concat(lua_State*L,int total,int last); +static const TValue luaO_nilobject_={{NULL},0}; +static int luaO_int2fb(unsigned int x){ +int e=0; +while(x>=16){ +x=(x+1)>>1; +e++; +} +if(x<8)return x; +else return((e+1)<<3)|(cast_int(x)-8); +} +static int luaO_fb2int(int x){ +int e=(x>>3)&31; +if(e==0)return x; +else return((x&7)+8)<<(e-1); +} +static int luaO_log2(unsigned int x){ +static const lu_byte log_2[256]={ +0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 +}; +int l=-1; +while(x>=256){l+=8;x>>=8;} +return l+log_2[x]; +} +static int luaO_rawequalObj(const TValue*t1,const TValue*t2){ +if(ttype(t1)!=ttype(t2))return 0; +else switch(ttype(t1)){ +case 0: +return 1; +case 3: +return luai_numeq(nvalue(t1),nvalue(t2)); +case 1: +return bvalue(t1)==bvalue(t2); +case 2: +return pvalue(t1)==pvalue(t2); +default: +return gcvalue(t1)==gcvalue(t2); +} +} +static int luaO_str2d(const char*s,lua_Number*result){ +char*endptr; +*result=lua_str2number(s,&endptr); +if(endptr==s)return 0; +if(*endptr=='x'||*endptr=='X') +*result=cast_num(strtoul(s,&endptr,16)); +if(*endptr=='\0')return 1; +while(isspace(cast(unsigned char,*endptr)))endptr++; +if(*endptr!='\0')return 0; +return 1; +} +static void pushstr(lua_State*L,const char*str){ +setsvalue(L,L->top,luaS_new(L,str)); +incr_top(L); +} +static const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){ +int n=1; +pushstr(L,""); +for(;;){ +const char*e=strchr(fmt,'%'); +if(e==NULL)break; +setsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt)); +incr_top(L); +switch(*(e+1)){ +case's':{ +const char*s=va_arg(argp,char*); +if(s==NULL)s="(null)"; +pushstr(L,s); +break; +} +case'c':{ +char buff[2]; +buff[0]=cast(char,va_arg(argp,int)); +buff[1]='\0'; +pushstr(L,buff); +break; +} +case'd':{ +setnvalue(L->top,cast_num(va_arg(argp,int))); +incr_top(L); +break; +} +case'f':{ +setnvalue(L->top,cast_num(va_arg(argp,l_uacNumber))); +incr_top(L); +break; +} +case'p':{ +char buff[4*sizeof(void*)+8]; +sprintf(buff,"%p",va_arg(argp,void*)); +pushstr(L,buff); +break; +} +case'%':{ +pushstr(L,"%"); +break; +} +default:{ +char buff[3]; +buff[0]='%'; +buff[1]=*(e+1); +buff[2]='\0'; +pushstr(L,buff); +break; +} +} +n+=2; +fmt=e+2; +} +pushstr(L,fmt); +luaV_concat(L,n+1,cast_int(L->top-L->base)-1); +L->top-=n; +return svalue(L->top-1); +} +static const char*luaO_pushfstring(lua_State*L,const char*fmt,...){ +const char*msg; +va_list argp; +va_start(argp,fmt); +msg=luaO_pushvfstring(L,fmt,argp); +va_end(argp); +return msg; +} +static void luaO_chunkid(char*out,const char*source,size_t bufflen){ +if(*source=='='){ +strncpy(out,source+1,bufflen); +out[bufflen-1]='\0'; +} +else{ +if(*source=='@'){ +size_t l; +source++; +bufflen-=sizeof(" '...' "); +l=strlen(source); +strcpy(out,""); +if(l>bufflen){ +source+=(l-bufflen); +strcat(out,"..."); +} +strcat(out,source); +} +else{ +size_t len=strcspn(source,"\n\r"); +bufflen-=sizeof(" [string \"...\"] "); +if(len>bufflen)len=bufflen; +strcpy(out,"[string \""); +if(source[len]!='\0'){ +strncat(out,source,len); +strcat(out,"..."); +} +else +strcat(out,source); +strcat(out,"\"]"); +} +} +} +#define gnode(t,i)(&(t)->node[i]) +#define gkey(n)(&(n)->i_key.nk) +#define gval(n)(&(n)->i_val) +#define gnext(n)((n)->i_key.nk.next) +#define key2tval(n)(&(n)->i_key.tvk) +static TValue*luaH_setnum(lua_State*L,Table*t,int key); +static const TValue*luaH_getstr(Table*t,TString*key); +static TValue*luaH_set(lua_State*L,Table*t,const TValue*key); +static const char*const luaT_typenames[]={ +"nil","boolean","userdata","number", +"string","table","function","userdata","thread", +"proto","upval" +}; +static void luaT_init(lua_State*L){ +static const char*const luaT_eventname[]={ +"__index","__newindex", +"__gc","__mode","__eq", +"__add","__sub","__mul","__div","__mod", +"__pow","__unm","__len","__lt","__le", +"__concat","__call" +}; +int i; +for(i=0;itmname[i]=luaS_new(L,luaT_eventname[i]); +luaS_fix(G(L)->tmname[i]); +} +} +static const TValue*luaT_gettm(Table*events,TMS event,TString*ename){ +const TValue*tm=luaH_getstr(events,ename); +if(ttisnil(tm)){ +events->flags|=cast_byte(1u<metatable; +break; +case 7: +mt=uvalue(o)->metatable; +break; +default: +mt=G(L)->mt[ttype(o)]; +} +return(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_)); +} +#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1))) +#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1))) +static Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){ +Closure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems))); +luaC_link(L,obj2gco(c),6); +c->c.isC=1; +c->c.env=e; +c->c.nupvalues=cast_byte(nelems); +return c; +} +static Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){ +Closure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems))); +luaC_link(L,obj2gco(c),6); +c->l.isC=0; +c->l.env=e; +c->l.nupvalues=cast_byte(nelems); +while(nelems--)c->l.upvals[nelems]=NULL; +return c; +} +static UpVal*luaF_newupval(lua_State*L){ +UpVal*uv=luaM_new(L,UpVal); +luaC_link(L,obj2gco(uv),(8+2)); +uv->v=&uv->u.value; +setnilvalue(uv->v); +return uv; +} +static UpVal*luaF_findupval(lua_State*L,StkId level){ +global_State*g=G(L); +GCObject**pp=&L->openupval; +UpVal*p; +UpVal*uv; +while(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){ +if(p->v==level){ +if(isdead(g,obj2gco(p))) +changewhite(obj2gco(p)); +return p; +} +pp=&p->next; +} +uv=luaM_new(L,UpVal); +uv->tt=(8+2); +uv->marked=luaC_white(g); +uv->v=level; +uv->next=*pp; +*pp=obj2gco(uv); +uv->u.l.prev=&g->uvhead; +uv->u.l.next=g->uvhead.u.l.next; +uv->u.l.next->u.l.prev=uv; +g->uvhead.u.l.next=uv; +return uv; +} +static void unlinkupval(UpVal*uv){ +uv->u.l.next->u.l.prev=uv->u.l.prev; +uv->u.l.prev->u.l.next=uv->u.l.next; +} +static void luaF_freeupval(lua_State*L,UpVal*uv){ +if(uv->v!=&uv->u.value) +unlinkupval(uv); +luaM_free(L,uv); +} +static void luaF_close(lua_State*L,StkId level){ +UpVal*uv; +global_State*g=G(L); +while(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){ +GCObject*o=obj2gco(uv); +L->openupval=uv->next; +if(isdead(g,o)) +luaF_freeupval(L,uv); +else{ +unlinkupval(uv); +setobj(L,&uv->u.value,uv->v); +uv->v=&uv->u.value; +luaC_linkupval(L,uv); +} +} +} +static Proto*luaF_newproto(lua_State*L){ +Proto*f=luaM_new(L,Proto); +luaC_link(L,obj2gco(f),(8+1)); +f->k=NULL; +f->sizek=0; +f->p=NULL; +f->sizep=0; +f->code=NULL; +f->sizecode=0; +f->sizelineinfo=0; +f->sizeupvalues=0; +f->nups=0; +f->upvalues=NULL; +f->numparams=0; +f->is_vararg=0; +f->maxstacksize=0; +f->lineinfo=NULL; +f->sizelocvars=0; +f->locvars=NULL; +f->linedefined=0; +f->lastlinedefined=0; +f->source=NULL; +return f; +} +static void luaF_freeproto(lua_State*L,Proto*f){ +luaM_freearray(L,f->code,f->sizecode,Instruction); +luaM_freearray(L,f->p,f->sizep,Proto*); +luaM_freearray(L,f->k,f->sizek,TValue); +luaM_freearray(L,f->lineinfo,f->sizelineinfo,int); +luaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar); +luaM_freearray(L,f->upvalues,f->sizeupvalues,TString*); +luaM_free(L,f); +} +static void luaF_freeclosure(lua_State*L,Closure*c){ +int size=(c->c.isC)?sizeCclosure(c->c.nupvalues): +sizeLclosure(c->l.nupvalues); +luaM_freemem(L,c,size); +} +#define MASK1(n,p)((~((~(Instruction)0)<>0)&MASK1(6,0))) +#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0)))) +#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0))) +#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6))))) +#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0))) +#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9))))) +#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0))) +#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8))))) +#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0))) +#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8))))) +#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1)) +#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1))) +#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8))) +#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8))) +#define ISK(x)((x)&(1<<(9-1))) +#define INDEXK(r)((int)(r)&~(1<<(9-1))) +#define RKASK(x)((x)|(1<<(9-1))) +static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]; +#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3)) +#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3)) +#define testTMode(m)(luaP_opmodes[m]&(1<<7)) +typedef struct expdesc{ +expkind k; +union{ +struct{int info,aux;}s; +lua_Number nval; +}u; +int t; +int f; +}expdesc; +typedef struct upvaldesc{ +lu_byte k; +lu_byte info; +}upvaldesc; +struct BlockCnt; +typedef struct FuncState{ +Proto*f; +Table*h; +struct FuncState*prev; +struct LexState*ls; +struct lua_State*L; +struct BlockCnt*bl; +int pc; +int lasttarget; +int jpc; +int freereg; +int nk; +int np; +short nlocvars; +lu_byte nactvar; +upvaldesc upvalues[60]; +unsigned short actvar[200]; +}FuncState; +static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff, +const char*name); +struct lua_longjmp{ +struct lua_longjmp*previous; +jmp_buf b; +volatile int status; +}; +static void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){ +switch(errcode){ +case 4:{ +setsvalue(L,oldtop,luaS_newliteral(L,"not enough memory")); +break; +} +case 5:{ +setsvalue(L,oldtop,luaS_newliteral(L,"error in error handling")); +break; +} +case 3: +case 2:{ +setobj(L,oldtop,L->top-1); +break; +} +} +L->top=oldtop+1; +} +static void restore_stack_limit(lua_State*L){ +if(L->size_ci>20000){ +int inuse=cast_int(L->ci-L->base_ci); +if(inuse+1<20000) +luaD_reallocCI(L,20000); +} +} +static void resetstack(lua_State*L,int status){ +L->ci=L->base_ci; +L->base=L->ci->base; +luaF_close(L,L->base); +luaD_seterrorobj(L,status,L->base); +L->nCcalls=L->baseCcalls; +L->allowhook=1; +restore_stack_limit(L); +L->errfunc=0; +L->errorJmp=NULL; +} +static void luaD_throw(lua_State*L,int errcode){ +if(L->errorJmp){ +L->errorJmp->status=errcode; +LUAI_THROW(L,L->errorJmp); +} +else{ +L->status=cast_byte(errcode); +if(G(L)->panic){ +resetstack(L,errcode); +G(L)->panic(L); +} +exit(EXIT_FAILURE); +} +} +static int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){ +struct lua_longjmp lj; +lj.status=0; +lj.previous=L->errorJmp; +L->errorJmp=&lj; +LUAI_TRY(L,&lj, +(*f)(L,ud); +); +L->errorJmp=lj.previous; +return lj.status; +} +static void correctstack(lua_State*L,TValue*oldstack){ +CallInfo*ci; +GCObject*up; +L->top=(L->top-oldstack)+L->stack; +for(up=L->openupval;up!=NULL;up=up->gch.next) +gco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack; +for(ci=L->base_ci;ci<=L->ci;ci++){ +ci->top=(ci->top-oldstack)+L->stack; +ci->base=(ci->base-oldstack)+L->stack; +ci->func=(ci->func-oldstack)+L->stack; +} +L->base=(L->base-oldstack)+L->stack; +} +static void luaD_reallocstack(lua_State*L,int newsize){ +TValue*oldstack=L->stack; +int realsize=newsize+1+5; +luaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue); +L->stacksize=realsize; +L->stack_last=L->stack+newsize; +correctstack(L,oldstack); +} +static void luaD_reallocCI(lua_State*L,int newsize){ +CallInfo*oldci=L->base_ci; +luaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo); +L->size_ci=newsize; +L->ci=(L->ci-oldci)+L->base_ci; +L->end_ci=L->base_ci+L->size_ci-1; +} +static void luaD_growstack(lua_State*L,int n){ +if(n<=L->stacksize) +luaD_reallocstack(L,2*L->stacksize); +else +luaD_reallocstack(L,L->stacksize+n); +} +static CallInfo*growCI(lua_State*L){ +if(L->size_ci>20000) +luaD_throw(L,5); +else{ +luaD_reallocCI(L,2*L->size_ci); +if(L->size_ci>20000) +luaG_runerror(L,"stack overflow"); +} +return++L->ci; +} +static StkId adjust_varargs(lua_State*L,Proto*p,int actual){ +int i; +int nfixargs=p->numparams; +Table*htab=NULL; +StkId base,fixed; +for(;actualtop++); +fixed=L->top-actual; +base=L->top; +for(i=0;itop++,fixed+i); +setnilvalue(fixed+i); +} +if(htab){ +sethvalue(L,L->top++,htab); +} +return base; +} +static StkId tryfuncTM(lua_State*L,StkId func){ +const TValue*tm=luaT_gettmbyobj(L,func,TM_CALL); +StkId p; +ptrdiff_t funcr=savestack(L,func); +if(!ttisfunction(tm)) +luaG_typeerror(L,func,"call"); +for(p=L->top;p>func;p--)setobj(L,p,p-1); +incr_top(L); +func=restorestack(L,funcr); +setobj(L,func,tm); +return func; +} +#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci)) +static int luaD_precall(lua_State*L,StkId func,int nresults){ +LClosure*cl; +ptrdiff_t funcr; +if(!ttisfunction(func)) +func=tryfuncTM(L,func); +funcr=savestack(L,func); +cl=&clvalue(func)->l; +L->ci->savedpc=L->savedpc; +if(!cl->isC){ +CallInfo*ci; +StkId st,base; +Proto*p=cl->p; +luaD_checkstack(L,p->maxstacksize); +func=restorestack(L,funcr); +if(!p->is_vararg){ +base=func+1; +if(L->top>base+p->numparams) +L->top=base+p->numparams; +} +else{ +int nargs=cast_int(L->top-func)-1; +base=adjust_varargs(L,p,nargs); +func=restorestack(L,funcr); +} +ci=inc_ci(L); +ci->func=func; +L->base=ci->base=base; +ci->top=L->base+p->maxstacksize; +L->savedpc=p->code; +ci->tailcalls=0; +ci->nresults=nresults; +for(st=L->top;sttop;st++) +setnilvalue(st); +L->top=ci->top; +return 0; +} +else{ +CallInfo*ci; +int n; +luaD_checkstack(L,20); +ci=inc_ci(L); +ci->func=restorestack(L,funcr); +L->base=ci->base=ci->func+1; +ci->top=L->top+20; +ci->nresults=nresults; +n=(*curr_func(L)->c.f)(L); +if(n<0) +return 2; +else{ +luaD_poscall(L,L->top-n); +return 1; +} +} +} +static int luaD_poscall(lua_State*L,StkId firstResult){ +StkId res; +int wanted,i; +CallInfo*ci; +ci=L->ci--; +res=ci->func; +wanted=ci->nresults; +L->base=(ci-1)->base; +L->savedpc=(ci-1)->savedpc; +for(i=wanted;i!=0&&firstResulttop;i--) +setobj(L,res++,firstResult++); +while(i-->0) +setnilvalue(res++); +L->top=res; +return(wanted-(-1)); +} +static void luaD_call(lua_State*L,StkId func,int nResults){ +if(++L->nCcalls>=200){ +if(L->nCcalls==200) +luaG_runerror(L,"C stack overflow"); +else if(L->nCcalls>=(200+(200>>3))) +luaD_throw(L,5); +} +if(luaD_precall(L,func,nResults)==0) +luaV_execute(L,1); +L->nCcalls--; +luaC_checkGC(L); +} +static int luaD_pcall(lua_State*L,Pfunc func,void*u, +ptrdiff_t old_top,ptrdiff_t ef){ +int status; +unsigned short oldnCcalls=L->nCcalls; +ptrdiff_t old_ci=saveci(L,L->ci); +lu_byte old_allowhooks=L->allowhook; +ptrdiff_t old_errfunc=L->errfunc; +L->errfunc=ef; +status=luaD_rawrunprotected(L,func,u); +if(status!=0){ +StkId oldtop=restorestack(L,old_top); +luaF_close(L,oldtop); +luaD_seterrorobj(L,status,oldtop); +L->nCcalls=oldnCcalls; +L->ci=restoreci(L,old_ci); +L->base=L->ci->base; +L->savedpc=L->ci->savedpc; +L->allowhook=old_allowhooks; +restore_stack_limit(L); +} +L->errfunc=old_errfunc; +return status; +} +struct SParser{ +ZIO*z; +Mbuffer buff; +const char*name; +}; +static void f_parser(lua_State*L,void*ud){ +int i; +Proto*tf; +Closure*cl; +struct SParser*p=cast(struct SParser*,ud); +luaC_checkGC(L); +tf=luaY_parser(L,p->z, +&p->buff,p->name); +cl=luaF_newLclosure(L,tf->nups,hvalue(gt(L))); +cl->l.p=tf; +for(i=0;inups;i++) +cl->l.upvals[i]=luaF_newupval(L); +setclvalue(L,L->top,cl); +incr_top(L); +} +static int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){ +struct SParser p; +int status; +p.z=z;p.name=name; +luaZ_initbuffer(L,&p.buff); +status=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc); +luaZ_freebuffer(L,&p.buff); +return status; +} +static void luaS_resize(lua_State*L,int newsize){ +GCObject**newhash; +stringtable*tb; +int i; +if(G(L)->gcstate==2) +return; +newhash=luaM_newvector(L,newsize,GCObject*); +tb=&G(L)->strt; +for(i=0;isize;i++){ +GCObject*p=tb->hash[i]; +while(p){ +GCObject*next=p->gch.next; +unsigned int h=gco2ts(p)->hash; +int h1=lmod(h,newsize); +p->gch.next=newhash[h1]; +newhash[h1]=p; +p=next; +} +} +luaM_freearray(L,tb->hash,tb->size,TString*); +tb->size=newsize; +tb->hash=newhash; +} +static TString*newlstr(lua_State*L,const char*str,size_t l, +unsigned int h){ +TString*ts; +stringtable*tb; +if(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char)) +luaM_toobig(L); +ts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString))); +ts->tsv.len=l; +ts->tsv.hash=h; +ts->tsv.marked=luaC_white(G(L)); +ts->tsv.tt=4; +ts->tsv.reserved=0; +memcpy(ts+1,str,l*sizeof(char)); +((char*)(ts+1))[l]='\0'; +tb=&G(L)->strt; +h=lmod(h,tb->size); +ts->tsv.next=tb->hash[h]; +tb->hash[h]=obj2gco(ts); +tb->nuse++; +if(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2) +luaS_resize(L,tb->size*2); +return ts; +} +static TString*luaS_newlstr(lua_State*L,const char*str,size_t l){ +GCObject*o; +unsigned int h=cast(unsigned int,l); +size_t step=(l>>5)+1; +size_t l1; +for(l1=l;l1>=step;l1-=step) +h=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1])); +for(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)]; +o!=NULL; +o=o->gch.next){ +TString*ts=rawgco2ts(o); +if(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){ +if(isdead(G(L),o))changewhite(o); +return ts; +} +} +return newlstr(L,str,l,h); +} +static Udata*luaS_newudata(lua_State*L,size_t s,Table*e){ +Udata*u; +if(s>((size_t)(~(size_t)0)-2)-sizeof(Udata)) +luaM_toobig(L); +u=cast(Udata*,luaM_malloc(L,s+sizeof(Udata))); +u->uv.marked=luaC_white(G(L)); +u->uv.tt=7; +u->uv.len=s; +u->uv.metatable=NULL; +u->uv.env=e; +u->uv.next=G(L)->mainthread->next; +G(L)->mainthread->next=obj2gco(u); +return u; +} +#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t)))) +#define hashstr(t,str)hashpow2(t,(str)->tsv.hash) +#define hashboolean(t,p)hashpow2(t,p) +#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1)))) +#define hashpointer(t,p)hashmod(t,IntPoint(p)) +static const Node dummynode_={ +{{NULL},0}, +{{{NULL},0,NULL}} +}; +static Node*hashnum(const Table*t,lua_Number n){ +unsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))]; +int i; +if(luai_numeq(n,0)) +return gnode(t,0); +memcpy(a,&n,sizeof(a)); +for(i=1;isizearray) +return i-1; +else{ +Node*n=mainposition(t,key); +do{ +if(luaO_rawequalObj(key2tval(n),key)|| +(ttype(gkey(n))==(8+3)&&iscollectable(key)&& +gcvalue(gkey(n))==gcvalue(key))){ +i=cast_int(n-gnode(t,0)); +return i+t->sizearray; +} +else n=gnext(n); +}while(n); +luaG_runerror(L,"invalid key to "LUA_QL("next")); +return 0; +} +} +static int luaH_next(lua_State*L,Table*t,StkId key){ +int i=findindex(L,t,key); +for(i++;isizearray;i++){ +if(!ttisnil(&t->array[i])){ +setnvalue(key,cast_num(i+1)); +setobj(L,key+1,&t->array[i]); +return 1; +} +} +for(i-=t->sizearray;i<(int)sizenode(t);i++){ +if(!ttisnil(gval(gnode(t,i)))){ +setobj(L,key,key2tval(gnode(t,i))); +setobj(L,key+1,gval(gnode(t,i))); +return 1; +} +} +return 0; +} +static int computesizes(int nums[],int*narray){ +int i; +int twotoi; +int a=0; +int na=0; +int n=0; +for(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){ +if(nums[i]>0){ +a+=nums[i]; +if(a>twotoi/2){ +n=twotoi; +na=a; +} +} +if(a==*narray)break; +} +*narray=n; +return na; +} +static int countint(const TValue*key,int*nums){ +int k=arrayindex(key); +if(0t->sizearray){ +lim=t->sizearray; +if(i>lim) +break; +} +for(;i<=lim;i++){ +if(!ttisnil(&t->array[i-1])) +lc++; +} +nums[lg]+=lc; +ause+=lc; +} +return ause; +} +static int numusehash(const Table*t,int*nums,int*pnasize){ +int totaluse=0; +int ause=0; +int i=sizenode(t); +while(i--){ +Node*n=&t->node[i]; +if(!ttisnil(gval(n))){ +ause+=countint(key2tval(n),nums); +totaluse++; +} +} +*pnasize+=ause; +return totaluse; +} +static void setarrayvector(lua_State*L,Table*t,int size){ +int i; +luaM_reallocvector(L,t->array,t->sizearray,size,TValue); +for(i=t->sizearray;iarray[i]); +t->sizearray=size; +} +static void setnodevector(lua_State*L,Table*t,int size){ +int lsize; +if(size==0){ +t->node=cast(Node*,(&dummynode_)); +lsize=0; +} +else{ +int i; +lsize=ceillog2(size); +if(lsize>(32-2)) +luaG_runerror(L,"table overflow"); +size=twoto(lsize); +t->node=luaM_newvector(L,size,Node); +for(i=0;ilsizenode=cast_byte(lsize); +t->lastfree=gnode(t,size); +} +static void resize(lua_State*L,Table*t,int nasize,int nhsize){ +int i; +int oldasize=t->sizearray; +int oldhsize=t->lsizenode; +Node*nold=t->node; +if(nasize>oldasize) +setarrayvector(L,t,nasize); +setnodevector(L,t,nhsize); +if(nasizesizearray=nasize; +for(i=nasize;iarray[i])) +setobj(L,luaH_setnum(L,t,i+1),&t->array[i]); +} +luaM_reallocvector(L,t->array,oldasize,nasize,TValue); +} +for(i=twoto(oldhsize)-1;i>=0;i--){ +Node*old=nold+i; +if(!ttisnil(gval(old))) +setobj(L,luaH_set(L,t,key2tval(old)),gval(old)); +} +if(nold!=(&dummynode_)) +luaM_freearray(L,nold,twoto(oldhsize),Node); +} +static void luaH_resizearray(lua_State*L,Table*t,int nasize){ +int nsize=(t->node==(&dummynode_))?0:sizenode(t); +resize(L,t,nasize,nsize); +} +static void rehash(lua_State*L,Table*t,const TValue*ek){ +int nasize,na; +int nums[(32-2)+1]; +int i; +int totaluse; +for(i=0;i<=(32-2);i++)nums[i]=0; +nasize=numusearray(t,nums); +totaluse=nasize; +totaluse+=numusehash(t,nums,&nasize); +nasize+=countint(ek,nums); +totaluse++; +na=computesizes(nums,&nasize); +resize(L,t,nasize,totaluse-na); +} +static Table*luaH_new(lua_State*L,int narray,int nhash){ +Table*t=luaM_new(L,Table); +luaC_link(L,obj2gco(t),5); +t->metatable=NULL; +t->flags=cast_byte(~0); +t->array=NULL; +t->sizearray=0; +t->lsizenode=0; +t->node=cast(Node*,(&dummynode_)); +setarrayvector(L,t,narray); +setnodevector(L,t,nhash); +return t; +} +static void luaH_free(lua_State*L,Table*t){ +if(t->node!=(&dummynode_)) +luaM_freearray(L,t->node,sizenode(t),Node); +luaM_freearray(L,t->array,t->sizearray,TValue); +luaM_free(L,t); +} +static Node*getfreepos(Table*t){ +while(t->lastfree-->t->node){ +if(ttisnil(gkey(t->lastfree))) +return t->lastfree; +} +return NULL; +} +static TValue*newkey(lua_State*L,Table*t,const TValue*key){ +Node*mp=mainposition(t,key); +if(!ttisnil(gval(mp))||mp==(&dummynode_)){ +Node*othern; +Node*n=getfreepos(t); +if(n==NULL){ +rehash(L,t,key); +return luaH_set(L,t,key); +} +othern=mainposition(t,key2tval(mp)); +if(othern!=mp){ +while(gnext(othern)!=mp)othern=gnext(othern); +gnext(othern)=n; +*n=*mp; +gnext(mp)=NULL; +setnilvalue(gval(mp)); +} +else{ +gnext(n)=gnext(mp); +gnext(mp)=n; +mp=n; +} +} +gkey(mp)->value=key->value;gkey(mp)->tt=key->tt; +luaC_barriert(L,t,key); +return gval(mp); +} +static const TValue*luaH_getnum(Table*t,int key){ +if(cast(unsigned int,key-1)sizearray)) +return&t->array[key-1]; +else{ +lua_Number nk=cast_num(key); +Node*n=hashnum(t,nk); +do{ +if(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk)) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +} +static const TValue*luaH_getstr(Table*t,TString*key){ +Node*n=hashstr(t,key); +do{ +if(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +static const TValue*luaH_get(Table*t,const TValue*key){ +switch(ttype(key)){ +case 0:return(&luaO_nilobject_); +case 4:return luaH_getstr(t,rawtsvalue(key)); +case 3:{ +int k; +lua_Number n=nvalue(key); +lua_number2int(k,n); +if(luai_numeq(cast_num(k),nvalue(key))) +return luaH_getnum(t,k); +} +default:{ +Node*n=mainposition(t,key); +do{ +if(luaO_rawequalObj(key2tval(n),key)) +return gval(n); +else n=gnext(n); +}while(n); +return(&luaO_nilobject_); +} +} +} +static TValue*luaH_set(lua_State*L,Table*t,const TValue*key){ +const TValue*p=luaH_get(t,key); +t->flags=0; +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +if(ttisnil(key))luaG_runerror(L,"table index is nil"); +else if(ttisnumber(key)&&luai_numisnan(nvalue(key))) +luaG_runerror(L,"table index is NaN"); +return newkey(L,t,key); +} +} +static TValue*luaH_setnum(lua_State*L,Table*t,int key){ +const TValue*p=luaH_getnum(t,key); +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +TValue k; +setnvalue(&k,cast_num(key)); +return newkey(L,t,&k); +} +} +static TValue*luaH_setstr(lua_State*L,Table*t,TString*key){ +const TValue*p=luaH_getstr(t,key); +if(p!=(&luaO_nilobject_)) +return cast(TValue*,p); +else{ +TValue k; +setsvalue(L,&k,key); +return newkey(L,t,&k); +} +} +static int unbound_search(Table*t,unsigned int j){ +unsigned int i=j; +j++; +while(!ttisnil(luaH_getnum(t,j))){ +i=j; +j*=2; +if(j>cast(unsigned int,(INT_MAX-2))){ +i=1; +while(!ttisnil(luaH_getnum(t,i)))i++; +return i-1; +} +} +while(j-i>1){ +unsigned int m=(i+j)/2; +if(ttisnil(luaH_getnum(t,m)))j=m; +else i=m; +} +return i; +} +static int luaH_getn(Table*t){ +unsigned int j=t->sizearray; +if(j>0&&ttisnil(&t->array[j-1])){ +unsigned int i=0; +while(j-i>1){ +unsigned int m=(i+j)/2; +if(ttisnil(&t->array[m-1]))j=m; +else i=m; +} +return i; +} +else if(t->node==(&dummynode_)) +return j; +else return unbound_search(t,j); +} +#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g))) +#define white2gray(x)reset2bits((x)->gch.marked,0,1) +#define black2gray(x)resetbit((x)->gch.marked,2) +#define stringmark(s)reset2bits((s)->tsv.marked,0,1) +#define isfinalized(u)testbit((u)->marked,3) +#define markfinalized(u)l_setbit((u)->marked,3) +#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));} +#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));} +#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause) +static void removeentry(Node*n){ +if(iscollectable(gkey(n))) +setttype(gkey(n),(8+3)); +} +static void reallymarkobject(global_State*g,GCObject*o){ +white2gray(o); +switch(o->gch.tt){ +case 4:{ +return; +} +case 7:{ +Table*mt=gco2u(o)->metatable; +gray2black(o); +if(mt)markobject(g,mt); +markobject(g,gco2u(o)->env); +return; +} +case(8+2):{ +UpVal*uv=gco2uv(o); +markvalue(g,uv->v); +if(uv->v==&uv->u.value) +gray2black(o); +return; +} +case 6:{ +gco2cl(o)->c.gclist=g->gray; +g->gray=o; +break; +} +case 5:{ +gco2h(o)->gclist=g->gray; +g->gray=o; +break; +} +case 8:{ +gco2th(o)->gclist=g->gray; +g->gray=o; +break; +} +case(8+1):{ +gco2p(o)->gclist=g->gray; +g->gray=o; +break; +} +default:; +} +} +static void marktmu(global_State*g){ +GCObject*u=g->tmudata; +if(u){ +do{ +u=u->gch.next; +makewhite(g,u); +reallymarkobject(g,u); +}while(u!=g->tmudata); +} +} +static size_t luaC_separateudata(lua_State*L,int all){ +global_State*g=G(L); +size_t deadmem=0; +GCObject**p=&g->mainthread->next; +GCObject*curr; +while((curr=*p)!=NULL){ +if(!(iswhite(curr)||all)||isfinalized(gco2u(curr))) +p=&curr->gch.next; +else if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){ +markfinalized(gco2u(curr)); +p=&curr->gch.next; +} +else{ +deadmem+=sizeudata(gco2u(curr)); +markfinalized(gco2u(curr)); +*p=curr->gch.next; +if(g->tmudata==NULL) +g->tmudata=curr->gch.next=curr; +else{ +curr->gch.next=g->tmudata->gch.next; +g->tmudata->gch.next=curr; +g->tmudata=curr; +} +} +} +return deadmem; +} +static int traversetable(global_State*g,Table*h){ +int i; +int weakkey=0; +int weakvalue=0; +const TValue*mode; +if(h->metatable) +markobject(g,h->metatable); +mode=gfasttm(g,h->metatable,TM_MODE); +if(mode&&ttisstring(mode)){ +weakkey=(strchr(svalue(mode),'k')!=NULL); +weakvalue=(strchr(svalue(mode),'v')!=NULL); +if(weakkey||weakvalue){ +h->marked&=~(bitmask(3)|bitmask(4)); +h->marked|=cast_byte((weakkey<<3)| +(weakvalue<<4)); +h->gclist=g->weak; +g->weak=obj2gco(h); +} +} +if(weakkey&&weakvalue)return 1; +if(!weakvalue){ +i=h->sizearray; +while(i--) +markvalue(g,&h->array[i]); +} +i=sizenode(h); +while(i--){ +Node*n=gnode(h,i); +if(ttisnil(gval(n))) +removeentry(n); +else{ +if(!weakkey)markvalue(g,gkey(n)); +if(!weakvalue)markvalue(g,gval(n)); +} +} +return weakkey||weakvalue; +} +static void traverseproto(global_State*g,Proto*f){ +int i; +if(f->source)stringmark(f->source); +for(i=0;isizek;i++) +markvalue(g,&f->k[i]); +for(i=0;isizeupvalues;i++){ +if(f->upvalues[i]) +stringmark(f->upvalues[i]); +} +for(i=0;isizep;i++){ +if(f->p[i]) +markobject(g,f->p[i]); +} +for(i=0;isizelocvars;i++){ +if(f->locvars[i].varname) +stringmark(f->locvars[i].varname); +} +} +static void traverseclosure(global_State*g,Closure*cl){ +markobject(g,cl->c.env); +if(cl->c.isC){ +int i; +for(i=0;ic.nupvalues;i++) +markvalue(g,&cl->c.upvalue[i]); +} +else{ +int i; +markobject(g,cl->l.p); +for(i=0;il.nupvalues;i++) +markobject(g,cl->l.upvals[i]); +} +} +static void checkstacksizes(lua_State*L,StkId max){ +int ci_used=cast_int(L->ci-L->base_ci); +int s_used=cast_int(max-L->stack); +if(L->size_ci>20000) +return; +if(4*ci_usedsize_ci&&2*8size_ci) +luaD_reallocCI(L,L->size_ci/2); +condhardstacktests(luaD_reallocCI(L,ci_used+1)); +if(4*s_usedstacksize&& +2*((2*20)+5)stacksize) +luaD_reallocstack(L,L->stacksize/2); +condhardstacktests(luaD_reallocstack(L,s_used)); +} +static void traversestack(global_State*g,lua_State*l){ +StkId o,lim; +CallInfo*ci; +markvalue(g,gt(l)); +lim=l->top; +for(ci=l->base_ci;ci<=l->ci;ci++){ +if(limtop)lim=ci->top; +} +for(o=l->stack;otop;o++) +markvalue(g,o); +for(;o<=lim;o++) +setnilvalue(o); +checkstacksizes(l,lim); +} +static l_mem propagatemark(global_State*g){ +GCObject*o=g->gray; +gray2black(o); +switch(o->gch.tt){ +case 5:{ +Table*h=gco2h(o); +g->gray=h->gclist; +if(traversetable(g,h)) +black2gray(o); +return sizeof(Table)+sizeof(TValue)*h->sizearray+ +sizeof(Node)*sizenode(h); +} +case 6:{ +Closure*cl=gco2cl(o); +g->gray=cl->c.gclist; +traverseclosure(g,cl); +return(cl->c.isC)?sizeCclosure(cl->c.nupvalues): +sizeLclosure(cl->l.nupvalues); +} +case 8:{ +lua_State*th=gco2th(o); +g->gray=th->gclist; +th->gclist=g->grayagain; +g->grayagain=o; +black2gray(o); +traversestack(g,th); +return sizeof(lua_State)+sizeof(TValue)*th->stacksize+ +sizeof(CallInfo)*th->size_ci; +} +case(8+1):{ +Proto*p=gco2p(o); +g->gray=p->gclist; +traverseproto(g,p); +return sizeof(Proto)+sizeof(Instruction)*p->sizecode+ +sizeof(Proto*)*p->sizep+ +sizeof(TValue)*p->sizek+ +sizeof(int)*p->sizelineinfo+ +sizeof(LocVar)*p->sizelocvars+ +sizeof(TString*)*p->sizeupvalues; +} +default:return 0; +} +} +static size_t propagateall(global_State*g){ +size_t m=0; +while(g->gray)m+=propagatemark(g); +return m; +} +static int iscleared(const TValue*o,int iskey){ +if(!iscollectable(o))return 0; +if(ttisstring(o)){ +stringmark(rawtsvalue(o)); +return 0; +} +return iswhite(gcvalue(o))|| +(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o)))); +} +static void cleartable(GCObject*l){ +while(l){ +Table*h=gco2h(l); +int i=h->sizearray; +if(testbit(h->marked,4)){ +while(i--){ +TValue*o=&h->array[i]; +if(iscleared(o,0)) +setnilvalue(o); +} +} +i=sizenode(h); +while(i--){ +Node*n=gnode(h,i); +if(!ttisnil(gval(n))&& +(iscleared(key2tval(n),1)||iscleared(gval(n),0))){ +setnilvalue(gval(n)); +removeentry(n); +} +} +l=h->gclist; +} +} +static void freeobj(lua_State*L,GCObject*o){ +switch(o->gch.tt){ +case(8+1):luaF_freeproto(L,gco2p(o));break; +case 6:luaF_freeclosure(L,gco2cl(o));break; +case(8+2):luaF_freeupval(L,gco2uv(o));break; +case 5:luaH_free(L,gco2h(o));break; +case 8:{ +luaE_freethread(L,gco2th(o)); +break; +} +case 4:{ +G(L)->strt.nuse--; +luaM_freemem(L,o,sizestring(gco2ts(o))); +break; +} +case 7:{ +luaM_freemem(L,o,sizeudata(gco2u(o))); +break; +} +default:; +} +} +#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2)) +static GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){ +GCObject*curr; +global_State*g=G(L); +int deadmask=otherwhite(g); +while((curr=*p)!=NULL&&count-->0){ +if(curr->gch.tt==8) +sweepwholelist(L,&gco2th(curr)->openupval); +if((curr->gch.marked^bit2mask(0,1))&deadmask){ +makewhite(g,curr); +p=&curr->gch.next; +} +else{ +*p=curr->gch.next; +if(curr==g->rootgc) +g->rootgc=curr->gch.next; +freeobj(L,curr); +} +} +return p; +} +static void checkSizes(lua_State*L){ +global_State*g=G(L); +if(g->strt.nusestrt.size/4)&& +g->strt.size>32*2) +luaS_resize(L,g->strt.size/2); +if(luaZ_sizebuffer(&g->buff)>32*2){ +size_t newsize=luaZ_sizebuffer(&g->buff)/2; +luaZ_resizebuffer(L,&g->buff,newsize); +} +} +static void GCTM(lua_State*L){ +global_State*g=G(L); +GCObject*o=g->tmudata->gch.next; +Udata*udata=rawgco2u(o); +const TValue*tm; +if(o==g->tmudata) +g->tmudata=NULL; +else +g->tmudata->gch.next=udata->uv.next; +udata->uv.next=g->mainthread->next; +g->mainthread->next=o; +makewhite(g,o); +tm=fasttm(L,udata->uv.metatable,TM_GC); +if(tm!=NULL){ +lu_byte oldah=L->allowhook; +lu_mem oldt=g->GCthreshold; +L->allowhook=0; +g->GCthreshold=2*g->totalbytes; +setobj(L,L->top,tm); +setuvalue(L,L->top+1,udata); +L->top+=2; +luaD_call(L,L->top-2,0); +L->allowhook=oldah; +g->GCthreshold=oldt; +} +} +static void luaC_callGCTM(lua_State*L){ +while(G(L)->tmudata) +GCTM(L); +} +static void luaC_freeall(lua_State*L){ +global_State*g=G(L); +int i; +g->currentwhite=bit2mask(0,1)|bitmask(6); +sweepwholelist(L,&g->rootgc); +for(i=0;istrt.size;i++) +sweepwholelist(L,&g->strt.hash[i]); +} +static void markmt(global_State*g){ +int i; +for(i=0;i<(8+1);i++) +if(g->mt[i])markobject(g,g->mt[i]); +} +static void markroot(lua_State*L){ +global_State*g=G(L); +g->gray=NULL; +g->grayagain=NULL; +g->weak=NULL; +markobject(g,g->mainthread); +markvalue(g,gt(g->mainthread)); +markvalue(g,registry(L)); +markmt(g); +g->gcstate=1; +} +static void remarkupvals(global_State*g){ +UpVal*uv; +for(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){ +if(isgray(obj2gco(uv))) +markvalue(g,uv->v); +} +} +static void atomic(lua_State*L){ +global_State*g=G(L); +size_t udsize; +remarkupvals(g); +propagateall(g); +g->gray=g->weak; +g->weak=NULL; +markobject(g,L); +markmt(g); +propagateall(g); +g->gray=g->grayagain; +g->grayagain=NULL; +propagateall(g); +udsize=luaC_separateudata(L,0); +marktmu(g); +udsize+=propagateall(g); +cleartable(g->weak); +g->currentwhite=cast_byte(otherwhite(g)); +g->sweepstrgc=0; +g->sweepgc=&g->rootgc; +g->gcstate=2; +g->estimate=g->totalbytes-udsize; +} +static l_mem singlestep(lua_State*L){ +global_State*g=G(L); +switch(g->gcstate){ +case 0:{ +markroot(L); +return 0; +} +case 1:{ +if(g->gray) +return propagatemark(g); +else{ +atomic(L); +return 0; +} +} +case 2:{ +lu_mem old=g->totalbytes; +sweepwholelist(L,&g->strt.hash[g->sweepstrgc++]); +if(g->sweepstrgc>=g->strt.size) +g->gcstate=3; +g->estimate-=old-g->totalbytes; +return 10; +} +case 3:{ +lu_mem old=g->totalbytes; +g->sweepgc=sweeplist(L,g->sweepgc,40); +if(*g->sweepgc==NULL){ +checkSizes(L); +g->gcstate=4; +} +g->estimate-=old-g->totalbytes; +return 40*10; +} +case 4:{ +if(g->tmudata){ +GCTM(L); +if(g->estimate>100) +g->estimate-=100; +return 100; +} +else{ +g->gcstate=0; +g->gcdept=0; +return 0; +} +} +default:return 0; +} +} +static void luaC_step(lua_State*L){ +global_State*g=G(L); +l_mem lim=(1024u/100)*g->gcstepmul; +if(lim==0) +lim=(((lu_mem)(~(lu_mem)0)-2)-1)/2; +g->gcdept+=g->totalbytes-g->GCthreshold; +do{ +lim-=singlestep(L); +if(g->gcstate==0) +break; +}while(lim>0); +if(g->gcstate!=0){ +if(g->gcdept<1024u) +g->GCthreshold=g->totalbytes+1024u; +else{ +g->gcdept-=1024u; +g->GCthreshold=g->totalbytes; +} +} +else{ +setthreshold(g); +} +} +static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){ +global_State*g=G(L); +if(g->gcstate==1) +reallymarkobject(g,v); +else +makewhite(g,o); +} +static void luaC_barrierback(lua_State*L,Table*t){ +global_State*g=G(L); +GCObject*o=obj2gco(t); +black2gray(o); +t->gclist=g->grayagain; +g->grayagain=o; +} +static void luaC_link(lua_State*L,GCObject*o,lu_byte tt){ +global_State*g=G(L); +o->gch.next=g->rootgc; +g->rootgc=o; +o->gch.marked=luaC_white(g); +o->gch.tt=tt; +} +static void luaC_linkupval(lua_State*L,UpVal*uv){ +global_State*g=G(L); +GCObject*o=obj2gco(uv); +o->gch.next=g->rootgc; +g->rootgc=o; +if(isgray(o)){ +if(g->gcstate==1){ +gray2black(o); +luaC_barrier(L,uv,uv->v); +} +else{ +makewhite(g,o); +} +} +} +typedef union{ +lua_Number r; +TString*ts; +}SemInfo; +typedef struct Token{ +int token; +SemInfo seminfo; +}Token; +typedef struct LexState{ +int current; +int linenumber; +int lastline; +Token t; +Token lookahead; +struct FuncState*fs; +struct lua_State*L; +ZIO*z; +Mbuffer*buff; +TString*source; +char decpoint; +}LexState; +static void luaX_init(lua_State*L); +static void luaX_lexerror(LexState*ls,const char*msg,int token); +#define state_size(x)(sizeof(x)+0) +#define fromstate(l)(cast(lu_byte*,(l))-0) +#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0)) +typedef struct LG{ +lua_State l; +global_State g; +}LG; +static void stack_init(lua_State*L1,lua_State*L){ +L1->base_ci=luaM_newvector(L,8,CallInfo); +L1->ci=L1->base_ci; +L1->size_ci=8; +L1->end_ci=L1->base_ci+L1->size_ci-1; +L1->stack=luaM_newvector(L,(2*20)+5,TValue); +L1->stacksize=(2*20)+5; +L1->top=L1->stack; +L1->stack_last=L1->stack+(L1->stacksize-5)-1; +L1->ci->func=L1->top; +setnilvalue(L1->top++); +L1->base=L1->ci->base=L1->top; +L1->ci->top=L1->top+20; +} +static void freestack(lua_State*L,lua_State*L1){ +luaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo); +luaM_freearray(L,L1->stack,L1->stacksize,TValue); +} +static void f_luaopen(lua_State*L,void*ud){ +global_State*g=G(L); +UNUSED(ud); +stack_init(L,L); +sethvalue(L,gt(L),luaH_new(L,0,2)); +sethvalue(L,registry(L),luaH_new(L,0,2)); +luaS_resize(L,32); +luaT_init(L); +luaX_init(L); +luaS_fix(luaS_newliteral(L,"not enough memory")); +g->GCthreshold=4*g->totalbytes; +} +static void preinit_state(lua_State*L,global_State*g){ +G(L)=g; +L->stack=NULL; +L->stacksize=0; +L->errorJmp=NULL; +L->hook=NULL; +L->hookmask=0; +L->basehookcount=0; +L->allowhook=1; +resethookcount(L); +L->openupval=NULL; +L->size_ci=0; +L->nCcalls=L->baseCcalls=0; +L->status=0; +L->base_ci=L->ci=NULL; +L->savedpc=NULL; +L->errfunc=0; +setnilvalue(gt(L)); +} +static void close_state(lua_State*L){ +global_State*g=G(L); +luaF_close(L,L->stack); +luaC_freeall(L); +luaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*); +luaZ_freebuffer(L,&g->buff); +freestack(L,L); +(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0); +} +static void luaE_freethread(lua_State*L,lua_State*L1){ +luaF_close(L1,L1->stack); +freestack(L,L1); +luaM_freemem(L,fromstate(L1),state_size(lua_State)); +} +static lua_State*lua_newstate(lua_Alloc f,void*ud){ +int i; +lua_State*L; +global_State*g; +void*l=(*f)(ud,NULL,0,state_size(LG)); +if(l==NULL)return NULL; +L=tostate(l); +g=&((LG*)L)->g; +L->next=NULL; +L->tt=8; +g->currentwhite=bit2mask(0,5); +L->marked=luaC_white(g); +set2bits(L->marked,5,6); +preinit_state(L,g); +g->frealloc=f; +g->ud=ud; +g->mainthread=L; +g->uvhead.u.l.prev=&g->uvhead; +g->uvhead.u.l.next=&g->uvhead; +g->GCthreshold=0; +g->strt.size=0; +g->strt.nuse=0; +g->strt.hash=NULL; +setnilvalue(registry(L)); +luaZ_initbuffer(L,&g->buff); +g->panic=NULL; +g->gcstate=0; +g->rootgc=obj2gco(L); +g->sweepstrgc=0; +g->sweepgc=&g->rootgc; +g->gray=NULL; +g->grayagain=NULL; +g->weak=NULL; +g->tmudata=NULL; +g->totalbytes=sizeof(LG); +g->gcpause=200; +g->gcstepmul=200; +g->gcdept=0; +for(i=0;i<(8+1);i++)g->mt[i]=NULL; +if(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){ +close_state(L); +L=NULL; +} +else +{} +return L; +} +static void callallgcTM(lua_State*L,void*ud){ +UNUSED(ud); +luaC_callGCTM(L); +} +static void lua_close(lua_State*L){ +L=G(L)->mainthread; +luaF_close(L,L->stack); +luaC_separateudata(L,1); +L->errfunc=0; +do{ +L->ci=L->base_ci; +L->base=L->top=L->ci->base; +L->nCcalls=L->baseCcalls=0; +}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0); +close_state(L); +} +#define getcode(fs,e)((fs)->f->code[(e)->u.s.info]) +#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1)) +#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1)) +static int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx); +static int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C); +static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults); +static void luaK_patchtohere(FuncState*fs,int list); +static void luaK_concat(FuncState*fs,int*l1,int l2); +static int currentpc(lua_State*L,CallInfo*ci){ +if(!isLua(ci))return-1; +if(ci==L->ci) +ci->savedpc=L->savedpc; +return pcRel(ci->savedpc,ci_func(ci)->l.p); +} +static int currentline(lua_State*L,CallInfo*ci){ +int pc=currentpc(L,ci); +if(pc<0) +return-1; +else +return getline_(ci_func(ci)->l.p,pc); +} +static int lua_getstack(lua_State*L,int level,lua_Debug*ar){ +int status; +CallInfo*ci; +for(ci=L->ci;level>0&&ci>L->base_ci;ci--){ +level--; +if(f_isLua(ci)) +level-=ci->tailcalls; +} +if(level==0&&ci>L->base_ci){ +status=1; +ar->i_ci=cast_int(ci-L->base_ci); +} +else if(level<0){ +status=1; +ar->i_ci=0; +} +else status=0; +return status; +} +static Proto*getluaproto(CallInfo*ci){ +return(isLua(ci)?ci_func(ci)->l.p:NULL); +} +static void funcinfo(lua_Debug*ar,Closure*cl){ +if(cl->c.isC){ +ar->source="=[C]"; +ar->linedefined=-1; +ar->lastlinedefined=-1; +ar->what="C"; +} +else{ +ar->source=getstr(cl->l.p->source); +ar->linedefined=cl->l.p->linedefined; +ar->lastlinedefined=cl->l.p->lastlinedefined; +ar->what=(ar->linedefined==0)?"main":"Lua"; +} +luaO_chunkid(ar->short_src,ar->source,60); +} +static void info_tailcall(lua_Debug*ar){ +ar->name=ar->namewhat=""; +ar->what="tail"; +ar->lastlinedefined=ar->linedefined=ar->currentline=-1; +ar->source="=(tail call)"; +luaO_chunkid(ar->short_src,ar->source,60); +ar->nups=0; +} +static void collectvalidlines(lua_State*L,Closure*f){ +if(f==NULL||f->c.isC){ +setnilvalue(L->top); +} +else{ +Table*t=luaH_new(L,0,0); +int*lineinfo=f->l.p->lineinfo; +int i; +for(i=0;il.p->sizelineinfo;i++) +setbvalue(luaH_setnum(L,t,lineinfo[i]),1); +sethvalue(L,L->top,t); +} +incr_top(L); +} +static int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar, +Closure*f,CallInfo*ci){ +int status=1; +if(f==NULL){ +info_tailcall(ar); +return status; +} +for(;*what;what++){ +switch(*what){ +case'S':{ +funcinfo(ar,f); +break; +} +case'l':{ +ar->currentline=(ci)?currentline(L,ci):-1; +break; +} +case'u':{ +ar->nups=f->c.nupvalues; +break; +} +case'n':{ +ar->namewhat=(ci)?NULL:NULL; +if(ar->namewhat==NULL){ +ar->namewhat=""; +ar->name=NULL; +} +break; +} +case'L': +case'f': +break; +default:status=0; +} +} +return status; +} +static int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){ +int status; +Closure*f=NULL; +CallInfo*ci=NULL; +if(*what=='>'){ +StkId func=L->top-1; +luai_apicheck(L,ttisfunction(func)); +what++; +f=clvalue(func); +L->top--; +} +else if(ar->i_ci!=0){ +ci=L->base_ci+ar->i_ci; +f=clvalue(ci->func); +} +status=auxgetinfo(L,what,ar,f,ci); +if(strchr(what,'f')){ +if(f==NULL)setnilvalue(L->top); +else setclvalue(L,L->top,f); +incr_top(L); +} +if(strchr(what,'L')) +collectvalidlines(L,f); +return status; +} +static int isinstack(CallInfo*ci,const TValue*o){ +StkId p; +for(p=ci->base;ptop;p++) +if(o==p)return 1; +return 0; +} +static void luaG_typeerror(lua_State*L,const TValue*o,const char*op){ +const char*name=NULL; +const char*t=luaT_typenames[ttype(o)]; +const char*kind=(isinstack(L->ci,o))? +NULL: +NULL; +if(kind) +luaG_runerror(L,"attempt to %s %s "LUA_QL("%s")" (a %s value)", +op,kind,name,t); +else +luaG_runerror(L,"attempt to %s a %s value",op,t); +} +static void luaG_concaterror(lua_State*L,StkId p1,StkId p2){ +if(ttisstring(p1)||ttisnumber(p1))p1=p2; +luaG_typeerror(L,p1,"concatenate"); +} +static void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){ +TValue temp; +if(luaV_tonumber(p1,&temp)==NULL) +p2=p1; +luaG_typeerror(L,p2,"perform arithmetic on"); +} +static int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){ +const char*t1=luaT_typenames[ttype(p1)]; +const char*t2=luaT_typenames[ttype(p2)]; +if(t1[2]==t2[2]) +luaG_runerror(L,"attempt to compare two %s values",t1); +else +luaG_runerror(L,"attempt to compare %s with %s",t1,t2); +return 0; +} +static void addinfo(lua_State*L,const char*msg){ +CallInfo*ci=L->ci; +if(isLua(ci)){ +char buff[60]; +int line=currentline(L,ci); +luaO_chunkid(buff,getstr(getluaproto(ci)->source),60); +luaO_pushfstring(L,"%s:%d: %s",buff,line,msg); +} +} +static void luaG_errormsg(lua_State*L){ +if(L->errfunc!=0){ +StkId errfunc=restorestack(L,L->errfunc); +if(!ttisfunction(errfunc))luaD_throw(L,5); +setobj(L,L->top,L->top-1); +setobj(L,L->top-1,errfunc); +incr_top(L); +luaD_call(L,L->top-2,1); +} +luaD_throw(L,2); +} +static void luaG_runerror(lua_State*L,const char*fmt,...){ +va_list argp; +va_start(argp,fmt); +addinfo(L,luaO_pushvfstring(L,fmt,argp)); +va_end(argp); +luaG_errormsg(L); +} +static int luaZ_fill(ZIO*z){ +size_t size; +lua_State*L=z->L; +const char*buff; +buff=z->reader(L,z->data,&size); +if(buff==NULL||size==0)return(-1); +z->n=size-1; +z->p=buff; +return char2int(*(z->p++)); +} +static void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){ +z->L=L; +z->reader=reader; +z->data=data; +z->n=0; +z->p=NULL; +} +static char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){ +if(n>buff->buffsize){ +if(n<32)n=32; +luaZ_resizebuffer(L,buff,n); +} +return buff->buffer; +} +#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m)) +static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={ +opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgK,OpArgN,iABx) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgU,OpArgN,iABC) +,opmode(0,1,OpArgK,OpArgN,iABx) +,opmode(0,1,OpArgR,OpArgK,iABC) +,opmode(0,0,OpArgK,OpArgN,iABx) +,opmode(0,0,OpArgU,OpArgN,iABC) +,opmode(0,0,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgR,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgK,OpArgK,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgR,iABC) +,opmode(0,0,OpArgR,OpArgN,iAsBx) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,0,OpArgK,OpArgK,iABC) +,opmode(1,1,OpArgR,OpArgU,iABC) +,opmode(1,1,OpArgR,OpArgU,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,1,OpArgU,OpArgU,iABC) +,opmode(0,0,OpArgU,OpArgN,iABC) +,opmode(0,1,OpArgR,OpArgN,iAsBx) +,opmode(0,1,OpArgR,OpArgN,iAsBx) +,opmode(1,0,OpArgN,OpArgU,iABC) +,opmode(0,0,OpArgU,OpArgU,iABC) +,opmode(0,0,OpArgN,OpArgN,iABC) +,opmode(0,1,OpArgU,OpArgN,iABx) +,opmode(0,1,OpArgU,OpArgN,iABC) +}; +#define next(ls)(ls->current=zgetc(ls->z)) +#define currIsNewline(ls)(ls->current=='\n'||ls->current=='\r') +static const char*const luaX_tokens[]={ +"and","break","do","else","elseif", +"end","false","for","function","if", +"in","local","nil","not","or","repeat", +"return","then","true","until","while", +"..","...","==",">=","<=","~=", +"","","","", +NULL +}; +#define save_and_next(ls)(save(ls,ls->current),next(ls)) +static void save(LexState*ls,int c){ +Mbuffer*b=ls->buff; +if(b->n+1>b->buffsize){ +size_t newsize; +if(b->buffsize>=((size_t)(~(size_t)0)-2)/2) +luaX_lexerror(ls,"lexical element too long",0); +newsize=b->buffsize*2; +luaZ_resizebuffer(ls->L,b,newsize); +} +b->buffer[b->n++]=cast(char,c); +} +static void luaX_init(lua_State*L){ +int i; +for(i=0;i<(cast(int,TK_WHILE-257+1));i++){ +TString*ts=luaS_new(L,luaX_tokens[i]); +luaS_fix(ts); +ts->tsv.reserved=cast_byte(i+1); +} +} +static const char*luaX_token2str(LexState*ls,int token){ +if(token<257){ +return(iscntrl(token))?luaO_pushfstring(ls->L,"char(%d)",token): +luaO_pushfstring(ls->L,"%c",token); +} +else +return luaX_tokens[token-257]; +} +static const char*txtToken(LexState*ls,int token){ +switch(token){ +case TK_NAME: +case TK_STRING: +case TK_NUMBER: +save(ls,'\0'); +return luaZ_buffer(ls->buff); +default: +return luaX_token2str(ls,token); +} +} +static void luaX_lexerror(LexState*ls,const char*msg,int token){ +char buff[80]; +luaO_chunkid(buff,getstr(ls->source),80); +msg=luaO_pushfstring(ls->L,"%s:%d: %s",buff,ls->linenumber,msg); +if(token) +luaO_pushfstring(ls->L,"%s near "LUA_QL("%s"),msg,txtToken(ls,token)); +luaD_throw(ls->L,3); +} +static void luaX_syntaxerror(LexState*ls,const char*msg){ +luaX_lexerror(ls,msg,ls->t.token); +} +static TString*luaX_newstring(LexState*ls,const char*str,size_t l){ +lua_State*L=ls->L; +TString*ts=luaS_newlstr(L,str,l); +TValue*o=luaH_setstr(L,ls->fs->h,ts); +if(ttisnil(o)){ +setbvalue(o,1); +luaC_checkGC(L); +} +return ts; +} +static void inclinenumber(LexState*ls){ +int old=ls->current; +next(ls); +if(currIsNewline(ls)&&ls->current!=old) +next(ls); +if(++ls->linenumber>=(INT_MAX-2)) +luaX_syntaxerror(ls,"chunk has too many lines"); +} +static void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){ +ls->decpoint='.'; +ls->L=L; +ls->lookahead.token=TK_EOS; +ls->z=z; +ls->fs=NULL; +ls->linenumber=1; +ls->lastline=1; +ls->source=source; +luaZ_resizebuffer(ls->L,ls->buff,32); +next(ls); +} +static int check_next(LexState*ls,const char*set){ +if(!strchr(set,ls->current)) +return 0; +save_and_next(ls); +return 1; +} +static void buffreplace(LexState*ls,char from,char to){ +size_t n=luaZ_bufflen(ls->buff); +char*p=luaZ_buffer(ls->buff); +while(n--) +if(p[n]==from)p[n]=to; +} +static void read_numeral(LexState*ls,SemInfo*seminfo){ +do{ +save_and_next(ls); +}while(isdigit(ls->current)||ls->current=='.'); +if(check_next(ls,"Ee")) +check_next(ls,"+-"); +while(isalnum(ls->current)||ls->current=='_') +save_and_next(ls); +save(ls,'\0'); +buffreplace(ls,'.',ls->decpoint); +if(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r)) +luaX_lexerror(ls,"malformed number",TK_NUMBER); +} +static int skip_sep(LexState*ls){ +int count=0; +int s=ls->current; +save_and_next(ls); +while(ls->current=='='){ +save_and_next(ls); +count++; +} +return(ls->current==s)?count:(-count)-1; +} +static void read_long_string(LexState*ls,SemInfo*seminfo,int sep){ +int cont=0; +(void)(cont); +save_and_next(ls); +if(currIsNewline(ls)) +inclinenumber(ls); +for(;;){ +switch(ls->current){ +case(-1): +luaX_lexerror(ls,(seminfo)?"unfinished long string": +"unfinished long comment",TK_EOS); +break; +case']':{ +if(skip_sep(ls)==sep){ +save_and_next(ls); +goto endloop; +} +break; +} +case'\n': +case'\r':{ +save(ls,'\n'); +inclinenumber(ls); +if(!seminfo)luaZ_resetbuffer(ls->buff); +break; +} +default:{ +if(seminfo)save_and_next(ls); +else next(ls); +} +} +}endloop: +if(seminfo) +seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep), +luaZ_bufflen(ls->buff)-2*(2+sep)); +} +static void read_string(LexState*ls,int del,SemInfo*seminfo){ +save_and_next(ls); +while(ls->current!=del){ +switch(ls->current){ +case(-1): +luaX_lexerror(ls,"unfinished string",TK_EOS); +continue; +case'\n': +case'\r': +luaX_lexerror(ls,"unfinished string",TK_STRING); +continue; +case'\\':{ +int c; +next(ls); +switch(ls->current){ +case'a':c='\a';break; +case'b':c='\b';break; +case'f':c='\f';break; +case'n':c='\n';break; +case'r':c='\r';break; +case't':c='\t';break; +case'v':c='\v';break; +case'\n': +case'\r':save(ls,'\n');inclinenumber(ls);continue; +case(-1):continue; +default:{ +if(!isdigit(ls->current)) +save_and_next(ls); +else{ +int i=0; +c=0; +do{ +c=10*c+(ls->current-'0'); +next(ls); +}while(++i<3&&isdigit(ls->current)); +if(c>UCHAR_MAX) +luaX_lexerror(ls,"escape sequence too large",TK_STRING); +save(ls,c); +} +continue; +} +} +save(ls,c); +next(ls); +continue; +} +default: +save_and_next(ls); +} +} +save_and_next(ls); +seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1, +luaZ_bufflen(ls->buff)-2); +} +static int llex(LexState*ls,SemInfo*seminfo){ +luaZ_resetbuffer(ls->buff); +for(;;){ +switch(ls->current){ +case'\n': +case'\r':{ +inclinenumber(ls); +continue; +} +case'-':{ +next(ls); +if(ls->current!='-')return'-'; +next(ls); +if(ls->current=='['){ +int sep=skip_sep(ls); +luaZ_resetbuffer(ls->buff); +if(sep>=0){ +read_long_string(ls,NULL,sep); +luaZ_resetbuffer(ls->buff); +continue; +} +} +while(!currIsNewline(ls)&&ls->current!=(-1)) +next(ls); +continue; +} +case'[':{ +int sep=skip_sep(ls); +if(sep>=0){ +read_long_string(ls,seminfo,sep); +return TK_STRING; +} +else if(sep==-1)return'['; +else luaX_lexerror(ls,"invalid long string delimiter",TK_STRING); +} +case'=':{ +next(ls); +if(ls->current!='=')return'='; +else{next(ls);return TK_EQ;} +} +case'<':{ +next(ls); +if(ls->current!='=')return'<'; +else{next(ls);return TK_LE;} +} +case'>':{ +next(ls); +if(ls->current!='=')return'>'; +else{next(ls);return TK_GE;} +} +case'~':{ +next(ls); +if(ls->current!='=')return'~'; +else{next(ls);return TK_NE;} +} +case'"': +case'\'':{ +read_string(ls,ls->current,seminfo); +return TK_STRING; +} +case'.':{ +save_and_next(ls); +if(check_next(ls,".")){ +if(check_next(ls,".")) +return TK_DOTS; +else return TK_CONCAT; +} +else if(!isdigit(ls->current))return'.'; +else{ +read_numeral(ls,seminfo); +return TK_NUMBER; +} +} +case(-1):{ +return TK_EOS; +} +default:{ +if(isspace(ls->current)){ +next(ls); +continue; +} +else if(isdigit(ls->current)){ +read_numeral(ls,seminfo); +return TK_NUMBER; +} +else if(isalpha(ls->current)||ls->current=='_'){ +TString*ts; +do{ +save_and_next(ls); +}while(isalnum(ls->current)||ls->current=='_'); +ts=luaX_newstring(ls,luaZ_buffer(ls->buff), +luaZ_bufflen(ls->buff)); +if(ts->tsv.reserved>0) +return ts->tsv.reserved-1+257; +else{ +seminfo->ts=ts; +return TK_NAME; +} +} +else{ +int c=ls->current; +next(ls); +return c; +} +} +} +} +} +static void luaX_next(LexState*ls){ +ls->lastline=ls->linenumber; +if(ls->lookahead.token!=TK_EOS){ +ls->t=ls->lookahead; +ls->lookahead.token=TK_EOS; +} +else +ls->t.token=llex(ls,&ls->t.seminfo); +} +static void luaX_lookahead(LexState*ls){ +ls->lookahead.token=llex(ls,&ls->lookahead.seminfo); +} +#define hasjumps(e)((e)->t!=(e)->f) +static int isnumeral(expdesc*e){ +return(e->k==VKNUM&&e->t==(-1)&&e->f==(-1)); +} +static void luaK_nil(FuncState*fs,int from,int n){ +Instruction*previous; +if(fs->pc>fs->lasttarget){ +if(fs->pc==0){ +if(from>=fs->nactvar) +return; +} +else{ +previous=&fs->f->code[fs->pc-1]; +if(GET_OPCODE(*previous)==OP_LOADNIL){ +int pfrom=GETARG_A(*previous); +int pto=GETARG_B(*previous); +if(pfrom<=from&&from<=pto+1){ +if(from+n-1>pto) +SETARG_B(*previous,from+n-1); +return; +} +} +} +} +luaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0); +} +static int luaK_jump(FuncState*fs){ +int jpc=fs->jpc; +int j; +fs->jpc=(-1); +j=luaK_codeAsBx(fs,OP_JMP,0,(-1)); +luaK_concat(fs,&j,jpc); +return j; +} +static void luaK_ret(FuncState*fs,int first,int nret){ +luaK_codeABC(fs,OP_RETURN,first,nret+1,0); +} +static int condjump(FuncState*fs,OpCode op,int A,int B,int C){ +luaK_codeABC(fs,op,A,B,C); +return luaK_jump(fs); +} +static void fixjump(FuncState*fs,int pc,int dest){ +Instruction*jmp=&fs->f->code[pc]; +int offset=dest-(pc+1); +if(abs(offset)>(((1<<(9+9))-1)>>1)) +luaX_syntaxerror(fs->ls,"control structure too long"); +SETARG_sBx(*jmp,offset); +} +static int luaK_getlabel(FuncState*fs){ +fs->lasttarget=fs->pc; +return fs->pc; +} +static int getjump(FuncState*fs,int pc){ +int offset=GETARG_sBx(fs->f->code[pc]); +if(offset==(-1)) +return(-1); +else +return(pc+1)+offset; +} +static Instruction*getjumpcontrol(FuncState*fs,int pc){ +Instruction*pi=&fs->f->code[pc]; +if(pc>=1&&testTMode(GET_OPCODE(*(pi-1)))) +return pi-1; +else +return pi; +} +static int need_value(FuncState*fs,int list){ +for(;list!=(-1);list=getjump(fs,list)){ +Instruction i=*getjumpcontrol(fs,list); +if(GET_OPCODE(i)!=OP_TESTSET)return 1; +} +return 0; +} +static int patchtestreg(FuncState*fs,int node,int reg){ +Instruction*i=getjumpcontrol(fs,node); +if(GET_OPCODE(*i)!=OP_TESTSET) +return 0; +if(reg!=((1<<8)-1)&®!=GETARG_B(*i)) +SETARG_A(*i,reg); +else +*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i)); +return 1; +} +static void removevalues(FuncState*fs,int list){ +for(;list!=(-1);list=getjump(fs,list)) +patchtestreg(fs,list,((1<<8)-1)); +} +static void patchlistaux(FuncState*fs,int list,int vtarget,int reg, +int dtarget){ +while(list!=(-1)){ +int next=getjump(fs,list); +if(patchtestreg(fs,list,reg)) +fixjump(fs,list,vtarget); +else +fixjump(fs,list,dtarget); +list=next; +} +} +static void dischargejpc(FuncState*fs){ +patchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc); +fs->jpc=(-1); +} +static void luaK_patchlist(FuncState*fs,int list,int target){ +if(target==fs->pc) +luaK_patchtohere(fs,list); +else{ +patchlistaux(fs,list,target,((1<<8)-1),target); +} +} +static void luaK_patchtohere(FuncState*fs,int list){ +luaK_getlabel(fs); +luaK_concat(fs,&fs->jpc,list); +} +static void luaK_concat(FuncState*fs,int*l1,int l2){ +if(l2==(-1))return; +else if(*l1==(-1)) +*l1=l2; +else{ +int list=*l1; +int next; +while((next=getjump(fs,list))!=(-1)) +list=next; +fixjump(fs,list,l2); +} +} +static void luaK_checkstack(FuncState*fs,int n){ +int newstack=fs->freereg+n; +if(newstack>fs->f->maxstacksize){ +if(newstack>=250) +luaX_syntaxerror(fs->ls,"function or expression too complex"); +fs->f->maxstacksize=cast_byte(newstack); +} +} +static void luaK_reserveregs(FuncState*fs,int n){ +luaK_checkstack(fs,n); +fs->freereg+=n; +} +static void freereg(FuncState*fs,int reg){ +if(!ISK(reg)&®>=fs->nactvar){ +fs->freereg--; +} +} +static void freeexp(FuncState*fs,expdesc*e){ +if(e->k==VNONRELOC) +freereg(fs,e->u.s.info); +} +static int addk(FuncState*fs,TValue*k,TValue*v){ +lua_State*L=fs->L; +TValue*idx=luaH_set(L,fs->h,k); +Proto*f=fs->f; +int oldsize=f->sizek; +if(ttisnumber(idx)){ +return cast_int(nvalue(idx)); +} +else{ +setnvalue(idx,cast_num(fs->nk)); +luaM_growvector(L,f->k,fs->nk,f->sizek,TValue, +((1<<(9+9))-1),"constant table overflow"); +while(oldsizesizek)setnilvalue(&f->k[oldsize++]); +setobj(L,&f->k[fs->nk],v); +luaC_barrier(L,f,v); +return fs->nk++; +} +} +static int luaK_stringK(FuncState*fs,TString*s){ +TValue o; +setsvalue(fs->L,&o,s); +return addk(fs,&o,&o); +} +static int luaK_numberK(FuncState*fs,lua_Number r){ +TValue o; +setnvalue(&o,r); +return addk(fs,&o,&o); +} +static int boolK(FuncState*fs,int b){ +TValue o; +setbvalue(&o,b); +return addk(fs,&o,&o); +} +static int nilK(FuncState*fs){ +TValue k,v; +setnilvalue(&v); +sethvalue(fs->L,&k,fs->h); +return addk(fs,&k,&v); +} +static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){ +if(e->k==VCALL){ +SETARG_C(getcode(fs,e),nresults+1); +} +else if(e->k==VVARARG){ +SETARG_B(getcode(fs,e),nresults+1); +SETARG_A(getcode(fs,e),fs->freereg); +luaK_reserveregs(fs,1); +} +} +static void luaK_setoneret(FuncState*fs,expdesc*e){ +if(e->k==VCALL){ +e->k=VNONRELOC; +e->u.s.info=GETARG_A(getcode(fs,e)); +} +else if(e->k==VVARARG){ +SETARG_B(getcode(fs,e),2); +e->k=VRELOCABLE; +} +} +static void luaK_dischargevars(FuncState*fs,expdesc*e){ +switch(e->k){ +case VLOCAL:{ +e->k=VNONRELOC; +break; +} +case VUPVAL:{ +e->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0); +e->k=VRELOCABLE; +break; +} +case VGLOBAL:{ +e->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info); +e->k=VRELOCABLE; +break; +} +case VINDEXED:{ +freereg(fs,e->u.s.aux); +freereg(fs,e->u.s.info); +e->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux); +e->k=VRELOCABLE; +break; +} +case VVARARG: +case VCALL:{ +luaK_setoneret(fs,e); +break; +} +default:break; +} +} +static int code_label(FuncState*fs,int A,int b,int jump){ +luaK_getlabel(fs); +return luaK_codeABC(fs,OP_LOADBOOL,A,b,jump); +} +static void discharge2reg(FuncState*fs,expdesc*e,int reg){ +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:{ +luaK_nil(fs,reg,1); +break; +} +case VFALSE:case VTRUE:{ +luaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0); +break; +} +case VK:{ +luaK_codeABx(fs,OP_LOADK,reg,e->u.s.info); +break; +} +case VKNUM:{ +luaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval)); +break; +} +case VRELOCABLE:{ +Instruction*pc=&getcode(fs,e); +SETARG_A(*pc,reg); +break; +} +case VNONRELOC:{ +if(reg!=e->u.s.info) +luaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0); +break; +} +default:{ +return; +} +} +e->u.s.info=reg; +e->k=VNONRELOC; +} +static void discharge2anyreg(FuncState*fs,expdesc*e){ +if(e->k!=VNONRELOC){ +luaK_reserveregs(fs,1); +discharge2reg(fs,e,fs->freereg-1); +} +} +static void exp2reg(FuncState*fs,expdesc*e,int reg){ +discharge2reg(fs,e,reg); +if(e->k==VJMP) +luaK_concat(fs,&e->t,e->u.s.info); +if(hasjumps(e)){ +int final; +int p_f=(-1); +int p_t=(-1); +if(need_value(fs,e->t)||need_value(fs,e->f)){ +int fj=(e->k==VJMP)?(-1):luaK_jump(fs); +p_f=code_label(fs,reg,0,1); +p_t=code_label(fs,reg,1,0); +luaK_patchtohere(fs,fj); +} +final=luaK_getlabel(fs); +patchlistaux(fs,e->f,final,reg,p_f); +patchlistaux(fs,e->t,final,reg,p_t); +} +e->f=e->t=(-1); +e->u.s.info=reg; +e->k=VNONRELOC; +} +static void luaK_exp2nextreg(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +freeexp(fs,e); +luaK_reserveregs(fs,1); +exp2reg(fs,e,fs->freereg-1); +} +static int luaK_exp2anyreg(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +if(e->k==VNONRELOC){ +if(!hasjumps(e))return e->u.s.info; +if(e->u.s.info>=fs->nactvar){ +exp2reg(fs,e,e->u.s.info); +return e->u.s.info; +} +} +luaK_exp2nextreg(fs,e); +return e->u.s.info; +} +static void luaK_exp2val(FuncState*fs,expdesc*e){ +if(hasjumps(e)) +luaK_exp2anyreg(fs,e); +else +luaK_dischargevars(fs,e); +} +static int luaK_exp2RK(FuncState*fs,expdesc*e){ +luaK_exp2val(fs,e); +switch(e->k){ +case VKNUM: +case VTRUE: +case VFALSE: +case VNIL:{ +if(fs->nk<=((1<<(9-1))-1)){ +e->u.s.info=(e->k==VNIL)?nilK(fs): +(e->k==VKNUM)?luaK_numberK(fs,e->u.nval): +boolK(fs,(e->k==VTRUE)); +e->k=VK; +return RKASK(e->u.s.info); +} +else break; +} +case VK:{ +if(e->u.s.info<=((1<<(9-1))-1)) +return RKASK(e->u.s.info); +else break; +} +default:break; +} +return luaK_exp2anyreg(fs,e); +} +static void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){ +switch(var->k){ +case VLOCAL:{ +freeexp(fs,ex); +exp2reg(fs,ex,var->u.s.info); +return; +} +case VUPVAL:{ +int e=luaK_exp2anyreg(fs,ex); +luaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0); +break; +} +case VGLOBAL:{ +int e=luaK_exp2anyreg(fs,ex); +luaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info); +break; +} +case VINDEXED:{ +int e=luaK_exp2RK(fs,ex); +luaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e); +break; +} +default:{ +break; +} +} +freeexp(fs,ex); +} +static void luaK_self(FuncState*fs,expdesc*e,expdesc*key){ +int func; +luaK_exp2anyreg(fs,e); +freeexp(fs,e); +func=fs->freereg; +luaK_reserveregs(fs,2); +luaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key)); +freeexp(fs,key); +e->u.s.info=func; +e->k=VNONRELOC; +} +static void invertjump(FuncState*fs,expdesc*e){ +Instruction*pc=getjumpcontrol(fs,e->u.s.info); +SETARG_A(*pc,!(GETARG_A(*pc))); +} +static int jumponcond(FuncState*fs,expdesc*e,int cond){ +if(e->k==VRELOCABLE){ +Instruction ie=getcode(fs,e); +if(GET_OPCODE(ie)==OP_NOT){ +fs->pc--; +return condjump(fs,OP_TEST,GETARG_B(ie),0,!cond); +} +} +discharge2anyreg(fs,e); +freeexp(fs,e); +return condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond); +} +static void luaK_goiftrue(FuncState*fs,expdesc*e){ +int pc; +luaK_dischargevars(fs,e); +switch(e->k){ +case VK:case VKNUM:case VTRUE:{ +pc=(-1); +break; +} +case VJMP:{ +invertjump(fs,e); +pc=e->u.s.info; +break; +} +default:{ +pc=jumponcond(fs,e,0); +break; +} +} +luaK_concat(fs,&e->f,pc); +luaK_patchtohere(fs,e->t); +e->t=(-1); +} +static void luaK_goiffalse(FuncState*fs,expdesc*e){ +int pc; +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:case VFALSE:{ +pc=(-1); +break; +} +case VJMP:{ +pc=e->u.s.info; +break; +} +default:{ +pc=jumponcond(fs,e,1); +break; +} +} +luaK_concat(fs,&e->t,pc); +luaK_patchtohere(fs,e->f); +e->f=(-1); +} +static void codenot(FuncState*fs,expdesc*e){ +luaK_dischargevars(fs,e); +switch(e->k){ +case VNIL:case VFALSE:{ +e->k=VTRUE; +break; +} +case VK:case VKNUM:case VTRUE:{ +e->k=VFALSE; +break; +} +case VJMP:{ +invertjump(fs,e); +break; +} +case VRELOCABLE: +case VNONRELOC:{ +discharge2anyreg(fs,e); +freeexp(fs,e); +e->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0); +e->k=VRELOCABLE; +break; +} +default:{ +break; +} +} +{int temp=e->f;e->f=e->t;e->t=temp;} +removevalues(fs,e->f); +removevalues(fs,e->t); +} +static void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){ +t->u.s.aux=luaK_exp2RK(fs,k); +t->k=VINDEXED; +} +static int constfolding(OpCode op,expdesc*e1,expdesc*e2){ +lua_Number v1,v2,r; +if(!isnumeral(e1)||!isnumeral(e2))return 0; +v1=e1->u.nval; +v2=e2->u.nval; +switch(op){ +case OP_ADD:r=luai_numadd(v1,v2);break; +case OP_SUB:r=luai_numsub(v1,v2);break; +case OP_MUL:r=luai_nummul(v1,v2);break; +case OP_DIV: +if(v2==0)return 0; +r=luai_numdiv(v1,v2);break; +case OP_MOD: +if(v2==0)return 0; +r=luai_nummod(v1,v2);break; +case OP_POW:r=luai_numpow(v1,v2);break; +case OP_UNM:r=luai_numunm(v1);break; +case OP_LEN:return 0; +default:r=0;break; +} +if(luai_numisnan(r))return 0; +e1->u.nval=r; +return 1; +} +static void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){ +if(constfolding(op,e1,e2)) +return; +else{ +int o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0; +int o1=luaK_exp2RK(fs,e1); +if(o1>o2){ +freeexp(fs,e1); +freeexp(fs,e2); +} +else{ +freeexp(fs,e2); +freeexp(fs,e1); +} +e1->u.s.info=luaK_codeABC(fs,op,0,o1,o2); +e1->k=VRELOCABLE; +} +} +static void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1, +expdesc*e2){ +int o1=luaK_exp2RK(fs,e1); +int o2=luaK_exp2RK(fs,e2); +freeexp(fs,e2); +freeexp(fs,e1); +if(cond==0&&op!=OP_EQ){ +int temp; +temp=o1;o1=o2;o2=temp; +cond=1; +} +e1->u.s.info=condjump(fs,op,cond,o1,o2); +e1->k=VJMP; +} +static void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){ +expdesc e2; +e2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0; +switch(op){ +case OPR_MINUS:{ +if(!isnumeral(e)) +luaK_exp2anyreg(fs,e); +codearith(fs,OP_UNM,e,&e2); +break; +} +case OPR_NOT:codenot(fs,e);break; +case OPR_LEN:{ +luaK_exp2anyreg(fs,e); +codearith(fs,OP_LEN,e,&e2); +break; +} +default:; +} +} +static void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){ +switch(op){ +case OPR_AND:{ +luaK_goiftrue(fs,v); +break; +} +case OPR_OR:{ +luaK_goiffalse(fs,v); +break; +} +case OPR_CONCAT:{ +luaK_exp2nextreg(fs,v); +break; +} +case OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV: +case OPR_MOD:case OPR_POW:{ +if(!isnumeral(v))luaK_exp2RK(fs,v); +break; +} +default:{ +luaK_exp2RK(fs,v); +break; +} +} +} +static void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){ +switch(op){ +case OPR_AND:{ +luaK_dischargevars(fs,e2); +luaK_concat(fs,&e2->f,e1->f); +*e1=*e2; +break; +} +case OPR_OR:{ +luaK_dischargevars(fs,e2); +luaK_concat(fs,&e2->t,e1->t); +*e1=*e2; +break; +} +case OPR_CONCAT:{ +luaK_exp2val(fs,e2); +if(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){ +freeexp(fs,e1); +SETARG_B(getcode(fs,e2),e1->u.s.info); +e1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info; +} +else{ +luaK_exp2nextreg(fs,e2); +codearith(fs,OP_CONCAT,e1,e2); +} +break; +} +case OPR_ADD:codearith(fs,OP_ADD,e1,e2);break; +case OPR_SUB:codearith(fs,OP_SUB,e1,e2);break; +case OPR_MUL:codearith(fs,OP_MUL,e1,e2);break; +case OPR_DIV:codearith(fs,OP_DIV,e1,e2);break; +case OPR_MOD:codearith(fs,OP_MOD,e1,e2);break; +case OPR_POW:codearith(fs,OP_POW,e1,e2);break; +case OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break; +case OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break; +case OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break; +case OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break; +case OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break; +case OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break; +default:; +} +} +static void luaK_fixline(FuncState*fs,int line){ +fs->f->lineinfo[fs->pc-1]=line; +} +static int luaK_code(FuncState*fs,Instruction i,int line){ +Proto*f=fs->f; +dischargejpc(fs); +luaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction, +(INT_MAX-2),"code size overflow"); +f->code[fs->pc]=i; +luaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int, +(INT_MAX-2),"code size overflow"); +f->lineinfo[fs->pc]=line; +return fs->pc++; +} +static int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){ +return luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline); +} +static int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){ +return luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline); +} +static void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){ +int c=(nelems-1)/50+1; +int b=(tostore==(-1))?0:tostore; +if(c<=((1<<9)-1)) +luaK_codeABC(fs,OP_SETLIST,base,b,c); +else{ +luaK_codeABC(fs,OP_SETLIST,base,b,0); +luaK_code(fs,cast(Instruction,c),fs->ls->lastline); +} +fs->freereg=base+1; +} +#define hasmultret(k)((k)==VCALL||(k)==VVARARG) +#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]]) +#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m) +typedef struct BlockCnt{ +struct BlockCnt*previous; +int breaklist; +lu_byte nactvar; +lu_byte upval; +lu_byte isbreakable; +}BlockCnt; +static void chunk(LexState*ls); +static void expr(LexState*ls,expdesc*v); +static void anchor_token(LexState*ls){ +if(ls->t.token==TK_NAME||ls->t.token==TK_STRING){ +TString*ts=ls->t.seminfo.ts; +luaX_newstring(ls,getstr(ts),ts->tsv.len); +} +} +static void error_expected(LexState*ls,int token){ +luaX_syntaxerror(ls, +luaO_pushfstring(ls->L,LUA_QL("%s")" expected",luaX_token2str(ls,token))); +} +static void errorlimit(FuncState*fs,int limit,const char*what){ +const char*msg=(fs->f->linedefined==0)? +luaO_pushfstring(fs->L,"main function has more than %d %s",limit,what): +luaO_pushfstring(fs->L,"function at line %d has more than %d %s", +fs->f->linedefined,limit,what); +luaX_lexerror(fs->ls,msg,0); +} +static int testnext(LexState*ls,int c){ +if(ls->t.token==c){ +luaX_next(ls); +return 1; +} +else return 0; +} +static void check(LexState*ls,int c){ +if(ls->t.token!=c) +error_expected(ls,c); +} +static void checknext(LexState*ls,int c){ +check(ls,c); +luaX_next(ls); +} +#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);} +static void check_match(LexState*ls,int what,int who,int where){ +if(!testnext(ls,what)){ +if(where==ls->linenumber) +error_expected(ls,what); +else{ +luaX_syntaxerror(ls,luaO_pushfstring(ls->L, +LUA_QL("%s")" expected (to close "LUA_QL("%s")" at line %d)", +luaX_token2str(ls,what),luaX_token2str(ls,who),where)); +} +} +} +static TString*str_checkname(LexState*ls){ +TString*ts; +check(ls,TK_NAME); +ts=ls->t.seminfo.ts; +luaX_next(ls); +return ts; +} +static void init_exp(expdesc*e,expkind k,int i){ +e->f=e->t=(-1); +e->k=k; +e->u.s.info=i; +} +static void codestring(LexState*ls,expdesc*e,TString*s){ +init_exp(e,VK,luaK_stringK(ls->fs,s)); +} +static void checkname(LexState*ls,expdesc*e){ +codestring(ls,e,str_checkname(ls)); +} +static int registerlocalvar(LexState*ls,TString*varname){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int oldsize=f->sizelocvars; +luaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars, +LocVar,SHRT_MAX,"too many local variables"); +while(oldsizesizelocvars)f->locvars[oldsize++].varname=NULL; +f->locvars[fs->nlocvars].varname=varname; +luaC_objbarrier(ls->L,f,varname); +return fs->nlocvars++; +} +#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,""v,(sizeof(v)/sizeof(char))-1),n) +static void new_localvar(LexState*ls,TString*name,int n){ +FuncState*fs=ls->fs; +luaY_checklimit(fs,fs->nactvar+n+1,200,"local variables"); +fs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name)); +} +static void adjustlocalvars(LexState*ls,int nvars){ +FuncState*fs=ls->fs; +fs->nactvar=cast_byte(fs->nactvar+nvars); +for(;nvars;nvars--){ +getlocvar(fs,fs->nactvar-nvars).startpc=fs->pc; +} +} +static void removevars(LexState*ls,int tolevel){ +FuncState*fs=ls->fs; +while(fs->nactvar>tolevel) +getlocvar(fs,--fs->nactvar).endpc=fs->pc; +} +static int indexupvalue(FuncState*fs,TString*name,expdesc*v){ +int i; +Proto*f=fs->f; +int oldsize=f->sizeupvalues; +for(i=0;inups;i++){ +if(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){ +return i; +} +} +luaY_checklimit(fs,f->nups+1,60,"upvalues"); +luaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues, +TString*,(INT_MAX-2),""); +while(oldsizesizeupvalues)f->upvalues[oldsize++]=NULL; +f->upvalues[f->nups]=name; +luaC_objbarrier(fs->L,f,name); +fs->upvalues[f->nups].k=cast_byte(v->k); +fs->upvalues[f->nups].info=cast_byte(v->u.s.info); +return f->nups++; +} +static int searchvar(FuncState*fs,TString*n){ +int i; +for(i=fs->nactvar-1;i>=0;i--){ +if(n==getlocvar(fs,i).varname) +return i; +} +return-1; +} +static void markupval(FuncState*fs,int level){ +BlockCnt*bl=fs->bl; +while(bl&&bl->nactvar>level)bl=bl->previous; +if(bl)bl->upval=1; +} +static int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){ +if(fs==NULL){ +init_exp(var,VGLOBAL,((1<<8)-1)); +return VGLOBAL; +} +else{ +int v=searchvar(fs,n); +if(v>=0){ +init_exp(var,VLOCAL,v); +if(!base) +markupval(fs,v); +return VLOCAL; +} +else{ +if(singlevaraux(fs->prev,n,var,0)==VGLOBAL) +return VGLOBAL; +var->u.s.info=indexupvalue(fs,n,var); +var->k=VUPVAL; +return VUPVAL; +} +} +} +static void singlevar(LexState*ls,expdesc*var){ +TString*varname=str_checkname(ls); +FuncState*fs=ls->fs; +if(singlevaraux(fs,varname,var,1)==VGLOBAL) +var->u.s.info=luaK_stringK(fs,varname); +} +static void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){ +FuncState*fs=ls->fs; +int extra=nvars-nexps; +if(hasmultret(e->k)){ +extra++; +if(extra<0)extra=0; +luaK_setreturns(fs,e,extra); +if(extra>1)luaK_reserveregs(fs,extra-1); +} +else{ +if(e->k!=VVOID)luaK_exp2nextreg(fs,e); +if(extra>0){ +int reg=fs->freereg; +luaK_reserveregs(fs,extra); +luaK_nil(fs,reg,extra); +} +} +} +static void enterlevel(LexState*ls){ +if(++ls->L->nCcalls>200) +luaX_lexerror(ls,"chunk has too many syntax levels",0); +} +#define leavelevel(ls)((ls)->L->nCcalls--) +static void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){ +bl->breaklist=(-1); +bl->isbreakable=isbreakable; +bl->nactvar=fs->nactvar; +bl->upval=0; +bl->previous=fs->bl; +fs->bl=bl; +} +static void leaveblock(FuncState*fs){ +BlockCnt*bl=fs->bl; +fs->bl=bl->previous; +removevars(fs->ls,bl->nactvar); +if(bl->upval) +luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); +fs->freereg=fs->nactvar; +luaK_patchtohere(fs,bl->breaklist); +} +static void pushclosure(LexState*ls,FuncState*func,expdesc*v){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int oldsize=f->sizep; +int i; +luaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*, +((1<<(9+9))-1),"constant table overflow"); +while(oldsizesizep)f->p[oldsize++]=NULL; +f->p[fs->np++]=func->f; +luaC_objbarrier(ls->L,f,func->f); +init_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1)); +for(i=0;if->nups;i++){ +OpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL; +luaK_codeABC(fs,o,0,func->upvalues[i].info,0); +} +} +static void open_func(LexState*ls,FuncState*fs){ +lua_State*L=ls->L; +Proto*f=luaF_newproto(L); +fs->f=f; +fs->prev=ls->fs; +fs->ls=ls; +fs->L=L; +ls->fs=fs; +fs->pc=0; +fs->lasttarget=-1; +fs->jpc=(-1); +fs->freereg=0; +fs->nk=0; +fs->np=0; +fs->nlocvars=0; +fs->nactvar=0; +fs->bl=NULL; +f->source=ls->source; +f->maxstacksize=2; +fs->h=luaH_new(L,0,0); +sethvalue(L,L->top,fs->h); +incr_top(L); +setptvalue(L,L->top,f); +incr_top(L); +} +static void close_func(LexState*ls){ +lua_State*L=ls->L; +FuncState*fs=ls->fs; +Proto*f=fs->f; +removevars(ls,0); +luaK_ret(fs,0,0); +luaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction); +f->sizecode=fs->pc; +luaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int); +f->sizelineinfo=fs->pc; +luaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue); +f->sizek=fs->nk; +luaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*); +f->sizep=fs->np; +luaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar); +f->sizelocvars=fs->nlocvars; +luaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*); +f->sizeupvalues=f->nups; +ls->fs=fs->prev; +if(fs)anchor_token(ls); +L->top-=2; +} +static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){ +struct LexState lexstate; +struct FuncState funcstate; +lexstate.buff=buff; +luaX_setinput(L,&lexstate,z,luaS_new(L,name)); +open_func(&lexstate,&funcstate); +funcstate.f->is_vararg=2; +luaX_next(&lexstate); +chunk(&lexstate); +check(&lexstate,TK_EOS); +close_func(&lexstate); +return funcstate.f; +} +static void field(LexState*ls,expdesc*v){ +FuncState*fs=ls->fs; +expdesc key; +luaK_exp2anyreg(fs,v); +luaX_next(ls); +checkname(ls,&key); +luaK_indexed(fs,v,&key); +} +static void yindex(LexState*ls,expdesc*v){ +luaX_next(ls); +expr(ls,v); +luaK_exp2val(ls->fs,v); +checknext(ls,']'); +} +struct ConsControl{ +expdesc v; +expdesc*t; +int nh; +int na; +int tostore; +}; +static void recfield(LexState*ls,struct ConsControl*cc){ +FuncState*fs=ls->fs; +int reg=ls->fs->freereg; +expdesc key,val; +int rkkey; +if(ls->t.token==TK_NAME){ +luaY_checklimit(fs,cc->nh,(INT_MAX-2),"items in a constructor"); +checkname(ls,&key); +} +else +yindex(ls,&key); +cc->nh++; +checknext(ls,'='); +rkkey=luaK_exp2RK(fs,&key); +expr(ls,&val); +luaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val)); +fs->freereg=reg; +} +static void closelistfield(FuncState*fs,struct ConsControl*cc){ +if(cc->v.k==VVOID)return; +luaK_exp2nextreg(fs,&cc->v); +cc->v.k=VVOID; +if(cc->tostore==50){ +luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); +cc->tostore=0; +} +} +static void lastlistfield(FuncState*fs,struct ConsControl*cc){ +if(cc->tostore==0)return; +if(hasmultret(cc->v.k)){ +luaK_setmultret(fs,&cc->v); +luaK_setlist(fs,cc->t->u.s.info,cc->na,(-1)); +cc->na--; +} +else{ +if(cc->v.k!=VVOID) +luaK_exp2nextreg(fs,&cc->v); +luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); +} +} +static void listfield(LexState*ls,struct ConsControl*cc){ +expr(ls,&cc->v); +luaY_checklimit(ls->fs,cc->na,(INT_MAX-2),"items in a constructor"); +cc->na++; +cc->tostore++; +} +static void constructor(LexState*ls,expdesc*t){ +FuncState*fs=ls->fs; +int line=ls->linenumber; +int pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0); +struct ConsControl cc; +cc.na=cc.nh=cc.tostore=0; +cc.t=t; +init_exp(t,VRELOCABLE,pc); +init_exp(&cc.v,VVOID,0); +luaK_exp2nextreg(ls->fs,t); +checknext(ls,'{'); +do{ +if(ls->t.token=='}')break; +closelistfield(fs,&cc); +switch(ls->t.token){ +case TK_NAME:{ +luaX_lookahead(ls); +if(ls->lookahead.token!='=') +listfield(ls,&cc); +else +recfield(ls,&cc); +break; +} +case'[':{ +recfield(ls,&cc); +break; +} +default:{ +listfield(ls,&cc); +break; +} +} +}while(testnext(ls,',')||testnext(ls,';')); +check_match(ls,'}','{',line); +lastlistfield(fs,&cc); +SETARG_B(fs->f->code[pc],luaO_int2fb(cc.na)); +SETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh)); +} +static void parlist(LexState*ls){ +FuncState*fs=ls->fs; +Proto*f=fs->f; +int nparams=0; +f->is_vararg=0; +if(ls->t.token!=')'){ +do{ +switch(ls->t.token){ +case TK_NAME:{ +new_localvar(ls,str_checkname(ls),nparams++); +break; +} +case TK_DOTS:{ +luaX_next(ls); +f->is_vararg|=2; +break; +} +default:luaX_syntaxerror(ls," or "LUA_QL("...")" expected"); +} +}while(!f->is_vararg&&testnext(ls,',')); +} +adjustlocalvars(ls,nparams); +f->numparams=cast_byte(fs->nactvar-(f->is_vararg&1)); +luaK_reserveregs(fs,fs->nactvar); +} +static void body(LexState*ls,expdesc*e,int needself,int line){ +FuncState new_fs; +open_func(ls,&new_fs); +new_fs.f->linedefined=line; +checknext(ls,'('); +if(needself){ +new_localvarliteral(ls,"self",0); +adjustlocalvars(ls,1); +} +parlist(ls); +checknext(ls,')'); +chunk(ls); +new_fs.f->lastlinedefined=ls->linenumber; +check_match(ls,TK_END,TK_FUNCTION,line); +close_func(ls); +pushclosure(ls,&new_fs,e); +} +static int explist1(LexState*ls,expdesc*v){ +int n=1; +expr(ls,v); +while(testnext(ls,',')){ +luaK_exp2nextreg(ls->fs,v); +expr(ls,v); +n++; +} +return n; +} +static void funcargs(LexState*ls,expdesc*f){ +FuncState*fs=ls->fs; +expdesc args; +int base,nparams; +int line=ls->linenumber; +switch(ls->t.token){ +case'(':{ +if(line!=ls->lastline) +luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); +luaX_next(ls); +if(ls->t.token==')') +args.k=VVOID; +else{ +explist1(ls,&args); +luaK_setmultret(fs,&args); +} +check_match(ls,')','(',line); +break; +} +case'{':{ +constructor(ls,&args); +break; +} +case TK_STRING:{ +codestring(ls,&args,ls->t.seminfo.ts); +luaX_next(ls); +break; +} +default:{ +luaX_syntaxerror(ls,"function arguments expected"); +return; +} +} +base=f->u.s.info; +if(hasmultret(args.k)) +nparams=(-1); +else{ +if(args.k!=VVOID) +luaK_exp2nextreg(fs,&args); +nparams=fs->freereg-(base+1); +} +init_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2)); +luaK_fixline(fs,line); +fs->freereg=base+1; +} +static void prefixexp(LexState*ls,expdesc*v){ +switch(ls->t.token){ +case'(':{ +int line=ls->linenumber; +luaX_next(ls); +expr(ls,v); +check_match(ls,')','(',line); +luaK_dischargevars(ls->fs,v); +return; +} +case TK_NAME:{ +singlevar(ls,v); +return; +} +default:{ +luaX_syntaxerror(ls,"unexpected symbol"); +return; +} +} +} +static void primaryexp(LexState*ls,expdesc*v){ +FuncState*fs=ls->fs; +prefixexp(ls,v); +for(;;){ +switch(ls->t.token){ +case'.':{ +field(ls,v); +break; +} +case'[':{ +expdesc key; +luaK_exp2anyreg(fs,v); +yindex(ls,&key); +luaK_indexed(fs,v,&key); +break; +} +case':':{ +expdesc key; +luaX_next(ls); +checkname(ls,&key); +luaK_self(fs,v,&key); +funcargs(ls,v); +break; +} +case'(':case TK_STRING:case'{':{ +luaK_exp2nextreg(fs,v); +funcargs(ls,v); +break; +} +default:return; +} +} +} +static void simpleexp(LexState*ls,expdesc*v){ +switch(ls->t.token){ +case TK_NUMBER:{ +init_exp(v,VKNUM,0); +v->u.nval=ls->t.seminfo.r; +break; +} +case TK_STRING:{ +codestring(ls,v,ls->t.seminfo.ts); +break; +} +case TK_NIL:{ +init_exp(v,VNIL,0); +break; +} +case TK_TRUE:{ +init_exp(v,VTRUE,0); +break; +} +case TK_FALSE:{ +init_exp(v,VFALSE,0); +break; +} +case TK_DOTS:{ +FuncState*fs=ls->fs; +check_condition(ls,fs->f->is_vararg, +"cannot use "LUA_QL("...")" outside a vararg function"); +fs->f->is_vararg&=~4; +init_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0)); +break; +} +case'{':{ +constructor(ls,v); +return; +} +case TK_FUNCTION:{ +luaX_next(ls); +body(ls,v,0,ls->linenumber); +return; +} +default:{ +primaryexp(ls,v); +return; +} +} +luaX_next(ls); +} +static UnOpr getunopr(int op){ +switch(op){ +case TK_NOT:return OPR_NOT; +case'-':return OPR_MINUS; +case'#':return OPR_LEN; +default:return OPR_NOUNOPR; +} +} +static BinOpr getbinopr(int op){ +switch(op){ +case'+':return OPR_ADD; +case'-':return OPR_SUB; +case'*':return OPR_MUL; +case'/':return OPR_DIV; +case'%':return OPR_MOD; +case'^':return OPR_POW; +case TK_CONCAT:return OPR_CONCAT; +case TK_NE:return OPR_NE; +case TK_EQ:return OPR_EQ; +case'<':return OPR_LT; +case TK_LE:return OPR_LE; +case'>':return OPR_GT; +case TK_GE:return OPR_GE; +case TK_AND:return OPR_AND; +case TK_OR:return OPR_OR; +default:return OPR_NOBINOPR; +} +} +static const struct{ +lu_byte left; +lu_byte right; +}priority[]={ +{6,6},{6,6},{7,7},{7,7},{7,7}, +{10,9},{5,4}, +{3,3},{3,3}, +{3,3},{3,3},{3,3},{3,3}, +{2,2},{1,1} +}; +static BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){ +BinOpr op; +UnOpr uop; +enterlevel(ls); +uop=getunopr(ls->t.token); +if(uop!=OPR_NOUNOPR){ +luaX_next(ls); +subexpr(ls,v,8); +luaK_prefix(ls->fs,uop,v); +} +else simpleexp(ls,v); +op=getbinopr(ls->t.token); +while(op!=OPR_NOBINOPR&&priority[op].left>limit){ +expdesc v2; +BinOpr nextop; +luaX_next(ls); +luaK_infix(ls->fs,op,v); +nextop=subexpr(ls,&v2,priority[op].right); +luaK_posfix(ls->fs,op,v,&v2); +op=nextop; +} +leavelevel(ls); +return op; +} +static void expr(LexState*ls,expdesc*v){ +subexpr(ls,v,0); +} +static int block_follow(int token){ +switch(token){ +case TK_ELSE:case TK_ELSEIF:case TK_END: +case TK_UNTIL:case TK_EOS: +return 1; +default:return 0; +} +} +static void block(LexState*ls){ +FuncState*fs=ls->fs; +BlockCnt bl; +enterblock(fs,&bl,0); +chunk(ls); +leaveblock(fs); +} +struct LHS_assign{ +struct LHS_assign*prev; +expdesc v; +}; +static void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){ +FuncState*fs=ls->fs; +int extra=fs->freereg; +int conflict=0; +for(;lh;lh=lh->prev){ +if(lh->v.k==VINDEXED){ +if(lh->v.u.s.info==v->u.s.info){ +conflict=1; +lh->v.u.s.info=extra; +} +if(lh->v.u.s.aux==v->u.s.info){ +conflict=1; +lh->v.u.s.aux=extra; +} +} +} +if(conflict){ +luaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0); +luaK_reserveregs(fs,1); +} +} +static void assignment(LexState*ls,struct LHS_assign*lh,int nvars){ +expdesc e; +check_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED, +"syntax error"); +if(testnext(ls,',')){ +struct LHS_assign nv; +nv.prev=lh; +primaryexp(ls,&nv.v); +if(nv.v.k==VLOCAL) +check_conflict(ls,lh,&nv.v); +luaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls, +"variables in assignment"); +assignment(ls,&nv,nvars+1); +} +else{ +int nexps; +checknext(ls,'='); +nexps=explist1(ls,&e); +if(nexps!=nvars){ +adjust_assign(ls,nvars,nexps,&e); +if(nexps>nvars) +ls->fs->freereg-=nexps-nvars; +} +else{ +luaK_setoneret(ls->fs,&e); +luaK_storevar(ls->fs,&lh->v,&e); +return; +} +} +init_exp(&e,VNONRELOC,ls->fs->freereg-1); +luaK_storevar(ls->fs,&lh->v,&e); +} +static int cond(LexState*ls){ +expdesc v; +expr(ls,&v); +if(v.k==VNIL)v.k=VFALSE; +luaK_goiftrue(ls->fs,&v); +return v.f; +} +static void breakstat(LexState*ls){ +FuncState*fs=ls->fs; +BlockCnt*bl=fs->bl; +int upval=0; +while(bl&&!bl->isbreakable){ +upval|=bl->upval; +bl=bl->previous; +} +if(!bl) +luaX_syntaxerror(ls,"no loop to break"); +if(upval) +luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); +luaK_concat(fs,&bl->breaklist,luaK_jump(fs)); +} +static void whilestat(LexState*ls,int line){ +FuncState*fs=ls->fs; +int whileinit; +int condexit; +BlockCnt bl; +luaX_next(ls); +whileinit=luaK_getlabel(fs); +condexit=cond(ls); +enterblock(fs,&bl,1); +checknext(ls,TK_DO); +block(ls); +luaK_patchlist(fs,luaK_jump(fs),whileinit); +check_match(ls,TK_END,TK_WHILE,line); +leaveblock(fs); +luaK_patchtohere(fs,condexit); +} +static void repeatstat(LexState*ls,int line){ +int condexit; +FuncState*fs=ls->fs; +int repeat_init=luaK_getlabel(fs); +BlockCnt bl1,bl2; +enterblock(fs,&bl1,1); +enterblock(fs,&bl2,0); +luaX_next(ls); +chunk(ls); +check_match(ls,TK_UNTIL,TK_REPEAT,line); +condexit=cond(ls); +if(!bl2.upval){ +leaveblock(fs); +luaK_patchlist(ls->fs,condexit,repeat_init); +} +else{ +breakstat(ls); +luaK_patchtohere(ls->fs,condexit); +leaveblock(fs); +luaK_patchlist(ls->fs,luaK_jump(fs),repeat_init); +} +leaveblock(fs); +} +static int exp1(LexState*ls){ +expdesc e; +int k; +expr(ls,&e); +k=e.k; +luaK_exp2nextreg(ls->fs,&e); +return k; +} +static void forbody(LexState*ls,int base,int line,int nvars,int isnum){ +BlockCnt bl; +FuncState*fs=ls->fs; +int prep,endfor; +adjustlocalvars(ls,3); +checknext(ls,TK_DO); +prep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs); +enterblock(fs,&bl,0); +adjustlocalvars(ls,nvars); +luaK_reserveregs(fs,nvars); +block(ls); +leaveblock(fs); +luaK_patchtohere(fs,prep); +endfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)): +luaK_codeABC(fs,OP_TFORLOOP,base,0,nvars); +luaK_fixline(fs,line); +luaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1); +} +static void fornum(LexState*ls,TString*varname,int line){ +FuncState*fs=ls->fs; +int base=fs->freereg; +new_localvarliteral(ls,"(for index)",0); +new_localvarliteral(ls,"(for limit)",1); +new_localvarliteral(ls,"(for step)",2); +new_localvar(ls,varname,3); +checknext(ls,'='); +exp1(ls); +checknext(ls,','); +exp1(ls); +if(testnext(ls,',')) +exp1(ls); +else{ +luaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1)); +luaK_reserveregs(fs,1); +} +forbody(ls,base,line,1,1); +} +static void forlist(LexState*ls,TString*indexname){ +FuncState*fs=ls->fs; +expdesc e; +int nvars=0; +int line; +int base=fs->freereg; +new_localvarliteral(ls,"(for generator)",nvars++); +new_localvarliteral(ls,"(for state)",nvars++); +new_localvarliteral(ls,"(for control)",nvars++); +new_localvar(ls,indexname,nvars++); +while(testnext(ls,',')) +new_localvar(ls,str_checkname(ls),nvars++); +checknext(ls,TK_IN); +line=ls->linenumber; +adjust_assign(ls,3,explist1(ls,&e),&e); +luaK_checkstack(fs,3); +forbody(ls,base,line,nvars-3,0); +} +static void forstat(LexState*ls,int line){ +FuncState*fs=ls->fs; +TString*varname; +BlockCnt bl; +enterblock(fs,&bl,1); +luaX_next(ls); +varname=str_checkname(ls); +switch(ls->t.token){ +case'=':fornum(ls,varname,line);break; +case',':case TK_IN:forlist(ls,varname);break; +default:luaX_syntaxerror(ls,LUA_QL("=")" or "LUA_QL("in")" expected"); +} +check_match(ls,TK_END,TK_FOR,line); +leaveblock(fs); +} +static int test_then_block(LexState*ls){ +int condexit; +luaX_next(ls); +condexit=cond(ls); +checknext(ls,TK_THEN); +block(ls); +return condexit; +} +static void ifstat(LexState*ls,int line){ +FuncState*fs=ls->fs; +int flist; +int escapelist=(-1); +flist=test_then_block(ls); +while(ls->t.token==TK_ELSEIF){ +luaK_concat(fs,&escapelist,luaK_jump(fs)); +luaK_patchtohere(fs,flist); +flist=test_then_block(ls); +} +if(ls->t.token==TK_ELSE){ +luaK_concat(fs,&escapelist,luaK_jump(fs)); +luaK_patchtohere(fs,flist); +luaX_next(ls); +block(ls); +} +else +luaK_concat(fs,&escapelist,flist); +luaK_patchtohere(fs,escapelist); +check_match(ls,TK_END,TK_IF,line); +} +static void localfunc(LexState*ls){ +expdesc v,b; +FuncState*fs=ls->fs; +new_localvar(ls,str_checkname(ls),0); +init_exp(&v,VLOCAL,fs->freereg); +luaK_reserveregs(fs,1); +adjustlocalvars(ls,1); +body(ls,&b,0,ls->linenumber); +luaK_storevar(fs,&v,&b); +getlocvar(fs,fs->nactvar-1).startpc=fs->pc; +} +static void localstat(LexState*ls){ +int nvars=0; +int nexps; +expdesc e; +do{ +new_localvar(ls,str_checkname(ls),nvars++); +}while(testnext(ls,',')); +if(testnext(ls,'=')) +nexps=explist1(ls,&e); +else{ +e.k=VVOID; +nexps=0; +} +adjust_assign(ls,nvars,nexps,&e); +adjustlocalvars(ls,nvars); +} +static int funcname(LexState*ls,expdesc*v){ +int needself=0; +singlevar(ls,v); +while(ls->t.token=='.') +field(ls,v); +if(ls->t.token==':'){ +needself=1; +field(ls,v); +} +return needself; +} +static void funcstat(LexState*ls,int line){ +int needself; +expdesc v,b; +luaX_next(ls); +needself=funcname(ls,&v); +body(ls,&b,needself,line); +luaK_storevar(ls->fs,&v,&b); +luaK_fixline(ls->fs,line); +} +static void exprstat(LexState*ls){ +FuncState*fs=ls->fs; +struct LHS_assign v; +primaryexp(ls,&v.v); +if(v.v.k==VCALL) +SETARG_C(getcode(fs,&v.v),1); +else{ +v.prev=NULL; +assignment(ls,&v,1); +} +} +static void retstat(LexState*ls){ +FuncState*fs=ls->fs; +expdesc e; +int first,nret; +luaX_next(ls); +if(block_follow(ls->t.token)||ls->t.token==';') +first=nret=0; +else{ +nret=explist1(ls,&e); +if(hasmultret(e.k)){ +luaK_setmultret(fs,&e); +if(e.k==VCALL&&nret==1){ +SET_OPCODE(getcode(fs,&e),OP_TAILCALL); +} +first=fs->nactvar; +nret=(-1); +} +else{ +if(nret==1) +first=luaK_exp2anyreg(fs,&e); +else{ +luaK_exp2nextreg(fs,&e); +first=fs->nactvar; +} +} +} +luaK_ret(fs,first,nret); +} +static int statement(LexState*ls){ +int line=ls->linenumber; +switch(ls->t.token){ +case TK_IF:{ +ifstat(ls,line); +return 0; +} +case TK_WHILE:{ +whilestat(ls,line); +return 0; +} +case TK_DO:{ +luaX_next(ls); +block(ls); +check_match(ls,TK_END,TK_DO,line); +return 0; +} +case TK_FOR:{ +forstat(ls,line); +return 0; +} +case TK_REPEAT:{ +repeatstat(ls,line); +return 0; +} +case TK_FUNCTION:{ +funcstat(ls,line); +return 0; +} +case TK_LOCAL:{ +luaX_next(ls); +if(testnext(ls,TK_FUNCTION)) +localfunc(ls); +else +localstat(ls); +return 0; +} +case TK_RETURN:{ +retstat(ls); +return 1; +} +case TK_BREAK:{ +luaX_next(ls); +breakstat(ls); +return 1; +} +default:{ +exprstat(ls); +return 0; +} +} +} +static void chunk(LexState*ls){ +int islast=0; +enterlevel(ls); +while(!islast&&!block_follow(ls->t.token)){ +islast=statement(ls); +testnext(ls,';'); +ls->fs->freereg=ls->fs->nactvar; +} +leavelevel(ls); +} +static const TValue*luaV_tonumber(const TValue*obj,TValue*n){ +lua_Number num; +if(ttisnumber(obj))return obj; +if(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){ +setnvalue(n,num); +return n; +} +else +return NULL; +} +static int luaV_tostring(lua_State*L,StkId obj){ +if(!ttisnumber(obj)) +return 0; +else{ +char s[32]; +lua_Number n=nvalue(obj); +lua_number2str(s,n); +setsvalue(L,obj,luaS_new(L,s)); +return 1; +} +} +static void callTMres(lua_State*L,StkId res,const TValue*f, +const TValue*p1,const TValue*p2){ +ptrdiff_t result=savestack(L,res); +setobj(L,L->top,f); +setobj(L,L->top+1,p1); +setobj(L,L->top+2,p2); +luaD_checkstack(L,3); +L->top+=3; +luaD_call(L,L->top-3,1); +res=restorestack(L,result); +L->top--; +setobj(L,res,L->top); +} +static void callTM(lua_State*L,const TValue*f,const TValue*p1, +const TValue*p2,const TValue*p3){ +setobj(L,L->top,f); +setobj(L,L->top+1,p1); +setobj(L,L->top+2,p2); +setobj(L,L->top+3,p3); +luaD_checkstack(L,4); +L->top+=4; +luaD_call(L,L->top-4,0); +} +static void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){ +int loop; +for(loop=0;loop<100;loop++){ +const TValue*tm; +if(ttistable(t)){ +Table*h=hvalue(t); +const TValue*res=luaH_get(h,key); +if(!ttisnil(res)|| +(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){ +setobj(L,val,res); +return; +} +} +else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX))) +luaG_typeerror(L,t,"index"); +if(ttisfunction(tm)){ +callTMres(L,val,tm,t,key); +return; +} +t=tm; +} +luaG_runerror(L,"loop in gettable"); +} +static void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){ +int loop; +TValue temp; +for(loop=0;loop<100;loop++){ +const TValue*tm; +if(ttistable(t)){ +Table*h=hvalue(t); +TValue*oldval=luaH_set(L,h,key); +if(!ttisnil(oldval)|| +(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){ +setobj(L,oldval,val); +h->flags=0; +luaC_barriert(L,h,val); +return; +} +} +else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX))) +luaG_typeerror(L,t,"index"); +if(ttisfunction(tm)){ +callTM(L,tm,t,key,val); +return; +} +setobj(L,&temp,tm); +t=&temp; +} +luaG_runerror(L,"loop in settable"); +} +static int call_binTM(lua_State*L,const TValue*p1,const TValue*p2, +StkId res,TMS event){ +const TValue*tm=luaT_gettmbyobj(L,p1,event); +if(ttisnil(tm)) +tm=luaT_gettmbyobj(L,p2,event); +if(ttisnil(tm))return 0; +callTMres(L,res,tm,p1,p2); +return 1; +} +static const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2, +TMS event){ +const TValue*tm1=fasttm(L,mt1,event); +const TValue*tm2; +if(tm1==NULL)return NULL; +if(mt1==mt2)return tm1; +tm2=fasttm(L,mt2,event); +if(tm2==NULL)return NULL; +if(luaO_rawequalObj(tm1,tm2)) +return tm1; +return NULL; +} +static int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2, +TMS event){ +const TValue*tm1=luaT_gettmbyobj(L,p1,event); +const TValue*tm2; +if(ttisnil(tm1))return-1; +tm2=luaT_gettmbyobj(L,p2,event); +if(!luaO_rawequalObj(tm1,tm2)) +return-1; +callTMres(L,L->top,tm1,p1,p2); +return!l_isfalse(L->top); +} +static int l_strcmp(const TString*ls,const TString*rs){ +const char*l=getstr(ls); +size_t ll=ls->tsv.len; +const char*r=getstr(rs); +size_t lr=rs->tsv.len; +for(;;){ +int temp=strcoll(l,r); +if(temp!=0)return temp; +else{ +size_t len=strlen(l); +if(len==lr) +return(len==ll)?0:1; +else if(len==ll) +return-1; +len++; +l+=len;ll-=len;r+=len;lr-=len; +} +} +} +static int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){ +int res; +if(ttype(l)!=ttype(r)) +return luaG_ordererror(L,l,r); +else if(ttisnumber(l)) +return luai_numlt(nvalue(l),nvalue(r)); +else if(ttisstring(l)) +return l_strcmp(rawtsvalue(l),rawtsvalue(r))<0; +else if((res=call_orderTM(L,l,r,TM_LT))!=-1) +return res; +return luaG_ordererror(L,l,r); +} +static int lessequal(lua_State*L,const TValue*l,const TValue*r){ +int res; +if(ttype(l)!=ttype(r)) +return luaG_ordererror(L,l,r); +else if(ttisnumber(l)) +return luai_numle(nvalue(l),nvalue(r)); +else if(ttisstring(l)) +return l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0; +else if((res=call_orderTM(L,l,r,TM_LE))!=-1) +return res; +else if((res=call_orderTM(L,r,l,TM_LT))!=-1) +return!res; +return luaG_ordererror(L,l,r); +} +static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){ +const TValue*tm; +switch(ttype(t1)){ +case 0:return 1; +case 3:return luai_numeq(nvalue(t1),nvalue(t2)); +case 1:return bvalue(t1)==bvalue(t2); +case 2:return pvalue(t1)==pvalue(t2); +case 7:{ +if(uvalue(t1)==uvalue(t2))return 1; +tm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable, +TM_EQ); +break; +} +case 5:{ +if(hvalue(t1)==hvalue(t2))return 1; +tm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ); +break; +} +default:return gcvalue(t1)==gcvalue(t2); +} +if(tm==NULL)return 0; +callTMres(L,L->top,tm,t1,t2); +return!l_isfalse(L->top); +} +static void luaV_concat(lua_State*L,int total,int last){ +do{ +StkId top=L->base+last+1; +int n=2; +if(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){ +if(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT)) +luaG_concaterror(L,top-2,top-1); +}else if(tsvalue(top-1)->len==0) +(void)tostring(L,top-2); +else{ +size_t tl=tsvalue(top-1)->len; +char*buffer; +int i; +for(n=1;nlen; +if(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,"string length overflow"); +tl+=l; +} +buffer=luaZ_openspace(L,&G(L)->buff,tl); +tl=0; +for(i=n;i>0;i--){ +size_t l=tsvalue(top-i)->len; +memcpy(buffer+tl,svalue(top-i),l); +tl+=l; +} +setsvalue(L,top-n,luaS_newlstr(L,buffer,tl)); +} +total-=n-1; +last-=n-1; +}while(total>1); +} +static void Arith(lua_State*L,StkId ra,const TValue*rb, +const TValue*rc,TMS op){ +TValue tempb,tempc; +const TValue*b,*c; +if((b=luaV_tonumber(rb,&tempb))!=NULL&& +(c=luaV_tonumber(rc,&tempc))!=NULL){ +lua_Number nb=nvalue(b),nc=nvalue(c); +switch(op){ +case TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break; +case TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break; +case TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break; +case TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break; +case TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break; +case TM_POW:setnvalue(ra,luai_numpow(nb,nc));break; +case TM_UNM:setnvalue(ra,luai_numunm(nb));break; +default:break; +} +} +else if(!call_binTM(L,rb,rc,ra,op)) +luaG_aritherror(L,rb,rc); +} +#define runtime_check(L,c){if(!(c))break;} +#define RA(i)(base+GETARG_A(i)) +#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i)) +#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i)) +#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i)) +#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i)) +#define dojump(L,pc,i){(pc)+=(i);} +#define Protect(x){L->savedpc=pc;{x;};base=L->base;} +#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));} +static void luaV_execute(lua_State*L,int nexeccalls){ +LClosure*cl; +StkId base; +TValue*k; +const Instruction*pc; +reentry: +pc=L->savedpc; +cl=&clvalue(L->ci->func)->l; +base=L->base; +k=cl->p->k; +for(;;){ +const Instruction i=*pc++; +StkId ra; +ra=RA(i); +switch(GET_OPCODE(i)){ +case OP_MOVE:{ +setobj(L,ra,RB(i)); +continue; +} +case OP_LOADK:{ +setobj(L,ra,KBx(i)); +continue; +} +case OP_LOADBOOL:{ +setbvalue(ra,GETARG_B(i)); +if(GETARG_C(i))pc++; +continue; +} +case OP_LOADNIL:{ +TValue*rb=RB(i); +do{ +setnilvalue(rb--); +}while(rb>=ra); +continue; +} +case OP_GETUPVAL:{ +int b=GETARG_B(i); +setobj(L,ra,cl->upvals[b]->v); +continue; +} +case OP_GETGLOBAL:{ +TValue g; +TValue*rb=KBx(i); +sethvalue(L,&g,cl->env); +Protect(luaV_gettable(L,&g,rb,ra)); +continue; +} +case OP_GETTABLE:{ +Protect(luaV_gettable(L,RB(i),RKC(i),ra)); +continue; +} +case OP_SETGLOBAL:{ +TValue g; +sethvalue(L,&g,cl->env); +Protect(luaV_settable(L,&g,KBx(i),ra)); +continue; +} +case OP_SETUPVAL:{ +UpVal*uv=cl->upvals[GETARG_B(i)]; +setobj(L,uv->v,ra); +luaC_barrier(L,uv,ra); +continue; +} +case OP_SETTABLE:{ +Protect(luaV_settable(L,ra,RKB(i),RKC(i))); +continue; +} +case OP_NEWTABLE:{ +int b=GETARG_B(i); +int c=GETARG_C(i); +sethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c))); +Protect(luaC_checkGC(L)); +continue; +} +case OP_SELF:{ +StkId rb=RB(i); +setobj(L,ra+1,rb); +Protect(luaV_gettable(L,rb,RKC(i),ra)); +continue; +} +case OP_ADD:{ +arith_op(luai_numadd,TM_ADD); +continue; +} +case OP_SUB:{ +arith_op(luai_numsub,TM_SUB); +continue; +} +case OP_MUL:{ +arith_op(luai_nummul,TM_MUL); +continue; +} +case OP_DIV:{ +arith_op(luai_numdiv,TM_DIV); +continue; +} +case OP_MOD:{ +arith_op(luai_nummod,TM_MOD); +continue; +} +case OP_POW:{ +arith_op(luai_numpow,TM_POW); +continue; +} +case OP_UNM:{ +TValue*rb=RB(i); +if(ttisnumber(rb)){ +lua_Number nb=nvalue(rb); +setnvalue(ra,luai_numunm(nb)); +} +else{ +Protect(Arith(L,ra,rb,rb,TM_UNM)); +} +continue; +} +case OP_NOT:{ +int res=l_isfalse(RB(i)); +setbvalue(ra,res); +continue; +} +case OP_LEN:{ +const TValue*rb=RB(i); +switch(ttype(rb)){ +case 5:{ +setnvalue(ra,cast_num(luaH_getn(hvalue(rb)))); +break; +} +case 4:{ +setnvalue(ra,cast_num(tsvalue(rb)->len)); +break; +} +default:{ +Protect( +if(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN)) +luaG_typeerror(L,rb,"get length of"); +) +} +} +continue; +} +case OP_CONCAT:{ +int b=GETARG_B(i); +int c=GETARG_C(i); +Protect(luaV_concat(L,c-b+1,c);luaC_checkGC(L)); +setobj(L,RA(i),base+b); +continue; +} +case OP_JMP:{ +dojump(L,pc,GETARG_sBx(i)); +continue; +} +case OP_EQ:{ +TValue*rb=RKB(i); +TValue*rc=RKC(i); +Protect( +if(equalobj(L,rb,rc)==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_LT:{ +Protect( +if(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_LE:{ +Protect( +if(lessequal(L,RKB(i),RKC(i))==GETARG_A(i)) +dojump(L,pc,GETARG_sBx(*pc)); +) +pc++; +continue; +} +case OP_TEST:{ +if(l_isfalse(ra)!=GETARG_C(i)) +dojump(L,pc,GETARG_sBx(*pc)); +pc++; +continue; +} +case OP_TESTSET:{ +TValue*rb=RB(i); +if(l_isfalse(rb)!=GETARG_C(i)){ +setobj(L,ra,rb); +dojump(L,pc,GETARG_sBx(*pc)); +} +pc++; +continue; +} +case OP_CALL:{ +int b=GETARG_B(i); +int nresults=GETARG_C(i)-1; +if(b!=0)L->top=ra+b; +L->savedpc=pc; +switch(luaD_precall(L,ra,nresults)){ +case 0:{ +nexeccalls++; +goto reentry; +} +case 1:{ +if(nresults>=0)L->top=L->ci->top; +base=L->base; +continue; +} +default:{ +return; +} +} +} +case OP_TAILCALL:{ +int b=GETARG_B(i); +if(b!=0)L->top=ra+b; +L->savedpc=pc; +switch(luaD_precall(L,ra,(-1))){ +case 0:{ +CallInfo*ci=L->ci-1; +int aux; +StkId func=ci->func; +StkId pfunc=(ci+1)->func; +if(L->openupval)luaF_close(L,ci->base); +L->base=ci->base=ci->func+((ci+1)->base-pfunc); +for(aux=0;pfunc+auxtop;aux++) +setobj(L,func+aux,pfunc+aux); +ci->top=L->top=func+aux; +ci->savedpc=L->savedpc; +ci->tailcalls++; +L->ci--; +goto reentry; +} +case 1:{ +base=L->base; +continue; +} +default:{ +return; +} +} +} +case OP_RETURN:{ +int b=GETARG_B(i); +if(b!=0)L->top=ra+b-1; +if(L->openupval)luaF_close(L,base); +L->savedpc=pc; +b=luaD_poscall(L,ra); +if(--nexeccalls==0) +return; +else{ +if(b)L->top=L->ci->top; +goto reentry; +} +} +case OP_FORLOOP:{ +lua_Number step=nvalue(ra+2); +lua_Number idx=luai_numadd(nvalue(ra),step); +lua_Number limit=nvalue(ra+1); +if(luai_numlt(0,step)?luai_numle(idx,limit) +:luai_numle(limit,idx)){ +dojump(L,pc,GETARG_sBx(i)); +setnvalue(ra,idx); +setnvalue(ra+3,idx); +} +continue; +} +case OP_FORPREP:{ +const TValue*init=ra; +const TValue*plimit=ra+1; +const TValue*pstep=ra+2; +L->savedpc=pc; +if(!tonumber(init,ra)) +luaG_runerror(L,LUA_QL("for")" initial value must be a number"); +else if(!tonumber(plimit,ra+1)) +luaG_runerror(L,LUA_QL("for")" limit must be a number"); +else if(!tonumber(pstep,ra+2)) +luaG_runerror(L,LUA_QL("for")" step must be a number"); +setnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep))); +dojump(L,pc,GETARG_sBx(i)); +continue; +} +case OP_TFORLOOP:{ +StkId cb=ra+3; +setobj(L,cb+2,ra+2); +setobj(L,cb+1,ra+1); +setobj(L,cb,ra); +L->top=cb+3; +Protect(luaD_call(L,cb,GETARG_C(i))); +L->top=L->ci->top; +cb=RA(i)+3; +if(!ttisnil(cb)){ +setobj(L,cb-1,cb); +dojump(L,pc,GETARG_sBx(*pc)); +} +pc++; +continue; +} +case OP_SETLIST:{ +int n=GETARG_B(i); +int c=GETARG_C(i); +int last; +Table*h; +if(n==0){ +n=cast_int(L->top-ra)-1; +L->top=L->ci->top; +} +if(c==0)c=cast_int(*pc++); +runtime_check(L,ttistable(ra)); +h=hvalue(ra); +last=((c-1)*50)+n; +if(last>h->sizearray) +luaH_resizearray(L,h,last); +for(;n>0;n--){ +TValue*val=ra+n; +setobj(L,luaH_setnum(L,h,last--),val); +luaC_barriert(L,h,val); +} +continue; +} +case OP_CLOSE:{ +luaF_close(L,ra); +continue; +} +case OP_CLOSURE:{ +Proto*p; +Closure*ncl; +int nup,j; +p=cl->p->p[GETARG_Bx(i)]; +nup=p->nups; +ncl=luaF_newLclosure(L,nup,cl->env); +ncl->l.p=p; +for(j=0;jl.upvals[j]=cl->upvals[GETARG_B(*pc)]; +else{ +ncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc)); +} +} +setclvalue(L,ra,ncl); +Protect(luaC_checkGC(L)); +continue; +} +case OP_VARARG:{ +int b=GETARG_B(i)-1; +int j; +CallInfo*ci=L->ci; +int n=cast_int(ci->base-ci->func)-cl->p->numparams-1; +if(b==(-1)){ +Protect(luaD_checkstack(L,n)); +ra=RA(i); +b=n; +L->top=ra+n; +} +for(j=0;jbase-n+j); +} +else{ +setnilvalue(ra+j); +} +} +continue; +} +} +} +} +#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base)) +#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_)) +#define api_incr_top(L){luai_apicheck(L,L->topci->top);L->top++;} +static TValue*index2adr(lua_State*L,int idx){ +if(idx>0){ +TValue*o=L->base+(idx-1); +luai_apicheck(L,idx<=L->ci->top-L->base); +if(o>=L->top)return cast(TValue*,(&luaO_nilobject_)); +else return o; +} +else if(idx>(-10000)){ +luai_apicheck(L,idx!=0&&-idx<=L->top-L->base); +return L->top+idx; +} +else switch(idx){ +case(-10000):return registry(L); +case(-10001):{ +Closure*func=curr_func(L); +sethvalue(L,&L->env,func->c.env); +return&L->env; +} +case(-10002):return gt(L); +default:{ +Closure*func=curr_func(L); +idx=(-10002)-idx; +return(idx<=func->c.nupvalues) +?&func->c.upvalue[idx-1] +:cast(TValue*,(&luaO_nilobject_)); +} +} +} +static Table*getcurrenv(lua_State*L){ +if(L->ci==L->base_ci) +return hvalue(gt(L)); +else{ +Closure*func=curr_func(L); +return func->c.env; +} +} +static int lua_checkstack(lua_State*L,int size){ +int res=1; +if(size>8000||(L->top-L->base+size)>8000) +res=0; +else if(size>0){ +luaD_checkstack(L,size); +if(L->ci->toptop+size) +L->ci->top=L->top+size; +} +return res; +} +static lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){ +lua_CFunction old; +old=G(L)->panic; +G(L)->panic=panicf; +return old; +} +static int lua_gettop(lua_State*L){ +return cast_int(L->top-L->base); +} +static void lua_settop(lua_State*L,int idx){ +if(idx>=0){ +luai_apicheck(L,idx<=L->stack_last-L->base); +while(L->topbase+idx) +setnilvalue(L->top++); +L->top=L->base+idx; +} +else{ +luai_apicheck(L,-(idx+1)<=(L->top-L->base)); +L->top+=idx+1; +} +} +static void lua_remove(lua_State*L,int idx){ +StkId p; +p=index2adr(L,idx); +api_checkvalidindex(L,p); +while(++ptop)setobj(L,p-1,p); +L->top--; +} +static void lua_insert(lua_State*L,int idx){ +StkId p; +StkId q; +p=index2adr(L,idx); +api_checkvalidindex(L,p); +for(q=L->top;q>p;q--)setobj(L,q,q-1); +setobj(L,p,L->top); +} +static void lua_replace(lua_State*L,int idx){ +StkId o; +if(idx==(-10001)&&L->ci==L->base_ci) +luaG_runerror(L,"no calling environment"); +api_checknelems(L,1); +o=index2adr(L,idx); +api_checkvalidindex(L,o); +if(idx==(-10001)){ +Closure*func=curr_func(L); +luai_apicheck(L,ttistable(L->top-1)); +func->c.env=hvalue(L->top-1); +luaC_barrier(L,func,L->top-1); +} +else{ +setobj(L,o,L->top-1); +if(idx<(-10002)) +luaC_barrier(L,curr_func(L),L->top-1); +} +L->top--; +} +static void lua_pushvalue(lua_State*L,int idx){ +setobj(L,L->top,index2adr(L,idx)); +api_incr_top(L); +} +static int lua_type(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return(o==(&luaO_nilobject_))?(-1):ttype(o); +} +static const char*lua_typename(lua_State*L,int t){ +UNUSED(L); +return(t==(-1))?"no value":luaT_typenames[t]; +} +static int lua_iscfunction(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return iscfunction(o); +} +static int lua_isnumber(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +return tonumber(o,&n); +} +static int lua_isstring(lua_State*L,int idx){ +int t=lua_type(L,idx); +return(t==4||t==3); +} +static int lua_rawequal(lua_State*L,int index1,int index2){ +StkId o1=index2adr(L,index1); +StkId o2=index2adr(L,index2); +return(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 +:luaO_rawequalObj(o1,o2); +} +static int lua_lessthan(lua_State*L,int index1,int index2){ +StkId o1,o2; +int i; +o1=index2adr(L,index1); +o2=index2adr(L,index2); +i=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 +:luaV_lessthan(L,o1,o2); +return i; +} +static lua_Number lua_tonumber(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +if(tonumber(o,&n)) +return nvalue(o); +else +return 0; +} +static lua_Integer lua_tointeger(lua_State*L,int idx){ +TValue n; +const TValue*o=index2adr(L,idx); +if(tonumber(o,&n)){ +lua_Integer res; +lua_Number num=nvalue(o); +lua_number2integer(res,num); +return res; +} +else +return 0; +} +static int lua_toboolean(lua_State*L,int idx){ +const TValue*o=index2adr(L,idx); +return!l_isfalse(o); +} +static const char*lua_tolstring(lua_State*L,int idx,size_t*len){ +StkId o=index2adr(L,idx); +if(!ttisstring(o)){ +if(!luaV_tostring(L,o)){ +if(len!=NULL)*len=0; +return NULL; +} +luaC_checkGC(L); +o=index2adr(L,idx); +} +if(len!=NULL)*len=tsvalue(o)->len; +return svalue(o); +} +static size_t lua_objlen(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +switch(ttype(o)){ +case 4:return tsvalue(o)->len; +case 7:return uvalue(o)->len; +case 5:return luaH_getn(hvalue(o)); +case 3:{ +size_t l; +l=(luaV_tostring(L,o)?tsvalue(o)->len:0); +return l; +} +default:return 0; +} +} +static lua_CFunction lua_tocfunction(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +return(!iscfunction(o))?NULL:clvalue(o)->c.f; +} +static void*lua_touserdata(lua_State*L,int idx){ +StkId o=index2adr(L,idx); +switch(ttype(o)){ +case 7:return(rawuvalue(o)+1); +case 2:return pvalue(o); +default:return NULL; +} +} +static void lua_pushnil(lua_State*L){ +setnilvalue(L->top); +api_incr_top(L); +} +static void lua_pushnumber(lua_State*L,lua_Number n){ +setnvalue(L->top,n); +api_incr_top(L); +} +static void lua_pushinteger(lua_State*L,lua_Integer n){ +setnvalue(L->top,cast_num(n)); +api_incr_top(L); +} +static void lua_pushlstring(lua_State*L,const char*s,size_t len){ +luaC_checkGC(L); +setsvalue(L,L->top,luaS_newlstr(L,s,len)); +api_incr_top(L); +} +static void lua_pushstring(lua_State*L,const char*s){ +if(s==NULL) +lua_pushnil(L); +else +lua_pushlstring(L,s,strlen(s)); +} +static const char*lua_pushvfstring(lua_State*L,const char*fmt, +va_list argp){ +const char*ret; +luaC_checkGC(L); +ret=luaO_pushvfstring(L,fmt,argp); +return ret; +} +static const char*lua_pushfstring(lua_State*L,const char*fmt,...){ +const char*ret; +va_list argp; +luaC_checkGC(L); +va_start(argp,fmt); +ret=luaO_pushvfstring(L,fmt,argp); +va_end(argp); +return ret; +} +static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){ +Closure*cl; +luaC_checkGC(L); +api_checknelems(L,n); +cl=luaF_newCclosure(L,n,getcurrenv(L)); +cl->c.f=fn; +L->top-=n; +while(n--) +setobj(L,&cl->c.upvalue[n],L->top+n); +setclvalue(L,L->top,cl); +api_incr_top(L); +} +static void lua_pushboolean(lua_State*L,int b){ +setbvalue(L->top,(b!=0)); +api_incr_top(L); +} +static int lua_pushthread(lua_State*L){ +setthvalue(L,L->top,L); +api_incr_top(L); +return(G(L)->mainthread==L); +} +static void lua_gettable(lua_State*L,int idx){ +StkId t; +t=index2adr(L,idx); +api_checkvalidindex(L,t); +luaV_gettable(L,t,L->top-1,L->top-1); +} +static void lua_getfield(lua_State*L,int idx,const char*k){ +StkId t; +TValue key; +t=index2adr(L,idx); +api_checkvalidindex(L,t); +setsvalue(L,&key,luaS_new(L,k)); +luaV_gettable(L,t,&key,L->top); +api_incr_top(L); +} +static void lua_rawget(lua_State*L,int idx){ +StkId t; +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +setobj(L,L->top-1,luaH_get(hvalue(t),L->top-1)); +} +static void lua_rawgeti(lua_State*L,int idx,int n){ +StkId o; +o=index2adr(L,idx); +luai_apicheck(L,ttistable(o)); +setobj(L,L->top,luaH_getnum(hvalue(o),n)); +api_incr_top(L); +} +static void lua_createtable(lua_State*L,int narray,int nrec){ +luaC_checkGC(L); +sethvalue(L,L->top,luaH_new(L,narray,nrec)); +api_incr_top(L); +} +static int lua_getmetatable(lua_State*L,int objindex){ +const TValue*obj; +Table*mt=NULL; +int res; +obj=index2adr(L,objindex); +switch(ttype(obj)){ +case 5: +mt=hvalue(obj)->metatable; +break; +case 7: +mt=uvalue(obj)->metatable; +break; +default: +mt=G(L)->mt[ttype(obj)]; +break; +} +if(mt==NULL) +res=0; +else{ +sethvalue(L,L->top,mt); +api_incr_top(L); +res=1; +} +return res; +} +static void lua_getfenv(lua_State*L,int idx){ +StkId o; +o=index2adr(L,idx); +api_checkvalidindex(L,o); +switch(ttype(o)){ +case 6: +sethvalue(L,L->top,clvalue(o)->c.env); +break; +case 7: +sethvalue(L,L->top,uvalue(o)->env); +break; +case 8: +setobj(L,L->top,gt(thvalue(o))); +break; +default: +setnilvalue(L->top); +break; +} +api_incr_top(L); +} +static void lua_settable(lua_State*L,int idx){ +StkId t; +api_checknelems(L,2); +t=index2adr(L,idx); +api_checkvalidindex(L,t); +luaV_settable(L,t,L->top-2,L->top-1); +L->top-=2; +} +static void lua_setfield(lua_State*L,int idx,const char*k){ +StkId t; +TValue key; +api_checknelems(L,1); +t=index2adr(L,idx); +api_checkvalidindex(L,t); +setsvalue(L,&key,luaS_new(L,k)); +luaV_settable(L,t,&key,L->top-1); +L->top--; +} +static void lua_rawset(lua_State*L,int idx){ +StkId t; +api_checknelems(L,2); +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +setobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1); +luaC_barriert(L,hvalue(t),L->top-1); +L->top-=2; +} +static void lua_rawseti(lua_State*L,int idx,int n){ +StkId o; +api_checknelems(L,1); +o=index2adr(L,idx); +luai_apicheck(L,ttistable(o)); +setobj(L,luaH_setnum(L,hvalue(o),n),L->top-1); +luaC_barriert(L,hvalue(o),L->top-1); +L->top--; +} +static int lua_setmetatable(lua_State*L,int objindex){ +TValue*obj; +Table*mt; +api_checknelems(L,1); +obj=index2adr(L,objindex); +api_checkvalidindex(L,obj); +if(ttisnil(L->top-1)) +mt=NULL; +else{ +luai_apicheck(L,ttistable(L->top-1)); +mt=hvalue(L->top-1); +} +switch(ttype(obj)){ +case 5:{ +hvalue(obj)->metatable=mt; +if(mt) +luaC_objbarriert(L,hvalue(obj),mt); +break; +} +case 7:{ +uvalue(obj)->metatable=mt; +if(mt) +luaC_objbarrier(L,rawuvalue(obj),mt); +break; +} +default:{ +G(L)->mt[ttype(obj)]=mt; +break; +} +} +L->top--; +return 1; +} +static int lua_setfenv(lua_State*L,int idx){ +StkId o; +int res=1; +api_checknelems(L,1); +o=index2adr(L,idx); +api_checkvalidindex(L,o); +luai_apicheck(L,ttistable(L->top-1)); +switch(ttype(o)){ +case 6: +clvalue(o)->c.env=hvalue(L->top-1); +break; +case 7: +uvalue(o)->env=hvalue(L->top-1); +break; +case 8: +sethvalue(L,gt(thvalue(o)),hvalue(L->top-1)); +break; +default: +res=0; +break; +} +if(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1)); +L->top--; +return res; +} +#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;} +#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na))) +static void lua_call(lua_State*L,int nargs,int nresults){ +StkId func; +api_checknelems(L,nargs+1); +checkresults(L,nargs,nresults); +func=L->top-(nargs+1); +luaD_call(L,func,nresults); +adjustresults(L,nresults); +} +struct CallS{ +StkId func; +int nresults; +}; +static void f_call(lua_State*L,void*ud){ +struct CallS*c=cast(struct CallS*,ud); +luaD_call(L,c->func,c->nresults); +} +static int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){ +struct CallS c; +int status; +ptrdiff_t func; +api_checknelems(L,nargs+1); +checkresults(L,nargs,nresults); +if(errfunc==0) +func=0; +else{ +StkId o=index2adr(L,errfunc); +api_checkvalidindex(L,o); +func=savestack(L,o); +} +c.func=L->top-(nargs+1); +c.nresults=nresults; +status=luaD_pcall(L,f_call,&c,savestack(L,c.func),func); +adjustresults(L,nresults); +return status; +} +static int lua_load(lua_State*L,lua_Reader reader,void*data, +const char*chunkname){ +ZIO z; +int status; +if(!chunkname)chunkname="?"; +luaZ_init(L,&z,reader,data); +status=luaD_protectedparser(L,&z,chunkname); +return status; +} +static int lua_error(lua_State*L){ +api_checknelems(L,1); +luaG_errormsg(L); +return 0; +} +static int lua_next(lua_State*L,int idx){ +StkId t; +int more; +t=index2adr(L,idx); +luai_apicheck(L,ttistable(t)); +more=luaH_next(L,hvalue(t),L->top-1); +if(more){ +api_incr_top(L); +} +else +L->top-=1; +return more; +} +static void lua_concat(lua_State*L,int n){ +api_checknelems(L,n); +if(n>=2){ +luaC_checkGC(L); +luaV_concat(L,n,cast_int(L->top-L->base)-1); +L->top-=(n-1); +} +else if(n==0){ +setsvalue(L,L->top,luaS_newlstr(L,"",0)); +api_incr_top(L); +} +} +static void*lua_newuserdata(lua_State*L,size_t size){ +Udata*u; +luaC_checkGC(L); +u=luaS_newudata(L,size,getcurrenv(L)); +setuvalue(L,L->top,u); +api_incr_top(L); +return u+1; +} +#define luaL_getn(L,i)((int)lua_objlen(L,i)) +#define luaL_setn(L,i,j)((void)0) +typedef struct luaL_Reg{ +const char*name; +lua_CFunction func; +}luaL_Reg; +static void luaI_openlib(lua_State*L,const char*libname, +const luaL_Reg*l,int nup); +static int luaL_argerror(lua_State*L,int numarg,const char*extramsg); +static const char* luaL_checklstring(lua_State*L,int numArg, +size_t*l); +static const char* luaL_optlstring(lua_State*L,int numArg, +const char*def,size_t*l); +static lua_Integer luaL_checkinteger(lua_State*L,int numArg); +static lua_Integer luaL_optinteger(lua_State*L,int nArg, +lua_Integer def); +static int luaL_error(lua_State*L,const char*fmt,...); +static const char* luaL_findtable(lua_State*L,int idx, +const char*fname,int szhint); +#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg)))) +#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL)) +#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL)) +#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n))) +#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d))) +#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i))) +#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n))) +#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n))) +typedef struct luaL_Buffer{ +char*p; +int lvl; +lua_State*L; +char buffer[BUFSIZ]; +}luaL_Buffer; +#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c))) +#define luaL_addsize(B,n)((B)->p+=(n)) +static char* luaL_prepbuffer(luaL_Buffer*B); +static int luaL_argerror(lua_State*L,int narg,const char*extramsg){ +lua_Debug ar; +if(!lua_getstack(L,0,&ar)) +return luaL_error(L,"bad argument #%d (%s)",narg,extramsg); +lua_getinfo(L,"n",&ar); +if(strcmp(ar.namewhat,"method")==0){ +narg--; +if(narg==0) +return luaL_error(L,"calling "LUA_QL("%s")" on bad self (%s)", +ar.name,extramsg); +} +if(ar.name==NULL) +ar.name="?"; +return luaL_error(L,"bad argument #%d to "LUA_QL("%s")" (%s)", +narg,ar.name,extramsg); +} +static int luaL_typerror(lua_State*L,int narg,const char*tname){ +const char*msg=lua_pushfstring(L,"%s expected, got %s", +tname,luaL_typename(L,narg)); +return luaL_argerror(L,narg,msg); +} +static void tag_error(lua_State*L,int narg,int tag){ +luaL_typerror(L,narg,lua_typename(L,tag)); +} +static void luaL_where(lua_State*L,int level){ +lua_Debug ar; +if(lua_getstack(L,level,&ar)){ +lua_getinfo(L,"Sl",&ar); +if(ar.currentline>0){ +lua_pushfstring(L,"%s:%d: ",ar.short_src,ar.currentline); +return; +} +} +lua_pushliteral(L,""); +} +static int luaL_error(lua_State*L,const char*fmt,...){ +va_list argp; +va_start(argp,fmt); +luaL_where(L,1); +lua_pushvfstring(L,fmt,argp); +va_end(argp); +lua_concat(L,2); +return lua_error(L); +} +static int luaL_newmetatable(lua_State*L,const char*tname){ +lua_getfield(L,(-10000),tname); +if(!lua_isnil(L,-1)) +return 0; +lua_pop(L,1); +lua_newtable(L); +lua_pushvalue(L,-1); +lua_setfield(L,(-10000),tname); +return 1; +} +static void*luaL_checkudata(lua_State*L,int ud,const char*tname){ +void*p=lua_touserdata(L,ud); +if(p!=NULL){ +if(lua_getmetatable(L,ud)){ +lua_getfield(L,(-10000),tname); +if(lua_rawequal(L,-1,-2)){ +lua_pop(L,2); +return p; +} +} +} +luaL_typerror(L,ud,tname); +return NULL; +} +static void luaL_checkstack(lua_State*L,int space,const char*mes){ +if(!lua_checkstack(L,space)) +luaL_error(L,"stack overflow (%s)",mes); +} +static void luaL_checktype(lua_State*L,int narg,int t){ +if(lua_type(L,narg)!=t) +tag_error(L,narg,t); +} +static void luaL_checkany(lua_State*L,int narg){ +if(lua_type(L,narg)==(-1)) +luaL_argerror(L,narg,"value expected"); +} +static const char*luaL_checklstring(lua_State*L,int narg,size_t*len){ +const char*s=lua_tolstring(L,narg,len); +if(!s)tag_error(L,narg,4); +return s; +} +static const char*luaL_optlstring(lua_State*L,int narg, +const char*def,size_t*len){ +if(lua_isnoneornil(L,narg)){ +if(len) +*len=(def?strlen(def):0); +return def; +} +else return luaL_checklstring(L,narg,len); +} +static lua_Number luaL_checknumber(lua_State*L,int narg){ +lua_Number d=lua_tonumber(L,narg); +if(d==0&&!lua_isnumber(L,narg)) +tag_error(L,narg,3); +return d; +} +static lua_Integer luaL_checkinteger(lua_State*L,int narg){ +lua_Integer d=lua_tointeger(L,narg); +if(d==0&&!lua_isnumber(L,narg)) +tag_error(L,narg,3); +return d; +} +static lua_Integer luaL_optinteger(lua_State*L,int narg, +lua_Integer def){ +return luaL_opt(L,luaL_checkinteger,narg,def); +} +static int luaL_getmetafield(lua_State*L,int obj,const char*event){ +if(!lua_getmetatable(L,obj)) +return 0; +lua_pushstring(L,event); +lua_rawget(L,-2); +if(lua_isnil(L,-1)){ +lua_pop(L,2); +return 0; +} +else{ +lua_remove(L,-2); +return 1; +} +} +static void luaL_register(lua_State*L,const char*libname, +const luaL_Reg*l){ +luaI_openlib(L,libname,l,0); +} +static int libsize(const luaL_Reg*l){ +int size=0; +for(;l->name;l++)size++; +return size; +} +static void luaI_openlib(lua_State*L,const char*libname, +const luaL_Reg*l,int nup){ +if(libname){ +int size=libsize(l); +luaL_findtable(L,(-10000),"_LOADED",1); +lua_getfield(L,-1,libname); +if(!lua_istable(L,-1)){ +lua_pop(L,1); +if(luaL_findtable(L,(-10002),libname,size)!=NULL) +luaL_error(L,"name conflict for module "LUA_QL("%s"),libname); +lua_pushvalue(L,-1); +lua_setfield(L,-3,libname); +} +lua_remove(L,-2); +lua_insert(L,-(nup+1)); +} +for(;l->name;l++){ +int i; +for(i=0;ifunc,nup); +lua_setfield(L,-(nup+2),l->name); +} +lua_pop(L,nup); +} +static const char*luaL_findtable(lua_State*L,int idx, +const char*fname,int szhint){ +const char*e; +lua_pushvalue(L,idx); +do{ +e=strchr(fname,'.'); +if(e==NULL)e=fname+strlen(fname); +lua_pushlstring(L,fname,e-fname); +lua_rawget(L,-2); +if(lua_isnil(L,-1)){ +lua_pop(L,1); +lua_createtable(L,0,(*e=='.'?1:szhint)); +lua_pushlstring(L,fname,e-fname); +lua_pushvalue(L,-2); +lua_settable(L,-4); +} +else if(!lua_istable(L,-1)){ +lua_pop(L,2); +return fname; +} +lua_remove(L,-2); +fname=e+1; +}while(*e=='.'); +return NULL; +} +#define bufflen(B)((B)->p-(B)->buffer) +#define bufffree(B)((size_t)(BUFSIZ-bufflen(B))) +static int emptybuffer(luaL_Buffer*B){ +size_t l=bufflen(B); +if(l==0)return 0; +else{ +lua_pushlstring(B->L,B->buffer,l); +B->p=B->buffer; +B->lvl++; +return 1; +} +} +static void adjuststack(luaL_Buffer*B){ +if(B->lvl>1){ +lua_State*L=B->L; +int toget=1; +size_t toplen=lua_strlen(L,-1); +do{ +size_t l=lua_strlen(L,-(toget+1)); +if(B->lvl-toget+1>=(20/2)||toplen>l){ +toplen+=l; +toget++; +} +else break; +}while(togetlvl); +lua_concat(L,toget); +B->lvl=B->lvl-toget+1; +} +} +static char*luaL_prepbuffer(luaL_Buffer*B){ +if(emptybuffer(B)) +adjuststack(B); +return B->buffer; +} +static void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){ +while(l--) +luaL_addchar(B,*s++); +} +static void luaL_pushresult(luaL_Buffer*B){ +emptybuffer(B); +lua_concat(B->L,B->lvl); +B->lvl=1; +} +static void luaL_addvalue(luaL_Buffer*B){ +lua_State*L=B->L; +size_t vl; +const char*s=lua_tolstring(L,-1,&vl); +if(vl<=bufffree(B)){ +memcpy(B->p,s,vl); +B->p+=vl; +lua_pop(L,1); +} +else{ +if(emptybuffer(B)) +lua_insert(L,-2); +B->lvl++; +adjuststack(B); +} +} +static void luaL_buffinit(lua_State*L,luaL_Buffer*B){ +B->L=L; +B->p=B->buffer; +B->lvl=0; +} +typedef struct LoadF{ +int extraline; +FILE*f; +char buff[BUFSIZ]; +}LoadF; +static const char*getF(lua_State*L,void*ud,size_t*size){ +LoadF*lf=(LoadF*)ud; +(void)L; +if(lf->extraline){ +lf->extraline=0; +*size=1; +return"\n"; +} +if(feof(lf->f))return NULL; +*size=fread(lf->buff,1,sizeof(lf->buff),lf->f); +return(*size>0)?lf->buff:NULL; +} +static int errfile(lua_State*L,const char*what,int fnameindex){ +const char*serr=strerror(errno); +const char*filename=lua_tostring(L,fnameindex)+1; +lua_pushfstring(L,"cannot %s %s: %s",what,filename,serr); +lua_remove(L,fnameindex); +return(5+1); +} +static int luaL_loadfile(lua_State*L,const char*filename){ +LoadF lf; +int status,readstatus; +int c; +int fnameindex=lua_gettop(L)+1; +lf.extraline=0; +if(filename==NULL){ +lua_pushliteral(L,"=stdin"); +lf.f=stdin; +} +else{ +lua_pushfstring(L,"@%s",filename); +lf.f=fopen(filename,"r"); +if(lf.f==NULL)return errfile(L,"open",fnameindex); +} +c=getc(lf.f); +if(c=='#'){ +lf.extraline=1; +while((c=getc(lf.f))!=EOF&&c!='\n'); +if(c=='\n')c=getc(lf.f); +} +if(c=="\033Lua"[0]&&filename){ +lf.f=freopen(filename,"rb",lf.f); +if(lf.f==NULL)return errfile(L,"reopen",fnameindex); +while((c=getc(lf.f))!=EOF&&c!="\033Lua"[0]); +lf.extraline=0; +} +ungetc(c,lf.f); +status=lua_load(L,getF,&lf,lua_tostring(L,-1)); +readstatus=ferror(lf.f); +if(filename)fclose(lf.f); +if(readstatus){ +lua_settop(L,fnameindex); +return errfile(L,"read",fnameindex); +} +lua_remove(L,fnameindex); +return status; +} +typedef struct LoadS{ +const char*s; +size_t size; +}LoadS; +static const char*getS(lua_State*L,void*ud,size_t*size){ +LoadS*ls=(LoadS*)ud; +(void)L; +if(ls->size==0)return NULL; +*size=ls->size; +ls->size=0; +return ls->s; +} +static int luaL_loadbuffer(lua_State*L,const char*buff,size_t size, +const char*name){ +LoadS ls; +ls.s=buff; +ls.size=size; +return lua_load(L,getS,&ls,name); +} +static void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){ +(void)ud; +(void)osize; +if(nsize==0){ +free(ptr); +return NULL; +} +else +return realloc(ptr,nsize); +} +static int panic(lua_State*L){ +(void)L; +fprintf(stderr,"PANIC: unprotected error in call to Lua API (%s)\n", +lua_tostring(L,-1)); +return 0; +} +static lua_State*luaL_newstate(void){ +lua_State*L=lua_newstate(l_alloc,NULL); +if(L)lua_atpanic(L,&panic); +return L; +} +static int luaB_tonumber(lua_State*L){ +int base=luaL_optint(L,2,10); +if(base==10){ +luaL_checkany(L,1); +if(lua_isnumber(L,1)){ +lua_pushnumber(L,lua_tonumber(L,1)); +return 1; +} +} +else{ +const char*s1=luaL_checkstring(L,1); +char*s2; +unsigned long n; +luaL_argcheck(L,2<=base&&base<=36,2,"base out of range"); +n=strtoul(s1,&s2,base); +if(s1!=s2){ +while(isspace((unsigned char)(*s2)))s2++; +if(*s2=='\0'){ +lua_pushnumber(L,(lua_Number)n); +return 1; +} +} +} +lua_pushnil(L); +return 1; +} +static int luaB_error(lua_State*L){ +int level=luaL_optint(L,2,1); +lua_settop(L,1); +if(lua_isstring(L,1)&&level>0){ +luaL_where(L,level); +lua_pushvalue(L,1); +lua_concat(L,2); +} +return lua_error(L); +} +static int luaB_setmetatable(lua_State*L){ +int t=lua_type(L,2); +luaL_checktype(L,1,5); +luaL_argcheck(L,t==0||t==5,2, +"nil or table expected"); +if(luaL_getmetafield(L,1,"__metatable")) +luaL_error(L,"cannot change a protected metatable"); +lua_settop(L,2); +lua_setmetatable(L,1); +return 1; +} +static void getfunc(lua_State*L,int opt){ +if(lua_isfunction(L,1))lua_pushvalue(L,1); +else{ +lua_Debug ar; +int level=opt?luaL_optint(L,1,1):luaL_checkint(L,1); +luaL_argcheck(L,level>=0,1,"level must be non-negative"); +if(lua_getstack(L,level,&ar)==0) +luaL_argerror(L,1,"invalid level"); +lua_getinfo(L,"f",&ar); +if(lua_isnil(L,-1)) +luaL_error(L,"no function environment for tail call at level %d", +level); +} +} +static int luaB_setfenv(lua_State*L){ +luaL_checktype(L,2,5); +getfunc(L,0); +lua_pushvalue(L,2); +if(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){ +lua_pushthread(L); +lua_insert(L,-2); +lua_setfenv(L,-2); +return 0; +} +else if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0) +luaL_error(L, +LUA_QL("setfenv")" cannot change environment of given object"); +return 1; +} +static int luaB_rawget(lua_State*L){ +luaL_checktype(L,1,5); +luaL_checkany(L,2); +lua_settop(L,2); +lua_rawget(L,1); +return 1; +} +static int luaB_type(lua_State*L){ +luaL_checkany(L,1); +lua_pushstring(L,luaL_typename(L,1)); +return 1; +} +static int luaB_next(lua_State*L){ +luaL_checktype(L,1,5); +lua_settop(L,2); +if(lua_next(L,1)) +return 2; +else{ +lua_pushnil(L); +return 1; +} +} +static int luaB_pairs(lua_State*L){ +luaL_checktype(L,1,5); +lua_pushvalue(L,lua_upvalueindex(1)); +lua_pushvalue(L,1); +lua_pushnil(L); +return 3; +} +static int ipairsaux(lua_State*L){ +int i=luaL_checkint(L,2); +luaL_checktype(L,1,5); +i++; +lua_pushinteger(L,i); +lua_rawgeti(L,1,i); +return(lua_isnil(L,-1))?0:2; +} +static int luaB_ipairs(lua_State*L){ +luaL_checktype(L,1,5); +lua_pushvalue(L,lua_upvalueindex(1)); +lua_pushvalue(L,1); +lua_pushinteger(L,0); +return 3; +} +static int load_aux(lua_State*L,int status){ +if(status==0) +return 1; +else{ +lua_pushnil(L); +lua_insert(L,-2); +return 2; +} +} +static int luaB_loadstring(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +const char*chunkname=luaL_optstring(L,2,s); +return load_aux(L,luaL_loadbuffer(L,s,l,chunkname)); +} +static int luaB_loadfile(lua_State*L){ +const char*fname=luaL_optstring(L,1,NULL); +return load_aux(L,luaL_loadfile(L,fname)); +} +static int luaB_assert(lua_State*L){ +luaL_checkany(L,1); +if(!lua_toboolean(L,1)) +return luaL_error(L,"%s",luaL_optstring(L,2,"assertion failed!")); +return lua_gettop(L); +} +static int luaB_unpack(lua_State*L){ +int i,e,n; +luaL_checktype(L,1,5); +i=luaL_optint(L,2,1); +e=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1)); +if(i>e)return 0; +n=e-i+1; +if(n<=0||!lua_checkstack(L,n)) +return luaL_error(L,"too many results to unpack"); +lua_rawgeti(L,1,i); +while(i++e)e=pos; +for(i=e;i>pos;i--){ +lua_rawgeti(L,1,i-1); +lua_rawseti(L,1,i); +} +break; +} +default:{ +return luaL_error(L,"wrong number of arguments to "LUA_QL("insert")); +} +} +luaL_setn(L,1,e); +lua_rawseti(L,1,pos); +return 0; +} +static int tremove(lua_State*L){ +int e=aux_getn(L,1); +int pos=luaL_optint(L,2,e); +if(!(1<=pos&&pos<=e)) +return 0; +luaL_setn(L,1,e-1); +lua_rawgeti(L,1,pos); +for(;posu)luaL_error(L,"invalid order function for sorting"); +lua_pop(L,1); +} +while(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){ +if(j0); +} +l=strlen(p); +if(l==0||p[l-1]!='\n') +luaL_addsize(&b,l); +else{ +luaL_addsize(&b,l-1); +luaL_pushresult(&b); +return 1; +} +} +} +static int read_chars(lua_State*L,FILE*f,size_t n){ +size_t rlen; +size_t nr; +luaL_Buffer b; +luaL_buffinit(L,&b); +rlen=BUFSIZ; +do{ +char*p=luaL_prepbuffer(&b); +if(rlen>n)rlen=n; +nr=fread(p,sizeof(char),rlen,f); +luaL_addsize(&b,nr); +n-=nr; +}while(n>0&&nr==rlen); +luaL_pushresult(&b); +return(n==0||lua_objlen(L,-1)>0); +} +static int g_read(lua_State*L,FILE*f,int first){ +int nargs=lua_gettop(L)-1; +int success; +int n; +clearerr(f); +if(nargs==0){ +success=read_line(L,f); +n=first+1; +} +else{ +luaL_checkstack(L,nargs+20,"too many arguments"); +success=1; +for(n=first;nargs--&&success;n++){ +if(lua_type(L,n)==3){ +size_t l=(size_t)lua_tointeger(L,n); +success=(l==0)?test_eof(L,f):read_chars(L,f,l); +} +else{ +const char*p=lua_tostring(L,n); +luaL_argcheck(L,p&&p[0]=='*',n,"invalid option"); +switch(p[1]){ +case'n': +success=read_number(L,f); +break; +case'l': +success=read_line(L,f); +break; +case'a': +read_chars(L,f,~((size_t)0)); +success=1; +break; +default: +return luaL_argerror(L,n,"invalid format"); +} +} +} +} +if(ferror(f)) +return pushresult(L,0,NULL); +if(!success){ +lua_pop(L,1); +lua_pushnil(L); +} +return n-first; +} +static int io_read(lua_State*L){ +return g_read(L,getiofile(L,1),1); +} +static int f_read(lua_State*L){ +return g_read(L,tofile(L),2); +} +static int io_readline(lua_State*L){ +FILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1)); +int sucess; +if(f==NULL) +luaL_error(L,"file is already closed"); +sucess=read_line(L,f); +if(ferror(f)) +return luaL_error(L,"%s",strerror(errno)); +if(sucess)return 1; +else{ +if(lua_toboolean(L,lua_upvalueindex(2))){ +lua_settop(L,0); +lua_pushvalue(L,lua_upvalueindex(1)); +aux_close(L); +} +return 0; +} +} +static int g_write(lua_State*L,FILE*f,int arg){ +int nargs=lua_gettop(L)-1; +int status=1; +for(;nargs--;arg++){ +if(lua_type(L,arg)==3){ +status=status&& +fprintf(f,"%.14g",lua_tonumber(L,arg))>0; +} +else{ +size_t l; +const char*s=luaL_checklstring(L,arg,&l); +status=status&&(fwrite(s,sizeof(char),l,f)==l); +} +} +return pushresult(L,status,NULL); +} +static int io_write(lua_State*L){ +return g_write(L,getiofile(L,2),1); +} +static int f_write(lua_State*L){ +return g_write(L,tofile(L),2); +} +static int io_flush(lua_State*L){ +return pushresult(L,fflush(getiofile(L,2))==0,NULL); +} +static int f_flush(lua_State*L){ +return pushresult(L,fflush(tofile(L))==0,NULL); +} +static const luaL_Reg iolib[]={ +{"close",io_close}, +{"flush",io_flush}, +{"input",io_input}, +{"lines",io_lines}, +{"open",io_open}, +{"output",io_output}, +{"read",io_read}, +{"type",io_type}, +{"write",io_write}, +{NULL,NULL} +}; +static const luaL_Reg flib[]={ +{"close",io_close}, +{"flush",f_flush}, +{"lines",f_lines}, +{"read",f_read}, +{"write",f_write}, +{"__gc",io_gc}, +{NULL,NULL} +}; +static void createmeta(lua_State*L){ +luaL_newmetatable(L,"FILE*"); +lua_pushvalue(L,-1); +lua_setfield(L,-2,"__index"); +luaL_register(L,NULL,flib); +} +static void createstdfile(lua_State*L,FILE*f,int k,const char*fname){ +*newfile(L)=f; +if(k>0){ +lua_pushvalue(L,-1); +lua_rawseti(L,(-10001),k); +} +lua_pushvalue(L,-2); +lua_setfenv(L,-2); +lua_setfield(L,-3,fname); +} +static void newfenv(lua_State*L,lua_CFunction cls){ +lua_createtable(L,0,1); +lua_pushcfunction(L,cls); +lua_setfield(L,-2,"__close"); +} +static int luaopen_io(lua_State*L){ +createmeta(L); +newfenv(L,io_fclose); +lua_replace(L,(-10001)); +luaL_register(L,"io",iolib); +newfenv(L,io_noclose); +createstdfile(L,stdin,1,"stdin"); +createstdfile(L,stdout,2,"stdout"); +createstdfile(L,stderr,0,"stderr"); +lua_pop(L,1); +lua_getfield(L,-1,"popen"); +newfenv(L,io_pclose); +lua_setfenv(L,-2); +lua_pop(L,1); +return 1; +} +static int os_pushresult(lua_State*L,int i,const char*filename){ +int en=errno; +if(i){ +lua_pushboolean(L,1); +return 1; +} +else{ +lua_pushnil(L); +lua_pushfstring(L,"%s: %s",filename,strerror(en)); +lua_pushinteger(L,en); +return 3; +} +} +static int os_remove(lua_State*L){ +const char*filename=luaL_checkstring(L,1); +return os_pushresult(L,remove(filename)==0,filename); +} +static int os_exit(lua_State*L){ +exit(luaL_optint(L,1,EXIT_SUCCESS)); +} +static const luaL_Reg syslib[]={ +{"exit",os_exit}, +{"remove",os_remove}, +{NULL,NULL} +}; +static int luaopen_os(lua_State*L){ +luaL_register(L,"os",syslib); +return 1; +} +#define uchar(c)((unsigned char)(c)) +static ptrdiff_t posrelat(ptrdiff_t pos,size_t len){ +if(pos<0)pos+=(ptrdiff_t)len+1; +return(pos>=0)?pos:0; +} +static int str_sub(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +ptrdiff_t start=posrelat(luaL_checkinteger(L,2),l); +ptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l); +if(start<1)start=1; +if(end>(ptrdiff_t)l)end=(ptrdiff_t)l; +if(start<=end) +lua_pushlstring(L,s+start-1,end-start+1); +else lua_pushliteral(L,""); +return 1; +} +static int str_lower(lua_State*L){ +size_t l; +size_t i; +luaL_Buffer b; +const char*s=luaL_checklstring(L,1,&l); +luaL_buffinit(L,&b); +for(i=0;i0) +luaL_addlstring(&b,s,l); +luaL_pushresult(&b); +return 1; +} +static int str_byte(lua_State*L){ +size_t l; +const char*s=luaL_checklstring(L,1,&l); +ptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l); +ptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l); +int n,i; +if(posi<=0)posi=1; +if((size_t)pose>l)pose=l; +if(posi>pose)return 0; +n=(int)(pose-posi+1); +if(posi+n<=pose) +luaL_error(L,"string slice too long"); +luaL_checkstack(L,n,"string slice too long"); +for(i=0;i=ms->level||ms->capture[l].len==(-1)) +return luaL_error(ms->L,"invalid capture index"); +return l; +} +static int capture_to_close(MatchState*ms){ +int level=ms->level; +for(level--;level>=0;level--) +if(ms->capture[level].len==(-1))return level; +return luaL_error(ms->L,"invalid pattern capture"); +} +static const char*classend(MatchState*ms,const char*p){ +switch(*p++){ +case'%':{ +if(*p=='\0') +luaL_error(ms->L,"malformed pattern (ends with "LUA_QL("%%")")"); +return p+1; +} +case'[':{ +if(*p=='^')p++; +do{ +if(*p=='\0') +luaL_error(ms->L,"malformed pattern (missing "LUA_QL("]")")"); +if(*(p++)=='%'&&*p!='\0') +p++; +}while(*p!=']'); +return p+1; +} +default:{ +return p; +} +} +} +static int match_class(int c,int cl){ +int res; +switch(tolower(cl)){ +case'a':res=isalpha(c);break; +case'c':res=iscntrl(c);break; +case'd':res=isdigit(c);break; +case'l':res=islower(c);break; +case'p':res=ispunct(c);break; +case's':res=isspace(c);break; +case'u':res=isupper(c);break; +case'w':res=isalnum(c);break; +case'x':res=isxdigit(c);break; +case'z':res=(c==0);break; +default:return(cl==c); +} +return(islower(cl)?res:!res); +} +static int matchbracketclass(int c,const char*p,const char*ec){ +int sig=1; +if(*(p+1)=='^'){ +sig=0; +p++; +} +while(++pL,"unbalanced pattern"); +if(*s!=*p)return NULL; +else{ +int b=*p; +int e=*(p+1); +int cont=1; +while(++ssrc_end){ +if(*s==e){ +if(--cont==0)return s+1; +} +else if(*s==b)cont++; +} +} +return NULL; +} +static const char*max_expand(MatchState*ms,const char*s, +const char*p,const char*ep){ +ptrdiff_t i=0; +while((s+i)src_end&&singlematch(uchar(*(s+i)),p,ep)) +i++; +while(i>=0){ +const char*res=match(ms,(s+i),ep+1); +if(res)return res; +i--; +} +return NULL; +} +static const char*min_expand(MatchState*ms,const char*s, +const char*p,const char*ep){ +for(;;){ +const char*res=match(ms,s,ep+1); +if(res!=NULL) +return res; +else if(ssrc_end&&singlematch(uchar(*s),p,ep)) +s++; +else return NULL; +} +} +static const char*start_capture(MatchState*ms,const char*s, +const char*p,int what){ +const char*res; +int level=ms->level; +if(level>=32)luaL_error(ms->L,"too many captures"); +ms->capture[level].init=s; +ms->capture[level].len=what; +ms->level=level+1; +if((res=match(ms,s,p))==NULL) +ms->level--; +return res; +} +static const char*end_capture(MatchState*ms,const char*s, +const char*p){ +int l=capture_to_close(ms); +const char*res; +ms->capture[l].len=s-ms->capture[l].init; +if((res=match(ms,s,p))==NULL) +ms->capture[l].len=(-1); +return res; +} +static const char*match_capture(MatchState*ms,const char*s,int l){ +size_t len; +l=check_capture(ms,l); +len=ms->capture[l].len; +if((size_t)(ms->src_end-s)>=len&& +memcmp(ms->capture[l].init,s,len)==0) +return s+len; +else return NULL; +} +static const char*match(MatchState*ms,const char*s,const char*p){ +init: +switch(*p){ +case'(':{ +if(*(p+1)==')') +return start_capture(ms,s,p+2,(-2)); +else +return start_capture(ms,s,p+1,(-1)); +} +case')':{ +return end_capture(ms,s,p+1); +} +case'%':{ +switch(*(p+1)){ +case'b':{ +s=matchbalance(ms,s,p+2); +if(s==NULL)return NULL; +p+=4;goto init; +} +case'f':{ +const char*ep;char previous; +p+=2; +if(*p!='[') +luaL_error(ms->L,"missing "LUA_QL("[")" after " +LUA_QL("%%f")" in pattern"); +ep=classend(ms,p); +previous=(s==ms->src_init)?'\0':*(s-1); +if(matchbracketclass(uchar(previous),p,ep-1)|| +!matchbracketclass(uchar(*s),p,ep-1))return NULL; +p=ep;goto init; +} +default:{ +if(isdigit(uchar(*(p+1)))){ +s=match_capture(ms,s,uchar(*(p+1))); +if(s==NULL)return NULL; +p+=2;goto init; +} +goto dflt; +} +} +} +case'\0':{ +return s; +} +case'$':{ +if(*(p+1)=='\0') +return(s==ms->src_end)?s:NULL; +else goto dflt; +} +default:dflt:{ +const char*ep=classend(ms,p); +int m=ssrc_end&&singlematch(uchar(*s),p,ep); +switch(*ep){ +case'?':{ +const char*res; +if(m&&((res=match(ms,s+1,ep+1))!=NULL)) +return res; +p=ep+1;goto init; +} +case'*':{ +return max_expand(ms,s,p,ep); +} +case'+':{ +return(m?max_expand(ms,s+1,p,ep):NULL); +} +case'-':{ +return min_expand(ms,s,p,ep); +} +default:{ +if(!m)return NULL; +s++;p=ep;goto init; +} +} +} +} +} +static const char*lmemfind(const char*s1,size_t l1, +const char*s2,size_t l2){ +if(l2==0)return s1; +else if(l2>l1)return NULL; +else{ +const char*init; +l2--; +l1=l1-l2; +while(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){ +init++; +if(memcmp(init,s2+1,l2)==0) +return init-1; +else{ +l1-=init-s1; +s1=init; +} +} +return NULL; +} +} +static void push_onecapture(MatchState*ms,int i,const char*s, +const char*e){ +if(i>=ms->level){ +if(i==0) +lua_pushlstring(ms->L,s,e-s); +else +luaL_error(ms->L,"invalid capture index"); +} +else{ +ptrdiff_t l=ms->capture[i].len; +if(l==(-1))luaL_error(ms->L,"unfinished capture"); +if(l==(-2)) +lua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1); +else +lua_pushlstring(ms->L,ms->capture[i].init,l); +} +} +static int push_captures(MatchState*ms,const char*s,const char*e){ +int i; +int nlevels=(ms->level==0&&s)?1:ms->level; +luaL_checkstack(ms->L,nlevels,"too many captures"); +for(i=0;il1)init=(ptrdiff_t)l1; +if(find&&(lua_toboolean(L,4)|| +strpbrk(p,"^$*+?.([%-")==NULL)){ +const char*s2=lmemfind(s+init,l1-init,p,l2); +if(s2){ +lua_pushinteger(L,s2-s+1); +lua_pushinteger(L,s2-s+l2); +return 2; +} +} +else{ +MatchState ms; +int anchor=(*p=='^')?(p++,1):0; +const char*s1=s+init; +ms.L=L; +ms.src_init=s; +ms.src_end=s+l1; +do{ +const char*res; +ms.level=0; +if((res=match(&ms,s1,p))!=NULL){ +if(find){ +lua_pushinteger(L,s1-s+1); +lua_pushinteger(L,res-s); +return push_captures(&ms,NULL,0)+2; +} +else +return push_captures(&ms,s1,res); +} +}while(s1++L,3,&l); +for(i=0;iL; +switch(lua_type(L,3)){ +case 3: +case 4:{ +add_s(ms,b,s,e); +return; +} +case 6:{ +int n; +lua_pushvalue(L,3); +n=push_captures(ms,s,e); +lua_call(L,n,1); +break; +} +case 5:{ +push_onecapture(ms,0,s,e); +lua_gettable(L,3); +break; +} +} +if(!lua_toboolean(L,-1)){ +lua_pop(L,1); +lua_pushlstring(L,s,e-s); +} +else if(!lua_isstring(L,-1)) +luaL_error(L,"invalid replacement value (a %s)",luaL_typename(L,-1)); +luaL_addvalue(b); +} +static int str_gsub(lua_State*L){ +size_t srcl; +const char*src=luaL_checklstring(L,1,&srcl); +const char*p=luaL_checkstring(L,2); +int tr=lua_type(L,3); +int max_s=luaL_optint(L,4,srcl+1); +int anchor=(*p=='^')?(p++,1):0; +int n=0; +MatchState ms; +luaL_Buffer b; +luaL_argcheck(L,tr==3||tr==4|| +tr==6||tr==5,3, +"string/function/table expected"); +luaL_buffinit(L,&b); +ms.L=L; +ms.src_init=src; +ms.src_end=src+srcl; +while(nsrc) +src=e; +else if(src=sizeof("-+ #0")) +luaL_error(L,"invalid format (repeated flags)"); +if(isdigit(uchar(*p)))p++; +if(isdigit(uchar(*p)))p++; +if(*p=='.'){ +p++; +if(isdigit(uchar(*p)))p++; +if(isdigit(uchar(*p)))p++; +} +if(isdigit(uchar(*p))) +luaL_error(L,"invalid format (width or precision too long)"); +*(form++)='%'; +strncpy(form,strfrmt,p-strfrmt+1); +form+=p-strfrmt+1; +*form='\0'; +return p; +} +static void addintlen(char*form){ +size_t l=strlen(form); +char spec=form[l-1]; +strcpy(form+l-1,"l"); +form[l+sizeof("l")-2]=spec; +form[l+sizeof("l")-1]='\0'; +} +static int str_format(lua_State*L){ +int top=lua_gettop(L); +int arg=1; +size_t sfl; +const char*strfrmt=luaL_checklstring(L,arg,&sfl); +const char*strfrmt_end=strfrmt+sfl; +luaL_Buffer b; +luaL_buffinit(L,&b); +while(strfrmttop) +luaL_argerror(L,arg,"no value"); +strfrmt=scanformat(L,strfrmt,form); +switch(*strfrmt++){ +case'c':{ +sprintf(buff,form,(int)luaL_checknumber(L,arg)); +break; +} +case'd':case'i':{ +addintlen(form); +sprintf(buff,form,(long)luaL_checknumber(L,arg)); +break; +} +case'o':case'u':case'x':case'X':{ +addintlen(form); +sprintf(buff,form,(unsigned long)luaL_checknumber(L,arg)); +break; +} +case'e':case'E':case'f': +case'g':case'G':{ +sprintf(buff,form,(double)luaL_checknumber(L,arg)); +break; +} +case'q':{ +addquoted(L,&b,arg); +continue; +} +case's':{ +size_t l; +const char*s=luaL_checklstring(L,arg,&l); +if(!strchr(form,'.')&&l>=100){ +lua_pushvalue(L,arg); +luaL_addvalue(&b); +continue; +} +else{ +sprintf(buff,form,s); +break; +} +} +default:{ +return luaL_error(L,"invalid option "LUA_QL("%%%c")" to " +LUA_QL("format"),*(strfrmt-1)); +} +} +luaL_addlstring(&b,buff,strlen(buff)); +} +} +luaL_pushresult(&b); +return 1; +} +static const luaL_Reg strlib[]={ +{"byte",str_byte}, +{"char",str_char}, +{"find",str_find}, +{"format",str_format}, +{"gmatch",gmatch}, +{"gsub",str_gsub}, +{"lower",str_lower}, +{"match",str_match}, +{"rep",str_rep}, +{"sub",str_sub}, +{"upper",str_upper}, +{NULL,NULL} +}; +static void createmetatable(lua_State*L){ +lua_createtable(L,0,1); +lua_pushliteral(L,""); +lua_pushvalue(L,-2); +lua_setmetatable(L,-2); +lua_pop(L,1); +lua_pushvalue(L,-2); +lua_setfield(L,-2,"__index"); +lua_pop(L,1); +} +static int luaopen_string(lua_State*L){ +luaL_register(L,"string",strlib); +createmetatable(L); +return 1; +} +static const luaL_Reg lualibs[]={ +{"",luaopen_base}, +{"table",luaopen_table}, +{"io",luaopen_io}, +{"os",luaopen_os}, +{"string",luaopen_string}, +{NULL,NULL} +}; +static void luaL_openlibs(lua_State*L){ +const luaL_Reg*lib=lualibs; +for(;lib->func;lib++){ +lua_pushcfunction(L,lib->func); +lua_pushstring(L,lib->name); +lua_call(L,1,0); +} +} +typedef unsigned int UB; +static UB barg(lua_State*L,int idx){ +union{lua_Number n;U64 b;}bn; +bn.n=lua_tonumber(L,idx)+6755399441055744.0; +if(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number"); +return(UB)bn.b; +} +#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1; +static int tobit(lua_State*L){ +BRET(barg(L,1))} +static int bnot(lua_State*L){ +BRET(~barg(L,1))} +static int band(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)} +static int bor(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)} +static int bxor(lua_State*L){ +int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)} +static int lshift(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET(b<>n)} +static int arshift(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)} +static int rol(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b<>(32-n)))} +static int ror(lua_State*L){ +UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))} +static int bswap(lua_State*L){ +UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} +static int tohex(lua_State*L){ +UB b=barg(L,1); +int n=lua_isnone(L,2)?8:(int)barg(L,2); +const char*hexdigits="0123456789abcdef"; +char buf[8]; +int i; +if(n<0){n=-n;hexdigits="0123456789ABCDEF";} +if(n>8)n=8; +for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} +lua_pushlstring(L,buf,(size_t)n); +return 1; +} +static const struct luaL_Reg bitlib[]={ +{"tobit",tobit}, +{"bnot",bnot}, +{"band",band}, +{"bor",bor}, +{"bxor",bxor}, +{"lshift",lshift}, +{"rshift",rshift}, +{"arshift",arshift}, +{"rol",rol}, +{"ror",ror}, +{"bswap",bswap}, +{"tohex",tohex}, +{NULL,NULL} +}; +int main(int argc,char**argv){ +lua_State*L=luaL_newstate(); +int i; +luaL_openlibs(L); +luaL_register(L,"bit",bitlib); +if(argc<2)return sizeof(void*); +lua_createtable(L,0,1); +lua_pushstring(L,argv[1]); +lua_rawseti(L,-2,0); +lua_setglobal(L,"arg"); +if(luaL_loadfile(L,argv[1])) +goto err; +for(i=2;i -- BYTECODE -- [...] +-- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello" +-- +-- local out = { +-- -- Do something with each line: +-- write = function(t, ...) io.write(...) end, +-- close = function(t) end, +-- flush = function(t) end, +-- } +-- bc.dump(foo, out) +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local bit = require("bit") +local sub, gsub, format = string.sub, string.gsub, string.format +local byte, band, shr = string.byte, bit.band, bit.rshift +local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck +local funcuvname = jutil.funcuvname +local bcnames = vmdef.bcnames +local stdout, stderr = io.stdout, io.stderr + +------------------------------------------------------------------------------ + +local function ctlsub(c) + if c == "\n" then return "\\n" + elseif c == "\r" then return "\\r" + elseif c == "\t" then return "\\t" + else return format("\\%03d", byte(c)) + end +end + +-- Return one bytecode line. +local function bcline(func, pc, prefix) + local ins, m = funcbc(func, pc) + if not ins then return end + local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128) + local a = band(shr(ins, 8), 0xff) + local oidx = 6*band(ins, 0xff) + local op = sub(bcnames, oidx+1, oidx+6) + local s = format("%04d %s %-6s %3s ", + pc, prefix or " ", op, ma == 0 and "" or a) + local d = shr(ins, 16) + if mc == 13*128 then -- BCMjump + return format("%s=> %04d\n", s, pc+d-0x7fff) + end + if mb ~= 0 then + d = band(d, 0xff) + elseif mc == 0 then + return s.."\n" + end + local kc + if mc == 10*128 then -- BCMstr + kc = funck(func, -d-1) + kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub)) + elseif mc == 9*128 then -- BCMnum + kc = funck(func, d) + if op == "TSETM " then kc = kc - 2^52 end + elseif mc == 12*128 then -- BCMfunc + local fi = funcinfo(funck(func, -d-1)) + if fi.ffid then + kc = vmdef.ffnames[fi.ffid] + else + kc = fi.loc + end + elseif mc == 5*128 then -- BCMuv + kc = funcuvname(func, d) + end + if ma == 5 then -- BCMuv + local ka = funcuvname(func, a) + if kc then kc = ka.." ; "..kc else kc = ka end + end + if mb ~= 0 then + local b = shr(ins, 24) + if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end + return format("%s%3d %3d\n", s, b, d) + end + if kc then return format("%s%3d ; %s\n", s, d, kc) end + if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits + return format("%s%3d\n", s, d) +end + +-- Collect branch targets of a function. +local function bctargets(func) + local target = {} + for pc=1,1000000000 do + local ins, m = funcbc(func, pc) + if not ins then break end + if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end + end + return target +end + +-- Dump bytecode instructions of a function. +local function bcdump(func, out, all) + if not out then out = stdout end + local fi = funcinfo(func) + if all and fi.children then + for n=-1,-1000000000,-1 do + local k = funck(func, n) + if not k then break end + if type(k) == "proto" then bcdump(k, out, true) end + end + end + out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined)) + local target = bctargets(func) + for pc=1,1000000000 do + local s = bcline(func, pc, target[pc] and "=>") + if not s then break end + out:write(s) + end + out:write("\n") + out:flush() +end + +------------------------------------------------------------------------------ + +-- Active flag and output file handle. +local active, out + +-- List handler. +local function h_list(func) + return bcdump(func, out) +end + +-- Detach list handler. +local function bclistoff() + if active then + active = false + jit.attach(h_list) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach list handler. +local function bcliston(outfile) + if active then bclistoff() end + if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stderr + end + jit.attach(h_list, "bc") + active = true +end + +-- Public module functions. +module(...) + +line = bcline +dump = bcdump +targets = bctargets + +on = bcliston +off = bclistoff +start = bcliston -- For -j command line option. + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/bcsave.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/bcsave.lua new file mode 100644 index 0000000..f55bda9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/bcsave.lua @@ -0,0 +1,659 @@ +---------------------------------------------------------------------------- +-- LuaJIT module to save/list bytecode. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module saves or lists the bytecode for an input file. +-- It's run by the -b command line option. +-- +------------------------------------------------------------------------------ + +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local bit = require("bit") + +-- Symbol name prefix for LuaJIT bytecode. +local LJBC_PREFIX = "luaJIT_BC_" + +------------------------------------------------------------------------------ + +local function usage() + io.stderr:write[[ +Save LuaJIT bytecode: luajit -b[options] input output + -l Only list bytecode. + -s Strip debug info (default). + -g Keep debug info. + -n name Set module name (default: auto-detect from input name). + -t type Set output file type (default: auto-detect from output name). + -a arch Override architecture for object files (default: native). + -o os Override OS for object files (default: native). + -e chunk Use chunk string as input. + -- Stop handling options. + - Use stdin as input and/or stdout as output. + +File types: c h obj o raw (default) +]] + os.exit(1) +end + +local function check(ok, ...) + if ok then return ok, ... end + io.stderr:write("luajit: ", ...) + io.stderr:write("\n") + os.exit(1) +end + +local function readfile(input) + if type(input) == "function" then return input end + if input == "-" then input = nil end + return check(loadfile(input)) +end + +local function savefile(name, mode) + if name == "-" then return io.stdout end + return check(io.open(name, mode)) +end + +------------------------------------------------------------------------------ + +local map_type = { + raw = "raw", c = "c", h = "h", o = "obj", obj = "obj", +} + +local map_arch = { + x86 = true, x64 = true, arm = true, ppc = true, ppcspe = true, + mips = true, mipsel = true, +} + +local map_os = { + linux = true, windows = true, osx = true, freebsd = true, netbsd = true, + openbsd = true, solaris = true, +} + +local function checkarg(str, map, err) + str = string.lower(str) + local s = check(map[str], "unknown ", err) + return s == true and str or s +end + +local function detecttype(str) + local ext = string.match(string.lower(str), "%.(%a+)$") + return map_type[ext] or "raw" +end + +local function checkmodname(str) + check(string.match(str, "^[%w_.%-]+$"), "bad module name") + return string.gsub(str, "[%.%-]", "_") +end + +local function detectmodname(str) + if type(str) == "string" then + local tail = string.match(str, "[^/\\]+$") + if tail then str = tail end + local head = string.match(str, "^(.*)%.[^.]*$") + if head then str = head end + str = string.match(str, "^[%w_.%-]+") + else + str = nil + end + check(str, "cannot derive module name, use -n name") + return string.gsub(str, "[%.%-]", "_") +end + +------------------------------------------------------------------------------ + +local function bcsave_tail(fp, output, s) + local ok, err = fp:write(s) + if ok and output ~= "-" then ok, err = fp:close() end + check(ok, "cannot write ", output, ": ", err) +end + +local function bcsave_raw(output, s) + local fp = savefile(output, "wb") + bcsave_tail(fp, output, s) +end + +local function bcsave_c(ctx, output, s) + local fp = savefile(output, "w") + if ctx.type == "c" then + fp:write(string.format([[ +#ifdef _cplusplus +extern "C" +#endif +#ifdef _WIN32 +__declspec(dllexport) +#endif +const char %s%s[] = { +]], LJBC_PREFIX, ctx.modname)) + else + fp:write(string.format([[ +#define %s%s_SIZE %d +static const char %s%s[] = { +]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname)) + end + local t, n, m = {}, 0, 0 + for i=1,#s do + local b = tostring(string.byte(s, i)) + m = m + #b + 1 + if m > 78 then + fp:write(table.concat(t, ",", 1, n), ",\n") + n, m = 0, #b + 1 + end + n = n + 1 + t[n] = b + end + bcsave_tail(fp, output, table.concat(t, ",", 1, n).."\n};\n") +end + +local function bcsave_elfobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct { + uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7]; + uint16_t type, machine; + uint32_t version; + uint32_t entry, phofs, shofs; + uint32_t flags; + uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx; +} ELF32header; +typedef struct { + uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7]; + uint16_t type, machine; + uint32_t version; + uint64_t entry, phofs, shofs; + uint32_t flags; + uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx; +} ELF64header; +typedef struct { + uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize; +} ELF32sectheader; +typedef struct { + uint32_t name, type; + uint64_t flags, addr, ofs, size; + uint32_t link, info; + uint64_t align, entsize; +} ELF64sectheader; +typedef struct { + uint32_t name, value, size; + uint8_t info, other; + uint16_t sectidx; +} ELF32symbol; +typedef struct { + uint32_t name; + uint8_t info, other; + uint16_t sectidx; + uint64_t value, size; +} ELF64symbol; +typedef struct { + ELF32header hdr; + ELF32sectheader sect[6]; + ELF32symbol sym[2]; + uint8_t space[4096]; +} ELF32obj; +typedef struct { + ELF64header hdr; + ELF64sectheader sect[6]; + ELF64symbol sym[2]; + uint8_t space[4096]; +} ELF64obj; +]] + local symname = LJBC_PREFIX..ctx.modname + local is64, isbe = false, false + if ctx.arch == "x64" then + is64 = true + elseif ctx.arch == "ppc" or ctx.arch == "ppcspe" or ctx.arch == "mips" then + isbe = true + end + + -- Handle different host/target endianess. + local function f32(x) return x end + local f16, fofs = f32, f32 + if ffi.abi("be") ~= isbe then + f32 = bit.bswap + function f16(x) return bit.rshift(bit.bswap(x), 16) end + if is64 then + local two32 = ffi.cast("int64_t", 2^32) + function fofs(x) return bit.bswap(x)*two32 end + else + fofs = f32 + end + end + + -- Create ELF object and fill in header. + local o = ffi.new(is64 and "ELF64obj" or "ELF32obj") + local hdr = o.hdr + if ctx.os == "bsd" or ctx.os == "other" then -- Determine native hdr.eosabi. + local bf = assert(io.open("/bin/ls", "rb")) + local bs = bf:read(9) + bf:close() + ffi.copy(o, bs, 9) + check(hdr.emagic[0] == 127, "no support for writing native object files") + else + hdr.emagic = "\127ELF" + hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0 + end + hdr.eclass = is64 and 2 or 1 + hdr.eendian = isbe and 2 or 1 + hdr.eversion = 1 + hdr.type = f16(1) + hdr.machine = f16(({ x86=3, x64=62, arm=40, ppc=20, ppcspe=20, mips=8, mipsel=8 })[ctx.arch]) + if ctx.arch == "mips" or ctx.arch == "mipsel" then + hdr.flags = 0x50001006 + end + hdr.version = f32(1) + hdr.shofs = fofs(ffi.offsetof(o, "sect")) + hdr.ehsize = f16(ffi.sizeof(hdr)) + hdr.shentsize = f16(ffi.sizeof(o.sect[0])) + hdr.shnum = f16(6) + hdr.shstridx = f16(2) + + -- Fill in sections and symbols. + local sofs, ofs = ffi.offsetof(o, "space"), 1 + for i,name in ipairs{ + ".symtab", ".shstrtab", ".strtab", ".rodata", ".note.GNU-stack", + } do + local sect = o.sect[i] + sect.align = fofs(1) + sect.name = f32(ofs) + ffi.copy(o.space+ofs, name) + ofs = ofs + #name+1 + end + o.sect[1].type = f32(2) -- .symtab + o.sect[1].link = f32(3) + o.sect[1].info = f32(1) + o.sect[1].align = fofs(8) + o.sect[1].ofs = fofs(ffi.offsetof(o, "sym")) + o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0])) + o.sect[1].size = fofs(ffi.sizeof(o.sym)) + o.sym[1].name = f32(1) + o.sym[1].sectidx = f16(4) + o.sym[1].size = fofs(#s) + o.sym[1].info = 17 + o.sect[2].type = f32(3) -- .shstrtab + o.sect[2].ofs = fofs(sofs) + o.sect[2].size = fofs(ofs) + o.sect[3].type = f32(3) -- .strtab + o.sect[3].ofs = fofs(sofs + ofs) + o.sect[3].size = fofs(#symname+1) + ffi.copy(o.space+ofs+1, symname) + ofs = ofs + #symname + 2 + o.sect[4].type = f32(1) -- .rodata + o.sect[4].flags = fofs(2) + o.sect[4].ofs = fofs(sofs + ofs) + o.sect[4].size = fofs(#s) + o.sect[5].type = f32(1) -- .note.GNU-stack + o.sect[5].ofs = fofs(sofs + ofs + #s) + + -- Write ELF object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs)) + bcsave_tail(fp, output, s) +end + +local function bcsave_peobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct { + uint16_t arch, nsects; + uint32_t time, symtabofs, nsyms; + uint16_t opthdrsz, flags; +} PEheader; +typedef struct { + char name[8]; + uint32_t vsize, vaddr, size, ofs, relocofs, lineofs; + uint16_t nreloc, nline; + uint32_t flags; +} PEsection; +typedef struct __attribute((packed)) { + union { + char name[8]; + uint32_t nameref[2]; + }; + uint32_t value; + int16_t sect; + uint16_t type; + uint8_t scl, naux; +} PEsym; +typedef struct __attribute((packed)) { + uint32_t size; + uint16_t nreloc, nline; + uint32_t cksum; + uint16_t assoc; + uint8_t comdatsel, unused[3]; +} PEsymaux; +typedef struct { + PEheader hdr; + PEsection sect[2]; + // Must be an even number of symbol structs. + PEsym sym0; + PEsymaux sym0aux; + PEsym sym1; + PEsymaux sym1aux; + PEsym sym2; + PEsym sym3; + uint32_t strtabsize; + uint8_t space[4096]; +} PEobj; +]] + local symname = LJBC_PREFIX..ctx.modname + local is64 = false + if ctx.arch == "x86" then + symname = "_"..symname + elseif ctx.arch == "x64" then + is64 = true + end + local symexport = " /EXPORT:"..symname..",DATA " + + -- The file format is always little-endian. Swap if the host is big-endian. + local function f32(x) return x end + local f16 = f32 + if ffi.abi("be") then + f32 = bit.bswap + function f16(x) return bit.rshift(bit.bswap(x), 16) end + end + + -- Create PE object and fill in header. + local o = ffi.new("PEobj") + local hdr = o.hdr + hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2, mips=0x366, mipsel=0x366 })[ctx.arch]) + hdr.nsects = f16(2) + hdr.symtabofs = f32(ffi.offsetof(o, "sym0")) + hdr.nsyms = f32(6) + + -- Fill in sections and symbols. + o.sect[0].name = ".drectve" + o.sect[0].size = f32(#symexport) + o.sect[0].flags = f32(0x00100a00) + o.sym0.sect = f16(1) + o.sym0.scl = 3 + o.sym0.name = ".drectve" + o.sym0.naux = 1 + o.sym0aux.size = f32(#symexport) + o.sect[1].name = ".rdata" + o.sect[1].size = f32(#s) + o.sect[1].flags = f32(0x40300040) + o.sym1.sect = f16(2) + o.sym1.scl = 3 + o.sym1.name = ".rdata" + o.sym1.naux = 1 + o.sym1aux.size = f32(#s) + o.sym2.sect = f16(2) + o.sym2.scl = 2 + o.sym2.nameref[1] = f32(4) + o.sym3.sect = f16(-1) + o.sym3.scl = 2 + o.sym3.value = f32(1) + o.sym3.name = "@feat.00" -- Mark as SafeSEH compliant. + ffi.copy(o.space, symname) + local ofs = #symname + 1 + o.strtabsize = f32(ofs + 4) + o.sect[0].ofs = f32(ffi.offsetof(o, "space") + ofs) + ffi.copy(o.space + ofs, symexport) + ofs = ofs + #symexport + o.sect[1].ofs = f32(ffi.offsetof(o, "space") + ofs) + + -- Write PE object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs)) + bcsave_tail(fp, output, s) +end + +local function bcsave_machobj(ctx, output, s, ffi) + ffi.cdef[[ +typedef struct +{ + uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags; +} mach_header; +typedef struct +{ + mach_header; uint32_t reserved; +} mach_header_64; +typedef struct { + uint32_t cmd, cmdsize; + char segname[16]; + uint32_t vmaddr, vmsize, fileoff, filesize; + uint32_t maxprot, initprot, nsects, flags; +} mach_segment_command; +typedef struct { + uint32_t cmd, cmdsize; + char segname[16]; + uint64_t vmaddr, vmsize, fileoff, filesize; + uint32_t maxprot, initprot, nsects, flags; +} mach_segment_command_64; +typedef struct { + char sectname[16], segname[16]; + uint32_t addr, size; + uint32_t offset, align, reloff, nreloc, flags; + uint32_t reserved1, reserved2; +} mach_section; +typedef struct { + char sectname[16], segname[16]; + uint64_t addr, size; + uint32_t offset, align, reloff, nreloc, flags; + uint32_t reserved1, reserved2, reserved3; +} mach_section_64; +typedef struct { + uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize; +} mach_symtab_command; +typedef struct { + int32_t strx; + uint8_t type, sect; + int16_t desc; + uint32_t value; +} mach_nlist; +typedef struct { + uint32_t strx; + uint8_t type, sect; + uint16_t desc; + uint64_t value; +} mach_nlist_64; +typedef struct +{ + uint32_t magic, nfat_arch; +} mach_fat_header; +typedef struct +{ + uint32_t cputype, cpusubtype, offset, size, align; +} mach_fat_arch; +typedef struct { + struct { + mach_header hdr; + mach_segment_command seg; + mach_section sec; + mach_symtab_command sym; + } arch[1]; + mach_nlist sym_entry; + uint8_t space[4096]; +} mach_obj; +typedef struct { + struct { + mach_header_64 hdr; + mach_segment_command_64 seg; + mach_section_64 sec; + mach_symtab_command sym; + } arch[1]; + mach_nlist_64 sym_entry; + uint8_t space[4096]; +} mach_obj_64; +typedef struct { + mach_fat_header fat; + mach_fat_arch fat_arch[4]; + struct { + mach_header hdr; + mach_segment_command seg; + mach_section sec; + mach_symtab_command sym; + } arch[4]; + mach_nlist sym_entry; + uint8_t space[4096]; +} mach_fat_obj; +]] + local symname = '_'..LJBC_PREFIX..ctx.modname + local isfat, is64, align, mobj = false, false, 4, "mach_obj" + if ctx.arch == "x64" then + is64, align, mobj = true, 8, "mach_obj_64" + elseif ctx.arch == "arm" then + isfat, mobj = true, "mach_fat_obj" + else + check(ctx.arch == "x86", "unsupported architecture for OSX") + end + local function aligned(v, a) return bit.band(v+a-1, -a) end + local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE. + + -- Create Mach-O object and fill in header. + local o = ffi.new(mobj) + local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align) + local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12,12,12} })[ctx.arch] + local cpusubtype = ({ x86={3}, x64={3}, arm={3,6,9,11} })[ctx.arch] + if isfat then + o.fat.magic = be32(0xcafebabe) + o.fat.nfat_arch = be32(#cpusubtype) + end + + -- Fill in sections and symbols. + for i=0,#cpusubtype-1 do + local ofs = 0 + if isfat then + local a = o.fat_arch[i] + a.cputype = be32(cputype[i+1]) + a.cpusubtype = be32(cpusubtype[i+1]) + -- Subsequent slices overlap each other to share data. + ofs = ffi.offsetof(o, "arch") + i*ffi.sizeof(o.arch[0]) + a.offset = be32(ofs) + a.size = be32(mach_size-ofs+#s) + end + local a = o.arch[i] + a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface + a.hdr.cputype = cputype[i+1] + a.hdr.cpusubtype = cpusubtype[i+1] + a.hdr.filetype = 1 + a.hdr.ncmds = 2 + a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym) + a.seg.cmd = is64 and 0x19 or 0x1 + a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec) + a.seg.vmsize = #s + a.seg.fileoff = mach_size-ofs + a.seg.filesize = #s + a.seg.maxprot = 1 + a.seg.initprot = 1 + a.seg.nsects = 1 + ffi.copy(a.sec.sectname, "__data") + ffi.copy(a.sec.segname, "__DATA") + a.sec.size = #s + a.sec.offset = mach_size-ofs + a.sym.cmd = 2 + a.sym.cmdsize = ffi.sizeof(a.sym) + a.sym.symoff = ffi.offsetof(o, "sym_entry")-ofs + a.sym.nsyms = 1 + a.sym.stroff = ffi.offsetof(o, "sym_entry")+ffi.sizeof(o.sym_entry)-ofs + a.sym.strsize = aligned(#symname+2, align) + end + o.sym_entry.type = 0xf + o.sym_entry.sect = 1 + o.sym_entry.strx = 1 + ffi.copy(o.space+1, symname) + + -- Write Macho-O object file. + local fp = savefile(output, "wb") + fp:write(ffi.string(o, mach_size)) + bcsave_tail(fp, output, s) +end + +local function bcsave_obj(ctx, output, s) + local ok, ffi = pcall(require, "ffi") + check(ok, "FFI library required to write this file type") + if ctx.os == "windows" then + return bcsave_peobj(ctx, output, s, ffi) + elseif ctx.os == "osx" then + return bcsave_machobj(ctx, output, s, ffi) + else + return bcsave_elfobj(ctx, output, s, ffi) + end +end + +------------------------------------------------------------------------------ + +local function bclist(input, output) + local f = readfile(input) + require("jit.bc").dump(f, savefile(output, "w"), true) +end + +local function bcsave(ctx, input, output) + local f = readfile(input) + local s = string.dump(f, ctx.strip) + local t = ctx.type + if not t then + t = detecttype(output) + ctx.type = t + end + if t == "raw" then + bcsave_raw(output, s) + else + if not ctx.modname then ctx.modname = detectmodname(input) end + if t == "obj" then + bcsave_obj(ctx, output, s) + else + bcsave_c(ctx, output, s) + end + end +end + +local function docmd(...) + local arg = {...} + local n = 1 + local list = false + local ctx = { + strip = true, arch = jit.arch, os = string.lower(jit.os), + type = false, modname = false, + } + while n <= #arg do + local a = arg[n] + if type(a) == "string" and string.sub(a, 1, 1) == "-" and a ~= "-" then + table.remove(arg, n) + if a == "--" then break end + for m=2,#a do + local opt = string.sub(a, m, m) + if opt == "l" then + list = true + elseif opt == "s" then + ctx.strip = true + elseif opt == "g" then + ctx.strip = false + else + if arg[n] == nil or m ~= #a then usage() end + if opt == "e" then + if n ~= 1 then usage() end + arg[1] = check(loadstring(arg[1])) + elseif opt == "n" then + ctx.modname = checkmodname(table.remove(arg, n)) + elseif opt == "t" then + ctx.type = checkarg(table.remove(arg, n), map_type, "file type") + elseif opt == "a" then + ctx.arch = checkarg(table.remove(arg, n), map_arch, "architecture") + elseif opt == "o" then + ctx.os = checkarg(table.remove(arg, n), map_os, "OS name") + else + usage() + end + end + end + else + n = n + 1 + end + end + if list then + if #arg == 0 or #arg > 2 then usage() end + bclist(arg[1], arg[2] or "-") + else + if #arg ~= 2 then usage() end + bcsave(ctx, arg[1], arg[2]) + end +end + +------------------------------------------------------------------------------ + +-- Public module functions. +module(...) + +start = docmd -- Process -b command line option. + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_arm.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_arm.lua new file mode 100644 index 0000000..b3d0ebc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_arm.lua @@ -0,0 +1,689 @@ +---------------------------------------------------------------------------- +-- LuaJIT ARM disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles most user-mode ARMv7 instructions +-- NYI: Advanced SIMD and VFP instructions. +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, ror, tohex = bit.band, bit.bor, bit.ror, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Opcode maps +------------------------------------------------------------------------------ + +local map_loadc = { + shift = 8, mask = 15, + [10] = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "vmovFmDN", "vstmFNdr", + _ = { + shift = 21, mask = 1, + [0] = "vstrFdl", + { shift = 16, mask = 15, [13] = "vpushFdr", _ = "vstmdbFNdr", } + }, + }, + { + shift = 23, mask = 3, + [0] = "vmovFDNm", + { shift = 16, mask = 15, [13] = "vpopFdr", _ = "vldmFNdr", }, + _ = { + shift = 21, mask = 1, + [0] = "vldrFdl", "vldmdbFNdr", + }, + }, + }, + [11] = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "vmovGmDN", "vstmGNdr", + _ = { + shift = 21, mask = 1, + [0] = "vstrGdl", + { shift = 16, mask = 15, [13] = "vpushGdr", _ = "vstmdbGNdr", } + }, + }, + { + shift = 23, mask = 3, + [0] = "vmovGDNm", + { shift = 16, mask = 15, [13] = "vpopGdr", _ = "vldmGNdr", }, + _ = { + shift = 21, mask = 1, + [0] = "vldrGdl", "vldmdbGNdr", + }, + }, + }, + _ = { + shift = 0, mask = 0 -- NYI ldc, mcrr, mrrc. + }, +} + +local map_vfps = { + shift = 6, mask = 0x2c001, + [0] = "vmlaF.dnm", "vmlsF.dnm", + [0x04000] = "vnmlsF.dnm", [0x04001] = "vnmlaF.dnm", + [0x08000] = "vmulF.dnm", [0x08001] = "vnmulF.dnm", + [0x0c000] = "vaddF.dnm", [0x0c001] = "vsubF.dnm", + [0x20000] = "vdivF.dnm", + [0x24000] = "vfnmsF.dnm", [0x24001] = "vfnmaF.dnm", + [0x28000] = "vfmaF.dnm", [0x28001] = "vfmsF.dnm", + [0x2c000] = "vmovF.dY", + [0x2c001] = { + shift = 7, mask = 0x1e01, + [0] = "vmovF.dm", "vabsF.dm", + [0x0200] = "vnegF.dm", [0x0201] = "vsqrtF.dm", + [0x0800] = "vcmpF.dm", [0x0801] = "vcmpeF.dm", + [0x0a00] = "vcmpzF.d", [0x0a01] = "vcmpzeF.d", + [0x0e01] = "vcvtG.dF.m", + [0x1000] = "vcvt.f32.u32Fdm", [0x1001] = "vcvt.f32.s32Fdm", + [0x1800] = "vcvtr.u32F.dm", [0x1801] = "vcvt.u32F.dm", + [0x1a00] = "vcvtr.s32F.dm", [0x1a01] = "vcvt.s32F.dm", + }, +} + +local map_vfpd = { + shift = 6, mask = 0x2c001, + [0] = "vmlaG.dnm", "vmlsG.dnm", + [0x04000] = "vnmlsG.dnm", [0x04001] = "vnmlaG.dnm", + [0x08000] = "vmulG.dnm", [0x08001] = "vnmulG.dnm", + [0x0c000] = "vaddG.dnm", [0x0c001] = "vsubG.dnm", + [0x20000] = "vdivG.dnm", + [0x24000] = "vfnmsG.dnm", [0x24001] = "vfnmaG.dnm", + [0x28000] = "vfmaG.dnm", [0x28001] = "vfmsG.dnm", + [0x2c000] = "vmovG.dY", + [0x2c001] = { + shift = 7, mask = 0x1e01, + [0] = "vmovG.dm", "vabsG.dm", + [0x0200] = "vnegG.dm", [0x0201] = "vsqrtG.dm", + [0x0800] = "vcmpG.dm", [0x0801] = "vcmpeG.dm", + [0x0a00] = "vcmpzG.d", [0x0a01] = "vcmpzeG.d", + [0x0e01] = "vcvtF.dG.m", + [0x1000] = "vcvt.f64.u32GdFm", [0x1001] = "vcvt.f64.s32GdFm", + [0x1800] = "vcvtr.u32FdG.m", [0x1801] = "vcvt.u32FdG.m", + [0x1a00] = "vcvtr.s32FdG.m", [0x1a01] = "vcvt.s32FdG.m", + }, +} + +local map_datac = { + shift = 24, mask = 1, + [0] = { + shift = 4, mask = 1, + [0] = { + shift = 8, mask = 15, + [10] = map_vfps, + [11] = map_vfpd, + -- NYI cdp, mcr, mrc. + }, + { + shift = 8, mask = 15, + [10] = { + shift = 20, mask = 15, + [0] = "vmovFnD", "vmovFDn", + [14] = "vmsrD", + [15] = { shift = 12, mask = 15, [15] = "vmrs", _ = "vmrsD", }, + }, + }, + }, + "svcT", +} + +local map_loadcu = { + shift = 0, mask = 0, -- NYI unconditional CP load/store. +} + +local map_datacu = { + shift = 0, mask = 0, -- NYI unconditional CP data. +} + +local map_simddata = { + shift = 0, mask = 0, -- NYI SIMD data. +} + +local map_simdload = { + shift = 0, mask = 0, -- NYI SIMD load/store, preload. +} + +local map_preload = { + shift = 0, mask = 0, -- NYI preload. +} + +local map_media = { + shift = 20, mask = 31, + [0] = false, + { --01 + shift = 5, mask = 7, + [0] = "sadd16DNM", "sasxDNM", "ssaxDNM", "ssub16DNM", + "sadd8DNM", false, false, "ssub8DNM", + }, + { --02 + shift = 5, mask = 7, + [0] = "qadd16DNM", "qasxDNM", "qsaxDNM", "qsub16DNM", + "qadd8DNM", false, false, "qsub8DNM", + }, + { --03 + shift = 5, mask = 7, + [0] = "shadd16DNM", "shasxDNM", "shsaxDNM", "shsub16DNM", + "shadd8DNM", false, false, "shsub8DNM", + }, + false, + { --05 + shift = 5, mask = 7, + [0] = "uadd16DNM", "uasxDNM", "usaxDNM", "usub16DNM", + "uadd8DNM", false, false, "usub8DNM", + }, + { --06 + shift = 5, mask = 7, + [0] = "uqadd16DNM", "uqasxDNM", "uqsaxDNM", "uqsub16DNM", + "uqadd8DNM", false, false, "uqsub8DNM", + }, + { --07 + shift = 5, mask = 7, + [0] = "uhadd16DNM", "uhasxDNM", "uhsaxDNM", "uhsub16DNM", + "uhadd8DNM", false, false, "uhsub8DNM", + }, + { --08 + shift = 5, mask = 7, + [0] = "pkhbtDNMU", false, "pkhtbDNMU", + { shift = 16, mask = 15, [15] = "sxtb16DMU", _ = "sxtab16DNMU", }, + "pkhbtDNMU", "selDNM", "pkhtbDNMU", + }, + false, + { --0a + shift = 5, mask = 7, + [0] = "ssatDxMu", "ssat16DxM", "ssatDxMu", + { shift = 16, mask = 15, [15] = "sxtbDMU", _ = "sxtabDNMU", }, + "ssatDxMu", false, "ssatDxMu", + }, + { --0b + shift = 5, mask = 7, + [0] = "ssatDxMu", "revDM", "ssatDxMu", + { shift = 16, mask = 15, [15] = "sxthDMU", _ = "sxtahDNMU", }, + "ssatDxMu", "rev16DM", "ssatDxMu", + }, + { --0c + shift = 5, mask = 7, + [3] = { shift = 16, mask = 15, [15] = "uxtb16DMU", _ = "uxtab16DNMU", }, + }, + false, + { --0e + shift = 5, mask = 7, + [0] = "usatDwMu", "usat16DwM", "usatDwMu", + { shift = 16, mask = 15, [15] = "uxtbDMU", _ = "uxtabDNMU", }, + "usatDwMu", false, "usatDwMu", + }, + { --0f + shift = 5, mask = 7, + [0] = "usatDwMu", "rbitDM", "usatDwMu", + { shift = 16, mask = 15, [15] = "uxthDMU", _ = "uxtahDNMU", }, + "usatDwMu", "revshDM", "usatDwMu", + }, + { --10 + shift = 12, mask = 15, + [15] = { + shift = 5, mask = 7, + "smuadNMS", "smuadxNMS", "smusdNMS", "smusdxNMS", + }, + _ = { + shift = 5, mask = 7, + [0] = "smladNMSD", "smladxNMSD", "smlsdNMSD", "smlsdxNMSD", + }, + }, + false, false, false, + { --14 + shift = 5, mask = 7, + [0] = "smlaldDNMS", "smlaldxDNMS", "smlsldDNMS", "smlsldxDNMS", + }, + { --15 + shift = 5, mask = 7, + [0] = { shift = 12, mask = 15, [15] = "smmulNMS", _ = "smmlaNMSD", }, + { shift = 12, mask = 15, [15] = "smmulrNMS", _ = "smmlarNMSD", }, + false, false, false, false, + "smmlsNMSD", "smmlsrNMSD", + }, + false, false, + { --18 + shift = 5, mask = 7, + [0] = { shift = 12, mask = 15, [15] = "usad8NMS", _ = "usada8NMSD", }, + }, + false, + { --1a + shift = 5, mask = 3, [2] = "sbfxDMvw", + }, + { --1b + shift = 5, mask = 3, [2] = "sbfxDMvw", + }, + { --1c + shift = 5, mask = 3, + [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", }, + }, + { --1d + shift = 5, mask = 3, + [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", }, + }, + { --1e + shift = 5, mask = 3, [2] = "ubfxDMvw", + }, + { --1f + shift = 5, mask = 3, [2] = "ubfxDMvw", + }, +} + +local map_load = { + shift = 21, mask = 9, + { + shift = 20, mask = 5, + [0] = "strtDL", "ldrtDL", [4] = "strbtDL", [5] = "ldrbtDL", + }, + _ = { + shift = 20, mask = 5, + [0] = "strDL", "ldrDL", [4] = "strbDL", [5] = "ldrbDL", + } +} + +local map_load1 = { + shift = 4, mask = 1, + [0] = map_load, map_media, +} + +local map_loadm = { + shift = 20, mask = 1, + [0] = { + shift = 23, mask = 3, + [0] = "stmdaNR", "stmNR", + { shift = 16, mask = 63, [45] = "pushR", _ = "stmdbNR", }, "stmibNR", + }, + { + shift = 23, mask = 3, + [0] = "ldmdaNR", { shift = 16, mask = 63, [61] = "popR", _ = "ldmNR", }, + "ldmdbNR", "ldmibNR", + }, +} + +local map_data = { + shift = 21, mask = 15, + [0] = "andDNPs", "eorDNPs", "subDNPs", "rsbDNPs", + "addDNPs", "adcDNPs", "sbcDNPs", "rscDNPs", + "tstNP", "teqNP", "cmpNP", "cmnNP", + "orrDNPs", "movDPs", "bicDNPs", "mvnDPs", +} + +local map_mul = { + shift = 21, mask = 7, + [0] = "mulNMSs", "mlaNMSDs", "umaalDNMS", "mlsDNMS", + "umullDNMSs", "umlalDNMSs", "smullDNMSs", "smlalDNMSs", +} + +local map_sync = { + shift = 20, mask = 15, -- NYI: brackets around N. R(D+1) for ldrexd/strexd. + [0] = "swpDMN", false, false, false, + "swpbDMN", false, false, false, + "strexDMN", "ldrexDN", "strexdDN", "ldrexdDN", + "strexbDMN", "ldrexbDN", "strexhDN", "ldrexhDN", +} + +local map_mulh = { + shift = 21, mask = 3, + [0] = { shift = 5, mask = 3, + [0] = "smlabbNMSD", "smlatbNMSD", "smlabtNMSD", "smlattNMSD", }, + { shift = 5, mask = 3, + [0] = "smlawbNMSD", "smulwbNMS", "smlawtNMSD", "smulwtNMS", }, + { shift = 5, mask = 3, + [0] = "smlalbbDNMS", "smlaltbDNMS", "smlalbtDNMS", "smlalttDNMS", }, + { shift = 5, mask = 3, + [0] = "smulbbNMS", "smultbNMS", "smulbtNMS", "smulttNMS", }, +} + +local map_misc = { + shift = 4, mask = 7, + -- NYI: decode PSR bits of msr. + [0] = { shift = 21, mask = 1, [0] = "mrsD", "msrM", }, + { shift = 21, mask = 3, "bxM", false, "clzDM", }, + { shift = 21, mask = 3, "bxjM", }, + { shift = 21, mask = 3, "blxM", }, + false, + { shift = 21, mask = 3, [0] = "qaddDMN", "qsubDMN", "qdaddDMN", "qdsubDMN", }, + false, + { shift = 21, mask = 3, "bkptK", }, +} + +local map_datar = { + shift = 4, mask = 9, + [9] = { + shift = 5, mask = 3, + [0] = { shift = 24, mask = 1, [0] = map_mul, map_sync, }, + { shift = 20, mask = 1, [0] = "strhDL", "ldrhDL", }, + { shift = 20, mask = 1, [0] = "ldrdDL", "ldrsbDL", }, + { shift = 20, mask = 1, [0] = "strdDL", "ldrshDL", }, + }, + _ = { + shift = 20, mask = 25, + [16] = { shift = 7, mask = 1, [0] = map_misc, map_mulh, }, + _ = { + shift = 0, mask = 0xffffffff, + [bor(0xe1a00000)] = "nop", + _ = map_data, + } + }, +} + +local map_datai = { + shift = 20, mask = 31, -- NYI: decode PSR bits of msr. Decode imm12. + [16] = "movwDW", [20] = "movtDW", + [18] = { shift = 0, mask = 0xf00ff, [0] = "nopv6", _ = "msrNW", }, + [22] = "msrNW", + _ = map_data, +} + +local map_branch = { + shift = 24, mask = 1, + [0] = "bB", "blB" +} + +local map_condins = { + [0] = map_datar, map_datai, map_load, map_load1, + map_loadm, map_branch, map_loadc, map_datac +} + +-- NYI: setend. +local map_uncondins = { + [0] = false, map_simddata, map_simdload, map_preload, + false, "blxB", map_loadcu, map_datacu, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc", +} + +local map_cond = { + [0] = "eq", "ne", "hs", "lo", "mi", "pl", "vs", "vc", + "hi", "ls", "ge", "lt", "gt", "le", "al", +} + +local map_shift = { [0] = "lsl", "lsr", "asr", "ror", } + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then + extra = "\t->"..sym + elseif band(ctx.op, 0x0e000000) ~= 0x0a000000 then + extra = "\t; 0x"..tohex(ctx.rel) + end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-5s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-5s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +-- Format operand 2 of load/store opcodes. +local function fmtload(ctx, op, pos) + local base = map_gpr[band(rshift(op, 16), 15)] + local x, ofs + local ext = (band(op, 0x04000000) == 0) + if not ext and band(op, 0x02000000) == 0 then + ofs = band(op, 4095) + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + ofs = "#"..ofs + elseif ext and band(op, 0x00400000) ~= 0 then + ofs = band(op, 15) + band(rshift(op, 4), 0xf0) + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + ofs = "#"..ofs + else + ofs = map_gpr[band(op, 15)] + if ext or band(op, 0xfe0) == 0 then + elseif band(op, 0xfe0) == 0x60 then + ofs = format("%s, rrx", ofs) + else + local sh = band(rshift(op, 7), 31) + if sh == 0 then sh = 32 end + ofs = format("%s, %s #%d", ofs, map_shift[band(rshift(op, 5), 3)], sh) + end + if band(op, 0x00800000) == 0 then ofs = "-"..ofs end + end + if ofs == "#0" then + x = format("[%s]", base) + elseif band(op, 0x01000000) == 0 then + x = format("[%s], %s", base, ofs) + else + x = format("[%s, %s]", base, ofs) + end + if band(op, 0x01200000) == 0x01200000 then x = x.."!" end + return x +end + +-- Format operand 2 of vector load/store opcodes. +local function fmtvload(ctx, op, pos) + local base = map_gpr[band(rshift(op, 16), 15)] + local ofs = band(op, 255)*4 + if band(op, 0x00800000) == 0 then ofs = -ofs end + if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end + if ofs == 0 then + return format("[%s]", base) + else + return format("[%s, #%d]", base, ofs) + end +end + +local function fmtvr(op, vr, sh0, sh1) + if vr == "s" then + return format("s%d", 2*band(rshift(op, sh0), 15)+band(rshift(op, sh1), 1)) + else + return format("d%d", band(rshift(op, sh0), 15)+band(rshift(op, sh1-4), 16)) + end +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0) + local operands = {} + local suffix = "" + local last, name, pat + local vr + ctx.op = op + ctx.rel = nil + + local cond = rshift(op, 28) + local opat + if cond == 15 then + opat = map_uncondins[band(rshift(op, 25), 7)] + else + if cond ~= 14 then suffix = map_cond[cond] end + opat = map_condins[band(rshift(op, 25), 7)] + end + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._ + end + name, pat = match(opat, "^([a-z0-9]*)(.*)") + if sub(pat, 1, 1) == "." then + local s2, p2 = match(pat, "^([a-z0-9.]*)(.*)") + suffix = suffix..s2 + pat = p2 + end + + for p in gmatch(pat, ".") do + local x = nil + if p == "D" then + x = map_gpr[band(rshift(op, 12), 15)] + elseif p == "N" then + x = map_gpr[band(rshift(op, 16), 15)] + elseif p == "S" then + x = map_gpr[band(rshift(op, 8), 15)] + elseif p == "M" then + x = map_gpr[band(op, 15)] + elseif p == "d" then + x = fmtvr(op, vr, 12, 22) + elseif p == "n" then + x = fmtvr(op, vr, 16, 7) + elseif p == "m" then + x = fmtvr(op, vr, 0, 5) + elseif p == "P" then + if band(op, 0x02000000) ~= 0 then + x = ror(band(op, 255), 2*band(rshift(op, 8), 15)) + else + x = map_gpr[band(op, 15)] + if band(op, 0xff0) ~= 0 then + operands[#operands+1] = x + local s = map_shift[band(rshift(op, 5), 3)] + local r = nil + if band(op, 0xf90) == 0 then + if s == "ror" then s = "rrx" else r = "#32" end + elseif band(op, 0x10) == 0 then + r = "#"..band(rshift(op, 7), 31) + else + r = map_gpr[band(rshift(op, 8), 15)] + end + if name == "mov" then name = s; x = r + elseif r then x = format("%s %s", s, r) + else x = s end + end + end + elseif p == "L" then + x = fmtload(ctx, op, pos) + elseif p == "l" then + x = fmtvload(ctx, op, pos) + elseif p == "B" then + local addr = ctx.addr + pos + 8 + arshift(lshift(op, 8), 6) + if cond == 15 then addr = addr + band(rshift(op, 23), 2) end + ctx.rel = addr + x = "0x"..tohex(addr) + elseif p == "F" then + vr = "s" + elseif p == "G" then + vr = "d" + elseif p == "." then + suffix = suffix..(vr == "s" and ".f32" or ".f64") + elseif p == "R" then + if band(op, 0x00200000) ~= 0 and #operands == 1 then + operands[1] = operands[1].."!" + end + local t = {} + for i=0,15 do + if band(rshift(op, i), 1) == 1 then t[#t+1] = map_gpr[i] end + end + x = "{"..concat(t, ", ").."}" + elseif p == "r" then + if band(op, 0x00200000) ~= 0 and #operands == 2 then + operands[1] = operands[1].."!" + end + local s = tonumber(sub(last, 2)) + local n = band(op, 255) + if vr == "d" then n = rshift(n, 1) end + operands[#operands] = format("{%s-%s%d}", last, vr, s+n-1) + elseif p == "W" then + x = band(op, 0x0fff) + band(rshift(op, 4), 0xf000) + elseif p == "T" then + x = "#0x"..tohex(band(op, 0x00ffffff), 6) + elseif p == "U" then + x = band(rshift(op, 7), 31) + if x == 0 then x = nil end + elseif p == "u" then + x = band(rshift(op, 7), 31) + if band(op, 0x40) == 0 then + if x == 0 then x = nil else x = "lsl #"..x end + else + if x == 0 then x = "asr #32" else x = "asr #"..x end + end + elseif p == "v" then + x = band(rshift(op, 7), 31) + elseif p == "w" then + x = band(rshift(op, 16), 31) + elseif p == "x" then + x = band(rshift(op, 16), 31) + 1 + elseif p == "X" then + x = band(rshift(op, 16), 31) - last + 1 + elseif p == "Y" then + x = band(rshift(op, 12), 0xf0) + band(op, 0x0f) + elseif p == "K" then + x = "#0x"..tohex(band(rshift(op, 4), 0x0000fff0) + band(op, 15), 4) + elseif p == "s" then + if band(op, 0x00100000) ~= 0 then suffix = "s"..suffix end + else + assert(false) + end + if x then + last = x + if type(x) == "number" then x = "#"..x end + operands[#operands+1] = x + end + end + + return putop(ctx, name..suffix, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + ctx.pos = ofs + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 16 then return map_gpr[r] end + return "d"..(r-16) +end + +-- Public module functions. +module(...) + +create = create_ +disass = disass_ +regname = regname_ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mips.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mips.lua new file mode 100644 index 0000000..47a7a83 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mips.lua @@ -0,0 +1,428 @@ +---------------------------------------------------------------------------- +-- LuaJIT MIPS disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT/X license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles all standard MIPS32R1/R2 instructions. +-- Default mode is big-endian, but see: dis_mipsel.lua +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, tohex = bit.band, bit.bor, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Primary and extended opcode maps +------------------------------------------------------------------------------ + +local map_movci = { shift = 16, mask = 1, [0] = "movfDSC", "movtDSC", } +local map_srl = { shift = 21, mask = 1, [0] = "srlDTA", "rotrDTA", } +local map_srlv = { shift = 6, mask = 1, [0] = "srlvDTS", "rotrvDTS", } + +local map_special = { + shift = 0, mask = 63, + [0] = { shift = 0, mask = -1, [0] = "nop", _ = "sllDTA" }, + map_movci, map_srl, "sraDTA", + "sllvDTS", false, map_srlv, "sravDTS", + "jrS", "jalrD1S", "movzDST", "movnDST", + "syscallY", "breakY", false, "sync", + "mfhiD", "mthiS", "mfloD", "mtloS", + false, false, false, false, + "multST", "multuST", "divST", "divuST", + false, false, false, false, + "addDST", "addu|moveDST0", "subDST", "subu|neguDS0T", + "andDST", "orDST", "xorDST", "nor|notDST0", + false, false, "sltDST", "sltuDST", + false, false, false, false, + "tgeSTZ", "tgeuSTZ", "tltSTZ", "tltuSTZ", + "teqSTZ", false, "tneSTZ", +} + +local map_special2 = { + shift = 0, mask = 63, + [0] = "maddST", "madduST", "mulDST", false, + "msubST", "msubuST", + [32] = "clzDS", [33] = "cloDS", + [63] = "sdbbpY", +} + +local map_bshfl = { + shift = 6, mask = 31, + [2] = "wsbhDT", + [16] = "sebDT", + [24] = "sehDT", +} + +local map_special3 = { + shift = 0, mask = 63, + [0] = "extTSAK", [4] = "insTSAL", + [32] = map_bshfl, + [59] = "rdhwrTD", +} + +local map_regimm = { + shift = 16, mask = 31, + [0] = "bltzSB", "bgezSB", "bltzlSB", "bgezlSB", + false, false, false, false, + "tgeiSI", "tgeiuSI", "tltiSI", "tltiuSI", + "teqiSI", false, "tneiSI", false, + "bltzalSB", "bgezalSB", "bltzallSB", "bgezallSB", + false, false, false, false, + false, false, false, false, + false, false, false, "synciSO", +} + +local map_cop0 = { + shift = 25, mask = 1, + [0] = { + shift = 21, mask = 15, + [0] = "mfc0TDW", [4] = "mtc0TDW", + [10] = "rdpgprDT", + [11] = { shift = 5, mask = 1, [0] = "diT0", "eiT0", }, + [14] = "wrpgprDT", + }, { + shift = 0, mask = 63, + [1] = "tlbr", [2] = "tlbwi", [6] = "tlbwr", [8] = "tlbp", + [24] = "eret", [31] = "deret", + [32] = "wait", + }, +} + +local map_cop1s = { + shift = 0, mask = 63, + [0] = "add.sFGH", "sub.sFGH", "mul.sFGH", "div.sFGH", + "sqrt.sFG", "abs.sFG", "mov.sFG", "neg.sFG", + "round.l.sFG", "trunc.l.sFG", "ceil.l.sFG", "floor.l.sFG", + "round.w.sFG", "trunc.w.sFG", "ceil.w.sFG", "floor.w.sFG", + false, + { shift = 16, mask = 1, [0] = "movf.sFGC", "movt.sFGC" }, + "movz.sFGT", "movn.sFGT", + false, "recip.sFG", "rsqrt.sFG", false, + false, false, false, false, + false, false, false, false, + false, "cvt.d.sFG", false, false, + "cvt.w.sFG", "cvt.l.sFG", "cvt.ps.sFGH", false, + false, false, false, false, + false, false, false, false, + "c.f.sVGH", "c.un.sVGH", "c.eq.sVGH", "c.ueq.sVGH", + "c.olt.sVGH", "c.ult.sVGH", "c.ole.sVGH", "c.ule.sVGH", + "c.sf.sVGH", "c.ngle.sVGH", "c.seq.sVGH", "c.ngl.sVGH", + "c.lt.sVGH", "c.nge.sVGH", "c.le.sVGH", "c.ngt.sVGH", +} + +local map_cop1d = { + shift = 0, mask = 63, + [0] = "add.dFGH", "sub.dFGH", "mul.dFGH", "div.dFGH", + "sqrt.dFG", "abs.dFG", "mov.dFG", "neg.dFG", + "round.l.dFG", "trunc.l.dFG", "ceil.l.dFG", "floor.l.dFG", + "round.w.dFG", "trunc.w.dFG", "ceil.w.dFG", "floor.w.dFG", + false, + { shift = 16, mask = 1, [0] = "movf.dFGC", "movt.dFGC" }, + "movz.dFGT", "movn.dFGT", + false, "recip.dFG", "rsqrt.dFG", false, + false, false, false, false, + false, false, false, false, + "cvt.s.dFG", false, false, false, + "cvt.w.dFG", "cvt.l.dFG", false, false, + false, false, false, false, + false, false, false, false, + "c.f.dVGH", "c.un.dVGH", "c.eq.dVGH", "c.ueq.dVGH", + "c.olt.dVGH", "c.ult.dVGH", "c.ole.dVGH", "c.ule.dVGH", + "c.df.dVGH", "c.ngle.dVGH", "c.deq.dVGH", "c.ngl.dVGH", + "c.lt.dVGH", "c.nge.dVGH", "c.le.dVGH", "c.ngt.dVGH", +} + +local map_cop1ps = { + shift = 0, mask = 63, + [0] = "add.psFGH", "sub.psFGH", "mul.psFGH", false, + false, "abs.psFG", "mov.psFG", "neg.psFG", + false, false, false, false, + false, false, false, false, + false, + { shift = 16, mask = 1, [0] = "movf.psFGC", "movt.psFGC" }, + "movz.psFGT", "movn.psFGT", + false, false, false, false, + false, false, false, false, + false, false, false, false, + "cvt.s.puFG", false, false, false, + false, false, false, false, + "cvt.s.plFG", false, false, false, + "pll.psFGH", "plu.psFGH", "pul.psFGH", "puu.psFGH", + "c.f.psVGH", "c.un.psVGH", "c.eq.psVGH", "c.ueq.psVGH", + "c.olt.psVGH", "c.ult.psVGH", "c.ole.psVGH", "c.ule.psVGH", + "c.psf.psVGH", "c.ngle.psVGH", "c.pseq.psVGH", "c.ngl.psVGH", + "c.lt.psVGH", "c.nge.psVGH", "c.le.psVGH", "c.ngt.psVGH", +} + +local map_cop1w = { + shift = 0, mask = 63, + [32] = "cvt.s.wFG", [33] = "cvt.d.wFG", +} + +local map_cop1l = { + shift = 0, mask = 63, + [32] = "cvt.s.lFG", [33] = "cvt.d.lFG", +} + +local map_cop1bc = { + shift = 16, mask = 3, + [0] = "bc1fCB", "bc1tCB", "bc1flCB", "bc1tlCB", +} + +local map_cop1 = { + shift = 21, mask = 31, + [0] = "mfc1TG", false, "cfc1TG", "mfhc1TG", + "mtc1TG", false, "ctc1TG", "mthc1TG", + map_cop1bc, false, false, false, + false, false, false, false, + map_cop1s, map_cop1d, false, false, + map_cop1w, map_cop1l, map_cop1ps, +} + +local map_cop1x = { + shift = 0, mask = 63, + [0] = "lwxc1FSX", "ldxc1FSX", false, false, + false, "luxc1FSX", false, false, + "swxc1FSX", "sdxc1FSX", false, false, + false, "suxc1FSX", false, "prefxMSX", + false, false, false, false, + false, false, false, false, + false, false, false, false, + false, false, "alnv.psFGHS", false, + "madd.sFRGH", "madd.dFRGH", false, false, + false, false, "madd.psFRGH", false, + "msub.sFRGH", "msub.dFRGH", false, false, + false, false, "msub.psFRGH", false, + "nmadd.sFRGH", "nmadd.dFRGH", false, false, + false, false, "nmadd.psFRGH", false, + "nmsub.sFRGH", "nmsub.dFRGH", false, false, + false, false, "nmsub.psFRGH", false, +} + +local map_pri = { + [0] = map_special, map_regimm, "jJ", "jalJ", + "beq|beqz|bST00B", "bne|bnezST0B", "blezSB", "bgtzSB", + "addiTSI", "addiu|liTS0I", "sltiTSI", "sltiuTSI", + "andiTSU", "ori|liTS0U", "xoriTSU", "luiTU", + map_cop0, map_cop1, false, map_cop1x, + "beql|beqzlST0B", "bnel|bnezlST0B", "blezlSB", "bgtzlSB", + false, false, false, false, + map_special2, false, false, map_special3, + "lbTSO", "lhTSO", "lwlTSO", "lwTSO", + "lbuTSO", "lhuTSO", "lwrTSO", false, + "sbTSO", "shTSO", "swlTSO", "swTSO", + false, false, "swrTSO", "cacheNSO", + "llTSO", "lwc1HSO", "lwc2TSO", "prefNSO", + false, "ldc1HSO", "ldc2TSO", false, + "scTSO", "swc1HSO", "swc2TSO", false, + false, "sdc1HSO", "sdc2TSO", false, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "sp", "r30", "ra", +} + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then extra = "\t->"..sym end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-7s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-7s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +local function get_be(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3) +end + +local function get_le(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0) +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local op = ctx:get() + local operands = {} + local last = nil + ctx.op = op + ctx.rel = nil + + local opat = map_pri[rshift(op, 26)] + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._ + end + local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") + local altname, pat2 = match(pat, "|([a-z0-9_.|]*)(.*)") + if altname then pat = pat2 end + + for p in gmatch(pat, ".") do + local x = nil + if p == "S" then + x = map_gpr[band(rshift(op, 21), 31)] + elseif p == "T" then + x = map_gpr[band(rshift(op, 16), 31)] + elseif p == "D" then + x = map_gpr[band(rshift(op, 11), 31)] + elseif p == "F" then + x = "f"..band(rshift(op, 6), 31) + elseif p == "G" then + x = "f"..band(rshift(op, 11), 31) + elseif p == "H" then + x = "f"..band(rshift(op, 16), 31) + elseif p == "R" then + x = "f"..band(rshift(op, 21), 31) + elseif p == "A" then + x = band(rshift(op, 6), 31) + elseif p == "M" then + x = band(rshift(op, 11), 31) + elseif p == "N" then + x = band(rshift(op, 16), 31) + elseif p == "C" then + x = band(rshift(op, 18), 7) + if x == 0 then x = nil end + elseif p == "K" then + x = band(rshift(op, 11), 31) + 1 + elseif p == "L" then + x = band(rshift(op, 11), 31) - last + 1 + elseif p == "I" then + x = arshift(lshift(op, 16), 16) + elseif p == "U" then + x = band(op, 0xffff) + elseif p == "O" then + local disp = arshift(lshift(op, 16), 16) + operands[#operands] = format("%d(%s)", disp, last) + elseif p == "X" then + local index = map_gpr[band(rshift(op, 16), 31)] + operands[#operands] = format("%s(%s)", index, last) + elseif p == "B" then + x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4 + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "J" then + x = band(ctx.addr + ctx.pos, 0xf0000000) + band(op, 0x03ffffff)*4 + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "V" then + x = band(rshift(op, 8), 7) + if x == 0 then x = nil end + elseif p == "W" then + x = band(op, 7) + if x == 0 then x = nil end + elseif p == "Y" then + x = band(rshift(op, 6), 0x000fffff) + if x == 0 then x = nil end + elseif p == "Z" then + x = band(rshift(op, 6), 1023) + if x == 0 then x = nil end + elseif p == "0" then + if last == "r0" or last == 0 then + local n = #operands + operands[n] = nil + last = operands[n-1] + if altname then + local a1, a2 = match(altname, "([^|]*)|(.*)") + if a1 then name, altname = a1, a2 + else name = altname end + end + end + elseif p == "1" then + if last == "ra" then + operands[#operands] = nil + end + else + assert(false) + end + if x then operands[#operands+1] = x; last = x end + end + + return putop(ctx, name, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + stop = stop - stop % 4 + ctx.pos = ofs - ofs % 4 + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + ctx.get = get_be + return ctx +end + +local function create_el_(code, addr, out) + local ctx = create_(code, addr, out) + ctx.get = get_le + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +local function disass_el_(code, addr, out) + create_el_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 32 then return map_gpr[r] end + return "f"..(r-32) +end + +-- Public module functions. +module(...) + +create = create_ +create_el = create_el_ +disass = disass_ +disass_el = disass_el_ +regname = regname_ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mipsel.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mipsel.lua new file mode 100644 index 0000000..d19de31 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_mipsel.lua @@ -0,0 +1,20 @@ +---------------------------------------------------------------------------- +-- LuaJIT MIPSEL disassembler wrapper module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This module just exports the little-endian functions from the +-- MIPS disassembler module. All the interesting stuff is there. +------------------------------------------------------------------------------ + +local require = require + +module(...) + +local dis_mips = require(_PACKAGE.."dis_mips") + +create = dis_mips.create_el +disass = dis_mips.disass_el +regname = dis_mips.regname + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_ppc.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_ppc.lua new file mode 100644 index 0000000..cfaf982 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_ppc.lua @@ -0,0 +1,591 @@ +---------------------------------------------------------------------------- +-- LuaJIT PPC disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT/X license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- It disassembles all common, non-privileged 32/64 bit PowerPC instructions +-- plus the e500 SPE instructions and some Cell/Xenon extensions. +-- +-- NYI: VMX, VMX128 +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local concat = table.concat +local bit = require("bit") +local band, bor, tohex = bit.band, bit.bor, bit.tohex +local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift + +------------------------------------------------------------------------------ +-- Primary and extended opcode maps +------------------------------------------------------------------------------ + +local map_crops = { + shift = 1, mask = 1023, + [0] = "mcrfXX", + [33] = "crnor|crnotCCC=", [129] = "crandcCCC", + [193] = "crxor|crclrCCC%", [225] = "crnandCCC", + [257] = "crandCCC", [289] = "creqv|crsetCCC%", + [417] = "crorcCCC", [449] = "cror|crmoveCCC=", + [16] = "b_lrKB", [528] = "b_ctrKB", + [150] = "isync", +} + +local map_rlwinm = setmetatable({ + shift = 0, mask = -1, +}, +{ __index = function(t, x) + local rot = band(rshift(x, 11), 31) + local mb = band(rshift(x, 6), 31) + local me = band(rshift(x, 1), 31) + if mb == 0 and me == 31-rot then + return "slwiRR~A." + elseif me == 31 and mb == 32-rot then + return "srwiRR~-A." + else + return "rlwinmRR~AAA." + end + end +}) + +local map_rld = { + shift = 2, mask = 7, + [0] = "rldiclRR~HM.", "rldicrRR~HM.", "rldicRR~HM.", "rldimiRR~HM.", + { + shift = 1, mask = 1, + [0] = "rldclRR~RM.", "rldcrRR~RM.", + }, +} + +local map_ext = setmetatable({ + shift = 1, mask = 1023, + + [0] = "cmp_YLRR", [32] = "cmpl_YLRR", + [4] = "twARR", [68] = "tdARR", + + [8] = "subfcRRR.", [40] = "subfRRR.", + [104] = "negRR.", [136] = "subfeRRR.", + [200] = "subfzeRR.", [232] = "subfmeRR.", + [520] = "subfcoRRR.", [552] = "subfoRRR.", + [616] = "negoRR.", [648] = "subfeoRRR.", + [712] = "subfzeoRR.", [744] = "subfmeoRR.", + + [9] = "mulhduRRR.", [73] = "mulhdRRR.", [233] = "mulldRRR.", + [457] = "divduRRR.", [489] = "divdRRR.", + [745] = "mulldoRRR.", + [969] = "divduoRRR.", [1001] = "divdoRRR.", + + [10] = "addcRRR.", [138] = "addeRRR.", + [202] = "addzeRR.", [234] = "addmeRR.", [266] = "addRRR.", + [522] = "addcoRRR.", [650] = "addeoRRR.", + [714] = "addzeoRR.", [746] = "addmeoRR.", [778] = "addoRRR.", + + [11] = "mulhwuRRR.", [75] = "mulhwRRR.", [235] = "mullwRRR.", + [459] = "divwuRRR.", [491] = "divwRRR.", + [747] = "mullwoRRR.", + [971] = "divwouRRR.", [1003] = "divwoRRR.", + + [15] = "iselltRRR", [47] = "iselgtRRR", [79] = "iseleqRRR", + + [144] = { shift = 20, mask = 1, [0] = "mtcrfRZ~", "mtocrfRZ~", }, + [19] = { shift = 20, mask = 1, [0] = "mfcrR", "mfocrfRZ", }, + [371] = { shift = 11, mask = 1023, [392] = "mftbR", [424] = "mftbuR", }, + [339] = { + shift = 11, mask = 1023, + [32] = "mferR", [256] = "mflrR", [288] = "mfctrR", [16] = "mfspefscrR", + }, + [467] = { + shift = 11, mask = 1023, + [32] = "mtxerR", [256] = "mtlrR", [288] = "mtctrR", [16] = "mtspefscrR", + }, + + [20] = "lwarxRR0R", [84] = "ldarxRR0R", + + [21] = "ldxRR0R", [53] = "lduxRRR", + [149] = "stdxRR0R", [181] = "stduxRRR", + [341] = "lwaxRR0R", [373] = "lwauxRRR", + + [23] = "lwzxRR0R", [55] = "lwzuxRRR", + [87] = "lbzxRR0R", [119] = "lbzuxRRR", + [151] = "stwxRR0R", [183] = "stwuxRRR", + [215] = "stbxRR0R", [247] = "stbuxRRR", + [279] = "lhzxRR0R", [311] = "lhzuxRRR", + [343] = "lhaxRR0R", [375] = "lhauxRRR", + [407] = "sthxRR0R", [439] = "sthuxRRR", + + [54] = "dcbst-R0R", [86] = "dcbf-R0R", + [150] = "stwcxRR0R.", [214] = "stdcxRR0R.", + [246] = "dcbtst-R0R", [278] = "dcbt-R0R", + [310] = "eciwxRR0R", [438] = "ecowxRR0R", + [470] = "dcbi-RR", + + [598] = { + shift = 21, mask = 3, + [0] = "sync", "lwsync", "ptesync", + }, + [758] = "dcba-RR", + [854] = "eieio", [982] = "icbi-R0R", [1014] = "dcbz-R0R", + + [26] = "cntlzwRR~", [58] = "cntlzdRR~", + [122] = "popcntbRR~", + [154] = "prtywRR~", [186] = "prtydRR~", + + [28] = "andRR~R.", [60] = "andcRR~R.", [124] = "nor|notRR~R=.", + [284] = "eqvRR~R.", [316] = "xorRR~R.", + [412] = "orcRR~R.", [444] = "or|mrRR~R=.", [476] = "nandRR~R.", + [508] = "cmpbRR~R", + + [512] = "mcrxrX", + + [532] = "ldbrxRR0R", [660] = "stdbrxRR0R", + + [533] = "lswxRR0R", [597] = "lswiRR0A", + [661] = "stswxRR0R", [725] = "stswiRR0A", + + [534] = "lwbrxRR0R", [662] = "stwbrxRR0R", + [790] = "lhbrxRR0R", [918] = "sthbrxRR0R", + + [535] = "lfsxFR0R", [567] = "lfsuxFRR", + [599] = "lfdxFR0R", [631] = "lfduxFRR", + [663] = "stfsxFR0R", [695] = "stfsuxFRR", + [727] = "stfdxFR0R", [759] = "stfduxFR0R", + [855] = "lfiwaxFR0R", + [983] = "stfiwxFR0R", + + [24] = "slwRR~R.", + + [27] = "sldRR~R.", [536] = "srwRR~R.", + [792] = "srawRR~R.", [824] = "srawiRR~A.", + + [794] = "sradRR~R.", [826] = "sradiRR~H.", [827] = "sradiRR~H.", + [922] = "extshRR~.", [954] = "extsbRR~.", [986] = "extswRR~.", + + [539] = "srdRR~R.", +}, +{ __index = function(t, x) + if band(x, 31) == 15 then return "iselRRRC" end + end +}) + +local map_ld = { + shift = 0, mask = 3, + [0] = "ldRRE", "lduRRE", "lwaRRE", +} + +local map_std = { + shift = 0, mask = 3, + [0] = "stdRRE", "stduRRE", +} + +local map_fps = { + shift = 5, mask = 1, + { + shift = 1, mask = 15, + [0] = false, false, "fdivsFFF.", false, + "fsubsFFF.", "faddsFFF.", "fsqrtsF-F.", false, + "fresF-F.", "fmulsFF-F.", "frsqrtesF-F.", false, + "fmsubsFFFF~.", "fmaddsFFFF~.", "fnmsubsFFFF~.", "fnmaddsFFFF~.", + } +} + +local map_fpd = { + shift = 5, mask = 1, + [0] = { + shift = 1, mask = 1023, + [0] = "fcmpuXFF", [32] = "fcmpoXFF", [64] = "mcrfsXX", + [38] = "mtfsb1A.", [70] = "mtfsb0A.", [134] = "mtfsfiA>>-A>", + [8] = "fcpsgnFFF.", [40] = "fnegF-F.", [72] = "fmrF-F.", + [136] = "fnabsF-F.", [264] = "fabsF-F.", + [12] = "frspF-F.", + [14] = "fctiwF-F.", [15] = "fctiwzF-F.", + [583] = "mffsF.", [711] = "mtfsfZF.", + [392] = "frinF-F.", [424] = "frizF-F.", + [456] = "fripF-F.", [488] = "frimF-F.", + [814] = "fctidF-F.", [815] = "fctidzF-F.", [846] = "fcfidF-F.", + }, + { + shift = 1, mask = 15, + [0] = false, false, "fdivFFF.", false, + "fsubFFF.", "faddFFF.", "fsqrtF-F.", "fselFFFF~.", + "freF-F.", "fmulFF-F.", "frsqrteF-F.", false, + "fmsubFFFF~.", "fmaddFFFF~.", "fnmsubFFFF~.", "fnmaddFFFF~.", + } +} + +local map_spe = { + shift = 0, mask = 2047, + + [512] = "evaddwRRR", [514] = "evaddiwRAR~", + [516] = "evsubwRRR~", [518] = "evsubiwRAR~", + [520] = "evabsRR", [521] = "evnegRR", + [522] = "evextsbRR", [523] = "evextshRR", [524] = "evrndwRR", + [525] = "evcntlzwRR", [526] = "evcntlswRR", + + [527] = "brincRRR", + + [529] = "evandRRR", [530] = "evandcRRR", [534] = "evxorRRR", + [535] = "evor|evmrRRR=", [536] = "evnor|evnotRRR=", + [537] = "eveqvRRR", [539] = "evorcRRR", [542] = "evnandRRR", + + [544] = "evsrwuRRR", [545] = "evsrwsRRR", + [546] = "evsrwiuRRA", [547] = "evsrwisRRA", + [548] = "evslwRRR", [550] = "evslwiRRA", + [552] = "evrlwRRR", [553] = "evsplatiRS", + [554] = "evrlwiRRA", [555] = "evsplatfiRS", + [556] = "evmergehiRRR", [557] = "evmergeloRRR", + [558] = "evmergehiloRRR", [559] = "evmergelohiRRR", + + [560] = "evcmpgtuYRR", [561] = "evcmpgtsYRR", + [562] = "evcmpltuYRR", [563] = "evcmpltsYRR", + [564] = "evcmpeqYRR", + + [632] = "evselRRR", [633] = "evselRRRW", + [634] = "evselRRRW", [635] = "evselRRRW", + [636] = "evselRRRW", [637] = "evselRRRW", + [638] = "evselRRRW", [639] = "evselRRRW", + + [640] = "evfsaddRRR", [641] = "evfssubRRR", + [644] = "evfsabsRR", [645] = "evfsnabsRR", [646] = "evfsnegRR", + [648] = "evfsmulRRR", [649] = "evfsdivRRR", + [652] = "evfscmpgtYRR", [653] = "evfscmpltYRR", [654] = "evfscmpeqYRR", + [656] = "evfscfuiR-R", [657] = "evfscfsiR-R", + [658] = "evfscfufR-R", [659] = "evfscfsfR-R", + [660] = "evfsctuiR-R", [661] = "evfsctsiR-R", + [662] = "evfsctufR-R", [663] = "evfsctsfR-R", + [664] = "evfsctuizR-R", [666] = "evfsctsizR-R", + [668] = "evfststgtYRR", [669] = "evfststltYRR", [670] = "evfststeqYRR", + + [704] = "efsaddRRR", [705] = "efssubRRR", + [708] = "efsabsRR", [709] = "efsnabsRR", [710] = "efsnegRR", + [712] = "efsmulRRR", [713] = "efsdivRRR", + [716] = "efscmpgtYRR", [717] = "efscmpltYRR", [718] = "efscmpeqYRR", + [719] = "efscfdR-R", + [720] = "efscfuiR-R", [721] = "efscfsiR-R", + [722] = "efscfufR-R", [723] = "efscfsfR-R", + [724] = "efsctuiR-R", [725] = "efsctsiR-R", + [726] = "efsctufR-R", [727] = "efsctsfR-R", + [728] = "efsctuizR-R", [730] = "efsctsizR-R", + [732] = "efststgtYRR", [733] = "efststltYRR", [734] = "efststeqYRR", + + [736] = "efdaddRRR", [737] = "efdsubRRR", + [738] = "efdcfuidR-R", [739] = "efdcfsidR-R", + [740] = "efdabsRR", [741] = "efdnabsRR", [742] = "efdnegRR", + [744] = "efdmulRRR", [745] = "efddivRRR", + [746] = "efdctuidzR-R", [747] = "efdctsidzR-R", + [748] = "efdcmpgtYRR", [749] = "efdcmpltYRR", [750] = "efdcmpeqYRR", + [751] = "efdcfsR-R", + [752] = "efdcfuiR-R", [753] = "efdcfsiR-R", + [754] = "efdcfufR-R", [755] = "efdcfsfR-R", + [756] = "efdctuiR-R", [757] = "efdctsiR-R", + [758] = "efdctufR-R", [759] = "efdctsfR-R", + [760] = "efdctuizR-R", [762] = "efdctsizR-R", + [764] = "efdtstgtYRR", [765] = "efdtstltYRR", [766] = "efdtsteqYRR", + + [768] = "evlddxRR0R", [769] = "evlddRR8", + [770] = "evldwxRR0R", [771] = "evldwRR8", + [772] = "evldhxRR0R", [773] = "evldhRR8", + [776] = "evlhhesplatxRR0R", [777] = "evlhhesplatRR2", + [780] = "evlhhousplatxRR0R", [781] = "evlhhousplatRR2", + [782] = "evlhhossplatxRR0R", [783] = "evlhhossplatRR2", + [784] = "evlwhexRR0R", [785] = "evlwheRR4", + [788] = "evlwhouxRR0R", [789] = "evlwhouRR4", + [790] = "evlwhosxRR0R", [791] = "evlwhosRR4", + [792] = "evlwwsplatxRR0R", [793] = "evlwwsplatRR4", + [796] = "evlwhsplatxRR0R", [797] = "evlwhsplatRR4", + + [800] = "evstddxRR0R", [801] = "evstddRR8", + [802] = "evstdwxRR0R", [803] = "evstdwRR8", + [804] = "evstdhxRR0R", [805] = "evstdhRR8", + [816] = "evstwhexRR0R", [817] = "evstwheRR4", + [820] = "evstwhoxRR0R", [821] = "evstwhoRR4", + [824] = "evstwwexRR0R", [825] = "evstwweRR4", + [828] = "evstwwoxRR0R", [829] = "evstwwoRR4", + + [1027] = "evmhessfRRR", [1031] = "evmhossfRRR", [1032] = "evmheumiRRR", + [1033] = "evmhesmiRRR", [1035] = "evmhesmfRRR", [1036] = "evmhoumiRRR", + [1037] = "evmhosmiRRR", [1039] = "evmhosmfRRR", [1059] = "evmhessfaRRR", + [1063] = "evmhossfaRRR", [1064] = "evmheumiaRRR", [1065] = "evmhesmiaRRR", + [1067] = "evmhesmfaRRR", [1068] = "evmhoumiaRRR", [1069] = "evmhosmiaRRR", + [1071] = "evmhosmfaRRR", [1095] = "evmwhssfRRR", [1096] = "evmwlumiRRR", + [1100] = "evmwhumiRRR", [1101] = "evmwhsmiRRR", [1103] = "evmwhsmfRRR", + [1107] = "evmwssfRRR", [1112] = "evmwumiRRR", [1113] = "evmwsmiRRR", + [1115] = "evmwsmfRRR", [1127] = "evmwhssfaRRR", [1128] = "evmwlumiaRRR", + [1132] = "evmwhumiaRRR", [1133] = "evmwhsmiaRRR", [1135] = "evmwhsmfaRRR", + [1139] = "evmwssfaRRR", [1144] = "evmwumiaRRR", [1145] = "evmwsmiaRRR", + [1147] = "evmwsmfaRRR", + + [1216] = "evaddusiaawRR", [1217] = "evaddssiaawRR", + [1218] = "evsubfusiaawRR", [1219] = "evsubfssiaawRR", + [1220] = "evmraRR", + [1222] = "evdivwsRRR", [1223] = "evdivwuRRR", + [1224] = "evaddumiaawRR", [1225] = "evaddsmiaawRR", + [1226] = "evsubfumiaawRR", [1227] = "evsubfsmiaawRR", + + [1280] = "evmheusiaawRRR", [1281] = "evmhessiaawRRR", + [1283] = "evmhessfaawRRR", [1284] = "evmhousiaawRRR", + [1285] = "evmhossiaawRRR", [1287] = "evmhossfaawRRR", + [1288] = "evmheumiaawRRR", [1289] = "evmhesmiaawRRR", + [1291] = "evmhesmfaawRRR", [1292] = "evmhoumiaawRRR", + [1293] = "evmhosmiaawRRR", [1295] = "evmhosmfaawRRR", + [1320] = "evmhegumiaaRRR", [1321] = "evmhegsmiaaRRR", + [1323] = "evmhegsmfaaRRR", [1324] = "evmhogumiaaRRR", + [1325] = "evmhogsmiaaRRR", [1327] = "evmhogsmfaaRRR", + [1344] = "evmwlusiaawRRR", [1345] = "evmwlssiaawRRR", + [1352] = "evmwlumiaawRRR", [1353] = "evmwlsmiaawRRR", + [1363] = "evmwssfaaRRR", [1368] = "evmwumiaaRRR", + [1369] = "evmwsmiaaRRR", [1371] = "evmwsmfaaRRR", + [1408] = "evmheusianwRRR", [1409] = "evmhessianwRRR", + [1411] = "evmhessfanwRRR", [1412] = "evmhousianwRRR", + [1413] = "evmhossianwRRR", [1415] = "evmhossfanwRRR", + [1416] = "evmheumianwRRR", [1417] = "evmhesmianwRRR", + [1419] = "evmhesmfanwRRR", [1420] = "evmhoumianwRRR", + [1421] = "evmhosmianwRRR", [1423] = "evmhosmfanwRRR", + [1448] = "evmhegumianRRR", [1449] = "evmhegsmianRRR", + [1451] = "evmhegsmfanRRR", [1452] = "evmhogumianRRR", + [1453] = "evmhogsmianRRR", [1455] = "evmhogsmfanRRR", + [1472] = "evmwlusianwRRR", [1473] = "evmwlssianwRRR", + [1480] = "evmwlumianwRRR", [1481] = "evmwlsmianwRRR", + [1491] = "evmwssfanRRR", [1496] = "evmwumianRRR", + [1497] = "evmwsmianRRR", [1499] = "evmwsmfanRRR", +} + +local map_pri = { + [0] = false, false, "tdiARI", "twiARI", + map_spe, false, false, "mulliRRI", + "subficRRI", false, "cmpl_iYLRU", "cmp_iYLRI", + "addicRRI", "addic.RRI", "addi|liRR0I", "addis|lisRR0I", + "b_KBJ", "sc", "bKJ", map_crops, + "rlwimiRR~AAA.", map_rlwinm, false, "rlwnmRR~RAA.", + "oriNRR~U", "orisRR~U", "xoriRR~U", "xorisRR~U", + "andi.RR~U", "andis.RR~U", map_rld, map_ext, + "lwzRRD", "lwzuRRD", "lbzRRD", "lbzuRRD", + "stwRRD", "stwuRRD", "stbRRD", "stbuRRD", + "lhzRRD", "lhzuRRD", "lhaRRD", "lhauRRD", + "sthRRD", "sthuRRD", "lmwRRD", "stmwRRD", + "lfsFRD", "lfsuFRD", "lfdFRD", "lfduFRD", + "stfsFRD", "stfsuFRD", "stfdFRD", "stfduFRD", + false, false, map_ld, map_fps, + false, false, map_std, map_fpd, +} + +------------------------------------------------------------------------------ + +local map_gpr = { + [0] = "r0", "sp", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", +} + +local map_cond = { [0] = "lt", "gt", "eq", "so", "ge", "le", "ne", "ns", } + +-- Format a condition bit. +local function condfmt(cond) + if cond <= 3 then + return map_cond[band(cond, 3)] + else + return format("4*cr%d+%s", rshift(cond, 2), map_cond[band(cond, 3)]) + end +end + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local pos = ctx.pos + local extra = "" + if ctx.rel then + local sym = ctx.symtab[ctx.rel] + if sym then extra = "\t->"..sym end + end + if ctx.hexdump > 0 then + ctx.out(format("%08x %s %-7s %s%s\n", + ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra)) + else + ctx.out(format("%08x %-7s %s%s\n", + ctx.addr+pos, text, concat(operands, ", "), extra)) + end + ctx.pos = pos + 4 +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + return putop(ctx, ".long", { "0x"..tohex(ctx.op) }) +end + +-- Disassemble a single instruction. +local function disass_ins(ctx) + local pos = ctx.pos + local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) + local op = bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3) + local operands = {} + local last = nil + local rs = 21 + ctx.op = op + ctx.rel = nil + + local opat = map_pri[rshift(b0, 2)] + while type(opat) ~= "string" do + if not opat then return unknown(ctx) end + opat = opat[band(rshift(op, opat.shift), opat.mask)] + end + local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") + local altname, pat2 = match(pat, "|([a-z0-9_.]*)(.*)") + if altname then pat = pat2 end + + for p in gmatch(pat, ".") do + local x = nil + if p == "R" then + x = map_gpr[band(rshift(op, rs), 31)] + rs = rs - 5 + elseif p == "F" then + x = "f"..band(rshift(op, rs), 31) + rs = rs - 5 + elseif p == "A" then + x = band(rshift(op, rs), 31) + rs = rs - 5 + elseif p == "S" then + x = arshift(lshift(op, 27-rs), 27) + rs = rs - 5 + elseif p == "I" then + x = arshift(lshift(op, 16), 16) + elseif p == "U" then + x = band(op, 0xffff) + elseif p == "D" or p == "E" then + local disp = arshift(lshift(op, 16), 16) + if p == "E" then disp = band(disp, -4) end + if last == "r0" then last = "0" end + operands[#operands] = format("%d(%s)", disp, last) + elseif p >= "2" and p <= "8" then + local disp = band(rshift(op, rs), 31) * p + if last == "r0" then last = "0" end + operands[#operands] = format("%d(%s)", disp, last) + elseif p == "H" then + x = band(rshift(op, rs), 31) + lshift(band(op, 2), 4) + rs = rs - 5 + elseif p == "M" then + x = band(rshift(op, rs), 31) + band(op, 0x20) + elseif p == "C" then + x = condfmt(band(rshift(op, rs), 31)) + rs = rs - 5 + elseif p == "B" then + local bo = rshift(op, 21) + local cond = band(rshift(op, 16), 31) + local cn = "" + rs = rs - 10 + if band(bo, 4) == 0 then + cn = band(bo, 2) == 0 and "dnz" or "dz" + if band(bo, 0x10) == 0 then + cn = cn..(band(bo, 8) == 0 and "f" or "t") + end + if band(bo, 0x10) == 0 then x = condfmt(cond) end + name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+") + elseif band(bo, 0x10) == 0 then + cn = map_cond[band(cond, 3) + (band(bo, 8) == 0 and 4 or 0)] + if cond > 3 then x = "cr"..rshift(cond, 2) end + name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+") + end + name = gsub(name, "_", cn) + elseif p == "J" then + x = arshift(lshift(op, 27-rs), 29-rs)*4 + if band(op, 2) == 0 then x = ctx.addr + pos + x end + ctx.rel = x + x = "0x"..tohex(x) + elseif p == "K" then + if band(op, 1) ~= 0 then name = name.."l" end + if band(op, 2) ~= 0 then name = name.."a" end + elseif p == "X" or p == "Y" then + x = band(rshift(op, rs+2), 7) + if x == 0 and p == "Y" then x = nil else x = "cr"..x end + rs = rs - 5 + elseif p == "W" then + x = "cr"..band(op, 7) + elseif p == "Z" then + x = band(rshift(op, rs-4), 255) + rs = rs - 10 + elseif p == ">" then + operands[#operands] = rshift(operands[#operands], 1) + elseif p == "0" then + if last == "r0" then + operands[#operands] = nil + if altname then name = altname end + end + elseif p == "L" then + name = gsub(name, "_", band(op, 0x00200000) ~= 0 and "d" or "w") + elseif p == "." then + if band(op, 1) == 1 then name = name.."." end + elseif p == "N" then + if op == 0x60000000 then name = "nop"; break end + elseif p == "~" then + local n = #operands + operands[n-1], operands[n] = operands[n], operands[n-1] + elseif p == "=" then + local n = #operands + if last == operands[n-1] then + operands[n] = nil + name = altname + end + elseif p == "%" then + local n = #operands + if last == operands[n-1] and last == operands[n-2] then + operands[n] = nil + operands[n-1] = nil + name = altname + end + elseif p == "-" then + rs = rs - 5 + else + assert(false) + end + if x then operands[#operands+1] = x; last = x end + end + + return putop(ctx, name, operands) +end + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + stop = stop - stop % 4 + ctx.pos = ofs - ofs % 4 + ctx.rel = nil + while ctx.pos < stop do disass_ins(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = addr or 0 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 8 + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 32 then return map_gpr[r] end + return "f"..(r-32) +end + +-- Public module functions. +module(...) + +create = create_ +disass = disass_ +regname = regname_ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x64.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x64.lua new file mode 100644 index 0000000..4f49169 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x64.lua @@ -0,0 +1,20 @@ +---------------------------------------------------------------------------- +-- LuaJIT x64 disassembler wrapper module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This module just exports the 64 bit functions from the combined +-- x86/x64 disassembler module. All the interesting stuff is there. +------------------------------------------------------------------------------ + +local require = require + +module(...) + +local dis_x86 = require(_PACKAGE.."dis_x86") + +create = dis_x86.create64 +disass = dis_x86.disass64 +regname = dis_x86.regname64 + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x86.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x86.lua new file mode 100644 index 0000000..0b865ab --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dis_x86.lua @@ -0,0 +1,836 @@ +---------------------------------------------------------------------------- +-- LuaJIT x86/x64 disassembler module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- This is a helper module used by the LuaJIT machine code dumper module. +-- +-- Sending small code snippets to an external disassembler and mixing the +-- output with our own stuff was too fragile. So I had to bite the bullet +-- and write yet another x86 disassembler. Oh well ... +-- +-- The output format is very similar to what ndisasm generates. But it has +-- been developed independently by looking at the opcode tables from the +-- Intel and AMD manuals. The supported instruction set is quite extensive +-- and reflects what a current generation Intel or AMD CPU implements in +-- 32 bit and 64 bit mode. Yes, this includes MMX, SSE, SSE2, SSE3, SSSE3, +-- SSE4.1, SSE4.2, SSE4a and even privileged and hypervisor (VMX/SVM) +-- instructions. +-- +-- Notes: +-- * The (useless) a16 prefix, 3DNow and pre-586 opcodes are unsupported. +-- * No attempt at optimization has been made -- it's fast enough for my needs. +-- * The public API may change when more architectures are added. +------------------------------------------------------------------------------ + +local type = type +local sub, byte, format = string.sub, string.byte, string.format +local match, gmatch, gsub = string.match, string.gmatch, string.gsub +local lower, rep = string.lower, string.rep + +-- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on. +local map_opc1_32 = { +--0x +[0]="addBmr","addVmr","addBrm","addVrm","addBai","addVai","push es","pop es", +"orBmr","orVmr","orBrm","orVrm","orBai","orVai","push cs","opc2*", +--1x +"adcBmr","adcVmr","adcBrm","adcVrm","adcBai","adcVai","push ss","pop ss", +"sbbBmr","sbbVmr","sbbBrm","sbbVrm","sbbBai","sbbVai","push ds","pop ds", +--2x +"andBmr","andVmr","andBrm","andVrm","andBai","andVai","es:seg","daa", +"subBmr","subVmr","subBrm","subVrm","subBai","subVai","cs:seg","das", +--3x +"xorBmr","xorVmr","xorBrm","xorVrm","xorBai","xorVai","ss:seg","aaa", +"cmpBmr","cmpVmr","cmpBrm","cmpVrm","cmpBai","cmpVai","ds:seg","aas", +--4x +"incVR","incVR","incVR","incVR","incVR","incVR","incVR","incVR", +"decVR","decVR","decVR","decVR","decVR","decVR","decVR","decVR", +--5x +"pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR", +"popUR","popUR","popUR","popUR","popUR","popUR","popUR","popUR", +--6x +"sz*pushaw,pusha","sz*popaw,popa","boundVrm","arplWmr", +"fs:seg","gs:seg","o16:","a16", +"pushUi","imulVrmi","pushBs","imulVrms", +"insb","insVS","outsb","outsVS", +--7x +"joBj","jnoBj","jbBj","jnbBj","jzBj","jnzBj","jbeBj","jaBj", +"jsBj","jnsBj","jpeBj","jpoBj","jlBj","jgeBj","jleBj","jgBj", +--8x +"arith!Bmi","arith!Vmi","arith!Bmi","arith!Vms", +"testBmr","testVmr","xchgBrm","xchgVrm", +"movBmr","movVmr","movBrm","movVrm", +"movVmg","leaVrm","movWgm","popUm", +--9x +"nop*xchgVaR|pause|xchgWaR|repne nop","xchgVaR","xchgVaR","xchgVaR", +"xchgVaR","xchgVaR","xchgVaR","xchgVaR", +"sz*cbw,cwde,cdqe","sz*cwd,cdq,cqo","call farViw","wait", +"sz*pushfw,pushf","sz*popfw,popf","sahf","lahf", +--Ax +"movBao","movVao","movBoa","movVoa", +"movsb","movsVS","cmpsb","cmpsVS", +"testBai","testVai","stosb","stosVS", +"lodsb","lodsVS","scasb","scasVS", +--Bx +"movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi", +"movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI", +--Cx +"shift!Bmu","shift!Vmu","retBw","ret","$lesVrm","$ldsVrm","movBmi","movVmi", +"enterBwu","leave","retfBw","retf","int3","intBu","into","iretVS", +--Dx +"shift!Bm1","shift!Vm1","shift!Bmc","shift!Vmc","aamBu","aadBu","salc","xlatb", +"fp*0","fp*1","fp*2","fp*3","fp*4","fp*5","fp*6","fp*7", +--Ex +"loopneBj","loopeBj","loopBj","sz*jcxzBj,jecxzBj,jrcxzBj", +"inBau","inVau","outBua","outVua", +"callVj","jmpVj","jmp farViw","jmpBj","inBad","inVad","outBda","outVda", +--Fx +"lock:","int1","repne:rep","rep:","hlt","cmc","testb!Bm","testv!Vm", +"clc","stc","cli","sti","cld","std","incb!Bm","incd!Vm", +} +assert(#map_opc1_32 == 255) + +-- Map for 1st opcode byte in 64 bit mode (overrides only). +local map_opc1_64 = setmetatable({ + [0x06]=false, [0x07]=false, [0x0e]=false, + [0x16]=false, [0x17]=false, [0x1e]=false, [0x1f]=false, + [0x27]=false, [0x2f]=false, [0x37]=false, [0x3f]=false, + [0x60]=false, [0x61]=false, [0x62]=false, [0x63]="movsxdVrDmt", [0x67]="a32:", + [0x40]="rex*", [0x41]="rex*b", [0x42]="rex*x", [0x43]="rex*xb", + [0x44]="rex*r", [0x45]="rex*rb", [0x46]="rex*rx", [0x47]="rex*rxb", + [0x48]="rex*w", [0x49]="rex*wb", [0x4a]="rex*wx", [0x4b]="rex*wxb", + [0x4c]="rex*wr", [0x4d]="rex*wrb", [0x4e]="rex*wrx", [0x4f]="rex*wrxb", + [0x82]=false, [0x9a]=false, [0xc4]=false, [0xc5]=false, [0xce]=false, + [0xd4]=false, [0xd5]=false, [0xd6]=false, [0xea]=false, +}, { __index = map_opc1_32 }) + +-- Map for 2nd opcode byte (0F xx). True CISC hell. Hey, I told you. +-- Prefix dependent MMX/SSE opcodes: (none)|rep|o16|repne, -|F3|66|F2 +local map_opc2 = { +--0x +[0]="sldt!Dmp","sgdt!Ump","larVrm","lslVrm",nil,"syscall","clts","sysret", +"invd","wbinvd",nil,"ud1",nil,"$prefetch!Bm","femms","3dnowMrmu", +--1x +"movupsXrm|movssXrm|movupdXrm|movsdXrm", +"movupsXmr|movssXmr|movupdXmr|movsdXmr", +"movhlpsXrm$movlpsXrm|movsldupXrm|movlpdXrm|movddupXrm", +"movlpsXmr||movlpdXmr", +"unpcklpsXrm||unpcklpdXrm", +"unpckhpsXrm||unpckhpdXrm", +"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm", +"movhpsXmr||movhpdXmr", +"$prefetcht!Bm","hintnopVm","hintnopVm","hintnopVm", +"hintnopVm","hintnopVm","hintnopVm","hintnopVm", +--2x +"movUmx$","movUmy$","movUxm$","movUym$","movUmz$",nil,"movUzm$",nil, +"movapsXrm||movapdXrm", +"movapsXmr||movapdXmr", +"cvtpi2psXrMm|cvtsi2ssXrVmt|cvtpi2pdXrMm|cvtsi2sdXrVmt", +"movntpsXmr|movntssXmr|movntpdXmr|movntsdXmr", +"cvttps2piMrXm|cvttss2siVrXm|cvttpd2piMrXm|cvttsd2siVrXm", +"cvtps2piMrXm|cvtss2siVrXm|cvtpd2piMrXm|cvtsd2siVrXm", +"ucomissXrm||ucomisdXrm", +"comissXrm||comisdXrm", +--3x +"wrmsr","rdtsc","rdmsr","rdpmc","sysenter","sysexit",nil,"getsec", +"opc3*38",nil,"opc3*3a",nil,nil,nil,nil,nil, +--4x +"cmovoVrm","cmovnoVrm","cmovbVrm","cmovnbVrm", +"cmovzVrm","cmovnzVrm","cmovbeVrm","cmovaVrm", +"cmovsVrm","cmovnsVrm","cmovpeVrm","cmovpoVrm", +"cmovlVrm","cmovgeVrm","cmovleVrm","cmovgVrm", +--5x +"movmskpsVrXm$||movmskpdVrXm$","sqrtpsXrm|sqrtssXrm|sqrtpdXrm|sqrtsdXrm", +"rsqrtpsXrm|rsqrtssXrm","rcppsXrm|rcpssXrm", +"andpsXrm||andpdXrm","andnpsXrm||andnpdXrm", +"orpsXrm||orpdXrm","xorpsXrm||xorpdXrm", +"addpsXrm|addssXrm|addpdXrm|addsdXrm","mulpsXrm|mulssXrm|mulpdXrm|mulsdXrm", +"cvtps2pdXrm|cvtss2sdXrm|cvtpd2psXrm|cvtsd2ssXrm", +"cvtdq2psXrm|cvttps2dqXrm|cvtps2dqXrm", +"subpsXrm|subssXrm|subpdXrm|subsdXrm","minpsXrm|minssXrm|minpdXrm|minsdXrm", +"divpsXrm|divssXrm|divpdXrm|divsdXrm","maxpsXrm|maxssXrm|maxpdXrm|maxsdXrm", +--6x +"punpcklbwPrm","punpcklwdPrm","punpckldqPrm","packsswbPrm", +"pcmpgtbPrm","pcmpgtwPrm","pcmpgtdPrm","packuswbPrm", +"punpckhbwPrm","punpckhwdPrm","punpckhdqPrm","packssdwPrm", +"||punpcklqdqXrm","||punpckhqdqXrm", +"movPrVSm","movqMrm|movdquXrm|movdqaXrm", +--7x +"pshufwMrmu|pshufhwXrmu|pshufdXrmu|pshuflwXrmu","pshiftw!Pmu", +"pshiftd!Pmu","pshiftq!Mmu||pshiftdq!Xmu", +"pcmpeqbPrm","pcmpeqwPrm","pcmpeqdPrm","emms|", +"vmreadUmr||extrqXmuu$|insertqXrmuu$","vmwriteUrm||extrqXrm$|insertqXrm$", +nil,nil, +"||haddpdXrm|haddpsXrm","||hsubpdXrm|hsubpsXrm", +"movVSmMr|movqXrm|movVSmXr","movqMmr|movdquXmr|movdqaXmr", +--8x +"joVj","jnoVj","jbVj","jnbVj","jzVj","jnzVj","jbeVj","jaVj", +"jsVj","jnsVj","jpeVj","jpoVj","jlVj","jgeVj","jleVj","jgVj", +--9x +"setoBm","setnoBm","setbBm","setnbBm","setzBm","setnzBm","setbeBm","setaBm", +"setsBm","setnsBm","setpeBm","setpoBm","setlBm","setgeBm","setleBm","setgBm", +--Ax +"push fs","pop fs","cpuid","btVmr","shldVmru","shldVmrc",nil,nil, +"push gs","pop gs","rsm","btsVmr","shrdVmru","shrdVmrc","fxsave!Dmp","imulVrm", +--Bx +"cmpxchgBmr","cmpxchgVmr","$lssVrm","btrVmr", +"$lfsVrm","$lgsVrm","movzxVrBmt","movzxVrWmt", +"|popcntVrm","ud2Dp","bt!Vmu","btcVmr", +"bsfVrm","bsrVrm|lzcntVrm|bsrWrm","movsxVrBmt","movsxVrWmt", +--Cx +"xaddBmr","xaddVmr", +"cmppsXrmu|cmpssXrmu|cmppdXrmu|cmpsdXrmu","$movntiVmr|", +"pinsrwPrWmu","pextrwDrPmu", +"shufpsXrmu||shufpdXrmu","$cmpxchg!Qmp", +"bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR", +--Dx +"||addsubpdXrm|addsubpsXrm","psrlwPrm","psrldPrm","psrlqPrm", +"paddqPrm","pmullwPrm", +"|movq2dqXrMm|movqXmr|movdq2qMrXm$","pmovmskbVrMm||pmovmskbVrXm", +"psubusbPrm","psubuswPrm","pminubPrm","pandPrm", +"paddusbPrm","padduswPrm","pmaxubPrm","pandnPrm", +--Ex +"pavgbPrm","psrawPrm","psradPrm","pavgwPrm", +"pmulhuwPrm","pmulhwPrm", +"|cvtdq2pdXrm|cvttpd2dqXrm|cvtpd2dqXrm","$movntqMmr||$movntdqXmr", +"psubsbPrm","psubswPrm","pminswPrm","porPrm", +"paddsbPrm","paddswPrm","pmaxswPrm","pxorPrm", +--Fx +"|||lddquXrm","psllwPrm","pslldPrm","psllqPrm", +"pmuludqPrm","pmaddwdPrm","psadbwPrm","maskmovqMrm||maskmovdquXrm$", +"psubbPrm","psubwPrm","psubdPrm","psubqPrm", +"paddbPrm","paddwPrm","padddPrm","ud", +} +assert(map_opc2[255] == "ud") + +-- Map for three-byte opcodes. Can't wait for their next invention. +local map_opc3 = { +["38"] = { -- [66] 0f 38 xx +--0x +[0]="pshufbPrm","phaddwPrm","phadddPrm","phaddswPrm", +"pmaddubswPrm","phsubwPrm","phsubdPrm","phsubswPrm", +"psignbPrm","psignwPrm","psigndPrm","pmulhrswPrm", +nil,nil,nil,nil, +--1x +"||pblendvbXrma",nil,nil,nil, +"||blendvpsXrma","||blendvpdXrma",nil,"||ptestXrm", +nil,nil,nil,nil, +"pabsbPrm","pabswPrm","pabsdPrm",nil, +--2x +"||pmovsxbwXrm","||pmovsxbdXrm","||pmovsxbqXrm","||pmovsxwdXrm", +"||pmovsxwqXrm","||pmovsxdqXrm",nil,nil, +"||pmuldqXrm","||pcmpeqqXrm","||$movntdqaXrm","||packusdwXrm", +nil,nil,nil,nil, +--3x +"||pmovzxbwXrm","||pmovzxbdXrm","||pmovzxbqXrm","||pmovzxwdXrm", +"||pmovzxwqXrm","||pmovzxdqXrm",nil,"||pcmpgtqXrm", +"||pminsbXrm","||pminsdXrm","||pminuwXrm","||pminudXrm", +"||pmaxsbXrm","||pmaxsdXrm","||pmaxuwXrm","||pmaxudXrm", +--4x +"||pmulddXrm","||phminposuwXrm", +--Fx +[0xf0] = "|||crc32TrBmt",[0xf1] = "|||crc32TrVmt", +}, + +["3a"] = { -- [66] 0f 3a xx +--0x +[0x00]=nil,nil,nil,nil,nil,nil,nil,nil, +"||roundpsXrmu","||roundpdXrmu","||roundssXrmu","||roundsdXrmu", +"||blendpsXrmu","||blendpdXrmu","||pblendwXrmu","palignrPrmu", +--1x +nil,nil,nil,nil, +"||pextrbVmXru","||pextrwVmXru","||pextrVmSXru","||extractpsVmXru", +nil,nil,nil,nil,nil,nil,nil,nil, +--2x +"||pinsrbXrVmu","||insertpsXrmu","||pinsrXrVmuS",nil, +--4x +[0x40] = "||dppsXrmu", +[0x41] = "||dppdXrmu", +[0x42] = "||mpsadbwXrmu", +--6x +[0x60] = "||pcmpestrmXrmu",[0x61] = "||pcmpestriXrmu", +[0x62] = "||pcmpistrmXrmu",[0x63] = "||pcmpistriXrmu", +}, +} + +-- Map for VMX/SVM opcodes 0F 01 C0-FF (sgdt group with register operands). +local map_opcvm = { +[0xc1]="vmcall",[0xc2]="vmlaunch",[0xc3]="vmresume",[0xc4]="vmxoff", +[0xc8]="monitor",[0xc9]="mwait", +[0xd8]="vmrun",[0xd9]="vmmcall",[0xda]="vmload",[0xdb]="vmsave", +[0xdc]="stgi",[0xdd]="clgi",[0xde]="skinit",[0xdf]="invlpga", +[0xf8]="swapgs",[0xf9]="rdtscp", +} + +-- Map for FP opcodes. And you thought stack machines are simple? +local map_opcfp = { +-- D8-DF 00-BF: opcodes with a memory operand. +-- D8 +[0]="faddFm","fmulFm","fcomFm","fcompFm","fsubFm","fsubrFm","fdivFm","fdivrFm", +"fldFm",nil,"fstFm","fstpFm","fldenvVm","fldcwWm","fnstenvVm","fnstcwWm", +-- DA +"fiaddDm","fimulDm","ficomDm","ficompDm", +"fisubDm","fisubrDm","fidivDm","fidivrDm", +-- DB +"fildDm","fisttpDm","fistDm","fistpDm",nil,"fld twordFmp",nil,"fstp twordFmp", +-- DC +"faddGm","fmulGm","fcomGm","fcompGm","fsubGm","fsubrGm","fdivGm","fdivrGm", +-- DD +"fldGm","fisttpQm","fstGm","fstpGm","frstorDmp",nil,"fnsaveDmp","fnstswWm", +-- DE +"fiaddWm","fimulWm","ficomWm","ficompWm", +"fisubWm","fisubrWm","fidivWm","fidivrWm", +-- DF +"fildWm","fisttpWm","fistWm","fistpWm", +"fbld twordFmp","fildQm","fbstp twordFmp","fistpQm", +-- xx C0-FF: opcodes with a pseudo-register operand. +-- D8 +"faddFf","fmulFf","fcomFf","fcompFf","fsubFf","fsubrFf","fdivFf","fdivrFf", +-- D9 +"fldFf","fxchFf",{"fnop"},nil, +{"fchs","fabs",nil,nil,"ftst","fxam"}, +{"fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz"}, +{"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp"}, +{"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"}, +-- DA +"fcmovbFf","fcmoveFf","fcmovbeFf","fcmovuFf",nil,{nil,"fucompp"},nil,nil, +-- DB +"fcmovnbFf","fcmovneFf","fcmovnbeFf","fcmovnuFf", +{nil,nil,"fnclex","fninit"},"fucomiFf","fcomiFf",nil, +-- DC +"fadd toFf","fmul toFf",nil,nil, +"fsub toFf","fsubr toFf","fdivr toFf","fdiv toFf", +-- DD +"ffreeFf",nil,"fstFf","fstpFf","fucomFf","fucompFf",nil,nil, +-- DE +"faddpFf","fmulpFf",nil,{nil,"fcompp"}, +"fsubrpFf","fsubpFf","fdivrpFf","fdivpFf", +-- DF +nil,nil,nil,nil,{"fnstsw ax"},"fucomipFf","fcomipFf",nil, +} +assert(map_opcfp[126] == "fcomipFf") + +-- Map for opcode groups. The subkey is sp from the ModRM byte. +local map_opcgroup = { + arith = { "add", "or", "adc", "sbb", "and", "sub", "xor", "cmp" }, + shift = { "rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar" }, + testb = { "testBmi", "testBmi", "not", "neg", "mul", "imul", "div", "idiv" }, + testv = { "testVmi", "testVmi", "not", "neg", "mul", "imul", "div", "idiv" }, + incb = { "inc", "dec" }, + incd = { "inc", "dec", "callUmp", "$call farDmp", + "jmpUmp", "$jmp farDmp", "pushUm" }, + sldt = { "sldt", "str", "lldt", "ltr", "verr", "verw" }, + sgdt = { "vm*$sgdt", "vm*$sidt", "$lgdt", "vm*$lidt", + "smsw", nil, "lmsw", "vm*$invlpg" }, + bt = { nil, nil, nil, nil, "bt", "bts", "btr", "btc" }, + cmpxchg = { nil, "sz*,cmpxchg8bQmp,cmpxchg16bXmp", nil, nil, + nil, nil, "vmptrld|vmxon|vmclear", "vmptrst" }, + pshiftw = { nil, nil, "psrlw", nil, "psraw", nil, "psllw" }, + pshiftd = { nil, nil, "psrld", nil, "psrad", nil, "pslld" }, + pshiftq = { nil, nil, "psrlq", nil, nil, nil, "psllq" }, + pshiftdq = { nil, nil, "psrlq", "psrldq", nil, nil, "psllq", "pslldq" }, + fxsave = { "$fxsave", "$fxrstor", "$ldmxcsr", "$stmxcsr", + nil, "lfenceDp$", "mfenceDp$", "sfenceDp$clflush" }, + prefetch = { "prefetch", "prefetchw" }, + prefetcht = { "prefetchnta", "prefetcht0", "prefetcht1", "prefetcht2" }, +} + +------------------------------------------------------------------------------ + +-- Maps for register names. +local map_regs = { + B = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh", + "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" }, + B64 = { "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil", + "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" }, + W = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", + "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w" }, + D = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", + "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" }, + Q = { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" }, + M = { "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", + "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7" }, -- No x64 ext! + X = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", + "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" }, +} +local map_segregs = { "es", "cs", "ss", "ds", "fs", "gs", "segr6", "segr7" } + +-- Maps for size names. +local map_sz2n = { + B = 1, W = 2, D = 4, Q = 8, M = 8, X = 16, +} +local map_sz2prefix = { + B = "byte", W = "word", D = "dword", + Q = "qword", + M = "qword", X = "xword", + F = "dword", G = "qword", -- No need for sizes/register names for these two. +} + +------------------------------------------------------------------------------ + +-- Output a nicely formatted line with an opcode and operands. +local function putop(ctx, text, operands) + local code, pos, hex = ctx.code, ctx.pos, "" + local hmax = ctx.hexdump + if hmax > 0 then + for i=ctx.start,pos-1 do + hex = hex..format("%02X", byte(code, i, i)) + end + if #hex > hmax then hex = sub(hex, 1, hmax)..". " + else hex = hex..rep(" ", hmax-#hex+2) end + end + if operands then text = text.." "..operands end + if ctx.o16 then text = "o16 "..text; ctx.o16 = false end + if ctx.a32 then text = "a32 "..text; ctx.a32 = false end + if ctx.rep then text = ctx.rep.." "..text; ctx.rep = false end + if ctx.rex then + local t = (ctx.rexw and "w" or "")..(ctx.rexr and "r" or "").. + (ctx.rexx and "x" or "")..(ctx.rexb and "b" or "") + if t ~= "" then text = "rex."..t.." "..text end + ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false + ctx.rex = false + end + if ctx.seg then + local text2, n = gsub(text, "%[", "["..ctx.seg..":") + if n == 0 then text = ctx.seg.." "..text else text = text2 end + ctx.seg = false + end + if ctx.lock then text = "lock "..text; ctx.lock = false end + local imm = ctx.imm + if imm then + local sym = ctx.symtab[imm] + if sym then text = text.."\t->"..sym end + end + ctx.out(format("%08x %s%s\n", ctx.addr+ctx.start, hex, text)) + ctx.mrm = false + ctx.start = pos + ctx.imm = nil +end + +-- Clear all prefix flags. +local function clearprefixes(ctx) + ctx.o16 = false; ctx.seg = false; ctx.lock = false; ctx.rep = false + ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false + ctx.rex = false; ctx.a32 = false +end + +-- Fallback for incomplete opcodes at the end. +local function incomplete(ctx) + ctx.pos = ctx.stop+1 + clearprefixes(ctx) + return putop(ctx, "(incomplete)") +end + +-- Fallback for unknown opcodes. +local function unknown(ctx) + clearprefixes(ctx) + return putop(ctx, "(unknown)") +end + +-- Return an immediate of the specified size. +local function getimm(ctx, pos, n) + if pos+n-1 > ctx.stop then return incomplete(ctx) end + local code = ctx.code + if n == 1 then + local b1 = byte(code, pos, pos) + return b1 + elseif n == 2 then + local b1, b2 = byte(code, pos, pos+1) + return b1+b2*256 + else + local b1, b2, b3, b4 = byte(code, pos, pos+3) + local imm = b1+b2*256+b3*65536+b4*16777216 + ctx.imm = imm + return imm + end +end + +-- Process pattern string and generate the operands. +local function putpat(ctx, name, pat) + local operands, regs, sz, mode, sp, rm, sc, rx, sdisp + local code, pos, stop = ctx.code, ctx.pos, ctx.stop + + -- Chars used: 1DFGIMPQRSTUVWXacdfgijmoprstuwxyz + for p in gmatch(pat, ".") do + local x = nil + if p == "V" or p == "U" then + if ctx.rexw then sz = "Q"; ctx.rexw = false + elseif ctx.o16 then sz = "W"; ctx.o16 = false + elseif p == "U" and ctx.x64 then sz = "Q" + else sz = "D" end + regs = map_regs[sz] + elseif p == "T" then + if ctx.rexw then sz = "Q"; ctx.rexw = false else sz = "D" end + regs = map_regs[sz] + elseif p == "B" then + sz = "B" + regs = ctx.rex and map_regs.B64 or map_regs.B + elseif match(p, "[WDQMXFG]") then + sz = p + regs = map_regs[sz] + elseif p == "P" then + sz = ctx.o16 and "X" or "M"; ctx.o16 = false + regs = map_regs[sz] + elseif p == "S" then + name = name..lower(sz) + elseif p == "s" then + local imm = getimm(ctx, pos, 1); if not imm then return end + x = imm <= 127 and format("+0x%02x", imm) + or format("-0x%02x", 256-imm) + pos = pos+1 + elseif p == "u" then + local imm = getimm(ctx, pos, 1); if not imm then return end + x = format("0x%02x", imm) + pos = pos+1 + elseif p == "w" then + local imm = getimm(ctx, pos, 2); if not imm then return end + x = format("0x%x", imm) + pos = pos+2 + elseif p == "o" then -- [offset] + if ctx.x64 then + local imm1 = getimm(ctx, pos, 4); if not imm1 then return end + local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end + x = format("[0x%08x%08x]", imm2, imm1) + pos = pos+8 + else + local imm = getimm(ctx, pos, 4); if not imm then return end + x = format("[0x%08x]", imm) + pos = pos+4 + end + elseif p == "i" or p == "I" then + local n = map_sz2n[sz] + if n == 8 and ctx.x64 and p == "I" then + local imm1 = getimm(ctx, pos, 4); if not imm1 then return end + local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end + x = format("0x%08x%08x", imm2, imm1) + else + if n == 8 then n = 4 end + local imm = getimm(ctx, pos, n); if not imm then return end + if sz == "Q" and (imm < 0 or imm > 0x7fffffff) then + imm = (0xffffffff+1)-imm + x = format(imm > 65535 and "-0x%08x" or "-0x%x", imm) + else + x = format(imm > 65535 and "0x%08x" or "0x%x", imm) + end + end + pos = pos+n + elseif p == "j" then + local n = map_sz2n[sz] + if n == 8 then n = 4 end + local imm = getimm(ctx, pos, n); if not imm then return end + if sz == "B" and imm > 127 then imm = imm-256 + elseif imm > 2147483647 then imm = imm-4294967296 end + pos = pos+n + imm = imm + pos + ctx.addr + if imm > 4294967295 and not ctx.x64 then imm = imm-4294967296 end + ctx.imm = imm + if sz == "W" then + x = format("word 0x%04x", imm%65536) + elseif ctx.x64 then + local lo = imm % 0x1000000 + x = format("0x%02x%06x", (imm-lo) / 0x1000000, lo) + else + x = format("0x%08x", imm) + end + elseif p == "R" then + local r = byte(code, pos-1, pos-1)%8 + if ctx.rexb then r = r + 8; ctx.rexb = false end + x = regs[r+1] + elseif p == "a" then x = regs[1] + elseif p == "c" then x = "cl" + elseif p == "d" then x = "dx" + elseif p == "1" then x = "1" + else + if not mode then + mode = ctx.mrm + if not mode then + if pos > stop then return incomplete(ctx) end + mode = byte(code, pos, pos) + pos = pos+1 + end + rm = mode%8; mode = (mode-rm)/8 + sp = mode%8; mode = (mode-sp)/8 + sdisp = "" + if mode < 3 then + if rm == 4 then + if pos > stop then return incomplete(ctx) end + sc = byte(code, pos, pos) + pos = pos+1 + rm = sc%8; sc = (sc-rm)/8 + rx = sc%8; sc = (sc-rx)/8 + if ctx.rexx then rx = rx + 8; ctx.rexx = false end + if rx == 4 then rx = nil end + end + if mode > 0 or rm == 5 then + local dsz = mode + if dsz ~= 1 then dsz = 4 end + local disp = getimm(ctx, pos, dsz); if not disp then return end + if mode == 0 then rm = nil end + if rm or rx or (not sc and ctx.x64 and not ctx.a32) then + if dsz == 1 and disp > 127 then + sdisp = format("-0x%x", 256-disp) + elseif disp >= 0 and disp <= 0x7fffffff then + sdisp = format("+0x%x", disp) + else + sdisp = format("-0x%x", (0xffffffff+1)-disp) + end + else + sdisp = format(ctx.x64 and not ctx.a32 and + not (disp >= 0 and disp <= 0x7fffffff) + and "0xffffffff%08x" or "0x%08x", disp) + end + pos = pos+dsz + end + end + if rm and ctx.rexb then rm = rm + 8; ctx.rexb = false end + if ctx.rexr then sp = sp + 8; ctx.rexr = false end + end + if p == "m" then + if mode == 3 then x = regs[rm+1] + else + local aregs = ctx.a32 and map_regs.D or ctx.aregs + local srm, srx = "", "" + if rm then srm = aregs[rm+1] + elseif not sc and ctx.x64 and not ctx.a32 then srm = "rip" end + ctx.a32 = false + if rx then + if rm then srm = srm.."+" end + srx = aregs[rx+1] + if sc > 0 then srx = srx.."*"..(2^sc) end + end + x = format("[%s%s%s]", srm, srx, sdisp) + end + if mode < 3 and + (not match(pat, "[aRrgp]") or match(pat, "t")) then -- Yuck. + x = map_sz2prefix[sz].." "..x + end + elseif p == "r" then x = regs[sp+1] + elseif p == "g" then x = map_segregs[sp+1] + elseif p == "p" then -- Suppress prefix. + elseif p == "f" then x = "st"..rm + elseif p == "x" then + if sp == 0 and ctx.lock and not ctx.x64 then + x = "CR8"; ctx.lock = false + else + x = "CR"..sp + end + elseif p == "y" then x = "DR"..sp + elseif p == "z" then x = "TR"..sp + elseif p == "t" then + else + error("bad pattern `"..pat.."'") + end + end + if x then operands = operands and operands..", "..x or x end + end + ctx.pos = pos + return putop(ctx, name, operands) +end + +-- Forward declaration. +local map_act + +-- Fetch and cache MRM byte. +local function getmrm(ctx) + local mrm = ctx.mrm + if not mrm then + local pos = ctx.pos + if pos > ctx.stop then return nil end + mrm = byte(ctx.code, pos, pos) + ctx.pos = pos+1 + ctx.mrm = mrm + end + return mrm +end + +-- Dispatch to handler depending on pattern. +local function dispatch(ctx, opat, patgrp) + if not opat then return unknown(ctx) end + if match(opat, "%|") then -- MMX/SSE variants depending on prefix. + local p + if ctx.rep then + p = ctx.rep=="rep" and "%|([^%|]*)" or "%|[^%|]*%|[^%|]*%|([^%|]*)" + ctx.rep = false + elseif ctx.o16 then p = "%|[^%|]*%|([^%|]*)"; ctx.o16 = false + else p = "^[^%|]*" end + opat = match(opat, p) + if not opat then return unknown(ctx) end +-- ctx.rep = false; ctx.o16 = false + --XXX fails for 66 f2 0f 38 f1 06 crc32 eax,WORD PTR [esi] + --XXX remove in branches? + end + if match(opat, "%$") then -- reg$mem variants. + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + opat = match(opat, mrm >= 192 and "^[^%$]*" or "%$(.*)") + if opat == "" then return unknown(ctx) end + end + if opat == "" then return unknown(ctx) end + local name, pat = match(opat, "^([a-z0-9 ]*)(.*)") + if pat == "" and patgrp then pat = patgrp end + return map_act[sub(pat, 1, 1)](ctx, name, pat) +end + +-- Get a pattern from an opcode map and dispatch to handler. +local function dispatchmap(ctx, opcmap) + local pos = ctx.pos + local opat = opcmap[byte(ctx.code, pos, pos)] + pos = pos + 1 + ctx.pos = pos + return dispatch(ctx, opat) +end + +-- Map for action codes. The key is the first char after the name. +map_act = { + -- Simple opcodes without operands. + [""] = function(ctx, name, pat) + return putop(ctx, name) + end, + + -- Operand size chars fall right through. + B = putpat, W = putpat, D = putpat, Q = putpat, + V = putpat, U = putpat, T = putpat, + M = putpat, X = putpat, P = putpat, + F = putpat, G = putpat, + + -- Collect prefixes. + [":"] = function(ctx, name, pat) + ctx[pat == ":" and name or sub(pat, 2)] = name + if ctx.pos - ctx.start > 5 then return unknown(ctx) end -- Limit #prefixes. + end, + + -- Chain to special handler specified by name. + ["*"] = function(ctx, name, pat) + return map_act[name](ctx, name, sub(pat, 2)) + end, + + -- Use named subtable for opcode group. + ["!"] = function(ctx, name, pat) + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + return dispatch(ctx, map_opcgroup[name][((mrm-(mrm%8))/8)%8+1], sub(pat, 2)) + end, + + -- o16,o32[,o64] variants. + sz = function(ctx, name, pat) + if ctx.o16 then ctx.o16 = false + else + pat = match(pat, ",(.*)") + if ctx.rexw then + local p = match(pat, ",(.*)") + if p then pat = p; ctx.rexw = false end + end + end + pat = match(pat, "^[^,]*") + return dispatch(ctx, pat) + end, + + -- Two-byte opcode dispatch. + opc2 = function(ctx, name, pat) + return dispatchmap(ctx, map_opc2) + end, + + -- Three-byte opcode dispatch. + opc3 = function(ctx, name, pat) + return dispatchmap(ctx, map_opc3[pat]) + end, + + -- VMX/SVM dispatch. + vm = function(ctx, name, pat) + return dispatch(ctx, map_opcvm[ctx.mrm]) + end, + + -- Floating point opcode dispatch. + fp = function(ctx, name, pat) + local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end + local rm = mrm%8 + local idx = pat*8 + ((mrm-rm)/8)%8 + if mrm >= 192 then idx = idx + 64 end + local opat = map_opcfp[idx] + if type(opat) == "table" then opat = opat[rm+1] end + return dispatch(ctx, opat) + end, + + -- REX prefix. + rex = function(ctx, name, pat) + if ctx.rex then return unknown(ctx) end -- Only 1 REX prefix allowed. + for p in gmatch(pat, ".") do ctx["rex"..p] = true end + ctx.rex = true + end, + + -- Special case for nop with REX prefix. + nop = function(ctx, name, pat) + return dispatch(ctx, ctx.rex and pat or "nop") + end, +} + +------------------------------------------------------------------------------ + +-- Disassemble a block of code. +local function disass_block(ctx, ofs, len) + if not ofs then ofs = 0 end + local stop = len and ofs+len or #ctx.code + ofs = ofs + 1 + ctx.start = ofs + ctx.pos = ofs + ctx.stop = stop + ctx.imm = nil + ctx.mrm = false + clearprefixes(ctx) + while ctx.pos <= stop do dispatchmap(ctx, ctx.map1) end + if ctx.pos ~= ctx.start then incomplete(ctx) end +end + +-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). +local function create_(code, addr, out) + local ctx = {} + ctx.code = code + ctx.addr = (addr or 0) - 1 + ctx.out = out or io.write + ctx.symtab = {} + ctx.disass = disass_block + ctx.hexdump = 16 + ctx.x64 = false + ctx.map1 = map_opc1_32 + ctx.aregs = map_regs.D + return ctx +end + +local function create64_(code, addr, out) + local ctx = create_(code, addr, out) + ctx.x64 = true + ctx.map1 = map_opc1_64 + ctx.aregs = map_regs.Q + return ctx +end + +-- Simple API: disassemble code (a string) at address and output via out. +local function disass_(code, addr, out) + create_(code, addr, out):disass() +end + +local function disass64_(code, addr, out) + create64_(code, addr, out):disass() +end + +-- Return register name for RID. +local function regname_(r) + if r < 8 then return map_regs.D[r+1] end + return map_regs.X[r-7] +end + +local function regname64_(r) + if r < 16 then return map_regs.Q[r+1] end + return map_regs.X[r-15] +end + +-- Public module functions. +module(...) + +create = create_ +create64 = create64_ +disass = disass_ +disass64 = disass64_ +regname = regname_ +regname64 = regname64_ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dump.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dump.lua new file mode 100644 index 0000000..556ce88 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/dump.lua @@ -0,0 +1,699 @@ +---------------------------------------------------------------------------- +-- LuaJIT compiler dump module. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module can be used to debug the JIT compiler itself. It dumps the +-- code representations and structures used in various compiler stages. +-- +-- Example usage: +-- +-- luajit -jdump -e "local x=0; for i=1,1e6 do x=x+i end; print(x)" +-- luajit -jdump=im -e "for i=1,1000 do for j=1,1000 do end end" | less -R +-- luajit -jdump=is myapp.lua | less -R +-- luajit -jdump=-b myapp.lua +-- luajit -jdump=+aH,myapp.html myapp.lua +-- luajit -jdump=ixT,myapp.dump myapp.lua +-- +-- The first argument specifies the dump mode. The second argument gives +-- the output file name. Default output is to stdout, unless the environment +-- variable LUAJIT_DUMPFILE is set. The file is overwritten every time the +-- module is started. +-- +-- Different features can be turned on or off with the dump mode. If the +-- mode starts with a '+', the following features are added to the default +-- set of features; a '-' removes them. Otherwise the features are replaced. +-- +-- The following dump features are available (* marks the default): +-- +-- * t Print a line for each started, ended or aborted trace (see also -jv). +-- * b Dump the traced bytecode. +-- * i Dump the IR (intermediate representation). +-- r Augment the IR with register/stack slots. +-- s Dump the snapshot map. +-- * m Dump the generated machine code. +-- x Print each taken trace exit. +-- X Print each taken trace exit and the contents of all registers. +-- a Print the IR of aborted traces, too. +-- +-- The output format can be set with the following characters: +-- +-- T Plain text output. +-- A ANSI-colored text output +-- H Colorized HTML + CSS output. +-- +-- The default output format is plain text. It's set to ANSI-colored text +-- if the COLORTERM variable is set. Note: this is independent of any output +-- redirection, which is actually considered a feature. +-- +-- You probably want to use less -R to enjoy viewing ANSI-colored text from +-- a pipe or a file. Add this to your ~/.bashrc: export LESS="-R" +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc +local traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek +local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap +local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr +local bit = require("bit") +local band, shl, shr = bit.band, bit.lshift, bit.rshift +local sub, gsub, format = string.sub, string.gsub, string.format +local byte, char, rep = string.byte, string.char, string.rep +local type, tostring = type, tostring +local stdout, stderr = io.stdout, io.stderr + +-- Load other modules on-demand. +local bcline, disass + +-- Active flag, output file handle and dump mode. +local active, out, dumpmode + +------------------------------------------------------------------------------ + +local symtabmt = { __index = false } +local symtab = {} +local nexitsym = 0 + +-- Fill nested symbol table with per-trace exit stub addresses. +local function fillsymtab_tr(tr, nexit) + local t = {} + symtabmt.__index = t + if jit.arch == "mips" or jit.arch == "mipsel" then + t[traceexitstub(tr, 0)] = "exit" + return + end + for i=0,nexit-1 do + local addr = traceexitstub(tr, i) + t[addr] = tostring(i) + end + local addr = traceexitstub(tr, nexit) + if addr then t[addr] = "stack_check" end +end + +-- Fill symbol table with trace exit stub addresses. +local function fillsymtab(tr, nexit) + local t = symtab + if nexitsym == 0 then + local ircall = vmdef.ircall + for i=0,#ircall do + local addr = ircalladdr(i) + if addr ~= 0 then t[addr] = ircall[i] end + end + end + if nexitsym == 1000000 then -- Per-trace exit stubs. + fillsymtab_tr(tr, nexit) + elseif nexit > nexitsym then -- Shared exit stubs. + for i=nexitsym,nexit-1 do + local addr = traceexitstub(i) + if addr == nil then -- Fall back to per-trace exit stubs. + fillsymtab_tr(tr, nexit) + setmetatable(symtab, symtabmt) + nexit = 1000000 + break + end + t[addr] = tostring(i) + end + nexitsym = nexit + end + return t +end + +local function dumpwrite(s) + out:write(s) +end + +-- Disassemble machine code. +local function dump_mcode(tr) + local info = traceinfo(tr) + if not info then return end + local mcode, addr, loop = tracemc(tr) + if not mcode then return end + if not disass then disass = require("jit.dis_"..jit.arch) end + out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") + local ctx = disass.create(mcode, addr, dumpwrite) + ctx.hexdump = 0 + ctx.symtab = fillsymtab(tr, info.nexit) + if loop ~= 0 then + symtab[addr+loop] = "LOOP" + ctx:disass(0, loop) + out:write("->LOOP:\n") + ctx:disass(loop, #mcode-loop) + symtab[addr+loop] = nil + else + ctx:disass(0, #mcode) + end +end + +------------------------------------------------------------------------------ + +local irtype_text = { + [0] = "nil", + "fal", + "tru", + "lud", + "str", + "p32", + "thr", + "pro", + "fun", + "p64", + "cdt", + "tab", + "udt", + "flt", + "num", + "i8 ", + "u8 ", + "i16", + "u16", + "int", + "u32", + "i64", + "u64", + "sfp", +} + +local colortype_ansi = { + [0] = "%s", + "%s", + "%s", + "\027[36m%s\027[m", + "\027[32m%s\027[m", + "%s", + "\027[1m%s\027[m", + "%s", + "\027[1m%s\027[m", + "%s", + "\027[33m%s\027[m", + "\027[31m%s\027[m", + "\027[36m%s\027[m", + "\027[34m%s\027[m", + "\027[34m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", + "\027[35m%s\027[m", +} + +local function colorize_text(s, t) + return s +end + +local function colorize_ansi(s, t) + return format(colortype_ansi[t], s) +end + +local irtype_ansi = setmetatable({}, + { __index = function(tab, t) + local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end }) + +local html_escape = { ["<"] = "<", [">"] = ">", ["&"] = "&", } + +local function colorize_html(s, t) + s = gsub(s, "[<>&]", html_escape) + return format('%s', irtype_text[t], s) +end + +local irtype_html = setmetatable({}, + { __index = function(tab, t) + local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end }) + +local header_html = [[ + +]] + +local colorize, irtype + +-- Lookup tables to convert some literals into names. +local litname = { + ["SLOAD "] = setmetatable({}, { __index = function(t, mode) + local s = "" + if band(mode, 1) ~= 0 then s = s.."P" end + if band(mode, 2) ~= 0 then s = s.."F" end + if band(mode, 4) ~= 0 then s = s.."T" end + if band(mode, 8) ~= 0 then s = s.."C" end + if band(mode, 16) ~= 0 then s = s.."R" end + if band(mode, 32) ~= 0 then s = s.."I" end + t[mode] = s + return s + end}), + ["XLOAD "] = { [0] = "", "R", "V", "RV", "U", "RU", "VU", "RVU", }, + ["CONV "] = setmetatable({}, { __index = function(t, mode) + local s = irtype[band(mode, 31)] + s = irtype[band(shr(mode, 5), 31)].."."..s + if band(mode, 0x400) ~= 0 then s = s.." trunc" + elseif band(mode, 0x800) ~= 0 then s = s.." sext" end + local c = shr(mode, 14) + if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end + t[mode] = s + return s + end}), + ["FLOAD "] = vmdef.irfield, + ["FREF "] = vmdef.irfield, + ["FPMATH"] = vmdef.irfpm, +} + +local function ctlsub(c) + if c == "\n" then return "\\n" + elseif c == "\r" then return "\\r" + elseif c == "\t" then return "\\t" + else return format("\\%03d", byte(c)) + end +end + +local function fmtfunc(func, pc) + local fi = funcinfo(func, pc) + if fi.loc then + return fi.loc + elseif fi.ffid then + return vmdef.ffnames[fi.ffid] + elseif fi.addr then + return format("C:%x", fi.addr) + else + return "(?)" + end +end + +local function formatk(tr, idx) + local k, t, slot = tracek(tr, idx) + local tn = type(k) + local s + if tn == "number" then + if k == 2^52+2^51 then + s = "bias" + else + s = format("%+.14g", k) + end + elseif tn == "string" then + s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) + elseif tn == "function" then + s = fmtfunc(k) + elseif tn == "table" then + s = format("{%p}", k) + elseif tn == "userdata" then + if t == 12 then + s = format("userdata:%p", k) + else + s = format("[%p]", k) + if s == "[0x00000000]" then s = "NULL" end + end + elseif t == 21 then -- int64_t + s = sub(tostring(k), 1, -3) + if sub(s, 1, 1) ~= "-" then s = "+"..s end + else + s = tostring(k) -- For primitives. + end + s = colorize(format("%-4s", s), t) + if slot then + s = format("%s @%d", s, slot) + end + return s +end + +local function printsnap(tr, snap) + local n = 2 + for s=0,snap[1]-1 do + local sn = snap[n] + if shr(sn, 24) == s then + n = n + 1 + local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS + if ref < 0 then + out:write(formatk(tr, ref)) + elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM + out:write(colorize(format("%04d/%04d", ref, ref+1), 14)) + else + local m, ot, op1, op2 = traceir(tr, ref) + out:write(colorize(format("%04d", ref), band(ot, 31))) + end + out:write(band(sn, 0x10000) == 0 and " " or "|") -- SNAP_FRAME + else + out:write("---- ") + end + end + out:write("]\n") +end + +-- Dump snapshots (not interleaved with IR). +local function dump_snap(tr) + out:write("---- TRACE ", tr, " snapshots\n") + for i=0,1000000000 do + local snap = tracesnap(tr, i) + if not snap then break end + out:write(format("#%-3d %04d [ ", i, snap[0])) + printsnap(tr, snap) + end +end + +-- Return a register name or stack slot for a rid/sp location. +local function ridsp_name(ridsp, ins) + if not disass then disass = require("jit.dis_"..jit.arch) end + local rid, slot = band(ridsp, 0xff), shr(ridsp, 8) + if rid == 253 or rid == 254 then + return (slot == 0 or slot == 255) and " {sink" or format(" {%04d", ins-slot) + end + if ridsp > 255 then return format("[%x]", slot*4) end + if rid < 128 then return disass.regname(rid) end + return "" +end + +-- Dump CALL* function ref and return optional ctype. +local function dumpcallfunc(tr, ins) + local ctype + if ins > 0 then + local m, ot, op1, op2 = traceir(tr, ins) + if band(ot, 31) == 0 then -- nil type means CARG(func, ctype). + ins = op1 + ctype = formatk(tr, op2) + end + end + if ins < 0 then + out:write(format("[0x%x](", tonumber((tracek(tr, ins))))) + else + out:write(format("%04d (", ins)) + end + return ctype +end + +-- Recursively gather CALL* args and dump them. +local function dumpcallargs(tr, ins) + if ins < 0 then + out:write(formatk(tr, ins)) + else + local m, ot, op1, op2 = traceir(tr, ins) + local oidx = 6*shr(ot, 8) + local op = sub(vmdef.irnames, oidx+1, oidx+6) + if op == "CARG " then + dumpcallargs(tr, op1) + if op2 < 0 then + out:write(" ", formatk(tr, op2)) + else + out:write(" ", format("%04d", op2)) + end + else + out:write(format("%04d", ins)) + end + end +end + +-- Dump IR and interleaved snapshots. +local function dump_ir(tr, dumpsnap, dumpreg) + local info = traceinfo(tr) + if not info then return end + local nins = info.nins + out:write("---- TRACE ", tr, " IR\n") + local irnames = vmdef.irnames + local snapref = 65536 + local snap, snapno + if dumpsnap then + snap = tracesnap(tr, 0) + snapref = snap[0] + snapno = 0 + end + for ins=1,nins do + if ins >= snapref then + if dumpreg then + out:write(format(".... SNAP #%-3d [ ", snapno)) + else + out:write(format(".... SNAP #%-3d [ ", snapno)) + end + printsnap(tr, snap) + snapno = snapno + 1 + snap = tracesnap(tr, snapno) + snapref = snap and snap[0] or 65536 + end + local m, ot, op1, op2, ridsp = traceir(tr, ins) + local oidx, t = 6*shr(ot, 8), band(ot, 31) + local op = sub(irnames, oidx+1, oidx+6) + if op == "LOOP " then + if dumpreg then + out:write(format("%04d ------------ LOOP ------------\n", ins)) + else + out:write(format("%04d ------ LOOP ------------\n", ins)) + end + elseif op ~= "NOP " and op ~= "CARG " and + (dumpreg or op ~= "RENAME") then + local rid = band(ridsp, 255) + if dumpreg then + out:write(format("%04d %-6s", ins, ridsp_name(ridsp, ins))) + else + out:write(format("%04d ", ins)) + end + out:write(format("%s%s %s %s ", + (rid == 254 or rid == 253) and "}" or + (band(ot, 128) == 0 and " " or ">"), + band(ot, 64) == 0 and " " or "+", + irtype[t], op)) + local m1, m2 = band(m, 3), band(m, 3*4) + if sub(op, 1, 4) == "CALL" then + local ctype + if m2 == 1*4 then -- op2 == IRMlit + out:write(format("%-10s (", vmdef.ircall[op2])) + else + ctype = dumpcallfunc(tr, op2) + end + if op1 ~= -1 then dumpcallargs(tr, op1) end + out:write(")") + if ctype then out:write(" ctype ", ctype) end + elseif op == "CNEW " and op2 == -1 then + out:write(formatk(tr, op1)) + elseif m1 ~= 3 then -- op1 != IRMnone + if op1 < 0 then + out:write(formatk(tr, op1)) + else + out:write(format(m1 == 0 and "%04d" or "#%-3d", op1)) + end + if m2 ~= 3*4 then -- op2 != IRMnone + if m2 == 1*4 then -- op2 == IRMlit + local litn = litname[op] + if litn and litn[op2] then + out:write(" ", litn[op2]) + elseif op == "UREFO " or op == "UREFC " then + out:write(format(" #%-3d", shr(op2, 8))) + else + out:write(format(" #%-3d", op2)) + end + elseif op2 < 0 then + out:write(" ", formatk(tr, op2)) + else + out:write(format(" %04d", op2)) + end + end + end + out:write("\n") + end + end + if snap then + if dumpreg then + out:write(format(".... SNAP #%-3d [ ", snapno)) + else + out:write(format(".... SNAP #%-3d [ ", snapno)) + end + printsnap(tr, snap) + end +end + +------------------------------------------------------------------------------ + +local recprefix = "" +local recdepth = 0 + +-- Format trace error message. +local function fmterr(err, info) + if type(err) == "number" then + if type(info) == "function" then info = fmtfunc(info) end + err = format(vmdef.traceerr[err], info) + end + return err +end + +-- Dump trace states. +local function dump_trace(what, tr, func, pc, otr, oex) + if what == "stop" or (what == "abort" and dumpmode.a) then + if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == "stop") + elseif dumpmode.s then dump_snap(tr) end + if dumpmode.m then dump_mcode(tr) end + end + if what == "start" then + if dumpmode.H then out:write('
    \n') end
    +    out:write("---- TRACE ", tr, " ", what)
    +    if otr then out:write(" ", otr, "/", oex) end
    +    out:write(" ", fmtfunc(func, pc), "\n")
    +  elseif what == "stop" or what == "abort" then
    +    out:write("---- TRACE ", tr, " ", what)
    +    if what == "abort" then
    +      out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
    +    else
    +      local info = traceinfo(tr)
    +      local link, ltype = info.link, info.linktype
    +      if link == tr or link == 0 then
    +	out:write(" -> ", ltype, "\n")
    +      elseif ltype == "root" then
    +	out:write(" -> ", link, "\n")
    +      else
    +	out:write(" -> ", link, " ", ltype, "\n")
    +      end
    +    end
    +    if dumpmode.H then out:write("
    \n\n") else out:write("\n") end + else + out:write("---- TRACE ", what, "\n\n") + end + out:flush() +end + +-- Dump recorded bytecode. +local function dump_record(tr, func, pc, depth, callee) + if depth ~= recdepth then + recdepth = depth + recprefix = rep(" .", depth) + end + local line + if pc >= 0 then + line = bcline(func, pc, recprefix) + if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end + else + line = "0000 "..recprefix.." FUNCC \n" + callee = func + end + if pc <= 0 then + out:write(sub(line, 1, -2), " ; ", fmtfunc(func), "\n") + else + out:write(line) + end + if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC + out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond. + end +end + +------------------------------------------------------------------------------ + +-- Dump taken trace exits. +local function dump_texit(tr, ex, ngpr, nfpr, ...) + out:write("---- TRACE ", tr, " exit ", ex, "\n") + if dumpmode.X then + local regs = {...} + if jit.arch == "x64" then + for i=1,ngpr do + out:write(format(" %016x", regs[i])) + if i % 4 == 0 then out:write("\n") end + end + else + for i=1,ngpr do + out:write(format(" %08x", regs[i])) + if i % 8 == 0 then out:write("\n") end + end + end + if jit.arch == "mips" or jit.arch == "mipsel" then + for i=1,nfpr,2 do + out:write(format(" %+17.14g", regs[ngpr+i])) + if i % 8 == 7 then out:write("\n") end + end + else + for i=1,nfpr do + out:write(format(" %+17.14g", regs[ngpr+i])) + if i % 4 == 0 then out:write("\n") end + end + end + end +end + +------------------------------------------------------------------------------ + +-- Detach dump handlers. +local function dumpoff() + if active then + active = false + jit.attach(dump_texit) + jit.attach(dump_record) + jit.attach(dump_trace) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach dump handlers. +local function dumpon(opt, outfile) + if active then dumpoff() end + + local colormode = os.getenv("COLORTERM") and "A" or "T" + if opt then + opt = gsub(opt, "[TAH]", function(mode) colormode = mode; return ""; end) + end + + local m = { t=true, b=true, i=true, m=true, } + if opt and opt ~= "" then + local o = sub(opt, 1, 1) + if o ~= "+" and o ~= "-" then m = {} end + for i=1,#opt do m[sub(opt, i, i)] = (o ~= "-") end + end + dumpmode = m + + if m.t or m.b or m.i or m.s or m.m then + jit.attach(dump_trace, "trace") + end + if m.b then + jit.attach(dump_record, "record") + if not bcline then bcline = require("jit.bc").line end + end + if m.x or m.X then + jit.attach(dump_texit, "texit") + end + + if not outfile then outfile = os.getenv("LUAJIT_DUMPFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stdout + end + + m[colormode] = true + if colormode == "A" then + colorize = colorize_ansi + irtype = irtype_ansi + elseif colormode == "H" then + colorize = colorize_html + irtype = irtype_html + out:write(header_html) + else + colorize = colorize_text + irtype = irtype_text + end + + active = true +end + +-- Public module functions. +module(...) + +on = dumpon +off = dumpoff +start = dumpon -- For -j command line option. + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/v.lua b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/v.lua new file mode 100644 index 0000000..197e67c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/jit/v.lua @@ -0,0 +1,167 @@ +---------------------------------------------------------------------------- +-- Verbose mode of the LuaJIT compiler. +-- +-- Copyright (C) 2005-2014 Mike Pall. All rights reserved. +-- Released under the MIT license. See Copyright Notice in luajit.h +---------------------------------------------------------------------------- +-- +-- This module shows verbose information about the progress of the +-- JIT compiler. It prints one line for each generated trace. This module +-- is useful to see which code has been compiled or where the compiler +-- punts and falls back to the interpreter. +-- +-- Example usage: +-- +-- luajit -jv -e "for i=1,1000 do for j=1,1000 do end end" +-- luajit -jv=myapp.out myapp.lua +-- +-- Default output is to stderr. To redirect the output to a file, pass a +-- filename as an argument (use '-' for stdout) or set the environment +-- variable LUAJIT_VERBOSEFILE. The file is overwritten every time the +-- module is started. +-- +-- The output from the first example should look like this: +-- +-- [TRACE 1 (command line):1 loop] +-- [TRACE 2 (1/3) (command line):1 -> 1] +-- +-- The first number in each line is the internal trace number. Next are +-- the file name ('(command line)') and the line number (':1') where the +-- trace has started. Side traces also show the parent trace number and +-- the exit number where they are attached to in parentheses ('(1/3)'). +-- An arrow at the end shows where the trace links to ('-> 1'), unless +-- it loops to itself. +-- +-- In this case the inner loop gets hot and is traced first, generating +-- a root trace. Then the last exit from the 1st trace gets hot, too, +-- and triggers generation of the 2nd trace. The side trace follows the +-- path along the outer loop and *around* the inner loop, back to its +-- start, and then links to the 1st trace. Yes, this may seem unusual, +-- if you know how traditional compilers work. Trace compilers are full +-- of surprises like this -- have fun! :-) +-- +-- Aborted traces are shown like this: +-- +-- [TRACE --- foo.lua:44 -- leaving loop in root trace at foo:lua:50] +-- +-- Don't worry -- trace aborts are quite common, even in programs which +-- can be fully compiled. The compiler may retry several times until it +-- finds a suitable trace. +-- +-- Of course this doesn't work with features that are not-yet-implemented +-- (NYI error messages). The VM simply falls back to the interpreter. This +-- may not matter at all if the particular trace is not very high up in +-- the CPU usage profile. Oh, and the interpreter is quite fast, too. +-- +-- Also check out the -jdump module, which prints all the gory details. +-- +------------------------------------------------------------------------------ + +-- Cache some library functions and objects. +local jit = require("jit") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +local jutil = require("jit.util") +local vmdef = require("jit.vmdef") +local funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo +local type, format = type, string.format +local stdout, stderr = io.stdout, io.stderr + +-- Active flag and output file handle. +local active, out + +------------------------------------------------------------------------------ + +local startloc, startex + +local function fmtfunc(func, pc) + local fi = funcinfo(func, pc) + if fi.loc then + return fi.loc + elseif fi.ffid then + return vmdef.ffnames[fi.ffid] + elseif fi.addr then + return format("C:%x", fi.addr) + else + return "(?)" + end +end + +-- Format trace error message. +local function fmterr(err, info) + if type(err) == "number" then + if type(info) == "function" then info = fmtfunc(info) end + err = format(vmdef.traceerr[err], info) + end + return err +end + +-- Dump trace states. +local function dump_trace(what, tr, func, pc, otr, oex) + if what == "start" then + startloc = fmtfunc(func, pc) + startex = otr and "("..otr.."/"..oex..") " or "" + else + if what == "abort" then + local loc = fmtfunc(func, pc) + if loc ~= startloc then + out:write(format("[TRACE --- %s%s -- %s at %s]\n", + startex, startloc, fmterr(otr, oex), loc)) + else + out:write(format("[TRACE --- %s%s -- %s]\n", + startex, startloc, fmterr(otr, oex))) + end + elseif what == "stop" then + local info = traceinfo(tr) + local link, ltype = info.link, info.linktype + if ltype == "interpreter" then + out:write(format("[TRACE %3s %s%s -- fallback to interpreter]\n", + tr, startex, startloc)) + elseif link == tr or link == 0 then + out:write(format("[TRACE %3s %s%s %s]\n", + tr, startex, startloc, ltype)) + elseif ltype == "root" then + out:write(format("[TRACE %3s %s%s -> %d]\n", + tr, startex, startloc, link)) + else + out:write(format("[TRACE %3s %s%s -> %d %s]\n", + tr, startex, startloc, link, ltype)) + end + else + out:write(format("[TRACE %s]\n", what)) + end + out:flush() + end +end + +------------------------------------------------------------------------------ + +-- Detach dump handlers. +local function dumpoff() + if active then + active = false + jit.attach(dump_trace) + if out and out ~= stdout and out ~= stderr then out:close() end + out = nil + end +end + +-- Open the output file and attach dump handlers. +local function dumpon(outfile) + if active then dumpoff() end + if not outfile then outfile = os.getenv("LUAJIT_VERBOSEFILE") end + if outfile then + out = outfile == "-" and stdout or assert(io.open(outfile, "w")) + else + out = stderr + end + jit.attach(dump_trace, "trace") + active = true +end + +-- Public module functions. +module(...) + +on = dumpon +off = dumpoff +start = dumpon -- For -j command line option. + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lapi.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lapi.c new file mode 100644 index 0000000..db20e4d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lapi.c @@ -0,0 +1,1099 @@ +/* +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res = 1; + lua_lock(L); + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else if (size > 0) { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + /* explicit test for incompatible code */ + if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) + luaG_runerror(L, "no calling environment"); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); + else + status = 1; + lua_unlock(L); + return status; +} + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } + } + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} + +LUA_API void Lua_ReturnArray(lua_State *L,int Array[],int num) +{ + lua_newtable( L ); + int i; + for (i=0;i +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + lf.extraline = 0; + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lauxlib.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lauxlib.h new file mode 100644 index 0000000..4931ac4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lauxlib.h @@ -0,0 +1,166 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + +LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + +/* From Lua 5.2. */ +LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname); +LUALIB_API int luaL_execresult(lua_State *L, int stat); +LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, + const char *mode); +LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, + const char *name, const char *mode); +LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, + int level); + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lbaselib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lbaselib.c new file mode 100644 index 0000000..2a4c079 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lbaselib.c @@ -0,0 +1,653 @@ +/* +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L, int opt) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L, 1); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L, 0); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int load_aux (lua_State *L, int status) { + if (status == 0) /* OK? */ + return 1; + else { + lua_pushnil(L); + lua_insert(L, -2); /* put before error message */ + return 2; /* return nil plus error message */ + } +} + + +static int luaB_loadstring (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + const char *chunkname = luaL_optstring(L, 2, s); + return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); +} + + +static int luaB_loadfile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + return load_aux(L, luaL_loadfile(L, fname)); +} + + +/* +** Reader for generic `load' function: `lua_load' uses the +** stack for internal stuff, so the reader cannot change the +** stack top. Instead, it keeps its resulting string in a +** reserved slot inside the stack. +*/ +static const char *generic_reader (lua_State *L, void *ud, size_t *size) { + (void)ud; /* to avoid warnings */ + luaL_checkstack(L, 2, "too many nested functions"); + lua_pushvalue(L, 1); /* get function */ + lua_call(L, 0, 1); /* call it */ + if (lua_isnil(L, -1)) { + *size = 0; + return NULL; + } + else if (lua_isstring(L, -1)) { + lua_replace(L, 3); /* save string in a reserved stack slot */ + return lua_tolstring(L, 3, size); + } + else luaL_error(L, "reader function must return a string"); + return NULL; /* to avoid warnings */ +} + + +static int luaB_load (lua_State *L) { + int status; + const char *cname = luaL_optstring(L, 2, "=(load)"); + luaL_checktype(L, 1, LUA_TFUNCTION); + lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ + status = lua_load(L, generic_reader, NULL, cname); + return load_aux(L, status); +} + + +static int luaB_dofile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); + if (luaL_loadfile(L, fname) != 0) lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ + n = e - i + 1; /* number of elements */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"dofile", luaB_dofile}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"loadfile", luaB_loadfile}, + {"load", luaB_load}, + {"loadstring", luaB_loadstring}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status = costatus(L, co); + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + lua_setlevel(L, co); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres + 1)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.c new file mode 100644 index 0000000..cff626b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.c @@ -0,0 +1,839 @@ +/* +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: r = luai_numpow(v1, v2); break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (!isnumeral(e)) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + default: { + luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.h new file mode 100644 index 0000000..b941c60 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lcode.h @@ -0,0 +1,76 @@ +/* +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldblib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldblib.c new file mode 100644 index 0000000..67de122 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldblib.c @@ -0,0 +1,397 @@ +/* +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static int db_getregistry (lua_State *L) { + lua_pushvalue(L, LUA_REGISTRYINDEX); + return 1; +} + + +static int db_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); /* no metatable */ + } + return 1; +} + + +static int db_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + lua_settop(L, 2); + lua_pushboolean(L, lua_setmetatable(L, 1)); + return 1; +} + + +static int db_getfenv (lua_State *L) { + lua_getfenv(L, 1); + return 1; +} + + +static int db_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + if (lua_setfenv(L, 1) == 0) + luaL_error(L, LUA_QL("setfenv") + " cannot change environment of given object"); + return 1; +} + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int db_setlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + luaL_checkany(L, arg+3); + lua_settop(L, arg+3); + lua_xmove(L, L1, 1); + lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); + return 1; +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + +static int db_setupvalue (lua_State *L) { + luaL_checkany(L, 3); + return auxupvalue(L, 0); +} + + + +static const char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg, mask, count; + lua_Hook func; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_pushvalue(L, arg+1); + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +static int db_debug (lua_State *L) { + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"debug", db_debug}, + {"getfenv", db_getfenv}, + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getregistry", db_getregistry}, + {"getmetatable", db_getmetatable}, + {"getupvalue", db_getupvalue}, + {"setfenv", db_setfenv}, + {"sethook", db_sethook}, + {"setlocal", db_setlocal}, + {"setmetatable", db_setmetatable}, + {"setupvalue", db_setupvalue}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.c new file mode 100644 index 0000000..50ad3d3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.c @@ -0,0 +1,638 @@ +/* +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + int j; + /* check that it does not jump to a setlist count; this + is tricky, because the count from a previous setlist may + have the same value of an invalid setlist; so, we must + go all the way back to the first of them (if any) */ + for (j = 0; j < dest; j++) { + Instruction d = pt->code[dest-1-j]; + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; + } + /* if 'j' is even, previous value is not a setlist (even if + it looks like one) */ + check((j&1) == 0); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + if (c == 1) { /* does it jump? */ + check(pc+2 < pt->sizecode); /* check its jump */ + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || + GETARG_C(pt->code[pc+1]) != 0); + } + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } + break; + } + case OP_CLOSURE: { + int nup, j; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.h new file mode 100644 index 0000000..ba28a97 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.c new file mode 100644 index 0000000..a8b6ca4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.c @@ -0,0 +1,527 @@ +/* +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + + + + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + + +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { + switch (errcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = L->baseCcalls; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +void luaD_throw (lua_State *L, int errcode) { + if (L->errorJmp) { + L->errorJmp->status = errcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(errcode); + if (G(L)->panic) { + resetstack(L, errcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status == 0) { /* start coroutine? */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + lua_assert(L->status == LUA_YIELD); + L->status = 0; + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + return resume_error(L, "cannot resume non-suspended coroutine"); + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else { + lua_assert(L->nCcalls == L->baseCcalls); + status = L->status; + } + --L->nCcalls; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > L->baseCcalls) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +#ifdef _JZ_LUA_CODE +LUA_API int lua_setconstlist(lua_State *L, lua_const *constlist) +{ + L->constlist = constlist; + return 0; +} +#endif + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.h new file mode 100644 index 0000000..98fddac --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldo.h @@ -0,0 +1,57 @@ +/* +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldump.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldump.c new file mode 100644 index 0000000..c9d3d48 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.c new file mode 100644 index 0000000..813e88f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.c @@ -0,0 +1,174 @@ +/* +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.h new file mode 100644 index 0000000..a68cf51 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.c new file mode 100644 index 0000000..d9e0b78 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.c @@ -0,0 +1,711 @@ +/* +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.h new file mode 100644 index 0000000..5a8dc60 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_aux.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_aux.c new file mode 100644 index 0000000..1b01fe0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_aux.c @@ -0,0 +1,356 @@ +/* +** Auxiliary library for the Lua/C API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major parts taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define lib_aux_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_state.h" +#include "lj_trace.h" +#include "lj_lib.h" + +#if LJ_TARGET_POSIX +#include +#endif + +/* -- I/O error handling -------------------------------------------------- */ + +LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname) +{ + if (stat) { + setboolV(L->top++, 1); + return 1; + } else { + int en = errno; /* Lua API calls may change this value. */ + setnilV(L->top++); + if (fname) + lua_pushfstring(L, "%s: %s", fname, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + setintV(L->top++, en); + lj_trace_abort(G(L)); + return 3; + } +} + +LUALIB_API int luaL_execresult(lua_State *L, int stat) +{ + if (stat != -1) { +#if LJ_TARGET_POSIX + if (WIFSIGNALED(stat)) { + stat = WTERMSIG(stat); + setnilV(L->top++); + lua_pushliteral(L, "signal"); + } else { + if (WIFEXITED(stat)) + stat = WEXITSTATUS(stat); + if (stat == 0) + setboolV(L->top++, 1); + else + setnilV(L->top++); + lua_pushliteral(L, "exit"); + } +#else + if (stat == 0) + setboolV(L->top++, 1); + else + setnilV(L->top++); + lua_pushliteral(L, "exit"); +#endif + setintV(L->top++, stat); + return 3; + } + return luaL_fileresult(L, 0, NULL); +} + +/* -- Module registration ------------------------------------------------- */ + +LUALIB_API const char *luaL_findtable(lua_State *L, int idx, + const char *fname, int szhint) +{ + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, (size_t)(e - fname)); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, (size_t)(e - fname)); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + +static int libsize(const luaL_Reg *l) +{ + int size = 0; + for (; l->name; l++) size++; + return size; +} + +LUALIB_API void luaL_openlib(lua_State *L, const char *libname, + const luaL_Reg *l, int nup) +{ + lj_lib_checkfpu(L); + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + +LUALIB_API void luaL_register(lua_State *L, const char *libname, + const luaL_Reg *l) +{ + luaL_openlib(L, libname, l, 0); +} + +LUALIB_API const char *luaL_gsub(lua_State *L, const char *s, + const char *p, const char *r) +{ + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, (size_t)(wild - s)); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + +/* -- Buffer handling ----------------------------------------------------- */ + +#define bufflen(B) ((size_t)((B)->p - (B)->buffer)) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +static int emptybuffer(luaL_Buffer *B) +{ + size_t l = bufflen(B); + if (l == 0) + return 0; /* put nothing on stack */ + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; +} + +static void adjuststack(luaL_Buffer *B) +{ + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l)) + break; + toplen += l; + toget++; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + +LUALIB_API char *luaL_prepbuffer(luaL_Buffer *B) +{ + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + +LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l) +{ + while (l--) + luaL_addchar(B, *s++); +} + +LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s) +{ + luaL_addlstring(B, s, strlen(s)); +} + +LUALIB_API void luaL_pushresult(luaL_Buffer *B) +{ + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + +LUALIB_API void luaL_addvalue(luaL_Buffer *B) +{ + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + +LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B) +{ + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* -- Reference management ------------------------------------------------ */ + +#define FREELIST_REF 0 + +/* Convert a stack index to an absolute index. */ +#define abs_index(L, i) \ + ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) + +LUALIB_API int luaL_ref(lua_State *L, int t) +{ + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + +LUALIB_API void luaL_unref(lua_State *L, int t, int ref) +{ + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + +/* -- Default allocator and panic function -------------------------------- */ + +static int panic(lua_State *L) +{ + const char *s = lua_tostring(L, -1); + fputs("PANIC: unprotected error in call to Lua API (", stderr); + fputs(s ? s : "?", stderr); + fputc(')', stderr); fputc('\n', stderr); + fflush(stderr); + return 0; +} + +#ifdef LUAJIT_USE_SYSMALLOC + +#if LJ_64 +#error "Must use builtin allocator for 64 bit target" +#endif + +static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +{ + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, nsize); + } +} + +LUALIB_API lua_State *luaL_newstate(void) +{ + lua_State *L = lua_newstate(mem_alloc, NULL); + if (L) G(L)->panic = panic; + return L; +} + +#else + +#include "lj_alloc.h" + +LUALIB_API lua_State *luaL_newstate(void) +{ + lua_State *L; + void *ud = lj_alloc_create(); + if (ud == NULL) return NULL; +#if LJ_64 + L = lj_state_newstate(lj_alloc_f, ud); +#else + L = lua_newstate(lj_alloc_f, ud); +#endif + if (L) G(L)->panic = panic; + return L; +} + +#if LJ_64 +LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) +{ + UNUSED(f); UNUSED(ud); + fputs("Must use luaL_newstate() for 64 bit target\n", stderr); + return NULL; +} +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_base.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_base.c new file mode 100644 index 0000000..324e4dd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_base.c @@ -0,0 +1,682 @@ +/* +** Base and coroutine library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lib_base_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_state.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cconv.h" +#endif +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_dispatch.h" +#include "lj_char.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* -- Base library: checks ------------------------------------------------ */ + +#define LJLIB_MODULE_base + +LJLIB_ASM(assert) LJLIB_REC(.) +{ + GCstr *s; + lj_lib_checkany(L, 1); + s = lj_lib_optstr(L, 2); + if (s) + lj_err_callermsg(L, strdata(s)); + else + lj_err_caller(L, LJ_ERR_ASSERT); + return FFH_UNREACHABLE; +} + +/* ORDER LJ_T */ +LJLIB_PUSH("nil") +LJLIB_PUSH("boolean") +LJLIB_PUSH(top-1) /* boolean */ +LJLIB_PUSH("userdata") +LJLIB_PUSH("string") +LJLIB_PUSH("upval") +LJLIB_PUSH("thread") +LJLIB_PUSH("proto") +LJLIB_PUSH("function") +LJLIB_PUSH("trace") +LJLIB_PUSH("cdata") +LJLIB_PUSH("table") +LJLIB_PUSH(top-9) /* userdata */ +LJLIB_PUSH("number") +LJLIB_ASM_(type) LJLIB_REC(.) +/* Recycle the lj_lib_checkany(L, 1) from assert. */ + +/* -- Base library: iterators --------------------------------------------- */ + +/* This solves a circular dependency problem -- change FF_next_N as needed. */ +LJ_STATIC_ASSERT((int)FF_next == FF_next_N); + +LJLIB_ASM(next) +{ + lj_lib_checktab(L, 1); + return FFH_UNREACHABLE; +} + +#if LJ_52 || LJ_HASFFI +static int ffh_pairs(lua_State *L, MMS mm) +{ + TValue *o = lj_lib_checkany(L, 1); + cTValue *mo = lj_meta_lookup(L, o, mm); + if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) { + L->top = o+1; /* Only keep one argument. */ + copyTV(L, L->base-1, mo); /* Replace callable. */ + return FFH_TAILCALL; + } else { + if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE); + setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1))); + if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0); + return FFH_RES(3); + } +} +#else +#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE) +#endif + +LJLIB_PUSH(lastcl) +LJLIB_ASM(pairs) +{ + return ffh_pairs(L, MM_pairs); +} + +LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkint(L, 2); + return FFH_UNREACHABLE; +} + +LJLIB_PUSH(lastcl) +LJLIB_ASM(ipairs) LJLIB_REC(.) +{ + return ffh_pairs(L, MM_ipairs); +} + +/* -- Base library: getters and setters ----------------------------------- */ + +LJLIB_ASM_(getmetatable) LJLIB_REC(.) +/* Recycle the lj_lib_checkany(L, 1) from assert. */ + +LJLIB_ASM(setmetatable) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + GCtab *mt = lj_lib_checktabornil(L, 2); + if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable))) + lj_err_caller(L, LJ_ERR_PROTMT); + setgcref(t->metatable, obj2gco(mt)); + if (mt) { lj_gc_objbarriert(L, t, mt); } + settabV(L, L->base-1, t); + return FFH_RES(1); +} + +LJLIB_CF(getfenv) +{ + GCfunc *fn; + cTValue *o = L->base; + if (!(o < L->top && tvisfunc(o))) { + int level = lj_lib_optint(L, 1, 1); + o = lj_debug_frame(L, level, &level); + if (o == NULL) + lj_err_arg(L, 1, LJ_ERR_INVLVL); + } + fn = &gcval(o)->fn; + settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env)); + return 1; +} + +LJLIB_CF(setfenv) +{ + GCfunc *fn; + GCtab *t = lj_lib_checktab(L, 2); + cTValue *o = L->base; + if (!(o < L->top && tvisfunc(o))) { + int level = lj_lib_checkint(L, 1); + if (level == 0) { + /* NOBARRIER: A thread (i.e. L) is never black. */ + setgcref(L->env, obj2gco(t)); + return 0; + } + o = lj_debug_frame(L, level, &level); + if (o == NULL) + lj_err_arg(L, 1, LJ_ERR_INVLVL); + } + fn = &gcval(o)->fn; + if (!isluafunc(fn)) + lj_err_caller(L, LJ_ERR_SETFENV); + setgcref(fn->l.env, obj2gco(t)); + lj_gc_objbarrier(L, obj2gco(fn), t); + setfuncV(L, L->top++, fn); + return 1; +} + +LJLIB_ASM(rawget) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkany(L, 2); + return FFH_UNREACHABLE; +} + +LJLIB_CF(rawset) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + lj_lib_checkany(L, 2); + L->top = 1+lj_lib_checkany(L, 3); + lua_rawset(L, 1); + return 1; +} + +LJLIB_CF(rawequal) LJLIB_REC(.) +{ + cTValue *o1 = lj_lib_checkany(L, 1); + cTValue *o2 = lj_lib_checkany(L, 2); + setboolV(L->top-1, lj_obj_equal(o1, o2)); + return 1; +} + +#if LJ_52 +LJLIB_CF(rawlen) LJLIB_REC(.) +{ + cTValue *o = L->base; + int32_t len; + if (L->top > o && tvisstr(o)) + len = (int32_t)strV(o)->len; + else + len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1)); + setintV(L->top-1, len); + return 1; +} +#endif + +LJLIB_CF(unpack) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t n, i = lj_lib_optint(L, 2, 1); + int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ? + lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t); + if (i > e) return 0; + n = e - i + 1; + if (n <= 0 || !lua_checkstack(L, n)) + lj_err_caller(L, LJ_ERR_UNPACK); + do { + cTValue *tv = lj_tab_getint(t, i); + if (tv) { + copyTV(L, L->top++, tv); + } else { + setnilV(L->top++); + } + } while (i++ < e); + return n; +} + +LJLIB_CF(select) LJLIB_REC(.) +{ + int32_t n = (int32_t)(L->top - L->base); + if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') { + setintV(L->top-1, n-1); + return 1; + } else { + int32_t i = lj_lib_checkint(L, 1); + if (i < 0) i = n + i; else if (i > n) i = n; + if (i < 1) + lj_err_arg(L, 1, LJ_ERR_IDXRNG); + return n - i; + } +} + +/* -- Base library: conversions ------------------------------------------- */ +LJLIB_ASM(tonumber) LJLIB_REC(.) +{ + int32_t base = lj_lib_optint(L, 2, 10); + if (base == 10) { + TValue *o = lj_lib_checkany(L, 1); + if (lj_strscan_numberobj(o)) { + copyTV(L, L->base-1, o); + return FFH_RES(1); + } +#if LJ_HASFFI + if (tviscdata(o)) { + CTState *cts = ctype_cts(L); + CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) { + if (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) && + ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) { + int32_t i; + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0); + setintV(L->base-1, i); + return FFH_RES(1); + } + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE), + (uint8_t *)&(L->base-1)->n, o, 0); + return FFH_RES(1); + } + } +#endif + } else { + const char *p = strdata(lj_lib_checkstr(L, 1)); + char *ep; + unsigned long ul; + if (base < 2 || base > 36) + lj_err_arg(L, 2, LJ_ERR_BASERNG); + ul = strtoul(p, &ep, base); + if (p != ep) { + while (lj_char_isspace((unsigned char)(*ep))) ep++; + if (*ep == '\0') { + if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u)) + setintV(L->base-1, (int32_t)ul); + else + setnumV(L->base-1, (lua_Number)ul); + return FFH_RES(1); + } + } + } + setnilV(L->base-1); + return FFH_RES(1); +} + +LJLIB_PUSH("nil") +LJLIB_PUSH("false") +LJLIB_PUSH("true") +LJLIB_ASM(tostring) LJLIB_REC(.) +{ + TValue *o = lj_lib_checkany(L, 1); + cTValue *mo; + L->top = o+1; /* Only keep one argument. */ + if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { + copyTV(L, L->base-1, mo); /* Replace callable. */ + return FFH_TAILCALL; + } else { + GCstr *s; + if (tvisnumber(o)) { + s = lj_str_fromnumber(L, o); + } else if (tvispri(o)) { + s = strV(lj_lib_upvalue(L, -(int32_t)itype(o))); + } else { + if (tvisfunc(o) && isffunc(funcV(o))) + lua_pushfstring(L, "function: builtin#%d", funcV(o)->c.ffid); + else + lua_pushfstring(L, "%s: %p", lj_typename(o), lua_topointer(L, 1)); + /* Note: lua_pushfstring calls the GC which may invalidate o. */ + s = strV(L->top-1); + } + setstrV(L, L->base-1, s); + return FFH_RES(1); + } +} + +/* -- Base library: throw and catch errors -------------------------------- */ + +LJLIB_CF(error) +{ + int32_t level = lj_lib_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + +LJLIB_ASM(pcall) LJLIB_REC(.) +{ + lj_lib_checkany(L, 1); + lj_lib_checkfunc(L, 2); /* For xpcall only. */ + return FFH_UNREACHABLE; +} +LJLIB_ASM_(xpcall) LJLIB_REC(.) + +/* -- Base library: load Lua code ----------------------------------------- */ + +static int load_aux(lua_State *L, int status, int envarg) +{ + if (status == 0) { + if (tvistab(L->base+envarg-1)) { + GCfunc *fn = funcV(L->top-1); + GCtab *t = tabV(L->base+envarg-1); + setgcref(fn->c.env, obj2gco(t)); + lj_gc_objbarrier(L, fn, t); + } + return 1; + } else { + setnilV(L->top-2); + return 2; + } +} + +LJLIB_CF(loadfile) +{ + GCstr *fname = lj_lib_optstr(L, 1); + GCstr *mode = lj_lib_optstr(L, 2); + int status; + lua_settop(L, 3); /* Ensure env arg exists. */ + status = luaL_loadfilex(L, fname ? strdata(fname) : NULL, + mode ? strdata(mode) : NULL); + return load_aux(L, status, 3); +} + +static const char *reader_func(lua_State *L, void *ud, size_t *size) +{ + UNUSED(ud); + luaL_checkstack(L, 2, "too many nested functions"); + copyTV(L, L->top++, L->base); + lua_call(L, 0, 1); /* Call user-supplied function. */ + L->top--; + if (tvisnil(L->top)) { + *size = 0; + return NULL; + } else if (tvisstr(L->top) || tvisnumber(L->top)) { + copyTV(L, L->base+4, L->top); /* Anchor string in reserved stack slot. */ + return lua_tolstring(L, 5, size); + } else { + lj_err_caller(L, LJ_ERR_RDRSTR); + return NULL; + } +} + +LJLIB_CF(load) +{ + GCstr *name = lj_lib_optstr(L, 2); + GCstr *mode = lj_lib_optstr(L, 3); + int status; + if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) { + GCstr *s = lj_lib_checkstr(L, 1); + lua_settop(L, 4); /* Ensure env arg exists. */ + status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s), + mode ? strdata(mode) : NULL); + } else { + lj_lib_checkfunc(L, 1); + lua_settop(L, 5); /* Reserve a slot for the string from the reader. */ + status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : "=(load)", + mode ? strdata(mode) : NULL); + } + return load_aux(L, status, 4); +} + +LJLIB_CF(loadstring) +{ + return lj_cf_load(L); +} + +LJLIB_CF(dofile) +{ + GCstr *fname = lj_lib_optstr(L, 1); + setnilV(L->top); + L->top = L->base+1; + if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0) + lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return (int)(L->top - L->base) - 1; +} + +/* -- Base library: GC control -------------------------------------------- */ + +LJLIB_CF(gcinfo) +{ + setintV(L->top++, (G(L)->gc.total >> 10)); + return 1; +} + +LJLIB_CF(collectgarbage) +{ + int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */ + "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul"); + int32_t data = lj_lib_optint(L, 2, 0); + if (opt == LUA_GCCOUNT) { + setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0); + } else { + int res = lua_gc(L, opt, data); + if (opt == LUA_GCSTEP) + setboolV(L->top, res); + else + setintV(L->top, res); + } + L->top++; + return 1; +} + +/* -- Base library: miscellaneous functions ------------------------------- */ + +LJLIB_PUSH(top-2) /* Upvalue holds weak table. */ +LJLIB_CF(newproxy) +{ + lua_settop(L, 1); + lua_newuserdata(L, 0); + if (lua_toboolean(L, 1) == 0) { /* newproxy(): without metatable. */ + return 1; + } else if (lua_isboolean(L, 1)) { /* newproxy(true): with metatable. */ + lua_newtable(L); + lua_pushvalue(L, -1); + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* Remember mt in weak table. */ + } else { /* newproxy(proxy): inherit metatable. */ + int validproxy = 0; + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); + } + if (!validproxy) + lj_err_arg(L, 1, LJ_ERR_NOPROXY); + lua_getmetatable(L, 1); + } + lua_setmetatable(L, 2); + return 1; +} + +LJLIB_PUSH("tostring") +LJLIB_CF(print) +{ + ptrdiff_t i, nargs = L->top - L->base; + cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1))); + int shortcut; + if (tv && !tvisnil(tv)) { + copyTV(L, L->top++, tv); + } else { + setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1))); + lua_gettable(L, LUA_GLOBALSINDEX); + tv = L->top-1; + } + shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring); + for (i = 0; i < nargs; i++) { + const char *str; + size_t size; + cTValue *o = &L->base[i]; + if (shortcut && tvisstr(o)) { + str = strVdata(o); + size = strV(o)->len; + } else if (shortcut && tvisint(o)) { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, intV(o)); + size = (size_t)(buf+LJ_STR_INTBUF-p); + str = p; + } else if (shortcut && tvisnum(o)) { + char buf[LJ_STR_NUMBUF]; + size = lj_str_bufnum(buf, o); + str = buf; + } else { + copyTV(L, L->top+1, o); + copyTV(L, L->top, L->top-1); + L->top += 2; + lua_call(L, 1, 1); + str = lua_tolstring(L, -1, &size); + if (!str) + lj_err_caller(L, LJ_ERR_PRTOSTR); + L->top--; + } + if (i) + putchar('\t'); + fwrite(str, 1, size, stdout); + } + putchar('\n'); + return 0; +} + +LJLIB_PUSH(top-3) +LJLIB_SET(_VERSION) + +#include "lj_libdef.h" + +/* -- Coroutine library --------------------------------------------------- */ + +#define LJLIB_MODULE_coroutine + +LJLIB_CF(coroutine_status) +{ + const char *s; + lua_State *co; + if (!(L->top > L->base && tvisthread(L->base))) + lj_err_arg(L, 1, LJ_ERR_NOCORO); + co = threadV(L->base); + if (co == L) s = "running"; + else if (co->status == LUA_YIELD) s = "suspended"; + else if (co->status != 0) s = "dead"; + else if (co->base > tvref(co->stack)+1) s = "normal"; + else if (co->top == co->base) s = "dead"; + else s = "suspended"; + lua_pushstring(L, s); + return 1; +} + +LJLIB_CF(coroutine_running) +{ +#if LJ_52 + int ismain = lua_pushthread(L); + setboolV(L->top++, ismain); + return 2; +#else + if (lua_pushthread(L)) + setnilV(L->top++); + return 1; +#endif +} + +LJLIB_CF(coroutine_create) +{ + lua_State *L1; + if (!(L->base < L->top && tvisfunc(L->base))) + lj_err_argt(L, 1, LUA_TFUNCTION); + L1 = lua_newthread(L); + setfuncV(L, L1->top++, funcV(L->base)); + return 1; +} + +LJLIB_ASM(coroutine_yield) +{ + lj_err_caller(L, LJ_ERR_CYIELD); + return FFH_UNREACHABLE; +} + +static int ffh_resume(lua_State *L, lua_State *co, int wrap) +{ + if (co->cframe != NULL || co->status > LUA_YIELD || + (co->status == 0 && co->top == co->base)) { + ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD; + if (wrap) lj_err_caller(L, em); + setboolV(L->base-1, 0); + setstrV(L, L->base, lj_err_str(L, em)); + return FFH_RES(2); + } + lj_state_growstack(co, (MSize)(L->top - L->base)); + return FFH_RETRY; +} + +LJLIB_ASM(coroutine_resume) +{ + if (!(L->top > L->base && tvisthread(L->base))) + lj_err_arg(L, 1, LJ_ERR_NOCORO); + return ffh_resume(L, threadV(L->base), 0); +} + +LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux) +{ + return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1); +} + +/* Inline declarations. */ +LJ_ASMF void lj_ff_coroutine_wrap_aux(void); +#if !(LJ_TARGET_MIPS && defined(ljamalg_c)) +LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, + lua_State *co); +#endif + +/* Error handler, called from assembler VM. */ +void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co) +{ + co->top--; copyTV(L, L->top, co->top); L->top++; + if (tvisstr(L->top-1)) + lj_err_callermsg(L, strVdata(L->top-1)); + else + lj_err_run(L); +} + +/* Forward declaration. */ +static void setpc_wrap_aux(lua_State *L, GCfunc *fn); + +LJLIB_CF(coroutine_wrap) +{ + lj_cf_coroutine_create(L); + lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1); + setpc_wrap_aux(L, funcV(L->top-1)); + return 1; +} + +#include "lj_libdef.h" + +/* Fix the PC of wrap_aux. Really ugly workaround. */ +static void setpc_wrap_aux(lua_State *L, GCfunc *fn) +{ + setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]); +} + +/* ------------------------------------------------------------------------ */ + +static void newproxy_weaktable(lua_State *L) +{ + /* NOBARRIER: The table is new (marked white). */ + GCtab *t = lj_tab_new(L, 0, 1); + settabV(L, L->top++, t); + setgcref(t->metatable, obj2gco(t)); + setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), + lj_str_newlit(L, "kv")); + t->nomm = (uint8_t)(~(1u<env); + settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, "_G")), env); + lua_pushliteral(L, LUA_VERSION); /* top-3. */ + newproxy_weaktable(L); /* top-2. */ + LJ_LIB_REG(L, "_G", base); + LJ_LIB_REG(L, LUA_COLIBNAME, coroutine); + return 2; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_bit.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_bit.c new file mode 100644 index 0000000..739924b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_bit.c @@ -0,0 +1,74 @@ +/* +** Bit manipulation library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_bit_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_bit + +LJLIB_ASM(bit_tobit) LJLIB_REC(bit_unary IR_TOBIT) +{ + lj_lib_checknumber(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(bit_bnot) LJLIB_REC(bit_unary IR_BNOT) +LJLIB_ASM_(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP) + +LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL) +{ + lj_lib_checknumber(L, 1); + lj_lib_checkbit(L, 2); + return FFH_RETRY; +} +LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR) +LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR) +LJLIB_ASM_(bit_rol) LJLIB_REC(bit_shift IR_BROL) +LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR) + +LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND) +{ + int i = 0; + do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top); + return FFH_RETRY; +} +LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR) +LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR) + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(bit_tohex) +{ + uint32_t b = (uint32_t)lj_lib_checkbit(L, 1); + int32_t i, n = L->base+1 >= L->top ? 8 : lj_lib_checkbit(L, 2); + const char *hexdigits = "0123456789abcdef"; + char buf[8]; + if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } + if (n > 8) n = 8; + for (i = n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; } + lua_pushlstring(L, buf, (size_t)n); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_bit(lua_State *L) +{ + LJ_LIB_REG(L, LUA_BITLIBNAME, bit); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_debug.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_debug.c new file mode 100644 index 0000000..97f032f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_debug.c @@ -0,0 +1,405 @@ +/* +** Debug library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_debug_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_debug + +LJLIB_CF(debug_getregistry) +{ + copyTV(L, L->top++, registry(L)); + return 1; +} + +LJLIB_CF(debug_getmetatable) +{ + lj_lib_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + setnilV(L->top-1); + } + return 1; +} + +LJLIB_CF(debug_setmetatable) +{ + lj_lib_checktabornil(L, 2); + L->top = L->base+2; + lua_setmetatable(L, 1); +#if !LJ_52 + setboolV(L->top-1, 1); +#endif + return 1; +} + +LJLIB_CF(debug_getfenv) +{ + lj_lib_checkany(L, 1); + lua_getfenv(L, 1); + return 1; +} + +LJLIB_CF(debug_setfenv) +{ + lj_lib_checktab(L, 2); + L->top = L->base+2; + if (!lua_setfenv(L, 1)) + lj_err_caller(L, LJ_ERR_SETFENV); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void settabss(lua_State *L, const char *i, const char *v) +{ + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + +static void settabsi(lua_State *L, const char *i, int v) +{ + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + +static void settabsb(lua_State *L, const char *i, int v) +{ + lua_pushboolean(L, v); + lua_setfield(L, -2, i); +} + +static lua_State *getthread(lua_State *L, int *arg) +{ + if (L->base < L->top && tvisthread(L->base)) { + *arg = 1; + return threadV(L->base); + } else { + *arg = 0; + return L; + } +} + +static void treatstackoption(lua_State *L, lua_State *L1, const char *fname) +{ + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + +LJLIB_CF(debug_getinfo) +{ + lj_Debug ar; + int arg, opt_f = 0, opt_L = 0; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) { + setnilV(L->top-1); + return 1; + } + } else if (L->base+arg < L->top && tvisfunc(L->base+arg)) { + options = lua_pushfstring(L, ">%s", options); + setfuncV(L1, L1->top++, funcV(L->base+arg)); + } else { + lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL); + } + if (!lj_debug_getinfo(L1, options, &ar, 1)) + lj_err_arg(L, arg+2, LJ_ERR_INVOPT); + lua_createtable(L, 0, 16); /* Create result table. */ + for (; *options; options++) { + switch (*options) { + case 'S': + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + break; + case 'l': + settabsi(L, "currentline", ar.currentline); + break; + case 'u': + settabsi(L, "nups", ar.nups); + settabsi(L, "nparams", ar.nparams); + settabsb(L, "isvararg", ar.isvararg); + break; + case 'n': + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + break; + case 'f': opt_f = 1; break; + case 'L': opt_L = 1; break; + default: break; + } + } + if (opt_L) treatstackoption(L, L1, "activelines"); + if (opt_f) treatstackoption(L, L1, "func"); + return 1; /* Return result table. */ +} + +LJLIB_CF(debug_getlocal) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + int slot = lj_lib_checkint(L, arg+2); + if (tvisfunc(L->base+arg)) { + L->top = L->base+arg+1; + lua_pushstring(L, lua_getlocal(L, NULL, slot)); + return 1; + } + if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) + lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); + name = lua_getlocal(L1, &ar, slot); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } else { + setnilV(L->top-1); + return 1; + } +} + +LJLIB_CF(debug_setlocal) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + TValue *tv; + if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) + lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); + tv = lj_lib_checkany(L, arg+3); + copyTV(L1, L1->top++, tv); + lua_pushstring(L, lua_setlocal(L1, &ar, lj_lib_checkint(L, arg+2))); + return 1; +} + +static int debug_getupvalue(lua_State *L, int get) +{ + int32_t n = lj_lib_checkint(L, 2); + const char *name; + lj_lib_checkfunc(L, 1); + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name) { + lua_pushstring(L, name); + if (!get) return 1; + copyTV(L, L->top, L->top-2); + L->top++; + return 2; + } + return 0; +} + +LJLIB_CF(debug_getupvalue) +{ + return debug_getupvalue(L, 1); +} + +LJLIB_CF(debug_setupvalue) +{ + lj_lib_checkany(L, 3); + return debug_getupvalue(L, 0); +} + +LJLIB_CF(debug_upvalueid) +{ + GCfunc *fn = lj_lib_checkfunc(L, 1); + int32_t n = lj_lib_checkint(L, 2) - 1; + if ((uint32_t)n >= fn->l.nupvalues) + lj_err_arg(L, 2, LJ_ERR_IDXRNG); + setlightudV(L->top-1, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : + (void *)&fn->c.upvalue[n]); + return 1; +} + +LJLIB_CF(debug_upvaluejoin) +{ + GCfunc *fn[2]; + GCRef *p[2]; + int i; + for (i = 0; i < 2; i++) { + int32_t n; + fn[i] = lj_lib_checkfunc(L, 2*i+1); + if (!isluafunc(fn[i])) + lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC); + n = lj_lib_checkint(L, 2*i+2) - 1; + if ((uint32_t)n >= fn[i]->l.nupvalues) + lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG); + p[i] = &fn[i]->l.uvptr[n]; + } + setgcrefr(*p[0], *p[1]); + lj_gc_objbarrier(L, fn[0], gcref(*p[1])); + return 0; +} + +#if LJ_52 +LJLIB_CF(debug_getuservalue) +{ + TValue *o = L->base; + if (o < L->top && tvisudata(o)) + settabV(L, o, tabref(udataV(o)->env)); + else + setnilV(o); + L->top = o+1; + return 1; +} + +LJLIB_CF(debug_setuservalue) +{ + TValue *o = L->base; + if (!(o < L->top && tvisudata(o))) + lj_err_argt(L, 1, LUA_TUSERDATA); + if (!(o+1 < L->top && tvistab(o+1))) + lj_err_argt(L, 2, LUA_TTABLE); + L->top = o+2; + lua_setfenv(L, 1); + return 1; +} +#endif + +/* ------------------------------------------------------------------------ */ + +static const char KEY_HOOK = 'h'; + +static void hookf(lua_State *L, lua_Debug *ar) +{ + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_call(L, 2, 0); + } +} + +static int makemask(const char *smask, int count) +{ + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + +static char *unmakemask(int mask, char *smask) +{ + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + +LJLIB_CF(debug_sethook) +{ + int arg, mask, count; + lua_Hook func; + (void)getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, arg+1); + lua_rawset(L, LUA_REGISTRYINDEX); + lua_sethook(L, func, mask, count); + return 0; +} + +LJLIB_CF(debug_gethook) +{ + char buff[5]; + int mask = lua_gethookmask(L); + lua_Hook hook = lua_gethook(L); + if (hook != NULL && hook != hookf) { /* external hook? */ + lua_pushliteral(L, "external hook"); + } else { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L)); + return 3; +} + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(debug_debug) +{ + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + +/* ------------------------------------------------------------------------ */ + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +LJLIB_CF(debug_traceback) +{ + int arg; + lua_State *L1 = getthread(L, &arg); + const char *msg = lua_tostring(L, arg+1); + if (msg == NULL && L->top > L->base+arg) + L->top = L->base+arg+1; + else + luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1))); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_debug(lua_State *L) +{ + LJ_LIB_REG(L, LUA_DBLIBNAME, debug); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_ffi.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_ffi.c new file mode 100644 index 0000000..e789ad6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_ffi.c @@ -0,0 +1,850 @@ +/* +** FFI library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_ffi_c +#define LUA_LIB + +#include + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_ctype.h" +#include "lj_cparse.h" +#include "lj_cdata.h" +#include "lj_cconv.h" +#include "lj_carith.h" +#include "lj_ccall.h" +#include "lj_ccallback.h" +#include "lj_clib.h" +#include "lj_ff.h" +#include "lj_lib.h" + +/* -- C type checks ------------------------------------------------------- */ + +/* Check first argument for a C type and returns its ID. */ +static CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param) +{ + TValue *o = L->base; + if (!(o < L->top)) { + err_argtype: + lj_err_argtype(L, 1, "C type"); + } + if (tvisstr(o)) { /* Parse an abstract C type declaration. */ + GCstr *s = strV(o); + CPState cp; + int errcode; + cp.L = L; + cp.cts = cts; + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = param; + cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT; + errcode = lj_cparse(&cp); + if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */ + return cp.val.id; + } else { + GCcdata *cd; + if (!tviscdata(o)) goto err_argtype; + if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM); + cd = cdataV(o); + return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid; + } +} + +/* Check argument for C data and return it. */ +static GCcdata *ffi_checkcdata(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tviscdata(o))) + lj_err_argt(L, narg, LUA_TCDATA); + return cdataV(o); +} + +/* Convert argument to C pointer. */ +static void *ffi_checkptr(lua_State *L, int narg, CTypeID id) +{ + CTState *cts = ctype_cts(L); + TValue *o = L->base + narg-1; + void *p; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg)); + return p; +} + +/* Convert argument to int32_t. */ +static int32_t ffi_checkint(lua_State *L, int narg) +{ + CTState *cts = ctype_cts(L); + TValue *o = L->base + narg-1; + int32_t i; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, + CCF_ARG(narg)); + return i; +} + +/* -- C type metamethods -------------------------------------------------- */ + +#define LJLIB_MODULE_ffi_meta + +/* Handle ctype __index/__newindex metamethods. */ +static int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm) +{ + CTypeID id = ctype_typeid(cts, ct); + cTValue *tv = lj_ctype_meta(cts, id, mm); + TValue *base = L->base; + if (!tv) { + const char *s; + err_index: + s = strdata(lj_ctype_repr(L, id, NULL)); + if (tvisstr(L->base+1)) { + lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1)); + } else { + const char *key = tviscdata(L->base+1) ? + strdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) : + lj_typename(L->base+1); + lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key); + } + } + if (!tvisfunc(tv)) { + if (mm == MM_index) { + cTValue *o = lj_meta_tget(L, tv, base+1); + if (o) { + if (tvisnil(o)) goto err_index; + copyTV(L, L->top-1, o); + return 1; + } + } else { + TValue *o = lj_meta_tset(L, tv, base+1); + if (o) { + copyTV(L, o, base+2); + return 0; + } + } + tv = L->top-1; + } + return lj_meta_tailcall(L, tv); +} + +LJLIB_CF(ffi_meta___index) LJLIB_REC(cdata_index 0) +{ + CTState *cts = ctype_cts(L); + CTInfo qual = 0; + CType *ct; + uint8_t *p; + TValue *o = L->base; + if (!(o+1 < L->top && tviscdata(o))) /* Also checks for presence of key. */ + lj_err_argt(L, 1, LUA_TCDATA); + ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual); + if ((qual & 1)) + return ffi_index_meta(L, cts, ct, MM_index); + if (lj_cdata_get(cts, ct, L->top-1, p)) + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_meta___newindex) LJLIB_REC(cdata_index 1) +{ + CTState *cts = ctype_cts(L); + CTInfo qual = 0; + CType *ct; + uint8_t *p; + TValue *o = L->base; + if (!(o+2 < L->top && tviscdata(o))) /* Also checks for key and value. */ + lj_err_argt(L, 1, LUA_TCDATA); + ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual); + if ((qual & 1)) { + if ((qual & CTF_CONST)) + lj_err_caller(L, LJ_ERR_FFI_WRCONST); + return ffi_index_meta(L, cts, ct, MM_newindex); + } + lj_cdata_set(cts, ct, p, o+2, qual); + return 0; +} + +/* Common handler for cdata arithmetic. */ +static int ffi_arith(lua_State *L) +{ + MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq); + return lj_carith_op(L, mm); +} + +/* The following functions must be in contiguous ORDER MM. */ +LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___le) LJLIB_REC(cdata_arith MM_le) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___concat) LJLIB_REC(cdata_arith MM_concat) +{ + return ffi_arith(L); +} + +/* Forward declaration. */ +static int lj_cf_ffi_new(lua_State *L); + +LJLIB_CF(ffi_meta___call) LJLIB_REC(cdata_call) +{ + CTState *cts = ctype_cts(L); + GCcdata *cd = ffi_checkcdata(L, 1); + CTypeID id = cd->ctypeid; + CType *ct; + cTValue *tv; + MMS mm = MM_call; + if (cd->ctypeid == CTID_CTYPEID) { + id = *(CTypeID *)cdataptr(cd); + mm = MM_new; + } else { + int ret = lj_ccall_func(L, cd); + if (ret >= 0) + return ret; + } + /* Handle ctype __call/__new metamethod. */ + ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + if (tv) + return lj_meta_tailcall(L, tv); + else if (mm == MM_call) + lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL))); + return lj_cf_ffi_new(L); +} + +LJLIB_CF(ffi_meta___add) LJLIB_REC(cdata_arith MM_add) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___sub) LJLIB_REC(cdata_arith MM_sub) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___mul) LJLIB_REC(cdata_arith MM_mul) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___div) LJLIB_REC(cdata_arith MM_div) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___mod) LJLIB_REC(cdata_arith MM_mod) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___pow) LJLIB_REC(cdata_arith MM_pow) +{ + return ffi_arith(L); +} + +LJLIB_CF(ffi_meta___unm) LJLIB_REC(cdata_arith MM_unm) +{ + return ffi_arith(L); +} +/* End of contiguous ORDER MM. */ + +LJLIB_CF(ffi_meta___tostring) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + const char *msg = "cdata<%s>: %p"; + CTypeID id = cd->ctypeid; + void *p = cdataptr(cd); + if (id == CTID_CTYPEID) { + msg = "ctype<%s>"; + id = *(CTypeID *)p; + } else { + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, id); + if (ctype_isref(ct->info)) { + p = *(void **)p; + ct = ctype_rawchild(cts, ct); + } + if (ctype_iscomplex(ct->info)) { + setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size)); + goto checkgc; + } else if (ct->size == 8 && ctype_isinteger(ct->info)) { + setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd), + (ct->info & CTF_UNSIGNED))); + goto checkgc; + } else if (ctype_isfunc(ct->info)) { + p = *(void **)p; + } else if (ctype_isenum(ct->info)) { + msg = "cdata<%s>: %d"; + p = (void *)(uintptr_t)*(uint32_t **)p; + } else { + if (ctype_isptr(ct->info)) { + p = cdata_getptr(p, ct->size); + ct = ctype_rawchild(cts, ct); + } + if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) { + /* Handle ctype __tostring metamethod. */ + cTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring); + if (tv) + return lj_meta_tailcall(L, tv); + } + } + } + lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); +checkgc: + lj_gc_check(L); + return 1; +} + +static int ffi_pairs(lua_State *L, MMS mm) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkcdata(L, 1)->ctypeid; + CType *ct = ctype_raw(cts, id); + cTValue *tv; + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + if (!tv) + lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)), + strdata(mmname_str(G(L), mm))); + return lj_meta_tailcall(L, tv); +} + +LJLIB_CF(ffi_meta___pairs) +{ + return ffi_pairs(L, MM_pairs); +} + +LJLIB_CF(ffi_meta___ipairs) +{ + return ffi_pairs(L, MM_ipairs); +} + +LJLIB_PUSH("ffi") LJLIB_SET(__metatable) + +#include "lj_libdef.h" + +/* -- C library metamethods ----------------------------------------------- */ + +#define LJLIB_MODULE_ffi_clib + +/* Index C library by a name. */ +static TValue *ffi_clib_index(lua_State *L) +{ + TValue *o = L->base; + CLibrary *cl; + if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)) + lj_err_argt(L, 1, LUA_TUSERDATA); + cl = (CLibrary *)uddata(udataV(o)); + if (!(o+1 < L->top && tvisstr(o+1))) + lj_err_argt(L, 2, LUA_TSTRING); + return lj_clib_index(L, cl, strV(o+1)); +} + +LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index 1) +{ + TValue *tv = ffi_clib_index(L); + if (tviscdata(tv)) { + CTState *cts = ctype_cts(L); + GCcdata *cd = cdataV(tv); + CType *s = ctype_get(cts, cd->ctypeid); + if (ctype_isextern(s->info)) { + CTypeID sid = ctype_cid(s->info); + void *sp = *(void **)cdataptr(cd); + CType *ct = ctype_raw(cts, sid); + if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp)) + lj_gc_check(L); + return 1; + } + } + copyTV(L, L->top-1, tv); + return 1; +} + +LJLIB_CF(ffi_clib___newindex) LJLIB_REC(clib_index 0) +{ + TValue *tv = ffi_clib_index(L); + TValue *o = L->base+2; + if (o < L->top && tviscdata(tv)) { + CTState *cts = ctype_cts(L); + GCcdata *cd = cdataV(tv); + CType *d = ctype_get(cts, cd->ctypeid); + if (ctype_isextern(d->info)) { + CTInfo qual = 0; + for (;;) { /* Skip attributes and collect qualifiers. */ + d = ctype_child(cts, d); + if (!ctype_isattrib(d->info)) break; + if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size; + } + if (!((d->info|qual) & CTF_CONST)) { + lj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0); + return 0; + } + } + } + lj_err_caller(L, LJ_ERR_FFI_WRCONST); + return 0; /* unreachable */ +} + +LJLIB_CF(ffi_clib___gc) +{ + TValue *o = L->base; + if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB) + lj_clib_unload((CLibrary *)uddata(udataV(o))); + return 0; +} + +#include "lj_libdef.h" + +/* -- Callback function metamethods --------------------------------------- */ + +#define LJLIB_MODULE_ffi_callback + +static int ffi_callback_set(lua_State *L, GCfunc *fn) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, cd->ctypeid); + if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) { + MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd)); + if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) { + GCtab *t = cts->miscmap; + TValue *tv = lj_tab_setint(L, t, (int32_t)slot); + if (fn) { + setfuncV(L, tv, fn); + lj_gc_anybarriert(L, t); + } else { + setnilV(tv); + cts->cb.cbid[slot] = 0; + cts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid; + } + return 0; + } + } + lj_err_caller(L, LJ_ERR_FFI_BADCBACK); + return 0; +} + +LJLIB_CF(ffi_callback_free) +{ + return ffi_callback_set(L, NULL); +} + +LJLIB_CF(ffi_callback_set) +{ + GCfunc *fn = lj_lib_checkfunc(L, 2); + return ffi_callback_set(L, fn); +} + +LJLIB_PUSH(top-1) LJLIB_SET(__index) + +#include "lj_libdef.h" + +/* -- FFI library functions ----------------------------------------------- */ + +#define LJLIB_MODULE_ffi + +LJLIB_CF(ffi_cdef) +{ + GCstr *s = lj_lib_checkstr(L, 1); + CPState cp; + int errcode; + cp.L = L; + cp.cts = ctype_cts(L); + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = L->base+1; + cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT; + errcode = lj_cparse(&cp); + if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */ + lj_gc_check(L); + return 0; +} + +LJLIB_CF(ffi_new) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CType *ct = ctype_raw(cts, id); + CTSize sz; + CTInfo info = lj_ctype_info(cts, id, &sz); + TValue *o = L->base+1; + GCcdata *cd; + if ((info & CTF_VLA)) { + o++; + sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2)); + } + if (sz == CTSIZE_INVALID) + lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE); + if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN) + cd = lj_cdata_new(cts, id, sz); + else + cd = lj_cdata_newv(cts, id, sz, ctype_align(info)); + setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */ + lj_cconv_ct_init(cts, ct, sz, cdataptr(cd), + o, (MSize)(L->top - o)); /* Initialize cdata. */ + if (ctype_isstruct(ct->info)) { + /* Handle ctype __gc metamethod. Use the fast lookup here. */ + cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id); + if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) { + GCtab *t = cts->finalizer; + if (gcref(t->metatable)) { + /* Add to finalizer table, if still enabled. */ + copyTV(L, lj_tab_set(L, t, o-1), tv); + lj_gc_anybarriert(L, t); + cd->marked |= LJ_GC_CDATA_FIN; + } + } + } + L->top = o; /* Only return the cdata itself. */ + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_cast) LJLIB_REC(ffi_new) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CType *d = ctype_raw(cts, id); + TValue *o = lj_lib_checkany(L, 2); + L->top = o+1; /* Make sure this is the last item on the stack. */ + if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) { + GCcdata *cd = lj_cdata_new(cts, id, d->size); + lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST); + setcdataV(L, o, cd); + lj_gc_check(L); + } + return 1; +} + +LJLIB_CF(ffi_typeof) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, L->base+1); + GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4); + *(CTypeID *)cdataptr(cd) = id; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_istype) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + CTypeID id1 = ffi_checkctype(L, cts, NULL); + TValue *o = lj_lib_checkany(L, 2); + int b = 0; + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : + cd->ctypeid; + CType *ct1 = lj_ctype_rawref(cts, id1); + CType *ct2 = lj_ctype_rawref(cts, id2); + if (ct1 == ct2) { + b = 1; + } else if (ctype_type(ct1->info) == ctype_type(ct2->info) && + ct1->size == ct2->size) { + if (ctype_ispointer(ct1->info)) + b = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL); + else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info)) + b = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0); + } else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) && + ct1 == ctype_rawchild(cts, ct2)) { + b = 1; + } + } + setboolV(L->top-1, b); + setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */ + return 1; +} + +LJLIB_CF(ffi_sizeof) LJLIB_REC(ffi_xof FF_ffi_sizeof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CTSize sz; + if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) { + sz = cdatavlen(cdataV(L->base)); + } else { + CType *ct = lj_ctype_rawref(cts, id); + if (ctype_isvltype(ct->info)) + sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2)); + else + sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID; + if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) { + setnilV(L->top-1); + return 1; + } + } + setintV(L->top-1, (int32_t)sz); + return 1; +} + +LJLIB_CF(ffi_alignof) LJLIB_REC(ffi_xof FF_ffi_alignof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + CTSize sz = 0; + CTInfo info = lj_ctype_info(cts, id, &sz); + setintV(L->top-1, 1 << ctype_align(info)); + return 1; +} + +LJLIB_CF(ffi_offsetof) LJLIB_REC(ffi_xof FF_ffi_offsetof) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + GCstr *name = lj_lib_checkstr(L, 2); + CType *ct = lj_ctype_rawref(cts, id); + CTSize ofs; + if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) { + CType *fct = lj_ctype_getfield(cts, ct, name, &ofs); + if (fct) { + setintV(L->top-1, ofs); + if (ctype_isfield(fct->info)) { + return 1; + } else if (ctype_isbitfield(fct->info)) { + setintV(L->top++, ctype_bitpos(fct->info)); + setintV(L->top++, ctype_bitbsz(fct->info)); + return 3; + } + } + } + return 0; +} + +LJLIB_CF(ffi_errno) LJLIB_REC(.) +{ + int err = errno; + if (L->top > L->base) + errno = ffi_checkint(L, 1); + setintV(L->top++, err); + return 1; +} + +LJLIB_CF(ffi_string) LJLIB_REC(.) +{ + CTState *cts = ctype_cts(L); + TValue *o = lj_lib_checkany(L, 1); + const char *p; + size_t len; + if (o+1 < L->top && !tvisnil(o+1)) { + len = (size_t)ffi_checkint(L, 2); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o, + CCF_ARG(1)); + } else { + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o, + CCF_ARG(1)); + len = strlen(p); + } + L->top = o+1; /* Make sure this is the last item on the stack. */ + setstrV(L, o, lj_str_new(L, p, len)); + lj_gc_check(L); + return 1; +} + +LJLIB_CF(ffi_copy) LJLIB_REC(.) +{ + void *dp = ffi_checkptr(L, 1, CTID_P_VOID); + void *sp = ffi_checkptr(L, 2, CTID_P_CVOID); + TValue *o = L->base+1; + CTSize len; + if (tvisstr(o) && o+1 >= L->top) + len = strV(o)->len+1; /* Copy Lua string including trailing '\0'. */ + else + len = (CTSize)ffi_checkint(L, 3); + memcpy(dp, sp, len); + return 0; +} + +LJLIB_CF(ffi_fill) LJLIB_REC(.) +{ + void *dp = ffi_checkptr(L, 1, CTID_P_VOID); + CTSize len = (CTSize)ffi_checkint(L, 2); + int32_t fill = 0; + if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3); + memset(dp, fill, len); + return 0; +} + +#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be) + +/* Test ABI string. */ +LJLIB_CF(ffi_abi) LJLIB_REC(.) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int b = 0; + switch (s->hash) { +#if LJ_64 + case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */ +#else + case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */ +#endif +#if LJ_ARCH_HASFPU + case H_(e33ee463,e33ee463): b = 1; break; /* fpu */ +#endif +#if LJ_ABI_SOFTFP + case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */ +#else + case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */ +#endif +#if LJ_ABI_EABI + case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */ +#endif +#if LJ_ABI_WIN + case H_(4ab624a8,4ab624a8): b = 1; break; /* win */ +#endif + case H_(3af93066,1f001464): b = 1; break; /* le/be */ + default: + break; + } + setboolV(L->top-1, b); + setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */ + return 1; +} + +#undef H_ + +LJLIB_PUSH(top-8) LJLIB_SET(!) /* Store reference to miscmap table. */ + +LJLIB_CF(ffi_metatype) +{ + CTState *cts = ctype_cts(L); + CTypeID id = ffi_checkctype(L, cts, NULL); + GCtab *mt = lj_lib_checktab(L, 2); + GCtab *t = cts->miscmap; + CType *ct = ctype_get(cts, id); /* Only allow raw types. */ + TValue *tv; + GCcdata *cd; + if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) || + ctype_isvector(ct->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + tv = lj_tab_setinth(L, t, -(int32_t)id); + if (!tvisnil(tv)) + lj_err_caller(L, LJ_ERR_PROTMT); + settabV(L, tv, mt); + lj_gc_anybarriert(L, t); + cd = lj_cdata_new(cts, CTID_CTYPEID, 4); + *(CTypeID *)cdataptr(cd) = id; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */ + +LJLIB_CF(ffi_gc) LJLIB_REC(.) +{ + GCcdata *cd = ffi_checkcdata(L, 1); + TValue *fin = lj_lib_checkany(L, 2); + CTState *cts = ctype_cts(L); + GCtab *t = cts->finalizer; + CType *ct = ctype_raw(cts, cd->ctypeid); + if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) || + ctype_isrefarray(ct->info))) + lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); + if (gcref(t->metatable)) { /* Update finalizer table, if still enabled. */ + copyTV(L, lj_tab_set(L, t, L->base), fin); + lj_gc_anybarriert(L, t); + if (!tvisnil(fin)) + cd->marked |= LJ_GC_CDATA_FIN; + else + cd->marked &= ~LJ_GC_CDATA_FIN; + } + L->top = L->base+1; /* Pass through the cdata object. */ + return 1; +} + +LJLIB_PUSH(top-5) LJLIB_SET(!) /* Store clib metatable in func environment. */ + +LJLIB_CF(ffi_load) +{ + GCstr *name = lj_lib_checkstr(L, 1); + int global = (L->base+1 < L->top && tvistruecond(L->base+1)); + lj_clib_load(L, tabref(curr_func(L)->c.env), name, global); + return 1; +} + +LJLIB_PUSH(top-4) LJLIB_SET(C) +LJLIB_PUSH(top-3) LJLIB_SET(os) +LJLIB_PUSH(top-2) LJLIB_SET(arch) + +#include "lj_libdef.h" + +/* ------------------------------------------------------------------------ */ + +/* Create special weak-keyed finalizer table. */ +static GCtab *ffi_finalizer(lua_State *L) +{ + /* NOBARRIER: The table is new (marked white). */ + GCtab *t = lj_tab_new(L, 0, 1); + settabV(L, L->top++, t); + setgcref(t->metatable, obj2gco(t)); + setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), + lj_str_newlit(L, "K")); + t->nomm = (uint8_t)(~(1u<top-1); + lj_gc_anybarriert(L, t); + } +} + +LUALIB_API int luaopen_ffi(lua_State *L) +{ + CTState *cts = lj_ctype_init(L); + settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1))); + cts->finalizer = ffi_finalizer(L); + LJ_LIB_REG(L, NULL, ffi_meta); + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1))); + LJ_LIB_REG(L, NULL, ffi_clib); + LJ_LIB_REG(L, NULL, ffi_callback); + /* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */ + settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1)); + L->top--; + lj_clib_default(L, tabV(L->top-1)); /* Create ffi.C default namespace. */ + lua_pushliteral(L, LJ_OS_NAME); + lua_pushliteral(L, LJ_ARCH_NAME); + LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */ + ffi_register_module(L); + return 1; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_init.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_init.c new file mode 100644 index 0000000..a729d12 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_init.c @@ -0,0 +1,55 @@ +/* +** Library initialization. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major parts taken verbatim from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_init_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_arch.h" + +static const luaL_Reg lj_lib_load[] = { + { "", luaopen_base }, + { LUA_LOADLIBNAME, luaopen_package }, + { LUA_TABLIBNAME, luaopen_table }, + { LUA_IOLIBNAME, luaopen_io }, + { LUA_OSLIBNAME, luaopen_os }, + { LUA_STRLIBNAME, luaopen_string }, + { LUA_MATHLIBNAME, luaopen_math }, + { LUA_DBLIBNAME, luaopen_debug }, + { LUA_BITLIBNAME, luaopen_bit }, + { LUA_JITLIBNAME, luaopen_jit }, + { NULL, NULL } +}; + +static const luaL_Reg lj_lib_preload[] = { +#if LJ_HASFFI + { LUA_FFILIBNAME, luaopen_ffi }, +#endif + { NULL, NULL } +}; + +LUALIB_API void luaL_openlibs(lua_State *L) +{ + const luaL_Reg *lib; + for (lib = lj_lib_load; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } + luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", + sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1); + for (lib = lj_lib_preload; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_setfield(L, -2, lib->name); + } + lua_pop(L, 1); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_io.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_io.c new file mode 100644 index 0000000..4fbc8eb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_io.c @@ -0,0 +1,538 @@ +/* +** I/O library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include + +#define lib_io_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_state.h" +#include "lj_ff.h" +#include "lj_lib.h" + +/* Userdata payload for I/O file. */ +typedef struct IOFileUD { + FILE *fp; /* File handle. */ + uint32_t type; /* File type. */ +} IOFileUD; + +#define IOFILE_TYPE_FILE 0 /* Regular file. */ +#define IOFILE_TYPE_PIPE 1 /* Pipe. */ +#define IOFILE_TYPE_STDF 2 /* Standard file handle. */ +#define IOFILE_TYPE_MASK 3 + +#define IOFILE_FLAG_CLOSE 4 /* Close after io.lines() iterator. */ + +#define IOSTDF_UD(L, id) (&gcref(G(L)->gcroot[(id)])->ud) +#define IOSTDF_IOF(L, id) ((IOFileUD *)uddata(IOSTDF_UD(L, (id)))) + +/* -- Open/close helpers -------------------------------------------------- */ + +static IOFileUD *io_tofilep(lua_State *L) +{ + if (!(L->base < L->top && tvisudata(L->base) && + udataV(L->base)->udtype == UDTYPE_IO_FILE)) + lj_err_argtype(L, 1, "FILE*"); + return (IOFileUD *)uddata(udataV(L->base)); +} + +static IOFileUD *io_tofile(lua_State *L) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOCLFL); + return iof; +} + +static FILE *io_stdfile(lua_State *L, ptrdiff_t id) +{ + IOFileUD *iof = IOSTDF_IOF(L, id); + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOSTDCL); + return iof->fp; +} + +static IOFileUD *io_file_new(lua_State *L) +{ + IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD)); + GCudata *ud = udataV(L->top-1); + ud->udtype = UDTYPE_IO_FILE; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcrefr(ud->metatable, curr_func(L)->c.env); + iof->fp = NULL; + iof->type = IOFILE_TYPE_FILE; + return iof; +} + +static IOFileUD *io_file_open(lua_State *L, const char *mode) +{ + const char *fname = strdata(lj_lib_checkstr(L, 1)); + IOFileUD *iof = io_file_new(L); + iof->fp = fopen(fname, mode); + if (iof->fp == NULL) + luaL_argerror(L, 1, lj_str_pushf(L, "%s: %s", fname, strerror(errno))); + return iof; +} + +static int io_file_close(lua_State *L, IOFileUD *iof) +{ + int ok; + if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) { + ok = (fclose(iof->fp) == 0); + } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) { + int stat = -1; +#if LJ_TARGET_POSIX + stat = pclose(iof->fp); +#elif LJ_TARGET_WINDOWS + stat = _pclose(iof->fp); +#else + lua_assert(0); + return 0; +#endif +#if LJ_52 + iof->fp = NULL; + return luaL_execresult(L, stat); +#else + ok = (stat != -1); +#endif + } else { + lua_assert((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_STDF); + setnilV(L->top++); + lua_pushliteral(L, "cannot close standard file"); + return 2; + } + iof->fp = NULL; + return luaL_fileresult(L, ok, NULL); +} + +/* -- Read/write helpers -------------------------------------------------- */ + +static int io_file_readnum(lua_State *L, FILE *fp) +{ + lua_Number d; + if (fscanf(fp, LUA_NUMBER_SCAN, &d) == 1) { + if (LJ_DUALNUM) { + int32_t i = lj_num2int(d); + if (d == (lua_Number)i && !tvismzero((cTValue *)&d)) { + setintV(L->top++, i); + return 1; + } + } + setnumV(L->top++, d); + return 1; + } else { + setnilV(L->top++); + return 0; + } +} + +static int io_file_readline(lua_State *L, FILE *fp, MSize chop) +{ + MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0; + char *buf; + for (;;) { + buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + if (fgets(buf+n, m-n, fp) == NULL) break; + n += (MSize)strlen(buf+n); + ok |= n; + if (n && buf[n-1] == '\n') { n -= chop; break; } + if (n >= m - 64) m += m; + } + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return (int)ok; +} + +static void io_file_readall(lua_State *L, FILE *fp) +{ + MSize m, n; + for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) { + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + n += (MSize)fread(buf+n, 1, m-n, fp); + if (n != m) { + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return; + } + } +} + +static int io_file_readlen(lua_State *L, FILE *fp, MSize m) +{ + if (m) { + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); + MSize n = (MSize)fread(buf, 1, m, fp); + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); + lj_gc_check(L); + return (n > 0 || m == 0); + } else { + int c = getc(fp); + ungetc(c, fp); + setstrV(L, L->top++, &G(L)->strempty); + return (c != EOF); + } +} + +static int io_file_read(lua_State *L, FILE *fp, int start) +{ + int ok, n, nargs = (int)(L->top - L->base) - start; + clearerr(fp); + if (nargs == 0) { + ok = io_file_readline(L, fp, 1); + n = start+1; /* Return 1 result. */ + } else { + /* The results plus the buffers go on top of the args. */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + ok = 1; + for (n = start; nargs-- && ok; n++) { + if (tvisstr(L->base+n)) { + const char *p = strVdata(L->base+n); + if (p[0] != '*') + lj_err_arg(L, n+1, LJ_ERR_INVOPT); + if (p[1] == 'n') + ok = io_file_readnum(L, fp); + else if ((p[1] & ~0x20) == 'L') + ok = io_file_readline(L, fp, (p[1] == 'l')); + else if (p[1] == 'a') + io_file_readall(L, fp); + else + lj_err_arg(L, n+1, LJ_ERR_INVFMT); + } else if (tvisnumber(L->base+n)) { + ok = io_file_readlen(L, fp, (MSize)lj_lib_checkint(L, n+1)); + } else { + lj_err_arg(L, n+1, LJ_ERR_INVOPT); + } + } + } + if (ferror(fp)) + return luaL_fileresult(L, 0, NULL); + if (!ok) + setnilV(L->top-1); /* Replace last result with nil. */ + return n - start; +} + +static int io_file_write(lua_State *L, FILE *fp, int start) +{ + cTValue *tv; + int status = 1; + for (tv = L->base+start; tv < L->top; tv++) { + if (tvisstr(tv)) { + MSize len = strV(tv)->len; + status = status && (fwrite(strVdata(tv), 1, len, fp) == len); + } else if (tvisint(tv)) { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, intV(tv)); + size_t len = (size_t)(buf+LJ_STR_INTBUF-p); + status = status && (fwrite(p, 1, len, fp) == len); + } else if (tvisnum(tv)) { + status = status && (fprintf(fp, LUA_NUMBER_FMT, numV(tv)) > 0); + } else { + lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING); + } + } + if (LJ_52 && status) { + L->top = L->base+1; + if (start == 0) + setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT)); + return 1; + } + return luaL_fileresult(L, status, NULL); +} + +static int io_file_iter(lua_State *L) +{ + GCfunc *fn = curr_func(L); + IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0])); + int n = fn->c.nupvalues - 1; + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOCLFL); + L->top = L->base; + if (n) { /* Copy upvalues with options to stack. */ + if (n > LUAI_MAXCSTACK) + lj_err_caller(L, LJ_ERR_STKOV); + lj_state_checkstack(L, (MSize)n); + memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue)); + L->top += n; + } + n = io_file_read(L, iof->fp, 0); + if (ferror(iof->fp)) + lj_err_callermsg(L, strVdata(L->top-2)); + if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) { + io_file_close(L, iof); /* Return values are ignored. */ + return 0; + } + return n; +} + +/* -- I/O file methods ---------------------------------------------------- */ + +#define LJLIB_MODULE_io_method + +LJLIB_CF(io_method_close) +{ + IOFileUD *iof = L->base < L->top ? io_tofile(L) : + IOSTDF_IOF(L, GCROOT_IO_OUTPUT); + return io_file_close(L, iof); +} + +LJLIB_CF(io_method_read) +{ + return io_file_read(L, io_tofile(L)->fp, 1); +} + +LJLIB_CF(io_method_write) LJLIB_REC(io_write 0) +{ + return io_file_write(L, io_tofile(L)->fp, 1); +} + +LJLIB_CF(io_method_flush) LJLIB_REC(io_flush 0) +{ + return luaL_fileresult(L, fflush(io_tofile(L)->fp) == 0, NULL); +} + +LJLIB_CF(io_method_seek) +{ + FILE *fp = io_tofile(L)->fp; + int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); + int64_t ofs = 0; + cTValue *o; + int res; + if (opt == 0) opt = SEEK_SET; + else if (opt == 1) opt = SEEK_CUR; + else if (opt == 2) opt = SEEK_END; + o = L->base+2; + if (o < L->top) { + if (tvisint(o)) + ofs = (int64_t)intV(o); + else if (tvisnum(o)) + ofs = (int64_t)numV(o); + else if (!tvisnil(o)) + lj_err_argt(L, 3, LUA_TNUMBER); + } +#if LJ_TARGET_POSIX + res = fseeko(fp, ofs, opt); +#elif _MSC_VER >= 1400 + res = _fseeki64(fp, ofs, opt); +#elif defined(__MINGW32__) + res = fseeko64(fp, ofs, opt); +#else + res = fseek(fp, (long)ofs, opt); +#endif + if (res) + return luaL_fileresult(L, 0, NULL); +#if LJ_TARGET_POSIX + ofs = ftello(fp); +#elif _MSC_VER >= 1400 + ofs = _ftelli64(fp); +#elif defined(__MINGW32__) + ofs = ftello64(fp); +#else + ofs = (int64_t)ftell(fp); +#endif + setint64V(L->top-1, ofs); + return 1; +} + +LJLIB_CF(io_method_setvbuf) +{ + FILE *fp = io_tofile(L)->fp; + int opt = lj_lib_checkopt(L, 2, -1, "\4full\4line\2no"); + size_t sz = (size_t)lj_lib_optint(L, 3, LUAL_BUFFERSIZE); + if (opt == 0) opt = _IOFBF; + else if (opt == 1) opt = _IOLBF; + else if (opt == 2) opt = _IONBF; + return luaL_fileresult(L, setvbuf(fp, NULL, opt, sz) == 0, NULL); +} + +LJLIB_CF(io_method_lines) +{ + io_tofile(L); + lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); + return 1; +} + +LJLIB_CF(io_method___gc) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp != NULL && (iof->type & IOFILE_TYPE_MASK) != IOFILE_TYPE_STDF) + io_file_close(L, iof); + return 0; +} + +LJLIB_CF(io_method___tostring) +{ + IOFileUD *iof = io_tofilep(L); + if (iof->fp != NULL) + lua_pushfstring(L, "file (%p)", iof->fp); + else + lua_pushliteral(L, "file (closed)"); + return 1; +} + +LJLIB_PUSH(top-1) LJLIB_SET(__index) + +#include "lj_libdef.h" + +/* -- I/O library functions ----------------------------------------------- */ + +#define LJLIB_MODULE_io + +LJLIB_PUSH(top-2) LJLIB_SET(!) /* Set environment. */ +LJLIB_CF(io_open) +{ + const char *fname = strdata(lj_lib_checkstr(L, 1)); + GCstr *s = lj_lib_optstr(L, 2); + const char *mode = s ? strdata(s) : "r"; + IOFileUD *iof = io_file_new(L); + iof->fp = fopen(fname, mode); + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname); +} + +LJLIB_CF(io_popen) +{ +#if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS + const char *fname = strdata(lj_lib_checkstr(L, 1)); + GCstr *s = lj_lib_optstr(L, 2); + const char *mode = s ? strdata(s) : "r"; + IOFileUD *iof = io_file_new(L); + iof->type = IOFILE_TYPE_PIPE; +#if LJ_TARGET_POSIX + fflush(NULL); + iof->fp = popen(fname, mode); +#else + iof->fp = _popen(fname, mode); +#endif + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname); +#else + return luaL_error(L, LUA_QL("popen") " not supported"); +#endif +} + +LJLIB_CF(io_tmpfile) +{ + IOFileUD *iof = io_file_new(L); +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 + iof->fp = NULL; errno = ENOSYS; +#else + iof->fp = tmpfile(); +#endif + return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL); +} + +LJLIB_CF(io_close) +{ + return lj_cf_io_method_close(L); +} + +LJLIB_CF(io_read) +{ + return io_file_read(L, io_stdfile(L, GCROOT_IO_INPUT), 0); +} + +LJLIB_CF(io_write) LJLIB_REC(io_write GCROOT_IO_OUTPUT) +{ + return io_file_write(L, io_stdfile(L, GCROOT_IO_OUTPUT), 0); +} + +LJLIB_CF(io_flush) LJLIB_REC(io_flush GCROOT_IO_OUTPUT) +{ + return luaL_fileresult(L, fflush(io_stdfile(L, GCROOT_IO_OUTPUT)) == 0, NULL); +} + +static int io_std_getset(lua_State *L, ptrdiff_t id, const char *mode) +{ + if (L->base < L->top && !tvisnil(L->base)) { + if (tvisudata(L->base)) { + io_tofile(L); + L->top = L->base+1; + } else { + io_file_open(L, mode); + } + /* NOBARRIER: The standard I/O handles are GC roots. */ + setgcref(G(L)->gcroot[id], gcV(L->top-1)); + } else { + setudataV(L, L->top++, IOSTDF_UD(L, id)); + } + return 1; +} + +LJLIB_CF(io_input) +{ + return io_std_getset(L, GCROOT_IO_INPUT, "r"); +} + +LJLIB_CF(io_output) +{ + return io_std_getset(L, GCROOT_IO_OUTPUT, "w"); +} + +LJLIB_CF(io_lines) +{ + if (L->base == L->top) setnilV(L->top++); + if (!tvisnil(L->base)) { /* io.lines(fname) */ + IOFileUD *iof = io_file_open(L, "r"); + iof->type = IOFILE_TYPE_FILE|IOFILE_FLAG_CLOSE; + L->top--; + setudataV(L, L->base, udataV(L->top)); + } else { /* io.lines() iterates over stdin. */ + setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); + } + lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); + return 1; +} + +LJLIB_CF(io_type) +{ + cTValue *o = lj_lib_checkany(L, 1); + if (!(tvisudata(o) && udataV(o)->udtype == UDTYPE_IO_FILE)) + setnilV(L->top++); + else if (((IOFileUD *)uddata(udataV(o)))->fp != NULL) + lua_pushliteral(L, "file"); + else + lua_pushliteral(L, "closed file"); + return 1; +} + +#include "lj_libdef.h" + +/* ------------------------------------------------------------------------ */ + +static GCobj *io_std_new(lua_State *L, FILE *fp, const char *name) +{ + IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD)); + GCudata *ud = udataV(L->top-1); + ud->udtype = UDTYPE_IO_FILE; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcref(ud->metatable, gcV(L->top-3)); + iof->fp = fp; + iof->type = IOFILE_TYPE_STDF; + lua_setfield(L, -2, name); + return obj2gco(ud); +} + +LUALIB_API int luaopen_io(lua_State *L) +{ + LJ_LIB_REG(L, NULL, io_method); + copyTV(L, L->top, L->top-1); L->top++; + lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + LJ_LIB_REG(L, LUA_IOLIBNAME, io); + setgcref(G(L)->gcroot[GCROOT_IO_INPUT], io_std_new(L, stdin, "stdin")); + setgcref(G(L)->gcroot[GCROOT_IO_OUTPUT], io_std_new(L, stdout, "stdout")); + io_std_new(L, stderr, "stderr"); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_jit.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_jit.c new file mode 100644 index 0000000..0fadf8b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_jit.c @@ -0,0 +1,663 @@ +/* +** JIT library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lib_jit_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_arch.h" +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_target.h" +#endif +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" +#include "lj_lib.h" + +#include "luajit.h" + +/* -- jit.* functions ----------------------------------------------------- */ + +#define LJLIB_MODULE_jit + +static int setjitmode(lua_State *L, int mode) +{ + int idx = 0; + if (L->base == L->top || tvisnil(L->base)) { /* jit.on/off/flush([nil]) */ + mode |= LUAJIT_MODE_ENGINE; + } else { + /* jit.on/off/flush(func|proto, nil|true|false) */ + if (tvisfunc(L->base) || tvisproto(L->base)) + idx = 1; + else if (!tvistrue(L->base)) /* jit.on/off/flush(true, nil|true|false) */ + goto err; + if (L->base+1 < L->top && tvisbool(L->base+1)) + mode |= boolV(L->base+1) ? LUAJIT_MODE_ALLFUNC : LUAJIT_MODE_ALLSUBFUNC; + else + mode |= LUAJIT_MODE_FUNC; + } + if (luaJIT_setmode(L, idx, mode) != 1) { + if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE) + lj_err_caller(L, LJ_ERR_NOJIT); + err: + lj_err_argt(L, 1, LUA_TFUNCTION); + } + return 0; +} + +LJLIB_CF(jit_on) +{ + return setjitmode(L, LUAJIT_MODE_ON); +} + +LJLIB_CF(jit_off) +{ + return setjitmode(L, LUAJIT_MODE_OFF); +} + +LJLIB_CF(jit_flush) +{ +#if LJ_HASJIT + if (L->base < L->top && tvisnumber(L->base)) { + int traceno = lj_lib_checkint(L, 1); + luaJIT_setmode(L, traceno, LUAJIT_MODE_FLUSH|LUAJIT_MODE_TRACE); + return 0; + } +#endif + return setjitmode(L, LUAJIT_MODE_FLUSH); +} + +#if LJ_HASJIT +/* Push a string for every flag bit that is set. */ +static void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base, + const char *str) +{ + for (; *str; base <<= 1, str += 1+*str) + if (flags & base) + setstrV(L, L->top++, lj_str_new(L, str+1, *(uint8_t *)str)); +} +#endif + +LJLIB_CF(jit_status) +{ +#if LJ_HASJIT + jit_State *J = L2J(L); + L->top = L->base; + setboolV(L->top++, (J->flags & JIT_F_ON) ? 1 : 0); + flagbits_to_strings(L, J->flags, JIT_F_CPU_FIRST, JIT_F_CPUSTRING); + flagbits_to_strings(L, J->flags, JIT_F_OPT_FIRST, JIT_F_OPTSTRING); + return (int)(L->top - L->base); +#else + setboolV(L->top++, 0); + return 1; +#endif +} + +LJLIB_CF(jit_attach) +{ +#ifdef LUAJIT_DISABLE_VMEVENT + luaL_error(L, "vmevent API disabled"); +#else + GCfunc *fn = lj_lib_checkfunc(L, 1); + GCstr *s = lj_lib_optstr(L, 2); + luaL_findtable(L, LUA_REGISTRYINDEX, LJ_VMEVENTS_REGKEY, LJ_VMEVENTS_HSIZE); + if (s) { /* Attach to given event. */ + const uint8_t *p = (const uint8_t *)strdata(s); + uint32_t h = s->len; + while (*p) h = h ^ (lj_rol(h, 6) + *p++); + lua_pushvalue(L, 1); + lua_rawseti(L, -2, VMEVENT_HASHIDX(h)); + G(L)->vmevmask = VMEVENT_NOCACHE; /* Invalidate cache. */ + } else { /* Detach if no event given. */ + setnilV(L->top++); + while (lua_next(L, -2)) { + L->top--; + if (tvisfunc(L->top) && funcV(L->top) == fn) { + setnilV(lj_tab_set(L, tabV(L->top-2), L->top-1)); + } + } + } +#endif + return 0; +} + +LJLIB_PUSH(top-5) LJLIB_SET(os) +LJLIB_PUSH(top-4) LJLIB_SET(arch) +LJLIB_PUSH(top-3) LJLIB_SET(version_num) +LJLIB_PUSH(top-2) LJLIB_SET(version) + +#include "lj_libdef.h" + +/* -- jit.util.* functions ------------------------------------------------ */ + +#define LJLIB_MODULE_jit_util + +/* -- Reflection API for Lua functions ------------------------------------ */ + +/* Return prototype of first argument (Lua function or prototype object) */ +static GCproto *check_Lproto(lua_State *L, int nolua) +{ + TValue *o = L->base; + if (L->top > o) { + if (tvisproto(o)) { + return protoV(o); + } else if (tvisfunc(o)) { + if (isluafunc(funcV(o))) + return funcproto(funcV(o)); + else if (nolua) + return NULL; + } + } + lj_err_argt(L, 1, LUA_TFUNCTION); + return NULL; /* unreachable */ +} + +static void setintfield(lua_State *L, GCtab *t, const char *name, int32_t val) +{ + setintV(lj_tab_setstr(L, t, lj_str_newz(L, name)), val); +} + +/* local info = jit.util.funcinfo(func [,pc]) */ +LJLIB_CF(jit_util_funcinfo) +{ + GCproto *pt = check_Lproto(L, 1); + if (pt) { + BCPos pc = (BCPos)lj_lib_optint(L, 2, 0); + GCtab *t; + lua_createtable(L, 0, 16); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + setintfield(L, t, "linedefined", pt->firstline); + setintfield(L, t, "lastlinedefined", pt->firstline + pt->numline); + setintfield(L, t, "stackslots", pt->framesize); + setintfield(L, t, "params", pt->numparams); + setintfield(L, t, "bytecodes", (int32_t)pt->sizebc); + setintfield(L, t, "gcconsts", (int32_t)pt->sizekgc); + setintfield(L, t, "nconsts", (int32_t)pt->sizekn); + setintfield(L, t, "upvalues", (int32_t)pt->sizeuv); + if (pc < pt->sizebc) + setintfield(L, t, "currentline", lj_debug_line(pt, pc)); + lua_pushboolean(L, (pt->flags & PROTO_VARARG)); + lua_setfield(L, -2, "isvararg"); + lua_pushboolean(L, (pt->flags & PROTO_CHILD)); + lua_setfield(L, -2, "children"); + setstrV(L, L->top++, proto_chunkname(pt)); + lua_setfield(L, -2, "source"); + lj_debug_pushloc(L, pt, pc); + lua_setfield(L, -2, "loc"); + } else { + GCfunc *fn = funcV(L->base); + GCtab *t; + lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + if (!iscfunc(fn)) + setintfield(L, t, "ffid", fn->c.ffid); + setintptrV(lj_tab_setstr(L, t, lj_str_newlit(L, "addr")), + (intptr_t)(void *)fn->c.f); + setintfield(L, t, "upvalues", fn->c.nupvalues); + } + return 1; +} + +/* local ins, m = jit.util.funcbc(func, pc) */ +LJLIB_CF(jit_util_funcbc) +{ + GCproto *pt = check_Lproto(L, 0); + BCPos pc = (BCPos)lj_lib_checkint(L, 2); + if (pc < pt->sizebc) { + BCIns ins = proto_bc(pt)[pc]; + BCOp op = bc_op(ins); + lua_assert(op < BC__MAX); + setintV(L->top, ins); + setintV(L->top+1, lj_bc_mode[op]); + L->top += 2; + return 2; + } + return 0; +} + +/* local k = jit.util.funck(func, idx) */ +LJLIB_CF(jit_util_funck) +{ + GCproto *pt = check_Lproto(L, 0); + ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2); + if (idx >= 0) { + if (idx < (ptrdiff_t)pt->sizekn) { + copyTV(L, L->top-1, proto_knumtv(pt, idx)); + return 1; + } + } else { + if (~idx < (ptrdiff_t)pt->sizekgc) { + GCobj *gc = proto_kgc(pt, idx); + setgcV(L, L->top-1, gc, ~gc->gch.gct); + return 1; + } + } + return 0; +} + +/* local name = jit.util.funcuvname(func, idx) */ +LJLIB_CF(jit_util_funcuvname) +{ + GCproto *pt = check_Lproto(L, 0); + uint32_t idx = (uint32_t)lj_lib_checkint(L, 2); + if (idx < pt->sizeuv) { + setstrV(L, L->top-1, lj_str_newz(L, lj_debug_uvname(pt, idx))); + return 1; + } + return 0; +} + +/* -- Reflection API for traces ------------------------------------------- */ + +#if LJ_HASJIT + +/* Check trace argument. Must not throw for non-existent trace numbers. */ +static GCtrace *jit_checktrace(lua_State *L) +{ + TraceNo tr = (TraceNo)lj_lib_checkint(L, 1); + jit_State *J = L2J(L); + if (tr > 0 && tr < J->sizetrace) + return traceref(J, tr); + return NULL; +} + +/* Names of link types. ORDER LJ_TRLINK */ +static const char *const jit_trlinkname[] = { + "none", "root", "loop", "tail-recursion", "up-recursion", "down-recursion", + "interpreter", "return" +}; + +/* local info = jit.util.traceinfo(tr) */ +LJLIB_CF(jit_util_traceinfo) +{ + GCtrace *T = jit_checktrace(L); + if (T) { + GCtab *t; + lua_createtable(L, 0, 8); /* Increment hash size if fields are added. */ + t = tabV(L->top-1); + setintfield(L, t, "nins", (int32_t)T->nins - REF_BIAS - 1); + setintfield(L, t, "nk", REF_BIAS - (int32_t)T->nk); + setintfield(L, t, "link", T->link); + setintfield(L, t, "nexit", T->nsnap); + setstrV(L, L->top++, lj_str_newz(L, jit_trlinkname[T->linktype])); + lua_setfield(L, -2, "linktype"); + /* There are many more fields. Add them only when needed. */ + return 1; + } + return 0; +} + +/* local m, ot, op1, op2, prev = jit.util.traceir(tr, idx) */ +LJLIB_CF(jit_util_traceir) +{ + GCtrace *T = jit_checktrace(L); + IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS; + if (T && ref >= REF_BIAS && ref < T->nins) { + IRIns *ir = &T->ir[ref]; + int32_t m = lj_ir_mode[ir->o]; + setintV(L->top-2, m); + setintV(L->top-1, ir->ot); + setintV(L->top++, (int32_t)ir->op1 - (irm_op1(m)==IRMref ? REF_BIAS : 0)); + setintV(L->top++, (int32_t)ir->op2 - (irm_op2(m)==IRMref ? REF_BIAS : 0)); + setintV(L->top++, ir->prev); + return 5; + } + return 0; +} + +/* local k, t [, slot] = jit.util.tracek(tr, idx) */ +LJLIB_CF(jit_util_tracek) +{ + GCtrace *T = jit_checktrace(L); + IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS; + if (T && ref >= T->nk && ref < REF_BIAS) { + IRIns *ir = &T->ir[ref]; + int32_t slot = -1; + if (ir->o == IR_KSLOT) { + slot = ir->op2; + ir = &T->ir[ir->op1]; + } + lj_ir_kvalue(L, L->top-2, ir); + setintV(L->top-1, (int32_t)irt_type(ir->t)); + if (slot == -1) + return 2; + setintV(L->top++, slot); + return 3; + } + return 0; +} + +/* local snap = jit.util.tracesnap(tr, sn) */ +LJLIB_CF(jit_util_tracesnap) +{ + GCtrace *T = jit_checktrace(L); + SnapNo sn = (SnapNo)lj_lib_checkint(L, 2); + if (T && sn < T->nsnap) { + SnapShot *snap = &T->snap[sn]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + GCtab *t; + lua_createtable(L, nent+2, 0); + t = tabV(L->top-1); + setintV(lj_tab_setint(L, t, 0), (int32_t)snap->ref - REF_BIAS); + setintV(lj_tab_setint(L, t, 1), (int32_t)snap->nslots); + for (n = 0; n < nent; n++) + setintV(lj_tab_setint(L, t, (int32_t)(n+2)), (int32_t)map[n]); + setintV(lj_tab_setint(L, t, (int32_t)(nent+2)), (int32_t)SNAP(255, 0, 0)); + return 1; + } + return 0; +} + +/* local mcode, addr, loop = jit.util.tracemc(tr) */ +LJLIB_CF(jit_util_tracemc) +{ + GCtrace *T = jit_checktrace(L); + if (T && T->mcode != NULL) { + setstrV(L, L->top-1, lj_str_new(L, (const char *)T->mcode, T->szmcode)); + setintptrV(L->top++, (intptr_t)(void *)T->mcode); + setintV(L->top++, T->mcloop); + return 3; + } + return 0; +} + +/* local addr = jit.util.traceexitstub([tr,] exitno) */ +LJLIB_CF(jit_util_traceexitstub) +{ +#ifdef EXITSTUBS_PER_GROUP + ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1); + jit_State *J = L2J(L); + if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) { + setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno)); + return 1; + } +#else + if (L->top > L->base+1) { /* Don't throw for one-argument variant. */ + GCtrace *T = jit_checktrace(L); + ExitNo exitno = (ExitNo)lj_lib_checkint(L, 2); + ExitNo maxexit = T->root ? T->nsnap+1 : T->nsnap; + if (T && T->mcode != NULL && exitno < maxexit) { + setintptrV(L->top-1, (intptr_t)(void *)exitstub_trace_addr(T, exitno)); + return 1; + } + } +#endif + return 0; +} + +/* local addr = jit.util.ircalladdr(idx) */ +LJLIB_CF(jit_util_ircalladdr) +{ + uint32_t idx = (uint32_t)lj_lib_checkint(L, 1); + if (idx < IRCALL__MAX) { + setintptrV(L->top-1, (intptr_t)(void *)lj_ir_callinfo[idx].func); + return 1; + } + return 0; +} + +#endif + +#include "lj_libdef.h" + +/* -- jit.opt module ------------------------------------------------------ */ + +#if LJ_HASJIT + +#define LJLIB_MODULE_jit_opt + +/* Parse optimization level. */ +static int jitopt_level(jit_State *J, const char *str) +{ + if (str[0] >= '0' && str[0] <= '9' && str[1] == '\0') { + uint32_t flags; + if (str[0] == '0') flags = JIT_F_OPT_0; + else if (str[0] == '1') flags = JIT_F_OPT_1; + else if (str[0] == '2') flags = JIT_F_OPT_2; + else flags = JIT_F_OPT_3; + J->flags = (J->flags & ~JIT_F_OPT_MASK) | flags; + return 1; /* Ok. */ + } + return 0; /* No match. */ +} + +/* Parse optimization flag. */ +static int jitopt_flag(jit_State *J, const char *str) +{ + const char *lst = JIT_F_OPTSTRING; + uint32_t opt; + int set = 1; + if (str[0] == '+') { + str++; + } else if (str[0] == '-') { + str++; + set = 0; + } else if (str[0] == 'n' && str[1] == 'o') { + str += str[2] == '-' ? 3 : 2; + set = 0; + } + for (opt = JIT_F_OPT_FIRST; ; opt <<= 1) { + size_t len = *(const uint8_t *)lst; + if (len == 0) + break; + if (strncmp(str, lst+1, len) == 0 && str[len] == '\0') { + if (set) J->flags |= opt; else J->flags &= ~opt; + return 1; /* Ok. */ + } + lst += 1+len; + } + return 0; /* No match. */ +} + +/* Parse optimization parameter. */ +static int jitopt_param(jit_State *J, const char *str) +{ + const char *lst = JIT_P_STRING; + int i; + for (i = 0; i < JIT_P__MAX; i++) { + size_t len = *(const uint8_t *)lst; + lua_assert(len != 0); + if (strncmp(str, lst+1, len) == 0 && str[len] == '=') { + int32_t n = 0; + const char *p = &str[len+1]; + while (*p >= '0' && *p <= '9') + n = n*10 + (*p++ - '0'); + if (*p) return 0; /* Malformed number. */ + J->param[i] = n; + if (i == JIT_P_hotloop) + lj_dispatch_init_hotcount(J2G(J)); + return 1; /* Ok. */ + } + lst += 1+len; + } + return 0; /* No match. */ +} + +/* jit.opt.start(flags...) */ +LJLIB_CF(jit_opt_start) +{ + jit_State *J = L2J(L); + int nargs = (int)(L->top - L->base); + if (nargs == 0) { + J->flags = (J->flags & ~JIT_F_OPT_MASK) | JIT_F_OPT_DEFAULT; + } else { + int i; + for (i = 1; i <= nargs; i++) { + const char *str = strdata(lj_lib_checkstr(L, i)); + if (!jitopt_level(J, str) && + !jitopt_flag(J, str) && + !jitopt_param(J, str)) + lj_err_callerv(L, LJ_ERR_JITOPT, str); + } + } + return 0; +} + +#include "lj_libdef.h" + +#endif + +/* -- JIT compiler initialization ----------------------------------------- */ + +#if LJ_HASJIT +/* Default values for JIT parameters. */ +static const int32_t jit_param_default[JIT_P__MAX+1] = { +#define JIT_PARAMINIT(len, name, value) (value), +JIT_PARAMDEF(JIT_PARAMINIT) +#undef JIT_PARAMINIT + 0 +}; +#endif + +#if LJ_TARGET_ARM && LJ_TARGET_LINUX +#include +#endif + +/* Arch-dependent CPU detection. */ +static uint32_t jit_cpudetect(lua_State *L) +{ + uint32_t flags = 0; +#if LJ_TARGET_X86ORX64 + uint32_t vendor[4]; + uint32_t features[4]; + if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { +#if !LJ_HASJIT +#define JIT_F_CMOV 1 +#define JIT_F_SSE2 2 +#endif + flags |= ((features[3] >> 15)&1) * JIT_F_CMOV; + flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; +#if LJ_HASJIT + flags |= ((features[2] >> 0)&1) * JIT_F_SSE3; + flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; + if (vendor[2] == 0x6c65746e) { /* Intel. */ + if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */ + flags |= JIT_F_P4; /* Currently unused. */ + else if ((features[0] & 0x0fff0ff0) == 0x000106c0) /* Atom. */ + flags |= JIT_F_LEA_AGU; + } else if (vendor[2] == 0x444d4163) { /* AMD. */ + uint32_t fam = (features[0] & 0x0ff00f00); + if (fam == 0x00000f00) /* K8. */ + flags |= JIT_F_SPLIT_XMM; + if (fam >= 0x00000f00) /* K8, K10. */ + flags |= JIT_F_PREFER_IMUL; + } +#endif + } + /* Check for required instruction set support on x86 (unnecessary on x64). */ +#if LJ_TARGET_X86 +#if !defined(LUAJIT_CPU_NOCMOV) + if (!(flags & JIT_F_CMOV)) + luaL_error(L, "CPU not supported"); +#endif +#if defined(LUAJIT_CPU_SSE2) + if (!(flags & JIT_F_SSE2)) + luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); +#endif +#endif +#elif LJ_TARGET_ARM +#if LJ_HASJIT + int ver = LJ_ARCH_VERSION; /* Compile-time ARM CPU detection. */ +#if LJ_TARGET_LINUX + if (ver < 70) { /* Runtime ARM CPU detection. */ + struct utsname ut; + uname(&ut); + if (strncmp(ut.machine, "armv", 4) == 0) { + if (ut.machine[4] >= '7') + ver = 70; + else if (ut.machine[4] == '6') + ver = 60; + } + } +#endif + flags |= ver >= 70 ? JIT_F_ARMV7 : + ver >= 61 ? JIT_F_ARMV6T2_ : + ver >= 60 ? JIT_F_ARMV6_ : 0; + flags |= LJ_ARCH_HASFPU == 0 ? 0 : ver >= 70 ? JIT_F_VFPV3 : JIT_F_VFPV2; +#endif +#elif LJ_TARGET_PPC +#if LJ_HASJIT +#if LJ_ARCH_SQRT + flags |= JIT_F_SQRT; +#endif +#if LJ_ARCH_ROUND + flags |= JIT_F_ROUND; +#endif +#endif +#elif LJ_TARGET_PPCSPE + /* Nothing to do. */ +#elif LJ_TARGET_MIPS +#if LJ_HASJIT + /* Compile-time MIPS CPU detection. */ +#if LJ_ARCH_VERSION >= 20 + flags |= JIT_F_MIPS32R2; +#endif + /* Runtime MIPS CPU detection. */ +#if defined(__GNUC__) + if (!(flags & JIT_F_MIPS32R2)) { + int x; + /* On MIPS32R1 rotr is treated as srl. rotr r2,r2,1 -> srl r2,r2,1. */ + __asm__("li $2, 1\n\t.long 0x00221042\n\tmove %0, $2" : "=r"(x) : : "$2"); + if (x) flags |= JIT_F_MIPS32R2; /* Either 0x80000000 (R2) or 0 (R1). */ + } +#endif +#endif +#else +#error "Missing CPU detection for this architecture" +#endif + UNUSED(L); + return flags; +} + +/* Initialize JIT compiler. */ +static void jit_init(lua_State *L) +{ + uint32_t flags = jit_cpudetect(L); +#if LJ_HASJIT + jit_State *J = L2J(L); +#if LJ_TARGET_X86 + /* Silently turn off the JIT compiler on CPUs without SSE2. */ + if ((flags & JIT_F_SSE2)) +#endif + J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; + memcpy(J->param, jit_param_default, sizeof(J->param)); + lj_dispatch_update(G(L)); +#else + UNUSED(flags); +#endif +} + +LUALIB_API int luaopen_jit(lua_State *L) +{ + lua_pushliteral(L, LJ_OS_NAME); + lua_pushliteral(L, LJ_ARCH_NAME); + lua_pushinteger(L, LUAJIT_VERSION_NUM); + lua_pushliteral(L, LUAJIT_VERSION); + LJ_LIB_REG(L, LUA_JITLIBNAME, jit); +#ifndef LUAJIT_DISABLE_JITUTIL + LJ_LIB_REG(L, "jit.util", jit_util); +#endif +#if LJ_HASJIT + LJ_LIB_REG(L, "jit.opt", jit_opt); +#endif + L->top -= 2; + jit_init(L); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_math.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_math.c new file mode 100644 index 0000000..3aa5c6b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_math.c @@ -0,0 +1,233 @@ +/* +** Math library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lib_math_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_lib.h" +#include "lj_vm.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_math + +LJLIB_ASM(math_abs) LJLIB_REC(.) +{ + lj_lib_checknumber(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(math_floor) LJLIB_REC(math_round IRFPM_FLOOR) +LJLIB_ASM_(math_ceil) LJLIB_REC(math_round IRFPM_CEIL) + +LJLIB_ASM(math_sqrt) LJLIB_REC(math_unary IRFPM_SQRT) +{ + lj_lib_checknum(L, 1); + return FFH_RETRY; +} +LJLIB_ASM_(math_log10) LJLIB_REC(math_unary IRFPM_LOG10) +LJLIB_ASM_(math_exp) LJLIB_REC(math_unary IRFPM_EXP) +LJLIB_ASM_(math_sin) LJLIB_REC(math_unary IRFPM_SIN) +LJLIB_ASM_(math_cos) LJLIB_REC(math_unary IRFPM_COS) +LJLIB_ASM_(math_tan) LJLIB_REC(math_unary IRFPM_TAN) +LJLIB_ASM_(math_asin) LJLIB_REC(math_atrig FF_math_asin) +LJLIB_ASM_(math_acos) LJLIB_REC(math_atrig FF_math_acos) +LJLIB_ASM_(math_atan) LJLIB_REC(math_atrig FF_math_atan) +LJLIB_ASM_(math_sinh) LJLIB_REC(math_htrig IRCALL_sinh) +LJLIB_ASM_(math_cosh) LJLIB_REC(math_htrig IRCALL_cosh) +LJLIB_ASM_(math_tanh) LJLIB_REC(math_htrig IRCALL_tanh) +LJLIB_ASM_(math_frexp) +LJLIB_ASM_(math_modf) LJLIB_REC(.) + +LJLIB_PUSH(57.29577951308232) +LJLIB_ASM_(math_deg) LJLIB_REC(math_degrad) + +LJLIB_PUSH(0.017453292519943295) +LJLIB_ASM_(math_rad) LJLIB_REC(math_degrad) + +LJLIB_ASM(math_log) LJLIB_REC(math_log) +{ + double x = lj_lib_checknum(L, 1); + if (L->base+1 < L->top) { + double y = lj_lib_checknum(L, 2); +#ifdef LUAJIT_NO_LOG2 + x = log(x); y = 1.0 / log(y); +#else + x = lj_vm_log2(x); y = 1.0 / lj_vm_log2(y); +#endif + setnumV(L->base-1, x*y); /* Do NOT join the expression to x / y. */ + return FFH_RES(1); + } + return FFH_RETRY; +} + +LJLIB_ASM(math_atan2) LJLIB_REC(.) +{ + lj_lib_checknum(L, 1); + lj_lib_checknum(L, 2); + return FFH_RETRY; +} +LJLIB_ASM_(math_pow) LJLIB_REC(.) +LJLIB_ASM_(math_fmod) + +LJLIB_ASM(math_ldexp) LJLIB_REC(.) +{ + lj_lib_checknum(L, 1); +#if LJ_DUALNUM && !LJ_TARGET_X86ORX64 + lj_lib_checkint(L, 2); +#else + lj_lib_checknum(L, 2); +#endif + return FFH_RETRY; +} + +LJLIB_ASM(math_min) LJLIB_REC(math_minmax IR_MIN) +{ + int i = 0; + do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top); + return FFH_RETRY; +} +LJLIB_ASM_(math_max) LJLIB_REC(math_minmax IR_MAX) + +LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) +LJLIB_PUSH(1e310) LJLIB_SET(huge) + +/* ------------------------------------------------------------------------ */ + +/* This implements a Tausworthe PRNG with period 2^223. Based on: +** Tables of maximally-equidistributed combined LFSR generators, +** Pierre L'Ecuyer, 1991, table 3, 1st entry. +** Full-period ME-CF generator with L=64, J=4, k=223, N1=49. +*/ + +/* PRNG state. */ +struct RandomState { + uint64_t gen[4]; /* State of the 4 LFSR generators. */ + int valid; /* State is valid. */ +}; + +/* Union needed for bit-pattern conversion between uint64_t and double. */ +typedef union { uint64_t u64; double d; } U64double; + +/* Update generator i and compute a running xor of all states. */ +#define TW223_GEN(i, k, q, s) \ + z = rs->gen[i]; \ + z = (((z<> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<gen[i] = z; + +/* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */ +LJ_NOINLINE uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs) +{ + uint64_t z, r = 0; + TW223_GEN(0, 63, 31, 18) + TW223_GEN(1, 58, 19, 28) + TW223_GEN(2, 55, 24, 7) + TW223_GEN(3, 47, 21, 8) + return (r & U64x(000fffff,ffffffff)) | U64x(3ff00000,00000000); +} + +/* PRNG initialization function. */ +static void random_init(RandomState *rs, double d) +{ + uint32_t r = 0x11090601; /* 64-k[i] as four 8 bit constants. */ + int i; + for (i = 0; i < 4; i++) { + U64double u; + uint32_t m = 1u << (r&255); + r >>= 8; + u.d = d = d * 3.14159265358979323846 + 2.7182818284590452354; + if (u.u64 < m) u.u64 += m; /* Ensure k[i] MSB of gen[i] are non-zero. */ + rs->gen[i] = u.u64; + } + rs->valid = 1; + for (i = 0; i < 10; i++) + lj_math_random_step(rs); +} + +/* PRNG extract function. */ +LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */ +LJLIB_CF(math_random) LJLIB_REC(.) +{ + int n = (int)(L->top - L->base); + RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); + U64double u; + double d; + if (LJ_UNLIKELY(!rs->valid)) random_init(rs, 0.0); + u.u64 = lj_math_random_step(rs); + d = u.d - 1.0; + if (n > 0) { +#if LJ_DUALNUM + int isint = 1; + double r1; + lj_lib_checknumber(L, 1); + if (tvisint(L->base)) { + r1 = (lua_Number)intV(L->base); + } else { + isint = 0; + r1 = numV(L->base); + } +#else + double r1 = lj_lib_checknum(L, 1); +#endif + if (n == 1) { + d = lj_vm_floor(d*r1) + 1.0; /* d is an int in range [1, r1] */ + } else { +#if LJ_DUALNUM + double r2; + lj_lib_checknumber(L, 2); + if (tvisint(L->base+1)) { + r2 = (lua_Number)intV(L->base+1); + } else { + isint = 0; + r2 = numV(L->base+1); + } +#else + double r2 = lj_lib_checknum(L, 2); +#endif + d = lj_vm_floor(d*(r2-r1+1.0)) + r1; /* d is an int in range [r1, r2] */ + } +#if LJ_DUALNUM + if (isint) { + setintV(L->top-1, lj_num2int(d)); + return 1; + } +#endif + } /* else: d is a double in range [0, 1] */ + setnumV(L->top++, d); + return 1; +} + +/* PRNG seed function. */ +LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */ +LJLIB_CF(math_randomseed) +{ + RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); + random_init(rs, lj_lib_checknum(L, 1)); + return 0; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_math(lua_State *L) +{ + RandomState *rs; + rs = (RandomState *)lua_newuserdata(L, sizeof(RandomState)); + rs->valid = 0; /* Use lazy initialization to save some time on startup. */ + LJ_LIB_REG(L, LUA_MATHLIBNAME, math); +#if defined(LUA_COMPAT_MOD) && !LJ_52 + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_os.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_os.c new file mode 100644 index 0000000..f62e8c8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_os.c @@ -0,0 +1,280 @@ +/* +** OS library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define lib_os_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_lib.h" + +#if LJ_TARGET_POSIX +#include +#else +#include +#endif + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_os + +LJLIB_CF(os_execute) +{ +#if LJ_TARGET_CONSOLE +#if LJ_52 + errno = ENOSYS; + return luaL_fileresult(L, 0, NULL); +#else + lua_pushinteger(L, -1); + return 1; +#endif +#else + const char *cmd = luaL_optstring(L, 1, NULL); + int stat = system(cmd); +#if LJ_52 + if (cmd) + return luaL_execresult(L, stat); + setboolV(L->top++, 1); +#else + setintV(L->top++, stat); +#endif + return 1; +#endif +} + +LJLIB_CF(os_remove) +{ + const char *filename = luaL_checkstring(L, 1); + return luaL_fileresult(L, remove(filename) == 0, filename); +} + +LJLIB_CF(os_rename) +{ + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return luaL_fileresult(L, rename(fromname, toname) == 0, fromname); +} + +LJLIB_CF(os_tmpname) +{ +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 + lj_err_caller(L, LJ_ERR_OSUNIQF); + return 0; +#else +#if LJ_TARGET_POSIX + char buf[15+1]; + int fp; + strcpy(buf, "/tmp/lua_XXXXXX"); + fp = mkstemp(buf); + if (fp != -1) + close(fp); + else + lj_err_caller(L, LJ_ERR_OSUNIQF); +#else + char buf[L_tmpnam]; + if (tmpnam(buf) == NULL) + lj_err_caller(L, LJ_ERR_OSUNIQF); +#endif + lua_pushstring(L, buf); + return 1; +#endif +} + +LJLIB_CF(os_getenv) +{ +#if LJ_TARGET_CONSOLE + lua_pushnil(L); +#else + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ +#endif + return 1; +} + +LJLIB_CF(os_exit) +{ + int status; + if (L->base < L->top && tvisbool(L->base)) + status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE; + else + status = lj_lib_optint(L, 1, EXIT_SUCCESS); + if (L->base+1 < L->top && tvistruecond(L->base+1)) + lua_close(L); + exit(status); + return 0; /* Unreachable. */ +} + +LJLIB_CF(os_clock) +{ + setnumV(L->top++, ((lua_Number)clock())*(1.0/(lua_Number)CLOCKS_PER_SEC)); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void setfield(lua_State *L, const char *key, int value) +{ + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield(lua_State *L, const char *key, int value) +{ + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield(lua_State *L, const char *key) +{ + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + +static int getfield(lua_State *L, const char *key, int d) +{ + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) { + res = (int)lua_tointeger(L, -1); + } else { + if (d < 0) + lj_err_callerv(L, LJ_ERR_OSDATEF, key); + res = d; + } + lua_pop(L, 1); + return res; +} + +LJLIB_CF(os_date) +{ + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; +#if LJ_TARGET_POSIX + struct tm rtm; +#endif + if (*s == '!') { /* UTC? */ + s++; /* Skip '!' */ +#if LJ_TARGET_POSIX + stm = gmtime_r(&t, &rtm); +#else + stm = gmtime(&t); +#endif + } else { +#if LJ_TARGET_POSIX + stm = localtime_r(&t, &rtm); +#else + stm = localtime(&t); +#endif + } + if (stm == NULL) { /* Invalid date? */ + setnilV(L->top-1); + } else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') { /* No conversion specifier? */ + luaL_addchar(&b, *s); + } else { + size_t reslen; + char buff[200]; /* Should be big enough for any conversion result. */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + +LJLIB_CF(os_time) +{ + time_t t; + if (lua_isnoneornil(L, 1)) { /* called without args? */ + t = time(NULL); /* get current time */ + } else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + +LJLIB_CF(os_difftime) +{ + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, (lua_Number)0)))); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +LJLIB_CF(os_setlocale) +{ + GCstr *s = lj_lib_optstr(L, 1); + const char *str = s ? strdata(s) : NULL; + int opt = lj_lib_checkopt(L, 2, 6, + "\5ctype\7numeric\4time\7collate\10monetary\1\377\3all"); + if (opt == 0) opt = LC_CTYPE; + else if (opt == 1) opt = LC_NUMERIC; + else if (opt == 2) opt = LC_TIME; + else if (opt == 3) opt = LC_COLLATE; + else if (opt == 4) opt = LC_MONETARY; + else if (opt == 6) opt = LC_ALL; + lua_pushstring(L, setlocale(opt, str)); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_os(lua_State *L) +{ + LJ_LIB_REG(L, LUA_OSLIBNAME, os); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_package.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_package.c new file mode 100644 index 0000000..e341039 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_package.c @@ -0,0 +1,602 @@ +/* +** Package library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lib_package_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +/* Error codes for ll_loadfunc. */ +#define PACKAGE_ERR_LIB 1 +#define PACKAGE_ERR_FUNC 2 +#define PACKAGE_ERR_LOAD 3 + +/* Redefined in platform specific part. */ +#define PACKAGE_LIB_FAIL "open" +#define setprogdir(L) ((void)0) + +/* Symbol name prefixes. */ +#define SYMPREFIX_CF "luaopen_%s" +#define SYMPREFIX_BC "luaJIT_BC_%s" + +#if LJ_TARGET_DLOPEN + +#include + +static void ll_unloadlib(void *lib) +{ + dlclose(lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL)); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ +#if defined(RTLD_DEFAULT) + if (lib == NULL) lib = RTLD_DEFAULT; +#elif LJ_TARGET_OSX || LJ_TARGET_BSD + if (lib == NULL) lib = (void *)(intptr_t)-2; +#endif + return (const char *)dlsym(lib, sym); +} + +#elif LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4 +#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2 +BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*); +#endif + +#undef setprogdir + +static void setprogdir(lua_State *L) +{ + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) { + luaL_error(L, "unable to get ModuleFileName"); + } else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + +static void pusherror(lua_State *L) +{ + DWORD error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib(void *lib) +{ + FreeLibrary((HINSTANCE)lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + UNUSED(gl); + return lib; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ + if (lib) { + return (const char *)GetProcAddress((HINSTANCE)lib, sym); + } else { + HINSTANCE h = GetModuleHandleA(NULL); + const char *p = (const char *)GetProcAddress(h, sym); + if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)ll_bcsym, &h)) + p = (const char *)GetProcAddress(h, sym); + return p; + } +} + +#else + +#undef PACKAGE_LIB_FAIL +#define PACKAGE_LIB_FAIL "absent" + +#define DLMSG "dynamic libraries not enabled; no support for target OS" + +static void ll_unloadlib(void *lib) +{ + UNUSED(lib); +} + +static void *ll_load(lua_State *L, const char *path, int gl) +{ + UNUSED(path); UNUSED(gl); + lua_pushliteral(L, DLMSG); + return NULL; +} + +static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) +{ + UNUSED(lib); UNUSED(sym); + lua_pushliteral(L, DLMSG); + return NULL; +} + +static const char *ll_bcsym(void *lib, const char *sym) +{ + UNUSED(lib); UNUSED(sym); + return NULL; +} + +#endif + +/* ------------------------------------------------------------------------ */ + +static void **ll_register(lua_State *L, const char *path) +{ + void **plib; + lua_pushfstring(L, "LOADLIB: %s", path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) { /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + } else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "LOADLIB: %s", path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + +static const char *mksymname(lua_State *L, const char *modname, + const char *prefix) +{ + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", "_"); + funcname = lua_pushfstring(L, prefix, funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + +static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) +{ + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path, (*name == '*')); + if (*reg == NULL) { + return PACKAGE_ERR_LIB; /* Unable to load library. */ + } else if (*name == '*') { /* Only load library into global namespace. */ + lua_pushboolean(L, 1); + return 0; + } else { + const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF); + lua_CFunction f = ll_sym(L, *reg, sym); + if (f) { + lua_pushcfunction(L, f); + return 0; + } + if (!r) { + const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); + lua_pop(L, 1); + if (bcdata) { + if (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) + return PACKAGE_ERR_LOAD; + return 0; + } + } + return PACKAGE_ERR_FUNC; /* Unable to find function. */ + } +} + +static int lj_cf_package_loadlib(lua_State *L) +{ + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int st = ll_loadfunc(L, path, init, 1); + if (st == 0) { /* no errors? */ + return 1; /* return the loaded function */ + } else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (st == PACKAGE_ERR_LIB) ? PACKAGE_LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + +static int lj_cf_package_unloadlib(lua_State *L) +{ + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int readable(const char *filename) +{ + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + +static const char *pushnexttemplate(lua_State *L, const char *path) +{ + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, (size_t)(l - path)); /* template */ + return l; +} + +static const char *searchpath (lua_State *L, const char *name, + const char *path, const char *sep, + const char *dirsep) +{ + luaL_Buffer msg; /* to build error message */ + luaL_buffinit(L, &msg); + if (*sep != '\0') /* non-empty separator? */ + name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename = luaL_gsub(L, lua_tostring(L, -1), + LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + luaL_addvalue(&msg); /* concatenate error msg. entry */ + } + luaL_pushresult(&msg); /* create error message */ + return NULL; /* not found */ +} + +static int lj_cf_package_searchpath(lua_State *L) +{ + const char *f = searchpath(L, luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_optstring(L, 3, "."), + luaL_optstring(L, 4, LUA_DIRSEP)); + if (f != NULL) { + return 1; + } else { /* error message is on top of the stack */ + lua_pushnil(L); + lua_insert(L, -2); + return 2; /* return nil + error message */ + } +} + +static const char *findfile(lua_State *L, const char *name, + const char *pname) +{ + const char *path; + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + return searchpath(L, name, path, ".", LUA_DIRSEP); +} + +static void loaderror(lua_State *L, const char *filename) +{ + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + +static int lj_cf_package_loader_lua(lua_State *L) +{ + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + +static int lj_cf_package_loader_c(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + if (ll_loadfunc(L, filename, name, 0) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + +static int lj_cf_package_loader_croot(lua_State *L) +{ + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int st; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, (size_t)(p - name)); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + if ((st = ll_loadfunc(L, filename, name, 0)) != 0) { + if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + +static int lj_cf_package_loader_preload(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) { /* Not found? */ + const char *bcname = mksymname(L, name, SYMPREFIX_BC); + const char *bcdata = ll_bcsym(NULL, bcname); + if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + } + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + +static int lj_cf_package_require(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i = 1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + lj_lib_checkfpu(L); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void setfenv(lua_State *L) +{ + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + +static void dooptions(lua_State *L, int n) +{ + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + +static void modinit(lua_State *L, const char *modname) +{ + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, (size_t)(dot - modname)); + lua_setfield(L, -2, "_PACKAGE"); +} + +static int lj_cf_package_module(lua_State *L) +{ + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) { /* is table an initialized module? */ + lua_pop(L, 1); + } else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + +static int lj_cf_package_seeall(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + +/* ------------------------------------------------------------------------ */ + +#define AUXMARK "\1" + +static void setpath(lua_State *L, const char *fieldname, const char *envname, + const char *def, int noenv) +{ +#if LJ_TARGET_CONSOLE + const char *path = NULL; + UNUSED(envname); +#else + const char *path = getenv(envname); +#endif + if (path == NULL || noenv) { + lua_pushstring(L, def); + } else { + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + +static const luaL_Reg package_lib[] = { + { "loadlib", lj_cf_package_loadlib }, + { "searchpath", lj_cf_package_searchpath }, + { "seeall", lj_cf_package_seeall }, + { NULL, NULL } +}; + +static const luaL_Reg package_global[] = { + { "module", lj_cf_package_module }, + { "require", lj_cf_package_require }, + { NULL, NULL } +}; + +static const lua_CFunction package_loaders[] = +{ + lj_cf_package_loader_preload, + lj_cf_package_loader_lua, + lj_cf_package_loader_c, + lj_cf_package_loader_croot, + NULL +}; + +LUALIB_API int luaopen_package(lua_State *L) +{ + int i; + int noenv; + luaL_newmetatable(L, "_LOADLIB"); + lj_lib_pushcf(L, lj_cf_package_unloadlib, 1); + lua_setfield(L, -2, "__gc"); + luaL_register(L, LUA_LOADLIBNAME, package_lib); + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0); + for (i = 0; package_loaders[i] != NULL; i++) { + lj_lib_pushcf(L, package_loaders[i], 1); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); + noenv = lua_toboolean(L, -1); + lua_pop(L, 1); + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv); + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv); + lua_pushliteral(L, LUA_PATH_CONFIG); + lua_setfield(L, -2, "config"); + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_setfield(L, -2, "loaded"); + luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, package_global); + lua_pop(L, 1); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_string.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_string.c new file mode 100644 index 0000000..9ec6d0c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lib_string.c @@ -0,0 +1,940 @@ +/* +** String library. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lib_string_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_ff.h" +#include "lj_bcdump.h" +#include "lj_char.h" +#include "lj_lib.h" + +/* ------------------------------------------------------------------------ */ + +#define LJLIB_MODULE_string + +LJLIB_ASM(string_len) LJLIB_REC(.) +{ + lj_lib_checkstr(L, 1); + return FFH_RETRY; +} + +LJLIB_ASM(string_byte) LJLIB_REC(string_range 0) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int32_t len = (int32_t)s->len; + int32_t start = lj_lib_optint(L, 2, 1); + int32_t stop = lj_lib_optint(L, 3, start); + int32_t n, i; + const unsigned char *p; + if (stop < 0) stop += len+1; + if (start < 0) start += len+1; + if (start <= 0) start = 1; + if (stop > len) stop = len; + if (start > stop) return FFH_RES(0); /* Empty interval: return no results. */ + start--; + n = stop - start; + if ((uint32_t)n > LUAI_MAXCSTACK) + lj_err_caller(L, LJ_ERR_STRSLC); + lj_state_checkstack(L, (MSize)n); + p = (const unsigned char *)strdata(s) + start; + for (i = 0; i < n; i++) + setintV(L->base + i-1, p[i]); + return FFH_RES(n); +} + +LJLIB_ASM(string_char) +{ + int i, nargs = (int)(L->top - L->base); + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, (MSize)nargs); + for (i = 1; i <= nargs; i++) { + int32_t k = lj_lib_checkint(L, i); + if (!checku8(k)) + lj_err_arg(L, i, LJ_ERR_BADVAL); + buf[i-1] = (char)k; + } + setstrV(L, L->base-1, lj_str_new(L, buf, (size_t)nargs)); + return FFH_RES(1); +} + +LJLIB_ASM(string_sub) LJLIB_REC(string_range 1) +{ + lj_lib_checkstr(L, 1); + lj_lib_checkint(L, 2); + setintV(L->base+2, lj_lib_optint(L, 3, -1)); + return FFH_RETRY; +} + +LJLIB_ASM(string_rep) +{ + GCstr *s = lj_lib_checkstr(L, 1); + int32_t k = lj_lib_checkint(L, 2); + GCstr *sep = lj_lib_optstr(L, 3); + int32_t len = (int32_t)s->len; + global_State *g = G(L); + int64_t tlen; + const char *src; + char *buf; + if (k <= 0) { + empty: + setstrV(L, L->base-1, &g->strempty); + return FFH_RES(1); + } + if (sep) { + tlen = (int64_t)len + sep->len; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + tlen *= k; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + } else { + tlen = (int64_t)k * len; + if (tlen > LJ_MAX_STR) + lj_err_caller(L, LJ_ERR_STROV); + } + if (tlen == 0) goto empty; + buf = lj_str_needbuf(L, &g->tmpbuf, (MSize)tlen); + src = strdata(s); + if (sep) { + tlen -= sep->len; /* Ignore trailing separator. */ + if (k > 1) { /* Paste one string and one separator. */ + int32_t i; + i = 0; while (i < len) *buf++ = src[i++]; + src = strdata(sep); len = sep->len; + i = 0; while (i < len) *buf++ = src[i++]; + src = g->tmpbuf.buf; len += s->len; k--; /* Now copy that k-1 times. */ + } + } + do { + int32_t i = 0; + do { *buf++ = src[i++]; } while (i < len); + } while (--k > 0); + setstrV(L, L->base-1, lj_str_new(L, g->tmpbuf.buf, (size_t)tlen)); + return FFH_RES(1); +} + +LJLIB_ASM(string_reverse) +{ + GCstr *s = lj_lib_checkstr(L, 1); + lj_str_needbuf(L, &G(L)->tmpbuf, s->len); + return FFH_RETRY; +} +LJLIB_ASM_(string_lower) +LJLIB_ASM_(string_upper) + +/* ------------------------------------------------------------------------ */ + +static int writer_buf(lua_State *L, const void *p, size_t size, void *b) +{ + luaL_addlstring((luaL_Buffer *)b, (const char *)p, size); + UNUSED(L); + return 0; +} + +LJLIB_CF(string_dump) +{ + GCfunc *fn = lj_lib_checkfunc(L, 1); + int strip = L->base+1 < L->top && tvistruecond(L->base+1); + luaL_Buffer b; + L->top = L->base+1; + luaL_buffinit(L, &b); + if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, &b, strip)) + lj_err_caller(L, LJ_ERR_STRDUMP); + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + +#define CAP_UNFINISHED (-1) +#define CAP_POSITION (-2) + +typedef struct MatchState { + const char *src_init; /* init of source string */ + const char *src_end; /* end (`\0') of source string */ + lua_State *L; + int level; /* total number of captures (finished or unfinished) */ + int depth; + struct { + const char *init; + ptrdiff_t len; + } capture[LUA_MAXCAPTURES]; +} MatchState; + +#define L_ESC '%' +#define SPECIALS "^$*+?.([%-" + +static int check_capture(MatchState *ms, int l) +{ + l -= '1'; + if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) + lj_err_caller(ms->L, LJ_ERR_STRCAPI); + return l; +} + +static int capture_to_close(MatchState *ms) +{ + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + lj_err_caller(ms->L, LJ_ERR_STRPATC); + return 0; /* unreachable */ +} + +static const char *classend(MatchState *ms, const char *p) +{ + switch (*p++) { + case L_ESC: + if (*p == '\0') + lj_err_caller(ms->L, LJ_ERR_STRPATE); + return p+1; + case '[': + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + lj_err_caller(ms->L, LJ_ERR_STRPATM); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + default: + return p; + } +} + +static const unsigned char match_class_map[32] = { + 0,LJ_CHAR_ALPHA,0,LJ_CHAR_CNTRL,LJ_CHAR_DIGIT,0,0,LJ_CHAR_GRAPH,0,0,0,0, + LJ_CHAR_LOWER,0,0,0,LJ_CHAR_PUNCT,0,0,LJ_CHAR_SPACE,0, + LJ_CHAR_UPPER,0,LJ_CHAR_ALNUM,LJ_CHAR_XDIGIT,0,0,0,0,0,0,0 +}; + +static int match_class(int c, int cl) +{ + if ((cl & 0xc0) == 0x40) { + int t = match_class_map[(cl&0x1f)]; + if (t) { + t = lj_char_isa(c, t); + return (cl & 0x20) ? t : !t; + } + if (cl == 'z') return c == 0; + if (cl == 'Z') return c != 0; + } + return (cl == c); +} + +static int matchbracketclass(int c, const char *p, const char *ec) +{ + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + +static int singlematch(int c, const char *p, const char *ep) +{ + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + +static const char *match(MatchState *ms, const char *s, const char *p); + +static const char *matchbalance(MatchState *ms, const char *s, const char *p) +{ + if (*p == 0 || *(p+1) == 0) + lj_err_caller(ms->L, LJ_ERR_STRPATU); + if (*s != *p) { + return NULL; + } else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } else if (*s == b) { + cont++; + } + } + } + return NULL; /* string ends out of balance */ +} + +static const char *max_expand(MatchState *ms, const char *s, + const char *p, const char *ep) +{ + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + +static const char *min_expand(MatchState *ms, const char *s, + const char *p, const char *ep) +{ + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else + return NULL; + } +} + +static const char *start_capture(MatchState *ms, const char *s, + const char *p, int what) +{ + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) lj_err_caller(ms->L, LJ_ERR_STRCAPN); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + +static const char *end_capture(MatchState *ms, const char *s, + const char *p) +{ + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + +static const char *match_capture(MatchState *ms, const char *s, int l) +{ + size_t len; + l = check_capture(ms, l); + len = (size_t)ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else + return NULL; +} + +static const char *match(MatchState *ms, const char *s, const char *p) +{ + if (++ms->depth > LJ_MAX_XLEVEL) + lj_err_caller(ms->L, LJ_ERR_STRPATX); + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': /* start capture */ + if (*(p+1) == ')') /* position capture? */ + s = start_capture(ms, s, p+2, CAP_POSITION); + else + s = start_capture(ms, s, p+1, CAP_UNFINISHED); + break; + case ')': /* end capture */ + s = end_capture(ms, s, p+1); + break; + case L_ESC: + switch (*(p+1)) { + case 'b': /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) break; + p+=4; + goto init; /* else s = match(ms, s, p+4); */ + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + lj_err_caller(ms->L, LJ_ERR_STRPATB); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) { s = NULL; break; } + p=ep; + goto init; /* else s = match(ms, s, ep); */ + } + default: + if (lj_char_isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) break; + p+=2; + goto init; /* else s = match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + break; + case '\0': /* end of pattern */ + break; /* match succeeded */ + case '$': + /* is the `$' the last char in pattern? */ + if (*(p+1) != '\0') goto dflt; + if (s != ms->src_end) s = NULL; /* check end of string */ + break; + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) { + s = res; + break; + } + p=ep+1; + goto init; /* else s = match(ms, s, ep+1); */ + } + case '*': /* 0 or more repetitions */ + s = max_expand(ms, s, p, ep); + break; + case '+': /* 1 or more repetitions */ + s = (m ? max_expand(ms, s+1, p, ep) : NULL); + break; + case '-': /* 0 or more repetitions (minimum) */ + s = min_expand(ms, s, p, ep); + break; + default: + if (m) { s++; p=ep; goto init; } /* else s = match(ms, s+1, ep); */ + s = NULL; + break; + } + break; + } + } + ms->depth--; + return s; +} + +static const char *lmemfind(const char *s1, size_t l1, + const char *s2, size_t l2) +{ + if (l2 == 0) { + return s1; /* empty strings are everywhere */ + } else if (l2 > l1) { + return NULL; /* avoids a negative `l1' */ + } else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) { + return init-1; + } else { /* correct `l1' and `s1' to try again */ + l1 -= (size_t)(init-s1); + s1 = init; + } + } + return NULL; /* not found */ + } +} + +static void push_onecapture(MatchState *ms, int i, const char *s, const char *e) +{ + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, (size_t)(e - s)); /* add whole match */ + else + lj_err_caller(ms->L, LJ_ERR_STRCAPI); + } else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) lj_err_caller(ms->L, LJ_ERR_STRCAPU); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, (size_t)l); + } +} + +static int push_captures(MatchState *ms, const char *s, const char *e) +{ + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + +static ptrdiff_t posrelat(ptrdiff_t pos, size_t len) +{ + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + +static int str_find_aux(lua_State *L, int find) +{ + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) { + init = 0; + } else if ((size_t)(init) > l1) { +#if LJ_52 + setnilV(L->top-1); + return 1; +#else + init = (ptrdiff_t)l1; +#endif + } + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-(size_t)init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+(ptrdiff_t)l2); + return 2; + } + } else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = ms.depth = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } else { + return push_captures(&ms, s1, res); + } + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + +LJLIB_CF(string_find) +{ + return str_find_aux(L, 1); +} + +LJLIB_CF(string_match) +{ + return str_find_aux(L, 0); +} + +LJLIB_NOREG LJLIB_CF(string_gmatch_aux) +{ + const char *p = strVdata(lj_lib_upvalue(L, 2)); + GCstr *str = strV(lj_lib_upvalue(L, 1)); + const char *s = strdata(str); + TValue *tvpos = lj_lib_upvalue(L, 3); + const char *src = s + tvpos->u32.lo; + MatchState ms; + ms.L = L; + ms.src_init = s; + ms.src_end = s + str->len; + for (; src <= ms.src_end; src++) { + const char *e; + ms.level = ms.depth = 0; + if ((e = match(&ms, src, p)) != NULL) { + int32_t pos = (int32_t)(e - s); + if (e == src) pos++; /* Ensure progress for empty match. */ + tvpos->u32.lo = (uint32_t)pos; + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + +LJLIB_CF(string_gmatch) +{ + lj_lib_checkstr(L, 1); + lj_lib_checkstr(L, 2); + L->top = L->base+3; + (L->top-1)->u64 = 0; + lj_lib_pushcc(L, lj_cf_string_gmatch_aux, FF_string_gmatch_aux, 3); + return 1; +} + +static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e) +{ + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) { + luaL_addchar(b, news[i]); + } else { + i++; /* skip ESC */ + if (!lj_char_isdigit(uchar(news[i]))) { + luaL_addchar(b, news[i]); + } else if (news[i] == '0') { + luaL_addlstring(b, s, (size_t)(e - s)); + } else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + +static void add_value(MatchState *ms, luaL_Buffer *b, + const char *s, const char *e) +{ + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, (size_t)(e - s)); /* keep original text */ + } else if (!lua_isstring(L, -1)) { + lj_err_callerv(L, LJ_ERR_STRGSRV, luaL_typename(L, -1)); + } + luaL_addvalue(b); /* add result to accumulator */ +} + +LJLIB_CF(string_gsub) +{ + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, (int)(srcl+1)); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + if (!(tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE)) + lj_err_arg(L, 3, LJ_ERR_NOSFT); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = ms.depth = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else + break; + if (anchor) + break; + } + luaL_addlstring(&b, src, (size_t)(ms.src_end-src)); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* ------------------------------------------------------------------------ */ + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_FMTITEM 512 +/* valid flags in a format specification */ +#define FMT_FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FMTSPEC (sizeof(FMT_FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + +static void addquoted(lua_State *L, luaL_Buffer *b, int arg) +{ + GCstr *str = lj_lib_checkstr(L, arg); + int32_t len = (int32_t)str->len; + const char *s = strdata(str); + luaL_addchar(b, '"'); + while (len--) { + uint32_t c = uchar(*s); + if (c == '"' || c == '\\' || c == '\n') { + luaL_addchar(b, '\\'); + } else if (lj_char_iscntrl(c)) { /* This can only be 0-31 or 127. */ + uint32_t d; + luaL_addchar(b, '\\'); + if (c >= 100 || lj_char_isdigit(uchar(s[1]))) { + luaL_addchar(b, '0'+(c >= 100)); if (c >= 100) c -= 100; + goto tens; + } else if (c >= 10) { + tens: + d = (c * 205) >> 11; c -= d * 10; luaL_addchar(b, '0'+d); + } + c += '0'; + } + luaL_addchar(b, c); + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat(lua_State *L, const char *strfrmt, char *form) +{ + const char *p = strfrmt; + while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS)) + lj_err_caller(L, LJ_ERR_STRFMTR); + if (lj_char_isdigit(uchar(*p))) p++; /* skip width */ + if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (lj_char_isdigit(uchar(*p))) p++; /* skip precision */ + if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (lj_char_isdigit(uchar(*p))) + lj_err_caller(L, LJ_ERR_STRFMTW); + *(form++) = '%'; + strncpy(form, strfrmt, (size_t)(p - strfrmt + 1)); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + +static void addintlen(char *form) +{ + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + +static unsigned LUA_INTFRM_T num2intfrm(lua_State *L, int arg) +{ + if (sizeof(LUA_INTFRM_T) == 4) { + return (LUA_INTFRM_T)lj_lib_checkbit(L, arg); + } else { + cTValue *o; + lj_lib_checknumber(L, arg); + o = L->base+arg-1; + if (tvisint(o)) + return (LUA_INTFRM_T)intV(o); + else + return (LUA_INTFRM_T)numV(o); + } +} + +static unsigned LUA_INTFRM_T num2uintfrm(lua_State *L, int arg) +{ + if (sizeof(LUA_INTFRM_T) == 4) { + return (unsigned LUA_INTFRM_T)lj_lib_checkbit(L, arg); + } else { + cTValue *o; + lj_lib_checknumber(L, arg); + o = L->base+arg-1; + if (tvisint(o)) + return (unsigned LUA_INTFRM_T)intV(o); + else if ((int32_t)o->u32.hi < 0) + return (unsigned LUA_INTFRM_T)(LUA_INTFRM_T)numV(o); + else + return (unsigned LUA_INTFRM_T)numV(o); + } +} + +static GCstr *meta_tostring(lua_State *L, int arg) +{ + TValue *o = L->base+arg-1; + cTValue *mo; + lua_assert(o < L->top); /* Caller already checks for existence. */ + if (LJ_LIKELY(tvisstr(o))) + return strV(o); + if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { + copyTV(L, L->top++, mo); + copyTV(L, L->top++, o); + lua_call(L, 1, 1); + L->top--; + if (tvisstr(L->top)) + return strV(L->top); + o = L->base+arg-1; + copyTV(L, o, L->top); + } + if (tvisnumber(o)) { + return lj_str_fromnumber(L, o); + } else if (tvisnil(o)) { + return lj_str_newlit(L, "nil"); + } else if (tvisfalse(o)) { + return lj_str_newlit(L, "false"); + } else if (tvistrue(o)) { + return lj_str_newlit(L, "true"); + } else { + if (tvisfunc(o) && isffunc(funcV(o))) + lj_str_pushf(L, "function: builtin#%d", funcV(o)->c.ffid); + else + lj_str_pushf(L, "%s: %p", lj_typename(o), lua_topointer(L, arg)); + L->top--; + return strV(L->top); + } +} + +LJLIB_CF(string_format) +{ + int arg = 1, top = (int)(L->top - L->base); + GCstr *fmt = lj_lib_checkstr(L, arg); + const char *strfrmt = strdata(fmt); + const char *strfrmt_end = strfrmt + fmt->len; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) { + luaL_addchar(&b, *strfrmt++); + } else if (*++strfrmt == L_ESC) { + luaL_addchar(&b, *strfrmt++); /* %% */ + } else { /* format item */ + char form[MAX_FMTSPEC]; /* to store the format (`%...') */ + char buff[MAX_FMTITEM]; /* to store the formatted item */ + if (++arg > top) + luaL_argerror(L, arg, lj_obj_typename[0]); + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': + sprintf(buff, form, lj_lib_checkint(L, arg)); + break; + case 'd': case 'i': + addintlen(form); + sprintf(buff, form, num2intfrm(L, arg)); + break; + case 'o': case 'u': case 'x': case 'X': + addintlen(form); + sprintf(buff, form, num2uintfrm(L, arg)); + break; + case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A': { + TValue tv; + tv.n = lj_lib_checknum(L, arg); + if (LJ_UNLIKELY((tv.u32.hi << 1) >= 0xffe00000)) { + /* Canonicalize output of non-finite values. */ + char *p, nbuf[LJ_STR_NUMBUF]; + size_t len = lj_str_bufnum(nbuf, &tv); + if (strfrmt[-1] < 'a') { + nbuf[len-3] = nbuf[len-3] - 0x20; + nbuf[len-2] = nbuf[len-2] - 0x20; + nbuf[len-1] = nbuf[len-1] - 0x20; + } + nbuf[len] = '\0'; + for (p = form; *p < 'A' && *p != '.'; p++) ; + *p++ = 's'; *p = '\0'; + sprintf(buff, form, nbuf); + break; + } + sprintf(buff, form, (double)tv.n); + break; + } + case 'q': + addquoted(L, &b, arg); + continue; + case 'p': + lj_str_pushf(L, "%p", lua_topointer(L, arg)); + luaL_addvalue(&b); + continue; + case 's': { + GCstr *str = meta_tostring(L, arg); + if (!strchr(form, '.') && str->len >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + setstrV(L, L->top++, str); + luaL_addvalue(&b); + continue; + } + sprintf(buff, form, strdata(str)); + break; + } + default: + lj_err_callerv(L, LJ_ERR_STRFMTO, *(strfrmt -1)); + break; + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_string(lua_State *L) +{ + GCtab *mt; + global_State *g; + LJ_LIB_REG(L, LUA_STRLIBNAME, string); +#if defined(LUA_COMPAT_GFIND) && !LJ_52 + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + mt = lj_tab_new(L, 0, 1); + /* NOBARRIER: basemt is a GC root. */ + g = G(L); + setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt)); + settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1)); + mt->nomm = (uint8_t)(~(1u<top, func); + setintV(L->top+1, i); + val = lj_tab_getint(t, (int32_t)i); + if (val) { copyTV(L, L->top+2, val); } else { setnilV(L->top+2); } + L->top += 3; + lua_call(L, 2, 1); + if (!tvisnil(L->top-1)) + return 1; + L->top--; + } + return 0; +} + +LJLIB_CF(table_foreach) +{ + GCtab *t = lj_lib_checktab(L, 1); + GCfunc *func = lj_lib_checkfunc(L, 2); + L->top = L->base+3; + setnilV(L->top-1); + while (lj_tab_next(L, t, L->top-1)) { + copyTV(L, L->top+2, L->top); + copyTV(L, L->top+1, L->top-1); + setfuncV(L, L->top, func); + L->top += 3; + lua_call(L, 2, 1); + if (!tvisnil(L->top-1)) + return 1; + L->top--; + } + return 0; +} + +LJLIB_ASM(table_getn) LJLIB_REC(.) +{ + lj_lib_checktab(L, 1); + return FFH_UNREACHABLE; +} + +LJLIB_CF(table_maxn) +{ + GCtab *t = lj_lib_checktab(L, 1); + TValue *array = tvref(t->array); + Node *node; + lua_Number m = 0; + ptrdiff_t i; + for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--) + if (!tvisnil(&array[i])) { + m = (lua_Number)(int32_t)i; + break; + } + node = noderef(t->node); + for (i = (ptrdiff_t)t->hmask; i >= 0; i--) + if (!tvisnil(&node[i].val) && tvisnumber(&node[i].key)) { + lua_Number n = numberVnum(&node[i].key); + if (n > m) m = n; + } + setnumV(L->top-1, m); + return 1; +} + +LJLIB_CF(table_insert) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t n, i = (int32_t)lj_tab_len(t) + 1; + int nargs = (int)((char *)L->top - (char *)L->base); + if (nargs != 2*sizeof(TValue)) { + if (nargs != 3*sizeof(TValue)) + lj_err_caller(L, LJ_ERR_TABINS); + /* NOBARRIER: This just moves existing elements around. */ + for (n = lj_lib_checkint(L, 2); i > n; i--) { + /* The set may invalidate the get pointer, so need to do it first! */ + TValue *dst = lj_tab_setint(L, t, i); + cTValue *src = lj_tab_getint(t, i-1); + if (src) { + copyTV(L, dst, src); + } else { + setnilV(dst); + } + } + i = n; + } + { + TValue *dst = lj_tab_setint(L, t, i); + copyTV(L, dst, L->top-1); /* Set new value. */ + lj_gc_barriert(L, t, dst); + } + return 0; +} + +LJLIB_CF(table_remove) LJLIB_REC(.) +{ + GCtab *t = lj_lib_checktab(L, 1); + int32_t e = (int32_t)lj_tab_len(t); + int32_t pos = lj_lib_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* Nothing to remove? */ + return 0; + lua_rawgeti(L, 1, pos); /* Get previous value. */ + /* NOBARRIER: This just moves existing elements around. */ + for (; pos < e; pos++) { + cTValue *src = lj_tab_getint(t, pos+1); + TValue *dst = lj_tab_setint(L, t, pos); + if (src) { + copyTV(L, dst, src); + } else { + setnilV(dst); + } + } + setnilV(lj_tab_setint(L, t, e)); /* Remove (last) value. */ + return 1; /* Return previous value. */ +} + +LJLIB_CF(table_concat) +{ + luaL_Buffer b; + GCtab *t = lj_lib_checktab(L, 1); + GCstr *sep = lj_lib_optstr(L, 2); + MSize seplen = sep ? sep->len : 0; + int32_t i = lj_lib_optint(L, 3, 1); + int32_t e = (L->base+3 < L->top && !tvisnil(L->base+3)) ? + lj_lib_checkint(L, 4) : (int32_t)lj_tab_len(t); + luaL_buffinit(L, &b); + if (i <= e) { + for (;;) { + cTValue *o; + lua_rawgeti(L, 1, i); + o = L->top-1; + if (!(tvisstr(o) || tvisnumber(o))) + lj_err_callerv(L, LJ_ERR_TABCAT, lj_typename(o), i); + luaL_addvalue(&b); + if (i++ == e) break; + if (seplen) + luaL_addlstring(&b, strdata(sep), seplen); + } + } + luaL_pushresult(&b); + return 1; +} + +/* ------------------------------------------------------------------------ */ + +static void set2(lua_State *L, int i, int j) +{ + lua_rawseti(L, 1, i); + lua_rawseti(L, 1, j); +} + +static int sort_comp(lua_State *L, int a, int b) +{ + if (!lua_isnil(L, 2)) { /* function? */ + int res; + lua_pushvalue(L, 2); + lua_pushvalue(L, a-1); /* -1 to compensate function */ + lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */ + lua_call(L, 2, 1); + res = lua_toboolean(L, -1); + lua_pop(L, 1); + return res; + } else { /* a < b? */ + return lua_lessthan(L, a, b); + } +} + +static void auxsort(lua_State *L, int l, int u) +{ + while (l < u) { /* for tail recursion */ + int i, j; + /* sort elements a[l], a[(l+u)/2] and a[u] */ + lua_rawgeti(L, 1, l); + lua_rawgeti(L, 1, u); + if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */ + set2(L, l, u); /* swap a[l] - a[u] */ + else + lua_pop(L, 2); + if (u-l == 1) break; /* only 2 elements */ + i = (l+u)/2; + lua_rawgeti(L, 1, i); + lua_rawgeti(L, 1, l); + if (sort_comp(L, -2, -1)) { /* a[i]= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>=u) lj_err_caller(L, LJ_ERR_TABSORT); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j<=l) lj_err_caller(L, LJ_ERR_TABSORT); + lua_pop(L, 1); /* remove a[j] */ + } + if (jbase+1)) + lj_lib_checkfunc(L, 2); + auxsort(L, 1, n); + return 0; +} + +#if LJ_52 +LJLIB_PUSH("n") +LJLIB_CF(table_pack) +{ + TValue *array, *base = L->base; + MSize i, n = (uint32_t)(L->top - base); + GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1); + /* NOBARRIER: The table is new (marked white). */ + setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n); + for (array = tvref(t->array) + 1, i = 0; i < n; i++) + copyTV(L, &array[i], &base[i]); + settabV(L, base, t); + L->top = base+1; + lj_gc_check(L); + return 1; +} +#endif + +/* ------------------------------------------------------------------------ */ + +#include "lj_libdef.h" + +LUALIB_API int luaopen_table(lua_State *L) +{ + LJ_LIB_REG(L, LUA_TABLIBNAME, table); +#if LJ_52 + lua_getglobal(L, "unpack"); + lua_setfield(L, -2, "unpack"); +#endif + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/linit.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/linit.c new file mode 100644 index 0000000..16c72ac --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/linit.c @@ -0,0 +1,37 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/liolib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/liolib.c new file mode 100644 index 0000000..e79ed1c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/liolib.c @@ -0,0 +1,553 @@ +/* +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define liolib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + + +static const char *const fnames[] = {"input", "output"}; + + +static int pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror (lua_State *L, int arg, const char *filename) { + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type (lua_State *L) { + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile (lua_State *L) { + FILE **f = tofilep(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile (lua_State *L) { + FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files +*/ +static int io_pclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = lua_pclose(L, *p); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +/* +** function to close regular files +*/ +static int io_fclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = (fclose(*p) == 0); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close (lua_State *L) { + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1))(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc (lua_State *L) { + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) + aux_close(L); + return 0; +} + + +static int io_tostring (lua_State *L) { + FILE *f = *tofilep(L); + if (f == NULL) + lua_pushliteral(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = lua_popen(L, filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, int findex) { + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **)lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile (lua_State *L, int f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +static void aux_lines (lua_State *L, int idx, int toclose) { + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } + else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number (lua_State *L, FILE *f) { + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } + else return 0; /* read fails */ +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f) { + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l-1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_objlen(L, -1) > 0); +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f); + break; + case 'a': /* file */ + read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + return g_write(L, tofile(L), 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); +} + + +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); +} + + +LUALIB_API int luaopen_io (lua_State *L) { + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + newfenv(L, io_fclose); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + lua_pop(L, 1); /* pop environment for default files */ + lua_getfield(L, -1, "popen"); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ + lua_pop(L, 1); /* pop 'popen' */ + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj.supp b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj.supp new file mode 100644 index 0000000..411f261 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj.supp @@ -0,0 +1,26 @@ +# Valgrind suppression file for LuaJIT 2.0. +{ + Optimized string compare + Memcheck:Addr4 + fun:lj_str_cmp +} +{ + Optimized string compare + Memcheck:Addr1 + fun:lj_str_cmp +} +{ + Optimized string compare + Memcheck:Addr4 + fun:lj_str_new +} +{ + Optimized string compare + Memcheck:Addr1 + fun:lj_str_new +} +{ + Optimized string compare + Memcheck:Cond + fun:lj_str_new +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.c new file mode 100644 index 0000000..f856a7a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.c @@ -0,0 +1,1390 @@ +/* +** Bundled memory allocator. +** +** Beware: this is a HEAVILY CUSTOMIZED version of dlmalloc. +** The original bears the following remark: +** +** This is a version (aka dlmalloc) of malloc/free/realloc written by +** Doug Lea and released to the public domain, as explained at +** http://creativecommons.org/licenses/publicdomain. +** +** * Version pre-2.8.4 Wed Mar 29 19:46:29 2006 (dl at gee) +** +** No additional copyright is claimed over the customizations. +** Please do NOT bother the original author about this version here! +** +** If you want to use dlmalloc in another project, you should get +** the original from: ftp://gee.cs.oswego.edu/pub/misc/ +** For thread-safe derivatives, take a look at: +** - ptmalloc: http://www.malloc.de/ +** - nedmalloc: http://www.nedprod.com/programs/portable/nedmalloc/ +*/ + +#define lj_alloc_c +#define LUA_CORE + +/* To get the mremap prototype. Must be defined before any system includes. */ +#if defined(__linux__) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + +#include "lj_def.h" +#include "lj_arch.h" +#include "lj_alloc.h" + +#ifndef LUAJIT_USE_SYSMALLOC + +#define MAX_SIZE_T (~(size_t)0) +#define MALLOC_ALIGNMENT ((size_t)8U) + +#define DEFAULT_GRANULARITY ((size_t)128U * (size_t)1024U) +#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) +#define DEFAULT_MMAP_THRESHOLD ((size_t)128U * (size_t)1024U) +#define MAX_RELEASE_CHECK_RATE 255 + +/* ------------------- size_t and alignment properties -------------------- */ + +/* The byte and bit size of a size_t */ +#define SIZE_T_SIZE (sizeof(size_t)) +#define SIZE_T_BITSIZE (sizeof(size_t) << 3) + +/* Some constants coerced to size_t */ +/* Annoying but necessary to avoid errors on some platforms */ +#define SIZE_T_ZERO ((size_t)0) +#define SIZE_T_ONE ((size_t)1) +#define SIZE_T_TWO ((size_t)2) +#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) +#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) +#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) + +/* The bit mask value corresponding to MALLOC_ALIGNMENT */ +#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) + +/* the number of bytes to offset an address to align it */ +#define align_offset(A)\ + ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ + ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) + +/* -------------------------- MMAP support ------------------------------- */ + +#define MFAIL ((void *)(MAX_SIZE_T)) +#define CMFAIL ((char *)(MFAIL)) /* defined for convenience */ + +#define IS_DIRECT_BIT (SIZE_T_ONE) + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#if LJ_64 + +/* Undocumented, but hey, that's what we all love so much about Windows. */ +typedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits, + size_t *size, ULONG alloctype, ULONG prot); +static PNTAVM ntavm; + +/* Number of top bits of the lower 32 bits of an address that must be zero. +** Apparently 0 gives us full 64 bit addresses and 1 gives us the lower 2GB. +*/ +#define NTAVM_ZEROBITS 1 + +static void INIT_MMAP(void) +{ + ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA("ntdll.dll"), + "NtAllocateVirtualMemory"); +} + +/* Win64 32 bit MMAP via NtAllocateVirtualMemory. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = NULL; + long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size, + MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + SetLastError(olderr); + return st == 0 ? ptr : MFAIL; +} + +/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ +static LJ_AINLINE void *DIRECT_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = NULL; + long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size, + MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE); + SetLastError(olderr); + return st == 0 ? ptr : MFAIL; +} + +#else + +#define INIT_MMAP() ((void)0) + +/* Win32 MMAP via VirtualAlloc */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + SetLastError(olderr); + return ptr ? ptr : MFAIL; +} + +/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ +static LJ_AINLINE void *DIRECT_MMAP(size_t size) +{ + DWORD olderr = GetLastError(); + void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, + PAGE_READWRITE); + SetLastError(olderr); + return ptr ? ptr : MFAIL; +} + +#endif + +/* This function supports releasing coalesed segments */ +static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size) +{ + DWORD olderr = GetLastError(); + MEMORY_BASIC_INFORMATION minfo; + char *cptr = (char *)ptr; + while (size) { + if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) + return -1; + if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || + minfo.State != MEM_COMMIT || minfo.RegionSize > size) + return -1; + if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) + return -1; + cptr += minfo.RegionSize; + size -= minfo.RegionSize; + } + SetLastError(olderr); + return 0; +} + +#else + +#include +#include + +#define MMAP_PROT (PROT_READ|PROT_WRITE) +#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) +#define MAP_ANONYMOUS MAP_ANON +#endif +#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) + +#if LJ_64 +/* 64 bit mode needs special support for allocating memory in the lower 2GB. */ + +#if defined(MAP_32BIT) + +/* Actually this only gives us max. 1GB in current Linux kernels. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + void *ptr = mmap(NULL, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0); + errno = olderr; + return ptr; +} + +#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) + +/* OSX and FreeBSD mmap() use a naive first-fit linear search. +** That's perfect for us. Except that -pagezero_size must be set for OSX, +** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs +** to be reduced to 250MB on FreeBSD. +*/ +#if LJ_TARGET_OSX +#define MMAP_REGION_START ((uintptr_t)0x10000) +#elif LJ_TARGET_PS4 +#define MMAP_REGION_START ((uintptr_t)0x4000) +#else +#define MMAP_REGION_START ((uintptr_t)0x10000000) +#endif +#define MMAP_REGION_END ((uintptr_t)0x80000000) + +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 +#include +#endif + +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + /* Hint for next allocation. Doesn't need to be thread-safe. */ + static uintptr_t alloc_hint = MMAP_REGION_START; + int retry = 0; +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 + static int rlimit_modified = 0; + if (LJ_UNLIKELY(rlimit_modified == 0)) { + struct rlimit rlim; + rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START; + setrlimit(RLIMIT_DATA, &rlim); /* Ignore result. May fail below. */ + rlimit_modified = 1; + } +#endif + for (;;) { + void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0); + if ((uintptr_t)p >= MMAP_REGION_START && + (uintptr_t)p + size < MMAP_REGION_END) { + alloc_hint = (uintptr_t)p + size; + errno = olderr; + return p; + } + if (p != CMFAIL) munmap(p, size); +#ifdef __sun__ + alloc_hint += 0x1000000; /* Need near-exhaustive linear scan. */ + if (alloc_hint + size < MMAP_REGION_END) continue; +#endif + if (retry) break; + retry = 1; + alloc_hint = MMAP_REGION_START; + } + errno = olderr; + return CMFAIL; +} + +#else + +#error "NYI: need an equivalent of MAP_32BIT for this 64 bit OS" + +#endif + +#else + +/* 32 bit mode is easy. */ +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0); + errno = olderr; + return ptr; +} + +#endif + +#define INIT_MMAP() ((void)0) +#define DIRECT_MMAP(s) CALL_MMAP(s) + +static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size) +{ + int olderr = errno; + int ret = munmap(ptr, size); + errno = olderr; + return ret; +} + +#if LJ_TARGET_LINUX +/* Need to define _GNU_SOURCE to get the mremap prototype. */ +static LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz, + int flags) +{ + int olderr = errno; + ptr = mremap(ptr, osz, nsz, flags); + errno = olderr; + return ptr; +} + +#define CALL_MREMAP(addr, osz, nsz, mv) CALL_MREMAP_((addr), (osz), (nsz), (mv)) +#define CALL_MREMAP_NOMOVE 0 +#define CALL_MREMAP_MAYMOVE 1 +#if LJ_64 +#define CALL_MREMAP_MV CALL_MREMAP_NOMOVE +#else +#define CALL_MREMAP_MV CALL_MREMAP_MAYMOVE +#endif +#endif + +#endif + +#ifndef CALL_MREMAP +#define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL) +#endif + +/* ----------------------- Chunk representations ------------------------ */ + +struct malloc_chunk { + size_t prev_foot; /* Size of previous chunk (if free). */ + size_t head; /* Size and inuse bits. */ + struct malloc_chunk *fd; /* double links -- used only if free. */ + struct malloc_chunk *bk; +}; + +typedef struct malloc_chunk mchunk; +typedef struct malloc_chunk *mchunkptr; +typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */ +typedef size_t bindex_t; /* Described below */ +typedef unsigned int binmap_t; /* Described below */ +typedef unsigned int flag_t; /* The type of various bit flag sets */ + +/* ------------------- Chunks sizes and alignments ----------------------- */ + +#define MCHUNK_SIZE (sizeof(mchunk)) + +#define CHUNK_OVERHEAD (SIZE_T_SIZE) + +/* Direct chunks need a second word of overhead ... */ +#define DIRECT_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) +/* ... and additional padding for fake next-chunk at foot */ +#define DIRECT_FOOT_PAD (FOUR_SIZE_T_SIZES) + +/* The smallest size we can malloc is an aligned minimal chunk */ +#define MIN_CHUNK_SIZE\ + ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* conversion from malloc headers to user pointers, and back */ +#define chunk2mem(p) ((void *)((char *)(p) + TWO_SIZE_T_SIZES)) +#define mem2chunk(mem) ((mchunkptr)((char *)(mem) - TWO_SIZE_T_SIZES)) +/* chunk associated with aligned address A */ +#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) + +/* Bounds on request (not chunk) sizes. */ +#define MAX_REQUEST ((~MIN_CHUNK_SIZE+1) << 2) +#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) + +/* pad request bytes into a usable size */ +#define pad_request(req) \ + (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* pad request, checking for minimum (but not maximum) */ +#define request2size(req) \ + (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) + +/* ------------------ Operations on head and foot fields ----------------- */ + +#define PINUSE_BIT (SIZE_T_ONE) +#define CINUSE_BIT (SIZE_T_TWO) +#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) + +/* Head value for fenceposts */ +#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) + +/* extraction of fields from head words */ +#define cinuse(p) ((p)->head & CINUSE_BIT) +#define pinuse(p) ((p)->head & PINUSE_BIT) +#define chunksize(p) ((p)->head & ~(INUSE_BITS)) + +#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) +#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) + +/* Treat space at ptr +/- offset as a chunk */ +#define chunk_plus_offset(p, s) ((mchunkptr)(((char *)(p)) + (s))) +#define chunk_minus_offset(p, s) ((mchunkptr)(((char *)(p)) - (s))) + +/* Ptr to next or previous physical malloc_chunk. */ +#define next_chunk(p) ((mchunkptr)(((char *)(p)) + ((p)->head & ~INUSE_BITS))) +#define prev_chunk(p) ((mchunkptr)(((char *)(p)) - ((p)->prev_foot) )) + +/* extract next chunk's pinuse bit */ +#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) + +/* Get/set size at footer */ +#define get_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot) +#define set_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot = (s)) + +/* Set size, pinuse bit, and foot */ +#define set_size_and_pinuse_of_free_chunk(p, s)\ + ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) + +/* Set size, pinuse bit, foot, and clear next pinuse */ +#define set_free_with_pinuse(p, s, n)\ + (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) + +#define is_direct(p)\ + (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_DIRECT_BIT)) + +/* Get the internal overhead associated with chunk p */ +#define overhead_for(p)\ + (is_direct(p)? DIRECT_CHUNK_OVERHEAD : CHUNK_OVERHEAD) + +/* ---------------------- Overlaid data structures ----------------------- */ + +struct malloc_tree_chunk { + /* The first four fields must be compatible with malloc_chunk */ + size_t prev_foot; + size_t head; + struct malloc_tree_chunk *fd; + struct malloc_tree_chunk *bk; + + struct malloc_tree_chunk *child[2]; + struct malloc_tree_chunk *parent; + bindex_t index; +}; + +typedef struct malloc_tree_chunk tchunk; +typedef struct malloc_tree_chunk *tchunkptr; +typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */ + +/* A little helper macro for trees */ +#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) + +/* ----------------------------- Segments -------------------------------- */ + +struct malloc_segment { + char *base; /* base address */ + size_t size; /* allocated size */ + struct malloc_segment *next; /* ptr to next segment */ +}; + +typedef struct malloc_segment msegment; +typedef struct malloc_segment *msegmentptr; + +/* ---------------------------- malloc_state ----------------------------- */ + +/* Bin types, widths and sizes */ +#define NSMALLBINS (32U) +#define NTREEBINS (32U) +#define SMALLBIN_SHIFT (3U) +#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) +#define TREEBIN_SHIFT (8U) +#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) +#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) +#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) + +struct malloc_state { + binmap_t smallmap; + binmap_t treemap; + size_t dvsize; + size_t topsize; + mchunkptr dv; + mchunkptr top; + size_t trim_check; + size_t release_checks; + mchunkptr smallbins[(NSMALLBINS+1)*2]; + tbinptr treebins[NTREEBINS]; + msegment seg; +}; + +typedef struct malloc_state *mstate; + +#define is_initialized(M) ((M)->top != 0) + +/* -------------------------- system alloc setup ------------------------- */ + +/* page-align a size */ +#define page_align(S)\ + (((S) + (LJ_PAGESIZE - SIZE_T_ONE)) & ~(LJ_PAGESIZE - SIZE_T_ONE)) + +/* granularity-align a size */ +#define granularity_align(S)\ + (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\ + & ~(DEFAULT_GRANULARITY - SIZE_T_ONE)) + +#if LJ_TARGET_WINDOWS +#define mmap_align(S) granularity_align(S) +#else +#define mmap_align(S) page_align(S) +#endif + +/* True if segment S holds address A */ +#define segment_holds(S, A)\ + ((char *)(A) >= S->base && (char *)(A) < S->base + S->size) + +/* Return segment holding given address */ +static msegmentptr segment_holding(mstate m, char *addr) +{ + msegmentptr sp = &m->seg; + for (;;) { + if (addr >= sp->base && addr < sp->base + sp->size) + return sp; + if ((sp = sp->next) == 0) + return 0; + } +} + +/* Return true if segment contains a segment link */ +static int has_segment_link(mstate m, msegmentptr ss) +{ + msegmentptr sp = &m->seg; + for (;;) { + if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size) + return 1; + if ((sp = sp->next) == 0) + return 0; + } +} + +/* + TOP_FOOT_SIZE is padding at the end of a segment, including space + that may be needed to place segment records and fenceposts when new + noncontiguous segments are added. +*/ +#define TOP_FOOT_SIZE\ + (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) + +/* ---------------------------- Indexing Bins ---------------------------- */ + +#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) +#define small_index(s) ((s) >> SMALLBIN_SHIFT) +#define small_index2size(i) ((i) << SMALLBIN_SHIFT) +#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) + +/* addressing by index. See above about smallbin repositioning */ +#define smallbin_at(M, i) ((sbinptr)((char *)&((M)->smallbins[(i)<<1]))) +#define treebin_at(M,i) (&((M)->treebins[i])) + +/* assign tree index for size S to variable I */ +#define compute_tree_index(S, I)\ +{\ + unsigned int X = (unsigned int)(S >> TREEBIN_SHIFT);\ + if (X == 0) {\ + I = 0;\ + } else if (X > 0xFFFF) {\ + I = NTREEBINS-1;\ + } else {\ + unsigned int K = lj_fls(X);\ + I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ + }\ +} + +/* Bit representing maximum resolved size in a treebin at i */ +#define bit_for_tree_index(i) \ + (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) + +/* Shift placing maximum resolved bit in a treebin at i as sign bit */ +#define leftshift_for_tree_index(i) \ + ((i == NTREEBINS-1)? 0 : \ + ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) + +/* The size of the smallest chunk held in bin with index i */ +#define minsize_for_tree_index(i) \ + ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ + (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) + +/* ------------------------ Operations on bin maps ----------------------- */ + +/* bit corresponding to given index */ +#define idx2bit(i) ((binmap_t)(1) << (i)) + +/* Mark/Clear bits with given index */ +#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) +#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) +#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) + +#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) +#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) +#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) + +/* mask with all bits to left of least bit of x on */ +#define left_bits(x) ((x<<1) | (~(x<<1)+1)) + +/* Set cinuse bit and pinuse bit of next chunk */ +#define set_inuse(M,p,s)\ + ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ + ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set cinuse and pinuse of this chunk and pinuse of next chunk */ +#define set_inuse_and_pinuse(M,p,s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ + ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set size, cinuse and pinuse bit of this chunk */ +#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) + +/* ----------------------- Operations on smallbins ----------------------- */ + +/* Link a free chunk into a smallbin */ +#define insert_small_chunk(M, P, S) {\ + bindex_t I = small_index(S);\ + mchunkptr B = smallbin_at(M, I);\ + mchunkptr F = B;\ + if (!smallmap_is_marked(M, I))\ + mark_smallmap(M, I);\ + else\ + F = B->fd;\ + B->fd = P;\ + F->bk = P;\ + P->fd = F;\ + P->bk = B;\ +} + +/* Unlink a chunk from a smallbin */ +#define unlink_small_chunk(M, P, S) {\ + mchunkptr F = P->fd;\ + mchunkptr B = P->bk;\ + bindex_t I = small_index(S);\ + if (F == B) {\ + clear_smallmap(M, I);\ + } else {\ + F->bk = B;\ + B->fd = F;\ + }\ +} + +/* Unlink the first chunk from a smallbin */ +#define unlink_first_small_chunk(M, B, P, I) {\ + mchunkptr F = P->fd;\ + if (B == F) {\ + clear_smallmap(M, I);\ + } else {\ + B->fd = F;\ + F->bk = B;\ + }\ +} + +/* Replace dv node, binning the old one */ +/* Used only when dvsize known to be small */ +#define replace_dv(M, P, S) {\ + size_t DVS = M->dvsize;\ + if (DVS != 0) {\ + mchunkptr DV = M->dv;\ + insert_small_chunk(M, DV, DVS);\ + }\ + M->dvsize = S;\ + M->dv = P;\ +} + +/* ------------------------- Operations on trees ------------------------- */ + +/* Insert chunk into tree */ +#define insert_large_chunk(M, X, S) {\ + tbinptr *H;\ + bindex_t I;\ + compute_tree_index(S, I);\ + H = treebin_at(M, I);\ + X->index = I;\ + X->child[0] = X->child[1] = 0;\ + if (!treemap_is_marked(M, I)) {\ + mark_treemap(M, I);\ + *H = X;\ + X->parent = (tchunkptr)H;\ + X->fd = X->bk = X;\ + } else {\ + tchunkptr T = *H;\ + size_t K = S << leftshift_for_tree_index(I);\ + for (;;) {\ + if (chunksize(T) != S) {\ + tchunkptr *C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ + K <<= 1;\ + if (*C != 0) {\ + T = *C;\ + } else {\ + *C = X;\ + X->parent = T;\ + X->fd = X->bk = X;\ + break;\ + }\ + } else {\ + tchunkptr F = T->fd;\ + T->fd = F->bk = X;\ + X->fd = F;\ + X->bk = T;\ + X->parent = 0;\ + break;\ + }\ + }\ + }\ +} + +#define unlink_large_chunk(M, X) {\ + tchunkptr XP = X->parent;\ + tchunkptr R;\ + if (X->bk != X) {\ + tchunkptr F = X->fd;\ + R = X->bk;\ + F->bk = R;\ + R->fd = F;\ + } else {\ + tchunkptr *RP;\ + if (((R = *(RP = &(X->child[1]))) != 0) ||\ + ((R = *(RP = &(X->child[0]))) != 0)) {\ + tchunkptr *CP;\ + while ((*(CP = &(R->child[1])) != 0) ||\ + (*(CP = &(R->child[0])) != 0)) {\ + R = *(RP = CP);\ + }\ + *RP = 0;\ + }\ + }\ + if (XP != 0) {\ + tbinptr *H = treebin_at(M, X->index);\ + if (X == *H) {\ + if ((*H = R) == 0) \ + clear_treemap(M, X->index);\ + } else {\ + if (XP->child[0] == X) \ + XP->child[0] = R;\ + else \ + XP->child[1] = R;\ + }\ + if (R != 0) {\ + tchunkptr C0, C1;\ + R->parent = XP;\ + if ((C0 = X->child[0]) != 0) {\ + R->child[0] = C0;\ + C0->parent = R;\ + }\ + if ((C1 = X->child[1]) != 0) {\ + R->child[1] = C1;\ + C1->parent = R;\ + }\ + }\ + }\ +} + +/* Relays to large vs small bin operations */ + +#define insert_chunk(M, P, S)\ + if (is_small(S)) { insert_small_chunk(M, P, S)\ + } else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } + +#define unlink_chunk(M, P, S)\ + if (is_small(S)) { unlink_small_chunk(M, P, S)\ + } else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } + +/* ----------------------- Direct-mmapping chunks ----------------------- */ + +static void *direct_alloc(size_t nb) +{ + size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + if (LJ_LIKELY(mmsize > nb)) { /* Check for wrap around 0 */ + char *mm = (char *)(DIRECT_MMAP(mmsize)); + if (mm != CMFAIL) { + size_t offset = align_offset(chunk2mem(mm)); + size_t psize = mmsize - offset - DIRECT_FOOT_PAD; + mchunkptr p = (mchunkptr)(mm + offset); + p->prev_foot = offset | IS_DIRECT_BIT; + p->head = psize|CINUSE_BIT; + chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; + return chunk2mem(p); + } + } + return NULL; +} + +static mchunkptr direct_resize(mchunkptr oldp, size_t nb) +{ + size_t oldsize = chunksize(oldp); + if (is_small(nb)) /* Can't shrink direct regions below small size */ + return NULL; + /* Keep old chunk if big enough but not too big */ + if (oldsize >= nb + SIZE_T_SIZE && + (oldsize - nb) <= (DEFAULT_GRANULARITY >> 1)) { + return oldp; + } else { + size_t offset = oldp->prev_foot & ~IS_DIRECT_BIT; + size_t oldmmsize = oldsize + offset + DIRECT_FOOT_PAD; + size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + char *cp = (char *)CALL_MREMAP((char *)oldp - offset, + oldmmsize, newmmsize, CALL_MREMAP_MV); + if (cp != CMFAIL) { + mchunkptr newp = (mchunkptr)(cp + offset); + size_t psize = newmmsize - offset - DIRECT_FOOT_PAD; + newp->head = psize|CINUSE_BIT; + chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; + return newp; + } + } + return NULL; +} + +/* -------------------------- mspace management -------------------------- */ + +/* Initialize top chunk and its size */ +static void init_top(mstate m, mchunkptr p, size_t psize) +{ + /* Ensure alignment */ + size_t offset = align_offset(chunk2mem(p)); + p = (mchunkptr)((char *)p + offset); + psize -= offset; + + m->top = p; + m->topsize = psize; + p->head = psize | PINUSE_BIT; + /* set size of fake trailing chunk holding overhead space only once */ + chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; + m->trim_check = DEFAULT_TRIM_THRESHOLD; /* reset on each update */ +} + +/* Initialize bins for a new mstate that is otherwise zeroed out */ +static void init_bins(mstate m) +{ + /* Establish circular links for smallbins */ + bindex_t i; + for (i = 0; i < NSMALLBINS; i++) { + sbinptr bin = smallbin_at(m,i); + bin->fd = bin->bk = bin; + } +} + +/* Allocate chunk and prepend remainder with chunk in successor base. */ +static void *prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb) +{ + mchunkptr p = align_as_chunk(newbase); + mchunkptr oldfirst = align_as_chunk(oldbase); + size_t psize = (size_t)((char *)oldfirst - (char *)p); + mchunkptr q = chunk_plus_offset(p, nb); + size_t qsize = psize - nb; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + + /* consolidate remainder with first chunk of old base */ + if (oldfirst == m->top) { + size_t tsize = m->topsize += qsize; + m->top = q; + q->head = tsize | PINUSE_BIT; + } else if (oldfirst == m->dv) { + size_t dsize = m->dvsize += qsize; + m->dv = q; + set_size_and_pinuse_of_free_chunk(q, dsize); + } else { + if (!cinuse(oldfirst)) { + size_t nsize = chunksize(oldfirst); + unlink_chunk(m, oldfirst, nsize); + oldfirst = chunk_plus_offset(oldfirst, nsize); + qsize += nsize; + } + set_free_with_pinuse(q, qsize, oldfirst); + insert_chunk(m, q, qsize); + } + + return chunk2mem(p); +} + +/* Add a segment to hold a new noncontiguous region */ +static void add_segment(mstate m, char *tbase, size_t tsize) +{ + /* Determine locations and sizes of segment, fenceposts, old top */ + char *old_top = (char *)m->top; + msegmentptr oldsp = segment_holding(m, old_top); + char *old_end = oldsp->base + oldsp->size; + size_t ssize = pad_request(sizeof(struct malloc_segment)); + char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + size_t offset = align_offset(chunk2mem(rawsp)); + char *asp = rawsp + offset; + char *csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; + mchunkptr sp = (mchunkptr)csp; + msegmentptr ss = (msegmentptr)(chunk2mem(sp)); + mchunkptr tnext = chunk_plus_offset(sp, ssize); + mchunkptr p = tnext; + + /* reset top to new space */ + init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); + + /* Set up segment record */ + set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); + *ss = m->seg; /* Push current record */ + m->seg.base = tbase; + m->seg.size = tsize; + m->seg.next = ss; + + /* Insert trailing fenceposts */ + for (;;) { + mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); + p->head = FENCEPOST_HEAD; + if ((char *)(&(nextp->head)) < old_end) + p = nextp; + else + break; + } + + /* Insert the rest of old top into a bin as an ordinary free chunk */ + if (csp != old_top) { + mchunkptr q = (mchunkptr)old_top; + size_t psize = (size_t)(csp - old_top); + mchunkptr tn = chunk_plus_offset(q, psize); + set_free_with_pinuse(q, psize, tn); + insert_chunk(m, q, psize); + } +} + +/* -------------------------- System allocation -------------------------- */ + +static void *alloc_sys(mstate m, size_t nb) +{ + char *tbase = CMFAIL; + size_t tsize = 0; + + /* Directly map large chunks */ + if (LJ_UNLIKELY(nb >= DEFAULT_MMAP_THRESHOLD)) { + void *mem = direct_alloc(nb); + if (mem != 0) + return mem; + } + + { + size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE; + size_t rsize = granularity_align(req); + if (LJ_LIKELY(rsize > nb)) { /* Fail if wraps around zero */ + char *mp = (char *)(CALL_MMAP(rsize)); + if (mp != CMFAIL) { + tbase = mp; + tsize = rsize; + } + } + } + + if (tbase != CMFAIL) { + msegmentptr sp = &m->seg; + /* Try to merge with an existing segment */ + while (sp != 0 && tbase != sp->base + sp->size) + sp = sp->next; + if (sp != 0 && segment_holds(sp, m->top)) { /* append */ + sp->size += tsize; + init_top(m, m->top, m->topsize + tsize); + } else { + sp = &m->seg; + while (sp != 0 && sp->base != tbase + tsize) + sp = sp->next; + if (sp != 0) { + char *oldbase = sp->base; + sp->base = tbase; + sp->size += tsize; + return prepend_alloc(m, tbase, oldbase, nb); + } else { + add_segment(m, tbase, tsize); + } + } + + if (nb < m->topsize) { /* Allocate from new or extended top space */ + size_t rsize = m->topsize -= nb; + mchunkptr p = m->top; + mchunkptr r = m->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + return chunk2mem(p); + } + } + + return NULL; +} + +/* ----------------------- system deallocation -------------------------- */ + +/* Unmap and unlink any mmapped segments that don't contain used chunks */ +static size_t release_unused_segments(mstate m) +{ + size_t released = 0; + size_t nsegs = 0; + msegmentptr pred = &m->seg; + msegmentptr sp = pred->next; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + msegmentptr next = sp->next; + nsegs++; + { + mchunkptr p = align_as_chunk(base); + size_t psize = chunksize(p); + /* Can unmap if first chunk holds entire segment and not pinned */ + if (!cinuse(p) && (char *)p + psize >= base + size - TOP_FOOT_SIZE) { + tchunkptr tp = (tchunkptr)p; + if (p == m->dv) { + m->dv = 0; + m->dvsize = 0; + } else { + unlink_large_chunk(m, tp); + } + if (CALL_MUNMAP(base, size) == 0) { + released += size; + /* unlink obsoleted record */ + sp = pred; + sp->next = next; + } else { /* back out if cannot unmap */ + insert_large_chunk(m, tp, psize); + } + } + } + pred = sp; + sp = next; + } + /* Reset check counter */ + m->release_checks = nsegs > MAX_RELEASE_CHECK_RATE ? + nsegs : MAX_RELEASE_CHECK_RATE; + return released; +} + +static int alloc_trim(mstate m, size_t pad) +{ + size_t released = 0; + if (pad < MAX_REQUEST && is_initialized(m)) { + pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ + + if (m->topsize > pad) { + /* Shrink top space in granularity-size units, keeping at least one */ + size_t unit = DEFAULT_GRANULARITY; + size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - + SIZE_T_ONE) * unit; + msegmentptr sp = segment_holding(m, (char *)m->top); + + if (sp->size >= extra && + !has_segment_link(m, sp)) { /* can't shrink if pinned */ + size_t newsize = sp->size - extra; + /* Prefer mremap, fall back to munmap */ + if ((CALL_MREMAP(sp->base, sp->size, newsize, CALL_MREMAP_NOMOVE) != MFAIL) || + (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { + released = extra; + } + } + + if (released != 0) { + sp->size -= released; + init_top(m, m->top, m->topsize - released); + } + } + + /* Unmap any unused mmapped segments */ + released += release_unused_segments(m); + + /* On failure, disable autotrim to avoid repeated failed future calls */ + if (released == 0 && m->topsize > m->trim_check) + m->trim_check = MAX_SIZE_T; + } + + return (released != 0)? 1 : 0; +} + +/* ---------------------------- malloc support --------------------------- */ + +/* allocate a large request from the best fitting chunk in a treebin */ +static void *tmalloc_large(mstate m, size_t nb) +{ + tchunkptr v = 0; + size_t rsize = ~nb+1; /* Unsigned negation */ + tchunkptr t; + bindex_t idx; + compute_tree_index(nb, idx); + + if ((t = *treebin_at(m, idx)) != 0) { + /* Traverse tree for this bin looking for node with size == nb */ + size_t sizebits = nb << leftshift_for_tree_index(idx); + tchunkptr rst = 0; /* The deepest untaken right subtree */ + for (;;) { + tchunkptr rt; + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + v = t; + if ((rsize = trem) == 0) + break; + } + rt = t->child[1]; + t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; + if (rt != 0 && rt != t) + rst = rt; + if (t == 0) { + t = rst; /* set t to least subtree holding sizes > nb */ + break; + } + sizebits <<= 1; + } + } + + if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ + binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; + if (leftbits != 0) + t = *treebin_at(m, lj_ffs(leftbits)); + } + + while (t != 0) { /* find smallest of tree or subtree */ + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + t = leftmost_child(t); + } + + /* If dv is a better fit, return NULL so malloc will use it */ + if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { + mchunkptr r = chunk_plus_offset(v, nb); + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(m, v, (rsize + nb)); + } else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + insert_chunk(m, r, rsize); + } + return chunk2mem(v); + } + return NULL; +} + +/* allocate a small request from the best fitting chunk in a treebin */ +static void *tmalloc_small(mstate m, size_t nb) +{ + tchunkptr t, v; + mchunkptr r; + size_t rsize; + bindex_t i = lj_ffs(m->treemap); + + v = t = *treebin_at(m, i); + rsize = chunksize(t) - nb; + + while ((t = leftmost_child(t)) != 0) { + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + } + + r = chunk_plus_offset(v, nb); + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(m, v, (rsize + nb)); + } else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(m, r, rsize); + } + return chunk2mem(v); +} + +/* ----------------------------------------------------------------------- */ + +void *lj_alloc_create(void) +{ + size_t tsize = DEFAULT_GRANULARITY; + char *tbase; + INIT_MMAP(); + tbase = (char *)(CALL_MMAP(tsize)); + if (tbase != CMFAIL) { + size_t msize = pad_request(sizeof(struct malloc_state)); + mchunkptr mn; + mchunkptr msp = align_as_chunk(tbase); + mstate m = (mstate)(chunk2mem(msp)); + memset(m, 0, msize); + msp->head = (msize|PINUSE_BIT|CINUSE_BIT); + m->seg.base = tbase; + m->seg.size = tsize; + m->release_checks = MAX_RELEASE_CHECK_RATE; + init_bins(m); + mn = next_chunk(mem2chunk(m)); + init_top(m, mn, (size_t)((tbase + tsize) - (char *)mn) - TOP_FOOT_SIZE); + return m; + } + return NULL; +} + +void lj_alloc_destroy(void *msp) +{ + mstate ms = (mstate)msp; + msegmentptr sp = &ms->seg; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + sp = sp->next; + CALL_MUNMAP(base, size); + } +} + +static LJ_NOINLINE void *lj_alloc_malloc(void *msp, size_t nsize) +{ + mstate ms = (mstate)msp; + void *mem; + size_t nb; + if (nsize <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (nsize < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(nsize); + idx = small_index(nb); + smallbits = ms->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at(ms, idx); + p = b->fd; + unlink_first_small_chunk(ms, b, p, idx); + set_inuse_and_pinuse(ms, p, small_index2size(idx)); + mem = chunk2mem(p); + return mem; + } else if (nb > ms->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); + bindex_t i = lj_ffs(leftbits); + b = smallbin_at(ms, i); + p = b->fd; + unlink_first_small_chunk(ms, b, p, i); + rsize = small_index2size(i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) { + set_inuse_and_pinuse(ms, p, small_index2size(i)); + } else { + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + r = chunk_plus_offset(p, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(ms, r, rsize); + } + mem = chunk2mem(p); + return mem; + } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { + return mem; + } + } + } else if (nsize >= MAX_REQUEST) { + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + } else { + nb = pad_request(nsize); + if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { + return mem; + } + } + + if (nb <= ms->dvsize) { + size_t rsize = ms->dvsize - nb; + mchunkptr p = ms->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = ms->dv = chunk_plus_offset(p, nb); + ms->dvsize = rsize; + set_size_and_pinuse_of_free_chunk(r, rsize); + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + } else { /* exhaust dv */ + size_t dvs = ms->dvsize; + ms->dvsize = 0; + ms->dv = 0; + set_inuse_and_pinuse(ms, p, dvs); + } + mem = chunk2mem(p); + return mem; + } else if (nb < ms->topsize) { /* Split top */ + size_t rsize = ms->topsize -= nb; + mchunkptr p = ms->top; + mchunkptr r = ms->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + mem = chunk2mem(p); + return mem; + } + return alloc_sys(ms, nb); +} + +static LJ_NOINLINE void *lj_alloc_free(void *msp, void *ptr) +{ + if (ptr != 0) { + mchunkptr p = mem2chunk(ptr); + mstate fm = (mstate)msp; + size_t psize = chunksize(p); + mchunkptr next = chunk_plus_offset(p, psize); + if (!pinuse(p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_DIRECT_BIT) != 0) { + prevsize &= ~IS_DIRECT_BIT; + psize += prevsize + DIRECT_FOOT_PAD; + CALL_MUNMAP((char *)p - prevsize, psize); + return NULL; + } else { + mchunkptr prev = chunk_minus_offset(p, prevsize); + psize += prevsize; + p = prev; + /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk(fm, p, prevsize); + } else if ((next->head & INUSE_BITS) == INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse(p, psize, next); + return NULL; + } + } + } + if (!cinuse(next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (tsize > fm->trim_check) + alloc_trim(fm, 0); + return NULL; + } else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk(p, dsize); + return NULL; + } else { + size_t nsize = chunksize(next); + psize += nsize; + unlink_chunk(fm, next, nsize); + set_size_and_pinuse_of_free_chunk(p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + return NULL; + } + } + } else { + set_free_with_pinuse(p, psize, next); + } + + if (is_small(psize)) { + insert_small_chunk(fm, p, psize); + } else { + tchunkptr tp = (tchunkptr)p; + insert_large_chunk(fm, tp, psize); + if (--fm->release_checks == 0) + release_unused_segments(fm); + } + } + return NULL; +} + +static LJ_NOINLINE void *lj_alloc_realloc(void *msp, void *ptr, size_t nsize) +{ + if (nsize >= MAX_REQUEST) { + return NULL; + } else { + mstate m = (mstate)msp; + mchunkptr oldp = mem2chunk(ptr); + size_t oldsize = chunksize(oldp); + mchunkptr next = chunk_plus_offset(oldp, oldsize); + mchunkptr newp = 0; + size_t nb = request2size(nsize); + + /* Try to either shrink or extend into top. Else malloc-copy-free */ + if (is_direct(oldp)) { + newp = direct_resize(oldp, nb); /* this may return NULL. */ + } else if (oldsize >= nb) { /* already big enough */ + size_t rsize = oldsize - nb; + newp = oldp; + if (rsize >= MIN_CHUNK_SIZE) { + mchunkptr rem = chunk_plus_offset(newp, nb); + set_inuse(m, newp, nb); + set_inuse(m, rem, rsize); + lj_alloc_free(m, chunk2mem(rem)); + } + } else if (next == m->top && oldsize + m->topsize > nb) { + /* Expand into top */ + size_t newsize = oldsize + m->topsize; + size_t newtopsize = newsize - nb; + mchunkptr newtop = chunk_plus_offset(oldp, nb); + set_inuse(m, oldp, nb); + newtop->head = newtopsize |PINUSE_BIT; + m->top = newtop; + m->topsize = newtopsize; + newp = oldp; + } + + if (newp != 0) { + return chunk2mem(newp); + } else { + void *newmem = lj_alloc_malloc(m, nsize); + if (newmem != 0) { + size_t oc = oldsize - overhead_for(oldp); + memcpy(newmem, ptr, oc < nsize ? oc : nsize); + lj_alloc_free(m, ptr); + } + return newmem; + } + } +} + +void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize) +{ + (void)osize; + if (nsize == 0) { + return lj_alloc_free(msp, ptr); + } else if (ptr == NULL) { + return lj_alloc_malloc(msp, nsize); + } else { + return lj_alloc_realloc(msp, ptr, nsize); + } +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.h new file mode 100644 index 0000000..f87a7cf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_alloc.h @@ -0,0 +1,17 @@ +/* +** Bundled memory allocator. +** Donated to the public domain. +*/ + +#ifndef _LJ_ALLOC_H +#define _LJ_ALLOC_H + +#include "lj_def.h" + +#ifndef LUAJIT_USE_SYSMALLOC +LJ_FUNC void *lj_alloc_create(void); +LJ_FUNC void lj_alloc_destroy(void *msp); +LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_api.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_api.c new file mode 100644 index 0000000..410b1b9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_api.c @@ -0,0 +1,1220 @@ +/* +** Public Lua/C API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_api_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_udata.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_bc.h" +#include "lj_frame.h" +#include "lj_trace.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* -- Common helper functions --------------------------------------------- */ + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) +#define api_checkvalidindex(L, i) api_check(L, (i) != niltv(L)) + +static TValue *index2adr(lua_State *L, int idx) +{ + if (idx > 0) { + TValue *o = L->base + (idx - 1); + return o < L->top ? o : niltv(L); + } else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } else if (idx == LUA_GLOBALSINDEX) { + TValue *o = &G(L)->tmptv; + settabV(L, o, tabref(L->env)); + return o; + } else if (idx == LUA_REGISTRYINDEX) { + return registry(L); + } else { + GCfunc *fn = curr_func(L); + api_check(L, fn->c.gct == ~LJ_TFUNC && !isluafunc(fn)); + if (idx == LUA_ENVIRONINDEX) { + TValue *o = &G(L)->tmptv; + settabV(L, o, tabref(fn->c.env)); + return o; + } else { + idx = LUA_GLOBALSINDEX - idx; + return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L); + } + } +} + +static TValue *stkindex2adr(lua_State *L, int idx) +{ + if (idx > 0) { + TValue *o = L->base + (idx - 1); + return o < L->top ? o : niltv(L); + } else { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } +} + +static GCtab *getcurrenv(lua_State *L) +{ + GCfunc *fn = curr_func(L); + return fn->c.gct == ~LJ_TFUNC ? tabref(fn->c.env) : tabref(L->env); +} + +/* -- Miscellaneous API functions ----------------------------------------- */ + +LUA_API int lua_status(lua_State *L) +{ + return L->status; +} + +LUA_API int lua_checkstack(lua_State *L, int size) +{ + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) { + return 0; /* Stack overflow. */ + } else if (size > 0) { + lj_state_checkstack(L, (MSize)size); + } + return 1; +} + +LUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg) +{ + if (!lua_checkstack(L, size)) + lj_err_callerv(L, LJ_ERR_STKOVM, msg); +} + +LUA_API void lua_xmove(lua_State *from, lua_State *to, int n) +{ + TValue *f, *t; + if (from == to) return; + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + lj_state_checkstack(to, (MSize)n); + f = from->top; + t = to->top = to->top + n; + while (--n >= 0) copyTV(to, --t, --f); + from->top = f; +} + +/* -- Stack manipulation -------------------------------------------------- */ + +LUA_API int lua_gettop(lua_State *L) +{ + return (int)(L->top - L->base); +} + +LUA_API void lua_settop(lua_State *L, int idx) +{ + if (idx >= 0) { + api_check(L, idx <= tvref(L->maxstack) - L->base); + if (L->base + idx > L->top) { + if (L->base + idx >= tvref(L->maxstack)) + lj_state_growstack(L, (MSize)idx - (MSize)(L->top - L->base)); + do { setnilV(L->top++); } while (L->top < L->base + idx); + } else { + L->top = L->base + idx; + } + } else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* Shrinks top (idx < 0). */ + } +} + +LUA_API void lua_remove(lua_State *L, int idx) +{ + TValue *p = stkindex2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) copyTV(L, p-1, p); + L->top--; +} + +LUA_API void lua_insert(lua_State *L, int idx) +{ + TValue *q, *p = stkindex2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q > p; q--) copyTV(L, q, q-1); + copyTV(L, p, L->top); +} + +LUA_API void lua_replace(lua_State *L, int idx) +{ + api_checknelems(L, 1); + if (idx == LUA_GLOBALSINDEX) { + api_check(L, tvistab(L->top-1)); + /* NOBARRIER: A thread (i.e. L) is never black. */ + setgcref(L->env, obj2gco(tabV(L->top-1))); + } else if (idx == LUA_ENVIRONINDEX) { + GCfunc *fn = curr_func(L); + if (fn->c.gct != ~LJ_TFUNC) + lj_err_msg(L, LJ_ERR_NOENV); + api_check(L, tvistab(L->top-1)); + setgcref(fn->c.env, obj2gco(tabV(L->top-1))); + lj_gc_barrier(L, fn, L->top-1); + } else { + TValue *o = index2adr(L, idx); + api_checkvalidindex(L, o); + copyTV(L, o, L->top-1); + if (idx < LUA_GLOBALSINDEX) /* Need a barrier for upvalues. */ + lj_gc_barrier(L, curr_func(L), L->top-1); + } + L->top--; +} + +LUA_API void lua_pushvalue(lua_State *L, int idx) +{ + copyTV(L, L->top, index2adr(L, idx)); + incr_top(L); +} + +/* -- Stack getters ------------------------------------------------------- */ + +LUA_API int lua_type(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisnumber(o)) { + return LUA_TNUMBER; +#if LJ_64 + } else if (tvislightud(o)) { + return LUA_TLIGHTUSERDATA; +#endif + } else if (o == niltv(L)) { + return LUA_TNONE; + } else { /* Magic internal/external tag conversion. ORDER LJ_T */ + uint32_t t = ~itype(o); +#if LJ_64 + int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u); +#else + int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u); +#endif + lua_assert(tt != LUA_TNIL || tvisnil(o)); + return tt; + } +} + +LUALIB_API void luaL_checktype(lua_State *L, int idx, int tt) +{ + if (lua_type(L, idx) != tt) + lj_err_argt(L, idx, tt); +} + +LUALIB_API void luaL_checkany(lua_State *L, int idx) +{ + if (index2adr(L, idx) == niltv(L)) + lj_err_arg(L, idx, LJ_ERR_NOVAL); +} + +LUA_API const char *lua_typename(lua_State *L, int t) +{ + UNUSED(L); + return lj_obj_typename[t+1]; +} + +LUA_API int lua_iscfunction(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return tvisfunc(o) && !isluafunc(funcV(o)); +} + +LUA_API int lua_isnumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + return (tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), &tmp))); +} + +LUA_API int lua_isstring(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (tvisstr(o) || tvisnumber(o)); +} + +LUA_API int lua_isuserdata(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (tvisudata(o) || tvislightud(o)); +} + +LUA_API int lua_rawequal(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + return (o1 == niltv(L) || o2 == niltv(L)) ? 0 : lj_obj_equal(o1, o2); +} + +LUA_API int lua_equal(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + if (tvisint(o1) && tvisint(o2)) { + return intV(o1) == intV(o2); + } else if (tvisnumber(o1) && tvisnumber(o2)) { + return numberVnum(o1) == numberVnum(o2); + } else if (itype(o1) != itype(o2)) { + return 0; + } else if (tvispri(o1)) { + return o1 != niltv(L) && o2 != niltv(L); +#if LJ_64 + } else if (tvislightud(o1)) { + return o1->u64 == o2->u64; +#endif + } else if (gcrefeq(o1->gcr, o2->gcr)) { + return 1; + } else if (!tvistabud(o1)) { + return 0; + } else { + TValue *base = lj_meta_equal(L, gcV(o1), gcV(o2), 0); + if ((uintptr_t)base <= 1) { + return (int)(uintptr_t)base; + } else { + L->top = base+2; + lj_vm_call(L, base, 1+1); + L->top -= 2; + return tvistruecond(L->top+1); + } + } +} + +LUA_API int lua_lessthan(lua_State *L, int idx1, int idx2) +{ + cTValue *o1 = index2adr(L, idx1); + cTValue *o2 = index2adr(L, idx2); + if (o1 == niltv(L) || o2 == niltv(L)) { + return 0; + } else if (tvisint(o1) && tvisint(o2)) { + return intV(o1) < intV(o2); + } else if (tvisnumber(o1) && tvisnumber(o2)) { + return numberVnum(o1) < numberVnum(o2); + } else { + TValue *base = lj_meta_comp(L, o1, o2, 0); + if ((uintptr_t)base <= 1) { + return (int)(uintptr_t)base; + } else { + L->top = base+2; + lj_vm_call(L, base, 1+1); + L->top -= 2; + return tvistruecond(L->top+1); + } + } +} + +LUA_API lua_Number lua_tonumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp)) + return numV(&tmp); + else + return 0; +} + +LUALIB_API lua_Number luaL_checknumber(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + return numV(&tmp); +} + +LUALIB_API lua_Number luaL_optnumber(lua_State *L, int idx, lua_Number def) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + if (LJ_LIKELY(tvisnumber(o))) + return numberVnum(o); + else if (tvisnil(o)) + return def; + else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + return numV(&tmp); +} + +LUA_API lua_Integer lua_tointeger(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + return 0; + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def) +{ + cTValue *o = index2adr(L, idx); + TValue tmp; + lua_Number n; + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else if (LJ_LIKELY(tvisnum(o))) { + n = numV(o); + } else if (tvisnil(o)) { + return def; + } else { + if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) + lj_err_argt(L, idx, LUA_TNUMBER); + if (tvisint(&tmp)) + return (lua_Integer)intV(&tmp); + n = numV(&tmp); + } +#if LJ_64 + return (lua_Integer)n; +#else + return lj_num2int(n); +#endif +} + +LUA_API int lua_toboolean(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return tvistruecond(o); +} + +LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + if (len != NULL) *len = 0; + return NULL; + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + lj_err_argt(L, idx, LUA_TSTRING); + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API const char *luaL_optlstring(lua_State *L, int idx, + const char *def, size_t *len) +{ + TValue *o = index2adr(L, idx); + GCstr *s; + if (LJ_LIKELY(tvisstr(o))) { + s = strV(o); + } else if (tvisnil(o)) { + if (len != NULL) *len = def ? strlen(def) : 0; + return def; + } else if (tvisnumber(o)) { + lj_gc_check(L); + o = index2adr(L, idx); /* GC may move the stack. */ + s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + } else { + lj_err_argt(L, idx, LUA_TSTRING); + } + if (len != NULL) *len = s->len; + return strdata(s); +} + +LUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def, + const char *const lst[]) +{ + ptrdiff_t i; + const char *s = lua_tolstring(L, idx, NULL); + if (s == NULL && (s = def) == NULL) + lj_err_argt(L, idx, LUA_TSTRING); + for (i = 0; lst[i]; i++) + if (strcmp(lst[i], s) == 0) + return (int)i; + lj_err_argv(L, idx, LJ_ERR_INVOPTM, s); +} + +LUA_API size_t lua_objlen(lua_State *L, int idx) +{ + TValue *o = index2adr(L, idx); + if (tvisstr(o)) { + return strV(o)->len; + } else if (tvistab(o)) { + return (size_t)lj_tab_len(tabV(o)); + } else if (tvisudata(o)) { + return udataV(o)->len; + } else if (tvisnumber(o)) { + GCstr *s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + return s->len; + } else { + return 0; + } +} + +LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisfunc(o)) { + BCOp op = bc_op(*mref(funcV(o)->c.pc, BCIns)); + if (op == BC_FUNCC || op == BC_FUNCCW) + return funcV(o)->c.f; + } + return NULL; +} + +LUA_API void *lua_touserdata(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) + return uddata(udataV(o)); + else if (tvislightud(o)) + return lightudV(o); + else + return NULL; +} + +LUA_API lua_State *lua_tothread(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + return (!tvisthread(o)) ? NULL : threadV(o); +} + +LUA_API const void *lua_topointer(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) + return uddata(udataV(o)); + else if (tvislightud(o)) + return lightudV(o); + else if (tviscdata(o)) + return cdataptr(cdataV(o)); + else if (tvisgcv(o)) + return gcV(o); + else + return NULL; +} + +/* -- Stack setters (object creation) ------------------------------------- */ + +LUA_API void lua_pushnil(lua_State *L) +{ + setnilV(L->top); + incr_top(L); +} + +LUA_API void lua_pushnumber(lua_State *L, lua_Number n) +{ + setnumV(L->top, n); + if (LJ_UNLIKELY(tvisnan(L->top))) + setnanV(L->top); /* Canonicalize injected NaNs. */ + incr_top(L); +} + +LUA_API void lua_pushinteger(lua_State *L, lua_Integer n) +{ + setintptrV(L->top, n); + incr_top(L); +} + +LUA_API void lua_pushlstring(lua_State *L, const char *str, size_t len) +{ + GCstr *s; + lj_gc_check(L); + s = lj_str_new(L, str, len); + setstrV(L, L->top, s); + incr_top(L); +} + +LUA_API void lua_pushstring(lua_State *L, const char *str) +{ + if (str == NULL) { + setnilV(L->top); + } else { + GCstr *s; + lj_gc_check(L); + s = lj_str_newz(L, str); + setstrV(L, L->top, s); + } + incr_top(L); +} + +LUA_API const char *lua_pushvfstring(lua_State *L, const char *fmt, + va_list argp) +{ + lj_gc_check(L); + return lj_str_pushvf(L, fmt, argp); +} + +LUA_API const char *lua_pushfstring(lua_State *L, const char *fmt, ...) +{ + const char *ret; + va_list argp; + lj_gc_check(L); + va_start(argp, fmt); + ret = lj_str_pushvf(L, fmt, argp); + va_end(argp); + return ret; +} + +LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction f, int n) +{ + GCfunc *fn; + lj_gc_check(L); + api_checknelems(L, n); + fn = lj_func_newC(L, (MSize)n, getcurrenv(L)); + fn->c.f = f; + L->top -= n; + while (n--) + copyTV(L, &fn->c.upvalue[n], L->top+n); + setfuncV(L, L->top, fn); + lua_assert(iswhite(obj2gco(fn))); + incr_top(L); +} + +LUA_API void lua_pushboolean(lua_State *L, int b) +{ + setboolV(L->top, (b != 0)); + incr_top(L); +} + +LUA_API void lua_pushlightuserdata(lua_State *L, void *p) +{ + setlightudV(L->top, checklightudptr(L, p)); + incr_top(L); +} + +LUA_API void lua_createtable(lua_State *L, int narray, int nrec) +{ + GCtab *t; + lj_gc_check(L); + t = lj_tab_new(L, (uint32_t)(narray > 0 ? narray+1 : 0), hsize2hbits(nrec)); + settabV(L, L->top, t); + incr_top(L); +} + +LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname) +{ + GCtab *regt = tabV(registry(L)); + TValue *tv = lj_tab_setstr(L, regt, lj_str_newz(L, tname)); + if (tvisnil(tv)) { + GCtab *mt = lj_tab_new(L, 0, 1); + settabV(L, tv, mt); + settabV(L, L->top++, mt); + lj_gc_anybarriert(L, regt); + return 1; + } else { + copyTV(L, L->top++, tv); + return 0; + } +} + +LUA_API int lua_pushthread(lua_State *L) +{ + setthreadV(L, L->top, L); + incr_top(L); + return (mainthread(G(L)) == L); +} + +LUA_API lua_State *lua_newthread(lua_State *L) +{ + lua_State *L1; + lj_gc_check(L); + L1 = lj_state_new(L); + setthreadV(L, L->top, L1); + incr_top(L); + return L1; +} + +LUA_API void *lua_newuserdata(lua_State *L, size_t size) +{ + GCudata *ud; + lj_gc_check(L); + if (size > LJ_MAX_UDATA) + lj_err_msg(L, LJ_ERR_UDATAOV); + ud = lj_udata_new(L, (MSize)size, getcurrenv(L)); + setudataV(L, L->top, ud); + incr_top(L); + return uddata(ud); +} + +LUA_API void lua_concat(lua_State *L, int n) +{ + api_checknelems(L, n); + if (n >= 2) { + n--; + do { + TValue *top = lj_meta_cat(L, L->top-1, -n); + if (top == NULL) { + L->top -= n; + break; + } + n -= (int)(L->top - top); + L->top = top+2; + lj_vm_call(L, top, 1+1); + L->top--; + copyTV(L, L->top-1, L->top); + } while (--n > 0); + } else if (n == 0) { /* Push empty string. */ + setstrV(L, L->top, &G(L)->strempty); + incr_top(L); + } + /* else n == 1: nothing to do. */ +} + +/* -- Object getters ------------------------------------------------------ */ + +LUA_API void lua_gettable(lua_State *L, int idx) +{ + cTValue *v, *t = index2adr(L, idx); + api_checkvalidindex(L, t); + v = lj_meta_tget(L, t, L->top-1); + if (v == NULL) { + L->top += 2; + lj_vm_call(L, L->top-2, 1+1); + L->top -= 2; + v = L->top+1; + } + copyTV(L, L->top-1, v); +} + +LUA_API void lua_getfield(lua_State *L, int idx, const char *k) +{ + cTValue *v, *t = index2adr(L, idx); + TValue key; + api_checkvalidindex(L, t); + setstrV(L, &key, lj_str_newz(L, k)); + v = lj_meta_tget(L, t, &key); + if (v == NULL) { + L->top += 2; + lj_vm_call(L, L->top-2, 1+1); + L->top -= 2; + v = L->top+1; + } + copyTV(L, L->top, v); + incr_top(L); +} + +LUA_API void lua_rawget(lua_State *L, int idx) +{ + cTValue *t = index2adr(L, idx); + api_check(L, tvistab(t)); + copyTV(L, L->top-1, lj_tab_get(L, tabV(t), L->top-1)); +} + +LUA_API void lua_rawgeti(lua_State *L, int idx, int n) +{ + cTValue *v, *t = index2adr(L, idx); + api_check(L, tvistab(t)); + v = lj_tab_getint(tabV(t), n); + if (v) { + copyTV(L, L->top, v); + } else { + setnilV(L->top); + } + incr_top(L); +} + +LUA_API int lua_getmetatable(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + GCtab *mt = NULL; + if (tvistab(o)) + mt = tabref(tabV(o)->metatable); + else if (tvisudata(o)) + mt = tabref(udataV(o)->metatable); + else + mt = tabref(basemt_obj(G(L), o)); + if (mt == NULL) + return 0; + settabV(L, L->top, mt); + incr_top(L); + return 1; +} + +LUALIB_API int luaL_getmetafield(lua_State *L, int idx, const char *field) +{ + if (lua_getmetatable(L, idx)) { + cTValue *tv = lj_tab_getstr(tabV(L->top-1), lj_str_newz(L, field)); + if (tv && !tvisnil(tv)) { + copyTV(L, L->top-1, tv); + return 1; + } + L->top--; + } + return 0; +} + +LUA_API void lua_getfenv(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (tvisfunc(o)) { + settabV(L, L->top, tabref(funcV(o)->c.env)); + } else if (tvisudata(o)) { + settabV(L, L->top, tabref(udataV(o)->env)); + } else if (tvisthread(o)) { + settabV(L, L->top, tabref(threadV(o)->env)); + } else { + setnilV(L->top); + } + incr_top(L); +} + +LUA_API int lua_next(lua_State *L, int idx) +{ + cTValue *t = index2adr(L, idx); + int more; + api_check(L, tvistab(t)); + more = lj_tab_next(L, tabV(t), L->top-1); + if (more) { + incr_top(L); /* Return new key and value slot. */ + } else { /* End of traversal. */ + L->top--; /* Remove key slot. */ + } + return more; +} + +LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) +{ + TValue *val; + const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val); + if (name) { + copyTV(L, L->top, val); + incr_top(L); + } + return name; +} + +LUA_API void *lua_upvalueid(lua_State *L, int idx, int n) +{ + GCfunc *fn = funcV(index2adr(L, idx)); + n--; + api_check(L, (uint32_t)n < fn->l.nupvalues); + return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : + (void *)&fn->c.upvalue[n]; +} + +LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2) +{ + GCfunc *fn1 = funcV(index2adr(L, idx1)); + GCfunc *fn2 = funcV(index2adr(L, idx2)); + n1--; n2--; + api_check(L, isluafunc(fn1) && (uint32_t)n1 < fn1->l.nupvalues); + api_check(L, isluafunc(fn2) && (uint32_t)n2 < fn2->l.nupvalues); + setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]); + lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1])); +} + +LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) +{ + cTValue *o = index2adr(L, idx); + if (tvisudata(o)) { + GCudata *ud = udataV(o); + cTValue *tv = lj_tab_getstr(tabV(registry(L)), lj_str_newz(L, tname)); + if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable)) + return uddata(ud); + } + lj_err_argtype(L, idx, tname); + return NULL; /* unreachable */ +} + +/* -- Object setters ------------------------------------------------------ */ + +LUA_API void lua_settable(lua_State *L, int idx) +{ + TValue *o; + cTValue *t = index2adr(L, idx); + api_checknelems(L, 2); + api_checkvalidindex(L, t); + o = lj_meta_tset(L, t, L->top-2); + if (o) { + /* NOBARRIER: lj_meta_tset ensures the table is not black. */ + copyTV(L, o, L->top-1); + L->top -= 2; + } else { + L->top += 3; + copyTV(L, L->top-1, L->top-6); + lj_vm_call(L, L->top-3, 0+1); + L->top -= 3; + } +} + +LUA_API void lua_setfield(lua_State *L, int idx, const char *k) +{ + TValue *o; + TValue key; + cTValue *t = index2adr(L, idx); + api_checknelems(L, 1); + api_checkvalidindex(L, t); + setstrV(L, &key, lj_str_newz(L, k)); + o = lj_meta_tset(L, t, &key); + if (o) { + L->top--; + /* NOBARRIER: lj_meta_tset ensures the table is not black. */ + copyTV(L, o, L->top); + } else { + L->top += 3; + copyTV(L, L->top-1, L->top-6); + lj_vm_call(L, L->top-3, 0+1); + L->top -= 2; + } +} + +LUA_API void lua_rawset(lua_State *L, int idx) +{ + GCtab *t = tabV(index2adr(L, idx)); + TValue *dst, *key; + api_checknelems(L, 2); + key = L->top-2; + dst = lj_tab_set(L, t, key); + copyTV(L, dst, key+1); + lj_gc_anybarriert(L, t); + L->top = key; +} + +LUA_API void lua_rawseti(lua_State *L, int idx, int n) +{ + GCtab *t = tabV(index2adr(L, idx)); + TValue *dst, *src; + api_checknelems(L, 1); + dst = lj_tab_setint(L, t, n); + src = L->top-1; + copyTV(L, dst, src); + lj_gc_barriert(L, t, dst); + L->top = src; +} + +LUA_API int lua_setmetatable(lua_State *L, int idx) +{ + global_State *g; + GCtab *mt; + cTValue *o = index2adr(L, idx); + api_checknelems(L, 1); + api_checkvalidindex(L, o); + if (tvisnil(L->top-1)) { + mt = NULL; + } else { + api_check(L, tvistab(L->top-1)); + mt = tabV(L->top-1); + } + g = G(L); + if (tvistab(o)) { + setgcref(tabV(o)->metatable, obj2gco(mt)); + if (mt) + lj_gc_objbarriert(L, tabV(o), mt); + } else if (tvisudata(o)) { + setgcref(udataV(o)->metatable, obj2gco(mt)); + if (mt) + lj_gc_objbarrier(L, udataV(o), mt); + } else { + /* Flush cache, since traces specialize to basemt. But not during __gc. */ + if (lj_trace_flushall(L)) + lj_err_caller(L, LJ_ERR_NOGCMM); + if (tvisbool(o)) { + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_it(g, LJ_TTRUE), obj2gco(mt)); + setgcref(basemt_it(g, LJ_TFALSE), obj2gco(mt)); + } else { + /* NOBARRIER: basemt is a GC root. */ + setgcref(basemt_obj(g, o), obj2gco(mt)); + } + } + L->top--; + return 1; +} + +LUA_API int lua_setfenv(lua_State *L, int idx) +{ + cTValue *o = index2adr(L, idx); + GCtab *t; + api_checknelems(L, 1); + api_checkvalidindex(L, o); + api_check(L, tvistab(L->top-1)); + t = tabV(L->top-1); + if (tvisfunc(o)) { + setgcref(funcV(o)->c.env, obj2gco(t)); + } else if (tvisudata(o)) { + setgcref(udataV(o)->env, obj2gco(t)); + } else if (tvisthread(o)) { + setgcref(threadV(o)->env, obj2gco(t)); + } else { + L->top--; + return 0; + } + lj_gc_objbarrier(L, gcV(o), t); + L->top--; + return 1; +} + +LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n) +{ + cTValue *f = index2adr(L, idx); + TValue *val; + const char *name; + api_checknelems(L, 1); + name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val); + if (name) { + L->top--; + copyTV(L, val, L->top); + lj_gc_barrier(L, funcV(f), L->top); + } + return name; +} + +/* -- Calls --------------------------------------------------------------- */ + +LUA_API void lua_call(lua_State *L, int nargs, int nresults) +{ + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + api_checknelems(L, nargs+1); + lj_vm_call(L, L->top - nargs, nresults+1); +} + +LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc) +{ + global_State *g = G(L); + uint8_t oldh = hook_save(g); + ptrdiff_t ef; + int status; + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + api_checknelems(L, nargs+1); + if (errfunc == 0) { + ef = 0; + } else { + cTValue *o = stkindex2adr(L, errfunc); + api_checkvalidindex(L, o); + ef = savestack(L, o); + } + status = lj_vm_pcall(L, L->top - nargs, nresults+1, ef); + if (status) hook_restore(g, oldh); + return status; +} + +static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud) +{ + GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L)); + fn->c.f = func; + setfuncV(L, L->top, fn); + setlightudV(L->top+1, checklightudptr(L, ud)); + cframe_nres(L->cframe) = 1+0; /* Zero results. */ + L->top += 2; + return L->top-1; /* Now call the newly allocated C function. */ +} + +LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud) +{ + global_State *g = G(L); + uint8_t oldh = hook_save(g); + int status; + api_check(L, L->status == 0 || L->status == LUA_ERRERR); + status = lj_vm_cpcall(L, func, ud, cpcall); + if (status) hook_restore(g, oldh); + return status; +} + +LUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field) +{ + if (luaL_getmetafield(L, idx, field)) { + TValue *base = L->top--; + copyTV(L, base, index2adr(L, idx)); + L->top = base+1; + lj_vm_call(L, base, 1+1); + return 1; + } + return 0; +} + +/* -- Coroutine yield and resume ------------------------------------------ */ + +LUA_API int lua_yield(lua_State *L, int nresults) +{ + void *cf = L->cframe; + global_State *g = G(L); + if (cframe_canyield(cf)) { + cf = cframe_raw(cf); + if (!hook_active(g)) { /* Regular yield: move results down if needed. */ + cTValue *f = L->top - nresults; + if (f > L->base) { + TValue *t = L->base; + while (--nresults >= 0) copyTV(L, t++, f++); + L->top = t; + } + L->cframe = NULL; + L->status = LUA_YIELD; + return -1; + } else { /* Yield from hook: add a pseudo-frame. */ + TValue *top = L->top; + hook_leave(g); + top->u64 = cframe_multres(cf); + setcont(top+1, lj_cont_hook); + setframe_pc(top+1, cframe_pc(cf)-1); + setframe_gc(top+2, obj2gco(L)); + setframe_ftsz(top+2, (int)((char *)(top+3)-(char *)L->base)+FRAME_CONT); + L->top = L->base = top+3; +#if LJ_TARGET_X64 + lj_err_throw(L, LUA_YIELD); +#else + L->cframe = NULL; + L->status = LUA_YIELD; + lj_vm_unwind_c(cf, LUA_YIELD); +#endif + } + } + lj_err_msg(L, LJ_ERR_CYIELD); + return 0; /* unreachable */ +} + +LUA_API int lua_resume(lua_State *L, int nargs) +{ + if (L->cframe == NULL && L->status <= LUA_YIELD) + return lj_vm_resume(L, L->top - nargs, 0, 0); + L->top = L->base; + setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP)); + incr_top(L); + return LUA_ERRRUN; +} + +/* -- GC and memory management -------------------------------------------- */ + +LUA_API int lua_gc(lua_State *L, int what, int data) +{ + global_State *g = G(L); + int res = 0; + switch (what) { + case LUA_GCSTOP: + g->gc.threshold = LJ_MAX_MEM; + break; + case LUA_GCRESTART: + g->gc.threshold = data == -1 ? (g->gc.total/100)*g->gc.pause : g->gc.total; + break; + case LUA_GCCOLLECT: + lj_gc_fullgc(L); + break; + case LUA_GCCOUNT: + res = (int)(g->gc.total >> 10); + break; + case LUA_GCCOUNTB: + res = (int)(g->gc.total & 0x3ff); + break; + case LUA_GCSTEP: { + MSize a = (MSize)data << 10; + g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0; + while (g->gc.total >= g->gc.threshold) + if (lj_gc_step(L) > 0) { + res = 1; + break; + } + break; + } + case LUA_GCSETPAUSE: + res = (int)(g->gc.pause); + g->gc.pause = (MSize)data; + break; + case LUA_GCSETSTEPMUL: + res = (int)(g->gc.stepmul); + g->gc.stepmul = (MSize)data; + break; + default: + res = -1; /* Invalid option. */ + } + return res; +} + +LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud) +{ + global_State *g = G(L); + if (ud) *ud = g->allocd; + return g->allocf; +} + +LUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud) +{ + global_State *g = G(L); + g->allocd = ud; + g->allocf = f; +} + +LUA_API int lua_setconstlist(lua_State *L, lua_const *constlist) +{ + L->constlist = constlist; + return 0; +} + +LUA_API void Lua_ReturnArray(lua_State *L,int Array[],int num) +{ +lua_newtable( L ); +int i; +for (i=0;i LUAJIT_OS_WINDOWS) +#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX + +#ifdef __CELLOS_LV2__ +#define LJ_TARGET_PS3 1 +#define LJ_TARGET_CONSOLE 1 +#endif + +#ifdef __ORBIS__ +#define LJ_TARGET_PS4 1 +#define LJ_TARGET_CONSOLE 1 +#undef NULL +#define NULL ((void*)0) +#endif + +#if _XBOX_VER >= 200 +#define LJ_TARGET_XBOX360 1 +#define LJ_TARGET_CONSOLE 1 +#endif + +#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */ +#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */ +#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */ +#define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */ + +/* Set target architecture properties. */ +#if LUAJIT_TARGET == LUAJIT_ARCH_X86 + +#define LJ_ARCH_NAME "x86" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#if LJ_TARGET_WINDOWS || __CYGWIN__ +#define LJ_ABI_WIN 1 +#else +#define LJ_ABI_WIN 0 +#endif +#define LJ_TARGET_X86 1 +#define LJ_TARGET_X86ORX64 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNALIGNED 1 +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL + +#elif LUAJIT_TARGET == LUAJIT_ARCH_X64 + +#define LJ_ARCH_NAME "x64" +#define LJ_ARCH_BITS 64 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#define LJ_ABI_WIN LJ_TARGET_WINDOWS +#define LJ_TARGET_X64 1 +#define LJ_TARGET_X86ORX64 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */ +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNALIGNED 1 +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL + +#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM + +#define LJ_ARCH_NAME "arm" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_LE +#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__ +#define LJ_ARCH_HASFPU 0 +#endif +#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP +#define LJ_ABI_SOFTFP 1 +#endif +#define LJ_ABI_EABI 1 +#define LJ_TARGET_ARM 1 +#define LJ_TARGET_EHRETREG 0 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL + +#if __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ +#define LJ_ARCH_VERSION 70 +#elif __ARM_ARCH_6T2__ +#define LJ_ARCH_VERSION 61 +#elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__ +#define LJ_ARCH_VERSION 60 +#else +#define LJ_ARCH_VERSION 50 +#endif + +#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC + +#define LJ_ARCH_NAME "ppc" +#if _LP64 +#define LJ_ARCH_BITS 64 +#else +#define LJ_ARCH_BITS 32 +#endif +#define LJ_ARCH_ENDIAN LUAJIT_BE +#define LJ_TARGET_PPC 1 +#define LJ_TARGET_EHRETREG 3 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE + +#if _ARCH_PWR7 +#define LJ_ARCH_VERSION 70 +#elif _ARCH_PWR6 +#define LJ_ARCH_VERSION 60 +#elif _ARCH_PWR5X +#define LJ_ARCH_VERSION 51 +#elif _ARCH_PWR5 +#define LJ_ARCH_VERSION 50 +#elif _ARCH_PWR4 +#define LJ_ARCH_VERSION 40 +#else +#define LJ_ARCH_VERSION 0 +#endif +#if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE +#define LJ_ARCH_PPC64 1 +#define LJ_ARCH_NOFFI 1 +#endif +#if _ARCH_PPCSQ +#define LJ_ARCH_SQRT 1 +#endif +#if _ARCH_PWR5X +#define LJ_ARCH_ROUND 1 +#endif +#if __PPU__ +#define LJ_ARCH_CELL 1 +#endif +#if LJ_TARGET_XBOX360 +#define LJ_ARCH_XENON 1 +#endif + +#elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE + +#define LJ_ARCH_NAME "ppcspe" +#define LJ_ARCH_BITS 32 +#define LJ_ARCH_ENDIAN LUAJIT_BE +#ifndef LJ_ABI_SOFTFP +#define LJ_ABI_SOFTFP 1 +#endif +#define LJ_ABI_EABI 1 +#define LJ_TARGET_PPCSPE 1 +#define LJ_TARGET_EHRETREG 3 +#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ +#define LJ_TARGET_MASKSHIFT 0 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE +#define LJ_ARCH_NOFFI 1 /* NYI: comparisons, calls. */ +#define LJ_ARCH_NOJIT 1 + +#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS + +#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) +#define LJ_ARCH_NAME "mipsel" +#define LJ_ARCH_ENDIAN LUAJIT_LE +#else +#define LJ_ARCH_NAME "mips" +#define LJ_ARCH_ENDIAN LUAJIT_BE +#endif +#define LJ_ARCH_BITS 32 +#define LJ_TARGET_MIPS 1 +#define LJ_TARGET_EHRETREG 4 +#define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */ +#define LJ_TARGET_MASKSHIFT 1 +#define LJ_TARGET_MASKROT 1 +#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ +#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE + +#if _MIPS_ARCH_MIPS32R2 +#define LJ_ARCH_VERSION 20 +#else +#define LJ_ARCH_VERSION 10 +#endif + +#else +#error "No target architecture defined" +#endif + +#ifndef LJ_PAGESIZE +#define LJ_PAGESIZE 4096 +#endif + +/* Check for minimum required compiler versions. */ +#if defined(__GNUC__) +#if LJ_TARGET_X86 +#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4) +#error "Need at least GCC 3.4 or newer" +#endif +#elif LJ_TARGET_X64 +#if __GNUC__ < 4 +#error "Need at least GCC 4.0 or newer" +#endif +#elif LJ_TARGET_ARM +#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2) +#error "Need at least GCC 4.2 or newer" +#endif +#elif !LJ_TARGET_PS3 +#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3) +#error "Need at least GCC 4.3 or newer" +#endif +#endif +#endif + +/* Check target-specific constraints. */ +#ifndef _BUILDVM_H +#if LJ_TARGET_X64 +#if __USING_SJLJ_EXCEPTIONS__ +#error "Need a C compiler with native exception handling on x64" +#endif +#elif LJ_TARGET_ARM +#if defined(__ARMEB__) +#error "No support for big-endian ARM" +#endif +#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ +#error "No support for Cortex-M CPUs" +#endif +#if !(__ARM_EABI__ || LJ_TARGET_IOS) +#error "Only ARM EABI or iOS 3.0+ ABI is supported" +#endif +#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE +#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE) +#error "No support for PowerPC CPUs without double-precision FPU" +#endif +#if defined(_LITTLE_ENDIAN) +#error "No support for little-endian PowerPC" +#endif +#if defined(_LP64) +#error "No support for PowerPC 64 bit mode" +#endif +#elif LJ_TARGET_MIPS +#if defined(__mips_soft_float) +#error "No support for MIPS CPUs without FPU" +#endif +#endif +#endif + +/* Enable or disable the dual-number mode for the VM. */ +#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1) +#error "No support for this number mode on this architecture" +#endif +#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \ + (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2) +#define LJ_DUALNUM 1 +#else +#define LJ_DUALNUM 0 +#endif + +#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE +/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */ +/* Ditto for the consoles. Complain to Sony or MS, not me. */ +#ifndef LUAJIT_ENABLE_JIT +#define LJ_OS_NOJIT 1 +#endif +#endif + +/* Disable or enable the JIT compiler. */ +#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT) +#define LJ_HASJIT 0 +#else +#define LJ_HASJIT 1 +#endif + +/* Disable or enable the FFI extension. */ +#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI) +#define LJ_HASFFI 0 +#else +#define LJ_HASFFI 1 +#endif + +#ifndef LJ_ARCH_HASFPU +#define LJ_ARCH_HASFPU 1 +#endif +#ifndef LJ_ABI_SOFTFP +#define LJ_ABI_SOFTFP 0 +#endif +#define LJ_SOFTFP (!LJ_ARCH_HASFPU) + +#if LJ_ARCH_ENDIAN == LUAJIT_BE +#define LJ_LE 0 +#define LJ_BE 1 +#define LJ_ENDIAN_SELECT(le, be) be +#define LJ_ENDIAN_LOHI(lo, hi) hi lo +#else +#define LJ_LE 1 +#define LJ_BE 0 +#define LJ_ENDIAN_SELECT(le, be) le +#define LJ_ENDIAN_LOHI(lo, hi) lo hi +#endif + +#if LJ_ARCH_BITS == 32 +#define LJ_32 1 +#define LJ_64 0 +#else +#define LJ_32 0 +#define LJ_64 1 +#endif + +#ifndef LJ_TARGET_UNALIGNED +#define LJ_TARGET_UNALIGNED 0 +#endif + +/* Various workarounds for embedded operating systems. */ +#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360 +#define LUAJIT_NO_LOG2 +#endif +#if defined(__symbian__) +#define LUAJIT_NO_EXP2 +#endif + +#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 +#define LJ_NO_UNWIND 1 +#endif + +/* Compatibility with Lua 5.1 vs. 5.2. */ +#ifdef LUAJIT_ENABLE_LUA52COMPAT +#define LJ_52 1 +#else +#define LJ_52 0 +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.c new file mode 100644 index 0000000..264649a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.c @@ -0,0 +1,1914 @@ +/* +** IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_asm_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_mcode.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_asm.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_target.h" + +#ifdef LUA_USE_ASSERT +#include +#endif + +/* -- Assembler state and common macros ----------------------------------- */ + +/* Assembler state. */ +typedef struct ASMState { + RegCost cost[RID_MAX]; /* Reference and blended allocation cost for regs. */ + + MCode *mcp; /* Current MCode pointer (grows down). */ + MCode *mclim; /* Lower limit for MCode memory + red zone. */ +#ifdef LUA_USE_ASSERT + MCode *mcp_prev; /* Red zone overflow check. */ +#endif + + IRIns *ir; /* Copy of pointer to IR instructions/constants. */ + jit_State *J; /* JIT compiler state. */ + +#if LJ_TARGET_X86ORX64 + x86ModRM mrm; /* Fused x86 address operand. */ +#endif + + RegSet freeset; /* Set of free registers. */ + RegSet modset; /* Set of registers modified inside the loop. */ + RegSet weakset; /* Set of weakly referenced registers. */ + RegSet phiset; /* Set of PHI registers. */ + + uint32_t flags; /* Copy of JIT compiler flags. */ + int loopinv; /* Loop branch inversion (0:no, 1:yes, 2:yes+CC_P). */ + + int32_t evenspill; /* Next even spill slot. */ + int32_t oddspill; /* Next odd spill slot (or 0). */ + + IRRef curins; /* Reference of current instruction. */ + IRRef stopins; /* Stop assembly before hitting this instruction. */ + IRRef orignins; /* Original T->nins. */ + + IRRef snapref; /* Current snapshot is active after this reference. */ + IRRef snaprename; /* Rename highwater mark for snapshot check. */ + SnapNo snapno; /* Current snapshot number. */ + SnapNo loopsnapno; /* Loop snapshot number. */ + + IRRef fuseref; /* Fusion limit (loopref, 0 or FUSE_DISABLED). */ + IRRef sectref; /* Section base reference (loopref or 0). */ + IRRef loopref; /* Reference of LOOP instruction (or 0). */ + + BCReg topslot; /* Number of slots for stack check (unless 0). */ + int32_t gcsteps; /* Accumulated number of GC steps (per section). */ + + GCtrace *T; /* Trace to assemble. */ + GCtrace *parent; /* Parent trace (or NULL). */ + + MCode *mcbot; /* Bottom of reserved MCode. */ + MCode *mctop; /* Top of generated MCode. */ + MCode *mcloop; /* Pointer to loop MCode (or NULL). */ + MCode *invmcp; /* Points to invertible loop branch (or NULL). */ + MCode *flagmcp; /* Pending opportunity to merge flag setting ins. */ + MCode *realign; /* Realign loop if not NULL. */ + +#ifdef RID_NUM_KREF + int32_t krefk[RID_NUM_KREF]; +#endif + IRRef1 phireg[RID_MAX]; /* PHI register references. */ + uint16_t parentmap[LJ_MAX_JSLOTS]; /* Parent instruction to RegSP map. */ +} ASMState; + +#define IR(ref) (&as->ir[(ref)]) + +#define ASMREF_TMP1 REF_TRUE /* Temp. register. */ +#define ASMREF_TMP2 REF_FALSE /* Temp. register. */ +#define ASMREF_L REF_NIL /* Stores register for L. */ + +/* Check for variant to invariant references. */ +#define iscrossref(as, ref) ((ref) < as->sectref) + +/* Inhibit memory op fusion from variant to invariant references. */ +#define FUSE_DISABLED (~(IRRef)0) +#define mayfuse(as, ref) ((ref) > as->fuseref) +#define neverfuse(as) (as->fuseref == FUSE_DISABLED) +#define canfuse(as, ir) (!neverfuse(as) && !irt_isphi((ir)->t)) +#define opisfusableload(o) \ + ((o) == IR_ALOAD || (o) == IR_HLOAD || (o) == IR_ULOAD || \ + (o) == IR_FLOAD || (o) == IR_XLOAD || (o) == IR_SLOAD || (o) == IR_VLOAD) + +/* Sparse limit checks using a red zone before the actual limit. */ +#define MCLIM_REDZONE 64 + +static LJ_NORET LJ_NOINLINE void asm_mclimit(ASMState *as) +{ + lj_mcode_limiterr(as->J, (size_t)(as->mctop - as->mcp + 4*MCLIM_REDZONE)); +} + +static LJ_AINLINE void checkmclim(ASMState *as) +{ +#ifdef LUA_USE_ASSERT + if (as->mcp + MCLIM_REDZONE < as->mcp_prev) { + IRIns *ir = IR(as->curins+1); + fprintf(stderr, "RED ZONE OVERFLOW: %p IR %04d %02d %04d %04d\n", as->mcp, + as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS); + lua_assert(0); + } +#endif + if (LJ_UNLIKELY(as->mcp < as->mclim)) asm_mclimit(as); +#ifdef LUA_USE_ASSERT + as->mcp_prev = as->mcp; +#endif +} + +#ifdef RID_NUM_KREF +#define ra_iskref(ref) ((ref) < RID_NUM_KREF) +#define ra_krefreg(ref) ((Reg)(RID_MIN_KREF + (Reg)(ref))) +#define ra_krefk(as, ref) (as->krefk[(ref)]) + +static LJ_AINLINE void ra_setkref(ASMState *as, Reg r, int32_t k) +{ + IRRef ref = (IRRef)(r - RID_MIN_KREF); + as->krefk[ref] = k; + as->cost[r] = REGCOST(ref, ref); +} + +#else +#define ra_iskref(ref) 0 +#define ra_krefreg(ref) RID_MIN_GPR +#define ra_krefk(as, ref) 0 +#endif + +/* Arch-specific field offsets. */ +static const uint8_t field_ofs[IRFL__MAX+1] = { +#define FLOFS(name, ofs) (uint8_t)(ofs), +IRFLDEF(FLOFS) +#undef FLOFS + 0 +}; + +/* -- Target-specific instruction emitter --------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_emit_x86.h" +#elif LJ_TARGET_ARM +#include "lj_emit_arm.h" +#elif LJ_TARGET_PPC +#include "lj_emit_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_emit_mips.h" +#else +#error "Missing instruction emitter for target CPU" +#endif + +/* -- Register allocator debugging ---------------------------------------- */ + +/* #define LUAJIT_DEBUG_RA */ + +#ifdef LUAJIT_DEBUG_RA + +#include +#include + +#define RIDNAME(name) #name, +static const char *const ra_regname[] = { + GPRDEF(RIDNAME) + FPRDEF(RIDNAME) + VRIDDEF(RIDNAME) + NULL +}; +#undef RIDNAME + +static char ra_dbg_buf[65536]; +static char *ra_dbg_p; +static char *ra_dbg_merge; +static MCode *ra_dbg_mcp; + +static void ra_dstart(void) +{ + ra_dbg_p = ra_dbg_buf; + ra_dbg_merge = NULL; + ra_dbg_mcp = NULL; +} + +static void ra_dflush(void) +{ + fwrite(ra_dbg_buf, 1, (size_t)(ra_dbg_p-ra_dbg_buf), stdout); + ra_dstart(); +} + +static void ra_dprintf(ASMState *as, const char *fmt, ...) +{ + char *p; + va_list argp; + va_start(argp, fmt); + p = ra_dbg_mcp == as->mcp ? ra_dbg_merge : ra_dbg_p; + ra_dbg_mcp = NULL; + p += sprintf(p, "%08x \e[36m%04d ", (uintptr_t)as->mcp, as->curins-REF_BIAS); + for (;;) { + const char *e = strchr(fmt, '$'); + if (e == NULL) break; + memcpy(p, fmt, (size_t)(e-fmt)); + p += e-fmt; + if (e[1] == 'r') { + Reg r = va_arg(argp, Reg) & RID_MASK; + if (r <= RID_MAX) { + const char *q; + for (q = ra_regname[r]; *q; q++) + *p++ = *q >= 'A' && *q <= 'Z' ? *q + 0x20 : *q; + } else { + *p++ = '?'; + lua_assert(0); + } + } else if (e[1] == 'f' || e[1] == 'i') { + IRRef ref; + if (e[1] == 'f') + ref = va_arg(argp, IRRef); + else + ref = va_arg(argp, IRIns *) - as->ir; + if (ref >= REF_BIAS) + p += sprintf(p, "%04d", ref - REF_BIAS); + else + p += sprintf(p, "K%03d", REF_BIAS - ref); + } else if (e[1] == 's') { + uint32_t slot = va_arg(argp, uint32_t); + p += sprintf(p, "[sp+0x%x]", sps_scale(slot)); + } else if (e[1] == 'x') { + p += sprintf(p, "%08x", va_arg(argp, int32_t)); + } else { + lua_assert(0); + } + fmt = e+2; + } + va_end(argp); + while (*fmt) + *p++ = *fmt++; + *p++ = '\e'; *p++ = '['; *p++ = 'm'; *p++ = '\n'; + if (p > ra_dbg_buf+sizeof(ra_dbg_buf)-256) { + fwrite(ra_dbg_buf, 1, (size_t)(p-ra_dbg_buf), stdout); + p = ra_dbg_buf; + } + ra_dbg_p = p; +} + +#define RA_DBG_START() ra_dstart() +#define RA_DBG_FLUSH() ra_dflush() +#define RA_DBG_REF() \ + do { char *_p = ra_dbg_p; ra_dprintf(as, ""); \ + ra_dbg_merge = _p; ra_dbg_mcp = as->mcp; } while (0) +#define RA_DBGX(x) ra_dprintf x + +#else +#define RA_DBG_START() ((void)0) +#define RA_DBG_FLUSH() ((void)0) +#define RA_DBG_REF() ((void)0) +#define RA_DBGX(x) ((void)0) +#endif + +/* -- Register allocator -------------------------------------------------- */ + +#define ra_free(as, r) rset_set(as->freeset, (r)) +#define ra_modified(as, r) rset_set(as->modset, (r)) +#define ra_weak(as, r) rset_set(as->weakset, (r)) +#define ra_noweak(as, r) rset_clear(as->weakset, (r)) + +#define ra_used(ir) (ra_hasreg((ir)->r) || ra_hasspill((ir)->s)) + +/* Setup register allocator. */ +static void ra_setup(ASMState *as) +{ + Reg r; + /* Initially all regs (except the stack pointer) are free for use. */ + as->freeset = RSET_INIT; + as->modset = RSET_EMPTY; + as->weakset = RSET_EMPTY; + as->phiset = RSET_EMPTY; + memset(as->phireg, 0, sizeof(as->phireg)); + for (r = RID_MIN_GPR; r < RID_MAX; r++) + as->cost[r] = REGCOST(~0u, 0u); +} + +/* Rematerialize constants. */ +static Reg ra_rematk(ASMState *as, IRRef ref) +{ + IRIns *ir; + Reg r; + if (ra_iskref(ref)) { + r = ra_krefreg(ref); + lua_assert(!rset_test(as->freeset, r)); + ra_free(as, r); + ra_modified(as, r); + emit_loadi(as, r, ra_krefk(as, ref)); + return r; + } + ir = IR(ref); + r = ir->r; + lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s)); + ra_free(as, r); + ra_modified(as, r); + ir->r = RID_INIT; /* Do not keep any hint. */ + RA_DBGX((as, "remat $i $r", ir, r)); +#if !LJ_SOFTFP + if (ir->o == IR_KNUM) { + emit_loadn(as, r, ir_knum(ir)); + } else +#endif + if (emit_canremat(REF_BASE) && ir->o == IR_BASE) { + ra_sethint(ir->r, RID_BASE); /* Restore BASE register hint. */ + emit_getgl(as, r, jit_base); + } else if (emit_canremat(ASMREF_L) && ir->o == IR_KPRI) { + lua_assert(irt_isnil(ir->t)); /* REF_NIL stores ASMREF_L register. */ + emit_getgl(as, r, jit_L); +#if LJ_64 + } else if (ir->o == IR_KINT64) { + emit_loadu64(as, r, ir_kint64(ir)->u64); +#endif + } else { + lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || + ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); + emit_loadi(as, r, ir->i); + } + return r; +} + +/* Force a spill. Allocate a new spill slot if needed. */ +static int32_t ra_spill(ASMState *as, IRIns *ir) +{ + int32_t slot = ir->s; + if (!ra_hasspill(slot)) { + if (irt_is64(ir->t)) { + slot = as->evenspill; + as->evenspill += 2; + } else if (as->oddspill) { + slot = as->oddspill; + as->oddspill = 0; + } else { + slot = as->evenspill; + as->oddspill = slot+1; + as->evenspill += 2; + } + if (as->evenspill > 256) + lj_trace_err(as->J, LJ_TRERR_SPILLOV); + ir->s = (uint8_t)slot; + } + return sps_scale(slot); +} + +/* Release the temporarily allocated register in ASMREF_TMP1/ASMREF_TMP2. */ +static Reg ra_releasetmp(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + Reg r = ir->r; + lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s)); + ra_free(as, r); + ra_modified(as, r); + ir->r = RID_INIT; + return r; +} + +/* Restore a register (marked as free). Rematerialize or force a spill. */ +static Reg ra_restore(ASMState *as, IRRef ref) +{ + if (emit_canremat(ref)) { + return ra_rematk(as, ref); + } else { + IRIns *ir = IR(ref); + int32_t ofs = ra_spill(as, ir); /* Force a spill slot. */ + Reg r = ir->r; + lua_assert(ra_hasreg(r)); + ra_sethint(ir->r, r); /* Keep hint. */ + ra_free(as, r); + if (!rset_test(as->weakset, r)) { /* Only restore non-weak references. */ + ra_modified(as, r); + RA_DBGX((as, "restore $i $r", ir, r)); + emit_spload(as, ir, r, ofs); + } + return r; + } +} + +/* Save a register to a spill slot. */ +static void ra_save(ASMState *as, IRIns *ir, Reg r) +{ + RA_DBGX((as, "save $i $r", ir, r)); + emit_spstore(as, ir, r, sps_scale(ir->s)); +} + +#define MINCOST(name) \ + if (rset_test(RSET_ALL, RID_##name) && \ + LJ_LIKELY(allow&RID2RSET(RID_##name)) && as->cost[RID_##name] < cost) \ + cost = as->cost[RID_##name]; + +/* Evict the register with the lowest cost, forcing a restore. */ +static Reg ra_evict(ASMState *as, RegSet allow) +{ + IRRef ref; + RegCost cost = ~(RegCost)0; + lua_assert(allow != RSET_EMPTY); + if (RID_NUM_FPR == 0 || allow < RID2RSET(RID_MAX_GPR)) { + GPRDEF(MINCOST) + } else { + FPRDEF(MINCOST) + } + ref = regcost_ref(cost); + lua_assert(ra_iskref(ref) || (ref >= as->T->nk && ref < as->T->nins)); + /* Preferably pick any weak ref instead of a non-weak, non-const ref. */ + if (!irref_isk(ref) && (as->weakset & allow)) { + IRIns *ir = IR(ref); + if (!rset_test(as->weakset, ir->r)) + ref = regcost_ref(as->cost[rset_pickbot((as->weakset & allow))]); + } + return ra_restore(as, ref); +} + +/* Pick any register (marked as free). Evict on-demand. */ +static Reg ra_pick(ASMState *as, RegSet allow) +{ + RegSet pick = as->freeset & allow; + if (!pick) + return ra_evict(as, allow); + else + return rset_picktop(pick); +} + +/* Get a scratch register (marked as free). */ +static Reg ra_scratch(ASMState *as, RegSet allow) +{ + Reg r = ra_pick(as, allow); + ra_modified(as, r); + RA_DBGX((as, "scratch $r", r)); + return r; +} + +/* Evict all registers from a set (if not free). */ +static void ra_evictset(ASMState *as, RegSet drop) +{ + RegSet work; + as->modset |= drop; +#if !LJ_SOFTFP + work = (drop & ~as->freeset) & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +#endif + work = (drop & ~as->freeset); + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +} + +/* Evict (rematerialize) all registers allocated to constants. */ +static void ra_evictk(ASMState *as) +{ + RegSet work; +#if !LJ_SOFTFP + work = ~as->freeset & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + if (emit_canremat(ref) && irref_isk(ref)) { + ra_rematk(as, ref); + checkmclim(as); + } + rset_clear(work, r); + } +#endif + work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + if (emit_canremat(ref) && irref_isk(ref)) { + ra_rematk(as, ref); + checkmclim(as); + } + rset_clear(work, r); + } +} + +#ifdef RID_NUM_KREF +/* Allocate a register for a constant. */ +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow) +{ + /* First try to find a register which already holds the same constant. */ + RegSet pick, work = ~as->freeset & RSET_GPR; + Reg r; + while (work) { + IRRef ref; + r = rset_pickbot(work); + ref = regcost_ref(as->cost[r]); + if (ref < ASMREF_L && + k == (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i)) + return r; + rset_clear(work, r); + } + pick = as->freeset & allow; + if (pick) { + /* Constants should preferably get unmodified registers. */ + if ((pick & ~as->modset)) + pick &= ~as->modset; + r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */ + } else { + r = ra_evict(as, allow); + } + RA_DBGX((as, "allock $x $r", k, r)); + ra_setkref(as, r, k); + rset_clear(as->freeset, r); + ra_noweak(as, r); + return r; +} + +/* Allocate a specific register for a constant. */ +static void ra_allockreg(ASMState *as, int32_t k, Reg r) +{ + Reg kr = ra_allock(as, k, RID2RSET(r)); + if (kr != r) { + IRIns irdummy; + irdummy.t.irt = IRT_INT; + ra_scratch(as, RID2RSET(r)); + emit_movrr(as, &irdummy, r, kr); + } +} +#else +#define ra_allockreg(as, k, r) emit_loadi(as, (r), (k)) +#endif + +/* Allocate a register for ref from the allowed set of registers. +** Note: this function assumes the ref does NOT have a register yet! +** Picks an optimal register, sets the cost and marks the register as non-free. +*/ +static Reg ra_allocref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + RegSet pick = as->freeset & allow; + Reg r; + lua_assert(ra_noreg(ir->r)); + if (pick) { + /* First check register hint from propagation or PHI. */ + if (ra_hashint(ir->r)) { + r = ra_gethint(ir->r); + if (rset_test(pick, r)) /* Use hint register if possible. */ + goto found; + /* Rematerialization is cheaper than missing a hint. */ + if (rset_test(allow, r) && emit_canremat(regcost_ref(as->cost[r]))) { + ra_rematk(as, regcost_ref(as->cost[r])); + goto found; + } + RA_DBGX((as, "hintmiss $f $r", ref, r)); + } + /* Invariants should preferably get unmodified registers. */ + if (ref < as->loopref && !irt_isphi(ir->t)) { + if ((pick & ~as->modset)) + pick &= ~as->modset; + r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */ + } else { + /* We've got plenty of regs, so get callee-save regs if possible. */ + if (RID_NUM_GPR > 8 && (pick & ~RSET_SCRATCH)) + pick &= ~RSET_SCRATCH; + r = rset_picktop(pick); + } + } else { + r = ra_evict(as, allow); + } +found: + RA_DBGX((as, "alloc $f $r", ref, r)); + ir->r = (uint8_t)r; + rset_clear(as->freeset, r); + ra_noweak(as, r); + as->cost[r] = REGCOST_REF_T(ref, irt_t(ir->t)); + return r; +} + +/* Allocate a register on-demand. */ +static Reg ra_alloc1(ASMState *as, IRRef ref, RegSet allow) +{ + Reg r = IR(ref)->r; + /* Note: allow is ignored if the register is already allocated. */ + if (ra_noreg(r)) r = ra_allocref(as, ref, allow); + ra_noweak(as, r); + return r; +} + +/* Rename register allocation and emit move. */ +static void ra_rename(ASMState *as, Reg down, Reg up) +{ + IRRef ren, ref = regcost_ref(as->cost[up] = as->cost[down]); + IRIns *ir = IR(ref); + ir->r = (uint8_t)up; + as->cost[down] = 0; + lua_assert((down < RID_MAX_GPR) == (up < RID_MAX_GPR)); + lua_assert(!rset_test(as->freeset, down) && rset_test(as->freeset, up)); + ra_free(as, down); /* 'down' is free ... */ + ra_modified(as, down); + rset_clear(as->freeset, up); /* ... and 'up' is now allocated. */ + ra_noweak(as, up); + RA_DBGX((as, "rename $f $r $r", regcost_ref(as->cost[up]), down, up)); + emit_movrr(as, ir, down, up); /* Backwards codegen needs inverse move. */ + if (!ra_hasspill(IR(ref)->s)) { /* Add the rename to the IR. */ + lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), ref, as->snapno); + ren = tref_ref(lj_ir_emit(as->J)); + as->ir = as->T->ir; /* The IR may have been reallocated. */ + IR(ren)->r = (uint8_t)down; + IR(ren)->s = SPS_NONE; + } +} + +/* Pick a destination register (marked as free). +** Caveat: allow is ignored if there's already a destination register. +** Use ra_destreg() to get a specific register. +*/ +static Reg ra_dest(ASMState *as, IRIns *ir, RegSet allow) +{ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + } else { + if (ra_hashint(dest) && rset_test((as->freeset&allow), ra_gethint(dest))) { + dest = ra_gethint(dest); + ra_modified(as, dest); + RA_DBGX((as, "dest $r", dest)); + } else { + dest = ra_scratch(as, allow); + } + ir->r = dest; + } + if (LJ_UNLIKELY(ra_hasspill(ir->s))) ra_save(as, ir, dest); + return dest; +} + +/* Force a specific destination register (marked as free). */ +static void ra_destreg(ASMState *as, IRIns *ir, Reg r) +{ + Reg dest = ra_dest(as, ir, RID2RSET(r)); + if (dest != r) { + lua_assert(rset_test(as->freeset, r)); + ra_modified(as, r); + emit_movrr(as, ir, dest, r); + } +} + +#if LJ_TARGET_X86ORX64 +/* Propagate dest register to left reference. Emit moves as needed. +** This is a required fixup step for all 2-operand machine instructions. +*/ +static void ra_left(ASMState *as, Reg dest, IRRef lref) +{ + IRIns *ir = IR(lref); + Reg left = ir->r; + if (ra_noreg(left)) { + if (irref_isk(lref)) { + if (ir->o == IR_KNUM) { + cTValue *tv = ir_knum(ir); + /* FP remat needs a load except for +0. Still better than eviction. */ + if (tvispzero(tv) || !(as->freeset & RSET_FPR)) { + emit_loadn(as, dest, tv); + return; + } +#if LJ_64 + } else if (ir->o == IR_KINT64) { + emit_loadu64(as, dest, ir_kint64(ir)->u64); + return; +#endif + } else { + lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || + ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); + emit_loadi(as, dest, ir->i); + return; + } + } + if (!ra_hashint(left) && !iscrossref(as, lref)) + ra_sethint(ir->r, dest); /* Propagate register hint. */ + left = ra_allocref(as, lref, dest < RID_MAX_GPR ? RSET_GPR : RSET_FPR); + } + ra_noweak(as, left); + /* Move needed for true 3-operand instruction: y=a+b ==> y=a; y+=b. */ + if (dest != left) { + /* Use register renaming if dest is the PHI reg. */ + if (irt_isphi(ir->t) && as->phireg[dest] == lref) { + ra_modified(as, left); + ra_rename(as, left, dest); + } else { + emit_movrr(as, ir, dest, left); + } + } +} +#else +/* Similar to ra_left, except we override any hints. */ +static void ra_leftov(ASMState *as, Reg dest, IRRef lref) +{ + IRIns *ir = IR(lref); + Reg left = ir->r; + if (ra_noreg(left)) { + ra_sethint(ir->r, dest); /* Propagate register hint. */ + left = ra_allocref(as, lref, + (LJ_SOFTFP || dest < RID_MAX_GPR) ? RSET_GPR : RSET_FPR); + } + ra_noweak(as, left); + if (dest != left) { + /* Use register renaming if dest is the PHI reg. */ + if (irt_isphi(ir->t) && as->phireg[dest] == lref) { + ra_modified(as, left); + ra_rename(as, left, dest); + } else { + emit_movrr(as, ir, dest, left); + } + } +} +#endif + +#if !LJ_64 +/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */ +static void ra_destpair(ASMState *as, IRIns *ir) +{ + Reg destlo = ir->r, desthi = (ir+1)->r; + /* First spill unrelated refs blocking the destination registers. */ + if (!rset_test(as->freeset, RID_RETLO) && + destlo != RID_RETLO && desthi != RID_RETLO) + ra_restore(as, regcost_ref(as->cost[RID_RETLO])); + if (!rset_test(as->freeset, RID_RETHI) && + destlo != RID_RETHI && desthi != RID_RETHI) + ra_restore(as, regcost_ref(as->cost[RID_RETHI])); + /* Next free the destination registers (if any). */ + if (ra_hasreg(destlo)) { + ra_free(as, destlo); + ra_modified(as, destlo); + } else { + destlo = RID_RETLO; + } + if (ra_hasreg(desthi)) { + ra_free(as, desthi); + ra_modified(as, desthi); + } else { + desthi = RID_RETHI; + } + /* Check for conflicts and shuffle the registers as needed. */ + if (destlo == RID_RETHI) { + if (desthi == RID_RETLO) { +#if LJ_TARGET_X86 + *--as->mcp = XI_XCHGa + RID_RETHI; +#else + emit_movrr(as, ir, RID_RETHI, RID_TMP); + emit_movrr(as, ir, RID_RETLO, RID_RETHI); + emit_movrr(as, ir, RID_TMP, RID_RETLO); +#endif + } else { + emit_movrr(as, ir, RID_RETHI, RID_RETLO); + if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI); + } + } else if (desthi == RID_RETLO) { + emit_movrr(as, ir, RID_RETLO, RID_RETHI); + if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO); + } else { + if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI); + if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO); + } + /* Restore spill slots (if any). */ + if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI); + if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO); +} +#endif + +/* -- Snapshot handling --------- ----------------------------------------- */ + +/* Can we rematerialize a KNUM instead of forcing a spill? */ +static int asm_snap_canremat(ASMState *as) +{ + Reg r; + for (r = RID_MIN_FPR; r < RID_MAX_FPR; r++) + if (irref_isk(regcost_ref(as->cost[r]))) + return 1; + return 0; +} + +/* Check whether a sunk store corresponds to an allocation. */ +static int asm_sunk_store(ASMState *as, IRIns *ira, IRIns *irs) +{ + if (irs->s == 255) { + if (irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE) { + IRIns *irk = IR(irs->op1); + if (irk->o == IR_AREF || irk->o == IR_HREFK) + irk = IR(irk->op1); + return (IR(irk->op1) == ira); + } + return 0; + } else { + return (ira + irs->s == irs); /* Quick check. */ + } +} + +/* Allocate register or spill slot for a ref that escapes to a snapshot. */ +static void asm_snap_alloc1(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (!irref_isk(ref) && (!(ra_used(ir) || ir->r == RID_SUNK))) { + if (ir->r == RID_SINK) { + ir->r = RID_SUNK; +#if LJ_HASFFI + if (ir->o == IR_CNEWI) { /* Allocate CNEWI value. */ + asm_snap_alloc1(as, ir->op2); + if (LJ_32 && (ir+1)->o == IR_HIOP) + asm_snap_alloc1(as, (ir+1)->op2); + } else +#endif + { /* Allocate stored values for TNEW, TDUP and CNEW. */ + IRIns *irs; + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW); + for (irs = IR(as->snapref-1); irs > ir; irs--) + if (irs->r == RID_SINK && asm_sunk_store(as, ir, irs)) { + lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE); + asm_snap_alloc1(as, irs->op2); + if (LJ_32 && (irs+1)->o == IR_HIOP) + asm_snap_alloc1(as, (irs+1)->op2); + } + } + } else { + RegSet allow; + if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) { + IRIns *irc; + for (irc = IR(as->curins); irc > ir; irc--) + if ((irc->op1 == ref || irc->op2 == ref) && + !(irc->r == RID_SINK || irc->r == RID_SUNK)) + goto nosink; /* Don't sink conversion if result is used. */ + asm_snap_alloc1(as, ir->op1); + return; + } + nosink: + allow = (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR; + if ((as->freeset & allow) || + (allow == RSET_FPR && asm_snap_canremat(as))) { + /* Get a weak register if we have a free one or can rematerialize. */ + Reg r = ra_allocref(as, ref, allow); /* Allocate a register. */ + if (!irt_isphi(ir->t)) + ra_weak(as, r); /* But mark it as weakly referenced. */ + checkmclim(as); + RA_DBGX((as, "snapreg $f $r", ref, ir->r)); + } else { + ra_spill(as, ir); /* Otherwise force a spill slot. */ + RA_DBGX((as, "snapspill $f $s", ref, ir->s)); + } + } + } +} + +/* Allocate refs escaping to a snapshot. */ +static void asm_snap_alloc(ASMState *as) +{ + SnapShot *snap = &as->T->snap[as->snapno]; + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef ref = snap_ref(sn); + if (!irref_isk(ref)) { + asm_snap_alloc1(as, ref); + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) { + lua_assert(irt_type(IR(ref+1)->t) == IRT_SOFTFP); + asm_snap_alloc1(as, ref+1); + } + } + } +} + +/* All guards for a snapshot use the same exitno. This is currently the +** same as the snapshot number. Since the exact origin of the exit cannot +** be determined, all guards for the same snapshot must exit with the same +** RegSP mapping. +** A renamed ref which has been used in a prior guard for the same snapshot +** would cause an inconsistency. The easy way out is to force a spill slot. +*/ +static int asm_snap_checkrename(ASMState *as, IRRef ren) +{ + SnapShot *snap = &as->T->snap[as->snapno]; + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef ref = snap_ref(sn); + if (ref == ren || (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && ++ref == ren)) { + IRIns *ir = IR(ref); + ra_spill(as, ir); /* Register renamed, so force a spill slot. */ + RA_DBGX((as, "snaprensp $f $s", ref, ir->s)); + return 1; /* Found. */ + } + } + return 0; /* Not found. */ +} + +/* Prepare snapshot for next guard instruction. */ +static void asm_snap_prep(ASMState *as) +{ + if (as->curins < as->snapref) { + do { + if (as->snapno == 0) return; /* Called by sunk stores before snap #0. */ + as->snapno--; + as->snapref = as->T->snap[as->snapno].ref; + } while (as->curins < as->snapref); + asm_snap_alloc(as); + as->snaprename = as->T->nins; + } else { + /* Process any renames above the highwater mark. */ + for (; as->snaprename < as->T->nins; as->snaprename++) { + IRIns *ir = IR(as->snaprename); + if (asm_snap_checkrename(as, ir->op1)) + ir->op2 = REF_BIAS-1; /* Kill rename. */ + } + } +} + +/* -- Miscellaneous helpers ----------------------------------------------- */ + +/* Collect arguments from CALL* and CARG instructions. */ +static void asm_collectargs(ASMState *as, IRIns *ir, + const CCallInfo *ci, IRRef *args) +{ + uint32_t n = CCI_NARGS(ci); + lua_assert(n <= CCI_NARGS_MAX*2); /* Account for split args. */ + if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; } + while (n-- > 1) { + ir = IR(ir->op1); + lua_assert(ir->o == IR_CARG); + args[n] = ir->op2 == REF_NIL ? 0 : ir->op2; + } + args[0] = ir->op1 == REF_NIL ? 0 : ir->op1; + lua_assert(IR(ir->op1)->o != IR_CARG); +} + +/* Reconstruct CCallInfo flags for CALLX*. */ +static uint32_t asm_callx_flags(ASMState *as, IRIns *ir) +{ + uint32_t nargs = 0; + if (ir->op1 != REF_NIL) { /* Count number of arguments first. */ + IRIns *ira = IR(ir->op1); + nargs++; + while (ira->o == IR_CARG) { nargs++; ira = IR(ira->op1); } + } +#if LJ_HASFFI + if (IR(ir->op2)->o == IR_CARG) { /* Copy calling convention info. */ + CTypeID id = (CTypeID)IR(IR(ir->op2)->op2)->i; + CType *ct = ctype_get(ctype_ctsG(J2G(as->J)), id); + nargs |= ((ct->info & CTF_VARARG) ? CCI_VARARG : 0); +#if LJ_TARGET_X86 + nargs |= (ctype_cconv(ct->info) << CCI_CC_SHIFT); +#endif + } +#endif + return (nargs | (ir->t.irt << CCI_OTSHIFT)); +} + +/* Calculate stack adjustment. */ +static int32_t asm_stack_adjust(ASMState *as) +{ + if (as->evenspill <= SPS_FIXED) + return 0; + return sps_scale(sps_align(as->evenspill)); +} + +/* Must match with hash*() in lj_tab.c. */ +static uint32_t ir_khash(IRIns *ir) +{ + uint32_t lo, hi; + if (irt_isstr(ir->t)) { + return ir_kstr(ir)->hash; + } else if (irt_isnum(ir->t)) { + lo = ir_knum(ir)->u32.lo; + hi = ir_knum(ir)->u32.hi << 1; + } else if (irt_ispri(ir->t)) { + lua_assert(!irt_isnil(ir->t)); + return irt_type(ir->t)-IRT_FALSE; + } else { + lua_assert(irt_isgcv(ir->t)); + lo = u32ptr(ir_kgc(ir)); + hi = lo + HASH_BIAS; + } + return hashrot(lo, hi); +} + +/* -- Allocations --------------------------------------------------------- */ + +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args); +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci); + +static void asm_snew(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_new]; + IRRef args[3]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* const char *str */ + args[2] = ir->op2; /* size_t len */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); +} + +static void asm_tnew(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_new1]; + IRRef args[2]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* uint32_t ahsize */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCtab * */ + asm_gencall(as, ci, args); + ra_allockreg(as, ir->op1 | (ir->op2 << 24), ra_releasetmp(as, ASMREF_TMP1)); +} + +static void asm_tdup(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_dup]; + IRRef args[2]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* const GCtab *kt */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCtab * */ + asm_gencall(as, ci, args); +} + +static void asm_gc_check(ASMState *as); + +/* Explicit GC step. */ +static void asm_gcstep(ASMState *as, IRIns *ir) +{ + IRIns *ira; + for (ira = IR(as->stopins+1); ira < ir; ira++) + if ((ira->o == IR_TNEW || ira->o == IR_TDUP || + (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI))) && + ra_used(ira)) + as->gcsteps++; + if (as->gcsteps) + asm_gc_check(as); + as->gcsteps = 0x80000000; /* Prevent implicit GC check further up. */ +} + +/* -- PHI and loop handling ----------------------------------------------- */ + +/* Break a PHI cycle by renaming to a free register (evict if needed). */ +static void asm_phi_break(ASMState *as, RegSet blocked, RegSet blockedby, + RegSet allow) +{ + RegSet candidates = blocked & allow; + if (candidates) { /* If this register file has candidates. */ + /* Note: the set for ra_pick cannot be empty, since each register file + ** has some registers never allocated to PHIs. + */ + Reg down, up = ra_pick(as, ~blocked & allow); /* Get a free register. */ + if (candidates & ~blockedby) /* Optimize shifts, else it's a cycle. */ + candidates = candidates & ~blockedby; + down = rset_picktop(candidates); /* Pick candidate PHI register. */ + ra_rename(as, down, up); /* And rename it to the free register. */ + } +} + +/* PHI register shuffling. +** +** The allocator tries hard to preserve PHI register assignments across +** the loop body. Most of the time this loop does nothing, since there +** are no register mismatches. +** +** If a register mismatch is detected and ... +** - the register is currently free: rename it. +** - the register is blocked by an invariant: restore/remat and rename it. +** - Otherwise the register is used by another PHI, so mark it as blocked. +** +** The renames are order-sensitive, so just retry the loop if a register +** is marked as blocked, but has been freed in the meantime. A cycle is +** detected if all of the blocked registers are allocated. To break the +** cycle rename one of them to a free register and retry. +** +** Note that PHI spill slots are kept in sync and don't need to be shuffled. +*/ +static void asm_phi_shuffle(ASMState *as) +{ + RegSet work; + + /* Find and resolve PHI register mismatches. */ + for (;;) { + RegSet blocked = RSET_EMPTY; + RegSet blockedby = RSET_EMPTY; + RegSet phiset = as->phiset; + while (phiset) { /* Check all left PHI operand registers. */ + Reg r = rset_pickbot(phiset); + IRIns *irl = IR(as->phireg[r]); + Reg left = irl->r; + if (r != left) { /* Mismatch? */ + if (!rset_test(as->freeset, r)) { /* PHI register blocked? */ + IRRef ref = regcost_ref(as->cost[r]); + /* Blocked by other PHI (w/reg)? */ + if (!ra_iskref(ref) && irt_ismarked(IR(ref)->t)) { + rset_set(blocked, r); + if (ra_hasreg(left)) + rset_set(blockedby, left); + left = RID_NONE; + } else { /* Otherwise grab register from invariant. */ + ra_restore(as, ref); + checkmclim(as); + } + } + if (ra_hasreg(left)) { + ra_rename(as, left, r); + checkmclim(as); + } + } + rset_clear(phiset, r); + } + if (!blocked) break; /* Finished. */ + if (!(as->freeset & blocked)) { /* Break cycles if none are free. */ + asm_phi_break(as, blocked, blockedby, RSET_GPR); + if (!LJ_SOFTFP) asm_phi_break(as, blocked, blockedby, RSET_FPR); + checkmclim(as); + } /* Else retry some more renames. */ + } + + /* Restore/remat invariants whose registers are modified inside the loop. */ +#if !LJ_SOFTFP + work = as->modset & ~(as->freeset | as->phiset) & RSET_FPR; + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } +#endif + work = as->modset & ~(as->freeset | as->phiset); + while (work) { + Reg r = rset_pickbot(work); + ra_restore(as, regcost_ref(as->cost[r])); + rset_clear(work, r); + checkmclim(as); + } + + /* Allocate and save all unsaved PHI regs and clear marks. */ + work = as->phiset; + while (work) { + Reg r = rset_picktop(work); + IRRef lref = as->phireg[r]; + IRIns *ir = IR(lref); + if (ra_hasspill(ir->s)) { /* Left PHI gained a spill slot? */ + irt_clearmark(ir->t); /* Handled here, so clear marker now. */ + ra_alloc1(as, lref, RID2RSET(r)); + ra_save(as, ir, r); /* Save to spill slot inside the loop. */ + checkmclim(as); + } + rset_clear(work, r); + } +} + +/* Copy unsynced left/right PHI spill slots. Rarely needed. */ +static void asm_phi_copyspill(ASMState *as) +{ + int need = 0; + IRIns *ir; + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) + if (ra_hasspill(ir->s) && ra_hasspill(IR(ir->op1)->s)) + need |= irt_isfp(ir->t) ? 2 : 1; /* Unsynced spill slot? */ + if ((need & 1)) { /* Copy integer spill slots. */ +#if !LJ_TARGET_X86ORX64 + Reg r = RID_TMP; +#else + Reg r = RID_RET; + if ((as->freeset & RSET_GPR)) + r = rset_pickbot((as->freeset & RSET_GPR)); + else + emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); +#endif + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) { + if (ra_hasspill(ir->s)) { + IRIns *irl = IR(ir->op1); + if (ra_hasspill(irl->s) && !irt_isfp(ir->t)) { + emit_spstore(as, irl, r, sps_scale(irl->s)); + emit_spload(as, ir, r, sps_scale(ir->s)); + checkmclim(as); + } + } + } +#if LJ_TARGET_X86ORX64 + if (!rset_test(as->freeset, r)) + emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); +#endif + } +#if !LJ_SOFTFP + if ((need & 2)) { /* Copy FP spill slots. */ +#if LJ_TARGET_X86 + Reg r = RID_XMM0; +#else + Reg r = RID_FPRET; +#endif + if ((as->freeset & RSET_FPR)) + r = rset_pickbot((as->freeset & RSET_FPR)); + if (!rset_test(as->freeset, r)) + emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); + for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) { + if (ra_hasspill(ir->s)) { + IRIns *irl = IR(ir->op1); + if (ra_hasspill(irl->s) && irt_isfp(ir->t)) { + emit_spstore(as, irl, r, sps_scale(irl->s)); + emit_spload(as, ir, r, sps_scale(ir->s)); + checkmclim(as); + } + } + } + if (!rset_test(as->freeset, r)) + emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP); + } +#endif +} + +/* Emit renames for left PHIs which are only spilled outside the loop. */ +static void asm_phi_fixup(ASMState *as) +{ + RegSet work = as->phiset; + while (work) { + Reg r = rset_picktop(work); + IRRef lref = as->phireg[r]; + IRIns *ir = IR(lref); + if (irt_ismarked(ir->t)) { + irt_clearmark(ir->t); + /* Left PHI gained a spill slot before the loop? */ + if (ra_hasspill(ir->s)) { + IRRef ren; + lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), lref, as->loopsnapno); + ren = tref_ref(lj_ir_emit(as->J)); + as->ir = as->T->ir; /* The IR may have been reallocated. */ + IR(ren)->r = (uint8_t)r; + IR(ren)->s = SPS_NONE; + } + } + rset_clear(work, r); + } +} + +/* Setup right PHI reference. */ +static void asm_phi(ASMState *as, IRIns *ir) +{ + RegSet allow = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & + ~as->phiset; + RegSet afree = (as->freeset & allow); + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + if (ir->r == RID_SINK) /* Sink PHI. */ + return; + /* Spill slot shuffling is not implemented yet (but rarely needed). */ + if (ra_hasspill(irl->s) || ra_hasspill(irr->s)) + lj_trace_err(as->J, LJ_TRERR_NYIPHI); + /* Leave at least one register free for non-PHIs (and PHI cycle breaking). */ + if ((afree & (afree-1))) { /* Two or more free registers? */ + Reg r; + if (ra_noreg(irr->r)) { /* Get a register for the right PHI. */ + r = ra_allocref(as, ir->op2, allow); + } else { /* Duplicate right PHI, need a copy (rare). */ + r = ra_scratch(as, allow); + emit_movrr(as, irr, r, irr->r); + } + ir->r = (uint8_t)r; + rset_set(as->phiset, r); + as->phireg[r] = (IRRef1)ir->op1; + irt_setmark(irl->t); /* Marks left PHIs _with_ register. */ + if (ra_noreg(irl->r)) + ra_sethint(irl->r, r); /* Set register hint for left PHI. */ + } else { /* Otherwise allocate a spill slot. */ + /* This is overly restrictive, but it triggers only on synthetic code. */ + if (ra_hasreg(irl->r) || ra_hasreg(irr->r)) + lj_trace_err(as->J, LJ_TRERR_NYIPHI); + ra_spill(as, ir); + irr->s = ir->s; /* Set right PHI spill slot. Sync left slot later. */ + } +} + +static void asm_loop_fixup(ASMState *as); + +/* Middle part of a loop. */ +static void asm_loop(ASMState *as) +{ + MCode *mcspill; + /* LOOP is a guard, so the snapno is up to date. */ + as->loopsnapno = as->snapno; + if (as->gcsteps) + asm_gc_check(as); + /* LOOP marks the transition from the variant to the invariant part. */ + as->flagmcp = as->invmcp = NULL; + as->sectref = 0; + if (!neverfuse(as)) as->fuseref = 0; + asm_phi_shuffle(as); + mcspill = as->mcp; + asm_phi_copyspill(as); + asm_loop_fixup(as); + as->mcloop = as->mcp; + RA_DBGX((as, "===== LOOP =====")); + if (!as->realign) RA_DBG_FLUSH(); + if (as->mcp != mcspill) + emit_jmp(as, mcspill); +} + +/* -- Target-specific assembler ------------------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_asm_x86.h" +#elif LJ_TARGET_ARM +#include "lj_asm_arm.h" +#elif LJ_TARGET_PPC +#include "lj_asm_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_asm_mips.h" +#else +#error "Missing assembler for target CPU" +#endif + +/* -- Head of trace ------------------------------------------------------- */ + +/* Head of a root trace. */ +static void asm_head_root(ASMState *as) +{ + int32_t spadj; + asm_head_root_base(as); + emit_setvmstate(as, (int32_t)as->T->traceno); + spadj = asm_stack_adjust(as); + as->T->spadjust = (uint16_t)spadj; + emit_spsub(as, spadj); + /* Root traces assume a checked stack for the starting proto. */ + as->T->topslot = gcref(as->T->startpt)->pt.framesize; +} + +/* Head of a side trace. +** +** The current simplistic algorithm requires that all slots inherited +** from the parent are live in a register between pass 2 and pass 3. This +** avoids the complexity of stack slot shuffling. But of course this may +** overflow the register set in some cases and cause the dreaded error: +** "NYI: register coalescing too complex". A refined algorithm is needed. +*/ +static void asm_head_side(ASMState *as) +{ + IRRef1 sloadins[RID_MAX]; + RegSet allow = RSET_ALL; /* Inverse of all coalesced registers. */ + RegSet live = RSET_EMPTY; /* Live parent registers. */ + IRIns *irp = &as->parent->ir[REF_BASE]; /* Parent base. */ + int32_t spadj, spdelta; + int pass2 = 0; + int pass3 = 0; + IRRef i; + + allow = asm_head_side_base(as, irp, allow); + + /* Scan all parent SLOADs and collect register dependencies. */ + for (i = as->stopins; i > REF_BASE; i--) { + IRIns *ir = IR(i); + RegSP rs; + lua_assert((ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_PARENT)) || + (LJ_SOFTFP && ir->o == IR_HIOP) || ir->o == IR_PVAL); + rs = as->parentmap[i - REF_FIRST]; + if (ra_hasreg(ir->r)) { + rset_clear(allow, ir->r); + if (ra_hasspill(ir->s)) { + ra_save(as, ir, ir->r); + checkmclim(as); + } + } else if (ra_hasspill(ir->s)) { + irt_setmark(ir->t); + pass2 = 1; + } + if (ir->r == rs) { /* Coalesce matching registers right now. */ + ra_free(as, ir->r); + } else if (ra_hasspill(regsp_spill(rs))) { + if (ra_hasreg(ir->r)) + pass3 = 1; + } else if (ra_used(ir)) { + sloadins[rs] = (IRRef1)i; + rset_set(live, rs); /* Block live parent register. */ + } + } + + /* Calculate stack frame adjustment. */ + spadj = asm_stack_adjust(as); + spdelta = spadj - (int32_t)as->parent->spadjust; + if (spdelta < 0) { /* Don't shrink the stack frame. */ + spadj = (int32_t)as->parent->spadjust; + spdelta = 0; + } + as->T->spadjust = (uint16_t)spadj; + + /* Reload spilled target registers. */ + if (pass2) { + for (i = as->stopins; i > REF_BASE; i--) { + IRIns *ir = IR(i); + if (irt_ismarked(ir->t)) { + RegSet mask; + Reg r; + RegSP rs; + irt_clearmark(ir->t); + rs = as->parentmap[i - REF_FIRST]; + if (!ra_hasspill(regsp_spill(rs))) + ra_sethint(ir->r, rs); /* Hint may be gone, set it again. */ + else if (sps_scale(regsp_spill(rs))+spdelta == sps_scale(ir->s)) + continue; /* Same spill slot, do nothing. */ + mask = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & allow; + if (mask == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + r = ra_allocref(as, i, mask); + ra_save(as, ir, r); + rset_clear(allow, r); + if (r == rs) { /* Coalesce matching registers right now. */ + ra_free(as, r); + rset_clear(live, r); + } else if (ra_hasspill(regsp_spill(rs))) { + pass3 = 1; + } + checkmclim(as); + } + } + } + + /* Store trace number and adjust stack frame relative to the parent. */ + emit_setvmstate(as, (int32_t)as->T->traceno); + emit_spsub(as, spdelta); + +#if !LJ_TARGET_X86ORX64 + /* Restore BASE register from parent spill slot. */ + if (ra_hasspill(irp->s)) + emit_spload(as, IR(REF_BASE), IR(REF_BASE)->r, sps_scale(irp->s)); +#endif + + /* Restore target registers from parent spill slots. */ + if (pass3) { + RegSet work = ~as->freeset & RSET_ALL; + while (work) { + Reg r = rset_pickbot(work); + IRRef ref = regcost_ref(as->cost[r]); + RegSP rs = as->parentmap[ref - REF_FIRST]; + rset_clear(work, r); + if (ra_hasspill(regsp_spill(rs))) { + int32_t ofs = sps_scale(regsp_spill(rs)); + ra_free(as, r); + emit_spload(as, IR(ref), r, ofs); + checkmclim(as); + } + } + } + + /* Shuffle registers to match up target regs with parent regs. */ + for (;;) { + RegSet work; + + /* Repeatedly coalesce free live registers by moving to their target. */ + while ((work = as->freeset & live) != RSET_EMPTY) { + Reg rp = rset_pickbot(work); + IRIns *ir = IR(sloadins[rp]); + rset_clear(live, rp); + rset_clear(allow, rp); + ra_free(as, ir->r); + emit_movrr(as, ir, ir->r, rp); + checkmclim(as); + } + + /* We're done if no live registers remain. */ + if (live == RSET_EMPTY) + break; + + /* Break cycles by renaming one target to a temp. register. */ + if (live & RSET_GPR) { + RegSet tmpset = as->freeset & ~live & allow & RSET_GPR; + if (tmpset == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + ra_rename(as, rset_pickbot(live & RSET_GPR), rset_pickbot(tmpset)); + } + if (!LJ_SOFTFP && (live & RSET_FPR)) { + RegSet tmpset = as->freeset & ~live & allow & RSET_FPR; + if (tmpset == RSET_EMPTY) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + ra_rename(as, rset_pickbot(live & RSET_FPR), rset_pickbot(tmpset)); + } + checkmclim(as); + /* Continue with coalescing to fix up the broken cycle(s). */ + } + + /* Inherit top stack slot already checked by parent trace. */ + as->T->topslot = as->parent->topslot; + if (as->topslot > as->T->topslot) { /* Need to check for higher slot? */ +#ifdef EXITSTATE_CHECKEXIT + /* Highest exit + 1 indicates stack check. */ + ExitNo exitno = as->T->nsnap; +#else + /* Reuse the parent exit in the context of the parent trace. */ + ExitNo exitno = as->J->exitno; +#endif + as->T->topslot = (uint8_t)as->topslot; /* Remember for child traces. */ + asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno); + } +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Get base slot for a snapshot. */ +static BCReg asm_baseslot(ASMState *as, SnapShot *snap, int *gotframe) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + MSize n; + for (n = snap->nent; n > 0; n--) { + SnapEntry sn = map[n-1]; + if ((sn & SNAP_FRAME)) { + *gotframe = 1; + return snap_slot(sn); + } + } + return 0; +} + +/* Link to another trace. */ +static void asm_tail_link(ASMState *as) +{ + SnapNo snapno = as->T->nsnap-1; /* Last snapshot. */ + SnapShot *snap = &as->T->snap[snapno]; + int gotframe = 0; + BCReg baseslot = asm_baseslot(as, snap, &gotframe); + + as->topslot = snap->topslot; + checkmclim(as); + ra_allocref(as, REF_BASE, RID2RSET(RID_BASE)); + + if (as->T->link == 0) { + /* Setup fixed registers for exit to interpreter. */ + const BCIns *pc = snap_pc(as->T->snapmap[snap->mapofs + snap->nent]); + int32_t mres; + if (bc_op(*pc) == BC_JLOOP) { /* NYI: find a better way to do this. */ + BCIns *retpc = &traceref(as->J, bc_d(*pc))->startins; + if (bc_isret(bc_op(*retpc))) + pc = retpc; + } + ra_allockreg(as, i32ptr(J2GG(as->J)->dispatch), RID_DISPATCH); + ra_allockreg(as, i32ptr(pc), RID_LPC); + mres = (int32_t)(snap->nslots - baseslot); + switch (bc_op(*pc)) { + case BC_CALLM: case BC_CALLMT: + mres -= (int32_t)(1 + bc_a(*pc) + bc_c(*pc)); break; + case BC_RETM: mres -= (int32_t)(bc_a(*pc) + bc_d(*pc)); break; + case BC_TSETM: mres -= (int32_t)bc_a(*pc); break; + default: if (bc_op(*pc) < BC_FUNCF) mres = 0; break; + } + ra_allockreg(as, mres, RID_RET); /* Return MULTRES or 0. */ + } else if (baseslot) { + /* Save modified BASE for linking to trace with higher start frame. */ + emit_setgl(as, RID_BASE, jit_base); + } + emit_addptr(as, RID_BASE, 8*(int32_t)baseslot); + + /* Sync the interpreter state with the on-trace state. */ + asm_stack_restore(as, snap); + + /* Root traces that add frames need to check the stack at the end. */ + if (!as->parent && gotframe) + asm_stack_check(as, as->topslot, NULL, as->freeset & RSET_GPR, snapno); +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Clear reg/sp for all instructions and add register hints. */ +static void asm_setup_regsp(ASMState *as) +{ + GCtrace *T = as->T; + int sink = T->sinktags; + IRRef nins = T->nins; + IRIns *ir, *lastir; + int inloop; +#if LJ_TARGET_ARM + uint32_t rload = 0xa6402a64; +#endif + + ra_setup(as); + + /* Clear reg/sp for constants. */ + for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++) + ir->prev = REGSP_INIT; + + /* REF_BASE is used for implicit references to the BASE register. */ + lastir->prev = REGSP_HINT(RID_BASE); + + ir = IR(nins-1); + if (ir->o == IR_RENAME) { + do { ir--; nins--; } while (ir->o == IR_RENAME); + T->nins = nins; /* Remove any renames left over from ASM restart. */ + } + as->snaprename = nins; + as->snapref = nins; + as->snapno = T->nsnap; + + as->stopins = REF_BASE; + as->orignins = nins; + as->curins = nins; + + /* Setup register hints for parent link instructions. */ + ir = IR(REF_FIRST); + if (as->parent) { + uint16_t *p; + lastir = lj_snap_regspmap(as->parent, as->J->exitno, ir); + if (lastir - ir > LJ_MAX_JSLOTS) + lj_trace_err(as->J, LJ_TRERR_NYICOAL); + as->stopins = (IRRef)((lastir-1) - as->ir); + for (p = as->parentmap; ir < lastir; ir++) { + RegSP rs = ir->prev; + *p++ = (uint16_t)rs; /* Copy original parent RegSP to parentmap. */ + if (!ra_hasspill(regsp_spill(rs))) + ir->prev = (uint16_t)REGSP_HINT(regsp_reg(rs)); + else + ir->prev = REGSP_INIT; + } + } + + inloop = 0; + as->evenspill = SPS_FIRST; + for (lastir = IR(nins); ir < lastir; ir++) { + if (sink) { + if (ir->r == RID_SINK) + continue; + if (ir->r == RID_SUNK) { /* Revert after ASM restart. */ + ir->r = RID_SINK; + continue; + } + } + switch (ir->o) { + case IR_LOOP: + inloop = 1; + break; +#if LJ_TARGET_ARM + case IR_SLOAD: + if (!((ir->op2 & IRSLOAD_TYPECHECK) || (ir+1)->o == IR_HIOP)) + break; + /* fallthrough */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + if (!LJ_SOFTFP && irt_isnum(ir->t)) break; + ir->prev = (uint16_t)REGSP_HINT((rload & 15)); + rload = lj_ror(rload, 4); + continue; +#endif + case IR_CALLXS: { + CCallInfo ci; + ci.flags = asm_callx_flags(as, ir); + ir->prev = asm_setup_call_slots(as, ir, &ci); + if (inloop) + as->modset |= RSET_SCRATCH; + continue; + } + case IR_CALLN: case IR_CALLL: case IR_CALLS: { + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + ir->prev = asm_setup_call_slots(as, ir, ci); + if (inloop) + as->modset |= (ci->flags & CCI_NOFPRCLOBBER) ? + (RSET_SCRATCH & ~RSET_FPR) : RSET_SCRATCH; + continue; + } +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) + case IR_HIOP: + switch ((ir-1)->o) { +#if LJ_SOFTFP && LJ_TARGET_ARM + case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + if (ra_hashint((ir-1)->r)) { + ir->prev = (ir-1)->prev + 1; + continue; + } + break; +#endif +#if !LJ_SOFTFP && LJ_NEED_FP64 + case IR_CONV: + if (irt_isfp((ir-1)->t)) { + ir->prev = REGSP_HINT(RID_FPRET); + continue; + } + /* fallthrough */ +#endif + case IR_CALLN: case IR_CALLXS: +#if LJ_SOFTFP + case IR_MIN: case IR_MAX: +#endif + (ir-1)->prev = REGSP_HINT(RID_RETLO); + ir->prev = REGSP_HINT(RID_RETHI); + continue; + default: + break; + } + break; +#endif +#if LJ_SOFTFP + case IR_MIN: case IR_MAX: + if ((ir+1)->o != IR_HIOP) break; + /* fallthrough */ +#endif + /* C calls evict all scratch regs and return results in RID_RET. */ + case IR_SNEW: case IR_XSNEW: case IR_NEWREF: + if (REGARG_NUMGPR < 3 && as->evenspill < 3) + as->evenspill = 3; /* lj_str_new and lj_tab_newkey need 3 args. */ + case IR_TNEW: case IR_TDUP: case IR_CNEW: case IR_CNEWI: case IR_TOSTR: + ir->prev = REGSP_HINT(RID_RET); + if (inloop) + as->modset = RSET_SCRATCH; + continue; + case IR_STRTO: case IR_OBAR: + if (inloop) + as->modset = RSET_SCRATCH; + break; +#if !LJ_TARGET_X86ORX64 && !LJ_SOFTFP + case IR_ATAN2: case IR_LDEXP: +#endif + case IR_POW: + if (!LJ_SOFTFP && irt_isnum(ir->t)) { +#if LJ_TARGET_X86ORX64 + ir->prev = REGSP_HINT(RID_XMM0); + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX); +#else + ir->prev = REGSP_HINT(RID_FPRET); + if (inloop) + as->modset |= RSET_SCRATCH; +#endif + continue; + } + /* fallthrough for integer POW */ + case IR_DIV: case IR_MOD: + if (!irt_isnum(ir->t)) { + ir->prev = REGSP_HINT(RID_RET); + if (inloop) + as->modset |= (RSET_SCRATCH & RSET_GPR); + continue; + } + break; + case IR_FPMATH: +#if LJ_TARGET_X86ORX64 + if (ir->op2 == IRFPM_EXP2) { /* May be joined to lj_vm_pow_sse. */ + ir->prev = REGSP_HINT(RID_XMM0); +#if !LJ_64 + if (as->evenspill < 4) /* Leave room for 16 byte scratch area. */ + as->evenspill = 4; +#endif + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX); + continue; + } else if (ir->op2 <= IRFPM_TRUNC && !(as->flags & JIT_F_SSE4_1)) { + ir->prev = REGSP_HINT(RID_XMM0); + if (inloop) + as->modset |= RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX); + continue; + } + break; +#else + ir->prev = REGSP_HINT(RID_FPRET); + if (inloop) + as->modset |= RSET_SCRATCH; + continue; +#endif +#if LJ_TARGET_X86ORX64 + /* Non-constant shift counts need to be in RID_ECX on x86/x64. */ + case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR: + if (!irref_isk(ir->op2) && !ra_hashint(IR(ir->op2)->r)) { + IR(ir->op2)->r = REGSP_HINT(RID_ECX); + if (inloop) + rset_set(as->modset, RID_ECX); + } + break; +#endif + /* Do not propagate hints across type conversions or loads. */ + case IR_TOBIT: + case IR_XLOAD: +#if !LJ_TARGET_ARM + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: +#endif + break; + case IR_CONV: + if (irt_isfp(ir->t) || (ir->op2 & IRCONV_SRCMASK) == IRT_NUM || + (ir->op2 & IRCONV_SRCMASK) == IRT_FLOAT) + break; + /* fallthrough */ + default: + /* Propagate hints across likely 'op reg, imm' or 'op reg'. */ + if (irref_isk(ir->op2) && !irref_isk(ir->op1) && + ra_hashint(regsp_reg(IR(ir->op1)->prev))) { + ir->prev = IR(ir->op1)->prev; + continue; + } + break; + } + ir->prev = REGSP_INIT; + } + if ((as->evenspill & 1)) + as->oddspill = as->evenspill++; + else + as->oddspill = 0; +} + +/* -- Assembler core ------------------------------------------------------ */ + +/* Assemble a trace. */ +void lj_asm_trace(jit_State *J, GCtrace *T) +{ + ASMState as_; + ASMState *as = &as_; + MCode *origtop; + + /* Ensure an initialized instruction beyond the last one for HIOP checks. */ + J->cur.nins = lj_ir_nextins(J); + J->cur.ir[J->cur.nins].o = IR_NOP; + + /* Setup initial state. Copy some fields to reduce indirections. */ + as->J = J; + as->T = T; + as->ir = T->ir; + as->flags = J->flags; + as->loopref = J->loopref; + as->realign = NULL; + as->loopinv = 0; + as->parent = J->parent ? traceref(J, J->parent) : NULL; + + /* Reserve MCode memory. */ + as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot); + as->mcp = as->mctop; + as->mclim = as->mcbot + MCLIM_REDZONE; + asm_setup_target(as); + + do { + as->mcp = as->mctop; +#ifdef LUA_USE_ASSERT + as->mcp_prev = as->mcp; +#endif + as->curins = T->nins; + RA_DBG_START(); + RA_DBGX((as, "===== STOP =====")); + + /* General trace setup. Emit tail of trace. */ + asm_tail_prep(as); + as->mcloop = NULL; + as->flagmcp = NULL; + as->topslot = 0; + as->gcsteps = 0; + as->sectref = as->loopref; + as->fuseref = (as->flags & JIT_F_OPT_FUSE) ? as->loopref : FUSE_DISABLED; + asm_setup_regsp(as); + if (!as->loopref) + asm_tail_link(as); + + /* Assemble a trace in linear backwards order. */ + for (as->curins--; as->curins > as->stopins; as->curins--) { + IRIns *ir = IR(as->curins); + lua_assert(!(LJ_32 && irt_isint64(ir->t))); /* Handled by SPLIT. */ + if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE)) + continue; /* Dead-code elimination can be soooo easy. */ + if (irt_isguard(ir->t)) + asm_snap_prep(as); + RA_DBG_REF(); + checkmclim(as); + asm_ir(as, ir); + } + } while (as->realign); /* Retry in case the MCode needs to be realigned. */ + + /* Emit head of trace. */ + RA_DBG_REF(); + checkmclim(as); + if (as->gcsteps > 0) { + as->curins = as->T->snap[0].ref; + asm_snap_prep(as); /* The GC check is a guard. */ + asm_gc_check(as); + } + ra_evictk(as); + if (as->parent) + asm_head_side(as); + else + asm_head_root(as); + asm_phi_fixup(as); + + RA_DBGX((as, "===== START ====")); + RA_DBG_FLUSH(); + if (as->freeset != RSET_ALL) + lj_trace_err(as->J, LJ_TRERR_BADRA); /* Ouch! Should never happen. */ + + /* Set trace entry point before fixing up tail to allow link to self. */ + T->mcode = as->mcp; + T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0; + if (!as->loopref) + asm_tail_fixup(as, T->link); /* Note: this may change as->mctop! */ + T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp); + lj_mcode_sync(T->mcode, origtop); +} + +#undef IR + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.h new file mode 100644 index 0000000..f5d0159 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm.h @@ -0,0 +1,17 @@ +/* +** IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_ASM_H +#define _LJ_ASM_H + +#include "lj_jit.h" + +#if LJ_HASJIT +LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T); +LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, + MCode *target); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_arm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_arm.h new file mode 100644 index 0000000..72f205d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_arm.h @@ -0,0 +1,2361 @@ +/* +** ARM IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate a scratch register pair. */ +static Reg ra_scratchpair(ASMState *as, RegSet allow) +{ + RegSet pick1 = as->freeset & allow; + RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN; + Reg r; + if (pick2) { + r = rset_picktop(pick2); + } else { + RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN; + if (pick) { + r = rset_picktop(pick); + ra_restore(as, regcost_ref(as->cost[r+1])); + } else { + pick = pick1 & (allow << 1) & RSET_GPRODD; + if (pick) { + r = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1])); + } else { + r = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN); + ra_restore(as, regcost_ref(as->cost[r+1])); + } + } + } + lua_assert(rset_test(RSET_GPREVEN, r)); + ra_modified(as, r); + ra_modified(as, r+1); + RA_DBGX((as, "scratchpair $r $r", r, r+1)); + return r; +} + +#if !LJ_SOFTFP +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_allocref(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_allocref(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_allocref(as, ir->op2, allow); + left = ra_alloc1(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_allocref(as, ir->op1, allow); + right = ra_alloc1(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} +#endif + +/* -- Guard handling ------------------------------------------------------ */ + +/* Generate an exit stub group at the bottom of the reserved MCode memory. */ +static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) +{ + MCode *mxp = as->mcbot; + int i; + if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop) + asm_mclimit(as); + /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */ + *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP); + *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu); + mxp++; + *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch); /* DISPATCH address */ + *mxp++ = group*EXITSTUBS_PER_GROUP; + for (i = 0; i < EXITSTUBS_PER_GROUP; i++) + *mxp++ = ARMI_B|((-6-i)&0x00ffffffu); + lj_mcode_sync(as->mcbot, mxp); + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + return mxp - EXITSTUBS_PER_GROUP; +} + +/* Setup all needed exit stubs. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) + lj_trace_err(as->J, LJ_TRERR_SNAPOV); + for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++) + if (as->J->exitstubgroup[i] == NULL) + as->J->exitstubgroup[i] = asm_exitstub_gen(as, i); +} + +/* Emit conditional branch to exit for guard. */ +static void asm_guardcc(ASMState *as, ARMCC cc) +{ + MCode *target = exitstub_addr(as->J, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *p = ARMI_BL | ((target-p-2) & 0x00ffffffu); + emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1); + return; + } + emit_branch(as, ARMF_CC(ARMI_BL, cc), target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow, + int lim) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (ofs > -lim && ofs < lim) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (ofs < lim) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + *ofsp = (ofs & 255); /* Mask out less bits to allow LDRD. */ + return ra_allock(as, (ofs & ~255), allow); + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse m operand into arithmetic/logic instructions. */ +static uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_hasreg(ir->r)) { + ra_noweak(as, ir->r); + return ARMF_M(ir->r); + } else if (irref_isk(ref)) { + uint32_t k = emit_isk12(ai, ir->i); + if (k) + return k; + } else if (mayfuse(as, ref)) { + if (ir->o >= IR_BSHL && ir->o <= IR_BROR) { + Reg m = ra_alloc1(as, ir->op1, allow); + ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL : + ir->o == IR_BSHR ? ARMSH_LSR : + ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR; + if (irref_isk(ir->op2)) { + return m | ARMF_SH(sh, (IR(ir->op2)->i & 31)); + } else { + Reg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m)); + return m | ARMF_RSH(sh, s); + } + } else if (ir->o == IR_ADD && ir->op1 == ir->op2) { + Reg m = ra_alloc1(as, ir->op1, allow); + return m | ARMF_SH(ARMSH_LSL, 1); + } + } + return ra_allocref(as, ref, allow); +} + +/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */ +static IRRef asm_fuselsl2(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL && + irref_isk(ir->op2) && IR(ir->op2)->i == 2) + return ir->op1; + return 0; /* No fusion. */ +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 : + (ai & 0x04000000) ? 4096 : 256; + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && + (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim && + (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) { + ofs = ofs2; + ref = ir->op1; + } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) { + IRRef lref = ir->op1, rref = ir->op2; + Reg rn, rm; + if ((ai & 0x04000000)) { + IRRef sref = asm_fuselsl2(as, rref); + if (sref) { + rref = sref; + ai |= ARMF_SH(ARMSH_LSL, 2); + } else if ((sref = asm_fuselsl2(as, lref)) != 0) { + lref = rref; + rref = sref; + ai |= ARMF_SH(ARMSH_LSL, 2); + } + } + rn = ra_alloc1(as, lref, allow); + rm = ra_alloc1(as, rref, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) ai |= ARMI_LS_R; + emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm); + return; + } + } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) { + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs += IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs += IR(ir->op1)->i; + ref = ir->op2; + } else { + /* NYI: Fuse ADD with constant. */ + Reg rn = ra_alloc1(as, ir->op1, allow); + uint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) + emit_lso(as, ai, rd, rd, ofs); + else + emit_lsox(as, ai, rd, rd, ofs); + emit_dn(as, ARMI_ADD^m, rd, rn); + return; + } + if (ofs <= -lim || ofs >= lim) { + Reg rn = ra_alloc1(as, ref, allow); + Reg rm = ra_allock(as, ofs, rset_exclude(allow, rn)); + if ((ai & 0x04000000)) ai |= ARMI_LS_R; + emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm); + return; + } + } + } + base = ra_alloc1(as, ref, allow); +#if !LJ_SOFTFP + if ((ai & 0x08000000)) + emit_vlso(as, ai, rd, base, ofs); + else +#endif + if ((ai & 0x04000000)) + emit_lso(as, ai, rd, base, ofs); + else + emit_lsox(as, ai, rd, base, ofs); +} + +#if !LJ_SOFTFP +/* Fuse to multiply-add/sub instruction. */ +static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air) +{ + IRRef lref = ir->op1, rref = ir->op2; + IRIns *irm; + if (lref != rref && + ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && + ra_noreg(irm->r)) || + (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && + (rref = lref, ai = air, ra_noreg(irm->r))))) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg add = ra_hintalloc(as, rref, dest, RSET_FPR); + Reg right, left = ra_alloc2(as, irm, + rset_exclude(rset_exclude(RSET_FPR, dest), add)); + right = (left >> 8); left &= 255; + emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15)); + if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15)); + return 1; + } + return 0; +} +#endif + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 0; +#if LJ_SOFTFP + Reg gpr = REGARG_FIRSTGPR; +#else + Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0; +#endif + if ((void *)ci->func) + emit_call(as, (void *)ci->func); +#if !LJ_SOFTFP + for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) + as->cost[gpr] = REGCOST(~0u, ASMREF_L); + gpr = REGARG_FIRSTGPR; +#endif + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + IRIns *ir = IR(ref); +#if !LJ_SOFTFP + if (ref && irt_isfp(ir->t)) { + RegSet of = as->freeset; + Reg src; + if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { + if (irt_isnum(ir->t)) { + if (fpr <= REGARG_LASTFPR) { + ra_leftov(as, fpr, ref); + fpr++; + continue; + } + } else if (fprodd) { /* Ick. */ + src = ra_alloc1(as, ref, RSET_FPR); + emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000); + fprodd = 0; + continue; + } else if (fpr <= REGARG_LASTFPR) { + ra_leftov(as, fpr, ref); + fprodd = fpr++; + continue; + } + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + fprodd = 0; + goto stackfp; + } + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u; + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */ + if (irt_isnum(ir->t)) { + lua_assert(rset_test(as->freeset, gpr+1)); /* Ditto. */ + emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15)); + gpr += 2; + } else { + emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15)); + gpr++; + } + } else { + stackfp: + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, src, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } else +#endif + { + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */ + if (ref) ra_leftov(as, gpr, ref); + gpr++; + } else { + if (ref) { + Reg r = ra_alloc1(as, ref, RSET_GPR); + emit_spstore(as, ir, r, ofs); + } + ofs += 4; + } + } + } +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (!LJ_SOFTFP && irt_isfp(ir->t)) { + if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) { + Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); + if (irt_isnum(ir->t)) + emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest); + else + emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest); + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } + UNUSED(ci); +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need a non-argument register for indirect calls. */ + Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1)); + emit_m(as, ARMI_BLXr, freg); + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + /* Need to force a spill on REF_BASE now to update the stack slot. */ + emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE))); + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_nm(as, ARMI_CMP, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_lso(as, ARMI_LDR, RID_TMP, base, -4); +} + +/* -- Type conversions ---------------------------------------------------- */ + +#if !LJ_SOFTFP +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guardcc(as, CC_NE); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15)); + emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15)); + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15)); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15)); +} +#endif + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if !LJ_SOFTFP + int stfp = (st == IRT_NUM || st == IRT_FLOAT); +#endif + IRRef lref = ir->op1; + /* 64 bit integer conversions are handled by SPLIT. */ + lua_assert(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64)); +#if LJ_SOFTFP + /* FP conversions are handled by SPLIT. */ + lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT)); + /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */ +#else + lua_assert(irt_type(ir->t) != st); + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32, + (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15)); + } else { /* Integer to FP conversion. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + ARMIns ai = irt_isfloat(ir->t) ? + (st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) : + (st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32); + emit_dm(as, ai, (dest & 15), (dest & 15)); + emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15)); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + ARMIns ai; + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + ai = irt_isint(ir->t) ? + (st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) : + (st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32); + emit_dm(as, ai, (tmp & 15), (left & 15)); + } + } else +#endif + { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((as->flags & JIT_F_ARMV6)) { + ARMIns ai = st == IRT_I8 ? ARMI_SXTB : + st == IRT_U8 ? ARMI_UXTB : + st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH; + emit_dm(as, ai, dest, left); + } else if (st == IRT_U8) { + emit_dn(as, ARMI_AND|ARMI_K12|255, dest, left); + } else { + uint32_t shift = st == IRT_I8 ? 24 : 16; + ARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR; + emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP); + emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left); + } + } else { /* Handle 32/32 bit no-op (cast). */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if !LJ_SOFTFP && LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + CCallInfo ci; + IRRef args[2]; + args[0] = (ir-1)->op1; + args[1] = ir->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = lj_ir_callinfo[id]; +#if !LJ_ABI_SOFTFP + ci.flags |= CCI_VARARG; /* These calls don't use the hard-float ABI! */ +#endif + asm_setupresult(as, ir, &ci); + asm_gencall(as, &ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + Reg rlo = 0, rhi = 0, tmp; + int destused = ra_used(ir); + int32_t ofs = 0; + ra_evictset(as, RSET_SCRATCH); +#if LJ_SOFTFP + if (destused) { + if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) && + (ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) { + int i; + for (i = 0; i < 2; i++) { + Reg r = (ir+i)->r; + if (ra_hasreg(r)) { + ra_free(as, r); + ra_modified(as, r); + emit_spload(as, ir+i, r, sps_scale((ir+i)->s)); + } + } + ofs = sps_scale(ir->s); + destused = 0; + } else { + rhi = ra_dest(as, ir+1, RSET_GPR); + rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi)); + } + } + asm_guardcc(as, CC_EQ); + if (destused) { + emit_lso(as, ARMI_LDR, rhi, RID_SP, 4); + emit_lso(as, ARMI_LDR, rlo, RID_SP, 0); + } +#else + UNUSED(rhi); + if (destused) { + if (ra_hasspill(ir->s)) { + ofs = sps_scale(ir->s); + destused = 0; + if (ra_hasreg(ir->r)) { + ra_free(as, ir->r); + ra_modified(as, ir->r); + emit_spload(as, ir, ir->r, ofs); + } + } else { + rlo = ra_dest(as, ir, RSET_FPR); + } + } + asm_guardcc(as, CC_EQ); + if (destused) + emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0); +#endif + emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + if (ofs == 0) + emit_dm(as, ARMI_MOV, tmp, RID_SP); + else + emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) { + /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + } else { +#if LJ_SOFTFP + lua_assert(0); +#else + /* Otherwise force a spill and use the spill slot. */ + emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR); +#endif + } + } else { + /* Otherwise use [sp] and [sp+4] to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_dm(as, ARMI_MOV, dest, RID_SP); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_lso(as, ARMI_STR, src, RID_SP, 0); + } + if ((ir+1)->o == IR_HIOP) + type = ra_alloc1(as, ref+1, allow); + else + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_lso(as, ARMI_STR, type, RID_SP, 4); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i); + if (k) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_dn(as, ARMI_ADD^k, dest, base); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir, IROp merge) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt)); + uint32_t khash; + MCLabel l_end, l_loop; + rset_clear(allow, tab); + if (!irref_isk(refkey) || irt_isstr(kt)) { +#if LJ_SOFTFP + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + if (irkey[1].o == IR_HIOP) { + if (ra_hasreg((irkey+1)->r)) { + keynumhi = (irkey+1)->r; + keyhi = RID_TMP; + ra_noweak(as, keynumhi); + } else { + keyhi = keynumhi = ra_allocref(as, refkey+1, allow); + } + rset_clear(allow, keynumhi); + khi = 0; + } +#else + if (irt_isnum(kt)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + keyhi = keynumhi = ra_scratch(as, allow); + rset_clear(allow, keyhi); + khi = 0; + } else { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } +#endif + } else if (irt_isnum(kt)) { + int32_t val = (int32_t)ir_knum(irkey)->u32.lo; + k = emit_isk12(ARMI_CMP, val); + if (!k) { + key = ra_allock(as, val, allow); + rset_clear(allow, key); + } + val = (int32_t)ir_knum(irkey)->u32.hi; + khi = emit_isk12(ARMI_CMP, val); + if (!khi) { + keyhi = ra_allock(as, val, allow); + rset_clear(allow, keyhi); + } + } else if (!irt_ispri(kt)) { + k = emit_isk12(ARMI_CMP, irkey->i); + if (!k) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } + } + if (!irt_ispri(kt)) + tmp = ra_scratchpair(as, allow); + + /* Key not found in chain: jump to exit (if merged) or load niltv. */ + l_end = emit_label(as); + as->invmcp = NULL; + if (merge == IR_NE) + asm_guardcc(as, CC_AL); + else if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + + /* Follow hash chain until the end. */ + l_loop = --as->mcp; + emit_n(as, ARMI_CMP|ARMI_K12|0, dest); + emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next)); + + /* Type and value comparison. */ + if (merge == IR_EQ) + asm_guardcc(as, CC_EQ); + else + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + if (!irt_ispri(kt)) { + emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key); + emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi); + emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key)); + } else { + emit_n(as, ARMI_CMP^khi, tmp); + emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it)); + } + *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp); + emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp); + if (irt_isstr(kt)) { /* Fetch of str->hash is cheaper than ra_allock. */ + emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, hash)); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + } else if (irref_isk(refkey)) { + emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash, + rset_exclude(rset_exclude(RSET_GPR, tab), dest)); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + } else { /* Must match with hash*() in lj_tab.c. */ + if (ra_hasreg(keynumhi)) { /* Canonicalize +-0.0 to 0.0. */ + if (keyhi == RID_TMP) + emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi); + emit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi); + } + emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP); + emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1); + emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)), + tmp, tmp+1, tmp); + emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); + emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp); + if (ra_hasreg(keynumhi)) { + emit_dnm(as, ARMI_EOR, tmp+1, tmp, key); + emit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key); /* Test for +-0.0. */ + emit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi); +#if !LJ_SOFTFP + emit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi, + (ra_alloc1(as, refkey, RSET_FPR) & 15)); +#endif + } else { + emit_dnm(as, ARMI_EOR, tmp+1, tmp, key); + emit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS, + rset_exclude(rset_exclude(RSET_GPR, tab), key)); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 4095) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_opk(as, ARMI_ADD, dest, node, ofs, allow); + } + asm_guardcc(as, CC_NE); + if (!irt_ispri(irkey->t)) { + RegSet even = (as->freeset & allow); + even = even & (even >> 1) & RSET_GPREVEN; + if (even) { + key = ra_scratch(as, even); + if (rset_test(as->freeset, key+1)) { + type = key+1; + ra_modified(as, type); + } + } else { + key = ra_scratch(as, allow); + } + rset_clear(allow, key); + } + rset_clear(allow, type); + if (irt_isnum(irkey->t)) { + emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type, + (int32_t)ir_knum(irkey)->u32.hi, allow); + emit_opk(as, ARMI_CMP, 0, key, + (int32_t)ir_knum(irkey)->u32.lo, allow); + } else { + if (ra_hasreg(key)) + emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type); + } + emit_lso(as, ARMI_LDR, type, idx, kofs+4); + if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs); + if (ofs > 4095) + emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR); +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, ARMI_LDR, dest, v); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guardcc(as, CC_NE); + emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP); + emit_opk(as, ARMI_ADD, dest, uv, + (int32_t)offsetof(GCupval, tv), RSET_GPR); + emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_lso(as, ARMI_LDR, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + uint32_t k, m = ARMI_K12|sizeof(GCstr); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + (k = emit_isk12(ARMI_ADD, + (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) { + m = k; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_dn(as, ARMI_ADD^m, dest, dest); + emit_dnm(as, ARMI_ADD, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + emit_opk(as, ARMI_ADD, dest, r, + sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r)); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static ARMIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return ARMI_LDRSB; + case IRT_U8: return ARMI_LDRB; + case IRT_I16: return ARMI_LDRSH; + case IRT_U16: return ARMI_LDRH; + case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VLDR_D; + case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S; + default: return ARMI_LDR; + } +} + +static ARMIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return ARMI_STRB; + case IRT_I16: case IRT_U16: return ARMI_STRH; + case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VSTR_D; + case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S; + default: return ARMI_STR; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + ARMIns ai = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx); + return; + } + } + ofs = field_ofs[ir->op2]; + if ((ai & 0x04000000)) + emit_lso(as, ai, dest, idx, ofs); + else + emit_lsox(as, ai, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + ARMIns ai = asm_fxstoreins(ir); + if ((ai & 0x04000000)) + emit_lso(as, ai, src, idx, ofs); + else + emit_lsox(as, ai, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, + (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, + (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + IRType t = hiop ? IRT_NUM : irt_type(ir->t); + Reg dest = RID_NONE, type = RID_NONE, idx; + RegSet allow = RSET_GPR; + int32_t ofs = 0; + if (hiop && ra_used(ir+1)) { + type = ra_dest(as, ir+1, allow); + rset_clear(allow, type); + } + if (ra_used(ir)) { + lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || + irt_isint(ir->t) || irt_isaddr(ir->t)); + dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow, + (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096); + if (!hiop || type == RID_NONE) { + rset_clear(allow, idx); + if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && + rset_test((as->freeset & allow), dest+1)) { + type = dest+1; + ra_modified(as, type); + } else { + type = RID_TMP; + } + } + asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type); + if (ra_hasreg(dest)) { +#if !LJ_SOFTFP + if (t == IRT_NUM) + emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs); + else +#endif + emit_lso(as, ARMI_LDR, dest, idx, ofs); + } + emit_lso(as, ARMI_LDR, type, idx, ofs+4); +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = 0; +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024); + emit_vlso(as, ARMI_VSTR_D, src, idx, ofs); + } else +#endif + { + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + if (hiop) + type = ra_alloc1(as, (ir+1)->op2, allow); + else + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096); + if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs); + emit_lso(as, ARMI_STR, type, idx, ofs+4); + } + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP); + IRType t = hiop ? IRT_NUM : irt_type(ir->t); + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK)); +#if LJ_SOFTFP + lua_assert(!(ir->op2 & IRSLOAD_CONVERT)); /* Handled by LJ_SOFTFP SPLIT. */ + if (hiop && ra_used(ir+1)) { + type = ra_dest(as, ir+1, allow); + rset_clear(allow, type); + } +#else + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t = IRT_NUM; /* Continue with a regular number type check. */ + } else +#endif + if (ra_used(ir)) { + Reg tmp = RID_NONE; + if ((ir->op2 & IRSLOAD_CONVERT)) + tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR); + lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || + irt_isint(ir->t) || irt_isaddr(ir->t)); + dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (t == IRT_INT) { + emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); + emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15)); + t = IRT_NUM; /* Check for original type. */ + } else { + emit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15)); + emit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15)); + t = IRT_INT; /* Check for original type. */ + } + dest = tmp; + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); +dotypecheck: + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + if (ra_noreg(type)) { + if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && + rset_test((as->freeset & allow), dest+1)) { + type = dest+1; + ra_modified(as, type); + } else { + type = RID_TMP; + } + } + asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); + emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type); + } + if (ra_hasreg(dest)) { +#if !LJ_SOFTFP + if (t == IRT_NUM) { + if (ofs < 1024) { + emit_vlso(as, ARMI_VLDR_D, dest, base, ofs); + } else { + if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4); + emit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0); + emit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow); + return; + } + } else +#endif + emit_lso(as, ARMI_LDR, dest, base, ofs); + } + if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; ir++; + lua_assert(ir->o == IR_HIOP); + } + for (;;) { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_lso(as, ARMI_STR, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir--; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + { + uint32_t k = emit_isk12(ARMI_MOV, ctypeid); + Reg r = k ? RID_R1 : ra_allock(as, ctypeid, allow); + emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct)); + emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid)); + emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP); + if (k) emit_d(as, ARMI_MOV^k, RID_R1); + } + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg gr = ra_allock(as, i32ptr(J2G(as->J)), + rset_exclude(rset_exclude(RSET_GPR, tab), link)); + Reg mark = RID_TMP; + MCLabel l_end = emit_label(as); + emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_lso(as, ARMI_STR, tab, gr, + (int32_t)offsetof(global_State, gc.grayagain)); + emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark); + emit_lso(as, ARMI_LDR, link, gr, + (int32_t)offsetof(global_State, gc.grayagain)); + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark); + emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + if ((l_end[-1] >> 28) == CC_AL) + l_end[-1] = ARMF_CC(l_end[-1], CC_NE); + else + emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); + ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1)); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp); + emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_lso(as, ARMI_LDRB, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +#if !LJ_SOFTFP +static void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15)); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_dm(as, ai, (dest & 15), (left & 15)); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} +#endif + +static int asm_swapops(ASMState *as, IRRef lref, IRRef rref) +{ + IRIns *ir; + if (irref_isk(rref)) + return 0; /* Don't swap constants to the left. */ + if (irref_isk(lref)) + return 1; /* But swap constants to the right. */ + ir = IR(rref); + if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || + (ir->o == IR_ADD && ir->op1 == ir->op2)) + return 0; /* Don't swap fusable operands to the left. */ + ir = IR(lref); + if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || + (ir->o == IR_ADD && ir->op1 == ir->op2)) + return 1; /* But swap fusable operands to the right. */ + return 0; /* Otherwise don't swap. */ +} + +static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai) +{ + IRRef lref = ir->op1, rref = ir->op2; + Reg left, dest = ra_dest(as, ir, RSET_GPR); + uint32_t m; + if (asm_swapops(as, lref, rref)) { + IRRef tmp = lref; lref = rref; rref = tmp; + if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC) + ai ^= (ARMI_SUB^ARMI_RSB); + } + left = ra_hintalloc(as, lref, dest, RSET_GPR); + m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left)); + if (irt_isguard(ir->t)) { /* For IR_ADDOV etc. */ + asm_guardcc(as, CC_VS); + ai |= ARMI_S; + } + emit_dn(as, ai^m, dest, left); +} + +static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai) +{ + if (as->flagmcp == as->mcp) { /* Drop cmp r, #0. */ + as->flagmcp = NULL; + as->mcp++; + ai |= ARMI_S; + } + asm_intop(as, ir, ai); +} + +static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai) +{ + if (as->flagmcp == as->mcp) { /* Try to drop cmp r, #0. */ + uint32_t cc = (as->mcp[1] >> 28); + as->flagmcp = NULL; + if (cc <= CC_NE) { + as->mcp++; + ai |= ARMI_S; + } else if (cc == CC_GE) { + *++as->mcp ^= ((CC_GE^CC_PL) << 28); + ai |= ARMI_S; + } else if (cc == CC_LT) { + *++as->mcp ^= ((CC_LT^CC_MI) << 28); + ai |= ARMI_S; + } /* else: other conds don't work with bit ops. */ + } + if (ir->op2 == 0) { + Reg dest = ra_dest(as, ir, RSET_GPR); + uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR); + emit_d(as, ai^m, dest); + } else { + /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */ + asm_intop(as, ir, ai); + } +} + +static void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_dn(as, ai|ARMI_K12|0, dest, left); +} + +/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */ +static void asm_intmul(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest)); + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + Reg tmp = RID_NONE; + /* ARMv5 restriction: dest != left and dest_hi != left. */ + if (dest == left && left != right) { left = right; right = dest; } + if (irt_isguard(ir->t)) { /* IR_MULOV */ + if (!(as->flags & JIT_F_ARMV6) && dest == left) + tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left)); + asm_guardcc(as, CC_NE); + emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest); + emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left); + } else { + if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP; + emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left); + } + /* Only need this for the dest == left == right case. */ + if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right); +} + +static void asm_add(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D)) + asm_fparith(as, ir, ARMI_VADD_D); + return; + } +#endif + asm_intop_s(as, ir, ARMI_ADD); +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D)) + asm_fparith(as, ir, ARMI_VSUB_D); + return; + } +#endif + asm_intop_s(as, ir, ARMI_SUB); +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, ARMI_VMUL_D); + return; + } +#endif + asm_intmul(as, ir); +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, ARMI_VNEG_D); + return; + } +#endif + asm_intneg(as, ir, ARMI_RSB); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +#if !LJ_SOFTFP +static void asm_callround(ASMState *as, IRIns *ir, int id) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)| + RID2RSET(RID_R3)|RID2RSET(RID_R12); + RegSet of; + Reg dest, src; + ra_evictset(as, drop); + dest = ra_dest(as, ir, RSET_FPR); + emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15)); + emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf : + id == IRFPM_CEIL ? (void *)lj_vm_ceil_sf : + (void *)lj_vm_trunc_sf); + /* Workaround to protect argument GPRs from being used for remat. */ + of = as->freeset; + as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1); + as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L); + src = ra_alloc1(as, ir->op1, RSET_FPR); /* May alloc GPR to remat FPR. */ + as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1)); + emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15)); +} +#endif + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + if ((as->flags & JIT_F_ARMV6)) { + emit_dm(as, ARMI_REV, dest, left); + } else { + Reg tmp2 = dest; + if (tmp2 == left) + tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left)); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP); + emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left); + emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP); + emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left); + } +} + +static void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh) +{ + if (irref_isk(ir->op2)) { /* Constant shifts. */ + /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */ + /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + int32_t shift = (IR(ir->op2)->i & 31); + emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left); + } +} + +static void asm_intmin_max(ASMState *as, IRIns *ir, int cc) +{ + uint32_t kcmp = 0, kmov = 0; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + Reg right = 0; + if (irref_isk(ir->op2)) { + kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i); + if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i); + } + if (!kmov) { + kcmp = 0; + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + if (kmov || dest != right) { + emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right); + cc ^= 1; /* Must use opposite conditions for paired moves. */ + } else { + cc ^= (CC_LT^CC_GT); /* Otherwise may swap CC_LT <-> CC_GT. */ + } + if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left); + emit_nm(as, ARMI_CMP^kcmp, left, right); +} + +#if LJ_SOFTFP +static void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; + RegSet drop = RSET_SCRATCH; + Reg r; + IRRef args[4]; + args[0] = ir->op1; args[1] = (ir+1)->op1; + args[2] = ir->op2; args[3] = (ir+1)->op2; + /* __aeabi_cdcmple preserves r0-r3. */ + if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); + if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r); + if (!rset_test(as->freeset, RID_R2) && + regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2); + if (!rset_test(as->freeset, RID_R3) && + regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3); + ra_evictset(as, drop); + ra_destpair(as, ir); + emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3); + emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2); + emit_call(as, (void *)ci->func); + for (r = RID_R0; r <= RID_R3; r++) + ra_leftov(as, r, args[r-RID_R0]); +} +#else +static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc) +{ + Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = ((left >> 8) & 15); left &= 15; + if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left); + if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ARMI_VCMP_D, left, right); +} +#endif + +static void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc) +{ +#if LJ_SOFTFP + UNUSED(fcc); +#else + if (irt_isnum(ir->t)) + asm_fpmin_max(as, ir, fcc); + else +#endif + asm_intmin_max(as, ir, cc); +} + +/* -- Comparisons --------------------------------------------------------- */ + +/* Map of comparisons to flags. ORDER IR. */ +static const uint8_t asm_compmap[IR_ABC+1] = { + /* op FP swp int cc FP cc */ + /* LT */ CC_GE + (CC_HS << 4), + /* GE x */ CC_LT + (CC_HI << 4), + /* LE */ CC_GT + (CC_HI << 4), + /* GT x */ CC_LE + (CC_HS << 4), + /* ULT x */ CC_HS + (CC_LS << 4), + /* UGE */ CC_LO + (CC_LO << 4), + /* ULE x */ CC_HI + (CC_LO << 4), + /* UGT */ CC_LS + (CC_LS << 4), + /* EQ */ CC_NE + (CC_NE << 4), + /* NE */ CC_EQ + (CC_EQ << 4), + /* ABC */ CC_LS + (CC_LS << 4) /* Same as UGT. */ +}; + +#if LJ_SOFTFP +/* FP comparisons. */ +static void asm_sfpcomp(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; + RegSet drop = RSET_SCRATCH; + Reg r; + IRRef args[4]; + int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1); + args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1; + args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2; + /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */ + for (r = RID_R0; r <= RID_R3; r++) + if (!rset_test(as->freeset, r) && + regcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r); + ra_evictset(as, drop); + asm_guardcc(as, (asm_compmap[ir->o] >> 4)); + emit_call(as, (void *)ci->func); + for (r = RID_R0; r <= RID_R3; r++) + ra_leftov(as, r, args[r-RID_R0]); +} +#else +/* FP comparisons. */ +static void asm_fpcomp(ASMState *as, IRIns *ir) +{ + Reg left, right; + ARMIns ai; + int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1); + if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) { + left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15); + right = 0; + ai = ARMI_VCMPZ_D; + } else { + left = ra_alloc2(as, ir, RSET_FPR); + if (swp) { + right = (left & 15); left = ((left >> 8) & 15); + } else { + right = ((left >> 8) & 15); left &= 15; + } + ai = ARMI_VCMP_D; + } + asm_guardcc(as, (asm_compmap[ir->o] >> 4)); + emit_d(as, ARMI_VMRS, 0); + emit_dm(as, ai, left, right); +} +#endif + +/* Integer comparisons. */ +static void asm_intcomp(ASMState *as, IRIns *ir) +{ + ARMCC cc = (asm_compmap[ir->o] & 15); + IRRef lref = ir->op1, rref = ir->op2; + Reg left; + uint32_t m; + int cmpprev0 = 0; + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + if (asm_swapops(as, lref, rref)) { + Reg tmp = lref; lref = rref; rref = tmp; + if (cc >= CC_GE) cc ^= 7; /* LT <-> GT, LE <-> GE */ + else if (cc > CC_NE) cc ^= 11; /* LO <-> HI, LS <-> HS */ + } + if (irref_isk(rref) && IR(rref)->i == 0) { + IRIns *irl = IR(lref); + cmpprev0 = (irl+1 == ir); + /* Combine comp(BAND(left, right), 0) into tst left, right. */ + if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) { + IRRef blref = irl->op1, brref = irl->op2; + uint32_t m2 = 0; + Reg bleft; + if (asm_swapops(as, blref, brref)) { + Reg tmp = blref; blref = brref; brref = tmp; + } + if (irref_isk(brref)) { + m2 = emit_isk12(ARMI_AND, IR(brref)->i); + if ((m2 & (ARMI_AND^ARMI_BIC))) + goto notst; /* Not beneficial if we miss a constant operand. */ + } + if (cc == CC_GE) cc = CC_PL; + else if (cc == CC_LT) cc = CC_MI; + else if (cc > CC_NE) goto notst; /* Other conds don't work with tst. */ + bleft = ra_alloc1(as, blref, RSET_GPR); + if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft)); + asm_guardcc(as, cc); + emit_n(as, ARMI_TST^m2, bleft); + return; + } + } +notst: + left = ra_alloc1(as, lref, RSET_GPR); + m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left)); + asm_guardcc(as, cc); + emit_n(as, ARMI_CMP^m, left); + /* Signed comparison with zero and referencing previous ins? */ + if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE)) + as->flagmcp = as->mcp; /* Allow elimination of the compare. */ +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_int64comp(ASMState *as, IRIns *ir) +{ + int signedcomp = (ir->o <= IR_GT); + ARMCC cclo, cchi; + Reg leftlo, lefthi; + uint32_t mlo, mhi; + RegSet allow = RSET_GPR, oldfree; + + /* Always use unsigned comparison for loword. */ + cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15; + leftlo = ra_alloc1(as, ir->op1, allow); + oldfree = as->freeset; + mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo)); + allow &= ~(oldfree & ~as->freeset); /* Update for allocs of asm_fuseopm. */ + + /* Use signed or unsigned comparison for hiword. */ + cchi = asm_compmap[ir->o] & 15; + lefthi = ra_alloc1(as, (ir+1)->op1, allow); + mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi)); + + /* All register allocations must be performed _before_ this point. */ + if (signedcomp) { + MCLabel l_around = emit_label(as); + asm_guardcc(as, cclo); + emit_n(as, ARMI_CMP^mlo, leftlo); + emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around); + if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6; /* GE -> GT, LE -> LT */ + asm_guardcc(as, cchi); + } else { + asm_guardcc(as, cclo); + emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo); + } + emit_n(as, ARMI_CMP^mhi, lefthi); +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI || LJ_SOFTFP + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o <= IR_NE) { /* 64 bit integer or FP comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ +#if LJ_SOFTFP + if (!irt_isint(ir->t)) { + asm_sfpcomp(as, ir-1); + return; + } +#endif +#if LJ_HASFFI + asm_int64comp(as, ir-1); +#endif + return; +#if LJ_SOFTFP + } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) { + as->curins--; /* Always skip the loword min/max. */ + if (uselo || usehi) + asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_HI : CC_LO); + return; +#elif LJ_HASFFI + } else if ((ir-1)->o == IR_CONV) { + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; +#endif + } else if ((ir-1)->o == IR_XSTORE) { + if ((ir-1)->r != RID_SINK) + asm_xstore(as, ir, 4); + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { +#if LJ_HASFFI + case IR_ADD: + as->curins--; + asm_intop(as, ir, ARMI_ADC); + asm_intop(as, ir-1, ARMI_ADD|ARMI_S); + break; + case IR_SUB: + as->curins--; + asm_intop(as, ir, ARMI_SBC); + asm_intop(as, ir-1, ARMI_SUB|ARMI_S); + break; + case IR_NEG: + as->curins--; + asm_intneg(as, ir, ARMI_RSC); + asm_intneg(as, ir-1, ARMI_RSB|ARMI_S); + break; +#endif +#if LJ_SOFTFP + case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + case IR_STRTO: + if (!uselo) + ra_allocref(as, ir->op1, RSET_GPR); /* Mark lo op as used. */ + break; +#endif + case IR_CALLN: + case IR_CALLS: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; +#if LJ_SOFTFP + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: +#endif + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + Reg pbase; + uint32_t k; + if (irp) { + if (!ra_hasspill(irp->s)) { + pbase = irp->r; + lua_assert(ra_hasreg(pbase)); + } else if (allow) { + pbase = rset_pickbot(allow); + } else { + pbase = RID_RET; + emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0); /* Restore temp. register. */ + } + } else { + pbase = RID_BASE; + } + emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno)); + k = emit_isk12(0, (int32_t)(8*topslot)); + lua_assert(k); + emit_n(as, ARMI_CMP^k, RID_TMP); + emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase); + emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, + (int32_t)offsetof(lua_State, maxstack)); + if (irp) { /* Must not spill arbitrary registers in head of side trace. */ + int32_t i = i32ptr(&J2G(as->J)->jit_L); + if (ra_hasspill(irp->s)) + emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s)); + emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095)); + if (ra_hasspill(irp->s) && !allow) + emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0); /* Save temp. register. */ + emit_loadi(as, RID_TMP, (i & ~4095)); + } else { + emit_getgl(as, RID_TMP, jit_L); + } +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { +#if LJ_SOFTFP + RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); + Reg tmp; + lua_assert(irref_isk(ref)); /* LJ_SOFTFP: must be a number constant. */ + tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, + rset_exclude(RSET_GPREVEN, RID_BASE)); + emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs); + if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1); + tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd); + emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4); +#else + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs); +#endif + } else { + RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); + Reg type; + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE)); + emit_lso(as, ARMI_STR, src, RID_BASE, ofs); + if (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), odd); +#if LJ_SOFTFP + } else if ((sn & SNAP_SOFTFPNUM)) { + type = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE)); +#endif + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), odd); + } + emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp1, tmp2; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + tmp1 = ra_releasetmp(as, ASMREF_TMP1); + tmp2 = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp2, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end); + emit_nm(as, ARMI_CMP, RID_TMP, tmp2); + emit_lso(as, ARMI_LDR, tmp2, tmp1, + (int32_t)offsetof(global_State, gc.threshold)); + emit_lso(as, ARMI_LDR, RID_TMP, tmp1, + (int32_t)offsetof(global_State, gc.total)); + ra_allockreg(as, i32ptr(J2G(as->J)), tmp1); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the bcc and patched the final bl. */ + p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu); + } else { + p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Reload L register from g->jit_L. */ +static void asm_head_lreg(ASMState *as) +{ + IRIns *ir = IR(ASMREF_L); + if (ra_used(ir)) { + Reg r = ra_dest(as, ir, RSET_GPR); + emit_getgl(as, r, jit_L); + ra_evictk(as); + } +} + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir; + asm_head_lreg(as); + ir = IR(REF_BASE); + if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) + ra_spill(as, ir); + ra_destreg(as, ir, RID_BASE); +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir; + asm_head_lreg(as); + ir = IR(REF_BASE); + if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) + ra_spill(as, ir); + if (ra_hasspill(irp->s)) { + rset_clear(allow, ra_dest(as, ir, allow)); + } else { + Reg r = irp->r; + lua_assert(ra_hasreg(r)); + rset_clear(allow, r); + if (r != ir->r && !rset_test(as->freeset, r)) + ra_restore(as, regcost_ref(as->cost[r])); + ra_destreg(as, ir, r); + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *p = as->mctop; + MCode *target; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + as->mctop = --p; + } else { + /* Patch stack adjustment. */ + uint32_t k = emit_isk12(ARMI_ADD, spadj); + lua_assert(k); + p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP); + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop - 1; /* Leave room for exit branch. */ + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + as->mcp = p-1; /* Leave room for stack pointer adjustment. */ + as->invmcp = NULL; + } + *p = 0; /* Prevent load/store merging. */ +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: + if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) { + as->curins--; + asm_href(as, ir-1, (IROp)ir->o); + break; + } + /* fallthrough */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: +#if !LJ_SOFTFP + if (irt_isnum(ir->t)) { asm_fpcomp(as, ir); break; } +#endif + asm_intcomp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitop(as, ir, ARMI_MVN); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitop(as, ir, ARMI_AND); break; + case IR_BOR: asm_bitop(as, ir, ARMI_ORR); break; + case IR_BXOR: asm_bitop(as, ir, ARMI_EOR); break; + + case IR_BSHL: asm_bitshift(as, ir, ARMSH_LSL); break; + case IR_BSHR: asm_bitshift(as, ir, ARMSH_LSR); break; + case IR_BSAR: asm_bitshift(as, ir, ARMSH_ASR); break; + case IR_BROR: asm_bitshift(as, ir, ARMSH_ROR); break; + case IR_BROL: lua_assert(0); break; + + /* Arithmetic ops. */ + case IR_ADD: case IR_ADDOV: asm_add(as, ir); break; + case IR_SUB: case IR_SUBOV: asm_sub(as, ir); break; + case IR_MUL: case IR_MULOV: asm_mul(as, ir); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_NEG: asm_neg(as, ir); break; + +#if LJ_SOFTFP + case IR_DIV: case IR_POW: case IR_ABS: + case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT: + lua_assert(0); /* Unused for LJ_SOFTFP. */ + break; +#else + case IR_DIV: asm_fparith(as, ir, ARMI_VDIV_D); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_ABS: asm_fpunary(as, ir, ARMI_VABS_D); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 <= IRFPM_TRUNC) + asm_callround(as, ir, ir->op2); + else if (ir->op2 == IRFPM_SQRT) + asm_fpunary(as, ir, ARMI_VSQRT_D); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + case IR_TOBIT: asm_tobit(as, ir); break; +#endif + + case IR_MIN: asm_min_max(as, ir, CC_GT, CC_HI); break; + case IR_MAX: asm_min_max(as, ir, CC_LT, CC_LO); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir, 0); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) { + if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) { + if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { + if (irt_isnum(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; + else fprodd = 0, nslots = (nslots + 3) & ~1; + } else { + if (fprodd) fprodd--; + else if (nfpr > 0) fprodd = 1, nfpr--; + else nslots++; + } + } else if (irt_isnum(IR(args[i])->t)) { + ngpr &= ~1; + if (ngpr > 0) ngpr -= 2; else nslots += 2; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + /* May need extra exit for asm_stack_check on side traces. */ + asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0)); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *cstart = NULL, *cend = p; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MCode *px = exitstub_addr(J, exitno) - 2; + for (; p < pe; p++) { + /* Look for bl_cc exitstub, replace with b_cc target. */ + uint32_t ins = *p; + if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u && + ((ins ^ (px-p)) & 0x00ffffffu) == 0) { + *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu); + cend = p+1; + if (!cstart) cstart = p; + } + } + lua_assert(cstart != NULL); + lj_mcode_sync(cstart, cend); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_mips.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_mips.h new file mode 100644 index 0000000..e5c67b5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_mips.h @@ -0,0 +1,1977 @@ +/* +** MIPS IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate a register or RID_ZERO. */ +static Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!(allow & RSET_FPR) && irref_isk(ref) && IR(ref)->i == 0) + return RID_ZERO; + r = ra_allocref(as, ref, allow); + } else { + ra_noweak(as, r); + } + return r; +} + +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_alloc1z(as, ir->op2, allow); + left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_alloc1z(as, ir->op1, allow); + right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} + +/* -- Guard handling ------------------------------------------------------ */ + +/* Need some spare long-range jump slots, for out-of-range branches. */ +#define MIPS_SPAREJUMP 4 + +/* Setup spare long-range jump slots per mcarea. */ +static void asm_sparejump_setup(ASMState *as) +{ + MCode *mxp = as->mcbot; + /* Assumes sizeof(MCLink) == 8. */ + if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == 8) { + lua_assert(MIPSI_NOP == 0); + memset(mxp+2, 0, MIPS_SPAREJUMP*8); + mxp += MIPS_SPAREJUMP*2; + lua_assert(mxp < as->mctop); + lj_mcode_sync(as->mcbot, mxp); + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + } +} + +/* Setup exit stub after the end of each trace. */ +static void asm_exitstub_setup(ASMState *as) +{ + MCode *mxp = as->mctop; + /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */ + *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno; + *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu); + lua_assert(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0); + *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0; + as->mctop = mxp; +} + +/* Keep this in-sync with exitstub_trace_addr(). */ +#define asm_exitstub_addr(as) ((as)->mctop) + +/* Emit conditional branch to exit for guard. */ +static void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt) +{ + MCode *target = asm_exitstub_addr(as); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->invmcp = NULL; + as->loopinv = 1; + as->mcp = p+1; + mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u); /* Invert cond. */ + target = p; /* Patch target later in asm_loop_fixup. */ + } + emit_ti(as, MIPSI_LI, RID_TMP, as->snapno); + emit_branch(as, mi, rs, rt, target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + int32_t jgl = (intptr_t)J2G(as->J); + if ((uint32_t)(ofs-jgl) < 65536) { + *ofsp = ofs-jgl-32768; + return RID_JGL; + } else { + *ofsp = (int16_t)ofs; + return ra_allock(as, ofs-(int16_t)ofs, allow); + } + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) { + ref = ir->op1; + ofs = ofs2; + } + } else if (ir->o == IR_STRREF) { + int32_t ofs2 = 65536; + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs2 = ofs + IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs2 = ofs + IR(ir->op1)->i; + ref = ir->op2; + } + if (!checki16(ofs2)) { + /* NYI: Fuse ADD with constant. */ + Reg right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + emit_hsi(as, mi, rt, RID_TMP, ofs); + emit_dst(as, MIPSI_ADDU, RID_TMP, left, right); + return; + } + ofs = ofs2; + } + } + base = ra_alloc1(as, ref, allow); + emit_hsi(as, mi, rt, base, ofs); +} + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 16; + Reg gpr, fpr = REGARG_FIRSTFPR; + if ((void *)ci->func) + emit_call(as, (void *)ci->func); + for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) + as->cost[gpr] = REGCOST(~0u, ASMREF_L); + gpr = REGARG_FIRSTGPR; + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + if (ref) { + IRIns *ir = IR(ref); + if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR && + !(ci->flags & CCI_VARARG)) { + lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */ + ra_leftov(as, fpr, ref); + fpr += 2; + gpr += irt_isnum(ir->t) ? 2 : 1; + } else { + fpr = REGARG_LASTFPR+1; + if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1; + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */ + if (irt_isfp(ir->t)) { + RegSet of = as->freeset; + Reg r; + /* Workaround to protect argument GPRs from being used for remat. */ + as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1); + r = ra_alloc1(as, ref, RSET_FPR); + as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1)); + if (irt_isnum(ir->t)) { + emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1); + emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r); + lua_assert(rset_test(as->freeset, gpr+1)); /* Already evicted. */ + gpr += 2; + } else if (irt_isfloat(ir->t)) { + emit_tg(as, MIPSI_MFC1, gpr, r); + gpr++; + } + } else { + ra_leftov(as, gpr, ref); + gpr++; + } + } else { + Reg r = ra_alloc1z(as, ref, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, r, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } + } else { + fpr = REGARG_LASTFPR+1; + if (gpr <= REGARG_LASTGPR) + gpr++; + else + ofs += 4; + } + checkmclim(as); + } +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (irt_isfp(ir->t)) { + if ((ci->flags & CCI_CASTU64)) { + int32_t ofs = sps_scale(ir->s); + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1); + emit_tg(as, MIPSI_MTC1, RID_RETLO, dest); + } + if (ofs) { + emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4)); + } + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need specific register for indirect calls. */ + Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR)); + MCode *p = as->mcp; + if (r == RID_CFUNCADDR) + *--p = MIPSI_NOP; + else + *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r); + *--p = MIPSI_JALR | MIPSF_S(r); + as->mcp = p; + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callround(ASMState *as, IRIns *ir, IRCallID id) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)| + RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR); + if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); + ra_evictset(as, drop); + ra_destreg(as, ir, RID_FPRET); + emit_call(as, (void *)lj_ir_callinfo[id].func); + ra_leftov(as, REGARG_FIRSTFPR, ir->op1); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guard(as, MIPSI_BNE, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_tsi(as, MIPSI_LW, RID_TMP, base, -8); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guard(as, MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left); + emit_fg(as, MIPSI_CVT_D_W, tmp, tmp); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, MIPSI_CVT_W_D, tmp, left); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fgh(as, MIPSI_ADD_D, tmp, left, right); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(irt_isint64(ir->t) || + (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S, + dest, ra_alloc1(as, lref, RSET_FPR)); + } else if (st == IRT_U32) { /* U32 to FP conversion. */ + /* y = (x ^ 0x8000000) + 2147483648.0 */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + emit_fgh(as, irt_isfloat(ir->t) ? MIPSI_ADD_S : MIPSI_ADD_D, + dest, dest, tmp); + emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W, + dest, dest); + if (irt_isfloat(ir->t)) + emit_lsptr(as, MIPSI_LWC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)), + RSET_GPR); + else + emit_lsptr(as, MIPSI_LDC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)), + RSET_GPR); + emit_tg(as, MIPSI_MTC1, RID_TMP, dest); + emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left); + emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000); + } else { /* Integer to FP conversion. */ + Reg left = ra_alloc1(as, lref, RSET_GPR); + emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W, + dest, dest); + emit_tg(as, MIPSI_MTC1, left, dest); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + if (irt_isu32(ir->t)) { + /* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */ + emit_dst(as, MIPSI_XOR, dest, dest, RID_TMP); + emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D, + tmp, tmp); + emit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D, + tmp, left, tmp); + if (st == IRT_FLOAT) + emit_lsptr(as, MIPSI_LWC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)), + RSET_GPR); + else + emit_lsptr(as, MIPSI_LDC1, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)), + RSET_GPR); + } else { + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D, + tmp, left); + } + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((ir->op2 & IRCONV_SEXT)) { + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left); + } else { + uint32_t shift = st == IRT_I8 ? 24 : 16; + emit_dta(as, MIPSI_SRA, dest, dest, shift); + emit_dta(as, MIPSI_SLL, dest, left, shift); + } + } else { + emit_tsi(as, MIPSI_ANDI, dest, left, + (int32_t)(st == IRT_U8 ? 0xff : 0xffff)); + } + } else { /* 32/64 bit integer conversions. */ + /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + const CCallInfo *ci; + IRRef args[2]; + args[LJ_BE?0:1] = ir->op1; + args[LJ_BE?1:0] = (ir-1)->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = &lj_ir_callinfo[id]; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + RegSet drop = RSET_SCRATCH; + if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */ + ra_evictset(as, drop); + asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), + RID_SP, sps_scale(ir->s)); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + else /* Otherwise force a spill and use the spill slot. */ + emit_tsi(as, MIPSI_ADDIU, dest, RID_SP, ra_spill(as, ir)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, offsetof(global_State, tmptv)-32768); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_setgl(as, src, tmptv.gcr); + } + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_setgl(as, type, tmptv.it); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_tsi(as, MIPSI_ADDIU, dest, base, ofs); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_dst(as, MIPSI_ADDU, dest, RID_TMP, base); + emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + rset_clear(allow, tab); + if (irt_isnum(kt)) { + key = ra_alloc1(as, refkey, RSET_FPR); + tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key)); + } else if (!irt_ispri(kt)) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + type = ra_allock(as, irt_toitype(irkey->t), allow); + rset_clear(allow, type); + } + tmp2 = ra_scratch(as, allow); + rset_clear(allow, tmp2); + + /* Key not found in chain: load niltv. */ + l_end = emit_label(as); + if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + else + *--as->mcp = MIPSI_NOP; + /* Follow hash chain until the end. */ + emit_move(as, dest, tmp1); + l_loop = --as->mcp; + emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (irt_isnum(kt)) { + emit_branch(as, MIPSI_BC1T, 0, 0, l_end); + emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key); + emit_tg(as, MIPSI_MFC1, tmp1, key+1); + emit_branch(as, MIPSI_BEQ, tmp1, RID_ZERO, l_next); + emit_tsi(as, MIPSI_SLTIU, tmp1, tmp1, (int32_t)LJ_TISNUM); + emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n)); + } else { + if (irt_ispri(kt)) { + emit_branch(as, MIPSI_BEQ, tmp1, type, l_end); + } else { + emit_branch(as, MIPSI_BEQ, tmp2, key, l_end); + emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.gcr)); + emit_branch(as, MIPSI_BNE, tmp1, type, l_next); + } + } + emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.it)); + *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + Reg tmphash = tmp1; + if (irref_isk(refkey)) + tmphash = ra_allock(as, khash, allow); + emit_dst(as, MIPSI_ADDU, dest, dest, tmp1); + lua_assert(sizeof(Node) == 24); + emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1); + emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3); + emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5); + emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash); + emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask)); + if (irref_isk(refkey)) { + /* Nothing to do. */ + } else if (irt_isstr(kt)) { + emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, hash)); + } else { /* Must match with hash*() in lj_tab.c. */ + emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2); + emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31); + emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2); + emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31); + emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest); + if (irt_isnum(kt)) { + emit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1); + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31); + } else { + emit_dst(as, MIPSI_OR, dest, dest, tmp1); + emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1); + emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31); + } + emit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1); + emit_tg(as, MIPSI_MFC1, tmp2, key); + emit_tg(as, MIPSI_MFC1, tmp1, key+1); + } else { + emit_dst(as, MIPSI_XOR, tmp2, key, tmp1); + emit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31); + emit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow)); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + int32_t lo, hi; + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 32736) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_tsi(as, MIPSI_ADDIU, dest, node, ofs); + } + if (!irt_ispri(irkey->t)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + } + if (irt_isnum(irkey->t)) { + lo = (int32_t)ir_knum(irkey)->u32.lo; + hi = (int32_t)ir_knum(irkey)->u32.hi; + } else { + lo = irkey->i; + hi = irt_toitype(irkey->t); + if (!ra_hasreg(key)) + goto nolo; + } + asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO); +nolo: + asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO); + if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4)); + if (ofs > 32736) + emit_tsi(as, MIPSI_ADDU, dest, node, ra_allock(as, ofs, allow)); +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); + } +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, MIPSI_LW, dest, v, RSET_GPR); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, MIPSI_ADDIU, dest, uv, (int32_t)offsetof(GCupval, tv)); + emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_tsi(as, MIPSI_LW, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_tsi(as, MIPSI_LW, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + int32_t ofs = (int32_t)sizeof(GCstr); + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + checki16(ofs + IR(irr->op2)->i)) { + ofs += IR(irr->op2)->i; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs); + emit_dst(as, MIPSI_ADDU, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + ofs += IR(refk)->i; + if (checki16(ofs)) + emit_tsi(as, MIPSI_ADDIU, dest, r, ofs); + else + emit_dst(as, MIPSI_ADDU, dest, r, + ra_allock(as, ofs, rset_exclude(RSET_GPR, r))); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static MIPSIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return MIPSI_LB; + case IRT_U8: return MIPSI_LBU; + case IRT_I16: return MIPSI_LH; + case IRT_U16: return MIPSI_LHU; + case IRT_NUM: return MIPSI_LDC1; + case IRT_FLOAT: return MIPSI_LWC1; + default: return MIPSI_LW; + } +} + +static MIPSIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return MIPSI_SB; + case IRT_I16: case IRT_U16: return MIPSI_SH; + case IRT_NUM: return MIPSI_SDC1; + case IRT_FLOAT: return MIPSI_SWC1; + default: return MIPSI_SW; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + MIPSIns mi = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_tsi(as, MIPSI_ADDIU, dest, idx, ofs); + return; + } + } + ofs = field_ofs[ir->op2]; + lua_assert(!irt_isfp(ir->t)); + emit_tsi(as, mi, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1z(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + MIPSIns mi = asm_fxstoreins(ir); + lua_assert(!irt_isfp(ir->t)); + emit_tsi(as, mi, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1z(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_TMP, idx; + RegSet allow = RSET_GPR; + int32_t ofs = 0; + if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + rset_clear(allow, idx); + if (irt_isnum(t)) { + asm_guard(as, MIPSI_BEQ, type, RID_ZERO); + emit_tsi(as, MIPSI_SLTIU, type, type, (int32_t)LJ_TISNUM); + if (ra_hasreg(dest)) + emit_hsi(as, MIPSI_LDC1, dest, idx, ofs); + } else { + asm_guard(as, MIPSI_BNE, type, ra_allock(as, irt_toitype(t), allow)); + if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0)); + } + emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4)); +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = 0; + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + } else { + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + rset_clear(allow, type); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(ir->t)) { + emit_hsi(as, MIPSI_SDC1, src, idx, ofs); + } else { + if (ra_hasreg(src)) + emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0)); + emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4)); + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(!irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ + } else if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (irt_isint(t)) { + Reg tmp = ra_scratch(as, RSET_FPR); + emit_tg(as, MIPSI_MFC1, dest, tmp); + emit_fg(as, MIPSI_CVT_W_D, tmp, tmp); + dest = tmp; + t.irt = IRT_NUM; /* Check for original type. */ + } else { + Reg tmp = ra_scratch(as, RSET_GPR); + emit_fg(as, MIPSI_CVT_D_W, dest, dest); + emit_tg(as, MIPSI_MTC1, tmp, dest); + dest = tmp; + t.irt = IRT_INT; /* Check for original type. */ + } + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); +dotypecheck: + if (irt_isnum(t)) { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)LJ_TISNUM); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_hsi(as, MIPSI_LDC1, dest, base, ofs); + } else { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + Reg ktype = ra_allock(as, irt_toitype(t), allow); + asm_guard(as, MIPSI_BNE, RID_TMP, ktype); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0)); + } + if (ra_hasreg(type)) emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4)); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; + lua_assert((ir+1)->o == IR_HIOP); + if (LJ_LE) ir++; + } + for (;;) { + Reg r = ra_alloc1z(as, ir->op2, allow); + emit_tsi(as, MIPSI_SW, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; if (LJ_BE) ir++; else ir--; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct)); + emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid)); + emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA); + emit_ti(as, MIPSI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */ + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg link = RID_TMP; + MCLabel l_end = emit_label(as); + emit_tsi(as, MIPSI_SW, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_setgl(as, tab, gc.grayagain); + emit_getgl(as, link, gc.grayagain); + emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP); /* Clear black bit. */ + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK); + emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK); + emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end); + emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_tsi(as, MIPSI_LBU, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +static void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + emit_fgh(as, mi, dest, left, right); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_fg(as, mi, dest, left); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_ADD_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, MIPSI_ADDU, dest, left, right); + } +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_SUB_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_SUBU, dest, left, right); + } +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, MIPSI_MUL_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_MUL, dest, left, right); + } +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, MIPSI_NEG_D); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); + } +} + +static void asm_arithov(ASMState *as, IRIns *ir) +{ + Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { + int k = IR(ir->op2)->i; + if (ir->o == IR_SUBOV) k = -k; + if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */ + left = ra_alloc1(as, ir->op1, RSET_GPR); + asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + if (dest == left) emit_move(as, RID_TMP, left); + return; + } + } + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left), + right), dest)); + asm_guard(as, MIPSI_BLTZ, RID_TMP, 0); + emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp); + if (ir->o == IR_ADDOV) { /* ((dest^left) & (dest^right)) < 0 */ + emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right); + } else { /* ((dest^left) & (dest^~right)) < 0 */ + emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest); + emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO); + } + emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left); + emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right); + if (dest == left || dest == right) + emit_move(as, RID_TMP, dest == left ? left : right); +} + +static void asm_mulov(ASMState *as, IRIns *ir) +{ +#if LJ_DUALNUM +#error "NYI: MULOV" +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused in single-number mode. */ +#endif +} + +#if LJ_HASFFI +static void asm_add64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) { + emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP); + goto loarith; + } else if (checki16(k)) { + emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + goto loarith; + } + } + emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP); + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, MIPSI_ADDU, dest, left, right); +loarith: + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) { + if (dest != left) + emit_move(as, dest, left); + return; + } else if (checki16(k)) { + if (dest == left) { + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left); + emit_tsi(as, MIPSI_ADDIU, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + if (dest == left && dest == right) { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left); + emit_dst(as, MIPSI_ADDU, dest, left, right); +} + +static void asm_sub64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SUBU, dest, left, right); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (dest == left) { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_move(as, dest, tmp); + dest = tmp; + } + emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest); + emit_dst(as, MIPSI_SUBU, dest, left, right); +} + +static void asm_neg64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest); + emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left); +} +#endif + +static void asm_bitnot(ASMState *as, IRIns *ir) +{ + Reg left, right, dest = ra_dest(as, ir, RSET_GPR); + IRIns *irl = IR(ir->op1); + if (mayfuse(as, ir->op1) && irl->o == IR_BOR) { + left = ra_alloc2(as, irl, RSET_GPR); + right = (left >> 8); left &= 255; + } else { + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + right = RID_ZERO; + } + emit_dst(as, MIPSI_NOR, dest, left, right); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16); + emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left); + } else { + Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest)); + emit_dst(as, MIPSI_OR, dest, dest, tmp); + emit_dst(as, MIPSI_OR, dest, dest, RID_TMP); + emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00); + emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8); + emit_dta(as, MIPSI_SRL, dest, left, 8); + emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00); + emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP); + emit_dta(as, MIPSI_SRL, tmp, left, 24); + emit_dta(as, MIPSI_SLL, RID_TMP, left, 24); + } +} + +static void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checku16(k)) { + emit_tsi(as, mik, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_dst(as, mi, dest, left, right); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31); + emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR), shift); + } else { + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, mi, dest, right, left); /* Shift amount is in rs. */ + } +} + +static void asm_bitror(ASMState *as, IRIns *ir) +{ + if ((as->flags & JIT_F_MIPS32R2)) { + asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_rotr(as, dest, left, RID_TMP, shift); + } else { + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_OR, dest, dest, RID_TMP); + emit_dst(as, MIPSI_SRLV, dest, right, left); + emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left); + emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right); + } + } +} + +static void asm_min_max(ASMState *as, IRIns *ir, int ismax) +{ + if (irt_isnum(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (dest == left) { + emit_fg(as, MIPSI_MOVT_D, dest, right); + } else { + emit_fg(as, MIPSI_MOVF_D, dest, left); + if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right); + } + emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? left : right, ismax ? right : left); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (dest == left) { + emit_dst(as, MIPSI_MOVN, dest, right, RID_TMP); + } else { + emit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP); + if (dest != right) emit_move(as, dest, right); + } + emit_dst(as, MIPSI_SLT, RID_TMP, + ismax ? left : right, ismax ? right : left); + } +} + +/* -- Comparisons --------------------------------------------------------- */ + +static void asm_comp(ASMState *as, IRIns *ir) +{ + /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */ + IROp op = ir->o; + if (irt_isnum(ir->t)) { + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right); + } else { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + if (op == IR_ABC) op = IR_UGT; + if ((op&4) == 0 && irref_isk(ir->op2) && IR(ir->op2)->i == 0) { + MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) : + ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ); + asm_guard(as, mi, left, 0); + } else { + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if ((op&2)) k++; + if (checki16(k)) { + asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI, + RID_TMP, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, + RID_TMP, (op&2) ? right : left, (op&2) ? left : right); + } + } +} + +static void asm_compeq(ASMState *as, IRIns *ir) +{ + Reg right, left = ra_alloc2(as, ir, irt_isnum(ir->t) ? RSET_FPR : RSET_GPR); + right = (left >> 8); left &= 255; + if (irt_isnum(ir->t)) { + asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0); + emit_fgh(as, MIPSI_C_EQ_D, 0, left, right); + } else { + asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right); + } +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_comp64(ASMState *as, IRIns *ir) +{ + /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */ + IROp op = (ir-1)->o; + MCLabel l_end; + Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR); + righthi = (lefthi >> 8); lefthi &= 255; + leftlo = ra_alloc2(as, ir-1, + rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi)); + rightlo = (leftlo >> 8); leftlo &= 255; + asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); + l_end = emit_label(as); + if (lefthi != righthi) + emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP, + (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi); + emit_dst(as, MIPSI_SLTU, RID_TMP, + (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo); + if (lefthi != righthi) + emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end); +} + +static void asm_comp64eq(ASMState *as, IRIns *ir) +{ + Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO); + tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right)); + emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp); + emit_dst(as, MIPSI_XOR, tmp, left, right); + left = ra_alloc2(as, ir-1, RSET_GPR); + right = (left >> 8); left &= 255; + emit_dst(as, MIPSI_XOR, RID_TMP, left, right); +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; + } else if ((ir-1)->o < IR_EQ) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64(as, ir); + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64eq(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + as->curins--; /* Handle both stores here. */ + if ((ir-1)->r != RID_SINK) { + asm_xstore(as, ir, LJ_LE ? 4 : 0); + asm_xstore(as, ir-1, LJ_LE ? 0 : 4); + } + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: as->curins--; asm_add64(as, ir); break; + case IR_SUB: as->curins--; asm_sub64(as, ir); break; + case IR_NEG: as->curins--; asm_neg64(as, ir); break; + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */ + Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE; + ExitNo oldsnap = as->snapno; + rset_clear(allow, pbase); + tmp = allow ? rset_pickbot(allow) : + (pbase == RID_RETHI ? RID_RETLO : RID_RETHI); + as->snapno = exitno; + asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO); + as->snapno = oldsnap; + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_tsi(as, MIPSI_LW, tmp, RID_SP, 0); + else + ra_modified(as, tmp); + emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot)); + emit_dst(as, MIPSI_SUBU, RID_TMP, tmp, pbase); + emit_tsi(as, MIPSI_LW, tmp, tmp, offsetof(lua_State, maxstack)); + if (pbase == RID_TMP) + emit_getgl(as, RID_TMP, jit_base); + emit_getgl(as, tmp, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_tsi(as, MIPSI_SW, tmp, RID_SP, 0); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs); + } else { + Reg type; + RegSet allow = rset_exclude(RSET_GPR, RID_BASE); + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + rset_clear(allow, src); + emit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0)); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), allow); + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + } + emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4)); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + /* Assumes asm_snap_prep() already done. */ + asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + tmp = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end); + emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp); + emit_getgl(as, tmp, gc.threshold); + emit_getgl(as, RID_TMP, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + p[-1] = MIPSI_NOP; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guard already inverted the cond branch. Only patch the target. */ + p[-3] |= ((target-p+2) & 0x0000ffffu); + } else { + p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (as->loopinv) as->mctop--; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_move(as, r, RID_BASE); + } +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (as->loopinv) as->mctop--; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_move(as, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp; + int32_t spadj = as->T->spadjust; + MCode *p = as->mctop-1; + *p = spadj ? (MIPSI_ADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP; + p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + as->mcp = as->mctop-2; /* Leave room for branch plus nop or stack adj. */ + as->invmcp = as->loopref ? as->mcp : NULL; +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: asm_compeq(as, ir); break; + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: + asm_comp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitnot(as, ir); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI); break; + case IR_BOR: asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI); break; + case IR_BXOR: asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI); break; + + case IR_BSHL: asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL); break; + case IR_BSHR: asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL); break; + case IR_BSAR: asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA); break; + case IR_BROL: lua_assert(0); break; + case IR_BROR: asm_bitror(as, ir); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: asm_sub(as, ir); break; + case IR_MUL: asm_mul(as, ir); break; + case IR_DIV: asm_fparith(as, ir, MIPSI_DIV_D); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_NEG: asm_neg(as, ir); break; + + case IR_ABS: asm_fpunary(as, ir, MIPSI_ABS_D); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_MIN: asm_min_max(as, ir, 0); break; + case IR_MAX: asm_min_max(as, ir, 1); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 <= IRFPM_TRUNC) + asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2); + else if (ir->op2 == IRFPM_SQRT) + asm_fpunary(as, ir, MIPSI_SQRT_D); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + + /* Overflow-checking arithmetic ops. */ + case IR_ADDOV: asm_arithov(as, ir); break; + case IR_SUBOV: asm_arithov(as, ir); break; + case IR_MULOV: asm_mulov(as, ir); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) { + if (args[i] && irt_isfp(IR(args[i])->t) && + nfpr > 0 && !(ci->flags & CCI_VARARG)) { + nfpr--; + ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1; + } else if (args[i] && irt_isnum(IR(args[i])->t)) { + nfpr = 0; + ngpr = ngpr & ~1; + if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1; + } else { + nfpr = 0; + if (ngpr > 0) ngpr--; else nslots++; + } + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + asm_sparejump_setup(as); + asm_exitstub_setup(as); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *px = exitstub_trace_addr(T, exitno); + MCode *cstart = NULL, *cstop = NULL; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno; + MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); + for (p++; p < pe; p++) { + if (*p == exitload) { /* Look for load of exit number. */ + if (((p[-1] ^ (px-p)) & 0xffffu) == 0) { /* Look for exitstub branch. */ + ptrdiff_t delta = target - p; + if (((delta + 0x8000) >> 16) == 0) { /* Patch in-range branch. */ + patchbranch: + p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu); + *p = MIPSI_NOP; /* Replace the load of the exit number. */ + cstop = p; + if (!cstart) cstart = p-1; + } else { /* Branch out of range. Use spare jump slot in mcarea. */ + int i; + for (i = 2; i < 2+MIPS_SPAREJUMP*2; i += 2) { + if (mcarea[i] == tjump) { + delta = mcarea+i - p; + goto patchbranch; + } else if (mcarea[i] == MIPSI_NOP) { + mcarea[i] = tjump; + cstart = mcarea+i; + delta = mcarea+i - p; + goto patchbranch; + } + } + /* Ignore jump slot overflow. Child trace is simply not attached. */ + } + } else if (p+1 == pe) { + /* Patch NOP after code for inverted loop branch. Use of J is ok. */ + lua_assert(p[1] == MIPSI_NOP); + p[1] = tjump; + *p = MIPSI_NOP; /* Replace the load of the exit number. */ + cstop = p+2; + if (!cstart) cstart = p+1; + } + } + } + if (cstart) lj_mcode_sync(cstart, cstop); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_ppc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_ppc.h new file mode 100644 index 0000000..e1a496a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_ppc.h @@ -0,0 +1,2167 @@ +/* +** PPC IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Register allocator extensions --------------------------------------- */ + +/* Allocate a register with a hint. */ +static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) +{ + Reg r = IR(ref)->r; + if (ra_noreg(r)) { + if (!ra_hashint(r) && !iscrossref(as, ref)) + ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ + r = ra_allocref(as, ref, allow); + } + ra_noweak(as, r); + return r; +} + +/* Allocate two source registers for three-operand instructions. */ +static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + Reg left = irl->r, right = irr->r; + if (ra_hasreg(left)) { + ra_noweak(as, left); + if (ra_noreg(right)) + right = ra_allocref(as, ir->op2, rset_exclude(allow, left)); + else + ra_noweak(as, right); + } else if (ra_hasreg(right)) { + ra_noweak(as, right); + left = ra_allocref(as, ir->op1, rset_exclude(allow, right)); + } else if (ra_hashint(right)) { + right = ra_allocref(as, ir->op2, allow); + left = ra_alloc1(as, ir->op1, rset_exclude(allow, right)); + } else { + left = ra_allocref(as, ir->op1, allow); + right = ra_alloc1(as, ir->op2, rset_exclude(allow, left)); + } + return left | (right << 8); +} + +/* -- Guard handling ------------------------------------------------------ */ + +/* Setup exit stubs after the end of each trace. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + MCode *mxp = as->mctop; + /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */ + for (i = nexits-1; (int32_t)i >= 0; i--) + *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2); + *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno; /* Read by exit handler. */ + mxp--; + *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2); + *--mxp = PPCI_MFLR|PPCF_T(RID_TMP); + as->mctop = mxp; +} + +static MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno) +{ + /* Keep this in-sync with exitstub_trace_addr(). */ + return as->mctop + exitno + 3; +} + +/* Emit conditional branch to exit for guard. */ +static void asm_guardcc(ASMState *as, PPCCC cc) +{ + MCode *target = asm_exitstub_addr(as, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2); + emit_condbranch(as, PPCI_BC, cc^4, p); + return; + } + emit_condbranch(as, PPCI_BC, cc, target); +} + +/* -- Operand fusion ------------------------------------------------------ */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if there's no conflicting instruction between curins and ref. */ +static int noconflict(ASMState *as, IRRef ref, IROp conflict) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + return 1; /* Ok, no conflict. */ +} + +/* Fuse the array base of colocated arrays. */ +static int32_t asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) + return (int32_t)sizeof(GCtab); + return 0; +} + +/* Indicates load/store indexed is ok. */ +#define AHUREF_LSX ((int32_t)0x80000000) + +/* Fuse array/hash/upvalue reference into register+offset operand. */ +static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + if (ir->o == IR_AREF) { + if (mayfuse(as, ref)) { + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, refa, allow); + } + } + if (*ofsp == AHUREF_LSX) { + Reg base = ra_alloc1(as, ir->op1, allow); + Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + return base | (idx << 8); + } + } + } else if (ir->o == IR_HREFK) { + if (mayfuse(as, ref)) { + int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + if (checki16(ofs)) { + *ofsp = ofs; + return ra_alloc1(as, ir->op1, allow); + } + } + } else if (ir->o == IR_UREFC) { + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); + int32_t jgl = (intptr_t)J2G(as->J); + if ((uint32_t)(ofs-jgl) < 65536) { + *ofsp = ofs-jgl-32768; + return RID_JGL; + } else { + *ofsp = (int16_t)ofs; + return ra_allock(as, ofs-(int16_t)ofs, allow); + } + } + } + } + *ofsp = 0; + return ra_alloc1(as, ref, allow); +} + +/* Fuse XLOAD/XSTORE reference into load/store operand. */ +static void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref, + RegSet allow, int32_t ofs) +{ + IRIns *ir = IR(ref); + Reg base; + if (ra_noreg(ir->r) && canfuse(as, ir)) { + if (ir->o == IR_ADD) { + int32_t ofs2; + if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) { + ofs = ofs2; + ref = ir->op1; + } else if (ofs == 0) { + Reg right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right); + return; + } + } else if (ir->o == IR_STRREF) { + lua_assert(ofs == 0); + ofs = (int32_t)sizeof(GCstr); + if (irref_isk(ir->op2)) { + ofs += IR(ir->op2)->i; + ref = ir->op1; + } else if (irref_isk(ir->op1)) { + ofs += IR(ir->op1)->i; + ref = ir->op2; + } else { + /* NYI: Fuse ADD with constant. */ + Reg tmp, right, left = ra_alloc2(as, ir, allow); + right = (left >> 8); left &= 255; + tmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right)); + emit_fai(as, pi, rt, tmp, ofs); + emit_tab(as, PPCI_ADD, tmp, left, right); + return; + } + if (!checki16(ofs)) { + Reg left = ra_alloc1(as, ref, allow); + Reg right = ra_allock(as, ofs, rset_exclude(allow, left)); + emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right); + return; + } + } + } + base = ra_alloc1(as, ref, allow); + emit_fai(as, pi, rt, base, ofs); +} + +/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */ +static void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref, + RegSet allow) +{ + IRIns *ira = IR(ref); + Reg right, left; + if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) { + left = ra_alloc2(as, ira, allow); + right = (left >> 8); left &= 255; + } else { + right = ra_alloc1(as, ref, allow); + left = RID_R0; + } + emit_tab(as, pi, rt, left, right); +} + +/* Fuse to multiply-add/sub instruction. */ +static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir) +{ + IRRef lref = ir->op1, rref = ir->op2; + IRIns *irm; + if (lref != rref && + ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && + ra_noreg(irm->r)) || + (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && + (rref = lref, pi = pir, ra_noreg(irm->r))))) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg add = ra_alloc1(as, rref, RSET_FPR); + Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add)); + right = (left >> 8); left &= 255; + emit_facb(as, pi, dest, left, right, add); + return 1; + } + return 0; +} + +/* -- Calls --------------------------------------------------------------- */ + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = 8; + Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR; + if ((void *)ci->func) + emit_call(as, (void *)ci->func); + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + if (ref) { + IRIns *ir = IR(ref); + if (irt_isfp(ir->t)) { + if (fpr <= REGARG_LASTFPR) { + lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */ + ra_leftov(as, fpr, ref); + fpr++; + } else { + Reg r = ra_alloc1(as, ref, RSET_FPR); + if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; + emit_spstore(as, ir, r, ofs); + ofs += irt_isnum(ir->t) ? 8 : 4; + } + } else { + if (gpr <= REGARG_LASTGPR) { + lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */ + ra_leftov(as, gpr, ref); + gpr++; + } else { + Reg r = ra_alloc1(as, ref, RSET_GPR); + emit_spstore(as, ir, r, ofs); + ofs += 4; + } + } + } else { + if (gpr <= REGARG_LASTGPR) + gpr++; + else + ofs += 4; + } + checkmclim(as); + } + if ((ci->flags & CCI_VARARG)) /* Vararg calls need to know about FPR use. */ + emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6); +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = ((ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + lua_assert(!irt_ispri(ir->t)); + if (irt_isfp(ir->t)) { + if ((ci->flags & CCI_CASTU64)) { + /* Use spill slot or temp slots. */ + int32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP; + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_fai(as, PPCI_LFD, dest, RID_SP, ofs); + } + emit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs); + emit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4); + } else { + ra_destreg(as, ir, RID_FPRET); + } + } else if (hiop) { + ra_destpair(as, ir); + } else { + ra_destreg(as, ir, RID_RET); + } + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + if (irref_isk(func)) { /* Call to constant address. */ + ci.func = (ASMFunction)(void *)(irf->i); + } else { /* Need a non-argument register for indirect calls. */ + RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1); + Reg freg = ra_alloc1(as, func, allow); + *--as->mcp = PPCI_BCTRL; + *--as->mcp = PPCI_MTCTR | PPCF_T(freg); + ci.func = (ASMFunction)(void *)0; + } + asm_gencall(as, &ci, args); +} + +static void asm_callid(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_ab(as, PPCI_CMPW, RID_TMP, + ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); + emit_tai(as, PPCI_LWZ, RID_TMP, base, -8); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + RegSet allow = RSET_FPR; + Reg tmp = ra_scratch(as, rset_clear(allow, left)); + Reg fbias = ra_scratch(as, rset_clear(allow, tmp)); + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest)); + asm_guardcc(as, CC_NE); + emit_fab(as, PPCI_FCMPU, 0, tmp, left); + emit_fab(as, PPCI_FSUB, tmp, tmp, fbias); + emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP); + emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000); + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_lsptr(as, PPCI_LFS, (fbias & 31), + (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)), + RSET_GPR); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, left); +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_FPR; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, allow); + Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); + Reg tmp = ra_scratch(as, rset_clear(allow, right)); + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fab(as, PPCI_FADD, tmp, left, right); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(irt_isint64(ir->t) || + (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + if (st == IRT_NUM) /* double -> float conversion. */ + emit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR)); + else /* float -> double conversion is a no-op on PPC. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else { /* Integer to FP conversion. */ + /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */ + /* IRT_U32: Bias with 2^52, subtract 2^52. */ + RegSet allow = RSET_GPR; + Reg left = ra_alloc1(as, lref, allow); + Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left)); + Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + const float *kbias; + if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest); + emit_fab(as, PPCI_FSUB, dest, dest, fbias); + emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP); + kbias = (const float *)lj_ir_k64_find(as->J, U64x(59800004,59800000)); + if (st == IRT_U32) kbias++; + emit_lsptr(as, PPCI_LFS, (fbias & 31), (void *)kbias, + rset_clear(allow, hibias)); + emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP, + RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000); + } + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, lref, RSET_FPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + if (irt_isu32(ir->t)) { + /* Convert both x and x-2^31 to int and merge results. */ + Reg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest)); + emit_asb(as, PPCI_OR, dest, dest, tmpi); /* Select with mask idiom. */ + emit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP); + emit_asb(as, PPCI_ANDC, dest, dest, RID_TMP); + emit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO); /* tmp = (int)(x) */ + emit_tai(as, PPCI_ADDIS, dest, dest, 0x8000); /* dest += 2^31 */ + emit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31); /* mask = -(dest < 0) */ + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_tai(as, PPCI_LWZ, dest, + RID_SP, SPOFS_TMPLO); /* dest = (int)(x-2^31) */ + emit_fb(as, PPCI_FCTIWZ, tmp, left); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, tmp); + emit_fab(as, PPCI_FSUB, tmp, left, tmp); + emit_lsptr(as, PPCI_LFS, (tmp & 31), + (void *)lj_ir_k64_find(as->J, U64x(4f000000,00000000)), + RSET_GPR); + } else { + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, tmp, left); + } + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if ((ir->op2 & IRCONV_SEXT)) + emit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left); + else + emit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31); + } else { /* 32/64 bit integer conversions. */ + /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */ + ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } +} + +#if LJ_HASFFI +static void asm_conv64(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + IRCallID id; + const CCallInfo *ci; + IRRef args[2]; + args[0] = ir->op1; + args[1] = (ir-1)->op1; + if (st == IRT_NUM || st == IRT_FLOAT) { + id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64); + ir--; + } else { + id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64); + } + ci = &lj_ir_callinfo[id]; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + int32_t ofs; + RegSet drop = RSET_SCRATCH; + if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */ + ra_evictset(as, drop); + asm_guardcc(as, CC_EQ); + emit_ai(as, PPCI_CMPWI, RID_RET, 0); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP; + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs); +} + +/* Get pointer to TValue. */ +static void asm_tvptr(ASMState *as, Reg dest, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isnum(ir->t)) { + if (irref_isk(ref)) /* Use the number constant itself as a TValue. */ + ra_allockreg(as, i32ptr(ir_knum(ir)), dest); + else /* Otherwise force a spill and use the spill slot. */ + emit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + RegSet allow = rset_exclude(RSET_GPR, dest); + Reg type; + emit_tai(as, PPCI_ADDI, dest, RID_JGL, offsetof(global_State, tmptv)-32768); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + emit_setgl(as, src, tmptv.gcr); + } + type = ra_allock(as, irt_toitype(ir->t), allow); + emit_setgl(as, type, tmptv.it); + } +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx, base; + if (irref_isk(ir->op2)) { + IRRef tab = IR(ir->op1)->op1; + int32_t ofs = asm_fuseabase(as, tab); + IRRef refa = ofs ? tab : ir->op1; + ofs += 8*IR(ir->op2)->i; + if (checki16(ofs)) { + base = ra_alloc1(as, refa, RSET_GPR); + emit_tai(as, PPCI_ADDI, dest, base, ofs); + return; + } + } + base = ra_alloc1(as, ir->op1, RSET_GPR); + idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); + emit_tab(as, PPCI_ADD, dest, RID_TMP, base); + emit_slwi(as, RID_TMP, idx, 3); +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir, IROp merge) +{ + RegSet allow = RSET_GPR; + int destused = ra_used(ir); + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, tmp1 = RID_TMP, tmp2; + Reg tisnum = RID_NONE, tmpnum = RID_NONE; + IRRef refkey = ir->op2; + IRIns *irkey = IR(refkey); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + rset_clear(allow, tab); + if (irt_isnum(kt)) { + key = ra_alloc1(as, refkey, RSET_FPR); + tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key)); + tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow); + rset_clear(allow, tisnum); + } else if (!irt_ispri(kt)) { + key = ra_alloc1(as, refkey, allow); + rset_clear(allow, key); + } + tmp2 = ra_scratch(as, allow); + rset_clear(allow, tmp2); + + /* Key not found in chain: jump to exit (if merged) or load niltv. */ + l_end = emit_label(as); + as->invmcp = NULL; + if (merge == IR_NE) + asm_guardcc(as, CC_EQ); + else if (destused) + emit_loada(as, dest, niltvg(J2G(as->J))); + + /* Follow hash chain until the end. */ + l_loop = --as->mcp; + emit_ai(as, PPCI_CMPWI, dest, 0); + emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (merge == IR_EQ) + asm_guardcc(as, CC_EQ); + else + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + if (irt_isnum(kt)) { + emit_fab(as, PPCI_FCMPU, 0, tmpnum, key); + emit_condbranch(as, PPCI_BC, CC_GE, l_next); + emit_ab(as, PPCI_CMPLW, tmp1, tisnum); + emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n)); + } else { + if (!irt_ispri(kt)) { + emit_ab(as, PPCI_CMPW, tmp2, key); + emit_condbranch(as, PPCI_BC, CC_NE, l_next); + } + emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t)); + if (!irt_ispri(kt)) + emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr)); + } + emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it)); + *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) | + (((char *)as->mcp-(char *)l_loop) & 0xffffu); + + /* Load main position relative to tab->node into dest. */ + khash = irref_isk(refkey) ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node)); + } else { + Reg tmphash = tmp1; + if (irref_isk(refkey)) + tmphash = ra_allock(as, khash, allow); + emit_tab(as, PPCI_ADD, dest, dest, tmp1); + emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node)); + emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash); + emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node)); + emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask)); + if (irref_isk(refkey)) { + /* Nothing to do. */ + } else if (irt_isstr(kt)) { + emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, hash)); + } else { /* Must match with hash*() in lj_tab.c. */ + emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1); + emit_rotlwi(as, tmp2, tmp2, HASH_ROT3); + emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2); + emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31); + emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2); + if (irt_isnum(kt)) { + int32_t ofs = ra_spill(as, irkey); + emit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1); + emit_rotlwi(as, dest, tmp1, HASH_ROT1); + emit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1); + emit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4); + emit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs); + } else { + emit_asb(as, PPCI_XOR, tmp2, key, tmp1); + emit_rotlwi(as, dest, tmp1, HASH_ROT1); + emit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS); + emit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + int32_t kofs = ofs + (int32_t)offsetof(Node, key); + Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); + Reg key = RID_NONE, type = RID_TMP, idx = node; + RegSet allow = rset_exclude(RSET_GPR, node); + lua_assert(ofs % sizeof(Node) == 0); + if (ofs > 32736) { + idx = dest; + rset_clear(allow, dest); + kofs = (int32_t)offsetof(Node, key); + } else if (ra_hasreg(dest)) { + emit_tai(as, PPCI_ADDI, dest, node, ofs); + } + asm_guardcc(as, CC_NE); + if (!irt_ispri(irkey->t)) { + key = ra_scratch(as, allow); + rset_clear(allow, key); + } + rset_clear(allow, type); + if (irt_isnum(irkey->t)) { + emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo); + asm_guardcc(as, CC_NE); + emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi); + } else { + if (ra_hasreg(key)) { + emit_cmpi(as, key, irkey->i); /* May use RID_TMP, i.e. type. */ + asm_guardcc(as, CC_NE); + } + emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t)); + } + if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4); + emit_tai(as, PPCI_LWZ, type, idx, kofs); + if (ofs > 32736) { + emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16); + emit_tai(as, PPCI_ADDI, dest, node, ofs); + } +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2); +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, RID_TMP, 1); + emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv)); + emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); + } else { + emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v)); + } + emit_tai(as, PPCI_LWZ, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + UNUSED(as); UNUSED(ir); + lua_assert(!ra_used(ir)); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRRef ref = ir->op2, refk = ir->op1; + int32_t ofs = (int32_t)sizeof(GCstr); + Reg r; + if (irref_isk(ref)) { + IRRef tmp = refk; refk = ref; ref = tmp; + } else if (!irref_isk(refk)) { + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + IRIns *irr = IR(ir->op2); + if (ra_hasreg(irr->r)) { + ra_noweak(as, irr->r); + right = irr->r; + } else if (mayfuse(as, irr->op2) && + irr->o == IR_ADD && irref_isk(irr->op2) && + checki16(ofs + IR(irr->op2)->i)) { + ofs += IR(irr->op2)->i; + right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); + } else { + right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tai(as, PPCI_ADDI, dest, dest, ofs); + emit_tab(as, PPCI_ADD, dest, left, right); + return; + } + r = ra_alloc1(as, ref, RSET_GPR); + ofs += IR(refk)->i; + if (checki16(ofs)) + emit_tai(as, PPCI_ADDI, dest, r, ofs); + else + emit_tab(as, PPCI_ADD, dest, r, + ra_allock(as, ofs, rset_exclude(RSET_GPR, r))); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static PPCIns asm_fxloadins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: return PPCI_LBZ; /* Needs sign-extension. */ + case IRT_U8: return PPCI_LBZ; + case IRT_I16: return PPCI_LHA; + case IRT_U16: return PPCI_LHZ; + case IRT_NUM: return PPCI_LFD; + case IRT_FLOAT: return PPCI_LFS; + default: return PPCI_LWZ; + } +} + +static PPCIns asm_fxstoreins(IRIns *ir) +{ + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: return PPCI_STB; + case IRT_I16: case IRT_U16: return PPCI_STH; + case IRT_NUM: return PPCI_STFD; + case IRT_FLOAT: return PPCI_STFS; + default: return PPCI_STW; + } +} + +static void asm_fload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); + PPCIns pi = asm_fxloadins(ir); + int32_t ofs; + if (ir->op2 == IRFL_TAB_ARRAY) { + ofs = asm_fuseabase(as, ir->op1); + if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ + emit_tai(as, PPCI_ADDI, dest, idx, ofs); + return; + } + } + ofs = field_ofs[ir->op2]; + lua_assert(!irt_isi8(ir->t)); + emit_tai(as, pi, dest, idx, ofs); +} + +static void asm_fstore(ASMState *as, IRIns *ir) +{ + if (ir->r != RID_SINK) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + IRIns *irf = IR(ir->op1); + Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); + int32_t ofs = field_ofs[irf->op2]; + PPCIns pi = asm_fxstoreins(ir); + emit_tai(as, pi, src, idx, ofs); + } +} + +static void asm_xload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED)); + if (irt_isi8(ir->t)) + emit_as(as, PPCI_EXTSB, dest, dest); + asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0); +} + +static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs) +{ + IRIns *irb; + if (ir->r == RID_SINK) + return; + if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP && + ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) { + /* Fuse BSWAP with XSTORE to stwbrx. */ + Reg src = ra_alloc1(as, irb->op1, RSET_GPR); + asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src)); + } else { + Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1, + rset_exclude(RSET_GPR, src), ofs); + } +} + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx; + RegSet allow = RSET_GPR; + int32_t ofs = AHUREF_LSX; + if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + if (!irt_isnum(t)) ofs = 0; + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(t)) { + Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx)); + asm_guardcc(as, CC_GE); + emit_ab(as, PPCI_CMPLW, type, tisnum); + if (ra_hasreg(dest)) { + if (ofs == AHUREF_LSX) { + tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, + (idx&255)), (idx>>8))); + emit_fab(as, PPCI_LFDX, dest, (idx&255), tmp); + } else { + emit_fai(as, PPCI_LFD, dest, idx, ofs); + } + } + } else { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, type, irt_toitype(t)); + if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4); + } + if (ofs == AHUREF_LSX) { + emit_tab(as, PPCI_LWZX, type, (idx&255), tmp); + emit_slwi(as, tmp, (idx>>8), 3); + } else { + emit_tai(as, PPCI_LWZ, type, idx, ofs); + } +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg idx, src = RID_NONE, type = RID_NONE; + int32_t ofs = AHUREF_LSX; + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + src = ra_alloc1(as, ir->op2, RSET_FPR); + } else { + if (!irt_ispri(ir->t)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + ofs = 0; + } + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + rset_clear(allow, type); + } + idx = asm_fuseahuref(as, ir->op1, &ofs, allow); + if (irt_isnum(ir->t)) { + if (ofs == AHUREF_LSX) { + emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP); + emit_slwi(as, RID_TMP, (idx>>8), 3); + } else { + emit_fai(as, PPCI_STFD, src, idx, ofs); + } + } else { + if (ra_hasreg(src)) + emit_tai(as, PPCI_STW, src, idx, ofs+4); + if (ofs == AHUREF_LSX) { + emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP); + emit_slwi(as, RID_TMP, (idx>>8), 3); + } else { + emit_tai(as, PPCI_STW, type, idx, ofs); + } + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4); + IRType1 t = ir->t; + Reg dest = RID_NONE, type = RID_NONE, base; + RegSet allow = RSET_GPR; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(LJ_DUALNUM || + !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + dest = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, dest); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ + } else if (ra_used(ir)) { + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR); + rset_clear(allow, dest); + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); + if ((ir->op2 & IRSLOAD_CONVERT)) { + if (irt_isint(t)) { + emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO); + dest = ra_scratch(as, RSET_FPR); + emit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP); + emit_fb(as, PPCI_FCTIWZ, dest, dest); + t.irt = IRT_NUM; /* Check for original type. */ + } else { + Reg tmp = ra_scratch(as, allow); + Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp)); + Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + emit_fab(as, PPCI_FSUB, dest, dest, fbias); + emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP); + emit_lsptr(as, PPCI_LFS, (fbias & 31), + (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)), + rset_clear(allow, hibias)); + emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO); + emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI); + emit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000); + dest = tmp; + t.irt = IRT_INT; /* Check for original type. */ + } + } + goto dotypecheck; + } + base = ra_alloc1(as, REF_BASE, allow); + rset_clear(allow, base); +dotypecheck: + if (irt_isnum(t)) { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow); + asm_guardcc(as, CC_GE); + emit_ab(as, PPCI_CMPLW, RID_TMP, tisnum); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_fai(as, PPCI_LFD, dest, base, ofs-4); + } else { + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + asm_guardcc(as, CC_NE); + emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t)); + type = RID_TMP; + } + if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs); + } + if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4); +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + RegSet drop = RSET_SCRATCH; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + if (ra_used(ir)) + ra_destreg(as, ir, RID_RET); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + int32_t ofs = sizeof(GCcdata); + lua_assert(sz == 4 || sz == 8); + if (sz == 8) { + ofs += 4; + lua_assert((ir+1)->o == IR_HIOP); + } + for (;;) { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_tai(as, PPCI_STW, r, RID_RET, ofs); + rset_clear(allow, r); + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir++; + } + } + /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ + emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct)); + emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid)); + emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA); + emit_ti(as, PPCI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */ + asm_gencall(as, ci, args); + ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)), + ra_releasetmp(as, ASMREF_TMP1)); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + Reg link = RID_TMP; + MCLabel l_end = emit_label(as); + emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist)); + emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked)); + emit_setgl(as, tab, gc.grayagain); + lua_assert(LJ_GC_BLACK == 0x04); + emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28); /* Clear black bit. */ + emit_getgl(as, link, gc.grayagain); + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK); + emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj, val, tmp; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + obj = IR(ir->op1)->r; + tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK); + emit_condbranch(as, PPCI_BC, CC_EQ, l_end); + emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES); + val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); + emit_tai(as, PPCI_LBZ, tmp, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); + emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked)); +} + +/* -- Arithmetic and logic operations ------------------------------------- */ + +static void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (pi == PPCI_FMUL) + emit_fac(as, pi, dest, left, right); + else + emit_fab(as, pi, dest, left, right); +} + +static void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); + emit_fb(as, pi, dest, left); +} + +static int asm_fpjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow]; + IRRef args[2]; + args[0] = irpp->op1; + args[1] = irp->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); + return 1; + } + } + return 0; +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD)) + asm_fparith(as, ir, PPCI_FADD); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + PPCIns pi; + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + pi = PPCI_ADDI; + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi = PPCI_ADDICDOT; + } + emit_tai(as, pi, dest, left, k); + return; + } else if ((k & 0xffff) == 0) { + emit_tai(as, PPCI_ADDIS, dest, left, (k >> 16)); + return; + } else if (!as->sectref) { + emit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16); + emit_tai(as, PPCI_ADDI, dest, left, k); + return; + } + } + pi = PPCI_ADD; + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, left, right); + } +} + +static void asm_sub(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB)) + asm_fparith(as, ir, PPCI_FSUB); + } else { + PPCIns pi = PPCI_SUBF; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left, right; + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (checki16(k)) { + right = ra_alloc1(as, ir->op2, RSET_GPR); + emit_tai(as, PPCI_SUBFIC, dest, right, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */ + } +} + +static void asm_mul(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fparith(as, ir, PPCI_FMUL); + } else { + PPCIns pi = PPCI_MULLW; + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tai(as, PPCI_MULLI, dest, left, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, pi, dest, left, right); + } +} + +static void asm_neg(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) { + asm_fpunary(as, ir, PPCI_FNEG); + } else { + Reg dest, left; + PPCIns pi = PPCI_NEG; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + emit_tab(as, pi, dest, left, 0); + } +} + +static void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi) +{ + Reg dest, left, right; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + } + asm_guardcc(as, CC_SO); + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; } + emit_tab(as, pi|PPCF_DOT, dest, left, right); +} + +#if LJ_HASFFI +static void asm_add64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); + PPCIns pi = PPCI_ADDE; + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k == 0) + pi = PPCI_ADDZE; + else if (k == -1) + pi = PPCI_ADDME; + else + goto needright; + right = 0; + } else { + needright: + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + } + emit_tab(as, pi, dest, left, right); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (checki16(k)) { + emit_tai(as, PPCI_ADDIC, dest, left, k); + return; + } + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_tab(as, PPCI_ADDC, dest, left, right); +} + +static void asm_sub64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR); + PPCIns pi = PPCI_SUBFE; + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (k == 0) + pi = PPCI_SUBFZE; + else if (k == -1) + pi = PPCI_SUBFME; + else + goto needleft; + left = 0; + } else { + needleft: + left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right)); + } + emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */ + ir--; + dest = ra_dest(as, ir, RSET_GPR); + right = ra_alloc1(as, ir->op2, RSET_GPR); + if (irref_isk(ir->op1)) { + int32_t k = IR(ir->op1)->i; + if (checki16(k)) { + emit_tai(as, PPCI_SUBFIC, dest, right, k); + return; + } + } + left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right)); + emit_tab(as, PPCI_SUBFC, dest, right, left); +} + +static void asm_neg64(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_tab(as, PPCI_SUBFZE, dest, left, 0); + ir--; + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + emit_tai(as, PPCI_SUBFIC, dest, left, 0); +} +#endif + +static void asm_bitnot(ASMState *as, IRIns *ir) +{ + Reg dest, left, right; + PPCIns pi = PPCI_NOR; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + if (mayfuse(as, ir->op1)) { + IRIns *irl = IR(ir->op1); + if (irl->o == IR_BAND) + pi ^= (PPCI_NOR ^ PPCI_NAND); + else if (irl->o == IR_BXOR) + pi ^= (PPCI_NOR ^ PPCI_EQV); + else if (irl->o != IR_BOR) + goto nofuse; + left = ra_hintalloc(as, irl->op1, dest, RSET_GPR); + right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left)); + } else { +nofuse: + left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + } + emit_asb(as, pi, dest, left, right); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + IRIns *irx; + if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD && + ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) { + /* Fuse BSWAP with XLOAD to lwbrx. */ + asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR); + } else { + Reg left = ra_alloc1(as, ir->op1, RSET_GPR); + Reg tmp = dest; + if (tmp == left) { + tmp = RID_TMP; + emit_mr(as, dest, RID_TMP); + } + emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23); + emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7); + emit_rotlwi(as, tmp, left, 8); + } +} + +static void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + Reg tmp = left; + if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) { + if (!checku16(k)) { + emit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16)); + if ((k & 0xffff) == 0) return; + } + emit_asi(as, pik, dest, left, k); + return; + } + } + /* May fail due to spills/restores above, but simplifies the logic. */ + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + pi |= PPCF_DOT; + } + right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, pi, dest, left, right); +} + +/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */ +static void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref) +{ + IRIns *ir; + Reg left; + if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) && + irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) { + int32_t sh = (IR(ir->op2)->i & 31); + switch (ir->o) { + case IR_BSHL: + if ((mask & ((1u<>sh))) goto nofuse; + sh = ((32-sh)&31); + break; + case IR_BROL: + break; + default: + goto nofuse; + } + left = ra_alloc1(as, ir->op1, RSET_GPR); + *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh); + return; + } +nofuse: + left = ra_alloc1(as, ref, RSET_GPR); + *--as->mcp = pi | PPCF_T(left); +} + +static void asm_bitand(ASMState *as, IRIns *ir) +{ + Reg dest, left, right; + IRRef lref = ir->op1; + PPCIns dot = 0; + IRRef op2; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + dot = PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (k) { + /* First check for a contiguous bitmask as used by rlwinm. */ + uint32_t s1 = lj_ffs((uint32_t)k); + uint32_t k1 = ((uint32_t)k >> s1); + if ((k1 & (k1+1)) == 0) { + asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) | + PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1), + k, lref); + return; + } + if (~(uint32_t)k) { + uint32_t s2 = lj_ffs(~(uint32_t)k); + uint32_t k2 = (~(uint32_t)k >> s2); + if ((k2 & (k2+1)) == 0) { + asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) | + PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)), + k, lref); + return; + } + } + } + if (checku16(k)) { + left = ra_alloc1(as, lref, RSET_GPR); + emit_asi(as, PPCI_ANDIDOT, dest, left, k); + return; + } else if ((k & 0xffff) == 0) { + left = ra_alloc1(as, lref, RSET_GPR); + emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16)); + return; + } + } + op2 = ir->op2; + if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) { + dot ^= (PPCI_AND ^ PPCI_ANDC); + op2 = IR(op2)->op1; + } + left = ra_hintalloc(as, lref, dest, RSET_GPR); + right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, PPCI_AND ^ dot, dest, left, right); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik) +{ + Reg dest, left; + Reg dot = 0; + if (as->flagmcp == as->mcp) { + as->flagmcp = NULL; + as->mcp++; + dot = PPCF_DOT; + } + dest = ra_dest(as, ir, RSET_GPR); + left = ra_alloc1(as, ir->op1, RSET_GPR); + if (irref_isk(ir->op2)) { /* Constant shifts. */ + int32_t shift = (IR(ir->op2)->i & 31); + if (pik == 0) /* SLWI */ + emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift); + else if (pik == 1) /* SRWI */ + emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31); + else + emit_asb(as, pik|dot, dest, left, shift); + } else { + Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); + emit_asb(as, pi|dot, dest, left, right); + } +} + +static void asm_min_max(ASMState *as, IRIns *ir, int ismax) +{ + if (irt_isnum(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg tmp = dest; + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + if (tmp == left || tmp == right) + tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR, + dest), left), right)); + emit_facb(as, PPCI_FSEL, dest, tmp, + ismax ? left : right, ismax ? right : left); + emit_fab(as, PPCI_FSUB, tmp, left, right); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg tmp1 = RID_TMP, tmp2 = dest; + Reg right, left = ra_alloc2(as, ir, RSET_GPR); + right = (left >> 8); left &= 255; + if (tmp2 == left || tmp2 == right) + tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, + dest), left), right)); + emit_tab(as, PPCI_ADD, dest, tmp2, right); + emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1); + emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1); + emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1); + emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000); + emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000); + } +} + +/* -- Comparisons --------------------------------------------------------- */ + +#define CC_UNSIGNED 0x08 /* Unsigned integer comparison. */ +#define CC_TWO 0x80 /* Check two flags for FP comparison. */ + +/* Map of comparisons to flags. ORDER IR. */ +static const uint8_t asm_compmap[IR_ABC+1] = { + /* op int cc FP cc */ + /* LT */ CC_GE + (CC_GE<<4), + /* GE */ CC_LT + (CC_LE<<4) + CC_TWO, + /* LE */ CC_GT + (CC_GE<<4) + CC_TWO, + /* GT */ CC_LE + (CC_LE<<4), + /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO, + /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4), + /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4), + /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO, + /* EQ */ CC_NE + (CC_NE<<4), + /* NE */ CC_EQ + (CC_EQ<<4), + /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO /* Same as UGT. */ +}; + +static void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc) +{ + Reg right, left = ra_alloc1(as, lref, RSET_GPR); + if (irref_isk(rref)) { + int32_t k = IR(rref)->i; + if ((cc & CC_UNSIGNED) == 0) { /* Signed comparison with constant. */ + if (checki16(k)) { + emit_tai(as, PPCI_CMPWI, cr, left, k); + /* Signed comparison with zero and referencing previous ins? */ + if (k == 0 && lref == as->curins-1) + as->flagmcp = as->mcp; /* Allow elimination of the compare. */ + return; + } else if ((cc & 3) == (CC_EQ & 3)) { /* Use CMPLWI for EQ or NE. */ + if (checku16(k)) { + emit_tai(as, PPCI_CMPLWI, cr, left, k); + return; + } else if (!as->sectref && ra_noreg(IR(rref)->r)) { + emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k); + emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16)); + return; + } + } + } else { /* Unsigned comparison with constant. */ + if (checku16(k)) { + emit_tai(as, PPCI_CMPLWI, cr, left, k); + return; + } + } + } + right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left)); + emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right); +} + +static void asm_comp(ASMState *as, IRIns *ir) +{ + PPCCC cc = asm_compmap[ir->o]; + if (irt_isnum(ir->t)) { + Reg right, left = ra_alloc2(as, ir, RSET_FPR); + right = (left >> 8); left &= 255; + asm_guardcc(as, (cc >> 4)); + if ((cc & CC_TWO)) + emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3)); + emit_fab(as, PPCI_FCMPU, 0, left, right); + } else { + IRRef lref = ir->op1, rref = ir->op2; + if (irref_isk(lref) && !irref_isk(rref)) { + /* Swap constants to the right (only for ABC). */ + IRRef tmp = lref; lref = rref; rref = tmp; + if ((cc & 2) == 0) cc ^= 1; /* LT <-> GT, LE <-> GE */ + } + asm_guardcc(as, cc); + asm_intcomp_(as, lref, rref, 0, cc); + } +} + +#if LJ_HASFFI +/* 64 bit integer comparisons. */ +static void asm_comp64(ASMState *as, IRIns *ir) +{ + PPCCC cc = asm_compmap[(ir-1)->o]; + if ((cc&3) == (CC_EQ&3)) { + asm_guardcc(as, cc); + emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR, + (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3)); + } else { + asm_guardcc(as, CC_EQ); + emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1)); + emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC, + (CC_EQ&3), (CC_EQ&3), 4+(cc&3)); + } + /* Loword comparison sets cr1 and is unsigned, except for equality. */ + asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4, + cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED)); + /* Hiword comparison sets cr0. */ + asm_intcomp_(as, ir->op1, ir->op2, 0, cc); + as->flagmcp = NULL; /* Doesn't work here. */ +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + as->curins--; /* Always skip the CONV. */ + if (usehi || uselo) + asm_conv64(as, ir); + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + as->curins--; /* Always skip the loword comparison. */ + asm_comp64(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + as->curins--; /* Handle both stores here. */ + if ((ir-1)->r != RID_SINK) { + asm_xstore(as, ir, 0); + asm_xstore(as, ir-1, 4); + } + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: as->curins--; asm_add64(as, ir); break; + case IR_SUB: as->curins--; asm_sub64(as, ir); break; + case IR_NEG: as->curins--; asm_neg64(as, ir); break; + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by lo op itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */ + Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE; + rset_clear(allow, pbase); + tmp = allow ? rset_pickbot(allow) : + (pbase == RID_RETHI ? RID_RETLO : RID_RETHI); + emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno)); + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW); + else + ra_modified(as, tmp); + emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot)); + emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp); + emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack)); + if (pbase == RID_TMP) + emit_getgl(as, RID_TMP, jit_base); + emit_getgl(as, tmp, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_fai(as, PPCI_STFD, src, RID_BASE, ofs); + } else { + Reg type; + RegSet allow = rset_exclude(RSET_GPR, RID_BASE); + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t)); + if (!irt_ispri(ir->t)) { + Reg src = ra_alloc1(as, ref, allow); + rset_clear(allow, src); + emit_tai(as, PPCI_STW, src, RID_BASE, ofs+4); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s == 0) continue; /* Do not overwrite link to previous frame. */ + type = ra_allock(as, (int32_t)(*flinks--), allow); + } else { + type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); + } + emit_tai(as, PPCI_STW, type, RID_BASE, ofs); + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_ai(as, PPCI_CMPWI, RID_RET, 0); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768); + tmp = ra_releasetmp(as, ASMREF_TMP2); + emit_loadi(as, tmp, as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end); + emit_ab(as, PPCI_CMPLW, RID_TMP, tmp); + emit_getgl(as, tmp, gc.threshold); + emit_getgl(as, RID_TMP, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the cond branch and patched the final b. */ + p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2); + } else { + p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2); + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_mr(as, r, RID_BASE); + } +} + +/* Coalesce BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_mr(as, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + MCode *p = as->mctop; + MCode *target; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + *--p = PPCI_NOP; + *--p = PPCI_NOP; + as->mctop = p; + } else { + /* Patch stack adjustment. */ + lua_assert(checki16(CFRAME_SIZE+spadj)); + p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj); + p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj; + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2); +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop - 1; /* Leave room for exit branch. */ + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + as->mcp = p-2; /* Leave room for stack pointer adjustment. */ + as->invmcp = NULL; + } +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_EQ: case IR_NE: + if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) { + as->curins--; + asm_href(as, ir-1, (IROp)ir->o); + break; + } + /* fallthrough */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_ABC: + asm_comp(as, ir); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_bitnot(as, ir); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_bitand(as, ir); break; + case IR_BOR: asm_bitop(as, ir, PPCI_OR, PPCI_ORI); break; + case IR_BXOR: asm_bitop(as, ir, PPCI_XOR, PPCI_XORI); break; + + case IR_BSHL: asm_bitshift(as, ir, PPCI_SLW, 0); break; + case IR_BSHR: asm_bitshift(as, ir, PPCI_SRW, 1); break; + case IR_BSAR: asm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI); break; + case IR_BROL: asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31), + PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31)); break; + case IR_BROR: lua_assert(0); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: asm_sub(as, ir); break; + case IR_MUL: asm_mul(as, ir); break; + case IR_DIV: asm_fparith(as, ir, PPCI_FDIV); break; + case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break; + case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break; + case IR_NEG: asm_neg(as, ir); break; + + case IR_ABS: asm_fpunary(as, ir, PPCI_FABS); break; + case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break; + case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break; + case IR_MIN: asm_min_max(as, ir, 0); break; + case IR_MAX: asm_min_max(as, ir, 1); break; + case IR_FPMATH: + if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) + break; + if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT)) + asm_fpunary(as, ir, PPCI_FSQRT); + else + asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); + break; + + /* Overflow-checking arithmetic ops. */ + case IR_ADDOV: asm_arithov(as, ir, PPCI_ADDO); break; + case IR_SUBOV: asm_arithov(as, ir, PPCI_SUBFO); break; + case IR_MULOV: asm_arithov(as, ir, PPCI_MULLWO); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir, 0); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: asm_fload(as, ir); break; + case IR_XLOAD: asm_xload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: asm_fstore(as, ir); break; + case IR_XSTORE: asm_xstore(as, ir, 0); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_CONV: asm_conv(as, ir); break; + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + uint32_t i, nargs = (int)CCI_NARGS(ci); + int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + asm_collectargs(as, ir, ci, args); + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +} + +static void asm_setup_target(ASMState *as) +{ + asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0)); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *pe = (MCode *)((char *)p + T->szmcode); + MCode *px = exitstub_trace_addr(T, exitno); + MCode *cstart = NULL; + MCode *mcarea = lj_mcode_patch(J, p, 0); + int clearso = 0; + for (; p < pe; p++) { + /* Look for exitstub branch, try to replace with branch to target. */ + uint32_t ins = *p; + if ((ins & 0xfc000000u) == 0x40000000u && + ((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) { + ptrdiff_t delta = (char *)target - (char *)p; + if (((ins >> 16) & 3) == (CC_SO&3)) { + clearso = sizeof(MCode); + delta -= sizeof(MCode); + } + /* Many, but not all short-range branches can be patched directly. */ + if (((delta + 0x8000) >> 16) == 0) { + *p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) | + ((delta & 0x8000) * (PPCF_Y/0x8000)); + if (!cstart) cstart = p; + } + } else if ((ins & 0xfc000000u) == PPCI_B && + ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) { + ptrdiff_t delta = (char *)target - (char *)p; + lua_assert(((delta + 0x02000000) >> 26) == 0); + *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu); + if (!cstart) cstart = p; + } + } + { /* Always patch long-range branch in exit stub itself. */ + ptrdiff_t delta = (char *)target - (char *)px - clearso; + lua_assert(((delta + 0x02000000) >> 26) == 0); + *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu); + } + if (!cstart) cstart = px; + lj_mcode_sync(cstart, px+1); + if (clearso) { /* Extend the current trace. Ugly workaround. */ + MCode *pp = J->cur.mcode; + J->cur.szmcode += sizeof(MCode); + *--pp = PPCI_MCRXR; /* Clear SO flag. */ + J->cur.mcode = pp; + lj_mcode_sync(pp, pp+1); + } + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_x86.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_x86.h new file mode 100644 index 0000000..fda911e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_asm_x86.h @@ -0,0 +1,2794 @@ +/* +** x86/x64 IR assembler (SSA IR -> machine code). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Guard handling ------------------------------------------------------ */ + +/* Generate an exit stub group at the bottom of the reserved MCode memory. */ +static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) +{ + ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff; + MCode *mxp = as->mcbot; + MCode *mxpstart = mxp; + if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop) + asm_mclimit(as); + /* Push low byte of exitno for each exit stub. */ + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs; + for (i = 1; i < EXITSTUBS_PER_GROUP; i++) { + *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2); + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i); + } + /* Push the high byte of the exitno for each exit stub group. */ + *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8); + /* Store DISPATCH at original stack slot 0. Account for the two push ops. */ + *mxp++ = XI_MOVmi; + *mxp++ = MODRM(XM_OFS8, 0, RID_ESP); + *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + *mxp++ = 2*sizeof(void *); + *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4; + /* Jump to exit handler which fills in the ExitState. */ + *mxp++ = XI_JMP; mxp += 4; + *((int32_t *)(mxp-4)) = jmprel(mxp, (MCode *)(void *)lj_vm_exit_handler); + /* Commit the code for this group (even if assembly fails later on). */ + lj_mcode_commitbot(as->J, mxp); + as->mcbot = mxp; + as->mclim = as->mcbot + MCLIM_REDZONE; + return mxpstart; +} + +/* Setup all needed exit stubs. */ +static void asm_exitstub_setup(ASMState *as, ExitNo nexits) +{ + ExitNo i; + if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) + lj_trace_err(as->J, LJ_TRERR_SNAPOV); + for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++) + if (as->J->exitstubgroup[i] == NULL) + as->J->exitstubgroup[i] = asm_exitstub_gen(as, i); +} + +/* Emit conditional branch to exit for guard. +** It's important to emit this *after* all registers have been allocated, +** because rematerializations may invalidate the flags. +*/ +static void asm_guardcc(ASMState *as, int cc) +{ + MCode *target = exitstub_addr(as->J, as->snapno); + MCode *p = as->mcp; + if (LJ_UNLIKELY(p == as->invmcp)) { + as->loopinv = 1; + *(int32_t *)(p+1) = jmprel(p+5, target); + target = p; + cc ^= 1; + if (as->realign) { + emit_sjcc(as, cc, target); + return; + } + } + emit_jcc(as, cc, target); +} + +/* -- Memory operand fusion ----------------------------------------------- */ + +/* Limit linear search to this distance. Avoids O(n^2) behavior. */ +#define CONFLICT_SEARCH_LIM 31 + +/* Check if a reference is a signed 32 bit constant. */ +static int asm_isk32(ASMState *as, IRRef ref, int32_t *k) +{ + if (irref_isk(ref)) { + IRIns *ir = IR(ref); + if (ir->o != IR_KINT64) { + *k = ir->i; + return 1; + } else if (checki32((int64_t)ir_kint64(ir)->u64)) { + *k = (int32_t)ir_kint64(ir)->u64; + return 1; + } + } + return 0; +} + +/* Check if there's no conflicting instruction between curins and ref. +** Also avoid fusing loads if there are multiple references. +*/ +static int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload) +{ + IRIns *ir = as->ir; + IRRef i = as->curins; + if (i > ref + CONFLICT_SEARCH_LIM) + return 0; /* Give up, ref is too far away. */ + while (--i > ref) { + if (ir[i].o == conflict) + return 0; /* Conflict found. */ + else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref)) + return 0; + } + return 1; /* Ok, no conflict. */ +} + +/* Fuse array base into memory operand. */ +static IRRef asm_fuseabase(ASMState *as, IRRef ref) +{ + IRIns *irb = IR(ref); + as->mrm.ofs = 0; + if (irb->o == IR_FLOAD) { + IRIns *ira = IR(irb->op1); + lua_assert(irb->op2 == IRFL_TAB_ARRAY); + /* We can avoid the FLOAD of t->array for colocated arrays. */ + if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE && + !neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) { + as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */ + return irb->op1; /* Table obj. */ + } + } else if (irb->o == IR_ADD && irref_isk(irb->op2)) { + /* Fuse base offset (vararg load). */ + as->mrm.ofs = IR(irb->op2)->i; + return irb->op1; + } + return ref; /* Otherwise use the given array base. */ +} + +/* Fuse array reference into memory operand. */ +static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irx; + lua_assert(ir->o == IR_AREF); + as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow); + irx = IR(ir->op2); + if (irref_isk(ir->op2)) { + as->mrm.ofs += 8*irx->i; + as->mrm.idx = RID_NONE; + } else { + rset_clear(allow, as->mrm.base); + as->mrm.scale = XM_SCALE8; + /* Fuse a constant ADD (e.g. t[i+1]) into the offset. + ** Doesn't help much without ABCelim, but reduces register pressure. + */ + if (!LJ_64 && /* Has bad effects with negative index on x64. */ + mayfuse(as, ir->op2) && ra_noreg(irx->r) && + irx->o == IR_ADD && irref_isk(irx->op2)) { + as->mrm.ofs += 8*IR(irx->op2)->i; + as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow); + } else { + as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow); + } + } +} + +/* Fuse array/hash/upvalue reference into memory operand. +** Caveat: this may allocate GPRs for the base/idx registers. Be sure to +** pass the final allow mask, excluding any GPRs used for other inputs. +** In particular: 2-operand GPR instructions need to call ra_dest() first! +*/ +static void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_noreg(ir->r)) { + switch ((IROp)ir->o) { + case IR_AREF: + if (mayfuse(as, ref)) { + asm_fusearef(as, ir, allow); + return; + } + break; + case IR_HREFK: + if (mayfuse(as, ref)) { + as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); + as->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); + as->mrm.idx = RID_NONE; + return; + } + break; + case IR_UREFC: + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + GCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv; + as->mrm.ofs = ptr2addr(&uv->tv); + as->mrm.base = as->mrm.idx = RID_NONE; + return; + } + break; + default: + lua_assert(ir->o == IR_HREF || ir->o == IR_NEWREF || ir->o == IR_UREFO || + ir->o == IR_KKPTR); + break; + } + } + as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow); + as->mrm.ofs = 0; + as->mrm.idx = RID_NONE; +} + +/* Fuse FLOAD/FREF reference into memory operand. */ +static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow) +{ + lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF); + as->mrm.ofs = field_ofs[ir->op2]; + as->mrm.idx = RID_NONE; + if (irref_isk(ir->op1)) { + as->mrm.ofs += IR(ir->op1)->i; + as->mrm.base = RID_NONE; + } else { + as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow); + } +} + +/* Fuse string reference into memory operand. */ +static void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow) +{ + IRIns *irr; + lua_assert(ir->o == IR_STRREF); + as->mrm.base = as->mrm.idx = RID_NONE; + as->mrm.scale = XM_SCALE1; + as->mrm.ofs = sizeof(GCstr); + if (irref_isk(ir->op1)) { + as->mrm.ofs += IR(ir->op1)->i; + } else { + Reg r = ra_alloc1(as, ir->op1, allow); + rset_clear(allow, r); + as->mrm.base = (uint8_t)r; + } + irr = IR(ir->op2); + if (irref_isk(ir->op2)) { + as->mrm.ofs += irr->i; + } else { + Reg r; + /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */ + if (!LJ_64 && /* Has bad effects with negative index on x64. */ + mayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) { + as->mrm.ofs += IR(irr->op2)->i; + r = ra_alloc1(as, irr->op1, allow); + } else { + r = ra_alloc1(as, ir->op2, allow); + } + if (as->mrm.base == RID_NONE) + as->mrm.base = (uint8_t)r; + else + as->mrm.idx = (uint8_t)r; + } +} + +static void asm_fusexref(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + as->mrm.idx = RID_NONE; + if (ir->o == IR_KPTR || ir->o == IR_KKPTR) { + as->mrm.ofs = ir->i; + as->mrm.base = RID_NONE; + } else if (ir->o == IR_STRREF) { + asm_fusestrref(as, ir, allow); + } else { + as->mrm.ofs = 0; + if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) { + /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */ + IRIns *irx; + IRRef idx; + Reg r; + if (asm_isk32(as, ir->op2, &as->mrm.ofs)) { /* Recognize x+ofs. */ + ref = ir->op1; + ir = IR(ref); + if (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r))) + goto noadd; + } + as->mrm.scale = XM_SCALE1; + idx = ir->op1; + ref = ir->op2; + irx = IR(idx); + if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) { /* Try other operand. */ + idx = ir->op2; + ref = ir->op1; + irx = IR(idx); + } + if (canfuse(as, irx) && ra_noreg(irx->r)) { + if (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) { + /* Recognize idx<op1; + as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6); + } else if (irx->o == IR_ADD && irx->op1 == irx->op2) { + /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */ + idx = irx->op1; + as->mrm.scale = XM_SCALE2; + } + } + r = ra_alloc1(as, idx, allow); + rset_clear(allow, r); + as->mrm.idx = (uint8_t)r; + } + noadd: + as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow); + } +} + +/* Fuse load into memory operand. */ +static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow) +{ + IRIns *ir = IR(ref); + if (ra_hasreg(ir->r)) { + if (allow != RSET_EMPTY) { /* Fast path. */ + ra_noweak(as, ir->r); + return ir->r; + } + fusespill: + /* Force a spill if only memory operands are allowed (asm_x87load). */ + as->mrm.base = RID_ESP; + as->mrm.ofs = ra_spill(as, ir); + as->mrm.idx = RID_NONE; + return RID_MRM; + } + if (ir->o == IR_KNUM) { + RegSet avail = as->freeset & ~as->modset & RSET_FPR; + lua_assert(allow != RSET_EMPTY); + if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */ + as->mrm.ofs = ptr2addr(ir_knum(ir)); + as->mrm.base = as->mrm.idx = RID_NONE; + return RID_MRM; + } + } else if (mayfuse(as, ref)) { + RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR; + if (ir->o == IR_SLOAD) { + if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) && + noconflict(as, ref, IR_RETF, 0)) { + as->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow); + as->mrm.ofs = 8*((int32_t)ir->op1-1) + ((ir->op2&IRSLOAD_FRAME)?4:0); + as->mrm.idx = RID_NONE; + return RID_MRM; + } + } else if (ir->o == IR_FLOAD) { + /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */ + if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) && + noconflict(as, ref, IR_FSTORE, 0)) { + asm_fusefref(as, ir, xallow); + return RID_MRM; + } + } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) { + if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0)) { + asm_fuseahuref(as, ir->op1, xallow); + return RID_MRM; + } + } else if (ir->o == IR_XLOAD) { + /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp). + ** Fusing unaligned memory operands is ok on x86 (except for SIMD types). + */ + if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) && + noconflict(as, ref, IR_XSTORE, 0)) { + asm_fusexref(as, ir->op1, xallow); + return RID_MRM; + } + } else if (ir->o == IR_VLOAD) { + asm_fuseahuref(as, ir->op1, xallow); + return RID_MRM; + } + } + if (!(as->freeset & allow) && + (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref))) + goto fusespill; + return ra_allocref(as, ref, allow); +} + +#if LJ_64 +/* Don't fuse a 32 bit load into a 64 bit operation. */ +static Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64) +{ + if (is64 && !irt_is64(IR(ref)->t)) + return ra_alloc1(as, ref, allow); + return asm_fuseload(as, ref, allow); +} +#else +#define asm_fuseloadm(as, ref, allow, is64) asm_fuseload(as, (ref), (allow)) +#endif + +/* -- Calls --------------------------------------------------------------- */ + +/* Count the required number of stack slots for a call. */ +static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t i, nargs = CCI_NARGS(ci); + int nslots = 0; +#if LJ_64 + if (LJ_ABI_WIN) { + nslots = (int)(nargs*2); /* Only matters for more than four args. */ + } else { + int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + if (nfpr > 0) nfpr--; else nslots += 2; + } else { + if (ngpr > 0) ngpr--; else nslots += 2; + } + } +#else + int ngpr = 0; + if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL) + ngpr = 2; + else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL) + ngpr = 1; + for (i = 0; i < nargs; i++) + if (args[i] && irt_isfp(IR(args[i])->t)) { + nslots += irt_isnum(IR(args[i])->t) ? 2 : 1; + } else { + if (ngpr > 0) ngpr--; else nslots++; + } +#endif + return nslots; +} + +/* Generate a call to a C function. */ +static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) +{ + uint32_t n, nargs = CCI_NARGS(ci); + int32_t ofs = STACKARG_OFS; +#if LJ_64 + uint32_t gprs = REGARG_GPRS; + Reg fpr = REGARG_FIRSTFPR; +#if !LJ_ABI_WIN + MCode *patchnfpr = NULL; +#endif +#else + uint32_t gprs = 0; + if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) { + if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL) + gprs = (REGARG_GPRS & 31); + else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL) + gprs = REGARG_GPRS; + } +#endif + if ((void *)ci->func) + emit_call(as, ci->func); +#if LJ_64 + if ((ci->flags & CCI_VARARG)) { /* Special handling for vararg calls. */ +#if LJ_ABI_WIN + for (n = 0; n < 4 && n < nargs; n++) { + IRIns *ir = IR(args[n]); + if (irt_isfp(ir->t)) /* Duplicate FPRs in GPRs. */ + emit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n), + ((gprs >> (n*5)) & 31)); /* Either MOVD or MOVQ. */ + } +#else + patchnfpr = --as->mcp; /* Indicate number of used FPRs in register al. */ + *--as->mcp = XI_MOVrib | RID_EAX; +#endif + } +#endif + for (n = 0; n < nargs; n++) { /* Setup args. */ + IRRef ref = args[n]; + IRIns *ir = IR(ref); + Reg r; +#if LJ_64 && LJ_ABI_WIN + /* Windows/x64 argument registers are strictly positional. */ + r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31); + fpr++; gprs >>= 5; +#elif LJ_64 + /* POSIX/x64 argument registers are used in order of appearance. */ + if (irt_isfp(ir->t)) { + r = fpr <= REGARG_LASTFPR ? fpr++ : 0; + } else { + r = gprs & 31; gprs >>= 5; + } +#else + if (ref && irt_isfp(ir->t)) { + r = 0; + } else { + r = gprs & 31; gprs >>= 5; + if (!ref) continue; + } +#endif + if (r) { /* Argument is in a register. */ + if (r < RID_MAX_GPR && ref < ASMREF_TMP1) { +#if LJ_64 + if (ir->o == IR_KINT64) + emit_loadu64(as, r, ir_kint64(ir)->u64); + else +#endif + emit_loadi(as, r, ir->i); + } else { + lua_assert(rset_test(as->freeset, r)); /* Must have been evicted. */ + if (ra_hasreg(ir->r)) { + ra_noweak(as, ir->r); + emit_movrr(as, ir, r, ir->r); + } else { + ra_allocref(as, ref, RID2RSET(r)); + } + } + } else if (irt_isfp(ir->t)) { /* FP argument is on stack. */ + lua_assert(!(irt_isfloat(ir->t) && irref_isk(ref))); /* No float k. */ + if (LJ_32 && (ofs & 4) && irref_isk(ref)) { + /* Split stores for unaligned FP consts. */ + emit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo); + emit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi); + } else { + r = ra_alloc1(as, ref, RSET_FPR); + emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, + r, RID_ESP, ofs); + } + ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8; + } else { /* Non-FP argument is on stack. */ + if (LJ_32 && ref < ASMREF_TMP1) { + emit_movmroi(as, RID_ESP, ofs, ir->i); + } else { + r = ra_alloc1(as, ref, RSET_GPR); + emit_movtomro(as, REX_64 + r, RID_ESP, ofs); + } + ofs += sizeof(intptr_t); + } + checkmclim(as); + } +#if LJ_64 && !LJ_ABI_WIN + if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR; +#endif +} + +/* Setup result reg/sp for call. Evict scratch regs. */ +static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + RegSet drop = RSET_SCRATCH; + int hiop = (LJ_32 && (ir+1)->o == IR_HIOP); + if ((ci->flags & CCI_NOFPRCLOBBER)) + drop &= ~RSET_FPR; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + if (hiop && ra_hasreg((ir+1)->r)) + rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */ + ra_evictset(as, drop); /* Evictions must be performed first. */ + if (ra_used(ir)) { + if (irt_isfp(ir->t)) { + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ +#if LJ_64 + if ((ci->flags & CCI_CASTU64)) { + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rr(as, XO_MOVD, dest|REX_64, RID_RET); /* Really MOVQ. */ + } + if (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs); + } else { + ra_destreg(as, ir, RID_FPRET); + } +#else + /* Number result is in x87 st0 for x86 calling convention. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, + dest, RID_ESP, ofs); + } + if ((ci->flags & CCI_CASTU64)) { + emit_movtomro(as, RID_RETLO, RID_ESP, ofs); + emit_movtomro(as, RID_RETHI, RID_ESP, ofs+4); + } else { + emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd, + irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs); + } +#endif +#if LJ_32 + } else if (hiop) { + ra_destpair(as, ir); +#endif + } else { + lua_assert(!irt_ispri(ir->t)); + ra_destreg(as, ir, RID_RET); + } + } else if (LJ_32 && irt_isfp(ir->t)) { + emit_x87op(as, XI_FPOP); /* Pop unused result from x87 st0. */ + } +} + +static void asm_call(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX]; + const CCallInfo *ci = &lj_ir_callinfo[ir->op2]; + asm_collectargs(as, ir, ci, args); + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +/* Return a constant function pointer or NULL for indirect calls. */ +static void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func) +{ +#if LJ_32 + UNUSED(as); + if (irref_isk(func)) + return (void *)irf->i; +#else + if (irref_isk(func)) { + MCode *p; + if (irf->o == IR_KINT64) + p = (MCode *)(void *)ir_k64(irf)->u64; + else + p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i; + if (p - as->mcp == (int32_t)(p - as->mcp)) + return p; /* Call target is still in +-2GB range. */ + /* Avoid the indirect case of emit_call(). Try to hoist func addr. */ + } +#endif + return NULL; +} + +static void asm_callx(ASMState *as, IRIns *ir) +{ + IRRef args[CCI_NARGS_MAX*2]; + CCallInfo ci; + IRRef func; + IRIns *irf; + int32_t spadj = 0; + ci.flags = asm_callx_flags(as, ir); + asm_collectargs(as, ir, &ci, args); + asm_setupresult(as, ir, &ci); +#if LJ_32 + /* Have to readjust stack after non-cdecl calls due to callee cleanup. */ + if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL) + spadj = 4 * asm_count_call_slots(as, &ci, args); +#endif + func = ir->op2; irf = IR(func); + if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } + ci.func = (ASMFunction)asm_callx_func(as, irf, func); + if (!(void *)ci.func) { + /* Use a (hoistable) non-scratch register for indirect calls. */ + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); + Reg r = ra_alloc1(as, func, allow); + if (LJ_32) emit_spsub(as, spadj); /* Above code may cause restores! */ + emit_rr(as, XO_GROUP5, XOg_CALL, r); + } else if (LJ_32) { + emit_spsub(as, spadj); + } + asm_gencall(as, &ci, args); +} + +/* -- Returns ------------------------------------------------------------- */ + +/* Return to lower frame. Guard that it goes to the right spot. */ +static void asm_retf(ASMState *as, IRIns *ir) +{ + Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); + void *pc = ir_kptr(IR(ir->op2)); + int32_t delta = 1+bc_a(*((const BCIns *)pc - 1)); + as->topslot -= (BCReg)delta; + if ((int32_t)as->topslot < 0) as->topslot = 0; + irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ + emit_setgl(as, base, jit_base); + emit_addptr(as, base, -8*delta); + asm_guardcc(as, CC_NE); + emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc)); +} + +/* -- Type conversions ---------------------------------------------------- */ + +static void asm_tointg(ASMState *as, IRIns *ir, Reg left) +{ + Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_guardcc(as, CC_P); + asm_guardcc(as, CC_NE); + emit_rr(as, XO_UCOMISD, left, tmp); + emit_rr(as, XO_CVTSI2SD, tmp, dest); + if (!(as->flags & JIT_F_SPLIT_XMM)) + emit_rr(as, XO_XORPS, tmp, tmp); /* Avoid partial register stall. */ + emit_rr(as, XO_CVTTSD2SI, dest, left); + /* Can't fuse since left is needed twice. */ +} + +static void asm_tobit(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + Reg tmp = ra_noreg(IR(ir->op1)->r) ? + ra_alloc1(as, ir->op1, RSET_FPR) : + ra_scratch(as, RSET_FPR); + Reg right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp)); + emit_rr(as, XO_MOVDto, tmp, dest); + emit_mrm(as, XO_ADDSD, tmp, right); + ra_left(as, tmp, ir->op1); +} + +static void asm_conv(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64)); + int stfp = (st == IRT_NUM || st == IRT_FLOAT); + IRRef lref = ir->op1; + lua_assert(irt_type(ir->t) != st); + lua_assert(!(LJ_32 && (irt_isint64(ir->t) || st64))); /* Handled by SPLIT. */ + if (irt_isfp(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_FPR); + if (stfp) { /* FP to FP conversion. */ + Reg left = asm_fuseload(as, lref, RSET_FPR); + emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left); + if (left == dest) return; /* Avoid the XO_XORPS. */ + } else if (LJ_32 && st == IRT_U32) { /* U32 to FP conversion on x86. */ + /* number = (2^52+2^51 .. u32) - (2^52+2^51) */ + cTValue *k = lj_ir_k64_find(as->J, U64x(43380000,00000000)); + Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest)); + if (irt_isfloat(ir->t)) + emit_rr(as, XO_CVTSD2SS, dest, dest); + emit_rr(as, XO_SUBSD, dest, bias); /* Subtract 2^52+2^51 bias. */ + emit_rr(as, XO_XORPS, dest, bias); /* Merge bias and integer. */ + emit_loadn(as, bias, k); + emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR)); + return; + } else { /* Integer to FP conversion. */ + Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ? + ra_alloc1(as, lref, RSET_GPR) : + asm_fuseloadm(as, lref, RSET_GPR, st64); + if (LJ_64 && st == IRT_U64) { + MCLabel l_end = emit_label(as); + const void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000)); + emit_rma(as, XO_ADDSD, dest, k); /* Add 2^64 to compensate. */ + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, left|REX_64, left); /* Check if u64 >= 2^63. */ + } + emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS, + dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left); + } + if (!(as->flags & JIT_F_SPLIT_XMM)) + emit_rr(as, XO_XORPS, dest, dest); /* Avoid partial register stall. */ + } else if (stfp) { /* FP to integer conversion. */ + if (irt_isguard(ir->t)) { + /* Checked conversions are only supported from number to int. */ + lua_assert(irt_isint(ir->t) && st == IRT_NUM); + asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + x86Op op = st == IRT_NUM ? + ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) : + ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI); + if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) { + /* LJ_64: For inputs >= 2^63 add -2^64, convert again. */ + /* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */ + Reg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) : + ra_scratch(as, RSET_FPR); + MCLabel l_end = emit_label(as); + if (LJ_32) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000); + emit_rr(as, op, dest|REX_64, tmp); + if (st == IRT_NUM) + emit_rma(as, XO_ADDSD, tmp, lj_ir_k64_find(as->J, + LJ_64 ? U64x(c3f00000,00000000) : U64x(c1e00000,00000000))); + else + emit_rma(as, XO_ADDSS, tmp, lj_ir_k64_find(as->J, + LJ_64 ? U64x(00000000,df800000) : U64x(00000000,cf000000))); + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, dest|REX_64, dest); /* Check if dest negative. */ + emit_rr(as, op, dest|REX_64, tmp); + ra_left(as, tmp, lref); + } else { + Reg left = asm_fuseload(as, lref, RSET_FPR); + if (LJ_64 && irt_isu32(ir->t)) + emit_rr(as, XO_MOV, dest, dest); /* Zero hiword. */ + emit_mrm(as, op, + dest|((LJ_64 && + (irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0), + left); + } + } + } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ + Reg left, dest = ra_dest(as, ir, RSET_GPR); + RegSet allow = RSET_GPR; + x86Op op; + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t)); + if (st == IRT_I8) { + op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX; + } else if (st == IRT_U8) { + op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX; + } else if (st == IRT_I16) { + op = XO_MOVSXw; + } else { + op = XO_MOVZXw; + } + left = asm_fuseload(as, lref, allow); + /* Add extra MOV if source is already in wrong register. */ + if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) { + Reg tmp = ra_scratch(as, allow); + emit_rr(as, op, dest, tmp); + emit_rr(as, XO_MOV, tmp, left); + } else { + emit_mrm(as, op, dest, left); + } + } else { /* 32/64 bit integer conversions. */ + if (LJ_32) { /* Only need to handle 32/32 bit no-op (cast) on x86. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else if (irt_is64(ir->t)) { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st64 || !(ir->op2 & IRCONV_SEXT)) { + /* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */ + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } else { /* 32 to 64 bit sign extension. */ + Reg left = asm_fuseload(as, lref, RSET_GPR); + emit_mrm(as, XO_MOVSXd, dest|REX_64, left); + } + } else { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (st64) { + Reg left = asm_fuseload(as, lref, RSET_GPR); + /* This is either a 32 bit reg/reg mov which zeroes the hiword + ** or a load of the loword from a 64 bit address. + */ + emit_mrm(as, XO_MOV, dest, left); + } else { /* 32/32 bit no-op (cast). */ + ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */ + } + } + } +} + +#if LJ_32 && LJ_HASFFI +/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */ + +/* 64 bit integer to FP conversion in 32 bit mode. */ +static void asm_conv_fp_int64(ASMState *as, IRIns *ir) +{ + Reg hi = ra_alloc1(as, ir->op1, RSET_GPR); + Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi)); + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, + dest, RID_ESP, ofs); + } + emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd, + irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs); + if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) { + /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */ + MCLabel l_end = emit_label(as); + emit_rma(as, XO_FADDq, XOg_FADDq, + lj_ir_k64_find(as->J, U64x(43f00000,00000000))); + emit_sjcc(as, CC_NS, l_end); + emit_rr(as, XO_TEST, hi, hi); /* Check if u64 >= 2^63. */ + } else { + lua_assert(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64); + } + emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0); + /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */ + emit_rmro(as, XO_MOVto, hi, RID_ESP, 4); + emit_rmro(as, XO_MOVto, lo, RID_ESP, 0); +} + +/* FP to 64 bit integer conversion in 32 bit mode. */ +static void asm_conv_int64_fp(ASMState *as, IRIns *ir) +{ + IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK); + IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH); + Reg lo, hi; + lua_assert(st == IRT_NUM || st == IRT_FLOAT); + lua_assert(dt == IRT_I64 || dt == IRT_U64); + lua_assert(((ir-1)->op2 & IRCONV_TRUNC)); + hi = ra_dest(as, ir, RSET_GPR); + lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi)); + if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0); + /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */ + if (!(as->flags & JIT_F_SSE3)) { /* Set FPU rounding mode to default. */ + emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4); + emit_rmro(as, XO_MOVto, lo, RID_ESP, 4); + emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff); + } + if (dt == IRT_U64) { + /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */ + MCLabel l_pop, l_end = emit_label(as); + emit_x87op(as, XI_FPOP); + l_pop = emit_label(as); + emit_sjmp(as, l_end); + emit_rmro(as, XO_MOV, hi, RID_ESP, 4); + if ((as->flags & JIT_F_SSE3)) + emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0); + else + emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0); + emit_rma(as, XO_FADDq, XOg_FADDq, + lj_ir_k64_find(as->J, U64x(c3f00000,00000000))); + emit_sjcc(as, CC_NS, l_pop); + emit_rr(as, XO_TEST, hi, hi); /* Check if out-of-range (2^63). */ + } + emit_rmro(as, XO_MOV, hi, RID_ESP, 4); + if ((as->flags & JIT_F_SSE3)) { /* Truncation is easy with SSE3. */ + emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0); + } else { /* Otherwise set FPU rounding mode to truncate before the store. */ + emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0); + emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0); + emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0); + emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0); + emit_loadi(as, lo, 0xc00); + emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0); + } + if (dt == IRT_U64) + emit_x87op(as, XI_FDUP); + emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd, + st == IRT_NUM ? XOg_FLDq: XOg_FLDd, + asm_fuseload(as, ir->op1, RSET_EMPTY)); +} +#endif + +static void asm_strto(ASMState *as, IRIns *ir) +{ + /* Force a spill slot for the destination register (if any). */ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; + IRRef args[2]; + RegSet drop = RSET_SCRATCH; + if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r)) + rset_set(drop, ir->r); /* WIN64 doesn't spill all FPRs. */ + ra_evictset(as, drop); + asm_guardcc(as, CC_E); + emit_rr(as, XO_TEST, RID_RET, RID_RET); /* Test return status. */ + args[0] = ir->op1; /* GCstr *str */ + args[1] = ASMREF_TMP1; /* TValue *n */ + asm_gencall(as, ci, args); + /* Store the result to the spill slot or temp slots. */ + emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64, + RID_ESP, sps_scale(ir->s)); +} + +static void asm_tostr(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRRef args[2]; + args[0] = ASMREF_L; + as->gcsteps++; + if (irt_isnum(irl->t)) { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum]; + args[1] = ASMREF_TMP1; /* const lua_Number * */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64, + RID_ESP, ra_spill(as, irl)); + } else { + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint]; + args[1] = ir->op1; /* int32_t k */ + asm_setupresult(as, ir, ci); /* GCstr * */ + asm_gencall(as, ci, args); + } +} + +/* -- Memory references --------------------------------------------------- */ + +static void asm_aref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusearef(as, ir, RSET_GPR); + if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0)) + emit_mrm(as, XO_LEA, dest, RID_MRM); + else if (as->mrm.base != dest) + emit_rr(as, XO_MOV, dest, as->mrm.base); +} + +/* Merge NE(HREF, niltv) check. */ +static MCode *merge_href_niltv(ASMState *as, IRIns *ir) +{ + /* Assumes nothing else generates NE of HREF. */ + if ((ir[1].o == IR_NE || ir[1].o == IR_EQ) && ir[1].op1 == as->curins && + ra_hasreg(ir->r)) { + MCode *p = as->mcp; + p += (LJ_64 && *p != XI_ARITHi) ? 7+6 : 6+6; + /* Ensure no loop branch inversion happened. */ + if (p[-6] == 0x0f && p[-5] == XI_JCCn+(CC_NE^(ir[1].o & 1))) { + as->mcp = p; /* Kill cmp reg, imm32 + jz exit. */ + return p + *(int32_t *)(p-4); /* Return exit address. */ + } + } + return NULL; +} + +/* Inlined hash lookup. Specialized for key type and for const keys. +** The equivalent C code is: +** Node *n = hashkey(t, key); +** do { +** if (lj_obj_equal(&n->key, key)) return &n->val; +** } while ((n = nextnode(n))); +** return niltv(L); +*/ +static void asm_href(ASMState *as, IRIns *ir) +{ + MCode *nilexit = merge_href_niltv(as, ir); /* Do this before any restores. */ + RegSet allow = RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); + Reg key = RID_NONE, tmp = RID_NONE; + IRIns *irkey = IR(ir->op2); + int isk = irref_isk(ir->op2); + IRType1 kt = irkey->t; + uint32_t khash; + MCLabel l_end, l_loop, l_next; + + if (!isk) { + rset_clear(allow, tab); + key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow); + if (!irt_isstr(kt)) + tmp = ra_scratch(as, rset_exclude(allow, key)); + } + + /* Key not found in chain: jump to exit (if merged with NE) or load niltv. */ + l_end = emit_label(as); + if (nilexit && ir[1].o == IR_NE) { + emit_jcc(as, CC_E, nilexit); /* XI_JMP is not found by lj_asm_patchexit. */ + nilexit = NULL; + } else { + emit_loada(as, dest, niltvg(J2G(as->J))); + } + + /* Follow hash chain until the end. */ + l_loop = emit_sjcc_label(as, CC_NZ); + emit_rr(as, XO_TEST, dest, dest); + emit_rmro(as, XO_MOV, dest, dest, offsetof(Node, next)); + l_next = emit_label(as); + + /* Type and value comparison. */ + if (nilexit) + emit_jcc(as, CC_E, nilexit); + else + emit_sjcc(as, CC_E, l_end); + if (irt_isnum(kt)) { + if (isk) { + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo), + (int32_t)ir_knum(irkey)->u32.lo); + emit_sjcc(as, CC_NE, l_next); + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi), + (int32_t)ir_knum(irkey)->u32.hi); + } else { + emit_sjcc(as, CC_P, l_next); + emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n)); + emit_sjcc(as, CC_AE, l_next); + /* The type check avoids NaN penalties and complaints from Valgrind. */ +#if LJ_64 + emit_u32(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it)); +#else + emit_i8(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it)); +#endif + } +#if LJ_64 + } else if (irt_islightud(kt)) { + emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64)); +#endif + } else { + if (!irt_ispri(kt)) { + lua_assert(irt_isaddr(kt)); + if (isk) + emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr), + ptr2addr(ir_kgc(irkey))); + else + emit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr)); + emit_sjcc(as, CC_NE, l_next); + } + lua_assert(!irt_isnil(kt)); + emit_i8(as, irt_toitype(kt)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it)); + } + emit_sfixup(as, l_loop); + checkmclim(as); + + /* Load main position relative to tab->node into dest. */ + khash = isk ? ir_khash(irkey) : 1; + if (khash == 0) { + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, node)); + } else { + emit_rmro(as, XO_ARITH(XOg_ADD), dest, tab, offsetof(GCtab, node)); + if ((as->flags & JIT_F_PREFER_IMUL)) { + emit_i8(as, sizeof(Node)); + emit_rr(as, XO_IMULi8, dest, dest); + } else { + emit_shifti(as, XOg_SHL, dest, 3); + emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0); + } + if (isk) { + emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash); + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask)); + } else if (irt_isstr(kt)) { + emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, hash)); + emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask)); + } else { /* Must match with hashrot() in lj_tab.c. */ + emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask)); + emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp); + emit_shifti(as, XOg_ROL, tmp, HASH_ROT3); + emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp); + emit_shifti(as, XOg_ROL, dest, HASH_ROT2); + emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest); + emit_shifti(as, XOg_ROL, dest, HASH_ROT1); + emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest); + if (irt_isnum(kt)) { + emit_rr(as, XO_ARITH(XOg_ADD), dest, dest); +#if LJ_64 + emit_shifti(as, XOg_SHR|REX_64, dest, 32); + emit_rr(as, XO_MOV, tmp, dest); + emit_rr(as, XO_MOVDto, key|REX_64, dest); +#else + emit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4); + emit_rr(as, XO_MOVDto, key, tmp); +#endif + } else { + emit_rr(as, XO_MOV, tmp, key); + emit_rmro(as, XO_LEA, dest, key, HASH_BIAS); + } + } + } +} + +static void asm_hrefk(ASMState *as, IRIns *ir) +{ + IRIns *kslot = IR(ir->op2); + IRIns *irkey = IR(kslot->op1); + int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); + Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; + Reg node = ra_alloc1(as, ir->op1, RSET_GPR); +#if !LJ_64 + MCLabel l_exit; +#endif + lua_assert(ofs % sizeof(Node) == 0); + if (ra_hasreg(dest)) { + if (ofs != 0) { + if (dest == node && !(as->flags & JIT_F_LEA_AGU)) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, ofs); + else + emit_rmro(as, XO_LEA, dest, node, ofs); + } else if (dest != node) { + emit_rr(as, XO_MOV, dest, node); + } + } + asm_guardcc(as, CC_NE); +#if LJ_64 + if (!irt_ispri(irkey->t)) { + Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node)); + emit_rmro(as, XO_CMP, key|REX_64, node, + ofs + (int32_t)offsetof(Node, key.u64)); + lua_assert(irt_isnum(irkey->t) || irt_isgcv(irkey->t)); + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 : + ((uint64_t)irt_toitype(irkey->t) << 32) | + (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey))); + } else { + lua_assert(!irt_isnil(irkey->t)); + emit_i8(as, irt_toitype(irkey->t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, node, + ofs + (int32_t)offsetof(Node, key.it)); + } +#else + l_exit = emit_label(as); + if (irt_isnum(irkey->t)) { + /* Assumes -0.0 is already canonicalized to +0.0. */ + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.u32.lo), + (int32_t)ir_knum(irkey)->u32.lo); + emit_sjcc(as, CC_NE, l_exit); + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.u32.hi), + (int32_t)ir_knum(irkey)->u32.hi); + } else { + if (!irt_ispri(irkey->t)) { + lua_assert(irt_isgcv(irkey->t)); + emit_gmroi(as, XG_ARITHi(XOg_CMP), node, + ofs + (int32_t)offsetof(Node, key.gcr), + ptr2addr(ir_kgc(irkey))); + emit_sjcc(as, CC_NE, l_exit); + } + lua_assert(!irt_isnil(irkey->t)); + emit_i8(as, irt_toitype(irkey->t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, node, + ofs + (int32_t)offsetof(Node, key.it)); + } +#endif +} + +static void asm_newref(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey]; + IRRef args[3]; + IRIns *irkey; + Reg tmp; + if (ir->r == RID_SINK) + return; + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ir->op1; /* GCtab *t */ + args[2] = ASMREF_TMP1; /* cTValue *key */ + asm_setupresult(as, ir, ci); /* TValue * */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + irkey = IR(ir->op2); + if (irt_isnum(irkey->t)) { + /* For numbers use the constant itself or a spill slot as a TValue. */ + if (irref_isk(ir->op2)) + emit_loada(as, tmp, ir_knum(irkey)); + else + emit_rmro(as, XO_LEA, tmp|REX_64, RID_ESP, ra_spill(as, irkey)); + } else { + /* Otherwise use g->tmptv to hold the TValue. */ + if (!irref_isk(ir->op2)) { + Reg src = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, tmp)); + emit_movtomro(as, REX_64IR(irkey, src), tmp, 0); + } else if (!irt_ispri(irkey->t)) { + emit_movmroi(as, tmp, 0, irkey->i); + } + if (!(LJ_64 && irt_islightud(irkey->t))) + emit_movmroi(as, tmp, 4, irt_toitype(irkey->t)); + emit_loada(as, tmp, &J2G(as->J)->tmptv); + } +} + +static void asm_uref(ASMState *as, IRIns *ir) +{ + /* NYI: Check that UREFO is still open and not aliasing a slot. */ + Reg dest = ra_dest(as, ir, RSET_GPR); + if (irref_isk(ir->op1)) { + GCfunc *fn = ir_kfunc(IR(ir->op1)); + MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; + emit_rma(as, XO_MOV, dest, v); + } else { + Reg uv = ra_scratch(as, RSET_GPR); + Reg func = ra_alloc1(as, ir->op1, RSET_GPR); + if (ir->o == IR_UREFC) { + emit_rmro(as, XO_LEA, dest, uv, offsetof(GCupval, tv)); + asm_guardcc(as, CC_NE); + emit_i8(as, 1); + emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed)); + } else { + emit_rmro(as, XO_MOV, dest, uv, offsetof(GCupval, v)); + } + emit_rmro(as, XO_MOV, uv, func, + (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); + } +} + +static void asm_fref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusefref(as, ir, RSET_GPR); + emit_mrm(as, XO_LEA, dest, RID_MRM); +} + +static void asm_strref(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + asm_fusestrref(as, ir, RSET_GPR); + if (as->mrm.base == RID_NONE) + emit_loadi(as, dest, as->mrm.ofs); + else if (as->mrm.base == dest && as->mrm.idx == RID_NONE) + emit_gri(as, XG_ARITHi(XOg_ADD), dest, as->mrm.ofs); + else + emit_mrm(as, XO_LEA, dest, RID_MRM); +} + +/* -- Loads and stores ---------------------------------------------------- */ + +static void asm_fxload(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); + x86Op xo; + if (ir->o == IR_FLOAD) + asm_fusefref(as, ir, RSET_GPR); + else + asm_fusexref(as, ir->op1, RSET_GPR); + /* ir->op2 is ignored -- unaligned loads are ok on x86. */ + switch (irt_type(ir->t)) { + case IRT_I8: xo = XO_MOVSXb; break; + case IRT_U8: xo = XO_MOVZXb; break; + case IRT_I16: xo = XO_MOVSXw; break; + case IRT_U16: xo = XO_MOVZXw; break; + case IRT_NUM: xo = XMM_MOVRM(as); break; + case IRT_FLOAT: xo = XO_MOVSS; break; + default: + if (LJ_64 && irt_is64(ir->t)) + dest |= REX_64; + else + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + xo = XO_MOV; + break; + } + emit_mrm(as, xo, dest, RID_MRM); +} + +static void asm_fxstore(ASMState *as, IRIns *ir) +{ + RegSet allow = RSET_GPR; + Reg src = RID_NONE, osrc = RID_NONE; + int32_t k = 0; + if (ir->r == RID_SINK) + return; + /* The IRT_I16/IRT_U16 stores should never be simplified for constant + ** values since mov word [mem], imm16 has a length-changing prefix. + */ + if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) || + !asm_isk32(as, ir->op2, &k)) { + RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR : + (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR; + src = osrc = ra_alloc1(as, ir->op2, allow8); + if (!LJ_64 && !rset_test(allow8, src)) { /* Already in wrong register. */ + rset_clear(allow, osrc); + src = ra_scratch(as, allow8); + } + rset_clear(allow, src); + } + if (ir->o == IR_FSTORE) { + asm_fusefref(as, IR(ir->op1), allow); + } else { + asm_fusexref(as, ir->op1, allow); + if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4; + } + if (ra_hasreg(src)) { + x86Op xo; + switch (irt_type(ir->t)) { + case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break; + case IRT_I16: case IRT_U16: xo = XO_MOVtow; break; + case IRT_NUM: xo = XO_MOVSDto; break; + case IRT_FLOAT: xo = XO_MOVSSto; break; +#if LJ_64 + case IRT_LIGHTUD: lua_assert(0); /* NYI: mask 64 bit lightuserdata. */ +#endif + default: + if (LJ_64 && irt_is64(ir->t)) + src |= REX_64; + else + lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)); + xo = XO_MOVto; + break; + } + emit_mrm(as, xo, src, RID_MRM); + if (!LJ_64 && src != osrc) { + ra_noweak(as, osrc); + emit_rr(as, XO_MOV, src, osrc); + } + } else { + if (irt_isi8(ir->t) || irt_isu8(ir->t)) { + emit_i8(as, k); + emit_mrm(as, XO_MOVmib, 0, RID_MRM); + } else { + lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) || + irt_isaddr(ir->t)); + emit_i32(as, k); + emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM); + } + } +} + +#if LJ_64 +static Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck) +{ + if (ra_used(ir) || typecheck) { + Reg dest = ra_dest(as, ir, RSET_GPR); + if (typecheck) { + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest)); + asm_guardcc(as, CC_NE); + emit_i8(as, -2); + emit_rr(as, XO_ARITHi8, XOg_CMP, tmp); + emit_shifti(as, XOg_SAR|REX_64, tmp, 47); + emit_rr(as, XO_MOV, tmp|REX_64, dest); + } + return dest; + } else { + return RID_NONE; + } +} +#endif + +static void asm_ahuvload(ASMState *as, IRIns *ir) +{ + lua_assert(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) || + (LJ_DUALNUM && irt_isint(ir->t))); +#if LJ_64 + if (irt_islightud(ir->t)) { + Reg dest = asm_load_lightud64(as, ir, 1); + if (ra_hasreg(dest)) { + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM); + } + return; + } else +#endif + if (ra_used(ir)) { + RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XMM_MOVRM(as), dest, RID_MRM); + } else { + asm_fuseahuref(as, ir->op1, RSET_GPR); + } + /* Always do the type check, even if the load result is unused. */ + as->mrm.ofs += 4; + asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE); + if (LJ_64 && irt_type(ir->t) >= IRT_NUM) { + lua_assert(irt_isinteger(ir->t) || irt_isnum(ir->t)); + emit_u32(as, LJ_TISNUM); + emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM); + } else { + emit_i8(as, irt_toitype(ir->t)); + emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM); + } +} + +static void asm_ahustore(ASMState *as, IRIns *ir) +{ + if (ir->r == RID_SINK) + return; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ir->op2, RSET_FPR); + asm_fuseahuref(as, ir->op1, RSET_GPR); + emit_mrm(as, XO_MOVSDto, src, RID_MRM); +#if LJ_64 + } else if (irt_islightud(ir->t)) { + Reg src = ra_alloc1(as, ir->op2, RSET_GPR); + asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src)); + emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM); +#endif + } else { + IRIns *irr = IR(ir->op2); + RegSet allow = RSET_GPR; + Reg src = RID_NONE; + if (!irref_isk(ir->op2)) { + src = ra_alloc1(as, ir->op2, allow); + rset_clear(allow, src); + } + asm_fuseahuref(as, ir->op1, allow); + if (ra_hasreg(src)) { + emit_mrm(as, XO_MOVto, src, RID_MRM); + } else if (!irt_ispri(irr->t)) { + lua_assert(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t))); + emit_i32(as, irr->i); + emit_mrm(as, XO_MOVmi, 0, RID_MRM); + } + as->mrm.ofs += 4; + emit_i32(as, (int32_t)irt_toitype(ir->t)); + emit_mrm(as, XO_MOVmi, 0, RID_MRM); + } +} + +static void asm_sload(ASMState *as, IRIns *ir) +{ + int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); + IRType1 t = ir->t; + Reg base; + lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */ + lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK)); + lua_assert(LJ_DUALNUM || + !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME))); + if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) { + Reg left = ra_scratch(as, RSET_FPR); + asm_tointg(as, ir, left); /* Frees dest reg. Do this before base alloc. */ + base = ra_alloc1(as, REF_BASE, RSET_GPR); + emit_rmro(as, XMM_MOVRM(as), left, base, ofs); + t.irt = IRT_NUM; /* Continue with a regular number type check. */ +#if LJ_64 + } else if (irt_islightud(t)) { + Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK)); + if (ra_hasreg(dest)) { + base = ra_alloc1(as, REF_BASE, RSET_GPR); + emit_rmro(as, XO_MOV, dest|REX_64, base, ofs); + } + return; +#endif + } else if (ra_used(ir)) { + RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR; + Reg dest = ra_dest(as, ir, allow); + base = ra_alloc1(as, REF_BASE, RSET_GPR); + lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t)); + if ((ir->op2 & IRSLOAD_CONVERT)) { + t.irt = irt_isint(t) ? IRT_NUM : IRT_INT; /* Check for original type. */ + emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTSD2SI, dest, base, ofs); + } else if (irt_isnum(t)) { + emit_rmro(as, XMM_MOVRM(as), dest, base, ofs); + } else { + emit_rmro(as, XO_MOV, dest, base, ofs); + } + } else { + if (!(ir->op2 & IRSLOAD_TYPECHECK)) + return; /* No type check: avoid base alloc. */ + base = ra_alloc1(as, REF_BASE, RSET_GPR); + } + if ((ir->op2 & IRSLOAD_TYPECHECK)) { + /* Need type check, even if the load result is unused. */ + asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE); + if (LJ_64 && irt_type(t) >= IRT_NUM) { + lua_assert(irt_isinteger(t) || irt_isnum(t)); + emit_u32(as, LJ_TISNUM); + emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4); + } else { + emit_i8(as, irt_toitype(t)); + emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4); + } + } +} + +/* -- Allocations --------------------------------------------------------- */ + +#if LJ_HASFFI +static void asm_cnew(ASMState *as, IRIns *ir) +{ + CTState *cts = ctype_ctsG(J2G(as->J)); + CTypeID ctypeid = (CTypeID)IR(ir->op1)->i; + CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ? + lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i; + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; + IRRef args[2]; + lua_assert(sz != CTSIZE_INVALID); + + args[0] = ASMREF_L; /* lua_State *L */ + args[1] = ASMREF_TMP1; /* MSize size */ + as->gcsteps++; + asm_setupresult(as, ir, ci); /* GCcdata * */ + + /* Initialize immutable cdata object. */ + if (ir->o == IR_CNEWI) { + RegSet allow = (RSET_GPR & ~RSET_SCRATCH); +#if LJ_64 + Reg r64 = sz == 8 ? REX_64 : 0; + if (irref_isk(ir->op2)) { + IRIns *irk = IR(ir->op2); + uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 : + (uint64_t)(uint32_t)irk->i; + if (sz == 4 || checki32((int64_t)k)) { + emit_i32(as, (int32_t)k); + emit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata)); + } else { + emit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata)); + emit_loadu64(as, RID_ECX, k); + } + } else { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata)); + } +#else + int32_t ofs = sizeof(GCcdata); + if (sz == 8) { + ofs += 4; ir++; + lua_assert(ir->o == IR_HIOP); + } + do { + if (irref_isk(ir->op2)) { + emit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i); + } else { + Reg r = ra_alloc1(as, ir->op2, allow); + emit_movtomro(as, r, RID_RET, ofs); + rset_clear(allow, r); + } + if (ofs == sizeof(GCcdata)) break; + ofs -= 4; ir--; + } while (1); +#endif + lua_assert(sz == 4 || sz == 8); + } + + /* Combine initialization of marked, gct and ctypeid. */ + emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked)); + emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX, + (int32_t)((~LJ_TCDATA<<8)+(ctypeid<<16))); + emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES); + emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite); + + asm_gencall(as, ci, args); + emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata))); +} +#else +#define asm_cnew(as, ir) ((void)0) +#endif + +/* -- Write barriers ------------------------------------------------------ */ + +static void asm_tbar(ASMState *as, IRIns *ir) +{ + Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab)); + MCLabel l_end = emit_label(as); + emit_movtomro(as, tmp, tab, offsetof(GCtab, gclist)); + emit_setgl(as, tab, gc.grayagain); + emit_getgl(as, tmp, gc.grayagain); + emit_i8(as, ~LJ_GC_BLACK); + emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked)); + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_BLACK); + emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked)); +} + +static void asm_obar(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; + IRRef args[2]; + MCLabel l_end; + Reg obj; + /* No need for other object barriers (yet). */ + lua_assert(IR(ir->op1)->o == IR_UREFC); + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ir->op1; /* TValue *tv */ + asm_gencall(as, ci, args); + emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J)); + obj = IR(ir->op1)->r; + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_WHITES); + if (irref_isk(ir->op2)) { + GCobj *vp = ir_kgc(IR(ir->op2)); + emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked); + } else { + Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj)); + emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked)); + } + emit_sjcc(as, CC_Z, l_end); + emit_i8(as, LJ_GC_BLACK); + emit_rmro(as, XO_GROUP3b, XOg_TEST, obj, + (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); +} + +/* -- FP/int arithmetic and logic operations ------------------------------ */ + +/* Load reference onto x87 stack. Force a spill to memory if needed. */ +static void asm_x87load(ASMState *as, IRRef ref) +{ + IRIns *ir = IR(ref); + if (ir->o == IR_KNUM) { + cTValue *tv = ir_knum(ir); + if (tvispzero(tv)) /* Use fldz only for +0. */ + emit_x87op(as, XI_FLDZ); + else if (tvispone(tv)) + emit_x87op(as, XI_FLD1); + else + emit_rma(as, XO_FLDq, XOg_FLDq, tv); + } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) && + !irref_isk(ir->op1) && mayfuse(as, ir->op1)) { + IRIns *iri = IR(ir->op1); + emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri)); + } else { + emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY)); + } +} + +/* Try to rejoin pow from EXP2, MUL and LOG2 (if still unsplit). */ +static int fpmjoin_pow(ASMState *as, IRIns *ir) +{ + IRIns *irp = IR(ir->op1); + if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) { + IRIns *irpp = IR(irp->op1); + if (irpp == ir-2 && irpp->o == IR_FPMATH && + irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) { + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX); + IRIns *irx; + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, lj_vm_pow_sse); + irx = IR(irpp->op1); + if (ra_noreg(irx->r) && ra_gethint(irx->r) == RID_XMM1) + irx->r = RID_INIT; /* Avoid allocating xmm1 for x. */ + ra_left(as, RID_XMM0, irpp->op1); + ra_left(as, RID_XMM1, irp->op2); + return 1; + } + } + return 0; +} + +static void asm_fpmath(ASMState *as, IRIns *ir) +{ + IRFPMathOp fpm = ir->o == IR_FPMATH ? (IRFPMathOp)ir->op2 : IRFPM_OTHER; + if (fpm == IRFPM_SQRT) { + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = asm_fuseload(as, ir->op1, RSET_FPR); + emit_mrm(as, XO_SQRTSD, dest, left); + } else if (fpm <= IRFPM_TRUNC) { + if (as->flags & JIT_F_SSE4_1) { /* SSE4.1 has a rounding instruction. */ + Reg dest = ra_dest(as, ir, RSET_FPR); + Reg left = asm_fuseload(as, ir->op1, RSET_FPR); + /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op. + ** Let's pretend it's a 3-byte opcode, and compensate afterwards. + ** This is atrocious, but the alternatives are much worse. + */ + /* Round down/up/trunc == 1001/1010/1011. */ + emit_i8(as, 0x09 + fpm); + emit_mrm(as, XO_ROUNDSD, dest, left); + if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) { + as->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f; /* Swap 0F and REX. */ + } + *--as->mcp = 0x66; /* 1st byte of ROUNDSD opcode. */ + } else { /* Call helper functions for SSE2 variant. */ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse : + fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse); + ra_left(as, RID_XMM0, ir->op1); + } + } else if (fpm == IRFPM_EXP2 && fpmjoin_pow(as, ir)) { + /* Rejoined to pow(). */ + } else { /* Handle x87 ops. */ + int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */ + Reg dest = ir->r; + if (ra_hasreg(dest)) { + ra_free(as, dest); + ra_modified(as, dest); + emit_rmro(as, XMM_MOVRM(as), dest, RID_ESP, ofs); + } + emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs); + switch (fpm) { /* st0 = lj_vm_*(st0) */ + case IRFPM_EXP: emit_call(as, lj_vm_exp_x87); break; + case IRFPM_EXP2: emit_call(as, lj_vm_exp2_x87); break; + case IRFPM_SIN: emit_x87op(as, XI_FSIN); break; + case IRFPM_COS: emit_x87op(as, XI_FCOS); break; + case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break; + case IRFPM_LOG: case IRFPM_LOG2: case IRFPM_LOG10: + /* Note: the use of fyl2xp1 would be pointless here. When computing + ** log(1.0+eps) the precision is already lost after 1.0 is added. + ** Subtracting 1.0 won't recover it. OTOH math.log1p would make sense. + */ + emit_x87op(as, XI_FYL2X); break; + case IRFPM_OTHER: + switch (ir->o) { + case IR_ATAN2: + emit_x87op(as, XI_FPATAN); asm_x87load(as, ir->op2); break; + case IR_LDEXP: + emit_x87op(as, XI_FPOP1); emit_x87op(as, XI_FSCALE); break; + default: lua_assert(0); break; + } + break; + default: lua_assert(0); break; + } + asm_x87load(as, ir->op1); + switch (fpm) { + case IRFPM_LOG: emit_x87op(as, XI_FLDLN2); break; + case IRFPM_LOG2: emit_x87op(as, XI_FLD1); break; + case IRFPM_LOG10: emit_x87op(as, XI_FLDLG2); break; + case IRFPM_OTHER: + if (ir->o == IR_LDEXP) asm_x87load(as, ir->op2); + break; + default: break; + } + } +} + +static void asm_fppowi(ASMState *as, IRIns *ir) +{ + /* The modified regs must match with the *.dasc implementation. */ + RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX); + if (ra_hasreg(ir->r)) + rset_clear(drop, ir->r); /* Dest reg handled below. */ + ra_evictset(as, drop); + ra_destreg(as, ir, RID_XMM0); + emit_call(as, lj_vm_powi_sse); + ra_left(as, RID_XMM0, ir->op1); + ra_left(as, RID_EAX, ir->op2); +} + +#if LJ_64 && LJ_HASFFI +static void asm_arith64(ASMState *as, IRIns *ir, IRCallID id) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} +#endif + +static void asm_intmod(ASMState *as, IRIns *ir) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_vm_modi]; + IRRef args[2]; + args[0] = ir->op1; + args[1] = ir->op2; + asm_setupresult(as, ir, ci); + asm_gencall(as, ci, args); +} + +static int asm_swapops(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + lua_assert(ra_noreg(irr->r)); + if (!irm_iscomm(lj_ir_mode[ir->o])) + return 0; /* Can't swap non-commutative operations. */ + if (irref_isk(ir->op2)) + return 0; /* Don't swap constants to the left. */ + if (ra_hasreg(irl->r)) + return 1; /* Swap if left already has a register. */ + if (ra_samehint(ir->r, irr->r)) + return 1; /* Swap if dest and right have matching hints. */ + if (as->curins > as->loopref) { /* In variant part? */ + if (ir->op2 < as->loopref && !irt_isphi(irr->t)) + return 0; /* Keep invariants on the right. */ + if (ir->op1 < as->loopref && !irt_isphi(irl->t)) + return 1; /* Swap invariants to the right. */ + } + if (opisfusableload(irl->o)) + return 1; /* Swap fusable loads to the right. */ + return 0; /* Otherwise don't swap. */ +} + +static void asm_fparith(ASMState *as, IRIns *ir, x86Op xo) +{ + IRRef lref = ir->op1; + IRRef rref = ir->op2; + RegSet allow = RSET_FPR; + Reg dest; + Reg right = IR(rref)->r; + if (ra_hasreg(right)) { + rset_clear(allow, right); + ra_noweak(as, right); + } + dest = ra_dest(as, ir, allow); + if (lref == rref) { + right = dest; + } else if (ra_noreg(right)) { + if (asm_swapops(as, ir)) { + IRRef tmp = lref; lref = rref; rref = tmp; + } + right = asm_fuseload(as, rref, rset_clear(allow, dest)); + } + emit_mrm(as, xo, dest, right); + ra_left(as, dest, lref); +} + +static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa) +{ + IRRef lref = ir->op1; + IRRef rref = ir->op2; + RegSet allow = RSET_GPR; + Reg dest, right; + int32_t k = 0; + if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */ + as->flagmcp = NULL; + as->mcp += (LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2; + } + right = IR(rref)->r; + if (ra_hasreg(right)) { + rset_clear(allow, right); + ra_noweak(as, right); + } + dest = ra_dest(as, ir, allow); + if (lref == rref) { + right = dest; + } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) { + if (asm_swapops(as, ir)) { + IRRef tmp = lref; lref = rref; rref = tmp; + } + right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t)); + } + if (irt_isguard(ir->t)) /* For IR_ADDOV etc. */ + asm_guardcc(as, CC_O); + if (xa != XOg_X_IMUL) { + if (ra_hasreg(right)) + emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right); + else + emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k); + } else if (ra_hasreg(right)) { /* IMUL r, mrm. */ + emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right); + } else { /* IMUL r, r, k. */ + /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */ + Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t)); + x86Op xo; + if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8; + } else { emit_i32(as, k); xo = XO_IMULi; } + emit_mrm(as, xo, REX_64IR(ir, dest), left); + return; + } + ra_left(as, dest, lref); +} + +/* LEA is really a 4-operand ADD with an independent destination register, +** up to two source registers and an immediate. One register can be scaled +** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several +** instructions. +** +** Currently only a few common cases are supported: +** - 3-operand ADD: y = a+b; y = a+k with a and b already allocated +** - Left ADD fusion: y = (a+b)+k; y = (a+k)+b +** - Right ADD fusion: y = a+(b+k) +** The ommited variants have already been reduced by FOLD. +** +** There are more fusion opportunities, like gathering shifts or joining +** common references. But these are probably not worth the trouble, since +** array indexing is not decomposed and already makes use of all fields +** of the ModRM operand. +*/ +static int asm_lea(ASMState *as, IRIns *ir) +{ + IRIns *irl = IR(ir->op1); + IRIns *irr = IR(ir->op2); + RegSet allow = RSET_GPR; + Reg dest; + as->mrm.base = as->mrm.idx = RID_NONE; + as->mrm.scale = XM_SCALE1; + as->mrm.ofs = 0; + if (ra_hasreg(irl->r)) { + rset_clear(allow, irl->r); + ra_noweak(as, irl->r); + as->mrm.base = irl->r; + if (irref_isk(ir->op2) || ra_hasreg(irr->r)) { + /* The PHI renaming logic does a better job in some cases. */ + if (ra_hasreg(ir->r) && + ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) || + (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2))) + return 0; + if (irref_isk(ir->op2)) { + as->mrm.ofs = irr->i; + } else { + rset_clear(allow, irr->r); + ra_noweak(as, irr->r); + as->mrm.idx = irr->r; + } + } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) && + irref_isk(irr->op2)) { + Reg idx = ra_alloc1(as, irr->op1, allow); + rset_clear(allow, idx); + as->mrm.idx = (uint8_t)idx; + as->mrm.ofs = IR(irr->op2)->i; + } else { + return 0; + } + } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) && + (irref_isk(ir->op2) || irref_isk(irl->op2))) { + Reg idx, base = ra_alloc1(as, irl->op1, allow); + rset_clear(allow, base); + as->mrm.base = (uint8_t)base; + if (irref_isk(ir->op2)) { + as->mrm.ofs = irr->i; + idx = ra_alloc1(as, irl->op2, allow); + } else { + as->mrm.ofs = IR(irl->op2)->i; + idx = ra_alloc1(as, ir->op2, allow); + } + rset_clear(allow, idx); + as->mrm.idx = (uint8_t)idx; + } else { + return 0; + } + dest = ra_dest(as, ir, allow); + emit_mrm(as, XO_LEA, dest, RID_MRM); + return 1; /* Success. */ +} + +static void asm_add(ASMState *as, IRIns *ir) +{ + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_ADDSD); + else if ((as->flags & JIT_F_LEA_AGU) || as->flagmcp == as->mcp || + irt_is64(ir->t) || !asm_lea(as, ir)) + asm_intarith(as, ir, XOg_ADD); +} + +static void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest); + ra_left(as, dest, ir->op1); +} + +static void asm_min_max(ASMState *as, IRIns *ir, int cc) +{ + Reg right, dest = ra_dest(as, ir, RSET_GPR); + IRRef lref = ir->op1, rref = ir->op2; + if (irref_isk(rref)) { lref = rref; rref = ir->op1; } + right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest)); + emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right); + emit_rr(as, XO_CMP, REX_64IR(ir, dest), right); + ra_left(as, dest, lref); +} + +static void asm_bitswap(ASMState *as, IRIns *ir) +{ + Reg dest = ra_dest(as, ir, RSET_GPR); + as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24), + REX_64IR(ir, 0), dest, 0, as->mcp, 1); + ra_left(as, dest, ir->op1); +} + +static void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs) +{ + IRRef rref = ir->op2; + IRIns *irr = IR(rref); + Reg dest; + if (irref_isk(rref)) { /* Constant shifts. */ + int shift; + dest = ra_dest(as, ir, RSET_GPR); + shift = irr->i & (irt_is64(ir->t) ? 63 : 31); + switch (shift) { + case 0: break; + case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break; + default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break; + } + } else { /* Variable shifts implicitly use register cl (i.e. ecx). */ + Reg right; + dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX)); + if (dest == RID_ECX) { + dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX)); + emit_rr(as, XO_MOV, RID_ECX, dest); + } + right = irr->r; + if (ra_noreg(right)) + right = ra_allocref(as, rref, RID2RSET(RID_ECX)); + else if (right != RID_ECX) + ra_scratch(as, RID2RSET(RID_ECX)); + emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest); + ra_noweak(as, right); + if (right != RID_ECX) + emit_rr(as, XO_MOV, RID_ECX, right); + } + ra_left(as, dest, ir->op1); + /* + ** Note: avoid using the flags resulting from a shift or rotate! + ** All of them cause a partial flag stall, except for r,1 shifts + ** (but not rotates). And a shift count of 0 leaves the flags unmodified. + */ +} + +/* -- Comparisons --------------------------------------------------------- */ + +/* Virtual flags for unordered FP comparisons. */ +#define VCC_U 0x1000 /* Unordered. */ +#define VCC_P 0x2000 /* Needs extra CC_P branch. */ +#define VCC_S 0x4000 /* Swap avoids CC_P branch. */ +#define VCC_PS (VCC_P|VCC_S) + +/* Map of comparisons to flags. ORDER IR. */ +#define COMPFLAGS(ci, cin, cu, cf) ((ci)+((cu)<<4)+((cin)<<8)+(cf)) +static const uint16_t asm_compmap[IR_ABC+1] = { + /* signed non-eq unsigned flags */ + /* LT */ COMPFLAGS(CC_GE, CC_G, CC_AE, VCC_PS), + /* GE */ COMPFLAGS(CC_L, CC_L, CC_B, 0), + /* LE */ COMPFLAGS(CC_G, CC_G, CC_A, VCC_PS), + /* GT */ COMPFLAGS(CC_LE, CC_L, CC_BE, 0), + /* ULT */ COMPFLAGS(CC_AE, CC_A, CC_AE, VCC_U), + /* UGE */ COMPFLAGS(CC_B, CC_B, CC_B, VCC_U|VCC_PS), + /* ULE */ COMPFLAGS(CC_A, CC_A, CC_A, VCC_U), + /* UGT */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS), + /* EQ */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P), + /* NE */ COMPFLAGS(CC_E, CC_E, CC_E, VCC_U|VCC_P), + /* ABC */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS) /* Same as UGT. */ +}; + +/* FP and integer comparisons. */ +static void asm_comp(ASMState *as, IRIns *ir, uint32_t cc) +{ + if (irt_isnum(ir->t)) { + IRRef lref = ir->op1; + IRRef rref = ir->op2; + Reg left, right; + MCLabel l_around; + /* + ** An extra CC_P branch is required to preserve ordered/unordered + ** semantics for FP comparisons. This can be avoided by swapping + ** the operands and inverting the condition (except for EQ and UNE). + ** So always try to swap if possible. + ** + ** Another option would be to swap operands to achieve better memory + ** operand fusion. But it's unlikely that this outweighs the cost + ** of the extra branches. + */ + if (cc & VCC_S) { /* Swap? */ + IRRef tmp = lref; lref = rref; rref = tmp; + cc ^= (VCC_PS|(5<<4)); /* A <-> B, AE <-> BE, PS <-> none */ + } + left = ra_alloc1(as, lref, RSET_FPR); + right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left)); + l_around = emit_label(as); + asm_guardcc(as, cc >> 4); + if (cc & VCC_P) { /* Extra CC_P branch required? */ + if (!(cc & VCC_U)) { + asm_guardcc(as, CC_P); /* Branch to exit for ordered comparisons. */ + } else if (l_around != as->invmcp) { + emit_sjcc(as, CC_P, l_around); /* Branch around for unordered. */ + } else { + /* Patched to mcloop by asm_loop_fixup. */ + as->loopinv = 2; + if (as->realign) + emit_sjcc(as, CC_P, as->mcp); + else + emit_jcc(as, CC_P, as->mcp); + } + } + emit_mrm(as, XO_UCOMISD, left, right); + } else { + IRRef lref = ir->op1, rref = ir->op2; + IROp leftop = (IROp)(IR(lref)->o); + Reg r64 = REX_64IR(ir, 0); + int32_t imm = 0; + lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || + irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t)); + /* Swap constants (only for ABC) and fusable loads to the right. */ + if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) { + if ((cc & 0xc) == 0xc) cc ^= 0x53; /* L <-> G, LE <-> GE */ + else if ((cc & 0xa) == 0x2) cc ^= 0x55; /* A <-> B, AE <-> BE */ + lref = ir->op2; rref = ir->op1; + } + if (asm_isk32(as, rref, &imm)) { + IRIns *irl = IR(lref); + /* Check wether we can use test ins. Not for unsigned, since CF=0. */ + int usetest = (imm == 0 && (cc & 0xa) != 0x2); + if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) { + /* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */ + Reg right, left = RID_NONE; + RegSet allow = RSET_GPR; + if (!asm_isk32(as, irl->op2, &imm)) { + left = ra_alloc1(as, irl->op2, allow); + rset_clear(allow, left); + } else { /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */ + IRIns *irll = IR(irl->op1); + if (opisfusableload((IROp)irll->o) && + (irt_isi8(irll->t) || irt_isu8(irll->t))) { + IRType1 origt = irll->t; /* Temporarily flip types. */ + irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT; + as->curins--; /* Skip to BAND to avoid failing in noconflict(). */ + right = asm_fuseload(as, irl->op1, RSET_GPR); + as->curins++; + irll->t = origt; + if (right != RID_MRM) goto test_nofuse; + /* Fusion succeeded, emit test byte mrm, imm8. */ + asm_guardcc(as, cc); + emit_i8(as, (imm & 0xff)); + emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM); + return; + } + } + as->curins--; /* Skip to BAND to avoid failing in noconflict(). */ + right = asm_fuseloadm(as, irl->op1, allow, r64); + as->curins++; /* Undo the above. */ + test_nofuse: + asm_guardcc(as, cc); + if (ra_noreg(left)) { + emit_i32(as, imm); + emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right); + } else { + emit_mrm(as, XO_TEST, r64 + left, right); + } + } else { + Reg left; + if (opisfusableload((IROp)irl->o) && + ((irt_isu8(irl->t) && checku8(imm)) || + ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) || + (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) { + /* Only the IRT_INT case is fused by asm_fuseload. + ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads + ** are handled here. + ** Note that cmp word [mem], imm16 should not be generated, + ** since it has a length-changing prefix. Compares of a word + ** against a sign-extended imm8 are ok, however. + */ + IRType1 origt = irl->t; /* Temporarily flip types. */ + irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT; + left = asm_fuseload(as, lref, RSET_GPR); + irl->t = origt; + if (left == RID_MRM) { /* Fusion succeeded? */ + if (irt_isu8(irl->t) || irt_isu16(irl->t)) + cc >>= 4; /* Need unsigned compare. */ + asm_guardcc(as, cc); + emit_i8(as, imm); + emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ? + XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM); + return; + } /* Otherwise handle register case as usual. */ + } else { + left = asm_fuseloadm(as, lref, + irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64); + } + asm_guardcc(as, cc); + if (usetest && left != RID_MRM) { + /* Use test r,r instead of cmp r,0. */ + x86Op xo = XO_TEST; + if (irt_isu8(ir->t)) { + lua_assert(ir->o == IR_EQ || ir->o == IR_NE); + xo = XO_TESTb; + if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) { + if (LJ_64) { + left |= FORCE_REX; + } else { + emit_i32(as, 0xff); + emit_mrm(as, XO_GROUP3, XOg_TEST, left); + return; + } + } + } + emit_rr(as, xo, r64 + left, left); + if (irl+1 == ir) /* Referencing previous ins? */ + as->flagmcp = as->mcp; /* Set flag to drop test r,r if possible. */ + } else { + emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm); + } + } + } else { + Reg left = ra_alloc1(as, lref, RSET_GPR); + Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64); + asm_guardcc(as, cc); + emit_mrm(as, XO_CMP, r64 + left, right); + } + } +} + +#if LJ_32 && LJ_HASFFI +/* 64 bit integer comparisons in 32 bit mode. */ +static void asm_comp_int64(ASMState *as, IRIns *ir) +{ + uint32_t cc = asm_compmap[(ir-1)->o]; + RegSet allow = RSET_GPR; + Reg lefthi = RID_NONE, leftlo = RID_NONE; + Reg righthi = RID_NONE, rightlo = RID_NONE; + MCLabel l_around; + x86ModRM mrm; + + as->curins--; /* Skip loword ins. Avoids failing in noconflict(), too. */ + + /* Allocate/fuse hiword operands. */ + if (irref_isk(ir->op2)) { + lefthi = asm_fuseload(as, ir->op1, allow); + } else { + lefthi = ra_alloc1(as, ir->op1, allow); + rset_clear(allow, lefthi); + righthi = asm_fuseload(as, ir->op2, allow); + if (righthi == RID_MRM) { + if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base); + if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx); + } else { + rset_clear(allow, righthi); + } + } + mrm = as->mrm; /* Save state for hiword instruction. */ + + /* Allocate/fuse loword operands. */ + if (irref_isk((ir-1)->op2)) { + leftlo = asm_fuseload(as, (ir-1)->op1, allow); + } else { + leftlo = ra_alloc1(as, (ir-1)->op1, allow); + rset_clear(allow, leftlo); + rightlo = asm_fuseload(as, (ir-1)->op2, allow); + } + + /* All register allocations must be performed _before_ this point. */ + l_around = emit_label(as); + as->invmcp = as->flagmcp = NULL; /* Cannot use these optimizations. */ + + /* Loword comparison and branch. */ + asm_guardcc(as, cc >> 4); /* Always use unsigned compare for loword. */ + if (ra_noreg(rightlo)) { + int32_t imm = IR((ir-1)->op2)->i; + if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM) + emit_rr(as, XO_TEST, leftlo, leftlo); + else + emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm); + } else { + emit_mrm(as, XO_CMP, leftlo, rightlo); + } + + /* Hiword comparison and branches. */ + if ((cc & 15) != CC_NE) + emit_sjcc(as, CC_NE, l_around); /* Hiword unequal: skip loword compare. */ + if ((cc & 15) != CC_E) + asm_guardcc(as, cc >> 8); /* Hiword compare without equality check. */ + as->mrm = mrm; /* Restore state. */ + if (ra_noreg(righthi)) { + int32_t imm = IR(ir->op2)->i; + if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM) + emit_rr(as, XO_TEST, lefthi, lefthi); + else + emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm); + } else { + emit_mrm(as, XO_CMP, lefthi, righthi); + } +} +#endif + +/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */ + +/* Hiword op of a split 64 bit op. Previous op must be the loword op. */ +static void asm_hiop(ASMState *as, IRIns *ir) +{ +#if LJ_32 && LJ_HASFFI + /* HIOP is marked as a store because it needs its own DCE logic. */ + int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */ + if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; + if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */ + if (usehi || uselo) { + if (irt_isfp(ir->t)) + asm_conv_fp_int64(as, ir); + else + asm_conv_int64_fp(as, ir); + } + as->curins--; /* Always skip the CONV. */ + return; + } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */ + asm_comp_int64(as, ir); + return; + } else if ((ir-1)->o == IR_XSTORE) { + if ((ir-1)->r != RID_SINK) + asm_fxstore(as, ir); + return; + } + if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ + switch ((ir-1)->o) { + case IR_ADD: + as->flagmcp = NULL; + as->curins--; + asm_intarith(as, ir, XOg_ADC); + asm_intarith(as, ir-1, XOg_ADD); + break; + case IR_SUB: + as->flagmcp = NULL; + as->curins--; + asm_intarith(as, ir, XOg_SBB); + asm_intarith(as, ir-1, XOg_SUB); + break; + case IR_NEG: { + Reg dest = ra_dest(as, ir, RSET_GPR); + emit_rr(as, XO_GROUP3, XOg_NEG, dest); + emit_i8(as, 0); + emit_rr(as, XO_ARITHi8, XOg_ADC, dest); + ra_left(as, dest, ir->op1); + as->curins--; + asm_neg_not(as, ir-1, XOg_NEG); + break; + } + case IR_CALLN: + case IR_CALLXS: + if (!uselo) + ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ + break; + case IR_CNEWI: + /* Nothing to do here. Handled by CNEWI itself. */ + break; + default: lua_assert(0); break; + } +#else + UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused on x64 or without FFI. */ +#endif +} + +/* -- Stack handling ------------------------------------------------------ */ + +/* Check Lua stack size for overflow. Use exit handler as fallback. */ +static void asm_stack_check(ASMState *as, BCReg topslot, + IRIns *irp, RegSet allow, ExitNo exitno) +{ + /* Try to get an unused temp. register, otherwise spill/restore eax. */ + Reg pbase = irp ? irp->r : RID_BASE; + Reg r = allow ? rset_pickbot(allow) : RID_EAX; + emit_jcc(as, CC_B, exitstub_addr(as->J, exitno)); + if (allow == RSET_EMPTY) /* Restore temp. register. */ + emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0); + else + ra_modified(as, r); + emit_gri(as, XG_ARITHi(XOg_CMP), r, (int32_t)(8*topslot)); + if (ra_hasreg(pbase) && pbase != r) + emit_rr(as, XO_ARITH(XOg_SUB), r, pbase); + else + emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE, + ptr2addr(&J2G(as->J)->jit_base)); + emit_rmro(as, XO_MOV, r, r, offsetof(lua_State, maxstack)); + emit_getgl(as, r, jit_L); + if (allow == RSET_EMPTY) /* Spill temp. register. */ + emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0); +} + +/* Restore Lua stack from on-trace state. */ +static void asm_stack_restore(ASMState *as, SnapShot *snap) +{ + SnapEntry *map = &as->T->snapmap[snap->mapofs]; + SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; + MSize n, nent = snap->nent; + /* Store the value of all modified slots to the Lua stack. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + int32_t ofs = 8*((int32_t)s-1); + IRRef ref = snap_ref(sn); + IRIns *ir = IR(ref); + if ((sn & SNAP_NORESTORE)) + continue; + if (irt_isnum(ir->t)) { + Reg src = ra_alloc1(as, ref, RSET_FPR); + emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs); + } else { + lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || + (LJ_DUALNUM && irt_isinteger(ir->t))); + if (!irref_isk(ref)) { + Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE)); + emit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs); + } else if (!irt_ispri(ir->t)) { + emit_movmroi(as, RID_BASE, ofs, ir->i); + } + if ((sn & (SNAP_CONT|SNAP_FRAME))) { + if (s != 0) /* Do not overwrite link to previous frame. */ + emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--)); + } else { + if (!(LJ_64 && irt_islightud(ir->t))) + emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t)); + } + } + checkmclim(as); + } + lua_assert(map + nent == flinks); +} + +/* -- GC handling --------------------------------------------------------- */ + +/* Check GC threshold and do one or more GC steps. */ +static void asm_gc_check(ASMState *as) +{ + const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; + IRRef args[2]; + MCLabel l_end; + Reg tmp; + ra_evictset(as, RSET_SCRATCH); + l_end = emit_label(as); + /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ + asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ + emit_rr(as, XO_TEST, RID_RET, RID_RET); + args[0] = ASMREF_TMP1; /* global_State *g */ + args[1] = ASMREF_TMP2; /* MSize steps */ + asm_gencall(as, ci, args); + tmp = ra_releasetmp(as, ASMREF_TMP1); + emit_loada(as, tmp, J2G(as->J)); + emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps); + /* Jump around GC step if GC total < GC threshold. */ + emit_sjcc(as, CC_B, l_end); + emit_opgl(as, XO_ARITH(XOg_CMP), tmp, gc.threshold); + emit_getgl(as, tmp, gc.total); + as->gcsteps = 0; + checkmclim(as); +} + +/* -- Loop handling ------------------------------------------------------- */ + +/* Fixup the loop branch. */ +static void asm_loop_fixup(ASMState *as) +{ + MCode *p = as->mctop; + MCode *target = as->mcp; + if (as->realign) { /* Realigned loops use short jumps. */ + as->realign = NULL; /* Stop another retry. */ + lua_assert(((intptr_t)target & 15) == 0); + if (as->loopinv) { /* Inverted loop branch? */ + p -= 5; + p[0] = XI_JMP; + lua_assert(target - p >= -128); + p[-1] = (MCode)(target - p); /* Patch sjcc. */ + if (as->loopinv == 2) + p[-3] = (MCode)(target - p + 2); /* Patch opt. short jp. */ + } else { + lua_assert(target - p >= -128); + p[-1] = (MCode)(int8_t)(target - p); /* Patch short jmp. */ + p[-2] = XI_JMPs; + } + } else { + MCode *newloop; + p[-5] = XI_JMP; + if (as->loopinv) { /* Inverted loop branch? */ + /* asm_guardcc already inverted the jcc and patched the jmp. */ + p -= 5; + newloop = target+4; + *(int32_t *)(p-4) = (int32_t)(target - p); /* Patch jcc. */ + if (as->loopinv == 2) { + *(int32_t *)(p-10) = (int32_t)(target - p + 6); /* Patch opt. jp. */ + newloop = target+8; + } + } else { /* Otherwise just patch jmp. */ + *(int32_t *)(p-4) = (int32_t)(target - p); + newloop = target+3; + } + /* Realign small loops and shorten the loop branch. */ + if (newloop >= p - 128) { + as->realign = newloop; /* Force a retry and remember alignment. */ + as->curins = as->stopins; /* Abort asm_trace now. */ + as->T->nins = as->orignins; /* Remove any added renames. */ + } + } +} + +/* -- Head of trace ------------------------------------------------------- */ + +/* Coalesce BASE register for a root trace. */ +static void asm_head_root_base(ASMState *as) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (r != RID_BASE) + emit_rr(as, XO_MOV, r, RID_BASE); + } +} + +/* Coalesce or reload BASE register for a side trace. */ +static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) +{ + IRIns *ir = IR(REF_BASE); + Reg r = ir->r; + if (ra_hasreg(r)) { + ra_free(as, r); + if (rset_test(as->modset, r) || irt_ismarked(ir->t)) + ir->r = RID_INIT; /* No inheritance for modified BASE register. */ + if (irp->r == r) { + rset_clear(allow, r); /* Mark same BASE register as coalesced. */ + } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) { + rset_clear(allow, irp->r); + emit_rr(as, XO_MOV, r, irp->r); /* Move from coalesced parent reg. */ + } else { + emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */ + } + } + return allow; +} + +/* -- Tail of trace ------------------------------------------------------- */ + +/* Fixup the tail code. */ +static void asm_tail_fixup(ASMState *as, TraceNo lnk) +{ + /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */ + MCode *p = as->mctop; + MCode *target, *q; + int32_t spadj = as->T->spadjust; + if (spadj == 0) { + p -= ((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0); + } else { + MCode *p1; + /* Patch stack adjustment. */ + if (checki8(spadj)) { + p -= 3; + p1 = p-6; + *p1 = (MCode)spadj; + } else { + p1 = p-9; + *(int32_t *)p1 = spadj; + } + if ((as->flags & JIT_F_LEA_AGU)) { +#if LJ_64 + p1[-4] = 0x48; +#endif + p1[-3] = (MCode)XI_LEA; + p1[-2] = MODRM(checki8(spadj) ? XM_OFS8 : XM_OFS32, RID_ESP, RID_ESP); + p1[-1] = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } else { +#if LJ_64 + p1[-3] = 0x48; +#endif + p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi); + p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP); + } + } + /* Patch exit branch. */ + target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_JMP; + /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */ + for (q = as->mctop-1; q >= p; q--) + *q = XI_NOP; + as->mctop = p; +} + +/* Prepare tail of code. */ +static void asm_tail_prep(ASMState *as) +{ + MCode *p = as->mctop; + /* Realign and leave room for backwards loop branch or exit branch. */ + if (as->realign) { + int i = ((int)(intptr_t)as->realign) & 15; + /* Fill unused mcode tail with NOPs to make the prefetcher happy. */ + while (i-- > 0) + *--p = XI_NOP; + as->mctop = p; + p -= (as->loopinv ? 5 : 2); /* Space for short/near jmp. */ + } else { + p -= 5; /* Space for exit branch (near jmp). */ + } + if (as->loopref) { + as->invmcp = as->mcp = p; + } else { + /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */ + as->mcp = p - (((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0)); + as->invmcp = NULL; + } +} + +/* -- Instruction dispatch ------------------------------------------------ */ + +/* Assemble a single instruction. */ +static void asm_ir(ASMState *as, IRIns *ir) +{ + switch ((IROp)ir->o) { + /* Miscellaneous ops. */ + case IR_LOOP: asm_loop(as); break; + case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break; + case IR_USE: + ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break; + case IR_PHI: asm_phi(as, ir); break; + case IR_HIOP: asm_hiop(as, ir); break; + case IR_GCSTEP: asm_gcstep(as, ir); break; + + /* Guarded assertions. */ + case IR_LT: case IR_GE: case IR_LE: case IR_GT: + case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT: + case IR_EQ: case IR_NE: case IR_ABC: + asm_comp(as, ir, asm_compmap[ir->o]); + break; + + case IR_RETF: asm_retf(as, ir); break; + + /* Bit ops. */ + case IR_BNOT: asm_neg_not(as, ir, XOg_NOT); break; + case IR_BSWAP: asm_bitswap(as, ir); break; + + case IR_BAND: asm_intarith(as, ir, XOg_AND); break; + case IR_BOR: asm_intarith(as, ir, XOg_OR); break; + case IR_BXOR: asm_intarith(as, ir, XOg_XOR); break; + + case IR_BSHL: asm_bitshift(as, ir, XOg_SHL); break; + case IR_BSHR: asm_bitshift(as, ir, XOg_SHR); break; + case IR_BSAR: asm_bitshift(as, ir, XOg_SAR); break; + case IR_BROL: asm_bitshift(as, ir, XOg_ROL); break; + case IR_BROR: asm_bitshift(as, ir, XOg_ROR); break; + + /* Arithmetic ops. */ + case IR_ADD: asm_add(as, ir); break; + case IR_SUB: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_SUBSD); + else /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */ + asm_intarith(as, ir, XOg_SUB); + break; + case IR_MUL: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MULSD); + else + asm_intarith(as, ir, XOg_X_IMUL); + break; + case IR_DIV: +#if LJ_64 && LJ_HASFFI + if (!irt_isnum(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 : + IRCALL_lj_carith_divu64); + else +#endif + asm_fparith(as, ir, XO_DIVSD); + break; + case IR_MOD: +#if LJ_64 && LJ_HASFFI + if (!irt_isint(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 : + IRCALL_lj_carith_modu64); + else +#endif + asm_intmod(as, ir); + break; + + case IR_NEG: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_XORPS); + else + asm_neg_not(as, ir, XOg_NEG); + break; + case IR_ABS: asm_fparith(as, ir, XO_ANDPS); break; + + case IR_MIN: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MINSD); + else + asm_min_max(as, ir, CC_G); + break; + case IR_MAX: + if (irt_isnum(ir->t)) + asm_fparith(as, ir, XO_MAXSD); + else + asm_min_max(as, ir, CC_L); + break; + + case IR_FPMATH: case IR_ATAN2: case IR_LDEXP: + asm_fpmath(as, ir); + break; + case IR_POW: +#if LJ_64 && LJ_HASFFI + if (!irt_isnum(ir->t)) + asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 : + IRCALL_lj_carith_powu64); + else +#endif + asm_fppowi(as, ir); + break; + + /* Overflow-checking arithmetic ops. Note: don't use LEA here! */ + case IR_ADDOV: asm_intarith(as, ir, XOg_ADD); break; + case IR_SUBOV: asm_intarith(as, ir, XOg_SUB); break; + case IR_MULOV: asm_intarith(as, ir, XOg_X_IMUL); break; + + /* Memory references. */ + case IR_AREF: asm_aref(as, ir); break; + case IR_HREF: asm_href(as, ir); break; + case IR_HREFK: asm_hrefk(as, ir); break; + case IR_NEWREF: asm_newref(as, ir); break; + case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break; + case IR_FREF: asm_fref(as, ir); break; + case IR_STRREF: asm_strref(as, ir); break; + + /* Loads and stores. */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + asm_ahuvload(as, ir); + break; + case IR_FLOAD: case IR_XLOAD: asm_fxload(as, ir); break; + case IR_SLOAD: asm_sload(as, ir); break; + + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break; + case IR_FSTORE: case IR_XSTORE: asm_fxstore(as, ir); break; + + /* Allocations. */ + case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break; + case IR_TNEW: asm_tnew(as, ir); break; + case IR_TDUP: asm_tdup(as, ir); break; + case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break; + + /* Write barriers. */ + case IR_TBAR: asm_tbar(as, ir); break; + case IR_OBAR: asm_obar(as, ir); break; + + /* Type conversions. */ + case IR_TOBIT: asm_tobit(as, ir); break; + case IR_CONV: asm_conv(as, ir); break; + case IR_TOSTR: asm_tostr(as, ir); break; + case IR_STRTO: asm_strto(as, ir); break; + + /* Calls. */ + case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break; + case IR_CALLXS: asm_callx(as, ir); break; + case IR_CARG: break; + + default: + setintV(&as->J->errinfo, ir->o); + lj_trace_err_info(as->J, LJ_TRERR_NYIIR); + break; + } +} + +/* -- Trace setup --------------------------------------------------------- */ + +/* Ensure there are enough stack slots for call arguments. */ +static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) +{ + IRRef args[CCI_NARGS_MAX*2]; + int nslots; + asm_collectargs(as, ir, ci, args); + nslots = asm_count_call_slots(as, ci, args); + if (nslots > as->evenspill) /* Leave room for args in stack slots. */ + as->evenspill = nslots; +#if LJ_64 + return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET); +#else + return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET); +#endif +} + +/* Target-specific setup. */ +static void asm_setup_target(ASMState *as) +{ + asm_exitstub_setup(as, as->T->nsnap); +} + +/* -- Trace patching ------------------------------------------------------ */ + +/* Patch exit jumps of existing machine code to a new target. */ +void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) +{ + MCode *p = T->mcode; + MCode *mcarea = lj_mcode_patch(J, p, 0); + MSize len = T->szmcode; + MCode *px = exitstub_addr(J, exitno) - 6; + MCode *pe = p+len-6; + uint32_t stateaddr = u32ptr(&J2G(J)->vmstate); + if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px) + *(int32_t *)(p+len-4) = jmprel(p+len, target); + /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */ + for (; p < pe; p++) + if (*(uint32_t *)(p+(LJ_64 ? 3 : 2)) == stateaddr && p[0] == XI_MOVmi) { + p += LJ_64 ? 11 : 10; + break; + } + lua_assert(p < pe); + for (; p < pe; p++) { + if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px) { + *(int32_t *)(p+2) = jmprel(p+6, target); + p += 5; + } + } + lj_mcode_sync(T->mcode, T->mcode + T->szmcode); + lj_mcode_patch(J, mcarea, 1); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.c new file mode 100644 index 0000000..d5d3d78 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.c @@ -0,0 +1,14 @@ +/* +** Bytecode instruction modes. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bc_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_bc.h" + +/* Bytecode offsets and bytecode instruction modes. */ +#include "lj_bcdef.h" + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.h new file mode 100644 index 0000000..1a4ade3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bc.h @@ -0,0 +1,261 @@ +/* +** Bytecode instruction format. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_BC_H +#define _LJ_BC_H + +#include "lj_def.h" +#include "lj_arch.h" + +/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit: +** +** +----+----+----+----+ +** | B | C | A | OP | Format ABC +** +----+----+----+----+ +** | D | A | OP | Format AD +** +-------------------- +** MSB LSB +** +** In-memory instructions are always stored in host byte order. +*/ + +/* Operand ranges and related constants. */ +#define BCMAX_A 0xff +#define BCMAX_B 0xff +#define BCMAX_C 0xff +#define BCMAX_D 0xffff +#define BCBIAS_J 0x8000 +#define NO_REG BCMAX_A +#define NO_JMP (~(BCPos)0) + +/* Macros to get instruction fields. */ +#define bc_op(i) ((BCOp)((i)&0xff)) +#define bc_a(i) ((BCReg)(((i)>>8)&0xff)) +#define bc_b(i) ((BCReg)((i)>>24)) +#define bc_c(i) ((BCReg)(((i)>>16)&0xff)) +#define bc_d(i) ((BCReg)((i)>>16)) +#define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J) + +/* Macros to set instruction fields. */ +#define setbc_byte(p, x, ofs) \ + ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x) +#define setbc_op(p, x) setbc_byte(p, (x), 0) +#define setbc_a(p, x) setbc_byte(p, (x), 1) +#define setbc_b(p, x) setbc_byte(p, (x), 3) +#define setbc_c(p, x) setbc_byte(p, (x), 2) +#define setbc_d(p, x) \ + ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x) +#define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J)) + +/* Macros to compose instructions. */ +#define BCINS_ABC(o, a, b, c) \ + (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16)) +#define BCINS_AD(o, a, d) \ + (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16)) +#define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J)) + +/* Bytecode instruction definition. Order matters, see below. +** +** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod) +** +** The opcode name suffixes specify the type for RB/RC or RD: +** V = variable slot +** S = string const +** N = number const +** P = primitive type (~itype) +** B = unsigned byte literal +** M = multiple args/results +*/ +#define BCDEF(_) \ + /* Comparison ops. ORDER OPR. */ \ + _(ISLT, var, ___, var, lt) \ + _(ISGE, var, ___, var, lt) \ + _(ISLE, var, ___, var, le) \ + _(ISGT, var, ___, var, le) \ + \ + _(ISEQV, var, ___, var, eq) \ + _(ISNEV, var, ___, var, eq) \ + _(ISEQS, var, ___, str, eq) \ + _(ISNES, var, ___, str, eq) \ + _(ISEQN, var, ___, num, eq) \ + _(ISNEN, var, ___, num, eq) \ + _(ISEQP, var, ___, pri, eq) \ + _(ISNEP, var, ___, pri, eq) \ + \ + /* Unary test and copy ops. */ \ + _(ISTC, dst, ___, var, ___) \ + _(ISFC, dst, ___, var, ___) \ + _(IST, ___, ___, var, ___) \ + _(ISF, ___, ___, var, ___) \ + \ + /* Unary ops. */ \ + _(MOV, dst, ___, var, ___) \ + _(NOT, dst, ___, var, ___) \ + _(UNM, dst, ___, var, unm) \ + _(LEN, dst, ___, var, len) \ + \ + /* Binary ops. ORDER OPR. VV last, POW must be next. */ \ + _(ADDVN, dst, var, num, add) \ + _(SUBVN, dst, var, num, sub) \ + _(MULVN, dst, var, num, mul) \ + _(DIVVN, dst, var, num, div) \ + _(MODVN, dst, var, num, mod) \ + \ + _(ADDNV, dst, var, num, add) \ + _(SUBNV, dst, var, num, sub) \ + _(MULNV, dst, var, num, mul) \ + _(DIVNV, dst, var, num, div) \ + _(MODNV, dst, var, num, mod) \ + \ + _(ADDVV, dst, var, var, add) \ + _(SUBVV, dst, var, var, sub) \ + _(MULVV, dst, var, var, mul) \ + _(DIVVV, dst, var, var, div) \ + _(MODVV, dst, var, var, mod) \ + \ + _(POW, dst, var, var, pow) \ + _(CAT, dst, rbase, rbase, concat) \ + \ + /* Constant ops. */ \ + _(KSTR, dst, ___, str, ___) \ + _(KCDATA, dst, ___, cdata, ___) \ + _(KSHORT, dst, ___, lits, ___) \ + _(KNUM, dst, ___, num, ___) \ + _(KPRI, dst, ___, pri, ___) \ + _(KNIL, base, ___, base, ___) \ + \ + /* Upvalue and function ops. */ \ + _(UGET, dst, ___, uv, ___) \ + _(USETV, uv, ___, var, ___) \ + _(USETS, uv, ___, str, ___) \ + _(USETN, uv, ___, num, ___) \ + _(USETP, uv, ___, pri, ___) \ + _(UCLO, rbase, ___, jump, ___) \ + _(FNEW, dst, ___, func, gc) \ + \ + /* Table ops. */ \ + _(TNEW, dst, ___, lit, gc) \ + _(TDUP, dst, ___, tab, gc) \ + _(GGET, dst, ___, str, index) \ + _(GSET, var, ___, str, newindex) \ + _(TGETV, dst, var, var, index) \ + _(TGETS, dst, var, str, index) \ + _(TGETB, dst, var, lit, index) \ + _(TSETV, var, var, var, newindex) \ + _(TSETS, var, var, str, newindex) \ + _(TSETB, var, var, lit, newindex) \ + _(TSETM, base, ___, num, newindex) \ + \ + /* Calls and vararg handling. T = tail call. */ \ + _(CALLM, base, lit, lit, call) \ + _(CALL, base, lit, lit, call) \ + _(CALLMT, base, ___, lit, call) \ + _(CALLT, base, ___, lit, call) \ + _(ITERC, base, lit, lit, call) \ + _(ITERN, base, lit, lit, call) \ + _(VARG, base, lit, lit, ___) \ + _(ISNEXT, base, ___, jump, ___) \ + \ + /* Returns. */ \ + _(RETM, base, ___, lit, ___) \ + _(RET, rbase, ___, lit, ___) \ + _(RET0, rbase, ___, lit, ___) \ + _(RET1, rbase, ___, lit, ___) \ + \ + /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \ + _(FORI, base, ___, jump, ___) \ + _(JFORI, base, ___, jump, ___) \ + \ + _(FORL, base, ___, jump, ___) \ + _(IFORL, base, ___, jump, ___) \ + _(JFORL, base, ___, lit, ___) \ + \ + _(ITERL, base, ___, jump, ___) \ + _(IITERL, base, ___, jump, ___) \ + _(JITERL, base, ___, lit, ___) \ + \ + _(LOOP, rbase, ___, jump, ___) \ + _(ILOOP, rbase, ___, jump, ___) \ + _(JLOOP, rbase, ___, lit, ___) \ + \ + _(JMP, rbase, ___, jump, ___) \ + \ + /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \ + _(FUNCF, rbase, ___, ___, ___) \ + _(IFUNCF, rbase, ___, ___, ___) \ + _(JFUNCF, rbase, ___, lit, ___) \ + _(FUNCV, rbase, ___, ___, ___) \ + _(IFUNCV, rbase, ___, ___, ___) \ + _(JFUNCV, rbase, ___, lit, ___) \ + _(FUNCC, rbase, ___, ___, ___) \ + _(FUNCCW, rbase, ___, ___, ___) + +/* Bytecode opcode numbers. */ +typedef enum { +#define BCENUM(name, ma, mb, mc, mt) BC_##name, +BCDEF(BCENUM) +#undef BCENUM + BC__MAX +} BCOp; + +LJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV); +LJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV); +LJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES); +LJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN); +LJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP); +LJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE); +LJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT); +LJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT); +LJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC); +LJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM); +LJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT); +LJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET); +LJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL); +LJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL); +LJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL); +LJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL); +LJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP); +LJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP); +LJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF); +LJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF); +LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV); +LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV); + +/* This solves a circular dependency problem, change as needed. */ +#define FF_next_N 4 + +/* Stack slots used by FORI/FORL, relative to operand A. */ +enum { + FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT +}; + +/* Bytecode operand modes. ORDER BCMode */ +typedef enum { + BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */ + BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata, + BCM_max +} BCMode; +#define BCM___ BCMnone + +#define bcmode_a(op) ((BCMode)(lj_bc_mode[op] & 7)) +#define bcmode_b(op) ((BCMode)((lj_bc_mode[op]>>3) & 15)) +#define bcmode_c(op) ((BCMode)((lj_bc_mode[op]>>7) & 15)) +#define bcmode_d(op) bcmode_c(op) +#define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3)) +#define bcmode_mm(op) ((MMS)(lj_bc_mode[op]>>11)) + +#define BCMODE(name, ma, mb, mc, mm) \ + (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)), +#define BCMODE_FF 0 + +static LJ_AINLINE int bc_isret(BCOp op) +{ + return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1); +} + +LJ_DATA const uint16_t lj_bc_mode[]; +LJ_DATA const uint16_t lj_bc_ofs[]; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcdump.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcdump.h new file mode 100644 index 0000000..77a789e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcdump.h @@ -0,0 +1,66 @@ +/* +** Bytecode dump definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_BCDUMP_H +#define _LJ_BCDUMP_H + +#include "lj_obj.h" +#include "lj_lex.h" + +/* -- Bytecode dump format ------------------------------------------------ */ + +/* +** dump = header proto+ 0U +** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*] +** proto = lengthU pdata +** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*] +** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU +** [debuglenU [firstlineU numlineU]] +** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* } +** knum = intU0 | (loU1 hiU) +** ktab = narrayU nhashU karray* khash* +** karray = ktabk +** khash = ktabk ktabk +** ktabk = ktabtypeU { intU | (loU hiU) | strB* } +** +** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1 +*/ + +/* Bytecode dump header. */ +#define BCDUMP_HEAD1 0x1b +#define BCDUMP_HEAD2 0x4c +#define BCDUMP_HEAD3 0x4a + +/* If you perform *any* kind of private modifications to the bytecode itself +** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher. +*/ +#define BCDUMP_VERSION 1 + +/* Compatibility flags. */ +#define BCDUMP_F_BE 0x01 +#define BCDUMP_F_STRIP 0x02 +#define BCDUMP_F_FFI 0x04 + +#define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1) + +/* Type codes for the GC constants of a prototype. Plus length for strings. */ +enum { + BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64, + BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR +}; + +/* Type codes for the keys/values of a constant table. */ +enum { + BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE, + BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR +}; + +/* -- Bytecode reader/writer ---------------------------------------------- */ + +LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, + void *data, int strip); +LJ_FUNC GCproto *lj_bcread(LexState *ls); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcread.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcread.c new file mode 100644 index 0000000..c0baece --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcread.c @@ -0,0 +1,476 @@ +/* +** Bytecode reader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bcread_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lualib.h" +#endif +#include "lj_lex.h" +#include "lj_bcdump.h" +#include "lj_state.h" + +/* Reuse some lexer fields for our own purposes. */ +#define bcread_flags(ls) ls->level +#define bcread_swap(ls) \ + ((bcread_flags(ls) & BCDUMP_F_BE) != LJ_BE*BCDUMP_F_BE) +#define bcread_oldtop(L, ls) restorestack(L, ls->lastline) +#define bcread_savetop(L, ls, top) \ + ls->lastline = (BCLine)savestack(L, (top)) + +/* -- Input buffer handling ----------------------------------------------- */ + +/* Throw reader error. */ +static LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em) +{ + lua_State *L = ls->L; + const char *name = ls->chunkarg; + if (*name == BCDUMP_HEAD1) name = "(binary)"; + else if (*name == '@' || *name == '=') name++; + lj_str_pushf(L, "%s: %s", name, err2msg(em)); + lj_err_throw(L, LUA_ERRSYNTAX); +} + +/* Resize input buffer. */ +static void bcread_resize(LexState *ls, MSize len) +{ + if (ls->sb.sz < len) { + MSize sz = ls->sb.sz * 2; + while (len > sz) sz = sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, sz); + /* Caveat: this may change ls->sb.buf which may affect ls->p. */ + } +} + +/* Refill buffer if needed. */ +static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) +{ + lua_assert(len != 0); + if (len > LJ_MAX_MEM || ls->current < 0) + bcread_error(ls, LJ_ERR_BCBAD); + do { + const char *buf; + size_t size; + if (ls->n) { /* Copy remainder to buffer. */ + if (ls->sb.n) { /* Move down in buffer. */ + lua_assert(ls->p + ls->n == ls->sb.buf + ls->sb.n); + if (ls->n != ls->sb.n) + memmove(ls->sb.buf, ls->p, ls->n); + } else { /* Copy from buffer provided by reader. */ + bcread_resize(ls, len); + memcpy(ls->sb.buf, ls->p, ls->n); + } + ls->p = ls->sb.buf; + } + ls->sb.n = ls->n; + buf = ls->rfunc(ls->L, ls->rdata, &size); /* Get more data from reader. */ + if (buf == NULL || size == 0) { /* EOF? */ + if (need) bcread_error(ls, LJ_ERR_BCBAD); + ls->current = -1; /* Only bad if we get called again. */ + break; + } + if (ls->sb.n) { /* Append to buffer. */ + MSize n = ls->sb.n + (MSize)size; + bcread_resize(ls, n < len ? len : n); + memcpy(ls->sb.buf + ls->sb.n, buf, size); + ls->n = ls->sb.n = n; + ls->p = ls->sb.buf; + } else { /* Return buffer provided by reader. */ + ls->n = (MSize)size; + ls->p = buf; + } + } while (ls->n < len); +} + +/* Need a certain number of bytes. */ +static LJ_AINLINE void bcread_need(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->n < len)) + bcread_fill(ls, len, 1); +} + +/* Want to read up to a certain number of bytes, but may need less. */ +static LJ_AINLINE void bcread_want(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->n < len)) + bcread_fill(ls, len, 0); +} + +#define bcread_dec(ls) check_exp(ls->n > 0, ls->n--) +#define bcread_consume(ls, len) check_exp(ls->n >= (len), ls->n -= (len)) + +/* Return memory block from buffer. */ +static uint8_t *bcread_mem(LexState *ls, MSize len) +{ + uint8_t *p = (uint8_t *)ls->p; + bcread_consume(ls, len); + ls->p = (char *)p + len; + return p; +} + +/* Copy memory block from buffer. */ +static void bcread_block(LexState *ls, void *q, MSize len) +{ + memcpy(q, bcread_mem(ls, len), len); +} + +/* Read byte from buffer. */ +static LJ_AINLINE uint32_t bcread_byte(LexState *ls) +{ + bcread_dec(ls); + return (uint32_t)(uint8_t)*ls->p++; +} + +/* Read ULEB128 value from buffer. */ +static uint32_t bcread_uleb128(LexState *ls) +{ + const uint8_t *p = (const uint8_t *)ls->p; + uint32_t v = *p++; + if (LJ_UNLIKELY(v >= 0x80)) { + int sh = 0; + v &= 0x7f; + do { + v |= ((*p & 0x7f) << (sh += 7)); + bcread_dec(ls); + } while (*p++ >= 0x80); + } + bcread_dec(ls); + ls->p = (char *)p; + return v; +} + +/* Read top 32 bits of 33 bit ULEB128 value from buffer. */ +static uint32_t bcread_uleb128_33(LexState *ls) +{ + const uint8_t *p = (const uint8_t *)ls->p; + uint32_t v = (*p++ >> 1); + if (LJ_UNLIKELY(v >= 0x40)) { + int sh = -1; + v &= 0x3f; + do { + v |= ((*p & 0x7f) << (sh += 7)); + bcread_dec(ls); + } while (*p++ >= 0x80); + } + bcread_dec(ls); + ls->p = (char *)p; + return v; +} + +/* -- Bytecode reader ----------------------------------------------------- */ + +/* Read debug info of a prototype. */ +static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg) +{ + void *lineinfo = (void *)proto_lineinfo(pt); + bcread_block(ls, lineinfo, sizedbg); + /* Swap lineinfo if the endianess differs. */ + if (bcread_swap(ls) && pt->numline >= 256) { + MSize i, n = pt->sizebc-1; + if (pt->numline < 65536) { + uint16_t *p = (uint16_t *)lineinfo; + for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8)); + } else { + uint32_t *p = (uint32_t *)lineinfo; + for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]); + } + } +} + +/* Find pointer to varinfo. */ +static const void *bcread_varinfo(GCproto *pt) +{ + const uint8_t *p = proto_uvinfo(pt); + MSize n = pt->sizeuv; + if (n) while (*p++ || --n) ; + return p; +} + +/* Read a single constant key/value of a template table. */ +static void bcread_ktabk(LexState *ls, TValue *o) +{ + MSize tp = bcread_uleb128(ls); + if (tp >= BCDUMP_KTAB_STR) { + MSize len = tp - BCDUMP_KTAB_STR; + const char *p = (const char *)bcread_mem(ls, len); + setstrV(ls->L, o, lj_str_new(ls->L, p, len)); + } else if (tp == BCDUMP_KTAB_INT) { + setintV(o, (int32_t)bcread_uleb128(ls)); + } else if (tp == BCDUMP_KTAB_NUM) { + o->u32.lo = bcread_uleb128(ls); + o->u32.hi = bcread_uleb128(ls); + } else { + lua_assert(tp <= BCDUMP_KTAB_TRUE); + setitype(o, ~tp); + } +} + +/* Read a template table. */ +static GCtab *bcread_ktab(LexState *ls) +{ + MSize narray = bcread_uleb128(ls); + MSize nhash = bcread_uleb128(ls); + GCtab *t = lj_tab_new(ls->L, narray, hsize2hbits(nhash)); + if (narray) { /* Read array entries. */ + MSize i; + TValue *o = tvref(t->array); + for (i = 0; i < narray; i++, o++) + bcread_ktabk(ls, o); + } + if (nhash) { /* Read hash entries. */ + MSize i; + for (i = 0; i < nhash; i++) { + TValue key; + bcread_ktabk(ls, &key); + lua_assert(!tvisnil(&key)); + bcread_ktabk(ls, lj_tab_set(ls->L, t, &key)); + } + } + return t; +} + +/* Read GC constants of a prototype. */ +static void bcread_kgc(LexState *ls, GCproto *pt, MSize sizekgc) +{ + MSize i; + GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc; + for (i = 0; i < sizekgc; i++, kr++) { + MSize tp = bcread_uleb128(ls); + if (tp >= BCDUMP_KGC_STR) { + MSize len = tp - BCDUMP_KGC_STR; + const char *p = (const char *)bcread_mem(ls, len); + setgcref(*kr, obj2gco(lj_str_new(ls->L, p, len))); + } else if (tp == BCDUMP_KGC_TAB) { + setgcref(*kr, obj2gco(bcread_ktab(ls))); +#if LJ_HASFFI + } else if (tp != BCDUMP_KGC_CHILD) { + CTypeID id = tp == BCDUMP_KGC_COMPLEX ? CTID_COMPLEX_DOUBLE : + tp == BCDUMP_KGC_I64 ? CTID_INT64 : CTID_UINT64; + CTSize sz = tp == BCDUMP_KGC_COMPLEX ? 16 : 8; + GCcdata *cd = lj_cdata_new_(ls->L, id, sz); + TValue *p = (TValue *)cdataptr(cd); + setgcref(*kr, obj2gco(cd)); + p[0].u32.lo = bcread_uleb128(ls); + p[0].u32.hi = bcread_uleb128(ls); + if (tp == BCDUMP_KGC_COMPLEX) { + p[1].u32.lo = bcread_uleb128(ls); + p[1].u32.hi = bcread_uleb128(ls); + } +#endif + } else { + lua_State *L = ls->L; + lua_assert(tp == BCDUMP_KGC_CHILD); + if (L->top <= bcread_oldtop(L, ls)) /* Stack underflow? */ + bcread_error(ls, LJ_ERR_BCBAD); + L->top--; + setgcref(*kr, obj2gco(protoV(L->top))); + } + } +} + +/* Read number constants of a prototype. */ +static void bcread_knum(LexState *ls, GCproto *pt, MSize sizekn) +{ + MSize i; + TValue *o = mref(pt->k, TValue); + for (i = 0; i < sizekn; i++, o++) { + int isnum = (ls->p[0] & 1); + uint32_t lo = bcread_uleb128_33(ls); + if (isnum) { + o->u32.lo = lo; + o->u32.hi = bcread_uleb128(ls); + } else { + setintV(o, lo); + } + } +} + +/* Read bytecode instructions. */ +static void bcread_bytecode(LexState *ls, GCproto *pt, MSize sizebc) +{ + BCIns *bc = proto_bc(pt); + bc[0] = BCINS_AD((pt->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF, + pt->framesize, 0); + bcread_block(ls, bc+1, (sizebc-1)*(MSize)sizeof(BCIns)); + /* Swap bytecode instructions if the endianess differs. */ + if (bcread_swap(ls)) { + MSize i; + for (i = 1; i < sizebc; i++) bc[i] = lj_bswap(bc[i]); + } +} + +/* Read upvalue refs. */ +static void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv) +{ + if (sizeuv) { + uint16_t *uv = proto_uv(pt); + bcread_block(ls, uv, sizeuv*2); + /* Swap upvalue refs if the endianess differs. */ + if (bcread_swap(ls)) { + MSize i; + for (i = 0; i < sizeuv; i++) + uv[i] = (uint16_t)((uv[i] >> 8)|(uv[i] << 8)); + } + } +} + +/* Read a prototype. */ +static GCproto *bcread_proto(LexState *ls) +{ + GCproto *pt; + MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept; + MSize ofsk, ofsuv, ofsdbg; + MSize sizedbg = 0; + BCLine firstline = 0, numline = 0; + MSize len, startn; + + /* Read length. */ + if (ls->n > 0 && ls->p[0] == 0) { /* Shortcut EOF. */ + ls->n--; ls->p++; + return NULL; + } + bcread_want(ls, 5); + len = bcread_uleb128(ls); + if (!len) return NULL; /* EOF */ + bcread_need(ls, len); + startn = ls->n; + + /* Read prototype header. */ + flags = bcread_byte(ls); + numparams = bcread_byte(ls); + framesize = bcread_byte(ls); + sizeuv = bcread_byte(ls); + sizekgc = bcread_uleb128(ls); + sizekn = bcread_uleb128(ls); + sizebc = bcread_uleb128(ls) + 1; + if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) { + sizedbg = bcread_uleb128(ls); + if (sizedbg) { + firstline = bcread_uleb128(ls); + numline = bcread_uleb128(ls); + } + } + + /* Calculate total size of prototype including all colocated arrays. */ + sizept = (MSize)sizeof(GCproto) + + sizebc*(MSize)sizeof(BCIns) + + sizekgc*(MSize)sizeof(GCRef); + sizept = (sizept + (MSize)sizeof(TValue)-1) & ~((MSize)sizeof(TValue)-1); + ofsk = sizept; sizept += sizekn*(MSize)sizeof(TValue); + ofsuv = sizept; sizept += ((sizeuv+1)&~1)*2; + ofsdbg = sizept; sizept += sizedbg; + + /* Allocate prototype object and initialize its fields. */ + pt = (GCproto *)lj_mem_newgco(ls->L, (MSize)sizept); + pt->gct = ~LJ_TPROTO; + pt->numparams = (uint8_t)numparams; + pt->framesize = (uint8_t)framesize; + pt->sizebc = sizebc; + setmref(pt->k, (char *)pt + ofsk); + setmref(pt->uv, (char *)pt + ofsuv); + pt->sizekgc = 0; /* Set to zero until fully initialized. */ + pt->sizekn = sizekn; + pt->sizept = sizept; + pt->sizeuv = (uint8_t)sizeuv; + pt->flags = (uint8_t)flags; + pt->trace = 0; + setgcref(pt->chunkname, obj2gco(ls->chunkname)); + + /* Close potentially uninitialized gap between bc and kgc. */ + *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(sizekgc+1)) = 0; + + /* Read bytecode instructions and upvalue refs. */ + bcread_bytecode(ls, pt, sizebc); + bcread_uv(ls, pt, sizeuv); + + /* Read constants. */ + bcread_kgc(ls, pt, sizekgc); + pt->sizekgc = sizekgc; + bcread_knum(ls, pt, sizekn); + + /* Read and initialize debug info. */ + pt->firstline = firstline; + pt->numline = numline; + if (sizedbg) { + MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2); + setmref(pt->lineinfo, (char *)pt + ofsdbg); + setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli); + bcread_dbg(ls, pt, sizedbg); + setmref(pt->varinfo, bcread_varinfo(pt)); + } else { + setmref(pt->lineinfo, NULL); + setmref(pt->uvinfo, NULL); + setmref(pt->varinfo, NULL); + } + + if (len != startn - ls->n) + bcread_error(ls, LJ_ERR_BCBAD); + return pt; +} + +/* Read and check header of bytecode dump. */ +static int bcread_header(LexState *ls) +{ + uint32_t flags; + bcread_want(ls, 3+5+5); + if (bcread_byte(ls) != BCDUMP_HEAD2 || + bcread_byte(ls) != BCDUMP_HEAD3 || + bcread_byte(ls) != BCDUMP_VERSION) return 0; + bcread_flags(ls) = flags = bcread_uleb128(ls); + if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0; + if ((flags & BCDUMP_F_FFI)) { +#if LJ_HASFFI + lua_State *L = ls->L; + if (!ctype_ctsG(G(L))) { + ptrdiff_t oldtop = savestack(L, L->top); + luaopen_ffi(L); /* Load FFI library on-demand. */ + L->top = restorestack(L, oldtop); + } +#else + return 0; +#endif + } + if ((flags & BCDUMP_F_STRIP)) { + ls->chunkname = lj_str_newz(ls->L, ls->chunkarg); + } else { + MSize len = bcread_uleb128(ls); + bcread_need(ls, len); + ls->chunkname = lj_str_new(ls->L, (const char *)bcread_mem(ls, len), len); + } + return 1; /* Ok. */ +} + +/* Read a bytecode dump. */ +GCproto *lj_bcread(LexState *ls) +{ + lua_State *L = ls->L; + lua_assert(ls->current == BCDUMP_HEAD1); + bcread_savetop(L, ls, L->top); + lj_str_resetbuf(&ls->sb); + /* Check for a valid bytecode dump header. */ + if (!bcread_header(ls)) + bcread_error(ls, LJ_ERR_BCFMT); + for (;;) { /* Process all prototypes in the bytecode dump. */ + GCproto *pt = bcread_proto(ls); + if (!pt) break; + setprotoV(L, L->top, pt); + incr_top(L); + } + if ((int32_t)ls->n > 0 || L->top-1 != bcread_oldtop(L, ls)) + bcread_error(ls, LJ_ERR_BCBAD); + /* Pop off last prototype. */ + L->top--; + return protoV(L->top); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcwrite.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcwrite.c new file mode 100644 index 0000000..dcdaa10 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_bcwrite.c @@ -0,0 +1,396 @@ +/* +** Bytecode writer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_bcwrite_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#if LJ_HASJIT +#include "lj_dispatch.h" +#include "lj_jit.h" +#endif +#include "lj_bcdump.h" +#include "lj_vm.h" + +/* Context for bytecode writer. */ +typedef struct BCWriteCtx { + SBuf sb; /* Output buffer. */ + lua_State *L; /* Lua state. */ + GCproto *pt; /* Root prototype. */ + lua_Writer wfunc; /* Writer callback. */ + void *wdata; /* Writer callback data. */ + int strip; /* Strip debug info. */ + int status; /* Status from writer callback. */ +} BCWriteCtx; + +/* -- Output buffer handling ---------------------------------------------- */ + +/* Resize buffer if needed. */ +static LJ_NOINLINE void bcwrite_resize(BCWriteCtx *ctx, MSize len) +{ + MSize sz = ctx->sb.sz * 2; + while (ctx->sb.n + len > sz) sz = sz * 2; + lj_str_resizebuf(ctx->L, &ctx->sb, sz); +} + +/* Need a certain amount of buffer space. */ +static LJ_AINLINE void bcwrite_need(BCWriteCtx *ctx, MSize len) +{ + if (LJ_UNLIKELY(ctx->sb.n + len > ctx->sb.sz)) + bcwrite_resize(ctx, len); +} + +/* Add memory block to buffer. */ +static void bcwrite_block(BCWriteCtx *ctx, const void *p, MSize len) +{ + uint8_t *q = (uint8_t *)(ctx->sb.buf + ctx->sb.n); + MSize i; + ctx->sb.n += len; + for (i = 0; i < len; i++) q[i] = ((uint8_t *)p)[i]; +} + +/* Add byte to buffer. */ +static LJ_AINLINE void bcwrite_byte(BCWriteCtx *ctx, uint8_t b) +{ + ctx->sb.buf[ctx->sb.n++] = b; +} + +/* Add ULEB128 value to buffer. */ +static void bcwrite_uleb128(BCWriteCtx *ctx, uint32_t v) +{ + MSize n = ctx->sb.n; + uint8_t *p = (uint8_t *)ctx->sb.buf; + for (; v >= 0x80; v >>= 7) + p[n++] = (uint8_t)((v & 0x7f) | 0x80); + p[n++] = (uint8_t)v; + ctx->sb.n = n; +} + +/* -- Bytecode writer ----------------------------------------------------- */ + +/* Write a single constant key/value of a template table. */ +static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow) +{ + bcwrite_need(ctx, 1+10); + if (tvisstr(o)) { + const GCstr *str = strV(o); + MSize len = str->len; + bcwrite_need(ctx, 5+len); + bcwrite_uleb128(ctx, BCDUMP_KTAB_STR+len); + bcwrite_block(ctx, strdata(str), len); + } else if (tvisint(o)) { + bcwrite_byte(ctx, BCDUMP_KTAB_INT); + bcwrite_uleb128(ctx, intV(o)); + } else if (tvisnum(o)) { + if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ + lua_Number num = numV(o); + int32_t k = lj_num2int(num); + if (num == (lua_Number)k) { /* -0 is never a constant. */ + bcwrite_byte(ctx, BCDUMP_KTAB_INT); + bcwrite_uleb128(ctx, k); + return; + } + } + bcwrite_byte(ctx, BCDUMP_KTAB_NUM); + bcwrite_uleb128(ctx, o->u32.lo); + bcwrite_uleb128(ctx, o->u32.hi); + } else { + lua_assert(tvispri(o)); + bcwrite_byte(ctx, BCDUMP_KTAB_NIL+~itype(o)); + } +} + +/* Write a template table. */ +static void bcwrite_ktab(BCWriteCtx *ctx, const GCtab *t) +{ + MSize narray = 0, nhash = 0; + if (t->asize > 0) { /* Determine max. length of array part. */ + ptrdiff_t i; + TValue *array = tvref(t->array); + for (i = (ptrdiff_t)t->asize-1; i >= 0; i--) + if (!tvisnil(&array[i])) + break; + narray = (MSize)(i+1); + } + if (t->hmask > 0) { /* Count number of used hash slots. */ + MSize i, hmask = t->hmask; + Node *node = noderef(t->node); + for (i = 0; i <= hmask; i++) + nhash += !tvisnil(&node[i].val); + } + /* Write number of array slots and hash slots. */ + bcwrite_uleb128(ctx, narray); + bcwrite_uleb128(ctx, nhash); + if (narray) { /* Write array entries (may contain nil). */ + MSize i; + TValue *o = tvref(t->array); + for (i = 0; i < narray; i++, o++) + bcwrite_ktabk(ctx, o, 1); + } + if (nhash) { /* Write hash entries. */ + MSize i = nhash; + Node *node = noderef(t->node) + t->hmask; + for (;; node--) + if (!tvisnil(&node->val)) { + bcwrite_ktabk(ctx, &node->key, 0); + bcwrite_ktabk(ctx, &node->val, 1); + if (--i == 0) break; + } + } +} + +/* Write GC constants of a prototype. */ +static void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt) +{ + MSize i, sizekgc = pt->sizekgc; + GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc; + for (i = 0; i < sizekgc; i++, kr++) { + GCobj *o = gcref(*kr); + MSize tp, need = 1; + /* Determine constant type and needed size. */ + if (o->gch.gct == ~LJ_TSTR) { + tp = BCDUMP_KGC_STR + gco2str(o)->len; + need = 5+gco2str(o)->len; + } else if (o->gch.gct == ~LJ_TPROTO) { + lua_assert((pt->flags & PROTO_CHILD)); + tp = BCDUMP_KGC_CHILD; +#if LJ_HASFFI + } else if (o->gch.gct == ~LJ_TCDATA) { + CTypeID id = gco2cd(o)->ctypeid; + need = 1+4*5; + if (id == CTID_INT64) { + tp = BCDUMP_KGC_I64; + } else if (id == CTID_UINT64) { + tp = BCDUMP_KGC_U64; + } else { + lua_assert(id == CTID_COMPLEX_DOUBLE); + tp = BCDUMP_KGC_COMPLEX; + } +#endif + } else { + lua_assert(o->gch.gct == ~LJ_TTAB); + tp = BCDUMP_KGC_TAB; + need = 1+2*5; + } + /* Write constant type. */ + bcwrite_need(ctx, need); + bcwrite_uleb128(ctx, tp); + /* Write constant data (if any). */ + if (tp >= BCDUMP_KGC_STR) { + bcwrite_block(ctx, strdata(gco2str(o)), gco2str(o)->len); + } else if (tp == BCDUMP_KGC_TAB) { + bcwrite_ktab(ctx, gco2tab(o)); +#if LJ_HASFFI + } else if (tp != BCDUMP_KGC_CHILD) { + cTValue *p = (TValue *)cdataptr(gco2cd(o)); + bcwrite_uleb128(ctx, p[0].u32.lo); + bcwrite_uleb128(ctx, p[0].u32.hi); + if (tp == BCDUMP_KGC_COMPLEX) { + bcwrite_uleb128(ctx, p[1].u32.lo); + bcwrite_uleb128(ctx, p[1].u32.hi); + } +#endif + } + } +} + +/* Write number constants of a prototype. */ +static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt) +{ + MSize i, sizekn = pt->sizekn; + cTValue *o = mref(pt->k, TValue); + bcwrite_need(ctx, 10*sizekn); + for (i = 0; i < sizekn; i++, o++) { + int32_t k; + if (tvisint(o)) { + k = intV(o); + goto save_int; + } else { + /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */ + if (!LJ_DUALNUM) { /* Narrow number constants to integers. */ + lua_Number num = numV(o); + k = lj_num2int(num); + if (num == (lua_Number)k) { /* -0 is never a constant. */ + save_int: + bcwrite_uleb128(ctx, 2*(uint32_t)k | ((uint32_t)k & 0x80000000u)); + if (k < 0) { + char *p = &ctx->sb.buf[ctx->sb.n-1]; + *p = (*p & 7) | ((k>>27) & 0x18); + } + continue; + } + } + bcwrite_uleb128(ctx, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u))); + if (o->u32.lo >= 0x80000000u) { + char *p = &ctx->sb.buf[ctx->sb.n-1]; + *p = (*p & 7) | ((o->u32.lo>>27) & 0x18); + } + bcwrite_uleb128(ctx, o->u32.hi); + } + } +} + +/* Write bytecode instructions. */ +static void bcwrite_bytecode(BCWriteCtx *ctx, GCproto *pt) +{ + MSize nbc = pt->sizebc-1; /* Omit the [JI]FUNC* header. */ +#if LJ_HASJIT + uint8_t *p = (uint8_t *)&ctx->sb.buf[ctx->sb.n]; +#endif + bcwrite_block(ctx, proto_bc(pt)+1, nbc*(MSize)sizeof(BCIns)); +#if LJ_HASJIT + /* Unpatch modified bytecode containing ILOOP/JLOOP etc. */ + if ((pt->flags & PROTO_ILOOP) || pt->trace) { + jit_State *J = L2J(ctx->L); + MSize i; + for (i = 0; i < nbc; i++, p += sizeof(BCIns)) { + BCOp op = (BCOp)p[LJ_ENDIAN_SELECT(0, 3)]; + if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP || + op == BC_JFORI) { + p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_IFORL+BC_FORL); + } else if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) { + BCReg rd = p[LJ_ENDIAN_SELECT(2, 1)] + (p[LJ_ENDIAN_SELECT(3, 0)] << 8); + BCIns ins = traceref(J, rd)->startins; + p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_JFORL+BC_FORL); + p[LJ_ENDIAN_SELECT(2, 1)] = bc_c(ins); + p[LJ_ENDIAN_SELECT(3, 0)] = bc_b(ins); + } + } + } +#endif +} + +/* Write prototype. */ +static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt) +{ + MSize sizedbg = 0; + + /* Recursively write children of prototype. */ + if ((pt->flags & PROTO_CHILD)) { + ptrdiff_t i, n = pt->sizekgc; + GCRef *kr = mref(pt->k, GCRef) - 1; + for (i = 0; i < n; i++, kr--) { + GCobj *o = gcref(*kr); + if (o->gch.gct == ~LJ_TPROTO) + bcwrite_proto(ctx, gco2pt(o)); + } + } + + /* Start writing the prototype info to a buffer. */ + lj_str_resetbuf(&ctx->sb); + ctx->sb.n = 5; /* Leave room for final size. */ + bcwrite_need(ctx, 4+6*5+(pt->sizebc-1)*(MSize)sizeof(BCIns)+pt->sizeuv*2); + + /* Write prototype header. */ + bcwrite_byte(ctx, (pt->flags & (PROTO_CHILD|PROTO_VARARG|PROTO_FFI))); + bcwrite_byte(ctx, pt->numparams); + bcwrite_byte(ctx, pt->framesize); + bcwrite_byte(ctx, pt->sizeuv); + bcwrite_uleb128(ctx, pt->sizekgc); + bcwrite_uleb128(ctx, pt->sizekn); + bcwrite_uleb128(ctx, pt->sizebc-1); + if (!ctx->strip) { + if (proto_lineinfo(pt)) + sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt); + bcwrite_uleb128(ctx, sizedbg); + if (sizedbg) { + bcwrite_uleb128(ctx, pt->firstline); + bcwrite_uleb128(ctx, pt->numline); + } + } + + /* Write bytecode instructions and upvalue refs. */ + bcwrite_bytecode(ctx, pt); + bcwrite_block(ctx, proto_uv(pt), pt->sizeuv*2); + + /* Write constants. */ + bcwrite_kgc(ctx, pt); + bcwrite_knum(ctx, pt); + + /* Write debug info, if not stripped. */ + if (sizedbg) { + bcwrite_need(ctx, sizedbg); + bcwrite_block(ctx, proto_lineinfo(pt), sizedbg); + } + + /* Pass buffer to writer function. */ + if (ctx->status == 0) { + MSize n = ctx->sb.n - 5; + MSize nn = (lj_fls(n)+8)*9 >> 6; + ctx->sb.n = 5 - nn; + bcwrite_uleb128(ctx, n); /* Fill in final size. */ + lua_assert(ctx->sb.n == 5); + ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf+5-nn, nn+n, ctx->wdata); + } +} + +/* Write header of bytecode dump. */ +static void bcwrite_header(BCWriteCtx *ctx) +{ + GCstr *chunkname = proto_chunkname(ctx->pt); + const char *name = strdata(chunkname); + MSize len = chunkname->len; + lj_str_resetbuf(&ctx->sb); + bcwrite_need(ctx, 5+5+len); + bcwrite_byte(ctx, BCDUMP_HEAD1); + bcwrite_byte(ctx, BCDUMP_HEAD2); + bcwrite_byte(ctx, BCDUMP_HEAD3); + bcwrite_byte(ctx, BCDUMP_VERSION); + bcwrite_byte(ctx, (ctx->strip ? BCDUMP_F_STRIP : 0) + + (LJ_BE ? BCDUMP_F_BE : 0) + + ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0)); + if (!ctx->strip) { + bcwrite_uleb128(ctx, len); + bcwrite_block(ctx, name, len); + } + ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf, ctx->sb.n, ctx->wdata); +} + +/* Write footer of bytecode dump. */ +static void bcwrite_footer(BCWriteCtx *ctx) +{ + if (ctx->status == 0) { + uint8_t zero = 0; + ctx->status = ctx->wfunc(ctx->L, &zero, 1, ctx->wdata); + } +} + +/* Protected callback for bytecode writer. */ +static TValue *cpwriter(lua_State *L, lua_CFunction dummy, void *ud) +{ + BCWriteCtx *ctx = (BCWriteCtx *)ud; + UNUSED(dummy); + lj_str_resizebuf(L, &ctx->sb, 1024); /* Avoids resize for most prototypes. */ + bcwrite_header(ctx); + bcwrite_proto(ctx, ctx->pt); + bcwrite_footer(ctx); + return NULL; +} + +/* Write bytecode for a prototype. */ +int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, void *data, + int strip) +{ + BCWriteCtx ctx; + int status; + ctx.L = L; + ctx.pt = pt; + ctx.wfunc = writer; + ctx.wdata = data; + ctx.strip = strip; + ctx.status = 0; + lj_str_initbuf(&ctx.sb); + status = lj_vm_cpcall(L, NULL, &ctx, cpwriter); + if (status == 0) status = ctx.status; + lj_str_freebuf(G(ctx.L), &ctx.sb); + return status; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.c new file mode 100644 index 0000000..9f94091 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.c @@ -0,0 +1,351 @@ +/* +** C data arithmetic. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_carith.h" + +/* -- C data arithmetic --------------------------------------------------- */ + +/* Binary operands of an operator converted to ctypes. */ +typedef struct CDArith { + uint8_t *p[2]; + CType *ct[2]; +} CDArith; + +/* Check arguments for arithmetic metamethods. */ +static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) +{ + TValue *o = L->base; + int ok = 1; + MSize i; + if (o+1 >= L->top) + lj_err_argt(L, 1, LUA_TCDATA); + for (i = 0; i < 2; i++, o++) { + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + CTypeID id = (CTypeID)cd->ctypeid; + CType *ct = ctype_raw(cts, id); + uint8_t *p = (uint8_t *)cdataptr(cd); + if (ctype_isptr(ct->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); + } else if (ctype_isfunc(ct->info)) { + p = (uint8_t *)*(void **)p; + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); + } + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + ca->ct[i] = ct; + ca->p[i] = p; + } else if (tvisint(o)) { + ca->ct[i] = ctype_get(cts, CTID_INT32); + ca->p[i] = (uint8_t *)&o->i; + } else if (tvisnum(o)) { + ca->ct[i] = ctype_get(cts, CTID_DOUBLE); + ca->p[i] = (uint8_t *)&o->n; + } else if (tvisnil(o)) { + ca->ct[i] = ctype_get(cts, CTID_P_VOID); + ca->p[i] = (uint8_t *)0; + } else if (tvisstr(o)) { + TValue *o2 = i == 0 ? o+1 : o-1; + CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid); + ca->ct[i] = NULL; + ca->p[i] = NULL; + ok = 0; + if (ctype_isenum(ct->info)) { + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, ct, strV(o), &ofs); + if (cct && ctype_isconstval(cct->info)) { + ca->ct[i] = ctype_child(cts, cct); + ca->p[i] = (uint8_t *)&cct->size; /* Assumes ct does not grow. */ + ok = 1; + } else { + ca->ct[1-i] = ct; /* Use enum to improve error message. */ + ca->p[1-i] = NULL; + break; + } + } + } else { + ca->ct[i] = NULL; + ca->p[i] = NULL; + ok = 0; + } + } + return ok; +} + +/* Pointer arithmetic. */ +static int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + CType *ctp = ca->ct[0]; + uint8_t *pp = ca->p[0]; + ptrdiff_t idx; + CTSize sz; + CTypeID id; + GCcdata *cd; + if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) { + if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) && + (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) { + uint8_t *pp2 = ca->p[1]; + if (mm == MM_eq) { /* Pointer equality. Incompatible pointers are ok. */ + setboolV(L->top-1, (pp == pp2)); + return 1; + } + if (!lj_cconv_compatptr(cts, ctp, ca->ct[1], CCF_IGNQUAL)) + return 0; + if (mm == MM_sub) { /* Pointer difference. */ + intptr_t diff; + sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */ + if (sz == 0 || sz == CTSIZE_INVALID) + return 0; + diff = ((intptr_t)pp - (intptr_t)pp2) / (int32_t)sz; + /* All valid pointer differences on x64 are in (-2^47, +2^47), + ** which fits into a double without loss of precision. + */ + setintptrV(L->top-1, (int32_t)diff); + return 1; + } else if (mm == MM_lt) { /* Pointer comparison (unsigned). */ + setboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2)); + return 1; + } else { + lua_assert(mm == MM_le); + setboolV(L->top-1, ((uintptr_t)pp <= (uintptr_t)pp2)); + return 1; + } + } + if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(ca->ct[1]->info))) + return 0; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[1], + (uint8_t *)&idx, ca->p[1], 0); + if (mm == MM_sub) idx = -idx; + } else if (mm == MM_add && ctype_isnum(ctp->info) && + (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) { + /* Swap pointer and index. */ + ctp = ca->ct[1]; pp = ca->p[1]; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[0], + (uint8_t *)&idx, ca->p[0], 0); + } else { + return 0; + } + sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */ + if (sz == CTSIZE_INVALID) + return 0; + pp += idx*(int32_t)sz; /* Compute pointer + index. */ + id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)), + CTSIZE_PTR); + cd = lj_cdata_new(cts, id, CTSIZE_PTR); + *(uint8_t **)cdataptr(cd) = pp; + setcdataV(L, L->top-1, cd); + lj_gc_check(L); + return 1; +} + +/* 64 bit integer arithmetic. */ +static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + if (ctype_isnum(ca->ct[0]->info) && ca->ct[0]->size <= 8 && + ctype_isnum(ca->ct[1]->info) && ca->ct[1]->size <= 8) { + CTypeID id = (((ca->ct[0]->info & CTF_UNSIGNED) && ca->ct[0]->size == 8) || + ((ca->ct[1]->info & CTF_UNSIGNED) && ca->ct[1]->size == 8)) ? + CTID_UINT64 : CTID_INT64; + CType *ct = ctype_get(cts, id); + GCcdata *cd; + uint64_t u0, u1, *up; + lj_cconv_ct_ct(cts, ct, ca->ct[0], (uint8_t *)&u0, ca->p[0], 0); + if (mm != MM_unm) + lj_cconv_ct_ct(cts, ct, ca->ct[1], (uint8_t *)&u1, ca->p[1], 0); + switch (mm) { + case MM_eq: + setboolV(L->top-1, (u0 == u1)); + return 1; + case MM_lt: + setboolV(L->top-1, + id == CTID_INT64 ? ((int64_t)u0 < (int64_t)u1) : (u0 < u1)); + return 1; + case MM_le: + setboolV(L->top-1, + id == CTID_INT64 ? ((int64_t)u0 <= (int64_t)u1) : (u0 <= u1)); + return 1; + default: break; + } + cd = lj_cdata_new(cts, id, 8); + up = (uint64_t *)cdataptr(cd); + setcdataV(L, L->top-1, cd); + switch (mm) { + case MM_add: *up = u0 + u1; break; + case MM_sub: *up = u0 - u1; break; + case MM_mul: *up = u0 * u1; break; + case MM_div: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_divi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_divu64(u0, u1); + break; + case MM_mod: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_modi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_modu64(u0, u1); + break; + case MM_pow: + if (id == CTID_INT64) + *up = (uint64_t)lj_carith_powi64((int64_t)u0, (int64_t)u1); + else + *up = lj_carith_powu64(u0, u1); + break; + case MM_unm: *up = (uint64_t)-(int64_t)u0; break; + default: lua_assert(0); break; + } + lj_gc_check(L); + return 1; + } + return 0; +} + +/* Handle ctype arithmetic metamethods. */ +static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm) +{ + cTValue *tv = NULL; + if (tviscdata(L->base)) { + CTypeID id = cdataV(L->base)->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + } + if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) { + CTypeID id = cdataV(L->base+1)->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, mm); + } + if (!tv) { + const char *repr[2]; + int i, isenum = -1, isstr = -1; + if (mm == MM_eq) { /* Equality checks never raise an error. */ + setboolV(L->top-1, 0); + return 1; + } + for (i = 0; i < 2; i++) { + if (ca->ct[i] && tviscdata(L->base+i)) { + if (ctype_isenum(ca->ct[i]->info)) isenum = i; + repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); + } else { + if (tvisstr(&L->base[i])) isstr = i; + repr[i] = lj_typename(&L->base[i]); + } + } + if ((isenum ^ isstr) == 1) + lj_err_callerv(L, LJ_ERR_FFI_BADCONV, repr[isstr], repr[isenum]); + lj_err_callerv(L, mm == MM_len ? LJ_ERR_FFI_BADLEN : + mm == MM_concat ? LJ_ERR_FFI_BADCONCAT : + mm < MM_add ? LJ_ERR_FFI_BADCOMP : LJ_ERR_FFI_BADARITH, + repr[0], repr[1]); + } + return lj_meta_tailcall(L, tv); +} + +/* Arithmetic operators for cdata. */ +int lj_carith_op(lua_State *L, MMS mm) +{ + CTState *cts = ctype_cts(L); + CDArith ca; + if (carith_checkarg(L, cts, &ca)) { + if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) { + copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */ + return 1; + } + } + return lj_carith_meta(L, cts, &ca, mm); +} + +/* -- 64 bit integer arithmetic helpers ----------------------------------- */ + +#if LJ_32 && LJ_HASJIT +/* Signed/unsigned 64 bit multiplication. */ +int64_t lj_carith_mul64(int64_t a, int64_t b) +{ + return a * b; +} +#endif + +/* Unsigned 64 bit division. */ +uint64_t lj_carith_divu64(uint64_t a, uint64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + return a / b; +} + +/* Signed 64 bit division. */ +int64_t lj_carith_divi64(int64_t a, int64_t b) +{ + if (b == 0 || (a == (int64_t)U64x(80000000,00000000) && b == -1)) + return U64x(80000000,00000000); + return a / b; +} + +/* Unsigned 64 bit modulo. */ +uint64_t lj_carith_modu64(uint64_t a, uint64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + return a % b; +} + +/* Signed 64 bit modulo. */ +int64_t lj_carith_modi64(int64_t a, int64_t b) +{ + if (b == 0) return U64x(80000000,00000000); + if (a == (int64_t)U64x(80000000,00000000) && b == -1) return 0; + return a % b; +} + +/* Unsigned 64 bit x^k. */ +uint64_t lj_carith_powu64(uint64_t x, uint64_t k) +{ + uint64_t y; + if (k == 0) + return 1; + for (; (k & 1) == 0; k >>= 1) x *= x; + y = x; + if ((k >>= 1) != 0) { + for (;;) { + x *= x; + if (k == 1) break; + if (k & 1) y *= x; + k >>= 1; + } + y *= x; + } + return y; +} + +/* Signed 64 bit x^k. */ +int64_t lj_carith_powi64(int64_t x, int64_t k) +{ + if (k == 0) + return 1; + if (k < 0) { + if (x == 0) + return U64x(7fffffff,ffffffff); + else if (x == 1) + return 1; + else if (x == -1) + return (k & 1) ? -1 : 1; + else + return 0; + } + return (int64_t)lj_carith_powu64((uint64_t)x, (uint64_t)k); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.h new file mode 100644 index 0000000..8b28556 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_carith.h @@ -0,0 +1,27 @@ +/* +** C data arithmetic. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CARITH_H +#define _LJ_CARITH_H + +#include "lj_obj.h" + +#if LJ_HASFFI + +LJ_FUNC int lj_carith_op(lua_State *L, MMS mm); + +#if LJ_32 && LJ_HASJIT +LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k); +#endif +LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b); +LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b); +LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b); +LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b); +LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k); +LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.c new file mode 100644 index 0000000..70c9ba5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.c @@ -0,0 +1,900 @@ +/* +** FFI C call handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_ccall.h" +#include "lj_trace.h" + +/* Target-specific handling of register arguments. */ +#if LJ_TARGET_X86 +/* -- x86 calling conventions --------------------------------------------- */ + +#if LJ_ABI_WIN + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs bigger than 8 by reference (on stack only). */ \ + cc->retref = (sz > 8); \ + if (cc->retref) cc->stack[nsp++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET + +#else + +#if LJ_TARGET_OSX + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size 1, 2, 4 or 8 in registers. */ \ + cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \ + if (cc->retref) { \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; \ + } else { /* Struct with single FP field ends up in FPR. */ \ + cc->resx87 = ccall_classify_struct(cts, ctr); \ + } + +#define CCALL_HANDLE_STRUCTRET2 \ + if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \ + memcpy(dp, sp, ctr->size); + +#else + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference (in reg or on stack). */ \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; + +#endif + +#define CCALL_HANDLE_COMPLEXRET \ + /* Return complex float in GPRs and complex double by reference. */ \ + cc->retref = (sz > 8); \ + if (cc->retref) { \ + if (ngpr < maxgpr) \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + else \ + cc->stack[nsp++] = (GPRArg)dp; \ + } + +#endif + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!cc->retref) \ + *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + ngpr = maxgpr; /* Pass all structs by value on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 1; /* Pass complex by value on stack. */ + +#define CCALL_HANDLE_REGARG \ + if (!isfp) { /* Only non-FP values may be passed in registers. */ \ + if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \ + if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \ + } else if (ngpr + 1 <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_X64 && LJ_ABI_WIN +/* -- Windows/x64 calling conventions ------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \ + cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!cc->retref) \ + *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \ + if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all other structs by reference. */ \ + } + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex float in a GPR and complex double by reference. */ \ + if (sz != 2*sizeof(float)) { \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; \ + } + +/* Windows/x64 argument registers are strictly positional (use ngpr). */ +#define CCALL_HANDLE_REGARG \ + if (isfp) { \ + if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \ + } else { \ + if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \ + } + +#elif LJ_TARGET_X64 +/* -- POSIX/x64 calling conventions --------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + if (ccall_classify_struct(cts, ctr, rcl, 0)) { \ + cc->retref = 1; /* Return struct by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; \ + } else { \ + cc->retref = 0; /* Return small structs in registers. */ \ + } + +#define CCALL_HANDLE_STRUCTRET2 \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + ccall_classify_struct(cts, ctr, rcl, 0); \ + ccall_struct_ret(cc, rcl, dp, ctr->size); + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in one or two FPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPR. */ \ + *(int64_t *)dp = cc->fpr[0].l[0]; \ + } else { /* Copy non-contiguous complex double from FPRs. */ \ + ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \ + ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \ + } + +#define CCALL_HANDLE_STRUCTARG \ + int rcl[2]; rcl[0] = rcl[1] = 0; \ + if (!ccall_classify_struct(cts, d, rcl, 0)) { \ + cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \ + if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \ + nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \ + continue; \ + } /* Pass all other structs by value on stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 2; /* Pass complex in FPRs or on stack. Needs postprocessing. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp) { /* Try to pass argument in FPRs. */ \ + int n2 = ctype_isvector(d->info) ? 1 : n; \ + if (nfpr + n2 <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += n2; \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + /* Note that reordering is explicitly allowed in the x64 ABI. */ \ + if (n <= 2 && ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_ARM +/* -- ARM calling conventions --------------------------------------------- */ + +#if LJ_ABI_SOFTFP + +#define CCALL_HANDLE_STRUCTRET \ + /* Return structs of size <= 4 in a GPR. */ \ + cc->retref = !(sz <= 4); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + cc->retref = 1; /* Return all complex values by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET2 \ + UNUSED(dp); /* Nothing to do. */ + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG_FP1 +#define CCALL_HANDLE_REGARG_FP2 + +#else + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = !ccall_classify_struct(cts, ctr, ct); \ + if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_STRUCTRET2 \ + if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \ + memcpy(dp, sp, ctr->size); + +#define CCALL_HANDLE_COMPLEXRET \ + if (!(ct->info & CTF_VARARG)) cc->retref = 0; /* Return complex in FPRs. */ + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size); + +#define CCALL_HANDLE_STRUCTARG \ + isfp = (ccall_classify_struct(cts, d, ct) > 1); + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + isfp = 1; /* Pass complex by value in FPRs or on stack. */ + +#define CCALL_HANDLE_REGARG_FP1 \ + if (isfp && !(ct->info & CTF_VARARG)) { \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \ + if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += (n >> 1); \ + goto done; \ + } \ + } else { \ + if (sz > 1 && fprodd != nfpr) fprodd = 0; \ + if (fprodd) { \ + if (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \ + dp = (void *)&cc->fpr[fprodd-1].f[1]; \ + nfpr += (n >> 1); \ + if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \ + goto done; \ + } \ + } else { \ + if (2*nfpr+n <= 2*CCALL_NARG_FPR) { \ + dp = (void *)&cc->fpr[nfpr]; \ + nfpr += (n >> 1); \ + if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \ + goto done; \ + } \ + } \ + } \ + fprodd = 0; /* No reordering after the first FP value is on stack. */ \ + } else { + +#define CCALL_HANDLE_REGARG_FP2 } + +#endif + +#define CCALL_HANDLE_REGARG \ + CCALL_HANDLE_REGARG_FP1 \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \ + if (ngpr < maxgpr) \ + ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + } \ + if (ngpr < maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + if (ngpr + n > maxgpr) { \ + nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \ + if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \ + ngpr = maxgpr; \ + } else { \ + ngpr += n; \ + } \ + goto done; \ + } CCALL_HANDLE_REGARG_FP2 + +#define CCALL_HANDLE_RET \ + if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0]; + +#elif LJ_TARGET_PPC +/* -- PPC calling conventions --------------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 2 or 4 GPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all structs by reference. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp) { /* Try to pass argument in FPRs. */ \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + dp = &cc->fpr[nfpr]; \ + nfpr += 1; \ + d = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + if (n > 1) { \ + lua_assert(n == 2 || n == 4); /* int64_t or complex (float). */ \ + if (ctype_isinteger(d->info)) \ + ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \ + else if (ngpr + n > maxgpr) \ + ngpr = maxgpr; /* Prevent reordering. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CCALL_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + ctr = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ + +#elif LJ_TARGET_PPCSPE +/* -- PPC/SPE calling conventions ----------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 2 or 4 GPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */ + +#define CCALL_HANDLE_STRUCTARG \ + rp = cdataptr(lj_cdata_new(cts, did, sz)); \ + sz = CTSIZE_PTR; /* Pass all structs by reference. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +/* PPC/SPE has a softfp ABI. */ +#define CCALL_HANDLE_REGARG \ + if (n > 1) { /* Doesn't fit in a single GPR? */ \ + lua_assert(n == 2 || n == 4); /* int64_t, double or complex (float). */ \ + if (n == 2) \ + ngpr = (ngpr + 1u) & ~1u; /* Only align 64 bit value to regpair. */ \ + else if (ngpr + n > maxgpr) \ + ngpr = maxgpr; /* Prevent reordering. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } + +#elif LJ_TARGET_MIPS +/* -- MIPS calling conventions -------------------------------------------- */ + +#define CCALL_HANDLE_STRUCTRET \ + cc->retref = 1; /* Return all structs by reference. */ \ + cc->gpr[ngpr++] = (GPRArg)dp; + +#define CCALL_HANDLE_COMPLEXRET \ + /* Complex values are returned in 1 or 2 FPRs. */ \ + cc->retref = 0; + +#define CCALL_HANDLE_COMPLEXRET2 \ + if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPRs. */ \ + ((float *)dp)[0] = cc->fpr[0].f; \ + ((float *)dp)[1] = cc->fpr[1].f; \ + } else { /* Copy complex double from FPRs. */ \ + ((double *)dp)[0] = cc->fpr[0].d; \ + ((double *)dp)[1] = cc->fpr[1].d; \ + } + +#define CCALL_HANDLE_STRUCTARG \ + /* Pass all structs by value in registers and/or on the stack. */ + +#define CCALL_HANDLE_COMPLEXARG \ + /* Pass complex by value in 2 or 4 GPRs. */ + +#define CCALL_HANDLE_REGARG \ + if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \ + /* Try to pass argument in FPRs. */ \ + dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \ + nfpr++; ngpr += n; \ + goto done; \ + } else { /* Try to pass argument in GPRs. */ \ + nfpr = CCALL_NARG_FPR; \ + if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \ + ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr < maxgpr) { \ + dp = &cc->gpr[ngpr]; \ + if (ngpr + n > maxgpr) { \ + nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \ + if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \ + ngpr = maxgpr; \ + } else { \ + ngpr += n; \ + } \ + goto done; \ + } \ + } + +#define CCALL_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + sp = (uint8_t *)&cc->fpr[0].f; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +#ifndef CCALL_HANDLE_STRUCTRET2 +#define CCALL_HANDLE_STRUCTRET2 \ + memcpy(dp, sp, ctr->size); /* Copy struct return value from GPRs. */ +#endif + +/* -- x86 OSX ABI struct classification ----------------------------------- */ + +#if LJ_TARGET_X86 && LJ_TARGET_OSX + +/* Check for struct with single FP field. */ +static int ccall_classify_struct(CTState *cts, CType *ct) +{ + CTSize sz = ct->size; + if (!(sz == sizeof(float) || sz == sizeof(double))) return 0; + if ((ct->info & CTF_UNION)) return 0; + while (ct->sib) { + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + CType *sct = ctype_rawchild(cts, ct); + if (ctype_isfp(sct->info)) { + if (sct->size == sz) + return (sz >> 2); /* Return 1 for float or 2 for double. */ + } else if (ctype_isstruct(sct->info)) { + if (sct->size) + return ccall_classify_struct(cts, sct); + } else { + break; + } + } else if (ctype_isbitfield(ct->info)) { + break; + } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + CType *sct = ctype_rawchild(cts, ct); + if (sct->size) + return ccall_classify_struct(cts, sct); + } + } + return 0; +} + +#endif + +/* -- x64 struct classification ------------------------------------------- */ + +#if LJ_TARGET_X64 && !LJ_ABI_WIN + +/* Register classes for x64 struct classification. */ +#define CCALL_RCL_INT 1 +#define CCALL_RCL_SSE 2 +#define CCALL_RCL_MEM 4 +/* NYI: classify vectors. */ + +static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs); + +/* Classify a C type. */ +static void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs) +{ + if (ctype_isarray(ct->info)) { + CType *cct = ctype_rawchild(cts, ct); + CTSize eofs, esz = cct->size, asz = ct->size; + for (eofs = 0; eofs < asz; eofs += esz) + ccall_classify_ct(cts, cct, rcl, ofs+eofs); + } else if (ctype_isstruct(ct->info)) { + ccall_classify_struct(cts, ct, rcl, ofs); + } else { + int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT; + lua_assert(ctype_hassize(ct->info)); + if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM; /* Unaligned. */ + rcl[(ofs >= 8)] |= cl; + } +} + +/* Recursively classify a struct based on its fields. */ +static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs) +{ + if (ct->size > 16) return CCALL_RCL_MEM; /* Too big, gets memory class. */ + while (ct->sib) { + CTSize fofs; + ct = ctype_get(cts, ct->sib); + fofs = ofs+ct->size; + if (ctype_isfield(ct->info)) + ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs); + else if (ctype_isbitfield(ct->info)) + rcl[(fofs >= 8)] |= CCALL_RCL_INT; /* NYI: unaligned bitfields? */ + else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) + ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs); + } + return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM); /* Memory class? */ +} + +/* Try to split up a small struct into registers. */ +static int ccall_struct_reg(CCallState *cc, GPRArg *dp, int *rcl) +{ + MSize ngpr = cc->ngpr, nfpr = cc->nfpr; + uint32_t i; + for (i = 0; i < 2; i++) { + lua_assert(!(rcl[i] & CCALL_RCL_MEM)); + if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */ + if (ngpr >= CCALL_NARG_GPR) return 1; /* Register overflow. */ + cc->gpr[ngpr++] = dp[i]; + } else if ((rcl[i] & CCALL_RCL_SSE)) { + if (nfpr >= CCALL_NARG_FPR) return 1; /* Register overflow. */ + cc->fpr[nfpr++].l[0] = dp[i]; + } + } + cc->ngpr = ngpr; cc->nfpr = nfpr; + return 0; /* Ok. */ +} + +/* Pass a small struct argument. */ +static int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl, + TValue *o, int narg) +{ + GPRArg dp[2]; + dp[0] = dp[1] = 0; + /* Convert to temp. struct. */ + lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg)); + if (ccall_struct_reg(cc, dp, rcl)) { /* Register overflow? Pass on stack. */ + MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1; + if (nsp + n > CCALL_MAXSTACK) return 1; /* Too many arguments. */ + cc->nsp = nsp + n; + memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR); + } + return 0; /* Ok. */ +} + +/* Combine returned small struct. */ +static void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz) +{ + GPRArg sp[2]; + MSize ngpr = 0, nfpr = 0; + uint32_t i; + for (i = 0; i < 2; i++) { + if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */ + sp[i] = cc->gpr[ngpr++]; + } else if ((rcl[i] & CCALL_RCL_SSE)) { + sp[i] = cc->fpr[nfpr++].l[0]; + } + } + memcpy(dp, sp, sz); +} +#endif + +/* -- ARM hard-float ABI struct classification ---------------------------- */ + +#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP + +/* Classify a struct based on its fields. */ +static unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf) +{ + CTSize sz = ct->size; + unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION); + if ((ctf->info & CTF_VARARG)) goto noth; + while (ct->sib) { + CType *sct; + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + sct = ctype_rawchild(cts, ct); + if (ctype_isfp(sct->info)) { + r |= sct->size; + if (!isu) n++; else if (n == 0) n = 1; + } else if (ctype_iscomplex(sct->info)) { + r |= (sct->size >> 1); + if (!isu) n += 2; else if (n < 2) n = 2; + } else if (ctype_isstruct(sct->info)) { + goto substruct; + } else { + goto noth; + } + } else if (ctype_isbitfield(ct->info)) { + goto noth; + } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + sct = ctype_rawchild(cts, ct); + substruct: + if (sct->size > 0) { + unsigned int s = ccall_classify_struct(cts, sct, ctf); + if (s <= 1) goto noth; + r |= (s & 255); + if (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8); + } + } + } + if ((r == 4 || r == 8) && n <= 4) + return r + (n << 8); +noth: /* Not a homogeneous float/double aggregate. */ + return (sz <= 4); /* Return structs of size <= 4 in a GPR. */ +} + +#endif + +/* -- Common C call handling ---------------------------------------------- */ + +/* Infer the destination CTypeID for a vararg argument. */ +CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o) +{ + if (tvisnumber(o)) { + return CTID_DOUBLE; + } else if (tviscdata(o)) { + CTypeID id = cdataV(o)->ctypeid; + CType *s = ctype_get(cts, id); + if (ctype_isrefarray(s->info)) { + return lj_ctype_intern(cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR); + } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) { + /* NYI: how to pass a struct by value in a vararg argument? */ + return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR); + } else if (ctype_isfp(s->info) && s->size == sizeof(float)) { + return CTID_DOUBLE; + } else { + return id; + } + } else if (tvisstr(o)) { + return CTID_P_CCHAR; + } else if (tvisbool(o)) { + return CTID_BOOL; + } else { + return CTID_P_VOID; + } +} + +/* Setup arguments for C call. */ +static int ccall_set_args(lua_State *L, CTState *cts, CType *ct, + CCallState *cc) +{ + int gcsteps = 0; + TValue *o, *top = L->top; + CTypeID fid; + CType *ctr; + MSize maxgpr, ngpr = 0, nsp = 0, narg; +#if CCALL_NARG_FPR + MSize nfpr = 0; +#if LJ_TARGET_ARM + MSize fprodd = 0; +#endif +#endif + + /* Clear unused regs to get some determinism in case of misdeclaration. */ + memset(cc->gpr, 0, sizeof(cc->gpr)); +#if CCALL_NUM_FPR + memset(cc->fpr, 0, sizeof(cc->fpr)); +#endif + +#if LJ_TARGET_X86 + /* x86 has several different calling conventions. */ + cc->resx87 = 0; + switch (ctype_cconv(ct->info)) { + case CTCC_FASTCALL: maxgpr = 2; break; + case CTCC_THISCALL: maxgpr = 1; break; + default: maxgpr = 0; break; + } +#else + maxgpr = CCALL_NARG_GPR; +#endif + + /* Perform required setup for some result types. */ + ctr = ctype_rawchild(cts, ct); + if (ctype_isvector(ctr->info)) { + if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16))) + goto err_nyi; + } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) { + /* Preallocate cdata object and anchor it after arguments. */ + CTSize sz = ctr->size; + GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz); + void *dp = cdataptr(cd); + setcdataV(L, L->top++, cd); + if (ctype_isstruct(ctr->info)) { + CCALL_HANDLE_STRUCTRET + } else { + CCALL_HANDLE_COMPLEXRET + } +#if LJ_TARGET_X86 + } else if (ctype_isfp(ctr->info)) { + cc->resx87 = ctr->size == sizeof(float) ? 1 : 2; +#endif + } + + /* Skip initial attributes. */ + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) break; + fid = ctf->sib; + } + + /* Walk through all passed arguments. */ + for (o = L->base+1, narg = 1; o < top; o++, narg++) { + CTypeID did; + CType *d; + CTSize sz; + MSize n, isfp = 0, isva = 0; + void *dp, *rp = NULL; + + if (fid) { /* Get argument type from field. */ + CType *ctf = ctype_get(cts, fid); + fid = ctf->sib; + lua_assert(ctype_isfield(ctf->info)); + did = ctype_cid(ctf->info); + } else { + if (!(ct->info & CTF_VARARG)) + lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too many arguments. */ + did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */ + isva = 1; + } + d = ctype_raw(cts, did); + sz = d->size; + + /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */ + if (ctype_isnum(d->info)) { + if (sz > 8) goto err_nyi; + if ((d->info & CTF_FP)) + isfp = 1; + } else if (ctype_isvector(d->info)) { + if (CCALL_VECTOR_REG && (sz == 8 || sz == 16)) + isfp = 1; + else + goto err_nyi; + } else if (ctype_isstruct(d->info)) { + CCALL_HANDLE_STRUCTARG + } else if (ctype_iscomplex(d->info)) { + CCALL_HANDLE_COMPLEXARG + } else { + sz = CTSIZE_PTR; + } + sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1); + n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */ + + CCALL_HANDLE_REGARG /* Handle register arguments. */ + + /* Otherwise pass argument on stack. */ + if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) { + MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1; + nsp = (nsp + align) & ~align; /* Align argument on stack. */ + } + if (nsp + n > CCALL_MAXSTACK) { /* Too many arguments. */ + err_nyi: + lj_err_caller(L, LJ_ERR_FFI_NYICALL); + } + dp = &cc->stack[nsp]; + nsp += n; + isva = 0; + + done: + if (rp) { /* Pass by reference. */ + gcsteps++; + *(void **)dp = rp; + dp = rp; + } + lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg)); + /* Extend passed integers to 32 bits at least. */ + if (ctype_isinteger_or_bool(d->info) && d->size < 4) { + if (d->info & CTF_UNSIGNED) + *(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp : + (uint32_t)*(uint16_t *)dp; + else + *(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp : + (int32_t)*(int16_t *)dp; + } +#if LJ_TARGET_X64 && LJ_ABI_WIN + if (isva) { /* Windows/x64 mirrors varargs in both register sets. */ + if (nfpr == ngpr) + cc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0]; + else + cc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1]; + } +#else + UNUSED(isva); +#endif +#if LJ_TARGET_X64 && !LJ_ABI_WIN + if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) { + cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1]; /* Split complex double. */ + cc->fpr[nfpr-2].d[1] = 0; + } +#else + UNUSED(isfp); +#endif + } + if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too few arguments. */ + +#if LJ_TARGET_X64 || LJ_TARGET_PPC + cc->nfpr = nfpr; /* Required for vararg functions. */ +#endif + cc->nsp = nsp; + cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR; + if (nsp > CCALL_SPS_FREE) + cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u); + return gcsteps; +} + +/* Get results from C call. */ +static int ccall_get_results(lua_State *L, CTState *cts, CType *ct, + CCallState *cc, int *ret) +{ + CType *ctr = ctype_rawchild(cts, ct); + uint8_t *sp = (uint8_t *)&cc->gpr[0]; + if (ctype_isvoid(ctr->info)) { + *ret = 0; /* Zero results. */ + return 0; /* No additional GC step. */ + } + *ret = 1; /* One result. */ + if (ctype_isstruct(ctr->info)) { + /* Return cdata object which is already on top of stack. */ + if (!cc->retref) { + void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */ + CCALL_HANDLE_STRUCTRET2 + } + return 1; /* One GC step. */ + } + if (ctype_iscomplex(ctr->info)) { + /* Return cdata object which is already on top of stack. */ + void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */ + CCALL_HANDLE_COMPLEXRET2 + return 1; /* One GC step. */ + } + if (LJ_BE && ctype_isinteger_or_bool(ctr->info) && ctr->size < CTSIZE_PTR) + sp += (CTSIZE_PTR - ctr->size); +#if CCALL_NUM_FPR + if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info)) + sp = (uint8_t *)&cc->fpr[0]; +#endif +#ifdef CCALL_HANDLE_RET + CCALL_HANDLE_RET +#endif + /* No reference types end up here, so there's no need for the CTypeID. */ + lua_assert(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info))); + return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp); +} + +/* Call C function. */ +int lj_ccall_func(lua_State *L, GCcdata *cd) +{ + CTState *cts = ctype_cts(L); + CType *ct = ctype_raw(cts, cd->ctypeid); + CTSize sz = CTSIZE_PTR; + if (ctype_isptr(ct->info)) { + sz = ct->size; + ct = ctype_rawchild(cts, ct); + } + if (ctype_isfunc(ct->info)) { + CCallState cc; + int gcsteps, ret; + cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz); + gcsteps = ccall_set_args(L, cts, ct, &cc); + ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab); + cts->cb.slot = ~0u; + lj_vm_ffi_call(&cc); + if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */ + TValue tv; + setlightudV(&tv, (void *)cc.func); + setboolV(lj_tab_set(L, cts->miscmap, &tv), 1); + } + ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab); /* May be reallocated. */ + gcsteps += ccall_get_results(L, cts, ct, &cc, &ret); +#if LJ_TARGET_X86 && LJ_ABI_WIN + /* Automatically detect __stdcall and fix up C function declaration. */ + if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) { + CTF_INSERT(ct->info, CCONV, CTCC_STDCALL); + lj_trace_abort(G(L)); + } +#endif + while (gcsteps-- > 0) + lj_gc_check(L); + return ret; + } + return -1; /* Not a function. */ +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.h new file mode 100644 index 0000000..c3ea9e6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccall.h @@ -0,0 +1,171 @@ +/* +** FFI C call handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCALL_H +#define _LJ_CCALL_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* -- C calling conventions ----------------------------------------------- */ + +#if LJ_TARGET_X86ORX64 + +#if LJ_TARGET_X86 +#define CCALL_NARG_GPR 2 /* For fastcall arguments. */ +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 1 /* For FP results on x87 stack. */ +#define CCALL_ALIGN_STACKARG 0 /* Don't align argument on stack. */ +#elif LJ_ABI_WIN +#define CCALL_NARG_GPR 4 +#define CCALL_NARG_FPR 4 +#define CCALL_NRET_GPR 1 +#define CCALL_NRET_FPR 1 +#define CCALL_SPS_EXTRA 4 +#else +#define CCALL_NARG_GPR 6 +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 2 +#define CCALL_VECTOR_REG 1 /* Pass vectors in registers. */ +#endif + +#define CCALL_SPS_FREE 1 +#define CCALL_ALIGN_CALLSTATE 16 + +typedef LJ_ALIGN(16) union FPRArg { + double d[2]; + float f[4]; + uint8_t b[16]; + uint16_t s[8]; + int i[4]; + int64_t l[2]; +} FPRArg; + +typedef intptr_t GPRArg; + +#elif LJ_TARGET_ARM + +#define CCALL_NARG_GPR 4 +#define CCALL_NRET_GPR 2 /* For softfp double. */ +#if LJ_ABI_SOFTFP +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_FPR 0 +#else +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_FPR 4 +#endif +#define CCALL_SPS_FREE 0 + +typedef intptr_t GPRArg; +typedef union FPRArg { + double d; + float f[2]; +} FPRArg; + +#elif LJ_TARGET_PPC + +#define CCALL_NARG_GPR 8 +#define CCALL_NARG_FPR 8 +#define CCALL_NRET_GPR 4 /* For complex double. */ +#define CCALL_NRET_FPR 1 +#define CCALL_SPS_EXTRA 4 +#define CCALL_SPS_FREE 0 + +typedef intptr_t GPRArg; +typedef double FPRArg; + +#elif LJ_TARGET_PPCSPE + +#define CCALL_NARG_GPR 8 +#define CCALL_NARG_FPR 0 +#define CCALL_NRET_GPR 4 /* For softfp complex double. */ +#define CCALL_NRET_FPR 0 +#define CCALL_SPS_FREE 0 /* NYI */ + +typedef intptr_t GPRArg; + +#elif LJ_TARGET_MIPS + +#define CCALL_NARG_GPR 4 +#define CCALL_NARG_FPR 2 +#define CCALL_NRET_GPR 2 +#define CCALL_NRET_FPR 2 +#define CCALL_SPS_EXTRA 7 +#define CCALL_SPS_FREE 1 + +typedef intptr_t GPRArg; +typedef union FPRArg { + double d; + struct { LJ_ENDIAN_LOHI(float f; , float g;) }; +} FPRArg; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +#ifndef CCALL_SPS_EXTRA +#define CCALL_SPS_EXTRA 0 +#endif +#ifndef CCALL_VECTOR_REG +#define CCALL_VECTOR_REG 0 +#endif +#ifndef CCALL_ALIGN_STACKARG +#define CCALL_ALIGN_STACKARG 1 +#endif +#ifndef CCALL_ALIGN_CALLSTATE +#define CCALL_ALIGN_CALLSTATE 8 +#endif + +#define CCALL_NUM_GPR \ + (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR) +#define CCALL_NUM_FPR \ + (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR) + +/* Check against constants in lj_ctype.h. */ +LJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR); +LJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR); + +#define CCALL_MAXSTACK 32 + +/* -- C call state -------------------------------------------------------- */ + +typedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState { + void (*func)(void); /* Pointer to called function. */ + uint32_t spadj; /* Stack pointer adjustment. */ + uint8_t nsp; /* Number of stack slots. */ + uint8_t retref; /* Return value by reference. */ +#if LJ_TARGET_X64 + uint8_t ngpr; /* Number of arguments in GPRs. */ + uint8_t nfpr; /* Number of arguments in FPRs. */ +#elif LJ_TARGET_X86 + uint8_t resx87; /* Result on x87 stack: 1:float, 2:double. */ +#elif LJ_TARGET_PPC + uint8_t nfpr; /* Number of arguments in FPRs. */ +#endif +#if LJ_32 + int32_t align1; +#endif +#if CCALL_NUM_FPR + FPRArg fpr[CCALL_NUM_FPR]; /* Arguments/results in FPRs. */ +#endif + GPRArg gpr[CCALL_NUM_GPR]; /* Arguments/results in GPRs. */ + GPRArg stack[CCALL_MAXSTACK]; /* Stack slots. */ +} CCallState; + +/* -- C call handling ----------------------------------------------------- */ + +/* Really belongs to lj_vm.h. */ +LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc); + +LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o); +LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.c new file mode 100644 index 0000000..d872d67 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.c @@ -0,0 +1,644 @@ +/* +** FFI C callback handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_ccall.h" +#include "lj_ccallback.h" +#include "lj_target.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* -- Target-specific handling of callback slots -------------------------- */ + +#define CALLBACK_MCODE_SIZE (LJ_PAGESIZE * LJ_NUM_CBPAGE) + +#if LJ_OS_NOJIT + +/* Disabled callback support. */ +#define CALLBACK_SLOT2OFS(slot) (0*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) +#define CALLBACK_MAX_SLOT 0 + +#elif LJ_TARGET_X86ORX64 + +#define CALLBACK_MCODE_HEAD (LJ_64 ? 8 : 0) +#define CALLBACK_MCODE_GROUP (-2+1+2+5+(LJ_64 ? 6 : 5)) + +#define CALLBACK_SLOT2OFS(slot) \ + (CALLBACK_MCODE_HEAD + CALLBACK_MCODE_GROUP*((slot)/32) + 4*(slot)) + +static MSize CALLBACK_OFS2SLOT(MSize ofs) +{ + MSize group; + ofs -= CALLBACK_MCODE_HEAD; + group = ofs / (32*4 + CALLBACK_MCODE_GROUP); + return (ofs % (32*4 + CALLBACK_MCODE_GROUP))/4 + group*32; +} + +#define CALLBACK_MAX_SLOT \ + (((CALLBACK_MCODE_SIZE-CALLBACK_MCODE_HEAD)/(CALLBACK_MCODE_GROUP+4*32))*32) + +#elif LJ_TARGET_ARM + +#define CALLBACK_MCODE_HEAD 32 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#elif LJ_TARGET_PPC + +#define CALLBACK_MCODE_HEAD 24 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#elif LJ_TARGET_MIPS + +#define CALLBACK_MCODE_HEAD 24 +#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) +#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) + +#else + +/* Missing support for this architecture. */ +#define CALLBACK_SLOT2OFS(slot) (0*(slot)) +#define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) +#define CALLBACK_MAX_SLOT 0 + +#endif + +/* Convert callback slot number to callback function pointer. */ +static void *callback_slot2ptr(CTState *cts, MSize slot) +{ + return (uint8_t *)cts->cb.mcode + CALLBACK_SLOT2OFS(slot); +} + +/* Convert callback function pointer to slot number. */ +MSize lj_ccallback_ptr2slot(CTState *cts, void *p) +{ + uintptr_t ofs = (uintptr_t)((uint8_t *)p -(uint8_t *)cts->cb.mcode); + if (ofs < CALLBACK_MCODE_SIZE) { + MSize slot = CALLBACK_OFS2SLOT((MSize)ofs); + if (CALLBACK_SLOT2OFS(slot) == (MSize)ofs) + return slot; + } + return ~0u; /* Not a known callback function pointer. */ +} + +/* Initialize machine code for callback function pointers. */ +#if LJ_OS_NOJIT +/* Disabled callback support. */ +#define callback_mcode_init(g, p) UNUSED(p) +#elif LJ_TARGET_X86ORX64 +static void callback_mcode_init(global_State *g, uint8_t *page) +{ + uint8_t *p = page; + uint8_t *target = (uint8_t *)(void *)lj_vm_ffi_callback; + MSize slot; +#if LJ_64 + *(void **)p = target; p += 8; +#endif + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + /* mov al, slot; jmp group */ + *p++ = XI_MOVrib | RID_EAX; *p++ = (uint8_t)slot; + if ((slot & 31) == 31 || slot == CALLBACK_MAX_SLOT-1) { + /* push ebp/rbp; mov ah, slot>>8; mov ebp, &g. */ + *p++ = XI_PUSH + RID_EBP; + *p++ = XI_MOVrib | (RID_EAX+4); *p++ = (uint8_t)(slot >> 8); + *p++ = XI_MOVri | RID_EBP; + *(int32_t *)p = i32ptr(g); p += 4; +#if LJ_64 + /* jmp [rip-pageofs] where lj_vm_ffi_callback is stored. */ + *p++ = XI_GROUP5; *p++ = XM_OFS0 + (XOg_JMP<<3) + RID_EBP; + *(int32_t *)p = (int32_t)(page-(p+4)); p += 4; +#else + /* jmp lj_vm_ffi_callback. */ + *p++ = XI_JMP; *(int32_t *)p = target-(p+4); p += 4; +#endif + } else { + *p++ = XI_JMPs; *p++ = (uint8_t)((2+2)*(31-(slot&31)) - 2); + } + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_ARM +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + /* This must match with the saveregs macro in buildvm_arm.dasc. */ + *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC); + *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR); + *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD; + *p++ = ARMI_STR|ARMI_LS_P|ARMI_LS_W|ARMF_D(RID_R12)|ARMF_N(RID_SP)|(CFRAME_SIZE-4*9); + *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_R12)|ARMF_N(RID_PC); + *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_PC)|ARMF_N(RID_PC); + *p++ = u32ptr(g); + *p++ = u32ptr(target); + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p++ = ARMI_MOV|ARMF_D(RID_R12)|ARMF_M(RID_PC); + *p = ARMI_B | ((page-p-2) & 0x00ffffffu); + p++; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_PPC +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + *p++ = PPCI_LIS | PPCF_T(RID_TMP) | (u32ptr(target) >> 16); + *p++ = PPCI_LIS | PPCF_T(RID_R12) | (u32ptr(g) >> 16); + *p++ = PPCI_ORI | PPCF_A(RID_TMP)|PPCF_T(RID_TMP) | (u32ptr(target) & 0xffff); + *p++ = PPCI_ORI | PPCF_A(RID_R12)|PPCF_T(RID_R12) | (u32ptr(g) & 0xffff); + *p++ = PPCI_MTCTR | PPCF_T(RID_TMP); + *p++ = PPCI_BCTR; + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p++ = PPCI_LI | PPCF_T(RID_R11) | slot; + *p = PPCI_B | (((page-p) & 0x00ffffffu) << 2); + p++; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#elif LJ_TARGET_MIPS +static void callback_mcode_init(global_State *g, uint32_t *page) +{ + uint32_t *p = page; + void *target = (void *)lj_vm_ffi_callback; + MSize slot; + *p++ = MIPSI_SW | MIPSF_T(RID_R1)|MIPSF_S(RID_SP) | 0; + *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (u32ptr(target) >> 16); + *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (u32ptr(g) >> 16); + *p++ = MIPSI_ORI | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) |(u32ptr(target)&0xffff); + *p++ = MIPSI_JR | MIPSF_S(RID_R3); + *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (u32ptr(g)&0xffff); + for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { + *p = MIPSI_B | ((page-p-1) & 0x0000ffffu); + p++; + *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot; + } + lua_assert(p - page <= CALLBACK_MCODE_SIZE); +} +#else +/* Missing support for this architecture. */ +#define callback_mcode_init(g, p) UNUSED(p) +#endif + +/* -- Machine code management --------------------------------------------- */ + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#elif LJ_TARGET_POSIX + +#include +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +#endif + +/* Allocate and initialize area for callback function pointers. */ +static void callback_mcode_new(CTState *cts) +{ + size_t sz = (size_t)CALLBACK_MCODE_SIZE; + void *p; + if (CALLBACK_MAX_SLOT == 0) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#if LJ_TARGET_WINDOWS + p = VirtualAlloc(NULL, sz, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + if (!p) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#elif LJ_TARGET_POSIX + p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS, + -1, 0); + if (p == MAP_FAILED) + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); +#else + /* Fallback allocator. Fails if memory is not executable by default. */ + p = lj_mem_new(cts->L, sz); +#endif + cts->cb.mcode = p; + callback_mcode_init(cts->g, p); + lj_mcode_sync(p, (char *)p + sz); +#if LJ_TARGET_WINDOWS + { + DWORD oprot; + VirtualProtect(p, sz, PAGE_EXECUTE_READ, &oprot); + } +#elif LJ_TARGET_POSIX + mprotect(p, sz, (PROT_READ|PROT_EXEC)); +#endif +} + +/* Free area for callback function pointers. */ +void lj_ccallback_mcode_free(CTState *cts) +{ + size_t sz = (size_t)CALLBACK_MCODE_SIZE; + void *p = cts->cb.mcode; + if (p == NULL) return; +#if LJ_TARGET_WINDOWS + VirtualFree(p, 0, MEM_RELEASE); + UNUSED(sz); +#elif LJ_TARGET_POSIX + munmap(p, sz); +#else + lj_mem_free(cts->g, p, sz); +#endif +} + +/* -- C callback entry ---------------------------------------------------- */ + +/* Target-specific handling of register arguments. Similar to lj_ccall.c. */ +#if LJ_TARGET_X86 + +#define CALLBACK_HANDLE_REGARG \ + if (!isfp) { /* Only non-FP values may be passed in registers. */ \ + if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \ + if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \ + } else if (ngpr + 1 <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_X64 && LJ_ABI_WIN + +/* Windows/x64 argument registers are strictly positional (use ngpr). */ +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (ngpr < maxgpr) { sp = &cts->cb.fpr[ngpr++]; UNUSED(nfpr); goto done; } \ + } else { \ + if (ngpr < maxgpr) { sp = &cts->cb.gpr[ngpr++]; goto done; } \ + } + +#elif LJ_TARGET_X64 + +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (nfpr + n <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr]; \ + nfpr += n; \ + goto done; \ + } \ + } else { \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#elif LJ_TARGET_ARM + +#if LJ_ABI_SOFTFP + +#define CALLBACK_HANDLE_REGARG_FP1 UNUSED(isfp); +#define CALLBACK_HANDLE_REGARG_FP2 + +#else + +#define CALLBACK_HANDLE_REGARG_FP1 \ + if (isfp) { \ + if (n == 1) { \ + if (fprodd) { \ + sp = &cts->cb.fpr[fprodd-1]; \ + fprodd = 0; \ + goto done; \ + } else if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + fprodd = nfpr; \ + goto done; \ + } \ + } else { \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + goto done; \ + } \ + } \ + fprodd = 0; /* No reordering after the first FP value is on stack. */ \ + } else { + +#define CALLBACK_HANDLE_REGARG_FP2 } + +#endif + +#define CALLBACK_HANDLE_REGARG \ + CALLBACK_HANDLE_REGARG_FP1 \ + if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } CALLBACK_HANDLE_REGARG_FP2 + +#elif LJ_TARGET_PPC + +#define CALLBACK_HANDLE_REGARG \ + if (isfp) { \ + if (nfpr + 1 <= CCALL_NARG_FPR) { \ + sp = &cts->cb.fpr[nfpr++]; \ + cta = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \ + goto done; \ + } \ + } else { /* Try to pass argument in GPRs. */ \ + if (n > 1) { \ + lua_assert(ctype_isinteger(cta->info) && n == 2); /* int64_t. */ \ + ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \ + } \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CALLBACK_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + *(double *)dp = *(float *)dp; /* FPRs always hold doubles. */ + +#elif LJ_TARGET_MIPS + +#define CALLBACK_HANDLE_REGARG \ + if (isfp && nfpr < CCALL_NARG_FPR) { /* Try to pass argument in FPRs. */ \ + sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \ + nfpr++; ngpr += n; \ + goto done; \ + } else { /* Try to pass argument in GPRs. */ \ + nfpr = CCALL_NARG_FPR; \ + if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ + if (ngpr + n <= maxgpr) { \ + sp = &cts->cb.gpr[ngpr]; \ + ngpr += n; \ + goto done; \ + } \ + } + +#define CALLBACK_HANDLE_RET \ + if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ + ((float *)dp)[1] = *(float *)dp; + +#else +#error "Missing calling convention definitions for this architecture" +#endif + +/* Convert and push callback arguments to Lua stack. */ +static void callback_conv_args(CTState *cts, lua_State *L) +{ + TValue *o = L->top; + intptr_t *stack = cts->cb.stack; + MSize slot = cts->cb.slot; + CTypeID id = 0, rid, fid; + int gcsteps = 0; + CType *ct; + GCfunc *fn; + MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR; +#if CCALL_NARG_FPR + MSize nfpr = 0; +#if LJ_TARGET_ARM + MSize fprodd = 0; +#endif +#endif + + if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) { + ct = ctype_get(cts, id); + rid = ctype_cid(ct->info); + fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot)); + } else { /* Must set up frame first, before throwing the error. */ + ct = NULL; + rid = 0; + fn = (GCfunc *)L; + } + o->u32.lo = LJ_CONT_FFI_CALLBACK; /* Continuation returns from callback. */ + o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */ + o++; + setframe_gc(o, obj2gco(fn)); + setframe_ftsz(o, (int)((char *)(o+1) - (char *)L->base) + FRAME_CONT); + L->top = L->base = ++o; + if (!ct) + lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK); + if (isluafunc(fn)) + setcframe_pc(L->cframe, proto_bc(funcproto(fn))+1); + lj_state_checkstack(L, LUA_MINSTACK); /* May throw. */ + o = L->base; /* Might have been reallocated. */ + +#if LJ_TARGET_X86 + /* x86 has several different calling conventions. */ + switch (ctype_cconv(ct->info)) { + case CTCC_FASTCALL: maxgpr = 2; break; + case CTCC_THISCALL: maxgpr = 1; break; + default: maxgpr = 0; break; + } +#endif + + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) { + CType *cta; + void *sp; + CTSize sz; + int isfp; + MSize n; + lua_assert(ctype_isfield(ctf->info)); + cta = ctype_rawchild(cts, ctf); + isfp = ctype_isfp(cta->info); + sz = (cta->size + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1); + n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */ + + CALLBACK_HANDLE_REGARG /* Handle register arguments. */ + + /* Otherwise pass argument on stack. */ + if (CCALL_ALIGN_STACKARG && LJ_32 && sz == 8) + nsp = (nsp + 1) & ~1u; /* Align 64 bit argument on stack. */ + sp = &stack[nsp]; + nsp += n; + + done: + if (LJ_BE && cta->size < CTSIZE_PTR) + sp = (void *)((uint8_t *)sp + CTSIZE_PTR-cta->size); + gcsteps += lj_cconv_tv_ct(cts, cta, 0, o++, sp); + } + fid = ctf->sib; + } + L->top = o; +#if LJ_TARGET_X86 + /* Store stack adjustment for returns from non-cdecl callbacks. */ + if (ctype_cconv(ct->info) != CTCC_CDECL) + (L->base-2)->u32.hi |= (nsp << (16+2)); +#endif + while (gcsteps-- > 0) + lj_gc_check(L); +} + +/* Convert Lua object to callback result. */ +static void callback_conv_result(CTState *cts, lua_State *L, TValue *o) +{ + CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi); +#if LJ_TARGET_X86 + cts->cb.gpr[2] = 0; +#endif + if (!ctype_isvoid(ctr->info)) { + uint8_t *dp = (uint8_t *)&cts->cb.gpr[0]; +#if CCALL_NUM_FPR + if (ctype_isfp(ctr->info)) + dp = (uint8_t *)&cts->cb.fpr[0]; +#endif + lj_cconv_ct_tv(cts, ctr, dp, o, 0); +#ifdef CALLBACK_HANDLE_RET + CALLBACK_HANDLE_RET +#endif + /* Extend returned integers to (at least) 32 bits. */ + if (ctype_isinteger_or_bool(ctr->info) && ctr->size < 4) { + if (ctr->info & CTF_UNSIGNED) + *(uint32_t *)dp = ctr->size == 1 ? (uint32_t)*(uint8_t *)dp : + (uint32_t)*(uint16_t *)dp; + else + *(int32_t *)dp = ctr->size == 1 ? (int32_t)*(int8_t *)dp : + (int32_t)*(int16_t *)dp; + } +#if LJ_TARGET_X86 + if (ctype_isfp(ctr->info)) + cts->cb.gpr[2] = ctr->size == sizeof(float) ? 1 : 2; +#endif + } +} + +/* Enter callback. */ +lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf) +{ + lua_State *L = cts->L; + global_State *g = cts->g; + lua_assert(L != NULL); + if (gcref(g->jit_L)) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_FFI_BADCBACK)); + if (g->panic) g->panic(L); + exit(EXIT_FAILURE); + } + lj_trace_abort(g); /* Never record across callback. */ + /* Setup C frame. */ + cframe_prev(cf) = L->cframe; + setcframe_L(cf, L); + cframe_errfunc(cf) = -1; + cframe_nres(cf) = 0; + L->cframe = cf; + callback_conv_args(cts, L); + return L; /* Now call the function on this stack. */ +} + +/* Leave callback. */ +void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o) +{ + lua_State *L = cts->L; + GCfunc *fn; + TValue *obase = L->base; + L->base = L->top; /* Keep continuation frame for throwing errors. */ + if (o >= L->base) { + /* PC of RET* is lost. Point to last line for result conv. errors. */ + fn = curr_func(L); + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + setcframe_pc(L->cframe, proto_bc(pt)+pt->sizebc+1); + } + } + callback_conv_result(cts, L, o); + /* Finally drop C frame and continuation frame. */ + L->cframe = cframe_prev(L->cframe); + L->top -= 2; + L->base = obase; + cts->cb.slot = 0; /* Blacklist C function that called the callback. */ +} + +/* -- C callback management ----------------------------------------------- */ + +/* Get an unused slot in the callback slot table. */ +static MSize callback_slot_new(CTState *cts, CType *ct) +{ + CTypeID id = ctype_typeid(cts, ct); + CTypeID1 *cbid = cts->cb.cbid; + MSize top; + for (top = cts->cb.topid; top < cts->cb.sizeid; top++) + if (LJ_LIKELY(cbid[top] == 0)) + goto found; +#if CALLBACK_MAX_SLOT + if (top >= CALLBACK_MAX_SLOT) +#endif + lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); + if (!cts->cb.mcode) + callback_mcode_new(cts); + lj_mem_growvec(cts->L, cbid, cts->cb.sizeid, CALLBACK_MAX_SLOT, CTypeID1); + cts->cb.cbid = cbid; + memset(cbid+top, 0, (cts->cb.sizeid-top)*sizeof(CTypeID1)); +found: + cbid[top] = id; + cts->cb.topid = top+1; + return top; +} + +/* Check for function pointer and supported argument/result types. */ +static CType *callback_checkfunc(CTState *cts, CType *ct) +{ + int narg = 0; + if (!ctype_isptr(ct->info) || (LJ_64 && ct->size != CTSIZE_PTR)) + return NULL; + ct = ctype_rawchild(cts, ct); + if (ctype_isfunc(ct->info)) { + CType *ctr = ctype_rawchild(cts, ct); + CTypeID fid = ct->sib; + if (!(ctype_isvoid(ctr->info) || ctype_isenum(ctr->info) || + ctype_isptr(ctr->info) || (ctype_isnum(ctr->info) && ctr->size <= 8))) + return NULL; + if ((ct->info & CTF_VARARG)) + return NULL; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) { + CType *cta; + lua_assert(ctype_isfield(ctf->info)); + cta = ctype_rawchild(cts, ctf); + if (!(ctype_isenum(cta->info) || ctype_isptr(cta->info) || + (ctype_isnum(cta->info) && cta->size <= 8)) || + ++narg >= LUA_MINSTACK-3) + return NULL; + } + fid = ctf->sib; + } + return ct; + } + return NULL; +} + +/* Create a new callback and return the callback function pointer. */ +void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn) +{ + ct = callback_checkfunc(cts, ct); + if (ct) { + MSize slot = callback_slot_new(cts, ct); + GCtab *t = cts->miscmap; + setfuncV(cts->L, lj_tab_setint(cts->L, t, (int32_t)slot), fn); + lj_gc_anybarriert(cts->L, t); + return callback_slot2ptr(cts, slot); + } + return NULL; /* Bad conversion. */ +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.h new file mode 100644 index 0000000..45b5ff0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ccallback.h @@ -0,0 +1,25 @@ +/* +** FFI C callback handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCALLBACK_H +#define _LJ_CCALLBACK_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Really belongs to lj_vm.h. */ +LJ_ASMF void lj_vm_ffi_callback(void); + +LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p); +LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf); +LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o); +LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn); +LJ_FUNC void lj_ccallback_mcode_free(CTState *cts); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.c new file mode 100644 index 0000000..de4938e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.c @@ -0,0 +1,751 @@ +/* +** C type conversions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_cconv.h" +#include "lj_ccallback.h" + +/* -- Conversion errors --------------------------------------------------- */ + +/* Bad conversion. */ +LJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s, + CTInfo flags) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + const char *src; + if ((flags & CCF_FROMTV)) + src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER : + ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)]; + else + src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL)); + if (CCF_GETARG(flags)) + lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst); + else + lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst); +} + +/* Bad conversion from TValue. */ +LJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o, + CTInfo flags) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + const char *src = lj_typename(o); + if (CCF_GETARG(flags)) + lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst); + else + lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst); +} + +/* Initializer overflow. */ +LJ_NORET static void cconv_err_initov(CTState *cts, CType *d) +{ + const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL)); + lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst); +} + +/* -- C type compatibility checks ----------------------------------------- */ + +/* Get raw type and qualifiers for a child type. Resolves enums, too. */ +static CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual) +{ + ct = ctype_child(cts, ct); + for (;;) { + if (ctype_isattrib(ct->info)) { + if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; + } else if (!ctype_isenum(ct->info)) { + break; + } + ct = ctype_child(cts, ct); + } + *qual |= (ct->info & CTF_QUAL); + return ct; +} + +/* Check for compatible types when converting to a pointer. +** Note: these checks are more relaxed than what C99 mandates. +*/ +int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags) +{ + if (!((flags & CCF_CAST) || d == s)) { + CTInfo dqual = 0, squal = 0; + d = cconv_childqual(cts, d, &dqual); + if (!ctype_isstruct(s->info)) + s = cconv_childqual(cts, s, &squal); + if ((flags & CCF_SAME)) { + if (dqual != squal) + return 0; /* Different qualifiers. */ + } else if (!(flags & CCF_IGNQUAL)) { + if ((dqual & squal) != squal) + return 0; /* Discarded qualifiers. */ + if (ctype_isvoid(d->info) || ctype_isvoid(s->info)) + return 1; /* Converting to/from void * is always ok. */ + } + if (ctype_type(d->info) != ctype_type(s->info) || + d->size != s->size) + return 0; /* Different type or different size. */ + if (ctype_isnum(d->info)) { + if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP))) + return 0; /* Different numeric types. */ + } else if (ctype_ispointer(d->info)) { + /* Check child types for compatibility. */ + return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME); + } else if (ctype_isstruct(d->info)) { + if (d != s) + return 0; /* Must be exact same type for struct/union. */ + } else if (ctype_isfunc(d->info)) { + /* NYI: structural equality of functions. */ + } + } + return 1; /* Types are compatible. */ +} + +/* -- C type to C type conversion ----------------------------------------- */ + +/* Convert C type to C type. Caveat: expects to get the raw CType! +** +** Note: This is only used by the interpreter and not optimized at all. +** The JIT compiler will do a much better job specializing for each case. +*/ +void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, + uint8_t *dp, uint8_t *sp, CTInfo flags) +{ + CTSize dsize = d->size, ssize = s->size; + CTInfo dinfo = d->info, sinfo = s->info; + void *tmpptr; + + lua_assert(!ctype_isenum(dinfo) && !ctype_isenum(sinfo)); + lua_assert(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo)); + + if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT) + goto err_conv; + + /* Some basic sanity checks. */ + lua_assert(!ctype_isnum(dinfo) || dsize > 0); + lua_assert(!ctype_isnum(sinfo) || ssize > 0); + lua_assert(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4); + lua_assert(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4); + lua_assert(!ctype_isinteger(dinfo) || (1u< ssize) { /* Zero-extend or sign-extend LSB. */ +#if LJ_LE + uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0; + memcpy(dp, sp, ssize); + memset(dp + ssize, fill, dsize-ssize); +#else + uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0; + memset(dp, fill, dsize-ssize); + memcpy(dp + (dsize-ssize), sp, ssize); +#endif + } else { /* Copy LSB. */ +#if LJ_LE + memcpy(dp, sp, dsize); +#else + memcpy(dp, sp + (ssize-dsize), dsize); +#endif + } + break; + case CCX(I, F): { + double n; /* Always convert via double. */ + conv_I_F: + /* Convert source to double. */ + if (ssize == sizeof(double)) n = *(double *)sp; + else if (ssize == sizeof(float)) n = (double)*(float *)sp; + else goto err_conv; /* NYI: long double. */ + /* Then convert double to integer. */ + /* The conversion must exactly match the semantics of JIT-compiled code! */ + if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) { + int32_t i = (int32_t)n; + if (dsize == 4) *(int32_t *)dp = i; + else if (dsize == 2) *(int16_t *)dp = (int16_t)i; + else *(int8_t *)dp = (int8_t)i; + } else if (dsize == 4) { + *(uint32_t *)dp = (uint32_t)n; + } else if (dsize == 8) { + if (!(dinfo & CTF_UNSIGNED)) + *(int64_t *)dp = (int64_t)n; + else + *(uint64_t *)dp = lj_num2u64(n); + } else { + goto err_conv; /* NYI: conversion to >64 bit integers. */ + } + break; + } + case CCX(I, C): + s = ctype_child(cts, s); + sinfo = s->info; + ssize = s->size; + goto conv_I_F; /* Just convert re. */ + case CCX(I, P): + if (!(flags & CCF_CAST)) goto err_conv; + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + goto conv_I_I; + case CCX(I, A): + if (!(flags & CCF_CAST)) goto err_conv; + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + ssize = CTSIZE_PTR; + tmpptr = sp; + sp = (uint8_t *)&tmpptr; + goto conv_I_I; + + /* Destination is a floating-point number. */ + case CCX(F, B): + case CCX(F, I): { + double n; /* Always convert via double. */ + conv_F_I: + /* First convert source to double. */ + /* The conversion must exactly match the semantics of JIT-compiled code! */ + if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) { + int32_t i; + if (ssize == 4) { + i = *(int32_t *)sp; + } else if (!(sinfo & CTF_UNSIGNED)) { + if (ssize == 2) i = *(int16_t *)sp; + else i = *(int8_t *)sp; + } else { + if (ssize == 2) i = *(uint16_t *)sp; + else i = *(uint8_t *)sp; + } + n = (double)i; + } else if (ssize == 4) { + n = (double)*(uint32_t *)sp; + } else if (ssize == 8) { + if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp; + else n = (double)*(uint64_t *)sp; + } else { + goto err_conv; /* NYI: conversion from >64 bit integers. */ + } + /* Convert double to destination. */ + if (dsize == sizeof(double)) *(double *)dp = n; + else if (dsize == sizeof(float)) *(float *)dp = (float)n; + else goto err_conv; /* NYI: long double. */ + break; + } + case CCX(F, F): { + double n; /* Always convert via double. */ + conv_F_F: + if (ssize == dsize) goto copyval; + /* Convert source to double. */ + if (ssize == sizeof(double)) n = *(double *)sp; + else if (ssize == sizeof(float)) n = (double)*(float *)sp; + else goto err_conv; /* NYI: long double. */ + /* Convert double to destination. */ + if (dsize == sizeof(double)) *(double *)dp = n; + else if (dsize == sizeof(float)) *(float *)dp = (float)n; + else goto err_conv; /* NYI: long double. */ + break; + } + case CCX(F, C): + s = ctype_child(cts, s); + sinfo = s->info; + ssize = s->size; + goto conv_F_F; /* Ignore im, and convert from re. */ + + /* Destination is a complex number. */ + case CCX(C, I): + d = ctype_child(cts, d); + dinfo = d->info; + dsize = d->size; + memset(dp + dsize, 0, dsize); /* Clear im. */ + goto conv_F_I; /* Convert to re. */ + case CCX(C, F): + d = ctype_child(cts, d); + dinfo = d->info; + dsize = d->size; + memset(dp + dsize, 0, dsize); /* Clear im. */ + goto conv_F_F; /* Convert to re. */ + + case CCX(C, C): + if (dsize != ssize) { /* Different types: convert re/im separately. */ + CType *dc = ctype_child(cts, d); + CType *sc = ctype_child(cts, s); + lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags); + lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags); + return; + } + goto copyval; /* Otherwise this is easy. */ + + /* Destination is a vector. */ + case CCX(V, I): + case CCX(V, F): + case CCX(V, C): { + CType *dc = ctype_child(cts, d); + CTSize esize; + /* First convert the scalar to the first element. */ + lj_cconv_ct_ct(cts, dc, s, dp, sp, flags); + /* Then replicate it to the other elements (splat). */ + for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) { + dp += esize; + memcpy(dp, sp, esize); + } + break; + } + + case CCX(V, V): + /* Copy same-sized vectors, even for different lengths/element-types. */ + if (dsize != ssize) goto err_conv; + goto copyval; + + /* Destination is a pointer. */ + case CCX(P, I): + if (!(flags & CCF_CAST)) goto err_conv; + dinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + goto conv_I_I; + + case CCX(P, F): + if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv; + /* The signed conversion is cheaper. x64 really has 47 bit pointers. */ + dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED); + goto conv_I_F; + + case CCX(P, P): + if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv; + cdata_setptr(dp, dsize, cdata_getptr(sp, ssize)); + break; + + case CCX(P, A): + case CCX(P, S): + if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv; + cdata_setptr(dp, dsize, sp); + break; + + /* Destination is an array. */ + case CCX(A, A): + if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize || + d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags)) + goto err_conv; + goto copyval; + + /* Destination is a struct/union. */ + case CCX(S, S): + if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s) + goto err_conv; /* Must be exact same type. */ +copyval: /* Copy value. */ + lua_assert(dsize == ssize); + memcpy(dp, sp, dsize); + break; + + default: + err_conv: + cconv_err_conv(cts, d, s, flags); + } +} + +/* -- C type to TValue conversion ----------------------------------------- */ + +/* Convert C type to TValue. Caveat: expects to get the raw CType! */ +int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, + TValue *o, uint8_t *sp) +{ + CTInfo sinfo = s->info; + if (ctype_isnum(sinfo)) { + if (!ctype_isbool(sinfo)) { + if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; + if (LJ_DUALNUM && ctype_isinteger(sinfo)) { + int32_t i; + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s, + (uint8_t *)&i, sp, 0); + if ((sinfo & CTF_UNSIGNED) && i < 0) + setnumV(o, (lua_Number)(uint32_t)i); + else + setintV(o, i); + } else { + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s, + (uint8_t *)&o->n, sp, 0); + /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ + lua_assert(tvisnum(o)); + } + } else { + uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0); + setboolV(o, b); + setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */ + } + return 0; + } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { + /* Create reference. */ + setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid)); + return 1; /* Need GC step. */ + } else { + GCcdata *cd; + CTSize sz; + copyval: /* Copy value. */ + sz = s->size; + lua_assert(sz != CTSIZE_INVALID); + /* Attributes are stripped, qualifiers are kept (but mostly ignored). */ + cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz); + setcdataV(cts->L, o, cd); + memcpy(cdataptr(cd), sp, sz); + return 1; /* Need GC step. */ + } +} + +/* Convert bitfield to TValue. */ +int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp) +{ + CTInfo info = s->info; + CTSize pos, bsz; + uint32_t val; + lua_assert(ctype_isbitfield(info)); + /* NYI: packed bitfields may cause misaligned reads. */ + switch (ctype_bitcsz(info)) { + case 4: val = *(uint32_t *)sp; break; + case 2: val = *(uint16_t *)sp; break; + case 1: val = *(uint8_t *)sp; break; + default: lua_assert(0); val = 0; break; + } + /* Check if a packed bitfield crosses a container boundary. */ + pos = ctype_bitpos(info); + bsz = ctype_bitbsz(info); + lua_assert(pos < 8*ctype_bitcsz(info)); + lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info)); + if (pos + bsz > 8*ctype_bitcsz(info)) + lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); + if (!(info & CTF_BOOL)) { + CTSize shift = 32 - bsz; + if (!(info & CTF_UNSIGNED)) { + setintV(o, (int32_t)(val << (shift-pos)) >> shift); + } else { + val = (val << (shift-pos)) >> shift; + if (!LJ_DUALNUM || (int32_t)val < 0) + setnumV(o, (lua_Number)(uint32_t)val); + else + setintV(o, (int32_t)val); + } + } else { + lua_assert(bsz == 1); + setboolV(o, (val >> pos) & 1); + } + return 0; /* No GC step needed. */ +} + +/* -- TValue to C type conversion ----------------------------------------- */ + +/* Convert table to array. */ +static void cconv_array_tab(CTState *cts, CType *d, + uint8_t *dp, GCtab *t, CTInfo flags) +{ + int32_t i; + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize size = d->size, esize = dc->size, ofs = 0; + for (i = 0; ; i++) { + TValue *tv = (TValue *)lj_tab_getint(t, i); + if (!tv || tvisnil(tv)) { + if (i == 0) continue; /* Try again for 1-based tables. */ + break; /* Stop at first nil. */ + } + if (ofs >= size) + cconv_err_initov(cts, d); + lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags); + ofs += esize; + } + if (size != CTSIZE_INVALID) { /* Only fill up arrays with known size. */ + if (ofs == esize) { /* Replicate a single element. */ + for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize); + } else { /* Otherwise fill the remainder with zero. */ + memset(dp + ofs, 0, size - ofs); + } + } +} + +/* Convert table to sub-struct/union. */ +static void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp, + GCtab *t, int32_t *ip, CTInfo flags) +{ + CTypeID id = d->sib; + while (id) { + CType *df = ctype_get(cts, id); + id = df->sib; + if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) { + TValue *tv; + int32_t i = *ip, iz = i; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + if (i >= 0) { + retry: + tv = (TValue *)lj_tab_getint(t, i); + if (!tv || tvisnil(tv)) { + if (i == 0) { i = 1; goto retry; } /* 1-based tables. */ + if (iz == 0) { *ip = i = -1; goto tryname; } /* Init named fields. */ + break; /* Stop at first nil. */ + } + *ip = i + 1; + } else { + tryname: + tv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name))); + if (!tv || tvisnil(tv)) continue; + } + if (ctype_isfield(df->info)) + lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags); + else + lj_cconv_bf_tv(cts, df, dp+df->size, tv); + if ((d->info & CTF_UNION)) break; + } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) { + cconv_substruct_tab(cts, ctype_rawchild(cts, df), + dp+df->size, t, ip, flags); + } /* Ignore all other entries in the chain. */ + } +} + +/* Convert table to struct/union. */ +static void cconv_struct_tab(CTState *cts, CType *d, + uint8_t *dp, GCtab *t, CTInfo flags) +{ + int32_t i = 0; + memset(dp, 0, d->size); /* Much simpler to clear the struct first. */ + cconv_substruct_tab(cts, d, dp, t, &i, flags); +} + +/* Convert TValue to C type. Caveat: expects to get the raw CType! */ +void lj_cconv_ct_tv(CTState *cts, CType *d, + uint8_t *dp, TValue *o, CTInfo flags) +{ + CTypeID sid = CTID_P_VOID; + CType *s; + void *tmpptr; + uint8_t tmpbool, *sp = (uint8_t *)&tmpptr; + if (LJ_LIKELY(tvisint(o))) { + sp = (uint8_t *)&o->i; + sid = CTID_INT32; + flags |= CCF_FROMTV; + } else if (LJ_LIKELY(tvisnum(o))) { + sp = (uint8_t *)&o->n; + sid = CTID_DOUBLE; + flags |= CCF_FROMTV; + } else if (tviscdata(o)) { + sp = cdataptr(cdataV(o)); + sid = cdataV(o)->ctypeid; + s = ctype_get(cts, sid); + if (ctype_isref(s->info)) { /* Resolve reference for value. */ + lua_assert(s->size == CTSIZE_PTR); + sp = *(void **)sp; + sid = ctype_cid(s->info); + } + s = ctype_raw(cts, sid); + if (ctype_isfunc(s->info)) { + sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR); + } else { + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + goto doconv; + } + } else if (tvisstr(o)) { + GCstr *str = strV(o); + if (ctype_isenum(d->info)) { /* Match string against enum constant. */ + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, d, str, &ofs); + if (!cct || !ctype_isconstval(cct->info)) + goto err_conv; + lua_assert(d->size == 4); + sp = (uint8_t *)&cct->size; + sid = ctype_cid(cct->info); + } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */ + CType *dc = ctype_rawchild(cts, d); + CTSize sz = str->len+1; + if (!ctype_isinteger(dc->info) || dc->size != 1) + goto err_conv; + if (d->size != 0 && d->size < sz) + sz = d->size; + memcpy(dp, strdata(str), sz); + return; + } else { /* Otherwise pass it as a const char[]. */ + sp = (uint8_t *)strdata(str); + sid = CTID_A_CCHAR; + flags |= CCF_FROMTV; + } + } else if (tvistab(o)) { + if (ctype_isarray(d->info)) { + cconv_array_tab(cts, d, dp, tabV(o), flags); + return; + } else if (ctype_isstruct(d->info)) { + cconv_struct_tab(cts, d, dp, tabV(o), flags); + return; + } else { + goto err_conv; + } + } else if (tvisbool(o)) { + tmpbool = boolV(o); + sp = &tmpbool; + sid = CTID_BOOL; + } else if (tvisnil(o)) { + tmpptr = (void *)0; + flags |= CCF_FROMTV; + } else if (tvisudata(o)) { + GCudata *ud = udataV(o); + tmpptr = uddata(ud); + if (ud->udtype == UDTYPE_IO_FILE) + tmpptr = *(void **)tmpptr; + } else if (tvislightud(o)) { + tmpptr = lightudV(o); + } else if (tvisfunc(o)) { + void *p = lj_ccallback_new(cts, d, funcV(o)); + if (p) { + *(void **)dp = p; + return; + } + goto err_conv; + } else { + err_conv: + cconv_err_convtv(cts, d, o, flags); + } + s = ctype_get(cts, sid); +doconv: + if (ctype_isenum(d->info)) d = ctype_child(cts, d); + lj_cconv_ct_ct(cts, d, s, dp, sp, flags); +} + +/* Convert TValue to bitfield. */ +void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o) +{ + CTInfo info = d->info; + CTSize pos, bsz; + uint32_t val, mask; + lua_assert(ctype_isbitfield(info)); + if ((info & CTF_BOOL)) { + uint8_t tmpbool; + lua_assert(ctype_bitbsz(info) == 1); + lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0); + val = tmpbool; + } else { + CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32; + lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0); + } + pos = ctype_bitpos(info); + bsz = ctype_bitbsz(info); + lua_assert(pos < 8*ctype_bitcsz(info)); + lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info)); + /* Check if a packed bitfield crosses a container boundary. */ + if (pos + bsz > 8*ctype_bitcsz(info)) + lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); + mask = ((1u << bsz) - 1u) << pos; + val = (val << pos) & mask; + /* NYI: packed bitfields may cause misaligned reads/writes. */ + switch (ctype_bitcsz(info)) { + case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break; + case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break; + case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break; + default: lua_assert(0); break; + } +} + +/* -- Initialize C type with TValues -------------------------------------- */ + +/* Initialize an array with TValues. */ +static void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp, + TValue *o, MSize len) +{ + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize ofs, esize = dc->size; + MSize i; + if (len*esize > sz) + cconv_err_initov(cts, d); + for (i = 0, ofs = 0; i < len; i++, ofs += esize) + lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0); + if (ofs == esize) { /* Replicate a single element. */ + for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize); + } else { /* Otherwise fill the remainder with zero. */ + memset(dp + ofs, 0, sz - ofs); + } +} + +/* Initialize a sub-struct/union with TValues. */ +static void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp, + TValue *o, MSize len, MSize *ip) +{ + CTypeID id = d->sib; + while (id) { + CType *df = ctype_get(cts, id); + id = df->sib; + if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) { + MSize i = *ip; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + if (i >= len) break; + *ip = i + 1; + if (ctype_isfield(df->info)) + lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0); + else + lj_cconv_bf_tv(cts, df, dp+df->size, o + i); + if ((d->info & CTF_UNION)) break; + } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) { + cconv_substruct_init(cts, ctype_rawchild(cts, df), + dp+df->size, o, len, ip); + } /* Ignore all other entries in the chain. */ + } +} + +/* Initialize a struct/union with TValues. */ +static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp, + TValue *o, MSize len) +{ + MSize i = 0; + memset(dp, 0, sz); /* Much simpler to clear the struct first. */ + cconv_substruct_init(cts, d, dp, o, len, &i); + if (i < len) + cconv_err_initov(cts, d); +} + +/* Check whether to use a multi-value initializer. +** This is true if an aggregate is to be initialized with a value. +** Valarrays are treated as values here so ct_tv handles (V|C, I|F). +*/ +int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o) +{ + if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info))) + return 0; /* Destination is not an aggregate. */ + if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info))) + return 0; /* Initializer is not a value. */ + if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d) + return 0; /* Source and destination are identical aggregates. */ + return 1; /* Otherwise the initializer is a value. */ +} + +/* Initialize C type with TValues. Caveat: expects to get the raw CType! */ +void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, + uint8_t *dp, TValue *o, MSize len) +{ + if (len == 0) + memset(dp, 0, sz); + else if (len == 1 && !lj_cconv_multi_init(cts, d, o)) + lj_cconv_ct_tv(cts, d, dp, o, 0); + else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */ + cconv_array_init(cts, d, sz, dp, o, len); + else if (ctype_isstruct(d->info)) + cconv_struct_init(cts, d, sz, dp, o, len); + else + cconv_err_initov(cts, d); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.h new file mode 100644 index 0000000..17e0f05 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cconv.h @@ -0,0 +1,70 @@ +/* +** C type conversions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CCONV_H +#define _LJ_CCONV_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Compressed C type index. ORDER CCX. */ +enum { + CCX_B, /* Bool. */ + CCX_I, /* Integer. */ + CCX_F, /* Floating-point number. */ + CCX_C, /* Complex. */ + CCX_V, /* Vector. */ + CCX_P, /* Pointer. */ + CCX_A, /* Refarray. */ + CCX_S /* Struct/union. */ +}; + +/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */ +static LJ_AINLINE uint32_t cconv_idx(CTInfo info) +{ + uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */ + lua_assert(ctype_type(info) <= CT_MAYCONVERT); +#if LJ_64 + idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u); +#else + idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u); +#endif + lua_assert(idx < 8); + return idx; +} + +#define cconv_idx2(dinfo, sinfo) \ + ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo))) + +#define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src) + +/* Conversion flags. */ +#define CCF_CAST 0x00000001u +#define CCF_FROMTV 0x00000002u +#define CCF_SAME 0x00000004u +#define CCF_IGNQUAL 0x00000008u + +#define CCF_ARG_SHIFT 8 +#define CCF_ARG(n) ((n) << CCF_ARG_SHIFT) +#define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT) + +LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags); +LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, + uint8_t *dp, uint8_t *sp, CTInfo flags); +LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, + TValue *o, uint8_t *sp); +LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp); +LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, + uint8_t *dp, TValue *o, CTInfo flags); +LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); +LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o); +LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, + uint8_t *dp, TValue *o, MSize len); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.c new file mode 100644 index 0000000..590ddf1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.c @@ -0,0 +1,285 @@ +/* +** C data management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" + +/* -- C data allocation --------------------------------------------------- */ + +/* Allocate a new C data object holding a reference to another object. */ +GCcdata *lj_cdata_newref(CTState *cts, const void *p, CTypeID id) +{ + CTypeID refid = lj_ctype_intern(cts, CTINFO_REF(id), CTSIZE_PTR); + GCcdata *cd = lj_cdata_new(cts, refid, CTSIZE_PTR); + *(const void **)cdataptr(cd) = p; + return cd; +} + +/* Allocate variable-sized or specially aligned C data object. */ +GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, CTSize align) +{ + global_State *g; + MSize extra = sizeof(GCcdataVar) + sizeof(GCcdata) + + (align > CT_MEMALIGN ? (1u<L, extra + sz, char); + uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata); + uintptr_t almask = (1u << align) - 1u; + GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata)); + lua_assert((char *)cd - p < 65536); + cdatav(cd)->offset = (uint16_t)((char *)cd - p); + cdatav(cd)->extra = extra; + cdatav(cd)->len = sz; + g = cts->g; + setgcrefr(cd->nextgc, g->gc.root); + setgcref(g->gc.root, obj2gco(cd)); + newwhite(g, obj2gco(cd)); + cd->marked |= 0x80; + cd->gct = ~LJ_TCDATA; + cd->ctypeid = id; + return cd; +} + +/* Free a C data object. */ +void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd) +{ + if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) { + GCobj *root; + makewhite(g, obj2gco(cd)); + markfinalized(obj2gco(cd)); + if ((root = gcref(g->gc.mmudata)) != NULL) { + setgcrefr(cd->nextgc, root->gch.nextgc); + setgcref(root->gch.nextgc, obj2gco(cd)); + setgcref(g->gc.mmudata, obj2gco(cd)); + } else { + setgcref(cd->nextgc, obj2gco(cd)); + setgcref(g->gc.mmudata, obj2gco(cd)); + } + } else if (LJ_LIKELY(!cdataisv(cd))) { + CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid); + CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR; + lua_assert(ctype_hassize(ct->info) || ctype_isfunc(ct->info) || + ctype_isextern(ct->info)); + lj_mem_free(g, cd, sizeof(GCcdata) + sz); + } else { + lj_mem_free(g, memcdatav(cd), sizecdatav(cd)); + } +} + +TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd) +{ + global_State *g = G(L); + GCtab *t = ctype_ctsG(g)->finalizer; + if (gcref(t->metatable)) { + /* Add cdata to finalizer table, if still enabled. */ + TValue *tv, tmp; + setcdataV(L, &tmp, cd); + lj_gc_anybarriert(L, t); + tv = lj_tab_set(L, t, &tmp); + cd->marked |= LJ_GC_CDATA_FIN; + return tv; + } else { + /* Otherwise return dummy TValue. */ + return &g->tmptv; + } +} + +/* -- C data indexing ----------------------------------------------------- */ + +/* Index C data by a TValue. Return CType and pointer. */ +CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp, + CTInfo *qual) +{ + uint8_t *p = (uint8_t *)cdataptr(cd); + CType *ct = ctype_get(cts, cd->ctypeid); + ptrdiff_t idx; + + /* Resolve reference for cdata object. */ + if (ctype_isref(ct->info)) { + lua_assert(ct->size == CTSIZE_PTR); + p = *(uint8_t **)p; + ct = ctype_child(cts, ct); + } + +collect_attrib: + /* Skip attributes and collect qualifiers. */ + while (ctype_isattrib(ct->info)) { + if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; + ct = ctype_child(cts, ct); + } + lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ + + if (tvisint(key)) { + idx = (ptrdiff_t)intV(key); + goto integer_key; + } else if (tvisnum(key)) { /* Numeric key. */ + idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); + integer_key: + if (ctype_ispointer(ct->info)) { + CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */ + if (sz != CTSIZE_INVALID) { + if (ctype_isptr(ct->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) { + if ((ct->info & CTF_COMPLEX)) idx &= 1; + *qual |= CTF_CONST; /* Valarray elements are constant. */ + } + *pp = p + idx*(int32_t)sz; + return ct; + } + } + } else if (tviscdata(key)) { /* Integer cdata key. */ + GCcdata *cdk = cdataV(key); + CType *ctk = ctype_raw(cts, cdk->ctypeid); + if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk); + if (ctype_isinteger(ctk->info)) { + lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk, + (uint8_t *)&idx, cdataptr(cdk), 0); + goto integer_key; + } + } else if (tvisstr(key)) { /* String key. */ + GCstr *name = strV(key); + if (ctype_isstruct(ct->info)) { + CTSize ofs; + CType *fct = lj_ctype_getfieldq(cts, ct, name, &ofs, qual); + if (fct) { + *pp = p + ofs; + return fct; + } + } else if (ctype_iscomplex(ct->info)) { + if (name->len == 2) { + *qual |= CTF_CONST; /* Complex fields are constant. */ + if (strdata(name)[0] == 'r' && strdata(name)[1] == 'e') { + *pp = p; + return ct; + } else if (strdata(name)[0] == 'i' && strdata(name)[1] == 'm') { + *pp = p + (ct->size >> 1); + return ct; + } + } + } else if (cd->ctypeid == CTID_CTYPEID) { + /* Allow indexing a (pointer to) struct constructor to get constants. */ + CType *sct = ctype_raw(cts, *(CTypeID *)p); + if (ctype_isptr(sct->info)) + sct = ctype_rawchild(cts, sct); + if (ctype_isstruct(sct->info)) { + CTSize ofs; + CType *fct = lj_ctype_getfield(cts, sct, name, &ofs); + if (fct && ctype_isconstval(fct->info)) + return fct; + } + ct = sct; /* Allow resolving metamethods for constructors, too. */ + } + } + if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ + if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) { + p = (uint8_t *)cdata_getptr(p, ct->size); + ct = ctype_child(cts, ct); + goto collect_attrib; + } + } + *qual |= 1; /* Lookup failed. */ + return ct; /* But return the resolved raw type. */ +} + +/* -- C data getters ------------------------------------------------------ */ + +/* Get constant value and convert to TValue. */ +static void cdata_getconst(CTState *cts, TValue *o, CType *ct) +{ + CType *ctt = ctype_child(cts, ct); + lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); + /* Constants are already zero-extended/sign-extended to 32 bits. */ + if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) + setnumV(o, (lua_Number)(uint32_t)ct->size); + else + setintV(o, (int32_t)ct->size); +} + +/* Get C data value and convert to TValue. */ +int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp) +{ + CTypeID sid; + + if (ctype_isconstval(s->info)) { + cdata_getconst(cts, o, s); + return 0; /* No GC step needed. */ + } else if (ctype_isbitfield(s->info)) { + return lj_cconv_tv_bf(cts, s, o, sp); + } + + /* Get child type of pointer/array/field. */ + lua_assert(ctype_ispointer(s->info) || ctype_isfield(s->info)); + sid = ctype_cid(s->info); + s = ctype_get(cts, sid); + + /* Resolve reference for field. */ + if (ctype_isref(s->info)) { + lua_assert(s->size == CTSIZE_PTR); + sp = *(uint8_t **)sp; + sid = ctype_cid(s->info); + s = ctype_get(cts, sid); + } + + /* Skip attributes. */ + while (ctype_isattrib(s->info)) + s = ctype_child(cts, s); + + return lj_cconv_tv_ct(cts, s, sid, o, sp); +} + +/* -- C data setters ------------------------------------------------------ */ + +/* Convert TValue and set C data value. */ +void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual) +{ + if (ctype_isconstval(d->info)) { + goto err_const; + } else if (ctype_isbitfield(d->info)) { + if (((d->info|qual) & CTF_CONST)) goto err_const; + lj_cconv_bf_tv(cts, d, dp, o); + return; + } + + /* Get child type of pointer/array/field. */ + lua_assert(ctype_ispointer(d->info) || ctype_isfield(d->info)); + d = ctype_child(cts, d); + + /* Resolve reference for field. */ + if (ctype_isref(d->info)) { + lua_assert(d->size == CTSIZE_PTR); + dp = *(uint8_t **)dp; + d = ctype_child(cts, d); + } + + /* Skip attributes and collect qualifiers. */ + for (;;) { + if (ctype_isattrib(d->info)) { + if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size; + } else { + break; + } + d = ctype_child(cts, d); + } + + lua_assert(ctype_hassize(d->info) && !ctype_isvoid(d->info)); + + if (((d->info|qual) & CTF_CONST)) { + err_const: + lj_err_caller(cts->L, LJ_ERR_FFI_WRCONST); + } + + lj_cconv_ct_tv(cts, d, dp, o, 0); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.h new file mode 100644 index 0000000..6c8e7a1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cdata.h @@ -0,0 +1,75 @@ +/* +** C data management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CDATA_H +#define _LJ_CDATA_H + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* Get C data pointer. */ +static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz) +{ + if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ + return ((void *)(uintptr_t)*(uint32_t *)p); + } else { + lua_assert(sz == CTSIZE_PTR); + return *(void **)p; + } +} + +/* Set C data pointer. */ +static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v) +{ + if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ + *(uint32_t *)p = (uint32_t)(uintptr_t)v; + } else { + lua_assert(sz == CTSIZE_PTR); + *(void **)p = (void *)v; + } +} + +/* Allocate fixed-size C data object. */ +static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz) +{ + GCcdata *cd; +#ifdef LUA_USE_ASSERT + CType *ct = ctype_raw(cts, id); + lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz); +#endif + cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz); + cd->gct = ~LJ_TCDATA; + cd->ctypeid = ctype_check(cts, id); + return cd; +} + +/* Variant which works without a valid CTState. */ +static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz) +{ + GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz); + cd->gct = ~LJ_TCDATA; + cd->ctypeid = id; + return cd; +} + +LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id); +LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, + CTSize align); + +LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd); +LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd); + +LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, + uint8_t **pp, CTInfo *qual); +LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp); +LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, + CTInfo qual); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.c new file mode 100644 index 0000000..11f23ef --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.c @@ -0,0 +1,43 @@ +/* +** Character types. +** Donated to the public domain. +** +** This is intended to replace the problematic libc single-byte NLS functions. +** These just don't make sense anymore with UTF-8 locales becoming the norm +** on POSIX systems. It never worked too well on Windows systems since hardly +** anyone bothered to call setlocale(). +** +** This table is hardcoded for ASCII. Identifiers include the characters +** 128-255, too. This allows for the use of all non-ASCII chars as identifiers +** in the lexer. This is a broad definition, but works well in practice +** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*). +** +** If you really need proper character types for UTF-8 strings, please use +** an add-on library such as slnunicode: http://luaforge.net/projects/sln/ +*/ + +#define lj_char_c +#define LUA_CORE + +#include "lj_char.h" + +LJ_DATADEF const uint8_t lj_char_bits[257] = { + 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 152,152,152,152,152,152,152,152,152,152, 4, 4, 4, 4, 4, 4, + 4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160, + 160,160,160,160,160,160,160,160,160,160,160, 4, 4, 4, 4,132, + 4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192, + 192,192,192,192,192,192,192,192,192,192,192, 4, 4, 4, 4, 1, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, + 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128 +}; + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.h new file mode 100644 index 0000000..c3c86d3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_char.h @@ -0,0 +1,42 @@ +/* +** Character types. +** Donated to the public domain. +*/ + +#ifndef _LJ_CHAR_H +#define _LJ_CHAR_H + +#include "lj_def.h" + +#define LJ_CHAR_CNTRL 0x01 +#define LJ_CHAR_SPACE 0x02 +#define LJ_CHAR_PUNCT 0x04 +#define LJ_CHAR_DIGIT 0x08 +#define LJ_CHAR_XDIGIT 0x10 +#define LJ_CHAR_UPPER 0x20 +#define LJ_CHAR_LOWER 0x40 +#define LJ_CHAR_IDENT 0x80 +#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER) +#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT) +#define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT) + +/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */ +#define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t) +#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL) +#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE) +#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT) +#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT) +#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT) +#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER) +#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER) +#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT) +#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA) +#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM) +#define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH) + +#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1)) +#define lj_char_tolower(c) ((c) + lj_char_isupper(c)) + +LJ_DATA const uint8_t lj_char_bits[257]; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.c new file mode 100644 index 0000000..ccb99e5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.c @@ -0,0 +1,409 @@ +/* +** FFI C library loader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" +#include "lj_str.h" +#include "lj_udata.h" +#include "lj_ctype.h" +#include "lj_cconv.h" +#include "lj_cdata.h" +#include "lj_clib.h" + +/* -- OS-specific functions ----------------------------------------------- */ + +#if LJ_TARGET_DLOPEN + +#include +#include + +#if defined(RTLD_DEFAULT) +#define CLIB_DEFHANDLE RTLD_DEFAULT +#elif LJ_TARGET_OSX || LJ_TARGET_BSD +#define CLIB_DEFHANDLE ((void *)(intptr_t)-2) +#else +#define CLIB_DEFHANDLE NULL +#endif + +LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L) +{ + lj_err_callermsg(L, dlerror()); +} + +#define clib_error(L, fmt, name) clib_error_(L) + +#if defined(__CYGWIN__) +#define CLIB_SOPREFIX "cyg" +#else +#define CLIB_SOPREFIX "lib" +#endif + +#if LJ_TARGET_OSX +#define CLIB_SOEXT "%s.dylib" +#elif defined(__CYGWIN__) +#define CLIB_SOEXT "%s.dll" +#else +#define CLIB_SOEXT "%s.so" +#endif + +static const char *clib_extname(lua_State *L, const char *name) +{ + if (!strchr(name, '/') +#ifdef __CYGWIN__ + && !strchr(name, '\\') +#endif + ) { + if (!strchr(name, '.')) { + name = lj_str_pushf(L, CLIB_SOEXT, name); + L->top--; +#ifdef __CYGWIN__ + } else { + return name; +#endif + } + if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] && + name[2] == CLIB_SOPREFIX[2])) { + name = lj_str_pushf(L, CLIB_SOPREFIX "%s", name); + L->top--; + } + } + return name; +} + +/* Check for a recognized ld script line. */ +static const char *clib_check_lds(lua_State *L, const char *buf) +{ + char *p, *e; + if ((!strncmp(buf, "GROUP", 5) || !strncmp(buf, "INPUT", 5)) && + (p = strchr(buf, '('))) { + while (*++p == ' ') ; + for (e = p; *e && *e != ' ' && *e != ')'; e++) ; + return strdata(lj_str_new(L, p, e-p)); + } + return NULL; +} + +/* Quick and dirty solution to resolve shared library name from ld script. */ +static const char *clib_resolve_lds(lua_State *L, const char *name) +{ + FILE *fp = fopen(name, "r"); + const char *p = NULL; + if (fp) { + char buf[256]; + if (fgets(buf, sizeof(buf), fp)) { + if (!strncmp(buf, "/* GNU ld script", 16)) { /* ld script magic? */ + while (fgets(buf, sizeof(buf), fp)) { /* Check all lines. */ + p = clib_check_lds(L, buf); + if (p) break; + } + } else { /* Otherwise check only the first line. */ + p = clib_check_lds(L, buf); + } + } + fclose(fp); + } + return p; +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + void *h = dlopen(clib_extname(L, name), + RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL)); + if (!h) { + const char *e, *err = dlerror(); + if (*err == '/' && (e = strchr(err, ':')) && + (name = clib_resolve_lds(L, strdata(lj_str_new(L, err, e-err))))) { + h = dlopen(name, RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL)); + if (h) return h; + err = dlerror(); + } + lj_err_callermsg(L, err); + } + return h; +} + +static void clib_unloadlib(CLibrary *cl) +{ + if (cl->handle && cl->handle != CLIB_DEFHANDLE) + dlclose(cl->handle); +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + void *p = dlsym(cl->handle, name); + return p; +} + +#elif LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4 +#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2 +BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*); +#endif + +#define CLIB_DEFHANDLE ((void *)-1) + +/* Default libraries. */ +enum { + CLIB_HANDLE_EXE, + CLIB_HANDLE_DLL, + CLIB_HANDLE_CRT, + CLIB_HANDLE_KERNEL32, + CLIB_HANDLE_USER32, + CLIB_HANDLE_GDI32, + CLIB_HANDLE_MAX +}; + +static void *clib_def_handle[CLIB_HANDLE_MAX]; + +LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt, + const char *name) +{ + DWORD err = GetLastError(); + char buf[128]; + if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, err, 0, buf, sizeof(buf), NULL)) + buf[0] = '\0'; + lj_err_callermsg(L, lj_str_pushf(L, fmt, name, buf)); +} + +static int clib_needext(const char *s) +{ + while (*s) { + if (*s == '/' || *s == '\\' || *s == '.') return 0; + s++; + } + return 1; +} + +static const char *clib_extname(lua_State *L, const char *name) +{ + if (clib_needext(name)) { + name = lj_str_pushf(L, "%s.dll", name); + L->top--; + } + return name; +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + DWORD oldwerr = GetLastError(); + void *h = (void *)LoadLibraryA(clib_extname(L, name)); + if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); + SetLastError(oldwerr); + UNUSED(global); + return h; +} + +static void clib_unloadlib(CLibrary *cl) +{ + if (cl->handle == CLIB_DEFHANDLE) { + MSize i; + for (i = CLIB_HANDLE_KERNEL32; i < CLIB_HANDLE_MAX; i++) { + void *h = clib_def_handle[i]; + if (h) { + clib_def_handle[i] = NULL; + FreeLibrary((HINSTANCE)h); + } + } + } else if (cl->handle) { + FreeLibrary((HINSTANCE)cl->handle); + } +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + void *p = NULL; + if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */ + MSize i; + for (i = 0; i < CLIB_HANDLE_MAX; i++) { + HINSTANCE h = (HINSTANCE)clib_def_handle[i]; + if (!(void *)h) { /* Resolve default library handles (once). */ + switch (i) { + case CLIB_HANDLE_EXE: GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, &h); break; + case CLIB_HANDLE_DLL: + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)clib_def_handle, &h); + break; + case CLIB_HANDLE_CRT: + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (const char *)&_fmode, &h); + break; + case CLIB_HANDLE_KERNEL32: h = LoadLibraryA("kernel32.dll"); break; + case CLIB_HANDLE_USER32: h = LoadLibraryA("user32.dll"); break; + case CLIB_HANDLE_GDI32: h = LoadLibraryA("gdi32.dll"); break; + } + if (!h) continue; + clib_def_handle[i] = (void *)h; + } + p = (void *)GetProcAddress(h, name); + if (p) break; + } + } else { + p = (void *)GetProcAddress((HINSTANCE)cl->handle, name); + } + return p; +} + +#else + +#define CLIB_DEFHANDLE NULL + +LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt, + const char *name) +{ + lj_err_callermsg(L, lj_str_pushf(L, fmt, name, "no support for this OS")); +} + +static void *clib_loadlib(lua_State *L, const char *name, int global) +{ + lj_err_callermsg(L, "no support for loading dynamic libraries for this OS"); + UNUSED(name); UNUSED(global); + return NULL; +} + +static void clib_unloadlib(CLibrary *cl) +{ + UNUSED(cl); +} + +static void *clib_getsym(CLibrary *cl, const char *name) +{ + UNUSED(cl); UNUSED(name); + return NULL; +} + +#endif + +/* -- C library indexing -------------------------------------------------- */ + +#if LJ_TARGET_X86 && LJ_ABI_WIN +/* Compute argument size for fastcall/stdcall functions. */ +static CTSize clib_func_argsize(CTState *cts, CType *ct) +{ + CTSize n = 0; + while (ct->sib) { + CType *d; + ct = ctype_get(cts, ct->sib); + if (ctype_isfield(ct->info)) { + d = ctype_rawchild(cts, ct); + n += ((d->size + 3) & ~3); + } + } + return n; +} +#endif + +/* Get redirected or mangled external symbol. */ +static const char *clib_extsym(CTState *cts, CType *ct, GCstr *name) +{ + if (ct->sib) { + CType *ctf = ctype_get(cts, ct->sib); + if (ctype_isxattrib(ctf->info, CTA_REDIR)) + return strdata(gco2str(gcref(ctf->name))); + } + return strdata(name); +} + +/* Index a C library by name. */ +TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name) +{ + TValue *tv = lj_tab_setstr(L, cl->cache, name); + if (LJ_UNLIKELY(tvisnil(tv))) { + CTState *cts = ctype_cts(L); + CType *ct; + CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); + if (!id) + lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name)); + if (ctype_isconstval(ct->info)) { + CType *ctt = ctype_child(cts, ct); + lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); + if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) + setnumV(tv, (lua_Number)(uint32_t)ct->size); + else + setintV(tv, (int32_t)ct->size); + } else { + const char *sym = clib_extsym(cts, ct, name); +#if LJ_TARGET_WINDOWS + DWORD oldwerr = GetLastError(); +#endif + void *p = clib_getsym(cl, sym); + GCcdata *cd; + lua_assert(ctype_isfunc(ct->info) || ctype_isextern(ct->info)); +#if LJ_TARGET_X86 && LJ_ABI_WIN + /* Retry with decorated name for fastcall/stdcall functions. */ + if (!p && ctype_isfunc(ct->info)) { + CTInfo cconv = ctype_cconv(ct->info); + if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) { + CTSize sz = clib_func_argsize(cts, ct); + const char *symd = lj_str_pushf(L, + cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d", + sym, sz); + L->top--; + p = clib_getsym(cl, symd); + } + } +#endif + if (!p) + clib_error(L, "cannot resolve symbol " LUA_QS ": %s", sym); +#if LJ_TARGET_WINDOWS + SetLastError(oldwerr); +#endif + cd = lj_cdata_new(cts, id, CTSIZE_PTR); + *(void **)cdataptr(cd) = p; + setcdataV(L, tv, cd); + } + } + return tv; +} + +/* -- C library management ------------------------------------------------ */ + +/* Create a new CLibrary object and push it on the stack. */ +static CLibrary *clib_new(lua_State *L, GCtab *mt) +{ + GCtab *t = lj_tab_new(L, 0, 0); + GCudata *ud = lj_udata_new(L, sizeof(CLibrary), t); + CLibrary *cl = (CLibrary *)uddata(ud); + cl->cache = t; + ud->udtype = UDTYPE_FFI_CLIB; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcref(ud->metatable, obj2gco(mt)); + setudataV(L, L->top++, ud); + return cl; +} + +/* Load a C library. */ +void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global) +{ + void *handle = clib_loadlib(L, strdata(name), global); + CLibrary *cl = clib_new(L, mt); + cl->handle = handle; +} + +/* Unload a C library. */ +void lj_clib_unload(CLibrary *cl) +{ + clib_unloadlib(cl); + cl->handle = NULL; +} + +/* Create the default C library object. */ +void lj_clib_default(lua_State *L, GCtab *mt) +{ + CLibrary *cl = clib_new(L, mt); + cl->handle = CLIB_DEFHANDLE; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.h new file mode 100644 index 0000000..4737328 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_clib.h @@ -0,0 +1,29 @@ +/* +** FFI C library loader. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CLIB_H +#define _LJ_CLIB_H + +#include "lj_obj.h" + +#if LJ_HASFFI + +/* Namespace for C library indexing. */ +#define CLNS_INDEX ((1u<env. */ +} CLibrary; + +LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name); +LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global); +LJ_FUNC void lj_clib_unload(CLibrary *cl); +LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.c new file mode 100644 index 0000000..6ffe16a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.c @@ -0,0 +1,1872 @@ +/* +** C declaration parser. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ctype.h" +#include "lj_cparse.h" +#include "lj_frame.h" +#include "lj_vm.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* +** Important note: this is NOT a validating C parser! This is a minimal +** C declaration parser, solely for use by the LuaJIT FFI. +** +** It ought to return correct results for properly formed C declarations, +** but it may accept some invalid declarations, too (and return nonsense). +** Also, it shows rather generic error messages to avoid unnecessary bloat. +** If in doubt, please check the input against your favorite C compiler. +*/ + +/* -- C lexer ------------------------------------------------------------- */ + +/* C lexer token names. */ +static const char *const ctoknames[] = { +#define CTOKSTR(name, str) str, +CTOKDEF(CTOKSTR) +#undef CTOKSTR + NULL +}; + +/* Forward declaration. */ +LJ_NORET static void cp_err(CPState *cp, ErrMsg em); + +static const char *cp_tok2str(CPState *cp, CPToken tok) +{ + lua_assert(tok < CTOK_FIRSTDECL); + if (tok > CTOK_OFS) + return ctoknames[tok-CTOK_OFS-1]; + else if (!lj_char_iscntrl(tok)) + return lj_str_pushf(cp->L, "%c", tok); + else + return lj_str_pushf(cp->L, "char(%d)", tok); +} + +/* End-of-line? */ +static LJ_AINLINE int cp_iseol(CPChar c) +{ + return (c == '\n' || c == '\r'); +} + +/* Peek next raw character. */ +static LJ_AINLINE CPChar cp_rawpeek(CPState *cp) +{ + return (CPChar)(uint8_t)(*cp->p); +} + +static LJ_NOINLINE CPChar cp_get_bs(CPState *cp); + +/* Get next character. */ +static LJ_AINLINE CPChar cp_get(CPState *cp) +{ + cp->c = (CPChar)(uint8_t)(*cp->p++); + if (LJ_LIKELY(cp->c != '\\')) return cp->c; + return cp_get_bs(cp); +} + +/* Transparently skip backslash-escaped line breaks. */ +static LJ_NOINLINE CPChar cp_get_bs(CPState *cp) +{ + CPChar c2, c = cp_rawpeek(cp); + if (!cp_iseol(c)) return cp->c; + cp->p++; + c2 = cp_rawpeek(cp); + if (cp_iseol(c2) && c2 != c) cp->p++; + cp->linenumber++; + return cp_get(cp); +} + +/* Grow save buffer. */ +static LJ_NOINLINE void cp_save_grow(CPState *cp, CPChar c) +{ + MSize newsize; + if (cp->sb.sz >= CPARSE_MAX_BUF/2) + cp_err(cp, LJ_ERR_XELEM); + newsize = cp->sb.sz * 2; + lj_str_resizebuf(cp->L, &cp->sb, newsize); + cp->sb.buf[cp->sb.n++] = (char)c; +} + +/* Save character in buffer. */ +static LJ_AINLINE void cp_save(CPState *cp, CPChar c) +{ + if (LJ_UNLIKELY(cp->sb.n + 1 > cp->sb.sz)) + cp_save_grow(cp, c); + else + cp->sb.buf[cp->sb.n++] = (char)c; +} + +/* Skip line break. Handles "\n", "\r", "\r\n" or "\n\r". */ +static void cp_newline(CPState *cp) +{ + CPChar c = cp_rawpeek(cp); + if (cp_iseol(c) && c != cp->c) cp->p++; + cp->linenumber++; +} + +LJ_NORET static void cp_errmsg(CPState *cp, CPToken tok, ErrMsg em, ...) +{ + const char *msg, *tokstr; + lua_State *L; + va_list argp; + if (tok == 0) { + tokstr = NULL; + } else if (tok == CTOK_IDENT || tok == CTOK_INTEGER || tok == CTOK_STRING || + tok >= CTOK_FIRSTDECL) { + if (cp->sb.n == 0) cp_save(cp, '$'); + cp_save(cp, '\0'); + tokstr = cp->sb.buf; + } else { + tokstr = cp_tok2str(cp, tok); + } + L = cp->L; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + if (tokstr) + msg = lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tokstr); + if (cp->linenumber > 1) + msg = lj_str_pushf(L, "%s at line %d", msg, cp->linenumber); + lj_err_callermsg(L, msg); +} + +LJ_NORET LJ_NOINLINE static void cp_err_token(CPState *cp, CPToken tok) +{ + cp_errmsg(cp, cp->tok, LJ_ERR_XTOKEN, cp_tok2str(cp, tok)); +} + +LJ_NORET LJ_NOINLINE static void cp_err_badidx(CPState *cp, CType *ct) +{ + GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL); + cp_errmsg(cp, 0, LJ_ERR_FFI_BADIDX, strdata(s)); +} + +LJ_NORET LJ_NOINLINE static void cp_err(CPState *cp, ErrMsg em) +{ + cp_errmsg(cp, 0, em); +} + +/* -- Main lexical scanner ------------------------------------------------ */ + +/* Parse number literal. Only handles int32_t/uint32_t right now. */ +static CPToken cp_number(CPState *cp) +{ + StrScanFmt fmt; + TValue o; + do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp))); + cp_save(cp, '\0'); + fmt = lj_strscan_scan((const uint8_t *)cp->sb.buf, &o, STRSCAN_OPT_C); + if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32; + else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32; + else if (!(cp->mode & CPARSE_MODE_SKIP)) + cp_errmsg(cp, CTOK_INTEGER, LJ_ERR_XNUMBER); + cp->val.u32 = (uint32_t)o.i; + return CTOK_INTEGER; +} + +/* Parse identifier or keyword. */ +static CPToken cp_ident(CPState *cp) +{ + do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp))); + cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n); + cp->val.id = lj_ctype_getname(cp->cts, &cp->ct, cp->str, cp->tmask); + if (ctype_type(cp->ct->info) == CT_KW) + return ctype_cid(cp->ct->info); + return CTOK_IDENT; +} + +/* Parse parameter. */ +static CPToken cp_param(CPState *cp) +{ + CPChar c = cp_get(cp); + TValue *o = cp->param; + if (lj_char_isident(c) || c == '$') /* Reserve $xyz for future extensions. */ + cp_errmsg(cp, c, LJ_ERR_XSYNTAX); + if (!o || o >= cp->L->top) + cp_err(cp, LJ_ERR_FFI_NUMPARAM); + cp->param = o+1; + if (tvisstr(o)) { + cp->str = strV(o); + cp->val.id = 0; + cp->ct = &cp->cts->tab[0]; + return CTOK_IDENT; + } else if (tvisnumber(o)) { + cp->val.i32 = numberVint(o); + cp->val.id = CTID_INT32; + return CTOK_INTEGER; + } else { + GCcdata *cd; + if (!tviscdata(o)) + lj_err_argtype(cp->L, (int)(o-cp->L->base)+1, "type parameter"); + cd = cdataV(o); + if (cd->ctypeid == CTID_CTYPEID) + cp->val.id = *(CTypeID *)cdataptr(cd); + else + cp->val.id = cd->ctypeid; + return '$'; + } +} + +/* Parse string or character constant. */ +static CPToken cp_string(CPState *cp) +{ + CPChar delim = cp->c; + cp_get(cp); + while (cp->c != delim) { + CPChar c = cp->c; + if (c == '\0') cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); + if (c == '\\') { + c = cp_get(cp); + switch (c) { + case '\0': cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); break; + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'e': c = 27; break; + case 'x': + c = 0; + while (lj_char_isxdigit(cp_get(cp))) + c = (c<<4) + (lj_char_isdigit(cp->c) ? cp->c-'0' : (cp->c&15)+9); + cp_save(cp, (c & 0xff)); + continue; + default: + if (lj_char_isdigit(c)) { + c -= '0'; + if (lj_char_isdigit(cp_get(cp))) { + c = c*8 + (cp->c - '0'); + if (lj_char_isdigit(cp_get(cp))) { + c = c*8 + (cp->c - '0'); + cp_get(cp); + } + } + cp_save(cp, (c & 0xff)); + continue; + } + break; + } + } + cp_save(cp, c); + cp_get(cp); + } + cp_get(cp); + if (delim == '"') { + cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n); + return CTOK_STRING; + } else { + if (cp->sb.n != 1) cp_err_token(cp, '\''); + cp->val.i32 = (int32_t)(char)cp->sb.buf[0]; + cp->val.id = CTID_INT32; + return CTOK_INTEGER; + } +} + +/* Skip C comment. */ +static void cp_comment_c(CPState *cp) +{ + do { + if (cp_get(cp) == '*') { + do { + if (cp_get(cp) == '/') { cp_get(cp); return; } + } while (cp->c == '*'); + } + if (cp_iseol(cp->c)) cp_newline(cp); + } while (cp->c != '\0'); +} + +/* Skip C++ comment. */ +static void cp_comment_cpp(CPState *cp) +{ + while (!cp_iseol(cp_get(cp)) && cp->c != '\0') + ; +} + +/* Lexical scanner for C. Only a minimal subset is implemented. */ +static CPToken cp_next_(CPState *cp) +{ + lj_str_resetbuf(&cp->sb); + for (;;) { + if (lj_char_isident(cp->c)) + return lj_char_isdigit(cp->c) ? cp_number(cp) : cp_ident(cp); + switch (cp->c) { + case '\n': case '\r': cp_newline(cp); /* fallthrough. */ + case ' ': case '\t': case '\v': case '\f': cp_get(cp); break; + case '"': case '\'': return cp_string(cp); + case '/': + if (cp_get(cp) == '*') cp_comment_c(cp); + else if (cp->c == '/') cp_comment_cpp(cp); + else return '/'; + break; + case '|': + if (cp_get(cp) != '|') return '|'; cp_get(cp); return CTOK_OROR; + case '&': + if (cp_get(cp) != '&') return '&'; cp_get(cp); return CTOK_ANDAND; + case '=': + if (cp_get(cp) != '=') return '='; cp_get(cp); return CTOK_EQ; + case '!': + if (cp_get(cp) != '=') return '!'; cp_get(cp); return CTOK_NE; + case '<': + if (cp_get(cp) == '=') { cp_get(cp); return CTOK_LE; } + else if (cp->c == '<') { cp_get(cp); return CTOK_SHL; } + return '<'; + case '>': + if (cp_get(cp) == '=') { cp_get(cp); return CTOK_GE; } + else if (cp->c == '>') { cp_get(cp); return CTOK_SHR; } + return '>'; + case '-': + if (cp_get(cp) != '>') return '-'; cp_get(cp); return CTOK_DEREF; + case '$': + return cp_param(cp); + case '\0': return CTOK_EOF; + default: { CPToken c = cp->c; cp_get(cp); return c; } + } + } +} + +static LJ_NOINLINE CPToken cp_next(CPState *cp) +{ + return (cp->tok = cp_next_(cp)); +} + +/* -- C parser ------------------------------------------------------------ */ + +/* Namespaces for resolving identifiers. */ +#define CPNS_DEFAULT \ + ((1u<linenumber = 1; + cp->depth = 0; + cp->curpack = 0; + cp->packstack[0] = 255; + lj_str_initbuf(&cp->sb); + lj_str_resizebuf(cp->L, &cp->sb, LJ_MIN_SBUF); + lua_assert(cp->p != NULL); + cp_get(cp); /* Read-ahead first char. */ + cp->tok = 0; + cp->tmask = CPNS_DEFAULT; + cp_next(cp); /* Read-ahead first token. */ +} + +/* Cleanup C parser state. */ +static void cp_cleanup(CPState *cp) +{ + global_State *g = G(cp->L); + lj_str_freebuf(g, &cp->sb); +} + +/* Check and consume optional token. */ +static int cp_opt(CPState *cp, CPToken tok) +{ + if (cp->tok == tok) { cp_next(cp); return 1; } + return 0; +} + +/* Check and consume token. */ +static void cp_check(CPState *cp, CPToken tok) +{ + if (cp->tok != tok) cp_err_token(cp, tok); + cp_next(cp); +} + +/* Check if the next token may start a type declaration. */ +static int cp_istypedecl(CPState *cp) +{ + if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECL) return 1; + if (cp->tok == CTOK_IDENT && ctype_istypedef(cp->ct->info)) return 1; + if (cp->tok == '$') return 1; + return 0; +} + +/* -- Constant expression evaluator --------------------------------------- */ + +/* Forward declarations. */ +static void cp_expr_unary(CPState *cp, CPValue *k); +static void cp_expr_sub(CPState *cp, CPValue *k, int pri); + +/* Please note that type handling is very weak here. Most ops simply +** assume integer operands. Accessors are only needed to compute types and +** return synthetic values. The only purpose of the expression evaluator +** is to compute the values of constant expressions one would typically +** find in C header files. And again: this is NOT a validating C parser! +*/ + +/* Parse comma separated expression and return last result. */ +static void cp_expr_comma(CPState *cp, CPValue *k) +{ + do { cp_expr_sub(cp, k, 0); } while (cp_opt(cp, ',')); +} + +/* Parse sizeof/alignof operator. */ +static void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz) +{ + CTSize sz; + CTInfo info; + if (cp_opt(cp, '(')) { + if (cp_istypedecl(cp)) + k->id = cp_decl_abstract(cp); + else + cp_expr_comma(cp, k); + cp_check(cp, ')'); + } else { + cp_expr_unary(cp, k); + } + info = lj_ctype_info(cp->cts, k->id, &sz); + if (wantsz) { + if (sz != CTSIZE_INVALID) + k->u32 = sz; + else if (k->id != CTID_A_CCHAR) /* Special case for sizeof("string"). */ + cp_err(cp, LJ_ERR_FFI_INVSIZE); + } else { + k->u32 = 1u << ctype_align(info); + } + k->id = CTID_UINT32; /* Really size_t. */ +} + +/* Parse prefix operators. */ +static void cp_expr_prefix(CPState *cp, CPValue *k) +{ + if (cp->tok == CTOK_INTEGER) { + *k = cp->val; cp_next(cp); + } else if (cp_opt(cp, '+')) { + cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */ + } else if (cp_opt(cp, '-')) { + cp_expr_unary(cp, k); k->i32 = -k->i32; + } else if (cp_opt(cp, '~')) { + cp_expr_unary(cp, k); k->i32 = ~k->i32; + } else if (cp_opt(cp, '!')) { + cp_expr_unary(cp, k); k->i32 = !k->i32; k->id = CTID_INT32; + } else if (cp_opt(cp, '(')) { + if (cp_istypedecl(cp)) { /* Cast operator. */ + CTypeID id = cp_decl_abstract(cp); + cp_check(cp, ')'); + cp_expr_unary(cp, k); + k->id = id; /* No conversion performed. */ + } else { /* Sub-expression. */ + cp_expr_comma(cp, k); + cp_check(cp, ')'); + } + } else if (cp_opt(cp, '*')) { /* Indirection. */ + CType *ct; + cp_expr_unary(cp, k); + ct = lj_ctype_rawref(cp->cts, k->id); + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + k->u32 = 0; k->id = ctype_cid(ct->info); + } else if (cp_opt(cp, '&')) { /* Address operator. */ + cp_expr_unary(cp, k); + k->id = lj_ctype_intern(cp->cts, CTINFO(CT_PTR, CTALIGN_PTR+k->id), + CTSIZE_PTR); + } else if (cp_opt(cp, CTOK_SIZEOF)) { + cp_expr_sizeof(cp, k, 1); + } else if (cp_opt(cp, CTOK_ALIGNOF)) { + cp_expr_sizeof(cp, k, 0); + } else if (cp->tok == CTOK_IDENT) { + if (ctype_type(cp->ct->info) == CT_CONSTVAL) { + k->u32 = cp->ct->size; k->id = ctype_cid(cp->ct->info); + } else if (ctype_type(cp->ct->info) == CT_EXTERN) { + k->u32 = cp->val.id; k->id = ctype_cid(cp->ct->info); + } else if (ctype_type(cp->ct->info) == CT_FUNC) { + k->u32 = cp->val.id; k->id = cp->val.id; + } else { + goto err_expr; + } + cp_next(cp); + } else if (cp->tok == CTOK_STRING) { + CTSize sz = cp->str->len; + while (cp_next(cp) == CTOK_STRING) + sz += cp->str->len; + k->u32 = sz + 1; + k->id = CTID_A_CCHAR; + } else { + err_expr: + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + } +} + +/* Parse postfix operators. */ +static void cp_expr_postfix(CPState *cp, CPValue *k) +{ + for (;;) { + CType *ct; + if (cp_opt(cp, '[')) { /* Array/pointer index. */ + CPValue k2; + cp_expr_comma(cp, &k2); + ct = lj_ctype_rawref(cp->cts, k->id); + if (!ctype_ispointer(ct->info)) { + ct = lj_ctype_rawref(cp->cts, k2.id); + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + } + cp_check(cp, ']'); + k->u32 = 0; + } else if (cp->tok == '.' || cp->tok == CTOK_DEREF) { /* Struct deref. */ + CTSize ofs; + CType *fct; + ct = lj_ctype_rawref(cp->cts, k->id); + if (cp->tok == CTOK_DEREF) { + if (!ctype_ispointer(ct->info)) + cp_err_badidx(cp, ct); + ct = lj_ctype_rawref(cp->cts, ctype_cid(ct->info)); + } + cp_next(cp); + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (!ctype_isstruct(ct->info) || ct->size == CTSIZE_INVALID || + !(fct = lj_ctype_getfield(cp->cts, ct, cp->str, &ofs)) || + ctype_isbitfield(fct->info)) { + GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL); + cp_errmsg(cp, 0, LJ_ERR_FFI_BADMEMBER, strdata(s), strdata(cp->str)); + } + ct = fct; + k->u32 = ctype_isconstval(ct->info) ? ct->size : 0; + cp_next(cp); + } else { + return; + } + k->id = ctype_cid(ct->info); + } +} + +/* Parse infix operators. */ +static void cp_expr_infix(CPState *cp, CPValue *k, int pri) +{ + CPValue k2; + k2.u32 = 0; k2.id = 0; /* Silence the compiler. */ + for (;;) { + switch (pri) { + case 0: + if (cp_opt(cp, '?')) { + CPValue k3; + cp_expr_comma(cp, &k2); /* Right-associative. */ + cp_check(cp, ':'); + cp_expr_sub(cp, &k3, 0); + k->u32 = k->u32 ? k2.u32 : k3.u32; + k->id = k2.id > k3.id ? k2.id : k3.id; + continue; + } + case 1: + if (cp_opt(cp, CTOK_OROR)) { + cp_expr_sub(cp, &k2, 2); k->i32 = k->u32 || k2.u32; k->id = CTID_INT32; + continue; + } + case 2: + if (cp_opt(cp, CTOK_ANDAND)) { + cp_expr_sub(cp, &k2, 3); k->i32 = k->u32 && k2.u32; k->id = CTID_INT32; + continue; + } + case 3: + if (cp_opt(cp, '|')) { + cp_expr_sub(cp, &k2, 4); k->u32 = k->u32 | k2.u32; goto arith_result; + } + case 4: + if (cp_opt(cp, '^')) { + cp_expr_sub(cp, &k2, 5); k->u32 = k->u32 ^ k2.u32; goto arith_result; + } + case 5: + if (cp_opt(cp, '&')) { + cp_expr_sub(cp, &k2, 6); k->u32 = k->u32 & k2.u32; goto arith_result; + } + case 6: + if (cp_opt(cp, CTOK_EQ)) { + cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 == k2.u32; k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_NE)) { + cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 != k2.u32; k->id = CTID_INT32; + continue; + } + case 7: + if (cp_opt(cp, '<')) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 < k2.i32; + else + k->i32 = k->u32 < k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, '>')) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 > k2.i32; + else + k->i32 = k->u32 > k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_LE)) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 <= k2.i32; + else + k->i32 = k->u32 <= k2.u32; + k->id = CTID_INT32; + continue; + } else if (cp_opt(cp, CTOK_GE)) { + cp_expr_sub(cp, &k2, 8); + if (k->id == CTID_INT32 && k2.id == CTID_INT32) + k->i32 = k->i32 >= k2.i32; + else + k->i32 = k->u32 >= k2.u32; + k->id = CTID_INT32; + continue; + } + case 8: + if (cp_opt(cp, CTOK_SHL)) { + cp_expr_sub(cp, &k2, 9); k->u32 = k->u32 << k2.u32; + continue; + } else if (cp_opt(cp, CTOK_SHR)) { + cp_expr_sub(cp, &k2, 9); + if (k->id == CTID_INT32) + k->i32 = k->i32 >> k2.i32; + else + k->u32 = k->u32 >> k2.u32; + continue; + } + case 9: + if (cp_opt(cp, '+')) { + cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 + k2.u32; + arith_result: + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + continue; + } else if (cp_opt(cp, '-')) { + cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 - k2.u32; goto arith_result; + } + case 10: + if (cp_opt(cp, '*')) { + cp_expr_unary(cp, &k2); k->u32 = k->u32 * k2.u32; goto arith_result; + } else if (cp_opt(cp, '/')) { + cp_expr_unary(cp, &k2); + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + if (k2.u32 == 0 || + (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1)) + cp_err(cp, LJ_ERR_BADVAL); + if (k->id == CTID_INT32) + k->i32 = k->i32 / k2.i32; + else + k->u32 = k->u32 / k2.u32; + continue; + } else if (cp_opt(cp, '%')) { + cp_expr_unary(cp, &k2); + if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */ + if (k2.u32 == 0 || + (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1)) + cp_err(cp, LJ_ERR_BADVAL); + if (k->id == CTID_INT32) + k->i32 = k->i32 % k2.i32; + else + k->u32 = k->u32 % k2.u32; + continue; + } + default: + return; + } + } +} + +/* Parse and evaluate unary expression. */ +static void cp_expr_unary(CPState *cp, CPValue *k) +{ + if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS); + cp_expr_prefix(cp, k); + cp_expr_postfix(cp, k); + cp->depth--; +} + +/* Parse and evaluate sub-expression. */ +static void cp_expr_sub(CPState *cp, CPValue *k, int pri) +{ + cp_expr_unary(cp, k); + cp_expr_infix(cp, k, pri); +} + +/* Parse constant integer expression. */ +static void cp_expr_kint(CPState *cp, CPValue *k) +{ + CType *ct; + cp_expr_sub(cp, k, 0); + ct = ctype_raw(cp->cts, k->id); + if (!ctype_isinteger(ct->info)) cp_err(cp, LJ_ERR_BADVAL); +} + +/* Parse (non-negative) size expression. */ +static CTSize cp_expr_ksize(CPState *cp) +{ + CPValue k; + cp_expr_kint(cp, &k); + if (k.u32 >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE); + return k.u32; +} + +/* -- Type declaration stack management ----------------------------------- */ + +/* Add declaration element behind the insertion position. */ +static CPDeclIdx cp_add(CPDecl *decl, CTInfo info, CTSize size) +{ + CPDeclIdx top = decl->top; + if (top >= CPARSE_MAX_DECLSTACK) cp_err(decl->cp, LJ_ERR_XLEVELS); + decl->stack[top].info = info; + decl->stack[top].size = size; + decl->stack[top].sib = 0; + setgcrefnull(decl->stack[top].name); + decl->stack[top].next = decl->stack[decl->pos].next; + decl->stack[decl->pos].next = (CTypeID1)top; + decl->top = top+1; + return top; +} + +/* Push declaration element before the insertion position. */ +static CPDeclIdx cp_push(CPDecl *decl, CTInfo info, CTSize size) +{ + return (decl->pos = cp_add(decl, info, size)); +} + +/* Push or merge attributes. */ +static void cp_push_attributes(CPDecl *decl) +{ + CType *ct = &decl->stack[decl->pos]; + if (ctype_isfunc(ct->info)) { /* Ok to modify in-place. */ +#if LJ_TARGET_X86 + if ((decl->fattr & CTFP_CCONV)) + ct->info = (ct->info & (CTMASK_NUM|CTF_VARARG|CTMASK_CID)) + + (decl->fattr & ~CTMASK_CID); +#endif + } else { + if ((decl->attr & CTFP_ALIGNED) && !(decl->mode & CPARSE_MODE_FIELD)) + cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_ALIGN)), + ctype_align(decl->attr)); + } +} + +/* Push unrolled type to declaration stack and merge qualifiers. */ +static void cp_push_type(CPDecl *decl, CTypeID id) +{ + CType *ct = ctype_get(decl->cp->cts, id); + CTInfo info = ct->info; + CTSize size = ct->size; + switch (ctype_type(info)) { + case CT_STRUCT: case CT_ENUM: + cp_push(decl, CTINFO(CT_TYPEDEF, id), 0); /* Don't copy unique types. */ + if ((decl->attr & CTF_QUAL)) { /* Push unmerged qualifiers. */ + cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_QUAL)), + (decl->attr & CTF_QUAL)); + decl->attr &= ~CTF_QUAL; + } + break; + case CT_ATTRIB: + if (ctype_isxattrib(info, CTA_QUAL)) + decl->attr &= ~size; /* Remove redundant qualifiers. */ + cp_push_type(decl, ctype_cid(info)); /* Unroll. */ + cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ + break; + case CT_ARRAY: + cp_push_type(decl, ctype_cid(info)); /* Unroll. */ + cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ + decl->stack[decl->pos].sib = 1; /* Mark as already checked and sized. */ + /* Note: this is not copied to the ct->sib in the C type table. */ + break; + case CT_FUNC: + /* Copy type, link parameters (shared). */ + decl->stack[cp_push(decl, info, size)].sib = ct->sib; + break; + default: + /* Copy type, merge common qualifiers. */ + cp_push(decl, info|(decl->attr & CTF_QUAL), size); + decl->attr &= ~CTF_QUAL; + break; + } +} + +/* Consume the declaration element chain and intern the C type. */ +static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl) +{ + CTypeID id = 0; + CPDeclIdx idx = 0; + CTSize csize = CTSIZE_INVALID; + CTSize cinfo = 0; + do { + CType *ct = &decl->stack[idx]; + CTInfo info = ct->info; + CTInfo size = ct->size; + /* The cid is already part of info for copies of pointers/functions. */ + idx = ct->next; + if (ctype_istypedef(info)) { + lua_assert(id == 0); + id = ctype_cid(info); + /* Always refetch info/size, since struct/enum may have been completed. */ + cinfo = ctype_get(cp->cts, id)->info; + csize = ctype_get(cp->cts, id)->size; + lua_assert(ctype_isstruct(cinfo) || ctype_isenum(cinfo)); + } else if (ctype_isfunc(info)) { /* Intern function. */ + CType *fct; + CTypeID fid; + CTypeID sib; + if (id) { + CType *refct = ctype_raw(cp->cts, id); + /* Reject function or refarray return types. */ + if (ctype_isfunc(refct->info) || ctype_isrefarray(refct->info)) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + } + /* No intervening attributes allowed, skip forward. */ + while (idx) { + CType *ctn = &decl->stack[idx]; + if (!ctype_isattrib(ctn->info)) break; + idx = ctn->next; /* Skip attribute. */ + } + sib = ct->sib; /* Next line may reallocate the C type table. */ + fid = lj_ctype_new(cp->cts, &fct); + csize = CTSIZE_INVALID; + fct->info = cinfo = info + id; + fct->size = size; + fct->sib = sib; + id = fid; + } else if (ctype_isattrib(info)) { + if (ctype_isxattrib(info, CTA_QUAL)) + cinfo |= size; + else if (ctype_isxattrib(info, CTA_ALIGN)) + CTF_INSERT(cinfo, ALIGN, size); + id = lj_ctype_intern(cp->cts, info+id, size); + /* Inherit csize/cinfo from original type. */ + } else { + if (ctype_isnum(info)) { /* Handle mode/vector-size attributes. */ + lua_assert(id == 0); + if (!(info & CTF_BOOL)) { + CTSize msize = ctype_msizeP(decl->attr); + CTSize vsize = ctype_vsizeP(decl->attr); + if (msize && (!(info & CTF_FP) || (msize == 4 || msize == 8))) { + CTSize malign = lj_fls(msize); + if (malign > 4) malign = 4; /* Limit alignment. */ + CTF_INSERT(info, ALIGN, malign); + size = msize; /* Override size via mode. */ + } + if (vsize) { /* Vector size set? */ + CTSize esize = lj_fls(size); + if (vsize >= esize) { + /* Intern the element type first. */ + id = lj_ctype_intern(cp->cts, info, size); + /* Then create a vector (array) with vsize alignment. */ + size = (1u << vsize); + if (vsize > 4) vsize = 4; /* Limit alignment. */ + if (ctype_align(info) > vsize) vsize = ctype_align(info); + info = CTINFO(CT_ARRAY, (info & CTF_QUAL) + CTF_VECTOR + + CTALIGN(vsize)); + } + } + } + } else if (ctype_isptr(info)) { + /* Reject pointer/ref to ref. */ + if (id && ctype_isref(ctype_raw(cp->cts, id)->info)) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + if (ctype_isref(info)) { + info &= ~CTF_VOLATILE; /* Refs are always const, never volatile. */ + /* No intervening attributes allowed, skip forward. */ + while (idx) { + CType *ctn = &decl->stack[idx]; + if (!ctype_isattrib(ctn->info)) break; + idx = ctn->next; /* Skip attribute. */ + } + } + } else if (ctype_isarray(info)) { /* Check for valid array size etc. */ + if (ct->sib == 0) { /* Only check/size arrays not copied by unroll. */ + if (ctype_isref(cinfo)) /* Reject arrays of refs. */ + cp_err(cp, LJ_ERR_FFI_INVTYPE); + /* Reject VLS or unknown-sized types. */ + if (ctype_isvltype(cinfo) || csize == CTSIZE_INVALID) + cp_err(cp, LJ_ERR_FFI_INVSIZE); + /* a[] and a[?] keep their invalid size. */ + if (size != CTSIZE_INVALID) { + uint64_t xsz = (uint64_t)size * csize; + if (xsz >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE); + size = (CTSize)xsz; + } + } + if ((cinfo & CTF_ALIGN) > (info & CTF_ALIGN)) /* Find max. align. */ + info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN); + info |= (cinfo & CTF_QUAL); /* Inherit qual. */ + } else { + lua_assert(ctype_isvoid(info)); + } + csize = size; + cinfo = info+id; + id = lj_ctype_intern(cp->cts, info+id, size); + } + } while (idx); + return id; +} + +/* -- C declaration parser ------------------------------------------------ */ + +#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be) + +/* Reset declaration state to declaration specifier. */ +static void cp_decl_reset(CPDecl *decl) +{ + decl->pos = decl->specpos; + decl->top = decl->specpos+1; + decl->stack[decl->specpos].next = 0; + decl->attr = decl->specattr; + decl->fattr = decl->specfattr; + decl->name = NULL; + decl->redir = NULL; +} + +/* Parse constant initializer. */ +/* NYI: FP constants and strings as initializers. */ +static CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID ctypeid) +{ + CType *ctt = ctype_get(cp->cts, ctypeid); + CTInfo info; + CTSize size; + CPValue k; + CTypeID constid; + while (ctype_isattrib(ctt->info)) { /* Skip attributes. */ + ctypeid = ctype_cid(ctt->info); /* Update ID, too. */ + ctt = ctype_get(cp->cts, ctypeid); + } + info = ctt->info; + size = ctt->size; + if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4) + cp_err(cp, LJ_ERR_FFI_INVTYPE); + cp_check(cp, '='); + cp_expr_sub(cp, &k, 0); + constid = lj_ctype_new(cp->cts, ctp); + (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|ctypeid); + k.u32 <<= 8*(4-size); + if ((info & CTF_UNSIGNED)) + k.u32 >>= 8*(4-size); + else + k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size)); + (*ctp)->size = k.u32; + return constid; +} + +/* Parse size in parentheses as part of attribute. */ +static CTSize cp_decl_sizeattr(CPState *cp) +{ + CTSize sz; + uint32_t oldtmask = cp->tmask; + cp->tmask = CPNS_DEFAULT; /* Required for expression evaluator. */ + cp_check(cp, '('); + sz = cp_expr_ksize(cp); + cp->tmask = oldtmask; + cp_check(cp, ')'); + return sz; +} + +/* Parse alignment attribute. */ +static void cp_decl_align(CPState *cp, CPDecl *decl) +{ + CTSize al = 4; /* Unspecified alignment is 16 bytes. */ + if (cp->tok == '(') { + al = cp_decl_sizeattr(cp); + al = al ? lj_fls(al) : 0; + } + CTF_INSERT(decl->attr, ALIGN, al); + decl->attr |= CTFP_ALIGNED; +} + +/* Parse GCC asm("name") redirect. */ +static void cp_decl_asm(CPState *cp, CPDecl *decl) +{ + UNUSED(decl); + cp_next(cp); + cp_check(cp, '('); + if (cp->tok == CTOK_STRING) { + GCstr *str = cp->str; + while (cp_next(cp) == CTOK_STRING) { + lj_str_pushf(cp->L, "%s%s", strdata(str), strdata(cp->str)); + cp->L->top--; + str = strV(cp->L->top); + } + decl->redir = str; + } + cp_check(cp, ')'); +} + +/* Parse GCC __attribute__((mode(...))). */ +static void cp_decl_mode(CPState *cp, CPDecl *decl) +{ + cp_check(cp, '('); + if (cp->tok == CTOK_IDENT) { + const char *s = strdata(cp->str); + CTSize sz = 0, vlen = 0; + if (s[0] == '_' && s[1] == '_') s += 2; + if (*s == 'V') { + s++; + vlen = *s++ - '0'; + if (*s >= '0' && *s <= '9') + vlen = vlen*10 + (*s++ - '0'); + } + switch (*s++) { + case 'Q': sz = 1; break; + case 'H': sz = 2; break; + case 'S': sz = 4; break; + case 'D': sz = 8; break; + case 'T': sz = 16; break; + case 'O': sz = 32; break; + default: goto bad_size; + } + if (*s == 'I' || *s == 'F') { + CTF_INSERT(decl->attr, MSIZEP, sz); + if (vlen) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vlen*sz)); + } + bad_size: + cp_next(cp); + } + cp_check(cp, ')'); +} + +/* Parse GCC __attribute__((...)). */ +static void cp_decl_gccattribute(CPState *cp, CPDecl *decl) +{ + cp_next(cp); + cp_check(cp, '('); + cp_check(cp, '('); + while (cp->tok != ')') { + if (cp->tok == CTOK_IDENT) { + GCstr *attrstr = cp->str; + cp_next(cp); + switch (attrstr->hash) { + case H_(64a9208e,8ce14319): case H_(8e6331b2,95a282af): /* aligned */ + cp_decl_align(cp, decl); + break; + case H_(42eb47de,f0ede26c): case H_(29f48a09,cf383e0c): /* packed */ + decl->attr |= CTFP_PACKED; + break; + case H_(0a84eef6,8dfab04c): case H_(995cf92c,d5696591): /* mode */ + cp_decl_mode(cp, decl); + break; + case H_(0ab31997,2d5213fa): case H_(bf875611,200e9990): /* vector_size */ + { + CTSize vsize = cp_decl_sizeattr(cp); + if (vsize) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vsize)); + } + break; +#if LJ_TARGET_X86 + case H_(5ad22db8,c689b848): case H_(439150fa,65ea78cb): /* regparm */ + CTF_INSERT(decl->fattr, REGPARM, cp_decl_sizeattr(cp)); + decl->fattr |= CTFP_CCONV; + break; + case H_(18fc0b98,7ff4c074): case H_(4e62abed,0a747424): /* cdecl */ + CTF_INSERT(decl->fattr, CCONV, CTCC_CDECL); + decl->fattr |= CTFP_CCONV; + break; + case H_(72b2e41b,494c5a44): case H_(f2356d59,f25fc9bd): /* thiscall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_THISCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(0d0ffc42,ab746f88): case H_(21c54ba1,7f0ca7e3): /* fastcall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_FASTCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(ef76b040,9412e06a): case H_(de56697b,c750e6e1): /* stdcall */ + CTF_INSERT(decl->fattr, CCONV, CTCC_STDCALL); + decl->fattr |= CTFP_CCONV; + break; + case H_(ea78b622,f234bd8e): case H_(252ffb06,8d50f34b): /* sseregparm */ + decl->fattr |= CTF_SSEREGPARM; + decl->fattr |= CTFP_CCONV; + break; +#endif + default: /* Skip all other attributes. */ + goto skip_attr; + } + } else if (cp->tok >= CTOK_FIRSTDECL) { /* For __attribute((const)) etc. */ + cp_next(cp); + skip_attr: + if (cp_opt(cp, '(')) { + while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp); + cp_check(cp, ')'); + } + } else { + break; + } + if (!cp_opt(cp, ',')) break; + } + cp_check(cp, ')'); + cp_check(cp, ')'); +} + +/* Parse MSVC __declspec(...). */ +static void cp_decl_msvcattribute(CPState *cp, CPDecl *decl) +{ + cp_next(cp); + cp_check(cp, '('); + while (cp->tok == CTOK_IDENT) { + GCstr *attrstr = cp->str; + cp_next(cp); + switch (attrstr->hash) { + case H_(bc2395fa,98f267f8): /* align */ + cp_decl_align(cp, decl); + break; + default: /* Ignore all other attributes. */ + if (cp_opt(cp, '(')) { + while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp); + cp_check(cp, ')'); + } + break; + } + } + cp_check(cp, ')'); +} + +/* Parse declaration attributes (and common qualifiers). */ +static void cp_decl_attributes(CPState *cp, CPDecl *decl) +{ + for (;;) { + switch (cp->tok) { + case CTOK_CONST: decl->attr |= CTF_CONST; break; + case CTOK_VOLATILE: decl->attr |= CTF_VOLATILE; break; + case CTOK_RESTRICT: break; /* Ignore. */ + case CTOK_EXTENSION: break; /* Ignore. */ + case CTOK_ATTRIBUTE: cp_decl_gccattribute(cp, decl); continue; + case CTOK_ASM: cp_decl_asm(cp, decl); continue; + case CTOK_DECLSPEC: cp_decl_msvcattribute(cp, decl); continue; + case CTOK_CCDECL: +#if LJ_TARGET_X86 + CTF_INSERT(decl->fattr, CCONV, cp->ct->size); + decl->fattr |= CTFP_CCONV; +#endif + break; + case CTOK_PTRSZ: +#if LJ_64 + CTF_INSERT(decl->attr, MSIZEP, cp->ct->size); +#endif + break; + default: return; + } + cp_next(cp); + } +} + +/* Parse struct/union/enum name. */ +static CTypeID cp_struct_name(CPState *cp, CPDecl *sdecl, CTInfo info) +{ + CTypeID sid; + CType *ct; + cp->tmask = CPNS_STRUCT; + cp_next(cp); + cp_decl_attributes(cp, sdecl); + cp->tmask = CPNS_DEFAULT; + if (cp->tok != '{') { + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (cp->val.id) { /* Name of existing struct/union/enum. */ + sid = cp->val.id; + ct = cp->ct; + if ((ct->info ^ info) & (CTMASK_NUM|CTF_UNION)) /* Wrong type. */ + cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name)))); + } else { /* Create named, incomplete struct/union/enum. */ + if ((cp->mode & CPARSE_MODE_NOIMPLICIT)) + cp_errmsg(cp, 0, LJ_ERR_FFI_BADTAG, strdata(cp->str)); + sid = lj_ctype_new(cp->cts, &ct); + ct->info = info; + ct->size = CTSIZE_INVALID; + ctype_setname(ct, cp->str); + lj_ctype_addname(cp->cts, ct, sid); + } + cp_next(cp); + } else { /* Create anonymous, incomplete struct/union/enum. */ + sid = lj_ctype_new(cp->cts, &ct); + ct->info = info; + ct->size = CTSIZE_INVALID; + } + if (cp->tok == '{') { + if (ct->size != CTSIZE_INVALID || ct->sib) + cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name)))); + ct->sib = 1; /* Indicate the type is currently being defined. */ + } + return sid; +} + +/* Determine field alignment. */ +static CTSize cp_field_align(CPState *cp, CType *ct, CTInfo info) +{ + CTSize align = ctype_align(info); + UNUSED(cp); UNUSED(ct); +#if (LJ_TARGET_X86 && !LJ_ABI_WIN) || (LJ_TARGET_ARM && __APPLE__) + /* The SYSV i386 and iOS ABIs limit alignment of non-vector fields to 2^2. */ + if (align > 2 && !(info & CTFP_ALIGNED)) { + if (ctype_isarray(info) && !(info & CTF_VECTOR)) { + do { + ct = ctype_rawchild(cp->cts, ct); + info = ct->info; + } while (ctype_isarray(info) && !(info & CTF_VECTOR)); + } + if (ctype_isnum(info) || ctype_isenum(info)) + align = 2; + } +#endif + return align; +} + +/* Layout struct/union fields. */ +static void cp_struct_layout(CPState *cp, CTypeID sid, CTInfo sattr) +{ + CTSize bofs = 0, bmaxofs = 0; /* Bit offset and max. bit offset. */ + CTSize maxalign = ctype_align(sattr); + CType *sct = ctype_get(cp->cts, sid); + CTInfo sinfo = sct->info; + CTypeID fieldid = sct->sib; + while (fieldid) { + CType *ct = ctype_get(cp->cts, fieldid); + CTInfo attr = ct->size; /* Field declaration attributes (temp.). */ + + if (ctype_isfield(ct->info) || + (ctype_isxattrib(ct->info, CTA_SUBTYPE) && attr)) { + CTSize align, amask; /* Alignment (pow2) and alignment mask (bits). */ + CTSize sz; + CTInfo info = lj_ctype_info(cp->cts, ctype_cid(ct->info), &sz); + CTSize bsz, csz = 8*sz; /* Field size and container size (in bits). */ + sinfo |= (info & (CTF_QUAL|CTF_VLA)); /* Merge pseudo-qualifiers. */ + + /* Check for size overflow and determine alignment. */ + if (sz >= 0x20000000u || bofs + csz < bofs || (info & CTF_VLA)) { + if (!(sz == CTSIZE_INVALID && ctype_isarray(info) && + !(sinfo & CTF_UNION))) + cp_err(cp, LJ_ERR_FFI_INVSIZE); + csz = sz = 0; /* Treat a[] and a[?] as zero-sized. */ + } + align = cp_field_align(cp, ct, info); + if (((attr|sattr) & CTFP_PACKED) || + ((attr & CTFP_ALIGNED) && ctype_align(attr) > align)) + align = ctype_align(attr); + if (cp->packstack[cp->curpack] < align) + align = cp->packstack[cp->curpack]; + if (align > maxalign) maxalign = align; + amask = (8u << align) - 1; + + bsz = ctype_bitcsz(ct->info); /* Bitfield size (temp.). */ + if (bsz == CTBSZ_FIELD || !ctype_isfield(ct->info)) { + bsz = csz; /* Regular fields or subtypes always fill the container. */ + bofs = (bofs + amask) & ~amask; /* Start new aligned field. */ + ct->size = (bofs >> 3); /* Store field offset. */ + } else { /* Bitfield. */ + if (bsz == 0 || (attr & CTFP_ALIGNED) || + (!((attr|sattr) & CTFP_PACKED) && (bofs & amask) + bsz > csz)) + bofs = (bofs + amask) & ~amask; /* Start new aligned field. */ + + /* Prefer regular field over bitfield. */ + if (bsz == csz && (bofs & amask) == 0) { + ct->info = CTINFO(CT_FIELD, ctype_cid(ct->info)); + ct->size = (bofs >> 3); /* Store field offset. */ + } else { + ct->info = CTINFO(CT_BITFIELD, + (info & (CTF_QUAL|CTF_UNSIGNED|CTF_BOOL)) + + (csz << (CTSHIFT_BITCSZ-3)) + (bsz << CTSHIFT_BITBSZ)); +#if LJ_BE + ct->info += ((csz - (bofs & (csz-1)) - bsz) << CTSHIFT_BITPOS); +#else + ct->info += ((bofs & (csz-1)) << CTSHIFT_BITPOS); +#endif + ct->size = ((bofs & ~(csz-1)) >> 3); /* Store container offset. */ + } + } + + /* Determine next offset or max. offset. */ + if ((sinfo & CTF_UNION)) { + if (bsz > bmaxofs) bmaxofs = bsz; + } else { + bofs += bsz; + } + } /* All other fields in the chain are already set up. */ + + fieldid = ct->sib; + } + + /* Complete struct/union. */ + sct->info = sinfo + CTALIGN(maxalign); + bofs = (sinfo & CTF_UNION) ? bmaxofs : bofs; + maxalign = (8u << maxalign) - 1; + sct->size = (((bofs + maxalign) & ~maxalign) >> 3); +} + +/* Parse struct/union declaration. */ +static CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo) +{ + CTypeID sid = cp_struct_name(cp, sdecl, sinfo); + if (cp_opt(cp, '{')) { /* Struct/union definition. */ + CTypeID lastid = sid; + int lastdecl = 0; + while (cp->tok != '}') { + CPDecl decl; + CPscl scl = cp_decl_spec(cp, &decl, CDF_STATIC); + decl.mode = scl ? CPARSE_MODE_DIRECT : + CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD; + + for (;;) { + CTypeID ctypeid; + + if (lastdecl) cp_err_token(cp, '}'); + + /* Parse field declarator. */ + decl.bits = CTSIZE_INVALID; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + + if ((scl & CDF_STATIC)) { /* Static constant in struct namespace. */ + CType *ct; + CTypeID fieldid = cp_decl_constinit(cp, &ct, ctypeid); + ctype_get(cp->cts, lastid)->sib = fieldid; + lastid = fieldid; + ctype_setname(ct, decl.name); + } else { + CTSize bsz = CTBSZ_FIELD; /* Temp. for layout phase. */ + CType *ct; + CTypeID fieldid = lj_ctype_new(cp->cts, &ct); /* Do this first. */ + CType *tct = ctype_raw(cp->cts, ctypeid); + + if (decl.bits == CTSIZE_INVALID) { /* Regular field. */ + if (ctype_isarray(tct->info) && tct->size == CTSIZE_INVALID) + lastdecl = 1; /* a[] or a[?] must be the last declared field. */ + + /* Accept transparent struct/union/enum. */ + if (!decl.name) { + if (!((ctype_isstruct(tct->info) && !(tct->info & CTF_VLA)) || + ctype_isenum(tct->info))) + cp_err_token(cp, CTOK_IDENT); + ct->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_SUBTYPE) + ctypeid); + ct->size = ctype_isstruct(tct->info) ? + (decl.attr|0x80000000u) : 0; /* For layout phase. */ + goto add_field; + } + } else { /* Bitfield. */ + bsz = decl.bits; + if (!ctype_isinteger_or_bool(tct->info) || + (bsz == 0 && decl.name) || 8*tct->size > CTBSZ_MAX || + bsz > ((tct->info & CTF_BOOL) ? 1 : 8*tct->size)) + cp_errmsg(cp, ':', LJ_ERR_BADVAL); + } + + /* Create temporary field for layout phase. */ + ct->info = CTINFO(CT_FIELD, ctypeid + (bsz << CTSHIFT_BITCSZ)); + ct->size = decl.attr; + if (decl.name) ctype_setname(ct, decl.name); + + add_field: + ctype_get(cp->cts, lastid)->sib = fieldid; + lastid = fieldid; + } + if (!cp_opt(cp, ',')) break; + cp_decl_reset(&decl); + } + cp_check(cp, ';'); + } + cp_check(cp, '}'); + ctype_get(cp->cts, lastid)->sib = 0; /* Drop sib = 1 for empty structs. */ + cp_decl_attributes(cp, sdecl); /* Layout phase needs postfix attributes. */ + cp_struct_layout(cp, sid, sdecl->attr); + } + return sid; +} + +/* Parse enum declaration. */ +static CTypeID cp_decl_enum(CPState *cp, CPDecl *sdecl) +{ + CTypeID eid = cp_struct_name(cp, sdecl, CTINFO(CT_ENUM, CTID_VOID)); + CTInfo einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_UINT32); + CTSize esize = 4; /* Only 32 bit enums are supported. */ + if (cp_opt(cp, '{')) { /* Enum definition. */ + CPValue k; + CTypeID lastid = eid; + k.u32 = 0; + k.id = CTID_INT32; + do { + GCstr *name = cp->str; + if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT); + if (cp->val.id) cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(name)); + cp_next(cp); + if (cp_opt(cp, '=')) { + cp_expr_kint(cp, &k); + if (k.id == CTID_UINT32) { + /* C99 says that enum constants are always (signed) integers. + ** But since unsigned constants like 0x80000000 are quite common, + ** those are left as uint32_t. + */ + if (k.i32 >= 0) k.id = CTID_INT32; + } else { + /* OTOH it's common practice and even mandated by some ABIs + ** that the enum type itself is unsigned, unless there are any + ** negative constants. + */ + k.id = CTID_INT32; + if (k.i32 < 0) einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_INT32); + } + } + /* Add named enum constant. */ + { + CType *ct; + CTypeID constid = lj_ctype_new(cp->cts, &ct); + ctype_get(cp->cts, lastid)->sib = constid; + lastid = constid; + ctype_setname(ct, name); + ct->info = CTINFO(CT_CONSTVAL, CTF_CONST|k.id); + ct->size = k.u32++; + if (k.u32 == 0x80000000u) k.id = CTID_UINT32; + lj_ctype_addname(cp->cts, ct, constid); + } + if (!cp_opt(cp, ',')) break; + } while (cp->tok != '}'); /* Trailing ',' is ok. */ + cp_check(cp, '}'); + /* Complete enum. */ + ctype_get(cp->cts, eid)->info = einfo; + ctype_get(cp->cts, eid)->size = esize; + } + return eid; +} + +/* Parse declaration specifiers. */ +static CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl) +{ + uint32_t cds = 0, sz = 0; + CTypeID tdef = 0; + + decl->cp = cp; + decl->mode = cp->mode; + decl->name = NULL; + decl->redir = NULL; + decl->attr = 0; + decl->fattr = 0; + decl->pos = decl->top = 0; + decl->stack[0].next = 0; + + for (;;) { /* Parse basic types. */ + cp_decl_attributes(cp, decl); + if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) { + uint32_t cbit; + if (cp->ct->size) { + if (sz) goto end_decl; + sz = cp->ct->size; + } + cbit = (1u << (cp->tok - CTOK_FIRSTDECL)); + cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1); + if (cp->tok >= CTOK_FIRSTSCL) { + if (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL); + } else if (tdef) { + goto end_decl; + } + cp_next(cp); + continue; + } + if (sz || tdef || + (cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX))) + break; + switch (cp->tok) { + case CTOK_STRUCT: + tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0)); + continue; + case CTOK_UNION: + tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION)); + continue; + case CTOK_ENUM: + tdef = cp_decl_enum(cp, decl); + continue; + case CTOK_IDENT: + if (ctype_istypedef(cp->ct->info)) { + tdef = ctype_cid(cp->ct->info); /* Get typedef. */ + cp_next(cp); + continue; + } + break; + case '$': + tdef = cp->val.id; + cp_next(cp); + continue; + default: + break; + } + break; + } +end_decl: + + if ((cds & CDF_COMPLEX)) /* Use predefined complex types. */ + tdef = sz == 4 ? CTID_COMPLEX_FLOAT : CTID_COMPLEX_DOUBLE; + + if (tdef) { + cp_push_type(decl, tdef); + } else if ((cds & CDF_VOID)) { + cp_push(decl, CTINFO(CT_VOID, (decl->attr & CTF_QUAL)), CTSIZE_INVALID); + decl->attr &= ~CTF_QUAL; + } else { + /* Determine type info and size. */ + CTInfo info = CTINFO(CT_NUM, (cds & CDF_UNSIGNED) ? CTF_UNSIGNED : 0); + if ((cds & CDF_BOOL)) { + if ((cds & ~(CDF_SCL|CDF_BOOL|CDF_INT|CDF_SIGNED|CDF_UNSIGNED))) + cp_errmsg(cp, 0, LJ_ERR_FFI_INVTYPE); + info |= CTF_BOOL; + if (!(cds & CDF_SIGNED)) info |= CTF_UNSIGNED; + if (!sz) { + sz = 1; + } + } else if ((cds & CDF_FP)) { + info = CTINFO(CT_NUM, CTF_FP); + if ((cds & CDF_LONG)) sz = sizeof(long double); + } else if ((cds & CDF_CHAR)) { + if ((cds & (CDF_CHAR|CDF_SIGNED|CDF_UNSIGNED)) == CDF_CHAR) + info |= CTF_UCHAR; /* Handle platforms where char is unsigned. */ + } else if ((cds & CDF_SHORT)) { + sz = sizeof(short); + } else if ((cds & CDF_LONGLONG)) { + sz = 8; + } else if ((cds & CDF_LONG)) { + info |= CTF_LONG; + sz = sizeof(long); + } else if (!sz) { + if (!(cds & (CDF_SIGNED|CDF_UNSIGNED))) + cp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC); + sz = sizeof(int); + } + lua_assert(sz != 0); + info += CTALIGN(lj_fls(sz)); /* Use natural alignment. */ + info += (decl->attr & CTF_QUAL); /* Merge qualifiers. */ + cp_push(decl, info, sz); + decl->attr &= ~CTF_QUAL; + } + decl->specpos = decl->pos; + decl->specattr = decl->attr; + decl->specfattr = decl->fattr; + return (cds & CDF_SCL); /* Return storage class. */ +} + +/* Parse array declaration. */ +static void cp_decl_array(CPState *cp, CPDecl *decl) +{ + CTInfo info = CTINFO(CT_ARRAY, 0); + CTSize nelem = CTSIZE_INVALID; /* Default size for a[] or a[?]. */ + cp_decl_attributes(cp, decl); + if (cp_opt(cp, '?')) + info |= CTF_VLA; /* Create variable-length array a[?]. */ + else if (cp->tok != ']') + nelem = cp_expr_ksize(cp); + cp_check(cp, ']'); + cp_add(decl, info, nelem); +} + +/* Parse function declaration. */ +static void cp_decl_func(CPState *cp, CPDecl *fdecl) +{ + CTSize nargs = 0; + CTInfo info = CTINFO(CT_FUNC, 0); + CTypeID lastid = 0, anchor = 0; + if (cp->tok != ')') { + do { + CPDecl decl; + CTypeID ctypeid, fieldid; + CType *ct; + if (cp_opt(cp, '.')) { /* Vararg function. */ + cp_check(cp, '.'); /* Workaround for the minimalistic lexer. */ + cp_check(cp, '.'); + info |= CTF_VARARG; + break; + } + cp_decl_spec(cp, &decl, CDF_REGISTER); + decl.mode = CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + ct = ctype_raw(cp->cts, ctypeid); + if (ctype_isvoid(ct->info)) + break; + else if (ctype_isrefarray(ct->info)) + ctypeid = lj_ctype_intern(cp->cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ct->info)), CTSIZE_PTR); + else if (ctype_isfunc(ct->info)) + ctypeid = lj_ctype_intern(cp->cts, + CTINFO(CT_PTR, CTALIGN_PTR|ctypeid), CTSIZE_PTR); + /* Add new parameter. */ + fieldid = lj_ctype_new(cp->cts, &ct); + if (anchor) + ctype_get(cp->cts, lastid)->sib = fieldid; + else + anchor = fieldid; + lastid = fieldid; + if (decl.name) ctype_setname(ct, decl.name); + ct->info = CTINFO(CT_FIELD, ctypeid); + ct->size = nargs++; + } while (cp_opt(cp, ',')); + } + cp_check(cp, ')'); + if (cp_opt(cp, '{')) { /* Skip function definition. */ + int level = 1; + cp->mode |= CPARSE_MODE_SKIP; + for (;;) { + if (cp->tok == '{') level++; + else if (cp->tok == '}' && --level == 0) break; + else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}'); + cp_next(cp); + } + cp->mode &= ~CPARSE_MODE_SKIP; + cp->tok = ';'; /* Ok for cp_decl_multi(), error in cp_decl_single(). */ + } + info |= (fdecl->fattr & ~CTMASK_CID); + fdecl->fattr = 0; + fdecl->stack[cp_add(fdecl, info, nargs)].sib = anchor; +} + +/* Parse declarator. */ +static void cp_declarator(CPState *cp, CPDecl *decl) +{ + if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS); + + for (;;) { /* Head of declarator. */ + if (cp_opt(cp, '*')) { /* Pointer. */ + CTSize sz; + CTInfo info; + cp_decl_attributes(cp, decl); + sz = CTSIZE_PTR; + info = CTINFO(CT_PTR, CTALIGN_PTR); +#if LJ_64 + if (ctype_msizeP(decl->attr) == 4) { + sz = 4; + info = CTINFO(CT_PTR, CTALIGN(2)); + } +#endif + info += (decl->attr & (CTF_QUAL|CTF_REF)); + decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<mode & CPARSE_MODE_ABSTRACT) && + (cp->tok == ')' || cp_istypedecl(cp))) goto func_decl; + pos = decl->pos; + cp_declarator(cp, decl); + cp_check(cp, ')'); + decl->pos = pos; + } else if (cp->tok == CTOK_IDENT) { /* Direct declarator. */ + if (!(decl->mode & CPARSE_MODE_DIRECT)) cp_err_token(cp, CTOK_EOF); + decl->name = cp->str; + decl->nameid = cp->val.id; + cp_next(cp); + } else { /* Abstract declarator. */ + if (!(decl->mode & CPARSE_MODE_ABSTRACT)) cp_err_token(cp, CTOK_IDENT); + } + + for (;;) { /* Tail of declarator. */ + if (cp_opt(cp, '[')) { /* Array. */ + cp_decl_array(cp, decl); + } else if (cp_opt(cp, '(')) { /* Function. */ + func_decl: + cp_decl_func(cp, decl); + } else { + break; + } + } + + if ((decl->mode & CPARSE_MODE_FIELD) && cp_opt(cp, ':')) /* Field width. */ + decl->bits = cp_expr_ksize(cp); + + /* Process postfix attributes. */ + cp_decl_attributes(cp, decl); + cp_push_attributes(decl); + + cp->depth--; +} + +/* Parse an abstract type declaration and return it's C type ID. */ +static CTypeID cp_decl_abstract(CPState *cp) +{ + CPDecl decl; + cp_decl_spec(cp, &decl, 0); + decl.mode = CPARSE_MODE_ABSTRACT; + cp_declarator(cp, &decl); + return cp_decl_intern(cp, &decl); +} + +/* Handle pragmas. */ +static void cp_pragma(CPState *cp, BCLine pragmaline) +{ + cp_next(cp); + if (cp->tok == CTOK_IDENT && + cp->str->hash == H_(e79b999f,42ca3e85)) { /* pack */ + cp_next(cp); + cp_check(cp, '('); + if (cp->tok == CTOK_IDENT) { + if (cp->str->hash == H_(738e923c,a1b65954)) { /* push */ + if (cp->curpack < CPARSE_MAX_PACKSTACK) { + cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack]; + cp->curpack++; + } + } else if (cp->str->hash == H_(6c71cf27,6c71cf27)) { /* pop */ + if (cp->curpack > 0) cp->curpack--; + } else { + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + } + cp_next(cp); + if (!cp_opt(cp, ',')) goto end_pack; + } + if (cp->tok == CTOK_INTEGER) { + cp->packstack[cp->curpack] = cp->val.u32 ? lj_fls(cp->val.u32) : 0; + cp_next(cp); + } else { + cp->packstack[cp->curpack] = 255; + } + end_pack: + cp_check(cp, ')'); + } else { /* Ignore all other pragmas. */ + while (cp->tok != CTOK_EOF && cp->linenumber == pragmaline) + cp_next(cp); + } +} + +/* Parse multiple C declarations of types or extern identifiers. */ +static void cp_decl_multi(CPState *cp) +{ + int first = 1; + while (cp->tok != CTOK_EOF) { + CPDecl decl; + CPscl scl; + if (cp_opt(cp, ';')) { /* Skip empty statements. */ + first = 0; + continue; + } + if (cp->tok == '#') { /* Workaround, since we have no preprocessor, yet. */ + BCLine pragmaline = cp->linenumber; + if (!(cp_next(cp) == CTOK_IDENT && + cp->str->hash == H_(f5e6b4f8,1d509107))) /* pragma */ + cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL); + cp_pragma(cp, pragmaline); + continue; + } + scl = cp_decl_spec(cp, &decl, CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC); + if ((cp->tok == ';' || cp->tok == CTOK_EOF) && + ctype_istypedef(decl.stack[0].info)) { + CTInfo info = ctype_rawchild(cp->cts, &decl.stack[0])->info; + if (ctype_isstruct(info) || ctype_isenum(info)) + goto decl_end; /* Accept empty declaration of struct/union/enum. */ + } + for (;;) { + CTypeID ctypeid; + cp_declarator(cp, &decl); + ctypeid = cp_decl_intern(cp, &decl); + if (decl.name && !decl.nameid) { /* NYI: redeclarations are ignored. */ + CType *ct; + CTypeID id; + if ((scl & CDF_TYPEDEF)) { /* Create new typedef. */ + id = lj_ctype_new(cp->cts, &ct); + ct->info = CTINFO(CT_TYPEDEF, ctypeid); + goto noredir; + } else if (ctype_isfunc(ctype_get(cp->cts, ctypeid)->info)) { + /* Treat both static and extern function declarations as extern. */ + ct = ctype_get(cp->cts, ctypeid); + /* We always get new anonymous functions (typedefs are copied). */ + lua_assert(gcref(ct->name) == NULL); + id = ctypeid; /* Just name it. */ + } else if ((scl & CDF_STATIC)) { /* Accept static constants. */ + id = cp_decl_constinit(cp, &ct, ctypeid); + goto noredir; + } else { /* External references have extern or no storage class. */ + id = lj_ctype_new(cp->cts, &ct); + ct->info = CTINFO(CT_EXTERN, ctypeid); + } + if (decl.redir) { /* Add attribute for redirected symbol name. */ + CType *cta; + CTypeID aid = lj_ctype_new(cp->cts, &cta); + ct = ctype_get(cp->cts, id); /* Table may have been reallocated. */ + cta->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_REDIR)); + cta->sib = ct->sib; + ct->sib = aid; + ctype_setname(cta, decl.redir); + } + noredir: + ctype_setname(ct, decl.name); + lj_ctype_addname(cp->cts, ct, id); + } + if (!cp_opt(cp, ',')) break; + cp_decl_reset(&decl); + } + decl_end: + if (cp->tok == CTOK_EOF && first) break; /* May omit ';' for 1 decl. */ + first = 0; + cp_check(cp, ';'); + } +} + +/* Parse a single C type declaration. */ +static void cp_decl_single(CPState *cp) +{ + CPDecl decl; + cp_decl_spec(cp, &decl, 0); + cp_declarator(cp, &decl); + cp->val.id = cp_decl_intern(cp, &decl); + if (cp->tok != CTOK_EOF) cp_err_token(cp, CTOK_EOF); +} + +#undef H_ + +/* ------------------------------------------------------------------------ */ + +/* Protected callback for C parser. */ +static TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud) +{ + CPState *cp = (CPState *)ud; + UNUSED(dummy); + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + cp_init(cp); + if ((cp->mode & CPARSE_MODE_MULTI)) + cp_decl_multi(cp); + else + cp_decl_single(cp); + if (cp->param && cp->param != cp->L->top) + cp_err(cp, LJ_ERR_FFI_NUMPARAM); + lua_assert(cp->depth == 0); + return NULL; +} + +/* C parser. */ +int lj_cparse(CPState *cp) +{ + LJ_CTYPE_SAVE(cp->cts); + int errcode = lj_vm_cpcall(cp->L, NULL, cp, cpcparser); + if (errcode) + LJ_CTYPE_RESTORE(cp->cts); + cp_cleanup(cp); + return errcode; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.h new file mode 100644 index 0000000..586f494 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_cparse.h @@ -0,0 +1,65 @@ +/* +** C declaration parser. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CPARSE_H +#define _LJ_CPARSE_H + +#include "lj_obj.h" +#include "lj_ctype.h" + +#if LJ_HASFFI + +/* C parser limits. */ +#define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */ +#define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */ +#define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */ +#define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */ + +/* Flags for C parser mode. */ +#define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */ +#define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */ +#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */ +#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */ +#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */ +#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */ + +typedef int CPChar; /* C parser character. Unsigned ext. from char. */ +typedef int CPToken; /* C parser token. */ + +/* C parser internal value representation. */ +typedef struct CPValue { + union { + int32_t i32; /* Value for CTID_INT32. */ + uint32_t u32; /* Value for CTID_UINT32. */ + }; + CTypeID id; /* C Type ID of the value. */ +} CPValue; + +/* C parser state. */ +typedef struct CPState { + CPChar c; /* Current character. */ + CPToken tok; /* Current token. */ + CPValue val; /* Token value. */ + GCstr *str; /* Interned string of identifier/keyword. */ + CType *ct; /* C type table entry. */ + const char *p; /* Current position in input buffer. */ + SBuf sb; /* String buffer for tokens. */ + lua_State *L; /* Lua state. */ + CTState *cts; /* C type state. */ + TValue *param; /* C type parameters. */ + const char *srcname; /* Current source name. */ + BCLine linenumber; /* Input line counter. */ + int depth; /* Recursive declaration depth. */ + uint32_t tmask; /* Type mask for next identifier. */ + uint32_t mode; /* C parser mode. */ + uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */ + uint8_t curpack; /* Current position in pack pragma stack. */ +} CPState; + +LJ_FUNC int lj_cparse(CPState *cp); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.c new file mode 100644 index 0000000..da9013f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.c @@ -0,0 +1,1653 @@ +/* +** Trace recorder for C data operations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ffrecord_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT && LJ_HASFFI + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_cparse.h" +#include "lj_cconv.h" +#include "lj_clib.h" +#include "lj_ccall.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_snap.h" +#include "lj_crecord.h" +#include "lj_dispatch.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +#define emitconv(a, dt, st, flags) \ + emitir(IRT(IR_CONV, (dt)), (a), (st)|((dt) << 5)|(flags)) + +/* -- C type checks ------------------------------------------------------- */ + +static GCcdata *argv2cdata(jit_State *J, TRef tr, cTValue *o) +{ + GCcdata *cd; + TRef trtypeid; + if (!tref_iscdata(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + cd = cdataV(o); + /* Specialize to the CTypeID. */ + trtypeid = emitir(IRT(IR_FLOAD, IRT_U16), tr, IRFL_CDATA_CTYPEID); + emitir(IRTG(IR_EQ, IRT_INT), trtypeid, lj_ir_kint(J, (int32_t)cd->ctypeid)); + return cd; +} + +/* Specialize to the CTypeID held by a cdata constructor. */ +static CTypeID crec_constructor(jit_State *J, GCcdata *cd, TRef tr) +{ + CTypeID id; + lua_assert(tref_iscdata(tr) && cd->ctypeid == CTID_CTYPEID); + id = *(CTypeID *)cdataptr(cd); + tr = emitir(IRT(IR_FLOAD, IRT_INT), tr, IRFL_CDATA_INT); + emitir(IRTG(IR_EQ, IRT_INT), tr, lj_ir_kint(J, (int32_t)id)); + return id; +} + +static CTypeID argv2ctype(jit_State *J, TRef tr, cTValue *o) +{ + if (tref_isstr(tr)) { + GCstr *s = strV(o); + CPState cp; + CTypeID oldtop; + /* Specialize to the string containing the C type declaration. */ + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, s)); + cp.L = J->L; + cp.cts = ctype_ctsG(J2G(J)); + oldtop = cp.cts->top; + cp.srcname = strdata(s); + cp.p = strdata(s); + cp.param = NULL; + cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT; + if (lj_cparse(&cp) || cp.cts->top > oldtop) /* Avoid new struct defs. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + return cp.val.id; + } else { + GCcdata *cd = argv2cdata(J, tr, o); + return cd->ctypeid == CTID_CTYPEID ? crec_constructor(J, cd, tr) : + cd->ctypeid; + } +} + +/* Convert CType to IRType (if possible). */ +static IRType crec_ct2irt(CTState *cts, CType *ct) +{ + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (LJ_LIKELY(ctype_isnum(ct->info))) { + if ((ct->info & CTF_FP)) { + if (ct->size == sizeof(double)) + return IRT_NUM; + else if (ct->size == sizeof(float)) + return IRT_FLOAT; + } else { + uint32_t b = lj_fls(ct->size); + if (b <= 3) + return IRT_I8 + 2*b + ((ct->info & CTF_UNSIGNED) ? 1 : 0); + } + } else if (ctype_isptr(ct->info)) { + return (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + } else if (ctype_iscomplex(ct->info)) { + if (ct->size == 2*sizeof(double)) + return IRT_NUM; + else if (ct->size == 2*sizeof(float)) + return IRT_FLOAT; + } + return IRT_CDATA; +} + +/* -- Optimized memory fill and copy -------------------------------------- */ + +/* Maximum length and unroll of inlined copy/fill. */ +#define CREC_COPY_MAXUNROLL 16 +#define CREC_COPY_MAXLEN 128 + +#define CREC_FILL_MAXUNROLL 16 + +/* Number of windowed registers used for optimized memory copy. */ +#if LJ_TARGET_X86 +#define CREC_COPY_REGWIN 2 +#elif LJ_TARGET_PPC || LJ_TARGET_MIPS +#define CREC_COPY_REGWIN 8 +#else +#define CREC_COPY_REGWIN 4 +#endif + +/* List of memory offsets for copy/fill. */ +typedef struct CRecMemList { + CTSize ofs; /* Offset in bytes. */ + IRType tp; /* Type of load/store. */ + TRef trofs; /* TRef of interned offset. */ + TRef trval; /* TRef of load value. */ +} CRecMemList; + +/* Generate copy list for element-wise struct copy. */ +static MSize crec_copy_struct(CRecMemList *ml, CTState *cts, CType *ct) +{ + CTypeID fid = ct->sib; + MSize mlp = 0; + while (fid) { + CType *df = ctype_get(cts, fid); + fid = df->sib; + if (ctype_isfield(df->info)) { + CType *cct; + IRType tp; + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + cct = ctype_rawchild(cts, df); /* Field type. */ + tp = crec_ct2irt(cts, cct); + if (tp == IRT_CDATA) return 0; /* NYI: aggregates. */ + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = df->size; + ml[mlp].tp = tp; + mlp++; + if (ctype_iscomplex(cct->info)) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = df->size + (cct->size >> 1); + ml[mlp].tp = tp; + mlp++; + } + } else if (!ctype_isconstval(df->info)) { + /* NYI: bitfields and sub-structures. */ + return 0; + } + } + return mlp; +} + +/* Generate unrolled copy list, from highest to lowest step size/alignment. */ +static MSize crec_copy_unroll(CRecMemList *ml, CTSize len, CTSize step, + IRType tp) +{ + CTSize ofs = 0; + MSize mlp = 0; + if (tp == IRT_CDATA) tp = IRT_U8 + 2*lj_fls(step); + do { + while (ofs + step <= len) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = ofs; + ml[mlp].tp = tp; + mlp++; + ofs += step; + } + step >>= 1; + tp -= 2; + } while (ofs < len); + return mlp; +} + +/* +** Emit copy list with windowed loads/stores. +** LJ_TARGET_UNALIGNED: may emit unaligned loads/stores (not marked as such). +*/ +static void crec_copy_emit(jit_State *J, CRecMemList *ml, MSize mlp, + TRef trdst, TRef trsrc) +{ + MSize i, j, rwin = 0; + for (i = 0, j = 0; i < mlp; ) { + TRef trofs = lj_ir_kintp(J, ml[i].ofs); + TRef trsptr = emitir(IRT(IR_ADD, IRT_PTR), trsrc, trofs); + ml[i].trval = emitir(IRT(IR_XLOAD, ml[i].tp), trsptr, 0); + ml[i].trofs = trofs; + i++; + rwin += (LJ_SOFTFP && ml[i].tp == IRT_NUM) ? 2 : 1; + if (rwin >= CREC_COPY_REGWIN || i >= mlp) { /* Flush buffered stores. */ + rwin = 0; + for ( ; j < i; j++) { + TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, ml[j].trofs); + emitir(IRT(IR_XSTORE, ml[j].tp), trdptr, ml[j].trval); + } + } + } +} + +/* Optimized memory copy. */ +static void crec_copy(jit_State *J, TRef trdst, TRef trsrc, TRef trlen, + CType *ct) +{ + if (tref_isk(trlen)) { /* Length must be constant. */ + CRecMemList ml[CREC_COPY_MAXUNROLL]; + MSize mlp = 0; + CTSize step = 1, len = (CTSize)IR(tref_ref(trlen))->i; + IRType tp = IRT_CDATA; + int needxbar = 0; + if (len == 0) return; /* Shortcut. */ + if (len > CREC_COPY_MAXLEN) goto fallback; + if (ct) { + CTState *cts = ctype_ctsG(J2G(J)); + lua_assert(ctype_isarray(ct->info) || ctype_isstruct(ct->info)); + if (ctype_isarray(ct->info)) { + CType *cct = ctype_rawchild(cts, ct); + tp = crec_ct2irt(cts, cct); + if (tp == IRT_CDATA) goto rawcopy; + step = lj_ir_type_size[tp]; + lua_assert((len & (step-1)) == 0); + } else if ((ct->info & CTF_UNION)) { + step = (1u << ctype_align(ct->info)); + goto rawcopy; + } else { + mlp = crec_copy_struct(ml, cts, ct); + goto emitcopy; + } + } else { + rawcopy: + needxbar = 1; + if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR) + step = CTSIZE_PTR; + } + mlp = crec_copy_unroll(ml, len, step, tp); + emitcopy: + if (mlp) { + crec_copy_emit(J, ml, mlp, trdst, trsrc); + if (needxbar) + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); + return; + } + } +fallback: + /* Call memcpy. Always needs a barrier to disable alias analysis. */ + lj_ir_call(J, IRCALL_memcpy, trdst, trsrc, trlen); + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); +} + +/* Generate unrolled fill list, from highest to lowest step size/alignment. */ +static MSize crec_fill_unroll(CRecMemList *ml, CTSize len, CTSize step) +{ + CTSize ofs = 0; + MSize mlp = 0; + IRType tp = IRT_U8 + 2*lj_fls(step); + do { + while (ofs + step <= len) { + if (mlp >= CREC_COPY_MAXUNROLL) return 0; + ml[mlp].ofs = ofs; + ml[mlp].tp = tp; + mlp++; + ofs += step; + } + step >>= 1; + tp -= 2; + } while (ofs < len); + return mlp; +} + +/* +** Emit stores for fill list. +** LJ_TARGET_UNALIGNED: may emit unaligned stores (not marked as such). +*/ +static void crec_fill_emit(jit_State *J, CRecMemList *ml, MSize mlp, + TRef trdst, TRef trfill) +{ + MSize i; + for (i = 0; i < mlp; i++) { + TRef trofs = lj_ir_kintp(J, ml[i].ofs); + TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, trofs); + emitir(IRT(IR_XSTORE, ml[i].tp), trdptr, trfill); + } +} + +/* Optimized memory fill. */ +static void crec_fill(jit_State *J, TRef trdst, TRef trlen, TRef trfill, + CTSize step) +{ + if (tref_isk(trlen)) { /* Length must be constant. */ + CRecMemList ml[CREC_FILL_MAXUNROLL]; + MSize mlp; + CTSize len = (CTSize)IR(tref_ref(trlen))->i; + if (len == 0) return; /* Shortcut. */ + if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR) + step = CTSIZE_PTR; + if (step * CREC_FILL_MAXUNROLL < len) goto fallback; + mlp = crec_fill_unroll(ml, len, step); + if (!mlp) goto fallback; + if (tref_isk(trfill) || ml[0].tp != IRT_U8) + trfill = emitconv(trfill, IRT_INT, IRT_U8, 0); + if (ml[0].tp != IRT_U8) { /* Scatter U8 to U16/U32/U64. */ + if (CTSIZE_PTR == 8 && ml[0].tp == IRT_U64) { + if (tref_isk(trfill)) /* Pointless on x64 with zero-extended regs. */ + trfill = emitconv(trfill, IRT_U64, IRT_U32, 0); + trfill = emitir(IRT(IR_MUL, IRT_U64), trfill, + lj_ir_kint64(J, U64x(01010101,01010101))); + } else { + trfill = emitir(IRTI(IR_MUL), trfill, + lj_ir_kint(J, ml[0].tp == IRT_U16 ? 0x0101 : 0x01010101)); + } + } + crec_fill_emit(J, ml, mlp, trdst, trfill); + } else { +fallback: + /* Call memset. Always needs a barrier to disable alias analysis. */ + lj_ir_call(J, IRCALL_memset, trdst, trfill, trlen); /* Note: arg order! */ + } + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); +} + +/* -- Convert C type to C type -------------------------------------------- */ + +/* +** This code mirrors the code in lj_cconv.c. It performs the same steps +** for the trace recorder that lj_cconv.c does for the interpreter. +** +** One major difference is that we can get away with much fewer checks +** here. E.g. checks for casts, constness or correct types can often be +** omitted, even if they might fail. The interpreter subsequently throws +** an error, which aborts the trace. +** +** All operations are specialized to their C types, so the on-trace +** outcome must be the same as the outcome in the interpreter. If the +** interpreter doesn't throw an error, then the trace is correct, too. +** Care must be taken not to generate invalid (temporary) IR or to +** trigger asserts. +*/ + +/* Determine whether a passed number or cdata number is non-zero. */ +static int crec_isnonzero(CType *s, void *p) +{ + if (p == (void *)0) + return 0; + if (p == (void *)1) + return 1; + if ((s->info & CTF_FP)) { + if (s->size == sizeof(float)) + return (*(float *)p != 0); + else + return (*(double *)p != 0); + } else { + if (s->size == 1) + return (*(uint8_t *)p != 0); + else if (s->size == 2) + return (*(uint16_t *)p != 0); + else if (s->size == 4) + return (*(uint32_t *)p != 0); + else + return (*(uint64_t *)p != 0); + } +} + +static TRef crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp, + void *svisnz) +{ + IRType dt = crec_ct2irt(ctype_ctsG(J2G(J)), d); + IRType st = crec_ct2irt(ctype_ctsG(J2G(J)), s); + CTSize dsize = d->size, ssize = s->size; + CTInfo dinfo = d->info, sinfo = s->info; + + if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT) + goto err_conv; + + /* + ** Note: Unlike lj_cconv_ct_ct(), sp holds the _value_ of pointers and + ** numbers up to 8 bytes. Otherwise sp holds a pointer. + */ + + switch (cconv_idx2(dinfo, sinfo)) { + /* Destination is a bool. */ + case CCX(B, B): + goto xstore; /* Source operand is already normalized. */ + case CCX(B, I): + case CCX(B, F): + if (st != IRT_CDATA) { + /* Specialize to the result of a comparison against 0. */ + TRef zero = (st == IRT_NUM || st == IRT_FLOAT) ? lj_ir_knum(J, 0) : + (st == IRT_I64 || st == IRT_U64) ? lj_ir_kint64(J, 0) : + lj_ir_kint(J, 0); + int isnz = crec_isnonzero(s, svisnz); + emitir(IRTG(isnz ? IR_NE : IR_EQ, st), sp, zero); + sp = lj_ir_kint(J, isnz); + goto xstore; + } + goto err_nyi; + + /* Destination is an integer. */ + case CCX(I, B): + case CCX(I, I): + conv_I_I: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + /* Extend 32 to 64 bit integer. */ + if (dsize == 8 && ssize < 8 && !(LJ_64 && (sinfo & CTF_UNSIGNED))) + sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, + (sinfo & CTF_UNSIGNED) ? 0 : IRCONV_SEXT); + else if (dsize < 8 && ssize == 8) /* Truncate from 64 bit integer. */ + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, 0); + else if (st == IRT_INT) + sp = lj_opt_narrow_toint(J, sp); + xstore: + if (dt == IRT_I64 || dt == IRT_U64) lj_needsplit(J); + if (dp == 0) return sp; + emitir(IRT(IR_XSTORE, dt), dp, sp); + break; + case CCX(I, C): + sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */ + /* fallthrough */ + case CCX(I, F): + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, IRCONV_TRUNC|IRCONV_ANY); + goto xstore; + case CCX(I, P): + case CCX(I, A): + sinfo = CTINFO(CT_NUM, CTF_UNSIGNED); + ssize = CTSIZE_PTR; + st = IRT_UINTP; + if (((dsize ^ ssize) & 8) == 0) { /* Must insert no-op type conversion. */ + sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, IRT_PTR, 0); + goto xstore; + } + goto conv_I_I; + + /* Destination is a floating-point number. */ + case CCX(F, B): + case CCX(F, I): + conv_F_I: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, 0); + goto xstore; + case CCX(F, C): + sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */ + /* fallthrough */ + case CCX(F, F): + conv_F_F: + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + if (dt != st) sp = emitconv(sp, dt, st, 0); + goto xstore; + + /* Destination is a complex number. */ + case CCX(C, I): + case CCX(C, F): + { /* Clear im. */ + TRef ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1))); + emitir(IRT(IR_XSTORE, dt), ptr, lj_ir_knum(J, 0)); + } + /* Convert to re. */ + if ((sinfo & CTF_FP)) goto conv_F_F; else goto conv_F_I; + + case CCX(C, C): + if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi; + { + TRef re, im, ptr; + re = emitir(IRT(IR_XLOAD, st), sp, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, (ssize >> 1))); + im = emitir(IRT(IR_XLOAD, st), ptr, 0); + if (dt != st) { + re = emitconv(re, dt, st, 0); + im = emitconv(im, dt, st, 0); + } + emitir(IRT(IR_XSTORE, dt), dp, re); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1))); + emitir(IRT(IR_XSTORE, dt), ptr, im); + } + break; + + /* Destination is a vector. */ + case CCX(V, I): + case CCX(V, F): + case CCX(V, C): + case CCX(V, V): + goto err_nyi; + + /* Destination is a pointer. */ + case CCX(P, P): + case CCX(P, A): + case CCX(P, S): + /* There are only 32 bit pointers/addresses on 32 bit machines. + ** Also ok on x64, since all 32 bit ops clear the upper part of the reg. + */ + goto xstore; + case CCX(P, I): + if (st == IRT_CDATA) goto err_nyi; + if (!LJ_64 && ssize == 8) /* Truncate from 64 bit integer. */ + sp = emitconv(sp, IRT_U32, st, 0); + goto xstore; + case CCX(P, F): + if (st == IRT_CDATA) goto err_nyi; + /* The signed conversion is cheaper. x64 really has 47 bit pointers. */ + sp = emitconv(sp, (LJ_64 && dsize == 8) ? IRT_I64 : IRT_U32, + st, IRCONV_TRUNC|IRCONV_ANY); + goto xstore; + + /* Destination is an array. */ + case CCX(A, A): + /* Destination is a struct/union. */ + case CCX(S, S): + if (dp == 0) goto err_conv; + crec_copy(J, dp, sp, lj_ir_kint(J, dsize), d); + break; + + default: + err_conv: + err_nyi: + lj_trace_err(J, LJ_TRERR_NYICONV); + break; + } + return 0; +} + +/* -- Convert C type to TValue (load) ------------------------------------- */ + +static TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp) +{ + CTState *cts = ctype_ctsG(J2G(J)); + IRType t = crec_ct2irt(cts, s); + CTInfo sinfo = s->info; + if (ctype_isnum(sinfo)) { + TRef tr; + if (t == IRT_CDATA) + goto err_nyi; /* NYI: copyval of >64 bit integers. */ + tr = emitir(IRT(IR_XLOAD, t), sp, 0); + if (t == IRT_FLOAT || t == IRT_U32) { /* Keep uint32_t/float as numbers. */ + return emitconv(tr, IRT_NUM, t, 0); + } else if (t == IRT_I64 || t == IRT_U64) { /* Box 64 bit integer. */ + sp = tr; + lj_needsplit(J); + } else if ((sinfo & CTF_BOOL)) { + /* Assume not equal to zero. Fixup and emit pending guard later. */ + lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } else { + return tr; + } + } else if (ctype_isptr(sinfo) || ctype_isenum(sinfo)) { + sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Box pointers and enums. */ + } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { + cts->L = J->L; + sid = lj_ctype_intern(cts, CTINFO_REF(sid), CTSIZE_PTR); /* Create ref. */ + } else if (ctype_iscomplex(sinfo)) { /* Unbox/box complex. */ + ptrdiff_t esz = (ptrdiff_t)(s->size >> 1); + TRef ptr, tr1, tr2, dp; + dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL); + tr1 = emitir(IRT(IR_XLOAD, t), sp, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz)); + tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata))); + emitir(IRT(IR_XSTORE, t), ptr, tr1); + ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)+esz)); + emitir(IRT(IR_XSTORE, t), ptr, tr2); + return dp; + } else { + /* NYI: copyval of vectors. */ + err_nyi: + lj_trace_err(J, LJ_TRERR_NYICONV); + } + /* Box pointer, ref, enum or 64 bit integer. */ + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, sid), sp); +} + +/* -- Convert TValue to C type (store) ------------------------------------ */ + +static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CTypeID sid = CTID_P_VOID; + void *svisnz = 0; + CType *s; + if (LJ_LIKELY(tref_isinteger(sp))) { + sid = CTID_INT32; + svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval)); + } else if (tref_isnum(sp)) { + sid = CTID_DOUBLE; + svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval)); + } else if (tref_isbool(sp)) { + sp = lj_ir_kint(J, tref_istrue(sp) ? 1 : 0); + sid = CTID_BOOL; + } else if (tref_isnil(sp)) { + sp = lj_ir_kptr(J, NULL); + } else if (tref_isudata(sp)) { + GCudata *ud = udataV(sval); + if (ud->udtype == UDTYPE_IO_FILE) { + TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); + sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_UDATA_FILE); + } else { + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCudata))); + } + } else if (tref_isstr(sp)) { + if (ctype_isenum(d->info)) { /* Match string against enum constant. */ + GCstr *str = strV(sval); + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, d, str, &ofs); + /* Specialize to the name of the enum constant. */ + emitir(IRTG(IR_EQ, IRT_STR), sp, lj_ir_kstr(J, str)); + if (cct && ctype_isconstval(cct->info)) { + lua_assert(ctype_child(cts, cct)->size == 4); + svisnz = (void *)(intptr_t)(ofs != 0); + sp = lj_ir_kint(J, (int32_t)ofs); + sid = ctype_cid(cct->info); + } /* else: interpreter will throw. */ + } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); /* NYI */ + } else { /* Otherwise pass the string data as a const char[]. */ + /* Don't use STRREF. It folds with SNEW, which loses the trailing NUL. */ + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCstr))); + sid = CTID_A_CCHAR; + } + } else { /* NYI: tref_istab(sp), tref_islightud(sp). */ + IRType t; + sid = argv2cdata(J, sp, sval)->ctypeid; + s = ctype_raw(cts, sid); + svisnz = cdataptr(cdataV(sval)); + t = crec_ct2irt(cts, s); + if (ctype_isptr(s->info)) { + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR); + if (ctype_isref(s->info)) { + svisnz = *(void **)svisnz; + s = ctype_rawchild(cts, s); + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + t = crec_ct2irt(cts, s); + } else { + goto doconv; + } + } else if (t == IRT_I64 || t == IRT_U64) { + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64); + lj_needsplit(J); + goto doconv; + } else if (t == IRT_INT || t == IRT_U32) { + if (ctype_isenum(s->info)) s = ctype_child(cts, s); + sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT); + goto doconv; + } else { + sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata))); + } + if (ctype_isnum(s->info) && t != IRT_CDATA) + sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Load number value. */ + goto doconv; + } + s = ctype_get(cts, sid); +doconv: + if (ctype_isenum(d->info)) d = ctype_child(cts, d); + return crec_ct_ct(J, d, s, dp, sp, svisnz); +} + +/* -- C data metamethods -------------------------------------------------- */ + +/* This would be rather difficult in FOLD, so do it here: +** (base+k)+(idx*sz)+ofs ==> (base+idx*sz)+(ofs+k) +** (base+(idx+k)*sz)+ofs ==> (base+idx*sz)+(ofs+k*sz) +*/ +static TRef crec_reassoc_ofs(jit_State *J, TRef tr, ptrdiff_t *ofsp, MSize sz) +{ + IRIns *ir = IR(tref_ref(tr)); + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && irref_isk(ir->op2) && + (ir->o == IR_ADD || ir->o == IR_ADDOV || ir->o == IR_SUBOV)) { + IRIns *irk = IR(ir->op2); + ptrdiff_t k; + if (LJ_64 && irk->o == IR_KINT64) + k = (ptrdiff_t)ir_kint64(irk)->u64 * sz; + else + k = (ptrdiff_t)irk->i * sz; + if (ir->o == IR_SUBOV) *ofsp -= k; else *ofsp += k; + tr = ir->op1; /* Not a TRef, but the caller doesn't care. */ + } + return tr; +} + +/* Record ctype __index/__newindex metamethods. */ +static void crec_index_meta(jit_State *J, CTState *cts, CType *ct, + RecordFFData *rd) +{ + CTypeID id = ctype_typeid(cts, ct); + cTValue *tv = lj_ctype_meta(cts, id, rd->data ? MM_newindex : MM_index); + if (!tv) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + } else if (rd->data == 0 && tvistab(tv) && tref_isstr(J->base[1])) { + /* Specialize to result of __index lookup. */ + cTValue *o = lj_tab_get(J->L, tabV(tv), &rd->argv[1]); + J->base[0] = lj_record_constify(J, o); + if (!J->base[0]) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* Always specialize to the key. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1]))); + } else { + /* NYI: resolving of non-function metamethods. */ + /* NYI: non-string keys for __index table. */ + /* NYI: stores to __newindex table. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + } +} + +void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) +{ + TRef idx, ptr = J->base[0]; + ptrdiff_t ofs = sizeof(GCcdata); + GCcdata *cd = argv2cdata(J, ptr, &rd->argv[0]); + CTState *cts = ctype_ctsG(J2G(J)); + CType *ct = ctype_raw(cts, cd->ctypeid); + CTypeID sid = 0; + + /* Resolve pointer or reference for cdata object. */ + if (ctype_isptr(ct->info)) { + IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); + ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR); + ofs = 0; + ptr = crec_reassoc_ofs(J, ptr, &ofs, 1); + } + +again: + idx = J->base[1]; + if (tref_isnumber(idx)) { + idx = lj_opt_narrow_cindex(J, idx); + if (ctype_ispointer(ct->info)) { + CTSize sz; + integer_key: + if ((ct->info & CTF_COMPLEX)) + idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1)); + sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info))); + idx = crec_reassoc_ofs(J, idx, &ofs, sz); +#if LJ_TARGET_ARM || LJ_TARGET_PPC + /* Hoist base add to allow fusion of index/shift into operands. */ + if (LJ_LIKELY(J->flags & JIT_F_OPT_LOOP) && ofs +#if LJ_TARGET_ARM + && (sz == 1 || sz == 4) +#endif + ) { + ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs)); + ofs = 0; + } +#endif + idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz)); + ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr); + } + } else if (tref_iscdata(idx)) { + GCcdata *cdk = cdataV(&rd->argv[1]); + CType *ctk = ctype_raw(cts, cdk->ctypeid); + IRType t = crec_ct2irt(cts, ctk); + if (ctype_ispointer(ct->info) && t >= IRT_I8 && t <= IRT_U64) { + if (ctk->size == 8) { + idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT64); + } else if (ctk->size == 4) { + idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT); + } else { + idx = emitir(IRT(IR_ADD, IRT_PTR), idx, + lj_ir_kintp(J, sizeof(GCcdata))); + idx = emitir(IRT(IR_XLOAD, t), idx, 0); + } + if (LJ_64 && ctk->size < sizeof(intptr_t) && !(ctk->info & CTF_UNSIGNED)) + idx = emitconv(idx, IRT_INTP, IRT_INT, IRCONV_SEXT); + if (!LJ_64 && ctk->size > sizeof(intptr_t)) { + idx = emitconv(idx, IRT_INTP, t, 0); + lj_needsplit(J); + } + goto integer_key; + } + } else if (tref_isstr(idx)) { + GCstr *name = strV(&rd->argv[1]); + if (cd->ctypeid == CTID_CTYPEID) + ct = ctype_raw(cts, crec_constructor(J, cd, ptr)); + if (ctype_isstruct(ct->info)) { + CTSize fofs; + CType *fct; + fct = lj_ctype_getfield(cts, ct, name, &fofs); + if (fct) { + /* Always specialize to the field name. */ + emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); + if (ctype_isconstval(fct->info)) { + if (fct->size >= 0x80000000u && + (ctype_child(cts, fct)->info & CTF_UNSIGNED)) { + J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)fct->size); + return; + } + J->base[0] = lj_ir_kint(J, (int32_t)fct->size); + return; /* Interpreter will throw for newindex. */ + } else if (ctype_isbitfield(fct->info)) { + lj_trace_err(J, LJ_TRERR_NYICONV); + } else { + lua_assert(ctype_isfield(fct->info)); + sid = ctype_cid(fct->info); + } + ofs += (ptrdiff_t)fofs; + } + } else if (ctype_iscomplex(ct->info)) { + if (name->len == 2 && + ((strdata(name)[0] == 'r' && strdata(name)[1] == 'e') || + (strdata(name)[0] == 'i' && strdata(name)[1] == 'm'))) { + /* Always specialize to the field name. */ + emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); + if (strdata(name)[0] == 'i') ofs += (ct->size >> 1); + sid = ctype_cid(ct->info); + } + } + } + if (!sid) { + if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ + CType *cct = ctype_rawchild(cts, ct); + if (ctype_isstruct(cct->info)) { + ct = cct; + if (tref_isstr(idx)) goto again; + } + } + crec_index_meta(J, cts, ct, rd); + return; + } + + if (ofs) + ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs)); + + /* Resolve reference for field. */ + ct = ctype_get(cts, sid); + if (ctype_isref(ct->info)) + ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0); + + while (ctype_isattrib(ct->info)) + ct = ctype_child(cts, ct); /* Skip attributes. */ + + if (rd->data == 0) { /* __index metamethod. */ + J->base[0] = crec_tv_ct(J, ct, sid, ptr); + } else { /* __newindex metamethod. */ + rd->nres = 0; + J->needsnap = 1; + crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]); + } +} + +/* Record setting a finalizer. */ +static void crec_finalizer(jit_State *J, TRef trcd, cTValue *fin) +{ + TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd); + TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4)); + if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; } + if (tvisfunc(fin)) { + emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin))); + emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC)); + } else if (tviscdata(fin)) { + emitir(IRT(IR_XSTORE, IRT_P32), trlo, + lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA)); + emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA)); + } else { + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + J->needsnap = 1; +} + +/* Record cdata allocation. */ +static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CTSize sz; + CTInfo info = lj_ctype_info(cts, id, &sz); + CType *d = ctype_raw(cts, id); + TRef trid; + if (!sz || sz > 128 || (info & CTF_VLA) || ctype_align(info) > CT_MEMALIGN) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: large/special allocations. */ + trid = lj_ir_kint(J, id); + /* Use special instruction to box pointer or 32/64 bit integer. */ + if (ctype_isptr(info) || (ctype_isinteger(info) && (sz == 4 || sz == 8))) { + TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) : + ctype_isptr(info) ? lj_ir_kptr(J, NULL) : + sz == 4 ? lj_ir_kint(J, 0) : + (lj_needsplit(J), lj_ir_kint64(J, 0)); + J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, sp); + } else { + TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL); + cTValue *fin; + J->base[0] = trcd; + if (J->base[1] && !J->base[2] && + !lj_cconv_multi_init(cts, d, &rd->argv[1])) { + goto single_init; + } else if (ctype_isarray(d->info)) { + CType *dc = ctype_rawchild(cts, d); /* Array element type. */ + CTSize ofs, esize = dc->size; + TRef sp = 0; + TValue tv; + TValue *sval = &tv; + MSize i; + tv.u64 = 0; + if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info))) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init array of aggregates. */ + for (i = 1, ofs = 0; ofs < sz; ofs += esize) { + TRef dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, + lj_ir_kintp(J, ofs + sizeof(GCcdata))); + if (J->base[i]) { + sp = J->base[i]; + sval = &rd->argv[i]; + i++; + } else if (i != 2) { + sp = ctype_isnum(dc->info) ? lj_ir_kint(J, 0) : TREF_NIL; + } + crec_ct_tv(J, dc, dp, sp, sval); + } + } else if (ctype_isstruct(d->info)) { + CTypeID fid = d->sib; + MSize i = 1; + while (fid) { + CType *df = ctype_get(cts, fid); + fid = df->sib; + if (ctype_isfield(df->info)) { + CType *dc; + TRef sp, dp; + TValue tv; + TValue *sval = &tv; + setintV(&tv, 0); + if (!gcref(df->name)) continue; /* Ignore unnamed fields. */ + dc = ctype_rawchild(cts, df); /* Field type. */ + if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) || + ctype_isenum(dc->info))) + lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init aggregates. */ + if (J->base[i]) { + sp = J->base[i]; + sval = &rd->argv[i]; + i++; + } else { + sp = ctype_isptr(dc->info) ? TREF_NIL : lj_ir_kint(J, 0); + } + dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, + lj_ir_kintp(J, df->size + sizeof(GCcdata))); + crec_ct_tv(J, dc, dp, sp, sval); + } else if (!ctype_isconstval(df->info)) { + /* NYI: init bitfields and sub-structures. */ + lj_trace_err(J, LJ_TRERR_NYICONV); + } + } + } else { + TRef dp; + single_init: + dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata))); + if (J->base[1]) { + crec_ct_tv(J, d, dp, J->base[1], &rd->argv[1]); + } else { + TValue tv; + tv.u64 = 0; + crec_ct_tv(J, d, dp, lj_ir_kint(J, 0), &tv); + } + } + /* Handle __gc metamethod. */ + fin = lj_ctype_meta(cts, id, MM_gc); + if (fin) + crec_finalizer(J, trcd, fin); + } +} + +/* Record argument conversions. */ +static TRef crec_call_args(jit_State *J, RecordFFData *rd, + CTState *cts, CType *ct) +{ + TRef args[CCI_NARGS_MAX]; + CTypeID fid; + MSize i, n; + TRef tr, *base; + cTValue *o; +#if LJ_TARGET_X86 +#if LJ_ABI_WIN + TRef *arg0 = NULL, *arg1 = NULL; +#endif + int ngpr = 0; + if (ctype_cconv(ct->info) == CTCC_THISCALL) + ngpr = 1; + else if (ctype_cconv(ct->info) == CTCC_FASTCALL) + ngpr = 2; +#endif + + /* Skip initial attributes. */ + fid = ct->sib; + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (!ctype_isattrib(ctf->info)) break; + fid = ctf->sib; + } + args[0] = TREF_NIL; + for (n = 0, base = J->base+1, o = rd->argv+1; *base; n++, base++, o++) { + CTypeID did; + CType *d; + + if (n >= CCI_NARGS_MAX) + lj_trace_err(J, LJ_TRERR_NYICALL); + + if (fid) { /* Get argument type from field. */ + CType *ctf = ctype_get(cts, fid); + fid = ctf->sib; + lua_assert(ctype_isfield(ctf->info)); + did = ctype_cid(ctf->info); + } else { + if (!(ct->info & CTF_VARARG)) + lj_trace_err(J, LJ_TRERR_NYICALL); /* Too many arguments. */ + did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */ + } + d = ctype_raw(cts, did); + if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || + ctype_isenum(d->info))) + lj_trace_err(J, LJ_TRERR_NYICALL); + tr = crec_ct_tv(J, d, 0, *base, o); + if (ctype_isinteger_or_bool(d->info)) { + if (d->size < 4) { + if ((d->info & CTF_UNSIGNED)) + tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_U8 : IRT_U16, 0); + else + tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_I8 : IRT_I16,IRCONV_SEXT); + } + } else if (LJ_SOFTFP && ctype_isfp(d->info) && d->size > 4) { + lj_needsplit(J); + } +#if LJ_TARGET_X86 + /* 64 bit args must not end up in registers for fastcall/thiscall. */ +#if LJ_ABI_WIN + if (!ctype_isfp(d->info)) { + /* Sigh, the Windows/x86 ABI allows reordering across 64 bit args. */ + if (tref_typerange(tr, IRT_I64, IRT_U64)) { + if (ngpr) { + arg0 = &args[n]; args[n++] = TREF_NIL; ngpr--; + if (ngpr) { + arg1 = &args[n]; args[n++] = TREF_NIL; ngpr--; + } + } + } else { + if (arg0) { *arg0 = tr; arg0 = NULL; n--; continue; } + if (arg1) { *arg1 = tr; arg1 = NULL; n--; continue; } + if (ngpr) ngpr--; + } + } +#else + if (!ctype_isfp(d->info) && ngpr) { + if (tref_typerange(tr, IRT_I64, IRT_U64)) { + /* No reordering for other x86 ABIs. Simply add alignment args. */ + do { args[n++] = TREF_NIL; } while (--ngpr); + } else { + ngpr--; + } + } +#endif +#endif + args[n] = tr; + } + tr = args[0]; + for (i = 1; i < n; i++) + tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]); + return tr; +} + +/* Create a snapshot for the caller, simulating a 'false' return value. */ +static void crec_snap_caller(jit_State *J) +{ + lua_State *L = J->L; + TValue *base = L->base, *top = L->top; + const BCIns *pc = J->pc; + TRef ftr = J->base[-1]; + ptrdiff_t delta; + if (!frame_islua(base-1) || J->framedepth <= 0) + lj_trace_err(J, LJ_TRERR_NYICALL); + J->pc = frame_pc(base-1); delta = 1+bc_a(J->pc[-1]); + L->top = base; L->base = base - delta; + J->base[-1] = TREF_FALSE; + J->base -= delta; J->baseslot -= (BCReg)delta; + J->maxslot = (BCReg)delta; J->framedepth--; + lj_snap_add(J); + L->base = base; L->top = top; + J->framedepth++; J->maxslot = 1; + J->base += delta; J->baseslot += (BCReg)delta; + J->base[-1] = ftr; J->pc = pc; +} + +/* Record function call. */ +static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *ct = ctype_raw(cts, cd->ctypeid); + IRType tp = IRT_PTR; + if (ctype_isptr(ct->info)) { + tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; + ct = ctype_rawchild(cts, ct); + } + if (ctype_isfunc(ct->info)) { + TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR); + CType *ctr = ctype_rawchild(cts, ct); + IRType t = crec_ct2irt(cts, ctr); + TRef tr; + TValue tv; + /* Check for blacklisted C functions that might call a callback. */ + setlightudV(&tv, + cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4)); + if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv))) + lj_trace_err(J, LJ_TRERR_BLACKL); + if (ctype_isvoid(ctr->info)) { + t = IRT_NIL; + rd->nres = 0; + } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) || + ctype_isenum(ctr->info)) || t == IRT_CDATA) { + lj_trace_err(J, LJ_TRERR_NYICALL); + } + if ((ct->info & CTF_VARARG) +#if LJ_TARGET_X86 + || ctype_cconv(ct->info) != CTCC_CDECL +#endif + ) + func = emitir(IRT(IR_CARG, IRT_NIL), func, + lj_ir_kint(J, ctype_typeid(cts, ct))); + tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); + if (ctype_isbool(ctr->info)) { + if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) { + /* Don't check result if ignored. */ + tr = TREF_NIL; + } else { + crec_snap_caller(J); +#if LJ_TARGET_X86ORX64 + /* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */ + lj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0)); +#else + lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); +#endif + J->postproc = LJ_POST_FIXGUARDSNAP; + tr = TREF_TRUE; + } + } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) || + t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) { + TRef trid = lj_ir_kint(J, ctype_cid(ct->info)); + tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr); + if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); + } else if (t == IRT_FLOAT || t == IRT_U32) { + tr = emitconv(tr, IRT_NUM, t, 0); + } else if (t == IRT_I8 || t == IRT_I16) { + tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT); + } else if (t == IRT_U8 || t == IRT_U16) { + tr = emitconv(tr, IRT_INT, t, 0); + } + J->base[0] = tr; + J->needsnap = 1; + return 1; + } + return 0; +} + +void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]); + CTypeID id = cd->ctypeid; + CType *ct; + cTValue *tv; + MMS mm = MM_call; + if (id == CTID_CTYPEID) { + id = crec_constructor(J, cd, J->base[0]); + mm = MM_new; + } else if (crec_call(J, rd, cd)) { + return; + } + /* Record ctype __call/__new metamethod. */ + ct = ctype_raw(cts, id); + tv = lj_ctype_meta(cts, ctype_isptr(ct->info) ? ctype_cid(ct->info) : id, mm); + if (tv) { + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + return; + } + } else if (mm == MM_new) { + crec_alloc(J, rd, id); + return; + } + /* No metamethod or NYI: non-function metamethods. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); +} + +static TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm) +{ + if (ctype_isnum(s[0]->info) && ctype_isnum(s[1]->info)) { + IRType dt; + CTypeID id; + TRef tr; + MSize i; + IROp op; + lj_needsplit(J); + if (((s[0]->info & CTF_UNSIGNED) && s[0]->size == 8) || + ((s[1]->info & CTF_UNSIGNED) && s[1]->size == 8)) { + dt = IRT_U64; id = CTID_UINT64; + } else { + dt = IRT_I64; id = CTID_INT64; + if (mm < MM_add && + !((s[0]->info | s[1]->info) & CTF_FP) && + s[0]->size == 4 && s[1]->size == 4) { /* Try to narrow comparison. */ + if (!((s[0]->info ^ s[1]->info) & CTF_UNSIGNED) || + (tref_isk(sp[1]) && IR(tref_ref(sp[1]))->i >= 0)) { + dt = (s[0]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT; + goto comp; + } else if (tref_isk(sp[0]) && IR(tref_ref(sp[0]))->i >= 0) { + dt = (s[1]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT; + goto comp; + } + } + } + for (i = 0; i < 2; i++) { + IRType st = tref_type(sp[i]); + if (st == IRT_NUM || st == IRT_FLOAT) + sp[i] = emitconv(sp[i], dt, st, IRCONV_TRUNC|IRCONV_ANY); + else if (!(st == IRT_I64 || st == IRT_U64)) + sp[i] = emitconv(sp[i], dt, IRT_INT, + (s[i]->info & CTF_UNSIGNED) ? 0 : IRCONV_SEXT); + } + if (mm < MM_add) { + comp: + /* Assume true comparison. Fixup and emit pending guard later. */ + if (mm == MM_eq) { + op = IR_EQ; + } else { + op = mm == MM_lt ? IR_LT : IR_LE; + if (dt == IRT_U32 || dt == IRT_U64) + op += (IR_ULT-IR_LT); + } + lj_ir_set(J, IRTG(op, dt), sp[0], sp[1]); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } else { + tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, dt), sp[0], sp[1]); + } + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); + } + return 0; +} + +static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *ctp = s[0]; + if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) { + if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) && + (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) { + if (mm == MM_sub) { /* Pointer difference. */ + TRef tr; + CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info)); + if (sz == 0 || (sz & (sz-1)) != 0) + return 0; /* NYI: integer division. */ + tr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]); + tr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz))); +#if LJ_64 + tr = emitconv(tr, IRT_NUM, IRT_INTP, 0); +#endif + return tr; + } else { /* Pointer comparison (unsigned). */ + /* Assume true comparison. Fixup and emit pending guard later. */ + IROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE; + lj_ir_set(J, IRTG(op, IRT_PTR), sp[0], sp[1]); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } + } + if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(s[1]->info))) + return 0; + } else if (mm == MM_add && ctype_isnum(ctp->info) && + (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) { + TRef tr = sp[0]; sp[0] = sp[1]; sp[1] = tr; /* Swap pointer and index. */ + ctp = s[1]; + } else { + return 0; + } + { + TRef tr = sp[1]; + IRType t = tref_type(tr); + CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info)); + CTypeID id; +#if LJ_64 + if (t == IRT_NUM || t == IRT_FLOAT) + tr = emitconv(tr, IRT_INTP, t, IRCONV_TRUNC|IRCONV_ANY); + else if (!(t == IRT_I64 || t == IRT_U64)) + tr = emitconv(tr, IRT_INTP, IRT_INT, + ((t - IRT_I8) & 1) ? 0 : IRCONV_SEXT); +#else + if (!tref_typerange(sp[1], IRT_I8, IRT_U32)) { + tr = emitconv(tr, IRT_INTP, t, + (t == IRT_NUM || t == IRT_FLOAT) ? + IRCONV_TRUNC|IRCONV_ANY : 0); + } +#endif + tr = emitir(IRT(IR_MUL, IRT_INTP), tr, lj_ir_kintp(J, sz)); + tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, IRT_PTR), sp[0], tr); + id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)), + CTSIZE_PTR); + return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); + } +} + +/* Record ctype arithmetic metamethods. */ +static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd) +{ + cTValue *tv = NULL; + if (J->base[0]) { + if (tviscdata(&rd->argv[0])) { + CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, (MMS)rd->data); + } + if (!tv && J->base[1] && tviscdata(&rd->argv[1])) { + CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid; + CType *ct = ctype_raw(cts, id); + if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); + tv = lj_ctype_meta(cts, id, (MMS)rd->data); + } + } + if (tv) { + if (tvisfunc(tv)) { + J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; + rd->nres = -1; /* Pending tailcall. */ + return; + } /* NYI: non-function metamethods. */ + } else if ((MMS)rd->data == MM_eq) { + J->base[0] = TREF_FALSE; + return; + } + lj_trace_err(J, LJ_TRERR_BADTYPE); +} + +void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef sp[2]; + CType *s[2]; + MSize i; + for (i = 0; i < 2; i++) { + TRef tr = J->base[i]; + CType *ct = ctype_get(cts, CTID_DOUBLE); + if (!tr) { + goto trymeta; + } else if (tref_iscdata(tr)) { + CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid; + IRType t; + ct = ctype_raw(cts, id); + t = crec_ct2irt(cts, ct); + if (ctype_isptr(ct->info)) { /* Resolve pointer or reference. */ + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR); + if (ctype_isref(ct->info)) { + ct = ctype_rawchild(cts, ct); + t = crec_ct2irt(cts, ct); + } + } else if (t == IRT_I64 || t == IRT_U64) { + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64); + lj_needsplit(J); + goto ok; + } else if (t == IRT_INT || t == IRT_U32) { + tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + goto ok; + } else if (ctype_isfunc(ct->info)) { + tr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR); + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); + goto ok; + } else { + tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata))); + } + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info)) { + if (t == IRT_CDATA) goto trymeta; + if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); + tr = emitir(IRT(IR_XLOAD, t), tr, 0); + } else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) { + goto trymeta; + } + } else if (tref_isnil(tr)) { + tr = lj_ir_kptr(J, NULL); + ct = ctype_get(cts, CTID_P_VOID); + } else if (tref_isinteger(tr)) { + ct = ctype_get(cts, CTID_INT32); + } else if (tref_isstr(tr)) { + TRef tr2 = J->base[1-i]; + CTypeID id = argv2cdata(J, tr2, &rd->argv[1-i])->ctypeid; + ct = ctype_raw(cts, id); + if (ctype_isenum(ct->info)) { /* Match string against enum constant. */ + GCstr *str = strV(&rd->argv[i]); + CTSize ofs; + CType *cct = lj_ctype_getfield(cts, ct, str, &ofs); + if (cct && ctype_isconstval(cct->info)) { + /* Specialize to the name of the enum constant. */ + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str)); + ct = ctype_child(cts, cct); + tr = lj_ir_kint(J, (int32_t)ofs); + } /* else: interpreter will throw. */ + } /* else: interpreter will throw. */ + } else if (!tref_isnum(tr)) { + goto trymeta; + } + ok: + s[i] = ct; + sp[i] = tr; + } + { + TRef tr; + if ((tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) || + (tr = crec_arith_ptr(J, sp, s, (MMS)rd->data))) { + J->base[0] = tr; + /* Fixup cdata comparisons, too. Avoids some cdata escapes. */ + if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) && + !irt_isguard(J->guardemit)) { + const BCIns *pc = frame_contpc(J->L->base-1) - 1; + if (bc_op(*pc) <= BC_ISNEP) { + setframe_pc(&J2G(J)->tmptv, pc); + J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1); + J->postproc = LJ_POST_FIXCOMP; + } + } + } else { + trymeta: + crec_arith_meta(J, cts, rd); + } + } +} + +/* -- C library namespace metamethods ------------------------------------- */ + +void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) && + udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) { + CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0])); + GCstr *name = strV(&rd->argv[1]); + CType *ct; + CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); + cTValue *tv = lj_tab_getstr(cl->cache, name); + rd->nres = rd->data; + if (id && tv && !tvisnil(tv)) { + /* Specialize to the symbol name and make the result a constant. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name)); + if (ctype_isconstval(ct->info)) { + if (ct->size >= 0x80000000u && + (ctype_child(cts, ct)->info & CTF_UNSIGNED)) + J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size); + else + J->base[0] = lj_ir_kint(J, (int32_t)ct->size); + } else if (ctype_isextern(ct->info)) { + CTypeID sid = ctype_cid(ct->info); + void *sp = *(void **)cdataptr(cdataV(tv)); + TRef ptr; + ct = ctype_raw(cts, sid); + if (LJ_64 && !checkptr32(sp)) + ptr = lj_ir_kintp(J, (uintptr_t)sp); + else + ptr = lj_ir_kptr(J, sp); + if (rd->data) { + J->base[0] = crec_tv_ct(J, ct, sid, ptr); + } else { + J->needsnap = 1; + crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]); + } + } else { + J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA); + } + } else { + lj_trace_err(J, LJ_TRERR_NOCACHE); + } + } /* else: interpreter will throw. */ +} + +/* -- FFI library functions ----------------------------------------------- */ + +static TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval) +{ + return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval); +} + +void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd) +{ + crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0])); +} + +void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd) +{ + UNUSED(rd); + if (J->base[0]) + lj_trace_err(J, LJ_TRERR_NYICALL); + J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno); +} + +void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef tr = J->base[0]; + if (tr) { + TRef trlen = J->base[1]; + if (!tref_isnil(trlen)) { + trlen = crec_toint(J, cts, trlen, &rd->argv[1]); + tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]); + } else { + tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]); + trlen = lj_ir_call(J, IRCALL_strlen, tr); + } + J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), tr, trlen); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2]; + if (trdst && trsrc && (trlen || tref_isstr(trsrc))) { + trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]); + trsrc = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, trsrc, &rd->argv[1]); + if (trlen) { + trlen = crec_toint(J, cts, trlen, &rd->argv[2]); + } else { + trlen = emitir(IRTI(IR_FLOAD), J->base[1], IRFL_STR_LEN); + trlen = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1)); + } + rd->nres = 0; + crec_copy(J, trdst, trsrc, trlen, NULL); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2]; + if (trdst && trlen) { + CTSize step = 1; + if (tviscdata(&rd->argv[0])) { /* Get alignment of original destination. */ + CTSize sz; + CType *ct = ctype_raw(cts, cdataV(&rd->argv[0])->ctypeid); + if (ctype_isptr(ct->info)) + ct = ctype_rawchild(cts, ct); + step = (1u<argv[0]); + trlen = crec_toint(J, cts, trlen, &rd->argv[1]); + if (trfill) + trfill = crec_toint(J, cts, trfill, &rd->argv[2]); + else + trfill = lj_ir_kint(J, 0); + rd->nres = 0; + crec_fill(J, trdst, trlen, trfill, step); + } /* else: interpreter will throw. */ +} + +void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd) +{ + if (tref_iscdata(J->base[0])) { + TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0])); + J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), + lj_ir_kint(J, CTID_CTYPEID), trid); + } else { + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFFU); + } +} + +void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd) +{ + argv2ctype(J, J->base[0], &rd->argv[0]); + if (tref_iscdata(J->base[1])) { + argv2ctype(J, J->base[1], &rd->argv[1]); + J->postproc = LJ_POST_FIXBOOL; + J->base[0] = TREF_TRUE; + } else { + J->base[0] = TREF_FALSE; + } +} + +void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd) +{ + if (tref_isstr(J->base[0])) { + /* Specialize to the ABI string to make the boolean result a constant. */ + emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0]))); + J->postproc = LJ_POST_FIXBOOL; + J->base[0] = TREF_TRUE; + } else { + lj_trace_err(J, LJ_TRERR_BADTYPE); + } +} + +/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */ +void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd) +{ + CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]); + if (rd->data == FF_ffi_sizeof) { + CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id); + if (ctype_isvltype(ct->info)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + } else if (rd->data == FF_ffi_offsetof) { /* Specialize to the field name. */ + if (!tref_isstr(J->base[1])) + lj_trace_err(J, LJ_TRERR_BADTYPE); + emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1]))); + rd->nres = 3; /* Just in case. */ + } + J->postproc = LJ_POST_FIXCONST; + J->base[0] = J->base[1] = J->base[2] = TREF_NIL; +} + +void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd) +{ + argv2cdata(J, J->base[0], &rd->argv[0]); + crec_finalizer(J, J->base[0], &rd->argv[1]); +} + +/* -- Miscellaneous library functions ------------------------------------- */ + +void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) +{ + CTState *cts = ctype_ctsG(J2G(J)); + CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid); + if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); + if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) { + if (ctype_isinteger_or_bool(ct->info) && ct->size <= 4 && + !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) + d = ctype_get(cts, CTID_INT32); + else + d = ctype_get(cts, CTID_DOUBLE); + J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]); + } else { + J->base[0] = TREF_NIL; + } +} + +#undef IR +#undef emitir +#undef emitconv + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.h new file mode 100644 index 0000000..fb77ca6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_crecord.h @@ -0,0 +1,31 @@ +/* +** Trace recorder for C data operations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CRECORD_H +#define _LJ_CRECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" +#include "lj_ffrecord.h" + +#if LJ_HASJIT && LJ_HASFFI +LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd); +LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.c new file mode 100644 index 0000000..e9fe094 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.c @@ -0,0 +1,634 @@ +/* +** C type management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include "lj_obj.h" + +#if LJ_HASFFI + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_ccallback.h" + +/* -- C type definitions -------------------------------------------------- */ + +/* Predefined typedefs. */ +#define CTTDDEF(_) \ + /* Vararg handling. */ \ + _("va_list", P_VOID) \ + _("__builtin_va_list", P_VOID) \ + _("__gnuc_va_list", P_VOID) \ + /* From stddef.h. */ \ + _("ptrdiff_t", INT_PSZ) \ + _("size_t", UINT_PSZ) \ + _("wchar_t", WCHAR) \ + /* Subset of stdint.h. */ \ + _("int8_t", INT8) \ + _("int16_t", INT16) \ + _("int32_t", INT32) \ + _("int64_t", INT64) \ + _("uint8_t", UINT8) \ + _("uint16_t", UINT16) \ + _("uint32_t", UINT32) \ + _("uint64_t", UINT64) \ + _("intptr_t", INT_PSZ) \ + _("uintptr_t", UINT_PSZ) \ + /* End of typedef list. */ + +/* Keywords (only the ones we actually care for). */ +#define CTKWDEF(_) \ + /* Type specifiers. */ \ + _("void", -1, CTOK_VOID) \ + _("_Bool", 0, CTOK_BOOL) \ + _("bool", 1, CTOK_BOOL) \ + _("char", 1, CTOK_CHAR) \ + _("int", 4, CTOK_INT) \ + _("__int8", 1, CTOK_INT) \ + _("__int16", 2, CTOK_INT) \ + _("__int32", 4, CTOK_INT) \ + _("__int64", 8, CTOK_INT) \ + _("float", 4, CTOK_FP) \ + _("double", 8, CTOK_FP) \ + _("long", 0, CTOK_LONG) \ + _("short", 0, CTOK_SHORT) \ + _("_Complex", 0, CTOK_COMPLEX) \ + _("complex", 0, CTOK_COMPLEX) \ + _("__complex", 0, CTOK_COMPLEX) \ + _("__complex__", 0, CTOK_COMPLEX) \ + _("signed", 0, CTOK_SIGNED) \ + _("__signed", 0, CTOK_SIGNED) \ + _("__signed__", 0, CTOK_SIGNED) \ + _("unsigned", 0, CTOK_UNSIGNED) \ + /* Type qualifiers. */ \ + _("const", 0, CTOK_CONST) \ + _("__const", 0, CTOK_CONST) \ + _("__const__", 0, CTOK_CONST) \ + _("volatile", 0, CTOK_VOLATILE) \ + _("__volatile", 0, CTOK_VOLATILE) \ + _("__volatile__", 0, CTOK_VOLATILE) \ + _("restrict", 0, CTOK_RESTRICT) \ + _("__restrict", 0, CTOK_RESTRICT) \ + _("__restrict__", 0, CTOK_RESTRICT) \ + _("inline", 0, CTOK_INLINE) \ + _("__inline", 0, CTOK_INLINE) \ + _("__inline__", 0, CTOK_INLINE) \ + /* Storage class specifiers. */ \ + _("typedef", 0, CTOK_TYPEDEF) \ + _("extern", 0, CTOK_EXTERN) \ + _("static", 0, CTOK_STATIC) \ + _("auto", 0, CTOK_AUTO) \ + _("register", 0, CTOK_REGISTER) \ + /* GCC Attributes. */ \ + _("__extension__", 0, CTOK_EXTENSION) \ + _("__attribute", 0, CTOK_ATTRIBUTE) \ + _("__attribute__", 0, CTOK_ATTRIBUTE) \ + _("asm", 0, CTOK_ASM) \ + _("__asm", 0, CTOK_ASM) \ + _("__asm__", 0, CTOK_ASM) \ + /* MSVC Attributes. */ \ + _("__declspec", 0, CTOK_DECLSPEC) \ + _("__cdecl", CTCC_CDECL, CTOK_CCDECL) \ + _("__thiscall", CTCC_THISCALL, CTOK_CCDECL) \ + _("__fastcall", CTCC_FASTCALL, CTOK_CCDECL) \ + _("__stdcall", CTCC_STDCALL, CTOK_CCDECL) \ + _("__ptr32", 4, CTOK_PTRSZ) \ + _("__ptr64", 8, CTOK_PTRSZ) \ + /* Other type specifiers. */ \ + _("struct", 0, CTOK_STRUCT) \ + _("union", 0, CTOK_UNION) \ + _("enum", 0, CTOK_ENUM) \ + /* Operators. */ \ + _("sizeof", 0, CTOK_SIZEOF) \ + _("__alignof", 0, CTOK_ALIGNOF) \ + _("__alignof__", 0, CTOK_ALIGNOF) \ + /* End of keyword list. */ + +/* Type info for predefined types. Size merged in. */ +static CTInfo lj_ctype_typeinfo[] = { +#define CTTYINFODEF(id, sz, ct, info) CTINFO((ct),(((sz)&0x3fu)<<10)+(info)), +#define CTTDINFODEF(name, id) CTINFO(CT_TYPEDEF, CTID_##id), +#define CTKWINFODEF(name, sz, kw) CTINFO(CT_KW,(((sz)&0x3fu)<<10)+(kw)), +CTTYDEF(CTTYINFODEF) +CTTDDEF(CTTDINFODEF) +CTKWDEF(CTKWINFODEF) +#undef CTTYINFODEF +#undef CTTDINFODEF +#undef CTKWINFODEF + 0 +}; + +/* Predefined type names collected in a single string. */ +static const char * const lj_ctype_typenames = +#define CTTDNAMEDEF(name, id) name "\0" +#define CTKWNAMEDEF(name, sz, cds) name "\0" +CTTDDEF(CTTDNAMEDEF) +CTKWDEF(CTKWNAMEDEF) +#undef CTTDNAMEDEF +#undef CTKWNAMEDEF +; + +#define CTTYPEINFO_NUM (sizeof(lj_ctype_typeinfo)/sizeof(CTInfo)-1) +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR +#define CTTYPETAB_MIN CTTYPEINFO_NUM +#else +#define CTTYPETAB_MIN 128 +#endif + +/* -- C type interning ---------------------------------------------------- */ + +#define ct_hashtype(info, size) (hashrot(info, size) & CTHASH_MASK) +#define ct_hashname(name) \ + (hashrot(u32ptr(name), u32ptr(name) + HASH_BIAS) & CTHASH_MASK) + +/* Create new type element. */ +CTypeID lj_ctype_new(CTState *cts, CType **ctp) +{ + CTypeID id = cts->top; + CType *ct; + lua_assert(cts->L); + if (LJ_UNLIKELY(id >= cts->sizetab)) { + if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV); +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR + ct = lj_mem_newvec(cts->L, id+1, CType); + memcpy(ct, cts->tab, id*sizeof(CType)); + memset(cts->tab, 0, id*sizeof(CType)); + lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType); + cts->tab = ct; + cts->sizetab = id+1; +#else + lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType); +#endif + } + cts->top = id+1; + *ctp = ct = &cts->tab[id]; + ct->info = 0; + ct->size = 0; + ct->sib = 0; + ct->next = 0; + setgcrefnull(ct->name); + return id; +} + +/* Intern a type element. */ +CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size) +{ + uint32_t h = ct_hashtype(info, size); + CTypeID id = cts->hash[h]; + lua_assert(cts->L); + while (id) { + CType *ct = ctype_get(cts, id); + if (ct->info == info && ct->size == size) + return id; + id = ct->next; + } + id = cts->top; + if (LJ_UNLIKELY(id >= cts->sizetab)) { + if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV); + lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType); + } + cts->top = id+1; + cts->tab[id].info = info; + cts->tab[id].size = size; + cts->tab[id].sib = 0; + cts->tab[id].next = cts->hash[h]; + setgcrefnull(cts->tab[id].name); + cts->hash[h] = (CTypeID1)id; + return id; +} + +/* Add type element to hash table. */ +static void ctype_addtype(CTState *cts, CType *ct, CTypeID id) +{ + uint32_t h = ct_hashtype(ct->info, ct->size); + ct->next = cts->hash[h]; + cts->hash[h] = (CTypeID1)id; +} + +/* Add named element to hash table. */ +void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id) +{ + uint32_t h = ct_hashname(gcref(ct->name)); + ct->next = cts->hash[h]; + cts->hash[h] = (CTypeID1)id; +} + +/* Get a C type by name, matching the type mask. */ +CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, uint32_t tmask) +{ + CTypeID id = cts->hash[ct_hashname(name)]; + while (id) { + CType *ct = ctype_get(cts, id); + if (gcref(ct->name) == obj2gco(name) && + ((tmask >> ctype_type(ct->info)) & 1)) { + *ctp = ct; + return id; + } + id = ct->next; + } + *ctp = &cts->tab[0]; /* Simplify caller logic. ctype_get() would assert. */ + return 0; +} + +/* Get a struct/union/enum/function field by name. */ +CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, CTSize *ofs, + CTInfo *qual) +{ + while (ct->sib) { + ct = ctype_get(cts, ct->sib); + if (gcref(ct->name) == obj2gco(name)) { + *ofs = ct->size; + return ct; + } + if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) { + CType *fct, *cct = ctype_child(cts, ct); + CTInfo q = 0; + while (ctype_isattrib(cct->info)) { + if (ctype_attrib(cct->info) == CTA_QUAL) q |= cct->size; + cct = ctype_child(cts, cct); + } + fct = lj_ctype_getfieldq(cts, cct, name, ofs, qual); + if (fct) { + if (qual) *qual |= q; + *ofs += ct->size; + return fct; + } + } + } + return NULL; /* Not found. */ +} + +/* -- C type information -------------------------------------------------- */ + +/* Follow references and get raw type for a C type ID. */ +CType *lj_ctype_rawref(CTState *cts, CTypeID id) +{ + CType *ct = ctype_get(cts, id); + while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) + ct = ctype_child(cts, ct); + return ct; +} + +/* Get size for a C type ID. Does NOT support VLA/VLS. */ +CTSize lj_ctype_size(CTState *cts, CTypeID id) +{ + CType *ct = ctype_raw(cts, id); + return ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID; +} + +/* Get size for a variable-length C type. Does NOT support other C types. */ +CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem) +{ + uint64_t xsz = 0; + if (ctype_isstruct(ct->info)) { + CTypeID arrid = 0, fid = ct->sib; + xsz = ct->size; /* Add the struct size. */ + while (fid) { + CType *ctf = ctype_get(cts, fid); + if (ctype_type(ctf->info) == CT_FIELD) + arrid = ctype_cid(ctf->info); /* Remember last field of VLS. */ + fid = ctf->sib; + } + ct = ctype_raw(cts, arrid); + } + lua_assert(ctype_isvlarray(ct->info)); /* Must be a VLA. */ + ct = ctype_rawchild(cts, ct); /* Get array element. */ + lua_assert(ctype_hassize(ct->info)); + /* Calculate actual size of VLA and check for overflow. */ + xsz += (uint64_t)ct->size * nelem; + return xsz < 0x80000000u ? (CTSize)xsz : CTSIZE_INVALID; +} + +/* Get type, qualifiers, size and alignment for a C type ID. */ +CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp) +{ + CTInfo qual = 0; + CType *ct = ctype_get(cts, id); + for (;;) { + CTInfo info = ct->info; + if (ctype_isenum(info)) { + /* Follow child. Need to look at its attributes, too. */ + } else if (ctype_isattrib(info)) { + if (ctype_isxattrib(info, CTA_QUAL)) + qual |= ct->size; + else if (ctype_isxattrib(info, CTA_ALIGN) && !(qual & CTFP_ALIGNED)) + qual |= CTFP_ALIGNED + CTALIGN(ct->size); + } else { + if (!(qual & CTFP_ALIGNED)) qual |= (info & CTF_ALIGN); + qual |= (info & ~(CTF_ALIGN|CTMASK_CID)); + lua_assert(ctype_hassize(info) || ctype_isfunc(info)); + *szp = ctype_isfunc(info) ? CTSIZE_INVALID : ct->size; + break; + } + ct = ctype_get(cts, ctype_cid(info)); + } + return qual; +} + +/* Get ctype metamethod. */ +cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm) +{ + CType *ct = ctype_get(cts, id); + cTValue *tv; + while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) { + id = ctype_cid(ct->info); + ct = ctype_get(cts, id); + } + if (ctype_isptr(ct->info) && + ctype_isfunc(ctype_get(cts, ctype_cid(ct->info))->info)) + tv = lj_tab_getstr(cts->miscmap, &cts->g->strempty); + else + tv = lj_tab_getinth(cts->miscmap, -(int32_t)id); + if (tv && tvistab(tv) && + (tv = lj_tab_getstr(tabV(tv), mmname_str(cts->g, mm))) && !tvisnil(tv)) + return tv; + return NULL; +} + +/* -- C type representation ----------------------------------------------- */ + +/* Fixed max. length of a C type representation. */ +#define CTREPR_MAX 512 + +typedef struct CTRepr { + char *pb, *pe; + CTState *cts; + lua_State *L; + int needsp; + int ok; + char buf[CTREPR_MAX]; +} CTRepr; + +/* Prepend string. */ +static void ctype_prepstr(CTRepr *ctr, const char *str, MSize len) +{ + char *p = ctr->pb; + if (ctr->buf + len+1 > p) { ctr->ok = 0; return; } + if (ctr->needsp) *--p = ' '; + ctr->needsp = 1; + p -= len; + while (len-- > 0) p[len] = str[len]; + ctr->pb = p; +} + +#define ctype_preplit(ctr, str) ctype_prepstr((ctr), "" str, sizeof(str)-1) + +/* Prepend char. */ +static void ctype_prepc(CTRepr *ctr, int c) +{ + if (ctr->buf >= ctr->pb) { ctr->ok = 0; return; } + *--ctr->pb = c; +} + +/* Prepend number. */ +static void ctype_prepnum(CTRepr *ctr, uint32_t n) +{ + char *p = ctr->pb; + if (ctr->buf + 10+1 > p) { ctr->ok = 0; return; } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + ctr->pb = p; + ctr->needsp = 0; +} + +/* Append char. */ +static void ctype_appc(CTRepr *ctr, int c) +{ + if (ctr->pe >= ctr->buf + CTREPR_MAX) { ctr->ok = 0; return; } + *ctr->pe++ = c; +} + +/* Append number. */ +static void ctype_appnum(CTRepr *ctr, uint32_t n) +{ + char buf[10]; + char *p = buf+sizeof(buf); + char *q = ctr->pe; + if (q > ctr->buf + CTREPR_MAX - 10) { ctr->ok = 0; return; } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + do { *q++ = *p++; } while (p < buf+sizeof(buf)); + ctr->pe = q; +} + +/* Prepend qualifiers. */ +static void ctype_prepqual(CTRepr *ctr, CTInfo info) +{ + if ((info & CTF_VOLATILE)) ctype_preplit(ctr, "volatile"); + if ((info & CTF_CONST)) ctype_preplit(ctr, "const"); +} + +/* Prepend named type. */ +static void ctype_preptype(CTRepr *ctr, CType *ct, CTInfo qual, const char *t) +{ + if (gcref(ct->name)) { + GCstr *str = gco2str(gcref(ct->name)); + ctype_prepstr(ctr, strdata(str), str->len); + } else { + if (ctr->needsp) ctype_prepc(ctr, ' '); + ctype_prepnum(ctr, ctype_typeid(ctr->cts, ct)); + ctr->needsp = 1; + } + ctype_prepstr(ctr, t, (MSize)strlen(t)); + ctype_prepqual(ctr, qual); +} + +static void ctype_repr(CTRepr *ctr, CTypeID id) +{ + CType *ct = ctype_get(ctr->cts, id); + CTInfo qual = 0; + int ptrto = 0; + for (;;) { + CTInfo info = ct->info; + CTSize size = ct->size; + switch (ctype_type(info)) { + case CT_NUM: + if ((info & CTF_BOOL)) { + ctype_preplit(ctr, "bool"); + } else if ((info & CTF_FP)) { + if (size == sizeof(double)) ctype_preplit(ctr, "double"); + else if (size == sizeof(float)) ctype_preplit(ctr, "float"); + else ctype_preplit(ctr, "long double"); + } else if (size == 1) { + if (!((info ^ CTF_UCHAR) & CTF_UNSIGNED)) ctype_preplit(ctr, "char"); + else if (CTF_UCHAR) ctype_preplit(ctr, "signed char"); + else ctype_preplit(ctr, "unsigned char"); + } else if (size < 8) { + if (size == 4) ctype_preplit(ctr, "int"); + else ctype_preplit(ctr, "short"); + if ((info & CTF_UNSIGNED)) ctype_preplit(ctr, "unsigned"); + } else { + ctype_preplit(ctr, "_t"); + ctype_prepnum(ctr, size*8); + ctype_preplit(ctr, "int"); + if ((info & CTF_UNSIGNED)) ctype_prepc(ctr, 'u'); + } + ctype_prepqual(ctr, (qual|info)); + return; + case CT_VOID: + ctype_preplit(ctr, "void"); + ctype_prepqual(ctr, (qual|info)); + return; + case CT_STRUCT: + ctype_preptype(ctr, ct, qual, (info & CTF_UNION) ? "union" : "struct"); + return; + case CT_ENUM: + if (id == CTID_CTYPEID) { + ctype_preplit(ctr, "ctype"); + return; + } + ctype_preptype(ctr, ct, qual, "enum"); + return; + case CT_ATTRIB: + if (ctype_attrib(info) == CTA_QUAL) qual |= size; + break; + case CT_PTR: + if ((info & CTF_REF)) { + ctype_prepc(ctr, '&'); + } else { + ctype_prepqual(ctr, (qual|info)); + if (LJ_64 && size == 4) ctype_preplit(ctr, "__ptr32"); + ctype_prepc(ctr, '*'); + } + qual = 0; + ptrto = 1; + ctr->needsp = 1; + break; + case CT_ARRAY: + if (ctype_isrefarray(info)) { + ctr->needsp = 1; + if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); } + ctype_appc(ctr, '['); + if (size != CTSIZE_INVALID) { + CTSize csize = ctype_child(ctr->cts, ct)->size; + ctype_appnum(ctr, csize ? size/csize : 0); + } else if ((info & CTF_VLA)) { + ctype_appc(ctr, '?'); + } + ctype_appc(ctr, ']'); + } else if ((info & CTF_COMPLEX)) { + if (size == 2*sizeof(float)) ctype_preplit(ctr, "float"); + ctype_preplit(ctr, "complex"); + return; + } else { + ctype_preplit(ctr, ")))"); + ctype_prepnum(ctr, size); + ctype_preplit(ctr, "__attribute__((vector_size("); + } + break; + case CT_FUNC: + ctr->needsp = 1; + if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); } + ctype_appc(ctr, '('); + ctype_appc(ctr, ')'); + break; + default: + lua_assert(0); + break; + } + ct = ctype_get(ctr->cts, ctype_cid(info)); + } +} + +/* Return a printable representation of a C type. */ +GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name) +{ + global_State *g = G(L); + CTRepr ctr; + ctr.pb = ctr.pe = &ctr.buf[CTREPR_MAX/2]; + ctr.cts = ctype_ctsG(g); + ctr.L = L; + ctr.ok = 1; + ctr.needsp = 0; + if (name) ctype_prepstr(&ctr, strdata(name), name->len); + ctype_repr(&ctr, id); + if (LJ_UNLIKELY(!ctr.ok)) return lj_str_newlit(L, "?"); + return lj_str_new(L, ctr.pb, ctr.pe - ctr.pb); +} + +/* Convert int64_t/uint64_t to string with 'LL' or 'ULL' suffix. */ +GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned) +{ + char buf[1+20+3]; + char *p = buf+sizeof(buf); + int sign = 0; + *--p = 'L'; *--p = 'L'; + if (isunsigned) { + *--p = 'U'; + } else if ((int64_t)n < 0) { + n = (uint64_t)-(int64_t)n; + sign = 1; + } + do { *--p = (char)('0' + n % 10); } while (n /= 10); + if (sign) *--p = '-'; + return lj_str_new(L, p, (size_t)(buf+sizeof(buf)-p)); +} + +/* Convert complex to string with 'i' or 'I' suffix. */ +GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size) +{ + char buf[2*LJ_STR_NUMBUF+2+1]; + TValue re, im; + size_t len; + if (size == 2*sizeof(double)) { + re.n = *(double *)sp; im.n = ((double *)sp)[1]; + } else { + re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1]; + } + len = lj_str_bufnum(buf, &re); + if (!(im.u32.hi & 0x80000000u) || im.n != im.n) buf[len++] = '+'; + len += lj_str_bufnum(buf+len, &im); + buf[len] = buf[len-1] >= 'a' ? 'I' : 'i'; + return lj_str_new(L, buf, len+1); +} + +/* -- C type state -------------------------------------------------------- */ + +/* Initialize C type table and state. */ +CTState *lj_ctype_init(lua_State *L) +{ + CTState *cts = lj_mem_newt(L, sizeof(CTState), CTState); + CType *ct = lj_mem_newvec(L, CTTYPETAB_MIN, CType); + const char *name = lj_ctype_typenames; + CTypeID id; + memset(cts, 0, sizeof(CTState)); + cts->tab = ct; + cts->sizetab = CTTYPETAB_MIN; + cts->top = CTTYPEINFO_NUM; + cts->L = NULL; + cts->g = G(L); + for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) { + CTInfo info = lj_ctype_typeinfo[id]; + ct->size = (CTSize)((int32_t)(info << 16) >> 26); + ct->info = info & 0xffff03ffu; + ct->sib = 0; + if (ctype_type(info) == CT_KW || ctype_istypedef(info)) { + size_t len = strlen(name); + GCstr *str = lj_str_new(L, name, len); + ctype_setname(ct, str); + name += len+1; + lj_ctype_addname(cts, ct, id); + } else { + setgcrefnull(ct->name); + ct->next = 0; + if (!ctype_isenum(info)) ctype_addtype(cts, ct, id); + } + } + setmref(G(L)->ctype_state, cts); + return cts; +} + +/* Free C type table and state. */ +void lj_ctype_freestate(global_State *g) +{ + CTState *cts = ctype_ctsG(g); + if (cts) { + lj_ccallback_mcode_free(cts); + lj_mem_freevec(g, cts->tab, cts->sizetab, CType); + lj_mem_freevec(g, cts->cb.cbid, cts->cb.sizeid, CTypeID1); + lj_mem_freet(g, cts); + } +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.h new file mode 100644 index 0000000..ff8ee06 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ctype.h @@ -0,0 +1,461 @@ +/* +** C type management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_CTYPE_H +#define _LJ_CTYPE_H + +#include "lj_obj.h" +#include "lj_gc.h" + +#if LJ_HASFFI + +/* -- C type definitions -------------------------------------------------- */ + +/* C type numbers. Highest 4 bits of C type info. ORDER CT. */ +enum { + /* Externally visible types. */ + CT_NUM, /* Integer or floating-point numbers. */ + CT_STRUCT, /* Struct or union. */ + CT_PTR, /* Pointer or reference. */ + CT_ARRAY, /* Array or complex type. */ + CT_MAYCONVERT = CT_ARRAY, + CT_VOID, /* Void type. */ + CT_ENUM, /* Enumeration. */ + CT_HASSIZE = CT_ENUM, /* Last type where ct->size holds the actual size. */ + CT_FUNC, /* Function. */ + CT_TYPEDEF, /* Typedef. */ + CT_ATTRIB, /* Miscellaneous attributes. */ + /* Internal element types. */ + CT_FIELD, /* Struct/union field or function parameter. */ + CT_BITFIELD, /* Struct/union bitfield. */ + CT_CONSTVAL, /* Constant value. */ + CT_EXTERN, /* External reference. */ + CT_KW /* Keyword. */ +}; + +LJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR); +LJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT); + +/* +** ---------- info ------------ +** |type flags... A cid | size | sib | next | name | +** +----------------------------+--------+-------+-------+-------+-- +** |NUM BFvcUL.. A | size | | type | | +** |STRUCT ..vcU..V A | size | field | name? | name? | +** |PTR ..vcR... A cid | size | | type | | +** |ARRAY VCvc...V A cid | size | | type | | +** |VOID ..vc.... A | size | | type | | +** |ENUM A cid | size | const | name? | name? | +** |FUNC ....VS.. cc cid | nargs | field | name? | name? | +** |TYPEDEF cid | | | name | name | +** |ATTRIB attrnum cid | attr | sib? | type? | | +** |FIELD cid | offset | field | | name? | +** |BITFIELD B.vcU csz bsz pos | offset | field | | name? | +** |CONSTVAL c cid | value | const | name | name | +** |EXTERN cid | | sib? | name | name | +** |KW tok | size | | name | name | +** +----------------------------+--------+-------+-------+-------+-- +** ^^ ^^--- bits used for C type conversion dispatch +*/ + +/* C type info flags. TFFArrrr */ +#define CTF_BOOL 0x08000000u /* Boolean: NUM, BITFIELD. */ +#define CTF_FP 0x04000000u /* Floating-point: NUM. */ +#define CTF_CONST 0x02000000u /* Const qualifier. */ +#define CTF_VOLATILE 0x01000000u /* Volatile qualifier. */ +#define CTF_UNSIGNED 0x00800000u /* Unsigned: NUM, BITFIELD. */ +#define CTF_LONG 0x00400000u /* Long: NUM. */ +#define CTF_VLA 0x00100000u /* Variable-length: ARRAY, STRUCT. */ +#define CTF_REF 0x00800000u /* Reference: PTR. */ +#define CTF_VECTOR 0x08000000u /* Vector: ARRAY. */ +#define CTF_COMPLEX 0x04000000u /* Complex: ARRAY. */ +#define CTF_UNION 0x00800000u /* Union: STRUCT. */ +#define CTF_VARARG 0x00800000u /* Vararg: FUNC. */ +#define CTF_SSEREGPARM 0x00400000u /* SSE register parameters: FUNC. */ + +#define CTF_QUAL (CTF_CONST|CTF_VOLATILE) +#define CTF_ALIGN (CTMASK_ALIGN< 0 ? CTF_UNSIGNED : 0) + +/* Flags used in parser. .F.Ammvf cp->attr */ +#define CTFP_ALIGNED 0x00000001u /* cp->attr + ALIGN */ +#define CTFP_PACKED 0x00000002u /* cp->attr */ +/* ...C...f cp->fattr */ +#define CTFP_CCONV 0x00000001u /* cp->fattr + CCONV/[SSE]REGPARM */ + +/* C type info bitfields. */ +#define CTMASK_CID 0x0000ffffu /* Max. 65536 type IDs. */ +#define CTMASK_NUM 0xf0000000u /* Max. 16 type numbers. */ +#define CTSHIFT_NUM 28 +#define CTMASK_ALIGN 15 /* Max. alignment is 2^15. */ +#define CTSHIFT_ALIGN 16 +#define CTMASK_ATTRIB 255 /* Max. 256 attributes. */ +#define CTSHIFT_ATTRIB 16 +#define CTMASK_CCONV 3 /* Max. 4 calling conventions. */ +#define CTSHIFT_CCONV 16 +#define CTMASK_REGPARM 3 /* Max. 0-3 regparms. */ +#define CTSHIFT_REGPARM 18 +/* Bitfields only used in parser. */ +#define CTMASK_VSIZEP 15 /* Max. vector size is 2^15. */ +#define CTSHIFT_VSIZEP 4 +#define CTMASK_MSIZEP 255 /* Max. type size (via mode) is 128. */ +#define CTSHIFT_MSIZEP 8 + +/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */ +#define CTBSZ_MAX 32 /* Max. size of bitfield is 32 bit. */ +#define CTBSZ_FIELD 127 /* Temp. marker for regular field. */ +#define CTMASK_BITPOS 127 +#define CTMASK_BITBSZ 127 +#define CTMASK_BITCSZ 127 +#define CTSHIFT_BITPOS 0 +#define CTSHIFT_BITBSZ 8 +#define CTSHIFT_BITCSZ 16 + +#define CTF_INSERT(info, field, val) \ + info = (info & ~(CTMASK_##field<> CTSHIFT_NUM) +#define ctype_cid(info) ((CTypeID)((info) & CTMASK_CID)) +#define ctype_align(info) (((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN) +#define ctype_attrib(info) (((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB) +#define ctype_bitpos(info) (((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS) +#define ctype_bitbsz(info) (((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ) +#define ctype_bitcsz(info) (((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ) +#define ctype_vsizeP(info) (((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP) +#define ctype_msizeP(info) (((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP) +#define ctype_cconv(info) (((info) >> CTSHIFT_CCONV) & CTMASK_CCONV) + +/* Simple type checks. */ +#define ctype_isnum(info) (ctype_type((info)) == CT_NUM) +#define ctype_isvoid(info) (ctype_type((info)) == CT_VOID) +#define ctype_isptr(info) (ctype_type((info)) == CT_PTR) +#define ctype_isarray(info) (ctype_type((info)) == CT_ARRAY) +#define ctype_isstruct(info) (ctype_type((info)) == CT_STRUCT) +#define ctype_isfunc(info) (ctype_type((info)) == CT_FUNC) +#define ctype_isenum(info) (ctype_type((info)) == CT_ENUM) +#define ctype_istypedef(info) (ctype_type((info)) == CT_TYPEDEF) +#define ctype_isattrib(info) (ctype_type((info)) == CT_ATTRIB) +#define ctype_isfield(info) (ctype_type((info)) == CT_FIELD) +#define ctype_isbitfield(info) (ctype_type((info)) == CT_BITFIELD) +#define ctype_isconstval(info) (ctype_type((info)) == CT_CONSTVAL) +#define ctype_isextern(info) (ctype_type((info)) == CT_EXTERN) +#define ctype_hassize(info) (ctype_type((info)) <= CT_HASSIZE) + +/* Combined type and flag checks. */ +#define ctype_isinteger(info) \ + (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0)) +#define ctype_isinteger_or_bool(info) \ + (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0)) +#define ctype_isbool(info) \ + (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL)) +#define ctype_isfp(info) \ + (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP)) + +#define ctype_ispointer(info) \ + ((ctype_type(info) >> 1) == (CT_PTR >> 1)) /* Pointer or array. */ +#define ctype_isref(info) \ + (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF)) + +#define ctype_isrefarray(info) \ + (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0)) +#define ctype_isvector(info) \ + (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR)) +#define ctype_iscomplex(info) \ + (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX)) + +#define ctype_isvltype(info) \ + (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<") _(STRING, "") \ + _(INTEGER, "") _(EOF, "") \ + _(OROR, "||") _(ANDAND, "&&") _(EQ, "==") _(NE, "!=") \ + _(LE, "<=") _(GE, ">=") _(SHL, "<<") _(SHR, ">>") _(DEREF, "->") + +/* Simple declaration specifiers. */ +#define CDSDEF(_) \ + _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \ + _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \ + _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \ + _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER) + +/* C keywords. */ +#define CKWDEF(_) \ + CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \ + _(DECLSPEC) _(CCDECL) _(PTRSZ) \ + _(STRUCT) _(UNION) _(ENUM) \ + _(SIZEOF) _(ALIGNOF) + +/* C token numbers. */ +enum { + CTOK_OFS = 255, +#define CTOKNUM(name, sym) CTOK_##name, +#define CKWNUM(name) CTOK_##name, +CTOKDEF(CTOKNUM) +CKWDEF(CKWNUM) +#undef CTOKNUM +#undef CKWNUM + CTOK_FIRSTDECL = CTOK_VOID, + CTOK_FIRSTSCL = CTOK_TYPEDEF, + CTOK_LASTDECLFLAG = CTOK_REGISTER, + CTOK_LASTDECL = CTOK_ENUM +}; + +/* Declaration specifier flags. */ +enum { +#define CDSFLAG(name) CDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)), +CDSDEF(CDSFLAG) +#undef CDSFLAG + CDF__END +}; + +#define CDF_SCL (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER) + +/* -- C type management --------------------------------------------------- */ + +#define ctype_ctsG(g) (mref((g)->ctype_state, CTState)) + +/* Get C type state. */ +static LJ_AINLINE CTState *ctype_cts(lua_State *L) +{ + CTState *cts = ctype_ctsG(G(L)); + cts->L = L; /* Save L for errors and allocations. */ + return cts; +} + +/* Save and restore state of C type table. */ +#define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts) +#define LJ_CTYPE_RESTORE(cts) \ + ((cts)->top = savects_.top, \ + memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash))) + +/* Check C type ID for validity when assertions are enabled. */ +static LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id) +{ + lua_assert(id > 0 && id < cts->top); UNUSED(cts); + return id; +} + +/* Get C type for C type ID. */ +static LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id) +{ + return &cts->tab[ctype_check(cts, id)]; +} + +/* Get C type ID for a C type. */ +#define ctype_typeid(cts, ct) ((CTypeID)((ct) - (cts)->tab)) + +/* Get child C type. */ +static LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct) +{ + lua_assert(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) || + ctype_isbitfield(ct->info))); /* These don't have children. */ + return ctype_get(cts, ctype_cid(ct->info)); +} + +/* Get raw type for a C type ID. */ +static LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id) +{ + CType *ct = ctype_get(cts, id); + while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct); + return ct; +} + +/* Get raw type of the child of a C type. */ +static LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct) +{ + do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info)); + return ct; +} + +/* Set the name of a C type table element. */ +static LJ_AINLINE void ctype_setname(CType *ct, GCstr *s) +{ + /* NOBARRIER: mark string as fixed -- the C type table is never collected. */ + fixstring(s); + setgcref(ct->name, obj2gco(s)); +} + +LJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp); +LJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size); +LJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id); +LJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, + uint32_t tmask); +LJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, + CTSize *ofs, CTInfo *qual); +#define lj_ctype_getfield(cts, ct, name, ofs) \ + lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL) +LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id); +LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id); +LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem); +LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp); +LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm); +LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name); +LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned); +LJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size); +LJ_FUNC CTState *lj_ctype_init(lua_State *L); +LJ_FUNC void lj_ctype_freestate(global_State *g); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.c new file mode 100644 index 0000000..4653a4e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.c @@ -0,0 +1,603 @@ +/* +** Debugging and introspection. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_debug_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif + +/* -- Frames -------------------------------------------------------------- */ + +/* Get frame corresponding to a level. */ +cTValue *lj_debug_frame(lua_State *L, int level, int *size) +{ + cTValue *frame, *nextframe, *bot = tvref(L->stack); + /* Traverse frames backwards. */ + for (nextframe = frame = L->base-1; frame > bot; ) { + if (frame_gc(frame) == obj2gco(L)) + level++; /* Skip dummy frames. See lj_meta_call(). */ + if (level-- == 0) { + *size = (int)(nextframe - frame); + return frame; /* Level found. */ + } + nextframe = frame; + if (frame_islua(frame)) { + frame = frame_prevl(frame); + } else { + if (frame_isvarg(frame)) + level++; /* Skip vararg pseudo-frame. */ + frame = frame_prevd(frame); + } + } + *size = level; + return NULL; /* Level not found. */ +} + +/* Invalid bytecode position. */ +#define NO_BCPOS (~(BCPos)0) + +/* Return bytecode position for function/frame or NO_BCPOS. */ +static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) +{ + const BCIns *ins; + GCproto *pt; + BCPos pos; + lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD); + if (!isluafunc(fn)) { /* Cannot derive a PC for non-Lua functions. */ + return NO_BCPOS; + } else if (nextframe == NULL) { /* Lua function on top. */ + void *cf = cframe_raw(L->cframe); + if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf)) + return NO_BCPOS; + ins = cframe_pc(cf); /* Only happens during error/hook handling. */ + } else { + if (frame_islua(nextframe)) { + ins = frame_pc(nextframe); + } else if (frame_iscont(nextframe)) { + ins = frame_contpc(nextframe); + } else { + /* Lua function below errfunc/gc/hook: find cframe to get the PC. */ + void *cf = cframe_raw(L->cframe); + TValue *f = L->base-1; + for (;;) { + if (cf == NULL) + return NO_BCPOS; + while (cframe_nres(cf) < 0) { + if (f >= restorestack(L, -cframe_nres(cf))) + break; + cf = cframe_raw(cframe_prev(cf)); + if (cf == NULL) + return NO_BCPOS; + } + if (f < nextframe) + break; + if (frame_islua(f)) { + f = frame_prevl(f); + } else { + if (frame_isc(f)) + cf = cframe_raw(cframe_prev(cf)); + f = frame_prevd(f); + } + } + ins = cframe_pc(cf); + } + } + pt = funcproto(fn); + pos = proto_bcpos(pt, ins) - 1; +#if LJ_HASJIT + if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */ + GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); + lua_assert(bc_isret(bc_op(ins[-1]))); + pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + } +#endif + return pos; +} + +/* -- Line numbers -------------------------------------------------------- */ + +/* Get line number for a bytecode position. */ +BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc) +{ + const void *lineinfo = proto_lineinfo(pt); + if (pc <= pt->sizebc && lineinfo) { + BCLine first = pt->firstline; + if (pc == pt->sizebc) return first + pt->numline; + if (pc-- == 0) return first; + if (pt->numline < 256) + return first + (BCLine)((const uint8_t *)lineinfo)[pc]; + else if (pt->numline < 65536) + return first + (BCLine)((const uint16_t *)lineinfo)[pc]; + else + return first + (BCLine)((const uint32_t *)lineinfo)[pc]; + } + return 0; +} + +/* Get line number for function/frame. */ +static BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe) +{ + BCPos pc = debug_framepc(L, fn, nextframe); + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + lua_assert(pc <= pt->sizebc); + return lj_debug_line(pt, pc); + } + return -1; +} + +/* -- Variable names ------------------------------------------------------ */ + +/* Read ULEB128 value. */ +static uint32_t debug_read_uleb128(const uint8_t **pp) +{ + const uint8_t *p = *pp; + uint32_t v = *p++; + if (LJ_UNLIKELY(v >= 0x80)) { + int sh = 0; + v &= 0x7f; + do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80); + } + *pp = p; + return v; +} + +/* Get name of a local variable from slot number and PC. */ +static const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot) +{ + const uint8_t *p = proto_varinfo(pt); + if (p) { + BCPos lastpc = 0; + for (;;) { + const char *name = (const char *)p; + uint32_t vn = *p++; + BCPos startpc, endpc; + if (vn < VARNAME__MAX) { + if (vn == VARNAME_END) break; /* End of varinfo. */ + } else { + while (*p++) ; /* Skip over variable name string. */ + } + lastpc = startpc = lastpc + debug_read_uleb128(&p); + if (startpc > pc) break; + endpc = startpc + debug_read_uleb128(&p); + if (pc < endpc && slot-- == 0) { + if (vn < VARNAME__MAX) { +#define VARNAMESTR(name, str) str "\0" + name = VARNAMEDEF(VARNAMESTR); +#undef VARNAMESTR + if (--vn) while (*name++ || --vn) ; + } + return name; + } + } + } + return NULL; +} + +/* Get name of local variable from 1-based slot number and function/frame. */ +static TValue *debug_localname(lua_State *L, const lua_Debug *ar, + const char **name, BCReg slot1) +{ + uint32_t offset = (uint32_t)ar->i_ci & 0xffff; + uint32_t size = (uint32_t)ar->i_ci >> 16; + TValue *frame = tvref(L->stack) + offset; + TValue *nextframe = size ? frame + size : NULL; + GCfunc *fn = frame_func(frame); + BCPos pc = debug_framepc(L, fn, nextframe); + if (!nextframe) nextframe = L->top; + if ((int)slot1 < 0) { /* Negative slot number is for varargs. */ + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + if ((pt->flags & PROTO_VARARG)) { + slot1 = pt->numparams + (BCReg)(-(int)slot1); + if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */ + nextframe = frame; + frame = frame_prevd(frame); + } + if (frame + slot1 < nextframe) { + *name = "(*vararg)"; + return frame+slot1; + } + } + } + return NULL; + } + if (pc != NO_BCPOS && + (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL) + ; + else if (slot1 > 0 && frame + slot1 < nextframe) + *name = "(*temporary)"; + return frame+slot1; +} + +/* Get name of upvalue. */ +const char *lj_debug_uvname(GCproto *pt, uint32_t idx) +{ + const uint8_t *p = proto_uvinfo(pt); + lua_assert(idx < pt->sizeuv); + if (!p) return ""; + if (idx) while (*p++ || --idx) ; + return (const char *)p; +} + +/* Get name and value of upvalue. */ +const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp) +{ + if (tvisfunc(o)) { + GCfunc *fn = funcV(o); + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + if (idx < pt->sizeuv) { + *tvp = uvval(&gcref(fn->l.uvptr[idx])->uv); + return lj_debug_uvname(pt, idx); + } + } else { + if (idx < fn->c.nupvalues) { + *tvp = &fn->c.upvalue[idx]; + return ""; + } + } + } + return NULL; +} + +/* Deduce name of an object from slot number and PC. */ +const char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot, + const char **name) +{ + const char *lname; +restart: + lname = debug_varname(pt, proto_bcpos(pt, ip), slot); + if (lname != NULL) { *name = lname; return "local"; } + while (--ip > proto_bc(pt)) { + BCIns ins = *ip; + BCOp op = bc_op(ins); + BCReg ra = bc_a(ins); + if (bcmode_a(op) == BCMbase) { + if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins))) + return NULL; + } else if (bcmode_a(op) == BCMdst && ra == slot) { + switch (bc_op(ins)) { + case BC_MOV: + if (ra == slot) { slot = bc_d(ins); goto restart; } + break; + case BC_GGET: + *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins)))); + return "global"; + case BC_TGETS: + *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins)))); + if (ip > proto_bc(pt)) { + BCIns insp = ip[-1]; + if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 && + bc_d(insp) == bc_b(ins)) + return "method"; + } + return "field"; + case BC_UGET: + *name = lj_debug_uvname(pt, bc_d(ins)); + return "upvalue"; + default: + return NULL; + } + } + } + return NULL; +} + +/* Deduce function name from caller of a frame. */ +const char *lj_debug_funcname(lua_State *L, TValue *frame, const char **name) +{ + TValue *pframe; + GCfunc *fn; + BCPos pc; + if (frame <= tvref(L->stack)) + return NULL; + if (frame_isvarg(frame)) + frame = frame_prevd(frame); + pframe = frame_prev(frame); + fn = frame_func(pframe); + pc = debug_framepc(L, fn, frame); + if (pc != NO_BCPOS) { + GCproto *pt = funcproto(fn); + const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)]; + MMS mm = bcmode_mm(bc_op(*ip)); + if (mm == MM_call) { + BCReg slot = bc_a(*ip); + if (bc_op(*ip) == BC_ITERC) slot -= 3; + return lj_debug_slotname(pt, ip, slot, name); + } else if (mm != MM__MAX) { + *name = strdata(mmname_str(G(L), mm)); + return "metamethod"; + } + } + return NULL; +} + +/* -- Source code locations ----------------------------------------------- */ + +/* Generate shortened source name. */ +void lj_debug_shortname(char *out, GCstr *str) +{ + const char *src = strdata(str); + if (*src == '=') { + strncpy(out, src+1, LUA_IDSIZE); /* Remove first char. */ + out[LUA_IDSIZE-1] = '\0'; /* Ensures null termination. */ + } else if (*src == '@') { /* Output "source", or "...source". */ + size_t len = str->len-1; + src++; /* Skip the `@' */ + if (len >= LUA_IDSIZE) { + src += len-(LUA_IDSIZE-4); /* Get last part of file name. */ + *out++ = '.'; *out++ = '.'; *out++ = '.'; + } + strcpy(out, src); + } else { /* Output [string "string"]. */ + size_t len; /* Length, up to first control char. */ + for (len = 0; len < LUA_IDSIZE-12; len++) + if (((const unsigned char *)src)[len] < ' ') break; + strcpy(out, "[string \""); out += 9; + if (src[len] != '\0') { /* Must truncate? */ + if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15; + strncpy(out, src, len); out += len; + strcpy(out, "..."); out += 3; + } else { + strcpy(out, src); out += len; + } + strcpy(out, "\"]"); + } +} + +/* Add current location of a frame to error message. */ +void lj_debug_addloc(lua_State *L, const char *msg, + cTValue *frame, cTValue *nextframe) +{ + if (frame) { + GCfunc *fn = frame_func(frame); + if (isluafunc(fn)) { + BCLine line = debug_frameline(L, fn, nextframe); + if (line >= 0) { + char buf[LUA_IDSIZE]; + lj_debug_shortname(buf, proto_chunkname(funcproto(fn))); + lj_str_pushf(L, "%s:%d: %s", buf, line, msg); + return; + } + } + } + lj_str_pushf(L, "%s", msg); +} + +/* Push location string for a bytecode position to Lua stack. */ +void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc) +{ + GCstr *name = proto_chunkname(pt); + const char *s = strdata(name); + MSize i, len = name->len; + BCLine line = lj_debug_line(pt, pc); + if (*s == '@') { + s++; len--; + for (i = len; i > 0; i--) + if (s[i] == '/' || s[i] == '\\') { + s += i+1; + break; + } + lj_str_pushf(L, "%s:%d", s, line); + } else if (len > 40) { + lj_str_pushf(L, "%p:%d", pt, line); + } else if (*s == '=') { + lj_str_pushf(L, "%s:%d", s+1, line); + } else { + lj_str_pushf(L, "\"%s\":%d", s, line); + } +} + +/* -- Public debug API ---------------------------------------------------- */ + +/* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */ + +LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) +{ + const char *name = NULL; + if (ar) { + TValue *o = debug_localname(L, ar, &name, (BCReg)n); + if (name) { + copyTV(L, L->top, o); + incr_top(L); + } + } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) { + name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1); + } + return name; +} + +LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) +{ + const char *name = NULL; + TValue *o = debug_localname(L, ar, &name, (BCReg)n); + if (name) + copyTV(L, o, L->top-1); + L->top--; + return name; +} + +int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext) +{ + int opt_f = 0, opt_L = 0; + TValue *frame = NULL; + TValue *nextframe = NULL; + GCfunc *fn; + if (*what == '>') { + TValue *func = L->top - 1; + api_check(L, tvisfunc(func)); + fn = funcV(func); + L->top--; + what++; + } else { + uint32_t offset = (uint32_t)ar->i_ci & 0xffff; + uint32_t size = (uint32_t)ar->i_ci >> 16; + lua_assert(offset != 0); + frame = tvref(L->stack) + offset; + if (size) nextframe = frame + size; + lua_assert(frame <= tvref(L->maxstack) && + (!nextframe || nextframe <= tvref(L->maxstack))); + fn = frame_func(frame); + lua_assert(fn->c.gct == ~LJ_TFUNC); + } + for (; *what; what++) { + if (*what == 'S') { + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + BCLine firstline = pt->firstline; + GCstr *name = proto_chunkname(pt); + ar->source = strdata(name); + lj_debug_shortname(ar->short_src, name); + ar->linedefined = (int)firstline; + ar->lastlinedefined = (int)(firstline + pt->numline); + ar->what = firstline ? "Lua" : "main"; + } else { + ar->source = "=[C]"; + ar->short_src[0] = '['; + ar->short_src[1] = 'C'; + ar->short_src[2] = ']'; + ar->short_src[3] = '\0'; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + } else if (*what == 'l') { + ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1; + } else if (*what == 'u') { + ar->nups = fn->c.nupvalues; + if (ext) { + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + ar->nparams = pt->numparams; + ar->isvararg = !!(pt->flags & PROTO_VARARG); + } else { + ar->nparams = 0; + ar->isvararg = 1; + } + } + } else if (*what == 'n') { + ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; + ar->name = NULL; + } + } else if (*what == 'f') { + opt_f = 1; + } else if (*what == 'L') { + opt_L = 1; + } else { + return 0; /* Bad option. */ + } + } + if (opt_f) { + setfuncV(L, L->top, fn); + incr_top(L); + } + if (opt_L) { + if (isluafunc(fn)) { + GCtab *t = lj_tab_new(L, 0, 0); + GCproto *pt = funcproto(fn); + const void *lineinfo = proto_lineinfo(pt); + if (lineinfo) { + BCLine first = pt->firstline; + int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4; + MSize i, szl = pt->sizebc-1; + for (i = 0; i < szl; i++) { + BCLine line = first + + (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] : + sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] : + (BCLine)((const uint32_t *)lineinfo)[i]); + setboolV(lj_tab_setint(L, t, line), 1); + } + } + settabV(L, L->top, t); + } else { + setnilV(L->top); + } + incr_top(L); + } + return 1; /* Ok. */ +} + +LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) +{ + return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0); +} + +LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) +{ + int size; + cTValue *frame = lj_debug_frame(L, level, &size); + if (frame) { + ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack)); + return 1; + } else { + ar->i_ci = level - size; + return 0; + } +} + +/* Number of frames for the leading and trailing part of a traceback. */ +#define TRACEBACK_LEVELS1 12 +#define TRACEBACK_LEVELS2 10 + +LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, + int level) +{ + int top = (int)(L->top - L->base); + int lim = TRACEBACK_LEVELS1; + lua_Debug ar; + if (msg) lua_pushfstring(L, "%s\n", msg); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + GCfunc *fn; + if (level > lim) { + if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) { + level--; + } else { + lua_pushliteral(L, "\n\t..."); + lua_getstack(L1, -10, &ar); + level = ar.i_ci - TRACEBACK_LEVELS2; + } + lim = 2147483647; + continue; + } + lua_getinfo(L1, "Snlf", &ar); + fn = funcV(L1->top-1); L1->top--; + if (isffunc(fn) && !*ar.namewhat) + lua_pushfstring(L, "\n\t[builtin#%d]:", fn->c.ffid); + else + lua_pushfstring(L, "\n\t%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat) { + lua_pushfstring(L, " in function " LUA_QS, ar.name); + } else { + if (*ar.what == 'm') { + lua_pushliteral(L, " in main chunk"); + } else if (*ar.what == 'C') { + lua_pushfstring(L, " at %p", fn->c.f); + } else { + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + } + if ((int)(L->top - L->base) - top >= 15) + lua_concat(L, (int)(L->top - L->base) - top); + } + lua_concat(L, (int)(L->top - L->base) - top); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.h new file mode 100644 index 0000000..bec6b4f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_debug.h @@ -0,0 +1,61 @@ +/* +** Debugging and introspection. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DEBUG_H +#define _LJ_DEBUG_H + +#include "lj_obj.h" + +typedef struct lj_Debug { + /* Common fields. Must be in the same order as in lua.h. */ + int event; + const char *name; + const char *namewhat; + const char *what; + const char *source; + int currentline; + int nups; + int linedefined; + int lastlinedefined; + char short_src[LUA_IDSIZE]; + int i_ci; + /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/ + int nparams; + int isvararg; +} lj_Debug; + +LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); +LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); +LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); +LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp); +LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc, + BCReg slot, const char **name); +LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame, + const char **name); +LJ_FUNC void lj_debug_shortname(char *out, GCstr *str); +LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg, + cTValue *frame, cTValue *nextframe); +LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc); +LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, + int ext); + +/* Fixed internal variable names. */ +#define VARNAMEDEF(_) \ + _(FOR_IDX, "(for index)") \ + _(FOR_STOP, "(for limit)") \ + _(FOR_STEP, "(for step)") \ + _(FOR_GEN, "(for generator)") \ + _(FOR_STATE, "(for state)") \ + _(FOR_CTL, "(for control)") + +enum { + VARNAME_END, +#define VARNAMEENUM(name, str) VARNAME_##name, + VARNAMEDEF(VARNAMEENUM) +#undef VARNAMEENUM + VARNAME__MAX +}; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_def.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_def.h new file mode 100644 index 0000000..3c43be7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_def.h @@ -0,0 +1,349 @@ +/* +** LuaJIT common internal definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DEF_H +#define _LJ_DEF_H + +#include "lua.h" + +#if defined(_MSC_VER) +/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#ifdef _WIN64 +typedef __int64 intptr_t; +typedef unsigned __int64 uintptr_t; +#else +typedef __int32 intptr_t; +typedef unsigned __int32 uintptr_t; +#endif +#elif defined(__symbian__) +/* Cough. */ +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef int intptr_t; +typedef unsigned int uintptr_t; +#else +#include +#endif + +/* Needed everywhere. */ +#include +#include + +/* Various VM limits. */ +#define LJ_MAX_MEM 0x7fffff00 /* Max. total memory allocation. */ +#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */ +#define LJ_MAX_STR LJ_MAX_MEM /* Max. string length. */ +#define LJ_MAX_UDATA LJ_MAX_MEM /* Max. userdata length. */ + +#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */ +#define LJ_MAX_HBITS 26 /* Max. hash bits. */ +#define LJ_MAX_ABITS 28 /* Max. bits of array key. */ +#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */ +#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */ + +#define LJ_MAX_LINE LJ_MAX_MEM /* Max. source code line number. */ +#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */ +#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */ +#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */ +#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */ +#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */ + +#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */ +#define LJ_STACK_EXTRA 5 /* Extra stack space (metamethods). */ + +#define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */ + +/* Minimum table/buffer sizes. */ +#define LJ_MIN_GLOBAL 6 /* Min. global table size (hbits). */ +#define LJ_MIN_REGISTRY 2 /* Min. registry size (hbits). */ +#define LJ_MIN_STRTAB 256 /* Min. string table size (pow2). */ +#define LJ_MIN_SBUF 32 /* Min. string buffer length. */ +#define LJ_MIN_VECSZ 8 /* Min. size for growable vectors. */ +#define LJ_MIN_IRSZ 32 /* Min. size for growable IR. */ +#define LJ_MIN_K64SZ 16 /* Min. size for chained K64Array. */ + +/* JIT compiler limits. */ +#define LJ_MAX_JSLOTS 250 /* Max. # of stack slots for a trace. */ +#define LJ_MAX_PHI 64 /* Max. # of PHIs for a loop. */ +#define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */ + +/* Various macros. */ +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + +#define U64x(hi, lo) (((uint64_t)0x##hi << 32) + (uint64_t)0x##lo) +#define i32ptr(p) ((int32_t)(intptr_t)(void *)(p)) +#define u32ptr(p) ((uint32_t)(intptr_t)(void *)(p)) + +#define checki8(x) ((x) == (int32_t)(int8_t)(x)) +#define checku8(x) ((x) == (int32_t)(uint8_t)(x)) +#define checki16(x) ((x) == (int32_t)(int16_t)(x)) +#define checku16(x) ((x) == (int32_t)(uint16_t)(x)) +#define checki32(x) ((x) == (int32_t)(x)) +#define checku32(x) ((x) == (uint32_t)(x)) +#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) + +/* Every half-decent C compiler transforms this into a rotate instruction. */ +#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1)))) +#define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n))) + +/* A really naive Bloom filter. But sufficient for our needs. */ +typedef uintptr_t BloomFilter; +#define BLOOM_MASK (8*sizeof(BloomFilter) - 1) +#define bloombit(x) ((uintptr_t)1 << ((x) & BLOOM_MASK)) +#define bloomset(b, x) ((b) |= bloombit((x))) +#define bloomtest(b, x) ((b) & bloombit((x))) + +#if defined(__GNUC__) + +#define LJ_NORET __attribute__((noreturn)) +#define LJ_ALIGN(n) __attribute__((aligned(n))) +#define LJ_INLINE inline +#define LJ_AINLINE inline __attribute__((always_inline)) +#define LJ_NOINLINE __attribute__((noinline)) + +#if defined(__ELF__) || defined(__MACH__) +#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__)) +#define LJ_NOAPI extern __attribute__((visibility("hidden"))) +#endif +#endif + +/* Note: it's only beneficial to use fastcall on x86 and then only for up to +** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only +** indirect calls and related tail-called C functions are marked as fastcall. +*/ +#if defined(__i386__) +#define LJ_FASTCALL __attribute__((fastcall)) +#endif + +#define LJ_LIKELY(x) __builtin_expect(!!(x), 1) +#define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0) + +#define lj_ffs(x) ((uint32_t)__builtin_ctz(x)) +/* Don't ask ... */ +#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__)) +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r; +} +#else +#define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31)) +#endif + +#if defined(__arm__) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + uint32_t r; +#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\ + __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ + __asm__("rev %0, %1" : "=r" (r) : "r" (x)); + return r; +#else +#ifdef __thumb__ + r = x ^ lj_ror(x, 16); +#else + __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x)); +#endif + return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8); +#endif +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32)); +} +#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + return (uint32_t)__builtin_bswap32((int32_t)x); +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return (uint64_t)__builtin_bswap64((int64_t)x); +} +#elif defined(__i386__) || defined(__x86_64__) +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; +} + +#if defined(__i386__) +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32)); +} +#else +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; +} +#endif +#else +static LJ_AINLINE uint32_t lj_bswap(uint32_t x) +{ + return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24); +} + +static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) +{ + return (uint64_t)lj_bswap((uint32_t)(x >> 32)) | + ((uint64_t)lj_bswap((uint32_t)x) << 32); +} +#endif + +typedef union __attribute__((packed)) Unaligned16 { + uint16_t u; + uint8_t b[2]; +} Unaligned16; + +typedef union __attribute__((packed)) Unaligned32 { + uint32_t u; + uint8_t b[4]; +} Unaligned32; + +/* Unaligned load of uint16_t. */ +static LJ_AINLINE uint16_t lj_getu16(const void *p) +{ + return ((const Unaligned16 *)p)->u; +} + +/* Unaligned load of uint32_t. */ +static LJ_AINLINE uint32_t lj_getu32(const void *p) +{ + return ((const Unaligned32 *)p)->u; +} + +#elif defined(_MSC_VER) + +#define LJ_NORET __declspec(noreturn) +#define LJ_ALIGN(n) __declspec(align(n)) +#define LJ_INLINE __inline +#define LJ_AINLINE __forceinline +#define LJ_NOINLINE __declspec(noinline) +#if defined(_M_IX86) +#define LJ_FASTCALL __fastcall +#endif + +#ifdef _M_PPC +unsigned int _CountLeadingZeros(long); +#pragma intrinsic(_CountLeadingZeros) +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + return _CountLeadingZeros(x) ^ 31; +} +#else +unsigned char _BitScanForward(uint32_t *, unsigned long); +unsigned char _BitScanReverse(uint32_t *, unsigned long); +#pragma intrinsic(_BitScanForward) +#pragma intrinsic(_BitScanReverse) + +static LJ_AINLINE uint32_t lj_ffs(uint32_t x) +{ + uint32_t r; _BitScanForward(&r, x); return r; +} + +static LJ_AINLINE uint32_t lj_fls(uint32_t x) +{ + uint32_t r; _BitScanReverse(&r, x); return r; +} +#endif + +unsigned long _byteswap_ulong(unsigned long); +uint64_t _byteswap_uint64(uint64_t); +#define lj_bswap(x) (_byteswap_ulong((x))) +#define lj_bswap64(x) (_byteswap_uint64((x))) + +#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED) +/* +** Replacement for unaligned loads on Xbox 360. Disabled by default since it's +** usually more costly than the occasional stall when crossing a cache-line. +*/ +static LJ_AINLINE uint16_t lj_getu16(const void *v) +{ + const uint8_t *p = (const uint8_t *)v; + return (uint16_t)((p[0]<<8) | p[1]); +} +static LJ_AINLINE uint32_t lj_getu32(const void *v) +{ + const uint8_t *p = (const uint8_t *)v; + return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]); +} +#else +/* Unaligned loads are generally ok on x86/x64. */ +#define lj_getu16(p) (*(uint16_t *)(p)) +#define lj_getu32(p) (*(uint32_t *)(p)) +#endif + +#else +#error "missing defines for your compiler" +#endif + +/* Optional defines. */ +#ifndef LJ_FASTCALL +#define LJ_FASTCALL +#endif +#ifndef LJ_NORET +#define LJ_NORET +#endif +#ifndef LJ_NOAPI +#define LJ_NOAPI extern +#endif +#ifndef LJ_LIKELY +#define LJ_LIKELY(x) (x) +#define LJ_UNLIKELY(x) (x) +#endif + +/* Attributes for internal functions. */ +#define LJ_DATA LJ_NOAPI +#define LJ_DATADEF +#define LJ_ASMF LJ_NOAPI +#define LJ_FUNCA LJ_NOAPI +#if defined(ljamalg_c) +#define LJ_FUNC static +#else +#define LJ_FUNC LJ_NOAPI +#endif +#define LJ_FUNC_NORET LJ_FUNC LJ_NORET +#define LJ_FUNCA_NORET LJ_FUNCA LJ_NORET +#define LJ_ASMF_NORET LJ_ASMF LJ_NORET + +/* Runtime assertions. */ +#ifdef lua_assert +#define check_exp(c, e) (lua_assert(c), (e)) +#define api_check(l, e) lua_assert(e) +#else +#define lua_assert(c) ((void)0) +#define check_exp(c, e) (e) +#define api_check luai_apicheck +#endif + +/* Static assertions. */ +#define LJ_ASSERT_NAME2(name, line) name ## line +#define LJ_ASSERT_NAME(line) LJ_ASSERT_NAME2(lj_assert_, line) +#ifdef __COUNTER__ +#define LJ_STATIC_ASSERT(cond) \ + extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) +#else +#define LJ_STATIC_ASSERT(cond) \ + extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.c new file mode 100644 index 0000000..58d6c3e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.c @@ -0,0 +1,494 @@ +/* +** Instruction dispatch handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_dispatch_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_func.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_debug.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ff.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif +#if LJ_HASFFI +#include "lj_ccallback.h" +#endif +#include "lj_trace.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "luajit.h" + +/* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */ +LJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC); + +/* -- Dispatch table management ------------------------------------------- */ + +#if LJ_TARGET_MIPS +#include +LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, + lua_State *co); + +#define GOTFUNC(name) (ASMFunction)name, +static const ASMFunction dispatch_got[] = { + GOTDEF(GOTFUNC) +}; +#undef GOTFUNC +#endif + +/* Initialize instruction dispatch table and hot counters. */ +void lj_dispatch_init(GG_State *GG) +{ + uint32_t i; + ASMFunction *disp = GG->dispatch; + for (i = 0; i < GG_LEN_SDISP; i++) + disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]); + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = makeasmfunc(lj_bc_ofs[i]); + /* The JIT engine is off by default. luaopen_jit() turns it on. */ + disp[BC_FORL] = disp[BC_IFORL]; + disp[BC_ITERL] = disp[BC_IITERL]; + disp[BC_LOOP] = disp[BC_ILOOP]; + disp[BC_FUNCF] = disp[BC_IFUNCF]; + disp[BC_FUNCV] = disp[BC_IFUNCV]; + GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0); + for (i = 0; i < GG_NUM_ASMFF; i++) + GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0); +#if LJ_TARGET_MIPS + memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4); +#endif +} + +#if LJ_HASJIT +/* Initialize hotcount table. */ +void lj_dispatch_init_hotcount(global_State *g) +{ + int32_t hotloop = G2J(g)->param[JIT_P_hotloop]; + HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1); + HotCount *hotcount = G2GG(g)->hotcount; + uint32_t i; + for (i = 0; i < HOTCOUNT_SIZE; i++) + hotcount[i] = start; +} +#endif + +/* Internal dispatch mode bits. */ +#define DISPMODE_JIT 0x01 /* JIT compiler on. */ +#define DISPMODE_REC 0x02 /* Recording active. */ +#define DISPMODE_INS 0x04 /* Override instruction dispatch. */ +#define DISPMODE_CALL 0x08 /* Override call dispatch. */ +#define DISPMODE_RET 0x10 /* Override return dispatch. */ + +/* Update dispatch table depending on various flags. */ +void lj_dispatch_update(global_State *g) +{ + uint8_t oldmode = g->dispatchmode; + uint8_t mode = 0; +#if LJ_HASJIT + mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0; + mode |= G2J(g)->state != LJ_TRACE_IDLE ? + (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0; +#endif + mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0; + mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0; + mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0; + if (oldmode != mode) { /* Mode changed? */ + ASMFunction *disp = G2GG(g)->dispatch; + ASMFunction f_forl, f_iterl, f_loop, f_funcf, f_funcv; + g->dispatchmode = mode; + + /* Hotcount if JIT is on, but not while recording. */ + if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) { + f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]); + f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]); + f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]); + f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]); + f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]); + } else { /* Otherwise use the non-hotcounting instructions. */ + f_forl = disp[GG_LEN_DDISP+BC_IFORL]; + f_iterl = disp[GG_LEN_DDISP+BC_IITERL]; + f_loop = disp[GG_LEN_DDISP+BC_ILOOP]; + f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]); + f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]); + } + /* Init static counting instruction dispatch first (may be copied below). */ + disp[GG_LEN_DDISP+BC_FORL] = f_forl; + disp[GG_LEN_DDISP+BC_ITERL] = f_iterl; + disp[GG_LEN_DDISP+BC_LOOP] = f_loop; + + /* Set dynamic instruction dispatch. */ + if ((oldmode ^ mode) & (DISPMODE_REC|DISPMODE_INS)) { + /* Need to update the whole table. */ + if (!(mode & (DISPMODE_REC|DISPMODE_INS))) { /* No ins dispatch? */ + /* Copy static dispatch table to dynamic dispatch table. */ + memcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction)); + /* Overwrite with dynamic return dispatch. */ + if ((mode & DISPMODE_RET)) { + disp[BC_RETM] = lj_vm_rethook; + disp[BC_RET] = lj_vm_rethook; + disp[BC_RET0] = lj_vm_rethook; + disp[BC_RET1] = lj_vm_rethook; + } + } else { + /* The recording dispatch also checks for hooks. */ + ASMFunction f = (mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook; + uint32_t i; + for (i = 0; i < GG_LEN_SDISP; i++) + disp[i] = f; + } + } else if (!(mode & (DISPMODE_REC|DISPMODE_INS))) { + /* Otherwise set dynamic counting ins. */ + disp[BC_FORL] = f_forl; + disp[BC_ITERL] = f_iterl; + disp[BC_LOOP] = f_loop; + /* Set dynamic return dispatch. */ + if ((mode & DISPMODE_RET)) { + disp[BC_RETM] = lj_vm_rethook; + disp[BC_RET] = lj_vm_rethook; + disp[BC_RET0] = lj_vm_rethook; + disp[BC_RET1] = lj_vm_rethook; + } else { + disp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM]; + disp[BC_RET] = disp[GG_LEN_DDISP+BC_RET]; + disp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0]; + disp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1]; + } + } + + /* Set dynamic call dispatch. */ + if ((oldmode ^ mode) & DISPMODE_CALL) { /* Update the whole table? */ + uint32_t i; + if ((mode & DISPMODE_CALL) == 0) { /* No call hooks? */ + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = makeasmfunc(lj_bc_ofs[i]); + } else { + for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++) + disp[i] = lj_vm_callhook; + } + } + if (!(mode & DISPMODE_CALL)) { /* Overwrite dynamic counting ins. */ + disp[BC_FUNCF] = f_funcf; + disp[BC_FUNCV] = f_funcv; + } + +#if LJ_HASJIT + /* Reset hotcounts for JIT off to on transition. */ + if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT)) + lj_dispatch_init_hotcount(g); +#endif + } +} + +/* -- JIT mode setting ---------------------------------------------------- */ + +#if LJ_HASJIT +/* Set JIT mode for a single prototype. */ +static void setptmode(global_State *g, GCproto *pt, int mode) +{ + if ((mode & LUAJIT_MODE_ON)) { /* (Re-)enable JIT compilation. */ + pt->flags &= ~PROTO_NOJIT; + lj_trace_reenableproto(pt); /* Unpatch all ILOOP etc. bytecodes. */ + } else { /* Flush and/or disable JIT compilation. */ + if (!(mode & LUAJIT_MODE_FLUSH)) + pt->flags |= PROTO_NOJIT; + lj_trace_flushproto(g, pt); /* Flush all traces of prototype. */ + } +} + +/* Recursively set the JIT mode for all children of a prototype. */ +static void setptmode_all(global_State *g, GCproto *pt, int mode) +{ + ptrdiff_t i; + if (!(pt->flags & PROTO_CHILD)) return; + for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) { + GCobj *o = proto_kgc(pt, i); + if (o->gch.gct == ~LJ_TPROTO) { + setptmode(g, gco2pt(o), mode); + setptmode_all(g, gco2pt(o), mode); + } + } +} +#endif + +/* Public API function: control the JIT engine. */ +int luaJIT_setmode(lua_State *L, int idx, int mode) +{ + global_State *g = G(L); + int mm = mode & LUAJIT_MODE_MASK; + lj_trace_abort(g); /* Abort recording on any state change. */ + /* Avoid pulling the rug from under our own feet. */ + if ((g->hookmask & HOOK_GC)) + lj_err_caller(L, LJ_ERR_NOGCMM); + switch (mm) { +#if LJ_HASJIT + case LUAJIT_MODE_ENGINE: + if ((mode & LUAJIT_MODE_FLUSH)) { + lj_trace_flushall(L); + } else { + if (!(mode & LUAJIT_MODE_ON)) + G2J(g)->flags &= ~(uint32_t)JIT_F_ON; +#if LJ_TARGET_X86ORX64 + else if ((G2J(g)->flags & JIT_F_SSE2)) + G2J(g)->flags |= (uint32_t)JIT_F_ON; + else + return 0; /* Don't turn on JIT compiler without SSE2 support. */ +#else + else + G2J(g)->flags |= (uint32_t)JIT_F_ON; +#endif + lj_dispatch_update(g); + } + break; + case LUAJIT_MODE_FUNC: + case LUAJIT_MODE_ALLFUNC: + case LUAJIT_MODE_ALLSUBFUNC: { + cTValue *tv = idx == 0 ? frame_prev(L->base-1) : + idx > 0 ? L->base + (idx-1) : L->top + idx; + GCproto *pt; + if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn)) + pt = funcproto(&gcval(tv)->fn); /* Cannot use funcV() for frame slot. */ + else if (tvisproto(tv)) + pt = protoV(tv); + else + return 0; /* Failed. */ + if (mm != LUAJIT_MODE_ALLSUBFUNC) + setptmode(g, pt, mode); + if (mm != LUAJIT_MODE_FUNC) + setptmode_all(g, pt, mode); + break; + } + case LUAJIT_MODE_TRACE: + if (!(mode & LUAJIT_MODE_FLUSH)) + return 0; /* Failed. */ + lj_trace_flush(G2J(g), idx); + break; +#else + case LUAJIT_MODE_ENGINE: + case LUAJIT_MODE_FUNC: + case LUAJIT_MODE_ALLFUNC: + case LUAJIT_MODE_ALLSUBFUNC: + UNUSED(idx); + if ((mode & LUAJIT_MODE_ON)) + return 0; /* Failed. */ + break; +#endif + case LUAJIT_MODE_WRAPCFUNC: + if ((mode & LUAJIT_MODE_ON)) { + if (idx != 0) { + cTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx; + if (tvislightud(tv)) + g->wrapf = (lua_CFunction)lightudV(tv); + else + return 0; /* Failed. */ + } else { + return 0; /* Failed. */ + } + g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0); + } else { + g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0); + } + break; + default: + return 0; /* Failed. */ + } + return 1; /* OK. */ +} + +/* Enforce (dynamic) linker error for version mismatches. See luajit.c. */ +LUA_API void LUAJIT_VERSION_SYM(void) +{ +} + +/* -- Hooks --------------------------------------------------------------- */ + +/* This function can be called asynchronously (e.g. during a signal). */ +LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count) +{ + global_State *g = G(L); + mask &= HOOK_EVENTMASK; + if (func == NULL || mask == 0) { mask = 0; func = NULL; } /* Consistency. */ + g->hookf = func; + g->hookcount = g->hookcstart = (int32_t)count; + g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask); + lj_trace_abort(g); /* Abort recording on any hook change. */ + lj_dispatch_update(g); + return 1; +} + +LUA_API lua_Hook lua_gethook(lua_State *L) +{ + return G(L)->hookf; +} + +LUA_API int lua_gethookmask(lua_State *L) +{ + return G(L)->hookmask & HOOK_EVENTMASK; +} + +LUA_API int lua_gethookcount(lua_State *L) +{ + return (int)G(L)->hookcstart; +} + +/* Call a hook. */ +static void callhook(lua_State *L, int event, BCLine line) +{ + global_State *g = G(L); + lua_Hook hookf = g->hookf; + if (hookf && !hook_active(g)) { + lua_Debug ar; + lj_trace_abort(g); /* Abort recording on any hook call. */ + ar.event = event; + ar.currentline = line; + /* Top frame, nextframe = NULL. */ + ar.i_ci = (int)((L->base-1) - tvref(L->stack)); + lj_state_checkstack(L, 1+LUA_MINSTACK); + hook_enter(g); + hookf(L, &ar); + lua_assert(hook_active(g)); + hook_leave(g); + } +} + +/* -- Dispatch callbacks -------------------------------------------------- */ + +/* Calculate number of used stack slots in the current frame. */ +static BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres) +{ + BCIns ins = pc[-1]; + if (bc_op(ins) == BC_UCLO) + ins = pc[bc_j(ins)]; + switch (bc_op(ins)) { + case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1; + case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1; + case BC_TSETM: return bc_a(ins) + nres-1; + default: return pt->framesize; + } +} + +/* Instruction dispatch. Used by instr/line/return hooks or when recording. */ +void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc) +{ + ERRNO_SAVE + GCfunc *fn = curr_func(L); + GCproto *pt = funcproto(fn); + void *cf = cframe_raw(L->cframe); + const BCIns *oldpc = cframe_pc(cf); + global_State *g = G(L); + BCReg slots; + setcframe_pc(cf, pc); + slots = cur_topslot(pt, pc, cframe_multres_n(cf)); + L->top = L->base + slots; /* Fix top. */ +#if LJ_HASJIT + { + jit_State *J = G2J(g); + if (J->state != LJ_TRACE_IDLE) { +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + J->L = L; + lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */ + lua_assert(L->top - L->base == delta); + } + } +#endif + if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) { + g->hookcount = g->hookcstart; + callhook(L, LUA_HOOKCOUNT, -1); + L->top = L->base + slots; /* Fix top again. */ + } + if ((g->hookmask & LUA_MASKLINE)) { + BCPos npc = proto_bcpos(pt, pc) - 1; + BCPos opc = proto_bcpos(pt, oldpc) - 1; + BCLine line = lj_debug_line(pt, npc); + if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) { + callhook(L, LUA_HOOKLINE, line); + L->top = L->base + slots; /* Fix top again. */ + } + } + if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1]))) + callhook(L, LUA_HOOKRET, -1); + ERRNO_RESTORE +} + +/* Initialize call. Ensure stack space and return # of missing parameters. */ +static int call_init(lua_State *L, GCfunc *fn) +{ + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + int numparams = pt->numparams; + int gotparams = (int)(L->top - L->base); + int need = pt->framesize; + if ((pt->flags & PROTO_VARARG)) need += 1+gotparams; + lj_state_checkstack(L, (MSize)need); + numparams -= gotparams; + return numparams >= 0 ? numparams : 0; + } else { + lj_state_checkstack(L, LUA_MINSTACK); + return 0; + } +} + +/* Call dispatch. Used by call hooks, hot calls or when recording. */ +ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc) +{ + ERRNO_SAVE + GCfunc *fn = curr_func(L); + BCOp op; + global_State *g = G(L); +#if LJ_HASJIT + jit_State *J = G2J(g); +#endif + int missing = call_init(L, fn); +#if LJ_HASJIT + J->L = L; + if ((uintptr_t)pc & 1) { /* Marker for hot call. */ +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1); + lj_trace_hot(J, pc); + lua_assert(L->top - L->base == delta); + goto out; + } else if (J->state != LJ_TRACE_IDLE && + !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) { +#ifdef LUA_USE_ASSERT + ptrdiff_t delta = L->top - L->base; +#endif + /* Record the FUNC* bytecodes, too. */ + lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */ + lua_assert(L->top - L->base == delta); + } +#endif + if ((g->hookmask & LUA_MASKCALL)) { + int i; + for (i = 0; i < missing; i++) /* Add missing parameters. */ + setnilV(L->top++); + callhook(L, LUA_HOOKCALL, -1); + /* Preserve modifications of missing parameters by lua_setlocal(). */ + while (missing-- > 0 && tvisnil(L->top - 1)) + L->top--; + } +#if LJ_HASJIT +out: +#endif + op = bc_op(pc[-1]); /* Get FUNC* op. */ +#if LJ_HASJIT + /* Use the non-hotcounting variants if JIT is off or while recording. */ + if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) && + (op == BC_FUNCF || op == BC_FUNCV)) + op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF); +#endif + ERRNO_RESTORE + return makeasmfunc(lj_bc_ofs[op]); /* Return static dispatch target. */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.h new file mode 100644 index 0000000..5960e64 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_dispatch.h @@ -0,0 +1,131 @@ +/* +** Instruction dispatch handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_DISPATCH_H +#define _LJ_DISPATCH_H + +#include "lj_obj.h" +#include "lj_bc.h" +#if LJ_HASJIT +#include "lj_jit.h" +#endif + +#if LJ_TARGET_MIPS +/* Need our own global offset table for the dreaded MIPS calling conventions. */ +#if LJ_HASJIT +#define JITGOTDEF(_) _(lj_trace_exit) _(lj_trace_hot) +#else +#define JITGOTDEF(_) +#endif +#if LJ_HASFFI +#define FFIGOTDEF(_) \ + _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave) +#else +#define FFIGOTDEF(_) +#endif +#define GOTDEF(_) \ + _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \ + _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \ + _(pow) _(fmod) _(ldexp) \ + _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_err_throw) \ + _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \ + _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \ + _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \ + _(lj_meta_for) _(lj_meta_len) _(lj_meta_tget) _(lj_meta_tset) \ + _(lj_state_growstack) _(lj_str_fromnum) _(lj_str_fromnumber) _(lj_str_new) \ + _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) _(lj_tab_new) \ + _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \ + JITGOTDEF(_) FFIGOTDEF(_) + +enum { +#define GOTENUM(name) LJ_GOT_##name, +GOTDEF(GOTENUM) +#undef GOTENUM + LJ_GOT__MAX +}; +#endif + +/* Type of hot counter. Must match the code in the assembler VM. */ +/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */ +typedef uint16_t HotCount; + +/* Number of hot counter hash table entries (must be a power of two). */ +#define HOTCOUNT_SIZE 64 +#define HOTCOUNT_PCMASK ((HOTCOUNT_SIZE-1)*sizeof(HotCount)) + +/* Hotcount decrements. */ +#define HOTCOUNT_LOOP 2 +#define HOTCOUNT_CALL 1 + +/* This solves a circular dependency problem -- bump as needed. Sigh. */ +#define GG_NUM_ASMFF 62 + +#define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF) +#define GG_LEN_SDISP BC_FUNCF +#define GG_LEN_DISP (GG_LEN_DDISP + GG_LEN_SDISP) + +/* Global state, main thread and extra fields are allocated together. */ +typedef struct GG_State { + lua_State L; /* Main thread. */ + global_State g; /* Global state. */ +#if LJ_TARGET_MIPS + ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */ +#endif +#if LJ_HASJIT + jit_State J; /* JIT state. */ + HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */ +#endif + ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */ + BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */ +} GG_State; + +#define GG_OFS(field) ((int)offsetof(GG_State, field)) +#define G2GG(gl) ((GG_State *)((char *)(gl) - GG_OFS(g))) +#define J2GG(j) ((GG_State *)((char *)(j) - GG_OFS(J))) +#define L2GG(L) (G2GG(G(L))) +#define J2G(J) (&J2GG(J)->g) +#define G2J(gl) (&G2GG(gl)->J) +#define L2J(L) (&L2GG(L)->J) +#define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g)) +#define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch)) +#define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch)) +#define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch)) +#define GG_DISP2STATIC (GG_LEN_DDISP*(int)sizeof(ASMFunction)) + +#define hotcount_get(gg, pc) \ + (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)] +#define hotcount_set(gg, pc, val) \ + (hotcount_get((gg), (pc)) = (HotCount)(val)) + +/* Dispatch table management. */ +LJ_FUNC void lj_dispatch_init(GG_State *GG); +#if LJ_HASJIT +LJ_FUNC void lj_dispatch_init_hotcount(global_State *g); +#endif +LJ_FUNC void lj_dispatch_update(global_State *g); + +/* Instruction dispatch callback for hooks or when recording. */ +LJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc); +LJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc); +LJ_FUNCA void LJ_FASTCALL lj_dispatch_return(lua_State *L, const BCIns *pc); + +#if LJ_HASFFI && !defined(_BUILDVM_H) +/* Save/restore errno and GetLastError() around hooks, exits and recording. */ +#include +#if LJ_TARGET_WINDOWS +#define WIN32_LEAN_AND_MEAN +#include +#define ERRNO_SAVE int olderr = errno; DWORD oldwerr = GetLastError(); +#define ERRNO_RESTORE errno = olderr; SetLastError(oldwerr); +#else +#define ERRNO_SAVE int olderr = errno; +#define ERRNO_RESTORE errno = olderr; +#endif +#else +#define ERRNO_SAVE +#define ERRNO_RESTORE +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_arm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_arm.h new file mode 100644 index 0000000..3bac367 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_arm.h @@ -0,0 +1,356 @@ +/* +** ARM instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Constant encoding --------------------------------------------------- */ + +static uint8_t emit_invai[16] = { + /* AND */ (ARMI_AND^ARMI_BIC) >> 21, + /* EOR */ 0, + /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21, + /* RSB */ 0, + /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21, + /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21, + /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21, + /* RSC */ 0, + /* TST */ 0, + /* TEQ */ 0, + /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21, + /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21, + /* ORR */ 0, + /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21, + /* BIC */ (ARMI_BIC^ARMI_AND) >> 21, + /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21 +}; + +/* Encode constant in K12 format for data processing instructions. */ +static uint32_t emit_isk12(ARMIns ai, int32_t n) +{ + uint32_t invai, i, m = (uint32_t)n; + /* K12: unsigned 8 bit value, rotated in steps of two bits. */ + for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2)) + if (m <= 255) return ARMI_K12|m|i; + /* Otherwise try negation/complement with the inverse instruction. */ + invai = emit_invai[((ai >> 21) & 15)]; + if (!invai) return 0; /* Failed. No inverse instruction. */ + m = ~(uint32_t)n; + if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) || + invai == (ARMI_CMP^ARMI_CMN) >> 21) m++; + for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2)) + if (m <= 255) return ARMI_K12|(invai<<21)|m|i; + return 0; /* Failed. */ +} + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm); +} + +static void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm); +} + +static void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn) +{ + *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn); +} + +static void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm) +{ + *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm); +} + +static void emit_d(ASMState *as, ARMIns ai, Reg rd) +{ + *--as->mcp = ai | ARMF_D(rd); +} + +static void emit_n(ASMState *as, ARMIns ai, Reg rn) +{ + *--as->mcp = ai | ARMF_N(rn); +} + +static void emit_m(ASMState *as, ARMIns ai, Reg rm) +{ + *--as->mcp = ai | ARMF_M(rm); +} + +static void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -255 && ofs <= 255); + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) | + ((ofs & 0xf0) << 4) | (ofs & 0x0f); +} + +static void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -4095 && ofs <= 4095); + /* Combine LDR/STR pairs to LDRD/STRD. */ + if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) && + (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn && + (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) && + as->mcp != as->mcloop) { + as->mcp++; + emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4); + return; + } + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs; +} + +#if !LJ_SOFTFP +static void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) +{ + lua_assert(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0); + if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U; + *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2); +} +#endif + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer spills of BASE/L. */ +#define emit_canremat(ref) ((ref) < ASMREF_L) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg d, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != d); + if (emit_canremat(ref)) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + uint32_t k = emit_isk12(ARMI_ADD, delta); + if (k) { + if (k == ARMI_K12) + emit_dm(as, ARMI_MOV, d, r); + else + emit_dn(as, ARMI_ADD^k, d, r); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Try to find a two step delta relative to another constant. */ +static int emit_kdelta2(ASMState *as, Reg d, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != d); + if (emit_canremat(ref)) { + int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i; + if (other) { + int32_t delta = i - other; + uint32_t sh, inv = 0, k2, k; + if (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; } + sh = lj_ffs(delta) & ~1; + k2 = emit_isk12(0, delta & (255 << sh)); + k = emit_isk12(0, delta & ~(255 << sh)); + if (k) { + emit_dn(as, ARMI_ADD^k2^inv, d, d); + emit_dn(as, ARMI_ADD^k^inv, d, r); + return 1; + } + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + uint32_t k = emit_isk12(ARMI_MOV, i); + lua_assert(rset_test(as->freeset, r) || r == RID_TMP); + if (k) { + /* Standard K12 constant. */ + emit_d(as, ARMI_MOV^k, r); + } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) { + /* 16 bit loword constant for ARMv6T2. */ + emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r); + } else if (emit_kdelta1(as, r, i)) { + /* One step delta relative to another constant. */ + } else if ((as->flags & JIT_F_ARMV6T2)) { + /* 32 bit hiword/loword constant for ARMv6T2. */ + emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), r); + emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r); + } else if (emit_kdelta2(as, r, i)) { + /* Two step delta relative to another constant. */ + } else { + /* Otherwise construct the constant with up to 4 instructions. */ + /* NYI: use mvn+bic, use pc-relative loads. */ + for (;;) { + uint32_t sh = lj_ffs(i) & ~1; + int32_t m = i & (255 << sh); + i &= ~(255 << sh); + if (i == 0) { + emit_d(as, ARMI_MOV ^ emit_isk12(0, m), r); + break; + } + emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), r, r); + } + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p) +{ + int32_t i = i32ptr(p); + emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)), + (i & 4095)); +} + +#if !LJ_SOFTFP +/* Load a number constant into an FPR. */ +static void emit_loadn(ASMState *as, Reg r, cTValue *tv) +{ + int32_t i; + if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) { + uint32_t hi = tv->u32.hi; + uint32_t b = ((hi >> 22) & 0x1ff); + if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) { + *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) | + ((tv->u32.hi >> 12) & 0x00080000) | + ((tv->u32.hi >> 4) & 0x00070000) | + ((tv->u32.hi >> 16) & 0x0000000f); + return; + } + } + i = i32ptr(tv); + emit_vlso(as, ARMI_VLDR_D, r, + ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020)); +} +#endif + +/* Get/set global_State fields. */ +#define emit_getgl(as, r, field) \ + emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field) +#define emit_setgl(as, r, field) \ + emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field) + +/* Trace number is determined from pc of exit instruction. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_branch(ASMState *as, ARMIns ai, MCode *target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = (target - p) - 1; + lua_assert(((delta + 0x00800000) >> 24) == 0); + *--p = ai | ((uint32_t)delta & 0x00ffffffu); + as->mcp = p; +} + +#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target)) + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = ((char *)target - (char *)p) - 8; + if ((((delta>>2) + 0x00800000) >> 24) == 0) { + if ((delta & 1)) + *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 27); + else + *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu); + } else { /* Target out of range: need indirect call. But don't use R0-R3. */ + Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1)); + *p = ARMI_BLXr | ARMF_M(r); + } +} + +/* -- Emit generic operations --------------------------------------------- */ + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (dst >= RID_MAX_GPR) { + emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S, + (dst & 15), (src & 15)); + return; + } +#endif + if (as->mcp != as->mcloop) { /* Swap early registers for loads/stores. */ + MCode ins = *as->mcp, swp = (src^dst); + if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) { + if (!((ins ^ (dst << 16)) & 0x000f0000)) + *as->mcp = ins ^ (swp << 16); /* Swap N in load/store. */ + if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000)) + *as->mcp = ins ^ (swp << 12); /* Swap D in store. */ + } + } + emit_dm(as, ARMI_MOV, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (r >= RID_MAX_GPR) + emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, RID_SP, ofs); + else +#endif + emit_lso(as, ARMI_LDR, r, RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ +#if LJ_SOFTFP + lua_assert(!irt_isnum(ir->t)); UNUSED(ir); +#else + if (r >= RID_MAX_GPR) + emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, RID_SP, ofs); + else +#endif + emit_lso(as, ARMI_STR, r, RID_SP, ofs); +} + +/* Emit an arithmetic/logic operation with a constant operand. */ +static void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src, + int32_t i, RegSet allow) +{ + uint32_t k = emit_isk12(ai, i); + if (k) + emit_dn(as, ai^k, dest, src); + else + emit_dnm(as, ai, dest, src, ra_allock(as, i, allow)); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) + emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r)); +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_mips.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_mips.h new file mode 100644 index 0000000..dc9197a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_mips.h @@ -0,0 +1,211 @@ +/* +** MIPS instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt) +{ + *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt); +} + +static void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a) +{ + *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a); +} + +#define emit_ds(as, mi, rd, rs) emit_dst(as, (mi), (rd), (rs), 0) +#define emit_tg(as, mi, rt, rg) emit_dst(as, (mi), (rg)&31, 0, (rt)) + +static void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i) +{ + *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff); +} + +#define emit_ti(as, mi, rt, i) emit_tsi(as, (mi), (rt), 0, (i)) +#define emit_hsi(as, mi, rh, rs, i) emit_tsi(as, (mi), (rh) & 31, (rs), (i)) + +static void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh) +{ + *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31); +} + +#define emit_fg(as, mi, rf, rg) emit_fgh(as, (mi), (rf), (rg), 0) + +static void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift) +{ + if ((as->flags & JIT_F_MIPS32R2)) { + emit_dta(as, MIPSI_ROTR, dest, src, shift); + } else { + emit_dst(as, MIPSI_OR, dest, dest, tmp); + emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31); + emit_dta(as, MIPSI_SRL, tmp, src, shift); + } +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg t, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != t); + if (ref < ASMREF_L) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + if (checki16(delta)) { + emit_tsi(as, MIPSI_ADDIU, t, r, delta); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + if (checki16(i)) { + emit_ti(as, MIPSI_LI, r, i); + } else { + if ((i & 0xffff)) { + int32_t jgl = i32ptr(J2G(as->J)); + if ((uint32_t)(i-jgl) < 65536) { + emit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768); + return; + } else if (emit_kdelta1(as, r, i)) { + return; + } else if ((i >> 16) == 0) { + emit_tsi(as, MIPSI_ORI, r, RID_ZERO, i); + return; + } + emit_tsi(as, MIPSI_ORI, r, r, i); + } + emit_ti(as, MIPSI_LUI, r, (i >> 16)); + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); +static void ra_allockreg(ASMState *as, int32_t k, Reg r); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow) +{ + int32_t jgl = i32ptr(J2G(as->J)); + int32_t i = i32ptr(p); + Reg base; + if ((uint32_t)(i-jgl) < 65536) { + i = i-jgl-32768; + base = RID_JGL; + } else { + base = ra_allock(as, i-(int16_t)i, allow); + } + emit_tsi(as, mi, r, base, i); +} + +#define emit_loadn(as, r, tv) \ + emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)(tv), RSET_GPR) + +/* Get/set global_State fields. */ +static void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs) +{ + emit_tsi(as, mi, r, RID_JGL, ofs-32768); +} + +#define emit_getgl(as, r, field) \ + emit_lsglptr(as, MIPSI_LW, (r), (int32_t)offsetof(global_State, field)) +#define emit_setgl(as, r, field) \ + emit_lsglptr(as, MIPSI_SW, (r), (int32_t)offsetof(global_State, field)) + +/* Trace number is determined from per-trace exit stubs. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(((delta + 0x8000) >> 16) == 0); + *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu); + as->mcp = p; +} + +static void emit_jmp(ASMState *as, MCode *target) +{ + *--as->mcp = MIPSI_NOP; + emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target)); +} + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = as->mcp; + *--p = MIPSI_NOP; + if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0) + *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu); + else /* Target out of range: need indirect call. */ + *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR); + as->mcp = p; + ra_allockreg(as, i32ptr(target), RID_CFUNCADDR); +} + +/* -- Emit generic operations --------------------------------------------- */ + +#define emit_move(as, dst, src) \ + emit_ds(as, MIPSI_MOVE, (dst), (src)) + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + if (dst < RID_MAX_GPR) + emit_move(as, dst, src); + else + emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tsi(as, MIPSI_LW, r, RID_SP, ofs); + else + emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1, + (r & 31), RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tsi(as, MIPSI_SW, r, RID_SP, ofs); + else + emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1, + (r&31), RID_SP, ofs); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + lua_assert(checki16(ofs)); + emit_tsi(as, MIPSI_ADDIU, r, r, ofs); + } +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_ppc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_ppc.h new file mode 100644 index 0000000..3a2ae38 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_ppc.h @@ -0,0 +1,238 @@ +/* +** PPC instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +static void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb) +{ + *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb); +} + +#define emit_asb(as, pi, ra, rs, rb) emit_tab(as, (pi), (rs), (ra), (rb)) +#define emit_as(as, pi, ra, rs) emit_tab(as, (pi), (rs), (ra), 0) +#define emit_ab(as, pi, ra, rb) emit_tab(as, (pi), 0, (ra), (rb)) + +static void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i) +{ + *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff); +} + +#define emit_ti(as, pi, rt, i) emit_tai(as, (pi), (rt), 0, (i)) +#define emit_ai(as, pi, ra, i) emit_tai(as, (pi), 0, (ra), (i)) +#define emit_asi(as, pi, ra, rs, i) emit_tai(as, (pi), (rs), (ra), (i)) + +#define emit_fab(as, pi, rf, ra, rb) \ + emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31) +#define emit_fb(as, pi, rf, rb) emit_tab(as, (pi), (rf)&31, 0, (rb)&31) +#define emit_fac(as, pi, rf, ra, rc) \ + emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0) +#define emit_facb(as, pi, rf, ra, rc, rb) \ + emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31) +#define emit_fai(as, pi, rf, ra, i) emit_tai(as, (pi), (rf)&31, (ra), (i)) + +static void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs, + int32_t n, int32_t b, int32_t e) +{ + *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) | + PPCF_MB(b) | PPCF_ME(e); +} + +static void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n) +{ + lua_assert(n >= 0 && n < 32); + emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n); +} + +static void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n) +{ + lua_assert(n >= 0 && n < 32); + emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31); +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + +/* Try to find a one step delta relative to another constant. */ +static int emit_kdelta1(ASMState *as, Reg t, int32_t i) +{ + RegSet work = ~as->freeset & RSET_GPR; + while (work) { + Reg r = rset_picktop(work); + IRRef ref = regcost_ref(as->cost[r]); + lua_assert(r != t); + if (ref < ASMREF_L) { + int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); + if (checki16(delta)) { + emit_tai(as, PPCI_ADDI, t, r, delta); + return 1; + } + } + rset_clear(work, r); + } + return 0; /* Failed. */ +} + +/* Load a 32 bit constant into a GPR. */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + if (checki16(i)) { + emit_ti(as, PPCI_LI, r, i); + } else { + if ((i & 0xffff)) { + int32_t jgl = i32ptr(J2G(as->J)); + if ((uint32_t)(i-jgl) < 65536) { + emit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768); + return; + } else if (emit_kdelta1(as, r, i)) { + return; + } + emit_asi(as, PPCI_ORI, r, r, i); + } + emit_ti(as, PPCI_LIS, r, (i >> 16)); + } +} + +#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr))) + +static Reg ra_allock(ASMState *as, int32_t k, RegSet allow); + +/* Get/set from constant pointer. */ +static void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow) +{ + int32_t jgl = i32ptr(J2G(as->J)); + int32_t i = i32ptr(p); + Reg base; + if ((uint32_t)(i-jgl) < 65536) { + i = i-jgl-32768; + base = RID_JGL; + } else { + base = ra_allock(as, i-(int16_t)i, allow); + } + emit_tai(as, pi, r, base, i); +} + +#define emit_loadn(as, r, tv) \ + emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)(tv), RSET_GPR) + +/* Get/set global_State fields. */ +static void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs) +{ + emit_tai(as, pi, r, RID_JGL, ofs-32768); +} + +#define emit_getgl(as, r, field) \ + emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field)) +#define emit_setgl(as, r, field) \ + emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field)) + +/* Trace number is determined from per-trace exit stubs. */ +#define emit_setvmstate(as, i) UNUSED(i) + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for internal jumps. */ +typedef MCode *MCLabel; + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +static void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + lua_assert(((delta + 0x8000) >> 16) == 0); + pi ^= (delta & 0x8000) * (PPCF_Y/0x8000); + *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu); +} + +static void emit_jmp(ASMState *as, MCode *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + *p = PPCI_B | (delta & 0x03fffffcu); +} + +static void emit_call(ASMState *as, void *target) +{ + MCode *p = --as->mcp; + ptrdiff_t delta = (char *)target - (char *)p; + if ((((delta>>2) + 0x00800000) >> 24) == 0) { + *p = PPCI_BL | (delta & 0x03fffffcu); + } else { /* Target out of range: need indirect call. Don't use arg reg. */ + RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1); + Reg r = ra_allock(as, i32ptr(target), allow); + *p = PPCI_BCTRL; + p[-1] = PPCI_MTCTR | PPCF_T(r); + as->mcp = p-1; + } +} + +/* -- Emit generic operations --------------------------------------------- */ + +#define emit_mr(as, dst, src) \ + emit_asb(as, PPCI_MR, (dst), (src), (src)) + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + UNUSED(ir); + if (dst < RID_MAX_GPR) + emit_mr(as, dst, src); + else + emit_fb(as, PPCI_FMR, dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tai(as, PPCI_LWZ, r, RID_SP, ofs); + else + emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, RID_SP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_tai(as, PPCI_STW, r, RID_SP, ofs); + else + emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, RID_SP, ofs); +} + +/* Emit a compare (for equality) with a constant operand. */ +static void emit_cmpi(ASMState *as, Reg r, int32_t k) +{ + if (checki16(k)) { + emit_ai(as, PPCI_CMPWI, r, k); + } else if (checku16(k)) { + emit_ai(as, PPCI_CMPLWI, r, k); + } else { + emit_ai(as, PPCI_CMPLWI, RID_TMP, k); + emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16)); + } +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + emit_tai(as, PPCI_ADDI, r, r, ofs); + if (!checki16(ofs)) + emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16); + } +} + +static void emit_spsub(ASMState *as, int32_t ofs) +{ + if (ofs) { + emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs); + emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP, + CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0)); + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_x86.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_x86.h new file mode 100644 index 0000000..8cfb654 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_emit_x86.h @@ -0,0 +1,466 @@ +/* +** x86/x64 instruction emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* -- Emit basic instructions --------------------------------------------- */ + +#define MODRM(mode, r1, r2) ((MCode)((mode)+(((r1)&7)<<3)+((r2)&7))) + +#if LJ_64 +#define REXRB(p, rr, rb) \ + { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \ + if (rex != 0x40) *--(p) = rex; } +#define FORCE_REX 0x200 +#define REX_64 (FORCE_REX|0x080000) +#else +#define REXRB(p, rr, rb) ((void)0) +#define FORCE_REX 0 +#define REX_64 0 +#endif + +#define emit_i8(as, i) (*--as->mcp = (MCode)(i)) +#define emit_i32(as, i) (*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4) +#define emit_u32(as, u) (*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4) + +#define emit_x87op(as, xo) \ + (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2) + +/* op */ +static LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx, + MCode *p, int delta) +{ + int n = (int8_t)xo; +#if defined(__GNUC__) + if (__builtin_constant_p(xo) && n == -2) + p[delta-2] = (MCode)(xo >> 24); + else if (__builtin_constant_p(xo) && n == -3) + *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16); + else +#endif + *(uint32_t *)(p+delta-5) = (uint32_t)xo; + p += n + delta; +#if LJ_64 + { + uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1); + if (rex != 0x40) { + rex |= (rr >> 16); + if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); } + else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; } + *--p = (MCode)rex; + } + } +#else + UNUSED(rr); UNUSED(rb); UNUSED(rx); +#endif + return p; +} + +/* op + modrm */ +#define emit_opm(xo, mode, rr, rb, p, delta) \ + (p[(delta)-1] = MODRM((mode), (rr), (rb)), \ + emit_op((xo), (rr), (rb), 0, (p), (delta))) + +/* op + modrm + sib */ +#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \ + (p[-1] = MODRM((scale), (rx), (rb)), \ + p[-2] = MODRM((mode), (rr), RID_ESP), \ + emit_op((xo), (rr), (rb), (rx), (p), -1)) + +/* op r1, r2 */ +static void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2) +{ + MCode *p = as->mcp; + as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0); +} + +#if LJ_64 && defined(LUA_USE_ASSERT) +/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */ +static int32_t ptr2addr(const void *p) +{ + lua_assert((uintptr_t)p < (uintptr_t)0x80000000); + return i32ptr(p); +} +#else +#define ptr2addr(p) (i32ptr((p))) +#endif + +/* op r, [addr] */ +static void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = ptr2addr(addr); +#if LJ_64 + p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5); +#else + as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4); +#endif +} + +/* op r, [base+ofs] */ +static void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs) +{ + MCode *p = as->mcp; + x86Mode mode; + if (ra_hasreg(rb)) { + if (ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(ofs)) { + *--p = (MCode)ofs; + mode = XM_OFS8; + } else { + p -= 4; + *(int32_t *)p = ofs; + mode = XM_OFS32; + } + if ((rb&7) == RID_ESP) + *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } else { + *(int32_t *)(p-4) = ofs; +#if LJ_64 + p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + p -= 5; + rb = RID_ESP; +#else + p -= 4; + rb = RID_EBP; +#endif + mode = XM_OFS0; + } + as->mcp = emit_opm(xo, mode, rr, rb, p, 0); +} + +/* op r, [base+idx*scale+ofs] */ +static void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx, + x86Mode scale, int32_t ofs) +{ + MCode *p = as->mcp; + x86Mode mode; + if (ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(ofs)) { + mode = XM_OFS8; + *--p = (MCode)ofs; + } else { + mode = XM_OFS32; + p -= 4; + *(int32_t *)p = ofs; + } + as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p); +} + +/* op r, i */ +static void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i) +{ + MCode *p = as->mcp; + x86Op xo; + if (checki8(i)) { + *--p = (MCode)i; + xo = XG_TOXOi8(xg); + } else { + p -= 4; + *(int32_t *)p = i; + xo = XG_TOXOi(xg); + } + as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0); +} + +/* op [base+ofs], i */ +static void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs, + int32_t i) +{ + x86Op xo; + if (checki8(i)) { + emit_i8(as, i); + xo = XG_TOXOi8(xg); + } else { + emit_i32(as, i); + xo = XG_TOXOi(xg); + } + emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs); +} + +#define emit_shifti(as, xg, r, i) \ + (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r))) + +/* op r, rm/mrm */ +static void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb) +{ + MCode *p = as->mcp; + x86Mode mode = XM_REG; + if (rb == RID_MRM) { + rb = as->mrm.base; + if (rb == RID_NONE) { + rb = RID_EBP; + mode = XM_OFS0; + p -= 4; + *(int32_t *)p = as->mrm.ofs; + if (as->mrm.idx != RID_NONE) + goto mrmidx; +#if LJ_64 + *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP); + rb = RID_ESP; +#endif + } else { + if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) { + mode = XM_OFS0; + } else if (checki8(as->mrm.ofs)) { + *--p = (MCode)as->mrm.ofs; + mode = XM_OFS8; + } else { + p -= 4; + *(int32_t *)p = as->mrm.ofs; + mode = XM_OFS32; + } + if (as->mrm.idx != RID_NONE) { + mrmidx: + as->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p); + return; + } + if ((rb&7) == RID_ESP) + *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP); + } + } + as->mcp = emit_opm(xo, mode, rr, rb, p, 0); +} + +/* op rm/mrm, i */ +static void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i) +{ + x86Op xo; + if (checki8(i)) { + emit_i8(as, i); + xo = XG_TOXOi8(xg); + } else { + emit_i32(as, i); + xo = XG_TOXOi(xg); + } + emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64)); +} + +/* -- Emit loads/stores --------------------------------------------------- */ + +/* Instruction selection for XMM moves. */ +#define XMM_MOVRR(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVSD : XO_MOVAPS) +#define XMM_MOVRM(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVLPD : XO_MOVSD) + +/* mov [base+ofs], i */ +static void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i) +{ + emit_i32(as, i); + emit_rmro(as, XO_MOVmi, 0, base, ofs); +} + +/* mov [base+ofs], r */ +#define emit_movtomro(as, r, base, ofs) \ + emit_rmro(as, XO_MOVto, (r), (base), (ofs)) + +/* Get/set global_State fields. */ +#define emit_opgl(as, xo, r, field) \ + emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field) +#define emit_getgl(as, r, field) emit_opgl(as, XO_MOV, (r), field) +#define emit_setgl(as, r, field) emit_opgl(as, XO_MOVto, (r), field) + +#define emit_setvmstate(as, i) \ + (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate)) + +/* mov r, i / xor r, r */ +static void emit_loadi(ASMState *as, Reg r, int32_t i) +{ + /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP. */ + if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP || + (as->curins+1 < as->T->nins && + IR(as->curins+1)->o == IR_HIOP)))) { + emit_rr(as, XO_ARITH(XOg_XOR), r, r); + } else { + MCode *p = as->mcp; + *(int32_t *)(p-4) = i; + p[-5] = (MCode)(XI_MOVri+(r&7)); + p -= 5; + REXRB(p, 0, r); + as->mcp = p; + } +} + +/* mov r, addr */ +#define emit_loada(as, r, addr) \ + emit_loadi(as, (r), ptr2addr((addr))) + +#if LJ_64 +/* mov r, imm64 or shorter 32 bit extended load. */ +static void emit_loadu64(ASMState *as, Reg r, uint64_t u64) +{ + if (checku32(u64)) { /* 32 bit load clears upper 32 bits. */ + emit_loadi(as, r, (int32_t)u64); + } else if (checki32((int64_t)u64)) { /* Sign-extended 32 bit load. */ + MCode *p = as->mcp; + *(int32_t *)(p-4) = (int32_t)u64; + as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4); + } else { /* Full-size 64 bit load. */ + MCode *p = as->mcp; + *(uint64_t *)(p-8) = u64; + p[-9] = (MCode)(XI_MOVri+(r&7)); + p[-10] = 0x48 + ((r>>3)&1); + p -= 10; + as->mcp = p; + } +} +#endif + +/* movsd r, [&tv->n] / xorps r, r */ +static void emit_loadn(ASMState *as, Reg r, cTValue *tv) +{ + if (tvispzero(tv)) /* Use xor only for +0. */ + emit_rr(as, XO_XORPS, r, r); + else + emit_rma(as, XMM_MOVRM(as), r, &tv->n); +} + +/* -- Emit control-flow instructions -------------------------------------- */ + +/* Label for short jumps. */ +typedef MCode *MCLabel; + +#if LJ_32 && LJ_HASFFI +/* jmp short target */ +static void emit_sjmp(ASMState *as, MCLabel target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(delta == (int8_t)delta); + p[-1] = (MCode)(int8_t)delta; + p[-2] = XI_JMPs; + as->mcp = p - 2; +} +#endif + +/* jcc short target */ +static void emit_sjcc(ASMState *as, int cc, MCLabel target) +{ + MCode *p = as->mcp; + ptrdiff_t delta = target - p; + lua_assert(delta == (int8_t)delta); + p[-1] = (MCode)(int8_t)delta; + p[-2] = (MCode)(XI_JCCs+(cc&15)); + as->mcp = p - 2; +} + +/* jcc short (pending target) */ +static MCLabel emit_sjcc_label(ASMState *as, int cc) +{ + MCode *p = as->mcp; + p[-1] = 0; + p[-2] = (MCode)(XI_JCCs+(cc&15)); + as->mcp = p - 2; + return p; +} + +/* Fixup jcc short target. */ +static void emit_sfixup(ASMState *as, MCLabel source) +{ + source[-1] = (MCode)(as->mcp-source); +} + +/* Return label pointing to current PC. */ +#define emit_label(as) ((as)->mcp) + +/* Compute relative 32 bit offset for jump and call instructions. */ +static LJ_AINLINE int32_t jmprel(MCode *p, MCode *target) +{ + ptrdiff_t delta = target - p; + lua_assert(delta == (int32_t)delta); + return (int32_t)delta; +} + +/* jcc target */ +static void emit_jcc(ASMState *as, int cc, MCode *target) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = (MCode)(XI_JCCn+(cc&15)); + p[-6] = 0x0f; + as->mcp = p - 6; +} + +/* jmp target */ +static void emit_jmp(ASMState *as, MCode *target) +{ + MCode *p = as->mcp; + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_JMP; + as->mcp = p - 5; +} + +/* call target */ +static void emit_call_(ASMState *as, MCode *target) +{ + MCode *p = as->mcp; +#if LJ_64 + if (target-p != (int32_t)(target-p)) { + /* Assumes RID_RET is never an argument to calls and always clobbered. */ + emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET); + emit_loadu64(as, RID_RET, (uint64_t)target); + return; + } +#endif + *(int32_t *)(p-4) = jmprel(p, target); + p[-5] = XI_CALL; + as->mcp = p - 5; +} + +#define emit_call(as, f) emit_call_(as, (MCode *)(void *)(f)) + +/* -- Emit generic operations --------------------------------------------- */ + +/* Use 64 bit operations to handle 64 bit IR types. */ +#if LJ_64 +#define REX_64IR(ir, r) ((r) + (irt_is64((ir)->t) ? REX_64 : 0)) +#else +#define REX_64IR(ir, r) (r) +#endif + +/* Generic move between two regs. */ +static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) +{ + UNUSED(ir); + if (dst < RID_MAX_GPR) + emit_rr(as, XO_MOV, REX_64IR(ir, dst), src); + else + emit_rr(as, XMM_MOVRR(as), dst, src); +} + +/* Generic load of register from stack slot. */ +static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_rmro(as, XO_MOV, REX_64IR(ir, r), RID_ESP, ofs); + else + emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, r, RID_ESP, ofs); +} + +/* Generic store of register to stack slot. */ +static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs) +{ + if (r < RID_MAX_GPR) + emit_rmro(as, XO_MOVto, REX_64IR(ir, r), RID_ESP, ofs); + else + emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, RID_ESP, ofs); +} + +/* Add offset to pointer. */ +static void emit_addptr(ASMState *as, Reg r, int32_t ofs) +{ + if (ofs) { + if ((as->flags & JIT_F_LEA_AGU)) + emit_rmro(as, XO_LEA, r, r, ofs); + else + emit_gri(as, XG_ARITHi(XOg_ADD), r, ofs); + } +} + +#define emit_spsub(as, ofs) emit_addptr(as, RID_ESP|REX_64, -(ofs)) + +/* Prefer rematerialization of BASE/L from global_State over spills. */ +#define emit_canremat(ref) ((ref) <= REF_BASE) + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.c new file mode 100644 index 0000000..db18267 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.c @@ -0,0 +1,785 @@ +/* +** Error handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_err_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_func.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_ff.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* +** LuaJIT can either use internal or external frame unwinding: +** +** - Internal frame unwinding (INT) is free-standing and doesn't require +** any OS or library support. +** +** - External frame unwinding (EXT) uses the system-provided unwind handler. +** +** Pros and Cons: +** +** - EXT requires unwind tables for *all* functions on the C stack between +** the pcall/catch and the error/throw. This is the default on x64, +** but needs to be manually enabled on x86/PPC for non-C++ code. +** +** - INT is faster when actually throwing errors (but this happens rarely). +** Setting up error handlers is zero-cost in any case. +** +** - EXT provides full interoperability with C++ exceptions. You can throw +** Lua errors or C++ exceptions through a mix of Lua frames and C++ frames. +** C++ destructors are called as needed. C++ exceptions caught by pcall +** are converted to the string "C++ exception". Lua errors can be caught +** with catch (...) in C++. +** +** - INT has only limited support for automatically catching C++ exceptions +** on POSIX systems using DWARF2 stack unwinding. Other systems may use +** the wrapper function feature. Lua errors thrown through C++ frames +** cannot be caught by C++ code and C++ destructors are not run. +** +** EXT is the default on x64 systems, INT is the default on all other systems. +** +** EXT can be manually enabled on POSIX systems using GCC and DWARF2 stack +** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled +** with -funwind-tables (or -fexceptions). This includes LuaJIT itself (set +** TARGET_CFLAGS), all of your C/Lua binding code, all loadable C modules +** and all C libraries that have callbacks which may be used to call back +** into Lua. C++ code must *not* be compiled with -fno-exceptions. +** +** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH. +** EXT is mandatory on WIN64 since the calling convention has an abundance +** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15). +** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. +*/ + +#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) +#define LJ_UNWIND_EXT 1 +#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS +#define LJ_UNWIND_EXT 1 +#endif + +/* -- Error messages ------------------------------------------------------ */ + +/* Error message strings. */ +LJ_DATADEF const char *lj_err_allmsg = +#define ERRDEF(name, msg) msg "\0" +#include "lj_errmsg.h" +; + +/* -- Internal frame unwinding -------------------------------------------- */ + +/* Unwind Lua stack and move error message to new top. */ +LJ_NOINLINE static void unwindstack(lua_State *L, TValue *top) +{ + lj_func_closeuv(L, top); + if (top < L->top-1) { + copyTV(L, top, L->top-1); + L->top = top+1; + } + lj_state_relimitstack(L); +} + +/* Unwind until stop frame. Optionally cleanup frames. */ +static void *err_unwind(lua_State *L, void *stopcf, int errcode) +{ + TValue *frame = L->base-1; + void *cf = L->cframe; + while (cf) { + int32_t nres = cframe_nres(cframe_raw(cf)); + if (nres < 0) { /* C frame without Lua frame? */ + TValue *top = restorestack(L, -nres); + if (frame < top) { /* Frame reached? */ + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame+1; + unwindstack(L, top); + } + return cf; + } + } + if (frame <= tvref(L->stack)) + break; + switch (frame_typep(frame)) { + case FRAME_LUA: /* Lua frame. */ + case FRAME_LUAP: + frame = frame_prevl(frame); + break; + case FRAME_C: /* C frame. */ +#if LJ_HASFFI + unwind_c: +#endif +#if LJ_UNWIND_EXT + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame_prevd(frame) + 1; + unwindstack(L, frame); + } else if (cf != stopcf) { + cf = cframe_prev(cf); + frame = frame_prevd(frame); + break; + } + return NULL; /* Continue unwinding. */ +#else + UNUSED(stopcf); + cf = cframe_prev(cf); + frame = frame_prevd(frame); + break; +#endif + case FRAME_CP: /* Protected C frame. */ + if (cframe_canyield(cf)) { /* Resume? */ + if (errcode) { + hook_leave(G(L)); /* Assumes nobody uses coroutines inside hooks. */ + L->cframe = NULL; + L->status = (uint8_t)errcode; + } + return cf; + } + if (errcode) { + L->cframe = cframe_prev(cf); + L->base = frame_prevd(frame) + 1; + unwindstack(L, frame); + } + return cf; + case FRAME_CONT: /* Continuation frame. */ +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) + goto unwind_c; +#endif + case FRAME_VARG: /* Vararg frame. */ + frame = frame_prevd(frame); + break; + case FRAME_PCALL: /* FF pcall() frame. */ + case FRAME_PCALLH: /* FF pcall() frame inside hook. */ + if (errcode) { + if (errcode == LUA_YIELD) { + frame = frame_prevd(frame); + break; + } + if (frame_typep(frame) == FRAME_PCALL) + hook_leave(G(L)); + L->cframe = cf; + L->base = frame_prevd(frame) + 1; + unwindstack(L, L->base); + } + return (void *)((intptr_t)cf | CFRAME_UNWIND_FF); + } + } + /* No C frame. */ + if (errcode) { + L->cframe = NULL; + L->base = tvref(L->stack)+1; + unwindstack(L, L->base); + if (G(L)->panic) + G(L)->panic(L); + exit(EXIT_FAILURE); + } + return L; /* Anything non-NULL will do. */ +} + +/* -- External frame unwinding -------------------------------------------- */ + +#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_TARGET_WINDOWS + +/* +** We have to use our own definitions instead of the mandatory (!) unwind.h, +** since various OS, distros and compilers mess up the header installation. +*/ + +typedef struct _Unwind_Exception +{ + uint64_t exclass; + void (*excleanup)(int, struct _Unwind_Exception *); + uintptr_t p1, p2; +} __attribute__((__aligned__)) _Unwind_Exception; + +typedef struct _Unwind_Context _Unwind_Context; + +#define _URC_OK 0 +#define _URC_FATAL_PHASE1_ERROR 3 +#define _URC_HANDLER_FOUND 6 +#define _URC_INSTALL_CONTEXT 7 +#define _URC_CONTINUE_UNWIND 8 +#define _URC_FAILURE 9 + +#if !LJ_TARGET_ARM + +extern uintptr_t _Unwind_GetCFA(_Unwind_Context *); +extern void _Unwind_SetGR(_Unwind_Context *, int, uintptr_t); +extern void _Unwind_SetIP(_Unwind_Context *, uintptr_t); +extern void _Unwind_DeleteException(_Unwind_Exception *); +extern int _Unwind_RaiseException(_Unwind_Exception *); + +#define _UA_SEARCH_PHASE 1 +#define _UA_CLEANUP_PHASE 2 +#define _UA_HANDLER_FRAME 4 +#define _UA_FORCE_UNWIND 8 + +#define LJ_UEXCLASS 0x4c55414a49543200ULL /* LUAJIT2\0 */ +#define LJ_UEXCLASS_MAKE(c) (LJ_UEXCLASS | (uint64_t)(c)) +#define LJ_UEXCLASS_CHECK(cl) (((cl) ^ LJ_UEXCLASS) <= 0xff) +#define LJ_UEXCLASS_ERRCODE(cl) ((int)((cl) & 0xff)) + +/* DWARF2 personality handler referenced from interpreter .eh_frame. */ +LJ_FUNCA int lj_err_unwind_dwarf(int version, int actions, + uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx) +{ + void *cf; + lua_State *L; + if (version != 1) + return _URC_FATAL_PHASE1_ERROR; + UNUSED(uexclass); + cf = (void *)_Unwind_GetCFA(ctx); + L = cframe_L(cf); + if ((actions & _UA_SEARCH_PHASE)) { +#if LJ_UNWIND_EXT + if (err_unwind(L, cf, 0) == NULL) + return _URC_CONTINUE_UNWIND; +#endif + if (!LJ_UEXCLASS_CHECK(uexclass)) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + } + return _URC_HANDLER_FOUND; + } + if ((actions & _UA_CLEANUP_PHASE)) { + int errcode; + if (LJ_UEXCLASS_CHECK(uexclass)) { + errcode = LJ_UEXCLASS_ERRCODE(uexclass); + } else { + if ((actions & _UA_HANDLER_FRAME)) + _Unwind_DeleteException(uex); + errcode = LUA_ERRRUN; + } +#if LJ_UNWIND_EXT + cf = err_unwind(L, cf, errcode); + if ((actions & _UA_FORCE_UNWIND)) { + return _URC_CONTINUE_UNWIND; + } else if (cf) { + _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode); + _Unwind_SetIP(ctx, (uintptr_t)(cframe_unwind_ff(cf) ? + lj_vm_unwind_ff_eh : + lj_vm_unwind_c_eh)); + return _URC_INSTALL_CONTEXT; + } +#if LJ_TARGET_X86ORX64 + else if ((actions & _UA_HANDLER_FRAME)) { + /* Workaround for ancient libgcc bug. Still present in RHEL 5.5. :-/ + ** Real fix: http://gcc.gnu.org/viewcvs/trunk/gcc/unwind-dw2.c?r1=121165&r2=124837&pathrev=153877&diff_format=h + */ + _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode); + _Unwind_SetIP(ctx, (uintptr_t)lj_vm_unwind_rethrow); + return _URC_INSTALL_CONTEXT; + } +#endif +#else + /* This is not the proper way to escape from the unwinder. We get away with + ** it on non-x64 because the interpreter restores all callee-saved regs. + */ + lj_err_throw(L, errcode); +#endif + } + return _URC_CONTINUE_UNWIND; +} + +#if LJ_UNWIND_EXT +#if LJ_TARGET_OSX || defined(__OpenBSD__) +/* Sorry, no thread safety for OSX. Complain to Apple, not me. */ +static _Unwind_Exception static_uex; +#else +static __thread _Unwind_Exception static_uex; +#endif + +/* Raise DWARF2 exception. */ +static void err_raise_ext(int errcode) +{ + static_uex.exclass = LJ_UEXCLASS_MAKE(errcode); + static_uex.excleanup = NULL; + _Unwind_RaiseException(&static_uex); +} +#endif + +#else + +extern void _Unwind_DeleteException(void *); +extern int __gnu_unwind_frame (void *, _Unwind_Context *); +extern int _Unwind_VRS_Set(_Unwind_Context *, int, uint32_t, int, void *); +extern int _Unwind_VRS_Get(_Unwind_Context *, int, uint32_t, int, void *); + +static inline uint32_t _Unwind_GetGR(_Unwind_Context *ctx, int r) +{ + uint32_t v; + _Unwind_VRS_Get(ctx, 0, r, 0, &v); + return v; +} + +static inline void _Unwind_SetGR(_Unwind_Context *ctx, int r, uint32_t v) +{ + _Unwind_VRS_Set(ctx, 0, r, 0, &v); +} + +#define _US_VIRTUAL_UNWIND_FRAME 0 +#define _US_UNWIND_FRAME_STARTING 1 +#define _US_ACTION_MASK 3 +#define _US_FORCE_UNWIND 8 + +/* ARM unwinder personality handler referenced from interpreter .ARM.extab. */ +LJ_FUNCA int lj_err_unwind_arm(int state, void *ucb, _Unwind_Context *ctx) +{ + void *cf = (void *)_Unwind_GetGR(ctx, 13); + lua_State *L = cframe_L(cf); + if ((state & _US_ACTION_MASK) == _US_VIRTUAL_UNWIND_FRAME) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + return _URC_HANDLER_FOUND; + } + if ((state&(_US_ACTION_MASK|_US_FORCE_UNWIND)) == _US_UNWIND_FRAME_STARTING) { + _Unwind_DeleteException(ucb); + _Unwind_SetGR(ctx, 15, (uint32_t)(void *)lj_err_throw); + _Unwind_SetGR(ctx, 0, (uint32_t)L); + _Unwind_SetGR(ctx, 1, (uint32_t)LUA_ERRRUN); + return _URC_INSTALL_CONTEXT; + } + if (__gnu_unwind_frame(ucb, ctx) != _URC_OK) + return _URC_FAILURE; + return _URC_CONTINUE_UNWIND; +} + +#endif + +#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS + +/* +** Someone in Redmond owes me several days of my life. A lot of this is +** undocumented or just plain wrong on MSDN. Some of it can be gathered +** from 3rd party docs or must be found by trial-and-error. They really +** don't want you to write your own language-specific exception handler +** or to interact gracefully with MSVC. :-( +** +** Apparently MSVC doesn't call C++ destructors for foreign exceptions +** unless you compile your C++ code with /EHa. Unfortunately this means +** catch (...) also catches things like access violations. The use of +** _set_se_translator doesn't really help, because it requires /EHa, too. +*/ + +#define WIN32_LEAN_AND_MEAN +#include + +/* Taken from: http://www.nynaeve.net/?p=99 */ +typedef struct UndocumentedDispatcherContext { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} UndocumentedDispatcherContext; + +/* Another wild guess. */ +extern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow); + +#ifdef MINGW_SDK_INIT +/* Workaround for broken MinGW64 declaration. */ +VOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm("RtlUnwindEx"); +#define RtlUnwindEx RtlUnwindEx_FIXED +#endif + +#define LJ_MSVC_EXCODE ((DWORD)0xe06d7363) +#define LJ_GCC_EXCODE ((DWORD)0x20474343) + +#define LJ_EXCODE ((DWORD)0xe24c4a00) +#define LJ_EXCODE_MAKE(c) (LJ_EXCODE | (DWORD)(c)) +#define LJ_EXCODE_CHECK(cl) (((cl) ^ LJ_EXCODE) <= 0xff) +#define LJ_EXCODE_ERRCODE(cl) ((int)((cl) & 0xff)) + +/* Win64 exception handler for interpreter frame. */ +LJ_FUNCA EXCEPTION_DISPOSITION lj_err_unwind_win64(EXCEPTION_RECORD *rec, + void *cf, CONTEXT *ctx, UndocumentedDispatcherContext *dispatch) +{ + lua_State *L = cframe_L(cf); + int errcode = LJ_EXCODE_CHECK(rec->ExceptionCode) ? + LJ_EXCODE_ERRCODE(rec->ExceptionCode) : LUA_ERRRUN; + if ((rec->ExceptionFlags & 6)) { /* EH_UNWINDING|EH_EXIT_UNWIND */ + /* Unwind internal frames. */ + err_unwind(L, cf, errcode); + } else { + void *cf2 = err_unwind(L, cf, 0); + if (cf2) { /* We catch it, so start unwinding the upper frames. */ + if (rec->ExceptionCode == LJ_MSVC_EXCODE || + rec->ExceptionCode == LJ_GCC_EXCODE) { + __DestructExceptionObject(rec, 1); + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); + } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) { + /* Don't catch access violations etc. */ + return ExceptionContinueSearch; + } + /* Unwind the stack and call all handlers for all lower C frames + ** (including ourselves) again with EH_UNWINDING set. Then set + ** rsp = cf, rax = errcode and jump to the specified target. + */ + RtlUnwindEx(cf, (void *)((cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ? + lj_vm_unwind_ff_eh : + lj_vm_unwind_c_eh), + rec, (void *)(uintptr_t)errcode, ctx, dispatch->HistoryTable); + /* RtlUnwindEx should never return. */ + } + } + return ExceptionContinueSearch; +} + +/* Raise Windows exception. */ +static void err_raise_ext(int errcode) +{ + RaiseException(LJ_EXCODE_MAKE(errcode), 1 /* EH_NONCONTINUABLE */, 0, NULL); +} + +#endif + +/* -- Error handling ------------------------------------------------------ */ + +/* Throw error. Find catch frame, unwind stack and continue. */ +LJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode) +{ + global_State *g = G(L); + lj_trace_abort(g); + setgcrefnull(g->jit_L); + L->status = 0; +#if LJ_UNWIND_EXT + err_raise_ext(errcode); + /* + ** A return from this function signals a corrupt C stack that cannot be + ** unwound. We have no choice but to call the panic function and exit. + ** + ** Usually this is caused by a C function without unwind information. + ** This should never happen on x64, but may happen if you've manually + ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every* + ** non-C++ file with -funwind-tables. + */ + if (G(L)->panic) + G(L)->panic(L); +#else + { + void *cf = err_unwind(L, NULL, errcode); + if (cframe_unwind_ff(cf)) + lj_vm_unwind_ff(cframe_raw(cf)); + else + lj_vm_unwind_c(cframe_raw(cf), errcode); + } +#endif + exit(EXIT_FAILURE); +} + +/* Return string object for error message. */ +LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em) +{ + return lj_str_newz(L, err2msg(em)); +} + +/* Out-of-memory error. */ +LJ_NOINLINE void lj_err_mem(lua_State *L) +{ + if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ + lj_vm_unwind_c(L->cframe, LUA_ERRMEM); + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); + lj_err_throw(L, LUA_ERRMEM); +} + +/* Find error function for runtime errors. Requires an extra stack traversal. */ +static ptrdiff_t finderrfunc(lua_State *L) +{ + cTValue *frame = L->base-1, *bot = tvref(L->stack); + void *cf = L->cframe; + while (frame > bot) { + lua_assert(cf != NULL); + while (cframe_nres(cframe_raw(cf)) < 0) { /* cframe without frame? */ + if (frame >= restorestack(L, -cframe_nres(cf))) + break; + if (cframe_errfunc(cf) >= 0) /* Error handler not inherited (-1)? */ + return cframe_errfunc(cf); + cf = cframe_prev(cf); /* Else unwind cframe and continue searching. */ + if (cf == NULL) + return 0; + } + switch (frame_typep(frame)) { + case FRAME_LUA: + case FRAME_LUAP: + frame = frame_prevl(frame); + break; + case FRAME_C: + cf = cframe_prev(cf); + /* fallthrough */ + case FRAME_CONT: +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) + cf = cframe_prev(cf); +#endif + case FRAME_VARG: + frame = frame_prevd(frame); + break; + case FRAME_CP: + if (cframe_canyield(cf)) return 0; + if (cframe_errfunc(cf) >= 0) + return cframe_errfunc(cf); + frame = frame_prevd(frame); + break; + case FRAME_PCALL: + case FRAME_PCALLH: + if (frame_ftsz(frame) >= (ptrdiff_t)(2*sizeof(TValue))) /* xpcall? */ + return savestack(L, frame-1); /* Point to xpcall's errorfunc. */ + return 0; + default: + lua_assert(0); + return 0; + } + } + return 0; +} + +/* Runtime error. */ +LJ_NOINLINE void lj_err_run(lua_State *L) +{ + ptrdiff_t ef = finderrfunc(L); + if (ef) { + TValue *errfunc = restorestack(L, ef); + TValue *top = L->top; + lj_trace_abort(G(L)); + if (!tvisfunc(errfunc) || L->status == LUA_ERRERR) { + setstrV(L, top-1, lj_err_str(L, LJ_ERR_ERRERR)); + lj_err_throw(L, LUA_ERRERR); + } + L->status = LUA_ERRERR; + copyTV(L, top, top-1); + copyTV(L, top-1, errfunc); + L->top = top+1; + lj_vm_call(L, top, 1+1); /* Stack: |errfunc|msg| -> |msg| */ + } + lj_err_throw(L, LUA_ERRRUN); +} + +/* Formatted runtime error message. */ +LJ_NORET LJ_NOINLINE static void err_msgv(lua_State *L, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + if (curr_funcisL(L)) L->top = curr_topL(L); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + lj_debug_addloc(L, msg, L->base-1, NULL); + lj_err_run(L); +} + +/* Non-vararg variant for better calling conventions. */ +LJ_NOINLINE void lj_err_msg(lua_State *L, ErrMsg em) +{ + err_msgv(L, em); +} + +/* Lexer error. */ +LJ_NOINLINE void lj_err_lex(lua_State *L, GCstr *src, const char *tok, + BCLine line, ErrMsg em, va_list argp) +{ + char buff[LUA_IDSIZE]; + const char *msg; + lj_debug_shortname(buff, src); + msg = lj_str_pushvf(L, err2msg(em), argp); + msg = lj_str_pushf(L, "%s:%d: %s", buff, line, msg); + if (tok) + lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tok); + lj_err_throw(L, LUA_ERRSYNTAX); +} + +/* Typecheck error for operands. */ +LJ_NOINLINE void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm) +{ + const char *tname = lj_typename(o); + const char *opname = err2msg(opm); + if (curr_funcisL(L)) { + GCproto *pt = curr_proto(L); + const BCIns *pc = cframe_Lpc(L) - 1; + const char *oname = NULL; + const char *kind = lj_debug_slotname(pt, pc, (BCReg)(o-L->base), &oname); + if (kind) + err_msgv(L, LJ_ERR_BADOPRT, opname, kind, oname, tname); + } + err_msgv(L, LJ_ERR_BADOPRV, opname, tname); +} + +/* Typecheck error for ordered comparisons. */ +LJ_NOINLINE void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2) +{ + const char *t1 = lj_typename(o1); + const char *t2 = lj_typename(o2); + err_msgv(L, t1 == t2 ? LJ_ERR_BADCMPV : LJ_ERR_BADCMPT, t1, t2); + /* This assumes the two "boolean" entries are commoned by the C compiler. */ +} + +/* Typecheck error for __call. */ +LJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o) +{ + /* Gross hack if lua_[p]call or pcall/xpcall fail for a non-callable object: + ** L->base still points to the caller. So add a dummy frame with L instead + ** of a function. See lua_getstack(). + */ + const BCIns *pc = cframe_Lpc(L); + if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) { + const char *tname = lj_typename(o); + setframe_pc(o, pc); + setframe_gc(o, obj2gco(L)); + L->top = L->base = o+1; + err_msgv(L, LJ_ERR_BADCALL, tname); + } + lj_err_optype(L, o, LJ_ERR_OPCALL); +} + +/* Error in context of caller. */ +LJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg) +{ + TValue *frame = L->base-1; + TValue *pframe = NULL; + if (frame_islua(frame)) { + pframe = frame_prevl(frame); + } else if (frame_iscont(frame)) { +#if LJ_HASFFI + if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) { + pframe = frame; + frame = NULL; + } else +#endif + { + pframe = frame_prevd(frame); +#if LJ_HASFFI + /* Remove frame for FFI metamethods. */ + if (frame_func(frame)->c.ffid >= FF_ffi_meta___index && + frame_func(frame)->c.ffid <= FF_ffi_meta___tostring) { + L->base = pframe+1; + L->top = frame; + setcframe_pc(cframe_raw(L->cframe), frame_contpc(frame)); + } +#endif + } + } + lj_debug_addloc(L, msg, pframe, frame); + lj_err_run(L); +} + +/* Formatted error in context of caller. */ +LJ_NOINLINE void lj_err_callerv(lua_State *L, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + lj_err_callermsg(L, msg); +} + +/* Error in context of caller. */ +LJ_NOINLINE void lj_err_caller(lua_State *L, ErrMsg em) +{ + lj_err_callermsg(L, err2msg(em)); +} + +/* Argument error message. */ +LJ_NORET LJ_NOINLINE static void err_argmsg(lua_State *L, int narg, + const char *msg) +{ + const char *fname = "?"; + const char *ftype = lj_debug_funcname(L, L->base - 1, &fname); + if (narg < 0 && narg > LUA_REGISTRYINDEX) + narg = (int)(L->top - L->base) + narg + 1; + if (ftype && ftype[3] == 'h' && --narg == 0) /* Check for "method". */ + msg = lj_str_pushf(L, err2msg(LJ_ERR_BADSELF), fname, msg); + else + msg = lj_str_pushf(L, err2msg(LJ_ERR_BADARG), narg, fname, msg); + lj_err_callermsg(L, msg); +} + +/* Formatted argument error. */ +LJ_NOINLINE void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...) +{ + const char *msg; + va_list argp; + va_start(argp, em); + msg = lj_str_pushvf(L, err2msg(em), argp); + va_end(argp); + err_argmsg(L, narg, msg); +} + +/* Argument error. */ +LJ_NOINLINE void lj_err_arg(lua_State *L, int narg, ErrMsg em) +{ + err_argmsg(L, narg, err2msg(em)); +} + +/* Typecheck error for arguments. */ +LJ_NOINLINE void lj_err_argtype(lua_State *L, int narg, const char *xname) +{ + TValue *o = narg < 0 ? L->top + narg : L->base + narg-1; + const char *tname = o < L->top ? lj_typename(o) : lj_obj_typename[0]; + const char *msg = lj_str_pushf(L, err2msg(LJ_ERR_BADTYPE), xname, tname); + err_argmsg(L, narg, msg); +} + +/* Typecheck error for arguments. */ +LJ_NOINLINE void lj_err_argt(lua_State *L, int narg, int tt) +{ + lj_err_argtype(L, narg, lj_obj_typename[tt+1]); +} + +/* -- Public error handling API ------------------------------------------- */ + +LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf) +{ + lua_CFunction old = G(L)->panic; + G(L)->panic = panicf; + return old; +} + +/* Forwarders for the public API (C calling convention and no LJ_NORET). */ +LUA_API int lua_error(lua_State *L) +{ + lj_err_run(L); + return 0; /* unreachable */ +} + +LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *msg) +{ + err_argmsg(L, narg, msg); + return 0; /* unreachable */ +} + +LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *xname) +{ + lj_err_argtype(L, narg, xname); + return 0; /* unreachable */ +} + +LUALIB_API void luaL_where(lua_State *L, int level) +{ + int size; + cTValue *frame = lj_debug_frame(L, level, &size); + lj_debug_addloc(L, "", frame, size ? frame+size : NULL); +} + +LUALIB_API int luaL_error(lua_State *L, const char *fmt, ...) +{ + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = lj_str_pushvf(L, fmt, argp); + va_end(argp); + lj_err_callermsg(L, msg); + return 0; /* unreachable */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.h new file mode 100644 index 0000000..7ea512a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_err.h @@ -0,0 +1,41 @@ +/* +** Error handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_ERR_H +#define _LJ_ERR_H + +#include + +#include "lj_obj.h" + +typedef enum { +#define ERRDEF(name, msg) \ + LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1, +#include "lj_errmsg.h" + LJ_ERR__MAX +} ErrMsg; + +LJ_DATA const char *lj_err_allmsg; +#define err2msg(em) (lj_err_allmsg+(int)(em)) + +LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em); +LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode); +LJ_FUNC_NORET void lj_err_mem(lua_State *L); +LJ_FUNC_NORET void lj_err_run(lua_State *L); +LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em); +LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok, + BCLine line, ErrMsg em, va_list argp); +LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm); +LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2); +LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o); +LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg); +LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...); +LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em); +LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em); +LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...); +LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname); +LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_errmsg.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_errmsg.h new file mode 100644 index 0000000..137831e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_errmsg.h @@ -0,0 +1,193 @@ +/* +** VM error messages. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* This file may be included multiple times with different ERRDEF macros. */ + +/* Basic error handling. */ +ERRDEF(ERRMEM, "not enough memory") +ERRDEF(ERRERR, "error in error handling") +ERRDEF(ERRCPP, "C++ exception") + +/* Allocations. */ +ERRDEF(STROV, "string length overflow") +ERRDEF(UDATAOV, "userdata length overflow") +ERRDEF(STKOV, "stack overflow") +ERRDEF(STKOVM, "stack overflow (%s)") +ERRDEF(TABOV, "table overflow") + +/* Table indexing. */ +ERRDEF(NANIDX, "table index is NaN") +ERRDEF(NILIDX, "table index is nil") +ERRDEF(NEXTIDX, "invalid key to " LUA_QL("next")) + +/* Metamethod resolving. */ +ERRDEF(BADCALL, "attempt to call a %s value") +ERRDEF(BADOPRT, "attempt to %s %s " LUA_QS " (a %s value)") +ERRDEF(BADOPRV, "attempt to %s a %s value") +ERRDEF(BADCMPT, "attempt to compare %s with %s") +ERRDEF(BADCMPV, "attempt to compare two %s values") +ERRDEF(GETLOOP, "loop in gettable") +ERRDEF(SETLOOP, "loop in settable") +ERRDEF(OPCALL, "call") +ERRDEF(OPINDEX, "index") +ERRDEF(OPARITH, "perform arithmetic on") +ERRDEF(OPCAT, "concatenate") +ERRDEF(OPLEN, "get length of") + +/* Type checks. */ +ERRDEF(BADSELF, "calling " LUA_QS " on bad self (%s)") +ERRDEF(BADARG, "bad argument #%d to " LUA_QS " (%s)") +ERRDEF(BADTYPE, "%s expected, got %s") +ERRDEF(BADVAL, "invalid value") +ERRDEF(NOVAL, "value expected") +ERRDEF(NOCORO, "coroutine expected") +ERRDEF(NOTABN, "nil or table expected") +ERRDEF(NOLFUNC, "Lua function expected") +ERRDEF(NOFUNCL, "function or level expected") +ERRDEF(NOSFT, "string/function/table expected") +ERRDEF(NOPROXY, "boolean or proxy expected") +ERRDEF(FORINIT, LUA_QL("for") " initial value must be a number") +ERRDEF(FORLIM, LUA_QL("for") " limit must be a number") +ERRDEF(FORSTEP, LUA_QL("for") " step must be a number") + +/* C API checks. */ +ERRDEF(NOENV, "no calling environment") +ERRDEF(CYIELD, "attempt to yield across C-call boundary") +ERRDEF(BADLU, "bad light userdata pointer") +ERRDEF(NOGCMM, "bad action while in __gc metamethod") +#if LJ_TARGET_WINDOWS +ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)") +#endif + +/* Standard library function errors. */ +ERRDEF(ASSERT, "assertion failed!") +ERRDEF(PROTMT, "cannot change a protected metatable") +ERRDEF(UNPACK, "too many results to unpack") +ERRDEF(RDRSTR, "reader function must return a string") +ERRDEF(PRTOSTR, LUA_QL("tostring") " must return a string to " LUA_QL("print")) +ERRDEF(IDXRNG, "index out of range") +ERRDEF(BASERNG, "base out of range") +ERRDEF(LVLRNG, "level out of range") +ERRDEF(INVLVL, "invalid level") +ERRDEF(INVOPT, "invalid option") +ERRDEF(INVOPTM, "invalid option " LUA_QS) +ERRDEF(INVFMT, "invalid format") +ERRDEF(SETFENV, LUA_QL("setfenv") " cannot change environment of given object") +ERRDEF(CORUN, "cannot resume running coroutine") +ERRDEF(CODEAD, "cannot resume dead coroutine") +ERRDEF(COSUSP, "cannot resume non-suspended coroutine") +ERRDEF(TABINS, "wrong number of arguments to " LUA_QL("insert")) +ERRDEF(TABCAT, "invalid value (%s) at index %d in table for " LUA_QL("concat")) +ERRDEF(TABSORT, "invalid order function for sorting") +ERRDEF(IOCLFL, "attempt to use a closed file") +ERRDEF(IOSTDCL, "standard file is closed") +ERRDEF(OSUNIQF, "unable to generate a unique filename") +ERRDEF(OSDATEF, "field " LUA_QS " missing in date table") +ERRDEF(STRDUMP, "unable to dump given function") +ERRDEF(STRSLC, "string slice too long") +ERRDEF(STRPATB, "missing " LUA_QL("[") " after " LUA_QL("%f") " in pattern") +ERRDEF(STRPATC, "invalid pattern capture") +ERRDEF(STRPATE, "malformed pattern (ends with " LUA_QL("%") ")") +ERRDEF(STRPATM, "malformed pattern (missing " LUA_QL("]") ")") +ERRDEF(STRPATU, "unbalanced pattern") +ERRDEF(STRPATX, "pattern too complex") +ERRDEF(STRCAPI, "invalid capture index") +ERRDEF(STRCAPN, "too many captures") +ERRDEF(STRCAPU, "unfinished capture") +ERRDEF(STRFMTO, "invalid option " LUA_QL("%%%c") " to " LUA_QL("format")) +ERRDEF(STRFMTR, "invalid format (repeated flags)") +ERRDEF(STRFMTW, "invalid format (width or precision too long)") +ERRDEF(STRGSRV, "invalid replacement value (a %s)") +ERRDEF(BADMODN, "name conflict for module " LUA_QS) +#if LJ_HASJIT +ERRDEF(JITPROT, "runtime code generation failed, restricted kernel?") +#if LJ_TARGET_X86ORX64 +ERRDEF(NOJIT, "JIT compiler disabled, CPU does not support SSE2") +#else +ERRDEF(NOJIT, "JIT compiler disabled") +#endif +#elif defined(LJ_ARCH_NOJIT) +ERRDEF(NOJIT, "no JIT compiler for this architecture (yet)") +#else +ERRDEF(NOJIT, "JIT compiler permanently disabled by build option") +#endif +ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS) + +/* Lexer/parser errors. */ +ERRDEF(XMODE, "attempt to load chunk with wrong mode") +ERRDEF(XNEAR, "%s near " LUA_QS) +ERRDEF(XELEM, "lexical element too long") +ERRDEF(XLINES, "chunk has too many lines") +ERRDEF(XLEVELS, "chunk has too many syntax levels") +ERRDEF(XNUMBER, "malformed number") +ERRDEF(XLSTR, "unfinished long string") +ERRDEF(XLCOM, "unfinished long comment") +ERRDEF(XSTR, "unfinished string") +ERRDEF(XESC, "invalid escape sequence") +ERRDEF(XLDELIM, "invalid long string delimiter") +ERRDEF(XTOKEN, LUA_QS " expected") +ERRDEF(XJUMP, "control structure too long") +ERRDEF(XSLOTS, "function or expression too complex") +ERRDEF(XLIMC, "chunk has more than %d local variables") +ERRDEF(XLIMM, "main function has more than %d %s") +ERRDEF(XLIMF, "function at line %d has more than %d %s") +ERRDEF(XMATCH, LUA_QS " expected (to close " LUA_QS " at line %d)") +ERRDEF(XFIXUP, "function too long for return fixup") +ERRDEF(XPARAM, " or " LUA_QL("...") " expected") +#if !LJ_52 +ERRDEF(XAMBIG, "ambiguous syntax (function call x new statement)") +#endif +ERRDEF(XFUNARG, "function arguments expected") +ERRDEF(XSYMBOL, "unexpected symbol") +ERRDEF(XDOTS, "cannot use " LUA_QL("...") " outside a vararg function") +ERRDEF(XSYNTAX, "syntax error") +ERRDEF(XFOR, LUA_QL("=") " or " LUA_QL("in") " expected") +ERRDEF(XBREAK, "no loop to break") +ERRDEF(XLUNDEF, "undefined label " LUA_QS) +ERRDEF(XLDUP, "duplicate label " LUA_QS) +ERRDEF(XGSCOPE, " jumps into the scope of local " LUA_QS) + +/* Bytecode reader errors. */ +ERRDEF(BCFMT, "cannot load incompatible bytecode") +ERRDEF(BCBAD, "cannot load malformed bytecode") + +#if LJ_HASFFI +/* FFI errors. */ +ERRDEF(FFI_INVTYPE, "invalid C type") +ERRDEF(FFI_INVSIZE, "size of C type is unknown or too large") +ERRDEF(FFI_BADSCL, "bad storage class") +ERRDEF(FFI_DECLSPEC, "declaration specifier expected") +ERRDEF(FFI_BADTAG, "undeclared or implicit tag " LUA_QS) +ERRDEF(FFI_REDEF, "attempt to redefine " LUA_QS) +ERRDEF(FFI_NUMPARAM, "wrong number of type parameters") +ERRDEF(FFI_INITOV, "too many initializers for " LUA_QS) +ERRDEF(FFI_BADCONV, "cannot convert " LUA_QS " to " LUA_QS) +ERRDEF(FFI_BADLEN, "attempt to get length of " LUA_QS) +ERRDEF(FFI_BADCONCAT, "attempt to concatenate " LUA_QS " and " LUA_QS) +ERRDEF(FFI_BADARITH, "attempt to perform arithmetic on " LUA_QS " and " LUA_QS) +ERRDEF(FFI_BADCOMP, "attempt to compare " LUA_QS " with " LUA_QS) +ERRDEF(FFI_BADCALL, LUA_QS " is not callable") +ERRDEF(FFI_NUMARG, "wrong number of arguments for function call") +ERRDEF(FFI_BADMEMBER, LUA_QS " has no member named " LUA_QS) +ERRDEF(FFI_BADIDX, LUA_QS " cannot be indexed") +ERRDEF(FFI_BADIDXW, LUA_QS " cannot be indexed with " LUA_QS) +ERRDEF(FFI_BADMM, LUA_QS " has no " LUA_QS " metamethod") +ERRDEF(FFI_WRCONST, "attempt to write to constant location") +ERRDEF(FFI_NODECL, "missing declaration for symbol " LUA_QS) +ERRDEF(FFI_BADCBACK, "bad callback") +#if LJ_OS_NOJIT +ERRDEF(FFI_CBACKOV, "no support for callbacks on this OS") +#else +ERRDEF(FFI_CBACKOV, "too many callbacks") +#endif +ERRDEF(FFI_NYIPACKBIT, "NYI: packed bit fields") +ERRDEF(FFI_NYICALL, "NYI: cannot call this C function (yet)") +#endif + +#undef ERRDEF + +/* Detecting unused error messages: + awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, ""); printf "grep -q LJ_ERR_%s *.[ch] || echo %s\n", $1, $1}' lj_errmsg.h | sh +*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ff.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ff.h new file mode 100644 index 0000000..d91a739 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ff.h @@ -0,0 +1,18 @@ +/* +** Fast function IDs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FF_H +#define _LJ_FF_H + +/* Fast function ID. */ +typedef enum { + FF_LUA_ = FF_LUA, /* Lua function (must be 0). */ + FF_C_ = FF_C, /* Regular C function (must be 1). */ +#define FFDEF(name) FF_##name, +#include "lj_ffdef.h" + FF__MAX +} FastFunc; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.c new file mode 100644 index 0000000..794bbd4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.c @@ -0,0 +1,888 @@ +/* +** Fast function call recorder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ffrecord_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_crecord.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* -- Fast function recording handlers ------------------------------------ */ + +/* Conventions for fast function call handlers: +** +** The argument slots start at J->base[0]. All of them are guaranteed to be +** valid and type-specialized references. J->base[J->maxslot] is set to 0 +** as a sentinel. The runtime argument values start at rd->argv[0]. +** +** In general fast functions should check for presence of all of their +** arguments and for the correct argument types. Some simplifications +** are allowed if the interpreter throws instead. But even if recording +** is aborted, the generated IR must be consistent (no zero-refs). +** +** The number of results in rd->nres is set to 1. Handlers that return +** a different number of results need to override it. A negative value +** prevents return processing (e.g. for pending calls). +** +** Results need to be stored starting at J->base[0]. Return processing +** moves them to the right slots later. +** +** The per-ffid auxiliary data is the value of the 2nd part of the +** LJLIB_REC() annotation. This allows handling similar functionality +** in a common handler. +*/ + +/* Type of handler to record a fast function. */ +typedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd); + +/* Get runtime value of int argument. */ +static int32_t argv2int(jit_State *J, TValue *o) +{ + if (!lj_strscan_numberobj(o)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + return tvisint(o) ? intV(o) : lj_num2int(numV(o)); +} + +/* Get runtime value of string argument. */ +static GCstr *argv2str(jit_State *J, TValue *o) +{ + if (LJ_LIKELY(tvisstr(o))) { + return strV(o); + } else { + GCstr *s; + if (!tvisnumber(o)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if (tvisint(o)) + s = lj_str_fromint(J->L, intV(o)); + else + s = lj_str_fromnum(J->L, &o->n); + setstrV(J->L, o, s); + return s; + } +} + +/* Return number of results wanted by caller. */ +static ptrdiff_t results_wanted(jit_State *J) +{ + TValue *frame = J->L->base-1; + if (frame_islua(frame)) + return (ptrdiff_t)bc_b(frame_pc(frame)[-1]) - 1; + else + return -1; +} + +/* Throw error for unsupported variant of fast function. */ +LJ_NORET static void recff_nyiu(jit_State *J) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFFU); +} + +/* Fallback handler for all fast functions that are not recorded (yet). */ +static void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYIFF); + UNUSED(rd); +} + +/* C functions can have arbitrary side-effects and are not recorded (yet). */ +static void LJ_FASTCALL recff_c(jit_State *J, RecordFFData *rd) +{ + setfuncV(J->L, &J->errinfo, J->fn); + lj_trace_err_info(J, LJ_TRERR_NYICF); + UNUSED(rd); +} + +/* -- Base library fast functions ----------------------------------------- */ + +static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd) +{ + /* Arguments already specialized. The interpreter throws for nil/false. */ + rd->nres = J->maxslot; /* Pass through all arguments. */ +} + +static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd) +{ + /* Arguments already specialized. Result is a constant string. Neat, huh? */ + uint32_t t; + if (tvisnumber(&rd->argv[0])) + t = ~LJ_TNUMX; + else if (LJ_64 && tvislightud(&rd->argv[0])) + t = ~LJ_TLIGHTUD; + else + t = ~itype(&rd->argv[0]); + J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[t])); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tr) { + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + if (lj_record_mm_lookup(J, &ix, MM_metatable)) + J->base[0] = ix.mobj; + else + J->base[0] = ix.mt; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + TRef mt = J->base[1]; + if (tref_istab(tr) && (tref_istab(mt) || (mt && tref_isnil(mt)))) { + TRef fref, mtref; + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + lj_record_mm_lookup(J, &ix, MM_metatable); /* Guard for no __metatable. */ + fref = emitir(IRT(IR_FREF, IRT_P32), tr, IRFL_TAB_META); + mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt; + emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref); + if (!tref_isnil(mt)) + emitir(IRT(IR_TBAR, IRT_TAB), tr, 0); + J->base[0] = tr; + J->needsnap = 1; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawget(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; ix.key = J->base[1]; + if (tref_istab(ix.tab) && ix.key) { + ix.val = 0; ix.idxchain = 0; + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + copyTV(J->L, &ix.keyv, &rd->argv[1]); + J->base[0] = lj_record_idx(J, &ix); + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawset(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; ix.key = J->base[1]; ix.val = J->base[2]; + if (tref_istab(ix.tab) && ix.key && ix.val) { + ix.idxchain = 0; + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + copyTV(J->L, &ix.keyv, &rd->argv[1]); + copyTV(J->L, &ix.valv, &rd->argv[2]); + lj_record_idx(J, &ix); + /* Pass through table at J->base[0] as result. */ + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd) +{ + TRef tra = J->base[0]; + TRef trb = J->base[1]; + if (tra && trb) { + int diff = lj_record_objcmp(J, tra, trb, &rd->argv[0], &rd->argv[1]); + J->base[0] = diff ? TREF_FALSE : TREF_TRUE; + } /* else: Interpreter will throw. */ +} + +#if LJ_52 +static void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isstr(tr)) + J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN); + else if (tref_istab(tr)) + J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr); + /* else: Interpreter will throw. */ + UNUSED(rd); +} +#endif + +/* Determine mode of select() call. */ +int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv) +{ + if (tref_isstr(tr) && *strVdata(tv) == '#') { /* select('#', ...) */ + if (strV(tv)->len == 1) { + emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, strV(tv))); + } else { + TRef trptr = emitir(IRT(IR_STRREF, IRT_P32), tr, lj_ir_kint(J, 0)); + TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY); + emitir(IRTG(IR_EQ, IRT_INT), trchar, lj_ir_kint(J, '#')); + } + return 0; + } else { /* select(n, ...) */ + int32_t start = argv2int(J, tv); + if (start == 0) lj_trace_err(J, LJ_TRERR_BADTYPE); /* A bit misleading. */ + return start; + } +} + +static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tr) { + ptrdiff_t start = lj_ffrecord_select_mode(J, tr, &rd->argv[0]); + if (start == 0) { /* select('#', ...) */ + J->base[0] = lj_ir_kint(J, J->maxslot - 1); + } else if (tref_isk(tr)) { /* select(k, ...) */ + ptrdiff_t n = (ptrdiff_t)J->maxslot; + if (start < 0) start += n; + else if (start > n) start = n; + rd->nres = n - start; + if (start >= 1) { + ptrdiff_t i; + for (i = 0; i < n - start; i++) + J->base[i] = J->base[start+i]; + } /* else: Interpreter will throw. */ + } else { + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + TRef base = J->base[1]; + if (tr && !tref_isnil(base)) { + base = lj_opt_narrow_toint(J, base); + if (!tref_isk(base) || IR(tref_ref(base))->i != 10) + recff_nyiu(J); + } + if (tref_isnumber_str(tr)) { + if (tref_isstr(tr)) { + TValue tmp; + if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) + recff_nyiu(J); /* Would need an inverted STRTO for this case. */ + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + } +#if LJ_HASFFI + } else if (tref_iscdata(tr)) { + lj_crecord_tonumber(J, rd); + return; +#endif + } else { + tr = TREF_NIL; + } + J->base[0] = tr; + UNUSED(rd); +} + +static TValue *recff_metacall_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + lj_record_tailcall(J, 0, 1); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +static int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm) +{ + RecordIndex ix; + ix.tab = J->base[0]; + copyTV(J->L, &ix.tabv, &rd->argv[0]); + if (lj_record_mm_lookup(J, &ix, mm)) { /* Has metamethod? */ + int errcode; + TValue argv0; + /* Temporarily insert metamethod below object. */ + J->base[1] = J->base[0]; + J->base[0] = ix.mobj; + copyTV(J->L, &argv0, &rd->argv[0]); + copyTV(J->L, &rd->argv[1], &rd->argv[0]); + copyTV(J->L, &rd->argv[0], &ix.mobjv); + /* Need to protect lj_record_tailcall because it may throw. */ + errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp); + /* Always undo Lua stack changes to avoid confusing the interpreter. */ + copyTV(J->L, &rd->argv[0], &argv0); + if (errcode) + lj_err_throw(J->L, errcode); /* Propagate errors. */ + rd->nres = -1; /* Pending call. */ + return 1; /* Tailcalled to metamethod. */ + } + return 0; +} + +static void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isstr(tr)) { + /* Ignore __tostring in the string base metatable. */ + /* Pass on result in J->base[0]. */ + } else if (!recff_metacall(J, rd, MM_tostring)) { + if (tref_isnumber(tr)) { + J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); + } else if (tref_ispri(tr)) { + J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[tref_type(tr)])); + } else { + recff_nyiu(J); + } + } +} + +static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; + if (tref_istab(ix.tab)) { + if (!tvisnumber(&rd->argv[1])) /* No support for string coercion. */ + lj_trace_err(J, LJ_TRERR_BADTYPE); + setintV(&ix.keyv, numberVint(&rd->argv[1])+1); + settabV(J->L, &ix.tabv, tabV(&rd->argv[0])); + ix.val = 0; ix.idxchain = 0; + ix.key = lj_opt_narrow_toint(J, J->base[1]); + J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1)); + J->base[1] = lj_record_idx(J, &ix); + rd->nres = tref_isnil(J->base[1]) ? 0 : 2; + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) +{ + if (!(LJ_52 && recff_metacall(J, rd, MM_ipairs))) { + TRef tab = J->base[0]; + if (tref_istab(tab)) { + J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); + J->base[1] = tab; + J->base[2] = lj_ir_kint(J, 0); + rd->nres = 3; + } /* else: Interpreter will throw. */ + } +} + +static void LJ_FASTCALL recff_pcall(jit_State *J, RecordFFData *rd) +{ + if (J->maxslot >= 1) { + lj_record_call(J, 0, J->maxslot - 1); + rd->nres = -1; /* Pending call. */ + } /* else: Interpreter will throw. */ +} + +static TValue *recff_xpcall_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + lj_record_call(J, 1, J->maxslot - 2); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd) +{ + if (J->maxslot >= 2) { + TValue argv0, argv1; + TRef tmp; + int errcode; + /* Swap function and traceback. */ + tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp; + copyTV(J->L, &argv0, &rd->argv[0]); + copyTV(J->L, &argv1, &rd->argv[1]); + copyTV(J->L, &rd->argv[0], &argv1); + copyTV(J->L, &rd->argv[1], &argv0); + /* Need to protect lj_record_call because it may throw. */ + errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp); + /* Always undo Lua stack swap to avoid confusing the interpreter. */ + copyTV(J->L, &rd->argv[0], &argv0); + copyTV(J->L, &rd->argv[1], &argv1); + if (errcode) + lj_err_throw(J->L, errcode); /* Propagate errors. */ + rd->nres = -1; /* Pending call. */ + } /* else: Interpreter will throw. */ +} + +/* -- Math library fast functions ----------------------------------------- */ + +static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + J->base[0] = emitir(IRTN(IR_ABS), tr, lj_ir_knum_abs(J)); + UNUSED(rd); +} + +/* Record rounding functions math.floor and math.ceil. */ +static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (!tref_isinteger(tr)) { /* Pass through integers unmodified. */ + tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data); + /* Result is integral (or NaN/Inf), but may not fit an int32_t. */ + if (LJ_DUALNUM) { /* Try to narrow using a guarded conversion to int. */ + lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data); + if (n == (lua_Number)lj_num2int(n)) + tr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK); + } + J->base[0] = tr; + } +} + +/* Record unary math.* functions, mapped to IR_FPMATH opcode. */ +static void LJ_FASTCALL recff_math_unary(jit_State *J, RecordFFData *rd) +{ + J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data); +} + +/* Record math.log. */ +static void LJ_FASTCALL recff_math_log(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + if (J->base[1]) { +#ifdef LUAJIT_NO_LOG2 + uint32_t fpm = IRFPM_LOG; +#else + uint32_t fpm = IRFPM_LOG2; +#endif + TRef trb = lj_ir_tonum(J, J->base[1]); + tr = emitir(IRTN(IR_FPMATH), tr, fpm); + trb = emitir(IRTN(IR_FPMATH), trb, fpm); + trb = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), trb); + tr = emitir(IRTN(IR_MUL), tr, trb); + } else { + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_LOG); + } + J->base[0] = tr; + UNUSED(rd); +} + +/* Record math.atan2. */ +static void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + TRef tr2 = lj_ir_tonum(J, J->base[1]); + J->base[0] = emitir(IRTN(IR_ATAN2), tr, tr2); + UNUSED(rd); +} + +/* Record math.ldexp. */ +static void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); +#if LJ_TARGET_X86ORX64 + TRef tr2 = lj_ir_tonum(J, J->base[1]); +#else + TRef tr2 = lj_opt_narrow_toint(J, J->base[1]); +#endif + J->base[0] = emitir(IRTN(IR_LDEXP), tr, tr2); + UNUSED(rd); +} + +/* Record math.asin, math.acos, math.atan. */ +static void LJ_FASTCALL recff_math_atrig(jit_State *J, RecordFFData *rd) +{ + TRef y = lj_ir_tonum(J, J->base[0]); + TRef x = lj_ir_knum_one(J); + uint32_t ffid = rd->data; + if (ffid != FF_math_atan) { + TRef tmp = emitir(IRTN(IR_MUL), y, y); + tmp = emitir(IRTN(IR_SUB), x, tmp); + tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_SQRT); + if (ffid == FF_math_asin) { x = tmp; } else { x = y; y = tmp; } + } + J->base[0] = emitir(IRTN(IR_ATAN2), y, x); +} + +static void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data); +} + +static void LJ_FASTCALL recff_math_modf(jit_State *J, RecordFFData *rd) +{ + TRef tr = J->base[0]; + if (tref_isinteger(tr)) { + J->base[0] = tr; + J->base[1] = lj_ir_kint(J, 0); + } else { + TRef trt; + tr = lj_ir_tonum(J, tr); + trt = emitir(IRTN(IR_FPMATH), tr, IRFPM_TRUNC); + J->base[0] = trt; + J->base[1] = emitir(IRTN(IR_SUB), tr, trt); + } + rd->nres = 2; +} + +static void LJ_FASTCALL recff_math_degrad(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + TRef trm = lj_ir_knum(J, numV(&J->fn->c.upvalue[0])); + J->base[0] = emitir(IRTN(IR_MUL), tr, trm); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonum(J, J->base[0]); + if (!tref_isnumber_str(J->base[1])) + lj_trace_err(J, LJ_TRERR_BADTYPE); + J->base[0] = lj_opt_narrow_pow(J, tr, J->base[1], &rd->argv[1]); + UNUSED(rd); +} + +static void LJ_FASTCALL recff_math_minmax(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_ir_tonumber(J, J->base[0]); + uint32_t op = rd->data; + BCReg i; + for (i = 1; J->base[i] != 0; i++) { + TRef tr2 = lj_ir_tonumber(J, J->base[i]); + IRType t = IRT_INT; + if (!(tref_isinteger(tr) && tref_isinteger(tr2))) { + if (tref_isinteger(tr)) tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + if (tref_isinteger(tr2)) tr2 = emitir(IRTN(IR_CONV), tr2, IRCONV_NUM_INT); + t = IRT_NUM; + } + tr = emitir(IRT(op, t), tr, tr2); + } + J->base[0] = tr; +} + +static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd) +{ + GCudata *ud = udataV(&J->fn->c.upvalue[0]); + TRef tr, one; + lj_ir_kgc(J, obj2gco(ud), IRT_UDATA); /* Prevent collection. */ + tr = lj_ir_call(J, IRCALL_lj_math_random_step, lj_ir_kptr(J, uddata(ud))); + one = lj_ir_knum_one(J); + tr = emitir(IRTN(IR_SUB), tr, one); + if (J->base[0]) { + TRef tr1 = lj_ir_tonum(J, J->base[0]); + if (J->base[1]) { /* d = floor(d*(r2-r1+1.0)) + r1 */ + TRef tr2 = lj_ir_tonum(J, J->base[1]); + tr2 = emitir(IRTN(IR_SUB), tr2, tr1); + tr2 = emitir(IRTN(IR_ADD), tr2, one); + tr = emitir(IRTN(IR_MUL), tr, tr2); + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); + tr = emitir(IRTN(IR_ADD), tr, tr1); + } else { /* d = floor(d*r1) + 1.0 */ + tr = emitir(IRTN(IR_MUL), tr, tr1); + tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); + tr = emitir(IRTN(IR_ADD), tr, one); + } + } + J->base[0] = tr; + UNUSED(rd); +} + +/* -- Bit library fast functions ------------------------------------------ */ + +/* Record unary bit.tobit, bit.bnot, bit.bswap. */ +static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + J->base[0] = (rd->data == IR_TOBIT) ? tr : emitir(IRTI(rd->data), tr, 0); +} + +/* Record N-ary bit.band, bit.bor, bit.bxor. */ +static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + uint32_t op = rd->data; + BCReg i; + for (i = 1; J->base[i] != 0; i++) + tr = emitir(IRTI(op), tr, lj_opt_narrow_tobit(J, J->base[i])); + J->base[0] = tr; +} + +/* Record bit shifts. */ +static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) +{ + TRef tr = lj_opt_narrow_tobit(J, J->base[0]); + TRef tsh = lj_opt_narrow_tobit(J, J->base[1]); + IROp op = (IROp)rd->data; + if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && + !tref_isk(tsh)) + tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31)); +#ifdef LJ_TARGET_UNIFYROT + if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) { + op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR; + tsh = emitir(IRTI(IR_NEG), tsh, tsh); + } +#endif + J->base[0] = emitir(IRTI(op), tr, tsh); +} + +/* -- String library fast functions --------------------------------------- */ + +static void LJ_FASTCALL recff_string_len(jit_State *J, RecordFFData *rd) +{ + J->base[0] = emitir(IRTI(IR_FLOAD), lj_ir_tostr(J, J->base[0]), IRFL_STR_LEN); + UNUSED(rd); +} + +/* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */ +static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) +{ + TRef trstr = lj_ir_tostr(J, J->base[0]); + TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN); + TRef tr0 = lj_ir_kint(J, 0); + TRef trstart, trend; + GCstr *str = argv2str(J, &rd->argv[0]); + int32_t start, end; + if (rd->data) { /* string.sub(str, start [,end]) */ + start = argv2int(J, &rd->argv[1]); + trstart = lj_opt_narrow_toint(J, J->base[1]); + trend = J->base[2]; + if (tref_isnil(trend)) { + trend = lj_ir_kint(J, -1); + end = -1; + } else { + trend = lj_opt_narrow_toint(J, trend); + end = argv2int(J, &rd->argv[2]); + } + } else { /* string.byte(str, [,start [,end]]) */ + if (tref_isnil(J->base[1])) { + start = 1; + trstart = lj_ir_kint(J, 1); + } else { + start = argv2int(J, &rd->argv[1]); + trstart = lj_opt_narrow_toint(J, J->base[1]); + } + if (J->base[1] && !tref_isnil(J->base[2])) { + trend = lj_opt_narrow_toint(J, J->base[2]); + end = argv2int(J, &rd->argv[2]); + } else { + trend = trstart; + end = start; + } + } + if (end < 0) { + emitir(IRTGI(IR_LT), trend, tr0); + trend = emitir(IRTI(IR_ADD), emitir(IRTI(IR_ADD), trlen, trend), + lj_ir_kint(J, 1)); + end = end+(int32_t)str->len+1; + } else if ((MSize)end <= str->len) { + emitir(IRTGI(IR_ULE), trend, trlen); + } else { + emitir(IRTGI(IR_GT), trend, trlen); + end = (int32_t)str->len; + trend = trlen; + } + if (start < 0) { + emitir(IRTGI(IR_LT), trstart, tr0); + trstart = emitir(IRTI(IR_ADD), trlen, trstart); + start = start+(int32_t)str->len; + emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), trstart, tr0); + if (start < 0) { + trstart = tr0; + start = 0; + } + } else { + if (start == 0) { + emitir(IRTGI(IR_EQ), trstart, tr0); + trstart = tr0; + } else { + trstart = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1)); + emitir(IRTGI(IR_GE), trstart, tr0); + start--; + } + } + if (rd->data) { /* Return string.sub result. */ + if (end - start >= 0) { + /* Also handle empty range here, to avoid extra traces. */ + TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart); + emitir(IRTGI(IR_GE), trslen, tr0); + trptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart); + J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen); + } else { /* Range underflow: return empty string. */ + emitir(IRTGI(IR_LT), trend, trstart); + J->base[0] = lj_ir_kstr(J, lj_str_new(J->L, strdata(str), 0)); + } + } else { /* Return string.byte result(s). */ + ptrdiff_t i, len = end - start; + if (len > 0) { + TRef trslen = emitir(IRTI(IR_SUB), trend, trstart); + emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len)); + if (J->baseslot + len > LJ_MAX_JSLOTS) + lj_trace_err_info(J, LJ_TRERR_STACKOV); + rd->nres = len; + for (i = 0; i < len; i++) { + TRef tmp = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, (int32_t)i)); + tmp = emitir(IRT(IR_STRREF, IRT_P32), trstr, tmp); + J->base[i] = emitir(IRT(IR_XLOAD, IRT_U8), tmp, IRXLOAD_READONLY); + } + } else { /* Empty range or range underflow: return no results. */ + emitir(IRTGI(IR_LE), trend, trstart); + rd->nres = 0; + } + } +} + +/* -- Table library fast functions ---------------------------------------- */ + +static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd) +{ + if (tref_istab(J->base[0])) + J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]); + /* else: Interpreter will throw. */ + UNUSED(rd); +} + +static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) +{ + TRef tab = J->base[0]; + rd->nres = 0; + if (tref_istab(tab)) { + if (tref_isnil(J->base[1])) { /* Simple pop: t[#t] = nil */ + TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, tab); + GCtab *t = tabV(&rd->argv[0]); + MSize len = lj_tab_len(t); + emitir(IRTGI(len ? IR_NE : IR_EQ), trlen, lj_ir_kint(J, 0)); + if (len) { + RecordIndex ix; + ix.tab = tab; + ix.key = trlen; + settabV(J->L, &ix.tabv, t); + setintV(&ix.keyv, len); + ix.idxchain = 0; + if (results_wanted(J) != 0) { /* Specialize load only if needed. */ + ix.val = 0; + J->base[0] = lj_record_idx(J, &ix); /* Load previous value. */ + rd->nres = 1; + /* Assumes ix.key/ix.tab is not modified for raw lj_record_idx(). */ + } + ix.val = TREF_NIL; + lj_record_idx(J, &ix); /* Remove value. */ + } + } else { /* Complex case: remove in the middle. */ + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) +{ + RecordIndex ix; + ix.tab = J->base[0]; + ix.val = J->base[1]; + rd->nres = 0; + if (tref_istab(ix.tab) && ix.val) { + if (!J->base[2]) { /* Simple push: t[#t+1] = v */ + TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, ix.tab); + GCtab *t = tabV(&rd->argv[0]); + ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1)); + settabV(J->L, &ix.tabv, t); + setintV(&ix.keyv, lj_tab_len(t) + 1); + ix.idxchain = 0; + lj_record_idx(J, &ix); /* Set new value. */ + } else { /* Complex case: insert in the middle. */ + recff_nyiu(J); + } + } /* else: Interpreter will throw. */ +} + +/* -- I/O library fast functions ------------------------------------------ */ + +/* Get FILE* for I/O function. Any I/O error aborts recording, so there's +** no need to encode the alternate cases for any of the guards. +*/ +static TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id) +{ + TRef tr, ud, fp; + if (id) { /* io.func() */ + tr = lj_ir_kptr(J, &J2G(J)->gcroot[id]); + ud = emitir(IRT(IR_XLOAD, IRT_UDATA), tr, 0); + } else { /* fp:method() */ + ud = J->base[0]; + if (!tref_isudata(ud)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); + } + *udp = ud; + fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE); + emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR)); + return fp; +} + +static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd) +{ + TRef ud, fp = recff_io_fp(J, &ud, rd->data); + TRef zero = lj_ir_kint(J, 0); + TRef one = lj_ir_kint(J, 1); + ptrdiff_t i = rd->data == 0 ? 1 : 0; + for (; J->base[i]; i++) { + TRef str = lj_ir_tostr(J, J->base[i]); + TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero); + TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN); + if (tref_isk(len) && IR(tref_ref(len))->i == 1) { + TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY); + tr = lj_ir_call(J, IRCALL_fputc, tr, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1)); + } else { + TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_EQ), tr, len); + } + } + J->base[0] = LJ_52 ? ud : TREF_TRUE; +} + +static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) +{ + TRef ud, fp = recff_io_fp(J, &ud, rd->data); + TRef tr = lj_ir_call(J, IRCALL_fflush, fp); + if (results_wanted(J) != 0) /* Check result only if not ignored. */ + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); + J->base[0] = TREF_TRUE; +} + +/* -- Record calls to fast functions -------------------------------------- */ + +#include "lj_recdef.h" + +static uint32_t recdef_lookup(GCfunc *fn) +{ + if (fn->c.ffid < sizeof(recff_idmap)/sizeof(recff_idmap[0])) + return recff_idmap[fn->c.ffid]; + else + return 0; +} + +/* Record entry to a fast function or C function. */ +void lj_ffrecord_func(jit_State *J) +{ + RecordFFData rd; + uint32_t m = recdef_lookup(J->fn); + rd.data = m & 0xff; + rd.nres = 1; /* Default is one result. */ + rd.argv = J->L->base; + J->base[J->maxslot] = 0; /* Mark end of arguments. */ + (recff_func[m >> 8])(J, &rd); /* Call recff_* handler. */ + if (rd.nres >= 0) { + if (J->postproc == LJ_POST_NONE) J->postproc = LJ_POST_FFRETRY; + lj_record_ret(J, 0, rd.nres); + } +} + +#undef IR +#undef emitir + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.h new file mode 100644 index 0000000..b3bc662 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ffrecord.h @@ -0,0 +1,24 @@ +/* +** Fast function call recorder. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FFRECORD_H +#define _LJ_FFRECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* Data used by handlers to record a fast function. */ +typedef struct RecordFFData { + TValue *argv; /* Runtime argument values. */ + ptrdiff_t nres; /* Number of returned results (defaults to 1). */ + uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */ +} RecordFFData; + +LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv); +LJ_FUNC void lj_ffrecord_func(jit_State *J); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_frame.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_frame.h new file mode 100644 index 0000000..fb533b0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_frame.h @@ -0,0 +1,183 @@ +/* +** Stack frames. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FRAME_H +#define _LJ_FRAME_H + +#include "lj_obj.h" +#include "lj_bc.h" + +/* -- Lua stack frame ----------------------------------------------------- */ + +/* Frame type markers in callee function slot (callee base-1). */ +enum { + FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG, + FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH +}; +#define FRAME_TYPE 3 +#define FRAME_P 4 +#define FRAME_TYPEP (FRAME_TYPE|FRAME_P) + +/* Macros to access and modify Lua frames. */ +#define frame_gc(f) (gcref((f)->fr.func)) +#define frame_func(f) (&frame_gc(f)->fn) +#define frame_ftsz(f) ((f)->fr.tp.ftsz) + +#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE) +#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP) +#define frame_islua(f) (frame_type(f) == FRAME_LUA) +#define frame_isc(f) (frame_type(f) == FRAME_C) +#define frame_iscont(f) (frame_typep(f) == FRAME_CONT) +#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG) +#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL) + +#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns)) +#define frame_contpc(f) (frame_pc((f)-1)) +#if LJ_64 +#define frame_contf(f) \ + ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \ + (intptr_t)(int32_t)((f)-1)->u32.lo)) +#else +#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void)) +#endif +#define frame_delta(f) (frame_ftsz(f) >> 3) +#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP) + +#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1]))) +#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f))) +#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f)) +/* Note: this macro does not skip over FRAME_VARG. */ + +#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc))) +#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz)) +#define setframe_gc(f, p) (setgcref((f)->fr.func, (p))) + +/* -- C stack frame ------------------------------------------------------- */ + +/* Macros to access and modify the C stack frame chain. */ + +/* These definitions must match with the arch-specific *.dasc files. */ +#if LJ_TARGET_X86 +#define CFRAME_OFS_ERRF (15*4) +#define CFRAME_OFS_NRES (14*4) +#define CFRAME_OFS_PREV (13*4) +#define CFRAME_OFS_L (12*4) +#define CFRAME_OFS_PC (6*4) +#define CFRAME_OFS_MULTRES (5*4) +#define CFRAME_SIZE (12*4) +#define CFRAME_SHIFT_MULTRES 0 +#elif LJ_TARGET_X64 +#if LJ_ABI_WIN +#define CFRAME_OFS_PREV (13*8) +#define CFRAME_OFS_PC (25*4) +#define CFRAME_OFS_L (24*4) +#define CFRAME_OFS_ERRF (23*4) +#define CFRAME_OFS_NRES (22*4) +#define CFRAME_OFS_MULTRES (21*4) +#define CFRAME_SIZE (10*8) +#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8) +#define CFRAME_SHIFT_MULTRES 0 +#else +#define CFRAME_OFS_PREV (4*8) +#define CFRAME_OFS_PC (7*4) +#define CFRAME_OFS_L (6*4) +#define CFRAME_OFS_ERRF (5*4) +#define CFRAME_OFS_NRES (4*4) +#define CFRAME_OFS_MULTRES (1*4) +#define CFRAME_SIZE (10*8) +#define CFRAME_SIZE_JIT (CFRAME_SIZE + 16) +#define CFRAME_SHIFT_MULTRES 0 +#endif +#elif LJ_TARGET_ARM +#define CFRAME_OFS_ERRF 24 +#define CFRAME_OFS_NRES 20 +#define CFRAME_OFS_PREV 16 +#define CFRAME_OFS_L 12 +#define CFRAME_OFS_PC 8 +#define CFRAME_OFS_MULTRES 4 +#if LJ_ARCH_HASFPU +#define CFRAME_SIZE 128 +#else +#define CFRAME_SIZE 64 +#endif +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_TARGET_PPC +#if LJ_TARGET_XBOX360 +#define CFRAME_OFS_ERRF 424 +#define CFRAME_OFS_NRES 420 +#define CFRAME_OFS_PREV 400 +#define CFRAME_OFS_L 416 +#define CFRAME_OFS_PC 412 +#define CFRAME_OFS_MULTRES 408 +#define CFRAME_SIZE 384 +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_ARCH_PPC64 +#define CFRAME_OFS_ERRF 472 +#define CFRAME_OFS_NRES 468 +#define CFRAME_OFS_PREV 448 +#define CFRAME_OFS_L 464 +#define CFRAME_OFS_PC 460 +#define CFRAME_OFS_MULTRES 456 +#define CFRAME_SIZE 400 +#define CFRAME_SHIFT_MULTRES 3 +#else +#define CFRAME_OFS_ERRF 48 +#define CFRAME_OFS_NRES 44 +#define CFRAME_OFS_PREV 40 +#define CFRAME_OFS_L 36 +#define CFRAME_OFS_PC 32 +#define CFRAME_OFS_MULTRES 28 +#define CFRAME_SIZE 272 +#define CFRAME_SHIFT_MULTRES 3 +#endif +#elif LJ_TARGET_PPCSPE +#define CFRAME_OFS_ERRF 28 +#define CFRAME_OFS_NRES 24 +#define CFRAME_OFS_PREV 20 +#define CFRAME_OFS_L 16 +#define CFRAME_OFS_PC 12 +#define CFRAME_OFS_MULTRES 8 +#define CFRAME_SIZE 184 +#define CFRAME_SHIFT_MULTRES 3 +#elif LJ_TARGET_MIPS +#define CFRAME_OFS_ERRF 124 +#define CFRAME_OFS_NRES 120 +#define CFRAME_OFS_PREV 116 +#define CFRAME_OFS_L 112 +#define CFRAME_OFS_PC 20 +#define CFRAME_OFS_MULTRES 16 +#define CFRAME_SIZE 112 +#define CFRAME_SHIFT_MULTRES 3 +#else +#error "Missing CFRAME_* definitions for this architecture" +#endif + +#ifndef CFRAME_SIZE_JIT +#define CFRAME_SIZE_JIT CFRAME_SIZE +#endif + +#define CFRAME_RESUME 1 +#define CFRAME_UNWIND_FF 2 /* Only used in unwinder. */ +#define CFRAME_RAWMASK (~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF)) + +#define cframe_errfunc(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF)) +#define cframe_nres(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES)) +#define cframe_prev(cf) (*(void **)(((char *)(cf))+CFRAME_OFS_PREV)) +#define cframe_multres(cf) (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES)) +#define cframe_multres_n(cf) (cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES) +#define cframe_L(cf) \ + (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th) +#define cframe_pc(cf) \ + (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns)) +#define setcframe_L(cf, L) \ + (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L))) +#define setcframe_pc(cf, pc) \ + (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc))) +#define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_RESUME) +#define cframe_unwind_ff(cf) ((intptr_t)(cf) & CFRAME_UNWIND_FF) +#define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK)) +#define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe)) + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.c new file mode 100644 index 0000000..9a59b0f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.c @@ -0,0 +1,185 @@ +/* +** Function handling (prototypes, functions and upvalues). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_func_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_func.h" +#include "lj_trace.h" +#include "lj_vm.h" + +/* -- Prototypes ---------------------------------------------------------- */ + +void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt) +{ + lj_mem_free(g, pt, pt->sizept); +} + +/* -- Upvalues ------------------------------------------------------------ */ + +static void unlinkuv(GCupval *uv) +{ + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + setgcrefr(uvnext(uv)->prev, uv->prev); + setgcrefr(uvprev(uv)->next, uv->next); +} + +/* Find existing open upvalue for a stack slot or create a new one. */ +static GCupval *func_finduv(lua_State *L, TValue *slot) +{ + global_State *g = G(L); + GCRef *pp = &L->openupval; + GCupval *p; + GCupval *uv; + /* Search the sorted list of open upvalues. */ + while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) { + lua_assert(!p->closed && uvval(p) != &p->tv); + if (uvval(p) == slot) { /* Found open upvalue pointing to same slot? */ + if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */ + flipwhite(obj2gco(p)); + return p; + } + pp = &p->nextgc; + } + /* No matching upvalue found. Create a new one. */ + uv = lj_mem_newt(L, sizeof(GCupval), GCupval); + newwhite(g, uv); + uv->gct = ~LJ_TUPVAL; + uv->closed = 0; /* Still open. */ + setmref(uv->v, slot); /* Pointing to the stack slot. */ + /* NOBARRIER: The GCupval is new (marked white) and open. */ + setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */ + setgcref(*pp, obj2gco(uv)); + setgcref(uv->prev, obj2gco(&g->uvhead)); /* Insert into GC list, too. */ + setgcrefr(uv->next, g->uvhead.next); + setgcref(uvnext(uv)->prev, obj2gco(uv)); + setgcref(g->uvhead.next, obj2gco(uv)); + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + return uv; +} + +/* Create an empty and closed upvalue. */ +static GCupval *func_emptyuv(lua_State *L) +{ + GCupval *uv = (GCupval *)lj_mem_newgco(L, sizeof(GCupval)); + uv->gct = ~LJ_TUPVAL; + uv->closed = 1; + setnilV(&uv->tv); + setmref(uv->v, &uv->tv); + return uv; +} + +/* Close all open upvalues pointing to some stack level or above. */ +void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level) +{ + GCupval *uv; + global_State *g = G(L); + while (gcref(L->openupval) != NULL && + uvval((uv = gco2uv(gcref(L->openupval)))) >= level) { + GCobj *o = obj2gco(uv); + lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv); + setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */ + if (isdead(g, o)) { + lj_func_freeuv(g, uv); + } else { + unlinkuv(uv); + lj_gc_closeuv(g, uv); + } + } +} + +void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv) +{ + if (!uv->closed) + unlinkuv(uv); + lj_mem_freet(g, uv); +} + +/* -- Functions (closures) ------------------------------------------------ */ + +GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env) +{ + GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeCfunc(nelems)); + fn->c.gct = ~LJ_TFUNC; + fn->c.ffid = FF_C; + fn->c.nupvalues = (uint8_t)nelems; + /* NOBARRIER: The GCfunc is new (marked white). */ + setmref(fn->c.pc, &G(L)->bc_cfunc_ext); + setgcref(fn->c.env, obj2gco(env)); + return fn; +} + +static GCfunc *func_newL(lua_State *L, GCproto *pt, GCtab *env) +{ + uint32_t count; + GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeLfunc((MSize)pt->sizeuv)); + fn->l.gct = ~LJ_TFUNC; + fn->l.ffid = FF_LUA; + fn->l.nupvalues = 0; /* Set to zero until upvalues are initialized. */ + /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */ + setmref(fn->l.pc, proto_bc(pt)); + setgcref(fn->l.env, obj2gco(env)); + /* Saturating 3 bit counter (0..7) for created closures. */ + count = (uint32_t)pt->flags + PROTO_CLCOUNT; + pt->flags = (uint8_t)(count - ((count >> PROTO_CLC_BITS) & PROTO_CLCOUNT)); + return fn; +} + +/* Create a new Lua function with empty upvalues. */ +GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env) +{ + GCfunc *fn = func_newL(L, pt, env); + MSize i, nuv = pt->sizeuv; + /* NOBARRIER: The GCfunc is new (marked white). */ + for (i = 0; i < nuv; i++) { + GCupval *uv = func_emptyuv(L); + uv->dhash = (uint32_t)(uintptr_t)pt ^ ((uint32_t)proto_uv(pt)[i] << 24); + setgcref(fn->l.uvptr[i], obj2gco(uv)); + } + fn->l.nupvalues = (uint8_t)nuv; + return fn; +} + +/* Do a GC check and create a new Lua function with inherited upvalues. */ +GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent) +{ + GCfunc *fn; + GCRef *puv; + MSize i, nuv; + TValue *base; + lj_gc_check_fixtop(L); + fn = func_newL(L, pt, tabref(parent->env)); + /* NOBARRIER: The GCfunc is new (marked white). */ + puv = parent->uvptr; + nuv = pt->sizeuv; + base = L->base; + for (i = 0; i < nuv; i++) { + uint32_t v = proto_uv(pt)[i]; + GCupval *uv; + if ((v & PROTO_UV_LOCAL)) { + uv = func_finduv(L, base + (v & 0xff)); + uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1); + uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24); + } else { + uv = &gcref(puv[v])->uv; + } + setgcref(fn->l.uvptr[i], obj2gco(uv)); + } + fn->l.nupvalues = (uint8_t)nuv; + return fn; +} + +void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *fn) +{ + MSize size = isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) : + sizeCfunc((MSize)fn->c.nupvalues); + lj_mem_free(g, fn, size); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.h new file mode 100644 index 0000000..88732e8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_func.h @@ -0,0 +1,24 @@ +/* +** Function handling (prototypes, functions and upvalues). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_FUNC_H +#define _LJ_FUNC_H + +#include "lj_obj.h" + +/* Prototypes. */ +LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt); + +/* Upvalues. */ +LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level); +LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv); + +/* Functions (closures). */ +LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env); +LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env); +LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent); +LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.c new file mode 100644 index 0000000..c2bc397 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.c @@ -0,0 +1,849 @@ +/* +** Garbage collector. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_gc_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_udata.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#endif +#include "lj_trace.h" +#include "lj_vm.h" + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + +/* Macros to set GCobj colors and flags. */ +#define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES) +#define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK) +#define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED) + +/* -- Mark phase ---------------------------------------------------------- */ + +/* Mark a TValue (if needed). */ +#define gc_marktv(g, tv) \ + { lua_assert(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct)); \ + if (tviswhite(tv)) gc_mark(g, gcV(tv)); } + +/* Mark a GCobj (if needed). */ +#define gc_markobj(g, o) \ + { if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); } + +/* Mark a string object. */ +#define gc_mark_str(s) ((s)->marked &= (uint8_t)~LJ_GC_WHITES) + +/* Mark a white GCobj. */ +static void gc_mark(global_State *g, GCobj *o) +{ + int gct = o->gch.gct; + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) { + GCtab *mt = tabref(gco2ud(o)->metatable); + gray2black(o); /* Userdata are never gray. */ + if (mt) gc_markobj(g, mt); + gc_markobj(g, tabref(gco2ud(o)->env)); + } else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) { + GCupval *uv = gco2uv(o); + gc_marktv(g, uvval(uv)); + if (uv->closed) + gray2black(o); /* Closed upvalues are never gray. */ + } else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) { + lua_assert(gct == ~LJ_TFUNC || gct == ~LJ_TTAB || + gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO); + setgcrefr(o->gch.gclist, g->gc.gray); + setgcref(g->gc.gray, o); + } +} + +/* Mark GC roots. */ +static void gc_mark_gcroot(global_State *g) +{ + ptrdiff_t i; + for (i = 0; i < GCROOT_MAX; i++) + if (gcref(g->gcroot[i]) != NULL) + gc_markobj(g, gcref(g->gcroot[i])); +} + +/* Start a GC cycle and mark the root set. */ +static void gc_mark_start(global_State *g) +{ + setgcrefnull(g->gc.gray); + setgcrefnull(g->gc.grayagain); + setgcrefnull(g->gc.weak); + gc_markobj(g, mainthread(g)); + gc_markobj(g, tabref(mainthread(g)->env)); + gc_marktv(g, &g->registrytv); + gc_mark_gcroot(g); + g->gc.state = GCSpropagate; +} + +/* Mark open upvalues. */ +static void gc_mark_uv(global_State *g) +{ + GCupval *uv; + for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) { + lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); + if (isgray(obj2gco(uv))) + gc_marktv(g, uvval(uv)); + } +} + +/* Mark userdata in mmudata list. */ +static void gc_mark_mmudata(global_State *g) +{ + GCobj *root = gcref(g->gc.mmudata); + GCobj *u = root; + if (u) { + do { + u = gcnext(u); + makewhite(g, u); /* Could be from previous GC. */ + gc_mark(g, u); + } while (u != root); + } +} + +/* Separate userdata objects to be finalized to mmudata list. */ +size_t lj_gc_separateudata(global_State *g, int all) +{ + size_t m = 0; + GCRef *p = &mainthread(g)->nextgc; + GCobj *o; + while ((o = gcref(*p)) != NULL) { + if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) { + p = &o->gch.nextgc; /* Nothing to do. */ + } else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) { + markfinalized(o); /* Done, as there's no __gc metamethod. */ + p = &o->gch.nextgc; + } else { /* Otherwise move userdata to be finalized to mmudata list. */ + m += sizeudata(gco2ud(o)); + markfinalized(o); + *p = o->gch.nextgc; + if (gcref(g->gc.mmudata)) { /* Link to end of mmudata list. */ + GCobj *root = gcref(g->gc.mmudata); + setgcrefr(o->gch.nextgc, root->gch.nextgc); + setgcref(root->gch.nextgc, o); + setgcref(g->gc.mmudata, o); + } else { /* Create circular list. */ + setgcref(o->gch.nextgc, o); + setgcref(g->gc.mmudata, o); + } + } + } + return m; +} + +/* -- Propagation phase --------------------------------------------------- */ + +/* Traverse a table. */ +static int gc_traverse_tab(global_State *g, GCtab *t) +{ + int weak = 0; + cTValue *mode; + GCtab *mt = tabref(t->metatable); + if (mt) + gc_markobj(g, mt); + mode = lj_meta_fastg(g, mt, MM_mode); + if (mode && tvisstr(mode)) { /* Valid __mode field? */ + const char *modestr = strVdata(mode); + int c; + while ((c = *modestr++)) { + if (c == 'k') weak |= LJ_GC_WEAKKEY; + else if (c == 'v') weak |= LJ_GC_WEAKVAL; + else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL); + } + if (weak > 0) { /* Weak tables are cleared in the atomic phase. */ + t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); + setgcrefr(t->gclist, g->gc.weak); + setgcref(g->gc.weak, obj2gco(t)); + } + } + if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */ + return 1; + if (!(weak & LJ_GC_WEAKVAL)) { /* Mark array part. */ + MSize i, asize = t->asize; + for (i = 0; i < asize; i++) + gc_marktv(g, arrayslot(t, i)); + } + if (t->hmask > 0) { /* Mark hash part. */ + Node *node = noderef(t->node); + MSize i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (!tvisnil(&n->val)) { /* Mark non-empty slot. */ + lua_assert(!tvisnil(&n->key)); + if (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key); + if (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val); + } + } + } + return weak; +} + +/* Traverse a function. */ +static void gc_traverse_func(global_State *g, GCfunc *fn) +{ + gc_markobj(g, tabref(fn->c.env)); + if (isluafunc(fn)) { + uint32_t i; + lua_assert(fn->l.nupvalues <= funcproto(fn)->sizeuv); + gc_markobj(g, funcproto(fn)); + for (i = 0; i < fn->l.nupvalues; i++) /* Mark Lua function upvalues. */ + gc_markobj(g, &gcref(fn->l.uvptr[i])->uv); + } else { + uint32_t i; + for (i = 0; i < fn->c.nupvalues; i++) /* Mark C function upvalues. */ + gc_marktv(g, &fn->c.upvalue[i]); + } +} + +#if LJ_HASJIT +/* Mark a trace. */ +static void gc_marktrace(global_State *g, TraceNo traceno) +{ + GCobj *o = obj2gco(traceref(G2J(g), traceno)); + lua_assert(traceno != G2J(g)->cur.traceno); + if (iswhite(o)) { + white2gray(o); + setgcrefr(o->gch.gclist, g->gc.gray); + setgcref(g->gc.gray, o); + } +} + +/* Traverse a trace. */ +static void gc_traverse_trace(global_State *g, GCtrace *T) +{ + IRRef ref; + if (T->traceno == 0) return; + for (ref = T->nk; ref < REF_TRUE; ref++) { + IRIns *ir = &T->ir[ref]; + if (ir->o == IR_KGC) + gc_markobj(g, ir_kgc(ir)); + } + if (T->link) gc_marktrace(g, T->link); + if (T->nextroot) gc_marktrace(g, T->nextroot); + if (T->nextside) gc_marktrace(g, T->nextside); + gc_markobj(g, gcref(T->startpt)); +} + +/* The current trace is a GC root while not anchored in the prototype (yet). */ +#define gc_traverse_curtrace(g) gc_traverse_trace(g, &G2J(g)->cur) +#else +#define gc_traverse_curtrace(g) UNUSED(g) +#endif + +/* Traverse a prototype. */ +static void gc_traverse_proto(global_State *g, GCproto *pt) +{ + ptrdiff_t i; + gc_mark_str(proto_chunkname(pt)); + for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */ + gc_markobj(g, proto_kgc(pt, i)); +#if LJ_HASJIT + if (pt->trace) gc_marktrace(g, pt->trace); +#endif +} + +/* Traverse the frame structure of a stack. */ +static MSize gc_traverse_frames(global_State *g, lua_State *th) +{ + TValue *frame, *top = th->top-1, *bot = tvref(th->stack); + /* Note: extra vararg frame not skipped, marks function twice (harmless). */ + for (frame = th->base-1; frame > bot; frame = frame_prev(frame)) { + GCfunc *fn = frame_func(frame); + TValue *ftop = frame; + if (isluafunc(fn)) ftop += funcproto(fn)->framesize; + if (ftop > top) top = ftop; + gc_markobj(g, fn); /* Need to mark hidden function (or L). */ + } + top++; /* Correct bias of -1 (frame == base-1). */ + if (top > tvref(th->maxstack)) top = tvref(th->maxstack); + return (MSize)(top - bot); /* Return minimum needed stack size. */ +} + +/* Traverse a thread object. */ +static void gc_traverse_thread(global_State *g, lua_State *th) +{ + TValue *o, *top = th->top; + for (o = tvref(th->stack)+1; o < top; o++) + gc_marktv(g, o); + if (g->gc.state == GCSatomic) { + top = tvref(th->stack) + th->stacksize; + for (; o < top; o++) /* Clear unmarked slots. */ + setnilV(o); + } + gc_markobj(g, tabref(th->env)); + lj_state_shrinkstack(th, gc_traverse_frames(g, th)); +} + +/* Propagate one gray object. Traverse it and turn it black. */ +static size_t propagatemark(global_State *g) +{ + GCobj *o = gcref(g->gc.gray); + int gct = o->gch.gct; + lua_assert(isgray(o)); + gray2black(o); + setgcrefr(g->gc.gray, o->gch.gclist); /* Remove from gray list. */ + if (LJ_LIKELY(gct == ~LJ_TTAB)) { + GCtab *t = gco2tab(o); + if (gc_traverse_tab(g, t) > 0) + black2gray(o); /* Keep weak tables gray. */ + return sizeof(GCtab) + sizeof(TValue) * t->asize + + sizeof(Node) * (t->hmask + 1); + } else if (LJ_LIKELY(gct == ~LJ_TFUNC)) { + GCfunc *fn = gco2func(o); + gc_traverse_func(g, fn); + return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) : + sizeCfunc((MSize)fn->c.nupvalues); + } else if (LJ_LIKELY(gct == ~LJ_TPROTO)) { + GCproto *pt = gco2pt(o); + gc_traverse_proto(g, pt); + return pt->sizept; + } else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) { + lua_State *th = gco2th(o); + setgcrefr(th->gclist, g->gc.grayagain); + setgcref(g->gc.grayagain, o); + black2gray(o); /* Threads are never black. */ + gc_traverse_thread(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize; + } else { +#if LJ_HASJIT + GCtrace *T = gco2trace(o); + gc_traverse_trace(g, T); + return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) + + T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry); +#else + lua_assert(0); + return 0; +#endif + } +} + +/* Propagate all gray objects. */ +static size_t gc_propagate_gray(global_State *g) +{ + size_t m = 0; + while (gcref(g->gc.gray) != NULL) + m += propagatemark(g); + return m; +} + +/* -- Sweep phase --------------------------------------------------------- */ + +/* Try to shrink some common data structures. */ +static void gc_shrink(global_State *g, lua_State *L) +{ + if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1) + lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */ + if (g->tmpbuf.sz > LJ_MIN_SBUF*2) + lj_str_resizebuf(L, &g->tmpbuf, g->tmpbuf.sz >> 1); /* Shrink temp buf. */ +} + +/* Type of GC free functions. */ +typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o); + +/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */ +static const GCFreeFunc gc_freefunc[] = { + (GCFreeFunc)lj_str_free, + (GCFreeFunc)lj_func_freeuv, + (GCFreeFunc)lj_state_free, + (GCFreeFunc)lj_func_freeproto, + (GCFreeFunc)lj_func_free, +#if LJ_HASJIT + (GCFreeFunc)lj_trace_free, +#else + (GCFreeFunc)0, +#endif +#if LJ_HASFFI + (GCFreeFunc)lj_cdata_free, +#else + (GCFreeFunc)0, +#endif + (GCFreeFunc)lj_tab_free, + (GCFreeFunc)lj_udata_free +}; + +/* Full sweep of a GC list. */ +#define gc_fullsweep(g, p) gc_sweep(g, (p), LJ_MAX_MEM) + +/* Partial sweep of a GC list. */ +static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim) +{ + /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */ + int ow = otherwhite(g); + GCobj *o; + while ((o = gcref(*p)) != NULL && lim-- > 0) { + if (o->gch.gct == ~LJ_TTHREAD) /* Need to sweep open upvalues, too. */ + gc_fullsweep(g, &gco2th(o)->openupval); + if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) { /* Black or current white? */ + lua_assert(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED)); + makewhite(g, o); /* Value is alive, change to the current white. */ + p = &o->gch.nextgc; + } else { /* Otherwise value is dead, free it. */ + lua_assert(isdead(g, o) || ow == LJ_GC_SFIXED); + setgcrefr(*p, o->gch.nextgc); + if (o == gcref(g->gc.root)) + setgcrefr(g->gc.root, o->gch.nextgc); /* Adjust list anchor. */ + gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o); + } + } + return p; +} + +/* Check whether we can clear a key or a value slot from a table. */ +static int gc_mayclear(cTValue *o, int val) +{ + if (tvisgcv(o)) { /* Only collectable objects can be weak references. */ + if (tvisstr(o)) { /* But strings cannot be used as weak references. */ + gc_mark_str(strV(o)); /* And need to be marked. */ + return 0; + } + if (iswhite(gcV(o))) + return 1; /* Object is about to be collected. */ + if (tvisudata(o) && val && isfinalized(udataV(o))) + return 1; /* Finalized userdata is dropped only from values. */ + } + return 0; /* Cannot clear. */ +} + +/* Clear collected entries from weak tables. */ +static void gc_clearweak(GCobj *o) +{ + while (o) { + GCtab *t = gco2tab(o); + lua_assert((t->marked & LJ_GC_WEAK)); + if ((t->marked & LJ_GC_WEAKVAL)) { + MSize i, asize = t->asize; + for (i = 0; i < asize; i++) { + /* Clear array slot when value is about to be collected. */ + TValue *tv = arrayslot(t, i); + if (gc_mayclear(tv, 1)) + setnilV(tv); + } + } + if (t->hmask > 0) { + Node *node = noderef(t->node); + MSize i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + /* Clear hash slot when key or value is about to be collected. */ + if (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) || + gc_mayclear(&n->val, 1))) + setnilV(&n->val); + } + } + o = gcref(t->gclist); + } +} + +/* Call a userdata or cdata finalizer. */ +static void gc_call_finalizer(global_State *g, lua_State *L, + cTValue *mo, GCobj *o) +{ + /* Save and restore lots of state around the __gc callback. */ + uint8_t oldh = hook_save(g); + MSize oldt = g->gc.threshold; + int errcode; + TValue *top; + lj_trace_abort(g); + top = L->top; + L->top = top+2; + hook_entergc(g); /* Disable hooks and new traces during __gc. */ + g->gc.threshold = LJ_MAX_MEM; /* Prevent GC steps. */ + copyTV(L, top, mo); + setgcV(L, top+1, o, ~o->gch.gct); + errcode = lj_vm_pcall(L, top+1, 1+0, -1); /* Stack: |mo|o| -> | */ + hook_restore(g, oldh); + g->gc.threshold = oldt; /* Restore GC threshold. */ + if (errcode) + lj_err_throw(L, errcode); /* Propagate errors. */ +} + +/* Finalize one userdata or cdata object from the mmudata list. */ +static void gc_finalize(lua_State *L) +{ + global_State *g = G(L); + GCobj *o = gcnext(gcref(g->gc.mmudata)); + cTValue *mo; + lua_assert(gcref(g->jit_L) == NULL); /* Must not be called on trace. */ + /* Unchain from list of userdata to be finalized. */ + if (o == gcref(g->gc.mmudata)) + setgcrefnull(g->gc.mmudata); + else + setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc); +#if LJ_HASFFI + if (o->gch.gct == ~LJ_TCDATA) { + TValue tmp, *tv; + /* Add cdata back to the GC list and make it white. */ + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + makewhite(g, o); + o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN; + /* Resolve finalizer. */ + setcdataV(L, &tmp, gco2cd(o)); + tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp); + if (!tvisnil(tv)) { + g->gc.nocdatafin = 0; + copyTV(L, &tmp, tv); + setnilV(tv); /* Clear entry in finalizer table. */ + gc_call_finalizer(g, L, &tmp, o); + } + return; + } +#endif + /* Add userdata back to the main userdata list and make it white. */ + setgcrefr(o->gch.nextgc, mainthread(g)->nextgc); + setgcref(mainthread(g)->nextgc, o); + makewhite(g, o); + /* Resolve the __gc metamethod. */ + mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc); + if (mo) + gc_call_finalizer(g, L, mo, o); +} + +/* Finalize all userdata objects from mmudata list. */ +void lj_gc_finalize_udata(lua_State *L) +{ + while (gcref(G(L)->gc.mmudata) != NULL) + gc_finalize(L); +} + +#if LJ_HASFFI +/* Finalize all cdata objects from finalizer table. */ +void lj_gc_finalize_cdata(lua_State *L) +{ + global_State *g = G(L); + CTState *cts = ctype_ctsG(g); + if (cts) { + GCtab *t = cts->finalizer; + Node *node = noderef(t->node); + ptrdiff_t i; + setgcrefnull(t->metatable); /* Mark finalizer table as disabled. */ + for (i = (ptrdiff_t)t->hmask; i >= 0; i--) + if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) { + GCobj *o = gcV(&node[i].key); + TValue tmp; + makewhite(g, o); + o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN; + copyTV(L, &tmp, &node[i].val); + setnilV(&node[i].val); + gc_call_finalizer(g, L, &tmp, o); + } + } +} +#endif + +/* Free all remaining GC objects. */ +void lj_gc_freeall(global_State *g) +{ + MSize i, strmask; + /* Free everything, except super-fixed objects (the main thread). */ + g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED; + gc_fullsweep(g, &g->gc.root); + strmask = g->strmask; + for (i = 0; i <= strmask; i++) /* Free all string hash chains. */ + gc_fullsweep(g, &g->strhash[i]); +} + +/* -- Collector ----------------------------------------------------------- */ + +/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */ +static void atomic(global_State *g, lua_State *L) +{ + size_t udsize; + + gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */ + gc_propagate_gray(g); /* Propagate any left-overs. */ + + setgcrefr(g->gc.gray, g->gc.weak); /* Empty the list of weak tables. */ + setgcrefnull(g->gc.weak); + lua_assert(!iswhite(obj2gco(mainthread(g)))); + gc_markobj(g, L); /* Mark running thread. */ + gc_traverse_curtrace(g); /* Traverse current trace. */ + gc_mark_gcroot(g); /* Mark GC roots (again). */ + gc_propagate_gray(g); /* Propagate all of the above. */ + + setgcrefr(g->gc.gray, g->gc.grayagain); /* Empty the 2nd chance list. */ + setgcrefnull(g->gc.grayagain); + gc_propagate_gray(g); /* Propagate it. */ + + udsize = lj_gc_separateudata(g, 0); /* Separate userdata to be finalized. */ + gc_mark_mmudata(g); /* Mark them. */ + udsize += gc_propagate_gray(g); /* And propagate the marks. */ + + /* All marking done, clear weak tables. */ + gc_clearweak(gcref(g->gc.weak)); + + /* Prepare for sweep phase. */ + g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ + g->strempty.marked = g->gc.currentwhite; + setmref(g->gc.sweep, &g->gc.root); + g->gc.estimate = g->gc.total - (MSize)udsize; /* Initial estimate. */ +} + +/* GC state machine. Returns a cost estimate for each step performed. */ +static size_t gc_onestep(lua_State *L) +{ + global_State *g = G(L); + switch (g->gc.state) { + case GCSpause: + gc_mark_start(g); /* Start a new GC cycle by marking all GC roots. */ + return 0; + case GCSpropagate: + if (gcref(g->gc.gray) != NULL) + return propagatemark(g); /* Propagate one gray object. */ + g->gc.state = GCSatomic; /* End of mark phase. */ + return 0; + case GCSatomic: + if (gcref(g->jit_L)) /* Don't run atomic phase on trace. */ + return LJ_MAX_MEM; + atomic(g, L); + g->gc.state = GCSsweepstring; /* Start of sweep phase. */ + g->gc.sweepstr = 0; + return 0; + case GCSsweepstring: { + MSize old = g->gc.total; + gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */ + if (g->gc.sweepstr > g->strmask) + g->gc.state = GCSsweep; /* All string hash chains sweeped. */ + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; + return GCSWEEPCOST; + } + case GCSsweep: { + MSize old = g->gc.total; + setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); + if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { + gc_shrink(g, L); + if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ + g->gc.state = GCSfinalize; +#if LJ_HASFFI + g->gc.nocdatafin = 1; +#endif + } else { /* Otherwise skip this phase to help the JIT. */ + g->gc.state = GCSpause; /* End of GC cycle. */ + g->gc.debt = 0; + } + } + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: + if (gcref(g->gc.mmudata) != NULL) { + if (gcref(g->jit_L)) /* Don't call finalizers on trace. */ + return LJ_MAX_MEM; + gc_finalize(L); /* Finalize one userdata object. */ + if (g->gc.estimate > GCFINALIZECOST) + g->gc.estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } +#if LJ_HASFFI + if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer); +#endif + g->gc.state = GCSpause; /* End of GC cycle. */ + g->gc.debt = 0; + return 0; + default: + lua_assert(0); + return 0; + } +} + +/* Perform a limited amount of incremental GC steps. */ +int LJ_FASTCALL lj_gc_step(lua_State *L) +{ + global_State *g = G(L); + MSize lim; + int32_t ostate = g->vmstate; + setvmstate(g, GC); + lim = (GCSTEPSIZE/100) * g->gc.stepmul; + if (lim == 0) + lim = LJ_MAX_MEM; + if (g->gc.total > g->gc.threshold) + g->gc.debt += g->gc.total - g->gc.threshold; + do { + lim -= (MSize)gc_onestep(L); + if (g->gc.state == GCSpause) { + g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; + g->vmstate = ostate; + return 1; /* Finished a GC cycle. */ + } + } while ((int32_t)lim > 0); + if (g->gc.debt < GCSTEPSIZE) { + g->gc.threshold = g->gc.total + GCSTEPSIZE; + g->vmstate = ostate; + return -1; + } else { + g->gc.debt -= GCSTEPSIZE; + g->gc.threshold = g->gc.total; + g->vmstate = ostate; + return 0; + } +} + +/* Ditto, but fix the stack top first. */ +void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L) +{ + if (curr_funcisL(L)) L->top = curr_topL(L); + lj_gc_step(L); +} + +#if LJ_HASJIT +/* Perform multiple GC steps. Called from JIT-compiled code. */ +int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps) +{ + lua_State *L = gco2th(gcref(g->jit_L)); + L->base = mref(G(L)->jit_base, TValue); + L->top = curr_topL(L); + while (steps-- > 0 && lj_gc_step(L) == 0) + ; + /* Return 1 to force a trace exit. */ + return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize); +} +#endif + +/* Perform a full GC cycle. */ +void lj_gc_fullgc(lua_State *L) +{ + global_State *g = G(L); + int32_t ostate = g->vmstate; + setvmstate(g, GC); + if (g->gc.state <= GCSatomic) { /* Caught somewhere in the middle. */ + setmref(g->gc.sweep, &g->gc.root); /* Sweep everything (preserving it). */ + setgcrefnull(g->gc.gray); /* Reset lists from partial propagation. */ + setgcrefnull(g->gc.grayagain); + setgcrefnull(g->gc.weak); + g->gc.state = GCSsweepstring; /* Fast forward to the sweep phase. */ + g->gc.sweepstr = 0; + } + while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep) + gc_onestep(L); /* Finish sweep. */ + lua_assert(g->gc.state == GCSfinalize || g->gc.state == GCSpause); + /* Now perform a full GC. */ + g->gc.state = GCSpause; + do { gc_onestep(L); } while (g->gc.state != GCSpause); + g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; + g->vmstate = ostate; +} + +/* -- Write barriers ------------------------------------------------------ */ + +/* Move the GC propagation frontier forward. */ +void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v) +{ + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + lua_assert(o->gch.gct != ~LJ_TTAB); + /* Preserve invariant during propagation. Otherwise it doesn't matter. */ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_mark(g, v); /* Move frontier forward. */ + else + makewhite(g, o); /* Make it white to avoid the following barrier. */ +} + +/* Specialized barrier for closed upvalue. Pass &uv->tv. */ +void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv) +{ +#define TV2MARKED(x) \ + (*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked))) + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_mark(g, gcV(tv)); + else + TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g); +#undef TV2MARKED +} + +/* Close upvalue. Also needs a write barrier. */ +void lj_gc_closeuv(global_State *g, GCupval *uv) +{ + GCobj *o = obj2gco(uv); + /* Copy stack slot to upvalue itself and point to the copy. */ + copyTV(mainthread(g), &uv->tv, uvval(uv)); + setmref(uv->v, &uv->tv); + uv->closed = 1; + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) { + gray2black(o); /* Make it black and preserve invariant. */ + if (tviswhite(&uv->tv)) + lj_gc_barrierf(g, o, gcV(&uv->tv)); + } else { + makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */ + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + } + } +} + +#if LJ_HASJIT +/* Mark a trace if it's saved during the propagation phase. */ +void lj_gc_barriertrace(global_State *g, uint32_t traceno) +{ + if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) + gc_marktrace(g, traceno); +} +#endif + +/* -- Allocator ----------------------------------------------------------- */ + +/* Call pluggable memory allocator to allocate or resize a fragment. */ +void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) +{ + global_State *g = G(L); + lua_assert((osz == 0) == (p == NULL)); + p = g->allocf(g->allocd, p, osz, nsz); + if (p == NULL && nsz > 0) + lj_err_mem(L); + lua_assert((nsz == 0) == (p == NULL)); + lua_assert(checkptr32(p)); + g->gc.total = (g->gc.total - osz) + nsz; + return p; +} + +/* Allocate new GC object and link it to the root set. */ +void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size) +{ + global_State *g = G(L); + GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); + if (o == NULL) + lj_err_mem(L); + lua_assert(checkptr32(o)); + g->gc.total += size; + setgcrefr(o->gch.nextgc, g->gc.root); + setgcref(g->gc.root, o); + newwhite(g, o); + return o; +} + +/* Resize growable vector. */ +void *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz) +{ + MSize sz = (*szp) << 1; + if (sz < LJ_MIN_VECSZ) + sz = LJ_MIN_VECSZ; + if (sz > lim) + sz = lim; + p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz); + *szp = sz; + return p; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.h new file mode 100644 index 0000000..c85d075 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gc.h @@ -0,0 +1,134 @@ +/* +** Garbage collector. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_GC_H +#define _LJ_GC_H + +#include "lj_obj.h" + +/* Garbage collector states. Order matters. */ +enum { + GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize +}; + +/* Bitmasks for marked field of GCobj. */ +#define LJ_GC_WHITE0 0x01 +#define LJ_GC_WHITE1 0x02 +#define LJ_GC_BLACK 0x04 +#define LJ_GC_FINALIZED 0x08 +#define LJ_GC_WEAKKEY 0x08 +#define LJ_GC_WEAKVAL 0x10 +#define LJ_GC_CDATA_FIN 0x10 +#define LJ_GC_FIXED 0x20 +#define LJ_GC_SFIXED 0x40 + +#define LJ_GC_WHITES (LJ_GC_WHITE0 | LJ_GC_WHITE1) +#define LJ_GC_COLORS (LJ_GC_WHITES | LJ_GC_BLACK) +#define LJ_GC_WEAK (LJ_GC_WEAKKEY | LJ_GC_WEAKVAL) + +/* Macros to test and set GCobj colors. */ +#define iswhite(x) ((x)->gch.marked & LJ_GC_WHITES) +#define isblack(x) ((x)->gch.marked & LJ_GC_BLACK) +#define isgray(x) (!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES))) +#define tviswhite(x) (tvisgcv(x) && iswhite(gcV(x))) +#define otherwhite(g) (g->gc.currentwhite ^ LJ_GC_WHITES) +#define isdead(g, v) ((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES) + +#define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES) +#define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g)) +#define makewhite(g, x) \ + ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g)) +#define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES) +#define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK) +#define fixstring(s) ((s)->marked |= LJ_GC_FIXED) +#define markfinalized(x) ((x)->gch.marked |= LJ_GC_FINALIZED) + +/* Collector. */ +LJ_FUNC size_t lj_gc_separateudata(global_State *g, int all); +LJ_FUNC void lj_gc_finalize_udata(lua_State *L); +#if LJ_HASFFI +LJ_FUNC void lj_gc_finalize_cdata(lua_State *L); +#else +#define lj_gc_finalize_cdata(L) UNUSED(L) +#endif +LJ_FUNC void lj_gc_freeall(global_State *g); +LJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L); +LJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L); +#if LJ_HASJIT +LJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps); +#endif +LJ_FUNC void lj_gc_fullgc(lua_State *L); + +/* GC check: drive collector forward if the GC threshold has been reached. */ +#define lj_gc_check(L) \ + { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \ + lj_gc_step(L); } +#define lj_gc_check_fixtop(L) \ + { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \ + lj_gc_step_fixtop(L); } + +/* Write barriers. */ +LJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v); +LJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv); +LJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv); +#if LJ_HASJIT +LJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno); +#endif + +/* Move the GC propagation frontier back for tables (make it gray again). */ +static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t) +{ + GCobj *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); + black2gray(o); + setgcrefr(t->gclist, g->gc.grayagain); + setgcref(g->gc.grayagain, o); +} + +/* Barrier for stores to table objects. TValue and GCobj variant. */ +#define lj_gc_anybarriert(L, t) \ + { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); } +#define lj_gc_barriert(L, t, tv) \ + { if (tviswhite(tv) && isblack(obj2gco(t))) \ + lj_gc_barrierback(G(L), (t)); } +#define lj_gc_objbarriert(L, t, o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \ + lj_gc_barrierback(G(L), (t)); } + +/* Barrier for stores to any other object. TValue and GCobj variant. */ +#define lj_gc_barrier(L, p, tv) \ + { if (tviswhite(tv) && isblack(obj2gco(p))) \ + lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); } +#define lj_gc_objbarrier(L, p, o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); } + +/* Allocator. */ +LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz); +LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size); +LJ_FUNC void *lj_mem_grow(lua_State *L, void *p, + MSize *szp, MSize lim, MSize esz); + +#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s)) + +static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize) +{ + g->gc.total -= (MSize)osize; + g->allocf(g->allocd, p, osize, 0); +} + +#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t)))) +#define lj_mem_reallocvec(L, p, on, n, t) \ + ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (MSize)((n)*sizeof(t)))) +#define lj_mem_growvec(L, p, n, m, t) \ + ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t))) +#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t)) + +#define lj_mem_newobj(L, t) ((t *)lj_mem_newgco(L, sizeof(t))) +#define lj_mem_newt(L, s, t) ((t *)lj_mem_new(L, (s))) +#define lj_mem_freet(g, p) lj_mem_free(g, (p), sizeof(*(p))) + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.c new file mode 100644 index 0000000..5e7fca1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.c @@ -0,0 +1,793 @@ +/* +** Client for the GDB JIT API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_gdbjit_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_frame.h" +#include "lj_jit.h" +#include "lj_dispatch.h" + +/* This is not compiled in by default. +** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything. +*/ +#ifdef LUAJIT_USE_GDBJIT + +/* The GDB JIT API allows JIT compilers to pass debug information about +** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher +** to see it in action. +** +** This is a passive API, so it works even when not running under GDB +** or when attaching to an already running process. Alas, this implies +** enabling it always has a non-negligible overhead -- do not use in +** release mode! +** +** The LuaJIT GDB JIT client is rather minimal at the moment. It gives +** each trace a symbol name and adds a source location and frame unwind +** information. Obviously LuaJIT itself and any embedding C application +** should be compiled with debug symbols, too (see the Makefile). +** +** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace +** numbers from -jv or -jdump. Use "break TRACE_1" or "tbreak TRACE_1" etc. +** to set breakpoints on specific traces (even ahead of their creation). +** +** The source location for each trace allows listing the corresponding +** source lines with the GDB command "list" (but only if the Lua source +** has been loaded from a file). Currently this is always set to the +** location where the trace has been started. +** +** Frame unwind information can be inspected with the GDB command +** "info frame". This also allows proper backtraces across JIT-compiled +** code with the GDB command "bt". +** +** You probably want to add the following settings to a .gdbinit file +** (or add them to ~/.gdbinit): +** set disassembly-flavor intel +** set breakpoint pending on +** +** Here's a sample GDB session: +** ------------------------------------------------------------------------ + +$ cat >x.lua +for outer=1,100 do + for inner=1,100 do end +end +^D + +$ luajit -jv x.lua +[TRACE 1 x.lua:2] +[TRACE 2 (1/3) x.lua:1 -> 1] + +$ gdb --quiet --args luajit x.lua +(gdb) tbreak TRACE_1 +Function "TRACE_1" not defined. +Temporary breakpoint 1 (TRACE_1) pending. +(gdb) run +Starting program: luajit x.lua + +Temporary breakpoint 1, TRACE_1 () at x.lua:2 +2 for inner=1,100 do end +(gdb) list +1 for outer=1,100 do +2 for inner=1,100 do end +3 end +(gdb) bt +#0 TRACE_1 () at x.lua:2 +#1 0x08053690 in lua_pcall [...] +[...] +#7 0x0806ff90 in main [...] +(gdb) disass TRACE_1 +Dump of assembler code for function TRACE_1: +0xf7fd9fba : mov DWORD PTR ds:0xf7e0e2a0,0x1 +0xf7fd9fc4 : movsd xmm7,QWORD PTR [edx+0x20] +[...] +0xf7fd9ff8 : jmp 0xf7fd2014 +End of assembler dump. +(gdb) tbreak TRACE_2 +Function "TRACE_2" not defined. +Temporary breakpoint 2 (TRACE_2) pending. +(gdb) cont +Continuing. + +Temporary breakpoint 2, TRACE_2 () at x.lua:1 +1 for outer=1,100 do +(gdb) info frame +Stack level 0, frame at 0xffffd7c0: + eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690 + called by frame at 0xffffd7e0 + source language unknown. + Arglist at 0xffffd78c, args: + Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0 + Saved registers: + ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4, + eip at 0xffffd7bc +(gdb) + +** ------------------------------------------------------------------------ +*/ + +/* -- GDB JIT API --------------------------------------------------------- */ + +/* GDB JIT actions. */ +enum { + GDBJIT_NOACTION = 0, + GDBJIT_REGISTER, + GDBJIT_UNREGISTER +}; + +/* GDB JIT entry. */ +typedef struct GDBJITentry { + struct GDBJITentry *next_entry; + struct GDBJITentry *prev_entry; + const char *symfile_addr; + uint64_t symfile_size; +} GDBJITentry; + +/* GDB JIT descriptor. */ +typedef struct GDBJITdesc { + uint32_t version; + uint32_t action_flag; + GDBJITentry *relevant_entry; + GDBJITentry *first_entry; +} GDBJITdesc; + +GDBJITdesc __jit_debug_descriptor = { + 1, GDBJIT_NOACTION, NULL, NULL +}; + +/* GDB sets a breakpoint at this function. */ +void LJ_NOINLINE __jit_debug_register_code() +{ + __asm__ __volatile__(""); +}; + +/* -- In-memory ELF object definitions ------------------------------------ */ + +/* ELF definitions. */ +typedef struct ELFheader { + uint8_t emagic[4]; + uint8_t eclass; + uint8_t eendian; + uint8_t eversion; + uint8_t eosabi; + uint8_t eabiversion; + uint8_t epad[7]; + uint16_t type; + uint16_t machine; + uint32_t version; + uintptr_t entry; + uintptr_t phofs; + uintptr_t shofs; + uint32_t flags; + uint16_t ehsize; + uint16_t phentsize; + uint16_t phnum; + uint16_t shentsize; + uint16_t shnum; + uint16_t shstridx; +} ELFheader; + +typedef struct ELFsectheader { + uint32_t name; + uint32_t type; + uintptr_t flags; + uintptr_t addr; + uintptr_t ofs; + uintptr_t size; + uint32_t link; + uint32_t info; + uintptr_t align; + uintptr_t entsize; +} ELFsectheader; + +#define ELFSECT_IDX_ABS 0xfff1 + +enum { + ELFSECT_TYPE_PROGBITS = 1, + ELFSECT_TYPE_SYMTAB = 2, + ELFSECT_TYPE_STRTAB = 3, + ELFSECT_TYPE_NOBITS = 8 +}; + +#define ELFSECT_FLAGS_WRITE 1 +#define ELFSECT_FLAGS_ALLOC 2 +#define ELFSECT_FLAGS_EXEC 4 + +typedef struct ELFsymbol { +#if LJ_64 + uint32_t name; + uint8_t info; + uint8_t other; + uint16_t sectidx; + uintptr_t value; + uint64_t size; +#else + uint32_t name; + uintptr_t value; + uint32_t size; + uint8_t info; + uint8_t other; + uint16_t sectidx; +#endif +} ELFsymbol; + +enum { + ELFSYM_TYPE_FUNC = 2, + ELFSYM_TYPE_FILE = 4, + ELFSYM_BIND_LOCAL = 0 << 4, + ELFSYM_BIND_GLOBAL = 1 << 4, +}; + +/* DWARF definitions. */ +#define DW_CIE_VERSION 1 + +enum { + DW_CFA_nop = 0x0, + DW_CFA_offset_extended = 0x5, + DW_CFA_def_cfa = 0xc, + DW_CFA_def_cfa_offset = 0xe, + DW_CFA_offset_extended_sf = 0x11, + DW_CFA_advance_loc = 0x40, + DW_CFA_offset = 0x80 +}; + +enum { + DW_EH_PE_udata4 = 3, + DW_EH_PE_textrel = 0x20 +}; + +enum { + DW_TAG_compile_unit = 0x11 +}; + +enum { + DW_children_no = 0, + DW_children_yes = 1 +}; + +enum { + DW_AT_name = 0x03, + DW_AT_stmt_list = 0x10, + DW_AT_low_pc = 0x11, + DW_AT_high_pc = 0x12 +}; + +enum { + DW_FORM_addr = 0x01, + DW_FORM_data4 = 0x06, + DW_FORM_string = 0x08 +}; + +enum { + DW_LNS_extended_op = 0, + DW_LNS_copy = 1, + DW_LNS_advance_pc = 2, + DW_LNS_advance_line = 3 +}; + +enum { + DW_LNE_end_sequence = 1, + DW_LNE_set_address = 2 +}; + +enum { +#if LJ_TARGET_X86 + DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX, + DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI, + DW_REG_RA, +#elif LJ_TARGET_X64 + /* Yes, the order is strange, but correct. */ + DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX, + DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP, + DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11, + DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15, + DW_REG_RA, +#elif LJ_TARGET_ARM + DW_REG_SP = 13, + DW_REG_RA = 14, +#elif LJ_TARGET_PPC + DW_REG_SP = 1, + DW_REG_RA = 65, + DW_REG_CR = 70, +#elif LJ_TARGET_MIPS + DW_REG_SP = 29, + DW_REG_RA = 31, +#else +#error "Unsupported target architecture" +#endif +}; + +/* Minimal list of sections for the in-memory ELF object. */ +enum { + GDBJIT_SECT_NULL, + GDBJIT_SECT_text, + GDBJIT_SECT_eh_frame, + GDBJIT_SECT_shstrtab, + GDBJIT_SECT_strtab, + GDBJIT_SECT_symtab, + GDBJIT_SECT_debug_info, + GDBJIT_SECT_debug_abbrev, + GDBJIT_SECT_debug_line, + GDBJIT_SECT__MAX +}; + +enum { + GDBJIT_SYM_UNDEF, + GDBJIT_SYM_FILE, + GDBJIT_SYM_FUNC, + GDBJIT_SYM__MAX +}; + +/* In-memory ELF object. */ +typedef struct GDBJITobj { + ELFheader hdr; /* ELF header. */ + ELFsectheader sect[GDBJIT_SECT__MAX]; /* ELF sections. */ + ELFsymbol sym[GDBJIT_SYM__MAX]; /* ELF symbol table. */ + uint8_t space[4096]; /* Space for various section data. */ +} GDBJITobj; + +/* Combined structure for GDB JIT entry and ELF object. */ +typedef struct GDBJITentryobj { + GDBJITentry entry; + size_t sz; + GDBJITobj obj; +} GDBJITentryobj; + +/* Template for in-memory ELF header. */ +static const ELFheader elfhdr_template = { + .emagic = { 0x7f, 'E', 'L', 'F' }, + .eclass = LJ_64 ? 2 : 1, + .eendian = LJ_ENDIAN_SELECT(1, 2), + .eversion = 1, +#if LJ_TARGET_LINUX + .eosabi = 0, /* Nope, it's not 3. */ +#elif defined(__FreeBSD__) + .eosabi = 9, +#elif defined(__NetBSD__) + .eosabi = 2, +#elif defined(__OpenBSD__) + .eosabi = 12, +#elif (defined(__sun__) && defined(__svr4__)) + .eosabi = 6, +#else + .eosabi = 0, +#endif + .eabiversion = 0, + .epad = { 0, 0, 0, 0, 0, 0, 0 }, + .type = 1, +#if LJ_TARGET_X86 + .machine = 3, +#elif LJ_TARGET_X64 + .machine = 62, +#elif LJ_TARGET_ARM + .machine = 40, +#elif LJ_TARGET_PPC + .machine = 20, +#elif LJ_TARGET_MIPS + .machine = 8, +#else +#error "Unsupported target architecture" +#endif + .version = 1, + .entry = 0, + .phofs = 0, + .shofs = offsetof(GDBJITobj, sect), + .flags = 0, + .ehsize = sizeof(ELFheader), + .phentsize = 0, + .phnum = 0, + .shentsize = sizeof(ELFsectheader), + .shnum = GDBJIT_SECT__MAX, + .shstridx = GDBJIT_SECT_shstrtab +}; + +/* -- In-memory ELF object generation ------------------------------------- */ + +/* Context for generating the ELF object for the GDB JIT API. */ +typedef struct GDBJITctx { + uint8_t *p; /* Pointer to next address in obj.space. */ + uint8_t *startp; /* Pointer to start address in obj.space. */ + GCtrace *T; /* Generate symbols for this trace. */ + uintptr_t mcaddr; /* Machine code address. */ + MSize szmcode; /* Size of machine code. */ + MSize spadjp; /* Stack adjustment for parent trace or interpreter. */ + MSize spadj; /* Stack adjustment for trace itself. */ + BCLine lineno; /* Starting line number. */ + const char *filename; /* Starting file name. */ + size_t objsize; /* Final size of ELF object. */ + GDBJITobj obj; /* In-memory ELF object. */ +} GDBJITctx; + +/* Add a zero-terminated string. */ +static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str) +{ + uint8_t *p = ctx->p; + uint32_t ofs = (uint32_t)(p - ctx->startp); + do { + *p++ = (uint8_t)*str; + } while (*str++); + ctx->p = p; + return ofs; +} + +/* Append a decimal number. */ +static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n) +{ + if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); } + *ctx->p++ = '0' + n; +} + +/* Add a ULEB128 value. */ +static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v) +{ + uint8_t *p = ctx->p; + for (; v >= 0x80; v >>= 7) + *p++ = (uint8_t)((v & 0x7f) | 0x80); + *p++ = (uint8_t)v; + ctx->p = p; +} + +/* Add a SLEB128 value. */ +static void gdbjit_sleb128(GDBJITctx *ctx, int32_t v) +{ + uint8_t *p = ctx->p; + for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7) + *p++ = (uint8_t)((v & 0x7f) | 0x80); + *p++ = (uint8_t)(v & 0x7f); + ctx->p = p; +} + +/* Shortcuts to generate DWARF structures. */ +#define DB(x) (*p++ = (x)) +#define DI8(x) (*(int8_t *)p = (x), p++) +#define DU16(x) (*(uint16_t *)p = (x), p += 2) +#define DU32(x) (*(uint32_t *)p = (x), p += 4) +#define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t)) +#define DUV(x) (ctx->p = p, gdbjit_uleb128(ctx, (x)), p = ctx->p) +#define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p) +#define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p) +#define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop +#define DSECT(name, stmt) \ + { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \ + *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \ + +/* Initialize ELF section headers. */ +static void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx) +{ + ELFsectheader *sect; + + *ctx->p++ = '\0'; /* Empty string at start of string table. */ + +#define SECTDEF(id, tp, al) \ + sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \ + sect->name = gdbjit_strz(ctx, "." #id); \ + sect->type = ELFSECT_TYPE_##tp; \ + sect->align = (al) + + SECTDEF(text, NOBITS, 16); + sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC; + sect->addr = ctx->mcaddr; + sect->ofs = 0; + sect->size = ctx->szmcode; + + SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t)); + sect->flags = ELFSECT_FLAGS_ALLOC; + + SECTDEF(shstrtab, STRTAB, 1); + SECTDEF(strtab, STRTAB, 1); + + SECTDEF(symtab, SYMTAB, sizeof(uintptr_t)); + sect->ofs = offsetof(GDBJITobj, sym); + sect->size = sizeof(ctx->obj.sym); + sect->link = GDBJIT_SECT_strtab; + sect->entsize = sizeof(ELFsymbol); + sect->info = GDBJIT_SYM_FUNC; + + SECTDEF(debug_info, PROGBITS, 1); + SECTDEF(debug_abbrev, PROGBITS, 1); + SECTDEF(debug_line, PROGBITS, 1); + +#undef SECTDEF +} + +/* Initialize symbol table. */ +static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx) +{ + ELFsymbol *sym; + + *ctx->p++ = '\0'; /* Empty string at start of string table. */ + + sym = &ctx->obj.sym[GDBJIT_SYM_FILE]; + sym->name = gdbjit_strz(ctx, "JIT mcode"); + sym->sectidx = ELFSECT_IDX_ABS; + sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL; + + sym = &ctx->obj.sym[GDBJIT_SYM_FUNC]; + sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--; + gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0'; + sym->sectidx = GDBJIT_SECT_text; + sym->value = 0; + sym->size = ctx->szmcode; + sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL; +} + +/* Initialize .eh_frame section. */ +static void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + uint8_t *framep = p; + + /* Emit DWARF EH CIE. */ + DSECT(CIE, + DU32(0); /* Offset to CIE itself. */ + DB(DW_CIE_VERSION); + DSTR("zR"); /* Augmentation. */ + DUV(1); /* Code alignment factor. */ + DSV(-(int32_t)sizeof(uintptr_t)); /* Data alignment factor. */ + DB(DW_REG_RA); /* Return address register. */ + DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4); /* Augmentation data. */ + DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t)); +#if LJ_TARGET_PPC + DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1); +#else + DB(DW_CFA_offset|DW_REG_RA); DUV(1); +#endif + DALIGNNOP(sizeof(uintptr_t)); + ) + + /* Emit DWARF EH FDE. */ + DSECT(FDE, + DU32((uint32_t)(p-framep)); /* Offset to CIE. */ + DU32(0); /* Machine code offset relative to .text. */ + DU32(ctx->szmcode); /* Machine code length. */ + DB(0); /* Augmentation data. */ + /* Registers saved in CFRAME. */ +#if LJ_TARGET_X86 + DB(DW_CFA_offset|DW_REG_BP); DUV(2); + DB(DW_CFA_offset|DW_REG_DI); DUV(3); + DB(DW_CFA_offset|DW_REG_SI); DUV(4); + DB(DW_CFA_offset|DW_REG_BX); DUV(5); +#elif LJ_TARGET_X64 + DB(DW_CFA_offset|DW_REG_BP); DUV(2); + DB(DW_CFA_offset|DW_REG_BX); DUV(3); + DB(DW_CFA_offset|DW_REG_15); DUV(4); + DB(DW_CFA_offset|DW_REG_14); DUV(5); + /* Extra registers saved for JIT-compiled code. */ + DB(DW_CFA_offset|DW_REG_13); DUV(9); + DB(DW_CFA_offset|DW_REG_12); DUV(10); +#elif LJ_TARGET_ARM + { + int i; + for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); } + } +#elif LJ_TARGET_PPC + { + int i; + DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55); + for (i = 14; i <= 31; i++) { + DB(DW_CFA_offset|i); DUV(37+(31-i)); + DB(DW_CFA_offset|32|i); DUV(2+2*(31-i)); + } + } +#elif LJ_TARGET_MIPS + { + int i; + DB(DW_CFA_offset|30); DUV(2); + for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); } + for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); } + } +#else +#error "Unsupported target architecture" +#endif + if (ctx->spadjp != ctx->spadj) { /* Parent/interpreter stack frame size. */ + DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp); + DB(DW_CFA_advance_loc|1); /* Only an approximation. */ + } + DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj); /* Trace stack frame size. */ + DALIGNNOP(sizeof(uintptr_t)); + ) + + ctx->p = p; +} + +/* Initialize .debug_info section. */ +static void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + DSECT(info, + DU16(2); /* DWARF version. */ + DU32(0); /* Abbrev offset. */ + DB(sizeof(uintptr_t)); /* Pointer size. */ + + DUV(1); /* Abbrev #1: DW_TAG_compile_unit. */ + DSTR(ctx->filename); /* DW_AT_name. */ + DADDR(ctx->mcaddr); /* DW_AT_low_pc. */ + DADDR(ctx->mcaddr + ctx->szmcode); /* DW_AT_high_pc. */ + DU32(0); /* DW_AT_stmt_list. */ + ) + + ctx->p = p; +} + +/* Initialize .debug_abbrev section. */ +static void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + /* Abbrev #1: DW_TAG_compile_unit. */ + DUV(1); DUV(DW_TAG_compile_unit); + DB(DW_children_no); + DUV(DW_AT_name); DUV(DW_FORM_string); + DUV(DW_AT_low_pc); DUV(DW_FORM_addr); + DUV(DW_AT_high_pc); DUV(DW_FORM_addr); + DUV(DW_AT_stmt_list); DUV(DW_FORM_data4); + DB(0); DB(0); + + ctx->p = p; +} + +#define DLNE(op, s) (DB(DW_LNS_extended_op), DUV(1+(s)), DB((op))) + +/* Initialize .debug_line section. */ +static void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx) +{ + uint8_t *p = ctx->p; + + DSECT(line, + DU16(2); /* DWARF version. */ + DSECT(header, + DB(1); /* Minimum instruction length. */ + DB(1); /* is_stmt. */ + DI8(0); /* Line base for special opcodes. */ + DB(2); /* Line range for special opcodes. */ + DB(3+1); /* Opcode base at DW_LNS_advance_line+1. */ + DB(0); DB(1); DB(1); /* Standard opcode lengths. */ + /* Directory table. */ + DB(0); + /* File name table. */ + DSTR(ctx->filename); DUV(0); DUV(0); DUV(0); + DB(0); + ) + + DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr); + if (ctx->lineno) { + DB(DW_LNS_advance_line); DSV(ctx->lineno-1); + } + DB(DW_LNS_copy); + DB(DW_LNS_advance_pc); DUV(ctx->szmcode); + DLNE(DW_LNE_end_sequence, 0); + ) + + ctx->p = p; +} + +#undef DLNE + +/* Undef shortcuts. */ +#undef DB +#undef DI8 +#undef DU16 +#undef DU32 +#undef DADDR +#undef DUV +#undef DSV +#undef DSTR +#undef DALIGNNOP +#undef DSECT + +/* Type of a section initializer callback. */ +typedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx); + +/* Call section initializer and set the section offset and size. */ +static void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf) +{ + ctx->startp = ctx->p; + ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj); + initf(ctx); + ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp); +} + +#define SECTALIGN(p, a) \ + ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1))) + +/* Build in-memory ELF object. */ +static void gdbjit_buildobj(GDBJITctx *ctx) +{ + GDBJITobj *obj = &ctx->obj; + /* Fill in ELF header and clear structures. */ + memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader)); + memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX); + memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX); + /* Initialize sections. */ + ctx->p = obj->space; + gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr); + gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev); + gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline); + SECTALIGN(ctx->p, sizeof(uintptr_t)); + gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe); + ctx->objsize = (size_t)((char *)ctx->p - (char *)obj); + lua_assert(ctx->objsize < sizeof(GDBJITobj)); +} + +#undef SECTALIGN + +/* -- Interface to GDB JIT API -------------------------------------------- */ + +/* Add new entry to GDB JIT symbol chain. */ +static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) +{ + /* Allocate memory for GDB JIT entry and ELF object. */ + MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize); + GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj); + memcpy(&eo->obj, &ctx->obj, ctx->objsize); /* Copy ELF object. */ + eo->sz = sz; + ctx->T->gdbjit_entry = (void *)eo; + /* Link new entry to chain and register it. */ + eo->entry.prev_entry = NULL; + eo->entry.next_entry = __jit_debug_descriptor.first_entry; + if (eo->entry.next_entry) + eo->entry.next_entry->prev_entry = &eo->entry; + eo->entry.symfile_addr = (const char *)&eo->obj; + eo->entry.symfile_size = ctx->objsize; + __jit_debug_descriptor.first_entry = &eo->entry; + __jit_debug_descriptor.relevant_entry = &eo->entry; + __jit_debug_descriptor.action_flag = GDBJIT_REGISTER; + __jit_debug_register_code(); +} + +/* Add debug info for newly compiled trace and notify GDB. */ +void lj_gdbjit_addtrace(jit_State *J, GCtrace *T) +{ + GDBJITctx ctx; + GCproto *pt = &gcref(T->startpt)->pt; + TraceNo parent = T->ir[REF_BASE].op1; + const BCIns *startpc = mref(T->startpc, const BCIns); + ctx.T = T; + ctx.mcaddr = (uintptr_t)T->mcode; + ctx.szmcode = T->szmcode; + ctx.spadjp = CFRAME_SIZE_JIT + + (MSize)(parent ? traceref(J, parent)->spadjust : 0); + ctx.spadj = CFRAME_SIZE_JIT + T->spadjust; + lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc); + ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc)); + ctx.filename = proto_chunknamestr(pt); + if (*ctx.filename == '@' || *ctx.filename == '=') + ctx.filename++; + else + ctx.filename = "(string)"; + gdbjit_buildobj(&ctx); + gdbjit_newentry(J->L, &ctx); +} + +/* Delete debug info for trace and notify GDB. */ +void lj_gdbjit_deltrace(jit_State *J, GCtrace *T) +{ + GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry; + if (eo) { + if (eo->entry.prev_entry) + eo->entry.prev_entry->next_entry = eo->entry.next_entry; + else + __jit_debug_descriptor.first_entry = eo->entry.next_entry; + if (eo->entry.next_entry) + eo->entry.next_entry->prev_entry = eo->entry.prev_entry; + __jit_debug_descriptor.relevant_entry = &eo->entry; + __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER; + __jit_debug_register_code(); + lj_mem_free(J2G(J), eo, eo->sz); + } +} + +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.h new file mode 100644 index 0000000..9ae504f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_gdbjit.h @@ -0,0 +1,22 @@ +/* +** Client for the GDB JIT API. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_GDBJIT_H +#define _LJ_GDBJIT_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT) + +LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T); +LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T); + +#else +#define lj_gdbjit_addtrace(J, T) UNUSED(T) +#define lj_gdbjit_deltrace(J, T) UNUSED(T) +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.c new file mode 100644 index 0000000..b2170a1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.c @@ -0,0 +1,501 @@ +/* +** SSA IR (Intermediate Representation) emitter. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_ir_c +#define LUA_CORE + +/* For pointers to libc/libm functions. */ +#include +#include + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lj_carith.h" +#endif +#include "lj_vm.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* -- IR tables ----------------------------------------------------------- */ + +/* IR instruction modes. */ +LJ_DATADEF const uint8_t lj_ir_mode[IR__MAX+1] = { +IRDEF(IRMODE) + 0 +}; + +/* IR type sizes. */ +LJ_DATADEF const uint8_t lj_ir_type_size[IRT__MAX+1] = { +#define IRTSIZE(name, size) size, +IRTDEF(IRTSIZE) +#undef IRTSIZE + 0 +}; + +/* C call info for CALL* instructions. */ +LJ_DATADEF const CCallInfo lj_ir_callinfo[] = { +#define IRCALLCI(cond, name, nargs, kind, type, flags) \ + { (ASMFunction)IRCALLCOND_##cond(name), \ + (nargs)|(CCI_CALL_##kind)|(IRT_##type<irbuf + J->irbotlim; + MSize szins = J->irtoplim - J->irbotlim; + if (szins) { + baseir = (IRIns *)lj_mem_realloc(J->L, baseir, szins*sizeof(IRIns), + 2*szins*sizeof(IRIns)); + J->irtoplim = J->irbotlim + 2*szins; + } else { + baseir = (IRIns *)lj_mem_realloc(J->L, NULL, 0, LJ_MIN_IRSZ*sizeof(IRIns)); + J->irbotlim = REF_BASE - LJ_MIN_IRSZ/4; + J->irtoplim = J->irbotlim + LJ_MIN_IRSZ; + } + J->cur.ir = J->irbuf = baseir - J->irbotlim; +} + +/* Grow IR buffer at the bottom or shift it up. */ +static void lj_ir_growbot(jit_State *J) +{ + IRIns *baseir = J->irbuf + J->irbotlim; + MSize szins = J->irtoplim - J->irbotlim; + lua_assert(szins != 0); + lua_assert(J->cur.nk == J->irbotlim); + if (J->cur.nins + (szins >> 1) < J->irtoplim) { + /* More than half of the buffer is free on top: shift up by a quarter. */ + MSize ofs = szins >> 2; + memmove(baseir + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns)); + J->irbotlim -= ofs; + J->irtoplim -= ofs; + J->cur.ir = J->irbuf = baseir - J->irbotlim; + } else { + /* Double the buffer size, but split the growth amongst top/bottom. */ + IRIns *newbase = lj_mem_newt(J->L, 2*szins*sizeof(IRIns), IRIns); + MSize ofs = szins >= 256 ? 128 : (szins >> 1); /* Limit bottom growth. */ + memcpy(newbase + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns)); + lj_mem_free(G(J->L), baseir, szins*sizeof(IRIns)); + J->irbotlim -= ofs; + J->irtoplim = J->irbotlim + 2*szins; + J->cur.ir = J->irbuf = newbase - J->irbotlim; + } +} + +/* Emit IR without any optimizations. */ +TRef LJ_FASTCALL lj_ir_emit(jit_State *J) +{ + IRRef ref = lj_ir_nextins(J); + IRIns *ir = IR(ref); + IROp op = fins->o; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; + ir->o = op; + ir->op1 = fins->op1; + ir->op2 = fins->op2; + J->guardemit.irt |= fins->t.irt; + return TREF(ref, irt_t((ir->t = fins->t))); +} + +/* Emit call to a C function. */ +TRef lj_ir_call(jit_State *J, IRCallID id, ...) +{ + const CCallInfo *ci = &lj_ir_callinfo[id]; + uint32_t n = CCI_NARGS(ci); + TRef tr = TREF_NIL; + va_list argp; + va_start(argp, id); + if ((ci->flags & CCI_L)) n--; + if (n > 0) + tr = va_arg(argp, IRRef); + while (n-- > 1) + tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef)); + va_end(argp); + if (CCI_OP(ci) == IR_CALLS) + J->needsnap = 1; /* Need snapshot after call with side effect. */ + return emitir(CCI_OPTYPE(ci), tr, id); +} + +/* -- Interning of constants ---------------------------------------------- */ + +/* +** IR instructions for constants are kept between J->cur.nk >= ref < REF_BIAS. +** They are chained like all other instructions, but grow downwards. +** The are interned (like strings in the VM) to facilitate reference +** comparisons. The same constant must get the same reference. +*/ + +/* Get ref of next IR constant and optionally grow IR. +** Note: this may invalidate all IRIns *! +*/ +static LJ_AINLINE IRRef ir_nextk(jit_State *J) +{ + IRRef ref = J->cur.nk; + if (LJ_UNLIKELY(ref <= J->irbotlim)) lj_ir_growbot(J); + J->cur.nk = --ref; + return ref; +} + +/* Intern int32_t constant. */ +TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + for (ref = J->chain[IR_KINT]; ref; ref = cir[ref].prev) + if (cir[ref].i == k) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->i = k; + ir->t.irt = IRT_INT; + ir->o = IR_KINT; + ir->prev = J->chain[IR_KINT]; + J->chain[IR_KINT] = (IRRef1)ref; +found: + return TREF(ref, IRT_INT); +} + +/* The MRef inside the KNUM/KINT64 IR instructions holds the address of the +** 64 bit constant. The constants themselves are stored in a chained array +** and shared across traces. +** +** Rationale for choosing this data structure: +** - The address of the constants is embedded in the generated machine code +** and must never move. A resizable array or hash table wouldn't work. +** - Most apps need very few non-32 bit integer constants (less than a dozen). +** - Linear search is hard to beat in terms of speed and low complexity. +*/ +typedef struct K64Array { + MRef next; /* Pointer to next list. */ + MSize numk; /* Number of used elements in this array. */ + TValue k[LJ_MIN_K64SZ]; /* Array of constants. */ +} K64Array; + +/* Free all chained arrays. */ +void lj_ir_k64_freeall(jit_State *J) +{ + K64Array *k; + for (k = mref(J->k64, K64Array); k; ) { + K64Array *next = mref(k->next, K64Array); + lj_mem_free(J2G(J), k, sizeof(K64Array)); + k = next; + } +} + +/* Find 64 bit constant in chained array or add it. */ +cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) +{ + K64Array *k, *kp = NULL; + TValue *ntv; + MSize idx; + /* Search for the constant in the whole chain of arrays. */ + for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) { + kp = k; /* Remember previous element in list. */ + for (idx = 0; idx < k->numk; idx++) { /* Search one array. */ + TValue *tv = &k->k[idx]; + if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */ + return tv; + } + } + /* Constant was not found, need to add it. */ + if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ + K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); + setmref(kn->next, NULL); + kn->numk = 0; + if (kp) + setmref(kp->next, kn); /* Chain to the end of the list. */ + else + setmref(J->k64, kn); /* Link first array. */ + kp = kn; + } + ntv = &kp->k[kp->numk++]; /* Add to current array. */ + ntv->u64 = u64; + return ntv; +} + +/* Intern 64 bit constant, given by its address. */ +TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64; + for (ref = J->chain[op]; ref; ref = cir[ref].prev) + if (ir_k64(&cir[ref]) == tv) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + lua_assert(checkptr32(tv)); + setmref(ir->ptr, tv); + ir->t.irt = t; + ir->o = op; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern FP constant, given by its 64 bit pattern. */ +TRef lj_ir_knum_u64(jit_State *J, uint64_t u64) +{ + return lj_ir_k64(J, IR_KNUM, lj_ir_k64_find(J, u64)); +} + +/* Intern 64 bit integer constant. */ +TRef lj_ir_kint64(jit_State *J, uint64_t u64) +{ + return lj_ir_k64(J, IR_KINT64, lj_ir_k64_find(J, u64)); +} + +/* Check whether a number is int and return it. -0 is NOT considered an int. */ +static int numistrueint(lua_Number n, int32_t *kp) +{ + int32_t k = lj_num2int(n); + if (n == (lua_Number)k) { + if (kp) *kp = k; + if (k == 0) { /* Special check for -0. */ + TValue tv; + setnumV(&tv, n); + if (tv.u32.hi != 0) + return 0; + } + return 1; + } + return 0; +} + +/* Intern number as int32_t constant if possible, otherwise as FP constant. */ +TRef lj_ir_knumint(jit_State *J, lua_Number n) +{ + int32_t k; + if (numistrueint(n, &k)) + return lj_ir_kint(J, k); + else + return lj_ir_knum(J, n); +} + +/* Intern GC object "constant". */ +TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + lua_assert(!isdead(J2G(J), o)); + for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev) + if (ir_kgc(&cir[ref]) == o) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + /* NOBARRIER: Current trace is a GC root. */ + setgcref(ir->gcr, o); + ir->t.irt = (uint8_t)t; + ir->o = IR_KGC; + ir->prev = J->chain[IR_KGC]; + J->chain[IR_KGC] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern 32 bit pointer constant. */ +TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr); + for (ref = J->chain[op]; ref; ref = cir[ref].prev) + if (mref(cir[ref].ptr, void) == ptr) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + setmref(ir->ptr, ptr); + ir->t.irt = IRT_P32; + ir->o = op; + ir->prev = J->chain[op]; + J->chain[op] = (IRRef1)ref; +found: + return TREF(ref, IRT_P32); +} + +/* Intern typed NULL constant. */ +TRef lj_ir_knull(jit_State *J, IRType t) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef ref; + for (ref = J->chain[IR_KNULL]; ref; ref = cir[ref].prev) + if (irt_t(cir[ref].t) == t) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->i = 0; + ir->t.irt = (uint8_t)t; + ir->o = IR_KNULL; + ir->prev = J->chain[IR_KNULL]; + J->chain[IR_KNULL] = (IRRef1)ref; +found: + return TREF(ref, t); +} + +/* Intern key slot. */ +TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot) +{ + IRIns *ir, *cir = J->cur.ir; + IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot); + IRRef ref; + /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */ + lua_assert(tref_isk(key) && slot == (IRRef)(IRRef1)slot); + for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev) + if (cir[ref].op12 == op12) + goto found; + ref = ir_nextk(J); + ir = IR(ref); + ir->op12 = op12; + ir->t.irt = IRT_P32; + ir->o = IR_KSLOT; + ir->prev = J->chain[IR_KSLOT]; + J->chain[IR_KSLOT] = (IRRef1)ref; +found: + return TREF(ref, IRT_P32); +} + +/* -- Access to IR constants ---------------------------------------------- */ + +/* Copy value of IR constant. */ +void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir) +{ + UNUSED(L); + lua_assert(ir->o != IR_KSLOT); /* Common mistake. */ + switch (ir->o) { + case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break; + case IR_KINT: setintV(tv, ir->i); break; + case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; + case IR_KPTR: case IR_KKPTR: case IR_KNULL: + setlightudV(tv, mref(ir->ptr, void)); + break; + case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; +#if LJ_HASFFI + case IR_KINT64: { + GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8); + *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64; + setcdataV(L, tv, cd); + break; + } +#endif + default: lua_assert(0); break; + } +} + +/* -- Convert IR operand types -------------------------------------------- */ + +/* Convert from string to number. */ +TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr) +{ + if (!tref_isnumber(tr)) { + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + else + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + return tr; +} + +/* Convert from integer or string to number. */ +TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr) +{ + if (!tref_isnum(tr)) { + if (tref_isinteger(tr)) + tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + else if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + else + lj_trace_err(J, LJ_TRERR_BADTYPE); + } + return tr; +} + +/* Convert from integer or number to string. */ +TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr) +{ + if (!tref_isstr(tr)) { + if (!tref_isnumber(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + tr = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); + } + return tr; +} + +/* -- Miscellaneous IR ops ------------------------------------------------ */ + +/* Evaluate numeric comparison. */ +int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op) +{ + switch (op) { + case IR_EQ: return (a == b); + case IR_NE: return (a != b); + case IR_LT: return (a < b); + case IR_GE: return (a >= b); + case IR_LE: return (a <= b); + case IR_GT: return (a > b); + case IR_ULT: return !(a >= b); + case IR_UGE: return !(a < b); + case IR_ULE: return !(a > b); + case IR_UGT: return !(a <= b); + default: lua_assert(0); return 0; + } +} + +/* Evaluate string comparison. */ +int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op) +{ + int res = lj_str_cmp(a, b); + switch (op) { + case IR_LT: return (res < 0); + case IR_GE: return (res >= 0); + case IR_LE: return (res <= 0); + case IR_GT: return (res > 0); + default: lua_assert(0); return 0; + } +} + +/* Rollback IR to previous state. */ +void lj_ir_rollback(jit_State *J, IRRef ref) +{ + IRRef nins = J->cur.nins; + while (nins > ref) { + IRIns *ir; + nins--; + ir = IR(nins); + J->chain[ir->o] = ir->prev; + } + J->cur.nins = nins; +} + +#undef IR +#undef fins +#undef emitir + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.h new file mode 100644 index 0000000..80763d8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ir.h @@ -0,0 +1,551 @@ +/* +** SSA IR (Intermediate Representation) format. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IR_H +#define _LJ_IR_H + +#include "lj_obj.h" + +/* -- IR instructions ----------------------------------------------------- */ + +/* IR instruction definition. Order matters, see below. ORDER IR */ +#define IRDEF(_) \ + /* Guarded assertions. */ \ + /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \ + _(LT, N , ref, ref) \ + _(GE, N , ref, ref) \ + _(LE, N , ref, ref) \ + _(GT, N , ref, ref) \ + \ + _(ULT, N , ref, ref) \ + _(UGE, N , ref, ref) \ + _(ULE, N , ref, ref) \ + _(UGT, N , ref, ref) \ + \ + _(EQ, C , ref, ref) \ + _(NE, C , ref, ref) \ + \ + _(ABC, N , ref, ref) \ + _(RETF, S , ref, ref) \ + \ + /* Miscellaneous ops. */ \ + _(NOP, N , ___, ___) \ + _(BASE, N , lit, lit) \ + _(PVAL, N , lit, ___) \ + _(GCSTEP, S , ___, ___) \ + _(HIOP, S , ref, ref) \ + _(LOOP, S , ___, ___) \ + _(USE, S , ref, ___) \ + _(PHI, S , ref, ref) \ + _(RENAME, S , ref, lit) \ + \ + /* Constants. */ \ + _(KPRI, N , ___, ___) \ + _(KINT, N , cst, ___) \ + _(KGC, N , cst, ___) \ + _(KPTR, N , cst, ___) \ + _(KKPTR, N , cst, ___) \ + _(KNULL, N , cst, ___) \ + _(KNUM, N , cst, ___) \ + _(KINT64, N , cst, ___) \ + _(KSLOT, N , ref, lit) \ + \ + /* Bit ops. */ \ + _(BNOT, N , ref, ___) \ + _(BSWAP, N , ref, ___) \ + _(BAND, C , ref, ref) \ + _(BOR, C , ref, ref) \ + _(BXOR, C , ref, ref) \ + _(BSHL, N , ref, ref) \ + _(BSHR, N , ref, ref) \ + _(BSAR, N , ref, ref) \ + _(BROL, N , ref, ref) \ + _(BROR, N , ref, ref) \ + \ + /* Arithmetic ops. ORDER ARITH */ \ + _(ADD, C , ref, ref) \ + _(SUB, N , ref, ref) \ + _(MUL, C , ref, ref) \ + _(DIV, N , ref, ref) \ + _(MOD, N , ref, ref) \ + _(POW, N , ref, ref) \ + _(NEG, N , ref, ref) \ + \ + _(ABS, N , ref, ref) \ + _(ATAN2, N , ref, ref) \ + _(LDEXP, N , ref, ref) \ + _(MIN, C , ref, ref) \ + _(MAX, C , ref, ref) \ + _(FPMATH, N , ref, lit) \ + \ + /* Overflow-checking arithmetic ops. */ \ + _(ADDOV, CW, ref, ref) \ + _(SUBOV, NW, ref, ref) \ + _(MULOV, CW, ref, ref) \ + \ + /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \ + \ + /* Memory references. */ \ + _(AREF, R , ref, ref) \ + _(HREFK, R , ref, ref) \ + _(HREF, L , ref, ref) \ + _(NEWREF, S , ref, ref) \ + _(UREFO, LW, ref, lit) \ + _(UREFC, LW, ref, lit) \ + _(FREF, R , ref, lit) \ + _(STRREF, N , ref, ref) \ + \ + /* Loads and Stores. These must be in the same order. */ \ + _(ALOAD, L , ref, ___) \ + _(HLOAD, L , ref, ___) \ + _(ULOAD, L , ref, ___) \ + _(FLOAD, L , ref, lit) \ + _(XLOAD, L , ref, lit) \ + _(SLOAD, L , lit, lit) \ + _(VLOAD, L , ref, ___) \ + \ + _(ASTORE, S , ref, ref) \ + _(HSTORE, S , ref, ref) \ + _(USTORE, S , ref, ref) \ + _(FSTORE, S , ref, ref) \ + _(XSTORE, S , ref, ref) \ + \ + /* Allocations. */ \ + _(SNEW, N , ref, ref) /* CSE is ok, not marked as A. */ \ + _(XSNEW, A , ref, ref) \ + _(TNEW, AW, lit, lit) \ + _(TDUP, AW, ref, ___) \ + _(CNEW, AW, ref, ref) \ + _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \ + \ + /* Barriers. */ \ + _(TBAR, S , ref, ___) \ + _(OBAR, S , ref, ref) \ + _(XBAR, S , ___, ___) \ + \ + /* Type conversions. */ \ + _(CONV, NW, ref, lit) \ + _(TOBIT, N , ref, ref) \ + _(TOSTR, N , ref, ___) \ + _(STRTO, N , ref, ___) \ + \ + /* Calls. */ \ + _(CALLN, N , ref, lit) \ + _(CALLL, L , ref, lit) \ + _(CALLS, S , ref, lit) \ + _(CALLXS, S , ref, ref) \ + _(CARG, N , ref, ref) \ + \ + /* End of list. */ + +/* IR opcodes (max. 256). */ +typedef enum { +#define IRENUM(name, m, m1, m2) IR_##name, +IRDEF(IRENUM) +#undef IRENUM + IR__MAX +} IROp; + +/* Stored opcode. */ +typedef uint8_t IROp1; + +LJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE); +LJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE); +LJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT); +LJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT); +LJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT); + +/* Delta between xLOAD and xSTORE. */ +#define IRDELTA_L2S ((int)IR_ASTORE - (int)IR_ALOAD) + +LJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE); +LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE); +LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE); +LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE); + +/* -- Named IR literals --------------------------------------------------- */ + +/* FPMATH sub-functions. ORDER FPM. */ +#define IRFPMDEF(_) \ + _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \ + _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \ + _(SIN) _(COS) _(TAN) \ + _(OTHER) + +typedef enum { +#define FPMENUM(name) IRFPM_##name, +IRFPMDEF(FPMENUM) +#undef FPMENUM + IRFPM__MAX +} IRFPMathOp; + +/* FLOAD fields. */ +#define IRFLDEF(_) \ + _(STR_LEN, offsetof(GCstr, len)) \ + _(FUNC_ENV, offsetof(GCfunc, l.env)) \ + _(FUNC_PC, offsetof(GCfunc, l.pc)) \ + _(TAB_META, offsetof(GCtab, metatable)) \ + _(TAB_ARRAY, offsetof(GCtab, array)) \ + _(TAB_NODE, offsetof(GCtab, node)) \ + _(TAB_ASIZE, offsetof(GCtab, asize)) \ + _(TAB_HMASK, offsetof(GCtab, hmask)) \ + _(TAB_NOMM, offsetof(GCtab, nomm)) \ + _(UDATA_META, offsetof(GCudata, metatable)) \ + _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \ + _(UDATA_FILE, sizeof(GCudata)) \ + _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \ + _(CDATA_PTR, sizeof(GCcdata)) \ + _(CDATA_INT, sizeof(GCcdata)) \ + _(CDATA_INT64, sizeof(GCcdata)) \ + _(CDATA_INT64_4, sizeof(GCcdata) + 4) + +typedef enum { +#define FLENUM(name, ofs) IRFL_##name, +IRFLDEF(FLENUM) +#undef FLENUM + IRFL__MAX +} IRFieldID; + +/* SLOAD mode bits, stored in op2. */ +#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */ +#define IRSLOAD_FRAME 0x02 /* Load hiword of frame. */ +#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */ +#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */ +#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */ +#define IRSLOAD_INHERIT 0x20 /* Inherited by exits/side traces. */ + +/* XLOAD mode, stored in op2. */ +#define IRXLOAD_READONLY 1 /* Load from read-only data. */ +#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */ +#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */ + +/* CONV mode, stored in op2. */ +#define IRCONV_SRCMASK 0x001f /* Source IRType. */ +#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */ +#define IRCONV_DSH 5 +#define IRCONV_NUM_INT ((IRT_NUM<>2)&3)) +#define irm_iscomm(m) ((m) & IRM_C) +#define irm_kind(m) ((m) & IRM_S) + +#define IRMODE(name, m, m1, m2) (((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W), + +LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1]; + +/* -- IR instruction types ------------------------------------------------ */ + +/* Map of itypes to non-negative numbers. ORDER LJ_T. +** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for +** IRT_P32 and IRT_P64, which never escape the IR. +** The various integers are only used in the IR and can only escape to +** a TValue after implicit or explicit conversion. Their types must be +** contiguous and next to IRT_NUM (see the typerange macros below). +*/ +#define IRTDEF(_) \ + _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \ + _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \ + _(TAB, 4) _(UDATA, 4) \ + _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \ + _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \ + _(SOFTFP, 4) /* There is room for 9 more types. */ + +/* IR result type and flags (8 bit). */ +typedef enum { +#define IRTENUM(name, size) IRT_##name, +IRTDEF(IRTENUM) +#undef IRTENUM + IRT__MAX, + + /* Native pointer type and the corresponding integer type. */ + IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32, + IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT, + IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32, + + /* Additional flags. */ + IRT_MARK = 0x20, /* Marker for misc. purposes. */ + IRT_ISPHI = 0x40, /* Instruction is left or right PHI operand. */ + IRT_GUARD = 0x80, /* Instruction is a guard. */ + + /* Masks. */ + IRT_TYPE = 0x1f, + IRT_T = 0xff +} IRType; + +#define irtype_ispri(irt) ((uint32_t)(irt) <= IRT_TRUE) + +/* Stored IRType. */ +typedef struct IRType1 { uint8_t irt; } IRType1; + +#define IRT(o, t) ((uint32_t)(((o)<<8) | (t))) +#define IRTI(o) (IRT((o), IRT_INT)) +#define IRTN(o) (IRT((o), IRT_NUM)) +#define IRTG(o, t) (IRT((o), IRT_GUARD|(t))) +#define IRTGI(o) (IRT((o), IRT_GUARD|IRT_INT)) + +#define irt_t(t) ((IRType)(t).irt) +#define irt_type(t) ((IRType)((t).irt & IRT_TYPE)) +#define irt_sametype(t1, t2) ((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0) +#define irt_typerange(t, first, last) \ + ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first)) + +#define irt_isnil(t) (irt_type(t) == IRT_NIL) +#define irt_ispri(t) ((uint32_t)irt_type(t) <= IRT_TRUE) +#define irt_islightud(t) (irt_type(t) == IRT_LIGHTUD) +#define irt_isstr(t) (irt_type(t) == IRT_STR) +#define irt_istab(t) (irt_type(t) == IRT_TAB) +#define irt_iscdata(t) (irt_type(t) == IRT_CDATA) +#define irt_isfloat(t) (irt_type(t) == IRT_FLOAT) +#define irt_isnum(t) (irt_type(t) == IRT_NUM) +#define irt_isint(t) (irt_type(t) == IRT_INT) +#define irt_isi8(t) (irt_type(t) == IRT_I8) +#define irt_isu8(t) (irt_type(t) == IRT_U8) +#define irt_isi16(t) (irt_type(t) == IRT_I16) +#define irt_isu16(t) (irt_type(t) == IRT_U16) +#define irt_isu32(t) (irt_type(t) == IRT_U32) +#define irt_isi64(t) (irt_type(t) == IRT_I64) +#define irt_isu64(t) (irt_type(t) == IRT_U64) + +#define irt_isfp(t) (irt_isnum(t) || irt_isfloat(t)) +#define irt_isinteger(t) (irt_typerange((t), IRT_I8, IRT_INT)) +#define irt_isgcv(t) (irt_typerange((t), IRT_STR, IRT_UDATA)) +#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA)) +#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64)) + +#if LJ_64 +#define IRT_IS64 \ + ((1u<> irt_type(t)) & 1) +#define irt_is64orfp(t) (((IRT_IS64|(1u<>irt_type(t)) & 1) + +#define irt_size(t) (lj_ir_type_size[irt_t((t))]) + +LJ_DATA const uint8_t lj_ir_type_size[]; + +static LJ_AINLINE IRType itype2irt(const TValue *tv) +{ + if (tvisint(tv)) + return IRT_INT; + else if (tvisnum(tv)) + return IRT_NUM; +#if LJ_64 + else if (tvislightud(tv)) + return IRT_LIGHTUD; +#endif + else + return (IRType)~itype(tv); +} + +static LJ_AINLINE uint32_t irt_toitype_(IRType t) +{ + lua_assert(!LJ_64 || t != IRT_LIGHTUD); + if (LJ_DUALNUM && t > IRT_NUM) { + return LJ_TISNUM; + } else { + lua_assert(t <= IRT_NUM); + return ~(uint32_t)t; + } +} + +#define irt_toitype(t) irt_toitype_(irt_type((t))) + +#define irt_isguard(t) ((t).irt & IRT_GUARD) +#define irt_ismarked(t) ((t).irt & IRT_MARK) +#define irt_setmark(t) ((t).irt |= IRT_MARK) +#define irt_clearmark(t) ((t).irt &= ~IRT_MARK) +#define irt_isphi(t) ((t).irt & IRT_ISPHI) +#define irt_setphi(t) ((t).irt |= IRT_ISPHI) +#define irt_clearphi(t) ((t).irt &= ~IRT_ISPHI) + +/* Stored combined IR opcode and type. */ +typedef uint16_t IROpT; + +/* -- IR references ------------------------------------------------------- */ + +/* IR references. */ +typedef uint16_t IRRef1; /* One stored reference. */ +typedef uint32_t IRRef2; /* Two stored references. */ +typedef uint32_t IRRef; /* Used to pass around references. */ + +/* Fixed references. */ +enum { + REF_BIAS = 0x8000, + REF_TRUE = REF_BIAS-3, + REF_FALSE = REF_BIAS-2, + REF_NIL = REF_BIAS-1, /* \--- Constants grow downwards. */ + REF_BASE = REF_BIAS, /* /--- IR grows upwards. */ + REF_FIRST = REF_BIAS+1, + REF_DROP = 0xffff +}; + +/* Note: IRMlit operands must be < REF_BIAS, too! +** This allows for fast and uniform manipulation of all operands +** without looking up the operand mode in lj_ir_mode: +** - CSE calculates the maximum reference of two operands. +** This must work with mixed reference/literal operands, too. +** - DCE marking only checks for operand >= REF_BIAS. +** - LOOP needs to substitute reference operands. +** Constant references and literals must not be modified. +*/ + +#define IRREF2(lo, hi) ((IRRef2)(lo) | ((IRRef2)(hi) << 16)) + +#define irref_isk(ref) ((ref) < REF_BIAS) + +/* Tagged IR references (32 bit). +** +** +-------+-------+---------------+ +** | irt | flags | ref | +** +-------+-------+---------------+ +** +** The tag holds a copy of the IRType and speeds up IR type checks. +*/ +typedef uint32_t TRef; + +#define TREF_REFMASK 0x0000ffff +#define TREF_FRAME 0x00010000 +#define TREF_CONT 0x00020000 + +#define TREF(ref, t) ((TRef)((ref) + ((t)<<24))) + +#define tref_ref(tr) ((IRRef1)(tr)) +#define tref_t(tr) ((IRType)((tr)>>24)) +#define tref_type(tr) ((IRType)(((tr)>>24) & IRT_TYPE)) +#define tref_typerange(tr, first, last) \ + ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first)) + +#define tref_istype(tr, t) (((tr) & (IRT_TYPE<<24)) == ((t)<<24)) +#define tref_isnil(tr) (tref_istype((tr), IRT_NIL)) +#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE)) +#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE)) +#define tref_isstr(tr) (tref_istype((tr), IRT_STR)) +#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC)) +#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA)) +#define tref_istab(tr) (tref_istype((tr), IRT_TAB)) +#define tref_isudata(tr) (tref_istype((tr), IRT_UDATA)) +#define tref_isnum(tr) (tref_istype((tr), IRT_NUM)) +#define tref_isint(tr) (tref_istype((tr), IRT_INT)) + +#define tref_isbool(tr) (tref_typerange((tr), IRT_FALSE, IRT_TRUE)) +#define tref_ispri(tr) (tref_typerange((tr), IRT_NIL, IRT_TRUE)) +#define tref_istruecond(tr) (!tref_typerange((tr), IRT_NIL, IRT_FALSE)) +#define tref_isinteger(tr) (tref_typerange((tr), IRT_I8, IRT_INT)) +#define tref_isnumber(tr) (tref_typerange((tr), IRT_NUM, IRT_INT)) +#define tref_isnumber_str(tr) (tref_isnumber((tr)) || tref_isstr((tr))) +#define tref_isgcv(tr) (tref_typerange((tr), IRT_STR, IRT_UDATA)) + +#define tref_isk(tr) (irref_isk(tref_ref((tr)))) +#define tref_isk2(tr1, tr2) (irref_isk(tref_ref((tr1) | (tr2)))) + +#define TREF_PRI(t) (TREF(REF_NIL-(t), (t))) +#define TREF_NIL (TREF_PRI(IRT_NIL)) +#define TREF_FALSE (TREF_PRI(IRT_FALSE)) +#define TREF_TRUE (TREF_PRI(IRT_TRUE)) + +/* -- IR format ----------------------------------------------------------- */ + +/* IR instruction format (64 bit). +** +** 16 16 8 8 8 8 +** +-------+-------+---+---+---+---+ +** | op1 | op2 | t | o | r | s | +** +-------+-------+---+---+---+---+ +** | op12/i/gco | ot | prev | (alternative fields in union) +** +---------------+-------+-------+ +** 32 16 16 +** +** prev is only valid prior to register allocation and then reused for r + s. +*/ + +typedef union IRIns { + struct { + LJ_ENDIAN_LOHI( + IRRef1 op1; /* IR operand 1. */ + , IRRef1 op2; /* IR operand 2. */ + ) + IROpT ot; /* IR opcode and type (overlaps t and o). */ + IRRef1 prev; /* Previous ins in same chain (overlaps r and s). */ + }; + struct { + IRRef2 op12; /* IR operand 1 and 2 (overlaps op1 and op2). */ + LJ_ENDIAN_LOHI( + IRType1 t; /* IR type. */ + , IROp1 o; /* IR opcode. */ + ) + LJ_ENDIAN_LOHI( + uint8_t r; /* Register allocation (overlaps prev). */ + , uint8_t s; /* Spill slot allocation (overlaps prev). */ + ) + }; + int32_t i; /* 32 bit signed integer literal (overlaps op12). */ + GCRef gcr; /* GCobj constant (overlaps op12). */ + MRef ptr; /* Pointer constant (overlaps op12). */ +} IRIns; + +#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr)) +#define ir_kstr(ir) (gco2str(ir_kgc((ir)))) +#define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) +#define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) +#define ir_kcdata(ir) (gco2cd(ir_kgc((ir)))) +#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue)) +#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) +#define ir_k64(ir) \ + check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) +#define ir_kptr(ir) \ + check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void)) + +/* A store or any other op with a non-weak guard has a side-effect. */ +static LJ_AINLINE int ir_sideeff(IRIns *ir) +{ + return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S); +} + +LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ircall.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ircall.h new file mode 100644 index 0000000..af30ba8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_ircall.h @@ -0,0 +1,271 @@ +/* +** IR CALL* instruction definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IRCALL_H +#define _LJ_IRCALL_H + +#include "lj_obj.h" +#include "lj_ir.h" +#include "lj_jit.h" + +/* C call info for CALL* instructions. */ +typedef struct CCallInfo { + ASMFunction func; /* Function pointer. */ + uint32_t flags; /* Number of arguments and flags. */ +} CCallInfo; + +#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */ +#define CCI_NARGS_MAX 32 /* Max. # of args. */ + +#define CCI_OTSHIFT 16 +#define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */ +#define CCI_OPSHIFT 24 +#define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */ + +#define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT) +#define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT) +#define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT) +#define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL) +#define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL) +#define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL) + +/* C call info flags. */ +#define CCI_L 0x0100 /* Implicit L arg. */ +#define CCI_CASTU64 0x0200 /* Cast u64 result to number. */ +#define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */ +#define CCI_VARARG 0x0800 /* Vararg function. */ + +#define CCI_CC_MASK 0x3000 /* Calling convention mask. */ +#define CCI_CC_SHIFT 12 +/* ORDER CC */ +#define CCI_CC_CDECL 0x0000 /* Default cdecl calling convention. */ +#define CCI_CC_THISCALL 0x1000 /* Thiscall calling convention. */ +#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */ +#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */ + +/* Helpers for conditional function definitions. */ +#define IRCALLCOND_ANY(x) x + +#if LJ_TARGET_X86ORX64 +#define IRCALLCOND_FPMATH(x) NULL +#else +#define IRCALLCOND_FPMATH(x) x +#endif + +#if LJ_SOFTFP +#define IRCALLCOND_SOFTFP(x) x +#if LJ_HASFFI +#define IRCALLCOND_SOFTFP_FFI(x) x +#else +#define IRCALLCOND_SOFTFP_FFI(x) NULL +#endif +#else +#define IRCALLCOND_SOFTFP(x) NULL +#define IRCALLCOND_SOFTFP_FFI(x) NULL +#endif + +#define LJ_NEED_FP64 (LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS) + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +#define IRCALLCOND_FP64_FFI(x) x +#else +#define IRCALLCOND_FP64_FFI(x) NULL +#endif + +#if LJ_HASFFI +#define IRCALLCOND_FFI(x) x +#if LJ_32 +#define IRCALLCOND_FFI32(x) x +#else +#define IRCALLCOND_FFI32(x) NULL +#endif +#else +#define IRCALLCOND_FFI(x) NULL +#define IRCALLCOND_FFI32(x) NULL +#endif + +#if LJ_SOFTFP +#define ARG1_FP 2 /* Treat as 2 32 bit arguments. */ +#else +#define ARG1_FP 1 +#endif + +#if LJ_32 +#define ARG2_64 4 /* Treat as 4 32 bit arguments. */ +#else +#define ARG2_64 2 +#endif + +/* Function definitions for CALL* instructions. */ +#define IRCALLDEF(_) \ + _(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \ + _(ANY, lj_str_new, 3, S, STR, CCI_L) \ + _(ANY, lj_strscan_num, 2, FN, INT, 0) \ + _(ANY, lj_str_fromint, 2, FN, STR, CCI_L) \ + _(ANY, lj_str_fromnum, 2, FN, STR, CCI_L) \ + _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \ + _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \ + _(ANY, lj_tab_newkey, 3, S, P32, CCI_L) \ + _(ANY, lj_tab_len, 1, FL, INT, 0) \ + _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \ + _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \ + _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \ + _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \ + _(ANY, lj_vm_modi, 2, FN, INT, 0) \ + _(ANY, sinh, ARG1_FP, N, NUM, 0) \ + _(ANY, cosh, ARG1_FP, N, NUM, 0) \ + _(ANY, tanh, ARG1_FP, N, NUM, 0) \ + _(ANY, fputc, 2, S, INT, 0) \ + _(ANY, fwrite, 4, S, INT, 0) \ + _(ANY, fflush, 1, S, INT, 0) \ + /* ORDER FPM */ \ + _(FPMATH, lj_vm_floor, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_ceil, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_trunc, ARG1_FP, N, NUM, 0) \ + _(FPMATH, sqrt, ARG1_FP, N, NUM, 0) \ + _(FPMATH, exp, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_exp2, ARG1_FP, N, NUM, 0) \ + _(FPMATH, log, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_log2, ARG1_FP, N, NUM, 0) \ + _(FPMATH, log10, ARG1_FP, N, NUM, 0) \ + _(FPMATH, sin, ARG1_FP, N, NUM, 0) \ + _(FPMATH, cos, ARG1_FP, N, NUM, 0) \ + _(FPMATH, tan, ARG1_FP, N, NUM, 0) \ + _(FPMATH, lj_vm_powi, ARG1_FP+1, N, NUM, 0) \ + _(FPMATH, pow, ARG1_FP*2, N, NUM, 0) \ + _(FPMATH, atan2, ARG1_FP*2, N, NUM, 0) \ + _(FPMATH, ldexp, ARG1_FP+1, N, NUM, 0) \ + _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \ + _(SOFTFP, softfp_add, 4, N, NUM, 0) \ + _(SOFTFP, softfp_sub, 4, N, NUM, 0) \ + _(SOFTFP, softfp_mul, 4, N, NUM, 0) \ + _(SOFTFP, softfp_div, 4, N, NUM, 0) \ + _(SOFTFP, softfp_cmp, 4, N, NIL, 0) \ + _(SOFTFP, softfp_i2d, 1, N, NUM, 0) \ + _(SOFTFP, softfp_d2i, 2, N, INT, 0) \ + _(SOFTFP_FFI, softfp_ui2d, 1, N, NUM, 0) \ + _(SOFTFP_FFI, softfp_f2d, 1, N, NUM, 0) \ + _(SOFTFP_FFI, softfp_d2ui, 2, N, INT, 0) \ + _(SOFTFP_FFI, softfp_d2f, 2, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_i2f, 1, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \ + _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \ + _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \ + _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_d2l, ARG1_FP, N, I64, 0) \ + _(FP64_FFI, fp64_d2ul, ARG1_FP, N, U64, 0) \ + _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \ + _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \ + _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ + _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \ + _(FFI, strlen, 1, L, INTP, 0) \ + _(FFI, memcpy, 3, S, PTR, 0) \ + _(FFI, memset, 3, S, PTR, 0) \ + _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \ + _(FFI32, lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) + \ + /* End of list. */ + +typedef enum { +#define IRCALLENUM(cond, name, nargs, kind, type, flags) IRCALL_##name, +IRCALLDEF(IRCALLENUM) +#undef IRCALLENUM + IRCALL__MAX +} IRCallID; + +LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...); + +LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1]; + +/* Soft-float declarations. */ +#if LJ_SOFTFP +#if LJ_TARGET_ARM +#define softfp_add __aeabi_dadd +#define softfp_sub __aeabi_dsub +#define softfp_mul __aeabi_dmul +#define softfp_div __aeabi_ddiv +#define softfp_cmp __aeabi_cdcmple +#define softfp_i2d __aeabi_i2d +#define softfp_d2i __aeabi_d2iz +#define softfp_ui2d __aeabi_ui2d +#define softfp_f2d __aeabi_f2d +#define softfp_d2ui __aeabi_d2uiz +#define softfp_d2f __aeabi_d2f +#define softfp_i2f __aeabi_i2f +#define softfp_ui2f __aeabi_ui2f +#define softfp_f2i __aeabi_f2iz +#define softfp_f2ui __aeabi_f2uiz +#define fp64_l2d __aeabi_l2d +#define fp64_ul2d __aeabi_ul2d +#define fp64_l2f __aeabi_l2f +#define fp64_ul2f __aeabi_ul2f +#if LJ_TARGET_IOS +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi +#else +#define fp64_d2l __aeabi_d2lz +#define fp64_d2ul __aeabi_d2ulz +#define fp64_f2l __aeabi_f2lz +#define fp64_f2ul __aeabi_f2ulz +#endif +#else +#error "Missing soft-float definitions for target architecture" +#endif +extern double softfp_add(double a, double b); +extern double softfp_sub(double a, double b); +extern double softfp_mul(double a, double b); +extern double softfp_div(double a, double b); +extern void softfp_cmp(double a, double b); +extern double softfp_i2d(int32_t a); +extern int32_t softfp_d2i(double a); +#if LJ_HASFFI +extern double softfp_ui2d(uint32_t a); +extern double softfp_f2d(float a); +extern uint32_t softfp_d2ui(double a); +extern float softfp_d2f(double a); +extern float softfp_i2f(int32_t a); +extern float softfp_ui2f(uint32_t a); +extern int32_t softfp_f2i(float a); +extern uint32_t softfp_f2ui(float a); +#endif +#endif + +#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP) +#ifdef __GNUC__ +#define fp64_l2d __floatdidf +#define fp64_ul2d __floatundidf +#define fp64_l2f __floatdisf +#define fp64_ul2f __floatundisf +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi +#else +#error "Missing fp64 helper definitions for this compiler" +#endif +#endif + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +extern double fp64_l2d(int64_t a); +extern double fp64_ul2d(uint64_t a); +extern float fp64_l2f(int64_t a); +extern float fp64_ul2f(uint64_t a); +extern int64_t fp64_d2l(double a); +extern uint64_t fp64_d2ul(double a); +extern int64_t fp64_f2l(float a); +extern uint64_t fp64_f2ul(float a); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_iropt.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_iropt.h new file mode 100644 index 0000000..e45ae2b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_iropt.h @@ -0,0 +1,161 @@ +/* +** Common header for IR emitter and optimizations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_IROPT_H +#define _LJ_IROPT_H + +#include + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* IR emitter. */ +LJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J); + +/* Save current IR in J->fold.ins, but do not emit it (yet). */ +static LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b) +{ + J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b; +} + +#define lj_ir_set(J, ot, a, b) \ + lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b)) + +/* Get ref of next IR instruction and optionally grow IR. +** Note: this may invalidate all IRIns*! +*/ +static LJ_AINLINE IRRef lj_ir_nextins(jit_State *J) +{ + IRRef ref = J->cur.nins; + if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J); + J->cur.nins = ref + 1; + return ref; +} + +/* Interning of constants. */ +LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k); +LJ_FUNC void lj_ir_k64_freeall(jit_State *J); +LJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv); +LJ_FUNC cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n); +LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64); +LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t); +LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr); +LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t); +LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot); + +#if LJ_64 +#define lj_ir_kintp(J, k) lj_ir_kint64(J, (uint64_t)(k)) +#else +#define lj_ir_kintp(J, k) lj_ir_kint(J, (int32_t)(k)) +#endif + +static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n) +{ + TValue tv; + tv.n = n; + return lj_ir_knum_u64(J, tv.u64); +} + +#define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR) +#define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB) +#define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC) +#define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr)) +#define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr)) + +/* Special FP constants. */ +#define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000)) +#define lj_ir_knum_one(J) lj_ir_knum_u64(J, U64x(3ff00000,00000000)) +#define lj_ir_knum_tobit(J) lj_ir_knum_u64(J, U64x(43380000,00000000)) + +/* Special 128 bit SIMD constants. */ +#define lj_ir_knum_abs(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_ABS)) +#define lj_ir_knum_neg(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_NEG)) + +/* Access to constants. */ +LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir); + +/* Convert IR operand types. */ +LJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr); + +/* Miscellaneous IR ops. */ +LJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op); +LJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op); +LJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref); + +/* Emit IR instructions with on-the-fly optimizations. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim); + +/* Special return values for the fold functions. */ +enum { + NEXTFOLD, /* Couldn't fold, pass on. */ + RETRYFOLD, /* Retry fold with modified fins. */ + KINTFOLD, /* Return ref for int constant in fins->i. */ + FAILFOLD, /* Guard would always fail. */ + DROPFOLD, /* Guard eliminated. */ + MAX_FOLD +}; + +#define INTFOLD(k) ((J->fold.ins.i = (k)), (TRef)KINTFOLD) +#define INT64FOLD(k) (lj_ir_kint64(J, (k))) +#define CONDFOLD(cond) ((TRef)FAILFOLD + (TRef)(cond)) +#define LEFTFOLD (J->fold.ins.op1) +#define RIGHTFOLD (J->fold.ins.op2) +#define CSEFOLD (lj_opt_cse(J)) +#define EMITFOLD (lj_ir_emit(J)) + +/* Load/store forwarding. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J); +LJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J); +LJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim); +LJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref); + +/* Dead-store elimination. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J); + +/* Narrowing. */ +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr); +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr); +#if LJ_HASFFI +LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key); +#endif +LJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc, + TValue *vb, TValue *vc, IROp op); +LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc); +LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc); +LJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc); +LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase); + +/* Optimization passes. */ +LJ_FUNC void lj_opt_dce(jit_State *J); +LJ_FUNC int lj_opt_loop(jit_State *J); +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) +LJ_FUNC void lj_opt_split(jit_State *J); +#else +#define lj_opt_split(J) UNUSED(J) +#endif +LJ_FUNC void lj_opt_sink(jit_State *J); + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_jit.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_jit.h new file mode 100644 index 0000000..b69e4f4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_jit.h @@ -0,0 +1,416 @@ +/* +** Common definitions for the JIT compiler. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_JIT_H +#define _LJ_JIT_H + +#include "lj_obj.h" +#include "lj_ir.h" + +/* JIT engine flags. */ +#define JIT_F_ON 0x00000001 + +/* CPU-specific JIT engine flags. */ +#if LJ_TARGET_X86ORX64 +#define JIT_F_CMOV 0x00000010 +#define JIT_F_SSE2 0x00000020 +#define JIT_F_SSE3 0x00000040 +#define JIT_F_SSE4_1 0x00000080 +#define JIT_F_P4 0x00000100 +#define JIT_F_PREFER_IMUL 0x00000200 +#define JIT_F_SPLIT_XMM 0x00000400 +#define JIT_F_LEA_AGU 0x00000800 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_CMOV +#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM" +#elif LJ_TARGET_ARM +#define JIT_F_ARMV6_ 0x00000010 +#define JIT_F_ARMV6T2_ 0x00000020 +#define JIT_F_ARMV7 0x00000040 +#define JIT_F_VFPV2 0x00000080 +#define JIT_F_VFPV3 0x00000100 + +#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7) +#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7) +#define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3) + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_ARMV6_ +#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3" +#elif LJ_TARGET_PPC +#define JIT_F_SQRT 0x00000010 +#define JIT_F_ROUND 0x00000020 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_SQRT +#define JIT_F_CPUSTRING "\4SQRT\5ROUND" +#elif LJ_TARGET_MIPS +#define JIT_F_MIPS32R2 0x00000010 + +/* Names for the CPU-specific flags. Must match the order above. */ +#define JIT_F_CPU_FIRST JIT_F_MIPS32R2 +#define JIT_F_CPUSTRING "\010MIPS32R2" +#else +#define JIT_F_CPU_FIRST 0 +#define JIT_F_CPUSTRING "" +#endif + +/* Optimization flags. */ +#define JIT_F_OPT_MASK 0x0fff0000 + +#define JIT_F_OPT_FOLD 0x00010000 +#define JIT_F_OPT_CSE 0x00020000 +#define JIT_F_OPT_DCE 0x00040000 +#define JIT_F_OPT_FWD 0x00080000 +#define JIT_F_OPT_DSE 0x00100000 +#define JIT_F_OPT_NARROW 0x00200000 +#define JIT_F_OPT_LOOP 0x00400000 +#define JIT_F_OPT_ABC 0x00800000 +#define JIT_F_OPT_SINK 0x01000000 +#define JIT_F_OPT_FUSE 0x02000000 + +/* Optimizations names for -O. Must match the order above. */ +#define JIT_F_OPT_FIRST JIT_F_OPT_FOLD +#define JIT_F_OPTSTRING \ + "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse" + +/* Optimization levels set a fixed combination of flags. */ +#define JIT_F_OPT_0 0 +#define JIT_F_OPT_1 (JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE) +#define JIT_F_OPT_2 (JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP) +#define JIT_F_OPT_3 (JIT_F_OPT_2|\ + JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE) +#define JIT_F_OPT_DEFAULT JIT_F_OPT_3 + +#if LJ_TARGET_WINDOWS || LJ_64 +/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ +#define JIT_P_sizemcode_DEFAULT 64 +#else +/* Could go as low as 4K, but the mmap() overhead would be rather high. */ +#define JIT_P_sizemcode_DEFAULT 32 +#endif + +/* Optimization parameters and their defaults. Length is a char in octal! */ +#define JIT_PARAMDEF(_) \ + _(\010, maxtrace, 1000) /* Max. # of traces in cache. */ \ + _(\011, maxrecord, 4000) /* Max. # of recorded IR instructions. */ \ + _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \ + _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \ + _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \ + \ + _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \ + _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \ + _(\007, tryside, 4) /* # of attempts to compile a side trace. */ \ + \ + _(\012, instunroll, 4) /* Max. unroll for instable loops. */ \ + _(\012, loopunroll, 15) /* Max. unroll for loop ops in side traces. */ \ + _(\012, callunroll, 3) /* Max. unroll for recursive calls. */ \ + _(\011, recunroll, 2) /* Min. unroll for true recursion. */ \ + \ + /* Size of each machine code area (in KBytes). */ \ + _(\011, sizemcode, JIT_P_sizemcode_DEFAULT) \ + /* Max. total size of all machine code areas (in KBytes). */ \ + _(\010, maxmcode, 512) \ + /* End of list. */ + +enum { +#define JIT_PARAMENUM(len, name, value) JIT_P_##name, +JIT_PARAMDEF(JIT_PARAMENUM) +#undef JIT_PARAMENUM + JIT_P__MAX +}; + +#define JIT_PARAMSTR(len, name, value) #len #name +#define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR) + +/* Trace compiler state. */ +typedef enum { + LJ_TRACE_IDLE, /* Trace compiler idle. */ + LJ_TRACE_ACTIVE = 0x10, + LJ_TRACE_RECORD, /* Bytecode recording active. */ + LJ_TRACE_START, /* New trace started. */ + LJ_TRACE_END, /* End of trace. */ + LJ_TRACE_ASM, /* Assemble trace. */ + LJ_TRACE_ERR /* Trace aborted with error. */ +} TraceState; + +/* Post-processing action. */ +typedef enum { + LJ_POST_NONE, /* No action. */ + LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */ + LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */ + LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */ + LJ_POST_FIXBOOL, /* Fixup boolean result. */ + LJ_POST_FIXCONST, /* Fixup constant results. */ + LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */ +} PostProc; + +/* Machine code type. */ +#if LJ_TARGET_X86ORX64 +typedef uint8_t MCode; +#else +typedef uint32_t MCode; +#endif + +/* Stack snapshot header. */ +typedef struct SnapShot { + uint16_t mapofs; /* Offset into snapshot map. */ + IRRef1 ref; /* First IR ref for this snapshot. */ + uint8_t nslots; /* Number of valid slots. */ + uint8_t topslot; /* Maximum frame extent. */ + uint8_t nent; /* Number of compressed entries. */ + uint8_t count; /* Count of taken exits for this snapshot. */ +} SnapShot; + +#define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */ + +/* Compressed snapshot entry. */ +typedef uint32_t SnapEntry; + +#define SNAP_FRAME 0x010000 /* Frame slot. */ +#define SNAP_CONT 0x020000 /* Continuation slot. */ +#define SNAP_NORESTORE 0x040000 /* No need to restore slot. */ +#define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */ +LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME); +LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT); + +#define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref)) +#define SNAP_TR(slot, tr) \ + (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK))) +#define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc)) +#define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz)) +#define snap_ref(sn) ((sn) & 0xffff) +#define snap_slot(sn) ((BCReg)((sn) >> 24)) +#define snap_isframe(sn) ((sn) & SNAP_FRAME) +#define snap_pc(sn) ((const BCIns *)(uintptr_t)(sn)) +#define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref)) + +/* Snapshot and exit numbers. */ +typedef uint32_t SnapNo; +typedef uint32_t ExitNo; + +/* Trace number. */ +typedef uint32_t TraceNo; /* Used to pass around trace numbers. */ +typedef uint16_t TraceNo1; /* Stored trace number. */ + +/* Type of link. ORDER LJ_TRLINK */ +typedef enum { + LJ_TRLINK_NONE, /* Incomplete trace. No link, yet. */ + LJ_TRLINK_ROOT, /* Link to other root trace. */ + LJ_TRLINK_LOOP, /* Loop to same trace. */ + LJ_TRLINK_TAILREC, /* Tail-recursion. */ + LJ_TRLINK_UPREC, /* Up-recursion. */ + LJ_TRLINK_DOWNREC, /* Down-recursion. */ + LJ_TRLINK_INTERP, /* Fallback to interpreter. */ + LJ_TRLINK_RETURN /* Return to interpreter. */ +} TraceLink; + +/* Trace object. */ +typedef struct GCtrace { + GCHeader; + uint8_t topslot; /* Top stack slot already checked to be allocated. */ + uint8_t linktype; /* Type of link. */ + IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */ + GCRef gclist; + IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */ + IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */ + uint16_t nsnap; /* Number of snapshots. */ + uint16_t nsnapmap; /* Number of snapshot map elements. */ + SnapShot *snap; /* Snapshot array. */ + SnapEntry *snapmap; /* Snapshot map. */ + GCRef startpt; /* Starting prototype. */ + MRef startpc; /* Bytecode PC of starting instruction. */ + BCIns startins; /* Original bytecode of starting instruction. */ + MSize szmcode; /* Size of machine code. */ + MCode *mcode; /* Start of machine code. */ + MSize mcloop; /* Offset of loop start in machine code. */ + uint16_t nchild; /* Number of child traces (root trace only). */ + uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */ + TraceNo1 traceno; /* Trace number. */ + TraceNo1 link; /* Linked trace (or self for loops). */ + TraceNo1 root; /* Root trace of side trace (or 0 for root traces). */ + TraceNo1 nextroot; /* Next root trace for same prototype. */ + TraceNo1 nextside; /* Next side trace of same root trace. */ + uint8_t sinktags; /* Trace has SINK tags. */ + uint8_t unused1; +#ifdef LUAJIT_USE_GDBJIT + void *gdbjit_entry; /* GDB JIT entry. */ +#endif +} GCtrace; + +#define gco2trace(o) check_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o)) +#define traceref(J, n) \ + check_exp((n)>0 && (MSize)(n)sizetrace, (GCtrace *)gcref(J->trace[(n)])) + +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist)); + +static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap) +{ + if (snap+1 == &T->snap[T->nsnap]) + return T->nsnapmap; + else + return (snap+1)->mapofs; +} + +/* Round-robin penalty cache for bytecodes leading to aborted traces. */ +typedef struct HotPenalty { + MRef pc; /* Starting bytecode PC. */ + uint16_t val; /* Penalty value, i.e. hotcount start. */ + uint16_t reason; /* Abort reason (really TraceErr). */ +} HotPenalty; + +#define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */ +#define PENALTY_MIN (36*2) /* Minimum penalty value. */ +#define PENALTY_MAX 60000 /* Maximum penalty value. */ +#define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */ + +/* Round-robin backpropagation cache for narrowing conversions. */ +typedef struct BPropEntry { + IRRef1 key; /* Key: original reference. */ + IRRef1 val; /* Value: reference after conversion. */ + IRRef mode; /* Mode for this entry (currently IRCONV_*). */ +} BPropEntry; + +/* Number of slots for the backpropagation cache. Must be a power of 2. */ +#define BPROP_SLOTS 16 + +/* Scalar evolution analysis cache. */ +typedef struct ScEvEntry { + IRRef1 idx; /* Index reference. */ + IRRef1 start; /* Constant start reference. */ + IRRef1 stop; /* Constant stop reference. */ + IRRef1 step; /* Constant step reference. */ + IRType1 t; /* Scalar type. */ + uint8_t dir; /* Direction. 1: +, 0: -. */ +} ScEvEntry; + +/* 128 bit SIMD constants. */ +enum { + LJ_KSIMD_ABS, + LJ_KSIMD_NEG, + LJ_KSIMD__MAX +}; + +/* Get 16 byte aligned pointer to SIMD constant. */ +#define LJ_KSIMD(J, n) \ + ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15)) + +/* Set/reset flag to activate the SPLIT pass for the current trace. */ +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) +#define lj_needsplit(J) (J->needsplit = 1) +#define lj_resetsplit(J) (J->needsplit = 0) +#else +#define lj_needsplit(J) UNUSED(J) +#define lj_resetsplit(J) UNUSED(J) +#endif + +/* Fold state is used to fold instructions on-the-fly. */ +typedef struct FoldState { + IRIns ins; /* Currently emitted instruction. */ + IRIns left; /* Instruction referenced by left operand. */ + IRIns right; /* Instruction referenced by right operand. */ +} FoldState; + +/* JIT compiler state. */ +typedef struct jit_State { + GCtrace cur; /* Current trace. */ + + lua_State *L; /* Current Lua state. */ + const BCIns *pc; /* Current PC. */ + GCfunc *fn; /* Current function. */ + GCproto *pt; /* Current prototype. */ + TRef *base; /* Current frame base, points into J->slots. */ + + uint32_t flags; /* JIT engine flags. */ + BCReg maxslot; /* Relative to baseslot. */ + BCReg baseslot; /* Current frame base, offset into J->slots. */ + + uint8_t mergesnap; /* Allowed to merge with next snapshot. */ + uint8_t needsnap; /* Need snapshot before recording next bytecode. */ + IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */ + uint8_t bcskip; /* Number of bytecode instructions to skip. */ + + FoldState fold; /* Fold state. */ + + const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */ + MSize bc_extent; /* Extent of the range. */ + + TraceState state; /* Trace compiler state. */ + + int32_t instunroll; /* Unroll counter for instable loops. */ + int32_t loopunroll; /* Unroll counter for loop ops in side traces. */ + int32_t tailcalled; /* Number of successive tailcalls. */ + int32_t framedepth; /* Current frame depth. */ + int32_t retdepth; /* Return frame depth (count of RETF). */ + + MRef k64; /* Pointer to chained array of 64 bit constants. */ + TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */ + + IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */ + IRRef irtoplim; /* Upper limit of instuction buffer (biased). */ + IRRef irbotlim; /* Lower limit of instuction buffer (biased). */ + IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */ + + MSize sizesnap; /* Size of temp. snapshot buffer. */ + SnapShot *snapbuf; /* Temp. snapshot buffer. */ + SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */ + MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ + + PostProc postproc; /* Required post-processing after execution. */ +#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) + int needsplit; /* Need SPLIT pass. */ +#endif + + GCRef *trace; /* Array of traces. */ + TraceNo freetrace; /* Start of scan for next free trace. */ + MSize sizetrace; /* Size of trace array. */ + + IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */ + TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */ + + int32_t param[JIT_P__MAX]; /* JIT engine parameters. */ + + MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */ + + HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ + uint32_t penaltyslot; /* Round-robin index into penalty slots. */ + uint32_t prngstate; /* PRNG state. */ + + BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ + uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ + + ScEvEntry scev; /* Scalar evolution analysis cache slots. */ + + const BCIns *startpc; /* Bytecode PC of starting instruction. */ + TraceNo parent; /* Parent of current side trace (0 for root traces). */ + ExitNo exitno; /* Exit number in parent of current side trace. */ + + BCIns *patchpc; /* PC for pending re-patch. */ + BCIns patchins; /* Instruction for pending re-patch. */ + + int mcprot; /* Protection of current mcode area. */ + MCode *mcarea; /* Base of current mcode area. */ + MCode *mctop; /* Top of current mcode area. */ + MCode *mcbot; /* Bottom of current mcode area. */ + size_t szmcarea; /* Size of current mcode area. */ + size_t szallmcarea; /* Total size of all allocated mcode areas. */ + + TValue errinfo; /* Additional info element for trace errors. */ +} +#if LJ_TARGET_ARM +LJ_ALIGN(16) /* For DISPATCH-relative addresses in assembler part. */ +#endif +jit_State; + +/* Trivial PRNG e.g. used for penalty randomization. */ +static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits) +{ + /* Yes, this LCG is very weak, but that doesn't matter for our use case. */ + J->prngstate = J->prngstate * 1103515245 + 12345; + return J->prngstate >> (32-bits); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.c new file mode 100644 index 0000000..274d93c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.c @@ -0,0 +1,505 @@ +/* +** Lexical analyzer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_lex_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#if LJ_HASFFI +#include "lj_tab.h" +#include "lj_ctype.h" +#include "lj_cdata.h" +#include "lualib.h" +#endif +#include "lj_state.h" +#include "lj_lex.h" +#include "lj_parse.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* Lua lexer token names. */ +static const char *const tokennames[] = { +#define TKSTR1(name) #name, +#define TKSTR2(name, sym) #sym, +TKDEF(TKSTR1, TKSTR2) +#undef TKSTR1 +#undef TKSTR2 + NULL +}; + +/* -- Buffer handling ----------------------------------------------------- */ + +#define char2int(c) ((int)(uint8_t)(c)) +#define next(ls) \ + (ls->current = (ls->n--) > 0 ? char2int(*ls->p++) : fillbuf(ls)) +#define save_and_next(ls) (save(ls, ls->current), next(ls)) +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') +#define END_OF_STREAM (-1) + +static int fillbuf(LexState *ls) +{ + size_t sz; + const char *buf = ls->rfunc(ls->L, ls->rdata, &sz); + if (buf == NULL || sz == 0) return END_OF_STREAM; + ls->n = (MSize)sz - 1; + ls->p = buf; + return char2int(*(ls->p++)); +} + +static LJ_NOINLINE void save_grow(LexState *ls, int c) +{ + MSize newsize; + if (ls->sb.sz >= LJ_MAX_STR/2) + lj_lex_error(ls, 0, LJ_ERR_XELEM); + newsize = ls->sb.sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, newsize); + ls->sb.buf[ls->sb.n++] = (char)c; +} + +static LJ_AINLINE void save(LexState *ls, int c) +{ + if (LJ_UNLIKELY(ls->sb.n + 1 > ls->sb.sz)) + save_grow(ls, c); + else + ls->sb.buf[ls->sb.n++] = (char)c; +} + +static void inclinenumber(LexState *ls) +{ + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= LJ_MAX_LINE) + lj_lex_error(ls, ls->token, LJ_ERR_XLINES); +} + +/* -- Scanner for terminals ----------------------------------------------- */ + +/* Parse a number literal. */ +static void lex_number(LexState *ls, TValue *tv) +{ + StrScanFmt fmt; + int c, xp = 'e'; + lua_assert(lj_char_isdigit(ls->current)); + if ((c = ls->current) == '0') { + save_and_next(ls); + if ((ls->current | 0x20) == 'x') xp = 'p'; + } + while (lj_char_isident(ls->current) || ls->current == '.' || + ((ls->current == '-' || ls->current == '+') && (c | 0x20) == xp)) { + c = ls->current; + save_and_next(ls); + } + save(ls, '\0'); + fmt = lj_strscan_scan((const uint8_t *)ls->sb.buf, tv, + (LJ_DUALNUM ? STRSCAN_OPT_TOINT : STRSCAN_OPT_TONUM) | + (LJ_HASFFI ? (STRSCAN_OPT_LL|STRSCAN_OPT_IMAG) : 0)); + if (LJ_DUALNUM && fmt == STRSCAN_INT) { + setitype(tv, LJ_TISNUM); + } else if (fmt == STRSCAN_NUM) { + /* Already in correct format. */ +#if LJ_HASFFI + } else if (fmt != STRSCAN_ERROR) { + lua_State *L = ls->L; + GCcdata *cd; + lua_assert(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG); + if (!ctype_ctsG(G(L))) { + ptrdiff_t oldtop = savestack(L, L->top); + luaopen_ffi(L); /* Load FFI library on-demand. */ + L->top = restorestack(L, oldtop); + } + if (fmt == STRSCAN_IMAG) { + cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); + ((double *)cdataptr(cd))[0] = 0; + ((double *)cdataptr(cd))[1] = numV(tv); + } else { + cd = lj_cdata_new_(L, fmt==STRSCAN_I64 ? CTID_INT64 : CTID_UINT64, 8); + *(uint64_t *)cdataptr(cd) = tv->u64; + } + lj_parse_keepcdata(ls, tv, cd); +#endif + } else { + lua_assert(fmt == STRSCAN_ERROR); + lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER); + } +} + +static int skip_sep(LexState *ls) +{ + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + +static void read_long_string(LexState *ls, TValue *tv, int sep) +{ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case END_OF_STREAM: + lj_lex_error(ls, TK_eof, tv ? LJ_ERR_XLSTR : LJ_ERR_XLCOM); + break; + case ']': + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ + goto endloop; + } + break; + case '\n': + case '\r': + save(ls, '\n'); + inclinenumber(ls); + if (!tv) lj_str_resetbuf(&ls->sb); /* avoid wasting space */ + break; + default: + if (tv) save_and_next(ls); + else next(ls); + break; + } + } endloop: + if (tv) { + GCstr *str = lj_parse_keepstr(ls, ls->sb.buf + (2 + (MSize)sep), + ls->sb.n - 2*(2 + (MSize)sep)); + setstrV(ls->L, tv, str); + } +} + +static void read_string(LexState *ls, int delim, TValue *tv) +{ + save_and_next(ls); + while (ls->current != delim) { + switch (ls->current) { + case END_OF_STREAM: + lj_lex_error(ls, TK_eof, LJ_ERR_XSTR); + continue; + case '\n': + case '\r': + lj_lex_error(ls, TK_string, LJ_ERR_XSTR); + continue; + case '\\': { + int c = next(ls); /* Skip the '\\'. */ + switch (c) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'x': /* Hexadecimal escape '\xXX'. */ + c = (next(ls) & 15u) << 4; + if (!lj_char_isdigit(ls->current)) { + if (!lj_char_isxdigit(ls->current)) goto err_xesc; + c += 9 << 4; + } + c += (next(ls) & 15u); + if (!lj_char_isdigit(ls->current)) { + if (!lj_char_isxdigit(ls->current)) goto err_xesc; + c += 9; + } + break; + case 'z': /* Skip whitespace. */ + next(ls); + while (lj_char_isspace(ls->current)) + if (currIsNewline(ls)) inclinenumber(ls); else next(ls); + continue; + case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case '\\': case '\"': case '\'': break; + case END_OF_STREAM: continue; + default: + if (!lj_char_isdigit(c)) + goto err_xesc; + c -= '0'; /* Decimal escape '\ddd'. */ + if (lj_char_isdigit(next(ls))) { + c = c*10 + (ls->current - '0'); + if (lj_char_isdigit(next(ls))) { + c = c*10 + (ls->current - '0'); + if (c > 255) { + err_xesc: + lj_lex_error(ls, TK_string, LJ_ERR_XESC); + } + next(ls); + } + } + save(ls, c); + continue; + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + break; + } + } + save_and_next(ls); /* skip delimiter */ + setstrV(ls->L, tv, lj_parse_keepstr(ls, ls->sb.buf + 1, ls->sb.n - 2)); +} + +/* -- Main lexical scanner ------------------------------------------------ */ + +static int llex(LexState *ls, TValue *tv) +{ + lj_str_resetbuf(&ls->sb); + for (;;) { + if (lj_char_isident(ls->current)) { + GCstr *s; + if (lj_char_isdigit(ls->current)) { /* Numeric literal. */ + lex_number(ls, tv); + return TK_number; + } + /* Identifier or reserved word. */ + do { + save_and_next(ls); + } while (lj_char_isident(ls->current)); + s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n); + setstrV(ls->L, tv, s); + if (s->reserved > 0) /* Reserved word? */ + return TK_OFS + s->reserved; + return TK_name; + } + switch (ls->current) { + case '\n': + case '\r': + inclinenumber(ls); + continue; + case ' ': + case '\t': + case '\v': + case '\f': + next(ls); + continue; + case '-': + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + lj_str_resetbuf(&ls->sb); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + lj_str_resetbuf(&ls->sb); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != END_OF_STREAM) + next(ls); + continue; + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, tv, sep); + return TK_string; + } else if (sep == -1) { + return '['; + } else { + lj_lex_error(ls, TK_string, LJ_ERR_XLDELIM); + continue; + } + } + case '=': + next(ls); + if (ls->current != '=') return '='; else { next(ls); return TK_eq; } + case '<': + next(ls); + if (ls->current != '=') return '<'; else { next(ls); return TK_le; } + case '>': + next(ls); + if (ls->current != '=') return '>'; else { next(ls); return TK_ge; } + case '~': + next(ls); + if (ls->current != '=') return '~'; else { next(ls); return TK_ne; } + case ':': + next(ls); + if (ls->current != ':') return ':'; else { next(ls); return TK_label; } + case '"': + case '\'': + read_string(ls, ls->current, tv); + return TK_string; + case '%': + { + lua_const *tm_constlist = ls->L->constlist; + unsigned int i = 0; + if(tm_constlist != NULL) + { + while(tm_constlist->name != NULL) + { + if(tm_constlist->size < ls->n) + { + if(memcmp(ls->p, tm_constlist->name, tm_constlist->size - 1) == 0) + { + for(i = 0; i < tm_constlist->size; i++) + { + save_and_next(ls); + } + tv->n = tm_constlist->vl; + return TK_number; + } + } + tm_constlist++; + } + } + } + case '.': + save_and_next(ls); + if (ls->current == '.') { + next(ls); + if (ls->current == '.') { + next(ls); + return TK_dots; /* ... */ + } + return TK_concat; /* .. */ + } else if (!lj_char_isdigit(ls->current)) { + return '.'; + } else { + lex_number(ls, tv); + return TK_number; + } + case END_OF_STREAM: + return TK_eof; + default: { + int c = ls->current; + next(ls); + return c; /* Single-char tokens (+ - / ...). */ + } + } + } +} + +/* -- Lexer API ----------------------------------------------------------- */ + +/* Setup lexer state. */ +int lj_lex_setup(lua_State *L, LexState *ls) +{ + int header = 0; + ls->L = L; + ls->fs = NULL; + ls->n = 0; + ls->p = NULL; + ls->vstack = NULL; + ls->sizevstack = 0; + ls->vtop = 0; + ls->bcstack = NULL; + ls->sizebcstack = 0; + ls->lookahead = TK_eof; /* No look-ahead token. */ + ls->linenumber = 1; + ls->lastline = 1; + lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); + next(ls); /* Read-ahead first char. */ + if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && + char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ + ls->n -= 2; + ls->p += 2; + next(ls); + header = 1; + } + if (ls->current == '#') { /* Skip POSIX #! header line. */ + do { + next(ls); + if (ls->current == END_OF_STREAM) return 0; + } while (!currIsNewline(ls)); + inclinenumber(ls); + header = 1; + } + if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */ + if (header) { + /* + ** Loading bytecode with an extra header is disabled for security + ** reasons. This may circumvent the usual check for bytecode vs. + ** Lua code by looking at the first char. Since this is a potential + ** security violation no attempt is made to echo the chunkname either. + */ + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD)); + lj_err_throw(L, LUA_ERRSYNTAX); + } + return 1; + } + return 0; +} + +/* Cleanup lexer state. */ +void lj_lex_cleanup(lua_State *L, LexState *ls) +{ + global_State *g = G(L); + lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine); + lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo); + lj_str_freebuf(g, &ls->sb); +} + +void lj_lex_next(LexState *ls) +{ + ls->lastline = ls->linenumber; + if (LJ_LIKELY(ls->lookahead == TK_eof)) { /* No lookahead token? */ + ls->token = llex(ls, &ls->tokenval); /* Get next token. */ + } else { /* Otherwise return lookahead token. */ + ls->token = ls->lookahead; + ls->lookahead = TK_eof; + ls->tokenval = ls->lookaheadval; + } +} + +LexToken lj_lex_lookahead(LexState *ls) +{ + lua_assert(ls->lookahead == TK_eof); + ls->lookahead = llex(ls, &ls->lookaheadval); + return ls->lookahead; +} + +const char *lj_lex_token2str(LexState *ls, LexToken token) +{ + if (token > TK_OFS) + return tokennames[token-TK_OFS-1]; + else if (!lj_char_iscntrl(token)) + return lj_str_pushf(ls->L, "%c", token); + else + return lj_str_pushf(ls->L, "char(%d)", token); +} + +void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...) +{ + const char *tok; + va_list argp; + if (token == 0) { + tok = NULL; + } else if (token == TK_name || token == TK_string || token == TK_number) { + save(ls, '\0'); + tok = ls->sb.buf; + } else { + tok = lj_lex_token2str(ls, token); + } + va_start(argp, em); + lj_err_lex(ls->L, ls->chunkname, tok, ls->linenumber, em, argp); + va_end(argp); +} + +void lj_lex_init(lua_State *L) +{ + uint32_t i; + for (i = 0; i < TK_RESERVED; i++) { + GCstr *s = lj_str_newz(L, tokennames[i]); + fixstring(s); /* Reserved words are never collected. */ + s->reserved = (uint8_t)(i+1); + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.h new file mode 100644 index 0000000..a7ff29a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lex.h @@ -0,0 +1,85 @@ +/* +** Lexical analyzer. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_LEX_H +#define _LJ_LEX_H + +#include + +#include "lj_obj.h" +#include "lj_err.h" + +/* Lua lexer tokens. */ +#define TKDEF(_, __) \ + _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \ + _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \ + _(repeat) _(return) _(then) _(true) _(until) _(while) \ + __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \ + __(label, ::) __(number, ) __(name, ) __(string, ) \ + __(eof, ) + +enum { + TK_OFS = 256, +#define TKENUM1(name) TK_##name, +#define TKENUM2(name, sym) TK_##name, +TKDEF(TKENUM1, TKENUM2) +#undef TKENUM1 +#undef TKENUM2 + TK_RESERVED = TK_while - TK_OFS +}; + +typedef int LexToken; + +/* Combined bytecode ins/line. Only used during bytecode generation. */ +typedef struct BCInsLine { + BCIns ins; /* Bytecode instruction. */ + BCLine line; /* Line number for this bytecode. */ +} BCInsLine; + +/* Info for local variables. Only used during bytecode generation. */ +typedef struct VarInfo { + GCRef name; /* Local variable name or goto/label name. */ + BCPos startpc; /* First point where the local variable is active. */ + BCPos endpc; /* First point where the local variable is dead. */ + uint8_t slot; /* Variable slot. */ + uint8_t info; /* Variable/goto/label info. */ +} VarInfo; + +/* Lua lexer state. */ +typedef struct LexState { + struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */ + struct lua_State *L; /* Lua state. */ + TValue tokenval; /* Current token value. */ + TValue lookaheadval; /* Lookahead token value. */ + int current; /* Current character (charint). */ + LexToken token; /* Current token. */ + LexToken lookahead; /* Lookahead token. */ + MSize n; /* Bytes left in input buffer. */ + const char *p; /* Current position in input buffer. */ + SBuf sb; /* String buffer for tokens. */ + lua_Reader rfunc; /* Reader callback. */ + void *rdata; /* Reader callback data. */ + BCLine linenumber; /* Input line counter. */ + BCLine lastline; /* Line of last token. */ + GCstr *chunkname; /* Current chunk name (interned string). */ + const char *chunkarg; /* Chunk name argument. */ + const char *mode; /* Allow loading bytecode (b) and/or source text (t). */ + VarInfo *vstack; /* Stack for names and extents of local variables. */ + MSize sizevstack; /* Size of variable stack. */ + MSize vtop; /* Top of variable stack. */ + BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */ + MSize sizebcstack; /* Size of bytecode stack. */ + uint32_t level; /* Syntactical nesting level. */ +} LexState; + +LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls); +LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls); +LJ_FUNC void lj_lex_next(LexState *ls); +LJ_FUNC LexToken lj_lex_lookahead(LexState *ls); +LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token); +LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...); +LJ_FUNC void lj_lex_init(lua_State *L); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.c new file mode 100644 index 0000000..76c8a06 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.c @@ -0,0 +1,258 @@ +/* +** Library function support. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_lib_c +#define LUA_CORE + +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_bc.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_strscan.h" +#include "lj_lib.h" + +/* -- Library initialization ---------------------------------------------- */ + +static GCtab *lib_create_table(lua_State *L, const char *libname, int hsize) +{ + if (libname) { + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); + lua_getfield(L, -1, libname); + if (!tvistab(L->top-1)) { + L->top--; + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, hsize) != NULL) + lj_err_callerv(L, LJ_ERR_BADMODN, libname); + settabV(L, L->top, tabV(L->top-1)); + L->top++; + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + L->top--; + settabV(L, L->top-1, tabV(L->top)); + } else { + lua_createtable(L, 0, hsize); + } + return tabV(L->top-1); +} + +void lj_lib_register(lua_State *L, const char *libname, + const uint8_t *p, const lua_CFunction *cf) +{ + GCtab *env = tabref(L->env); + GCfunc *ofn = NULL; + int ffid = *p++; + BCIns *bcff = &L2GG(L)->bcff[*p++]; + GCtab *tab = lib_create_table(L, libname, *p++); + ptrdiff_t tpos = L->top - L->base; + + /* Avoid barriers further down. */ + lj_gc_anybarriert(L, tab); + tab->nomm = 0; + + for (;;) { + uint32_t tag = *p++; + MSize len = tag & LIBINIT_LENMASK; + tag &= LIBINIT_TAGMASK; + if (tag != LIBINIT_STRING) { + const char *name; + MSize nuv = (MSize)(L->top - L->base - tpos); + GCfunc *fn = lj_func_newC(L, nuv, env); + if (nuv) { + L->top = L->base + tpos; + memcpy(fn->c.upvalue, L->top, sizeof(TValue)*nuv); + } + fn->c.ffid = (uint8_t)(ffid++); + name = (const char *)p; + p += len; + if (tag == LIBINIT_CF) + setmref(fn->c.pc, &G(L)->bc_cfunc_int); + else + setmref(fn->c.pc, bcff++); + if (tag == LIBINIT_ASM_) + fn->c.f = ofn->c.f; /* Copy handler from previous function. */ + else + fn->c.f = *cf++; /* Get cf or handler from C function table. */ + if (len) { + /* NOBARRIER: See above for common barrier. */ + setfuncV(L, lj_tab_setstr(L, tab, lj_str_new(L, name, len)), fn); + } + ofn = fn; + } else { + switch (tag | len) { + case LIBINIT_SET: + L->top -= 2; + if (tvisstr(L->top+1) && strV(L->top+1)->len == 0) + env = tabV(L->top); + else /* NOBARRIER: See above for common barrier. */ + copyTV(L, lj_tab_set(L, tab, L->top+1), L->top); + break; + case LIBINIT_NUMBER: + memcpy(&L->top->n, p, sizeof(double)); + L->top++; + p += sizeof(double); + break; + case LIBINIT_COPY: + copyTV(L, L->top, L->top - *p++); + L->top++; + break; + case LIBINIT_LASTCL: + setfuncV(L, L->top++, ofn); + break; + case LIBINIT_FFID: + ffid++; + break; + case LIBINIT_END: + return; + default: + setstrV(L, L->top++, lj_str_new(L, (const char *)p, len)); + p += len; + break; + } + } + } +} + +/* -- Type checks --------------------------------------------------------- */ + +TValue *lj_lib_checkany(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o >= L->top) + lj_err_arg(L, narg, LJ_ERR_NOVAL); + return o; +} + +GCstr *lj_lib_checkstr(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o < L->top) { + if (LJ_LIKELY(tvisstr(o))) { + return strV(o); + } else if (tvisnumber(o)) { + GCstr *s = lj_str_fromnumber(L, o); + setstrV(L, o, s); + return s; + } + } + lj_err_argt(L, narg, LUA_TSTRING); + return NULL; /* unreachable */ +} + +GCstr *lj_lib_optstr(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL; +} + +#if LJ_DUALNUM +void lj_lib_checknumber(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); +} +#endif + +lua_Number lj_lib_checknum(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && + (tvisnumber(o) || (tvisstr(o) && lj_strscan_num(strV(o), o))))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_UNLIKELY(tvisint(o))) { + lua_Number n = (lua_Number)intV(o); + setnumV(o, n); + return n; + } else { + return numV(o); + } +} + +int32_t lj_lib_checkint(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else { + int32_t i = lj_num2int(numV(o)); + if (LJ_DUALNUM) setintV(o, i); + return i; + } +} + +int32_t lj_lib_optint(lua_State *L, int narg, int32_t def) +{ + TValue *o = L->base + narg-1; + return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def; +} + +int32_t lj_lib_checkbit(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && lj_strscan_numberobj(o))) + lj_err_argt(L, narg, LUA_TNUMBER); + if (LJ_LIKELY(tvisint(o))) { + return intV(o); + } else { + int32_t i = lj_num2bit(numV(o)); + if (LJ_DUALNUM) setintV(o, i); + return i; + } +} + +GCfunc *lj_lib_checkfunc(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tvisfunc(o))) + lj_err_argt(L, narg, LUA_TFUNCTION); + return funcV(o); +} + +GCtab *lj_lib_checktab(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (!(o < L->top && tvistab(o))) + lj_err_argt(L, narg, LUA_TTABLE); + return tabV(o); +} + +GCtab *lj_lib_checktabornil(lua_State *L, int narg) +{ + TValue *o = L->base + narg-1; + if (o < L->top) { + if (tvistab(o)) + return tabV(o); + else if (tvisnil(o)) + return NULL; + } + lj_err_arg(L, narg, LJ_ERR_NOTABN); + return NULL; /* unreachable */ +} + +int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst) +{ + GCstr *s = def >= 0 ? lj_lib_optstr(L, narg) : lj_lib_checkstr(L, narg); + if (s) { + const char *opt = strdata(s); + MSize len = s->len; + int i; + for (i = 0; *(const uint8_t *)lst; i++) { + if (*(const uint8_t *)lst == len && memcmp(opt, lst+1, len) == 0) + return i; + lst += 1+*(const uint8_t *)lst; + } + lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt); + } + return def; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.h new file mode 100644 index 0000000..daacb92 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_lib.h @@ -0,0 +1,112 @@ +/* +** Library function support. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_LIB_H +#define _LJ_LIB_H + +#include "lj_obj.h" + +/* +** A fallback handler is called by the assembler VM if the fast path fails: +** +** - too few arguments: unrecoverable. +** - wrong argument type: recoverable, if coercion succeeds. +** - bad argument value: unrecoverable. +** - stack overflow: recoverable, if stack reallocation succeeds. +** - extra handling: recoverable. +** +** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(), +** lj_err_caller() or lj_err_callermsg(). +** The recoverable cases return 0 or the number of results + 1. +** The assembler VM retries the fast path only if 0 is returned. +** This time the fallback must not be called again or it gets stuck in a loop. +*/ + +/* Return values from fallback handler. */ +#define FFH_RETRY 0 +#define FFH_UNREACHABLE FFH_RETRY +#define FFH_RES(n) ((n)+1) +#define FFH_TAILCALL (-1) + +LJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg); +LJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg); +LJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg); +#if LJ_DUALNUM +LJ_FUNC void lj_lib_checknumber(lua_State *L, int narg); +#else +#define lj_lib_checknumber(L, narg) lj_lib_checknum((L), (narg)) +#endif +LJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg); +LJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg); +LJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def); +LJ_FUNC int32_t lj_lib_checkbit(lua_State *L, int narg); +LJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg); +LJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg); +LJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg); +LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst); + +/* Avoid including lj_frame.h. */ +#define lj_lib_upvalue(L, n) \ + (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1]) + +#if LJ_TARGET_WINDOWS +#define lj_lib_checkfpu(L) \ + do { setnumV(L->top++, (lua_Number)1437217655); \ + if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \ + L->top--; } while (0) +#else +#define lj_lib_checkfpu(L) UNUSED(L) +#endif + +/* Push internal function on the stack. */ +static LJ_AINLINE void lj_lib_pushcc(lua_State *L, lua_CFunction f, + int id, int n) +{ + GCfunc *fn; + lua_pushcclosure(L, f, n); + fn = funcV(L->top-1); + fn->c.ffid = (uint8_t)id; + setmref(fn->c.pc, &G(L)->bc_cfunc_int); +} + +#define lj_lib_pushcf(L, fn, id) (lj_lib_pushcc(L, (fn), (id), 0)) + +/* Library function declarations. Scanned by buildvm. */ +#define LJLIB_CF(name) static int lj_cf_##name(lua_State *L) +#define LJLIB_ASM(name) static int lj_ffh_##name(lua_State *L) +#define LJLIB_ASM_(name) +#define LJLIB_SET(name) +#define LJLIB_PUSH(arg) +#define LJLIB_REC(handler) +#define LJLIB_NOREGUV +#define LJLIB_NOREG + +#define LJ_LIB_REG(L, regname, name) \ + lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name) + +LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, + const uint8_t *init, const lua_CFunction *cf); + +/* Library init data tags. */ +#define LIBINIT_LENMASK 0x3f +#define LIBINIT_TAGMASK 0xc0 +#define LIBINIT_CF 0x00 +#define LIBINIT_ASM 0x40 +#define LIBINIT_ASM_ 0x80 +#define LIBINIT_STRING 0xc0 +#define LIBINIT_MAXSTR 0x39 +#define LIBINIT_SET 0xfa +#define LIBINIT_NUMBER 0xfb +#define LIBINIT_COPY 0xfc +#define LIBINIT_LASTCL 0xfd +#define LIBINIT_FFID 0xfe +#define LIBINIT_END 0xff + +/* Exported library functions. */ + +typedef struct RandomState RandomState; +LJ_FUNC uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_load.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_load.c new file mode 100644 index 0000000..98ff430 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_load.c @@ -0,0 +1,183 @@ +/* +** Load and dump code. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include +#include +//#include +#define lj_load_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_func.h" +#include "lj_frame.h" +#include "lj_vm.h" +#include "lj_lex.h" +#include "lj_bcdump.h" +#include "lj_parse.h" + +/* -- Load Lua source code and bytecode ----------------------------------- */ + +static TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud) +{ + LexState *ls = (LexState *)ud; + GCproto *pt; + GCfunc *fn; + int bc; + UNUSED(dummy); + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + bc = lj_lex_setup(L, ls); + if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) { + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE)); + lj_err_throw(L, LUA_ERRSYNTAX); + } + pt = bc ? lj_bcread(ls) : lj_parse(ls); + fn = lj_func_newL_empty(L, pt, tabref(L->env)); + /* Don't combine above/below into one statement. */ + setfuncV(L, L->top++, fn); + return NULL; +} + +LUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data, + const char *chunkname, const char *mode) +{ + LexState ls; + int status; + ls.rfunc = reader; + ls.rdata = data; + ls.chunkarg = chunkname ? chunkname : "?"; + ls.mode = mode; + lj_str_initbuf(&ls.sb); + status = lj_vm_cpcall(L, NULL, &ls, cpparser); + lj_lex_cleanup(L, &ls); + lj_gc_check(L); + return status; +} + +LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, + const char *chunkname) +{ + return lua_loadx(L, reader, data, chunkname, NULL); +} + +typedef struct FileReaderCtx { + FILE *fp; + char buf[LUAL_BUFFERSIZE]; +} FileReaderCtx; + +static const char *reader_file(lua_State *L, void *ud, size_t *size) +{ + FileReaderCtx *ctx = (FileReaderCtx *)ud; + UNUSED(L); + if (feof(ctx->fp)) return NULL; + *size = fread(ctx->buf, 1, sizeof(ctx->buf), ctx->fp); + return *size > 0 ? ctx->buf : NULL; +} +/* +int code_convert(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t outlen) + { + iconv_t cd; + char **pin = &inbuf; + char **pout = &outbuf; + + cd = iconv_open(to_charset,from_charset); + if (cd==0) return -1; + memset(outbuf,0,outlen); + if (iconv(cd,pin,&inlen,pout,&outlen)==-1) return -1; + iconv_close(cd); + return 0; + } +*/ +LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename, + const char *mode) +{ + FileReaderCtx ctx; + int status; + const char *chunkname; + if (filename) { + ctx.fp = fopen(filename, "rb"); + if (ctx.fp == NULL) { + lua_pushfstring(L, "cannot open %s: %s", filename, strerror(errno)); + return LUA_ERRFILE; + } + chunkname = lua_pushfstring(L, "@%s", filename); + } else { + ctx.fp = stdin; + chunkname = "=stdin"; + } + status = lua_loadx(L, reader_file, &ctx, chunkname, mode); + if (ferror(ctx.fp)) { + L->top -= filename ? 2 : 1; + lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno)); + if (filename) + fclose(ctx.fp); + return LUA_ERRFILE; + } + if (filename) { + L->top--; + copyTV(L, L->top-1, L->top); + fclose(ctx.fp); + } + return status; +} + + +LUALIB_API int luaL_loadfile(lua_State *L, const char *filename) +{ + return luaL_loadfilex(L, filename, NULL); +} + +typedef struct StringReaderCtx { + const char *str; + size_t size; +} StringReaderCtx; + +static const char *reader_string(lua_State *L, void *ud, size_t *size) +{ + StringReaderCtx *ctx = (StringReaderCtx *)ud; + UNUSED(L); + if (ctx->size == 0) return NULL; + *size = ctx->size; + ctx->size = 0; + return ctx->str; +} + +LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size, + const char *name, const char *mode) +{ + StringReaderCtx ctx; + ctx.str = buf; + ctx.size = size; + return lua_loadx(L, reader_string, &ctx, name, mode); +} + +LUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size, + const char *name) +{ + return luaL_loadbufferx(L, buf, size, name, NULL); +} + +LUALIB_API int luaL_loadstring(lua_State *L, const char *s) +{ + return luaL_loadbuffer(L, s, strlen(s), s); +} + +/* -- Dump bytecode ------------------------------------------------------- */ + +LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data) +{ + cTValue *o = L->top-1; + api_check(L, L->top > L->base); + if (tvisfunc(o) && isluafunc(funcV(o))) + return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0); + else + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.c new file mode 100644 index 0000000..5a73296 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.c @@ -0,0 +1,373 @@ +/* +** Machine code management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_mcode_c +#define LUA_CORE + +#include "lj_obj.h" +#if LJ_HASJIT +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_jit.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_dispatch.h" +#endif +#if LJ_HASJIT || LJ_HASFFI +#include "lj_vm.h" +#endif + +/* -- OS-specific functions ----------------------------------------------- */ + +#if LJ_HASJIT || LJ_HASFFI + +/* Define this if you want to run LuaJIT with Valgrind. */ +#ifdef LUAJIT_USE_VALGRIND +#include +#endif + +#if LJ_TARGET_IOS +void sys_icache_invalidate(void *start, size_t len); +#endif + +/* Synchronize data/instruction cache. */ +void lj_mcode_sync(void *start, void *end) +{ +#ifdef LUAJIT_USE_VALGRIND + VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start); +#endif +#if LJ_TARGET_X86ORX64 + UNUSED(start); UNUSED(end); +#elif LJ_TARGET_IOS + sys_icache_invalidate(start, (char *)end-(char *)start); +#elif LJ_TARGET_PPC + lj_vm_cachesync(start, end); +#elif defined(__GNUC__) + __clear_cache(start, end); +#else +#error "Missing builtin to flush instruction cache" +#endif +} + +#endif + +#if LJ_HASJIT + +#if LJ_TARGET_WINDOWS + +#define WIN32_LEAN_AND_MEAN +#include + +#define MCPROT_RW PAGE_READWRITE +#define MCPROT_RX PAGE_EXECUTE_READ +#define MCPROT_RWX PAGE_EXECUTE_READWRITE + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, DWORD prot) +{ + void *p = VirtualAlloc((void *)hint, sz, + MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, prot); + if (!p && !hint) + lj_trace_err(J, LJ_TRERR_MCODEAL); + return p; +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + UNUSED(J); UNUSED(sz); + VirtualFree(p, 0, MEM_RELEASE); +} + +static int mcode_setprot(void *p, size_t sz, DWORD prot) +{ + DWORD oprot; + return !VirtualProtect(p, sz, prot, &oprot); +} + +#elif LJ_TARGET_POSIX + +#include + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +#define MCPROT_RW (PROT_READ|PROT_WRITE) +#define MCPROT_RX (PROT_READ|PROT_EXEC) +#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC) + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) +{ + void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) { + if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); + p = NULL; + } + return p; +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + UNUSED(J); + munmap(p, sz); +} + +static int mcode_setprot(void *p, size_t sz, int prot) +{ + return mprotect(p, sz, prot); +} + +#elif LJ_64 + +#error "Missing OS support for explicit placement of executable memory" + +#else + +/* Fallback allocator. This will fail if memory is not executable by default. */ +#define LUAJIT_UNPROTECT_MCODE +#define MCPROT_RW 0 +#define MCPROT_RX 0 +#define MCPROT_RWX 0 + +static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) +{ + UNUSED(hint); UNUSED(prot); + return lj_mem_new(J->L, sz); +} + +static void mcode_free(jit_State *J, void *p, size_t sz) +{ + lj_mem_free(J2G(J), p, sz); +} + +#endif + +/* -- MCode area protection ----------------------------------------------- */ + +/* Define this ONLY if the page protection twiddling becomes a bottleneck. */ +#ifdef LUAJIT_UNPROTECT_MCODE + +/* It's generally considered to be a potential security risk to have +** pages with simultaneous write *and* execute access in a process. +** +** Do not even think about using this mode for server processes or +** apps handling untrusted external data (such as a browser). +** +** The security risk is not in LuaJIT itself -- but if an adversary finds +** any *other* flaw in your C application logic, then any RWX memory page +** simplifies writing an exploit considerably. +*/ +#define MCPROT_GEN MCPROT_RWX +#define MCPROT_RUN MCPROT_RWX + +static void mcode_protect(jit_State *J, int prot) +{ + UNUSED(J); UNUSED(prot); +} + +#else + +/* This is the default behaviour and much safer: +** +** Most of the time the memory pages holding machine code are executable, +** but NONE of them is writable. +** +** The current memory area is marked read-write (but NOT executable) only +** during the short time window while the assembler generates machine code. +*/ +#define MCPROT_GEN MCPROT_RW +#define MCPROT_RUN MCPROT_RX + +/* Protection twiddling failed. Probably due to kernel security. */ +static LJ_NOINLINE void mcode_protfail(jit_State *J) +{ + lua_CFunction panic = J2G(J)->panic; + if (panic) { + lua_State *L = J->L; + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_JITPROT)); + panic(L); + } +} + +/* Change protection of MCode area. */ +static void mcode_protect(jit_State *J, int prot) +{ + if (J->mcprot != prot) { + if (LJ_UNLIKELY(mcode_setprot(J->mcarea, J->szmcarea, prot))) + mcode_protfail(J); + J->mcprot = prot; + } +} + +#endif + +/* -- MCode area allocation ----------------------------------------------- */ + +#if LJ_TARGET_X64 +#define mcode_validptr(p) ((p) && (uintptr_t)(p) < (uintptr_t)1<<47) +#else +#define mcode_validptr(p) ((p) && (uintptr_t)(p) < 0xffff0000) +#endif + +#ifdef LJ_TARGET_JUMPRANGE + +/* Get memory within relative jump distance of our code in 64 bit mode. */ +static void *mcode_alloc(jit_State *J, size_t sz) +{ + /* Target an address in the static assembler code (64K aligned). + ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB. + ** Use half the jump range so every address in the range can reach any other. + */ +#if LJ_TARGET_MIPS + /* Use the middle of the 256MB-aligned region. */ + uintptr_t target = ((uintptr_t)(void *)lj_vm_exit_handler & 0xf0000000u) + + 0x08000000u; +#else + uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; +#endif + const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21); + /* First try a contiguous area below the last one. */ + uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0; + int i; + for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */ + if (mcode_validptr(hint)) { + void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); + + if (mcode_validptr(p) && + ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)) + return p; + if (p) mcode_free(J, p, sz); /* Free badly placed area. */ + } + /* Next try probing pseudo-random addresses. */ + do { + hint = (0x78fb ^ LJ_PRNG_BITS(J, 15)) << 16; /* 64K aligned. */ + } while (!(hint + sz < range)); + hint = target + hint - (range>>1); + } + lj_trace_err(J, LJ_TRERR_MCODEAL); /* Give up. OS probably ignores hints? */ + return NULL; +} + +#else + +/* All memory addresses are reachable by relative jumps. */ +#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN) + +#endif + +/* -- MCode area management ----------------------------------------------- */ + +/* Linked list of MCode areas. */ +typedef struct MCLink { + MCode *next; /* Next area. */ + size_t size; /* Size of current area. */ +} MCLink; + +/* Allocate a new MCode area. */ +static void mcode_allocarea(jit_State *J) +{ + MCode *oldarea = J->mcarea; + size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10; + sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); + J->mcarea = (MCode *)mcode_alloc(J, sz); + J->szmcarea = sz; + J->mcprot = MCPROT_GEN; + J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea); + J->mcbot = (MCode *)((char *)J->mcarea + sizeof(MCLink)); + ((MCLink *)J->mcarea)->next = oldarea; + ((MCLink *)J->mcarea)->size = sz; + J->szallmcarea += sz; +} + +/* Free all MCode areas. */ +void lj_mcode_free(jit_State *J) +{ + MCode *mc = J->mcarea; + J->mcarea = NULL; + J->szallmcarea = 0; + while (mc) { + MCode *next = ((MCLink *)mc)->next; + mcode_free(J, mc, ((MCLink *)mc)->size); + mc = next; + } +} + +/* -- MCode transactions -------------------------------------------------- */ + +/* Reserve the remainder of the current MCode area. */ +MCode *lj_mcode_reserve(jit_State *J, MCode **lim) +{ + if (!J->mcarea) + mcode_allocarea(J); + else + mcode_protect(J, MCPROT_GEN); + *lim = J->mcbot; + return J->mctop; +} + +/* Commit the top part of the current MCode area. */ +void lj_mcode_commit(jit_State *J, MCode *top) +{ + J->mctop = top; + mcode_protect(J, MCPROT_RUN); +} + +/* Abort the reservation. */ +void lj_mcode_abort(jit_State *J) +{ + if (J->mcarea) + mcode_protect(J, MCPROT_RUN); +} + +/* Set/reset protection to allow patching of MCode areas. */ +MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish) +{ +#ifdef LUAJIT_UNPROTECT_MCODE + UNUSED(J); UNUSED(ptr); UNUSED(finish); + return NULL; +#else + if (finish) { + if (J->mcarea == ptr) + mcode_protect(J, MCPROT_RUN); + else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN))) + mcode_protfail(J); + return NULL; + } else { + MCode *mc = J->mcarea; + /* Try current area first to use the protection cache. */ + if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) { + mcode_protect(J, MCPROT_GEN); + return mc; + } + /* Otherwise search through the list of MCode areas. */ + for (;;) { + mc = ((MCLink *)mc)->next; + lua_assert(mc != NULL); + if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) { + if (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN))) + mcode_protfail(J); + return mc; + } + } + } +#endif +} + +/* Limit of MCode reservation reached. */ +void lj_mcode_limiterr(jit_State *J, size_t need) +{ + size_t sizemcode, maxmcode; + lj_mcode_abort(J); + sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10; + sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); + maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10; + if ((size_t)need > sizemcode) + lj_trace_err(J, LJ_TRERR_MCODEOV); /* Too long for any area. */ + if (J->szallmcarea + sizemcode > maxmcode) + lj_trace_err(J, LJ_TRERR_MCODEAL); + mcode_allocarea(J); + lj_trace_err(J, LJ_TRERR_MCODELM); /* Retry with new area. */ +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.h new file mode 100644 index 0000000..89344fc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_mcode.h @@ -0,0 +1,30 @@ +/* +** Machine code management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_MCODE_H +#define _LJ_MCODE_H + +#include "lj_obj.h" + +#if LJ_HASJIT || LJ_HASFFI +LJ_FUNC void lj_mcode_sync(void *start, void *end); +#endif + +#if LJ_HASJIT + +#include "lj_jit.h" + +LJ_FUNC void lj_mcode_free(jit_State *J); +LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim); +LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m); +LJ_FUNC void lj_mcode_abort(jit_State *J); +LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish); +LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need); + +#define lj_mcode_commitbot(J, m) (J->mcbot = (m)) + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.c new file mode 100644 index 0000000..0a52667 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.c @@ -0,0 +1,466 @@ +/* +** Metamethod handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_meta_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* -- Metamethod handling ------------------------------------------------- */ + +/* String interning of metamethod names for fast indexing. */ +void lj_meta_init(lua_State *L) +{ +#define MMNAME(name) "__" #name + const char *metanames = MMDEF(MMNAME); +#undef MMNAME + global_State *g = G(L); + const char *p, *q; + uint32_t mm; + for (mm = 0, p = metanames; *p; mm++, p = q) { + GCstr *s; + for (q = p+2; *q && *q != '_'; q++) ; + s = lj_str_new(L, p, (size_t)(q-p)); + /* NOBARRIER: g->gcroot[] is a GC root. */ + setgcref(g->gcroot[GCROOT_MMNAME+mm], obj2gco(s)); + } +} + +/* Negative caching of a few fast metamethods. See the lj_meta_fast() macro. */ +cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name) +{ + cTValue *mo = lj_tab_getstr(mt, name); + lua_assert(mm <= MM_FAST); + if (!mo || tvisnil(mo)) { /* No metamethod? */ + mt->nomm |= (uint8_t)(1u<metatable); + else if (tvisudata(o)) + mt = tabref(udataV(o)->metatable); + else + mt = tabref(basemt_obj(G(L), o)); + if (mt) { + cTValue *mo = lj_tab_getstr(mt, mmname_str(G(L), mm)); + if (mo) + return mo; + } + return niltv(L); +} + +#if LJ_HASFFI +/* Tailcall from C function. */ +int lj_meta_tailcall(lua_State *L, cTValue *tv) +{ + TValue *base = L->base; + TValue *top = L->top; + const BCIns *pc = frame_pc(base-1); /* Preserve old PC from frame. */ + copyTV(L, base-1, tv); /* Replace frame with new object. */ + top->u32.lo = LJ_CONT_TAILCALL; + setframe_pc(top, pc); + setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */ + setframe_ftsz(top+1, (int)((char *)(top+2) - (char *)base) + FRAME_CONT); + L->base = L->top = top+2; + /* + ** before: [old_mo|PC] [... ...] + ** ^base ^top + ** after: [new_mo|itype] [... ...] [NULL|PC] [dummy|delta] + ** ^base/top + ** tailcall: [new_mo|PC] [... ...] + ** ^base ^top + */ + return 0; +} +#endif + +/* Setup call to metamethod to be run by Assembler VM. */ +static TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo, + cTValue *a, cTValue *b) +{ + /* + ** |-- framesize -> top top+1 top+2 top+3 + ** before: [func slots ...] + ** mm setup: [func slots ...] [cont|?] [mo|tmtype] [a] [b] + ** in asm: [func slots ...] [cont|PC] [mo|delta] [a] [b] + ** ^-- func base ^-- mm base + ** after mm: [func slots ...] [result] + ** ^-- copy to base[PC_RA] --/ for lj_cont_ra + ** istruecond + branch for lj_cont_cond* + ** ignore for lj_cont_nop + ** next PC: [func slots ...] + */ + TValue *top = L->top; + if (curr_funcisL(L)) top = curr_topL(L); + setcont(top, cont); /* Assembler VM stores PC in upper word. */ + copyTV(L, top+1, mo); /* Store metamethod and two arguments. */ + copyTV(L, top+2, a); + copyTV(L, top+3, b); + return top+2; /* Return new base. */ +} + +/* -- C helpers for some instructions, called from assembler VM ----------- */ + +/* Helper for TGET*. __index chain and metamethod. */ +cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k) +{ + int loop; + for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) { + cTValue *mo; + if (LJ_LIKELY(tvistab(o))) { + GCtab *t = tabV(o); + cTValue *tv = lj_tab_get(L, t, k); + if (!tvisnil(tv) || + !(mo = lj_meta_fast(L, tabref(t->metatable), MM_index))) + return tv; + } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_index))) { + lj_err_optype(L, o, LJ_ERR_OPINDEX); + return NULL; /* unreachable */ + } + if (tvisfunc(mo)) { + L->top = mmcall(L, lj_cont_ra, mo, o, k); + return NULL; /* Trigger metamethod call. */ + } + o = mo; + } + lj_err_msg(L, LJ_ERR_GETLOOP); + return NULL; /* unreachable */ +} + +/* Helper for TSET*. __newindex chain and metamethod. */ +TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k) +{ + TValue tmp; + int loop; + for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) { + cTValue *mo; + if (LJ_LIKELY(tvistab(o))) { + GCtab *t = tabV(o); + cTValue *tv = lj_tab_get(L, t, k); + if (LJ_LIKELY(!tvisnil(tv))) { + t->nomm = 0; /* Invalidate negative metamethod cache. */ + lj_gc_anybarriert(L, t); + return (TValue *)tv; + } else if (!(mo = lj_meta_fast(L, tabref(t->metatable), MM_newindex))) { + t->nomm = 0; /* Invalidate negative metamethod cache. */ + lj_gc_anybarriert(L, t); + if (tv != niltv(L)) + return (TValue *)tv; + if (tvisnil(k)) lj_err_msg(L, LJ_ERR_NILIDX); + else if (tvisint(k)) { setnumV(&tmp, (lua_Number)intV(k)); k = &tmp; } + else if (tvisnum(k) && tvisnan(k)) lj_err_msg(L, LJ_ERR_NANIDX); + return lj_tab_newkey(L, t, k); + } + } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_newindex))) { + lj_err_optype(L, o, LJ_ERR_OPINDEX); + return NULL; /* unreachable */ + } + if (tvisfunc(mo)) { + L->top = mmcall(L, lj_cont_nop, mo, o, k); + /* L->top+2 = v filled in by caller. */ + return NULL; /* Trigger metamethod call. */ + } + copyTV(L, &tmp, mo); + o = &tmp; + } + lj_err_msg(L, LJ_ERR_SETLOOP); + return NULL; /* unreachable */ +} + +static cTValue *str2num(cTValue *o, TValue *n) +{ + if (tvisnum(o)) + return o; + else if (tvisint(o)) + return (setnumV(n, (lua_Number)intV(o)), n); + else if (tvisstr(o) && lj_strscan_num(strV(o), n)) + return n; + else + return NULL; +} + +/* Helper for arithmetic instructions. Coercion, metamethod. */ +TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, cTValue *rc, + BCReg op) +{ + MMS mm = bcmode_mm(op); + TValue tempb, tempc; + cTValue *b, *c; + if ((b = str2num(rb, &tempb)) != NULL && + (c = str2num(rc, &tempc)) != NULL) { /* Try coercion first. */ + setnumV(ra, lj_vm_foldarith(numV(b), numV(c), (int)mm-MM_add)); + return NULL; + } else { + cTValue *mo = lj_meta_lookup(L, rb, mm); + if (tvisnil(mo)) { + mo = lj_meta_lookup(L, rc, mm); + if (tvisnil(mo)) { + if (str2num(rb, &tempb) == NULL) rc = rb; + lj_err_optype(L, rc, LJ_ERR_OPARITH); + return NULL; /* unreachable */ + } + } + return mmcall(L, lj_cont_ra, mo, rb, rc); + } +} + +/* In-place coercion of a number to a string. */ +static LJ_AINLINE int tostring(lua_State *L, TValue *o) +{ + if (tvisstr(o)) { + return 1; + } else if (tvisnumber(o)) { + setstrV(L, o, lj_str_fromnumber(L, o)); + return 1; + } else { + return 0; + } +} + +/* Helper for CAT. Coercion, iterative concat, __concat metamethod. */ +TValue *lj_meta_cat(lua_State *L, TValue *top, int left) +{ + int fromc = 0; + if (left < 0) { left = -left; fromc = 1; } + do { + int n = 1; + if (!(tvisstr(top-1) || tvisnumber(top-1)) || !tostring(L, top)) { + cTValue *mo = lj_meta_lookup(L, top-1, MM_concat); + if (tvisnil(mo)) { + mo = lj_meta_lookup(L, top, MM_concat); + if (tvisnil(mo)) { + if (tvisstr(top-1) || tvisnumber(top-1)) top++; + lj_err_optype(L, top-1, LJ_ERR_OPCAT); + return NULL; /* unreachable */ + } + } + /* One of the top two elements is not a string, call __cat metamethod: + ** + ** before: [...][CAT stack .........................] + ** top-1 top top+1 top+2 + ** pick two: [...][CAT stack ...] [o1] [o2] + ** setup mm: [...][CAT stack ...] [cont|?] [mo|tmtype] [o1] [o2] + ** in asm: [...][CAT stack ...] [cont|PC] [mo|delta] [o1] [o2] + ** ^-- func base ^-- mm base + ** after mm: [...][CAT stack ...] <--push-- [result] + ** next step: [...][CAT stack .............] + */ + copyTV(L, top+2, top); /* Careful with the order of stack copies! */ + copyTV(L, top+1, top-1); + copyTV(L, top, mo); + setcont(top-1, lj_cont_cat); + return top+1; /* Trigger metamethod call. */ + } else if (strV(top)->len == 0) { /* Shortcut. */ + (void)tostring(L, top-1); + } else { + /* Pick as many strings as possible from the top and concatenate them: + ** + ** before: [...][CAT stack ...........................] + ** pick str: [...][CAT stack ...] [...... strings ......] + ** concat: [...][CAT stack ...] [result] + ** next step: [...][CAT stack ............] + */ + MSize tlen = strV(top)->len; + char *buffer; + int i; + for (n = 1; n <= left && tostring(L, top-n); n++) { + MSize len = strV(top-n)->len; + if (len >= LJ_MAX_STR - tlen) + lj_err_msg(L, LJ_ERR_STROV); + tlen += len; + } + buffer = lj_str_needbuf(L, &G(L)->tmpbuf, tlen); + n--; + tlen = 0; + for (i = n; i >= 0; i--) { + MSize len = strV(top-i)->len; + memcpy(buffer + tlen, strVdata(top-i), len); + tlen += len; + } + setstrV(L, top-n, lj_str_new(L, buffer, tlen)); + } + left -= n; + top -= n; + } while (left >= 1); + if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) { + if (!fromc) L->top = curr_topL(L); + lj_gc_step(L); + } + return NULL; +} + +/* Helper for LEN. __len metamethod. */ +TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o) +{ + cTValue *mo = lj_meta_lookup(L, o, MM_len); + if (tvisnil(mo)) { + if (LJ_52 && tvistab(o)) + tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<gch.metatable), MM_eq); + if (mo) { + TValue *top; + uint32_t it; + if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) { + cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq); + if (mo2 == NULL || !lj_obj_equal(mo, mo2)) + return (TValue *)(intptr_t)ne; + } + top = curr_top(L); + setcont(top, ne ? lj_cont_condf : lj_cont_condt); + copyTV(L, top+1, mo); + it = ~(uint32_t)o1->gch.gct; + setgcV(L, top+2, o1, it); + setgcV(L, top+3, o2, it); + return top+2; /* Trigger metamethod call. */ + } + return (TValue *)(intptr_t)ne; +} + +#if LJ_HASFFI +TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins) +{ + ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt; + int op = (int)bc_op(ins) & ~1; + TValue tv; + cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)]; + cTValue *o1mm = o1; + if (op == BC_ISEQV) { + o2 = &L->base[bc_d(ins)]; + if (!tviscdata(o1mm)) o1mm = o2; + } else if (op == BC_ISEQS) { + setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins)))); + o2 = &tv; + } else if (op == BC_ISEQN) { + o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)]; + } else { + lua_assert(op == BC_ISEQP); + setitype(&tv, ~bc_d(ins)); + o2 = &tv; + } + mo = lj_meta_lookup(L, o1mm, MM_eq); + if (LJ_LIKELY(!tvisnil(mo))) + return mmcall(L, cont, mo, o1, o2); + else + return (TValue *)(intptr_t)(bc_op(ins) & 1); +} +#endif + +/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */ +TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op) +{ + if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) { + ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt; + MMS mm = (op & 2) ? MM_le : MM_lt; + cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm); + if (LJ_UNLIKELY(tvisnil(mo))) goto err; + return mmcall(L, cont, mo, o1, o2); + } else if (LJ_52 || itype(o1) == itype(o2)) { + /* Never called with two numbers. */ + if (tvisstr(o1) && tvisstr(o2)) { + int32_t res = lj_str_cmp(strV(o1), strV(o2)); + return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1)); + } else { + trymt: + while (1) { + ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt; + MMS mm = (op & 2) ? MM_le : MM_lt; + cTValue *mo = lj_meta_lookup(L, o1, mm); +#if LJ_52 + if (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm)))) +#else + cTValue *mo2 = lj_meta_lookup(L, o2, mm); + if (tvisnil(mo) || !lj_obj_equal(mo, mo2)) +#endif + { + if (op & 2) { /* MM_le not found: retry with MM_lt. */ + cTValue *ot = o1; o1 = o2; o2 = ot; /* Swap operands. */ + op ^= 3; /* Use LT and flip condition. */ + continue; + } + goto err; + } + return mmcall(L, cont, mo, o1, o2); + } + } + } else if (tvisbool(o1) && tvisbool(o2)) { + goto trymt; + } else { + err: + lj_err_comp(L, o1, o2); + return NULL; + } +} + +/* Helper for calls. __call metamethod. */ +void lj_meta_call(lua_State *L, TValue *func, TValue *top) +{ + cTValue *mo = lj_meta_lookup(L, func, MM_call); + TValue *p; + if (!tvisfunc(mo)) + lj_err_optype_call(L, func); + for (p = top; p > func; p--) copyTV(L, p, p-1); + copyTV(L, func, mo); +} + +/* Helper for FORI. Coercion. */ +void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o) +{ + if (!lj_strscan_numberobj(o)) lj_err_msg(L, LJ_ERR_FORINIT); + if (!lj_strscan_numberobj(o+1)) lj_err_msg(L, LJ_ERR_FORLIM); + if (!lj_strscan_numberobj(o+2)) lj_err_msg(L, LJ_ERR_FORSTEP); + if (LJ_DUALNUM) { + /* Ensure all slots are integers or all slots are numbers. */ + int32_t k[3]; + int nint = 0; + ptrdiff_t i; + for (i = 0; i <= 2; i++) { + if (tvisint(o+i)) { + k[i] = intV(o+i); nint++; + } else { + k[i] = lj_num2int(numV(o+i)); nint += ((lua_Number)k[i] == numV(o+i)); + } + } + if (nint == 3) { /* Narrow to integers. */ + setintV(o, k[0]); + setintV(o+1, k[1]); + setintV(o+2, k[2]); + } else if (nint != 0) { /* Widen to numbers. */ + if (tvisint(o)) setnumV(o, (lua_Number)intV(o)); + if (tvisint(o+1)) setnumV(o+1, (lua_Number)intV(o+1)); + if (tvisint(o+2)) setnumV(o+2, (lua_Number)intV(o+2)); + } + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.h new file mode 100644 index 0000000..8d7c2cd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_meta.h @@ -0,0 +1,37 @@ +/* +** Metamethod handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_META_H +#define _LJ_META_H + +#include "lj_obj.h" + +/* Metamethod handling */ +LJ_FUNC void lj_meta_init(lua_State *L); +LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name); +LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm); +#if LJ_HASFFI +LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv); +#endif + +#define lj_meta_fastg(g, mt, mm) \ + ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \ + lj_meta_cache(mt, mm, mmname_str(g, mm))) +#define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm) + +/* C helpers for some instructions, called from assembler VM. */ +LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k); +LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k); +LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, + cTValue *rc, BCReg op); +LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left); +LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o); +LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne); +LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins); +LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op); +LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top); +LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.c new file mode 100644 index 0000000..c7f3bc1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.c @@ -0,0 +1,35 @@ +/* +** Miscellaneous object handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_obj_c +#define LUA_CORE + +#include "lj_obj.h" + +/* Object type names. */ +LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */ + "no value", "nil", "boolean", "userdata", "number", "string", + "table", "function", "userdata", "thread", "proto", "cdata" +}; + +LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */ + "nil", "boolean", "boolean", "userdata", "string", "upval", "thread", + "proto", "function", "trace", "cdata", "table", "userdata", "number" +}; + +/* Compare two objects without calling metamethods. */ +int lj_obj_equal(cTValue *o1, cTValue *o2) +{ + if (itype(o1) == itype(o2)) { + if (tvispri(o1)) + return 1; + if (!tvisnum(o1)) + return gcrefeq(o1->gcr, o2->gcr); + } else if (!tvisnumber(o1) || !tvisnumber(o2)) { + return 0; + } + return numberVnum(o1) == numberVnum(o2); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.h new file mode 100644 index 0000000..d545d07 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_obj.h @@ -0,0 +1,857 @@ +/* +** LuaJIT VM tags, values and objects. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#ifndef _LJ_OBJ_H +#define _LJ_OBJ_H + +#include "lua.h" +#include "lj_def.h" +#include "lj_arch.h" + +/* -- Memory references (32 bit address space) ---------------------------- */ + +/* Memory size. */ +typedef uint32_t MSize; + +/* Memory reference */ +typedef struct MRef { + uint32_t ptr32; /* Pseudo 32 bit pointer. */ +} MRef; + +#define mref(r, t) ((t *)(void *)(uintptr_t)(r).ptr32) + +#define setmref(r, p) ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p)) +#define setmrefr(r, v) ((r).ptr32 = (v).ptr32) + +/* -- GC object references (32 bit address space) ------------------------- */ + +/* GCobj reference */ +typedef struct GCRef { + uint32_t gcptr32; /* Pseudo 32 bit pointer. */ +} GCRef; + +/* Common GC header for all collectable objects. */ +#define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct +/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */ + +#define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32) +#define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32) +#define gcrefu(r) ((r).gcptr32) +#define gcrefi(r) ((int32_t)(r).gcptr32) +#define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32) +#define gcnext(gc) (gcref((gc)->gch.nextgc)) + +#define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch) +#define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i)) +#define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p)) +#define setgcrefnull(r) ((r).gcptr32 = 0) +#define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32) + +/* IMPORTANT NOTE: +** +** All uses of the setgcref* macros MUST be accompanied with a write barrier. +** +** This is to ensure the integrity of the incremental GC. The invariant +** to preserve is that a black object never points to a white object. +** I.e. never store a white object into a field of a black object. +** +** It's ok to LEAVE OUT the write barrier ONLY in the following cases: +** - The source is not a GC object (NULL). +** - The target is a GC root. I.e. everything in global_State. +** - The target is a lua_State field (threads are never black). +** - The target is a stack slot, see setgcV et al. +** - The target is an open upvalue, i.e. pointing to a stack slot. +** - The target is a newly created object (i.e. marked white). But make +** sure nothing invokes the GC inbetween. +** - The target and the source are the same object (self-reference). +** - The target already contains the object (e.g. moving elements around). +** +** The most common case is a store to a stack slot. All other cases where +** a barrier has been omitted are annotated with a NOBARRIER comment. +** +** The same logic applies for stores to table slots (array part or hash +** part). ALL uses of lj_tab_set* require a barrier for the stored value +** *and* the stored key, based on the above rules. In practice this means +** a barrier is needed if *either* of the key or value are a GC object. +** +** It's ok to LEAVE OUT the write barrier in the following special cases: +** - The stored value is nil. The key doesn't matter because it's either +** not resurrected or lj_tab_newkey() will take care of the key barrier. +** - The key doesn't matter if the *previously* stored value is guaranteed +** to be non-nil (because the key is kept alive in the table). +** - The key doesn't matter if it's guaranteed not to be part of the table, +** since lj_tab_newkey() takes care of the key barrier. This applies +** trivially to new tables, but watch out for resurrected keys. Storing +** a nil value leaves the key in the table! +** +** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used +** by the interpreter for all table stores. +** +** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark +** dead keys in tables. The reference is left in, but it's guaranteed to +** be never dereferenced as long as the value is nil. It's ok if the key is +** freed or if any object subsequently gets the same address. +** +** Not destroying dead keys helps to keep key hash slots stable. This avoids +** specialization back-off for HREFK when a value flips between nil and +** non-nil and the GC gets in the way. It also allows safely hoisting +** HREF/HREFK across GC steps. Dead keys are only removed if a table is +** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize. +** +** The trade-off is that a write barrier for tables must take the key into +** account, too. Implicitly resurrecting the key by storing a non-nil value +** may invalidate the incremental GC invariant. +*/ + +/* -- Common type definitions --------------------------------------------- */ + +/* Types for handling bytecodes. Need this here, details in lj_bc.h. */ +typedef uint32_t BCIns; /* Bytecode instruction. */ +typedef uint32_t BCPos; /* Bytecode position. */ +typedef uint32_t BCReg; /* Bytecode register. */ +typedef int32_t BCLine; /* Bytecode line number. */ + +/* Internal assembler functions. Never call these directly from C. */ +typedef void (*ASMFunction)(void); + +/* Resizable string buffer. Need this here, details in lj_str.h. */ +typedef struct SBuf { + char *buf; /* String buffer base. */ + MSize n; /* String buffer length. */ + MSize sz; /* String buffer size. */ +} SBuf; + +/* -- Tags and values ----------------------------------------------------- */ + +/* Frame link. */ +typedef union { + int32_t ftsz; /* Frame type and size of previous frame. */ + MRef pcr; /* Overlaps PC for Lua frames. */ +} FrameLink; + +/* Tagged value. */ +typedef LJ_ALIGN(8) union TValue { + uint64_t u64; /* 64 bit pattern overlaps number. */ + lua_Number n; /* Number object overlaps split tag/value object. */ + struct { + LJ_ENDIAN_LOHI( + union { + GCRef gcr; /* GCobj reference (if any). */ + int32_t i; /* Integer value. */ + }; + , uint32_t it; /* Internal object tag. Must overlap MSW of number. */ + ) + }; + struct { + LJ_ENDIAN_LOHI( + GCRef func; /* Function for next frame (or dummy L). */ + , FrameLink tp; /* Link to previous frame. */ + ) + } fr; + struct { + LJ_ENDIAN_LOHI( + uint32_t lo; /* Lower 32 bits of number. */ + , uint32_t hi; /* Upper 32 bits of number. */ + ) + } u32; +} TValue; + +typedef const TValue cTValue; + +#define tvref(r) (mref(r, TValue)) + +/* More external and GCobj tags for internal objects. */ +#define LAST_TT LUA_TTHREAD +#define LUA_TPROTO (LAST_TT+1) +#define LUA_TCDATA (LAST_TT+2) + +/* Internal object tags. +** +** Internal tags overlap the MSW of a number object (must be a double). +** Interpreted as a double these are special NaNs. The FPU only generates +** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available +** for use as internal tags. Small negative numbers are used to shorten the +** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate). +** +** ---MSW---.---LSW--- +** primitive types | itype | | +** lightuserdata | itype | void * | (32 bit platforms) +** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers) +** GC objects | itype | GCRef | +** int (LJ_DUALNUM)| itype | int | +** number -------double------ +** +** ORDER LJ_T +** Primitive types nil/false/true must be first, lightuserdata next. +** GC objects are at the end, table/userdata must be lowest. +** Also check lj_ir.h for similar ordering constraints. +*/ +#define LJ_TNIL (~0u) +#define LJ_TFALSE (~1u) +#define LJ_TTRUE (~2u) +#define LJ_TLIGHTUD (~3u) +#define LJ_TSTR (~4u) +#define LJ_TUPVAL (~5u) +#define LJ_TTHREAD (~6u) +#define LJ_TPROTO (~7u) +#define LJ_TFUNC (~8u) +#define LJ_TTRACE (~9u) +#define LJ_TCDATA (~10u) +#define LJ_TTAB (~11u) +#define LJ_TUDATA (~12u) +/* This is just the canonical number type used in some places. */ +#define LJ_TNUMX (~13u) + +/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */ +#if LJ_64 +#define LJ_TISNUM 0xfffeffffu +#else +#define LJ_TISNUM LJ_TNUMX +#endif +#define LJ_TISTRUECOND LJ_TFALSE +#define LJ_TISPRI LJ_TTRUE +#define LJ_TISGCV (LJ_TSTR+1) +#define LJ_TISTABUD LJ_TTAB + +/* -- String object ------------------------------------------------------- */ + +/* String object header. String payload follows. */ +typedef struct GCstr { + GCHeader; + uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */ + uint8_t unused; + MSize hash; /* Hash of string. */ + MSize len; /* Size of string. */ +} GCstr; + +#define strref(r) (&gcref((r))->str) +#define strdata(s) ((const char *)((s)+1)) +#define strdatawr(s) ((char *)((s)+1)) +#define strVdata(o) strdata(strV(o)) +#define sizestring(s) (sizeof(struct GCstr)+(s)->len+1) + +/* -- Userdata object ----------------------------------------------------- */ + +/* Userdata object. Payload follows. */ +typedef struct GCudata { + GCHeader; + uint8_t udtype; /* Userdata type. */ + uint8_t unused2; + GCRef env; /* Should be at same offset in GCfunc. */ + MSize len; /* Size of payload. */ + GCRef metatable; /* Must be at same offset in GCtab. */ + uint32_t align1; /* To force 8 byte alignment of the payload. */ +} GCudata; + +/* Userdata types. */ +enum { + UDTYPE_USERDATA, /* Regular userdata. */ + UDTYPE_IO_FILE, /* I/O library FILE. */ + UDTYPE_FFI_CLIB, /* FFI C library namespace. */ + UDTYPE__MAX +}; + +#define uddata(u) ((void *)((u)+1)) +#define sizeudata(u) (sizeof(struct GCudata)+(u)->len) + +/* -- C data object ------------------------------------------------------- */ + +/* C data object. Payload follows. */ +typedef struct GCcdata { + GCHeader; + uint16_t ctypeid; /* C type ID. */ +} GCcdata; + +/* Prepended to variable-sized or realigned C data objects. */ +typedef struct GCcdataVar { + uint16_t offset; /* Offset to allocated memory (relative to GCcdata). */ + uint16_t extra; /* Extra space allocated (incl. GCcdata + GCcdatav). */ + MSize len; /* Size of payload. */ +} GCcdataVar; + +#define cdataptr(cd) ((void *)((cd)+1)) +#define cdataisv(cd) ((cd)->marked & 0x80) +#define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar))) +#define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len) +#define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra) +#define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset)) + +/* -- Prototype object ---------------------------------------------------- */ + +#define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef)) +#define round_nkgc(n) (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1)) + +typedef struct GCproto { + GCHeader; + uint8_t numparams; /* Number of parameters. */ + uint8_t framesize; /* Fixed frame size. */ + MSize sizebc; /* Number of bytecode instructions. */ + GCRef gclist; + MRef k; /* Split constant array (points to the middle). */ + MRef uv; /* Upvalue list. local slot|0x8000 or parent uv idx. */ + MSize sizekgc; /* Number of collectable constants. */ + MSize sizekn; /* Number of lua_Number constants. */ + MSize sizept; /* Total size including colocated arrays. */ + uint8_t sizeuv; /* Number of upvalues. */ + uint8_t flags; /* Miscellaneous flags (see below). */ + uint16_t trace; /* Anchor for chain of root traces. */ + /* ------ The following fields are for debugging/tracebacks only ------ */ + GCRef chunkname; /* Name of the chunk this function was defined in. */ + BCLine firstline; /* First line of the function definition. */ + BCLine numline; /* Number of lines for the function definition. */ + MRef lineinfo; /* Compressed map from bytecode ins. to source line. */ + MRef uvinfo; /* Upvalue names. */ + MRef varinfo; /* Names and compressed extents of local variables. */ +} GCproto; + +/* Flags for prototype. */ +#define PROTO_CHILD 0x01 /* Has child prototypes. */ +#define PROTO_VARARG 0x02 /* Vararg function. */ +#define PROTO_FFI 0x04 /* Uses BC_KCDATA for FFI datatypes. */ +#define PROTO_NOJIT 0x08 /* JIT disabled for this function. */ +#define PROTO_ILOOP 0x10 /* Patched bytecode with ILOOP etc. */ +/* Only used during parsing. */ +#define PROTO_HAS_RETURN 0x20 /* Already emitted a return. */ +#define PROTO_FIXUP_RETURN 0x40 /* Need to fixup emitted returns. */ +/* Top bits used for counting created closures. */ +#define PROTO_CLCOUNT 0x20 /* Base of saturating 3 bit counter. */ +#define PROTO_CLC_BITS 3 +#define PROTO_CLC_POLY (3*PROTO_CLCOUNT) /* Polymorphic threshold. */ + +#define PROTO_UV_LOCAL 0x8000 /* Upvalue for local slot. */ +#define PROTO_UV_IMMUTABLE 0x4000 /* Immutable upvalue. */ + +#define proto_kgc(pt, idx) \ + check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \ + gcref(mref((pt)->k, GCRef)[(idx)])) +#define proto_knumtv(pt, idx) \ + check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)]) +#define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto))) +#define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt))) +#define proto_uv(pt) (mref((pt)->uv, uint16_t)) + +#define proto_chunkname(pt) (strref((pt)->chunkname)) +#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt)))) +#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void)) +#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t)) +#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t)) + +/* -- Upvalue object ------------------------------------------------------ */ + +typedef struct GCupval { + GCHeader; + uint8_t closed; /* Set if closed (i.e. uv->v == &uv->u.value). */ + uint8_t immutable; /* Immutable value. */ + union { + TValue tv; /* If closed: the value itself. */ + struct { /* If open: double linked list, anchored at thread. */ + GCRef prev; + GCRef next; + }; + }; + MRef v; /* Points to stack slot (open) or above (closed). */ + uint32_t dhash; /* Disambiguation hash: dh1 != dh2 => cannot alias. */ +} GCupval; + +#define uvprev(uv_) (&gcref((uv_)->prev)->uv) +#define uvnext(uv_) (&gcref((uv_)->next)->uv) +#define uvval(uv_) (mref((uv_)->v, TValue)) + +/* -- Function object (closures) ------------------------------------------ */ + +/* Common header for functions. env should be at same offset in GCudata. */ +#define GCfuncHeader \ + GCHeader; uint8_t ffid; uint8_t nupvalues; \ + GCRef env; GCRef gclist; MRef pc + +typedef struct GCfuncC { + GCfuncHeader; + lua_CFunction f; /* C function to be called. */ + TValue upvalue[1]; /* Array of upvalues (TValue). */ +} GCfuncC; + +typedef struct GCfuncL { + GCfuncHeader; + GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */ +} GCfuncL; + +typedef union GCfunc { + GCfuncC c; + GCfuncL l; +} GCfunc; + +#define FF_LUA 0 +#define FF_C 1 +#define isluafunc(fn) ((fn)->c.ffid == FF_LUA) +#define iscfunc(fn) ((fn)->c.ffid == FF_C) +#define isffunc(fn) ((fn)->c.ffid > FF_C) +#define funcproto(fn) \ + check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto))) +#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n)) +#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n)) + +/* -- Table object -------------------------------------------------------- */ + +/* Hash node. */ +typedef struct Node { + TValue val; /* Value object. Must be first field. */ + TValue key; /* Key object. */ + MRef next; /* Hash chain. */ + MRef freetop; /* Top of free elements (stored in t->node[0]). */ +} Node; + +LJ_STATIC_ASSERT(offsetof(Node, val) == 0); + +typedef struct GCtab { + GCHeader; + uint8_t nomm; /* Negative cache for fast metamethods. */ + int8_t colo; /* Array colocation. */ + MRef array; /* Array part. */ + GCRef gclist; + GCRef metatable; /* Must be at same offset in GCudata. */ + MRef node; /* Hash part. */ + uint32_t asize; /* Size of array part (keys [0, asize-1]). */ + uint32_t hmask; /* Hash part mask (size of hash part - 1). */ +} GCtab; + +#define sizetabcolo(n) ((n)*sizeof(TValue) + sizeof(GCtab)) +#define tabref(r) (&gcref((r))->tab) +#define noderef(r) (mref((r), Node)) +#define nextnode(n) (mref((n)->next, Node)) + +/* -- State objects ------------------------------------------------------- */ + +/* VM states. */ +enum { + LJ_VMST_INTERP, /* Interpreter. */ + LJ_VMST_C, /* C function. */ + LJ_VMST_GC, /* Garbage collector. */ + LJ_VMST_EXIT, /* Trace exit handler. */ + LJ_VMST_RECORD, /* Trace recorder. */ + LJ_VMST_OPT, /* Optimizer. */ + LJ_VMST_ASM, /* Assembler. */ + LJ_VMST__MAX +}; + +#define setvmstate(g, st) ((g)->vmstate = ~LJ_VMST_##st) + +/* Metamethods. ORDER MM */ +#ifdef LJ_HASFFI +#define MMDEF_FFI(_) _(new) +#else +#define MMDEF_FFI(_) +#endif + +#if LJ_52 || LJ_HASFFI +#define MMDEF_PAIRS(_) _(pairs) _(ipairs) +#else +#define MMDEF_PAIRS(_) +#define MM_pairs 255 +#define MM_ipairs 255 +#endif + +#define MMDEF(_) \ + _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \ + /* Only the above (fast) metamethods are negative cached (max. 8). */ \ + _(lt) _(le) _(concat) _(call) \ + /* The following must be in ORDER ARITH. */ \ + _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \ + /* The following are used in the standard libraries. */ \ + _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_) + +typedef enum { +#define MMENUM(name) MM_##name, +MMDEF(MMENUM) +#undef MMENUM + MM__MAX, + MM____ = MM__MAX, + MM_FAST = MM_len +} MMS; + +/* GC root IDs. */ +typedef enum { + GCROOT_MMNAME, /* Metamethod names. */ + GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1, + GCROOT_BASEMT, /* Metatables for base types. */ + GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX, + GCROOT_IO_INPUT, /* Userdata for default I/O input file. */ + GCROOT_IO_OUTPUT, /* Userdata for default I/O output file. */ + GCROOT_MAX +} GCRootID; + +#define basemt_it(g, it) ((g)->gcroot[GCROOT_BASEMT+~(it)]) +#define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)]) +#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) + +typedef struct GCState { + MSize total; /* Memory currently allocated. */ + MSize threshold; /* Memory threshold. */ + uint8_t currentwhite; /* Current white color. */ + uint8_t state; /* GC state. */ + uint8_t nocdatafin; /* No cdata finalizer called. */ + uint8_t unused2; + MSize sweepstr; /* Sweep position in string table. */ + GCRef root; /* List of all collectable objects. */ + MRef sweep; /* Sweep position in root list. */ + GCRef gray; /* List of gray objects. */ + GCRef grayagain; /* List of objects for atomic traversal. */ + GCRef weak; /* List of weak tables (to be cleared). */ + GCRef mmudata; /* List of userdata (to be finalized). */ + MSize stepmul; /* Incremental GC step granularity. */ + MSize debt; /* Debt (how much GC is behind schedule). */ + MSize estimate; /* Estimate of memory actually in use. */ + MSize pause; /* Pause between successive GC cycles. */ +} GCState; + +/* Global state, shared by all threads of a Lua universe. */ +typedef struct global_State { + GCRef *strhash; /* String hash table (hash chain anchors). */ + MSize strmask; /* String hash mask (size of hash table - 1). */ + MSize strnum; /* Number of strings in hash table. */ + lua_Alloc allocf; /* Memory allocator. */ + void *allocd; /* Memory allocator data. */ + GCState gc; /* Garbage collector. */ + SBuf tmpbuf; /* Temporary buffer for string concatenation. */ + Node nilnode; /* Fallback 1-element hash part (nil key and value). */ + GCstr strempty; /* Empty string. */ + uint8_t stremptyz; /* Zero terminator of empty string. */ + uint8_t hookmask; /* Hook mask. */ + uint8_t dispatchmode; /* Dispatch mode. */ + uint8_t vmevmask; /* VM event mask. */ + GCRef mainthref; /* Link to main thread. */ + TValue registrytv; /* Anchor for registry. */ + TValue tmptv, tmptv2; /* Temporary TValues. */ + GCupval uvhead; /* Head of double-linked list of all open upvalues. */ + int32_t hookcount; /* Instruction hook countdown. */ + int32_t hookcstart; /* Start count for instruction hook counter. */ + lua_Hook hookf; /* Hook function. */ + lua_CFunction wrapf; /* Wrapper for C function calls. */ + lua_CFunction panic; /* Called as a last resort for errors. */ + volatile int32_t vmstate; /* VM state or current JIT code trace number. */ + BCIns bc_cfunc_int; /* Bytecode for internal C function calls. */ + BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */ + GCRef jit_L; /* Current JIT code lua_State or NULL. */ + MRef jit_base; /* Current JIT code L->base. */ + MRef ctype_state; /* Pointer to C type state. */ + GCRef gcroot[GCROOT_MAX]; /* GC roots. */ +} global_State; + +#define mainthread(g) (&gcref(g->mainthref)->th) +#define niltv(L) \ + check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val) +#define niltvg(g) \ + check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val) + +/* Hook management. Hook event masks are defined in lua.h. */ +#define HOOK_EVENTMASK 0x0f +#define HOOK_ACTIVE 0x10 +#define HOOK_ACTIVE_SHIFT 4 +#define HOOK_VMEVENT 0x20 +#define HOOK_GC 0x40 +#define hook_active(g) ((g)->hookmask & HOOK_ACTIVE) +#define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE) +#define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC)) +#define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT)) +#define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE) +#define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK) +#define hook_restore(g, h) \ + ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h)) + +/* Per-thread state object. */ +struct lua_State { + GCHeader; + uint8_t dummy_ffid; /* Fake FF_C for curr_funcisL() on dummy frames. */ + uint8_t status; /* Thread status. */ + MRef glref; /* Link to global state. */ + GCRef gclist; /* GC chain. */ + TValue *base; /* Base of currently executing function. */ + TValue *top; /* First free slot in the stack. */ + MRef maxstack; /* Last free slot in the stack. */ + MRef stack; /* Stack base. */ + GCRef openupval; /* List of open upvalues in the stack. */ + GCRef env; /* Thread environment (table of globals). */ + void *cframe; /* End of C stack frame chain. */ + MSize stacksize; /* True stack size (incl. LJ_STACK_EXTRA). */ + lua_const *constlist; +}; + +#define G(L) (mref(L->glref, global_State)) +#define registry(L) (&G(L)->registrytv) + +/* Macros to access the currently executing (Lua) function. */ +#define curr_func(L) (&gcref((L->base-1)->fr.func)->fn) +#define curr_funcisL(L) (isluafunc(curr_func(L))) +#define curr_proto(L) (funcproto(curr_func(L))) +#define curr_topL(L) (L->base + curr_proto(L)->framesize) +#define curr_top(L) (curr_funcisL(L) ? curr_topL(L) : L->top) + +/* -- GC object definition and conversions -------------------------------- */ + +/* GC header for generic access to common fields of GC objects. */ +typedef struct GChead { + GCHeader; + uint8_t unused1; + uint8_t unused2; + GCRef env; + GCRef gclist; + GCRef metatable; +} GChead; + +/* The env field SHOULD be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env)); +LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env)); + +/* The metatable field MUST be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable)); +LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable)); + +/* The gclist field MUST be at the same offset for all GC objects. */ +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist)); +LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist)); + +typedef union GCobj { + GChead gch; + GCstr str; + GCupval uv; + lua_State th; + GCproto pt; + GCfunc fn; + GCcdata cd; + GCtab tab; + GCudata ud; +} GCobj; + +/* Macros to convert a GCobj pointer into a specific value. */ +#define gco2str(o) check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str) +#define gco2uv(o) check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv) +#define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th) +#define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt) +#define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn) +#define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd) +#define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab) +#define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud) + +/* Macro to convert any collectable object into a GCobj pointer. */ +#define obj2gco(v) ((GCobj *)(v)) + +/* -- TValue getters/setters ---------------------------------------------- */ + +#ifdef LUA_USE_ASSERT +#include "lj_gc.h" +#endif + +/* Macros to test types. */ +#define itype(o) ((o)->it) +#define tvisnil(o) (itype(o) == LJ_TNIL) +#define tvisfalse(o) (itype(o) == LJ_TFALSE) +#define tvistrue(o) (itype(o) == LJ_TTRUE) +#define tvisbool(o) (tvisfalse(o) || tvistrue(o)) +#if LJ_64 +#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2) +#else +#define tvislightud(o) (itype(o) == LJ_TLIGHTUD) +#endif +#define tvisstr(o) (itype(o) == LJ_TSTR) +#define tvisfunc(o) (itype(o) == LJ_TFUNC) +#define tvisthread(o) (itype(o) == LJ_TTHREAD) +#define tvisproto(o) (itype(o) == LJ_TPROTO) +#define tviscdata(o) (itype(o) == LJ_TCDATA) +#define tvistab(o) (itype(o) == LJ_TTAB) +#define tvisudata(o) (itype(o) == LJ_TUDATA) +#define tvisnumber(o) (itype(o) <= LJ_TISNUM) +#define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM) +#define tvisnum(o) (itype(o) < LJ_TISNUM) + +#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND) +#define tvispri(o) (itype(o) >= LJ_TISPRI) +#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */ +#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV)) + +/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */ +#define tvisnan(o) ((o)->n != (o)->n) +#if LJ_64 +#define tviszero(o) (((o)->u64 << 1) == 0) +#else +#define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0) +#endif +#define tvispzero(o) ((o)->u64 == 0) +#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000)) +#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000)) +#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64) + +/* Macros to convert type ids. */ +#if LJ_64 +#define itypemap(o) \ + (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o)) +#else +#define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o)) +#endif + +/* Macros to get tagged values. */ +#define gcval(o) (gcref((o)->gcr)) +#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it)) +#if LJ_64 +#define lightudV(o) \ + check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff))) +#else +#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void)) +#endif +#define gcV(o) check_exp(tvisgcv(o), gcval(o)) +#define strV(o) check_exp(tvisstr(o), &gcval(o)->str) +#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn) +#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th) +#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt) +#define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd) +#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) +#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) +#define numV(o) check_exp(tvisnum(o), (o)->n) +#define intV(o) check_exp(tvisint(o), (int32_t)(o)->i) + +/* Macros to set tagged values. */ +#define setitype(o, i) ((o)->it = (i)) +#define setnilV(o) ((o)->it = LJ_TNIL) +#define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x)) + +static LJ_AINLINE void setlightudV(TValue *o, void *p) +{ +#if LJ_64 + o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48); +#else + setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD); +#endif +} + +#if LJ_64 +#define checklightudptr(L, p) \ + (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p)) +#define setcont(o, f) \ + ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) +#else +#define checklightudptr(L, p) (p) +#define setcont(o, f) setlightudV((o), (void *)(f)) +#endif + +#define tvchecklive(L, o) \ + UNUSED(L), lua_assert(!tvisgcv(o) || \ + ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o)))) + +static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t itype) +{ + setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o); +} + +#define define_setV(name, type, tag) \ +static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \ +{ \ + setgcV(L, o, obj2gco(v), tag); \ +} +define_setV(setstrV, GCstr, LJ_TSTR) +define_setV(setthreadV, lua_State, LJ_TTHREAD) +define_setV(setprotoV, GCproto, LJ_TPROTO) +define_setV(setfuncV, GCfunc, LJ_TFUNC) +define_setV(setcdataV, GCcdata, LJ_TCDATA) +define_setV(settabV, GCtab, LJ_TTAB) +define_setV(setudataV, GCudata, LJ_TUDATA) + +#define setnumV(o, x) ((o)->n = (x)) +#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000)) +#define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000)) +#define setminfV(o) ((o)->u64 = U64x(fff00000,00000000)) + +static LJ_AINLINE void setintV(TValue *o, int32_t i) +{ +#if LJ_DUALNUM + o->i = (uint32_t)i; setitype(o, LJ_TISNUM); +#else + o->n = (lua_Number)i; +#endif +} + +static LJ_AINLINE void setint64V(TValue *o, int64_t i) +{ + if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i)) + setintV(o, (int32_t)i); + else + setnumV(o, (lua_Number)i); +} + +#if LJ_64 +#define setintptrV(o, i) setint64V((o), (i)) +#else +#define setintptrV(o, i) setintV((o), (i)) +#endif + +/* Copy tagged values. */ +static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2) +{ + *o1 = *o2; tvchecklive(L, o1); +} + +/* -- Number to integer conversion ---------------------------------------- */ + +#if LJ_SOFTFP +LJ_ASMF int32_t lj_vm_tobit(double x); +#endif + +static LJ_AINLINE int32_t lj_num2bit(lua_Number n) +{ +#if LJ_SOFTFP + return lj_vm_tobit(n); +#else + TValue o; + o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */ + return (int32_t)o.u32.lo; +#endif +} + +#if LJ_TARGET_X86 && !defined(__SSE2__) +#define lj_num2int(n) lj_num2bit((n)) +#else +#define lj_num2int(n) ((int32_t)(n)) +#endif + +static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) +{ +#ifdef _MSC_VER + if (n >= 9223372036854775808.0) /* They think it's a feature. */ + return (uint64_t)(int64_t)(n - 18446744073709551616.0); + else +#endif + return (uint64_t)n; +} + +static LJ_AINLINE int32_t numberVint(cTValue *o) +{ + if (LJ_LIKELY(tvisint(o))) + return intV(o); + else + return lj_num2int(numV(o)); +} + +static LJ_AINLINE lua_Number numberVnum(cTValue *o) +{ + if (LJ_UNLIKELY(tvisint(o))) + return (lua_Number)intV(o); + else + return numV(o); +} + +/* -- Miscellaneous object handling --------------------------------------- */ + +/* Names and maps for internal and external object tags. */ +LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1]; +LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1]; + +#define lj_typename(o) (lj_obj_itypename[itypemap(o)]) + +/* Compare two objects without calling metamethods. */ +LJ_FUNC int lj_obj_equal(cTValue *o1, cTValue *o2); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_dce.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_dce.c new file mode 100644 index 0000000..be80189 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_dce.c @@ -0,0 +1,77 @@ +/* +** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_dce_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Scan through all snapshots and mark all referenced instructions. */ +static void dce_marksnap(jit_State *J) +{ + SnapNo i, nsnap = J->cur.nsnap; + for (i = 0; i < nsnap; i++) { + SnapShot *snap = &J->cur.snap[i]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (ref >= REF_FIRST) + irt_setmark(IR(ref)->t); + } + } +} + +/* Backwards propagate marks. Replace unused instructions with NOPs. */ +static void dce_propagate(jit_State *J) +{ + IRRef1 *pchain[IR__MAX]; + IRRef ins; + uint32_t i; + for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i]; + for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) { + IRIns *ir = IR(ins); + if (irt_ismarked(ir->t)) { + irt_clearmark(ir->t); + pchain[ir->o] = &ir->prev; + } else if (!ir_sideeff(ir)) { + *pchain[ir->o] = ir->prev; /* Reroute original instruction chain. */ + ir->t.irt = IRT_NIL; + ir->o = IR_NOP; /* Replace instruction with NOP. */ + ir->op1 = ir->op2 = 0; + ir->prev = 0; + continue; + } + if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t); + if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t); + } +} + +/* Dead Code Elimination. +** +** First backpropagate marks for all used instructions. Then replace +** the unused ones with a NOP. Note that compressing the IR to eliminate +** the NOPs does not pay off. +*/ +void lj_opt_dce(jit_State *J) +{ + if ((J->flags & JIT_F_OPT_DCE)) { + dce_marksnap(J); + dce_propagate(J); + } +} + +#undef IR + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_fold.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_fold.c new file mode 100644 index 0000000..8a5b41c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_fold.c @@ -0,0 +1,2297 @@ +/* +** FOLD: Constant Folding, Algebraic Simplifications and Reassociation. +** ABCelim: Array Bounds Check Elimination. +** CSE: Common-Subexpression Elimination. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_fold_c +#define LUA_CORE + +#include + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_carith.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Here's a short description how the FOLD engine processes instructions: +** +** The FOLD engine receives a single instruction stored in fins (J->fold.ins). +** The instruction and its operands are used to select matching fold rules. +** These are applied iteratively until a fixed point is reached. +** +** The 8 bit opcode of the instruction itself plus the opcodes of the +** two instructions referenced by its operands form a 24 bit key +** 'ins left right' (unused operands -> 0, literals -> lowest 8 bits). +** +** This key is used for partial matching against the fold rules. The +** left/right operand fields of the key are successively masked with +** the 'any' wildcard, from most specific to least specific: +** +** ins left right +** ins any right +** ins left any +** ins any any +** +** The masked key is used to lookup a matching fold rule in a semi-perfect +** hash table. If a matching rule is found, the related fold function is run. +** Multiple rules can share the same fold function. A fold rule may return +** one of several special values: +** +** - NEXTFOLD means no folding was applied, because an additional test +** inside the fold function failed. Matching continues against less +** specific fold rules. Finally the instruction is passed on to CSE. +** +** - RETRYFOLD means the instruction was modified in-place. Folding is +** retried as if this instruction had just been received. +** +** All other return values are terminal actions -- no further folding is +** applied: +** +** - INTFOLD(i) returns a reference to the integer constant i. +** +** - LEFTFOLD and RIGHTFOLD return the left/right operand reference +** without emitting an instruction. +** +** - CSEFOLD and EMITFOLD pass the instruction directly to CSE or emit +** it without passing through any further optimizations. +** +** - FAILFOLD, DROPFOLD and CONDFOLD only apply to instructions which have +** no result (e.g. guarded assertions): FAILFOLD means the guard would +** always fail, i.e. the current trace is pointless. DROPFOLD means +** the guard is always true and has been eliminated. CONDFOLD is a +** shortcut for FAILFOLD + cond (i.e. drop if true, otherwise fail). +** +** - Any other return value is interpreted as an IRRef or TRef. This +** can be a reference to an existing or a newly created instruction. +** Only the least-significant 16 bits (IRRef1) are used to form a TRef +** which is finally returned to the caller. +** +** The FOLD engine receives instructions both from the trace recorder and +** substituted instructions from LOOP unrolling. This means all types +** of instructions may end up here, even though the recorder bypasses +** FOLD in some cases. Thus all loads, stores and allocations must have +** an any/any rule to avoid being passed on to CSE. +** +** Carefully read the following requirements before adding or modifying +** any fold rules: +** +** Requirement #1: All fold rules must preserve their destination type. +** +** Consistently use INTFOLD() (KINT result) or lj_ir_knum() (KNUM result). +** Never use lj_ir_knumint() which can have either a KINT or KNUM result. +** +** Requirement #2: Fold rules should not create *new* instructions which +** reference operands *across* PHIs. +** +** E.g. a RETRYFOLD with 'fins->op1 = fleft->op1' is invalid if the +** left operand is a PHI. Then fleft->op1 would point across the PHI +** frontier to an invariant instruction. Adding a PHI for this instruction +** would be counterproductive. The solution is to add a barrier which +** prevents folding across PHIs, i.e. 'PHIBARRIER(fleft)' in this case. +** The only exception is for recurrences with high latencies like +** repeated int->num->int conversions. +** +** One could relax this condition a bit if the referenced instruction is +** a PHI, too. But this often leads to worse code due to excessive +** register shuffling. +** +** Note: returning *existing* instructions (e.g. LEFTFOLD) is ok, though. +** Even returning fleft->op1 would be ok, because a new PHI will added, +** if needed. But again, this leads to excessive register shuffling and +** should be avoided. +** +** Requirement #3: The set of all fold rules must be monotonic to guarantee +** termination. +** +** The goal is optimization, so one primarily wants to add strength-reducing +** rules. This means eliminating an instruction or replacing an instruction +** with one or more simpler instructions. Don't add fold rules which point +** into the other direction. +** +** Some rules (like commutativity) do not directly reduce the strength of +** an instruction, but enable other fold rules (e.g. by moving constants +** to the right operand). These rules must be made unidirectional to avoid +** cycles. +** +** Rule of thumb: the trace recorder expands the IR and FOLD shrinks it. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) +#define fleft (&J->fold.left) +#define fright (&J->fold.right) +#define knumleft (ir_knum(fleft)->n) +#define knumright (ir_knum(fright)->n) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Fold function type. Fastcall on x86 significantly reduces their size. */ +typedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J); + +/* Macros for the fold specs, so buildvm can recognize them. */ +#define LJFOLD(x) +#define LJFOLDX(x) +#define LJFOLDF(name) static TRef LJ_FASTCALL fold_##name(jit_State *J) +/* Note: They must be at the start of a line or buildvm ignores them! */ + +/* Barrier to prevent using operands across PHIs. */ +#define PHIBARRIER(ir) if (irt_isphi((ir)->t)) return NEXTFOLD + +/* Barrier to prevent folding across a GC step. +** GC steps can only happen at the head of a trace and at LOOP. +** And the GC is only driven forward if there is at least one allocation. +*/ +#define gcstep_barrier(J, ref) \ + ((ref) < J->chain[IR_LOOP] && \ + (J->chain[IR_SNEW] || J->chain[IR_XSNEW] || \ + J->chain[IR_TNEW] || J->chain[IR_TDUP] || \ + J->chain[IR_CNEW] || J->chain[IR_CNEWI] || J->chain[IR_TOSTR])) + +/* -- Constant folding for FP numbers ------------------------------------- */ + +LJFOLD(ADD KNUM KNUM) +LJFOLD(SUB KNUM KNUM) +LJFOLD(MUL KNUM KNUM) +LJFOLD(DIV KNUM KNUM) +LJFOLD(NEG KNUM KNUM) +LJFOLD(ABS KNUM KNUM) +LJFOLD(ATAN2 KNUM KNUM) +LJFOLD(LDEXP KNUM KNUM) +LJFOLD(MIN KNUM KNUM) +LJFOLD(MAX KNUM KNUM) +LJFOLDF(kfold_numarith) +{ + lua_Number a = knumleft; + lua_Number b = knumright; + lua_Number y = lj_vm_foldarith(a, b, fins->o - IR_ADD); + return lj_ir_knum(J, y); +} + +LJFOLD(LDEXP KNUM KINT) +LJFOLDF(kfold_ldexp) +{ +#if LJ_TARGET_X86ORX64 + UNUSED(J); + return NEXTFOLD; +#else + return lj_ir_knum(J, ldexp(knumleft, fright->i)); +#endif +} + +LJFOLD(FPMATH KNUM any) +LJFOLDF(kfold_fpmath) +{ + lua_Number a = knumleft; + lua_Number y = lj_vm_foldfpm(a, fins->op2); + return lj_ir_knum(J, y); +} + +LJFOLD(POW KNUM KINT) +LJFOLDF(kfold_numpow) +{ + lua_Number a = knumleft; + lua_Number b = (lua_Number)fright->i; + lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD); + return lj_ir_knum(J, y); +} + +/* Must not use kfold_kref for numbers (could be NaN). */ +LJFOLD(EQ KNUM KNUM) +LJFOLD(NE KNUM KNUM) +LJFOLD(LT KNUM KNUM) +LJFOLD(GE KNUM KNUM) +LJFOLD(LE KNUM KNUM) +LJFOLD(GT KNUM KNUM) +LJFOLD(ULT KNUM KNUM) +LJFOLD(UGE KNUM KNUM) +LJFOLD(ULE KNUM KNUM) +LJFOLD(UGT KNUM KNUM) +LJFOLDF(kfold_numcomp) +{ + return CONDFOLD(lj_ir_numcmp(knumleft, knumright, (IROp)fins->o)); +} + +/* -- Constant folding for 32 bit integers -------------------------------- */ + +static int32_t kfold_intop(int32_t k1, int32_t k2, IROp op) +{ + switch (op) { + case IR_ADD: k1 += k2; break; + case IR_SUB: k1 -= k2; break; + case IR_MUL: k1 *= k2; break; + case IR_MOD: k1 = lj_vm_modi(k1, k2); break; + case IR_NEG: k1 = -k1; break; + case IR_BAND: k1 &= k2; break; + case IR_BOR: k1 |= k2; break; + case IR_BXOR: k1 ^= k2; break; + case IR_BSHL: k1 <<= (k2 & 31); break; + case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 31)); break; + case IR_BSAR: k1 >>= (k2 & 31); break; + case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 31)); break; + case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 31)); break; + case IR_MIN: k1 = k1 < k2 ? k1 : k2; break; + case IR_MAX: k1 = k1 > k2 ? k1 : k2; break; + default: lua_assert(0); break; + } + return k1; +} + +LJFOLD(ADD KINT KINT) +LJFOLD(SUB KINT KINT) +LJFOLD(MUL KINT KINT) +LJFOLD(MOD KINT KINT) +LJFOLD(NEG KINT KINT) +LJFOLD(BAND KINT KINT) +LJFOLD(BOR KINT KINT) +LJFOLD(BXOR KINT KINT) +LJFOLD(BSHL KINT KINT) +LJFOLD(BSHR KINT KINT) +LJFOLD(BSAR KINT KINT) +LJFOLD(BROL KINT KINT) +LJFOLD(BROR KINT KINT) +LJFOLD(MIN KINT KINT) +LJFOLD(MAX KINT KINT) +LJFOLDF(kfold_intarith) +{ + return INTFOLD(kfold_intop(fleft->i, fright->i, (IROp)fins->o)); +} + +LJFOLD(ADDOV KINT KINT) +LJFOLD(SUBOV KINT KINT) +LJFOLD(MULOV KINT KINT) +LJFOLDF(kfold_intovarith) +{ + lua_Number n = lj_vm_foldarith((lua_Number)fleft->i, (lua_Number)fright->i, + fins->o - IR_ADDOV); + int32_t k = lj_num2int(n); + if (n != (lua_Number)k) + return FAILFOLD; + return INTFOLD(k); +} + +LJFOLD(BNOT KINT) +LJFOLDF(kfold_bnot) +{ + return INTFOLD(~fleft->i); +} + +LJFOLD(BSWAP KINT) +LJFOLDF(kfold_bswap) +{ + return INTFOLD((int32_t)lj_bswap((uint32_t)fleft->i)); +} + +LJFOLD(LT KINT KINT) +LJFOLD(GE KINT KINT) +LJFOLD(LE KINT KINT) +LJFOLD(GT KINT KINT) +LJFOLD(ULT KINT KINT) +LJFOLD(UGE KINT KINT) +LJFOLD(ULE KINT KINT) +LJFOLD(UGT KINT KINT) +LJFOLD(ABC KINT KINT) +LJFOLDF(kfold_intcomp) +{ + int32_t a = fleft->i, b = fright->i; + switch ((IROp)fins->o) { + case IR_LT: return CONDFOLD(a < b); + case IR_GE: return CONDFOLD(a >= b); + case IR_LE: return CONDFOLD(a <= b); + case IR_GT: return CONDFOLD(a > b); + case IR_ULT: return CONDFOLD((uint32_t)a < (uint32_t)b); + case IR_UGE: return CONDFOLD((uint32_t)a >= (uint32_t)b); + case IR_ULE: return CONDFOLD((uint32_t)a <= (uint32_t)b); + case IR_ABC: + case IR_UGT: return CONDFOLD((uint32_t)a > (uint32_t)b); + default: lua_assert(0); return FAILFOLD; + } +} + +LJFOLD(UGE any KINT) +LJFOLDF(kfold_intcomp0) +{ + if (fright->i == 0) + return DROPFOLD; + return NEXTFOLD; +} + +/* -- Constant folding for 64 bit integers -------------------------------- */ + +static uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op) +{ + switch (op) { +#if LJ_64 || LJ_HASFFI + case IR_ADD: k1 += k2; break; + case IR_SUB: k1 -= k2; break; +#endif +#if LJ_HASFFI + case IR_MUL: k1 *= k2; break; + case IR_BAND: k1 &= k2; break; + case IR_BOR: k1 |= k2; break; + case IR_BXOR: k1 ^= k2; break; +#endif + default: UNUSED(k2); lua_assert(0); break; + } + return k1; +} + +LJFOLD(ADD KINT64 KINT64) +LJFOLD(SUB KINT64 KINT64) +LJFOLD(MUL KINT64 KINT64) +LJFOLD(BAND KINT64 KINT64) +LJFOLD(BOR KINT64 KINT64) +LJFOLD(BXOR KINT64 KINT64) +LJFOLDF(kfold_int64arith) +{ + return INT64FOLD(kfold_int64arith(ir_k64(fleft)->u64, + ir_k64(fright)->u64, (IROp)fins->o)); +} + +LJFOLD(DIV KINT64 KINT64) +LJFOLD(MOD KINT64 KINT64) +LJFOLD(POW KINT64 KINT64) +LJFOLDF(kfold_int64arith2) +{ +#if LJ_HASFFI + uint64_t k1 = ir_k64(fleft)->u64, k2 = ir_k64(fright)->u64; + if (irt_isi64(fins->t)) { + k1 = fins->o == IR_DIV ? lj_carith_divi64((int64_t)k1, (int64_t)k2) : + fins->o == IR_MOD ? lj_carith_modi64((int64_t)k1, (int64_t)k2) : + lj_carith_powi64((int64_t)k1, (int64_t)k2); + } else { + k1 = fins->o == IR_DIV ? lj_carith_divu64(k1, k2) : + fins->o == IR_MOD ? lj_carith_modu64(k1, k2) : + lj_carith_powu64(k1, k2); + } + return INT64FOLD(k1); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BSHL KINT64 KINT) +LJFOLD(BSHR KINT64 KINT) +LJFOLD(BSAR KINT64 KINT) +LJFOLD(BROL KINT64 KINT) +LJFOLD(BROR KINT64 KINT) +LJFOLDF(kfold_int64shift) +{ +#if LJ_HASFFI || LJ_64 + uint64_t k = ir_k64(fleft)->u64; + int32_t sh = (fright->i & 63); + switch ((IROp)fins->o) { + case IR_BSHL: k <<= sh; break; +#if LJ_HASFFI + case IR_BSHR: k >>= sh; break; + case IR_BSAR: k = (uint64_t)((int64_t)k >> sh); break; + case IR_BROL: k = lj_rol(k, sh); break; + case IR_BROR: k = lj_ror(k, sh); break; +#endif + default: lua_assert(0); break; + } + return INT64FOLD(k); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BNOT KINT64) +LJFOLDF(kfold_bnot64) +{ +#if LJ_HASFFI + return INT64FOLD(~ir_k64(fleft)->u64); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(BSWAP KINT64) +LJFOLDF(kfold_bswap64) +{ +#if LJ_HASFFI + return INT64FOLD(lj_bswap64(ir_k64(fleft)->u64)); +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(LT KINT64 KINT64) +LJFOLD(GE KINT64 KINT64) +LJFOLD(LE KINT64 KINT64) +LJFOLD(GT KINT64 KINT64) +LJFOLD(ULT KINT64 KINT64) +LJFOLD(UGE KINT64 KINT64) +LJFOLD(ULE KINT64 KINT64) +LJFOLD(UGT KINT64 KINT64) +LJFOLDF(kfold_int64comp) +{ +#if LJ_HASFFI + uint64_t a = ir_k64(fleft)->u64, b = ir_k64(fright)->u64; + switch ((IROp)fins->o) { + case IR_LT: return CONDFOLD(a < b); + case IR_GE: return CONDFOLD(a >= b); + case IR_LE: return CONDFOLD(a <= b); + case IR_GT: return CONDFOLD(a > b); + case IR_ULT: return CONDFOLD((uint64_t)a < (uint64_t)b); + case IR_UGE: return CONDFOLD((uint64_t)a >= (uint64_t)b); + case IR_ULE: return CONDFOLD((uint64_t)a <= (uint64_t)b); + case IR_UGT: return CONDFOLD((uint64_t)a > (uint64_t)b); + default: lua_assert(0); return FAILFOLD; + } +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(UGE any KINT64) +LJFOLDF(kfold_int64comp0) +{ +#if LJ_HASFFI + if (ir_k64(fright)->u64 == 0) + return DROPFOLD; + return NEXTFOLD; +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +/* -- Constant folding for strings ---------------------------------------- */ + +LJFOLD(SNEW KKPTR KINT) +LJFOLDF(kfold_snew_kptr) +{ + GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i); + return lj_ir_kstr(J, s); +} + +LJFOLD(SNEW any KINT) +LJFOLDF(kfold_snew_empty) +{ + if (fright->i == 0) + return lj_ir_kstr(J, &J2G(J)->strempty); + return NEXTFOLD; +} + +LJFOLD(STRREF KGC KINT) +LJFOLDF(kfold_strref) +{ + GCstr *str = ir_kstr(fleft); + lua_assert((MSize)fright->i <= str->len); + return lj_ir_kkptr(J, (char *)strdata(str) + fright->i); +} + +LJFOLD(STRREF SNEW any) +LJFOLDF(kfold_strref_snew) +{ + PHIBARRIER(fleft); + if (irref_isk(fins->op2) && fright->i == 0) { + return fleft->op1; /* strref(snew(ptr, len), 0) ==> ptr */ + } else { + /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */ + IRIns *ir = IR(fleft->op1); + IRRef1 str = ir->op1; /* IRIns * is not valid across emitir. */ + lua_assert(ir->o == IR_STRREF); + PHIBARRIER(ir); + fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */ + fins->op1 = str; + fins->ot = IRT(IR_STRREF, IRT_P32); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(CALLN CARG IRCALL_lj_str_cmp) +LJFOLDF(kfold_strcmp) +{ + if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) { + GCstr *a = ir_kstr(IR(fleft->op1)); + GCstr *b = ir_kstr(IR(fleft->op2)); + return INTFOLD(lj_str_cmp(a, b)); + } + return NEXTFOLD; +} + +/* -- Constant folding of pointer arithmetic ------------------------------ */ + +LJFOLD(ADD KGC KINT) +LJFOLD(ADD KGC KINT64) +LJFOLDF(kfold_add_kgc) +{ + GCobj *o = ir_kgc(fleft); +#if LJ_64 + ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64; +#else + ptrdiff_t ofs = fright->i; +#endif +#if LJ_HASFFI + if (irt_iscdata(fleft->t)) { + CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid); + if (ctype_isnum(ct->info) || ctype_isenum(ct->info) || + ctype_isptr(ct->info) || ctype_isfunc(ct->info) || + ctype_iscomplex(ct->info) || ctype_isvector(ct->info)) + return lj_ir_kkptr(J, (char *)o + ofs); + } +#endif + return lj_ir_kptr(J, (char *)o + ofs); +} + +LJFOLD(ADD KPTR KINT) +LJFOLD(ADD KPTR KINT64) +LJFOLD(ADD KKPTR KINT) +LJFOLD(ADD KKPTR KINT64) +LJFOLDF(kfold_add_kptr) +{ + void *p = ir_kptr(fleft); +#if LJ_64 + ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64; +#else + ptrdiff_t ofs = fright->i; +#endif + return lj_ir_kptr_(J, fleft->o, (char *)p + ofs); +} + +LJFOLD(ADD any KGC) +LJFOLD(ADD any KPTR) +LJFOLD(ADD any KKPTR) +LJFOLDF(kfold_add_kright) +{ + if (fleft->o == IR_KINT || fleft->o == IR_KINT64) { + IRRef1 tmp = fins->op1; fins->op1 = fins->op2; fins->op2 = tmp; + return RETRYFOLD; + } + return NEXTFOLD; +} + +/* -- Constant folding of conversions ------------------------------------- */ + +LJFOLD(TOBIT KNUM KNUM) +LJFOLDF(kfold_tobit) +{ + return INTFOLD(lj_num2bit(knumleft)); +} + +LJFOLD(CONV KINT IRCONV_NUM_INT) +LJFOLDF(kfold_conv_kint_num) +{ + return lj_ir_knum(J, (lua_Number)fleft->i); +} + +LJFOLD(CONV KINT IRCONV_NUM_U32) +LJFOLDF(kfold_conv_kintu32_num) +{ + return lj_ir_knum(J, (lua_Number)(uint32_t)fleft->i); +} + +LJFOLD(CONV KINT IRCONV_INT_I8) +LJFOLD(CONV KINT IRCONV_INT_U8) +LJFOLD(CONV KINT IRCONV_INT_I16) +LJFOLD(CONV KINT IRCONV_INT_U16) +LJFOLDF(kfold_conv_kint_ext) +{ + int32_t k = fleft->i; + if ((fins->op2 & IRCONV_SRCMASK) == IRT_I8) k = (int8_t)k; + else if ((fins->op2 & IRCONV_SRCMASK) == IRT_U8) k = (uint8_t)k; + else if ((fins->op2 & IRCONV_SRCMASK) == IRT_I16) k = (int16_t)k; + else k = (uint16_t)k; + return INTFOLD(k); +} + +LJFOLD(CONV KINT IRCONV_I64_INT) +LJFOLD(CONV KINT IRCONV_U64_INT) +LJFOLD(CONV KINT IRCONV_I64_U32) +LJFOLD(CONV KINT IRCONV_U64_U32) +LJFOLDF(kfold_conv_kint_i64) +{ + if ((fins->op2 & IRCONV_SEXT)) + return INT64FOLD((uint64_t)(int64_t)fleft->i); + else + return INT64FOLD((uint64_t)(int64_t)(uint32_t)fleft->i); +} + +LJFOLD(CONV KINT64 IRCONV_NUM_I64) +LJFOLDF(kfold_conv_kint64_num_i64) +{ + return lj_ir_knum(J, (lua_Number)(int64_t)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KINT64 IRCONV_NUM_U64) +LJFOLDF(kfold_conv_kint64_num_u64) +{ + return lj_ir_knum(J, (lua_Number)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KINT64 IRCONV_INT_I64) +LJFOLD(CONV KINT64 IRCONV_U32_I64) +LJFOLDF(kfold_conv_kint64_int_i64) +{ + return INTFOLD((int32_t)ir_kint64(fleft)->u64); +} + +LJFOLD(CONV KNUM IRCONV_INT_NUM) +LJFOLDF(kfold_conv_knum_int_num) +{ + lua_Number n = knumleft; + if (!(fins->op2 & IRCONV_TRUNC)) { + int32_t k = lj_num2int(n); + if (irt_isguard(fins->t) && n != (lua_Number)k) { + /* We're about to create a guard which always fails, like CONV +1.5. + ** Some pathological loops cause this during LICM, e.g.: + ** local x,k,t = 0,1.5,{1,[1.5]=2} + ** for i=1,200 do x = x+ t[k]; k = k == 1 and 1.5 or 1 end + ** assert(x == 300) + */ + return FAILFOLD; + } + return INTFOLD(k); + } else { + return INTFOLD((int32_t)n); + } +} + +LJFOLD(CONV KNUM IRCONV_U32_NUM) +LJFOLDF(kfold_conv_knum_u32_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); +#ifdef _MSC_VER + { /* Workaround for MSVC bug. */ + volatile uint32_t u = (uint32_t)knumleft; + return INTFOLD((int32_t)u); + } +#else + return INTFOLD((int32_t)(uint32_t)knumleft); +#endif +} + +LJFOLD(CONV KNUM IRCONV_I64_NUM) +LJFOLDF(kfold_conv_knum_i64_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); + return INT64FOLD((uint64_t)(int64_t)knumleft); +} + +LJFOLD(CONV KNUM IRCONV_U64_NUM) +LJFOLDF(kfold_conv_knum_u64_num) +{ + lua_assert((fins->op2 & IRCONV_TRUNC)); + return INT64FOLD(lj_num2u64(knumleft)); +} + +LJFOLD(TOSTR KNUM) +LJFOLDF(kfold_tostr_knum) +{ + return lj_ir_kstr(J, lj_str_fromnum(J->L, &knumleft)); +} + +LJFOLD(TOSTR KINT) +LJFOLDF(kfold_tostr_kint) +{ + return lj_ir_kstr(J, lj_str_fromint(J->L, fleft->i)); +} + +LJFOLD(STRTO KGC) +LJFOLDF(kfold_strto) +{ + TValue n; + if (lj_strscan_num(ir_kstr(fleft), &n)) + return lj_ir_knum(J, numV(&n)); + return FAILFOLD; +} + +/* -- Constant folding of equality checks --------------------------------- */ + +/* Don't constant-fold away FLOAD checks against KNULL. */ +LJFOLD(EQ FLOAD KNULL) +LJFOLD(NE FLOAD KNULL) +LJFOLDX(lj_opt_cse) + +/* But fold all other KNULL compares, since only KNULL is equal to KNULL. */ +LJFOLD(EQ any KNULL) +LJFOLD(NE any KNULL) +LJFOLD(EQ KNULL any) +LJFOLD(NE KNULL any) +LJFOLD(EQ KINT KINT) /* Constants are unique, so same refs <==> same value. */ +LJFOLD(NE KINT KINT) +LJFOLD(EQ KINT64 KINT64) +LJFOLD(NE KINT64 KINT64) +LJFOLD(EQ KGC KGC) +LJFOLD(NE KGC KGC) +LJFOLDF(kfold_kref) +{ + return CONDFOLD((fins->op1 == fins->op2) ^ (fins->o == IR_NE)); +} + +/* -- Algebraic shortcuts ------------------------------------------------- */ + +LJFOLD(FPMATH FPMATH IRFPM_FLOOR) +LJFOLD(FPMATH FPMATH IRFPM_CEIL) +LJFOLD(FPMATH FPMATH IRFPM_TRUNC) +LJFOLDF(shortcut_round) +{ + IRFPMathOp op = (IRFPMathOp)fleft->op2; + if (op == IRFPM_FLOOR || op == IRFPM_CEIL || op == IRFPM_TRUNC) + return LEFTFOLD; /* round(round_left(x)) = round_left(x) */ + return NEXTFOLD; +} + +LJFOLD(ABS ABS KNUM) +LJFOLDF(shortcut_left) +{ + return LEFTFOLD; /* f(g(x)) ==> g(x) */ +} + +LJFOLD(ABS NEG KNUM) +LJFOLDF(shortcut_dropleft) +{ + PHIBARRIER(fleft); + fins->op1 = fleft->op1; /* abs(neg(x)) ==> abs(x) */ + return RETRYFOLD; +} + +/* Note: no safe shortcuts with STRTO and TOSTR ("1e2" ==> +100 ==> "100"). */ +LJFOLD(NEG NEG any) +LJFOLD(BNOT BNOT) +LJFOLD(BSWAP BSWAP) +LJFOLDF(shortcut_leftleft) +{ + PHIBARRIER(fleft); /* See above. Fold would be ok, but not beneficial. */ + return fleft->op1; /* f(g(x)) ==> x */ +} + +/* -- FP algebraic simplifications ---------------------------------------- */ + +/* FP arithmetic is tricky -- there's not much to simplify. +** Please note the following common pitfalls before sending "improvements": +** x+0 ==> x is INVALID for x=-0 +** 0-x ==> -x is INVALID for x=+0 +** x*0 ==> 0 is INVALID for x=-0, x=+-Inf or x=NaN +*/ + +LJFOLD(ADD NEG any) +LJFOLDF(simplify_numadd_negx) +{ + PHIBARRIER(fleft); + fins->o = IR_SUB; /* (-a) + b ==> b - a */ + fins->op1 = fins->op2; + fins->op2 = fleft->op1; + return RETRYFOLD; +} + +LJFOLD(ADD any NEG) +LJFOLDF(simplify_numadd_xneg) +{ + PHIBARRIER(fright); + fins->o = IR_SUB; /* a + (-b) ==> a - b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(SUB any KNUM) +LJFOLDF(simplify_numsub_k) +{ + lua_Number n = knumright; + if (n == 0.0) /* x - (+-0) ==> x */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(SUB NEG KNUM) +LJFOLDF(simplify_numsub_negk) +{ + PHIBARRIER(fleft); + fins->op2 = fleft->op1; /* (-x) - k ==> (-k) - x */ + fins->op1 = (IRRef1)lj_ir_knum(J, -knumright); + return RETRYFOLD; +} + +LJFOLD(SUB any NEG) +LJFOLDF(simplify_numsub_xneg) +{ + PHIBARRIER(fright); + fins->o = IR_ADD; /* a - (-b) ==> a + b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(MUL any KNUM) +LJFOLD(DIV any KNUM) +LJFOLDF(simplify_nummuldiv_k) +{ + lua_Number n = knumright; + if (n == 1.0) { /* x o 1 ==> x */ + return LEFTFOLD; + } else if (n == -1.0) { /* x o -1 ==> -x */ + fins->o = IR_NEG; + fins->op2 = (IRRef1)lj_ir_knum_neg(J); + return RETRYFOLD; + } else if (fins->o == IR_MUL && n == 2.0) { /* x * 2 ==> x + x */ + fins->o = IR_ADD; + fins->op2 = fins->op1; + return RETRYFOLD; + } else if (fins->o == IR_DIV) { /* x / 2^k ==> x * 2^-k */ + uint64_t u = ir_knum(fright)->u64; + uint32_t ex = ((uint32_t)(u >> 52) & 0x7ff); + if ((u & U64x(000fffff,ffffffff)) == 0 && ex - 1 < 0x7fd) { + u = (u & ((uint64_t)1 << 63)) | ((uint64_t)(0x7fe - ex) << 52); + fins->o = IR_MUL; /* Multiply by exact reciprocal. */ + fins->op2 = lj_ir_knum_u64(J, u); + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(MUL NEG KNUM) +LJFOLD(DIV NEG KNUM) +LJFOLDF(simplify_nummuldiv_negk) +{ + PHIBARRIER(fleft); + fins->op1 = fleft->op1; /* (-a) o k ==> a o (-k) */ + fins->op2 = (IRRef1)lj_ir_knum(J, -knumright); + return RETRYFOLD; +} + +LJFOLD(MUL NEG NEG) +LJFOLD(DIV NEG NEG) +LJFOLDF(simplify_nummuldiv_negneg) +{ + PHIBARRIER(fleft); + PHIBARRIER(fright); + fins->op1 = fleft->op1; /* (-a) o (-b) ==> a o b */ + fins->op2 = fright->op1; + return RETRYFOLD; +} + +LJFOLD(POW any KINT) +LJFOLDF(simplify_numpow_xk) +{ + int32_t k = fright->i; + TRef ref = fins->op1; + if (k == 0) /* x ^ 0 ==> 1 */ + return lj_ir_knum_one(J); /* Result must be a number, not an int. */ + if (k == 1) /* x ^ 1 ==> x */ + return LEFTFOLD; + if ((uint32_t)(k+65536) > 2*65536u) /* Limit code explosion. */ + return NEXTFOLD; + if (k < 0) { /* x ^ (-k) ==> (1/x) ^ k. */ + ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref); + k = -k; + } + /* Unroll x^k for 1 <= k <= 65536. */ + for (; (k & 1) == 0; k >>= 1) /* Handle leading zeros. */ + ref = emitir(IRTN(IR_MUL), ref, ref); + if ((k >>= 1) != 0) { /* Handle trailing bits. */ + TRef tmp = emitir(IRTN(IR_MUL), ref, ref); + for (; k != 1; k >>= 1) { + if (k & 1) + ref = emitir(IRTN(IR_MUL), ref, tmp); + tmp = emitir(IRTN(IR_MUL), tmp, tmp); + } + ref = emitir(IRTN(IR_MUL), ref, tmp); + } + return ref; +} + +LJFOLD(POW KNUM any) +LJFOLDF(simplify_numpow_kx) +{ + lua_Number n = knumleft; + if (n == 2.0) { /* 2.0 ^ i ==> ldexp(1.0, tonum(i)) */ + fins->o = IR_CONV; +#if LJ_TARGET_X86ORX64 + fins->op1 = fins->op2; + fins->op2 = IRCONV_NUM_INT; + fins->op2 = (IRRef1)lj_opt_fold(J); +#endif + fins->op1 = (IRRef1)lj_ir_knum_one(J); + fins->o = IR_LDEXP; + return RETRYFOLD; + } + return NEXTFOLD; +} + +/* -- Simplify conversions ------------------------------------------------ */ + +LJFOLD(CONV CONV IRCONV_NUM_INT) /* _NUM */ +LJFOLDF(shortcut_conv_num_int) +{ + PHIBARRIER(fleft); + /* Only safe with a guarded conversion to int. */ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_NUM && irt_isguard(fleft->t)) + return fleft->op1; /* f(g(x)) ==> x */ + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_INT_NUM) /* _INT */ +LJFOLD(CONV CONV IRCONV_U32_NUM) /* _U32*/ +LJFOLDF(simplify_conv_int_num) +{ + /* Fold even across PHI to avoid expensive num->int conversions in loop. */ + if ((fleft->op2 & IRCONV_SRCMASK) == + ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) + return fleft->op1; + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_I64_NUM) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U64_NUM) /* _INT or _U32 */ +LJFOLDF(simplify_conv_i64_num) +{ + PHIBARRIER(fleft); + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) { + /* Reduce to a sign-extension. */ + fins->op1 = fleft->op1; + fins->op2 = ((IRT_I64<<5)|IRT_INT|IRCONV_SEXT); + return RETRYFOLD; + } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) { +#if LJ_TARGET_X64 + return fleft->op1; +#else + /* Reduce to a zero-extension. */ + fins->op1 = fleft->op1; + fins->op2 = (IRT_I64<<5)|IRT_U32; + return RETRYFOLD; +#endif + } + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_INT_I64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_INT_U64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U32_I64) /* _INT or _U32 */ +LJFOLD(CONV CONV IRCONV_U32_U64) /* _INT or _U32 */ +LJFOLDF(simplify_conv_int_i64) +{ + int src; + PHIBARRIER(fleft); + src = (fleft->op2 & IRCONV_SRCMASK); + if (src == IRT_INT || src == IRT_U32) { + if (src == ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) { + return fleft->op1; + } else { + fins->op2 = ((fins->op2 & IRCONV_DSTMASK) | src); + fins->op1 = fleft->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(CONV CONV IRCONV_FLOAT_NUM) /* _FLOAT */ +LJFOLDF(simplify_conv_flt_num) +{ + PHIBARRIER(fleft); + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_FLOAT) + return fleft->op1; + return NEXTFOLD; +} + +/* Shortcut TOBIT + IRT_NUM <- IRT_INT/IRT_U32 conversion. */ +LJFOLD(TOBIT CONV KNUM) +LJFOLDF(simplify_tobit_conv) +{ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT || + (fleft->op2 & IRCONV_SRCMASK) == IRT_U32) { + /* Fold even across PHI to avoid expensive num->int conversions in loop. */ + lua_assert(irt_isnum(fleft->t)); + return fleft->op1; + } + return NEXTFOLD; +} + +/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */ +LJFOLD(FPMATH CONV IRFPM_FLOOR) +LJFOLD(FPMATH CONV IRFPM_CEIL) +LJFOLD(FPMATH CONV IRFPM_TRUNC) +LJFOLDF(simplify_floor_conv) +{ + if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT || + (fleft->op2 & IRCONV_SRCMASK) == IRT_U32) + return LEFTFOLD; + return NEXTFOLD; +} + +/* Strength reduction of widening. */ +LJFOLD(CONV any IRCONV_I64_INT) +LJFOLD(CONV any IRCONV_U64_INT) +LJFOLDF(simplify_conv_sext) +{ + IRRef ref = fins->op1; + int64_t ofs = 0; + if (!(fins->op2 & IRCONV_SEXT)) + return NEXTFOLD; + PHIBARRIER(fleft); + if (fleft->o == IR_XLOAD && (irt_isu8(fleft->t) || irt_isu16(fleft->t))) + goto ok_reduce; + if (fleft->o == IR_ADD && irref_isk(fleft->op2)) { + ofs = (int64_t)IR(fleft->op2)->i; + ref = fleft->op1; + } + /* Use scalar evolution analysis results to strength-reduce sign-extension. */ + if (ref == J->scev.idx) { + IRRef lo = J->scev.dir ? J->scev.start : J->scev.stop; + lua_assert(irt_isint(J->scev.t)); + if (lo && IR(lo)->i + ofs >= 0) { + ok_reduce: +#if LJ_TARGET_X64 + /* Eliminate widening. All 32 bit ops do an implicit zero-extension. */ + return LEFTFOLD; +#else + /* Reduce to a (cheaper) zero-extension. */ + fins->op2 &= ~IRCONV_SEXT; + return RETRYFOLD; +#endif + } + } + return NEXTFOLD; +} + +/* Strength reduction of narrowing. */ +LJFOLD(CONV ADD IRCONV_INT_I64) +LJFOLD(CONV SUB IRCONV_INT_I64) +LJFOLD(CONV MUL IRCONV_INT_I64) +LJFOLD(CONV ADD IRCONV_INT_U64) +LJFOLD(CONV SUB IRCONV_INT_U64) +LJFOLD(CONV MUL IRCONV_INT_U64) +LJFOLD(CONV ADD IRCONV_U32_I64) +LJFOLD(CONV SUB IRCONV_U32_I64) +LJFOLD(CONV MUL IRCONV_U32_I64) +LJFOLD(CONV ADD IRCONV_U32_U64) +LJFOLD(CONV SUB IRCONV_U32_U64) +LJFOLD(CONV MUL IRCONV_U32_U64) +LJFOLDF(simplify_conv_narrow) +{ + IROp op = (IROp)fleft->o; + IRType t = irt_type(fins->t); + IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2; + PHIBARRIER(fleft); + op1 = emitir(IRTI(IR_CONV), op1, mode); + op2 = emitir(IRTI(IR_CONV), op2, mode); + fins->ot = IRT(op, t); + fins->op1 = op1; + fins->op2 = op2; + return RETRYFOLD; +} + +/* Special CSE rule for CONV. */ +LJFOLD(CONV any any) +LJFOLDF(cse_conv) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + IRRef op1 = fins->op1, op2 = (fins->op2 & IRCONV_MODEMASK); + uint8_t guard = irt_isguard(fins->t); + IRRef ref = J->chain[IR_CONV]; + while (ref > op1) { + IRIns *ir = IR(ref); + /* Commoning with stronger checks is ok. */ + if (ir->op1 == op1 && (ir->op2 & IRCONV_MODEMASK) == op2 && + irt_isguard(ir->t) >= guard) + return ref; + ref = ir->prev; + } + } + return EMITFOLD; /* No fallthrough to regular CSE. */ +} + +/* FP conversion narrowing. */ +LJFOLD(TOBIT ADD KNUM) +LJFOLD(TOBIT SUB KNUM) +LJFOLD(CONV ADD IRCONV_INT_NUM) +LJFOLD(CONV SUB IRCONV_INT_NUM) +LJFOLD(CONV ADD IRCONV_I64_NUM) +LJFOLD(CONV SUB IRCONV_I64_NUM) +LJFOLDF(narrow_convert) +{ + PHIBARRIER(fleft); + /* Narrowing ignores PHIs and repeating it inside the loop is not useful. */ + if (J->chain[IR_LOOP]) + return NEXTFOLD; + lua_assert(fins->o != IR_CONV || (fins->op2&IRCONV_CONVMASK) != IRCONV_TOBIT); + return lj_opt_narrow_convert(J); +} + +/* -- Integer algebraic simplifications ----------------------------------- */ + +LJFOLD(ADD any KINT) +LJFOLD(ADDOV any KINT) +LJFOLD(SUBOV any KINT) +LJFOLDF(simplify_intadd_k) +{ + if (fright->i == 0) /* i o 0 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(MULOV any KINT) +LJFOLDF(simplify_intmul_k) +{ + if (fright->i == 0) /* i * 0 ==> 0 */ + return RIGHTFOLD; + if (fright->i == 1) /* i * 1 ==> i */ + return LEFTFOLD; + if (fright->i == 2) { /* i * 2 ==> i + i */ + fins->o = IR_ADDOV; + fins->op2 = fins->op1; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(SUB any KINT) +LJFOLDF(simplify_intsub_k) +{ + if (fright->i == 0) /* i - 0 ==> i */ + return LEFTFOLD; + fins->o = IR_ADD; /* i - k ==> i + (-k) */ + fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i); /* Overflow for -2^31 ok. */ + return RETRYFOLD; +} + +LJFOLD(SUB KINT any) +LJFOLD(SUB KINT64 any) +LJFOLDF(simplify_intsub_kleft) +{ + if (fleft->o == IR_KINT ? (fleft->i == 0) : (ir_kint64(fleft)->u64 == 0)) { + fins->o = IR_NEG; /* 0 - i ==> -i */ + fins->op1 = fins->op2; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(ADD any KINT64) +LJFOLDF(simplify_intadd_k64) +{ + if (ir_kint64(fright)->u64 == 0) /* i + 0 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(SUB any KINT64) +LJFOLDF(simplify_intsub_k64) +{ + uint64_t k = ir_kint64(fright)->u64; + if (k == 0) /* i - 0 ==> i */ + return LEFTFOLD; + fins->o = IR_ADD; /* i - k ==> i + (-k) */ + fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k); + return RETRYFOLD; +} + +static TRef simplify_intmul_k(jit_State *J, int32_t k) +{ + /* Note: many more simplifications are possible, e.g. 2^k1 +- 2^k2. + ** But this is mainly intended for simple address arithmetic. + ** Also it's easier for the backend to optimize the original multiplies. + */ + if (k == 1) { /* i * 1 ==> i */ + return LEFTFOLD; + } else if ((k & (k-1)) == 0) { /* i * 2^k ==> i << k */ + fins->o = IR_BSHL; + fins->op2 = lj_ir_kint(J, lj_fls((uint32_t)k)); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MUL any KINT) +LJFOLDF(simplify_intmul_k32) +{ + if (fright->i == 0) /* i * 0 ==> 0 */ + return INTFOLD(0); + else if (fright->i > 0) + return simplify_intmul_k(J, fright->i); + return NEXTFOLD; +} + +LJFOLD(MUL any KINT64) +LJFOLDF(simplify_intmul_k64) +{ + if (ir_kint64(fright)->u64 == 0) /* i * 0 ==> 0 */ + return INT64FOLD(0); +#if LJ_64 + /* NYI: SPLIT for BSHL and 32 bit backend support. */ + else if (ir_kint64(fright)->u64 < 0x80000000u) + return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64); +#endif + return NEXTFOLD; +} + +LJFOLD(MOD any KINT) +LJFOLDF(simplify_intmod_k) +{ + int32_t k = fright->i; + lua_assert(k != 0); + if (k > 0 && (k & (k-1)) == 0) { /* i % (2^k) ==> i & (2^k-1) */ + fins->o = IR_BAND; + fins->op2 = lj_ir_kint(J, k-1); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MOD KINT any) +LJFOLDF(simplify_intmod_kleft) +{ + if (fleft->i == 0) + return INTFOLD(0); + return NEXTFOLD; +} + +LJFOLD(SUB any any) +LJFOLD(SUBOV any any) +LJFOLDF(simplify_intsub) +{ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) /* i - i ==> 0 */ + return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0); + return NEXTFOLD; +} + +LJFOLD(SUB ADD any) +LJFOLDF(simplify_intsubadd_leftcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) /* (i + j) - i ==> j */ + return fleft->op2; + if (fins->op2 == fleft->op2) /* (i + j) - j ==> i */ + return fleft->op1; + } + return NEXTFOLD; +} + +LJFOLD(SUB SUB any) +LJFOLDF(simplify_intsubsub_leftcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) { /* (i - j) - i ==> 0 - j */ + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + fins->op2 = fleft->op2; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(SUB any SUB) +LJFOLDF(simplify_intsubsub_rightcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fright); + if (fins->op1 == fright->op1) /* i - (i - j) ==> j */ + return fright->op2; + } + return NEXTFOLD; +} + +LJFOLD(SUB any ADD) +LJFOLDF(simplify_intsubadd_rightcancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fright); + if (fins->op1 == fright->op1) { /* i - (i + j) ==> 0 - j */ + fins->op2 = fright->op2; + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + return RETRYFOLD; + } + if (fins->op1 == fright->op2) { /* i - (j + i) ==> 0 - j */ + fins->op2 = fright->op1; + fins->op1 = (IRRef1)lj_ir_kint(J, 0); + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(SUB ADD ADD) +LJFOLDF(simplify_intsubaddadd_cancel) +{ + if (!irt_isnum(fins->t)) { + PHIBARRIER(fleft); + PHIBARRIER(fright); + if (fleft->op1 == fright->op1) { /* (i + j1) - (i + j2) ==> j1 - j2 */ + fins->op1 = fleft->op2; + fins->op2 = fright->op2; + return RETRYFOLD; + } + if (fleft->op1 == fright->op2) { /* (i + j1) - (j2 + i) ==> j1 - j2 */ + fins->op1 = fleft->op2; + fins->op2 = fright->op1; + return RETRYFOLD; + } + if (fleft->op2 == fright->op1) { /* (j1 + i) - (i + j2) ==> j1 - j2 */ + fins->op1 = fleft->op1; + fins->op2 = fright->op2; + return RETRYFOLD; + } + if (fleft->op2 == fright->op2) { /* (j1 + i) - (j2 + i) ==> j1 - j2 */ + fins->op1 = fleft->op1; + fins->op2 = fright->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(BAND any KINT) +LJFOLD(BAND any KINT64) +LJFOLDF(simplify_band_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i & 0 ==> 0 */ + return RIGHTFOLD; + if (k == -1) /* i & -1 ==> i */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BOR any KINT) +LJFOLD(BOR any KINT64) +LJFOLDF(simplify_bor_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i | 0 ==> i */ + return LEFTFOLD; + if (k == -1) /* i | -1 ==> -1 */ + return RIGHTFOLD; + return NEXTFOLD; +} + +LJFOLD(BXOR any KINT) +LJFOLD(BXOR any KINT64) +LJFOLDF(simplify_bxor_k) +{ + int64_t k = fright->o == IR_KINT ? (int64_t)fright->i : + (int64_t)ir_k64(fright)->u64; + if (k == 0) /* i xor 0 ==> i */ + return LEFTFOLD; + if (k == -1) { /* i xor -1 ==> ~i */ + fins->o = IR_BNOT; + fins->op2 = 0; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BSHL any KINT) +LJFOLD(BSHR any KINT) +LJFOLD(BSAR any KINT) +LJFOLD(BROL any KINT) +LJFOLD(BROR any KINT) +LJFOLDF(simplify_shift_ik) +{ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = (fright->i & mask); + if (k == 0) /* i o 0 ==> i */ + return LEFTFOLD; + if (k == 1 && fins->o == IR_BSHL) { /* i << 1 ==> i + i */ + fins->o = IR_ADD; + fins->op2 = fins->op1; + return RETRYFOLD; + } + if (k != fright->i) { /* i o k ==> i o (k & mask) */ + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; + } +#ifndef LJ_TARGET_UNIFYROT + if (fins->o == IR_BROR) { /* bror(i, k) ==> brol(i, (-k)&mask) */ + fins->o = IR_BROL; + fins->op2 = (IRRef1)lj_ir_kint(J, (-k)&mask); + return RETRYFOLD; + } +#endif + return NEXTFOLD; +} + +LJFOLD(BSHL any BAND) +LJFOLD(BSHR any BAND) +LJFOLD(BSAR any BAND) +LJFOLD(BROL any BAND) +LJFOLD(BROR any BAND) +LJFOLDF(simplify_shift_andk) +{ + IRIns *irk = IR(fright->op2); + PHIBARRIER(fright); + if ((fins->o < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && + irk->o == IR_KINT) { /* i o (j & mask) ==> i o j */ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = irk->i & mask; + if (k == mask) { + fins->op2 = fright->op1; + return RETRYFOLD; + } + } + return NEXTFOLD; +} + +LJFOLD(BSHL KINT any) +LJFOLD(BSHR KINT any) +LJFOLD(BSHL KINT64 any) +LJFOLD(BSHR KINT64 any) +LJFOLDF(simplify_shift1_ki) +{ + int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i : + (int64_t)ir_k64(fleft)->u64; + if (k == 0) /* 0 o i ==> 0 */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BSAR KINT any) +LJFOLD(BROL KINT any) +LJFOLD(BROR KINT any) +LJFOLD(BSAR KINT64 any) +LJFOLD(BROL KINT64 any) +LJFOLD(BROR KINT64 any) +LJFOLDF(simplify_shift2_ki) +{ + int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i : + (int64_t)ir_k64(fleft)->u64; + if (k == 0 || k == -1) /* 0 o i ==> 0; -1 o i ==> -1 */ + return LEFTFOLD; + return NEXTFOLD; +} + +LJFOLD(BSHL BAND KINT) +LJFOLD(BSHR BAND KINT) +LJFOLD(BROL BAND KINT) +LJFOLD(BROR BAND KINT) +LJFOLDF(simplify_shiftk_andk) +{ + IRIns *irk = IR(fleft->op2); + PHIBARRIER(fleft); + if (irk->o == IR_KINT) { /* (i & k1) o k2 ==> (i o k2) & (k1 o k2) */ + int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o); + fins->op1 = fleft->op1; + fins->op1 = (IRRef1)lj_opt_fold(J); + fins->op2 = (IRRef1)lj_ir_kint(J, k); + fins->ot = IRTI(IR_BAND); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BAND BSHL KINT) +LJFOLD(BAND BSHR KINT) +LJFOLDF(simplify_andk_shiftk) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT && + kfold_intop(-1, irk->i, (IROp)fleft->o) == fright->i) + return LEFTFOLD; /* (i o k1) & k2 ==> i, if (-1 o k1) == k2 */ + return NEXTFOLD; +} + +/* -- Reassociation ------------------------------------------------------- */ + +LJFOLD(ADD ADD KINT) +LJFOLD(MUL MUL KINT) +LJFOLD(BAND BAND KINT) +LJFOLD(BOR BOR KINT) +LJFOLD(BXOR BXOR KINT) +LJFOLDF(reassoc_intarith_k) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT) { + int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o); + if (k == irk->i) /* (i o k1) o k2 ==> i o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */ + } + return NEXTFOLD; +} + +LJFOLD(ADD ADD KINT64) +LJFOLD(MUL MUL KINT64) +LJFOLD(BAND BAND KINT64) +LJFOLD(BOR BOR KINT64) +LJFOLD(BXOR BXOR KINT64) +LJFOLDF(reassoc_intarith_k64) +{ +#if LJ_HASFFI || LJ_64 + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KINT64) { + uint64_t k = kfold_int64arith(ir_k64(irk)->u64, + ir_k64(fright)->u64, (IROp)fins->o); + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint64(J, k); + return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */ + } + return NEXTFOLD; +#else + UNUSED(J); lua_assert(0); return FAILFOLD; +#endif +} + +LJFOLD(MIN MIN any) +LJFOLD(MAX MAX any) +LJFOLD(BAND BAND any) +LJFOLD(BOR BOR any) +LJFOLDF(reassoc_dup) +{ + if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2) + return LEFTFOLD; /* (a o b) o a ==> a o b; (a o b) o b ==> a o b */ + return NEXTFOLD; +} + +LJFOLD(BXOR BXOR any) +LJFOLDF(reassoc_bxor) +{ + PHIBARRIER(fleft); + if (fins->op2 == fleft->op1) /* (a xor b) xor a ==> b */ + return fleft->op2; + if (fins->op2 == fleft->op2) /* (a xor b) xor b ==> a */ + return fleft->op1; + return NEXTFOLD; +} + +LJFOLD(BSHL BSHL KINT) +LJFOLD(BSHR BSHR KINT) +LJFOLD(BSAR BSAR KINT) +LJFOLD(BROL BROL KINT) +LJFOLD(BROR BROR KINT) +LJFOLDF(reassoc_shift) +{ + IRIns *irk = IR(fleft->op2); + PHIBARRIER(fleft); /* The (shift any KINT) rule covers k2 == 0 and more. */ + if (irk->o == IR_KINT) { /* (i o k1) o k2 ==> i o (k1 + k2) */ + int32_t mask = irt_is64(fins->t) ? 63 : 31; + int32_t k = (irk->i & mask) + (fright->i & mask); + if (k > mask) { /* Combined shift too wide? */ + if (fins->o == IR_BSHL || fins->o == IR_BSHR) + return mask == 31 ? INTFOLD(0) : INT64FOLD(0); + else if (fins->o == IR_BSAR) + k = mask; + else + k &= mask; + } + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, k); + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(MIN MIN KNUM) +LJFOLD(MAX MAX KNUM) +LJFOLD(MIN MIN KINT) +LJFOLD(MAX MAX KINT) +LJFOLDF(reassoc_minmax_k) +{ + IRIns *irk = IR(fleft->op2); + if (irk->o == IR_KNUM) { + lua_Number a = ir_knum(irk)->n; + lua_Number y = lj_vm_foldarith(a, knumright, fins->o - IR_ADD); + if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_knum(J, y); + return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */ + } else if (irk->o == IR_KINT) { + int32_t a = irk->i; + int32_t y = kfold_intop(a, fright->i, fins->o); + if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */ + return LEFTFOLD; + PHIBARRIER(fleft); + fins->op1 = fleft->op1; + fins->op2 = (IRRef1)lj_ir_kint(J, y); + return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */ + } + return NEXTFOLD; +} + +LJFOLD(MIN MAX any) +LJFOLD(MAX MIN any) +LJFOLDF(reassoc_minmax_left) +{ + if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2) + return RIGHTFOLD; /* (b o1 a) o2 b ==> b; (a o1 b) o2 b ==> b */ + return NEXTFOLD; +} + +LJFOLD(MIN any MAX) +LJFOLD(MAX any MIN) +LJFOLDF(reassoc_minmax_right) +{ + if (fins->op1 == fright->op1 || fins->op1 == fright->op2) + return LEFTFOLD; /* a o2 (a o1 b) ==> a; a o2 (b o1 a) ==> a */ + return NEXTFOLD; +} + +/* -- Array bounds check elimination -------------------------------------- */ + +/* Eliminate ABC across PHIs to handle t[i-1] forwarding case. +** ABC(asize, (i+k)+(-k)) ==> ABC(asize, i), but only if it already exists. +** Could be generalized to (i+k1)+k2 ==> i+(k1+k2), but needs better disambig. +*/ +LJFOLD(ABC any ADD) +LJFOLDF(abc_fwd) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { + if (irref_isk(fright->op2)) { + IRIns *add2 = IR(fright->op1); + if (add2->o == IR_ADD && irref_isk(add2->op2) && + IR(fright->op2)->i == -IR(add2->op2)->i) { + IRRef ref = J->chain[IR_ABC]; + IRRef lim = add2->op1; + if (fins->op1 > lim) lim = fins->op1; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == fins->op1 && ir->op2 == add2->op1) + return DROPFOLD; + ref = ir->prev; + } + } + } + } + return NEXTFOLD; +} + +/* Eliminate ABC for constants. +** ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2)) +** Drop second ABC if k2 is lower. Otherwise patch first ABC with k2. +*/ +LJFOLD(ABC any KINT) +LJFOLDF(abc_k) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { + IRRef ref = J->chain[IR_ABC]; + IRRef asize = fins->op1; + while (ref > asize) { + IRIns *ir = IR(ref); + if (ir->op1 == asize && irref_isk(ir->op2)) { + int32_t k = IR(ir->op2)->i; + if (fright->i > k) + ir->op2 = fins->op2; + return DROPFOLD; + } + ref = ir->prev; + } + return EMITFOLD; /* Already performed CSE. */ + } + return NEXTFOLD; +} + +/* Eliminate invariant ABC inside loop. */ +LJFOLD(ABC any any) +LJFOLDF(abc_invar) +{ + /* Invariant ABC marked as PTR. Drop if op1 is invariant, too. */ + if (!irt_isint(fins->t) && fins->op1 < J->chain[IR_LOOP] && + !irt_isphi(IR(fins->op1)->t)) + return DROPFOLD; + return NEXTFOLD; +} + +/* -- Commutativity ------------------------------------------------------- */ + +/* The refs of commutative ops are canonicalized. Lower refs go to the right. +** Rationale behind this: +** - It (also) moves constants to the right. +** - It reduces the number of FOLD rules (e.g. (BOR any KINT) suffices). +** - It helps CSE to find more matches. +** - The assembler generates better code with constants at the right. +*/ + +LJFOLD(ADD any any) +LJFOLD(MUL any any) +LJFOLD(ADDOV any any) +LJFOLD(MULOV any any) +LJFOLDF(comm_swap) +{ + if (fins->op1 < fins->op2) { /* Move lower ref to the right. */ + IRRef1 tmp = fins->op1; + fins->op1 = fins->op2; + fins->op2 = tmp; + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(EQ any any) +LJFOLD(NE any any) +LJFOLDF(comm_equal) +{ + /* For non-numbers only: x == x ==> drop; x ~= x ==> fail */ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) + return CONDFOLD(fins->o == IR_EQ); + return fold_comm_swap(J); +} + +LJFOLD(LT any any) +LJFOLD(GE any any) +LJFOLD(LE any any) +LJFOLD(GT any any) +LJFOLD(ULT any any) +LJFOLD(UGE any any) +LJFOLD(ULE any any) +LJFOLD(UGT any any) +LJFOLDF(comm_comp) +{ + /* For non-numbers only: x <=> x ==> drop; x <> x ==> fail */ + if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) + return CONDFOLD((fins->o ^ (fins->o >> 1)) & 1); + if (fins->op1 < fins->op2) { /* Move lower ref to the right. */ + IRRef1 tmp = fins->op1; + fins->op1 = fins->op2; + fins->op2 = tmp; + fins->o ^= 3; /* GT <-> LT, GE <-> LE, does not affect U */ + return RETRYFOLD; + } + return NEXTFOLD; +} + +LJFOLD(BAND any any) +LJFOLD(BOR any any) +LJFOLD(MIN any any) +LJFOLD(MAX any any) +LJFOLDF(comm_dup) +{ + if (fins->op1 == fins->op2) /* x o x ==> x */ + return LEFTFOLD; + return fold_comm_swap(J); +} + +LJFOLD(BXOR any any) +LJFOLDF(comm_bxor) +{ + if (fins->op1 == fins->op2) /* i xor i ==> 0 */ + return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0); + return fold_comm_swap(J); +} + +/* -- Simplification of compound expressions ------------------------------ */ + +static TRef kfold_xload(jit_State *J, IRIns *ir, const void *p) +{ + int32_t k; + switch (irt_type(ir->t)) { + case IRT_NUM: return lj_ir_knum_u64(J, *(uint64_t *)p); + case IRT_I8: k = (int32_t)*(int8_t *)p; break; + case IRT_U8: k = (int32_t)*(uint8_t *)p; break; + case IRT_I16: k = (int32_t)(int16_t)lj_getu16(p); break; + case IRT_U16: k = (int32_t)(uint16_t)lj_getu16(p); break; + case IRT_INT: case IRT_U32: k = (int32_t)lj_getu32(p); break; + case IRT_I64: case IRT_U64: return lj_ir_kint64(J, *(uint64_t *)p); + default: return 0; + } + return lj_ir_kint(J, k); +} + +/* Turn: string.sub(str, a, b) == kstr +** into: string.byte(str, a) == string.byte(kstr, 1) etc. +** Note: this creates unaligned XLOADs on x86/x64. +*/ +LJFOLD(EQ SNEW KGC) +LJFOLD(NE SNEW KGC) +LJFOLDF(merge_eqne_snew_kgc) +{ + GCstr *kstr = ir_kstr(fright); + int32_t len = (int32_t)kstr->len; + lua_assert(irt_isstr(fins->t)); + +#if LJ_TARGET_UNALIGNED +#define FOLD_SNEW_MAX_LEN 4 /* Handle string lengths 0, 1, 2, 3, 4. */ +#define FOLD_SNEW_TYPE8 IRT_I8 /* Creates shorter immediates. */ +#else +#define FOLD_SNEW_MAX_LEN 1 /* Handle string lengths 0 or 1. */ +#define FOLD_SNEW_TYPE8 IRT_U8 /* Prefer unsigned loads. */ +#endif + + PHIBARRIER(fleft); + if (len <= FOLD_SNEW_MAX_LEN) { + IROp op = (IROp)fins->o; + IRRef strref = fleft->op1; + lua_assert(IR(strref)->o == IR_STRREF); + if (op == IR_EQ) { + emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len)); + /* Caveat: fins/fleft/fright is no longer valid after emitir. */ + } else { + /* NE is not expanded since this would need an OR of two conds. */ + if (!irref_isk(fleft->op2)) /* Only handle the constant length case. */ + return NEXTFOLD; + if (IR(fleft->op2)->i != len) + return DROPFOLD; + } + if (len > 0) { + /* A 4 byte load for length 3 is ok -- all strings have an extra NUL. */ + uint16_t ot = (uint16_t)(len == 1 ? IRT(IR_XLOAD, FOLD_SNEW_TYPE8) : + len == 2 ? IRT(IR_XLOAD, IRT_U16) : + IRTI(IR_XLOAD)); + TRef tmp = emitir(ot, strref, + IRXLOAD_READONLY | (len > 1 ? IRXLOAD_UNALIGNED : 0)); + TRef val = kfold_xload(J, IR(tref_ref(tmp)), strdata(kstr)); + if (len == 3) + tmp = emitir(IRTI(IR_BAND), tmp, + lj_ir_kint(J, LJ_ENDIAN_SELECT(0x00ffffff, 0xffffff00))); + fins->op1 = (IRRef1)tmp; + fins->op2 = (IRRef1)val; + fins->ot = (IROpT)IRTGI(op); + return RETRYFOLD; + } else { + return DROPFOLD; + } + } + return NEXTFOLD; +} + +/* -- Loads --------------------------------------------------------------- */ + +/* Loads cannot be folded or passed on to CSE in general. +** Alias analysis is needed to check for forwarding opportunities. +** +** Caveat: *all* loads must be listed here or they end up at CSE! +*/ + +LJFOLD(ALOAD any) +LJFOLDX(lj_opt_fwd_aload) + +/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */ +LJFOLD(HLOAD KKPTR) +LJFOLDF(kfold_hload_kkptr) +{ + UNUSED(J); + lua_assert(ir_kptr(fleft) == niltvg(J2G(J))); + return TREF_NIL; +} + +LJFOLD(HLOAD any) +LJFOLDX(lj_opt_fwd_hload) + +LJFOLD(ULOAD any) +LJFOLDX(lj_opt_fwd_uload) + +LJFOLD(CALLL any IRCALL_lj_tab_len) +LJFOLDX(lj_opt_fwd_tab_len) + +/* Upvalue refs are really loads, but there are no corresponding stores. +** So CSE is ok for them, except for UREFO across a GC step (see below). +** If the referenced function is const, its upvalue addresses are const, too. +** This can be used to improve CSE by looking for the same address, +** even if the upvalues originate from a different function. +*/ +LJFOLD(UREFO KGC any) +LJFOLD(UREFC KGC any) +LJFOLDF(cse_uref) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + IRRef ref = J->chain[fins->o]; + GCfunc *fn = ir_kfunc(fleft); + GCupval *uv = gco2uv(gcref(fn->l.uvptr[(fins->op2 >> 8)])); + while (ref > 0) { + IRIns *ir = IR(ref); + if (irref_isk(ir->op1)) { + GCfunc *fn2 = ir_kfunc(IR(ir->op1)); + if (gco2uv(gcref(fn2->l.uvptr[(ir->op2 >> 8)])) == uv) { + if (fins->o == IR_UREFO && gcstep_barrier(J, ref)) + break; + return ref; + } + } + ref = ir->prev; + } + } + return EMITFOLD; +} + +LJFOLD(HREFK any any) +LJFOLDX(lj_opt_fwd_hrefk) + +LJFOLD(HREF TNEW any) +LJFOLDF(fwd_href_tnew) +{ + if (lj_opt_fwd_href_nokey(J)) + return lj_ir_kkptr(J, niltvg(J2G(J))); + return NEXTFOLD; +} + +LJFOLD(HREF TDUP KPRI) +LJFOLD(HREF TDUP KGC) +LJFOLD(HREF TDUP KNUM) +LJFOLDF(fwd_href_tdup) +{ + TValue keyv; + lj_ir_kvalue(J->L, &keyv, fright); + if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) && + lj_opt_fwd_href_nokey(J)) + return lj_ir_kkptr(J, niltvg(J2G(J))); + return NEXTFOLD; +} + +/* We can safely FOLD/CSE array/hash refs and field loads, since there +** are no corresponding stores. But we need to check for any NEWREF with +** an aliased table, as it may invalidate all of the pointers and fields. +** Only HREF needs the NEWREF check -- AREF and HREFK already depend on +** FLOADs. And NEWREF itself is treated like a store (see below). +*/ +LJFOLD(FLOAD TNEW IRFL_TAB_ASIZE) +LJFOLDF(fload_tab_tnew_asize) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD(fleft->op1); + return NEXTFOLD; +} + +LJFOLD(FLOAD TNEW IRFL_TAB_HMASK) +LJFOLDF(fload_tab_tnew_hmask) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((1 << fleft->op2)-1); + return NEXTFOLD; +} + +LJFOLD(FLOAD TDUP IRFL_TAB_ASIZE) +LJFOLDF(fload_tab_tdup_asize) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->asize); + return NEXTFOLD; +} + +LJFOLD(FLOAD TDUP IRFL_TAB_HMASK) +LJFOLDF(fload_tab_tdup_hmask) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1)) + return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->hmask); + return NEXTFOLD; +} + +LJFOLD(HREF any any) +LJFOLD(FLOAD any IRFL_TAB_ARRAY) +LJFOLD(FLOAD any IRFL_TAB_NODE) +LJFOLD(FLOAD any IRFL_TAB_ASIZE) +LJFOLD(FLOAD any IRFL_TAB_HMASK) +LJFOLDF(fload_tab_ah) +{ + TRef tr = lj_opt_cse(J); + return lj_opt_fwd_tptr(J, tref_ref(tr)) ? tr : EMITFOLD; +} + +/* Strings are immutable, so we can safely FOLD/CSE the related FLOAD. */ +LJFOLD(FLOAD KGC IRFL_STR_LEN) +LJFOLDF(fload_str_len_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return INTFOLD((int32_t)ir_kstr(fleft)->len); + return NEXTFOLD; +} + +LJFOLD(FLOAD SNEW IRFL_STR_LEN) +LJFOLDF(fload_str_len_snew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { + PHIBARRIER(fleft); + return fleft->op2; + } + return NEXTFOLD; +} + +/* The C type ID of cdata objects is immutable. */ +LJFOLD(FLOAD KGC IRFL_CDATA_CTYPEID) +LJFOLDF(fload_cdata_typeid_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return INTFOLD((int32_t)ir_kcdata(fleft)->ctypeid); + return NEXTFOLD; +} + +/* Get the contents of immutable cdata objects. */ +LJFOLD(FLOAD KGC IRFL_CDATA_PTR) +LJFOLD(FLOAD KGC IRFL_CDATA_INT) +LJFOLD(FLOAD KGC IRFL_CDATA_INT64) +LJFOLDF(fload_cdata_int64_kgc) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { + void *p = cdataptr(ir_kcdata(fleft)); + if (irt_is64(fins->t)) + return INT64FOLD(*(uint64_t *)p); + else + return INTFOLD(*(int32_t *)p); + } + return NEXTFOLD; +} + +LJFOLD(FLOAD CNEW IRFL_CDATA_CTYPEID) +LJFOLD(FLOAD CNEWI IRFL_CDATA_CTYPEID) +LJFOLDF(fload_cdata_typeid_cnew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return fleft->op1; /* No PHI barrier needed. CNEW/CNEWI op1 is const. */ + return NEXTFOLD; +} + +/* Pointer, int and int64 cdata objects are immutable. */ +LJFOLD(FLOAD CNEWI IRFL_CDATA_PTR) +LJFOLD(FLOAD CNEWI IRFL_CDATA_INT) +LJFOLD(FLOAD CNEWI IRFL_CDATA_INT64) +LJFOLDF(fload_cdata_ptr_int64_cnew) +{ + if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) + return fleft->op2; /* Fold even across PHI to avoid allocations. */ + return NEXTFOLD; +} + +LJFOLD(FLOAD any IRFL_STR_LEN) +LJFOLD(FLOAD any IRFL_CDATA_CTYPEID) +LJFOLD(FLOAD any IRFL_CDATA_PTR) +LJFOLD(FLOAD any IRFL_CDATA_INT) +LJFOLD(FLOAD any IRFL_CDATA_INT64) +LJFOLD(VLOAD any any) /* Vararg loads have no corresponding stores. */ +LJFOLDX(lj_opt_cse) + +/* All other field loads need alias analysis. */ +LJFOLD(FLOAD any any) +LJFOLDX(lj_opt_fwd_fload) + +/* This is for LOOP only. Recording handles SLOADs internally. */ +LJFOLD(SLOAD any any) +LJFOLDF(fwd_sload) +{ + if ((fins->op2 & IRSLOAD_FRAME)) { + TRef tr = lj_opt_cse(J); + return tref_ref(tr) < J->chain[IR_RETF] ? EMITFOLD : tr; + } else { + lua_assert(J->slot[fins->op1] != 0); + return J->slot[fins->op1]; + } +} + +/* Only fold for KKPTR. The pointer _and_ the contents must be const. */ +LJFOLD(XLOAD KKPTR any) +LJFOLDF(xload_kptr) +{ + TRef tr = kfold_xload(J, fins, ir_kptr(fleft)); + return tr ? tr : NEXTFOLD; +} + +LJFOLD(XLOAD any any) +LJFOLDX(lj_opt_fwd_xload) + +/* -- Write barriers ------------------------------------------------------ */ + +/* Write barriers are amenable to CSE, but not across any incremental +** GC steps. +** +** The same logic applies to open upvalue references, because a stack +** may be resized during a GC step (not the current stack, but maybe that +** of a coroutine). +*/ +LJFOLD(TBAR any) +LJFOLD(OBAR any any) +LJFOLD(UREFO any any) +LJFOLDF(barrier_tab) +{ + TRef tr = lj_opt_cse(J); + if (gcstep_barrier(J, tref_ref(tr))) /* CSE across GC step? */ + return EMITFOLD; /* Raw emit. Assumes fins is left intact by CSE. */ + return tr; +} + +LJFOLD(TBAR TNEW) +LJFOLD(TBAR TDUP) +LJFOLDF(barrier_tnew_tdup) +{ + /* New tables are always white and never need a barrier. */ + if (fins->op1 < J->chain[IR_LOOP]) /* Except across a GC step. */ + return NEXTFOLD; + return DROPFOLD; +} + +/* -- Stores and allocations ---------------------------------------------- */ + +/* Stores and allocations cannot be folded or passed on to CSE in general. +** But some stores can be eliminated with dead-store elimination (DSE). +** +** Caveat: *all* stores and allocs must be listed here or they end up at CSE! +*/ + +LJFOLD(ASTORE any any) +LJFOLD(HSTORE any any) +LJFOLDX(lj_opt_dse_ahstore) + +LJFOLD(USTORE any any) +LJFOLDX(lj_opt_dse_ustore) + +LJFOLD(FSTORE any any) +LJFOLDX(lj_opt_dse_fstore) + +LJFOLD(XSTORE any any) +LJFOLDX(lj_opt_dse_xstore) + +LJFOLD(NEWREF any any) /* Treated like a store. */ +LJFOLD(CALLS any any) +LJFOLD(CALLL any any) /* Safeguard fallback. */ +LJFOLD(CALLXS any any) +LJFOLD(XBAR) +LJFOLD(RETF any any) /* Modifies BASE. */ +LJFOLD(TNEW any any) +LJFOLD(TDUP any) +LJFOLD(CNEW any any) +LJFOLD(XSNEW any any) +LJFOLDX(lj_ir_emit) + +/* ------------------------------------------------------------------------ */ + +/* Every entry in the generated hash table is a 32 bit pattern: +** +** xxxxxxxx iiiiiii lllllll rrrrrrrrrr +** +** xxxxxxxx = 8 bit index into fold function table +** iiiiiii = 7 bit folded instruction opcode +** lllllll = 7 bit left instruction opcode +** rrrrrrrrrr = 8 bit right instruction opcode or 10 bits from literal field +*/ + +#include "lj_folddef.h" + +/* ------------------------------------------------------------------------ */ + +/* Fold IR instruction. */ +TRef LJ_FASTCALL lj_opt_fold(jit_State *J) +{ + uint32_t key, any; + IRRef ref; + + if (LJ_UNLIKELY((J->flags & JIT_F_OPT_MASK) != JIT_F_OPT_DEFAULT)) { + lua_assert(((JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE|JIT_F_OPT_DSE) | + JIT_F_OPT_DEFAULT) == JIT_F_OPT_DEFAULT); + /* Folding disabled? Chain to CSE, but not for loads/stores/allocs. */ + if (!(J->flags & JIT_F_OPT_FOLD) && irm_kind(lj_ir_mode[fins->o]) == IRM_N) + return lj_opt_cse(J); + + /* No FOLD, forwarding or CSE? Emit raw IR for loads, except for SLOAD. */ + if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE)) != + (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE) && + irm_kind(lj_ir_mode[fins->o]) == IRM_L && fins->o != IR_SLOAD) + return lj_ir_emit(J); + + /* No FOLD or DSE? Emit raw IR for stores. */ + if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_DSE)) != + (JIT_F_OPT_FOLD|JIT_F_OPT_DSE) && + irm_kind(lj_ir_mode[fins->o]) == IRM_S) + return lj_ir_emit(J); + } + + /* Fold engine start/retry point. */ +retry: + /* Construct key from opcode and operand opcodes (unless literal/none). */ + key = ((uint32_t)fins->o << 17); + if (fins->op1 >= J->cur.nk) { + key += (uint32_t)IR(fins->op1)->o << 10; + *fleft = *IR(fins->op1); + } + if (fins->op2 >= J->cur.nk) { + key += (uint32_t)IR(fins->op2)->o; + *fright = *IR(fins->op2); + } else { + key += (fins->op2 & 0x3ffu); /* Literal mask. Must include IRCONV_*MASK. */ + } + + /* Check for a match in order from most specific to least specific. */ + any = 0; + for (;;) { + uint32_t k = key | (any & 0x1ffff); + uint32_t h = fold_hashkey(k); + uint32_t fh = fold_hash[h]; /* Lookup key in semi-perfect hash table. */ + if ((fh & 0xffffff) == k || (fh = fold_hash[h+1], (fh & 0xffffff) == k)) { + ref = (IRRef)tref_ref(fold_func[fh >> 24](J)); + if (ref != NEXTFOLD) + break; + } + if (any == 0xfffff) /* Exhausted folding. Pass on to CSE. */ + return lj_opt_cse(J); + any = (any | (any >> 10)) ^ 0xffc00; + } + + /* Return value processing, ordered by frequency. */ + if (LJ_LIKELY(ref >= MAX_FOLD)) + return TREF(ref, irt_t(IR(ref)->t)); + if (ref == RETRYFOLD) + goto retry; + if (ref == KINTFOLD) + return lj_ir_kint(J, fins->i); + if (ref == FAILFOLD) + lj_trace_err(J, LJ_TRERR_GFAIL); + lua_assert(ref == DROPFOLD); + return REF_DROP; +} + +/* -- Common-Subexpression Elimination ------------------------------------ */ + +/* CSE an IR instruction. This is very fast due to the skip-list chains. */ +TRef LJ_FASTCALL lj_opt_cse(jit_State *J) +{ + /* Avoid narrow to wide store-to-load forwarding stall */ + IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16); + IROp op = fins->o; + if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { + /* Limited search for same operands in per-opcode chain. */ + IRRef ref = J->chain[op]; + IRRef lim = fins->op1; + if (fins->op2 > lim) lim = fins->op2; /* Relies on lit < REF_BIAS. */ + while (ref > lim) { + if (IR(ref)->op12 == op12) + return TREF(ref, irt_t(IR(ref)->t)); /* Common subexpression found. */ + ref = IR(ref)->prev; + } + } + /* Otherwise emit IR (inlined for speed). */ + { + IRRef ref = lj_ir_nextins(J); + IRIns *ir = IR(ref); + ir->prev = J->chain[op]; + ir->op12 = op12; + J->chain[op] = (IRRef1)ref; + ir->o = fins->o; + J->guardemit.irt |= fins->t.irt; + return TREF(ref, irt_t((ir->t = fins->t))); + } +} + +/* CSE with explicit search limit. */ +TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim) +{ + IRRef ref = J->chain[fins->o]; + IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16); + while (ref > lim) { + if (IR(ref)->op12 == op12) + return ref; + ref = IR(ref)->prev; + } + return lj_ir_emit(J); +} + +/* ------------------------------------------------------------------------ */ + +#undef IR +#undef fins +#undef fleft +#undef fright +#undef knumleft +#undef knumright +#undef emitir + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_loop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_loop.c new file mode 100644 index 0000000..fa00115 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_loop.c @@ -0,0 +1,436 @@ +/* +** LOOP: Loop Optimizations. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_loop_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_vm.h" + +/* Loop optimization: +** +** Traditional Loop-Invariant Code Motion (LICM) splits the instructions +** of a loop into invariant and variant instructions. The invariant +** instructions are hoisted out of the loop and only the variant +** instructions remain inside the loop body. +** +** Unfortunately LICM is mostly useless for compiling dynamic languages. +** The IR has many guards and most of the subsequent instructions are +** control-dependent on them. The first non-hoistable guard would +** effectively prevent hoisting of all subsequent instructions. +** +** That's why we use a special form of unrolling using copy-substitution, +** combined with redundancy elimination: +** +** The recorded instruction stream is re-emitted to the compiler pipeline +** with substituted operands. The substitution table is filled with the +** refs returned by re-emitting each instruction. This can be done +** on-the-fly, because the IR is in strict SSA form, where every ref is +** defined before its use. +** +** This aproach generates two code sections, separated by the LOOP +** instruction: +** +** 1. The recorded instructions form a kind of pre-roll for the loop. It +** contains a mix of invariant and variant instructions and performs +** exactly one loop iteration (but not necessarily the 1st iteration). +** +** 2. The loop body contains only the variant instructions and performs +** all remaining loop iterations. +** +** On first sight that looks like a waste of space, because the variant +** instructions are present twice. But the key insight is that the +** pre-roll honors the control-dependencies for *both* the pre-roll itself +** *and* the loop body! +** +** It also means one doesn't have to explicitly model control-dependencies +** (which, BTW, wouldn't help LICM much). And it's much easier to +** integrate sparse snapshotting with this approach. +** +** One of the nicest aspects of this approach is that all of the +** optimizations of the compiler pipeline (FOLD, CSE, FWD, etc.) can be +** reused with only minor restrictions (e.g. one should not fold +** instructions across loop-carried dependencies). +** +** But in general all optimizations can be applied which only need to look +** backwards into the generated instruction stream. At any point in time +** during the copy-substitution process this contains both a static loop +** iteration (the pre-roll) and a dynamic one (from the to-be-copied +** instruction up to the end of the partial loop body). +** +** Since control-dependencies are implicitly kept, CSE also applies to all +** kinds of guards. The major advantage is that all invariant guards can +** be hoisted, too. +** +** Load/store forwarding works across loop iterations, too. This is +** important if loop-carried dependencies are kept in upvalues or tables. +** E.g. 'self.idx = self.idx + 1' deep down in some OO-style method may +** become a forwarded loop-recurrence after inlining. +** +** Since the IR is in SSA form, loop-carried dependencies have to be +** modeled with PHI instructions. The potential candidates for PHIs are +** collected on-the-fly during copy-substitution. After eliminating the +** redundant ones, PHI instructions are emitted *below* the loop body. +** +** Note that this departure from traditional SSA form doesn't change the +** semantics of the PHI instructions themselves. But it greatly simplifies +** on-the-fly generation of the IR and the machine code. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- PHI elimination ----------------------------------------------------- */ + +/* Emit or eliminate collected PHIs. */ +static void loop_emit_phi(jit_State *J, IRRef1 *subst, IRRef1 *phi, IRRef nphi, + SnapNo onsnap) +{ + int passx = 0; + IRRef i, j, nslots; + IRRef invar = J->chain[IR_LOOP]; + /* Pass #1: mark redundant and potentially redundant PHIs. */ + for (i = 0, j = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRRef rref = subst[lref]; + if (lref == rref || rref == REF_DROP) { /* Invariants are redundant. */ + irt_clearphi(IR(lref)->t); + } else { + phi[j++] = (IRRef1)lref; + if (!(IR(rref)->op1 == lref || IR(rref)->op2 == lref)) { + /* Quick check for simple recurrences failed, need pass2. */ + irt_setmark(IR(lref)->t); + passx = 1; + } + } + } + nphi = j; + /* Pass #2: traverse variant part and clear marks of non-redundant PHIs. */ + if (passx) { + SnapNo s; + for (i = J->cur.nins-1; i > invar; i--) { + IRIns *ir = IR(i); + if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t); + if (!irref_isk(ir->op1)) { + irt_clearmark(IR(ir->op1)->t); + if (ir->op1 < invar && + ir->o >= IR_CALLN && ir->o <= IR_CARG) { /* ORDER IR */ + ir = IR(ir->op1); + while (ir->o == IR_CARG) { + if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t); + if (irref_isk(ir->op1)) break; + ir = IR(ir->op1); + irt_clearmark(ir->t); + } + } + } + } + for (s = J->cur.nsnap-1; s >= onsnap; s--) { + SnapShot *snap = &J->cur.snap[s]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (!irref_isk(ref)) irt_clearmark(IR(ref)->t); + } + } + } + /* Pass #3: add PHIs for variant slots without a corresponding SLOAD. */ + nslots = J->baseslot+J->maxslot; + for (i = 1; i < nslots; i++) { + IRRef ref = tref_ref(J->slot[i]); + while (!irref_isk(ref) && ref != subst[ref]) { + IRIns *ir = IR(ref); + irt_clearmark(ir->t); /* Unmark potential uses, too. */ + if (irt_isphi(ir->t) || irt_ispri(ir->t)) + break; + irt_setphi(ir->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + ref = subst[ref]; + if (ref > invar) + break; + } + } + /* Pass #4: propagate non-redundant PHIs. */ + while (passx) { + passx = 0; + for (i = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRIns *ir = IR(lref); + if (!irt_ismarked(ir->t)) { /* Propagate only from unmarked PHIs. */ + IRIns *irr = IR(subst[lref]); + if (irt_ismarked(irr->t)) { /* Right ref points to other PHI? */ + irt_clearmark(irr->t); /* Mark that PHI as non-redundant. */ + passx = 1; /* Retry. */ + } + } + } + } + /* Pass #5: emit PHI instructions or eliminate PHIs. */ + for (i = 0; i < nphi; i++) { + IRRef lref = phi[i]; + IRIns *ir = IR(lref); + if (!irt_ismarked(ir->t)) { /* Emit PHI if not marked. */ + IRRef rref = subst[lref]; + if (rref > invar) + irt_setphi(IR(rref)->t); + emitir_raw(IRT(IR_PHI, irt_type(ir->t)), lref, rref); + } else { /* Otherwise eliminate PHI. */ + irt_clearmark(ir->t); + irt_clearphi(ir->t); + } + } +} + +/* -- Loop unrolling using copy-substitution ------------------------------ */ + +/* Copy-substitute snapshot. */ +static void loop_subst_snap(jit_State *J, SnapShot *osnap, + SnapEntry *loopmap, IRRef1 *subst) +{ + SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs]; + SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)]; + MSize nmapofs; + MSize on, ln, nn, onent = osnap->nent; + BCReg nslots = osnap->nslots; + SnapShot *snap = &J->cur.snap[J->cur.nsnap]; + if (irt_isguard(J->guardemit)) { /* Guard inbetween? */ + nmapofs = J->cur.nsnapmap; + J->cur.nsnap++; /* Add new snapshot. */ + } else { /* Otherwise overwrite previous snapshot. */ + snap--; + nmapofs = snap->mapofs; + } + J->guardemit.irt = 0; + /* Setup new snapshot. */ + snap->mapofs = (uint16_t)nmapofs; + snap->ref = (IRRef1)J->cur.nins; + snap->nslots = nslots; + snap->topslot = osnap->topslot; + snap->count = 0; + nmap = &J->cur.snapmap[nmapofs]; + /* Substitute snapshot slots. */ + on = ln = nn = 0; + while (on < onent) { + SnapEntry osn = omap[on], lsn = loopmap[ln]; + if (snap_slot(lsn) < snap_slot(osn)) { /* Copy slot from loop map. */ + nmap[nn++] = lsn; + ln++; + } else { /* Copy substituted slot from snapshot map. */ + if (snap_slot(lsn) == snap_slot(osn)) ln++; /* Shadowed loop slot. */ + if (!irref_isk(snap_ref(osn))) + osn = snap_setref(osn, subst[snap_ref(osn)]); + nmap[nn++] = osn; + on++; + } + } + while (snap_slot(loopmap[ln]) < nslots) /* Copy remaining loop slots. */ + nmap[nn++] = loopmap[ln++]; + snap->nent = (uint8_t)nn; + omap += onent; + nmap += nn; + while (omap < nextmap) /* Copy PC + frame links. */ + *nmap++ = *omap++; + J->cur.nsnapmap = (uint16_t)(nmap - J->cur.snapmap); +} + +/* Unroll loop. */ +static void loop_unroll(jit_State *J) +{ + IRRef1 phi[LJ_MAX_PHI]; + uint32_t nphi = 0; + IRRef1 *subst; + SnapNo onsnap; + SnapShot *osnap, *loopsnap; + SnapEntry *loopmap, *psentinel; + IRRef ins, invar; + + /* Use temp buffer for substitution table. + ** Only non-constant refs in [REF_BIAS,invar) are valid indexes. + ** Caveat: don't call into the VM or run the GC or the buffer may be gone. + */ + invar = J->cur.nins; + subst = (IRRef1 *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, + (invar-REF_BIAS)*sizeof(IRRef1)) - REF_BIAS; + subst[REF_BASE] = REF_BASE; + + /* LOOP separates the pre-roll from the loop body. */ + emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0); + + /* Grow snapshot buffer and map for copy-substituted snapshots. + ** Need up to twice the number of snapshots minus #0 and loop snapshot. + ** Need up to twice the number of entries plus fallback substitutions + ** from the loop snapshot entries for each new snapshot. + ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap! + */ + onsnap = J->cur.nsnap; + lj_snap_grow_buf(J, 2*onsnap-2); + lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent); + + /* The loop snapshot is used for fallback substitutions. */ + loopsnap = &J->cur.snap[onsnap-1]; + loopmap = &J->cur.snapmap[loopsnap->mapofs]; + /* The PC of snapshot #0 and the loop snapshot must match. */ + psentinel = &loopmap[loopsnap->nent]; + lua_assert(*psentinel == J->cur.snapmap[J->cur.snap[0].nent]); + *psentinel = SNAP(255, 0, 0); /* Replace PC with temporary sentinel. */ + + /* Start substitution with snapshot #1 (#0 is empty for root traces). */ + osnap = &J->cur.snap[1]; + + /* Copy and substitute all recorded instructions and snapshots. */ + for (ins = REF_FIRST; ins < invar; ins++) { + IRIns *ir; + IRRef op1, op2; + + if (ins >= osnap->ref) /* Instruction belongs to next snapshot? */ + loop_subst_snap(J, osnap++, loopmap, subst); /* Copy-substitute it. */ + + /* Substitute instruction operands. */ + ir = IR(ins); + op1 = ir->op1; + if (!irref_isk(op1)) op1 = subst[op1]; + op2 = ir->op2; + if (!irref_isk(op2)) op2 = subst[op2]; + if (irm_kind(lj_ir_mode[ir->o]) == IRM_N && + op1 == ir->op1 && op2 == ir->op2) { /* Regular invariant ins? */ + subst[ins] = (IRRef1)ins; /* Shortcut. */ + } else { + /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */ + IRType1 t = ir->t; /* Get this first, since emitir may invalidate ir. */ + IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2)); + subst[ins] = (IRRef1)ref; + if (ref != ins) { + IRIns *irr = IR(ref); + if (ref < invar) { /* Loop-carried dependency? */ + /* Potential PHI? */ + if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) { + irt_setphi(irr->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + } + /* Check all loop-carried dependencies for type instability. */ + if (!irt_sametype(t, irr->t)) { + if (irt_isinteger(t) && irt_isinteger(irr->t)) + continue; + else if (irt_isnum(t) && irt_isinteger(irr->t)) /* Fix int->num. */ + ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT)); + else if (irt_isnum(irr->t) && irt_isinteger(t)) /* Fix num->int. */ + ref = tref_ref(emitir(IRTGI(IR_CONV), ref, + IRCONV_INT_NUM|IRCONV_CHECK)); + else + lj_trace_err(J, LJ_TRERR_TYPEINS); + subst[ins] = (IRRef1)ref; + irr = IR(ref); + goto phiconv; + } + } else if (ref != REF_DROP && irr->o == IR_CONV && + ref > invar && irr->op1 < invar) { + /* May need an extra PHI for a CONV. */ + ref = irr->op1; + irr = IR(ref); + phiconv: + if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) { + irt_setphi(irr->t); + if (nphi >= LJ_MAX_PHI) + lj_trace_err(J, LJ_TRERR_PHIOV); + phi[nphi++] = (IRRef1)ref; + } + } + } + } + } + if (!irt_isguard(J->guardemit)) /* Drop redundant snapshot. */ + J->cur.nsnapmap = (uint16_t)J->cur.snap[--J->cur.nsnap].mapofs; + lua_assert(J->cur.nsnapmap <= J->sizesnapmap); + *psentinel = J->cur.snapmap[J->cur.snap[0].nent]; /* Restore PC. */ + + loop_emit_phi(J, subst, phi, nphi, onsnap); +} + +/* Undo any partial changes made by the loop optimization. */ +static void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap) +{ + ptrdiff_t i; + SnapShot *snap = &J->cur.snap[nsnap-1]; + SnapEntry *map = J->cur.snapmap; + map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent]; /* Restore PC. */ + J->cur.nsnapmap = (uint16_t)nsnapmap; + J->cur.nsnap = nsnap; + J->guardemit.irt = 0; + lj_ir_rollback(J, ins); + for (i = 0; i < BPROP_SLOTS; i++) { /* Remove backprop. cache entries. */ + BPropEntry *bp = &J->bpropcache[i]; + if (bp->val >= ins) + bp->key = 0; + } + for (ins--; ins >= REF_FIRST; ins--) { /* Remove flags. */ + IRIns *ir = IR(ins); + irt_clearphi(ir->t); + irt_clearmark(ir->t); + } +} + +/* Protected callback for loop optimization. */ +static TValue *cploop_opt(lua_State *L, lua_CFunction dummy, void *ud) +{ + UNUSED(L); UNUSED(dummy); + loop_unroll((jit_State *)ud); + return NULL; +} + +/* Loop optimization. */ +int lj_opt_loop(jit_State *J) +{ + IRRef nins = J->cur.nins; + SnapNo nsnap = J->cur.nsnap; + MSize nsnapmap = J->cur.nsnapmap; + int errcode = lj_vm_cpcall(J->L, NULL, J, cploop_opt); + if (LJ_UNLIKELY(errcode)) { + lua_State *L = J->L; + if (errcode == LUA_ERRRUN && tvisnumber(L->top-1)) { /* Trace error? */ + int32_t e = numberVint(L->top-1); + switch ((TraceError)e) { + case LJ_TRERR_TYPEINS: /* Type instability. */ + case LJ_TRERR_GFAIL: /* Guard would always fail. */ + /* Unrolling via recording fixes many cases, e.g. a flipped boolean. */ + if (--J->instunroll < 0) /* But do not unroll forever. */ + break; + L->top--; /* Remove error object. */ + loop_undo(J, nins, nsnap, nsnapmap); + return 1; /* Loop optimization failed, continue recording. */ + default: + break; + } + } + lj_err_throw(L, errcode); /* Propagate all other errors. */ + } + return 0; /* Loop optimization is ok. */ +} + +#undef IR +#undef emitir +#undef emitir_raw + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_mem.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_mem.c new file mode 100644 index 0000000..c8cdc3e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_mem.c @@ -0,0 +1,917 @@ +/* +** Memory access optimizations. +** AA: Alias Analysis using high-level semantic disambiguation. +** FWD: Load Forwarding (L2L) + Store Forwarding (S2L). +** DSE: Dead-Store Elimination. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_mem_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_tab.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) +#define fleft (&J->fold.left) +#define fright (&J->fold.right) + +/* +** Caveat #1: return value is not always a TRef -- only use with tref_ref(). +** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold(). +*/ + +/* Return values from alias analysis. */ +typedef enum { + ALIAS_NO, /* The two refs CANNOT alias (exact). */ + ALIAS_MAY, /* The two refs MAY alias (inexact). */ + ALIAS_MUST /* The two refs MUST alias (exact). */ +} AliasRet; + +/* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */ + +/* Simplified escape analysis: check for intervening stores. */ +static AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop) +{ + IRRef ref = (IRRef)(ir - J->cur.ir); /* The ref that might be stored. */ + for (ir++; ir < stop; ir++) + if (ir->op2 == ref && + (ir->o == IR_ASTORE || ir->o == IR_HSTORE || + ir->o == IR_USTORE || ir->o == IR_FSTORE)) + return ALIAS_MAY; /* Reference was stored and might alias. */ + return ALIAS_NO; /* Reference was not stored. */ +} + +/* Alias analysis for two different table references. */ +static AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb) +{ + IRIns *taba = IR(ta), *tabb = IR(tb); + int newa, newb; + lua_assert(ta != tb); + lua_assert(irt_istab(taba->t) && irt_istab(tabb->t)); + /* Disambiguate new allocations. */ + newa = (taba->o == IR_TNEW || taba->o == IR_TDUP); + newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP); + if (newa && newb) + return ALIAS_NO; /* Two different allocations never alias. */ + if (newb) { /* At least one allocation? */ + IRIns *tmp = taba; taba = tabb; tabb = tmp; + } else if (!newa) { + return ALIAS_MAY; /* Anything else: we just don't know. */ + } + return aa_escape(J, taba, tabb); +} + +/* Alias analysis for array and hash access using key-based disambiguation. */ +static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb) +{ + IRRef ka = refa->op2; + IRRef kb = refb->op2; + IRIns *keya, *keyb; + IRRef ta, tb; + if (refa == refb) + return ALIAS_MUST; /* Shortcut for same refs. */ + keya = IR(ka); + if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); } + keyb = IR(kb); + if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); } + ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1; + tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1; + if (ka == kb) { + /* Same key. Check for same table with different ref (NEWREF vs. HREF). */ + if (ta == tb) + return ALIAS_MUST; /* Same key, same table. */ + else + return aa_table(J, ta, tb); /* Same key, possibly different table. */ + } + if (irref_isk(ka) && irref_isk(kb)) + return ALIAS_NO; /* Different constant keys. */ + if (refa->o == IR_AREF) { + /* Disambiguate array references based on index arithmetic. */ + int32_t ofsa = 0, ofsb = 0; + IRRef basea = ka, baseb = kb; + lua_assert(refb->o == IR_AREF); + /* Gather base and offset from t[base] or t[base+-ofs]. */ + if (keya->o == IR_ADD && irref_isk(keya->op2)) { + basea = keya->op1; + ofsa = IR(keya->op2)->i; + if (basea == kb && ofsa != 0) + return ALIAS_NO; /* t[base+-ofs] vs. t[base]. */ + } + if (keyb->o == IR_ADD && irref_isk(keyb->op2)) { + baseb = keyb->op1; + ofsb = IR(keyb->op2)->i; + if (ka == baseb && ofsb != 0) + return ALIAS_NO; /* t[base] vs. t[base+-ofs]. */ + } + if (basea == baseb && ofsa != ofsb) + return ALIAS_NO; /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */ + } else { + /* Disambiguate hash references based on the type of their keys. */ + lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) && + (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF)); + if (!irt_sametype(keya->t, keyb->t)) + return ALIAS_NO; /* Different key types. */ + } + if (ta == tb) + return ALIAS_MAY; /* Same table, cannot disambiguate keys. */ + else + return aa_table(J, ta, tb); /* Try to disambiguate tables. */ +} + +/* Array and hash load forwarding. */ +static TRef fwd_ahload(jit_State *J, IRRef xref) +{ + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[fins->o+IRDELTA_L2S]; + while (ref > xref) { + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + + /* No conflicting store (yet): const-fold loads from allocations. */ + { + IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr; + IRRef tab = ir->op1; + ir = IR(tab); + if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) { + /* A NEWREF with a number key may end up pointing to the array part. + ** But it's referenced from HSTORE and not found in the ASTORE chain. + ** For now simply consider this a conflict without forwarding anything. + */ + if (xr->o == IR_AREF) { + IRRef ref2 = J->chain[IR_NEWREF]; + while (ref2 > tab) { + IRIns *newref = IR(ref2); + if (irt_isnum(IR(newref->op2)->t)) + goto cselim; + ref2 = newref->prev; + } + } + /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF. + ** But the above search for conflicting stores was limited by xref. + ** So continue searching, limited by the TNEW/TDUP. Store forwarding + ** is ok, too. A conflict does NOT limit the search for a matching load. + */ + while (ref > tab) { + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: goto cselim; /* Conflicting store. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + lua_assert(ir->o != IR_TNEW || irt_isnil(fins->t)); + if (irt_ispri(fins->t)) { + return TREF_PRI(irt_type(fins->t)); + } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) || + irt_isstr(fins->t)) { + TValue keyv; + cTValue *tv; + IRIns *key = IR(xr->op2); + if (key->o == IR_KSLOT) key = IR(key->op1); + lj_ir_kvalue(J->L, &keyv, key); + tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv); + lua_assert(itype2irt(tv) == irt_type(fins->t)); + if (irt_isnum(fins->t)) + return lj_ir_knum_u64(J, tv->u64); + else if (LJ_DUALNUM && irt_isint(fins->t)) + return lj_ir_kint(J, intV(tv)); + else + return lj_ir_kstr(J, strV(tv)); + } + /* Othwerwise: don't intern as a constant. */ + } + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + ref = J->chain[fins->o]; + while (ref > lim) { + IRIns *load = IR(ref); + if (load->op1 == xref) + return ref; /* Load forwarding. */ + ref = load->prev; + } + return 0; /* Conflict or no match. */ +} + +/* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */ +static TRef fwd_aload_reassoc(jit_State *J) +{ + IRIns *irx = IR(fins->op1); + IRIns *key = IR(irx->op2); + if (key->o == IR_ADD && irref_isk(key->op2)) { + IRIns *add2 = IR(key->op1); + if (add2->o == IR_ADD && irref_isk(add2->op2) && + IR(key->op2)->i == -IR(add2->op2)->i) { + IRRef ref = J->chain[IR_AREF]; + IRRef lim = add2->op1; + if (irx->op1 > lim) lim = irx->op1; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == irx->op1 && ir->op2 == add2->op1) + return fwd_ahload(J, ref); + ref = ir->prev; + } + } + } + return 0; +} + +/* ALOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J) +{ + IRRef ref; + if ((ref = fwd_ahload(J, fins->op1)) || + (ref = fwd_aload_reassoc(J))) + return ref; + return EMITFOLD; +} + +/* HLOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J) +{ + IRRef ref = fwd_ahload(J, fins->op1); + if (ref) + return ref; + return EMITFOLD; +} + +/* HREFK forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J) +{ + IRRef tab = fleft->op1; + IRRef ref = J->chain[IR_NEWREF]; + while (ref > tab) { + IRIns *newref = IR(ref); + if (tab == newref->op1) { + if (fright->op1 == newref->op2) + return ref; /* Forward from NEWREF. */ + else + goto docse; + } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) { + goto docse; + } + ref = newref->prev; + } + /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */ + if (IR(tab)->o == IR_TDUP) + fins->t.irt &= ~IRT_GUARD; /* Drop HREFK guard. */ +docse: + return CSEFOLD; +} + +/* Check whether HREF of TNEW/TDUP can be folded to niltv. */ +int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J) +{ + IRRef lim = fins->op1; /* Search limit. */ + IRRef ref; + + /* The key for an ASTORE may end up in the hash part after a NEWREF. */ + if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) { + ref = J->chain[IR_ASTORE]; + while (ref > lim) { + if (ref < J->chain[IR_NEWREF]) + return 0; /* Conflict. */ + ref = IR(ref)->prev; + } + } + + /* Search for conflicting stores. */ + ref = J->chain[IR_HSTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO) + return 0; /* Conflict. */ + ref = store->prev; + } + + return 1; /* No conflict. Can fold to niltv. */ +} + +/* Check whether there's no aliasing NEWREF for the left operand. */ +int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim) +{ + IRRef ta = fins->op1; + IRRef ref = J->chain[IR_NEWREF]; + while (ref > lim) { + IRIns *newref = IR(ref); + if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO) + return 0; /* Conflict. */ + ref = newref->prev; + } + return 1; /* No conflict. Can safely FOLD/CSE. */ +} + +/* ASTORE/HSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J) +{ + IRRef xref = fins->op1; /* xREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(xref); + IRRef1 *refp = &J->chain[fins->o]; + IRRef ref = *refp; + while (ref > xref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_ahref(J, xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: /* Store to MAYBE the same location. */ + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: /* Store to the same location. */ + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards (includes conflicting loads). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || ir->o == IR_CALLL) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- ULOAD forwarding ---------------------------------------------------- */ + +/* The current alias analysis for upvalues is very simplistic. It only +** disambiguates between the unique upvalues of the same function. +** This is good enough for now, since most upvalues are read-only. +** +** A more precise analysis would be feasible with the help of the parser: +** generate a unique key for every upvalue, even across all prototypes. +** Lacking a realistic use-case, it's unclear whether this is beneficial. +*/ +static AliasRet aa_uref(IRIns *refa, IRIns *refb) +{ + if (refa->o != refb->o) + return ALIAS_NO; /* Different UREFx type. */ + if (refa->op1 == refb->op1) { /* Same function. */ + if (refa->op2 == refb->op2) + return ALIAS_MUST; /* Same function, same upvalue idx. */ + else + return ALIAS_NO; /* Same function, different upvalue idx. */ + } else { /* Different functions, check disambiguation hash values. */ + if (((refa->op2 ^ refb->op2) & 0xff)) + return ALIAS_NO; /* Upvalues with different hash values cannot alias. */ + else + return ALIAS_MAY; /* No conclusion can be drawn for same hash value. */ + } +} + +/* ULOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J) +{ + IRRef uref = fins->op1; + IRRef lim = REF_BASE; /* Search limit. */ + IRIns *xr = IR(uref); + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[IR_USTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + switch (aa_uref(xr, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + + ref = J->chain[IR_ULOAD]; + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == uref || + (IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o)) + return ref; /* Match for identical or equal UREFx (non-CSEable UREFO). */ + ref = ir->prev; + } + return lj_ir_emit(J); +} + +/* USTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J) +{ + IRRef xref = fins->op1; /* xREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(xref); + IRRef1 *refp = &J->chain[IR_USTORE]; + IRRef ref = *refp; + while (ref > xref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_uref(xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: /* Store to MAYBE the same location. */ + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: /* Store to the same location. */ + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards (includes conflicting loads). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t)) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + if (ref+1 < J->cur.nins && + store[1].o == IR_OBAR && store[1].op1 == xref) { + IRRef1 *bp = &J->chain[IR_OBAR]; + IRIns *obar; + for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp)) + bp = &obar->prev; + /* Remove OBAR, too. */ + *bp = obar->prev; + obar->o = IR_NOP; + obar->t.irt = IRT_NIL; + obar->op1 = obar->op2 = 0; + obar->prev = 0; + } + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- FLOAD forwarding and FSTORE elimination ----------------------------- */ + +/* Alias analysis for field access. +** Field loads are cheap and field stores are rare. +** Simple disambiguation based on field types is good enough. +*/ +static AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb) +{ + if (refa->op2 != refb->op2) + return ALIAS_NO; /* Different fields. */ + if (refa->op1 == refb->op1) + return ALIAS_MUST; /* Same field, same object. */ + else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM) + return aa_table(J, refa->op1, refb->op1); /* Disambiguate tables. */ + else + return ALIAS_MAY; /* Same field, possibly different object. */ +} + +/* Only the loads for mutable fields end up here (see FOLD). */ +TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J) +{ + IRRef oref = fins->op1; /* Object reference. */ + IRRef fid = fins->op2; /* Field ID. */ + IRRef lim = oref; /* Search limit. */ + IRRef ref; + + /* Search for conflicting stores. */ + ref = J->chain[IR_FSTORE]; + while (ref > oref) { + IRIns *store = IR(ref); + switch (aa_fref(J, fins, IR(store->op1))) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + + /* No conflicting store: const-fold field loads from allocations. */ + if (fid == IRFL_TAB_META) { + IRIns *ir = IR(oref); + if (ir->o == IR_TNEW || ir->o == IR_TDUP) + return lj_ir_knull(J, IRT_TAB); + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + return lj_opt_cselim(J, lim); +} + +/* FSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J) +{ + IRRef fref = fins->op1; /* FREF reference. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRIns *xr = IR(fref); + IRRef1 *refp = &J->chain[IR_FSTORE]; + IRRef ref = *refp; + while (ref > fref) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_fref(J, xr, IR(store->op1))) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards or conflicting loads. */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2)) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- XLOAD forwarding and XSTORE elimination ----------------------------- */ + +/* Find cdata allocation for a reference (if any). */ +static IRIns *aa_findcnew(jit_State *J, IRIns *ir) +{ + while (ir->o == IR_ADD) { + if (!irref_isk(ir->op1)) { + IRIns *ir1 = aa_findcnew(J, IR(ir->op1)); /* Left-recursion. */ + if (ir1) return ir1; + } + if (irref_isk(ir->op2)) return NULL; + ir = IR(ir->op2); /* Flatten right-recursion. */ + } + return ir->o == IR_CNEW ? ir : NULL; +} + +/* Alias analysis for two cdata allocations. */ +static AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb) +{ + IRIns *cnewa = aa_findcnew(J, refa); + IRIns *cnewb = aa_findcnew(J, refb); + if (cnewa == cnewb) + return ALIAS_MAY; /* Same allocation or neither is an allocation. */ + if (cnewa && cnewb) + return ALIAS_NO; /* Two different allocations never alias. */ + if (cnewb) { cnewa = cnewb; refb = refa; } + return aa_escape(J, cnewa, refb); +} + +/* Alias analysis for XLOAD/XSTORE. */ +static AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb) +{ + ptrdiff_t ofsa = 0, ofsb = 0; + IRIns *refb = IR(xb->op1); + IRIns *basea = refa, *baseb = refb; + if (refa == refb && irt_sametype(xa->t, xb->t)) + return ALIAS_MUST; /* Shortcut for same refs with identical type. */ + /* Offset-based disambiguation. */ + if (refa->o == IR_ADD && irref_isk(refa->op2)) { + IRIns *irk = IR(refa->op2); + basea = IR(refa->op1); + ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + } + if (refb->o == IR_ADD && irref_isk(refb->op2)) { + IRIns *irk = IR(refb->op2); + baseb = IR(refb->op1); + ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + } + /* Treat constified pointers like base vs. base+offset. */ + if (basea->o == IR_KPTR && baseb->o == IR_KPTR) { + ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea); + baseb = basea; + } + /* This implements (very) strict aliasing rules. + ** Different types do NOT alias, except for differences in signedness. + ** Type punning through unions is allowed (but forces a reload). + */ + if (basea == baseb) { + ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t); + if (ofsa == ofsb) { + if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t)) + return ALIAS_MUST; /* Same-sized, same-kind. May need to convert. */ + } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) { + return ALIAS_NO; /* Non-overlapping base+-o1 vs. base+-o2. */ + } + /* NYI: extract, extend or reinterpret bits (int <-> fp). */ + return ALIAS_MAY; /* Overlapping or type punning: force reload. */ + } + if (!irt_sametype(xa->t, xb->t) && + !(irt_typerange(xa->t, IRT_I8, IRT_U64) && + ((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1)) + return ALIAS_NO; + /* NYI: structural disambiguation. */ + return aa_cnew(J, basea, baseb); /* Try to disambiguate allocations. */ +} + +/* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */ +static IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2) +{ + IRRef ref = J->chain[op]; + IRRef lim = op1; + if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; } + while (ref > lim) { + IRIns *ir = IR(ref); + if (ir->op1 == op1 && ir->op2 == op2) + return ref; + ref = ir->prev; + } + return 0; +} + +/* Reassociate index references. */ +static IRRef reassoc_xref(jit_State *J, IRIns *ir) +{ + ptrdiff_t ofs = 0; + if (ir->o == IR_ADD && irref_isk(ir->op2)) { /* Get constant offset. */ + IRIns *irk = IR(ir->op2); + ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 : + (ptrdiff_t)irk->i; + ir = IR(ir->op1); + } + if (ir->o == IR_ADD) { /* Add of base + index. */ + /* Index ref > base ref for loop-carried dependences. Only check op1. */ + IRIns *ir2, *ir1 = IR(ir->op1); + int32_t shift = 0; + IRRef idxref; + /* Determine index shifts. Don't bother with IR_MUL here. */ + if (ir1->o == IR_BSHL && irref_isk(ir1->op2)) + shift = IR(ir1->op2)->i; + else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2) + shift = 1; + else + ir1 = ir; + ir2 = IR(ir1->op1); + /* A non-reassociated add. Must be a loop-carried dependence. */ + if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2)) + ofs += (ptrdiff_t)IR(ir2->op2)->i << shift; + else + return 0; + idxref = ir2->op1; + /* Try to CSE the reassociated chain. Give up if not found. */ + if (ir1 != ir && + !(idxref = reassoc_trycse(J, ir1->o, idxref, + ir1->o == IR_BSHL ? ir1->op2 : idxref))) + return 0; + if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2))) + return 0; + if (ofs != 0) { + IRRef refk = tref_ref(lj_ir_kintp(J, ofs)); + if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk))) + return 0; + } + return idxref; /* Success, found a reassociated index reference. Phew. */ + } + return 0; /* Failure. */ +} + +/* XLOAD forwarding. */ +TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J) +{ + IRRef xref = fins->op1; + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef ref; + + if ((fins->op2 & IRXLOAD_READONLY)) + goto cselim; + if ((fins->op2 & IRXLOAD_VOLATILE)) + goto doemit; + + /* Search for conflicting stores. */ + ref = J->chain[IR_XSTORE]; +retry: + if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS]; + if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR]; + while (ref > lim) { + IRIns *store = IR(ref); + switch (aa_xref(J, xr, fins, store)) { + case ALIAS_NO: break; /* Continue searching. */ + case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */ + case ALIAS_MUST: + /* Emit conversion if the loaded type doesn't match the forwarded type. */ + if (!irt_sametype(fins->t, IR(store->op2)->t)) { + IRType st = irt_type(fins->t); + if (st == IRT_I8 || st == IRT_I16) { /* Trunc + sign-extend. */ + st |= IRCONV_SEXT; + } else if (st == IRT_U8 || st == IRT_U16) { /* Trunc + zero-extend. */ + } else if (st == IRT_INT) { + st = irt_type(IR(store->op2)->t); /* Needs dummy CONV.int.*. */ + } else { /* I64/U64 are boxed, U32 is hidden behind a CONV.num.u32. */ + goto store_fwd; + } + fins->ot = IRTI(IR_CONV); + fins->op1 = store->op2; + fins->op2 = (IRT_INT<<5)|st; + return RETRYFOLD; + } + store_fwd: + return store->op2; /* Store forwarding. */ + } + ref = store->prev; + } + +cselim: + /* Try to find a matching load. Below the conflicting store, if any. */ + ref = J->chain[IR_XLOAD]; + while (ref > lim) { + /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */ + if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t)) + return ref; + ref = IR(ref)->prev; + } + + /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */ + if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] && + xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) { + ref = J->chain[IR_XSTORE]; + while (ref > lim) /* Skip stores that have already been checked. */ + ref = IR(ref)->prev; + lim = xref; + xr = IR(xref); + goto retry; /* Retry with the reassociated reference. */ + } +doemit: + return EMITFOLD; +} + +/* XSTORE elimination. */ +TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J) +{ + IRRef xref = fins->op1; + IRIns *xr = IR(xref); + IRRef lim = xref; /* Search limit. */ + IRRef val = fins->op2; /* Stored value reference. */ + IRRef1 *refp = &J->chain[IR_XSTORE]; + IRRef ref = *refp; + if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS]; + if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR]; + while (ref > lim) { /* Search for redundant or conflicting stores. */ + IRIns *store = IR(ref); + switch (aa_xref(J, xr, fins, store)) { + case ALIAS_NO: + break; /* Continue searching. */ + case ALIAS_MAY: + if (store->op2 != val) /* Conflict if the value is different. */ + goto doemit; + break; /* Otherwise continue searching. */ + case ALIAS_MUST: + if (store->op2 == val) /* Same value: drop the new store. */ + return DROPFOLD; + /* Different value: try to eliminate the redundant store. */ + if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */ + IRIns *ir; + /* Check for any intervening guards or any XLOADs (no AA performed). */ + for (ir = IR(J->cur.nins-1); ir > store; ir--) + if (irt_isguard(ir->t) || ir->o == IR_XLOAD) + goto doemit; /* No elimination possible. */ + /* Remove redundant store from chain and replace with NOP. */ + *refp = store->prev; + store->o = IR_NOP; + store->t.irt = IRT_NIL; + store->op1 = store->op2 = 0; + store->prev = 0; + /* Now emit the new store instead. */ + } + goto doemit; + } + ref = *(refp = &store->prev); + } +doemit: + return EMITFOLD; /* Otherwise we have a conflict or simply no match. */ +} + +/* -- Forwarding of lj_tab_len -------------------------------------------- */ + +/* This is rather simplistic right now, but better than nothing. */ +TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J) +{ + IRRef tab = fins->op1; /* Table reference. */ + IRRef lim = tab; /* Search limit. */ + IRRef ref; + + /* Any ASTORE is a conflict and limits the search. */ + if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE]; + + /* Search for conflicting HSTORE with numeric key. */ + ref = J->chain[IR_HSTORE]; + while (ref > lim) { + IRIns *store = IR(ref); + IRIns *href = IR(store->op1); + IRIns *key = IR(href->op2); + if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) { + lim = ref; /* Conflicting store found, limits search for TLEN. */ + break; + } + ref = store->prev; + } + + /* Try to find a matching load. Below the conflicting store, if any. */ + return lj_opt_cselim(J, lim); +} + +/* -- ASTORE/HSTORE previous type analysis -------------------------------- */ + +/* Check whether the previous value for a table store is non-nil. +** This can be derived either from a previous store or from a previous +** load (because all loads from tables perform a type check). +** +** The result of the analysis can be used to avoid the metatable check +** and the guard against HREF returning niltv. Both of these are cheap, +** so let's not spend too much effort on the analysis. +** +** A result of 1 is exact: previous value CANNOT be nil. +** A result of 0 is inexact: previous value MAY be nil. +*/ +int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref) +{ + /* First check stores. */ + IRRef ref = J->chain[loadop+IRDELTA_L2S]; + while (ref > xref) { + IRIns *store = IR(ref); + if (store->op1 == xref) { /* Same xREF. */ + /* A nil store MAY alias, but a non-nil store MUST alias. */ + return !irt_isnil(store->t); + } else if (irt_isnil(store->t)) { /* Must check any nil store. */ + IRRef skref = IR(store->op1)->op2; + IRRef xkref = IR(xref)->op2; + /* Same key type MAY alias. Need ALOAD check due to multiple int types. */ + if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) { + if (skref == xkref || !irref_isk(skref) || !irref_isk(xkref)) + return 0; /* A nil store with same const key or var key MAY alias. */ + /* Different const keys CANNOT alias. */ + } /* Different key types CANNOT alias. */ + } /* Other non-nil stores MAY alias. */ + ref = store->prev; + } + + /* Check loads since nothing could be derived from stores. */ + ref = J->chain[loadop]; + while (ref > xref) { + IRIns *load = IR(ref); + if (load->op1 == xref) { /* Same xREF. */ + /* A nil load MAY alias, but a non-nil load MUST alias. */ + return !irt_isnil(load->t); + } /* Other non-nil loads MAY alias. */ + ref = load->prev; + } + return 0; /* Nothing derived at all, previous value MAY be nil. */ +} + +/* ------------------------------------------------------------------------ */ + +#undef IR +#undef fins +#undef fleft +#undef fright + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_narrow.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_narrow.c new file mode 100644 index 0000000..2cecf65 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_narrow.c @@ -0,0 +1,648 @@ +/* +** NARROW: Narrowing of numbers to integers (double to int32_t). +** STRIPOV: Stripping of overflow checks. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_narrow_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_vm.h" +#include "lj_strscan.h" + +/* Rationale for narrowing optimizations: +** +** Lua has only a single number type and this is a FP double by default. +** Narrowing doubles to integers does not pay off for the interpreter on a +** current-generation x86/x64 machine. Most FP operations need the same +** amount of execution resources as their integer counterparts, except +** with slightly longer latencies. Longer latencies are a non-issue for +** the interpreter, since they are usually hidden by other overhead. +** +** The total CPU execution bandwidth is the sum of the bandwidth of the FP +** and the integer units, because they execute in parallel. The FP units +** have an equal or higher bandwidth than the integer units. Not using +** them means losing execution bandwidth. Moving work away from them to +** the already quite busy integer units is a losing proposition. +** +** The situation for JIT-compiled code is a bit different: the higher code +** density makes the extra latencies much more visible. Tight loops expose +** the latencies for updating the induction variables. Array indexing +** requires narrowing conversions with high latencies and additional +** guards (to check that the index is really an integer). And many common +** optimizations only work on integers. +** +** One solution would be speculative, eager narrowing of all number loads. +** This causes many problems, like losing -0 or the need to resolve type +** mismatches between traces. It also effectively forces the integer type +** to have overflow-checking semantics. This impedes many basic +** optimizations and requires adding overflow checks to all integer +** arithmetic operations (whereas FP arithmetics can do without). +** +** Always replacing an FP op with an integer op plus an overflow check is +** counter-productive on a current-generation super-scalar CPU. Although +** the overflow check branches are highly predictable, they will clog the +** execution port for the branch unit and tie up reorder buffers. This is +** turning a pure data-flow dependency into a different data-flow +** dependency (with slightly lower latency) *plus* a control dependency. +** In general, you don't want to do this since latencies due to data-flow +** dependencies can be well hidden by out-of-order execution. +** +** A better solution is to keep all numbers as FP values and only narrow +** when it's beneficial to do so. LuaJIT uses predictive narrowing for +** induction variables and demand-driven narrowing for index expressions, +** integer arguments and bit operations. Additionally it can eliminate or +** hoist most of the resulting overflow checks. Regular arithmetic +** computations are never narrowed to integers. +** +** The integer type in the IR has convenient wrap-around semantics and +** ignores overflow. Extra operations have been added for +** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type. +** Apart from reducing overall complexity of the compiler, this also +** nicely solves the problem where you want to apply algebraic +** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can +** use lea instead of an add for integer ADD, but not for ADDOV (lea does +** not affect the flags, but it helps to avoid register moves). +** +** +** All of the above has to be reconsidered for architectures with slow FP +** operations or without a hardware FPU. The dual-number mode of LuaJIT +** addresses this issue. Arithmetic operations are performed on integers +** as far as possible and overflow checks are added as needed. +** +** This implies that narrowing for integer arguments and bit operations +** should also strip overflow checks, e.g. replace ADDOV with ADD. The +** original overflow guards are weak and can be eliminated by DCE, if +** there's no other use. +** +** A slight twist is that it's usually beneficial to use overflow-checked +** integer arithmetics if all inputs are already integers. This is the only +** change that affects the single-number mode, too. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) +#define fins (&J->fold.ins) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Elimination of narrowing type conversions --------------------------- */ + +/* Narrowing of index expressions and bit operations is demand-driven. The +** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT) +** in all of these cases (e.g. array indexing or string indexing). FOLD +** already takes care of eliminating simple redundant conversions like +** CONV.int.num(CONV.num.int(x)) ==> x. +** +** But the surrounding code is FP-heavy and arithmetic operations are +** performed on FP numbers (for the single-number mode). Consider a common +** example such as 'x=t[i+1]', with 'i' already an integer (due to induction +** variable narrowing). The index expression would be recorded as +** CONV.int.num(ADD(CONV.num.int(i), 1)) +** which is clearly suboptimal. +** +** One can do better by recursively backpropagating the narrowing type +** conversion across FP arithmetic operations. This turns FP ops into +** their corresponding integer counterparts. Depending on the semantics of +** the conversion they also need to check for overflow. Currently only ADD +** and SUB are supported. +** +** The above example can be rewritten as +** ADDOV(CONV.int.num(CONV.num.int(i)), 1) +** and then into ADDOV(i, 1) after folding of the conversions. The original +** FP ops remain in the IR and are eliminated by DCE since all references to +** them are gone. +** +** [In dual-number mode the trace recorder already emits ADDOV etc., but +** this can be further reduced. See below.] +** +** Special care has to be taken to avoid narrowing across an operation +** which is potentially operating on non-integral operands. One obvious +** case is when an expression contains a non-integral constant, but ends +** up as an integer index at runtime (like t[x+1.5] with x=0.5). +** +** Operations with two non-constant operands illustrate a similar problem +** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there, +** unless it can be proven that either operand is integral (e.g. by CSEing +** a previous conversion). As a not-so-obvious corollary this logic also +** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]). +** +** Correctness of the transformation is guaranteed by avoiding to expand +** the tree by adding more conversions than the one we would need to emit +** if not backpropagating. TOBIT employs a more optimistic rule, because +** the conversion has special semantics, designed to make the life of the +** compiler writer easier. ;-) +** +** Using on-the-fly backpropagation of an expression tree doesn't work +** because it's unknown whether the transform is correct until the end. +** This either requires IR rollback and cache invalidation for every +** subtree or a two-pass algorithm. The former didn't work out too well, +** so the code now combines a recursive collector with a stack-based +** emitter. +** +** [A recursive backpropagation algorithm with backtracking, employing +** skip-list lookup and round-robin caching, emitting stack operations +** on-the-fly for a stack-based interpreter -- and all of that in a meager +** kilobyte? Yep, compilers are a great treasure chest. Throw away your +** textbooks and read the codebase of a compiler today!] +** +** There's another optimization opportunity for array indexing: it's +** always accompanied by an array bounds-check. The outermost overflow +** check may be delegated to the ABC operation. This works because ABC is +** an unsigned comparison and wrap-around due to overflow creates negative +** numbers. +** +** But this optimization is only valid for constants that cannot overflow +** an int32_t into the range of valid array indexes [0..2^27+1). A check +** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30 +** wraps to -2^30-1. +** +** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are +** quite common. So the above example finally ends up as ADD(i, 1)! +** +** Later on, the assembler is able to fuse the whole array reference and +** the ADD into the memory operands of loads and other instructions. This +** is why LuaJIT is able to generate very pretty (and fast) machine code +** for array indexing. And that, my dear, concludes another story about +** one of the hidden secrets of LuaJIT ... +*/ + +/* Maximum backpropagation depth and maximum stack size. */ +#define NARROW_MAX_BACKPROP 100 +#define NARROW_MAX_STACK 256 + +/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1] +** The lower 16 bits hold a reference (or 0). The upper 16 bits hold +** the IR opcode + type or one of the following special opcodes: +*/ +enum { + NARROW_REF, /* Push ref. */ + NARROW_CONV, /* Push conversion of ref. */ + NARROW_SEXT, /* Push sign-extension of ref. */ + NARROW_INT /* Push KINT ref. The next code holds an int32_t. */ +}; + +typedef uint32_t NarrowIns; + +#define NARROWINS(op, ref) (((op) << 16) + (ref)) +#define narrow_op(ins) ((IROpT)((ins) >> 16)) +#define narrow_ref(ins) ((IRRef1)(ins)) + +/* Context used for narrowing of type conversions. */ +typedef struct NarrowConv { + jit_State *J; /* JIT compiler state. */ + NarrowIns *sp; /* Current stack pointer. */ + NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */ + int lim; /* Limit on the number of emitted conversions. */ + IRRef mode; /* Conversion mode (IRCONV_*). */ + IRType t; /* Destination type: IRT_INT or IRT_I64. */ + NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */ +} NarrowConv; + +/* Lookup a reference in the backpropagation cache. */ +static BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode) +{ + ptrdiff_t i; + for (i = 0; i < BPROP_SLOTS; i++) { + BPropEntry *bp = &J->bpropcache[i]; + /* Stronger checks are ok, too. */ + if (bp->key == key && bp->mode >= mode && + ((bp->mode ^ mode) & IRCONV_MODEMASK) == 0) + return bp; + } + return NULL; +} + +/* Add an entry to the backpropagation cache. */ +static void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode) +{ + uint32_t slot = J->bpropslot; + BPropEntry *bp = &J->bpropcache[slot]; + J->bpropslot = (slot + 1) & (BPROP_SLOTS-1); + bp->key = key; + bp->val = val; + bp->mode = mode; +} + +/* Backpropagate overflow stripping. */ +static void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth) +{ + jit_State *J = nc->J; + IRIns *ir = IR(ref); + if (ir->o == IR_ADDOV || ir->o == IR_SUBOV || + (ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) { + BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT); + if (bp) { + ref = bp->val; + } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { + narrow_stripov_backprop(nc, ir->op1, depth); + narrow_stripov_backprop(nc, ir->op2, depth); + *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref); + return; + } + } + *nc->sp++ = NARROWINS(NARROW_REF, ref); +} + +/* Backpropagate narrowing conversion. Return number of needed conversions. */ +static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth) +{ + jit_State *J = nc->J; + IRIns *ir = IR(ref); + IRRef cref; + + /* Check the easy cases first. */ + if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) { + if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY) + narrow_stripov_backprop(nc, ir->op1, depth+1); + else + *nc->sp++ = NARROWINS(NARROW_REF, ir->op1); /* Undo conversion. */ + if (nc->t == IRT_I64) + *nc->sp++ = NARROWINS(NARROW_SEXT, 0); /* Sign-extend integer. */ + return 0; + } else if (ir->o == IR_KNUM) { /* Narrow FP constant. */ + lua_Number n = ir_knum(ir)->n; + if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) { + /* Allows a wider range of constants. */ + int64_t k64 = (int64_t)n; + if (n == (lua_Number)k64) { /* Only if const doesn't lose precision. */ + *nc->sp++ = NARROWINS(NARROW_INT, 0); + *nc->sp++ = (NarrowIns)k64; /* But always truncate to 32 bits. */ + return 0; + } + } else { + int32_t k = lj_num2int(n); + /* Only if constant is a small integer. */ + if (checki16(k) && n == (lua_Number)k) { + *nc->sp++ = NARROWINS(NARROW_INT, 0); + *nc->sp++ = (NarrowIns)k; + return 0; + } + } + return 10; /* Never narrow other FP constants (this is rare). */ + } + + /* Try to CSE the conversion. Stronger checks are ok, too. */ + cref = J->chain[fins->o]; + while (cref > ref) { + IRIns *cr = IR(cref); + if (cr->op1 == ref && + (fins->o == IR_TOBIT || + ((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) && + irt_isguard(cr->t) >= irt_isguard(fins->t)))) { + *nc->sp++ = NARROWINS(NARROW_REF, cref); + return 0; /* Already there, no additional conversion needed. */ + } + cref = cr->prev; + } + + /* Backpropagate across ADD/SUB. */ + if (ir->o == IR_ADD || ir->o == IR_SUB) { + /* Try cache lookup first. */ + IRRef mode = nc->mode; + BPropEntry *bp; + /* Inner conversions need a stronger check. */ + if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0) + mode += IRCONV_CHECK-IRCONV_INDEX; + bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode); + if (bp) { + *nc->sp++ = NARROWINS(NARROW_REF, bp->val); + return 0; + } else if (nc->t == IRT_I64) { + /* Try sign-extending from an existing (checked) conversion to int. */ + mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX; + bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode); + if (bp) { + *nc->sp++ = NARROWINS(NARROW_REF, bp->val); + *nc->sp++ = NARROWINS(NARROW_SEXT, 0); + return 0; + } + } + if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { + NarrowIns *savesp = nc->sp; + int count = narrow_conv_backprop(nc, ir->op1, depth); + count += narrow_conv_backprop(nc, ir->op2, depth); + if (count <= nc->lim) { /* Limit total number of conversions. */ + *nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref); + return count; + } + nc->sp = savesp; /* Too many conversions, need to backtrack. */ + } + } + + /* Otherwise add a conversion. */ + *nc->sp++ = NARROWINS(NARROW_CONV, ref); + return 1; +} + +/* Emit the conversions collected during backpropagation. */ +static IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc) +{ + /* The fins fields must be saved now -- emitir() overwrites them. */ + IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0; + IROpT convot = fins->ot; + IRRef1 convop2 = fins->op2; + NarrowIns *next = nc->stack; /* List of instructions from backpropagation. */ + NarrowIns *last = nc->sp; + NarrowIns *sp = nc->stack; /* Recycle the stack to store operands. */ + while (next < last) { /* Simple stack machine to process the ins. list. */ + NarrowIns ref = *next++; + IROpT op = narrow_op(ref); + if (op == NARROW_REF) { + *sp++ = ref; + } else if (op == NARROW_CONV) { + *sp++ = emitir_raw(convot, ref, convop2); /* Raw emit avoids a loop. */ + } else if (op == NARROW_SEXT) { + lua_assert(sp >= nc->stack+1); + sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1], + (IRT_I64<<5)|IRT_INT|IRCONV_SEXT); + } else if (op == NARROW_INT) { + lua_assert(next < last); + *sp++ = nc->t == IRT_I64 ? + lj_ir_kint64(J, (int64_t)(int32_t)*next++) : + lj_ir_kint(J, *next++); + } else { /* Regular IROpT. Pops two operands and pushes one result. */ + IRRef mode = nc->mode; + lua_assert(sp >= nc->stack+2); + sp--; + /* Omit some overflow checks for array indexing. See comments above. */ + if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) { + if (next == last && irref_isk(narrow_ref(sp[0])) && + (uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u) + guardot = 0; + else /* Otherwise cache a stronger check. */ + mode += IRCONV_CHECK-IRCONV_INDEX; + } + sp[-1] = emitir(op+guardot, sp[-1], sp[0]); + /* Add to cache. */ + if (narrow_ref(ref)) + narrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode); + } + } + lua_assert(sp == nc->stack+1); + return nc->stack[0]; +} + +/* Narrow a type conversion of an arithmetic operation. */ +TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J) +{ + if ((J->flags & JIT_F_OPT_NARROW)) { + NarrowConv nc; + nc.J = J; + nc.sp = nc.stack; + nc.maxsp = &nc.stack[NARROW_MAX_STACK-4]; + nc.t = irt_type(fins->t); + if (fins->o == IR_TOBIT) { + nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */ + nc.lim = 2; /* TOBIT can use a more optimistic rule. */ + } else { + nc.mode = fins->op2; + nc.lim = 1; + } + if (narrow_conv_backprop(&nc, fins->op1, 0) <= nc.lim) + return narrow_conv_emit(J, &nc); + } + return NEXTFOLD; +} + +/* -- Narrowing of implicit conversions ----------------------------------- */ + +/* Recursively strip overflow checks. */ +static TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode) +{ + IRRef ref = tref_ref(tr); + IRIns *ir = IR(ref); + int op = ir->o; + if (op >= IR_ADDOV && op <= lastop) { + BPropEntry *bp = narrow_bpc_get(J, ref, mode); + if (bp) { + return TREF(bp->val, irt_t(IR(bp->val)->t)); + } else { + IRRef op1 = ir->op1, op2 = ir->op2; /* The IR may be reallocated. */ + op1 = narrow_stripov(J, op1, lastop, mode); + op2 = narrow_stripov(J, op2, lastop, mode); + tr = emitir(IRT(op - IR_ADDOV + IR_ADD, + ((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2); + narrow_bpc_set(J, ref, tref_ref(tr), mode); + } + } else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) { + tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode); + } + return tr; +} + +/* Narrow array index. */ +TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr) +{ + IRIns *ir; + lua_assert(tref_isnumber(tr)); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX); + /* Omit some overflow checks for array indexing. See comments above. */ + ir = IR(tref_ref(tr)); + if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) && + (uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u) + return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2); + return tr; +} + +/* Narrow conversion to integer operand (overflow undefined). */ +TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr) +{ + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY); + if (!tref_isinteger(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* + ** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. + ** Use IRCONV_TOBIT for the cache entries, since the semantics are the same. + */ + return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT); +} + +/* Narrow conversion to bitop operand (overflow wrapped). */ +TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr) +{ + if (tref_isstr(tr)) + tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); + if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */ + return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J)); + if (!tref_isinteger(tr)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* + ** Wrapped overflow semantics allow stripping of ADDOV and SUBOV. + ** MULOV cannot be stripped due to precision widening. + */ + return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT); +} + +#if LJ_HASFFI +/* Narrow C array index (overflow undefined). */ +TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr) +{ + lua_assert(tref_isnumber(tr)); + if (tref_isnum(tr)) + return emitir(IRT(IR_CONV, IRT_INTP), tr, + (IRT_INTP<<5)|IRT_NUM|IRCONV_TRUNC|IRCONV_ANY); + /* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */ + return narrow_stripov(J, tr, IR_MULOV, + LJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) : + ((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT)); +} +#endif + +/* -- Narrowing of arithmetic operators ----------------------------------- */ + +/* Check whether a number fits into an int32_t (-0 is ok, too). */ +static int numisint(lua_Number n) +{ + return (n == (lua_Number)lj_num2int(n)); +} + +/* Narrowing of arithmetic operations. */ +TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc, + TValue *vb, TValue *vc, IROp op) +{ + if (tref_isstr(rb)) { + rb = emitir(IRTG(IR_STRTO, IRT_NUM), rb, 0); + lj_strscan_num(strV(vb), vb); + } + if (tref_isstr(rc)) { + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + lj_strscan_num(strV(vc), vc); + } + /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */ + if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) && + tref_isinteger(rb) && tref_isinteger(rc) && + numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc), + (int)op - (int)IR_ADD))) + return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc); + if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT); + if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + return emitir(IRTN(op), rb, rc); +} + +/* Narrowing of unary minus operator. */ +TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc) +{ + if (tref_isstr(rc)) { + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + lj_strscan_num(strV(vc), vc); + } + if (tref_isinteger(rc)) { + if ((uint32_t)numberVint(vc) != 0x80000000u) + return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc); + rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + } + return emitir(IRTN(IR_NEG), rc, lj_ir_knum_neg(J)); +} + +/* Narrowing of modulo operator. */ +TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc) +{ + TRef tmp; + if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) && + tref_isinteger(rb) && tref_isinteger(rc) && + (tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) { + emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0)); + return emitir(IRTI(IR_MOD), rb, rc); + } + /* b % c ==> b - floor(b/c)*c */ + rb = lj_ir_tonum(J, rb); + rc = lj_ir_tonum(J, rc); + tmp = emitir(IRTN(IR_DIV), rb, rc); + tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR); + tmp = emitir(IRTN(IR_MUL), tmp, rc); + return emitir(IRTN(IR_SUB), rb, tmp); +} + +/* Narrowing of power operator or math.pow. */ +TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc) +{ + if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc)) + lj_trace_err(J, LJ_TRERR_BADTYPE); + /* Narrowing must be unconditional to preserve (-x)^i semantics. */ + if (tvisint(vc) || numisint(numV(vc))) { + int checkrange = 0; + /* Split pow is faster for bigger exponents. But do this only for (+k)^i. */ + if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) { + int32_t k = numberVint(vc); + if (!(k >= -65536 && k <= 65536)) goto split_pow; + checkrange = 1; + } + if (!tref_isinteger(rc)) { + if (tref_isstr(rc)) + rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0); + /* Guarded conversion to integer! */ + rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK); + } + if (checkrange && !tref_isk(rc)) { /* Range guard: -65536 <= i <= 65536 */ + TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536)); + emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536)); + } + return emitir(IRTN(IR_POW), rb, rc); + } +split_pow: + /* FOLD covers most cases, but some are easier to do here. */ + if (tref_isk(rb) && tvispone(ir_knum(IR(tref_ref(rb))))) + return rb; /* 1 ^ x ==> 1 */ + rc = lj_ir_tonum(J, rc); + if (tref_isk(rc) && ir_knum(IR(tref_ref(rc)))->n == 0.5) + return emitir(IRTN(IR_FPMATH), rb, IRFPM_SQRT); /* x ^ 0.5 ==> sqrt(x) */ + /* Split up b^c into exp2(c*log2(b)). Assembler may rejoin later. */ + rb = emitir(IRTN(IR_FPMATH), rb, IRFPM_LOG2); + rc = emitir(IRTN(IR_MUL), rb, rc); + return emitir(IRTN(IR_FPMATH), rc, IRFPM_EXP2); +} + +/* -- Predictive narrowing of induction variables ------------------------- */ + +/* Narrow a single runtime value. */ +static int narrow_forl(jit_State *J, cTValue *o) +{ + if (tvisint(o)) return 1; + if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o)); + return 0; +} + +/* Narrow the FORL index type by looking at the runtime values. */ +IRType lj_opt_narrow_forl(jit_State *J, cTValue *tv) +{ + lua_assert(tvisnumber(&tv[FORL_IDX]) && + tvisnumber(&tv[FORL_STOP]) && + tvisnumber(&tv[FORL_STEP])); + /* Narrow only if the runtime values of start/stop/step are all integers. */ + if (narrow_forl(J, &tv[FORL_IDX]) && + narrow_forl(J, &tv[FORL_STOP]) && + narrow_forl(J, &tv[FORL_STEP])) { + /* And if the loop index can't possibly overflow. */ + lua_Number step = numberVnum(&tv[FORL_STEP]); + lua_Number sum = numberVnum(&tv[FORL_STOP]) + step; + if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0)) + return IRT_INT; + } + return IRT_NUM; +} + +#undef IR +#undef fins +#undef emitir +#undef emitir_raw + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_sink.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_sink.c new file mode 100644 index 0000000..3a33346 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_sink.c @@ -0,0 +1,245 @@ +/* +** SINK: Allocation Sinking and Store Sinking. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_sink_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_target.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Check whether the store ref points to an eligible allocation. */ +static IRIns *sink_checkalloc(jit_State *J, IRIns *irs) +{ + IRIns *ir = IR(irs->op1); + if (!irref_isk(ir->op2)) + return NULL; /* Non-constant key. */ + if (ir->o == IR_HREFK || ir->o == IR_AREF) + ir = IR(ir->op1); + else if (!(ir->o == IR_HREF || ir->o == IR_NEWREF || + ir->o == IR_FREF || ir->o == IR_ADD)) + return NULL; /* Unhandled reference type (for XSTORE). */ + ir = IR(ir->op1); + if (!(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW)) + return NULL; /* Not an allocation. */ + return ir; /* Return allocation. */ +} + +/* Recursively check whether a value depends on a PHI. */ +static int sink_phidep(jit_State *J, IRRef ref) +{ + IRIns *ir = IR(ref); + if (irt_isphi(ir->t)) return 1; + if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1; + if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1; + return 0; +} + +/* Check whether a value is a sinkable PHI or loop-invariant. */ +static int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref) +{ + if (ref >= REF_FIRST) { + IRIns *ir = IR(ref); + if (irt_isphi(ir->t) || (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && + irt_isphi(IR(ir->op1)->t))) { + ira->prev++; + return 1; /* Sinkable PHI. */ + } + /* Otherwise the value must be loop-invariant. */ + return ref < J->loopref && !sink_phidep(J, ref); + } + return 1; /* Constant (non-PHI). */ +} + +/* Mark non-sinkable allocations using single-pass backward propagation. +** +** Roots for the marking process are: +** - Some PHIs or snapshots (see below). +** - Non-PHI, non-constant values stored to PHI allocations. +** - All guards. +** - Any remaining loads not eliminated by store-to-load forwarding. +** - Stores with non-constant keys. +** - All stored values. +*/ +static void sink_mark_ins(jit_State *J) +{ + IRIns *ir, *irlast = IR(J->cur.nins-1); + for (ir = irlast ; ; ir--) { + switch (ir->o) { + case IR_BASE: + return; /* Finished. */ + case IR_CALLL: /* IRCALL_lj_tab_len */ + case IR_ALOAD: case IR_HLOAD: case IR_XLOAD: case IR_TBAR: + irt_setmark(IR(ir->op1)->t); /* Mark ref for remaining loads. */ + break; + case IR_FLOAD: + if (irt_ismarked(ir->t) || ir->op2 == IRFL_TAB_META) + irt_setmark(IR(ir->op1)->t); /* Mark table for remaining loads. */ + break; + case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: { + IRIns *ira = sink_checkalloc(J, ir); + if (!ira || (irt_isphi(ira->t) && !sink_checkphi(J, ira, ir->op2))) + irt_setmark(IR(ir->op1)->t); /* Mark ineligible ref. */ + irt_setmark(IR(ir->op2)->t); /* Mark stored value. */ + break; + } +#if LJ_HASFFI + case IR_CNEWI: + if (irt_isphi(ir->t) && + (!sink_checkphi(J, ir, ir->op2) || + (LJ_32 && ir+1 < irlast && (ir+1)->o == IR_HIOP && + !sink_checkphi(J, ir, (ir+1)->op2)))) + irt_setmark(ir->t); /* Mark ineligible allocation. */ + /* fallthrough */ +#endif + case IR_USTORE: + irt_setmark(IR(ir->op2)->t); /* Mark stored value. */ + break; +#if LJ_HASFFI + case IR_CALLXS: +#endif + case IR_CALLS: + irt_setmark(IR(ir->op1)->t); /* Mark (potentially) stored values. */ + break; + case IR_PHI: { + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + irl->prev = irr->prev = 0; /* Clear PHI value counts. */ + if (irl->o == irr->o && + (irl->o == IR_TNEW || irl->o == IR_TDUP || + (LJ_HASFFI && (irl->o == IR_CNEW || irl->o == IR_CNEWI)))) + break; + irt_setmark(irl->t); + irt_setmark(irr->t); + break; + } + default: + if (irt_ismarked(ir->t) || irt_isguard(ir->t)) { /* Propagate mark. */ + if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t); + if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t); + } + break; + } + } +} + +/* Mark all instructions referenced by a snapshot. */ +static void sink_mark_snap(jit_State *J, SnapShot *snap) +{ + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + IRRef ref = snap_ref(map[n]); + if (!irref_isk(ref)) + irt_setmark(IR(ref)->t); + } +} + +/* Iteratively remark PHI refs with differing marks or PHI value counts. */ +static void sink_remark_phi(jit_State *J) +{ + IRIns *ir; + int remark; + do { + remark = 0; + for (ir = IR(J->cur.nins-1); ir->o == IR_PHI; ir--) { + IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); + if (((irl->t.irt ^ irr->t.irt) & IRT_MARK)) + remark = 1; + else if (irl->prev == irr->prev) + continue; + irt_setmark(IR(ir->op1)->t); + irt_setmark(IR(ir->op2)->t); + } + } while (remark); +} + +/* Sweep instructions and tag sunken allocations and stores. */ +static void sink_sweep_ins(jit_State *J) +{ + IRIns *ir, *irfirst = IR(J->cur.nk); + for (ir = IR(J->cur.nins-1) ; ir >= irfirst; ir--) { + switch (ir->o) { + case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: { + IRIns *ira = sink_checkalloc(J, ir); + if (ira && !irt_ismarked(ira->t)) { + int delta = (int)(ir - ira); + ir->prev = REGSP(RID_SINK, delta > 255 ? 255 : delta); + } else { + ir->prev = REGSP_INIT; + } + break; + } + case IR_NEWREF: + if (!irt_ismarked(IR(ir->op1)->t)) { + ir->prev = REGSP(RID_SINK, 0); + } else { + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + } + break; +#if LJ_HASFFI + case IR_CNEW: case IR_CNEWI: +#endif + case IR_TNEW: case IR_TDUP: + if (!irt_ismarked(ir->t)) { + ir->t.irt &= ~IRT_GUARD; + ir->prev = REGSP(RID_SINK, 0); + J->cur.sinktags = 1; /* Signal present SINK tags to assembler. */ + } else { + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + } + break; + case IR_PHI: { + IRIns *ira = IR(ir->op2); + if (!irt_ismarked(ira->t) && + (ira->o == IR_TNEW || ira->o == IR_TDUP || + (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI)))) { + ir->prev = REGSP(RID_SINK, 0); + } else { + ir->prev = REGSP_INIT; + } + break; + } + default: + irt_clearmark(ir->t); + ir->prev = REGSP_INIT; + break; + } + } +} + +/* Allocation sinking and store sinking. +** +** 1. Mark all non-sinkable allocations. +** 2. Then sink all remaining allocations and the related stores. +*/ +void lj_opt_sink(jit_State *J) +{ + const uint32_t need = (JIT_F_OPT_SINK|JIT_F_OPT_FWD| + JIT_F_OPT_DCE|JIT_F_OPT_CSE|JIT_F_OPT_FOLD); + if ((J->flags & need) == need && + (J->chain[IR_TNEW] || J->chain[IR_TDUP] || + (LJ_HASFFI && (J->chain[IR_CNEW] || J->chain[IR_CNEWI])))) { + if (!J->loopref) + sink_mark_snap(J, &J->cur.snap[J->cur.nsnap-1]); + sink_mark_ins(J); + if (J->loopref) + sink_remark_phi(J); + sink_sweep_ins(J); + } +} + +#undef IR + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_split.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_split.c new file mode 100644 index 0000000..99d1058 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_opt_split.c @@ -0,0 +1,731 @@ +/* +** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_opt_split_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT && (LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_vm.h" + +/* SPLIT pass: +** +** This pass splits up 64 bit IR instructions into multiple 32 bit IR +** instructions. It's only active for soft-float targets or for 32 bit CPUs +** which lack native 64 bit integer operations (the FFI is currently the +** only emitter for 64 bit integer instructions). +** +** Splitting the IR in a separate pass keeps each 32 bit IR assembler +** backend simple. Only a small amount of extra functionality needs to be +** implemented. This is much easier than adding support for allocating +** register pairs to each backend (believe me, I tried). A few simple, but +** important optimizations can be performed by the SPLIT pass, which would +** be tedious to do in the backend. +** +** The basic idea is to replace each 64 bit IR instruction with its 32 bit +** equivalent plus an extra HIOP instruction. The splitted IR is not passed +** through FOLD or any other optimizations, so each HIOP is guaranteed to +** immediately follow it's counterpart. The actual functionality of HIOP is +** inferred from the previous instruction. +** +** The operands of HIOP hold the hiword input references. The output of HIOP +** is the hiword output reference, which is also used to hold the hiword +** register or spill slot information. The register allocator treats this +** instruction independently of any other instruction, which improves code +** quality compared to using fixed register pairs. +** +** It's easier to split up some instructions into two regular 32 bit +** instructions. E.g. XLOAD is split up into two XLOADs with two different +** addresses. Obviously 64 bit constants need to be split up into two 32 bit +** constants, too. Some hiword instructions can be entirely omitted, e.g. +** when zero-extending a 32 bit value to 64 bits. 64 bit arguments for calls +** are split up into two 32 bit arguments each. +** +** On soft-float targets, floating-point instructions are directly converted +** to soft-float calls by the SPLIT pass (except for comparisons and MIN/MAX). +** HIOP for number results has the type IRT_SOFTFP ("sfp" in -jdump). +** +** Here's the IR and x64 machine code for 'x.b = x.a + 1' for a struct with +** two int64_t fields: +** +** 0100 p32 ADD base +8 +** 0101 i64 XLOAD 0100 +** 0102 i64 ADD 0101 +1 +** 0103 p32 ADD base +16 +** 0104 i64 XSTORE 0103 0102 +** +** mov rax, [esi+0x8] +** add rax, +0x01 +** mov [esi+0x10], rax +** +** Here's the transformed IR and the x86 machine code after the SPLIT pass: +** +** 0100 p32 ADD base +8 +** 0101 int XLOAD 0100 +** 0102 p32 ADD base +12 +** 0103 int XLOAD 0102 +** 0104 int ADD 0101 +1 +** 0105 int HIOP 0103 +0 +** 0106 p32 ADD base +16 +** 0107 int XSTORE 0106 0104 +** 0108 int HIOP 0106 0105 +** +** mov eax, [esi+0x8] +** mov ecx, [esi+0xc] +** add eax, +0x01 +** adc ecx, +0x00 +** mov [esi+0x10], eax +** mov [esi+0x14], ecx +** +** You may notice the reassociated hiword address computation, which is +** later fused into the mov operands by the assembler. +*/ + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Directly emit the transformed IR without updating chains etc. */ +static IRRef split_emit(jit_State *J, uint16_t ot, IRRef1 op1, IRRef1 op2) +{ + IRRef nref = lj_ir_nextins(J); + IRIns *ir = IR(nref); + ir->ot = ot; + ir->op1 = op1; + ir->op2 = op2; + return nref; +} + +#if LJ_SOFTFP +/* Emit a (checked) number to integer conversion. */ +static IRRef split_num2int(jit_State *J, IRRef lo, IRRef hi, int check) +{ + IRRef tmp, res; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), lo, hi); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hi, lo); +#endif + res = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_softfp_d2i); + if (check) { + tmp = split_emit(J, IRTI(IR_CALLN), res, IRCALL_softfp_i2d); + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); + split_emit(J, IRTGI(IR_EQ), tmp, lo); + split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), tmp+1, hi); + } + return res; +} + +/* Emit a CALLN with one split 64 bit argument. */ +static IRRef split_call_l(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); +} + +/* Emit a CALLN with one split 64 bit argument and a 32 bit argument. */ +static IRRef split_call_li(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1, op2 = ir->op2; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); +} +#endif + +/* Emit a CALLN with two split 64 bit arguments. */ +static IRRef split_call_ll(jit_State *J, IRRef1 *hisubst, IRIns *oir, + IRIns *ir, IRCallID id) +{ + IRRef tmp, op1 = ir->op1, op2 = ir->op2; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev); +#endif + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id); + return split_emit(J, + IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT), + tmp, tmp); +} + +/* Get a pointer to the other 32 bit word (LE: hiword, BE: loword). */ +static IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref) +{ + IRRef nref = oir[ref].prev; + IRIns *ir = IR(nref); + int32_t ofs = 4; + if (ir->o == IR_KPTR) + return lj_ir_kptr(J, (char *)ir_kptr(ir) + ofs); + if (ir->o == IR_ADD && irref_isk(ir->op2) && !irt_isphi(oir[ref].t)) { + /* Reassociate address. */ + ofs += IR(ir->op2)->i; + nref = ir->op1; + if (ofs == 0) return nref; + } + return split_emit(J, IRTI(IR_ADD), nref, lj_ir_kint(J, ofs)); +} + +/* Substitute references of a snapshot. */ +static void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir) +{ + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRIns *ir = &oir[snap_ref(sn)]; + if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn)))) + map[n] = ((sn & 0xffff0000) | ir->prev); + } +} + +/* Transform the old IR to the new IR. */ +static void split_ir(jit_State *J) +{ + IRRef nins = J->cur.nins, nk = J->cur.nk; + MSize irlen = nins - nk; + MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1)); + IRIns *oir = (IRIns *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, need); + IRRef1 *hisubst; + IRRef ref, snref; + SnapShot *snap; + + /* Copy old IR to buffer. */ + memcpy(oir, IR(nk), irlen*sizeof(IRIns)); + /* Bias hiword substitution table and old IR. Loword kept in field prev. */ + hisubst = (IRRef1 *)&oir[irlen] - nk; + oir -= nk; + + /* Remove all IR instructions, but retain IR constants. */ + J->cur.nins = REF_FIRST; + J->loopref = 0; + + /* Process constants and fixed references. */ + for (ref = nk; ref <= REF_BASE; ref++) { + IRIns *ir = &oir[ref]; + if ((LJ_SOFTFP && ir->o == IR_KNUM) || ir->o == IR_KINT64) { + /* Split up 64 bit constant. */ + TValue tv = *ir_k64(ir); + ir->prev = lj_ir_kint(J, (int32_t)tv.u32.lo); + hisubst[ref] = lj_ir_kint(J, (int32_t)tv.u32.hi); + } else { + ir->prev = ref; /* Identity substitution for loword. */ + hisubst[ref] = 0; + } + } + + /* Process old IR instructions. */ + snap = J->cur.snap; + snref = snap->ref; + for (ref = REF_FIRST; ref < nins; ref++) { + IRIns *ir = &oir[ref]; + IRRef nref = lj_ir_nextins(J); + IRIns *nir = IR(nref); + IRRef hi = 0; + + if (ref >= snref) { + snap->ref = nref; + split_subst_snap(J, snap++, oir); + snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0; + } + + /* Copy-substitute old instruction to new instruction. */ + nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev; + nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev; + ir->prev = nref; /* Loword substitution. */ + nir->o = ir->o; + nir->t.irt = ir->t.irt & ~(IRT_MARK|IRT_ISPHI); + hisubst[ref] = 0; + + /* Split 64 bit instructions. */ +#if LJ_SOFTFP + if (irt_isnum(ir->t)) { + nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */ + /* Note: hi ref = lo ref + 1! Required for SNAP_SOFTFPNUM logic. */ + switch (ir->o) { + case IR_ADD: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_add); + break; + case IR_SUB: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_sub); + break; + case IR_MUL: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_mul); + break; + case IR_DIV: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div); + break; + case IR_POW: + hi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi); + break; + case IR_FPMATH: + /* Try to rejoin pow from EXP2, MUL and LOG2. */ + if (nir->op2 == IRFPM_EXP2 && nir->op1 > J->loopref) { + IRIns *irp = IR(nir->op1); + if (irp->o == IR_CALLN && irp->op2 == IRCALL_softfp_mul) { + IRIns *irm4 = IR(irp->op1); + IRIns *irm3 = IR(irm4->op1); + IRIns *irm12 = IR(irm3->op1); + IRIns *irl1 = IR(irm12->op1); + if (irm12->op1 > J->loopref && irl1->o == IR_CALLN && + irl1->op2 == IRCALL_lj_vm_log2) { + IRRef tmp = irl1->op1; /* Recycle first two args from LOG2. */ + IRRef arg3 = irm3->op2, arg4 = irm4->op2; + J->cur.nins--; + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg3); + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg4); + ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_pow); + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp); + break; + } + } + } + hi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2); + break; + case IR_ATAN2: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_atan2); + break; + case IR_LDEXP: + hi = split_call_li(J, hisubst, oir, ir, IRCALL_ldexp); + break; + case IR_NEG: case IR_ABS: + nir->o = IR_CONV; /* Pass through loword. */ + nir->op2 = (IRT_INT << 5) | IRT_INT; + hi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + case IR_SLOAD: + if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from int to number. */ + nir->op2 &= ~IRSLOAD_CONVERT; + ir->prev = nref = split_emit(J, IRTI(IR_CALLN), nref, + IRCALL_softfp_i2d); + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + } + /* fallthrough */ + case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: + case IR_STRTO: + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + case IR_XLOAD: { + IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */ + J->cur.nins--; + hi = split_ptr(J, oir, ir->op1); /* Insert the hiref ADD. */ + nref = lj_ir_nextins(J); + nir = IR(nref); + *nir = inslo; /* Re-emit lo XLOAD immediately before hi XLOAD. */ + hi = split_emit(J, IRT(IR_XLOAD, IRT_SOFTFP), hi, ir->op2); +#if LJ_LE + ir->prev = nref; +#else + ir->prev = hi; hi = nref; +#endif + break; + } + case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_XSTORE: + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nir->op1, hisubst[ir->op2]); + break; + case IR_CONV: { /* Conversion to number. Others handled below. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); + UNUSED(st); +#if LJ_32 && LJ_HASFFI + if (st == IRT_I64 || st == IRT_U64) { + hi = split_call_l(J, hisubst, oir, ir, + st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d); + break; + } +#endif + lua_assert(st == IRT_INT || + (LJ_32 && LJ_HASFFI && (st == IRT_U32 || st == IRT_FLOAT))); + nir->o = IR_CALLN; +#if LJ_32 && LJ_HASFFI + nir->op2 = st == IRT_INT ? IRCALL_softfp_i2d : + st == IRT_FLOAT ? IRCALL_softfp_f2d : + IRCALL_softfp_ui2d; +#else + nir->op2 = IRCALL_softfp_i2d; +#endif + hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + break; + } + case IR_CALLN: + case IR_CALLL: + case IR_CALLS: + case IR_CALLXS: + goto split_call; + case IR_PHI: + if (nir->op1 == nir->op2) + J->cur.nins--; /* Drop useless PHIs. */ + if (hisubst[ir->op1] != hisubst[ir->op2]) + split_emit(J, IRT(IR_PHI, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + case IR_HIOP: + J->cur.nins--; /* Drop joining HIOP. */ + ir->prev = nir->op1; + hi = nir->op2; + break; + default: + lua_assert(ir->o <= IR_NE || ir->o == IR_MIN || ir->o == IR_MAX); + hi = split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), + hisubst[ir->op1], hisubst[ir->op2]); + break; + } + } else +#endif +#if LJ_32 && LJ_HASFFI + if (irt_isint64(ir->t)) { + IRRef hiref = hisubst[ir->op1]; + nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */ + switch (ir->o) { + case IR_ADD: + case IR_SUB: + /* Use plain op for hiword if loword cannot produce a carry/borrow. */ + if (irref_isk(nir->op2) && IR(nir->op2)->i == 0) { + ir->prev = nir->op1; /* Pass through loword. */ + nir->op1 = hiref; nir->op2 = hisubst[ir->op2]; + hi = nref; + break; + } + /* fallthrough */ + case IR_NEG: + hi = split_emit(J, IRTI(IR_HIOP), hiref, hisubst[ir->op2]); + break; + case IR_MUL: + hi = split_call_ll(J, hisubst, oir, ir, IRCALL_lj_carith_mul64); + break; + case IR_DIV: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 : + IRCALL_lj_carith_divu64); + break; + case IR_MOD: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 : + IRCALL_lj_carith_modu64); + break; + case IR_POW: + hi = split_call_ll(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 : + IRCALL_lj_carith_powu64); + break; + case IR_FLOAD: + lua_assert(ir->op2 == IRFL_CDATA_INT64); + hi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4); +#if LJ_BE + ir->prev = hi; hi = nref; +#endif + break; + case IR_XLOAD: + hi = split_emit(J, IRTI(IR_XLOAD), split_ptr(J, oir, ir->op1), ir->op2); +#if LJ_BE + ir->prev = hi; hi = nref; +#endif + break; + case IR_XSTORE: + split_emit(J, IRTI(IR_HIOP), nir->op1, hisubst[ir->op2]); + break; + case IR_CONV: { /* Conversion to 64 bit integer. Others handled below. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if LJ_SOFTFP + if (st == IRT_NUM) { /* NUM to 64 bit int conv. */ + hi = split_call_l(J, hisubst, oir, ir, + irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul); + } else if (st == IRT_FLOAT) { /* FLOAT to 64 bit int conv. */ + nir->o = IR_CALLN; + nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul; + hi = split_emit(J, IRTI(IR_HIOP), nref, nref); + } +#else + if (st == IRT_NUM || st == IRT_FLOAT) { /* FP to 64 bit int conv. */ + hi = split_emit(J, IRTI(IR_HIOP), nir->op1, nref); + } +#endif + else if (st == IRT_I64 || st == IRT_U64) { /* 64/64 bit cast. */ + /* Drop cast, since assembler doesn't care. */ + goto fwdlo; + } else if ((ir->op2 & IRCONV_SEXT)) { /* Sign-extend to 64 bit. */ + IRRef k31 = lj_ir_kint(J, 31); + nir = IR(nref); /* May have been reallocated. */ + ir->prev = nir->op1; /* Pass through loword. */ + nir->o = IR_BSAR; /* hi = bsar(lo, 31). */ + nir->op2 = k31; + hi = nref; + } else { /* Zero-extend to 64 bit. */ + hi = lj_ir_kint(J, 0); + goto fwdlo; + } + break; + } + case IR_CALLXS: + goto split_call; + case IR_PHI: { + IRRef hiref2; + if ((irref_isk(nir->op1) && irref_isk(nir->op2)) || + nir->op1 == nir->op2) + J->cur.nins--; /* Drop useless PHIs. */ + hiref2 = hisubst[ir->op2]; + if (!((irref_isk(hiref) && irref_isk(hiref2)) || hiref == hiref2)) + split_emit(J, IRTI(IR_PHI), hiref, hiref2); + break; + } + case IR_HIOP: + J->cur.nins--; /* Drop joining HIOP. */ + ir->prev = nir->op1; + hi = nir->op2; + break; + default: + lua_assert(ir->o <= IR_NE); /* Comparisons. */ + split_emit(J, IRTGI(IR_HIOP), hiref, hisubst[ir->op2]); + break; + } + } else +#endif +#if LJ_SOFTFP + if (ir->o == IR_SLOAD) { + if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from number to int. */ + nir->op2 &= ~IRSLOAD_CONVERT; + if (!(nir->op2 & IRSLOAD_TYPECHECK)) + nir->t.irt = IRT_INT; /* Drop guard. */ + split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); + ir->prev = split_num2int(J, nref, nref+1, irt_isguard(ir->t)); + } + } else if (ir->o == IR_TOBIT) { + IRRef tmp, op1 = ir->op1; + J->cur.nins--; +#if LJ_LE + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]); +#else + tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev); +#endif + ir->prev = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_lj_vm_tobit); + } else if (ir->o == IR_TOSTR) { + if (hisubst[ir->op1]) { + if (irref_isk(ir->op1)) + nir->op1 = ir->op1; + else + split_emit(J, IRT(IR_HIOP, IRT_NIL), hisubst[ir->op1], nref); + } + } else if (ir->o == IR_HREF || ir->o == IR_NEWREF) { + if (irref_isk(ir->op2) && hisubst[ir->op2]) + nir->op2 = ir->op2; + } else +#endif + if (ir->o == IR_CONV) { /* See above, too. */ + IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); +#if LJ_32 && LJ_HASFFI + if (st == IRT_I64 || st == IRT_U64) { /* Conversion from 64 bit int. */ +#if LJ_SOFTFP + if (irt_isfloat(ir->t)) { + split_call_l(J, hisubst, oir, ir, + st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f); + J->cur.nins--; /* Drop unused HIOP. */ + } +#else + if (irt_isfp(ir->t)) { /* 64 bit integer to FP conversion. */ + ir->prev = split_emit(J, IRT(IR_HIOP, irt_type(ir->t)), + hisubst[ir->op1], nref); + } +#endif + else { /* Truncate to lower 32 bits. */ + fwdlo: + ir->prev = nir->op1; /* Forward loword. */ + /* Replace with NOP to avoid messing up the snapshot logic. */ + nir->ot = IRT(IR_NOP, IRT_NIL); + nir->op1 = nir->op2 = 0; + } + } +#endif +#if LJ_SOFTFP && LJ_32 && LJ_HASFFI + else if (irt_isfloat(ir->t)) { + if (st == IRT_NUM) { + split_call_l(J, hisubst, oir, ir, IRCALL_softfp_d2f); + J->cur.nins--; /* Drop unused HIOP. */ + } else { + nir->o = IR_CALLN; + nir->op2 = st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f; + } + } else if (st == IRT_FLOAT) { + nir->o = IR_CALLN; + nir->op2 = irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui; + } else +#endif +#if LJ_SOFTFP + if (st == IRT_NUM || (LJ_32 && LJ_HASFFI && st == IRT_FLOAT)) { + if (irt_isguard(ir->t)) { + lua_assert(st == IRT_NUM && irt_isint(ir->t)); + J->cur.nins--; + ir->prev = split_num2int(J, nir->op1, hisubst[ir->op1], 1); + } else { + split_call_l(J, hisubst, oir, ir, +#if LJ_32 && LJ_HASFFI + st == IRT_NUM ? + (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) : + (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui) +#else + IRCALL_softfp_d2i +#endif + ); + J->cur.nins--; /* Drop unused HIOP. */ + } + } +#endif + } else if (ir->o == IR_CALLXS) { + IRRef hiref; + split_call: + hiref = hisubst[ir->op1]; + if (hiref) { + IROpT ot = nir->ot; + IRRef op2 = nir->op2; + nir->ot = IRT(IR_CARG, IRT_NIL); +#if LJ_LE + nir->op2 = hiref; +#else + nir->op2 = nir->op1; nir->op1 = hiref; +#endif + ir->prev = nref = split_emit(J, ot, nref, op2); + } + if (LJ_SOFTFP ? irt_is64(ir->t) : irt_isint64(ir->t)) + hi = split_emit(J, + IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT), + nref, nref); + } else if (ir->o == IR_CARG) { + IRRef hiref = hisubst[ir->op1]; + if (hiref) { + IRRef op2 = nir->op2; +#if LJ_LE + nir->op2 = hiref; +#else + nir->op2 = nir->op1; nir->op1 = hiref; +#endif + ir->prev = nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2); + nir = IR(nref); + } + hiref = hisubst[ir->op2]; + if (hiref) { +#if !LJ_TARGET_X86 + int carg = 0; + IRIns *cir; + for (cir = IR(nir->op1); cir->o == IR_CARG; cir = IR(cir->op1)) + carg++; + if ((carg & 1) == 0) { /* Align 64 bit arguments. */ + IRRef op2 = nir->op2; + nir->op2 = REF_NIL; + nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2); + nir = IR(nref); + } +#endif +#if LJ_BE + { IRRef tmp = nir->op2; nir->op2 = hiref; hiref = tmp; } +#endif + ir->prev = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, hiref); + } + } else if (ir->o == IR_CNEWI) { + if (hisubst[ir->op2]) + split_emit(J, IRT(IR_HIOP, IRT_NIL), nref, hisubst[ir->op2]); + } else if (ir->o == IR_LOOP) { + J->loopref = nref; /* Needed by assembler. */ + } + hisubst[ref] = hi; /* Store hiword substitution. */ + } + if (snref == nins) { /* Substitution for last snapshot. */ + snap->ref = J->cur.nins; + split_subst_snap(J, snap, oir); + } + + /* Add PHI marks. */ + for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) { + IRIns *ir = IR(ref); + if (ir->o != IR_PHI) break; + if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t); + if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t); + } +} + +/* Protected callback for split pass. */ +static TValue *cpsplit(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + split_ir(J); + UNUSED(L); UNUSED(dummy); + return NULL; +} + +#if defined(LUA_USE_ASSERT) || LJ_SOFTFP +/* Slow, but sure way to check whether a SPLIT pass is needed. */ +static int split_needsplit(jit_State *J) +{ + IRIns *ir, *irend; + IRRef ref; + for (ir = IR(REF_FIRST), irend = IR(J->cur.nins); ir < irend; ir++) + if (LJ_SOFTFP ? irt_is64orfp(ir->t) : irt_isint64(ir->t)) + return 1; + if (LJ_SOFTFP) { + for (ref = J->chain[IR_SLOAD]; ref; ref = IR(ref)->prev) + if ((IR(ref)->op2 & IRSLOAD_CONVERT)) + return 1; + if (J->chain[IR_TOBIT]) + return 1; + } + for (ref = J->chain[IR_CONV]; ref; ref = IR(ref)->prev) { + IRType st = (IR(ref)->op2 & IRCONV_SRCMASK); + if ((LJ_SOFTFP && (st == IRT_NUM || st == IRT_FLOAT)) || + st == IRT_I64 || st == IRT_U64) + return 1; + } + return 0; /* Nope. */ +} +#endif + +/* SPLIT pass. */ +void lj_opt_split(jit_State *J) +{ +#if LJ_SOFTFP + if (!J->needsplit) + J->needsplit = split_needsplit(J); +#else + lua_assert(J->needsplit >= split_needsplit(J)); /* Verify flag. */ +#endif + if (J->needsplit) { + int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit); + if (errcode) { + /* Completely reset the trace to avoid inconsistent dump on abort. */ + J->cur.nins = J->cur.nk = REF_BASE; + J->cur.nsnap = 0; + lj_err_throw(J->L, errcode); /* Propagate errors. */ + } + } +} + +#undef IR + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.c new file mode 100644 index 0000000..e8aafba --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.c @@ -0,0 +1,2752 @@ +/* +** Lua parser (source code -> bytecode). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_parse_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_state.h" +#include "lj_bc.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_lex.h" +#include "lj_parse.h" +#include "lj_vm.h" +#include "lj_vmevent.h" + +/* -- Parser structures and definitions ----------------------------------- */ + +/* Expression kinds. */ +typedef enum { + /* Constant expressions must be first and in this order: */ + VKNIL, + VKFALSE, + VKTRUE, + VKSTR, /* sval = string value */ + VKNUM, /* nval = number value */ + VKLAST = VKNUM, + VKCDATA, /* nval = cdata value, not treated as a constant expression */ + /* Non-constant expressions follow: */ + VLOCAL, /* info = local register, aux = vstack index */ + VUPVAL, /* info = upvalue index, aux = vstack index */ + VGLOBAL, /* sval = string value */ + VINDEXED, /* info = table register, aux = index reg/byte/string const */ + VJMP, /* info = instruction PC */ + VRELOCABLE, /* info = instruction PC */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction PC, aux = base */ + VVOID +} ExpKind; + +/* Expression descriptor. */ +typedef struct ExpDesc { + union { + struct { + uint32_t info; /* Primary info. */ + uint32_t aux; /* Secondary info. */ + } s; + TValue nval; /* Number value. */ + GCstr *sval; /* String value. */ + } u; + ExpKind k; + BCPos t; /* True condition jump list. */ + BCPos f; /* False condition jump list. */ +} ExpDesc; + +/* Macros for expressions. */ +#define expr_hasjump(e) ((e)->t != (e)->f) + +#define expr_isk(e) ((e)->k <= VKLAST) +#define expr_isk_nojump(e) (expr_isk(e) && !expr_hasjump(e)) +#define expr_isnumk(e) ((e)->k == VKNUM) +#define expr_isnumk_nojump(e) (expr_isnumk(e) && !expr_hasjump(e)) +#define expr_isstrk(e) ((e)->k == VKSTR) + +#define expr_numtv(e) check_exp(expr_isnumk((e)), &(e)->u.nval) +#define expr_numberV(e) numberVnum(expr_numtv((e))) + +/* Initialize expression. */ +static LJ_AINLINE void expr_init(ExpDesc *e, ExpKind k, uint32_t info) +{ + e->k = k; + e->u.s.info = info; + e->f = e->t = NO_JMP; +} + +/* Check number constant for +-0. */ +static int expr_numiszero(ExpDesc *e) +{ + TValue *o = expr_numtv(e); + return tvisint(o) ? (intV(o) == 0) : tviszero(o); +} + +/* Per-function linked list of scope blocks. */ +typedef struct FuncScope { + struct FuncScope *prev; /* Link to outer scope. */ + MSize vstart; /* Start of block-local variables. */ + uint8_t nactvar; /* Number of active vars outside the scope. */ + uint8_t flags; /* Scope flags. */ +} FuncScope; + +#define FSCOPE_LOOP 0x01 /* Scope is a (breakable) loop. */ +#define FSCOPE_BREAK 0x02 /* Break used in scope. */ +#define FSCOPE_GOLA 0x04 /* Goto or label used in scope. */ +#define FSCOPE_UPVAL 0x08 /* Upvalue in scope. */ +#define FSCOPE_NOCLOSE 0x10 /* Do not close upvalues. */ + +#define NAME_BREAK ((GCstr *)(uintptr_t)1) + +/* Index into variable stack. */ +typedef uint16_t VarIndex; +#define LJ_MAX_VSTACK (65536 - LJ_MAX_UPVAL) + +/* Variable/goto/label info. */ +#define VSTACK_VAR_RW 0x01 /* R/W variable. */ +#define VSTACK_GOTO 0x02 /* Pending goto. */ +#define VSTACK_LABEL 0x04 /* Label. */ + +/* Per-function state. */ +typedef struct FuncState { + GCtab *kt; /* Hash table for constants. */ + LexState *ls; /* Lexer state. */ + lua_State *L; /* Lua state. */ + FuncScope *bl; /* Current scope. */ + struct FuncState *prev; /* Enclosing function. */ + BCPos pc; /* Next bytecode position. */ + BCPos lasttarget; /* Bytecode position of last jump target. */ + BCPos jpc; /* Pending jump list to next bytecode. */ + BCReg freereg; /* First free register. */ + BCReg nactvar; /* Number of active local variables. */ + BCReg nkn, nkgc; /* Number of lua_Number/GCobj constants */ + BCLine linedefined; /* First line of the function definition. */ + BCInsLine *bcbase; /* Base of bytecode stack. */ + BCPos bclim; /* Limit of bytecode stack. */ + MSize vbase; /* Base of variable stack for this function. */ + uint8_t flags; /* Prototype flags. */ + uint8_t numparams; /* Number of parameters. */ + uint8_t framesize; /* Fixed frame size. */ + uint8_t nuv; /* Number of upvalues */ + VarIndex varmap[LJ_MAX_LOCVAR]; /* Map from register to variable idx. */ + VarIndex uvmap[LJ_MAX_UPVAL]; /* Map from upvalue to variable idx. */ + VarIndex uvtmp[LJ_MAX_UPVAL]; /* Temporary upvalue map. */ +} FuncState; + +/* Binary and unary operators. ORDER OPR */ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, /* ORDER ARITH */ + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_GE, OPR_LE, OPR_GT, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + +LJ_STATIC_ASSERT((int)BC_ISGE-(int)BC_ISLT == (int)OPR_GE-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_ISLE-(int)BC_ISLT == (int)OPR_LE-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_ISGT-(int)BC_ISLT == (int)OPR_GT-(int)OPR_LT); +LJ_STATIC_ASSERT((int)BC_SUBVV-(int)BC_ADDVV == (int)OPR_SUB-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_MULVV-(int)BC_ADDVV == (int)OPR_MUL-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_DIVVV-(int)BC_ADDVV == (int)OPR_DIV-(int)OPR_ADD); +LJ_STATIC_ASSERT((int)BC_MODVV-(int)BC_ADDVV == (int)OPR_MOD-(int)OPR_ADD); + +/* -- Error handling ------------------------------------------------------ */ + +LJ_NORET LJ_NOINLINE static void err_syntax(LexState *ls, ErrMsg em) +{ + lj_lex_error(ls, ls->token, em); +} + +LJ_NORET LJ_NOINLINE static void err_token(LexState *ls, LexToken token) +{ + lj_lex_error(ls, ls->token, LJ_ERR_XTOKEN, lj_lex_token2str(ls, token)); +} + +LJ_NORET static void err_limit(FuncState *fs, uint32_t limit, const char *what) +{ + if (fs->linedefined == 0) + lj_lex_error(fs->ls, 0, LJ_ERR_XLIMM, limit, what); + else + lj_lex_error(fs->ls, 0, LJ_ERR_XLIMF, fs->linedefined, limit, what); +} + +#define checklimit(fs, v, l, m) if ((v) >= (l)) err_limit(fs, l, m) +#define checklimitgt(fs, v, l, m) if ((v) > (l)) err_limit(fs, l, m) +#define checkcond(ls, c, em) { if (!(c)) err_syntax(ls, em); } + +/* -- Management of constants --------------------------------------------- */ + +/* Return bytecode encoding for primitive constant. */ +#define const_pri(e) check_exp((e)->k <= VKTRUE, (e)->k) + +#define tvhaskslot(o) ((o)->u32.hi == 0) +#define tvkslot(o) ((o)->u32.lo) + +/* Add a number constant. */ +static BCReg const_num(FuncState *fs, ExpDesc *e) +{ + lua_State *L = fs->L; + TValue *o; + lua_assert(expr_isnumk(e)); + o = lj_tab_set(L, fs->kt, &e->u.nval); + if (tvhaskslot(o)) + return tvkslot(o); + o->u64 = fs->nkn; + return fs->nkn++; +} + +/* Add a GC object constant. */ +static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype) +{ + lua_State *L = fs->L; + TValue key, *o; + setgcV(L, &key, gc, itype); + /* NOBARRIER: the key is new or kept alive. */ + o = lj_tab_set(L, fs->kt, &key); + if (tvhaskslot(o)) + return tvkslot(o); + o->u64 = fs->nkgc; + return fs->nkgc++; +} + +/* Add a string constant. */ +static BCReg const_str(FuncState *fs, ExpDesc *e) +{ + lua_assert(expr_isstrk(e) || e->k == VGLOBAL); + return const_gc(fs, obj2gco(e->u.sval), LJ_TSTR); +} + +/* Anchor string constant to avoid GC. */ +GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len) +{ + /* NOBARRIER: the key is new or kept alive. */ + lua_State *L = ls->L; + GCstr *s = lj_str_new(L, str, len); + TValue *tv = lj_tab_setstr(L, ls->fs->kt, s); + if (tvisnil(tv)) setboolV(tv, 1); + lj_gc_check(L); + return s; +} + +#if LJ_HASFFI +/* Anchor cdata to avoid GC. */ +void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd) +{ + /* NOBARRIER: the key is new or kept alive. */ + lua_State *L = ls->L; + setcdataV(L, tv, cd); + setboolV(lj_tab_set(L, ls->fs->kt, tv), 1); +} +#endif + +/* -- Jump list handling -------------------------------------------------- */ + +/* Get next element in jump list. */ +static BCPos jmp_next(FuncState *fs, BCPos pc) +{ + ptrdiff_t delta = bc_j(fs->bcbase[pc].ins); + if ((BCPos)delta == NO_JMP) + return NO_JMP; + else + return (BCPos)(((ptrdiff_t)pc+1)+delta); +} + +/* Check if any of the instructions on the jump list produce no value. */ +static int jmp_novalue(FuncState *fs, BCPos list) +{ + for (; list != NO_JMP; list = jmp_next(fs, list)) { + BCIns p = fs->bcbase[list >= 1 ? list-1 : list].ins; + if (!(bc_op(p) == BC_ISTC || bc_op(p) == BC_ISFC || bc_a(p) == NO_REG)) + return 1; + } + return 0; +} + +/* Patch register of test instructions. */ +static int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg) +{ + BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc]; + BCOp op = bc_op(ilp->ins); + if (op == BC_ISTC || op == BC_ISFC) { + if (reg != NO_REG && reg != bc_d(ilp->ins)) { + setbc_a(&ilp->ins, reg); + } else { /* Nothing to store or already in the right register. */ + setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC)); + setbc_a(&ilp->ins, 0); + } + } else if (bc_a(ilp->ins) == NO_REG) { + if (reg == NO_REG) { + ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0); + } else { + setbc_a(&ilp->ins, reg); + if (reg >= bc_a(ilp[1].ins)) + setbc_a(&ilp[1].ins, reg+1); + } + } else { + return 0; /* Cannot patch other instructions. */ + } + return 1; +} + +/* Drop values for all instructions on jump list. */ +static void jmp_dropval(FuncState *fs, BCPos list) +{ + for (; list != NO_JMP; list = jmp_next(fs, list)) + jmp_patchtestreg(fs, list, NO_REG); +} + +/* Patch jump instruction to target. */ +static void jmp_patchins(FuncState *fs, BCPos pc, BCPos dest) +{ + BCIns *jmp = &fs->bcbase[pc].ins; + BCPos offset = dest-(pc+1)+BCBIAS_J; + lua_assert(dest != NO_JMP); + if (offset > BCMAX_D) + err_syntax(fs->ls, LJ_ERR_XJUMP); + setbc_d(jmp, offset); +} + +/* Append to jump list. */ +static void jmp_append(FuncState *fs, BCPos *l1, BCPos l2) +{ + if (l2 == NO_JMP) { + return; + } else if (*l1 == NO_JMP) { + *l1 = l2; + } else { + BCPos list = *l1; + BCPos next; + while ((next = jmp_next(fs, list)) != NO_JMP) /* Find last element. */ + list = next; + jmp_patchins(fs, list, l2); + } +} + +/* Patch jump list and preserve produced values. */ +static void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget, + BCReg reg, BCPos dtarget) +{ + while (list != NO_JMP) { + BCPos next = jmp_next(fs, list); + if (jmp_patchtestreg(fs, list, reg)) + jmp_patchins(fs, list, vtarget); /* Jump to target with value. */ + else + jmp_patchins(fs, list, dtarget); /* Jump to default target. */ + list = next; + } +} + +/* Jump to following instruction. Append to list of pending jumps. */ +static void jmp_tohere(FuncState *fs, BCPos list) +{ + fs->lasttarget = fs->pc; + jmp_append(fs, &fs->jpc, list); +} + +/* Patch jump list to target. */ +static void jmp_patch(FuncState *fs, BCPos list, BCPos target) +{ + if (target == fs->pc) { + jmp_tohere(fs, list); + } else { + lua_assert(target < fs->pc); + jmp_patchval(fs, list, target, NO_REG, target); + } +} + +/* -- Bytecode register allocator ----------------------------------------- */ + +/* Bump frame size. */ +static void bcreg_bump(FuncState *fs, BCReg n) +{ + BCReg sz = fs->freereg + n; + if (sz > fs->framesize) { + if (sz >= LJ_MAX_SLOTS) + err_syntax(fs->ls, LJ_ERR_XSLOTS); + fs->framesize = (uint8_t)sz; + } +} + +/* Reserve registers. */ +static void bcreg_reserve(FuncState *fs, BCReg n) +{ + bcreg_bump(fs, n); + fs->freereg += n; +} + +/* Free register. */ +static void bcreg_free(FuncState *fs, BCReg reg) +{ + if (reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + +/* Free register for expression. */ +static void expr_free(FuncState *fs, ExpDesc *e) +{ + if (e->k == VNONRELOC) + bcreg_free(fs, e->u.s.info); +} + +/* -- Bytecode emitter ---------------------------------------------------- */ + +/* Emit bytecode instruction. */ +static BCPos bcemit_INS(FuncState *fs, BCIns ins) +{ + BCPos pc = fs->pc; + LexState *ls = fs->ls; + jmp_patchval(fs, fs->jpc, pc, NO_REG, pc); + fs->jpc = NO_JMP; + if (LJ_UNLIKELY(pc >= fs->bclim)) { + ptrdiff_t base = fs->bcbase - ls->bcstack; + checklimit(fs, ls->sizebcstack, LJ_MAX_BCINS, "bytecode instructions"); + lj_mem_growvec(fs->L, ls->bcstack, ls->sizebcstack, LJ_MAX_BCINS,BCInsLine); + fs->bclim = (BCPos)(ls->sizebcstack - base); + fs->bcbase = ls->bcstack + base; + } + fs->bcbase[pc].ins = ins; + fs->bcbase[pc].line = ls->lastline; + fs->pc = pc+1; + return pc; +} + +#define bcemit_ABC(fs, o, a, b, c) bcemit_INS(fs, BCINS_ABC(o, a, b, c)) +#define bcemit_AD(fs, o, a, d) bcemit_INS(fs, BCINS_AD(o, a, d)) +#define bcemit_AJ(fs, o, a, j) bcemit_INS(fs, BCINS_AJ(o, a, j)) + +#define bcptr(fs, e) (&(fs)->bcbase[(e)->u.s.info].ins) + +/* -- Bytecode emitter for expressions ------------------------------------ */ + +/* Discharge non-constant expression to any register. */ +static void expr_discharge(FuncState *fs, ExpDesc *e) +{ + BCIns ins; + if (e->k == VUPVAL) { + ins = BCINS_AD(BC_UGET, 0, e->u.s.info); + } else if (e->k == VGLOBAL) { + ins = BCINS_AD(BC_GGET, 0, const_str(fs, e)); + } else if (e->k == VINDEXED) { + BCReg rc = e->u.s.aux; + if ((int32_t)rc < 0) { + ins = BCINS_ABC(BC_TGETS, 0, e->u.s.info, ~rc); + } else if (rc > BCMAX_C) { + ins = BCINS_ABC(BC_TGETB, 0, e->u.s.info, rc-(BCMAX_C+1)); + } else { + bcreg_free(fs, rc); + ins = BCINS_ABC(BC_TGETV, 0, e->u.s.info, rc); + } + bcreg_free(fs, e->u.s.info); + } else if (e->k == VCALL) { + e->u.s.info = e->u.s.aux; + e->k = VNONRELOC; + return; + } else if (e->k == VLOCAL) { + e->k = VNONRELOC; + return; + } else { + return; + } + e->u.s.info = bcemit_INS(fs, ins); + e->k = VRELOCABLE; +} + +/* Emit bytecode to set a range of registers to nil. */ +static void bcemit_nil(FuncState *fs, BCReg from, BCReg n) +{ + if (fs->pc > fs->lasttarget) { /* No jumps to current position? */ + BCIns *ip = &fs->bcbase[fs->pc-1].ins; + BCReg pto, pfrom = bc_a(*ip); + switch (bc_op(*ip)) { /* Try to merge with the previous instruction. */ + case BC_KPRI: + if (bc_d(*ip) != ~LJ_TNIL) break; + if (from == pfrom) { + if (n == 1) return; + } else if (from == pfrom+1) { + from = pfrom; + n++; + } else { + break; + } + *ip = BCINS_AD(BC_KNIL, from, from+n-1); /* Replace KPRI. */ + return; + case BC_KNIL: + pto = bc_d(*ip); + if (pfrom <= from && from <= pto+1) { /* Can we connect both ranges? */ + if (from+n-1 > pto) + setbc_d(ip, from+n-1); /* Patch previous instruction range. */ + return; + } + break; + default: + break; + } + } + /* Emit new instruction or replace old instruction. */ + bcemit_INS(fs, n == 1 ? BCINS_AD(BC_KPRI, from, VKNIL) : + BCINS_AD(BC_KNIL, from, from+n-1)); +} + +/* Discharge an expression to a specific register. Ignore branches. */ +static void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg) +{ + BCIns ins; + expr_discharge(fs, e); + if (e->k == VKSTR) { + ins = BCINS_AD(BC_KSTR, reg, const_str(fs, e)); + } else if (e->k == VKNUM) { +#if LJ_DUALNUM + cTValue *tv = expr_numtv(e); + if (tvisint(tv) && checki16(intV(tv))) + ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv)); + else +#else + lua_Number n = expr_numberV(e); + int32_t k = lj_num2int(n); + if (checki16(k) && n == (lua_Number)k) + ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); + else +#endif + ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e)); +#if LJ_HASFFI + } else if (e->k == VKCDATA) { + fs->flags |= PROTO_FFI; + ins = BCINS_AD(BC_KCDATA, reg, + const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA)); +#endif + } else if (e->k == VRELOCABLE) { + setbc_a(bcptr(fs, e), reg); + goto noins; + } else if (e->k == VNONRELOC) { + if (reg == e->u.s.info) + goto noins; + ins = BCINS_AD(BC_MOV, reg, e->u.s.info); + } else if (e->k == VKNIL) { + bcemit_nil(fs, reg, 1); + goto noins; + } else if (e->k <= VKTRUE) { + ins = BCINS_AD(BC_KPRI, reg, const_pri(e)); + } else { + lua_assert(e->k == VVOID || e->k == VJMP); + return; + } + bcemit_INS(fs, ins); +noins: + e->u.s.info = reg; + e->k = VNONRELOC; +} + +/* Forward declaration. */ +static BCPos bcemit_jmp(FuncState *fs); + +/* Discharge an expression to a specific register. */ +static void expr_toreg(FuncState *fs, ExpDesc *e, BCReg reg) +{ + expr_toreg_nobranch(fs, e, reg); + if (e->k == VJMP) + jmp_append(fs, &e->t, e->u.s.info); /* Add it to the true jump list. */ + if (expr_hasjump(e)) { /* Discharge expression with branches. */ + BCPos jend, jfalse = NO_JMP, jtrue = NO_JMP; + if (jmp_novalue(fs, e->t) || jmp_novalue(fs, e->f)) { + BCPos jval = (e->k == VJMP) ? NO_JMP : bcemit_jmp(fs); + jfalse = bcemit_AD(fs, BC_KPRI, reg, VKFALSE); + bcemit_AJ(fs, BC_JMP, fs->freereg, 1); + jtrue = bcemit_AD(fs, BC_KPRI, reg, VKTRUE); + jmp_tohere(fs, jval); + } + jend = fs->pc; + fs->lasttarget = jend; + jmp_patchval(fs, e->f, jend, reg, jfalse); + jmp_patchval(fs, e->t, jend, reg, jtrue); + } + e->f = e->t = NO_JMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + +/* Discharge an expression to the next free register. */ +static void expr_tonextreg(FuncState *fs, ExpDesc *e) +{ + expr_discharge(fs, e); + expr_free(fs, e); + bcreg_reserve(fs, 1); + expr_toreg(fs, e, fs->freereg - 1); +} + +/* Discharge an expression to any register. */ +static BCReg expr_toanyreg(FuncState *fs, ExpDesc *e) +{ + expr_discharge(fs, e); + if (e->k == VNONRELOC) { + if (!expr_hasjump(e)) return e->u.s.info; /* Already in a register. */ + if (e->u.s.info >= fs->nactvar) { + expr_toreg(fs, e, e->u.s.info); /* Discharge to temp. register. */ + return e->u.s.info; + } + } + expr_tonextreg(fs, e); /* Discharge to next register. */ + return e->u.s.info; +} + +/* Partially discharge expression to a value. */ +static void expr_toval(FuncState *fs, ExpDesc *e) +{ + if (expr_hasjump(e)) + expr_toanyreg(fs, e); + else + expr_discharge(fs, e); +} + +/* Emit store for LHS expression. */ +static void bcemit_store(FuncState *fs, ExpDesc *var, ExpDesc *e) +{ + BCIns ins; + if (var->k == VLOCAL) { + fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW; + expr_free(fs, e); + expr_toreg(fs, e, var->u.s.info); + return; + } else if (var->k == VUPVAL) { + fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW; + expr_toval(fs, e); + if (e->k <= VKTRUE) + ins = BCINS_AD(BC_USETP, var->u.s.info, const_pri(e)); + else if (e->k == VKSTR) + ins = BCINS_AD(BC_USETS, var->u.s.info, const_str(fs, e)); + else if (e->k == VKNUM) + ins = BCINS_AD(BC_USETN, var->u.s.info, const_num(fs, e)); + else + ins = BCINS_AD(BC_USETV, var->u.s.info, expr_toanyreg(fs, e)); + } else if (var->k == VGLOBAL) { + BCReg ra = expr_toanyreg(fs, e); + ins = BCINS_AD(BC_GSET, ra, const_str(fs, var)); + } else { + BCReg ra, rc; + lua_assert(var->k == VINDEXED); + ra = expr_toanyreg(fs, e); + rc = var->u.s.aux; + if ((int32_t)rc < 0) { + ins = BCINS_ABC(BC_TSETS, ra, var->u.s.info, ~rc); + } else if (rc > BCMAX_C) { + ins = BCINS_ABC(BC_TSETB, ra, var->u.s.info, rc-(BCMAX_C+1)); + } else { + /* Free late alloced key reg to avoid assert on free of value reg. */ + /* This can only happen when called from expr_table(). */ + lua_assert(e->k != VNONRELOC || ra < fs->nactvar || + rc < ra || (bcreg_free(fs, rc),1)); + ins = BCINS_ABC(BC_TSETV, ra, var->u.s.info, rc); + } + } + bcemit_INS(fs, ins); + expr_free(fs, e); +} + +/* Emit method lookup expression. */ +static void bcemit_method(FuncState *fs, ExpDesc *e, ExpDesc *key) +{ + BCReg idx, func, obj = expr_toanyreg(fs, e); + expr_free(fs, e); + func = fs->freereg; + bcemit_AD(fs, BC_MOV, func+1, obj); /* Copy object to first argument. */ + lua_assert(expr_isstrk(key)); + idx = const_str(fs, key); + if (idx <= BCMAX_C) { + bcreg_reserve(fs, 2); + bcemit_ABC(fs, BC_TGETS, func, obj, idx); + } else { + bcreg_reserve(fs, 3); + bcemit_AD(fs, BC_KSTR, func+2, idx); + bcemit_ABC(fs, BC_TGETV, func, obj, func+2); + fs->freereg--; + } + e->u.s.info = func; + e->k = VNONRELOC; +} + +/* -- Bytecode emitter for branches --------------------------------------- */ + +/* Emit unconditional branch. */ +static BCPos bcemit_jmp(FuncState *fs) +{ + BCPos jpc = fs->jpc; + BCPos j = fs->pc - 1; + BCIns *ip = &fs->bcbase[j].ins; + fs->jpc = NO_JMP; + if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) + setbc_j(ip, NO_JMP); + else + j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP); + jmp_append(fs, &j, jpc); + return j; +} + +/* Invert branch condition of bytecode instruction. */ +static void invertcond(FuncState *fs, ExpDesc *e) +{ + BCIns *ip = &fs->bcbase[e->u.s.info - 1].ins; + setbc_op(ip, bc_op(*ip)^1); +} + +/* Emit conditional branch. */ +static BCPos bcemit_branch(FuncState *fs, ExpDesc *e, int cond) +{ + BCPos pc; + if (e->k == VRELOCABLE) { + BCIns *ip = bcptr(fs, e); + if (bc_op(*ip) == BC_NOT) { + *ip = BCINS_AD(cond ? BC_ISF : BC_IST, 0, bc_d(*ip)); + return bcemit_jmp(fs); + } + } + if (e->k != VNONRELOC) { + bcreg_reserve(fs, 1); + expr_toreg_nobranch(fs, e, fs->freereg-1); + } + bcemit_AD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->u.s.info); + pc = bcemit_jmp(fs); + expr_free(fs, e); + return pc; +} + +/* Emit branch on true condition. */ +static void bcemit_branch_t(FuncState *fs, ExpDesc *e) +{ + BCPos pc; + expr_discharge(fs, e); + if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE) + pc = NO_JMP; /* Never jump. */ + else if (e->k == VJMP) + invertcond(fs, e), pc = e->u.s.info; + else if (e->k == VKFALSE || e->k == VKNIL) + expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs); + else + pc = bcemit_branch(fs, e, 0); + jmp_append(fs, &e->f, pc); + jmp_tohere(fs, e->t); + e->t = NO_JMP; +} + +/* Emit branch on false condition. */ +static void bcemit_branch_f(FuncState *fs, ExpDesc *e) +{ + BCPos pc; + expr_discharge(fs, e); + if (e->k == VKNIL || e->k == VKFALSE) + pc = NO_JMP; /* Never jump. */ + else if (e->k == VJMP) + pc = e->u.s.info; + else if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE) + expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs); + else + pc = bcemit_branch(fs, e, 1); + jmp_append(fs, &e->t, pc); + jmp_tohere(fs, e->f); + e->f = NO_JMP; +} + +/* -- Bytecode emitter for operators -------------------------------------- */ + +/* Try constant-folding of arithmetic operators. */ +static int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + TValue o; + lua_Number n; + if (!expr_isnumk_nojump(e1) || !expr_isnumk_nojump(e2)) return 0; + n = lj_vm_foldarith(expr_numberV(e1), expr_numberV(e2), (int)opr-OPR_ADD); + setnumV(&o, n); + if (tvisnan(&o) || tvismzero(&o)) return 0; /* Avoid NaN and -0 as consts. */ + if (LJ_DUALNUM) { + int32_t k = lj_num2int(n); + if ((lua_Number)k == n) { + setintV(&e1->u.nval, k); + return 1; + } + } + setnumV(&e1->u.nval, n); + return 1; +} + +/* Emit arithmetic operator. */ +static void bcemit_arith(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + BCReg rb, rc, t; + uint32_t op; + if (foldarith(opr, e1, e2)) + return; + if (opr == OPR_POW) { + op = BC_POW; + rc = expr_toanyreg(fs, e2); + rb = expr_toanyreg(fs, e1); + } else { + op = opr-OPR_ADD+BC_ADDVV; + /* Must discharge 2nd operand first since VINDEXED might free regs. */ + expr_toval(fs, e2); + if (expr_isnumk(e2) && (rc = const_num(fs, e2)) <= BCMAX_C) + op -= BC_ADDVV-BC_ADDVN; + else + rc = expr_toanyreg(fs, e2); + /* 1st operand discharged by bcemit_binop_left, but need KNUM/KSHORT. */ + lua_assert(expr_isnumk(e1) || e1->k == VNONRELOC); + expr_toval(fs, e1); + /* Avoid two consts to satisfy bytecode constraints. */ + if (expr_isnumk(e1) && !expr_isnumk(e2) && + (t = const_num(fs, e1)) <= BCMAX_B) { + rb = rc; rc = t; op -= BC_ADDVV-BC_ADDNV; + } else { + rb = expr_toanyreg(fs, e1); + } + } + /* Using expr_free might cause asserts if the order is wrong. */ + if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--; + if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--; + e1->u.s.info = bcemit_ABC(fs, op, 0, rb, rc); + e1->k = VRELOCABLE; +} + +/* Emit comparison operator. */ +static void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2) +{ + ExpDesc *eret = e1; + BCIns ins; + expr_toval(fs, e1); + if (opr == OPR_EQ || opr == OPR_NE) { + BCOp op = opr == OPR_EQ ? BC_ISEQV : BC_ISNEV; + BCReg ra; + if (expr_isk(e1)) { e1 = e2; e2 = eret; } /* Need constant in 2nd arg. */ + ra = expr_toanyreg(fs, e1); /* First arg must be in a reg. */ + expr_toval(fs, e2); + switch (e2->k) { + case VKNIL: case VKFALSE: case VKTRUE: + ins = BCINS_AD(op+(BC_ISEQP-BC_ISEQV), ra, const_pri(e2)); + break; + case VKSTR: + ins = BCINS_AD(op+(BC_ISEQS-BC_ISEQV), ra, const_str(fs, e2)); + break; + case VKNUM: + ins = BCINS_AD(op+(BC_ISEQN-BC_ISEQV), ra, const_num(fs, e2)); + break; + default: + ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2)); + break; + } + } else { + uint32_t op = opr-OPR_LT+BC_ISLT; + BCReg ra, rd; + if ((op-BC_ISLT) & 1) { /* GT -> LT, GE -> LE */ + e1 = e2; e2 = eret; /* Swap operands. */ + op = ((op-BC_ISLT)^3)+BC_ISLT; + expr_toval(fs, e1); + } + rd = expr_toanyreg(fs, e2); + ra = expr_toanyreg(fs, e1); + ins = BCINS_AD(op, ra, rd); + } + /* Using expr_free might cause asserts if the order is wrong. */ + if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--; + if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--; + bcemit_INS(fs, ins); + eret->u.s.info = bcemit_jmp(fs); + eret->k = VJMP; +} + +/* Fixup left side of binary operator. */ +static void bcemit_binop_left(FuncState *fs, BinOpr op, ExpDesc *e) +{ + if (op == OPR_AND) { + bcemit_branch_t(fs, e); + } else if (op == OPR_OR) { + bcemit_branch_f(fs, e); + } else if (op == OPR_CONCAT) { + expr_tonextreg(fs, e); + } else if (op == OPR_EQ || op == OPR_NE) { + if (!expr_isk_nojump(e)) expr_toanyreg(fs, e); + } else { + if (!expr_isnumk_nojump(e)) expr_toanyreg(fs, e); + } +} + +/* Emit binary operator. */ +static void bcemit_binop(FuncState *fs, BinOpr op, ExpDesc *e1, ExpDesc *e2) +{ + if (op <= OPR_POW) { + bcemit_arith(fs, op, e1, e2); + } else if (op == OPR_AND) { + lua_assert(e1->t == NO_JMP); /* List must be closed. */ + expr_discharge(fs, e2); + jmp_append(fs, &e2->f, e1->f); + *e1 = *e2; + } else if (op == OPR_OR) { + lua_assert(e1->f == NO_JMP); /* List must be closed. */ + expr_discharge(fs, e2); + jmp_append(fs, &e2->t, e1->t); + *e1 = *e2; + } else if (op == OPR_CONCAT) { + expr_toval(fs, e2); + if (e2->k == VRELOCABLE && bc_op(*bcptr(fs, e2)) == BC_CAT) { + lua_assert(e1->u.s.info == bc_b(*bcptr(fs, e2))-1); + expr_free(fs, e1); + setbc_b(bcptr(fs, e2), e1->u.s.info); + e1->u.s.info = e2->u.s.info; + } else { + expr_tonextreg(fs, e2); + expr_free(fs, e2); + expr_free(fs, e1); + e1->u.s.info = bcemit_ABC(fs, BC_CAT, 0, e1->u.s.info, e2->u.s.info); + } + e1->k = VRELOCABLE; + } else { + lua_assert(op == OPR_NE || op == OPR_EQ || + op == OPR_LT || op == OPR_GE || op == OPR_LE || op == OPR_GT); + bcemit_comp(fs, op, e1, e2); + } +} + +/* Emit unary operator. */ +static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e) +{ + if (op == BC_NOT) { + /* Swap true and false lists. */ + { BCPos temp = e->f; e->f = e->t; e->t = temp; } + jmp_dropval(fs, e->f); + jmp_dropval(fs, e->t); + expr_discharge(fs, e); + if (e->k == VKNIL || e->k == VKFALSE) { + e->k = VKTRUE; + return; + } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) { + e->k = VKFALSE; + return; + } else if (e->k == VJMP) { + invertcond(fs, e); + return; + } else if (e->k == VRELOCABLE) { + bcreg_reserve(fs, 1); + setbc_a(bcptr(fs, e), fs->freereg-1); + e->u.s.info = fs->freereg-1; + e->k = VNONRELOC; + } else { + lua_assert(e->k == VNONRELOC); + } + } else { + lua_assert(op == BC_UNM || op == BC_LEN); + if (op == BC_UNM && !expr_hasjump(e)) { /* Constant-fold negations. */ +#if LJ_HASFFI + if (e->k == VKCDATA) { /* Fold in-place since cdata is not interned. */ + GCcdata *cd = cdataV(&e->u.nval); + int64_t *p = (int64_t *)cdataptr(cd); + if (cd->ctypeid == CTID_COMPLEX_DOUBLE) + p[1] ^= (int64_t)U64x(80000000,00000000); + else + *p = -*p; + return; + } else +#endif + if (expr_isnumk(e) && !expr_numiszero(e)) { /* Avoid folding to -0. */ + TValue *o = expr_numtv(e); + if (tvisint(o)) { + int32_t k = intV(o); + if (k == -k) + setnumV(o, -(lua_Number)k); + else + setintV(o, -k); + return; + } else { + o->u64 ^= U64x(80000000,00000000); + return; + } + } + } + expr_toanyreg(fs, e); + } + expr_free(fs, e); + e->u.s.info = bcemit_AD(fs, op, 0, e->u.s.info); + e->k = VRELOCABLE; +} + +/* -- Lexer support ------------------------------------------------------- */ + +/* Check and consume optional token. */ +static int lex_opt(LexState *ls, LexToken tok) +{ + if (ls->token == tok) { + lj_lex_next(ls); + return 1; + } + return 0; +} + +/* Check and consume token. */ +static void lex_check(LexState *ls, LexToken tok) +{ + if (ls->token != tok) + err_token(ls, tok); + lj_lex_next(ls); +} + +/* Check for matching token. */ +static void lex_match(LexState *ls, LexToken what, LexToken who, BCLine line) +{ + if (!lex_opt(ls, what)) { + if (line == ls->linenumber) { + err_token(ls, what); + } else { + const char *swhat = lj_lex_token2str(ls, what); + const char *swho = lj_lex_token2str(ls, who); + lj_lex_error(ls, ls->token, LJ_ERR_XMATCH, swhat, swho, line); + } + } +} + +/* Check for string token. */ +static GCstr *lex_str(LexState *ls) +{ + GCstr *s; + if (ls->token != TK_name && (LJ_52 || ls->token != TK_goto)) + err_token(ls, TK_name); + s = strV(&ls->tokenval); + lj_lex_next(ls); + return s; +} + +/* -- Variable handling --------------------------------------------------- */ + +#define var_get(ls, fs, i) ((ls)->vstack[(fs)->varmap[(i)]]) + +/* Define a new local variable. */ +static void var_new(LexState *ls, BCReg n, GCstr *name) +{ + FuncState *fs = ls->fs; + MSize vtop = ls->vtop; + checklimit(fs, fs->nactvar+n, LJ_MAX_LOCVAR, "local variables"); + if (LJ_UNLIKELY(vtop >= ls->sizevstack)) { + if (ls->sizevstack >= LJ_MAX_VSTACK) + lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK); + lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo); + } + lua_assert((uintptr_t)name < VARNAME__MAX || + lj_tab_getstr(fs->kt, name) != NULL); + /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */ + setgcref(ls->vstack[vtop].name, obj2gco(name)); + fs->varmap[fs->nactvar+n] = (uint16_t)vtop; + ls->vtop = vtop+1; +} + +#define var_new_lit(ls, n, v) \ + var_new(ls, (n), lj_parse_keepstr(ls, "" v, sizeof(v)-1)) + +#define var_new_fixed(ls, n, vn) \ + var_new(ls, (n), (GCstr *)(uintptr_t)(vn)) + +/* Add local variables. */ +static void var_add(LexState *ls, BCReg nvars) +{ + FuncState *fs = ls->fs; + BCReg nactvar = fs->nactvar; + while (nvars--) { + VarInfo *v = &var_get(ls, fs, nactvar); + v->startpc = fs->pc; + v->slot = nactvar++; + v->info = 0; + } + fs->nactvar = nactvar; +} + +/* Remove local variables. */ +static void var_remove(LexState *ls, BCReg tolevel) +{ + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + var_get(ls, fs, --fs->nactvar).endpc = fs->pc; +} + +/* Lookup local variable name. */ +static BCReg var_lookup_local(FuncState *fs, GCstr *n) +{ + int i; + for (i = fs->nactvar-1; i >= 0; i--) { + if (n == strref(var_get(fs->ls, fs, i).name)) + return (BCReg)i; + } + return (BCReg)-1; /* Not found. */ +} + +/* Lookup or add upvalue index. */ +static MSize var_lookup_uv(FuncState *fs, MSize vidx, ExpDesc *e) +{ + MSize i, n = fs->nuv; + for (i = 0; i < n; i++) + if (fs->uvmap[i] == vidx) + return i; /* Already exists. */ + /* Otherwise create a new one. */ + checklimit(fs, fs->nuv, LJ_MAX_UPVAL, "upvalues"); + lua_assert(e->k == VLOCAL || e->k == VUPVAL); + fs->uvmap[n] = (uint16_t)vidx; + fs->uvtmp[n] = (uint16_t)(e->k == VLOCAL ? vidx : LJ_MAX_VSTACK+e->u.s.info); + fs->nuv = n+1; + return n; +} + +/* Forward declaration. */ +static void fscope_uvmark(FuncState *fs, BCReg level); + +/* Recursively lookup variables in enclosing functions. */ +static MSize var_lookup_(FuncState *fs, GCstr *name, ExpDesc *e, int first) +{ + if (fs) { + BCReg reg = var_lookup_local(fs, name); + if ((int32_t)reg >= 0) { /* Local in this function? */ + expr_init(e, VLOCAL, reg); + if (!first) + fscope_uvmark(fs, reg); /* Scope now has an upvalue. */ + return (MSize)(e->u.s.aux = (uint32_t)fs->varmap[reg]); + } else { + MSize vidx = var_lookup_(fs->prev, name, e, 0); /* Var in outer func? */ + if ((int32_t)vidx >= 0) { /* Yes, make it an upvalue here. */ + e->u.s.info = (uint8_t)var_lookup_uv(fs, vidx, e); + e->k = VUPVAL; + return vidx; + } + } + } else { /* Not found in any function, must be a global. */ + expr_init(e, VGLOBAL, 0); + e->u.sval = name; + } + return (MSize)-1; /* Global. */ +} + +/* Lookup variable name. */ +#define var_lookup(ls, e) \ + var_lookup_((ls)->fs, lex_str(ls), (e), 1) + +/* -- Goto an label handling ---------------------------------------------- */ + +/* Add a new goto or label. */ +static MSize gola_new(LexState *ls, GCstr *name, uint8_t info, BCPos pc) +{ + FuncState *fs = ls->fs; + MSize vtop = ls->vtop; + if (LJ_UNLIKELY(vtop >= ls->sizevstack)) { + if (ls->sizevstack >= LJ_MAX_VSTACK) + lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK); + lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo); + } + lua_assert(name == NAME_BREAK || lj_tab_getstr(fs->kt, name) != NULL); + /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */ + setgcref(ls->vstack[vtop].name, obj2gco(name)); + ls->vstack[vtop].startpc = pc; + ls->vstack[vtop].slot = (uint8_t)fs->nactvar; + ls->vstack[vtop].info = info; + ls->vtop = vtop+1; + return vtop; +} + +#define gola_isgoto(v) ((v)->info & VSTACK_GOTO) +#define gola_islabel(v) ((v)->info & VSTACK_LABEL) +#define gola_isgotolabel(v) ((v)->info & (VSTACK_GOTO|VSTACK_LABEL)) + +/* Patch goto to jump to label. */ +static void gola_patch(LexState *ls, VarInfo *vg, VarInfo *vl) +{ + FuncState *fs = ls->fs; + BCPos pc = vg->startpc; + setgcrefnull(vg->name); /* Invalidate pending goto. */ + setbc_a(&fs->bcbase[pc].ins, vl->slot); + jmp_patch(fs, pc, vl->startpc); +} + +/* Patch goto to close upvalues. */ +static void gola_close(LexState *ls, VarInfo *vg) +{ + FuncState *fs = ls->fs; + BCPos pc = vg->startpc; + BCIns *ip = &fs->bcbase[pc].ins; + lua_assert(gola_isgoto(vg)); + lua_assert(bc_op(*ip) == BC_JMP || bc_op(*ip) == BC_UCLO); + setbc_a(ip, vg->slot); + if (bc_op(*ip) == BC_JMP) { + BCPos next = jmp_next(fs, pc); + if (next != NO_JMP) jmp_patch(fs, next, pc); /* Jump to UCLO. */ + setbc_op(ip, BC_UCLO); /* Turn into UCLO. */ + setbc_j(ip, NO_JMP); + } +} + +/* Resolve pending forward gotos for label. */ +static void gola_resolve(LexState *ls, FuncScope *bl, MSize idx) +{ + VarInfo *vg = ls->vstack + bl->vstart; + VarInfo *vl = ls->vstack + idx; + for (; vg < vl; vg++) + if (gcrefeq(vg->name, vl->name) && gola_isgoto(vg)) { + if (vg->slot < vl->slot) { + GCstr *name = strref(var_get(ls, ls->fs, vg->slot).name); + lua_assert((uintptr_t)name >= VARNAME__MAX); + ls->linenumber = ls->fs->bcbase[vg->startpc].line; + lua_assert(strref(vg->name) != NAME_BREAK); + lj_lex_error(ls, 0, LJ_ERR_XGSCOPE, + strdata(strref(vg->name)), strdata(name)); + } + gola_patch(ls, vg, vl); + } +} + +/* Fixup remaining gotos and labels for scope. */ +static void gola_fixup(LexState *ls, FuncScope *bl) +{ + VarInfo *v = ls->vstack + bl->vstart; + VarInfo *ve = ls->vstack + ls->vtop; + for (; v < ve; v++) { + GCstr *name = strref(v->name); + if (name != NULL) { /* Only consider remaining valid gotos/labels. */ + if (gola_islabel(v)) { + VarInfo *vg; + setgcrefnull(v->name); /* Invalidate label that goes out of scope. */ + for (vg = v+1; vg < ve; vg++) /* Resolve pending backward gotos. */ + if (strref(vg->name) == name && gola_isgoto(vg)) { + if ((bl->flags&FSCOPE_UPVAL) && vg->slot > v->slot) + gola_close(ls, vg); + gola_patch(ls, vg, v); + } + } else if (gola_isgoto(v)) { + if (bl->prev) { /* Propagate goto or break to outer scope. */ + bl->prev->flags |= name == NAME_BREAK ? FSCOPE_BREAK : FSCOPE_GOLA; + v->slot = bl->nactvar; + if ((bl->flags & FSCOPE_UPVAL)) + gola_close(ls, v); + } else { /* No outer scope: undefined goto label or no loop. */ + ls->linenumber = ls->fs->bcbase[v->startpc].line; + if (name == NAME_BREAK) + lj_lex_error(ls, 0, LJ_ERR_XBREAK); + else + lj_lex_error(ls, 0, LJ_ERR_XLUNDEF, strdata(name)); + } + } + } + } +} + +/* Find existing label. */ +static VarInfo *gola_findlabel(LexState *ls, GCstr *name) +{ + VarInfo *v = ls->vstack + ls->fs->bl->vstart; + VarInfo *ve = ls->vstack + ls->vtop; + for (; v < ve; v++) + if (strref(v->name) == name && gola_islabel(v)) + return v; + return NULL; +} + +/* -- Scope handling ------------------------------------------------------ */ + +/* Begin a scope. */ +static void fscope_begin(FuncState *fs, FuncScope *bl, int flags) +{ + bl->nactvar = (uint8_t)fs->nactvar; + bl->flags = flags; + bl->vstart = fs->ls->vtop; + bl->prev = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + +/* End a scope. */ +static void fscope_end(FuncState *fs) +{ + FuncScope *bl = fs->bl; + LexState *ls = fs->ls; + fs->bl = bl->prev; + var_remove(ls, bl->nactvar); + fs->freereg = fs->nactvar; + lua_assert(bl->nactvar == fs->nactvar); + if ((bl->flags & (FSCOPE_UPVAL|FSCOPE_NOCLOSE)) == FSCOPE_UPVAL) + bcemit_AJ(fs, BC_UCLO, bl->nactvar, 0); + if ((bl->flags & FSCOPE_BREAK)) { + if ((bl->flags & FSCOPE_LOOP)) { + MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc); + ls->vtop = idx; /* Drop break label immediately. */ + gola_resolve(ls, bl, idx); + return; + } /* else: need the fixup step to propagate the breaks. */ + } else if (!(bl->flags & FSCOPE_GOLA)) { + return; + } + gola_fixup(ls, bl); +} + +/* Mark scope as having an upvalue. */ +static void fscope_uvmark(FuncState *fs, BCReg level) +{ + FuncScope *bl; + for (bl = fs->bl; bl && bl->nactvar > level; bl = bl->prev) + ; + if (bl) + bl->flags |= FSCOPE_UPVAL; +} + +/* -- Function state management ------------------------------------------- */ + +/* Fixup bytecode for prototype. */ +static void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, MSize n) +{ + BCInsLine *base = fs->bcbase; + MSize i; + pt->sizebc = n; + bc[0] = BCINS_AD((fs->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF, + fs->framesize, 0); + for (i = 1; i < n; i++) + bc[i] = base[i].ins; +} + +/* Fixup upvalues for child prototype, step #2. */ +static void fs_fixup_uv2(FuncState *fs, GCproto *pt) +{ + VarInfo *vstack = fs->ls->vstack; + uint16_t *uv = proto_uv(pt); + MSize i, n = pt->sizeuv; + for (i = 0; i < n; i++) { + VarIndex vidx = uv[i]; + if (vidx >= LJ_MAX_VSTACK) + uv[i] = vidx - LJ_MAX_VSTACK; + else if ((vstack[vidx].info & VSTACK_VAR_RW)) + uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL; + else + uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL | PROTO_UV_IMMUTABLE; + } +} + +/* Fixup constants for prototype. */ +static void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr) +{ + GCtab *kt; + TValue *array; + Node *node; + MSize i, hmask; + checklimitgt(fs, fs->nkn, BCMAX_D+1, "constants"); + checklimitgt(fs, fs->nkgc, BCMAX_D+1, "constants"); + setmref(pt->k, kptr); + pt->sizekn = fs->nkn; + pt->sizekgc = fs->nkgc; + kt = fs->kt; + array = tvref(kt->array); + for (i = 0; i < kt->asize; i++) + if (tvhaskslot(&array[i])) { + TValue *tv = &((TValue *)kptr)[tvkslot(&array[i])]; + if (LJ_DUALNUM) + setintV(tv, (int32_t)i); + else + setnumV(tv, (lua_Number)i); + } + node = noderef(kt->node); + hmask = kt->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (tvhaskslot(&n->val)) { + ptrdiff_t kidx = (ptrdiff_t)tvkslot(&n->val); + lua_assert(!tvisint(&n->key)); + if (tvisnum(&n->key)) { + TValue *tv = &((TValue *)kptr)[kidx]; + if (LJ_DUALNUM) { + lua_Number nn = numV(&n->key); + int32_t k = lj_num2int(nn); + lua_assert(!tvismzero(&n->key)); + if ((lua_Number)k == nn) + setintV(tv, k); + else + *tv = n->key; + } else { + *tv = n->key; + } + } else { + GCobj *o = gcV(&n->key); + setgcref(((GCRef *)kptr)[~kidx], o); + lj_gc_objbarrier(fs->L, pt, o); + if (tvisproto(&n->key)) + fs_fixup_uv2(fs, gco2pt(o)); + } + } + } +} + +/* Fixup upvalues for prototype, step #1. */ +static void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv) +{ + setmref(pt->uv, uv); + pt->sizeuv = fs->nuv; + memcpy(uv, fs->uvtmp, fs->nuv*sizeof(VarIndex)); +} + +#ifndef LUAJIT_DISABLE_DEBUGINFO +/* Prepare lineinfo for prototype. */ +static size_t fs_prep_line(FuncState *fs, BCLine numline) +{ + return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2); +} + +/* Fixup lineinfo for prototype. */ +static void fs_fixup_line(FuncState *fs, GCproto *pt, + void *lineinfo, BCLine numline) +{ + BCInsLine *base = fs->bcbase + 1; + BCLine first = fs->linedefined; + MSize i = 0, n = fs->pc-1; + pt->firstline = fs->linedefined; + pt->numline = numline; + setmref(pt->lineinfo, lineinfo); + if (LJ_LIKELY(numline < 256)) { + uint8_t *li = (uint8_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0 && delta < 256); + li[i] = (uint8_t)delta; + } while (++i < n); + } else if (LJ_LIKELY(numline < 65536)) { + uint16_t *li = (uint16_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0 && delta < 65536); + li[i] = (uint16_t)delta; + } while (++i < n); + } else { + uint32_t *li = (uint32_t *)lineinfo; + do { + BCLine delta = base[i].line - first; + lua_assert(delta >= 0); + li[i] = (uint32_t)delta; + } while (++i < n); + } +} + +/* Resize buffer if needed. */ +static LJ_NOINLINE void fs_buf_resize(LexState *ls, MSize len) +{ + MSize sz = ls->sb.sz * 2; + while (ls->sb.n + len > sz) sz = sz * 2; + lj_str_resizebuf(ls->L, &ls->sb, sz); +} + +static LJ_AINLINE void fs_buf_need(LexState *ls, MSize len) +{ + if (LJ_UNLIKELY(ls->sb.n + len > ls->sb.sz)) + fs_buf_resize(ls, len); +} + +/* Add string to buffer. */ +static void fs_buf_str(LexState *ls, const char *str, MSize len) +{ + char *p = ls->sb.buf + ls->sb.n; + MSize i; + ls->sb.n += len; + for (i = 0; i < len; i++) p[i] = str[i]; +} + +/* Add ULEB128 value to buffer. */ +static void fs_buf_uleb128(LexState *ls, uint32_t v) +{ + MSize n = ls->sb.n; + uint8_t *p = (uint8_t *)ls->sb.buf; + for (; v >= 0x80; v >>= 7) + p[n++] = (uint8_t)((v & 0x7f) | 0x80); + p[n++] = (uint8_t)v; + ls->sb.n = n; +} + +/* Prepare variable info for prototype. */ +static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar) +{ + VarInfo *vs =ls->vstack, *ve; + MSize i, n; + BCPos lastpc; + lj_str_resetbuf(&ls->sb); /* Copy to temp. string buffer. */ + /* Store upvalue names. */ + for (i = 0, n = fs->nuv; i < n; i++) { + GCstr *s = strref(vs[fs->uvmap[i]].name); + MSize len = s->len+1; + fs_buf_need(ls, len); + fs_buf_str(ls, strdata(s), len); + } + *ofsvar = ls->sb.n; + lastpc = 0; + /* Store local variable names and compressed ranges. */ + for (ve = vs + ls->vtop, vs += fs->vbase; vs < ve; vs++) { + if (!gola_isgotolabel(vs)) { + GCstr *s = strref(vs->name); + BCPos startpc; + if ((uintptr_t)s < VARNAME__MAX) { + fs_buf_need(ls, 1 + 2*5); + ls->sb.buf[ls->sb.n++] = (uint8_t)(uintptr_t)s; + } else { + MSize len = s->len+1; + fs_buf_need(ls, len + 2*5); + fs_buf_str(ls, strdata(s), len); + } + startpc = vs->startpc; + fs_buf_uleb128(ls, startpc-lastpc); + fs_buf_uleb128(ls, vs->endpc-startpc); + lastpc = startpc; + } + } + fs_buf_need(ls, 1); + ls->sb.buf[ls->sb.n++] = '\0'; /* Terminator for varinfo. */ + return ls->sb.n; +} + +/* Fixup variable info for prototype. */ +static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar) +{ + setmref(pt->uvinfo, p); + setmref(pt->varinfo, (char *)p + ofsvar); + memcpy(p, ls->sb.buf, ls->sb.n); /* Copy from temp. string buffer. */ +} +#else + +/* Initialize with empty debug info, if disabled. */ +#define fs_prep_line(fs, numline) (UNUSED(numline), 0) +#define fs_fixup_line(fs, pt, li, numline) \ + pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL) +#define fs_prep_var(ls, fs, ofsvar) (UNUSED(ofsvar), 0) +#define fs_fixup_var(ls, pt, p, ofsvar) \ + setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL) + +#endif + +/* Check if bytecode op returns. */ +static int bcopisret(BCOp op) +{ + switch (op) { + case BC_CALLMT: case BC_CALLT: + case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1: + return 1; + default: + return 0; + } +} + +/* Fixup return instruction for prototype. */ +static void fs_fixup_ret(FuncState *fs) +{ + BCPos lastpc = fs->pc; + if (lastpc <= fs->lasttarget || !bcopisret(bc_op(fs->bcbase[lastpc-1].ins))) { + if ((fs->bl->flags & FSCOPE_UPVAL)) + bcemit_AJ(fs, BC_UCLO, 0, 0); + bcemit_AD(fs, BC_RET0, 0, 1); /* Need final return. */ + } + fs->bl->flags |= FSCOPE_NOCLOSE; /* Handled above. */ + fscope_end(fs); + lua_assert(fs->bl == NULL); + /* May need to fixup returns encoded before first function was created. */ + if (fs->flags & PROTO_FIXUP_RETURN) { + BCPos pc; + for (pc = 1; pc < lastpc; pc++) { + BCIns ins = fs->bcbase[pc].ins; + BCPos offset; + switch (bc_op(ins)) { + case BC_CALLMT: case BC_CALLT: + case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1: + offset = bcemit_INS(fs, ins); /* Copy original instruction. */ + fs->bcbase[offset].line = fs->bcbase[pc].line; + offset = offset-(pc+1)+BCBIAS_J; + if (offset > BCMAX_D) + err_syntax(fs->ls, LJ_ERR_XFIXUP); + /* Replace with UCLO plus branch. */ + fs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset); + break; + case BC_UCLO: + return; /* We're done. */ + default: + break; + } + } + } +} + +/* Finish a FuncState and return the new prototype. */ +static GCproto *fs_finish(LexState *ls, BCLine line) +{ + lua_State *L = ls->L; + FuncState *fs = ls->fs; + BCLine numline = line - fs->linedefined; + size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar; + GCproto *pt; + + /* Apply final fixups. */ + fs_fixup_ret(fs); + + /* Calculate total size of prototype including all colocated arrays. */ + sizept = sizeof(GCproto) + fs->pc*sizeof(BCIns) + fs->nkgc*sizeof(GCRef); + sizept = (sizept + sizeof(TValue)-1) & ~(sizeof(TValue)-1); + ofsk = sizept; sizept += fs->nkn*sizeof(TValue); + ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2; + ofsli = sizept; sizept += fs_prep_line(fs, numline); + ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar); + + /* Allocate prototype and initialize its fields. */ + pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept); + pt->gct = ~LJ_TPROTO; + pt->sizept = (MSize)sizept; + pt->trace = 0; + pt->flags = (uint8_t)(fs->flags & ~(PROTO_HAS_RETURN|PROTO_FIXUP_RETURN)); + pt->numparams = fs->numparams; + pt->framesize = fs->framesize; + setgcref(pt->chunkname, obj2gco(ls->chunkname)); + + /* Close potentially uninitialized gap between bc and kgc. */ + *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(fs->nkgc+1)) = 0; + fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), fs->pc); + fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk)); + fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv)); + fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline); + fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar); + + lj_vmevent_send(L, BC, + setprotoV(L, L->top++, pt); + ); + + L->top--; /* Pop table of constants. */ + ls->vtop = fs->vbase; /* Reset variable stack. */ + ls->fs = fs->prev; + lua_assert(ls->fs != NULL || ls->token == TK_eof); + return pt; +} + +/* Initialize a new FuncState. */ +static void fs_init(LexState *ls, FuncState *fs) +{ + lua_State *L = ls->L; + fs->prev = ls->fs; ls->fs = fs; /* Append to list. */ + fs->ls = ls; + fs->vbase = ls->vtop; + fs->L = L; + fs->pc = 0; + fs->lasttarget = 0; + fs->jpc = NO_JMP; + fs->freereg = 0; + fs->nkgc = 0; + fs->nkn = 0; + fs->nactvar = 0; + fs->nuv = 0; + fs->bl = NULL; + fs->flags = 0; + fs->framesize = 1; /* Minimum frame size. */ + fs->kt = lj_tab_new(L, 0, 0); + /* Anchor table of constants in stack to avoid being collected. */ + settabV(L, L->top, fs->kt); + incr_top(L); +} + +/* -- Expressions --------------------------------------------------------- */ + +/* Forward declaration. */ +static void expr(LexState *ls, ExpDesc *v); + +/* Return string expression. */ +static void expr_str(LexState *ls, ExpDesc *e) +{ + expr_init(e, VKSTR, 0); + e->u.sval = lex_str(ls); +} + +/* Return index expression. */ +static void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e) +{ + /* Already called: expr_toval(fs, e). */ + t->k = VINDEXED; + if (expr_isnumk(e)) { +#if LJ_DUALNUM + if (tvisint(expr_numtv(e))) { + int32_t k = intV(expr_numtv(e)); + if (checku8(k)) { + t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ + return; + } + } +#else + lua_Number n = expr_numberV(e); + int32_t k = lj_num2int(n); + if (checku8(k) && n == (lua_Number)k) { + t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ + return; + } +#endif + } else if (expr_isstrk(e)) { + BCReg idx = const_str(fs, e); + if (idx <= BCMAX_C) { + t->u.s.aux = ~idx; /* -256..-1: const string key */ + return; + } + } + t->u.s.aux = expr_toanyreg(fs, e); /* 0..255: register */ +} + +/* Parse index expression with named field. */ +static void expr_field(LexState *ls, ExpDesc *v) +{ + FuncState *fs = ls->fs; + ExpDesc key; + expr_toanyreg(fs, v); + lj_lex_next(ls); /* Skip dot or colon. */ + expr_str(ls, &key); + expr_index(fs, v, &key); +} + +/* Parse index expression with brackets. */ +static void expr_bracket(LexState *ls, ExpDesc *v) +{ + lj_lex_next(ls); /* Skip '['. */ + expr(ls, v); + expr_toval(ls->fs, v); + lex_check(ls, ']'); +} + +/* Get value of constant expression. */ +static void expr_kvalue(TValue *v, ExpDesc *e) +{ + if (e->k <= VKTRUE) { + setitype(v, ~(uint32_t)e->k); + } else if (e->k == VKSTR) { + setgcref(v->gcr, obj2gco(e->u.sval)); + setitype(v, LJ_TSTR); + } else { + lua_assert(tvisnumber(expr_numtv(e))); + *v = *expr_numtv(e); + } +} + +/* Parse table constructor expression. */ +static void expr_table(LexState *ls, ExpDesc *e) +{ + FuncState *fs = ls->fs; + BCLine line = ls->linenumber; + GCtab *t = NULL; + int vcall = 0, needarr = 0, fixt = 0; + uint32_t narr = 1; /* First array index. */ + uint32_t nhash = 0; /* Number of hash entries. */ + BCReg freg = fs->freereg; + BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0); + expr_init(e, VNONRELOC, freg); + bcreg_reserve(fs, 1); + freg++; + lex_check(ls, '{'); + while (ls->token != '}') { + ExpDesc key, val; + vcall = 0; + if (ls->token == '[') { + expr_bracket(ls, &key); /* Already calls expr_toval. */ + if (!expr_isk(&key)) expr_index(fs, e, &key); + if (expr_isnumk(&key) && expr_numiszero(&key)) needarr = 1; else nhash++; + lex_check(ls, '='); + } else if ((ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) && + lj_lex_lookahead(ls) == '=') { + expr_str(ls, &key); + lex_check(ls, '='); + nhash++; + } else { + expr_init(&key, VKNUM, 0); + setintV(&key.u.nval, (int)narr); + narr++; + needarr = vcall = 1; + } + expr(ls, &val); + if (expr_isk(&key) && key.k != VKNIL && + (key.k == VKSTR || expr_isk_nojump(&val))) { + TValue k, *v; + if (!t) { /* Create template table on demand. */ + BCReg kidx; + t = lj_tab_new(fs->L, needarr ? narr : 0, hsize2hbits(nhash)); + kidx = const_gc(fs, obj2gco(t), LJ_TTAB); + fs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx); + } + vcall = 0; + expr_kvalue(&k, &key); + v = lj_tab_set(fs->L, t, &k); + lj_gc_anybarriert(fs->L, t); + if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */ + expr_kvalue(v, &val); + } else { /* Otherwise create dummy string key (avoids lj_tab_newkey). */ + settabV(fs->L, v, t); /* Preserve key with table itself as value. */ + fixt = 1; /* Fix this later, after all resizes. */ + goto nonconst; + } + } else { + nonconst: + if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; } + if (expr_isk(&key)) expr_index(fs, e, &key); + bcemit_store(fs, e, &val); + } + fs->freereg = freg; + if (!lex_opt(ls, ',') && !lex_opt(ls, ';')) break; + } + lex_match(ls, '}', '{', line); + if (vcall) { + BCInsLine *ilp = &fs->bcbase[fs->pc-1]; + ExpDesc en; + lua_assert(bc_a(ilp->ins) == freg && + bc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB)); + expr_init(&en, VKNUM, 0); + en.u.nval.u32.lo = narr-1; + en.u.nval.u32.hi = 0x43300000; /* Biased integer to avoid denormals. */ + if (narr > 256) { fs->pc--; ilp--; } + ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en)); + setbc_b(&ilp[-1].ins, 0); + } + if (pc == fs->pc-1) { /* Make expr relocable if possible. */ + e->u.s.info = pc; + fs->freereg--; + e->k = VRELOCABLE; + } else { + e->k = VNONRELOC; /* May have been changed by expr_index. */ + } + if (!t) { /* Construct TNEW RD: hhhhhaaaaaaaaaaa. */ + BCIns *ip = &fs->bcbase[pc].ins; + if (!needarr) narr = 0; + else if (narr < 3) narr = 3; + else if (narr > 0x7ff) narr = 0x7ff; + setbc_d(ip, narr|(hsize2hbits(nhash)<<11)); + } else { + if (needarr && t->asize < narr) + lj_tab_reasize(fs->L, t, narr-1); + if (fixt) { /* Fix value for dummy keys in template table. */ + Node *node = noderef(t->node); + uint32_t i, hmask = t->hmask; + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (tvistab(&n->val)) { + lua_assert(tabV(&n->val) == t); + setnilV(&n->val); /* Turn value into nil. */ + } + } + } + lj_gc_check(fs->L); + } +} + +/* Parse function parameters. */ +static BCReg parse_params(LexState *ls, int needself) +{ + FuncState *fs = ls->fs; + BCReg nparams = 0; + lex_check(ls, '('); + if (needself) + var_new_lit(ls, nparams++, "self"); + if (ls->token != ')') { + do { + if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) { + var_new(ls, nparams++, lex_str(ls)); + } else if (ls->token == TK_dots) { + lj_lex_next(ls); + fs->flags |= PROTO_VARARG; + break; + } else { + err_syntax(ls, LJ_ERR_XPARAM); + } + } while (lex_opt(ls, ',')); + } + var_add(ls, nparams); + lua_assert(fs->nactvar == nparams); + bcreg_reserve(fs, nparams); + lex_check(ls, ')'); + return nparams; +} + +/* Forward declaration. */ +static void parse_chunk(LexState *ls); + +/* Parse body of a function. */ +static void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line) +{ + FuncState fs, *pfs = ls->fs; + FuncScope bl; + GCproto *pt; + ptrdiff_t oldbase = pfs->bcbase - ls->bcstack; + fs_init(ls, &fs); + fscope_begin(&fs, &bl, 0); + fs.linedefined = line; + fs.numparams = (uint8_t)parse_params(ls, needself); + fs.bcbase = pfs->bcbase + pfs->pc; + fs.bclim = pfs->bclim - pfs->pc; + bcemit_AD(&fs, BC_FUNCF, 0, 0); /* Placeholder. */ + parse_chunk(ls); + if (ls->token != TK_end) lex_match(ls, TK_end, TK_function, line); + pt = fs_finish(ls, (ls->lastline = ls->linenumber)); + pfs->bcbase = ls->bcstack + oldbase; /* May have been reallocated. */ + pfs->bclim = (BCPos)(ls->sizebcstack - oldbase); + /* Store new prototype in the constant array of the parent. */ + expr_init(e, VRELOCABLE, + bcemit_AD(pfs, BC_FNEW, 0, const_gc(pfs, obj2gco(pt), LJ_TPROTO))); +#if LJ_HASFFI + pfs->flags |= (fs.flags & PROTO_FFI); +#endif + if (!(pfs->flags & PROTO_CHILD)) { + if (pfs->flags & PROTO_HAS_RETURN) + pfs->flags |= PROTO_FIXUP_RETURN; + pfs->flags |= PROTO_CHILD; + } + lj_lex_next(ls); +} + +/* Parse expression list. Last expression is left open. */ +static BCReg expr_list(LexState *ls, ExpDesc *v) +{ + BCReg n = 1; + expr(ls, v); + while (lex_opt(ls, ',')) { + expr_tonextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + +/* Parse function argument list. */ +static void parse_args(LexState *ls, ExpDesc *e) +{ + FuncState *fs = ls->fs; + ExpDesc args; + BCIns ins; + BCReg base; + BCLine line = ls->linenumber; + if (ls->token == '(') { +#if !LJ_52 + if (line != ls->lastline) + err_syntax(ls, LJ_ERR_XAMBIG); +#endif + lj_lex_next(ls); + if (ls->token == ')') { /* f(). */ + args.k = VVOID; + } else { + expr_list(ls, &args); + if (args.k == VCALL) /* f(a, b, g()) or f(a, b, ...). */ + setbc_b(bcptr(fs, &args), 0); /* Pass on multiple results. */ + } + lex_match(ls, ')', '(', line); + } else if (ls->token == '{') { + expr_table(ls, &args); + } else if (ls->token == TK_string) { + expr_init(&args, VKSTR, 0); + args.u.sval = strV(&ls->tokenval); + lj_lex_next(ls); + } else { + err_syntax(ls, LJ_ERR_XFUNARG); + return; /* Silence compiler. */ + } + lua_assert(e->k == VNONRELOC); + base = e->u.s.info; /* Base register for call. */ + if (args.k == VCALL) { + ins = BCINS_ABC(BC_CALLM, base, 2, args.u.s.aux - base - 1); + } else { + if (args.k != VVOID) + expr_tonextreg(fs, &args); + ins = BCINS_ABC(BC_CALL, base, 2, fs->freereg - base); + } + expr_init(e, VCALL, bcemit_INS(fs, ins)); + e->u.s.aux = base; + fs->bcbase[fs->pc - 1].line = line; + fs->freereg = base+1; /* Leave one result by default. */ +} + +/* Parse primary expression. */ +static void expr_primary(LexState *ls, ExpDesc *v) +{ + FuncState *fs = ls->fs; + /* Parse prefix expression. */ + if (ls->token == '(') { + BCLine line = ls->linenumber; + lj_lex_next(ls); + expr(ls, v); + lex_match(ls, ')', '(', line); + expr_discharge(ls->fs, v); + } else if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) { + var_lookup(ls, v); + } else { + err_syntax(ls, LJ_ERR_XSYMBOL); + } + for (;;) { /* Parse multiple expression suffixes. */ + if (ls->token == '.') { + expr_field(ls, v); + } else if (ls->token == '[') { + ExpDesc key; + expr_toanyreg(fs, v); + expr_bracket(ls, &key); + expr_index(fs, v, &key); + } else if (ls->token == ':') { + ExpDesc key; + lj_lex_next(ls); + expr_str(ls, &key); + bcemit_method(fs, v, &key); + parse_args(ls, v); + } else if (ls->token == '(' || ls->token == TK_string || ls->token == '{') { + expr_tonextreg(fs, v); + parse_args(ls, v); + } else { + break; + } + } +} + +/* Parse simple expression. */ +static void expr_simple(LexState *ls, ExpDesc *v) +{ + switch (ls->token) { + case TK_number: + expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokenval)) ? VKCDATA : VKNUM, 0); + copyTV(ls->L, &v->u.nval, &ls->tokenval); + break; + case TK_string: + expr_init(v, VKSTR, 0); + v->u.sval = strV(&ls->tokenval); + break; + case TK_nil: + expr_init(v, VKNIL, 0); + break; + case TK_true: + expr_init(v, VKTRUE, 0); + break; + case TK_false: + expr_init(v, VKFALSE, 0); + break; + case TK_dots: { /* Vararg. */ + FuncState *fs = ls->fs; + BCReg base; + checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS); + bcreg_reserve(fs, 1); + base = fs->freereg-1; + expr_init(v, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams)); + v->u.s.aux = base; + break; + } + case '{': /* Table constructor. */ + expr_table(ls, v); + return; + case TK_function: + lj_lex_next(ls); + parse_body(ls, v, 0, ls->linenumber); + return; + default: + expr_primary(ls, v); + return; + } + lj_lex_next(ls); +} + +/* Manage syntactic levels to avoid blowing up the stack. */ +static void synlevel_begin(LexState *ls) +{ + if (++ls->level >= LJ_MAX_XLEVEL) + lj_lex_error(ls, 0, LJ_ERR_XLEVELS); +} + +#define synlevel_end(ls) ((ls)->level--) + +/* Convert token to binary operator. */ +static BinOpr token2binop(LexToken tok) +{ + switch (tok) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_concat: return OPR_CONCAT; + case TK_ne: return OPR_NE; + case TK_eq: return OPR_EQ; + case '<': return OPR_LT; + case TK_le: return OPR_LE; + case '>': return OPR_GT; + case TK_ge: return OPR_GE; + case TK_and: return OPR_AND; + case TK_or: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + +/* Priorities for each binary operator. ORDER OPR. */ +static const struct { + uint8_t left; /* Left priority. */ + uint8_t right; /* Right priority. */ +} priority[] = { + {6,6}, {6,6}, {7,7}, {7,7}, {7,7}, /* ADD SUB MUL DIV MOD */ + {10,9}, {5,4}, /* POW CONCAT (right associative) */ + {3,3}, {3,3}, /* EQ NE */ + {3,3}, {3,3}, {3,3}, {3,3}, /* LT GE GT LE */ + {2,2}, {1,1} /* AND OR */ +}; + +#define UNARY_PRIORITY 8 /* Priority for unary operators. */ + +/* Forward declaration. */ +static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit); + +/* Parse unary expression. */ +static void expr_unop(LexState *ls, ExpDesc *v) +{ + BCOp op; + if (ls->token == TK_not) { + op = BC_NOT; + } else if (ls->token == '-') { + op = BC_UNM; + } else if (ls->token == '#') { + op = BC_LEN; + } else { + expr_simple(ls, v); + return; + } + lj_lex_next(ls); + expr_binop(ls, v, UNARY_PRIORITY); + bcemit_unop(ls->fs, op, v); +} + +/* Parse binary expressions with priority higher than the limit. */ +static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit) +{ + BinOpr op; + synlevel_begin(ls); + expr_unop(ls, v); + op = token2binop(ls->token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + ExpDesc v2; + BinOpr nextop; + lj_lex_next(ls); + bcemit_binop_left(ls->fs, op, v); + /* Parse binary expression with higher priority. */ + nextop = expr_binop(ls, &v2, priority[op].right); + bcemit_binop(ls->fs, op, v, &v2); + op = nextop; + } + synlevel_end(ls); + return op; /* Return unconsumed binary operator (if any). */ +} + +/* Parse expression. */ +static void expr(LexState *ls, ExpDesc *v) +{ + expr_binop(ls, v, 0); /* Priority 0: parse whole expression. */ +} + +/* Assign expression to the next register. */ +static void expr_next(LexState *ls) +{ + ExpDesc e; + expr(ls, &e); + expr_tonextreg(ls->fs, &e); +} + +/* Parse conditional expression. */ +static BCPos expr_cond(LexState *ls) +{ + ExpDesc v; + expr(ls, &v); + if (v.k == VKNIL) v.k = VKFALSE; + bcemit_branch_t(ls->fs, &v); + return v.f; +} + +/* -- Assignments --------------------------------------------------------- */ + +/* List of LHS variables. */ +typedef struct LHSVarList { + ExpDesc v; /* LHS variable. */ + struct LHSVarList *prev; /* Link to previous LHS variable. */ +} LHSVarList; + +/* Eliminate write-after-read hazards for local variable assignment. */ +static void assign_hazard(LexState *ls, LHSVarList *lh, const ExpDesc *v) +{ + FuncState *fs = ls->fs; + BCReg reg = v->u.s.info; /* Check against this variable. */ + BCReg tmp = fs->freereg; /* Rename to this temp. register (if needed). */ + int hazard = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == reg) { /* t[i], t = 1, 2 */ + hazard = 1; + lh->v.u.s.info = tmp; + } + if (lh->v.u.s.aux == reg) { /* t[i], i = 1, 2 */ + hazard = 1; + lh->v.u.s.aux = tmp; + } + } + } + if (hazard) { + bcemit_AD(fs, BC_MOV, tmp, reg); /* Rename conflicting variable. */ + bcreg_reserve(fs, 1); + } +} + +/* Adjust LHS/RHS of an assignment. */ +static void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e) +{ + FuncState *fs = ls->fs; + int32_t extra = (int32_t)nvars - (int32_t)nexps; + if (e->k == VCALL) { + extra++; /* Compensate for the VCALL itself. */ + if (extra < 0) extra = 0; + setbc_b(bcptr(fs, e), extra+1); /* Fixup call results. */ + if (extra > 1) bcreg_reserve(fs, (BCReg)extra-1); + } else { + if (e->k != VVOID) + expr_tonextreg(fs, e); /* Close last expression. */ + if (extra > 0) { /* Leftover LHS are set to nil. */ + BCReg reg = fs->freereg; + bcreg_reserve(fs, (BCReg)extra); + bcemit_nil(fs, reg, (BCReg)extra); + } + } +} + +/* Recursively parse assignment statement. */ +static void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars) +{ + ExpDesc e; + checkcond(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, LJ_ERR_XSYNTAX); + if (lex_opt(ls, ',')) { /* Collect LHS list and recurse upwards. */ + LHSVarList vl; + vl.prev = lh; + expr_primary(ls, &vl.v); + if (vl.v.k == VLOCAL) + assign_hazard(ls, lh, &vl.v); + checklimit(ls->fs, ls->level + nvars, LJ_MAX_XLEVEL, "variable names"); + parse_assignment(ls, &vl, nvars+1); + } else { /* Parse RHS. */ + BCReg nexps; + lex_check(ls, '='); + nexps = expr_list(ls, &e); + if (nexps == nvars) { + if (e.k == VCALL) { + if (bc_op(*bcptr(ls->fs, &e)) == BC_VARG) { /* Vararg assignment. */ + ls->fs->freereg--; + e.k = VRELOCABLE; + } else { /* Multiple call results. */ + e.u.s.info = e.u.s.aux; /* Base of call is not relocatable. */ + e.k = VNONRELOC; + } + } + bcemit_store(ls->fs, &lh->v, &e); + return; + } + assign_adjust(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* Drop leftover regs. */ + } + /* Assign RHS to LHS and recurse downwards. */ + expr_init(&e, VNONRELOC, ls->fs->freereg-1); + bcemit_store(ls->fs, &lh->v, &e); +} + +/* Parse call statement or assignment. */ +static void parse_call_assign(LexState *ls) +{ + FuncState *fs = ls->fs; + LHSVarList vl; + expr_primary(ls, &vl.v); + if (vl.v.k == VCALL) { /* Function call statement. */ + setbc_b(bcptr(fs, &vl.v), 1); /* No results. */ + } else { /* Start of an assignment. */ + vl.prev = NULL; + parse_assignment(ls, &vl, 1); + } +} + +/* Parse 'local' statement. */ +static void parse_local(LexState *ls) +{ + if (lex_opt(ls, TK_function)) { /* Local function declaration. */ + ExpDesc v, b; + FuncState *fs = ls->fs; + var_new(ls, 0, lex_str(ls)); + expr_init(&v, VLOCAL, fs->freereg); + v.u.s.aux = fs->varmap[fs->freereg]; + bcreg_reserve(fs, 1); + var_add(ls, 1); + parse_body(ls, &b, 0, ls->linenumber); + /* bcemit_store(fs, &v, &b) without setting VSTACK_VAR_RW. */ + expr_free(fs, &b); + expr_toreg(fs, &b, v.u.s.info); + /* The upvalue is in scope, but the local is only valid after the store. */ + var_get(ls, fs, fs->nactvar - 1).startpc = fs->pc; + } else { /* Local variable declaration. */ + ExpDesc e; + BCReg nexps, nvars = 0; + do { /* Collect LHS. */ + var_new(ls, nvars++, lex_str(ls)); + } while (lex_opt(ls, ',')); + if (lex_opt(ls, '=')) { /* Optional RHS. */ + nexps = expr_list(ls, &e); + } else { /* Or implicitly set to nil. */ + e.k = VVOID; + nexps = 0; + } + assign_adjust(ls, nvars, nexps, &e); + var_add(ls, nvars); + } +} + +/* Parse 'function' statement. */ +static void parse_func(LexState *ls, BCLine line) +{ + FuncState *fs; + ExpDesc v, b; + int needself = 0; + lj_lex_next(ls); /* Skip 'function'. */ + /* Parse function name. */ + var_lookup(ls, &v); + while (ls->token == '.') /* Multiple dot-separated fields. */ + expr_field(ls, &v); + if (ls->token == ':') { /* Optional colon to signify method call. */ + needself = 1; + expr_field(ls, &v); + } + parse_body(ls, &b, needself, line); + fs = ls->fs; + bcemit_store(fs, &v, &b); + fs->bcbase[fs->pc - 1].line = line; /* Set line for the store. */ +} + +/* -- Control transfer statements ----------------------------------------- */ + +/* Check for end of block. */ +static int endofblock(LexToken token) +{ + switch (token) { + case TK_else: case TK_elseif: case TK_end: case TK_until: case TK_eof: + return 1; + default: + return 0; + } +} + +/* Parse 'return' statement. */ +static void parse_return(LexState *ls) +{ + BCIns ins; + FuncState *fs = ls->fs; + lj_lex_next(ls); /* Skip 'return'. */ + fs->flags |= PROTO_HAS_RETURN; + if (endofblock(ls->token) || ls->token == ';') { /* Bare return. */ + ins = BCINS_AD(BC_RET0, 0, 1); + } else { /* Return with one or more values. */ + ExpDesc e; /* Receives the _last_ expression in the list. */ + BCReg nret = expr_list(ls, &e); + if (nret == 1) { /* Return one result. */ + if (e.k == VCALL) { /* Check for tail call. */ + BCIns *ip = bcptr(fs, &e); + /* It doesn't pay off to add BC_VARGT just for 'return ...'. */ + if (bc_op(*ip) == BC_VARG) goto notailcall; + fs->pc--; + ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip)); + } else { /* Can return the result from any register. */ + ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2); + } + } else { + if (e.k == VCALL) { /* Append all results from a call. */ + notailcall: + setbc_b(bcptr(fs, &e), 0); + ins = BCINS_AD(BC_RETM, fs->nactvar, e.u.s.aux - fs->nactvar); + } else { + expr_tonextreg(fs, &e); /* Force contiguous registers. */ + ins = BCINS_AD(BC_RET, fs->nactvar, nret+1); + } + } + } + if (fs->flags & PROTO_CHILD) + bcemit_AJ(fs, BC_UCLO, 0, 0); /* May need to close upvalues first. */ + bcemit_INS(fs, ins); +} + +/* Parse 'break' statement. */ +static void parse_break(LexState *ls) +{ + ls->fs->bl->flags |= FSCOPE_BREAK; + gola_new(ls, NAME_BREAK, VSTACK_GOTO, bcemit_jmp(ls->fs)); +} + +/* Parse 'goto' statement. */ +static void parse_goto(LexState *ls) +{ + FuncState *fs = ls->fs; + GCstr *name = lex_str(ls); + VarInfo *vl = gola_findlabel(ls, name); + if (vl) /* Treat backwards goto within same scope like a loop. */ + bcemit_AJ(fs, BC_LOOP, vl->slot, -1); /* No BC range check. */ + fs->bl->flags |= FSCOPE_GOLA; + gola_new(ls, name, VSTACK_GOTO, bcemit_jmp(fs)); +} + +/* Parse label. */ +static void parse_label(LexState *ls) +{ + FuncState *fs = ls->fs; + GCstr *name; + MSize idx; + fs->lasttarget = fs->pc; + fs->bl->flags |= FSCOPE_GOLA; + lj_lex_next(ls); /* Skip '::'. */ + name = lex_str(ls); + if (gola_findlabel(ls, name)) + lj_lex_error(ls, 0, LJ_ERR_XLDUP, strdata(name)); + idx = gola_new(ls, name, VSTACK_LABEL, fs->pc); + lex_check(ls, TK_label); + /* Recursively parse trailing statements: labels and ';' (Lua 5.2 only). */ + for (;;) { + if (ls->token == TK_label) { + synlevel_begin(ls); + parse_label(ls); + synlevel_end(ls); + } else if (LJ_52 && ls->token == ';') { + lj_lex_next(ls); + } else { + break; + } + } + /* Trailing label is considered to be outside of scope. */ + if (endofblock(ls->token) && ls->token != TK_until) + ls->vstack[idx].slot = fs->bl->nactvar; + gola_resolve(ls, fs->bl, idx); +} + +/* -- Blocks, loops and conditional statements ---------------------------- */ + +/* Parse a block. */ +static void parse_block(LexState *ls) +{ + FuncState *fs = ls->fs; + FuncScope bl; + fscope_begin(fs, &bl, 0); + parse_chunk(ls); + fscope_end(fs); +} + +/* Parse 'while' statement. */ +static void parse_while(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos start, loop, condexit; + FuncScope bl; + lj_lex_next(ls); /* Skip 'while'. */ + start = fs->lasttarget = fs->pc; + condexit = expr_cond(ls); + fscope_begin(fs, &bl, FSCOPE_LOOP); + lex_check(ls, TK_do); + loop = bcemit_AD(fs, BC_LOOP, fs->nactvar, 0); + parse_block(ls); + jmp_patch(fs, bcemit_jmp(fs), start); + lex_match(ls, TK_end, TK_while, line); + fscope_end(fs); + jmp_tohere(fs, condexit); + jmp_patchins(fs, loop, fs->pc); +} + +/* Parse 'repeat' statement. */ +static void parse_repeat(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos loop = fs->lasttarget = fs->pc; + BCPos condexit; + FuncScope bl1, bl2; + fscope_begin(fs, &bl1, FSCOPE_LOOP); /* Breakable loop scope. */ + fscope_begin(fs, &bl2, 0); /* Inner scope. */ + lj_lex_next(ls); /* Skip 'repeat'. */ + bcemit_AD(fs, BC_LOOP, fs->nactvar, 0); + parse_chunk(ls); + lex_match(ls, TK_until, TK_repeat, line); + condexit = expr_cond(ls); /* Parse condition (still inside inner scope). */ + if (!(bl2.flags & FSCOPE_UPVAL)) { /* No upvalues? Just end inner scope. */ + fscope_end(fs); + } else { /* Otherwise generate: cond: UCLO+JMP out, !cond: UCLO+JMP loop. */ + parse_break(ls); /* Break from loop and close upvalues. */ + jmp_tohere(fs, condexit); + fscope_end(fs); /* End inner scope and close upvalues. */ + condexit = bcemit_jmp(fs); + } + jmp_patch(fs, condexit, loop); /* Jump backwards if !cond. */ + jmp_patchins(fs, loop, fs->pc); + fscope_end(fs); /* End loop scope. */ +} + +/* Parse numeric 'for'. */ +static void parse_for_num(LexState *ls, GCstr *varname, BCLine line) +{ + FuncState *fs = ls->fs; + BCReg base = fs->freereg; + FuncScope bl; + BCPos loop, loopend; + /* Hidden control variables. */ + var_new_fixed(ls, FORL_IDX, VARNAME_FOR_IDX); + var_new_fixed(ls, FORL_STOP, VARNAME_FOR_STOP); + var_new_fixed(ls, FORL_STEP, VARNAME_FOR_STEP); + /* Visible copy of index variable. */ + var_new(ls, FORL_EXT, varname); + lex_check(ls, '='); + expr_next(ls); + lex_check(ls, ','); + expr_next(ls); + if (lex_opt(ls, ',')) { + expr_next(ls); + } else { + bcemit_AD(fs, BC_KSHORT, fs->freereg, 1); /* Default step is 1. */ + bcreg_reserve(fs, 1); + } + var_add(ls, 3); /* Hidden control variables. */ + lex_check(ls, TK_do); + loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP); + fscope_begin(fs, &bl, 0); /* Scope for visible variables. */ + var_add(ls, 1); + bcreg_reserve(fs, 1); + parse_block(ls); + fscope_end(fs); + /* Perform loop inversion. Loop control instructions are at the end. */ + loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP); + fs->bcbase[loopend].line = line; /* Fix line for control ins. */ + jmp_patchins(fs, loopend, loop+1); + jmp_patchins(fs, loop, fs->pc); +} + +/* Try to predict whether the iterator is next() and specialize the bytecode. +** Detecting next() and pairs() by name is simplistic, but quite effective. +** The interpreter backs off if the check for the closure fails at runtime. +*/ +static int predict_next(LexState *ls, FuncState *fs, BCPos pc) +{ + BCIns ins = fs->bcbase[pc].ins; + GCstr *name; + cTValue *o; + switch (bc_op(ins)) { + case BC_MOV: + name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name)); + break; + case BC_UGET: + name = gco2str(gcref(ls->vstack[fs->uvmap[bc_d(ins)]].name)); + break; + case BC_GGET: + /* There's no inverse index (yet), so lookup the strings. */ + o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "pairs")); + if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins)) + return 1; + o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "next")); + if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins)) + return 1; + return 0; + default: + return 0; + } + return (name->len == 5 && !strcmp(strdata(name), "pairs")) || + (name->len == 4 && !strcmp(strdata(name), "next")); +} + +/* Parse 'for' iterator. */ +static void parse_for_iter(LexState *ls, GCstr *indexname) +{ + FuncState *fs = ls->fs; + ExpDesc e; + BCReg nvars = 0; + BCLine line; + BCReg base = fs->freereg + 3; + BCPos loop, loopend, exprpc = fs->pc; + FuncScope bl; + int isnext; + /* Hidden control variables. */ + var_new_fixed(ls, nvars++, VARNAME_FOR_GEN); + var_new_fixed(ls, nvars++, VARNAME_FOR_STATE); + var_new_fixed(ls, nvars++, VARNAME_FOR_CTL); + /* Visible variables returned from iterator. */ + var_new(ls, nvars++, indexname); + while (lex_opt(ls, ',')) + var_new(ls, nvars++, lex_str(ls)); + lex_check(ls, TK_in); + line = ls->linenumber; + assign_adjust(ls, 3, expr_list(ls, &e), &e); + bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */ + isnext = (nvars <= 5 && predict_next(ls, fs, exprpc)); + var_add(ls, 3); /* Hidden control variables. */ + lex_check(ls, TK_do); + loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP); + fscope_begin(fs, &bl, 0); /* Scope for visible variables. */ + var_add(ls, nvars-3); + bcreg_reserve(fs, nvars-3); + parse_block(ls); + fscope_end(fs); + /* Perform loop inversion. Loop control instructions are at the end. */ + jmp_patchins(fs, loop, fs->pc); + bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1); + loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP); + fs->bcbase[loopend-1].line = line; /* Fix line for control ins. */ + fs->bcbase[loopend].line = line; + jmp_patchins(fs, loopend, loop+1); +} + +/* Parse 'for' statement. */ +static void parse_for(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + GCstr *varname; + FuncScope bl; + fscope_begin(fs, &bl, FSCOPE_LOOP); + lj_lex_next(ls); /* Skip 'for'. */ + varname = lex_str(ls); /* Get first variable name. */ + if (ls->token == '=') + parse_for_num(ls, varname, line); + else if (ls->token == ',' || ls->token == TK_in) + parse_for_iter(ls, varname); + else + err_syntax(ls, LJ_ERR_XFOR); + lex_match(ls, TK_end, TK_for, line); + fscope_end(fs); /* Resolve break list. */ +} + +/* Parse condition and 'then' block. */ +static BCPos parse_then(LexState *ls) +{ + BCPos condexit; + lj_lex_next(ls); /* Skip 'if' or 'elseif'. */ + condexit = expr_cond(ls); + lex_check(ls, TK_then); + parse_block(ls); + return condexit; +} + +/* Parse 'if' statement. */ +static void parse_if(LexState *ls, BCLine line) +{ + FuncState *fs = ls->fs; + BCPos flist; + BCPos escapelist = NO_JMP; + flist = parse_then(ls); + while (ls->token == TK_elseif) { /* Parse multiple 'elseif' blocks. */ + jmp_append(fs, &escapelist, bcemit_jmp(fs)); + jmp_tohere(fs, flist); + flist = parse_then(ls); + } + if (ls->token == TK_else) { /* Parse optional 'else' block. */ + jmp_append(fs, &escapelist, bcemit_jmp(fs)); + jmp_tohere(fs, flist); + lj_lex_next(ls); /* Skip 'else'. */ + parse_block(ls); + } else { + jmp_append(fs, &escapelist, flist); + } + jmp_tohere(fs, escapelist); + lex_match(ls, TK_end, TK_if, line); +} + +/* -- Parse statements ---------------------------------------------------- */ + +/* Parse a statement. Returns 1 if it must be the last one in a chunk. */ +static int parse_stmt(LexState *ls) +{ + BCLine line = ls->linenumber; + switch (ls->token) { + case TK_if: + parse_if(ls, line); + break; + case TK_while: + parse_while(ls, line); + break; + case TK_do: + lj_lex_next(ls); + parse_block(ls); + lex_match(ls, TK_end, TK_do, line); + break; + case TK_for: + parse_for(ls, line); + break; + case TK_repeat: + parse_repeat(ls, line); + break; + case TK_function: + parse_func(ls, line); + break; + case TK_local: + lj_lex_next(ls); + parse_local(ls); + break; + case TK_return: + parse_return(ls); + return 1; /* Must be last. */ + case TK_break: + lj_lex_next(ls); + parse_break(ls); + return !LJ_52; /* Must be last in Lua 5.1. */ +#if LJ_52 + case ';': + lj_lex_next(ls); + break; +#endif + case TK_label: + parse_label(ls); + break; + case TK_goto: + if (LJ_52 || lj_lex_lookahead(ls) == TK_name) { + lj_lex_next(ls); + parse_goto(ls); + break; + } /* else: fallthrough */ + default: + parse_call_assign(ls); + break; + } + return 0; +} + +/* A chunk is a list of statements optionally separated by semicolons. */ +static void parse_chunk(LexState *ls) +{ + int islast = 0; + synlevel_begin(ls); + while (!islast && !endofblock(ls->token)) { + islast = parse_stmt(ls); + lex_opt(ls, ';'); + lua_assert(ls->fs->framesize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* Free registers after each stmt. */ + } + synlevel_end(ls); +} + +/* Entry point of bytecode parser. */ +GCproto *lj_parse(LexState *ls) +{ + FuncState fs; + FuncScope bl; + GCproto *pt; + lua_State *L = ls->L; +#ifdef LUAJIT_DISABLE_DEBUGINFO + ls->chunkname = lj_str_newlit(L, "="); +#else + ls->chunkname = lj_str_newz(L, ls->chunkarg); +#endif + setstrV(L, L->top, ls->chunkname); /* Anchor chunkname string. */ + incr_top(L); + ls->level = 0; + fs_init(ls, &fs); + fs.linedefined = 0; + fs.numparams = 0; + fs.bcbase = NULL; + fs.bclim = 0; + fs.flags |= PROTO_VARARG; /* Main chunk is always a vararg func. */ + fscope_begin(&fs, &bl, 0); + bcemit_AD(&fs, BC_FUNCV, 0, 0); /* Placeholder. */ + lj_lex_next(ls); /* Read-ahead first token. */ + parse_chunk(ls); + if (ls->token != TK_eof) + err_token(ls, TK_eof); + pt = fs_finish(ls, ls->linenumber); + L->top--; /* Drop chunkname. */ + lua_assert(fs.prev == NULL); + lua_assert(ls->fs == NULL); + lua_assert(pt->sizeuv == 0); + return pt; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.h new file mode 100644 index 0000000..532657a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_parse.h @@ -0,0 +1,18 @@ +/* +** Lua parser (source code -> bytecode). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_PARSE_H +#define _LJ_PARSE_H + +#include "lj_obj.h" +#include "lj_lex.h" + +LJ_FUNC GCproto *lj_parse(LexState *ls); +LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l); +#if LJ_HASFFI +LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.c new file mode 100644 index 0000000..c6848fc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.c @@ -0,0 +1,2248 @@ +/* +** Trace recorder (bytecode -> SSA IR). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_record_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_meta.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_bc.h" +#include "lj_ff.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_ircall.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_record.h" +#include "lj_ffrecord.h" +#include "lj_snap.h" +#include "lj_dispatch.h" +#include "lj_vm.h" + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Sanity checks ------------------------------------------------------- */ + +#ifdef LUA_USE_ASSERT +/* Sanity check the whole IR -- sloooow. */ +static void rec_check_ir(jit_State *J) +{ + IRRef i, nins = J->cur.nins, nk = J->cur.nk; + lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536); + for (i = nins-1; i >= nk; i--) { + IRIns *ir = IR(i); + uint32_t mode = lj_ir_mode[ir->o]; + IRRef op1 = ir->op1; + IRRef op2 = ir->op2; + switch (irm_op1(mode)) { + case IRMnone: lua_assert(op1 == 0); break; + case IRMref: lua_assert(op1 >= nk); + lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break; + case IRMlit: break; + case IRMcst: lua_assert(i < REF_BIAS); continue; + } + switch (irm_op2(mode)) { + case IRMnone: lua_assert(op2 == 0); break; + case IRMref: lua_assert(op2 >= nk); + lua_assert(i >= REF_BIAS ? op2 < i : op2 > i); break; + case IRMlit: break; + case IRMcst: lua_assert(0); break; + } + if (ir->prev) { + lua_assert(ir->prev >= nk); + lua_assert(i >= REF_BIAS ? ir->prev < i : ir->prev > i); + lua_assert(ir->o == IR_NOP || IR(ir->prev)->o == ir->o); + } + } +} + +/* Compare stack slots and frames of the recorder and the VM. */ +static void rec_check_slots(jit_State *J) +{ + BCReg s, nslots = J->baseslot + J->maxslot; + int32_t depth = 0; + cTValue *base = J->L->base - J->baseslot; + lua_assert(J->baseslot >= 1 && J->baseslot < LJ_MAX_JSLOTS); + lua_assert(J->baseslot == 1 || (J->slot[J->baseslot-1] & TREF_FRAME)); + lua_assert(nslots < LJ_MAX_JSLOTS); + for (s = 0; s < nslots; s++) { + TRef tr = J->slot[s]; + if (tr) { + cTValue *tv = &base[s]; + IRRef ref = tref_ref(tr); + IRIns *ir; + lua_assert(ref >= J->cur.nk && ref < J->cur.nins); + ir = IR(ref); + lua_assert(irt_t(ir->t) == tref_t(tr)); + if (s == 0) { + lua_assert(tref_isfunc(tr)); + } else if ((tr & TREF_FRAME)) { + GCfunc *fn = gco2func(frame_gc(tv)); + BCReg delta = (BCReg)(tv - frame_prev(tv)); + lua_assert(tref_isfunc(tr)); + if (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir)); + lua_assert(s > delta ? (J->slot[s-delta] & TREF_FRAME) : (s == delta)); + depth++; + } else if ((tr & TREF_CONT)) { + lua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void)); + lua_assert((J->slot[s+1] & TREF_FRAME)); + depth++; + } else { + if (tvisnumber(tv)) + lua_assert(tref_isnumber(tr)); /* Could be IRT_INT etc., too. */ + else + lua_assert(itype2irt(tv) == tref_type(tr)); + if (tref_isk(tr)) { /* Compare constants. */ + TValue tvk; + lj_ir_kvalue(J->L, &tvk, ir); + if (!(tvisnum(&tvk) && tvisnan(&tvk))) + lua_assert(lj_obj_equal(tv, &tvk)); + else + lua_assert(tvisnum(tv) && tvisnan(tv)); + } + } + } + } + lua_assert(J->framedepth == depth); +} +#endif + +/* -- Type handling and specialization ------------------------------------ */ + +/* Note: these functions return tagged references (TRef). */ + +/* Specialize a slot to a specific type. Note: slot can be negative! */ +static TRef sloadt(jit_State *J, int32_t slot, IRType t, int mode) +{ + /* Caller may set IRT_GUARD in t. */ + TRef ref = emitir_raw(IRT(IR_SLOAD, t), (int32_t)J->baseslot+slot, mode); + J->base[slot] = ref; + return ref; +} + +/* Specialize a slot to the runtime type. Note: slot can be negative! */ +static TRef sload(jit_State *J, int32_t slot) +{ + IRType t = itype2irt(&J->L->base[slot]); + TRef ref = emitir_raw(IRTG(IR_SLOAD, t), (int32_t)J->baseslot+slot, + IRSLOAD_TYPECHECK); + if (irtype_ispri(t)) ref = TREF_PRI(t); /* Canonicalize primitive refs. */ + J->base[slot] = ref; + return ref; +} + +/* Get TRef from slot. Load slot and specialize if not done already. */ +#define getslot(J, s) (J->base[(s)] ? J->base[(s)] : sload(J, (int32_t)(s))) + +/* Get TRef for current function. */ +static TRef getcurrf(jit_State *J) +{ + if (J->base[-1]) + return J->base[-1]; + lua_assert(J->baseslot == 1); + return sloadt(J, -1, IRT_FUNC, IRSLOAD_READONLY); +} + +/* Compare for raw object equality. +** Returns 0 if the objects are the same. +** Returns 1 if they are different, but the same type. +** Returns 2 for two different types. +** Comparisons between primitives always return 1 -- no caller cares about it. +*/ +int lj_record_objcmp(jit_State *J, TRef a, TRef b, cTValue *av, cTValue *bv) +{ + int diff = !lj_obj_equal(av, bv); + if (!tref_isk2(a, b)) { /* Shortcut, also handles primitives. */ + IRType ta = tref_isinteger(a) ? IRT_INT : tref_type(a); + IRType tb = tref_isinteger(b) ? IRT_INT : tref_type(b); + if (ta != tb) { + /* Widen mixed number/int comparisons to number/number comparison. */ + if (ta == IRT_INT && tb == IRT_NUM) { + a = emitir(IRTN(IR_CONV), a, IRCONV_NUM_INT); + ta = IRT_NUM; + } else if (ta == IRT_NUM && tb == IRT_INT) { + b = emitir(IRTN(IR_CONV), b, IRCONV_NUM_INT); + } else { + return 2; /* Two different types are never equal. */ + } + } + emitir(IRTG(diff ? IR_NE : IR_EQ, ta), a, b); + } + return diff; +} + +/* Constify a value. Returns 0 for non-representable object types. */ +TRef lj_record_constify(jit_State *J, cTValue *o) +{ + if (tvisgcv(o)) + return lj_ir_kgc(J, gcV(o), itype2irt(o)); + else if (tvisint(o)) + return lj_ir_kint(J, intV(o)); + else if (tvisnum(o)) + return lj_ir_knumint(J, numV(o)); + else if (tvisbool(o)) + return TREF_PRI(itype2irt(o)); + else + return 0; /* Can't represent lightuserdata (pointless). */ +} + +/* -- Record loop ops ----------------------------------------------------- */ + +/* Loop event. */ +typedef enum { + LOOPEV_LEAVE, /* Loop is left or not entered. */ + LOOPEV_ENTERLO, /* Loop is entered with a low iteration count left. */ + LOOPEV_ENTER /* Loop is entered. */ +} LoopEvent; + +/* Canonicalize slots: convert integers to numbers. */ +static void canonicalize_slots(jit_State *J) +{ + BCReg s; + if (LJ_DUALNUM) return; + for (s = J->baseslot+J->maxslot-1; s >= 1; s--) { + TRef tr = J->slot[s]; + if (tref_isinteger(tr)) { + IRIns *ir = IR(tref_ref(tr)); + if (!(ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_READONLY))) + J->slot[s] = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + } + } +} + +/* Stop recording. */ +static void rec_stop(jit_State *J, TraceLink linktype, TraceNo lnk) +{ + lj_trace_end(J); + J->cur.linktype = (uint8_t)linktype; + J->cur.link = (uint16_t)lnk; + /* Looping back at the same stack level? */ + if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) { + if ((J->flags & JIT_F_OPT_LOOP)) /* Shall we try to create a loop? */ + goto nocanon; /* Do not canonicalize or we lose the narrowing. */ + if (J->cur.root) /* Otherwise ensure we always link to the root trace. */ + J->cur.link = J->cur.root; + } + canonicalize_slots(J); +nocanon: + /* Note: all loop ops must set J->pc to the following instruction! */ + lj_snap_add(J); /* Add loop snapshot. */ + J->needsnap = 0; + J->mergesnap = 1; /* In case recording continues. */ +} + +/* Search bytecode backwards for a int/num constant slot initializer. */ +static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t) +{ + /* This algorithm is rather simplistic and assumes quite a bit about + ** how the bytecode is generated. It works fine for FORI initializers, + ** but it won't necessarily work in other cases (e.g. iterator arguments). + ** It doesn't do anything fancy, either (like backpropagating MOVs). + */ + const BCIns *pc, *startpc = proto_bc(J->pt); + for (pc = endpc-1; pc > startpc; pc--) { + BCIns ins = *pc; + BCOp op = bc_op(ins); + /* First try to find the last instruction that stores to this slot. */ + if (bcmode_a(op) == BCMbase && bc_a(ins) <= slot) { + return 0; /* Multiple results, e.g. from a CALL or KNIL. */ + } else if (bcmode_a(op) == BCMdst && bc_a(ins) == slot) { + if (op == BC_KSHORT || op == BC_KNUM) { /* Found const. initializer. */ + /* Now try to verify there's no forward jump across it. */ + const BCIns *kpc = pc; + for (; pc > startpc; pc--) + if (bc_op(*pc) == BC_JMP) { + const BCIns *target = pc+bc_j(*pc)+1; + if (target > kpc && target <= endpc) + return 0; /* Conditional assignment. */ + } + if (op == BC_KSHORT) { + int32_t k = (int32_t)(int16_t)bc_d(ins); + return t == IRT_INT ? lj_ir_kint(J, k) : lj_ir_knum(J, (lua_Number)k); + } else { + cTValue *tv = proto_knumtv(J->pt, bc_d(ins)); + if (t == IRT_INT) { + int32_t k = numberVint(tv); + if (tvisint(tv) || numV(tv) == (lua_Number)k) /* -0 is ok here. */ + return lj_ir_kint(J, k); + return 0; /* Type mismatch. */ + } else { + return lj_ir_knum(J, numberVnum(tv)); + } + } + } + return 0; /* Non-constant initializer. */ + } + } + return 0; /* No assignment to this slot found? */ +} + +/* Load and optionally convert a FORI argument from a slot. */ +static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode) +{ + int conv = (tvisint(&J->L->base[slot]) != (t==IRT_INT)) ? IRSLOAD_CONVERT : 0; + return sloadt(J, (int32_t)slot, + t + (((mode & IRSLOAD_TYPECHECK) || + (conv && t == IRT_INT && !(mode >> 16))) ? + IRT_GUARD : 0), + mode + conv); +} + +/* Peek before FORI to find a const initializer. Otherwise load from slot. */ +static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, + IRType t, int mode) +{ + TRef tr = J->base[slot]; + if (!tr) { + tr = find_kinit(J, fori, slot, t); + if (!tr) + tr = fori_load(J, slot, t, mode); + } + return tr; +} + +/* Return the direction of the FOR loop iterator. +** It's important to exactly reproduce the semantics of the interpreter. +*/ +static int rec_for_direction(cTValue *o) +{ + return (tvisint(o) ? intV(o) : (int32_t)o->u32.hi) >= 0; +} + +/* Simulate the runtime behavior of the FOR loop iterator. */ +static LoopEvent rec_for_iter(IROp *op, cTValue *o, int isforl) +{ + lua_Number stopv = numberVnum(&o[FORL_STOP]); + lua_Number idxv = numberVnum(&o[FORL_IDX]); + lua_Number stepv = numberVnum(&o[FORL_STEP]); + if (isforl) + idxv += stepv; + if (rec_for_direction(&o[FORL_STEP])) { + if (idxv <= stopv) { + *op = IR_LE; + return idxv + 2*stepv > stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER; + } + *op = IR_GT; return LOOPEV_LEAVE; + } else { + if (stopv <= idxv) { + *op = IR_GE; + return idxv + 2*stepv < stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER; + } + *op = IR_LT; return LOOPEV_LEAVE; + } +} + +/* Record checks for FOR loop overflow and step direction. */ +static void rec_for_check(jit_State *J, IRType t, int dir, + TRef stop, TRef step, int init) +{ + if (!tref_isk(step)) { + /* Non-constant step: need a guard for the direction. */ + TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); + emitir(IRTG(dir ? IR_GE : IR_LT, t), step, zero); + /* Add hoistable overflow checks for a narrowed FORL index. */ + if (init && t == IRT_INT) { + if (tref_isk(stop)) { + /* Constant stop: optimize check away or to a range check for step. */ + int32_t k = IR(tref_ref(stop))->i; + if (dir) { + if (k > 0) + emitir(IRTGI(IR_LE), step, lj_ir_kint(J, (int32_t)0x7fffffff-k)); + } else { + if (k < 0) + emitir(IRTGI(IR_GE), step, lj_ir_kint(J, (int32_t)0x80000000-k)); + } + } else { + /* Stop+step variable: need full overflow check. */ + TRef tr = emitir(IRTGI(IR_ADDOV), step, stop); + emitir(IRTI(IR_USE), tr, 0); /* ADDOV is weak. Avoid dead result. */ + } + } + } else if (init && t == IRT_INT && !tref_isk(stop)) { + /* Constant step: optimize overflow check to a range check for stop. */ + int32_t k = IR(tref_ref(step))->i; + k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; + emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); + } +} + +/* Record a FORL instruction. */ +static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev, + int init) +{ + BCReg ra = bc_a(*fori); + cTValue *tv = &J->L->base[ra]; + TRef idx = J->base[ra+FORL_IDX]; + IRType t = idx ? tref_type(idx) : + (init || LJ_DUALNUM) ? lj_opt_narrow_forl(J, tv) : IRT_NUM; + int mode = IRSLOAD_INHERIT + + ((!LJ_DUALNUM || tvisint(tv) == (t == IRT_INT)) ? IRSLOAD_READONLY : 0); + TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode); + TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode); + int tc, dir = rec_for_direction(&tv[FORL_STEP]); + lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); + scev->t.irt = t; + scev->dir = dir; + scev->stop = tref_ref(stop); + scev->step = tref_ref(step); + rec_for_check(J, t, dir, stop, step, init); + scev->start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT)); + tc = (LJ_DUALNUM && + !(scev->start && irref_isk(scev->stop) && irref_isk(scev->step) && + tvisint(&tv[FORL_IDX]) == (t == IRT_INT))) ? + IRSLOAD_TYPECHECK : 0; + if (tc) { + J->base[ra+FORL_STOP] = stop; + J->base[ra+FORL_STEP] = step; + } + if (!idx) + idx = fori_load(J, ra+FORL_IDX, t, + IRSLOAD_INHERIT + tc + (J->scev.start << 16)); + if (!init) + J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); + J->base[ra+FORL_EXT] = idx; + scev->idx = tref_ref(idx); + J->maxslot = ra+FORL_EXT+1; +} + +/* Record FORL/JFORL or FORI/JFORI. */ +static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) +{ + BCReg ra = bc_a(*fori); + TValue *tv = &J->L->base[ra]; + TRef *tr = &J->base[ra]; + IROp op; + LoopEvent ev; + TRef stop; + IRType t; + if (isforl) { /* Handle FORL/JFORL opcodes. */ + TRef idx = tr[FORL_IDX]; + if (tref_ref(idx) == J->scev.idx) { + t = J->scev.t.irt; + stop = J->scev.stop; + idx = emitir(IRT(IR_ADD, t), idx, J->scev.step); + tr[FORL_EXT] = tr[FORL_IDX] = idx; + } else { + ScEvEntry scev; + rec_for_loop(J, fori, &scev, 0); + t = scev.t.irt; + stop = scev.stop; + } + } else { /* Handle FORI/JFORI opcodes. */ + BCReg i; + lj_meta_for(J->L, tv); + t = (LJ_DUALNUM || tref_isint(tr[FORL_IDX])) ? lj_opt_narrow_forl(J, tv) : + IRT_NUM; + for (i = FORL_IDX; i <= FORL_STEP; i++) { + if (!tr[i]) sload(J, ra+i); + lua_assert(tref_isnumber_str(tr[i])); + if (tref_isstr(tr[i])) + tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); + if (t == IRT_INT) { + if (!tref_isinteger(tr[i])) + tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK); + } else { + if (!tref_isnum(tr[i])) + tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT); + } + } + tr[FORL_EXT] = tr[FORL_IDX]; + stop = tr[FORL_STOP]; + rec_for_check(J, t, rec_for_direction(&tv[FORL_STEP]), + stop, tr[FORL_STEP], 1); + } + + ev = rec_for_iter(&op, tv, isforl); + if (ev == LOOPEV_LEAVE) { + J->maxslot = ra+FORL_EXT+1; + J->pc = fori+1; + } else { + J->maxslot = ra; + J->pc = fori+bc_j(*fori)+1; + } + lj_snap_add(J); + + emitir(IRTG(op, t), tr[FORL_IDX], stop); + + if (ev == LOOPEV_LEAVE) { + J->maxslot = ra; + J->pc = fori+bc_j(*fori)+1; + } else { + J->maxslot = ra+FORL_EXT+1; + J->pc = fori+1; + } + J->needsnap = 1; + return ev; +} + +/* Record ITERL/JITERL. */ +static LoopEvent rec_iterl(jit_State *J, const BCIns iterins) +{ + BCReg ra = bc_a(iterins); + lua_assert(J->base[ra] != 0); + if (!tref_isnil(J->base[ra])) { /* Looping back? */ + J->base[ra-1] = J->base[ra]; /* Copy result of ITERC to control var. */ + J->maxslot = ra-1+bc_b(J->pc[-1]); + J->pc += bc_j(iterins)+1; + return LOOPEV_ENTER; + } else { + J->maxslot = ra-3; + J->pc++; + return LOOPEV_LEAVE; + } +} + +/* Record LOOP/JLOOP. Now, that was easy. */ +static LoopEvent rec_loop(jit_State *J, BCReg ra) +{ + if (ra < J->maxslot) J->maxslot = ra; + J->pc++; + return LOOPEV_ENTER; +} + +/* Check if a loop repeatedly failed to trace because it didn't loop back. */ +static int innerloopleft(jit_State *J, const BCIns *pc) +{ + ptrdiff_t i; + for (i = 0; i < PENALTY_SLOTS; i++) + if (mref(J->penalty[i].pc, const BCIns) == pc) { + if ((J->penalty[i].reason == LJ_TRERR_LLEAVE || + J->penalty[i].reason == LJ_TRERR_LINNER) && + J->penalty[i].val >= 2*PENALTY_MIN) + return 1; + break; + } + return 0; +} + +/* Handle the case when an interpreted loop op is hit. */ +static void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev) +{ + if (J->parent == 0) { + if (pc == J->startpc && J->framedepth + J->retdepth == 0) { + /* Same loop? */ + if (ev == LOOPEV_LEAVE) /* Must loop back to form a root trace. */ + lj_trace_err(J, LJ_TRERR_LLEAVE); + rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Looping root trace. */ + } else if (ev != LOOPEV_LEAVE) { /* Entering inner loop? */ + /* It's usually better to abort here and wait until the inner loop + ** is traced. But if the inner loop repeatedly didn't loop back, + ** this indicates a low trip count. In this case try unrolling + ** an inner loop even in a root trace. But it's better to be a bit + ** more conservative here and only do it for very short loops. + */ + if (bc_j(*pc) != -1 && !innerloopleft(J, pc)) + lj_trace_err(J, LJ_TRERR_LINNER); /* Root trace hit an inner loop. */ + if ((ev != LOOPEV_ENTERLO && + J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0) + lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */ + J->loopref = J->cur.nins; + } + } else if (ev != LOOPEV_LEAVE) { /* Side trace enters an inner loop. */ + J->loopref = J->cur.nins; + if (--J->loopunroll < 0) + lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */ + } /* Side trace continues across a loop that's left or not entered. */ +} + +/* Handle the case when an already compiled loop op is hit. */ +static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev) +{ + if (J->parent == 0) { /* Root trace hit an inner loop. */ + /* Better let the inner loop spawn a side trace back here. */ + lj_trace_err(J, LJ_TRERR_LINNER); + } else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */ + J->instunroll = 0; /* Cannot continue across a compiled loop op. */ + if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Form an extra loop. */ + else + rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the loop. */ + } /* Side trace continues across a loop that's left or not entered. */ +} + +/* -- Record calls and returns -------------------------------------------- */ + +/* Specialize to the runtime value of the called function or its prototype. */ +static TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr) +{ + TRef kfunc; + if (isluafunc(fn)) { + GCproto *pt = funcproto(fn); + /* Too many closures created? Probably not a monomorphic function. */ + if (pt->flags >= PROTO_CLC_POLY) { /* Specialize to prototype instead. */ + TRef trpt = emitir(IRT(IR_FLOAD, IRT_P32), tr, IRFL_FUNC_PC); + emitir(IRTG(IR_EQ, IRT_P32), trpt, lj_ir_kptr(J, proto_bc(pt))); + (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); /* Prevent GC of proto. */ + return tr; + } + } + /* Otherwise specialize to the function (closure) value itself. */ + kfunc = lj_ir_kfunc(J, fn); + emitir(IRTG(IR_EQ, IRT_FUNC), tr, kfunc); + return kfunc; +} + +/* Record call setup. */ +static void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + RecordIndex ix; + TValue *functv = &J->L->base[func]; + TRef *fbase = &J->base[func]; + ptrdiff_t i; + for (i = 0; i <= nargs; i++) + (void)getslot(J, func+i); /* Ensure func and all args have a reference. */ + if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */ + ix.tab = fbase[0]; + copyTV(J->L, &ix.tabv, functv); + if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj)) + lj_trace_err(J, LJ_TRERR_NOMM); + for (i = ++nargs; i > 0; i--) /* Shift arguments up. */ + fbase[i] = fbase[i-1]; + fbase[0] = ix.mobj; /* Replace function. */ + functv = &ix.mobjv; + } + fbase[0] = TREF_FRAME | rec_call_specialize(J, funcV(functv), fbase[0]); + J->maxslot = (BCReg)nargs; +} + +/* Record call. */ +void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + rec_call_setup(J, func, nargs); + /* Bump frame. */ + J->framedepth++; + J->base += func+1; + J->baseslot += func+1; +} + +/* Record tail call. */ +void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs) +{ + rec_call_setup(J, func, nargs); + if (frame_isvarg(J->L->base - 1)) { + BCReg cbase = (BCReg)frame_delta(J->L->base - 1); + if (--J->framedepth < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + func += cbase; + } + /* Move func + args down. */ + memmove(&J->base[-1], &J->base[func], sizeof(TRef)*(J->maxslot+1)); + /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */ + /* Tailcalls can form a loop, so count towards the loop unroll limit. */ + if (++J->tailcalled > J->loopunroll) + lj_trace_err(J, LJ_TRERR_LUNROLL); +} + +/* Check unroll limits for down-recursion. */ +static int check_downrec_unroll(jit_State *J, GCproto *pt) +{ + IRRef ptref; + for (ptref = J->chain[IR_KGC]; ptref; ptref = IR(ptref)->prev) + if (ir_kgc(IR(ptref)) == obj2gco(pt)) { + int count = 0; + IRRef ref; + for (ref = J->chain[IR_RETF]; ref; ref = IR(ref)->prev) + if (IR(ref)->op1 == ptref) + count++; + if (count) { + if (J->pc == J->startpc) { + if (count + J->tailcalled > J->param[JIT_P_recunroll]) + return 1; + } else { + lj_trace_err(J, LJ_TRERR_DOWNREC); + } + } + } + return 0; +} + +/* Record return. */ +void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) +{ + TValue *frame = J->L->base - 1; + ptrdiff_t i; + for (i = 0; i < gotresults; i++) + (void)getslot(J, rbase+i); /* Ensure all results have a reference. */ + while (frame_ispcall(frame)) { /* Immediately resolve pcall() returns. */ + BCReg cbase = (BCReg)frame_delta(frame); + if (--J->framedepth < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + lua_assert(J->baseslot > 1); + gotresults++; + rbase += cbase; + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + J->base[--rbase] = TREF_TRUE; /* Prepend true to results. */ + frame = frame_prevd(frame); + } + /* Return to lower frame via interpreter for unhandled cases. */ + if (J->framedepth == 0 && J->pt && bc_isret(bc_op(*J->pc)) && + (!frame_islua(frame) || + (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))))) { + /* NYI: specialize to frame type and return directly, not via RET*. */ + for (i = 0; i < (ptrdiff_t)rbase; i++) + J->base[i] = 0; /* Purge dead slots. */ + J->maxslot = rbase + (BCReg)gotresults; + rec_stop(J, LJ_TRLINK_RETURN, 0); /* Return to interpreter. */ + return; + } + if (frame_isvarg(frame)) { + BCReg cbase = (BCReg)frame_delta(frame); + if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */ + lj_trace_err(J, LJ_TRERR_NYIRETL); + lua_assert(J->baseslot > 1); + rbase += cbase; + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + frame = frame_prevd(frame); + } + if (frame_islua(frame)) { /* Return to Lua frame. */ + BCIns callins = *(frame_pc(frame)-1); + ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults; + BCReg cbase = bc_a(callins); + GCproto *pt = funcproto(frame_func(frame - (cbase+1))); + if ((pt->flags & PROTO_NOJIT)) + lj_trace_err(J, LJ_TRERR_CJITOFF); + if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) { + if (check_downrec_unroll(J, pt)) { + J->maxslot = (BCReg)(rbase + gotresults); + lj_snap_purge(J); + rec_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno); /* Down-recursion. */ + return; + } + lj_snap_add(J); + } + for (i = 0; i < nresults; i++) /* Adjust results. */ + J->base[i-1] = i < gotresults ? J->base[rbase+i] : TREF_NIL; + J->maxslot = cbase+(BCReg)nresults; + if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */ + J->framedepth--; + lua_assert(J->baseslot > cbase+1); + J->baseslot -= cbase+1; + J->base -= cbase+1; + } else if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) { + /* Return to lower frame would leave the loop in a root trace. */ + lj_trace_err(J, LJ_TRERR_LLEAVE); + } else { /* Return to lower frame. Guard for the target we return to. */ + TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); + TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame)); + emitir(IRTG(IR_RETF, IRT_P32), trpt, trpc); + J->retdepth++; + J->needsnap = 1; + lua_assert(J->baseslot == 1); + /* Shift result slots up and clear the slots of the new frame below. */ + memmove(J->base + cbase, J->base-1, sizeof(TRef)*nresults); + memset(J->base-1, 0, sizeof(TRef)*(cbase+1)); + } + } else if (frame_iscont(frame)) { /* Return to continuation frame. */ + ASMFunction cont = frame_contf(frame); + BCReg cbase = (BCReg)frame_delta(frame); + if ((J->framedepth -= 2) < 0) + lj_trace_err(J, LJ_TRERR_NYIRETL); + J->baseslot -= (BCReg)cbase; + J->base -= cbase; + J->maxslot = cbase-2; + if (cont == lj_cont_ra) { + /* Copy result to destination slot. */ + BCReg dst = bc_a(*(frame_contpc(frame)-1)); + J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL; + if (dst >= J->maxslot) J->maxslot = dst+1; + } else if (cont == lj_cont_nop) { + /* Nothing to do here. */ + } else if (cont == lj_cont_cat) { + lua_assert(0); + } else { + /* Result type already specialized. */ + lua_assert(cont == lj_cont_condf || cont == lj_cont_condt); + } + } else { + lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */ + } + lua_assert(J->baseslot >= 1); +} + +/* -- Metamethod handling ------------------------------------------------- */ + +/* Prepare to record call to metamethod. */ +static BCReg rec_mm_prep(jit_State *J, ASMFunction cont) +{ + BCReg s, top = curr_proto(J->L)->framesize; + TRef trcont; + setcont(&J->L->base[top], cont); +#if LJ_64 + trcont = lj_ir_kptr(J, (void *)((int64_t)cont - (int64_t)lj_vm_asm_begin)); +#else + trcont = lj_ir_kptr(J, (void *)cont); +#endif + J->base[top] = trcont | TREF_CONT; + J->framedepth++; + for (s = J->maxslot; s < top; s++) + J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */ + return top+1; +} + +/* Record metamethod lookup. */ +int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) +{ + RecordIndex mix; + GCtab *mt; + if (tref_istab(ix->tab)) { + mt = tabref(tabV(&ix->tabv)->metatable); + mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META); + } else if (tref_isudata(ix->tab)) { + int udtype = udataV(&ix->tabv)->udtype; + mt = tabref(udataV(&ix->tabv)->metatable); + /* The metatables of special userdata objects are treated as immutable. */ + if (udtype != UDTYPE_USERDATA) { + cTValue *mo; + if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) { + /* Specialize to the C library namespace object. */ + emitir(IRTG(IR_EQ, IRT_P32), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv))); + } else { + /* Specialize to the type of userdata. */ + TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, udtype)); + } + immutable_mt: + mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm)); + if (!mo || tvisnil(mo)) + return 0; /* No metamethod. */ + /* Treat metamethod or index table as immutable, too. */ + if (!(tvisfunc(mo) || tvistab(mo))) + lj_trace_err(J, LJ_TRERR_BADTYPE); + copyTV(J->L, &ix->mobjv, mo); + ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB); + ix->mtv = mt; + ix->mt = TREF_NIL; /* Dummy value for comparison semantics. */ + return 1; /* Got metamethod or index table. */ + } + mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META); + } else { + /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */ + mt = tabref(basemt_obj(J2G(J), &ix->tabv)); + if (mt == NULL) { + ix->mt = TREF_NIL; + return 0; /* No metamethod. */ + } + /* The cdata metatable is treated as immutable. */ + if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt; + ix->mt = mix.tab = lj_ir_ktab(J, mt); + goto nocheck; + } + ix->mt = mt ? mix.tab : TREF_NIL; + emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mix.tab, lj_ir_knull(J, IRT_TAB)); +nocheck: + if (mt) { + GCstr *mmstr = mmname_str(J2G(J), mm); + cTValue *mo = lj_tab_getstr(mt, mmstr); + if (mo && !tvisnil(mo)) + copyTV(J->L, &ix->mobjv, mo); + ix->mtv = mt; + settabV(J->L, &mix.tabv, mt); + setstrV(J->L, &mix.keyv, mmstr); + mix.key = lj_ir_kstr(J, mmstr); + mix.val = 0; + mix.idxchain = 0; + ix->mobj = lj_record_idx(J, &mix); + return !tref_isnil(ix->mobj); /* 1 if metamethod found, 0 if not. */ + } + return 0; /* No metamethod. */ +} + +/* Record call to arithmetic metamethod. */ +static TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm) +{ + /* Set up metamethod call first to save ix->tab and ix->tabv. */ + BCReg func = rec_mm_prep(J, lj_cont_ra); + TRef *base = J->base + func; + TValue *basev = J->L->base + func; + base[1] = ix->tab; base[2] = ix->key; + copyTV(J->L, basev+1, &ix->tabv); + copyTV(J->L, basev+2, &ix->keyv); + if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + if (mm != MM_unm) { + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + if (lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */ + goto ok; + } + lj_trace_err(J, LJ_TRERR_NOMM); + } +ok: + base[0] = ix->mobj; + copyTV(J->L, basev+0, &ix->mobjv); + lj_record_call(J, func, 2); + return 0; /* No result yet. */ +} + +/* Record call to __len metamethod. */ +static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv) +{ + RecordIndex ix; + ix.tab = tr; + copyTV(J->L, &ix.tabv, tv); + if (lj_record_mm_lookup(J, &ix, MM_len)) { + BCReg func = rec_mm_prep(J, lj_cont_ra); + TRef *base = J->base + func; + TValue *basev = J->L->base + func; + base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv); + base[1] = tr; copyTV(J->L, basev+1, tv); +#if LJ_52 + base[2] = tr; copyTV(J->L, basev+2, tv); +#else + base[2] = TREF_NIL; setnilV(basev+2); +#endif + lj_record_call(J, func, 2); + } else { + if (LJ_52 && tref_istab(tr)) + return lj_ir_call(J, IRCALL_lj_tab_len, tr); + lj_trace_err(J, LJ_TRERR_NOMM); + } + return 0; /* No result yet. */ +} + +/* Call a comparison metamethod. */ +static void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op) +{ + BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt); + TRef *base = J->base + func; + TValue *tv = J->L->base + func; + base[0] = ix->mobj; base[1] = ix->val; base[2] = ix->key; + copyTV(J->L, tv+0, &ix->mobjv); + copyTV(J->L, tv+1, &ix->valv); + copyTV(J->L, tv+2, &ix->keyv); + lj_record_call(J, func, 2); +} + +/* Record call to equality comparison metamethod (for tab and udata only). */ +static void rec_mm_equal(jit_State *J, RecordIndex *ix, int op) +{ + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + if (lj_record_mm_lookup(J, ix, MM_eq)) { /* Lookup mm on 1st operand. */ + cTValue *bv; + TRef mo1 = ix->mobj; + TValue mo1v; + copyTV(J->L, &mo1v, &ix->mobjv); + /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */ + bv = &ix->keyv; + if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else { /* Lookup metamethod on 2nd operand and compare both. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, bv); + if (!lj_record_mm_lookup(J, ix, MM_eq) || + lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv)) + return; + } + rec_mm_callcomp(J, ix, op); + } +} + +/* Record call to ordered comparison metamethods (for arbitrary objects). */ +static void rec_mm_comp(jit_State *J, RecordIndex *ix, int op) +{ + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + while (1) { + MMS mm = (op & 2) ? MM_le : MM_lt; /* Try __le + __lt or only __lt. */ +#if LJ_52 + if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + if (!lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */ + goto nomatch; + } + rec_mm_callcomp(J, ix, op); + return; +#else + if (lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */ + cTValue *bv; + TRef mo1 = ix->mobj; + TValue mo1v; + copyTV(J->L, &mo1v, &ix->mobjv); + /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */ + bv = &ix->keyv; + if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) { + TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META); + emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt); + } else { /* Lookup metamethod on 2nd operand and compare both. */ + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, bv); + if (!lj_record_mm_lookup(J, ix, mm) || + lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv)) + goto nomatch; + } + rec_mm_callcomp(J, ix, op); + return; + } +#endif + nomatch: + /* Lookup failed. Retry with __lt and swapped operands. */ + if (!(op & 2)) break; /* Already at __lt. Interpreter will throw. */ + ix->tab = ix->key; ix->key = ix->val; ix->val = ix->tab; + copyTV(J->L, &ix->tabv, &ix->keyv); + copyTV(J->L, &ix->keyv, &ix->valv); + copyTV(J->L, &ix->valv, &ix->tabv); + op ^= 3; + } +} + +#if LJ_HASFFI +/* Setup call to cdata comparison metamethod. */ +static void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm) +{ + lj_snap_add(J); + if (tref_iscdata(ix->val)) { + ix->tab = ix->val; + copyTV(J->L, &ix->tabv, &ix->valv); + } else { + lua_assert(tref_iscdata(ix->key)); + ix->tab = ix->key; + copyTV(J->L, &ix->tabv, &ix->keyv); + } + lj_record_mm_lookup(J, ix, mm); + rec_mm_callcomp(J, ix, op); +} +#endif + +/* -- Indexed access ------------------------------------------------------ */ + +/* Record bounds-check. */ +static void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize) +{ + /* Try to emit invariant bounds checks. */ + if ((J->flags & (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) == + (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) { + IRRef ref = tref_ref(ikey); + IRIns *ir = IR(ref); + int32_t ofs = 0; + IRRef ofsref = 0; + /* Handle constant offsets. */ + if (ir->o == IR_ADD && irref_isk(ir->op2)) { + ofsref = ir->op2; + ofs = IR(ofsref)->i; + ref = ir->op1; + ir = IR(ref); + } + /* Got scalar evolution analysis results for this reference? */ + if (ref == J->scev.idx) { + int32_t stop; + lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD); + stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]); + /* Runtime value for stop of loop is within bounds? */ + if ((int64_t)stop + ofs < (int64_t)asize) { + /* Emit invariant bounds check for stop. */ + emitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop : + emitir(IRTI(IR_ADD), J->scev.stop, ofsref)); + /* Emit invariant bounds check for start, if not const or negative. */ + if (!(J->scev.dir && J->scev.start && + (int64_t)IR(J->scev.start)->i + ofs >= 0)) + emitir(IRTG(IR_ABC, IRT_P32), asizeref, ikey); + return; + } + } + } + emitir(IRTGI(IR_ABC), asizeref, ikey); /* Emit regular bounds check. */ +} + +/* Record indexed key lookup. */ +static TRef rec_idx_key(jit_State *J, RecordIndex *ix) +{ + TRef key; + GCtab *t = tabV(&ix->tabv); + ix->oldv = lj_tab_get(J->L, t, &ix->keyv); /* Lookup previous value. */ + + /* Integer keys are looked up in the array part first. */ + key = ix->key; + if (tref_isnumber(key)) { + int32_t k = numberVint(&ix->keyv); + if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k) + k = LJ_MAX_ASIZE; + if ((MSize)k < LJ_MAX_ASIZE) { /* Potential array key? */ + TRef ikey = lj_opt_narrow_index(J, key); + TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); + if ((MSize)k < t->asize) { /* Currently an array key? */ + TRef arrayref; + rec_idx_abc(J, asizeref, ikey, t->asize); + arrayref = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_ARRAY); + return emitir(IRT(IR_AREF, IRT_P32), arrayref, ikey); + } else { /* Currently not in array (may be an array extension)? */ + emitir(IRTGI(IR_ULE), asizeref, ikey); /* Inv. bounds check. */ + if (k == 0 && tref_isk(key)) + key = lj_ir_knum_zero(J); /* Canonicalize 0 or +-0.0 to +0.0. */ + /* And continue with the hash lookup. */ + } + } else if (!tref_isk(key)) { + /* We can rule out const numbers which failed the integerness test + ** above. But all other numbers are potential array keys. + */ + if (t->asize == 0) { /* True sparse tables have an empty array part. */ + /* Guard that the array part stays empty. */ + TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); + emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0)); + } else { + lj_trace_err(J, LJ_TRERR_NYITMIX); + } + } + } + + /* Otherwise the key is located in the hash part. */ + if (t->hmask == 0) { /* Shortcut for empty hash part. */ + /* Guard that the hash part stays empty. */ + TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK); + emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0)); + return lj_ir_kkptr(J, niltvg(J2G(J))); + } + if (tref_isinteger(key)) /* Hash keys are based on numbers, not ints. */ + key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT); + if (tref_isk(key)) { + /* Optimize lookup of constant hash keys. */ + MSize hslot = (MSize)((char *)ix->oldv - (char *)&noderef(t->node)[0].val); + if (t->hmask > 0 && hslot <= t->hmask*(MSize)sizeof(Node) && + hslot <= 65535*(MSize)sizeof(Node)) { + TRef node, kslot; + TRef hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK); + emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask)); + node = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_NODE); + kslot = lj_ir_kslot(J, key, hslot / sizeof(Node)); + return emitir(IRTG(IR_HREFK, IRT_P32), node, kslot); + } + } + /* Fall back to a regular hash lookup. */ + return emitir(IRT(IR_HREF, IRT_P32), ix->tab, key); +} + +/* Determine whether a key is NOT one of the fast metamethod names. */ +static int nommstr(jit_State *J, TRef key) +{ + if (tref_isstr(key)) { + if (tref_isk(key)) { + GCstr *str = ir_kstr(IR(tref_ref(key))); + uint32_t mm; + for (mm = 0; mm <= MM_FAST; mm++) + if (mmname_str(J2G(J), mm) == str) + return 0; /* MUST be one the fast metamethod names. */ + } else { + return 0; /* Variable string key MAY be a metamethod name. */ + } + } + return 1; /* CANNOT be a metamethod name. */ +} + +/* Record indexed load/store. */ +TRef lj_record_idx(jit_State *J, RecordIndex *ix) +{ + TRef xref; + IROp xrefop, loadop; + cTValue *oldv; + + while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */ + /* Never call raw lj_record_idx() on non-table. */ + lua_assert(ix->idxchain != 0); + if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index)) + lj_trace_err(J, LJ_TRERR_NOMM); + handlemm: + if (tref_isfunc(ix->mobj)) { /* Handle metamethod call. */ + BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra); + TRef *base = J->base + func; + TValue *tv = J->L->base + func; + base[0] = ix->mobj; base[1] = ix->tab; base[2] = ix->key; + setfuncV(J->L, tv+0, funcV(&ix->mobjv)); + copyTV(J->L, tv+1, &ix->tabv); + copyTV(J->L, tv+2, &ix->keyv); + if (ix->val) { + base[3] = ix->val; + copyTV(J->L, tv+3, &ix->valv); + lj_record_call(J, func, 3); /* mobj(tab, key, val) */ + return 0; + } else { + lj_record_call(J, func, 2); /* res = mobj(tab, key) */ + return 0; /* No result yet. */ + } + } + /* Otherwise retry lookup with metaobject. */ + ix->tab = ix->mobj; + copyTV(J->L, &ix->tabv, &ix->mobjv); + if (--ix->idxchain == 0) + lj_trace_err(J, LJ_TRERR_IDXLOOP); + } + + /* First catch nil and NaN keys for tables. */ + if (tvisnil(&ix->keyv) || (tvisnum(&ix->keyv) && tvisnan(&ix->keyv))) { + if (ix->val) /* Better fail early. */ + lj_trace_err(J, LJ_TRERR_STORENN); + if (tref_isk(ix->key)) { + if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_index)) + goto handlemm; + return TREF_NIL; + } + } + + /* Record the key lookup. */ + xref = rec_idx_key(J, ix); + xrefop = IR(tref_ref(xref))->o; + loadop = xrefop == IR_AREF ? IR_ALOAD : IR_HLOAD; + /* The lj_meta_tset() inconsistency is gone, but better play safe. */ + oldv = xrefop == IR_KKPTR ? (cTValue *)ir_kptr(IR(tref_ref(xref))) : ix->oldv; + + if (ix->val == 0) { /* Indexed load */ + IRType t = itype2irt(oldv); + TRef res; + if (oldv == niltvg(J2G(J))) { + emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + res = TREF_NIL; + } else { + res = emitir(IRTG(loadop, t), xref, 0); + } + if (t == IRT_NIL && ix->idxchain && lj_record_mm_lookup(J, ix, MM_index)) + goto handlemm; + if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitives. */ + return res; + } else { /* Indexed store. */ + GCtab *mt = tabref(tabV(&ix->tabv)->metatable); + int keybarrier = tref_isgcv(ix->key) && !tref_isnil(ix->val); + if (tvisnil(oldv)) { /* Previous value was nil? */ + /* Need to duplicate the hasmm check for the early guards. */ + int hasmm = 0; + if (ix->idxchain && mt) { + cTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), MM_newindex)); + hasmm = mo && !tvisnil(mo); + } + if (hasmm) + emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */ + else if (xrefop == IR_HREF) + emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32), + xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) { + lua_assert(hasmm); + goto handlemm; + } + lua_assert(!hasmm); + if (oldv == niltvg(J2G(J))) { /* Need to insert a new key. */ + TRef key = ix->key; + if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */ + key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT); + xref = emitir(IRT(IR_NEWREF, IRT_P32), ix->tab, key); + keybarrier = 0; /* NEWREF already takes care of the key barrier. */ + } + } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) { + /* Cannot derive that the previous value was non-nil, must do checks. */ + if (xrefop == IR_HREF) /* Guard against store to niltv. */ + emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); + if (ix->idxchain) { /* Metamethod lookup required? */ + /* A check for NULL metatable is cheaper (hoistable) than a load. */ + if (!mt) { + TRef mtref = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META); + emitir(IRTG(IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB)); + } else { + IRType t = itype2irt(oldv); + emitir(IRTG(loadop, t), xref, 0); /* Guard for non-nil value. */ + } + } + } else { + keybarrier = 0; /* Previous non-nil value kept the key alive. */ + } + /* Convert int to number before storing. */ + if (!LJ_DUALNUM && tref_isinteger(ix->val)) + ix->val = emitir(IRTN(IR_CONV), ix->val, IRCONV_NUM_INT); + emitir(IRT(loadop+IRDELTA_L2S, tref_type(ix->val)), xref, ix->val); + if (keybarrier || tref_isgcv(ix->val)) + emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0); + /* Invalidate neg. metamethod cache for stores with certain string keys. */ + if (!nommstr(J, ix->key)) { + TRef fref = emitir(IRT(IR_FREF, IRT_P32), ix->tab, IRFL_TAB_NOMM); + emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0)); + } + J->needsnap = 1; + return 0; + } +} + +/* -- Upvalue access ------------------------------------------------------ */ + +/* Check whether upvalue is immutable and ok to constify. */ +static int rec_upvalue_constify(jit_State *J, GCupval *uvp) +{ + if (uvp->immutable) { + cTValue *o = uvval(uvp); + /* Don't constify objects that may retain large amounts of memory. */ +#if LJ_HASFFI + if (tviscdata(o)) { + GCcdata *cd = cdataV(o); + if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) { + CType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid); + if (!ctype_hassize(ct->info) || ct->size <= 16) + return 1; + } + return 0; + } +#else + UNUSED(J); +#endif + if (!(tvistab(o) || tvisudata(o) || tvisthread(o))) + return 1; + } + return 0; +} + +/* Record upvalue load/store. */ +static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val) +{ + GCupval *uvp = &gcref(J->fn->l.uvptr[uv])->uv; + TRef fn = getcurrf(J); + IRRef uref; + int needbarrier = 0; + if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */ + TRef tr, kfunc; + lua_assert(val == 0); + if (!tref_isk(fn)) { /* Late specialization of current function. */ + if (J->pt->flags >= PROTO_CLC_POLY) + goto noconstify; + kfunc = lj_ir_kfunc(J, J->fn); + emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc); + J->base[-1] = TREF_FRAME | kfunc; + fn = kfunc; + } + tr = lj_record_constify(J, uvval(uvp)); + if (tr) + return tr; + } +noconstify: + /* Note: this effectively limits LJ_MAX_UPVAL to 127. */ + uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff); + if (!uvp->closed) { + /* In current stack? */ + if (uvval(uvp) >= tvref(J->L->stack) && + uvval(uvp) < tvref(J->L->maxstack)) { + int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot)); + if (slot >= 0) { /* Aliases an SSA slot? */ + slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */ + /* NYI: add IR to guard that it's still aliasing the same slot. */ + if (val == 0) { + return getslot(J, slot); + } else { + J->base[slot] = val; + if (slot >= (int32_t)J->maxslot) J->maxslot = (BCReg)(slot+1); + return 0; + } + } + } + uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_P32), fn, uv)); + } else { + needbarrier = 1; + uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_P32), fn, uv)); + } + if (val == 0) { /* Upvalue load */ + IRType t = itype2irt(uvval(uvp)); + TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0); + if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */ + return res; + } else { /* Upvalue store. */ + /* Convert int to number before storing. */ + if (!LJ_DUALNUM && tref_isinteger(val)) + val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); + emitir(IRT(IR_USTORE, tref_type(val)), uref, val); + if (needbarrier && tref_isgcv(val)) + emitir(IRT(IR_OBAR, IRT_NIL), uref, val); + J->needsnap = 1; + return 0; + } +} + +/* -- Record calls to Lua functions --------------------------------------- */ + +/* Check unroll limits for calls. */ +static void check_call_unroll(jit_State *J, TraceNo lnk) +{ + cTValue *frame = J->L->base - 1; + void *pc = mref(frame_func(frame)->l.pc, void); + int32_t depth = J->framedepth; + int32_t count = 0; + if ((J->pt->flags & PROTO_VARARG)) depth--; /* Vararg frame still missing. */ + for (; depth > 0; depth--) { /* Count frames with same prototype. */ + if (frame_iscont(frame)) depth--; + frame = frame_prev(frame); + if (mref(frame_func(frame)->l.pc, void) == pc) + count++; + } + if (J->pc == J->startpc) { + if (count + J->tailcalled > J->param[JIT_P_recunroll]) { + J->pc++; + if (J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Tail-recursion. */ + else + rec_stop(J, LJ_TRLINK_UPREC, J->cur.traceno); /* Up-recursion. */ + } + } else { + if (count > J->param[JIT_P_callunroll]) { + if (lnk) { /* Possible tail- or up-recursion. */ + lj_trace_flush(J, lnk); /* Flush trace that only returns. */ + /* Set a small, pseudo-random hotcount for a quick retry of JFUNC*. */ + hotcount_set(J2GG(J), J->pc+1, LJ_PRNG_BITS(J, 4)); + } + lj_trace_err(J, LJ_TRERR_CUNROLL); + } + } +} + +/* Record Lua function setup. */ +static void rec_func_setup(jit_State *J) +{ + GCproto *pt = J->pt; + BCReg s, numparams = pt->numparams; + if ((pt->flags & PROTO_NOJIT)) + lj_trace_err(J, LJ_TRERR_CJITOFF); + if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + /* Fill up missing parameters with nil. */ + for (s = J->maxslot; s < numparams; s++) + J->base[s] = TREF_NIL; + /* The remaining slots should never be read before they are written. */ + J->maxslot = numparams; +} + +/* Record Lua vararg function setup. */ +static void rec_func_vararg(jit_State *J) +{ + GCproto *pt = J->pt; + BCReg s, fixargs, vframe = J->maxslot+1; + lua_assert((pt->flags & PROTO_VARARG)); + if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + J->base[vframe-1] = J->base[-1]; /* Copy function up. */ + /* Copy fixarg slots up and set their original slots to nil. */ + fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot; + for (s = 0; s < fixargs; s++) { + J->base[vframe+s] = J->base[s]; + J->base[s] = TREF_NIL; + } + J->maxslot = fixargs; + J->framedepth++; + J->base += vframe; + J->baseslot += vframe; +} + +/* Record entry to a Lua function. */ +static void rec_func_lua(jit_State *J) +{ + rec_func_setup(J); + check_call_unroll(J, 0); +} + +/* Record entry to an already compiled function. */ +static void rec_func_jit(jit_State *J, TraceNo lnk) +{ + GCtrace *T; + rec_func_setup(J); + T = traceref(J, lnk); + if (T->linktype == LJ_TRLINK_RETURN) { /* Trace returns to interpreter? */ + check_call_unroll(J, lnk); + /* Temporarily unpatch JFUNC* to continue recording across function. */ + J->patchins = *J->pc; + J->patchpc = (BCIns *)J->pc; + *J->patchpc = T->startins; + return; + } + J->instunroll = 0; /* Cannot continue across a compiled function. */ + if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) + rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Extra tail-recursion. */ + else + rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the function. */ +} + +/* -- Vararg handling ----------------------------------------------------- */ + +/* Detect y = select(x, ...) idiom. */ +static int select_detect(jit_State *J) +{ + BCIns ins = J->pc[1]; + if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) { + cTValue *func = &J->L->base[bc_a(ins)]; + if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) + return 1; + } + return 0; +} + +/* Record vararg instruction. */ +static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) +{ + int32_t numparams = J->pt->numparams; + ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1; + lua_assert(frame_isvarg(J->L->base-1)); + if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */ + ptrdiff_t i; + if (nvararg < 0) nvararg = 0; + if (nresults == -1) { + nresults = nvararg; + J->maxslot = dst + (BCReg)nvararg; + } else if (dst + nresults > J->maxslot) { + J->maxslot = dst + (BCReg)nresults; + } + for (i = 0; i < nresults; i++) + J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL; + } else { /* Unknown number of varargs passed to trace. */ + TRef fr = emitir(IRTI(IR_SLOAD), 0, IRSLOAD_READONLY|IRSLOAD_FRAME); + int32_t frofs = 8*(1+numparams)+FRAME_VARG; + if (nresults >= 0) { /* Known fixed number of results. */ + ptrdiff_t i; + if (nvararg > 0) { + ptrdiff_t nload = nvararg >= nresults ? nresults : nvararg; + TRef vbase; + if (nvararg >= nresults) + emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults)); + else + emitir(IRTGI(IR_EQ), fr, lj_ir_kint(J, frame_ftsz(J->L->base-1))); + vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); + vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); + for (i = 0; i < nload; i++) { + IRType t = itype2irt(&J->L->base[i-1-nvararg]); + TRef aref = emitir(IRT(IR_AREF, IRT_P32), + vbase, lj_ir_kint(J, (int32_t)i)); + TRef tr = emitir(IRTG(IR_VLOAD, t), aref, 0); + if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */ + J->base[dst+i] = tr; + } + } else { + emitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs)); + nvararg = 0; + } + for (i = nvararg; i < nresults; i++) + J->base[dst+i] = TREF_NIL; + if (dst + (BCReg)nresults > J->maxslot) + J->maxslot = dst + (BCReg)nresults; + } else if (select_detect(J)) { /* y = select(x, ...) */ + TRef tridx = J->base[dst-1]; + TRef tr = TREF_NIL; + ptrdiff_t idx = lj_ffrecord_select_mode(J, tridx, &J->L->base[dst-1]); + if (idx < 0) goto nyivarg; + if (idx != 0 && !tref_isinteger(tridx)) + tridx = emitir(IRTGI(IR_CONV), tridx, IRCONV_INT_NUM|IRCONV_INDEX); + if (idx != 0 && tref_isk(tridx)) { + emitir(IRTGI(idx <= nvararg ? IR_GE : IR_LT), + fr, lj_ir_kint(J, frofs+8*(int32_t)idx)); + frofs -= 8; /* Bias for 1-based index. */ + } else if (idx <= nvararg) { /* Compute size. */ + TRef tmp = emitir(IRTI(IR_ADD), fr, lj_ir_kint(J, -frofs)); + if (numparams) + emitir(IRTGI(IR_GE), tmp, lj_ir_kint(J, 0)); + tr = emitir(IRTI(IR_BSHR), tmp, lj_ir_kint(J, 3)); + if (idx != 0) { + tridx = emitir(IRTI(IR_ADD), tridx, lj_ir_kint(J, -1)); + rec_idx_abc(J, tr, tridx, (uint32_t)nvararg); + } + } else { + TRef tmp = lj_ir_kint(J, frofs); + if (idx != 0) { + TRef tmp2 = emitir(IRTI(IR_BSHL), tridx, lj_ir_kint(J, 3)); + tmp = emitir(IRTI(IR_ADD), tmp2, tmp); + } else { + tr = lj_ir_kint(J, 0); + } + emitir(IRTGI(IR_LT), fr, tmp); + } + if (idx != 0 && idx <= nvararg) { + IRType t; + TRef aref, vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); + vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); + t = itype2irt(&J->L->base[idx-2-nvararg]); + aref = emitir(IRT(IR_AREF, IRT_P32), vbase, tridx); + tr = emitir(IRTG(IR_VLOAD, t), aref, 0); + if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */ + } + J->base[dst-2] = tr; + J->maxslot = dst-1; + J->bcskip = 2; /* Skip CALLM + select. */ + } else { + nyivarg: + setintV(&J->errinfo, BC_VARG); + lj_trace_err_info(J, LJ_TRERR_NYIBC); + } + } +} + +/* -- Record allocations -------------------------------------------------- */ + +static TRef rec_tnew(jit_State *J, uint32_t ah) +{ + uint32_t asize = ah & 0x7ff; + uint32_t hbits = ah >> 11; + if (asize == 0x7ff) asize = 0x801; + return emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits); +} + +/* -- Record bytecode ops ------------------------------------------------- */ + +/* Prepare for comparison. */ +static void rec_comp_prep(jit_State *J) +{ + /* Prevent merging with snapshot #0 (GC exit) since we fixup the PC. */ + if (J->cur.nsnap == 1 && J->cur.snap[0].ref == J->cur.nins) + emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); + lj_snap_add(J); +} + +/* Fixup comparison. */ +static void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond) +{ + BCIns jmpins = pc[1]; + const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0); + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + /* Set PC to opposite target to avoid re-recording the comp. in side trace. */ + J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc); + J->needsnap = 1; + if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins); + lj_snap_shrink(J); /* Shrink last snapshot if possible. */ +} + +/* Record the next bytecode instruction (_before_ it's executed). */ +void lj_record_ins(jit_State *J) +{ + cTValue *lbase; + RecordIndex ix; + const BCIns *pc; + BCIns ins; + BCOp op; + TRef ra, rb, rc; + + /* Perform post-processing action before recording the next instruction. */ + if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) { + switch (J->postproc) { + case LJ_POST_FIXCOMP: /* Fixup comparison. */ + pc = frame_pc(&J2G(J)->tmptv); + rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1))); + /* fallthrough */ + case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */ + case LJ_POST_FIXGUARDSNAP: /* Fixup and emit pending guard and snapshot. */ + if (!tvistruecond(&J2G(J)->tmptv2)) { + J->fold.ins.o ^= 1; /* Flip guard to opposite. */ + if (J->postproc == LJ_POST_FIXGUARDSNAP) { + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + J->cur.snapmap[snap->mapofs+snap->nent-1]--; /* False -> true. */ + } + } + lj_opt_fold(J); /* Emit pending guard. */ + /* fallthrough */ + case LJ_POST_FIXBOOL: + if (!tvistruecond(&J2G(J)->tmptv2)) { + BCReg s; + TValue *tv = J->L->base; + for (s = 0; s < J->maxslot; s++) /* Fixup stack slot (if any). */ + if (J->base[s] == TREF_TRUE && tvisfalse(&tv[s])) { + J->base[s] = TREF_FALSE; + break; + } + } + break; + case LJ_POST_FIXCONST: + { + BCReg s; + TValue *tv = J->L->base; + for (s = 0; s < J->maxslot; s++) /* Constify stack slots (if any). */ + if (J->base[s] == TREF_NIL && !tvisnil(&tv[s])) + J->base[s] = lj_record_constify(J, &tv[s]); + } + break; + case LJ_POST_FFRETRY: /* Suppress recording of retried fast function. */ + if (bc_op(*J->pc) >= BC__MAX) + return; + break; + default: lua_assert(0); break; + } + J->postproc = LJ_POST_NONE; + } + + /* Need snapshot before recording next bytecode (e.g. after a store). */ + if (J->needsnap) { + J->needsnap = 0; + lj_snap_purge(J); + lj_snap_add(J); + J->mergesnap = 1; + } + + /* Skip some bytecodes. */ + if (LJ_UNLIKELY(J->bcskip > 0)) { + J->bcskip--; + return; + } + + /* Record only closed loops for root traces. */ + pc = J->pc; + if (J->framedepth == 0 && + (MSize)((char *)pc - (char *)J->bc_min) >= J->bc_extent) + lj_trace_err(J, LJ_TRERR_LLEAVE); + +#ifdef LUA_USE_ASSERT + rec_check_slots(J); + rec_check_ir(J); +#endif + + /* Keep a copy of the runtime values of var/num/str operands. */ +#define rav (&ix.valv) +#define rbv (&ix.tabv) +#define rcv (&ix.keyv) + + lbase = J->L->base; + ins = *pc; + op = bc_op(ins); + ra = bc_a(ins); + ix.val = 0; + switch (bcmode_a(op)) { + case BCMvar: + copyTV(J->L, rav, &lbase[ra]); ix.val = ra = getslot(J, ra); break; + default: break; /* Handled later. */ + } + rb = bc_b(ins); + rc = bc_c(ins); + switch (bcmode_b(op)) { + case BCMnone: rb = 0; rc = bc_d(ins); break; /* Upgrade rc to 'rd'. */ + case BCMvar: + copyTV(J->L, rbv, &lbase[rb]); ix.tab = rb = getslot(J, rb); break; + default: break; /* Handled later. */ + } + switch (bcmode_c(op)) { + case BCMvar: + copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break; + case BCMpri: setitype(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break; + case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc); + copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) : + lj_ir_knumint(J, numV(tv)); } break; + case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc)); + setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break; + default: break; /* Handled later. */ + } + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: +#if LJ_HASFFI + if (tref_iscdata(ra) || tref_iscdata(rc)) { + rec_mm_comp_cdata(J, &ix, op, ((int)op & 2) ? MM_le : MM_lt); + break; + } +#endif + /* Emit nothing for two numeric or string consts. */ + if (!(tref_isk2(ra,rc) && tref_isnumber_str(ra) && tref_isnumber_str(rc))) { + IRType ta = tref_isinteger(ra) ? IRT_INT : tref_type(ra); + IRType tc = tref_isinteger(rc) ? IRT_INT : tref_type(rc); + int irop; + if (ta != tc) { + /* Widen mixed number/int comparisons to number/number comparison. */ + if (ta == IRT_INT && tc == IRT_NUM) { + ra = emitir(IRTN(IR_CONV), ra, IRCONV_NUM_INT); + ta = IRT_NUM; + } else if (ta == IRT_NUM && tc == IRT_INT) { + rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); + } else if (LJ_52) { + ta = IRT_NIL; /* Force metamethod for different types. */ + } else if (!((ta == IRT_FALSE || ta == IRT_TRUE) && + (tc == IRT_FALSE || tc == IRT_TRUE))) { + break; /* Interpreter will throw for two different types. */ + } + } + rec_comp_prep(J); + irop = (int)op - (int)BC_ISLT + (int)IR_LT; + if (ta == IRT_NUM) { + if ((irop & 1)) irop ^= 4; /* ISGE/ISGT are unordered. */ + if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop)) + irop ^= 5; + } else if (ta == IRT_INT) { + if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop)) + irop ^= 1; + } else if (ta == IRT_STR) { + if (!lj_ir_strcmp(strV(rav), strV(rcv), (IROp)irop)) irop ^= 1; + ra = lj_ir_call(J, IRCALL_lj_str_cmp, ra, rc); + rc = lj_ir_kint(J, 0); + ta = IRT_INT; + } else { + rec_mm_comp(J, &ix, (int)op); + break; + } + emitir(IRTG(irop, ta), ra, rc); + rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1); + } + break; + + case BC_ISEQV: case BC_ISNEV: + case BC_ISEQS: case BC_ISNES: + case BC_ISEQN: case BC_ISNEN: + case BC_ISEQP: case BC_ISNEP: +#if LJ_HASFFI + if (tref_iscdata(ra) || tref_iscdata(rc)) { + rec_mm_comp_cdata(J, &ix, op, MM_eq); + break; + } +#endif + /* Emit nothing for two non-table, non-udata consts. */ + if (!(tref_isk2(ra, rc) && !(tref_istab(ra) || tref_isudata(ra)))) { + int diff; + rec_comp_prep(J); + diff = lj_record_objcmp(J, ra, rc, rav, rcv); + if (diff == 2 || !(tref_istab(ra) || tref_isudata(ra))) + rec_comp_fixup(J, J->pc, ((int)op & 1) == !diff); + else if (diff == 1) /* Only check __eq if different, but same type. */ + rec_mm_equal(J, &ix, (int)op); + } + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: + if ((op & 1) == tref_istruecond(rc)) + rc = 0; /* Don't store if condition is not true. */ + /* fallthrough */ + case BC_IST: case BC_ISF: /* Type specialization suffices. */ + if (bc_a(pc[1]) < J->maxslot) + J->maxslot = bc_a(pc[1]); /* Shrink used slots. */ + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_NOT: + /* Type specialization already forces const result. */ + rc = tref_istruecond(rc) ? TREF_FALSE : TREF_TRUE; + break; + + case BC_LEN: + if (tref_isstr(rc)) + rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN); + else if (!LJ_52 && tref_istab(rc)) + rc = lj_ir_call(J, IRCALL_lj_tab_len, rc); + else + rc = rec_mm_len(J, rc, rcv); + break; + + /* -- Arithmetic ops ---------------------------------------------------- */ + + case BC_UNM: + if (tref_isnumber_str(rc)) { + rc = lj_opt_narrow_unm(J, rc, rcv); + } else { + ix.tab = rc; + copyTV(J->L, &ix.tabv, rcv); + rc = rec_mm_arith(J, &ix, MM_unm); + } + break; + + case BC_ADDNV: case BC_SUBNV: case BC_MULNV: case BC_DIVNV: case BC_MODNV: + /* Swap rb/rc and rbv/rcv. rav is temp. */ + ix.tab = rc; ix.key = rc = rb; rb = ix.tab; + copyTV(J->L, rav, rbv); + copyTV(J->L, rbv, rcv); + copyTV(J->L, rcv, rav); + if (op == BC_MODNV) + goto recmod; + /* fallthrough */ + case BC_ADDVN: case BC_SUBVN: case BC_MULVN: case BC_DIVVN: + case BC_ADDVV: case BC_SUBVV: case BC_MULVV: case BC_DIVVV: { + MMS mm = bcmode_mm(op); + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv, + (int)mm - (int)MM_add + (int)IR_ADD); + else + rc = rec_mm_arith(J, &ix, mm); + break; + } + + case BC_MODVN: case BC_MODVV: + recmod: + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_mod(J, rb, rc, rcv); + else + rc = rec_mm_arith(J, &ix, MM_mod); + break; + + case BC_POW: + if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) + rc = lj_opt_narrow_pow(J, lj_ir_tonum(J, rb), rc, rcv); + else + rc = rec_mm_arith(J, &ix, MM_pow); + break; + + /* -- Constant and move ops --------------------------------------------- */ + + case BC_MOV: + /* Clear gap of method call to avoid resurrecting previous refs. */ + if (ra > J->maxslot) J->base[ra-1] = 0; + break; + case BC_KSTR: case BC_KNUM: case BC_KPRI: + break; + case BC_KSHORT: + rc = lj_ir_kint(J, (int32_t)(int16_t)rc); + break; + case BC_KNIL: + while (ra <= rc) + J->base[ra++] = TREF_NIL; + if (rc >= J->maxslot) J->maxslot = rc+1; + break; +#if LJ_HASFFI + case BC_KCDATA: + rc = lj_ir_kgc(J, proto_kgc(J->pt, ~(ptrdiff_t)rc), IRT_CDATA); + break; +#endif + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + rc = rec_upvalue(J, rc, 0); + break; + case BC_USETV: case BC_USETS: case BC_USETN: case BC_USETP: + rec_upvalue(J, ra, rc); + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_GGET: case BC_GSET: + settabV(J->L, &ix.tabv, tabref(J->fn->l.env)); + ix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), getcurrf(J), IRFL_FUNC_ENV); + ix.idxchain = LJ_MAX_IDXCHAIN; + rc = lj_record_idx(J, &ix); + break; + + case BC_TGETB: case BC_TSETB: + setintV(&ix.keyv, (int32_t)rc); + ix.key = lj_ir_kint(J, (int32_t)rc); + /* fallthrough */ + case BC_TGETV: case BC_TGETS: case BC_TSETV: case BC_TSETS: + ix.idxchain = LJ_MAX_IDXCHAIN; + rc = lj_record_idx(J, &ix); + break; + + case BC_TNEW: + rc = rec_tnew(J, rc); + break; + case BC_TDUP: + rc = emitir(IRTG(IR_TDUP, IRT_TAB), + lj_ir_ktab(J, gco2tab(proto_kgc(J->pt, ~(ptrdiff_t)rc))), 0); + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_ITERC: + J->base[ra] = getslot(J, ra-3); + J->base[ra+1] = getslot(J, ra-2); + J->base[ra+2] = getslot(J, ra-1); + { /* Do the actual copy now because lj_record_call needs the values. */ + TValue *b = &J->L->base[ra]; + copyTV(J->L, b, b-3); + copyTV(J->L, b+1, b-2); + copyTV(J->L, b+2, b-1); + } + lj_record_call(J, ra, (ptrdiff_t)rc-1); + break; + + /* L->top is set to L->base+ra+rc+NARGS-1+1. See lj_dispatch_ins(). */ + case BC_CALLM: + rc = (BCReg)(J->L->top - J->L->base) - ra; + /* fallthrough */ + case BC_CALL: + lj_record_call(J, ra, (ptrdiff_t)rc-1); + break; + + case BC_CALLMT: + rc = (BCReg)(J->L->top - J->L->base) - ra; + /* fallthrough */ + case BC_CALLT: + lj_record_tailcall(J, ra, (ptrdiff_t)rc-1); + break; + + case BC_VARG: + rec_varg(J, ra, (ptrdiff_t)rb-1); + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + /* L->top is set to L->base+ra+rc+NRESULTS-1, see lj_dispatch_ins(). */ + rc = (BCReg)(J->L->top - J->L->base) - ra + 1; + /* fallthrough */ + case BC_RET: case BC_RET0: case BC_RET1: + lj_record_ret(J, ra, (ptrdiff_t)rc-1); + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORI: + if (rec_for(J, pc, 0) != LOOPEV_LEAVE) + J->loopref = J->cur.nins; + break; + case BC_JFORI: + lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL); + if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */ + rec_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J])); + /* Continue tracing if the loop is not entered. */ + break; + + case BC_FORL: + rec_loop_interp(J, pc, rec_for(J, pc+((ptrdiff_t)rc-BCBIAS_J), 1)); + break; + case BC_ITERL: + rec_loop_interp(J, pc, rec_iterl(J, *pc)); + break; + case BC_LOOP: + rec_loop_interp(J, pc, rec_loop(J, ra)); + break; + + case BC_JFORL: + rec_loop_jit(J, rc, rec_for(J, pc+bc_j(traceref(J, rc)->startins), 1)); + break; + case BC_JITERL: + rec_loop_jit(J, rc, rec_iterl(J, traceref(J, rc)->startins)); + break; + case BC_JLOOP: + rec_loop_jit(J, rc, rec_loop(J, ra)); + break; + + case BC_IFORL: + case BC_IITERL: + case BC_ILOOP: + case BC_IFUNCF: + case BC_IFUNCV: + lj_trace_err(J, LJ_TRERR_BLACKL); + break; + + case BC_JMP: + if (ra < J->maxslot) + J->maxslot = ra; /* Shrink used slots. */ + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + rec_func_lua(J); + break; + case BC_JFUNCF: + rec_func_jit(J, rc); + break; + + case BC_FUNCV: + rec_func_vararg(J); + rec_func_lua(J); + break; + case BC_JFUNCV: + lua_assert(0); /* Cannot happen. No hotcall counting for varag funcs. */ + break; + + case BC_FUNCC: + case BC_FUNCCW: + lj_ffrecord_func(J); + break; + + default: + if (op >= BC__MAX) { + lj_ffrecord_func(J); + break; + } + /* fallthrough */ + case BC_ITERN: + case BC_ISNEXT: + case BC_CAT: + case BC_UCLO: + case BC_FNEW: + case BC_TSETM: + setintV(&J->errinfo, (int32_t)op); + lj_trace_err_info(J, LJ_TRERR_NYIBC); + break; + } + + /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */ + if (bcmode_a(op) == BCMdst && rc) { + J->base[ra] = rc; + if (ra >= J->maxslot) J->maxslot = ra+1; + } + +#undef rav +#undef rbv +#undef rcv + + /* Limit the number of recorded IR instructions. */ + if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord]) + lj_trace_err(J, LJ_TRERR_TRACEOV); +} + +/* -- Recording setup ----------------------------------------------------- */ + +/* Setup recording for a root trace started by a hot loop. */ +static const BCIns *rec_setup_root(jit_State *J) +{ + /* Determine the next PC and the bytecode range for the loop. */ + const BCIns *pcj, *pc = J->pc; + BCIns ins = *pc; + BCReg ra = bc_a(ins); + switch (bc_op(ins)) { + case BC_FORL: + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + pc += 1+bc_j(ins); + J->bc_min = pc; + break; + case BC_ITERL: + lua_assert(bc_op(pc[-1]) == BC_ITERC); + J->maxslot = ra + bc_b(pc[-1]) - 1; + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + pc += 1+bc_j(ins); + lua_assert(bc_op(pc[-1]) == BC_JMP); + J->bc_min = pc; + break; + case BC_LOOP: + /* Only check BC range for real loops, but not for "repeat until true". */ + pcj = pc + bc_j(ins); + ins = *pcj; + if (bc_op(ins) == BC_JMP && bc_j(ins) < 0) { + J->bc_min = pcj+1 + bc_j(ins); + J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); + } + J->maxslot = ra; + pc++; + break; + case BC_RET: + case BC_RET0: + case BC_RET1: + /* No bytecode range check for down-recursive root traces. */ + J->maxslot = ra + bc_d(ins) - 1; + break; + case BC_FUNCF: + /* No bytecode range check for root traces started by a hot call. */ + J->maxslot = J->pt->numparams; + pc++; + break; + default: + lua_assert(0); + break; + } + return pc; +} + +/* Setup for recording a new trace. */ +void lj_record_setup(jit_State *J) +{ + uint32_t i; + + /* Initialize state related to current trace. */ + memset(J->slot, 0, sizeof(J->slot)); + memset(J->chain, 0, sizeof(J->chain)); + memset(J->bpropcache, 0, sizeof(J->bpropcache)); + J->scev.idx = REF_NIL; + + J->baseslot = 1; /* Invoking function is at base[-1]. */ + J->base = J->slot + J->baseslot; + J->maxslot = 0; + J->framedepth = 0; + J->retdepth = 0; + + J->instunroll = J->param[JIT_P_instunroll]; + J->loopunroll = J->param[JIT_P_loopunroll]; + J->tailcalled = 0; + J->loopref = 0; + + J->bc_min = NULL; /* Means no limit. */ + J->bc_extent = ~(MSize)0; + + /* Emit instructions for fixed references. Also triggers initial IR alloc. */ + emitir_raw(IRT(IR_BASE, IRT_P32), J->parent, J->exitno); + for (i = 0; i <= 2; i++) { + IRIns *ir = IR(REF_NIL-i); + ir->i = 0; + ir->t.irt = (uint8_t)(IRT_NIL+i); + ir->o = IR_KPRI; + ir->prev = 0; + } + J->cur.nk = REF_TRUE; + + J->startpc = J->pc; + setmref(J->cur.startpc, J->pc); + if (J->parent) { /* Side trace. */ + GCtrace *T = traceref(J, J->parent); + TraceNo root = T->root ? T->root : J->parent; + J->cur.root = (uint16_t)root; + J->cur.startins = BCINS_AD(BC_JMP, 0, 0); + /* Check whether we could at least potentially form an extra loop. */ + if (J->exitno == 0 && T->snap[0].nent == 0) { + /* We can narrow a FORL for some side traces, too. */ + if (J->pc > proto_bc(J->pt) && bc_op(J->pc[-1]) == BC_JFORI && + bc_d(J->pc[bc_j(J->pc[-1])-1]) == root) { + lj_snap_add(J); + rec_for_loop(J, J->pc-1, &J->scev, 1); + goto sidecheck; + } + } else { + J->startpc = NULL; /* Prevent forming an extra loop. */ + } + lj_snap_replay(J, T); + sidecheck: + if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || + T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + + J->param[JIT_P_tryside]) { + rec_stop(J, LJ_TRLINK_INTERP, 0); + } + } else { /* Root trace. */ + J->cur.root = 0; + J->cur.startins = *J->pc; + J->pc = rec_setup_root(J); + /* Note: the loop instruction itself is recorded at the end and not + ** at the start! So snapshot #0 needs to point to the *next* instruction. + */ + lj_snap_add(J); + if (bc_op(J->cur.startins) == BC_FORL) + rec_for_loop(J, J->pc-1, &J->scev, 1); + if (1 + J->pt->framesize >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); + } +#ifdef LUAJIT_ENABLE_CHECKHOOK + /* Regularly check for instruction/line hooks from compiled code and + ** exit to the interpreter if the hooks are set. + ** + ** This is a compile-time option and disabled by default, since the + ** hook checks may be quite expensive in tight loops. + ** + ** Note this is only useful if hooks are *not* set most of the time. + ** Use this only if you want to *asynchronously* interrupt the execution. + ** + ** You can set the instruction hook via lua_sethook() with a count of 1 + ** from a signal handler or another native thread. Please have a look + ** at the first few functions in luajit.c for an example (Ctrl-C handler). + */ + { + TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), + lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE); + tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT))); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); + } +#endif +} + +#undef IR +#undef emitir_raw +#undef emitir + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.h new file mode 100644 index 0000000..940e105 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_record.h @@ -0,0 +1,44 @@ +/* +** Trace recorder (bytecode -> SSA IR). +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_RECORD_H +#define _LJ_RECORD_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +/* Context for recording an indexed load/store. */ +typedef struct RecordIndex { + TValue tabv; /* Runtime value of table (or indexed object). */ + TValue keyv; /* Runtime value of key. */ + TValue valv; /* Runtime value of stored value. */ + TValue mobjv; /* Runtime value of metamethod object. */ + GCtab *mtv; /* Runtime value of metatable object. */ + cTValue *oldv; /* Runtime value of previously stored value. */ + TRef tab; /* Table (or indexed object) reference. */ + TRef key; /* Key reference. */ + TRef val; /* Value reference for a store or 0 for a load. */ + TRef mt; /* Metatable reference. */ + TRef mobj; /* Metamethod object reference. */ + int idxchain; /* Index indirections left or 0 for raw lookup. */ +} RecordIndex; + +LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b, + cTValue *av, cTValue *bv); +LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o); + +LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs); +LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs); +LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults); + +LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm); +LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix); + +LJ_FUNC void lj_record_ins(jit_State *J); +LJ_FUNC void lj_record_setup(jit_State *J); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.c new file mode 100644 index 0000000..1c978c2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.c @@ -0,0 +1,865 @@ +/* +** Snapshot handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_snap_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_frame.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_target.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#include "lj_cdata.h" +#endif + +/* Some local macros to save typing. Undef'd at the end. */ +#define IR(ref) (&J->cur.ir[(ref)]) + +/* Pass IR on to next optimization in chain (FOLD). */ +#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) + +/* Emit raw IR without passing through optimizations. */ +#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J)) + +/* -- Snapshot buffer allocation ------------------------------------------ */ + +/* Grow snapshot buffer. */ +void lj_snap_grow_buf_(jit_State *J, MSize need) +{ + MSize maxsnap = (MSize)J->param[JIT_P_maxsnap]; + if (need > maxsnap) + lj_trace_err(J, LJ_TRERR_SNAPOV); + lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot); + J->cur.snap = J->snapbuf; +} + +/* Grow snapshot map buffer. */ +void lj_snap_grow_map_(jit_State *J, MSize need) +{ + if (need < 2*J->sizesnapmap) + need = 2*J->sizesnapmap; + else if (need < 64) + need = 64; + J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf, + J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry)); + J->cur.snapmap = J->snapmapbuf; + J->sizesnapmap = need; +} + +/* -- Snapshot generation ------------------------------------------------- */ + +/* Add all modified slots to the snapshot. */ +static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) +{ + IRRef retf = J->chain[IR_RETF]; /* Limits SLOAD restore elimination. */ + BCReg s; + MSize n = 0; + for (s = 0; s < nslots; s++) { + TRef tr = J->slot[s]; + IRRef ref = tref_ref(tr); + if (ref) { + SnapEntry sn = SNAP_TR(s, tr); + IRIns *ir = IR(ref); + if (!(sn & (SNAP_CONT|SNAP_FRAME)) && + ir->o == IR_SLOAD && ir->op1 == s && ref > retf) { + /* No need to snapshot unmodified non-inherited slots. */ + if (!(ir->op2 & IRSLOAD_INHERIT)) + continue; + /* No need to restore readonly slots and unmodified non-parent slots. */ + if (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) && + (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT) + sn |= SNAP_NORESTORE; + } + if (LJ_SOFTFP && irt_isnum(ir->t)) + sn |= SNAP_SOFTFPNUM; + map[n++] = sn; + } + } + return n; +} + +/* Add frame links at the end of the snapshot. */ +static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map) +{ + cTValue *frame = J->L->base - 1; + cTValue *lim = J->L->base - J->baseslot; + cTValue *ftop = frame + funcproto(frame_func(frame))->framesize; + MSize f = 0; + map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */ + while (frame > lim) { /* Backwards traversal of all frames above base. */ + if (frame_islua(frame)) { + map[f++] = SNAP_MKPC(frame_pc(frame)); + frame = frame_prevl(frame); + if (frame + funcproto(frame_func(frame))->framesize > ftop) + ftop = frame + funcproto(frame_func(frame))->framesize; + } else if (frame_iscont(frame)) { + map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); + map[f++] = SNAP_MKPC(frame_contpc(frame)); + frame = frame_prevd(frame); + } else { + lua_assert(!frame_isc(frame)); + map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); + frame = frame_prevd(frame); + } + } + lua_assert(f == (MSize)(1 + J->framedepth)); + return (BCReg)(ftop - lim); +} + +/* Take a snapshot of the current stack. */ +static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap) +{ + BCReg nslots = J->baseslot + J->maxslot; + MSize nent; + SnapEntry *p; + /* Conservative estimate. */ + lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1); + p = &J->cur.snapmap[nsnapmap]; + nent = snapshot_slots(J, p, nslots); + snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent); + snap->mapofs = (uint16_t)nsnapmap; + snap->ref = (IRRef1)J->cur.nins; + snap->nent = (uint8_t)nent; + snap->nslots = (uint8_t)nslots; + snap->count = 0; + J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth); +} + +/* Add or merge a snapshot. */ +void lj_snap_add(jit_State *J) +{ + MSize nsnap = J->cur.nsnap; + MSize nsnapmap = J->cur.nsnapmap; + /* Merge if no ins. inbetween or if requested and no guard inbetween. */ + if (J->mergesnap ? !irt_isguard(J->guardemit) : + (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) { + if (nsnap == 1) { /* But preserve snap #0 PC. */ + emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); + goto nomerge; + } + nsnapmap = J->cur.snap[--nsnap].mapofs; + } else { + nomerge: + lj_snap_grow_buf(J, nsnap+1); + J->cur.nsnap = (uint16_t)(nsnap+1); + } + J->mergesnap = 0; + J->guardemit.irt = 0; + snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap); +} + +/* -- Snapshot modification ----------------------------------------------- */ + +#define SNAP_USEDEF_SLOTS (LJ_MAX_JSLOTS+LJ_STACK_EXTRA) + +/* Find unused slots with reaching-definitions bytecode data-flow analysis. */ +static BCReg snap_usedef(jit_State *J, uint8_t *udf, + const BCIns *pc, BCReg maxslot) +{ + BCReg s; + GCobj *o; + + if (maxslot == 0) return 0; +#ifdef LUAJIT_USE_VALGRIND + /* Avoid errors for harmless reads beyond maxslot. */ + memset(udf, 1, SNAP_USEDEF_SLOTS); +#else + memset(udf, 1, maxslot); +#endif + + /* Treat open upvalues as used. */ + o = gcref(J->L->openupval); + while (o) { + if (uvval(gco2uv(o)) < J->L->base) break; + udf[uvval(gco2uv(o)) - J->L->base] = 0; + o = gcref(o->gch.nextgc); + } + +#define USE_SLOT(s) udf[(s)] &= ~1 +#define DEF_SLOT(s) udf[(s)] *= 3 + + /* Scan through following bytecode and check for uses/defs. */ + lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc); + for (;;) { + BCIns ins = *pc++; + BCOp op = bc_op(ins); + switch (bcmode_b(op)) { + case BCMvar: USE_SLOT(bc_b(ins)); break; + default: break; + } + switch (bcmode_c(op)) { + case BCMvar: USE_SLOT(bc_c(ins)); break; + case BCMrbase: + lua_assert(op == BC_CAT); + for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + break; + case BCMjump: + handle_jump: { + BCReg minslot = bc_a(ins); + if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT; + else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1; + else if (op == BC_UCLO) { pc += bc_j(ins); break; } + for (s = minslot; s < maxslot; s++) DEF_SLOT(s); + return minslot < maxslot ? minslot : maxslot; + } + case BCMlit: + if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) { + goto handle_jump; + } else if (bc_isret(op)) { + BCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1); + for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s); + for (; s < top; s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + return 0; + } + break; + case BCMfunc: return maxslot; /* NYI: will abort, anyway. */ + default: break; + } + switch (bcmode_a(op)) { + case BCMvar: USE_SLOT(bc_a(ins)); break; + case BCMdst: + if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins)); + break; + case BCMbase: + if (op >= BC_CALLM && op <= BC_VARG) { + BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ? + maxslot : (bc_a(ins) + bc_c(ins)); + s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0); + for (; s < top; s++) USE_SLOT(s); + for (; s < maxslot; s++) DEF_SLOT(s); + if (op == BC_CALLT || op == BC_CALLMT) { + for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s); + return 0; + } + } else if (op == BC_KNIL) { + for (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s); + } else if (op == BC_TSETM) { + for (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s); + } + break; + default: break; + } + lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc); + } + +#undef USE_SLOT +#undef DEF_SLOT + + return 0; /* unreachable */ +} + +/* Purge dead slots before the next snapshot. */ +void lj_snap_purge(jit_State *J) +{ + uint8_t udf[SNAP_USEDEF_SLOTS]; + BCReg maxslot = J->maxslot; + BCReg s = snap_usedef(J, udf, J->pc, maxslot); + for (; s < maxslot; s++) + if (udf[s] != 0) + J->base[s] = 0; /* Purge dead slots. */ +} + +/* Shrink last snapshot. */ +void lj_snap_shrink(jit_State *J) +{ + SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; + SnapEntry *map = &J->cur.snapmap[snap->mapofs]; + MSize n, m, nlim, nent = snap->nent; + uint8_t udf[SNAP_USEDEF_SLOTS]; + BCReg maxslot = J->maxslot; + BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot); + BCReg baseslot = J->baseslot; + maxslot += baseslot; + minslot += baseslot; + snap->nslots = (uint8_t)maxslot; + for (n = m = 0; n < nent; n++) { /* Remove unused slots from snapshot. */ + BCReg s = snap_slot(map[n]); + if (s < minslot || (s < maxslot && udf[s-baseslot] == 0)) + map[m++] = map[n]; /* Only copy used slots. */ + } + snap->nent = (uint8_t)m; + nlim = J->cur.nsnapmap - snap->mapofs - 1; + while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */ + J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */ +} + +/* -- Snapshot access ----------------------------------------------------- */ + +/* Initialize a Bloom Filter with all renamed refs. +** There are very few renames (often none), so the filter has +** very few bits set. This makes it suitable for negative filtering. +*/ +static BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim) +{ + BloomFilter rfilt = 0; + IRIns *ir; + for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--) + if (ir->op2 <= lim) + bloomset(rfilt, ir->op1); + return rfilt; +} + +/* Process matching renames to find the original RegSP. */ +static RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs) +{ + IRIns *ir; + for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--) + if (ir->op1 == ref && ir->op2 <= lim) + rs = ir->prev; + return rs; +} + +/* Copy RegSP from parent snapshot to the parent links of the IR. */ +IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir) +{ + SnapShot *snap = &T->snap[snapno]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + BloomFilter rfilt = snap_renamefilter(T, snapno); + MSize n = 0; + IRRef ref = 0; + for ( ; ; ir++) { + uint32_t rs; + if (ir->o == IR_SLOAD) { + if (!(ir->op2 & IRSLOAD_PARENT)) break; + for ( ; ; n++) { + lua_assert(n < snap->nent); + if (snap_slot(map[n]) == ir->op1) { + ref = snap_ref(map[n++]); + break; + } + } + } else if (LJ_SOFTFP && ir->o == IR_HIOP) { + ref++; + } else if (ir->o == IR_PVAL) { + ref = ir->op1 + REF_BIAS; + } else { + break; + } + rs = T->ir[ref].prev; + if (bloomtest(rfilt, ref)) + rs = snap_renameref(T, snapno, ref, rs); + ir->prev = (uint16_t)rs; + lua_assert(regsp_used(rs)); + } + return ir; +} + +/* -- Snapshot replay ----------------------------------------------------- */ + +/* Replay constant from parent trace. */ +static TRef snap_replay_const(jit_State *J, IRIns *ir) +{ + /* Only have to deal with constants that can occur in stack slots. */ + switch ((IROp)ir->o) { + case IR_KPRI: return TREF_PRI(irt_type(ir->t)); + case IR_KINT: return lj_ir_kint(J, ir->i); + case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); + case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir)); + case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir)); + case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ + default: lua_assert(0); return TREF_NIL; break; + } +} + +/* De-duplicate parent reference. */ +static TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref) +{ + MSize j; + for (j = 0; j < nmax; j++) + if (snap_ref(map[j]) == ref) + return J->slot[snap_slot(map[j])] & ~(SNAP_CONT|SNAP_FRAME); + return 0; +} + +/* Emit parent reference with de-duplication. */ +static TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax, + BloomFilter seen, IRRef ref) +{ + IRIns *ir = &T->ir[ref]; + TRef tr; + if (irref_isk(ref)) + tr = snap_replay_const(J, ir); + else if (!regsp_used(ir->prev)) + tr = 0; + else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0) + tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0); + return tr; +} + +/* Check whether a sunk store corresponds to an allocation. Slow path. */ +static int snap_sunk_store2(jit_State *J, IRIns *ira, IRIns *irs) +{ + if (irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE || irs->o == IR_XSTORE) { + IRIns *irk = IR(irs->op1); + if (irk->o == IR_AREF || irk->o == IR_HREFK) + irk = IR(irk->op1); + return (IR(irk->op1) == ira); + } + return 0; +} + +/* Check whether a sunk store corresponds to an allocation. Fast path. */ +static LJ_AINLINE int snap_sunk_store(jit_State *J, IRIns *ira, IRIns *irs) +{ + if (irs->s != 255) + return (ira + irs->s == irs); /* Fast check. */ + return snap_sunk_store2(J, ira, irs); +} + +/* Replay snapshot state to setup side trace. */ +void lj_snap_replay(jit_State *J, GCtrace *T) +{ + SnapShot *snap = &T->snap[J->exitno]; + SnapEntry *map = &T->snapmap[snap->mapofs]; + MSize n, nent = snap->nent; + BloomFilter seen = 0; + int pass23 = 0; + J->framedepth = 0; + /* Emit IR for slots inherited from parent snapshot. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + BCReg s = snap_slot(sn); + IRRef ref = snap_ref(sn); + IRIns *ir = &T->ir[ref]; + TRef tr; + /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */ + if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0) + goto setslot; + bloomset(seen, ref); + if (irref_isk(ref)) { + tr = snap_replay_const(J, ir); + } else if (!regsp_used(ir->prev)) { + pass23 = 1; + lua_assert(s != 0); + tr = s; + } else { + IRType t = irt_type(ir->t); + uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT; + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; + if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY); + tr = emitir_raw(IRT(IR_SLOAD, t), s, mode); + } + setslot: + J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ + J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); + if ((sn & SNAP_FRAME)) + J->baseslot = s+1; + } + if (pass23) { + IRIns *irlast = &T->ir[snap->ref]; + pass23 = 0; + /* Emit dependent PVALs. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + IRRef refp = snap_ref(sn); + IRIns *ir = &T->ir[refp]; + if (regsp_reg(ir->r) == RID_SUNK) { + if (J->slot[snap_slot(sn)] != snap_slot(sn)) continue; + pass23 = 1; + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || + ir->o == IR_CNEW || ir->o == IR_CNEWI); + if (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1); + if (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2); + if (LJ_HASFFI && ir->o == IR_CNEWI) { + if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) + snap_pref(J, T, map, nent, seen, (ir+1)->op2); + } else { + IRIns *irs; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (snap_pref(J, T, map, nent, seen, irs->op2) == 0) + snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1); + else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && + irs+1 < irlast && (irs+1)->o == IR_HIOP) + snap_pref(J, T, map, nent, seen, (irs+1)->op2); + } + } + } else if (!irref_isk(refp) && !regsp_used(ir->prev)) { + lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + J->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1); + } + } + /* Replay sunk instructions. */ + for (n = 0; pass23 && n < nent; n++) { + SnapEntry sn = map[n]; + IRRef refp = snap_ref(sn); + IRIns *ir = &T->ir[refp]; + if (regsp_reg(ir->r) == RID_SUNK) { + TRef op1, op2; + if (J->slot[snap_slot(sn)] != snap_slot(sn)) { /* De-dup allocs. */ + J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]]; + continue; + } + op1 = ir->op1; + if (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1); + op2 = ir->op2; + if (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2); + if (LJ_HASFFI && ir->o == IR_CNEWI) { + if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) { + lj_needsplit(J); /* Emit joining HIOP. */ + op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2, + snap_pref(J, T, map, nent, seen, (ir+1)->op2)); + } + J->slot[snap_slot(sn)] = emitir(ir->ot, op1, op2); + } else { + IRIns *irs; + TRef tr = emitir(ir->ot, op1, op2); + J->slot[snap_slot(sn)] = tr; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *irr = &T->ir[irs->op1]; + TRef val, key = irr->op2, tmp = tr; + if (irr->o != IR_FREF) { + IRIns *irk = &T->ir[key]; + if (irr->o == IR_HREFK) + key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]), + irk->op2); + else + key = snap_replay_const(J, irk); + if (irr->o == IR_HREFK || irr->o == IR_AREF) { + IRIns *irf = &T->ir[irr->op1]; + tmp = emitir(irf->ot, tmp, irf->op2); + } + } + tmp = emitir(irr->ot, tmp, key); + val = snap_pref(J, T, map, nent, seen, irs->op2); + if (val == 0) { + IRIns *irc = &T->ir[irs->op2]; + lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT); + val = snap_pref(J, T, map, nent, seen, irc->op1); + val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); + } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && + irs+1 < irlast && (irs+1)->o == IR_HIOP) { + IRType t = IRT_I64; + if (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP) + t = IRT_NUM; + lj_needsplit(J); + if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) { + uint64_t k = (uint32_t)T->ir[irs->op2].i + + ((uint64_t)T->ir[(irs+1)->op2].i << 32); + val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM, + lj_ir_k64_find(J, k)); + } else { + val = emitir_raw(IRT(IR_HIOP, t), val, + snap_pref(J, T, map, nent, seen, (irs+1)->op2)); + } + tmp = emitir(IRT(irs->o, t), tmp, val); + continue; + } + tmp = emitir(irs->ot, tmp, val); + } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) { + emitir(IRT(IR_XBAR, IRT_NIL), 0, 0); + } + } + } + } + } + J->base = J->slot + J->baseslot; + J->maxslot = snap->nslots - J->baseslot; + lj_snap_add(J); + if (pass23) /* Need explicit GC step _after_ initial snapshot. */ + emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0); +} + +/* -- Snapshot restore ---------------------------------------------------- */ + +static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRIns *ir, TValue *o); + +/* Restore a value from the trace exit state. */ +static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRRef ref, TValue *o) +{ + IRIns *ir = &T->ir[ref]; + IRType1 t = ir->t; + RegSP rs = ir->prev; + if (irref_isk(ref)) { /* Restore constant slot. */ + lj_ir_kvalue(J->L, o, ir); + return; + } + if (LJ_UNLIKELY(bloomtest(rfilt, ref))) + rs = snap_renameref(T, snapno, ref, rs); + if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */ + int32_t *sps = &ex->spill[regsp_spill(rs)]; + if (irt_isinteger(t)) { + setintV(o, *sps); +#if !LJ_SOFTFP + } else if (irt_isnum(t)) { + o->u64 = *(uint64_t *)sps; +#endif + } else if (LJ_64 && irt_islightud(t)) { + /* 64 bit lightuserdata which may escape already has the tag bits. */ + o->u64 = *(uint64_t *)sps; + } else { + lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */ + setgcrefi(o->gcr, *sps); + setitype(o, irt_toitype(t)); + } + } else { /* Restore from register. */ + Reg r = regsp_reg(rs); + if (ra_noreg(r)) { + lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o); + if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o)); + return; + } else if (irt_isinteger(t)) { + setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]); +#if !LJ_SOFTFP + } else if (irt_isnum(t)) { + setnumV(o, ex->fpr[r-RID_MIN_FPR]); +#endif + } else if (LJ_64 && irt_islightud(t)) { + /* 64 bit lightuserdata which may escape already has the tag bits. */ + o->u64 = ex->gpr[r-RID_MIN_GPR]; + } else { + if (!irt_ispri(t)) + setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]); + setitype(o, irt_toitype(t)); + } + } +} + +#if LJ_HASFFI +/* Restore raw data from the trace exit state. */ +static void snap_restoredata(GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRRef ref, void *dst, CTSize sz) +{ + IRIns *ir = &T->ir[ref]; + RegSP rs = ir->prev; + int32_t *src; + uint64_t tmp; + if (irref_isk(ref)) { + if (ir->o == IR_KNUM || ir->o == IR_KINT64) { + src = mref(ir->ptr, int32_t); + } else if (sz == 8) { + tmp = (uint64_t)(uint32_t)ir->i; + src = (int32_t *)&tmp; + } else { + src = &ir->i; + } + } else { + if (LJ_UNLIKELY(bloomtest(rfilt, ref))) + rs = snap_renameref(T, snapno, ref, rs); + if (ra_hasspill(regsp_spill(rs))) { + src = &ex->spill[regsp_spill(rs)]; + if (sz == 8 && !irt_is64(ir->t)) { + tmp = (uint64_t)(uint32_t)*src; + src = (int32_t *)&tmp; + } + } else { + Reg r = regsp_reg(rs); + if (ra_noreg(r)) { + /* Note: this assumes CNEWI is never used for SOFTFP split numbers. */ + lua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); + snap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4); + *(lua_Number *)dst = (lua_Number)*(int32_t *)dst; + return; + } + src = (int32_t *)&ex->gpr[r-RID_MIN_GPR]; +#if !LJ_SOFTFP + if (r >= RID_MAX_GPR) { + src = (int32_t *)&ex->fpr[r-RID_MIN_FPR]; +#if LJ_TARGET_PPC + if (sz == 4) { /* PPC FPRs are always doubles. */ + *(float *)dst = (float)*(double *)src; + return; + } +#else + if (LJ_BE && sz == 4) src++; +#endif + } +#endif + } + } + lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8); + if (sz == 4) *(int32_t *)dst = *src; + else if (sz == 8) *(int64_t *)dst = *(int64_t *)src; + else if (sz == 1) *(int8_t *)dst = (int8_t)*src; + else *(int16_t *)dst = (int16_t)*src; +} +#endif + +/* Unsink allocation from the trace exit state. Unsink sunk stores. */ +static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, + SnapNo snapno, BloomFilter rfilt, + IRIns *ir, TValue *o) +{ + lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || + ir->o == IR_CNEW || ir->o == IR_CNEWI); +#if LJ_HASFFI + if (ir->o == IR_CNEW || ir->o == IR_CNEWI) { + CTState *cts = ctype_cts(J->L); + CTypeID id = (CTypeID)T->ir[ir->op1].i; + CTSize sz = lj_ctype_size(cts, id); + GCcdata *cd = lj_cdata_new(cts, id, sz); + setcdataV(J->L, o, cd); + if (ir->o == IR_CNEWI) { + uint8_t *p = (uint8_t *)cdataptr(cd); + lua_assert(sz == 4 || sz == 8); + if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) { + snap_restoredata(T, ex, snapno, rfilt, (ir+1)->op2, LJ_LE?p+4:p, 4); + if (LJ_BE) p += 4; + sz = 4; + } + snap_restoredata(T, ex, snapno, rfilt, ir->op2, p, sz); + } else { + IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref]; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *iro = &T->ir[T->ir[irs->op1].op2]; + uint8_t *p = (uint8_t *)cd; + CTSize szs; + lua_assert(irs->o == IR_XSTORE && T->ir[irs->op1].o == IR_ADD); + lua_assert(iro->o == IR_KINT || iro->o == IR_KINT64); + if (irt_is64(irs->t)) szs = 8; + else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1; + else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2; + else szs = 4; + if (LJ_64 && iro->o == IR_KINT64) + p += (int64_t)ir_k64(iro)->u64; + else + p += iro->i; + lua_assert(p >= (uint8_t *)cdataptr(cd) && + p + szs <= (uint8_t *)cdataptr(cd) + sz); + if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { + lua_assert(szs == 4); + snap_restoredata(T, ex, snapno, rfilt, (irs+1)->op2, LJ_LE?p+4:p,4); + if (LJ_BE) p += 4; + } + snap_restoredata(T, ex, snapno, rfilt, irs->op2, p, szs); + } + } + } else +#endif + { + IRIns *irs, *irlast; + GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) : + lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1])); + settabV(J->L, o, t); + irlast = &T->ir[T->snap[snapno].ref]; + for (irs = ir+1; irs < irlast; irs++) + if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + IRIns *irk = &T->ir[irs->op1]; + TValue tmp, *val; + lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE || + irs->o == IR_FSTORE); + if (irk->o == IR_FREF) { + lua_assert(irk->op2 == IRFL_TAB_META); + snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp); + /* NOBARRIER: The table is new (marked white). */ + setgcref(t->metatable, obj2gco(tabV(&tmp))); + } else { + irk = &T->ir[irk->op2]; + if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1]; + lj_ir_kvalue(J->L, &tmp, irk); + val = lj_tab_set(J->L, t, &tmp); + /* NOBARRIER: The table is new (marked white). */ + snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val); + if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { + snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp); + val->u32.hi = tmp.u32.lo; + } + } + } + } +} + +/* Restore interpreter state from exit state with the help of a snapshot. */ +const BCIns *lj_snap_restore(jit_State *J, void *exptr) +{ + ExitState *ex = (ExitState *)exptr; + SnapNo snapno = J->exitno; /* For now, snapno == exitno. */ + GCtrace *T = traceref(J, J->parent); + SnapShot *snap = &T->snap[snapno]; + MSize n, nent = snap->nent; + SnapEntry *map = &T->snapmap[snap->mapofs]; + SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; + int32_t ftsz0; + TValue *frame; + BloomFilter rfilt = snap_renamefilter(T, snapno); + const BCIns *pc = snap_pc(map[nent]); + lua_State *L = J->L; + + /* Set interpreter PC to the next PC to get correct error messages. */ + setcframe_pc(cframe_raw(L->cframe), pc+1); + + /* Make sure the stack is big enough for the slots from the snapshot. */ + if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) { + L->top = curr_topL(L); + lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize); + } + + /* Fill stack slots with data from the registers and spill slots. */ + frame = L->base-1; + ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */ + for (n = 0; n < nent; n++) { + SnapEntry sn = map[n]; + if (!(sn & SNAP_NORESTORE)) { + TValue *o = &frame[snap_slot(sn)]; + IRRef ref = snap_ref(sn); + IRIns *ir = &T->ir[ref]; + if (ir->r == RID_SUNK) { + MSize j; + for (j = 0; j < n; j++) + if (snap_ref(map[j]) == ref) { /* De-duplicate sunk allocations. */ + copyTV(L, o, &frame[snap_slot(map[j])]); + goto dupslot; + } + snap_unsink(J, T, ex, snapno, rfilt, ir, o); + dupslot: + continue; + } + snap_restoreval(J, T, ex, snapno, rfilt, ref, o); + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) { + TValue tmp; + snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp); + o->u32.hi = tmp.u32.lo; + } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { + /* Overwrite tag with frame link. */ + o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0; + L->base = o+1; + } + } + } + lua_assert(map + nent == flinks); + + /* Compute current stack top. */ + switch (bc_op(*pc)) { + default: + if (bc_op(*pc) < BC_FUNCF) { + L->top = curr_topL(L); + break; + } + /* fallthrough */ + case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM: + L->top = frame + snap->nslots; + break; + } + return pc; +} + +#undef IR +#undef emitir_raw +#undef emitir + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.h new file mode 100644 index 0000000..1b2d74d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_snap.h @@ -0,0 +1,34 @@ +/* +** Snapshot handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_SNAP_H +#define _LJ_SNAP_H + +#include "lj_obj.h" +#include "lj_jit.h" + +#if LJ_HASJIT +LJ_FUNC void lj_snap_add(jit_State *J); +LJ_FUNC void lj_snap_purge(jit_State *J); +LJ_FUNC void lj_snap_shrink(jit_State *J); +LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir); +LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T); +LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr); +LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need); +LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need); + +static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need) +{ + if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need); +} + +static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need) +{ + if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need); +} + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.c new file mode 100644 index 0000000..451de69 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.c @@ -0,0 +1,288 @@ +/* +** State and stack handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_state_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_func.h" +#include "lj_meta.h" +#include "lj_state.h" +#include "lj_frame.h" +#if LJ_HASFFI +#include "lj_ctype.h" +#endif +#include "lj_trace.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_lex.h" +#include "lj_alloc.h" + +/* -- Stack handling ------------------------------------------------------ */ + +/* Stack sizes. */ +#define LJ_STACK_MIN LUA_MINSTACK /* Min. stack size. */ +#define LJ_STACK_MAX LUAI_MAXSTACK /* Max. stack size. */ +#define LJ_STACK_START (2*LJ_STACK_MIN) /* Starting stack size. */ +#define LJ_STACK_MAXEX (LJ_STACK_MAX + 1 + LJ_STACK_EXTRA) + +/* Explanation of LJ_STACK_EXTRA: +** +** Calls to metamethods store their arguments beyond the current top +** without checking for the stack limit. This avoids stack resizes which +** would invalidate passed TValue pointers. The stack check is performed +** later by the function header. This can safely resize the stack or raise +** an error. Thus we need some extra slots beyond the current stack limit. +** +** Most metamethods need 4 slots above top (cont, mobj, arg1, arg2) plus +** one extra slot if mobj is not a function. Only lj_meta_tset needs 5 +** slots above top, but then mobj is always a function. So we can get by +** with 5 extra slots. +*/ + +/* Resize stack slots and adjust pointers in state. */ +static void resizestack(lua_State *L, MSize n) +{ + TValue *st, *oldst = tvref(L->stack); + ptrdiff_t delta; + MSize oldsize = L->stacksize; + MSize realsize = n + 1 + LJ_STACK_EXTRA; + GCobj *up; + lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1); + st = (TValue *)lj_mem_realloc(L, tvref(L->stack), + (MSize)(L->stacksize*sizeof(TValue)), + (MSize)(realsize*sizeof(TValue))); + setmref(L->stack, st); + delta = (char *)st - (char *)oldst; + setmref(L->maxstack, st + n); + while (oldsize < realsize) /* Clear new slots. */ + setnilV(st + oldsize++); + L->stacksize = realsize; + L->base = (TValue *)((char *)L->base + delta); + L->top = (TValue *)((char *)L->top + delta); + for (up = gcref(L->openupval); up != NULL; up = gcnext(up)) + setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta)); + if (obj2gco(L) == gcref(G(L)->jit_L)) + setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta); +} + +/* Relimit stack after error, in case the limit was overdrawn. */ +void lj_state_relimitstack(lua_State *L) +{ + if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1) + resizestack(L, LJ_STACK_MAX); +} + +/* Try to shrink the stack (called from GC). */ +void lj_state_shrinkstack(lua_State *L, MSize used) +{ + if (L->stacksize > LJ_STACK_MAXEX) + return; /* Avoid stack shrinking while handling stack overflow. */ + if (4*used < L->stacksize && + 2*(LJ_STACK_START+LJ_STACK_EXTRA) < L->stacksize && + obj2gco(L) != gcref(G(L)->jit_L)) /* Don't shrink stack of live trace. */ + resizestack(L, L->stacksize >> 1); +} + +/* Try to grow stack. */ +void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) +{ + MSize n; + if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */ + lj_err_throw(L, LUA_ERRERR); + n = L->stacksize + need; + if (n > LJ_STACK_MAX) { + n += 2*LUA_MINSTACK; + } else if (n < 2*L->stacksize) { + n = 2*L->stacksize; + if (n >= LJ_STACK_MAX) + n = LJ_STACK_MAX; + } + resizestack(L, n); + if (L->stacksize > LJ_STACK_MAXEX) + lj_err_msg(L, LJ_ERR_STKOV); +} + +void LJ_FASTCALL lj_state_growstack1(lua_State *L) +{ + lj_state_growstack(L, 1); +} + +/* Allocate basic stack for new state. */ +static void stack_init(lua_State *L1, lua_State *L) +{ + TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue); + setmref(L1->stack, st); + L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA; + stend = st + L1->stacksize; + setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1); + L1->base = L1->top = st+1; + setthreadV(L1, st, L1); /* Needed for curr_funcisL() on empty stack. */ + while (st < stend) /* Clear new slots. */ + setnilV(st++); +} + +/* -- State handling ------------------------------------------------------ */ + +/* Open parts that may cause memory-allocation errors. */ +static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud) +{ + global_State *g = G(L); + UNUSED(dummy); + UNUSED(ud); + stack_init(L, L); + /* NOBARRIER: State initialization, all objects are white. */ + setgcref(L->env, obj2gco(lj_tab_new(L, 0, LJ_MIN_GLOBAL))); + settabV(L, registry(L), lj_tab_new(L, 0, LJ_MIN_REGISTRY)); + lj_str_resize(L, LJ_MIN_STRTAB-1); + lj_meta_init(L); + lj_lex_init(L); + fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */ + g->gc.threshold = 4*g->gc.total; + lj_trace_initstate(g); + return NULL; +} + +static void close_state(lua_State *L) +{ + global_State *g = G(L); + lj_func_closeuv(L, tvref(L->stack)); + lj_gc_freeall(g); + lua_assert(gcref(g->gc.root) == obj2gco(L)); + lua_assert(g->strnum == 0); + lj_trace_freestate(g); +#if LJ_HASFFI + lj_ctype_freestate(g); +#endif + lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); + lj_str_freebuf(g, &g->tmpbuf); + lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); + lua_assert(g->gc.total == sizeof(GG_State)); +#ifndef LUAJIT_USE_SYSMALLOC + if (g->allocf == lj_alloc_f) + lj_alloc_destroy(g->allocd); + else +#endif + g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); +} + +#if LJ_64 +lua_State *lj_state_newstate(lua_Alloc f, void *ud) +#else +LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) +#endif +{ + GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State)); + lua_State *L = &GG->L; + global_State *g = &GG->g; + if (GG == NULL || !checkptr32(GG)) return NULL; + memset(GG, 0, sizeof(GG_State)); + L->constlist=NULL; + L->gct = ~LJ_TTHREAD; + L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */ + L->dummy_ffid = FF_C; + setmref(L->glref, g); + g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED; + g->strempty.marked = LJ_GC_WHITE0; + g->strempty.gct = ~LJ_TSTR; + g->allocf = f; + g->allocd = ud; + setgcref(g->mainthref, obj2gco(L)); + setgcref(g->uvhead.prev, obj2gco(&g->uvhead)); + setgcref(g->uvhead.next, obj2gco(&g->uvhead)); + g->strmask = ~(MSize)0; + setnilV(registry(L)); + setnilV(&g->nilnode.val); + setnilV(&g->nilnode.key); + setmref(g->nilnode.freetop, &g->nilnode); + lj_str_initbuf(&g->tmpbuf); + g->gc.state = GCSpause; + setgcref(g->gc.root, obj2gco(L)); + setmref(g->gc.sweep, &g->gc.root); + g->gc.total = sizeof(GG_State); + g->gc.pause = LUAI_GCPAUSE; + g->gc.stepmul = LUAI_GCMUL; + lj_dispatch_init((GG_State *)L); + L->status = LUA_ERRERR+1; /* Avoid touching the stack upon memory error. */ + if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) { + /* Memory allocation error: free partial state. */ + close_state(L); + return NULL; + } + L->status = 0; + return L; +} + +static TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud) +{ + UNUSED(dummy); + UNUSED(ud); + lj_gc_finalize_cdata(L); + lj_gc_finalize_udata(L); + /* Frame pop omitted. */ + return NULL; +} + +LUA_API void lua_close(lua_State *L) +{ + global_State *g = G(L); + int i; + L = mainthread(g); /* Only the main thread can be closed. */ + lj_func_closeuv(L, tvref(L->stack)); + lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */ +#if LJ_HASJIT + G2J(g)->flags &= ~JIT_F_ON; + G2J(g)->state = LJ_TRACE_IDLE; + lj_dispatch_update(g); +#endif + for (i = 0;;) { + hook_enter(g); + L->status = 0; + L->cframe = NULL; + L->base = L->top = tvref(L->stack) + 1; + if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == 0) { + if (++i >= 10) break; + lj_gc_separateudata(g, 1); /* Separate udata again. */ + if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */ + break; + } + } + close_state(L); +} + +lua_State *lj_state_new(lua_State *L) +{ + lua_State *L1 = lj_mem_newobj(L, lua_State); + L1->gct = ~LJ_TTHREAD; + L1->dummy_ffid = FF_C; + L1->status = 0; + L1->stacksize = 0; + setmref(L1->stack, NULL); + L1->cframe = NULL; + /* NOBARRIER: The lua_State is new (marked white). */ + setgcrefnull(L1->openupval); + setmrefr(L1->glref, L->glref); + setgcrefr(L1->env, L->env); + stack_init(L1, L); /* init stack */ + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + +void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L) +{ + lua_assert(L != mainthread(g)); + lj_func_closeuv(L, tvref(L->stack)); + lua_assert(gcref(L->openupval) == NULL); + lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); + lj_mem_freet(g, L); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.h new file mode 100644 index 0000000..74249d9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_state.h @@ -0,0 +1,35 @@ +/* +** State and stack handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STATE_H +#define _LJ_STATE_H + +#include "lj_obj.h" + +#define incr_top(L) \ + (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0)) + +#define savestack(L, p) ((char *)(p) - mref(L->stack, char)) +#define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n))) + +LJ_FUNC void lj_state_relimitstack(lua_State *L); +LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used); +LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need); +LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L); + +static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need) +{ + if ((mref(L->maxstack, char) - (char *)L->top) <= + (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue)) + lj_state_growstack(L, need); +} + +LJ_FUNC lua_State *lj_state_new(lua_State *L); +LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L); +#if LJ_64 +LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.c new file mode 100644 index 0000000..aead8b5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.c @@ -0,0 +1,339 @@ +/* +** String handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include + +#define lj_str_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_str.h" +#include "lj_state.h" +#include "lj_char.h" + +/* -- String interning ---------------------------------------------------- */ + +/* Ordered compare of strings. Assumes string data is 4-byte aligned. */ +int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) +{ + MSize i, n = a->len > b->len ? b->len : a->len; + for (i = 0; i < n; i += 4) { + /* Note: innocuous access up to end of string + 3. */ + uint32_t va = *(const uint32_t *)(strdata(a)+i); + uint32_t vb = *(const uint32_t *)(strdata(b)+i); + if (va != vb) { +#if LJ_LE + va = lj_bswap(va); vb = lj_bswap(vb); +#endif + i -= n; + if ((int32_t)i >= -3) { + va >>= 32+(i<<3); vb >>= 32+(i<<3); + if (va == vb) break; + } + return va < vb ? -1 : 1; + } + } + return (int32_t)(a->len - b->len); +} + +/* Fast string data comparison. Caveat: unaligned access to 1st string! */ +static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) +{ + MSize i = 0; + lua_assert(len > 0); + lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); + do { /* Note: innocuous access up to end of string + 3. */ + uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); + if (v) { + i -= len; +#if LJ_LE + return (int32_t)i >= -3 ? (v << (32+(i<<3))) : 1; +#else + return (int32_t)i >= -3 ? (v >> (32+(i<<3))) : 1; +#endif + } + i += 4; + } while (i < len); + return 0; +} + +/* Resize the string hash table (grow and shrink). */ +void lj_str_resize(lua_State *L, MSize newmask) +{ + global_State *g = G(L); + GCRef *newhash; + MSize i; + if (g->gc.state == GCSsweepstring || newmask >= LJ_MAX_STRTAB-1) + return; /* No resizing during GC traversal or if already too big. */ + newhash = lj_mem_newvec(L, newmask+1, GCRef); + memset(newhash, 0, (newmask+1)*sizeof(GCRef)); + for (i = g->strmask; i != ~(MSize)0; i--) { /* Rehash old table. */ + GCobj *p = gcref(g->strhash[i]); + while (p) { /* Follow each hash chain and reinsert all strings. */ + MSize h = gco2str(p)->hash & newmask; + GCobj *next = gcnext(p); + /* NOBARRIER: The string table is a GC root. */ + setgcrefr(p->gch.nextgc, newhash[h]); + setgcref(newhash[h], p); + p = next; + } + } + lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); + g->strmask = newmask; + g->strhash = newhash; +} + +/* Intern a string and return string object. */ +GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) +{ + global_State *g; + GCstr *s; + GCobj *o; + MSize len = (MSize)lenx; + MSize a, b, h = len; + if (lenx >= LJ_MAX_STR) + lj_err_msg(L, LJ_ERR_STROV); + g = G(L); + /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */ + if (len >= 4) { /* Caveat: unaligned access! */ + a = lj_getu32(str); + h ^= lj_getu32(str+len-4); + b = lj_getu32(str+(len>>1)-2); + h ^= b; h -= lj_rol(b, 14); + b += lj_getu32(str+(len>>2)-1); + } else if (len > 0) { + a = *(const uint8_t *)str; + h ^= *(const uint8_t *)(str+len-1); + b = *(const uint8_t *)(str+(len>>1)); + h ^= b; h -= lj_rol(b, 14); + } else { + return &g->strempty; + } + a ^= h; a -= lj_rol(h, 11); + b ^= a; b -= lj_rol(a, 25); + h ^= b; h -= lj_rol(b, 16); + /* Check if the string has already been interned. */ + o = gcref(g->strhash[h & g->strmask]); + if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { + while (o != NULL) { + GCstr *sx = gco2str(o); + if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) { + /* Resurrect if dead. Can only happen with fixstring() (keywords). */ + if (isdead(g, o)) flipwhite(o); + return sx; /* Return existing string. */ + } + o = gcnext(o); + } + } else { /* Slow path: end of string is too close to a page boundary. */ + while (o != NULL) { + GCstr *sx = gco2str(o); + if (sx->len == len && memcmp(str, strdata(sx), len) == 0) { + /* Resurrect if dead. Can only happen with fixstring() (keywords). */ + if (isdead(g, o)) flipwhite(o); + return sx; /* Return existing string. */ + } + o = gcnext(o); + } + } + /* Nope, create a new string. */ + s = lj_mem_newt(L, sizeof(GCstr)+len+1, GCstr); + newwhite(g, s); + s->gct = ~LJ_TSTR; + s->len = len; + s->hash = h; + s->reserved = 0; + memcpy(strdatawr(s), str, len); + strdatawr(s)[len] = '\0'; /* Zero-terminate string. */ + /* Add it to string hash table. */ + h &= g->strmask; + s->nextgc = g->strhash[h]; + /* NOBARRIER: The string table is a GC root. */ + setgcref(g->strhash[h], obj2gco(s)); + if (g->strnum++ > g->strmask) /* Allow a 100% load factor. */ + lj_str_resize(L, (g->strmask<<1)+1); /* Grow string table. */ + return s; /* Return newly interned string. */ +} + +void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) +{ + g->strnum--; + lj_mem_free(g, s, sizestring(s)); +} + +/* -- Type conversions ---------------------------------------------------- */ + +/* Print number to buffer. Canonicalizes non-finite values. */ +size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o) +{ + if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */ + lua_Number n = o->n; +#if __BIONIC__ + if (tvismzero(o)) { s[0] = '-'; s[1] = '0'; return 2; } +#endif + return (size_t)lua_number2str(s, n); + } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) { + s[0] = 'n'; s[1] = 'a'; s[2] = 'n'; return 3; + } else if ((o->u32.hi & 0x80000000) == 0) { + s[0] = 'i'; s[1] = 'n'; s[2] = 'f'; return 3; + } else { + s[0] = '-'; s[1] = 'i'; s[2] = 'n'; s[3] = 'f'; return 4; + } +} + +/* Print integer to buffer. Returns pointer to start. */ +char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k) +{ + uint32_t u = (uint32_t)(k < 0 ? -k : k); + p += 1+10; + do { *--p = (char)('0' + u % 10); } while (u /= 10); + if (k < 0) *--p = '-'; + return p; +} + +/* Convert number to string. */ +GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np) +{ + char buf[LJ_STR_NUMBUF]; + size_t len = lj_str_bufnum(buf, (TValue *)np); + return lj_str_new(L, buf, len); +} + +/* Convert integer to string. */ +GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k) +{ + char s[1+10]; + char *p = lj_str_bufint(s, k); + return lj_str_new(L, p, (size_t)(s+sizeof(s)-p)); +} + +GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o) +{ + return tvisint(o) ? lj_str_fromint(L, intV(o)) : lj_str_fromnum(L, &o->n); +} + +/* -- String formatting --------------------------------------------------- */ + +static void addstr(lua_State *L, SBuf *sb, const char *str, MSize len) +{ + char *p; + MSize i; + if (sb->n + len > sb->sz) { + MSize sz = sb->sz * 2; + while (sb->n + len > sz) sz = sz * 2; + lj_str_resizebuf(L, sb, sz); + } + p = sb->buf + sb->n; + sb->n += len; + for (i = 0; i < len; i++) p[i] = str[i]; +} + +static void addchar(lua_State *L, SBuf *sb, int c) +{ + if (sb->n + 1 > sb->sz) { + MSize sz = sb->sz * 2; + lj_str_resizebuf(L, sb, sz); + } + sb->buf[sb->n++] = (char)c; +} + +/* Push formatted message as a string object to Lua stack. va_list variant. */ +const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp) +{ + SBuf *sb = &G(L)->tmpbuf; + lj_str_needbuf(L, sb, (MSize)strlen(fmt)); + lj_str_resetbuf(sb); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + addstr(L, sb, fmt, (MSize)(e-fmt)); + /* This function only handles %s, %c, %d, %f and %p formats. */ + switch (e[1]) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + addstr(L, sb, s, (MSize)strlen(s)); + break; + } + case 'c': + addchar(L, sb, va_arg(argp, int)); + break; + case 'd': { + char buf[LJ_STR_INTBUF]; + char *p = lj_str_bufint(buf, va_arg(argp, int32_t)); + addstr(L, sb, p, (MSize)(buf+LJ_STR_INTBUF-p)); + break; + } + case 'f': { + char buf[LJ_STR_NUMBUF]; + TValue tv; + MSize len; + tv.n = (lua_Number)(va_arg(argp, LUAI_UACNUMBER)); + len = (MSize)lj_str_bufnum(buf, &tv); + addstr(L, sb, buf, len); + break; + } + case 'p': { +#define FMTP_CHARS (2*sizeof(ptrdiff_t)) + char buf[2+FMTP_CHARS]; + ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *)); + ptrdiff_t i, lasti = 2+FMTP_CHARS; + if (p == 0) { + addstr(L, sb, "NULL", 4); + break; + } +#if LJ_64 + /* Shorten output for 64 bit pointers. */ + lasti = 2+2*4+((p >> 32) ? 2+2*(lj_fls((uint32_t)(p >> 32))>>3) : 0); +#endif + buf[0] = '0'; + buf[1] = 'x'; + for (i = lasti-1; i >= 2; i--, p >>= 4) + buf[i] = "0123456789abcdef"[(p & 15)]; + addstr(L, sb, buf, (MSize)lasti); + break; + } + case '%': + addchar(L, sb, '%'); + break; + default: + addchar(L, sb, '%'); + addchar(L, sb, e[1]); + break; + } + fmt = e+2; + } + addstr(L, sb, fmt, (MSize)strlen(fmt)); + setstrV(L, L->top, lj_str_new(L, sb->buf, sb->n)); + incr_top(L); + return strVdata(L->top - 1); +} + +/* Push formatted message as a string object to Lua stack. Vararg variant. */ +const char *lj_str_pushf(lua_State *L, const char *fmt, ...) +{ + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = lj_str_pushvf(L, fmt, argp); + va_end(argp); + return msg; +} + +/* -- Buffer handling ----------------------------------------------------- */ + +char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz) +{ + if (sz > sb->sz) { + if (sz < LJ_MIN_SBUF) sz = LJ_MIN_SBUF; + lj_str_resizebuf(L, sb, sz); + } + return sb->buf; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.h new file mode 100644 index 0000000..1602c98 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_str.h @@ -0,0 +1,50 @@ +/* +** String handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STR_H +#define _LJ_STR_H + +#include + +#include "lj_obj.h" + +/* String interning. */ +LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b); +LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask); +LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len); +LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s); + +#define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s))) +#define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1)) + +/* Type conversions. */ +LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o); +LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k); +LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np); +LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k); +LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o); + +#define LJ_STR_INTBUF (1+10) +#define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR + +/* String formatting. */ +LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp); +LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...) +#if defined(__GNUC__) + __attribute__ ((format (printf, 2, 3))) +#endif + ; + +/* Resizable string buffers. Struct definition in lj_obj.h. */ +LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz); + +#define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0) +#define lj_str_resetbuf(sb) ((sb)->n = 0) +#define lj_str_resizebuf(L, sb, size) \ + ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \ + (sb)->sz = (size)) +#define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz) + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.c new file mode 100644 index 0000000..a21c414 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.c @@ -0,0 +1,497 @@ +/* +** String scanning. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lj_strscan_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_char.h" +#include "lj_strscan.h" + +/* -- Scanning numbers ---------------------------------------------------- */ + +/* +** Rationale for the builtin string to number conversion library: +** +** It removes a dependency on libc's strtod(), which is a true portability +** nightmare. Mainly due to the plethora of supported OS and toolchain +** combinations. Sadly, the various implementations +** a) are often buggy, incomplete (no hex floats) and/or imprecise, +** b) sometimes crash or hang on certain inputs, +** c) return non-standard NaNs that need to be filtered out, and +** d) fail if the locale-specific decimal separator is not a dot, +** which can only be fixed with atrocious workarounds. +** +** Also, most of the strtod() implementations are hopelessly bloated, +** which is not just an I-cache hog, but a problem for static linkage +** on embedded systems, too. +** +** OTOH the builtin conversion function is very compact. Even though it +** does a lot more, like parsing long longs, octal or imaginary numbers +** and returning the result in different formats: +** a) It needs less than 3 KB (!) of machine code (on x64 with -Os), +** b) it doesn't perform any dynamic allocation and, +** c) it needs only around 600 bytes of stack space. +** +** The builtin function is faster than strtod() for typical inputs, e.g. +** "123", "1.5" or "1e6". Arguably, it's slower for very large exponents, +** which are not very common (this could be fixed, if needed). +** +** And most importantly, the builtin function is equally precise on all +** platforms. It correctly converts and rounds any input to a double. +** If this is not the case, please send a bug report -- but PLEASE verify +** that the implementation you're comparing to is not the culprit! +** +** The implementation quickly pre-scans the entire string first and +** handles simple integers on-the-fly. Otherwise, it dispatches to the +** base-specific parser. Hex and octal is straightforward. +** +** Decimal to binary conversion uses a fixed-length circular buffer in +** base 100. Some simple cases are handled directly. For other cases, the +** number in the buffer is up-scaled or down-scaled until the integer part +** is in the proper range. Then the integer part is rounded and converted +** to a double which is finally rescaled to the result. Denormals need +** special treatment to prevent incorrect 'double rounding'. +*/ + +/* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */ +#define STRSCAN_DIG 1024 +#define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ +#define STRSCAN_DDIG (STRSCAN_DIG/2) +#define STRSCAN_DMASK (STRSCAN_DDIG-1) + +/* Helpers for circular buffer. */ +#define DNEXT(a) (((a)+1) & STRSCAN_DMASK) +#define DPREV(a) (((a)-1) & STRSCAN_DMASK) +#define DLEN(lo, hi) ((int32_t)(((lo)-(hi)) & STRSCAN_DMASK)) + +#define casecmp(c, k) (((c) | 0x20) == k) + +/* Final conversion to double. */ +static void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg) +{ + double n; + + /* Avoid double rounding for denormals. */ + if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) { + /* NYI: all of this generates way too much code on 32 bit CPUs. */ +#if defined(__GNUC__) && LJ_64 + int32_t b = (int32_t)(__builtin_clzll(x)^63); +#else + int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) : + (int32_t)lj_fls((uint32_t)x); +#endif + if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) { + uint64_t rb = (uint64_t)1 << (-1075-ex2); + if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb; + x = (x & ~(rb+rb-1)); + } + } + + /* Convert to double using a signed int64_t conversion, then rescale. */ + lua_assert((int64_t)x >= 0); + n = (double)(int64_t)x; + if (neg) n = -n; + if (ex2) n = ldexp(n, ex2); + o->n = n; +} + +/* Parse hexadecimal number. */ +static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, + StrScanFmt fmt, uint32_t opt, + int32_t ex2, int32_t neg, uint32_t dig) +{ + uint64_t x = 0; + uint32_t i; + + /* Scan hex digits. */ + for (i = dig > 16 ? 16 : dig ; i; i--, p++) { + uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9; + x = (x << 4) + (d & 15); + } + + /* Summarize rounding-effect of excess digits. */ + for (i = 16; i < dig; i++, p++) + x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4; + + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_INT; /* Fast path for 32 bit integers. */ + } + if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } + /* fallthrough */ + case STRSCAN_U32: + if (dig > 8) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_U32; + case STRSCAN_I64: + case STRSCAN_U64: + if (dig > 16) return STRSCAN_ERROR; + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + return fmt; + default: + break; + } + + /* Reduce range then convert to double. */ + if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; } + strscan_double(x, o, ex2, neg); + return fmt; +} + +/* Parse octal number. */ +static StrScanFmt strscan_oct(const uint8_t *p, TValue *o, + StrScanFmt fmt, int32_t neg, uint32_t dig) +{ + uint64_t x = 0; + + /* Scan octal digits. */ + if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR; + while (dig-- > 0) { + if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR; + x = (x << 3) + (*p++ & 7); + } + + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (x >= 0x80000000u+neg) fmt = STRSCAN_U32; + /* fallthrough */ + case STRSCAN_U32: + if ((x >> 32)) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + break; + default: + case STRSCAN_I64: + case STRSCAN_U64: + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + break; + } + return fmt; +} + +/* Parse decimal number. */ +static StrScanFmt strscan_dec(const uint8_t *p, TValue *o, + StrScanFmt fmt, uint32_t opt, + int32_t ex10, int32_t neg, uint32_t dig) +{ + uint8_t xi[STRSCAN_DDIG], *xip = xi; + + if (dig) { + uint32_t i = dig; + if (i > STRSCAN_MAXDIG) { + ex10 += (int32_t)(i - STRSCAN_MAXDIG); + i = STRSCAN_MAXDIG; + } + /* Scan unaligned leading digit. */ + if (((ex10^i) & 1)) + *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++; + /* Scan aligned double-digits. */ + for ( ; i > 1; i -= 2) { + uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++; + *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++; + } + /* Scan and realign trailing digit. */ + if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, p++; + + /* Summarize rounding-effect of excess digits. */ + if (dig > STRSCAN_MAXDIG) { + do { + if ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; } + p++; + } while (--dig > STRSCAN_MAXDIG); + dig = STRSCAN_MAXDIG; + } else { /* Simplify exponent. */ + while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2; + } + } else { /* Only got zeros. */ + ex10 = 0; + xi[0] = 0; + } + + /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */ + if (dig <= 20 && ex10 == 0) { + uint8_t *xis; + uint64_t x = xi[0]; + double n; + for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis; + if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) { /* No overflow? */ + /* Format-specific handling. */ + switch (fmt) { + case STRSCAN_INT: + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_INT; /* Fast path for 32 bit integers. */ + } + if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; } + /* fallthrough */ + case STRSCAN_U32: + if ((x >> 32) != 0) return STRSCAN_ERROR; + o->i = neg ? -(int32_t)x : (int32_t)x; + return STRSCAN_U32; + case STRSCAN_I64: + case STRSCAN_U64: + o->u64 = neg ? (uint64_t)-(int64_t)x : x; + return fmt; + default: + plainnumber: /* Fast path for plain numbers < 2^63. */ + if ((int64_t)x < 0) break; + n = (double)(int64_t)x; + if (neg) n = -n; + o->n = n; + return fmt; + } + } + } + + /* Slow non-integer path. */ + if (fmt == STRSCAN_INT) { + if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR; + fmt = STRSCAN_NUM; + } else if (fmt > STRSCAN_INT) { + return STRSCAN_ERROR; + } + { + uint32_t hi = 0, lo = (uint32_t)(xip-xi); + int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1); + + lua_assert(lo > 0 && (ex10 & 1) == 0); + + /* Handle simple overflow/underflow. */ + if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; } + else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; } + + /* Scale up until we have at least 17 or 18 integer part digits. */ + while (idig < 9 && idig < DLEN(lo, hi)) { + uint32_t i, cy = 0; + ex2 -= 6; + for (i = DPREV(lo); ; i = DPREV(i)) { + uint32_t d = (xi[i] << 6) + cy; + cy = (((d >> 2) * 5243) >> 17); d = d - cy * 100; /* Div/mod 100. */ + xi[i] = (uint8_t)d; + if (i == hi) break; + if (d == 0 && i == DPREV(lo)) lo = i; + } + if (cy) { + hi = DPREV(hi); + if (xi[DPREV(lo)] == 0) lo = DPREV(lo); + else if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; } + xi[hi] = (uint8_t)cy; idig++; + } + } + + /* Scale down until no more than 17 or 18 integer part digits remain. */ + while (idig > 9) { + uint32_t i, cy = 0; + ex2 += 6; + for (i = hi; i != lo; i = DNEXT(i)) { + cy += xi[i]; + xi[i] = (cy >> 6); + cy = 100 * (cy & 0x3f); + if (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--; + } + while (cy) { + if (hi == lo) { xi[DPREV(lo)] |= 1; break; } + xi[lo] = (cy >> 6); lo = DNEXT(lo); + cy = 100 * (cy & 0x3f); + } + } + + /* Collect integer part digits and convert to rescaled double. */ + { + uint64_t x = xi[hi]; + uint32_t i; + for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i)) + x = x * 100 + xi[i]; + if (i == lo) { + while (--idig >= 0) x = x * 100; + } else { /* Gather round bit from remaining digits. */ + x <<= 1; ex2--; + do { + if (xi[i]) { x |= 1; break; } + i = DNEXT(i); + } while (i != lo); + } + strscan_double(x, o, ex2, neg); + } + } + return fmt; +} + +/* Scan string containing a number. Returns format. Returns value in o. */ +StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) +{ + int32_t neg = 0; + + /* Remove leading space, parse sign and non-numbers. */ + if (LJ_UNLIKELY(!lj_char_isdigit(*p))) { + while (lj_char_isspace(*p)) p++; + if (*p == '+' || *p == '-') neg = (*p++ == '-'); + if (LJ_UNLIKELY(*p >= 'A')) { /* Parse "inf", "infinity" or "nan". */ + TValue tmp; + setnanV(&tmp); + if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) { + if (neg) setminfV(&tmp); else setpinfV(&tmp); + p += 3; + if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') && + casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5; + } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) { + p += 3; + } + while (lj_char_isspace(*p)) p++; + if (*p) return STRSCAN_ERROR; + o->u64 = tmp.u64; + return STRSCAN_NUM; + } + } + + /* Parse regular number. */ + { + StrScanFmt fmt = STRSCAN_INT; + int cmask = LJ_CHAR_DIGIT; + int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10; + const uint8_t *sp, *dp = NULL; + uint32_t dig = 0, hasdig = 0, x = 0; + int32_t ex = 0; + + /* Determine base and skip leading zeros. */ + if (LJ_UNLIKELY(*p <= '0')) { + if (*p == '0' && casecmp(p[1], 'x')) + base = 16, cmask = LJ_CHAR_XDIGIT, p += 2; + for ( ; ; p++) { + if (*p == '0') { + hasdig = 1; + } else if (*p == '.') { + if (dp) return STRSCAN_ERROR; + dp = p; + } else { + break; + } + } + } + + /* Preliminary digit and decimal point scan. */ + for (sp = p; ; p++) { + if (LJ_LIKELY(lj_char_isa(*p, cmask))) { + x = x * 10 + (*p & 15); /* For fast path below. */ + dig++; + } else if (*p == '.') { + if (dp) return STRSCAN_ERROR; + dp = p; + } else { + break; + } + } + if (!(hasdig | dig)) return STRSCAN_ERROR; + + /* Handle decimal point. */ + if (dp) { + fmt = STRSCAN_NUM; + if (dig) { + ex = (int32_t)(dp-(p-1)); dp = p-1; + while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ + if (base == 16) ex *= 4; + } + } + + /* Parse exponent. */ + if (casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) { + uint32_t xx; + int negx = 0; + fmt = STRSCAN_NUM; p++; + if (*p == '+' || *p == '-') negx = (*p++ == '-'); + if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; + xx = (*p++ & 15); + while (lj_char_isdigit(*p)) { + if (xx < 65536) xx = xx * 10 + (*p & 15); + p++; + } + ex += negx ? -(int32_t)xx : (int32_t)xx; + } + + /* Parse suffix. */ + if (*p) { + /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */ + /* NYI: f (float). Not needed until cp_number() handles non-integers. */ + if (casecmp(*p, 'i')) { + if (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR; + p++; fmt = STRSCAN_IMAG; + } else if (fmt == STRSCAN_INT) { + if (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32; + if (casecmp(*p, 'l')) { + p++; + if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT; + else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR; + else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT; + } + if (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64)) + p++, fmt += STRSCAN_U32 - STRSCAN_INT; + if ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) || + (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL))) + return STRSCAN_ERROR; + } + while (lj_char_isspace(*p)) p++; + if (*p) return STRSCAN_ERROR; + } + + /* Fast path for decimal 32 bit integers. */ + if (fmt == STRSCAN_INT && base == 10 && + (dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) { + int32_t y = neg ? -(int32_t)x : (int32_t)x; + if ((opt & STRSCAN_OPT_TONUM)) { + o->n = (double)y; + return STRSCAN_NUM; + } else { + o->i = y; + return STRSCAN_INT; + } + } + + /* Dispatch to base-specific parser. */ + if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG)) + return strscan_oct(sp, o, fmt, neg, dig); + if (base == 16) + fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig); + else + fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); + + /* Try to convert number to integer, if requested. */ + if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { + double n = o->n; + int32_t i = lj_num2int(n); + if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } + } + return fmt; + } +} + +int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o) +{ + StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, + STRSCAN_OPT_TONUM); + lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM); + return (fmt != STRSCAN_ERROR); +} + +#if LJ_DUALNUM +int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o) +{ + StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, + STRSCAN_OPT_TOINT); + lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT); + if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM); + return (fmt != STRSCAN_ERROR); +} +#endif + +#undef DNEXT +#undef DPREV +#undef DLEN + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.h new file mode 100644 index 0000000..15abd6a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_strscan.h @@ -0,0 +1,39 @@ +/* +** String scanning. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_STRSCAN_H +#define _LJ_STRSCAN_H + +#include "lj_obj.h" + +/* Options for accepted/returned formats. */ +#define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */ +#define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */ +#define STRSCAN_OPT_IMAG 0x04 +#define STRSCAN_OPT_LL 0x08 +#define STRSCAN_OPT_C 0x10 + +/* Returned format. */ +typedef enum { + STRSCAN_ERROR, + STRSCAN_NUM, STRSCAN_IMAG, + STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64, +} StrScanFmt; + +LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt); +LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o); +#if LJ_DUALNUM +LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o); +#else +#define lj_strscan_number(s, o) lj_strscan_num((s), (o)) +#endif + +/* Check for number or convert string to number/int in-place (!). */ +static LJ_AINLINE int lj_strscan_numberobj(TValue *o) +{ + return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o)); +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.c new file mode 100644 index 0000000..fc7d0f1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.c @@ -0,0 +1,631 @@ +/* +** Table handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#define lj_tab_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_tab.h" + +/* -- Object hashing ------------------------------------------------------ */ + +/* Hash values are masked with the table hash mask and used as an index. */ +static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) +{ + Node *n = noderef(t->node); + return &n[hash & t->hmask]; +} + +/* String hashes are precomputed when they are interned. */ +#define hashstr(t, s) hashmask(t, (s)->hash) + +#define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi))) +#define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1)) +#define hashptr(t, p) hashlohi((t), u32ptr(p), u32ptr(p) + HASH_BIAS) +#define hashgcref(t, r) hashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS) + +/* Hash an arbitrary key and return its anchor position in the hash table. */ +static Node *hashkey(const GCtab *t, cTValue *key) +{ + lua_assert(!tvisint(key)); + if (tvisstr(key)) + return hashstr(t, strV(key)); + else if (tvisnum(key)) + return hashnum(t, key); + else if (tvisbool(key)) + return hashmask(t, boolV(key)); + else + return hashgcref(t, key->gcr); + /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */ +} + +/* -- Table creation and destruction -------------------------------------- */ + +/* Create new hash part for table. */ +static LJ_AINLINE void newhpart(lua_State *L, GCtab *t, uint32_t hbits) +{ + uint32_t hsize; + Node *node; + lua_assert(hbits != 0); + if (hbits > LJ_MAX_HBITS) + lj_err_msg(L, LJ_ERR_TABOV); + hsize = 1u << hbits; + node = lj_mem_newvec(L, hsize, Node); + setmref(node->freetop, &node[hsize]); + setmref(t->node, node); + t->hmask = hsize-1; +} + +/* +** Q: Why all of these copies of t->hmask, t->node etc. to local variables? +** A: Because alias analysis for C is _really_ tough. +** Even state-of-the-art C compilers won't produce good code without this. +*/ + +/* Clear hash part of table. */ +static LJ_AINLINE void clearhpart(GCtab *t) +{ + uint32_t i, hmask = t->hmask; + Node *node = noderef(t->node); + lua_assert(t->hmask != 0); + for (i = 0; i <= hmask; i++) { + Node *n = &node[i]; + setmref(n->next, NULL); + setnilV(&n->key); + setnilV(&n->val); + } +} + +/* Clear array part of table. */ +static LJ_AINLINE void clearapart(GCtab *t) +{ + uint32_t i, asize = t->asize; + TValue *array = tvref(t->array); + for (i = 0; i < asize; i++) + setnilV(&array[i]); +} + +/* Create a new table. Note: the slots are not initialized (yet). */ +static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits) +{ + GCtab *t; + /* First try to colocate the array part. */ + if (LJ_MAX_COLOSIZE != 0 && asize > 0 && asize <= LJ_MAX_COLOSIZE) { + lua_assert((sizeof(GCtab) & 7) == 0); + t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize)); + t->gct = ~LJ_TTAB; + t->nomm = (uint8_t)~0; + t->colo = (int8_t)asize; + setmref(t->array, (TValue *)((char *)t + sizeof(GCtab))); + setgcrefnull(t->metatable); + t->asize = asize; + t->hmask = 0; + setmref(t->node, &G(L)->nilnode); + } else { /* Otherwise separately allocate the array part. */ + t = lj_mem_newobj(L, GCtab); + t->gct = ~LJ_TTAB; + t->nomm = (uint8_t)~0; + t->colo = 0; + setmref(t->array, NULL); + setgcrefnull(t->metatable); + t->asize = 0; /* In case the array allocation fails. */ + t->hmask = 0; + setmref(t->node, &G(L)->nilnode); + if (asize > 0) { + if (asize > LJ_MAX_ASIZE) + lj_err_msg(L, LJ_ERR_TABOV); + setmref(t->array, lj_mem_newvec(L, asize, TValue)); + t->asize = asize; + } + } + if (hbits) + newhpart(L, t, hbits); + return t; +} + +/* Create a new table. +** +** IMPORTANT NOTE: The API differs from lua_createtable()! +** +** The array size is non-inclusive. E.g. asize=128 creates array slots +** for 0..127, but not for 128. If you need slots 1..128, pass asize=129 +** (slot 0 is wasted in this case). +** +** The hash size is given in hash bits. hbits=0 means no hash part. +** hbits=1 creates 2 hash slots, hbits=2 creates 4 hash slots and so on. +*/ +GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits) +{ + GCtab *t = newtab(L, asize, hbits); + clearapart(t); + if (t->hmask > 0) clearhpart(t); + return t; +} + +#if LJ_HASJIT +GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize) +{ + GCtab *t = newtab(L, ahsize & 0xffffff, ahsize >> 24); + clearapart(t); + if (t->hmask > 0) clearhpart(t); + return t; +} +#endif + +/* Duplicate a table. */ +GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt) +{ + GCtab *t; + uint32_t asize, hmask; + t = newtab(L, kt->asize, kt->hmask > 0 ? lj_fls(kt->hmask)+1 : 0); + lua_assert(kt->asize == t->asize && kt->hmask == t->hmask); + t->nomm = 0; /* Keys with metamethod names may be present. */ + asize = kt->asize; + if (asize > 0) { + TValue *array = tvref(t->array); + TValue *karray = tvref(kt->array); + if (asize < 64) { /* An inlined loop beats memcpy for < 512 bytes. */ + uint32_t i; + for (i = 0; i < asize; i++) + copyTV(L, &array[i], &karray[i]); + } else { + memcpy(array, karray, asize*sizeof(TValue)); + } + } + hmask = kt->hmask; + if (hmask > 0) { + uint32_t i; + Node *node = noderef(t->node); + Node *knode = noderef(kt->node); + ptrdiff_t d = (char *)node - (char *)knode; + setmref(node->freetop, (Node *)((char *)noderef(knode->freetop) + d)); + for (i = 0; i <= hmask; i++) { + Node *kn = &knode[i]; + Node *n = &node[i]; + Node *next = nextnode(kn); + /* Don't use copyTV here, since it asserts on a copy of a dead key. */ + n->val = kn->val; n->key = kn->key; + setmref(n->next, next == NULL? next : (Node *)((char *)next + d)); + } + } + return t; +} + +/* Free a table. */ +void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t) +{ + if (t->hmask > 0) + lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node); + if (t->asize > 0 && LJ_MAX_COLOSIZE != 0 && t->colo <= 0) + lj_mem_freevec(g, tvref(t->array), t->asize, TValue); + if (LJ_MAX_COLOSIZE != 0 && t->colo) + lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f)); + else + lj_mem_freet(g, t); +} + +/* -- Table resizing ------------------------------------------------------ */ + +/* Resize a table to fit the new array/hash part sizes. */ +static void resizetab(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits) +{ + Node *oldnode = noderef(t->node); + uint32_t oldasize = t->asize; + uint32_t oldhmask = t->hmask; + if (asize > oldasize) { /* Array part grows? */ + TValue *array; + uint32_t i; + if (asize > LJ_MAX_ASIZE) + lj_err_msg(L, LJ_ERR_TABOV); + if (LJ_MAX_COLOSIZE != 0 && t->colo > 0) { + /* A colocated array must be separated and copied. */ + TValue *oarray = tvref(t->array); + array = lj_mem_newvec(L, asize, TValue); + t->colo = (int8_t)(t->colo | 0x80); /* Mark as separated (colo < 0). */ + for (i = 0; i < oldasize; i++) + copyTV(L, &array[i], &oarray[i]); + } else { + array = (TValue *)lj_mem_realloc(L, tvref(t->array), + oldasize*sizeof(TValue), asize*sizeof(TValue)); + } + setmref(t->array, array); + t->asize = asize; + for (i = oldasize; i < asize; i++) /* Clear newly allocated slots. */ + setnilV(&array[i]); + } + /* Create new (empty) hash part. */ + if (hbits) { + newhpart(L, t, hbits); + clearhpart(t); + } else { + global_State *g = G(L); + setmref(t->node, &g->nilnode); + t->hmask = 0; + } + if (asize < oldasize) { /* Array part shrinks? */ + TValue *array = tvref(t->array); + uint32_t i; + t->asize = asize; /* Note: This 'shrinks' even colocated arrays. */ + for (i = asize; i < oldasize; i++) /* Reinsert old array values. */ + if (!tvisnil(&array[i])) + copyTV(L, lj_tab_setinth(L, t, (int32_t)i), &array[i]); + /* Physically shrink only separated arrays. */ + if (LJ_MAX_COLOSIZE != 0 && t->colo <= 0) + setmref(t->array, lj_mem_realloc(L, array, + oldasize*sizeof(TValue), asize*sizeof(TValue))); + } + if (oldhmask > 0) { /* Reinsert pairs from old hash part. */ + global_State *g; + uint32_t i; + for (i = 0; i <= oldhmask; i++) { + Node *n = &oldnode[i]; + if (!tvisnil(&n->val)) + copyTV(L, lj_tab_set(L, t, &n->key), &n->val); + } + g = G(L); + lj_mem_freevec(g, oldnode, oldhmask+1, Node); + } +} + +static uint32_t countint(cTValue *key, uint32_t *bins) +{ + lua_assert(!tvisint(key)); + if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if ((uint32_t)k < LJ_MAX_ASIZE && nk == (lua_Number)k) { + bins[(k > 2 ? lj_fls((uint32_t)(k-1)) : 0)]++; + return 1; + } + } + return 0; +} + +static uint32_t countarray(const GCtab *t, uint32_t *bins) +{ + uint32_t na, b, i; + if (t->asize == 0) return 0; + for (na = i = b = 0; b < LJ_MAX_ABITS; b++) { + uint32_t n, top = 2u << b; + TValue *array; + if (top >= t->asize) { + top = t->asize-1; + if (i > top) + break; + } + array = tvref(t->array); + for (n = 0; i <= top; i++) + if (!tvisnil(&array[i])) + n++; + bins[b] += n; + na += n; + } + return na; +} + +static uint32_t counthash(const GCtab *t, uint32_t *bins, uint32_t *narray) +{ + uint32_t total, na, i, hmask = t->hmask; + Node *node = noderef(t->node); + for (total = na = 0, i = 0; i <= hmask; i++) { + Node *n = &node[i]; + if (!tvisnil(&n->val)) { + na += countint(&n->key, bins); + total++; + } + } + *narray += na; + return total; +} + +static uint32_t bestasize(uint32_t bins[], uint32_t *narray) +{ + uint32_t b, sum, na = 0, sz = 0, nn = *narray; + for (b = 0, sum = 0; 2*nn > (1u< 0 && 2*(sum += bins[b]) > (1u<hmask > 0 ? lj_fls(t->hmask)+1 : 0); +} + +/* -- Table getters ------------------------------------------------------- */ + +cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key) +{ + TValue k; + Node *n; + k.n = (lua_Number)key; + n = hashnum(t, &k); + do { + if (tvisnum(&n->key) && n->key.n == k.n) + return &n->val; + } while ((n = nextnode(n))); + return NULL; +} + +cTValue *lj_tab_getstr(GCtab *t, GCstr *key) +{ + Node *n = hashstr(t, key); + do { + if (tvisstr(&n->key) && strV(&n->key) == key) + return &n->val; + } while ((n = nextnode(n))); + return NULL; +} + +cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key) +{ + if (tvisstr(key)) { + cTValue *tv = lj_tab_getstr(t, strV(key)); + if (tv) + return tv; + } else if (tvisint(key)) { + cTValue *tv = lj_tab_getint(t, intV(key)); + if (tv) + return tv; + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if (nk == (lua_Number)k) { + cTValue *tv = lj_tab_getint(t, k); + if (tv) + return tv; + } else { + goto genlookup; /* Else use the generic lookup. */ + } + } else if (!tvisnil(key)) { + Node *n; + genlookup: + n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return &n->val; + } while ((n = nextnode(n))); + } + return niltv(L); +} + +/* -- Table setters ------------------------------------------------------- */ + +/* Insert new key. Use Brent's variation to optimize the chain length. */ +TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key) +{ + Node *n = hashkey(t, key); + if (!tvisnil(&n->val) || t->hmask == 0) { + Node *nodebase = noderef(t->node); + Node *collide, *freenode = noderef(nodebase->freetop); + lua_assert(freenode >= nodebase && freenode <= nodebase+t->hmask+1); + do { + if (freenode == nodebase) { /* No free node found? */ + rehashtab(L, t, key); /* Rehash table. */ + return lj_tab_set(L, t, key); /* Retry key insertion. */ + } + } while (!tvisnil(&(--freenode)->key)); + setmref(nodebase->freetop, freenode); + lua_assert(freenode != &G(L)->nilnode); + collide = hashkey(t, &n->key); + if (collide != n) { /* Colliding node not the main node? */ + while (noderef(collide->next) != n) /* Find predecessor. */ + collide = nextnode(collide); + setmref(collide->next, freenode); /* Relink chain. */ + /* Copy colliding node into free node and free main node. */ + freenode->val = n->val; + freenode->key = n->key; + freenode->next = n->next; + setmref(n->next, NULL); + setnilV(&n->val); + /* Rechain pseudo-resurrected string keys with colliding hashes. */ + while (nextnode(freenode)) { + Node *nn = nextnode(freenode); + if (tvisstr(&nn->key) && !tvisnil(&nn->val) && + hashstr(t, strV(&nn->key)) == n) { + freenode->next = nn->next; + nn->next = n->next; + setmref(n->next, nn); + } else { + freenode = nn; + } + } + } else { /* Otherwise use free node. */ + setmrefr(freenode->next, n->next); /* Insert into chain. */ + setmref(n->next, freenode); + n = freenode; + } + } + n->key.u64 = key->u64; + if (LJ_UNLIKELY(tvismzero(&n->key))) + n->key.u64 = 0; + lj_gc_anybarriert(L, t); + lua_assert(tvisnil(&n->val)); + return &n->val; +} + +TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key) +{ + TValue k; + Node *n; + k.n = (lua_Number)key; + n = hashnum(t, &k); + do { + if (tvisnum(&n->key) && n->key.n == k.n) + return &n->val; + } while ((n = nextnode(n))); + return lj_tab_newkey(L, t, &k); +} + +TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key) +{ + TValue k; + Node *n = hashstr(t, key); + do { + if (tvisstr(&n->key) && strV(&n->key) == key) + return &n->val; + } while ((n = nextnode(n))); + setstrV(L, &k, key); + return lj_tab_newkey(L, t, &k); +} + +TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key) +{ + Node *n; + t->nomm = 0; /* Invalidate negative metamethod cache. */ + if (tvisstr(key)) { + return lj_tab_setstr(L, t, strV(key)); + } else if (tvisint(key)) { + return lj_tab_setint(L, t, intV(key)); + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if (nk == (lua_Number)k) + return lj_tab_setint(L, t, k); + if (tvisnan(key)) + lj_err_msg(L, LJ_ERR_NANIDX); + /* Else use the generic lookup. */ + } else if (tvisnil(key)) { + lj_err_msg(L, LJ_ERR_NILIDX); + } + n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return &n->val; + } while ((n = nextnode(n))); + return lj_tab_newkey(L, t, key); +} + +/* -- Table traversal ----------------------------------------------------- */ + +/* Get the traversal index of a key. */ +static uint32_t keyindex(lua_State *L, GCtab *t, cTValue *key) +{ + TValue tmp; + if (tvisint(key)) { + int32_t k = intV(key); + if ((uint32_t)k < t->asize) + return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */ + setnumV(&tmp, (lua_Number)k); + key = &tmp; + } else if (tvisnum(key)) { + lua_Number nk = numV(key); + int32_t k = lj_num2int(nk); + if ((uint32_t)k < t->asize && nk == (lua_Number)k) + return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */ + } + if (!tvisnil(key)) { + Node *n = hashkey(t, key); + do { + if (lj_obj_equal(&n->key, key)) + return t->asize + (uint32_t)(n - noderef(t->node)); + /* Hash key indexes: [t->asize..t->asize+t->nmask] */ + } while ((n = nextnode(n))); + if (key->u32.hi == 0xfffe7fff) /* ITERN was despecialized while running. */ + return key->u32.lo - 1; + lj_err_msg(L, LJ_ERR_NEXTIDX); + return 0; /* unreachable */ + } + return ~0u; /* A nil key starts the traversal. */ +} + +/* Advance to the next step in a table traversal. */ +int lj_tab_next(lua_State *L, GCtab *t, TValue *key) +{ + uint32_t i = keyindex(L, t, key); /* Find predecessor key index. */ + for (i++; i < t->asize; i++) /* First traverse the array keys. */ + if (!tvisnil(arrayslot(t, i))) { + setintV(key, i); + copyTV(L, key+1, arrayslot(t, i)); + return 1; + } + for (i -= t->asize; i <= t->hmask; i++) { /* Then traverse the hash keys. */ + Node *n = &noderef(t->node)[i]; + if (!tvisnil(&n->val)) { + copyTV(L, key, &n->key); + copyTV(L, key+1, &n->val); + return 1; + } + } + return 0; /* End of traversal. */ +} + +/* -- Table length calculation -------------------------------------------- */ + +static MSize unbound_search(GCtab *t, MSize j) +{ + cTValue *tv; + MSize i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while ((tv = lj_tab_getint(t, (int32_t)j)) && !tvisnil(tv)) { + i = j; + j *= 2; + if (j > (MSize)(INT_MAX-2)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while ((tv = lj_tab_getint(t, (int32_t)i)) && !tvisnil(tv)) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + MSize m = (i+j)/2; + cTValue *tvb = lj_tab_getint(t, (int32_t)m); + if (tvb && !tvisnil(tvb)) i = m; else j = m; + } + return i; +} + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +MSize LJ_FASTCALL lj_tab_len(GCtab *t) +{ + MSize j = (MSize)t->asize; + if (j > 1 && tvisnil(arrayslot(t, j-1))) { + MSize i = 1; + while (j - i > 1) { + MSize m = (i+j)/2; + if (tvisnil(arrayslot(t, m-1))) j = m; else i = m; + } + return i-1; + } + if (j) j--; + if (t->hmask <= 0) + return j; + return unbound_search(t, j); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.h new file mode 100644 index 0000000..44b1bbb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_tab.h @@ -0,0 +1,70 @@ +/* +** Table handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TAB_H +#define _LJ_TAB_H + +#include "lj_obj.h" + +/* Hash constants. Tuned using a brute force search. */ +#define HASH_BIAS (-0x04c11db7) +#define HASH_ROT1 14 +#define HASH_ROT2 5 +#define HASH_ROT3 13 + +/* Scramble the bits of numbers and pointers. */ +static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi) +{ +#if LJ_TARGET_X86ORX64 + /* Prefer variant that compiles well for a 2-operand CPU. */ + lo ^= hi; hi = lj_rol(hi, HASH_ROT1); + lo -= hi; hi = lj_rol(hi, HASH_ROT2); + hi ^= lo; hi -= lj_rol(lo, HASH_ROT3); +#else + lo ^= hi; + lo = lo - lj_rol(hi, HASH_ROT1); + hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2); + hi = hi - lj_rol(lo, HASH_ROT3); +#endif + return hi; +} + +#define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) + +LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits); +#if LJ_HASJIT +LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize); +#endif +LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt); +LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t); +#if LJ_HASFFI +LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t); +#endif +LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize); + +/* Caveat: all getters except lj_tab_get() can return NULL! */ + +LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key); +LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key); +LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key); + +/* Caveat: all setters require a write barrier for the stored value. */ + +LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key); +LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key); +LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key); +LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); + +#define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize) +#define arrayslot(t, i) (&tvref((t)->array)[(i)]) +#define lj_tab_getint(t, key) \ + (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key))) +#define lj_tab_setint(L, t, key) \ + (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key))) + +LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key); +LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target.h new file mode 100644 index 0000000..820a97a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target.h @@ -0,0 +1,162 @@ +/* +** Definitions for target CPU. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_H +#define _LJ_TARGET_H + +#include "lj_def.h" +#include "lj_arch.h" + +/* -- Registers and spill slots ------------------------------------------- */ + +/* Register type (uint8_t in ir->r). */ +typedef uint32_t Reg; + +/* The hi-bit is NOT set for an allocated register. This means the value +** can be directly used without masking. The hi-bit is set for a register +** allocation hint or for RID_INIT, RID_SINK or RID_SUNK. +*/ +#define RID_NONE 0x80 +#define RID_MASK 0x7f +#define RID_INIT (RID_NONE|RID_MASK) +#define RID_SINK (RID_INIT-1) +#define RID_SUNK (RID_INIT-2) + +#define ra_noreg(r) ((r) & RID_NONE) +#define ra_hasreg(r) (!((r) & RID_NONE)) + +/* The ra_hashint() macro assumes a previous test for ra_noreg(). */ +#define ra_hashint(r) ((r) < RID_SUNK) +#define ra_gethint(r) ((Reg)((r) & RID_MASK)) +#define ra_sethint(rr, r) rr = (uint8_t)((r)|RID_NONE) +#define ra_samehint(r1, r2) (ra_gethint((r1)^(r2)) == 0) + +/* Spill slot 0 means no spill slot has been allocated. */ +#define SPS_NONE 0 + +#define ra_hasspill(s) ((s) != SPS_NONE) + +/* Combined register and spill slot (uint16_t in ir->prev). */ +typedef uint32_t RegSP; + +#define REGSP(r, s) ((r) + ((s) << 8)) +#define REGSP_HINT(r) ((r)|RID_NONE) +#define REGSP_INIT REGSP(RID_INIT, 0) + +#define regsp_reg(rs) ((rs) & 255) +#define regsp_spill(rs) ((rs) >> 8) +#define regsp_used(rs) \ + (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0)) + +/* -- Register sets ------------------------------------------------------- */ + +/* Bitset for registers. 32 registers suffice for most architectures. +** Note that one set holds bits for both GPRs and FPRs. +*/ +#if LJ_TARGET_PPC || LJ_TARGET_MIPS +typedef uint64_t RegSet; +#else +typedef uint32_t RegSet; +#endif + +#define RID2RSET(r) (((RegSet)1) << (r)) +#define RSET_EMPTY ((RegSet)0) +#define RSET_RANGE(lo, hi) ((RID2RSET((hi)-(lo))-1) << (lo)) + +#define rset_test(rs, r) ((int)((rs) >> (r)) & 1) +#define rset_set(rs, r) (rs |= RID2RSET(r)) +#define rset_clear(rs, r) (rs &= ~RID2RSET(r)) +#define rset_exclude(rs, r) (rs & ~RID2RSET(r)) +#if LJ_TARGET_PPC || LJ_TARGET_MIPS +#define rset_picktop(rs) ((Reg)(__builtin_clzll(rs)^63)) +#define rset_pickbot(rs) ((Reg)__builtin_ctzll(rs)) +#else +#define rset_picktop(rs) ((Reg)lj_fls(rs)) +#define rset_pickbot(rs) ((Reg)lj_ffs(rs)) +#endif + +/* -- Register allocation cost -------------------------------------------- */ + +/* The register allocation heuristic keeps track of the cost for allocating +** a specific register: +** +** A free register (obviously) has a cost of 0 and a 1-bit in the free mask. +** +** An already allocated register has the (non-zero) IR reference in the lowest +** bits and the result of a blended cost-model in the higher bits. +** +** The allocator first checks the free mask for a hit. Otherwise an (unrolled) +** linear search for the minimum cost is used. The search doesn't need to +** keep track of the position of the minimum, which makes it very fast. +** The lowest bits of the minimum cost show the desired IR reference whose +** register is the one to evict. +** +** Without the cost-model this degenerates to the standard heuristics for +** (reverse) linear-scan register allocation. Since code generation is done +** in reverse, a live interval extends from the last use to the first def. +** For an SSA IR the IR reference is the first (and only) def and thus +** trivially marks the end of the interval. The LSRA heuristics says to pick +** the register whose live interval has the furthest extent, i.e. the lowest +** IR reference in our case. +** +** A cost-model should take into account other factors, like spill-cost and +** restore- or rematerialization-cost, which depend on the kind of instruction. +** E.g. constants have zero spill costs, variant instructions have higher +** costs than invariants and PHIs should preferably never be spilled. +** +** Here's a first cut at simple, but effective blended cost-model for R-LSRA: +** - Due to careful design of the IR, constants already have lower IR +** references than invariants and invariants have lower IR references +** than variants. +** - The cost in the upper 16 bits is the sum of the IR reference and a +** weighted score. The score currently only takes into account whether +** the IRT_ISPHI bit is set in the instruction type. +** - The PHI weight is the minimum distance (in IR instructions) a PHI +** reference has to be further apart from a non-PHI reference to be spilled. +** - It should be a power of two (for speed) and must be between 2 and 32768. +** Good values for the PHI weight seem to be between 40 and 150. +** - Further study is required. +*/ +#define REGCOST_PHI_WEIGHT 64 + +/* Cost for allocating a specific register. */ +typedef uint32_t RegCost; + +/* Note: assumes 16 bit IRRef1. */ +#define REGCOST(cost, ref) ((RegCost)(ref) + ((RegCost)(cost) << 16)) +#define regcost_ref(rc) ((IRRef1)(rc)) + +#define REGCOST_T(t) \ + ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI)) +#define REGCOST_REF_T(ref, t) (REGCOST((ref), (ref)) + REGCOST_T((t))) + +/* -- Target-specific definitions ----------------------------------------- */ + +#if LJ_TARGET_X86ORX64 +#include "lj_target_x86.h" +#elif LJ_TARGET_ARM +#include "lj_target_arm.h" +#elif LJ_TARGET_PPC +#include "lj_target_ppc.h" +#elif LJ_TARGET_MIPS +#include "lj_target_mips.h" +#else +#error "Missing include for target CPU" +#endif + +#ifdef EXITSTUBS_PER_GROUP +/* Return the address of an exit stub. */ +static LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno) +{ + lua_assert(group[exitno / EXITSTUBS_PER_GROUP] != NULL); + return (char *)group[exitno / EXITSTUBS_PER_GROUP] + + EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP); +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_addr(J, exitno) \ + ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno))) +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_arm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_arm.h new file mode 100644 index 0000000..63a0c92 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_arm.h @@ -0,0 +1,274 @@ +/* +** Definitions for ARM CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_ARM_H +#define _LJ_TARGET_ARM_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC) +#if LJ_SOFTFP +#define FPRDEF(_) +#else +#define FPRDEF(_) \ + _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \ + _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15) +#endif +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_TMP = RID_LR, + + /* Calling conventions. */ + RID_RET = RID_R0, + RID_RETLO = RID_R0, + RID_RETHI = RID_R1, +#if LJ_SOFTFP + RID_FPRET = RID_R0, +#else + RID_FPRET = RID_D0, +#endif + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R9, /* Interpreter BASE. */ + RID_LPC = RID_R6, /* Interpreter PC. */ + RID_DISPATCH = RID_R7, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R8, /* Interpreter L. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_PC+1, + RID_MIN_FPR = RID_MAX_GPR, +#if LJ_SOFTFP + RID_MAX_FPR = RID_MIN_FPR, +#else + RID_MAX_FPR = RID_D15+1, +#endif + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except sp, lr and pc. */ +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_R12+1)) +#define RSET_GPREVEN \ + (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \ + RID2RSET(RID_R8)|RID2RSET(RID_R10)) +#define RSET_GPRODD \ + (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \ + RID2RSET(RID_R9)|RID2RSET(RID_R11)) +#if LJ_SOFTFP +#define RSET_FPR 0 +#else +#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)) +#endif +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +/* ABI-specific register sets. lr is an implicit scratch register. */ +#define RSET_SCRATCH_GPR_ (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12)) +#ifdef __APPLE__ +#define RSET_SCRATCH_GPR (RSET_SCRATCH_GPR_|RID2RSET(RID_R9)) +#else +#define RSET_SCRATCH_GPR RSET_SCRATCH_GPR_ +#endif +#if LJ_SOFTFP +#define RSET_SCRATCH_FPR 0 +#else +#define RSET_SCRATCH_FPR (RSET_RANGE(RID_D0, RID_D7+1)) +#endif +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R0 +#define REGARG_LASTGPR RID_R3 +#define REGARG_NUMGPR 4 +#if LJ_ABI_SOFTFP +#define REGARG_FIRSTFPR 0 +#define REGARG_LASTFPR 0 +#define REGARG_NUMFPR 0 +#else +#define REGARG_FIRSTFPR RID_D0 +#define REGARG_LASTFPR RID_D7 +#define REGARG_NUMFPR 8 +#endif + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. +*/ +#define SPS_FIXED 2 +#define SPS_FIRST 2 + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { +#if !LJ_SOFTFP + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ +#endif + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* PC after instruction that caused an exit. Used to find the trace number. */ +#define EXITSTATE_PCREG RID_PC +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +#define EXITSTUB_SPACING 4 +#define EXITSTUBS_PER_GROUP 32 + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define ARMF_CC(ai, cc) (((ai) ^ ARMI_CCAL) | ((cc) << 28)) +#define ARMF_N(r) ((r) << 16) +#define ARMF_D(r) ((r) << 12) +#define ARMF_S(r) ((r) << 8) +#define ARMF_M(r) (r) +#define ARMF_SH(sh, n) (((sh) << 5) | ((n) << 7)) +#define ARMF_RSH(sh, r) (0x10 | ((sh) << 5) | ARMF_S(r)) + +typedef enum ARMIns { + ARMI_CCAL = 0xe0000000, + ARMI_S = 0x000100000, + ARMI_K12 = 0x02000000, + ARMI_KNEG = 0x00200000, + ARMI_LS_W = 0x00200000, + ARMI_LS_U = 0x00800000, + ARMI_LS_P = 0x01000000, + ARMI_LS_R = 0x02000000, + ARMI_LSX_I = 0x00400000, + + ARMI_AND = 0xe0000000, + ARMI_EOR = 0xe0200000, + ARMI_SUB = 0xe0400000, + ARMI_RSB = 0xe0600000, + ARMI_ADD = 0xe0800000, + ARMI_ADC = 0xe0a00000, + ARMI_SBC = 0xe0c00000, + ARMI_RSC = 0xe0e00000, + ARMI_TST = 0xe1100000, + ARMI_TEQ = 0xe1300000, + ARMI_CMP = 0xe1500000, + ARMI_CMN = 0xe1700000, + ARMI_ORR = 0xe1800000, + ARMI_MOV = 0xe1a00000, + ARMI_BIC = 0xe1c00000, + ARMI_MVN = 0xe1e00000, + + ARMI_NOP = 0xe1a00000, + + ARMI_MUL = 0xe0000090, + ARMI_SMULL = 0xe0c00090, + + ARMI_LDR = 0xe4100000, + ARMI_LDRB = 0xe4500000, + ARMI_LDRH = 0xe01000b0, + ARMI_LDRSB = 0xe01000d0, + ARMI_LDRSH = 0xe01000f0, + ARMI_LDRD = 0xe00000d0, + ARMI_STR = 0xe4000000, + ARMI_STRB = 0xe4400000, + ARMI_STRH = 0xe00000b0, + ARMI_STRD = 0xe00000f0, + ARMI_PUSH = 0xe92d0000, + + ARMI_B = 0xea000000, + ARMI_BL = 0xeb000000, + ARMI_BLX = 0xfa000000, + ARMI_BLXr = 0xe12fff30, + + /* ARMv6 */ + ARMI_REV = 0xe6bf0f30, + ARMI_SXTB = 0xe6af0070, + ARMI_SXTH = 0xe6bf0070, + ARMI_UXTB = 0xe6ef0070, + ARMI_UXTH = 0xe6ff0070, + + /* ARMv6T2 */ + ARMI_MOVW = 0xe3000000, + ARMI_MOVT = 0xe3400000, + + /* VFP */ + ARMI_VMOV_D = 0xeeb00b40, + ARMI_VMOV_S = 0xeeb00a40, + ARMI_VMOVI_D = 0xeeb00b00, + + ARMI_VMOV_R_S = 0xee100a10, + ARMI_VMOV_S_R = 0xee000a10, + ARMI_VMOV_RR_D = 0xec500b10, + ARMI_VMOV_D_RR = 0xec400b10, + + ARMI_VADD_D = 0xee300b00, + ARMI_VSUB_D = 0xee300b40, + ARMI_VMUL_D = 0xee200b00, + ARMI_VMLA_D = 0xee000b00, + ARMI_VMLS_D = 0xee000b40, + ARMI_VNMLS_D = 0xee100b00, + ARMI_VDIV_D = 0xee800b00, + + ARMI_VABS_D = 0xeeb00bc0, + ARMI_VNEG_D = 0xeeb10b40, + ARMI_VSQRT_D = 0xeeb10bc0, + + ARMI_VCMP_D = 0xeeb40b40, + ARMI_VCMPZ_D = 0xeeb50b40, + + ARMI_VMRS = 0xeef1fa10, + + ARMI_VCVT_S32_F32 = 0xeebd0ac0, + ARMI_VCVT_S32_F64 = 0xeebd0bc0, + ARMI_VCVT_U32_F32 = 0xeebc0ac0, + ARMI_VCVT_U32_F64 = 0xeebc0bc0, + ARMI_VCVTR_S32_F32 = 0xeebd0a40, + ARMI_VCVTR_S32_F64 = 0xeebd0b40, + ARMI_VCVTR_U32_F32 = 0xeebc0a40, + ARMI_VCVTR_U32_F64 = 0xeebc0b40, + ARMI_VCVT_F32_S32 = 0xeeb80ac0, + ARMI_VCVT_F64_S32 = 0xeeb80bc0, + ARMI_VCVT_F32_U32 = 0xeeb80a40, + ARMI_VCVT_F64_U32 = 0xeeb80b40, + ARMI_VCVT_F32_F64 = 0xeeb70bc0, + ARMI_VCVT_F64_F32 = 0xeeb70ac0, + + ARMI_VLDR_S = 0xed100a00, + ARMI_VLDR_D = 0xed100b00, + ARMI_VSTR_S = 0xed000a00, + ARMI_VSTR_D = 0xed000b00, +} ARMIns; + +typedef enum ARMShift { + ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR +} ARMShift; + +/* ARM condition codes. */ +typedef enum ARMCC { + CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC, + CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL, + CC_HS = CC_CS, CC_LO = CC_CC +} ARMCC; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_mips.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_mips.h new file mode 100644 index 0000000..e0fc152 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_mips.h @@ -0,0 +1,257 @@ +/* +** Definitions for MIPS CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_MIPS_H +#define _LJ_TARGET_MIPS_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \ + _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \ + _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA) +#define FPRDEF(_) \ + _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \ + _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \ + _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \ + _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31) +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_ZERO = RID_R0, + RID_TMP = RID_RA, + + /* Calling conventions. */ + RID_RET = RID_R2, +#if LJ_LE + RID_RETHI = RID_R3, + RID_RETLO = RID_R2, +#else + RID_RETHI = RID_R2, + RID_RETLO = RID_R3, +#endif + RID_FPRET = RID_F0, + RID_CFUNCADDR = RID_R25, + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R16, /* Interpreter BASE. */ + RID_LPC = RID_R18, /* Interpreter PC. */ + RID_DISPATCH = RID_R19, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R20, /* Interpreter L. */ + RID_JGL = RID_R30, /* On-trace: global_State + 32768. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_RA+1, + RID_MIN_FPR = RID_F0, + RID_MAX_FPR = RID_F31+1, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR /* Only even regs are used. */ +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2 and JGL. */ +#define RSET_FIXED \ + (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\ + RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)) +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED) +#define RSET_FPR \ + (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\ + RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\ + RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\ + RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30)) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#define RSET_SCRATCH_GPR \ + (RSET_RANGE(RID_R1, RID_R15+1)|\ + RID2RSET(RID_R24)|RID2RSET(RID_R25)|RID2RSET(RID_R28)) +#define RSET_SCRATCH_FPR \ + (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\ + RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\ + RID2RSET(RID_F16)|RID2RSET(RID_F18)) +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R4 +#define REGARG_LASTGPR RID_R7 +#define REGARG_NUMGPR 4 +#define REGARG_FIRSTFPR RID_F12 +#define REGARG_LASTFPR RID_F14 +#define REGARG_NUMFPR 2 + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. +*/ +#define SPS_FIXED 5 +#define SPS_FIRST 4 + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +/* Return the address of a per-trace exit stub. */ +static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p) +{ + while (*p == 0x00000000) p++; /* Skip MIPSI_NOP. */ + return p; +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_trace_addr(T, exitno) \ + exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode)) + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define MIPSF_S(r) ((r) << 21) +#define MIPSF_T(r) ((r) << 16) +#define MIPSF_D(r) ((r) << 11) +#define MIPSF_R(r) ((r) << 21) +#define MIPSF_H(r) ((r) << 16) +#define MIPSF_G(r) ((r) << 11) +#define MIPSF_F(r) ((r) << 6) +#define MIPSF_A(n) ((n) << 6) +#define MIPSF_M(n) ((n) << 11) + +typedef enum MIPSIns { + /* Integer instructions. */ + MIPSI_MOVE = 0x00000021, + MIPSI_NOP = 0x00000000, + + MIPSI_LI = 0x24000000, + MIPSI_LU = 0x34000000, + MIPSI_LUI = 0x3c000000, + + MIPSI_ADDIU = 0x24000000, + MIPSI_ANDI = 0x30000000, + MIPSI_ORI = 0x34000000, + MIPSI_XORI = 0x38000000, + MIPSI_SLTI = 0x28000000, + MIPSI_SLTIU = 0x2c000000, + + MIPSI_ADDU = 0x00000021, + MIPSI_SUBU = 0x00000023, + MIPSI_MUL = 0x70000002, + MIPSI_AND = 0x00000024, + MIPSI_OR = 0x00000025, + MIPSI_XOR = 0x00000026, + MIPSI_NOR = 0x00000027, + MIPSI_SLT = 0x0000002a, + MIPSI_SLTU = 0x0000002b, + MIPSI_MOVZ = 0x0000000a, + MIPSI_MOVN = 0x0000000b, + + MIPSI_SLL = 0x00000000, + MIPSI_SRL = 0x00000002, + MIPSI_SRA = 0x00000003, + MIPSI_ROTR = 0x00200002, /* MIPS32R2 */ + MIPSI_SLLV = 0x00000004, + MIPSI_SRLV = 0x00000006, + MIPSI_SRAV = 0x00000007, + MIPSI_ROTRV = 0x00000046, /* MIPS32R2 */ + + MIPSI_SEB = 0x7c000420, /* MIPS32R2 */ + MIPSI_SEH = 0x7c000620, /* MIPS32R2 */ + MIPSI_WSBH = 0x7c0000a0, /* MIPS32R2 */ + + MIPSI_B = 0x10000000, + MIPSI_J = 0x08000000, + MIPSI_JAL = 0x0c000000, + MIPSI_JR = 0x00000008, + MIPSI_JALR = 0x0000f809, + + MIPSI_BEQ = 0x10000000, + MIPSI_BNE = 0x14000000, + MIPSI_BLEZ = 0x18000000, + MIPSI_BGTZ = 0x1c000000, + MIPSI_BLTZ = 0x04000000, + MIPSI_BGEZ = 0x04010000, + + /* Load/store instructions. */ + MIPSI_LW = 0x8c000000, + MIPSI_SW = 0xac000000, + MIPSI_LB = 0x80000000, + MIPSI_SB = 0xa0000000, + MIPSI_LH = 0x84000000, + MIPSI_SH = 0xa4000000, + MIPSI_LBU = 0x90000000, + MIPSI_LHU = 0x94000000, + MIPSI_LWC1 = 0xc4000000, + MIPSI_SWC1 = 0xe4000000, + MIPSI_LDC1 = 0xd4000000, + MIPSI_SDC1 = 0xf4000000, + + /* FP instructions. */ + MIPSI_MOV_S = 0x46000006, + MIPSI_MOV_D = 0x46200006, + MIPSI_MOVT_D = 0x46210011, + MIPSI_MOVF_D = 0x46200011, + + MIPSI_ABS_D = 0x46200005, + MIPSI_NEG_D = 0x46200007, + + MIPSI_ADD_D = 0x46200000, + MIPSI_SUB_D = 0x46200001, + MIPSI_MUL_D = 0x46200002, + MIPSI_DIV_D = 0x46200003, + MIPSI_SQRT_D = 0x46200004, + + MIPSI_ADD_S = 0x46000000, + MIPSI_SUB_S = 0x46000001, + + MIPSI_CVT_D_S = 0x46000021, + MIPSI_CVT_W_S = 0x46000024, + MIPSI_CVT_S_D = 0x46200020, + MIPSI_CVT_W_D = 0x46200024, + MIPSI_CVT_S_W = 0x46800020, + MIPSI_CVT_D_W = 0x46800021, + + MIPSI_TRUNC_W_S = 0x4600000d, + MIPSI_TRUNC_W_D = 0x4620000d, + MIPSI_FLOOR_W_S = 0x4600000f, + MIPSI_FLOOR_W_D = 0x4620000f, + + MIPSI_MFC1 = 0x44000000, + MIPSI_MTC1 = 0x44800000, + + MIPSI_BC1F = 0x45000000, + MIPSI_BC1T = 0x45010000, + + MIPSI_C_EQ_D = 0x46200032, + MIPSI_C_OLT_D = 0x46200034, + MIPSI_C_ULT_D = 0x46200035, + MIPSI_C_OLE_D = 0x46200036, + MIPSI_C_ULE_D = 0x46200037, + +} MIPSIns; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_ppc.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_ppc.h new file mode 100644 index 0000000..475e046 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_ppc.h @@ -0,0 +1,280 @@ +/* +** Definitions for PPC CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_PPC_H +#define _LJ_TARGET_PPC_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#define GPRDEF(_) \ + _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \ + _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \ + _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \ + _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31) +#define FPRDEF(_) \ + _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \ + _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \ + _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \ + _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31) +#define VRIDDEF(_) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_TMP = RID_R0, + + /* Calling conventions. */ + RID_RET = RID_R3, + RID_RETHI = RID_R3, + RID_RETLO = RID_R4, + RID_FPRET = RID_F1, + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_R14, /* Interpreter BASE. */ + RID_LPC = RID_R16, /* Interpreter PC. */ + RID_DISPATCH = RID_R17, /* Interpreter DISPATCH table. */ + RID_LREG = RID_R18, /* Interpreter L. */ + RID_JGL = RID_R31, /* On-trace: global_State + 32768. */ + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_R0, + RID_MAX_GPR = RID_R31+1, + RID_MIN_FPR = RID_F0, + RID_MAX_FPR = RID_F31+1, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR +}; + +#define RID_NUM_KREF RID_NUM_GPR +#define RID_MIN_KREF RID_R0 + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */ +#define RSET_FIXED \ + (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\ + RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)) +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED) +#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#define RSET_SCRATCH_GPR (RSET_RANGE(RID_R3, RID_R12+1)) +#define RSET_SCRATCH_FPR (RSET_RANGE(RID_F0, RID_F13+1)) +#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) +#define REGARG_FIRSTGPR RID_R3 +#define REGARG_LASTGPR RID_R10 +#define REGARG_NUMGPR 8 +#define REGARG_FIRSTFPR RID_F1 +#define REGARG_LASTFPR RID_F8 +#define REGARG_NUMFPR 8 + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. +** [sp+12] tmplo word \ +** [sp+ 8] tmphi word / tmp dword, parameter area for callee +** [sp+ 4] tmpw, LR of callee +** [sp+ 0] stack chain +*/ +#define SPS_FIXED 7 +#define SPS_FIRST 4 + +/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */ +#define SPOFS_TMPW 4 +#define SPOFS_TMP 8 +#define SPOFS_TMPHI 8 +#define SPOFS_TMPLO 12 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Highest exit + 1 indicates stack check. */ +#define EXITSTATE_CHECKEXIT 1 + +/* Return the address of a per-trace exit stub. */ +static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno) +{ + while (*p == 0x60000000) p++; /* Skip PPCI_NOP. */ + return p + 3 + exitno; +} +/* Avoid dependence on lj_jit.h if only including lj_target.h. */ +#define exitstub_trace_addr(T, exitno) \ + exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno)) + +/* -- Instructions -------------------------------------------------------- */ + +/* Instruction fields. */ +#define PPCF_CC(cc) ((((cc) & 3) << 16) | (((cc) & 4) << 22)) +#define PPCF_T(r) ((r) << 21) +#define PPCF_A(r) ((r) << 16) +#define PPCF_B(r) ((r) << 11) +#define PPCF_C(r) ((r) << 6) +#define PPCF_MB(n) ((n) << 6) +#define PPCF_ME(n) ((n) << 1) +#define PPCF_Y 0x00200000 +#define PPCF_DOT 0x00000001 + +typedef enum PPCIns { + /* Integer instructions. */ + PPCI_MR = 0x7c000378, + PPCI_NOP = 0x60000000, + + PPCI_LI = 0x38000000, + PPCI_LIS = 0x3c000000, + + PPCI_ADD = 0x7c000214, + PPCI_ADDC = 0x7c000014, + PPCI_ADDO = 0x7c000614, + PPCI_ADDE = 0x7c000114, + PPCI_ADDZE = 0x7c000194, + PPCI_ADDME = 0x7c0001d4, + PPCI_ADDI = 0x38000000, + PPCI_ADDIS = 0x3c000000, + PPCI_ADDIC = 0x30000000, + PPCI_ADDICDOT = 0x34000000, + + PPCI_SUBF = 0x7c000050, + PPCI_SUBFC = 0x7c000010, + PPCI_SUBFO = 0x7c000450, + PPCI_SUBFE = 0x7c000110, + PPCI_SUBFZE = 0x7c000190, + PPCI_SUBFME = 0x7c0001d0, + PPCI_SUBFIC = 0x20000000, + + PPCI_NEG = 0x7c0000d0, + + PPCI_AND = 0x7c000038, + PPCI_ANDC = 0x7c000078, + PPCI_NAND = 0x7c0003b8, + PPCI_ANDIDOT = 0x70000000, + PPCI_ANDISDOT = 0x74000000, + + PPCI_OR = 0x7c000378, + PPCI_NOR = 0x7c0000f8, + PPCI_ORI = 0x60000000, + PPCI_ORIS = 0x64000000, + + PPCI_XOR = 0x7c000278, + PPCI_EQV = 0x7c000238, + PPCI_XORI = 0x68000000, + PPCI_XORIS = 0x6c000000, + + PPCI_CMPW = 0x7c000000, + PPCI_CMPLW = 0x7c000040, + PPCI_CMPWI = 0x2c000000, + PPCI_CMPLWI = 0x28000000, + + PPCI_MULLW = 0x7c0001d6, + PPCI_MULLI = 0x1c000000, + PPCI_MULLWO = 0x7c0005d6, + + PPCI_EXTSB = 0x7c000774, + PPCI_EXTSH = 0x7c000734, + + PPCI_SLW = 0x7c000030, + PPCI_SRW = 0x7c000430, + PPCI_SRAW = 0x7c000630, + PPCI_SRAWI = 0x7c000670, + + PPCI_RLWNM = 0x5c000000, + PPCI_RLWINM = 0x54000000, + PPCI_RLWIMI = 0x50000000, + + PPCI_B = 0x48000000, + PPCI_BL = 0x48000001, + PPCI_BC = 0x40800000, + PPCI_BCL = 0x40800001, + PPCI_BCTR = 0x4e800420, + PPCI_BCTRL = 0x4e800421, + + PPCI_CRANDC = 0x4c000102, + PPCI_CRXOR = 0x4c000182, + PPCI_CRAND = 0x4c000202, + PPCI_CREQV = 0x4c000242, + PPCI_CRORC = 0x4c000342, + PPCI_CROR = 0x4c000382, + + PPCI_MFLR = 0x7c0802a6, + PPCI_MTCTR = 0x7c0903a6, + + PPCI_MCRXR = 0x7c000400, + + /* Load/store instructions. */ + PPCI_LWZ = 0x80000000, + PPCI_LBZ = 0x88000000, + PPCI_STW = 0x90000000, + PPCI_STB = 0x98000000, + PPCI_LHZ = 0xa0000000, + PPCI_LHA = 0xa8000000, + PPCI_STH = 0xb0000000, + + PPCI_STWU = 0x94000000, + + PPCI_LFS = 0xc0000000, + PPCI_LFD = 0xc8000000, + PPCI_STFS = 0xd0000000, + PPCI_STFD = 0xd8000000, + + PPCI_LWZX = 0x7c00002e, + PPCI_LBZX = 0x7c0000ae, + PPCI_STWX = 0x7c00012e, + PPCI_STBX = 0x7c0001ae, + PPCI_LHZX = 0x7c00022e, + PPCI_LHAX = 0x7c0002ae, + PPCI_STHX = 0x7c00032e, + + PPCI_LWBRX = 0x7c00042c, + PPCI_STWBRX = 0x7c00052c, + + PPCI_LFSX = 0x7c00042e, + PPCI_LFDX = 0x7c0004ae, + PPCI_STFSX = 0x7c00052e, + PPCI_STFDX = 0x7c0005ae, + + /* FP instructions. */ + PPCI_FMR = 0xfc000090, + PPCI_FNEG = 0xfc000050, + PPCI_FABS = 0xfc000210, + + PPCI_FRSP = 0xfc000018, + PPCI_FCTIWZ = 0xfc00001e, + + PPCI_FADD = 0xfc00002a, + PPCI_FSUB = 0xfc000028, + PPCI_FMUL = 0xfc000032, + PPCI_FDIV = 0xfc000024, + PPCI_FSQRT = 0xfc00002c, + + PPCI_FMADD = 0xfc00003a, + PPCI_FMSUB = 0xfc000038, + PPCI_FNMSUB = 0xfc00003c, + + PPCI_FCMPU = 0xfc000000, + PPCI_FSEL = 0xfc00002e, +} PPCIns; + +typedef enum PPCCC { + CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO +} PPCCC; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_x86.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_x86.h new file mode 100644 index 0000000..41f401b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_target_x86.h @@ -0,0 +1,342 @@ +/* +** Definitions for x86 and x64 CPUs. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TARGET_X86_H +#define _LJ_TARGET_X86_H + +/* -- Registers IDs ------------------------------------------------------- */ + +#if LJ_64 +#define GPRDEF(_) \ + _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \ + _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D) +#define FPRDEF(_) \ + _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \ + _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15) +#else +#define GPRDEF(_) \ + _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) +#define FPRDEF(_) \ + _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) +#endif +#define VRIDDEF(_) \ + _(MRM) + +#define RIDENUM(name) RID_##name, + +enum { + GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ + FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ + RID_MAX, + RID_MRM = RID_MAX, /* Pseudo-id for ModRM operand. */ + + /* Calling conventions. */ + RID_RET = RID_EAX, +#if LJ_64 + RID_FPRET = RID_XMM0, +#else + RID_RETLO = RID_EAX, + RID_RETHI = RID_EDX, +#endif + + /* These definitions must match with the *.dasc file(s): */ + RID_BASE = RID_EDX, /* Interpreter BASE. */ +#if LJ_64 && !LJ_ABI_WIN + RID_LPC = RID_EBX, /* Interpreter PC. */ + RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */ +#else + RID_LPC = RID_ESI, /* Interpreter PC. */ + RID_DISPATCH = RID_EBX, /* Interpreter DISPATCH table. */ +#endif + + /* Register ranges [min, max) and number of registers. */ + RID_MIN_GPR = RID_EAX, + RID_MIN_FPR = RID_XMM0, + RID_MAX_GPR = RID_MIN_FPR, + RID_MAX_FPR = RID_MAX, + RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, + RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR, +}; + +/* -- Register sets ------------------------------------------------------- */ + +/* Make use of all registers, except the stack pointer. */ +#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP)) +#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)) +#define RSET_ALL (RSET_GPR|RSET_FPR) +#define RSET_INIT RSET_ALL + +#if LJ_64 +/* Note: this requires the use of FORCE_REX! */ +#define RSET_GPR8 RSET_GPR +#else +#define RSET_GPR8 (RSET_RANGE(RID_EAX, RID_EBX+1)) +#endif + +/* ABI-specific register sets. */ +#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX)) +#if LJ_64 +#if LJ_ABI_WIN +/* Windows x64 ABI. */ +#define RSET_SCRATCH \ + (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1)) +#define REGARG_GPRS \ + (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5)) +#define REGARG_NUMGPR 4 +#define REGARG_NUMFPR 4 +#define REGARG_FIRSTFPR RID_XMM0 +#define REGARG_LASTFPR RID_XMM3 +#define STACKARG_OFS (4*8) +#else +/* The rest of the civilized x64 world has a common ABI. */ +#define RSET_SCRATCH \ + (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR) +#define REGARG_GPRS \ + (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \ + <<5))<<5))<<5))<<5))<<5)) +#define REGARG_NUMGPR 6 +#define REGARG_NUMFPR 8 +#define REGARG_FIRSTFPR RID_XMM0 +#define REGARG_LASTFPR RID_XMM7 +#define STACKARG_OFS 0 +#endif +#else +/* Common x86 ABI. */ +#define RSET_SCRATCH (RSET_ACD|RSET_FPR) +#define REGARG_GPRS (RID_ECX|(RID_EDX<<5)) /* Fastcall only. */ +#define REGARG_NUMGPR 2 /* Fastcall only. */ +#define REGARG_NUMFPR 0 +#define STACKARG_OFS 0 +#endif + +#if LJ_64 +/* Prefer the low 8 regs of each type to reduce REX prefixes. */ +#undef rset_picktop +#define rset_picktop(rs) (lj_fls(lj_bswap(rs)) ^ 0x18) +#endif + +/* -- Spill slots --------------------------------------------------------- */ + +/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. +** +** SPS_FIXED: Available fixed spill slots in interpreter frame. +** This definition must match with the *.dasc file(s). +** +** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. +*/ +#if LJ_64 +#if LJ_ABI_WIN +#define SPS_FIXED (4*2) +#define SPS_FIRST (4*2) /* Don't use callee register save area. */ +#else +#define SPS_FIXED 4 +#define SPS_FIRST 2 +#endif +#else +#define SPS_FIXED 6 +#define SPS_FIRST 2 +#endif + +#define SPOFS_TMP 0 + +#define sps_scale(slot) (4 * (int32_t)(slot)) +#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3) + +/* -- Exit state ---------------------------------------------------------- */ + +/* This definition must match with the *.dasc file(s). */ +typedef struct { + lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ + intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ + int32_t spill[256]; /* Spill slots. */ +} ExitState; + +/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */ +#define EXITSTUB_SPACING (2+2) +#define EXITSTUBS_PER_GROUP 32 + +/* -- x86 ModRM operand encoding ------------------------------------------ */ + +typedef enum { + XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0, + XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0, + XM_MASK = 0xc0 +} x86Mode; + +/* Structure to hold variable ModRM operand. */ +typedef struct { + int32_t ofs; /* Offset. */ + uint8_t base; /* Base register or RID_NONE. */ + uint8_t idx; /* Index register or RID_NONE. */ + uint8_t scale; /* Index scale (XM_SCALE1 .. XM_SCALE8). */ +} x86ModRM; + +/* -- Opcodes ------------------------------------------------------------- */ + +/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */ +#define XO_(o) ((uint32_t)(0x0000fe + (0x##o<<24))) +#define XO_FPU(a,b) ((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24))) +#define XO_0f(o) ((uint32_t)(0x0f00fd + (0x##o<<24))) +#define XO_66(o) ((uint32_t)(0x6600fd + (0x##o<<24))) +#define XO_660f(o) ((uint32_t)(0x0f66fc + (0x##o<<24))) +#define XO_f20f(o) ((uint32_t)(0x0ff2fc + (0x##o<<24))) +#define XO_f30f(o) ((uint32_t)(0x0ff3fc + (0x##o<<24))) + +/* This list of x86 opcodes is not intended to be complete. Opcodes are only +** included when needed. Take a look at DynASM or jit.dis_x86 to see the +** whole mess. +*/ +typedef enum { + /* Fixed length opcodes. XI_* prefix. */ + XI_NOP = 0x90, + XI_XCHGa = 0x90, + XI_CALL = 0xe8, + XI_JMP = 0xe9, + XI_JMPs = 0xeb, + XI_PUSH = 0x50, /* Really 50+r. */ + XI_JCCs = 0x70, /* Really 7x. */ + XI_JCCn = 0x80, /* Really 0f8x. */ + XI_LEA = 0x8d, + XI_MOVrib = 0xb0, /* Really b0+r. */ + XI_MOVri = 0xb8, /* Really b8+r. */ + XI_ARITHib = 0x80, + XI_ARITHi = 0x81, + XI_ARITHi8 = 0x83, + XI_PUSHi8 = 0x6a, + XI_TESTb = 0x84, + XI_TEST = 0x85, + XI_MOVmi = 0xc7, + XI_GROUP5 = 0xff, + + /* Note: little-endian byte-order! */ + XI_FLDZ = 0xeed9, + XI_FLD1 = 0xe8d9, + XI_FLDLG2 = 0xecd9, + XI_FLDLN2 = 0xedd9, + XI_FDUP = 0xc0d9, /* Really fld st0. */ + XI_FPOP = 0xd8dd, /* Really fstp st0. */ + XI_FPOP1 = 0xd9dd, /* Really fstp st1. */ + XI_FRNDINT = 0xfcd9, + XI_FSIN = 0xfed9, + XI_FCOS = 0xffd9, + XI_FPTAN = 0xf2d9, + XI_FPATAN = 0xf3d9, + XI_FSCALE = 0xfdd9, + XI_FYL2X = 0xf1d9, + + /* Variable-length opcodes. XO_* prefix. */ + XO_MOV = XO_(8b), + XO_MOVto = XO_(89), + XO_MOVtow = XO_66(89), + XO_MOVtob = XO_(88), + XO_MOVmi = XO_(c7), + XO_MOVmib = XO_(c6), + XO_LEA = XO_(8d), + XO_ARITHib = XO_(80), + XO_ARITHi = XO_(81), + XO_ARITHi8 = XO_(83), + XO_ARITHiw8 = XO_66(83), + XO_SHIFTi = XO_(c1), + XO_SHIFT1 = XO_(d1), + XO_SHIFTcl = XO_(d3), + XO_IMUL = XO_0f(af), + XO_IMULi = XO_(69), + XO_IMULi8 = XO_(6b), + XO_CMP = XO_(3b), + XO_TESTb = XO_(84), + XO_TEST = XO_(85), + XO_GROUP3b = XO_(f6), + XO_GROUP3 = XO_(f7), + XO_GROUP5b = XO_(fe), + XO_GROUP5 = XO_(ff), + XO_MOVZXb = XO_0f(b6), + XO_MOVZXw = XO_0f(b7), + XO_MOVSXb = XO_0f(be), + XO_MOVSXw = XO_0f(bf), + XO_MOVSXd = XO_(63), + XO_BSWAP = XO_0f(c8), + XO_CMOV = XO_0f(40), + + XO_MOVSD = XO_f20f(10), + XO_MOVSDto = XO_f20f(11), + XO_MOVSS = XO_f30f(10), + XO_MOVSSto = XO_f30f(11), + XO_MOVLPD = XO_660f(12), + XO_MOVAPS = XO_0f(28), + XO_XORPS = XO_0f(57), + XO_ANDPS = XO_0f(54), + XO_ADDSD = XO_f20f(58), + XO_SUBSD = XO_f20f(5c), + XO_MULSD = XO_f20f(59), + XO_DIVSD = XO_f20f(5e), + XO_SQRTSD = XO_f20f(51), + XO_MINSD = XO_f20f(5d), + XO_MAXSD = XO_f20f(5f), + XO_ROUNDSD = 0x0b3a0ffc, /* Really 66 0f 3a 0b. See asm_fpmath. */ + XO_UCOMISD = XO_660f(2e), + XO_CVTSI2SD = XO_f20f(2a), + XO_CVTSD2SI = XO_f20f(2d), + XO_CVTTSD2SI= XO_f20f(2c), + XO_CVTSI2SS = XO_f30f(2a), + XO_CVTSS2SI = XO_f30f(2d), + XO_CVTTSS2SI= XO_f30f(2c), + XO_CVTSS2SD = XO_f30f(5a), + XO_CVTSD2SS = XO_f20f(5a), + XO_ADDSS = XO_f30f(58), + XO_MOVD = XO_660f(6e), + XO_MOVDto = XO_660f(7e), + + XO_FLDd = XO_(d9), XOg_FLDd = 0, + XO_FLDq = XO_(dd), XOg_FLDq = 0, + XO_FILDd = XO_(db), XOg_FILDd = 0, + XO_FILDq = XO_(df), XOg_FILDq = 5, + XO_FSTPd = XO_(d9), XOg_FSTPd = 3, + XO_FSTPq = XO_(dd), XOg_FSTPq = 3, + XO_FISTPq = XO_(df), XOg_FISTPq = 7, + XO_FISTTPq = XO_(dd), XOg_FISTTPq = 1, + XO_FADDq = XO_(dc), XOg_FADDq = 0, + XO_FLDCW = XO_(d9), XOg_FLDCW = 5, + XO_FNSTCW = XO_(d9), XOg_FNSTCW = 7 +} x86Op; + +/* x86 opcode groups. */ +typedef uint32_t x86Group; + +#define XG_(i8, i, g) ((x86Group)(((i8) << 16) + ((i) << 8) + (g))) +#define XG_ARITHi(g) XG_(XI_ARITHi8, XI_ARITHi, g) +#define XG_TOXOi(xg) ((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000))) +#define XG_TOXOi8(xg) ((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000))) + +#define XO_ARITH(a) ((x86Op)(0x030000fe + ((a)<<27))) +#define XO_ARITHw(a) ((x86Op)(0x036600fd + ((a)<<27))) + +typedef enum { + XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP, + XOg_X_IMUL +} x86Arith; + +typedef enum { + XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR +} x86Shift; + +typedef enum { + XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV +} x86Group3; + +typedef enum { + XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH +} x86Group5; + +/* x86 condition codes. */ +typedef enum { + CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE, + CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE, + CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB, + CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE, + CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL, + CC_NG = CC_LE, CC_G = CC_NLE +} x86CC; + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.c new file mode 100644 index 0000000..9e5e400 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.c @@ -0,0 +1,815 @@ +/* +** Trace management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_trace_c +#define LUA_CORE + +#include "lj_obj.h" + +#if LJ_HASJIT + +#include "lj_gc.h" +#include "lj_err.h" +#include "lj_debug.h" +#include "lj_str.h" +#include "lj_frame.h" +#include "lj_state.h" +#include "lj_bc.h" +#include "lj_ir.h" +#include "lj_jit.h" +#include "lj_iropt.h" +#include "lj_mcode.h" +#include "lj_trace.h" +#include "lj_snap.h" +#include "lj_gdbjit.h" +#include "lj_record.h" +#include "lj_asm.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" +#include "lj_target.h" + +/* -- Error handling ------------------------------------------------------ */ + +/* Synchronous abort with error message. */ +void lj_trace_err(jit_State *J, TraceError e) +{ + setnilV(&J->errinfo); /* No error info. */ + setintV(J->L->top++, (int32_t)e); + lj_err_throw(J->L, LUA_ERRRUN); +} + +/* Synchronous abort with error message and error info. */ +void lj_trace_err_info(jit_State *J, TraceError e) +{ + setintV(J->L->top++, (int32_t)e); + lj_err_throw(J->L, LUA_ERRRUN); +} + +/* -- Trace management ---------------------------------------------------- */ + +/* The current trace is first assembled in J->cur. The variable length +** arrays point to shared, growable buffers (J->irbuf etc.). When trace +** recording ends successfully, the current trace and its data structures +** are copied to a new (compact) GCtrace object. +*/ + +/* Find a free trace number. */ +static TraceNo trace_findfree(jit_State *J) +{ + MSize osz, lim; + if (J->freetrace == 0) + J->freetrace = 1; + for (; J->freetrace < J->sizetrace; J->freetrace++) + if (traceref(J, J->freetrace) == NULL) + return J->freetrace++; + /* Need to grow trace array. */ + lim = (MSize)J->param[JIT_P_maxtrace] + 1; + if (lim < 2) lim = 2; else if (lim > 65535) lim = 65535; + osz = J->sizetrace; + if (osz >= lim) + return 0; /* Too many traces. */ + lj_mem_growvec(J->L, J->trace, J->sizetrace, lim, GCRef); + for (; osz < J->sizetrace; osz++) + setgcrefnull(J->trace[osz]); + return J->freetrace; +} + +#define TRACE_APPENDVEC(field, szfield, tp) \ + T->field = (tp *)p; \ + memcpy(p, J->cur.field, J->cur.szfield*sizeof(tp)); \ + p += J->cur.szfield*sizeof(tp); + +#ifdef LUAJIT_USE_PERFTOOLS +/* +** Create symbol table of JIT-compiled code. For use with Linux perf tools. +** Example usage: +** perf record -f -e cycles luajit test.lua +** perf report -s symbol +** rm perf.data /tmp/perf-*.map +*/ +#include +#include + +static void perftools_addtrace(GCtrace *T) +{ + static FILE *fp; + GCproto *pt = &gcref(T->startpt)->pt; + const BCIns *startpc = mref(T->startpc, const BCIns); + const char *name = proto_chunknamestr(pt); + BCLine lineno; + if (name[0] == '@' || name[0] == '=') + name++; + else + name = "(string)"; + lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc); + lineno = lj_debug_line(pt, proto_bcpos(pt, startpc)); + if (!fp) { + char fname[40]; + sprintf(fname, "/tmp/perf-%d.map", getpid()); + if (!(fp = fopen(fname, "w"))) return; + setlinebuf(fp); + } + fprintf(fp, "%lx %x TRACE_%d::%s:%u\n", + (long)T->mcode, T->szmcode, T->traceno, name, lineno); +} +#endif + +/* Save current trace by copying and compacting it. */ +static void trace_save(jit_State *J) +{ + size_t sztr = ((sizeof(GCtrace)+7)&~7); + size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns); + size_t sz = sztr + szins + + J->cur.nsnap*sizeof(SnapShot) + + J->cur.nsnapmap*sizeof(SnapEntry); + GCtrace *T = lj_mem_newt(J->L, (MSize)sz, GCtrace); + char *p = (char *)T + sztr; + memcpy(T, &J->cur, sizeof(GCtrace)); + setgcrefr(T->nextgc, J2G(J)->gc.root); + setgcrefp(J2G(J)->gc.root, T); + newwhite(J2G(J), T); + T->gct = ~LJ_TTRACE; + T->ir = (IRIns *)p - J->cur.nk; + memcpy(p, J->cur.ir+J->cur.nk, szins); + p += szins; + TRACE_APPENDVEC(snap, nsnap, SnapShot) + TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry) + J->cur.traceno = 0; + setgcrefp(J->trace[T->traceno], T); + lj_gc_barriertrace(J2G(J), T->traceno); + lj_gdbjit_addtrace(J, T); +#ifdef LUAJIT_USE_PERFTOOLS + perftools_addtrace(T); +#endif +} + +void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T) +{ + jit_State *J = G2J(g); + if (T->traceno) { + lj_gdbjit_deltrace(J, T); + if (T->traceno < J->freetrace) + J->freetrace = T->traceno; + setgcrefnull(J->trace[T->traceno]); + } + lj_mem_free(g, T, + ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) + + T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry)); +} + +/* Re-enable compiling a prototype by unpatching any modified bytecode. */ +void lj_trace_reenableproto(GCproto *pt) +{ + if ((pt->flags & PROTO_ILOOP)) { + BCIns *bc = proto_bc(pt); + BCPos i, sizebc = pt->sizebc;; + pt->flags &= ~PROTO_ILOOP; + if (bc_op(bc[0]) == BC_IFUNCF) + setbc_op(&bc[0], BC_FUNCF); + for (i = 1; i < sizebc; i++) { + BCOp op = bc_op(bc[i]); + if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP) + setbc_op(&bc[i], (int)op+(int)BC_LOOP-(int)BC_ILOOP); + } + } +} + +/* Unpatch the bytecode modified by a root trace. */ +static void trace_unpatch(jit_State *J, GCtrace *T) +{ + BCOp op = bc_op(T->startins); + BCIns *pc = mref(T->startpc, BCIns); + UNUSED(J); + if (op == BC_JMP) + return; /* No need to unpatch branches in parent traces (yet). */ + switch (bc_op(*pc)) { + case BC_JFORL: + lua_assert(traceref(J, bc_d(*pc)) == T); + *pc = T->startins; + pc += bc_j(T->startins); + lua_assert(bc_op(*pc) == BC_JFORI); + setbc_op(pc, BC_FORI); + break; + case BC_JITERL: + case BC_JLOOP: + lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op)); + *pc = T->startins; + break; + case BC_JMP: + lua_assert(op == BC_ITERL); + pc += bc_j(*pc)+2; + if (bc_op(*pc) == BC_JITERL) { + lua_assert(traceref(J, bc_d(*pc)) == T); + *pc = T->startins; + } + break; + case BC_JFUNCF: + lua_assert(op == BC_FUNCF); + *pc = T->startins; + break; + default: /* Already unpatched. */ + break; + } +} + +/* Flush a root trace. */ +static void trace_flushroot(jit_State *J, GCtrace *T) +{ + GCproto *pt = &gcref(T->startpt)->pt; + lua_assert(T->root == 0 && pt != NULL); + /* First unpatch any modified bytecode. */ + trace_unpatch(J, T); + /* Unlink root trace from chain anchored in prototype. */ + if (pt->trace == T->traceno) { /* Trace is first in chain. Easy. */ + pt->trace = T->nextroot; + } else if (pt->trace) { /* Otherwise search in chain of root traces. */ + GCtrace *T2 = traceref(J, pt->trace); + if (T2) { + for (; T2->nextroot; T2 = traceref(J, T2->nextroot)) + if (T2->nextroot == T->traceno) { + T2->nextroot = T->nextroot; /* Unlink from chain. */ + break; + } + } + } +} + +/* Flush a trace. Only root traces are considered. */ +void lj_trace_flush(jit_State *J, TraceNo traceno) +{ + if (traceno > 0 && traceno < J->sizetrace) { + GCtrace *T = traceref(J, traceno); + if (T && T->root == 0) + trace_flushroot(J, T); + } +} + +/* Flush all traces associated with a prototype. */ +void lj_trace_flushproto(global_State *g, GCproto *pt) +{ + while (pt->trace != 0) + trace_flushroot(G2J(g), traceref(G2J(g), pt->trace)); +} + +/* Flush all traces. */ +int lj_trace_flushall(lua_State *L) +{ + jit_State *J = L2J(L); + ptrdiff_t i; + if ((J2G(J)->hookmask & HOOK_GC)) + return 1; + for (i = (ptrdiff_t)J->sizetrace-1; i > 0; i--) { + GCtrace *T = traceref(J, i); + if (T) { + if (T->root == 0) + trace_flushroot(J, T); + lj_gdbjit_deltrace(J, T); + T->traceno = 0; + setgcrefnull(J->trace[i]); + } + } + J->cur.traceno = 0; + J->freetrace = 0; + /* Clear penalty cache. */ + memset(J->penalty, 0, sizeof(J->penalty)); + /* Free the whole machine code and invalidate all exit stub groups. */ + lj_mcode_free(J); + memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup)); + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "flush")); + ); + return 0; +} + +/* Initialize JIT compiler state. */ +void lj_trace_initstate(global_State *g) +{ + jit_State *J = G2J(g); + TValue *tv; + /* Initialize SIMD constants. */ + tv = LJ_KSIMD(J, LJ_KSIMD_ABS); + tv[0].u64 = U64x(7fffffff,ffffffff); + tv[1].u64 = U64x(7fffffff,ffffffff); + tv = LJ_KSIMD(J, LJ_KSIMD_NEG); + tv[0].u64 = U64x(80000000,00000000); + tv[1].u64 = U64x(80000000,00000000); +} + +/* Free everything associated with the JIT compiler state. */ +void lj_trace_freestate(global_State *g) +{ + jit_State *J = G2J(g); +#ifdef LUA_USE_ASSERT + { /* This assumes all traces have already been freed. */ + ptrdiff_t i; + for (i = 1; i < (ptrdiff_t)J->sizetrace; i++) + lua_assert(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL); + } +#endif + lj_mcode_free(J); + lj_ir_k64_freeall(J); + lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry); + lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot); + lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns); + lj_mem_freevec(g, J->trace, J->sizetrace, GCRef); +} + +/* -- Penalties and blacklisting ------------------------------------------ */ + +/* Blacklist a bytecode instruction. */ +static void blacklist_pc(GCproto *pt, BCIns *pc) +{ + setbc_op(pc, (int)bc_op(*pc)+(int)BC_ILOOP-(int)BC_LOOP); + pt->flags |= PROTO_ILOOP; +} + +/* Penalize a bytecode instruction. */ +static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e) +{ + uint32_t i, val = PENALTY_MIN; + for (i = 0; i < PENALTY_SLOTS; i++) + if (mref(J->penalty[i].pc, const BCIns) == pc) { /* Cache slot found? */ + /* First try to bump its hotcount several times. */ + val = ((uint32_t)J->penalty[i].val << 1) + + LJ_PRNG_BITS(J, PENALTY_RNDBITS); + if (val > PENALTY_MAX) { + blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */ + return; + } + goto setpenalty; + } + /* Assign a new penalty cache slot. */ + i = J->penaltyslot; + J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1); + setmref(J->penalty[i].pc, pc); +setpenalty: + J->penalty[i].val = (uint16_t)val; + J->penalty[i].reason = e; + hotcount_set(J2GG(J), pc+1, val); +} + +/* -- Trace compiler state machine ---------------------------------------- */ + +/* Start tracing. */ +static void trace_start(jit_State *J) +{ + lua_State *L; + TraceNo traceno; + + if ((J->pt->flags & PROTO_NOJIT)) { /* JIT disabled for this proto? */ + if (J->parent == 0) { + /* Lazy bytecode patching to disable hotcount events. */ + lua_assert(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL || + bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF); + setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP); + J->pt->flags |= PROTO_ILOOP; + } + J->state = LJ_TRACE_IDLE; /* Silently ignored. */ + return; + } + + /* Get a new trace number. */ + traceno = trace_findfree(J); + if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */ + lua_assert((J2G(J)->hookmask & HOOK_GC) == 0); + lj_trace_flushall(J->L); + J->state = LJ_TRACE_IDLE; /* Silently ignored. */ + return; + } + setgcrefp(J->trace[traceno], &J->cur); + + /* Setup enough of the current trace to be able to send the vmevent. */ + memset(&J->cur, 0, sizeof(GCtrace)); + J->cur.traceno = traceno; + J->cur.nins = J->cur.nk = REF_BASE; + J->cur.ir = J->irbuf; + J->cur.snap = J->snapbuf; + J->cur.snapmap = J->snapmapbuf; + J->mergesnap = 0; + J->needsnap = 0; + J->bcskip = 0; + J->guardemit.irt = 0; + J->postproc = LJ_POST_NONE; + lj_resetsplit(J); + setgcref(J->cur.startpt, obj2gco(J->pt)); + + L = J->L; + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "start")); + setintV(L->top++, traceno); + setfuncV(L, L->top++, J->fn); + setintV(L->top++, proto_bcpos(J->pt, J->pc)); + if (J->parent) { + setintV(L->top++, J->parent); + setintV(L->top++, J->exitno); + } + ); + lj_record_setup(J); +} + +/* Stop tracing. */ +static void trace_stop(jit_State *J) +{ + BCIns *pc = mref(J->cur.startpc, BCIns); + BCOp op = bc_op(J->cur.startins); + GCproto *pt = &gcref(J->cur.startpt)->pt; + TraceNo traceno = J->cur.traceno; + lua_State *L; + + switch (op) { + case BC_FORL: + setbc_op(pc+bc_j(J->cur.startins), BC_JFORI); /* Patch FORI, too. */ + /* fallthrough */ + case BC_LOOP: + case BC_ITERL: + case BC_FUNCF: + /* Patch bytecode of starting instruction in root trace. */ + setbc_op(pc, (int)op+(int)BC_JLOOP-(int)BC_LOOP); + setbc_d(pc, traceno); + addroot: + /* Add to root trace chain in prototype. */ + J->cur.nextroot = pt->trace; + pt->trace = (TraceNo1)traceno; + break; + case BC_RET: + case BC_RET0: + case BC_RET1: + *pc = BCINS_AD(BC_JLOOP, J->cur.snap[0].nslots, traceno); + goto addroot; + case BC_JMP: + /* Patch exit branch in parent to side trace entry. */ + lua_assert(J->parent != 0 && J->cur.root != 0); + lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode); + /* Avoid compiling a side trace twice (stack resizing uses parent exit). */ + traceref(J, J->parent)->snap[J->exitno].count = SNAPCOUNT_DONE; + /* Add to side trace chain in root trace. */ + { + GCtrace *root = traceref(J, J->cur.root); + root->nchild++; + J->cur.nextside = root->nextside; + root->nextside = (TraceNo1)traceno; + } + break; + default: + lua_assert(0); + break; + } + + /* Commit new mcode only after all patching is done. */ + lj_mcode_commit(J, J->cur.mcode); + J->postproc = LJ_POST_NONE; + trace_save(J); + + L = J->L; + lj_vmevent_send(L, TRACE, + setstrV(L, L->top++, lj_str_newlit(L, "stop")); + setintV(L->top++, traceno); + ); +} + +/* Start a new root trace for down-recursion. */ +static int trace_downrec(jit_State *J) +{ + /* Restart recording at the return instruction. */ + lua_assert(J->pt != NULL); + lua_assert(bc_isret(bc_op(*J->pc))); + if (bc_op(*J->pc) == BC_RETM) + return 0; /* NYI: down-recursion with RETM. */ + J->parent = 0; + J->exitno = 0; + J->state = LJ_TRACE_RECORD; + trace_start(J); + return 1; +} + +/* Abort tracing. */ +static int trace_abort(jit_State *J) +{ + lua_State *L = J->L; + TraceError e = LJ_TRERR_RECERR; + TraceNo traceno; + + J->postproc = LJ_POST_NONE; + lj_mcode_abort(J); + if (tvisnumber(L->top-1)) + e = (TraceError)numberVint(L->top-1); + if (e == LJ_TRERR_MCODELM) { + L->top--; /* Remove error object */ + J->state = LJ_TRACE_ASM; + return 1; /* Retry ASM with new MCode area. */ + } + /* Penalize or blacklist starting bytecode instruction. */ + if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) + penalty_pc(J, &gcref(J->cur.startpt)->pt, mref(J->cur.startpc, BCIns), e); + + /* Is there anything to abort? */ + traceno = J->cur.traceno; + if (traceno) { + ptrdiff_t errobj = savestack(L, L->top-1); /* Stack may be resized. */ + J->cur.link = 0; + J->cur.linktype = LJ_TRLINK_NONE; + lj_vmevent_send(L, TRACE, + TValue *frame; + const BCIns *pc; + GCfunc *fn; + setstrV(L, L->top++, lj_str_newlit(L, "abort")); + setintV(L->top++, traceno); + /* Find original Lua function call to generate a better error message. */ + frame = J->L->base-1; + pc = J->pc; + while (!isluafunc(frame_func(frame))) { + pc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1; + frame = frame_prev(frame); + } + fn = frame_func(frame); + setfuncV(L, L->top++, fn); + setintV(L->top++, proto_bcpos(funcproto(fn), pc)); + copyTV(L, L->top++, restorestack(L, errobj)); + copyTV(L, L->top++, &J->errinfo); + ); + /* Drop aborted trace after the vmevent (which may still access it). */ + setgcrefnull(J->trace[traceno]); + if (traceno < J->freetrace) + J->freetrace = traceno; + J->cur.traceno = 0; + } + L->top--; /* Remove error object */ + if (e == LJ_TRERR_DOWNREC) + return trace_downrec(J); + else if (e == LJ_TRERR_MCODEAL) + lj_trace_flushall(L); + return 0; +} + +/* Perform pending re-patch of a bytecode instruction. */ +static LJ_AINLINE void trace_pendpatch(jit_State *J, int force) +{ + if (LJ_UNLIKELY(J->patchpc)) { + if (force || J->bcskip == 0) { + *J->patchpc = J->patchins; + J->patchpc = NULL; + } else { + J->bcskip = 0; + } + } +} + +/* State machine for the trace compiler. Protected callback. */ +static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud) +{ + jit_State *J = (jit_State *)ud; + UNUSED(dummy); + do { + retry: + switch (J->state) { + case LJ_TRACE_START: + J->state = LJ_TRACE_RECORD; /* trace_start() may change state. */ + trace_start(J); + lj_dispatch_update(J2G(J)); + break; + + case LJ_TRACE_RECORD: + trace_pendpatch(J, 0); + setvmstate(J2G(J), RECORD); + lj_vmevent_send_(L, RECORD, + /* Save/restore tmptv state for trace recorder. */ + TValue savetv = J2G(J)->tmptv; + TValue savetv2 = J2G(J)->tmptv2; + setintV(L->top++, J->cur.traceno); + setfuncV(L, L->top++, J->fn); + setintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1); + setintV(L->top++, J->framedepth); + , + J2G(J)->tmptv = savetv; + J2G(J)->tmptv2 = savetv2; + ); + lj_record_ins(J); + break; + + case LJ_TRACE_END: + trace_pendpatch(J, 1); + J->loopref = 0; + if ((J->flags & JIT_F_OPT_LOOP) && + J->cur.link == J->cur.traceno && J->framedepth + J->retdepth == 0) { + setvmstate(J2G(J), OPT); + lj_opt_dce(J); + if (lj_opt_loop(J)) { /* Loop optimization failed? */ + J->cur.link = 0; + J->cur.linktype = LJ_TRLINK_NONE; + J->loopref = J->cur.nins; + J->state = LJ_TRACE_RECORD; /* Try to continue recording. */ + break; + } + J->loopref = J->chain[IR_LOOP]; /* Needed by assembler. */ + } + lj_opt_split(J); + lj_opt_sink(J); + J->state = LJ_TRACE_ASM; + break; + + case LJ_TRACE_ASM: + setvmstate(J2G(J), ASM); + lj_asm_trace(J, &J->cur); + trace_stop(J); + setvmstate(J2G(J), INTERP); + J->state = LJ_TRACE_IDLE; + lj_dispatch_update(J2G(J)); + return NULL; + + default: /* Trace aborted asynchronously. */ + setintV(L->top++, (int32_t)LJ_TRERR_RECERR); + /* fallthrough */ + case LJ_TRACE_ERR: + trace_pendpatch(J, 1); + if (trace_abort(J)) + goto retry; + setvmstate(J2G(J), INTERP); + J->state = LJ_TRACE_IDLE; + lj_dispatch_update(J2G(J)); + return NULL; + } + } while (J->state > LJ_TRACE_RECORD); + return NULL; +} + +/* -- Event handling ------------------------------------------------------ */ + +/* A bytecode instruction is about to be executed. Record it. */ +void lj_trace_ins(jit_State *J, const BCIns *pc) +{ + /* Note: J->L must already be set. pc is the true bytecode PC here. */ + J->pc = pc; + J->fn = curr_func(J->L); + J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL; + while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0) + J->state = LJ_TRACE_ERR; +} + +/* A hotcount triggered. Start recording a root trace. */ +void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc) +{ + /* Note: pc is the interpreter bytecode PC here. It's offset by 1. */ + ERRNO_SAVE + /* Reset hotcount. */ + hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP); + /* Only start a new trace if not recording or inside __gc call or vmevent. */ + if (J->state == LJ_TRACE_IDLE && + !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) { + J->parent = 0; /* Root trace. */ + J->exitno = 0; + J->state = LJ_TRACE_START; + lj_trace_ins(J, pc-1); + } + ERRNO_RESTORE +} + +/* Check for a hot side exit. If yes, start recording a side trace. */ +static void trace_hotside(jit_State *J, const BCIns *pc) +{ + SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno]; + if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) && + snap->count != SNAPCOUNT_DONE && + ++snap->count >= J->param[JIT_P_hotexit]) { + lua_assert(J->state == LJ_TRACE_IDLE); + /* J->parent is non-zero for a side trace. */ + J->state = LJ_TRACE_START; + lj_trace_ins(J, pc); + } +} + +/* Tiny struct to pass data to protected call. */ +typedef struct ExitDataCP { + jit_State *J; + void *exptr; /* Pointer to exit state. */ + const BCIns *pc; /* Restart interpreter at this PC. */ +} ExitDataCP; + +/* Need to protect lj_snap_restore because it may throw. */ +static TValue *trace_exit_cp(lua_State *L, lua_CFunction dummy, void *ud) +{ + ExitDataCP *exd = (ExitDataCP *)ud; + cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ + exd->pc = lj_snap_restore(exd->J, exd->exptr); + UNUSED(dummy); + return NULL; +} + +#ifndef LUAJIT_DISABLE_VMEVENT +/* Push all registers from exit state. */ +static void trace_exit_regs(lua_State *L, ExitState *ex) +{ + int32_t i; + setintV(L->top++, RID_NUM_GPR); + setintV(L->top++, RID_NUM_FPR); + for (i = 0; i < RID_NUM_GPR; i++) { + if (sizeof(ex->gpr[i]) == sizeof(int32_t)) + setintV(L->top++, (int32_t)ex->gpr[i]); + else + setnumV(L->top++, (lua_Number)ex->gpr[i]); + } +#if !LJ_SOFTFP + for (i = 0; i < RID_NUM_FPR; i++) { + setnumV(L->top, ex->fpr[i]); + if (LJ_UNLIKELY(tvisnan(L->top))) + setnanV(L->top); + L->top++; + } +#endif +} +#endif + +#ifdef EXITSTATE_PCREG +/* Determine trace number from pc of exit instruction. */ +static TraceNo trace_exit_find(jit_State *J, MCode *pc) +{ + TraceNo traceno; + for (traceno = 1; traceno < J->sizetrace; traceno++) { + GCtrace *T = traceref(J, traceno); + if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode)) + return traceno; + } + lua_assert(0); + return 0; +} +#endif + +/* A trace exited. Restore interpreter state. */ +int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr) +{ + ERRNO_SAVE + lua_State *L = J->L; + ExitState *ex = (ExitState *)exptr; + ExitDataCP exd; + int errcode; + const BCIns *pc; + void *cf; + GCtrace *T; +#ifdef EXITSTATE_PCREG + J->parent = trace_exit_find(J, (MCode *)(intptr_t)ex->gpr[EXITSTATE_PCREG]); +#endif + T = traceref(J, J->parent); UNUSED(T); +#ifdef EXITSTATE_CHECKEXIT + if (J->exitno == T->nsnap) { /* Treat stack check like a parent exit. */ + lua_assert(T->root != 0); + J->exitno = T->ir[REF_BASE].op2; + J->parent = T->ir[REF_BASE].op1; + T = traceref(J, J->parent); + } +#endif + lua_assert(T != NULL && J->exitno < T->nsnap); + exd.J = J; + exd.exptr = exptr; + errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp); + if (errcode) + return -errcode; /* Return negated error code. */ + + lj_vmevent_send(L, TEXIT, + lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK); + setintV(L->top++, J->parent); + setintV(L->top++, J->exitno); + trace_exit_regs(L, ex); + ); + + pc = exd.pc; + cf = cframe_raw(L->cframe); + setcframe_pc(cf, pc); + if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) { + if (!(G(L)->hookmask & HOOK_GC)) + lj_gc_step(L); /* Exited because of GC: drive GC forward. */ + } else { + trace_hotside(J, pc); + } + if (bc_op(*pc) == BC_JLOOP) { + BCIns *retpc = &traceref(J, bc_d(*pc))->startins; + if (bc_isret(bc_op(*retpc))) { + if (J->state == LJ_TRACE_RECORD) { + J->patchins = *pc; + J->patchpc = (BCIns *)pc; + *J->patchpc = *retpc; + J->bcskip = 1; + } else { + pc = retpc; + setcframe_pc(cf, pc); + } + } + } + /* Return MULTRES or 0. */ + ERRNO_RESTORE + switch (bc_op(*pc)) { + case BC_CALLM: case BC_CALLMT: + return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc)); + case BC_RETM: + return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc)); + case BC_TSETM: + return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc)); + default: + if (bc_op(*pc) >= BC_FUNCF) + return (int)((BCReg)(L->top - L->base) + 1); + return 0; + } +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.h new file mode 100644 index 0000000..f310908 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_trace.h @@ -0,0 +1,53 @@ +/* +** Trace management. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_TRACE_H +#define _LJ_TRACE_H + +#include "lj_obj.h" + +#if LJ_HASJIT +#include "lj_jit.h" +#include "lj_dispatch.h" + +/* Trace errors. */ +typedef enum { +#define TREDEF(name, msg) LJ_TRERR_##name, +#include "lj_traceerr.h" + LJ_TRERR__MAX +} TraceError; + +LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e); +LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e); + +/* Trace management. */ +LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T); +LJ_FUNC void lj_trace_reenableproto(GCproto *pt); +LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt); +LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno); +LJ_FUNC int lj_trace_flushall(lua_State *L); +LJ_FUNC void lj_trace_initstate(global_State *g); +LJ_FUNC void lj_trace_freestate(global_State *g); + +/* Event handling. */ +LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc); +LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc); +LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr); + +/* Signal asynchronous abort of trace or end of trace. */ +#define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE) +#define lj_trace_end(J) (J->state = LJ_TRACE_END) + +#else + +#define lj_trace_flushall(L) (UNUSED(L), 0) +#define lj_trace_initstate(g) UNUSED(g) +#define lj_trace_freestate(g) UNUSED(g) +#define lj_trace_abort(g) UNUSED(g) +#define lj_trace_end(J) UNUSED(J) + +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_traceerr.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_traceerr.h new file mode 100644 index 0000000..521560a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_traceerr.h @@ -0,0 +1,61 @@ +/* +** Trace compiler error messages. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* This file may be included multiple times with different TREDEF macros. */ + +/* Recording. */ +TREDEF(RECERR, "error thrown or hook called during recording") +TREDEF(TRACEOV, "trace too long") +TREDEF(STACKOV, "trace too deep") +TREDEF(SNAPOV, "too many snapshots") +TREDEF(BLACKL, "blacklisted") +TREDEF(NYIBC, "NYI: bytecode %d") + +/* Recording loop ops. */ +TREDEF(LLEAVE, "leaving loop in root trace") +TREDEF(LINNER, "inner loop in root trace") +TREDEF(LUNROLL, "loop unroll limit reached") + +/* Recording calls/returns. */ +TREDEF(BADTYPE, "bad argument type") +TREDEF(CJITOFF, "JIT compilation disabled for function") +TREDEF(CUNROLL, "call unroll limit reached") +TREDEF(DOWNREC, "down-recursion, restarting") +TREDEF(NYICF, "NYI: C function %p") +TREDEF(NYIFF, "NYI: FastFunc %s") +TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s") +TREDEF(NYIRETL, "NYI: return to lower frame") + +/* Recording indexed load/store. */ +TREDEF(STORENN, "store with nil or NaN key") +TREDEF(NOMM, "missing metamethod") +TREDEF(IDXLOOP, "looping index lookup") +TREDEF(NYITMIX, "NYI: mixed sparse/dense table") + +/* Recording C data operations. */ +TREDEF(NOCACHE, "symbol not in cache") +TREDEF(NYICONV, "NYI: unsupported C type conversion") +TREDEF(NYICALL, "NYI: unsupported C function type") + +/* Optimizations. */ +TREDEF(GFAIL, "guard would always fail") +TREDEF(PHIOV, "too many PHIs") +TREDEF(TYPEINS, "persistent type instability") + +/* Assembler. */ +TREDEF(MCODEAL, "failed to allocate mcode memory") +TREDEF(MCODEOV, "machine code too long") +TREDEF(MCODELM, "hit mcode limit (retrying)") +TREDEF(SPILLOV, "too many spill slots") +TREDEF(BADRA, "inconsistent register allocation") +TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d") +TREDEF(NYIPHI, "NYI: PHI shuffling too complex") +TREDEF(NYICOAL, "NYI: register coalescing too complex") + +#undef TREDEF + +/* Detecting unused error messages: + awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh +*/ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.c new file mode 100644 index 0000000..6cd357e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.c @@ -0,0 +1,34 @@ +/* +** Userdata handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_udata_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_gc.h" +#include "lj_udata.h" + +GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env) +{ + GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata); + global_State *g = G(L); + newwhite(g, ud); /* Not finalized. */ + ud->gct = ~LJ_TUDATA; + ud->udtype = UDTYPE_USERDATA; + ud->len = sz; + /* NOBARRIER: The GCudata is new (marked white). */ + setgcrefnull(ud->metatable); + setgcref(ud->env, obj2gco(env)); + /* Chain to userdata list (after main thread). */ + setgcrefr(ud->nextgc, mainthread(g)->nextgc); + setgcref(mainthread(g)->nextgc, obj2gco(ud)); + return ud; +} + +void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud) +{ + lj_mem_free(g, ud, sizeudata(ud)); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.h new file mode 100644 index 0000000..e03d9a3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_udata.h @@ -0,0 +1,14 @@ +/* +** Userdata handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_UDATA_H +#define _LJ_UDATA_H + +#include "lj_obj.h" + +LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env); +LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vm.h new file mode 100644 index 0000000..4a8f03f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vm.h @@ -0,0 +1,116 @@ +/* +** Assembler VM interface definitions. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_VM_H +#define _LJ_VM_H + +#include "lj_obj.h" + +/* Entry points for ASM parts of VM. */ +LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1); +LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); +typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud); +LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud, + lua_CPFunction cp); +LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); +LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode); +LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe); +LJ_ASMF void lj_vm_unwind_c_eh(void); +LJ_ASMF void lj_vm_unwind_ff_eh(void); +#if LJ_TARGET_X86ORX64 +LJ_ASMF void lj_vm_unwind_rethrow(void); +#endif + +/* Miscellaneous functions. */ +#if LJ_TARGET_X86ORX64 +LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]); +#endif +#if LJ_TARGET_PPC +void lj_vm_cachesync(void *start, void *end); +#endif +LJ_ASMF double lj_vm_foldarith(double x, double y, int op); +#if LJ_HASJIT +LJ_ASMF double lj_vm_foldfpm(double x, int op); +#endif +#if !LJ_ARCH_HASFPU +/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */ +#endif + +/* Dispatch targets for recording and hooks. */ +LJ_ASMF void lj_vm_record(void); +LJ_ASMF void lj_vm_inshook(void); +LJ_ASMF void lj_vm_rethook(void); +LJ_ASMF void lj_vm_callhook(void); + +/* Trace exit handling. */ +LJ_ASMF void lj_vm_exit_handler(void); +LJ_ASMF void lj_vm_exit_interp(void); + +/* Internal math helper functions. */ +#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC +#define lj_vm_floor floor +#define lj_vm_ceil ceil +#else +LJ_ASMF double lj_vm_floor(double); +LJ_ASMF double lj_vm_ceil(double); +#if LJ_TARGET_ARM +LJ_ASMF double lj_vm_floor_sf(double); +LJ_ASMF double lj_vm_ceil_sf(double); +#endif +#endif +#if defined(LUAJIT_NO_LOG2) || LJ_TARGET_X86ORX64 +LJ_ASMF double lj_vm_log2(double); +#else +#define lj_vm_log2 log2 +#endif + +#if LJ_HASJIT +#if LJ_TARGET_X86ORX64 +LJ_ASMF void lj_vm_floor_sse(void); +LJ_ASMF void lj_vm_ceil_sse(void); +LJ_ASMF void lj_vm_trunc_sse(void); +LJ_ASMF void lj_vm_exp_x87(void); +LJ_ASMF void lj_vm_exp2_x87(void); +LJ_ASMF void lj_vm_pow_sse(void); +LJ_ASMF void lj_vm_powi_sse(void); +#else +#if LJ_TARGET_PPC +#define lj_vm_trunc trunc +#else +LJ_ASMF double lj_vm_trunc(double); +#if LJ_TARGET_ARM +LJ_ASMF double lj_vm_trunc_sf(double); +#endif +#endif +LJ_ASMF double lj_vm_powi(double, int32_t); +#ifdef LUAJIT_NO_EXP2 +LJ_ASMF double lj_vm_exp2(double); +#else +#define lj_vm_exp2 exp2 +#endif +#endif +LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t); +#if LJ_HASFFI +LJ_ASMF int lj_vm_errno(void); +#endif +#endif + +/* Continuations for metamethods. */ +LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */ +LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */ +LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */ +LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */ +LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */ +LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */ + +enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */ + +/* Start of the ASM code. */ +LJ_ASMF char lj_vm_asm_begin[]; + +/* Bytecode offsets are relative to lj_vm_asm_begin. */ +#define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs))) + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.c new file mode 100644 index 0000000..e14ad5b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.c @@ -0,0 +1,57 @@ +/* +** VM event handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#include + +#define lj_vmevent_c +#define LUA_CORE + +#include "lj_obj.h" +#include "lj_str.h" +#include "lj_tab.h" +#include "lj_state.h" +#include "lj_dispatch.h" +#include "lj_vm.h" +#include "lj_vmevent.h" + +ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev) +{ + global_State *g = G(L); + GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY); + cTValue *tv = lj_tab_getstr(tabV(registry(L)), s); + if (tvistab(tv)) { + int hash = VMEVENT_HASH(ev); + tv = lj_tab_getint(tabV(tv), hash); + if (tv && tvisfunc(tv)) { + lj_state_checkstack(L, LUA_MINSTACK); + setfuncV(L, L->top++, funcV(tv)); + return savestack(L, L->top); + } + } + g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */ + return 0; +} + +void lj_vmevent_call(lua_State *L, ptrdiff_t argbase) +{ + global_State *g = G(L); + uint8_t oldmask = g->vmevmask; + uint8_t oldh = hook_save(g); + int status; + g->vmevmask = 0; /* Disable all events. */ + hook_vmevent(g); + status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0); + if (LJ_UNLIKELY(status)) { + /* Really shouldn't use stderr here, but where else to complain? */ + L->top--; + fputs("VM handler failed: ", stderr); + fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr); + fputc('\n', stderr); + } + hook_restore(g, oldh); + if (g->vmevmask != VMEVENT_NOCACHE) + g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.h new file mode 100644 index 0000000..51bae01 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmevent.h @@ -0,0 +1,59 @@ +/* +** VM event handling. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LJ_VMEVENT_H +#define _LJ_VMEVENT_H + +#include "lj_obj.h" + +/* Registry key for VM event handler table. */ +#define LJ_VMEVENTS_REGKEY "_VMEVENTS" +#define LJ_VMEVENTS_HSIZE 4 + +#define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7)) +#define VMEVENT_HASH(ev) ((int)(ev) & ~7) +#define VMEVENT_HASHIDX(h) ((int)(h) << 3) +#define VMEVENT_NOCACHE 255 + +#define VMEVENT_DEF(name, hash) \ + LJ_VMEVENT_##name##_, \ + LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3) + +/* VM event IDs. */ +typedef enum { + VMEVENT_DEF(BC, 0x00003883), + VMEVENT_DEF(TRACE, 0xb2d91467), + VMEVENT_DEF(RECORD, 0x9284bf4f), + VMEVENT_DEF(TEXIT, 0xb29df2b0), + LJ_VMEVENT__MAX +} VMEvent; + +#ifdef LUAJIT_DISABLE_VMEVENT +#define lj_vmevent_send(L, ev, args) UNUSED(L) +#define lj_vmevent_send_(L, ev, args, post) UNUSED(L) +#else +#define lj_vmevent_send(L, ev, args) \ + if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ + ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ + if (argbase) { \ + args \ + lj_vmevent_call(L, argbase); \ + } \ + } +#define lj_vmevent_send_(L, ev, args, post) \ + if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ + ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ + if (argbase) { \ + args \ + lj_vmevent_call(L, argbase); \ + post \ + } \ + } + +LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev); +LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase); +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmmath.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmmath.c new file mode 100644 index 0000000..63886aa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lj_vmmath.c @@ -0,0 +1,140 @@ +/* +** Math helper functions for assembler VM. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#define lj_vmmath_c +#define LUA_CORE + +#include +#include + +#include "lj_obj.h" +#include "lj_ir.h" +#include "lj_vm.h" + +/* -- Helper functions for generated machine code ------------------------- */ + +#if LJ_TARGET_X86ORX64 +/* Wrapper functions to avoid linker issues on OSX. */ +LJ_FUNCA double lj_vm_sinh(double x) { return sinh(x); } +LJ_FUNCA double lj_vm_cosh(double x) { return cosh(x); } +LJ_FUNCA double lj_vm_tanh(double x) { return tanh(x); } +#endif + +#if !LJ_TARGET_X86ORX64 +double lj_vm_foldarith(double x, double y, int op) +{ + switch (op) { + case IR_ADD - IR_ADD: return x+y; break; + case IR_SUB - IR_ADD: return x-y; break; + case IR_MUL - IR_ADD: return x*y; break; + case IR_DIV - IR_ADD: return x/y; break; + case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break; + case IR_POW - IR_ADD: return pow(x, y); break; + case IR_NEG - IR_ADD: return -x; break; + case IR_ABS - IR_ADD: return fabs(x); break; +#if LJ_HASJIT + case IR_ATAN2 - IR_ADD: return atan2(x, y); break; + case IR_LDEXP - IR_ADD: return ldexp(x, (int)y); break; + case IR_MIN - IR_ADD: return x > y ? y : x; break; + case IR_MAX - IR_ADD: return x < y ? y : x; break; +#endif + default: return x; + } +} +#endif + +#if LJ_HASJIT + +#ifdef LUAJIT_NO_LOG2 +double lj_vm_log2(double a) +{ + return log(a) * 1.4426950408889634074; +} +#endif + +#ifdef LUAJIT_NO_EXP2 +double lj_vm_exp2(double a) +{ + return exp(a * 0.6931471805599453); +} +#endif + +#if !(LJ_TARGET_ARM || LJ_TARGET_PPC) +int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b) +{ + uint32_t y, ua, ub; + lua_assert(b != 0); /* This must be checked before using this function. */ + ua = a < 0 ? (uint32_t)-a : (uint32_t)a; + ub = b < 0 ? (uint32_t)-b : (uint32_t)b; + y = ua % ub; + if (y != 0 && (a^b) < 0) y = y - ub; + if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y; + return (int32_t)y; +} +#endif + +#if !LJ_TARGET_X86ORX64 +/* Unsigned x^k. */ +static double lj_vm_powui(double x, uint32_t k) +{ + double y; + lua_assert(k != 0); + for (; (k & 1) == 0; k >>= 1) x *= x; + y = x; + if ((k >>= 1) != 0) { + for (;;) { + x *= x; + if (k == 1) break; + if (k & 1) y *= x; + k >>= 1; + } + y *= x; + } + return y; +} + +/* Signed x^k. */ +double lj_vm_powi(double x, int32_t k) +{ + if (k > 1) + return lj_vm_powui(x, (uint32_t)k); + else if (k == 1) + return x; + else if (k == 0) + return 1.0; + else + return 1.0 / lj_vm_powui(x, (uint32_t)-k); +} + +/* Computes fpm(x) for extended math functions. */ +double lj_vm_foldfpm(double x, int fpm) +{ + switch (fpm) { + case IRFPM_FLOOR: return lj_vm_floor(x); + case IRFPM_CEIL: return lj_vm_ceil(x); + case IRFPM_TRUNC: return lj_vm_trunc(x); + case IRFPM_SQRT: return sqrt(x); + case IRFPM_EXP: return exp(x); + case IRFPM_EXP2: return lj_vm_exp2(x); + case IRFPM_LOG: return log(x); + case IRFPM_LOG2: return lj_vm_log2(x); + case IRFPM_LOG10: return log10(x); + case IRFPM_SIN: return sin(x); + case IRFPM_COS: return cos(x); + case IRFPM_TAN: return tan(x); + default: lua_assert(0); + } + return 0; +} +#endif + +#if LJ_HASFFI +int lj_vm_errno(void) +{ + return errno; +} +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ljamalg.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ljamalg.c new file mode 100644 index 0000000..52a8615 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ljamalg.c @@ -0,0 +1,93 @@ +/* +** LuaJIT core and libraries amalgamation. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +/* ++--------------------------------------------------------------------------+ +| WARNING: Compiling the amalgamation needs a lot of virtual memory | +| (around 300 MB with GCC 4.x)! If you don't have enough physical memory | +| your machine will start swapping to disk and the compile will not finish | +| within a reasonable amount of time. | +| So either compile on a bigger machine or use the non-amalgamated build. | ++--------------------------------------------------------------------------+ +*/ + +#define ljamalg_c +#define LUA_CORE + +/* To get the mremap prototype. Must be defined before any system includes. */ +#if defined(__linux__) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + +#ifndef WINVER +#define WINVER 0x0501 +#endif + +#include "lua.h" +#include "lauxlib.h" + +#include "lj_gc.c" +#include "lj_err.c" +#include "lj_char.c" +#include "lj_bc.c" +#include "lj_obj.c" +#include "lj_str.c" +#include "lj_tab.c" +#include "lj_func.c" +#include "lj_udata.c" +#include "lj_meta.c" +#include "lj_debug.c" +#include "lj_state.c" +#include "lj_dispatch.c" +#include "lj_vmevent.c" +#include "lj_vmmath.c" +#include "lj_strscan.c" +#include "lj_api.c" +#include "lj_lex.c" +#include "lj_parse.c" +#include "lj_bcread.c" +#include "lj_bcwrite.c" +#include "lj_load.c" +#include "lj_ctype.c" +#include "lj_cdata.c" +#include "lj_cconv.c" +#include "lj_ccall.c" +#include "lj_ccallback.c" +#include "lj_carith.c" +#include "lj_clib.c" +#include "lj_cparse.c" +#include "lj_lib.c" +#include "lj_ir.c" +#include "lj_opt_mem.c" +#include "lj_opt_fold.c" +#include "lj_opt_narrow.c" +#include "lj_opt_dce.c" +#include "lj_opt_loop.c" +#include "lj_opt_split.c" +#include "lj_opt_sink.c" +#include "lj_mcode.c" +#include "lj_snap.c" +#include "lj_record.c" +#include "lj_crecord.c" +#include "lj_ffrecord.c" +#include "lj_asm.c" +#include "lj_trace.c" +#include "lj_gdbjit.c" +#include "lj_alloc.c" + +#include "lib_aux.c" +#include "lib_base.c" +#include "lib_math.c" +#include "lib_string.c" +#include "lib_table.c" +#include "lib_io.c" +#include "lib_os.c" +#include "lib_package.c" +#include "lib_debug.c" +#include "lib_bit.c" +#include "lib_jit.c" +#include "lib_ffi.c" +#include "lib_init.c" + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.c new file mode 100644 index 0000000..1cb43ae --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.c @@ -0,0 +1,486 @@ +/* +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "lzio.h" + + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } +#ifdef _JZ_LUA_CODE + case '%': { + lua_const *tm_constlist = ls->L->constlist; + unsigned int i = 0; + if(tm_constlist != NULL) + { + while(tm_constlist->name != NULL) + { + if(tm_constlist->size < ls->z->n) + { + if(memcmp(ls->z->p, tm_constlist->name, tm_constlist->size - 1) == 0) + { + for(i = 0; i < tm_constlist->size; i++) + { + save_and_next(ls); + } + seminfo->r = tm_constlist->vl; + return TK_NUMBER; + } + } + tm_constlist++; + } + } + } +#endif + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case EOZ: { + return TK_EOS; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.h new file mode 100644 index 0000000..a9201ce --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llex.h @@ -0,0 +1,81 @@ +/* +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llimits.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llimits.h new file mode 100644 index 0000000..ca8dcb7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmathlib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmathlib.c new file mode 100644 index 0000000..441fbf7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmathlib.c @@ -0,0 +1,263 @@ +/* +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ +** Standard mathematical library +** See Copyright Notice in lua.h +*/ + + +#include +#include + +#define lmathlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#undef PI +#define PI (3.14159265358979323846) +#define RADIANS_PER_DEGREE (PI/180.0) + + + +static int math_abs (lua_State *L) { + lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sin (lua_State *L) { + lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sinh (lua_State *L) { + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cos (lua_State *L) { + lua_pushnumber(L, cos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cosh (lua_State *L) { + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tan (lua_State *L) { + lua_pushnumber(L, tan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tanh (lua_State *L) { + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_asin (lua_State *L) { + lua_pushnumber(L, asin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_acos (lua_State *L) { + lua_pushnumber(L, acos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan (lua_State *L) { + lua_pushnumber(L, atan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan2 (lua_State *L) { + lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_ceil (lua_State *L) { + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); + return 1; +} + +static int math_floor (lua_State *L) { + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); + return 1; +} + +static int math_fmod (lua_State *L) { + lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_modf (lua_State *L) { + double ip; + double fp = modf(luaL_checknumber(L, 1), &ip); + lua_pushnumber(L, ip); + lua_pushnumber(L, fp); + return 2; +} + +static int math_sqrt (lua_State *L) { + lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); + return 1; +} + +static int math_pow (lua_State *L) { + lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_log (lua_State *L) { + lua_pushnumber(L, log(luaL_checknumber(L, 1))); + return 1; +} + +static int math_log10 (lua_State *L) { + lua_pushnumber(L, log10(luaL_checknumber(L, 1))); + return 1; +} + +static int math_exp (lua_State *L) { + lua_pushnumber(L, exp(luaL_checknumber(L, 1))); + return 1; +} + +static int math_deg (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); + return 1; +} + +static int math_rad (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); + return 1; +} + +static int math_frexp (lua_State *L) { + int e; + lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); + lua_pushinteger(L, e); + return 2; +} + +static int math_ldexp (lua_State *L) { + lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); + return 1; +} + + + +static int math_min (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmin = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d < dmin) + dmin = d; + } + lua_pushnumber(L, dmin); + return 1; +} + + +static int math_max (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmax = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d > dmax) + dmax = d; + } + lua_pushnumber(L, dmax); + return 1; +} + + +static int math_random (lua_State *L) { + /* the `%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ + lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; + } + case 1: { /* only upper limit */ + int u = luaL_checkint(L, 1); + luaL_argcheck(L, 1<=u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ + break; + } + case 2: { /* lower and upper limits */ + int l = luaL_checkint(L, 1); + int u = luaL_checkint(L, 2); + luaL_argcheck(L, l<=u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ + break; + } + default: return luaL_error(L, "wrong number of arguments"); + } + return 1; +} + + +static int math_randomseed (lua_State *L) { + srand(luaL_checkint(L, 1)); + return 0; +} + + +static const luaL_Reg mathlib[] = { + {"abs", math_abs}, + {"acos", math_acos}, + {"asin", math_asin}, + {"atan2", math_atan2}, + {"atan", math_atan}, + {"ceil", math_ceil}, + {"cosh", math_cosh}, + {"cos", math_cos}, + {"deg", math_deg}, + {"exp", math_exp}, + {"floor", math_floor}, + {"fmod", math_fmod}, + {"frexp", math_frexp}, + {"ldexp", math_ldexp}, + {"log10", math_log10}, + {"log", math_log}, + {"max", math_max}, + {"min", math_min}, + {"modf", math_modf}, + {"pow", math_pow}, + {"rad", math_rad}, + {"random", math_random}, + {"randomseed", math_randomseed}, + {"sinh", math_sinh}, + {"sin", math_sin}, + {"sqrt", math_sqrt}, + {"tanh", math_tanh}, + {"tan", math_tan}, + {NULL, NULL} +}; + + +/* +** Open math library +*/ +LUALIB_API int luaopen_math (lua_State *L) { + luaL_register(L, LUA_MATHLIBNAME, mathlib); + lua_pushnumber(L, PI); + lua_setfield(L, -2, "pi"); + lua_pushnumber(L, HUGE_VAL); + lua_setfield(L, -2, "huge"); +#if defined(LUA_COMPAT_MOD) + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.c new file mode 100644 index 0000000..ae7d8c9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.c @@ -0,0 +1,86 @@ +/* +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.h new file mode 100644 index 0000000..7c2dcb3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lmem.h @@ -0,0 +1,49 @@ +/* +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loadlib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loadlib.c new file mode 100644 index 0000000..0d401eb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loadlib.c @@ -0,0 +1,666 @@ +/* +** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +** +** This module contains an implementation of loadlib for Unix systems +** that have dlfcn, an implementation for Darwin (Mac OS X), an +** implementation for Windows, and a stub for other systems. +*/ + + +#include +#include + + +#define loadlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* prefix for open functions in C libraries */ +#define LUA_POF "luaopen_" + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "_" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +/* error codes for ll_loadfunc */ +#define ERRLIB 1 +#define ERRFUNC 2 + +#define setprogdir(L) ((void)0) + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(LUA_DL_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include + + +#undef setprogdir + +static void setprogdir (lua_State *L) { + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff)/sizeof(char); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); + else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include + + +/* Mac appends a `_' before C function names */ +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +#define DLMSG "dynamic libraries not enabled; check your Lua installation" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + return ERRLIB; /* unable to load library */ + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f == NULL) + return ERRFUNC; /* unable to find function */ + lua_pushcfunction(L, f); + return 0; /* return function */ + } +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int stat = ll_loadfunc(L, path, init); + if (stat == 0) /* no errors? */ + return 1; /* return the loaded function */ + else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + + + +/* +** {====================================================== +** 'require' function +** ======================================================= +*/ + + +static int readable (const char *filename) { + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + + +static const char *pushnexttemplate (lua_State *L, const char *path) { + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, l - path); /* template */ + return l; +} + + +static const char *findfile (lua_State *L, const char *name, + const char *pname) { + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + lua_pushliteral(L, ""); /* error accumulator */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename; + filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + lua_concat(L, 2); /* add entry to possible error message */ + } + return NULL; /* not found */ +} + + +static void loaderror (lua_State *L, const char *filename) { + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + + +static int loader_Lua (lua_State *L) { + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static const char *mkfuncname (lua_State *L, const char *modname) { + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, POF"%s", funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + + +static int loader_C (lua_State *L) { + const char *funcname; + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + funcname = mkfuncname(L, name); + if (ll_loadfunc(L, filename, funcname) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static int loader_Croot (lua_State *L) { + const char *funcname; + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int stat; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, p - name); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + funcname = mkfuncname(L, name); + if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { + if (stat != ERRFUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + + +static int loader_preload (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) /* not found? */ + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + return 1; +} + + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i=1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + return 1; +} + +/* }====================================================== */ + + + +/* +** {====================================================== +** 'module' function +** ======================================================= +*/ + + +static void setfenv (lua_State *L) { + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + + +static void dooptions (lua_State *L, int n) { + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + + +static void modinit (lua_State *L, const char *modname) { + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + return luaL_error(L, "name conflict for module " LUA_QS, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + + +static int ll_seeall (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + + +/* }====================================================== */ + + + +/* auxiliary mark (for internal use) */ +#define AUXMARK "\1" + +static void setpath (lua_State *L, const char *fieldname, const char *envname, + const char *def) { + const char *path = getenv(envname); + if (path == NULL) /* no environment variable? */ + lua_pushstring(L, def); /* use default */ + else { + /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + + +static const luaL_Reg pk_funcs[] = { + {"loadlib", ll_loadlib}, + {"seeall", ll_seeall}, + {NULL, NULL} +}; + + +static const luaL_Reg ll_funcs[] = { + {"module", ll_module}, + {"require", ll_require}, + {NULL, NULL} +}; + + +static const lua_CFunction loaders[] = + {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; + + +LUALIB_API int luaopen_package (lua_State *L) { + int i; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + luaL_register(L, LUA_LOADLIBNAME, pk_funcs); +#if defined(LUA_COMPAT_LOADLIB) + lua_getfield(L, -1, "loadlib"); + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); +#endif + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + /* create `loaders' table */ + lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + /* fill it with pre-defined loaders */ + for (i=0; loaders[i] != NULL; i++) { + lua_pushcfunction(L, loaders[i]); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ + /* store config information */ + lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); + lua_setfield(L, -2, "config"); + /* set field `loaded' */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_newtable(L); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, ll_funcs); /* open lib into global table */ + lua_pop(L, 1); + return 1; /* return 'package' table */ +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.c new file mode 100644 index 0000000..4ff5073 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.c @@ -0,0 +1,214 @@ +/* +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + *result = lua_str2number(s, &endptr); + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.h new file mode 100644 index 0000000..f1e447e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lobject.h @@ -0,0 +1,381 @@ +/* +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(rawtsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

    lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA const TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.c new file mode 100644 index 0000000..4cc7452 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.c @@ -0,0 +1,102 @@ +/* +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.h new file mode 100644 index 0000000..41224d6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lopcodes.h @@ -0,0 +1,268 @@ +/* +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loslib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loslib.c new file mode 100644 index 0000000..da06a57 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/loslib.c @@ -0,0 +1,243 @@ +/* +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ +** Standard Operating System library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define loslib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +static int os_pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static int os_execute (lua_State *L) { + lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + return 1; +} + + +static int os_remove (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return os_pushresult(L, remove(filename) == 0, filename); +} + + +static int os_rename (lua_State *L) { + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return os_pushresult(L, rename(fromname, toname) == 0, fromname); +} + + +static int os_tmpname (lua_State *L) { + char buff[LUA_TMPNAMBUFSIZE]; + int err; + lua_tmpnam(buff, err); + if (err) + return luaL_error(L, "unable to generate a unique filename"); + lua_pushstring(L, buff); + return 1; +} + + +static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + return 1; +} + + +static int os_clock (lua_State *L) { + lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + return 1; +} + + +/* +** {====================================================== +** Time/Date operations +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, +** wday=%w+1, yday=%j, isdst=? } +** ======================================================= +*/ + +static void setfield (lua_State *L, const char *key, int value) { + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield (lua_State *L, const char *key, int value) { + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield (lua_State *L, const char *key) { + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + + +static int getfield (lua_State *L, const char *key, int d) { + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) + res = (int)lua_tointeger(L, -1); + else { + if (d < 0) + return luaL_error(L, "field " LUA_QS " missing in date table", key); + res = d; + } + lua_pop(L, 1); + return res; +} + + +static int os_date (lua_State *L) { + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; + if (*s == '!') { /* UTC? */ + stm = gmtime(&t); + s++; /* skip `!' */ + } + else + stm = localtime(&t); + if (stm == NULL) /* invalid date? */ + lua_pushnil(L); + else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } + else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + + +static int os_time (lua_State *L) { + time_t t; + if (lua_isnoneornil(L, 1)) /* called without args? */ + t = time(NULL); /* get current time */ + else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + + +static int os_difftime (lua_State *L) { + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, 0)))); + return 1; +} + +/* }====================================================== */ + + +static int os_setlocale (lua_State *L) { + static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, + LC_NUMERIC, LC_TIME}; + static const char *const catnames[] = {"all", "collate", "ctype", "monetary", + "numeric", "time", NULL}; + const char *l = luaL_optstring(L, 1, NULL); + int op = luaL_checkoption(L, 2, "all", catnames); + lua_pushstring(L, setlocale(cat[op], l)); + return 1; +} + + +static int os_exit (lua_State *L) { + exit(luaL_optint(L, 1, EXIT_SUCCESS)); +} + +static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, + {"execute", os_execute}, + {"exit", os_exit}, + {"getenv", os_getenv}, + {"remove", os_remove}, + {"rename", os_rename}, + {"setlocale", os_setlocale}, + {"time", os_time}, + {"tmpname", os_tmpname}, + {NULL, NULL} +}; + +/* }====================================================== */ + + + +LUALIB_API int luaopen_os (lua_State *L) { + luaL_register(L, LUA_OSLIBNAME, syslib); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.c new file mode 100644 index 0000000..1e2a9a8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.c @@ -0,0 +1,1339 @@ +/* +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + /* a block either controls scope or breaks (never both) */ + lua_assert(!bl->isbreakable || !bl->upval); + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ +struct LHS_assign { + struct LHS_assign *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +}; + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} + + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + struct LHS_assign nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && !bl->isbreakable) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + checknext(ls, TK_DO); + block(ls); + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + checknext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + checknext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + struct LHS_assign v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + assignment(ls, &v, 1); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + breakstat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.h new file mode 100644 index 0000000..18836af --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lparser.h @@ -0,0 +1,82 @@ +/* +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.c new file mode 100644 index 0000000..fcb9d90 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.c @@ -0,0 +1,217 @@ +/* +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = L->baseCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; +#ifdef _JZ_LUA_CODE + L->constlist = NULL; +#endif + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = L->baseCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); + close_state(L); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.h new file mode 100644 index 0000000..13281ca --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstate.h @@ -0,0 +1,172 @@ +/* +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +#ifdef _JZ_LUA_CODE + lua_const *constlist; +#endif +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.c new file mode 100644 index 0000000..4911315 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.c @@ -0,0 +1,111 @@ +/* +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.h new file mode 100644 index 0000000..73a2ff8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstrlib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstrlib.c new file mode 100644 index 0000000..1b4763d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lstrlib.c @@ -0,0 +1,869 @@ +/* +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, + {"dump", str_dump}, + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.c new file mode 100644 index 0000000..ec84f4f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static const Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +const TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +const TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +const TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + const TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + const TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.h new file mode 100644 index 0000000..f5b9d5e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltablib.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltablib.c new file mode 100644 index 0000000..b6d9cb4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltablib.c @@ -0,0 +1,287 @@ +/* +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + const TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltm.h new file mode 100644 index 0000000..64343b7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ltm.h @@ -0,0 +1,54 @@ +/* +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.c new file mode 100644 index 0000000..3a46609 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.c @@ -0,0 +1,392 @@ +/* +** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lua_c + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + + + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + + +static void print_version (void) { + l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv(LUA_INIT); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + +int main (int argc, char **argv) { + int status; + struct Smain s; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + s.argc = argc; + s.argv = argv; + status = lua_cpcall(L, &pmain, &s); + report(L, status); + lua_close(L); + return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.h new file mode 100644 index 0000000..4a4d245 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.h @@ -0,0 +1,404 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + +/* From Lua 5.2. */ +LUA_API void *lua_upvalueid (lua_State *L, int idx, int n); +LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2); +LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname, const char *mode); + + +typedef struct __lua_const +{ + const char *name; + unsigned int size; + int vl; +}lua_const; + +LUA_API int lua_setconstlist(lua_State *L, lua_const *constlist); //ڶȡ + + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.hpp b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.hpp new file mode 100644 index 0000000..07e9002 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lua.hpp @@ -0,0 +1,9 @@ +// C++ wrapper for LuaJIT header files. + +extern "C" { +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "luajit.h" +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luac.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luac.c new file mode 100644 index 0000000..d070173 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luac.c @@ -0,0 +1,200 @@ +/* +** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $ +** Lua compiler (saves bytecodes to files; also list bytecodes) +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include + +#define luac_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstring.h" +#include "lundump.h" + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -l list\n" + " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n", + progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + int version=0; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i))->l.p) + +static const Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + int i,pc; + Proto* f=luaF_newproto(L); + setptvalue2s(L,L->top,f); incr_top(L); + f->source=luaS_newliteral(L,"=(" PROGNAME ")"); + f->maxstacksize=1; + pc=2*n+1; + f->code=luaM_newvector(L,pc,Instruction); + f->sizecode=pc; + f->p=luaM_newvector(L,n,Proto*); + f->sizep=n; + pc=0; + for (i=0; ip[i]=toproto(L,i-n-1); + f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); + f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); + } + f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +struct Smain { + int argc; + char** argv; +}; + +static int pmain(lua_State* L) +{ + struct Smain* s = (struct Smain*)lua_touserdata(L, 1); + int argc=s->argc; + char** argv=s->argv; + const Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +int main(int argc, char* argv[]) +{ + lua_State* L; + struct Smain s; + int i=doargs(argc,argv); + argc-=i; argv+=i; + if (argc<=0) usage("no input files given"); + L=lua_open(); + if (L==NULL) fatal("not enough memory for state"); + s.argc=argc; + s.argv=argv; + if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); + lua_close(L); + return EXIT_SUCCESS; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luaconf.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luaconf.h new file mode 100644 index 0000000..affb7da --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luaconf.h @@ -0,0 +1,156 @@ +/* +** Configuration header. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef luaconf_h +#define luaconf_h + +#ifndef WINVER +#define WINVER 0x0501 +#endif +#include +#include + +/* Default path for loading Lua and C modules with require(). */ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" +#else +/* +** Note to distribution maintainers: do NOT patch the following lines! +** Please read ../doc/install.html#distro and pass PREFIX=/usr instead. +*/ +#ifndef LUA_MULTILIB +#define LUA_MULTILIB "lib" +#endif +#ifndef LUA_LMULTILIB +#define LUA_LMULTILIB "lib" +#endif +#define LUA_LROOT "/usr/local" +#define LUA_LUADIR "/lua/5.1/" +#define LUA_LJDIR "/luajit-2.0.3/" + +#ifdef LUA_ROOT +#define LUA_JROOT LUA_ROOT +#define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR +#define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR +#define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua" +#define LUA_RCPATH ";" LUA_RCDIR "?.so" +#else +#define LUA_JROOT LUA_LROOT +#define LUA_RLPATH +#define LUA_RCPATH +#endif + +#define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua" +#define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR +#define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR +#define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua" +#define LUA_LCPATH1 ";" LUA_LCDIR "?.so" +#define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so" + +#define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH +#define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2 +#endif + +/* Environment variable names for path overrides and initialization code. */ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + +/* Special file system characters. */ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" +#define LUA_PATH_CONFIG \ + LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \ + LUA_EXECDIR "\n" LUA_IGMARK + +/* Quoting in error messages. */ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + +/* Various tunables. */ +#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */ +#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */ +#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */ +#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */ +#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */ + +/* Compatibility with older library function names. */ +#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */ +#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */ + +/* Configuration for the frontend (the luajit executable). */ +#if defined(luajit_c) +#define LUA_PROGNAME "luajit" /* Fallback frontend name. */ +#define LUA_PROMPT "> " /* Interactive prompt. */ +#define LUA_PROMPT2 ">> " /* Continuation prompt. */ +#define LUA_MAXINPUT 512 /* Max. input line length. */ +#endif + +/* Note: changing the following defines breaks the Lua 5.1 ABI. */ +#define LUA_INTEGER ptrdiff_t +#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */ +/* +** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using +** unreasonable amounts of stack space, but still retain ABI compatibility. +** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it. +*/ +#define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ) + +/* The following defines are here only for compatibility with luaconf.h +** from the standard Lua distribution. They must not be changed for LuaJIT. +*/ +#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER double +#define LUAI_UACNUMBER double +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +/* Linkage of public API functions. */ +#if defined(LUA_BUILD_AS_DLL) +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif +#else +#define LUA_API extern +#endif + +#define LUALIB_API LUA_API + +/* Support for internal assertions. */ +#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK) +#include +#endif +#ifdef LUA_USE_ASSERT +#define lua_assert(x) assert(x) +#endif +#ifdef LUA_USE_APICHECK +#define luai_apicheck(L, o) { (void)L; assert(o); } +#else +#define luai_apicheck(L, o) { (void)L; } +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.c new file mode 100644 index 0000000..363f3bf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.c @@ -0,0 +1,571 @@ +/* +** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +** +** Major portions taken verbatim or adapted from the Lua interpreter. +** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +*/ + +#include +#include +#include + +#define luajit_c + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "luajit.h" + +#include "lj_arch.h" + +#if LJ_TARGET_POSIX +#include +#define lua_stdin_is_tty() isatty(0) +#elif LJ_TARGET_WINDOWS +#include +#ifdef __BORLANDC__ +#define lua_stdin_is_tty() isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#endif +#else +#define lua_stdin_is_tty() 1 +#endif + +#if !LJ_TARGET_CONSOLE +#include +#endif + +static lua_State *globalL = NULL; +static const char *progname = LUA_PROGNAME; + +#if !LJ_TARGET_CONSOLE +static void lstop(lua_State *L, lua_Debug *ar) +{ + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + /* Avoid luaL_error -- a C hook doesn't add an extra frame. */ + luaL_where(L, 0); + lua_pushfstring(L, "%sinterrupted!", lua_tostring(L, -1)); + lua_error(L); +} + +static void laction(int i) +{ + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} +#endif + +static void print_usage(void) +{ + fprintf(stderr, + "usage: %s [options]... [script [args]...].\n" + "Available options are:\n" + " -e chunk Execute string " LUA_QL("chunk") ".\n" + " -l name Require library " LUA_QL("name") ".\n" + " -b ... Save or list bytecode.\n" + " -j cmd Perform LuaJIT control command.\n" + " -O[opt] Control LuaJIT optimizations.\n" + " -i Enter interactive mode after executing " LUA_QL("script") ".\n" + " -v Show version information.\n" + " -E Ignore environment variables.\n" + " -- Stop handling options.\n" + " - Execute stdin and stop handling options.\n" + , + progname); + fflush(stderr); +} + +static void l_message(const char *pname, const char *msg) +{ + if (pname) fprintf(stderr, "l_message %s: ", pname); + fprintf(stderr, "l_message %s\n", msg); + fflush(stderr); +} + +static int report(lua_State *L, int status) +{ + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + +static int traceback(lua_State *L) +{ + if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */ + if (lua_isnoneornil(L, 1) || + !luaL_callmeta(L, 1, "__tostring") || + !lua_isstring(L, -1)) + return 1; /* Return non-string error object. */ + lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */ + } + luaL_traceback(L, L, lua_tostring(L, 1), 1); + return 1; +} + +static int docall(lua_State *L, int narg, int clear) +{ + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ +#if !LJ_TARGET_CONSOLE + signal(SIGINT, laction); +#endif + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); +#if !LJ_TARGET_CONSOLE + signal(SIGINT, SIG_DFL); +#endif + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + +static void print_version(void) +{ + fputs(LUAJIT_VERSION " -- " LUAJIT_COPYRIGHT ". " LUAJIT_URL "\n", stdout); +} + +static void print_jit_status(lua_State *L) +{ + int n; + const char *s; + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit"); /* Get jit.* module table. */ + lua_remove(L, -2); + lua_getfield(L, -1, "status"); + lua_remove(L, -2); + n = lua_gettop(L); + lua_call(L, 0, LUA_MULTRET); + fputs(lua_toboolean(L, n) ? "JIT: ON" : "JIT: OFF", stdout); + for (n++; (s = lua_tostring(L, n)); n++) { + putc(' ', stdout); + fputs(s, stdout); + } + putc('\n', stdout); +} + +static int getargs(lua_State *L, char **argv, int n) +{ + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i = n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i = 0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + +static int dofile(lua_State *L, const char *name) +{ + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + +static int dostring(lua_State *L, const char *s, const char *name) +{ + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + +static int dolibrary(lua_State *L, const char *name) +{ + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + +static void write_prompt(lua_State *L, int firstline) +{ + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2; + fputs(p, stdout); + fflush(stdout); + lua_pop(L, 1); /* remove global */ +} + +static int incomplete(lua_State *L, int status) +{ + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + +static int pushline(lua_State *L, int firstline) +{ + char buf[LUA_MAXINPUT]; + write_prompt(L, firstline); + if (fgets(buf, LUA_MAXINPUT, stdin)) { + size_t len = strlen(buf); + if (len > 0 && buf[len-1] == '\n') + buf[len-1] = '\0'; + if (firstline && buf[0] == '=') + lua_pushfstring(L, "return %s", buf+1); + else + lua_pushstring(L, buf); + return 1; + } + return 0; +} + +static int loadline(lua_State *L) +{ + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_remove(L, 1); /* remove line */ + return status; +} + +static void dotty(lua_State *L) +{ + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, + lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + +static int handle_script(lua_State *L, char **argv, int n) +{ + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + +/* Load add-on module. */ +static int loadjitmodule(lua_State *L) +{ + lua_getglobal(L, "require"); + lua_pushliteral(L, "jit."); + lua_pushvalue(L, -3); + lua_concat(L, 2); + if (lua_pcall(L, 1, 1, 0)) { + const char *msg = lua_tostring(L, -1); + if (msg && !strncmp(msg, "module ", 7)) { + err: + l_message(progname, + "unknown luaJIT command or jit.* modules not installed"); + return 1; + } else { + return report(L, 1); + } + } + lua_getfield(L, -1, "start"); + if (lua_isnil(L, -1)) goto err; + lua_remove(L, -2); /* Drop module table. */ + return 0; +} + +/* Run command with options. */ +static int runcmdopt(lua_State *L, const char *opt) +{ + int narg = 0; + if (opt && *opt) { + for (;;) { /* Split arguments. */ + const char *p = strchr(opt, ','); + narg++; + if (!p) break; + if (p == opt) + lua_pushnil(L); + else + lua_pushlstring(L, opt, (size_t)(p - opt)); + opt = p + 1; + } + if (*opt) + lua_pushstring(L, opt); + else + lua_pushnil(L); + } + return report(L, lua_pcall(L, narg, 0, 0)); +} + +/* JIT engine control command: try jit library first or load add-on module. */ +static int dojitcmd(lua_State *L, const char *cmd) +{ + const char *opt = strchr(cmd, '='); + lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd)); + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit"); /* Get jit.* module table. */ + lua_remove(L, -2); + lua_pushvalue(L, -2); + lua_gettable(L, -2); /* Lookup library function. */ + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); /* Drop non-function and jit.* table, keep module name. */ + if (loadjitmodule(L)) + return 1; + } else { + lua_remove(L, -2); /* Drop jit.* table. */ + } + lua_remove(L, -2); /* Drop module name. */ + return runcmdopt(L, opt ? opt+1 : opt); +} + +/* Optimization flags. */ +static int dojitopt(lua_State *L, const char *opt) +{ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, -1, "jit.opt"); /* Get jit.opt.* module table. */ + lua_remove(L, -2); + lua_getfield(L, -1, "start"); + lua_remove(L, -2); + return runcmdopt(L, opt); +} + +/* Save or list bytecode. */ +static int dobytecode(lua_State *L, char **argv) +{ + int narg = 0; + lua_pushliteral(L, "bcsave"); + if (loadjitmodule(L)) + return 1; + if (argv[0][2]) { + narg++; + argv[0][1] = '-'; + lua_pushstring(L, argv[0]+1); + } + for (argv++; *argv != NULL; narg++, argv++) + lua_pushstring(L, *argv); + return report(L, lua_pcall(L, narg, 0, 0)); +} + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + +#define FLAGS_INTERACTIVE 1 +#define FLAGS_VERSION 2 +#define FLAGS_EXEC 4 +#define FLAGS_OPTION 8 +#define FLAGS_NOENV 16 + +static int collectargs(char **argv, int *flags) +{ + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* Not an option? */ + return i; + switch (argv[i][1]) { /* Check option. */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *flags |= FLAGS_INTERACTIVE; + /* fallthrough */ + case 'v': + notail(argv[i]); + *flags |= FLAGS_VERSION; + break; + case 'e': + *flags |= FLAGS_EXEC; + case 'j': /* LuaJIT extension */ + case 'l': + *flags |= FLAGS_OPTION; + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + case 'O': break; /* LuaJIT extension */ + case 'b': /* LuaJIT extension */ + if (*flags) return -1; + *flags |= FLAGS_EXEC; + return 0; + case 'E': + *flags |= FLAGS_NOENV; + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + +static int runargs(lua_State *L, char **argv, int n) +{ + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + case 'j': { /* LuaJIT extension */ + const char *cmd = argv[i] + 2; + if (*cmd == '\0') cmd = argv[++i]; + lua_assert(cmd != NULL); + if (dojitcmd(L, cmd)) + return 1; + break; + } + case 'O': /* LuaJIT extension */ + if (dojitopt(L, argv[i] + 2)) + return 1; + break; + case 'b': /* LuaJIT extension */ + return dobytecode(L, argv+i); + default: break; + } + } + return 0; +} + +static int handle_luainit(lua_State *L) +{ +#if LJ_TARGET_CONSOLE + const char *init = NULL; +#else + const char *init = getenv(LUA_INIT); +#endif + if (init == NULL) + return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + +static struct Smain { + char **argv; + int argc; + int status; +} smain; + +static int pmain(lua_State *L) +{ + struct Smain *s = &smain; + char **argv = s->argv; + int script; + int flags = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + LUAJIT_VERSION_SYM(); /* linker-enforced version check */ + script = collectargs(argv, &flags); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if ((flags & FLAGS_NOENV)) { + lua_pushboolean(L, 1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); + } + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, -1); + if (!(flags & FLAGS_NOENV)) { + s->status = handle_luainit(L); + if (s->status != 0) return 0; + } + if ((flags & FLAGS_VERSION)) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) { + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + } + if ((flags & FLAGS_INTERACTIVE)) { + print_jit_status(L); + dotty(L); + } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) { + if (lua_stdin_is_tty()) { + print_version(); + print_jit_status(L); + dotty(L); + } else { + dofile(L, NULL); /* executes stdin as a file */ + } + } + return 0; +} + +int main(int argc, char **argv) +{ + int status; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + smain.argc = argc; + smain.argv = argv; + status = lua_cpcall(L, pmain, NULL); + report(L, status); + lua_close(L); + return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.h new file mode 100644 index 0000000..be721cf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/luajit.h @@ -0,0 +1,70 @@ +/* +** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ +** +** Copyright (C) 2005-2014 Mike Pall. All rights reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] +*/ + +#ifndef _LUAJIT_H +#define _LUAJIT_H + +#include "lua.h" + +#define LUAJIT_VERSION "LuaJIT 2.0.3" +#define LUAJIT_VERSION_NUM 20003 /* Version 2.0.3 = 02.00.03. */ +#define LUAJIT_VERSION_SYM luaJIT_version_2_0_3 +#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2014 Mike Pall" +#define LUAJIT_URL "http://luajit.org/" + +/* Modes for luaJIT_setmode. */ +#define LUAJIT_MODE_MASK 0x00ff + +enum { + LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ + LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ + + LUAJIT_MODE_FUNC, /* Change mode for a function. */ + LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ + LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ + + LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ + + LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ + + LUAJIT_MODE_MAX +}; + +/* Flags or'ed in to the mode. */ +#define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ +#define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ +#define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ + +/* LuaJIT public C API. */ + +/* Control the JIT engine. */ +LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); + +/* Enforce (dynamic) linker error for version mismatches. Call from main. */ +LUA_API void LUAJIT_VERSION_SYM(void); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lualib.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lualib.h new file mode 100644 index 0000000..1c1e317 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lualib.h @@ -0,0 +1,43 @@ +/* +** Standard library header. +** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +*/ + +#ifndef _LUALIB_H +#define _LUALIB_H + +#include "lua.h" + +#define LUA_FILEHANDLE "FILE*" + +#define LUA_COLIBNAME "coroutine" +#define LUA_MATHLIBNAME "math" +#define LUA_STRLIBNAME "string" +#define LUA_TABLIBNAME "table" +#define LUA_IOLIBNAME "io" +#define LUA_OSLIBNAME "os" +#define LUA_LOADLIBNAME "package" +#define LUA_DBLIBNAME "debug" +#define LUA_BITLIBNAME "bit" +#define LUA_JITLIBNAME "jit" +#define LUA_FFILIBNAME "ffi" + +LUALIB_API int luaopen_base(lua_State *L); +LUALIB_API int luaopen_math(lua_State *L); +LUALIB_API int luaopen_string(lua_State *L); +LUALIB_API int luaopen_table(lua_State *L); +LUALIB_API int luaopen_io(lua_State *L); +LUALIB_API int luaopen_os(lua_State *L); +LUALIB_API int luaopen_package(lua_State *L); +LUALIB_API int luaopen_debug(lua_State *L); +LUALIB_API int luaopen_bit(lua_State *L); +LUALIB_API int luaopen_jit(lua_State *L); +LUALIB_API int luaopen_ffi(lua_State *L); + +LUALIB_API void luaL_openlibs(lua_State *L); + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.c new file mode 100644 index 0000000..8010a45 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.c @@ -0,0 +1,227 @@ +/* +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#define error(S,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)!=0); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + error(S,"bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f; + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); + f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + S->L->nCcalls--; + return f; +} + +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.h new file mode 100644 index 0000000..c80189d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lundump.h @@ -0,0 +1,36 @@ +/* +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.c new file mode 100644 index 0000000..ee3256a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.c @@ -0,0 +1,763 @@ +/* +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + if (!ttisnil(oldval) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (ttisnil(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, const TValue *rb, + const TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.h new file mode 100644 index 0000000..bfe4f56 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.c new file mode 100644 index 0000000..293edd5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.c @@ -0,0 +1,82 @@ +/* +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.h b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.h new file mode 100644 index 0000000..51d695d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/msvcbuild.bat b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/msvcbuild.bat new file mode 100644 index 0000000..9160e0f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/msvcbuild.bat @@ -0,0 +1,113 @@ +@rem Script to build LuaJIT with MSVC. +@rem Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +@rem +@rem Either open a "Visual Studio .NET Command Prompt" +@rem (Note that the Express Edition does not contain an x64 compiler) +@rem -or- +@rem Open a "Windows SDK Command Shell" and set the compiler environment: +@rem setenv /release /x86 +@rem -or- +@rem setenv /release /x64 +@rem +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL + +@setlocal +@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set LJLIB=lib /nologo /nodefaultlib +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set LJDLLNAME=lua51.dll +@set LJLIBNAME=lua51.lib +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64 +@set LJARCH=x64 +@minilua +@if errorlevel 8 goto :X64 +@set DASMFLAGS=-D WIN -D JIT -D FFI +@set LJARCH=x86 +:X64 +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m peobj -o lj_vm.obj +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% /Zi +@set LJLINK=%LJLINK% /debug +:NODEBUG +@if "%1"=="amalg" goto :AMALGDLL +@if "%1"=="static" goto :STATIC +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :MTDLL +:STATIC +%LJCOMPILE% lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :MTDLL +:AMALGDLL +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c +@if errorlevel 1 goto :BAD +%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj +@if errorlevel 1 goto :BAD +:MTDLL +if exist %LJDLLNAME%.manifest^ + %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2 + +%LJCOMPILE% luajit.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME% +@if errorlevel 1 goto :BAD +if exist luajit.exe.manifest^ + %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe + +@del *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for Windows/%LJARCH% === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo You must open a "Visual Studio .NET Command Prompt" to run this script +:END diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/print.c b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/print.c new file mode 100644 index 0000000..e240cfc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/print.c @@ -0,0 +1,227 @@ +/* +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lundump.h" + +#define PrintFunction luaU_print + +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) + +static void PrintString(const TString* ts) +{ + const char* s=getstr(ts); + size_t i,n=ts->tsv.len; + putchar('"'); + for (i=0; ik[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf(LUA_NUMBER_FMT,nvalue(o)); + break; + case LUA_TSTRING: + PrintString(rawtsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); + break; + case iABx: + if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); + break; + case iAsBx: + if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); + break; + case OP_GETGLOBAL: + case OP_SETGLOBAL: + printf("\t; %s",svalue(&f->k[bx])); + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_DIV: + case OP_POW: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); + else printf("\t; %d",c); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=getstr(f->source); + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintConstants(const Proto* f) +{ + int i,n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } +} + +static void PrintUpvalues(const Proto* f) +{ + int i,n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + if (f->upvalues==NULL) return; + for (i=0; iupvalues[i])); + } +} + +void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) + { + PrintConstants(f); + PrintLocals(f); + PrintUpvalues(f); + } + for (i=0; ip[i],full); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ps4build.bat b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ps4build.bat new file mode 100644 index 0000000..42fc9a6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/ps4build.bat @@ -0,0 +1,103 @@ +@rem Script to build LuaJIT with the PS4 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler) +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL +@if not defined SCE_ORBIS_SDK_DIR goto :FAIL + +@setlocal +@rem ---- Host compiler ---- +@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@rem Check for 64 bit host compiler. +@minilua +@if not errorlevel 8 goto :FAIL + +@set DASMFLAGS=-D P64 +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m elfasm -o lj_vm.s +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@rem ---- Cross compiler ---- +@set LJCOMPILE="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-clang" -c -Wall -DLUAJIT_DISABLE_FFI +@set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus +@set INCLUDE="" + +orbis-as -o lj_vm.o lj_vm.s + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% -g -O0 +@set TARGETLIB=libluajitD.a +goto :BUILD +:NODEBUG +@set LJCOMPILE=%LJCOMPILE% -O2 +@set TARGETLIB=libluajit.a +:BUILD +del %TARGETLIB% +@if "%1"=="amalg" goto :AMALG +for %%f in (lj_*.c lib_*.c) do ( + %LJCOMPILE% %%f + @if errorlevel 1 goto :BAD +) + +%LJLIB% %TARGETLIB% lj_*.o lib_*.o +@if errorlevel 1 goto :BAD +@goto :NOAMALG +:AMALG +%LJCOMPILE% ljamalg.c +@if errorlevel 1 goto :BAD +%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o +@if errorlevel 1 goto :BAD +:NOAMALG + +@del *.o *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for PS4 === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo To run this script you must open a "Visual Studio .NET Command Prompt" +@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too. +:END diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_arm.dasc b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_arm.dasc new file mode 100644 index 0000000..82cba90 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_arm.dasc @@ -0,0 +1,4487 @@ +|// Low-level VM code for ARM CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch arm +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +| +|// The following must be C callee-save. +|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding. +|.define KBASE, r5 // Constants of current Lua function. +|.define PC, r6 // Next PC. +|.define DISPATCH, r7 // Opcode dispatch table. +|.define LREG, r8 // Register holding lua_State (also in SAVE_L). +| +|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+. +|.define BASE, r9 // Base of current Lua stack frame. +| +|// The following temporaries are not saved across C calls, except for RA/RC. +|.define RA, r10 // Callee-save. +|.define RC, r11 // Callee-save. +|.define RB, r12 +|.define OP, r12 // Overlaps RB, must not be lr. +|.define INS, lr +| +|// Calling conventions. Also used as temporaries. +|.define CARG1, r0 +|.define CARG2, r1 +|.define CARG3, r2 +|.define CARG4, r3 +|.define CARG12, r0 // For 1st soft-fp double. +|.define CARG34, r2 // For 2nd soft-fp double. +| +|.define CRET1, r0 +|.define CRET2, r1 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define SAVE_R4, [sp, #28] +|.define CFRAME_SPACE, #28 +|.define SAVE_ERRF, [sp, #24] +|.define SAVE_NRES, [sp, #20] +|.define SAVE_CFRAME, [sp, #16] +|.define SAVE_L, [sp, #12] +|.define SAVE_PC, [sp, #8] +|.define SAVE_MULTRES, [sp, #4] +|.define ARG5, [sp] +| +|.define TMPDhi, [sp, #4] +|.define TMPDlo, [sp] +|.define TMPD, [sp] +|.define TMPDp, sp +| +|.if FPU +|.macro saveregs +| push {r5, r6, r7, r8, r9, r10, r11, lr} +| vpush {d8-d15} +| sub sp, sp, CFRAME_SPACE+4 +| str r4, SAVE_R4 +|.endmacro +|.macro restoreregs_ret +| ldr r4, SAVE_R4 +| add sp, sp, CFRAME_SPACE+4 +| vpop {d8-d15} +| pop {r5, r6, r7, r8, r9, r10, r11, pc} +|.endmacro +|.else +|.macro saveregs +| push {r4, r5, r6, r7, r8, r9, r10, r11, lr} +| sub sp, sp, CFRAME_SPACE +|.endmacro +|.macro restoreregs_ret +| add sp, sp, CFRAME_SPACE +| pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} +|.endmacro +|.endif +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// Trap for not-yet-implemented parts. +|.macro NYI; ud; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_FUNC, #-8 +|.define FRAME_PC, #-4 +| +|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro +|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro +|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro +|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro +|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| ldrb OP, [PC] +|.endmacro +|.macro ins_NEXT2 +| ldr INS, [PC], #4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT3 +| ldr OP, [DISPATCH, OP, lsl #2] +| decode_RA8 RA, INS +| decode_RD RC, INS +| bx OP +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +| ins_NEXT3 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +| .define ins_next3, ins_NEXT3 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| .endmacro +| .macro ins_next3 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Avoid register name substitution for field name. +#define field_pc pc +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| ldr PC, LFUNC:CARG3->field_pc +| ldrb OP, [PC] // STALL: load PC. early PC. +| ldr INS, [PC], #4 +| ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP. +| decode_RA8 RA, INS +| add RA, RA, BASE +| bx OP +|.endmacro +| +|.macro ins_call +| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| str PC, [BASE, FRAME_PC] +| ins_callt // STALL: locked PC. +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro +|.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro +|.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro +|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro +|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro +|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotcheck, delta +| lsr CARG1, PC, #1 +| and CARG1, CARG1, #126 +| sub CARG1, CARG1, #-GG_DISP2HOT +| ldrh CARG2, [DISPATCH, CARG1] +| subs CARG2, CARG2, #delta +| strh CARG2, [DISPATCH, CARG1] +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP +| blo ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL +| blo ->vm_hotcall +|.endmacro +| +|// Set current VM state. +|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro +|.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)] +| bic mark, mark, #LJ_GC_BLACK // black2gray(tab) +| str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)] +| strb mark, tab->marked +| str tmp, tab->gclist +|.endmacro +| +|.macro .IOS, a, b +|.if IOS +| a, b +|.endif +|.endmacro +| +|//----------------------------------------------------------------------- + +#if !LJ_DUALNUM +#error "Only dual-number mode supported for ARM target" +#endif + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: RB = previous base. + | tst PC, #FRAME_P + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame. + | mvn CARG2, #~LJ_TTRUE + | mov BASE, RB + | // Prepending may overwrite the pcall frame, so do it at the end. + | str CARG2, [RA, FRAME_PC] // Prepend true to results. + | sub RA, RA, #8 + | + |->vm_returnc: + | adds RC, RC, #8 // RC = (nresults+1)*8. + | mov CRET1, #LUA_YIELD + | beq ->vm_unwind_c_eh + | str RC, SAVE_MULTRES + | ands CARG1, PC, #FRAME_TYPE + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return + | // CARG1 = PC & FRAME_TYPE + | bic RB, PC, #FRAME_TYPEP + | cmp CARG1, #FRAME_C + | sub RB, BASE, RB // RB = previous base. + | bne ->vm_returnp + | + | str RB, L->base + | ldr KBASE, SAVE_NRES + | mv_vmstate CARG4, C + | sub BASE, BASE, #8 + | subs CARG3, RC, #8 + | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8 + | st_vmstate CARG4 + | beq >2 + |1: + | subs CARG3, CARG3, #8 + | ldrd CARG12, [RA], #8 + | strd CARG12, [BASE], #8 + | bne <1 + |2: + | cmp KBASE, RC // More/less results wanted? + | bne >6 + |3: + | str BASE, L->top // Store new top. + | + |->vm_leave_cp: + | ldr RC, SAVE_CFRAME // Restore previous C frame. + | mov CRET1, #0 // Ok return status for vm_pcall. + | str RC, L->cframe + | + |->vm_leave_unw: + | restoreregs_ret + | + |6: + | blt >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | ldr CARG3, L->maxstack + | mvn CARG2, #~LJ_TNIL + | cmp BASE, CARG3 + | bhs >8 + | str CARG2, [BASE, #4] + | add RC, RC, #8 + | add BASE, BASE, #8 + | b <2 + | + |7: // Less results wanted. + | sub CARG1, RC, KBASE + | cmp KBASE, #0 // LUA_MULTRET+1 case? + | subne BASE, BASE, CARG1 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | str BASE, L->top // Save current top held in BASE (yes). + | mov CARG2, KBASE + | mov CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mov sp, CARG1 + | mov CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | ldr L, SAVE_L + | mv_vmstate CARG4, C + | ldr GL:CARG3, L->glref + | str CARG4, GL:CARG3->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. + | mov sp, CARG1 + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | ldr L, SAVE_L + | mov MASKR8, #255 + | mov RC, #16 // 2 results: false + error message. + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | ldr BASE, L->base + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | mvn CARG1, #~LJ_TFALSE + | sub RA, BASE, #8 // Results start at BASE-8. + | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame. + | add DISPATCH, DISPATCH, #GG_G2DISP + | mv_vmstate CARG2, INTERP + | str CARG1, [BASE, #-4] // Prepend false to error message. + | st_vmstate CARG2 + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | // CARG1 = L + | mov CARG2, #LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | mov CARG1, L + | str BASE, L->base + | add PC, PC, #4 // Must point after first instruction. + | str RC, L->top + | lsr CARG3, RA, #3 + |2: + | // L->base = new base, L->top = top + | str PC, SAVE_PC + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | ldr RC, L->top + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | sub NARGS8:RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mov L, CARG1 + | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table. + | mov BASE, CARG2 + | add DISPATCH, DISPATCH, #GG_G2DISP + | str L, SAVE_L + | mov PC, #FRAME_CP + | str CARG3, SAVE_NRES + | add CARG2, sp, #CFRAME_RESUME + | ldrb CARG1, L->status + | str CARG3, SAVE_ERRF + | str CARG2, L->cframe + | str CARG3, SAVE_CFRAME + | cmp CARG1, #0 + | str L, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mov RA, BASE + | ldr BASE, L->base + | ldr CARG1, L->top + | mov MASKR8, #255 + | strb CARG3, L->status + | sub RC, CARG1, BASE + | ldr PC, [BASE, FRAME_PC] + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | mv_vmstate CARG2, INTERP + | add RC, RC, #8 + | ands CARG1, PC, #FRAME_TYPE + | st_vmstate CARG2 + | str RC, SAVE_MULTRES + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | mov PC, #FRAME_CP + | str CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | mov PC, #FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | ldr RC, L:CARG1->cframe + | str CARG3, SAVE_NRES + | mov L, CARG1 + | str CARG1, SAVE_L + | mov BASE, CARG2 + | str sp, L->cframe // Add our C frame to cframe chain. + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | str CARG1, SAVE_PC // Any value outside of bytecode is ok. + | str RC, SAVE_CFRAME + | add DISPATCH, DISPATCH, #GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | ldr RB, L->base // RB = old base (for vmeta_call). + | ldr CARG1, L->top + | mov MASKR8, #255 + | add PC, PC, BASE + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | sub PC, PC, RB // PC = frame delta + frame type + | mv_vmstate CARG2, INTERP + | sub NARGS8:RC, CARG1, BASE + | st_vmstate CARG2 + | + |->vm_call_dispatch: + | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC + | ldrd CARG34, [BASE, FRAME_FUNC] + | checkfunc CARG4, ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mov L, CARG1 + | ldr RA, L:CARG1->stack + | str CARG1, SAVE_L + | ldr RB, L->top + | str CARG1, SAVE_PC // Any value outside of bytecode is ok. + | ldr RC, L->cframe + | sub RA, RA, RB // Compute -savestack(L, L->top). + | str sp, L->cframe // Add our C frame to cframe chain. + | mov RB, #0 + | str RA, SAVE_NRES // Neg. delta means cframe w/o frame. + | str RB, SAVE_ERRF // No error function. + | str RC, SAVE_CFRAME + | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud) + | ldr DISPATCH, L->glref // Setup pointer to dispatch table. + | movs BASE, CRET1 + | mov PC, #FRAME_CP + | add DISPATCH, DISPATCH, #GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8 + | ldr LFUNC:CARG3, [RB, FRAME_FUNC] + | ldr CARG1, [BASE, #-16] // Get continuation. + | mov CARG4, BASE + | mov BASE, RB // Restore caller BASE. + |.if FFI + | cmp CARG1, #1 + |.endif + | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC]. + | ldr CARG3, LFUNC:CARG3->field_pc + | mvn INS, #~LJ_TNIL + | add CARG2, RA, RC + | str INS, [CARG2, #-4] // Ensure one valid arg. + |.if FFI + | bls >1 + |.endif + | ldr KBASE, [CARG3, #PC2PROTO(k)] + | // BASE = base, RA = resultptr, CARG4 = meta base + | bx CARG1 + | + |.if FFI + |1: + | beq ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + | ldr CARG3, [BASE, FRAME_FUNC] + | sub CARG4, CARG4, #16 + | sub RC, CARG4, BASE + | b ->vm_call_tail + |.endif + | + |->cont_cat: // RA = resultptr, CARG4 = meta base + | ldr INS, [PC, #-4] + | sub CARG2, CARG4, #16 + | ldrd CARG34, [RA] + | str BASE, L->base + | decode_RB8 RC, INS + | decode_RA8 RA, INS + | add CARG1, BASE, RC + | subs CARG1, CARG2, CARG1 + | strdne CARG34, [CARG2] + | movne CARG3, CARG1 + | bne ->BC_CAT_Z + | strd CARG34, [BASE, RA] + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | add CARG2, BASE, RB + | b >2 + | + |->vmeta_tgets: + | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) + | mvn CARG4, #~LJ_TTAB + | str TAB:RB, [CARG2] + | str CARG4, [CARG2, #4] + |2: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tgetb: // RC = index + | decode_RB8 RB, INS + | str RC, TMPDlo + | mvn CARG4, #~LJ_TISNUM + | add CARG2, BASE, RB + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tgetv: + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | beq >3 + | ldrd CARG34, [CRET1] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | rsb CARG1, BASE, #FRAME_CONT + | ldr BASE, L->top + | mov NARGS8:RC, #16 // 2 args for func(t, k). + | str PC, [BASE, #-12] // [cont|PC] + | add PC, CARG1, BASE + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | add CARG2, BASE, RB + | b >2 + | + |->vmeta_tsets: + | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) + | mvn CARG4, #~LJ_TTAB + | str TAB:RB, [CARG2] + | str CARG4, [CARG2, #4] + |2: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tsetb: // RC = index + | decode_RB8 RB, INS + | str RC, TMPDlo + | mvn CARG4, #~LJ_TISNUM + | add CARG2, BASE, RB + | str CARG4, TMPDhi + | mov CARG3, TMPDp + | b >1 + | + |->vmeta_tsetv: + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | ldrd CARG34, [BASE, RA] + | beq >3 + | ins_next1 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | strd CARG34, [CRET1] + | ins_next2 + | ins_next3 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | rsb CARG1, BASE, #FRAME_CONT + | ldr BASE, L->top + | mov NARGS8:RC, #24 // 3 args for func(t, k, v). + | strd CARG34, [BASE, #16] // Copy value to third argument. + | str PC, [BASE, #-12] // [cont|PC] + | add PC, CARG1, BASE + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mov CARG1, L + | sub PC, PC, #4 + | mov CARG2, RA + | str BASE, L->base + | mov CARG3, RC + | str PC, SAVE_PC + | decode_OP CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | .IOS ldr BASE, L->base + | cmp CRET1, #1 + | bhi ->vmeta_binop + |4: + | ldrh RB, [PC, #2] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | subhs PC, RB, #0x20000 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | ldr INS, [PC, #-4] + | ldrd CARG12, [RA] + | decode_RA8 CARG3, INS + | strd CARG12, [BASE, CARG3] + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | ldr CARG2, [RA, #4] + | mvn CARG1, #~LJ_TTRUE + | cmp CARG1, CARG2 // Branch if result is true. + | b <4 + | + |->cont_condf: // RA = resultptr + | ldr CARG2, [RA, #4] + | checktp CARG2, LJ_TFALSE // Branch if result is false. + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | sub PC, PC, #4 + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |->vmeta_equal_cd: + |.if FFI + | sub PC, PC, #4 + | str BASE, L->base + | mov CARG1, L + | mov CARG2, INS + | str PC, SAVE_PC + | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vn: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_nv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG4, BASE, RB + | add CARG3, KBASE, RC + | b >1 + | + |->vmeta_unm: + | ldr INS, [PC, #-8] + | sub PC, PC, #4 + | add CARG3, BASE, RC + | add CARG4, BASE, RC + | b >1 + | + |->vmeta_arith_vv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |1: + | decode_OP OP, INS + | add CARG2, BASE, RA + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | str OP, ARG5 + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub CARG2, CRET1, BASE + | str PC, [CRET1, #-12] // [cont|PC] + | add PC, CARG2, #FRAME_CONT + | mov BASE, CRET1 + | mov NARGS8:RC, #16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: + | add CARG2, BASE, RC + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). + | .IOS ldr BASE, L->base +#if LJ_52 + | cmp CRET1, #0 + | bne ->vmeta_binop // Binop call for compatibility. + | ldr TAB:CARG1, [BASE, RC] + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // RB = old base, BASE = new base, RC = nargs*8 + | mov CARG1, L + | str RB, L->base // This is the callers base! + | sub CARG2, BASE, #8 + | str PC, SAVE_PC + | add CARG3, BASE, NARGS8:RC + | .IOS mov RA, BASE + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | .IOS mov BASE, RA + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. + | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mov CARG1, L + | str BASE, L->base + | sub CARG2, RA, #8 + | str PC, SAVE_PC + | add CARG3, RA, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | .IOS ldr BASE, L->base + | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here. + | ldr PC, [BASE, FRAME_PC] + | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. + | b ->BC_CALLT2_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mov CARG1, L + | str BASE, L->base + | mov CARG2, RA + | str PC, SAVE_PC + | bl extern lj_meta_for // (lua_State *L, TValue *base) + | .IOS ldr BASE, L->base + |.if JIT + | ldrb OP, [PC, #-4] + |.endif + | ldr INS, [PC, #-4] + |.if JIT + | cmp OP, #BC_JFORI + |.endif + | decode_RA8 RA, INS + | decode_RD RC, INS + |.if JIT + | beq =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | checktp CARG2, LJ_TISNUM + | cmnlo CARG4, #-LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_d, name + | .ffunc name + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 + | vldr d0, [BASE] + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |.macro .ffunc_dd, name + | .ffunc name + | ldr CARG2, [BASE, #4] + | ldr CARG4, [BASE, #12] + | cmp NARGS8:RC, #16 + | vldr d0, [BASE] + | vldr d1, [BASE, #8] + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | cmnlo CARG4, #-LJ_TISNUM + | bhs ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2. + |.macro ffgccheck + | ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)] + | cmp CARG1, CARG2 + | blge ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | checktp CARG2, LJ_TTRUE + | bhi ->fff_fallback + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + | mov RB, BASE + | subs RA, NARGS8:RC, #8 + | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8. + | beq ->fff_res // Done if exactly 1 argument. + |1: + | ldrd CARG12, [RB, #8] + | subs RA, RA, #8 + | strd CARG12, [RB], #8 + | bne <1 + | b ->fff_res + | + |.ffunc type + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | mvnlo CARG2, #~LJ_TISNUM + | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1 + | lsl CARG4, CARG4, #3 + | ldrd CARG12, [CFUNC:CARG3, CARG4] + | b ->fff_restv + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktp CARG2, LJ_TTAB + | cmnne CARG2, #-LJ_TUDATA + | bne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | ldr TAB:RB, TAB:CARG1->metatable + |2: + | mvn CARG2, #~LJ_TNIL + | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])] + | cmp TAB:RB, #0 + | beq ->fff_restv + | ldr CARG3, TAB:RB->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:RB->node + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + |3: // Rearranged logic, because we expect _not_ to find the key. + | ldrd CARG34, NODE:INS->key // STALL: early NODE:INS. + | ldrd CARG12, NODE:INS->val + | ldr NODE:INS, NODE:INS->next + | checktp CARG4, LJ_TSTR + | cmpeq CARG3, STR:RC + | beq >5 + | cmp NODE:INS, #0 + | bne <3 + |4: + | mov CARG1, RB // Use metatable as default result. + | mvn CARG2, #~LJ_TTAB + | b ->fff_restv + |5: + | checktp CARG2, LJ_TNIL + | bne ->fff_restv + | b <4 + | + |6: + | checktp CARG2, LJ_TISNUM + | mvnhs CARG2, CARG2 + | movlo CARG2, #~LJ_TISNUM + | add CARG4, DISPATCH, CARG2, lsl #2 + | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])] + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | checktp CARG2, LJ_TTAB + | ldreq TAB:RB, TAB:CARG1->metatable + | checktpeq CARG4, LJ_TTAB + | ldrbeq CARG4, TAB:CARG1->marked + | cmpeq TAB:RB, #0 + | bne ->fff_fallback + | tst CARG4, #LJ_GC_BLACK // isblack(table) + | str TAB:CARG3, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, CARG4, CARG3 + | b ->fff_restv + | + |.ffunc rawget + | ldrd CARG34, [BASE] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | mov CARG2, CARG3 + | checktab CARG4, ->fff_fallback + | mov CARG1, L + | add CARG3, BASE, #8 + | .IOS mov RA, BASE + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | .IOS mov BASE, RA + | ldrd CARG12, [CRET1] + | b ->fff_restv + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | bne ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bls ->fff_restv + | b ->fff_fallback + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checktp CARG2, LJ_TSTR + | // A __tostring method in the string base metatable is ignored. + | beq ->fff_restv + | // Handle numbers inline, unless a number base metatable is present. + | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])] + | str BASE, L->base + | checktp CARG2, LJ_TISNUM + | cmpls CARG4, #0 + | str PC, SAVE_PC // Redundant (but a defined value). + | bhi ->fff_fallback + | ffgccheck + | mov CARG1, L + | mov CARG2, BASE + | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) + | // Returns GCstr *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc_1 next + | mvn CARG4, #~LJ_TNIL + | checktab CARG2, ->fff_fallback + | strd CARG34, [BASE, NARGS8:RC] // Set missing 2nd arg to nil. + | ldr PC, [BASE, FRAME_PC] + | mov CARG2, CARG1 + | str BASE, L->base // Add frame since C call can throw. + | mov CARG1, L + | str BASE, L->top // Dummy frame length is ok. + | add CARG3, BASE, #8 + | str PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | .IOS ldr BASE, L->base + | cmp CRET1, #0 + | mvneq CRET2, #~LJ_TNIL + | beq ->fff_restv // End of traversal: return nil. + | ldrd CARG12, [BASE, #8] // Copy key and value to results. + | ldrd CARG34, [BASE, #16] + | mov RC, #(2+1)*8 + | strd CARG12, [BASE, #-8] + | strd CARG34, [BASE] + | b ->fff_res + | + |.ffunc_1 pairs + | checktab CARG2, ->fff_fallback +#if LJ_52 + | ldr TAB:RB, TAB:CARG1->metatable +#endif + | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0] + | ldr PC, [BASE, FRAME_PC] +#if LJ_52 + | cmp TAB:RB, #0 + | bne ->fff_fallback +#endif + | mvn CARG2, #~LJ_TNIL + | mov RC, #(3+1)*8 + | strd CFUNC:CARG34, [BASE, #-8] + | str CARG2, [BASE, #12] + | b ->fff_res + | + |.ffunc_2 ipairs_aux + | checktp CARG2, LJ_TTAB + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | ldr RB, TAB:CARG1->asize + | ldr RC, TAB:CARG1->array + | add CARG3, CARG3, #1 + | ldr PC, [BASE, FRAME_PC] + | cmp CARG3, RB + | add RC, RC, CARG3, lsl #3 + | strd CARG34, [BASE, #-8] + | ldrdlo CARG12, [RC] + | mov RC, #(0+1)*8 + | bhs >2 // Not in array part? + |1: + | checktp CARG2, LJ_TNIL + | movne RC, #(2+1)*8 + | strdne CARG12, [BASE] + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | ldr RB, TAB:CARG1->hmask + | mov CARG2, CARG3 + | cmp RB, #0 + | beq ->fff_res + | .IOS mov RA, BASE + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | .IOS mov BASE, RA + | cmp CRET1, #0 + | beq ->fff_res + | ldrd CARG12, [CRET1] + | b <1 + | + |.ffunc_1 ipairs + | checktab CARG2, ->fff_fallback +#if LJ_52 + | ldr TAB:RB, TAB:CARG1->metatable +#endif + | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0] + | ldr PC, [BASE, FRAME_PC] +#if LJ_52 + | cmp TAB:RB, #0 + | bne ->fff_fallback +#endif + | mov CARG1, #0 + | mvn CARG2, #~LJ_TISNUM + | mov RC, #(3+1)*8 + | strd CFUNC:CARG34, [BASE, #-8] + | strd CARG12, [BASE, #8] + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. + | mov RB, BASE + | add BASE, BASE, #8 + | moveq PC, #8+FRAME_PCALL + | movne PC, #8+FRAME_PCALLH + | sub NARGS8:RC, NARGS8:RC, #8 + | b ->vm_call_dispatch + | + |.ffunc_2 xpcall + | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)] + | checkfunc CARG4, ->fff_fallback // Traceback must be a function. + | mov RB, BASE + | strd CARG12, [BASE, #8] // Swap function and traceback. + | strd CARG34, [BASE] + | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. + | add BASE, BASE, #16 + | moveq PC, #16+FRAME_PCALL + | movne PC, #16+FRAME_PCALLH + | sub NARGS8:RC, NARGS8:RC, #16 + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | checktp CARG2, LJ_TTHREAD + | bne ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr + |.endif + | ldr PC, [BASE, FRAME_PC] + | str BASE, L->base + | ldr CARG2, L:CARG1->top + | ldrb RA, L:CARG1->status + | ldr RB, L:CARG1->base + | add CARG3, CARG2, NARGS8:RC + | add CARG4, CARG2, RA + | str PC, SAVE_PC + | cmp CARG4, RB + | beq ->fff_fallback + | ldr CARG4, L:CARG1->maxstack + | ldr RB, L:CARG1->cframe + | cmp RA, #LUA_YIELD + | cmpls CARG3, CARG4 + | cmpls RB, #0 + | bhi ->fff_fallback + |1: + |.if resume + | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC. + | add BASE, BASE, #8 + | sub NARGS8:RC, NARGS8:RC, #8 + |.endif + | str CARG3, L:CARG1->top + | str BASE, L->top + |2: // Move args to coroutine. + | ldrd CARG34, [BASE, RB] + | cmp RB, NARGS8:RC + | strdne CARG34, [CARG2, RB] + | add RB, RB, #8 + | bne <2 + | + | mov CARG3, #0 + | mov L:RA, L:CARG1 + | mov CARG4, #0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | ldr CARG3, L:RA->base + | mv_vmstate CARG2, INTERP + | ldr CARG4, L:RA->top + | st_vmstate CARG2 + | cmp CRET1, #LUA_YIELD + | ldr BASE, L->base + | bhi >8 + | subs RC, CARG4, CARG3 + | ldr CARG1, L->maxstack + | add CARG2, BASE, RC + | beq >6 // No results? + | cmp CARG2, CARG1 + | mov RB, #0 + | bhi >9 // Need to grow stack? + | + | sub CARG4, RC, #8 + | str CARG3, L:RA->top // Clear coroutine stack. + |5: // Move results from coroutine. + | ldrd CARG12, [CARG3, RB] + | cmp RB, CARG4 + | strd CARG12, [BASE, RB] + | add RB, RB, #8 + | bne <5 + |6: + |.if resume + | mvn CARG3, #~LJ_TTRUE + | add RC, RC, #16 + |7: + | str CARG3, [BASE, #-4] // Prepend true/false to results. + | sub RA, BASE, #8 + |.else + | mov RA, BASE + | add RC, RC, #8 + |.endif + | ands CARG1, PC, #FRAME_TYPE + | str PC, SAVE_PC + | str RC, SAVE_MULTRES + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | ldrd CARG12, [CARG4, #-8]! + | mvn CARG3, #~LJ_TFALSE + | mov RC, #(2+1)*8 + | str CARG4, L:RA->top // Remove error from coroutine stack. + | strd CARG12, [BASE] // Copy error message. + | b <7 + |.else + | mov CARG1, L + | mov CARG2, L:RA + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + | // Never returns. + |.endif + | + |9: // Handle stack expansion on return from yield. + | mov CARG1, L + | lsr CARG2, RC, #3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | mov CRET1, #0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | ldr CARG1, L->cframe + | add CARG2, BASE, NARGS8:RC + | str BASE, L->base + | tst CARG1, #CFRAME_RESUME + | str CARG2, L->top + | mov CRET1, #LUA_YIELD + | mov CARG3, #0 + | beq ->fff_fallback + | str CARG3, L->cframe + | strb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.macro math_round, func + | .ffunc_1 math_ .. func + | checktp CARG2, LJ_TISNUM + | beq ->fff_restv + | bhi ->fff_fallback + | // Round FP value and normalize result. + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | bpl >2 // |x| < 1? + | mvn CARG4, #0x3e0 + | subs RB, CARG4, RB, asr #21 + | lsl CARG4, CARG2, #11 + | lsl CARG3, CARG1, #11 + | orr CARG4, CARG4, #0x80000000 + | rsb INS, RB, #32 + | orr CARG4, CARG4, CARG1, lsr #21 + | bls >3 // |x| >= 2^31? + | orr CARG3, CARG3, CARG4, lsl INS + | lsr CARG1, CARG4, RB + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 + | addne CARG1, CARG1, #1 + |.else + | bics CARG3, CARG3, CARG2, asr #31 + | addsne CARG1, CARG1, #1 + | ldrdvs CARG12, >9 + | bvs ->fff_restv + |.endif + | cmp CARG2, #0 + | rsblt CARG1, CARG1, #0 + |1: + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |2: // |x| < 1 + | bcs ->fff_restv // |x| is not finite. + | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1 + | moveq CARG1, #0 + | mvnne CARG1, #0 + |.else + | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1 + | moveq CARG1, #0 + | movne CARG1, #1 + |.endif + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |3: // |x| >= 2^31. Check for x == -(2^31). + | cmpeq CARG4, #0x80000000 + |.if "func" == "floor" + | cmpeq CARG3, #0 + |.endif + | bne >4 + | cmp CARG2, #0 + | movmi CARG1, #0x80000000 + | bmi <1 + |4: + | bl ->vm_..func.._sf + | b ->fff_restv + |.endmacro + | + | math_round floor + | math_round ceil + | + |.align 8 + |9: + | .long 0x00000000, 0x41e00000 // 2^31. + | + |.ffunc_1 math_abs + | checktp CARG2, LJ_TISNUM + | bhi ->fff_fallback + | bicne CARG2, CARG2, #0x80000000 + | bne ->fff_restv + | cmp CARG1, #0 + | rsbslt CARG1, CARG1, #0 + | ldrdvs CARG12, <9 + | // Fallthrough. + | + |->fff_restv: + | // CARG12 = TValue result. + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + |->fff_res1: + | // PC = return. + | mov RC, #(1+1)*8 + |->fff_res: + | // RC = (nresults+1)*8, PC = return. + | ands CARG1, PC, #FRAME_TYPE + | ldreq INS, [PC, #-4] + | str RC, SAVE_MULTRES + | sub RA, BASE, #8 + | bne ->vm_return + | decode_RB8 RB, INS + |5: + | cmp RB, RC // More results expected? + | bhi >6 + | decode_RA8 CARG1, INS + | ins_next1 + | ins_next2 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, CARG1 + | ins_next3 + | + |6: // Fill up results with nil. + | add CARG2, RA, RC + | mvn CARG1, #~LJ_TNIL + | add RC, RC, #8 + | str CARG1, [CARG2, #-4] + | b <5 + | + |.macro math_extern, func + |.if HFABI + | .ffunc_d math_ .. func + |.else + | .ffunc_n math_ .. func + |.endif + | .IOS mov RA, BASE + | bl extern func + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + |.endmacro + | + |.macro math_extern2, func + |.if HFABI + | .ffunc_dd math_ .. func + |.else + | .ffunc_nn math_ .. func + |.endif + | .IOS mov RA, BASE + | bl extern func + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + |.endmacro + | + |.if FPU + | .ffunc_d math_sqrt + | vsqrt.f64 d0, d0 + |->fff_resd: + | ldr PC, [BASE, FRAME_PC] + | vstr d0, [BASE, #-8] + | b ->fff_res1 + |.else + | math_extern sqrt + |.endif + | + |.ffunc math_log + |.if HFABI + | ldr CARG2, [BASE, #4] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | vldr d0, [BASE] + | bne ->fff_fallback + |.else + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | bne ->fff_fallback + |.endif + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + | .IOS mov RA, BASE + | bl extern log + | .IOS mov BASE, RA + |.if HFABI + | b ->fff_resd + |.else + | b ->fff_restv + |.endif + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.if FPU + | .ffunc_d math_rad + | vldr d1, CFUNC:CARG3->upvalue[0] + | vmul.f64 d0, d0, d1 + | b ->fff_resd + |.else + | .ffunc_n math_rad + | ldrd CARG34, CFUNC:CARG3->upvalue[0] + | bl extern __aeabi_dmul + | b ->fff_restv + |.endif + | + |.if HFABI + | .ffunc math_ldexp + | ldr CARG4, [BASE, #4] + | ldrd CARG12, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | vldr d0, [BASE] + | checktp CARG4, LJ_TISNUM + | bhs ->fff_fallback + | checktp CARG2, LJ_TISNUM + | bne ->fff_fallback + | .IOS mov RA, BASE + | bl extern ldexp // (double x, int exp) + | .IOS mov BASE, RA + | b ->fff_resd + |.else + |.ffunc_2 math_ldexp + | checktp CARG2, LJ_TISNUM + | bhs ->fff_fallback + | checktp CARG4, LJ_TISNUM + | bne ->fff_fallback + | .IOS mov RA, BASE + | bl extern ldexp // (double x, int exp) + | .IOS mov BASE, RA + | b ->fff_restv + |.endif + | + |.if HFABI + |.ffunc_d math_frexp + | mov CARG1, sp + | .IOS mov RA, BASE + | bl extern frexp + | .IOS mov BASE, RA + | ldr CARG3, [sp] + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | vstr d0, [BASE, #-8] + | mov RC, #(2+1)*8 + | strd CARG34, [BASE] + | b ->fff_res + |.else + |.ffunc_n math_frexp + | mov CARG3, sp + | .IOS mov RA, BASE + | bl extern frexp + | .IOS mov BASE, RA + | ldr CARG3, [sp] + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | strd CARG12, [BASE, #-8] + | mov RC, #(2+1)*8 + | strd CARG34, [BASE] + | b ->fff_res + |.endif + | + |.if HFABI + |.ffunc_d math_modf + | sub CARG1, BASE, #8 + | ldr PC, [BASE, FRAME_PC] + | .IOS mov RA, BASE + | bl extern modf + | .IOS mov BASE, RA + | mov RC, #(2+1)*8 + | vstr d0, [BASE] + | b ->fff_res + |.else + |.ffunc_n math_modf + | sub CARG3, BASE, #8 + | ldr PC, [BASE, FRAME_PC] + | .IOS mov RA, BASE + | bl extern modf + | .IOS mov BASE, RA + | mov RC, #(2+1)*8 + | strd CARG12, [BASE] + | b ->fff_res + |.endif + | + |.macro math_minmax, name, cond, fcond + |.if FPU + | .ffunc_1 name + | add RB, BASE, RC + | checktp CARG2, LJ_TISNUM + | add RA, BASE, #8 + | bne >4 + |1: // Handle integers. + | ldrd CARG34, [RA] + | cmp RA, RB + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bne >3 + | cmp CARG1, CARG3 + | add RA, RA, #8 + | mov..cond CARG1, CARG3 + | b <1 + |3: // Convert intermediate result to number and continue below. + | vmov s4, CARG1 + | bhi ->fff_fallback + | vldr d1, [RA] + | vcvt.f64.s32 d0, s4 + | b >6 + | + |4: + | vldr d0, [BASE] + | bhi ->fff_fallback + |5: // Handle numbers. + | ldrd CARG34, [RA] + | vldr d1, [RA] + | cmp RA, RB + | bhs ->fff_resd + | checktp CARG4, LJ_TISNUM + | bhs >7 + |6: + | vcmp.f64 d0, d1 + | vmrs + | add RA, RA, #8 + | vmov..fcond.f64 d0, d1 + | b <5 + |7: // Convert integer to number and continue above. + | vmov s4, CARG3 + | bhi ->fff_fallback + | vcvt.f64.s32 d1, s4 + | b <6 + | + |.else + | + | .ffunc_1 name + | checktp CARG2, LJ_TISNUM + | mov RA, #8 + | bne >4 + |1: // Handle integers. + | ldrd CARG34, [BASE, RA] + | cmp RA, RC + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bne >3 + | cmp CARG1, CARG3 + | add RA, RA, #8 + | mov..cond CARG1, CARG3 + | b <1 + |3: // Convert intermediate result to number and continue below. + | bhi ->fff_fallback + | bl extern __aeabi_i2d + | ldrd CARG34, [BASE, RA] + | b >6 + | + |4: + | bhi ->fff_fallback + |5: // Handle numbers. + | ldrd CARG34, [BASE, RA] + | cmp RA, RC + | bhs ->fff_restv + | checktp CARG4, LJ_TISNUM + | bhs >7 + |6: + | bl extern __aeabi_cdcmple + | add RA, RA, #8 + | mov..fcond CARG1, CARG3 + | mov..fcond CARG2, CARG4 + | b <5 + |7: // Convert integer to number and continue above. + | bhi ->fff_fallback + | strd CARG12, TMPD + | mov CARG1, CARG3 + | bl extern __aeabi_i2d + | ldrd CARG34, TMPD + | b <6 + |.endif + |.endmacro + | + | math_minmax math_min, gt, hi + | math_minmax math_max, lt, lo + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr CARG2, ->fff_fallback + | ldr CARG1, STR:CARG1->len + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.ffunc string_byte // Only handle the 1-arg case here. + | ldrd CARG12, [BASE] + | ldr PC, [BASE, FRAME_PC] + | cmp NARGS8:RC, #8 + | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument. + | bne ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end). + | mvn CARG2, #~LJ_TISNUM + | cmp CARG3, #0 + | moveq RC, #(0+1)*8 + | movne RC, #(1+1)*8 + | strd CARG12, [BASE, #-8] + | b ->fff_res + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | ldrd CARG12, [BASE] + | ldr PC, [BASE, FRAME_PC] + | cmp NARGS8:RC, #8 // Need exactly 1 argument. + | checktpeq CARG2, LJ_TISNUM + | bicseq CARG4, CARG1, #255 + | mov CARG3, #1 + | bne ->fff_fallback + | str CARG1, TMPD + | mov CARG2, TMPDp // Points to stack. Little-endian. + |->fff_newstr: + | // CARG2 = str, CARG3 = len. + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #16] + | cmp NARGS8:RC, #16 + | mvn RB, #0 + | beq >1 + | blo ->fff_fallback + | checktp CARG4, LJ_TISNUM + | mov RB, CARG3 + | bne ->fff_fallback + |1: + | ldrd CARG34, [BASE, #8] + | checktp CARG2, LJ_TSTR + | ldreq CARG2, STR:CARG1->len + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end + | add CARG4, CARG2, #1 + | cmp CARG3, #0 // if (start < 0) start += len+1 + | addlt CARG3, CARG3, CARG4 + | cmp CARG3, #1 // if (start < 1) start = 1 + | movlt CARG3, #1 + | cmp RB, #0 // if (end < 0) end += len+1 + | addlt RB, RB, CARG4 + | bic RB, RB, RB, asr #31 // if (end < 0) end = 0 + | cmp RB, CARG2 // if (end > len) end = len + | add CARG1, STR:CARG1, #sizeof(GCstr)-1 + | movgt RB, CARG2 + | add CARG2, CARG1, CARG3 + | subs CARG3, RB, CARG3 // len = end - start + | add CARG3, CARG3, #1 // len += 1 + | bge ->fff_newstr + |->fff_emptystr: + | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty) + | mvn CARG2, #~LJ_TSTR + | b ->fff_restv + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | ldrd CARG12, [BASE] + | ldrd CARG34, [BASE, #8] + | cmp NARGS8:RC, #16 + | bne ->fff_fallback // Exactly 2 arguments + | checktp CARG2, LJ_TSTR + | checktpeq CARG4, LJ_TISNUM + | bne ->fff_fallback + | subs CARG4, CARG3, #1 + | ldr CARG2, STR:CARG1->len + | blt ->fff_emptystr // Count <= 0? + | cmp CARG2, #1 + | blo ->fff_emptystr // Zero-length string? + | bne ->fff_fallback // Fallback for > 1-char strings. + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | ldr CARG1, STR:CARG1[1] + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // Fill buffer with char. + | strb CARG1, [CARG2, CARG4] + | subs CARG4, CARG4, #1 + | bge <1 + | b ->fff_newstr + | + |.ffunc string_reverse + | ffgccheck + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checkstr CARG2, ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | mov CARG4, CARG3 + | add CARG1, STR:CARG1, #sizeof(GCstr) + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // Reverse string copy. + | ldrb RB, [CARG1], #1 + | subs CARG4, CARG4, #1 + | blt ->fff_newstr + | strb RB, [CARG2, CARG4] + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | ldrd CARG12, [BASE] + | cmp NARGS8:RC, #8 + | blo ->fff_fallback + | checkstr CARG2, ->fff_fallback + | ldr CARG3, STR:CARG1->len + | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)] + | mov CARG4, #0 + | add CARG1, STR:CARG1, #sizeof(GCstr) + | cmp RB, CARG3 + | blo ->fff_fallback + |1: // ASCII case conversion. + | ldrb RB, [CARG1, CARG4] + | cmp CARG4, CARG3 + | bhs ->fff_newstr + | sub RC, RB, #lo + | cmp RC, #26 + | eorlo RB, RB, #0x20 + | strb RB, [CARG2, CARG4] + | add CARG4, CARG4, #1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG2, ->fff_fallback + | .IOS mov RA, BASE + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | .IOS mov BASE, RA + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |//-- Bit library -------------------------------------------------------- + | + |// FP number to bit conversion for soft-float. Clobbers r0-r3. + |->vm_tobit_fb: + | bhi ->fff_fallback + |->vm_tobit: + | lsl RB, CARG2, #1 + | adds RB, RB, #0x00200000 + | movpl CARG1, #0 // |x| < 1? + | bxpl lr + | mvn CARG4, #0x3e0 + | subs RB, CARG4, RB, asr #21 + | bmi >1 // |x| >= 2^32? + | lsl CARG4, CARG2, #11 + | orr CARG4, CARG4, #0x80000000 + | orr CARG4, CARG4, CARG1, lsr #21 + | cmp CARG2, #0 + | lsr CARG1, CARG4, RB + | rsblt CARG1, CARG1, #0 + | bx lr + |1: + | add RB, RB, #21 + | lsr CARG4, CARG1, RB + | rsb RB, RB, #20 + | lsl CARG1, CARG2, #12 + | cmp CARG2, #0 + | orr CARG1, CARG4, CARG1, lsl RB + | rsblt CARG1, CARG1, #0 + | bx lr + | + |.macro .ffunc_bit, name + | .ffunc_1 bit_..name + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + |.endmacro + | + |.ffunc_bit tobit + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | mov CARG3, CARG1 + | mov RA, #8 + |1: + | ldrd CARG12, [BASE, RA] + | cmp RA, NARGS8:RC + | add RA, RA, #8 + | bge >2 + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + | ins CARG3, CARG3, CARG1 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, orr + |.ffunc_bit_op bxor, eor + | + |2: + | mvn CARG4, #~LJ_TISNUM + | ldr PC, [BASE, FRAME_PC] + | strd CARG34, [BASE, #-8] + | b ->fff_res1 + | + |.ffunc_bit bswap + | eor CARG3, CARG1, CARG1, ror #16 + | bic CARG3, CARG3, #0x00ff0000 + | ror CARG1, CARG1, #8 + | mvn CARG2, #~LJ_TISNUM + | eor CARG1, CARG1, CARG3, lsr #8 + | b ->fff_restv + | + |.ffunc_bit bnot + | mvn CARG1, CARG1 + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc bit_..name + | ldrd CARG12, [BASE, #8] + | cmp NARGS8:RC, #16 + | blo ->fff_fallback + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + |.if shmod == 0 + | and RA, CARG1, #31 + |.else + | rsb RA, CARG1, #0 + |.endif + | ldrd CARG12, [BASE] + | checktp CARG2, LJ_TISNUM + | blne ->vm_tobit_fb + | ins CARG1, CARG1, RA + | mvn CARG2, #~LJ_TISNUM + | b ->fff_restv + |.endmacro + | + |.ffunc_bit_sh lshift, lsl, 0 + |.ffunc_bit_sh rshift, lsr, 0 + |.ffunc_bit_sh arshift, asr, 0 + |.ffunc_bit_sh rol, ror, 1 + |.ffunc_bit_sh ror, ror, 0 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RC = nargs*8 + | ldr CARG3, [BASE, FRAME_FUNC] + | ldr CARG2, L->maxstack + | add CARG1, BASE, NARGS8:RC + | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC. + | str CARG1, L->top + | ldr CARG3, CFUNC:CARG3->f + | str BASE, L->base + | add CARG1, CARG1, #8*LUA_MINSTACK + | str PC, SAVE_PC // Redundant (but a defined value). + | cmp CARG1, CARG2 + | mov CARG1, L + | bhi >5 // Need to grow stack. + | blx CARG3 // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | ldr BASE, L->base + | cmp CRET1, #0 + | lsl RC, CRET1, #3 + | sub RA, BASE, #8 + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | ldr CARG1, L->top + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | sub NARGS8:RC, CARG1, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | ands CARG1, PC, #FRAME_TYPE + | bic CARG2, PC, #FRAME_TYPEP + | ldreq INS, [PC, #-4] + | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8. + | addeq CARG2, CARG2, #8 + | sub RB, BASE, CARG2 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | mov CARG2, #LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | cmp CARG1, CARG1 // Set zero-flag to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mov RA, lr + | str BASE, L->base + | add CARG2, BASE, NARGS8:RC + | str PC, SAVE_PC // Redundant (but a defined value). + | str CARG2, L->top + | mov CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | ldr BASE, L->base + | mov lr, RA // Help return address predictor. + | ldr CFUNC:CARG3, [BASE, FRAME_FUNC] + | bx lr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent. + | bne >5 + | // Decrement the hookcount for consistency, but always do the call. + | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | tst CARG1, #HOOK_ACTIVE + | bne >1 + | sub CARG2, CARG2, #1 + | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT + | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | b >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | tst CARG1, #HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | decode_OP OP, INS + | add OP, DISPATCH, OP, lsl #2 + | ldr pc, [OP, #GG_DISP2STATIC] + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)] + | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | tst CARG1, #HOOK_ACTIVE // Hook already active? + | bne <5 + | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT + | beq <5 + | subs CARG2, CARG2, #1 + | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)] + | beq >1 + | tst CARG1, #LUA_MASKLINE + | beq <5 + |1: + | mov CARG1, L + | str BASE, L->base + | mov CARG2, PC + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | ldr BASE, L->base + |4: // Re-dispatch to static ins. + | ldrb OP, [PC, #-4] + | ldr INS, [PC, #-4] + | add OP, DISPATCH, OP, lsl #2 + | ldr OP, [OP, #GG_DISP2STATIC] + | decode_RA8 RA, INS + | decode_RD RC, INS + | bx OP + | + |->cont_hook: // Continue from hook yield. + | ldr CARG1, [CARG4, #-24] + | add PC, PC, #4 + | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L). + | sub CARG1, DISPATCH, #-GG_DISP2J + | str PC, SAVE_PC + | ldr CARG3, LFUNC:CARG3->field_pc + | mov CARG2, PC + | str L, [DISPATCH, #DISPATCH_J(L)] + | ldrb CARG3, [CARG3, #PC2PROTO(framesize)] + | str BASE, L->base + | add CARG3, BASE, CARG3, lsl #3 + | str CARG3, L->top + | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) + | b <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mov CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | orr CARG2, PC, #1 + |1: + |.endif + | add CARG4, BASE, RC + | str PC, SAVE_PC + | mov CARG1, L + | str BASE, L->base + | sub RA, RA, BASE + | str CARG4, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | ldr BASE, L->base + | ldr CARG4, L->top + | mov CARG2, #0 + | add RA, BASE, RA + | sub NARGS8:RC, CARG4, BASE + | str CARG2, SAVE_PC // Invalidate for subsequent line hook. + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | ldr INS, [PC, #-4] + | bx CRET1 + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_exit_handler: + |.if JIT + | sub sp, sp, #12 + | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12} + | ldr CARG1, [sp, #64] // Load original value of lr. + | ldr DISPATCH, [lr] // Load DISPATCH. + | add CARG3, sp, #64 // Recompute original value of sp. + | mv_vmstate CARG4, EXIT + | str CARG3, [sp, #52] // Store sp in RID_SP + | st_vmstate CARG4 + | ldr CARG2, [CARG1, #-4]! // Get exit instruction. + | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC. + | str CARG1, [sp, #60] + |.if FPU + | vpush {d0-d15} + |.endif + | lsl CARG2, CARG2, #8 + | add CARG1, CARG1, CARG2, asr #6 + | ldr CARG2, [lr, #4] // Load exit stub group offset. + | sub CARG1, CARG1, lr + | ldr L, [DISPATCH, #DISPATCH_GL(jit_L)] + | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number. + | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)] + | str CARG1, [DISPATCH, #DISPATCH_J(exitno)] + | mov CARG4, #0 + | str L, [DISPATCH, #DISPATCH_J(L)] + | str BASE, L->base + | str CARG4, [DISPATCH, #DISPATCH_GL(jit_L)] + | sub CARG1, DISPATCH, #-GG_DISP2J + | mov CARG2, sp + | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) + | // Returns MULTRES (unscaled) or negated error code. + | ldr CARG2, L->cframe + | ldr BASE, L->base + | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. + | mov sp, CARG2 + | ldr PC, SAVE_PC // Get SAVE_PC. + | str L, SAVE_L // Set SAVE_L (on-trace resume/yield). + | b >1 + |.endif + |->vm_exit_interp: + | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set. + |.if JIT + | ldr L, SAVE_L + |1: + | cmp CARG1, #0 + | blt >3 // Check for error from exit. + | lsl RC, CARG1, #3 + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | str RC, SAVE_MULTRES + | mov CARG3, #0 + | ldr CARG2, LFUNC:CARG2->field_pc + | str CARG3, [DISPATCH, #DISPATCH_GL(jit_L)] + | mv_vmstate CARG4, INTERP + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | // Modified copy of ins_next which handles function header dispatch, too. + | ldrb OP, [PC] + | mov MASKR8, #255 + | ldr INS, [PC], #4 + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | st_vmstate CARG4 + | cmp OP, #BC_FUNCF // Function header? + | ldr OP, [DISPATCH, OP, lsl #2] + | decode_RA8 RA, INS + | lsrlo RC, INS, #16 // No: Decode operands A*8 and D. + | subhs RC, RC, #8 + | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8 + | bx OP + | + |3: // Rethrow error from the right C frame. + | rsb CARG2, CARG1, #0 + | mov CARG1, L + | bl extern lj_err_throw // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called from JIT code. + |// + |// double lj_vm_floor/ceil/trunc(double x); + |.macro vm_round, func, hf + |.if hf == 1 + | vmov CARG1, CARG2, d0 + |.endif + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | bpl >2 // |x| < 1? + | mvn CARG4, #0x3cc + | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. + | bxlo lr // |x| >= 2^52: done. + | mvn CARG4, #1 + | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask + | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask + | subs RB, RB, #32 + | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask + | orrpl CARG3, CARG3, CARG4 + | mvnpl CARG4, #1 + | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) + |.else + | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) + |.endif + |.if hf == 1 + | vmoveq d0, CARG1, CARG2 + |.endif + | bxeq lr // iszero: done. + | mvn CARG4, #1 + | cmp RB, #0 + | lslpl CARG3, CARG4, RB + | mvnmi CARG3, #0 + | add RB, RB, #32 + | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask + | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + | + |2: // |x| < 1: + | bxcs lr // |x| is not finite. + | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo + |.if "func" == "floor" + | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) + |.else + | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) + |.endif + | mov CARG1, #0 // lo = 0 + | and CARG2, CARG2, #0x80000000 + | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0) + | orrne CARG2, CARG2, CARG4 + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + |.endmacro + | + |9: + | .long 0x3ff00000 // hiword(+1.0) + | + |->vm_floor: + |.if HFABI + | vm_round floor, 1 + |.endif + |->vm_floor_sf: + | vm_round floor, 0 + | + |->vm_ceil: + |.if HFABI + | vm_round ceil, 1 + |.endif + |->vm_ceil_sf: + | vm_round ceil, 0 + | + |.macro vm_trunc, hf + |.if JIT + |.if hf == 1 + | vmov CARG1, CARG2, d0 + |.endif + | lsl CARG3, CARG2, #1 + | adds RB, CARG3, #0x00200000 + | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0. + | movpl CARG1, #0 + |.if hf == 1 + | vmovpl d0, CARG1, CARG2 + |.endif + | bxpl lr + | mvn CARG4, #0x3cc + | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. + | bxlo lr // |x| >= 2^52: already done. + | mvn CARG4, #1 + | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask + | subs RB, RB, #32 + | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask + |.if hf == 1 + | vmov d0, CARG1, CARG2 + |.endif + | bx lr + |.endif + |.endmacro + | + |->vm_trunc: + |.if HFABI + | vm_trunc 1 + |.endif + |->vm_trunc_sf: + | vm_trunc 0 + | + | // double lj_vm_mod(double dividend, double divisor); + |->vm_mod: + |.if FPU + | // Special calling convention. Also, RC (r11) is not preserved. + | vdiv.f64 d0, d6, d7 + | mov RC, lr + | vmov CARG1, CARG2, d0 + | bl ->vm_floor_sf + | vmov d0, CARG1, CARG2 + | vmul.f64 d0, d0, d7 + | mov lr, RC + | vsub.f64 d6, d6, d0 + | bx lr + |.else + | push {r0, r1, r2, r3, r4, lr} + | bl extern __aeabi_ddiv + | bl ->vm_floor_sf + | ldrd CARG34, [sp, #8] + | bl extern __aeabi_dmul + | ldrd CARG34, [sp] + | eor CARG2, CARG2, #0x80000000 + | bl extern __aeabi_dadd + | add sp, sp, #20 + | pop {pc} + |.endif + | + | // int lj_vm_modi(int dividend, int divisor); + |->vm_modi: + | ands RB, CARG1, #0x80000000 + | rsbmi CARG1, CARG1, #0 // a = |dividend| + | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor). + | cmp CARG2, #0 + | rsbmi CARG2, CARG2, #0 // b = |divisor| + | subs CARG4, CARG2, #1 + | cmpne CARG1, CARG2 + | moveq CARG1, #0 // if (b == 1 || a == b) a = 0 + | tsthi CARG2, CARG4 + | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1 + | bls >1 + | // Use repeated subtraction to get the remainder. + | clz CARG3, CARG1 + | clz CARG4, CARG2 + | sub CARG4, CARG4, CARG3 + | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8 + | addne pc, pc, CARG3, lsl #3 // Duff's device. + | nop + { + int i; + for (i = 31; i >= 0; i--) { + | cmp CARG1, CARG2, lsl #i + | subhs CARG1, CARG1, CARG2, lsl #i + } + } + |1: + | cmp CARG1, #0 + | cmpne RB, #0 + | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b + | eors CARG2, CARG1, RB, lsl #1 + | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y + | bx lr + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. + |// Saveregs already performed. Callback slot number in [sp], g in r12. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | ldr CTSTATE, GL:r12->ctype_state + | add DISPATCH, r12, #GG_G2DISP + |.if FPU + | str r4, SAVE_R4 + | add r4, sp, CFRAME_SPACE+4+8*8 + | vstmdb r4!, {d8-d15} + |.endif + |.if HFABI + | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8]) + |.endif + | strd CARG34, CTSTATE->cb.gpr[2] + | strd CARG12, CTSTATE->cb.gpr[0] + |.if HFABI + | vstmdb r12!, {d0-d7} + |.endif + | ldr CARG4, [sp] + | add CARG3, sp, #CFRAME_SIZE + | mov CARG1, CTSTATE + | lsr CARG4, CARG4, #3 + | str CARG3, CTSTATE->cb.stack + | mov CARG2, sp + | str CARG4, CTSTATE->cb.slot + | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok. + | bl extern lj_ccallback_enter // (CTState *cts, void *cf) + | // Returns lua_State *. + | ldr BASE, L:CRET1->base + | mv_vmstate CARG2, INTERP + | ldr RC, L:CRET1->top + | mov MASKR8, #255 + | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] + | mov L, CRET1 + | sub RC, RC, BASE + | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. + | st_vmstate CARG2 + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)] + | str BASE, L->base + | str CARG4, L->top + | str L, CTSTATE->L + | mov CARG1, CTSTATE + | mov CARG2, RA + | bl extern lj_ccallback_leave // (CTState *cts, TValue *o) + | ldrd CARG12, CTSTATE->cb.gpr[0] + |.if HFABI + | vldr d0, CTSTATE->cb.fpr[0] + |.endif + | b ->vm_leave_unw + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, r4 + | push {CCSTATE, r5, r11, lr} + | mov CCSTATE, CARG1 + | ldr CARG1, CCSTATE:CARG1->spadj + | ldrb CARG2, CCSTATE->nsp + | add CARG3, CCSTATE, #offsetof(CCallState, stack) + |.if HFABI + | add RB, CCSTATE, #offsetof(CCallState, fpr[0]) + |.endif + | mov r11, sp + | sub sp, sp, CARG1 // Readjust stack. + | subs CARG2, CARG2, #1 + |.if HFABI + | vldm RB, {d0-d7} + |.endif + | ldr RB, CCSTATE->func + | bmi >2 + |1: // Copy stack slots. + | ldr CARG4, [CARG3, CARG2, lsl #2] + | str CARG4, [sp, CARG2, lsl #2] + | subs CARG2, CARG2, #1 + | bpl <1 + |2: + | ldrd CARG12, CCSTATE->gpr[0] + | ldrd CARG34, CCSTATE->gpr[2] + | blx RB + | mov sp, r11 + |.if HFABI + | add r12, CCSTATE, #offsetof(CCallState, fpr[4]) + |.endif + | strd CRET1, CCSTATE->gpr[0] + |.if HFABI + | vstmdb r12!, {d0-d3} + |.endif + | pop {CCSTATE, r5, r11, pc} + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RC = src2, JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, BASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TISNUM + | bne >3 + | checktp CARG4, LJ_TISNUM + | bne >4 + | cmp CARG1, CARG3 + if (op == BC_ISLT) { + | sublt PC, RB, #0x20000 + } else if (op == BC_ISGE) { + | subge PC, RB, #0x20000 + } else if (op == BC_ISLE) { + | suble PC, RB, #0x20000 + } else { + | subgt PC, RB, #0x20000 + } + |1: + | ins_next + | + |3: // CARG12 is not an integer. + |.if FPU + | vldr d0, [RA] + | bhi ->vmeta_comp + | // d0 is a number. + | checktp CARG4, LJ_TISNUM + | vldr d1, [RC] + | blo >5 + | bhi ->vmeta_comp + | // d0 is a number, CARG3 is an integer. + | vmov s4, CARG3 + | vcvt.f64.s32 d1, s4 + | b >5 + |4: // CARG1 is an integer, CARG34 is not an integer. + | vldr d1, [RC] + | bhi ->vmeta_comp + | // CARG1 is an integer, d1 is a number. + | vmov s4, CARG1 + | vcvt.f64.s32 d0, s4 + |5: // d0 and d1 are numbers. + | vcmp.f64 d0, d1 + | vmrs + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + if (op == BC_ISLT) { + | sublo PC, RB, #0x20000 + } else if (op == BC_ISGE) { + | subhs PC, RB, #0x20000 + } else if (op == BC_ISLE) { + | subls PC, RB, #0x20000 + } else { + | subhi PC, RB, #0x20000 + } + | b <1 + |.else + | bhi ->vmeta_comp + | // CARG12 is a number. + | checktp CARG4, LJ_TISNUM + | movlo RA, RB // Save RB. + | blo >5 + | bhi ->vmeta_comp + | // CARG12 is a number, CARG3 is an integer. + | mov CARG1, CARG3 + | mov RC, RA + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | mov CARG3, CARG1 + | mov CARG4, CARG2 + | ldrd CARG12, [RC] // Restore first operand. + | b >5 + |4: // CARG1 is an integer, CARG34 is not an integer. + | bhi ->vmeta_comp + | // CARG1 is an integer, CARG34 is a number. + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | ldrd CARG34, [RC] // Restore second operand. + |5: // CARG12 and CARG34 are numbers. + | bl extern __aeabi_cdcmple + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + if (op == BC_ISLT) { + | sublo PC, RA, #0x20000 + } else if (op == BC_ISGE) { + | subhs PC, RA, #0x20000 + } else if (op == BC_ISLE) { + | subls PC, RA, #0x20000 + } else { + | subhi PC, RA, #0x20000 + } + | b <1 + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RC = src2, JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, BASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TISNUM + | cmnls CARG4, #-LJ_TISNUM + if (vk) { + | bls ->BC_ISEQN_Z + } else { + | bls ->BC_ISNEN_Z + } + | // Either or both types are not numbers. + |.if FFI + | checktp CARG2, LJ_TCDATA + | checktpne CARG4, LJ_TCDATA + | beq ->vmeta_equal_cd + |.endif + | cmp CARG2, CARG4 // Compare types. + | bne >2 // Not the same type? + | checktp CARG2, LJ_TISPRI + | bhs >1 // Same type and primitive type? + | + | // Same types and not a primitive type. Compare GCobj or pvalue. + | cmp CARG1, CARG3 + if (vk) { + | bne >3 // Different GCobjs or pvalues? + |1: // Branch if same. + | sub PC, RB, #0x20000 + |2: // Different. + | ins_next + |3: + | checktp CARG2, LJ_TISTABUD + | bhi <2 // Different objects and not table/ud? + } else { + | beq >1 // Same GCobjs or pvalues? + | checktp CARG2, LJ_TISTABUD + | bhi >2 // Different objects and not table/ud? + } + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + if (vk) { + | beq <2 // No metatable? + } else { + | beq >2 // No metatable? + } + | ldrb RA, TAB:RA->nomm + | mov CARG4, #1-vk // ne = 0 or 1. + | mov CARG2, CARG1 + | tst RA, #1<vmeta_equal // 'no __eq' flag not set? + if (vk) { + | b <2 + } else { + |2: // Branch if different. + | sub PC, RB, #0x20000 + |1: // Same. + | ins_next + } + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RC = str_const (~), JMP with RC = target + | mvn RC, RC + | ldrd CARG12, [BASE, RA] + | ldrh RB, [PC, #2] + | ldr STR:CARG3, [KBASE, RC, lsl #2] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TSTR + |.if FFI + | bne >7 + | cmp CARG1, CARG3 + |.else + | cmpeq CARG1, CARG3 + |.endif + if (vk) { + | subeq PC, RB, #0x20000 + |1: + } else { + |1: + | subne PC, RB, #0x20000 + } + | ins_next + | + |.if FFI + |7: + | checktp CARG2, LJ_TCDATA + | bne <1 + | b ->vmeta_equal_cd + |.endif + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RC = num_const (~), JMP with RC = target + | lsl RC, RC, #3 + | ldrd CARG12, [RA, BASE]! + | ldrh RB, [PC, #2] + | ldrd CARG34, [RC, KBASE]! + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + if (vk) { + |->BC_ISEQN_Z: + } else { + |->BC_ISNEN_Z: + } + | checktp CARG2, LJ_TISNUM + | bne >3 + | checktp CARG4, LJ_TISNUM + | bne >4 + | cmp CARG1, CARG3 + if (vk) { + | subeq PC, RB, #0x20000 + |1: + } else { + |1: + | subne PC, RB, #0x20000 + } + |2: + | ins_next + | + |3: // CARG12 is not an integer. + |.if FFI + | bhi >7 + |.else + if (!vk) { + | subhi PC, RB, #0x20000 + } + | bhi <2 + |.endif + |.if FPU + | checktp CARG4, LJ_TISNUM + | vmov s4, CARG3 + | vldr d0, [RA] + | vldrlo d1, [RC] + | vcvths.f64.s32 d1, s4 + | b >5 + |4: // CARG1 is an integer, d1 is a number. + | vmov s4, CARG1 + | vldr d1, [RC] + | vcvt.f64.s32 d0, s4 + |5: // d0 and d1 are numbers. + | vcmp.f64 d0, d1 + | vmrs + if (vk) { + | subeq PC, RB, #0x20000 + } else { + | subne PC, RB, #0x20000 + } + | b <2 + |.else + | // CARG12 is a number. + | checktp CARG4, LJ_TISNUM + | movlo RA, RB // Save RB. + | blo >5 + | // CARG12 is a number, CARG3 is an integer. + | mov CARG1, CARG3 + | mov RC, RA + |4: // CARG1 is an integer, CARG34 is a number. + | mov RA, RB // Save RB. + | bl extern __aeabi_i2d + | ldrd CARG34, [RC] // Restore other operand. + |5: // CARG12 and CARG34 are numbers. + | bl extern __aeabi_cdcmpeq + if (vk) { + | subeq PC, RA, #0x20000 + } else { + | subne PC, RA, #0x20000 + } + | b <2 + |.endif + | + |.if FFI + |7: + | checktp CARG2, LJ_TCDATA + | bne <1 + | b ->vmeta_equal_cd + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RC = primitive_type (~), JMP with RC = target + | ldrd CARG12, [BASE, RA] + | ldrh RB, [PC, #2] + | add PC, PC, #4 + | mvn RC, RC + | add RB, PC, RB, lsl #2 + |.if FFI + | checktp CARG2, LJ_TCDATA + | beq ->vmeta_equal_cd + |.endif + | cmp CARG2, RC + if (vk) { + | subeq PC, RB, #0x20000 + } else { + | subne PC, RB, #0x20000 + } + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RC = src, JMP with RC = target + | add RC, BASE, RC, lsl #3 + | ldrh RB, [PC, #2] + | ldrd CARG12, [RC] + | add PC, PC, #4 + | add RB, PC, RB, lsl #2 + | checktp CARG2, LJ_TTRUE + if (op == BC_ISTC || op == BC_IST) { + | subls PC, RB, #0x20000 + if (op == BC_ISTC) { + | strdls CARG12, [BASE, RA] + } + } else { + | subhi PC, RB, #0x20000 + if (op == BC_ISFC) { + | strdhi CARG12, [BASE, RA] + } + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ins_next1 + | ldrd CARG12, [BASE, RC] + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_NOT: + | // RA = dst*8, RC = src + | add RC, BASE, RC, lsl #3 + | ins_next1 + | ldr CARG1, [RC, #4] + | add RA, BASE, RA + | ins_next2 + | checktp CARG1, LJ_TTRUE + | mvnls CARG2, #~LJ_TFALSE + | mvnhi CARG2, #~LJ_TTRUE + | str CARG2, [RA, #4] + | ins_next3 + break; + case BC_UNM: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ldrd CARG12, [BASE, RC] + | ins_next1 + | ins_next2 + | checktp CARG2, LJ_TISNUM + | bhi ->vmeta_unm + | eorne CARG2, CARG2, #0x80000000 + | bne >5 + | rsbseq CARG1, CARG1, #0 + | ldrdvs CARG12, >9 + |5: + | strd CARG12, [BASE, RA] + | ins_next3 + | + |.align 8 + |9: + | .long 0x00000000, 0x41e00000 // 2^31. + break; + case BC_LEN: + | // RA = dst*8, RC = src + | lsl RC, RC, #3 + | ldrd CARG12, [BASE, RC] + | checkstr CARG2, >2 + | ldr CARG1, STR:CARG1->len + |1: + | mvn CARG2, #~LJ_TISNUM + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |2: + | checktab CARG2, ->vmeta_len +#if LJ_52 + | ldr TAB:CARG3, TAB:CARG1->metatable + | cmp TAB:CARG3, #0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | .IOS mov RC, BASE + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | .IOS mov BASE, RC + | b <1 +#if LJ_52 + |9: + | ldrb CARG4, TAB:CARG3->nomm + | tst CARG4, #1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithcheck, cond, ncond, target + ||if (vk == 1) { + | cmn CARG4, #-LJ_TISNUM + | cmn..cond CARG2, #-LJ_TISNUM + ||} else { + | cmn CARG2, #-LJ_TISNUM + | cmn..cond CARG4, #-LJ_TISNUM + ||} + | b..ncond target + |.endmacro + |.macro ins_arithcheck_int, target + | ins_arithcheck eq, ne, target + |.endmacro + |.macro ins_arithcheck_num, target + | ins_arithcheck lo, hs, target + |.endmacro + | + |.macro ins_arithpre + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | .if FPU + | ldrd CARG12, [RB, BASE]! + | ldrd CARG34, [RC, KBASE]! + | .else + | ldrd CARG12, [BASE, RB] + | ldrd CARG34, [KBASE, RC] + | .endif + || break; + ||case 1: + | .if FPU + | ldrd CARG34, [RB, BASE]! + | ldrd CARG12, [RC, KBASE]! + | .else + | ldrd CARG34, [BASE, RB] + | ldrd CARG12, [KBASE, RC] + | .endif + || break; + ||default: + | .if FPU + | ldrd CARG12, [RB, BASE]! + | ldrd CARG34, [RC, BASE]! + | .else + | ldrd CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | .endif + || break; + ||} + |.endmacro + | + |.macro ins_arithpre_fpu, reg1, reg2 + |.if FPU + ||if (vk == 1) { + | vldr reg2, [RB] + | vldr reg1, [RC] + ||} else { + | vldr reg1, [RB] + | vldr reg2, [RC] + ||} + |.endif + |.endmacro + | + |.macro ins_arithpost_fpu, reg + | ins_next1 + | add RA, BASE, RA + | ins_next2 + | vstr reg, [RA] + | ins_next3 + |.endmacro + | + |.macro ins_arithfallback, ins + ||switch (vk) { + ||case 0: + | ins ->vmeta_arith_vn + || break; + ||case 1: + | ins ->vmeta_arith_nv + || break; + ||default: + | ins ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arithdn, intins, fpins, fpcall + | ins_arithpre + |.if "intins" ~= "vm_modi" and not FPU + | ins_next1 + |.endif + | ins_arithcheck_int >5 + |.if "intins" == "smull" + | smull CARG1, RC, CARG3, CARG1 + | cmp RC, CARG1, asr #31 + | ins_arithfallback bne + |.elif "intins" == "vm_modi" + | movs CARG2, CARG3 + | ins_arithfallback beq + | bl ->vm_modi + | mvn CARG2, #~LJ_TISNUM + |.else + | intins CARG1, CARG1, CARG3 + | ins_arithfallback bvs + |.endif + |4: + |.if "intins" == "vm_modi" or FPU + | ins_next1 + |.endif + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |5: // FP variant. + | ins_arithpre_fpu d6, d7 + | ins_arithfallback ins_arithcheck_num + |.if FPU + |.if "intins" == "vm_modi" + | bl fpcall + |.else + | fpins d6, d6, d7 + |.endif + | ins_arithpost_fpu d6 + |.else + | bl fpcall + |.if "intins" ~= "vm_modi" + | ins_next1 + |.endif + | b <4 + |.endif + |.endmacro + | + |.macro ins_arithfp, fpins, fpcall + | ins_arithpre + |.if "fpins" ~= "extern" or HFABI + | ins_arithpre_fpu d0, d1 + |.endif + | ins_arithfallback ins_arithcheck_num + |.if "fpins" == "extern" + | .IOS mov RC, BASE + | bl fpcall + | .IOS mov BASE, RC + |.elif FPU + | fpins d0, d0, d1 + |.else + | bl fpcall + |.endif + |.if ("fpins" ~= "extern" or HFABI) and FPU + | ins_arithpost_fpu d0 + |.else + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arithdn adds, vadd.f64, extern __aeabi_dadd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arithdn subs, vsub.f64, extern __aeabi_dsub + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arithdn smull, vmul.f64, extern __aeabi_dmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arithfp vdiv.f64, extern __aeabi_ddiv + break; + case BC_MODVN: case BC_MODNV: case BC_MODVV: + | ins_arithdn vm_modi, vm_mod, ->vm_mod + break; + case BC_POW: + | // NYI: (partial) integer arithmetic. + | ins_arithfp extern, extern pow + break; + + case BC_CAT: + | decode_RB8 RC, INS + | decode_RC8 RB, INS + | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!) + | sub CARG3, RB, RC + | str BASE, L->base + | add CARG2, BASE, RB + |->BC_CAT_Z: + | // RA = dst*8, RC = src_start*8, CARG2 = top-1 + | mov CARG1, L + | str PC, SAVE_PC + | lsr CARG3, CARG3, #3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | ldr BASE, L->base + | cmp CRET1, #0 + | bne ->vmeta_binop + | ldrd CARG34, [BASE, RC] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] // Copy result to RA. + | ins_next3 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RC = str_const (~) + | mvn RC, RC + | ins_next1 + | ldr CARG1, [KBASE, RC, lsl #2] + | mvn CARG2, #~LJ_TSTR + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RC = cdata_const (~) + | mvn RC, RC + | ins_next1 + | ldr CARG1, [KBASE, RC, lsl #2] + | mvn CARG2, #~LJ_TCDATA + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, (RC = int16_literal) + | mov CARG1, INS, asr #16 // Refetch sign-extended reg. + | mvn CARG2, #~LJ_TISNUM + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KNUM: + | // RA = dst*8, RC = num_const + | lsl RC, RC, #3 + | ins_next1 + | ldrd CARG12, [KBASE, RC] + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + case BC_KPRI: + | // RA = dst*8, RC = primitive_type (~) + | add RA, BASE, RA + | mvn RC, RC + | ins_next1 + | ins_next2 + | str RC, [RA, #4] + | ins_next3 + break; + case BC_KNIL: + | // RA = base*8, RC = end + | add RA, BASE, RA + | add RC, BASE, RC, lsl #3 + | mvn CARG1, #~LJ_TNIL + | str CARG1, [RA, #4] + | add RA, RA, #8 + |1: + | str CARG1, [RA, #4] + | cmp RA, RC + | add RA, RA, #8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RC = uvnum + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsl RC, RC, #2 + | add RC, RC, #offsetof(GCfuncL, uvptr) + | ldr UPVAL:CARG2, [LFUNC:CARG2, RC] + | ldr CARG2, UPVAL:CARG2->v + | ldrd CARG34, [CARG2] + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + break; + case BC_USETV: + | // RA = uvnum*8, RC = src + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | lsl RC, RC, #3 + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldrd CARG34, [BASE, RC] + | ldrb RB, UPVAL:CARG2->marked + | ldrb RC, UPVAL:CARG2->closed + | ldr CARG2, UPVAL:CARG2->v + | tst RB, #LJ_GC_BLACK // isblack(uv) + | add RB, CARG4, #-LJ_TISGCV + | cmpne RC, #0 + | strd CARG34, [CARG2] + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmn RB, #-(LJ_TNUMX - LJ_TISGCV) + | ldrbhi RC, GCOBJ:CARG3->gch.marked + | bls <1 // tvisgcv(v) + | sub CARG1, DISPATCH, #-GG_DISP2G + | tst RC, #LJ_GC_WHITES + | // Crossed a write barrier. Move the barrier forward. + |.if IOS + | beq <1 + | mov RC, BASE + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | mov BASE, RC + |.else + | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) + |.endif + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RC = str_const (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | mvn RC, RC + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldr STR:CARG3, [KBASE, RC, lsl #2] + | mvn CARG4, #~LJ_TSTR + | ldrb RB, UPVAL:CARG2->marked + | ldr CARG2, UPVAL:CARG2->v + | ldrb RC, UPVAL:CARG2->closed + | tst RB, #LJ_GC_BLACK // isblack(uv) + | ldrb RB, STR:CARG3->marked + | strd CARG34, [CARG2] + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | tst RB, #LJ_GC_WHITES // iswhite(str) + | cmpne RC, #0 + | sub CARG1, DISPATCH, #-GG_DISP2G + | // Crossed a write barrier. Move the barrier forward. + |.if IOS + | beq <1 + | mov RC, BASE + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | mov BASE, RC + |.else + | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) + |.endif + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RC = num_const + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | lsl RC, RC, #3 + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | ldrd CARG34, [KBASE, RC] + | ldr CARG2, UPVAL:CARG2->v + | ins_next1 + | ins_next2 + | strd CARG34, [CARG2] + | ins_next3 + break; + case BC_USETP: + | // RA = uvnum*8, RC = primitive_type (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | lsr RA, RA, #1 + | add RA, RA, #offsetof(GCfuncL, uvptr) + | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] + | mvn RC, RC + | ldr CARG2, UPVAL:CARG2->v + | ins_next1 + | ins_next2 + | str RC, [CARG2, #4] + | ins_next3 + break; + + case BC_UCLO: + | // RA = level*8, RC = target + | ldr CARG3, L->openupval + | add RC, PC, RC, lsl #2 + | str BASE, L->base + | cmp CARG3, #0 + | sub PC, RC, #0x20000 + | beq >1 + | mov CARG1, L + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | ldr BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RC = proto_const (~) (holding function prototype) + | mvn RC, RC + | str BASE, L->base + | ldr CARG2, [KBASE, RC, lsl #2] + | str PC, SAVE_PC + | ldr CARG3, [BASE, FRAME_FUNC] + | mov CARG1, L + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | ldr BASE, L->base + | mvn CARG2, #~LJ_TFUNC + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RC = (hbits|asize) | tab_const (~) + if (op == BC_TDUP) { + | mvn RC, RC + } + | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)] + | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)] + | str BASE, L->base + | str PC, SAVE_PC + | cmp CARG3, CARG4 + | mov CARG1, L + | bhs >5 + |1: + if (op == BC_TNEW) { + | lsl CARG2, RC, #21 + | lsr CARG3, RC, #11 + | asr RC, CARG2, #21 + | lsr CARG2, CARG2, #21 + | cmn RC, #1 + | addeq CARG2, CARG2, #2 + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns GCtab *. + } else { + | ldr CARG2, [KBASE, RC, lsl #2] + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns GCtab *. + } + | ldr BASE, L->base + | mvn CARG2, #~LJ_TTAB + | ins_next1 + | ins_next2 + | strd CARG12, [BASE, RA] + | ins_next3 + |5: + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mov CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RC = str_const (~) + case BC_GSET: + | // RA = dst*8, RC = str_const (~) + | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] + | mvn RC, RC + | ldr TAB:CARG1, LFUNC:CARG2->env + | ldr STR:RC, [KBASE, RC, lsl #2] + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = dst*8, RB = table*8, RC = key*8 + | ldrd TAB:CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12. + | checktp CARG4, LJ_TISNUM // Integer key? + | ldreq CARG4, TAB:CARG1->array + | ldreq CARG2, TAB:CARG1->asize + | bne >9 + | + | add CARG4, CARG4, CARG3, lsl #3 + | cmp CARG3, CARG2 // In array part? + | ldrdlo CARG34, [CARG4] + | bhs ->vmeta_tgetv + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | beq >5 + |1: + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG2, TAB:CARG1->metatable + | cmp TAB:CARG2, #0 + | beq <1 // No metatable: done. + | ldrb CARG2, TAB:CARG2->nomm + | tst CARG2, #1<vmeta_tgetv + | + |9: + | checktp CARG4, LJ_TSTR // String key? + | moveq STR:RC, CARG3 + | beq ->BC_TGETS_Z + | b ->vmeta_tgetv + break; + case BC_TGETS: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = dst*8, RB = table*8, RC = str_const (~) + | ldrd CARG12, [BASE, RB] + | mvn RC, RC + | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. + | checktab CARG2, ->vmeta_tgets1 + |->BC_TGETS_Z: + | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 + | ldr CARG3, TAB:CARG1->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:CARG1->node + | mov TAB:RB, TAB:CARG1 + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + |1: + | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS. + | ldrd CARG34, NODE:INS->val + | ldr NODE:INS, NODE:INS->next + | checktp CARG2, LJ_TSTR + | cmpeq CARG1, STR:RC + | bne >4 + | checktp CARG4, LJ_TNIL + | beq >5 + |3: + | ins_next1 + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |4: // Follow hash chain. + | cmp NODE:INS, #0 + | bne <1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG1, TAB:RB->metatable + | mov CARG3, #0 // Optional clear of undef. value (during load stall). + | mvn CARG4, #~LJ_TNIL + | cmp TAB:CARG1, #0 + | beq <3 // No metatable: done. + | ldrb CARG2, TAB:CARG1->nomm + | tst CARG2, #1<vmeta_tgets + break; + case BC_TGETB: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = dst*8, RB = table*8, RC = index + | ldrd CARG12, [BASE, RB] + | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12. + | ldr CARG3, TAB:CARG1->asize + | ldr CARG4, TAB:CARG1->array + | lsl CARG2, RC, #3 + | cmp RC, CARG3 + | ldrdlo CARG34, [CARG4, CARG2] + | bhs ->vmeta_tgetb + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | beq >5 + |1: + | ins_next2 + | strd CARG34, [BASE, RA] + | ins_next3 + | + |5: // Check for __index if table value is nil. + | ldr TAB:CARG2, TAB:CARG1->metatable + | cmp TAB:CARG2, #0 + | beq <1 // No metatable: done. + | ldrb CARG2, TAB:CARG2->nomm + | tst CARG2, #1<vmeta_tgetb + break; + + case BC_TSETV: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = src*8, RB = table*8, RC = key*8 + | ldrd TAB:CARG12, [BASE, RB] + | ldrd CARG34, [BASE, RC] + | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12. + | checktp CARG4, LJ_TISNUM // Integer key? + | ldreq CARG2, TAB:CARG1->array + | ldreq CARG4, TAB:CARG1->asize + | bne >9 + | + | add CARG2, CARG2, CARG3, lsl #3 + | cmp CARG3, CARG4 // In array part? + | ldrlo INS, [CARG2, #4] + | bhs ->vmeta_tsetv + | ins_next1 // Overwrites RB! + | checktp INS, LJ_TNIL + | ldrb INS, TAB:CARG1->marked + | ldrd CARG34, [BASE, RA] + | beq >5 + |1: + | tst INS, #LJ_GC_BLACK // isblack(table) + | strd CARG34, [CARG2] + | bne >7 + |2: + | ins_next2 + | ins_next3 + | + |5: // Check for __newindex if previous value is nil. + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + | beq <1 // No metatable: done. + | ldrb RA, TAB:RA->nomm + | tst RA, #1<vmeta_tsetv + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:CARG1, INS, CARG3 + | b <2 + | + |9: + | checktp CARG4, LJ_TSTR // String key? + | moveq STR:RC, CARG3 + | beq ->BC_TSETS_Z + | b ->vmeta_tsetv + break; + case BC_TSETS: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = src*8, RB = table*8, RC = str_const (~) + | ldrd CARG12, [BASE, RB] + | mvn RC, RC + | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. + | checktab CARG2, ->vmeta_tsets1 + |->BC_TSETS_Z: + | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 + | ldr CARG3, TAB:CARG1->hmask + | ldr CARG4, STR:RC->hash + | ldr NODE:INS, TAB:CARG1->node + | mov TAB:RB, TAB:CARG1 + | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask + | add CARG3, CARG3, CARG3, lsl #1 + | mov CARG4, #0 + | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 + | strb CARG4, TAB:RB->nomm // Clear metamethod cache. + |1: + | ldrd CARG12, NODE:INS->key + | ldr CARG4, NODE:INS->val.it + | ldr NODE:CARG3, NODE:INS->next + | checktp CARG2, LJ_TSTR + | cmpeq CARG1, STR:RC + | bne >5 + | ldrb CARG2, TAB:RB->marked + | checktp CARG4, LJ_TNIL // Key found, but nil value? + | ldrd CARG34, [BASE, RA] + | beq >4 + |2: + | tst CARG2, #LJ_GC_BLACK // isblack(table) + | strd CARG34, NODE:INS->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | ldr TAB:CARG1, TAB:RB->metatable + | cmp TAB:CARG1, #0 + | beq <2 // No metatable: done. + | ldrb CARG1, TAB:CARG1->nomm + | tst CARG1, #1<vmeta_tsets + | + |5: // Follow hash chain. + | movs NODE:INS, NODE:CARG3 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | ldr TAB:CARG1, TAB:RB->metatable + | mov CARG3, TMPDp + | str PC, SAVE_PC + | cmp TAB:CARG1, #0 // No metatable: continue. + | str BASE, L->base + | ldrbne CARG2, TAB:CARG1->nomm + | mov CARG1, L + | beq >6 + | tst CARG2, #1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mvn CARG4, #~LJ_TSTR + | str STR:RC, TMPDlo + | mov CARG2, TAB:RB + | str CARG4, TMPDhi + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | ldr BASE, L->base + | ldrd CARG34, [BASE, RA] + | strd CARG34, [CRET1] + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, CARG2, CARG3 + | b <3 + break; + case BC_TSETB: + | decode_RB8 RB, INS + | and RC, RC, #255 + | // RA = src*8, RB = table*8, RC = index + | ldrd CARG12, [BASE, RB] + | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12. + | ldr CARG3, TAB:CARG1->asize + | ldr RB, TAB:CARG1->array + | lsl CARG2, RC, #3 + | cmp RC, CARG3 + | ldrdlo CARG34, [CARG2, RB]! + | bhs ->vmeta_tsetb + | ins_next1 // Overwrites RB! + | checktp CARG4, LJ_TNIL + | ldrb INS, TAB:CARG1->marked + | ldrd CARG34, [BASE, RA] + | beq >5 + |1: + | tst INS, #LJ_GC_BLACK // isblack(table) + | strd CARG34, [CARG2] + | bne >7 + |2: + | ins_next2 + | ins_next3 + | + |5: // Check for __newindex if previous value is nil. + | ldr TAB:RA, TAB:CARG1->metatable + | cmp TAB:RA, #0 + | beq <1 // No metatable: done. + | ldrb RA, TAB:RA->nomm + | tst RA, #1<vmeta_tsetb + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:CARG1, INS, CARG3 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RC = num_const (start index) + | add RA, BASE, RA + |1: + | ldr RB, SAVE_MULTRES + | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table. + | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word. + | subs RB, RB, #8 + | ldr CARG4, TAB:CARG2->asize + | beq >4 // Nothing to copy? + | add CARG3, CARG1, RB, lsr #3 + | cmp CARG3, CARG4 + | ldr CARG4, TAB:CARG2->array + | add RB, RA, RB + | bhi >5 + | add INS, CARG4, CARG1, lsl #3 + | ldrb CARG1, TAB:CARG2->marked + |3: // Copy result slots to table. + | ldrd CARG34, [RA], #8 + | strd CARG34, [INS], #8 + | cmp RA, RB + | blo <3 + | tst CARG1, #LJ_GC_BLACK // isblack(table) + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | str BASE, L->base + | mov CARG1, L + | str PC, SAVE_PC + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | .IOS ldr BASE, L->base + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, CARG1, CARG3 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = nresults+1,) RC = extra_nargs + | ldr CARG1, SAVE_MULTRES + | decode_RC8 NARGS8:RC, INS + | add NARGS8:RC, NARGS8:RC, CARG1 + | b ->BC_CALL_Z + break; + case BC_CALL: + | decode_RC8 NARGS8:RC, INS + | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8 + |->BC_CALL_Z: + | mov RB, BASE // Save old BASE for vmeta_call. + | ldrd CARG34, [BASE, RA]! + | sub NARGS8:RC, NARGS8:RC, #8 + | add BASE, BASE, #8 + | checkfunc CARG4, ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs + | ldr CARG1, SAVE_MULTRES + | add NARGS8:RC, CARG1, RC, lsl #3 + | b ->BC_CALLT1_Z + break; + case BC_CALLT: + | lsl NARGS8:RC, RC, #3 + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + |->BC_CALLT1_Z: + | ldrd LFUNC:CARG34, [RA, BASE]! + | sub NARGS8:RC, NARGS8:RC, #8 + | add RA, RA, #8 + | checkfunc CARG4, ->vmeta_callt + | ldr PC, [BASE, FRAME_PC] + |->BC_CALLT2_Z: + | mov RB, #0 + | ldrb CARG4, LFUNC:CARG3->ffid + | tst PC, #FRAME_TYPE + | bne >7 + |1: + | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC. + | cmp NARGS8:RC, #0 + | beq >3 + |2: + | ldrd CARG12, [RA, RB] + | add INS, RB, #8 + | cmp INS, NARGS8:RC + | strd CARG12, [BASE, RB] + | mov RB, INS + | bne <2 + |3: + | cmp CARG4, #1 // (> FF_C) Calling a fast function? + | bhi >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | ldr INS, [PC, #-4] + | decode_RA8 RA, INS + | sub CARG1, BASE, RA + | ldr LFUNC:CARG1, [CARG1, #-16] + | ldr CARG1, LFUNC:CARG1->field_pc + | ldr KBASE, [CARG1, #PC2PROTO(k)] + | b <4 + | + |7: // Tailcall from a vararg function. + | eor PC, PC, #FRAME_VARG + | tst PC, #FRAME_TYPEP // Vararg frame below? + | movne CARG4, #0 // Clear ffid if no Lua function below. + | bne <1 + | sub BASE, BASE, PC + | ldr PC, [BASE, FRAME_PC] + | tst PC, #FRAME_TYPE + | movne CARG4, #0 // Clear ffid if no Lua function below. + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) + | add RA, BASE, RA + | mov RB, BASE // Save old BASE for vmeta_call. + | ldrd CARG34, [RA, #-16] + | ldrd CARG12, [RA, #-8] + | add BASE, RA, #8 + | strd CARG34, [RA, #8] // Copy state. + | strd CARG12, [RA, #16] // Copy control var. + | // STALL: locked CARG34. + | ldrd LFUNC:CARG34, [RA, #-24] + | mov NARGS8:RC, #16 // Iterators get 2 arguments. + | // STALL: load CARG34. + | strd LFUNC:CARG34, [RA] // Copy callable. + | checkfunc CARG4, ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | ldr TAB:RB, [RA, #-16] + | ldr CARG1, [RA, #-8] // Get index from control var. + | ldr INS, TAB:RB->asize + | ldr CARG2, TAB:RB->array + | add PC, PC, #4 + |1: // Traverse array part. + | subs RC, CARG1, INS + | add CARG3, CARG2, CARG1, lsl #3 + | bhs >5 // Index points after array part? + | ldrd CARG34, [CARG3] + | checktp CARG4, LJ_TNIL + | addeq CARG1, CARG1, #1 // Skip holes in array part. + | beq <1 + | ldrh RC, [PC, #-2] + | mvn CARG2, #~LJ_TISNUM + | strd CARG34, [RA, #8] + | add RC, PC, RC, lsl #2 + | add RB, CARG1, #1 + | strd CARG12, [RA] + | sub PC, RC, #0x20000 + | str RB, [RA, #-8] // Update control var. + |3: + | ins_next + | + |5: // Traverse hash part. + | ldr CARG4, TAB:RB->hmask + | ldr NODE:RB, TAB:RB->node + |6: + | add CARG1, RC, RC, lsl #1 + | cmp RC, CARG4 // End of iteration? Branch to ITERL+1. + | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8 + | bhi <3 + | ldrd CARG12, NODE:CARG3->val + | checktp CARG2, LJ_TNIL + | add RC, RC, #1 + | beq <6 // Skip holes in hash part. + | ldrh RB, [PC, #-2] + | add RC, RC, INS + | ldrd CARG34, NODE:CARG3->key + | str RC, [RA, #-8] // Update control var. + | strd CARG12, [RA, #8] + | add RC, PC, RB, lsl #2 + | sub PC, RC, #0x20000 + | strd CARG34, [RA] + | b <3 + break; + + case BC_ISNEXT: + | // RA = base*8, RC = target (points to ITERN) + | add RA, BASE, RA + | add RC, PC, RC, lsl #2 + | ldrd CFUNC:CARG12, [RA, #-24] + | ldr CARG3, [RA, #-12] + | ldr CARG4, [RA, #-4] + | checktp CARG2, LJ_TFUNC + | ldrbeq CARG1, CFUNC:CARG1->ffid + | checktpeq CARG3, LJ_TTAB + | checktpeq CARG4, LJ_TNIL + | cmpeq CARG1, #FF_next_N + | subeq PC, RC, #0x20000 + | bne >5 + | ins_next1 + | ins_next2 + | mov CARG1, #0 + | mvn CARG2, #0x00018000 + | strd CARG1, [RA, #-8] // Initialize control var. + |1: + | ins_next3 + |5: // Despecialize bytecode if any of the checks fail. + | mov CARG1, #BC_JMP + | mov OP, #BC_ITERC + | strb CARG1, [PC, #-4] + | sub PC, RC, #0x20000 + | strb OP, [PC] // Subsumes ins_next1. + | ins_next2 + | b <1 + break; + + case BC_VARG: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | ldr CARG1, [BASE, FRAME_PC] + | add RC, BASE, RC + | add RA, BASE, RA + | add RC, RC, #FRAME_VARG + | add CARG4, RA, RB + | sub CARG3, BASE, #8 // CARG3 = vtop + | sub RC, RC, CARG1 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmp RB, #0 + | sub CARG1, CARG3, RC + | beq >5 // Copy all varargs? + | sub CARG4, CARG4, #16 + |1: // Copy vararg slots to destination slots. + | cmp RC, CARG3 + | ldrdlo CARG12, [RC], #8 + | mvnhs CARG2, #~LJ_TNIL + | cmp RA, CARG4 + | strd CARG12, [RA], #8 + | blo <1 + |2: + | ins_next + | + |5: // Copy all varargs. + | ldr CARG4, L->maxstack + | cmp CARG1, #0 + | movle RB, #8 // MULTRES = (0+1)*8 + | addgt RB, CARG1, #8 + | add CARG2, RA, CARG1 + | str RB, SAVE_MULTRES + | ble <2 + | cmp CARG2, CARG4 + | bhi >7 + |6: + | ldrd CARG12, [RC], #8 + | strd CARG12, [RA], #8 + | cmp RC, CARG3 + | blo <6 + | b <2 + | + |7: // Grow stack for varargs. + | lsr CARG2, CARG1, #3 + | str RA, L->top + | mov CARG1, L + | str BASE, L->base + | sub RC, RC, BASE // Need delta, because BASE may change. + | str PC, SAVE_PC + | sub RA, RA, BASE + | bl extern lj_state_growstack // (lua_State *L, int n) + | ldr BASE, L->base + | add RA, BASE, RA + | add RC, BASE, RC + | sub CARG3, BASE, #8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RC = extra results + | ldr CARG1, SAVE_MULTRES + | ldr PC, [BASE, FRAME_PC] + | add RA, BASE, RA + | add RC, CARG1, RC, lsl #3 + | b ->BC_RETM_Z + break; + + case BC_RET: + | // RA = results*8, RC = nresults+1 + | ldr PC, [BASE, FRAME_PC] + | lsl RC, RC, #3 + | add RA, BASE, RA + |->BC_RETM_Z: + | str RC, SAVE_MULTRES + |1: + | ands CARG1, PC, #FRAME_TYPE + | eor CARG2, PC, #FRAME_VARG + | bne ->BC_RETV2_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return + | ldr INS, [PC, #-4] + | subs CARG4, RC, #8 + | sub CARG3, BASE, #8 + | beq >3 + |2: + | ldrd CARG12, [RA], #8 + | add BASE, BASE, #8 + | subs CARG4, CARG4, #8 + | strd CARG12, [BASE, #-16] + | bne <2 + |3: + | decode_RA8 RA, INS + | sub CARG4, CARG3, RA + | decode_RB8 RB, INS + | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC] + |5: + | cmp RB, RC // More results expected? + | bhi >6 + | mov BASE, CARG4 + | ldr CARG2, LFUNC:CARG1->field_pc + | ins_next1 + | ins_next2 + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | ins_next3 + | + |6: // Fill up results with nil. + | mvn CARG2, #~LJ_TNIL + | add BASE, BASE, #8 + | add RC, RC, #8 + | str CARG2, [BASE, #-12] + | b <5 + | + |->BC_RETV1_Z: // Non-standard return case. + | add RA, BASE, RA + |->BC_RETV2_Z: + | tst CARG2, #FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, CARG2 + | ldr PC, [BASE, FRAME_PC] + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RC = nresults+1 + | ldr PC, [BASE, FRAME_PC] + | lsl RC, RC, #3 + | str RC, SAVE_MULTRES + | ands CARG1, PC, #FRAME_TYPE + | eor CARG2, PC, #FRAME_VARG + | ldreq INS, [PC, #-4] + | bne ->BC_RETV1_Z + if (op == BC_RET1) { + | ldrd CARG12, [BASE, RA] + } + | sub CARG4, BASE, #8 + | decode_RA8 RA, INS + if (op == BC_RET1) { + | strd CARG12, [CARG4] + } + | sub BASE, CARG4, RA + | decode_RB8 RB, INS + | ldr LFUNC:CARG1, [BASE, FRAME_FUNC] + |5: + | cmp RB, RC + | bhi >6 + | ldr CARG2, LFUNC:CARG1->field_pc + | ins_next1 + | ins_next2 + | ldr KBASE, [CARG2, #PC2PROTO(k)] + | ins_next3 + | + |6: // Fill up results with nil. + | sub CARG2, CARG4, #4 + | mvn CARG3, #~LJ_TNIL + | str CARG3, [CARG2, RC] + | add RC, RC, #8 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4] + |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12] + |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20] + |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28] + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RC = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | ldrd CARG12, [RA, BASE]! + if (op != BC_JFORL) { + | add RC, PC, RC, lsl #2 + } + if (!vk) { + | ldrd CARG34, FOR_STOP + | checktp CARG2, LJ_TISNUM + | ldr RB, FOR_TSTEP + | bne >5 + | checktp CARG4, LJ_TISNUM + | ldr CARG4, FOR_STEP + | checktpeq RB, LJ_TISNUM + | bne ->vmeta_for + | cmp CARG4, #0 + | blt >4 + | cmp CARG1, CARG3 + } else { + | ldrd CARG34, FOR_STEP + | checktp CARG2, LJ_TISNUM + | bne >5 + | adds CARG1, CARG1, CARG3 + | ldr CARG4, FOR_STOP + if (op == BC_IFORL) { + | addvs RC, PC, #0x20000 // Overflow: prevent branch. + } else { + | bvs >2 // Overflow: do not enter mcode. + } + | cmp CARG3, #0 + | blt >4 + | cmp CARG1, CARG4 + } + |1: + if (op == BC_FORI) { + | subgt PC, RC, #0x20000 + } else if (op == BC_JFORI) { + | sub PC, RC, #0x20000 + | ldrhle RC, [PC, #-2] + } else if (op == BC_IFORL) { + | suble PC, RC, #0x20000 + } + if (vk) { + | strd CARG12, FOR_IDX + } + |2: + | ins_next1 + | ins_next2 + | strd CARG12, FOR_EXT + if (op == BC_JFORI || op == BC_JFORL) { + | ble =>BC_JLOOP + } + |3: + | ins_next3 + | + |4: // Invert check for negative step. + if (!vk) { + | cmp CARG3, CARG1 + } else { + | cmp CARG4, CARG1 + } + | b <1 + | + |5: // FP loop. + if (!vk) { + | cmnlo CARG4, #-LJ_TISNUM + | cmnlo RB, #-LJ_TISNUM + | bhs ->vmeta_for + |.if FPU + | vldr d0, FOR_IDX + | vldr d1, FOR_STOP + | cmp RB, #0 + | vstr d0, FOR_EXT + |.else + | cmp RB, #0 + | strd CARG12, FOR_EXT + | blt >8 + |.endif + } else { + |.if FPU + | vldr d0, FOR_IDX + | vldr d2, FOR_STEP + | vldr d1, FOR_STOP + | cmp CARG4, #0 + | vadd.f64 d0, d0, d2 + |.else + | cmp CARG4, #0 + | blt >8 + | bl extern __aeabi_dadd + | strd CARG12, FOR_IDX + | ldrd CARG34, FOR_STOP + | strd CARG12, FOR_EXT + |.endif + } + |6: + |.if FPU + | vcmpge.f64 d0, d1 + | vcmplt.f64 d1, d0 + | vmrs + |.else + | bl extern __aeabi_cdcmple + |.endif + if (vk) { + |.if FPU + | vstr d0, FOR_IDX + | vstr d0, FOR_EXT + |.endif + } + if (op == BC_FORI) { + | subhi PC, RC, #0x20000 + } else if (op == BC_JFORI) { + | sub PC, RC, #0x20000 + | ldrhls RC, [PC, #-2] + | bls =>BC_JLOOP + } else if (op == BC_IFORL) { + | subls PC, RC, #0x20000 + } else { + | bls =>BC_JLOOP + } + | ins_next1 + | ins_next2 + | b <3 + | + |.if not FPU + |8: // Invert check for negative step. + if (vk) { + | bl extern __aeabi_dadd + | strd CARG12, FOR_IDX + | strd CARG12, FOR_EXT + } + | mov CARG3, CARG1 + | mov CARG4, CARG2 + | ldrd CARG12, FOR_STOP + | b <6 + |.endif + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RC = target + | ldrd CARG12, [RA, BASE]! + if (op == BC_JITERL) { + | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. + | strdne CARG12, [RA, #-8] + | bne =>BC_JLOOP + } else { + | add RC, PC, RC, lsl #2 + | // STALL: load CARG12. + | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. + | subne PC, RC, #0x20000 // Otherwise save control var + branch. + | strdne CARG12, [RA, #-8] + } + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RC = target (loop extent) + | // Note: RA/RC is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RC = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base (ignored), RC = traceno + | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)] + | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0. + | ldr TRACE:RC, [CARG1, RC, lsl #2] + | st_vmstate CARG2 + | ldr RA, TRACE:RC->mcode + | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)] + | str L, [DISPATCH, #DISPATCH_GL(jit_L)] + | bx RA + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RC = target + | add RC, PC, RC, lsl #2 + | sub PC, RC, #0x20000 + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 + | ldr CARG1, L->maxstack + | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)] + | ldr KBASE, [PC, #-4+PC2PROTO(k)] + | cmp RA, CARG1 + | bhi ->vm_growstack_l + if (op != BC_JFUNCF) { + | ins_next1 + | ins_next2 + } + |2: + | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters. + | mvn CARG4, #~LJ_TNIL + | blo >3 + if (op == BC_JFUNCF) { + | decode_RD RC, INS + | b =>BC_JLOOP + } else { + | ins_next3 + } + | + |3: // Clear missing parameters. + | strd CARG34, [BASE, NARGS8:RC] + | add NARGS8:RC, NARGS8:RC, #8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 + | ldr CARG1, L->maxstack + | add CARG4, BASE, RC + | add RA, RA, RC + | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC. + | add CARG2, RC, #8+FRAME_VARG + | ldr KBASE, [PC, #-4+PC2PROTO(k)] + | cmp RA, CARG1 + | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG. + | bhs ->vm_growstack_l + | ldrb RB, [PC, #-4+PC2PROTO(numparams)] + | mov RA, BASE + | mov RC, CARG4 + | cmp RB, #0 + | add BASE, CARG4, #8 + | beq >3 + | mvn CARG3, #~LJ_TNIL + |1: + | cmp RA, RC // Less args than parameters? + | ldrdlo CARG12, [RA], #8 + | movhs CARG2, CARG3 + | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC). + |2: + | subs RB, RB, #1 + | strd CARG12, [CARG4, #8]! + | bne <1 + |3: + | ins_next + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | ldr CARG4, CFUNC:CARG3->f + } else { + | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)] + } + | add CARG2, RA, NARGS8:RC + | ldr CARG1, L->maxstack + | add RC, BASE, NARGS8:RC + | str BASE, L->base + | cmp CARG2, CARG1 + | str RC, L->top + if (op == BC_FUNCCW) { + | ldr CARG2, CFUNC:CARG3->f + } + | mv_vmstate CARG3, C + | mov CARG1, L + | bhi ->vm_growstack_c // Need to grow stack. + | st_vmstate CARG3 + | blx CARG4 // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | ldr BASE, L->base + | mv_vmstate CARG3, INTERP + | ldr CRET2, L->top + | lsl RC, CRET1, #3 + | st_vmstate CARG3 + | ldr PC, [BASE, FRAME_PC] + | sub RA, CRET2, RC // RA = L->top - nresults*8 + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 0xe\n" /* Return address is in lr. */ + "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */ + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */ + fcofs, CFRAME_SIZE); + for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */ + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i)); +#if LJ_ARCH_HASFPU + for (i = 15; i >= 8; i--) /* offset d8-d15 */ + fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n", + 64+2*i, 10+2*(15-i)); + fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */ +#endif + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" + "\t.long lj_vm_ffi_call\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */ + "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */ + "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */ + "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */ + "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */ + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + default: + break; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_mips.dasc b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_mips.dasc new file mode 100644 index 0000000..0ec13e6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_mips.dasc @@ -0,0 +1,4241 @@ +|// Low-level VM code for MIPS CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch mips +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r16 // Base of current Lua stack frame. +|.define KBASE, r17 // Constants of current Lua function. +|.define PC, r18 // Next PC. +|.define DISPATCH, r19 // Opcode dispatch table. +|.define LREG, r20 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r21 // Size of multi-result: (nresults+1)*8. +|// NYI: r22 currently unused. +| +|.define JGL, r30 // On-trace: global_State + 32768. +| +|// Constants for type-comparisons, stores and conversions. C callee-save. +|.define TISNIL, r30 +|.define TOBIT, f30 // 2^52 + 2^51. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r23 // Callee-save. +|.define RB, r8 +|.define RC, r9 +|.define RD, r10 +|.define INS, r11 +| +|.define AT, r1 // Assembler temporary. +|.define TMP0, r12 +|.define TMP1, r13 +|.define TMP2, r14 +|.define TMP3, r15 +| +|// Calling conventions. +|.define CFUNCADDR, r25 +|.define CARG1, r4 +|.define CARG2, r5 +|.define CARG3, r6 +|.define CARG4, r7 +| +|.define CRET1, r2 +|.define CRET2, r3 +| +|.define FARG1, f12 +|.define FARG2, f14 +| +|.define FRET1, f0 +|.define FRET2, f2 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define CFRAME_SPACE, 112 // Delta for sp. +| +|.define SAVE_ERRF, 124(sp) // 32 bit C frame info. +|.define SAVE_NRES, 120(sp) +|.define SAVE_CFRAME, 116(sp) +|.define SAVE_L, 112(sp) +|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter. +|.define SAVE_GPR_, 72 // .. 72+10*4: 32 bit GPR saves. +|.define SAVE_FPR_, 24 // .. 24+6*8: 64 bit FPR saves. +|.define SAVE_PC, 20(sp) +|.define ARG5, 16(sp) +|.define CSAVE_4, 12(sp) +|.define CSAVE_3, 8(sp) +|.define CSAVE_2, 4(sp) +|.define CSAVE_1, 0(sp) +|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee. +| +|.define ARG5_OFS, 16 +|.define SAVE_MULTRES, ARG5 +| +|.macro saveregs +| addiu sp, sp, -CFRAME_SPACE +| sw ra, SAVE_GPR_+9*4(sp) +| sw r30, SAVE_GPR_+8*4(sp) +| sdc1 f30, SAVE_FPR_+5*8(sp) +| sw r23, SAVE_GPR_+7*4(sp) +| sw r22, SAVE_GPR_+6*4(sp) +| sdc1 f28, SAVE_FPR_+4*8(sp) +| sw r21, SAVE_GPR_+5*4(sp) +| sw r20, SAVE_GPR_+4*4(sp) +| sdc1 f26, SAVE_FPR_+3*8(sp) +| sw r19, SAVE_GPR_+3*4(sp) +| sw r18, SAVE_GPR_+2*4(sp) +| sdc1 f24, SAVE_FPR_+2*8(sp) +| sw r17, SAVE_GPR_+1*4(sp) +| sw r16, SAVE_GPR_+0*4(sp) +| sdc1 f22, SAVE_FPR_+1*8(sp) +| sdc1 f20, SAVE_FPR_+0*8(sp) +|.endmacro +| +|.macro restoreregs_ret +| lw ra, SAVE_GPR_+9*4(sp) +| lw r30, SAVE_GPR_+8*4(sp) +| ldc1 f30, SAVE_FPR_+5*8(sp) +| lw r23, SAVE_GPR_+7*4(sp) +| lw r22, SAVE_GPR_+6*4(sp) +| ldc1 f28, SAVE_FPR_+4*8(sp) +| lw r21, SAVE_GPR_+5*4(sp) +| lw r20, SAVE_GPR_+4*4(sp) +| ldc1 f26, SAVE_FPR_+3*8(sp) +| lw r19, SAVE_GPR_+3*4(sp) +| lw r18, SAVE_GPR_+2*4(sp) +| ldc1 f24, SAVE_FPR_+2*8(sp) +| lw r17, SAVE_GPR_+1*4(sp) +| lw r16, SAVE_GPR_+0*4(sp) +| ldc1 f22, SAVE_FPR_+1*8(sp) +| ldc1 f20, SAVE_FPR_+0*8(sp) +| jr ra +| addiu sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// Trap for not-yet-implemented parts. +|.macro NYI; .long 0xf0f0f0f0; .endmacro +| +|// Macros to mark delay slots. +|.macro ., a; a; .endmacro +|.macro ., a,b; a,b; .endmacro +|.macro ., a,b,c; a,b,c; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Endian-specific defines. +|.define FRAME_PC, LJ_ENDIAN_SELECT(-4,-8) +|.define FRAME_FUNC, LJ_ENDIAN_SELECT(-8,-4) +|.define HI, LJ_ENDIAN_SELECT(4,0) +|.define LO, LJ_ENDIAN_SELECT(0,4) +|.define OFS_RD, LJ_ENDIAN_SELECT(2,0) +|.define OFS_RA, LJ_ENDIAN_SELECT(1,2) +|.define OFS_OP, LJ_ENDIAN_SELECT(0,3) +| +|// Instruction decode. +|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro +|.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro +|.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro +|.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro +|.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro +|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro +|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro +|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro +|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro +|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro +|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro +|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro +|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lw INS, 0(PC) +| addiu PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT2 +| decode_OP4a TMP1, INS +| decode_OP4b TMP1 +| addu TMP0, DISPATCH, TMP1 +| decode_RD8a RD, INS +| lw AT, 0(TMP0) +| decode_RA8a RA, INS +| decode_RD8b RD +| jr AT +| decode_RA8b RA +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lw PC, LFUNC:RB->pc +| lw INS, 0(PC) +| addiu PC, PC, 4 +| decode_OP4a TMP1, INS +| decode_RA8a RA, INS +| decode_OP4b TMP1 +| decode_RA8b RA +| addu TMP0, DISPATCH, TMP1 +| lw TMP0, 0(TMP0) +| jr TMP0 +| addu RA, RA, BASE +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| sw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|.macro branch_RD +| srl TMP0, RD, 1 +| lui AT, (-(BCBIAS_J*4 >> 16) & 65535) +| addu TMP0, TMP0, AT +| addu PC, PC, TMP0 +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +#define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch)) +#define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro load_got, func +| lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH) +|.endmacro +|// Much faster. Sadly, there's no easy way to force the required code layout. +|// .macro call_intern, func; bal extern func; .endmacro +|.macro call_intern, func; jalr CFUNCADDR; .endmacro +|.macro call_extern; jalr CFUNCADDR; .endmacro +|.macro jmp_extern; jr CFUNCADDR; .endmacro +| +|.macro hotcheck, delta, target +| srl TMP1, PC, 1 +| andi TMP1, TMP1, 126 +| addu TMP1, TMP1, DISPATCH +| lhu TMP2, GG_DISP2HOT(TMP1) +| addiu TMP2, TMP2, -delta +| bltz TMP2, target +|. sh TMP2, GG_DISP2HOT(TMP1) +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP, ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL, ->vm_hotcall +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp, target +| lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| andi mark, mark, ~LJ_GC_BLACK & 255 // black2gray(tab) +| sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| sb mark, tab->marked +| b target +|. sw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andi AT, PC, FRAME_P + | beqz AT, ->cont_dispatch + |. li TMP1, LJ_TTRUE + | + | // Return from pcall or xpcall fast func. + | lw PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | move BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | sw TMP1, FRAME_PC(RA) // Prepend true to results. + | addiu RA, RA, -8 + | + |->vm_returnc: + | addiu RD, RD, 8 // RD = (nresults+1)*8. + | andi TMP0, PC, FRAME_TYPE + | beqz RD, ->vm_unwind_c_eh + |. li CRET1, LUA_YIELD + | beqz TMP0, ->BC_RET_Z // Handle regular return to Lua. + |. move MULTRES, RD + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | li TMP2, -8 + | xori AT, TMP0, FRAME_C + | and TMP2, PC, TMP2 + | bnez AT, ->vm_returnp + | subu TMP2, BASE, TMP2 // TMP2 = previous base. + | + | addiu TMP1, RD, -8 + | sw TMP2, L->base + | li_vmstate C + | lw TMP2, SAVE_NRES + | addiu BASE, BASE, -8 + | st_vmstate + | beqz TMP1, >2 + |. sll TMP2, TMP2, 3 + |1: + | addiu TMP1, TMP1, -8 + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | sdc1 f0, 0(BASE) + | bnez TMP1, <1 + |. addiu BASE, BASE, 8 + | + |2: + | bne TMP2, RD, >6 + |3: + |. sw BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lw TMP0, SAVE_CFRAME // Restore previous C frame. + | move CRET1, r0 // Ok return status for vm_pcall. + | sw TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs_ret + | + |6: + | lw TMP1, L->maxstack + | slt AT, TMP2, RD + | bnez AT, >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + |. slt AT, BASE, TMP1 + | beqz AT, >8 + |. nop + | sw TISNIL, HI(BASE) + | addiu RD, RD, 8 + | b <2 + |. addiu BASE, BASE, 8 + | + |7: // Less results wanted. + | subu TMP0, RD, TMP2 + | subu TMP0, BASE, TMP0 // Either keep top or shrink it. + | b <3 + |. movn BASE, TMP0, TMP2 // LUA_MULTRET+1 case? + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | load_got lj_state_growstack + | move MULTRES, RD + | move CARG2, TMP2 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw TMP2, SAVE_NRES + | lw BASE, L->top // Need the (realloced) L->top in BASE. + | move RD, MULTRES + | b <2 + |. sll TMP2, TMP2, 3 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | move sp, CARG1 + | move CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lw L, SAVE_L + | li TMP0, ~LJ_VMST_C + | lw GL:TMP1, L->glref + | b ->vm_leave_unw + |. sw TMP0, GL:TMP1->vmstate + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | li AT, -4 + | and sp, CARG1, AT + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lw L, SAVE_L + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | li TISNIL, LJ_TNIL + | lw BASE, L->base + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | mtc1 TMP3, TOBIT + | li TMP1, LJ_TFALSE + | li_vmstate INTERP + | lw PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | cvt.d.s TOBIT, TOBIT + | addiu RA, BASE, -8 // Results start at BASE-8. + | addiu DISPATCH, DISPATCH, GG_G2DISP + | sw TMP1, HI(RA) // Prepend false to error message. + | st_vmstate + | b ->vm_returnc + |. li RD, 16 // 2 results: false + error message. + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | b >2 + |. li CARG2, LUA_MINSTACK + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | addu RC, BASE, RC + | subu RA, RA, BASE + | sw BASE, L->base + | addiu PC, PC, 4 // Must point after first instruction. + | sw RC, L->top + | srl CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | load_got lj_state_growstack + | sw PC, SAVE_PC + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw BASE, L->base + | lw RC, L->top + | lw LFUNC:RB, FRAME_FUNC(BASE) + | subu RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | move L, CARG1 + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | move BASE, CARG2 + | lbu TMP1, L->status + | sw L, SAVE_L + | li PC, FRAME_CP + | addiu TMP0, sp, CFRAME_RESUME + | addiu DISPATCH, DISPATCH, GG_G2DISP + | sw r0, SAVE_NRES + | sw r0, SAVE_ERRF + | sw TMP0, L->cframe + | sw r0, SAVE_CFRAME + | beqz TMP1, >3 + |. sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | + | // Resume after yield (like a return). + | move RA, BASE + | lw BASE, L->base + | lw TMP1, L->top + | lw PC, FRAME_PC(BASE) + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | subu RD, TMP1, BASE + | mtc1 TMP3, TOBIT + | sb r0, L->status + | cvt.d.s TOBIT, TOBIT + | li_vmstate INTERP + | addiu RD, RD, 8 + | st_vmstate + | move MULTRES, RD + | andi TMP0, PC, FRAME_TYPE + | beqz TMP0, ->BC_RET_Z + |. li TISNIL, LJ_TNIL + | b ->vm_return + |. nop + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | sw CARG4, SAVE_ERRF + | b >1 + |. li PC, FRAME_CP + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lw TMP1, L:CARG1->cframe + | sw CARG3, SAVE_NRES + | move L, CARG1 + | sw CARG1, SAVE_L + | move BASE, CARG2 + | sw sp, L->cframe // Add our C frame to cframe chain. + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sw TMP1, SAVE_CFRAME + | addiu DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lw TMP2, L->base // TMP2 = old base (used in vmeta_call). + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lw TMP1, L->top + | mtc1 TMP3, TOBIT + | addu PC, PC, BASE + | subu NARGS8:RC, TMP1, BASE + | subu PC, PC, TMP2 // PC = frame delta + frame type + | cvt.d.s TOBIT, TOBIT + | li_vmstate INTERP + | li TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | lw TMP0, FRAME_PC(BASE) + | li AT, LJ_TFUNC + | bne TMP0, AT, ->vmeta_call + |. lw LFUNC:RB, FRAME_FUNC(BASE) + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | move L, CARG1 + | lw TMP0, L:CARG1->stack + | sw CARG1, SAVE_L + | lw TMP1, L->top + | sw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | subu TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lw TMP1, L->cframe + | sw sp, L->cframe // Add our C frame to cframe chain. + | sw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | sw r0, SAVE_ERRF // No error function. + | move CFUNCADDR, CARG4 + | jalr CARG4 // (lua_State *L, lua_CFunction func, void *ud) + |. sw TMP1, SAVE_CFRAME + | move BASE, CRET1 + | lw DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | bnez CRET1, <3 // Else continue with the call. + |. addiu DISPATCH, DISPATCH, GG_G2DISP + | b ->vm_leave_cp // No base? Just remove C frame. + |. nop + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lw TMP0, -16+LO(BASE) // Continuation. + | move RB, BASE + | move BASE, TMP2 // Restore caller BASE. + | lw LFUNC:TMP1, FRAME_FUNC(TMP2) + |.if FFI + | sltiu AT, TMP0, 2 + |.endif + | lw PC, -16+HI(RB) // Restore PC from [cont|PC]. + | addu TMP2, RA, RD + | lw TMP1, LFUNC:TMP1->pc + |.if FFI + | bnez AT, >1 + |.endif + |. sw TISNIL, -8+HI(TMP2) // Ensure one valid arg. + | // BASE = base, RA = resultptr, RB = meta base + | jr TMP0 // Jump to continuation. + |. lw KBASE, PC2PROTO(k)(TMP1) + | + |.if FFI + |1: + | bnez TMP0, ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + |. addiu TMP1, RB, -16 + | b ->vm_call_tail + |. subu RC, TMP1, BASE + |.endif + | + |->cont_cat: // RA = resultptr, RB = meta base + | lw INS, -4(PC) + | addiu CARG2, RB, -16 + | ldc1 f0, 0(RA) + | decode_RB8a MULTRES, INS + | decode_RA8a RA, INS + | decode_RB8b MULTRES + | decode_RA8b RA + | addu TMP1, BASE, MULTRES + | sw BASE, L->base + | subu CARG3, CARG2, TMP1 + | bne TMP1, CARG2, ->BC_CAT_Z + |. sdc1 f0, 0(CARG2) + | addu RA, BASE, RA + | b ->cont_nop + |. sdc1 f0, 0(RA) + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP0, HI(CARG3) + | + |->vmeta_tgets: + | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TTAB + | sw TAB:RB, LO(CARG2) + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2) + | sw TMP0, HI(CARG2) + | li TMP1, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP1, HI(CARG3) + | + |->vmeta_tgetb: // TMP0 = index + | mtc1 TMP0, f0 + | cvt.d.w f0, f0 + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | sdc1 f0, 0(CARG3) + | + |->vmeta_tgetv: + |1: + | load_got lj_meta_tget + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + |. move CARG1, L + | // Returns TValue * (finished) or NULL (metamethod). + | beqz CRET1, >3 + |. addiu TMP1, BASE, -FRAME_CONT + | ldc1 f0, 0(CRET1) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | lw BASE, L->top + | sw PC, -16+HI(BASE) // [cont|PC] + | subu PC, BASE, TMP1 + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | b ->vm_call_dispatch_f + |. li NARGS8:RC, 16 // 2 args for func(t, k). + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP0, HI(CARG3) + | + |->vmeta_tsets: + | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv) + | li TMP0, LJ_TTAB + | sw TAB:RB, LO(CARG2) + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2) + | sw TMP0, HI(CARG2) + | li TMP1, LJ_TSTR + | sw STR:RC, LO(CARG3) + | b >1 + |. sw TMP1, HI(CARG3) + | + |->vmeta_tsetb: // TMP0 = index + | mtc1 TMP0, f0 + | cvt.d.w f0, f0 + | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | sdc1 f0, 0(CARG3) + | + |->vmeta_tsetv: + |1: + | load_got lj_meta_tset + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + |. move CARG1, L + | // Returns TValue * (finished) or NULL (metamethod). + | beqz CRET1, >3 + |. ldc1 f0, 0(RA) + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | ins_next1 + | sdc1 f0, 0(CRET1) + | ins_next2 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | addiu TMP1, BASE, -FRAME_CONT + | lw BASE, L->top + | sw PC, -16+HI(BASE) // [cont|PC] + | subu PC, BASE, TMP1 + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | sdc1 f0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + |. li NARGS8:RC, 24 // 3 args for func(t, k, v) + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | // CARG2, CARG3 are already set by BC_ISLT/BC_ISGE/BC_ISLE/BC_ISGT. + | load_got lj_meta_comp + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | decode_OP1 CARG4, INS + | call_intern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + |3: + | sltiu AT, CRET1, 2 + | beqz AT, ->vmeta_binop + | negu TMP2, CRET1 + |4: + | lhu RD, OFS_RD(PC) + | addiu PC, PC, 4 + | lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535) + | sll RD, RD, 2 + | addu RD, RD, TMP1 + | and RD, RD, TMP2 + | addu PC, PC, RD + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lbu TMP1, -4+OFS_RA(PC) + | ldc1 f0, 0(RA) + | sll TMP1, TMP1, 3 + | addu TMP1, BASE, TMP1 + | b ->cont_nop + |. sdc1 f0, 0(TMP1) + | + |->cont_condt: // RA = resultptr + | lw TMP0, HI(RA) + | sltiu AT, TMP0, LJ_TISTRUECOND + | b <4 + |. negu TMP2, AT // Branch if result is true. + | + |->cont_condf: // RA = resultptr + | lw TMP0, HI(RA) + | sltiu AT, TMP0, LJ_TISTRUECOND + | b <4 + |. addiu TMP2, AT, -1 // Branch if result is false. + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | load_got lj_meta_equal + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |. nop + | + |->vmeta_equal_cd: + |.if FFI + | load_got lj_meta_equal_cd + | move CARG2, INS + | addiu PC, PC, -4 + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_equal_cd // (lua_State *L, BCIns op) + |. move CARG1, L + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |. nop + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_unm: + | move CARG4, CARG3 + | + |->vmeta_arith: + | load_got lj_meta_arith + | decode_OP1 TMP0, INS + | sw BASE, L->base + | sw PC, SAVE_PC + | move CARG2, RA + | sw TMP0, ARG5 + | call_intern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + |. move CARG1, L + | // Returns NULL (finished) or TValue * (metamethod). + | beqz CRET1, ->cont_nop + |. nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | subu TMP1, CRET1, BASE + | sw PC, -16+HI(CRET1) // [cont|PC] + | move TMP2, BASE + | addiu PC, TMP1, FRAME_CONT + | move BASE, CRET1 + | b ->vm_call_dispatch + |. li NARGS8:RC, 16 // 2 args for func(o1, o2). + | + |->vmeta_len: + | // CARG2 already set by BC_LEN. +#if LJ_52 + | move MULTRES, CARG1 +#endif + | load_got lj_meta_len + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_meta_len // (lua_State *L, TValue *o) + |. move CARG1, L + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | bnez CRET1, ->vmeta_binop // Binop call for compatibility. + |. nop + | b ->BC_LEN_Z + |. move CARG1, MULTRES +#else + | b ->vmeta_binop // Binop call for compatibility. + |. nop +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | load_got lj_meta_call + | sw TMP2, L->base // This is the callers base! + | addiu CARG2, BASE, -8 + | sw PC, SAVE_PC + | addu CARG3, BASE, RC + | move MULTRES, NARGS8:RC + | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + |. move CARG1, L + | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addiu NARGS8:RC, MULTRES, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | load_got lj_meta_call + | sw BASE, L->base + | addiu CARG2, RA, -8 + | sw PC, SAVE_PC + | addu CARG3, RA, RC + | move MULTRES, NARGS8:RC + | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + |. move CARG1, L + | lw TMP1, FRAME_PC(BASE) + | lw LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + |. addiu NARGS8:RC, MULTRES, 8 // Got one more argument now. + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | load_got lj_meta_for + | sw BASE, L->base + | move CARG2, RA + | sw PC, SAVE_PC + | move MULTRES, INS + | call_intern lj_meta_for // (lua_State *L, TValue *base) + |. move CARG1, L + |.if JIT + | decode_OP1 TMP0, MULTRES + | li AT, BC_JFORI + |.endif + | decode_RA8a RA, MULTRES + | decode_RD8a RD, MULTRES + | decode_RA8b RA + |.if JIT + | beq TMP0, AT, =>BC_JFORI + |. decode_RD8b RD + | b =>BC_FORI + |. nop + |.else + | b =>BC_FORI + |. decode_RD8b RD + |.endif + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | beqz NARGS8:RC, ->fff_fallback + |. lw CARG3, HI(BASE) + | lw CARG1, LO(BASE) + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | bnez AT, ->fff_fallback + |. lw CARG4, 8+HI(BASE) + | lw CARG1, LO(BASE) + | lw CARG2, 8+LO(BASE) + |.endmacro + | + |.macro .ffunc_n, name // Caveat: has delay slot! + |->ff_ .. name: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. ldc1 FARG1, 0(BASE) + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name // Caveat: has delay slot! + |->ff_ .. name: + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | bnez AT, ->fff_fallback + |. lw CARG4, 8+HI(BASE) + | ldc1 FARG1, 0(BASE) + | ldc1 FARG2, 8(BASE) + | sltiu TMP0, CARG3, LJ_TISNUM + | sltiu TMP1, CARG4, LJ_TISNUM + | and TMP0, TMP0, TMP1 + | beqz TMP0, ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot! + |.macro ffgccheck + | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | subu AT, TMP0, TMP1 + | bgezal AT, ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | sltiu AT, CARG3, LJ_TISTRUECOND + | beqz AT, ->fff_fallback + |. addiu RA, BASE, -8 + | lw PC, FRAME_PC(BASE) + | addiu RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | addu TMP2, RA, NARGS8:RC + | sw CARG3, HI(RA) + | addiu TMP1, BASE, 8 + | beq BASE, TMP2, ->fff_res // Done if exactly 1 argument. + |. sw CARG1, LO(RA) + |1: + | ldc1 f0, 0(TMP1) + | sdc1 f0, -8(TMP1) + | bne TMP1, TMP2, <1 + |. addiu TMP1, TMP1, 8 + | b ->fff_res + |. nop + | + |.ffunc type + | lw CARG3, HI(BASE) + | li TMP1, LJ_TISNUM + | beqz NARGS8:RC, ->fff_fallback + |. sltiu TMP0, CARG3, LJ_TISNUM + | movz TMP1, CARG3, TMP0 + | not TMP1, TMP1 + | sll TMP1, TMP1, 3 + | addu TMP1, CFUNC:RB, TMP1 + | b ->fff_resn + |. ldc1 FRET1, CFUNC:TMP1->upvalue + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | li AT, LJ_TTAB + | bne CARG3, AT, >6 + |. li AT, LJ_TUDATA + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lw TAB:CARG1, TAB:CARG1->metatable + |2: + | lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beqz TAB:CARG1, ->fff_restv + |. li CARG3, LJ_TNIL + | lw TMP0, TAB:CARG1->hmask + | li CARG3, LJ_TTAB // Use metatable as default result. + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:CARG1->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + | li AT, LJ_TSTR + |3: // Rearranged logic, because we expect _not_ to find the key. + | lw CARG4, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | lw NODE:TMP3, NODE:TMP2->next + | bne CARG4, AT, >4 + |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | beq TMP0, STR:RC, >5 + |. lw TMP1, offsetof(Node, val)+LO(NODE:TMP2) + |4: + | beqz NODE:TMP3, ->fff_restv // Not found, keep default result. + |. move NODE:TMP2, NODE:TMP3 + | b <3 + |. nop + |5: + | beq CARG2, TISNIL, ->fff_restv // Ditto for nil value. + |. nop + | move CARG3, CARG2 // Return value of mt.__metatable. + | b ->fff_restv + |. move CARG1, TMP1 + | + |6: + | beq CARG3, AT, <1 + |. sltiu TMP0, CARG3, LJ_TISNUM + | li TMP1, LJ_TISNUM + | movz TMP1, CARG3, TMP0 + | not TMP1, TMP1 + | sll TMP1, TMP1, 2 + | addu TMP1, DISPATCH, TMP1 + | b <2 + |. lw TAB:CARG1, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1) + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. addiu CARG4, CARG4, -LJ_TTAB + | lw TAB:TMP1, TAB:CARG1->metatable + | lbu TMP3, TAB:CARG1->marked + | or AT, CARG4, TAB:TMP1 + | bnez AT, ->fff_fallback + |. andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | beqz AT, ->fff_restv + |. sw TAB:CARG2, TAB:CARG1->metatable + | barrierback TAB:CARG1, TMP3, TMP0, ->fff_restv + | + |.ffunc rawget + | lw CARG4, HI(BASE) + | sltiu AT, NARGS8:RC, 16 + | lw TAB:CARG2, LO(BASE) + | load_got lj_tab_get + | addiu CARG4, CARG4, -LJ_TTAB + | or AT, AT, CARG4 + | bnez AT, ->fff_fallback + | addiu CARG3, BASE, 8 + | call_intern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + |. move CARG1, L + | // Returns cTValue *. + | b ->fff_resn + |. ldc1 FRET1, 0(CRET1) + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | lw CARG1, HI(BASE) + | xori AT, NARGS8:RC, 8 + | sltiu CARG1, CARG1, LJ_TISNUM + | movn CARG1, r0, AT + | beqz CARG1, ->fff_fallback // Exactly one number argument. + |. ldc1 FRET1, 0(BASE) + | b ->fff_resn + |. nop + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | li AT, LJ_TSTR + | // A __tostring method in the string base metatable is ignored. + | beq CARG3, AT, ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + |. lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | sltiu TMP0, CARG3, LJ_TISNUM + | sltiu TMP1, TMP1, 1 + | and TMP0, TMP0, TMP1 + | beqz TMP0, ->fff_fallback + |. sw BASE, L->base // Add frame since C call can throw. + | ffgccheck + |. sw PC, SAVE_PC // Redundant (but a defined value). + | load_got lj_str_fromnum + | move CARG1, L + | call_intern lj_str_fromnum // (lua_State *L, lua_Number *np) + |. move CARG2, BASE + | // Returns GCstr *. + | li CARG3, LJ_TSTR + | b ->fff_restv + |. move CARG1, CRET1 + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | lw CARG1, HI(BASE) + | lw TAB:CARG2, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. addu TMP2, BASE, NARGS8:RC + | li AT, LJ_TTAB + | sw TISNIL, HI(TMP2) // Set missing 2nd arg to nil. + | bne CARG1, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) + | load_got lj_tab_next + | sw BASE, L->base // Add frame since C call can throw. + | sw BASE, L->top // Dummy frame length is ok. + | addiu CARG3, BASE, 8 + | sw PC, SAVE_PC + | call_intern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + |. move CARG1, L + | // Returns 0 at end of traversal. + | beqz CRET1, ->fff_restv // End of traversal: return nil. + |. li CARG3, LJ_TNIL + | ldc1 f0, 8(BASE) // Copy key and value to results. + | addiu RA, BASE, -8 + | ldc1 f2, 16(BASE) + | li RD, (2+1)*8 + | sdc1 f0, 0(RA) + | b ->fff_res + |. sdc1 f2, 8(RA) + | + |.ffunc_1 pairs + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | ldc1 f0, CFUNC:RB->upvalue[0] + | bnez TAB:TMP2, ->fff_fallback +#else + | ldc1 f0, CFUNC:RB->upvalue[0] +#endif + |. addiu RA, BASE, -8 + | sw TISNIL, 8+HI(BASE) + | li RD, (3+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |.ffunc ipairs_aux + | sltiu AT, NARGS8:RC, 16 + | lw CARG3, HI(BASE) + | lw TAB:CARG1, LO(BASE) + | lw CARG4, 8+HI(BASE) + | bnez AT, ->fff_fallback + |. ldc1 FARG2, 8(BASE) + | addiu CARG3, CARG3, -LJ_TTAB + | sltiu AT, CARG4, LJ_TISNUM + | li TMP0, 1 + | movn AT, r0, CARG3 + | mtc1 TMP0, FARG1 + | beqz AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) + | cvt.w.d FRET1, FARG2 + | cvt.d.w FARG1, FARG1 + | lw TMP0, TAB:CARG1->asize + | lw TMP1, TAB:CARG1->array + | mfc1 TMP2, FRET1 + | addiu RA, BASE, -8 + | add.d FARG2, FARG2, FARG1 + | addiu TMP2, TMP2, 1 + | sltu AT, TMP2, TMP0 + | sll TMP3, TMP2, 3 + | addu TMP3, TMP1, TMP3 + | beqz AT, >2 // Not in array part? + |. sdc1 FARG2, 0(RA) + | lw TMP2, HI(TMP3) + | ldc1 f0, 0(TMP3) + |1: + | beq TMP2, TISNIL, ->fff_res // End of iteration, return 0 results. + |. li RD, (0+1)*8 + | li RD, (2+1)*8 + | b ->fff_res + |. sdc1 f0, 8(RA) + |2: // Check for empty hash part first. Otherwise call C function. + | lw TMP0, TAB:CARG1->hmask + | load_got lj_tab_getinth + | beqz TMP0, ->fff_res + |. li RD, (0+1)*8 + | call_intern lj_tab_getinth // (GCtab *t, int32_t key) + |. move CARG2, TMP2 + | // Returns cTValue * or NULL. + | beqz CRET1, ->fff_res + |. li RD, (0+1)*8 + | lw TMP2, HI(CRET1) + | b <1 + |. ldc1 f0, 0(CRET1) + | + |.ffunc_1 ipairs + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. lw PC, FRAME_PC(BASE) +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | ldc1 f0, CFUNC:RB->upvalue[0] + | bnez TAB:TMP2, ->fff_fallback +#else + | ldc1 f0, CFUNC:RB->upvalue[0] +#endif + |. addiu RA, BASE, -8 + | sw r0, 8+HI(BASE) + | sw r0, 8+LO(BASE) + | li RD, (3+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | beqz NARGS8:RC, ->fff_fallback + | move TMP2, BASE + | addiu BASE, BASE, 8 + | // Remember active hook before pcall. + | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT + | andi TMP3, TMP3, 1 + | addiu PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + |. addiu NARGS8:RC, NARGS8:RC, -8 + | + |.ffunc xpcall + | sltiu AT, NARGS8:RC, 16 + | lw CARG4, 8+HI(BASE) + | bnez AT, ->fff_fallback + |. ldc1 FARG2, 8(BASE) + | ldc1 FARG1, 0(BASE) + | lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH) + | li AT, LJ_TFUNC + | move TMP2, BASE + | bne CARG4, AT, ->fff_fallback // Traceback must be a function. + | addiu BASE, BASE, 16 + | // Remember active hook before pcall. + | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT + | sdc1 FARG2, 0(TMP2) // Swap function and traceback. + | andi TMP3, TMP3, 1 + | sdc1 FARG1, 8(TMP2) + | addiu PC, TMP3, 16+FRAME_PCALL + | b ->vm_call_dispatch + |. addiu NARGS8:RC, NARGS8:RC, -16 + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | li AT, LJ_TTHREAD + | bne CARG3, AT, ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | lw L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + | lbu TMP0, L:CARG1->status + | lw TMP1, L:CARG1->cframe + | lw CARG2, L:CARG1->top + | lw TMP2, L:CARG1->base + | addiu TMP3, TMP0, -LUA_YIELD + | bgtz TMP3, ->fff_fallback // st > LUA_YIELD? + |. xor TMP2, TMP2, CARG2 + | bnez TMP1, ->fff_fallback // cframe != 0? + |. or AT, TMP2, TMP0 + | lw TMP0, L:CARG1->maxstack + | beqz AT, ->fff_fallback // base == top && st == 0? + |. lw PC, FRAME_PC(BASE) + | addu TMP2, CARG2, NARGS8:RC + | sltu AT, TMP0, TMP2 + | bnez AT, ->fff_fallback // Stack overflow? + |. sw PC, SAVE_PC + | sw BASE, L->base + |1: + |.if resume + | addiu BASE, BASE, 8 // Keep resumed thread in stack for GC. + | addiu NARGS8:RC, NARGS8:RC, -8 + | addiu TMP2, TMP2, -8 + |.endif + | sw TMP2, L:CARG1->top + | addu TMP1, BASE, NARGS8:RC + | move CARG3, CARG2 + | sw BASE, L->top + |2: // Move args to coroutine. + | ldc1 f0, 0(BASE) + | sltu AT, BASE, TMP1 + | beqz AT, >3 + |. addiu BASE, BASE, 8 + | sdc1 f0, 0(CARG3) + | b <2 + |. addiu CARG3, CARG3, 8 + |3: + | bal ->vm_resume // (lua_State *L, TValue *base, 0, 0) + |. move L:RA, L:CARG1 + | // Returns thread status. + |4: + | lw TMP2, L:RA->base + | sltiu AT, CRET1, LUA_YIELD+1 + | lw TMP3, L:RA->top + | li_vmstate INTERP + | lw BASE, L->base + | st_vmstate + | beqz AT, >8 + |. subu RD, TMP3, TMP2 + | lw TMP0, L->maxstack + | beqz RD, >6 // No results? + |. addu TMP1, BASE, RD + | sltu AT, TMP0, TMP1 + | bnez AT, >9 // Need to grow stack? + |. addu TMP3, TMP2, RD + | sw TMP2, L:RA->top // Clear coroutine stack. + | move TMP1, BASE + |5: // Move results from coroutine. + | ldc1 f0, 0(TMP2) + | addiu TMP2, TMP2, 8 + | sltu AT, TMP2, TMP3 + | sdc1 f0, 0(TMP1) + | bnez AT, <5 + |. addiu TMP1, TMP1, 8 + |6: + | andi TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | addiu RA, BASE, -8 + | sw TMP1, -8+HI(BASE) // Prepend true to results. + | addiu RD, RD, 16 + |.else + | move RA, BASE + | addiu RD, RD, 8 + |.endif + |7: + | sw PC, SAVE_PC + | beqz TMP0, ->BC_RET_Z + |. move MULTRES, RD + | b ->vm_return + |. nop + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | addiu TMP3, TMP3, -8 + | li TMP1, LJ_TFALSE + | ldc1 f0, 0(TMP3) + | sw TMP3, L:RA->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | sw TMP1, -8+HI(BASE) // Prepend false to results. + | addiu RA, BASE, -8 + | sdc1 f0, 0(BASE) // Copy error message. + | b <7 + |. andi TMP0, PC, FRAME_TYPE + |.else + | load_got lj_ffh_coroutine_wrap_err + | move CARG2, L:RA + | call_intern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |. move CARG1, L + |.endif + | + |9: // Handle stack expansion on return from yield. + | load_got lj_state_growstack + | srl CARG2, RD, 3 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | b <4 + |. li CRET1, 0 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lw TMP0, L->cframe + | addu TMP1, BASE, NARGS8:RC + | sw BASE, L->base + | andi TMP0, TMP0, CFRAME_RESUME + | sw TMP1, L->top + | beqz TMP0, ->fff_fallback + |. li CRET1, LUA_YIELD + | sw r0, L->cframe + | b ->vm_leave_unw + |. sb CRET1, L->status + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_n math_abs + |. abs.d FRET1, FARG1 + |->fff_resn: + | lw PC, FRAME_PC(BASE) + | addiu RA, BASE, -8 + | b ->fff_res1 + |. sdc1 FRET1, -8(BASE) + | + |->fff_restv: + | // CARG3/CARG1 = TValue result. + | lw PC, FRAME_PC(BASE) + | sw CARG3, -8+HI(BASE) + | addiu RA, BASE, -8 + | sw CARG1, -8+LO(BASE) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->vm_return + |. move MULTRES, RD + | lw INS, -4(PC) + | decode_RB8a RB, INS + | decode_RB8b RB + |5: + | sltu AT, RD, RB + | bnez AT, >6 // More results expected? + |. decode_RA8a TMP0, INS + | decode_RA8b TMP0 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | subu BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | addu TMP1, RA, RD + | addiu RD, RD, 8 + | b <5 + |. sw TISNIL, -8+HI(TMP1) + | + |.macro math_extern, func + |->ff_math_ .. func: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. load_got func + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. nop + | call_extern + |. ldc1 FARG1, 0(BASE) + | b ->fff_resn + |. nop + |.endmacro + | + |.macro math_extern2, func + | .ffunc_nn math_ .. func + |. load_got func + | call_extern + |. nop + | b ->fff_resn + |. nop + |.endmacro + | + |.macro math_round, func + | .ffunc_n math_ .. func + |. nop + | bal ->vm_ .. func + |. nop + | b ->fff_resn + |. nop + |.endmacro + | + | math_round floor + | math_round ceil + | + |.ffunc math_log + | lw CARG3, HI(BASE) + | li AT, 8 + | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument. + |. load_got log + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. nop + | call_extern + |. ldc1 FARG1, 0(BASE) + | b ->fff_resn + |. nop + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |.ffunc_n math_sqrt + |. sqrt.d FRET1, FARG1 + | b ->fff_resn + |. nop + | + |->ff_math_deg: + |.ffunc_n math_rad + |. ldc1 FARG2, CFUNC:RB->upvalue[0] + | b ->fff_resn + |. mul.d FRET1, FARG1, FARG2 + | + |.ffunc_nn math_ldexp + | cvt.w.d FARG2, FARG2 + | load_got ldexp + | mfc1 CARG3, FARG2 + | call_extern + |. nop + | b ->fff_resn + |. nop + | + |.ffunc_n math_frexp + | load_got frexp + | lw PC, FRAME_PC(BASE) + | call_extern + |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | lw TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | addiu RA, BASE, -8 + | mtc1 TMP1, FARG2 + | sdc1 FRET1, 0(RA) + | cvt.d.w FARG2, FARG2 + | sdc1 FARG2, 8(RA) + | b ->fff_res + |. li RD, (2+1)*8 + | + |.ffunc_n math_modf + | load_got modf + | lw PC, FRAME_PC(BASE) + | call_extern + |. addiu CARG3, BASE, -8 + | addiu RA, BASE, -8 + | sdc1 FRET1, 0(BASE) + | b ->fff_res + |. li RD, (2+1)*8 + | + |.macro math_minmax, name, ismax + |->ff_ .. name: + | lw CARG3, HI(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. ldc1 FRET1, 0(BASE) + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. addu TMP2, BASE, NARGS8:RC + | addiu TMP1, BASE, 8 + | beq TMP1, TMP2, ->fff_resn + |1: + |. lw CARG3, HI(TMP1) + | ldc1 FARG1, 0(TMP1) + | addiu TMP1, TMP1, 8 + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |.if ismax + |. c.olt.d FARG1, FRET1 + |.else + |. c.olt.d FRET1, FARG1 + |.endif + | bne TMP1, TMP2, <1 + |. movf.d FRET1, FARG1 + | b ->fff_resn + |. nop + |.endmacro + | + | math_minmax math_min, 0 + | math_minmax math_max, 1 + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. nop + | b ->fff_resi + |. lw CRET1, STR:CARG1->len + | + |.ffunc string_byte // Only handle the 1-arg case here. + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | xori AT, NARGS8:RC, 8 + | addiu CARG3, CARG3, -LJ_TSTR + | or AT, AT, CARG3 + | bnez AT, ->fff_fallback // Need exactly 1 string argument. + |. nop + | lw TMP0, STR:CARG1->len + | lbu TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | addiu RA, BASE, -8 + | sltu RD, r0, TMP0 + | mtc1 TMP1, f0 + | addiu RD, RD, 1 + | cvt.d.w f0, f0 + | lw PC, FRAME_PC(BASE) + | sll RD, RD, 3 // RD = ((str->len != 0)+1)*8 + | b ->fff_res + |. sdc1 f0, 0(RA) + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | lw CARG3, HI(BASE) + | ldc1 FARG1, 0(BASE) + | li AT, 8 + | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument. + |. sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. li CARG3, 1 + | cvt.w.d FARG1, FARG1 + | addiu CARG2, sp, ARG5_OFS + | sltiu AT, TMP0, 256 + | mfc1 TMP0, FARG1 + | beqz AT, ->fff_fallback + |. sw TMP0, ARG5 + |->fff_newstr: + | load_got lj_str_new + | sw BASE, L->base + | sw PC, SAVE_PC + | call_intern lj_str_new // (lua_State *L, char *str, size_t l) + |. move CARG1, L + | // Returns GCstr *. + | lw BASE, L->base + | move CARG1, CRET1 + | b ->fff_restv + |. li CARG3, LJ_TSTR + | + |.ffunc string_sub + | ffgccheck + | addiu AT, NARGS8:RC, -16 + | lw CARG3, 16+HI(BASE) + | ldc1 f0, 16(BASE) + | lw TMP0, HI(BASE) + | lw STR:CARG1, LO(BASE) + | bltz AT, ->fff_fallback + | lw CARG2, 8+HI(BASE) + | ldc1 f2, 8(BASE) + | beqz AT, >1 + |. li CARG4, -1 + | cvt.w.d f0, f0 + | sltiu AT, CARG3, LJ_TISNUM + | beqz AT, ->fff_fallback + |. mfc1 CARG4, f0 + |1: + | sltiu AT, CARG2, LJ_TISNUM + | beqz AT, ->fff_fallback + |. li AT, LJ_TSTR + | cvt.w.d f2, f2 + | bne TMP0, AT, ->fff_fallback + |. lw CARG2, STR:CARG1->len + | mfc1 CARG3, f2 + | // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end + | slt AT, CARG4, r0 + | addiu TMP0, CARG2, 1 + | addu TMP1, CARG4, TMP0 + | slt TMP3, CARG3, r0 + | movn CARG4, TMP1, AT // if (end < 0) end += len+1 + | addu TMP1, CARG3, TMP0 + | movn CARG3, TMP1, TMP3 // if (start < 0) start += len+1 + | li TMP2, 1 + | slt AT, CARG4, r0 + | slt TMP3, r0, CARG3 + | movn CARG4, r0, AT // if (end < 0) end = 0 + | movz CARG3, TMP2, TMP3 // if (start < 1) start = 1 + | slt AT, CARG2, CARG4 + | movn CARG4, CARG2, AT // if (end > len) end = len + | addu CARG2, STR:CARG1, CARG3 + | subu CARG3, CARG4, CARG3 // len = end - start + | addiu CARG2, CARG2, sizeof(GCstr)-1 + | bgez CARG3, ->fff_newstr + |. addiu CARG3, CARG3, 1 // len++ + |->fff_emptystr: // Return empty string. + | addiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty) + | b ->fff_restv + |. li CARG3, LJ_TSTR + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | lw TMP0, HI(BASE) + | addiu AT, NARGS8:RC, -16 // Exactly 2 arguments. + | lw CARG4, 8+HI(BASE) + | lw STR:CARG1, LO(BASE) + | addiu TMP0, TMP0, -LJ_TSTR + | ldc1 f0, 8(BASE) + | or AT, AT, TMP0 + | bnez AT, ->fff_fallback + |. sltiu AT, CARG4, LJ_TISNUM + | cvt.w.d f0, f0 + | beqz AT, ->fff_fallback + |. lw TMP0, STR:CARG1->len + | mfc1 CARG3, f0 + | lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | li AT, 1 + | blez CARG3, ->fff_emptystr // Count <= 0? + |. sltu AT, AT, TMP0 + | beqz TMP0, ->fff_emptystr // Zero length string? + |. sltu TMP0, TMP1, CARG3 + | or AT, AT, TMP0 + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | bnez AT, ->fff_fallback // Fallback for > 1-char strings. + |. lbu TMP0, STR:CARG1[1] + | addu TMP2, CARG2, CARG3 + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | addiu TMP2, TMP2, -1 + | sltu AT, CARG2, TMP2 + | bnez AT, <1 + |. sb TMP0, 0(TMP2) + | b ->fff_newstr + |. nop + | + |.ffunc string_reverse + | ffgccheck + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | lw CARG3, STR:CARG1->len + | addiu CARG1, STR:CARG1, #STR + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | sltu AT, TMP1, CARG3 + | bnez AT, ->fff_fallback + |. addu TMP3, CARG1, CARG3 + | addu CARG4, CARG2, CARG3 + |1: // Reverse string copy. + | lbu TMP1, 0(CARG1) + | sltu AT, CARG1, TMP3 + | beqz AT, ->fff_newstr + |. addiu CARG1, CARG1, 1 + | addiu CARG4, CARG4, -1 + | b <1 + | sb TMP1, 0(CARG4) + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | lw CARG3, HI(BASE) + | lw STR:CARG1, LO(BASE) + | beqz NARGS8:RC, ->fff_fallback + |. li AT, LJ_TSTR + | bne CARG3, AT, ->fff_fallback + |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | lw CARG3, STR:CARG1->len + | addiu CARG1, STR:CARG1, #STR + | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | sltu AT, TMP1, CARG3 + | bnez AT, ->fff_fallback + |. addu TMP3, CARG1, CARG3 + | move CARG4, CARG2 + |1: // ASCII case conversion. + | lbu TMP1, 0(CARG1) + | sltu AT, CARG1, TMP3 + | beqz AT, ->fff_newstr + |. addiu TMP0, TMP1, -lo + | xori TMP2, TMP1, 0x20 + | sltiu AT, TMP0, 26 + | movn TMP1, TMP2, AT + | addiu CARG1, CARG1, 1 + | sb TMP1, 0(CARG4) + | b <1 + |. addiu CARG4, CARG4, 1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | li AT, LJ_TTAB + | bne CARG3, AT, ->fff_fallback + |. load_got lj_tab_len + | call_intern lj_tab_len // (GCtab *t) + |. nop + | // Returns uint32_t (but less than 2^31). + | b ->fff_resi + |. nop + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + | .ffunc_n bit_..name + |. add.d FARG1, FARG1, TOBIT + | mfc1 CRET1, FARG1 + |.endmacro + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | addiu TMP1, BASE, 8 + | addu TMP2, BASE, NARGS8:RC + |1: + | lw CARG4, HI(TMP1) + | beq TMP1, TMP2, ->fff_resi + |. ldc1 FARG1, 0(TMP1) + | sltiu AT, CARG4, LJ_TISNUM + | beqz AT, ->fff_fallback + | add.d FARG1, FARG1, TOBIT + | mfc1 CARG2, FARG1 + | ins CRET1, CRET1, CARG2 + | b <1 + |. addiu TMP1, TMP1, 8 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | srl TMP0, CRET1, 24 + | srl TMP2, CRET1, 8 + | sll TMP1, CRET1, 24 + | andi TMP2, TMP2, 0xff00 + | or TMP0, TMP0, TMP1 + | andi CRET1, CRET1, 0xff00 + | or TMP0, TMP0, TMP2 + | sll CRET1, CRET1, 8 + | b ->fff_resi + |. or CRET1, TMP0, CRET1 + | + |.ffunc_bit bnot + | b ->fff_resi + |. not CRET1, CRET1 + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc_nn bit_..name + |. add.d FARG1, FARG1, TOBIT + | add.d FARG2, FARG2, TOBIT + | mfc1 CARG1, FARG1 + | mfc1 CARG2, FARG2 + |.if shmod == 1 + | li AT, 32 + | subu TMP0, AT, CARG2 + | sllv CARG2, CARG1, CARG2 + | srlv CARG1, CARG1, TMP0 + |.elif shmod == 2 + | li AT, 32 + | subu TMP0, AT, CARG2 + | srlv CARG2, CARG1, CARG2 + | sllv CARG1, CARG1, TMP0 + |.endif + | b ->fff_resi + |. ins CRET1, CARG1, CARG2 + |.endmacro + | + |.ffunc_bit_sh lshift, sllv, 0 + |.ffunc_bit_sh rshift, srlv, 0 + |.ffunc_bit_sh arshift, srav, 0 + |// Can't use rotrv, since it's only in MIPS32R2. + |.ffunc_bit_sh rol, or, 1 + |.ffunc_bit_sh ror, or, 2 + | + |.ffunc_bit tobit + |->fff_resi: + | mtc1 CRET1, FRET1 + | b ->fff_resn + |. cvt.d.w FRET1, FRET1 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lw TMP3, CFUNC:RB->f + | addu TMP1, BASE, NARGS8:RC + | lw PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addiu TMP0, TMP1, 8*LUA_MINSTACK + | lw TMP2, L->maxstack + | sw PC, SAVE_PC // Redundant (but a defined value). + | sltu AT, TMP2, TMP0 + | sw BASE, L->base + | sw TMP1, L->top + | bnez AT, >5 // Need to grow stack. + |. move CFUNCADDR, TMP3 + | jalr TMP3 // (lua_State *L) + |. move CARG1, L + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lw BASE, L->base + | sll RD, CRET1, 3 + | bgtz CRET1, ->fff_res // Returned nresults+1? + |. addiu RA, BASE, -8 + |1: // Returned 0 or -1: retry fast path. + | lw TMP0, L->top + | lw LFUNC:RB, FRAME_FUNC(BASE) + | bnez CRET1, ->vm_call_tail // Returned -1? + |. subu NARGS8:RC, TMP0, BASE + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andi TMP0, PC, FRAME_TYPE + | li AT, -4 + | bnez TMP0, >3 + |. and TMP1, PC, AT + | lbu TMP1, OFS_RA(PC) + | sll TMP1, TMP1, 3 + | addiu TMP1, TMP1, 8 + |3: + | b ->vm_call_dispatch // Resolve again for tailcall. + |. subu TMP2, BASE, TMP1 + | + |5: // Grow stack for fallback handler. + | load_got lj_state_growstack + | li CARG2, LUA_MINSTACK + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | lw BASE, L->base + | b <1 + |. li CRET1, 0 // Force retry. + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | move MULTRES, ra + | load_got lj_gc_step + | sw BASE, L->base + | addu TMP0, BASE, NARGS8:RC + | sw PC, SAVE_PC // Redundant (but a defined value). + | sw TMP0, L->top + | call_intern lj_gc_step // (lua_State *L) + |. move CARG1, L + | lw BASE, L->base + | move ra, MULTRES + | lw TMP0, L->top + | lw CFUNC:RB, FRAME_FUNC(BASE) + | jr ra + |. subu NARGS8:RC, TMP0, BASE + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi AT, TMP3, HOOK_VMEVENT // No recording while in vmevent. + | bnez AT, >5 + | // Decrement the hookcount for consistency, but always do the call. + |. lw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE + | bnez AT, >1 + |. addiu TMP2, TMP2, -1 + | andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqz AT, >1 + |. nop + | b >1 + |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE // Hook already active? + | beqz AT, >1 + |5: // Re-dispatch to static ins. + |. lw AT, GG_DISP2STATIC(TMP0) // Assumes TMP0 holds DISPATCH+OP*4. + | jr AT + |. nop + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, HOOK_ACTIVE // Hook already active? + | bnez AT, <5 + |. andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqz AT, <5 + |. addiu TMP2, TMP2, -1 + | beqz TMP2, >1 + |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi AT, TMP3, LUA_MASKLINE + | beqz AT, <5 + |1: + |. load_got lj_dispatch_ins + | sw MULTRES, SAVE_MULTRES + | move CARG2, PC + | sw BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | call_intern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |. move CARG1, L + |3: + | lw BASE, L->base + |4: // Re-dispatch to static ins. + | lw INS, -4(PC) + | decode_OP4a TMP1, INS + | decode_OP4b TMP1 + | addu TMP0, DISPATCH, TMP1 + | decode_RD8a RD, INS + | lw AT, GG_DISP2STATIC(TMP0) + | decode_RA8a RA, INS + | decode_RD8b RD + | jr AT + | decode_RA8b RA + | + |->cont_hook: // Continue from hook yield. + | addiu PC, PC, 4 + | b <4 + |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins. + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | lw LFUNC:TMP1, FRAME_FUNC(BASE) + | addiu CARG1, DISPATCH, GG_DISP2J + | sw PC, SAVE_PC + | lw TMP1, LFUNC:TMP1->pc + | move CARG2, PC + | sw L, DISPATCH_J(L)(DISPATCH) + | lbu TMP1, PC2PROTO(framesize)(TMP1) + | load_got lj_trace_hot + | sw BASE, L->base + | sll TMP1, TMP1, 3 + | addu TMP1, BASE, TMP1 + | call_intern lj_trace_hot // (jit_State *J, const BCIns *pc) + |. sw TMP1, L->top + | b <3 + |. nop + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + |.if JIT + | b >1 + |.endif + |. move CARG2, PC + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | load_got lj_dispatch_call + | addu TMP0, BASE, RC + | sw PC, SAVE_PC + | sw BASE, L->base + | subu RA, RA, BASE + | sw TMP0, L->top + | call_intern lj_dispatch_call // (lua_State *L, const BCIns *pc) + |. move CARG1, L + | // Returns ASMFunction. + | lw BASE, L->base + | lw TMP0, L->top + | sw r0, SAVE_PC // Invalidate for subsequent line hook. + | subu NARGS8:RC, TMP0, BASE + | addu RA, BASE, RA + | lw LFUNC:RB, FRAME_FUNC(BASE) + | jr CRET1 + |. lw INS, -4(PC) + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro savex_, a, b + | sdc1 f..a, 16+a*8(sp) + | sw r..a, 16+32*8+a*4(sp) + | sw r..b, 16+32*8+b*4(sp) + |.endmacro + | + |->vm_exit_handler: + |.if JIT + | addiu sp, sp, -(16+32*8+32*4) + | savex_ 0, 1 + | savex_ 2, 3 + | savex_ 4, 5 + | savex_ 6, 7 + | savex_ 8, 9 + | savex_ 10, 11 + | savex_ 12, 13 + | savex_ 14, 15 + | savex_ 16, 17 + | savex_ 18, 19 + | savex_ 20, 21 + | savex_ 22, 23 + | savex_ 24, 25 + | savex_ 26, 27 + | sdc1 f28, 16+28*8(sp) + | sw r28, 16+32*8+28*4(sp) + | sdc1 f30, 16+30*8(sp) + | sw r30, 16+32*8+30*4(sp) + | sw r0, 16+32*8+31*4(sp) // Clear RID_TMP. + | li_vmstate EXIT + | addiu TMP2, sp, 16+32*8+32*4 // Recompute original value of sp. + | addiu DISPATCH, JGL, -GG_DISP2G-32768 + | lw TMP1, 0(TMP2) // Load exit number. + | st_vmstate + | sw TMP2, 16+32*8+29*4(sp) // Store sp in RID_SP. + | lw L, DISPATCH_GL(jit_L)(DISPATCH) + | lw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | load_got lj_trace_exit + | sw L, DISPATCH_J(L)(DISPATCH) + | sw ra, DISPATCH_J(parent)(DISPATCH) // Store trace number. + | sw TMP1, DISPATCH_J(exitno)(DISPATCH) // Store exit number. + | addiu CARG1, DISPATCH, GG_DISP2J + | sw BASE, L->base + | call_intern lj_trace_exit // (jit_State *J, ExitState *ex) + |. addiu CARG2, sp, 16 + | // Returns MULTRES (unscaled) or negated error code. + | lw TMP1, L->cframe + | li AT, -4 + | lw BASE, L->base + | and sp, TMP1, AT + | lw PC, SAVE_PC // Get SAVE_PC. + | b >1 + |. sw L, SAVE_L // Set SAVE_L (on-trace resume/yield). + |.endif + |->vm_exit_interp: + |.if JIT + | // CRET1 = MULTRES or negated error code, BASE, PC and JGL set. + | lw L, SAVE_L + | addiu DISPATCH, JGL, -GG_DISP2G-32768 + |1: + | bltz CRET1, >3 // Check for error from exit. + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | sll MULTRES, CRET1, 3 + | li TISNIL, LJ_TNIL + | sw MULTRES, SAVE_MULTRES + | mtc1 TMP3, TOBIT + | lw TMP1, LFUNC:TMP1->pc + | sw r0, DISPATCH_GL(jit_L)(DISPATCH) + | lw KBASE, PC2PROTO(k)(TMP1) + | cvt.d.s TOBIT, TOBIT + | // Modified copy of ins_next which handles function header dispatch, too. + | lw INS, 0(PC) + | addiu PC, PC, 4 + | // Assumes TISNIL == ~LJ_VMST_INTERP == -1 + | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) + | decode_OP4a TMP1, INS + | decode_OP4b TMP1 + | sltiu TMP2, TMP1, BC_FUNCF*4 // Function header? + | addu TMP0, DISPATCH, TMP1 + | decode_RD8a RD, INS + | lw AT, 0(TMP0) + | decode_RA8a RA, INS + | beqz TMP2, >2 + |. decode_RA8b RA + | jr AT + |. decode_RD8b RD + |2: + | addiu RC, MULTRES, -8 + | jr AT + |. addu RA, RA, BASE + | + |3: // Rethrow error from the right C frame. + | load_got lj_err_throw + | negu CARG2, CRET1 + | call_intern lj_err_throw // (lua_State *L, int errcode) + |. move CARG1, L + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1. + |.macro vm_round, func + | lui TMP0, 0x4330 // Hiword of 2^52 (double). + | mtc1 r0, f4 + | mtc1 TMP0, f5 + | abs.d FRET2, FARG1 // |x| + | mfc1 AT, f13 + | c.olt.d 0, FRET2, f4 + | add.d FRET1, FRET2, f4 // (|x| + 2^52) - 2^52 + | bc1f 0, >1 // Truncate only if |x| < 2^52. + |. sub.d FRET1, FRET1, f4 + | slt AT, AT, r0 + |.if "func" == "ceil" + | lui TMP0, 0xbff0 // Hiword of -1 (double). Preserves -0. + |.else + | lui TMP0, 0x3ff0 // Hiword of +1 (double). + |.endif + |.if "func" == "trunc" + | mtc1 TMP0, f5 + | c.olt.d 0, FRET2, FRET1 // |x| < result? + | sub.d FRET2, FRET1, f4 + | movt.d FRET1, FRET2, 0 // If yes, subtract +1. + | neg.d FRET2, FRET1 + | jr ra + |. movn.d FRET1, FRET2, AT // Merge sign bit back in. + |.else + | neg.d FRET2, FRET1 + | mtc1 TMP0, f5 + | movn.d FRET1, FRET2, AT // Merge sign bit back in. + |.if "func" == "ceil" + | c.olt.d 0, FRET1, FARG1 // x > result? + |.else + | c.olt.d 0, FARG1, FRET1 // x < result? + |.endif + | sub.d FRET2, FRET1, f4 // If yes, subtract +-1. + | jr ra + |. movt.d FRET1, FRET2, 0 + |.endif + |1: + | jr ra + |. mov.d FRET1, FARG1 + |.endmacro + | + |->vm_floor: + | vm_round floor + |->vm_ceil: + | vm_round ceil + |->vm_trunc: + |.if JIT + | vm_round trunc + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in r1, g in r2. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | saveregs + | lw CTSTATE, GL:r2->ctype_state + | addiu DISPATCH, r2, GG_G2DISP + | load_got lj_ccallback_enter + | sw r1, CTSTATE->cb.slot + | sw CARG1, CTSTATE->cb.gpr[0] + | sw CARG2, CTSTATE->cb.gpr[1] + | sdc1 FARG1, CTSTATE->cb.fpr[0] + | sw CARG3, CTSTATE->cb.gpr[2] + | sw CARG4, CTSTATE->cb.gpr[3] + | sdc1 FARG2, CTSTATE->cb.fpr[1] + | addiu TMP0, sp, CFRAME_SPACE+16 + | sw TMP0, CTSTATE->cb.stack + | sw r0, SAVE_PC // Any value outside of bytecode is ok. + | move CARG2, sp + | call_intern lj_ccallback_enter // (CTState *cts, void *cf) + |. move CARG1, CTSTATE + | // Returns lua_State *. + | lw BASE, L:CRET1->base + | lw RC, L:CRET1->top + | move L, CRET1 + | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lw LFUNC:RB, FRAME_FUNC(BASE) + | mtc1 TMP3, TOBIT + | li_vmstate INTERP + | li TISNIL, LJ_TNIL + | subu RC, RC, BASE + | st_vmstate + | cvt.d.s TOBIT, TOBIT + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | load_got lj_ccallback_leave + | lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH) + | sw BASE, L->base + | sw RB, L->top + | sw L, CTSTATE->L + | move CARG2, RA + | call_intern lj_ccallback_leave // (CTState *cts, TValue *o) + |. move CARG1, CTSTATE + | lw CRET1, CTSTATE->cb.gpr[0] + | ldc1 FRET1, CTSTATE->cb.fpr[0] + | lw CRET2, CTSTATE->cb.gpr[1] + | b ->vm_leave_unw + |. ldc1 FRET2, CTSTATE->cb.fpr[1] + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, CARG1 + | lw TMP1, CCSTATE->spadj + | lbu CARG2, CCSTATE->nsp + | move TMP2, sp + | subu sp, sp, TMP1 + | sw ra, -4(TMP2) + | sll CARG2, CARG2, 2 + | sw r16, -8(TMP2) + | sw CCSTATE, -12(TMP2) + | move r16, TMP2 + | addiu TMP1, CCSTATE, offsetof(CCallState, stack) + | addiu TMP2, sp, 16 + | beqz CARG2, >2 + |. addu TMP3, TMP1, CARG2 + |1: + | lw TMP0, 0(TMP1) + | addiu TMP1, TMP1, 4 + | sltu AT, TMP1, TMP3 + | sw TMP0, 0(TMP2) + | bnez AT, <1 + |. addiu TMP2, TMP2, 4 + |2: + | lw CFUNCADDR, CCSTATE->func + | lw CARG2, CCSTATE->gpr[1] + | lw CARG3, CCSTATE->gpr[2] + | lw CARG4, CCSTATE->gpr[3] + | ldc1 FARG1, CCSTATE->fpr[0] + | ldc1 FARG2, CCSTATE->fpr[1] + | jalr CFUNCADDR + |. lw CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1. + | lw CCSTATE:TMP1, -12(r16) + | lw TMP2, -8(r16) + | lw ra, -4(r16) + | sw CRET1, CCSTATE:TMP1->gpr[0] + | sw CRET2, CCSTATE:TMP1->gpr[1] + | sdc1 FRET1, CCSTATE:TMP1->fpr[0] + | sdc1 FRET2, CCSTATE:TMP1->fpr[1] + | move sp, r16 + | jr ra + |. move r16, TMP2 + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + | addu CARG2, BASE, RA + | addu CARG3, BASE, RD + | lw TMP0, HI(CARG2) + | lw TMP1, HI(CARG3) + | ldc1 f0, 0(CARG2) + | ldc1 f2, 0(CARG3) + | sltiu TMP0, TMP0, LJ_TISNUM + | sltiu TMP1, TMP1, LJ_TISNUM + | lhu TMP2, OFS_RD(PC) + | and TMP0, TMP0, TMP1 + | addiu PC, PC, 4 + | beqz TMP0, ->vmeta_comp + |. lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535) + | decode_RD4b TMP2 + | addu TMP2, TMP2, TMP1 + if (op == BC_ISLT || op == BC_ISGE) { + | c.olt.d f0, f2 + } else { + | c.ole.d f0, f2 + } + if (op == BC_ISLT || op == BC_ISLE) { + | movf TMP2, r0 + } else { + | movt TMP2, r0 + } + | addu PC, PC, TMP2 + |1: + | ins_next + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | ldc1 f0, 0(RA) + | addu RD, BASE, RD + | lhu TMP2, -4+OFS_RD(PC) + | lw TMP1, HI(RD) + | ldc1 f2, 0(RD) + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sltiu AT, TMP0, LJ_TISNUM + | sltiu CARG1, TMP1, LJ_TISNUM + | decode_RD4b TMP2 + | and AT, AT, CARG1 + | beqz AT, >5 + |. addu TMP2, TMP2, TMP3 + | c.eq.d f0, f2 + if (vk) { + | movf TMP2, r0 + } else { + | movt TMP2, r0 + } + |1: + | addu PC, PC, TMP2 + | ins_next + |5: // Either or both types are not numbers. + | lw CARG2, LO(RA) + | lw CARG3, LO(RD) + |.if FFI + | li TMP3, LJ_TCDATA + | beq TMP0, TMP3, ->vmeta_equal_cd + |.endif + |. sltiu AT, TMP0, LJ_TISPRI // Not a primitive? + |.if FFI + | beq TMP1, TMP3, ->vmeta_equal_cd + |.endif + |. xor TMP3, CARG2, CARG3 // Same tv? + | xor TMP1, TMP1, TMP0 // Same type? + | sltiu CARG1, TMP0, LJ_TISTABUD+1 // Table or userdata? + | movz TMP3, r0, AT // Ignore tv if primitive. + | movn CARG1, r0, TMP1 // Tab/ud and same type? + | or AT, TMP1, TMP3 // Same type && (pri||same tv). + | movz CARG1, r0, AT + | beqz CARG1, <1 // Done if not tab/ud or not same type or same tv. + if (vk) { + |. movn TMP2, r0, AT + } else { + |. movz TMP2, r0, AT + } + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lw TAB:TMP1, TAB:CARG2->metatable + | beqz TAB:TMP1, <1 // No metatable? + |. nop + | lbu TMP1, TAB:TMP1->nomm + | andi TMP1, TMP1, 1<vmeta_equal // Handle __eq metamethod. + |. li CARG4, 1-vk // ne = 0 or 1. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | srl RD, RD, 1 + | lw STR:TMP3, LO(RA) + | subu RD, KBASE, RD + | lhu TMP2, -4+OFS_RD(PC) + |.if FFI + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |.endif + |. lw STR:TMP1, -4(RD) // KBASE-4-str_const*4 + | addiu TMP0, TMP0, -LJ_TSTR + | decode_RD4b TMP2 + | xor TMP1, STR:TMP1, STR:TMP3 + | or TMP0, TMP0, TMP1 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (vk) { + | movn TMP2, r0, TMP0 + } else { + | movz TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + | addu RA, BASE, RA + | addiu PC, PC, 4 + | lw TMP0, HI(RA) + | ldc1 f0, 0(RA) + | addu RD, KBASE, RD + | lhu TMP2, -4+OFS_RD(PC) + | ldc1 f2, 0(RD) + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sltiu AT, TMP0, LJ_TISNUM + | decode_RD4b TMP2 + |.if FFI + | beqz AT, >5 + |.else + | beqz AT, >1 + |.endif + |. addu TMP2, TMP2, TMP3 + | c.eq.d f0, f2 + if (vk) { + | movf TMP2, r0 + | addu PC, PC, TMP2 + |1: + } else { + | movt TMP2, r0 + |1: + | addu PC, PC, TMP2 + } + | ins_next + |.if FFI + |5: + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |. nop + | b <1 + |. nop + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | addu RA, BASE, RA + | srl TMP1, RD, 3 + | lw TMP0, HI(RA) + | lhu TMP2, OFS_RD(PC) + | not TMP1, TMP1 + | addiu PC, PC, 4 + |.if FFI + | li AT, LJ_TCDATA + | beq TMP0, AT, ->vmeta_equal_cd + |.endif + |. xor TMP0, TMP0, TMP1 + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (vk) { + | movn TMP2, r0, TMP0 + } else { + | movz TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | addu RD, BASE, RD + | lhu TMP2, OFS_RD(PC) + | lw TMP0, HI(RD) + | addiu PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + if (op == BC_IST) { + | movz TMP2, r0, TMP0 + } else { + | movn TMP2, r0, TMP0 + } + | addu PC, PC, TMP2 + } else { + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | ldc1 f0, 0(RD) + if (op == BC_ISTC) { + | beqz TMP0, >1 + } else { + | bnez TMP0, >1 + } + |. addu RA, BASE, RA + | decode_RD4b TMP2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | addu TMP2, TMP2, TMP3 + | sdc1 f0, 0(RA) + | addu PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | addu RD, BASE, RD + | addu RA, BASE, RA + | ldc1 f0, 0(RD) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | addu RD, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(RD) + | li TMP1, LJ_TFALSE + | sltiu TMP0, TMP0, LJ_TISTRUECOND + | addiu TMP1, TMP0, LJ_TTRUE + | ins_next1 + | sw TMP1, HI(RA) + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | addu CARG3, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(CARG3) + | ldc1 f0, 0(CARG3) + | sltiu AT, TMP0, LJ_TISNUM + | beqz AT, ->vmeta_unm + |. neg.d f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | addu CARG2, BASE, RD + | addu RA, BASE, RA + | lw TMP0, HI(CARG2) + | lw CARG1, LO(CARG2) + | li AT, LJ_TSTR + | bne TMP0, AT, >2 + |. li AT, LJ_TTAB + | lw CRET1, STR:CARG1->len + |1: + | mtc1 CRET1, f0 + | cvt.d.w f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + |2: + | bne TMP0, AT, ->vmeta_len + |. nop +#if LJ_52 + | lw TAB:TMP2, TAB:CARG1->metatable + | bnez TAB:TMP2, >9 + |. nop + |3: +#endif + |->BC_LEN_Z: + | load_got lj_tab_len + | call_intern lj_tab_len // (GCtab *t) + |. nop + | // Returns uint32_t (but less than 2^31). + | b <1 + |. nop +#if LJ_52 + |9: + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_len + |. nop +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||switch (vk) { + ||case 0: + | addu CARG3, BASE, RB + | addu CARG4, KBASE, RC + | lw TMP1, HI(CARG3) + | ldc1 f20, 0(CARG3) + | ldc1 f22, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + || break; + ||case 1: + | addu CARG4, BASE, RB + | addu CARG3, KBASE, RC + | lw TMP1, HI(CARG4) + | ldc1 f22, 0(CARG4) + | ldc1 f20, 0(CARG3) + | sltiu AT, TMP1, LJ_TISNUM + || break; + ||default: + | addu CARG3, BASE, RB + | addu CARG4, BASE, RC + | lw TMP1, HI(CARG3) + | lw TMP2, HI(CARG4) + | ldc1 f20, 0(CARG3) + | ldc1 f22, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + | sltiu TMP0, TMP2, LJ_TISNUM + | and AT, AT, TMP0 + || break; + ||} + | beqz AT, ->vmeta_arith + |. addu RA, BASE, RA + |.endmacro + | + |.macro fpmod, a, b, c + |->BC_MODVN_Z: + | bal ->vm_floor // floor(b/c) + |. div.d FARG1, b, c + | mul.d a, FRET1, c + | sub.d a, b, a // b - floor(b/c)*c + |.endmacro + | + |.macro ins_arith, ins + | ins_arithpre + |.if "ins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |. nop + |.else + | ins f0, f20, f22 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith add.d + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith sub.d + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith mul.d + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith div.d + break; + case BC_MODVN: + | ins_arith fpmod + break; + case BC_MODNV: case BC_MODVV: + | ins_arith fpmod_ + break; + case BC_POW: + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG3, BASE, RB + | addu CARG4, BASE, RC + | lw TMP1, HI(CARG3) + | lw TMP2, HI(CARG4) + | ldc1 FARG1, 0(CARG3) + | ldc1 FARG2, 0(CARG4) + | sltiu AT, TMP1, LJ_TISNUM + | sltiu TMP0, TMP2, LJ_TISNUM + | and AT, AT, TMP0 + | load_got pow + | beqz AT, ->vmeta_arith + |. addu RA, BASE, RA + | call_extern + |. nop + | ins_next1 + | sdc1 FRET1, 0(RA) + | ins_next2 + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | subu CARG3, RC, RB + | sw BASE, L->base + | addu CARG2, BASE, RC + | move MULTRES, RB + |->BC_CAT_Z: + | load_got lj_meta_cat + | srl CARG3, CARG3, 3 + | sw PC, SAVE_PC + | call_intern lj_meta_cat // (lua_State *L, TValue *top, int left) + |. move CARG1, L + | // Returns NULL (finished) or TValue * (metamethod). + | bnez CRET1, ->vmeta_binop + |. lw BASE, L->base + | addu RB, BASE, MULTRES + | ldc1 f0, 0(RB) + | addu RA, BASE, RA + | ins_next1 + | sdc1 f0, 0(RA) // Copy result from RB to RA. + | ins_next2 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | ins_next1 + | lw TMP0, -4(TMP1) // KBASE-4-str_const*4 + | addu RA, BASE, RA + | li TMP2, LJ_TSTR + | sw TMP0, LO(RA) + | sw TMP2, HI(RA) + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | ins_next1 + | lw TMP0, -4(TMP1) // KBASE-4-cdata_const*4 + | addu RA, BASE, RA + | li TMP2, LJ_TCDATA + | sw TMP0, LO(RA) + | sw TMP2, HI(RA) + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + | sra RD, INS, 16 + | mtc1 RD, f0 + | addu RA, BASE, RA + | cvt.d.w f0, f0 + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | addu RD, KBASE, RD + | addu RA, BASE, RA + | ldc1 f0, 0(RD) + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srl TMP1, RD, 3 + | addu RA, BASE, RA + | not TMP0, TMP1 + | ins_next1 + | sw TMP0, HI(RA) + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | addu RA, BASE, RA + | sw TISNIL, HI(RA) + | addiu RA, RA, 8 + | addu RD, BASE, RD + |1: + | sw TISNIL, HI(RA) + | slt AT, RA, RD + | bnez AT, <1 + |. addiu RA, RA, 8 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RD, RD, 1 + | addu RD, RD, LFUNC:RB + | lw UPVAL:RB, LFUNC:RD->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | ldc1 f0, 0(TMP1) + | addu RA, BASE, RA + | sdc1 f0, 0(RA) + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | addu RD, BASE, RD + | addu RA, RA, LFUNC:RB + | ldc1 f0, 0(RD) + | lw UPVAL:RB, LFUNC:RA->uvptr + | lbu TMP3, UPVAL:RB->marked + | lw CARG2, UPVAL:RB->v + | andi TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbu TMP0, UPVAL:RB->closed + | lw TMP2, HI(RD) + | sdc1 f0, 0(CARG2) + | li AT, LJ_GC_BLACK|1 + | or TMP3, TMP3, TMP0 + | beq TMP3, AT, >2 // Upvalue is closed and black? + |. addiu TMP2, TMP2, -(LJ_TNUMX+1) + |1: + | ins_next + | + |2: // Check if new value is collectable. + | sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1) + | beqz AT, <1 // tvisgcv(v) + |. lw TMP1, LO(RD) + | lbu TMP3, GCOBJ:TMP1->gch.marked + | andi TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | beqz TMP3, <1 + |. load_got lj_gc_barrieruv + | // Crossed a write barrier. Move the barrier forward. + | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv) + |. addiu CARG1, DISPATCH, GG_DISP2G + | b <1 + |. nop + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | srl TMP1, RD, 1 + | addu RA, RA, LFUNC:RB + | subu TMP1, KBASE, TMP1 + | lw UPVAL:RB, LFUNC:RA->uvptr + | lw STR:TMP1, -4(TMP1) // KBASE-4-str_const*4 + | lbu TMP2, UPVAL:RB->marked + | lw CARG2, UPVAL:RB->v + | lbu TMP3, STR:TMP1->marked + | andi AT, TMP2, LJ_GC_BLACK // isblack(uv) + | lbu TMP2, UPVAL:RB->closed + | li TMP0, LJ_TSTR + | sw STR:TMP1, LO(CARG2) + | bnez AT, >2 + |. sw TMP0, HI(CARG2) + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | beqz TMP2, <1 + |. andi AT, TMP3, LJ_GC_WHITES // iswhite(str) + | beqz AT, <1 + |. load_got lj_gc_barrieruv + | // Crossed a write barrier. Move the barrier forward. + | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv) + |. addiu CARG1, DISPATCH, GG_DISP2G + | b <1 + |. nop + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | addu RD, KBASE, RD + | addu RA, RA, LFUNC:RB + | ldc1 f0, 0(RD) + | lw UPVAL:RB, LFUNC:RA->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | sdc1 f0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | lw LFUNC:RB, FRAME_FUNC(BASE) + | srl RA, RA, 1 + | srl TMP0, RD, 3 + | addu RA, RA, LFUNC:RB + | not TMP0, TMP0 + | lw UPVAL:RB, LFUNC:RA->uvptr + | ins_next1 + | lw TMP1, UPVAL:RB->v + | sw TMP0, HI(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lw TMP2, L->openupval + | branch_RD // Do this first since RD is not saved. + | load_got lj_func_closeuv + | sw BASE, L->base + | beqz TMP2, >1 + |. move CARG1, L + | call_intern lj_func_closeuv // (lua_State *L, TValue *level) + |. addu CARG2, BASE, RA + | lw BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srl TMP1, RD, 1 + | load_got lj_func_newL_gc + | subu TMP1, KBASE, TMP1 + | lw CARG3, FRAME_FUNC(BASE) + | lw CARG2, -4(TMP1) // KBASE-4-tab_const*4 + | sw BASE, L->base + | sw PC, SAVE_PC + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | call_intern lj_func_newL_gc + |. move CARG1, L + | // Returns GCfuncL *. + | lw BASE, L->base + | li TMP0, LJ_TFUNC + | ins_next1 + | addu RA, BASE, RA + | sw TMP0, HI(RA) + | sw LFUNC:CRET1, LO(RA) + | ins_next2 + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | sw BASE, L->base + | sw PC, SAVE_PC + | sltu AT, TMP0, TMP1 + | beqz AT, >5 + |1: + if (op == BC_TNEW) { + | load_got lj_tab_new + | srl CARG2, RD, 3 + | andi CARG2, CARG2, 0x7ff + | li TMP0, 0x801 + | addiu AT, CARG2, -0x7ff + | srl CARG3, RD, 14 + | movz CARG2, TMP0, AT + | // (lua_State *L, int32_t asize, uint32_t hbits) + | call_intern lj_tab_new + |. move CARG1, L + | // Returns Table *. + } else { + | load_got lj_tab_dup + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | move CARG1, L + | call_intern lj_tab_dup // (lua_State *L, Table *kt) + |. lw CARG2, -4(TMP1) // KBASE-4-str_const*4 + | // Returns Table *. + } + | lw BASE, L->base + | ins_next1 + | addu RA, BASE, RA + | li TMP0, LJ_TTAB + | sw TAB:CRET1, LO(RA) + | sw TMP0, HI(RA) + | ins_next2 + |5: + | load_got lj_gc_step_fixtop + | move MULTRES, RD + | call_intern lj_gc_step_fixtop // (lua_State *L) + |. move CARG1, L + | b <1 + |. move RD, MULTRES + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lw LFUNC:TMP2, FRAME_FUNC(BASE) + | srl TMP1, RD, 1 + | subu TMP1, KBASE, TMP1 + | lw TAB:RB, LFUNC:TMP2->env + | lw STR:RC, -4(TMP1) // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + |. addu RA, BASE, RA + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG2, BASE, RB + | addu CARG3, BASE, RC + | lw TMP1, HI(CARG2) + | lw TMP2, HI(CARG3) + | lw TAB:RB, LO(CARG2) + | li AT, LJ_TTAB + | ldc1 f0, 0(CARG3) + | bne TMP1, AT, ->vmeta_tgetv + |. addu RA, BASE, RA + | sltiu AT, TMP2, LJ_TISNUM + | beqz AT, >5 + |. li AT, LJ_TSTR + | + | // Convert number key to integer, check for integerness and range. + | cvt.w.d f2, f0 + | lw TMP0, TAB:RB->asize + | mfc1 TMP2, f2 + | cvt.d.w f4, f2 + | lw TMP1, TAB:RB->array + | c.eq.d f0, f4 + | sltu AT, TMP2, TMP0 + | movf AT, r0 + | sll TMP2, TMP2, 3 + | beqz AT, ->vmeta_tgetv // Integer key and in array part? + |. addu TMP2, TMP1, TMP2 + | lw TMP0, HI(TMP2) + | beq TMP0, TISNIL, >2 + |. ldc1 f0, 0(TMP2) + |1: + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |2: // Check for __index if table value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_tgetv + |. nop + | + |5: + | bne TMP2, AT, ->vmeta_tgetv + |. lw STR:RC, LO(CARG3) + | b ->BC_TGETS_Z // String key? + |. nop + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*4 (~) + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RC4a RC, INS + | lw TMP0, HI(CARG2) + | decode_RC4b RC + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | subu CARG3, KBASE, RC + | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4 + | bne TMP0, AT, ->vmeta_tgets1 + |. addu RA, BASE, RA + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lw TMP0, TAB:RB->hmask + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:RB->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | lw NODE:TMP1, NODE:TMP2->next + | lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | addiu CARG1, CARG1, -LJ_TSTR + | xor TMP0, TMP0, STR:RC + | or AT, CARG1, TMP0 + | bnez AT, >4 + |. lw TAB:TMP3, TAB:RB->metatable + | beq CARG2, TISNIL, >5 // Key found, but nil value? + |. lw CARG1, offsetof(Node, val)+LO(NODE:TMP2) + |3: + | ins_next1 + | sw CARG2, HI(RA) + | sw CARG1, LO(RA) + | ins_next2 + | + |4: // Follow hash chain. + | bnez NODE:TMP1, <1 + |. move NODE:TMP2, NODE:TMP1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | beqz TAB:TMP3, <3 // No metatable: done. + |. li CARG2, LJ_TNIL + | lbu TMP0, TAB:TMP3->nomm + | andi TMP0, TMP0, 1<vmeta_tgets + |. nop + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RDtoRC8 RC, RD + | lw CARG1, HI(CARG2) + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | addu RA, BASE, RA + | bne CARG1, AT, ->vmeta_tgetb + |. srl TMP0, RC, 3 + | lw TMP1, TAB:RB->asize + | lw TMP2, TAB:RB->array + | sltu AT, TMP0, TMP1 + | beqz AT, ->vmeta_tgetb + |. addu RC, TMP2, RC + | lw TMP1, HI(RC) + | beq TMP1, TISNIL, >5 + |. ldc1 f0, 0(RC) + |1: + | ins_next1 + | sdc1 f0, 0(RA) + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP1, TAB:TMP2->nomm + | andi TMP1, TMP1, 1<vmeta_tgetb // Caveat: preserve TMP0! + |. nop + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | decode_RDtoRC8 RC, RD + | addu CARG2, BASE, RB + | addu CARG3, BASE, RC + | lw TMP1, HI(CARG2) + | lw TMP2, HI(CARG3) + | lw TAB:RB, LO(CARG2) + | li AT, LJ_TTAB + | ldc1 f0, 0(CARG3) + | bne TMP1, AT, ->vmeta_tsetv + |. addu RA, BASE, RA + | sltiu AT, TMP2, LJ_TISNUM + | beqz AT, >5 + |. li AT, LJ_TSTR + | + | // Convert number key to integer, check for integerness and range. + | cvt.w.d f2, f0 + | lw TMP0, TAB:RB->asize + | mfc1 TMP2, f2 + | cvt.d.w f4, f2 + | lw TMP1, TAB:RB->array + | c.eq.d f0, f4 + | sltu AT, TMP2, TMP0 + | movf AT, r0 + | sll TMP2, TMP2, 3 + | beqz AT, ->vmeta_tsetv // Integer key and in array part? + |. addu TMP1, TMP1, TMP2 + | lbu TMP3, TAB:RB->marked + | lw TMP0, HI(TMP1) + | beq TMP0, TISNIL, >3 + |. ldc1 f0, 0(RA) + |1: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f0, 0(TMP1) + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP2, TAB:TMP2->nomm + | andi TMP2, TMP2, 1<vmeta_tsetv + |. nop + | + |5: + | bne TMP2, AT, ->vmeta_tsetv + |. lw STR:RC, LO(CARG3) + | b ->BC_TSETS_Z // String key? + |. nop + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RC4a RC, INS + | lw TMP0, HI(CARG2) + | decode_RC4b RC + | li AT, LJ_TTAB + | subu CARG3, KBASE, RC + | lw TAB:RB, LO(CARG2) + | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4 + | bne TMP0, AT, ->vmeta_tsets1 + |. addu RA, BASE, RA + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8 + | lw TMP0, TAB:RB->hmask + | lw TMP1, STR:RC->hash + | lw NODE:TMP2, TAB:RB->node + | sb r0, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | sll TMP0, TMP1, 5 + | sll TMP1, TMP1, 3 + | subu TMP1, TMP0, TMP1 + | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + | ldc1 f20, 0(RA) + |1: + | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2) + | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2) + | li AT, LJ_TSTR + | lw NODE:TMP1, NODE:TMP2->next + | bne CARG1, AT, >5 + |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2) + | bne TMP0, STR:RC, >5 + |. lbu TMP3, TAB:RB->marked + | beq CARG2, TISNIL, >4 // Key found, but nil value? + |. lw TAB:TMP0, TAB:RB->metatable + |2: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f20, NODE:TMP2->val + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | beqz TAB:TMP0, <2 // No metatable: done. + |. nop + | lbu TMP0, TAB:TMP0->nomm + | andi TMP0, TMP0, 1<vmeta_tsets + |. nop + | + |5: // Follow hash chain. + | bnez NODE:TMP1, <1 + |. move NODE:TMP2, NODE:TMP1 + | // End of hash chain: key not found, add a new one + | + | // But check for __newindex first. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, >6 // No metatable: continue. + |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv) + | lbu TMP0, TAB:TMP2->nomm + | andi TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |. li AT, LJ_TSTR + |6: + | load_got lj_tab_newkey + | sw STR:RC, LO(CARG3) + | sw AT, HI(CARG3) + | sw BASE, L->base + | move CARG2, TAB:RB + | sw PC, SAVE_PC + | call_intern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k + |. move CARG1, L + | // Returns TValue *. + | lw BASE, L->base + | b <3 // No 2nd write barrier needed. + |. sdc1 f20, 0(CRET1) + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | decode_RB8a RB, INS + | decode_RB8b RB + | addu CARG2, BASE, RB + | decode_RDtoRC8 RC, RD + | lw CARG1, HI(CARG2) + | li AT, LJ_TTAB + | lw TAB:RB, LO(CARG2) + | addu RA, BASE, RA + | bne CARG1, AT, ->vmeta_tsetb + |. srl TMP0, RC, 3 + | lw TMP1, TAB:RB->asize + | lw TMP2, TAB:RB->array + | sltu AT, TMP0, TMP1 + | beqz AT, ->vmeta_tsetb + |. addu RC, TMP2, RC + | lw TMP1, HI(RC) + | lbu TMP3, TAB:RB->marked + | beq TMP1, TISNIL, >5 + |. ldc1 f0, 0(RA) + |1: + | andi AT, TMP3, LJ_GC_BLACK // isblack(table) + | bnez AT, >7 + |. sdc1 f0, 0(RC) + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lw TAB:TMP2, TAB:RB->metatable + | beqz TAB:TMP2, <1 // No metatable: done. + |. nop + | lbu TMP1, TAB:TMP2->nomm + | andi TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + |. nop + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0, <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | addu RA, BASE, RA + |1: + | addu TMP3, KBASE, RD + | lw TAB:CARG2, -8+LO(RA) // Guaranteed to be a table. + | addiu TMP0, MULTRES, -8 + | lw TMP3, LO(TMP3) // Integer constant is in lo-word. + | beqz TMP0, >4 // Nothing to copy? + |. srl CARG3, TMP0, 3 + | addu CARG3, CARG3, TMP3 + | lw TMP2, TAB:CARG2->asize + | sll TMP1, TMP3, 3 + | lbu TMP3, TAB:CARG2->marked + | lw CARG1, TAB:CARG2->array + | sltu AT, TMP2, CARG3 + | bnez AT, >5 + |. addu TMP2, RA, TMP0 + | addu TMP1, TMP1, CARG1 + | andi TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | sltu AT, RA, TMP2 + | sdc1 f0, 0(TMP1) + | bnez AT, <3 + |. addiu TMP1, TMP1, 8 + | bnez TMP0, >7 + |. nop + |4: + | ins_next + | + |5: // Need to resize array part. + | load_got lj_tab_reasize + | sw BASE, L->base + | sw PC, SAVE_PC + | move BASE, RD + | call_intern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + |. move CARG1, L + | // Must not reallocate the stack. + | move RD, BASE + | b <1 + |. lw BASE, L->base // Reload BASE for lack of a saved register. + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0, <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | decode_RDtoRC8 NARGS8:RC, RD + | b ->BC_CALL_Z + |. addu NARGS8:RC, NARGS8:RC, MULTRES + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | decode_RDtoRC8 NARGS8:RC, RD + |->BC_CALL_Z: + | move TMP2, BASE + | addu BASE, BASE, RA + | li AT, LJ_TFUNC + | lw TMP0, HI(BASE) + | lw LFUNC:RB, LO(BASE) + | addiu BASE, BASE, 8 + | bne TMP0, AT, ->vmeta_call + |. addiu NARGS8:RC, NARGS8:RC, -8 + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | addu NARGS8:RD, NARGS8:RD, MULTRES // BC_CALLT gets RC from RD. + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | addu RA, BASE, RA + | li AT, LJ_TFUNC + | lw TMP0, HI(RA) + | lw LFUNC:RB, LO(RA) + | move NARGS8:RC, RD + | lw TMP1, FRAME_PC(BASE) + | addiu RA, RA, 8 + | bne TMP0, AT, ->vmeta_callt + |. addiu NARGS8:RC, NARGS8:RC, -8 + |->BC_CALLT_Z: + | andi TMP0, TMP1, FRAME_TYPE // Caveat: preserve TMP0 until the 'or'. + | lbu TMP3, LFUNC:RB->ffid + | bnez TMP0, >7 + |. xori TMP2, TMP1, FRAME_VARG + |1: + | sw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | sltiu AT, TMP3, 2 // (> FF_C) Calling a fast function? + | move TMP2, BASE + | beqz NARGS8:RC, >3 + |. move TMP3, NARGS8:RC + |2: + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | addiu TMP3, TMP3, -8 + | sdc1 f0, 0(TMP2) + | bnez TMP3, <2 + |. addiu TMP2, TMP2, 8 + |3: + | or TMP0, TMP0, AT + | beqz TMP0, >5 + |. nop + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lw INS, -4(TMP1) + | decode_RA8a RA, INS + | decode_RA8b RA + | subu TMP1, BASE, RA + | lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1) + | lw TMP1, LFUNC:TMP1->pc + | b <4 + |. lw KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | + |7: // Tailcall from a vararg function. + | andi AT, TMP2, FRAME_TYPEP + | bnez AT, <1 // Vararg frame below? + |. subu TMP2, BASE, TMP2 // Relocate BASE down. + | move BASE, TMP2 + | lw TMP1, FRAME_PC(TMP2) + | b <1 + |. andi TMP0, TMP1, FRAME_TYPE + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | move TMP2, BASE + | addu BASE, BASE, RA + | li AT, LJ_TFUNC + | lw TMP1, -24+HI(BASE) + | lw LFUNC:RB, -24+LO(BASE) + | ldc1 f2, -8(BASE) + | ldc1 f0, -16(BASE) + | sw TMP1, HI(BASE) // Copy callable. + | sw LFUNC:RB, LO(BASE) + | sdc1 f2, 16(BASE) // Copy control var. + | sdc1 f0, 8(BASE) // Copy state. + | addiu BASE, BASE, 8 + | bne TMP1, AT, ->vmeta_call + |. li NARGS8:RC, 16 // Iterators get 2 arguments. + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | addu RA, BASE, RA + | lw TAB:RB, -16+LO(RA) + | lw RC, -8+LO(RA) // Get index from control var. + | lw TMP0, TAB:RB->asize + | lw TMP1, TAB:RB->array + | addiu PC, PC, 4 + |1: // Traverse array part. + | sltu AT, RC, TMP0 + | beqz AT, >5 // Index points after array part? + |. sll TMP3, RC, 3 + | addu TMP3, TMP1, TMP3 + | lw TMP2, HI(TMP3) + | ldc1 f0, 0(TMP3) + | mtc1 RC, f2 + | lhu RD, -4+OFS_RD(PC) + | beq TMP2, TISNIL, <1 // Skip holes in array part. + |. addiu RC, RC, 1 + | cvt.d.w f2, f2 + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sdc1 f0, 8(RA) + | decode_RD4b RD + | addu RD, RD, TMP3 + | sw RC, -8+LO(RA) // Update control var. + | addu PC, PC, RD + | sdc1 f2, 0(RA) + |3: + | ins_next + | + |5: // Traverse hash part. + | lw TMP1, TAB:RB->hmask + | subu RC, RC, TMP0 + | lw TMP2, TAB:RB->node + |6: + | sltu AT, TMP1, RC // End of iteration? Branch to ITERL+1. + | bnez AT, <3 + |. sll TMP3, RC, 5 + | sll RB, RC, 3 + | subu TMP3, TMP3, RB + | addu NODE:TMP3, TMP3, TMP2 + | lw RB, HI(NODE:TMP3) + | ldc1 f0, 0(NODE:TMP3) + | lhu RD, -4+OFS_RD(PC) + | beq RB, TISNIL, <6 // Skip holes in hash part. + |. addiu RC, RC, 1 + | ldc1 f2, NODE:TMP3->key + | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535) + | sdc1 f0, 8(RA) + | addu RC, RC, TMP0 + | decode_RD4b RD + | addu RD, RD, TMP3 + | sdc1 f2, 0(RA) + | addu PC, PC, RD + | b <3 + |. sw RC, -8+LO(RA) // Update control var. + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | addu RA, BASE, RA + | lw TMP0, -24+HI(RA) + | lw CFUNC:TMP1, -24+LO(RA) + | lw TMP2, -16+HI(RA) + | lw TMP3, -8+HI(RA) + | li AT, LJ_TFUNC + | bne TMP0, AT, >5 + |. addiu TMP2, TMP2, -LJ_TTAB + | lbu TMP1, CFUNC:TMP1->ffid + | addiu TMP3, TMP3, -LJ_TNIL + | srl TMP0, RD, 1 + | or TMP2, TMP2, TMP3 + | addiu TMP1, TMP1, -FF_next_N + | addu TMP0, PC, TMP0 + | or TMP1, TMP1, TMP2 + | bnez TMP1, >5 + |. lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535) + | addu PC, TMP0, TMP2 + | lui TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | sw r0, -8+LO(RA) // Initialize control var. + | sw TMP1, -8+HI(RA) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP3, BC_JMP + | li TMP1, BC_ITERC + | sb TMP3, -4+OFS_OP(PC) + | addu PC, TMP0, TMP2 + | b <1 + |. sb TMP1, OFS_OP(PC) + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lw TMP0, FRAME_PC(BASE) + | decode_RDtoRC8 RC, RD + | decode_RB8a RB, INS + | addu RC, BASE, RC + | decode_RB8b RB + | addu RA, BASE, RA + | addiu RC, RC, FRAME_VARG + | addu TMP2, RA, RB + | addiu TMP3, BASE, -8 // TMP3 = vtop + | subu RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | beqz RB, >5 // Copy all varargs? + |. subu TMP1, TMP3, RC + | addiu TMP2, TMP2, -16 + |1: // Copy vararg slots to destination slots. + | lw CARG1, HI(RC) + | sltu AT, RC, TMP3 + | lw CARG2, LO(RC) + | addiu RC, RC, 8 + | movz CARG1, TISNIL, AT + | sw CARG1, HI(RA) + | sw CARG2, LO(RA) + | sltu AT, RA, TMP2 + | bnez AT, <1 + |. addiu RA, RA, 8 + |3: + | ins_next + | + |5: // Copy all varargs. + | lw TMP0, L->maxstack + | blez TMP1, <3 // No vararg slots? + |. li MULTRES, 8 // MULTRES = (0+1)*8 + | addu TMP2, RA, TMP1 + | sltu AT, TMP0, TMP2 + | bnez AT, >7 + |. addiu MULTRES, TMP1, 8 + |6: + | ldc1 f0, 0(RC) + | addiu RC, RC, 8 + | sdc1 f0, 0(RA) + | sltu AT, RC, TMP3 + | bnez AT, <6 // More vararg slots? + |. addiu RA, RA, 8 + | b <3 + |. nop + | + |7: // Grow stack for varargs. + | load_got lj_state_growstack + | sw RA, L->top + | subu RA, RA, BASE + | sw BASE, L->base + | subu BASE, RC, BASE // Need delta, because BASE may change. + | sw PC, SAVE_PC + | srl CARG2, TMP1, 3 + | call_intern lj_state_growstack // (lua_State *L, int n) + |. move CARG1, L + | move RC, BASE + | lw BASE, L->base + | addu RA, BASE, RA + | addu RC, BASE, RC + | b <6 + |. addiu TMP3, BASE, -8 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | addu RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lw PC, FRAME_PC(BASE) + | addu RA, BASE, RA + | move MULTRES, RD + |1: + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->BC_RETV_Z + |. xori TMP1, PC, FRAME_VARG + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lw INS, -4(PC) + | addiu TMP2, BASE, -8 + | addiu RC, RD, -8 + | decode_RA8a TMP0, INS + | decode_RB8a RB, INS + | decode_RA8b TMP0 + | decode_RB8b RB + | addu TMP3, TMP2, RB + | beqz RC, >3 + |. subu BASE, TMP2, TMP0 + |2: + | ldc1 f0, 0(RA) + | addiu RA, RA, 8 + | addiu RC, RC, -8 + | sdc1 f0, 0(TMP2) + | bnez RC, <2 + |. addiu TMP2, TMP2, 8 + |3: + | addiu TMP3, TMP3, -8 + |5: + | sltu AT, TMP2, TMP3 + | bnez AT, >6 + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lw TMP1, LFUNC:TMP1->pc + | lw KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | sw TISNIL, HI(TMP2) + | b <5 + |. addiu TMP2, TMP2, 8 + | + |->BC_RETV_Z: // Non-standard return case. + | andi TMP2, TMP1, FRAME_TYPEP + | bnez TMP2, ->vm_return + |. nop + | // Return from vararg function: relocate BASE down. + | subu BASE, BASE, TMP1 + | b <1 + |. lw PC, FRAME_PC(BASE) + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lw PC, FRAME_PC(BASE) + | addu RA, BASE, RA + | move MULTRES, RD + | andi TMP0, PC, FRAME_TYPE + | bnez TMP0, ->BC_RETV_Z + |. xori TMP1, PC, FRAME_VARG + | + | lw INS, -4(PC) + | addiu TMP2, BASE, -8 + if (op == BC_RET1) { + | ldc1 f0, 0(RA) + } + | decode_RB8a RB, INS + | decode_RA8a RA, INS + | decode_RB8b RB + | decode_RA8b RA + if (op == BC_RET1) { + | sdc1 f0, 0(TMP2) + } + | subu BASE, TMP2, RA + |5: + | sltu AT, RD, RB + | bnez AT, >6 + |. lw LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lw TMP1, LFUNC:TMP1->pc + | lw KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | addiu TMP2, TMP2, 8 + | addiu RD, RD, 8 + | b <5 + if (op == BC_RET1) { + |. sw TISNIL, HI(TMP2) + } else { + |. sw TISNIL, -8+HI(TMP2) + } + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | addu RA, BASE, RA + if (vk) { + | ldc1 f0, FORL_IDX*8(RA) + | ldc1 f4, FORL_STEP*8(RA) + | ldc1 f2, FORL_STOP*8(RA) + | lw TMP3, FORL_STEP*8+HI(RA) + | add.d f0, f0, f4 + | sdc1 f0, FORL_IDX*8(RA) + } else { + | lw TMP1, FORL_IDX*8+HI(RA) + | lw TMP3, FORL_STEP*8+HI(RA) + | lw TMP2, FORL_STOP*8+HI(RA) + | sltiu TMP1, TMP1, LJ_TISNUM + | sltiu TMP0, TMP3, LJ_TISNUM + | sltiu TMP2, TMP2, LJ_TISNUM + | and TMP1, TMP1, TMP0 + | and TMP1, TMP1, TMP2 + | ldc1 f0, FORL_IDX*8(RA) + | beqz TMP1, ->vmeta_for + |. ldc1 f2, FORL_STOP*8(RA) + } + if (op != BC_JFORL) { + | srl RD, RD, 1 + | lui TMP0, (-(BCBIAS_J*4 >> 16) & 65535) + } + | c.le.d 0, f0, f2 + | c.le.d 1, f2, f0 + | sdc1 f0, FORL_EXT*8(RA) + if (op == BC_JFORI) { + | li TMP1, 1 + | li TMP2, 1 + | addu TMP0, RD, TMP0 + | slt TMP3, TMP3, r0 + | movf TMP1, r0, 0 + | addu PC, PC, TMP0 + | movf TMP2, r0, 1 + | lhu RD, -4+OFS_RD(PC) + | movn TMP1, TMP2, TMP3 + | bnez TMP1, =>BC_JLOOP + |. decode_RD8b RD + } else if (op == BC_JFORL) { + | li TMP1, 1 + | li TMP2, 1 + | slt TMP3, TMP3, r0 + | movf TMP1, r0, 0 + | movf TMP2, r0, 1 + | movn TMP1, TMP2, TMP3 + | bnez TMP1, =>BC_JLOOP + |. nop + } else { + | addu TMP1, RD, TMP0 + | slt TMP3, TMP3, r0 + | move TMP2, TMP1 + if (op == BC_FORI) { + | movt TMP1, r0, 0 + | movt TMP2, r0, 1 + } else { + | movf TMP1, r0, 0 + | movf TMP2, r0, 1 + } + | movn TMP1, TMP2, TMP3 + | addu PC, PC, TMP1 + } + | ins_next + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | addu RA, BASE, RA + | lw TMP1, HI(RA) + | beq TMP1, TISNIL, >1 // Stop if iterator returned nil. + |. lw TMP2, LO(RA) + if (op == BC_JITERL) { + | sw TMP1, -8+HI(RA) + | b =>BC_JLOOP + |. sw TMP2, -8+LO(RA) + } else { + | branch_RD // Otherwise save control var + branch. + | sw TMP1, -8+HI(RA) + | sw TMP2, -8+LO(RA) + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base*8 (ignored), RD = traceno*8 + | lw TMP1, DISPATCH_J(trace)(DISPATCH) + | srl RD, RD, 1 + | li AT, 0 + | addu TMP1, TMP1, RD + | // Traces on MIPS don't store the trace number, so use 0. + | sw AT, DISPATCH_GL(vmstate)(DISPATCH) + | lw TRACE:TMP2, 0(TMP1) + | sw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | sw L, DISPATCH_GL(jit_L)(DISPATCH) + | lw TMP2, TRACE:TMP2->mcode + | jr TMP2 + |. addiu JGL, DISPATCH, GG_DISP2G+32768 + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lw TMP2, L->maxstack + | lbu TMP1, -4+PC2PROTO(numparams)(PC) + | lw KBASE, -4+PC2PROTO(k)(PC) + | sltu AT, TMP2, RA + | bnez AT, ->vm_growstack_l + |. sll TMP1, TMP1, 3 + if (op != BC_JFUNCF) { + | ins_next1 + } + |2: + | sltu AT, NARGS8:RC, TMP1 // Check for missing parameters. + | bnez AT, >3 + |. addu AT, BASE, NARGS8:RC + if (op == BC_JFUNCF) { + | decode_RD8a RD, INS + | b =>BC_JLOOP + |. decode_RD8b RD + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | sw TISNIL, HI(AT) + | b <2 + |. addiu NARGS8:RC, NARGS8:RC, 8 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | addu TMP1, BASE, RC + | lw TMP2, L->maxstack + | addu TMP0, RA, RC + | sw LFUNC:RB, LO(TMP1) // Store copy of LFUNC. + | addiu TMP3, RC, 8+FRAME_VARG + | sltu AT, TMP0, TMP2 + | lw KBASE, -4+PC2PROTO(k)(PC) + | beqz AT, ->vm_growstack_l + |. sw TMP3, HI(TMP1) // Store delta + FRAME_VARG. + | lbu TMP2, -4+PC2PROTO(numparams)(PC) + | move RA, BASE + | move RC, TMP1 + | ins_next1 + | beqz TMP2, >3 + |. addiu BASE, TMP1, 8 + |1: + | lw TMP0, HI(RA) + | lw TMP3, LO(RA) + | sltu AT, RA, RC // Less args than parameters? + | move CARG1, TMP0 + | movz TMP0, TISNIL, AT // Clear missing parameters. + | movn CARG1, TISNIL, AT // Clear old fixarg slot (help the GC). + | sw TMP3, 8+LO(TMP1) + | addiu TMP2, TMP2, -1 + | sw TMP0, 8+HI(TMP1) + | addiu TMP1, TMP1, 8 + | sw CARG1, HI(RA) + | bnez TMP2, <1 + |. addiu RA, RA, 8 + |3: + | ins_next2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lw CFUNCADDR, CFUNC:RB->f + } else { + | lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH) + } + | addu TMP1, RA, NARGS8:RC + | lw TMP2, L->maxstack + | addu RC, BASE, NARGS8:RC + | sw BASE, L->base + | sltu AT, TMP2, TMP1 + | sw RC, L->top + | li_vmstate C + if (op == BC_FUNCCW) { + | lw CARG2, CFUNC:RB->f + } + | bnez AT, ->vm_growstack_c // Need to grow stack. + |. move CARG1, L + | jalr CFUNCADDR // (lua_State *L [, lua_CFunction f]) + |. st_vmstate + | // Returns nresults. + | lw BASE, L->base + | sll RD, CRET1, 3 + | lw TMP1, L->top + | li_vmstate INTERP + | lw PC, FRAME_PC(BASE) // Fetch PC of caller. + | subu RA, TMP1, RD // RA = L->top - nresults*8 + | b ->vm_returnc + |. st_vmstate + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.4byte .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.4byte 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.4byte .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.4byte .Lframe0\n" + "\t.4byte .Lbegin\n" + "\t.4byte %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x9f\n\t.sleb128 1\n" + "\t.byte 0x9e\n\t.sleb128 2\n", + fcofs, CFRAME_SIZE); + for (i = 23; i >= 16; i--) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i); + for (i = 30; i >= 20; i -= 2) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.4byte .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.4byte .Lframe0\n" + "\t.4byte lj_vm_ffi_call\n" + "\t.4byte %d\n" + "\t.byte 0x9f\n\t.uleb128 1\n" + "\t.byte 0x90\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0x10\n" + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif + fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); + fprintf(ctx->fp, + "\t.globl lj_err_unwind_dwarf\n" + ".Lframe1:\n" + "\t.4byte .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.4byte 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0\n" + "\t.4byte lj_err_unwind_dwarf\n" + "\t.byte 0\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.4byte .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.4byte .LASFDE2-.Lframe1\n" + "\t.4byte .Lbegin\n" + "\t.4byte %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x9f\n\t.sleb128 1\n" + "\t.byte 0x9e\n\t.sleb128 2\n", + fcofs, CFRAME_SIZE); + for (i = 23; i >= 16; i--) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i); + for (i = 30; i >= 20; i -= 2) + fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE2:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.4byte .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.4byte 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 31\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0\n" + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.4byte .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.4byte .LASFDE3-.Lframe2\n" + "\t.4byte lj_vm_ffi_call\n" + "\t.4byte %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0x9f\n\t.uleb128 1\n" + "\t.byte 0x90\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0x10\n" + "\t.align 2\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + default: + break; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppc.dasc b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppc.dasc new file mode 100644 index 0000000..da75f55 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppc.dasc @@ -0,0 +1,5137 @@ +|// Low-level VM code for PowerPC CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch ppc +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// DynASM defines used by the PPC port: +|// +|// P64 64 bit pointers (only for GPR64 testing). +|// Note: a full PPC64 _LP64 port is not planned. +|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3). +|// Affects reg saves, stack layout, carry/overflow/dot flags etc. +|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360). +|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3). +|// Function pointers are really a struct: code, TOC, env (optional). +|// TOCENV Function pointers have an environment pointer, too (not on PS3). +|// PPE Power Processor Element of Cell (PS3) or Xenon (Xbox 360). +|// Must avoid (slow) micro-coded instructions. +| +|.if P64 +|.define TOC, 1 +|.define TOCENV, 1 +|.macro lpx, a, b, c; ldx a, b, c; .endmacro +|.macro lp, a, b; ld a, b; .endmacro +|.macro stp, a, b; std a, b; .endmacro +|.define decode_OPP, decode_OP8 +|.if FFI +|// Missing: Calling conventions, 64 bit regs, TOC. +|.error lib_ffi not yet implemented for PPC64 +|.endif +|.else +|.macro lpx, a, b, c; lwzx a, b, c; .endmacro +|.macro lp, a, b; lwz a, b; .endmacro +|.macro stp, a, b; stw a, b; .endmacro +|.define decode_OPP, decode_OP4 +|.endif +| +|// Convenience macros for TOC handling. +|.if TOC +|// Linker needs a TOC patch area for every external call relocation. +|.macro blex, target; bl extern target@plt; nop; .endmacro +|.macro .toc, a, b; a, b; .endmacro +|.if P64 +|.define TOC_OFS, 8 +|.define ENV_OFS, 16 +|.else +|.define TOC_OFS, 4 +|.define ENV_OFS, 8 +|.endif +|.else // No TOC. +|.macro blex, target; bl extern target@plt; .endmacro +|.macro .toc, a, b; .endmacro +|.endif +|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro +| +|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro +| +|.macro andix., y, a, i +|.if PPE +| rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i) +| cmpwi y, 0 +|.else +| andi. y, a, i +|.endif +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA) +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r14 // Base of current Lua stack frame. +|.define KBASE, r15 // Constants of current Lua function. +|.define PC, r16 // Next PC. +|.define DISPATCH, r17 // Opcode dispatch table. +|.define LREG, r18 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. +|.define JGL, r31 // On-trace: global_State + 32768. +| +|// Constants for type-comparisons, stores and conversions. C callee-save. +|.define TISNUM, r22 +|.define TISNIL, r23 +|.define ZERO, r24 +|.define TOBIT, f30 // 2^52 + 2^51. +|.define TONUM, f31 // 2^52 + 2^51 + 2^31. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r20 // Callee-save. +|.define RB, r10 +|.define RC, r11 +|.define RD, r12 +|.define INS, r7 // Overlaps CARG5. +| +|.define TMP0, r0 +|.define TMP1, r8 +|.define TMP2, r9 +|.define TMP3, r6 // Overlaps CARG4. +| +|// Saved temporaries. +|.define SAVE0, r21 +| +|// Calling conventions. +|.define CARG1, r3 +|.define CARG2, r4 +|.define CARG3, r5 +|.define CARG4, r6 // Overlaps TMP3. +|.define CARG5, r7 // Overlaps INS. +| +|.define FARG1, f1 +|.define FARG2, f2 +| +|.define CRET1, r3 +|.define CRET2, r4 +| +|.define TOCREG, r2 // TOC register (only used by C code). +|.define ENVREG, r11 // Environment pointer (nested C functions). +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.if GPR64 +|.if FRAME32 +| +|// 456(sp) // \ 32/64 bit C frame info +|.define TONUM_LO, 452(sp) // | +|.define TONUM_HI, 448(sp) // | +|.define TMPD_LO, 444(sp) // | +|.define TMPD_HI, 440(sp) // | +|.define SAVE_CR, 432(sp) // | 64 bit CR save. +|.define SAVE_ERRF, 424(sp) // > Parameter save area. +|.define SAVE_NRES, 420(sp) // | +|.define SAVE_L, 416(sp) // | +|.define SAVE_PC, 412(sp) // | +|.define SAVE_MULTRES, 408(sp) // | +|.define SAVE_CFRAME, 400(sp) // / 64 bit C frame chain. +|// 392(sp) // Reserved. +|.define CFRAME_SPACE, 384 // Delta for sp. +|// Back chain for sp: 384(sp) <-- sp entering interpreter +|.define SAVE_LR, 376(sp) // 32 bit LR stored in hi-part. +|.define SAVE_GPR_, 232 // .. 232+18*8: 64 bit GPR saves. +|.define SAVE_FPR_, 88 // .. 88+18*8: 64 bit FPR saves. +|// 80(sp) // Needed for 16 byte stack frame alignment. +|// 16(sp) // Callee parameter save area (ABI mandated). +|// 8(sp) // Reserved +|// Back chain for sp: 0(sp) <-- sp while in interpreter +|// 32 bit sp stored in hi-part of 0(sp). +| +|.define TMPD_BLO, 447(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.else +| +|// 508(sp) // \ 32 bit C frame info. +|.define SAVE_ERRF, 472(sp) // | +|.define SAVE_NRES, 468(sp) // | +|.define SAVE_L, 464(sp) // > Parameter save area. +|.define SAVE_PC, 460(sp) // | +|.define SAVE_MULTRES, 456(sp) // | +|.define SAVE_CFRAME, 448(sp) // / 64 bit C frame chain. +|.define SAVE_LR, 416(sp) +|.define CFRAME_SPACE, 400 // Delta for sp. +|// Back chain for sp: 400(sp) <-- sp entering interpreter +|.define SAVE_FPR_, 256 // .. 256+18*8: 64 bit FPR saves. +|.define SAVE_GPR_, 112 // .. 112+18*8: 64 bit GPR saves. +|// 48(sp) // Callee parameter save area (ABI mandated). +|.define SAVE_TOC, 40(sp) // TOC save area. +|.define TMPD_LO, 36(sp) // \ Link editor temp (ABI mandated). +|.define TMPD_HI, 32(sp) // / +|.define TONUM_LO, 28(sp) // \ Compiler temp (ABI mandated). +|.define TONUM_HI, 24(sp) // / +|// Next frame lr: 16(sp) +|.define SAVE_CR, 8(sp) // 64 bit CR save. +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.define TMPD_BLO, 39(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.endif +|.else +| +|.define SAVE_LR, 276(sp) +|.define CFRAME_SPACE, 272 // Delta for sp. +|// Back chain for sp: 272(sp) <-- sp entering interpreter +|.define SAVE_FPR_, 128 // .. 128+18*8: 64 bit FPR saves. +|.define SAVE_GPR_, 56 // .. 56+18*4: 32 bit GPR saves. +|.define SAVE_CR, 52(sp) // 32 bit CR save. +|.define SAVE_ERRF, 48(sp) // 32 bit C frame info. +|.define SAVE_NRES, 44(sp) +|.define SAVE_CFRAME, 40(sp) +|.define SAVE_L, 36(sp) +|.define SAVE_PC, 32(sp) +|.define SAVE_MULTRES, 28(sp) +|.define UNUSED1, 24(sp) +|.define TMPD_LO, 20(sp) +|.define TMPD_HI, 16(sp) +|.define TONUM_LO, 12(sp) +|.define TONUM_HI, 8(sp) +|// Next frame lr: 4(sp) +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.define TMPD_BLO, 23(sp) +|.define TMPD, TMPD_HI +|.define TONUM_D, TONUM_HI +| +|.endif +| +|.macro save_, reg +|.if GPR64 +| std r..reg, SAVE_GPR_+(reg-14)*8(sp) +|.else +| stw r..reg, SAVE_GPR_+(reg-14)*4(sp) +|.endif +| stfd f..reg, SAVE_FPR_+(reg-14)*8(sp) +|.endmacro +|.macro rest_, reg +|.if GPR64 +| ld r..reg, SAVE_GPR_+(reg-14)*8(sp) +|.else +| lwz r..reg, SAVE_GPR_+(reg-14)*4(sp) +|.endif +| lfd f..reg, SAVE_FPR_+(reg-14)*8(sp) +|.endmacro +| +|.macro saveregs +|.if GPR64 and not FRAME32 +| stdu sp, -CFRAME_SPACE(sp) +|.else +| stwu sp, -CFRAME_SPACE(sp) +|.endif +| save_ 14; save_ 15; save_ 16 +| mflr r0 +| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22 +|.if GPR64 and not FRAME32 +| std r0, SAVE_LR +|.else +| stw r0, SAVE_LR +|.endif +| save_ 23; save_ 24; save_ 25 +| mfcr r0 +| save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31 +|.if GPR64 +| std r0, SAVE_CR +|.else +| stw r0, SAVE_CR +|.endif +| .toc std TOCREG, SAVE_TOC +|.endmacro +| +|.macro restoreregs +|.if GPR64 and not FRAME32 +| ld r0, SAVE_LR +|.else +| lwz r0, SAVE_LR +|.endif +|.if GPR64 +| ld r12, SAVE_CR +|.else +| lwz r12, SAVE_CR +|.endif +| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19 +| mtlr r0; +|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif +| rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25 +|.if PPE; mtocrf 0x10, r12; .endif +| rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31 +|.if PPE; mtocrf 0x08, r12; .endif +| addi sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// These basic macros should really be part of DynASM. +|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro +|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro +|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro +|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro +|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro +| +|// Trap for not-yet-implemented parts. +|.macro NYI; tw 4, sp, sp; .endmacro +| +|// int/FP conversions. +|.macro tonum_i, freg, reg +| xoris reg, reg, 0x8000 +| stw reg, TONUM_LO +| lfd freg, TONUM_D +| fsub freg, freg, TONUM +|.endmacro +| +|.macro tonum_u, freg, reg +| stw reg, TONUM_LO +| lfd freg, TONUM_D +| fsub freg, freg, TOBIT +|.endmacro +| +|.macro toint, reg, freg, tmpfreg +| fctiwz tmpfreg, freg +| stfd tmpfreg, TMPD +| lwz reg, TMPD_LO +|.endmacro +| +|.macro toint, reg, freg +| toint reg, freg, freg +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_PC, -8 +|.define FRAME_FUNC, -4 +| +|// Instruction decode. +|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro +|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro +|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro +|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro +|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro +|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro +| +|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro +|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lwz INS, 0(PC) +| addi PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. Note: optimized for e300! +|.macro ins_NEXT2 +| decode_OPP TMP1, INS +| lpx TMP0, DISPATCH, TMP1 +| mtctr TMP0 +| decode_RB8 RB, INS +| decode_RD8 RD, INS +| decode_RA8 RA, INS +| decode_RC8 RC, INS +| bctr +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lwz PC, LFUNC:RB->pc +| lwz INS, 0(PC) +| addi PC, PC, 4 +| decode_OPP TMP1, INS +| decode_RA8 RA, INS +| lpx TMP0, DISPATCH, TMP1 +| add RA, RA, BASE +| mtctr TMP0 +| bctr +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| stw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checknum, reg; cmplw reg, TISNUM; .endmacro +|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro +|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro +|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro +|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro +|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro +| +|.macro branch_RD +| srwi TMP0, RD, 1 +| addis PC, PC, -(BCBIAS_J*4 >> 16) +| add PC, PC, TMP0 +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotcheck, delta, target +| rlwinm TMP1, PC, 31, 25, 30 +| addi TMP1, TMP1, GG_DISP2HOT +| lhzx TMP2, DISPATCH, TMP1 +| addic. TMP2, TMP2, -delta +| sthx TMP2, DISPATCH, TMP1 +| blt target +|.endmacro +| +|.macro hotloop +| hotcheck HOTCOUNT_LOOP, ->vm_hotloop +|.endmacro +| +|.macro hotcall +| hotcheck HOTCOUNT_CALL, ->vm_hotcall +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| // Assumes LJ_GC_BLACK is 0x04. +| rlwinm mark, mark, 0, 30, 28 // black2gray(tab) +| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| stb mark, tab->marked +| stw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andix. TMP0, PC, FRAME_P + | li TMP1, LJ_TTRUE + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | mr BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | stwu TMP1, FRAME_PC(RA) // Prepend true to results. + | + |->vm_returnc: + | addi RD, RD, 8 // RD = (nresults+1)*8. + | andix. TMP0, PC, FRAME_TYPE + | cmpwi cr1, RD, 0 + | li CRET1, LUA_YIELD + | beq cr1, ->vm_unwind_c_eh + | mr MULTRES, RD + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | cmpwi TMP0, FRAME_C + | rlwinm TMP2, PC, 0, 0, 28 + | li_vmstate C + | sub TMP2, BASE, TMP2 // TMP2 = previous base. + | bney ->vm_returnp + | + | addic. TMP1, RD, -8 + | stp TMP2, L->base + | lwz TMP2, SAVE_NRES + | subi BASE, BASE, 8 + | st_vmstate + | slwi TMP2, TMP2, 3 + | beq >2 + |1: + | addic. TMP1, TMP1, -8 + | lfd f0, 0(RA) + | addi RA, RA, 8 + | stfd f0, 0(BASE) + | addi BASE, BASE, 8 + | bney <1 + | + |2: + | cmpw TMP2, RD // More/less results wanted? + | bne >6 + |3: + | stp BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lp TMP0, SAVE_CFRAME // Restore previous C frame. + | li CRET1, 0 // Ok return status for vm_pcall. + | stp TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs + | blr + | + |6: + | ble >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | lwz TMP1, L->maxstack + | cmplw BASE, TMP1 + | bge >8 + | stw TISNIL, 0(BASE) + | addi RD, RD, 8 + | addi BASE, BASE, 8 + | b <2 + | + |7: // Less results wanted. + | subfic TMP3, TMP2, 0 // LUA_MULTRET+1 case? + | sub TMP0, RD, TMP2 + | subfe TMP1, TMP1, TMP1 // TMP1 = TMP2 == 0 ? 0 : -1 + | and TMP0, TMP0, TMP1 + | sub BASE, BASE, TMP0 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | stp BASE, L->top // Save current top held in BASE (yes). + | mr SAVE0, RD + | mr CARG2, TMP2 + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz TMP2, SAVE_NRES + | mr RD, SAVE0 + | slwi TMP2, TMP2, 3 + | lp BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mr sp, CARG1 + | mr CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | .toc ld TOCREG, SAVE_TOC + | li TMP0, ~LJ_VMST_C + | lwz GL:TMP1, L->glref + | stw TMP0, GL:TMP1->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + |.if GPR64 + | rldicr sp, CARG1, 0, 61 + |.else + | rlwinm sp, CARG1, 0, 0, 29 + |.endif + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | .toc ld TOCREG, SAVE_TOC + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp BASE, L->base + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li ZERO, 0 + | stw TMP3, TMPD + | li TMP1, LJ_TFALSE + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | li TISNIL, LJ_TNIL + | li_vmstate INTERP + | lfs TOBIT, TMPD + | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | la RA, -8(BASE) // Results start at BASE-8. + | stw TMP3, TMPD + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw TMP1, 0(RA) // Prepend false to error message. + | li RD, 16 // 2 results: false + error message. + | st_vmstate + | lfs TONUM, TMPD + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | li CARG2, LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | stp BASE, L->base + | addi PC, PC, 4 // Must point after first instruction. + | stp RC, L->top + | srwi CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | stw PC, SAVE_PC + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | lp RC, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mr L, CARG1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | mr BASE, CARG2 + | lbz TMP1, L->status + | stw L, SAVE_L + | li PC, FRAME_CP + | addi TMP0, sp, CFRAME_RESUME + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw CARG3, SAVE_NRES + | cmplwi TMP1, 0 + | stw CARG3, SAVE_ERRF + | stp TMP0, L->cframe + | stp CARG3, SAVE_CFRAME + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mr RA, BASE + | lp BASE, L->base + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp TMP1, L->top + | lwz PC, FRAME_PC(BASE) + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | stb CARG3, L->status + | stw TMP3, TMPD + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | sub RD, TMP1, BASE + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | addi RD, RD, 8 + | stw TMP0, TONUM_HI + | li_vmstate INTERP + | li ZERO, 0 + | st_vmstate + | andix. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | lfs TONUM, TMPD + | li TISNIL, LJ_TNIL + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | li PC, FRAME_CP + | stw CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lp TMP1, L:CARG1->cframe + | stw CARG3, SAVE_NRES + | mr L, CARG1 + | stw CARG1, SAVE_L + | mr BASE, CARG2 + | stp sp, L->cframe // Add our C frame to cframe chain. + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | stp TMP1, SAVE_CFRAME + | addi DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lp TMP2, L->base // TMP2 = old base (used in vmeta_call). + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp TMP1, L->top + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | add PC, PC, BASE + | stw TMP3, TMPD + | li ZERO, 0 + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | sub PC, PC, TMP2 // PC = frame delta + frame type + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | sub NARGS8:RC, TMP1, BASE + | stw TMP0, TONUM_HI + | li_vmstate INTERP + | lfs TONUM, TMPD + | li TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | lwz TMP0, FRAME_PC(BASE) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | checkfunc TMP0; bne ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mr L, CARG1 + | lwz TMP0, L:CARG1->stack + | stw CARG1, SAVE_L + | lp TMP1, L->top + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lp TMP1, L->cframe + | stp sp, L->cframe // Add our C frame to cframe chain. + | .toc lp CARG4, 0(CARG4) + | li TMP2, 0 + | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | stw TMP2, SAVE_ERRF // No error function. + | stp TMP1, SAVE_CFRAME + | mtctr CARG4 + | bctrl // (lua_State *L, lua_CFunction func, void *ud) + |.if PPE + | mr BASE, CRET1 + | cmpwi CRET1, 0 + |.else + | mr. BASE, CRET1 + |.endif + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | addi DISPATCH, DISPATCH, GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lwz TMP0, -12(BASE) // Continuation. + | mr RB, BASE + | mr BASE, TMP2 // Restore caller BASE. + | lwz LFUNC:TMP1, FRAME_FUNC(TMP2) + |.if FFI + | cmplwi TMP0, 1 + |.endif + | lwz PC, -16(RB) // Restore PC from [cont|PC]. + | subi TMP2, RD, 8 + | lwz TMP1, LFUNC:TMP1->pc + | stwx TISNIL, RA, TMP2 // Ensure one valid arg. + |.if FFI + | ble >1 + |.endif + | lwz KBASE, PC2PROTO(k)(TMP1) + | // BASE = base, RA = resultptr, RB = meta base + | mtctr TMP0 + | bctr // Jump to continuation. + | + |.if FFI + |1: + | beq ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: tailcall from C function. + | subi TMP1, RB, 16 + | sub RC, TMP1, BASE + | b ->vm_call_tail + |.endif + | + |->cont_cat: // RA = resultptr, RB = meta base + | lwz INS, -4(PC) + | subi CARG2, RB, 16 + | decode_RB8 SAVE0, INS + | lfd f0, 0(RA) + | add TMP1, BASE, SAVE0 + | stp BASE, L->base + | cmplw TMP1, CARG2 + | sub CARG3, CARG2, TMP1 + | decode_RA8 RA, INS + | stfd f0, 0(CARG2) + | bney ->BC_CAT_Z + | stfdx f0, BASE, RA + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TSTR + | decode_RB8 RB, INS + | stw STR:RC, 4(CARG3) + | add CARG2, BASE, RB + | stw TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tgets: + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TTAB + | stw TAB:RB, 4(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | stw TMP0, 0(CARG2) + | li TMP1, LJ_TSTR + | stw STR:RC, 4(CARG3) + | stw TMP1, 0(CARG3) + | b >1 + | + |->vmeta_tgetb: // TMP0 = index + |.if not DUALNUM + | tonum_u f0, TMP0 + |.endif + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + |.if DUALNUM + | stw TISNUM, 0(CARG3) + | stw TMP0, 4(CARG3) + |.else + | stfd f0, 0(CARG3) + |.endif + | b >1 + | + |->vmeta_tgetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | beq >3 + | lfd f0, 0(CRET1) + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | subfic TMP1, BASE, FRAME_CONT + | lp BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 16 // 2 args for func(t, k). + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TSTR + | decode_RB8 RB, INS + | stw STR:RC, 4(CARG3) + | add CARG2, BASE, RB + | stw TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tsets: + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | li TMP0, LJ_TTAB + | stw TAB:RB, 4(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | stw TMP0, 0(CARG2) + | li TMP1, LJ_TSTR + | stw STR:RC, 4(CARG3) + | stw TMP1, 0(CARG3) + | b >1 + | + |->vmeta_tsetb: // TMP0 = index + |.if not DUALNUM + | tonum_u f0, TMP0 + |.endif + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + |.if DUALNUM + | stw TISNUM, 0(CARG3) + | stw TMP0, 4(CARG3) + |.else + | stfd f0, 0(CARG3) + |.endif + | b >1 + | + |->vmeta_tsetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | lfdx f0, BASE, RA + | beq >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | ins_next1 + | stfd f0, 0(CRET1) + | ins_next2 + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | subfic TMP1, BASE, FRAME_CONT + | lp BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 24 // 3 args for func(t, k, v) + | stfd f0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mr CARG1, L + | subi PC, PC, 4 + |.if DUALNUM + | mr CARG2, RA + |.else + | add CARG2, BASE, RA + |.endif + | stw PC, SAVE_PC + |.if DUALNUM + | mr CARG3, RD + |.else + | add CARG3, BASE, RD + |.endif + | stp BASE, L->base + | decode_OP1 CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | cmplwi CRET1, 1 + | bgt ->vmeta_binop + | subfic CRET1, CRET1, 0 + |4: + | lwz INS, 0(PC) + | addi PC, PC, 4 + | decode_RD4 TMP2, INS + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | and TMP2, TMP2, CRET1 + | add PC, PC, TMP2 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lwz INS, -4(PC) + | lfd f0, 0(RA) + | decode_RA8 TMP1, INS + | stfdx f0, BASE, TMP1 + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | lwz TMP0, 0(RA) + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is true. + | subfe CRET1, CRET1, CRET1 + | not CRET1, CRET1 + | b <4 + | + |->cont_condf: // RA = resultptr + | lwz TMP0, 0(RA) + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is false. + | subfe CRET1, CRET1, CRET1 + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | subi PC, PC, 4 + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |->vmeta_equal_cd: + |.if FFI + | mr CARG2, INS + | subi PC, PC, 4 + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_nv: + | add CARG3, KBASE, RC + | add CARG4, BASE, RB + | b >1 + |->vmeta_arith_nv2: + |.if DUALNUM + | mr CARG3, RC + | mr CARG4, RB + | b >1 + |.endif + | + |->vmeta_unm: + | mr CARG3, RD + | mr CARG4, RD + | b >1 + | + |->vmeta_arith_vn: + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_vv: + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |.if DUALNUM + | b >1 + |.endif + |->vmeta_arith_vn2: + |->vmeta_arith_vv2: + |.if DUALNUM + | mr CARG3, RB + | mr CARG4, RC + |.endif + |1: + | add CARG2, BASE, RA + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS. + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub TMP1, CRET1, BASE + | stw PC, -16(CRET1) // [cont|PC] + | mr TMP2, BASE + | addi PC, TMP1, FRAME_CONT + | mr BASE, CRET1 + | li NARGS8:RC, 16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: +#if LJ_52 + | mr SAVE0, CARG1 +#endif + | mr CARG2, RD + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | cmplwi CRET1, 0 + | bne ->vmeta_binop // Binop call for compatibility. + | mr CARG1, SAVE0 + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | mr CARG1, L + | stp TMP2, L->base // This is the callers base! + | subi CARG2, BASE, 8 + | stw PC, SAVE_PC + | add CARG3, BASE, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mr CARG1, L + | stp BASE, L->base + | subi CARG2, RA, 8 + | stw PC, SAVE_PC + | add CARG3, RA, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz TMP1, FRAME_PC(BASE) + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mr CARG1, L + | stp BASE, L->base + | mr CARG2, RA + | stw PC, SAVE_PC + | mr SAVE0, INS + | bl extern lj_meta_for // (lua_State *L, TValue *base) + |.if JIT + | decode_OP1 TMP0, SAVE0 + |.endif + | decode_RA8 RA, SAVE0 + |.if JIT + | cmpwi TMP0, BC_JFORI + |.endif + | decode_RD8 RD, SAVE0 + |.if JIT + | beqy =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz CARG1, 4(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lwz CARG4, 8(BASE) + | lwz CARG1, 4(BASE) + | lwz CARG2, 12(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | lwz CARG4, 8(BASE) + | lfd FARG2, 8(BASE) + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + | checknum CARG4; bge ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1. + |.macro ffgccheck + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | cmplw TMP0, TMP1 + | bgel ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | li TMP1, LJ_TFALSE + | la RA, -8(BASE) + | cmplw cr1, CARG3, TMP1 + | lwz PC, FRAME_PC(BASE) + | bge cr1, ->fff_fallback + | stw CARG3, 0(RA) + | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | stw CARG1, 4(RA) + | beq ->fff_res // Done if exactly 1 argument. + | li TMP1, 8 + | subi RC, RC, 8 + |1: + | cmplw TMP1, RC + | lfdx f0, BASE, TMP1 + | stfdx f0, RA, TMP1 + | addi TMP1, TMP1, 8 + | bney <1 + | b ->fff_res + | + |.ffunc type + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | blt ->fff_fallback + | .gpr64 extsw CARG1, CARG1 + | subfc TMP0, TISNUM, CARG1 + | subfe TMP2, CARG1, CARG1 + | orc TMP1, TMP2, TMP0 + | addi TMP1, TMP1, ~LJ_TISNUM+1 + | slwi TMP1, TMP1, 3 + | la TMP2, CFUNC:RB->upvalue + | lfdx FARG1, TMP2, TMP1 + | b ->fff_resn + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktab CARG3; bne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:CARG1, TAB:CARG1->metatable + |2: + | li CARG3, LJ_TNIL + | cmplwi TAB:CARG1, 0 + | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beq ->fff_restv + | lwz TMP0, TAB:CARG1->hmask + | li CARG3, LJ_TTAB // Use metatable as default result. + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:CARG1->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |3: // Rearranged logic, because we expect _not_ to find the key. + | lwz CARG4, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2) + | checkstr CARG4; bne >4 + | cmpw TMP0, STR:RC; beq >5 + |4: + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | beq ->fff_restv // Not found, keep default result. + | b <3 + |5: + | checknil CARG2 + | beq ->fff_restv // Ditto for nil value. + | mr CARG3, CARG2 // Return value of mt.__metatable. + | mr CARG1, TMP1 + | b ->fff_restv + | + |6: + | cmpwi CARG3, LJ_TUDATA; beq <1 + | .gpr64 extsw CARG3, CARG3 + | subfc TMP0, TISNUM, CARG3 + | subfe TMP2, CARG3, CARG3 + | orc TMP1, TMP2, TMP0 + | addi TMP1, TMP1, ~LJ_TISNUM+1 + | slwi TMP1, TMP1, 2 + | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH) + | lwzx TAB:CARG1, TMP2, TMP1 + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | checktab CARG3; bne ->fff_fallback + | lwz TAB:TMP1, TAB:CARG1->metatable + | checktab CARG4; bne ->fff_fallback + | cmplwi TAB:TMP1, 0 + | lbz TMP3, TAB:CARG1->marked + | bne ->fff_fallback + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stw TAB:CARG2, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, TMP3, TMP0 + | b ->fff_restv + | + |.ffunc rawget + | cmplwi NARGS8:RC, 16 + | lwz CARG4, 0(BASE) + | lwz TAB:CARG2, 4(BASE) + | blt ->fff_fallback + | checktab CARG4; bne ->fff_fallback + | la CARG3, 8(BASE) + | mr CARG1, L + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | lfd FARG1, 0(CRET1) + | b ->fff_resn + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Exactly one argument. + | checknum CARG1; bgt ->fff_fallback + | b ->fff_resn + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checkstr CARG3 + | // A __tostring method in the string base metatable is ignored. + | beq ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | checknum CARG3 + | cmplwi cr1, TMP0, 0 + | stp BASE, L->base // Add frame since C call can throw. + | crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq + | stw PC, SAVE_PC // Redundant (but a defined value). + | beq ->fff_fallback + | ffgccheck + | mr CARG1, L + | mr CARG2, BASE + |.if DUALNUM + | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) + |.else + | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) + |.endif + | // Returns GCstr *. + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | lwz TAB:CARG2, 4(BASE) + | blt ->fff_fallback + | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + | checktab CARG1 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback + | stp BASE, L->base // Add frame since C call can throw. + | mr CARG1, L + | stp BASE, L->top // Dummy frame length is ok. + | la CARG3, 8(BASE) + | stw PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | cmplwi CRET1, 0 + | li CARG3, LJ_TNIL + | beq ->fff_restv // End of traversal: return nil. + | lfd f0, 8(BASE) // Copy key and value to results. + | la RA, -8(BASE) + | lfd f1, 16(BASE) + | stfd f0, 0(RA) + | li RD, (2+1)*8 + | stfd f1, 8(RA) + | b ->fff_res + | + |.ffunc_1 pairs + | checktab CARG3 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | lfd f0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | lfd f0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | stw TISNIL, 8(BASE) + | li RD, (3+1)*8 + | stfd f0, 0(RA) + | b ->fff_res + | + |.ffunc ipairs_aux + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lwz TAB:CARG1, 4(BASE) + | lwz CARG4, 8(BASE) + |.if DUALNUM + | lwz TMP2, 12(BASE) + |.else + | lfd FARG2, 8(BASE) + |.endif + | blt ->fff_fallback + | checktab CARG3 + | checknum cr1, CARG4 + | lwz PC, FRAME_PC(BASE) + |.if DUALNUM + | bne ->fff_fallback + | bne cr1, ->fff_fallback + |.else + | lus TMP0, 0x3ff0 + | stw ZERO, TMPD_LO + | bne ->fff_fallback + | stw TMP0, TMPD_HI + | bge cr1, ->fff_fallback + | lfd FARG1, TMPD + | toint TMP2, FARG2, f0 + |.endif + | lwz TMP0, TAB:CARG1->asize + | lwz TMP1, TAB:CARG1->array + |.if not DUALNUM + | fadd FARG2, FARG2, FARG1 + |.endif + | addi TMP2, TMP2, 1 + | la RA, -8(BASE) + | cmplw TMP0, TMP2 + |.if DUALNUM + | stw TISNUM, 0(RA) + | slwi TMP3, TMP2, 3 + | stw TMP2, 4(RA) + |.else + | slwi TMP3, TMP2, 3 + | stfd FARG2, 0(RA) + |.endif + | ble >2 // Not in array part? + | lwzx TMP2, TMP1, TMP3 + | lfdx f0, TMP1, TMP3 + |1: + | checknil TMP2 + | li RD, (0+1)*8 + | beq ->fff_res // End of iteration, return 0 results. + | li RD, (2+1)*8 + | stfd f0, 8(RA) + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | lwz TMP0, TAB:CARG1->hmask + | cmplwi TMP0, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | mr CARG2, TMP2 + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | cmplwi CRET1, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | lwz TMP2, 0(CRET1) + | lfd f0, 0(CRET1) + | b <1 + | + |.ffunc_1 ipairs + | checktab CARG3 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | lfd f0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | lfd f0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + |.if DUALNUM + | stw TISNUM, 8(BASE) + |.else + | stw ZERO, 8(BASE) + |.endif + | stw ZERO, 12(BASE) + | li RD, (3+1)*8 + | stfd f0, 0(RA) + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | cmplwi NARGS8:RC, 8 + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | blt ->fff_fallback + | mr TMP2, BASE + | la BASE, 8(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | subi NARGS8:RC, NARGS8:RC, 8 + | addi PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + | + |.ffunc xpcall + | cmplwi NARGS8:RC, 16 + | lwz CARG4, 8(BASE) + | lfd FARG2, 8(BASE) + | lfd FARG1, 0(BASE) + | blt ->fff_fallback + | lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH) + | mr TMP2, BASE + | checkfunc CARG4; bne ->fff_fallback // Traceback must be a function. + | la BASE, 16(BASE) + | // Remember active hook before pcall. + | rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | stfd FARG2, 0(TMP2) // Swap function and traceback. + | subi NARGS8:RC, NARGS8:RC, 16 + | stfd FARG1, 8(TMP2) + | addi PC, TMP1, 16+FRAME_PCALL + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback + |.else + |.ffunc coroutine_wrap_aux + | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + | lbz TMP0, L:CARG1->status + | lp TMP1, L:CARG1->cframe + | lp CARG2, L:CARG1->top + | cmplwi cr0, TMP0, LUA_YIELD + | lp TMP2, L:CARG1->base + | cmplwi cr1, TMP1, 0 + | lwz TMP0, L:CARG1->maxstack + | cmplw cr7, CARG2, TMP2 + | lwz PC, FRAME_PC(BASE) + | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0 + | add TMP2, CARG2, NARGS8:RC + | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD + | cmplw cr1, TMP2, TMP0 + | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt + | stw PC, SAVE_PC + | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov + | stp BASE, L->base + | blt cr6, ->fff_fallback + |1: + |.if resume + | addi BASE, BASE, 8 // Keep resumed thread in stack for GC. + | subi NARGS8:RC, NARGS8:RC, 8 + | subi TMP2, TMP2, 8 + |.endif + | stp TMP2, L:CARG1->top + | li TMP1, 0 + | stp BASE, L->top + |2: // Move args to coroutine. + | cmpw TMP1, NARGS8:RC + | lfdx f0, BASE, TMP1 + | beq >3 + | stfdx f0, CARG2, TMP1 + | addi TMP1, TMP1, 8 + | b <2 + |3: + | li CARG3, 0 + | mr L:SAVE0, L:CARG1 + | li CARG4, 0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | lp TMP2, L:SAVE0->base + | cmplwi CRET1, LUA_YIELD + | lp TMP3, L:SAVE0->top + | li_vmstate INTERP + | lp BASE, L->base + | st_vmstate + | bgt >8 + | sub RD, TMP3, TMP2 + | lwz TMP0, L->maxstack + | cmplwi RD, 0 + | add TMP1, BASE, RD + | beq >6 // No results? + | cmplw TMP1, TMP0 + | li TMP1, 0 + | bgt >9 // Need to grow stack? + | + | subi TMP3, RD, 8 + | stp TMP2, L:SAVE0->top // Clear coroutine stack. + |5: // Move results from coroutine. + | cmplw TMP1, TMP3 + | lfdx f0, TMP2, TMP1 + | stfdx f0, BASE, TMP1 + | addi TMP1, TMP1, 8 + | bne <5 + |6: + | andix. TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | la RA, -8(BASE) + | stw TMP1, -8(BASE) // Prepend true to results. + | addi RD, RD, 16 + |.else + | mr RA, BASE + | addi RD, RD, 8 + |.endif + |7: + | stw PC, SAVE_PC + | mr MULTRES, RD + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | andix. TMP0, PC, FRAME_TYPE + | la TMP3, -8(TMP3) + | li TMP1, LJ_TFALSE + | lfd f0, 0(TMP3) + | stp TMP3, L:SAVE0->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | stw TMP1, -8(BASE) // Prepend false to results. + | la RA, -8(BASE) + | stfd f0, 0(BASE) // Copy error message. + | b <7 + |.else + | mr CARG1, L + | mr CARG2, L:SAVE0 + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |.endif + | + |9: // Handle stack expansion on return from yield. + | mr CARG1, L + | srwi CARG2, RD, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | li CRET1, 0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lp TMP0, L->cframe + | add TMP1, BASE, NARGS8:RC + | stp BASE, L->base + | andix. TMP0, TMP0, CFRAME_RESUME + | stp TMP1, L->top + | li CRET1, LUA_YIELD + | beq ->fff_fallback + | stp ZERO, L->cframe + | stb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_1 math_abs + | checknum CARG3 + |.if DUALNUM + | bne >2 + | srawi TMP1, CARG1, 31 + | xor TMP2, TMP1, CARG1 + |.if GPR64 + | lus TMP0, 0x8000 + | sub CARG1, TMP2, TMP1 + | cmplw CARG1, TMP0 + | beq >1 + |.else + | sub. CARG1, TMP2, TMP1 + | blt >1 + |.endif + |->fff_resi: + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | stw TISNUM, -8(BASE) + | stw CRET1, -4(BASE) + | b ->fff_res1 + |1: + | lus CARG3, 0x41e0 // 2^31. + | li CARG1, 0 + | b ->fff_restv + |2: + |.endif + | bge ->fff_fallback + | rlwinm CARG3, CARG3, 0, 1, 31 + | // Fallthrough. + | + |->fff_restv: + | // CARG3/CARG1 = TValue result. + | lwz PC, FRAME_PC(BASE) + | stw CARG3, -8(BASE) + | la RA, -8(BASE) + | stw CARG1, -4(BASE) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andix. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | bney ->vm_return + | lwz INS, -4(PC) + | decode_RB8 RB, INS + |5: + | cmplw RB, RD // More results expected? + | decode_RA8 TMP0, INS + | bgt >6 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, RA, TMP1 + | b <5 + | + |.macro math_extern, func + | .ffunc_n math_ .. func + | blex func + | b ->fff_resn + |.endmacro + | + |.macro math_extern2, func + | .ffunc_nn math_ .. func + | blex func + | b ->fff_resn + |.endmacro + | + |.macro math_round, func + | .ffunc_1 math_ .. func + | checknum CARG3; beqy ->fff_restv + | rlwinm TMP2, CARG3, 12, 21, 31 + | bge ->fff_fallback + | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023 + | cmplwi cr1, TMP2, 31 // 0 <= exp < 31? + | subfic TMP0, TMP2, 31 + | blt >3 + | slwi TMP1, CARG3, 11 + | srwi TMP3, CARG1, 21 + | oris TMP1, TMP1, 0x8000 + | addi TMP2, TMP2, 1 + | or TMP1, TMP1, TMP3 + | slwi CARG2, CARG1, 11 + | bge cr1, >4 + | slw TMP3, TMP1, TMP2 + | srw RD, TMP1, TMP0 + | or TMP3, TMP3, CARG2 + | srawi TMP2, CARG3, 31 + |.if "func" == "floor" + | and TMP1, TMP3, TMP2 + | addic TMP0, TMP1, -1 + | subfe TMP1, TMP0, TMP1 + | add CARG1, RD, TMP1 + | xor CARG1, CARG1, TMP2 + | sub CARG1, CARG1, TMP2 + | b ->fff_resi + |.else + | andc TMP1, TMP3, TMP2 + | addic TMP0, TMP1, -1 + | subfe TMP1, TMP0, TMP1 + | add CARG1, RD, TMP1 + | cmpw CARG1, RD + | xor CARG1, CARG1, TMP2 + | sub CARG1, CARG1, TMP2 + | bge ->fff_resi + | // Overflow to 2^31. + | lus CARG3, 0x41e0 // 2^31. + | li CARG1, 0 + | b ->fff_restv + |.endif + |3: // |x| < 1 + | slwi TMP2, CARG3, 1 + | srawi TMP1, CARG3, 31 + | or TMP2, CARG1, TMP2 // ztest = (hi+hi) | lo + |.if "func" == "floor" + | and TMP1, TMP2, TMP1 // (ztest & sign) == 0 ? 0 : -1 + | subfic TMP2, TMP1, 0 + | subfe CARG1, CARG1, CARG1 + |.else + | andc TMP1, TMP2, TMP1 // (ztest & ~sign) == 0 ? 0 : 1 + | addic TMP2, TMP1, -1 + | subfe CARG1, TMP2, TMP1 + |.endif + | b ->fff_resi + |4: // exp >= 31. Check for -(2^31). + | xoris TMP1, TMP1, 0x8000 + | srawi TMP2, CARG3, 31 + |.if "func" == "floor" + | or TMP1, TMP1, CARG2 + |.endif + |.if PPE + | orc TMP1, TMP1, TMP2 + | cmpwi TMP1, 0 + |.else + | orc. TMP1, TMP1, TMP2 + |.endif + | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | lus CARG1, 0x8000 // -(2^31). + | beqy ->fff_resi + |5: + | lfd FARG1, 0(BASE) + | blex func + | b ->fff_resn + |.endmacro + | + |.if DUALNUM + | math_round floor + | math_round ceil + |.else + | // NYI: use internal implementation. + | math_extern floor + | math_extern ceil + |.endif + | + |.if SQRT + |.ffunc_n math_sqrt + | fsqrt FARG1, FARG1 + | b ->fff_resn + |.else + | math_extern sqrt + |.endif + | + |.ffunc math_log + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checknum CARG3; bge ->fff_fallback + | blex log + | b ->fff_resn + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.ffunc_n math_rad + | lfd FARG2, CFUNC:RB->upvalue[0] + | fmul FARG1, FARG1, FARG2 + | b ->fff_resn + | + |.if DUALNUM + |.ffunc math_ldexp + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 0(BASE) + | lfd FARG1, 0(BASE) + | lwz CARG4, 8(BASE) + |.if GPR64 + | lwz CARG2, 12(BASE) + |.else + | lwz CARG1, 12(BASE) + |.endif + | blt ->fff_fallback + | checknum CARG3; bge ->fff_fallback + | checknum CARG4; bne ->fff_fallback + |.else + |.ffunc_nn math_ldexp + |.if GPR64 + | toint CARG2, FARG2 + |.else + | toint CARG1, FARG2 + |.endif + |.endif + | blex ldexp + | b ->fff_resn + | + |.ffunc_n math_frexp + |.if GPR64 + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + |.else + | la CARG1, DISPATCH_GL(tmptv)(DISPATCH) + |.endif + | lwz PC, FRAME_PC(BASE) + | blex frexp + | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | la RA, -8(BASE) + |.if not DUALNUM + | tonum_i FARG2, TMP1 + |.endif + | stfd FARG1, 0(RA) + | li RD, (2+1)*8 + |.if DUALNUM + | stw TISNUM, 8(RA) + | stw TMP1, 12(RA) + |.else + | stfd FARG2, 8(RA) + |.endif + | b ->fff_res + | + |.ffunc_n math_modf + |.if GPR64 + | la CARG2, -8(BASE) + |.else + | la CARG1, -8(BASE) + |.endif + | lwz PC, FRAME_PC(BASE) + | blex modf + | la RA, -8(BASE) + | stfd FARG1, 0(BASE) + | li RD, (2+1)*8 + | b ->fff_res + | + |.macro math_minmax, name, ismax + |.if DUALNUM + | .ffunc_1 name + | checknum CARG3 + | addi TMP1, BASE, 8 + | add TMP2, BASE, NARGS8:RC + | bne >4 + |1: // Handle integers. + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + | lwz CARG2, 4(TMP1) + | bge cr1, ->fff_resi + | checknum CARG4 + | xoris TMP0, CARG1, 0x8000 + | xoris TMP3, CARG2, 0x8000 + | bne >3 + | subfc TMP3, TMP3, TMP0 + | subfe TMP0, TMP0, TMP0 + |.if ismax + | andc TMP3, TMP3, TMP0 + |.else + | and TMP3, TMP3, TMP0 + |.endif + | add CARG1, TMP3, CARG2 + |.if GPR64 + | rldicl CARG1, CARG1, 0, 32 + |.endif + | addi TMP1, TMP1, 8 + | b <1 + |3: + | bge ->fff_fallback + | // Convert intermediate result to number and continue below. + | tonum_i FARG1, CARG1 + | lfd FARG2, 0(TMP1) + | b >6 + |4: + | lfd FARG1, 0(BASE) + | bge ->fff_fallback + |5: // Handle numbers. + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + | lfd FARG2, 0(TMP1) + | bge cr1, ->fff_resn + | checknum CARG4; bge >7 + |6: + | fsub f0, FARG1, FARG2 + | addi TMP1, TMP1, 8 + |.if ismax + | fsel FARG1, f0, FARG1, FARG2 + |.else + | fsel FARG1, f0, FARG2, FARG1 + |.endif + | b <5 + |7: // Convert integer to number and continue above. + | lwz CARG2, 4(TMP1) + | bne ->fff_fallback + | tonum_i FARG2, CARG2 + | b <6 + |.else + | .ffunc_n name + | li TMP1, 8 + |1: + | lwzx CARG2, BASE, TMP1 + | lfdx FARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_resn + | bge ->fff_fallback + | fsub f0, FARG1, FARG2 + | addi TMP1, TMP1, 8 + |.if ismax + | fsel FARG1, f0, FARG1, FARG2 + |.else + | fsel FARG1, f0, FARG2, FARG1 + |.endif + | b <1 + |.endif + |.endmacro + | + | math_minmax math_min, 0 + | math_minmax math_max, 1 + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr CARG3; bne ->fff_fallback + | lwz CRET1, STR:CARG1->len + | b ->fff_resi + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checkstr CARG3 + | bne ->fff_fallback + | lwz TMP0, STR:CARG1->len + |.if DUALNUM + | lbz CARG1, STR:CARG1[1] // Access is always ok (NUL at end). + | li RD, (0+1)*8 + | lwz PC, FRAME_PC(BASE) + | cmplwi TMP0, 0 + | la RA, -8(BASE) + | beqy ->fff_res + | b ->fff_resi + |.else + | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | addic TMP3, TMP0, -1 // RD = ((str->len != 0)+1)*8 + | subfe RD, TMP3, TMP0 + | stw TMP1, TONUM_LO // Inlined tonum_u f0, TMP1. + | addi RD, RD, 1 + | lfd f0, TONUM_D + | la RA, -8(BASE) + | lwz PC, FRAME_PC(BASE) + | fsub f0, f0, TOBIT + | slwi RD, RD, 3 + | stfd f0, 0(RA) + | b ->fff_res + |.endif + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + |.if DUALNUM + | lwz TMP0, 4(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG3; bne ->fff_fallback + | la CARG2, 7(BASE) + |.else + | lfd FARG1, 0(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG3; bge ->fff_fallback + | toint TMP0, FARG1 + | la CARG2, TMPD_BLO + |.endif + | li CARG3, 1 + | cmplwi TMP0, 255; bgt ->fff_fallback + |->fff_newstr: + | mr CARG1, L + | stp BASE, L->base + | stw PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | lp BASE, L->base + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | cmplwi NARGS8:RC, 16 + | lwz CARG3, 16(BASE) + |.if not DUALNUM + | lfd f0, 16(BASE) + |.endif + | lwz TMP0, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | lwz CARG2, 8(BASE) + |.if DUALNUM + | lwz TMP1, 12(BASE) + |.else + | lfd f1, 8(BASE) + |.endif + | li TMP2, -1 + | beq >1 + |.if DUALNUM + | checknum CARG3 + | lwz TMP2, 20(BASE) + | bne ->fff_fallback + |1: + | checknum CARG2; bne ->fff_fallback + |.else + | checknum CARG3; bge ->fff_fallback + | toint TMP2, f0 + |1: + | checknum CARG2; bge ->fff_fallback + |.endif + | checkstr TMP0; bne ->fff_fallback + |.if not DUALNUM + | toint TMP1, f1 + |.endif + | lwz TMP0, STR:CARG1->len + | cmplw TMP0, TMP2 // len < end? (unsigned compare) + | addi TMP3, TMP2, 1 + | blt >5 + |2: + | cmpwi TMP1, 0 // start <= 0? + | add TMP3, TMP1, TMP0 + | ble >7 + |3: + | sub CARG3, TMP2, TMP1 + | addi CARG2, STR:CARG1, #STR-1 + | srawi TMP0, CARG3, 31 + | addi CARG3, CARG3, 1 + | add CARG2, CARG2, TMP1 + | andc CARG3, CARG3, TMP0 + |.if GPR64 + | rldicl CARG2, CARG2, 0, 32 + | rldicl CARG3, CARG3, 0, 32 + |.endif + | b ->fff_newstr + | + |5: // Negative end or overflow. + | cmpw TMP0, TMP2 // len >= end? (signed compare) + | add TMP2, TMP0, TMP3 // Negative end: end = end+len+1. + | bge <2 + | mr TMP2, TMP0 // Overflow: end = len. + | b <2 + | + |7: // Negative start or underflow. + | .gpr64 extsw TMP1, TMP1 + | addic CARG3, TMP1, -1 + | subfe CARG3, CARG3, CARG3 + | srawi CARG2, TMP3, 31 // Note: modifies carry. + | andc TMP3, TMP3, CARG3 + | andc TMP1, TMP3, CARG2 + | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) + | b <3 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmplwi NARGS8:RC, 16 + | lwz TMP0, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | lwz CARG4, 8(BASE) + |.if DUALNUM + | lwz CARG3, 12(BASE) + |.else + | lfd FARG2, 8(BASE) + |.endif + | bne ->fff_fallback // Exactly 2 arguments. + | checkstr TMP0; bne ->fff_fallback + |.if DUALNUM + | checknum CARG4; bne ->fff_fallback + |.else + | checknum CARG4; bge ->fff_fallback + | toint CARG3, FARG2 + |.endif + | lwz TMP0, STR:CARG1->len + | cmpwi CARG3, 0 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | ble >2 // Count <= 0? (or non-int) + | cmplwi TMP0, 1 + | subi TMP2, CARG3, 1 + | blt >2 // Zero length string? + | cmplw cr1, TMP1, CARG3 + | bne ->fff_fallback // Fallback for > 1-char strings. + | lbz TMP0, STR:CARG1[1] + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | blt cr1, ->fff_fallback + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | cmplwi TMP2, 0 + | stbx TMP0, CARG2, TMP2 + | subi TMP2, TMP2, 1 + | bne <1 + | b ->fff_newstr + |2: // Return empty string. + | la STR:CARG1, DISPATCH_GL(strempty)(DISPATCH) + | li CARG3, LJ_TSTR + | b ->fff_restv + | + |.ffunc string_reverse + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | checkstr CARG3 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | bne ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | li TMP2, 0 + | cmplw TMP1, CARG3 + | subi TMP3, CARG3, 1 + | blt ->fff_fallback + |1: // Reverse string copy. + | cmpwi TMP3, 0 + | lbzx TMP1, CARG1, TMP2 + | blty ->fff_newstr + | stbx TMP1, CARG2, TMP3 + | subi TMP3, TMP3, 1 + | addi TMP2, TMP2, 1 + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | cmplwi NARGS8:RC, 8 + | lwz CARG3, 0(BASE) + | lwz STR:CARG1, 4(BASE) + | blt ->fff_fallback + | checkstr CARG3 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | bne ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | cmplw TMP1, CARG3 + | li TMP2, 0 + | blt ->fff_fallback + |1: // ASCII case conversion. + | cmplw TMP2, CARG3 + | lbzx TMP1, CARG1, TMP2 + | bgey ->fff_newstr + | subi TMP0, TMP1, lo + | xori TMP3, TMP1, 0x20 + | addic TMP0, TMP0, -26 + | subfe TMP3, TMP3, TMP3 + | rlwinm TMP3, TMP3, 0, 26, 26 // x &= 0x20. + | xor TMP1, TMP1, TMP3 + | stbx TMP1, CARG2, TMP2 + | addi TMP2, TMP2, 1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG3; bne ->fff_fallback + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b ->fff_resi + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + |.if DUALNUM + | .ffunc_1 bit_..name + | checknum CARG3; bnel ->fff_tobit_fb + |.else + | .ffunc_n bit_..name + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + |.endif + |.endmacro + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | addi TMP1, BASE, 8 + | add TMP2, BASE, NARGS8:RC + |1: + | lwz CARG4, 0(TMP1) + | cmplw cr1, TMP1, TMP2 + |.if DUALNUM + | lwz CARG2, 4(TMP1) + |.else + | lfd FARG1, 0(TMP1) + |.endif + | bgey cr1, ->fff_resi + | checknum CARG4 + |.if DUALNUM + | bnel ->fff_bitop_fb + |.else + | fadd FARG1, FARG1, TOBIT + | bge ->fff_fallback + | stfd FARG1, TMPD + | lwz CARG2, TMPD_LO + |.endif + | ins CARG1, CARG1, CARG2 + | addi TMP1, TMP1, 8 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | rotlwi TMP0, CARG1, 8 + | rlwimi TMP0, CARG1, 24, 0, 7 + | rlwimi TMP0, CARG1, 24, 16, 23 + | mr CRET1, TMP0 + | b ->fff_resi + | + |.ffunc_bit bnot + | not CRET1, CARG1 + | b ->fff_resi + | + |.macro .ffunc_bit_sh, name, ins, shmod + |.if DUALNUM + | .ffunc_2 bit_..name + | checknum CARG3; bnel ->fff_tobit_fb + | // Note: no inline conversion from number for 2nd argument! + | checknum CARG4; bne ->fff_fallback + |.else + | .ffunc_nn bit_..name + | fadd FARG1, FARG1, TOBIT + | fadd FARG2, FARG2, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + | stfd FARG2, TMPD + | lwz CARG2, TMPD_LO + |.endif + |.if shmod == 1 + | rlwinm CARG2, CARG2, 0, 27, 31 + |.elif shmod == 2 + | neg CARG2, CARG2 + |.endif + | ins CRET1, CARG1, CARG2 + | b ->fff_resi + |.endmacro + | + |.ffunc_bit_sh lshift, slw, 1 + |.ffunc_bit_sh rshift, srw, 1 + |.ffunc_bit_sh arshift, sraw, 1 + |.ffunc_bit_sh rol, rotlw, 0 + |.ffunc_bit_sh ror, rotlw, 2 + | + |.ffunc_bit tobit + |.if DUALNUM + | b ->fff_resi + |.else + |->fff_resi: + | tonum_i FARG1, CRET1 + |.endif + |->fff_resn: + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | stfd FARG1, -8(BASE) + | b ->fff_res1 + | + |// Fallback FP number to bit conversion. + |->fff_tobit_fb: + |.if DUALNUM + | lfd FARG1, 0(BASE) + | bgt ->fff_fallback + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG1, TMPD_LO + | blr + |.endif + |->fff_bitop_fb: + |.if DUALNUM + | lfd FARG1, 0(TMP1) + | bgt ->fff_fallback + | fadd FARG1, FARG1, TOBIT + | stfd FARG1, TMPD + | lwz CARG2, TMPD_LO + | blr + |.endif + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lp TMP3, CFUNC:RB->f + | add TMP1, BASE, NARGS8:RC + | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addi TMP0, TMP1, 8*LUA_MINSTACK + | lwz TMP2, L->maxstack + | stw PC, SAVE_PC // Redundant (but a defined value). + | .toc lp TMP3, 0(TMP3) + | cmplw TMP0, TMP2 + | stp BASE, L->base + | stp TMP1, L->top + | mr CARG1, L + | bgt >5 // Need to grow stack. + | mtctr TMP3 + | bctrl // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lp BASE, L->base + | cmpwi CRET1, 0 + | slwi RD, CRET1, 3 + | la RA, -8(BASE) + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | lp TMP0, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub NARGS8:RC, TMP0, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andix. TMP0, PC, FRAME_TYPE + | rlwinm TMP1, PC, 0, 0, 28 + | bne >3 + | lwz INS, -4(PC) + | decode_RA8 TMP1, INS + | addi TMP1, TMP1, 8 + |3: + | sub TMP2, BASE, TMP1 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | li CARG2, LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mflr SAVE0 + | stp BASE, L->base + | add TMP0, BASE, NARGS8:RC + | stw PC, SAVE_PC // Redundant (but a defined value). + | stp TMP0, L->top + | mr CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | lp BASE, L->base + | mtlr SAVE0 + | lp TMP0, L->top + | sub NARGS8:RC, TMP0, BASE + | lwz CFUNC:RB, FRAME_FUNC(BASE) + | blr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andix. TMP0, TMP3, HOOK_VMEVENT // No recording while in vmevent. + | bne >5 + | // Decrement the hookcount for consistency, but always do the call. + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE + | bne >1 + | subi TMP2, TMP2, 1 + | andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT + | beqy >1 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | b >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OPP TMP1, INS. + | lpx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | bctr + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0 + | bne <5 + | + | cmpwi cr1, TMP0, 0 + | addic. TMP2, TMP2, -1 + | beq cr1, <5 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | beq >1 + | bge cr1, <5 + |1: + | mr CARG1, L + | stw MULTRES, SAVE_MULTRES + | mr CARG2, PC + | stp BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | lp BASE, L->base + |4: // Re-dispatch to static ins. + | lwz INS, -4(PC) + | decode_OPP TMP1, INS + | decode_RB8 RB, INS + | addi TMP1, TMP1, GG_DISP2STATIC + | decode_RD8 RD, INS + | lpx TMP0, DISPATCH, TMP1 + | decode_RA8 RA, INS + | decode_RC8 RC, INS + | mtctr TMP0 + | bctr + | + |->cont_hook: // Continue from hook yield. + | addi PC, PC, 4 + | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | addi CARG1, DISPATCH, GG_DISP2J + | stw PC, SAVE_PC + | lwz TMP1, LFUNC:TMP1->pc + | mr CARG2, PC + | stw L, DISPATCH_J(L)(DISPATCH) + | lbz TMP1, PC2PROTO(framesize)(TMP1) + | stp BASE, L->base + | slwi TMP1, TMP1, 3 + | add TMP1, BASE, TMP1 + | stp TMP1, L->top + | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) + | b <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mr CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | add TMP0, BASE, RC + | stw PC, SAVE_PC + | mr CARG1, L + | stp BASE, L->base + | sub RA, RA, BASE + | stp TMP0, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | lp BASE, L->base + | lp TMP0, L->top + | stw ZERO, SAVE_PC // Invalidate for subsequent line hook. + | sub NARGS8:RC, TMP0, BASE + | add RA, BASE, RA + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | lwz INS, -4(PC) + | mtctr CRET1 + | bctr + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro savex_, a, b, c, d + | stfd f..a, 16+a*8(sp) + | stfd f..b, 16+b*8(sp) + | stfd f..c, 16+c*8(sp) + | stfd f..d, 16+d*8(sp) + |.endmacro + | + |->vm_exit_handler: + |.if JIT + | addi sp, sp, -(16+32*8+32*4) + | stmw r2, 16+32*8+2*4(sp) + | addi DISPATCH, JGL, -GG_DISP2G-32768 + | li CARG2, ~LJ_VMST_EXIT + | lwz CARG1, 16+32*8+32*4(sp) // Get stack chain. + | stw CARG2, DISPATCH_GL(vmstate)(DISPATCH) + | savex_ 0,1,2,3 + | stw CARG1, 0(sp) // Store extended stack chain. + | mcrxr cr0 // Clear SO flag. + | savex_ 4,5,6,7 + | addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp. + | savex_ 8,9,10,11 + | stw CARG2, 16+32*8+1*4(sp) // Store sp in RID_SP. + | savex_ 12,13,14,15 + | mflr CARG3 + | li TMP1, 0 + | savex_ 16,17,18,19 + | stw TMP1, 16+32*8+0*4(sp) // Clear RID_TMP. + | savex_ 20,21,22,23 + | lhz CARG4, 2(CARG3) // Load trace number. + | savex_ 24,25,26,27 + | lwz L, DISPATCH_GL(jit_L)(DISPATCH) + | savex_ 28,29,30,31 + | sub CARG3, TMP0, CARG3 // Compute exit number. + | lp BASE, DISPATCH_GL(jit_base)(DISPATCH) + | srwi CARG3, CARG3, 2 + | stw L, DISPATCH_J(L)(DISPATCH) + | subi CARG3, CARG3, 2 + | stw TMP1, DISPATCH_GL(jit_L)(DISPATCH) + | stw CARG4, DISPATCH_J(parent)(DISPATCH) + | stp BASE, L->base + | addi CARG1, DISPATCH, GG_DISP2J + | stw CARG3, DISPATCH_J(exitno)(DISPATCH) + | addi CARG2, sp, 16 + | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) + | // Returns MULTRES (unscaled) or negated error code. + | lp TMP1, L->cframe + | lwz TMP2, 0(sp) + | lp BASE, L->base + |.if GPR64 + | rldicr sp, TMP1, 0, 61 + |.else + | rlwinm sp, TMP1, 0, 0, 29 + |.endif + | lwz PC, SAVE_PC // Get SAVE_PC. + | stw TMP2, 0(sp) + | stw L, SAVE_L // Set SAVE_L (on-trace resume/yield). + | b >1 + |.endif + |->vm_exit_interp: + |.if JIT + | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set. + | lwz L, SAVE_L + | addi DISPATCH, JGL, -GG_DISP2G-32768 + |1: + | cmpwi CARG1, 0 + | blt >3 // Check for error from exit. + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | slwi MULTRES, CARG1, 3 + | li TMP2, 0 + | stw MULTRES, SAVE_MULTRES + | lwz TMP1, LFUNC:TMP1->pc + | stw TMP2, DISPATCH_GL(jit_L)(DISPATCH) + | lwz KBASE, PC2PROTO(k)(TMP1) + | // Setup type comparison constants. + | li TISNUM, LJ_TISNUM + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | stw TMP3, TMPD + | li ZERO, 0 + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | lfs TOBIT, TMPD + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | li TISNIL, LJ_TNIL + | stw TMP0, TONUM_HI + | lfs TONUM, TMPD + | // Modified copy of ins_next which handles function header dispatch, too. + | lwz INS, 0(PC) + | addi PC, PC, 4 + | // Assumes TISNIL == ~LJ_VMST_INTERP == -1. + | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) + | decode_OPP TMP1, INS + | decode_RA8 RA, INS + | lpx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | cmplwi TMP1, BC_FUNCF*4 // Function header? + | bge >2 + | decode_RB8 RB, INS + | decode_RD8 RD, INS + | decode_RC8 RC, INS + | bctr + |2: + | subi RC, MULTRES, 8 + | add RA, RA, BASE + | bctr + | + |3: // Rethrow error from the right C frame. + | neg CARG2, CARG1 + | mr CARG1, L + | bl extern lj_err_throw // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// NYI: Use internal implementations of floor, ceil, trunc. + | + |->vm_modi: + | divwo. TMP0, CARG1, CARG2 + | bso >1 + |.if GPR64 + | xor CARG3, CARG1, CARG2 + | cmpwi CARG3, 0 + |.else + | xor. CARG3, CARG1, CARG2 + |.endif + | mullw TMP0, TMP0, CARG2 + | sub CARG1, CARG1, TMP0 + | bgelr + | cmpwi CARG1, 0; beqlr + | add CARG1, CARG1, CARG2 + | blr + |1: + | cmpwi CARG2, 0 + | li CARG1, 0 + | beqlr + | mcrxr cr0 // Clear SO for -2147483648 % -1 and return 0. + | blr + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |// void lj_vm_cachesync(void *start, void *end) + |// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size. + |// This is a good lower bound, except for very ancient PPC models. + |->vm_cachesync: + |.if JIT or FFI + | // Compute start of first cache line and number of cache lines. + | rlwinm CARG1, CARG1, 0, 0, 26 + | sub CARG2, CARG2, CARG1 + | addi CARG2, CARG2, 31 + | rlwinm. CARG2, CARG2, 27, 5, 31 + | beqlr + | mtctr CARG2 + | mr CARG3, CARG1 + |1: // Flush D-Cache. + | dcbst r0, CARG1 + | addi CARG1, CARG1, 32 + | bdnz <1 + | sync + | mtctr CARG2 + |1: // Invalidate I-Cache. + | icbi r0, CARG3 + | addi CARG3, CARG3, 32 + | bdnz <1 + | isync + | blr + |.endif + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in r11, g in r12. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + | saveregs + | lwz CTSTATE, GL:r12->ctype_state + | addi DISPATCH, r12, GG_G2DISP + | stw r11, CTSTATE->cb.slot + | stw r3, CTSTATE->cb.gpr[0] + | stfd f1, CTSTATE->cb.fpr[0] + | stw r4, CTSTATE->cb.gpr[1] + | stfd f2, CTSTATE->cb.fpr[1] + | stw r5, CTSTATE->cb.gpr[2] + | stfd f3, CTSTATE->cb.fpr[2] + | stw r6, CTSTATE->cb.gpr[3] + | stfd f4, CTSTATE->cb.fpr[3] + | stw r7, CTSTATE->cb.gpr[4] + | stfd f5, CTSTATE->cb.fpr[4] + | stw r8, CTSTATE->cb.gpr[5] + | stfd f6, CTSTATE->cb.fpr[5] + | stw r9, CTSTATE->cb.gpr[6] + | stfd f7, CTSTATE->cb.fpr[6] + | stw r10, CTSTATE->cb.gpr[7] + | stfd f8, CTSTATE->cb.fpr[7] + | addi TMP0, sp, CFRAME_SPACE+8 + | stw TMP0, CTSTATE->cb.stack + | mr CARG1, CTSTATE + | stw CTSTATE, SAVE_PC // Any value outside of bytecode is ok. + | mr CARG2, sp + | bl extern lj_ccallback_enter // (CTState *cts, void *cf) + | // Returns lua_State *. + | lp BASE, L:CRET1->base + | li TISNUM, LJ_TISNUM // Setup type comparison constants. + | lp RC, L:CRET1->top + | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). + | li ZERO, 0 + | mr L, CRET1 + | stw TMP3, TMPD + | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). + | stw TMP0, TONUM_HI + | li TISNIL, LJ_TNIL + | li_vmstate INTERP + | lfs TOBIT, TMPD + | stw TMP3, TMPD + | sub RC, RC, BASE + | st_vmstate + | lfs TONUM, TMPD + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH) + | stp BASE, L->base + | stp RB, L->top + | stp L, CTSTATE->L + | mr CARG1, CTSTATE + | mr CARG2, RA + | bl extern lj_ccallback_leave // (CTState *cts, TValue *o) + | lwz CRET1, CTSTATE->cb.gpr[0] + | lfd FARG1, CTSTATE->cb.fpr[0] + | lwz CRET2, CTSTATE->cb.gpr[1] + | b ->vm_leave_unw + |.endif + | + |->vm_ffi_call: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + | .type CCSTATE, CCallState, CARG1 + | lwz TMP1, CCSTATE->spadj + | mflr TMP0 + | lbz CARG2, CCSTATE->nsp + | lbz CARG3, CCSTATE->nfpr + | neg TMP1, TMP1 + | stw TMP0, 4(sp) + | cmpwi cr1, CARG3, 0 + | mr TMP2, sp + | addic. CARG2, CARG2, -1 + | stwux sp, sp, TMP1 + | crnot 4*cr1+eq, 4*cr1+eq // For vararg calls. + | stw r14, -4(TMP2) + | stw CCSTATE, -8(TMP2) + | mr r14, TMP2 + | la TMP1, CCSTATE->stack + | slwi CARG2, CARG2, 2 + | blty >2 + | la TMP2, 8(sp) + |1: + | lwzx TMP0, TMP1, CARG2 + | stwx TMP0, TMP2, CARG2 + | addic. CARG2, CARG2, -4 + | bge <1 + |2: + | bney cr1, >3 + | lfd f1, CCSTATE->fpr[0] + | lfd f2, CCSTATE->fpr[1] + | lfd f3, CCSTATE->fpr[2] + | lfd f4, CCSTATE->fpr[3] + | lfd f5, CCSTATE->fpr[4] + | lfd f6, CCSTATE->fpr[5] + | lfd f7, CCSTATE->fpr[6] + | lfd f8, CCSTATE->fpr[7] + |3: + | lp TMP0, CCSTATE->func + | lwz CARG2, CCSTATE->gpr[1] + | lwz CARG3, CCSTATE->gpr[2] + | lwz CARG4, CCSTATE->gpr[3] + | lwz CARG5, CCSTATE->gpr[4] + | mtctr TMP0 + | lwz r8, CCSTATE->gpr[5] + | lwz r9, CCSTATE->gpr[6] + | lwz r10, CCSTATE->gpr[7] + | lwz CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1. + | bctrl + | lwz CCSTATE:TMP1, -8(r14) + | lwz TMP2, -4(r14) + | lwz TMP0, 4(r14) + | stw CARG1, CCSTATE:TMP1->gpr[0] + | stfd FARG1, CCSTATE:TMP1->fpr[0] + | stw CARG2, CCSTATE:TMP1->gpr[1] + | mtlr TMP0 + | stw CARG3, CCSTATE:TMP1->gpr[2] + | mr sp, r14 + | stw CARG4, CCSTATE:TMP1->gpr[3] + | mr r14, TMP2 + | blr + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, BASE + | lwz TMP2, -4(PC) + | checknum cr0, TMP0 + | lwz CARG3, 4(RD) + | decode_RD4 TMP2, TMP2 + | checknum cr1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bne cr0, >7 + | bne cr1, >8 + | cmpw CARG2, CARG3 + if (op == BC_ISLT) { + | bge >2 + } else if (op == BC_ISGE) { + | blt >2 + } else if (op == BC_ISLE) { + | bgt >2 + } else { + | ble >2 + } + |1: + | add PC, PC, TMP2 + |2: + | ins_next + | + |7: // RA is not an integer. + | bgt cr0, ->vmeta_comp + | // RA is a number. + | lfd f0, 0(RA) + | bgt cr1, ->vmeta_comp + | blt cr1, >4 + | // RA is a number, RD is an integer. + | tonum_i f1, CARG3 + | b >5 + | + |8: // RA is an integer, RD is not an integer. + | bgt cr1, ->vmeta_comp + | // RA is an integer, RD is a number. + | tonum_i f0, CARG2 + |4: + | lfd f1, 0(RD) + |5: + | fcmpu cr0, f0, f1 + if (op == BC_ISLT) { + | bge <2 + } else if (op == BC_ISGE) { + | blt <2 + } else if (op == BC_ISLE) { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | bge <2 + } else { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | blt <2 + } + | b <1 + |.else + | lwzx TMP0, BASE, RA + | addi PC, PC, 4 + | lfdx f0, BASE, RA + | lwzx TMP1, BASE, RD + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | lfdx f1, BASE, RD + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | bge cr0, ->vmeta_comp + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge cr1, ->vmeta_comp + | fcmpu cr0, f0, f1 + if (op == BC_ISLT) { + | bge >1 + } else if (op == BC_ISGE) { + | blt >1 + } else if (op == BC_ISLE) { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | bge >1 + } else { + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq + | blt >1 + } + | add PC, PC, TMP2 + |1: + | ins_next + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, BASE + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | lwz CARG3, 4(RD) + | cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (vk) { + | ble cr7, ->BC_ISEQN_Z + } else { + | ble cr7, ->BC_ISNEN_Z + } + |.else + | lwzux TMP0, RA, BASE + | lwz TMP2, 0(PC) + | lfd f0, 0(RA) + | addi PC, PC, 4 + | lwzux TMP1, RD, BASE + | checknum cr0, TMP0 + | decode_RD4 TMP2, TMP2 + | lfd f1, 0(RD) + | checknum cr1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge cr0, >5 + | bge cr1, >5 + | fcmpu cr0, f0, f1 + if (vk) { + | bne >1 + | add PC, PC, TMP2 + } else { + | beq >1 + | add PC, PC, TMP2 + } + |1: + | ins_next + |.endif + |5: // Either or both types are not numbers. + |.if not DUALNUM + | lwz CARG2, 4(RA) + | lwz CARG3, 4(RD) + |.endif + |.if FFI + | cmpwi cr7, TMP0, LJ_TCDATA + | cmpwi cr5, TMP1, LJ_TCDATA + |.endif + | not TMP3, TMP0 + | cmplw TMP0, TMP1 + | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive? + |.if FFI + | cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq + |.endif + | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata? + |.if FFI + | beq cr7, ->vmeta_equal_cd + |.endif + | cmplw cr5, CARG2, CARG3 + | crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt // 2: Same type and primitive. + | crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq // 1: Same tv or different type. + | crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq // 0: Same type and same tv. + | mr SAVE0, PC + | cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt // 0 or 2. + | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt // 1 or 2. + if (vk) { + | bne cr0, >6 + | add PC, PC, TMP2 + |6: + } else { + | beq cr0, >6 + | add PC, PC, TMP2 + |6: + } + |.if DUALNUM + | bge cr0, >2 // Done if 1 or 2. + |1: + | ins_next + |2: + |.else + | blt cr0, <1 // Done if 1 or 2. + |.endif + | blt cr6, <1 // Done if not tab/ud. + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:TMP2, TAB:CARG2->metatable + | li CARG4, 1-vk // ne = 0 or 1. + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable? + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_equal // Handle __eq metamethod. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | lwzux TMP0, RA, BASE + | srwi RD, RD, 1 + | lwz STR:TMP3, 4(RA) + | lwz TMP2, 0(PC) + | subfic RD, RD, -4 + | addi PC, PC, 4 + |.if FFI + | cmpwi TMP0, LJ_TCDATA + |.endif + | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4 + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TSTR + |.if FFI + | beq ->vmeta_equal_cd + |.endif + | sub TMP1, STR:TMP1, STR:TMP3 + | or TMP0, TMP0, TMP1 + | decode_RD4 TMP2, TMP2 + | subfic TMP0, TMP0, 0 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | subfe TMP1, TMP1, TMP1 + if (vk) { + | andc TMP2, TMP2, TMP1 + } else { + | and TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + |.if DUALNUM + | lwzux TMP0, RA, BASE + | addi PC, PC, 4 + | lwz CARG2, 4(RA) + | lwzux TMP1, RD, KBASE + | checknum cr0, TMP0 + | lwz TMP2, -4(PC) + | checknum cr1, TMP1 + | decode_RD4 TMP2, TMP2 + | lwz CARG3, 4(RD) + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (vk) { + |->BC_ISEQN_Z: + } else { + |->BC_ISNEN_Z: + } + | bne cr0, >7 + | bne cr1, >8 + | cmpw CARG2, CARG3 + |4: + |.else + if (vk) { + |->BC_ISEQN_Z: // Dummy label. + } else { + |->BC_ISNEN_Z: // Dummy label. + } + | lwzx TMP0, BASE, RA + | addi PC, PC, 4 + | lfdx f0, BASE, RA + | lwz TMP2, -4(PC) + | lfdx f1, KBASE, RD + | decode_RD4 TMP2, TMP2 + | checknum TMP0 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | bge >3 + | fcmpu cr0, f0, f1 + |.endif + if (vk) { + | bne >1 + | add PC, PC, TMP2 + |1: + |.if not FFI + |3: + |.endif + } else { + | beq >2 + |1: + |.if not FFI + |3: + |.endif + | add PC, PC, TMP2 + |2: + } + | ins_next + |.if FFI + |3: + | cmpwi TMP0, LJ_TCDATA + | beq ->vmeta_equal_cd + | b <1 + |.endif + |.if DUALNUM + |7: // RA is not an integer. + | bge cr0, <3 + | // RA is a number. + | lfd f0, 0(RA) + | blt cr1, >1 + | // RA is a number, RD is an integer. + | tonum_i f1, CARG3 + | b >2 + | + |8: // RA is an integer, RD is a number. + | tonum_i f0, CARG2 + |1: + | lfd f1, 0(RD) + |2: + | fcmpu cr0, f0, f1 + | b <4 + |.endif + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | lwzx TMP0, BASE, RA + | srwi TMP1, RD, 3 + | lwz TMP2, 0(PC) + | not TMP1, TMP1 + | addi PC, PC, 4 + |.if FFI + | cmpwi TMP0, LJ_TCDATA + |.endif + | sub TMP0, TMP0, TMP1 + |.if FFI + | beq ->vmeta_equal_cd + |.endif + | decode_RD4 TMP2, TMP2 + | .gpr64 extsw TMP0, TMP0 + | addic TMP0, TMP0, -1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + | subfe TMP1, TMP1, TMP1 + if (vk) { + | and TMP2, TMP2, TMP1 + } else { + | andc TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | lwzx TMP0, BASE, RD + | lwz INS, 0(PC) + | addi PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | .gpr64 extsw TMP0, TMP0 + | subfic TMP0, TMP0, LJ_TTRUE + | decode_RD4 TMP2, INS + | subfe TMP1, TMP1, TMP1 + | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16) + if (op == BC_IST) { + | andc TMP2, TMP2, TMP1 + } else { + | and TMP2, TMP2, TMP1 + } + | add PC, PC, TMP2 + } else { + | li TMP1, LJ_TFALSE + | lfdx f0, BASE, RD + | cmplw TMP0, TMP1 + if (op == BC_ISTC) { + | bge >1 + } else { + | blt >1 + } + | addis PC, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | stfdx f0, BASE, RA + | add PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lfdx f0, BASE, RD + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lwzx TMP0, BASE, RD + | .gpr64 extsw TMP0, TMP0 + | subfic TMP1, TMP0, LJ_TTRUE + | adde TMP0, TMP0, TMP1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | lwzux TMP1, RD, BASE + | lwz TMP0, 4(RD) + | checknum TMP1 + |.if DUALNUM + | bne >5 + |.if GPR64 + | lus TMP2, 0x8000 + | neg TMP0, TMP0 + | cmplw TMP0, TMP2 + | beq >4 + |.else + | nego. TMP0, TMP0 + | bso >4 + |1: + |.endif + | ins_next1 + | stwux TISNUM, RA, BASE + | stw TMP0, 4(RA) + |3: + | ins_next2 + |4: + |.if not GPR64 + | // Potential overflow. + | mcrxr cr0; bley <1 // Ignore unrelated overflow. + |.endif + | lus TMP1, 0x41e0 // 2^31. + | li TMP0, 0 + | b >7 + |.endif + |5: + | bge ->vmeta_unm + | xoris TMP1, TMP1, 0x8000 + |7: + | ins_next1 + | stwux TMP1, RA, BASE + | stw TMP0, 4(RA) + |.if DUALNUM + | b <3 + |.else + | ins_next2 + |.endif + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | lwzux TMP0, RD, BASE + | lwz CARG1, 4(RD) + | checkstr TMP0; bne >2 + | lwz CRET1, STR:CARG1->len + |1: + |.if DUALNUM + | ins_next1 + | stwux TISNUM, RA, BASE + | stw CRET1, 4(RA) + |.else + | tonum_u f0, CRET1 // Result is a non-negative integer. + | ins_next1 + | stfdx f0, BASE, RA + |.endif + | ins_next2 + |2: + | checktab TMP0; bne ->vmeta_len +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | cmplwi TAB:TMP2, 0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b <1 +#if LJ_52 + |9: + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | lwzx TMP1, BASE, RB + | .if DUALNUM + | lwzx TMP2, KBASE, RC + | .endif + | lfdx f14, BASE, RB + | lfdx f15, KBASE, RC + | .if DUALNUM + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vn + | .else + | checknum TMP1; bge ->vmeta_arith_vn + | .endif + || break; + ||case 1: + | lwzx TMP1, BASE, RB + | .if DUALNUM + | lwzx TMP2, KBASE, RC + | .endif + | lfdx f15, BASE, RB + | lfdx f14, KBASE, RC + | .if DUALNUM + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_nv + | .else + | checknum TMP1; bge ->vmeta_arith_nv + | .endif + || break; + ||default: + | lwzx TMP1, BASE, RB + | lwzx TMP2, BASE, RC + | lfdx f14, BASE, RB + | lfdx f15, BASE, RC + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arithfallback, ins + ||switch (vk) { + ||case 0: + | ins ->vmeta_arith_vn2 + || break; + ||case 1: + | ins ->vmeta_arith_nv2 + || break; + ||default: + | ins ->vmeta_arith_vv2 + || break; + ||} + |.endmacro + | + |.macro intmod, a, b, c + | bl ->vm_modi + |.endmacro + | + |.macro fpmod, a, b, c + |->BC_MODVN_Z: + | fdiv FARG1, b, c + | // NYI: Use internal implementation of floor. + | blex floor // floor(b/c) + | fmul a, FARG1, c + | fsub a, b, a // b - floor(b/c)*c + |.endmacro + | + |.macro ins_arithfp, fpins + | ins_arithpre + |.if "fpins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |.else + | fpins f0, f14, f15 + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + |.endif + |.endmacro + | + |.macro ins_arithdn, intins, fpins + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, KBASE + | lwz CARG1, 4(RB) + | checknum cr0, TMP1 + | lwz CARG2, 4(RC) + || break; + ||case 1: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, KBASE + | lwz CARG2, 4(RB) + | checknum cr0, TMP1 + | lwz CARG1, 4(RC) + || break; + ||default: + | lwzux TMP1, RB, BASE + | lwzux TMP2, RC, BASE + | lwz CARG1, 4(RB) + | checknum cr0, TMP1 + | lwz CARG2, 4(RC) + || break; + ||} + | checknum cr1, TMP2 + | bne >5 + | bne cr1, >5 + | intins CARG1, CARG1, CARG2 + | bso >4 + |1: + | ins_next1 + | stwux TISNUM, RA, BASE + | stw CARG1, 4(RA) + |2: + | ins_next2 + |4: // Overflow. + | mcrxr cr0; bley <1 // Ignore unrelated overflow. + | ins_arithfallback b + |5: // FP variant. + ||if (vk == 1) { + | lfd f15, 0(RB) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f14, 0(RC) + ||} else { + | lfd f14, 0(RB) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f15, 0(RC) + ||} + | ins_arithfallback bge + |.if "fpins" == "fpmod_" + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + |.else + | fpins f0, f14, f15 + | ins_next1 + | stfdx f0, BASE, RA + | b <2 + |.endif + |.endmacro + | + |.macro ins_arith, intins, fpins + |.if DUALNUM + | ins_arithdn intins, fpins + |.else + | ins_arithfp fpins + |.endif + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + |.if GPR64 + |.macro addo32., y, a, b + | // Need to check overflow for (a<<32) + (b<<32). + | rldicr TMP0, a, 32, 31 + | rldicr TMP3, b, 32, 31 + | addo. TMP0, TMP0, TMP3 + | add y, a, b + |.endmacro + | ins_arith addo32., fadd + |.else + | ins_arith addo., fadd + |.endif + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + |.if GPR64 + |.macro subo32., y, a, b + | // Need to check overflow for (a<<32) - (b<<32). + | rldicr TMP0, a, 32, 31 + | rldicr TMP3, b, 32, 31 + | subo. TMP0, TMP0, TMP3 + | sub y, a, b + |.endmacro + | ins_arith subo32., fsub + |.else + | ins_arith subo., fsub + |.endif + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith mullwo., fmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arithfp fdiv + break; + case BC_MODVN: + | ins_arith intmod, fpmod + break; + case BC_MODNV: case BC_MODVV: + | ins_arith intmod, fpmod_ + break; + case BC_POW: + | // NYI: (partial) integer arithmetic. + | lwzx TMP1, BASE, RB + | lfdx FARG1, BASE, RB + | lwzx TMP2, BASE, RC + | lfdx FARG2, BASE, RC + | checknum cr0, TMP1 + | checknum cr1, TMP2 + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | bge ->vmeta_arith_vv + | blex pow + | ins_next1 + | stfdx FARG1, BASE, RA + | ins_next2 + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | sub CARG3, RC, RB + | stp BASE, L->base + | add CARG2, BASE, RC + | mr SAVE0, RB + |->BC_CAT_Z: + | stw PC, SAVE_PC + | mr CARG1, L + | srwi CARG3, CARG3, 3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | lp BASE, L->base + | bne ->vmeta_binop + | ins_next1 + | lfdx f0, BASE, SAVE0 // Copy result from RB to RA. + | stfdx f0, BASE, RA + | ins_next2 + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | ins_next1 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4 + | li TMP2, LJ_TSTR + | stwux TMP2, RA, BASE + | stw TMP0, 4(RA) + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | ins_next1 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4 + | li TMP2, LJ_TCDATA + | stwux TMP2, RA, BASE + | stw TMP0, 4(RA) + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + |.if DUALNUM + | slwi RD, RD, 13 + | srawi RD, RD, 16 + | ins_next1 + | stwux TISNUM, RA, BASE + | stw RD, 4(RA) + | ins_next2 + |.else + | // The soft-float approach is faster. + | slwi RD, RD, 13 + | srawi TMP1, RD, 31 + | xor TMP2, TMP1, RD + | sub TMP2, TMP2, TMP1 // TMP2 = abs(x) + | cntlzw TMP3, TMP2 + | subfic TMP1, TMP3, 0x40d // TMP1 = exponent-1 + | slw TMP2, TMP2, TMP3 // TMP2 = left aligned mantissa + | subfic TMP3, RD, 0 + | slwi TMP1, TMP1, 20 + | rlwimi RD, TMP2, 21, 1, 31 // hi = sign(x) | (mantissa>>11) + | subfe TMP0, TMP0, TMP0 + | add RD, RD, TMP1 // hi = hi + exponent-1 + | and RD, RD, TMP0 // hi = x == 0 ? 0 : hi + | ins_next1 + | stwux RD, RA, BASE + | stw ZERO, 4(RA) + | ins_next2 + |.endif + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | ins_next1 + | lfdx f0, KBASE, RD + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srwi TMP1, RD, 3 + | not TMP0, TMP1 + | ins_next1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | stwx TISNIL, BASE, RA + | addi RA, RA, 8 + |1: + | stwx TISNIL, BASE, RA + | cmpw RA, RD + | addi RA, RA, 8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RD, RD, 1 + | addi RD, RD, offsetof(GCfuncL, uvptr) + | lwzx UPVAL:RB, LFUNC:RB, RD + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | lfd f0, 0(TMP1) + | stfdx f0, BASE, RA + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lfdux f0, RD, BASE + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP0, UPVAL:RB->closed + | lwz TMP2, 0(RD) + | stfd f0, 0(CARG2) + | cmplwi cr1, TMP0, 0 + | lwz TMP1, 4(RD) + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | subi TMP2, TMP2, (LJ_TNUMX+1) + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1) + | bge <1 // tvisgcv(v) + | lbz TMP3, GCOBJ:TMP1->gch.marked + | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | srwi RA, RA, 1 + | subfic TMP1, TMP1, -4 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4 + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP3, STR:TMP1->marked + | lbz TMP2, UPVAL:RB->closed + | li TMP0, LJ_TSTR + | stw STR:TMP1, 4(CARG2) + | stw TMP0, 0(CARG2) + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(str) + | cmplwi cr1, TMP2, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lfdx f0, KBASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | stfd f0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | srwi TMP0, RD, 3 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | not TMP0, TMP0 + | lwzx UPVAL:RB, LFUNC:RB, RA + | ins_next1 + | lwz TMP1, UPVAL:RB->v + | stw TMP0, 0(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lwz TMP1, L->openupval + | branch_RD // Do this first since RD is not saved. + | stp BASE, L->base + | cmplwi TMP1, 0 + | mr CARG1, L + | beq >1 + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | lp BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srwi TMP1, RD, 1 + | stp BASE, L->base + | subfic TMP1, TMP1, -4 + | stw PC, SAVE_PC + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | mr CARG1, L + | lwz CARG3, FRAME_FUNC(BASE) + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | lp BASE, L->base + | li TMP0, LJ_TFUNC + | stwux TMP0, RA, BASE + | stw LFUNC:CRET1, 4(RA) + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | mr CARG1, L + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | stp BASE, L->base + | cmplw TMP0, TMP1 + | stw PC, SAVE_PC + | bge >5 + |1: + if (op == BC_TNEW) { + | rlwinm CARG2, RD, 29, 21, 31 + | rlwinm CARG3, RD, 18, 27, 31 + | cmpwi CARG2, 0x7ff; beq >3 + |2: + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns Table *. + } else { + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns Table *. + } + | lp BASE, L->base + | li TMP0, LJ_TTAB + | stwux TMP0, RA, BASE + | stw TAB:CRET1, 4(RA) + | ins_next + if (op == BC_TNEW) { + |3: + | li CARG2, 0x801 + | b <2 + } + |5: + | mr SAVE0, RD + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mr RD, SAVE0 + | mr CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lwz LFUNC:TMP2, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | lwz TAB:RB, LFUNC:TMP2->env + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | lwzux CARG1, RB, BASE + | lwzux CARG2, RC, BASE + | lwz TAB:RB, 4(RB) + |.if DUALNUM + | lwz RC, 4(RC) + |.else + | lfd f0, 0(RC) + |.endif + | checktab CARG1 + | checknum cr1, CARG2 + | bne ->vmeta_tgetv + |.if DUALNUM + | lwz TMP0, TAB:RB->asize + | bne cr1, >5 + | lwz TMP1, TAB:RB->array + | cmplw TMP0, RC + | slwi TMP2, RC, 3 + |.else + | bge cr1, >5 + | // Convert number key to integer, check for integerness and range. + | fctiwz f1, f0 + | fadd f2, f0, TOBIT + | stfd f1, TMPD + | lwz TMP0, TAB:RB->asize + | fsub f2, f2, TOBIT + | lwz TMP2, TMPD_LO + | lwz TMP1, TAB:RB->array + | fcmpu cr1, f0, f2 + | cmplw cr0, TMP0, TMP2 + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq + | slwi TMP2, TMP2, 3 + |.endif + | ble ->vmeta_tgetv // Integer key and in array part? + | lwzx TMP0, TMP1, TMP2 + | lfdx f14, TMP1, TMP2 + | checknil TMP0; beq >2 + |1: + | ins_next1 + | stfdx f14, BASE, RA + | ins_next2 + | + |2: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_tgetv + | + |5: + | checkstr CARG2; bne ->vmeta_tgetv + |.if not DUALNUM + | lwz STR:RC, 4(RC) + |.endif + | b ->BC_TGETS_Z // String key? + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*8 (~) + | lwzux CARG1, RB, BASE + | srwi TMP1, RC, 1 + | lwz TAB:RB, 4(RB) + | subfic TMP1, TMP1, -4 + | checktab CARG1 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | bne ->vmeta_tgets1 + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lwz CARG1, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2) + | checkstr CARG1; bne >4 + | cmpw TMP0, STR:RC; bne >4 + | checknil CARG2; beq >5 // Key found, but nil value? + |3: + | stwux CARG2, RA, BASE + | stw TMP1, 4(RA) + | ins_next + | + |4: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, nil result. + | li CARG2, LJ_TNIL + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <3 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andix. TMP0, TMP0, 1<vmeta_tgets + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | lwzux CARG1, RB, BASE + | srwi TMP0, RC, 3 + | lwz TAB:RB, 4(RB) + | checktab CARG1; bne ->vmeta_tgetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | cmplw TMP0, TMP1; bge ->vmeta_tgetb + | lwzx TMP1, TMP2, RC + | lfdx f0, TMP2, RC + | checknil TMP1; beq >5 + |1: + | ins_next1 + | stfdx f0, BASE, RA + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_tgetb // Caveat: preserve TMP0! + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | lwzux CARG1, RB, BASE + | lwzux CARG2, RC, BASE + | lwz TAB:RB, 4(RB) + |.if DUALNUM + | lwz RC, 4(RC) + |.else + | lfd f0, 0(RC) + |.endif + | checktab CARG1 + | checknum cr1, CARG2 + | bne ->vmeta_tsetv + |.if DUALNUM + | lwz TMP0, TAB:RB->asize + | bne cr1, >5 + | lwz TMP1, TAB:RB->array + | cmplw TMP0, RC + | slwi TMP0, RC, 3 + |.else + | bge cr1, >5 + | // Convert number key to integer, check for integerness and range. + | fctiwz f1, f0 + | fadd f2, f0, TOBIT + | stfd f1, TMPD + | lwz TMP0, TAB:RB->asize + | fsub f2, f2, TOBIT + | lwz TMP2, TMPD_LO + | lwz TMP1, TAB:RB->array + | fcmpu cr1, f0, f2 + | cmplw cr0, TMP0, TMP2 + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq + | slwi TMP0, TMP2, 3 + |.endif + | ble ->vmeta_tsetv // Integer key and in array part? + | lwzx TMP2, TMP1, TMP0 + | lbz TMP3, TAB:RB->marked + | lfdx f14, BASE, RA + | checknil TMP2; beq >3 + |1: + | andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table) + | stfdx f14, TMP1, TMP0 + | bne >7 + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andix. TMP2, TMP2, 1<vmeta_tsetv + | + |5: + | checkstr CARG2; bne ->vmeta_tsetv + |.if not DUALNUM + | lwz STR:RC, 4(RC) + |.endif + | b ->BC_TSETS_Z // String key? + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | lwzux CARG1, RB, BASE + | srwi TMP1, RC, 1 + | lwz TAB:RB, 4(RB) + | subfic TMP1, TMP1, -4 + | checktab CARG1 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | bne ->vmeta_tsets1 + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | stb ZERO, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | lfdx f14, BASE, RA + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | lbz TMP3, TAB:RB->marked + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | lwz CARG1, NODE:TMP2->key + | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2) + | lwz CARG2, NODE:TMP2->val + | lwz NODE:TMP1, NODE:TMP2->next + | checkstr CARG1; bne >5 + | cmpw TMP0, STR:RC; bne >5 + | checknil CARG2; beq >4 // Key found, but nil value? + |2: + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stfd f14, NODE:TMP2->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <2 // No metatable: done. + | lbz TMP0, TAB:TMP1->nomm + | andix. TMP0, TMP0, 1<vmeta_tsets + | + |5: // Follow hash chain. + | cmplwi NODE:TMP1, 0 + | mr NODE:TMP2, NODE:TMP1 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | lwz TAB:TMP1, TAB:RB->metatable + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | stw PC, SAVE_PC + | mr CARG1, L + | cmplwi TAB:TMP1, 0 + | stp BASE, L->base + | beq >6 // No metatable: continue. + | lbz TMP0, TAB:TMP1->nomm + | andix. TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | li TMP0, LJ_TSTR + | stw STR:RC, 4(CARG3) + | mr CARG2, TAB:RB + | stw TMP0, 0(CARG3) + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | lp BASE, L->base + | stfd f14, 0(CRET1) + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | lwzux CARG1, RB, BASE + | srwi TMP0, RC, 3 + | lwz TAB:RB, 4(RB) + | checktab CARG1; bne ->vmeta_tsetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | lbz TMP3, TAB:RB->marked + | cmplw TMP0, TMP1 + | lfdx f14, BASE, RA + | bge ->vmeta_tsetb + | lwzx TMP1, TMP2, RC + | checknil TMP1; beq >5 + |1: + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stfdx f14, TMP2, RC + | bne >7 + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <1 // No metatable: done. + | lbz TMP1, TAB:TMP1->nomm + | andix. TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | add RA, BASE, RA + |1: + | add TMP3, KBASE, RD + | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table. + | addic. TMP0, MULTRES, -8 + | lwz TMP3, 4(TMP3) // Integer constant is in lo-word. + | srwi CARG3, TMP0, 3 + | beq >4 // Nothing to copy? + | add CARG3, CARG3, TMP3 + | lwz TMP2, TAB:CARG2->asize + | slwi TMP1, TMP3, 3 + | lbz TMP3, TAB:CARG2->marked + | cmplw CARG3, TMP2 + | add TMP2, RA, TMP0 + | lwz TMP0, TAB:CARG2->array + | bgt >5 + | add TMP1, TMP1, TMP0 + | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | lfd f0, 0(RA) + | addi RA, RA, 8 + | cmpw cr1, RA, TMP2 + | stfd f0, 0(TMP1) + | addi TMP1, TMP1, 8 + | blt cr1, <3 + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | stp BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | mr SAVE0, RD + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | mr RD, SAVE0 + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALL follows. + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | mr TMP2, BASE + | lwzux TMP0, BASE, RA + | lwz LFUNC:RB, 4(BASE) + | subi NARGS8:RC, NARGS8:RC, 8 + | addi BASE, BASE, 8 + | checkfunc TMP0; bne ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | lwzux TMP0, RA, BASE + | lwz LFUNC:RB, 4(RA) + | subi NARGS8:RC, NARGS8:RC, 8 + | lwz TMP1, FRAME_PC(BASE) + | checkfunc TMP0 + | addi RA, RA, 8 + | bne ->vmeta_callt + |->BC_CALLT_Z: + | andix. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand. + | lbz TMP3, LFUNC:RB->ffid + | xori TMP2, TMP1, FRAME_VARG + | cmplwi cr1, NARGS8:RC, 0 + | bne >7 + |1: + | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | li TMP2, 0 + | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function? + | beq cr1, >3 + |2: + | addi TMP3, TMP2, 8 + | lfdx f0, RA, TMP2 + | cmplw cr1, TMP3, NARGS8:RC + | stfdx f0, BASE, TMP2 + | mr TMP2, TMP3 + | bne cr1, <2 + |3: + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt + | beq >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lwz INS, -4(TMP1) + | decode_RA8 RA, INS + | sub TMP1, BASE, RA + | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1) + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | b <4 + | + |7: // Tailcall from a vararg function. + | andix. TMP0, TMP2, FRAME_TYPEP + | bne <1 // Vararg frame below? + | sub BASE, BASE, TMP2 // Relocate BASE down. + | lwz TMP1, FRAME_PC(BASE) + | andix. TMP0, TMP1, FRAME_TYPE + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | mr TMP2, BASE + | add BASE, BASE, RA + | lwz TMP1, -24(BASE) + | lwz LFUNC:RB, -20(BASE) + | lfd f1, -8(BASE) + | lfd f0, -16(BASE) + | stw TMP1, 0(BASE) // Copy callable. + | stw LFUNC:RB, 4(BASE) + | checkfunc TMP1 + | stfd f1, 16(BASE) // Copy control var. + | li NARGS8:RC, 16 // Iterators get 2 arguments. + | stfdu f0, 8(BASE) // Copy state. + | bne ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | lwz TAB:RB, -12(RA) + | lwz RC, -4(RA) // Get index from control var. + | lwz TMP0, TAB:RB->asize + | lwz TMP1, TAB:RB->array + | addi PC, PC, 4 + |1: // Traverse array part. + | cmplw RC, TMP0 + | slwi TMP3, RC, 3 + | bge >5 // Index points after array part? + | lwzx TMP2, TMP1, TMP3 + | lfdx f0, TMP1, TMP3 + | checknil TMP2 + | lwz INS, -4(PC) + | beq >4 + |.if DUALNUM + | stw RC, 4(RA) + | stw TISNUM, 0(RA) + |.else + | tonum_u f1, RC + |.endif + | addi RC, RC, 1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | stfd f0, 8(RA) + | decode_RD4 TMP1, INS + | stw RC, -4(RA) // Update control var. + | add PC, TMP1, TMP3 + |.if not DUALNUM + | stfd f1, 0(RA) + |.endif + |3: + | ins_next + | + |4: // Skip holes in array part. + | addi RC, RC, 1 + | b <1 + | + |5: // Traverse hash part. + | lwz TMP1, TAB:RB->hmask + | sub RC, RC, TMP0 + | lwz TMP2, TAB:RB->node + |6: + | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1. + | slwi TMP3, RC, 5 + | bgty <3 + | slwi RB, RC, 3 + | sub TMP3, TMP3, RB + | lwzx RB, TMP2, TMP3 + | lfdx f0, TMP2, TMP3 + | add NODE:TMP3, TMP2, TMP3 + | checknil RB + | lwz INS, -4(PC) + | beq >7 + | lfd f1, NODE:TMP3->key + | addis TMP2, PC, -(BCBIAS_J*4 >> 16) + | stfd f0, 8(RA) + | add RC, RC, TMP0 + | decode_RD4 TMP1, INS + | stfd f1, 0(RA) + | addi RC, RC, 1 + | add PC, TMP1, TMP2 + | stw RC, -4(RA) // Update control var. + | b <3 + | + |7: // Skip holes in hash part. + | addi RC, RC, 1 + | b <6 + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | add RA, BASE, RA + | lwz TMP0, -24(RA) + | lwz CFUNC:TMP1, -20(RA) + | lwz TMP2, -16(RA) + | lwz TMP3, -8(RA) + | cmpwi cr0, TMP2, LJ_TTAB + | cmpwi cr1, TMP0, LJ_TFUNC + | cmpwi cr6, TMP3, LJ_TNIL + | bne cr1, >5 + | lbz TMP1, CFUNC:TMP1->ffid + | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq + | cmpwi cr7, TMP1, FF_next_N + | srwi TMP0, RD, 1 + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | add TMP3, PC, TMP0 + | bne cr0, >5 + | lus TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | stw ZERO, -4(RA) // Initialize control var. + | stw TMP1, -8(RA) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP0, BC_JMP + | li TMP1, BC_ITERC + | stb TMP0, -1(PC) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + | stb TMP1, 3(PC) + | b <1 + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lwz TMP0, FRAME_PC(BASE) + | add RC, BASE, RC + | add RA, BASE, RA + | addi RC, RC, FRAME_VARG + | add TMP2, RA, RB + | subi TMP3, BASE, 8 // TMP3 = vtop + | sub RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmplwi cr1, RB, 0 + |.if PPE + | sub TMP1, TMP3, RC + | cmpwi TMP1, 0 + |.else + | sub. TMP1, TMP3, RC + |.endif + | beq cr1, >5 // Copy all varargs? + | subi TMP2, TMP2, 16 + | ble >2 // No vararg slots? + |1: // Copy vararg slots to destination slots. + | lfd f0, 0(RC) + | addi RC, RC, 8 + | stfd f0, 0(RA) + | cmplw RA, TMP2 + | cmplw cr1, RC, TMP3 + | bge >3 // All destination slots filled? + | addi RA, RA, 8 + | blt cr1, <1 // More vararg slots? + |2: // Fill up remainder with nil. + | stw TISNIL, 0(RA) + | cmplw RA, TMP2 + | addi RA, RA, 8 + | blt <2 + |3: + | ins_next + | + |5: // Copy all varargs. + | lwz TMP0, L->maxstack + | li MULTRES, 8 // MULTRES = (0+1)*8 + | bley <3 // No vararg slots? + | add TMP2, RA, TMP1 + | cmplw TMP2, TMP0 + | addi MULTRES, TMP1, 8 + | bgt >7 + |6: + | lfd f0, 0(RC) + | addi RC, RC, 8 + | stfd f0, 0(RA) + | cmplw RC, TMP3 + | addi RA, RA, 8 + | blt <6 // More vararg slots? + | b <3 + | + |7: // Grow stack for varargs. + | mr CARG1, L + | stp RA, L->top + | sub SAVE0, RC, BASE // Need delta, because BASE may change. + | stp BASE, L->base + | sub RA, RA, BASE + | stw PC, SAVE_PC + | srwi CARG2, TMP1, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | lp BASE, L->base + | add RA, BASE, RA + | add RC, BASE, SAVE0 + | subi TMP3, BASE, 8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + |1: + | andix. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lwz INS, -4(PC) + | cmpwi RD, 8 + | subi TMP2, BASE, 8 + | subi RC, RD, 8 + | decode_RB8 RB, INS + | beq >3 + | li TMP1, 0 + |2: + | addi TMP3, TMP1, 8 + | lfdx f0, RA, TMP1 + | cmpw TMP3, RC + | stfdx f0, TMP2, TMP1 + | beq >3 + | addi TMP1, TMP3, 8 + | lfdx f1, RA, TMP3 + | cmpw TMP1, RC + | stfdx f1, TMP2, TMP3 + | bne <2 + |3: + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, TMP2, TMP1 + | b <5 + | + |->BC_RETV_Z: // Non-standard return case. + | andix. TMP2, TMP1, FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, TMP1 + | lwz PC, FRAME_PC(BASE) + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + | andix. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bney ->BC_RETV_Z + | + | lwz INS, -4(PC) + | subi TMP2, BASE, 8 + | decode_RB8 RB, INS + if (op == BC_RET1) { + | lfd f0, 0(RA) + | stfd f0, 0(TMP2) + } + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | stwx TISNIL, TMP2, TMP1 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + |.if DUALNUM + | // Integer loop. + | lwzux TMP1, RA, BASE + | lwz CARG1, FORL_IDX*8+4(RA) + | cmplw cr0, TMP1, TISNUM + if (vk) { + | lwz CARG3, FORL_STEP*8+4(RA) + | bne >9 + |.if GPR64 + | // Need to check overflow for (a<<32) + (b<<32). + | rldicr TMP0, CARG1, 32, 31 + | rldicr TMP2, CARG3, 32, 31 + | add CARG1, CARG1, CARG3 + | addo. TMP0, TMP0, TMP2 + |.else + | addo. CARG1, CARG1, CARG3 + |.endif + | cmpwi cr6, CARG3, 0 + | lwz CARG2, FORL_STOP*8+4(RA) + | bso >6 + |4: + | stw CARG1, FORL_IDX*8+4(RA) + } else { + | lwz TMP3, FORL_STEP*8(RA) + | lwz CARG3, FORL_STEP*8+4(RA) + | lwz TMP2, FORL_STOP*8(RA) + | lwz CARG2, FORL_STOP*8+4(RA) + | cmplw cr7, TMP3, TISNUM + | cmplw cr1, TMP2, TISNUM + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | cmpwi cr6, CARG3, 0 + | bne >9 + } + | blt cr6, >5 + | cmpw CARG1, CARG2 + |1: + | stw TISNUM, FORL_EXT*8(RA) + if (op != BC_JFORL) { + | srwi RD, RD, 1 + } + | stw CARG1, FORL_EXT*8+4(RA) + if (op != BC_JFORL) { + | add RD, PC, RD + } + if (op == BC_FORI) { + | bgt >3 // See FP loop below. + } else if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + | bley >7 + } else if (op == BC_IFORL) { + | bgt >2 + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else { + | bley =>BC_JLOOP + } + |2: + | ins_next + |5: // Invert check for negative step. + | cmpw CARG2, CARG1 + | b <1 + if (vk) { + |6: // Potential overflow. + | mcrxr cr0; bley <4 // Ignore unrelated overflow. + | b <2 + } + |.endif + if (vk) { + |.if DUALNUM + |9: // FP loop. + | lfd f1, FORL_IDX*8(RA) + |.else + | lfdux f1, RA, BASE + |.endif + | lfd f3, FORL_STEP*8(RA) + | lfd f2, FORL_STOP*8(RA) + | lwz TMP3, FORL_STEP*8(RA) + | fadd f1, f1, f3 + | stfd f1, FORL_IDX*8(RA) + } else { + |.if DUALNUM + |9: // FP loop. + |.else + | lwzux TMP1, RA, BASE + | lwz TMP3, FORL_STEP*8(RA) + | lwz TMP2, FORL_STOP*8(RA) + | cmplw cr0, TMP1, TISNUM + | cmplw cr7, TMP3, TISNUM + | cmplw cr1, TMP2, TISNUM + |.endif + | lfd f1, FORL_IDX*8(RA) + | crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt + | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | lfd f2, FORL_STOP*8(RA) + | bge ->vmeta_for + } + | cmpwi cr6, TMP3, 0 + if (op != BC_JFORL) { + | srwi RD, RD, 1 + } + | stfd f1, FORL_EXT*8(RA) + if (op != BC_JFORL) { + | add RD, PC, RD + } + | fcmpu cr0, f1, f2 + if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } + | blt cr6, >5 + if (op == BC_FORI) { + | bgt >3 + } else if (op == BC_IFORL) { + |.if DUALNUM + | bgty <2 + |.else + | bgt >2 + |.endif + |1: + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else if (op == BC_JFORI) { + | bley >7 + } else { + | bley =>BC_JLOOP + } + |.if DUALNUM + | b <2 + |.else + |2: + | ins_next + |.endif + |5: // Negative step. + if (op == BC_FORI) { + | bge <2 + |3: // Used by integer loop, too. + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else if (op == BC_IFORL) { + | bgey <1 + } else if (op == BC_JFORI) { + | bgey >7 + } else { + | bgey =>BC_JLOOP + } + | b <2 + if (op == BC_JFORI) { + |7: + | lwz INS, -4(PC) + | decode_RD8 RD, INS + | b =>BC_JLOOP + } + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | lwzux TMP1, RA, BASE + | lwz TMP2, 4(RA) + | checknil TMP1; beq >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | stw TMP1, -8(RA) + | stw TMP2, -4(RA) + | b =>BC_JLOOP + } else { + | branch_RD // Otherwise save control var + branch. + | stw TMP1, -8(RA) + | stw TMP2, -4(RA) + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | // RA = base*8 (ignored), RD = traceno*8 + | lwz TMP1, DISPATCH_J(trace)(DISPATCH) + | srwi RD, RD, 1 + | // Traces on PPC don't store the trace number, so use 0. + | stw ZERO, DISPATCH_GL(vmstate)(DISPATCH) + | lwzx TRACE:TMP2, TMP1, RD + | mcrxr cr0 // Clear SO flag. + | lp TMP2, TRACE:TMP2->mcode + | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) + | mtctr TMP2 + | stw L, DISPATCH_GL(jit_L)(DISPATCH) + | addi JGL, DISPATCH, GG_DISP2G+32768 + | bctr + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | lbz TMP1, -4+PC2PROTO(numparams)(PC) + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw RA, TMP2 + | slwi TMP1, TMP1, 3 + | bgt ->vm_growstack_l + if (op != BC_JFUNCF) { + | ins_next1 + } + |2: + | cmplw NARGS8:RC, TMP1 // Check for missing parameters. + | blt >3 + if (op == BC_JFUNCF) { + | decode_RD8 RD, INS + | b =>BC_JLOOP + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | stwx TISNIL, BASE, NARGS8:RC + | addi NARGS8:RC, NARGS8:RC, 8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | add TMP1, BASE, RC + | add TMP0, RA, RC + | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC. + | addi TMP3, RC, 8+FRAME_VARG + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw TMP0, TMP2 + | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG. + | bge ->vm_growstack_l + | lbz TMP2, -4+PC2PROTO(numparams)(PC) + | mr RA, BASE + | mr RC, TMP1 + | ins_next1 + | cmpwi TMP2, 0 + | addi BASE, TMP1, 8 + | beq >3 + |1: + | cmplw RA, RC // Less args than parameters? + | lwz TMP0, 0(RA) + | lwz TMP3, 4(RA) + | bge >4 + | stw TISNIL, 0(RA) // Clear old fixarg slot (help the GC). + | addi RA, RA, 8 + |2: + | addic. TMP2, TMP2, -1 + | stw TMP0, 8(TMP1) + | stw TMP3, 12(TMP1) + | addi TMP1, TMP1, 8 + | bne <1 + |3: + | ins_next2 + | + |4: // Clear missing parameters. + | li TMP0, LJ_TNIL + | b <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lp RD, CFUNC:RB->f + } else { + | lp RD, DISPATCH_GL(wrapf)(DISPATCH) + } + | add TMP1, RA, NARGS8:RC + | lwz TMP2, L->maxstack + | .toc lp TMP3, 0(RD) + | add RC, BASE, NARGS8:RC + | stp BASE, L->base + | cmplw TMP1, TMP2 + | stp RC, L->top + | li_vmstate C + |.if TOC + | mtctr TMP3 + |.else + | mtctr RD + |.endif + if (op == BC_FUNCCW) { + | lp CARG2, CFUNC:RB->f + } + | mr CARG1, L + | bgt ->vm_growstack_c // Need to grow stack. + | .toc lp TOCREG, TOC_OFS(RD) + | .tocenv lp ENVREG, ENV_OFS(RD) + | st_vmstate + | bctrl // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | lp BASE, L->base + | .toc ld TOCREG, SAVE_TOC + | slwi RD, CRET1, 3 + | lp TMP1, L->top + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. + | sub RA, TMP1, RD // RA = L->top - nresults*8 + | st_vmstate + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n", + fcofs, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte %d\n\t.uleb128 %d\n", + 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" +#if LJ_TARGET_PS3 + "\t.long .lj_vm_ffi_call\n" +#else + "\t.long lj_vm_ffi_call\n" +#endif + "\t.long %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x8e\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0xe\n" + "\t.align 2\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif +#if !LJ_NO_UNWIND + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.long .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.long .LASFDE2-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n", + fcofs, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte %d\n\t.uleb128 %d\n", + 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE2:\n\n"); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.long .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.long .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.long .LASFDE3-.Lframe2\n" + "\t.long lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x8e\n\t.uleb128 2\n" + "\t.byte 0xd\n\t.uleb128 0xe\n" + "\t.align 2\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif +#endif + break; + default: + break; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppcspe.dasc b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppcspe.dasc new file mode 100644 index 0000000..adcec24 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_ppcspe.dasc @@ -0,0 +1,3691 @@ +|// Low-level VM code for PowerPC/e500 CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.arch ppc +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|// Note: The ragged indentation of the instructions is intentional. +|// The starting columns indicate data dependencies. +| +|//----------------------------------------------------------------------- +| +|// Fixed register assignments for the interpreter. +|// Don't use: r1 = sp, r2 and r13 = reserved and/or small data area ptr +| +|// The following must be C callee-save (but BASE is often refetched). +|.define BASE, r14 // Base of current Lua stack frame. +|.define KBASE, r15 // Constants of current Lua function. +|.define PC, r16 // Next PC. +|.define DISPATCH, r17 // Opcode dispatch table. +|.define LREG, r18 // Register holding lua_State (also in SAVE_L). +|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. +| +|// Constants for vectorized type-comparisons (hi+low GPR). C callee-save. +|.define TISNUM, r22 +|.define TISSTR, r23 +|.define TISTAB, r24 +|.define TISFUNC, r25 +|.define TISNIL, r26 +|.define TOBIT, r27 +|.define ZERO, TOBIT // Zero in lo word. +| +|// The following temporaries are not saved across C calls, except for RA. +|.define RA, r20 // Callee-save. +|.define RB, r10 +|.define RC, r11 +|.define RD, r12 +|.define INS, r7 // Overlaps CARG5. +| +|.define TMP0, r0 +|.define TMP1, r8 +|.define TMP2, r9 +|.define TMP3, r6 // Overlaps CARG4. +| +|// Saved temporaries. +|.define SAVE0, r21 +| +|// Calling conventions. +|.define CARG1, r3 +|.define CARG2, r4 +|.define CARG3, r5 +|.define CARG4, r6 // Overlaps TMP3. +|.define CARG5, r7 // Overlaps INS. +| +|.define CRET1, r3 +|.define CRET2, r4 +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|.define SAVE_LR, 188(sp) +|.define CFRAME_SPACE, 184 // Delta for sp. +|// Back chain for sp: 184(sp) <-- sp entering interpreter +|.define SAVE_r31, 176(sp) // 64 bit register saves. +|.define SAVE_r30, 168(sp) +|.define SAVE_r29, 160(sp) +|.define SAVE_r28, 152(sp) +|.define SAVE_r27, 144(sp) +|.define SAVE_r26, 136(sp) +|.define SAVE_r25, 128(sp) +|.define SAVE_r24, 120(sp) +|.define SAVE_r23, 112(sp) +|.define SAVE_r22, 104(sp) +|.define SAVE_r21, 96(sp) +|.define SAVE_r20, 88(sp) +|.define SAVE_r19, 80(sp) +|.define SAVE_r18, 72(sp) +|.define SAVE_r17, 64(sp) +|.define SAVE_r16, 56(sp) +|.define SAVE_r15, 48(sp) +|.define SAVE_r14, 40(sp) +|.define SAVE_CR, 36(sp) +|.define UNUSED1, 32(sp) +|.define SAVE_ERRF, 28(sp) // 32 bit C frame info. +|.define SAVE_NRES, 24(sp) +|.define SAVE_CFRAME, 20(sp) +|.define SAVE_L, 16(sp) +|.define SAVE_PC, 12(sp) +|.define SAVE_MULTRES, 8(sp) +|// Next frame lr: 4(sp) +|// Back chain for sp: 0(sp) <-- sp while in interpreter +| +|.macro save_, reg; evstdd reg, SAVE_..reg; .endmacro +|.macro rest_, reg; evldd reg, SAVE_..reg; .endmacro +| +|.macro saveregs +| stwu sp, -CFRAME_SPACE(sp) +| save_ r14; save_ r15; save_ r16; save_ r17; save_ r18; save_ r19 +| mflr r0; mfcr r12 +| save_ r20; save_ r21; save_ r22; save_ r23; save_ r24; save_ r25 +| stw r0, SAVE_LR; stw r12, SAVE_CR +| save_ r26; save_ r27; save_ r28; save_ r29; save_ r30; save_ r31 +|.endmacro +| +|.macro restoreregs +| lwz r0, SAVE_LR; lwz r12, SAVE_CR +| rest_ r14; rest_ r15; rest_ r16; rest_ r17; rest_ r18; rest_ r19 +| mtlr r0; mtcrf 0x38, r12 +| rest_ r20; rest_ r21; rest_ r22; rest_ r23; rest_ r24; rest_ r25 +| rest_ r26; rest_ r27; rest_ r28; rest_ r29; rest_ r30; rest_ r31 +| addi sp, sp, CFRAME_SPACE +|.endmacro +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State, LREG +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS8, int +|.type TRACE, GCtrace +| +|//----------------------------------------------------------------------- +| +|// These basic macros should really be part of DynASM. +|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro +|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro +|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro +|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro +|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro +| +|// Trap for not-yet-implemented parts. +|.macro NYI; tw 4, sp, sp; .endmacro +| +|//----------------------------------------------------------------------- +| +|// Access to frame relative to BASE. +|.define FRAME_PC, -8 +|.define FRAME_FUNC, -4 +| +|// Instruction decode. +|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro +|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro +|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro +|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro +|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro +| +|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro +|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro +| +|// Instruction fetch. +|.macro ins_NEXT1 +| lwz INS, 0(PC) +| addi PC, PC, 4 +|.endmacro +|// Instruction decode+dispatch. +|.macro ins_NEXT2 +| decode_OP4 TMP1, INS +| decode_RB8 RB, INS +| decode_RD8 RD, INS +| lwzx TMP0, DISPATCH, TMP1 +| decode_RA8 RA, INS +| decode_RC8 RC, INS +| mtctr TMP0 +| bctr +|.endmacro +|.macro ins_NEXT +| ins_NEXT1 +| ins_NEXT2 +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +| .define ins_next1, ins_NEXT1 +| .define ins_next2, ins_NEXT2 +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| .macro ins_next +| b ->ins_next +| .endmacro +| .macro ins_next1 +| .endmacro +| .macro ins_next2 +| b ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC +| lwz PC, LFUNC:RB->pc +| lwz INS, 0(PC) +| addi PC, PC, 4 +| decode_OP4 TMP1, INS +| decode_RA8 RA, INS +| lwzx TMP0, DISPATCH, TMP1 +| add RA, RA, BASE +| mtctr TMP0 +| bctr +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC +| stw PC, FRAME_PC(BASE) +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checknum, reg; evcmpltu reg, TISNUM; .endmacro +|.macro checkstr, reg; evcmpeq reg, TISSTR; .endmacro +|.macro checktab, reg; evcmpeq reg, TISTAB; .endmacro +|.macro checkfunc, reg; evcmpeq reg, TISFUNC; .endmacro +|.macro checknil, reg; evcmpeq reg, TISNIL; .endmacro +|.macro checkok, label; blt label; .endmacro +|.macro checkfail, label; bge label; .endmacro +|.macro checkanyfail, label; bns label; .endmacro +|.macro checkallok, label; bso label; .endmacro +| +|.macro branch_RD +| srwi TMP0, RD, 1 +| add PC, PC, TMP0 +| addis PC, PC, -(BCBIAS_J*4 >> 16) +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|.macro hotloop +| NYI +|.endmacro +| +|.macro hotcall +| NYI +|.endmacro +| +|// Set current VM state. Uses TMP0. +|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro +|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro +| +|// Move table write barrier back. Overwrites mark and tmp. +|.macro barrierback, tab, mark, tmp +| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH) +| // Assumes LJ_GC_BLACK is 0x04. +| rlwinm mark, mark, 0, 30, 28 // black2gray(tab) +| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH) +| stb mark, tab->marked +| stw tmp, tab->gclist +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | // See vm_return. Also: TMP2 = previous base. + | andi. TMP0, PC, FRAME_P + | evsplati TMP1, LJ_TTRUE + | beq ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame. + | mr BASE, TMP2 // Restore caller base. + | // Prepending may overwrite the pcall frame, so do it at the end. + | stwu TMP1, FRAME_PC(RA) // Prepend true to results. + | + |->vm_returnc: + | addi RD, RD, 8 // RD = (nresults+1)*8. + | andi. TMP0, PC, FRAME_TYPE + | cmpwi cr1, RD, 0 + | li CRET1, LUA_YIELD + | beq cr1, ->vm_unwind_c_eh + | mr MULTRES, RD + | beq ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return + | // TMP0 = PC & FRAME_TYPE + | cmpwi TMP0, FRAME_C + | rlwinm TMP2, PC, 0, 0, 28 + | li_vmstate C + | sub TMP2, BASE, TMP2 // TMP2 = previous base. + | bne ->vm_returnp + | + | addic. TMP1, RD, -8 + | stw TMP2, L->base + | lwz TMP2, SAVE_NRES + | subi BASE, BASE, 8 + | st_vmstate + | slwi TMP2, TMP2, 3 + | beq >2 + |1: + | addic. TMP1, TMP1, -8 + | evldd TMP0, 0(RA) + | addi RA, RA, 8 + | evstdd TMP0, 0(BASE) + | addi BASE, BASE, 8 + | bne <1 + | + |2: + | cmpw TMP2, RD // More/less results wanted? + | bne >6 + |3: + | stw BASE, L->top // Store new top. + | + |->vm_leave_cp: + | lwz TMP0, SAVE_CFRAME // Restore previous C frame. + | li CRET1, 0 // Ok return status for vm_pcall. + | stw TMP0, L->cframe + | + |->vm_leave_unw: + | restoreregs + | blr + | + |6: + | ble >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | lwz TMP1, L->maxstack + | cmplw BASE, TMP1 + | bge >8 + | evstdd TISNIL, 0(BASE) + | addi RD, RD, 8 + | addi BASE, BASE, 8 + | b <2 + | + |7: // Less results wanted. + | sub TMP0, RD, TMP2 + | cmpwi TMP2, 0 // LUA_MULTRET+1 case? + | sub TMP0, BASE, TMP0 // Subtract the difference. + | iseleq BASE, BASE, TMP0 // Either keep top or shrink it. + | b <3 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | stw BASE, L->top // Save current top held in BASE (yes). + | mr SAVE0, RD + | mr CARG2, TMP2 + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz TMP2, SAVE_NRES + | mr RD, SAVE0 + | slwi TMP2, TMP2, 3 + | lwz BASE, L->top // Need the (realloced) L->top in BASE. + | b <2 + | + |->vm_unwind_c: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + | mr sp, CARG1 + | mr CRET1, CARG2 + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | li TMP0, ~LJ_VMST_C + | lwz GL:TMP1, L->glref + | stw TMP0, GL:TMP1->vmstate + | b ->vm_leave_unw + | + |->vm_unwind_ff: // Unwind C stack, return from ff pcall. + | // (void *cframe) + | rlwinm sp, CARG1, 0, 0, 29 + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | lwz L, SAVE_L + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | evsplati TISFUNC, LJ_TFUNC + | lus TOBIT, 0x4338 + | evsplati TISTAB, LJ_TTAB + | li TMP0, 0 + | lwz BASE, L->base + | evmergelo TOBIT, TOBIT, TMP0 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | evsplati TISSTR, LJ_TSTR + | li TMP1, LJ_TFALSE + | evsplati TISNIL, LJ_TNIL + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame. + | la RA, -8(BASE) // Results start at BASE-8. + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw TMP1, 0(RA) // Prepend false to error message. + | li RD, 16 // 2 results: false + error message. + | st_vmstate + | b ->vm_returnc + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | li CARG2, LUA_MINSTACK + | b >2 + | + |->vm_growstack_l: // Grow stack for Lua function. + | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC + | add RC, BASE, RC + | sub RA, RA, BASE + | stw BASE, L->base + | addi PC, PC, 4 // Must point after first instruction. + | stw RC, L->top + | srwi CARG2, RA, 3 + |2: + | // L->base = new base, L->top = top + | stw PC, SAVE_PC + | mr CARG1, L + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | lwz RC, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub RC, RC, BASE + | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + | mr L, CARG1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | mr BASE, CARG2 + | lbz TMP1, L->status + | stw L, SAVE_L + | li PC, FRAME_CP + | addi TMP0, sp, CFRAME_RESUME + | addi DISPATCH, DISPATCH, GG_G2DISP + | stw CARG3, SAVE_NRES + | cmplwi TMP1, 0 + | stw CARG3, SAVE_ERRF + | stw TMP0, L->cframe + | stw CARG3, SAVE_CFRAME + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | beq >3 + | + | // Resume after yield (like a return). + | mr RA, BASE + | lwz BASE, L->base + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | lwz TMP1, L->top + | evsplati TISFUNC, LJ_TFUNC + | lus TOBIT, 0x4338 + | evsplati TISTAB, LJ_TTAB + | lwz PC, FRAME_PC(BASE) + | li TMP2, 0 + | evsplati TISSTR, LJ_TSTR + | sub RD, TMP1, BASE + | evmergelo TOBIT, TOBIT, TMP2 + | stb CARG3, L->status + | andi. TMP0, PC, FRAME_TYPE + | li_vmstate INTERP + | addi RD, RD, 8 + | evsplati TISNIL, LJ_TNIL + | mr MULTRES, RD + | st_vmstate + | beq ->BC_RET_Z + | b ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | li PC, FRAME_CP + | stw CARG4, SAVE_ERRF + | b >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | li PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + | lwz TMP1, L:CARG1->cframe + | stw CARG3, SAVE_NRES + | mr L, CARG1 + | stw CARG1, SAVE_L + | mr BASE, CARG2 + | stw sp, L->cframe // Add our C frame to cframe chain. + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | stw TMP1, SAVE_CFRAME + | addi DISPATCH, DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). + | lwz TMP2, L->base // TMP2 = old base (used in vmeta_call). + | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants. + | lwz TMP1, L->top + | evsplati TISFUNC, LJ_TFUNC + | add PC, PC, BASE + | evsplati TISTAB, LJ_TTAB + | lus TOBIT, 0x4338 + | li TMP0, 0 + | sub PC, PC, TMP2 // PC = frame delta + frame type + | evsplati TISSTR, LJ_TSTR + | sub NARGS8:RC, TMP1, BASE + | evmergelo TOBIT, TOBIT, TMP0 + | li_vmstate INTERP + | evsplati TISNIL, LJ_TNIL + | st_vmstate + | + |->vm_call_dispatch: + | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC + | li TMP0, -8 + | evlddx LFUNC:RB, BASE, TMP0 + | checkfunc LFUNC:RB + | checkfail ->vmeta_call + | + |->vm_call_dispatch_f: + | ins_call + | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + | mr L, CARG1 + | lwz TMP0, L:CARG1->stack + | stw CARG1, SAVE_L + | lwz TMP1, L->top + | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. + | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). + | lwz TMP1, L->cframe + | stw sp, L->cframe // Add our C frame to cframe chain. + | li TMP2, 0 + | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. + | stw TMP2, SAVE_ERRF // No error function. + | stw TMP1, SAVE_CFRAME + | mtctr CARG4 + | bctrl // (lua_State *L, lua_CFunction func, void *ud) + | mr. BASE, CRET1 + | lwz DISPATCH, L->glref // Setup pointer to dispatch table. + | li PC, FRAME_CP + | addi DISPATCH, DISPATCH, GG_G2DISP + | bne <3 // Else continue with the call. + | b ->vm_leave_cp // No base? Just remove C frame. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the + |// stack, so BASE doesn't need to be reloaded across these calls. + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8 + | lwz TMP0, -12(BASE) // Continuation. + | mr RB, BASE + | mr BASE, TMP2 // Restore caller BASE. + | lwz LFUNC:TMP1, FRAME_FUNC(TMP2) + | cmplwi TMP0, 0 + | lwz PC, -16(RB) // Restore PC from [cont|PC]. + | beq >1 + | subi TMP2, RD, 8 + | lwz TMP1, LFUNC:TMP1->pc + | evstddx TISNIL, RA, TMP2 // Ensure one valid arg. + | lwz KBASE, PC2PROTO(k)(TMP1) + | // BASE = base, RA = resultptr, RB = meta base + | mtctr TMP0 + | bctr // Jump to continuation. + | + |1: // Tail call from C function. + | subi TMP1, RB, 16 + | sub RC, TMP1, BASE + | b ->vm_call_tail + | + |->cont_cat: // RA = resultptr, RB = meta base + | lwz INS, -4(PC) + | subi CARG2, RB, 16 + | decode_RB8 SAVE0, INS + | evldd TMP0, 0(RA) + | add TMP1, BASE, SAVE0 + | stw BASE, L->base + | cmplw TMP1, CARG2 + | sub CARG3, CARG2, TMP1 + | decode_RA8 RA, INS + | evstdd TMP0, 0(CARG2) + | bne ->BC_CAT_Z + | evstddx TMP0, BASE, RA + | b ->cont_nop + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets1: + | evmergelo STR:RC, TISSTR, STR:RC + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | decode_RB8 RB, INS + | evstdd STR:RC, 0(CARG3) + | add CARG2, BASE, RB + | b >1 + | + |->vmeta_tgets: + | evmergelo TAB:RB, TISTAB, TAB:RB + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo STR:RC, TISSTR, STR:RC + | evstdd TAB:RB, 0(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | evstdd STR:RC, 0(CARG3) + | b >1 + | + |->vmeta_tgetb: // TMP0 = index + | efdcfsi TMP0, TMP0 + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + | evstdd TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tgetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | beq >3 + | evldd TMP0, 0(CRET1) + | evstddx TMP0, BASE, RA + | ins_next + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | subfic TMP1, BASE, FRAME_CONT + | lwz BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 16 // 2 args for func(t, k). + | b ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets1: + | evmergelo STR:RC, TISSTR, STR:RC + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | decode_RB8 RB, INS + | evstdd STR:RC, 0(CARG3) + | add CARG2, BASE, RB + | b >1 + | + |->vmeta_tsets: + | evmergelo TAB:RB, TISTAB, TAB:RB + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo STR:RC, TISSTR, STR:RC + | evstdd TAB:RB, 0(CARG2) + | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH) + | evstdd STR:RC, 0(CARG3) + | b >1 + | + |->vmeta_tsetb: // TMP0 = index + | efdcfsi TMP0, TMP0 + | decode_RB8 RB, INS + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | add CARG2, BASE, RB + | evstdd TMP0, 0(CARG3) + | b >1 + | + |->vmeta_tsetv: + | decode_RB8 RB, INS + | decode_RC8 RC, INS + | add CARG2, BASE, RB + | add CARG3, BASE, RC + |1: + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // Returns TValue * (finished) or NULL (metamethod). + | cmplwi CRET1, 0 + | evlddx TMP0, BASE, RA + | beq >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | evstdd TMP0, 0(CRET1) + | ins_next + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | subfic TMP1, BASE, FRAME_CONT + | lwz BASE, L->top + | stw PC, -16(BASE) // [cont|PC] + | add PC, TMP1, BASE + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | li NARGS8:RC, 24 // 3 args for func(t, k, v) + | evstdd TMP0, 16(BASE) // Copy value to third argument. + | b ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + | mr CARG1, L + | subi PC, PC, 4 + | add CARG2, BASE, RA + | stw PC, SAVE_PC + | add CARG3, BASE, RD + | stw BASE, L->base + | decode_OP1 CARG4, INS + | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // Returns 0/1 or TValue * (metamethod). + |3: + | cmplwi CRET1, 1 + | bgt ->vmeta_binop + |4: + | lwz INS, 0(PC) + | addi PC, PC, 4 + | decode_RD4 TMP2, INS + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | add TMP2, TMP2, TMP3 + | isellt PC, PC, TMP2 + |->cont_nop: + | ins_next + | + |->cont_ra: // RA = resultptr + | lwz INS, -4(PC) + | evldd TMP0, 0(RA) + | decode_RA8 TMP1, INS + | evstddx TMP0, BASE, TMP1 + | b ->cont_nop + | + |->cont_condt: // RA = resultptr + | lwz TMP0, 0(RA) + | li TMP1, LJ_TTRUE + | cmplw TMP1, TMP0 // Branch if result is true. + | b <4 + | + |->cont_condf: // RA = resultptr + | lwz TMP0, 0(RA) + | li TMP1, LJ_TFALSE + | cmplw TMP0, TMP1 // Branch if result is false. + | b <4 + | + |->vmeta_equal: + | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. + | subi PC, PC, 4 + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // Returns 0/1 or TValue * (metamethod). + | b <3 + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vn: + | add CARG3, BASE, RB + | add CARG4, KBASE, RC + | b >1 + | + |->vmeta_arith_nv: + | add CARG3, KBASE, RC + | add CARG4, BASE, RB + | b >1 + | + |->vmeta_unm: + | add CARG3, BASE, RD + | mr CARG4, CARG3 + | b >1 + | + |->vmeta_arith_vv: + | add CARG3, BASE, RB + | add CARG4, BASE, RC + |1: + | add CARG2, BASE, RA + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS. + | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | beq ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 + | sub TMP1, CRET1, BASE + | stw PC, -16(CRET1) // [cont|PC] + | mr TMP2, BASE + | addi PC, TMP1, FRAME_CONT + | mr BASE, CRET1 + | li NARGS8:RC, 16 // 2 args for func(o1, o2). + | b ->vm_call_dispatch + | + |->vmeta_len: +#if LJ_52 + | mr SAVE0, CARG1 +#endif + | add CARG2, BASE, RD + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | bl extern lj_meta_len // (lua_State *L, TValue *o) + | // Returns NULL (retry) or TValue * (metamethod base). +#if LJ_52 + | cmplwi CRET1, 0 + | bne ->vmeta_binop // Binop call for compatibility. + | mr CARG1, SAVE0 + | b ->BC_LEN_Z +#else + | b ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call: // Resolve and call __call metamethod. + | // TMP2 = old base, BASE = new base, RC = nargs*8 + | mr CARG1, L + | stw TMP2, L->base // This is the callers base! + | subi CARG2, BASE, 8 + | stw PC, SAVE_PC + | add CARG3, BASE, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here. + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | ins_call + | + |->vmeta_callt: // Resolve __call for BC_CALLT. + | // BASE = old base, RA = new base, RC = nargs*8 + | mr CARG1, L + | stw BASE, L->base + | subi CARG2, RA, 8 + | stw PC, SAVE_PC + | add CARG3, RA, RC + | mr SAVE0, NARGS8:RC + | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | lwz TMP1, FRAME_PC(BASE) + | addi NARGS8:RC, SAVE0, 8 // Got one more argument now. + | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here. + | b ->BC_CALLT_Z + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mr CARG1, L + | stw BASE, L->base + | mr CARG2, RA + | stw PC, SAVE_PC + | mr SAVE0, INS + | bl extern lj_meta_for // (lua_State *L, TValue *base) + |.if JIT + | decode_OP1 TMP0, SAVE0 + |.endif + | decode_RA8 RA, SAVE0 + |.if JIT + | cmpwi TMP0, BC_JFORI + |.endif + | decode_RD8 RD, SAVE0 + |.if JIT + | beq =>BC_JFORI + |.endif + | b =>BC_FORI + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmplwi NARGS8:RC, 16 + | evldd CARG1, 0(BASE) + | evldd CARG2, 8(BASE) + | blt ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | checknum CARG1 + | checkfail ->fff_fallback + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | evmergehi TMP0, CARG1, CARG2 + | checknum TMP0 + | checkanyfail ->fff_fallback + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1. + |.macro ffgccheck + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | cmplw TMP0, TMP1 + | bgel ->fff_gcstep + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc assert + | cmplwi NARGS8:RC, 8 + | evldd TMP0, 0(BASE) + | blt ->fff_fallback + | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE. + | la RA, -8(BASE) + | evcmpltu cr1, TMP0, TMP1 + | lwz PC, FRAME_PC(BASE) + | bge cr1, ->fff_fallback + | evstdd TMP0, 0(RA) + | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8. + | beq ->fff_res // Done if exactly 1 argument. + | li TMP1, 8 + | subi RC, RC, 8 + |1: + | cmplw TMP1, RC + | evlddx TMP0, BASE, TMP1 + | evstddx TMP0, RA, TMP1 + | addi TMP1, TMP1, 8 + | bne <1 + | b ->fff_res + | + |.ffunc type + | cmplwi NARGS8:RC, 8 + | lwz CARG1, 0(BASE) + | blt ->fff_fallback + | li TMP2, ~LJ_TNUMX + | cmplw CARG1, TISNUM + | not TMP1, CARG1 + | isellt TMP1, TMP2, TMP1 + | slwi TMP1, TMP1, 3 + | la TMP2, CFUNC:RB->upvalue + | evlddx STR:CRET1, TMP2, TMP1 + | b ->fff_restv + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | checktab CARG1 + | evmergehi TMP1, CARG1, CARG1 + | checkfail >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:RB, TAB:CARG1->metatable + |2: + | evmr CRET1, TISNIL + | cmplwi TAB:RB, 0 + | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH) + | beq ->fff_restv + | lwz TMP0, TAB:RB->hmask + | evmergelo CRET1, TISTAB, TAB:RB // Use metatable as default result. + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |3: // Rearranged logic, because we expect _not_ to find the key. + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | lwz NODE:TMP2, NODE:TMP2->next + | checkallok >5 + | cmplwi NODE:TMP2, 0 + | beq ->fff_restv // Not found, keep default result. + | b <3 + |5: + | checknil TMP1 + | checkok ->fff_restv // Ditto for nil value. + | evmr CRET1, TMP1 // Return value of mt.__metatable. + | b ->fff_restv + | + |6: + | cmpwi TMP1, LJ_TUDATA + | not TMP1, TMP1 + | beq <1 + | checknum CARG1 + | slwi TMP1, TMP1, 2 + | li TMP2, 4*~LJ_TNUMX + | isellt TMP1, TMP2, TMP1 + | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH) + | lwzx TAB:RB, TMP2, TMP1 + | b <2 + | + |.ffunc_2 setmetatable + | // Fast path: no mt for table yet and not clearing the mt. + | evmergehi TMP0, TAB:CARG1, TAB:CARG2 + | checktab TMP0 + | checkanyfail ->fff_fallback + | lwz TAB:TMP1, TAB:CARG1->metatable + | cmplwi TAB:TMP1, 0 + | lbz TMP3, TAB:CARG1->marked + | bne ->fff_fallback + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | stw TAB:CARG2, TAB:CARG1->metatable + | beq ->fff_restv + | barrierback TAB:CARG1, TMP3, TMP0 + | b ->fff_restv + | + |.ffunc rawget + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checktab CARG2 + | la CARG3, 8(BASE) + | checkfail ->fff_fallback + | mr CARG1, L + | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // Returns cTValue *. + | evldd CRET1, 0(CRET1) + | b ->fff_restv + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | bne ->fff_fallback // Exactly one argument. + | checknum CARG1 + | checkok ->fff_restv + | b ->fff_fallback + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | checkstr CARG1 + | // A __tostring method in the string base metatable is ignored. + | checkok ->fff_restv // String key? + | // Handle numbers inline, unless a number base metatable is present. + | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH) + | checknum CARG1 + | cmplwi cr1, TMP0, 0 + | stw BASE, L->base // Add frame since C call can throw. + | crand 4*cr0+eq, 4*cr0+lt, 4*cr1+eq + | stw PC, SAVE_PC // Redundant (but a defined value). + | bne ->fff_fallback + | ffgccheck + | mr CARG1, L + | mr CARG2, BASE + | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) + | // Returns GCstr *. + | evmergelo STR:CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc next + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | evstddx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + | checktab TAB:CARG2 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback + | stw BASE, L->base // Add frame since C call can throw. + | mr CARG1, L + | stw BASE, L->top // Dummy frame length is ok. + | la CARG3, 8(BASE) + | stw PC, SAVE_PC + | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Returns 0 at end of traversal. + | cmplwi CRET1, 0 + | evmr CRET1, TISNIL + | beq ->fff_restv // End of traversal: return nil. + | evldd TMP0, 8(BASE) // Copy key and value to results. + | la RA, -8(BASE) + | evldd TMP1, 16(BASE) + | evstdd TMP0, 0(RA) + | li RD, (2+1)*8 + | evstdd TMP1, 8(RA) + | b ->fff_res + | + |.ffunc_1 pairs + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | evstdd TISNIL, 8(BASE) + | li RD, (3+1)*8 + | evstdd CFUNC:TMP0, 0(RA) + | b ->fff_res + | + |.ffunc_2 ipairs_aux + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback + | checknum CARG2 + | lus TMP3, 0x3ff0 + | checkfail ->fff_fallback + | efdctsi TMP2, CARG2 + | lwz TMP0, TAB:CARG1->asize + | evmergelo TMP3, TMP3, ZERO + | lwz TMP1, TAB:CARG1->array + | efdadd CARG2, CARG2, TMP3 + | addi TMP2, TMP2, 1 + | la RA, -8(BASE) + | cmplw TMP0, TMP2 + | slwi TMP3, TMP2, 3 + | evstdd CARG2, 0(RA) + | ble >2 // Not in array part? + | evlddx TMP1, TMP1, TMP3 + |1: + | checknil TMP1 + | li RD, (0+1)*8 + | checkok ->fff_res // End of iteration, return 0 results. + | li RD, (2+1)*8 + | evstdd TMP1, 8(RA) + | b ->fff_res + |2: // Check for empty hash part first. Otherwise call C function. + | lwz TMP0, TAB:CARG1->hmask + | cmplwi TMP0, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | mr CARG2, TMP2 + | bl extern lj_tab_getinth // (GCtab *t, int32_t key) + | // Returns cTValue * or NULL. + | cmplwi CRET1, 0 + | li RD, (0+1)*8 + | beq ->fff_res + | evldd TMP1, 0(CRET1) + | b <1 + | + |.ffunc_1 ipairs + | checktab TAB:CARG1 + | lwz PC, FRAME_PC(BASE) + | checkfail ->fff_fallback +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | cmplwi TAB:TMP2, 0 + | la RA, -8(BASE) + | bne ->fff_fallback +#else + | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0] + | la RA, -8(BASE) +#endif + | evsplati TMP1, 0 + | li RD, (3+1)*8 + | evstdd TMP1, 8(BASE) + | evstdd CFUNC:TMP0, 0(RA) + | b ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc pcall + | cmplwi NARGS8:RC, 8 + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | blt ->fff_fallback + | mr TMP2, BASE + | la BASE, 8(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | subi NARGS8:RC, NARGS8:RC, 8 + | addi PC, TMP3, 8+FRAME_PCALL + | b ->vm_call_dispatch + | + |.ffunc_2 xpcall + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | mr TMP2, BASE + | checkfunc CARG2 // Traceback must be a function. + | checkfail ->fff_fallback + | la BASE, 16(BASE) + | // Remember active hook before pcall. + | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31 + | evstdd CARG2, 0(TMP2) // Swap function and traceback. + | subi NARGS8:RC, NARGS8:RC, 16 + | evstdd CARG1, 8(TMP2) + | addi PC, TMP3, 16+FRAME_PCALL + | b ->vm_call_dispatch + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | evmergehi TMP0, L:CARG1, L:CARG1 + |.else + |.ffunc coroutine_wrap_aux + | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr + |.endif + |.if resume + | cmpwi TMP0, LJ_TTHREAD + | bne ->fff_fallback + |.endif + | lbz TMP0, L:CARG1->status + | lwz TMP1, L:CARG1->cframe + | lwz CARG2, L:CARG1->top + | cmplwi cr0, TMP0, LUA_YIELD + | lwz TMP2, L:CARG1->base + | cmplwi cr1, TMP1, 0 + | lwz TMP0, L:CARG1->maxstack + | cmplw cr7, CARG2, TMP2 + | lwz PC, FRAME_PC(BASE) + | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0 + | add TMP2, CARG2, NARGS8:RC + | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD + | cmplw cr1, TMP2, TMP0 + | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt + | stw PC, SAVE_PC + | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov + | stw BASE, L->base + | blt cr6, ->fff_fallback + |1: + |.if resume + | addi BASE, BASE, 8 // Keep resumed thread in stack for GC. + | subi NARGS8:RC, NARGS8:RC, 8 + | subi TMP2, TMP2, 8 + |.endif + | stw TMP2, L:CARG1->top + | li TMP1, 0 + | stw BASE, L->top + |2: // Move args to coroutine. + | cmpw TMP1, NARGS8:RC + | evlddx TMP0, BASE, TMP1 + | beq >3 + | evstddx TMP0, CARG2, TMP1 + | addi TMP1, TMP1, 8 + | b <2 + |3: + | li CARG3, 0 + | mr L:SAVE0, L:CARG1 + | li CARG4, 0 + | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | // Returns thread status. + |4: + | lwz TMP2, L:SAVE0->base + | cmplwi CRET1, LUA_YIELD + | lwz TMP3, L:SAVE0->top + | li_vmstate INTERP + | lwz BASE, L->base + | st_vmstate + | bgt >8 + | sub RD, TMP3, TMP2 + | lwz TMP0, L->maxstack + | cmplwi RD, 0 + | add TMP1, BASE, RD + | beq >6 // No results? + | cmplw TMP1, TMP0 + | li TMP1, 0 + | bgt >9 // Need to grow stack? + | + | subi TMP3, RD, 8 + | stw TMP2, L:SAVE0->top // Clear coroutine stack. + |5: // Move results from coroutine. + | cmplw TMP1, TMP3 + | evlddx TMP0, TMP2, TMP1 + | evstddx TMP0, BASE, TMP1 + | addi TMP1, TMP1, 8 + | bne <5 + |6: + | andi. TMP0, PC, FRAME_TYPE + |.if resume + | li TMP1, LJ_TTRUE + | la RA, -8(BASE) + | stw TMP1, -8(BASE) // Prepend true to results. + | addi RD, RD, 16 + |.else + | mr RA, BASE + | addi RD, RD, 8 + |.endif + |7: + | stw PC, SAVE_PC + | mr MULTRES, RD + | beq ->BC_RET_Z + | b ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | andi. TMP0, PC, FRAME_TYPE + | la TMP3, -8(TMP3) + | li TMP1, LJ_TFALSE + | evldd TMP0, 0(TMP3) + | stw TMP3, L:SAVE0->top // Remove error from coroutine stack. + | li RD, (2+1)*8 + | stw TMP1, -8(BASE) // Prepend false to results. + | la RA, -8(BASE) + | evstdd TMP0, 0(BASE) // Copy error message. + | b <7 + |.else + | mr CARG1, L + | mr CARG2, L:SAVE0 + | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) + |.endif + | + |9: // Handle stack expansion on return from yield. + | mr CARG1, L + | srwi CARG2, RD, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | li CRET1, 0 + | b <4 + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | lwz TMP0, L->cframe + | add TMP1, BASE, NARGS8:RC + | stw BASE, L->base + | andi. TMP0, TMP0, CFRAME_RESUME + | stw TMP1, L->top + | li CRET1, LUA_YIELD + | beq ->fff_fallback + | stw ZERO, L->cframe + | stb CRET1, L->status + | b ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.ffunc_n math_abs + | efdabs CRET1, CARG1 + | // Fallthrough. + | + |->fff_restv: + | // CRET1 = TValue result. + | lwz PC, FRAME_PC(BASE) + | la RA, -8(BASE) + | evstdd CRET1, 0(RA) + |->fff_res1: + | // RA = results, PC = return. + | li RD, (1+1)*8 + |->fff_res: + | // RA = results, RD = (nresults+1)*8, PC = return. + | andi. TMP0, PC, FRAME_TYPE + | mr MULTRES, RD + | bne ->vm_return + | lwz INS, -4(PC) + | decode_RB8 RB, INS + |5: + | cmplw RB, RD // More results expected? + | decode_RA8 TMP0, INS + | bgt >6 + | ins_next1 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | sub BASE, RA, TMP0 + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, RA, TMP1 + | b <5 + | + |.macro math_extern, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | bl extern func@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + |.endmacro + | + |.macro math_extern2, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | evldd CARG4, 8(BASE) + | blt ->fff_fallback + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | evmergehi CARG3, CARG4, CARG4 + | checkanyfail ->fff_fallback + | bl extern func@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + |.endmacro + | + |.macro math_round, func + | .ffunc math_ .. func + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | lwz PC, FRAME_PC(BASE) + | bl ->vm_..func.._hilo; + | la RA, -8(BASE) + | evstdd CRET2, 0(RA) + | b ->fff_res1 + |.endmacro + | + | math_round floor + | math_round ceil + | + | math_extern sqrt + | + |.ffunc math_log + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | bl extern log@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + | + | math_extern log10 + | math_extern exp + | math_extern sin + | math_extern cos + | math_extern tan + | math_extern asin + | math_extern acos + | math_extern atan + | math_extern sinh + | math_extern cosh + | math_extern tanh + | math_extern2 pow + | math_extern2 atan2 + | math_extern2 fmod + | + |->ff_math_deg: + |.ffunc_n math_rad + | evldd CARG2, CFUNC:RB->upvalue[0] + | efdmul CRET1, CARG1, CARG2 + | b ->fff_restv + | + |.ffunc math_ldexp + | cmplwi NARGS8:RC, 16 + | evldd CARG2, 0(BASE) + | evldd CARG4, 8(BASE) + | blt ->fff_fallback + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | checkanyfail ->fff_fallback + | efdctsi CARG3, CARG4 + | bl extern ldexp@plt + | evmergelo CRET1, CRET1, CRET2 + | b ->fff_restv + | + |.ffunc math_frexp + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | lwz PC, FRAME_PC(BASE) + | bl extern frexp@plt + | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH) + | evmergelo CRET1, CRET1, CRET2 + | efdcfsi CRET2, TMP1 + | la RA, -8(BASE) + | evstdd CRET1, 0(RA) + | li RD, (2+1)*8 + | evstdd CRET2, 8(RA) + | b ->fff_res + | + |.ffunc math_modf + | cmplwi NARGS8:RC, 8 + | evldd CARG2, 0(BASE) + | blt ->fff_fallback + | checknum CARG2 + | evmergehi CARG1, CARG2, CARG2 + | checkfail ->fff_fallback + | la CARG3, -8(BASE) + | lwz PC, FRAME_PC(BASE) + | bl extern modf@plt + | evmergelo CRET1, CRET1, CRET2 + | la RA, -8(BASE) + | evstdd CRET1, 0(BASE) + | li RD, (2+1)*8 + | b ->fff_res + | + |.macro math_minmax, name, cmpop + | .ffunc_1 name + | checknum CARG1 + | li TMP1, 8 + | checkfail ->fff_fallback + |1: + | evlddx CARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_restv // Ok, since CRET1 = CARG1. + | checkfail ->fff_fallback + | cmpop CARG2, CARG1 + | addi TMP1, TMP1, 8 + | crmove 4*cr0+lt, 4*cr0+gt + | evsel CARG1, CARG2, CARG1 + | b <1 + |.endmacro + | + | math_minmax math_min, efdtstlt + | math_minmax math_max, efdtstgt + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | checkstr STR:CARG1 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmplwi NARGS8:RC, 8 + | evldd STR:CARG1, 0(BASE) + | bne ->fff_fallback // Need exactly 1 argument. + | checkstr STR:CARG1 + | la RA, -8(BASE) + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | li RD, (0+1)*8 + | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end). + | li TMP2, (1+1)*8 + | cmplwi TMP0, 0 + | lwz PC, FRAME_PC(BASE) + | efdcfsi CRET1, TMP1 + | iseleq RD, RD, TMP2 + | evstdd CRET1, 0(RA) + | b ->fff_res + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | bne ->fff_fallback // Exactly 1 argument. + | checknum CARG1 + | la CARG2, DISPATCH_GL(tmptv)(DISPATCH) + | checkfail ->fff_fallback + | efdctsiz TMP0, CARG1 + | li CARG3, 1 + | cmplwi TMP0, 255 + | stb TMP0, 0(CARG2) + | bgt ->fff_fallback + |->fff_newstr: + | mr CARG1, L + | stw BASE, L->base + | stw PC, SAVE_PC + | bl extern lj_str_new // (lua_State *L, char *str, size_t l) + | // Returns GCstr *. + | lwz BASE, L->base + | evmergelo STR:CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |.ffunc string_sub + | ffgccheck + | cmplwi NARGS8:RC, 16 + | evldd CARG3, 16(BASE) + | evldd STR:CARG1, 0(BASE) + | blt ->fff_fallback + | evldd CARG2, 8(BASE) + | li TMP2, -1 + | beq >1 + | checknum CARG3 + | checkfail ->fff_fallback + | efdctsiz TMP2, CARG3 + |1: + | checknum CARG2 + | checkfail ->fff_fallback + | checkstr STR:CARG1 + | efdctsiz TMP1, CARG2 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | cmplw TMP0, TMP2 // len < end? (unsigned compare) + | add TMP3, TMP2, TMP0 + | blt >5 + |2: + | cmpwi TMP1, 0 // start <= 0? + | add TMP3, TMP1, TMP0 + | ble >7 + |3: + | sub. CARG3, TMP2, TMP1 + | addi CARG2, STR:CARG1, #STR-1 + | addi CARG3, CARG3, 1 + | add CARG2, CARG2, TMP1 + | isellt CARG3, r0, CARG3 + | b ->fff_newstr + | + |5: // Negative end or overflow. + | cmpw TMP0, TMP2 + | addi TMP3, TMP3, 1 + | iselgt TMP2, TMP3, TMP0 // end = end > len ? len : end+len+1 + | b <2 + | + |7: // Negative start or underflow. + | cmpwi cr1, TMP3, 0 + | iseleq TMP1, r0, TMP3 + | isel TMP1, r0, TMP1, 4*cr1+lt + | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) + | b <3 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmplwi NARGS8:RC, 16 + | evldd CARG1, 0(BASE) + | evldd CARG2, 8(BASE) + | bne ->fff_fallback // Exactly 2 arguments. + | checknum CARG2 + | checkfail ->fff_fallback + | checkstr STR:CARG1 + | efdctsiz CARG3, CARG2 + | checkfail ->fff_fallback + | lwz TMP0, STR:CARG1->len + | cmpwi CARG3, 0 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | ble >2 // Count <= 0? (or non-int) + | cmplwi TMP0, 1 + | subi TMP2, CARG3, 1 + | blt >2 // Zero length string? + | cmplw cr1, TMP1, CARG3 + | bne ->fff_fallback // Fallback for > 1-char strings. + | lbz TMP0, STR:CARG1[1] + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | blt cr1, ->fff_fallback + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | cmplwi TMP2, 0 + | stbx TMP0, CARG2, TMP2 + | subi TMP2, TMP2, 1 + | bne <1 + | b ->fff_newstr + |2: // Return empty string. + | la STR:CRET1, DISPATCH_GL(strempty)(DISPATCH) + | evmergelo CRET1, TISSTR, STR:CRET1 + | b ->fff_restv + | + |.ffunc string_reverse + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + | checkstr STR:CARG1 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | checkfail ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | li TMP2, 0 + | cmplw TMP1, CARG3 + | subi TMP3, CARG3, 1 + | blt ->fff_fallback + |1: // Reverse string copy. + | cmpwi TMP3, 0 + | lbzx TMP1, CARG1, TMP2 + | blt ->fff_newstr + | stbx TMP1, CARG2, TMP3 + | subi TMP3, TMP3, 1 + | addi TMP2, TMP2, 1 + | b <1 + | + |.macro ffstring_case, name, lo + | .ffunc name + | ffgccheck + | cmplwi NARGS8:RC, 8 + | evldd CARG1, 0(BASE) + | blt ->fff_fallback + | checkstr STR:CARG1 + | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) + | checkfail ->fff_fallback + | lwz CARG3, STR:CARG1->len + | la CARG1, #STR(STR:CARG1) + | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) + | cmplw TMP1, CARG3 + | li TMP2, 0 + | blt ->fff_fallback + |1: // ASCII case conversion. + | cmplw TMP2, CARG3 + | lbzx TMP1, CARG1, TMP2 + | bge ->fff_newstr + | subi TMP0, TMP1, lo + | xori TMP3, TMP1, 0x20 + | cmplwi TMP0, 26 + | isellt TMP1, TMP3, TMP1 + | stbx TMP1, CARG2, TMP2 + | addi TMP2, TMP2, 1 + | b <1 + |.endmacro + | + |ffstring_case string_lower, 65 + |ffstring_case string_upper, 97 + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | checktab CARG1 + | checkfail ->fff_fallback + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | efdcfsi CRET1, CRET1 + | b ->fff_restv + | + |//-- Bit library -------------------------------------------------------- + | + |.macro .ffunc_bit, name + | .ffunc_n bit_..name + | efdadd CARG1, CARG1, TOBIT + |.endmacro + | + |.ffunc_bit tobit + |->fff_resbit: + | efdcfsi CRET1, CARG1 + | b ->fff_restv + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name + | li TMP1, 8 + |1: + | evlddx CARG2, BASE, TMP1 + | cmplw cr1, TMP1, NARGS8:RC + | checknum CARG2 + | bge cr1, ->fff_resbit + | checkfail ->fff_fallback + | efdadd CARG2, CARG2, TOBIT + | ins CARG1, CARG1, CARG2 + | addi TMP1, TMP1, 8 + | b <1 + |.endmacro + | + |.ffunc_bit_op band, and + |.ffunc_bit_op bor, or + |.ffunc_bit_op bxor, xor + | + |.ffunc_bit bswap + | rotlwi TMP0, CARG1, 8 + | rlwimi TMP0, CARG1, 24, 0, 7 + | rlwimi TMP0, CARG1, 24, 16, 23 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.ffunc_bit bnot + | not TMP0, CARG1 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + | + |.macro .ffunc_bit_sh, name, ins, shmod + | .ffunc_nn bit_..name + | efdadd CARG2, CARG2, TOBIT + | efdadd CARG1, CARG1, TOBIT + |.if shmod == 1 + | rlwinm CARG2, CARG2, 0, 27, 31 + |.elif shmod == 2 + | neg CARG2, CARG2 + |.endif + | ins TMP0, CARG1, CARG2 + | efdcfsi CRET1, TMP0 + | b ->fff_restv + |.endmacro + | + |.ffunc_bit_sh lshift, slw, 1 + |.ffunc_bit_sh rshift, srw, 1 + |.ffunc_bit_sh arshift, sraw, 1 + |.ffunc_bit_sh rol, rotlw, 0 + |.ffunc_bit_sh ror, rotlw, 2 + | + |//----------------------------------------------------------------------- + | + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RB = CFUNC, RC = nargs*8 + | lwz TMP3, CFUNC:RB->f + | add TMP1, BASE, NARGS8:RC + | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC. + | addi TMP0, TMP1, 8*LUA_MINSTACK + | lwz TMP2, L->maxstack + | stw PC, SAVE_PC // Redundant (but a defined value). + | cmplw TMP0, TMP2 + | stw BASE, L->base + | stw TMP1, L->top + | mr CARG1, L + | bgt >5 // Need to grow stack. + | mtctr TMP3 + | bctrl // (lua_State *L) + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | lwz BASE, L->base + | cmpwi CRET1, 0 + | slwi RD, CRET1, 3 + | la RA, -8(BASE) + | bgt ->fff_res // Returned nresults+1? + |1: // Returned 0 or -1: retry fast path. + | lwz TMP0, L->top + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | sub NARGS8:RC, TMP0, BASE + | bne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | andi. TMP0, PC, FRAME_TYPE + | rlwinm TMP1, PC, 0, 0, 28 + | bne >3 + | lwz INS, -4(PC) + | decode_RA8 TMP1, INS + | addi TMP1, TMP1, 8 + |3: + | sub TMP2, BASE, TMP1 + | b ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | li CARG2, LUA_MINSTACK + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry. + | b <1 + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RC = nargs*8 + | mflr SAVE0 + | stw BASE, L->base + | add TMP0, BASE, NARGS8:RC + | stw PC, SAVE_PC // Redundant (but a defined value). + | stw TMP0, L->top + | mr CARG1, L + | bl extern lj_gc_step // (lua_State *L) + | lwz BASE, L->base + | mtlr SAVE0 + | lwz TMP0, L->top + | sub NARGS8:RC, TMP0, BASE + | lwz CFUNC:RB, FRAME_FUNC(BASE) + | blr + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | NYI + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | beq >1 + |5: // Re-dispatch to static ins. + | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OP4 TMP1, INS. + | lwzx TMP0, DISPATCH, TMP1 + | mtctr TMP0 + | bctr + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) + | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active? + | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0 + | bne <5 + | + | cmpwi cr1, TMP0, 0 + | addic. TMP2, TMP2, -1 + | beq cr1, <5 + | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) + | beq >1 + | bge cr1, <5 + |1: + | mr CARG1, L + | stw MULTRES, SAVE_MULTRES + | mr CARG2, PC + | stw BASE, L->base + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) + |3: + | lwz BASE, L->base + |4: // Re-dispatch to static ins. + | lwz INS, -4(PC) + | decode_OP4 TMP1, INS + | decode_RB8 RB, INS + | addi TMP1, TMP1, GG_DISP2STATIC + | decode_RD8 RD, INS + | lwzx TMP0, DISPATCH, TMP1 + | decode_RA8 RA, INS + | decode_RC8 RC, INS + | mtctr TMP0 + | bctr + | + |->cont_hook: // Continue from hook yield. + | addi PC, PC, 4 + | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins. + | b <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | NYI + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mr CARG2, PC + |.if JIT + | b >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | ori CARG2, PC, 1 + |1: + |.endif + | add TMP0, BASE, RC + | stw PC, SAVE_PC + | mr CARG1, L + | stw BASE, L->base + | sub RA, RA, BASE + | stw TMP0, L->top + | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) + | // Returns ASMFunction. + | lwz BASE, L->base + | lwz TMP0, L->top + | stw ZERO, SAVE_PC // Invalidate for subsequent line hook. + | sub NARGS8:RC, TMP0, BASE + | add RA, BASE, RA + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | mtctr CRET1 + | bctr + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_exit_handler: + |.if JIT + | NYI + |.endif + |->vm_exit_interp: + |.if JIT + | NYI + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called by math.floor/math.ceil fast functions + |// and from JIT code. + |// + |// This can be inlined if the CPU has the frin/friz/frip/frim instructions. + |// The alternative hard-float approaches have a deep dependency chain. + |// The resulting latency is at least 3x-7x the double-precision FP latency + |// (e500v2: 6cy, e600: 5cy, Cell: 10cy) or around 20-70 cycles. + |// + |// The soft-float approach is tedious, but much faster (e500v2: ~11cy/~6cy). + |// However it relies on a fast way to transfer the FP value to GPRs + |// (e500v2: 0cy for lo-word, 1cy for hi-word). + |// + |.macro vm_round, name, mode + | // Used temporaries: TMP0, TMP1, TMP2, TMP3. + |->name.._efd: // Input: CARG2, output: CRET2 + | evmergehi CARG1, CARG2, CARG2 + |->name.._hilo: + | // Input: CARG1 (hi), CARG2 (hi, lo), output: CRET2 + | rlwinm TMP2, CARG1, 12, 21, 31 + | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023 + | li TMP1, -1 + | cmplwi cr1, TMP2, 51 // 0 <= exp <= 51? + | subfic TMP0, TMP2, 52 + | bgt cr1, >1 + | lus TMP3, 0xfff0 + | slw TMP0, TMP1, TMP0 // lomask = -1 << (52-exp) + | sraw TMP1, TMP3, TMP2 // himask = (int32_t)0xfff00000 >> exp + |.if mode == 2 // trunc(x): + | evmergelo TMP0, TMP1, TMP0 + | evand CRET2, CARG2, TMP0 // hi &= himask, lo &= lomask + |.else + | andc TMP2, CARG2, TMP0 + | andc TMP3, CARG1, TMP1 + | or TMP2, TMP2, TMP3 // ztest = (hi&~himask) | (lo&~lomask) + | srawi TMP3, CARG1, 31 // signmask = (int32_t)hi >> 31 + |.if mode == 0 // floor(x): + | and. TMP2, TMP2, TMP3 // iszero = ((ztest & signmask) == 0) + |.else // ceil(x): + | andc. TMP2, TMP2, TMP3 // iszero = ((ztest & ~signmask) == 0) + |.endif + | and CARG2, CARG2, TMP0 // lo &= lomask + | and CARG1, CARG1, TMP1 // hi &= himask + | subc TMP0, CARG2, TMP0 + | iseleq TMP0, CARG2, TMP0 // lo = iszero ? lo : lo-lomask + | sube TMP1, CARG1, TMP1 + | iseleq TMP1, CARG1, TMP1 // hi = iszero ? hi : hi-himask+carry + | evmergelo CRET2, TMP1, TMP0 + |.endif + | blr + |1: + | bgtlr // Already done if >=2^52, +-inf or nan. + |.if mode == 2 // trunc(x): + | rlwinm TMP1, CARG1, 0, 0, 0 // hi = sign(x) + | li TMP0, 0 + | evmergelo CRET2, TMP1, TMP0 + |.else + | rlwinm TMP2, CARG1, 0, 1, 31 + | srawi TMP0, CARG1, 31 // signmask = (int32_t)hi >> 31 + | or TMP2, TMP2, CARG2 // ztest = abs(hi) | lo + | lus TMP1, 0x3ff0 + |.if mode == 0 // floor(x): + | and. TMP2, TMP2, TMP0 // iszero = ((ztest & signmask) == 0) + |.else // ceil(x): + | andc. TMP2, TMP2, TMP0 // iszero = ((ztest & ~signmask) == 0) + |.endif + | li TMP0, 0 + | iseleq TMP1, r0, TMP1 + | rlwimi CARG1, TMP1, 0, 1, 31 // hi = sign(x) | (iszero ? 0.0 : 1.0) + | evmergelo CRET2, CARG1, TMP0 + |.endif + | blr + |.endmacro + | + |->vm_floor: + | mflr CARG3 + | evmergelo CARG2, CARG1, CARG2 + | bl ->vm_floor_hilo + | mtlr CARG3 + | evmergehi CRET1, CRET2, CRET2 + | blr + | + | vm_round vm_floor, 0 + | vm_round vm_ceil, 1 + |.if JIT + | vm_round vm_trunc, 2 + |.else + |->vm_trunc_efd: + |->vm_trunc_hilo: + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_ffi_call: + |.if FFI + | NYI + |.endif + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1*8, RD = src2*8, JMP with RD = target + | evlddx TMP0, BASE, RA + | addi PC, PC, 4 + | evlddx TMP1, BASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz TMP2, -4(PC) + | evmergehi RB, TMP0, TMP1 + | decode_RD4 TMP2, TMP2 + | checknum RB + | add TMP2, TMP2, TMP3 + | checkanyfail ->vmeta_comp + | efdcmplt TMP0, TMP1 + if (op == BC_ISLE || op == BC_ISGT) { + | efdcmpeq cr1, TMP0, TMP1 + | cror 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + } + if (op == BC_ISLT || op == BC_ISLE) { + | iselgt PC, TMP2, PC + } else { + | iselgt PC, PC, TMP2 + } + | ins_next + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | // RA = src1*8, RD = src2*8, JMP with RD = target + | evlddx CARG2, BASE, RA + | addi PC, PC, 4 + | evlddx CARG3, BASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz TMP2, -4(PC) + | evmergehi RB, CARG2, CARG3 + | decode_RD4 TMP2, TMP2 + | checknum RB + | add TMP2, TMP2, TMP3 + | checkanyfail >5 + | efdcmpeq CARG2, CARG3 + if (vk) { + | iselgt PC, TMP2, PC + } else { + | iselgt PC, PC, TMP2 + } + |1: + | ins_next + | + |5: // Either or both types are not numbers. + | evcmpeq CARG2, CARG3 + | not TMP3, RB + | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive? + | crorc 4*cr7+lt, 4*cr0+so, 4*cr0+lt // 1: Same tv or different type. + | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata? + | crandc 4*cr7+gt, 4*cr0+lt, 4*cr1+gt // 2: Same type and primitive. + | mr SAVE0, PC + if (vk) { + | isel PC, TMP2, PC, 4*cr7+gt + } else { + | isel TMP2, PC, TMP2, 4*cr7+gt + } + | cror 4*cr7+lt, 4*cr7+lt, 4*cr7+gt // 1 or 2. + if (vk) { + | isel PC, TMP2, PC, 4*cr0+so + } else { + | isel PC, PC, TMP2, 4*cr0+so + } + | blt cr7, <1 // Done if 1 or 2. + | blt cr6, <1 // Done if not tab/ud. + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | lwz TAB:TMP2, TAB:CARG2->metatable + | li CARG4, 1-vk // ne = 0 or 1. + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable? + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_equal // Handle __eq metamethod. + break; + + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | // RA = src*8, RD = str_const*8 (~), JMP with RD = target + | evlddx TMP0, BASE, RA + | srwi RD, RD, 1 + | lwz INS, 0(PC) + | subfic RD, RD, -4 + | addi PC, PC, 4 + | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | evmergelo STR:TMP1, TISSTR, STR:TMP1 + | add TMP2, TMP2, TMP3 + | evcmpeq TMP0, STR:TMP1 + if (vk) { + | isel PC, TMP2, PC, 4*cr0+so + } else { + | isel PC, PC, TMP2, 4*cr0+so + } + | ins_next + break; + + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | // RA = src*8, RD = num_const*8, JMP with RD = target + | evlddx TMP0, BASE, RA + | addi PC, PC, 4 + | evlddx TMP1, KBASE, RD + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | lwz INS, -4(PC) + | checknum TMP0 + | checkfail >5 + | efdcmpeq TMP0, TMP1 + |1: + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (vk) { + | iselgt PC, TMP2, PC + |5: + } else { + | iselgt PC, PC, TMP2 + } + |3: + | ins_next + if (!vk) { + |5: + | decode_RD4 TMP2, INS + | add PC, TMP2, TMP3 + | b <3 + } + break; + + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target + | lwzx TMP0, BASE, RA + | srwi TMP1, RD, 3 + | lwz INS, 0(PC) + | addi PC, PC, 4 + | not TMP1, TMP1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | cmplw TMP0, TMP1 + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (vk) { + | iseleq PC, TMP2, PC + } else { + | iseleq PC, PC, TMP2 + } + | ins_next + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | // RA = dst*8 or unused, RD = src*8, JMP with RD = target + | evlddx TMP0, BASE, RD + | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE. + | lwz INS, 0(PC) + | evcmpltu TMP0, TMP1 + | addi PC, PC, 4 + if (op == BC_IST || op == BC_ISF) { + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | add TMP2, TMP2, TMP3 + if (op == BC_IST) { + | isellt PC, TMP2, PC + } else { + | isellt PC, PC, TMP2 + } + } else { + if (op == BC_ISTC) { + | checkfail >1 + } else { + | checkok >1 + } + | addis PC, PC, -(BCBIAS_J*4 >> 16) + | decode_RD4 TMP2, INS + | evstddx TMP0, BASE, RA + | add PC, PC, TMP2 + |1: + } + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | // RA = dst*8, RD = src*8 + | ins_next1 + | evlddx TMP0, BASE, RD + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_NOT: + | // RA = dst*8, RD = src*8 + | ins_next1 + | lwzx TMP0, BASE, RD + | subfic TMP1, TMP0, LJ_TTRUE + | adde TMP0, TMP0, TMP1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_UNM: + | // RA = dst*8, RD = src*8 + | evlddx TMP0, BASE, RD + | checknum TMP0 + | checkfail ->vmeta_unm + | efdneg TMP0, TMP0 + | ins_next1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_LEN: + | // RA = dst*8, RD = src*8 + | evlddx CARG1, BASE, RD + | checkstr CARG1 + | checkfail >2 + | lwz CRET1, STR:CARG1->len + |1: + | ins_next1 + | efdcfsi TMP0, CRET1 + | evstddx TMP0, BASE, RA + | ins_next2 + |2: + | checktab CARG1 + | checkfail ->vmeta_len +#if LJ_52 + | lwz TAB:TMP2, TAB:CARG1->metatable + | cmplwi TAB:TMP2, 0 + | bne >9 + |3: +#endif + |->BC_LEN_Z: + | bl extern lj_tab_len // (GCtab *t) + | // Returns uint32_t (but less than 2^31). + | b <1 +#if LJ_52 + |9: + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_len +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre, t0, t1 + | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | evlddx t0, BASE, RB + | checknum t0 + | evlddx t1, KBASE, RC + | checkfail ->vmeta_arith_vn + || break; + ||case 1: + | evlddx t1, BASE, RB + | checknum t1 + | evlddx t0, KBASE, RC + | checkfail ->vmeta_arith_nv + || break; + ||default: + | evlddx t0, BASE, RB + | evlddx t1, BASE, RC + | evmergehi TMP2, t0, t1 + | checknum TMP2 + | checkanyfail ->vmeta_arith_vv + || break; + ||} + |.endmacro + | + |.macro ins_arith, ins + | ins_arithpre TMP0, TMP1 + | ins_next1 + | ins TMP0, TMP0, TMP1 + | evstddx TMP0, BASE, RA + | ins_next2 + |.endmacro + + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith efdadd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith efdsub + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith efdmul + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith efddiv + break; + case BC_MODVN: + | ins_arithpre RD, SAVE0 + |->BC_MODVN_Z: + | efddiv CARG2, RD, SAVE0 + | bl ->vm_floor_efd // floor(b/c) + | efdmul TMP0, CRET2, SAVE0 + | ins_next1 + | efdsub TMP0, RD, TMP0 // b - floor(b/c)*c + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_MODNV: case BC_MODVV: + | ins_arithpre RD, SAVE0 + | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + break; + case BC_POW: + | evlddx CARG2, BASE, RB + | evlddx CARG4, BASE, RC + | evmergehi CARG1, CARG4, CARG2 + | checknum CARG1 + | evmergehi CARG3, CARG4, CARG4 + | checkanyfail ->vmeta_arith_vv + | bl extern pow@plt + | evmergelo CRET2, CRET1, CRET2 + | evstddx CRET2, BASE, RA + | ins_next + break; + + case BC_CAT: + | // RA = dst*8, RB = src_start*8, RC = src_end*8 + | sub CARG3, RC, RB + | stw BASE, L->base + | add CARG2, BASE, RC + | mr SAVE0, RB + |->BC_CAT_Z: + | stw PC, SAVE_PC + | mr CARG1, L + | srwi CARG3, CARG3, 3 + | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // Returns NULL (finished) or TValue * (metamethod). + | cmplwi CRET1, 0 + | lwz BASE, L->base + | bne ->vmeta_binop + | evlddx TMP0, BASE, SAVE0 // Copy result from RB to RA. + | evstddx TMP0, BASE, RA + | ins_next + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | // RA = dst*8, RD = str_const*8 (~) + | ins_next1 + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4 + | evmergelo TMP0, TISSTR, TMP0 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KCDATA: + |.if FFI + | // RA = dst*8, RD = cdata_const*8 (~) + | ins_next1 + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4 + | li TMP2, LJ_TCDATA + | evmergelo TMP0, TMP2, TMP0 + | evstddx TMP0, BASE, RA + | ins_next2 + |.endif + break; + case BC_KSHORT: + | // RA = dst*8, RD = int16_literal*8 + | srwi TMP1, RD, 3 + | extsh TMP1, TMP1 + | ins_next1 + | efdcfsi TMP0, TMP1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNUM: + | // RA = dst*8, RD = num_const*8 + | evlddx TMP0, KBASE, RD + | ins_next1 + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_KPRI: + | // RA = dst*8, RD = primitive_type*8 (~) + | srwi TMP1, RD, 3 + | not TMP0, TMP1 + | ins_next1 + | stwx TMP0, BASE, RA + | ins_next2 + break; + case BC_KNIL: + | // RA = base*8, RD = end*8 + | evstddx TISNIL, BASE, RA + | addi RA, RA, 8 + |1: + | evstddx TISNIL, BASE, RA + | cmpw RA, RD + | addi RA, RA, 8 + | blt <1 + | ins_next_ + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | // RA = dst*8, RD = uvnum*8 + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RD, RD, 1 + | addi RD, RD, offsetof(GCfuncL, uvptr) + | lwzx UPVAL:RB, LFUNC:RB, RD + | lwz TMP1, UPVAL:RB->v + | evldd TMP0, 0(TMP1) + | evstddx TMP0, BASE, RA + | ins_next2 + break; + case BC_USETV: + | // RA = uvnum*8, RD = src*8 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | evlddx TMP1, BASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP0, UPVAL:RB->closed + | evmergehi TMP2, TMP1, TMP1 + | evstdd TMP1, 0(CARG2) + | cmplwi cr1, TMP0, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | subi TMP2, TMP2, (LJ_TISNUM+1) + | bne >2 // Upvalue is closed and black? + |1: + | ins_next + | + |2: // Check if new value is collectable. + | cmplwi TMP2, LJ_TISGCV - (LJ_TISNUM+1) + | bge <1 // tvisgcv(v) + | lbz TMP3, GCOBJ:TMP1->gch.marked + | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(v) + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETS: + | // RA = uvnum*8, RD = str_const*8 (~) + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | srwi RA, RA, 1 + | subfic TMP1, TMP1, -4 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4 + | lwzx UPVAL:RB, LFUNC:RB, RA + | evmergelo STR:TMP1, TISSTR, STR:TMP1 + | lbz TMP3, UPVAL:RB->marked + | lwz CARG2, UPVAL:RB->v + | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv) + | lbz TMP3, STR:TMP1->marked + | lbz TMP2, UPVAL:RB->closed + | evstdd STR:TMP1, 0(CARG2) + | bne >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(str) + | cmplwi cr1, TMP2, 0 + | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq + | la CARG1, GG_DISP2G(DISPATCH) + | // Crossed a write barrier. Move the barrier forward. + | beq <1 + | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) + | b <1 + break; + case BC_USETN: + | // RA = uvnum*8, RD = num_const*8 + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | evlddx TMP0, KBASE, RD + | lwzx UPVAL:RB, LFUNC:RB, RA + | lwz TMP1, UPVAL:RB->v + | evstdd TMP0, 0(TMP1) + | ins_next2 + break; + case BC_USETP: + | // RA = uvnum*8, RD = primitive_type*8 (~) + | ins_next1 + | lwz LFUNC:RB, FRAME_FUNC(BASE) + | srwi RA, RA, 1 + | addi RA, RA, offsetof(GCfuncL, uvptr) + | srwi TMP0, RD, 3 + | lwzx UPVAL:RB, LFUNC:RB, RA + | not TMP0, TMP0 + | lwz TMP1, UPVAL:RB->v + | stw TMP0, 0(TMP1) + | ins_next2 + break; + + case BC_UCLO: + | // RA = level*8, RD = target + | lwz TMP1, L->openupval + | branch_RD // Do this first since RD is not saved. + | stw BASE, L->base + | cmplwi TMP1, 0 + | mr CARG1, L + | beq >1 + | add CARG2, BASE, RA + | bl extern lj_func_closeuv // (lua_State *L, TValue *level) + | lwz BASE, L->base + |1: + | ins_next + break; + + case BC_FNEW: + | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype) + | srwi TMP1, RD, 1 + | stw BASE, L->base + | subfic TMP1, TMP1, -4 + | stw PC, SAVE_PC + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | mr CARG1, L + | lwz CARG3, FRAME_FUNC(BASE) + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | bl extern lj_func_newL_gc + | // Returns GCfuncL *. + | lwz BASE, L->base + | evmergelo LFUNC:CRET1, TISFUNC, LFUNC:CRET1 + | evstddx LFUNC:CRET1, BASE, RA + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + case BC_TDUP: + | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~) + | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH) + | mr CARG1, L + | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH) + | stw BASE, L->base + | cmplw TMP0, TMP1 + | stw PC, SAVE_PC + | bge >5 + |1: + if (op == BC_TNEW) { + | rlwinm CARG2, RD, 29, 21, 31 + | rlwinm CARG3, RD, 18, 27, 31 + | cmpwi CARG2, 0x7ff + | li TMP1, 0x801 + | iseleq CARG2, TMP1, CARG2 + | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Returns Table *. + } else { + | srwi TMP1, RD, 1 + | subfic TMP1, TMP1, -4 + | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4 + | bl extern lj_tab_dup // (lua_State *L, Table *kt) + | // Returns Table *. + } + | lwz BASE, L->base + | evmergelo TAB:CRET1, TISTAB, TAB:CRET1 + | evstddx TAB:CRET1, BASE, RA + | ins_next + |5: + | mr SAVE0, RD + | bl extern lj_gc_step_fixtop // (lua_State *L) + | mr RD, SAVE0 + | mr CARG1, L + | b <1 + break; + + case BC_GGET: + | // RA = dst*8, RD = str_const*8 (~) + case BC_GSET: + | // RA = src*8, RD = str_const*8 (~) + | lwz LFUNC:TMP2, FRAME_FUNC(BASE) + | srwi TMP1, RD, 1 + | lwz TAB:RB, LFUNC:TMP2->env + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + if (op == BC_GGET) { + | b ->BC_TGETS_Z + } else { + | b ->BC_TSETS_Z + } + break; + + case BC_TGETV: + | // RA = dst*8, RB = table*8, RC = key*8 + | evlddx TAB:RB, BASE, RB + | evlddx RC, BASE, RC + | checktab TAB:RB + | checkfail ->vmeta_tgetv + | checknum RC + | checkfail >5 + | // Convert number key to integer + | efdctsi TMP2, RC + | lwz TMP0, TAB:RB->asize + | efdcfsi TMP1, TMP2 + | cmplw cr0, TMP0, TMP2 + | efdcmpeq cr1, RC, TMP1 + | lwz TMP1, TAB:RB->array + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + | slwi TMP2, TMP2, 3 + | ble ->vmeta_tgetv // Integer key and in array part? + | evlddx TMP1, TMP1, TMP2 + | checknil TMP1 + | checkok >2 + |1: + | evstddx TMP1, BASE, RA + | ins_next + | + |2: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_tgetv + | + |5: + | checkstr STR:RC // String key? + | checkok ->BC_TGETS_Z + | b ->vmeta_tgetv + break; + case BC_TGETS: + | // RA = dst*8, RB = table*8, RC = str_const*8 (~) + | evlddx TAB:RB, BASE, RB + | srwi TMP1, RC, 1 + | checktab TAB:RB + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | checkfail ->vmeta_tgets1 + |->BC_TGETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | checkanyfail >4 + | checknil TMP1 + | checkok >5 // Key found, but nil value? + |3: + | evstddx TMP1, BASE, RA + | ins_next + | + |4: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, nil result. + | evmr TMP1, TISNIL + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <3 // No metatable: done. + | lbz TMP0, TAB:TMP2->nomm + | andi. TMP0, TMP0, 1<vmeta_tgets + break; + case BC_TGETB: + | // RA = dst*8, RB = table*8, RC = index*8 + | evlddx TAB:RB, BASE, RB + | srwi TMP0, RC, 3 + | checktab TAB:RB + | checkfail ->vmeta_tgetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | cmplw TMP0, TMP1 + | bge ->vmeta_tgetb + | evlddx TMP1, TMP2, RC + | checknil TMP1 + | checkok >5 + |1: + | ins_next1 + | evstddx TMP1, BASE, RA + | ins_next2 + | + |5: // Check for __index if table value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_tgetb // Caveat: preserve TMP0! + break; + + case BC_TSETV: + | // RA = src*8, RB = table*8, RC = key*8 + | evlddx TAB:RB, BASE, RB + | evlddx RC, BASE, RC + | checktab TAB:RB + | checkfail ->vmeta_tsetv + | checknum RC + | checkfail >5 + | // Convert number key to integer + | efdctsi TMP2, RC + | evlddx SAVE0, BASE, RA + | lwz TMP0, TAB:RB->asize + | efdcfsi TMP1, TMP2 + | cmplw cr0, TMP0, TMP2 + | efdcmpeq cr1, RC, TMP1 + | lwz TMP1, TAB:RB->array + | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt + | slwi TMP0, TMP2, 3 + | ble ->vmeta_tsetv // Integer key and in array part? + | lbz TMP3, TAB:RB->marked + | evlddx TMP2, TMP1, TMP0 + | checknil TMP2 + | checkok >3 + |1: + | andi. TMP2, TMP3, LJ_GC_BLACK // isblack(table) + | evstddx SAVE0, TMP1, TMP0 + | bne >7 + |2: + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | lwz TAB:TMP2, TAB:RB->metatable + | cmplwi TAB:TMP2, 0 + | beq <1 // No metatable: done. + | lbz TMP2, TAB:TMP2->nomm + | andi. TMP2, TMP2, 1<vmeta_tsetv + | + |5: + | checkstr STR:RC // String key? + | checkok ->BC_TSETS_Z + | b ->vmeta_tsetv + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + case BC_TSETS: + | // RA = src*8, RB = table*8, RC = str_const*8 (~) + | evlddx TAB:RB, BASE, RB + | srwi TMP1, RC, 1 + | checktab TAB:RB + | subfic TMP1, TMP1, -4 + | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4 + | checkfail ->vmeta_tsets1 + |->BC_TSETS_Z: + | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8 + | lwz TMP0, TAB:RB->hmask + | lwz TMP1, STR:RC->hash + | lwz NODE:TMP2, TAB:RB->node + | evmergelo STR:RC, TISSTR, STR:RC + | stb ZERO, TAB:RB->nomm // Clear metamethod cache. + | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask + | evlddx SAVE0, BASE, RA + | slwi TMP0, TMP1, 5 + | slwi TMP1, TMP1, 3 + | sub TMP1, TMP0, TMP1 + | lbz TMP3, TAB:RB->marked + | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8) + |1: + | evldd TMP0, NODE:TMP2->key + | evldd TMP1, NODE:TMP2->val + | evcmpeq TMP0, STR:RC + | checkanyfail >5 + | checknil TMP1 + | checkok >4 // Key found, but nil value? + |2: + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | evstdd SAVE0, NODE:TMP2->val + | bne >7 + |3: + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <2 // No metatable: done. + | lbz TMP0, TAB:TMP1->nomm + | andi. TMP0, TMP0, 1<vmeta_tsets + | + |5: // Follow hash chain. + | lwz NODE:TMP2, NODE:TMP2->next + | cmplwi NODE:TMP2, 0 + | bne <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | lwz TAB:TMP1, TAB:RB->metatable + | la CARG3, DISPATCH_GL(tmptv)(DISPATCH) + | stw PC, SAVE_PC + | mr CARG1, L + | cmplwi TAB:TMP1, 0 + | stw BASE, L->base + | beq >6 // No metatable: continue. + | lbz TMP0, TAB:TMP1->nomm + | andi. TMP0, TMP0, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mr CARG2, TAB:RB + | evstdd STR:RC, 0(CARG3) + | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Returns TValue *. + | lwz BASE, L->base + | evstdd SAVE0, 0(CRET1) + | b <3 // No 2nd write barrier needed. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <3 + break; + case BC_TSETB: + | // RA = src*8, RB = table*8, RC = index*8 + | evlddx TAB:RB, BASE, RB + | srwi TMP0, RC, 3 + | checktab TAB:RB + | checkfail ->vmeta_tsetb + | lwz TMP1, TAB:RB->asize + | lwz TMP2, TAB:RB->array + | lbz TMP3, TAB:RB->marked + | cmplw TMP0, TMP1 + | evlddx SAVE0, BASE, RA + | bge ->vmeta_tsetb + | evlddx TMP1, TMP2, RC + | checknil TMP1 + | checkok >5 + |1: + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + | evstddx SAVE0, TMP2, RC + | bne >7 + |2: + | ins_next + | + |5: // Check for __newindex if previous value is nil. + | lwz TAB:TMP1, TAB:RB->metatable + | cmplwi TAB:TMP1, 0 + | beq <1 // No metatable: done. + | lbz TMP1, TAB:TMP1->nomm + | andi. TMP1, TMP1, 1<vmeta_tsetb // Caveat: preserve TMP0! + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, TMP3, TMP0 + | b <2 + break; + + case BC_TSETM: + | // RA = base*8 (table at base-1), RD = num_const*8 (start index) + | add RA, BASE, RA + |1: + | add TMP3, KBASE, RD + | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table. + | addic. TMP0, MULTRES, -8 + | lwz TMP3, 4(TMP3) // Integer constant is in lo-word. + | srwi CARG3, TMP0, 3 + | beq >4 // Nothing to copy? + | add CARG3, CARG3, TMP3 + | lwz TMP2, TAB:CARG2->asize + | slwi TMP1, TMP3, 3 + | lbz TMP3, TAB:CARG2->marked + | cmplw CARG3, TMP2 + | add TMP2, RA, TMP0 + | lwz TMP0, TAB:CARG2->array + | bgt >5 + | add TMP1, TMP1, TMP0 + | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table) + |3: // Copy result slots to table. + | evldd TMP0, 0(RA) + | addi RA, RA, 8 + | cmpw cr1, RA, TMP2 + | evstdd TMP0, 0(TMP1) + | addi TMP1, TMP1, 8 + | blt cr1, <3 + | bne >7 + |4: + | ins_next + | + |5: // Need to resize array part. + | stw BASE, L->base + | mr CARG1, L + | stw PC, SAVE_PC + | mr SAVE0, RD + | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | // Must not reallocate the stack. + | mr RD, SAVE0 + | b <1 + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:CARG2, TMP3, TMP0 + | b <4 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALLM: + | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALL follows. + break; + case BC_CALL: + | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8 + | evlddx LFUNC:RB, BASE, RA + | mr TMP2, BASE + | add BASE, BASE, RA + | subi NARGS8:RC, NARGS8:RC, 8 + | checkfunc LFUNC:RB + | addi BASE, BASE, 8 + | checkfail ->vmeta_call + | ins_call + break; + + case BC_CALLMT: + | // RA = base*8, (RB = 0,) RC = extra_nargs*8 + | add NARGS8:RC, NARGS8:RC, MULTRES + | // Fall through. Assumes BC_CALLT follows. + break; + case BC_CALLT: + | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 + | evlddx LFUNC:RB, BASE, RA + | add RA, BASE, RA + | lwz TMP1, FRAME_PC(BASE) + | subi NARGS8:RC, NARGS8:RC, 8 + | checkfunc LFUNC:RB + | addi RA, RA, 8 + | checkfail ->vmeta_callt + |->BC_CALLT_Z: + | andi. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand. + | lbz TMP3, LFUNC:RB->ffid + | xori TMP2, TMP1, FRAME_VARG + | cmplwi cr1, NARGS8:RC, 0 + | bne >7 + |1: + | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC. + | li TMP2, 0 + | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function? + | beq cr1, >3 + |2: + | addi TMP3, TMP2, 8 + | evlddx TMP0, RA, TMP2 + | cmplw cr1, TMP3, NARGS8:RC + | evstddx TMP0, BASE, TMP2 + | mr TMP2, TMP3 + | bne cr1, <2 + |3: + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt + | beq >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function with a Lua frame below. + | lwz INS, -4(TMP1) + | decode_RA8 RA, INS + | sub TMP1, BASE, RA + | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1) + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE. + | b <4 + | + |7: // Tailcall from a vararg function. + | andi. TMP0, TMP2, FRAME_TYPEP + | bne <1 // Vararg frame below? + | sub BASE, BASE, TMP2 // Relocate BASE down. + | lwz TMP1, FRAME_PC(BASE) + | andi. TMP0, TMP1, FRAME_TYPE + | b <1 + break; + + case BC_ITERC: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8)) + | subi RA, RA, 24 // evldd doesn't support neg. offsets. + | mr TMP2, BASE + | evlddx LFUNC:RB, BASE, RA + | add BASE, BASE, RA + | evldd TMP0, 8(BASE) + | evldd TMP1, 16(BASE) + | evstdd LFUNC:RB, 24(BASE) // Copy callable. + | checkfunc LFUNC:RB + | evstdd TMP0, 32(BASE) // Copy state. + | li NARGS8:RC, 16 // Iterators get 2 arguments. + | evstdd TMP1, 40(BASE) // Copy control var. + | addi BASE, BASE, 32 + | checkfail ->vmeta_call + | ins_call + break; + + case BC_ITERN: + | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | add RA, BASE, RA + | lwz TAB:RB, -12(RA) + | lwz RC, -4(RA) // Get index from control var. + | lwz TMP0, TAB:RB->asize + | lwz TMP1, TAB:RB->array + | addi PC, PC, 4 + |1: // Traverse array part. + | cmplw RC, TMP0 + | slwi TMP3, RC, 3 + | bge >5 // Index points after array part? + | evlddx TMP2, TMP1, TMP3 + | checknil TMP2 + | lwz INS, -4(PC) + | checkok >4 + | efdcfsi TMP0, RC + | addi RC, RC, 1 + | addis TMP3, PC, -(BCBIAS_J*4 >> 16) + | evstdd TMP2, 8(RA) + | decode_RD4 TMP1, INS + | stw RC, -4(RA) // Update control var. + | add PC, TMP1, TMP3 + | evstdd TMP0, 0(RA) + |3: + | ins_next + | + |4: // Skip holes in array part. + | addi RC, RC, 1 + | b <1 + | + |5: // Traverse hash part. + | lwz TMP1, TAB:RB->hmask + | sub RC, RC, TMP0 + | lwz TMP2, TAB:RB->node + |6: + | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1. + | slwi TMP3, RC, 5 + | bgt <3 + | slwi RB, RC, 3 + | sub TMP3, TMP3, RB + | evlddx RB, TMP2, TMP3 + | add NODE:TMP3, TMP2, TMP3 + | checknil RB + | lwz INS, -4(PC) + | checkok >7 + | evldd TMP3, NODE:TMP3->key + | addis TMP2, PC, -(BCBIAS_J*4 >> 16) + | evstdd RB, 8(RA) + | add RC, RC, TMP0 + | decode_RD4 TMP1, INS + | evstdd TMP3, 0(RA) + | addi RC, RC, 1 + | add PC, TMP1, TMP2 + | stw RC, -4(RA) // Update control var. + | b <3 + | + |7: // Skip holes in hash part. + | addi RC, RC, 1 + | b <6 + break; + + case BC_ISNEXT: + | // RA = base*8, RD = target (points to ITERN) + | add RA, BASE, RA + | li TMP2, -24 + | evlddx CFUNC:TMP1, RA, TMP2 + | lwz TMP2, -16(RA) + | lwz TMP3, -8(RA) + | evmergehi TMP0, CFUNC:TMP1, CFUNC:TMP1 + | cmpwi cr0, TMP2, LJ_TTAB + | cmpwi cr1, TMP0, LJ_TFUNC + | cmpwi cr6, TMP3, LJ_TNIL + | bne cr1, >5 + | lbz TMP1, CFUNC:TMP1->ffid + | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq + | cmpwi cr7, TMP1, FF_next_N + | srwi TMP0, RD, 1 + | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq + | add TMP3, PC, TMP0 + | bne cr0, >5 + | lus TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | stw ZERO, -4(RA) // Initialize control var. + | stw TMP1, -8(RA) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | li TMP0, BC_JMP + | li TMP1, BC_ITERC + | stb TMP0, -1(PC) + | addis PC, TMP3, -(BCBIAS_J*4 >> 16) + | stb TMP1, 3(PC) + | b <1 + break; + + case BC_VARG: + | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 + | lwz TMP0, FRAME_PC(BASE) + | add RC, BASE, RC + | add RA, BASE, RA + | addi RC, RC, FRAME_VARG + | add TMP2, RA, RB + | subi TMP3, BASE, 8 // TMP3 = vtop + | sub RC, RC, TMP0 // RC = vbase + | // Note: RC may now be even _above_ BASE if nargs was < numparams. + | cmplwi cr1, RB, 0 + | sub. TMP1, TMP3, RC + | beq cr1, >5 // Copy all varargs? + | subi TMP2, TMP2, 16 + | ble >2 // No vararg slots? + |1: // Copy vararg slots to destination slots. + | evldd TMP0, 0(RC) + | addi RC, RC, 8 + | evstdd TMP0, 0(RA) + | cmplw RA, TMP2 + | cmplw cr1, RC, TMP3 + | bge >3 // All destination slots filled? + | addi RA, RA, 8 + | blt cr1, <1 // More vararg slots? + |2: // Fill up remainder with nil. + | evstdd TISNIL, 0(RA) + | cmplw RA, TMP2 + | addi RA, RA, 8 + | blt <2 + |3: + | ins_next + | + |5: // Copy all varargs. + | lwz TMP0, L->maxstack + | li MULTRES, 8 // MULTRES = (0+1)*8 + | ble <3 // No vararg slots? + | add TMP2, RA, TMP1 + | cmplw TMP2, TMP0 + | addi MULTRES, TMP1, 8 + | bgt >7 + |6: + | evldd TMP0, 0(RC) + | addi RC, RC, 8 + | evstdd TMP0, 0(RA) + | cmplw RC, TMP3 + | addi RA, RA, 8 + | blt <6 // More vararg slots? + | b <3 + | + |7: // Grow stack for varargs. + | mr CARG1, L + | stw RA, L->top + | sub SAVE0, RC, BASE // Need delta, because BASE may change. + | stw BASE, L->base + | sub RA, RA, BASE + | stw PC, SAVE_PC + | srwi CARG2, TMP1, 3 + | bl extern lj_state_growstack // (lua_State *L, int n) + | lwz BASE, L->base + | add RA, BASE, RA + | add RC, BASE, SAVE0 + | subi TMP3, BASE, 8 + | b <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | // RA = results*8, RD = extra_nresults*8 + | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8. + | // Fall through. Assumes BC_RET follows. + break; + + case BC_RET: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + |1: + | andi. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + |->BC_RET_Z: + | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return + | lwz INS, -4(PC) + | cmpwi RD, 8 + | subi TMP2, BASE, 8 + | subi RC, RD, 8 + | decode_RB8 RB, INS + | beq >3 + | li TMP1, 0 + |2: + | addi TMP3, TMP1, 8 + | evlddx TMP0, RA, TMP1 + | cmpw TMP3, RC + | evstddx TMP0, TMP2, TMP1 + | beq >3 + | addi TMP1, TMP3, 8 + | evlddx TMP0, RA, TMP3 + | cmpw TMP1, RC + | evstddx TMP0, TMP2, TMP3 + | bne <2 + |3: + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, TMP2, TMP1 + | b <5 + | + |->BC_RETV_Z: // Non-standard return case. + | andi. TMP2, TMP1, FRAME_TYPEP + | bne ->vm_return + | // Return from vararg function: relocate BASE down. + | sub BASE, BASE, TMP1 + | lwz PC, FRAME_PC(BASE) + | b <1 + break; + + case BC_RET0: case BC_RET1: + | // RA = results*8, RD = (nresults+1)*8 + | lwz PC, FRAME_PC(BASE) + | add RA, BASE, RA + | mr MULTRES, RD + | andi. TMP0, PC, FRAME_TYPE + | xori TMP1, PC, FRAME_VARG + | bne ->BC_RETV_Z + | + | lwz INS, -4(PC) + | subi TMP2, BASE, 8 + | decode_RB8 RB, INS + if (op == BC_RET1) { + | evldd TMP0, 0(RA) + | evstdd TMP0, 0(TMP2) + } + |5: + | cmplw RB, RD + | decode_RA8 RA, INS + | bgt >6 + | sub BASE, TMP2, RA + | lwz LFUNC:TMP1, FRAME_FUNC(BASE) + | ins_next1 + | lwz TMP1, LFUNC:TMP1->pc + | lwz KBASE, PC2PROTO(k)(TMP1) + | ins_next2 + | + |6: // Fill up results with nil. + | subi TMP1, RD, 8 + | addi RD, RD, 8 + | evstddx TISNIL, TMP2, TMP1 + | b <5 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + case BC_FORL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IFORL follows. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + | // RA = base*8, RD = target (after end of loop or start of loop) + vk = (op == BC_IFORL || op == BC_JFORL); + | add RA, BASE, RA + | evldd TMP1, FORL_IDX*8(RA) + | evldd TMP3, FORL_STEP*8(RA) + | evldd TMP2, FORL_STOP*8(RA) + if (!vk) { + | evcmpgtu cr0, TMP1, TISNUM + | evcmpgtu cr7, TMP3, TISNUM + | evcmpgtu cr1, TMP2, TISNUM + | cror 4*cr0+lt, 4*cr0+lt, 4*cr7+lt + | cror 4*cr0+lt, 4*cr0+lt, 4*cr1+lt + | blt ->vmeta_for + } + if (vk) { + | efdadd TMP1, TMP1, TMP3 + | evstdd TMP1, FORL_IDX*8(RA) + } + | evcmpgts TMP3, TISNIL + | evstdd TMP1, FORL_EXT*8(RA) + | bge >2 + | efdcmpgt TMP1, TMP2 + |1: + if (op != BC_JFORL) { + | srwi RD, RD, 1 + | add RD, PC, RD + if (op == BC_JFORI) { + | addis PC, RD, -(BCBIAS_J*4 >> 16) + } else { + | addis RD, RD, -(BCBIAS_J*4 >> 16) + } + } + if (op == BC_FORI) { + | iselgt PC, RD, PC + } else if (op == BC_IFORL) { + | iselgt PC, PC, RD + } else { + | ble =>BC_JLOOP + } + | ins_next + |2: + | efdcmpgt TMP2, TMP1 + | b <1 + break; + + case BC_ITERL: + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_IITERL follows. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | // RA = base*8, RD = target + | evlddx TMP1, BASE, RA + | subi RA, RA, 8 + | checknil TMP1 + | checkok >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | NYI + } else { + | branch_RD // Otherwise save control var + branch. + | evstddx TMP1, BASE, RA + } + |1: + | ins_next + break; + + case BC_LOOP: + | // RA = base*8, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop + |.endif + | // Fall through. Assumes BC_ILOOP follows. + break; + + case BC_ILOOP: + | // RA = base*8, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | NYI + |.endif + break; + + case BC_JMP: + | // RA = base*8 (only used by trace recorder), RD = target + | branch_RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + case BC_FUNCF: + |.if JIT + | hotcall + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | lbz TMP1, -4+PC2PROTO(numparams)(PC) + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw RA, TMP2 + | slwi TMP1, TMP1, 3 + | bgt ->vm_growstack_l + | ins_next1 + |2: + | cmplw NARGS8:RC, TMP1 // Check for missing parameters. + | ble >3 + if (op == BC_JFUNCF) { + | NYI + } else { + | ins_next2 + } + | + |3: // Clear missing parameters. + | evstddx TISNIL, BASE, NARGS8:RC + | addi NARGS8:RC, NARGS8:RC, 8 + | b <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | NYI // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 + | lwz TMP2, L->maxstack + | add TMP1, BASE, RC + | add TMP0, RA, RC + | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC. + | addi TMP3, RC, 8+FRAME_VARG + | lwz KBASE, -4+PC2PROTO(k)(PC) + | cmplw TMP0, TMP2 + | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG. + | bge ->vm_growstack_l + | lbz TMP2, -4+PC2PROTO(numparams)(PC) + | mr RA, BASE + | mr RC, TMP1 + | ins_next1 + | cmpwi TMP2, 0 + | addi BASE, TMP1, 8 + | beq >3 + |1: + | cmplw RA, RC // Less args than parameters? + | evldd TMP0, 0(RA) + | bge >4 + | evstdd TISNIL, 0(RA) // Clear old fixarg slot (help the GC). + | addi RA, RA, 8 + |2: + | addic. TMP2, TMP2, -1 + | evstdd TMP0, 8(TMP1) + | addi TMP1, TMP1, 8 + | bne <1 + |3: + | ins_next2 + | + |4: // Clear missing parameters. + | evmr TMP0, TISNIL + | b <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8 + if (op == BC_FUNCC) { + | lwz TMP3, CFUNC:RB->f + } else { + | lwz TMP3, DISPATCH_GL(wrapf)(DISPATCH) + } + | add TMP1, RA, NARGS8:RC + | lwz TMP2, L->maxstack + | add RC, BASE, NARGS8:RC + | stw BASE, L->base + | cmplw TMP1, TMP2 + | stw RC, L->top + | li_vmstate C + | mtctr TMP3 + if (op == BC_FUNCCW) { + | lwz CARG2, CFUNC:RB->f + } + | mr CARG1, L + | bgt ->vm_growstack_c // Need to grow stack. + | st_vmstate + | bctrl // (lua_State *L [, lua_CFunction f]) + | // Returns nresults. + | lwz TMP1, L->top + | slwi RD, CRET1, 3 + | lwz BASE, L->base + | li_vmstate INTERP + | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. + | sub RA, TMP1, RD // RA = L->top - nresults*8 + | st_vmstate + | b ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + + dasm_growpc(Dst, BC__MAX); + + build_subroutines(ctx); + + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int i; + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n", + (int)ctx->codesz, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n", + 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE0:\n\n"); + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -4\n" + "\t.byte 65\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n" + "\t.align 2\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .LASFDE1-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" + "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n" + "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n", + (int)ctx->codesz, CFRAME_SIZE); + for (i = 14; i <= 31; i++) + fprintf(ctx->fp, + "\t.byte %d\n\t.uleb128 %d\n" + "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n", + 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i)); + fprintf(ctx->fp, + "\t.align 2\n" + ".LEFDE1:\n\n"); + break; + default: + break; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_x86.dasc b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_x86.dasc new file mode 100644 index 0000000..8a9b536 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/vm_x86.dasc @@ -0,0 +1,6374 @@ +|// Low-level VM code for x86 CPUs. +|// Bytecode interpreter, fast functions and helper functions. +|// Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +| +|.if P64 +|.arch x64 +|.else +|.arch x86 +|.endif +|.section code_op, code_sub +| +|.actionlist build_actionlist +|.globals GLOB_ +|.globalnames globnames +|.externnames extnames +| +|//----------------------------------------------------------------------- +| +|.if P64 +|.define X64, 1 +|.define SSE, 1 +|.if WIN +|.define X64WIN, 1 +|.endif +|.endif +| +|// Fixed register assignments for the interpreter. +|// This is very fragile and has many dependencies. Caveat emptor. +|.define BASE, edx // Not C callee-save, refetched anyway. +|.if not X64 +|.define KBASE, edi // Must be C callee-save. +|.define KBASEa, KBASE +|.define PC, esi // Must be C callee-save. +|.define PCa, PC +|.define DISPATCH, ebx // Must be C callee-save. +|.elif X64WIN +|.define KBASE, edi // Must be C callee-save. +|.define KBASEa, rdi +|.define PC, esi // Must be C callee-save. +|.define PCa, rsi +|.define DISPATCH, ebx // Must be C callee-save. +|.else +|.define KBASE, r15d // Must be C callee-save. +|.define KBASEa, r15 +|.define PC, ebx // Must be C callee-save. +|.define PCa, rbx +|.define DISPATCH, r14d // Must be C callee-save. +|.endif +| +|.define RA, ecx +|.define RAH, ch +|.define RAL, cl +|.define RB, ebp // Must be ebp (C callee-save). +|.define RC, eax // Must be eax. +|.define RCW, ax +|.define RCH, ah +|.define RCL, al +|.define OP, RB +|.define RD, RC +|.define RDW, RCW +|.define RDL, RCL +|.if X64 +|.define RAa, rcx +|.define RBa, rbp +|.define RCa, rax +|.define RDa, rax +|.else +|.define RAa, RA +|.define RBa, RB +|.define RCa, RC +|.define RDa, RD +|.endif +| +|.if not X64 +|.define FCARG1, ecx // x86 fastcall arguments. +|.define FCARG2, edx +|.elif X64WIN +|.define CARG1, rcx // x64/WIN64 C call arguments. +|.define CARG2, rdx +|.define CARG3, r8 +|.define CARG4, r9 +|.define CARG1d, ecx +|.define CARG2d, edx +|.define CARG3d, r8d +|.define CARG4d, r9d +|.define FCARG1, CARG1d // Upwards compatible to x86 fastcall. +|.define FCARG2, CARG2d +|.else +|.define CARG1, rdi // x64/POSIX C call arguments. +|.define CARG2, rsi +|.define CARG3, rdx +|.define CARG4, rcx +|.define CARG5, r8 +|.define CARG6, r9 +|.define CARG1d, edi +|.define CARG2d, esi +|.define CARG3d, edx +|.define CARG4d, ecx +|.define CARG5d, r8d +|.define CARG6d, r9d +|.define FCARG1, CARG1d // Simulate x86 fastcall. +|.define FCARG2, CARG2d +|.endif +| +|// Type definitions. Some of these are only used for documentation. +|.type L, lua_State +|.type GL, global_State +|.type TVALUE, TValue +|.type GCOBJ, GCobj +|.type STR, GCstr +|.type TAB, GCtab +|.type LFUNC, GCfuncL +|.type CFUNC, GCfuncC +|.type PROTO, GCproto +|.type UPVAL, GCupval +|.type NODE, Node +|.type NARGS, int +|.type TRACE, GCtrace +| +|// Stack layout while in interpreter. Must match with lj_frame.h. +|//----------------------------------------------------------------------- +|.if not X64 // x86 stack layout. +| +|.define CFRAME_SPACE, aword*7 // Delta for esp (see <--). +|.macro saveregs_ +| push edi; push esi; push ebx +| sub esp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push ebp; saveregs_ +|.endmacro +|.macro restoreregs +| add esp, CFRAME_SPACE +| pop ebx; pop esi; pop edi; pop ebp +|.endmacro +| +|.define SAVE_ERRF, aword [esp+aword*15] // vm_pcall/vm_cpcall only. +|.define SAVE_NRES, aword [esp+aword*14] +|.define SAVE_CFRAME, aword [esp+aword*13] +|.define SAVE_L, aword [esp+aword*12] +|//----- 16 byte aligned, ^^^ arguments from C caller +|.define SAVE_RET, aword [esp+aword*11] //<-- esp entering interpreter. +|.define SAVE_R4, aword [esp+aword*10] +|.define SAVE_R3, aword [esp+aword*9] +|.define SAVE_R2, aword [esp+aword*8] +|//----- 16 byte aligned +|.define SAVE_R1, aword [esp+aword*7] //<-- esp after register saves. +|.define SAVE_PC, aword [esp+aword*6] +|.define TMP2, aword [esp+aword*5] +|.define TMP1, aword [esp+aword*4] +|//----- 16 byte aligned +|.define ARG4, aword [esp+aword*3] +|.define ARG3, aword [esp+aword*2] +|.define ARG2, aword [esp+aword*1] +|.define ARG1, aword [esp] //<-- esp while in interpreter. +|//----- 16 byte aligned, ^^^ arguments for C callee +| +|// FPARGx overlaps ARGx and ARG(x+1) on x86. +|.define FPARG3, qword [esp+qword*1] +|.define FPARG1, qword [esp] +|// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ). +|.define TMPQ, qword [esp+aword*4] +|.define TMP3, ARG4 +|.define ARG5, TMP1 +|.define TMPa, TMP1 +|.define MULTRES, TMP2 +| +|// Arguments for vm_call and vm_pcall. +|.define INARG_BASE, SAVE_CFRAME // Overwritten by SAVE_CFRAME! +| +|// Arguments for vm_cpcall. +|.define INARG_CP_CALL, SAVE_ERRF +|.define INARG_CP_UD, SAVE_NRES +|.define INARG_CP_FUNC, SAVE_CFRAME +| +|//----------------------------------------------------------------------- +|.elif X64WIN // x64/Windows stack layout +| +|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). +|.macro saveregs_ +| push rdi; push rsi; push rbx +| sub rsp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push rbp; saveregs_ +|.endmacro +|.macro restoreregs +| add rsp, CFRAME_SPACE +| pop rbx; pop rsi; pop rdi; pop rbp +|.endmacro +| +|.define SAVE_CFRAME, aword [rsp+aword*13] +|.define SAVE_PC, dword [rsp+dword*25] +|.define SAVE_L, dword [rsp+dword*24] +|.define SAVE_ERRF, dword [rsp+dword*23] +|.define SAVE_NRES, dword [rsp+dword*22] +|.define TMP2, dword [rsp+dword*21] +|.define TMP1, dword [rsp+dword*20] +|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter +|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*8] +|.define SAVE_R3, aword [rsp+aword*7] +|.define SAVE_R2, aword [rsp+aword*6] +|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.define ARG5, aword [rsp+aword*4] +|.define CSAVE_4, aword [rsp+aword*3] +|.define CSAVE_3, aword [rsp+aword*2] +|.define CSAVE_2, aword [rsp+aword*1] +|.define CSAVE_1, aword [rsp] //<-- rsp while in interpreter. +|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee +| +|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ). +|.define TMPQ, qword [rsp+aword*10] +|.define MULTRES, TMP2 +|.define TMPa, ARG5 +|.define ARG5d, dword [rsp+aword*4] +|.define TMP3, ARG5d +| +|//----------------------------------------------------------------------- +|.else // x64/POSIX stack layout +| +|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). +|.macro saveregs_ +| push rbx; push r15; push r14 +| sub rsp, CFRAME_SPACE +|.endmacro +|.macro saveregs +| push rbp; saveregs_ +|.endmacro +|.macro restoreregs +| add rsp, CFRAME_SPACE +| pop r14; pop r15; pop rbx; pop rbp +|.endmacro +| +|//----- 16 byte aligned, +|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*8] +|.define SAVE_R3, aword [rsp+aword*7] +|.define SAVE_R2, aword [rsp+aword*6] +|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.define SAVE_CFRAME, aword [rsp+aword*4] +|.define SAVE_PC, dword [rsp+dword*7] +|.define SAVE_L, dword [rsp+dword*6] +|.define SAVE_ERRF, dword [rsp+dword*5] +|.define SAVE_NRES, dword [rsp+dword*4] +|.define TMPa, aword [rsp+aword*1] +|.define TMP2, dword [rsp+dword*1] +|.define TMP1, dword [rsp] //<-- rsp while in interpreter. +|//----- 16 byte aligned +| +|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ). +|.define TMPQ, qword [rsp] +|.define TMP3, dword [rsp+aword*1] +|.define MULTRES, TMP2 +| +|.endif +| +|//----------------------------------------------------------------------- +| +|// Instruction headers. +|.macro ins_A; .endmacro +|.macro ins_AD; .endmacro +|.macro ins_AJ; .endmacro +|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro +|.macro ins_AB_; movzx RB, RCH; .endmacro +|.macro ins_A_C; movzx RC, RCL; .endmacro +|.macro ins_AND; not RDa; .endmacro +| +|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster). +|.macro ins_NEXT +| mov RC, [PC] +| movzx RA, RCH +| movzx OP, RCL +| add PC, 4 +| shr RC, 16 +|.if X64 +| jmp aword [DISPATCH+OP*8] +|.else +| jmp aword [DISPATCH+OP*4] +|.endif +|.endmacro +| +|// Instruction footer. +|.if 1 +| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. +| .define ins_next, ins_NEXT +| .define ins_next_, ins_NEXT +|.else +| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. +| // Affects only certain kinds of benchmarks (and only with -j off). +| // Around 10%-30% slower on Core2, a lot more slower on P4. +| .macro ins_next +| jmp ->ins_next +| .endmacro +| .macro ins_next_ +| ->ins_next: +| ins_NEXT +| .endmacro +|.endif +| +|// Call decode and dispatch. +|.macro ins_callt +| // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC +| mov PC, LFUNC:RB->pc +| mov RA, [PC] +| movzx OP, RAL +| movzx RA, RAH +| add PC, 4 +|.if X64 +| jmp aword [DISPATCH+OP*8] +|.else +| jmp aword [DISPATCH+OP*4] +|.endif +|.endmacro +| +|.macro ins_call +| // BASE = new base, RB = LFUNC, RD = nargs+1 +| mov [BASE-4], PC +| ins_callt +|.endmacro +| +|//----------------------------------------------------------------------- +| +|// Macros to test operand types. +|.macro checktp, reg, tp; cmp dword [BASE+reg*8+4], tp; .endmacro +|.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro +|.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro +|.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro +|.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro +| +|// These operands must be used with movzx. +|.define PC_OP, byte [PC-4] +|.define PC_RA, byte [PC-3] +|.define PC_RB, byte [PC-1] +|.define PC_RC, byte [PC-2] +|.define PC_RD, word [PC-2] +| +|.macro branchPC, reg +| lea PC, [PC+reg*4-BCBIAS_J*4] +|.endmacro +| +|// Assumes DISPATCH is relative to GL. +#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) +#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) +| +#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) +| +|// Decrement hashed hotcount and trigger trace recorder if zero. +|.macro hotloop, reg +| mov reg, PC +| shr reg, 1 +| and reg, HOTCOUNT_PCMASK +| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP +| jb ->vm_hotloop +|.endmacro +| +|.macro hotcall, reg +| mov reg, PC +| shr reg, 1 +| and reg, HOTCOUNT_PCMASK +| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL +| jb ->vm_hotcall +|.endmacro +| +|// Set current VM state. +|.macro set_vmstate, st +| mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st +|.endmacro +| +|// x87 compares. +|.macro fcomparepp // Compare and pop st0 >< st1. +| fucomip st1 +| fpop +|.endmacro +| +|.macro fdup; fld st0; .endmacro +|.macro fpop1; fstp st1; .endmacro +| +|// Synthesize SSE FP constants. +|.macro sseconst_abs, reg, tmp // Synthesize abs mask. +|.if X64 +| mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp +|.else +| pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1 +|.endif +|.endmacro +| +|.macro sseconst_hi, reg, tmp, val // Synthesize hi-32 bit const. +|.if X64 +| mov64 tmp, U64x(val,00000000); movd reg, tmp +|.else +| mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51 +|.endif +|.endmacro +| +|.macro sseconst_sign, reg, tmp // Synthesize sign mask. +| sseconst_hi reg, tmp, 80000000 +|.endmacro +|.macro sseconst_1, reg, tmp // Synthesize 1.0. +| sseconst_hi reg, tmp, 3ff00000 +|.endmacro +|.macro sseconst_m1, reg, tmp // Synthesize -1.0. +| sseconst_hi reg, tmp, bff00000 +|.endmacro +|.macro sseconst_2p52, reg, tmp // Synthesize 2^52. +| sseconst_hi reg, tmp, 43300000 +|.endmacro +|.macro sseconst_tobit, reg, tmp // Synthesize 2^52 + 2^51. +| sseconst_hi reg, tmp, 43380000 +|.endmacro +| +|// Move table write barrier back. Overwrites reg. +|.macro barrierback, tab, reg +| and byte tab->marked, (uint8_t)~LJ_GC_BLACK // black2gray(tab) +| mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)] +| mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab +| mov tab->gclist, reg +|.endmacro +| +|//----------------------------------------------------------------------- + +/* Generate subroutines used by opcodes and other parts of the VM. */ +/* The .code_sub section should be last to help static branch prediction. */ +static void build_subroutines(BuildCtx *ctx) +{ + |.code_sub + | + |//----------------------------------------------------------------------- + |//-- Return handling ---------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_returnp: + | test PC, FRAME_P + | jz ->cont_dispatch + | + | // Return from pcall or xpcall fast func. + | and PC, -8 + | sub BASE, PC // Restore caller base. + | lea RAa, [RA+PC-8] // Rebase RA and prepend one result. + | mov PC, [BASE-4] // Fetch PC of previous frame. + | // Prepending may overwrite the pcall frame, so do it at the end. + | mov dword [BASE+RA+4], LJ_TTRUE // Prepend true to results. + | + |->vm_returnc: + | add RD, 1 // RD = nresults+1 + | jz ->vm_unwind_yield + | mov MULTRES, RD + | test PC, FRAME_TYPE + | jz ->BC_RET_Z // Handle regular return to Lua. + | + |->vm_return: + | // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return + | xor PC, FRAME_C + | test PC, FRAME_TYPE + | jnz ->vm_returnp + | + | // Return to C. + | set_vmstate C + | and PC, -8 + | sub PC, BASE + | neg PC // Previous base = BASE - delta. + | + | sub RD, 1 + | jz >2 + |1: // Move results down. + |.if X64 + | mov RBa, [BASE+RA] + | mov [BASE-8], RBa + |.else + | mov RB, [BASE+RA] + | mov [BASE-8], RB + | mov RB, [BASE+RA+4] + | mov [BASE-4], RB + |.endif + | add BASE, 8 + | sub RD, 1 + | jnz <1 + |2: + | mov L:RB, SAVE_L + | mov L:RB->base, PC + |3: + | mov RD, MULTRES + | mov RA, SAVE_NRES // RA = wanted nresults+1 + |4: + | cmp RA, RD + | jne >6 // More/less results wanted? + |5: + | sub BASE, 8 + | mov L:RB->top, BASE + | + |->vm_leave_cp: + | mov RAa, SAVE_CFRAME // Restore previous C frame. + | mov L:RB->cframe, RAa + | xor eax, eax // Ok return status for vm_pcall. + | + |->vm_leave_unw: + | restoreregs + | ret + | + |6: + | jb >7 // Less results wanted? + | // More results wanted. Check stack size and fill up results with nil. + | cmp BASE, L:RB->maxstack + | ja >8 + | mov dword [BASE-4], LJ_TNIL + | add BASE, 8 + | add RD, 1 + | jmp <4 + | + |7: // Less results wanted. + | test RA, RA + | jz <5 // But check for LUA_MULTRET+1. + | sub RA, RD // Negative result! + | lea BASE, [BASE+RA*8] // Correct top. + | jmp <5 + | + |8: // Corner case: need to grow stack for filling up results. + | // This can happen if: + | // - A C function grows the stack (a lot). + | // - The GC shrinks the stack in between. + | // - A return back from a lua_call() with (high) nresults adjustment. + | mov L:RB->top, BASE // Save current top held in BASE (yes). + | mov MULTRES, RD // Need to fill only remainder with nil. + | mov FCARG2, RA + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->top // Need the (realloced) L->top in BASE. + | jmp <3 + | + |->vm_unwind_yield: + | mov al, LUA_YIELD + | jmp ->vm_unwind_c_eh + | + |->vm_unwind_c@8: // Unwind C stack, return from vm_pcall. + | // (void *cframe, int errcode) + |.if X64 + | mov eax, CARG2d // Error return status for vm_pcall. + | mov rsp, CARG1 + |.else + | mov eax, FCARG2 // Error return status for vm_pcall. + | mov esp, FCARG1 + |.endif + |->vm_unwind_c_eh: // Landing pad for external unwinder. + | mov L:RB, SAVE_L + | mov GL:RB, L:RB->glref + | mov dword GL:RB->vmstate, ~LJ_VMST_C + | jmp ->vm_leave_unw + | + |->vm_unwind_rethrow: + |.if X64 and not X64WIN + | mov FCARG1, SAVE_L + | mov FCARG2, eax + | restoreregs + | jmp extern lj_err_throw@8 // (lua_State *L, int errcode) + |.endif + | + |->vm_unwind_ff@4: // Unwind C stack, return from ff pcall. + | // (void *cframe) + |.if X64 + | and CARG1, CFRAME_RAWMASK + | mov rsp, CARG1 + |.else + | and FCARG1, CFRAME_RAWMASK + | mov esp, FCARG1 + |.endif + |->vm_unwind_ff_eh: // Landing pad for external unwinder. + | mov L:RB, SAVE_L + | mov RAa, -8 // Results start at BASE+RA = BASE-8. + | mov RD, 1+1 // Really 1+2 results, incr. later. + | mov BASE, L:RB->base + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | mov PC, [BASE-4] // Fetch PC of previous frame. + | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message. + | set_vmstate INTERP + | jmp ->vm_returnc // Increments RD/MULTRES and returns. + | + |//----------------------------------------------------------------------- + |//-- Grow stack for calls ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_growstack_c: // Grow stack for C function. + | mov FCARG2, LUA_MINSTACK + | jmp >2 + | + |->vm_growstack_v: // Grow stack for vararg Lua function. + | sub RD, 8 + | jmp >1 + | + |->vm_growstack_f: // Grow stack for fixarg Lua function. + | // BASE = new base, RD = nargs+1, RB = L, PC = first PC + | lea RD, [BASE+NARGS:RD*8-8] + |1: + | movzx RA, byte [PC-4+PC2PROTO(framesize)] + | add PC, 4 // Must point after first instruction. + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov SAVE_PC, PC + | mov FCARG2, RA + |2: + | // RB = L, L->base = new base, L->top = top + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | mov RD, L:RB->top + | mov LFUNC:RB, [BASE-8] + | sub RD, BASE + | shr RD, 3 + | add NARGS:RD, 1 + | // BASE = new base, RB = LFUNC, RD = nargs+1 + | ins_callt // Just retry the call. + | + |//----------------------------------------------------------------------- + |//-- Entry points into the assembler VM --------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_resume: // Setup C frame and resume thread. + | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) + | saveregs + |.if X64 + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + | mov RA, CARG2d + |.else + | mov L:RB, SAVE_L + | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! + |.endif + | mov PC, FRAME_CP + | xor RD, RD + | lea KBASEa, [esp+CFRAME_RESUME] + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | mov L:RB->cframe, KBASEa + | mov SAVE_PC, RD // Any value outside of bytecode is ok. + | mov SAVE_CFRAME, RDa + |.if X64 + | mov SAVE_NRES, RD + | mov SAVE_ERRF, RD + |.endif + | cmp byte L:RB->status, RDL + | je >3 // Initial resume (like a call). + | + | // Resume after yield (like a return). + | set_vmstate INTERP + | mov byte L:RB->status, RDL + | mov BASE, L:RB->base + | mov RD, L:RB->top + | sub RD, RA + | shr RD, 3 + | add RD, 1 // RD = nresults+1 + | sub RA, BASE // RA = resultofs + | mov PC, [BASE-4] + | mov MULTRES, RD + | test PC, FRAME_TYPE + | jz ->BC_RET_Z + | jmp ->vm_return + | + |->vm_pcall: // Setup protected C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) + | saveregs + | mov PC, FRAME_CP + |.if X64 + | mov SAVE_ERRF, CARG4d + |.endif + | jmp >1 + | + |->vm_call: // Setup C frame and enter VM. + | // (lua_State *L, TValue *base, int nres1) + | saveregs + | mov PC, FRAME_C + | + |1: // Entry point for vm_pcall above (PC = ftype). + |.if X64 + | mov SAVE_NRES, CARG3d + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + | mov RA, CARG2d + |.else + | mov L:RB, SAVE_L + | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! + |.endif + | + | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASEa + | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. + |.if X64 + | mov L:RB->cframe, rsp + |.else + | mov L:RB->cframe, esp + |.endif + | + |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype). + | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. + | add DISPATCH, GG_G2DISP + | + |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype). + | set_vmstate INTERP + | mov BASE, L:RB->base // BASE = old base (used in vmeta_call). + | add PC, RA + | sub PC, BASE // PC = frame delta + frame type + | + | mov RD, L:RB->top + | sub RD, RA + | shr NARGS:RD, 3 + | add NARGS:RD, 1 // RD = nargs+1 + | + |->vm_call_dispatch: + | mov LFUNC:RB, [RA-8] + | cmp dword [RA-4], LJ_TFUNC + | jne ->vmeta_call // Ensure KBASE defined and != BASE. + | + |->vm_call_dispatch_f: + | mov BASE, RA + | ins_call + | // BASE = new base, RB = func, RD = nargs+1, PC = caller PC + | + |->vm_cpcall: // Setup protected C frame, call C. + | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) + | saveregs + |.if X64 + | mov L:RB, CARG1d // Caveat: CARG1d may be RA. + | mov SAVE_L, CARG1d + |.else + | mov L:RB, SAVE_L + | // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap! + | mov RC, INARG_CP_UD // Get args before they are overwritten. + | mov RA, INARG_CP_FUNC + | mov BASE, INARG_CP_CALL + |.endif + | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. + | + | mov KBASE, L:RB->stack // Compute -savestack(L, L->top). + | sub KBASE, L:RB->top + | mov SAVE_ERRF, 0 // No error function. + | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame. + | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe). + | + |.if X64 + | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASEa + | mov L:RB->cframe, rsp + | + | call CARG4 // (lua_State *L, lua_CFunction func, void *ud) + |.else + | mov ARG3, RC // Have to copy args downwards. + | mov ARG2, RA + | mov ARG1, L:RB + | + | mov KBASE, L:RB->cframe // Add our C frame to cframe chain. + | mov SAVE_CFRAME, KBASE + | mov L:RB->cframe, esp + | + | call BASE // (lua_State *L, lua_CFunction func, void *ud) + |.endif + | // TValue * (new base) or NULL returned in eax (RC). + | test RC, RC + | jz ->vm_leave_cp // No base? Just remove C frame. + | mov RA, RC + | mov PC, FRAME_CP + | jmp <2 // Else continue with the call. + | + |//----------------------------------------------------------------------- + |//-- Metamethod handling ------------------------------------------------ + |//----------------------------------------------------------------------- + | + |//-- Continuation dispatch ---------------------------------------------- + | + |->cont_dispatch: + | // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES) + | add RA, BASE + | and PC, -8 + | mov RB, BASE + | sub BASE, PC // Restore caller BASE. + | mov dword [RA+RD*8-4], LJ_TNIL // Ensure one valid arg. + | mov RC, RA // ... in [RC] + | mov PC, [RB-12] // Restore PC from [cont|PC]. + |.if X64 + | movsxd RAa, dword [RB-16] // May be negative on WIN64 with debug. + |.if FFI + | cmp RA, 1 + | jbe >1 + |.endif + | lea KBASEa, qword [=>0] + | add RAa, KBASEa + |.else + | mov RA, dword [RB-16] + |.if FFI + | cmp RA, 1 + | jbe >1 + |.endif + |.endif + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | // BASE = base, RC = result, RB = meta base + | jmp RAa // Jump to continuation. + | + |.if FFI + |1: + | je ->cont_ffi_callback // cont = 1: return from FFI callback. + | // cont = 0: Tail call from C function. + | sub RB, BASE + | shr RB, 3 + | lea RD, [RB-1] + | jmp ->vm_call_tail + |.endif + | + |->cont_cat: // BASE = base, RC = result, RB = mbase + | movzx RA, PC_RB + | sub RB, 16 + | lea RA, [BASE+RA*8] + | sub RA, RB + | je ->cont_ra + | neg RA + | shr RA, 3 + |.if X64WIN + | mov CARG3d, RA + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | mov RCa, [RC] + | mov [RB], RCa + | mov CARG2d, RB + |.elif X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | mov CARG3d, RA + | mov RAa, [RC] + | mov [RB], RAa + | mov CARG2d, RB + |.else + | mov ARG3, RA + | mov RA, [RC+4] + | mov RC, [RC] + | mov [RB+4], RA + | mov [RB], RC + | mov ARG2, RB + |.endif + | jmp ->BC_CAT_Z + | + |//-- Table indexing metamethods ----------------------------------------- + | + |->vmeta_tgets: + | mov TMP1, RC // RC = GCstr * + | mov TMP2, LJ_TSTR + | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2. + | cmp PC_OP, BC_GGET + | jne >1 + | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. + | mov [RA], TAB:RB // RB = GCtab * + | mov dword [RA+4], LJ_TTAB + | mov RB, RA + | jmp >2 + | + |->vmeta_tgetb: + | movzx RC, PC_RC + |.if DUALNUM + | mov TMP2, LJ_TISNUM + | mov TMP1, RC + |.elif SSE + | cvtsi2sd xmm0, RC + | movsd TMPQ, xmm0 + |.else + | mov ARG4, RC + | fild ARG4 + | fstp TMPQ + |.endif + | lea RCa, TMPQ // Store temp. TValue in TMPQ. + | jmp >1 + | + |->vmeta_tgetv: + | movzx RC, PC_RC // Reload TValue *k from RC. + | lea RC, [BASE+RC*8] + |1: + | movzx RB, PC_RB // Reload TValue *t from RB. + | lea RB, [BASE+RB*8] + |2: + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RB + | mov CARG3, RCa // May be 64 bit ptr to stack. + | mov L:RB, L:CARG1d + |.else + | mov ARG2, RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) + | // TValue * (finished) or NULL (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz >3 + |->cont_ra: // BASE = base, RC = result + | movzx RA, PC_RA + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC+4] + | mov RC, [RC] + | mov [BASE+RA*8+4], RB + | mov [BASE+RA*8], RC + |.endif + | ins_next + | + |3: // Call __index metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k + | mov RA, L:RB->top + | mov [RA-12], PC // [cont|PC] + | lea PC, [RA+FRAME_CONT] + | sub PC, BASE + | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here. + | mov NARGS:RD, 2+1 // 2 args for func(t, k). + | jmp ->vm_call_dispatch_f + | + |//----------------------------------------------------------------------- + | + |->vmeta_tsets: + | mov TMP1, RC // RC = GCstr * + | mov TMP2, LJ_TSTR + | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2. + | cmp PC_OP, BC_GSET + | jne >1 + | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. + | mov [RA], TAB:RB // RB = GCtab * + | mov dword [RA+4], LJ_TTAB + | mov RB, RA + | jmp >2 + | + |->vmeta_tsetb: + | movzx RC, PC_RC + |.if DUALNUM + | mov TMP2, LJ_TISNUM + | mov TMP1, RC + |.elif SSE + | cvtsi2sd xmm0, RC + | movsd TMPQ, xmm0 + |.else + | mov ARG4, RC + | fild ARG4 + | fstp TMPQ + |.endif + | lea RCa, TMPQ // Store temp. TValue in TMPQ. + | jmp >1 + | + |->vmeta_tsetv: + | movzx RC, PC_RC // Reload TValue *k from RC. + | lea RC, [BASE+RC*8] + |1: + | movzx RB, PC_RB // Reload TValue *t from RB. + | lea RB, [BASE+RB*8] + |2: + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RB + | mov CARG3, RCa // May be 64 bit ptr to stack. + | mov L:RB, L:CARG1d + |.else + | mov ARG2, RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) + | // TValue * (finished) or NULL (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz >3 + | // NOBARRIER: lj_meta_tset ensures the table is not black. + | movzx RA, PC_RA + |.if X64 + | mov RBa, [BASE+RA*8] + | mov [RC], RBa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + |->cont_nop: // BASE = base, (RC = result) + | ins_next + | + |3: // Call __newindex metamethod. + | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) + | mov RA, L:RB->top + | mov [RA-12], PC // [cont|PC] + | movzx RC, PC_RA + | // Copy value to third argument. + |.if X64 + | mov RBa, [BASE+RC*8] + | mov [RA+16], RBa + |.else + | mov RB, [BASE+RC*8+4] + | mov RC, [BASE+RC*8] + | mov [RA+20], RB + | mov [RA+16], RC + |.endif + | lea PC, [RA+FRAME_CONT] + | sub PC, BASE + | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here. + | mov NARGS:RD, 3+1 // 3 args for func(t, k, v). + | jmp ->vm_call_dispatch_f + | + |//-- Comparison metamethods --------------------------------------------- + | + |->vmeta_comp: + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d == BASE. + |.if X64WIN + | lea CARG3d, [BASE+RD*8] + | lea CARG2d, [BASE+RA*8] + |.else + | lea CARG2d, [BASE+RA*8] + | lea CARG3d, [BASE+RD*8] + |.endif + | mov CARG1d, L:RB // Caveat: CARG1d/CARG4d == RA. + | movzx CARG4d, PC_OP + |.else + | movzx RB, PC_OP + | lea RD, [BASE+RD*8] + | lea RA, [BASE+RA*8] + | mov ARG4, RB + | mov L:RB, SAVE_L + | mov ARG3, RD + | mov ARG2, RA + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + |3: + | mov BASE, L:RB->base + | cmp RC, 1 + | ja ->vmeta_binop + |4: + | lea PC, [PC+4] + | jb >6 + |5: + | movzx RD, PC_RD + | branchPC RD + |6: + | ins_next + | + |->cont_condt: // BASE = base, RC = result + | add PC, 4 + | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is true. + | jb <5 + | jmp <6 + | + |->cont_condf: // BASE = base, RC = result + | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is false. + | jmp <4 + | + |->vmeta_equal: + | sub PC, 4 + |.if X64WIN + | mov CARG3d, RD + | mov CARG4d, RB + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d == BASE. + | mov CARG2d, RA + | mov CARG1d, L:RB // Caveat: CARG1d == RA. + |.elif X64 + | mov CARG2d, RA + | mov CARG4d, RB // Caveat: CARG4d == RA. + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG3d == BASE. + | mov CARG3d, RD + | mov CARG1d, L:RB + |.else + | mov ARG4, RB + | mov L:RB, SAVE_L + | mov ARG3, RD + | mov ARG2, RA + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + | jmp <3 + | + |->vmeta_equal_cd: + |.if FFI + | sub PC, 4 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG1, L:RB + | mov FCARG2, dword [PC-4] + | mov SAVE_PC, PC + | call extern lj_meta_equal_cd@8 // (lua_State *L, BCIns ins) + | // 0/1 or TValue * (metamethod) returned in eax (RC). + | jmp <3 + |.endif + | + |//-- Arithmetic metamethods --------------------------------------------- + | + |->vmeta_arith_vno: + |.if DUALNUM + | movzx RB, PC_RB + |.endif + |->vmeta_arith_vn: + | lea RC, [KBASE+RC*8] + | jmp >1 + | + |->vmeta_arith_nvo: + |.if DUALNUM + | movzx RC, PC_RC + |.endif + |->vmeta_arith_nv: + | lea RC, [KBASE+RC*8] + | lea RB, [BASE+RB*8] + | xchg RB, RC + | jmp >2 + | + |->vmeta_unm: + | lea RC, [BASE+RD*8] + | mov RB, RC + | jmp >2 + | + |->vmeta_arith_vvo: + |.if DUALNUM + | movzx RB, PC_RB + |.endif + |->vmeta_arith_vv: + | lea RC, [BASE+RC*8] + |1: + | lea RB, [BASE+RB*8] + |2: + | lea RA, [BASE+RA*8] + |.if X64WIN + | mov CARG3d, RB + | mov CARG4d, RC + | movzx RC, PC_OP + | mov ARG5d, RC + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d == BASE. + | mov CARG2d, RA + | mov CARG1d, L:RB // Caveat: CARG1d == RA. + |.elif X64 + | movzx CARG5d, PC_OP + | mov CARG2d, RA + | mov CARG4d, RC // Caveat: CARG4d == RA. + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG3d == BASE. + | mov CARG3d, RB + | mov L:RB, L:CARG1d + |.else + | mov ARG3, RB + | mov L:RB, SAVE_L + | mov ARG4, RC + | movzx RC, PC_OP + | mov ARG2, RA + | mov ARG5, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) + | // NULL (finished) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jz ->cont_nop + | + | // Call metamethod for binary op. + |->vmeta_binop: + | // BASE = base, RC = new base, stack = cont/func/o1/o2 + | mov RA, RC + | sub RC, BASE + | mov [RA-12], PC // [cont|PC] + | lea PC, [RC+FRAME_CONT] + | mov NARGS:RD, 2+1 // 2 args for func(o1, o2). + | jmp ->vm_call_dispatch + | + |->vmeta_len: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | lea FCARG2, [BASE+RD*8] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB + | mov SAVE_PC, PC + | call extern lj_meta_len@8 // (lua_State *L, TValue *o) + | // NULL (retry) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base +#if LJ_52 + | test RC, RC + | jne ->vmeta_binop // Binop call for compatibility. + | movzx RD, PC_RD + | mov TAB:FCARG1, [BASE+RD*8] + | jmp ->BC_LEN_Z +#else + | jmp ->vmeta_binop // Binop call for compatibility. +#endif + | + |//-- Call metamethod ---------------------------------------------------- + | + |->vmeta_call_ra: + | lea RA, [BASE+RA*8+8] + |->vmeta_call: // Resolve and call __call metamethod. + | // BASE = old base, RA = new base, RC = nargs+1, PC = return + | mov TMP2, RA // Save RA, RC for us. + | mov TMP1, NARGS:RD + | sub RA, 8 + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, RA + | lea CARG3d, [RA+NARGS:RD*8] + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | lea RC, [RA+NARGS:RD*8] + | mov L:RB, SAVE_L + | mov ARG2, RA + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE // This is the callers base! + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) + | mov BASE, L:RB->base + | mov RA, TMP2 + | mov NARGS:RD, TMP1 + | mov LFUNC:RB, [RA-8] + | add NARGS:RD, 1 + | // This is fragile. L->base must not move, KBASE must always be defined. + | cmp KBASE, BASE // Continue with CALLT if flag set. + | je ->BC_CALLT_Z + | mov BASE, RA + | ins_call // Otherwise call resolved metamethod. + | + |//-- Argument coercion for 'for' statement ------------------------------ + | + |->vmeta_for: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG2, RA // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | mov SAVE_PC, PC + | call extern lj_meta_for@8 // (lua_State *L, TValue *base) + | mov BASE, L:RB->base + | mov RC, [PC-4] + | movzx RA, RCH + | movzx OP, RCL + | shr RC, 16 + |.if X64 + | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Retry FORI or JFORI. + |.else + | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Retry FORI or JFORI. + |.endif + | + |//----------------------------------------------------------------------- + |//-- Fast functions ----------------------------------------------------- + |//----------------------------------------------------------------------- + | + |.macro .ffunc, name + |->ff_ .. name: + |.endmacro + | + |.macro .ffunc_1, name + |->ff_ .. name: + | cmp NARGS:RD, 1+1; jb ->fff_fallback + |.endmacro + | + |.macro .ffunc_2, name + |->ff_ .. name: + | cmp NARGS:RD, 2+1; jb ->fff_fallback + |.endmacro + | + |.macro .ffunc_n, name + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE] + |.endmacro + | + |.macro .ffunc_n, name, op + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | op + | fld qword [BASE] + |.endmacro + | + |.macro .ffunc_nsse, name, op + | .ffunc_1 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | op xmm0, qword [BASE] + |.endmacro + | + |.macro .ffunc_nsse, name + | .ffunc_nsse name, movsd + |.endmacro + | + |.macro .ffunc_nn, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE] + | fld qword [BASE+8] + |.endmacro + | + |.macro .ffunc_nnsse, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | movsd xmm0, qword [BASE] + | movsd xmm1, qword [BASE+8] + |.endmacro + | + |.macro .ffunc_nnr, name + | .ffunc_2 name + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback + | fld qword [BASE+8] + | fld qword [BASE] + |.endmacro + | + |// Inlined GC threshold check. Caveat: uses label 1. + |.macro ffgccheck + | mov RB, [DISPATCH+DISPATCH_GL(gc.total)] + | cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)] + | jb >1 + | call ->fff_gcstep + |1: + |.endmacro + | + |//-- Base library: checks ----------------------------------------------- + | + |.ffunc_1 assert + | mov RB, [BASE+4] + | cmp RB, LJ_TISTRUECOND; jae ->fff_fallback + | mov PC, [BASE-4] + | mov MULTRES, RD + | mov [BASE-4], RB + | mov RB, [BASE] + | mov [BASE-8], RB + | sub RD, 2 + | jz >2 + | mov RA, BASE + |1: + | add RA, 8 + |.if X64 + | mov RBa, [RA] + | mov [RA-8], RBa + |.else + | mov RB, [RA+4] + | mov [RA-4], RB + | mov RB, [RA] + | mov [RA-8], RB + |.endif + | sub RD, 1 + | jnz <1 + |2: + | mov RD, MULTRES + | jmp ->fff_res_ + | + |.ffunc_1 type + | mov RB, [BASE+4] + |.if X64 + | mov RA, RB + | sar RA, 15 + | cmp RA, -2 + | je >3 + |.endif + | mov RC, ~LJ_TNUMX + | not RB + | cmp RC, RB + | cmova RC, RB + |2: + | mov CFUNC:RB, [BASE-8] + | mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RC + | jmp ->fff_res1 + |.if X64 + |3: + | mov RC, ~LJ_TLIGHTUD + | jmp <2 + |.endif + | + |//-- Base library: getters and setters --------------------------------- + | + |.ffunc_1 getmetatable + | mov RB, [BASE+4] + | mov PC, [BASE-4] + | cmp RB, LJ_TTAB; jne >6 + |1: // Field metatable must be at same offset for GCtab and GCudata! + | mov TAB:RB, [BASE] + | mov TAB:RB, TAB:RB->metatable + |2: + | test TAB:RB, TAB:RB + | mov dword [BASE-4], LJ_TNIL + | jz ->fff_res1 + | mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)] + | mov dword [BASE-4], LJ_TTAB // Store metatable as default result. + | mov [BASE-8], TAB:RB + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | add NODE:RA, TAB:RB->node + |3: // Rearranged logic, because we expect _not_ to find the key. + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >4 + | cmp dword NODE:RA->key.gcr, STR:RC + | je >5 + |4: + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <3 + | jmp ->fff_res1 // Not found, keep default result. + |5: + | mov RB, [RA+4] + | cmp RB, LJ_TNIL; je ->fff_res1 // Ditto for nil value. + | mov RC, [RA] + | mov [BASE-4], RB // Return value of mt.__metatable. + | mov [BASE-8], RC + | jmp ->fff_res1 + | + |6: + | cmp RB, LJ_TUDATA; je <1 + |.if X64 + | cmp RB, LJ_TNUMX; ja >8 + | cmp RB, LJ_TISNUM; jbe >7 + | mov RB, LJ_TLIGHTUD + | jmp >8 + |7: + |.else + | cmp RB, LJ_TISNUM; ja >8 + |.endif + | mov RB, LJ_TNUMX + |8: + | not RB + | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])] + | jmp <2 + | + |.ffunc_2 setmetatable + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | // Fast path: no mt for table yet and not clearing the mt. + | mov TAB:RB, [BASE] + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TTAB; jne ->fff_fallback + | mov TAB:RC, [BASE+8] + | mov TAB:RB->metatable, TAB:RC + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TTAB // Return original table. + | mov [BASE-8], TAB:RB + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jz >1 + | // Possible write barrier. Table is black, but skip iswhite(mt) check. + | barrierback TAB:RB, RC + |1: + | jmp ->fff_res1 + | + |.ffunc_2 rawget + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + |.if X64WIN + | mov RB, BASE // Save BASE. + | lea CARG3d, [BASE+8] + | mov CARG2d, [BASE] // Caveat: CARG2d == BASE. + | mov CARG1d, SAVE_L + |.elif X64 + | mov RB, BASE // Save BASE. + | mov CARG2d, [BASE] + | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE. + | mov CARG1d, SAVE_L + |.else + | mov TAB:RD, [BASE] + | mov L:RB, SAVE_L + | mov ARG2, TAB:RD + | mov ARG1, L:RB + | mov RB, BASE // Save BASE. + | add BASE, 8 + | mov ARG3, BASE + |.endif + | call extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) + | // cTValue * returned in eax (RD). + | mov BASE, RB // Restore BASE. + | // Copy table slot. + |.if X64 + | mov RBa, [RD] + | mov PC, [BASE-4] + | mov [BASE-8], RBa + |.else + | mov RB, [RD] + | mov RD, [RD+4] + | mov PC, [BASE-4] + | mov [BASE-8], RB + | mov [BASE-4], RD + |.endif + | jmp ->fff_res1 + | + |//-- Base library: conversions ------------------------------------------ + | + |.ffunc tonumber + | // Only handles the number case inline (without a base argument). + | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument. + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >1 + | mov RB, dword [BASE]; jmp ->fff_resi + |1: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE]; jmp ->fff_resxmm0 + |.else + | fld qword [BASE]; jmp ->fff_resn + |.endif + | + |.ffunc_1 tostring + | // Only handles the string or number case inline. + | mov PC, [BASE-4] + | cmp dword [BASE+4], LJ_TSTR; jne >3 + | // A __tostring method in the string base metatable is ignored. + | mov STR:RD, [BASE] + |2: + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RD + | jmp ->fff_res1 + |3: // Handle numbers inline, unless a number base metatable is present. + | cmp dword [BASE+4], LJ_TISNUM; ja ->fff_fallback + | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0 + | jne ->fff_fallback + | ffgccheck // Caveat: uses label 1. + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Add frame since C call can throw. + | mov SAVE_PC, PC // Redundant (but a defined value). + |.if X64 and not X64WIN + | mov FCARG2, BASE // Otherwise: FCARG2 == BASE + |.endif + | mov L:FCARG1, L:RB + |.if DUALNUM + | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o) + |.else + | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np) + |.endif + | // GCstr returned in eax (RD). + | mov BASE, L:RB->base + | jmp <2 + | + |//-- Base library: iterators ------------------------------------------- + | + |.ffunc_1 next + | je >2 // Missing 2nd arg? + |1: + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Add frame since C call can throw. + | mov L:RB->top, BASE // Dummy frame length is ok. + | mov PC, [BASE-4] + |.if X64WIN + | lea CARG3d, [BASE+8] + | mov CARG2d, [BASE] // Caveat: CARG2d == BASE. + | mov CARG1d, L:RB + |.elif X64 + | mov CARG2d, [BASE] + | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE. + | mov CARG1d, L:RB + |.else + | mov TAB:RD, [BASE] + | mov ARG2, TAB:RD + | mov ARG1, L:RB + | add BASE, 8 + | mov ARG3, BASE + |.endif + | mov SAVE_PC, PC // Needed for ITERN fallback. + | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) + | // Flag returned in eax (RD). + | mov BASE, L:RB->base + | test RD, RD; jz >3 // End of traversal? + | // Copy key and value to results. + |.if X64 + | mov RBa, [BASE+8] + | mov RDa, [BASE+16] + | mov [BASE-8], RBa + | mov [BASE], RDa + |.else + | mov RB, [BASE+8] + | mov RD, [BASE+12] + | mov [BASE-8], RB + | mov [BASE-4], RD + | mov RB, [BASE+16] + | mov RD, [BASE+20] + | mov [BASE], RB + | mov [BASE+4], RD + |.endif + |->fff_res2: + | mov RD, 1+2 + | jmp ->fff_res + |2: // Set missing 2nd arg to nil. + | mov dword [BASE+12], LJ_TNIL + | jmp <1 + |3: // End of traversal: return nil. + | mov dword [BASE-4], LJ_TNIL + | jmp ->fff_res1 + | + |.ffunc_1 pairs + | mov TAB:RB, [BASE] + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback +#if LJ_52 + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback +#endif + | mov CFUNC:RB, [BASE-8] + | mov CFUNC:RD, CFUNC:RB->upvalue[0] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TFUNC + | mov [BASE-8], CFUNC:RD + | mov dword [BASE+12], LJ_TNIL + | mov RD, 1+3 + | jmp ->fff_res + | + |.ffunc_1 ipairs_aux + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | mov PC, [BASE-4] + |.if DUALNUM + | mov RD, dword [BASE+8] + | add RD, 1 + | mov dword [BASE-4], LJ_TISNUM + | mov dword [BASE-8], RD + |.elif SSE + | movsd xmm0, qword [BASE+8] + | sseconst_1 xmm1, RBa + | addsd xmm0, xmm1 + | cvtsd2si RD, xmm0 + | movsd qword [BASE-8], xmm0 + |.else + | fld qword [BASE+8] + | fld1 + | faddp st1 + | fist ARG1 + | fstp qword [BASE-8] + | mov RD, ARG1 + |.endif + | mov TAB:RB, [BASE] + | cmp RD, TAB:RB->asize; jae >2 // Not in array part? + | shl RD, 3 + | add RD, TAB:RB->array + |1: + | cmp dword [RD+4], LJ_TNIL; je ->fff_res0 + | // Copy array slot. + |.if X64 + | mov RBa, [RD] + | mov [BASE], RBa + |.else + | mov RB, [RD] + | mov RD, [RD+4] + | mov [BASE], RB + | mov [BASE+4], RD + |.endif + | jmp ->fff_res2 + |2: // Check for empty hash part first. Otherwise call C function. + | cmp dword TAB:RB->hmask, 0; je ->fff_res0 + | mov FCARG1, TAB:RB + | mov RB, BASE // Save BASE. + | mov FCARG2, RD // Caveat: FCARG2 == BASE + | call extern lj_tab_getinth@8 // (GCtab *t, int32_t key) + | // cTValue * or NULL returned in eax (RD). + | mov BASE, RB + | test RD, RD + | jnz <1 + |->fff_res0: + | mov RD, 1+0 + | jmp ->fff_res + | + |.ffunc_1 ipairs + | mov TAB:RB, [BASE] + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback +#if LJ_52 + | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback +#endif + | mov CFUNC:RB, [BASE-8] + | mov CFUNC:RD, CFUNC:RB->upvalue[0] + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TFUNC + | mov [BASE-8], CFUNC:RD + |.if DUALNUM + | mov dword [BASE+12], LJ_TISNUM + | mov dword [BASE+8], 0 + |.elif SSE + | xorps xmm0, xmm0 + | movsd qword [BASE+8], xmm0 + |.else + | fldz + | fstp qword [BASE+8] + |.endif + | mov RD, 1+3 + | jmp ->fff_res + | + |//-- Base library: catch errors ---------------------------------------- + | + |.ffunc_1 pcall + | lea RA, [BASE+8] + | sub NARGS:RD, 1 + | mov PC, 8+FRAME_PCALL + |1: + | movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)] + | shr RB, HOOK_ACTIVE_SHIFT + | and RB, 1 + | add PC, RB // Remember active hook before pcall. + | jmp ->vm_call_dispatch + | + |.ffunc_2 xpcall + | cmp dword [BASE+12], LJ_TFUNC; jne ->fff_fallback + | mov RB, [BASE+4] // Swap function and traceback. + | mov [BASE+12], RB + | mov dword [BASE+4], LJ_TFUNC + | mov LFUNC:RB, [BASE] + | mov PC, [BASE+8] + | mov [BASE+8], LFUNC:RB + | mov [BASE], PC + | lea RA, [BASE+16] + | sub NARGS:RD, 2 + | mov PC, 16+FRAME_PCALL + | jmp <1 + | + |//-- Coroutine library -------------------------------------------------- + | + |.macro coroutine_resume_wrap, resume + |.if resume + |.ffunc_1 coroutine_resume + | mov L:RB, [BASE] + |.else + |.ffunc coroutine_wrap_aux + | mov CFUNC:RB, [BASE-8] + | mov L:RB, CFUNC:RB->upvalue[0].gcr + |.endif + | mov PC, [BASE-4] + | mov SAVE_PC, PC + |.if X64 + | mov TMP1, L:RB + |.else + | mov ARG1, L:RB + |.endif + |.if resume + | cmp dword [BASE+4], LJ_TTHREAD; jne ->fff_fallback + |.endif + | cmp aword L:RB->cframe, 0; jne ->fff_fallback + | cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback + | mov RA, L:RB->top + | je >1 // Status != LUA_YIELD (i.e. 0)? + | cmp RA, L:RB->base // Check for presence of initial func. + | je ->fff_fallback + |1: + |.if resume + | lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread). + |.else + | lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1). + |.endif + | cmp PC, L:RB->maxstack; ja ->fff_fallback + | mov L:RB->top, PC + | + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + |.if resume + | add BASE, 8 // Keep resumed thread in stack for GC. + |.endif + | mov L:RB->top, BASE + |.if resume + | lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move. + |.else + | lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move. + |.endif + | sub RBa, PCa // Relative to PC. + | + | cmp PC, RA + | je >3 + |2: // Move args to coroutine. + |.if X64 + | mov RCa, [PC+RB] + | mov [PC-8], RCa + |.else + | mov RC, [PC+RB+4] + | mov [PC-4], RC + | mov RC, [PC+RB] + | mov [PC-8], RC + |.endif + | sub PC, 8 + | cmp PC, RA + | jne <2 + |3: + |.if X64 + | mov CARG2d, RA + | mov CARG1d, TMP1 + |.else + | mov ARG2, RA + | xor RA, RA + | mov ARG4, RA + | mov ARG3, RA + |.endif + | call ->vm_resume // (lua_State *L, TValue *base, 0, 0) + | set_vmstate INTERP + | + | mov L:RB, SAVE_L + |.if X64 + | mov L:PC, TMP1 + |.else + | mov L:PC, ARG1 // The callee doesn't modify SAVE_L. + |.endif + | mov BASE, L:RB->base + | cmp eax, LUA_YIELD + | ja >8 + |4: + | mov RA, L:PC->base + | mov KBASE, L:PC->top + | mov L:PC->top, RA // Clear coroutine stack. + | mov PC, KBASE + | sub PC, RA + | je >6 // No results? + | lea RD, [BASE+PC] + | shr PC, 3 + | cmp RD, L:RB->maxstack + | ja >9 // Need to grow stack? + | + | mov RB, BASE + | sub RBa, RAa + |5: // Move results from coroutine. + |.if X64 + | mov RDa, [RA] + | mov [RA+RB], RDa + |.else + | mov RD, [RA] + | mov [RA+RB], RD + | mov RD, [RA+4] + | mov [RA+RB+4], RD + |.endif + | add RA, 8 + | cmp RA, KBASE + | jne <5 + |6: + |.if resume + | lea RD, [PC+2] // nresults+1 = 1 + true + results. + | mov dword [BASE-4], LJ_TTRUE // Prepend true to results. + |.else + | lea RD, [PC+1] // nresults+1 = 1 + results. + |.endif + |7: + | mov PC, SAVE_PC + | mov MULTRES, RD + |.if resume + | mov RAa, -8 + |.else + | xor RA, RA + |.endif + | test PC, FRAME_TYPE + | jz ->BC_RET_Z + | jmp ->vm_return + | + |8: // Coroutine returned with error (at co->top-1). + |.if resume + | mov dword [BASE-4], LJ_TFALSE // Prepend false to results. + | mov RA, L:PC->top + | sub RA, 8 + | mov L:PC->top, RA // Clear error from coroutine stack. + | // Copy error message. + |.if X64 + | mov RDa, [RA] + | mov [BASE], RDa + |.else + | mov RD, [RA] + | mov [BASE], RD + | mov RD, [RA+4] + | mov [BASE+4], RD + |.endif + | mov RD, 1+2 // nresults+1 = 1 + false + error. + | jmp <7 + |.else + | mov FCARG2, L:PC + | mov FCARG1, L:RB + | call extern lj_ffh_coroutine_wrap_err@8 // (lua_State *L, lua_State *co) + | // Error function does not return. + |.endif + | + |9: // Handle stack expansion on return from yield. + |.if X64 + | mov L:RA, TMP1 + |.else + | mov L:RA, ARG1 // The callee doesn't modify SAVE_L. + |.endif + | mov L:RA->top, KBASE // Undo coroutine stack clearing. + | mov FCARG2, PC + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + |.if X64 + | mov L:PC, TMP1 + |.else + | mov L:PC, ARG1 + |.endif + | mov BASE, L:RB->base + | jmp <4 // Retry the stack move. + |.endmacro + | + | coroutine_resume_wrap 1 // coroutine.resume + | coroutine_resume_wrap 0 // coroutine.wrap + | + |.ffunc coroutine_yield + | mov L:RB, SAVE_L + | test aword L:RB->cframe, CFRAME_RESUME + | jz ->fff_fallback + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB->top, RD + | xor RD, RD + | mov aword L:RB->cframe, RDa + | mov al, LUA_YIELD + | mov byte L:RB->status, al + | jmp ->vm_leave_unw + | + |//-- Math library ------------------------------------------------------- + | + |.if not DUALNUM + |->fff_resi: // Dummy. + |.endif + | + |.if SSE + |->fff_resn: + | mov PC, [BASE-4] + | fstp qword [BASE-8] + | jmp ->fff_res1 + |.endif + | + | .ffunc_1 math_abs + |.if DUALNUM + | cmp dword [BASE+4], LJ_TISNUM; jne >2 + | mov RB, dword [BASE] + | cmp RB, 0; jns ->fff_resi + | neg RB; js >1 + |->fff_resbit: + |->fff_resi: + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TISNUM + | mov dword [BASE-8], RB + | jmp ->fff_res1 + |1: + | mov PC, [BASE-4] + | mov dword [BASE-4], 0x41e00000 // 2^31. + | mov dword [BASE-8], 0 + | jmp ->fff_res1 + |2: + | ja ->fff_fallback + |.else + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + |.endif + | + |.if SSE + | movsd xmm0, qword [BASE] + | sseconst_abs xmm1, RDa + | andps xmm0, xmm1 + |->fff_resxmm0: + | mov PC, [BASE-4] + | movsd qword [BASE-8], xmm0 + | // fallthrough + |.else + | fld qword [BASE] + | fabs + | // fallthrough + |->fff_resxmm0: // Dummy. + |->fff_resn: + | mov PC, [BASE-4] + | fstp qword [BASE-8] + |.endif + | + |->fff_res1: + | mov RD, 1+1 + |->fff_res: + | mov MULTRES, RD + |->fff_res_: + | test PC, FRAME_TYPE + | jnz >7 + |5: + | cmp PC_RB, RDL // More results expected? + | ja >6 + | // Adjust BASE. KBASE is assumed to be set for the calling frame. + | movzx RA, PC_RA + | not RAa // Note: ~RA = -(RA+1) + | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 + | ins_next + | + |6: // Fill up results with nil. + | mov dword [BASE+RD*8-12], LJ_TNIL + | add RD, 1 + | jmp <5 + | + |7: // Non-standard return case. + | mov RAa, -8 // Results start at BASE+RA = BASE-8. + | jmp ->vm_return + | + |.macro math_round, func + | .ffunc math_ .. func + |.if DUALNUM + | cmp dword [BASE+4], LJ_TISNUM; jne >1 + | mov RB, dword [BASE]; jmp ->fff_resi + |1: + | ja ->fff_fallback + |.else + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE] + | call ->vm_ .. func + | .if DUALNUM + | cvtsd2si RB, xmm0 + | cmp RB, 0x80000000 + | jne ->fff_resi + | cvtsi2sd xmm1, RB + | ucomisd xmm0, xmm1 + | jp ->fff_resxmm0 + | je ->fff_resi + | .endif + | jmp ->fff_resxmm0 + |.else + | fld qword [BASE] + | call ->vm_ .. func + | .if DUALNUM + | fist ARG1 + | mov RB, ARG1 + | cmp RB, 0x80000000; jne >2 + | fdup + | fild ARG1 + | fcomparepp + | jp ->fff_resn + | jne ->fff_resn + |2: + | fpop + | jmp ->fff_resi + | .else + | jmp ->fff_resn + | .endif + |.endif + |.endmacro + | + | math_round floor + | math_round ceil + | + |.if SSE + |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0 + |.else + |.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn + |.endif + | + |.ffunc math_log + | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument. + | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback + | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn + | + |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn + |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn + | + |.ffunc_n math_sin; fsin; jmp ->fff_resn + |.ffunc_n math_cos; fcos; jmp ->fff_resn + |.ffunc_n math_tan; fptan; fpop; jmp ->fff_resn + | + |.ffunc_n math_asin + | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fpatan + | jmp ->fff_resn + |.ffunc_n math_acos + | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fxch; fpatan + | jmp ->fff_resn + |.ffunc_n math_atan; fld1; fpatan; jmp ->fff_resn + | + |.macro math_extern, func + |.if SSE + | .ffunc_nsse math_ .. func + | .if not X64 + | movsd FPARG1, xmm0 + | .endif + |.else + | .ffunc_n math_ .. func + | fstp FPARG1 + |.endif + | mov RB, BASE + | call extern lj_vm_ .. func + | mov BASE, RB + | .if X64 + | jmp ->fff_resxmm0 + | .else + | jmp ->fff_resn + | .endif + |.endmacro + | + | math_extern sinh + | math_extern cosh + | math_extern tanh + | + |->ff_math_deg: + |.if SSE + |.ffunc_nsse math_rad + | mov CFUNC:RB, [BASE-8] + | mulsd xmm0, qword CFUNC:RB->upvalue[0] + | jmp ->fff_resxmm0 + |.else + |.ffunc_n math_rad + | mov CFUNC:RB, [BASE-8] + | fmul qword CFUNC:RB->upvalue[0] + | jmp ->fff_resn + |.endif + | + |.ffunc_nn math_atan2; fpatan; jmp ->fff_resn + |.ffunc_nnr math_ldexp; fscale; fpop1; jmp ->fff_resn + | + |.ffunc_1 math_frexp + | mov RB, [BASE+4] + | cmp RB, LJ_TISNUM; jae ->fff_fallback + | mov PC, [BASE-4] + | mov RC, [BASE] + | mov [BASE-4], RB; mov [BASE-8], RC + | shl RB, 1; cmp RB, 0xffe00000; jae >3 + | or RC, RB; jz >3 + | mov RC, 1022 + | cmp RB, 0x00200000; jb >4 + |1: + | shr RB, 21; sub RB, RC // Extract and unbias exponent. + |.if SSE + | cvtsi2sd xmm0, RB + |.else + | mov TMP1, RB; fild TMP1 + |.endif + | mov RB, [BASE-4] + | and RB, 0x800fffff // Mask off exponent. + | or RB, 0x3fe00000 // Put mantissa in range [0.5,1) or 0. + | mov [BASE-4], RB + |2: + |.if SSE + | movsd qword [BASE], xmm0 + |.else + | fstp qword [BASE] + |.endif + | mov RD, 1+2 + | jmp ->fff_res + |3: // Return +-0, +-Inf, NaN unmodified and an exponent of 0. + |.if SSE + | xorps xmm0, xmm0; jmp <2 + |.else + | fldz; jmp <2 + |.endif + |4: // Handle denormals by multiplying with 2^54 and adjusting the bias. + |.if SSE + | movsd xmm0, qword [BASE] + | sseconst_hi xmm1, RBa, 43500000 // 2^54. + | mulsd xmm0, xmm1 + | movsd qword [BASE-8], xmm0 + |.else + | fld qword [BASE] + | mov TMP1, 0x5a800000; fmul TMP1 // x = x*2^54 + | fstp qword [BASE-8] + |.endif + | mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1 + | + |.if SSE + |.ffunc_nsse math_modf + |.else + |.ffunc_n math_modf + |.endif + | mov RB, [BASE+4] + | mov PC, [BASE-4] + | shl RB, 1; cmp RB, 0xffe00000; je >4 // +-Inf? + |.if SSE + | movaps xmm4, xmm0 + | call ->vm_trunc + | subsd xmm4, xmm0 + |1: + | movsd qword [BASE-8], xmm0 + | movsd qword [BASE], xmm4 + |.else + | fdup + | call ->vm_trunc + | fsub st1, st0 + |1: + | fstp qword [BASE-8] + | fstp qword [BASE] + |.endif + | mov RC, [BASE-4]; mov RB, [BASE+4] + | xor RC, RB; js >3 // Need to adjust sign? + |2: + | mov RD, 1+2 + | jmp ->fff_res + |3: + | xor RB, 0x80000000; mov [BASE+4], RB // Flip sign of fraction. + | jmp <2 + |4: + |.if SSE + | xorps xmm4, xmm4; jmp <1 // Return +-Inf and +-0. + |.else + | fldz; fxch; jmp <1 // Return +-Inf and +-0. + |.endif + | + |.ffunc_nnr math_fmod + |1: ; fprem; fnstsw ax; sahf; jp <1 + | fpop1 + | jmp ->fff_resn + | + |.if SSE + |.ffunc_nnsse math_pow; call ->vm_pow; jmp ->fff_resxmm0 + |.else + |.ffunc_nn math_pow; call ->vm_pow; jmp ->fff_resn + |.endif + | + |.macro math_minmax, name, cmovop, fcmovop, sseop + | .ffunc name + | mov RA, 2 + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >4 + | mov RB, dword [BASE] + |1: // Handle integers. + | cmp RA, RD; jae ->fff_resi + | cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3 + | cmp RB, dword [BASE+RA*8-8] + | cmovop RB, dword [BASE+RA*8-8] + | add RA, 1 + | jmp <1 + |3: + | ja ->fff_fallback + | // Convert intermediate result to number and continue below. + |.if SSE + | cvtsi2sd xmm0, RB + |.else + | mov TMP1, RB + | fild TMP1 + |.endif + | jmp >6 + |4: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | + |.if SSE + | movsd xmm0, qword [BASE] + |5: // Handle numbers or integers. + | cmp RA, RD; jae ->fff_resxmm0 + | cmp dword [BASE+RA*8-4], LJ_TISNUM + |.if DUALNUM + | jb >6 + | ja ->fff_fallback + | cvtsi2sd xmm1, dword [BASE+RA*8-8] + | jmp >7 + |.else + | jae ->fff_fallback + |.endif + |6: + | movsd xmm1, qword [BASE+RA*8-8] + |7: + | sseop xmm0, xmm1 + | add RA, 1 + | jmp <5 + |.else + | fld qword [BASE] + |5: // Handle numbers or integers. + | cmp RA, RD; jae ->fff_resn + | cmp dword [BASE+RA*8-4], LJ_TISNUM + |.if DUALNUM + | jb >6 + | ja >9 + | fild dword [BASE+RA*8-8] + | jmp >7 + |.else + | jae >9 + |.endif + |6: + | fld qword [BASE+RA*8-8] + |7: + | fucomi st1; fcmovop st1; fpop1 + | add RA, 1 + | jmp <5 + |.endif + |.endmacro + | + | math_minmax math_min, cmovg, fcmovnbe, minsd + | math_minmax math_max, cmovl, fcmovbe, maxsd + |.if not SSE + |9: + | fpop; jmp ->fff_fallback + |.endif + | + |//-- String library ----------------------------------------------------- + | + |.ffunc_1 string_len + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + |.if DUALNUM + | mov RB, dword STR:RB->len; jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, dword STR:RB->len; jmp ->fff_resxmm0 + |.else + | fild dword STR:RB->len; jmp ->fff_resn + |.endif + | + |.ffunc string_byte // Only handle the 1-arg case here. + | cmp NARGS:RD, 1+1; jne ->fff_fallback + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov PC, [BASE-4] + | cmp dword STR:RB->len, 1 + | jb ->fff_res0 // Return no results for empty string. + | movzx RB, byte STR:RB[1] + |.if DUALNUM + | jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, RB; jmp ->fff_resxmm0 + |.else + | mov TMP1, RB; fild TMP1; jmp ->fff_resn + |.endif + | + |.ffunc string_char // Only handle the 1-arg case here. + | ffgccheck + | cmp NARGS:RD, 1+1; jne ->fff_fallback // *Exactly* 1 arg. + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + | mov RB, dword [BASE] + | cmp RB, 255; ja ->fff_fallback + | mov TMP2, RB + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RB, qword [BASE] + | cmp RB, 255; ja ->fff_fallback + | mov TMP2, RB + |.else + | jae ->fff_fallback + | fld qword [BASE] + | fistp TMP2 + | cmp TMP2, 255; ja ->fff_fallback + |.endif + |.if X64 + | mov TMP3, 1 + |.else + | mov ARG3, 1 + |.endif + | lea RDa, TMP2 // Points to stack. Little-endian. + |->fff_newstr: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + |.if X64 + | mov CARG3d, TMP3 // Zero-extended to size_t. + | mov CARG2, RDa // May be 64 bit ptr to stack. + | mov CARG1d, L:RB + |.else + | mov ARG2, RD + | mov ARG1, L:RB + |.endif + | mov SAVE_PC, PC + | call extern lj_str_new // (lua_State *L, char *str, size_t l) + | // GCstr * returned in eax (RD). + | mov BASE, L:RB->base + | mov PC, [BASE-4] + | mov dword [BASE-4], LJ_TSTR + | mov [BASE-8], STR:RD + | jmp ->fff_res1 + | + |.ffunc string_sub + | ffgccheck + | mov TMP2, -1 + | cmp NARGS:RD, 1+2; jb ->fff_fallback + | jna >1 + | cmp dword [BASE+20], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + | mov RB, dword [BASE+16] + | mov TMP2, RB + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RB, qword [BASE+16] + | mov TMP2, RB + |.else + | jae ->fff_fallback + | fld qword [BASE+16] + | fistp TMP2 + |.endif + |1: + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + |.if DUALNUM + | jne ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + | mov STR:RB, [BASE] + | mov TMP3, STR:RB + | mov RB, STR:RB->len + |.if DUALNUM + | mov RA, dword [BASE+8] + |.elif SSE + | cvttsd2si RA, qword [BASE+8] + |.else + | fld qword [BASE+8] + | fistp ARG3 + | mov RA, ARG3 + |.endif + | mov RC, TMP2 + | cmp RB, RC // len < end? (unsigned compare) + | jb >5 + |2: + | test RA, RA // start <= 0? + | jle >7 + |3: + | mov STR:RB, TMP3 + | sub RC, RA // start > end? + | jl ->fff_emptystr + | lea RB, [STR:RB+RA+#STR-1] + | add RC, 1 + |4: + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov RD, RB + | jmp ->fff_newstr + | + |5: // Negative end or overflow. + | jl >6 + | lea RC, [RC+RB+1] // end = end+(len+1) + | jmp <2 + |6: // Overflow. + | mov RC, RB // end = len + | jmp <2 + | + |7: // Negative start or underflow. + | je >8 + | add RA, RB // start = start+(len+1) + | add RA, 1 + | jg <3 // start > 0? + |8: // Underflow. + | mov RA, 1 // start = 1 + | jmp <3 + | + |->fff_emptystr: // Range underflow. + | xor RC, RC // Zero length. Any ptr in RB is ok. + | jmp <4 + | + |.ffunc string_rep // Only handle the 1-char case inline. + | ffgccheck + | cmp NARGS:RD, 2+1; jne ->fff_fallback // Exactly 2 arguments. + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | cmp dword [BASE+12], LJ_TISNUM + | mov STR:RB, [BASE] + |.if DUALNUM + | jne ->fff_fallback + | mov RC, dword [BASE+8] + |.elif SSE + | jae ->fff_fallback + | cvttsd2si RC, qword [BASE+8] + |.else + | jae ->fff_fallback + | fld qword [BASE+8] + | fistp TMP2 + | mov RC, TMP2 + |.endif + | test RC, RC + | jle ->fff_emptystr // Count <= 0? (or non-int) + | cmp dword STR:RB->len, 1 + | jb ->fff_emptystr // Zero length string? + | jne ->fff_fallback_2 // Fallback for > 1-char strings. + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_2 + | movzx RA, byte STR:RB[1] + | mov RB, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). + | mov [RB], RAL + | add RB, 1 + | sub RC, 1 + | jnz <1 + | mov RD, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + | jmp ->fff_newstr + | + |.ffunc_1 string_reverse + | ffgccheck + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov RC, STR:RB->len + | test RC, RC + | jz ->fff_emptystr // Zero length string? + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1 + | add RB, #STR + | mov TMP2, PC // Need another temp register. + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + |1: + | movzx RA, byte [RB] + | add RB, 1 + | sub RC, 1 + | mov [PC+RC], RAL + | jnz <1 + | mov RD, PC + | mov PC, TMP2 + | jmp ->fff_newstr + | + |.macro ffstring_case, name, lo, hi + | .ffunc_1 name + | ffgccheck + | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback + | mov STR:RB, [BASE] + | mov RC, STR:RB->len + | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1 + | add RB, #STR + | mov TMP2, PC // Need another temp register. + |.if X64 + | mov TMP3, RC + |.else + | mov ARG3, RC + |.endif + | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)] + | jmp >3 + |1: // ASCII case conversion. Yes, this is suboptimal code (do you care?). + | movzx RA, byte [RB+RC] + | cmp RA, lo + | jb >2 + | cmp RA, hi + | ja >2 + | xor RA, 0x20 + |2: + | mov [PC+RC], RAL + |3: + | sub RC, 1 + | jns <1 + | mov RD, PC + | mov PC, TMP2 + | jmp ->fff_newstr + |.endmacro + | + |ffstring_case string_lower, 0x41, 0x5a + |ffstring_case string_upper, 0x61, 0x7a + | + |//-- Table library ------------------------------------------------------ + | + |.ffunc_1 table_getn + | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback + | mov RB, BASE // Save BASE. + | mov TAB:FCARG1, [BASE] + | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t) + | // Length of table returned in eax (RD). + | mov BASE, RB // Restore BASE. + |.if DUALNUM + | mov RB, RD; jmp ->fff_resi + |.elif SSE + | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0 + |.else + | mov ARG1, RD; fild ARG1; jmp ->fff_resn + |.endif + | + |//-- Bit library -------------------------------------------------------- + | + |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!). + | + |.macro .ffunc_bit, name, kind + | .ffunc_1 name + |.if kind == 2 + |.if SSE + | sseconst_tobit xmm1, RBa + |.else + | mov TMP1, TOBIT_BIAS + |.endif + |.endif + | cmp dword [BASE+4], LJ_TISNUM + |.if DUALNUM + | jne >1 + | mov RB, dword [BASE] + |.if kind > 0 + | jmp >2 + |.else + | jmp ->fff_resbit + |.endif + |1: + | ja ->fff_fallback + |.else + | jae ->fff_fallback + |.endif + |.if SSE + | movsd xmm0, qword [BASE] + |.if kind < 2 + | sseconst_tobit xmm1, RBa + |.endif + | addsd xmm0, xmm1 + | movd RB, xmm0 + |.else + | fld qword [BASE] + |.if kind < 2 + | mov TMP1, TOBIT_BIAS + |.endif + | fadd TMP1 + | fstp FPARG1 + |.if kind > 0 + | mov RB, ARG1 + |.endif + |.endif + |2: + |.endmacro + | + |.ffunc_bit bit_tobit, 0 + |.if DUALNUM or SSE + |.if not SSE + | mov RB, ARG1 + |.endif + | jmp ->fff_resbit + |.else + | fild ARG1 + | jmp ->fff_resn + |.endif + | + |.macro .ffunc_bit_op, name, ins + | .ffunc_bit name, 2 + | mov TMP2, NARGS:RD // Save for fallback. + | lea RD, [BASE+NARGS:RD*8-16] + |1: + | cmp RD, BASE + | jbe ->fff_resbit + | cmp dword [RD+4], LJ_TISNUM + |.if DUALNUM + | jne >2 + | ins RB, dword [RD] + | sub RD, 8 + | jmp <1 + |2: + | ja ->fff_fallback_bit_op + |.else + | jae ->fff_fallback_bit_op + |.endif + |.if SSE + | movsd xmm0, qword [RD] + | addsd xmm0, xmm1 + | movd RA, xmm0 + | ins RB, RA + |.else + | fld qword [RD] + | fadd TMP1 + | fstp FPARG1 + | ins RB, ARG1 + |.endif + | sub RD, 8 + | jmp <1 + |.endmacro + | + |.ffunc_bit_op bit_band, and + |.ffunc_bit_op bit_bor, or + |.ffunc_bit_op bit_bxor, xor + | + |.ffunc_bit bit_bswap, 1 + | bswap RB + | jmp ->fff_resbit + | + |.ffunc_bit bit_bnot, 1 + | not RB + |.if DUALNUM + | jmp ->fff_resbit + |.elif SSE + |->fff_resbit: + | cvtsi2sd xmm0, RB + | jmp ->fff_resxmm0 + |.else + |->fff_resbit: + | mov ARG1, RB + | fild ARG1 + | jmp ->fff_resn + |.endif + | + |->fff_fallback_bit_op: + | mov NARGS:RD, TMP2 // Restore for fallback + | jmp ->fff_fallback + | + |.macro .ffunc_bit_sh, name, ins + |.if DUALNUM + | .ffunc_bit name, 1 + | // Note: no inline conversion from number for 2nd argument! + | cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback + | mov RA, dword [BASE+8] + |.elif SSE + | .ffunc_nnsse name + | sseconst_tobit xmm2, RBa + | addsd xmm0, xmm2 + | addsd xmm1, xmm2 + | movd RB, xmm0 + | movd RA, xmm1 + |.else + | .ffunc_nn name + | mov TMP1, TOBIT_BIAS + | fadd TMP1 + | fstp FPARG3 + | fadd TMP1 + | fstp FPARG1 + | mov RA, ARG3 + | mov RB, ARG1 + |.endif + | ins RB, cl // Assumes RA is ecx. + | jmp ->fff_resbit + |.endmacro + | + |.ffunc_bit_sh bit_lshift, shl + |.ffunc_bit_sh bit_rshift, shr + |.ffunc_bit_sh bit_arshift, sar + |.ffunc_bit_sh bit_rol, rol + |.ffunc_bit_sh bit_ror, ror + | + |//----------------------------------------------------------------------- + | + |->fff_fallback_2: + | mov NARGS:RD, 1+2 // Other args are ignored, anyway. + | jmp ->fff_fallback + |->fff_fallback_1: + | mov NARGS:RD, 1+1 // Other args are ignored, anyway. + |->fff_fallback: // Call fast function fallback handler. + | // BASE = new base, RD = nargs+1 + | mov L:RB, SAVE_L + | mov PC, [BASE-4] // Fallback may overwrite PC. + | mov SAVE_PC, PC // Redundant (but a defined value). + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | lea RA, [RD+8*LUA_MINSTACK] // Ensure enough space for handler. + | mov L:RB->top, RD + | mov CFUNC:RD, [BASE-8] + | cmp RA, L:RB->maxstack + | ja >5 // Need to grow stack. + |.if X64 + | mov CARG1d, L:RB + |.else + | mov ARG1, L:RB + |.endif + | call aword CFUNC:RD->f // (lua_State *L) + | mov BASE, L:RB->base + | // Either throws an error, or recovers and returns -1, 0 or nresults+1. + | test RD, RD; jg ->fff_res // Returned nresults+1? + |1: + | mov RA, L:RB->top + | sub RA, BASE + | shr RA, 3 + | test RD, RD + | lea NARGS:RD, [RA+1] + | mov LFUNC:RB, [BASE-8] + | jne ->vm_call_tail // Returned -1? + | ins_callt // Returned 0: retry fast path. + | + |// Reconstruct previous base for vmeta_call during tailcall. + |->vm_call_tail: + | mov RA, BASE + | test PC, FRAME_TYPE + | jnz >3 + | movzx RB, PC_RA + | not RBa // Note: ~RB = -(RB+1) + | lea BASE, [BASE+RB*8] // base = base - (RB+1)*8 + | jmp ->vm_call_dispatch // Resolve again for tailcall. + |3: + | mov RB, PC + | and RB, -8 + | sub BASE, RB + | jmp ->vm_call_dispatch // Resolve again for tailcall. + | + |5: // Grow stack for fallback handler. + | mov FCARG2, LUA_MINSTACK + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | xor RD, RD // Simulate a return 0. + | jmp <1 // Dumb retry (goes through ff first). + | + |->fff_gcstep: // Call GC step function. + | // BASE = new base, RD = nargs+1 + | pop RBa // Must keep stack at same level. + | mov TMPa, RBa // Save return address + | mov L:RB, SAVE_L + | mov SAVE_PC, PC // Redundant (but a defined value). + | mov L:RB->base, BASE + | lea RD, [BASE+NARGS:RD*8-8] + | mov FCARG1, L:RB + | mov L:RB->top, RD + | call extern lj_gc_step@4 // (lua_State *L) + | mov BASE, L:RB->base + | mov RD, L:RB->top + | sub RD, BASE + | shr RD, 3 + | add NARGS:RD, 1 + | mov RBa, TMPa + | push RBa // Restore return address. + | ret + | + |//----------------------------------------------------------------------- + |//-- Special dispatch targets ------------------------------------------- + |//----------------------------------------------------------------------- + | + |->vm_record: // Dispatch target for recording phase. + |.if JIT + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_VMEVENT // No recording while in vmevent. + | jnz >5 + | // Decrement the hookcount for consistency, but always do the call. + | test RDL, HOOK_ACTIVE + | jnz >1 + | test RDL, LUA_MASKLINE|LUA_MASKCOUNT + | jz >1 + | dec dword [DISPATCH+DISPATCH_GL(hookcount)] + | jmp >1 + |.endif + | + |->vm_rethook: // Dispatch target for return hooks. + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_ACTIVE // Hook already active? + | jnz >5 + | jmp >1 + | + |->vm_inshook: // Dispatch target for instr/line hooks. + | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)] + | test RDL, HOOK_ACTIVE // Hook already active? + | jnz >5 + | + | test RDL, LUA_MASKLINE|LUA_MASKCOUNT + | jz >5 + | dec dword [DISPATCH+DISPATCH_GL(hookcount)] + | jz >1 + | test RDL, LUA_MASKLINE + | jz >5 + |1: + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov FCARG2, PC // Caveat: FCARG2 == BASE + | mov FCARG1, L:RB + | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. + | call extern lj_dispatch_ins@8 // (lua_State *L, BCIns *pc) + |3: + | mov BASE, L:RB->base + |4: + | movzx RA, PC_RA + |5: + | movzx OP, PC_OP + | movzx RD, PC_RD + |.if X64 + | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins. + |.else + | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Re-dispatch to static ins. + |.endif + | + |->cont_hook: // Continue from hook yield. + | add PC, 4 + | mov RA, [RB-24] + | mov MULTRES, RA // Restore MULTRES for *M ins. + | jmp <4 + | + |->vm_hotloop: // Hot loop counter underflow. + |.if JIT + | mov LFUNC:RB, [BASE-8] // Same as curr_topL(L). + | mov RB, LFUNC:RB->pc + | movzx RD, byte [RB+PC2PROTO(framesize)] + | lea RD, [BASE+RD*8] + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov FCARG2, PC + | lea FCARG1, [DISPATCH+GG_DISP2J] + | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa + | mov SAVE_PC, PC + | call extern lj_trace_hot@8 // (jit_State *J, const BCIns *pc) + | jmp <3 + |.endif + | + |->vm_callhook: // Dispatch target for call hooks. + | mov SAVE_PC, PC + |.if JIT + | jmp >1 + |.endif + | + |->vm_hotcall: // Hot call counter underflow. + |.if JIT + | mov SAVE_PC, PC + | or PC, 1 // Marker for hot call. + |1: + |.endif + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov L:RB->top, RD + | mov FCARG2, PC + | mov FCARG1, L:RB + | call extern lj_dispatch_call@8 // (lua_State *L, const BCIns *pc) + | // ASMFunction returned in eax/rax (RDa). + | mov SAVE_PC, 0 // Invalidate for subsequent line hook. + |.if JIT + | and PC, -2 + |.endif + | mov BASE, L:RB->base + | mov RAa, RDa + | mov RD, L:RB->top + | sub RD, BASE + | mov RBa, RAa + | movzx RA, PC_RA + | shr RD, 3 + | add NARGS:RD, 1 + | jmp RBa + | + |//----------------------------------------------------------------------- + |//-- Trace exit handler ------------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Called from an exit stub with the exit number on the stack. + |// The 16 bit exit number is stored with two (sign-extended) push imm8. + |->vm_exit_handler: + |.if JIT + |.if X64 + | push r13; push r12 + | push r11; push r10; push r9; push r8 + | push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp + | push rbx; push rdx; push rcx; push rax + | movzx RC, byte [rbp-8] // Reconstruct exit number. + | mov RCH, byte [rbp-16] + | mov [rbp-8], r15; mov [rbp-16], r14 + |.else + | push ebp; lea ebp, [esp+12]; push ebp + | push ebx; push edx; push ecx; push eax + | movzx RC, byte [ebp-4] // Reconstruct exit number. + | mov RCH, byte [ebp-8] + | mov [ebp-4], edi; mov [ebp-8], esi + |.endif + | // Caveat: DISPATCH is ebx. + | mov DISPATCH, [ebp] + | mov RA, [DISPATCH+DISPATCH_GL(vmstate)] // Get trace number. + | set_vmstate EXIT + | mov [DISPATCH+DISPATCH_J(exitno)], RC + | mov [DISPATCH+DISPATCH_J(parent)], RA + |.if X64 + |.if X64WIN + | sub rsp, 16*8+4*8 // Room for SSE regs + save area. + |.else + | sub rsp, 16*8 // Room for SSE regs. + |.endif + | add rbp, -128 + | movsd qword [rbp-8], xmm15; movsd qword [rbp-16], xmm14 + | movsd qword [rbp-24], xmm13; movsd qword [rbp-32], xmm12 + | movsd qword [rbp-40], xmm11; movsd qword [rbp-48], xmm10 + | movsd qword [rbp-56], xmm9; movsd qword [rbp-64], xmm8 + | movsd qword [rbp-72], xmm7; movsd qword [rbp-80], xmm6 + | movsd qword [rbp-88], xmm5; movsd qword [rbp-96], xmm4 + | movsd qword [rbp-104], xmm3; movsd qword [rbp-112], xmm2 + | movsd qword [rbp-120], xmm1; movsd qword [rbp-128], xmm0 + |.else + | sub esp, 8*8+16 // Room for SSE regs + args. + | movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6 + | movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4 + | movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2 + | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0 + |.endif + | // Caveat: RB is ebp. + | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)] + | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)] + | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa + | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 + | mov L:RB->base, BASE + |.if X64WIN + | lea CARG2, [rsp+4*8] + |.elif X64 + | mov CARG2, rsp + |.else + | lea FCARG2, [esp+16] + |.endif + | lea FCARG1, [DISPATCH+GG_DISP2J] + | call extern lj_trace_exit@8 // (jit_State *J, ExitState *ex) + | // MULTRES or negated error code returned in eax (RD). + | mov RAa, L:RB->cframe + | and RAa, CFRAME_RAWMASK + |.if X64WIN + | // Reposition stack later. + |.elif X64 + | mov rsp, RAa // Reposition stack to C frame. + |.else + | mov esp, RAa // Reposition stack to C frame. + |.endif + | mov [RAa+CFRAME_OFS_L], L:RB // Set SAVE_L (on-trace resume/yield). + | mov BASE, L:RB->base + | mov PC, [RAa+CFRAME_OFS_PC] // Get SAVE_PC. + |.if X64 + | jmp >1 + |.endif + |.endif + |->vm_exit_interp: + | // RD = MULTRES or negated error code, BASE, PC and DISPATCH set. + |.if JIT + |.if X64 + | // Restore additional callee-save registers only used in compiled code. + |.if X64WIN + | lea RAa, [rsp+9*16+4*8] + |1: + | movdqa xmm15, [RAa-9*16] + | movdqa xmm14, [RAa-8*16] + | movdqa xmm13, [RAa-7*16] + | movdqa xmm12, [RAa-6*16] + | movdqa xmm11, [RAa-5*16] + | movdqa xmm10, [RAa-4*16] + | movdqa xmm9, [RAa-3*16] + | movdqa xmm8, [RAa-2*16] + | movdqa xmm7, [RAa-1*16] + | mov rsp, RAa // Reposition stack to C frame. + | movdqa xmm6, [RAa] + | mov r15, CSAVE_3 + | mov r14, CSAVE_4 + |.else + | add rsp, 16 // Reposition stack to C frame. + |1: + |.endif + | mov r13, TMPa + | mov r12, TMPQ + |.endif + | test RD, RD; js >3 // Check for error from exit. + | mov MULTRES, RD + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 + | set_vmstate INTERP + | // Modified copy of ins_next which handles function header dispatch, too. + | mov RC, [PC] + | movzx RA, RCH + | movzx OP, RCL + | add PC, 4 + | shr RC, 16 + | cmp OP, BC_FUNCF // Function header? + | jb >2 + | mov RC, MULTRES // RC/RD holds nres+1. + |2: + |.if X64 + | jmp aword [DISPATCH+OP*8] + |.else + | jmp aword [DISPATCH+OP*4] + |.endif + | + |3: // Rethrow error from the right C frame. + | neg RD + | mov FCARG1, L:RB + | mov FCARG2, RD + | call extern lj_err_throw@8 // (lua_State *L, int errcode) + |.endif + | + |//----------------------------------------------------------------------- + |//-- Math helper functions ---------------------------------------------- + |//----------------------------------------------------------------------- + | + |// FP value rounding. Called by math.floor/math.ceil fast functions + |// and from JIT code. + | + |// x87 variant: Arg/ret on x87 stack. No int/xmm registers modified. + |.macro vm_round_x87, mode1, mode2 + | fnstcw word [esp+4] // Caveat: overwrites ARG1 and ARG2. + | mov [esp+8], eax + | mov ax, mode1 + | or ax, [esp+4] + |.if mode2 ~= 0xffff + | and ax, mode2 + |.endif + | mov [esp+6], ax + | fldcw word [esp+6] + | frndint + | fldcw word [esp+4] + | mov eax, [esp+8] + | ret + |.endmacro + | + |// SSE variant: arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified. + |.macro vm_round_sse, mode + | sseconst_abs xmm2, RDa + | sseconst_2p52 xmm3, RDa + | movaps xmm1, xmm0 + | andpd xmm1, xmm2 // |x| + | ucomisd xmm3, xmm1 // No truncation if 2^52 <= |x|. + | jbe >1 + | andnpd xmm2, xmm0 // Isolate sign bit. + |.if mode == 2 // trunc(x)? + | movaps xmm0, xmm1 + | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52 + | subsd xmm1, xmm3 + | sseconst_1 xmm3, RDa + | cmpsd xmm0, xmm1, 1 // |x| < result? + | andpd xmm0, xmm3 + | subsd xmm1, xmm0 // If yes, subtract -1. + | orpd xmm1, xmm2 // Merge sign bit back in. + |.else + | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52 + | subsd xmm1, xmm3 + | orpd xmm1, xmm2 // Merge sign bit back in. + | .if mode == 1 // ceil(x)? + | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0. + | cmpsd xmm0, xmm1, 6 // x > result? + | .else // floor(x)? + | sseconst_1 xmm2, RDa + | cmpsd xmm0, xmm1, 1 // x < result? + | .endif + | andpd xmm0, xmm2 + | subsd xmm1, xmm0 // If yes, subtract +-1. + |.endif + | movaps xmm0, xmm1 + |1: + | ret + |.endmacro + | + |.macro vm_round, name, ssemode, mode1, mode2 + |->name: + |.if not SSE + | vm_round_x87 mode1, mode2 + |.endif + |->name .. _sse: + | vm_round_sse ssemode + |.endmacro + | + | vm_round vm_floor, 0, 0x0400, 0xf7ff + | vm_round vm_ceil, 1, 0x0800, 0xfbff + | vm_round vm_trunc, 2, 0x0c00, 0xffff + | + |// FP modulo x%y. Called by BC_MOD* and vm_arith. + |->vm_mod: + |.if SSE + |// Args in xmm0/xmm1, return value in xmm0. + |// Caveat: xmm0-xmm5 and RC (eax) modified! + | movaps xmm5, xmm0 + | divsd xmm0, xmm1 + | sseconst_abs xmm2, RDa + | sseconst_2p52 xmm3, RDa + | movaps xmm4, xmm0 + | andpd xmm4, xmm2 // |x/y| + | ucomisd xmm3, xmm4 // No truncation if 2^52 <= |x/y|. + | jbe >1 + | andnpd xmm2, xmm0 // Isolate sign bit. + | addsd xmm4, xmm3 // (|x/y| + 2^52) - 2^52 + | subsd xmm4, xmm3 + | orpd xmm4, xmm2 // Merge sign bit back in. + | sseconst_1 xmm2, RDa + | cmpsd xmm0, xmm4, 1 // x/y < result? + | andpd xmm0, xmm2 + | subsd xmm4, xmm0 // If yes, subtract 1.0. + | movaps xmm0, xmm5 + | mulsd xmm1, xmm4 + | subsd xmm0, xmm1 + | ret + |1: + | mulsd xmm1, xmm0 + | movaps xmm0, xmm5 + | subsd xmm0, xmm1 + | ret + |.else + |// Args/ret on x87 stack (y on top). No xmm registers modified. + |// Caveat: needs 3 slots on x87 stack! RC (eax) modified! + | fld st1 + | fdiv st1 + | fnstcw word [esp+4] + | mov ax, 0x0400 + | or ax, [esp+4] + | and ax, 0xf7ff + | mov [esp+6], ax + | fldcw word [esp+6] + | frndint + | fldcw word [esp+4] + | fmulp st1 + | fsubp st1 + | ret + |.endif + | + |// FP log2(x). Called by math.log(x, base). + |->vm_log2: + |.if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | fld1 + | fld qword [rsp+8] + | fyl2x + | fstp qword [rsp+8] + | movsd xmm0, qword [rsp+8] + |.elif X64 + | movsd qword [rsp-8], xmm0 // Use red zone. + | fld1 + | fld qword [rsp-8] + | fyl2x + | fstp qword [rsp-8] + | movsd xmm0, qword [rsp-8] + |.else + | fld1 + | fld qword [esp+4] + | fyl2x + |.endif + | ret + | + |// FP exponentiation e^x and 2^x. Called by math.exp fast function and + |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified. + |// Caveat: needs 3 slots on x87 stack! + |->vm_exp_x87: + | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e)) + |->vm_exp2_x87: + | .if X64WIN + | .define expscratch, dword [rsp+8] // Use scratch area. + | .elif X64 + | .define expscratch, dword [rsp-8] // Use red zone. + | .else + | .define expscratch, dword [esp+4] // Needs 4 byte scratch area. + | .endif + | fst expscratch // Caveat: overwrites ARG1. + | cmp expscratch, 0x7f800000; je >1 // Special case: e^+Inf = +Inf + | cmp expscratch, 0xff800000; je >2 // Special case: e^-Inf = 0 + |->vm_exp2raw: // Entry point for vm_pow. Without +-Inf check. + | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part. + | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int + |1: + | ret + |2: + | fpop; fldz; ret + | + |// Generic power function x^y. Called by BC_POW, math.pow fast function, + |// and vm_arith. + |// Args/ret on x87 stack (y on top). RC (eax) modified. + |// Caveat: needs 3 slots on x87 stack! + |->vm_pow: + |.if not SSE + | fist dword [esp+4] // Store/reload int before comparison. + | fild dword [esp+4] // Integral exponent used in vm_powi. + | fucomip st1 + | jnz >8 // Branch for FP exponents. + | jp >9 // Branch for NaN exponent. + | fpop // Pop y and fallthrough to vm_powi. + | + |// FP/int power function x^i. Arg1/ret on x87 stack. + |// Arg2 (int) on C stack. RC (eax) modified. + |// Caveat: needs 2 slots on x87 stack! + | mov eax, [esp+4] + | cmp eax, 1; jle >6 // i<=1? + | // Now 1 < (unsigned)i <= 0x80000000. + |1: // Handle leading zeros. + | test eax, 1; jnz >2 + | fmul st0 + | shr eax, 1 + | jmp <1 + |2: + | shr eax, 1; jz >5 + | fdup + |3: // Handle trailing bits. + | fmul st0 + | shr eax, 1; jz >4 + | jnc <3 + | fmul st1, st0 + | jmp <3 + |4: + | fmulp st1 + |5: + | ret + |6: + | je <5 // x^1 ==> x + | jb >7 + | fld1; fdivrp st1 + | neg eax + | cmp eax, 1; je <5 // x^-1 ==> 1/x + | jmp <1 // x^-i ==> (1/x)^i + |7: + | fpop; fld1 // x^0 ==> 1 + | ret + | + |8: // FP/FP power function x^y. + | fst dword [esp+4] + | fxch + | fst dword [esp+8] + | mov eax, [esp+4]; shl eax, 1 + | cmp eax, 0xff000000; je >2 // x^+-Inf? + | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y? + | cmp eax, 0xff000000; je >4 // +-Inf^y? + | fyl2x + | jmp ->vm_exp2raw + | + |9: // Handle x^NaN. + | fld1 + | fucomip st2 + | je >1 // 1^NaN ==> 1 + | fxch // x^NaN ==> NaN + |1: + | fpop + | ret + | + |2: // Handle x^+-Inf. + | fabs + | fld1 + | fucomip st1 + | je >3 // +-1^+-Inf ==> 1 + | fpop; fabs; fldz; mov eax, 0; setc al + | ror eax, 1; xor eax, [esp+4]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0 + | fxch + |3: + | fpop1; fabs + | ret + | + |4: // Handle +-0^y or +-Inf^y. + | cmp dword [esp+4], 0; jge <3 // y >= 0, x^y ==> |x| + | fpop; fpop + | test eax, eax; jz >5 // y < 0, +-0^y ==> +Inf + | fldz // y < 0, +-Inf^y ==> 0 + | ret + |5: + | mov dword [esp+4], 0x7f800000 // Return +Inf. + | fld dword [esp+4] + | ret + |.endif + | + |// Args in xmm0/xmm1. Ret in xmm0. xmm0-xmm2 and RC (eax) modified. + |// Needs 16 byte scratch area for x86. Also called from JIT code. + |->vm_pow_sse: + | cvtsd2si eax, xmm1 + | cvtsi2sd xmm2, eax + | ucomisd xmm1, xmm2 + | jnz >8 // Branch for FP exponents. + | jp >9 // Branch for NaN exponent. + | // Fallthrough to vm_powi_sse. + | + |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified. + |->vm_powi_sse: + | cmp eax, 1; jle >6 // i<=1? + | // Now 1 < (unsigned)i <= 0x80000000. + |1: // Handle leading zeros. + | test eax, 1; jnz >2 + | mulsd xmm0, xmm0 + | shr eax, 1 + | jmp <1 + |2: + | shr eax, 1; jz >5 + | movaps xmm1, xmm0 + |3: // Handle trailing bits. + | mulsd xmm0, xmm0 + | shr eax, 1; jz >4 + | jnc <3 + | mulsd xmm1, xmm0 + | jmp <3 + |4: + | mulsd xmm0, xmm1 + |5: + | ret + |6: + | je <5 // x^1 ==> x + | jb >7 // x^0 ==> 1 + | neg eax + | call <1 + | sseconst_1 xmm1, RDa + | divsd xmm1, xmm0 + | movaps xmm0, xmm1 + | ret + |7: + | sseconst_1 xmm0, RDa + | ret + | + |8: // FP/FP power function x^y. + |.if X64 + | movd rax, xmm1; shl rax, 1 + | rol rax, 12; cmp rax, 0xffe; je >2 // x^+-Inf? + | movd rax, xmm0; shl rax, 1; je >4 // +-0^y? + | rol rax, 12; cmp rax, 0xffe; je >5 // +-Inf^y? + | .if X64WIN + | movsd qword [rsp+16], xmm1 // Use scratch area. + | movsd qword [rsp+8], xmm0 + | fld qword [rsp+16] + | fld qword [rsp+8] + | .else + | movsd qword [rsp-16], xmm1 // Use red zone. + | movsd qword [rsp-8], xmm0 + | fld qword [rsp-16] + | fld qword [rsp-8] + | .endif + |.else + | movsd qword [esp+12], xmm1 // Needs 16 byte scratch area. + | movsd qword [esp+4], xmm0 + | cmp dword [esp+12], 0; jne >1 + | mov eax, [esp+16]; shl eax, 1 + | cmp eax, 0xffe00000; je >2 // x^+-Inf? + |1: + | cmp dword [esp+4], 0; jne >1 + | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y? + | cmp eax, 0xffe00000; je >5 // +-Inf^y? + |1: + | fld qword [esp+12] + | fld qword [esp+4] + |.endif + | fyl2x // y*log2(x) + | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part. + | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int + |.if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + |.elif X64 + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + |.else + | fstp qword [esp+4] // Needs 8 byte scratch area. + | movsd xmm0, qword [esp+4] + |.endif + | ret + | + |9: // Handle x^NaN. + | sseconst_1 xmm2, RDa + | ucomisd xmm0, xmm2; je >1 // 1^NaN ==> 1 + | movaps xmm0, xmm1 // x^NaN ==> NaN + |1: + | ret + | + |2: // Handle x^+-Inf. + | sseconst_abs xmm2, RDa + | andpd xmm0, xmm2 // |x| + | sseconst_1 xmm2, RDa + | ucomisd xmm0, xmm2; je <1 // +-1^+-Inf ==> 1 + | movmskpd eax, xmm1 + | xorps xmm0, xmm0 + | mov ah, al; setc al; xor al, ah; jne <1 // |x|<>1, x^+-Inf ==> +Inf/0 + |3: + | sseconst_hi xmm0, RDa, 7ff00000 // +Inf + | ret + | + |4: // Handle +-0^y. + | movmskpd eax, xmm1; test eax, eax; jnz <3 // y < 0, +-0^y ==> +Inf + | xorps xmm0, xmm0 // y >= 0, +-0^y ==> 0 + | ret + | + |5: // Handle +-Inf^y. + | movmskpd eax, xmm1; test eax, eax; jz <3 // y >= 0, +-Inf^y ==> +Inf + | xorps xmm0, xmm0 // y < 0, +-Inf^y ==> 0 + | ret + | + |// Callable from C: double lj_vm_foldfpm(double x, int fpm) + |// Computes fpm(x) for extended math functions. ORDER FPM. + |->vm_foldfpm: + |.if JIT + |.if X64 + | .if X64WIN + | .define fpmop, CARG2d + | .else + | .define fpmop, CARG1d + | .endif + | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil + | cmp fpmop, 3; jb ->vm_trunc; ja >2 + | sqrtsd xmm0, xmm0; ret + |2: + | .if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | fld qword [rsp+8] + | .else + | movsd qword [rsp-8], xmm0 // Use red zone. + | fld qword [rsp-8] + | .endif + | cmp fpmop, 5; ja >2 + | .if X64WIN; pop rax; .endif + | je >1 + | call ->vm_exp_x87 + | .if X64WIN; push rax; .endif + | jmp >7 + |1: + | call ->vm_exp2_x87 + | .if X64WIN; push rax; .endif + | jmp >7 + |2: ; cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; jmp >7 + |1: ; fld1; fxch; fyl2x; jmp >7 + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; jmp >7 + |1: ; fsin; jmp >7 + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; jmp >7 + |1: ; fptan; fpop + |7: + | .if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + | .else + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + | .endif + | ret + |.else // x86 calling convention. + | .define fpmop, eax + |.if SSE + | mov fpmop, [esp+12] + | movsd xmm0, qword [esp+4] + | cmp fpmop, 1; je >1; ja >2 + | call ->vm_floor; jmp >7 + |1: ; call ->vm_ceil; jmp >7 + |2: ; cmp fpmop, 3; je >1; ja >2 + | call ->vm_trunc; jmp >7 + |1: + | sqrtsd xmm0, xmm0 + |7: + | movsd qword [esp+4], xmm0 // Overwrite callee-owned args. + | fld qword [esp+4] + | ret + |2: ; fld qword [esp+4] + | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 + |2: ; cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; ret + |1: ; fld1; fxch; fyl2x; ret + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; ret + |1: ; fsin; ret + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; ret + |1: ; fptan; fpop; ret + |.else + | mov fpmop, [esp+12] + | fld qword [esp+4] + | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil + | cmp fpmop, 3; jb ->vm_trunc; ja >2 + | fsqrt; ret + |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 + | cmp fpmop, 7; je >1; ja >2 + | fldln2; fxch; fyl2x; ret + |1: ; fld1; fxch; fyl2x; ret + |2: ; cmp fpmop, 9; je >1; ja >2 + | fldlg2; fxch; fyl2x; ret + |1: ; fsin; ret + |2: ; cmp fpmop, 11; je >1; ja >9 + | fcos; ret + |1: ; fptan; fpop; ret + |.endif + |.endif + |9: ; int3 // Bad fpm. + |.endif + | + |// Callable from C: double lj_vm_foldarith(double x, double y, int op) + |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -) + |// and basic math functions. ORDER ARITH + |->vm_foldarith: + |.if X64 + | + | .if X64WIN + | .define foldop, CARG3d + | .else + | .define foldop, CARG1d + | .endif + | cmp foldop, 1; je >1; ja >2 + | addsd xmm0, xmm1; ret + |1: ; subsd xmm0, xmm1; ret + |2: ; cmp foldop, 3; je >1; ja >2 + | mulsd xmm0, xmm1; ret + |1: ; divsd xmm0, xmm1; ret + |2: ; cmp foldop, 5; jb ->vm_mod; je ->vm_pow + | cmp foldop, 7; je >1; ja >2 + | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; ret + |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; ret + |2: ; cmp foldop, 9; ja >2 + |.if X64WIN + | movsd qword [rsp+8], xmm0 // Use scratch area. + | movsd qword [rsp+16], xmm1 + | fld qword [rsp+8] + | fld qword [rsp+16] + |.else + | movsd qword [rsp-8], xmm0 // Use red zone. + | movsd qword [rsp-16], xmm1 + | fld qword [rsp-8] + | fld qword [rsp-16] + |.endif + | je >1 + | fpatan + |7: + |.if X64WIN + | fstp qword [rsp+8] // Use scratch area. + | movsd xmm0, qword [rsp+8] + |.else + | fstp qword [rsp-8] // Use red zone. + | movsd xmm0, qword [rsp-8] + |.endif + | ret + |1: ; fxch; fscale; fpop1; jmp <7 + |2: ; cmp foldop, 11; je >1; ja >9 + | minsd xmm0, xmm1; ret + |1: ; maxsd xmm0, xmm1; ret + |9: ; int3 // Bad op. + | + |.elif SSE // x86 calling convention with SSE ops. + | + | .define foldop, eax + | mov foldop, [esp+20] + | movsd xmm0, qword [esp+4] + | movsd xmm1, qword [esp+12] + | cmp foldop, 1; je >1; ja >2 + | addsd xmm0, xmm1 + |7: + | movsd qword [esp+4], xmm0 // Overwrite callee-owned args. + | fld qword [esp+4] + | ret + |1: ; subsd xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 3; je >1; ja >2 + | mulsd xmm0, xmm1; jmp <7 + |1: ; divsd xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 5 + | je >1; ja >2 + | call ->vm_mod; jmp <7 + |1: ; pop edx; call ->vm_pow; push edx; jmp <7 // Writes to scratch area. + |2: ; cmp foldop, 7; je >1; ja >2 + | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; jmp <7 + |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; jmp <7 + |2: ; cmp foldop, 9; ja >2 + | fld qword [esp+4] // Reload from stack + | fld qword [esp+12] + | je >1 + | fpatan; ret + |1: ; fxch; fscale; fpop1; ret + |2: ; cmp foldop, 11; je >1; ja >9 + | minsd xmm0, xmm1; jmp <7 + |1: ; maxsd xmm0, xmm1; jmp <7 + |9: ; int3 // Bad op. + | + |.else // x86 calling convention with x87 ops. + | + | mov eax, [esp+20] + | fld qword [esp+4] + | fld qword [esp+12] + | cmp eax, 1; je >1; ja >2 + | faddp st1; ret + |1: ; fsubp st1; ret + |2: ; cmp eax, 3; je >1; ja >2 + | fmulp st1; ret + |1: ; fdivp st1; ret + |2: ; cmp eax, 5; jb ->vm_mod; je ->vm_pow + | cmp eax, 7; je >1; ja >2 + | fpop; fchs; ret + |1: ; fpop; fabs; ret + |2: ; cmp eax, 9; je >1; ja >2 + | fpatan; ret + |1: ; fxch; fscale; fpop1; ret + |2: ; cmp eax, 11; je >1; ja >9 + | fucomi st1; fcmovnbe st1; fpop1; ret + |1: ; fucomi st1; fcmovbe st1; fpop1; ret + |9: ; int3 // Bad op. + | + |.endif + | + |//----------------------------------------------------------------------- + |//-- Miscellaneous functions -------------------------------------------- + |//----------------------------------------------------------------------- + | + |// int lj_vm_cpuid(uint32_t f, uint32_t res[4]) + |->vm_cpuid: + |.if X64 + | mov eax, CARG1d + | .if X64WIN; push rsi; mov rsi, CARG2; .endif + | push rbx + | cpuid + | mov [rsi], eax + | mov [rsi+4], ebx + | mov [rsi+8], ecx + | mov [rsi+12], edx + | pop rbx + | .if X64WIN; pop rsi; .endif + | ret + |.else + | pushfd + | pop edx + | mov ecx, edx + | xor edx, 0x00200000 // Toggle ID bit in flags. + | push edx + | popfd + | pushfd + | pop edx + | xor eax, eax // Zero means no features supported. + | cmp ecx, edx + | jz >1 // No ID toggle means no CPUID support. + | mov eax, [esp+4] // Argument 1 is function number. + | push edi + | push ebx + | cpuid + | mov edi, [esp+16] // Argument 2 is result area. + | mov [edi], eax + | mov [edi+4], ebx + | mov [edi+8], ecx + | mov [edi+12], edx + | pop ebx + | pop edi + |1: + | ret + |.endif + | + |//----------------------------------------------------------------------- + |//-- Assertions --------------------------------------------------------- + |//----------------------------------------------------------------------- + | + |->assert_bad_for_arg_type: +#ifdef LUA_USE_ASSERT + | int3 +#endif + | int3 + | + |//----------------------------------------------------------------------- + |//-- FFI helper functions ----------------------------------------------- + |//----------------------------------------------------------------------- + | + |// Handler for callback functions. Callback slot number in ah/al. + |->vm_ffi_callback: + |.if FFI + |.type CTSTATE, CTState, PC + |.if not X64 + | sub esp, 16 // Leave room for SAVE_ERRF etc. + |.endif + | saveregs_ // ebp/rbp already saved. ebp now holds global_State *. + | lea DISPATCH, [ebp+GG_G2DISP] + | mov CTSTATE, GL:ebp->ctype_state + | movzx eax, ax + | mov CTSTATE->cb.slot, eax + |.if X64 + | mov CTSTATE->cb.gpr[0], CARG1 + | mov CTSTATE->cb.gpr[1], CARG2 + | mov CTSTATE->cb.gpr[2], CARG3 + | mov CTSTATE->cb.gpr[3], CARG4 + | movsd qword CTSTATE->cb.fpr[0], xmm0 + | movsd qword CTSTATE->cb.fpr[1], xmm1 + | movsd qword CTSTATE->cb.fpr[2], xmm2 + | movsd qword CTSTATE->cb.fpr[3], xmm3 + |.if X64WIN + | lea rax, [rsp+CFRAME_SIZE+4*8] + |.else + | lea rax, [rsp+CFRAME_SIZE] + | mov CTSTATE->cb.gpr[4], CARG5 + | mov CTSTATE->cb.gpr[5], CARG6 + | movsd qword CTSTATE->cb.fpr[4], xmm4 + | movsd qword CTSTATE->cb.fpr[5], xmm5 + | movsd qword CTSTATE->cb.fpr[6], xmm6 + | movsd qword CTSTATE->cb.fpr[7], xmm7 + |.endif + | mov CTSTATE->cb.stack, rax + | mov CARG2, rsp + |.else + | lea eax, [esp+CFRAME_SIZE+16] + | mov CTSTATE->cb.gpr[0], FCARG1 + | mov CTSTATE->cb.gpr[1], FCARG2 + | mov CTSTATE->cb.stack, eax + | mov FCARG1, [esp+CFRAME_SIZE+12] // Move around misplaced retaddr/ebp. + | mov FCARG2, [esp+CFRAME_SIZE+8] + | mov SAVE_RET, FCARG1 + | mov SAVE_R4, FCARG2 + | mov FCARG2, esp + |.endif + | mov SAVE_PC, CTSTATE // Any value outside of bytecode is ok. + | mov FCARG1, CTSTATE + | call extern lj_ccallback_enter@8 // (CTState *cts, void *cf) + | // lua_State * returned in eax (RD). + | set_vmstate INTERP + | mov BASE, L:RD->base + | mov RD, L:RD->top + | sub RD, BASE + | mov LFUNC:RB, [BASE-8] + | shr RD, 3 + | add RD, 1 + | ins_callt + |.endif + | + |->cont_ffi_callback: // Return from FFI callback. + |.if FFI + | mov L:RA, SAVE_L + | mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)] + | mov aword CTSTATE->L, L:RAa + | mov L:RA->base, BASE + | mov L:RA->top, RB + | mov FCARG1, CTSTATE + | mov FCARG2, RC + | call extern lj_ccallback_leave@8 // (CTState *cts, TValue *o) + |.if X64 + | mov rax, CTSTATE->cb.gpr[0] + | movsd xmm0, qword CTSTATE->cb.fpr[0] + | jmp ->vm_leave_unw + |.else + | mov L:RB, SAVE_L + | mov eax, CTSTATE->cb.gpr[0] + | mov edx, CTSTATE->cb.gpr[1] + | cmp dword CTSTATE->cb.gpr[2], 1 + | jb >7 + | je >6 + | fld qword CTSTATE->cb.fpr[0].d + | jmp >7 + |6: + | fld dword CTSTATE->cb.fpr[0].f + |7: + | mov ecx, L:RB->top + | movzx ecx, word [ecx+6] // Get stack adjustment and copy up. + | mov SAVE_L, ecx // Must be one slot above SAVE_RET + | restoreregs + | pop ecx // Move return addr from SAVE_RET. + | add esp, [esp] // Adjust stack. + | add esp, 16 + | push ecx + | ret + |.endif + |.endif + | + |->vm_ffi_call@4: // Call C function via FFI. + | // Caveat: needs special frame unwinding, see below. + |.if FFI + |.if X64 + | .type CCSTATE, CCallState, rbx + | push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1 + |.else + | .type CCSTATE, CCallState, ebx + | push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1 + |.endif + | + | // Readjust stack. + |.if X64 + | mov eax, CCSTATE->spadj + | sub rsp, rax + |.else + | sub esp, CCSTATE->spadj + |.if WIN + | mov CCSTATE->spadj, esp + |.endif + |.endif + | + | // Copy stack slots. + | movzx ecx, byte CCSTATE->nsp + | sub ecx, 1 + | js >2 + |1: + |.if X64 + | mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)] + | mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax + |.else + | mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)] + | mov [esp+ecx*4], eax + |.endif + | sub ecx, 1 + | jns <1 + |2: + | + |.if X64 + | movzx eax, byte CCSTATE->nfpr + | mov CARG1, CCSTATE->gpr[0] + | mov CARG2, CCSTATE->gpr[1] + | mov CARG3, CCSTATE->gpr[2] + | mov CARG4, CCSTATE->gpr[3] + |.if not X64WIN + | mov CARG5, CCSTATE->gpr[4] + | mov CARG6, CCSTATE->gpr[5] + |.endif + | test eax, eax; jz >5 + | movaps xmm0, CCSTATE->fpr[0] + | movaps xmm1, CCSTATE->fpr[1] + | movaps xmm2, CCSTATE->fpr[2] + | movaps xmm3, CCSTATE->fpr[3] + |.if not X64WIN + | cmp eax, 4; jbe >5 + | movaps xmm4, CCSTATE->fpr[4] + | movaps xmm5, CCSTATE->fpr[5] + | movaps xmm6, CCSTATE->fpr[6] + | movaps xmm7, CCSTATE->fpr[7] + |.endif + |5: + |.else + | mov FCARG1, CCSTATE->gpr[0] + | mov FCARG2, CCSTATE->gpr[1] + |.endif + | + | call aword CCSTATE->func + | + |.if X64 + | mov CCSTATE->gpr[0], rax + | movaps CCSTATE->fpr[0], xmm0 + |.if not X64WIN + | mov CCSTATE->gpr[1], rdx + | movaps CCSTATE->fpr[1], xmm1 + |.endif + |.else + | mov CCSTATE->gpr[0], eax + | mov CCSTATE->gpr[1], edx + | cmp byte CCSTATE->resx87, 1 + | jb >7 + | je >6 + | fstp qword CCSTATE->fpr[0].d[0] + | jmp >7 + |6: + | fstp dword CCSTATE->fpr[0].f[0] + |7: + |.if WIN + | sub CCSTATE->spadj, esp + |.endif + |.endif + | + |.if X64 + | mov rbx, [rbp-8]; leave; ret + |.else + | mov ebx, [ebp-4]; leave; ret + |.endif + |.endif + |// Note: vm_ffi_call must be the last function in this object file! + | + |//----------------------------------------------------------------------- +} + +/* Generate the code for a single instruction. */ +static void build_ins(BuildCtx *ctx, BCOp op, int defop) +{ + int vk = 0; + |// Note: aligning all instructions does not pay off. + |=>defop: + + switch (op) { + + /* -- Comparison ops ---------------------------------------------------- */ + + /* Remember: all ops branch for a true comparison, fall through otherwise. */ + + |.macro jmp_comp, lt, ge, le, gt, target + ||switch (op) { + ||case BC_ISLT: + | lt target + ||break; + ||case BC_ISGE: + | ge target + ||break; + ||case BC_ISLE: + | le target + ||break; + ||case BC_ISGT: + | gt target + ||break; + ||default: break; /* Shut up GCC. */ + ||} + |.endmacro + + case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: + | // RA = src1, RD = src2, JMP with RD = target + | ins_AD + |.if DUALNUM + | checkint RA, >7 + | checkint RD, >8 + | mov RB, dword [BASE+RA*8] + | add PC, 4 + | cmp RB, dword [BASE+RD*8] + | jmp_comp jge, jl, jg, jle, >9 + |6: + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RA is not an integer. + | ja ->vmeta_comp + | // RA is a number. + | cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp + | // RA is a number, RD is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RD*8] + | jmp >2 + |.else + | fld qword [BASE+RA*8] + | fild dword [BASE+RD*8] + | jmp >3 + |.endif + | + |8: // RA is an integer, RD is not an integer. + | ja ->vmeta_comp + | // RA is an integer, RD is a number. + |.if SSE + | cvtsi2sd xmm1, dword [BASE+RA*8] + | movsd xmm0, qword [BASE+RD*8] + | add PC, 4 + | ucomisd xmm0, xmm1 + | jmp_comp jbe, ja, jb, jae, <9 + | jmp <6 + |.else + | fild dword [BASE+RA*8] + | jmp >2 + |.endif + |.else + | checknum RA, ->vmeta_comp + | checknum RD, ->vmeta_comp + |.endif + |.if SSE + |1: + | movsd xmm0, qword [BASE+RD*8] + |2: + | add PC, 4 + | ucomisd xmm0, qword [BASE+RA*8] + |3: + |.else + |1: + | fld qword [BASE+RA*8] // Reverse order, i.e like cmp D, A. + |2: + | fld qword [BASE+RD*8] + |3: + | add PC, 4 + | fcomparepp + |.endif + | // Unordered: all of ZF CF PF set, ordered: PF clear. + | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. + |.if DUALNUM + | jmp_comp jbe, ja, jb, jae, <9 + | jmp <6 + |.else + | jmp_comp jbe, ja, jb, jae, >1 + | movzx RD, PC_RD + | branchPC RD + |1: + | ins_next + |.endif + break; + + case BC_ISEQV: case BC_ISNEV: + vk = op == BC_ISEQV; + | ins_AD // RA = src1, RD = src2, JMP with RD = target + | mov RB, [BASE+RD*8+4] + | add PC, 4 + |.if DUALNUM + | cmp RB, LJ_TISNUM; jne >7 + | checkint RA, >8 + | mov RB, dword [BASE+RD*8] + | cmp RB, dword [BASE+RA*8] + if (vk) { + | jne >9 + } else { + | je >9 + } + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RD is not an integer. + | ja >5 + | // RD is a number. + | cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5 + | // RD is a number, RA is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RA*8] + |.else + | fild dword [BASE+RA*8] + |.endif + | jmp >2 + | + |8: // RD is an integer, RA is not an integer. + | ja >5 + | // RD is an integer, RA is a number. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RD*8] + | ucomisd xmm0, qword [BASE+RA*8] + |.else + | fild dword [BASE+RD*8] + | fld qword [BASE+RA*8] + |.endif + | jmp >4 + | + |.else + | cmp RB, LJ_TISNUM; jae >5 + | checknum RA, >5 + |.endif + |.if SSE + |1: + | movsd xmm0, qword [BASE+RA*8] + |2: + | ucomisd xmm0, qword [BASE+RD*8] + |4: + |.else + |1: + | fld qword [BASE+RA*8] + |2: + | fld qword [BASE+RD*8] + |4: + | fcomparepp + |.endif + iseqne_fp: + if (vk) { + | jp >2 // Unordered means not equal. + | jne >2 + } else { + | jp >2 // Unordered means not equal. + | je >1 + } + iseqne_end: + if (vk) { + |1: // EQ: Branch to the target. + | movzx RD, PC_RD + | branchPC RD + |2: // NE: Fallthrough to next instruction. + |.if not FFI + |3: + |.endif + } else { + |.if not FFI + |3: + |.endif + |2: // NE: Branch to the target. + | movzx RD, PC_RD + | branchPC RD + |1: // EQ: Fallthrough to next instruction. + } + if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV || + op == BC_ISEQN || op == BC_ISNEN)) { + | jmp <9 + } else { + | ins_next + } + | + if (op == BC_ISEQV || op == BC_ISNEV) { + |5: // Either or both types are not numbers. + |.if FFI + | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd + | checktp RA, LJ_TCDATA; je ->vmeta_equal_cd + |.endif + | checktp RA, RB // Compare types. + | jne <2 // Not the same type? + | cmp RB, LJ_TISPRI + | jae <1 // Same type and primitive type? + | + | // Same types and not a primitive type. Compare GCobj or pvalue. + | mov RA, [BASE+RA*8] + | mov RD, [BASE+RD*8] + | cmp RA, RD + | je <1 // Same GCobjs or pvalues? + | cmp RB, LJ_TISTABUD + | ja <2 // Different objects and not table/ud? + |.if X64 + | cmp RB, LJ_TUDATA // And not 64 bit lightuserdata. + | jb <2 + |.endif + | + | // Different tables or userdatas. Need to check __eq metamethod. + | // Field metatable must be at same offset for GCtab and GCudata! + | mov TAB:RB, TAB:RA->metatable + | test TAB:RB, TAB:RB + | jz <2 // No metatable? + | test byte TAB:RB->nomm, 1<vmeta_equal // Handle __eq metamethod. + } else { + |.if FFI + |3: + | cmp RB, LJ_TCDATA + if (LJ_DUALNUM && vk) { + | jne <9 + } else { + | jne <2 + } + | jmp ->vmeta_equal_cd + |.endif + } + break; + case BC_ISEQS: case BC_ISNES: + vk = op == BC_ISEQS; + | ins_AND // RA = src, RD = str const, JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + | cmp RB, LJ_TSTR; jne >3 + | mov RA, [BASE+RA*8] + | cmp RA, [KBASE+RD*4] + iseqne_test: + if (vk) { + | jne >2 + } else { + | je >1 + } + goto iseqne_end; + case BC_ISEQN: case BC_ISNEN: + vk = op == BC_ISEQN; + | ins_AD // RA = src, RD = num const, JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + |.if DUALNUM + | cmp RB, LJ_TISNUM; jne >7 + | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8 + | mov RB, dword [KBASE+RD*8] + | cmp RB, dword [BASE+RA*8] + if (vk) { + | jne >9 + } else { + | je >9 + } + | movzx RD, PC_RD + | branchPC RD + |9: + | ins_next + | + |7: // RA is not an integer. + | ja >3 + | // RA is a number. + | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1 + | // RA is a number, RD is an integer. + |.if SSE + | cvtsi2sd xmm0, dword [KBASE+RD*8] + |.else + | fild dword [KBASE+RD*8] + |.endif + | jmp >2 + | + |8: // RA is an integer, RD is a number. + |.if SSE + | cvtsi2sd xmm0, dword [BASE+RA*8] + | ucomisd xmm0, qword [KBASE+RD*8] + |.else + | fild dword [BASE+RA*8] + | fld qword [KBASE+RD*8] + |.endif + | jmp >4 + |.else + | cmp RB, LJ_TISNUM; jae >3 + |.endif + |.if SSE + |1: + | movsd xmm0, qword [KBASE+RD*8] + |2: + | ucomisd xmm0, qword [BASE+RA*8] + |4: + |.else + |1: + | fld qword [KBASE+RD*8] + |2: + | fld qword [BASE+RA*8] + |4: + | fcomparepp + |.endif + goto iseqne_fp; + case BC_ISEQP: case BC_ISNEP: + vk = op == BC_ISEQP; + | ins_AND // RA = src, RD = primitive type (~), JMP with RD = target + | mov RB, [BASE+RA*8+4] + | add PC, 4 + | cmp RB, RD + if (!LJ_HASFFI) goto iseqne_test; + if (vk) { + | jne >3 + | movzx RD, PC_RD + | branchPC RD + |2: + | ins_next + |3: + | cmp RB, LJ_TCDATA; jne <2 + | jmp ->vmeta_equal_cd + } else { + | je >2 + | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd + | movzx RD, PC_RD + | branchPC RD + |2: + | ins_next + } + break; + + /* -- Unary test and copy ops ------------------------------------------- */ + + case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: + | ins_AD // RA = dst or unused, RD = src, JMP with RD = target + | mov RB, [BASE+RD*8+4] + | add PC, 4 + | cmp RB, LJ_TISTRUECOND + if (op == BC_IST || op == BC_ISTC) { + | jae >1 + } else { + | jb >1 + } + if (op == BC_ISTC || op == BC_ISFC) { + | mov [BASE+RA*8+4], RB + | mov RB, [BASE+RD*8] + | mov [BASE+RA*8], RB + } + | movzx RD, PC_RD + | branchPC RD + |1: // Fallthrough to the next instruction. + | ins_next + break; + + /* -- Unary ops --------------------------------------------------------- */ + + case BC_MOV: + | ins_AD // RA = dst, RD = src + |.if X64 + | mov RBa, [BASE+RD*8] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [BASE+RD*8+4] + | mov RD, [BASE+RD*8] + | mov [BASE+RA*8+4], RB + | mov [BASE+RA*8], RD + |.endif + | ins_next_ + break; + case BC_NOT: + | ins_AD // RA = dst, RD = src + | xor RB, RB + | checktp RD, LJ_TISTRUECOND + | adc RB, LJ_TTRUE + | mov [BASE+RA*8+4], RB + | ins_next + break; + case BC_UNM: + | ins_AD // RA = dst, RD = src + |.if DUALNUM + | checkint RD, >5 + | mov RB, [BASE+RD*8] + | neg RB + | jo >4 + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RB + |9: + | ins_next + |4: + | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31. + | mov dword [BASE+RA*8], 0 + | jmp <9 + |5: + | ja ->vmeta_unm + |.else + | checknum RD, ->vmeta_unm + |.endif + |.if SSE + | movsd xmm0, qword [BASE+RD*8] + | sseconst_sign xmm1, RDa + | xorps xmm0, xmm1 + | movsd qword [BASE+RA*8], xmm0 + |.else + | fld qword [BASE+RD*8] + | fchs + | fstp qword [BASE+RA*8] + |.endif + |.if DUALNUM + | jmp <9 + |.else + | ins_next + |.endif + break; + case BC_LEN: + | ins_AD // RA = dst, RD = src + | checkstr RD, >2 + | mov STR:RD, [BASE+RD*8] + |.if DUALNUM + | mov RD, dword STR:RD->len + |1: + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RD + |.elif SSE + | xorps xmm0, xmm0 + | cvtsi2sd xmm0, dword STR:RD->len + |1: + | movsd qword [BASE+RA*8], xmm0 + |.else + | fild dword STR:RD->len + |1: + | fstp qword [BASE+RA*8] + |.endif + | ins_next + |2: + | checktab RD, ->vmeta_len + | mov TAB:FCARG1, [BASE+RD*8] +#if LJ_52 + | mov TAB:RB, TAB:FCARG1->metatable + | cmp TAB:RB, 0 + | jnz >9 + |3: +#endif + |->BC_LEN_Z: + | mov RB, BASE // Save BASE. + | call extern lj_tab_len@4 // (GCtab *t) + | // Length of table returned in eax (RD). + |.if DUALNUM + | // Nothing to do. + |.elif SSE + | cvtsi2sd xmm0, RD + |.else + | mov ARG1, RD + | fild ARG1 + |.endif + | mov BASE, RB // Restore BASE. + | movzx RA, PC_RA + | jmp <1 +#if LJ_52 + |9: // Check for __len. + | test byte TAB:RB->nomm, 1<vmeta_len // 'no __len' flag NOT set: check. +#endif + break; + + /* -- Binary ops -------------------------------------------------------- */ + + |.macro ins_arithpre, x87ins, sseins, ssereg + | ins_ABC + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | checknum RB, ->vmeta_arith_vn + | .if DUALNUM + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn + | .endif + | .if SSE + | movsd xmm0, qword [BASE+RB*8] + | sseins ssereg, qword [KBASE+RC*8] + | .else + | fld qword [BASE+RB*8] + | x87ins qword [KBASE+RC*8] + | .endif + || break; + ||case 1: + | checknum RB, ->vmeta_arith_nv + | .if DUALNUM + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv + | .endif + | .if SSE + | movsd xmm0, qword [KBASE+RC*8] + | sseins ssereg, qword [BASE+RB*8] + | .else + | fld qword [KBASE+RC*8] + | x87ins qword [BASE+RB*8] + | .endif + || break; + ||default: + | checknum RB, ->vmeta_arith_vv + | checknum RC, ->vmeta_arith_vv + | .if SSE + | movsd xmm0, qword [BASE+RB*8] + | sseins ssereg, qword [BASE+RC*8] + | .else + | fld qword [BASE+RB*8] + | x87ins qword [BASE+RC*8] + | .endif + || break; + ||} + |.endmacro + | + |.macro ins_arithdn, intins + | ins_ABC + ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); + ||switch (vk) { + ||case 0: + | checkint RB, ->vmeta_arith_vn + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn + | mov RB, [BASE+RB*8] + | intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno + || break; + ||case 1: + | checkint RB, ->vmeta_arith_nv + | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv + | mov RC, [KBASE+RC*8] + | intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo + || break; + ||default: + | checkint RB, ->vmeta_arith_vv + | checkint RC, ->vmeta_arith_vv + | mov RB, [BASE+RB*8] + | intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo + || break; + ||} + | mov dword [BASE+RA*8+4], LJ_TISNUM + ||if (vk == 1) { + | mov dword [BASE+RA*8], RC + ||} else { + | mov dword [BASE+RA*8], RB + ||} + | ins_next + |.endmacro + | + |.macro ins_arithpost + |.if SSE + | movsd qword [BASE+RA*8], xmm0 + |.else + | fstp qword [BASE+RA*8] + |.endif + |.endmacro + | + |.macro ins_arith, x87ins, sseins + | ins_arithpre x87ins, sseins, xmm0 + | ins_arithpost + | ins_next + |.endmacro + | + |.macro ins_arith, intins, x87ins, sseins + |.if DUALNUM + | ins_arithdn intins + |.else + | ins_arith, x87ins, sseins + |.endif + |.endmacro + + | // RA = dst, RB = src1 or num const, RC = src2 or num const + case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: + | ins_arith add, fadd, addsd + break; + case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: + | ins_arith sub, fsub, subsd + break; + case BC_MULVN: case BC_MULNV: case BC_MULVV: + | ins_arith imul, fmul, mulsd + break; + case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: + | ins_arith fdiv, divsd + break; + case BC_MODVN: + | ins_arithpre fld, movsd, xmm1 + |->BC_MODVN_Z: + | call ->vm_mod + | ins_arithpost + | ins_next + break; + case BC_MODNV: case BC_MODVV: + | ins_arithpre fld, movsd, xmm1 + | jmp ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway. + break; + case BC_POW: + | ins_arithpre fld, movsd, xmm1 + | call ->vm_pow + | ins_arithpost + | ins_next + break; + + case BC_CAT: + | ins_ABC // RA = dst, RB = src_start, RC = src_end + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | lea CARG2d, [BASE+RC*8] + | mov CARG3d, RC + | sub CARG3d, RB + |->BC_CAT_Z: + | mov L:RB, L:CARG1d + |.else + | lea RA, [BASE+RC*8] + | sub RC, RB + | mov ARG2, RA + | mov ARG3, RC + |->BC_CAT_Z: + | mov L:RB, SAVE_L + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_meta_cat // (lua_State *L, TValue *top, int left) + | // NULL (finished) or TValue * (metamethod) returned in eax (RC). + | mov BASE, L:RB->base + | test RC, RC + | jnz ->vmeta_binop + | movzx RB, PC_RB // Copy result to Stk[RA] from Stk[RB]. + | movzx RA, PC_RA + |.if X64 + | mov RCa, [BASE+RB*8] + | mov [BASE+RA*8], RCa + |.else + | mov RC, [BASE+RB*8+4] + | mov RB, [BASE+RB*8] + | mov [BASE+RA*8+4], RC + | mov [BASE+RA*8], RB + |.endif + | ins_next + break; + + /* -- Constant ops ------------------------------------------------------ */ + + case BC_KSTR: + | ins_AND // RA = dst, RD = str const (~) + | mov RD, [KBASE+RD*4] + | mov dword [BASE+RA*8+4], LJ_TSTR + | mov [BASE+RA*8], RD + | ins_next + break; + case BC_KCDATA: + |.if FFI + | ins_AND // RA = dst, RD = cdata const (~) + | mov RD, [KBASE+RD*4] + | mov dword [BASE+RA*8+4], LJ_TCDATA + | mov [BASE+RA*8], RD + | ins_next + |.endif + break; + case BC_KSHORT: + | ins_AD // RA = dst, RD = signed int16 literal + |.if DUALNUM + | movsx RD, RDW + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RD + |.elif SSE + | movsx RD, RDW // Sign-extend literal. + | cvtsi2sd xmm0, RD + | movsd qword [BASE+RA*8], xmm0 + |.else + | fild PC_RD // Refetch signed RD from instruction. + | fstp qword [BASE+RA*8] + |.endif + | ins_next + break; + case BC_KNUM: + | ins_AD // RA = dst, RD = num const + |.if SSE + | movsd xmm0, qword [KBASE+RD*8] + | movsd qword [BASE+RA*8], xmm0 + |.else + | fld qword [KBASE+RD*8] + | fstp qword [BASE+RA*8] + |.endif + | ins_next + break; + case BC_KPRI: + | ins_AND // RA = dst, RD = primitive type (~) + | mov [BASE+RA*8+4], RD + | ins_next + break; + case BC_KNIL: + | ins_AD // RA = dst_start, RD = dst_end + | lea RA, [BASE+RA*8+12] + | lea RD, [BASE+RD*8+4] + | mov RB, LJ_TNIL + | mov [RA-8], RB // Sets minimum 2 slots. + |1: + | mov [RA], RB + | add RA, 8 + | cmp RA, RD + | jbe <1 + | ins_next + break; + + /* -- Upvalue and function ops ------------------------------------------ */ + + case BC_UGET: + | ins_AD // RA = dst, RD = upvalue # + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)] + | mov RB, UPVAL:RB->v + |.if X64 + | mov RDa, [RB] + | mov [BASE+RA*8], RDa + |.else + | mov RD, [RB+4] + | mov RB, [RB] + | mov [BASE+RA*8+4], RD + | mov [BASE+RA*8], RB + |.endif + | ins_next + break; + case BC_USETV: +#define TV2MARKOFS \ + ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)) + | ins_AD // RA = upvalue #, RD = src + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | cmp byte UPVAL:RB->closed, 0 + | mov RB, UPVAL:RB->v + | mov RA, [BASE+RD*8] + | mov RD, [BASE+RD*8+4] + | mov [RB], RA + | mov [RB+4], RD + | jz >1 + | // Check barrier for closed upvalue. + | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv) + | jnz >2 + |1: + | ins_next + | + |2: // Upvalue is black. Check if new value is collectable and white. + | sub RD, LJ_TISGCV + | cmp RD, LJ_TNUMX - LJ_TISGCV // tvisgcv(v) + | jbe <1 + | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v) + | jz <1 + | // Crossed a write barrier. Move the barrier forward. + |.if X64 and not X64WIN + | mov FCARG2, RB + | mov RB, BASE // Save BASE. + |.else + | xchg FCARG2, RB // Save BASE (FCARG2 == BASE). + |.endif + | lea GL:FCARG1, [DISPATCH+GG_DISP2G] + | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv) + | mov BASE, RB // Restore BASE. + | jmp <1 + break; +#undef TV2MARKOFS + case BC_USETS: + | ins_AND // RA = upvalue #, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov GCOBJ:RA, [KBASE+RD*4] + | mov RD, UPVAL:RB->v + | mov [RD], GCOBJ:RA + | mov dword [RD+4], LJ_TSTR + | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv) + | jnz >2 + |1: + | ins_next + | + |2: // Check if string is white and ensure upvalue is closed. + | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str) + | jz <1 + | cmp byte UPVAL:RB->closed, 0 + | jz <1 + | // Crossed a write barrier. Move the barrier forward. + | mov RB, BASE // Save BASE (FCARG2 == BASE). + | mov FCARG2, RD + | lea GL:FCARG1, [DISPATCH+GG_DISP2G] + | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv) + | mov BASE, RB // Restore BASE. + | jmp <1 + break; + case BC_USETN: + | ins_AD // RA = upvalue #, RD = num const + | mov LFUNC:RB, [BASE-8] + |.if SSE + | movsd xmm0, qword [KBASE+RD*8] + |.else + | fld qword [KBASE+RD*8] + |.endif + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov RA, UPVAL:RB->v + |.if SSE + | movsd qword [RA], xmm0 + |.else + | fstp qword [RA] + |.endif + | ins_next + break; + case BC_USETP: + | ins_AND // RA = upvalue #, RD = primitive type (~) + | mov LFUNC:RB, [BASE-8] + | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] + | mov RA, UPVAL:RB->v + | mov [RA+4], RD + | ins_next + break; + case BC_UCLO: + | ins_AD // RA = level, RD = target + | branchPC RD // Do this first to free RD. + | mov L:RB, SAVE_L + | cmp dword L:RB->openupval, 0 + | je >1 + | mov L:RB->base, BASE + | lea FCARG2, [BASE+RA*8] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | call extern lj_func_closeuv@8 // (lua_State *L, TValue *level) + | mov BASE, L:RB->base + |1: + | ins_next + break; + + case BC_FNEW: + | ins_AND // RA = dst, RD = proto const (~) (holding function prototype) + |.if X64 + | mov L:RB, SAVE_L + | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG3d, [BASE-8] + | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *. + | mov CARG1d, L:RB + |.else + | mov LFUNC:RA, [BASE-8] + | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *. + | mov L:RB, SAVE_L + | mov ARG3, LFUNC:RA + | mov ARG2, PROTO:RD + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | // (lua_State *L, GCproto *pt, GCfuncL *parent) + | call extern lj_func_newL_gc + | // GCfuncL * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], LFUNC:RC + | mov dword [BASE+RA*8+4], LJ_TFUNC + | ins_next + break; + + /* -- Table ops --------------------------------------------------------- */ + + case BC_TNEW: + | ins_AD // RA = dst, RD = hbits|asize + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] + | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] + | mov SAVE_PC, PC + | jae >5 + |1: + |.if X64 + | mov CARG3d, RD + | and RD, 0x7ff + | shr CARG3d, 11 + |.else + | mov RA, RD + | and RD, 0x7ff + | shr RA, 11 + | mov ARG3, RA + |.endif + | cmp RD, 0x7ff + | je >3 + |2: + |.if X64 + | mov L:CARG1d, L:RB + | mov CARG2d, RD + |.else + | mov ARG1, L:RB + | mov ARG2, RD + |.endif + | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) + | // Table * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], TAB:RC + | mov dword [BASE+RA*8+4], LJ_TTAB + | ins_next + |3: // Turn 0x7ff into 0x801. + | mov RD, 0x801 + | jmp <2 + |5: + | mov L:FCARG1, L:RB + | call extern lj_gc_step_fixtop@4 // (lua_State *L) + | movzx RD, PC_RD + | jmp <1 + break; + case BC_TDUP: + | ins_AND // RA = dst, RD = table const (~) (holding template table) + | mov L:RB, SAVE_L + | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] + | mov SAVE_PC, PC + | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] + | mov L:RB->base, BASE + | jae >3 + |2: + | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE + | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA + | call extern lj_tab_dup@8 // (lua_State *L, Table *kt) + | // Table * returned in eax (RC). + | mov BASE, L:RB->base + | movzx RA, PC_RA + | mov [BASE+RA*8], TAB:RC + | mov dword [BASE+RA*8+4], LJ_TTAB + | ins_next + |3: + | mov L:FCARG1, L:RB + | call extern lj_gc_step_fixtop@4 // (lua_State *L) + | movzx RD, PC_RD // Need to reload RD. + | not RDa + | jmp <2 + break; + + case BC_GGET: + | ins_AND // RA = dst, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov TAB:RB, LFUNC:RB->env + | mov STR:RC, [KBASE+RD*4] + | jmp ->BC_TGETS_Z + break; + case BC_GSET: + | ins_AND // RA = src, RD = str const (~) + | mov LFUNC:RB, [BASE-8] + | mov TAB:RB, LFUNC:RB->env + | mov STR:RC, [KBASE+RD*4] + | jmp ->BC_TSETS_Z + break; + + case BC_TGETV: + | ins_ABC // RA = dst, RB = table, RC = key + | checktab RB, ->vmeta_tgetv + | mov TAB:RB, [BASE+RB*8] + | + | // Integer key? + |.if DUALNUM + | checkint RC, >5 + | mov RC, dword [BASE+RC*8] + |.else + | // Convert number to int and back and compare. + | checknum RC, >5 + |.if SSE + | movsd xmm0, qword [BASE+RC*8] + | cvtsd2si RC, xmm0 + | cvtsi2sd xmm1, RC + | ucomisd xmm0, xmm1 + |.else + | fld qword [BASE+RC*8] + | fist ARG1 + | fild ARG1 + | fcomparepp + | mov RC, ARG1 + |.endif + | jne ->vmeta_tgetv // Generic numeric key? Use fallback. + |.endif + | cmp RC, TAB:RB->asize // Takes care of unordered, too. + | jae ->vmeta_tgetv // Not in array part? Use fallback. + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >2 + | // Get array slot. + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC] + | mov RC, [RC+4] + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + |.endif + |1: + | ins_next + | + |2: // Check for __index if table value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz >3 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tgetv // 'no __index' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + |3: + | mov dword [BASE+RA*8+4], LJ_TNIL + | jmp <1 + | + |5: // String key? + | checkstr RC, ->vmeta_tgetv + | mov STR:RC, [BASE+RC*8] + | jmp ->BC_TGETS_Z + break; + case BC_TGETS: + | ins_ABC // RA = dst, RB = table, RC = str const (~) + | not RCa + | mov STR:RC, [KBASE+RC*4] + | checktab RB, ->vmeta_tgets + | mov TAB:RB, [BASE+RB*8] + |->BC_TGETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA. + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | add NODE:RA, TAB:RB->node + |1: + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >4 + | cmp dword NODE:RA->key.gcr, STR:RC + | jne >4 + | // Ok, key found. Assumes: offsetof(Node, val) == 0 + | cmp dword [RA+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >5 // Key found, but nil value? + | movzx RC, PC_RA + | // Get node value. + |.if X64 + | mov RBa, [RA] + | mov [BASE+RC*8], RBa + |.else + | mov RB, [RA] + | mov RA, [RA+4] + | mov [BASE+RC*8], RB + | mov [BASE+RC*8+4], RA + |.endif + |2: + | ins_next + | + |3: + | movzx RC, PC_RA + | mov dword [BASE+RC*8+4], LJ_TNIL + | jmp <2 + | + |4: // Follow hash chain. + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <1 + | // End of hash chain: key not found, nil result. + | + |5: // Check for __index if table value is nil. + | mov TAB:RA, TAB:RB->metatable + | test TAB:RA, TAB:RA + | jz <3 // No metatable: done. + | test byte TAB:RA->nomm, 1<vmeta_tgets // Caveat: preserve STR:RC. + break; + case BC_TGETB: + | ins_ABC // RA = dst, RB = table, RC = byte literal + | checktab RB, ->vmeta_tgetb + | mov TAB:RB, [BASE+RB*8] + | cmp RC, TAB:RB->asize + | jae ->vmeta_tgetb + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath. + | je >2 + | // Get array slot. + |.if X64 + | mov RBa, [RC] + | mov [BASE+RA*8], RBa + |.else + | mov RB, [RC] + | mov RC, [RC+4] + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + |.endif + |1: + | ins_next + | + |2: // Check for __index if table value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz >3 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tgetb // 'no __index' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + |3: + | mov dword [BASE+RA*8+4], LJ_TNIL + | jmp <1 + break; + + case BC_TSETV: + | ins_ABC // RA = src, RB = table, RC = key + | checktab RB, ->vmeta_tsetv + | mov TAB:RB, [BASE+RB*8] + | + | // Integer key? + |.if DUALNUM + | checkint RC, >5 + | mov RC, dword [BASE+RC*8] + |.else + | // Convert number to int and back and compare. + | checknum RC, >5 + |.if SSE + | movsd xmm0, qword [BASE+RC*8] + | cvtsd2si RC, xmm0 + | cvtsi2sd xmm1, RC + | ucomisd xmm0, xmm1 + |.else + | fld qword [BASE+RC*8] + | fist ARG1 + | fild ARG1 + | fcomparepp + | mov RC, ARG1 + |.endif + | jne ->vmeta_tsetv // Generic numeric key? Use fallback. + |.endif + | cmp RC, TAB:RB->asize // Takes care of unordered, too. + | jae ->vmeta_tsetv + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL + | je >3 // Previous value is nil? + |1: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: // Set array slot. + |.if X64 + | mov RBa, [BASE+RA*8] + | mov [RC], RBa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <1 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsetv // 'no __newindex' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + | jmp <1 + | + |5: // String key? + | checkstr RC, ->vmeta_tsetv + | mov STR:RC, [BASE+RC*8] + | jmp ->BC_TSETS_Z + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RA + | movzx RA, PC_RA // Restore RA. + | jmp <2 + break; + case BC_TSETS: + | ins_ABC // RA = src, RB = table, RC = str const (~) + | not RCa + | mov STR:RC, [KBASE+RC*4] + | checktab RB, ->vmeta_tsets + | mov TAB:RB, [BASE+RB*8] + |->BC_TSETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA. + | mov RA, TAB:RB->hmask + | and RA, STR:RC->hash + | imul RA, #NODE + | mov byte TAB:RB->nomm, 0 // Clear metamethod cache. + | add NODE:RA, TAB:RB->node + |1: + | cmp dword NODE:RA->key.it, LJ_TSTR + | jne >5 + | cmp dword NODE:RA->key.gcr, STR:RC + | jne >5 + | // Ok, key found. Assumes: offsetof(Node, val) == 0 + | cmp dword [RA+4], LJ_TNIL + | je >4 // Previous value is nil? + |2: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |3: // Set node value. + | movzx RC, PC_RA + |.if X64 + | mov RBa, [BASE+RC*8] + | mov [RA], RBa + |.else + | mov RB, [BASE+RC*8+4] + | mov RC, [BASE+RC*8] + | mov [RA+4], RB + | mov [RA], RC + |.endif + | ins_next + | + |4: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <2 + | mov TMP1, RA // Save RA. + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + | mov RA, TMP1 // Restore RA. + | jmp <2 + | + |5: // Follow hash chain. + | mov NODE:RA, NODE:RA->next + | test NODE:RA, NODE:RA + | jnz <1 + | // End of hash chain: key not found, add a new one. + | + | // But check for __newindex first. + | mov TAB:RA, TAB:RB->metatable + | test TAB:RA, TAB:RA + | jz >6 // No metatable: continue. + | test byte TAB:RA->nomm, 1<vmeta_tsets // 'no __newindex' flag NOT set: check. + |6: + | mov TMP1, STR:RC + | mov TMP2, LJ_TSTR + | mov TMP3, TAB:RB // Save TAB:RB for us. + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE + | lea CARG3, TMP1 + | mov CARG2d, TAB:RB + | mov L:RB, L:CARG1d + |.else + | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. + | mov ARG2, TAB:RB + | mov L:RB, SAVE_L + | mov ARG3, RC + | mov ARG1, L:RB + | mov L:RB->base, BASE + |.endif + | mov SAVE_PC, PC + | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) + | // Handles write barrier for the new key. TValue * returned in eax (RC). + | mov BASE, L:RB->base + | mov TAB:RB, TMP3 // Need TAB:RB for barrier. + | mov RA, eax + | jmp <2 // Must check write barrier for value. + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RC // Destroys STR:RC. + | jmp <3 + break; + case BC_TSETB: + | ins_ABC // RA = src, RB = table, RC = byte literal + | checktab RB, ->vmeta_tsetb + | mov TAB:RB, [BASE+RB*8] + | cmp RC, TAB:RB->asize + | jae ->vmeta_tsetb + | shl RC, 3 + | add RC, TAB:RB->array + | cmp dword [RC+4], LJ_TNIL + | je >3 // Previous value is nil? + |1: + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: // Set array slot. + |.if X64 + | mov RAa, [BASE+RA*8] + | mov [RC], RAa + |.else + | mov RB, [BASE+RA*8+4] + | mov RA, [BASE+RA*8] + | mov [RC+4], RB + | mov [RC], RA + |.endif + | ins_next + | + |3: // Check for __newindex if previous value is nil. + | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath. + | jz <1 + | mov TAB:RA, TAB:RB->metatable + | test byte TAB:RA->nomm, 1<vmeta_tsetb // 'no __newindex' flag NOT set: check. + | movzx RA, PC_RA // Restore RA. + | jmp <1 + | + |7: // Possible table write barrier for the value. Skip valiswhite check. + | barrierback TAB:RB, RA + | movzx RA, PC_RA // Restore RA. + | jmp <2 + break; + + case BC_TSETM: + | ins_AD // RA = base (table at base-1), RD = num const (start index) + | mov TMP1, KBASE // Need one more free register. + | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word. + |1: + | lea RA, [BASE+RA*8] + | mov TAB:RB, [RA-8] // Guaranteed to be a table. + | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table) + | jnz >7 + |2: + | mov RD, MULTRES + | sub RD, 1 + | jz >4 // Nothing to copy? + | add RD, KBASE // Compute needed size. + | cmp RD, TAB:RB->asize + | ja >5 // Doesn't fit into array part? + | sub RD, KBASE + | shl KBASE, 3 + | add KBASE, TAB:RB->array + |3: // Copy result slots to table. + |.if X64 + | mov RBa, [RA] + | add RA, 8 + | mov [KBASE], RBa + |.else + | mov RB, [RA] + | mov [KBASE], RB + | mov RB, [RA+4] + | add RA, 8 + | mov [KBASE+4], RB + |.endif + | add KBASE, 8 + | sub RD, 1 + | jnz <3 + |4: + | mov KBASE, TMP1 + | ins_next + | + |5: // Need to resize array part. + |.if X64 + | mov L:CARG1d, SAVE_L + | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. + | mov CARG2d, TAB:RB + | mov CARG3d, RD + | mov L:RB, L:CARG1d + |.else + | mov ARG2, TAB:RB + | mov L:RB, SAVE_L + | mov L:RB->base, BASE + | mov ARG3, RD + | mov ARG1, L:RB + |.endif + | mov SAVE_PC, PC + | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) + | mov BASE, L:RB->base + | movzx RA, PC_RA // Restore RA. + | jmp <1 // Retry. + | + |7: // Possible table write barrier for any value. Skip valiswhite check. + | barrierback TAB:RB, RD + | jmp <2 + break; + + /* -- Calls and vararg handling ----------------------------------------- */ + + case BC_CALL: case BC_CALLM: + | ins_A_C // RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs + if (op == BC_CALLM) { + | add NARGS:RD, MULTRES + } + | cmp dword [BASE+RA*8+4], LJ_TFUNC + | mov LFUNC:RB, [BASE+RA*8] + | jne ->vmeta_call_ra + | lea BASE, [BASE+RA*8+8] + | ins_call + break; + + case BC_CALLMT: + | ins_AD // RA = base, RD = extra_nargs + | add NARGS:RD, MULTRES + | // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op. + break; + case BC_CALLT: + | ins_AD // RA = base, RD = nargs+1 + | lea RA, [BASE+RA*8+8] + | mov KBASE, BASE // Use KBASE for move + vmeta_call hint. + | mov LFUNC:RB, [RA-8] + | cmp dword [RA-4], LJ_TFUNC + | jne ->vmeta_call + |->BC_CALLT_Z: + | mov PC, [BASE-4] + | test PC, FRAME_TYPE + | jnz >7 + |1: + | mov [BASE-8], LFUNC:RB // Copy function down, reloaded below. + | mov MULTRES, NARGS:RD + | sub NARGS:RD, 1 + | jz >3 + |2: // Move args down. + |.if X64 + | mov RBa, [RA] + | add RA, 8 + | mov [KBASE], RBa + |.else + | mov RB, [RA] + | mov [KBASE], RB + | mov RB, [RA+4] + | add RA, 8 + | mov [KBASE+4], RB + |.endif + | add KBASE, 8 + | sub NARGS:RD, 1 + | jnz <2 + | + | mov LFUNC:RB, [BASE-8] + |3: + | mov NARGS:RD, MULTRES + | cmp byte LFUNC:RB->ffid, 1 // (> FF_C) Calling a fast function? + | ja >5 + |4: + | ins_callt + | + |5: // Tailcall to a fast function. + | test PC, FRAME_TYPE // Lua frame below? + | jnz <4 + | movzx RA, PC_RA + | not RAa + | lea RA, [BASE+RA*8] + | mov LFUNC:KBASE, [RA-8] // Need to prepare KBASE. + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | jmp <4 + | + |7: // Tailcall from a vararg function. + | sub PC, FRAME_VARG + | test PC, FRAME_TYPEP + | jnz >8 // Vararg frame below? + | sub BASE, PC // Need to relocate BASE/KBASE down. + | mov KBASE, BASE + | mov PC, [BASE-4] + | jmp <1 + |8: + | add PC, FRAME_VARG + | jmp <1 + break; + + case BC_ITERC: + | ins_A // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1) + | lea RA, [BASE+RA*8+8] // fb = base+1 + |.if X64 + | mov RBa, [RA-24] // Copy state. fb[0] = fb[-3]. + | mov RCa, [RA-16] // Copy control var. fb[1] = fb[-2]. + | mov [RA], RBa + | mov [RA+8], RCa + |.else + | mov RB, [RA-24] // Copy state. fb[0] = fb[-3]. + | mov RC, [RA-20] + | mov [RA], RB + | mov [RA+4], RC + | mov RB, [RA-16] // Copy control var. fb[1] = fb[-2]. + | mov RC, [RA-12] + | mov [RA+8], RB + | mov [RA+12], RC + |.endif + | mov LFUNC:RB, [RA-32] // Copy callable. fb[-1] = fb[-4] + | mov RC, [RA-28] + | mov [RA-8], LFUNC:RB + | mov [RA-4], RC + | cmp RC, LJ_TFUNC // Handle like a regular 2-arg call. + | mov NARGS:RD, 2+1 + | jne ->vmeta_call + | mov BASE, RA + | ins_call + break; + + case BC_ITERN: + | ins_A // RA = base, (RB = nresults+1, RC = nargs+1 (2+1)) + |.if JIT + | // NYI: add hotloop, record BC_ITERN. + |.endif + | mov TMP1, KBASE // Need two more free registers. + | mov TMP2, DISPATCH + | mov TAB:RB, [BASE+RA*8-16] + | mov RC, [BASE+RA*8-8] // Get index from control var. + | mov DISPATCH, TAB:RB->asize + | add PC, 4 + | mov KBASE, TAB:RB->array + |1: // Traverse array part. + | cmp RC, DISPATCH; jae >5 // Index points after array part? + | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4 + |.if DUALNUM + | mov dword [BASE+RA*8+4], LJ_TISNUM + | mov dword [BASE+RA*8], RC + |.elif SSE + | cvtsi2sd xmm0, RC + |.else + | fild dword [BASE+RA*8-8] + |.endif + | // Copy array slot to returned value. + |.if X64 + | mov RBa, [KBASE+RC*8] + | mov [BASE+RA*8+8], RBa + |.else + | mov RB, [KBASE+RC*8+4] + | mov [BASE+RA*8+12], RB + | mov RB, [KBASE+RC*8] + | mov [BASE+RA*8+8], RB + |.endif + | add RC, 1 + | // Return array index as a numeric key. + |.if DUALNUM + | // See above. + |.elif SSE + | movsd qword [BASE+RA*8], xmm0 + |.else + | fstp qword [BASE+RA*8] + |.endif + | mov [BASE+RA*8-8], RC // Update control var. + |2: + | movzx RD, PC_RD // Get target from ITERL. + | branchPC RD + |3: + | mov DISPATCH, TMP2 + | mov KBASE, TMP1 + | ins_next + | + |4: // Skip holes in array part. + | add RC, 1 + |.if not (DUALNUM or SSE) + | mov [BASE+RA*8-8], RC + |.endif + | jmp <1 + | + |5: // Traverse hash part. + | sub RC, DISPATCH + |6: + | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1. + | imul KBASE, RC, #NODE + | add NODE:KBASE, TAB:RB->node + | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7 + | lea DISPATCH, [RC+DISPATCH+1] + | // Copy key and value from hash slot. + |.if X64 + | mov RBa, NODE:KBASE->key + | mov RCa, NODE:KBASE->val + | mov [BASE+RA*8], RBa + | mov [BASE+RA*8+8], RCa + |.else + | mov RB, NODE:KBASE->key.gcr + | mov RC, NODE:KBASE->key.it + | mov [BASE+RA*8], RB + | mov [BASE+RA*8+4], RC + | mov RB, NODE:KBASE->val.gcr + | mov RC, NODE:KBASE->val.it + | mov [BASE+RA*8+8], RB + | mov [BASE+RA*8+12], RC + |.endif + | mov [BASE+RA*8-8], DISPATCH + | jmp <2 + | + |7: // Skip holes in hash part. + | add RC, 1 + | jmp <6 + break; + + case BC_ISNEXT: + | ins_AD // RA = base, RD = target (points to ITERN) + | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5 + | mov CFUNC:RB, [BASE+RA*8-24] + | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5 + | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5 + | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 + | branchPC RD + | mov dword [BASE+RA*8-8], 0 // Initialize control var. + | mov dword [BASE+RA*8-4], 0xfffe7fff + |1: + | ins_next + |5: // Despecialize bytecode if any of the checks fail. + | mov PC_OP, BC_JMP + | branchPC RD + | mov byte [PC], BC_ITERC + | jmp <1 + break; + + case BC_VARG: + | ins_ABC // RA = base, RB = nresults+1, RC = numparams + | mov TMP1, KBASE // Need one more free register. + | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)] + | lea RA, [BASE+RA*8] + | sub KBASE, [BASE-4] + | // Note: KBASE may now be even _above_ BASE if nargs was < numparams. + | test RB, RB + | jz >5 // Copy all varargs? + | lea RB, [RA+RB*8-8] + | cmp KBASE, BASE // No vararg slots? + | jnb >2 + |1: // Copy vararg slots to destination slots. + |.if X64 + | mov RCa, [KBASE-8] + | add KBASE, 8 + | mov [RA], RCa + |.else + | mov RC, [KBASE-8] + | mov [RA], RC + | mov RC, [KBASE-4] + | add KBASE, 8 + | mov [RA+4], RC + |.endif + | add RA, 8 + | cmp RA, RB // All destination slots filled? + | jnb >3 + | cmp KBASE, BASE // No more vararg slots? + | jb <1 + |2: // Fill up remainder with nil. + | mov dword [RA+4], LJ_TNIL + | add RA, 8 + | cmp RA, RB + | jb <2 + |3: + | mov KBASE, TMP1 + | ins_next + | + |5: // Copy all varargs. + | mov MULTRES, 1 // MULTRES = 0+1 + | mov RC, BASE + | sub RC, KBASE + | jbe <3 // No vararg slots? + | mov RB, RC + | shr RB, 3 + | add RB, 1 + | mov MULTRES, RB // MULTRES = #varargs+1 + | mov L:RB, SAVE_L + | add RC, RA + | cmp RC, L:RB->maxstack + | ja >7 // Need to grow stack? + |6: // Copy all vararg slots. + |.if X64 + | mov RCa, [KBASE-8] + | add KBASE, 8 + | mov [RA], RCa + |.else + | mov RC, [KBASE-8] + | mov [RA], RC + | mov RC, [KBASE-4] + | add KBASE, 8 + | mov [RA+4], RC + |.endif + | add RA, 8 + | cmp KBASE, BASE // No more vararg slots? + | jb <6 + | jmp <3 + | + |7: // Grow stack for varargs. + | mov L:RB->base, BASE + | mov L:RB->top, RA + | mov SAVE_PC, PC + | sub KBASE, BASE // Need delta, because BASE may change. + | mov FCARG2, MULTRES + | sub FCARG2, 1 + | mov FCARG1, L:RB + | call extern lj_state_growstack@8 // (lua_State *L, int n) + | mov BASE, L:RB->base + | mov RA, L:RB->top + | add KBASE, BASE + | jmp <6 + break; + + /* -- Returns ----------------------------------------------------------- */ + + case BC_RETM: + | ins_AD // RA = results, RD = extra_nresults + | add RD, MULTRES // MULTRES >=1, so RD >=1. + | // Fall through. Assumes BC_RET follows and ins_AD is a no-op. + break; + + case BC_RET: case BC_RET0: case BC_RET1: + | ins_AD // RA = results, RD = nresults+1 + if (op != BC_RET0) { + | shl RA, 3 + } + |1: + | mov PC, [BASE-4] + | mov MULTRES, RD // Save nresults+1. + | test PC, FRAME_TYPE // Check frame type marker. + | jnz >7 // Not returning to a fixarg Lua func? + switch (op) { + case BC_RET: + |->BC_RET_Z: + | mov KBASE, BASE // Use KBASE for result move. + | sub RD, 1 + | jz >3 + |2: // Move results down. + |.if X64 + | mov RBa, [KBASE+RA] + | mov [KBASE-8], RBa + |.else + | mov RB, [KBASE+RA] + | mov [KBASE-8], RB + | mov RB, [KBASE+RA+4] + | mov [KBASE-4], RB + |.endif + | add KBASE, 8 + | sub RD, 1 + | jnz <2 + |3: + | mov RD, MULTRES // Note: MULTRES may be >255. + | movzx RB, PC_RB // So cannot compare with RDL! + |5: + | cmp RB, RD // More results expected? + | ja >6 + break; + case BC_RET1: + |.if X64 + | mov RBa, [BASE+RA] + | mov [BASE-8], RBa + |.else + | mov RB, [BASE+RA+4] + | mov [BASE-4], RB + | mov RB, [BASE+RA] + | mov [BASE-8], RB + |.endif + /* fallthrough */ + case BC_RET0: + |5: + | cmp PC_RB, RDL // More results expected? + | ja >6 + default: + break; + } + | movzx RA, PC_RA + | not RAa // Note: ~RA = -(RA+1) + | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 + | mov LFUNC:KBASE, [BASE-8] + | mov KBASE, LFUNC:KBASE->pc + | mov KBASE, [KBASE+PC2PROTO(k)] + | ins_next + | + |6: // Fill up results with nil. + if (op == BC_RET) { + | mov dword [KBASE-4], LJ_TNIL // Note: relies on shifted base. + | add KBASE, 8 + } else { + | mov dword [BASE+RD*8-12], LJ_TNIL + } + | add RD, 1 + | jmp <5 + | + |7: // Non-standard return case. + | lea RB, [PC-FRAME_VARG] + | test RB, FRAME_TYPEP + | jnz ->vm_return + | // Return from vararg function: relocate BASE down and RA up. + | sub BASE, RB + if (op != BC_RET0) { + | add RA, RB + } + | jmp <1 + break; + + /* -- Loops and branches ------------------------------------------------ */ + + |.define FOR_IDX, [RA]; .define FOR_TIDX, dword [RA+4] + |.define FOR_STOP, [RA+8]; .define FOR_TSTOP, dword [RA+12] + |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20] + |.define FOR_EXT, [RA+24]; .define FOR_TEXT, dword [RA+28] + + case BC_FORL: + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op. + break; + + case BC_JFORI: + case BC_JFORL: +#if !LJ_HASJIT + break; +#endif + case BC_FORI: + case BC_IFORL: + vk = (op == BC_IFORL || op == BC_JFORL); + | ins_AJ // RA = base, RD = target (after end of loop or start of loop) + | lea RA, [BASE+RA*8] + if (LJ_DUALNUM) { + | cmp FOR_TIDX, LJ_TISNUM; jne >9 + if (!vk) { + | cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for + | cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for + | mov RB, dword FOR_IDX + | cmp dword FOR_STEP, 0; jl >5 + } else { +#ifdef LUA_USE_ASSERT + | cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type + | cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type +#endif + | mov RB, dword FOR_STEP + | test RB, RB; js >5 + | add RB, dword FOR_IDX; jo >1 + | mov dword FOR_IDX, RB + } + | cmp RB, dword FOR_STOP + | mov FOR_TEXT, LJ_TISNUM + | mov dword FOR_EXT, RB + if (op == BC_FORI) { + | jle >7 + |1: + |6: + | branchPC RD + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jle =>BC_JLOOP + |1: + |6: + } else if (op == BC_IFORL) { + | jg >7 + |6: + | branchPC RD + |1: + } else { + | jle =>BC_JLOOP + |1: + |6: + } + |7: + | ins_next + | + |5: // Invert check for negative step. + if (vk) { + | add RB, dword FOR_IDX; jo <1 + | mov dword FOR_IDX, RB + } + | cmp RB, dword FOR_STOP + | mov FOR_TEXT, LJ_TISNUM + | mov dword FOR_EXT, RB + if (op == BC_FORI) { + | jge <7 + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jge =>BC_JLOOP + } else if (op == BC_IFORL) { + | jl <7 + } else { + | jge =>BC_JLOOP + } + | jmp <6 + |9: // Fallback to FP variant. + } else if (!vk) { + | cmp FOR_TIDX, LJ_TISNUM + } + if (!vk) { + | jae ->vmeta_for + | cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for + } else { +#ifdef LUA_USE_ASSERT + | cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type + | cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type +#endif + } + | mov RB, FOR_TSTEP // Load type/hiword of for step. + if (!vk) { + | cmp RB, LJ_TISNUM; jae ->vmeta_for + } + |.if SSE + | movsd xmm0, qword FOR_IDX + | movsd xmm1, qword FOR_STOP + if (vk) { + | addsd xmm0, qword FOR_STEP + | movsd qword FOR_IDX, xmm0 + | test RB, RB; js >3 + } else { + | jl >3 + } + | ucomisd xmm1, xmm0 + |1: + | movsd qword FOR_EXT, xmm0 + |.else + | fld qword FOR_STOP + | fld qword FOR_IDX + if (vk) { + | fadd qword FOR_STEP // nidx = idx + step + | fst qword FOR_IDX + | fst qword FOR_EXT + | test RB, RB; js >1 + } else { + | fst qword FOR_EXT + | jl >1 + } + | fxch // Swap lim/(n)idx if step non-negative. + |1: + | fcomparepp + |.endif + if (op == BC_FORI) { + |.if DUALNUM + | jnb <7 + |.else + | jnb >2 + | branchPC RD + |.endif + } else if (op == BC_JFORI) { + | branchPC RD + | movzx RD, PC_RD + | jnb =>BC_JLOOP + } else if (op == BC_IFORL) { + |.if DUALNUM + | jb <7 + |.else + | jb >2 + | branchPC RD + |.endif + } else { + | jnb =>BC_JLOOP + } + |.if DUALNUM + | jmp <6 + |.else + |2: + | ins_next + |.endif + |.if SSE + |3: // Invert comparison if step is negative. + | ucomisd xmm0, xmm1 + | jmp <1 + |.endif + break; + + case BC_ITERL: + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op. + break; + + case BC_JITERL: +#if !LJ_HASJIT + break; +#endif + case BC_IITERL: + | ins_AJ // RA = base, RD = target + | lea RA, [BASE+RA*8] + | mov RB, [RA+4] + | cmp RB, LJ_TNIL; je >1 // Stop if iterator returned nil. + if (op == BC_JITERL) { + | mov [RA-4], RB + | mov RB, [RA] + | mov [RA-8], RB + | jmp =>BC_JLOOP + } else { + | branchPC RD // Otherwise save control var + branch. + | mov RD, [RA] + | mov [RA-4], RB + | mov [RA-8], RD + } + |1: + | ins_next + break; + + case BC_LOOP: + | ins_A // RA = base, RD = target (loop extent) + | // Note: RA/RD is only used by trace recorder to determine scope/extent + | // This opcode does NOT jump, it's only purpose is to detect a hot loop. + |.if JIT + | hotloop RB + |.endif + | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op. + break; + + case BC_ILOOP: + | ins_A // RA = base, RD = target (loop extent) + | ins_next + break; + + case BC_JLOOP: + |.if JIT + | ins_AD // RA = base (ignored), RD = traceno + | mov RA, [DISPATCH+DISPATCH_J(trace)] + | mov TRACE:RD, [RA+RD*4] + | mov RDa, TRACE:RD->mcode + | mov L:RB, SAVE_L + | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE + | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB + | // Save additional callee-save registers only used in compiled code. + |.if X64WIN + | mov TMPQ, r12 + | mov TMPa, r13 + | mov CSAVE_4, r14 + | mov CSAVE_3, r15 + | mov RAa, rsp + | sub rsp, 9*16+4*8 + | movdqa [RAa], xmm6 + | movdqa [RAa-1*16], xmm7 + | movdqa [RAa-2*16], xmm8 + | movdqa [RAa-3*16], xmm9 + | movdqa [RAa-4*16], xmm10 + | movdqa [RAa-5*16], xmm11 + | movdqa [RAa-6*16], xmm12 + | movdqa [RAa-7*16], xmm13 + | movdqa [RAa-8*16], xmm14 + | movdqa [RAa-9*16], xmm15 + |.elif X64 + | mov TMPQ, r12 + | mov TMPa, r13 + | sub rsp, 16 + |.endif + | jmp RDa + |.endif + break; + + case BC_JMP: + | ins_AJ // RA = unused, RD = target + | branchPC RD + | ins_next + break; + + /* -- Function headers -------------------------------------------------- */ + + /* + ** Reminder: A function may be called with func/args above L->maxstack, + ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot, + ** too. This means all FUNC* ops (including fast functions) must check + ** for stack overflow _before_ adding more slots! + */ + + case BC_FUNCF: + |.if JIT + | hotcall RB + |.endif + case BC_FUNCV: /* NYI: compiled vararg functions. */ + | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op. + break; + + case BC_JFUNCF: +#if !LJ_HASJIT + break; +#endif + case BC_IFUNCF: + | ins_AD // BASE = new base, RA = framesize, RD = nargs+1 + | mov KBASE, [PC-4+PC2PROTO(k)] + | mov L:RB, SAVE_L + | lea RA, [BASE+RA*8] // Top of frame. + | cmp RA, L:RB->maxstack + | ja ->vm_growstack_f + | movzx RA, byte [PC-4+PC2PROTO(numparams)] + | cmp NARGS:RD, RA // Check for missing parameters. + | jbe >3 + |2: + if (op == BC_JFUNCF) { + | movzx RD, PC_RD + | jmp =>BC_JLOOP + } else { + | ins_next + } + | + |3: // Clear missing parameters. + | mov dword [BASE+NARGS:RD*8-4], LJ_TNIL + | add NARGS:RD, 1 + | cmp NARGS:RD, RA + | jbe <3 + | jmp <2 + break; + + case BC_JFUNCV: +#if !LJ_HASJIT + break; +#endif + | int3 // NYI: compiled vararg functions + break; /* NYI: compiled vararg functions. */ + + case BC_IFUNCV: + | ins_AD // BASE = new base, RA = framesize, RD = nargs+1 + | lea RB, [NARGS:RD*8+FRAME_VARG] + | lea RD, [BASE+NARGS:RD*8] + | mov LFUNC:KBASE, [BASE-8] + | mov [RD-4], RB // Store delta + FRAME_VARG. + | mov [RD-8], LFUNC:KBASE // Store copy of LFUNC. + | mov L:RB, SAVE_L + | lea RA, [RD+RA*8] + | cmp RA, L:RB->maxstack + | ja ->vm_growstack_v // Need to grow stack. + | mov RA, BASE + | mov BASE, RD + | movzx RB, byte [PC-4+PC2PROTO(numparams)] + | test RB, RB + | jz >2 + |1: // Copy fixarg slots up to new frame. + | add RA, 8 + | cmp RA, BASE + | jnb >3 // Less args than parameters? + | mov KBASE, [RA-8] + | mov [RD], KBASE + | mov KBASE, [RA-4] + | mov [RD+4], KBASE + | add RD, 8 + | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC). + | sub RB, 1 + | jnz <1 + |2: + if (op == BC_JFUNCV) { + | movzx RD, PC_RD + | jmp =>BC_JLOOP + } else { + | mov KBASE, [PC-4+PC2PROTO(k)] + | ins_next + } + | + |3: // Clear missing parameters. + | mov dword [RD+4], LJ_TNIL + | add RD, 8 + | sub RB, 1 + | jnz <3 + | jmp <2 + break; + + case BC_FUNCC: + case BC_FUNCCW: + | ins_AD // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1 + | mov CFUNC:RB, [BASE-8] + | mov KBASEa, CFUNC:RB->f + | mov L:RB, SAVE_L + | lea RD, [BASE+NARGS:RD*8-8] + | mov L:RB->base, BASE + | lea RA, [RD+8*LUA_MINSTACK] + | cmp RA, L:RB->maxstack + | mov L:RB->top, RD + if (op == BC_FUNCC) { + |.if X64 + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | mov ARG1, L:RB + |.endif + } else { + |.if X64 + | mov CARG2, KBASEa + | mov CARG1d, L:RB // Caveat: CARG1d may be RA. + |.else + | mov ARG2, KBASEa + | mov ARG1, L:RB + |.endif + } + | ja ->vm_growstack_c // Need to grow stack. + | set_vmstate C + if (op == BC_FUNCC) { + | call KBASEa // (lua_State *L) + } else { + | // (lua_State *L, lua_CFunction f) + | call aword [DISPATCH+DISPATCH_GL(wrapf)] + } + | set_vmstate INTERP + | // nresults returned in eax (RD). + | mov BASE, L:RB->base + | lea RA, [BASE+RD*8] + | neg RA + | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8 + | mov PC, [BASE-4] // Fetch PC of caller. + | jmp ->vm_returnc + break; + + /* ---------------------------------------------------------------------- */ + + default: + fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); + exit(2); + break; + } +} + +static int build_backend(BuildCtx *ctx) +{ + int op; + dasm_growpc(Dst, BC__MAX); + build_subroutines(ctx); + |.code_op + for (op = 0; op < BC__MAX; op++) + build_ins(ctx, (BCOp)op, op); + return BC__MAX; +} + +/* Emit pseudo frame-info for all assembler functions. */ +static void emit_asm_debug(BuildCtx *ctx) +{ + int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); +#if LJ_64 +#define SZPTR "8" +#define BSZPTR "3" +#define REG_SP "0x7" +#define REG_RA "0x10" +#else +#define SZPTR "4" +#define BSZPTR "2" +#define REG_SP "0x4" +#define REG_RA "0x8" +#endif + switch (ctx->mode) { + case BUILD_elfasm: + fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n"); + fprintf(ctx->fp, + ".Lframe0:\n" + "\t.long .LECIE0-.LSCIE0\n" + ".LSCIE0:\n" + "\t.long 0xffffffff\n" + "\t.byte 0x1\n" + "\t.string \"\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE0:\n\n"); + fprintf(ctx->fp, + ".LSFDE0:\n" + "\t.long .LEFDE0-.LASFDE0\n" + ".LASFDE0:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad .Lbegin\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.long .Lbegin\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE0:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".LSFDE1:\n" + "\t.long .LEFDE1-.LASFDE1\n" + ".LASFDE1:\n" + "\t.long .Lframe0\n" +#if LJ_64 + "\t.quad lj_vm_ffi_call\n" + "\t.quad %d\n" + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.long lj_vm_ffi_call\n" + "\t.long %d\n" + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); +#endif +#if (defined(__sun__) && defined(__svr4__)) +#if LJ_64 + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n"); +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); +#endif +#else + fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); +#endif + fprintf(ctx->fp, + ".Lframe1:\n" + "\t.long .LECIE1-.LSCIE1\n" + ".LSCIE1:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zPR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 6\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.long lj_err_unwind_dwarf-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE1:\n\n"); + fprintf(ctx->fp, + ".LSFDE2:\n" + "\t.long .LEFDE2-.LASFDE2\n" + ".LASFDE2:\n" + "\t.long .LASFDE2-.Lframe1\n" + "\t.long .Lbegin-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#else + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE2:\n\n", fcofs, CFRAME_SIZE); +#if LJ_HASFFI + fprintf(ctx->fp, + ".Lframe2:\n" + "\t.long .LECIE2-.LSCIE2\n" + ".LSCIE2:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.string \"zR\"\n" + "\t.uleb128 0x1\n" + "\t.sleb128 -" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.uleb128 1\n" /* augmentation length */ + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n" + "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n" + "\t.align " SZPTR "\n" + ".LECIE2:\n\n"); + fprintf(ctx->fp, + ".LSFDE3:\n" + "\t.long .LEFDE3-.LASFDE3\n" + ".LASFDE3:\n" + "\t.long .LASFDE3-.Lframe2\n" + "\t.long lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.uleb128 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */ + "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ + "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */ +#endif + "\t.align " SZPTR "\n" + ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif + break; + /* Mental note: never let Apple design an assembler. + ** Or a linker. Or a plastic case. But I digress. + */ + case BUILD_machasm: { +#if LJ_HASFFI + int fcsize = 0; +#endif + int i; + fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n"); + fprintf(ctx->fp, + "EH_frame1:\n" + "\t.set L$set$x,LECIEX-LSCIEX\n" + "\t.long L$set$x\n" + "LSCIEX:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zPR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 6\n" /* augmentation length */ + "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */ +#if LJ_64 + "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n" + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEX:\n\n"); + for (i = 0; i < ctx->nsym; i++) { + const char *name = ctx->sym[i].name; + int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; + if (size == 0) continue; +#if LJ_HASFFI + if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; } +#endif + fprintf(ctx->fp, + "%s.eh:\n" + "LSFDE%d:\n" + "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" + "\t.long L$set$%d\n" + "LASFDE%d:\n" + "\t.long LASFDE%d-EH_frame1\n" + "\t.long %s-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ + "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ +#if LJ_64 + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ + "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ + "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ +#else + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ + "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ + "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDE%d:\n\n", + name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); + } +#if LJ_HASFFI + if (fcsize) { + fprintf(ctx->fp, + "EH_frame2:\n" + "\t.set L$set$y,LECIEY-LSCIEY\n" + "\t.long L$set$y\n" + "LSCIEY:\n" + "\t.long 0\n" + "\t.byte 0x1\n" + "\t.ascii \"zR\\0\"\n" + "\t.byte 0x1\n" + "\t.byte 128-" SZPTR "\n" + "\t.byte " REG_RA "\n" + "\t.byte 1\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n" +#else + "\t.byte 0x1b\n" /* pcrel|sdata4 */ + "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */ +#endif + "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n" + "\t.align " BSZPTR "\n" + "LECIEY:\n\n"); + fprintf(ctx->fp, + "_lj_vm_ffi_call.eh:\n" + "LSFDEY:\n" + "\t.set L$set$yy,LEFDEY-LASFDEY\n" + "\t.long L$set$yy\n" + "LASFDEY:\n" + "\t.long LASFDEY-EH_frame2\n" + "\t.long _lj_vm_ffi_call-.\n" + "\t.long %d\n" + "\t.byte 0\n" /* augmentation length */ +#if LJ_64 + "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */ + "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ + "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ +#else + "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */ + "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ + "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */ + "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */ +#endif + "\t.align " BSZPTR "\n" + "LEFDEY:\n\n", fcsize); + } +#endif +#if LJ_64 + fprintf(ctx->fp, "\t.subsections_via_symbols\n"); +#else + fprintf(ctx->fp, + "\t.non_lazy_symbol_pointer\n" + "L_lj_err_unwind_dwarf$non_lazy_ptr:\n" + ".indirect_symbol _lj_err_unwind_dwarf\n" + ".long 0\n"); +#endif + } + break; + default: /* Difficult for other modes. */ + break; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/lua/xedkbuild.bat b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/xedkbuild.bat new file mode 100644 index 0000000..240ec87 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/lua/xedkbuild.bat @@ -0,0 +1,92 @@ +@rem Script to build LuaJIT with the Xbox 360 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler) +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL +@if not defined XEDK goto :FAIL + +@setlocal +@rem ---- Host compiler ---- +@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@rem Error out for 64 bit host compiler +@minilua +@if errorlevel 8 goto :FAIL + +@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_ppc.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m peobj -o lj_vm.obj +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@rem ---- Cross compiler ---- +@set LJCOMPILE="%XEDK%\bin\win32\cl" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC +@set LJLIB="%XEDK%\bin\win32\lib" /nologo +@set "INCLUDE=%XEDK%\include\xbox" + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set "LJCOMPILE=%LJCOMPILE% /Zi" +:NODEBUG +@if "%1"=="amalg" goto :AMALG +%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj +@if errorlevel 1 goto :BAD +@goto :NOAMALG +:AMALG +%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c +@if errorlevel 1 goto :BAD +%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj +@if errorlevel 1 goto :BAD +:NOAMALG + +@del *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for Xbox 360 === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo To run this script you must open a "Visual Studio .NET Command Prompt" +@echo (32 bit host compiler). The Xbox 360 SDK must be installed, too. +:END diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic.c b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic.c new file mode 100644 index 0000000..ff081b5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic.c @@ -0,0 +1,916 @@ +#include "version.h" +#include +#include + +#include "common.h" +#include "char_base.h" +#include "char_data.h" +#include "item.h" +#include "battle.h" +#include "magic_base.h" +#include "magic.h" +#include "magic_field.h" +#include "family.h" +#include "handletime.h" +#include "battle_magic.h" +#include "battle_event.h" +#include"lssproto_serv.h" +#ifdef _ITEM_ATTSKILLMAGIC +#include "pet_skill.h" +#endif +#ifdef _NO_USE_MAGIC_MAP +#include "configfile.h" +#endif +//#include "battle_event.h" +// shan add code +#define MP_RATE 0.7 + + +int MAGIC_Use( int charaindex, int haveitemindex, int toindex) +{ + int itemindex; + int magicid,marray,mp; + int ret; + MAGIC_CALLFUNC func; + + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ) return FALSE; + magicid = ITEM_getInt( itemindex, ITEM_MAGICID); + marray = MAGIC_getMagicArray( magicid); + if( marray == -1 ) return FALSE; + + func = MAGIC_getMagicFuncPointer( MAGIC_getChar( marray, MAGIC_FUNCNAME));//MAGIC_NAME + + if( (mp = ITEM_getInt( itemindex, ITEM_MAGICUSEMP)) < 0 ){ + print("err mp:%d -%s-%d\n", mp, ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) ); + + } + + // shan add begin + if( CHAR_getInt( charaindex, CHAR_FMINDEX ) >= 1 ){ + // ⾫ + if( CHAR_getInt( charaindex, CHAR_FMSPRITE ) == 0){ + if( (marray >=0 && marray <=31) || (marray >= 105 && marray <=107 )) + mp *= MP_RATE; + } + // + if( CHAR_getInt( charaindex, CHAR_FMSPRITE ) == 1){ + if( marray >=32 && marray <=81 ) + mp *= MP_RATE; + } + } + // shan end + if( func ) { + ret = func( charaindex, toindex, marray, mp ); + }else { + ret = FALSE; + } + return ret; +} + +int MAGIC_GetArrayNo( int charaindex, int haveitemindex) +{ + int itemindex; + int magicid; + itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if( !ITEM_CHECKINDEX( itemindex) ) return FALSE; + + magicid = ITEM_getInt( itemindex, ITEM_MAGICID); + + return magicid; +} +int MAGIC_DirectUse( + int charaindex, + int magicid, + int toindex, + int itemnum +) +{ + MAGIC_CALLFUNC func; + int mp, ret, marray; + int itemindex=-1; +#ifdef _MAGIC_NOCAST//Ĭ״̬޷ʩ + if( CHAR_getWorkInt( charaindex, CHAR_WORKNOCAST ) > 0 ){ + CHAR_talkToCli(charaindex, -1, "Ĭ޷", CHAR_COLORYELLOW); + return FALSE; + } +#endif + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + itemindex = CHAR_getItemIndex( charaindex, itemnum); + if( !ITEM_CHECKINDEX( itemindex) ){ + print("ANDY err MAGIC_DirectUse() itemindex:%d !\n", itemindex); + return FALSE; + } + }else{ + itemindex = itemnum; + } + marray = MAGIC_getMagicArray( magicid ); + func = MAGIC_getMagicFuncPointer( MAGIC_getChar( marray, MAGIC_FUNCNAME ) ); +#ifdef _NO_USE_MAGIC_MAP + int index; +for(index=0;index<30;index++){ + if(CHAR_getInt(charaindex,CHAR_FLOOR)==getNoMagicMap(index)){ + if (strcmp(MAGIC_getChar( marray, MAGIC_FUNCNAME),"MAGIC_MagicDef")==0){ + char ansmsg[256]; + strcpysafe( ansmsg, sizeof(ansmsg), + "õͼֹʹù⾵ؾ顣"); + CHAR_talkToCli( charaindex, -1, ansmsg, CHAR_COLORWHITE ); + return FALSE; + } + } +} +#endif + + if( (mp = ITEM_getInt( itemindex, ITEM_MAGICUSEMP )) < 0 ){ + } + // shan add begin + if( CHAR_getInt( charaindex, CHAR_FMINDEX ) >= 1 ){ + // ⾫ + if( CHAR_getInt( charaindex, CHAR_FMSPRITE ) == 0){ + if( (marray >=0 && marray <=31) ) + mp *= MP_RATE; + } + // + if( CHAR_getInt( charaindex, CHAR_FMSPRITE ) == 1){ + if( marray >=32 && marray <=81 ) + mp *= MP_RATE; + } + } + if( func ) { + ret = func( charaindex, toindex, marray, mp ); + } + else { + ret = FALSE; + } + return ret; +} +#ifdef _MAGIC_FEATHERS +int MAGIC_Feathers( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + char buf[256]; + int ff=0, fx=0, fy=0, flg=0; + if( sscanf( MAGIC_getChar( marray, MAGIC_OPTION ), "%d %d %d %d", &flg, &ff, &fx, &fy) == 4 ){ + +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ){ + CHAR_talkToCli(charaindex, -1, "Я޷ʹá", CHAR_COLORYELLOW); + return; + } +#endif + sprintf( buf, "%d", flg); + MAGIC_setChar( marray, MAGIC_OPTION, buf); + MAGIC_setChar( marray, MAGIC_COMMENT, "δ¼ص"); + if( ITEM_WarpForAny(charaindex, ff, fx, fy, flg) == FALSE )return; + + }else if( sscanf( MAGIC_getChar( marray, MAGIC_OPTION ), "%d", &flg) == 1){ + + int Mf, Mx, My; + Mf = CHAR_getInt( charaindex, CHAR_FLOOR ); + Mx = CHAR_getInt( charaindex, CHAR_X ); + My = CHAR_getInt( charaindex, CHAR_Y ); + + char escapeshowstring[64]; + char *showstr = MAP_getfloorShowstring(Mf); + + getStringFromIndexWithDelim( showstr, "|", 1, escapeshowstring, sizeof( escapeshowstring)); + + + sprintf( buf, "%d %d %d %d", flg, Mf, Mx, My); + MAGIC_setChar( marray, MAGIC_OPTION, buf); + sprintf( buf, "¼λ(%s,%d,%d)", escapeshowstring, Mx, My); + MAGIC_setChar( marray, MAGIC_COMMENT, buf); + CHAR_talkToCli(charaindex, -1, buf, CHAR_COLORYELLOW); + } +} +#endif + +int MAGIC_Recovery( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + if( IsBATTLING( charaindex ) == TRUE ){ +#ifdef _PREVENT_TEAMATTACK //ݲ ʹõз + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + + if( BATTLE_CheckSameSide( charaindex, toindex) == 0 ){//ͬ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "ݾ..ʩҵз", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + if (toindex==22){print("jinchao err\n");return FALSE;} // shan(ȫʹħbug)޸jinchao+2001/12/07 + MAGIC_Recovery_Battle( charaindex, toindex, marray, mp ); + }else{ + if( CHAR_CHECKINDEX( toindex ) == FALSE )return FALSE; // shan(ȫʹħbug)޸jinchao+2001/12/07 + MAGIC_Recovery_Field( charaindex, marray); + } + + return TRUE; +} + +int MAGIC_OtherRecovery( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + if( IsBATTLING( charaindex ) == TRUE ){ +#ifdef _PREVENT_TEAMATTACK // ʹõз + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + if( BATTLE_CheckSameSide( charaindex, toindex) == 0 ){//ͬ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "..ʩҵз", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + MAGIC_Recovery_Battle( charaindex, toindex, marray, mp ); + }else{ + if( CHAR_CHECKINDEX( toindex ) == FALSE )return FALSE; // + MAGIC_OtherRecovery_Field( charaindex, toindex, marray); + } + return TRUE; +} + +// ūë ܷ +int MAGIC_FieldAttChange( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + // ܷ ɧ ƻ УѨ̹ϵئ³練 + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + // + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_FieldAttChange_Battle( charaindex, toindex, marray, mp ); + }else{ + // ƥئ + return FALSE; + } +} +int MAGIC_StatusChange( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, CHAR_getInt( charaindex, CHAR_MP ) - mp ); + if( IsBATTLING( charaindex ) == TRUE ){ +#ifdef _PREVENT_TEAMATTACK //쳣״̬ʹѷ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER && + BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P ){ + if( BATTLE_CheckSameSide( charaindex, toindex) == 1 ){//ͬ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "쳣״̬..ʩѷ", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + return MAGIC_StatusChange_Battle( charaindex, toindex, marray, mp ); + }else{ + return FALSE; + } +} + +#ifdef _OTHER_MAGICSTAUTS +int MAGIC_MagicStatusChange( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, CHAR_getInt( charaindex, CHAR_MP ) - mp ); + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_MagicStatusChange_Battle( charaindex, toindex, marray, mp ); + }else{ + return FALSE; + } +} +#endif + +#ifdef _MAGIC_DEEPPOISON//ver2,Ҫ趨״̬5δʱ +// ëܸ ܷ +int MAGIC_StatusChange2( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + //call func + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_StatusChange_Battle2( charaindex, toindex, marray, mp ); + }else{ + return FALSE; + } +} +#endif +// ټ ܷ +int MAGIC_StatusRecovery( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + // ܷ ɧ ƻ УѨ̹ϵئ³練 + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + // + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_StatusRecovery_Battle( charaindex, toindex, marray, mp ); + }else{ + // ƥئ + return FALSE; + } +} + +int MAGIC_MagicDef( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, CHAR_getInt( charaindex, CHAR_MP ) - mp ); + if( IsBATTLING( charaindex ) == TRUE ){ +#ifdef _PREVENT_TEAMATTACK //⾵..ʹõз + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER + /*&& BattleArray[battleindex].type != BATTLE_TYPE_P_vs_P*/ ){ + if( BATTLE_CheckSameSide( charaindex, toindex) == 0 ){//ͬ + int battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + BATTLE_NoAction( battleindex, BATTLE_Index2No( battleindex, charaindex) ); + CHAR_talkToCli( charaindex, -1, "⾵..ʩз", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + return MAGIC_MagicDef_Battle( charaindex, toindex, marray, mp ); + }else{ + return FALSE; + } +} + + +// 姾ٽ ܷ +int MAGIC_Ressurect( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + // ܷ ɧ ƻ УѨ̹ϵئ³練 + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + // + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_Ressurect_Battle( charaindex, toindex, marray, mp ); + }else{ + // ƥئ + return FALSE; + } +} + +// ë ܷ +int MAGIC_AttReverse( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + // ܷ ɧ ƻ УѨ̹ϵئ³練 + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + // + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_AttReverse_Battle( charaindex, toindex, marray, mp ); + }else{ + // ƥئ + return FALSE; + } +} + + + +// 姾١ ܷ +int MAGIC_ResAndDef( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode; + + // INDEX + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; // + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + // + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; // ĸ + // ܷ ɧ ƻ УѨ̹ϵئ³練 + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + // + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_ResAndDef_Battle( charaindex, toindex, marray, mp ); + }else{ + // ƥئ + return FALSE; + } +} + + + +#ifdef _ATTACK_MAGIC + +int MAGIC_AttMagic( int charaindex , int toindex , int marray , int mp ) +{ + int battlemode; + + if( FALSE == CHAR_CHECKINDEX( charaindex ) ) + return FALSE; + + battlemode = CHAR_getWorkInt( charaindex , CHAR_WORKBATTLEMODE ); + if( BATTLE_CHARMODE_INIT == battlemode ) + return FALSE; + // dzħ,mp + if(CHAR_getInt(charaindex,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) + { + if( CHAR_getInt( charaindex , CHAR_MP ) < mp ) + return FALSE; + + CHAR_setInt( charaindex , CHAR_MP , CHAR_getInt( charaindex , CHAR_MP ) - mp ); + } + + if( TRUE == IsBATTLING( charaindex ) ) + return MAGIC_AttMagic_Battle( charaindex , toindex , marray , mp ); + + return FALSE; + +} + +#endif + +#ifdef _ITEM_METAMO +int MAGIC_Metamo( int charaindex, int toindex, int marray, int mp ) +{ + int battlemode, haveindex, power, i; + char msg[128]; + + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + // ݷ + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + // + if( IsBATTLING( charaindex ) == TRUE ){ + //MAGIC_Recovery_Battle( charaindex, toindex, marray, mp ); + //return FALSE; + toindex = BATTLE_No2Index( + CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ), toindex ); + //print(" battle_metamo:%d ", toindex); + } + + if( CHAR_CHECKINDEX( toindex ) == FALSE ) return FALSE; + + if( CHAR_getInt( charaindex, CHAR_RIDEPET ) != -1 ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORWHITE ); + return FALSE; + } +#ifdef _FIX_METAMORIDE + if( CHAR_CHECKJOINENEMY( charaindex) == TRUE ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return FALSE; + } +#else + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER) == 100259 ){ + CHAR_talkToCli( charaindex, -1, "޷вܱ", CHAR_COLORWHITE ); + return FALSE; + } +#endif +#ifdef _FIXBUG_ATTACKBOW + { + int armindex = CHAR_getItemIndex( charaindex, CHAR_ARM); + if( ITEM_CHECKINDEX( armindex) == TRUE ) { + int armtype = BATTLE_GetWepon( charaindex); + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( charaindex, -1, "ʹԶ޷", CHAR_COLORYELLOW ); + return FALSE; + } + } + } +#endif + haveindex = -1; + for( i = 0; i < 5; i++ ) + { + if( CHAR_getCharPet( charaindex, i) == toindex ) { + haveindex = i; + break; + } + } + if( haveindex == -1 && charaindex != toindex ) + { + CHAR_talkToCli( charaindex, -1, "޷ֻܱԼij", CHAR_COLORWHITE ); + return FALSE; + } + + if( CHAR_getInt( toindex, CHAR_BASEIMAGENUMBER) == 100259 ){ + CHAR_talkToCli( charaindex, -1, "ܱɼ", CHAR_COLORWHITE ); + return FALSE; + } + + power = atoi(MAGIC_getChar( marray, MAGIC_OPTION )); + + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_MP); + + if( toindex != charaindex ) { + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, NowTime.tv_sec +power); + sprintf( msg, "%s", CHAR_getChar( toindex, CHAR_NAME) ); + } + else { + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, 0); + sprintf( msg, "Լ"); + } + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORWHITE ); + + CHAR_setInt( charaindex, CHAR_BASEIMAGENUMBER, + CHAR_getInt( toindex, CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( charaindex); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); +//#endif + + return TRUE; +} +#endif + +#ifdef _ITEM_ATTSKILLMAGIC +int MAGIC_AttSkill( int charaindex, int toindex,int marray, int mp ) +{ + int battlemode; + int battleindex=-1; + char *magicarg, funName[256]; + int skillID=-1; + PETSKILL_CALLFUNC func; + if( CHAR_CHECKINDEX( charaindex ) == FALSE ) return FALSE; + if( IsBATTLING( charaindex ) == FALSE ) return FALSE; + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + if( battlemode == BATTLE_CHARMODE_INIT ) return FALSE; + if( toindex < 0 || toindex > 19 ) return FALSE; + if( CHAR_getInt( charaindex, CHAR_MP ) < mp ) { + if(MAGIC_getInt( marray, MAGIC_TARGET )!=8){ + return FALSE; + } + } + + memset( funName, 0, sizeof( char)*256 ); + //MAGIC_Recovery_Battle( charaindex, toindex, marray, mp ); + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + + if ( magicarg == "\0") return FALSE; + if( strstr( magicarg, ";" ) != NULL ) { + char buff1[256]; + if( getStringFromIndexWithDelim( magicarg, ";", 1, buff1, sizeof( buff1)) == FALSE ) + return FALSE; + snprintf( funName, sizeof(funName), buff1); + if( getStringFromIndexWithDelim( magicarg, ";", 2, buff1, sizeof( buff1)) == FALSE ) + return FALSE; + skillID = atoi( buff1); + }else + return FALSE; + func = PETSKILL_getPetskillFuncPointer( funName); + if( !func ){ + print("\n *func not FOUND !!"); + return FALSE; + } + if( func( charaindex, toindex, skillID, "MAGICSKILL" ) == FALSE ) return FALSE; + CHAR_setInt( charaindex, CHAR_MP, CHAR_getInt( charaindex, CHAR_MP ) - mp ); + return TRUE; + +} +#endif +#ifdef _MAGIC_BARRIER// vincent :ħ +int MAGIC_Barrier( int charaindex, int toindex, int marray, int mp ) +{ + + int battlemode; + int i,turn,perStatus; + int ToList[SIDE_OFFSET*2+1]; + char *magicarg; + int attackNo=0; + int battleindex,Success = 0; + char szTurn[] = "turn"; + char szSuccess[] = ""; + char *pszP; + + //check index + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ //?? + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + //mp + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + //mp + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + //ħ + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + + //ȡûغ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + // ɬ// + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } + + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + BATTLE_MultiList( battleindex, toindex, ToList ); +//ʩħЧ + BATTLE_MagicEffect(battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi); + + charaindex = BATTLE_No2Index( battleindex, attackNo ); + //checkǷս + if( IsBATTLING( charaindex ) == TRUE ) + { + + for( i = 0; ToList[i] != -1; i ++ ) + { + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BATTLE_StatusAttackCheck( charaindex,toindex, BATTLE_ST_BARRIER, Success, 30, 1.0, &perStatus ) == TRUE ) + { + CHAR_setWorkInt( toindex, CHAR_WORKBARRIER, turn+1 ); +// BATTLE_BadStatusString( ToList[i], BATTLE_ST_BARRIER ); + } + } + return TRUE; + }else{ + return FALSE; + } +} +#endif +#ifdef _MAGIC_NOCAST// vincent :Ĭ +int MAGIC_Nocast( int charaindex, int toindex, int marray, int mp ) +{ + + int battlemode; + int i,turn,perStatus; + int ToList[SIDE_OFFSET*2+1]; + char *magicarg; + int attackNo=0; + int battleindex,Success = 0; + char szTurn[] = "turn"; + char szSuccess[] = ""; + char *pszP; + + //check index + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ //?? + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + //mp + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + //mp + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + //ħ + magicarg = MAGIC_getChar( marray, MAGIC_OPTION ); + if( magicarg == "\0" ) { + print("\n magicarg == NULL "); + return FALSE; + } + pszP = magicarg; + + //ȡûغ + if( ( pszP = strstr( pszP, szTurn ) ) != NULL){ + pszP += sizeof( szTurn ); + sscanf( pszP, "%d", &turn ); + } + // ɬ// + if( ( pszP = strstr( pszP, szSuccess ) ) != NULL){ + pszP += sizeof( szSuccess ); + sscanf( pszP, "%d", &Success ); + } +// print("\nvincent-->MAGIC_Nocast use"); + battleindex = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX ); + attackNo = BATTLE_Index2No( battleindex, charaindex ); + BATTLE_MultiList( battleindex, toindex, ToList ); +//ʩħЧ + BATTLE_MagicEffect(battleindex, attackNo, ToList, MAGIC_EFFECT_USER, SPR_hoshi); + charaindex = BATTLE_No2Index( battleindex, attackNo ); + //checkǷս + if( IsBATTLING( charaindex ) == TRUE ) + { + + for( i = 0; ToList[i] != -1; i ++ ) + { + toindex = BATTLE_No2Index( battleindex, ToList[i] ); + if( BATTLE_StatusAttackCheck( charaindex,toindex, BATTLE_ST_NOCAST, Success, 30, 1.0, &perStatus ) == TRUE + && CHAR_getInt( toindex, CHAR_WHICHTYPE) != CHAR_TYPEPET) + { + CHAR_setWorkInt( toindex, CHAR_WORKNOCAST, turn ); +//޷չҳ + lssproto_NC_send( getfdFromCharaIndex( toindex ), 1); + //print("\nvincent-->NOCASTING2"); +// BATTLE_BadStatusString( ToList[i], BATTLE_ST_NOCAST ); + } + } + return TRUE; + }else{ + return FALSE; + } +} +#endif + +#ifdef _MAGIC_WEAKEN// vincent : +int MAGIC_Weaken( int charaindex, int toindex, int marray, int mp ) +{ + + int battlemode; + //check index + if( CHAR_CHECKINDEX( charaindex ) == FALSE )return FALSE; + + battlemode = CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ); + + // ݷ //?? + if( battlemode == BATTLE_CHARMODE_INIT ){ + return FALSE; + } + + //mp + if( CHAR_getInt( charaindex, CHAR_MP ) < mp )return FALSE; + //mp + CHAR_setInt( charaindex, CHAR_MP, + CHAR_getInt( charaindex, CHAR_MP ) - mp ); + + //checkǷս + if( IsBATTLING( charaindex ) == TRUE ){ + return MAGIC_ParamChange_Turn_Battle( charaindex, toindex, marray, mp ); + }else{ + return FALSE; + } +} +#endif + +#ifdef _MAGIC_TOCALL +int MAGIC_ToCallDragon( int charaindex, int toindex,int marray, int mp ) +{ + int battlemode; + + //print("MAGIC_ToCallDragon in .................\n"); + if( FALSE == CHAR_CHECKINDEX( charaindex ) ) + return FALSE; + + battlemode = CHAR_getWorkInt( charaindex , CHAR_WORKBATTLEMODE ); + if( BATTLE_CHARMODE_INIT == battlemode ) + return FALSE; + if( CHAR_getInt( charaindex , CHAR_MP ) < mp ) + return FALSE; + + CHAR_setInt( charaindex , CHAR_MP , CHAR_getInt( charaindex , CHAR_MP ) - mp ); + + if( TRUE == IsBATTLING( charaindex ) ) + return MAGIC_ToCallDragon_Battle( charaindex , toindex , marray , mp ); + + return FALSE; +} +#endif + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_base.c b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_base.c new file mode 100644 index 0000000..ae4dbdb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_base.c @@ -0,0 +1,532 @@ +#include "version.h" +#include +#include + +#include "common.h" +#include "buf.h" +#include "configfile.h" +#include "magic_base.h" +#include "magic.h" +#include "autil.h" +static Magic *MAGIC_magic; +static int MAGIC_magicnum; + + + +#ifdef _ATTACK_MAGIC + +AttMagic *ATTMAGIC_magic; +int ATTMAGIC_magicnum; + +#endif + + + +typedef struct tagMagic_MagicFunctionTable +{ + char *functionname; /* ɬð̻̤Ѽ */ + MAGIC_CALLFUNC func; /* ˱̫ľ */ + int hash; /* hash */ +}MAGIC_MagicFunctionTable; + +/* ë ֧ճ */ +static MAGIC_MagicFunctionTable MAGIC_functbl[] = { +#ifdef _MAGIC_FEATHERS + { "MAGIC_Feathers", MAGIC_Feathers, 0}, +#endif + { "MAGIC_Recovery", MAGIC_Recovery, 0}, + { "MAGIC_OtherRecovery", MAGIC_OtherRecovery, 0}, + { "MAGIC_FieldAttChange", MAGIC_FieldAttChange, 0}, + { "MAGIC_StatusChange", MAGIC_StatusChange, 0}, + { "MAGIC_MagicDef", MAGIC_MagicDef, 0}, + { "MAGIC_StatusRecovery", MAGIC_StatusRecovery, 0}, + { "MAGIC_Ressurect", MAGIC_Ressurect, 0}, + { "MAGIC_AttReverse", MAGIC_AttReverse, 0}, + { "MAGIC_ResAndDef", MAGIC_ResAndDef, 0}, + +#ifdef _ATTACK_MAGIC + { "MAGIC_AttMagic" , MAGIC_AttMagic , 0 }, +#endif +#ifdef _OTHER_MAGICSTAUTS + { "MAGIC_MagicStatusChange", MAGIC_MagicStatusChange, 0}, +#endif +#ifdef _ITEM_METAMO + { "MAGIC_Metamo", MAGIC_Metamo, 0}, +#endif +#ifdef _ITEM_ATTSKILLMAGIC + { "MAGIC_AttSkill", MAGIC_AttSkill, 0}, +#endif +#ifdef _MAGIC_WEAKEN // vincent : + { "MAGIC_Weaken", MAGIC_Weaken, 0}, +#endif +#ifdef _MAGIC_DEEPPOISON // vincent :綾 + { "MAGIC_StatusChange2", MAGIC_StatusChange2,0}, +#endif +#ifdef _MAGIC_BARRIER // vincent :ħ + { "MAGIC_Barrier", MAGIC_Barrier, 0}, +#endif +#ifdef _MAGIC_NOCAST // vincent :Ĭ + { "MAGIC_Nocast", MAGIC_Nocast, 0}, +#endif +#ifdef _MAGIC_TOCALL // + { "MAGIC_ToCallDragon", MAGIC_ToCallDragon, 0}, +#endif +}; + +/*----------------------------------------------------------------------*/ + + +/* ͣʧͱ */ +/*----------------------------------------------------------------------*/ +INLINE BOOL MAGIC_CHECKINDEX( int index ) +{ + if( MAGIC_magicnum<=index || index<0 )return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +static INLINE BOOL MAGIC_CHECKINTDATAINDEX( int index) +{ + if( MAGIC_DATAINTNUM <= index || index < 0 ) return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +static INLINE BOOL MAGIC_CHECKCHARDATAINDEX( int index) +{ + if( MAGIC_DATACHARNUM <= index || index < 0 ) return FALSE; + return TRUE; +} +/*----------------------------------------------------------------------*/ +INLINE int MAGIC_getInt( int index, MAGIC_DATAINT element) +{ + return MAGIC_magic[index].data[element]; +} +/*----------------------------------------------------------------------*/ +INLINE int MAGIC_setInt( int index, MAGIC_DATAINT element, int data) +{ + int buf; + buf = MAGIC_magic[index].data[element]; + MAGIC_magic[index].data[element]=data; + return buf; +} +/*----------------------------------------------------------------------*/ +INLINE char* MAGIC_getChar( int index, MAGIC_DATACHAR element) +{ + if( !MAGIC_CHECKINDEX( index)) return "\0"; + if( !MAGIC_CHECKCHARDATAINDEX( element)) return "\0"; + return MAGIC_magic[index].string[element].string; +} + +/*----------------------------------------------------------------------*/ +INLINE BOOL MAGIC_setChar( int index ,MAGIC_DATACHAR element, char* new ) +{ + if(!MAGIC_CHECKINDEX(index))return FALSE; + if(!MAGIC_CHECKCHARDATAINDEX(element))return FALSE; + strcpysafe( MAGIC_magic[index].string[element].string, + sizeof(MAGIC_magic[index].string[element].string), + new ); + return TRUE; +} +/*---------------------------------------------------------------------- + * ܷë£ + *---------------------------------------------------------------------*/ +int MAGIC_getMagicNum( void) +{ + return MAGIC_magicnum; +} + +/*---------------------------------------------------------------------- + * ܷɬð̻ë + *---------------------------------------------------------------------*/ +BOOL MAGIC_initMagic( char *filename) +{ + FILE* f; + char line[256]; + int linenum=0; + int magic_readlen=0; + int i,j; + + int max_magicid =0; + char token[256]; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + f = fopen( realopfile, "r"); + if( f != NULL ){ + crypto = TRUE; + }else +#endif +{ + f = fopen(filename,"r"); +} + if( f == NULL ){ + print( "ļʧ\n"); + return FALSE; + } + + MAGIC_magicnum=0; + + /* ئ滥ϵؤ¾Ʃ */ + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + +#ifdef _MAGIC_OPTIMUM // Robin ȡMAGIC ID + if( getStringFromIndexWithDelim( line, ",", MAGIC_DATACHARNUM+MAGIC_ID+1, + token, sizeof(token)) == FALSE ) + continue; + max_magicid = max( atoi( token), max_magicid); +#endif + + MAGIC_magicnum++; + } + +#ifdef _MAGIC_OPTIMUM + print("Чħ:%d ħ:%d ...", MAGIC_magicnum, max_magicid); + MAGIC_magicnum = max_magicid +1; +#endif + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "\n" ); + fclose(f); + return FALSE; + } + + MAGIC_magic = allocateMemory( sizeof(struct tagMagic) + * MAGIC_magicnum ); + if( MAGIC_magic == NULL ){ + fprint( "޷ڴ %d\n" , + sizeof(struct tagMagic)*MAGIC_magicnum); + fclose( f ); + return FALSE; + } + + /* */ + for( i = 0; i < MAGIC_magicnum; i ++ ) { + for( j = 0; j < MAGIC_DATAINTNUM; j ++ ) { + MAGIC_setInt( i,j,-1); + } + for( j = 0; j < MAGIC_DATACHARNUM; j ++ ) { + MAGIC_setChar( i,j,""); + } + } + + /* */ + linenum = 0; + while( fgets( line, sizeof( line ), f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ +{ + char buf[256]; + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } +} +{ + char token[256]; + int ret; + +#ifdef _MAGIC_OPTIMUM + if( getStringFromIndexWithDelim( line, ",", MAGIC_DATACHARNUM+MAGIC_ID+1, + token, sizeof(token)) == FALSE ) + continue; + magic_readlen = atoi( token); +#endif + + for( i = 0; i < MAGIC_DATACHARNUM; i ++ ) { + + /* ٯ ͼëέ */ + ret = getStringFromIndexWithDelim( line,",", + i + 1, + token,sizeof(token)); + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + MAGIC_setChar( magic_readlen, i, token); + } + /* 4 ϷѰ */ +#define MAGIC_STARTINTNUM 5 + for( i = MAGIC_STARTINTNUM; i < MAGIC_DATAINTNUM+MAGIC_STARTINTNUM; i ++ ) { + ret = getStringFromIndexWithDelim( line,",",i,token, + sizeof(token)); + +#ifdef _ATTACK_MAGIC + + if( FALSE == ret ) + + break; + + if( 0 != strlen( token ) ) + { + MAGIC_setInt( magic_readlen , i - MAGIC_STARTINTNUM , atoi( token ) ); + } + +#else + + if( ret==FALSE ){ + fprint("ļ﷨:%s %d\n",filename,linenum); + break; + } + if( strlen( token) != 0 ) { + MAGIC_setInt( magic_readlen, i - MAGIC_STARTINTNUM, atoi( token)); + } + + #endif + } + +#ifdef _ATTACK_MAGIC + + if( i != MAGIC_STARTINTNUM + MAGIC_IDX && i != MAGIC_DATAINTNUM + MAGIC_STARTINTNUM ) + continue; + +#else + + if( i < MAGIC_DATAINTNUM+MAGIC_STARTINTNUM ) + continue; + +#endif + /* нسƶ£ */ + if( MAGIC_getInt( magic_readlen, MAGIC_TARGET_DEADFLG) == 1 ) { + MAGIC_setInt( magic_readlen, MAGIC_TARGET, + MAGIC_getInt( magic_readlen, MAGIC_TARGET)+100); + } + + magic_readlen ++; +} + } + fclose(f); + + MAGIC_magicnum = magic_readlen; + + + print( "Чħ %d...", MAGIC_magicnum ); + + /* hash */ + for( i = 0; i < arraysizeof( MAGIC_functbl); i ++ ) { + MAGIC_functbl[i].hash = hashpjw( MAGIC_functbl[i].functionname); + } + return TRUE; +} +/*------------------------------------------------------------------------ + * Magicɬð̻ + *-----------------------------------------------------------------------*/ +BOOL MAGIC_reinitMagic( void ) +{ + freeMemory( MAGIC_magic); + return( MAGIC_initMagic( getMagicfile())); +} + + +#ifdef _ATTACK_MAGIC + +/*------------------------------------------------------------------------ + * AttMagicijʼ + *-----------------------------------------------------------------------*/ +BOOL ATTMAGIC_initMagic( char *filename ) +{ + FILE *file; + + // Open file + if( NULL == ( file = fopen( filename , "r" ) ) ) + { + ATTMAGIC_magicnum = 0; + ATTMAGIC_magic = NULL; + + return TRUE; + } + + fseek( file , 0 , SEEK_END ); + + // Calculate the number of attack magics + ATTMAGIC_magicnum = ftell( file ) / sizeof( struct tagAttMagic ); + if( ATTMAGIC_magicnum % 2 ) + { + fprint( "ļʧ\n" ); + fclose( file ); + + return FALSE; + } + + fseek( file , 0 , SEEK_SET ); + + // Allocate memory to attack magics + ATTMAGIC_magic = allocateMemory( sizeof( struct tagAttMagic ) * ATTMAGIC_magicnum ); + if( NULL == ATTMAGIC_magic ) + { + fprint( "޷ڴ %d\n" , sizeof( struct tagAttMagic ) * ATTMAGIC_magicnum ); + fclose( file ); + + return FALSE; + } + + // Read attack magics information + memset( ATTMAGIC_magic , 0 , sizeof( struct tagAttMagic ) * ATTMAGIC_magicnum ); + fread( ATTMAGIC_magic , 1 , sizeof( struct tagAttMagic ) * ATTMAGIC_magicnum , file ); + + fclose( file ); + + ATTMAGIC_magicnum = ATTMAGIC_magicnum / 2; + + print( "ЧĹħ %d\n" , ATTMAGIC_magicnum ); + + return TRUE; +} + + + +/*------------------------------------------------------------------------ + * AttMagicٶȳʼ + *-----------------------------------------------------------------------*/ +BOOL ATTMAGIC_reinitMagic( void ) +{ + freeMemory( ATTMAGIC_magic ); + ATTMAGIC_magicnum = 0; + + return ATTMAGIC_initMagic( getAttMagicfileName() ); +// return ATTMAGIC_initMagic( getMagicfile() ); +} + +#endif + +/*------------------------------------------------------------------------ + * MAGIC_IDսٯë + * ߯Ի + * : ٯ + * : -1 + *-----------------------------------------------------------------------*/ +int MAGIC_getMagicArray( int magicid) +{ +#ifdef _MAGIC_OPTIMUM + if( magicid >= 0 && magicid < MAGIC_magicnum) + return magicid; +#else + int i; + for( i = 0; i < MAGIC_magicnum; i ++ ) { + if( MAGIC_magic[i].data[MAGIC_ID] == magicid ) { + return i; + } + } +#endif + return -1; +} +/*------------------------------------------------------------ + *  պ̼ë߯ + * ¦ + * name char*  + * ߯Ի + * ѳ߼̼ئ巴NULL + ------------------------------------------------------------*/ +MAGIC_CALLFUNC MAGIC_getMagicFuncPointer(char* name) +{ + int i; + int hash; //ttom + //ttom 12/18/2000 + if(name==NULL) return NULL; + //ttom + //int hash = hashpjw( name ); + hash=hashpjw(name); + for( i = 0 ; i< arraysizeof( MAGIC_functbl) ; i++ ) { + if( MAGIC_functbl[i].hash == hash ) { + if( strcmp( MAGIC_functbl[i].functionname, name ) == 0 ) { + return MAGIC_functbl[i].func; + } + } + } + return NULL; +} + + +// Nuke start (08/23) +/* + Nuke ϼͣ + ܷ ë£ + + Check the validity of the target of a magic. + Return value: + 0: Valid + -1: Invalid +*/ +int MAGIC_isTargetValid( int magicid, int toindex) +{ + int marray; + marray= MAGIC_getMagicArray( magicid); + + #ifdef _ATTACK_MAGIC + + if( toindex >= 0 && toindex <= 19 ) + return 0; + + // One side of players + if( 20 == toindex || 21 == toindex ) + { + if( MAGIC_TARGET_WHOLEOTHERSIDE == MAGIC_magic[marray].data[MAGIC_TARGET] || MAGIC_TARGET_ALL_ROWS == MAGIC_magic[marray].data[MAGIC_TARGET] ) + return 0; + else + return -1; + } + + // All players + if( 22 == toindex ) + { + if( MAGIC_TARGET_ALL == MAGIC_magic[marray].data[MAGIC_TARGET] ) + return 0; + else + return -1; + } + + // One row + if( 23 == toindex || 24 == toindex || 25 == toindex || 26 == toindex ) + { + if( MAGIC_TARGET_ONE_ROW == MAGIC_magic[marray].data[MAGIC_TARGET] ) + return 0; + else + return -1; + } + + #else + + // Single player + if ((toindex >= 0x0) && (toindex <= 0x13)) return 0; + // All players + if (toindex == 0x16) { + if (MAGIC_magic[marray].data[MAGIC_TARGET] == MAGIC_TARGET_ALL) + return 0; else return -1; + } + // One side of players + if ((toindex == 0x14) || (toindex == 0x15)) { + if (MAGIC_magic[marray].data[MAGIC_TARGET] == MAGIC_TARGET_WHOLEOTHERSIDE) + return 0; else return -1; + } + + #endif + + // Others: Error + return -1; +} +// Nuke end diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_field.c b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_field.c new file mode 100644 index 0000000..f2356fa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/magic_field.c @@ -0,0 +1,149 @@ +#include "version.h" +#include + +#include "common.h" +#include "char_base.h" +#include "char.h" +#include "magic_base.h" +#include "magic.h" +#include "magic_field.h" + +/* + * ƥ ܷ + */ +/*---------------------------------------------------------------------- + * мļ + * ¦ + * charaindex int мindex + * magicindex int ܷindex + *---------------------------------------------------------------------*/ +int MAGIC_Recovery_Field( int charaindex, int magicindex) +{ + char *magicarg; + float power; + int workhp; + int prevhp; + char msgbuf[64]; + +#ifdef _TYPE_TOXICATION + if( CHAR_CanCureFlg( charaindex, "HP") == FALSE ) return TRUE; +#endif + magicarg = MAGIC_getChar( magicindex, MAGIC_OPTION ); + power = atoi( magicarg ); + power = RAND( (power*0.9), (power*1.1) ); +#ifndef _MAGIC_REHPAI + power *= GetRecoveryRate( charaindex ); +#endif + prevhp = CHAR_getInt( charaindex, CHAR_HP ); + workhp = prevhp + (int)power; + CHAR_setInt( charaindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP ) ) ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_HP|CHAR_P_STRING_MP); + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) { + int mypartyarray = -1; + int oyaindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex )) { + int i; + for( i = 0; i < getPartyNum(oyaindex ); i ++ ) { + int workindex = CHAR_getWorkInt( oyaindex, CHAR_WORKPARTYINDEX1 +i); + if( CHAR_CHECKINDEX( workindex) ) { + if( workindex == charaindex ) { + mypartyarray = i; + break; + } + } + } + if( mypartyarray != -1 ) { + for( i = 0; i < getPartyNum(charaindex ); i ++ ) { + int index = CHAR_getPartyIndex( charaindex, i); + if( CHAR_CHECKINDEX( index) ) { + if( index != charaindex) { + CHAR_send_N_StatusString( index, mypartyarray, + CHAR_N_STRING_HP|CHAR_N_STRING_MP); + } + } + } + } + } + } + snprintf( msgbuf, sizeof( msgbuf), ";ظ%d", + min( workhp, CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP)) - prevhp); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + return TRUE; + +} +/*---------------------------------------------------------------------- + * ְë + * ¦ + * charaindex int мindex + * toindex int мindex + * magicindex int ܷindex + *---------------------------------------------------------------------*/ +int MAGIC_OtherRecovery_Field( int charaindex, int toindex, int magicindex) +{ + char *magicarg; + float power; + int workhp; + int prevhp; + char msgbuf[64]; + +#ifdef _TYPE_TOXICATION + if( CHAR_CanCureFlg( charaindex, "HP") == FALSE )return FALSE; +#endif + magicarg = MAGIC_getChar( magicindex, MAGIC_OPTION ); + power = atoi( magicarg ); + power = RAND( (power*0.9), (power*1.1) ); +#ifndef _MAGIC_REHPAI + power *= GetRecoveryRate( toindex ); +#endif + prevhp = CHAR_getInt( toindex, CHAR_HP ); + workhp = prevhp + (int)power; + CHAR_setInt( toindex, CHAR_HP, + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP ) ) ); + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + if( charaindex != toindex ) { + CHAR_send_P_StatusString( toindex, CHAR_P_STRING_HP); + } + } + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_HP|CHAR_P_STRING_MP); + if( charaindex != toindex) { + CHAR_PartyUpdate( charaindex, CHAR_N_STRING_MP); + CHAR_PartyUpdate( toindex, CHAR_N_STRING_HP); + } + else { + CHAR_PartyUpdate( charaindex, CHAR_N_STRING_MP|CHAR_N_STRING_HP); + } + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPET ){ + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int workindex = CHAR_getCharPet( charaindex, i ); + if( workindex == toindex ){ + CHAR_send_K_StatusString( charaindex, i, CHAR_K_STRING_HP); + } + } + } + + if( charaindex != toindex) { + snprintf( msgbuf, sizeof( msgbuf), "%s;ظ%d", + CHAR_getUseName( toindex ), + min( workhp, CHAR_getWorkInt( toindex, CHAR_WORKMAXHP)) - prevhp); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + + if( CHAR_getInt( toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + snprintf( msgbuf, sizeof( msgbuf), "%s;ظ%d", + CHAR_getUseName( charaindex ), + min( workhp,CHAR_getWorkInt( toindex, CHAR_WORKMAXHP)) - prevhp); + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORWHITE); + } + } + else { + snprintf( msgbuf, sizeof( msgbuf), ";ظ%d", + min( workhp,CHAR_getWorkInt( charaindex, CHAR_WORKMAXHP)) - prevhp); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORWHITE); + + } + + return TRUE; + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/make.exe.stackdump b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/make.exe.stackdump new file mode 100644 index 0000000..bd4a174 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/make.exe.stackdump @@ -0,0 +1,4 @@ +Exception: STATUS_ACCESS_VIOLATION at eip=7C915F9C +eax=7C915F9C ebx=007CCDF0 ecx=611034B0 edx=FFFFFFFF esi=00000000 edi=007CCE64 +ebp=003D0000 esp=007CCDB4 program=J:\cygwin\bin\make.exe, pid 4224, thread unknown (0x1090) +cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023 diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile new file mode 100755 index 0000000..a1e8f5b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile @@ -0,0 +1,186 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmagic.a + +SRC=magic.c magic_base.c magic_field.c +OBJ=$(SRC:.c=.o) + + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +magic.o: magic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/battle.h ../include/trade.h ../include/magic_base.h \ + ../include/magic.h ../include/magic_field.h ../include/family.h \ + ../include/handletime.h ../include/battle_magic.h \ + ../include/battle_event.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h +magic_base.o: magic_base.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/buf.h ../include/configfile.h ../include/magic_base.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/magic.h ../include/autil.h ../include/version.h +magic_field.o: magic_field.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/magic_base.h \ + ../include/magic.h ../include/magic_field.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile.bak new file mode 100755 index 0000000..a1e8f5b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/makefile.bak @@ -0,0 +1,186 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmagic.a + +SRC=magic.c magic_base.c magic_field.c +OBJ=$(SRC:.c=.o) + + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +magic.o: magic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/battle.h ../include/trade.h ../include/magic_base.h \ + ../include/magic.h ../include/magic_field.h ../include/family.h \ + ../include/handletime.h ../include/battle_magic.h \ + ../include/battle_event.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h +magic_base.o: magic_base.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/buf.h ../include/configfile.h ../include/magic_base.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/magic.h ../include/autil.h ../include/version.h +magic_field.o: magic_field.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/magic_base.h \ + ../include/magic.h ../include/magic_field.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/magic/rm.exe.stackdump b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/rm.exe.stackdump new file mode 100644 index 0000000..f556039 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/magic/rm.exe.stackdump @@ -0,0 +1 @@ +Exception: STATUS_ACCESS_VIOLATION at eip=7C915F9C diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/main.c b/石器时代服务器端最新完整源代码/Serv/gmsv/main.c new file mode 100644 index 0000000..c9bb30f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/main.c @@ -0,0 +1,413 @@ +#include "version.h" +#include +#include +#include +#include +#include +#include +#include +#include "init.h" +#include "net.h" +#ifdef _EPOLL_ET_MODE +#include "epollnet.h" +#endif +#include "handletime.h" +#include "char.h" +#include "map_warppoint.h" +#include "npcgen.h" +#include "log.h" +#include "configfile.h" +#include "battle.h" +#include "petmail.h" +#include "autil.h" +#include "family.h" +#include "trade.h" +#include "longzoro/attestation.h" +#include "longzoro/sasql.h" +#ifdef _ALLBLUES_LUA +#include "mylua/ablua.h" +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ +#include "chatroom.h" +#endif +#include "shop.h" +jmp_buf mark; + + + +static void ShutdownProc( void); +void mainloop( void ); +struct tm tmNow, tmOld; +void family_proc(); + +#ifdef _CHANNEL_MODIFY +extern int InitOccChannel(void); +#endif + +#ifdef _GMSV_DEBUG +extern char *DebugMainFunction; +#endif + +#ifdef _ANGEL_SUMMON +#define ANGELTIMELIMIT 3*24*60*60 // ʱ() +int AngelReady =0; +int AngelTimelimit = ANGELTIMELIMIT; +time_t AngelNextTime; +void AngelReadyProc(); +#endif + +//#include "genver.h" + +void warplog_proc(); + + +int main( int argc , char** argv, char** env ) +{ + + /* Իؤëɬƻ */ + setNewTime(); + ShopData_Init(); +/* if ( argc > 1 && 0==strcmp(argv[1],"-v")) + { + printf("%s",genver); + exit(0); + } + else fprintf(stderr,"%s",genver);*/ + + EXITWITHEXITCODEIFFALSE( util_Init() , 1); + + LoadAnnounce(); // Arminius 7.12 loginannounce + + /* ɬ */ + memcpy( &tmOld, localtime( (time_t *)&NowTime.tv_sec), sizeof( tmNow ) ); + + EXITWITHEXITCODEIFFALSE( init(argc , argv ,env ) , 1); + + LoadPetTalk(); // Arminius 8.14 pet talk + +#ifdef _GAMBLE_BANK + Load_GambleBankItems(); +#endif + +#ifdef _CFREE_petskill + Load_PetSkillCodes(); +#endif + +#ifdef _ITEM_PILEFORTRADE + TRADE_InitTradeList(); +#endif + +#ifdef _SASQL + if(sasql_init()==FALSE){ + exit(1); + } +#endif + + mainloop(); + + return 0; +} + +void mainloop( void ) +{ + print("ʼNPC..."); + NPC_generateLoop( 1 ); + print("\n"); + print("ʼsignal1..."); + signal(SIGUSR1,sigusr1); + print("\n"); + print("ʼsignal2..."); + signal(SIGUSR2,sigusr2); + print("\n"); + +#ifdef _MAP_WARPPOINT + print("ʼͼ͵..."); + MAPPOINT_InitMapWarpPoint(); + print("\n"); + if( !MAPPOINT_loadMapWarpPoint() ){ + return; + } +#endif + +#ifdef _ASSESS_SYSEFFICACY + Assess_InitSysEfficacy(); +#endif +#ifdef _CHATROOMPROTOCOL // (ɿ) Syu ADD Ƶ + print("ʼƵ..."); + InitChatRoom(); + print("\n"); +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ +#ifdef _CHANNEL_MODIFY + print("ʼְҵƵ..."); + if(!InitOccChannel()) return; // ʼְҵƵ + print("\n"); +#endif +#endif +#ifdef _ANGEL_SUMMON + print("ʼۼʱ..."); + AngelReady = 0; +#ifdef _ANGEL_TIME + AngelNextTime = time(NULL) + getAngelPlayerTime(); +#else + AngelNextTime = time(NULL) + 1*60; +#endif + print("\n"); +#endif + +//#ifdef _ALLDOMAN +// print("ʼӢ۱..."); +// InitHeroList(); +// print("\n"); +//#endif +#ifdef _JZ_NEWSCRIPT_LUA + print("ʼLNS..."); + NPC_Lua_Init(getLuaFile()); + print("\n"); +#endif +#ifdef _ALLBLUES_LUA + print("ʼLUAű..."); + LoadAllbluesLUA("data/ablua"); + print("\n"); +#endif + +#ifdef _EPOLL_ET_MODE + //߳ + print("߳..."); + if(Start_PacketWrapper() != 0 ) + { + print("ʧ\n"); + return; + } + print("\n"); + +// //ͷ߳ +// print("ͷ߳..."); +// if(Start_Epoll_SendLoop() != 0 ) +// { +// print("ʧ\n"); +// return; +// } +// print("\n"); + + //epollѭ߳ + print("epollѭ߳..."); + if( Start_Epoll_Loop() != 0 ) + { + print("ʧ\n"); + return; + } + print("\n"); +#endif + + while(1){ +#ifdef _ASSESS_SYSEFFICACY +Assess_SysEfficacy( 0 ); +#endif + + setNewTime(); + memcpy(&tmNow, localtime( (time_t *)&NowTime.tv_sec), + sizeof( tmNow ) ); + if( tmOld.tm_hour != getLogHour( ) && tmNow.tm_hour == getLogHour( ) ){ + +#ifdef _GMSV_DEBUG + DebugMainFunction="backupAllLogFile"; +#endif + backupAllLogFile( &tmOld ); + } + + setNewTime(); +#ifdef _ASSESS_SYSEFFICACY_SUB //ʾLOOPʱ + +Assess_SysEfficacy_sub( 0, 1); +#ifdef _GMSV_DEBUG + DebugMainFunction="netloop_faster"; +#endif + +#ifdef _EPOLL_ET_MODE + System_Loop(); +#else + netloop_faster(); +#endif + +Assess_SysEfficacy_sub( 1, 1); +Assess_SysEfficacy_sub( 0, 2); +#ifdef _GMSV_DEBUG + DebugMainFunction="NPC_generateLoop"; +#endif + NPC_generateLoop( 0 ); +Assess_SysEfficacy_sub( 1, 2); + +Assess_SysEfficacy_sub( 0, 3); +#ifdef _GMSV_DEBUG + DebugMainFunction="BATTLE_Loop"; +#endif + BATTLE_Loop(); +Assess_SysEfficacy_sub( 1, 3); + +Assess_SysEfficacy_sub( 0, 4); +#ifdef _GMSV_DEBUG + DebugMainFunction="CHAR_Loop"; +#endif + CHAR_Loop(); +Assess_SysEfficacy_sub( 1, 4); + +#ifdef _GMSV_DEBUG + DebugMainFunction="PETMAIL_proc"; +#endif + PETMAIL_proc(); + +#ifdef _GMSV_DEBUG + DebugMainFunction="family_proc"; +#endif + family_proc(); + +#ifdef _GMSV_DEBUG + DebugMainFunction="chardatasavecheck"; +#endif + chardatasavecheck(); +#ifdef _ANGEL_SUMMON +#ifdef _GMSV_DEBUG + DebugMainFunction="AngelReadyProc"; +#endif + AngelReadyProc(); +#endif + tmOld = tmNow; + if( tmOld.tm_sec != tmNow.tm_sec ) { +#ifdef _GMSV_DEBUG + DebugMainFunction="CHAR_checkEffectLoop"; +#endif + CHAR_checkEffectLoop(); + } + if( SERVSTATE_getShutdown()> 0 ) { + ShutdownProc(); +#ifdef _GMSV_DEBUG + DebugMainFunction="ShutdownProc"; +#endif + } + tmOld = tmNow; + +#ifdef _ASSESS_SYSEFFICACY +Assess_SysEfficacy( 1 ); +#endif +#endif + } +} + +static void sendmsg_toall( char *msg ) +{ + int i; + int playernum = CHAR_getPlayerMaxNum(); + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, msg, CHAR_COLORYELLOW); + } + } +} +static void ShutdownProc( void) +{ +#define SYSINFO_SHUTDOWN_MSG "%d Ӻʼϵͳͣά, ǰݶʧ" +#define SYSINFO_SHUTDOWN_MSG_COMP "ѹرա" + int diff,hun; + + diff = NowTime.tv_sec - SERVSTATE_getShutdown(); + hun = SERVSTATE_getLimittime() - (diff/60); + if( hun != SERVSTATE_getDsptime() ){ + char buff[256]; + if( hun != 0 ) { + snprintf( buff, sizeof(buff), SYSINFO_SHUTDOWN_MSG, hun); + } + else { + strcpy( buff, SYSINFO_SHUTDOWN_MSG_COMP); + } + sendmsg_toall( buff); + SERVSTATE_setDsptime(hun); + if( hun == 1 ) { + SERVSTATE_SetAcceptMore( 0 ); + } + } + /* closesallsockets */ + if( hun == 0) { + closeAllConnectionandSaveData(); + SERVSTATE_setShutdown(0); + SERVSTATE_setDsptime(0); + SERVSTATE_setLimittime(0); + } + +} + +void family_proc() +{ + static unsigned long gettime = 0; + static unsigned long checktime = 0; + static unsigned long proctime = 0; + + if( time(NULL) < proctime ) return; + proctime = time(NULL)+5; + + if( (unsigned long)NowTime.tv_sec > gettime ){ + getNewFMList(); + gettime = (unsigned long)NowTime.tv_sec + 60*10; + } + + if( (unsigned long)NowTime.tv_sec > checktime ){ + checkFamilyIndex(); + checktime = (unsigned long)NowTime.tv_sec + 60*30; + } +} + +void warplog_proc() +{ + static unsigned long checktime = 0; + + if( (unsigned long)NowTime.tv_sec > checktime ){ + warplog_to_file(); + checktime = (unsigned long)NowTime.tv_sec + 300; + } +} + +#ifdef _ANGEL_SUMMON + +extern int player_online; + +void AngelReadyProc() +{ + //static time_t lastCreateTime = time(NULL); + time_t nowTime; + //static unsigned long AngelNextTime = 30*60; + struct tm *temptime; + char msg[1024]; + + nowTime = time(NULL); + + if( nowTime < AngelNextTime ) + return; +#ifdef _ANGEL_TIME + if( player_online <= getAngelPlayerMun() ) +#else + if( player_online <= 10 ) +#endif + { +// print("\nٻ:=%d\n", player_online ); + return; + } + + AngelReady = 1; + //AngelNextTime = min( (int)(10000/player_online), 100)*60 + (unsigned long)nowTime; +#ifdef _ANGEL_TIME + AngelNextTime = min( (int)(getAngelPlayerTime()/player_online), 100)*60 + (unsigned long)nowTime; +#else + AngelNextTime = min( (int)(5000/player_online), 100)*60 + (unsigned long)nowTime; +#endif + + temptime = localtime( &AngelNextTime ); + sprintf( msg, "\nٻ:һλȱ ´βʱ=(%d/%d %d:%d) Ŀǰ=%d\n", + temptime->tm_mon+1, temptime->tm_mday, temptime->tm_hour, temptime->tm_min, player_online ); + print( msg); + //LogAngel( msg); +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/makefile new file mode 100755 index 0000000..3b2f8b0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/makefile @@ -0,0 +1,1084 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +# USE_MITO 反穴伙民旦伊永玉IO毛银丹方丹卞允月$1¤7indy匹戊件由奶伙允月午五叄1¤7 +# pthread 反骚日卅中及匹}仇木毛反内仄化pthread 手反内允仇午 + +INCFLAGS=-I. -I./include -I./lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64: +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQL=-lodbc32 -lz + PROG=../gmsvjt +endif +ifeq ($(shell uname),Linux) + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz + PROG=./gmsvjt +endif + +#TOP=../.. +TOP=.. + +PERL=/usr/bin/env perl + +SIMPLEEX=$(TOP)/bin/simpleex.perl + +#RPC +RPCGEN=~/bin/lsgen.perl +CLIRPCHTML=~/doc/saacproto.html +CLIRPCSRC=saacproto_cli.c saacproto_util.c +CLIRPCINCLUDE=include/saacproto_cli.h include/saacproto_util.h +CLIRPCNOUSE=saacproto_serv.c include/saacproto_serv.h +CLIRPCOPTION=-h include -o . -euc + +SERVRPCHTML=~/doc/lssproto.html +SERVRPCSRC=lssproto_serv.c lssproto_util.c +SERVRPCINCLUDE=include/lssproto_serv.h include/lssproto_util.h +SERVRPCNOUSE=lssproto_cli.c include/lssproto_cli.h +SERVRPCOPTION= -h include -o . -euc -e + +RPCSRC=$(CLIRPCSRC) $(SERVRPCSRC) + +#PETSKILL +PETSKILLGEN=~/bin/makedefs.perl +PETSKILLTXT=data/petskill.txt +PETSKILLOPTION= -name 8 -value 4 -o + +#CHAR_ANIM +ANIMDATAGEN=~/bin/convertStringtographicnumber.perl +ANIMDATATXT=include/anim_tbl.h +ANIMDATAFILE=char/ls2data.h + + +SUBDIR=char npc map item battle magic longzoro mylua lua npc_lua +LIBS=char/libchar.a npc/libnpc.a map/libmap.a\ +item/libitem.a \ +magic/libmagic.a \ +battle/libbattle.a \ +longzoro/liblongzoro.a \ +mylua/libmylua.a \ +npc_lua/libnpc_lua.a \ +lua/libluajit.a \ + +SRC=main.c init.c configfile.c util.c epollnet.c net.c buf.c msignal.c link.c md5.c shop.c\ +callfromac.c callfromcli.c object.c handletime.c function.c log.c autil.c descrypt.c const.c\ +$(CLIRPCSRC) $(SERVRPCSRC) + +OBJ=$(SRC:.c=.o) + + +LDFLAGS=-lm -lpthread -ldl +#LDFLAGS=-lm + + +ifeq ($(shell uname),Linux) + LDFLAGS+= +endif +ifeq ($(shell uname),SunOS) + LDFLAGS+=-lnsl -lsocket +endif +ifeq ($(shell uname),FreeBSD) + LDFLAGS+= +endif + +all: $(PROG) + +$(PROG): allblues $(RPCSRC) $(ANIMDATAFILE) $(LIBS) $(OBJ) + $(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) $(LDFLAGS) $(SQL) + +allblues: + $(SHELL) ./longzoro.sh + +dos2unix: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir dos2unix;\ + done + dos2unix ./include/*.h ./include/longzoro/*.h $(SRC) makefile + +chmod: + chmod 777 -R * + +tar: + make clean + tar -zcvf ../gmsv$(date).tar.gz * + +depend: $(RPCSRC) $(ANIMDATAFILE) + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir depend;\ + done + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir clean;\ + done + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir distclean;\ + done + $(RM) $(CLIRPCSRC) + $(RM) $(CLIRPCINCLUDE) + $(RM) $(SERVRPCSRC) + $(RM) $(SERVRPCINCLUDE) + $(RM) $(ANIMDATAFILE) + $(RM) include/*~ + + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +data: $(RPCSRC) $(ANIMDATAFILE) + +$(CLIRPCSRC): #$(RPCGEN) $(CLIRPCHTML) $(CLIRPCGEN) +# $(PERL) $(RPCGEN) $(CLIRPCOPTION) $(CLIRPCHTML) +# $(RM) $(CLIRPCNOUSE) + +$(SERVRPCSRC): #$(RPCGEN) $(SERVRPCHTML) $(SERVRPCGEN) +# $(PERL) $(RPCGEN) $(SERVRPCOPTION) $(SERVRPCHTML) +# $(RM) $(SERVRPCNOUSE) + +$(ANIMDATAFILE): #$(ANIMDATAGEN) $(ANIMDATATXT) +# $(PERL) $(ANIMDATAGEN) $(ANIMDATATXT) > $(ANIMDATAFILE) + +$(LIBS): + @target=`echo $@ | $(SED) s/\\\\/.\\*//`; \ + $(MAKE) -C $$target; + + +jpex : + $(PERL) $(SIMPLEEX) *.c */*.c | nkf -s > jp_literal.sjis + +# DO NOT DELETE THIS LINE +main.o: main.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/string.h /usr/include/signal.h /usr/include/bits/sigset.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/pthread.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h /usr/include/setjmp.h include/init.h \ + include/net.h include/autil.h include/version.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h include/link.h \ + include/handletime.h include/char.h include/char_base.h include/skill.h \ + include/util.h /usr/include/stdlib.h /usr/include/alloca.h \ + include/title.h include/addressbook.h include/net.h lua/lua.h \ + lua/luaconf.h lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h \ + include/item.h include/char.h include/map_warppoint.h include/npcgen.h \ + include/log.h include/configfile.h include/battle.h include/trade.h \ + include/petmail.h include/autil.h include/family.h include/trade.h \ + include/longzoro/attestation.h include/longzoro/sasql.h \ + include/longzoro/version.h include/mylua/ablua.h include/chatroom.h \ + include/shop.h +init.o: init.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/dirent.h \ + /usr/include/bits/dirent.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h include/configfile.h include/util.h \ + /usr/include/sys/time.h /usr/include/stdlib.h /usr/include/alloca.h \ + include/net.h include/autil.h include/version.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/msignal.h \ + include/buf.h include/object.h include/char.h include/char_base.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h lua/lua.h lua/luaconf.h lua/lauxlib.h lua/lua.h \ + lua/lualib.h include/char_data.h include/item.h include/char.h \ + include/char_data.h include/item.h include/readmap.h include/function.h \ + include/saacproto_cli.h include/saacproto_util.h /usr/include/string.h \ + include/lssproto_serv.h include/lssproto_util.h include/readnpc.h \ + include/log.h include/handletime.h include/title.h include/encount.h \ + include/enemy.h include/battle.h include/trade.h include/magic_base.h \ + include/pet_skill.h include/item_gen.h include/petmail.h \ + include/npc_quiz.h include/char_talk.h include/longzoro/move.h \ + include/autil.h include/profession_skill.h include/mylua/mylua.h \ + lua/lua.h lua/lauxlib.h lua/lualib.h include/init.h +configfile.o: configfile.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/lssproto_util.h include/configfile.h include/net.h \ + include/autil.h include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/npcutil.h \ + include/char.h include/char_base.h include/skill.h include/util.h \ + include/title.h include/addressbook.h include/net.h lua/lua.h \ + lua/luaconf.h lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h \ + include/item.h include/char.h include/char_data.h \ + include/lssproto_serv.h include/lssproto_util.h include/autil.h +util.o: util.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/sys/time.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/arpa/inet.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/alloca.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h /usr/include/ctype.h \ + include/common.h include/util.h include/configfile.h \ + /usr/include/assert.h +epollnet.o: epollnet.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/sys/epoll.h /usr/include/stdint.h \ + /usr/include/netinet/in.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h /usr/include/string.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/netinet/tcp.h include/net.h include/common.h \ + include/autil.h include/version.h include/correct_bug.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/time.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/epollnet.h \ + include/configfile.h include/version.h +net.o: net.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/netdb.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/sys/time.h /usr/include/arpa/inet.h \ + /usr/include/netinet/tcp.h /usr/include/sys/timeb.h \ + /usr/include/fcntl.h /usr/include/bits/fcntl.h include/net.h \ + include/autil.h include/version.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/buf.h include/link.h \ + include/common.h include/msignal.h include/configfile.h include/util.h \ + include/saacproto_cli.h include/saacproto_util.h /usr/include/strings.h \ + include/lssproto_serv.h include/lssproto_util.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/handletime.h include/log.h include/object.h \ + include/item_event.h include/enemy.h include/battle.h include/trade.h \ + include/pet_event.h include/char_talk.h include/petmail.h \ + include/mylua/function.h include/npc_autopk.h include/longzoro/sasql.h \ + include/longzoro/version.h +buf.o: buf.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h include/buf.h \ + include/handletime.h /usr/include/sys/time.h +msignal.o: msignal.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/signal.h \ + /usr/include/bits/sigset.h /usr/include/bits/signum.h \ + /usr/include/time.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/execinfo.h include/buf.h include/net.h include/autil.h \ + include/version.h /usr/include/sys/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/stdlib.h /usr/include/alloca.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/item.h include/object.h include/configfile.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/string.h \ + /usr/include/strings.h include/saacproto_cli.h include/saacproto_util.h \ + include/log.h include/petmail.h longzoro.h include/mylua/mylua.h \ + lua/lua.h lua/lauxlib.h lua/lualib.h +link.o: link.c /usr/include/stdlib.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/sys/types.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/link.h include/buf.h +md5.o: md5.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h include/md5.h +shop.o: shop.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/autil.h include/version.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h include/buf.h include/md5.h \ + include/shop.h +callfromac.o: callfromac.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + include/version.h include/correct_bug.h include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/common.h include/saacproto_cli.h \ + include/version.h include/saacproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/lssproto_serv.h include/lssproto_util.h \ + include/net.h include/autil.h /usr/include/sys/time.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/object.h include/readmap.h include/msignal.h \ + include/map_deal.h include/npc_duelranking.h include/npc_warpman.h \ + include/handletime.h include/npc_scheduleman.h include/configfile.h \ + include/chatroom.h include/npc_eventaction.h include/family.h \ + include/log.h include/buf.h include/enemy.h include/battle.h \ + include/trade.h include/npc_alldoman.h longzoro.h +callfromcli.o: callfromcli.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/common.h include/util.h \ + /usr/include/sys/time.h include/lssproto_serv.h include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/saacproto_cli.h include/version.h \ + include/saacproto_util.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/object.h include/readmap.h include/addressbook.h \ + include/handletime.h include/configfile.h include/event.h include/pet.h \ + include/battle.h include/trade.h include/battle_command.h \ + include/magic.h include/petmail.h include/item_gen.h \ + include/pet_skill.h include/log.h include/map_deal.h include/trade.h \ + include/family.h include/item_event.h include/npc_autopk.h \ + include/npc_healer.h include/profession_skill.h include/chatroom.h \ + include/mylua/function.h +object.o: object.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/stat.h /usr/include/time.h \ + /usr/include/bits/stat.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h include/handletime.h \ + /usr/include/sys/time.h include/common.h include/object.h \ + include/char_base.h include/version.h include/skill.h include/util.h \ + include/title.h include/addressbook.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char.h include/char_base.h \ + include/char_data.h include/item.h include/char.h include/item.h \ + include/buf.h include/readmap.h include/pet.h +handletime.o: handletime.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h include/common.h \ + include/handletime.h +function.o: function.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h include/common.h \ + include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/char_event.h include/char_base.h include/version.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char.h include/char_data.h \ + include/item.h include/char.h include/item_event.h include/magic.h \ + include/pet_event.h include/npc_townpeople.h include/npc_Dengon.h \ + include/npc_door.h include/npc_healer.h include/npc_oldman.h \ + include/npc_warp.h include/npc_storyteller.h include/npc_msg.h \ + include/npc_npcenemy.h include/npc_action.h include/npc_windowman.h \ + include/npc_savepoint.h include/npc_windowhealer.h \ + include/npc_itemshop.h include/npc_sysinfo.h include/npc_duelranking.h \ + include/npc_petskillshop.h include/npc_petshop.h \ + include/npc_signboard.h include/npc_warpman.h include/npc_exchangeman.h \ + include/petmail.h include/npc_timeman.h include/npc_bodylan.h \ + include/npc_mic.h include/npc_luckyman.h include/npc_bus.h \ + include/npc_charm.h include/npc_poolitemshop.h include/npc_quiz.h \ + include/npc_checkman.h include/npc_janken.h \ + include/npc_transmigration.h include/battle_event.h include/enemy.h \ + include/npc_familyman.h include/npc_bankman.h include/npc_fmdengon.h \ + include/npc_fmhealer.h include/npc_petmaker.h include/npc_fmwarpman.h \ + include/npc_fmpkman.h include/npc_fmpkcallman.h include/npc_airplane.h \ + include/npc_scheduleman.h include/npc_manorsman.h \ + include/npc_riderman.h include/npc_fmletter.h include/npc_gamblebank.h \ + include/npc_newnpcman.h include/npc_gambleroulette.h \ + include/npc_gamblemaster.h include/npc_transerman.h \ + include/npc_vipshop.h include/npc_newvipshop.h include/npc_autopk.h \ + include/npc_pauctionman.h include/npc_freepetskillshop.h \ + include/npc_petracemaster.h include/npc_petracepet.h \ + include/npc_itemchange.h include/npc_makepair.h include/npc_petfusion.h \ + include/npc_alldoman.h include/npc_welfare.h include/npc_magiccard.h \ + include/npc_lua_interface.h +log.o: log.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h include/common.h include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h include/log.h \ + include/handletime.h include/net.h include/autil.h include/version.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char_base.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h lua/lua.h lua/luaconf.h lua/lauxlib.h lua/lua.h \ + lua/lualib.h +autil.o: autil.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/autil.h include/version.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/sys/time.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/lssproto_util.h /usr/include/string.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h +descrypt.o: descrypt.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h descrypt.h +const.o: const.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/common.h include/char.h \ + include/char_base.h include/version.h include/skill.h include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h include/title.h \ + include/addressbook.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/char_data.h include/item.h include/battle.h \ + include/trade.h include/object.h include/magic_base.h include/enemy.h +saacproto_cli.o: saacproto_cli.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/saacproto_cli.h include/version.h \ + include/saacproto_util.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h include/common.h \ + include/net.h include/autil.h /usr/include/sys/time.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/lssproto_serv.h \ + include/lssproto_util.h include/chatmagic.h +saacproto_util.o: saacproto_util.c include/version.h \ + include/correct_bug.h include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/saacproto_util.h +lssproto_serv.o: lssproto_serv.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/autil.h include/version.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h include/log.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/sys/time.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/battle.h include/trade.h descrypt.h \ + include/configfile.h include/net.h /usr/include/zutil.h \ + /usr/include/zlib.h /usr/include/zconf.h include/shop.h \ + include/npc_lua_interface.h +lssproto_util.o: lssproto_util.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/lssproto_util.h \ + include/common.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/makefile.bak new file mode 100755 index 0000000..3b2f8b0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/makefile.bak @@ -0,0 +1,1084 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +# USE_MITO 反穴伙民旦伊永玉IO毛银丹方丹卞允月$1¤7indy匹戊件由奶伙允月午五叄1¤7 +# pthread 反骚日卅中及匹}仇木毛反内仄化pthread 手反内允仇午 + +INCFLAGS=-I. -I./include -I./lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64: +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQL=-lodbc32 -lz + PROG=../gmsvjt +endif +ifeq ($(shell uname),Linux) + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz + PROG=./gmsvjt +endif + +#TOP=../.. +TOP=.. + +PERL=/usr/bin/env perl + +SIMPLEEX=$(TOP)/bin/simpleex.perl + +#RPC +RPCGEN=~/bin/lsgen.perl +CLIRPCHTML=~/doc/saacproto.html +CLIRPCSRC=saacproto_cli.c saacproto_util.c +CLIRPCINCLUDE=include/saacproto_cli.h include/saacproto_util.h +CLIRPCNOUSE=saacproto_serv.c include/saacproto_serv.h +CLIRPCOPTION=-h include -o . -euc + +SERVRPCHTML=~/doc/lssproto.html +SERVRPCSRC=lssproto_serv.c lssproto_util.c +SERVRPCINCLUDE=include/lssproto_serv.h include/lssproto_util.h +SERVRPCNOUSE=lssproto_cli.c include/lssproto_cli.h +SERVRPCOPTION= -h include -o . -euc -e + +RPCSRC=$(CLIRPCSRC) $(SERVRPCSRC) + +#PETSKILL +PETSKILLGEN=~/bin/makedefs.perl +PETSKILLTXT=data/petskill.txt +PETSKILLOPTION= -name 8 -value 4 -o + +#CHAR_ANIM +ANIMDATAGEN=~/bin/convertStringtographicnumber.perl +ANIMDATATXT=include/anim_tbl.h +ANIMDATAFILE=char/ls2data.h + + +SUBDIR=char npc map item battle magic longzoro mylua lua npc_lua +LIBS=char/libchar.a npc/libnpc.a map/libmap.a\ +item/libitem.a \ +magic/libmagic.a \ +battle/libbattle.a \ +longzoro/liblongzoro.a \ +mylua/libmylua.a \ +npc_lua/libnpc_lua.a \ +lua/libluajit.a \ + +SRC=main.c init.c configfile.c util.c epollnet.c net.c buf.c msignal.c link.c md5.c shop.c\ +callfromac.c callfromcli.c object.c handletime.c function.c log.c autil.c descrypt.c const.c\ +$(CLIRPCSRC) $(SERVRPCSRC) + +OBJ=$(SRC:.c=.o) + + +LDFLAGS=-lm -lpthread -ldl +#LDFLAGS=-lm + + +ifeq ($(shell uname),Linux) + LDFLAGS+= +endif +ifeq ($(shell uname),SunOS) + LDFLAGS+=-lnsl -lsocket +endif +ifeq ($(shell uname),FreeBSD) + LDFLAGS+= +endif + +all: $(PROG) + +$(PROG): allblues $(RPCSRC) $(ANIMDATAFILE) $(LIBS) $(OBJ) + $(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) $(LDFLAGS) $(SQL) + +allblues: + $(SHELL) ./longzoro.sh + +dos2unix: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir dos2unix;\ + done + dos2unix ./include/*.h ./include/longzoro/*.h $(SRC) makefile + +chmod: + chmod 777 -R * + +tar: + make clean + tar -zcvf ../gmsv$(date).tar.gz * + +depend: $(RPCSRC) $(ANIMDATAFILE) + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir depend;\ + done + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir clean;\ + done + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + @for dir in $(SUBDIR) ; do \ + $(MAKE) -C $$dir distclean;\ + done + $(RM) $(CLIRPCSRC) + $(RM) $(CLIRPCINCLUDE) + $(RM) $(SERVRPCSRC) + $(RM) $(SERVRPCINCLUDE) + $(RM) $(ANIMDATAFILE) + $(RM) include/*~ + + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +data: $(RPCSRC) $(ANIMDATAFILE) + +$(CLIRPCSRC): #$(RPCGEN) $(CLIRPCHTML) $(CLIRPCGEN) +# $(PERL) $(RPCGEN) $(CLIRPCOPTION) $(CLIRPCHTML) +# $(RM) $(CLIRPCNOUSE) + +$(SERVRPCSRC): #$(RPCGEN) $(SERVRPCHTML) $(SERVRPCGEN) +# $(PERL) $(RPCGEN) $(SERVRPCOPTION) $(SERVRPCHTML) +# $(RM) $(SERVRPCNOUSE) + +$(ANIMDATAFILE): #$(ANIMDATAGEN) $(ANIMDATATXT) +# $(PERL) $(ANIMDATAGEN) $(ANIMDATATXT) > $(ANIMDATAFILE) + +$(LIBS): + @target=`echo $@ | $(SED) s/\\\\/.\\*//`; \ + $(MAKE) -C $$target; + + +jpex : + $(PERL) $(SIMPLEEX) *.c */*.c | nkf -s > jp_literal.sjis + +# DO NOT DELETE THIS LINE +main.o: main.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/string.h /usr/include/signal.h /usr/include/bits/sigset.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/pthread.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h /usr/include/setjmp.h include/init.h \ + include/net.h include/autil.h include/version.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h include/link.h \ + include/handletime.h include/char.h include/char_base.h include/skill.h \ + include/util.h /usr/include/stdlib.h /usr/include/alloca.h \ + include/title.h include/addressbook.h include/net.h lua/lua.h \ + lua/luaconf.h lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h \ + include/item.h include/char.h include/map_warppoint.h include/npcgen.h \ + include/log.h include/configfile.h include/battle.h include/trade.h \ + include/petmail.h include/autil.h include/family.h include/trade.h \ + include/longzoro/attestation.h include/longzoro/sasql.h \ + include/longzoro/version.h include/mylua/ablua.h include/chatroom.h \ + include/shop.h +init.o: init.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/dirent.h \ + /usr/include/bits/dirent.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h include/configfile.h include/util.h \ + /usr/include/sys/time.h /usr/include/stdlib.h /usr/include/alloca.h \ + include/net.h include/autil.h include/version.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/msignal.h \ + include/buf.h include/object.h include/char.h include/char_base.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h lua/lua.h lua/luaconf.h lua/lauxlib.h lua/lua.h \ + lua/lualib.h include/char_data.h include/item.h include/char.h \ + include/char_data.h include/item.h include/readmap.h include/function.h \ + include/saacproto_cli.h include/saacproto_util.h /usr/include/string.h \ + include/lssproto_serv.h include/lssproto_util.h include/readnpc.h \ + include/log.h include/handletime.h include/title.h include/encount.h \ + include/enemy.h include/battle.h include/trade.h include/magic_base.h \ + include/pet_skill.h include/item_gen.h include/petmail.h \ + include/npc_quiz.h include/char_talk.h include/longzoro/move.h \ + include/autil.h include/profession_skill.h include/mylua/mylua.h \ + lua/lua.h lua/lauxlib.h lua/lualib.h include/init.h +configfile.o: configfile.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/lssproto_util.h include/configfile.h include/net.h \ + include/autil.h include/version.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/npcutil.h \ + include/char.h include/char_base.h include/skill.h include/util.h \ + include/title.h include/addressbook.h include/net.h lua/lua.h \ + lua/luaconf.h lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h \ + include/item.h include/char.h include/char_data.h \ + include/lssproto_serv.h include/lssproto_util.h include/autil.h +util.o: util.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/sys/time.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/arpa/inet.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/alloca.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h /usr/include/ctype.h \ + include/common.h include/util.h include/configfile.h \ + /usr/include/assert.h +epollnet.o: epollnet.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/sys/epoll.h /usr/include/stdint.h \ + /usr/include/netinet/in.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h /usr/include/string.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/netinet/tcp.h include/net.h include/common.h \ + include/autil.h include/version.h include/correct_bug.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/time.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/epollnet.h \ + include/configfile.h include/version.h +net.o: net.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/netdb.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/sys/time.h /usr/include/arpa/inet.h \ + /usr/include/netinet/tcp.h /usr/include/sys/timeb.h \ + /usr/include/fcntl.h /usr/include/bits/fcntl.h include/net.h \ + include/autil.h include/version.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/buf.h include/link.h \ + include/common.h include/msignal.h include/configfile.h include/util.h \ + include/saacproto_cli.h include/saacproto_util.h /usr/include/strings.h \ + include/lssproto_serv.h include/lssproto_util.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/handletime.h include/log.h include/object.h \ + include/item_event.h include/enemy.h include/battle.h include/trade.h \ + include/pet_event.h include/char_talk.h include/petmail.h \ + include/mylua/function.h include/npc_autopk.h include/longzoro/sasql.h \ + include/longzoro/version.h +buf.o: buf.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h include/buf.h \ + include/handletime.h /usr/include/sys/time.h +msignal.o: msignal.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/signal.h \ + /usr/include/bits/sigset.h /usr/include/bits/signum.h \ + /usr/include/time.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/execinfo.h include/buf.h include/net.h include/autil.h \ + include/version.h /usr/include/sys/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/stdlib.h /usr/include/alloca.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/item.h include/object.h include/configfile.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/string.h \ + /usr/include/strings.h include/saacproto_cli.h include/saacproto_util.h \ + include/log.h include/petmail.h longzoro.h include/mylua/mylua.h \ + lua/lua.h lua/lauxlib.h lua/lualib.h +link.o: link.c /usr/include/stdlib.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/sys/types.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/link.h include/buf.h +md5.o: md5.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h include/md5.h +shop.o: shop.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/autil.h include/version.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h include/buf.h include/md5.h \ + include/shop.h +callfromac.o: callfromac.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + include/version.h include/correct_bug.h include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/common.h include/saacproto_cli.h \ + include/version.h include/saacproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/lssproto_serv.h include/lssproto_util.h \ + include/net.h include/autil.h /usr/include/sys/time.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/object.h include/readmap.h include/msignal.h \ + include/map_deal.h include/npc_duelranking.h include/npc_warpman.h \ + include/handletime.h include/npc_scheduleman.h include/configfile.h \ + include/chatroom.h include/npc_eventaction.h include/family.h \ + include/log.h include/buf.h include/enemy.h include/battle.h \ + include/trade.h include/npc_alldoman.h longzoro.h +callfromcli.o: callfromcli.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/common.h include/util.h \ + /usr/include/sys/time.h include/lssproto_serv.h include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/saacproto_cli.h include/version.h \ + include/saacproto_util.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char.h \ + include/char_base.h include/skill.h include/util.h include/title.h \ + include/addressbook.h include/net.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/object.h include/readmap.h include/addressbook.h \ + include/handletime.h include/configfile.h include/event.h include/pet.h \ + include/battle.h include/trade.h include/battle_command.h \ + include/magic.h include/petmail.h include/item_gen.h \ + include/pet_skill.h include/log.h include/map_deal.h include/trade.h \ + include/family.h include/item_event.h include/npc_autopk.h \ + include/npc_healer.h include/profession_skill.h include/chatroom.h \ + include/mylua/function.h +object.o: object.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/sys/stat.h /usr/include/time.h \ + /usr/include/bits/stat.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h include/handletime.h \ + /usr/include/sys/time.h include/common.h include/object.h \ + include/char_base.h include/version.h include/skill.h include/util.h \ + include/title.h include/addressbook.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char.h include/char_base.h \ + include/char_data.h include/item.h include/char.h include/item.h \ + include/buf.h include/readmap.h include/pet.h +handletime.o: handletime.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h include/common.h \ + include/handletime.h +function.o: function.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h include/common.h \ + include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + include/char_event.h include/char_base.h include/version.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char.h include/char_data.h \ + include/item.h include/char.h include/item_event.h include/magic.h \ + include/pet_event.h include/npc_townpeople.h include/npc_Dengon.h \ + include/npc_door.h include/npc_healer.h include/npc_oldman.h \ + include/npc_warp.h include/npc_storyteller.h include/npc_msg.h \ + include/npc_npcenemy.h include/npc_action.h include/npc_windowman.h \ + include/npc_savepoint.h include/npc_windowhealer.h \ + include/npc_itemshop.h include/npc_sysinfo.h include/npc_duelranking.h \ + include/npc_petskillshop.h include/npc_petshop.h \ + include/npc_signboard.h include/npc_warpman.h include/npc_exchangeman.h \ + include/petmail.h include/npc_timeman.h include/npc_bodylan.h \ + include/npc_mic.h include/npc_luckyman.h include/npc_bus.h \ + include/npc_charm.h include/npc_poolitemshop.h include/npc_quiz.h \ + include/npc_checkman.h include/npc_janken.h \ + include/npc_transmigration.h include/battle_event.h include/enemy.h \ + include/npc_familyman.h include/npc_bankman.h include/npc_fmdengon.h \ + include/npc_fmhealer.h include/npc_petmaker.h include/npc_fmwarpman.h \ + include/npc_fmpkman.h include/npc_fmpkcallman.h include/npc_airplane.h \ + include/npc_scheduleman.h include/npc_manorsman.h \ + include/npc_riderman.h include/npc_fmletter.h include/npc_gamblebank.h \ + include/npc_newnpcman.h include/npc_gambleroulette.h \ + include/npc_gamblemaster.h include/npc_transerman.h \ + include/npc_vipshop.h include/npc_newvipshop.h include/npc_autopk.h \ + include/npc_pauctionman.h include/npc_freepetskillshop.h \ + include/npc_petracemaster.h include/npc_petracepet.h \ + include/npc_itemchange.h include/npc_makepair.h include/npc_petfusion.h \ + include/npc_alldoman.h include/npc_welfare.h include/npc_magiccard.h \ + include/npc_lua_interface.h +log.o: log.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h include/common.h include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h include/log.h \ + include/handletime.h include/net.h include/autil.h include/version.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/char_base.h \ + include/skill.h include/util.h include/title.h include/addressbook.h \ + include/net.h lua/lua.h lua/luaconf.h lua/lauxlib.h lua/lua.h \ + lua/lualib.h +autil.o: autil.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/autil.h include/version.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/sys/time.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/lssproto_util.h /usr/include/string.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h +descrypt.o: descrypt.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h descrypt.h +const.o: const.c include/version.h include/correct_bug.h include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/common.h include/char.h \ + include/char_base.h include/version.h include/skill.h include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h include/title.h \ + include/addressbook.h include/net.h include/autil.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/char_data.h include/item.h include/battle.h \ + include/trade.h include/object.h include/magic_base.h include/enemy.h +saacproto_cli.o: saacproto_cli.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/saacproto_cli.h include/version.h \ + include/saacproto_util.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h include/common.h \ + include/net.h include/autil.h /usr/include/sys/time.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h include/lssproto_serv.h \ + include/lssproto_util.h include/chatmagic.h +saacproto_util.o: saacproto_util.c include/version.h \ + include/correct_bug.h include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/saacproto_util.h +lssproto_serv.o: lssproto_serv.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h include/autil.h include/version.h \ + include/lssproto_serv.h include/lssproto_util.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/common.h include/log.h include/char.h \ + include/char_base.h include/skill.h include/util.h \ + /usr/include/sys/time.h include/title.h include/addressbook.h \ + include/net.h include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h include/link.h lua/lua.h lua/luaconf.h \ + lua/lauxlib.h lua/lua.h lua/lualib.h include/char_data.h include/item.h \ + include/char.h include/battle.h include/trade.h descrypt.h \ + include/configfile.h include/net.h /usr/include/zutil.h \ + /usr/include/zlib.h /usr/include/zconf.h include/shop.h \ + include/npc_lua_interface.h +lssproto_util.o: lssproto_util.c include/version.h include/correct_bug.h \ + include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/longzoro/version.h include/longzoro/longzoro.h \ + include/longzoro/debug.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/lssproto_util.h \ + include/common.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/make.exe.stackdump b/石器时代服务器端最新完整源代码/Serv/gmsv/map/make.exe.stackdump new file mode 100644 index 0000000..577a30a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/make.exe.stackdump @@ -0,0 +1,8 @@ +Exception: STATUS_ACCESS_VIOLATION at eip=7C915F9C +eax=7C915F9C ebx=007CCDF0 ecx=611034B0 edx=FFFFFFFF esi=00000000 edi=007CCE64 +ebp=003D0000 esp=007CCDB4 program=J:\cygwin\bin\make.exe, pid 6000, thread unknown (0x177C) +cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023 +Stack trace: +Frame Function Args +003D0000 7C915F9C (D0FF7C91, 430004C2, 72505C3A, 6172676F) + 3 [unknown (0x177C)] make 6000! _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack) diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile new file mode 100755 index 0000000..f5b5afc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile @@ -0,0 +1,250 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmap.a + +SRC=readmap.c map_deal.c map_util.c map_warppoint.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +readmap.o: readmap.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h ../include/common.h ../include/object.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + ../include/buf.h ../include/util.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h ../include/configfile.h ../include/autil.h +map_deal.o: map_deal.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/map_util.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/net.h \ + ../include/anim_tbl.h +map_util.o: map_util.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/readmap.h +map_warppoint.o: map_warppoint.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/object.h ../include/buf.h \ + ../include/util.h ../include/configfile.h ../include/readmap.h \ + ../include/map_warppoint.h ../include/autil.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile.bak new file mode 100755 index 0000000..f5b5afc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/makefile.bak @@ -0,0 +1,250 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I.. -I../include -I../lua + + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmap.a + +SRC=readmap.c map_deal.c map_util.c map_warppoint.c +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +readmap.o: readmap.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h ../include/common.h ../include/object.h \ + ../include/readmap.h ../include/util.h /usr/include/sys/time.h \ + ../include/buf.h ../include/util.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h ../include/configfile.h ../include/autil.h +map_deal.o: map_deal.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/readmap.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/map_util.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/net.h \ + ../include/anim_tbl.h +map_util.o: map_util.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/readmap.h +map_warppoint.o: map_warppoint.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/object.h ../include/buf.h \ + ../include/util.h ../include/configfile.h ../include/readmap.h \ + ../include/map_warppoint.h ../include/autil.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_deal.c b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_deal.c new file mode 100644 index 0000000..0336607 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_deal.c @@ -0,0 +1,405 @@ +#include "version.h" +#include "common.h" +#include "readmap.h" +#include "char.h" +#include "map_util.h" +#include "lssproto_serv.h" +#include "net.h" +#include "anim_tbl.h" + +/*#define MAPEDITORTROUBLE*/ +#define SPR_kmydamY CG_HIT_MARK_10 // anim_tbl.h ϿޤǤΥե + +/*------------------------------------------------------------ + * ⤱뤫ɤȽǤ롣餬Ǥ뤫ɤ롣 + * + * ff int floor + * fx int xɸ + * fy int yɸ + * isfly int Ǥ뤫ɤ + * ֤ + * ⤱ TRUE(1) + * ⤱ʤ FALSE(0) + ------------------------------------------------------------*/ +BOOL MAP_walkAbleFromPoint( int ff, int fx, int fy, BOOL isfly ) +{ + int map[2]; + + if( !MAP_getTileAndObjData( ff,fx,fy, &map[0], &map[1] ) ){ + return FALSE; + } + + if( isfly ){ + int i; + for( i = 0 ; i < 2 ; i ++ ) + if( MAP_getImageInt( map[i], MAP_HAVEHEIGHT ) == TRUE ){ + return FALSE; + } + return TRUE; + }else{ + switch( MAP_getImageInt( map[1], MAP_WALKABLE ) ){ + case 0: + return FALSE; + break; + case 1: + if( MAP_getImageInt( map[0], MAP_WALKABLE ) == 1 ){ + return TRUE; + }else{ + return FALSE; + } + break; + case 2: + return TRUE; + break; + default: + return FALSE; + break; + } + } + return FALSE; +} + +/* + * ⤱뤫ɤȽǤ롣 + * + * index int CharǤ Index + * ff int floor id + * fx int xɸ + * fy int yɸ + * ֤ + * ⤤Ƥ褤 TRUE(1) + * ⤤Ƥϥ FALSE(0) + ------------------------------------------------------------*/ +BOOL MAP_walkAble( int index,int ff, int fx, int fy) +{ + /* ƩʤOK */ + if( CHAR_getFlg( index, CHAR_ISTRANSPARENT ) ) return TRUE; + + // Arminius 7.9 Airplane ok + if( CHAR_getInt( index, CHAR_WHICHTYPE ) == CHAR_TYPEBUS) return TRUE; + if( CHAR_getWorkInt( index, CHAR_WORKPARTYMODE) == CHAR_PARTY_CLIENT ) { + int oyaindex = CHAR_getWorkInt( index, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex)) { + if (CHAR_getInt( oyaindex, CHAR_WHICHTYPE ) == CHAR_TYPEBUS) return TRUE; + } + } + + return MAP_walkAbleFromPoint( ff,fx,fy,CHAR_getFlg(index,CHAR_ISFLYING)|CHAR_getWorkInt(index,CHAR_WORKSKYWALKER) ); +} + +/*------------------------------------------------------------ + * ɸꤷơΥ֥Ȥ˹⤵뤫ɤ + * + * fl int ե + * x int x ɸ + * y int y ɸ + * ֤ + * ⤵ TRUE + * ⤵ʤ FALSE + ------------------------------------------------------------*/ +BOOL MAP_haveHeight( int fl, int x, int y ) +{ + int map[2]; + + /* ޥåץǡƤ */ + if( !MAP_getTileAndObjData( fl,x,y, &map[0], &map[1] ) ) + return FALSE; + + return MAP_getImageInt( map[1], MAP_HAVEHEIGHT ); +} + + + +/*---------------------------------------- + * ơѲϤѹ򤹤 + * + * index int Υǥå + +/*------------------------------------------------------------ + * Map ٥Ȥ pre post + * + * index int ȤƤ륭Υǥå + * mode BOOL TRUEλϡin FALSEλ out б + * ֤ͤʤ + ------------------------------------------------------------*/ +static void MAP_dealprepostevent( int index, BOOL mode ) +{ + int map[2]; + int i; + int damaged=FALSE; + + if( CHAR_getFlg(index,CHAR_ISFLYING) ) + /* ǤĤˤϲ⤷ʤ */ + return; + + if( !MAP_getMapDataFromCharIndex( index , map ) ) return; + + for( i = 0 ; i < 2 ; i ++ ){ + /* damage */ + int damage; + damage = MAP_getImageInt(map[i], + mode ? MAP_INTODAMAGE : MAP_OUTOFDAMAGE); + if( damage != 0 ){ + /* ᡼̤ɽΤؤ */ + int opt[2]={SPR_kmydamY,-damage}; + damaged=TRUE; + CHAR_setInt(index, CHAR_HP, + CHAR_getInt(index,CHAR_HP) + damage ); + CHAR_complianceParameter(index); + /* ᡼եȽФ */ + CHAR_sendWatchEvent(CHAR_getWorkInt(index,CHAR_WORKOBJINDEX), + CHAR_ACTDAMAGE,opt,2,TRUE); + } + } + if( damaged ) + CHAR_sendStatusString(index,"M"); +} + + +/*---------------------------------------- + * Υ˾˸ƤФ롣ǤयȡxxxϤ + * ¸롣 + * + * index int ȤƤ륭Υǥå + * flooor int եID + * fx int xɸ + * fy int yɸ + * ֤ + * ʤ + ----------------------------------------*/ +void MAP_preovered( int index ) +{ + MAP_dealprepostevent( index, FALSE ); +} + +/*---------------------------------------- + * Υ˾ä˸ƤФ롣 + * + * index int ȤƤ륭Υǥå + * ֤ + * ʤ + ----------------------------------------*/ +void MAP_postovered( int index ) +{ + MAP_dealprepostevent( index, TRUE ); +} + + +/*---------------------------------------- + * μΥޥåפ򤹤٤ + * + * fd int + * charaindex int Υǥå + * ֤ + * TRUE(1) + * FALSE(0) + ----------------------------------------*/ +BOOL MAP_sendArroundCharNeedFD( int fd,int charaindex ) +{ + char* stringdata; + int x=CHAR_getInt(charaindex,CHAR_X); + int y=CHAR_getInt(charaindex,CHAR_Y); + int fl=CHAR_getInt(charaindex,CHAR_FLOOR); + int size=MAP_CHAR_DEFAULTSEESIZ; + RECT seekr,retr; + seekr.x = x - (int)(size/2); + seekr.y = y - (int)(size/2); + seekr.width = size; + seekr.height = size; +#ifdef _MO_MAP_AUTO_UPDATE +{ + int tilesum, objsum, eventsum; + stringdata = MAP_getChecksumFromRECT(fl,&seekr,&retr, &tilesum,&objsum,&eventsum); + if( stringdata == NULL ) + return FALSE; + + lssproto_MC_send(fd,fl, + retr.x, retr.y, + retr.x + retr.width, retr.y + retr.height, + tilesum, + objsum, + eventsum, + stringdata ); +} +#else + stringdata = MAP_getdataFromRECT(fl,&seekr,&retr); + if( stringdata == NULL ) + return FALSE; + + lssproto_M_send(fd,fl, + retr.x, retr.y, + retr.x + retr.width, retr.y + retr.height, + stringdata ); +#endif + return TRUE; +} + + +/*---------------------------------------- + * ޥåץǡ롣 + * + * charaindex int Υǥå + * ֤ + * TRUE(1) + * FALSE(0) + ----------------------------------------*/ +BOOL MAP_sendArroundChar(int charaindex) +{ + int fd; + fd = getfdFromCharaIndex( charaindex ); + if( fd == -1 )return FALSE; + + return MAP_sendArroundCharNeedFD(fd, charaindex); +} +#ifdef _MO_LNS_NLGSUOXU +static int YCXX[] = {39,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,43,43,43,43,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,90,90,90,90,90,90,91,91,91,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,93,93,93,93,93,93,94,94,94,94,94,94,94,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,99,99,99,99,99,99,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,103,103,103,103,103,104,104,104,104,104,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,107,107,107,107 +}; + +static int YCXY[] = {39,39,40,64,65,66,76,77,78,40,41,63,66,67,73,74,75,79,82,83,40,61,62,68,70,71,72,80,81,83,39,60,69,83,40,60,83,41,47,59,63,64,65,66,67,68,69,70,71,72,78,82,40,47,48,60,63,73,76,77,78,81,39,40,44,45,46,49,60,63,74,76,78,82,40,45,46,47,48,50,60,63,75,78,83,40,48,51,55,59,60,62,78,84,40,49,50,52,55,56,57,58,61,79,85,40,50,52,54,60,72,73,75,80,81,86,40,48,49,50,51,52,53,60,72,76,77,82,87,40,47,48,49,50,51,52,59,72,78,83,88,89,90,40,52,58,72,78,84,91,92,93,40,52,57,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,79,85,94,95,96,40,53,57,60,73,77,80,86,97,98,99,108,109,110,40,54,57,59,72,77,78,81,87,91,92,100,107,108,109,110,111,40,54,57,59,71,77,79,82,83,88,89,90,93,98,99,101,102,103,104,105,106,107,111,112,113,39,54,57,58,59,60,61,62,63,64,65,66,70,76,77,80,84,94,95,96,97,100,101,106,112,114,38,53,56,57,60,67,71,75,77,79,85,86,93,94,99,100,101,102,106,112,114,37,53,55,56,57,61,68,72,73,74,75,76,77,78,87,88,91,92,95,96,97,98,101,103,106,112,115,120,34,35,36,53,54,62,69,73,77,89,90,102,103,106,113,116,119,121,34,52,53,54,63,68,72,77,89,90,102,103,106,113,117,118,120,34,39,48,49,50,51,52,53,63,68,69,70,71,77,90,91,102,104,105,106,113,118,119,34,39,40,41,46,47,48,49,50,51,63,67,68,77,90,92,93,94,95,96,102,104,105,106,107,112,113,118,119,34,39,42,45,46,51,63,66,72,73,74,77,91,92,93,96,99,100,101,102,103,104,107,112,114,118,34,39,43,44,45,51,64,70,71,75,77,93,95,98,102,107,108,109,110,111,112,115,118,35,39,45,51,52,53,65,69,75,77,93,94,97,103,112,115,119,121,36,39,45,53,54,66,67,68,75,77,92,93,96,97,98,99,100,101,104,112,115,119,121,36,37,38,39,40,45,54,67,75,77,91,93,95,96,100,105,108,109,110,111,112,113,114,115,116,117,118,120,121,40,45,55,75,78,90,93,94,96,99,106,108,114,115,119,120,121,41,45,56,57,58,75,79,90,93,96,98,107,114,115,119,44,55,56,57,59,76,80,85,86,87,89,92,93,96,98,111,112,113,114,115,118,41,42,43,54,57,60,61,77,81,84,87,89,91,93,96,97,111,115,117,118,119,120,121,41,42,43,54,58,59,60,61,62,63,64,78,81,83,87,88,90,93,96,111,116,117,120,41,44,52,53,54,64,65,79,80,83,86,87,89,93,95,96,112,117,45,52,64,66,79,80,83,84,85,86,87,88,89,90,91,92,93,94,96,113,114,117,45,49,50,51,64,66,69,70,71,72,75,76,78,79,80,81,84,86,88,93,96,113,118,45,49,64,66,68,72,73,74,77,78,81,82,83,84,86,88,89,90,91,92,96,111,112,119,45,48,64,66,68,79,81,83,85,86,87,88,91,93,96,105,106,107,108,109,110,111,119,45,46,47,64,65,66,67,79,80,81,82,87,90,94,96,102,103,104,109,119,64,65,78,81,82,87,90,94,96,98,99,100,101,102,105,109,118,64,65,78,79,80,81,82,87,90,94,95,97,100,106,108,109,110,111,112,113,114,115,117,63,64,65,81,87,90,93,95,96,99,106,108,115,116,62,63,64,65,66,81,87,89,90,91,92,95,97,98,106,107,108,116,62,65,66,81,86,87,89,91,96,97,116,61,66,67,81,85,87,89,92,97,98,116,62,64,67,68,81,84,87,88,93,97,98,99,116,62,63,65,68,69,81,83,86,88,94,97,98,99,63,66,70,81,82,86,87,93,97,98,99,63,64,67,80,81,85,93,97,98,99,64,65,68,69,80,81,84,85,93,97,98,99,64,65,69,80,81,82,83,84,94,95,96,97,98,99,69,80,81,82,84,97,98,70,80,81,82,84,96,98,70,71,72,73,74,75,76,80,81,82,84,96,98,73,74,75,76,77,80,82,84,95,97,98,73,80,82,84,94,96,73,80,82,83,95,98,71,72,80,82,83,91,92,94,96,97,70,81,82,90,93,96,69,81,83,89,95,69,83,84,88,94,69,85,86,87,94,70,80,81,82,83,93,94,95,96,71,72,73,74,75,76,77,78,79,80,84,89,90,91,92,94,85,86,87,88 +}; + +static int JJXX[] = {54,55,55,56,56,56,56,57,57,57,58,58,58,58,58,58,58,58,59,59,59,60,60,60,60,60,60,60,61,61,61,61,61,61,62,62,62,62,62,63,63,63,63,63,63,64,64,64,64,64,65,65,65,65,65,65,65,65,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,74,74,74,74,74,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,77,77,77,77,77,77,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,91,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,93,94,94,94,94,94,94,94,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,98,98,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,99,99,99,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,103,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,107,107,107,107,107,107,107,108,108,108,108,109,109,109,109,109,110,110,111,111,111,111,111,111,111,112,112,113,113,113,114,114,115 +}; + +static int JJXY[] = {107,106,107,98,99,100,106,99,101,105,100,101,102,103,104,115,116,117,103,114,118,102,104,112,113,114,119,123,101,104,112,120,122,124,99,100,103,112,121,96,97,98,103,112,118,96,103,112,117,119,95,103,111,116,117,118,119,120,95,104,110,115,124,95,104,108,109,110,111,112,113,114,123,95,105,106,107,108,109,110,122,90,91,92,94,121,89,93,113,114,115,116,117,118,119,120,88,92,94,112,89,90,92,94,102,103,104,105,106,107,111,91,92,94,101,107,111,94,100,101,107,111,56,57,58,94,99,102,103,107,110,56,59,94,103,107,110,56,60,94,103,107,110,56,60,94,103,107,110,57,60,95,96,97,98,99,100,101,102,103,107,110,58,61,93,94,95,96,107,111,58,61,92,96,97,98,108,111,59,61,78,79,92,99,109,111,60,62,77,80,92,100,109,111,61,62,75,76,81,82,93,100,110,62,63,74,83,94,100,110,63,64,73,84,95,99,111,63,65,71,72,85,86,96,99,112,63,66,67,68,70,87,88,89,90,91,92,95,98,113,62,69,89,90,92,93,94,95,96,97,114,62,86,87,88,115,62,87,93,94,95,96,97,116,62,66,88,93,94,95,96,116,62,65,67,68,88,93,94,95,116,62,65,69,88,89,92,115,62,65,70,90,91,115,62,65,70,90,91,92,104,105,106,107,108,114,63,64,65,66,70,87,88,89,93,103,108,113,66,67,70,87,88,89,94,95,101,102,106,107,108,113,67,68,70,85,87,88,89,90,96,100,106,113,68,70,84,86,91,97,98,99,100,101,102,106,114,70,83,87,88,92,98,103,104,106,114,70,74,75,84,89,90,91,93,97,105,106,114,70,73,76,84,92,94,96,105,107,114,70,73,77,85,93,94,95,104,108,109,110,111,112,114,69,73,78,79,84,86,96,97,104,113,114,69,73,80,82,83,85,86,98,104,68,73,80,81,86,99,103,68,73,100,103,68,72,101,102,103,68,71,64,65,66,67,68,69,70,66,67,66,67,68,66,67,66 +}; + +static int KLXX[] = {34,35,36,36,36,36,36,37,37,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,40,40,40,40,40,40,41,41,41,41,41,42,43,44,45,46,47,48,49,49,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,90,90,90,90,90,90,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,95,95,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,98,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,100,100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,103,103,103,103,103,104,104,105,105,106,106,106 +}; + +static int KLXY[] = {62,62,62,71,72,73,74,61,62,69,70,75,77,60,61,63,64,65,66,68,75,76,77,78,59,60,63,64,65,66,67,68,69,70,71,72,73,74,78,59,62,63,64,65,66,60,61,62,63,64,61,61,61,61,61,61,61,60,61,59,60,61,58,59,61,66,67,68,92,93,105,109,110,111,112,47,48,57,62,65,66,69,70,71,72,93,94,95,101,102,103,104,105,106,107,109,112,113,48,49,50,51,52,53,54,55,56,57,59,60,61,62,63,64,65,66,67,68,69,70,71,72,93,95,96,102,103,104,107,109,110,114,37,48,49,58,63,65,70,93,96,97,103,105,106,107,108,109,110,111,112,114,37,38,47,48,58,59,62,64,65,70,71,93,96,106,110,112,114,37,62,63,70,71,93,96,107,110,113,114,37,38,70,71,93,94,95,106,107,108,109,110,111,112,114,38,70,71,92,93,106,107,109,112,114,37,38,39,71,93,94,105,106,107,109,113,33,34,35,36,37,39,40,41,69,70,72,93,94,105,106,110,111,112,35,37,40,41,42,43,54,55,68,73,74,93,94,105,106,34,37,38,42,43,44,45,46,54,55,68,74,75,93,94,105,35,37,46,55,68,76,93,94,105,36,37,38,47,48,49,50,51,52,53,54,55,56,68,77,78,79,92,93,94,105,37,48,54,57,68,79,92,94,105,37,38,48,57,58,68,79,90,91,92,93,94,95,104,105,38,39,48,58,59,68,69,73,79,88,89,91,92,94,96,104,105,39,48,58,59,60,61,62,63,64,65,66,67,69,70,72,74,79,88,91,92,93,94,95,97,103,104,105,106,39,40,41,42,48,58,59,60,61,62,63,64,65,66,67,68,69,70,71,74,78,79,89,91,92,94,95,98,100,101,102,106,48,58,59,60,71,72,73,74,75,76,77,78,87,88,89,90,92,94,96,99,106,48,58,59,71,72,73,74,75,77,78,79,80,81,82,83,84,85,86,87,92,94,96,107,48,58,59,72,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,108,109,110,111,47,58,85,86,87,88,92,95,96,110,48,58,84,85,89,90,91,97,109,48,53,58,85,86,97,108,49,53,58,85,86,87,88,96,97,98,107,50,53,58,84,87,95,96,99,100,107,50,52,53,58,84,86,95,96,101,107,50,52,53,57,58,84,86,95,96,97,98,102,103,104,105,106,107,108,109,110,50,52,53,54,55,56,57,59,84,85,86,96,97,100,101,102,50,53,54,56,57,58,59,60,61,84,85,97,98,99,102,49,56,61,62,63,84,85,97,98,101,49,56,61,64,65,84,85,97,98,99,101,48,62,65,85,97,98,100,48,62,65,85,97,100,44,45,46,47,63,65,96,98,100,45,63,65,95,96,98,99,100,46,63,65,93,94,95,96,97,99,100,47,64,65,93,94,95,99,101,48,63,65,95,99,101,49,63,65,96,99,100,50,51,62,65,69,70,71,72,96,97,98,99,52,57,58,59,60,61,65,69,73,74,75,82,83,84,96,97,98,53,54,55,56,64,65,68,75,76,77,78,79,80,81,85,96,97,62,63,67,70,71,72,86,96,97,62,65,66,70,73,80,81,82,83,87,96,63,64,67,68,69,70,74,75,76,77,78,79,84,85,88,63,69,70,74,75,76,77,79,80,81,82,86,88,62,63,69,70,71,72,74,87,88,62,69,70,86,88,61,62,69,70,86,87,61,62,69,85,87,61,69,84,85,86,61,69,69,70,70,71,72 +}; + +static int SCXX[] = {27,27,27,27,27,28,28,28,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,31,31,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,34,34,34,34,35,35,35,35,35,35,36,36,36,36,36,36,36,36,36,36,36,36,37,37,37,37,37,37,37,37,38,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,47,47,47,47,47,48,48,48,48,48,48,48,49,49,49,49,49,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,67,67,67,67,67,67,67,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,90,90,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,94,94,94,94,94,94,94,94,94,94,94,95,95,95,95,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,99,99,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,112,112,112,112,112,112,112,112,112,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,117,117,117,117,117,117,118,118,118,118,118,118,118,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120,120,120,120 +}; + +static int SCXY[] = {67,68,69,70,71,65,66,72,64,73,78,79,80,81,82,83,84,85,53,54,55,56,57,58,59,60,61,62,63,74,75,76,77,85,52,86,51,87,51,60,61,73,74,75,88,51,59,61,74,75,76,77,78,79,80,81,89,51,58,62,75,82,90,47,48,49,50,51,57,62,75,83,86,87,90,49,56,62,76,83,85,86,90,49,55,62,76,83,85,90,49,54,61,76,82,85,90,49,54,61,76,81,85,86,90,48,49,54,61,73,74,75,76,77,78,79,80,81,85,87,90,48,54,62,73,76,85,88,90,48,54,62,72,76,85,89,90,48,54,55,56,63,66,67,68,69,70,71,76,77,85,90,91,48,57,64,65,66,78,86,90,91,48,58,59,79,87,90,91,48,60,80,88,91,48,61,62,63,64,81,89,48,65,82,90,101,48,66,83,91,100,102,110,48,66,84,92,93,99,103,108,109,111,48,66,84,85,94,98,103,107,112,48,66,83,90,95,96,97,103,106,113,47,66,82,89,103,105,113,119,120,121,47,66,82,88,104,114,118,122,47,66,82,87,90,91,92,93,94,95,96,97,98,99,100,115,116,117,123,124,47,66,82,86,91,92,101,102,103,104,105,106,107,108,124,46,65,83,84,85,93,101,102,109,124,45,64,82,83,84,94,100,103,110,111,112,113,114,115,116,117,118,119,120,124,44,63,81,82,85,94,99,104,112,113,114,115,116,117,118,124,43,62,83,86,87,88,89,90,91,92,93,94,95,96,97,98,104,105,106,107,108,109,112,124,42,55,56,57,58,59,60,61,84,85,94,104,110,111,124,41,54,76,77,78,79,80,81,86,94,124,40,52,53,75,82,87,94,125,39,46,47,48,49,50,51,75,83,88,94,126,39,46,75,84,89,94,127,39,45,75,84,89,94,128,39,45,74,84,89,94,128,39,45,49,50,51,52,53,54,55,56,74,84,90,94,127,38,44,50,57,73,85,86,90,94,126,37,44,51,58,72,87,90,94,95,125,36,43,51,59,72,88,91,96,125,35,43,52,60,72,89,92,97,125,35,43,53,61,62,63,72,89,93,94,98,125,35,38,43,52,53,63,64,72,74,75,76,77,78,89,94,99,125,35,38,43,51,65,66,71,73,79,89,95,96,100,125,35,38,39,43,50,67,71,72,80,89,97,98,101,102,103,104,125,35,38,39,43,49,68,70,72,80,90,99,105,125,35,38,39,43,49,68,69,72,81,91,100,106,125,35,38,40,43,49,68,69,72,81,92,101,106,124,35,38,41,42,49,68,69,72,81,93,98,99,100,101,102,106,124,34,38,39,49,68,72,73,81,93,96,97,106,123,32,33,39,49,68,73,81,93,94,95,106,120,121,122,31,39,48,49,67,73,81,92,93,107,120,31,38,47,59,60,61,62,63,64,65,66,74,81,90,91,92,97,98,99,107,120,31,32,37,38,39,40,41,42,43,44,45,46,50,51,52,53,54,55,56,57,59,66,75,76,77,78,79,80,81,82,88,89,90,91,96,100,108,120,32,49,50,58,59,65,79,83,84,95,101,102,103,104,105,106,107,109,120,33,43,44,45,46,47,48,62,63,64,78,85,86,87,88,89,90,91,92,93,94,108,110,119,34,35,43,61,62,77,109,111,112,113,118,35,43,60,76,110,113,118,34,42,59,76,111,113,118,34,41,55,56,58,76,111,112,118,35,40,43,44,45,46,47,48,54,57,76,83,84,85,111,118,35,39,41,42,49,50,54,76,82,86,117,34,38,39,40,51,54,76,80,81,87,116,34,52,54,76,77,78,79,87,116,33,53,54,76,87,116,33,53,54,76,87,116,33,53,54,75,76,87,116,117,127,128,129,33,53,54,55,74,77,88,117,118,119,120,121,122,123,126,129,32,54,55,64,65,73,77,89,90,91,124,125,129,32,53,54,65,72,77,92,93,94,95,96,97,98,99,100,101,102,124,125,126,127,128,31,53,54,66,71,77,78,103,124,31,53,54,66,67,70,78,104,123,30,37,51,52,53,65,68,69,78,105,123,29,36,38,49,50,52,65,71,72,78,105,123,28,34,35,38,44,45,46,47,48,49,50,51,52,63,64,65,71,72,78,105,111,112,113,114,115,116,117,118,119,120,121,122,123,28,31,32,33,39,44,49,52,61,62,63,71,72,78,105,111,29,30,31,39,44,49,61,72,73,74,75,76,77,78,104,105,111,29,40,44,49,61,73,103,111,29,40,44,49,61,74,103,111,28,29,40,44,50,61,75,102,110,29,41,42,43,50,61,75,102,109,28,49,62,75,102,108,28,49,62,75,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,107,29,43,44,45,46,47,48,62,64,65,66,67,68,69,70,71,72,73,74,75,86,107,29,42,62,64,86,107,29,30,41,62,64,87,107,31,32,33,34,35,40,62,64,65,66,67,68,69,70,87,107,32,33,34,35,36,37,38,39,40,58,62,70,88,107 +}; + +static int FCXX[] = {28,29,29,29,30,30,31,31,31,31,31,32,32,32,32,33,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,34,35,35,35,35,35,35,35,35,35,35,36,36,36,36,37,37,37,37,37,38,38,38,38,38,38,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,53,53,54,54,54,55,55,55,55,55,56,56 +}; + +static int FCXY[] = {33,33,34,37,35,36,35,51,52,53,54,35,36,50,54,34,36,37,38,39,40,50,54,33,34,40,41,42,43,50,53,54,33,34,43,44,48,49,50,51,52,53,33,34,51,52,33,34,52,53,54,34,35,52,53,55,56,34,35,51,52,53,54,56,27,28,29,32,33,36,51,54,56,58,59,29,30,31,37,51,52,54,56,59,29,32,33,34,35,36,38,47,48,49,50,51,52,53,54,56,59,60,61,62,29,32,36,38,44,45,46,47,49,50,51,53,56,57,58,59,60,61,23,24,25,28,29,31,36,38,43,45,46,47,48,49,50,51,53,54,55,56,59,61,22,26,27,28,29,30,32,36,39,40,41,42,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,20,21,22,23,26,27,31,32,33,34,35,36,39,40,41,42,43,44,47,48,49,51,55,56,57,60,23,27,32,35,36,37,38,42,47,49,50,51,55,56,57,60,23,26,31,32,33,34,35,40,41,48,49,50,51,59,60,23,25,29,30,31,36,37,38,39,59,23,25,26,27,28,29,30,31,32,33,34,35,36,37,23,24,25,29,33,34,35,23,26,28,29,30,31,32,23,26,22,25,26,22,23,24,25,26,25,26 +}; + +static int QGGXX[] = {42,42,42,42,42,42,42,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,63,63,63,64,64,65,65,65,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,69,69 +}; + +static int QGGXY[] = {52,53,54,55,56,58,59,52,55,57,58,59,51,52,53,54,55,56,57,59,61,62,50,51,58,59,60,62,49,50,58,59,62,48,49,59,61,64,65,66,67,68,71,72,73,74,75,83,49,50,59,61,64,69,70,76,78,79,80,81,82,43,44,45,46,47,49,51,59,62,63,68,69,70,71,72,73,74,75,76,77,80,43,48,51,59,66,67,68,70,71,72,73,74,75,76,77,78,79,43,50,52,58,59,60,61,63,64,65,69,79,43,49,50,52,53,54,55,56,57,58,61,62,68,79,80,42,51,52,55,56,58,67,68,79,80,81,42,51,52,53,54,56,57,58,67,79,81,42,50,52,54,55,57,58,59,67,79,80,81,43,44,49,50,51,53,56,59,67,79,45,48,51,52,53,54,55,58,66,79,42,43,44,47,48,51,52,58,66,68,74,75,76,77,78,42,43,44,45,46,48,50,51,58,66,68,69,72,73,42,44,45,46,47,48,49,50,58,66,67,70,72,42,45,46,49,50,58,66,70,72,43,44,47,48,50,58,71,48,51,58,52,58,52,57,58,52,55,56,57,58,59,60,50,51,52,53,54,55,59,60,61,62,50,54,55,56,57,58,61,54,57 +}; + +static int DNXX[] = {22,23,23,23,24,24,25,25,26,26,26,26,27,27,27,27,27,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,31,31,31,31,31,32,32,32,32,32,33,33,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,35,35,35,35,35,35,35,35,35,36,36,36,36,36,36,36,36,36,36,36,36,36,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,44,44,44,44,44,45,45,45,45,45,45,46,46,46,47,47 +}; + +static int DNXY[] = {33,32,33,34,31,35,31,36,31,32,36,37,31,33,34,35,37,31,33,34,37,30,33,34,35,36,39,26,27,28,29,30,34,35,36,37,38,39,40,31,37,40,41,42,32,37,39,40,42,28,31,36,37,38,39,40,41,43,28,29,30,35,36,40,42,44,31,34,35,36,40,42,44,47,48,30,32,34,35,36,40,41,42,43,44,45,46,48,29,31,32,33,34,36,37,38,39,40,41,42,43,44,45,46,47,29,33,34,35,36,37,39,40,41,42,44,45,46,48,29,30,31,32,33,34,37,38,39,41,43,44,45,46,47,48,49,51,52,31,32,34,37,38,39,40,43,44,45,46,49,50,51,32,33,34,37,38,39,40,41,42,43,44,45,46,48,49,50,51,32,33,37,38,39,41,44,48,49,50,51,37,38,39,41,51,36,38,39,40,41,36,37,38,39,40,41,37,38,40,38,39 +}; + +static int KAXX[] = {32,33,34,34,34,34,34,34,35,35,35,35,35,35,35,35,35,35,35,36,36,36,36,36,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,91,91,91,91,91,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,94,94,94,94,94,94,94,94,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,100,100,100,100,101,101,101 +}; + +static int KAXY[] = {65,65,60,61,62,63,64,66,37,38,39,40,41,42,43,44,45,59,67,36,46,58,68,69,35,47,58,70,35,48,58,60,61,62,63,64,65,66,71,35,48,58,60,67,72,99,100,101,35,48,58,60,68,73,98,101,35,48,58,60,61,69,74,97,102,34,49,58,60,61,62,67,70,74,96,97,102,34,50,51,57,60,61,63,66,68,71,75,89,90,91,92,93,94,95,96,97,102,33,48,52,53,54,55,56,60,61,64,65,69,72,76,90,96,98,99,100,101,32,38,39,40,41,42,43,46,47,49,59,61,64,65,70,73,76,82,83,91,96,33,34,37,44,45,50,53,54,55,56,57,58,61,64,71,74,77,78,79,80,81,84,88,89,90,91,96,35,36,50,52,61,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,85,87,91,92,97,104,105,106,107,108,38,39,40,41,50,52,61,64,73,76,79,86,93,98,103,108,37,39,42,50,51,61,65,73,77,78,94,99,101,102,107,37,39,40,41,42,43,44,45,46,47,50,52,61,66,73,77,78,81,94,100,102,106,116,37,40,43,48,50,52,55,56,57,61,65,73,76,79,81,95,101,103,105,114,115,116,37,40,43,49,50,52,53,55,58,61,64,74,75,80,81,95,100,104,112,113,115,38,40,44,49,51,52,55,58,61,63,74,75,76,81,96,100,111,115,38,40,44,48,49,51,55,59,61,62,73,77,81,96,100,104,105,106,107,108,109,110,115,116,37,40,44,48,49,51,52,53,54,55,59,61,62,73,78,81,96,100,103,117,36,40,41,44,48,49,59,60,63,69,72,77,81,96,100,102,116,37,40,45,47,50,58,60,62,68,69,73,76,81,96,99,101,110,116,38,39,40,41,42,43,44,45,46,51,52,53,54,55,56,57,59,62,67,70,74,75,80,81,95,98,100,110,115,40,45,58,62,66,69,74,75,79,90,91,92,93,94,98,100,110,111,114,36,40,41,42,43,44,45,46,47,57,62,65,68,74,76,77,78,90,98,100,110,111,114,36,37,44,47,48,49,50,51,52,53,54,55,56,61,64,67,74,76,78,90,99,101,111,113,36,38,42,43,46,47,53,54,55,56,57,58,59,60,61,63,66,73,76,79,90,99,101,102,111,112,113,36,39,40,41,46,47,52,62,67,69,70,71,72,77,80,81,82,90,100,101,102,112,113,37,41,45,47,51,60,61,68,77,82,83,84,85,86,87,88,89,90,101,102,112,38,45,48,50,59,68,69,70,71,72,73,74,75,76,77,78,88,89,90,91,92,93,94,95,96,97,102,103,113,39,40,44,48,50,58,63,67,70,78,79,80,88,97,102,104,105,106,107,108,109,110,114,37,40,41,43,44,47,50,56,57,58,62,64,65,66,70,79,80,81,88,97,98,102,110,114,37,38,39,41,42,43,44,47,50,51,52,53,54,55,56,61,64,65,70,80,81,82,88,99,102,110,114,37,38,39,40,44,46,47,49,50,57,58,59,60,63,66,70,81,82,83,84,85,88,90,91,100,102,110,114,40,41,42,43,44,45,47,48,49,55,56,62,67,70,81,83,85,86,87,90,91,99,102,110,114,35,41,43,45,46,49,53,54,63,67,70,80,84,85,87,90,91,97,98,99,102,107,110,114,35,37,38,39,40,41,42,46,49,54,63,67,71,79,85,86,87,89,91,94,95,96,103,106,108,109,111,114,35,36,37,39,40,41,46,49,55,63,67,72,79,84,85,86,87,88,91,93,94,103,104,105,109,112,115,46,50,56,63,67,73,75,79,83,87,91,95,96,97,98,99,100,101,109,113,116,46,51,52,57,64,68,74,75,76,79,82,88,89,90,91,101,109,112,115,117,47,53,58,65,69,74,75,77,78,79,81,84,85,86,87,88,89,90,91,96,97,98,101,106,107,108,109,110,111,112,113,114,118,119,120,47,54,59,60,65,70,74,75,80,83,90,91,95,99,101,105,109,111,113,120,47,53,54,55,56,57,61,65,71,74,75,79,82,90,95,100,101,105,109,110,112,115,116,120,47,52,54,58,62,65,71,74,75,76,77,78,81,90,94,101,105,108,110,111,112,113,114,117,121,47,51,53,59,63,65,71,73,77,80,90,92,93,96,97,98,101,105,107,110,111,117,121,46,50,51,52,60,64,65,70,72,73,77,80,90,91,92,93,96,99,105,106,109,110,111,112,113,114,115,116,117,121,46,54,55,56,57,61,65,69,71,73,77,80,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,107,108,120,46,51,52,53,58,62,68,70,72,76,80,86,90,95,96,99,100,101,105,107,108,118,119,120,46,48,49,50,59,63,67,69,71,75,81,85,90,96,98,99,101,104,106,109,117,46,47,60,63,64,65,66,68,71,74,76,77,78,79,80,81,84,89,97,99,100,102,103,104,105,109,116,60,63,67,70,72,73,74,75,76,77,81,82,83,87,88,96,99,101,102,109,116,60,64,65,66,69,73,86,96,101,108,116,61,62,63,68,74,75,86,97,100,107,116,61,62,67,75,86,98,99,100,107,116,62,67,76,86,87,89,90,91,92,93,94,95,96,97,98,107,116,63,67,76,86,87,88,107,111,112,113,114,115,63,64,67,76,85,86,87,88,107,110,64,67,76,84,87,107,109,64,65,66,75,83,88,107,109,63,66,72,73,74,80,81,82,83,84,85,86,87,88,108,109,62,65,67,68,69,70,71,79,82,108,109,62,63,64,70,72,77,78,80,81,61,62,63,70,71,73,77,79,61,62,72,73,74,75,76,77,78,61,62,73,77,74,75,76 +}; + +static int TMXX[] = {33,33,34,34,34,34,34,34,35,35,35,35,35,35,35,35,35,35,35,35,35,36,36,36,36,36,36,36,36,36,36,37,37,37,37,37,37,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,73,73,73,73,73,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84 +}; + +static int TMXY[] = {78,85,58,77,79,84,85,86,56,57,58,74,75,76,80,81,83,87,88,89,90,57,58,73,74,82,86,87,88,90,91,57,59,60,61,62,63,73,85,89,91,57,59,64,65,66,67,68,69,70,71,72,77,78,79,80,81,82,83,84,90,91,57,61,74,75,76,84,85,91,55,56,57,60,61,74,84,86,92,51,52,54,55,59,61,74,84,87,88,48,55,58,61,73,84,88,47,48,55,57,61,72,84,88,47,48,56,57,61,71,84,88,47,48,56,57,61,71,84,88,47,48,57,58,60,61,71,84,88,42,43,44,47,57,59,60,61,62,63,64,65,66,67,71,79,80,81,82,83,84,85,86,87,89,39,40,41,44,45,46,47,48,49,50,51,52,53,54,55,56,61,67,71,79,80,81,83,84,90,39,61,67,71,79,81,82,85,90,36,37,38,47,48,49,50,51,60,67,70,78,79,81,86,87,90,37,46,47,48,49,51,52,59,63,64,65,66,67,70,78,79,81,87,91,37,41,45,49,50,51,52,57,58,62,67,68,69,70,71,72,73,74,75,76,78,79,80,81,88,91,37,40,41,42,44,49,52,53,54,57,61,67,70,76,79,80,81,82,89,91,35,36,38,39,40,41,42,43,44,45,48,49,52,53,54,55,57,60,62,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,82,90,92,35,39,40,41,43,44,45,46,47,48,49,50,51,54,55,57,60,63,65,67,71,74,77,78,80,81,82,91,92,35,38,39,40,42,48,49,50,51,54,55,57,58,59,64,67,71,73,76,77,81,91,92,33,34,37,38,39,40,41,48,51,52,53,54,55,56,57,58,63,64,65,67,71,73,75,80,91,92,33,36,37,38,39,40,49,52,55,56,57,58,67,68,69,70,71,72,73,74,78,79,80,92,33,34,35,36,37,38,40,49,50,55,56,57,70,71,72,73,76,77,82,83,84,85,86,87,92,33,37,38,39,40,41,49,50,52,55,56,57,69,70,72,73,74,75,80,81,87,33,37,38,39,40,41,48,50,51,52,53,54,55,56,57,58,69,72,73,74,75,78,79,80,87,33,34,38,39,42,48,49,50,51,52,53,54,55,57,68,69,76,77,87,34,35,37,38,39,40,41,42,44,45,46,47,48,49,50,54,55,56,57,68,69,77,78,84,87,35,38,39,40,41,42,43,44,45,48,53,57,58,68,77,79,80,84,85,88,34,40,41,42,44,45,46,51,52,57,58,68,69,77,80,83,85,89,90,91,31,32,33,40,42,43,44,50,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,69,77,79,83,85,86,88,30,31,39,40,41,42,43,48,49,52,59,62,67,77,78,82,86,88,30,33,42,43,44,45,46,47,48,49,50,51,59,63,67,76,77,81,86,87,88,30,31,32,60,64,68,75,76,77,80,81,85,86,61,65,69,70,71,72,73,74,75,76,77,79,80,81,82,83,84,86,62,66,73,76,77,78,84,85,86,63,67,73,78,82,86,64,68,71,72,78,65,69,70,71,78,66,70,71,72,73,74,75,76,77,78,79,80,66,68,69,70,71,72,73,74,75,76,77,78,79,80,67,68,70,71,75,79,68,69,70,71,72,73,74,75,80,68,71,74,76,78,80,81,68,72,75,77,79,82,83,84,85,68,69,70,71,72,73,76,78,79,80,82,83,86,68,72,81,82,83,84,86,73,74,75,76,77,78,79,80,81,86,73,74,82,83,84,85,86 +}; + +static int KTXX[] = {62,62,62,62,62,62,62,63,63,63,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,90,90,90,90,90,90,91,91,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,94,94,94,94,94,94,94,94,94,94,94,94,94,94,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,98,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,99,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,102,102,102,102,102,102,102,103,103,103,103,103,103,103,103,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,107,107,107,107,107,107,107,108,108,108,108,109,109,109,109,109,109,110,110,110,110,110,110,110,110 +}; + +static int KTXY[] = {90,91,92,93,94,95,96,90,96,105,90,96,97,98,99,100,102,104,105,88,89,90,91,92,100,102,103,105,106,109,110,83,84,85,86,87,88,90,91,99,102,104,105,106,107,108,109,82,87,90,99,102,105,108,110,111,112,81,87,90,98,99,100,101,103,105,106,107,109,112,74,75,76,77,78,79,80,84,85,86,87,91,97,100,102,104,105,110,112,74,75,83,85,88,89,92,96,100,102,104,105,110,111,112,113,114,115,75,77,78,82,85,90,91,92,93,94,95,96,100,101,103,104,105,106,107,108,109,110,111,113,114,115,75,77,79,80,81,82,83,84,91,94,96,97,98,99,100,101,102,103,108,109,110,113,114,115,75,77,80,91,94,97,99,100,101,102,103,104,105,106,107,110,111,112,113,75,78,80,91,94,96,100,101,110,112,113,116,73,74,78,79,92,95,99,100,106,109,110,113,114,115,116,72,76,77,78,91,94,96,98,100,107,108,110,112,113,114,116,71,75,76,77,80,81,82,83,84,85,86,87,88,89,90,93,95,97,99,106,107,110,114,116,71,74,75,78,79,92,94,96,97,98,105,106,111,112,115,117,71,73,74,75,79,80,81,82,83,84,92,95,96,98,104,105,111,112,113,115,117,71,74,85,86,87,88,89,90,91,93,95,96,97,98,99,100,111,113,115,117,72,74,91,92,94,95,97,98,99,101,111,113,115,117,72,74,84,85,86,87,88,90,94,95,96,97,98,99,100,101,102,111,113,114,116,117,72,74,83,89,94,101,102,103,104,105,106,107,108,109,111,113,114,115,116,71,72,73,74,80,81,83,88,90,94,95,96,97,99,100,101,102,104,105,110,111,112,113,114,115,70,71,74,79,82,83,84,85,86,87,89,90,91,92,93,94,102,103,104,105,108,109,110,111,115,69,70,71,72,73,74,75,76,78,82,83,85,88,89,90,94,102,104,105,106,107,108,109,111,115,67,68,75,76,77,78,79,80,81,86,94,102,104,107,109,110,111,112,113,114,116,67,77,78,85,87,88,89,90,91,95,101,102,104,107,109,114,115,116,67,77,78,85,92,95,100,102,103,104,105,106,109,67,76,77,78,85,93,95,100,103,108,109,67,77,85,93,95,100,102,107,108,67,68,69,70,71,72,73,74,77,85,94,95,100,101,102,103,104,105,106,107,75,86,94,95,100,102,106,75,79,80,81,82,83,87,94,96,99,100,101,104,105,74,75,76,77,78,79,84,88,94,96,98,99,100,103,104,106,85,89,94,96,97,99,102,103,107,85,89,94,95,98,99,100,101,102,103,104,108,86,88,94,95,96,97,98,101,102,103,105,106,109,86,88,93,97,101,102,106,107,108,109,86,87,88,89,90,91,92,93,94,95,96,97,98,99,101,102,109,86,87,93,101,110,85,88,92,93,94,101,110,85,86,87,88,89,90,91,100,85,86,88,89,91,92,93,98,99,100,85,86,87,88,89,90,91,92,93,94,95,96,97,98,83,84,85,89,94,95,96,98,82,83,84,85,96,97,98,80,81,82,83,76,77,78,79,81,83,75,76,77,78,79,80,81,83 +}; + + +static int WLXX[] = {44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,70,70,70,70,70,70,71,71,71,71,71,71,72,72,72 +}; + +static int WLXY[] = {63,64,65,66,40,41,42,43,44,46,47,48,52,53,54,55,59,60,61,62,67,68,39,40,44,45,49,50,51,55,56,57,58,68,38,39,44,45,46,47,48,49,50,51,57,58,59,64,65,66,68,37,38,41,42,43,45,51,55,56,60,61,64,66,67,68,37,39,40,41,42,43,44,45,52,55,61,67,68,37,43,53,55,61,67,68,69,70,72,73,74,75,76,37,44,51,52,53,54,61,67,71,77,37,44,51,52,53,55,61,67,77,36,44,46,50,51,55,56,57,58,59,60,61,66,67,68,69,70,71,72,73,74,75,77,35,44,45,47,48,49,50,51,56,57,61,62,63,66,67,76,77,35,44,45,47,51,54,55,57,61,64,65,76,35,44,45,46,47,48,49,50,51,52,53,58,60,61,62,63,64,65,76,77,35,43,44,47,50,51,53,54,55,56,58,59,60,61,63,65,76,77,36,43,44,45,46,48,49,51,52,53,55,56,57,61,62,64,66,71,72,73,74,75,76,77,36,37,42,43,44,47,49,51,53,54,57,58,61,62,65,67,70,72,73,77,37,38,39,40,41,42,43,49,50,52,53,54,55,57,62,65,68,69,71,74,75,76,77,37,38,39,40,41,43,49,53,54,55,57,62,65,66,67,69,71,39,42,43,49,50,51,52,53,54,55,57,62,64,65,69,71,39,40,41,48,51,53,55,56,57,62,65,66,69,71,40,47,48,50,51,52,53,54,56,57,58,59,60,61,62,66,67,68,71,47,49,50,51,52,54,56,57,68,69,70,45,46,47,48,49,50,51,53,55,57,43,44,45,46,48,49,52,53,54,57,58,42,43,44,45,46,47,48,49,50,51,53,54,55,56,42,45,46,49,50,43,44,45,47,48,49,43,44,46,47,48,49,43,45,49 +}; + +static int HETXX[] = {16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,21,21,21,21,21,22,22,22,22,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,35,35,35,35,35,35,35,35,35,35,35,35,36,36,36,36,36,36,36,36,36,36,36,36,36,36,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,39,39,39,39,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,72,72,72,72,72,73,73,73,73,73,73,73,74,74,74,74,75,75,75,75,76,76,77,77,77,77,77,77,78,78,79,79,80,80,80,81,81,81,82,82,82,82,83,83,83,83,83,83,83,84,84,84,84,84,84,85,85,85 +}; + +static int HETXY[] = {18,19,20,25,26,27,28,29,36,37,38,39,40,41,17,21,22,23,24,30,31,32,33,34,35,42,43,47,48,16,44,45,46,48,16,28,33,34,35,36,37,38,39,40,41,48,17,27,29,30,31,32,42,43,48,17,18,26,43,48,18,26,43,48,18,26,30,31,32,33,44,48,59,18,26,30,34,44,47,59,60,65,66,67,18,19,26,30,35,44,46,47,57,58,59,61,62,63,64,68,18,20,21,26,30,36,37,44,48,49,50,51,52,53,54,55,56,63,69,70,17,22,26,29,31,32,38,39,40,41,42,43,44,54,55,56,57,58,63,64,71,72,73,26,29,32,33,34,35,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,65,66,73,26,28,32,36,37,38,39,40,41,46,54,63,67,68,69,73,26,28,32,42,43,44,47,54,64,65,69,73,18,19,20,21,22,23,24,25,26,28,29,30,31,44,48,49,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,73,19,28,44,50,52,54,66,67,70,73,20,28,29,44,49,52,55,56,57,58,59,67,70,71,73,21,28,30,31,32,33,34,45,48,52,60,66,70,71,73,22,28,35,45,47,52,56,61,66,69,71,73,22,28,36,44,45,47,52,56,57,61,65,68,71,73,23,28,35,36,37,38,39,40,41,42,43,47,51,56,58,61,64,68,71,73,23,28,34,36,37,47,50,56,59,60,61,63,68,71,73,24,25,29,34,38,46,49,56,61,62,69,71,73,81,26,30,31,32,35,39,40,41,42,43,44,45,49,53,54,55,56,60,66,70,71,74,80,81,27,32,35,43,44,48,53,55,57,58,59,65,67,71,72,75,76,77,78,79,81,27,32,35,43,45,48,53,54,58,59,60,61,62,63,64,67,71,72,81,27,31,35,43,46,47,51,52,53,54,58,67,71,72,81,27,30,35,47,51,54,57,67,72,81,28,31,32,34,43,47,48,49,51,54,57,62,67,72,73,74,75,80,28,33,34,43,44,47,50,51,54,56,61,62,67,72,75,79,29,36,37,38,39,40,41,42,43,44,48,51,55,56,60,63,67,72,75,79,30,31,32,33,34,36,40,44,47,50,51,55,56,59,63,68,69,70,72,75,80,30,31,34,36,39,44,45,46,49,51,52,53,54,57,58,64,69,72,75,81,30,31,34,36,39,43,44,47,48,57,58,64,68,71,75,81,29,30,31,32,33,34,36,38,42,44,46,47,48,56,59,60,61,62,63,64,67,70,71,72,73,75,81,27,28,31,32,35,39,40,41,43,45,47,48,49,50,51,55,64,65,67,69,70,74,75,80,27,32,34,36,38,39,43,44,46,47,50,52,54,62,63,66,67,68,70,76,79,28,29,30,31,33,34,35,36,37,38,39,40,41,42,43,44,45,46,51,52,53,54,55,56,57,58,59,60,61,65,67,68,70,79,29,30,31,32,35,36,41,43,45,53,64,67,68,70,79,30,31,36,40,43,44,53,64,67,68,70,79,30,31,36,37,38,39,40,41,42,43,53,54,64,67,68,70,79,29,30,31,36,39,44,53,54,64,67,68,70,78,28,30,32,36,38,39,45,46,53,54,65,67,68,70,77,27,29,30,31,32,33,34,35,36,37,38,40,47,48,49,50,51,52,53,54,66,67,68,70,76,27,29,30,31,36,39,41,42,46,54,55,56,57,58,59,60,61,62,63,64,65,66,68,69,75,27,28,30,31,32,33,35,38,40,43,45,46,49,50,51,54,55,65,68,74,27,28,29,32,33,34,35,36,37,41,42,43,44,47,48,50,53,56,64,67,68,71,72,73,27,28,30,31,35,44,46,47,49,53,57,58,60,61,62,63,64,65,66,68,71,24,25,26,27,29,32,35,43,45,48,49,52,54,55,56,57,58,59,62,68,70,23,24,25,26,29,33,34,35,44,48,49,51,53,60,61,67,70,25,26,27,29,35,36,42,43,48,49,51,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,25,28,36,42,48,50,51,53,56,57,58,59,60,62,63,64,65,66,67,25,26,27,28,36,37,38,41,49,52,53,54,55,56,60,61,66,67,37,39,40,41,48,49,52,53,37,40,48,49,50,51,53,37,40,48,49,53,37,39,48,49,50,51,52,37,40,48,49,37,41,42,43,37,43,36,38,39,40,41,42,36,38,35,39,35,40,41,33,34,41,32,34,35,41,31,34,36,37,38,39,41,30,32,33,39,40,41,30,31,32 +}; + +static int DDXX[] = {30,31,31,32,32,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,36,36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,39,39,39,39,39,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,43,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,49,49,49,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,60,60,60,60,60,60,61,61,61,61,61,62,62,62,63,63,63,64,64,64,64,64,64,64,64,65,65,65,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,67,67,68,68,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,78,78,78,78,78,79,79,80,80,80,81,81,81,81,81,81,81,82,82,82,83,83,84,84,84,84,84,84,84,85,85,85,85,85,85,85,86,86,86,86,87,87, +}; + +static int DDXY[] = {46,45,46,44,45,44,46,49,50,51,52,44,45,47,48,50,51,53,45,46,47,49,52,53,45,48,52,53,45,46,47,48,49,51,52,44,45,50,51,52,43,44,45,50,52,45,50,51,52,45,49,50,53,54,55,56,57,58,59,62,63,64,65,69,70,71,72,45,48,57,58,59,60,61,62,66,67,68,72,73,74,75,45,47,58,59,63,66,67,76,77,45,46,59,63,64,76,45,51,52,53,54,58,60,63,65,75,76,45,50,55,58,60,64,65,76,44,46,49,55,58,63,64,65,66,76,44,47,49,56,57,63,65,67,76,44,47,48,49,50,51,56,57,62,65,67,76,45,48,50,51,52,53,54,55,56,57,58,63,65,67,68,69,70,74,75,46,47,48,49,50,58,59,60,61,62,63,64,65,68,69,74,41,42,43,46,48,49,51,56,59,60,61,62,65,66,67,70,71,72,73,75,76,77,41,43,45,46,47,50,51,52,55,57,58,67,68,72,73,74,76,77,40,41,43,44,46,47,50,51,53,54,68,69,73,76,41,42,43,48,50,52,58,59,70,71,73,75,42,43,44,49,50,52,57,59,71,72,73,75,44,45,46,47,48,49,50,51,53,56,59,70,73,74,75,45,46,50,52,53,55,58,59,69,73,75,47,48,49,50,53,54,58,69,50,53,54,56,57,69,50,51,52,55,69,51,52,69,51,52,69,51,52,66,67,68,69,70,71,52,64,65,68,69,70,71,72,73,74,75,76,52,61,62,63,66,67,68,75,52,61,50,51,52,53,54,55,56,57,58,61,50,51,53,54,55,56,57,59,61,49,50,52,53,54,55,56,57,58,60,61,41,47,48,49,52,54,57,59,60,41,42,45,46,47,48,50,51,53,54,55,56,57,58,59,60,42,43,44,49,51,52,54,55,57,59,60,42,43,49,51,52,55,58,60,42,44,49,50,51,52,55,57,58,60,42,44,49,50,52,55,56,58,60,43,44,49,50,51,55,58,59,43,44,55,58,61,58,61,58,59,61,55,56,57,58,59,60,61,54,55,58,53,59,52,53,56,57,58,60,61,51,52,54,55,58,59,60,52,53,58,59,57,58, +}; + +static int SMDXX[] = {17,17,17,17,17,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,34,34,34,34,34,34,35,35,35,35,35,35,36,36,36,36,36,36,36,36,36,36,36,36,37,37,37,37,37,37,37,37,37,37,37,38,38,38,38,38,38,39,39,39,39,39,39,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,43,43,43,43,43,43,44,44,44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45,45,46,46,46,46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47,47,47,47,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,50,50,50,50,50,50,51,51,51,51,51,51,52,52,52,52,52,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,60,60,60,60,60,61,61,61,61,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,65,65,65,65,65,65,66,66,66,66,66,66,67,67,67,67,67,68,68,68,68,68,68,68,68,69,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,82,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,89,89,89,89,89,89,89,89,89,89,89,90,90,90,90,90,90,90,90,90,90,91,91,91,91,91,91,91,91,91,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,94,94,94,94,94,94,94,94,94,95,95,95,95,95,95,95,95,95,95,95,95,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,97,97,97,97,97,97,97,97,97,97,97,97,97,98,98,98,98,98,98,98,98,98,98,98,98,99,99,99,99,99,99,99,99,99,99,99,99,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,118,118,118,118,118,118,118,118,118,118,118,118,118,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,122,123,123,123,123,123,123,123,123,123,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,129,129,129,129,129,129,129,129,129,129,130,130,130,130,130,130,130,130,130,131,131,131,131,131,131,131,132,132,132,132,133,133,133,133,133,133,133,133,133,133,134,134,135,135,135,135,135,135,135,135,135,135,135,135 +}; + +static int SMDXY[] = {81,82,83,84,85,78,79,80,86,100,101,76,77,87,88,89,90,91,99,102,74,75,78,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,103,72,73,77,79,80,83,93,103,70,71,76,81,82,94,103,69,75,95,99,100,101,104,69,75,95,100,102,105,106,68,76,95,100,103,107,108,109,67,75,76,95,101,104,109,67,74,95,96,97,98,99,102,105,109,66,74,99,103,105,110,66,69,70,71,72,73,74,99,104,105,111,112,113,114,65,66,67,68,99,104,106,115,64,65,100,104,107,108,109,110,111,116,63,64,100,104,111,117,118,62,64,101,104,111,119,120,121,61,64,101,104,111,120,60,64,100,104,111,119,54,55,56,57,60,64,100,105,111,114,115,119,54,58,59,63,99,106,111,112,113,115,119,53,62,99,107,115,119,52,61,100,108,115,119,51,60,101,102,109,115,120,50,59,103,110,115,121,122,123,49,58,104,105,110,115,124,48,57,105,110,115,125,47,56,106,110,114,115,116,117,118,125,43,44,45,46,56,107,110,119,124,41,42,50,51,52,53,56,107,111,120,123,40,48,49,53,54,55,56,107,111,119,122,38,39,41,42,43,44,45,46,47,56,107,112,118,121,36,37,40,107,112,116,117,120,35,39,107,112,115,119,34,39,107,112,114,119,31,32,33,34,35,36,37,38,39,108,112,114,119,30,31,108,111,114,118,119,29,31,107,111,114,117,21,22,23,24,28,31,106,111,114,116,20,24,26,27,28,29,30,31,32,106,111,113,115,21,23,25,26,105,111,113,115,22,23,24,25,105,110,112,115,21,22,105,109,110,111,115,21,106,108,110,115,21,107,111,114,18,19,20,21,22,107,111,114,16,17,18,19,21,23,106,107,110,114,19,20,21,22,102,103,104,105,107,110,114,20,21,102,107,110,114,21,102,103,107,111,114,21,104,107,111,114,21,40,41,42,105,107,110,113,21,38,39,42,106,107,110,113,18,19,20,38,43,105,107,110,113,19,37,42,105,107,110,114,18,20,33,34,35,36,37,38,39,40,41,105,108,109,115,116,19,21,31,32,36,37,105,109,110,117,118,20,22,23,24,25,26,27,28,29,30,32,36,37,38,105,109,111,118,20,25,29,33,35,38,39,105,106,109,112,118,21,24,26,29,32,35,39,107,109,113,118,22,24,27,29,32,35,36,40,108,109,114,119,23,24,28,29,31,35,36,39,41,108,109,115,116,117,118,119,120,121,122,123,124,29,31,32,33,34,35,36,39,42,108,109,112,120,124,38,42,43,44,45,46,47,48,49,50,51,52,53,54,55,72,73,76,82,83,84,85,86,87,107,108,109,111,113,114,121,123,124,125,37,41,44,48,49,50,51,55,72,74,75,76,82,84,85,86,106,109,110,115,120,121,122,124,126,36,40,45,46,47,51,52,53,54,55,72,74,75,76,82,83,105,106,109,110,113,116,117,118,120,121,123,126,35,36,37,38,39,72,73,82,104,108,109,112,114,119,120,122,123,126,71,72,76,77,78,79,80,81,82,101,102,103,107,108,111,115,116,117,118,119,120,121,123,126,71,74,75,76,82,103,106,107,111,120,121,122,123,124,125,126,127,128,129,69,70,73,75,77,78,82,104,111,120,122,123,125,129,130,67,68,72,74,77,78,82,104,109,110,120,122,123,124,126,129,68,69,71,73,74,76,78,82,103,107,108,121,123,125,127,128,70,71,72,75,78,81,102,106,122,126,127,71,74,77,78,80,101,105,123,125,126,71,73,76,78,80,101,105,123,124,71,72,75,78,80,101,105,122,124,71,74,77,80,100,105,122,124,70,71,74,77,80,100,105,122,123,48,49,50,51,69,71,74,76,80,100,104,122,48,50,52,69,71,72,73,74,75,79,101,102,103,104,122,48,50,52,68,70,71,72,74,76,77,78,122,123,48,50,52,67,69,70,72,73,74,75,122,124,48,49,50,53,66,67,68,69,72,74,122,124,49,50,51,54,55,65,68,72,74,122,124,50,52,55,56,57,58,59,60,61,62,63,64,69,72,73,122,124,50,51,53,54,55,56,57,58,63,64,65,69,72,73,117,118,119,120,121,124,51,52,53,54,66,69,72,116,123,51,52,53,66,69,72,116,122,51,52,53,67,69,72,116,121,51,52,53,67,70,72,89,116,120,50,51,52,53,68,71,72,73,89,116,119,44,45,49,50,51,52,53,54,67,70,72,74,88,89,116,118,45,46,47,48,49,50,52,53,54,55,56,67,68,69,73,75,87,89,116,118,46,47,48,49,50,56,74,76,86,88,115,119,47,48,49,50,51,52,53,54,55,56,75,77,85,88,110,111,112,113,114,118,119,120,50,52,53,54,55,56,76,78,79,80,81,82,83,84,88,110,117,121,122,49,50,51,52,76,79,80,87,109,116,122,123,124,125,126,76,79,80,84,85,86,108,110,116,76,78,81,84,92,93,102,107,108,109,111,117,75,78,82,83,84,85,86,87,90,91,94,100,101,103,104,105,106,108,112,113,117,75,77,78,82,83,84,87,91,95,99,108,109,114,115,116,75,76,77,81,83,84,87,92,96,97,98,108,109,81,82,83,84,87,92,101,102,103,107,108,110,83,85,87,90,91,92,95,96,97,100,104,105,106,108,111,83,84,85,86,87,88,89,93,94,95,96,97,98,99,108,112,84,85,87,92,95,99,100,101,102,103,108,113,84,85,87,91,92,95,100,108,114,84,85,87,93,94,95,99,108,110,111,114,85,88,95,96,100,105,106,109,111,114,85,89,90,95,97,100,104,107,111,113,85,91,92,95,97,101,103,108,109,111,113,85,86,87,88,89,90,91,92,93,94,95,98,99,102,110,113,85,87,94,100,101,102,103,104,105,106,112,85,88,89,90,91,92,95,107,112,85,93,94,96,108,109,111,95,97,98,110,95,99,100,101,102,103,104,105,106,107,96,107,97,98,99,100,101,102,103,104,105,106,107,108 +}; + +int QuBiao (int MapId) +{ + int Xy = -1; + int biao = -1; + + if (MapId == 2000) {// + Xy = rand()%1019; + biao = YCXX[Xy]*1000; + biao += YCXY[Xy]; + }else if (MapId == 3000) {//ӼӴ + Xy = rand()%456; + biao = JJXX[Xy]*1000; + biao += JJXY[Xy]; + }else if (MapId == 1000) {// + Xy = rand()%790; + biao = KLXX[Xy]*1000; + biao += KLXY[Xy]; + }else if (MapId == 4000) {// + Xy = rand()%1109; + biao = SCXX[Xy]*1000; + biao += SCXY[Xy]; + }else if (MapId == 5000) {// + Xy = rand()%280; + biao = FCXX[Xy]*1000; + biao += FCXY[Xy]; + }else if (MapId == 3400) {//濩 + Xy = rand()%272; + biao = QGGXX[Xy]*1000; + biao += QGGXY[Xy]; + }else if (MapId == 5100) {// + Xy = rand()%201; + biao = DNXX[Xy]*1000; + biao += DNXY[Xy]; + }else if (MapId == 1100) {//ɰ´ + Xy = rand()%1263; + biao = KAXX[Xy]*1000; + biao += KAXY[Xy]; + }else if (MapId == 3100) {//ķ + Xy = rand()%783; + biao = TMXX[Xy]*1000; + biao += TMXY[Xy]; + }else if (MapId == 1400) {//̹ + Xy = rand()%697; + biao = KTXX[Xy]*1000; + biao += KTXY[Xy]; + }else if (MapId == 3300) {//³ + Xy = rand()%401; + biao = WLXX[Xy]*1000; + biao += WLXY[Xy]; + }else if (MapId == 1300) {//ش + Xy = rand()%1016; + biao = HETXX[Xy]*1000; + biao += HETXY[Xy]; + }else if (MapId == 3200) {// + Xy = rand()%484; + biao = DDXX[Xy]*1000; + biao += DDXY[Xy]; + }else if (MapId == 400) {//ɳķ + Xy = rand()%1330; + biao = SMDXX[Xy]*1000; + biao += SMDXY[Xy]; + } + + return biao; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_util.c b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_util.c new file mode 100644 index 0000000..ead0a3f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_util.c @@ -0,0 +1,35 @@ +#include "version.h" +#include "common.h" +#include "char.h" +#include "readmap.h" + + +#define MAP_CHARFLOOR(x) CHAR_getInt(x,CHAR_FLOOR) +#define MAP_CHARX(x) CHAR_getInt(x,CHAR_X) +#define MAP_CHARY(x) CHAR_getInt(x,CHAR_Y) + +BOOL MAP_getMapDataFromCharIndex( int index , int* map ) +{ + int mapdata[2]; + int ret; + + ret = MAP_getTileAndObjData(MAP_CHARFLOOR(index), + MAP_CHARX(index), + MAP_CHARY(index), + &mapdata[0],&mapdata[1] ); + map[0] = mapdata[0]; + map[1] = mapdata[1]; + return ret; +} + +BOOL MAP_getMapDataFromFXY( int f , int x , int y, int* map ) +{ + int mapdata[2]; + int ret; + + ret = MAP_getTileAndObjData(f,x,y,&mapdata[0],&mapdata[1] ); + map[0] = mapdata[0]; + map[1] = mapdata[1]; + return ret; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_warppoint.c b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_warppoint.c new file mode 100644 index 0000000..9229a72 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/map_warppoint.c @@ -0,0 +1,400 @@ +#include "version.h" + +#include +#include "common.h" +#include "char.h" +#include "char_base.h" +#include "object.h" +#include "buf.h" +#include "util.h" +#include "configfile.h" +#include "readmap.h" +#include "map_warppoint.h" +#include "autil.h" +#ifdef _MAP_WARPPOINT +#define MAP_MAXWARPPOINT 6000 + +typedef struct _tagMAPwarpPoints{ + int use; + int ofloor; + int ox; + int oy; + + int floor; + int x; + int y; + int type; +}_MAPwarpPoints; + +_MAPwarpPoints *MapWarppoint; +static int MapWarpPoints=0; +char PointType[3][256]={ "NONE", "FREE", "ERROR"}; + +char Filename[256]; +int MAPPOINT_InitMapWarpPoint() +{ + MapWarppoint = ( _MAPwarpPoints *)calloc( 1, sizeof( struct _tagMAPwarpPoints)*MAP_MAXWARPPOINT); + if( MapWarppoint == NULL ) return 0; + + sprintf(Filename, "%s/mapwarp.txt", getMapdir()); + MAPPOINT_resetMapWarpPoint( 0); + return MAP_MAXWARPPOINT; +} +/* +void MAPPOINT_checkMapWarpPoint( int floor, int x, int y) +{ + OBJECT object; + + for( object = MAP_getTopObj(fl,x,y) ; object ; + object = NEXT_OBJECT(object) ){ + int o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_WARPPOINT){ + if( !MAPPOINT_CHECKINDEX( OBJECT_getIndex( o)) ) continue; + if( OBJECT_getchartype( o) != event ) continue; + MAPPOINT_MapWarpHandle( charaindex, OBJECT_getIndex( o), fl, x, y ); + found = TRUE; + break; + } + +} +*/ +void MAPPOINT_resetMapWarpPoint( int flg) +{ + int i; + if( MapWarppoint == NULL ) return; + for( i=0; i= MAP_MAXWARPPOINT ) + return FALSE; + + return MapWarppoint[ ps].use; +} + +int MAPPOINT_getMPointEVType( int ps) +{ + if( !MAPPOINT_CHECKINDEX( ps) ) + return -1; + return MapWarppoint[ ps].type; +} + +int MAPPOINT_setMapWarpFrom( int ps, char *buf) +{ + char buf1[256]; + + if( MAPPOINT_CHECKINDEX( ps) ){ + print(" ô͵ %s !!\n", buf); + return -1; + } + + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].ofloor = atoi( buf1); + if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].ox = atoi( buf1); + if( getStringFromIndexWithDelim( buf, ",", 3, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].oy = atoi( buf1); + return 1; +} + +int MAPPOINT_setMapWarpGoal( int ps, char *buf) +{ + char buf1[256]; + if( MAPPOINT_CHECKINDEX( ps) ){ + print(" ô͵ :%s!!\n", buf); + return -1; + } + + memset( buf1, 0, sizeof( buf1)); + if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].floor = atoi( buf1); + if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].x = atoi( buf1); + if( getStringFromIndexWithDelim( buf, ",", 3, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ + MapWarppoint[ps].y = atoi( buf1); + return 1; +} + +int MAPPOINT_getMapWarpGoal( int ps, int ofl, int ox, int oy, int *fl, int *x, int *y) +{ + if( !MAPPOINT_CHECKINDEX( ps) ){ + print("ȡ͵PS:%d !!\n", ps); + return -1; + } + + if( MapWarppoint[ps].ofloor != ofl || + MapWarppoint[ps].ox != ox || MapWarppoint[ps].oy != oy ){ + print( "͵: ɵ⴫͵ %d %d %d !!\n" , ofl,ox,oy ); + return -1; + } + //ɼж + if( MAP_IsValidCoordinate( MapWarppoint[ps].floor, MapWarppoint[ps].x, MapWarppoint[ps].y)== FALSE ){ + print( "͵: %d %d %d !!\n" , + MapWarppoint[ps].floor,MapWarppoint[ps].x, MapWarppoint[ps].y ); + return -1; + } + *fl = MapWarppoint[ps].floor; + *x = MapWarppoint[ps].x; + *y = MapWarppoint[ps].y; + return 1; +} + +int MAPPOINT_loadMapWarpPoint( ) +{ + int i=0, ps=0, objtype; + FILE *fp=NULL; + char buf[256], buf1[256]; + + if( Filename == NULL ) return -1; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", Filename); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( Filename, "r"); +} + if( fp == NULL ){ + return 0; + } + while( fgets( buf, sizeof( buf)-1, fp) != NULL ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(buf); + } +#endif + if( strstr( buf, "#") != 0 ) continue; + if( getStringFromIndexWithDelim( buf, ":", 1, buf1, sizeof(buf1)) ==FALSE ) + continue; + for( i=0; i= arraysizeof( PointType) ){ + print(" 1.map ͵ %s \n", buf); + continue; + } + MapWarppoint[ps].type = i; + if( getStringFromIndexWithDelim( buf, ":", 2, buf1, sizeof(buf1)) ==FALSE ) continue; + objtype = CHAR_EVENT_WARP; + if( !strcmp( buf1, "NULL")){ + }else if( !strcmp( buf1, "M")){ + objtype = CHAR_EVENT_WARP_MORNING; + }else if( !strcmp( buf1, "N")){ + objtype = CHAR_EVENT_WARP_NIGHT; + }else if( !strcmp( buf1, "A")){ + objtype = CHAR_EVENT_WARP_NOON; + } + memset( buf1, 0, sizeof(buf1)); + if( getStringFromIndexWithDelim( buf, ":", 3, buf1, sizeof(buf1)) ==FALSE )continue; + + if( MAPPOINT_setMapWarpFrom( ps, buf1) == -1){ + print(" 2-1.map ͵ %s [%s] \n", buf, buf1); + continue; + } + if( MAPPOINT_creatMapWarpObj( ps, buf1, objtype) == -1 ){ + print(" 2.map ͵ %s [%s] \n", buf, buf1); + continue; + } + memset( buf1, 0, sizeof(buf1)); + if( getStringFromIndexWithDelim( buf, ":", 4, buf1, sizeof(buf1)) ==FALSE ){ + print(" 3.map ͵ %s [%s] \n", buf, buf1); + continue; + } + if( MAPPOINT_setMapWarpGoal( ps, buf1) == -1 ){ + print(" 4.map ͵ %s \n", buf); + continue; + } + memset( buf1, 0, sizeof(buf1)); + if( getStringFromIndexWithDelim( buf, ":", 5, buf1, sizeof(buf1)) ==FALSE ){ + print(" 5.map ͵ %s [%s] \n", buf, buf1); + continue; + } + MapWarppoint[ps].use = 1; + MapWarpPoints++; + ps++; + if( ps >= MAP_MAXWARPPOINT ){ + break; + } + } + //andy_log + print("ʼ %d ͼ͵...", MapWarpPoints); + fclose( fp); + print("\n"); + return 1; +} + +void MAPPOINT_MapWarpHandle( int charaindex, int ps, int ofl, int ox, int oy ) +{ + int floor, x, y; + if( MAPPOINT_getMapWarpGoal( ps, ofl, ox, oy, &floor, &x, &y) == -1 ){ + //andy_log + print( "ȡ͵( %d, %d,%d,%d)!!\n", ps, ofl, ox, oy); + return; + } + if( floor == 777 ) return; + CHAR_warpToSpecificPoint( charaindex, floor, x, y); + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) { + int i; + for( i = 1; i < getPartyNum(charaindex ); i ++ ) { + int index = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(index) ) { + CHAR_warpToSpecificPoint( index, floor, x, y); + } + } + } +} + +#ifdef _MO_LNS_MAPSUOXU +int DelMapPoint( int ps)//жصͼ͵ +{ + if (MapWarppoint[ps].use != 1) return FALSE; + MapWarppoint[ps].type = 0;//õͼĴ͵ + endObjectOne(get_mappointindex(MapWarppoint[ps].ofloor,MapWarppoint[ps].ox,MapWarppoint[ps].oy));//obj + MapWarppoint[ps].ofloor = -1;//õͼĴ͵ + MapWarppoint[ps].ox = -1;//õͼĴ͵ + MapWarppoint[ps].oy = -1;//õͼĴ͵ + MapWarppoint[ps].floor = -1;//õͼĴ͵ + MapWarppoint[ps].x = -1;//õͼĴ͵ + MapWarppoint[ps].y = -1;//õͼĴ͵ + MapWarppoint[ps].use = 0; + MapWarppoint[ps].type = 0; + return TRUE;//עô͵ʱȼǷԭд͵ +} + +int SetMapPoint( char* buf)//صͼ͵ +{ // "͵:NULL:2000,50,50:2006,20,20:" + if( MapWarpPoints >= MAP_MAXWARPPOINT ){ + print(" ͵Ѵޣ\n"); + return -1; + } + char buf1[256]; + char buf2[256]; + int objtype,i; + if( getStringFromIndexWithDelim( buf, ":", 1, buf1, sizeof(buf1)) ==FALSE )//ҳ͵ + { + return -2; + } + for( i=0; i= arraysizeof( PointType) ){//͵ʹ + return -3 ; + } + MapWarppoint[MapWarpPoints].type = i;//õͼĴ͵ + if( getStringFromIndexWithDelim( buf, ":", 2, buf1, sizeof(buf1)) ==FALSE ) //ҳ͵Чʱ + { + return -4 ; + } + objtype = CHAR_EVENT_WARP;//öΪ͵ + if( !strcmp( buf1, "NULL")){ + }else if( !strcmp( buf1, "M")){ + objtype = CHAR_EVENT_WARP_MORNING;//öΪ糿͵ + }else if( !strcmp( buf1, "N")){ + objtype = CHAR_EVENT_WARP_NIGHT;//öΪϴ͵ + }else if( !strcmp( buf1, "A")){ + objtype = CHAR_EVENT_WARP_NOON;//öΪ紫͵ + } + memset( buf1, 0, sizeof(buf1)); + if( getStringFromIndexWithDelim( buf, ":", 3, buf1, sizeof(buf1)) ==FALSE )//ҳԭ + { + return -5 ; + } + int fl = -1,x = -1,y = -1; + if( getStringFromIndexWithDelim( buf1, ",", 1, buf2, sizeof(buf1)) !=FALSE )//ҳԭ + { + fl = atoi(buf2); + } + if( getStringFromIndexWithDelim( buf1, ",", 2, buf2, sizeof(buf1)) !=FALSE )//ҳԭ + { + x = atoi(buf2); + } + if( getStringFromIndexWithDelim( buf1, ",", 3, buf2, sizeof(buf1)) !=FALSE )//ҳԭ + { + y = atoi(buf2); + } + if (fl == -1 || x == -1 || y == -1) return -5; + if (get_mappointindex( fl,x, y) != -1) return -5;//ù͵㣡 + for (i=0;i= MapWarpPoints) MapWarpPoints++;//ǰ͵ѾԤһ͵㡣 + return i; +} +#endif + + +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/map/readmap.c b/石器时代服务器端最新完整源代码/Serv/gmsv/map/readmap.c new file mode 100644 index 0000000..fe85630 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/map/readmap.c @@ -0,0 +1,1820 @@ +#include "version.h" +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "common.h" +#include "object.h" +#include "readmap.h" +#include "buf.h" +#include "util.h" +#include "char.h" +#include "lssproto_serv.h" +#include "configfile.h" +#include "autil.h" +#define MAP_MAGIC "LS2MAP" +#ifdef _MO_LNS_MAPSUOXU +static int fbmap[10000]; +#endif +static void MAP_makeDefaultImageData( MAP_ImageData* one ) +{ + one->data[MAP_WALKABLE] = TRUE; + one->data[MAP_HAVEHEIGHT] = FALSE; + one->data[MAP_DEFENCE] = 0; + one->data[MAP_INTODAMAGE] = 0; + one->data[MAP_OUTOFDAMAGE] = 0; + + one->data[MAP_SETED_BATTLEMAP] = 0; + one->data[MAP_BATTLEMAP] = 0; + one->data[MAP_BATTLEMAP2] = 0; + one->data[MAP_BATTLEMAP3] = 0; + one->data[MAP_INTODARKNESS] = 0; + one->data[MAP_INTOCONFUSION] = 0; + + one->data[MAP_OUTOFPOISON] = 0; + one->data[MAP_OUTOFPARALYSIS] = 0; + one->data[MAP_OUTOFSILENCE] = 0; + one->data[MAP_OUTOFSTONE] = 0; + one->data[MAP_OUTOFDARKNESS] = 0; + one->data[MAP_OUTOFCONFUSION] = 0; + +} + +static int MAP_flgSet( char* string ) +{ + int tmp; + tmp = atoi(string); + if( tmp == 0 ) + return 0; + return 1; +} +typedef enum +{ + MAP_INTENTRY=0, + MAP_CHARENTRY=1, + MAP_INTFUNC=2, + MAP_CHARFUNC=3, +}MAP_DATATYPECATEGORY; +static struct MAP_itemconfentry +{ + int type; + int index; + void* func; +}MAP_confentries[MAP_DATAINT_NUM+MAP_DATACHAR_NUM]={ + {MAP_INTENTRY, MAP_WALKABLE, MAP_flgSet}, + {MAP_INTENTRY, MAP_HAVEHEIGHT, MAP_flgSet}, + {MAP_INTENTRY, MAP_DEFENCE, NULL}, + {MAP_INTENTRY, MAP_INTODAMAGE, NULL}, + {MAP_INTENTRY, MAP_OUTOFDAMAGE, NULL}, + + {MAP_INTENTRY, MAP_SETED_BATTLEMAP, NULL}, + {MAP_INTENTRY, MAP_BATTLEMAP, NULL}, + {MAP_INTENTRY, MAP_BATTLEMAP2, NULL}, + {MAP_INTENTRY, MAP_BATTLEMAP3, NULL}, + {MAP_INTENTRY, MAP_INTODARKNESS, NULL}, + {MAP_INTENTRY, MAP_INTOCONFUSION, NULL}, + + {MAP_INTENTRY, MAP_OUTOFPOISON, NULL}, + {MAP_INTENTRY, MAP_OUTOFPARALYSIS, NULL}, + {MAP_INTENTRY, MAP_OUTOFSILENCE, NULL}, + {MAP_INTENTRY, MAP_OUTOFSTONE, NULL}, + {MAP_INTENTRY, MAP_OUTOFDARKNESS, NULL}, + {MAP_INTENTRY, MAP_OUTOFCONFUSION, NULL}, + +}; + +static MAP_ImageData* MAP_imagedata; +static unsigned int MAP_imagedatanum; +static int MAP_imgfilt[65535]; + +BOOL MAP_readMapConfFile( char* filename ) +{ + FILE* file; + char line[512]; + int maximagenumber=0; + int i; + int linenum=0; + int imgdataindex=0; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + file = fopen( realopfile, "r"); + if( file != NULL ){ + crypto = TRUE; + }else +#endif +{ + file = fopen( filename , "r" ); +} + if( file == NULL ){ + fprint( "޷ļ %s\n", filename ); + return FALSE; + } + while( fgets( line , sizeof( line ) , file ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + char imgnum[16]; + BOOL ret; + int imgnumber; + deleteSequentChar( line, " \t" ); + pohcd( line, " \t" ); + dchop(line, " \t"); + + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + ret = getStringFromIndexWithDelim( line , " " , 1 , imgnum , sizeof( imgnum ) ); + if( ret == FALSE )continue; + imgnumber = atoi(imgnum); + maximagenumber = max( maximagenumber , imgnumber ); + } + + MAP_imagedatanum = maximagenumber + 1; + MAP_imagedata=allocateMemory(sizeof(MAP_ImageData)*MAP_imagedatanum); + if( MAP_imagedata == NULL ){ + fprint("޷ͼݴС=%d\n",MAP_imagedatanum); + return FALSE; + } + + for( i = 0; i data[MAP_confentries[i].index] + = atoi( token ); + break; + case MAP_CHARENTRY: + strcpysafe( one->string[MAP_confentries[i].index].string, + sizeof( one->string[MAP_confentries[i].index]. + string), + token); + break; + case MAP_INTFUNC: + { + int (*intfunction)(char* ); + intfunction = MAP_confentries[i].func; + one->data[MAP_confentries[i].index] + = intfunction(token); + break; + } + case MAP_CHARFUNC: + { + char* (*charfunction)(char* ); + charfunction = MAP_confentries[i].func; + + strcpysafe( one->string[MAP_confentries[i].index].string, + sizeof(one->string[MAP_confentries[i].index]. + string), + charfunction(token)); + break; + } + default: + break; + } + } + } + + fclose( file ); + return TRUE; +} + +#if 1 +BOOL MAP_readBattleMapConfFile( char* filename ) +{ + FILE* file; + char line[512]; + + int i, j; + int linenum=0; + int BattleMapNo[3], iRet, iWork, iPre[3],iFirst, iLast; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", filename); + file = fopen( realopfile, "r"); + if( file != NULL ){ + crypto = TRUE; + }else +#endif +{ + file = fopen( filename , "r" ); +} + if( file == NULL ){ + fprint( "޷ %s\n", filename ); + return FALSE; + } + + BattleMapNo[0] = 0; + BattleMapNo[1] = 0; + BattleMapNo[2] = 0; + while( fgets( line , sizeof( line ) , file ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + char *p; + linenum++; + + pohcd( line, " \t" ); + dchop(line, " \t"); + + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + + if( line[0] == '$' ){ + iRet = sscanf( line+1, "%d %d %d", &iPre[0], &iPre[1], &iPre[2] ); + BattleMapNo[0] = BattleMapNo[1] = BattleMapNo[2] = iPre[0]; + if( iRet < 1 ){ + print( "!!!!! ޷ȡսͼ(%s)( line %d )\n", filename, linenum ); + } + for( i = 0; i < iRet; i ++ ){ + BattleMapNo[i] = iPre[i]; + if( BattleMapNo[i] < 0 ){ + print( "!!!!! սͼΪֵ (%s)( line %d )\n", filename, linenum ); + } + } + + continue; + + } + if( sscanf( line, "%d", &iWork ) != 1 ){ + continue; + } + if( iWork < 0 ){ + print( "!!!!! ǮΪֵ (%s)( line %d )\n", filename, linenum ); + continue; + } + iFirst = iWork; + p = strstr( line, "to" ); + if( p != NULL ){ + if( sscanf( p+2, "%d", &iWork ) != 1 ){ + iLast = iFirst; + }else{ + iLast = iWork; + } + if( iWork < 0 ){ + print( "!!!!! ǮΪֵ (%s)( line %d )\n", filename, linenum ); + continue; + } + }else{ + iLast = iFirst; + } + + for( i = iFirst; i <= iLast; i ++ ){ + if( MAP_getImageInt( i, MAP_SETED_BATTLEMAP ) > 0 ){ + print( "!!!!! ͬǮظ趨(%s)( line %d )(%d)(%d & %d)\n", + filename, linenum, i, + MAP_getImageInt( i, MAP_BATTLEMAP ), + BattleMapNo[0] ); + } + + // įо + if( IsValidImagenumber( i ) == FALSE ){ + continue; + } + MAP_setImageInt( i, MAP_BATTLEMAP, BattleMapNo[0] ); + MAP_setImageInt( i, MAP_BATTLEMAP2, BattleMapNo[1] ); + MAP_setImageInt( i, MAP_BATTLEMAP3, BattleMapNo[2] ); + MAP_setImageInt( i, MAP_SETED_BATTLEMAP, 1 ); + } + + } + fclose( file ); + + for( j = 0; j < arraysizeof( MAP_imgfilt ); j ++ ){ + if( MAP_imgfilt[j] == -1 )continue; + if( MAP_getImageInt( j, MAP_SETED_BATTLEMAP ) == 0 ){ + print( "!!!!! Ǯ(%d)δ趨 (%s)\n", j, filename ); + } + } + return TRUE; +} +#endif + +BOOL IsValidImagenumber( int imagenumber ) +{ + if( imagenumber < 0 || imagenumber >= arraysizeof( MAP_imgfilt ) ) + return FALSE; + + if( MAP_imgfilt[imagenumber] == -1 ) + return FALSE; + return TRUE; +} + +int MAP_getImageInt( int imagenumber, int element ) +{ + if( imagenumber < 0 || imagenumber >= arraysizeof( MAP_imgfilt )) + return FALSE; + + if( MAP_imgfilt[imagenumber] == -1 )return FALSE; + return MAP_imagedata[MAP_imgfilt[imagenumber]].data[element]; +} + +BOOL MAP_setImageInt( int imagenumber, int element, int value ) +{ + if( imagenumber < 0 || imagenumber >= arraysizeof( MAP_imgfilt )) + return FALSE; + + if( MAP_imgfilt[imagenumber] == -1 )return FALSE; + MAP_imagedata[MAP_imgfilt[imagenumber]].data[element] = value; + + return TRUE; +} + +static MAP_Map* MAP_map; +static unsigned int MAP_mapnum; +static unsigned int MAP_mapnum_index; + + +static int MAP_idjumptbl[65535]; +static int MAP_idtblsize; + +BOOL MAP_initMapArray( int num ) +{ + MAP_mapnum = num ; + + MAP_map = allocateMemory( sizeof( MAP_Map ) * MAP_mapnum ); + if( MAP_map == NULL )return FALSE; + + MAP_mapnum_index = 0; + + return TRUE; +} + +void MAP_endMapArray( void ) +{ + int i; + for( i = 0 ; i < MAP_mapnum ; i ++ ){ + if( MAP_map[i].tile != NULL ) + freeMemory( MAP_map[i].tile ); + + if( MAP_map[i].obj != NULL) + freeMemory( MAP_map[i].obj ); + + } + MAP_mapnum = 0; + MAP_mapnum_index = 0; + freeMemory( MAP_map ); + MAP_map = NULL; +} + +BOOL MAP_IsMapFile( char* filename ) +{ + FILE* f; + char buf[16]; + int ret; + + f = fopen(filename, "r"); + if( f == NULL ){ + errorprint; + return FALSE; + } + + ret = fread( buf , sizeof( char ) , 6 , f); + if( ret != 6 ) + goto FCLOSERETURNFALSE; + buf[ret] = '\0'; + + if( strcmp( buf , MAP_MAGIC ) != 0 ) + goto FCLOSERETURNFALSE; + else + goto FCLOSERETURNTRUE; + +FCLOSERETURNFALSE: + fclose(f); + return FALSE; +FCLOSERETURNTRUE: + fclose(f); + return TRUE; +} + +BOOL MAP_readMapOne( char* filename ) +{ + FILE* f; /* ̻ */ + char buf[16]; /* Ѩ͹ϼ */ + short data[1024]; /* */ + int ret; /* ߯ԻԻ */ + int i; /* */ + int mapindex; + + int id=0,xsiz=0,ysiz=0; /* Ѩ󷸡ɡ */ + + unsigned short *tile=NULL; + unsigned short *obj=NULL; + MAP_Objlink** olink=NULL; + char showstring[32]; /* Ѩ󷸡ɡ */ + struct stat filestat; /* ñ */ + BOOL invaliddata=FALSE; + + if( MAP_mapnum_index >= MAP_mapnum ){ + fprint( "û㹻ռװصͼ.\n" ); + return FALSE; + } + mapindex=MAP_mapnum_index; + f = fopen(filename, "r"); + if( f == NULL ){ + errorprint; + return FALSE; + } + if( fstat( fileno(f) , &filestat ) != 0 ){ + errorprint; + goto FCLOSERETURNFALSE; + } + + ret = fread( buf , sizeof( char ) , 6 , f); + if( ret != 6 ){ + errorprint; + goto FCLOSERETURNFALSE; + } + buf[ret] = '\0'; + + if( strcmp( buf , MAP_MAGIC ) != 0 ) + goto FCLOSERETURNFALSE; + ret = fread( data , sizeof( short ) , 1 , f); + if( ret != 1 ){ + errorprint; + goto FCLOSERETURNFALSE; + } + id = ntohs( data[0] ); + + ret = fread( showstring , sizeof(char), arraysizeof(showstring), f); + if( ret != arraysizeof(showstring) ){ + errorprint; + goto FCLOSERETURNFALSE; + } + +/* + FILE* fff = fopen( "map" , "a+" ); + if(fff != NULL){ + char token[256]; + sprintf( token, "ID:%d, :%s, ·:%s\n", id, showstring, filename ); + fwrite(token, strlen(token), 1, fff); + fclose(fff); + } +*/ + + showstring[arraysizeof(showstring)-1] = '\0'; + ret = fread( data, sizeof( short ) , 1 , f); + if( ret != 1 ){ + errorprint; + goto FCLOSERETURNFALSE; + } + xsiz = ntohs( data[0] ); + + ret = fread( data, sizeof( short ) , 1 , f); + if( ret != 1 ){ + errorprint; + goto FCLOSERETURNFALSE; + } + ysiz = ntohs( data[0] ); + tile = allocateMemory( sizeof( unsigned short ) * xsiz * ysiz ); + if( tile == NULL ){ + fprint( "޷ڴͼ:%s xsiz:%d ysiz:%d\n", filename, xsiz, ysiz); + goto FREEOBJHP; + } + + obj = allocateMemory( sizeof( unsigned short ) * xsiz * ysiz ); + if( obj == NULL ){ + fprint( "޷ڴ\n"); + goto FREETILE; + } + + olink = allocateMemory( sizeof(MAP_Objlink*) * xsiz * ysiz ); + if( olink == NULL ){ + fprint( "޷ڴ\n"); + goto FREEOBJ; + } + + ret = fread( tile , sizeof( unsigned short )*xsiz*ysiz,1,f ); + if( ret != 1 ){ + errorprint; + goto FREELINK; + } +// for( i = 0 ; i < xsiz * ysiz ; i ++ ) +// tile[i] = ntohs( tile[i] ); + for( i = 0 ; i < xsiz * ysiz ; i ++ ){ + tile[i] = ntohs( tile[i] ); + + if( !IsValidImagenumber( tile[i] ) ){ + fprint("ͼͼƬ:%d x:%d y:%d :%d\n", + id, i % xsiz, (int)(i / xsiz) , tile[i]); + invaliddata = TRUE; + } + /* + else{ + fprint("ͼͼƬΪ:%d x:%d y:%d :%d\n", + id, i % xsiz, (int)(i / xsiz) , tile[i]); + + } + */ + } + ret = fread( obj , sizeof( short )*xsiz*ysiz,1,f ); + if( ret != 1 ){ + errorprint; + goto FREELINK; + } +// for( i = 0 ; i < xsiz * ysiz ; i ++ ) +// obj[i] = ntohs( obj[i] ); + for( i = 0 ; i < xsiz * ysiz ; i ++ ){ + obj[i] = ntohs( obj[i] ); + if( !IsValidImagenumber( obj[i] ) ){ + fprint( + "ͼͼƬ:%d x:%d y:%d :%d\n", + id, i % xsiz, (int)(i / xsiz) , obj[i]); + invaliddata = TRUE; + } + /* + else{ + fprint( + "ͼͼƬΪ:%d x:%d y:%d :%d\n", + id, i % xsiz, (int)(i / xsiz) , obj[i]); + + } + */ + } + if( invaliddata )goto FREELINK; +/* if( ftell(f) != filestat.st_size) + fprintf(stderr,"ļСȷ(%s). ĿļС:%" +#ifdef linux + "l" +#elif __FreeBSD__ + "ll" +#endif + "d ʵʴС:%ld\n", + filename, filestat.st_size,ftell(f)); +*/ + + for( i=0 ; i< xsiz*ysiz ; i ++ ) + olink[i] = NULL; + + MAP_map[mapindex].id = id; + MAP_map[mapindex].xsiz = xsiz; + MAP_map[mapindex].ysiz = ysiz; + strcpysafe( MAP_map[mapindex].string , + sizeof(MAP_map[mapindex].string), + showstring ); + MAP_map[mapindex].tile = tile; + MAP_map[mapindex].obj = obj; + MAP_map[mapindex].olink = olink; + +#ifdef _MAP_NOEXIT + { + FILE *fp; + char mpexit[128]; + int floorID=0,exfloor=0,ex_X=0,ex_Y=0; + int map_type=0; + MAP_map[mapindex].startpoint = 0; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + fp = fopen( "./data/map/map_noexit.txt.allblues", "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( "./data/map/map_noexit.txt","r"); +} + if( fp != NULL ){ + while( fgets(mpexit, 128, fp) != NULL ) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(mpexit); + } +#endif + sscanf( mpexit,"%d %d %d %d %d", &floorID, &exfloor, &ex_X, &ex_Y, &map_type); + if( strstr( mpexit, "#" ) != NULL) + continue; + if( floorID == id) { + MAP_map[mapindex].startpoint = (exfloor<<16)+(ex_X << 8)+(ex_Y<<0); + MAP_map[mapindex].MapType = map_type; + } + } + // Nuke 1204: Bug fix + fclose(fp); + }else { + print("\n **** Ҳ map_noexit.txt ļ!!!"); + } + } +#endif + goto FCLOSERETURNTRUE; + +FCLOSERETURNTRUE: + MAP_idjumptbl[MAP_map[mapindex].id] = mapindex; + + if( MAP_idtblsize <= MAP_map[mapindex].id ){ + MAP_idtblsize = MAP_map[mapindex].id + 1; + } + + MAP_mapnum_index++; + fclose(f); + return TRUE; + +FREELINK: + freeMemory( olink ); +FREEOBJ: + freeMemory( obj ); +FREETILE: + freeMemory( tile ); +FREEOBJHP: +FCLOSERETURNFALSE: + fclose(f); + return FALSE; +} +#ifdef _MAP_NOEXIT +unsigned int MAP_getExFloor_XY( int floor, int *map_type) +{ + int i; + int exfloor; + for( i=0; i 0 ) { + exfloor = (MAP_map[i].startpoint>>16)&0xffffff; + if( exfloor >= 0 ) { + *map_type = MAP_map[i].MapType; + return MAP_map[i].startpoint ; + } + } + } + } + return 0; +} +BOOL CHECKFLOORID( id) +{ + int i; + + if( id < 0 ) + return FALSE; + + for( i=0; i MAP_getfloorX(mapid) || + y < 0 || y > MAP_getfloorY(mapid)) + return FALSE; + + return TRUE; +} + +#define MAP_GETMAXSIZE 45 +static char MAP_dataString[STRINGBUFSIZ*3]; +static int MAP_workdatabuffer[MAP_GETMAXSIZE*MAP_GETMAXSIZE]; +#define MAP_DATADELIMITER "," + +char* MAP_getdataFromRECT( int floor, RECT* seekr, RECT* realr ) +{ + int floorindex; + int stringlength=0; + char tmpbuffer[128]; + int i,j; + int floorx; + int databufferindex=0; + RECT scr; + char escapebuffer[128]; + + floorindex = MAP_getfloorIndex( floor ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return NULL; + } + if( seekr->width < 0 || seekr->height < 0 || + MAP_GETMAXSIZE < seekr->width || MAP_GETMAXSIZE < seekr->height ){ + print( "%s:%d:err\n", __FILE__, __LINE__); + return NULL; + } + snprintf( tmpbuffer,sizeof(tmpbuffer), + "%s|" , + makeEscapeString( MAP_map[floorindex].string, + escapebuffer,sizeof(escapebuffer))); + + strcpysafe( MAP_dataString, sizeof( MAP_dataString ), tmpbuffer ); + stringlength = strlen( tmpbuffer ); + + floorx = MAP_map[floorindex].xsiz; + scr.x = 0; + scr.y = 0; + scr.width = floorx; + scr.height= MAP_map[floorindex].ysiz; + + if( clipRect( seekr,&scr,realr ) == FALSE ){ + realr->x=realr->y=realr->width=realr->height=0; + return MAP_dataString; + } + for( i = realr->y ; i < realr->y + realr->height ; i ++ ){ + for( j = realr->x ; j < realr->x + realr->width ; j ++ ){ + MAP_workdatabuffer[databufferindex++] + = MAP_map[floorindex].tile[i*floorx+j]; + } + } + for( i = 0 ; i < databufferindex ; i ++ ){ + char buf[64]; + snprintf( tmpbuffer,sizeof(tmpbuffer),"%s" MAP_DATADELIMITER , + cnv10to62( MAP_workdatabuffer[i], buf, sizeof( buf)) ); + strcpysafe( &MAP_dataString[stringlength] , + sizeof( MAP_dataString ) - stringlength, + tmpbuffer ); + stringlength += strlen( tmpbuffer ); + } + if( stringlength < sizeof( MAP_dataString ) ) + MAP_dataString[stringlength-1] = NONCHAR_DELIMITER[0]; + databufferindex=0; + for( i = realr->y ; i < realr->y + realr->height ; i ++ ){ + for( j = realr->x ; j < realr->x + realr->width ; j ++ ){ + MAP_workdatabuffer[databufferindex++] + = MAP_map[floorindex].obj[i*floorx+j]; + } + } + for( i = 0 ; i < databufferindex ; i ++ ){ + char buf[64]; + if( MAP_workdatabuffer[i] == 0 ) buf[0] = '\0'; + else cnv10to62( MAP_workdatabuffer[i], buf, sizeof( buf)); + snprintf( tmpbuffer,sizeof(tmpbuffer),"%s" MAP_DATADELIMITER , + buf ); + strcpysafe( &MAP_dataString[stringlength] , + sizeof( MAP_dataString ) - stringlength, + tmpbuffer ); + stringlength += strlen( tmpbuffer ); + } + + if( stringlength < sizeof( MAP_dataString ) ) + MAP_dataString[stringlength-1] = NONCHAR_DELIMITER[0]; + + databufferindex=0; + for( i = realr->y ; i < realr->y + realr->height ; i ++ ){ + for( j = realr->x ; j < realr->x + realr->width ; j ++ ){ + OBJECT object; + BOOL found = FALSE; + for( object = MAP_getTopObj(floor,j,i) ; object ; + object = NEXT_OBJECT(object) ){ + int o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_CHARA ){ + int etype; + int charaindex=OBJECT_getIndex(o); + if( !CHAR_CHECKINDEX(charaindex) )continue; + etype = CHAR_getWorkInt( charaindex, CHAR_WORKEVENTTYPE); + if( etype != CHAR_EVENT_NONE ) { + MAP_workdatabuffer[databufferindex++] = etype; + found = TRUE; + break; + } + } +#ifdef _MAP_WARPPOINT + else if( OBJECT_getType(o) == OBJTYPE_WARPPOINT ){ + int etype = OBJECT_getchartype( o); + if( etype != CHAR_EVENT_NONE ) { + MAP_workdatabuffer[databufferindex++] = (unsigned short)etype; + found = TRUE; + break; + } + } +#endif + } + if( !found ) { + MAP_workdatabuffer[databufferindex++] + = CHAR_EVENT_NONE; + } + } + } + for( i = 0 ; i < databufferindex ; i ++ ){ + char buf[64]; + if( MAP_workdatabuffer[i] == 0 ) buf[0] = '\0'; + else cnv10to62( MAP_workdatabuffer[i], buf, sizeof( buf)); + + snprintf( tmpbuffer,sizeof(tmpbuffer),"%s" MAP_DATADELIMITER, buf); + strcpysafe( &MAP_dataString[stringlength] , + sizeof( MAP_dataString ) - stringlength, tmpbuffer ); + stringlength += strlen( tmpbuffer ); + } + dchop( MAP_dataString, MAP_DATADELIMITER ); + return MAP_dataString; +} + +char *MAP_getChecksumFromRECT( int floor, RECT* seekr, RECT* realr, + int *tilesum, int *objsum, int *eventsum ) +{ + int floorindex; + int i,j; + int floorx; + int databufferindex=0; + RECT scr; + char escapebuffer[128]; + unsigned short eventbuf[MAP_CHAR_DEFAULTSEESIZ * MAP_CHAR_DEFAULTSEESIZ]; + unsigned short tilebuf[ MAP_CHAR_DEFAULTSEESIZ * MAP_CHAR_DEFAULTSEESIZ]; + unsigned short objbuf[ MAP_CHAR_DEFAULTSEESIZ * MAP_CHAR_DEFAULTSEESIZ]; + + floorindex = MAP_getfloorIndex( floor ); + if( floorindex == -1 ) return NULL; + if( seekr->width < 0 || seekr->height < 0 || + MAP_GETMAXSIZE < seekr->width || MAP_GETMAXSIZE < seekr->height ) + return NULL; + + strcpysafe( MAP_dataString, sizeof( MAP_dataString ), + makeEscapeString( MAP_map[floorindex].string, + escapebuffer,sizeof(escapebuffer))); + + floorx = MAP_map[floorindex].xsiz; + scr.x = 0; + scr.y = 0; + scr.width = floorx; + scr.height= MAP_map[floorindex].ysiz; + + if( clipRect( seekr,&scr,realr ) == FALSE ){ + realr->x=realr->y=realr->width=realr->height=0; + return MAP_dataString; + } + + *tilesum = 0; + *objsum =0; + *eventsum = 0; + memset( tilebuf, 0, sizeof( tilebuf)); + memset( objbuf, 0, sizeof( objbuf)); + memset( eventbuf, 0, sizeof( eventbuf)); + for( i = realr->y ; i < realr->y + realr->height ; i ++ ){ + for( j = realr->x ; j < realr->x + realr->width ; j ++ ){ + OBJECT object; + //BOOL found = FALSE; + for( object = MAP_getTopObj(floor,j,i) ; object ; + object = NEXT_OBJECT(object) ){ + int o = GET_OBJINDEX(object); + if( OBJECT_getType(o) == OBJTYPE_CHARA ){ + int etype; + int charaindex=OBJECT_getIndex(o); + if( !CHAR_CHECKINDEX(charaindex) )continue; + etype = CHAR_getWorkInt( charaindex, CHAR_WORKEVENTTYPE); + if( etype != CHAR_EVENT_NONE ) { + eventbuf[databufferindex] = (unsigned short)etype; + break; + } + } +#ifdef _MAP_WARPPOINT + else if( OBJECT_getType(o) == OBJTYPE_WARPPOINT ){ + int etype = OBJECT_getchartype( o); + if( etype != CHAR_EVENT_NONE ) { + eventbuf[databufferindex] = (unsigned short)etype; + break; + } + } +#endif + } + tilebuf[databufferindex] = (unsigned short)MAP_map[floorindex].tile[i*floorx+j]; + objbuf[databufferindex] = (unsigned short)MAP_map[floorindex].obj[i*floorx+j]; + databufferindex++; + } + } + *tilesum = CheckCRC( (unsigned char*)tilebuf, sizeof( tilebuf)); + *objsum = CheckCRC( (unsigned char*)objbuf, sizeof( objbuf)); + *eventsum = CheckCRC( (unsigned char*)eventbuf, sizeof( eventbuf)); + + return MAP_dataString; +} + +BOOL MAP_getTileAndObjData( int ff ,int fx, int fy, int* tile, int* obj) +{ + int floorindex,xsiz; + floorindex = MAP_getfloorIndex( ff ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + xsiz = MAP_map[floorindex].xsiz; + + if( fx < 0 || fx >= xsiz ) { + return FALSE; + } + if( fy < 0 || fy >= MAP_map[floorindex].ysiz ) { + return FALSE; + } + + if( tile ) + *tile = MAP_map[floorindex].tile[fy*xsiz+fx]; + if( obj ) + *obj = MAP_map[floorindex].obj[fy*xsiz+fx]; + + return TRUE; +} + +BOOL MAP_setTileAndObjData( int ff ,int fx, int fy, int tile, int obj) +{ + int floorindex,xsiz; + floorindex = MAP_getfloorIndex( ff ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + xsiz = MAP_map[floorindex].xsiz; + if( fx < 0 || fx >= xsiz ) { + return FALSE; + } + if( fy < 0 || fy >= MAP_map[floorindex].ysiz ) { + return FALSE; + } + if( tile != -1 ) + MAP_map[floorindex].tile[fy*xsiz+fx] = tile; + if( obj != -1) + MAP_map[floorindex].obj[fy*xsiz+fx] = obj; + return TRUE; +} + +BOOL MAP_initReadMap( char* maptilefile , char* mapdir ) +{ + print("\n"); + if( !MAP_readMapConfFile(maptilefile) ) + return FALSE; + if( !MAP_readBattleMapConfFile( getBattleMapfile( ) ) ) + return FALSE; + if( !MAP_readMapDir(mapdir) ) + return FALSE; + return TRUE; +} + +static int MAP_coKindAndInt[MAP_KINDNUM]= +{ + MAP_WALKABLE, +}; + +BOOL MAP_makeVariousMap(char* atile, char* aobj, int floor, int startx, + int starty, int xsiz, int ysiz, MAP_kind kind ) +{ + int i,j; + int findex; + int fxsiz; + int startpoint; + + if( atile == NULL || aobj == NULL || kind < 0 || kind >= MAP_KINDNUM ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + findex = MAP_getfloorIndex( floor ); + if( findex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + fxsiz = MAP_map[findex].xsiz; + startpoint = startx + starty * fxsiz ; + + for( i = 0 ; i < ysiz ; i ++ ){ + for( j = 0 ; j < xsiz ; j ++ ){ + atile[i*xsiz+j] = MAP_getImageInt( MAP_map[findex].tile[ + startpoint + i*xsiz + j],MAP_coKindAndInt[kind] ) + ? 1 : 0; + + aobj[i*xsiz+j] = MAP_getImageInt( MAP_map[findex].obj[ + startpoint + i*xsiz + j],MAP_coKindAndInt[kind] ) + ? 1 : 0; + } + } + return TRUE; +} + +BOOL MAP_makeWalkableMap( char* data, int floor, int startx, int starty, + int xsiz, int ysiz ) +{ + int i,j; + char* obj; + obj = allocateMemory(xsiz*ysiz*sizeof(char)); + if( obj == NULL )return FALSE; + + if( MAP_makeVariousMap( data, obj, floor, startx, starty, xsiz, ysiz, + MAP_KINDWALKABLE ) == FALSE ){ + freeMemory( obj ); + return FALSE; + } + + for( i = 0 ; i < ysiz ; i ++ ) + for( j = 0 ; j < xsiz ; j ++ ) + data[j+i*ysiz] = data[j+i*ysiz] & obj[j+i*ysiz]; + +#ifdef DEBUG + for( i = 0 ; i < ysiz ; i ++ ){ + for( j = 0 ; j < xsiz ; j ++ ) + if( data[j+i*ysiz] ){ + print(" "); + }else + print("O"); + print("\n"); + } +#endif /*DEBUG*/ + + return TRUE; +} + +BOOL MAP_IsThereSpecificFloorid( int floorid ) +{ + if( MAP_getfloorIndex(floorid)== -1)return FALSE; + else return TRUE; +} + +BOOL MAP_IsValidCoordinate( int floor, int x, int y ) +{ + if( MAP_IsThereSpecificFloorid(floor)==FALSE )return FALSE; + if( x < 0 || MAP_getfloorX(floor)<=x )return FALSE; + if( y < 0 || MAP_getfloorY(floor)<=y )return FALSE; + return TRUE; +} + +int MAP_attackSpecificPoint( int floor, int x, int y, int damage , + int charaindex ) +{ +#if 0 + int mapindex; + int xsiz; + int objimagenumber; + + mapindex = MAP_getfloorIndex(floor); + if( mapindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return 5; + } + xsiz = MAP_map[mapindex].xsiz; + if( 0 > x || x >= xsiz || 0 >y || y >= MAP_map[mapindex].ysiz ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return 5; + } + if( damage <= 0 )return 5; + + objimagenumber = MAP_map[mapindex].obj[x+y*xsiz]; + + if( MAP_getImageInt( objimagenumber,MAP_DEFENCE ) > 0 ){ + MAP_map[mapindex].objhp[x+y*xsiz] -= damage; + if( MAP_map[mapindex].objhp[x+y*xsiz] < 0 ){ + MAP_map[mapindex].obj[x+y*xsiz] = 0; +#if 1 + { + char *stringdata; + RECT seekr , retr; + seekr.x = x; + seekr.y = y; + seekr.width = 1; + seekr.height = 1; + stringdata = MAP_getdataFromRECT(floor,&seekr,&retr); + if( stringdata ){ + print("RINGO: RETR: %d %d %d %d\n", + retr.x,retr.y,retr.width,retr.height); + if( CHAR_getInt( charaindex , CHAR_WHICHTYPE ) + == CHAR_TYPEPLAYER ){ + int fd = getfdFromCharaIndex( charaindex ); + lssproto_M_send(fd,floor, retr.x, retr.y, + retr.x + retr.width, retr.y + retr.height, + stringdata ); + } + } else { + print("RINGO: bad stringdata. %d %d %d %d\n", + seekr.x,seekr.y,seekr.width,seekr.height); + + } + + } +#endif + return 1; + } + return 2; + } + + if( MAP_getImageInt(MAP_map[mapindex].obj[y*xsiz+x],MAP_HAVEHEIGHT ) + == 0 ) + return 4; +#endif + return 3; +} +BOOL MAP_appendTailObj( int floor, int x, int y, int objindex ) +{ + int mapindex; + int xsiz; + int dataindex; + MAP_Objlink* c; + MAP_Objlink* top; + + mapindex = MAP_getfloorIndex( floor ); + if( mapindex == -1 ) { + //print( "%s:%d:err(fl=%d,x=%d,y=%d)\n", __FILE__, __LINE__, floor, x, y ); + return FALSE; + } + xsiz = MAP_map[mapindex].xsiz; + if( 0 > x || x >= xsiz || 0 >y || y >= MAP_map[mapindex].ysiz ) { + //print( "%s:%d:err(fl=%d,x=%d,y=%d)\n", __FILE__, __LINE__, floor, x, y); + return FALSE; + } + dataindex = y*xsiz+x; + top = MAP_map[mapindex].olink[dataindex]; + if( top == NULL ){ + top = allocateMemory( sizeof(MAP_Objlink) ); + if( top == NULL ) { + //print( "%s:%d:err(fl=%d,x=%d,y=%d)\n", __FILE__, __LINE__, floor, x, y); + return FALSE; + } + top->next = NULL; + top->objindex = objindex; + MAP_map[mapindex].olink[dataindex] = top; + return TRUE; + } + for( c=top ; c->next ; c = c->next ); + c->next = allocateMemory(sizeof(MAP_Objlink)); + if( c->next == NULL )return FALSE; + c->next->next = NULL; + c->next->objindex = objindex; + return TRUE; +} + +BOOL MAP_removeObj( int floor, int x, int y, int objindex ) +{ + int mapindex; + int xsiz; + int dataindex; + MAP_Objlink* c; + MAP_Objlink* last=NULL; + + mapindex = MAP_getfloorIndex( floor ); + if( mapindex == -1 ) { + print( "%s:%d:\n", __FILE__, __LINE__); + return FALSE; + } + xsiz = MAP_map[mapindex].xsiz; + if( 0 > x || x >= xsiz || 0 >y || y >= MAP_map[mapindex].ysiz ) { + print( "%s:%d: ͼ[%d] x:[%d] y:[%d]\n", __FILE__, __LINE__, floor, x, y); + return FALSE; + } + dataindex = y*xsiz+x; + c = MAP_map[mapindex].olink[dataindex]; + while( c ){ + if( c->objindex == objindex ){ + if( last ) + last->next = c->next; + else + MAP_map[mapindex].olink[dataindex] = c->next; + freeMemory( c ); + return TRUE; + } + last = c; + c = c->next; + } + print( "%s:%d:ͼ[%d]\n", __FILE__, __LINE__,floor); + return FALSE; +} + +BOOL _MAP_objmove( char *file, int line, int objindex, int ofloor, int ox, int oy, int nfloor, + int nx, int ny ) +{ +#if 1 + + int oldmapindex; + int oldxsiz; + + int dataindex; + MAP_Objlink* c; + MAP_Objlink* last=NULL; + MAP_Objlink* pointer=NULL; + + oldmapindex = MAP_getfloorIndex( ofloor ); + if( oldmapindex == -1 ) { + print( "%s:%d: ͼ[%d] x:[%d] y:[%d]\n", __FILE__, __LINE__, + ofloor, ox, oy); + return FALSE; + } + oldxsiz = MAP_map[oldmapindex].xsiz; + if( 0 > ox || ox >= oldxsiz + || 0 >oy || oy >= MAP_map[oldmapindex].ysiz ) + { + print( "%s:%d: ͼ[%d] x:[%d] y:[%d]\n", __FILE__, __LINE__, + ofloor, ox, oy); + return FALSE; + } + dataindex = oy*oldxsiz+ox; + c = MAP_map[oldmapindex].olink[dataindex]; + while( c ){ + if( c->objindex == objindex ){ + if( last ) + last->next = c->next; + else + MAP_map[oldmapindex].olink[dataindex] = c->next; + + pointer = c; + pointer->next = NULL; + break; + } + last = c; + c = c->next; + } + if( !pointer ) { + // print( "\n%s:%d:( %d,%d,%d )->(%d,%d,%d)\n", __FILE__, __LINE__, ofloor, ox, oy, nfloor, nx, ny ); + return FALSE; + } + { + int newmapindex; + int newxsiz; + MAP_Objlink* top; + + if( ofloor == nfloor ){ + newmapindex = oldmapindex; + newxsiz = oldxsiz; + }else{ + newmapindex = MAP_getfloorIndex( nfloor ); + if( newmapindex == -1 ) { + print( "%s:%d: ͼ[%d] x:[%d] y:[%d]\n", __FILE__, __LINE__, + nfloor, nx, ny); + return FALSE; + } + newxsiz = MAP_map[newmapindex].xsiz; + } + if( 0 > nx || nx >= newxsiz + || 0 >ny || ny >= MAP_map[newmapindex].ysiz ) + { + print( "%s:%d: ͼ[%d] x:[%d] y:[%d]\n", __FILE__, __LINE__, + nfloor, nx, ny); + return FALSE; + } + + dataindex = ny*newxsiz+nx; + top = MAP_map[newmapindex].olink[dataindex]; + if( top == NULL ){ + top = MAP_map[newmapindex].olink[dataindex] = pointer; + top->next = NULL; + return TRUE; + } + + for( c=top ; c->next ; c = c->next ); + c->next = pointer; + c->next->next = NULL; + return TRUE; + } +#else + if( MAP_removeObj( ofloor,ox,oy,objindex) + && MAP_appendTailObj( nfloor, nx ,ny, objindex ) ) + return TRUE; +#endif + print( "%s:%d:\n", __FILE__, __LINE__); + return FALSE; +} + +MAP_Objlink* _MAP_getTopObj( char *file, int line,int floor, int x, int y ) +{ + int mapindex; + int xsiz; + + mapindex = MAP_getfloorIndex( floor ); + if( mapindex == -1 ) { + //print( "callfrom[%s:%d] %s:%d:err floor(%d,%d,%d)\n", file, line, __FILE__, __LINE__, + // floor, x, y ); + return NULL; + } + + xsiz = MAP_map[mapindex].xsiz; + +#if 1 + if( x >= xsiz) return NULL; + if( y >= MAP_map[mapindex].ysiz ) return NULL; + if( x < 0 ) return NULL; + if( y < 0 ) return NULL; + return MAP_map[mapindex].olink[y*xsiz+x]; +#else + if( 0 <= x && x < xsiz && 0 <= y && y < MAP_map[mapindex].ysiz ) + return MAP_map[mapindex].olink[y*xsiz+x]; + else + return NULL; +#endif +} + +BOOL MAP_addNewObj( int floor, int x, int y, int objindex ) +{ + OBJECT map; + BOOL ret; + + for( map=MAP_getTopObj(floor,x,y) ; map ; map = NEXT_OBJECT(map)) { + if( GET_OBJINDEX(map) == objindex ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return 0; + } + } + ret = MAP_appendTailObj( floor, x, y, objindex ); + if( ret )return 1; + else return -1; +} + +char *MAP_getFloorName( int floor) +{ + int floorindex; + floorindex = MAP_getfloorIndex( floor ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return NULL; + } + return MAP_map[floorindex].string; +} + +#ifdef _MAKE_MAP +int MAP_getFloorXY( int floor, int *x, int *y) +{ + int floorindex; + floorindex = MAP_getfloorIndex( floor ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + *x=MAP_map[floorindex].xsiz; + *y=MAP_map[floorindex].ysiz; + return TRUE; +} +#endif + +BOOL MAP_setObjData( int ff ,int fx, int fy, int obj, int objhp ) +{ + int floorindex,xsiz; + + floorindex = MAP_getfloorIndex( ff ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + xsiz = MAP_map[floorindex].xsiz; + if( fx < 0 || fx >= xsiz ) { + return FALSE; + } + if( fy < 0 || fy >= MAP_map[floorindex].ysiz ) { + return FALSE; + } + MAP_map[floorindex].obj[fy*xsiz+fx] = obj; + return TRUE; +} + +void MAP_sendAroundMapdata( int fl, int fromx, int fromy) +{ + char* mapdata; + RECT seek,ret; + int i,j; + seek.x = fromx; + seek.y = fromy; + seek.width = seek.height = 1; + mapdata = MAP_getdataFromRECT(fl,&seek,&ret); + if( mapdata != NULL ) { + int x = fromx; + int y = fromy; + + for( i =x-MAP_CHAR_DEFAULTSEESIZ/2 ; i <= x+MAP_CHAR_DEFAULTSEESIZ/2 ; i++ ){ + for( j = y-MAP_CHAR_DEFAULTSEESIZ/2 ; j <= y+MAP_CHAR_DEFAULTSEESIZ/2 ; + j ++ ){ + OBJECT object; + for( object = MAP_getTopObj(fl,i,j) ; + object ; + object = NEXT_OBJECT(object ) ){ + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_NOUSE ) continue; + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ) { + int index = OBJECT_getIndex( objindex); + if( CHAR_getInt( index, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) { + int fd = getfdFromCharaIndex( index ); + if( fd != -1 ) { + lssproto_M_send( fd, fl, ret.x,ret.y, + ret.x+ret.width, ret.y+ret.height, + mapdata ); + } + } + } + } + } + } + }else { + print( "ͼݴ %s:%d \n" , __FILE__, __LINE__); + } +} + +#ifdef _STATUS_WATERWORD //ˮ״̬ +int MAP_getMapFloorType( int floor) +{ + int i=0; + int WaterWord[]={8101,8015,8029,8028,8027,817,8007,8100,151,160,161,-1}; + while( WaterWord[i] != -1 ){ + if( floor == WaterWord[i] ){ + return 1; + } + i++; + } + return 0; +} +#endif + +int MAP_getMapMaxNum( void ) +{ + return MAP_idtblsize; +} + + +#ifdef _PLAYER_DIY_MAP +Player_Diy_Map PlayerDiyMap[Player_Diy_Map_NUM]; + +int MAP_intPlayerMap( void ) +{ + struct dirent* ent = NULL; + DIR *pDir; + pDir=opendir("playermap"); + if(pDir==NULL){ + mkdir("playermap",0777); + return TRUE; + } + int i=0; + memset( PlayerDiyMap, 0, sizeof( PlayerDiyMap ) ); + while(NULL != (ent=readdir(pDir))) + { + if(ent->d_name[0] == '.')continue; + if (ent->d_type==8){ + char map[Player_Diy_Map_SIZE]; + char filename[128]; + + sprintf( filename, "playermap/%s", ent->d_name); + FILE *fp = fopen(filename, "rb"); + if (fp==NULL) continue; + fseek( fp, 0L, SEEK_END ); + if(ftell(fp)==Player_Diy_Map_SIZE){ + fseek( fp, 0L, SEEK_SET ); + fread(map, sizeof(map), 1,fp); + memcpy( &PlayerDiyMap[i] , &map, sizeof(map)); + int x,y; + int floorindex = MAP_getfloorIndex( PlayerDiyMap[i].ff ); + int xsiz = MAP_map[floorindex].xsiz; + int ysiz = MAP_map[floorindex].ysiz; + if(strlen(PlayerDiyMap[i].mapname)>0){ + strcpy(MAP_map[floorindex].string, PlayerDiyMap[i].mapname); + } + for(x=0;x0){ + MAP_map[floorindex].tile[y*xsiz+x] = PlayerDiyMap[i].MapPic[x][y].tile; + } + if(PlayerDiyMap[i].MapPic[x][y].obj>0){ + MAP_map[floorindex].obj[y*xsiz+x] = PlayerDiyMap[i].MapPic[x][y].obj; + } + } + } + i++; + if(i>=Player_Diy_Map_NUM)break; + } + fclose(fp); + } + } + + return TRUE; +} + +int MAP_savePlayerMap( int charaindex, int ff ,int fx, int fy, int tile, int obj) +{ + int floorindex,xsiz,ysiz; + floorindex = MAP_getfloorIndex( ff ); + if( floorindex == -1 ) { + print( "%s:%d:err\n", __FILE__, __LINE__); + return FALSE; + } + xsiz = MAP_map[floorindex].xsiz; + if( fx < 0 || fx >= xsiz || fx >= Player_Diy_Map_X ) { + return FALSE; + } + ysiz = MAP_map[floorindex].ysiz; + if( fy < 0 || fy >= ysiz || fy >= Player_Diy_Map_Y ) { + return FALSE; + } + + + int i; + for(i=0;i= MAP_mapnum ){//û㹻Ŀռװµĵͼ10µĿռװµͼ +// print( "û㹻ڴ棬·ڴ档\n"); + MAP_Map* MAP_map2;// + MAP_map2 = allocateMemory( sizeof( MAP_Map ) * MAP_mapnum); + if( MAP_map2 == 0 ){ + print( "ͼʧܣ\n"); + return -1; + } + memcpy( MAP_map2 , MAP_map ,sizeof(MAP_Map) * MAP_mapnum);//֮ǰ + freeMemory( MAP_map );//ͷŵ + MAP_map = 0; + MAP_mapnum += 100; + MAP_map = allocateMemory( sizeof( MAP_Map ) * MAP_mapnum);//¸ͼڴ + if( MAP_map == 0 ){ + print( "·ͼڴʧܣ\n"); + return -1; + } +// print( "·ͼڴɹ\n"); + memcpy( MAP_map , MAP_map2 ,sizeof(MAP_Map) * (MAP_mapnum-100));//֮ǰ + freeMemory( MAP_map2 ); + MAP_map2 = 0; + } + short *tile=0; + short *obj=0; + MAP_Objlink** olink; + int xy = MAP_map[tomapindex].xsiz * MAP_map[tomapindex].ysiz; + tile = allocateMemory( sizeof( short ) * MAP_map[tomapindex].xsiz * MAP_map[tomapindex].ysiz );//ͼڴ + if( tile == NULL ){ + print( "޷ڴͼͼ\n"); + return -1; + } + + obj = allocateMemory( sizeof( short ) * MAP_map[tomapindex].xsiz * MAP_map[tomapindex].ysiz );//ͼڴ + if( obj == NULL ){ + print( "޷ڴͼ\n"); + freeMemory( tile ); + return -1; + } + + olink = allocateMemory( sizeof(MAP_Objlink*) * MAP_map[tomapindex].xsiz * MAP_map[tomapindex].ysiz );//ͼڴ + if( olink == 0 ){ + print( "޷ڴͼ\n"); + freeMemory( obj ); + return -1; + } + memcpy( &tile , &MAP_map[tomapindex].tile ,sizeof(MAP_map[tomapindex].tile)); + memcpy( &obj , &MAP_map[tomapindex].obj ,sizeof(MAP_map[tomapindex].obj)); + for( i=0 ; i< xy ; i ++ ){ + olink[i] = 0; + } + MAP_map[makemapindex].id = mymapid; + MAP_map[makemapindex].xsiz = MAP_map[tomapindex].xsiz; + MAP_map[makemapindex].ysiz = MAP_map[tomapindex].ysiz; + if (strcmp(map_name,"")!=0 ){ + strcpysafe( MAP_map[makemapindex].string , + sizeof(MAP_map[makemapindex].string), + map_name ); + }else { + strcpysafe( MAP_map[makemapindex].string , + sizeof(MAP_map[makemapindex].string), + MAP_map[tomapindex].string ); + } + + MAP_map[makemapindex].tile = tile; + MAP_map[makemapindex].obj = obj; + MAP_map[makemapindex].olink = olink; + MAP_map[makemapindex].startpoint = (2006<<16)+(20 << 8)+(15<<0);//ĬΪͻ峤 + MAP_map[makemapindex].MapType = 0; + + MAP_idjumptbl[mymapid] = makemapindex; + if ( makemapindex >= MAP_mapnum_index) MAP_mapnum_index = makemapindex+1; +fbmap[mymapid-mapstartid] = mapid; +return mymapid; +} + +BOOL MAP_DelMap(int mapid ) +{ + int tomapindex = -1; + if ((tomapindex = MAP_getfloorIndex(mapid)) == -1) + { + print( "ҲĿͼȷϵͼIDǷȷ\n"); + return FALSE; + } + int mapstartid = getCopymapstartingID();//øͼʼID + if (mapid > mapstartid+9999 || mapid < mapstartid) { + print( "ֻͷŸͼ(%d-%d)\n",mapstartid,mapstartid+9999); + return FALSE; + } + MAP_map[tomapindex].id = 0; + if (MAP_map[tomapindex].tile != 0) freeMemory( MAP_map[tomapindex].tile );//ͷŵ + if (MAP_map[tomapindex].obj != 0) freeMemory( MAP_map[tomapindex].obj );//ͷŵ + freeMemory( MAP_map[tomapindex].olink );//ͷŵ + MAP_map[tomapindex].startpoint = -1;//ͷ˳ͼ͵ + MAP_map[tomapindex].MapType = 0;//ͼͣ Ŀǰ + MAP_idjumptbl[mapid] = -1;//ͼ + return TRUE; +} +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/md5.c b/石器时代服务器端最新完整源代码/Serv/gmsv/md5.c new file mode 100644 index 0000000..559b5d2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/md5.c @@ -0,0 +1,214 @@ +#include +#include +#include +#include +#include "md5.h" + + + + typedef unsigned char *POINTER; + typedef unsigned short int UINT2; + typedef unsigned long int UINT4; + + typedef struct + { + UINT4 state[4]; + UINT4 count[2]; + unsigned char buffer[64]; + } MD5_CTX; + + void MD5Init(MD5_CTX *); + void MD5Update(MD5_CTX *, unsigned char *, unsigned int); + void MD5Final(unsigned char [16], MD5_CTX *); + + #define S11 7 + #define S12 12 + #define S13 17 + #define S14 22 + #define S21 5 + #define S22 9 + #define S23 14 + #define S24 20 + #define S31 4 + #define S32 11 + #define S33 16 + #define S34 23 + #define S41 6 + #define S42 10 + #define S43 15 + #define S44 21 + + static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) + #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) + #define H(x, y, z) ((x) ^ (y) ^ (z)) + #define I(x, y, z) ((y) ^ ((x) | (~z))) + + #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + + #define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } + #define GG(a, b, c, d, x, s, ac) { (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } + #define HH(a, b, c, d, x, s, ac) { (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } + #define II(a, b, c, d, x, s, ac) { (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } + + + inline void Encode(unsigned char *output, UINT4 *input, unsigned int len) + { + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } + } + + inline void Decode(UINT4 *output, unsigned char *input, unsigned int len) + { + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + } + + inline void MD5Transform (UINT4 state[4], unsigned char block[64]) + { + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + Decode (x, block, 64); + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + memset ((POINTER)x, 0, sizeof (x)); + } + + inline void MD5Init(MD5_CTX *context) + { + context->count[0] = context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; + } + + inline void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen) + { + unsigned int i, index, partLen; + + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + if ((context->count[0] += ((UINT4)inputLen << 3)) + < ((UINT4)inputLen << 3)) + context->count[1]++; + context->count[1] += ((UINT4)inputLen >> 29); + + partLen = 64 - index; + + if (inputLen >= partLen) { + memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD5Transform(context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); + index = 0; + } + else + i = 0; + + memcpy((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); + } + + inline void MD5Final(unsigned char digest[16], MD5_CTX *context) + { + unsigned char bits[8]; + unsigned int index, padLen; + + Encode (bits, context->count, 8); + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD5Update (context, PADDING, padLen); + MD5Update (context, bits, 8); + Encode (digest, context->state, 16); + memset ((POINTER)context, 0, sizeof (*context)); + } + + void MD5Digest(char *pszInput, unsigned long nInputSize, char *pszOutPut) + { + MD5_CTX context; + unsigned int len = strlen (pszInput); + + MD5Init (&context); + MD5Update (&context, (unsigned char *)pszInput, len); + MD5Final ((unsigned char *)pszOutPut, &context); + } + \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/msignal.c b/石器时代服务器端最新完整源代码/Serv/gmsv/msignal.c new file mode 100644 index 0000000..8c76f3f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/msignal.c @@ -0,0 +1,273 @@ +#include "version.h" +#include +#include +#include + +#include +#include + +#include "buf.h" +#include "net.h" +#include "char.h" +#include "item.h" +#include "object.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "log.h" +#include "petmail.h" +#include "longzoro.h" +#ifdef _ALLBLUES_LUA +#include "mylua/mylua.h" +#endif +/*------------------------------------------------------------ + * ͻئľئئзëĸ + * ئ + ------------------------------------------------------------*/ + +void logerr(char *token) +{ + char tmp[256]; + struct tm now; + time_t timep; + time(&timep); + memcpy(&now, localtime(&timep), sizeof(now)); + + sprintf(tmp, "%04d-%02d-%02d.log", now.tm_year+1900, now.tm_mon+1, now.tm_mday); + + FILE *fp=fopen(tmp,"a+"); + fwrite(token, strlen(token), 1, fp); + fclose(fp); + printf( token ); +} + +void dump() +{ + void *array[10]; + size_t size; + char **strings; + size_t i; + + size = backtrace (array, 10); + strings = backtrace_symbols (array, size); + + printf ("Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++){ + logerr(strings[i]); + } + + free (strings); + +} + +void signalset( void ); + +static void allDataDump( void ) +{ + + int i; + for( i = 0; i < CHAR_getPlayerMaxNum(); i ++ ){ + if(CHAR_CHECKINDEX(i) == TRUE){ + CHAR_charSaveFromConnect(i, FALSE); + } + } + + saveforsaac(); + + storeCharaData(); + + closeAllLogFile(); +#ifdef _PET_ITEM + storeObjects( getStoredir() ); + storePetmail(); +#endif +#ifdef _ALLBLUES_LUA + closemyluaload(); +#endif +} + +/*------------------------------------------------------------ + * ئ + ------------------------------------------------------------*/ +void shutdownProgram( void ) +{ + printf("رSAAC:%d\n",close( acfd )); + printf("رհ󶨶˿:%d\n",close( bindedfd )); + memEnd(); +} + +#ifdef _KEEP_UP_NO_LOGIN +extern char keepupnologin[256]; +#endif +#ifdef _GMSV_DEBUG +char *DebugMainFunction = NULL; +extern time_t initTime; +#endif +extern int player_online; +extern int player_maxonline; +char saacretfunc[255]=""; +char *saacsendfunc = NULL; +int cliretfunc=0; +int clisendfunc=0; + + +#ifdef _ABSOLUTE_DEBUG +char errordata[256]=""; +char charId[32]=""; +int lastfunctime=0; +int debugline=0; +int comnum=-1; +#endif + + +void sigshutdown( int number) +{ + char buff[256]; + + if( number == 0 ){ + printf( "\n\n\nGMSVر\n" ); + }else if( number == 2 ){ +#ifdef _KEEP_UP_NO_LOGIN + if(strlen(keepupnologin) > 0){ + strcpy(keepupnologin,""); + printf( "ѽֹ½״̬\n" ); + return; + } +#endif + printf( "\n\n\nGMSVCTRL+Cֶж\n" ); + }else{ + sprintf( buff, "\n=========Ƿԭ=========\n"); + logerr(buff); + sprintf( buff, "׼Ϣ: %d\n" , number ); + logerr(buff); +#ifdef _GMSV_DEBUG + sprintf( buff, " : %s\n", DebugMainFunction ); + logerr(buff); +#endif + sprintf( buff, ": %d\n", player_online); + logerr(buff); + sprintf( buff, ": %d\n", player_maxonline); + logerr(buff); + sprintf( buff, "SAAC: %s\n", saacretfunc); + logerr(buff); + sprintf( buff, "SAAC: %s\n", saacsendfunc); + logerr(buff); + sprintf( buff, "cli : %d\n", cliretfunc); + logerr(buff); + sprintf( buff, "cli : %d\n", clisendfunc); + logerr(buff); +#ifdef _ABSOLUTE_DEBUG + sprintf( buff, ": %s\n", errordata); + logerr(buff); + sprintf( buff, "˺: %s\n", charId); + logerr(buff); + sprintf( buff, "ִ: %d\n", lastfunctime); + logerr(buff); + sprintf( buff, ": %d\n", debugline); + logerr(buff); + sprintf( buff, "COM ӿ: %d\n", comnum); + logerr(buff); + sprintf( buff, "ǰ汾: %s\n", SERVER_VERSION); + logerr(buff); +#endif + sprintf( buff, "Ҫ󣬱ύĴ\n"); + logerr(buff); + dump(); + + sprintf( buff, "=========Ƿԭ=========\n"); + logerr(buff); + + } + if( number == 0 || number == 2 ){ + printf( ": %d\n", player_online); + printf( ": %d\n", player_maxonline); + printf( "ǰ汾: %s\n", SERVER_VERSION); + } + +#ifdef _GMSV_DEBUG + { + time_t new_t; + int dd,hh,mm,ss; + char buf[128]; + time(&new_t); + if(initTime==0){ + printf( "ʱ: δʼ\n" ); + }else{ + new_t-=initTime; + + dd=(int) new_t / 86400; new_t=new_t % 86400; + hh=(int) new_t / 3600; new_t=new_t % 3600; + mm=(int) new_t / 60; new_t=new_t % 60; + ss=(int) new_t; + + if (dd>0) { + snprintf( buf, sizeof( buf ) , " %d %d Сʱ %d %d 롣",dd,hh,mm,ss); + } else if (hh>0) { + snprintf( buf, sizeof( buf ) , " %d Сʱ %d %d 롣",hh,mm,ss); + } else { + snprintf( buf, sizeof( buf ) , " %d %d 롣",mm,ss); + } + if( number == 0 || number == 2 ){ + printf( "ʱ: %s\n", buf ); + }else{ + sprintf( buff, "ʱ: %s\n", buf ); + logerr(buff); + } + } + } +#endif + remove( "gmsvlog.err2"); + rename( "gmsvlog.err1", "gmsvlog.err2" ); + rename( "gmsvlog.err", "gmsvlog.err1" ); + rename( "gmsvlog", "gmsvlog.err" ); + + allDataDump(); + + signal(SIGINT , SIG_IGN ); + signal(SIGQUIT, SIG_IGN ); + signal(SIGILL, SIG_IGN ); + signal(SIGTRAP, SIG_IGN ); + signal(SIGIOT, SIG_IGN ); + signal(SIGBUS, SIG_IGN ); + signal(SIGFPE, SIG_IGN ); + signal(SIGKILL, SIG_IGN ); + signal(SIGSEGV, SIG_IGN ); + signal(SIGPIPE, SIG_IGN ); + signal(SIGTERM, SIG_IGN ); + + shutdownProgram(); + exit(number); +} + + + +void signalset( void ) +{ + // CoolFish: Test Signal 2001/10/26 + print("\nʼȡź..\n"); + + print("SIGINT:%d\n", SIGINT); + print("SIGQUIT:%d\n", SIGQUIT); + print("SIGFPE:%d\n", SIGILL); + print("SIGTRAP:%d\n", SIGTRAP); + print("SIGIOT:%d\n", SIGIOT); + print("SIGBUS:%d\n", SIGBUS); + print("SIGFPE:%d\n", SIGFPE); + print("SIGKILL:%d\n", SIGKILL); + print("SIGSEGV:%d\n", SIGSEGV); + print("SIGPIPE:%d\n", SIGPIPE); + print("SIGTERM:%d\n", SIGTERM); + + signal( SIGINT , sigshutdown ); + signal( SIGQUIT, sigshutdown ); + signal( SIGILL, sigshutdown ); + signal( SIGTRAP, sigshutdown ); + signal( SIGIOT, sigshutdown ); + signal( SIGBUS, sigshutdown ); + signal( SIGFPE, sigshutdown ); + signal( SIGKILL, sigshutdown ); + signal( SIGSEGV, sigshutdown ); + signal( SIGPIPE, SIG_IGN ); + signal( SIGTERM, sigshutdown ); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/ablua.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/ablua.c new file mode 100644 index 0000000..10ccff2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/ablua.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include "autil.h" +#include "util.h" +#include "mylua/mylua.h" +#include "mylua/base.h" +#include "longzoro/version.h" + +#ifdef _ALLBLUES_LUA + +extern MY_Lua MYLua; + +void LoadAllbluesLUA(char *path) +{ + struct dirent* ent = NULL; + char filename[256]; + DIR *pDir; + pDir=opendir(path); + + while(NULL != (ent=readdir(pDir))) + { + if(ent->d_name[0] == '.')continue; + if (ent->d_type==8){ + if( strcmptail( ent->d_name, ".allblues" ) == 0 +#ifndef _NOT_NOCRYPTO_LUA + || strcmptail( ent->d_name, ".lua" ) == 0 +#endif + ){ + char filename[256]; + memset(filename, 0, 256); + sprintf(filename, "%s/%s", path, ent->d_name); + + myluaload(filename); + + } + }else{ + sprintf(filename, "%s/%s", path, ent->d_name); + LoadAllbluesLUA(filename); + } + } +} + +void ReLoadAllbluesLUA(char *filename) +{ + remyluaload(filename); +} + +void NewLoadAllbluesLUA(char *filename) +{ + char token[256]; + if(strlen(filename)>0){ + sprintf(token, "data/ablua/%s", filename); + myluaload(token); + }else{ + LoadAllbluesLUA("data/ablua"); + } +} + +const int getCharBaseValue(lua_State *L, int narg, CharBase *charbase, int num) +{ + if(!lua_isnumber(L, narg)){ + size_t l; + const char *data = luaL_checklstring(L, narg, &l); + + if( data == NULL || data[0] == '\0' ){ + return -1; + } + char field[64]; + int line = 1; + int i; + int value = 0; + while(getStringFromIndexWithDelim( data, "|", line, field, sizeof( field)) == TRUE) + { + for( i=0 ; i < num; i++ ){ + if( strcmp( charbase[i].field, field ) == 0 ){ + value |= charbase[i].element; + break; + } + } + + if(i == num){ + print("\ncharbaseȱʧֶ[%s]\n",field); + return -1; + } + line++; + } + + return value; + }else{ + return luaL_checkint(L, narg); + } +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/battlebase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/battlebase.c new file mode 100644 index 0000000..99e4791 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/battlebase.c @@ -0,0 +1,320 @@ +#include +#include "longzoro/version.h" +#include "char_base.h" +#include "enemy.h" +#include "object.h" +#include "char.h" +#include "lssproto_serv.h" +#include "battle.h" +#include "battle_command.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "mylua/mylua.h" +#include "mylua/base.h" +#ifdef _ALLBLUES_LUA + +static int CreateVsEnemy (lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int npcindex = luaL_checkint(L, 2); + int enemytable[11]; + int i; + for( i = 0; i < 11; i ++ ) { + enemytable[i] = -1; + } + luaL_checktype(L, 3, LUA_TTABLE); + int n = luaL_getn(L, 3); + int id = 0; + for(i = 0; i < n; i++){ + int enemyid = getArrayInt(L, i); + int curEnemy = ENEMY_getEnemyArrayFromId( enemyid ); + + if( ENEMY_CHECKINDEX( curEnemy) ) { + enemytable[id++] = curEnemy; + }else{ + enemytable[i] = -1; + } + } + int ret = BATTLE_CreateVsEnemyNew(charaindex, npcindex, enemytable); + if( ret == 0 ) { + if(npcindex>-1){ + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_INIT ); + CHAR_sendBattleEffect( npcindex, ON); + } + lua_pushinteger(L, CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX)); + return 1; + }else{ + return 0; + } +} + +static int CreateVsEnemyLv (lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + const int npcindex = luaL_checkint(L, 2); + char *enemytablebuf = luaL_checklstring(L, 3, &l); + char *enemylvtablebuf = luaL_checklstring(L, 4, &l); + char tmpenemytablebuf[10]; + char tmpenemylvtablebuf[10]; + int j=1; + int k=1; + int enemytable[11]; + int enemylvtable[11]; + int i; + for( i = 0; i < 11; i ++ ) { + enemytable[i] = -1; + enemylvtable[i] = -1; + } + while(getStringFromIndexWithDelim(enemytablebuf,",",j,tmpenemytablebuf,sizeof(tmpenemytablebuf))!=FALSE){ + int enemyid = atoi(tmpenemytablebuf); + int curEnemy = ENEMY_getEnemyArrayFromId( enemyid ); + if( ENEMY_CHECKINDEX( curEnemy) ) { + enemytable[j-1] = curEnemy; + }else{ + enemytable[j-1] = -1; + } + j++; + } + while(getStringFromIndexWithDelim(enemylvtablebuf,",",k,tmpenemylvtablebuf,sizeof(tmpenemylvtablebuf))!=FALSE){ + enemylvtable[k-1] = atoi(tmpenemylvtablebuf); + k++; + } + if(j != k){ + lua_pushinteger(L, -1); + return 0; + } + int ret = BATTLE_CreateVsEnemyLvNew(charaindex, npcindex, enemytable,enemylvtable); + if( ret == 0 ) { + if(npcindex>-1){ + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_INIT ); + CHAR_sendBattleEffect( npcindex, ON); + } + lua_pushinteger(L, CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX)); + return 1; + }else{ + return 0; + } +} + +static int getCharOne(lua_State *L) +{ + const int battle = luaL_checkint(L, 1); + const int num = luaL_checkint(L, 2); + const int side = luaL_checkint(L, 3); + + lua_pushinteger(L, BattleArray[battle].Side[side].Entry[num].charaindex); + + return 1; +} + +static int Exit(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int battleindex = luaL_checkint(L, 2); + + BATTLE_Exit( charaindex, battleindex ); + + return 1; +} + +#ifdef _ALLBLUES_LUA_1_4 +static CharBase BattleBaseEvent[] = { + {{"¼"}, BATTLE_FINISH} + ,{{"¼"}, BATTLE_ESCAPE} +}; + +static int CreateRandVsPlayer (lua_State *L) +{ + const int floorid = luaL_checkint(L, 1); + int charaindex1 = -1, charaindex2 = -1; + int num = 0; + int i = 0; + int playernum = CHAR_getPlayerMaxNum(); + for (i = 0; i < playernum; i++){ + if (CHAR_getCharUse(i) == FALSE) continue; + if ( !CHAR_CHECKINDEX( i ) )continue; + if ( CHAR_getInt( i, CHAR_FLOOR ) == floorid ) { + if (CHAR_getWorkInt(i, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE){ + if(charaindex1 == -1){ + charaindex1 = i; + }else{ + charaindex2 = i; + } + if(CHAR_CHECKINDEX( charaindex1 ) && CHAR_CHECKINDEX( charaindex2 ) ){ + BATTLE_CreateVsPlayer(charaindex1, charaindex2); + num ++; + } + } + } + } + + lua_pushinteger(L, num); + + return 1; +} + +static int CreateVsPlayer(lua_State *L) +{ + const int charaindex1 = luaL_checkint(L, 1); + const int charaindex2 = luaL_checkint(L, 2); + + if(CHAR_CHECKINDEX( charaindex1 ) && CHAR_CHECKINDEX( charaindex2 ) ){ + if( CHAR_getWorkInt( charaindex1, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE + && CHAR_getWorkInt( charaindex2, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ + if(BATTLE_CreateVsPlayer(charaindex1, charaindex2) == 0){ + lua_pushinteger(L, CHAR_getWorkInt( charaindex1, CHAR_WORKBATTLEINDEX)); + return 1; + } + } + } + lua_pushinteger(L, -1); + return 1; +} + +static int setLUAFunctionPointer(lua_State *L) +{ + size_t l; + const int battleindex = luaL_checkint(L, 1); + const int functype = getCharBaseValue(L, 2, BattleBaseEvent, arraysizeof(BattleBaseEvent)); + char *luafunctable=luaL_checklstring(L, 3, &l); + + BATTLE_setLUAFunction(battleindex, functype, L, luafunctable); + + return 1; +} + +static int WatchEntry(lua_State *L) +{ + const int meindex = luaL_checkint(L, 1); + const int toindex = luaL_checkint(L, 2); + + BATTLE_WatchEntry(meindex, toindex); + + return 1; +} + +static int NewEntry(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int battleindex = luaL_checkint(L, 2); + const int side = luaL_checkint(L, 3); + int fd = getfdFromCharaIndex(charaindex); + int iRet = BATTLE_NewEntry(charaindex, battleindex, side); + if( iRet == 0 ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_RESCUE ); + iRet = BATTLE_PetDefaultEntry( + charaindex, + battleindex, + side + ); + } + if( iRet == 0 ){ + int flg; + if( CHAR_getInt( charaindex, CHAR_DEFAULTPET ) >= 0 ){ + int pindex = CHAR_getCharPet( charaindex, CHAR_getInt( charaindex, CHAR_DEFAULTPET ) ); + CHAR_setWorkInt( pindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_RESCUE ); + } + if( fd != -1 ){ + lssproto_EN_send( fd, BattleArray[battleindex].type, BattleArray[battleindex].field_no ); + } + flg = (BattleArray[battleindex].Side[side].flg & BSIDE_FLG_HELP_OK)? TRUE:FALSE; + lssproto_HL_send( fd, flg); + char szBuffer[256]; + sprintf( szBuffer, "BP|%X|%X|%X", + BATTLE_Index2No( battleindex, charaindex ), BP_FLG_JOIN, CHAR_getInt(charaindex, CHAR_MP ) ); + BATTLE_CommandSend( charaindex, szBuffer ); + lua_pushinteger(L, 1); + }else{ + if( fd != -1 ){ + lssproto_EN_send( fd, FALSE, BattleArray[battleindex].field_no ); + } + lua_pushinteger(L, 0); + } + + return 1; +} +#endif + +#ifdef _ALLBLUES_LUA_1_9 +static int CreateForWatcher(lua_State *L) +{ + const int meindex = luaL_checkint(L, 1); + const int batleindex = luaL_checkint(L, 2); + + BATTLE_CreateForWatcher(meindex, batleindex); + + return 1; +} + +static int checkindex(lua_State *L) +{ + const int batleindex = luaL_checkint(L, 1); + + lua_pushinteger(L, BATTLE_CHECKINDEX(batleindex)); + + return 1; +} + +static int getType(lua_State *L) +{ + const int batleindex = luaL_checkint(L, 1); + + lua_pushinteger(L, BATTLE_getType(batleindex)); + + return 1; +} + +#ifdef _BATTLE_TIMESPEED +static int getCreateTime(lua_State *L) +{ + const int batleindex = luaL_checkint(L, 1); + + lua_pushinteger(L, BATTLE_getCreateTime(batleindex)); + + return 1; +} +#endif + +static int getBattleFloor(lua_State *L) +{ + const int battleindex = luaL_checkint(L, 1); + + lua_pushinteger(L, BATTLE_getBattleFloor(battleindex)); + + return 1; +} +#endif +static const luaL_Reg battlelib[] = { + {"CreateVsEnemy", CreateVsEnemy}, + {"CreateVsEnemyLv", CreateVsEnemyLv}, + {"getCharOne", getCharOne}, +#ifdef _ALLBLUES_LUA_1_4 + {"CreateRandVsPlayer", CreateRandVsPlayer}, + {"CreateVsPlayer", CreateVsPlayer}, + {"setLUAFunctionPointer", setLUAFunctionPointer}, + {"WatchEntry", WatchEntry}, + {"NewEntry", NewEntry}, +#endif +#ifdef _ALLBLUES_LUA_1_9 + {"CreateForWatcher", CreateForWatcher}, + {"checkindex", checkindex}, + {"getType", getType}, +#ifdef _BATTLE_TIMESPEED + {"getCreateTime", getCreateTime}, +#endif + {"getBattleFloor", getBattleFloor}, +#endif + {"Exit", Exit}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_Battle (lua_State *L) { + luaL_register(L, "battle", battlelib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/charbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/charbase.c new file mode 100644 index 0000000..df51143 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/charbase.c @@ -0,0 +1,2437 @@ +#include +#include "char.h" +#include "battle.h" +#include "object.h" +#include "char_base.h" +#include "enemy.h" +#include "mylua/base.h" +#include "npcutil.h" +#include "readmap.h" +#include "log.h" +#include "pet.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "longzoro/version.h" +#include "handletime.h" +#include "item_event.h" +#include "lssproto_serv.h" +#include "shop.h" +#ifdef _ALLBLUES_LUA +#include "mylua/mylua.h" +extern MY_Lua MYLua; +static CharBase CharBaseWorkInt[] = { + {{""}, CHAR_WORKOBJINDEX} +#ifdef _FONT_SIZE + ,{{"ֺ"}, CHAR_WORKFONTSIZE} +#endif + ,{{"ս"}, CHAR_WORKBATTLEMODE} + ,{{""}, CHAR_WORKPARTYMODE} + ,{{"ս"}, CHAR_WORKBATTLEINDEX} + ,{{"սӿ1"}, CHAR_WORKBATTLECOM1} + ,{{"սӿ2"}, CHAR_WORKBATTLECOM2} + ,{{"NPCʱ1"}, CHAR_NPCWORKINT1} + ,{{"NPCʱ2"}, CHAR_NPCWORKINT2} + ,{{"NPCʱ3"}, CHAR_NPCWORKINT3} + ,{{"NPCʱ4"}, CHAR_NPCWORKINT4} + ,{{"NPCʱ5"}, CHAR_NPCWORKINT5} + ,{{"NPCʱ6"}, CHAR_NPCWORKINT6} + ,{{"NPCʱ7"}, CHAR_NPCWORKINT7} + ,{{"NPCʱ8"}, CHAR_NPCWORKINT8} + ,{{"NPCʱ9"}, CHAR_NPCWORKINT9} + ,{{"NPCʱ10"}, CHAR_NPCWORKINT10} + ,{{"NPCʱ11"}, CHAR_NPCWORKINT11} + ,{{"NPCʱ12"}, CHAR_NPCWORKINT12} + ,{{"NPCʱ13"}, CHAR_NPCWORKINT13} + ,{{"ģʽ"}, CHAR_WORKPETFOLLOWMODE} + ,{{"Ա1"}, CHAR_WORKPARTYINDEX1} + ,{{"Ա2"}, CHAR_WORKPARTYINDEX2} + ,{{"Ա3"}, CHAR_WORKPARTYINDEX3} + ,{{"Ա4"}, CHAR_WORKPARTYINDEX4} + ,{{"Ա5"}, CHAR_WORKPARTYINDEX5} + ,{{"HP"}, CHAR_WORKMAXHP} + ,{{"MP"}, CHAR_WORKMAXMP} + ,{{""}, CHAR_WORKATTACKPOWER} + ,{{""}, CHAR_WORKDEFENCEPOWER} + ,{{""}, CHAR_WORKQUICK} + ,{{""}, CHAR_WORKFIXVITAL} + ,{{""}, CHAR_WORKFIXSTR} + ,{{""}, CHAR_WORKFIXTOUGH} + ,{{"ٶ"}, CHAR_WORKFIXDEX} + ,{{"ͼ"}, CHAR_WORKFMFLOOR} + ,{{""}, CHAR_WORKATTACKPOWER} + ,{{""}, CHAR_WORKDEFENCEPOWER} + ,{{""}, CHAR_WORKQUICK} + ,{{""}, CHAR_WORKDBATTLEESCAPE} + ,{{"ʱ"}, CHAR_WORKITEM_ADDEXPTIME} + ,{{"ӳ"}, CHAR_WORKITEM_ADDEXP} +#ifdef _OFFLINE_SYSTEM + ,{{""}, CHAR_WORK_OFFLINE} +#endif + ,{{"þ"}, CHAR_WORKGETEXP} +#ifdef _AUTO_PK + ,{{"ԶPK"}, CHAR_WORK_AUTOPK} + ,{{"ԶPK"}, CHAR_WORK_AUTOPK_DEAD} +#endif +#ifdef _SPECIAL_COUNTER + ,{{""}, CHAR_WORK_COUNTER} +#endif +#ifdef _SPECIAL_TIMER + ,{{"ʱ"}, CHAR_WORK_TIMER} +#endif +#ifdef _STREET_VENDOR + ,{{"̯"}, CHAR_WORKSTREETVENDOR} +#endif +#ifdef _RECORD_IP + ,{{"IP"}, CHAR_WORK_RECORD_IP} +#endif +#ifdef _ONLINE_TIME + ,{{"½ʱ"}, CHAR_WORK_LOGIN_TIME} +#endif +#ifdef _NEWCLISETSERVID + ,{{"ID"}, CHAR_WORK_SERVID} +#endif + //,{{"PKʱ"}, CHAR_WORKDBATTLETIME} +#ifdef _MIND_ICON + ,{{"˼"}, CHAR_MIND_NUM} +#endif +#ifdef _PLAYER_EFFECT + ,{{"Ч"}, CHAR_PLAYER_EFFECT} +#endif +#ifdef _MO_PLAYER_EFFECT + ,{{"Ч"}, CHAR_PLAYER_EFFECT_PRIORITY} + ,{{"սЧ"}, CHAR_PLAYER_EFFECT_PET} + ,{{"װЧ"}, CHAR_PLAYER_EFFECT_ITEM} +#endif +#ifdef FAMILY_MANOR_ + ,{{"ׯ԰Ч"}, CHAR_PLAYER_EFFECT_MANOR} +#endif +#ifdef _SINGLE_ONLINE + ,{{""}, CHAR_WORK_SINGLE_ONLINE} +#endif + ,{{""}, CHAR_WORKPLAYERINDEX} +#ifdef _NPC_EVENT_NOTICE + ,{{"NOTICE"}, CHAR_WORK_NOTICE} +#endif +#ifdef _MO_LUA_RESIST + ,{{""}, CHAR_WORKMODPOISON} + ,{{"鿹"}, CHAR_WORKMODPARALYSIS} + ,{{"˯"}, CHAR_WORKMODSLEEP} + ,{{"ʯ"}, CHAR_WORKMODSTONE} + ,{{"ƿ"}, CHAR_WORKMODDRUNK} + ,{{"쿹"}, CHAR_WORKMODCONFUSION} + ,{{"鿹"}, CHAR_WORKMODWEAKEN} + ,{{"翹"}, CHAR_WORKMODDEEPPOISON} + ,{{"Ͽ"}, CHAR_WORKMODBARRIER} + ,{{"Ĭ"}, CHAR_WORKMODNOCAST} + + ,{{""}, CHAR_WORK_RESIST_POISON} + ,{{"鿹"}, CHAR_WORK_RESIST_PARALYSIS} + ,{{"˯"}, CHAR_WORK_RESIST_SLEEP} + ,{{"ʯ"}, CHAR_WORK_RESIST_STONE} + ,{{"ƿ"}, CHAR_WORK_RESIST_DRUNK} + ,{{"쿹"}, CHAR_WORK_RESIST_CONFUSION} + ,{{"鿹"}, CHAR_WORK_RESIST_WEAKEN} + ,{{"翹"}, CHAR_WORK_RESIST_DEEPPOISON} + ,{{"Ͽ"}, CHAR_WORK_RESIST_BARRIER} + ,{{"Ĭ"}, CHAR_WORK_RESIST_NOCAST} +#endif +}; + +static CharBase CharBaseWorkChar[] = { + {{"NPCʱ1"}, CHAR_NPCWORKCHAR1} + ,{{"NPCʱ2"}, CHAR_NPCWORKCHAR2} + ,{{"NPCʱ3"}, CHAR_NPCWORKCHAR3} + ,{{"NPCʱ4"}, CHAR_NPCWORKCHAR4} + ,{{"NPCʱ5"}, CHAR_NPCWORKCHAR5} + ,{{"NPCʱ6"}, CHAR_NPCWORKCHAR6} +#ifdef _STREET_VENDOR + ,{{"̯"}, CHAR_STREETVENDOR_NAME} +#endif +#ifdef _NEWCLISETMAC + ,{{"MAC"}, CHAR_WORK_MAC} +#endif +}; + +static CharBase CharBaseValue[] = { + {{""}, 0} + ,{{""}, 1} + ,{{""}, 2} + ,{{""}, 3} + ,{{""}, 4} + ,{{""}, 5} + ,{{""}, 6} + ,{{""}, 7} + ,{{""}, CHAR_TYPENONE} + ,{{""}, CHAR_TYPEPLAYER} + ,{{""}, CHAR_TYPEENEMY} + ,{{""}, CHAR_TYPEPET} +#ifdef _ALLBLUES_LUA + ,{{"LUA"}, CHAR_TYPELUANPC} +#endif +#ifdef _PLAYER_NPC + ,{{""}, CHAR_TYPEPLAYERNPC} + ,{{""}, CHAR_TYPEPLAYERPETNPC} +#endif +}; + +static CharBase CharBaseWorkValue[] = { + {{""}, CHAR_PARTY_NONE} + ,{{"ӳ"}, CHAR_PARTY_LEADER} + ,{{"Ա"}, CHAR_PARTY_CLIENT} + ,{{"ս"}, BATTLE_CHARMODE_NONE} + ,{{"սʼ"}, BATTLE_CHARMODE_INIT} + ,{{"ȴս"}, BATTLE_CHARMODE_C_WAIT} + ,{{"ȷս"}, BATTLE_CHARMODE_C_OK} + ,{{"ս"}, BATTLE_CHARMODE_RESCUE} + ,{{"ս"}, BATTLE_CHARMODE_FINAL} + ,{{"սʼ"}, BATTLE_CHARMODE_WATCHINIT} + ,{{"ûм"}, FMMEMBER_NONE} + ,{{""}, FMMEMBER_APPLY} + ,{{"峤"}, FMMEMBER_LEADER} + ,{{"Ա"}, FMMEMBER_MEMBER} + ,{{""}, FMMEMBER_ELDER} +}; + +static CharBase CharBaseInt[] = { + {{"ͼ"}, CHAR_BASEIMAGENUMBER} + ,{{"ԭͼ"}, CHAR_BASEBASEIMAGENUMBER} + ,{{"ͷ"}, CHAR_FACEIMAGENUMBER} + ,{{"浵"}, CHAR_SAVEINDEXNUMBER} + ,{{"ͼ"}, CHAR_FLOOR} + ,{{"X"}, CHAR_X} + ,{{"Y"}, CHAR_Y} + ,{{""}, CHAR_DIR} + ,{{"ȼ"}, CHAR_LV} + ,{{"ʯ"}, CHAR_GOLD} + ,{{"HP"}, CHAR_HP} + ,{{"MP"}, CHAR_MP} + ,{{"MP"}, CHAR_MAXMP} + ,{{""}, CHAR_VITAL} + ,{{""}, CHAR_STR} + ,{{""}, CHAR_TOUGH} + ,{{"ٶ"}, CHAR_DEX} + ,{{""}, CHAR_EARTHAT} + ,{{"ˮ"}, CHAR_WATERAT} + ,{{""}, CHAR_FIREAT} + ,{{""}, CHAR_WINDAT} + ,{{"ս"}, CHAR_DEFAULTPET} + ,{{""}, CHAR_CHARM} + ,{{""}, CHAR_LUCK} + ,{{""}, CHAR_DEADCOUNT} + ,{{"·"}, CHAR_WALKCOUNT} + ,{{"˵"}, CHAR_TALKCOUNT} + ,{{"𻵴"}, CHAR_DAMAGECOUNT} + ,{{""}, CHAR_GETPETCOUNT} + ,{{"ɱ"}, CHAR_KILLPETCOUNT} + ,{{""}, CHAR_DEADPETCOUNT} + ,{{"ʼ"}, CHAR_SENDMAILCOUNT} + ,{{"ϳɴ"}, CHAR_MERGEITEMCOUNT} + ,{{"PK"}, CHAR_DUELBATTLECOUNT} + ,{{"PKӮ"}, CHAR_DUELWINCOUNT} + ,{{"PK"}, CHAR_DUELLOSECOUNT} + ,{{"PKʤ"}, CHAR_DUELSTWINCOUNT} + ,{{"PK"}, CHAR_DUELSTLOSECOUNT} + ,{{"PKʤ"}, CHAR_DUELMAXSTWINCOUNT} + ,{{""}, CHAR_WHICHTYPE} + ,{{"ѭ¼ʱ"}, CHAR_LOOPINTERVALAB} +#ifdef _NEWOPEN_MAXEXP + ,{{"ܾ"}, CHAR_OLDEXP} +#endif + ,{{"ǰ"}, CHAR_EXP} + ,{{"ܵ"}, CHAR_SKILLUPPOINT} + ,{{""}, CHAR_LEVELUPPOINT} + ,{{"DP"}, CHAR_DUELPOINT} + ,{{""}, CHAR_EXP} + ,{{""}, CHAR_LASTTALKELDER} + ,{{"ת"}, CHAR_TRANSMIGRATION} + ,{{""}, CHAR_SILENT} + ,{{""}, CHAR_FMINDEX} + ,{{"λ"}, CHAR_FMLEADERFLAG} + ,{{""}, CHAR_FMSPRITE} +#ifdef _NEW_RIDEPETS + ,{{"֤"}, CHAR_LOWRIDEPETS} +#endif +#ifdef _RIDE_CF + ,{{"֤1"}, CHAR_LOWRIDEPETS1} +#ifdef _ADD_RIDE_CF + ,{{"֤2"}, CHAR_LOWRIDEPETS2} +#endif +#endif + ,{{""}, CHAR_BANKGOLD} + ,{{""}, CHAR_RIDEPET} + ,{{""}, CHAR_CRITIAL} + ,{{""}, CHAR_COUNTER} + ,{{"ʱ"}, CHAR_LASTLEAVETIME} +#ifdef _GAMBLE_BANK +// ,{{"ij"}, CHAR_RIDEPET} +#endif +#ifdef _DROPSTAKENEW + ,{{"ij"}, CHAR_GAMBLENUM} +#endif +#ifdef _TRUMP_EQUIPMENT + ,{{"Ч"}, CHAR_TRUMP_EFFECT} +#endif +#ifdef _PERSONAL_FAME // Arminius 8.30: + ,{{""}, CHAR_FAME} +#endif +#ifdef _ATTACK_EFFECT + ,{{"Ч"}, CHAR_ATTACK_EFFECT} +#endif +#ifdef _ATTACK_MAGIC + ,{{"ħ"}, CHAR_EARTH_EXP} + ,{{"ˮħ"}, CHAR_WATER_EXP} + ,{{"ħ"}, CHAR_FIRE_EXP} + ,{{"ħ"}, CHAR_WIND_EXP} + ,{{"ħ"}, CHAR_EARTH_RESIST} + ,{{"ˮħ"}, CHAR_WATER_RESIST} + ,{{"ħ"}, CHAR_FIRE_RESIST} + ,{{"ħ"}, CHAR_WIND_RESIST} + ,{{"ħȾ"}, CHAR_EARTH_ATTMAGIC_EXP} + ,{{"ˮħȾ"}, CHAR_WATER_ATTMAGIC_EXP} + ,{{"ħȾ"}, CHAR_FIRE_ATTMAGIC_EXP} + ,{{"ħȾ"}, CHAR_WIND_ATTMAGIC_EXP} + ,{{"ħԾֵ"}, CHAR_EARTH_DEFMAGIC_EXP} + ,{{"ˮħԾֵ"}, CHAR_WATER_DEFMAGIC_EXP} + ,{{"ħԾֵ"}, CHAR_FIRE_DEFMAGIC_EXP} + ,{{"ħԾֵ"}, CHAR_WIND_DEFMAGIC_EXP} +#endif +#ifdef _CHAR_PROFESSION // WON ADD ְҵ + ,{{"ְҵ"}, PROFESSION_CLASS} + ,{{"ְҵȼ"}, PROFESSION_LEVEL} + ,{{"ܵ"}, PROFESSION_SKILL_POINT} + ,{{"Ӷѵ"}, ATTACHPILE} + ,{{""}, PROFESSION_FIRE_P} + ,{{""}, PROFESSION_ICE_P} + ,{{""}, PROFESSION_THUNDER_P} + ,{{""}, PROFESSION_FIRE_R} + ,{{""}, PROFESSION_ICE_R} + ,{{"׿"}, PROFESSION_THUNDER_R} +#endif +#ifdef _NEW_MANOR_LAW + ,{{""}, CHAR_MOMENTUM} +#endif +#ifdef _VIP_SERVER + ,{{""}, CHAR_AMPOINT} +#endif +#ifdef _VIP_RIDE + ,{{"Ա"}, CHAR_VIPRIDE} + ,{{"ԱЧ"}, CHAR_VIPTIME} +#endif +#ifdef _ITEM_PET_LOCKED + ,{{"ȫ"}, CHAR_LOCKED} +#endif +#ifdef _ONLINE_SHOP + ,{{""}, CHAR_BJ} +#endif + ,{{"ģʽAI"}, CHAR_MODAI} + ,{{"ɱAI"}, CHAR_VARIABLEAI} + ,{{"輼λ"}, CHAR_SLOT} + ,{{"ID"}, CHAR_PETID} + ,{{"ID"}, CHAR_PETENEMYID} + ,{{"ػ"}, CHAR_PETFAMILY} + ,{{"ֵ"}, CHAR_ALLOCPOINT} + ,{{"ɳ"}, CHAR_PETRANK} + ,{{"Ƶȼ"}, CHAR_LIMITLEVEL} +#ifdef _PET_BEATITUDE + ,{{"ֵ"}, CHAR_BEATITUDE} +#endif +#ifdef _CAMEO_MONEY + ,{{""}, CHAR_CAMEO} +#endif +#ifdef _MISSION_TRAIN + ,{{""}, CHAR_MISSIONTRAIN_NUM} + ,{{"ʱ"}, CHAR_MISSIONTRAIN_TIME} +#endif +#ifdef _PET_EVOLVE + ,{{""}, CHAR_EVOLVE} +#endif +#ifdef _ONLINE_TIME + ,{{"ʱ"}, CHAR_ONLINE_TIME} +#endif + +#ifdef _FLOOR_DIFI_FIELD + ,{{"¥ʱ"}, CHAR_FLOORDIFI_TIME} +#endif +#ifdef _ACTIVE_GAME + ,{{""}, CHAR_ACTIVE} +#endif +#ifdef _SUPER + ,{{"Ʒ"}, CHAR_SUPER} +#endif +#ifdef _ALLDOMAN + ,{{"Ӣ۳ƺ"}, CHAR_HEROFLOOR} +#endif + +#ifdef _PLAYER_TITLE + ,{{"ƺŵȼ"}, CHAR_TITLE_LV} + ,{{"ƺʱ"}, CHAR_TITLE_TIME} +#endif +#ifdef _MISSION_TIME + ,{{"ʱ"}, CHAR_MISSION_TIME} +#endif +#ifdef _PETCOM_ + ,{{""}, CHAR_YHP} + ,{{""}, CHAR_YATK} + ,{{""}, CHAR_YDEF} + ,{{"ٶ"}, CHAR_YQUICK} + ,{{"ȼ"}, CHAR_YLV} +#endif +#ifdef _PET_FUSION + ,{{"ںϳ"}, CHAR_FUSIONBEIT} + ,{{"ںϵ"}, CHAR_FUSIONRAISE} +#endif +#ifdef _REGISTRATION_TIME + ,{{"ǩʱ"}, CHAR_REGISTRATION_TIME} + ,{{"ǩ"}, CHAR_REGISTRATION_COUNT} + ,{{"ǩʱ"}, CHAR_REGISTRATION_ONLINE_TIME} +#endif +#ifdef _SPECIAL_COUNTER + ,{{""}, CHAR_SPCOUNTER} +#endif +#ifdef _SPECIAL_TIMER + ,{{"ʱ"}, CHAR_SPTIMER} +#endif +#ifdef _OFFLINE_TIME + ,{{"ʱ"}, CHAR_OFFLINE_TIME} +#endif +#ifdef _FAME_REG_TIME + ,{{"ǩʱ"}, CHAR_FAME_REG_TIME} +#endif +#ifdef _PET_VALIDITY + ,{{"Ч"}, CHAR_PETVALIDITY} +#endif +#ifdef _TENSE_FIELD + ,{{"ʱֶ"}, CHAR_TENSE_FIELD} +#endif +#ifdef _FM_JOINLIMIT + ,{{"ʱ"}, CHAR_FMTIMELIMIT} +#endif +#ifdef _NEW_ITEM_ + ,{{"״̬"}, CHAR_NEWITEMFLG} +#endif +#ifdef _MO_PLAYER_EFFECT + ,{{"ĬЧ"}, CHAR_PLAYER_EFFECT_DEFAULT} +#endif +#ifdef _PETCOM_ + ,{{"ԤѪ"}, CHAR_YHP} + ,{{"Ԥ⹥"}, CHAR_YATK} + ,{{"Ԥ"}, CHAR_YDEF} + ,{{"Ԥ"}, CHAR_YQUICK} + ,{{"Ԥȼ"}, CHAR_YLV} +#endif +#ifdef _MO_NO_WALK + ,{{""}, CHAR_NO_WALK} +#endif +#ifdef _NEW_TITLE + ,{{"Ĭϳƺ"}, CHAR_TITLE_DEFAULT} + ,{{"ƺ״̬1"}, CHAR_TITLE1} + ,{{"ƺ״̬2"}, CHAR_TITLE2} + ,{{"ƺ״̬3"}, CHAR_TITLE3} +#endif +#ifdef _TRUMP_EQUIPMENT + ,{{"״̬"}, CHAR_TRUMPFLG} +#endif +#ifdef _CHAR_TITLE_STR_ + ,{{"ֳƺ"}, CHAR_TITLE_} +#endif +}; + +static CharBase CharBaseChar[] = { + {{""}, CHAR_NAME} + ,{{"dz"}, CHAR_OWNTITLE} + ,{{""}, CHAR_USERPETNAME} + ,{{"˺"}, CHAR_CDKEY} + ,{{""}, CHAR_FMNAME} +#ifdef _TEACHER_SYSTEM + ,{{"ʦʺ"}, CHAR_TEACHER_ID} + ,{{"ʦ"}, CHAR_TEACHER_NAME} +#endif +#ifdef _ITEM_SETLOVER + ,{{"˺"}, CHAR_LOVERID} + ,{{""}, CHAR_LOVERNAME} +#endif +#ifdef _NEW_NAME + ,{{"ƺ"}, CHAR_NEWNAME} +#endif +#ifdef _LOTTERY_SYSTEM + ,{{"Ʊ"}, CHAR_LOTTERY_VALUE} +#endif + ,{{"˺"}, CHAR_OWNERCDKEY} + ,{{""}, CHAR_OWNERCHARANAME} + +#ifdef _POWER_UP + ,{{""}, CHAR_POWER_UP} +#endif +#ifdef _VISUAL_BEATITUDE + ,{{"ף״̬"}, CHAR_VB} +#endif + ,{{"Unicode"}, CHAR_UNIQUECODE} +}; + + +static CharBase CharBaseEvent[] = { + {{"ʼ¼"}, CHAR_INITFUNC} + //,{{"¼"}, CHAR_WALKPREFUNC} + //,{{"ߺ¼"}, CHAR_WALKPOSTFUNC} + //,{{"δ֪¼"}, CHAR_PREOVERFUNC} + //,{{"δ֪¼"}, CHAR_POSTOVERFUNC} + //,{{"ۿ¼"}, CHAR_WATCHFUNC} + ,{{"ѭ¼"}, CHAR_LOOPFUNC} + //,{{"¼"}, CHAR_DYINGFUNC} + ,{{"Ի¼"}, CHAR_TALKEDFUNC} + //,{{"¼"}, CHAR_PREATTACKEDFUNC} + //,{{"¼"}, CHAR_POSTATTACKEDFUNC} + //,{{"뿪¼"}, CHAR_OFFFUNC} + //,{{"¼"}, CHAR_LOOKEDFUNC} + //,{{"¼"}, CHAR_ITEMPUTFUNC} + //,{{"Ի¼"}, CHAR_SPECIALTALKEDFUNC} + ,{{"¼"}, CHAR_WINDOWTALKEDFUNC} +#ifdef _USER_CHARLOOPS + //,{{"ѭ¼1"}, CHAR_LOOPFUNCTEMP1} + //,{{"ѭ¼2"}, CHAR_LOOPFUNCTEMP2} + //,{{"δ֪¼"}, CHAR_BATTLEPROPERTY} +#endif + ,{{"ص¼"}, CHAR_OVERLAPEDFUNC} + ,{{"ս¼"}, CHAR_BATTLEOVERDFUNC} +#ifdef _ALLBLUES_LUA_1_4 + ,{{"dz¼"}, CHAR_LOGINOUTFUNC} +#endif +#ifdef _ALLBLUES_LUA_1_9 + ,{{"ս¼"}, CHAR_BATTLESETFUNC} +#endif +}; + +static CharBase CharBaseColor[] = { + {{"ɫ"}, CHAR_COLORWHITE} + ,{{"ɫ"}, CHAR_COLORCYAN} + ,{{"ɫ"}, CHAR_COLORPURPLE} + ,{{"ɫ"}, CHAR_COLORBLUE} + ,{{"ɫ"}, CHAR_COLORYELLOW} + ,{{"ɫ"}, CHAR_COLORGREEN} + ,{{"ɫ"}, CHAR_COLORRED} + ,{{"Ұɫ"}, CHAR_COLORGRAY} + ,{{"ɫ"}, CHAR_COLORBLUE2} + ,{{"ɫ"}, CHAR_COLORGREEN2} +}; + +static CharBase CharBaseUpdata[] = { + {{"HP"}, CHAR_P_STRING_HP} + ,{{"MAXHP"}, CHAR_P_STRING_MAXHP} + ,{{"MP"}, CHAR_P_STRING_MP} + ,{{"MAXMP"}, CHAR_P_STRING_MAXMP} + ,{{""}, CHAR_P_STRING_VITAL} + ,{{""}, CHAR_P_STRING_STR} + ,{{""}, CHAR_P_STRING_TOUGH} + ,{{"ٶ"}, CHAR_P_STRING_DEX} + ,{{""}, CHAR_P_STRING_EXP} + ,{{"һ"}, CHAR_P_STRING_NEXTEXP} + ,{{"ȼ"}, CHAR_P_STRING_LV} + ,{{""}, CHAR_P_STRING_ATK} + ,{{""}, CHAR_P_STRING_DEF} + ,{{""}, CHAR_P_STRING_QUICK} + ,{{""}, CHAR_P_STRING_CHARM} + ,{{""}, CHAR_P_STRING_LUCK} + ,{{""}, CHAR_P_STRING_EARTH} + ,{{"ˮ"}, CHAR_P_STRING_WATER} + ,{{""}, CHAR_P_STRING_FIRE} + ,{{""}, CHAR_P_STRING_WIND} + ,{{"ʯ"}, CHAR_P_STRING_GOLD} + ,{{""}, CHAR_P_STRING_TITLE} + ,{{"DP"}, CHAR_P_STRING_DUELPOINT} + ,{{"ת"}, CHAR_P_STRING_TRANSMIGRATION} + ,{{""}, CHAR_P_STRING_NAME} + ,{{"dz"}, CHAR_P_STRING_OWNTITLE} + ,{{""}, CHAR_P_STRING_RIDEPET} + ,{{"ѧ"}, CHAR_P_STRING_LEARNRIDE} + ,{{"ͼ"}, CHAR_P_STRING_BASEBASEIMAGENUMBER} + ,{{""}, CHAR_P_STRING_SKYWALKER} + ,{{"ģʽ"}, CHAR_P_STRING_DEBUGMODE} +}; + +static CharBase CharBaseFlg[] = { + {{"ɼ"}, CHAR_ISVISIBLE} + ,{{"͸"}, CHAR_ISTRANSPARENT} + ,{{""}, CHAR_ISFLYING} + ,{{""}, CHAR_ISDIE} + ,{{""}, CHAR_ISPARTY} + ,{{""}, CHAR_ISDUEL} + ,{{"Ƭ"}, CHAR_ISTRADECARD} + ,{{""}, CHAR_ISTRADE} +#ifdef _CHANNEL_MODIFY + ,{{"Ƶ"}, CHAR_ISTELL} + ,{{"Ƶ"}, CHAR_ISFM} + ,{{"ְҵƵ"}, CHAR_ISOCC} + ,{{"Ի"}, CHAR_ISSAVE} + ,{{""}, CHAR_ISCHAT} +#ifdef _CHATROOMPROTOCOL +#ifdef _THE_WORLD_SEND + ,{{"Ƶ"}, CHAR_ISWORLD} +#endif +#ifdef _ONLINE_TALK_IP + ,{{"ٱƵ"}, CHAR_ISTALKIP} +#endif +#endif +#endif + ,{{"AIģʽ"}, CHAR_AI_MOD} +}; + +static CharBase CharBaseAction[] = { + {{"վ"}, CHAR_ACTSTAND} + ,{{"߶"}, CHAR_ACTWALK} + ,{{""}, CHAR_ACTATTACK} + ,{{"Ͷ"}, CHAR_ACTTHROW} + ,{{""}, CHAR_ACTDAMAGE} + ,{{""}, CHAR_ACTDEAD} + ,{{"ħ"}, CHAR_ACTMAGIC} + ,{{""}, CHAR_ACTITEM} + ,{{"Ч"}, CHAR_ACTEFFECT} + ,{{""}, CHAR_ACTDOWN} + ,{{""}, CHAR_ACTSIT} + ,{{""}, CHAR_ACTHAND} + ,{{""}, CHAR_ACTPLEASURE} + ,{{"ŭ"}, CHAR_ACTANGRY} + ,{{""}, CHAR_ACTSAD} + ,{{""}, CHAR_ACTGUARD} + ,{{"·"}, CHAR_ACTACTIONWALK} + ,{{"ͷ"}, CHAR_ACTNOD} + ,{{"վ"}, CHAR_ACTACTIONSTAND} + ,{{"ս"}, CHAR_ACTBATTLE} + ,{{""}, CHAR_ACTLEADER} + ,{{"ս"}, CHAR_ACTBATTLEWATCH} + ,{{"δ֪"}, CHAR_ACTPOPUPNAME} + ,{{"ת"}, CHAR_ACTTURN} + ,{{""}, CHAR_ACTWARP} + ,{{""}, CHAR_ACTTRADE} +#ifdef _ANGEL_SUMMON + ,{{"ʹ"}, CHAR_ACTANGEL} +#endif + +#ifdef _MIND_ICON + ,{{"˼"}, CHAR_MIND} +#endif +#ifdef _STREET_VENDOR + ,{{"̯̲"}, CHAR_STREETVENDOR_OPEN} + ,{{"ر̯̲"}, CHAR_STREETVENDOR_CLOSE} +#endif +}; + + +static int getCharNum (lua_State *L) +{ + lua_pushinteger(L, CHAR_getCharNum()); + + return 1; +} + +static int getPlayerMaxNum (lua_State *L) +{ + lua_pushinteger(L, CHAR_getPlayerMaxNum()); + + return 1; +} + +static int getPetMaxNum (lua_State *L) +{ + lua_pushinteger(L, CHAR_getPetMaxNum()); + + return 1; +} + +static int getOthersMaxNum (lua_State *L) +{ + lua_pushinteger(L, CHAR_getOthersMaxNum()); + + return 1; +} + + +static int check (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, CHAR_CHECKINDEX(index)); + + return 1; +} + +static int setFlg (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseFlg, arraysizeof(CharBaseFlg)); + const int data = luaL_checkint(L, 3); + if(CHAR_setFlg(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getFlg (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseFlg, arraysizeof(CharBaseFlg)); + + lua_pushinteger(L, CHAR_getFlg(index, element)); + return 1; +} + +static int setWorkChar (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseWorkChar, arraysizeof(CharBaseWorkChar)); + char *data = luaL_checklstring(L, 3, &l); + if(CHAR_setWorkChar(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getWorkChar (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseWorkChar, arraysizeof(CharBaseWorkChar)); + lua_pushstring(L, CHAR_getWorkChar(index, element)); + return 1; +} + + +static int setWorkInt (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseWorkInt, arraysizeof(CharBaseWorkInt)); + const int data = getCharBaseValue(L, 3, CharBaseWorkValue, arraysizeof(CharBaseWorkValue)); + if(CHAR_setWorkInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getWorkInt (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseWorkInt, arraysizeof(CharBaseWorkInt)); + lua_pushinteger(L, CHAR_getWorkInt(index, element)); + return 1; +} + +static int setChar (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseChar, arraysizeof(CharBaseChar)); + char *data = luaL_checklstring(L, 3, &l); + if(CHAR_setChar(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getChar (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseChar, arraysizeof(CharBaseChar)); + lua_pushstring(L, CHAR_getChar(index, element)); + return 1; +} + +static int setInt (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseInt, arraysizeof(CharBaseInt)); + const int data = getCharBaseValue(L, 3, CharBaseValue, arraysizeof(CharBaseValue)); + if(CHAR_setInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getInt (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseInt, arraysizeof(CharBaseInt)); + lua_pushinteger(L, CHAR_getInt(index, element)); + return 1; +} + +static int setFunctionPointer(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int functype = getCharBaseValue(L, 2, CharBaseEvent, arraysizeof(CharBaseEvent)); + char *luafunctable=luaL_checklstring(L, 3, &l); + char *luafunctablepath=luaL_checklstring(L, 4, &l); + if(strlen(luafunctablepath) > 0){ + MY_Lua *mylua = &MYLua; + while(mylua->next != NULL){ + if(strcmp(mylua->luapath, luafunctablepath) == 0){ + return CHAR_setLUAFunction( index, functype, mylua->lua, luafunctable ); + } + mylua = mylua->next; + } + }else{ + return CHAR_setLUAFunction( index, functype, L, luafunctable ); + } + return 1; +} + +static int delFunctionPointer(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int functype = getCharBaseValue(L, 2, CharBaseEvent, arraysizeof(CharBaseEvent)); + + return CHAR_delLUAFunction( index, functype ); +} + +static int TalkToCli(lua_State *L) +{ + size_t l; + const int talkedcharaindex = luaL_checkint(L, 1); + const int talkcharaindex = luaL_checkint(L, 2); + char *message=luaL_checklstring(L, 3, &l); + const int color = getCharBaseValue(L, 4, CharBaseColor, arraysizeof(CharBaseColor)); + CHAR_talkToCli(talkedcharaindex, talkcharaindex, message, color); + return 1; +} + +static int TalkToRound(lua_State *L) +{ + size_t l; + const int talkedcharaindex = luaL_checkint(L, 1); + char *message=luaL_checklstring(L, 2, &l); + const int color = getCharBaseValue(L, 3, CharBaseColor, arraysizeof(CharBaseColor)); + + int fl = CHAR_getInt( talkedcharaindex, CHAR_FLOOR) ; + int x = CHAR_getInt( talkedcharaindex, CHAR_X) ; + int y = CHAR_getInt( talkedcharaindex, CHAR_Y) ; + + int i,j; + + int range = 8; + + for( i=x-range ; i<=x+range ; i++ ){ + for( j=y-range ; j<=y+range ; j++ ){ + OBJECT object; + for( object = MAP_getTopObj( fl,i,j ) ; object ; object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); + int toindex = OBJECT_getIndex( objindex); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA && toindex != talkedcharaindex ){ + if( CHAR_getInt(toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ + typedef void (*TALKF)(int,int,char*,int,int); + TALKF talkedfunc=NULL; + talkedfunc = (TALKF)CHAR_getFunctionPointer( toindex, CHAR_TALKEDFUNC); + if( talkedfunc ) { + talkedfunc(toindex, talkedcharaindex, message, color, -1); + } + } + } + } + } + } + + return 1; +} + +static int WalkPoint(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) return 0; + + const int x = luaL_checkint(L, 2); + const int y = luaL_checkint(L, 3); + + POINT start, end; + + start.x = CHAR_getInt( index, CHAR_X); + start.y = CHAR_getInt( index, CHAR_Y); + + end.x = x; + end.y = y; + + int pos = NPC_Util_getDirFromTwoPoint( &start, &end); + if( pos != - 1 ) { + CHAR_walk( index, pos, 0); + } + return 1; +} + +static int Walk(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) return 0; + + const int dir = luaL_checkint(L, 2); + const int step = luaL_checkint(L, 3); + + POINT start, end; + + start.x = CHAR_getInt( index, CHAR_X); + start.y = CHAR_getInt( index, CHAR_Y); + + end.x = start.x; + end.y = start.y; + switch(dir){ + case 0: + { + end.x = start.x - step; + break; + } + case 1: + { + end.x = start.x + step; + end.y = start.y - step; + break; + } + case 2: + { + end.x = start.x + step; + break; + } + case 3: + { + end.x = start.x + step; + end.y = start.y + step; + + break; + } + case 4: + { + end.y = start.y + step; + break; + } + case 5: + { + end.x = start.x - step; + end.y = start.y + step; + break; + } + case 6: + { + end.y = start.y - step; + break; + } + case 7: + { + end.x = start.x - step; + end.y = start.y - step; + break; + } + } + + int pos = NPC_Util_getDirFromTwoPoint( &start, &end); + if( dir != - 1 ) { + CHAR_walk( index, pos, 0); + } + return 1; +} + +static int BoundRandWalk(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + if( CHAR_getWorkInt( index, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) return 0; + + const int minX = min(luaL_checkint(L, 2), luaL_checkint(L, 4)); + const int minY = min(luaL_checkint(L, 3), luaL_checkint(L, 5)); + const int maxX = max(luaL_checkint(L, 2), luaL_checkint(L, 4)); + const int maxY = max(luaL_checkint(L, 3), luaL_checkint(L, 5)); + + POINT start, end; + int stepX = (rand() % 10) - 5; + int stepY = (rand() % 10) - 5; + + start.x = CHAR_getInt( index, CHAR_X); + start.y = CHAR_getInt( index, CHAR_Y); + + end.x = start.x + stepX; + if(end.x>maxX)end.x=maxX; + else if(end.xmaxY)end.y=maxY; + else if(end.y -1 ){ + CHAR_setCharPet( index, havepetelement, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, index); + } + + lua_pushinteger(L, havepetelement); + + return 1; +} + + int getCharPet(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int havepetid = luaL_checkint(L, 2); + + lua_pushinteger(L, CHAR_getCharPet( index, havepetid)); + + return 1; +} + +static int setCharPoolPet(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int petindex = luaL_checkint(L, 2); + + int havepetelement = CHAR_getCharPoolPetElement( index); + if( havepetelement > -1 ){ + CHAR_setCharPoolPet( index, havepetelement, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, index); + } + + lua_pushinteger(L, havepetelement); + + return 1; +} + +static int getCharPoolPet(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int havepetid = luaL_checkint(L, 2); + + lua_pushinteger(L, CHAR_getCharPoolPet( index, havepetid)); + + return 1; +} + +static int AB_WriteShopData(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + size_t l; + const char *data = luaL_checklstring(L, 2, &l); + WriteShopData(data,index); + return 1; +} + +static int setDepotPetIndex(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int petindex = luaL_checkint(L, 2); + + int havepetelement = CHAR_getCharPoolPetElement( index); + if( havepetelement > -1 ){ + CHAR_setDepotPetIndex( index, havepetelement, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, index); + } + + lua_pushinteger(L, havepetelement); + + return 1; +} + +static int getDepotPetIndex(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int havepetid = luaL_checkint(L, 2); + + lua_pushinteger(L, CHAR_getDepotPetIndex( index, havepetid)); + + return 1; +} + +static int DelItem(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int itemindex = luaL_checkint(L, 2); + + CHAR_DelItem( charaindex, itemindex); + + return 1; +} + +static int getFd(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, getfdFromCharaIndex(charaindex)); + return 1; +} + +static int Updata(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int indextable = getCharBaseValue(L, 2, CharBaseUpdata, arraysizeof(CharBaseUpdata)); + + CHAR_send_P_StatusString( charaindex , indextable); + return 1; +} + +static int Additem(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int itemid = luaL_checkint(L, 2); + int itemindex = -1; + int emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + + if( emptyitemindexinchara >= 0 ){ + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex > -1 ){ + CHAR_setItemIndex( charaindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX, -1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX, charaindex); + CHAR_sendItemDataOne( charaindex, emptyitemindexinchara); + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + atoi( message), +#endif + "AddItem(LUA)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + } + lua_pushinteger(L, itemindex); + return 1; +} +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static int Finditem(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int itemid = luaL_checkint(L, 2); + int i; + int itemindex=-1; + int id; + for( i=CHAR_STARTITEMARRAY;i> (4 - flg) * 8) & 0xFF); + + return 1; +} + +static int getLiftTo8(lua_State *L) +{ + const int value = luaL_checkint(L, 1); + const int flg = luaL_checkint(L, 2); + + lua_pushinteger(L, (value << (4 - flg) * 8)); + + return 1; +} + +static int complianceParameter(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + CHAR_complianceParameter(index); + + return 1; +} + + +static int sendStatusString(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + + CHAR_sendStatusString( index, data ); + + return 1; +} + +static int sendBattleEffect(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int val = luaL_checkint(L, 2); + + CHAR_sendBattleEffect( index, val ); + + return 1; +} + +static int sendWatchEvent(lua_State *L) +{ + const int objindex = luaL_checkint(L, 1); + const int action = getCharBaseValue(L, 2, CharBaseAction, arraysizeof(CharBaseAction)); + const int flg = luaL_checkint(L, 3); + + luaL_checktype(L, 4, LUA_TTABLE); + int n = luaL_getn(L, 4); + int *opt = (int *) malloc(n * sizeof(int)); + int i; + + for(i = 0; i < n; i++){ + opt[i] = getArrayInt(L, i); + } + + CHAR_sendWatchEvent( objindex, action, opt, n, flg); + + return 1; +} + +static int dropPetAbsolute(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int fl = luaL_checkint(L, 2); + const int fx = luaL_checkint(L, 3); + const int fy = luaL_checkint(L, 4); + const int dir = luaL_checkint(L, 5); + const int val = luaL_checkint(L, 6); + int dirx[9],diry[9]; + int floor, x, y, i; + + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX(dir + i+1); + diry[i+2] = CHAR_getDY(dir + i+1); + } + dirx[0] = CHAR_getDX(dir); + diry[0] = CHAR_getDY(dir); + dirx[1] = 0; + diry[1] = 0; + floor = fl; + for( i = 0 ; i < 9 ; i ++ ){ + int x=fx+dirx[i]; + int y=fy+diry[i]; + if( PET_isPutPoint( floor, x, y ) == TRUE ) { + break; + } + } + if( i == 9 ) i = 1; + x = fx+dirx[i]; + y = fy+diry[i]; + + int objindex = PET_dropPetAbsolute( index, floor, x, y, val ); + + if( objindex == -1 ){ + return 1; + } + + CHAR_setWorkInt( index, CHAR_WORKOBJINDEX, objindex ); + CHAR_setInt( index, CHAR_FLOOR, floor); + CHAR_setInt( index, CHAR_X, x); + CHAR_setInt( index, CHAR_Y, y); + CHAR_setInt( index, CHAR_PUTPETTIME, NowTime.tv_sec); + + CHAR_sendCToArroundCharacter( objindex); + + return 1; +} + +static int AllWarpToSpecificPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int floor = luaL_checkint(L, 2); + const int x = luaL_checkint(L, 3); + const int y = luaL_checkint(L, 4); + + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + int i; + for( i = 0; i < getPartyNum(charaindex); i ++ ){ + int subindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1+i ); + if( CHAR_CHECKINDEX( subindex ) == FALSE ) continue; + CHAR_warpToSpecificPoint( subindex, floor, x, y ); + ITEM_WarpDelErrorItem( subindex ); + } + }else if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + CHAR_talkToCli(charaindex, -1, "Ա޷ʹá", CHAR_COLORYELLOW); + return FALSE; + }else if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_NONE ){ + ITEM_WarpDelErrorItem( charaindex ); + CHAR_warpToSpecificPoint( charaindex, floor, x, y ); + } + + + return 1; +} + +static int Findpet(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int petid = luaL_checkint(L, 2); + const int lv = luaL_checkint(L, 3); + int i; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + int petindex = CHAR_getCharPet( charaindex, i ); + if(!CHAR_CHECKINDEX( petindex))continue; + if( CHAR_getInt(petindex, CHAR_PETID) == petid ){ + if(lv > 0){ + if( CHAR_getInt(petindex, CHAR_LV) != lv){ + continue; + } + } + lua_pushinteger(L, petindex); + return 1; + } + } + + lua_pushinteger(L, -1); + return 1; +} + +static int FindPetFormMatemo(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int metamo = luaL_checkint(L, 2); + const int lv = luaL_checkint(L, 3); + int i; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + int petindex = CHAR_getCharPet( charaindex, i ); + if(!CHAR_CHECKINDEX( petindex))continue; + if( CHAR_getInt(petindex, CHAR_BASEBASEIMAGENUMBER) == metamo ){ + if(lv > 0){ + if( CHAR_getInt(petindex, CHAR_LV) != lv){ + continue; + } + } + lua_pushinteger(L, petindex); + return 1; + } + } + + lua_pushinteger(L, -1); + return 1; +} + +static int FindPetFormEnemyTempID(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + char token[64]; + int enemytempid = -1, lv = 0; + int i; + + if(getStringFromIndexWithDelim(data, "-", 1, token, sizeof(token)) == TRUE){ + lv = atoi(token); + }else{ + lua_pushinteger(L, -1); + } + + if(getStringFromIndexWithDelim(data, "-", 2, token, sizeof(token)) == TRUE){ + enemytempid = atoi(token); + }else{ + lua_pushinteger(L, -1); + } + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + int petindex = CHAR_getCharPet( charaindex, i ); + if(!CHAR_CHECKINDEX( petindex))continue; + + if( CHAR_getInt( petindex, CHAR_PETID) == enemytempid ){ + if(lv > 0){ + if( CHAR_getInt(petindex, CHAR_LV) != lv){ + continue; + } + } + lua_pushinteger(L, petindex); + return 1; + } + } + + lua_pushinteger(L, -1); + return 1; +} + +static int CharaDeleteHavePet(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + CHAR_CharaDeleteHavePet( charaindex); + return 1; +} + + +static int DelPet(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int petindex = luaL_checkint(L, 2); + int i; + char category[12]; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( petindex == CHAR_getCharPet( charaindex, i ) ){ + if( CHAR_getInt( charaindex, CHAR_RIDEPET) == i ) { + CHAR_setInt( charaindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_RIDEPET ); + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + } + LogPet( CHAR_getChar( charaindex, CHAR_NAME ), // ƽҷ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "EvnetDell(LUAɾ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + CHAR_endCharOneArray( petindex ); + CHAR_setCharPet( charaindex, i, -1); + snprintf( category, sizeof( category), "K%d",i); + CHAR_sendStatusString( charaindex, category ); + break; + } + } + return 1; +} + +#endif + + + +#ifdef _ALLBLUES_LUA_1_7 +static int findEmptyItemBox(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, CHAR_findEmptyItemBox(charaindex)); + return 1; +} + +static int findEmptyPetBox(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + int num = 0; + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + int petindex = CHAR_getCharPet( charaindex, i ); + if(!CHAR_CHECKINDEX(petindex)){ + num ++ ; + } + } + lua_pushinteger(L, num); + return 1; +} + +static int dropPetFollow(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int havepetindex = luaL_checkint(L, 2); + char szPet[128]; + int dirx[9],diry[9]; + int i; + int objindex=-1; + int floor,x,y; + int petindex; + + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) return FALSE; + petindex = CHAR_getCharPet(charaindex,havepetindex); + if( petindex == -1 ) return FALSE; + if( !CHAR_CHECKINDEX( charaindex ) )return FALSE; + if( CHAR_CHECKINDEX( petindex) == FALSE ) return FALSE; + + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ + CHAR_talkToCli(charaindex, -1, "ػ޷", CHAR_COLORYELLOW); + return FALSE; + } + if (CHAR_getInt(charaindex, CHAR_RIDEPET) == havepetindex){ + CHAR_talkToCli(charaindex, -1, "еij޷棡", CHAR_COLORYELLOW); + return FALSE; + } + + for( i = 0 ; i < 7 ; i ++ ){ + dirx[i+2] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + diry[i+2] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR) + i+1); + } + dirx[0] = CHAR_getDX(CHAR_getInt(charaindex,CHAR_DIR)); + diry[0] = CHAR_getDY(CHAR_getInt(charaindex,CHAR_DIR)); + dirx[1] = 0; + diry[1] = 0; + + floor = CHAR_getInt( charaindex,CHAR_FLOOR ); + for( i = 0 ; i < 9 ; i ++ ){ + int x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + int y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + if( PET_isPutPoint( floor, x, y ) == TRUE ) { + break; + } + } + if( i == 9 ) i = 1; + + x=CHAR_getInt(charaindex,CHAR_X)+dirx[i]; + y=CHAR_getInt(charaindex,CHAR_Y)+diry[i]; + + objindex = PET_dropPetAbsolute( petindex,floor,x,y, FALSE ); + if( objindex == -1 ) return FALSE; + + CHAR_setWorkInt( petindex,CHAR_WORKOBJINDEX,objindex ); + CHAR_setCharPet( charaindex, havepetindex, -1); + CHAR_setInt( petindex, CHAR_FLOOR, floor); + CHAR_setInt( petindex, CHAR_X, x); + CHAR_setInt( petindex, CHAR_Y, y); + CHAR_setInt( petindex, CHAR_PUTPETTIME, NowTime.tv_sec); + if( havepetindex == CHAR_getInt( charaindex, CHAR_DEFAULTPET)) { + int fd; + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1); + fd = getfdFromCharaIndex( charaindex); + lssproto_KS_send( fd, havepetindex, 0); + + } + CHAR_sendCToArroundCharacter( objindex); + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER){ +#ifdef _PET_ITEM + CHAR_sendPetItemData( charaindex, havepetindex); +#endif + snprintf( szPet, sizeof( szPet ), "K%d", havepetindex ); + CHAR_sendStatusString( charaindex, szPet ); + } + + CHAR_setWorkInt( charaindex, CHAR_WORKPETFOLLOW, petindex); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWMODE, CHAR_PETFOLLOW_NOW); + CHAR_setWorkInt( petindex, CHAR_WORKPETFOLLOWCOUNT, 0); + CHAR_setInt( petindex, CHAR_PUTPETTIME, (int)(NowTime.tv_sec)); + CHAR_setInt( petindex, CHAR_WORKPLAYERINDEX, charaindex); + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "Follow(lua)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + return 1; +} + +static int getItemIndex(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int haveitemindex = luaL_checkint(L, 2); + + lua_pushinteger(L, CHAR_getItemIndex( charaindex, haveitemindex )); + return 1; + +} + +static int charSaveFromConnect(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + if( CHAR_getCharUse(charaindex) != FALSE ){ + CHAR_charSaveFromConnect( charaindex, FALSE ); + } + return 1; +} + +#ifdef _RECORD_IP +static int userip(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + unsigned long ip; + int a,b,c,d; + char strIP[32]; + + ip = CHAR_getWorkInt(charaindex, CHAR_WORK_RECORD_IP); + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + + sprintf(strIP, "%d.%d.%d.%d", a, b, c, d); + + lua_pushstring(L, strIP); + return 1; +} +#endif + +static int DischargeParty(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int flg = luaL_checkint(L, 2); + CHAR_DischargeParty_New(charaindex, flg); + return 1; +} + + +static int Skillupsend(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + CHAR_Skillupsend(charaindex); + return 1; +} +#endif + +#ifdef _ALLBLUES_LUA_1_9 +static int logou(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + CHAR_logout(charaindex, TRUE); + return 1; +} + int copyChar(lua_State *L) +{ + const int fromindex = luaL_checkint(L, 1); + const int toindex = luaL_checkint(L, 2); + + if( !CHAR_CHECKINDEX( fromindex) )return 1; + if( !CHAR_CHECKINDEX( toindex) )return 1; + + CHAR_setInt(toindex, CHAR_BASEIMAGENUMBER, CHAR_getInt(fromindex, CHAR_BASEIMAGENUMBER)); + CHAR_setInt(toindex, CHAR_BASEBASEIMAGENUMBER, CHAR_getInt(fromindex, CHAR_BASEBASEIMAGENUMBER)); + CHAR_setInt(toindex, CHAR_TRANSMIGRATION, CHAR_getInt(fromindex, CHAR_TRANSMIGRATION)); + CHAR_setInt(toindex, CHAR_LV, CHAR_getInt(fromindex, CHAR_LV)); + CHAR_setInt(toindex, CHAR_HP, CHAR_getInt(fromindex, CHAR_HP)); + CHAR_setInt(toindex, CHAR_MP, CHAR_getInt(fromindex, CHAR_MP)); + CHAR_setInt(toindex, CHAR_MAXMP, CHAR_getInt(fromindex, CHAR_MAXMP)); + CHAR_setInt(toindex, CHAR_VITAL, CHAR_getInt(fromindex, CHAR_VITAL)); + CHAR_setInt(toindex, CHAR_STR, CHAR_getInt(fromindex, CHAR_STR)); + CHAR_setInt(toindex, CHAR_TOUGH, CHAR_getInt(fromindex, CHAR_TOUGH)); + CHAR_setInt(toindex, CHAR_DEX, CHAR_getInt(fromindex, CHAR_DEX)); + CHAR_setInt(toindex, CHAR_ALLOCPOINT, CHAR_getInt(fromindex, CHAR_ALLOCPOINT)); + CHAR_setInt(toindex, CHAR_PETRANK, CHAR_getInt(fromindex, CHAR_PETRANK)); + CHAR_setInt(toindex, CHAR_LIMITLEVEL, CHAR_getInt(fromindex, CHAR_LIMITLEVEL)); + CHAR_setChar(toindex, CHAR_NAME, CHAR_getChar(fromindex, CHAR_NAME)); + CHAR_setChar(toindex, CHAR_OWNTITLE, CHAR_getChar(fromindex, CHAR_OWNTITLE)); + + CHAR_complianceParameter(toindex); + + return 1; +} + + int talkToAllServer(lua_State *L) +{ + size_t l; + char *message=luaL_checklstring(L, 1, &l); + saacproto_AllServSend_send(message); + return 1; +} + +#endif + +static int earnFame(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int num = luaL_checkint(L, 2); + CHAR_earnFame(charaindex, num); + return 1; +} + +static int Encounter(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); +#ifdef _USER_CHARLOOPS + { + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return 0; + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "CHAR_BattleStayLoop");//ս + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 2500); + CHAR_constructFunctable( charaindex); + } +#endif +} + + +static int ClearEncounter(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + clearStayEncount(fd); + return 1; +} + + + +static int getDX(lua_State *L) +{ + size_t l; + char *diy=luaL_checklstring(L, 1, &l); + + lua_pushinteger(L, CHAR_getDX(diy)); + return 1; +} + +static int getDY(lua_State *L) +{ + size_t l; + char *dir=luaL_checklstring(L, 1, &l); + + lua_pushinteger(L, CHAR_getDY(dir)); + return 1; +} + +static int sendAction(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int actionno = luaL_checkint(L, 2); + const int flg = luaL_checkint(L, 3); + CHAR_sendAction( charaindex, actionno, flg); + return 1; +} +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + +static int GetEmptyItemBoxNum(lua_State *_NLL) +{ + const int TM_CharIndex = luaL_checkint(_NLL, 1); + + if(!CHAR_CHECKINDEX(TM_CharIndex)) + { + lua_pushinteger(_NLL, -1); + return 0; + } + + int i = CHAR_EQUIPPLACENUM ; + int EmptyNum = 0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(TM_CharIndex); + for( ; i skill, 0, 0 ); + pSkil->use = 0; +} + +#endif + + +static int UpCahrData(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + size_t l; + const char *data = luaL_checklstring(L, 2, &l); + CHAR_sendStatusString(charaindex,data); + return 1; +} +#ifdef _NEW_TITLE +static int getCharNewTitleMode(lua_State *L){ + const int charaindex = luaL_checkint(L, 1); + const int id = luaL_checkint(L, 2); + if (id < 32){ + if (CHAR_getInt(charaindex,CHAR_TITLE1)&(1<=32 && id < 64) { + if (CHAR_getInt(charaindex,CHAR_TITLE2)&(1<<(id-32))) { + lua_pushinteger(L, 1); + return 1; + } + } + else if (id >=64 && id < 96){ + if (CHAR_getInt(charaindex,CHAR_TITLE3)&(1<<(id-64))) { + lua_pushinteger(L, 1); + return 1; + } + } + lua_pushinteger(L, -1); + return 1; +} + +static int setCharNewTitleMode(lua_State *L){ + const int charaindex = luaL_checkint(L, 1); + const int id = luaL_checkint(L, 2); + if (id < 32){ + CHAR_setInt(charaindex,CHAR_TITLE1,CHAR_getInt(charaindex,CHAR_TITLE1)|(1<=32 && id < 64) { + CHAR_setInt(charaindex,CHAR_TITLE2,CHAR_getInt(charaindex,CHAR_TITLE2)|(1<<(id-32))); + } + else if (id >=64 && id < 96){ + CHAR_setInt(charaindex,CHAR_TITLE3,CHAR_getInt(charaindex,CHAR_TITLE3)|(1<<(id-64))); + } + return 1; +} + +static int clrCharNewTitleMode(lua_State *L){ + const int charaindex = luaL_checkint(L, 1); + const int id = luaL_checkint(L, 2); + if (id < 32){ + CHAR_setInt(charaindex,CHAR_TITLE1,CHAR_getInt(charaindex,CHAR_TITLE1)& ~(1<=32 && id < 64) { + CHAR_setInt(charaindex,CHAR_TITLE2,CHAR_getInt(charaindex,CHAR_TITLE2)& ~(1<<(id-32))); + } + else if (id >=64 && id < 96){ + CHAR_setInt(charaindex,CHAR_TITLE3,CHAR_getInt(charaindex,CHAR_TITLE3)& ~(1<<(id-64))); + } + return 1; +} +#endif + +static int lua_getMyMaxPilenum(lua_State *L) +{ + int charaindex=luaL_checkint(L, 1); + lua_pushinteger(L, CHAR_getMyMaxPilenum(charaindex)); + return 1; +} + +static int PileItemFromItemBoxToItemBox(lua_State *L) +{ + int charaindex=luaL_checkint(L, 1); + int from=luaL_checkint(L, 2); + int to=luaL_checkint(L, 3); + lua_pushinteger(L, CHAR_PileItemFromItemBoxToItemBox(charaindex,from,to)); + return 1; +} + +static int CheckUserItem(lua_State *L) +{ + int charaindex=luaL_checkint(L, 1); + CHAR_CheckUserItem(charaindex); + return 1; +} + +extern int NPC_Lua_NLG_UpChar(lua_State *_NLL); +static const luaL_Reg charlib[] = { + {"PileItemFromItemBoxToItemBox", PileItemFromItemBoxToItemBox}, + {"getMyMaxPilenum", lua_getMyMaxPilenum}, + {"upchar", NPC_Lua_NLG_UpChar}, + {"getCharNum", getCharNum}, + {"UpCahrData", UpCahrData}, + {"getPlayerMaxNum", getPlayerMaxNum}, + {"getPetMaxNum", getPetMaxNum}, + {"getOthersMaxNum", getOthersMaxNum}, + {"check", check}, + {"setWorkChar", setWorkChar}, + {"getWorkChar", getWorkChar}, + {"setWorkInt", setWorkInt}, + {"getWorkInt", getWorkInt}, + {"setChar", setChar}, + {"getChar", getChar}, + {"setInt", setInt}, + {"getInt", getInt}, + {"setFlg", setFlg}, + {"getFlg", getFlg}, + {"setFunctionPointer", setFunctionPointer}, + {"delFunctionPointer", delFunctionPointer}, + {"TalkToCli", TalkToCli}, + {"TalkToRound", TalkToRound}, + {"talkToFloor", talkToFloor}, + {"talkToParty", talkToParty}, + {"talkToServer", talkToServer}, +#ifdef _MO_LUA_TALK_EX + {"talkToServerEx", talkToServerEx}, +#endif + {"BoundRandWalk", BoundRandWalk}, + {"ToAroundChar", ToAroundChar}, +#ifdef _ALLBLUES_LUA_1_1 + {"Walk", Walk}, + {"WalkPoint", WalkPoint}, + {"WarpToSpecificPoint", WarpToSpecificPoint}, + {"MapAllWarp", MapAllWarp}, + {"RandRandWalk", RandRandWalk}, +#endif +#ifdef _ALLBLUES_LUA_1_3 + {"createPet", createPet}, + {"setCharPet", setCharPet}, + {"getCharPet", getCharPet}, + {"setCharPoolPet", setCharPoolPet}, + {"getCharPoolPet", getCharPoolPet}, + {"setDepotPetIndex", setDepotPetIndex}, + {"getDepotPetIndex", getDepotPetIndex}, + {"DelItem", DelItem}, + {"getFd", getFd}, + {"Updata", Updata}, + {"Additem", Additem}, + {"AddPet", AddPet}, + {"Finditem", Finditem}, +#ifdef _PLAYER_NPC + {"setPlayerNpc", setPlayerNpc}, +#endif + {"Coordinate", Coordinate}, + {"setPetSkill", setPetSkill}, + {"getPetSkill", getPetSkill}, + {"PetLevelUp", PetLevelUp}, + {"JoinParty", JoinParty}, +#endif +#ifdef _ALLBLUES_LUA_1_4 + {"getLiftTo8", getLiftTo8}, + {"getRightTo8", getRightTo8}, + {"complianceParameter", complianceParameter}, + {"sendStatusString", sendStatusString}, + {"sendBattleEffect", sendBattleEffect}, + {"dropPetAbsolute", dropPetAbsolute}, + {"AddPetCf", AddPetCf}, + {"sendWatchEvent", sendWatchEvent}, + {"AllWarpToSpecificPoint",AllWarpToSpecificPoint}, + {"Findpet", Findpet}, + {"DelPet", DelPet}, + {"CharaDeleteHavePet", CharaDeleteHavePet}, + {"FindPetFormEnemyTempID",FindPetFormEnemyTempID}, + {"FindPetFormMatemo", FindPetFormMatemo}, +#endif +#ifdef _PETSKILL_SHOP_LUA + {"FreePetSkill", FreePetSkill}, +#endif +#ifdef _ALLBLUES_LUA_1_7 + {"findEmptyPetBox", findEmptyPetBox}, + {"findEmptyItemBox", findEmptyItemBox}, + {"dropPetFollow", dropPetFollow}, + {"getItemIndex", getItemIndex}, + {"charSaveFromConnect", charSaveFromConnect}, + {"DischargeParty", DischargeParty}, + {"Skillupsend", Skillupsend}, +#ifdef _RECORD_IP + {"userip", userip}, +#endif +#endif +#ifdef _ALLBLUES_LUA_1_9 + {"logou", logou}, + {"copyChar", copyChar}, + {"talkToAllServer", talkToAllServer}, +#endif + {"earnFame", earnFame}, + {"Encounter", Encounter}, + {"getDX", getDX}, + {"getDY", getDY}, + {"sendAction", sendAction}, + {"GetOldLevelExp", GetOldLevelExp}, +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + {"getCharSkill", getCharSkill}, + {"setCharSkill", setCharSkill}, + {"DelSProfeesionSkill", DelSProfeesionSkill}, +#endif + {"WriteShopData", AB_WriteShopData}, + {"GetEmptyItemBoxNum", GetEmptyItemBoxNum}, + {"ClearEncounter", ClearEncounter}, +#ifdef _NEW_TITLE + {"getCharNewTitleMode", getCharNewTitleMode}, + {"setCharNewTitleMode", setCharNewTitleMode}, + {"clrCharNewTitleMode", clrCharNewTitleMode}, +#endif +#ifdef _ITEM_USE_TIME + {"CheckUserItem", CheckUserItem}, +#endif + {NULL, NULL} +}; + +LUALIB_API int luaopen_Char (lua_State *L) { + luaL_register(L, "char", charlib); + return 1; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/configbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/configbase.c new file mode 100644 index 0000000..5db537b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/configbase.c @@ -0,0 +1,99 @@ +#include +#include "char.h" +#include "char_base.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "configfile.h" + +#ifdef _ALLBLUES_LUA + +#ifdef _ALLBLUES_LUA_1_1 +static int set(lua_State *L) +{ + size_t l; + char *data=luaL_checklstring(L, 1, &l); + luareadconfigfile(data); + return 1; +} + +static int checkIp(lua_State *L) +{ + int ip = luaL_checkint(L, 1); + + lua_pushinteger(L, checkServerIp(ip)); + return 1; +} + +static int getGameID(lua_State *L) +{ + lua_pushstring(L, getGameserverID()); + return 1; +} + +static int getGamename(lua_State *L) +{ + lua_pushstring(L, getGameservername()); + return 1; +} + +static int getnumber(lua_State *L) +{ + lua_pushinteger(L, getServernumber()); + return 1; +} +#ifdef _GET_BATTLE_EXP +static int getexp(lua_State *L) +{ + lua_pushinteger(L, getBattleexp()); + return 1; +} +#endif + +#ifdef _VIP_BATTLE_EXP +int getVipexp(lua_State *L) +{ + lua_pushinteger(L, getVipBattleexp()); + return 1; +} +#endif + +int getFdMaxNnum(lua_State *L) +{ + lua_pushinteger(L, getFdnum()); + return 1; +} + +int PlayerNum(lua_State *L) +{ + int num = luaL_checkint(L, 1); + + setPlayerNum(num); + return 1; +} +static const luaL_Reg configlib[] = { + {"set", set}, + {"checkIp", checkIp}, + {"getGameserverID", getGameID}, + {"getGameservername", getGamename}, + {"getServernumber", getnumber}, +#ifdef _GET_BATTLE_EXP + {"getBattleexp", getexp}, +#endif +#ifdef _VIP_BATTLE_EXP + {"getVipBattleexp", getVipexp}, +#endif + {"getFdnum", getFdMaxNnum}, + {"PlayerNum", PlayerNum}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Config (lua_State *L) { + luaL_register(L, "config", configlib); + return 1; +} +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/enemytempbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/enemytempbase.c new file mode 100644 index 0000000..ea946be --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/enemytempbase.c @@ -0,0 +1,159 @@ +#include +#include +#include "char.h" +#include "readmap.h" +#include "map_deal.h" +#include "char_base.h" +#include "enemy.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" + +#ifdef _ALLBLUES_LUA +#ifdef _ALLBLUES_LUA_1_4 + +static CharBase EnemytempBaseInt[] = { + {{""}, E_T_TEMPNO} + ,{{"ʼֵ"}, E_T_INITNUM} + ,{{"ɳ"}, E_T_LVUPPOINT} + ,{{""}, E_T_BASEVITAL} + ,{{""}, E_T_BASESTR} + ,{{""}, E_T_BASETGH} + ,{{"ٶ"}, E_T_BASEDEX} + ,{{""}, E_T_MODAI} + ,{{""}, E_T_GET} + ,{{""}, E_T_EARTHAT} + ,{{"ˮ"}, E_T_WATERAT} + ,{{""}, E_T_FIREAT} + ,{{""}, E_T_WINDAT} + ,{{""}, E_T_POISON} + ,{{"鿹"}, E_T_PARALYSIS} + ,{{"˯"}, E_T_SLEEP} + ,{{"ʯ"}, E_T_STONE} + ,{{"ƿ"}, E_T_DRUNK} + ,{{"쿹"}, E_T_CONFUSION} + ,{{"1"}, E_T_PETSKILL1} + ,{{"2"}, E_T_PETSKILL2} + ,{{"3"}, E_T_PETSKILL3} + ,{{"4"}, E_T_PETSKILL4} + ,{{"5"}, E_T_PETSKILL5} + ,{{"6"}, E_T_PETSKILL6} + ,{{"7"}, E_T_PETSKILL7} + ,{{""}, E_T_RARE} + ,{{""}, E_T_CRITICAL} + ,{{""}, E_T_COUNTER} + ,{{""}, E_T_SLOT} + ,{{""}, E_T_IMGNUMBER} + ,{{"ȼ"}, E_T_LIMITLEVEL} +#ifdef _PET_FUSION + ,{{"ںϳ"}, E_T_FUSIONCODE} +#endif +}; + +static CharBase EnemytempBaseChar[] = { + {{""}, E_T_NAME} +}; + +static int getInt (lua_State *L) +{ + const int array = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, EnemytempBaseInt, arraysizeof(EnemytempBaseInt)); + lua_pushinteger(L, ENEMYTEMP_getInt(array, element)); + return 1; +} + +static int getChar (lua_State *L) +{ + const int array = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, EnemytempBaseChar, arraysizeof(EnemytempBaseChar)); + lua_pushstring(L, ENEMYTEMP_getChar(array, element)); + return 1; +} + +static int getEnemyTempArray(lua_State *L) +{ + const int enemyid = luaL_checkint(L, 1); + lua_pushinteger(L, ENEMYTEMP_getEnemyTempArray(enemyid)); + return 1; +} + + +static int getEnemyTempArrayFromTempNo(lua_State *L) +{ + const int array = luaL_checkint(L, 1); + lua_pushinteger(L, ENEMYTEMP_getEnemyTempArrayFromTempNo(array)); + return 1; +} + +static int getEnemyTempArrayFromInitnum(lua_State *L) +{ + const int array = luaL_checkint(L, 1); + lua_pushinteger(L, ENEMYTEMP_getEnemyTempArrayFromInitnum(array)); + return 1; +} + +static int getEnemyTempNameFromEnemyID(lua_State *L) +{ + const int enemyid = luaL_checkint(L, 1); + int i; + for( i = 0; i < ENEMY_getEnemyNum(); i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == ENEMY_getEnemyNum() ){ + lua_pushstring(L, ""); + return 1; + } + int tarray = ENEMYTEMP_getEnemyTempArray( i ); + + if( !ENEMYTEMP_CHECKINDEX( tarray)) { + lua_pushstring(L, ""); + }else{ + lua_pushstring(L, ENEMYTEMP_getChar(tarray, E_T_NAME)); + } + return 1; +} + + +static int getEnemyTempIDFromEnemyID(lua_State *L) +{ + const int enemyid = luaL_checkint(L, 1); + int i; + for( i = 0; i < ENEMY_getEnemyNum(); i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == ENEMY_getEnemyNum() ){ + lua_pushinteger(L, -1); + return 1; + } + lua_pushinteger(L, ENEMY_getInt( i, ENEMY_TEMPNO)); + return 1; +} + + + + +static const luaL_Reg enemytemplib[] = { + {"getInt", getInt}, + {"getChar", getChar}, + {"getEnemyTempArray", getEnemyTempArray}, + {"getEnemyTempArrayFromTempNo", getEnemyTempArrayFromTempNo}, + {"getEnemyTempArrayFromInitnum", getEnemyTempArrayFromInitnum}, + {"getEnemyTempNameFromEnemyID", getEnemyTempNameFromEnemyID}, + {"getEnemyTempIDFromEnemyID", getEnemyTempIDFromEnemyID}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Enemytemp (lua_State *L) { + luaL_register(L, "enemytemp", enemytemplib); + return 1; +} +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/family.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/family.c new file mode 100644 index 0000000..10c86e7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/family.c @@ -0,0 +1,64 @@ +#include +#include "char.h" +#include "char_base.h" +#include "family.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "saacproto_cli.h" + +#ifdef _ALLBLUES_LUA + +extern char familyListBuf[MAXFAMILYLIST]; +#ifdef _MO_LUA_FMPOINT +extern struct FM_POINTLIST fmpointlist; // ݵ +#endif + +static int ShowFamilyList(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char subbuf[256]; + if( getStringFromIndexWithDelim( familyListBuf, "|", index, subbuf, sizeof(subbuf) ) == TRUE){ + lua_pushstring(L, subbuf); + }else{ + lua_pushstring(L, ""); + } + return 1; +} +#ifdef _MO_LUA_FMPOINT +static int ShowPointListArray(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if (index>=FAMILY_MAXHOME || index<0) lua_pushstring(L, fmpointlist.pointlistarray[0]); + lua_pushstring(L, fmpointlist.pointlistarray[index]); + return 1; +} +#endif +extern int getFamilyBadge(int index); +static int GetFamilyBadge(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + if (CHAR_CHECKINDEX(index)){ + lua_pushinteger(L,getFamilyBadge(index)); + }else lua_pushinteger(L,0); + return 1; +} +static const luaL_Reg Familylib[] = { + {"ShowFamilyList", ShowFamilyList}, + {"GetFamilyBadge", GetFamilyBadge}, +#ifdef _MO_LUA_FMPOINT + {"ShowPointListArray", ShowPointListArray}, +#endif + {NULL, NULL} +}; + +LUALIB_API int luaopen_Family (lua_State *L) { + luaL_register(L, "family", Familylib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/function.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/function.c new file mode 100644 index 0000000..767d2fe --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/function.c @@ -0,0 +1,1998 @@ +#include +#include "common.h" +#include "char_base.h" +#include "item.h" +#include "configfile.h" +#include "battle.h" +#include "mylua/base.h" +#include "longzoro/version.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "mylua/mylua.h" + +#ifdef _ALLBLUES_LUA +extern MY_Lua MYLua; + +lua_State *FindLua(char *filename) +{ + MY_Lua *mylua = &MYLua; + char newfilename[256]; + while(mylua->next != NULL){ + if(strcmptail( mylua->luapath, ".allblues" ) == 0 ){ + sprintf(newfilename, "%s.allblues", filename); + }else{ + sprintf(newfilename, "%s", filename); + } + + if(strcmp(newfilename, mylua->luapath) == 0){ + return mylua->lua; + } + mylua = mylua->next; + } + + return NULL; +} + + +#ifdef _MO_LUA_MERGE_CALLBACK +BOOL MergeCallBack( int charaindex, int petindex, char* data, int flg) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/mergecallback.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "MergeCallBack"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,petindex); + lua_pushstring(lua,data); + lua_pushnumber(lua,flg); + // printf("GloryCallBack:%d,%d\n", charaindex, point); + docall(lua, 4, 1); + + return TRUE; +} +#endif + +#ifdef _RIDEFLG_ +BOOL FamilyRideCheck( int meindex, int petindex, int petid ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/familyridefunction.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FamilyRideCheck"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + //η + lua_pushnumber(lua,meindex); + lua_pushnumber(lua,petindex); + lua_pushnumber(lua,petid); + + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + + +#ifdef _NEW_TITLE +int GetCharNewTitleNo( int charaindex, int id ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freechartitle.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "GetCharNewTitleNo"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,id); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + +char* GetCharNewTitleName( int charaindex, int id ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freechartitle.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "GetCharNewTitleName"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,id); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isstring(lua, -1)) + error(lua, "function `f' must return a string"); + + char *ret = lua_tostring(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + +#ifdef _CHAR_TITLE_STR_ +char* GetCharNewTitleString( int charaindex, int id ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freechartitle.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "GetCharNewTitleString"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,id); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isstring(lua, -1)) + error(lua, "function `f' must return a string"); + + char *ret = lua_tostring(lua, -1); + lua_pop(lua, 1); + return ret; +} + +#endif + +#ifdef _FAMILYBADGE_ +BOOL LoadFamilyBadge( int fd ) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/other/familybadge/init.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "LoadFamilyBadge"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,fd); + docall(lua, 1, 1); + + return TRUE; +} +#endif + +#ifdef _ALLBLUES_LUA_1_9 +int FreeCharDelet( int fd, char* cdkey,char* passwd ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freechardelete.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeCharDelete"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, fd); + lua_pushstring(lua, cdkey); + lua_pushstring(lua, passwd); + + if (lua_pcall(lua, 3, 1, 0) != 0) + return TRUE; + + if (!lua_isnumber(lua, -1)) + return TRUE; + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +BOOL BattleCommand( int charaindex, int battleindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/battlecommand.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "BattleCommand"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, battleindex); + docall(lua, 2, 1); + + return TRUE; +} +#ifdef _MO_LUA_KS_CALLBACK +BOOL FreeSelectBattlePet( int charaindex, int petarray ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/FreeSelectBattlePet.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeSelectBattlePet"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η2 + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, petarray); + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + if(ret == FALSE){ + return FALSE; + } + return TRUE; +} +#endif + + +int FreeItemInslay( int charaindex, int inslayindex, int itemindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freeiteminslay.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeItemInslay"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, inslayindex); + lua_pushnumber(lua, itemindex); + + + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} +#ifdef _LOCK_PET_ITEM +#ifdef _CTRL_TRANS_DEVELOP +int FreeCtrlTransDevelop( int petindex, int type ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freectrltransdevelop.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeCtrlTransDevelop"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, petindex); + lua_pushnumber(lua, type); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} +#endif +int FreeFmPk() +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freefmpk.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeFmPk"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + if (lua_pcall(lua, 0, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +int FreeStreetVendorPet( int charaindex, int petindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freestreetvendor.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeStreetVendorPet"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, petindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +int FreeStreetVendorItem( int charaindex, int itemindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freestreetvendor.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeStreetVendorItem"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +int FreeTradePet( int charaindex, int petindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freetrade.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeTradePet"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, petindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +int FreeTradeItem( int charaindex, int itemindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freetrade.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeTradeItem"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +#ifdef _LOCK_PET_ITEM +int FreeDropItem( int charaindex, int itemindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freedrop.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeDropItem"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} +#endif + +int FreeLockPetSave( int charaindex, int petindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freelockpetsave.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeLockPetSave"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, petindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} +#endif +void FreeAddFMAdv( int charaindex, int shiftbit ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freeaddfmadv.lua"); + if (lua == NULL)return ; + } + + lua_getglobal(lua, "FreeAddFMAdv"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return ; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, shiftbit); + docall(lua, 2, 1); + +} +#ifdef _FIRST_LOCK_ITEM +void FreeFirstLockPet( int charaindex, int petindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freefirstlock.lua"); + if (lua == NULL)return ; + } + + lua_getglobal(lua, "FreeFirstLockPet"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return ; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, petindex); + + docall(lua, 2, 1); + +} +void FreeFirstLockItem( int charaindex, int itemindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freefirstlock.lua"); + if (lua == NULL)return ; + } + + lua_getglobal(lua, "FreeFirstLockItem"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return ; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + +} +#endif + +void FreeCharExpSave( int charindex, int exp ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freecharexpsave.lua"); + if (lua == NULL)return ; + } + + lua_getglobal(lua, "FreeCharExpSave"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return ; + } + //η + lua_pushnumber(lua, charindex); + lua_pushnumber(lua, exp); + + docall(lua, 2, 1); + +} +#ifdef _PET_FUSION_LUA +int FreeFusionTableForBase( int MainIndex, int Subindex1, int Subindex2 ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freefusion.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeFusionTableForBase"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua, MainIndex); + lua_pushnumber(lua, Subindex1); + lua_pushnumber(lua, Subindex2); + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +BOOL FreeFusionSkill( int petskill ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freefusion.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeFusionSkill"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //ηһ + lua_pushnumber(lua, petskill); + if (lua_pcall(lua, 1, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} +#endif + +BOOL FreeAction( int charaindex, int x, int y, int actionno ) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/freeaction.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeAction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,x); + lua_pushnumber(lua,y); + lua_pushnumber(lua,actionno); + docall(lua, 4, 1); + + return TRUE; +} + +int FreeModeExp( int charindex, int getexp, int modexp ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freemodeexp.lua"); + if (lua == NULL)return 1; + } + + lua_getglobal(lua, "FreeModeExp"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return 1; + } + //ηһ + lua_pushnumber(lua, charindex); + lua_pushnumber(lua, getexp); + lua_pushnumber(lua, modexp); + if (lua_pcall(lua, 3, 1, 0) != 0) + return 1; + + if (!lua_isnumber(lua, -1)) + return 1; + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +BOOL FreePlayerExp( int charaindex ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freeplayerexp.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreePlayerExp"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //ηһ + lua_pushnumber(lua, charaindex); + + if (lua_pcall(lua, 1, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +BOOL FreeSaMenu( int charaindex, int index ) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/freesamenu.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeSaMenu"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,index); + + // printf("FreeSaMenu:%d,%d\n", charaindex, index); + docall(lua, 2, 1); + + return TRUE; +} + +#ifdef _DATA_INFO_SHOW +BOOL FreeDataInfoShow( int charaindex ) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/freedatainfoshow.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeDataInfoShow"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,charaindex); + docall(lua, 1, 1); + + return TRUE; +} +#endif +#ifdef _FAME_REG_TIME +BOOL FreeFameFeatures( int charaindex, int kind, int flg ) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/freefamefeatures.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeFameFeatures"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,kind); + lua_pushnumber(lua,flg); + + docall(lua, 3, 1); + + return TRUE; +} +#endif +BOOL FreeComplianceParameter( int charaindex ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freecomplianceparameter.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeComplianceParameter"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + //ηһ + lua_pushnumber(lua,charaindex); + + docall(lua, 1, 1); + + return TRUE; +} + +BOOL FreeLoginCheck( int fd ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freelogincheck.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreeLoginCheck"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //ηһ + lua_pushnumber(lua,fd); + + if (lua_pcall(lua, 1, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + + lua_pop(lua, 1); + + return ret; +} + +BOOL FreeCharLogout( int charaindex ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freecharlogout.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeCharLogout"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + //ηһ + lua_pushnumber(lua,charaindex); + docall(lua, 1, 1); + + return TRUE; +} + +BOOL EquipEffectFunction( int charaindex, int id ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/equipeffectfunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "EquipEffectFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,id); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + +BOOL EquipChangeFunction( int charaindex, int id ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/equipeffectfunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "EquipChangeFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,id); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + + +BOOL WalkFunction( int charaindex ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "WalkFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + + lua_pushnumber(mylua->lua,charaindex); + + if (lua_pcall(mylua->lua, 1, 1, 0) != 0) + error(mylua->lua, "error running function `f': %s", lua_tostring(mylua->lua, -1)); + + if (!lua_isnumber(mylua->lua, -1)) + error(mylua->lua, "function `f' must return a number"); + + int ret = lua_tonumber(mylua->lua, -1); + lua_pop(mylua->lua, 1); + if(ret == TRUE){ + return TRUE; + } + + mylua = mylua->next; + } + + return FALSE; +} +#ifdef _ITEM_OVER_LAP +BOOL ItemOverlapFunction( int charindex, int fromitemindex, int toitemindex ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "ItemOverlapFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + //η + lua_pushnumber(mylua->lua,charindex); + lua_pushnumber(mylua->lua,fromitemindex); + lua_pushnumber(mylua->lua,toitemindex); + + lua_pcall(mylua->lua, 3, 1, 0); + + lua_isnumber(mylua->lua, -1); + + int ret = lua_tonumber(mylua->lua, -1); + lua_pop(mylua->lua, 1); + if(ret == 1){ + mylua = mylua->next; + continue; + } + return ret; + } + + return TRUE; +} + +BOOL ItemOverlapedFunction( int charindex, int fromitemindex, int fromid, int toitemindex, int toid) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "ItemOverlapedFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + //η + lua_pushnumber(mylua->lua,charindex); + lua_pushnumber(mylua->lua,fromitemindex); + lua_pushnumber(mylua->lua,fromid); + lua_pushnumber(mylua->lua,toitemindex); + lua_pushnumber(mylua->lua,toid); + + docall(mylua->lua, 5, 1); + mylua = mylua->next; + } + + return TRUE; +} +#endif + +BOOL BattleFinishPvEFunction( int battleindex, int charaindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/battlefinishfunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "BattleFinishPvEFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,battleindex); + lua_pushnumber(lua,charaindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL BattleFinishFunction( int charaindex, int battletime, int battleturn, int battletype ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/battlefinishfunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "BattleFinishFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,battletime); + lua_pushnumber(lua,battleturn); + lua_pushnumber(lua,battletype); + + docall(lua, 4, 1); + + return TRUE; +} + +#ifdef _MO_LUA_BATTLE_START +BOOL BattleStartFunction( int battleindex) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/battlestartfunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "BattleStartFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,battleindex); + + docall(lua, 1, 1); + + return TRUE; +} +#endif + +BOOL SetBattleEnmeyFunction(int meindex, int enemyindex, int id ) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_BATTLESETFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, meindex); + lua_pushnumber(lua, enemyindex); + lua_pushnumber(lua, id); + docall(lua, 3, 1); + + return TRUE; +} + +#endif + +#ifdef _ALLBLUES_LUA_1_8 +BOOL CaptureOkFunction( int attackindex, int defindex ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "CaptureOkFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + //η + lua_pushnumber(mylua->lua,attackindex); + lua_pushnumber(mylua->lua,defindex); + + docall(mylua->lua, 2, 1); + mylua = mylua->next; + } + + return TRUE; +} + +BOOL CaptureCheckFunction( int attackindex, int defindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/capturefunction.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "CaptureCheckFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + + //η + lua_pushnumber(lua,attackindex); + lua_pushnumber(lua,defindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + +#ifdef _ALLBLUES_LUA_1_7 +BOOL CharVsEnemyFunction( int charaindex ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "CharVsEnemyFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + + lua_pushnumber(mylua->lua,charaindex); + + if (lua_pcall(mylua->lua, 1, 1, 0) != 0) + error(mylua->lua, "error running function `f': %s", lua_tostring(mylua->lua, -1)); + + if (!lua_isnumber(mylua->lua, -1)) + error(mylua->lua, "function `f' must return a number"); + + int ret = lua_tonumber(mylua->lua, -1); + lua_pop(mylua->lua, 1); + if(ret == TRUE){ + return TRUE; + } + + mylua = mylua->next; + } + + return FALSE; +} +#endif + +#ifdef _ALLBLUES_LUA_1_6 +BOOL CharTalkFunction( int charaindex, char *message, int color ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/chartalkfunction.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "CharTalkFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + //η + lua_pushnumber(lua,charaindex); + lua_pushstring(lua,message); + lua_pushnumber(lua,color); + + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + +BOOL FamilyRideFunction( int meindex, int petindex, int petid ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/familyridefunction.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FamilyRideFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + //η + lua_pushnumber(lua,meindex); + lua_pushnumber(lua,petindex); + lua_pushnumber(lua,petid); + + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + +#ifdef _ALLBLUES_LUA_1_5 +BOOL NetLoopFunction( void ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "NetLoopFunction"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + docall(mylua->lua, 0, 1); + mylua = mylua->next; + } + + return TRUE; +} + +BOOL FreeCharCreate( int charaindex ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freecharcreate.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeCharCreate"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + //η + lua_pushnumber(lua,charaindex); + + docall(lua, 1, 1); + + return TRUE; +} + +BOOL FreeCharLogin( int charaindex ) +{ + static lua_State *lua; + + + if (lua == NULL){ + lua = FindLua("data/ablua/freecharlogin.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeCharLogin"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + lua_pushnumber(lua,charaindex); + + if (lua_pcall(lua, 1, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + +BOOL FreeVsPlayer( int charaindex, int toindex ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freevsplayer.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "FreeVsPlayer"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,toindex); + + if (lua_pcall(lua, 2, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} + +BOOL FreePartyJoin( int charaindex, int toindex ) +{ + MY_Lua *mylua = &MYLua; + while(mylua->lua != NULL){ + lua_getglobal(mylua->lua, "FreePartyJoin"); + + if (!lua_isfunction(mylua->lua, -1)) { + lua_pop(mylua->lua, 1); + mylua = mylua->next; + continue; + } + //η + lua_pushnumber(mylua->lua,charaindex); + lua_pushnumber(mylua->lua,toindex); + + if (lua_pcall(mylua->lua, 2, 1, 0) != 0) + error(mylua->lua, "error running function `f': %s", lua_tostring(mylua->lua, -1)); + + + if (!lua_isnumber(mylua->lua, -1)) + error(mylua->lua, "function `f' must return a number"); + + int ret = lua_tonumber(mylua->lua, -1); + lua_pop(mylua->lua, 1); + if(ret == FALSE){ + return FALSE; + } + + mylua = mylua->next; + } + + return TRUE; +} +#endif + +#ifdef _ALLBLUES_LUA_1_4 + +BOOL RunCharLogOutEvent( int charaindex) +{ + lua_State *lua = CHAR_getLUAFunction(charaindex, CHAR_LOGINOUTFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + + docall(lua, 1, 1); + + return TRUE; +} + +BOOL BattleFinish( int battleindex, int charaindex) +{ + lua_State *lua = BATTLE_getLUAFunction(battleindex, BATTLE_FINISH); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + + docall(lua, 1, 1); + + return TRUE; +} + +BOOL BattleEscape( int battleindex, int charaindex) +{ + lua_State *lua = BATTLE_getLUAFunction(battleindex, BATTLE_ESCAPE); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + + docall(lua, 1, 1); + + return TRUE; +} +#endif + +#ifdef _OFFLINE_SYSTEM +BOOL OffLineCommand( int battleindex, int charaindex, int side) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/offlinecommand.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "OffLineCommand"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua,battleindex); + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,side); + + docall(lua, 3, 1); + + return TRUE; +} +#endif + + + + +void ABNPC_Lua_NEWSHOP_Recv( int charaindex) +{ + static lua_State *lua; + if (lua == NULL){ + char token[256]; + snprintf(token,sizeof(token), "data/ablua/newshop.lua"); + lua = FindLua(token); + if (lua == NULL)return; + } + lua_getglobal(lua, "newshop"); + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return; + } + //η + lua_pushnumber(lua, charaindex); + docall(lua, 1, 1); + + return; +} + +#ifdef _PETSKILL_SHOP_LUA +BOOL FreePetSkillShop( int talkerindex, int petindex, int oldSkillID, int newSkillID) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freepetskillshop.lua"); + if (lua == NULL)return TRUE; + } + + lua_getglobal(lua, "FreePetSkillShop"); + + if (!lua_isfunction(lua, -1)) { + return TRUE; + } + //η + lua_pushnumber(lua,talkerindex); + lua_pushnumber(lua,petindex); + lua_pushnumber(lua,oldSkillID); + lua_pushnumber(lua,newSkillID); + + if (lua_pcall(lua, 4, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isnumber(lua, -1)) + error(lua, "function `f' must return a number"); + + int ret = lua_tonumber(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + +#ifdef _ALLBLUES_LUA_1_2 +BOOL RunUseChatMagic( int charaindex, char *data, lua_State *lua) +{ + if(lua == NULL)return FALSE; + + //η + lua_pushnumber(lua, charaindex); + lua_pushstring(lua, data); + + docall(lua, 2, 1); + + return TRUE; +} + + +BOOL RunItemUseEvent( int itemindex, int charaindex, int toindex, int haveitemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_USEFUNC); + if ( lua == NULL) { + return FALSE; + } + + //ηĸ + lua_pushnumber(lua, itemindex); + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, toindex); + lua_pushnumber(lua, haveitemindex); + + docall(lua, 4, 1); + + return TRUE; +} + +BOOL RunItemDieReLifeEvent( int charaindex, int itemindex, int haveitemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_DIERELIFEFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + lua_pushnumber(lua, haveitemindex); + + docall(lua, 3, 1); + + return TRUE; +} + +BOOL RunItemDetachEvent( int charaindex, int itemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_DETACHFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunItemAttachEvent( int charaindex, int itemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_ATTACHFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunItemPickupEvent( int charaindex, int itemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_PICKUPFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunItemPostOverEvent( int itemindex, int charaindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_POSTOVERFUNC); + if ( lua == NULL) { + return FALSE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunItemPreOverEvent( int itemindex, int charaindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_PREOVERFUNC); + if ( lua == NULL) { + return FALSE; + } + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunItemDropEvent( int charaindex, int itemindex ) +{ + lua_State *lua = ITEM_getLUAFunction(itemindex, ITEM_DROPFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, charaindex); + lua_pushnumber(lua, itemindex); + + docall(lua, 2, 1); + + return TRUE; +} + +#endif + + +BOOL RunCharTalkedEvent(int meindex, int toindex, char *messageeraseescape, int color, int channel) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_TALKEDFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua,meindex); + lua_pushnumber(lua,toindex); + lua_pushstring(lua,messageeraseescape); + lua_pushnumber(lua,color); + lua_pushnumber(lua,channel); + + docall(lua, 5, 1); + + return TRUE; +} + + +BOOL RunCharLoopEvent(int meindex) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_LOOPFUNC); + if ( lua == NULL) { + return FALSE; + } + + //ηһ + lua_pushnumber(lua,meindex); + docall(lua, 1, 1); + + return TRUE; +} + +BOOL RunCharOverlapEvent( int meindex, int toindex) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_OVERLAPEDFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, meindex); + lua_pushnumber(lua, toindex); + docall(lua, 2, 1); + + return TRUE; +} + +BOOL RunCharBattleOverEvent( int meindex, int battleindex, int iswin) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_BATTLEOVERDFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, meindex); + lua_pushnumber(lua, battleindex); + lua_pushnumber(lua, iswin); + docall(lua, 3, 1); + + return TRUE; +} + +BOOL RunCharWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + lua_State *lua = CHAR_getLUAFunction(meindex, CHAR_WINDOWTALKEDFUNC); + if ( lua == NULL) { + return FALSE; + } + + //η + lua_pushnumber(lua, meindex); + lua_pushnumber(lua, talkerindex); + lua_pushnumber(lua, seqno); + lua_pushnumber(lua, select); + lua_pushstring(lua, data); + + docall(lua, 5, 1); + + return TRUE; +} + +#ifdef _VISUAL_BEATITUDE +void FreeVisualBeatitude( int charaindex,int petindex,int type) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/freevisualbeatitude.lua"); + if (lua == NULL) return; + } + lua_getglobal(lua, "FreeVisualBeatitude"); + if (!lua_isfunction(lua, -1)) { + return; + } + //η + lua_pushnumber(lua,charaindex); + lua_pushnumber(lua,petindex); + lua_pushnumber(lua,type); + docall(lua, 3, 1); + return; +} + +char* BeatitudeCheck( int meindex, int petindex,int havepetindex) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/freevisualbeatitude.lua"); + if (lua == NULL)return FALSE; + } + + lua_getglobal(lua, "BeatitudeCheck"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return FALSE; + } + + //η + lua_pushnumber(lua,meindex); + lua_pushnumber(lua,petindex); + lua_pushnumber(lua,havepetindex); + + if (lua_pcall(lua, 3, 1, 0) != 0) + error(lua, "error running function `f': %s", lua_tostring(lua, -1)); + + if (!lua_isstring(lua, -1)) + error(lua, "function `f' must return a string"); + + int ret = lua_tostring(lua, -1); + lua_pop(lua, 1); + return ret; +} +#endif + +#ifdef _RIDEQUERY_ +void FreeRideQuery( int charaindex) +{ + static lua_State *lua; + if (lua == NULL){ + lua = FindLua("data/ablua/familyridefunction.lua"); + if (lua == NULL) return; + } + lua_getglobal(lua, "FreeRideQuery"); + if (!lua_isfunction(lua, -1)) { + return; + } + //η + lua_pushnumber(lua,charaindex); + docall(lua, 1, 1); + return; +} +#endif + +#ifdef _RED_MEMOY_ +BOOL RedMoneyFunction( int charaindex, char* data ) +{ + static lua_State *lua; + + if (lua == NULL){ + lua = FindLua("data/ablua/redmoneyfunction.lua"); + if (lua == NULL)return TRUE; + } + lua_getglobal(lua, "RedMoneyFunction"); + + if (!lua_isfunction(lua, -1)) { + lua_pop(lua, 1); + return TRUE; + } + //η + lua_pushnumber(lua,charaindex); + lua_pushstring(lua, data); + docall(lua, 2, 1); + return TRUE; +} +#endif +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/init.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/init.c new file mode 100644 index 0000000..257dd03 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/init.c @@ -0,0 +1,62 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" +#include "mylua/base.h" + +static const luaL_Reg lualibs[] = { + {"char", luaopen_Char}, + {"npc", luaopen_NPC}, + {"lssproto", luaopen_Lssproto}, + {"battle", luaopen_Battle}, + {"obj", luaopen_Object}, +#ifdef _ALLBLUES_LUA_1_1 + {"map", luaopen_Map}, + {"other", luaopen_Other}, + {"config", luaopen_Config}, +#endif +#ifdef _ALLBLUES_LUA_1_2 + {"item", luaopen_Item}, + {"magic", luaopen_Magic}, +#endif +#ifdef _OFFLINE_SYSTEM + {"offline", luaopen_Offline}, +#endif +#ifdef _ALLBLUES_LUA_1_4 + {"enemytemp", luaopen_Enemytemp}, +#ifdef _SASQL + {"sasql", luaopen_Sasql}, +#endif +#endif + {"net", luaopen_Net}, + {"saacproto", luaopen_Saacproto}, +#ifdef _ALLBLUES_LUA_1_8 +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + {"Professionskill", luaopen_ProfessionSkill}, +#endif + {"family", luaopen_Family}, + {"petskill", luaopen_PetSkill}, +#endif + {NULL, NULL} +}; + + +LUALIB_API void luaAB_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/itembase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/itembase.c new file mode 100644 index 0000000..7ce09cb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/itembase.c @@ -0,0 +1,375 @@ +#include +#include "common.h" +#include "char_base.h" +#include "mylua/base.h" +#include "char.h" +#include "item.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _ALLBLUES_LUA_1_2 +#include "mylua/mylua.h" +extern MY_Lua MYLua; +static CharBase ItemBaseInt[] = { + {{""}, ITEM_ID} + ,{{"ͼ"}, ITEM_BASEIMAGENUMBER} + ,{{"ֵ"}, ITEM_COST} + ,{{""}, ITEM_TYPE} + ,{{"ʹ"}, ITEM_ABLEUSEFIELD} + ,{{"Ŀ"}, ITEM_TARGET} + ,{{"ȼ"}, ITEM_LEVEL} + ,{{""}, ITEM_DAMAGEBREAK} + ,{{"ѵ"}, ITEM_USEPILENUMS} + ,{{"ص"}, ITEM_CANBEPILE} + ,{{"蹥"}, ITEM_NEEDSTR} + ,{{""}, ITEM_NEEDDEX} + ,{{"ת"}, ITEM_NEEDTRANS} + ,{{"ְҵ"}, ITEM_NEEDPROFESSION} +#ifdef _TAKE_ITEMDAMAGE + ,{{"С"}, ITEM_DAMAGECRUSHE} + ,{{""}, ITEM_MAXDAMAGECRUSHE} +#endif + ,{{""}, ITEM_OTHERDAMAGE} + ,{{""}, ITEM_OTHERDEFC} + ,{{"װ"}, ITEM_SUITCODE} + ,{{"С"}, ITEM_ATTACKNUM_MIN} + ,{{"󹥻"}, ITEM_ATTACKNUM_MAX} + ,{{""}, ITEM_MODIFYATTACK} + ,{{""}, ITEM_MODIFYDEFENCE} + ,{{""}, ITEM_MODIFYQUICK} + ,{{"HP"}, ITEM_MODIFYHP} + ,{{"MP"}, ITEM_MODIFYMP} + ,{{""}, ITEM_MODIFYLUCK} + ,{{""}, ITEM_MODIFYCHARM} + ,{{"ر"}, ITEM_MODIFYAVOID} + ,{{""}, ITEM_MODIFYATTRIB} + ,{{"Ա"}, ITEM_MODIFYATTRIBVALUE} + ,{{""}, ITEM_MAGICID} + ,{{"о"}, ITEM_MAGICPROB} + ,{{"MP"}, ITEM_MAGICUSEMP} + ,{{""}, ITEM_MODIFYARRANGE} + ,{{""}, ITEM_MODIFYSEQUENCE} + ,{{""}, ITEM_ATTACHPILE} + ,{{""}, ITEM_HITRIGHT} + ,{{""}, ITEM_NEGLECTGUARD} + ,{{""}, ITEM_POISON} + ,{{""}, ITEM_PARALYSIS} + ,{{"˯"}, ITEM_SLEEP} + ,{{"ʯ"}, ITEM_STONE} + ,{{""}, ITEM_DRUNK} + ,{{""}, ITEM_CONFUSION} + ,{{""}, ITEM_CRITICAL} + ,{{""}, ITEM_USEACTION} + ,{{"dzʧ"}, ITEM_DROPATLOGOUT} + ,{{"ʧ"}, ITEM_VANISHATDROP} + ,{{""}, ITEM_ISOVERED} + ,{{"ʼ"}, ITEM_CANPETMAIL} + ,{{"ϳɴ"}, ITEM_CANMERGEFROM} + ,{{"ϳ"}, ITEM_CANMERGETO} + ,{{"0"}, ITEM_INGVALUE0} + ,{{"1"}, ITEM_INGVALUE1} + ,{{"2"}, ITEM_INGVALUE2} + ,{{"3"}, ITEM_INGVALUE3} + ,{{"4"}, ITEM_INGVALUE4} + ,{{"ɫ"}, ITEM_COLOER} + ,{{"Ʒȼ"}, ITEM_LEAKLEVEL} +#ifdef _ITEM_USE_TIME + ,{{"Ʒʱ"}, ITEM_USETIME} +#endif +}; + +static CharBase ItemBaseChar[] = { + {{""}, ITEM_NAME} + ,{{"ʾ"}, ITEM_SECRETNAME} + ,{{"˵"}, ITEM_EFFECTSTRING} + ,{{"ֶ"}, ITEM_ARGUMENT} + ,{{"ɷ0"}, ITEM_INGNAME0} + ,{{"ɷ1"}, ITEM_INGNAME1} + ,{{"ɷ2"}, ITEM_INGNAME2} + ,{{"ɷ3"}, ITEM_INGNAME3} + ,{{"ɷ4"}, ITEM_INGNAME4} +#ifdef _ANGEL_SUMMON + ,{{""}, ITEM_ANGELMISSION} + ,{{"ʹ"}, ITEM_ANGELINFO} + ,{{"Ӣ"}, ITEM_HEROINFO} +#endif + ,{{"Unicode"}, ITEM_UNIQUECODE} + ,{{""}, ITEM_UNIQUECODE} +}; + +static CharBase ItemBaseValue[] = { + {{"צ"}, ITEM_FIST} + ,{{""}, ITEM_AXE} + ,{{""}, ITEM_CLUB} + ,{{"ǹ"}, ITEM_SPEAR} + ,{{""}, ITEM_BOW} + ,{{""}, ITEM_SHIELD} + ,{{""}, ITEM_HELM} + ,{{""}, ITEM_ARMOUR} + ,{{""}, ITEM_BRACELET} + ,{{""}, ITEM_MUSIC} + ,{{""}, ITEM_NECKLACE} + ,{{""}, ITEM_RING} + ,{{""}, ITEM_BELT} + ,{{""}, ITEM_EARRING} + ,{{"ǻ"}, ITEM_NOSERING} + ,{{""}, ITEM_AMULET} + ,{{""}, ITEM_OTHER} + ,{{""}, ITEM_BOOMERANG} + ,{{"Ͷ"}, ITEM_BOUNDTHROW} + ,{{"Ͷʯ"}, ITEM_BREAKTHROW} + ,{{""}, ITEM_DISH} +#ifdef _ITEM_INSLAY + ,{{""}, ITEM_METAL} + ,{{"ʯ"}, ITEM_JEWEL} +#endif +#ifdef _ITEM_CHECKWARES + ,{{""}, ITEM_WARES} +#endif +#ifdef _ITEM_EQUITSPACE + ,{{""}, ITEM_WBELT} + ,{{""}, ITEM_WSHIELD} + ,{{"Ь"}, ITEM_WSHOES} +#endif +#ifdef _EQUIT_NEWGLOVE + ,{{""}, ITEM_WGLOVE} +#endif +#ifdef _ALCHEMIST + ,{{""}, ITEM_ALCHEMIST} +#endif +#ifdef _PET_ITEM + ,{{"ͷ"}, ITEM_PET_HEAD} + ,{{""}, ITEM_PET_TOOTH} + ,{{"צ"}, ITEM_PET_CLAW} + ,{{""}, ITEM_PET_BREAST} + ,{{"豳"}, ITEM_PET_BACK} + ,{{""}, ITEM_PET_WING} + ,{{""}, ITEM_PET_FEET} +#endif +}; + +static CharBase ItemBaseWorkInt[] = { + {{""}, ITEM_WORKOBJINDEX} + ,{{""}, ITEM_WORKCHARAINDEX} +}; + +static CharBase ItemBaseEvent[] = { + {{"δ֪¼"}, ITEM_PREOVERFUNC} + ,{{"ʼ¼"}, ITEM_POSTOVERFUNC} + ,{{"ʹ¼"}, ITEM_USEFUNC} + ,{{"װ¼"}, ITEM_ATTACHFUNC} + ,{{"ж¼"}, ITEM_DETACHFUNC} + ,{{"¼"}, ITEM_DROPFUNC} + ,{{"¼"}, ITEM_PICKUPFUNC} + ,{{"¼"}, ITEM_DIERELIFEFUNC} +}; + +static int getInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseInt, arraysizeof(ItemBaseInt)); + + lua_pushinteger(L, ITEM_getInt(index, element)); + return 1; +} + +static int setInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseInt, arraysizeof(ItemBaseInt)); + const int data = luaL_checkint(L, 3); + + if(ITEM_setInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getChar(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseChar, arraysizeof(ItemBaseChar)); + + lua_pushstring(L, ITEM_getChar(index, element)); + return 1; +} + +static int setChar(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseChar, arraysizeof(ItemBaseChar)); + char *data = luaL_checklstring(L, 3, &l); + + if(ITEM_setChar(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getWorkInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseWorkInt, arraysizeof(ItemBaseWorkInt)); + + lua_pushinteger(L, ITEM_getWorkInt(index, element)); + return 1; +} + +static int setWorkInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ItemBaseWorkInt, arraysizeof(ItemBaseWorkInt)); + const int data = luaL_checkint(L, 3); + + if(ITEM_setWorkInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getNameFromNumber(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushstring(L, ITEM_getNameFromNumber(id)); + + return 1; +} + +static int getArgumentString(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushstring(L, ITEM_getArgumentString(id)); + + return 1; +} + +static int getcostFromITEMtabl(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushinteger(L, ITEM_getcostFromITEMtabl(id)); + + return 1; +} + +static int getlevelFromITEMtabl(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushinteger(L, ITEM_getlevelFromITEMtabl(id)); + + return 1; +} + +static int getgraNoFromITEMtabl(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushinteger(L, ITEM_getgraNoFromITEMtabl(id)); + + return 1; +} + +static int getItemInfoFromNumber(lua_State *L) +{ + const int id = luaL_checkint(L, 1); + + lua_pushstring(L, ITEM_getItemInfoFromNumber(id)); + + return 1; +} + +static int setFunctionPointer(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int functype = getCharBaseValue(L, 2, ItemBaseEvent, arraysizeof(ItemBaseEvent)); + char *luafuncname=luaL_checklstring(L, 3, &l); + + return ITEM_setLUAFunction( index, functype, luafuncname ); +} + +static int addLUAListFunction(lua_State *L) +{ + size_t l; + char *luafuncname=luaL_checklstring(L, 1, &l); + char *luafunctable=luaL_checklstring(L, 2, &l); + char *luafunctablepath=luaL_checklstring(L, 3, &l); + + if(strlen(luafunctablepath) > 0){ + MY_Lua *mylua = &MYLua; + while(mylua->next != NULL){ + if(strcmp(mylua->luapath, luafunctablepath) == 0){ + return ITEM_addLUAListFunction( mylua->lua, luafuncname, luafunctable); + } + mylua = mylua->next; + } + }else{ + return ITEM_addLUAListFunction( L, luafuncname, luafunctable ); + } + return 1; +} + +static int UpdataItemOne(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int itemindex = luaL_checkint(L, 2); + + int i; + for( i = 0; i < CheckCharMaxItem(charaindex) ; i++ ){ + if(itemindex == CHAR_getItemIndex( charaindex , i )){ + CHAR_sendItemDataOne( charaindex, i); + break; + } + } + + return 1; +} + +static int UpdataHaveItemOne(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int haveitemindex = luaL_checkint(L, 2); + + CHAR_sendItemDataOne( charaindex, haveitemindex); + + return 1; +} + +static const luaL_Reg itemlib[] = { + {"getInt", getInt}, + {"setInt", setInt}, + {"getChar", getChar}, + {"setChar", setChar}, + {"getWorkInt", getWorkInt}, + {"setWorkInt", setWorkInt}, + {"setFunctionPointer", setFunctionPointer}, + {"addLUAListFunction", addLUAListFunction}, + {"getNameFromNumber", getNameFromNumber}, + {"getArgumentString", getArgumentString}, + {"getcostFromITEMtabl", getcostFromITEMtabl}, + {"getlevelFromITEMtabl", getlevelFromITEMtabl}, + {"getgraNoFromITEMtabl", getgraNoFromITEMtabl}, + {"getItemInfoFromNumber", getItemInfoFromNumber}, + {"UpdataItemOne", UpdataItemOne}, + {"UpdataHaveItemOne", UpdataHaveItemOne}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Item (lua_State *L) { + luaL_register(L, "item", itemlib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/liblua.a b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/liblua.a new file mode 100644 index 0000000..0bcdda0 Binary files /dev/null and b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/liblua.a differ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/lssprotobase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/lssprotobase.c new file mode 100644 index 0000000..082a47f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/lssprotobase.c @@ -0,0 +1,390 @@ +#include +#include +#include +#include "char.h" +#include "char_base.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" + +#ifdef _ALLBLUES_LUA + + +#define WINDOW_BUTTONTYPE_NONE (0) +#define WINDOW_BUTTONTYPE_OK (1 << 0) +#define WINDOW_BUTTONTYPE_CANCEL (1 << 1) +#define WINDOW_BUTTONTYPE_YES (1 << 2) +#define WINDOW_BUTTONTYPE_NO (1 << 3) +#define WINDOW_BUTTONTYPE_PREV (1 << 4) +#define WINDOW_BUTTONTYPE_NEXT (1 << 5) + +#define WINDOW_BUTTONTYPE_OKCANCEL (WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL) +#define WINDOW_BUTTONTYPE_YESNO (WINDOW_BUTTONTYPE_YES | WINDOW_BUTTONTYPE_NO) + + +static CharBase CharBaseWindow[] = { + {{"Ի"}, WINDOW_MESSAGETYPE_MESSAGE} + ,{{""}, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT} + ,{{"ѡ"}, WINDOW_MESSAGETYPE_SELECT} + ,{{""}, WINDOW_MESSAGETYPE_PETSELECT} + ,{{"߿"}, WINDOW_MESSAGETYPE_ITEMSHOPMENU} + ,{{"߿"}, WINDOW_MESSAGETYPE_ITEMSHOPMAIN} + ,{{"ѧܿ"}, WINDOW_MESSAGETYPE_PETSKILLSHOP} +#ifdef _NEW_MANOR_LAW + ,{{"ʮƼ"}, WINDOW_FMMESSAGETYPE_10_MEMONTUM} + ,{{"б"}, WINDOW_FMMESSAGETYPE_FM_MEMONTUM} +#endif + ,{{"Աб"}, WINDOW_FMMESSAGETYPE_DENGON} + ,{{"ׯ԰б"}, WINDOW_FMMESSAGETYPE_POINTLIST} + ,{{"ǰб"}, WINDOW_FMMESSAGETYPE_TOP30DP} + ,{{"п"}, WINDOW_MESSAGETYPE_BANK} + ,{{"Ի"}, WINDOW_MESSAGETYPE_WIDEMESSAGE} + ,{{""}, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT} + ,{{""}, WINDOW_MESSAGETYPE_AUCTIONNEW} + ,{{""}, WINDOW_MESSAGETYPE_AUCTIONLIST_BUY} + ,{{"鿴"}, WINDOW_MESSAGETYPE_AUCTIONSURVEY} + ,{{"޸Ŀ"}, WINDOW_MESSAGETYPE_AUCTIONMODIFY} + ,{{"б޸Ŀ"}, WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY} + ,{{""}, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT} +}; + +static CharBase CharBaseButton[] = { + {{"ްť"}, WINDOW_BUTTONTYPE_NONE} + ,{{"ȷ"}, WINDOW_BUTTONTYPE_OK} + ,{{"ȡ"}, WINDOW_BUTTONTYPE_CANCEL} + ,{{"YES"}, WINDOW_BUTTONTYPE_YES} + ,{{"NO"}, WINDOW_BUTTONTYPE_NO} + ,{{"һҳ"}, WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_CANCEL} + ,{{"һҳ"}, WINDOW_BUTTONTYPE_NEXT|WINDOW_BUTTONTYPE_CANCEL} +}; + +static CharBase CharBaseSeqNo[] = { + {{""}, -1} +#ifdef _NEW_STREET_VENDOR + ,{{"̯"}, CHAR_WINDOWTYPE_STREET_VENDOR_TYPE} +#endif +#ifdef _PETSKILL_CANNEDFOOD + ,{{"\ѡ"}, ITEM_WINDOWTYPE_SELECTPETSKILL_SELECT} +#endif +#ifdef _ITEM_OVER_LAP + ,{{"ص"}, CHAR_WINDOWTYPE_ITEMOVERLAP} +#endif +}; + + +static int windows_validation(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + const int windowtype = getCharBaseValue(L, 2, CharBaseWindow, arraysizeof(CharBaseWindow)); + const int buttontype = getCharBaseValue(L, 3, CharBaseButton, arraysizeof(CharBaseButton)); + const int seqno = getCharBaseValue(L, 4, CharBaseSeqNo, arraysizeof(CharBaseSeqNo)); + const int objindex=luaL_checkint(L, 5); + char *data=luaL_checklstring(L, 6, &l); + const int yzm=luaL_checkint(L, 7); + + int validation = 0; + int i; +#ifdef _NEW_VERIFICAITON + validation = atoi(str); +#else + validation = yzm << 6; +#endif + lssproto_WN_send(fd, windowtype, buttontype + validation, seqno, objindex, data); + return 1; +} + +static int effect(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + char *data=luaL_checklstring(L, 2, &l); + lssproto_BATTLESKILL_send(fd, data); + + return 1; +} + +static int MagiccardAction(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + char *data=luaL_checklstring(L, 2, &l); + lssproto_MagiccardAction_send(fd, data); + + return 1; +} + +static int MagiccardDamage(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + const int position = luaL_checkint(L, 2); + const int damage = luaL_checkint(L, 3); + const int offsetx = luaL_checkint(L, 4); + const int offsety = luaL_checkint(L, 5); + + lssproto_MagiccardDamage_send(fd, position, damage, offsetx, offsety); + + return 1; +} + + +static int MoveScreen(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + const int bMoveScreenMove = luaL_checkint(L, 2); + const int iXY = luaL_checkint(L, 3); + + lssproto_MoveScreen_send(fd, bMoveScreenMove, iXY); + + return 1; +} +/* +static int TheaterData(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + char *data=luaL_checklstring(L, 2, &l); + lssproto_TheaterData_send(fd, data); + + return 1; +} +*/ + +static int windows_send(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + const int windowtype = getCharBaseValue(L, 2, CharBaseWindow, arraysizeof(CharBaseWindow)); + const int buttontype = getCharBaseValue(L, 3, CharBaseButton, arraysizeof(CharBaseButton)); + const int seqno = getCharBaseValue(L, 4, CharBaseSeqNo, arraysizeof(CharBaseSeqNo)); + const int objindex=luaL_checkint(L, 5); + char *data=luaL_checklstring(L, 6, &l); + + + lssproto_WN_send(fd, windowtype, buttontype, seqno, objindex, data); + return 1; +} + +static int show(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + char *data=luaL_checklstring(L, 2, &l); + + + lssproto_C_send(fd, data); + return 1; +} + +static int FM(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_FM_send(fd, data); + return 1; +} +#ifdef _ADD_STATUS_2 +static int S2(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_S2_send(fd, data); + return 1; +} +#endif + + int dengon(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(index) == FALSE) return 0; + int fd = getfdFromCharaIndex( index); + char *data=luaL_checklstring(L, 2, &l); + const int color=luaL_checkint(L, 3); + const int num=luaL_checkint(L, 4); + + lssproto_DENGON_send(fd, data, color, num); + return 1; +} + +static int CharList(lua_State *L) +{ + size_t l; + const int fd = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_CharList_send(fd, FAILED, data); + return 1; +} + +static int SaMenu(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + const int index = luaL_checkint(L, 2); + size_t l; + char *data=luaL_checklstring(L, 3, &l); + lssproto_SAMENU_send(fd, index, data); + return 1; +} + +static int W2(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + const int x = luaL_checkint(L, 2); + const int y = luaL_checkint(L, 3); + size_t l; + char *direction=luaL_checklstring(L, 4, &l); + lssproto_W2_recv(fd, x, y, direction); + return 1; +} + +static int B(lua_State *L) +{ + size_t l; + const int charaindex = luaL_checkint(L, 1); + if(CHAR_CHECKINDEX(charaindex) == FALSE) return 0; + int fd = getfdFromCharaIndex( charaindex); + char *data=luaL_checklstring(L, 2, &l); + lssproto_B_recv(fd, data); + + return 1; +} + +#ifdef _FAMILYBADGE_ +int FamilyBadgeData[200]; +int FamilyBadgeDataNum; +int FamilyBadgePrice; + +static int FamilyBadge(lua_State *L) +{ + size_t l; + const int fd = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_FamilyBadge_send(fd, data); + return 1; +} + +static int GetFBData(lua_State *L) +{ + FamilyBadgeDataNum=-1; + int len = luaL_getn(L, 1); + if(len>0){ + int i=1; + for(i;i<=len;i++){ + FamilyBadgeDataNum++; + lua_rawgeti(L, 1, i); + FamilyBadgeData[FamilyBadgeDataNum]=(int)lua_tointeger(L, -1); + lua_pop(L, 1); + } + } + FamilyBadgePrice = luaL_checkint(L, 2); + return 1; +} +#endif + +#ifdef _NEW_TITLE +static int CharTitleSend(lua_State *L) +{ + size_t l; + const int fd = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_CharTitle_send(fd, data); + return 1; +} +static int CharTitleCancel(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + CHAR_CancelNewTitle( charaindex); + return 1; +} +#endif + +#ifdef _VISUAL_BEATITUDE +static int VisualBeatitudeSend(lua_State *L) +{ + size_t l; + const int fd = luaL_checkint(L, 1); + char *data=luaL_checklstring(L, 2, &l); + + lssproto_VisualBeatitude_send(fd, data); + return 1; +} +#endif + +static const luaL_Reg lssprotolib[] = { + {"windows", windows_send}, + {"show", show}, + {"FM", FM}, +#ifdef _ADD_STATUS_2 + {"S2", S2}, +#endif + {"dengon", dengon}, + {"CharList", CharList}, + {"SaMenu", SaMenu}, + {"W2", W2}, + {"B", B}, + {"windows_validation", windows_validation}, + {"effect", effect}, + {"MagiccardAction", MagiccardAction}, + {"MagiccardDamage", MagiccardDamage}, + {"MoveScreen", MoveScreen}, +// {"TheaterData", TheaterData}, + +#ifdef _FAMILYBADGE_ + {"FamilyBadge", FamilyBadge}, + {"GetFBData", GetFBData}, +#endif +#ifdef _NEW_TITLE + {"CharTitleSend", CharTitleSend}, + {"CharTitleCancel", CharTitleCancel}, +#endif +#ifdef _VISUAL_BEATITUDE + {"VisualBeatitude",VisualBeatitudeSend}, +#endif + {NULL, NULL} +}; + +LUALIB_API int luaopen_Lssproto (lua_State *L) { + luaL_register(L, "lssproto", lssprotolib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/magicbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/magicbase.c new file mode 100644 index 0000000..b782937 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/magicbase.c @@ -0,0 +1,99 @@ +#include +#include "common.h" +#include "char_talk.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "mylua/ablua.h" +#include "magic_base.h" +#include "lssproto_serv.h" +#ifdef _ALLBLUES_LUA_1_2 +#include "mylua/mylua.h" +extern MY_Lua MYLua; + +static CharBase MagicBaseInt[] = { + {{"ID"}, MAGIC_ID} + ,{{"ֶ"}, MAGIC_FIELD} + ,{{"Ŀ"}, MAGIC_TARGET} + ,{{"Ŀ"}, MAGIC_TARGET_DEADFLG} +#ifdef _ATTACK_MAGIC + ,{{""}, MAGIC_IDX} +#endif +}; + + +static CharBase MagicBaseChar[] = { + {{""}, MAGIC_NAME} + ,{{"ע"}, MAGIC_COMMENT} + ,{{""}, MAGIC_FUNCNAME} + ,{{"ѡ"}, MAGIC_OPTION} +}; + + +static int addLUAListFunction(lua_State *L) +{ + size_t l; + char *luafuncname = luaL_checklstring(L, 1, &l); + char *luafunctable = luaL_checklstring(L, 2, &l); + char *luafunctablepath = luaL_checklstring(L, 3, &l); + const int gmlevel = luaL_checkint(L, 4); + char *usestring = luaL_checklstring(L, 5, &l); + + + if(strlen(luafunctablepath) > 0){ + MY_Lua *mylua = &MYLua; + while(mylua->next != NULL){ + if(strcmp(mylua->luapath, luafunctablepath) == 0){ + return MAGIC_addLUAListFunction( mylua->lua, luafuncname, luafunctable, gmlevel, usestring ); + } + mylua = mylua->next; + } + }else{ + return MAGIC_addLUAListFunction( L, luafuncname, luafunctable, gmlevel, usestring ); + } + return 1; + +} + +static int getChar(lua_State *L) +{ + const int magicid = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, MagicBaseChar, arraysizeof(MagicBaseChar)); + int marray = MAGIC_getMagicArray( magicid); + if( marray != -1 ){ + lua_pushstring(L, MAGIC_getChar( marray, element)); + }else{ + lua_pushstring(L, ""); + } + return 1; +} + +static int getInt(lua_State *L) +{ + const int magicid = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, MagicBaseInt, arraysizeof(MagicBaseInt)); + int marray = MAGIC_getMagicArray( magicid); + if( marray != -1 ){ + lua_pushinteger(L, MAGIC_getInt( marray, element)); + }else{ + lua_pushinteger(L, -1); + } + return 1; +} + + +static const luaL_Reg magiclib[] = { + {"addLUAListFunction", addLUAListFunction}, + {"getInt", getInt}, + {"getChar", getChar}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Magic (lua_State *L) { + luaL_register(L, "magic", magiclib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile new file mode 100755 index 0000000..8ebbc96 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile @@ -0,0 +1,1077 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmylua.a + +SRC=mylua.c ablua.c init.c charbase.c npcbase.c function.c lssprotobase.c battlebase.c objectbase.c mapbase.c otherbase.c configbase.c itembase.c magicbase.c offlinebase.c netbase.c enemytempbase.c sasqlbase.c saacproto.c family.c petskill.c profession_skill.c + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +mylua.o: mylua.c /usr/include/signal.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/bits/sigset.h /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/bits/signum.h \ + /usr/include/time.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h ../include/autil.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/buf.h ../include/util.h /usr/include/sys/time.h ../lua/lua.h \ + ../lua/luaconf.h /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/longzoro/version.h \ + ../include/mylua/mylua.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h +ablua.o: ablua.c /usr/include/pthread.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/sched.h \ + /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/time.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/signal.h /usr/include/bits/sigset.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/setjmp.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/string.h \ + /usr/include/sys/types.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/sys/sysmacros.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h ../include/autil.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/stdlib.h /usr/include/alloca.h ../include/mylua/mylua.h \ + ../lua/lua.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/mylua/base.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + ../include/link.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h +init.o: init.c ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h /usr/include/bits/stdio_lim.h \ + /usr/include/bits/sys_errlist.h ../include/mylua/base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h +charbase.o: charbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/battle.h ../include/trade.h ../include/object.h \ + ../include/char_base.h ../include/enemy.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/npcutil.h ../include/readmap.h ../include/log.h \ + ../include/pet.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h ../include/handletime.h \ + ../include/item_event.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/shop.h ../include/mylua/mylua.h +npcbase.o: npcbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/battle.h ../include/net.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/trade.h \ + ../include/util.h /usr/include/stdlib.h /usr/include/alloca.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char_base.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/npccreate.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/enemy.h ../include/npc_eventaction.h ../lua/lua.h \ + ../include/longzoro/version.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/npcutil.h ../include/log.h +function.o: function.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/item.h ../include/configfile.h ../include/battle.h \ + ../include/trade.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/mylua.h +lssprotobase.o: lssprotobase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/math.h /usr/include/bits/huge_val.h \ + /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +battlebase.o: battlebase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/enemy.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/battle.h ../include/trade.h \ + ../include/battle_command.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/mylua.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/base.h ../include/char_base.h +objectbase.o: objectbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/object.h ../include/longzoro/version.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h +mapbase.o: mapbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/readmap.h ../include/map_deal.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +otherbase.o: otherbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h ../include/char.h ../include/common.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/util.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_scheduleman.h \ + ../include/mylua/mylua.h +configbase.o: configbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/configfile.h +itembase.o: itembase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/mylua/base.h ../include/char_base.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +magicbase.o: magicbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_talk.h ../include/common.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/net.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/mylua/base.h ../include/char_base.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/ablua.h ../include/magic_base.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +offlinebase.o: offlinebase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/enemy.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/battle.h ../include/trade.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/mylua/mylua.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h +netbase.o: netbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../lua/lauxlib.h /usr/include/stdio.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../lua/lua.h ../lua/lualib.h ../include/net.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/log.h +enemytempbase.o: enemytempbase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/readmap.h ../include/map_deal.h ../include/char_base.h \ + ../include/enemy.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +sasqlbase.o: sasqlbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../lua/lauxlib.h /usr/include/stdio.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../lua/lua.h ../lua/lualib.h ../include/net.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/log.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + /usr/include/mysql/mysql.h /usr/include/mysql/mysql_version.h \ + /usr/include/mysql/mysql_com.h /usr/include/mysql/mysql_time.h \ + /usr/include/mysql/typelib.h /usr/include/mysql/my_alloc.h \ + /usr/include/mysql/my_list.h +saacproto.o: saacproto.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h +family.o: family.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/family.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +petskill.o: petskill.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/pet_skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/mylua/base.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +profession_skill.o: profession_skill.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/profession_skill.h \ + ../include/version.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/skill.h ../include/mylua/base.h ../include/char_base.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile.bak new file mode 100755 index 0000000..8ebbc96 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/makefile.bak @@ -0,0 +1,1077 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O3 -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libmylua.a + +SRC=mylua.c ablua.c init.c charbase.c npcbase.c function.c lssprotobase.c battlebase.c objectbase.c mapbase.c otherbase.c configbase.c itembase.c magicbase.c offlinebase.c netbase.c enemytempbase.c sasqlbase.c saacproto.c family.c petskill.c profession_skill.c + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +mylua.o: mylua.c /usr/include/signal.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/bits/sigset.h /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/bits/signum.h \ + /usr/include/time.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h ../include/autil.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/buf.h ../include/util.h /usr/include/sys/time.h ../lua/lua.h \ + ../lua/luaconf.h /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/longzoro/version.h \ + ../include/mylua/mylua.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h +ablua.o: ablua.c /usr/include/pthread.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/endian.h /usr/include/bits/endian.h /usr/include/sched.h \ + /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/time.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/signal.h /usr/include/bits/sigset.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/setjmp.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h \ + /usr/include/linux/limits.h /usr/include/string.h \ + /usr/include/sys/types.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/sys/sysmacros.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h ../include/autil.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/stdlib.h /usr/include/alloca.h ../include/mylua/mylua.h \ + ../lua/lua.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix2_lim.h ../lua/lauxlib.h \ + ../lua/lua.h ../lua/lualib.h ../include/mylua/base.h \ + ../include/char_base.h ../include/skill.h ../include/util.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + ../include/link.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h +init.o: init.c ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h /usr/include/bits/stdio_lim.h \ + /usr/include/bits/sys_errlist.h ../include/mylua/base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h +charbase.o: charbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/battle.h ../include/trade.h ../include/object.h \ + ../include/char_base.h ../include/enemy.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/npcutil.h ../include/readmap.h ../include/log.h \ + ../include/pet.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h ../include/handletime.h \ + ../include/item_event.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/shop.h ../include/mylua/mylua.h +npcbase.o: npcbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/battle.h ../include/net.h ../include/common.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/trade.h \ + ../include/util.h /usr/include/stdlib.h /usr/include/alloca.h \ + ../lua/lua.h ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h \ + ../lua/lualib.h ../include/char_base.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/npccreate.h \ + ../include/object.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/enemy.h ../include/npc_eventaction.h ../lua/lua.h \ + ../include/longzoro/version.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/npcutil.h ../include/log.h +function.o: function.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/item.h ../include/configfile.h ../include/battle.h \ + ../include/trade.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/longzoro/version.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/mylua.h +lssprotobase.o: lssprotobase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/math.h /usr/include/bits/huge_val.h \ + /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +battlebase.o: battlebase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/enemy.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/battle.h ../include/trade.h \ + ../include/battle_command.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/mylua.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/base.h ../include/char_base.h +objectbase.o: objectbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/object.h ../include/longzoro/version.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h +mapbase.o: mapbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/readmap.h ../include/map_deal.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +otherbase.o: otherbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/sys/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h ../include/char.h ../include/common.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/util.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_scheduleman.h \ + ../include/mylua/mylua.h +configbase.o: configbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/configfile.h +itembase.o: itembase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/mylua/base.h ../include/char_base.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +magicbase.o: magicbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_talk.h ../include/common.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../include/net.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/mylua/base.h ../include/char_base.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/mylua/ablua.h ../include/magic_base.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +offlinebase.o: offlinebase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/enemy.h ../include/object.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/battle.h ../include/trade.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/mylua/mylua.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h +netbase.o: netbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../lua/lauxlib.h /usr/include/stdio.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../lua/lua.h ../lua/lualib.h ../include/net.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/log.h +enemytempbase.o: enemytempbase.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../include/char.h ../include/common.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h ../include/char_base.h \ + ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/readmap.h ../include/map_deal.h ../include/char_base.h \ + ../include/enemy.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +sasqlbase.o: sasqlbase.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../lua/lua.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h ../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/longzoro/version.h \ + ../include/longzoro/longzoro.h ../lua/lauxlib.h /usr/include/stdio.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + ../lua/lua.h ../lua/lualib.h ../include/net.h ../include/common.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/autil.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/debug.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../include/log.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + /usr/include/mysql/mysql.h /usr/include/mysql/mysql_version.h \ + /usr/include/mysql/mysql_com.h /usr/include/mysql/mysql_time.h \ + /usr/include/mysql/typelib.h /usr/include/mysql/my_alloc.h \ + /usr/include/mysql/my_list.h +saacproto.o: saacproto.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/mylua/base.h ../include/char_base.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h +family.o: family.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h ../include/char.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/char_base.h ../include/version.h ../include/correct_bug.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/family.h ../include/mylua/base.h \ + ../include/char_base.h ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +petskill.o: petskill.c /usr/include/string.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/pet_skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/mylua/base.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h +profession_skill.o: profession_skill.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + ../include/common.h /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/profession_skill.h \ + ../include/version.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/skill.h ../include/mylua/base.h ../include/char_base.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../lua/lua.h ../lua/lauxlib.h ../lua/lualib.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/item.h ../lua/lua.h ../lua/lauxlib.h \ + ../lua/lualib.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/mylua/mylua.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mapbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mapbase.c new file mode 100644 index 0000000..cd2dc17 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mapbase.c @@ -0,0 +1,303 @@ +#include +#include +#include "char.h" +#include "object.h" +#include "readmap.h" +#include "map_deal.h" +#include "char_base.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" + +#ifdef _ALLBLUES_LUA +#ifdef _ALLBLUES_LUA_1_1 +static int RandMap(lua_State *L) +{ + lua_pushinteger(L, MAP_getfloorId(rand()% MAP_getMapNum())); + return 1; +} + +static int RandXAndY(lua_State *L) +{ + const int ff = luaL_checkint(L, 1); + int fx,fy; + int i; + for(i=0;i<50;i++){ + fx = rand() % MAP_getfloorX(ff); + fy = rand() % MAP_getfloorY(ff); +#ifdef _ITEM_PATH + if(MAP_walkAbleFromPoint( ff,fx,fy,0, -1)==TRUE){ + lua_pushinteger(L, (fx << 16)|fy ); + return 1; + } +#else + if(MAP_walkAbleFromPoint( ff,fx,fy,0)==TRUE){ + lua_pushinteger(L, (fx << 16)|fy ); + return 1; + } +#endif + } + lua_pushinteger(L, -1); + return 1; +} + +static int getX(lua_State *L) +{ + const int XandY = luaL_checkint(L, 1); + lua_pushinteger(L, (XandY >> 16)&0xFFFF ); + return 1; +} + +static int getY(lua_State *L) +{ + const int XandY = luaL_checkint(L, 1); + lua_pushinteger(L, XandY&0xFFFF ); + return 1; +} +static int getfloorX(lua_State *L) +{ + const int floorid = luaL_checkint(L, 1); + lua_pushinteger(L, MAP_getfloorX(floorid) ); + return 1; +} + +static int getfloorY(lua_State *L) +{ + const int floorid = luaL_checkint(L, 1); + lua_pushinteger(L, MAP_getfloorY(floorid) ); + return 1; +} + + +static int getFrontTile(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + int dir, ff, fx, fy; + int tile, obj; + int fixtile, fixobj; + char buf[16]; + + ff = CHAR_getInt( charaindex, CHAR_FLOOR ); + fx = CHAR_getInt( charaindex, CHAR_X ); + fy = CHAR_getInt( charaindex, CHAR_Y ); + dir = CHAR_getInt( charaindex, CHAR_DIR ); + + fx += CHAR_getDX(dir); + fy += CHAR_getDY(dir); + + if( MAP_getTileAndObjData( ff, fx, fy, &tile, &obj) == FALSE ){ + lua_pushstring(L, 0); + return 1; + } + lua_pushinteger(L, tile ); + return 1; +} + +static int getFloorName(lua_State *L) +{ + const int floorid = luaL_checkint(L, 1); + + char escapeshowstring[256]; + char *showstr = MAP_getfloorShowstring(floorid); + + getStringFromIndexWithDelim( showstr, "|", 1, escapeshowstring, sizeof( escapeshowstring)); + + lua_pushstring(L, escapeshowstring); + return 1; +} + +static int getCharaindex(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int distance = luaL_checkint(L, 2); + const int type = luaL_checkint(L, 3); + + int fl ,x,y; + OBJECT object; + fl = CHAR_getInt(charaindex,CHAR_FLOOR); + int i; + for(i=1; i <=distance; i ++) + { + CHAR_getCoordinationDir( CHAR_getInt(charaindex,CHAR_DIR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + i, &x, &y ); + + for( object=MAP_getTopObj(fl,x,y) ; object ; + object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); +// printf("\ntype=%d objindex=%d chartype=%d",OBJECT_getType(objindex),objindex,CHAR_getInt( OBJECT_getIndex(objindex), CHAR_WHICHTYPE)); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + if( CHAR_getInt( OBJECT_getIndex(objindex), CHAR_WHICHTYPE) == type){ + lua_pushinteger(L, OBJECT_getIndex(objindex)); + return 1; + } + } + } + } + lua_pushinteger(L, -1); + return 1; +} + +static int getCharaNearBy(lua_State *L) { + const int charaindex = luaL_checkint(L, 1); + const int area = luaL_checkint(L, 2); + const int type = luaL_checkint(L, 3); + + + lua_newtable(L); //½һѹջ + lua_pushnumber(L,-1); //кһУû㶮ΪʲôҪִУluaлȡݾͻ + lua_rawseti(L,-2,0); + + int o, chara_index; + int getnum = 0; + int fl, x, y; + OBJECT object; + int i,j; + fl = CHAR_getInt(charaindex, CHAR_FLOOR); + x = CHAR_getInt(charaindex, CHAR_X); + y = CHAR_getInt(charaindex, CHAR_Y); + for (i = y - area; i <= y + area; i++) { + for (j = x - area; j <= x + area; j++) { + for (object = MAP_getTopObj(fl, j, i); object; object = + NEXT_OBJECT(object)) { + o = GET_OBJINDEX(object); + if (OBJECT_getType(o) == OBJTYPE_CHARA) { + chara_index = OBJECT_getIndex(o); + if (CHAR_CHECKINDEX(chara_index) == FALSE) + continue; + if ( CHAR_getInt(chara_index, CHAR_WHICHTYPE) + != type) + continue; + if (chara_index == charaindex) + continue; //ҵԼ + + lua_pushinteger(L,chara_index); + getnum++; + lua_rawseti(L,-2,getnum); + } + } + } + } + return 1; +} + +static int getCharaAhead(lua_State *L) { + const int charaindex = luaL_checkint(L, 1); + const int distance = luaL_checkint(L, 2); + const int area = luaL_checkint(L, 3); + const int type = luaL_checkint(L, 4); + + + lua_newtable(L); //½һѹջ + lua_pushnumber(L,-1); //кһУû㶮ΪʲôҪִУluaлȡݾͻ + lua_rawseti(L,-2,0); + + int o, chara_index; + int getnum = 0; + int fl, x, y; + OBJECT object; + int i,j; + fl = CHAR_getInt(charaindex, CHAR_FLOOR); + + CHAR_getCoordinationDir( CHAR_getInt(charaindex,CHAR_DIR), + CHAR_getInt(charaindex,CHAR_X), + CHAR_getInt(charaindex,CHAR_Y), + distance, &x, &y ); + + + for (i = y - area; i <= y + area; i++) { + for (j = x - area; j <= x + area; j++) { + for (object = MAP_getTopObj(fl, j, i); object; object = + NEXT_OBJECT(object)) { + o = GET_OBJINDEX(object); + if (OBJECT_getType(o) == OBJTYPE_CHARA) { + chara_index = OBJECT_getIndex(o); + if (CHAR_CHECKINDEX(chara_index) == FALSE) + continue; + if ( CHAR_getInt(chara_index, CHAR_WHICHTYPE) + != type) + continue; + if (chara_index == charaindex) + continue; //ҵԼ + + lua_pushinteger(L,chara_index); + getnum++; + lua_rawseti(L,-2,getnum); + } + } + } + } + return 1; +} + +static int getCharaByCoord(lua_State *L) { + const int charaindex = luaL_checkint(L, 1); + const int fl = luaL_checkint(L, 2); + const int x = luaL_checkint(L, 3); + const int y = luaL_checkint(L, 4); + const int area = luaL_checkint(L, 5); + const int type = luaL_checkint(L, 6); + + lua_newtable(L); //½һѹջ + lua_pushnumber(L,-1); //кһУû㶮ΪʲôҪִУluaлȡݾͻ + lua_rawseti(L,-2,0); + + int o, chara_index; + int getnum = 0; + OBJECT object; + int i,j; + for (i = y - area; i <= y + area; i++) { + for (j = x - area; j <= x + area; j++) { + for (object = MAP_getTopObj(fl, j, i); object; object = + NEXT_OBJECT(object)) { + o = GET_OBJINDEX(object); + if (OBJECT_getType(o) == OBJTYPE_CHARA) { + chara_index = OBJECT_getIndex(o); + if (CHAR_CHECKINDEX(chara_index) == FALSE) + continue; + if ( CHAR_getInt(chara_index, CHAR_WHICHTYPE) + != type) + continue; + if (chara_index == charaindex) + continue; //ҵԼ + + lua_pushinteger(L,chara_index); + getnum++; + lua_rawseti(L,-2,getnum); + } + } + } + } + return 1; +} + + + +static const luaL_Reg maplib[] = { + {"RandMap", RandMap}, + {"RandXAndY", RandXAndY}, + {"getfloorX", getfloorX}, + {"getfloorY", getfloorY}, + {"getFloorName", getFloorName}, + {"getX", getX}, + {"getY", getY}, + {"getCharaindex", getCharaindex}, + {"getCharaNearBy", getCharaNearBy}, + {"getCharaAhead", getCharaAhead}, + {"getCharaByCoord", getCharaByCoord}, + {"getFrontTile",getFrontTile}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Map (lua_State *L) { + luaL_register(L, "map", maplib); + return 1; +} +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mylua.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mylua.c new file mode 100644 index 0000000..d3fa20a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/mylua.c @@ -0,0 +1,350 @@ +#include +#include +#include +#include +#include +#include "autil.h" +#include "buf.h" +#include "util.h" +#define lua_c +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "longzoro/version.h" +#include "mylua/mylua.h" + + +#ifdef _ALLBLUES_LUA + +MY_Lua MYLua; + +static const char *progname = "lua"; + +int getArrayInt(lua_State *L, int idx) { + int result = 0; + lua_pushnumber(L, idx + 1); + lua_gettable(L, -2); + result = (int)lua_tonumber(L, -1); + lua_pop(L, 1); + return result; +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +int _docall(lua_State *L, int narg, int clear ,char *file) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0){ + printf("=%s ʾ%s\n",file,(char *)lua_tostring(L, -1)); + lua_gc(L, LUA_GCCOLLECT, 0); + } + return status; +} + + +int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + +char crypto[]=DEFAULTTABLE; + +void DecryptLua(char* buff, int len, int id) +{ + + int i; + int cryptolen = strlen(crypto); + for(i=0;id_name[0] == '.')continue; + if (ent->d_type==8){ + + if( (strcmptail( ent->d_name, ".lua" ) == 0 && flg == 1) + || (strcmptail( ent->d_name, ".allblues") == 0 && flg == 0)){ + char filename[256]; + char token[256]; + sprintf(filename, "%s/%s", path, ent->d_name); + + char *luabuff = NULL; + int luamaxlen = 0; + + if ((f=fopen(filename,"r"))!=NULL) { + fseek(f,0,SEEK_END); + luamaxlen = ftell(f); + luabuff = (char*)malloc(luamaxlen + 1); + memset(luabuff, 0, luamaxlen); + fseek(f,0,SEEK_SET); + fread(luabuff, luamaxlen, 1, f); + fclose(f); + } + + if( flg == 1 ){ + CryptoLua(luabuff, luamaxlen, id); + sprintf(token, "%s.allblues", filename); + }else if( flg == 0 ){ + DecryptLua(luabuff, luamaxlen, id); + sprintf(token, "%s", filename); + + token[strlen(token)-9] = '\0'; + } + if ((f=fopen(token,"w+"))!=NULL) { + fwrite(luabuff,1,luamaxlen,f); + fclose(f); + } + free(luabuff); + } + }else{ + sprintf(filename, "%s/%s", path, ent->d_name); + CryptoAllbluesLUA(filename, flg, id); + } + } +} +#endif +void Cryptodofile(lua_State *L, char *filename) +{ + FILE *f; + + char *luabuff; + char *cfbuff = NULL; + char *buff; + int luamaxlen = 0; + int cfmaxlen = 0; + char head[]="\nfunction init()\n"; + char end[]="\nend\n"; + char filenamecf[256]; + char loadfilename[256]; + strcpy(loadfilename, filename); + + if ((f=fopen(loadfilename,"r"))!=NULL) { + fseek(f,0,SEEK_END); + luamaxlen = ftell(f); + luabuff = (char*)malloc(luamaxlen + 1); + memset(luabuff, 0, luamaxlen + 1); + fseek(f,0,SEEK_SET); + fread(luabuff, luamaxlen, 1, f); + fclose(f); + }else{ + return; + } +/* + CryptoLua(buff, maxlen, _ATTESTAION_ID); + char token[256]; + sprintf(token, "%s.allblues", filename); + if ((f=fopen(token,"w+"))!=NULL) { + fwrite(buff,1,maxlen,f); + fclose(f); + } +*/ + + + DecryptLua(luabuff, luamaxlen, _ATTESTAION_ID); + loadfilename[strlen(loadfilename)-9] = '\0'; + + sprintf(filenamecf, "%s.cf", filename); + if ((f=fopen(filenamecf,"r"))!=NULL) { + fseek(f,0,SEEK_END); + cfmaxlen = ftell(f); + cfbuff = (char*)malloc(cfmaxlen + 1); + memset(cfbuff, 0, cfmaxlen + 1); + fseek(f,0,SEEK_SET); + fread(cfbuff, cfmaxlen, 1, f); + + fclose(f); + } + + int len = luamaxlen + cfmaxlen + strlen(head) + strlen(end) + 1; + buff = (char*)malloc(len); + memset(buff, 0, len); + len = 0; + memcpy( buff + len, head, strlen(head)); + len += strlen(head); + if(cfmaxlen > 0){ + memcpy( buff + len, cfbuff, cfmaxlen); + free(cfbuff); + } + len += cfmaxlen; + memcpy( buff + len, end, strlen(end)); + len += strlen(end); + memcpy( buff + len, luabuff, luamaxlen); + + luaL_dostring(L, buff); + + free(buff); + free(luabuff); +} + +int myluaload (char *filename) +{ + MY_Lua *mylua = &MYLua; + while(mylua->next!=NULL){ + if(strcmp(mylua->luapath, filename) == 0){ + return FALSE; + } + mylua = mylua->next; + } + mylua->luapath = allocateMemory( strlen(filename) ); + memset( mylua->luapath, 0 , strlen(filename) ); + strcpy(mylua->luapath, filename); + mylua->next = allocateMemory( sizeof(MY_Lua) ); + memset( mylua->next, 0 , sizeof(MY_Lua) ); + if(mylua->next == NULL)return EXIT_FAILURE; + + mylua->lua = lua_open(); /* create state */ + + if (mylua->lua == NULL) { + return FALSE; + } + + lua_gc(mylua->lua, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(mylua->lua); /* open libraries */ + luaAB_openlibs(mylua->lua); + lua_gc(mylua->lua, LUA_GCRESTART, 0); + + if(strcmptail( filename, ".allblues" ) == 0){ + Cryptodofile(mylua->lua, filename); + }else{ + dofile(mylua->lua, filename); + } + + lua_getglobal(mylua->lua, "init"); + if (lua_isfunction(mylua->lua, -1)) { + docall(mylua->lua, 0, 1); + } + + lua_getglobal(mylua->lua, "main"); + + if (lua_isfunction(mylua->lua, -1)) { + docall(mylua->lua, 0, 1); + } + + return TRUE; +} + +int remyluaload (char *filename) +{ + MY_Lua *mylua = &MYLua; + + while(mylua->next!=NULL){ + if(strlen(mylua->luapath) > 0){ + if(strlen(filename)>0){ + //printf("luapath=%s filename=%s\n",mylua->luapath,filename); + if(strstr(mylua->luapath, filename) == 0){ + mylua = mylua->next; + continue; + } + } + + lua_gc(mylua->lua, LUA_GCSTOP, 0); + luaL_openlibs(mylua->lua); + luaAB_openlibs(mylua->lua); + lua_gc(mylua->lua, LUA_GCRESTART, 0); + if(strcmptail( mylua->luapath, ".allblues" ) == 0){ + if ((fopen(mylua->luapath,"r"))==NULL) { + mylua = mylua->next; + continue; + } + Cryptodofile(mylua->lua, mylua->luapath); + }else{ + dofile(mylua->lua, mylua->luapath); + } + + lua_getglobal(mylua->lua, "data"); + + if (lua_isfunction(mylua->lua, -1)) { + docall(mylua->lua, 0, 1); + } + + } + mylua = mylua->next; + } + + return EXIT_SUCCESS; +} + + +int closemyluaload() +{ + MY_Lua *mylua = &MYLua; + while(mylua->next!=NULL){ + lua_pop(mylua->lua, 1); + lua_close(mylua->lua); + mylua = mylua->next; + } + + return EXIT_SUCCESS; +} + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/netbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/netbase.c new file mode 100644 index 0000000..a45acdb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/netbase.c @@ -0,0 +1,126 @@ +#include +#include "lua.h" +#include "longzoro/version.h" +#include "lauxlib.h" +#include "lualib.h" +#include "net.h" +#include "log.h" + +#ifdef _ALLBLUES_LUA + +static int endOne(lua_State *L) +{ + const int sockfd = luaL_checkint(L, 1); +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(sockfd,charname,32); + CONNECT_getCdkey(sockfd,cdkey,16); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,"ABLUA"); +#endif + CONNECT_endOne_debug(sockfd); + + return 1; +} + +static int userip(lua_State *L) +{ + int charaindex = luaL_checkint(L, 1); + + int sockfd = getfdFromCharaIndex(charaindex); + + unsigned long ip; + int a,b,c,d; + char strIP[32]; + ip = CONNECT_get_userip(sockfd); + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + + sprintf(strIP, "%d.%d.%d.%d", a, b, c, d); + + lua_pushstring(L, strIP); + return 1; +} +#ifdef _NEWCLISETSERVID +static int getServid(lua_State *L) +{ + int charaindex = luaL_checkint(L, 1); + + int sockfd = getfdFromCharaIndex(charaindex); + + lua_pushinteger(L, CONNECT_getServid(sockfd)); + return 1; +} +#endif +#ifdef _NEWCLISETMAC +static int getMac(lua_State *L) +{ + int sockfd = luaL_checkint(L, 1); + + char mac[128]; + CONNECT_getMAC( sockfd, mac, sizeof( mac )); + + lua_pushstring(L, mac); + return 1; +} +#endif + +static int getIP(lua_State *L) +{ + int sockfd = luaL_checkint(L, 1); + unsigned long ip; + int a,b,c,d; + char strIP[32]; + + ip = CONNECT_get_userip(sockfd); + + a=(ip % 0x100); ip=ip / 0x100; + b=(ip % 0x100); ip=ip / 0x100; + c=(ip % 0x100); ip=ip / 0x100; + d=(ip % 0x100); + + sprintf(strIP, "%d.%d.%d.%d", a, b, c, d); + + lua_pushstring(L, strIP); + return 1; +} + +static int getUse(lua_State *L) +{ + int fd = luaL_checkint(L, 1); + + lua_pushinteger(L, CONNECT_getUse(fd)); + return 1; +} +static int getCharaindex(lua_State *L) +{ + int fd = luaL_checkint(L, 1); + + lua_pushinteger(L, CONNECT_getCharaindex(fd)); + return 1; +} +static const luaL_Reg netlib[] = { + {"endOne", endOne}, + {"userip", userip}, +#ifdef _NEWCLISETSERVID + {"getServid", getServid}, +#endif +#ifdef _NEWCLISETMAC + {"getMac", getMac}, +#endif + {"getIP", getIP}, + {"getUse", getUse}, + {"getCharaindex", getCharaindex}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_Net (lua_State *L) { + luaL_register(L, "net", netlib); + return 1; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/npcbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/npcbase.c new file mode 100644 index 0000000..32ae38e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/npcbase.c @@ -0,0 +1,689 @@ +#include +#include "battle.h" +#include "char_base.h" +#include "npccreate.h" +#include "object.h" +#include "char.h" +#include "enemy.h" +#include "char_base.h" +#include "npc_eventaction.h" +#include "lua.h" +#include "longzoro/version.h" +#include "lauxlib.h" +#include "lualib.h" +#include "npcutil.h" +#include "log.h" +#ifdef _ALLBLUES_LUA +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static int CreateNpc (lua_State *L) { + Char one; + size_t l; + CHAR_getDefaultChar( &one, 0); + one.data[CHAR_WHICHTYPE] = CHAR_TYPELUANPC; + char *Name = luaL_checklstring(L, 1, &l); + const int Image = luaL_checkinteger(L, 2); + const int Floor = luaL_checkinteger(L, 3); + const int x = luaL_checkinteger(L, 4); + const int y = luaL_checkinteger(L, 5); + const int dir = luaL_checkinteger(L, 6); + + strcpysafe( one.string[CHAR_NAME].string , + sizeof(one.string[CHAR_NAME].string), + Name); + one.data[CHAR_BASEBASEIMAGENUMBER] = Image; + one.data[CHAR_BASEIMAGENUMBER] = Image; + one.data[CHAR_FLOOR]=Floor; + one.data[CHAR_X]=x; + one.data[CHAR_Y]=y; + one.data[CHAR_DIR] = dir; + + int npcindex = CHAR_initCharOneArray(&one); + + if( npcindex < 0 ) { + print( "NPCʧܡ\n"); + } + + Object object; + int objindex; + + + object.type = OBJTYPE_CHARA; + object.index = npcindex; + object.x =CHAR_getInt(npcindex, CHAR_X); + object.y = CHAR_getInt(npcindex, CHAR_Y); + object.floor = CHAR_getInt(npcindex, CHAR_FLOOR); + + objindex = initObjectOne( &object ); + + if( objindex == -1 ) { + CHAR_endCharOneArray( npcindex ); + }else { + CHAR_setWorkInt( npcindex,CHAR_WORKOBJINDEX, objindex ); + CHAR_LoginBesideSetWorkInt( npcindex, -1 ); + } + + lua_pushinteger(L, npcindex); + return 1; +} + +#ifdef _DEL_FAME +static int DelFame (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionDelFame(index, data); + return 1; +} +#endif +static int AddGold (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionAddGold2(index, data); + return 1; +} + + +static int DelGold (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionDelGold(index, data); + return 1; +} +#ifdef _MOMENTUM_NPC +static int DelMom (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionMomentum(index, data); + return 1; +} +#endif +#ifdef _DP_NPC +static int DelDP (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionDP(index, data); + return 1; +} +#endif +static int DelItem (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionDelItem(index, data); + return 1; +} + + +static int AddItem (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionAddItem(index, data); + return 1; +} +static int AddRandItem (lua_State *L) +{ + size_t l; + const int TM_Index = luaL_checkint(L, 1); + char *TM_ItemIdData = luaL_checklstring(L, 2, &l); + int TM_Num = 1; + int TM_ItemIndex = -1; + int TM_Int = -1; + int TM_ItemId = -1; + int TM_ItemIdStart = -1; + int TM_ItemIdEnd = -1; + char ItemIdBuf[32]; + if(getStringFromIndexWithDelim(TM_ItemIdData,",", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE){ + int TM_ItemNum = 0; + while(1){ + if(getStringFromIndexWithDelim(TM_ItemIdData,",", TM_ItemNum+1, ItemIdBuf, sizeof(ItemIdBuf)) == FALSE) + break; + TM_ItemNum++; + } + TM_ItemNum = RAND(1,TM_ItemNum); + getStringFromIndexWithDelim(TM_ItemIdData,",", TM_ItemNum, ItemIdBuf, sizeof(ItemIdBuf)); + char ItemIdBuf2[16]; + if( getStringFromIndexWithDelim(ItemIdBuf,"-", 2, ItemIdBuf2, sizeof(ItemIdBuf2)) != FALSE){ + int TM_ItemIdStart,TM_ItemIdEnd; + getStringFromIndexWithDelim(ItemIdBuf,"-", 1, ItemIdBuf2, sizeof(ItemIdBuf2)); + TM_ItemIdStart = atoi(ItemIdBuf2); + getStringFromIndexWithDelim(ItemIdBuf,"-", 2, ItemIdBuf2, sizeof(ItemIdBuf2)); + TM_ItemIdEnd = atoi(ItemIdBuf2); + TM_ItemId = RAND(TM_ItemIdStart,TM_ItemIdEnd); + }else{ + TM_ItemId = atoi(ItemIdBuf); + } + }else if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE){ + if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 1, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE) + TM_ItemIdStart = atoi(ItemIdBuf); + if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE) + TM_ItemIdEnd = atoi(ItemIdBuf); + if(TM_ItemIdStart<=TM_ItemIdEnd){ + TM_ItemId = RAND(TM_ItemIdStart,TM_ItemIdEnd); + } + }else{ + TM_ItemId = atoi(TM_ItemIdData); + } + if(TM_ItemId > -1){ + TM_ItemIndex = NPC_GiveItem(TM_Index, TM_ItemId); + } + lua_pushinteger(L, TM_ItemIndex); + return 1; +} + + +static int AddPet (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionAddPet(index, data); + return 1; +} + +static int EvEnd (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionSetEend(index, data); + return 1; +} + +static int EvNow (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionSetNow(index, data); + return 1; +} + +static int Event_End (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionSetEend(index, data); + return 1; +} + +static int Event_Now (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionSetNow(index, data); + return 1; +} + +static int EvClr (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionClearEvent(index, data); + return 1; +} + +#ifdef _VIP_SHOP +static int VipItem (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionVipItem(index, data); + return 1; +} + +static int VipPet (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionVipPet(index, data); + return 1; +} +#endif + +#ifdef _NEW_VIP_SHOP +static int Vip_Item (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionVipItem(index, data); + return 1; +} + +static int Vip_Pet (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionVipPet(index, data); + return 1; +} +#endif + +#ifdef _NPC_ADDLEVELUP +static int SetLevel (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionLevelAndTransUp( 0, index, atoi(data), 0, 0, -1); + return 1; +} + +static int AddExps (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionLevelAndTransUp( 0, index, 0, 0, atoi(data), -1); + return 1; +} + +static int AddSkillPoint (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionLevelAndTransUp( 0, index, 0, atoi(data), 0, -1); + return 1; +} + +static int SetRideType (lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + + NPC_ActionLevelAndTransUp( 0, index, 0, 0, 0, atoi(data)); + return 1; +} +#endif + +static int isFaceToFace (lua_State *L) +{ + const int meindex = luaL_checkint(L, 1); + const int talkerindex = luaL_checkint(L, 2); + + + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2)==FALSE){ + if( NPC_Util_CharDistance( talkerindex ,meindex ) > 1) { + lua_pushinteger(L, 0); + return 1; + } + } + + lua_pushinteger(L, 1); + return 1; +} + +static int ActionPassCheck (lua_State *L) +{ + size_t l; + const int meindex = luaL_checkint(L, 1); + const int toindex = luaL_checkint(L, 2); + char *data = luaL_checklstring(L, 3, &l); + + if( NPC_ActionPassCheck( meindex, toindex, data) == FALSE ) { + lua_pushinteger(L, 0); + return 1; + } + + lua_pushinteger(L, 1); + return 1; +} + + +#ifdef _ALLBLUES_LUA_1_1 +static int SetPoint (lua_State *L) +{ + const int meindex = luaL_checkint(L, 1); + const int ff = luaL_checkint(L, 2); + const int fx = luaL_checkint(L, 3); + const int fy = luaL_checkint(L, 4); + + OBJECT_setFloor(CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), ff); + OBJECT_setX(CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), fx); + OBJECT_setY(CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), fy); + CHAR_setInt(meindex, CHAR_FLOOR, ff); + CHAR_setInt(meindex, CHAR_X, fx); + CHAR_setInt(meindex, CHAR_Y, fy); + CHAR_sendCDArroundChar( ff, fx, fy, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + return 1; +} + + +static int DelItemNum (lua_State *L) +{ + size_t l; + int index = luaL_checkint(L, 1); + char *data = luaL_checklstring(L, 2, &l); + char tmp[16]; + int itemID = 0; + int itemNUM = 0; + + if( getStringFromIndexWithDelim( data, ",", 1, tmp, sizeof( tmp)) != FALSE ){ + itemID = atoi(tmp); + } + + if( getStringFromIndexWithDelim( data, ",", 2, tmp, sizeof( tmp)) != FALSE ){ + itemNUM = atoi(tmp); + } + + int i, itemindex; + char token[256]; + int num=0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(index); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i++ ){ +#else + for( i = CHAR_STARTITEMARRAY ; i < CHAR_MAXITEMHAVE ; i++ ){ +#endif + if(num >= itemNUM)break; + itemindex = CHAR_getItemIndex( index , i ); + if( !ITEM_CHECKINDEX(itemindex) ) continue; + if( ITEM_getInt(itemindex, ITEM_ID) != itemID ) continue; + sprintf( token, "%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( index, -1, token, CHAR_COLORYELLOW); + + LogItem( + CHAR_getChar( index, CHAR_NAME ), + CHAR_getChar( index, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "ȡ", + CHAR_getInt( index,CHAR_FLOOR), + CHAR_getInt( index,CHAR_X ), + CHAR_getInt( index,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_setItemIndex( index, i, -1); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( index, i); + num++; + } + + lua_pushinteger(L, num); + return 1; +} + +static int DelNpc (lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + if( !CHAR_CHECKINDEX( index ) ){ + print( "ANDY index=%d err\n", index); + return 1; + } + + CHAR_CharaDeleteHavePet( index); + CHAR_CharaDelete( index ); + + return 1; +} + +#endif + + + +#ifdef _PLAYER_NPC +static int CreateSpecialNpc (lua_State *L) +{ + Char one; + size_t l; + CHAR_getDefaultChar( &one, 0); + one.data[CHAR_WHICHTYPE] = CHAR_TYPELUANPC; + char *Name = luaL_checklstring(L, 1, &l); + const int Image = luaL_checkinteger(L, 2); + const int Floor = luaL_checkinteger(L, 3); + const int x = luaL_checkinteger(L, 4); + const int y = luaL_checkinteger(L, 5); + const int dir = luaL_checkinteger(L, 6); + const int enemyid = luaL_checkint(L, 7); + const int UpLevel = luaL_checkinteger(L, 8); + int i; + for( i = 0; i < ENEMY_getEnemyNum(); i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == ENEMY_getEnemyNum() ){ + lua_pushinteger(L, -1); + return 1; + } + + int npcindex = ENEMY_createEnemy( i, 0); + if( npcindex < 0 ) { + print( "NPCʧܡ\n"); + } + + + CHAR_setInt(npcindex, CHAR_WHICHTYPE, CHAR_TYPEPLAYERNPC); + CHAR_setChar(npcindex, CHAR_NAME, Name); + CHAR_setInt(npcindex, CHAR_BASEBASEIMAGENUMBER, Image); + CHAR_setInt(npcindex, CHAR_BASEIMAGENUMBER, Image); + CHAR_setInt(npcindex, CHAR_FLOOR, Floor); + CHAR_setInt(npcindex, CHAR_X, x); + CHAR_setInt(npcindex, CHAR_Y, y); + CHAR_setInt(npcindex, CHAR_DIR, dir); + + CHAR_setInt(npcindex, CHAR_MODAI, 10000); + CHAR_setInt(npcindex, CHAR_VARIABLEAI,10000); + + for( i = 0; i < UpLevel; i ++ ){ + CHAR_PetLevelUp( npcindex ); + CHAR_PetAddVariableAi( npcindex, AI_FIX_PETLEVELUP ); + } + CHAR_complianceParameter( npcindex ); + CHAR_setInt( npcindex, CHAR_HP, CHAR_getWorkInt( npcindex, CHAR_WORKMAXHP )); + Object object; + int objindex; + + object.type = OBJTYPE_CHARA; + object.index = npcindex; + object.x =CHAR_getInt(npcindex, CHAR_X); + object.y = CHAR_getInt(npcindex, CHAR_Y); + object.floor = CHAR_getInt(npcindex, CHAR_FLOOR); + + objindex = initObjectOne( &object ); + + if( objindex == -1 ) { + CHAR_endCharOneArray( npcindex ); + }else { + CHAR_setWorkInt( npcindex,CHAR_WORKOBJINDEX, objindex ); + CHAR_LoginBesideSetWorkInt( npcindex, -1 ); + } + + lua_pushinteger(L, npcindex); + return 1; +} +#endif + +#ifdef _ALLBLUES_LUA_1_4 +#ifdef _PLAYER_NPC +static int CreatePlayer (lua_State *L) { + Char one; + size_t l; + CHAR_getDefaultChar( &one, 0); + one.data[CHAR_WHICHTYPE] = CHAR_TYPEPLAYERNPC; + char *Name = luaL_checklstring(L, 1, &l); + const int Image = luaL_checkinteger(L, 2); + const int Floor = luaL_checkinteger(L, 3); + const int x = luaL_checkinteger(L, 4); + const int y = luaL_checkinteger(L, 5); + const int dir = luaL_checkinteger(L, 6); + + strcpysafe( one.string[CHAR_NAME].string , + sizeof(one.string[CHAR_NAME].string), + Name); + one.data[CHAR_BASEBASEIMAGENUMBER] = Image; + one.data[CHAR_BASEIMAGENUMBER] = Image; + one.data[CHAR_FLOOR]=Floor; + one.data[CHAR_X]=x; + one.data[CHAR_Y]=y; + one.data[CHAR_DIR] = dir; + + int npcindex = CHAR_initCharOneArray(&one); + + if( npcindex < 0 ) { + print( "NPCʧܡ\n"); + } + + Object object; + int objindex; + + + object.type = OBJTYPE_CHARA; + object.index = npcindex; + object.x =CHAR_getInt(npcindex, CHAR_X); + object.y = CHAR_getInt(npcindex, CHAR_Y); + object.floor = CHAR_getInt(npcindex, CHAR_FLOOR); + + objindex = initObjectOne( &object ); + + if( objindex == -1 ) { + CHAR_endCharOneArray( npcindex ); + lua_pushinteger(L, -1); + return 1; + } + + CHAR_setWorkInt( npcindex,CHAR_WORKOBJINDEX, objindex ); + CHAR_LoginBesideSetWorkInt( npcindex, -1 ); + + CHAR_setFlg( npcindex, CHAR_ISDUEL, 0); + CHAR_setFlg( npcindex, CHAR_ISTRADECARD, 0); + CHAR_setFlg( npcindex, CHAR_ISTRADE, 0); + CHAR_setFlg( npcindex, CHAR_ISPARTY, 0); + + lua_pushinteger(L, npcindex); + return 1; +} +#endif +#endif + + +#ifdef _ONLINE_COST +static int OnlineCost (lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + NPC_ActionOnlineCost(charaindex); + lua_pushinteger(L, 1); + return 1; +} + +static int OnlineBuy (lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + NPC_ActionOnlineBuy(charaindex); + lua_pushinteger(L, 1); + return 1; +} +#endif +static const luaL_Reg npclib[] = { + {"CreateNpc", CreateNpc}, +#ifdef _DEL_FAME + {"DelFame", DelFame}, +#endif + {"AddGold", AddGold}, + {"DelGold", DelGold}, +#ifdef _MOMENTUM_NPC + {"DelMom", DelMom}, +#endif +#ifdef _DP_NPC + {"DelDP", DelDP}, +#endif + {"DelItem", DelItem}, + {"AddItem", AddItem}, + {"AddRandItem", AddRandItem}, + {"AddPet", AddPet}, + {"EvEnd", EvEnd}, + {"EvNow", EvNow}, + {"Event_End", Event_End}, + {"Event_Now", Event_Now}, + {"EvClr", EvClr}, +#ifdef _VIP_SHOP + {"VipItem", VipItem}, + {"VipPet", VipPet}, +#endif +#ifdef _NEW_VIP_SHOP + {"Vip_Item", Vip_Item}, + {"Vip_Pet", Vip_Pet}, +#endif +#ifdef _NPC_ADDLEVELUP + {"SetLevel", SetLevel}, + {"AddExps", AddExps}, + {"AddSkillPoint", AddSkillPoint}, + {"SetRideType", SetRideType}, +#endif + {"isFaceToFace", isFaceToFace}, + {"Free", ActionPassCheck}, +#ifdef _ALLBLUES_LUA_1_1 + {"SetPoint", SetPoint}, + {"DelItemNum", DelItemNum}, + {"DelNpc", DelNpc}, +#endif +#ifdef _PLAYER_NPC + {"CreateSpecialNpc", CreateSpecialNpc}, +#ifdef _ALLBLUES_LUA_1_4 + {"CreatePlayer", CreatePlayer}, +#endif +#endif +#ifdef _ONLINE_COST + {"OnlineCost", OnlineCost}, + {"OnlineBuy", OnlineBuy}, +#endif + {NULL, NULL} +}; + + +LUALIB_API int luaopen_NPC (lua_State *L) { + luaL_register(L, "npc", npclib); + return 1; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/objectbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/objectbase.c new file mode 100644 index 0000000..691828a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/objectbase.c @@ -0,0 +1,140 @@ +#include +#include "char_base.h" +#include "object.h" +#include "longzoro/version.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "mylua/base.h" + +#ifdef _ALLBLUES_LUA + +static CharBase CharBaseObj[] = { + {{"ɫ"}, OBJTYPE_CHARA} + ,{{""}, OBJTYPE_ITEM} + ,{{""}, OBJTYPE_GOLD} + ,{{""}, OBJTYPE_WARPPOINT} +}; + +static int check (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, CHECKOBJECT(index)); + return 1; +} + +static int getType (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getType(index)); + return 1; +} + +static int setType (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, CharBaseObj, arraysizeof(CharBaseObj)); + OBJECT_setType(index, element); + return 1; +} + +static int getFloor (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getFloor(index)); + return 1; +} + +static int setFloor (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int floor = luaL_checkint(L, 2); + OBJECT_setFloor(index, floor); + return 1; +} + +static int getX (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getX(index)); + return 1; +} + +static int setX (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int x = luaL_checkint(L, 2); + OBJECT_setX(index, x); + return 1; +} + +static int getY (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getY(index)); + return 1; +} + +static int setY (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int y = luaL_checkint(L, 2); + OBJECT_setY(index, y); + return 1; +} + +static int getIndex (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getIndex(index)); + return 1; +} + +static int getNum (lua_State *L) { + lua_pushinteger(L, OBJECT_getNum()); + return 1; +} +static int setIndex (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int charaindex = luaL_checkint(L, 2); + OBJECT_setIndex(index, charaindex); + return 1; +} + +static int getchartype (lua_State *L) { + const int index = luaL_checkint(L, 1); + lua_pushinteger(L, OBJECT_getchartype(index)); + return 1; +} + +static int setchartype (lua_State *L) { + const int index = luaL_checkint(L, 1); + const int flg = luaL_checkint(L, 2); + OBJECT_setchartype(index, flg); + return 1; +} + +static int DelObjectOne (lua_State *L) { + const int index = luaL_checkint(L, 1); + endObjectOne(index); + return 1; +} + + +static const luaL_Reg objectlib[] = { + {"check", check}, + {"getType", getType}, + {"setType", setType}, + {"getFloor", getFloor}, + {"setFloor", setFloor}, + {"getX", getX}, + {"setX", setX}, + {"getY", getY}, + {"setY", setY}, + {"getIndex", getIndex}, + {"setIndex", setIndex}, + {"getNum", getNum}, + {"getchartype", getchartype}, + {"setchartype", setchartype}, + {"DelObjectOne", DelObjectOne}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_Object (lua_State *L) { + luaL_register(L, "obj", objectlib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/offlinebase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/offlinebase.c new file mode 100644 index 0000000..6bbdf3a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/offlinebase.c @@ -0,0 +1,89 @@ +#include +#include "longzoro/version.h" +#include "char_base.h" +#include "enemy.h" +#include "object.h" +#include "char.h" +#include "battle.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "mylua/mylua.h" + +#ifdef _OFFLINE_SYSTEM + int Attack(lua_State *L) +{ + const int battleindex = luaL_checkint(L, 1); + const int charaindex = luaL_checkint(L, 2); + const int side = 1 - luaL_checkint(L, 3); + + + + BATTLE_ENTRY *pEntry = BattleArray[battleindex].Side[side].Entry; + int iNum[10] = {9,7,5,6,8,4,2,0,1,3}; + int i; + for( i = 0; i < 10; i ++ ){ + if( pEntry[iNum[i]].charaindex != -1 ){ + break; + } + } + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, iNum[i] + side * BATTLE_ENTRY_MAX); + int At_SoubiIndex = CHAR_getItemIndex( charaindex, CHAR_ARM ); + if( ITEM_CHECKINDEX( At_SoubiIndex ) == TRUE ) + { + if( ITEM_getInt( At_SoubiIndex, ITEM_TYPE ) == ITEM_BOOMERANG ){ + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_BOOMERANG ); +#ifdef _PETSKILL_BECOMEFOX + if( CHAR_getInt( charaindex, CHAR_BASEIMAGENUMBER)==101749 + || CHAR_getWorkInt( charaindex, CHAR_WORKFOXROUND ) != -1 ){ //DZС겻ʹû + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_NONE ); + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charaindex, CHAR_BECOMEPIG) > -1 ){// + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_ATTACK ); + } +#endif + } + } + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, 1 ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return 1; +} + + int Recovery(lua_State *L) +{ + const int battleindex = luaL_checkint(L, 1); + const int charaindex = luaL_checkint(L, 2); + const int HP = luaL_checkint(L, 3); + + + int toNO = BATTLE_Index2No(battleindex, charaindex); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM1, BATTLE_COM_S_OFFLINE_RECOVERY ); + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLECOM2, toNO); + CHAR_SETWORKINT_LOW( charaindex, CHAR_WORKBATTLECOM3, HP ); + + CHAR_setWorkInt( charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_C_OK ); + + return 1; +} + + + +static const luaL_Reg offlinelib[] = { + {"Attack", Attack}, + {"Recovery", Recovery}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_Offline (lua_State *L) { + luaL_register(L, "offline", offlinelib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/otherbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/otherbase.c new file mode 100644 index 0000000..a1ca2ea --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/otherbase.c @@ -0,0 +1,307 @@ +#include +#include +#include +#include "char.h" +#include "char_base.h" +#include "mylua/base.h" +#include "util.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" +#include "npc_scheduleman.h" +#include "mylua/mylua.h" + +#ifdef _ALLBLUES_LUA +extern MY_Lua MYLua; + +static int nowtime(lua_State *L) +{ + lua_pushinteger(L, (int) time( NULL )); + return 1; +} + +static int strtoi(lua_State *L) +{ + size_t l; + char *data=luaL_checklstring(L, 1, &l); + lua_pushinteger(L, atoi(data)); + return 1; +} + +static int getString(lua_State *L) +{ + size_t l; + char *data = luaL_checklstring(L, 1, &l); + char *delim = luaL_checklstring(L, 2, &l); + const int index = luaL_checkint(L, 3); + + char token[256]; + if(getStringFromIndexWithDelim( data, delim, index, token, sizeof( token))){ + lua_pushstring(L, token); + }else{ + lua_pushstring(L, ""); + } + return 1; +} + +static int CallFunction(lua_State *L) +{ + size_t l; + char *funcname = luaL_checklstring(L, 1, &l); + char *filename = luaL_checklstring(L, 2, &l); + char newfilename[256]; + luaL_checktype(L, 3, LUA_TTABLE); + int n = luaL_getn(L, 3); + + lua_State *lua = NULL; + + MY_Lua *mylua = &MYLua; + while(mylua->next != NULL){ + if(strcmptail( mylua->luapath, ".allblues" ) == 0 + && strcmptail( filename, ".lua" ) == 0 ){ + sprintf(newfilename, "%s.allblues", filename); + }else{ + sprintf(newfilename, "%s", filename); + } + + if(strcmp(newfilename, mylua->luapath) == 0){ + lua = mylua->lua; + break; + } + mylua = mylua->next; + } + if (lua == NULL) { + return FALSE; + } + + lua_getglobal(lua, funcname); + + if (!lua_isfunction(lua, -1)) { + return FALSE; + } + + int i; + + for(i = 0; i < n; i++){ + lua_pushnumber(lua, getArrayInt(L, i)); + } + int TM_Ret = lua_pcall(lua, n, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("CallFunction Lua Err :%d(%s)\n", TM_Ret, lua_tostring(lua, -1)); + //ջ + lua_pop(lua, 1); + return FALSE; + } + lua_isnumber(lua, -1); + + int ret = lua_tonumber(lua, -1); + lua_pushinteger(L, ret); + return TRUE; +} + + +static int c10to62(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + char token[256]; + cnv10to62( index, token, sizeof(token)); + + lua_pushstring(L, token); + return 1; +} +#ifdef _OFFLINE_SYSTEM +int luaplayernum=0; +static int setLuaPLayerNum(lua_State *L) +{ + const int num = luaL_checkint(L, 1); + + luaplayernum = num; + return 1; +} + +static int getLuaPLayerNum(lua_State *L) +{ + lua_pushinteger(L, luaplayernum); + return 1; +} +extern playeronlinenum; + +static int getOnlinePlayer(lua_State *L) +{ + lua_pushinteger(L, playeronlinenum + luaplayernum + getPlayerNum()); + return 1; +} +#endif + +static int NumToAlpha(lua_State *L) +{ + const int Num = luaL_checkint(L, 1); + + char Alpha[10]; + int i; + for(i = 0; i < 9; i ++){ + int validation = Num; + validation /= pow((double)26, i); + if(validation == 0)break; + Alpha[i] = 'A' + (validation- 1) % 26; + } + Alpha[i] = '\0'; + lua_pushstring(L, Alpha); + return 1; +} + +static int AlphaToNum(lua_State *L) +{ + size_t l; + char *Alpha = luaL_checklstring(L, 1, &l); + + int Num = 0; + int i; + + for(i=0; i < strlen(Alpha); i ++){ + if(Alpha[i] >= 'A' && Alpha[i] <= 'Z'){ + Num += (((Alpha[i] - 'A') + 1) * pow(26, i)); + }else if(Alpha[i] >= 'a' && Alpha[i] <= 'z'){ + Num += (((Alpha[i] - 'a') + 1) * pow(26, i)); + } + } + + lua_pushinteger(L, Num); + return 1; +} + +static int DataAndData(lua_State *L) +{ + const int data1 = luaL_checkint(L, 1); + const int data2 = luaL_checkint(L, 2); + + lua_pushinteger(L, (data1 & 1 << data2)); + return 1; +} + +static int DataOrData(lua_State *L) +{ + const int data1 = luaL_checkint(L, 1); + const int data2 = luaL_checkint(L, 2); + + lua_pushinteger(L, (data1 | 1 << data2)); + return 1; +} + +static int getFmPKsGindex(lua_State *L) +{ + const int fmpks_pos = luaL_checkint(L, 1) * MAX_SCHEDULE; + + lua_pushinteger(L, ( fmpks[fmpks_pos+1].guest_index)); + return 1; +} + +static int getFmPKsHindex(lua_State *L) +{ + const int fmpks_pos = luaL_checkint(L, 1) * MAX_SCHEDULE; + + lua_pushinteger(L, ( fmpks[fmpks_pos+1].host_index)); + return 1; +} + +static int getFmPKsDueltime(lua_State *L) +{ + const int fmpks_pos = luaL_checkint(L, 1) * MAX_SCHEDULE; + + lua_pushinteger(L, ( fmpks[fmpks_pos+1].dueltime)); + return 1; +} + +static int getFmPKsPreparetime(lua_State *L) +{ + const int fmpks_pos = luaL_checkint(L, 1) * MAX_SCHEDULE; + + lua_pushinteger(L, ( fmpks[fmpks_pos+1].prepare_time)); + return 1; +} + + +static int Hash(lua_State *L) +{ + size_t l; + char *charId = luaL_checklstring(L, 1, &l); + + int hash = 0; + int j; + for( j=0; j> flg) & 0xFF)); + + return 1; +} + +static int Random(lua_State *L) +{ + const int rand1 = luaL_checkint(L, 1); + const int rand2 = luaL_checkint(L, 2); + + lua_pushinteger(L, RAND(rand1,rand2)); + return 1; + +} + +static const luaL_Reg otherlib[] = { + {"time", nowtime}, + {"atoi", strtoi}, + {"getString", getString}, + {"CallFunction", CallFunction}, + {"c10to62", c10to62}, + {"NumToAlpha", NumToAlpha}, + {"AlphaToNum", AlphaToNum}, +#ifdef _OFFLINE_SYSTEM + {"setLuaPLayerNum", setLuaPLayerNum}, + {"getLuaPLayerNum", getLuaPLayerNum}, + {"getOnlinePlayer", getOnlinePlayer}, +#endif + {"DataAndData", DataAndData}, + {"DataOrData", DataOrData}, + {"getFmPKsGindex", getFmPKsGindex}, + {"getFmPKsHindex", getFmPKsHindex}, + {"getFmPKsDueltime", getFmPKsDueltime}, + {"getFmPKsPreparetime", getFmPKsPreparetime}, + {"Hash", Hash}, + {"NumRightToNum", NumRightToNum}, + {"NumLeftToNum", NumLeftToNum}, + {"Random", Random}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Other (lua_State *L) { + luaL_register(L, "other", otherlib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/petskill.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/petskill.c new file mode 100644 index 0000000..0299e49 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/petskill.c @@ -0,0 +1,115 @@ +#include +#include "common.h" +#include "version.h" +#include "pet_skill.h" +#include "mylua/base.h" +#include "char.h" +#include "item.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" + +#ifdef _ALLBLUES_LUA_1_8 +#include "mylua/mylua.h" +extern MY_Lua MYLua; +static CharBase PetSkillBaseInt[] = { + {{""}, PETSKILL_ID} + ,{{"ֶ"}, PETSKILL_FIELD} + ,{{"Ŀ"}, PETSKILL_TARGET} +#ifdef _PETSKILL2_TXT + ,{{""}, PETSKILL_USETYPE} +#endif + ,{{"ֵ"}, PETSKILL_COST} + ,{{"Ƿ"}, PETSKILL_ILLEGAL} +}; + +static CharBase PetSkillBaseChar[] = { + {{""}, PETSKILL_NAME} + ,{{"ע"}, PETSKILL_COMMENT} + ,{{""}, PETSKILL_FUNCNAME} + ,{{"ѡ"}, PETSKILL_OPTION} +#ifdef _CFREE_petskill + ,{{""}, PETSKILL_FREE} + ,{{""}, PETSKILL_KINDCODE} +#endif +}; + +static int getInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, PetSkillBaseInt, arraysizeof(PetSkillBaseInt)); + + lua_pushinteger(L, PETSKILL_getInt(index, element)); + return 1; +} + +static int setInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, PetSkillBaseInt, arraysizeof(PetSkillBaseInt)); + const int data = luaL_checkint(L, 3); + + if(PETSKILL_setInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getChar(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, PetSkillBaseChar, arraysizeof(PetSkillBaseChar)); + + lua_pushstring(L, PETSKILL_getChar(index, element)); + return 1; +} + +static int setChar(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, PetSkillBaseChar, arraysizeof(PetSkillBaseChar)); + char *data = luaL_checklstring(L, 3, &l); + + if(PETSKILL_setChar(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int check(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + lua_pushinteger(L, PETSKILL_CHECKINDEX(index)); + return 1; +} + +static int getPetskillArray(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + lua_pushinteger(L, PETSKILL_getPetskillArray(index)); + return 1; +} + +static const luaL_Reg petskilllib[] = { + {"getInt", getInt}, + {"setInt", setInt}, + {"getChar", getChar}, + {"setChar", setChar}, + {"check", check}, + {"getPetskillArray", getPetskillArray}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_PetSkill (lua_State *L) { + luaL_register(L, "petskill", petskilllib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/profession_skill.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/profession_skill.c new file mode 100644 index 0000000..3d85156 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/profession_skill.c @@ -0,0 +1,115 @@ +#include +#include "common.h" +#include "version.h" +#include "profession_skill.h" +#include "mylua/base.h" +#include "char.h" +#include "item.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "lssproto_serv.h" + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#ifdef _ALLBLUES_LUA_1_8 +#include "mylua/mylua.h" +extern MY_Lua MYLua; + +static CharBase ProfessionSkillBaseInt[] = { + {{""}, PROFESSION_SKILL_ID} + ,{{"ְҵ"}, PROFESSION_SKILL_PROFESSION_CLASS} + ,{{"Ŀ"}, PROFESSION_SKILL_TARGET} + ,{{"ķMP"}, PROFESSION_SKILL_COST_MP} + ,{{""}, PROFESSION_SKILL_USE_FLAG} + ,{{""}, PROFESSION_SKILL_KIND} + ,{{"ͼ"}, PROFESSION_SKILL_ICON} + ,{{"ǰͼ"}, PROFESSION_SKILL_IMG_1} + ,{{"ͼ"}, PROFESSION_SKILL_IMG_2} + ,{{""}, PROFESSION_SKILL_COST} + ,{{"ֵ"}, PROFESSION_SKILL_FIX_VALUE} + ,{{"1"}, PROFESSION_SKILL_LIMIT1} + ,{{"1"}, PROFESSION_SKILL_PERCENT1} + ,{{"2"}, PROFESSION_SKILL_LIMIT2} + ,{{"2"}, PROFESSION_SKILL_PERCENT2} + ,{{"3"}, PROFESSION_SKILL_LIMIT3} + ,{{"3"}, PROFESSION_SKILL_PERCENT3} + ,{{"4"}, PROFESSION_SKILL_LIMIT4} + ,{{"4"}, PROFESSION_SKILL_PERCENT4} +}; + +static CharBase ProfessionSkillBaseChar[] = { + {{""}, PROFESSION_SKILL_NAME} + ,{{"ע"}, PROFESSION_SKILL_TXT} + ,{{""}, PROFESSION_SKILL_FUNCNAME} + ,{{"ѡ"}, PROFESSION_SKILL_OPTION} +}; + +static int getInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ProfessionSkillBaseInt, arraysizeof(ProfessionSkillBaseInt)); + + lua_pushinteger(L, PROFESSION_SKILL_getInt(index, element)); + return 1; +} + +static int setInt(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ProfessionSkillBaseInt, arraysizeof(ProfessionSkillBaseInt)); + const int data = luaL_checkint(L, 3); + + if(PROFESSION_SKILL_setInt(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getChar(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ProfessionSkillBaseChar, arraysizeof(ProfessionSkillBaseChar)); + + lua_pushstring(L, PROFESSION_SKILL_getChar(index, element)); + return 1; +} + +static int setChar(lua_State *L) +{ + size_t l; + const int index = luaL_checkint(L, 1); + const int element = getCharBaseValue(L, 2, ProfessionSkillBaseChar, arraysizeof(ProfessionSkillBaseChar)); + char *data = luaL_checklstring(L, 3, &l); + + if(PROFESSION_SKILL_setChar(index, element, data) == -1){ + return 0; + }else{ + return 1; + } +} + +static int getProfessionskillArray(lua_State *L) +{ + const int index = luaL_checkint(L, 1); + + lua_pushinteger(L, PROFESSION_SKILL_getskillArray(index)); + return 1; +} + +static const luaL_Reg Professionskilllib[] = { + {"getInt", getInt}, + {"setInt", setInt}, + {"getChar", getChar}, + {"setChar", setChar}, + {"getProfessionskillArray", getProfessionskillArray}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_ProfessionSkill (lua_State *L) { + luaL_register(L, "Professionskill", Professionskilllib); + return 1; +} +#endif +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/saacproto.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/saacproto.c new file mode 100644 index 0000000..749b5ad --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/saacproto.c @@ -0,0 +1,61 @@ +#include +#include "char.h" +#include "char_base.h" +#include "mylua/base.h" +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include "saacproto_cli.h" + +#ifdef _ALLBLUES_LUA +static int ACFixFMPoint(lua_State *L) +{ + size_t l; + char *winfmname=luaL_checklstring(L, 1, &l); + const int winfmindex = luaL_checkint(L, 2); + const int winindex = luaL_checkint(L, 3); + char *losefmname=luaL_checklstring(L, 4, &l); + const int losefmindex = luaL_checkint(L, 5); + const int loseindex = luaL_checkint(L, 6); + const int village = luaL_checkint(L, 7); + + saacproto_ACFixFMPoint_send(acfd, winfmname, winfmindex, winindex, losefmname, losefmindex, loseindex, village); + + return 1; +} + +static int ACFMDetail(lua_State *L) +{ + size_t l; + char *fmname=luaL_checklstring(L, 1, &l); + const int fmindex = luaL_checkint(L, 2); + const int tempindex = luaL_checkint(L, 3); + const int fd = luaL_checkint(L, 4); + saacproto_ACFMDetail_send( acfd, fmname, fmindex, tempindex, CONNECT_getFdid(fd)); + return 1; +} + +static int ItemPetLocked(lua_State *L) +{ + size_t l; + int charaindex=luaL_checkint(L, 1); + int fd = getfdFromCharaIndex( charaindex); + char *data=luaL_checklstring(L, 2, &l); + saacproto_ItemPetLocked_send( fd, CHAR_getChar(charaindex, CHAR_CDKEY), data); + return 1; +} + +static const luaL_Reg Saacprotolib[] = { + {"ACFixFMPoint", ACFixFMPoint}, + {"ACFMDetail", ACFMDetail}, + {"ItemPetLocked", ItemPetLocked}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_Saacproto (lua_State *L) { + luaL_register(L, "saacproto", Saacprotolib); + return 1; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/sasqlbase.c b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/sasqlbase.c new file mode 100644 index 0000000..b656286 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/mylua/sasqlbase.c @@ -0,0 +1,321 @@ +#include +#include "lua.h" +#include "longzoro/version.h" +#include "lauxlib.h" +#include "lualib.h" +#include "net.h" +#include "log.h" +#include "longzoro/sasql.h" + +#ifdef _ALLBLUES_LUA +#ifdef _ALLBLUES_LUA_1_4 +#ifdef _SASQL +#include +extern MYSQL mysql; +static MYSQL_RES *mysql_result; +static MYSQL_ROW mysql_row; +static MYSQL_FIELD *fields; +int numrow = 0; +int numfields = 0; +static int setVipPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setVipPoint(charaindex, point); + return 1; +} + +static int getVipPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getVipPoint(charaindex)); + return 1; +} + +static int setVipPointForCdkey(lua_State *L) +{ + size_t l; + char *id=luaL_checklstring(L, 1, &l); + const int point = luaL_checkint(L, 2); + + sasql_setVipPointForCdkey(id, point); + return 1; +} + +static int getVipPointForCdkey(lua_State *L) +{ + size_t l; + char *id=luaL_checklstring(L, 1, &l); + lua_pushinteger(L, sasql_getVipPointForCdkey(id)); + return 1; +} + +static int setPayPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setPayPoint(charaindex, point); + return 1; +} + +static int getPayPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getPayPoint(charaindex)); + return 1; +} + + +#ifdef _GAMBLE_POINT +static int setGamblePoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setGamblePoint(charaindex, point); + return 1; +} + +static int getGamblePoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getGamblePoint(charaindex)); + return 1; +} +#endif + +#ifdef _TRIAL_POINT +static int setTrialPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setTrialPoint(charaindex, point); + return 1; +} + +static int getTrialPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getTrialPoint(charaindex)); + return 1; +} +#endif + +#ifdef _GLORY_POINT +static int setGloryPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setGloryPoint(charaindex, point); + return 1; +} + +static int getGloryPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getGloryPoint(charaindex)); + return 1; +} +#endif + +static int setPayPointForCdkey(lua_State *L) +{ + size_t l; + char *id=luaL_checklstring(L, 1, &l); + const int point = luaL_checkint(L, 2); + + sasql_setPayPointForCdkey(id, point); + return 1; +} + +static int getPayPointForCdkey(lua_State *L) +{ + size_t l; + char *id=luaL_checklstring(L, 1, &l); + lua_pushinteger(L, sasql_getPayPointForCdkey(id)); + return 1; +} + + +static int query(lua_State *L) +{ + size_t l; + char *data=luaL_checklstring(L, 1, &l); + + if(!sasql_mysql_query(data)){ + lua_pushinteger(L, 1); + }else{ + lua_pushinteger(L, 0); + } + return 1; +} + +static int free_result(lua_State *L) +{ + mysql_free_result(mysql_result); + return 1; +} + +static int store_result(lua_State *L) +{ + mysql_result=mysql_store_result(&mysql); + return 1; +} + +static int num_rows(lua_State *L) +{ + numrow=mysql_num_rows(mysql_result); + lua_pushinteger(L, numrow); + return 1; +} + +static int num_fields(lua_State *L) +{ + lua_pushinteger(L, numfields); + return 1; +} + +static int fetch_row(lua_State *L) +{ + mysql_row = mysql_fetch_row(mysql_result); + return 1; +} + +static int data(lua_State *L) +{ + int id = luaL_checkint(L, 1) - 1; + lua_pushstring(L, mysql_row[id]); + return 1; +} +#ifdef _NEW_SQL_MONEY +static int setSQLPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setSQLPoint(charaindex, point); + return 1; +} + +static int getSQLPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getSQLPoint(charaindex)); + return 1; +} + +static int setGoldPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int point = luaL_checkint(L, 2); + + sasql_setGoldPoint(charaindex, point); + return 1; +} + +static int getGoldPoint(lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + + lua_pushinteger(L, sasql_getGoldPoint(charaindex)); + return 1; +} +static int setSQLPointByCdkey(lua_State *L) +{ + size_t l; + char *cdkey=luaL_checklstring(L, 1, &l); + + const int point = luaL_checkint(L, 2); + + sasql_setSQLPointByCdkey(cdkey, point); + return 1; +} + +static int getSQLPointByCdkey(lua_State *L) +{ + size_t l; + char *cdkey=luaL_checklstring(L, 1, &l); + + lua_pushinteger(L, sasql_getSQLPointByCdkey(cdkey)); + return 1; +} + +static int setGoldPointByCdkey(lua_State *L) +{ + size_t l; + char *cdkey=luaL_checklstring(L, 1, &l); + const int point = luaL_checkint(L, 2); + + sasql_setGoldPointByCdkey(cdkey, point); + return 1; +} + +static int getGoldPointByCdkey(lua_State *L) +{ + size_t l; + char *cdkey=luaL_checklstring(L, 1, &l); + + lua_pushinteger(L, sasql_getGoldPointByCdkey(cdkey)); + return 1; +} + +#endif + +static const luaL_Reg sasqllib[] = { + {"setVipPoint", setVipPoint}, + {"getVipPoint", getVipPoint}, + {"query", query}, + {"free_result", free_result}, + {"store_result", store_result}, + {"num_rows", num_rows}, + {"fetch_row", fetch_row}, + {"num_fields", num_fields}, + {"data", data}, + {"setVipPointForCdkey", setVipPointForCdkey}, + {"getVipPointForCdkey", getVipPointForCdkey}, + {"setPayPoint", setPayPoint}, + {"getPayPoint", getPayPoint}, + {"setPayPointForCdkey", setPayPointForCdkey}, + {"getPayPointForCdkey", getPayPointForCdkey}, +#ifdef _GAMBLE_POINT + {"setGamblePoint", setGamblePoint}, + {"getGamblePoint", getGamblePoint}, +#endif +#ifdef _TRIAL_POINT + {"setTrialPoint", setTrialPoint}, + {"getTrialPoint", getTrialPoint}, +#endif +#ifdef _GLORY_POINT + {"setGloryPoint", setGloryPoint}, + {"getGloryPoint", getGloryPoint}, +#endif +#ifdef _NEW_SQL_MONEY + {"setSQLPoint", setSQLPoint}, + {"getSQLPoint", getSQLPoint}, + {"setGoldPoint", setGoldPoint}, + {"getGoldPoint", getGoldPoint}, + {"setSQLPointByCdkey", setSQLPointByCdkey}, + {"getSQLPointByCdkey", getSQLPointByCdkey}, + {"setGoldPointByCdkey", setGoldPointByCdkey}, + {"getGoldPointByCdkey", getGoldPointByCdkey}, +#endif + {NULL, NULL} +}; + +LUALIB_API int luaopen_Sasql (lua_State *L) { + luaL_register(L, "sasql", sasqllib); + return 1; +} +#endif +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/net.c b/石器时代服务器端最新完整源代码/Serv/gmsv/net.c new file mode 100644 index 0000000..9a8ec75 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/net.c @@ -0,0 +1,4588 @@ +#define __NET_C__ +#include "version.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef _EPOLL +#include +#endif +#include +#include +#include +#include +#include +//ttom+1 +#include +#include +#include "net.h" +#include "buf.h" +#include "link.h" +#include "common.h" +#include "msignal.h" +#include "configfile.h" +#include "util.h" +#include "saacproto_cli.h" +#include "lssproto_serv.h" +#include "char.h" +#include "handletime.h" +#include "log.h" +#include "object.h" +#include "item_event.h" +#include "enemy.h" +// Arminius 7.31 cursed stone +#include "battle.h" +#include "version.h" +#include "pet_event.h" +#include "char_talk.h" +#include "petmail.h" +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +#ifdef _AUTO_PK +#include "npc_autopk.h" +#endif +#include "pet_event.h" +#ifdef _LUCK_STAR +#include "longzoro/luckstar.h" +#endif +#ifdef _PLAYER_DIY_MAP +#include "readmap.h" +extern Player_Diy_Map PlayerDiyMap[Player_Diy_Map_NUM]; +#endif +#ifdef _GMSV_DEBUG +extern char *DebugMainFunction; +#endif +#include "longzoro/sasql.h" +#define MIN(x,y) ( ( (x) < (y) ) ? (x) : (y) ) + +char rbmess[ 1024*256 ]; + +#define MAXSIZE 64000 +#define MAXEPS 256 +//#define EVENTS 100 +#define LISTENQ 32 +#define SERV_PORT 8000 + +#ifdef _NEW_SERVER_ +BOOL bNewServer = TRUE; +#else +BOOL bNewServer = FALSE; +#endif +extern time_t initTime; +// Nuke +1 0901: For state monitor +int StateTable[ WHILESAVEWAIT + 1 ]; +#ifdef _EPOLL +int epollfd; +struct epoll_event evEpoll; +struct epoll_event* eventsEpoll; +void procPlay(); +typedef struct Node Node; +typedef struct Node{ + int fd; + Node *next; +}; + +Node * EpollSendpNode[4]; +extern BOOL lianjielog; +pthread_mutex_t lianbiaomutex; +pthread_mutex_t lianbiaoRecvmutex; + +#define LIANBIAOSENDLOCK pthread_mutex_lock(&lianbiaomutex); +#define LIANBIAOSENDUNLOCK pthread_mutex_unlock(&lianbiaomutex ); +#define LIANBIAORECVLOCK pthread_mutex_lock(&lianbiaoRecvmutex); +#define LIANBIAORECVUNLOCK pthread_mutex_unlock(&lianbiaoRecvmutex ); + +#define CONNECT_LOCK(i) pthread_mutex_lock( &Connect[i].sEndmutex ); +#define CONNECT_UNLOCK(i) pthread_mutex_unlock( &Connect[i].sEndmutex ); +#define CONNECT_RecvLOCK(i) pthread_mutex_lock( &Connect[i].rEcvmutex ); +#define CONNECT_RecvUNLOCK(i) pthread_mutex_unlock( &Connect[i].rEcvmutex ); +#endif + +extern int luaplayernum; + +int CHAR_players(); +#define CONO_CHECK_LOGIN 0x001 +#define CONO_CHECK_ITEM 0x010 +#define CONO_CHECK_PET 0x100 +int cono_check = 0x111; + +int AC_WBSIZE = ( 1024*1024 ); +//ttom+1 for the performatce +static unsigned int MAX_item_use = 0; +int i_shutdown_time = 0; //ttom +BOOL b_first_shutdown = FALSE; //ttom + +int mfdfulll = 0; +int sendspeed = 0; +int recvspeed = 0; + +#ifdef _NO_ATTACK +unsigned int atttime=0; +static unsigned long useripnum = 100000; +static unsigned long* userip = 0; +static unsigned long* userip_count_data = 0; +static unsigned long useripcount = 0; +static unsigned long* useriptime = 0; +#endif + +/*------------------------------------------------------------ + * ӡP + ------------------------------------------------------------*/ +typedef struct tag_serverState +{ + BOOL acceptmore; /* 1գaccept ؤ + нƥclose */ + unsigned int fdid; /* fd ɧԻ */ + unsigned int closeallsocketnum; /* closeallsocket Ի + */ + int shutdown; /* ӡëshutdownƹ + * 0:ɧ ľ½:ƹ + * ƹئ޻ Ȼ£ + */ + int dsptime; /* shutdown ƹ񼰷 */ + int limittime; /* ľ */ +}ServerState; + +#ifdef _MO_LNS_NLSUOXU +typedef struct tagFuncKk +{ + char *FileName; /*ű·*/ + char *FuncName; /*ִк*/ + unsigned int EspTime; + unsigned int MespTime; + int ID; + unsigned int GetTime; +}FuncKk; + +FuncKk TimerLua[50]; +void SetTimerLua(void)//ʼLUAʱ +{ + int i; + for( i = 0 ; i < arraysizeof( TimerLua ) ; i ++ ){ + TimerLua[i].FileName = NULL; + TimerLua[i].FuncName = NULL; + TimerLua[i].EspTime = -1; + TimerLua[i].MespTime=-1; + TimerLua[i].ID = -1; + TimerLua[i].GetTime = -1; + } +} + +int SetTimer_net(char *FileName,char *FuncName,unsigned int EspTime) +{ + int i; + for( i = 0 ; i < arraysizeof( TimerLua ) ; i ++ ){ + if (TimerLua[i].ID == -1) break; + } + TimerLua[i].FileName = FileName; + TimerLua[i].FuncName = FuncName; + TimerLua[i].EspTime = NowTime.tv_sec; + TimerLua[i].MespTime= NowTime.tv_usec; + TimerLua[i].ID = i+1; + TimerLua[i].GetTime = EspTime*1024; + return i+1; +} +#endif + +typedef struct tagCONNECT +{ + BOOL use; + + char *rb; + int rbuse; + char *wb; + int wbuse; + int check_rb_oneline_b; + int check_rb_time; + pthread_mutex_t mutex; + + struct sockaddr_in sin; /* Ƽʧ */ + ConnectType ctype; /* ˒ */ + + char cdkey[ CDKEYLEN ]; /* CDKEY */ + char passwd[ PASSWDLEN ]; /* ɵ */ + LoginType state; /* ػ̼ */ + int nstatecount; + char charname[ CHARNAMELEN ]; /* ̼wƽҷ’o */ + int charaindex; /* char?d߼̼͵z + * ̼ԉɬýľ©z-1ɻ + * ?dئݩz + */ + char CAbuf[ 2048 ]; /* CA() ë¿м */ + int CAbufsiz; /* CAbuf */ + + struct timeval lastCAsendtime; /*ԉCAë˪ */ + + char CDbuf[ 2048 ]; /* CD() ë¿м */ + int CDbufsiz; /* CDbuf */ + + struct timeval lastCDsendtime; /*ԉCDë˪ */ + + struct timeval lastCharSaveTime; /* ԉƽҷ·ëƤ */ + + struct timeval lastprocesstime; /* ԉëʆA*/ + + struct timeval lastreadtime; /* ԉreadީz練л*/ + + // Nuke start 08/27 : For acceleration avoidance + // WALK_TOLERANCE: Permit n W messages in a second (3: is the most restricted) +#define WALK_TOLERANCE 4 + #define WALK_SPOOL 5 + #define WALK_RESTORE 100 + unsigned int Walktime; + unsigned int lastWalktime; + unsigned int Walkcount; + int Walkspool; // For walk burst after release key F10 + int Walkrestore; + // B3_TOLERANCE: Time distance between recently 3 B message (8: is the latgest) + // BEO_TOLERANCE: Time distance between the lastmost B and EO (5: is the largest) +#define B3_TOLERANCE 5 + #define BEO_TOLERANCE 3 + #define BEO_SPOOL 10 + #define BEO_RESTORE 100 + unsigned int Btime; + unsigned int lastBtime; + unsigned int lastlastBtime; + unsigned int EOtime; + +#ifdef _BATTLE_TIMESPEED + // unsigned int DefBtime; + int BDTime; + int CBTime; +#endif + +#ifdef _TYPE_TOXICATION + int toxication; +#endif + +#ifdef _ITEM_ADDEXP //vincent N + int EDTime; +#endif + // unsigned int BEO; + int BEOspool; + int BEOrestore; + + int credit; + int fcold; + // Nuke 0406: New Flow Control + int nu; + int nu_decrease; + + // Nuke 1213: Flow Control 2 + int packetin; + + // Nuke 0624: Avoid Null Connection + unsigned int cotime; + // Nuke 0626: For no enemy + int noenemy; + // Arminius 7.2: Ra's amulet + int eqnoenemy; +#ifdef _Item_MoonAct + int eqrandenemy; +#endif + +#ifdef _CHIKULA_STONE + int chistone; +#endif + // Arminius 7.31: cursed stone + int stayencount; + + int battlecharaindex[ CONNECT_WINDOWBUFSIZE ]; + int duelcharaindex[ CONNECT_WINDOWBUFSIZE ]; + int tradecardcharaindex[ CONNECT_WINDOWBUFSIZE ]; + int joinpartycharaindex[ CONNECT_WINDOWBUFSIZE ]; + + // CoolFish: Trade 2001/4/18 + int tradecharaindex[ CONNECT_WINDOWBUFSIZE ]; + int errornum; + int fdid; + + int close_request; //the second have this + + int appendwb_overflow_flag; /* 1ƥappendWb?1 */ + + BOOL b_shut_up; //for avoid the user wash the screen + BOOL b_pass; //for avoid the unlimited area + + struct timeval Wtime; + + struct timeval WLtime; + BOOL b_first_warp; + int state_trans; + + // CoolFish: Trade 2001/4/18 + char TradeTmp[ 256 ]; + +#ifdef _ITEM_PILEFORTRADE + int tradelist; +#endif + // Shan Recvdata Time + + struct timeval lastrecvtime; // 'FM' Stream Control time + + struct timeval lastrecvtime_d; // DENGON Talk Control time + + // Arminius: 6.22 encounter + int CEP; // Current Encounter Probability + // Arminius 7.12 login announce + int announced; + + // shan battle delay time 2001/12/26 + + struct timeval battle_recvtime; + + BOOL confirm_key; // shan trade(DoubleCheck) + +#ifdef _NEWCLISETSERVID + int servid; +#endif + +#ifdef _NEWCLISETMAC + char mac[128]; +#endif + + int connecttime; + unsigned int starttime; +#ifdef _NEW_FUNC_DECRYPT + int newerrnum; +#endif +} +CONNECT; + +CONNECT *Connect; /*ͥݤ*/ + + +/* ؿƬˤĤƤ狼褦ˤΥޥ */ +#define SINGLETHREAD +#define MUTLITHREAD +#define ANYTHREAD + +ServerState servstate; + +pthread_mutex_t MTIO_servstate_m; +#define SERVSTATE_LOCK() pthread_mutex_lock( &MTIO_servstate_m ); +#define SERVSTATE_UNLOCK() pthread_mutex_unlock( &MTIO_servstate_m ); +#define CONNECT_LOCK_ARG2(i,j) pthread_mutex_lock( &Connect[i].mutex ); +#define CONNECT_UNLOCK_ARG2(i,j) pthread_mutex_unlock( &Connect[i].mutex ); +#define CONNECT_LOCK(i) pthread_mutex_lock( &Connect[i].mutex ); +#define CONNECT_UNLOCK(i) pthread_mutex_unlock( &Connect[i].mutex ); +/* +#define SERVSTATE_LOCK() +#define SERVSTATE_UNLOCK() +#define CONNECT_LOCK_ARG2(i,j) +#define CONNECT_UNLOCK_ARG2(i,j) +#define CONNECT_LOCK(i) +#define CONNECT_UNLOCK(i) +*/ + + + +void SetTcpBuf( int fd, fd_set *fds) +{ + int yes = 1; + + int result = fcntl(fd,F_SETFL,O_NONBLOCK); + + setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof yes); // reuse fix + +// setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof yes); //reuse fix + + setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes); // reuse fix + + if(fd==-1){ + perror("accept"); + } else { + FD_SET(fd, fds); + } + result = fcntl(fd, F_SETFL, O_NONBLOCK); +} + +#ifdef _SAME_IP_ONLINE_NUM +int SameIpOnlineNum( unsigned long ip ){ +#ifdef _CHECK_SEVER_IP + if(checkServerIp(ip) == TRUE){ + return 0; + } +#endif + int MAX_USER = getFdnum(); + int i, num=0; + if(getSameIpOnlineNum()>0){ + for(i=4;i= getSameIpOnlineNum()){ + return 1; + } + } + } + } + } + + return 0; +} +#endif + +/*------------------------------------------------------------ + * servstateë©z + * ¦ѩy߯Ի + * ئ + ------------------------------------------------------------*/ +ANYTHREAD static void SERVSTATE_initserverState( void ) +{ + SERVSTATE_LOCK(); + servstate.acceptmore = TRUE; + servstate.fdid = 0; + servstate.closeallsocketnum = -1; + servstate.shutdown = 0; + servstate.limittime = 0; + servstate.dsptime = 0; + SERVSTATE_UNLOCK(); +} + +ANYTHREAD int SERVSTATE_SetAcceptMore( int nvalue ) +{ + BOOL buf; + SERVSTATE_LOCK(); + buf = servstate.acceptmore; + servstate.acceptmore = nvalue; + SERVSTATE_UNLOCK(); + return buf; +} +ANYTHREAD static int SERVSTATE_incrementFdid( void ) +{ + int ret; + SERVSTATE_LOCK(); + ret = servstate.fdid++; + SERVSTATE_UNLOCK(); + return ret; +} +ANYTHREAD static void SERVSTATE_setCloseallsocketnum( int a ) +{ + SERVSTATE_LOCK(); + servstate.closeallsocketnum = a; + SERVSTATE_UNLOCK(); +} +ANYTHREAD static void SERVSTATE_incrementCloseallsocketnum(void) +{ + SERVSTATE_LOCK(); + servstate.closeallsocketnum ++; + SERVSTATE_UNLOCK(); +} +ANYTHREAD void SERVSTATE_decrementCloseallsocketnum(void) +{ + SERVSTATE_LOCK(); + servstate.closeallsocketnum --; + SERVSTATE_UNLOCK(); +} +ANYTHREAD int SERVSTATE_getCloseallsocketnum( void ) +{ + int a; + SERVSTATE_LOCK(); + a = servstate.closeallsocketnum; + SERVSTATE_UNLOCK(); + return a; +} + +ANYTHREAD static int SERVSTATE_getAcceptmore(void) +{ + int a; + SERVSTATE_LOCK(); + a = servstate.acceptmore; + SERVSTATE_UNLOCK(); + return a; +} +ANYTHREAD int SERVSTATE_getShutdown(void) +{ + int a; + SERVSTATE_LOCK(); + a = servstate.shutdown; + SERVSTATE_UNLOCK(); + return a; +} +ANYTHREAD void SERVSTATE_setShutdown(int a) +{ + SERVSTATE_LOCK(); + servstate.shutdown = a; + SERVSTATE_UNLOCK(); +} +ANYTHREAD int SERVSTATE_getLimittime(void) +{ + int a; + SERVSTATE_LOCK(); + a = servstate.limittime; + SERVSTATE_UNLOCK(); + return a; +} +ANYTHREAD void SERVSTATE_setLimittime(int a) +{ + SERVSTATE_LOCK(); + servstate.limittime = a; + SERVSTATE_UNLOCK(); +} +ANYTHREAD int SERVSTATE_getDsptime(void) +{ + int a; + SERVSTATE_LOCK(); + a = servstate.dsptime; + SERVSTATE_UNLOCK(); + return a; +} +ANYTHREAD void SERVSTATE_setDsptime(int a) +{ + SERVSTATE_LOCK(); + servstate.dsptime = a; + SERVSTATE_UNLOCK(); +} + +static int appendWB( int fd, char *buf, int size ) +{ +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fd) != AC ) { +#else + if ( fd != acfd ) { +#endif + if ( Connect[ fd ].wbuse + size >= WBSIZE ) { + print( "appendWB:err buffer over[%d]:%s \n", + Connect[ fd ].wbuse + size, Connect[ fd ].cdkey ); + return -1; + } + }else { + if ( Connect[ fd ].wbuse + size > AC_WBSIZE ) { +/* + FILE * fp = NULL; + + if ( ( fp = fopen( "appendWBerr.log", "a+" ) ) == NULL ) return -1; + + fprintf( fp, "(SAAC) appendWB:err buffer over[%d+%d/%d]:\n", Connect[ fd ].wbuse, size, AC_WBSIZE ); + + fclose( fp ); +*/ + //print( "appendWB:err buffer over[%d+%d]:(SAAC) \n", Connect[ fd ].wbuse, size ); + return -1; + } + } + + + + memcpy( Connect[ fd ].wb + Connect[ fd ].wbuse , + buf, size ); + Connect[ fd ].wbuse += size; + return size; +} +static int appendRB( int fd, char *buf, int size ) +{ +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fd) != AC ) { +#else + if ( fd != acfd ) { +#endif + if ( Connect[ fd ].rbuse + size > RBSIZE ) { + //print( "appendRB:OTHER(%d) err buffer over \n", fd ); + + return -1; + } + }else { + if ( strlen( buf ) > size ) { + print( "appendRB AC buffer len err : %d/%d=\n", strlen( buf ), size ); + } + + if ( Connect[ fd ].rbuse + size > AC_RBSIZE ) { + printf("%s\n", buf); + print( "appendRB AC err buffer over: len:%d - AC_RBSIZE:%d \n", + Connect[ fd ].rbuse + size, AC_RBSIZE ); + return -1; + } + } + + memcpy( Connect[ fd ].rb + Connect[ fd ].rbuse , buf, size ); + Connect[ fd ].rbuse += size; + return size; +} + +static int shiftWB( int fd, int len ) +{ + if ( Connect[ fd ].wbuse < len ) { + print( "shiftWB: err\n" ); + return -1; + } + + memmove( Connect[ fd ].wb, Connect[ fd ].wb + len, Connect[ fd ].wbuse - len ); + Connect[ fd ].wbuse -= len; + + if ( Connect[ fd ].wbuse < 0 ) { + print( "shiftWB:wbuse err\n" ); + Connect[ fd ].wbuse = 0; + } + + return len; +} + +static int shiftRB( int fd, int len ) +{ + if ( Connect[ fd ].rbuse < len ) { + print( "shiftRB: err\n" ); + return -1; + } + + memmove( Connect[ fd ].rb, Connect[ fd ].rb + len, Connect[ fd ].rbuse - len ); + Connect[ fd ].rbuse -= len; + + if ( Connect[ fd ].rbuse < 0 ) { + print( "shiftRB:rbuse err\n" ); + Connect[ fd ].rbuse = 0; + } + + return len; +} + +SINGLETHREAD int lsrpcClientWriteFunc( int fd , char* buf , int size ) +{ + int r; + + if ( Connect[ fd ].use == FALSE ) { + return FALSE; + } + + if ( Connect[ fd ].appendwb_overflow_flag ) { + print( "lsrpcClientWriteFunc: buffer overflow fd:%d\n" , fd ); + return -1; + } + + r = appendWB( fd, buf , size ); + + // Nuke *1 0907: Ignore acfd from WB error +#ifdef _OTHER_SAAC_LINK + if ( ( r < 0 ) && ( CONNECT_getCtype(fd) != AC + && CONNECT_getCtype(fd) != SQL )){ +#else + if ( ( r < 0 ) && ( fd != acfd ) ) { +#endif + Connect[ fd ].appendwb_overflow_flag = 1; +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fd,charname,32); + CONNECT_getCdkey(fd,cdkey,16); + char token[128]; + sprintf(token,"appendWB r=%d Connect[ fd ].wbuse + size=%d",r,Connect[ fd ].wbuse + size); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + CONNECT_endOne_debug( fd ); + // Nuke + 1 0901: Why close + // print("closed in lsrpcClientWriteFunc"); +#ifdef _EPOLL + }else{ + ModEpollOut(fd); + +#endif + } + return r; +} + +static int logRBuseErr = 0; +SINGLETHREAD BOOL GetOneLine_fix( int fd, char *buf, int max ) +{ + int i; + + if ( Connect[ fd ].rbuse == 0 ) return FALSE; + + if ( Connect[ fd ].check_rb_oneline_b == 0 && + Connect[ fd ].check_rb_oneline_b == Connect[ fd ].rbuse ) { + return FALSE; + } + + + for ( i = 0; i < Connect[ fd ].rbuse && i < ( max - 1 ); i ++ ) { + if ( Connect[ fd ].rb[ i ] == '\n' ) { + memcpy( buf, Connect[ fd ].rb, i + 1); + buf[ i + 1 ] = '\0'; + shiftRB( fd, i + 1 ); + + //-------- + /* + //andy_log + if( strstr( Connect[fd].rb , "ACCharLoad") != NULL && + Connect[fd].check_rb_oneline_b != 0 )//Connect[fd].rb + LogAcMess( fd, "GetOne", Connect[fd].rb ); + */ + //-------- + logRBuseErr = 0; + Connect[ fd ].check_rb_oneline_b = 0; + Connect[ fd ].check_rb_time = 0; + return TRUE; + } + } + + if ( fd == acfd ){ + logRBuseErr++; + } + + if( logRBuseErr >= 50 ) { + Connect[ fd ].rb[Connect[ fd ].rbuse] = '\n'; + printf("rebuse err %d:%d\n", logRBuseErr, Connect[ fd ].rbuse); + logRBuseErr = 0; + } + //-------- + //andy_log +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fd) == AC && strstr( Connect[ fd ].rb , "ACCharLoad" ) != NULL && +#else + if ( fd == acfd && strstr( Connect[ fd ].rb , "ACCharLoad" ) != NULL && +#endif + logRBuseErr >= 50 ) { //Connect[fd].rb + char buf[ AC_RBSIZE ]; + memcpy( buf, Connect[ fd ].rb, Connect[ fd ].rbuse + 1 ); + buf[ Connect[ fd ].rbuse + 1 ] = 0; + LogAcMess( fd, "RBUFFER", buf ); + logRBuseErr = 0; + } + + //-------- + Connect[ fd ].check_rb_oneline_b = Connect[ fd ].rbuse; + + return FALSE; +} + +ANYTHREAD BOOL initConnectOne( int sockfd, struct sockaddr_in* sin ,int len ) +{ + CONNECT_LOCK( sockfd ); + + Connect[ sockfd ].use = TRUE; + Connect[ sockfd ].ctype = NOTDETECTED; + Connect[ sockfd ].wbuse = Connect[ sockfd ].rbuse = 0; + Connect[ sockfd ].check_rb_oneline_b = 0; + Connect[ sockfd ].check_rb_time = 0; + + memset( Connect[ sockfd ].cdkey , 0 , sizeof( Connect[ sockfd ].cdkey ) ); + memset( Connect[ sockfd ].passwd, 0 , sizeof( Connect[ sockfd ].passwd ) ); + + Connect[ sockfd ].state = NULLCONNECT; + Connect[ sockfd ].nstatecount = 0; + memset( Connect[ sockfd ].charname, 0, sizeof( Connect[ sockfd ].charname ) ); + Connect[ sockfd ].charaindex = -1; + + Connect[ sockfd ].CAbufsiz = 0; + Connect[ sockfd ].CDbufsiz = 0; + Connect[ sockfd ].rbuse = 0; + Connect[ sockfd ].wbuse = 0; + Connect[ sockfd ].check_rb_oneline_b = 0; + Connect[ sockfd ].check_rb_time = 0; + + Connect[ sockfd ].close_request = 0; /* Ӭۢư׷º */ + // Nuke 08/27 For acceleration avoidance + Connect[ sockfd ].Walktime = 0; + Connect[ sockfd ].lastWalktime = 0; + Connect[ sockfd ].Walkcount = 0; + Connect[ sockfd ].Walkspool = WALK_SPOOL; + Connect[ sockfd ].Walkrestore = WALK_RESTORE; + Connect[ sockfd ].Btime = 0; + Connect[ sockfd ].lastBtime = 0; + Connect[ sockfd ].lastlastBtime = 0; + Connect[ sockfd ].EOtime = 0; + Connect[ sockfd ].nu_decrease = 0; +#ifdef _BATTLE_TIMESPEED + // Connect[sockfd].DefBtime = 0; + Connect[ sockfd ].BDTime = 0; + Connect[ sockfd ].CBTime = 0; +#endif +#ifdef _TYPE_TOXICATION + Connect[ sockfd ].toxication = 0; +#endif +#ifdef _ITEM_ADDEXP //vincent + Connect[ sockfd ].EDTime = 0; +#endif + // Connect[sockfd].BEO = 0; + Connect[ sockfd ].BEOspool = BEO_SPOOL; + Connect[ sockfd ].BEOrestore = BEO_RESTORE; + //ttom + Connect[ sockfd ].b_shut_up = FALSE; + Connect[ sockfd ].Wtime.tv_sec = 0; // + Connect[ sockfd ].Wtime.tv_usec = 0; // + Connect[ sockfd ].WLtime.tv_sec = 0; // + Connect[ sockfd ].WLtime.tv_usec = 0; // + Connect[ sockfd ].b_first_warp = FALSE; + Connect[ sockfd ].state_trans = 0; //avoid the trans + + Connect[ sockfd ].credit = 3; + Connect[ sockfd ].fcold = 0; + // Nuke 0406: New Flow Control + Connect[ sockfd ].nu = 30; + + // Nuke 1213: Flow Control 2 + Connect[ sockfd ].packetin = 30; // if 10x10 seconds no packet, drop the line + + // Nuke 0624: Avoid Useless Connection + Connect[ sockfd ].cotime = 0; + // Nuke 0626: For no enemy + Connect[ sockfd ].noenemy = 0; + // Arminius 7.2: Ra's amulet + Connect[ sockfd ].eqnoenemy = 0; + +#ifdef _Item_MoonAct + Connect[ sockfd ].eqrandenemy = 0; +#endif +#ifdef _CHIKULA_STONE + Connect[ sockfd ].chistone = 0; +#endif + // Arminius 7.31: cursed stone + Connect[ sockfd ].stayencount = 0; + + // CoolFish: Init Trade 2001/4/18 + memset( &Connect[ sockfd ].TradeTmp, 0, sizeof( Connect[ sockfd ].TradeTmp ) ); +#ifdef _ITEM_PILEFORTRADE + Connect[ sockfd ].tradelist = -1; +#endif + // Arminius 6.22 Encounter + Connect[ sockfd ].CEP = 0; + + // Arminius 7.12 login announce + Connect[ sockfd ].announced = 0; + + Connect[ sockfd ].confirm_key = FALSE; // shan trade(DoubleCheck) + +#ifdef _NEW_FUNC_DECRYPT + Connect[ sockfd ].newerrnum = 0; +#endif + + if ( sin != NULL ) memcpy( &Connect[ sockfd ].sin , sin , len ); + + memset( &Connect[ sockfd ].lastprocesstime, 0 , + sizeof( Connect[ sockfd ].lastprocesstime ) ); + + memcpy( &Connect[ sockfd ].lastCAsendtime, &NowTime , + sizeof( Connect[ sockfd ].lastCAsendtime ) ); + + memcpy( &Connect[ sockfd ].lastCDsendtime, &NowTime , + sizeof( Connect[ sockfd ].lastCDsendtime ) ); + + memcpy( &Connect[ sockfd ].lastCharSaveTime, &NowTime , + sizeof( Connect[ sockfd ].lastCharSaveTime ) ); + + // Shan Add + memcpy( &Connect[ sockfd ].lastrecvtime, &NowTime , + sizeof( Connect[ sockfd ].lastrecvtime ) ); + + memcpy( &Connect[ sockfd ].lastrecvtime_d, &NowTime , + sizeof( Connect[ sockfd ].lastrecvtime_d ) ); + + memcpy( &Connect[ sockfd ].battle_recvtime, &NowTime , + sizeof( Connect[ sockfd ].battle_recvtime ) ); + + memcpy( &Connect[ sockfd ].lastreadtime , &NowTime, + + sizeof( struct timeval ) ); + + Connect[ sockfd ].lastreadtime.tv_sec -= DEBUG_ADJUSTTIME; + + Connect[ sockfd ].errornum = 0; + + Connect[ sockfd ].fdid = SERVSTATE_incrementFdid(); + + CONNECT_UNLOCK( sockfd ); + + Connect[ sockfd ].appendwb_overflow_flag = 0; + + Connect[sockfd].connecttime = time(NULL); + + memset(Connect[ sockfd ].mac, 0, sizeof(Connect[ sockfd ].mac)); + return TRUE; +} + +ANYTHREAD BOOL _CONNECT_endOne( char *file, int fromline, int sockfd , int line ) +{ + if(errno==113 || errno==104){ + return TRUE; + } + CONNECT_LOCK_ARG2(sockfd,line); + + if( Connect[sockfd].use == FALSE ){ + CONNECT_UNLOCK_ARG2(sockfd,line); + //andy_log + print("ѹر[%d]!!\n", sockfd ); + return TRUE; + } + Connect[sockfd].use = FALSE; + if( Connect[sockfd].ctype == CLI && CHAR_CHECKINDEX(Connect[sockfd].charaindex) == TRUE ){ + CONNECT_UNLOCK_ARG2( sockfd,line ); +#ifdef _OFFLINE_SYSTEM + if(CHAR_getWorkInt( Connect[sockfd].charaindex, CHAR_WORK_OFFLINE ) != 0){ + CHAR_setWorkInt( Connect[sockfd].charaindex, CHAR_WORKFD, -1); + }else +#endif + { + if( !CHAR_logout( Connect[sockfd].charaindex,TRUE )) { + //print( "err %s:%d from %s:%d \n", __FILE__, __LINE__, file, fromline); + } + print( "˳˺=%s \n", Connect[sockfd].cdkey ); + } + CONNECT_LOCK_ARG2( sockfd ,line); + } +#ifdef _NO_ATTACK + else{ + if(strlen(Connect[sockfd].cdkey)<1){ + // ʱ + time_t curtime; + struct tm *p; + time(&curtime); + p=localtime(&curtime); + curtime = mktime(p); + if( curtime - Connect[sockfd].starttime <= getAttTime() ){ + unsigned long tmpip=CONNECT_get_userip(sockfd); + unsigned long i = 0; + int ipa,ipb,ipc,ipd; + char ip[32]; + ipa=(tmpip % 0x100); tmpip=tmpip / 0x100; + ipb=(tmpip % 0x100); tmpip=tmpip / 0x100; + ipc=(tmpip % 0x100); tmpip=tmpip / 0x100; + ipd=(tmpip % 0x100); + sprintf(ip,"%d.%d.%d.%d",ipa,ipb,ipc,ipd); + for(; i < useripcount; ++i ){ + if( userip[i] == tmpip ){ + if(userip_count_data[i]>=getAttCnt()){ + Connect[sockfd].wbuse = 0; + Connect[sockfd].rbuse = 0; + Connect[sockfd].CAbufsiz = 0; + Connect[sockfd].CDbufsiz = 0; + CONNECT_UNLOCK_ARG2(sockfd,line); + + print( "Ƿ=%d ǷIP=%s \n", sockfd, ip ); + close(sockfd); + userip_count_data[i] = 1; + useriptime[i] = curtime; + return TRUE; + } + if(curtime-useriptime[i]<=getAttSafeTime()){ + ++userip_count_data[i]; + break; + }else{ + useriptime[i]=curtime; + break; + } + } + } + if(strcmp(ip,getNoAttIp(0))!=0 && strcmp(ip,getNoAttIp(1))!=0 && strcmp(ip,getNoAttIp(2))!=0 && strcmp(ip,getNoAttIp(3))!=0 && strcmp(ip,getNoAttIp(4))!=0){ + if(i>= useripcount && useripcount-1){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE )!= CHAR_PARTY_CLIENT ){ + if( getStayEncount( fd) ) return FALSE; + }else{ + int oyaindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1); + if( getStayEncount( getfdFromCharaIndex(oyaindex)) ) return FALSE; + } + }else{ + return FALSE; + } +#endif + CONNECT_LOCK( fd ); + /* ǸΥǥߥ ',' ʬ¿ݤʤ */ + if ( ( Connect[ fd ].CAbufsiz + size ) >= sizeof( Connect[ fd ].CAbuf ) ) { + CONNECT_UNLOCK( fd ); + return FALSE; + } + + memcpy( Connect[ fd ].CAbuf + Connect[ fd ].CAbufsiz , data , size ); + Connect[ fd ].CAbuf[ Connect[ fd ].CAbufsiz + size ] = ','; + Connect[ fd ].CAbufsiz += ( size + 1 ); + CONNECT_UNLOCK( fd ); +#ifdef _EPOLL + //ModEpollOut(fd); +#endif + return TRUE; +} + +ANYTHREAD static int CONNECT_getCAbuf( int fd, char *out, int outmax, + int *outlen ) +{ + CONNECT_LOCK( fd ); + if ( Connect[ fd ].use == TRUE ) { + int cplen = MIN( outmax, Connect[ fd ].CAbufsiz ); + memcpy( out, Connect[ fd ].CAbuf , cplen ); + *outlen = cplen; + CONNECT_UNLOCK( fd ); + return 0; + } else { + CONNECT_UNLOCK( fd ); + return -1; + } +} +ANYTHREAD static int CONNECT_getCDbuf( int fd, char *out, int outmax, + int *outlen ) +{ + CONNECT_LOCK( fd ); + + if ( Connect[ fd ].use == TRUE ) { + int cplen = MIN( outmax, Connect[ fd ].CDbufsiz ); + memcpy( out, Connect[ fd ].CDbuf, cplen ); + *outlen = cplen; + CONNECT_UNLOCK( fd ); + return 0; + } else { + CONNECT_UNLOCK( fd ); + return 0; + } +} + +ANYTHREAD static int CONNECT_setCAbufsiz( int fd, int len ) +{ + CONNECT_LOCK( fd ); + + if ( Connect[ fd ].use == TRUE ) { + Connect[ fd ].CAbufsiz = len; + CONNECT_UNLOCK( fd ); + return 0; + } else { + CONNECT_UNLOCK( fd ); + return -1; + } +} +ANYTHREAD static int CONNECT_setCDbufsiz( int fd, int len ) +{ + CONNECT_LOCK( fd ); + + if ( Connect[ fd ].use == TRUE ) { + Connect[ fd ].CDbufsiz = len; + CONNECT_UNLOCK( fd ); + return 0; + } else { + CONNECT_UNLOCK( fd ); + return -1; + } +} + +ANYTHREAD static void CONNECT_setLastCAsendtime( int fd, struct timeval *t) +{ + CONNECT_LOCK( fd ); + Connect[ fd ].lastCAsendtime = *t; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD static void CONNECT_getLastCAsendtime( int fd, struct timeval *t ) +{ + CONNECT_LOCK( fd ); + *t = Connect[ fd ].lastCAsendtime; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD static void CONNECT_setLastCDsendtime( int fd, struct timeval *t ) +{ + CONNECT_LOCK( fd ); + Connect[ fd ].lastCDsendtime = *t; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD static void CONNECT_getLastCDsendtime( int fd, struct timeval *t ) +{ + CONNECT_LOCK( fd ); + *t = Connect[ fd ].lastCDsendtime; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getUse_debug( int fd, int i ) +{ + int a; + if( 0 > fd || fd >= ConnectLen ){ + return 0; + } + CONNECT_LOCK_ARG2( fd, i ); + a = Connect[ fd ].use; + CONNECT_UNLOCK_ARG2( fd, i ); + return a; + +} + +ANYTHREAD int CONNECT_getUse( int fd ) +{ + int a; + if( 0 > fd || fd >= ConnectLen ){ + return 0; + } + CONNECT_LOCK( fd ); + a = Connect[ fd ].use; + CONNECT_UNLOCK( fd ); + return a; +} +void CONNECT_setUse( int fd , int a) +//ANYTHREAD static void CONNECT_setUse( int fd , int a) +{ + CONNECT_LOCK( fd ); + Connect[ fd ].use = a; + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD void CONNECT_checkStatecount( int a ) +{ + int i; + int count = 0; + + for ( i = 0; i < ConnectLen; i++ ) { + if ( Connect[ i ].use == FALSE || Connect[ i ].state != a ) continue; + + if ( Connect[ i ].nstatecount <= 0 ) { + Connect[ i ].nstatecount = ( int ) time( NULL ) + 60; + }else{ + if ( Connect[ i ].nstatecount < ( int ) time( NULL ) ) { +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CONNECT_getCharaindex( i ),charname,32); + CONNECT_getCdkey(CONNECT_getCharaindex( i ),cdkey,16); + char token[128]; + sprintf(token, "CONNECT_checkStatecount T "); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + CONNECT_endOne_debug( i ); + count++; + } + } + } + + { + memset( StateTable, 0, sizeof( StateTable ) ); + + for ( i = 0; i < ConnectLen; i++ ) + if ( Connect[ i ].use == TRUE ) + StateTable[ Connect[ i ].state ] ++; + } +} + +ANYTHREAD void CONNECT_setState( int fd , int a) +{ + CONNECT_LOCK( fd ); + Connect[ fd ].state = a; + Connect[ fd ].nstatecount = 0; + + // Nuke start 0829: For debugging + { + char temp[128],buffer[256]; + int i; + memset( StateTable, 0, sizeof( StateTable ) ); + + for ( i = 0; i < ConnectLen; i++ ){ + if ( Connect[ i ].use == TRUE ){ + if(Connect[ i ].state > WHILESAVEWAIT)continue; + StateTable[ Connect[ i ].state ] ++; + } + } + + buffer[ 0 ] = 0; + + for ( i = 0; i <= WHILESAVEWAIT; i++ ) { + sprintf( temp, "%-6d", StateTable[ i ] ); + strcat( buffer, temp ); + } +// print( "\nFILE:%s,LINE:%d", file,fromline ); +// print( "\n{{%s}}", buffer ); + } + // Nuke end + + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD int CONNECT_getState( int fd ) +{ + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].state; + CONNECT_UNLOCK( fd ); + return a; +} + +ANYTHREAD void CONNECT_setCharaindex( int fd, int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].charaindex = a; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getCharaindex( int fd ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].charaindex; + CONNECT_UNLOCK( fd ); + return a; +} +ANYTHREAD void CONNECT_getCdkey( int fd , char *out, int outlen ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( out, outlen, Connect[ fd ].cdkey ); + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD void CONNECT_setCdkey( int fd, char *cd ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + snprintf( Connect[ fd ].cdkey, sizeof( Connect[ fd ].cdkey ), "%s", cd ); + CONNECT_UNLOCK( fd ); +} + +#ifdef _NEWCLISETSERVID +ANYTHREAD void CONNECT_setServid( int fd, int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].servid = a; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getServid( int fd ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].servid; + CONNECT_UNLOCK( fd ); + return a; +} +#endif + +#ifdef _NEWCLISETMAC +ANYTHREAD void CONNECT_getMAC( int fd , char *out, int outlen ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( out, outlen, Connect[ fd ].mac ); + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD void CONNECT_setMAC( int fd, char *in ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( Connect[ fd ].mac, sizeof( Connect[ fd ].mac ), in ); + CONNECT_UNLOCK( fd ); +} +#endif + +ANYTHREAD void CONNECT_getPasswd( int fd , char *out, int outlen ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( out, outlen, Connect[ fd ].passwd ); + CONNECT_UNLOCK( fd ); +} +ANYTHREAD void CONNECT_setPasswd( int fd, char *in ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( Connect[ fd ].passwd, sizeof( Connect[ fd ].passwd ), in ); + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getCtype( int fd ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].ctype; + CONNECT_UNLOCK( fd ); + return a; +} +ANYTHREAD void CONNECT_setCtype( int fd , int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].ctype = a; + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD void CONNECT_getCharname( int fd , char *out, int outlen ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( out, outlen, Connect[ fd ].charname ); + CONNECT_UNLOCK( fd ); +} +ANYTHREAD void CONNECT_setCharname( int fd, char *in ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + strcpysafe( Connect[ fd ].charname, sizeof( Connect[ fd ].charname ), + in ); + CONNECT_UNLOCK( fd ); +} + +ANYTHREAD int CONNECT_getFdid( int fd ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].fdid; + CONNECT_UNLOCK( fd ); + return a; +} +ANYTHREAD void CONNECT_setDuelcharaindex( int fd, int i , int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].duelcharaindex[ i ] = a; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getDuelcharaindex( int fd, int i ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].duelcharaindex[ i ]; + CONNECT_UNLOCK( fd ); + return a; +} +ANYTHREAD void CONNECT_setBattlecharaindex( int fd, int i , int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].battlecharaindex[ i ] = a; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getBattlecharaindex( int fd, int i ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + a = Connect[ fd ].battlecharaindex[ i ]; + CONNECT_UNLOCK( fd ); + return a; +} +ANYTHREAD void CONNECT_setJoinpartycharaindex( int fd, int i , int a) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].joinpartycharaindex[ i ] = a; + CONNECT_UNLOCK( fd ); +} +ANYTHREAD int CONNECT_getJoinpartycharaindex( int fd, int i ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK( fd ); + + a = Connect[ fd ].joinpartycharaindex[ i ]; + CONNECT_UNLOCK( fd ); + return a; +} + +// CoolFish: Trade 2001/4/18 +ANYTHREAD void CONNECT_setTradecharaindex( int fd, int i , int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK( fd ); + Connect[ fd ].tradecharaindex[ i ] = a; + CONNECT_UNLOCK( fd ); +} + +// Shan Begin +ANYTHREAD void CONNECT_setLastrecvtime( int fd, struct timeval *a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + Connect[fd].lastrecvtime = *a; + CONNECT_UNLOCK(fd); +} +ANYTHREAD void CONNECT_getLastrecvtime( int fd, struct timeval *a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + *a = Connect[fd].lastrecvtime; + CONNECT_UNLOCK(fd); +} + +ANYTHREAD void CONNECT_setLastrecvtime_D( int fd, struct timeval *a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + Connect[fd].lastrecvtime_d = *a; + CONNECT_UNLOCK(fd); +} +ANYTHREAD void CONNECT_getLastrecvtime_D( int fd, struct timeval *a ) +{ + CONNECT_LOCK(fd); + *a = Connect[fd].lastrecvtime_d; + CONNECT_UNLOCK(fd); +} + +// 2001/12/26 +ANYTHREAD void CONNECT_SetBattleRecvTime( int fd, struct timeval *a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + Connect[fd].battle_recvtime = *a; + CONNECT_UNLOCK(fd); +} +ANYTHREAD void CONNECT_GetBattleRecvTime( int fd, struct timeval *a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + *a = Connect[fd].battle_recvtime; + CONNECT_UNLOCK(fd); +} +// Shan End + +#ifdef _ITEM_PILEFORTRADE +ANYTHREAD void CONNECT_setTradeList( int fd, int num) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[fd].tradelist = num; +} +ANYTHREAD int CONNECT_getTradeList(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[fd].tradelist; +} +#endif + +ANYTHREAD void CONNECT_setTradeTmp(int fd, char* a) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + strcpysafe( Connect[fd].TradeTmp, sizeof(Connect[fd].TradeTmp), a); + + CONNECT_UNLOCK(fd); +} +ANYTHREAD void CONNECT_getTradeTmp(int fd, char *trademsg, int trademsglen) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + strcpysafe(trademsg, trademsglen, Connect[fd].TradeTmp); + CONNECT_UNLOCK(fd); +} + +ANYTHREAD void CONNECT_setTradecardcharaindex( int fd, int i , int a ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + CONNECT_LOCK(fd); + Connect[fd].joinpartycharaindex[i] = a; + CONNECT_UNLOCK(fd); +} +ANYTHREAD int CONNECT_getTradecardcharaindex( int fd, int i ) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int a; + CONNECT_LOCK(fd); + a = Connect[fd].joinpartycharaindex[i]; + CONNECT_UNLOCK(fd); + return a; +} + +ANYTHREAD void CONNECT_setCloseRequest( int fd, int count) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } +// print("\nرΪ FILE:%s,LINE:%d ", file, line); + CONNECT_LOCK(fd); + Connect[fd].close_request = count; + // Nuke +// print("\nرΪ %d ",fd); + CONNECT_UNLOCK(fd); +} + + +/*------------------------------------------------------------ + * CAcheck ʤɤ˻Ȥؿºݤ롣 + * + * fd int եǥץ + * ֤ + * ʤ + ------------------------------------------------------------*/ +ANYTHREAD void CAsend( int fd ) +{ + char buf[sizeof(Connect[0].CAbuf)]; + int bufuse=0; + + if( CONNECT_getCAbuf( fd, buf, sizeof(buf), &bufuse ) < 0 )return; + if( bufuse == 0 )return; + + //print("\nshan--->(CAsend)->%s fd->%d", buf, fd); + + /*ǸΥǥߥ ',' '\0' Ȥ*/ + buf[bufuse-1] = '\0'; + lssproto_CA_send( fd , buf ); + + CONNECT_setCAbufsiz( fd, 0 ); +} + + +/*------------------------------------------------------------ + * CA롣 + * + * ֤ + * ʤ + ------------------------------------------------------------*/ +ANYTHREAD void CAcheck( void ) +{ + int i; +#ifdef _SYSTEM_SPEAD + unsigned int interval_us = getCAsendinterval_ms()*200; +#else + unsigned int interval_us = getCAsendinterval_ms()*1000; +#endif + + /* Connectз֧¾պϷئ */ + for( i = 0; i < ConnectLen; i ++) { + struct timeval t; + if( !CONNECT_getUse_debug(i,1008) )continue; + CONNECT_getLastCAsendtime( i, &t ); + if( time_diff_us( NowTime, t ) > interval_us ){ + CAsend( i); + CONNECT_setLastCAsendtime( i, &NowTime ); + } + } +} +ANYTHREAD void CAflush( int charaindex ) +{ + int i; + i = getfdFromCharaIndex( charaindex); + if( i == -1 )return; + CAsend(i); +} + + +/*------------------------------------------------------------ + * CDbuf ɲä롣 + * + * fd int եǥץ + * data char* ǡ + * size int ǡΥ + * ֤ + * TRUE(1) + * FALSE(0) + ------------------------------------------------------------*/ +ANYTHREAD BOOL CONNECT_appendCDbuf( int fd , char* data, int size ) +{ + CONNECT_LOCK(fd); + + if( ( Connect[fd].CDbufsiz + size ) >= sizeof( Connect[fd].CDbuf )){ + CONNECT_UNLOCK(fd); + return FALSE; + } + memcpy( Connect[fd].CDbuf + Connect[fd].CDbufsiz , data, size ); + Connect[fd].CDbuf[Connect[fd].CDbufsiz+size] = ','; + Connect[fd].CDbufsiz += ( size + 1 ); + CONNECT_UNLOCK(fd); +#ifdef _EPOLL + //ModEpollOut(fd); +#endif + return TRUE; +} + + +/*------------------------------------------------------------ + * CDcheck ʤɤ˻Ȥؿºݤ롣 + * + * fd int եǥץ + * ֤ + * ʤ + ------------------------------------------------------------*/ +ANYTHREAD void CDsend( int fd ) +{ + char buf[sizeof(Connect[0].CAbuf )]; + int bufuse=0; + if( CONNECT_getCDbuf( fd, buf, sizeof(buf), &bufuse ) < 0 ) return; + if( bufuse == 0 ) return; + buf[bufuse-1] = '\0'; + lssproto_CD_send(fd, buf ); + CONNECT_setCDbufsiz(fd,0); +} + + +/*------------------------------------------------------------ + * CD롣 + * + * ֤ + * ʤ + ------------------------------------------------------------*/ +ANYTHREAD void CDcheck( void ) +{ + int i; + unsigned int interval_us = getCDsendinterval_ms()*1000; + for(i=0; i interval_us ){ + CDsend( i); + CONNECT_setLastCDsendtime( i , &NowTime ); + } + } +} + +ANYTHREAD void CDflush( int charaindex ) +{ + int i; + i = getfdFromCharaIndex( charaindex); + if( i == -1 )return; + CDsend(i); +} + +void chardatasavecheck( void ) +{ + int i; + int interval = getCharSavesendinterval(); + static struct timeval chardatasavecheck_store; + if( NowTime.tv_sec > (chardatasavecheck_store.tv_sec +10)){ + chardatasavecheck_store = NowTime; + + +#ifdef _FIX_SAVE_CHAR + for(i=0;i interval){ + CHAR_charSaveFromConnect( i, FALSE ); + CHAR_setWorkInt( i, CHAR_WORK_SAVE_CHAR, tv_sec); + } + } + } +#else + for( i = 0; i < ConnectLen; i ++) { + CONNECT_LOCK(i); + if( Connect[i].use == TRUE + && Connect[i].state == LOGIN + && NowTime.tv_sec - Connect[i].lastCharSaveTime.tv_sec + > interval ){ + Connect[i].lastCharSaveTime = NowTime; + CONNECT_UNLOCK(i); + CHAR_charSaveFromConnect( CONNECT_getCharaindex( i ), FALSE ); + } else { + CONNECT_UNLOCK(i); + } + } +#endif + } else { + ; + } +} + +/*------------------------------------------------------------ + * fd valid ئּëƩ + * ¦ + * fd int fd + * ߯Ի + * valid TRUE(1) + * invalid FALSE(0) + ------------------------------------------------------------*/ +ANYTHREAD INLINE int CONNECT_checkfd( int fd ) +{ + if( 0 > fd || fd >= ConnectLen ){ + return FALSE; + } + CONNECT_LOCK(fd); + if( Connect[fd].use == FALSE ){ + CONNECT_UNLOCK(fd); + return FALSE; + } else { + CONNECT_UNLOCK(fd); + return TRUE; + } +} + + +/*------------------------------------------------------------ + * cdkey fd 롣 + * + * cd char* cdkey + * ֤ + * եǥץ äơ -1 λϥ顼 + ------------------------------------------------------------*/ +ANYTHREAD int getfdFromCdkey( char* cd ) +{ + int i; + for( i = 0 ;i < ConnectLen ; i ++ ){ + CONNECT_LOCK(i); + if( Connect[i].use == TRUE && + strcmp( Connect[i].cdkey , cd ) == 0 ){ + CONNECT_UNLOCK(i); + return i; + } + CONNECT_UNLOCK(i); + } + return -1; +} + + +/*------------------------------------------------------------ + * charaindex fd ë £ + * ½ ëף + * ¦ + * charaindex int ƽҷ¼̼͵ + * ߯Ի + * ̻ﷸū Ȼ -1 ݷ޷¡ + ------------------------------------------------------------*/ +ANYTHREAD int getfdFromCharaIndex( int charaindex ) +{ +#if 1 + int ret; + if( !CHAR_CHECKINDEX( charaindex)) return -1; + if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return -1; + ret = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + if( ret < 0 || ret >= ConnectLen ) return -1; + return ret; +#else + int i; + for( i = 0 ;i < ConnectLen ; i ++ ){ + CONNECT_LOCK(i); + if( Connect[i].use == TRUE + && Connect[i].charaindex == charaindex ){ + CONNECT_UNLOCK(i); + return i; + } + CONNECT_UNLOCK(i); + } + return -1; +#endif +} +/*------------------------------------------------------------ + * charaindex cdkey ë £ + * ¦ + * charaindex int ƽҷ¼̼͵ + * ߯Ի + * 0ئ ئ + ------------------------------------------------------------*/ +ANYTHREAD int getcdkeyFromCharaIndex( int charaindex , char *out, int outlen ) +{ + int i; + + for( i = 0 ;i < ConnectLen ; i ++ ){ + CONNECT_LOCK(i); + if( Connect[i].use == TRUE + && Connect[i].charaindex == charaindex ){ + snprintf( out, outlen, "%s" , Connect[i].cdkey ); + CONNECT_UNLOCK(i); + return 0; + } + CONNECT_UNLOCK(i); + } + return -1; +} + + +/*------------------------------------------------------------ + * Ʊfdid ۤõ + * + * fdid int fdid + * ֤ + * -1 ݷ޷¡ + ------------------------------------------------------------*/ +ANYTHREAD int getfdFromFdid( int fdid ) +{ + int i; + + for( i=0; i= 0 ){ + int a = Connect[i].charaindex; + CONNECT_UNLOCK(i); + return a; + } + CONNECT_UNLOCK(i); + } + + return -1; +} +/*------------------------------------------------------------ + * index fdid Ȥ롣 + * + * charind int եǥץ + * fdid ä饭ind + ------------------------------------------------------------*/ +ANYTHREAD int getFdidFromCharaIndex( int charind ) +{ + int i; + + for( i=0; i 10000 ) chikulatime = 0; +#ifdef _MO_RELOAD_NPC + if( getReloadNpcTime() > 0){ + if ( chikulatime % getReloadNpcTime() == 0 ) { + NPC_reloadNPC(); + MAPPOINT_resetMapWarpPoint(1); + MAPPOINT_loadMapWarpPoint(); + } + } +#endif +#ifdef _LUCK_STAR + if(getLuckStarTime()>0){ + if ( chikulatime % getLuckStarTime() == 0 ) { // ÿСʱ + LuckStar(); + } + } +#endif + int playernum = CHAR_getPlayerMaxNum(); + int charaindex; + for ( charaindex = 0;charaindex < playernum; charaindex++ ) { + if( !CHAR_CHECKINDEX(charaindex) )continue; +#ifdef _CANCEL_STREET_VENDOR + char token[256]; + if(CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR) == 3){ + if(CHAR_getWorkInt(charaindex,CHAR_WORK_STREET_VENDOR_TIME) < time( NULL) - 90){ + int toindex = CHAR_getWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO); + // 趨Ϊ̯,״̬ + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR,-1); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR,1); + // ͼʾ + CHAR_sendTradeEffect(charaindex,0); + CHAR_sendTradeEffect(toindex,0); + CHAR_setWorkInt(toindex,CHAR_WORKSTREETVENDOR_WHO,-1); + CHAR_setWorkInt(charaindex,CHAR_WORKSTREETVENDOR_WHO,-1); + lssproto_STREET_VENDOR_send(charaindex,"C|"); + CHAR_talkToCli(charaindex,-1,"鿴̯ʱ,ԶȡIJ鿴",CHAR_COLORYELLOW); + } + } +#endif + if ( chikulatime % 6 == 0 ) { // ÿ60 + +#ifdef _PETSKILL_BECOMEPIG + if ( CHAR_getInt( charaindex, CHAR_BECOMEPIG ) > -1 ) { //״̬ + + if ( ( CHAR_getInt( charaindex, CHAR_BECOMEPIG ) - 1 ) <= 0 ) { //ʱ + CHAR_setInt( charaindex, CHAR_BECOMEPIG, 0 ); + + if ( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { //ս״̬ + CHAR_setInt( charaindex, CHAR_BECOMEPIG, -1 ); //״̬ + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX ) ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER ); + CHAR_talkToCli( charaindex, -1, "ʧЧˡ", CHAR_COLORWHITE ); + } + } + else { + CHAR_setInt( charaindex, CHAR_BECOMEPIG, CHAR_getInt( charaindex, CHAR_BECOMEPIG ) - 10 ); + } + } +#endif + +#ifdef _SPECIAL_MAP + int floor = CHAR_getInt( charaindex, CHAR_FLOOR); + int x; + for(x=0;x<32;x++){ + if(floor == getSpecialMap(x)){ + break; + } + } + if(x<32) +#endif + { +#ifdef _BOUND_TIME + if(CHAR_getInt(charaindex,CHAR_BOUNDTIME) <= NowTimes ) { + int fl = 0, x = 0, y = 0; + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), &fl, &x, &y); + CHAR_warpToSpecificPoint(charaindex, fl, x, y); + + CHAR_talkToCli( charaindex, -1, "Ȩʱѵ԰ͻؼ¼㣡", CHAR_COLORYELLOW ); + } +#endif + } + } + + if ( chikulatime % 30 == 0 ) { // ÿ300 + +#ifdef _ITEM_ADDEXP //vincent +#ifdef _PET_ADD_EXP + if ( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + int exptime; + if ( CHAR_getWorkInt(charaindex, CHAR_WORKITEM_ADDEXP ) > 0 ){ + exptime = CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME ) - 300; + + if ( exptime <= 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXP, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, 0 ); + CHAR_talkToCli( charaindex,-1,"ѧϰʧ!",CHAR_COLORYELLOW); + } else { + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, exptime ); + //print("\n ADDEXPTIME %d ", exptime); + + if ( ( exptime % ( 60 * 60 ) ) < 300 && exptime >= ( 60 * 60 ) ) { + char msg[ 1024 ]; + sprintf( msg, "ѧϰʣԼ %d Сʱ", (int)(exptime/(60*60)) ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW ); + } + } + } + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int petindex = CHAR_getCharPet( charaindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + if ( CHAR_getWorkInt(petindex, CHAR_WORKITEM_ADDEXP ) > 0 ){ + exptime = CHAR_getWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME ) - 300; + + if ( exptime <= 0 ) { + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXP, 0 ); + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME, 0 ); + CHAR_talkToCli( charaindex,-1,"ѧϰʧ!",CHAR_COLORYELLOW); + } else { + CHAR_setWorkInt( petindex, CHAR_WORKITEM_ADDEXPTIME, exptime ); + //print("\n ADDEXPTIME %d ", exptime); + + if ( ( exptime % ( 60 * 60 ) ) < 300 && exptime >= ( 60 * 60 ) ) { + char msg[ 1024 ]; + sprintf( msg, "%sѧϰʣԼ %d Сʱ", CHAR_getChar( petindex, CHAR_NAME), (int)(exptime/(60*60)) ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW ); + } + } + } + } + } +#else + if ( CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXP ) > 0 && + CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) { + int exptime; + exptime = CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME ) - 300; + + if ( exptime <= 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXP, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, 0 ); + CHAR_talkToCli( charaindex,-1,"ѧϰʧ!",CHAR_COLORYELLOW); + } + else { + CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, exptime ); + //print("\n ADDEXPTIME %d ", exptime); + + if ( ( exptime % ( 60 * 60 ) ) < 300 && exptime >= ( 60 * 60 ) ) { + char msg[ 1024 ]; + sprintf( msg, "ѧϰʣԼ %d Сʱ", (int)(exptime/(60*60)) ); + //sprintf( msg, "ѧϰʣԼ %d ֡", (int)(exptime/(60)) ); + CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW ); + } + } + CHAR_setInt( charaindex, CHAR_ADDEXPPOWER, + CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXP) ); + CHAR_setInt( charaindex, CHAR_ADDEXPTIME, + CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME) ); + } +#endif + +#endif +#ifdef _ITEM_METAMO + if ( CHAR_getWorkInt( charaindex, CHAR_WORKITEMMETAMO ) < NowTime.tv_sec + && CHAR_getWorkInt( charaindex, CHAR_WORKITEMMETAMO ) != 0 ) { + CHAR_setWorkInt( charaindex, CHAR_WORKITEMMETAMO, 0 ); + CHAR_setWorkInt( charaindex, CHAR_WORKNPCMETAMO, 0 ); //npcԻıҲҪ + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX ) ); + CHAR_send_P_StatusString( charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER ); + CHAR_talkToCli( charaindex, -1, "ʧЧˡ", CHAR_COLORWHITE ); + } + +#endif +#ifdef _ITEM_TIME_LIMIT + ITEM_TimeLimit( charaindex ); // (ɿ) shan time limit of item. code:shan + +#endif + + } //%30 + +#ifdef _PETSKILL_BECOMEPIG + if ( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { //ս״̬ + + if ( CHAR_getInt( charaindex, CHAR_BECOMEPIG ) > -1 ) { //״̬ + char temp[ 256 ]; + CHAR_setInt( charaindex, CHAR_BECOMEPIG, CHAR_getInt( charaindex, CHAR_BECOMEPIG ) - 1 ); + sprintf( temp, "ʱ:%d", CHAR_getInt( charaindex, CHAR_BECOMEPIG ) ); + CHAR_talkToCli( charaindex, -1, temp, CHAR_COLORWHITE ); + } + } + +#endif + //10 +#ifdef _MAP_TIME + if ( CHAR_getWorkInt( charaindex, CHAR_WORK_MAP_TIME ) > 0 + && CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { + CHAR_setWorkInt( charaindex, CHAR_WORK_MAP_TIME, CHAR_getWorkInt( charaindex, CHAR_WORK_MAP_TIME ) - 10 ); + + if ( CHAR_getWorkInt( charaindex, CHAR_WORK_MAP_TIME ) <= 0 ) { + // ʱ䵽, + CHAR_talkToCli( charaindex, -1, "Ϊܲ˸ȶѷڡ", CHAR_COLORRED ); + CHAR_warpToSpecificPoint( charaindex, 30008, 39, 38 ); + CHAR_setInt( charaindex, CHAR_HP, 1 ); + CHAR_AddCharm( charaindex, -3 ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_HP ); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_CHARM ); + } + else { + char szMsg[ 64 ]; + sprintf( szMsg, "ȵĻֻٴ %d 롣", CHAR_getWorkInt( charaindex, CHAR_WORK_MAP_TIME ) ); + CHAR_talkToCli( charaindex, -1, szMsg, CHAR_COLORRED ); + } + } +#endif + } + + for ( i = 0;i < ConnectLen; i++ ) { +#ifdef _OTHER_SAAC_LINK + if ( ( Connect[ i ].use ) && ( CONNECT_getCtype(i) != AC )) +#else + if ( ( Connect[ i ].use ) && ( i != acfd )) +#endif + if(!CONNECT_getUse(i))continue; + if( !CHAR_CHECKINDEX(Connect[ i ].charaindex) )continue; + + { +#ifdef _NEW_AUTO_PK +{ + if(getAutoPkTime()>-1){ + if(getBAward()==FALSE){ + struct tm *p; + time_t timep; + time(&timep); + p=localtime(&timep); /*ȡõʱ*/ + + if(getBAward() == FALSE){ + if((getAutoPkTime() == p->tm_hour) && (p->tm_min == 0)){ + AutoPk_PKTimeSet(15); + AutoPk_GetAwardStr(); + } + } + } + } +} +#endif + +#ifndef _USER_CHARLOOPS + //here ԭ + if ( Connect[ i ].stayencount ) { + if ( Connect[ i ].BDTime < time( NULL ) ) { + if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { + lssproto_EN_recv( i, CHAR_getInt( Connect[ i ].charaindex, CHAR_X ), + CHAR_getInt( Connect[ i ].charaindex, CHAR_Y ) ); + Connect[ i ].BDTime = time( NULL ); + } + } + } + +#endif +#ifdef _CHIKULA_STONE + if ( chikulatime % 3 == 0 && getChiStone( i ) > 0 ) { //ԶѪ + CHAR_AutoChikulaStone( Connect[ i ].charaindex, getChiStone( i ) ); + } + +#endif + + if ( chikulatime % 6 == 0 ) { //ˮ״̬ + + +#ifdef _STATUS_WATERWORD + CHAR_CheckWaterStatus( Connect[ i ].charaindex ); +#endif + // Nuke 0626: No enemy + + if ( Connect[ i ].noenemy > 0 ) { + Connect[ i ].noenemy--; + + if ( Connect[ i ].noenemy == 0 ) { + CHAR_talkToCli( CONNECT_getCharaindex( i ), -1, "ػʧˡ", CHAR_COLORWHITE ); + } + } + } + + //ÿ10 +#ifdef _TYPE_TOXICATION //ж + if ( Connect[ i ].toxication > 0 ) { + CHAR_ComToxicationHp( Connect[ i ].charaindex ); + } + +#endif + // Nuke 0624 Avoid Useless Connection + if ( Connect[ i ].state == NOTLOGIN ) { + Connect[ i ].cotime++; + + if ( Connect[ i ].cotime > 30 ) { + print( "LATE" ); +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CONNECT_getCharaindex( i ),charname,32); + CONNECT_getCdkey(CONNECT_getCharaindex( i ),cdkey,16); + char token[128]; + sprintf(token, "ûе½ϷT "); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + + CONNECT_endOne_debug( i ); + } + }else{ + Connect[ i ].cotime = 0; + } + + if ( ( Connect[ i ].nu <= 22 ) ) { + + if ( Connect[ i ].nu <= 0 ) { + Connect[ i ].nu_decrease++; + + if ( Connect[ i ].nu_decrease >= 30 ) + Connect[ i ].nu_decrease = 30; + + if ( Connect[ i ].nu_decrease > 22 ) logSpeed( i ); + } + else { + Connect[ i ].nu_decrease -= 1; + + if ( Connect[ i ].nu_decrease < 0 ) + Connect[ i ].nu_decrease = 0; + } + lssproto_NU_send( i, 0 ); +/* + r = 22 - Connect[ i ].nu_decrease; + r = ( r >= 15 ) ? r : 15; + lssproto_NU_send( i, r ); + Connect[ i ].nu += r; +*/ + } + + } + + + } + } +} + +// Nuke 0126: Resource protection +int isThereThisIP(unsigned long ip) +{ + int i; + unsigned long ipa; + + for ( i = 0; i < ConnectLen ; i++ ) + if ( !Connect[ i ].use ) continue; + + if ( Connect[ i ].state == NOTLOGIN || Connect[ i ].state == WHILEDOWNLOADCHARLIST ) { + memcpy( &ipa, &Connect[ i ].sin.sin_addr, 4 ); + + if ( ipa == ip ) return 1; + } + + return 0; +} + +int player_online = 0; +int player_maxonline = 0; + +#ifdef _KEEP_UP_NO_LOGIN +char keepupnologin[256] = ""; +#endif +struct timeval speedst, speedet; +SINGLETHREAD BOOL netloop_faster( void ) +{ + static unsigned int total_item_use=0; + static int petcnt=0; + struct timeval st, et; + unsigned int looptime_us; + looptime_us = getOnelooptime_ms()*1000 ; + + + int ret , loop_num; + struct timeval tmv; /*timeval*/ + static int fdremember = 0; + int acceptmore = SERVSTATE_getAcceptmore(); + +// static unsigned int nu_time=0; + unsigned int casend_interval_us , cdsend_interval_us; + fd_set rfds, wfds , efds; + int allowerrornum = getAllowerrornum(); + int acwritesize = getAcwriteSize(); + +#ifdef _AC_PIORITY + static int flag_ac=1; + static int fdremembercopy=0; + static int totalloop=0; + static int totalfd=0; + static int totalacfd=0; + static int counter=0; +#endif + +#ifdef _SYSTEM_SPEAD + casend_interval_us = getCAsendinterval_ms() * 200; + cdsend_interval_us = getCDsendinterval_ms() * 200; +#else + casend_interval_us = getCAsendinterval_ms()*1000; + cdsend_interval_us = getCDsendinterval_ms()*1000; +#endif + FD_ZERO( & rfds ); + FD_ZERO( & wfds ); + FD_ZERO( & efds ); + FD_SET( bindedfd , & rfds ); + FD_SET( bindedfd , & wfds ); + FD_SET( bindedfd , & efds ); + tmv.tv_sec = tmv.tv_usec = 0; + ret = select( bindedfd + 1 , &rfds,&wfds,&efds,&tmv ); + if( ret < 0 && ( errno != EINTR )){ + ; + } + if( ret > 0 && FD_ISSET(bindedfd , &rfds ) ){ + struct sockaddr_in sin; + int addrlen=sizeof( struct sockaddr_in ); + int sockfd; + + sockfd = accept( bindedfd ,(struct sockaddr*) &sin , &addrlen ); + + SetTcpBuf(sockfd, &rfds); + + if( sockfd == -1 && errno == EINTR ){ + print( "accept err:%s\n", strerror(errno)); + }else if(sockfd > 1000){ + print( "sockfd:%d\n", sockfd); + close(sockfd); + }else if( sockfd != -1 ){ + unsigned long sinip; + int cono=1, from_acsv = 0; + if (cono_check&CONO_CHECK_LOGIN){ + if( StateTable[WHILELOGIN]+StateTable[WHILELOGOUTSAVE] > QUEUE_LENGTH1 || + StateTable[WHILEDOWNLOADCHARLIST] > QUEUE_LENGTH2 ){ + print("err State[%d,%d,%d]!!\n", StateTable[WHILELOGIN], + StateTable[WHILELOGOUTSAVE], + StateTable[WHILEDOWNLOADCHARLIST] ); + + CONNECT_checkStatecount( WHILEDOWNLOADCHARLIST); + cono=0; + } + } + if (cono_check&CONO_CHECK_ITEM) + if (total_item_use >= MAX_item_use){ + print("ʹƷ!!"); + cono=0; + } + if (cono_check&CONO_CHECK_PET) + if( petcnt >= CHAR_getPetMaxNum() ){ + print("ʹó!!"); + cono=0; + } + + //print("CO"); + + { + float fs=0.0; + if( (fs = ((float)Connect[acfd].rbuse/AC_RBSIZE) ) > 0.6 ){ + print( "andy AC rbuse: %3.2f [%4d]\n", fs, Connect[acfd].rbuse ); + if( fs > 0.78 ) cono = 0; + } + } + + memcpy( &sinip, &sin.sin_addr, 4); + // Nuke *1 0126: Resource protection + + if((cono == 0) || (acceptmore <= 0) || isThereThisIP( sinip) ){ + // Nuke +2 Errormessage + char mess[64]="EŷæУԺԡ"; + if (!from_acsv) + write(sockfd,mess,strlen(mess)+1); + print( "accept but drop[cono:%d,acceptmore:%d]\n", cono, acceptmore); + close(sockfd); + } +#ifdef _SAME_IP_ONLINE_NUM + else if(SameIpOnlineNum(sinip) == 1){ + char mess[64]; + sprintf(mess, "EIP%dˣ½ԾάϷƽ⣡\n", getSameIpOnlineNum()); + write(sockfd,mess,strlen(mess)+1); + close(sockfd); + } +#endif +#ifdef _KEEP_UP_NO_LOGIN + else if(strlen(keepupnologin) > 0){ + char mess[64]; + sprintf(mess, "E%s", keepupnologin); + write(sockfd,mess,strlen(mess)+1); + close(sockfd); + } +#endif + else if( sockfd < ConnectLen ){ + char mess[64] = "A";// Nuke +2 Errormessage + if( bNewServer ){ + mess[0]=_SA_VERSION; // 7.0 + + }else + mess[0]='$'; + + //char mess[1024]="EŷæУԺԡ"; + if (!from_acsv){ +#ifdef _NO_FULLPLAYER_ATT + if(sockfd-player_online>=getNoFullPlayer()){ + time_t curtime; + struct tm *p; + time(&curtime); + p=localtime(&curtime); + curtime = mktime(p); + if(curtime-atttime>getNoFullTime()){ + atttime = curtime; + int j,ipa,ipb,ipc,ipd; + char ip[32]; + char systemstr[256]; + unsigned long tmpip; + for(j=12;j= looptime_us ) //ִÿ0.1ҪĵĹ + { +#define LOOP_NUM_ADD_CREDIT 5 +#define CREDIT_SPOOL 3 + + switch ( acceptmore ) { + case - 1: + print( "#" ); + break; + case 0: + print( "$" ); + + if ( !b_first_shutdown ) { + b_first_shutdown = TRUE; + i_shutdown_time = SERVSTATE_getLimittime(); + print("\n رշʱ=%d",i_shutdown_time); + } + break; + default: + { + static int i_counter=0; + // Syu ADD ʱȡAnnounce + static int j_counter=0; + // Syu ADD ÿСʱ¸Ӣսа + static int h_counter=0; + // ļʱ + static long total_count=0; + + +#ifdef _AUTO_PK + static int h_autopk=0; +#endif + +#ifdef _LOOP_ANNOUNCE + static int loop_counter=0; +#endif + + int i; + int item_max; + + if ( i_counter > 10 ) { //10 + player_online = 0; //looptime_us +#ifdef _AC_PIORITY + totalloop = 0; totalfd = 0; totalacfd = 0; +#endif + i_counter = 0; + item_max = ITEM_getITEM_itemnum(); + total_item_use = ITEM_getITEM_UseItemnum(); + for ( i = 0;i < ConnectLen; i++ ) { + if ( ( Connect[ i ].use ) && ( i != acfd )) { + if ( CHAR_CHECKINDEX( Connect[ i ].charaindex ) ) + player_online++; + } + } + if(player_online>player_maxonline){ + player_maxonline=player_online; + } + { + int max, min; + char buff1[ 512 ]; + char szBuff1[ 256 ]; +#ifdef _ASSESS_SYSEFFICACY + { + float TVsec; + ASSESS_getSysEfficacy( &TVsec); + sprintf( szBuff1, "Sys:[%2.4f] \n", TVsec); + } +#endif + + memset( buff1, 0, sizeof( buff1)); + CHAR_getCharOnArrayPercentage( 1, &max, &min, &petcnt); +/* + sprintf( buff1,"\n=%d =%d Ʒ=%d ʼ:%d ս:%d %s", + player_online, petcnt,total_item_use, + PETMAIL_getPetMailTotalnums(), + Battle_getTotalBattleNum(), szBuff1 ); + */ + sprintf( buff1,"\n=%d =%d =%d Ʒ=%d ʼ:%d ս:%d %s", + player_online,luaplayernum, petcnt,total_item_use, + PETMAIL_getPetMailTotalnums(), + Battle_getTotalBattleNum(), szBuff1 ); + + + buff1[ strlen( buff1)+1] = 0; + print("%s", buff1); + + gettimeofday( &speedet, NULL ); + float speedtime = time_diff_us(speedet,speedst) / 1000000.0; + sprintf( buff1, "ϴ:[%2.3f K]ƽ[%2.3f K]" + ":[%2.3f K]ƽ[%2.3f K]" + "ʱ%2.3f\n" + , sendspeed / 1024.0, sendspeed / speedtime / 1024.0 + , recvspeed / 1024.0, recvspeed / speedtime / 1024.0 + , speedtime); + gettimeofday( &speedst, NULL ); + sendspeed = 0; + recvspeed = 0; + + buff1[ strlen( buff1)+1] = 0; + print("%s", buff1); + +#ifdef _ASSESS_SYSEFFICACY_SUB + { + float TVsec; + ASSESS_getSysEfficacy_sub( &TVsec, 1); + sprintf( szBuff1, "NT:[%2.4f] ", TVsec); + strcpy( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 2); + sprintf( szBuff1, "NG:[%2.4f] ", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 3); + sprintf( szBuff1, "BT:[%2.4f] ", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 4); + sprintf( szBuff1, "CH:[%2.4f] \n", TVsec); + strcat( buff1, szBuff1); +/* + ASSESS_getSysEfficacy_sub( &TVsec, 5); + sprintf( szBuff1, "PM:[%2.4f] \n", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 6); + sprintf( szBuff1, "FM:[%2.4f] ", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 7); + sprintf( szBuff1, "SV:[%2.4f] ", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 9); + sprintf( szBuff1, "AG:[%2.4f] ", TVsec); + strcat( buff1, szBuff1); + + ASSESS_getSysEfficacy_sub( &TVsec, 10); + sprintf( szBuff1, "CE:[%2.4f] \n", TVsec); + strcat( buff1, szBuff1); +*/ + + buff1[ strlen( buff1)+1] = 0; + print("%s.", buff1); + } +#endif + } +#ifdef _TIME_TICKET + check_TimeTicket(); +#endif + + } +#ifdef _LOOP_ANNOUNCE + if ( loop_counter > 60*getLoopAnnounceTime() && getLoopAnnounceMax()>0) + { + int i; + int playernum = CHAR_getPlayerMaxNum(); + static int index; + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + char buff[36]; + snprintf( buff, sizeof( buff),"%s档",getGameservername()); + CHAR_talkToCli( i, -1, buff, CHAR_COLORYELLOW); + CHAR_talkToCli( i, -1, getLoopAnnounce(index % getLoopAnnounceMax()), CHAR_COLORYELLOW); + } + } + index++; + loop_counter=0; + } +#endif + +#ifdef _AUTO_PK + if(AutoPk_PKTimeGet()>-1){ + if ( h_autopk > 60 ) + { + h_autopk=0; + AutoPk_PKSystemInfo(); + } + } +#endif + + // Syu ADD ʱȡAnnounce + if ( j_counter > 60*60 ) + {//6000 Լ 600=10 + j_counter=0; + print("\nʱȡ"); + LoadAnnounce(); + } + + /* + #ifdef _ALLDOMAN // Syu ADD аNPC + // Syu ADD ÿСʱ¸Ӣսа + if ( h_counter > 60*60 ){//36000 Լ 3600=60 + h_counter=0; + print("\nSyu log LoadHerolist"); + saacproto_UpdataStele_send ( acfd , "FirstLoad", "LoadHerolist" , "" , 0 , 0 , 0 , 999 ) ; + } + #endif + */ + if ( i_timeNu != time( NULL ) ) // ÿִһ + { + i_timeNu = time( NULL ); +#ifdef _PLAYER_DIY_MAP + if( total_count % 60 == 0 ) { //ÿִ + int i; + for(i=0;i0){ + int playernum=0; + int j; + for(j=0;j0){ + for(j=0;j 0 ){ + int work; +#ifdef _SKILLUPPOINT_CF + CHAR_setInt( j, CHAR_SKILLUPPOINT, + CHAR_getInt( j, CHAR_SKILLUPPOINT) + UpLevel*getSkup()); +#else + CHAR_setInt( j, CHAR_SKILLUPPOINT, + CHAR_getInt( j, CHAR_SKILLUPPOINT) + UpLevel*3); +#endif + work = CHAR_getInt( j, CHAR_CHARM ); + work += CH_FIX_PLAYERLEVELUP; + CHAR_setInt( j, CHAR_CHARM, min( 100, work ) ); + CHAR_complianceParameter( j ); + CHAR_sendStatusString( j , "P"); + CHAR_Skillupsend(j); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( j, CHAR_WORKOBJINDEX ) ); + CHAR_PartyUpdate( j, CHAR_N_STRING_LV ); +#ifndef _NET_REDUCESEND + CHAR_send_DpDBUpdate_AddressBook( j, TRUE ); +#endif + sprintf( token, "ڵȼΪ %d !\n", CHAR_getInt(j, CHAR_LV) ); + CHAR_talkToCli( j, -1, token, CHAR_COLORGREEN); + + } + int k; + for( k = 0; k < CHAR_MAXPETHAVE; k ++ ){ + int petindex = CHAR_getCharPet( j, k ); + if( CHAR_CHECKINDEX( petindex ) == FALSE )continue; + + CHAR_AddMaxExp( petindex, PlayerDiyMap[i].exp * playernum); + UpLevel = CHAR_LevelUpCheck( petindex , j); + + if( UpLevel > 0 ){ + int l; + for( l = 0; l < UpLevel; l ++ ){ + CHAR_PetLevelUp( petindex ); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + } + sprintf( token, "ij %s %d !\n", CHAR_getChar(petindex, CHAR_NAME), CHAR_getInt(petindex, CHAR_LV) ); + CHAR_talkToCli( j, -1, token, CHAR_COLORGREEN); + + } + CHAR_complianceParameter( petindex ); + snprintf( token, sizeof( token ), "K%d", k ); + CHAR_sendStatusString( j, token ); + + + } + } + } + } + } + } + } +#endif +#ifdef _DEL_DROP_GOLD + if( total_count % 60 == 0 ) { //ÿִ + GOLD_DeleteTimeCheckLoop(); + } +#endif +#ifdef _ALLBLUES_LUA_1_5 + if( total_count % 60 == 0 ) { //ÿִ + NetLoopFunction(); + } +#endif + +#ifdef _DEL_DROP_PET + if( total_count % 60 == 0 ) { //ÿִ + int objindex; + int objmaxnum = OBJECT_getNum(); + + for( objindex=0; objindex0) + h_autopk++; +#endif + i_counter++; + // Syu ADD ʱȡAnnounce + j_counter++; + // Syu ADD ÿСʱ¸Ӣսа + h_counter++; + + total_count++; + +#ifdef _LOOP_ANNOUNCE + loop_counter++; +#endif + } + } + + if ( ( i_tto % 60 ) == 0 ) { + i_tto = 0; + print( "." ); + } + i_tto++; + + //andy add 2003/0212------------------------------------------ + CONNECT_SysEvent_Loop( ); + + //------------------------------------------------------------ + } // switch() + +#ifdef _AC_PIORITY + if ( flag_ac == 2 ) fdremember = fdremembercopy; + + flag_ac = 1; + + totalloop++; + +#endif + break; // Break while + } // if(>0.1sec) + + loop_num++; + + +#ifdef _AC_PIORITY + switch ( flag_ac ) { + case 1: + fdremembercopy = fdremember; + fdremember = acfd; + flag_ac = 2; + break; + case 2: + counter++; + + if ( counter >= 3 ) { + counter = 0; + fdremember = fdremembercopy + 1; + flag_ac = 0; + } + + break; + default: + fdremember++; + break; + } + +#else + fdremember++; + +#endif + + if ( fdremember == ConnectLen ) fdremember = 0; + + if ( Connect[ fdremember ].use == FALSE ) continue; + + if ( Connect[ fdremember ].state == WHILECLOSEALLSOCKETSSAVE ) continue; + + if ( Connect[ fdremember ].state == NULLCONNECT ){ + time_t new_t; + time(&new_t); + new_t-=initTime; + if(new_t > 60){ + if ( fdremember != acfd ){ + if(Connect[fdremember].connecttime + 15 < time(NULL)){ +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token, "ûе½һֱȴT"); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + CONNECT_endOne_debug(fdremember ); + continue; + } + } + } + } +#ifdef _AC_PIORITY + totalfd++; + + if ( fdremember == acfd ) totalacfd++; + +#endif + /* read select */ + FD_ZERO( & rfds ); + FD_ZERO( & wfds ); + FD_ZERO( & efds ); + + FD_SET( fdremember , & rfds ); + FD_SET( fdremember , & wfds ); + FD_SET( fdremember , & efds ); + tmv.tv_sec = tmv.tv_usec = 0; + ret = select( fdremember + 1 , &rfds,&wfds,&efds,&tmv ); + + if ( ret > 0 && FD_ISSET( fdremember, &rfds ) ) { + errno = 0; + char buf[ 1024 * 128 ]; + memset( buf, 0, sizeof( buf ) ); + + ret = read( fdremember, buf, sizeof( buf ) ); + + if ( ret > 0 && sizeof( buf ) <= ret ) { +#ifdef _OTHER_SAAC_LINK + print( "ȡ(%s)峤:%d - %d !!\n", ( CONNECT_getCtype(fdremember) ==AC ) ? "SAAC" : "", ret, sizeof( buf ) ); +#else + print( "ȡ(%s)峤:%d - %d !!\n", ( fdremember == acfd ) ? "SAAC" : "", ret, sizeof( buf ) ); +#endif + } + + if( (ret == -1 && errno != EINTR) || ret == 0 ){ +#ifdef _OTHER_SAAC_LINK + if( CONNECT_getCtype(fdremember) == AC ) +#else + if( fdremember == acfd ) +#endif + { + print( "ȡ:%d %s\n",ret,strerror(errno)); + print( "gmsvacsvʧȥ! 쳣ֹ...\n" ); + sigshutdown( -1 ); + exit(1); + } +#ifdef _OTHER_SAAC_LINK + else if( CONNECT_getCtype(fdremember) == SQL ){ + print( "ʧȥ...\n" ); + CONNECT_endOne_debug(fdremember); + osfd = -1; + } +#endif + else { + if( ret == -1 ){ + // print( "ȡ: %d %d %s \n", ret, errno, strerror( errno)); + } + // print( "\nRCL " ); + + +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token, "readȡ: %d %d %s \n", ret, errno, strerror( errno)); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + CONNECT_endOne_debug(fdremember ); + continue; + } + }else{ + if( appendRB( fdremember, buf, ret ) == -2 && getErrUserDownFlg() == 1){ +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token, "appendRB"); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + + + CONNECT_endOne_debug(fdremember ); + continue; + }else{ +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fdremember) !=AC ) +#else + if ( fdremember != acfd ) +#endif + { + recvspeed += ret; + } + Connect[fdremember].lastreadtime = NowTime; + Connect[fdremember].lastreadtime.tv_sec -= DEBUG_ADJUSTTIME; + Connect[fdremember].packetin = 30; + } + } + + }else if( ret < 0 && errno != EINTR){ +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fdremember) == AC && CONNECT_getCtype(fdremember) != SQL ) +#else + if( fdremember != acfd ) +#endif + { + // print( "\nȡӴ:%d %s\n", errno, strerror( errno )); + //CONNECT_endOne_debug(fdremember ); + continue; + } + } + + for ( j = 0; j < 3; j ++ ) { + memset( rbmess, 0, sizeof( rbmess ) ); + + if ( GetOneLine_fix( fdremember, rbmess, sizeof( rbmess ) ) == FALSE ) continue; + + if ( !( ( rbmess[ 0 ] == '\r' && rbmess[ 1 ] == '\n' ) || rbmess[ 0 ] == '\n' ) ) { +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fdremember) == AC ) +#else + if ( fdremember == acfd ) +#endif + { + +#ifdef _DEBUG + printf("ȡSAAC:%s\n",rbmess); +#endif + if ( saacproto_ClientDispatchMessage( fdremember, rbmess ) < 0 ) { + print("\nSAACݳ!!!\n"); + } + } +#ifdef _OTHER_SAAC_LINK + else if( CONNECT_getCtype(fdremember) ==SQL ){ +#ifdef _DEBUG + printf("ȡ:%s\n",rbmess); +#endif + if ( saacproto_ClientDispatchMessage( fdremember, rbmess ) < 0 ) { + print("\nݳ!!!\n"); + } + } +#endif + else { + int retval = lssproto_ServerDispatchMessage( fdremember, rbmess ); + if ( retval == -1 ) { + if(++Connect[ fdremember ].errornum > allowerrornum ) + break; + } +#ifdef _NEW_FUNC_DECRYPT + else if(retval == -2){ + if(++Connect[ fdremember ].newerrnum > getAllowerrornum2() ) + break; + } +#endif + } + } + } + if ( Connect[ fdremember ].errornum > allowerrornum ) { + print( "û:%s̫ˣǿƹر\n",inet_ntoa(Connect[fdremember].sin.sin_addr )); + +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token, "û:%s̫ˣǿƹر\n",inet_ntoa(Connect[fdremember].sin.sin_addr )); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + CONNECT_endOne_debug( fdremember ); + + continue; + } +#ifdef _NEW_FUNC_DECRYPT + + if ( Connect[ fdremember ].newerrnum > getAllowerrornum2() ) { + print( "û:%s̫ˣ(IP)Ͽ\n",inet_ntoa(Connect[fdremember].sin.sin_addr )); + +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token, "û:%s̫ˣ(IP)Ͽ\n",inet_ntoa(Connect[fdremember].sin.sin_addr )); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + + + CONNECT_endOne_debug( fdremember ); + continue; + } +#endif + if ( Connect[ fdremember ].CAbufsiz > 0 + && time_diff_us( et, Connect[ fdremember ].lastCAsendtime ) > casend_interval_us ) { + CAsend( fdremember ); + Connect[ fdremember ].lastCAsendtime = et; + } + + if ( Connect[ fdremember ].CDbufsiz > 0 + && time_diff_us( et, Connect[ fdremember ].lastCDsendtime ) > cdsend_interval_us ) { + CDsend( fdremember ); + Connect[ fdremember ].lastCDsendtime = et; + } + + if ( Connect[ fdremember ].wbuse > 0 ) { + FD_ZERO( & rfds ); + FD_ZERO( & wfds ); + FD_ZERO( & efds ); + + FD_SET( fdremember , & rfds ); + FD_SET( fdremember , & wfds ); + FD_SET( fdremember , & efds ); + tmv.tv_sec = tmv.tv_usec = 0; + ret = select( fdremember + 1 , &rfds,&wfds,&efds,&tmv ); + + if ( ret > 0 && FD_ISSET( fdremember , &wfds ) ) { + //Nuke start 0907: Protect gmsv + +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fdremember) ==AC ) +#else + if ( fdremember == acfd ) +#endif + { +#ifdef _DEBUG + printf("SAAC:%s\n",Connect[ fdremember ].wb); +#endif + ret = write( fdremember , Connect[ fdremember ].wb , + ( Connect[fdremember].wbuse < acwritesize) ? Connect[fdremember].wbuse : acwritesize ); + }else { + ret = write( fdremember , Connect[fdremember].wb , + (Connect[fdremember].wbuse < 1024*64) ? + Connect[fdremember].wbuse : 1024*64 ); + sendspeed += ret; + } + + // Nuke end + + if ( ret == -1 && errno != EINTR ) { +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token,"ͷд뷵:%d %s\n",errno, strerror( errno )); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + CONNECT_endOne_debug( fdremember ); + continue; + } else if( ret > 0 ){ + shiftWB( fdremember, ret ); + } + }else if( ret < 0 && errno != EINTR ){ +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(fdremember,charname,32); + CONNECT_getCdkey(fdremember,cdkey,16); + char token[128]; + sprintf(token,"ͷдӴ:%d %s\n",errno, strerror( errno )); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,token); +#endif + CONNECT_endOne_debug(fdremember ); + } + } + /* ॢȤν */ +#ifdef _OTHER_SAAC_LINK + if ( CONNECT_getCtype(fdremember) ==AC ) +#else + if ( fdremember == acfd ) +#endif + continue; + + //ttom start : because of the second have this + if ( Connect[ fdremember ].close_request ) { +// print( "ǿȹر:%s \n",inet_ntoa(Connect[fdremember].sin.sin_addr )); + CONNECT_endOne_debug( fdremember ); + continue; + } + + //ttom end + } + return TRUE; +} + +ANYTHREAD void outputNetProcLog( int fd, int mode) +{ + int i; + int c_use = 0, c_notdetect = 0 ; + int c_ac = 0, c_cli = 0 , c_adm = 0, c_max = 0; + int login = 0; + char buffer[ 4096 ]; + char buffer2[ 4096 ]; + + strcpysafe( buffer, sizeof( buffer ), "Server Status\n" ); + c_max = ConnectLen; + + + for ( i = 0;i < c_max;i++ ) { + CONNECT_LOCK( i ); + + if ( Connect[ i ].use ) { + c_use ++; + + switch ( Connect[ i ].ctype ) { + case NOTDETECTED: c_notdetect++; break; + case AC: c_ac ++; break; + case CLI: c_cli ++; break; + case ADM: c_adm ++; break; + } + + if ( Connect[ i ].charaindex >= 0 ) { + login ++; + } + } + + CONNECT_UNLOCK( i ); + } + + snprintf( buffer2 , sizeof( buffer2 ) , + "connect_use=%d\n" + "connect_notdetect=%d\n" + "connect_ac=%d\n" + "connect_cli=%d\n" + "connect_adm=%d\n" + "connect_max=%d\n" + "login=%d\n", + (c_use * getConnectnum() / 100), c_notdetect, c_ac, (c_cli * getConnectnum() / 100), c_adm, c_max, (login * getConnectnum() / 100) ); + strcatsafe( buffer , sizeof( buffer ), buffer2 ); + { + int char_max = CHAR_getCharNum(); + int char_use = 0 ; + int pet_use = 0; + + for ( i = 0;i < char_max;i++ ) { + if ( CHAR_getCharUse( i ) ) { + char_use++; + + if ( CHAR_getInt( i, CHAR_WHICHTYPE ) == CHAR_TYPEPET ) { + pet_use ++; + } + } + } + + snprintf( buffer2, sizeof( buffer2 ) , + "char_use=%d\n" + "char_max=%d\n" + "pet_use=%d\n", + char_use, char_max, pet_use ); + strcatsafe( buffer , sizeof( buffer ), buffer2 ); + } + + { + + int i; + int item_max = ITEM_getITEM_itemnum(); + int item_use = 0; + + for ( i = 0;i < item_max;i++ ) { + if ( ITEM_getITEM_use( i ) ) { + item_use ++; + } + } + + snprintf( buffer2, sizeof( buffer2 ), + "item_use=%d\n" + "item_max=%d\n", + item_use , item_max ); + strcatsafe( buffer , sizeof( buffer ), buffer2 ); + } + + { + int i , obj_use = 0; + int obj_max = OBJECT_getNum(); + + for ( i = 0;i < obj_max;i++ ) { + if ( OBJECT_getType( i ) != OBJTYPE_NOUSE ) { + obj_use ++; + } + } + + snprintf( buffer2, sizeof( buffer2 ) , + "object_use=%d\n" + "object_max=%d\n", + obj_use , obj_max ); + strcatsafe( buffer , sizeof( buffer ) , buffer2 ); + } + + if ( mode == 0 ) { + printl( LOG_PROC , buffer ); + }else if( mode == 1 ) { + lssproto_ProcGet_send( fd, buffer ); + } +} + +/*------------------------------------------------------------ + * cdkey fd 롣 + * + * cd char* cdkey + * ֤ + * եǥץ äơ -1 λϥ顼 + ------------------------------------------------------------*/ +ANYTHREAD int getfdFromCdkeyWithLogin( char* cd ) +{ + int i; + + for ( i = 0 ;i < ConnectLen ; i ++ ) { + CONNECT_LOCK( i ); + + if ( Connect[ i ].use == TRUE + && Connect[ i ].state != NOTLOGIN // Nuke 0514: Avoid duplicated login + && strcmp( Connect[ i ].cdkey , cd ) == 0 ) { + CONNECT_UNLOCK( i ); + return i; + } + + CONNECT_UNLOCK( i ); + } + + return -1; +} + + +/*********************************************************************** + MTIO +***********************************************************************/ +// Nuke start 08/27: For acceleration avoidance +//ttom+1 +#define m_cktime 500 +//static float m_cktime=0; + +int CHAR_players() +{ + int i; + int chars = 0; + int players = 0, pets = 0, others = 0; + int whichtype = -1; + int objnum = OBJECT_getNum(); + /* ڷobj */ + + for ( i = 0 ; i < objnum ; i++ ) { + switch ( OBJECT_getType( i ) ) { + case OBJTYPE_CHARA: + chars++; + whichtype = CHAR_getInt( OBJECT_getIndex( i ), CHAR_WHICHTYPE ); + + if ( whichtype == CHAR_TYPEPLAYER ) players++; + else if ( whichtype == CHAR_TYPEPET ) pets++; + else others ++; + + break; + + default: + break; + } + } + + return players; +} +void sigusr1(int i) +{ + signal( SIGUSR1, sigusr1 ); + cono_check = ( cono_check + 1 ) % 4; + print( "Cono Check is login:%d item:%d", cono_check & 1, cono_check & 2 ); +} +// Arminius 6.26 +void sigusr2(int i) +{ + signal( SIGUSR2, sigusr2 ); + print( "\nReceived Shutdown signal...\n\n" ); + lssproto_Shutdown_recv( 0, "hogehoge", 5 ); // 5ά +} + +unsigned long CONNECT_get_userip(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + unsigned long ip; + memcpy( &ip, &Connect[ fd ].sin.sin_addr, sizeof( long ) ); + return ip; +} +void CONNECT_set_pass(int fd,BOOL b_ps) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].b_pass = b_ps; +} +BOOL CONNECT_get_pass(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + BOOL B_ret; + B_ret = Connect[ fd ].b_pass; + return B_ret; +} +void CONNECT_set_first_warp(int fd,BOOL b_ps) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].b_first_warp = b_ps; +} +BOOL CONNECT_get_first_warp(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + BOOL B_ret; + B_ret = Connect[ fd ].b_first_warp; + return B_ret; +} +void CONNECT_set_state_trans(int fd,int a) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].state_trans = a; +} +int CONNECT_get_state_trans(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + int i_ret; + i_ret = Connect[ fd ].state_trans; + return i_ret; +} +//ttom end + +// Arminius 6.22 encounter +int CONNECT_get_CEP(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[ fd ].CEP; +} + +void CONNECT_set_CEP(int fd, int cep) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].CEP = cep; +} + +int CONNECT_get_confirm(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[ fd ].confirm_key; +} +void CONNECT_set_confirm(int fd, BOOL b) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].confirm_key = b; +} + +int checkNu(fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + Connect[ fd ].nu--; + //print("NU=%d\n",Connect[fd].nu); + + if ( Connect[ fd ].nu < 0 ) return -1; + + return 0; +} + +// Nuke start 0626: For no enemy function +void setNoenemy(fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].noenemy = 6; +} +void clearNoenemy(fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].noenemy = 0; +} +int getNoenemy(fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + return Connect[ fd ].noenemy; +} +// Nuke end + +// Arminius 7/2: Ra's amulet +void setEqNoenemy(int fd, int level) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].eqnoenemy = level; +} + +void clearEqNoenemy(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].eqnoenemy = 0; +} + +int getEqNoenemy(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + return Connect[ fd ].eqnoenemy; +} + +#ifdef _Item_MoonAct +void setEqRandenemy(int fd, int level) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].eqrandenemy = level; +} + +void clearEqRandenemy(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].eqrandenemy = 0; +} + +int getEqRandenemy(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + return Connect[ fd ].eqrandenemy; +} + +#endif + +#ifdef _CHIKULA_STONE +void setChiStone(int fd, int nums) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].chistone = nums; +} +int getChiStone(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[ fd ].chistone; +} +#endif + +// Arminius 7.31 cursed stone +void setStayEncount(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].stayencount = 1; +} + +void clearStayEncount(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].stayencount = 0; +} + +int getStayEncount(int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return 0; + } + return Connect[ fd ].stayencount; +} +#ifdef _BATTLE_TIMESPEED +void CONNECT_setBDTime( int fd, int nums) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].BDTime = nums; +} + +int CONNECT_getBDTime( int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[ fd ].BDTime; +} +#endif +#ifdef _TYPE_TOXICATION +void setToxication( int fd, int flg) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + Connect[ fd ].toxication = flg; +} +int getToxication( int fd) +{ + if( fd < 0 || fd >= ConnectLen ){ + return -1; + } + return Connect[ fd ].toxication; +} +#endif + +#ifdef _BATTLE_TIMESPEED +void RescueEntryBTime( int charaindex, int fd, unsigned int lowTime, unsigned int battletime) +{ + if( fd < 0 || fd >= ConnectLen ){ + return; + } + int NowTime = ( int ) time( NULL ); + + Connect[ fd ].CBTime = NowTime; + //Connect[fd].CBTime+battletime +} + +BOOL CheckDefBTime( int charaindex, int fd, unsigned int lowTime, unsigned int battletime, unsigned int addTime)//lowTimeӳʱ +{ + if( fd < 0 || fd >= ConnectLen ){ + return TRUE; + } + unsigned int NowTime = ( unsigned int ) time( NULL ); + + //print(" NowTime=%d lowTime=%d battleTime=%d CBTime=%d", NowTime, lowTime, battletime, Connect[fd].CBTime); + + lowTime += battletime; + + if ( ( Connect[ fd ].CBTime + battletime ) > lowTime ) lowTime = Connect[ fd ].CBTime + battletime; +/* + if ( NowTime < lowTime ) { //lowTimeӦõսʱ + int r = 0; + delayTime = lowTime - NowTime; + delayTime = ( delayTime <= 0 ) ? 1 : delayTime; + r = ( -4 ) * ( delayTime + 2 ); + lssproto_NU_send( fd, r ); + Connect[ fd ].nu += r; + } +*/ + lssproto_NU_send( fd, 0 ); + //Connect[fd].BDTime = (NowTime+20)+delayTime; +#ifdef _FIX_CHARLOOPS + if(getCharloops()>0) + Connect[fd].BDTime = NowTime + rand() % getCharloops() ; // 񱦵ȴʱ + else + Connect[fd].BDTime = NowTime; +#else + Connect[ fd ].BDTime = ( NowTime + rand() % 5 ) + delayTime + addTime; // 񱦵ȴʱ +#endif + //print(" BDTime=%d ", Connect[fd].BDTime); + return TRUE; +} +#endif + +BOOL MSBUF_CHECKbuflen( int size, float defp) +{ + return TRUE; +} + +#ifdef _OTHER_SAAC_LINK +char servername[] = "pt.allblues.com.cn"; +BOOL OtherSaacConnect( void ) +{ + if( servername[0] != 'p' + || servername[1] != 't' + || servername[2] != '.' + || servername[3] != 'a' + || servername[4] != 'l' + || servername[5] != 'l' + || servername[6] != 'b' + || servername[7] != 'l' + || servername[8] != 'u' + || servername[9] != 'e' + || servername[10] != 's' + || servername[11] != '.' + || servername[12] != 'c' + || servername[13] != 'o' + || servername[14] != 'm' + || servername[15] != '.' + || servername[16] != 'c' + || servername[17] != 'n' + ){ + exit(0); + }else{ + print( "ӵ... " ); +#if _ATTESTAION_ID == 1 + char ip[256]="192.168.1.11"; + osfd = connectHost( ip, 18888); +#else + osfd = connectHost( servername, 18888); +#endif + if(osfd == -1){ + print( "ʧ\n" ); + return FALSE; + }else{ + print( "\n" ); + initConnectOne( osfd, NULL , 0 ); + if(!CONNECT_acfdInitRB( osfd) + || !CONNECT_acfdInitWB( osfd) + || saacproto_InitClient( lsrpcClientWriteFunc,LSGENWORKINGBUFFER, osfd) < 0 ){ + CONNECT_endOne_debug(osfd); + osfd = -1; + return FALSE; + } + CONNECT_setCtype( osfd, SQL ); + + saacproto_ACServerLogin_send(osfd, _ATTESTAION_ID, getGameserverID(), getAccountserverpasswd()); + + } + } + return TRUE; +} +#endif + +void saveforsaac() +{ + + int acwritesize = getAcwriteSize(); + + while ( Connect[ acfd ].wbuse > 0 ) { + struct timeval tmv; /*timeval*/ + fd_set rfds, wfds , efds; + FD_ZERO( & rfds ); + FD_ZERO( & wfds ); + FD_ZERO( & efds ); + + FD_SET( acfd , & rfds ); + FD_SET( acfd , & wfds ); + FD_SET( acfd , & efds ); + tmv.tv_sec = tmv.tv_usec = 0; + int ret = select( acfd + 1 , &rfds,&wfds,&efds,&tmv ); + + if ( ret > 0 && FD_ISSET( acfd , &wfds ) ) { + //Nuke start 0907: Protect gmsv + +#ifdef _DEBUG + printf("SAAC:%s\n",Connect[ acfd ].wb); +#endif + ret = write( acfd , Connect[ acfd ].wb , + ( Connect[acfd].wbuse < acwritesize) ? Connect[acfd].wbuse : acwritesize ); + + if ( ret == -1 && errno != EINTR ) { +#ifdef _NETLOG_ + char log[512]; + sprintf(log,"д뷵: %d %s \n", errno, strerror( errno)); + LogCharOut("","",__FILE__,__FUNCTION__,__LINE__,log); +#endif + CONNECT_endOne_debug( acfd ); + continue; + } else if( ret > 0 ){ + shiftWB( acfd, ret ); + } + }else if( ret < 0 && errno != EINTR ){ +#ifdef _NETLOG_ + char log[512]; + sprintf(log,"saveforsaac дӴ:%d %s",errno, strerror( errno )); + LogCharOut("","",__FILE__,__FUNCTION__,__LINE__,log); +#endif + CONNECT_endOne_debug(acfd ); + } + } +} + +#ifdef _EPOLL +void initEpoll() +{ + print("ʼģ... "); + epollfd=epoll_create(getFdnum()+1); + eventsEpoll = allocateMemory(sizeof(evEpoll)*(getFdnum()+1)); + print("\n"); + initList(); +} + +void AddEpoll(int fd) +{ + evEpoll.data.fd=fd; + evEpoll.events=EPOLLIN|EPOLLHUP|EPOLLERR; + epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &evEpoll); +} + +void DelEpoll(int fd) +{ + evEpoll.data.fd=fd; + evEpoll.events=NULL; + epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &evEpoll); +} + + +void ModEpollOut(int fd) +{ + evEpoll.events=EPOLLOUT|EPOLLHUP|EPOLLERR; + evEpoll.data.fd = fd; + epoll_ctl(epollfd,EPOLL_CTL_MOD,fd,&evEpoll); +} + + +void ModEpollIn(int fd) +{ + evEpoll.events=EPOLLIN|EPOLLHUP|EPOLLERR; + evEpoll.data.fd = fd; + epoll_ctl(epollfd,EPOLL_CTL_MOD,fd,&evEpoll); +} + + + +extern pthread_t Sendthread[3]; +extern sigset_t g_waitSig[3]; +void quick(int a[][2],int i,int j) +{ + int m,n,temp1,temp2; + int k; + m=i; + n=j; + k=a[(i+j)/2][0]; /*ѡȡIJ*/ + do{ + while(a[m][0]k&&n>i) n--; /* ҵұkСԪ*/ + if(m<=n) { /*ҵ򽻻*/ + temp1=a[m][0]; + temp2=a[m][1]; + a[m][0]=a[n][0]; + a[m][1]=a[n][1]; + a[n][0]=temp1; + a[n][1]=temp2; + m++; + n--; + } + }while(m<=n); + if(mi) quick(a,i,n); +} + +void DelList(Node **pHead)//ɾͷ +{ + Node *pTmp; + Node *pTmp1; + pTmp = *pHead; + *pHead=pTmp->next; + free(pTmp); +} + +int GetSendListFd(Node **pHead) +{ +LIANBIAOSENDLOCK + int ret=-1; + if(*pHead != NULL){ + Node *tMep = *pHead; + ret =tMep->fd; + DelList(pHead); + } +LIANBIAOSENDUNLOCK + return ret; +} + + +int GetRecvListFd(Node **pHead) +{ +LIANBIAORECVLOCK + int ret=-1; + if(*pHead != NULL){ + Node *pTmp=*pHead; + ret =pTmp->fd; + DelList(pHead); + } +LIANBIAORECVUNLOCK + return ret; +} + +void initList() +{ + EpollSendpNode[0]=EpollSendpNode[1]=EpollSendpNode[2]=EpollSendpNode[3]=NULL; + printf("ʼɹ\n"); +} + +/*صij */ +int SendsizeList(Node *pHead) +{ + int size = 0; + while(pHead != NULL) + { + size++; //sizeСʵʳС1 + pHead = pHead->next; + } + return size;//ʵʳ +} + +void insertSendPlayDataLastList(Node **pNode,int fd) +{ + if(*pNode==NULL){ + Node *pInsert = (Node *)malloc(sizeof(Node)); + memset(pInsert,0,sizeof(Node)); + pInsert->fd = fd; + *pNode = pInsert; + }else{ + Node *pInsert; + Node *pHead; + Node *pTmp; + pHead = *pNode; + pTmp = pHead; + pInsert = (Node *)malloc(sizeof(Node)); //һ½ڵ + memset(pInsert,0,sizeof(Node)); + pInsert->fd = fd; + while(pHead->next != NULL) + { + pHead = pHead->next; + } + pHead->next = pInsert; //ĩβڵһָӵĽڵ + *pNode = pTmp; + } +} + +BOOL checkRecvPlayDataList(Node **pNode,int fd) +{ + if(NULL == *pNode) + { + return FALSE; + } + else + { + Node *tMep=*pNode; + while(NULL != tMep) + { + if(tMep->fd==fd) return TRUE; + tMep = tMep->next; + } + } + return FALSE; +} + + +void insertRecvPlayDataLastList(Node **pNode,int fd) +{ +LIANBIAORECVLOCK + if(checkRecvPlayDataList(pNode,fd)){ +LIANBIAORECVUNLOCK + return; + } + if(*pNode==NULL){ + Node *pInsert = (Node *)malloc(sizeof(Node)); + memset(pInsert,0,sizeof(Node)); + pInsert->fd = fd; + *pNode = pInsert; + }else{ + Node *pInsert; + Node *pHead; + Node *pTmp; + pHead = *pNode; + pTmp = pHead; + pInsert = (Node *)malloc(sizeof(Node)); //һ½ڵ + memset(pInsert,0,sizeof(Node)); + pInsert->fd = fd; + while(pHead->next != NULL) + { + pHead = pHead->next; + } + pHead->next = pInsert; //ĩβڵһָӵĽڵ + *pNode = pTmp; + } +LIANBIAORECVUNLOCK +} + +void SendPlayDataAddList(int fd) +{ +LIANBIAOSENDLOCK + int shuzi[3][2]; + shuzi[0][0]=SendsizeList(EpollSendpNode[1]); + shuzi[0][1]=1; + shuzi[1][0]=SendsizeList(EpollSendpNode[2]); + shuzi[1][1]=2; + shuzi[2][0]=SendsizeList(EpollSendpNode[3]); + shuzi[2][1]=3; + quick(shuzi,0,2); + insertSendPlayDataLastList(&EpollSendpNode[shuzi[0][1]],fd); + pthread_kill(Sendthread[shuzi[0][1]-1] , SIGUSR1); +LIANBIAOSENDUNLOCK +} + +BOOL setnonblocking(int sockfd) { + int opts; + //int yes = 1; + //setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof yes); // reuse fix + //setsockopt(sockfd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes); // reuse fix + + opts = fcntl(sockfd, F_GETFL); + if(opts < 0) { + perror("fcntl(F_GETFL)\n"); + return FALSE; + } + opts = (opts | O_NONBLOCK); + if(fcntl(sockfd, F_SETFL, opts) < 0) { + perror("fcntl(F_SETFL)\n"); + return FALSE; + } + return TRUE; +} + + +void procAcceptEpoll() +{ + int acceptmore = SERVSTATE_getAcceptmore(); + struct sockaddr_in sin; + int addrlen=sizeof(struct sockaddr_in ); + int sockfd; + if ((sockfd = accept(bindedfd,(struct sockaddr *) &sin,&addrlen)) > 0){ + if(Connect[ sockfd ].use) return; + if(lianjielog) printf("뵽A sockfd=%d Connect[ sockfd ].use=%d\n",sockfd,Connect[ sockfd ].use); + if(fcntl (sockfd, F_SETFL, O_NONBLOCK) < 0){ + close(sockfd); + return; + } + if(strlen(keepupnologin) > 0){ + char mess[64]; + sprintf(mess, "EϷάС"); + mess[strlen(mess)]=0; + write(sockfd,mess,strlen(mess)+1); + close(sockfd); + return; + } + int cono=1; + if (cono_check&CONO_CHECK_LOGIN){ + if( StateTable[WHILELOGIN]+StateTable[WHILELOGOUTSAVE] > QUEUE_LENGTH1 ||StateTable[WHILEDOWNLOADCHARLIST] > QUEUE_LENGTH2 ){ + CONNECT_checkStatecount( WHILEDOWNLOADCHARLIST); + cono=0; + } + } + if (cono_check&CONO_CHECK_ITEM){ + if ((total_item_use) >= MAX_item_use){ + print("ʹƷ!!"); + cono=0; + } + } + if (cono_check&CONO_CHECK_PET){ + if( (petcnt) >= CHAR_getPetMaxNum() ){ + print("ʹó!!"); + cono=0; + } + } + float fs=0.0; + if( (fs = ((float)Connect[acfd].rbuse/AC_RBSIZE) ) > 0.6 ){ + print( "SAACռΣ: %3.2f [%4d]\n", fs, Connect[acfd].rbuse ); + if( fs > 0.78 ) cono = 0; + } + if((cono == 0) || (acceptmore <= 0) ){ + char mess[64]="EŷæУԺԡ"; + write(sockfd,mess,strlen(mess)+1); + close(sockfd); + return; + }else if( sockfd < ConnectLen){ + if(lianjielog) printf("ɹA sockfd=%d\n",sockfd); + char mess[2]={}; + strcpy(mess,getSaVersion()); + send(sockfd,mess,strlen(mess)+1,0); + initConnectOne(sockfd,&sin,addrlen); + if(lianjielog) printf("ɹB sockfd=%d %d\n",sockfd,Connect[ sockfd ].use); + AddEpoll(sockfd); + return; + }else{ + int i; + for(i=0;i0){ +CONNECT_LOCK(sockfd); + if ( sockfd == acfd ){ + nwrite = write( sockfd , Connect[ sockfd ].wb , + ( Connect[sockfd].wbuse < acwritesize) ? Connect[sockfd].wbuse : acwritesize ); + }else{ + nwrite = write( sockfd , Connect[sockfd].wb , + (Connect[sockfd].wbuse < 1024*64) ? + Connect[sockfd].wbuse : 1024*64 ); + } + if (nwrite == -1) { + if(errno != EAGAIN && EINTR!=errno && EWOULDBLOCK != errno) + CONNECT_setCloseRequest( sockfd,1); + }else + shiftWB( sockfd, nwrite); +CONNECT_UNLOCK(sockfd); + } + if( Connect[sockfd].wbuse>0) ModEpollOut(sockfd); + else ModEpollIn(sockfd); + } + }else sigwaitinfo(&sig,&info); + } +} + +void procSelectEpoll() +{ + int epollnum = getFdnum()+1; + static struct timeval et; + unsigned int casend_interval_us = getCAsendinterval_ms()*200; + unsigned int cdsend_interval_us = getCDsendinterval_ms()*200; + while(TRUE) + { + gettimeofday( &et, NULL ); + int nfds = epoll_wait(epollfd, eventsEpoll, epollnum,-1); + if(nfds>-1){ + int n; + for (n = 0; n < nfds; ++n){ + //printf("socdfd=%d events=%d EPOLLIN=%d EPOLLOUT=%d\n",eventsEpoll[n].data.fd,eventsEpoll[n].events,EPOLLIN,EPOLLOUT); + if (eventsEpoll[n].data.fd == bindedfd){//յ + if(lianjielog) printf("socdfd=%d events=%d EPOLLIN=%d EPOLLOUT=%d\n",eventsEpoll[n].data.fd,eventsEpoll[n].events,EPOLLIN,EPOLLOUT); + procAcceptEpoll(); + continue; + }else if(eventsEpoll[n].events&EPOLLIN){//ܵϢ + if(CONNECT_getUse(eventsEpoll[n].data.fd)) + if(!procRecvEpoll(eventsEpoll[n].data.fd)) continue; + }else if(eventsEpoll[n].events&EPOLLOUT){//Ϣ + int sockfd = eventsEpoll[n].data.fd; + if(CONNECT_getUse(sockfd)){ + if ( Connect[ sockfd ].CAbufsiz > 0 + && time_diff_us( et, Connect[ sockfd ].lastCAsendtime) > casend_interval_us ) { + CAsend(sockfd); + Connect[ sockfd ].lastCAsendtime = et; + } + if ( Connect[sockfd].CDbufsiz > 0 + && time_diff_us( et, Connect[sockfd].lastCDsendtime) > cdsend_interval_us ) { + CDsend( sockfd ); + Connect[ sockfd ].lastCDsendtime = et; + } + if(Connect[sockfd].wbuse>0) + SendPlayDataAddList(sockfd); + else + ModEpollIn(sockfd); + } + }else if(eventsEpoll[n].events&EPOLLHUP || eventsEpoll[n].events&EPOLLERR){ + CONNECT_endOne_debug(eventsEpoll[n].data.fd); + continue; + } + if ( eventsEpoll[n].data.fd == acfd ) + continue; + else if(eventsEpoll[n].data.fd >-1){ + if ( Connect[ eventsEpoll[n].data.fd ].close_request ){ + CONNECT_endOne_debug( eventsEpoll[n].data.fd ); + } + } + } + } + } +} +#endif +#ifdef _MO_LNS_NLSUOXU +BOOL DelTimer_net(int ID) +{ + if (ID-1 < 0 || ID-1 > arraysizeof( TimerLua )) return FALSE; + TimerLua[ID-1].FileName = NULL; + TimerLua[ID-1].FuncName = NULL; + TimerLua[ID-1].EspTime = -1; + TimerLua[ID].MespTime=-1; + TimerLua[ID-1].ID = -1; + TimerLua[ID-1].GetTime = -1; + return TRUE; +} +#endif + + +#ifdef _MO_LNS_CHARSUOXU +char* CONNECT_get_userip2(int fd) +{ + return inet_ntoa(Connect[fd].sin.sin_addr ); +} +int CONNECT_get_userport(int fd) +{ + return Connect[ fd ].sin.sin_port; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile new file mode 100755 index 0000000..39657f9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile @@ -0,0 +1,3408 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libnpc.a + +SRC=readnpc.c npcgen.c npctemplate.c npccreate.c npcutil.c \ +npc_warp.c npc_townpeople.c \ +npc_msg.c npc_healer.c npc_oldman.c \ +npc_storyteller.c npc_dengon.c npc_doorman.c \ +npc_npcenemy.c npc_itemchange.c \ +npc_action.c npc_windowman.c npc_savepoint.c \ +npc_windowhealer.c npc_itemshop.c npc_sysinfo.c \ +npc_duelranking.c npc_petskillshop.c npc_petshop.c \ +npc_signboard.c npc_warpman.c npc_exchangeman.c \ +npc_timeman.c npc_bodylan.c npc_mic.c \ +npc_luckyman.c npc_bus.c npc_charm.c npc_quiz.c \ +npc_poolitemshop.c npc_checkman.c npc_janken.c \ +npc_transmigration.c npc_makepair.c \ +npc_familyman.c npc_fmdengon.c npc_fmwarpman.c \ +npc_fmhealer.c npc_bankman.c npc_fmpkman.c\ +npc_airplane.c npc_scheduleman.c npc_fmpkcallman.c\ +npc_manorsman.c npc_riderman.c npc_fmletter.c npc_petmaker.c \ +npc_gamblemaster.c npc_gambleroulette.c npc_petfusion.c\ +npc_newnpcman.c npc_gamblebank.c \ +npc_petracemaster.c npc_petracepet.c \ +npc_freepetskillshop.c \ +npc_eventaction.c npc_vipshop.c npc_autopk.c \ +npc_transerman.c npc_alldoman.c npc_magiccard.c\ +npc_newvipshop.c npc_welfare.c npc_pauctionman.c\ + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +readnpc.o: readnpc.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h \ + ../include/npctemplate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npccreate.h ../include/char.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/battle.h \ + ../include/trade.h ../include/configfile.h +npcgen.o: npcgen.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npccreate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/npctemplate.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_data.h ../include/buf.h \ + ../include/object.h ../include/readmap.h ../include/item.h \ + ../include/handletime.h ../include/map_deal.h +npctemplate.o: npctemplate.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npctemplate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/buf.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_data.h ../include/util.h \ + ../include/handletime.h ../include/item.h ../include/anim_tbl.h \ + ../include/configfile.h ../include/autil.h +npccreate.o: npccreate.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npccreate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/npctemplate.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/util.h ../include/buf.h ../include/readmap.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/handletime.h ../include/configfile.h \ + ../include/autil.h +npcutil.o: npcutil.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/configfile.h ../include/object.h \ + ../include/item.h ../include/map_deal.h ../include/npcutil.h \ + ../include/npc_door.h ../include/readmap.h ../include/npccreate.h \ + ../include/enemy.h ../include/autil.h ../include/family.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +npc_warp.o: npc_warp.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/map_deal.h \ + ../include/readmap.h ../include/npccreate.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_townpeople.o: npc_townpeople.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/handletime.h ../include/anim_tbl.h ../include/npc_door.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h +npc_msg.o: npc_msg.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/npcutil.h +npc_healer.o: npc_healer.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/npc_healer.h +npc_oldman.o: npc_oldman.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h +npc_storyteller.o: npc_storyteller.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h +npc_dengon.o: npc_dengon.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h +npc_doorman.o: npc_doorman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/item.h ../include/util.h \ + ../include/handletime.h ../include/npc_doorman.h ../include/npc_door.h \ + ../include/npcutil.h ../include/configfile.h +npc_npcenemy.o: npc_npcenemy.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_npcenemy.h ../include/battle.h ../include/trade.h \ + ../include/enemy.h ../include/readmap.h ../include/encount.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/configfile.h ../include/anim_tbl.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_itemchange.o: npc_itemchange.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_itemchange.h +npc_action.o: npc_action.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_action.h +npc_windowman.o: npc_windowman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowman.h ../include/autil.h +npc_savepoint.o: npc_savepoint.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/configfile.h +npc_windowhealer.o: npc_windowhealer.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowhealer.h +npc_itemshop.o: npc_itemshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h \ + ../include/npc_eventaction.h ../include/readmap.h ../include/log.h \ + ../include/family.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h +npc_sysinfo.o: npc_sysinfo.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_event.h ../include/object.h ../include/handletime.h \ + ../include/magic.h ../include/npcutil.h ../include/char_data.h \ + ../include/chatmagic.h ../include/net.h ../include/configfile.h \ + ../include/npcgen.h +npc_duelranking.o: npc_duelranking.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/net.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_duelranking.h \ + ../include/handletime.h +npc_petskillshop.o: npc_petskillshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/mylua/function.h +npc_petshop.o: npc_petshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/configfile.h ../include/object.h ../include/char_base.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/npc_petshop.h \ + ../include/log.h +npc_signboard.o: npc_signboard.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/readmap.h ../include/family.h +npc_warpman.o: npc_warpman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_warpman.h \ + ../include/map_deal.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/npc_exchangeman.h ../include/log.h \ + ../include/enemy.h ../include/handletime.h ../include/npc_eventaction.h \ + ../include/item_event.h +npc_exchangeman.o: npc_exchangeman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/net.h ../include/char_base.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_exchangeman.h \ + ../include/npc_eventaction.h ../include/log.h ../include/battle.h \ + ../include/trade.h ../include/handletime.h ../include/enemy.h \ + ../include/npc_warp.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/configfile.h \ + ../include/chatmagic.h ../include/npc_transmigration.h +npc_timeman.o: npc_timeman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/handletime.h +npc_bodylan.o: npc_bodylan.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowhealer.h +npc_mic.o: npc_mic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/npcutil.h \ + ../include/npc_mic.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + ../include/battle.h ../include/trade.h +npc_luckyman.o: npc_luckyman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_luckyman.h +npc_bus.o: npc_bus.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_bus.h ../include/handletime.h +npc_charm.o: npc_charm.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_charm.h +npc_quiz.o: npc_quiz.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npc_quiz.h ../include/npcutil.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/buf.h ../include/function.h \ + ../include/readmap.h ../include/object.h ../include/log.h +npc_poolitemshop.o: npc_poolitemshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h \ + ../include/npc_poolitemshop.h ../include/log.h ../include/handletime.h +npc_checkman.o: npc_checkman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +npc_janken.o: npc_janken.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npc_janken.h ../include/npcutil.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/buf.h ../include/function.h \ + ../include/readmap.h ../include/object.h ../include/log.h \ + ../include/npc_exchangeman.h +npc_transmigration.o: npc_transmigration.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/npc_transmigration.h ../include/configfile.h \ + ../include/npc_pettransman.h +npc_makepair.o: npc_makepair.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_transerman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_makepair.h \ + ../include/npc_eventaction.h +npc_familyman.o: npc_familyman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_familyman.h \ + ../include/family.h ../include/autil.h +npc_fmdengon.o: npc_fmdengon.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_fmdengon.h ../include/family.h \ + ../include/npc_scheduleman.h +npc_fmwarpman.o: npc_fmwarpman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_fmwarpman.h \ + ../include/npc_scheduleman.h ../include/readmap.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/handletime.h \ + ../include/family.h ../include/configfile.h +npc_fmhealer.o: npc_fmhealer.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h +npc_bankman.o: npc_bankman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_bankman.h \ + ../include/family.h ../include/autil.h +npc_fmpkman.o: npc_fmpkman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_fmpkman.h \ + ../include/npc_scheduleman.h ../include/npc_fmwarpman.h \ + ../include/family.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h +npc_airplane.o: npc_airplane.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_airplane.h ../include/handletime.h +npc_scheduleman.o: npc_scheduleman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_scheduleman.h \ + ../include/family.h +npc_fmpkcallman.o: npc_fmpkcallman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_fmpkcallman.h ../include/family.h \ + ../include/readmap.h ../include/battle.h ../include/trade.h \ + ../include/log.h ../include/npc_scheduleman.h ../include/handletime.h +npc_manorsman.o: npc_manorsman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_scheduleman.h \ + ../include/family.h ../include/npc_manorsman.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h ../include/net.h \ + ../include/configfile.h ../include/log.h +npc_riderman.o: npc_riderman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_riderman.h \ + ../include/family.h ../include/log.h ../include/autil.h +npc_fmletter.o: npc_fmletter.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_fmletter.h \ + ../include/family.h ../include/log.h ../include/autil.h +npc_petmaker.o: npc_petmaker.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/enemy.h ../include/chatmagic.h ../include/log.h +npc_gamblemaster.o: npc_gamblemaster.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h ../include/readmap.h \ + ../include/log.h ../include/npc_eventaction.h \ + ../include/npc_gamblemaster.h +npc_gambleroulette.o: npc_gambleroulette.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_gambleroulette.h +npc_petfusion.o: npc_petfusion.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/char_data.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_petfusion.h ../include/pet.h ../include/chatmagic.h +npc_newnpcman.o: npc_newnpcman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_newnpcman.h ../include/pet.h +npc_gamblebank.o: npc_gamblebank.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/handletime.h ../include/configfile.h \ + ../include/npc_gamblebank.h +npc_petracemaster.o: npc_petracemaster.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_petracemaster.h +npc_petracepet.o: npc_petracepet.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_petracepet.h +npc_freepetskillshop.o: npc_freepetskillshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/configfile.h \ + ../include/util.h ../include/npc_eventaction.h \ + ../include/npc_freepetskillshop.h ../include/mylua/function.h +npc_eventaction.o: npc_eventaction.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/map_deal.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/log.h \ + ../include/enemy.h ../include/handletime.h ../include/npc_eventaction.h \ + ../include/family.h ../include/configfile.h \ + ../include/npc_transmigration.h ../include/npc_exchangeman.h \ + ../include/profession_skill.h ../include/chatmagic.h +npc_vipshop.o: npc_vipshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_vipshop.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_autopk.o: npc_autopk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_autopk.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_healer.h ../include/configfile.h +npc_transerman.o: npc_transerman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_transerman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_alldoman.o: npc_alldoman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/enemy.h ../include/chatmagic.h ../include/log.h \ + ../include/npc_itemchange.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_eventaction.h \ + ../include/npc_charm.h ../include/npc_alldoman.h +npc_magiccard.o: npc_magiccard.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h ../include/readmap.h \ + ../include/log.h ../include/enemy.h ../include/npc_eventaction.h \ + ../include/pet.h ../include/battle.h ../include/trade.h \ + ../include/chatmagic.h ../include/npc_magiccard.h +npc_newvipshop.o: npc_newvipshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_newvipshop.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_welfare.o: npc_welfare.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/profession_skill.h \ + ../include/chatmagic.h ../include/npc_welfare.h \ + ../include/npc_exchangeman.h +npc_pauctionman.o: npc_pauctionman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_pauctionman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/pet.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile.bak new file mode 100755 index 0000000..39657f9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/makefile.bak @@ -0,0 +1,3408 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + + +export SHELL=/bin/sh + +INCFLAGS=-I. -I../include -I../lua + +CFLAGS=-w -O -Wall -pipe $(INCFLAGS) +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + +PROG=libnpc.a + +SRC=readnpc.c npcgen.c npctemplate.c npccreate.c npcutil.c \ +npc_warp.c npc_townpeople.c \ +npc_msg.c npc_healer.c npc_oldman.c \ +npc_storyteller.c npc_dengon.c npc_doorman.c \ +npc_npcenemy.c npc_itemchange.c \ +npc_action.c npc_windowman.c npc_savepoint.c \ +npc_windowhealer.c npc_itemshop.c npc_sysinfo.c \ +npc_duelranking.c npc_petskillshop.c npc_petshop.c \ +npc_signboard.c npc_warpman.c npc_exchangeman.c \ +npc_timeman.c npc_bodylan.c npc_mic.c \ +npc_luckyman.c npc_bus.c npc_charm.c npc_quiz.c \ +npc_poolitemshop.c npc_checkman.c npc_janken.c \ +npc_transmigration.c npc_makepair.c \ +npc_familyman.c npc_fmdengon.c npc_fmwarpman.c \ +npc_fmhealer.c npc_bankman.c npc_fmpkman.c\ +npc_airplane.c npc_scheduleman.c npc_fmpkcallman.c\ +npc_manorsman.c npc_riderman.c npc_fmletter.c npc_petmaker.c \ +npc_gamblemaster.c npc_gambleroulette.c npc_petfusion.c\ +npc_newnpcman.c npc_gamblebank.c \ +npc_petracemaster.c npc_petracepet.c \ +npc_freepetskillshop.c \ +npc_eventaction.c npc_vipshop.c npc_autopk.c \ +npc_transerman.c npc_alldoman.c npc_magiccard.c\ +npc_newvipshop.c npc_welfare.c npc_pauctionman.c\ + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) + +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +dos2unix: + dos2unix $(SRC) makefile + +chmod: + chmod 777 $(SRC) makefile + +depend: + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(RM) makefile.bak + +# DO NOT DELETE THIS LINE +readnpc.o: readnpc.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/common.h \ + ../include/npctemplate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npccreate.h ../include/char.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/battle.h \ + ../include/trade.h ../include/configfile.h +npcgen.o: npcgen.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npccreate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/npctemplate.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_data.h ../include/buf.h \ + ../include/object.h ../include/readmap.h ../include/item.h \ + ../include/handletime.h ../include/map_deal.h +npctemplate.o: npctemplate.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npctemplate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/buf.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/char_data.h ../include/util.h \ + ../include/handletime.h ../include/item.h ../include/anim_tbl.h \ + ../include/configfile.h ../include/autil.h +npccreate.o: npccreate.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/npccreate.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/npctemplate.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/util.h ../include/buf.h ../include/readmap.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_data.h ../include/handletime.h ../include/configfile.h \ + ../include/autil.h +npcutil.o: npcutil.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char.h ../include/char_base.h ../include/version.h \ + ../include/skill.h ../include/util.h /usr/include/sys/time.h \ + /usr/include/time.h /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/configfile.h ../include/object.h \ + ../include/item.h ../include/map_deal.h ../include/npcutil.h \ + ../include/npc_door.h ../include/readmap.h ../include/npccreate.h \ + ../include/enemy.h ../include/autil.h ../include/family.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +npc_warp.o: npc_warp.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/map_deal.h \ + ../include/readmap.h ../include/npccreate.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_townpeople.o: npc_townpeople.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/handletime.h ../include/anim_tbl.h ../include/npc_door.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h +npc_msg.o: npc_msg.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_base.h ../include/npcutil.h +npc_healer.o: npc_healer.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/npc_healer.h +npc_oldman.o: npc_oldman.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/object.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h +npc_storyteller.o: npc_storyteller.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h +npc_dengon.o: npc_dengon.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h +npc_doorman.o: npc_doorman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/item.h ../include/util.h \ + ../include/handletime.h ../include/npc_doorman.h ../include/npc_door.h \ + ../include/npcutil.h ../include/configfile.h +npc_npcenemy.o: npc_npcenemy.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_npcenemy.h ../include/battle.h ../include/trade.h \ + ../include/enemy.h ../include/readmap.h ../include/encount.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/configfile.h ../include/anim_tbl.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_itemchange.o: npc_itemchange.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_itemchange.h +npc_action.o: npc_action.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_action.h +npc_windowman.o: npc_windowman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowman.h ../include/autil.h +npc_savepoint.o: npc_savepoint.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/configfile.h +npc_windowhealer.o: npc_windowhealer.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowhealer.h +npc_itemshop.o: npc_itemshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h \ + ../include/npc_eventaction.h ../include/readmap.h ../include/log.h \ + ../include/family.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h +npc_sysinfo.o: npc_sysinfo.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/char_event.h ../include/object.h ../include/handletime.h \ + ../include/magic.h ../include/npcutil.h ../include/char_data.h \ + ../include/chatmagic.h ../include/net.h ../include/configfile.h \ + ../include/npcgen.h +npc_duelranking.o: npc_duelranking.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/net.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_duelranking.h \ + ../include/handletime.h +npc_petskillshop.o: npc_petskillshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/mylua/function.h +npc_petshop.o: npc_petshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/configfile.h ../include/object.h ../include/char_base.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/npc_petshop.h \ + ../include/log.h +npc_signboard.o: npc_signboard.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/readmap.h ../include/family.h +npc_warpman.o: npc_warpman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_warpman.h \ + ../include/map_deal.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/npc_exchangeman.h ../include/log.h \ + ../include/enemy.h ../include/handletime.h ../include/npc_eventaction.h \ + ../include/item_event.h +npc_exchangeman.o: npc_exchangeman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/net.h ../include/char_base.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_exchangeman.h \ + ../include/npc_eventaction.h ../include/log.h ../include/battle.h \ + ../include/trade.h ../include/handletime.h ../include/enemy.h \ + ../include/npc_warp.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/configfile.h \ + ../include/chatmagic.h ../include/npc_transmigration.h +npc_timeman.o: npc_timeman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/npc_oldman.h ../include/title.h \ + ../include/char_data.h ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/log.h ../include/handletime.h +npc_bodylan.o: npc_bodylan.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_windowhealer.h +npc_mic.o: npc_mic.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/npcutil.h \ + ../include/npc_mic.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + ../include/battle.h ../include/trade.h +npc_luckyman.o: npc_luckyman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_luckyman.h +npc_bus.o: npc_bus.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_bus.h ../include/handletime.h +npc_charm.o: npc_charm.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_charm.h +npc_quiz.o: npc_quiz.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npc_quiz.h ../include/npcutil.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/buf.h ../include/function.h \ + ../include/readmap.h ../include/object.h ../include/log.h +npc_poolitemshop.o: npc_poolitemshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/configfile.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npcutil.h \ + ../include/npc_poolitemshop.h ../include/log.h ../include/handletime.h +npc_checkman.o: npc_checkman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h +npc_janken.o: npc_janken.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/common.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/npc_janken.h ../include/npcutil.h ../include/char.h \ + ../include/char_base.h ../include/char_data.h ../include/item.h \ + ../include/char.h ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/buf.h ../include/function.h \ + ../include/readmap.h ../include/object.h ../include/log.h \ + ../include/npc_exchangeman.h +npc_transmigration.o: npc_transmigration.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/npc_transmigration.h ../include/configfile.h \ + ../include/npc_pettransman.h +npc_makepair.o: npc_makepair.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_transerman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_makepair.h \ + ../include/npc_eventaction.h +npc_familyman.o: npc_familyman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_familyman.h \ + ../include/family.h ../include/autil.h +npc_fmdengon.o: npc_fmdengon.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_fmdengon.h ../include/family.h \ + ../include/npc_scheduleman.h +npc_fmwarpman.o: npc_fmwarpman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_fmwarpman.h \ + ../include/npc_scheduleman.h ../include/readmap.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/handletime.h \ + ../include/family.h ../include/configfile.h +npc_fmhealer.o: npc_fmhealer.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h +npc_bankman.o: npc_bankman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_bankman.h \ + ../include/family.h ../include/autil.h +npc_fmpkman.o: npc_fmpkman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_fmpkman.h \ + ../include/npc_scheduleman.h ../include/npc_fmwarpman.h \ + ../include/family.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h +npc_airplane.o: npc_airplane.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_airplane.h ../include/handletime.h +npc_scheduleman.o: npc_scheduleman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_scheduleman.h \ + ../include/family.h +npc_fmpkcallman.o: npc_fmpkcallman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/npc_fmpkcallman.h ../include/family.h \ + ../include/readmap.h ../include/battle.h ../include/trade.h \ + ../include/log.h ../include/npc_scheduleman.h ../include/handletime.h +npc_manorsman.o: npc_manorsman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/string.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/npcutil.h \ + ../include/handletime.h ../include/npc_scheduleman.h \ + ../include/family.h ../include/npc_manorsman.h \ + ../include/saacproto_cli.h ../include/saacproto_util.h ../include/net.h \ + ../include/configfile.h ../include/log.h +npc_riderman.o: npc_riderman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_riderman.h \ + ../include/family.h ../include/log.h ../include/autil.h +npc_fmletter.o: npc_fmletter.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/configfile.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_fmletter.h \ + ../include/family.h ../include/log.h ../include/autil.h +npc_petmaker.o: npc_petmaker.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/enemy.h ../include/chatmagic.h ../include/log.h +npc_gamblemaster.o: npc_gamblemaster.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h ../include/readmap.h \ + ../include/log.h ../include/npc_eventaction.h \ + ../include/npc_gamblemaster.h +npc_gambleroulette.o: npc_gambleroulette.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/readmap.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_gambleroulette.h +npc_petfusion.o: npc_petfusion.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/char_data.h \ + ../include/npcutil.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_petfusion.h ../include/pet.h ../include/chatmagic.h +npc_newnpcman.o: npc_newnpcman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_newnpcman.h ../include/pet.h +npc_gamblebank.o: npc_gamblebank.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/math.h \ + /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ + /usr/include/bits/mathcalls.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/time.h /usr/include/bits/time.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/enemy.h ../include/log.h \ + ../include/battle.h ../include/trade.h ../include/readmap.h \ + ../include/handletime.h ../include/configfile.h \ + ../include/npc_gamblebank.h +npc_petracemaster.o: npc_petracemaster.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_petracemaster.h +npc_petracepet.o: npc_petracepet.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h \ + ../include/npc_petracepet.h +npc_freepetskillshop.o: npc_freepetskillshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/configfile.h \ + ../include/util.h ../include/npc_eventaction.h \ + ../include/npc_freepetskillshop.h ../include/mylua/function.h +npc_eventaction.o: npc_eventaction.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/time.h \ + /usr/include/bits/time.h ../include/char.h ../include/char_base.h \ + ../include/version.h ../include/skill.h ../include/util.h \ + /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/map_deal.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/log.h \ + ../include/enemy.h ../include/handletime.h ../include/npc_eventaction.h \ + ../include/family.h ../include/configfile.h \ + ../include/npc_transmigration.h ../include/npc_exchangeman.h \ + ../include/profession_skill.h ../include/chatmagic.h +npc_vipshop.o: npc_vipshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_vipshop.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_autopk.o: npc_autopk.c ../include/version.h ../include/correct_bug.h \ + ../include/common.h /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_autopk.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/npc_healer.h ../include/configfile.h +npc_transerman.o: npc_transerman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_transerman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_alldoman.o: npc_alldoman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h /usr/include/ctype.h \ + /usr/include/endian.h /usr/include/bits/endian.h ../include/object.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char.h ../include/char_base.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/util.h \ + ../include/npcutil.h ../include/item.h ../include/readmap.h \ + ../include/enemy.h ../include/chatmagic.h ../include/log.h \ + ../include/npc_itemchange.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/npc_eventaction.h \ + ../include/npc_charm.h ../include/npc_alldoman.h +npc_magiccard.o: npc_magiccard.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/handletime.h ../include/readmap.h \ + ../include/log.h ../include/enemy.h ../include/npc_eventaction.h \ + ../include/pet.h ../include/battle.h ../include/trade.h \ + ../include/chatmagic.h ../include/npc_magiccard.h +npc_newvipshop.o: npc_newvipshop.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_newvipshop.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h +npc_welfare.o: npc_welfare.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/lssproto_serv.h ../include/lssproto_util.h \ + /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/pet_skill.h ../include/readmap.h \ + ../include/battle.h ../include/trade.h ../include/profession_skill.h \ + ../include/chatmagic.h ../include/npc_welfare.h \ + ../include/npc_exchangeman.h +npc_pauctionman.o: npc_pauctionman.c ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h /usr/include/string.h ../include/char.h \ + ../include/char_base.h ../include/version.h ../include/skill.h \ + ../include/util.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/bits/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + ../include/title.h ../include/addressbook.h ../include/net.h \ + ../include/autil.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/luaconf.h ../lua/lauxlib.h ../lua/lua.h ../lua/lualib.h \ + ../include/char_data.h ../include/item.h ../include/char.h \ + ../include/object.h ../include/char_base.h ../include/npcutil.h \ + ../include/npc_pauctionman.h ../include/lssproto_serv.h \ + ../include/lssproto_util.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h ../include/readmap.h ../include/battle.h \ + ../include/trade.h ../include/log.h ../include/enemy.h \ + ../include/handletime.h ../include/npc_eventaction.h \ + ../include/longzoro/sasql.h ../include/longzoro/version.h \ + ../include/pet.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_action.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_action.c new file mode 100644 index 0000000..26c85e5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_action.c @@ -0,0 +1,137 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_action.h" + +/* + * ʧ ɱNPC + * ǩԻ߯Ի·ֻ + * ʣ׷ Ȼ¼ʧ巴 ɱئУ + * + * ¦ѡ + * msgcol: ⼰ƣ۷ɻ + * normal: ɧȻ֧ ئʧ帲ƻ߯ + * attack: ʧ帲߯ + * damage: ĸëʧ帲߯ + * down: ľʧ帲߯ + * sit: ʧ帲ƻ߯ + * hand: ëʧ帲ƻ߯ + * pleasure: ʧ帲ƻ߯ + * angry: ʧ帲ƻ߯ + * sad: Ƹʧ帲ƻ߯ + * guard: ʧ帲ƻ߯ + */ + + +#define NPC_ACTION_MSGCOLOR_DEFAULT CHAR_COLORYELLOW + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; + +/********************************* +* +*********************************/ +BOOL NPC_ActionInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int tmp; + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "msgcol"); + if( tmp == -1 ) tmp = NPC_ACTION_MSGCOLOR_DEFAULT; + CHAR_setWorkInt( meindex, CHAR_WORK_MSGCOLOR, tmp); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEACTION ); + + + return TRUE; +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_ActionTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* */ + if( !NPC_Util_charIsInFrontOfChar( talkerindex, meindex, 1 )) return; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, + "normal", + buf, sizeof( buf)) + != NULL ) + { + CHAR_talkToCli( talkerindex, meindex ,buf , + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR )); + } + +} +/********************************* +* watch +*********************************/ +void NPC_ActionWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ) +{ + int meindex; + int index; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + int i; + struct { + CHAR_ACTION act; + char *string; + }searchtbl[] = { + { CHAR_ACTATTACK, "attack"}, + { CHAR_ACTDAMAGE, "damage"}, + { CHAR_ACTDOWN, "down"}, + { CHAR_ACTSIT, "sit"}, + { CHAR_ACTHAND, "hand"}, + { CHAR_ACTPLEASURE, "pleasure"}, + { CHAR_ACTANGRY, "angry"}, + { CHAR_ACTSAD, "sad"}, + { CHAR_ACTGUARD, "guard"}, + { CHAR_ACTNOD, "nod"}, + { CHAR_ACTTHROW, "throw"}, + }; + + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) return; + index = OBJECT_getIndex( objindex); + /* 弰 ɱ */ + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return; + + meindex = OBJECT_getIndex( meobjindex); + + /* Ȼƥئ ɱئ */ + if( NPC_Util_isFaceToFace( meindex, index, 1 ) != TRUE ) return; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + for( i = 0; i < arraysizeof( searchtbl); i ++ ) { + if( searchtbl[i].act == act) { + if( NPC_Util_GetStrFromStrWithDelim( argstr, + searchtbl[i].string, + buf, sizeof( buf)) + != NULL ) + { + CHAR_talkToCli( index, meindex ,buf , + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR )); + break; + } + } + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_airplane.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_airplane.c new file mode 100644 index 0000000..68edbdb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_airplane.c @@ -0,0 +1,761 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_airplane.h" +#include "handletime.h" + +/* + * (Made from Bus) + */ +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +enum { + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT1, /* ߣ */ + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, /* ߣ */ + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, /* */ + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, /* 微Ի ߡ ࡰԻ */ + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, + NPC_WORK_ONEWAYFLG = CHAR_NPCWORKINT11, + NPC_WORK_RUNWAVE = CHAR_NPCWORKINT13, +}; + +/* ⼰enum */ +enum { + NPC_AIR_MSG_GETTINGON, + NPC_AIR_MSG_NOTPARTY, + NPC_AIR_MSG_OVERPARTY, + NPC_AIR_MSG_DENIEDITEM, + NPC_AIR_MSG_ALLOWITEM, + NPC_AIR_MSG_LEVEL, + NPC_AIR_MSG_GOLD, + NPC_AIR_MSG_EVENT, + NPC_AIR_MSG_START, + NPC_AIR_MSG_END, +}; +typedef struct { + char option[32]; + char defaultmsg[128]; +}NPC_AIR_MSG; +NPC_AIR_MSG airmsg[] = { + { "msg_gettingon", "PAON޷;ࡣ"}, + { "msg_notparty", "PAPAON޷ŶӼࡣ"}, + { "msg_overparty", "PAON"}, + { "msg_denieditem", "PAPAONҿɲҪߣ"}, + { "msg_allowitem", "~(ҪǸ߰!)"}, + { "msg_level", "PAPAONĵȼࡣ"}, + { "msg_stone", "PAPAONǮࡣ"}, + { "msg_event", "PAON޷ࡣ"}, + { "msg_start", "~()"}, + { "msg_end", "~()"} +}; + +static int NPC_AirSetPoint( int meindex, char *argstr); +static void NPC_AirSetDestPoint( int meindex, char *argstr); +static BOOL NPC_AirCheckDeniedItem( int meindex, int charaindex, char *argstr); +static BOOL NPC_AirCheckLevel( int meindex, int charaindex, char *argstr); +static int NPC_AirCheckStone( int meindex, int charaindex, char *argstr); +static void NPC_AirSendMsg( int meindex, int talkerindex, int tablenum); +static int NPC_AirGetRoutePointNum( int meindex, char *argstr ); +static void NPC_Air_walk( int meindex); + +#define NPC_AIR_LOOPTIME 100 +#define NPC_AIR_WAITTIME_DEFAULT 180 +#define NPC_AIR_WAITINGMODE_WAITTIME 5000 + +/********************************* +* +*********************************/ +BOOL NPC_AirInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i; + char buf[256],buf1[256]; + int routenum; + int waittime; + int seflg; + int onewayflg; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* ئľئ¦Ѽ */ + routenum = NPC_Util_GetNumFromStrWithDelim( argstr, "routenum"); + if( routenum == -1 ) { + print( "npcair:nothing routenum \n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, routenum); + + for( i = 1; i <= routenum; i ++ ) { + char routetostring[64]; + snprintf( routetostring, sizeof( routetostring), "routeto%d", i); + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route to \n"); + return FALSE; + } + } + //ANDY_ADD NPC_WORK_RUNWAVE + if( NPC_Util_GetStrFromStrWithDelim( argstr, "WAVE",buf1, sizeof(buf1)) == NULL ) { + CHAR_setWorkInt( meindex, NPC_WORK_RUNWAVE, 77); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_RUNWAVE, atoi( buf1) ); + } + + waittime = NPC_Util_GetNumFromStrWithDelim( argstr, "waittime"); + if( waittime == -1 ) waittime = NPC_AIR_WAITTIME_DEFAULT; + CHAR_setWorkInt( meindex, NPC_WORK_WAITTIME, waittime); + seflg = NPC_Util_GetNumFromStrWithDelim( argstr, "seflg"); + if( seflg == -1 ) seflg = TRUE; + CHAR_setWorkInt( meindex, NPC_WORK_SEFLG, seflg); + + onewayflg = NPC_Util_GetNumFromStrWithDelim( argstr, "oneway"); + if( onewayflg == -1 ) onewayflg = FALSE; // default + CHAR_setWorkInt( meindex, NPC_WORK_ONEWAYFLG, onewayflg); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEBUS ); + + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, 2); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 0); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, 0); + + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, + NPC_AIR_WAITINGMODE_WAITTIME); + + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + + for( i = 0; i < getPartyNum(meindex ); i ++) { + CHAR_setWorkInt( meindex, CHAR_WORKPARTYINDEX1 + i, -1); + } + + /* */ +{ + int rev; + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + //print( "route:%d\n",CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + /* Ƿ */ + rev = NPC_Util_GetNumFromStrWithDelim( argstr, "reverse"); + if( rev == 1 ) { + int num = NPC_AirGetRoutePointNum( meindex, argstr); + if( num <= 0 ) { + print( "npcairplane:֣\n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 1); + } + /* ë */ + NPC_AirSetPoint( meindex, argstr); + /* ë */ + NPC_AirSetDestPoint( meindex, argstr); +} + + return TRUE; +} + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_AirTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + int i; + int partyflg = FALSE; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE); + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* мɡ ū Ʃ */ + for( i = 0; i < getPartyNum(meindex ); i ++ ) { + int index = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX(index)){ + if( index == talkerindex) { + partyflg = TRUE; + } + } + } + if( !partyflg ) { + //NPC_AirCheckJoinParty( meindex, talkerindex, TRUE); + } + else { + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) == 0 ) { + int i; + // #define NPC_AIR_DEBUGROUTINTG "routingtable:" + if( strstr( szMes, "" ) || + strstr( szMes, "" ) || + strstr( szMes, "Go" ) || + strstr( szMes, "go" )) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //andy_reEdit NPC_WORK_RUNWAVE + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_AirSendMsg( meindex, partyindex, NPC_AIR_MSG_START); + } + } + } + } + } +} +/************************************** + * + **************************************/ +void NPC_AirLoop( int meindex) +{ + int i; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE); + switch( CHAR_getWorkInt( meindex, NPC_WORK_MODE )) { + case 0: + /* ƹݣë */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) + < NowTime.tv_sec) + { + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //ANDY_reEdit + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_AirSendMsg( meindex, partyindex, NPC_AIR_MSG_START); + } + } + + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + } + return; + case 1: + /* */ + NPC_Air_walk( meindex); + case 2: + /* Ȼƹ */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + (CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) /3) + < NowTime.tv_sec) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + + } + return; + case 3: + /* ƻ֣ͷʧ мб + * Ƴƥëľ֧ + */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + 3 < NowTime.tv_sec){ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_WAITINGMODE_WAITTIME); + { + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, + CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP)^1); + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP) == 1) { + int num = NPC_AirGetRoutePointNum( meindex, argstr); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +1); + } + NPC_AirSetPoint( meindex, argstr); + NPC_AirSetDestPoint( meindex, argstr); + CHAR_DischargeParty( meindex, 0); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + if ((CHAR_getWorkInt(meindex, NPC_WORK_ONEWAYFLG) == 1) && + (CHAR_getWorkInt(meindex, NPC_WORK_ROUNDTRIP) == 1) ){ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 1); + } else + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + } + return; + default: + break; + } +} +/************************************** + * ʣ + **************************************/ +static void NPC_Air_walk( int meindex) +{ + POINT start, end; + int dir; + int ret; + int i; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE ); + + /* */ + /* ݼ */ + start.x = CHAR_getInt( meindex, CHAR_X); + start.y = CHAR_getInt( meindex, CHAR_Y); + end.x = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOX); + end.y = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOY); + + /* ׼ƥݼ̼ */ + if( start.x == end.x && start.y == end.y ) { + int add = 1; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP ) == 1 ) { + add *= -1; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +add); + if( NPC_AirSetPoint( meindex, argstr) == FALSE ) { + /* */ + /* ƹ */ + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //ANDY_reEdit + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_AirSendMsg( meindex, partyindex, NPC_AIR_MSG_END); + } + } + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; + } + else { + return; + } + } + /*-------------------------------------------------------*/ + /* ھ */ + + /* ëƻ */ + dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + + /* ɡ ūƥ */ + end.x = CHAR_getInt( meindex, CHAR_X); + end.y = CHAR_getInt( meindex, CHAR_Y); + + if( dir >= 0 && dir <= 7 ) { + /* */ + ret = CHAR_walk( meindex, dir, 0); + + if( ret == CHAR_WALKSUCCESSED ) { + /* лئëھ */ + int i; + int mefl=CHAR_getInt( meindex, CHAR_FLOOR); + // print("airmax=%d",getPartyNum(meindex )); + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int toindex = CHAR_getWorkInt( meindex, i + CHAR_WORKPARTYINDEX1); + // print("\n i=%d toindex=%d check=%d",i,toindex,CHAR_CHECKINDEX(toindex)); + if( !CHAR_CHECKINDEX(toindex) )continue; + int fl = CHAR_getInt( toindex, CHAR_FLOOR); + int xx = CHAR_getInt( toindex, CHAR_X); + int yy = CHAR_getInt( toindex, CHAR_Y); + // print("\n i=%d calc=%d",i,(abs(xx-end.x)+abs(yy-end.y))); + if( CHAR_CHECKINDEX(toindex) && + (mefl==fl) && (abs(xx-end.x)+abs(yy-end.y)<20) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + start.x = xx; + start.y = yy; + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + /* ·ūë ¿б + * ݼҷ󡼰Ҽ ëܰ + */ + end = start; + // print("\n i=%d parent_dir=%d",i,parent_dir); + if( parent_dir != -1 ) { + CHAR_walk( toindex, parent_dir, 0); + } + } + } + } + } +} +/************************************** + * ݼë + **************************************/ +static int NPC_AirSetPoint( int meindex, char *argstr) +{ + char buf[4096]; + char buf2[256]; + char buf3[256]; + int floor,warpx,warpy; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route \n"); + return FALSE; + } + + ret = getStringFromIndexWithDelim( buf, ";", + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT), + buf2, sizeof(buf2)); + if( ret == FALSE ) return FALSE; + + // Arminius: add floor + + ret = getStringFromIndexWithDelim( buf2, ",", 1, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + floor = atoi(buf3); + + ret = getStringFromIndexWithDelim( buf2, ",", 2, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, atoi( buf3)); + warpx = atoi(buf3); + + ret = getStringFromIndexWithDelim( buf2, ",", 3, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, atoi( buf3)); + warpy = atoi(buf3); + + if (floor!=CHAR_getInt(meindex, CHAR_FLOOR)) { + int i; + CHAR_warpToSpecificPoint(meindex, floor, warpx, warpy); + + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int toindex = CHAR_getWorkInt( meindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + CHAR_warpToSpecificPoint(toindex, floor, warpx, warpy); + } + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, warpx); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, warpy); + } + + return TRUE; +} +/************************************** + * route įգ 󡻥ؤչľë + * į屾£ + **************************************/ +static void NPC_AirSetDestPoint( int meindex, char *argstr) +{ + char buf[256]; + char routename[256]; + + snprintf( routename, sizeof( routename), "routename%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routename, buf, sizeof( buf)) + != NULL ) + { + CHAR_setChar( meindex, CHAR_OWNTITLE, buf); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼշֻ + **************************************/ +static BOOL NPC_AirCheckDeniedItem( int meindex, int charaindex, char *argstr) +{ + char buf[1024]; + BOOL found = TRUE; + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "denieditem", buf, sizeof( buf)) + != NULL ) + { + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + for( j = 0; j < CheckCharMaxItem(charaindex); j ++) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + found = FALSE; + break; + } + } + } + } + } + return found; +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼئֻ + **************************************/ +BOOL NPC_AirCheckAllowItem( int meindex, int charaindex, BOOL pickupmode) +{ + char buf[1024]; + BOOL found = TRUE; + BOOL pickup = FALSE; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pickupitem", buf, sizeof( buf)) + != NULL ) + { + pickup = TRUE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "allowitem", buf, sizeof( buf)) + != NULL ) + { + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + BOOL getflg; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + getflg = FALSE; + for( j = 0; j < CheckCharMaxItem(charaindex); j ++) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + /* Ȼ¾գݹʧ ةë */ + if( pickupmode && pickup && !getflg) { + CHAR_DelItem( charaindex, j); + getflg = TRUE; + } + break; + } + } + } + if( j == CheckCharMaxItem(charaindex)) { + found = FALSE; + break; + } + } + } + return found; +} + +/************************************** + * ϶ýľìﶯ + **************************************/ +static BOOL NPC_AirCheckLevel( int meindex, int charaindex, char *argstr) +{ + int level; + + /* ئľئ¦Ѽ */ + level = NPC_Util_GetNumFromStrWithDelim( argstr, "needlevel"); + if( level == -1 ) { + return TRUE; + } + if( CHAR_getInt( charaindex, CHAR_LV) >= level ) return TRUE; + + return FALSE; +} + +/************************************** + * ë + * -1 0 ݾ ۢStone + **************************************/ +static int NPC_AirCheckStone( int meindex, int charaindex, char *argstr) +{ + int gold; + + /* ئľئ¦Ѽ */ + gold = NPC_Util_GetNumFromStrWithDelim( argstr, "needstone"); + if( gold == -1 ) { + return 0; + } + if( CHAR_getInt( charaindex, CHAR_GOLD) >= gold ) return gold; + + return -1; +} +/************************************** + * ë˪ + * ¦Ѽ⻥ئľɷɻë˪ + **************************************/ +static void NPC_AirSendMsg( int meindex, int talkerindex, int tablenum) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + char msg[256]; + if( tablenum < 0 || tablenum >= arraysizeof( airmsg)) return; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, airmsg[tablenum].option, buf, sizeof( buf)) + != NULL ) + { + strcpy( msg, buf); + } + else { + snprintf( msg, sizeof(msg),airmsg[tablenum].defaultmsg); + } + CHAR_talkToCli( talkerindex, meindex, msg, CHAR_COLORYELLOW); +} +/************************************** + * ƤP̼ë + **************************************/ +static int NPC_AirGetRoutePointNum( int meindex, char *argstr ) +{ + int i; + char buf[4096]; + char buf2[256]; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route \n"); + return -1; + } + for( i = 1; ; i ++ ) { + ret = getStringFromIndexWithDelim( buf, ";", i, buf2, sizeof(buf2)); + if( ret == FALSE) break; + } + return( i -1); +} +BOOL NPC_AirCheckJoinParty( int meindex, int charaindex, BOOL msgflg) +{ + //int fd; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int ret; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* */ + if( !NPC_Util_charIsInFrontOfChar( charaindex, meindex, 1 )) return FALSE; + /* ַ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) != 0 ) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_GETTINGON); + return FALSE; + } + /* շֻ */ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) != CHAR_PARTY_NONE) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_NOTPARTY); + return FALSE; + } + /* ɡ ūë */ + if( CHAR_getEmptyPartyArray( meindex) == -1 ) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_OVERPARTY); + return FALSE; + } + /* ʧ ةë(ʧ ة) */ + if( !NPC_AirCheckDeniedItem( meindex, charaindex, argstr)) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_DENIEDITEM); + return FALSE; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ) { + CHAR_talkToCli( charaindex, -1, "޷Яϻ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + + /* ʧ ةë( ۢʧ ة) */ + if( !NPC_AirCheckAllowItem( meindex, charaindex, FALSE)) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_ALLOWITEM); + return FALSE; + } + /* ìPë */ + if( !NPC_AirCheckLevel( meindex, charaindex, argstr)) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_LEVEL); + return FALSE; + } + /* ì */ +// if( CHAR_getInt( charaindex, CHAR_NOWEVENT) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT2) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT3) != 0 ) +// { +// if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_EVENT); +// return FALSE; +// } + /* żë ë¼ƥ ͱ³ */ + ret = NPC_AirCheckStone( meindex, charaindex, argstr); + if( ret == -1 ) { + if( msgflg) NPC_AirSendMsg( meindex, charaindex, NPC_AIR_MSG_GOLD); + return FALSE; + } + if( ret != 0 ) { + char msgbuf[128]; + /* ë */ + CHAR_setInt( charaindex, CHAR_GOLD, + CHAR_getInt( charaindex, CHAR_GOLD) - ret); + /* ˪ */ + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + snprintf( msgbuf, sizeof( msgbuf), "֧%d Stone", ret); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + } + /* ɡ ū */ + //CHAR_JoinParty_Main( charaindex, meindex); + + //fd = getfdFromCharaIndex( charaindex ); + + //lssproto_PR_send( fd, 1, 1); + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_alldoman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_alldoman.c new file mode 100644 index 0000000..71ef643 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_alldoman.c @@ -0,0 +1,392 @@ +#include "version.h" +#include +#include +#include +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" +#include "enemy.h" +#include "chatmagic.h" +#include "log.h" +#include "npc_itemchange.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_eventaction.h" +#include "npc_charm.h" + +#ifdef _ALLDOMAN +#include "npc_alldoman.h" + +#define MAX_HERO_COLUMN 7 +#define MAX_HERO_LIST 100 +char Herolist[MAX_HERO_LIST][MAX_HERO_COLUMN][72]; + +int sort[MAX_HERO_LIST][2]; +int countnum = -1 ; +int showpage = 1 ; +int totalpage = 1; + +static void NPC_Alldoman_selectWindow( int meindex, int talker, int seqno,char *data); + +void NPC_AlldomanWindowTalked(int meindex, int talkerindex, int seqno, int select,char *data) +{ + char buf2[256]; + char buf[256]; + int i; + int playernum = CHAR_getPlayerMaxNum(); + //andy_log + //print( "seqno:%d\n", seqno); + switch(seqno) + { + case NPC_ALLDOMAN_MAIN_WND: + if ( select == WINDOW_BUTTONTYPE_NEXT ) { + showpage ++ ; + NPC_Alldoman_selectWindow(meindex , talkerindex , 4 ,""); + } + if ( select == WINDOW_BUTTONTYPE_OK ) { + //CHAR_talkToCli(talkerindex,meindex,"ˣ",CHAR_COLORRED); + showpage = 1 ; + NPC_Alldoman_selectWindow(meindex , talkerindex, 5 ,""); + } + break; + case NPC_ALLDOMAN_SELECT_WND: + if(atoi(data)==2) { + //CHAR_talkToCli(talkerindex,meindex,"",CHAR_COLORRED); + if ( CHAR_getInt( talkerindex , CHAR_FLOOR ) != 8200 ) { + CHAR_talkToCli(talkerindex,-1,"ֻܸӢۿд",CHAR_COLORRED); + break; + } + if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) > 132 || + CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) <= 0 ) { + CHAR_setWorkInt( talkerindex , CHAR_WORKHEROFLOOR , 0 ) ; + CHAR_talkToCli(talkerindex,-1,"ֻܸӢۿд",CHAR_COLORRED); + break; + } + sprintf( buf2 , "ó˴%3d֤ͼԼʯ" , CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) ); + CHAR_talkToCli(talkerindex,-1,buf2,CHAR_COLORRED); + if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) == 132 ) { + sprintf( buf2 , "%s" , "˹½Ӣ" ) ; + //ﶥȫϵ㲥 + sprintf( buf , "%sӢսɷ֮齫Ϣ֪ͨȫ磬µӢ۵!!" , CHAR_getChar( talkerindex, CHAR_NAME ) ); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, buf, CHAR_COLORBLUE2); + } + } + } + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 130 ) + sprintf( buf2 , "%s" , "˹½սʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 125 ) + sprintf( buf2 , "%s" , "˹½ʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 120 ) + sprintf( buf2 , "%s" , "˹Ӣ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 115 ) + sprintf( buf2 , "%s" , "˹ʹսʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 110 ) + sprintf( buf2 , "%s" , "ķսʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 100 ) + sprintf( buf2 , "%s" , "˿սʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 80 ) + sprintf( buf2 , "%s" , "̹սʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 60 ) + sprintf( buf2 , "%s" , "ضսʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 40 ) + sprintf( buf2 , "%s" , "ħʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 20 ) + sprintf( buf2 , "%s" , "ʥʿ" ) ; + else if ( CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) >= 1 ) + sprintf( buf2 , "%s" , "ʿ" ) ; + else + sprintf( buf2 , " " ); + saacproto_UpdataStele_send ( + acfd , + CHAR_getChar( talkerindex , CHAR_CDKEY ), + CHAR_getChar( talkerindex , CHAR_NAME ) , + buf2 , + CHAR_getInt( talkerindex , CHAR_LV ) , + CHAR_getInt( talkerindex , CHAR_TRANSMIGRATION) , + 10 , + CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR ) + ) ; + //WorkFloor + CHAR_setWorkInt( talkerindex , CHAR_WORKHEROFLOOR , 0 ) ; + } + if(atoi(data)==4) { + //CHAR_talkToCli(talkerindex,meindex,"",CHAR_COLORRED); + showpage = 1 ; + NPC_Alldoman_selectWindow(meindex , talkerindex, 6 ,""); + } + if(atoi(data)==6) { + //CHAR_talkToCli(talkerindex,meindex,"",CHAR_COLORRED); + } + break; + case NPC_ALLDOMAN_LIST_WND: + if( select == WINDOW_BUTTONTYPE_OK ){ + print("\nSyu log FloorWorkint => %d" , CHAR_getWorkInt( talkerindex , CHAR_WORKHEROFLOOR )); + } + if( select == WINDOW_BUTTONTYPE_PREV && showpage > 1 ) { + showpage -- ; + NPC_Alldoman_selectWindow(meindex , talkerindex, 6 ,"" ); + } + if( select == WINDOW_BUTTONTYPE_NEXT && showpage < totalpage ) { + showpage ++ ; + NPC_Alldoman_selectWindow(meindex , talkerindex, 6 ,""); + } + break; + } +} + +static void NPC_Alldoman_selectWindow( int meindex, int talker, int num, char *data) +{ + int buttontype = 0,windowtype = 0,windowno = 0 , i ; + int fd = getfdFromCharaIndex( talker); + char token[1024]; + char token2[100 * 100]; + + + //andy_log + // print( "NPC_Alldoman_selectWindow( num:%d)\n", num); + switch(num) + { + case 4: + if ( showpage == 1 ) { + buttontype = WINDOW_BUTTONTYPE_NEXT; + sprintf( token, "ʥʱ³ִУ֮һ⣬˹ijϴɹʶʿǰȺĻȺʿںڸȺսϣʵ⣬ʿأʿѡڻضͨ·"); + } + else if ( showpage == 2 ) { + buttontype = WINDOW_BUTTONTYPE_NEXT; + sprintf( token, "ĵĵֿ峤ټͨ³ĺͨڴӿǰڷ˵Ϊʥʱ죬Ϊʥʱʿʯ˵ضΪӢսЧҵоﵽǿǿ"); + } + else if ( showpage == 3) { + buttontype = WINDOW_BUTTONTYPE_OK; + sprintf( token, "ΪĿģ˹½ϢӢ´Ӣսģشگȫ˹Ӣۣ\n\n ӢսίԱ"); + } + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = NPC_ALLDOMAN_MAIN_WND; + lssproto_WN_send(fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token ); + break; + case 5: + buttontype = WINDOW_BUTTONTYPE_NONE; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = NPC_ALLDOMAN_SELECT_WND; + sprintf(token, + "0\n\nдʯ" + "\n\n" + "\n\nȡ" + ); + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),token); + break; + case 6: + if ( totalpage != 1 && showpage == 1 ) + buttontype = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_NEXT; + else if ( totalpage == 1 ) + buttontype = WINDOW_BUTTONTYPE_OK ; + else if ( totalpage != 1 && showpage == totalpage ) + buttontype = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; + else if ( totalpage != 1 && showpage != 1 && showpage != totalpage ) + buttontype = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_NEXT; + windowtype = WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT; + windowno = NPC_ALLDOMAN_LIST_WND; + sprintf ( token2 , "ͷΡ ȼת\n"); + for ( i=0+(showpage-1 )*15; i 1) return; + if( NPC_Util_isFaceToFace( talker, meindex , 1 ) == FALSE ) return; + showpage = 1 ; + NPC_Alldoman_selectWindow(meindex, talker , 4 ,""); +} +void NPC_AlldomanWriteStele ( char *token ) +{ + + int linenum = 0 , i , flag , temp , temp1 , j ; + int lens=0; + char *addr; + if( token == NULL || (lens = strlen( token)) <= 0 ) return; + while( linenum < 100 ){ + for ( i = 0 ; i < MAX_HERO_COLUMN ; i ++ ) { + if( getStringFromIndexWithDelim( token, "|", i + 1 , Herolist[ linenum ][ i ] , sizeof( Herolist[ linenum ][ i ] ) ) == FALSE ){ +#ifdef _ALLDOMAN_DEBUG + countnum = 0 ; + for ( i = 0 ; i < MAX_HERO_LIST ; i ++ ) { + sort[i][0] = atoi ( Herolist[i][6] ) ; + sort[i][1] = i ; + if ( sort[i][0] != 0 && sort[i][0] != -1 ) + countnum ++ ; + } + + for ( i = 0 ; i < MAX_HERO_LIST - 1 ; i ++ ) { + flag = 0 ; + for ( j = 0 ; j < MAX_HERO_LIST - 1 ; j ++ ) { + if ( sort[j][0] > sort[j+1][0] ){ + flag = 1 ; + temp = sort[j][0]; + temp1 = sort[j][1]; + sort[j][0] = sort[j + 1][0]; + sort[j][1] = sort[j + 1][1]; + sort[j+1][0] = temp; + sort[j+1][1] = temp1; + } + } + if ( flag != 1 ) + break; + } + totalpage = countnum / 15 ; + if ( ( countnum % 15 ) != 0 ) + totalpage ++; +#endif + return; + } + } + linenum ++; + + if ( (addr = strstr ( token , "\n" )) == NULL ) break; + strcpy ( token , addr + 1 ) ; + if( token == NULL || (lens = strlen( token)) <= 0 ) { +#ifdef _ALLDOMAN_DEBUG + countnum = 0 ; + for ( i = 0 ; i < MAX_HERO_LIST ; i ++ ) { + sort[i][0] = atoi ( Herolist[i][6] ) ; + sort[i][1] = i ; + if ( sort[i][0] != 0 && sort[i][0] != -1 ) + countnum ++ ; + } + for ( i = 0 ; i < MAX_HERO_LIST - 1 ; i ++ ) { + flag = 0 ; + for ( j = 0 ; j < MAX_HERO_LIST - 1 ; j ++ ) { + if ( sort[j][0] > sort[j+1][0] ){ + flag = 1 ; + temp = sort[j][0]; + temp1 = sort[j][1]; + sort[j][0] = sort[j + 1][0]; + sort[j][1] = sort[j + 1][1]; + sort[j+1][0] = temp; + sort[j+1][1] = temp1; + } + } + if ( flag != 1 ) + break; + } + totalpage = countnum / 15 ; + if ( ( countnum % 15 ) != 0 ) + totalpage ++; +#endif + return; + } + } + + countnum = 0 ; + for ( i = 0 ; i < MAX_HERO_LIST ; i ++ ) { + sort[i][0] = atoi ( Herolist[i][6] ) ; + sort[i][1] = i ; + if ( sort[i][0] != 0 && sort[i][0] != -1 ) + countnum ++ ; + } + + for ( i = 0 ; i < MAX_HERO_LIST - 1 ; i ++ ) { + flag = 0 ; + for ( j = 0 ; j < MAX_HERO_LIST - 1 ; j ++ ) { + if ( sort[j][0] > sort[j+1][0] ){ + flag = 1 ; + temp = sort[j][0]; + temp1 = sort[j][1]; + sort[j][0] = sort[j + 1][0]; + sort[j][1] = sort[j + 1][1]; + sort[j+1][0] = temp; + sort[j+1][1] = temp1; + } + } + if ( flag != 1 ) + break; + } + + + totalpage = countnum / 15 ; + if ( ( countnum % 15 ) != 0 ) + totalpage ++; +//#endif +} + +void NPC_Alldoman_S_WriteStele( char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ) +{ + int i , j , temp , temp1 , flag ; + for ( i = 0 ; i < MAX_HERO_COLUMN ; i ++ ) { + if ( ( strcmp( Herolist[i][0] , ocdkey ) == 0 ) && ( strcmp( Herolist[i][1] , oname ) == 0 ) ) { + sprintf( Herolist[i][0] , "%s" , ncdkey ) ; + sprintf( Herolist[i][1] , "%s" , nname ) ; + sprintf( Herolist[i][2] , "%s" , title ) ; + sprintf( Herolist[i][3] , "%d" , level ) ; + sprintf( Herolist[i][4] , "%d" , trns ) ; + sprintf( Herolist[i][6] , "%d" , floor ) ; + break; + } + } + countnum = 0 ; + for ( i = 0 ; i < MAX_HERO_LIST ; i ++ ) { + sort[i][0] = atoi ( Herolist[i][6] ) ; + sort[i][1] = i ; + if ( sort[i][0] != 0 && sort[i][0] != -1 ) + countnum ++ ; + } + for ( i = 0 ; i < MAX_HERO_LIST - 1 ; i ++ ) { + flag = 0 ; + for ( j = 0 ; j < MAX_HERO_LIST - 1 ; j ++ ) { + if ( sort[j][0] > sort[j+1][0] ){ + flag = 1 ; + temp = sort[j][0]; + temp1 = sort[j][1]; + sort[j][0] = sort[j + 1][0]; + sort[j][1] = sort[j + 1][1]; + sort[j+1][0] = temp; + sort[j+1][1] = temp1; + } + } + if ( flag != 1 ) + break; + } + totalpage = countnum / 15 ; + if ( ( countnum % 15 ) != 0 ) + totalpage ++ ; +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_autopk.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_autopk.c new file mode 100644 index 0000000..0e8e9c8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_autopk.c @@ -0,0 +1,885 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_autopk.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "npc_healer.h" +#include "configfile.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _GMRELOAD + extern struct GMINFO gminfo[GMMAXNUM]; +#endif + +#ifdef _AUTO_PK + +#define AWARDNO (1 << 0) +#define AWARDPET (1 << 1) +#define AWARDITEM (1 << 2) +#define AWARDALL (AWARDPET|AWARDITEM) + +enum { + WINDOW_START=1, + WINDOW_SELECT, + WINDOW_JOINPK, + WINDOW_PKLIST, + WINDOW_PKINFO, + WINDOW_HISTORY, + WINDOW_HISTORY_NEXT, + WINDOW_HISTORY_PREV, + WINDOW_END, +}; + +typedef struct tagautopk +{ + int winnum; + char cdkey[CDKEYLEN]; + char name[CHARNAMELEN]; +}Autopk; + +typedef struct tagaward +{ + int awardpetid; + int awarditemid; + char awardpet[32]; + char awarditem[32]; + int draw; +}Award; + +static int baward = FALSE; + +Award award[5]; + +Autopk ship[5]; + +BOOL getaward=FALSE; + +int autopklist; +static int autopktime=-1; +static int awardpetid=-1; +static int awarditemid=-1; +static char awardpet[32]; +static char awarditem[32]; + +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_WORK_TIMEFLAG = CHAR_NPCWORKINT9, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; +enum { + NPC_AUTOPK_START, + NPC_AUTOPK_SELECT, + NPC_AUTOPK_JOINPK, + NPC_AUTOPK_PKLIST, + NPC_AUTOPK_PKAWARD, + NPC_AUTOPK_HISTORY, + NPC_AUTOPK_OK, + NPC_AUTOPK_END, +}; +#define STANDBYTIME 50 + +static void NPC_AutoPk_selectWindow( int meindex, int toindex, int num,int select); +BOOL AutoPk_GetHistoryStr( char *token, int page ); +void AutoPk_PKNum( char *token ); +BOOL AutoPk_AddItem( int charindex, int index ); +BOOL AutoPk_AddPet( int charindex, int index ); + + +void setAward( BOOL val ); +BOOL getAward(); + +BOOL NPC_AutoPkInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + +//CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TRANSERMANS); + +//CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + AutoPk_GetAwardStr(); + + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_AutoPkTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_AutoPk_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +void NPC_AutoPkWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data) +{ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( seqno) { + case NPC_AUTOPK_START: + break; + case NPC_AUTOPK_SELECT: + NPC_AutoPk_selectWindow( meindex, talkerindex, WINDOW_SELECT, atoi( data)); + break; + case NPC_AUTOPK_JOINPK: + if(autopktime>2){ + char buf1[128]; + char buf2[255]; +#ifdef _NEW_AUTO_PK + if(CHAR_getInt(talkerindex,CHAR_TRANSMIGRATION)2){ + sprintf(token, " 񶷣УԱ\n\n" + "ǰʼʱ仹ʣ%dӣǷҪμӵǰ𣿣",autopktime); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_AUTOPK_JOINPK; + }else if(autopktime>0){ + sprintf(token, " 񶷣УԱ\n\n" + "PK%dӺʼ!\n޷أ",autopktime); + buttontype = WINDOW_BUTTONTYPE_CANCEL; + }else{ + sprintf(token, " 񶷣УԱ\n\n" + "ĿǰδPK!\nעPKϢ"); + buttontype = WINDOW_BUTTONTYPE_CANCEL; + } + }else if(select==2){ + sprintf(token, " 񶷣У\n"); + strcat(token, "ת ȼ \n"); + AutoPk_PKNum(token); + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_AUTOPK_PKLIST; + }else if(select==3){ + char buff[64]; + sprintf(token, " 񶷣УƷȡ\n"); + strcat(token, "ʤƷ\n"); + if(strlen(award[0].awardpet)>0){ + sprintf(buff, "ھ%s\n", award[0].awardpet); + }else{ + sprintf(buff, "ھ\n"); + } + strcat(token, buff); + if(strlen(award[0].awarditem)>0){ + sprintf(buff, "ھƷ%s\n", award[0].awarditem); + }else{ + sprintf(buff, "ھƷ\n"); + } + strcat(token, buff); + if(strlen(award[1].awardpet)>0){ + sprintf(buff, "Ǿ%s\n", award[1].awardpet); + }else{ + sprintf(buff, "Ǿ\n"); + } + strcat(token, buff); + if(strlen(award[1].awarditem)>0){ + sprintf(buff, "ǾƷ%s\n", award[1].awarditem); + }else{ + sprintf(buff, "ǾƷ\n"); + } + strcat(token, buff); + if(strlen(award[2].awardpet)>0){ + sprintf(buff, "%s\n", award[2].awardpet); + }else{ + sprintf(buff, "\n"); + } + strcat(token, buff); + if(strlen(award[2].awarditem)>0){ + sprintf(buff, "Ʒ%s\n", award[2].awarditem); + }else{ + sprintf(buff, "Ʒ\n"); + } + strcat(token, buff); + if(strlen(award[3].awardpet)>0){ + sprintf(buff, "ʤ%s\n", award[3].awardpet); + }else{ + sprintf(buff, "ʤ\n"); + } + strcat(token, buff); + if(strlen(award[3].awarditem)>0){ + sprintf(buff, "ʤƷ%s\n", award[3].awarditem); + }else{ + sprintf(buff, "ʤƷ\n"); + strcat(token, buff); + } + if(strlen(award[4].awardpet)>0){ + sprintf(buff, "ʤ%s\n", award[4].awardpet); + }else{ + sprintf(buff, "ʤ\n"); + strcat(token, buff); + } + if(strlen(award[4].awarditem)>0){ + sprintf(buff, "ʤƷ%s\n", award[4].awarditem); + }else{ + sprintf(buff, "ʤƷ\n"); + } + strcat(token, buff); + if(baward == FALSE){ + if((!strcmp(ship[0].cdkey, CHAR_getChar( toindex, CHAR_CDKEY)) + && !strcmp(ship[0].name, CHAR_getChar( toindex, CHAR_NAME)) + && award[0].draw != AWARDALL) + || (!strcmp(ship[1].cdkey, CHAR_getChar( toindex, CHAR_CDKEY)) + && !strcmp(ship[1].name, CHAR_getChar( toindex, CHAR_NAME)) + && award[1].draw != AWARDALL) + || (!strcmp(ship[2].cdkey, CHAR_getChar( toindex, CHAR_CDKEY)) + && !strcmp(ship[2].name, CHAR_getChar( toindex, CHAR_NAME)) + && award[2].draw != AWARDALL) + || (!strcmp(ship[3].cdkey, CHAR_getChar( toindex, CHAR_CDKEY)) + && !strcmp(ship[3].name, CHAR_getChar( toindex, CHAR_NAME)) + && award[3].draw != AWARDALL) + || (!strcmp(ship[4].cdkey, CHAR_getChar( toindex, CHAR_CDKEY)) + && !strcmp(ship[4].name, CHAR_getChar( toindex, CHAR_NAME)) + && award[4].draw != AWARDALL)){ + buttontype = WINDOW_BUTTONTYPE_YESNO; + }else{ + buttontype = WINDOW_BUTTONTYPE_CANCEL; + } + windowno = NPC_AUTOPK_PKAWARD; + } + }else if(select==4){ + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, 1); + if(AutoPk_GetHistoryStr(token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE))){ + buttontype = WINDOW_BUTTONTYPE_CANCEL; + }else{ + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + } + windowno = NPC_AUTOPK_HISTORY; + } + break; + case WINDOW_HISTORY_NEXT: + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)+1); + if(AutoPk_GetHistoryStr(token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE))) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_AUTOPK_HISTORY; + break; + case WINDOW_HISTORY_PREV: + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)-1); + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)<1)CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE,1); + if(AutoPk_GetHistoryStr(token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) || CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)==1) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_AUTOPK_HISTORY; + break; + case WINDOW_END: + return; + break; + } + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +BOOL AutoPk_GetHistoryStr( char *token, int page ) +{ + FILE* fp; + fp = fopen("./data/autopk/autopkhistory.txt", "r"); + if (fp == NULL) + { + print("鿴ʷļ򿪴\n"); + return FALSE; + } + typedef struct taghistory + { + char winnum[5]; + char name[CHARNAMELEN]; + }History; + History history[5]; + + char hstime[5],line[255],buf[255]; + int i; + for(i=0;i5)break; + sprintf(buf, "%3d%5d %s\n", + CHAR_getInt( i, CHAR_TRANSMIGRATION), + CHAR_getInt( i, CHAR_LV), + CHAR_getChar( i, CHAR_NAME)); + num++; + strcat(token,buf); + } + } + sprintf(buf, "ǰμPKΪ:%d",num); + strcat(token,buf); +} + +void AutoPk_PKSystemTalk( char *token1, char *token2 ) +{ + int playernum = CHAR_getPlayerMaxNum(); + int i; + for(i=0;i0){ + char buf1[64]; + char buf2[128]; + sprintf(buf1, "ֹμPKʱ仹ʣ%dӣ",autopktime); + if(awardpetid!=-1 && awarditemid==-1) + sprintf(buf2,"ֹμPKʱ仹ʣ%dӣαƷΪ::%d,:%s",autopktime-2,awardpetid,awardpet); + else if(awardpetid==-1 && awarditemid!=-1) + sprintf(buf2,"ֹμPKʱ仹ʣ%dӣαƷΪ::%d,Ʒ:%s",autopktime-2,awarditemid,awarditem); + else if(awardpetid!=-1 && awarditemid!=-1) + sprintf(buf2,"ֹμPKʱ仹ʣ%dӣαƷΪ::%d,:%sͱ:%d,Ʒ:%s",autopktime-2,awardpetid,awardpet,awarditemid,awarditem); + else + sprintf(buf2, "ʽPKʱ仹ʣ%dӣ",autopktime); + AutoPk_PKSystemTalk(buf1, buf2); + }else if(autopktime==0){ + int i,charaindex=0,num=0; + int playernum=CHAR_getPlayerMaxNum(); + for(i=0;i1)break; +#endif + } + } + if(num>1){ + AutoPk_PKSystemTalk("ʽʼ","ʽʼ"); + setAward(TRUE); + }else{ + if(CHAR_CHECKINDEX(charaindex)){ + int fl = 0, x = 0, y = 0; + CHAR_getElderPosition(CHAR_getInt(charaindex, CHAR_LASTTALKELDER), &fl, &x, &y); + CHAR_warpToSpecificPoint(charaindex, fl, x, y); + } + AutoPk_PKSystemTalk("ڲμӱ٣ȡ","ڲμӱ٣ȡ"); + baward = FALSE; + } + } +} + +void AutoPk_PKTimeSet( int pktime ) +{ + autopktime = pktime; + ship[0].winnum=0; + strcpy(ship[0].cdkey, "\0"); + strcpy(ship[0].name, "\0"); + ship[1].winnum=0; + strcpy(ship[1].cdkey, "\0"); + strcpy(ship[1].name, "\0"); + ship[2].winnum=0; + strcpy(ship[2].cdkey, "\0"); + strcpy(ship[2].name, "\0"); + baward = TRUE; +} + +int AutoPk_PKTimeGet( void ) +{ + return autopktime; +} + +void AutoPk_AwardSet( int petid, char *pet, int itemid, char *item ) +{ + if(petid>0){ + awardpetid=petid; + strcpy(awardpet,pet); + }else{ + awardpetid=-1; + } + if(itemid>0){ + awarditemid=itemid; + strcpy(awarditem,item); + }else{ + awarditemid=-1; + } +} + +void AutoPk_ChampionShipSet( int charaindex, int winnum, int win ) +{ + char *cdkey = CHAR_getChar( charaindex, CHAR_CDKEY); + char *name = CHAR_getChar( charaindex, CHAR_NAME); + if(win==0){ + char token[64]; + if(winnum>ship[0].winnum){ + sprintf( token, "%sһɱ˵÷%d֣", name, winnum); + AutoPk_PKSystemTalk(token,token); + if(strstr(ship[0].cdkey,cdkey) && strstr(ship[0].name,name)){ + ship[0].winnum=winnum; + }else if(strstr(ship[1].cdkey,cdkey) && strstr(ship[1].name,name)){ + ship[1].winnum=ship[0].winnum; + strcpy(ship[1].cdkey, ship[0].cdkey); + strcpy(ship[1].name, ship[0].name); + ship[0].winnum=winnum; + strcpy(ship[0].cdkey, cdkey); + strcpy(ship[0].name, name); + }else{ + ship[2].winnum=ship[1].winnum; + strcpy(ship[2].cdkey, ship[1].cdkey); + strcpy(ship[2].name, ship[1].name); + ship[1].winnum=ship[0].winnum; + strcpy(ship[1].cdkey, ship[0].cdkey); + strcpy(ship[1].name, ship[0].name); + ship[0].winnum=winnum; + strcpy(ship[0].cdkey, cdkey); + strcpy(ship[0].name, name); + } + }else if(winnum>ship[1].winnum){ + sprintf( token, "%sڶɱ˵÷%d֣", name, winnum); + AutoPk_PKSystemTalk(token,token); + if(strstr(ship[1].cdkey,cdkey) && strstr(ship[1].name,name)){ + ship[1].winnum=winnum; + }else{ + ship[2].winnum=ship[1].winnum; + strcpy(ship[2].cdkey, ship[1].cdkey); + strcpy(ship[2].name, ship[1].name); + ship[1].winnum=winnum; + strcpy(ship[1].cdkey, cdkey); + strcpy(ship[1].name, name); + } + }else if(winnum>ship[2].winnum){ + sprintf( token, "%sɱ˵÷%d֣", name, winnum); + AutoPk_PKSystemTalk(token,token); + ship[2].winnum=winnum; + strcpy(ship[2].cdkey, cdkey); + strcpy(ship[2].name, name); + } + }else if(win==1){ + ship[3].winnum=winnum; + strcpy(ship[3].cdkey, cdkey); + strcpy(ship[3].name, name); + }else if(win==2){ + ship[4].winnum=winnum; + strcpy(ship[4].cdkey, cdkey); + strcpy(ship[4].name, name); + } +} + +void AutoPk_GetChampionShip( void ) +{ + char token[64]; + if(strlen(ship[0].cdkey)>0){ + sprintf( token, "ϲ%sñPKھɱ˵÷%d֣", ship[0].name, ship[0].winnum); + AutoPk_PKSystemTalk(token,token); + } + if(strlen(ship[1].cdkey)>0){ + sprintf( token, "ϲ%sñPKǾɱ˵÷%d֣", ship[1].name, ship[1].winnum); + AutoPk_PKSystemTalk(token,token); + } + if(strlen(ship[2].cdkey)>0){ + sprintf( token, "ϲ%sñPKɱ˵÷%d֣", ship[2].name, ship[2].winnum); + AutoPk_PKSystemTalk(token,token); + } + sprintf( token, "ϲ%s%sñPKʤ", ship[3].name,ship[4].name); + AutoPk_PKSystemTalk(token,token); + + setAward(TRUE); + + AutoPk_SetHistoryStr(); + + baward = FALSE; +} + +BOOL AutoPk_AddItem( int charindex, int index ) +{ + char msgbuf[64]; + int ret; + int itemindex=-1; + itemindex = CHAR_findEmptyItemBox( charindex ); + if( itemindex < 0 ) { + CHAR_talkToCli( charindex, -1, "Ʒռ䲻㣡", CHAR_COLORYELLOW); + return FALSE; + } + + itemindex = ITEM_makeItemAndRegist( award[index].awarditemid ); + if(itemindex == -1) + return FALSE; + ret = CHAR_addItemSpecificItemIndex( charindex, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(charindex) ) { + ITEM_endExistItemsOne( itemindex ); + print ("\n ret error!!"); + return FALSE; + } + sprintf( msgbuf,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( charindex, ret); + return TRUE; +} + +BOOL AutoPk_AddPet( int charindex, int index) +{ + int ret; + char msgbuf[64]; + int enemynum; + int i,j; + int petindex, petindex2; + + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( charindex, i); + if( petindex == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ) { + snprintf( msgbuf,sizeof( msgbuf), ""); + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + return FALSE; + } + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == award[index].awardpetid) { + break; + } + } + + if( i == enemynum ) + return FALSE; + + ret = ENEMY_createPetFromEnemyIndex( charindex, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( charindex, i ) == ret ) + break; + } + + petindex2 = CHAR_getCharPet(charindex, i); + if( !CHAR_CHECKINDEX( petindex2) ) + return FALSE; + snprintf( msgbuf,sizeof( msgbuf), "õ%s", CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( charindex, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_setInt(petindex2,CHAR_VARIABLEAI,10000); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(charindex, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( charindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( charindex, msgbuf ); + } + return TRUE; +} + +BOOL AutoPk_GetAwardStr( void ) +{ + FILE* fp; + int i=0; + int j=0; + int enemynum = ENEMY_getEnemyNum(); + fp = fopen("./data/autopk/autopkaward.txt", "r"); + if (fp == NULL) + { + print("鿴Ʒļ򿪴\n"); + return FALSE; + } + for(i=0;i<5;i++){ + char line[64],buf[32]; + if (fgets(line, sizeof(line), fp) == NULL)break; + chop(line); + getStringFromIndexWithDelim(line,"|", 1, buf, sizeof(buf)); + award[i].awardpetid=atoi(buf); + if(award[i].awardpetid!=-1){ + for( j=0; j 0 && award[i].awarditemid <= getItemnum() ) + strcpy(award[i].awarditem,ITEM_getNameFromNumber(award[i].awarditemid)); + else + strcpy(award[i].awarditem, "\0"); + award[i].draw=AWARDNO; + } + fclose(fp); + return TRUE; +} + + +void setAward( BOOL val ) +{ + getaward=val; +} + +BOOL getAward() +{ + return getaward; +} + +BOOL getBAward() +{ + return baward; +} + +void AutoPk_SetAwardStr( char *token ) +{ + FILE* fp; + fp = fopen("./data/autopk/autopkaward.txt", "w"); + fwrite(token, strlen(token), 1, fp); + fclose(fp); +} +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bankman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bankman.c new file mode 100644 index 0000000..75488ad --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bankman.c @@ -0,0 +1,602 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_bankman.h" +#include "family.h" +#include "autil.h" + +extern int familyNumTotal; +extern char familyListBuf[MAXFAMILYLIST]; + +char sendbuf[1024]; +char buf[1024]; +char subbuf[128]; +int i, j; + + +struct { + int windowno; + int windowtype; + int buttontype; + int takeitem; + int giveitem; + char message[4096]; +}w; + +struct { + BOOL use; + int checkhaveitem; + int checkhaveitemgotowin; + int checkdonthaveitem; + int checkdonthaveitemgotowin; + int warp; + int battle; + int gotowin; +}buttonproc[13]; /* ok,cancel, yes,no,prev,next ݼ */ + + + + + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; +static void NPC_Bankman_selectWindow( int meindex, int toindex, int num); +static BOOL NPC_Bankman_readData( int meindex, int windowno, BOOL chkflg); +static int NPC_Bankman_restoreButtontype( char *data ); + +BOOL NPC_BankmanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", buf, sizeof( buf))== NULL ){ + print( "familyman:ûָ趨ĵ \n"); + return FALSE; + } + /* ݱɬ÷ëƻ֧ */ + if( !NPC_Bankman_readData( meindex, -1, TRUE) ) { + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWINDOWMAN ); + + return TRUE; +} + +void NPC_BankmanTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + NPC_Bankman_selectWindow( meindex, talkerindex, 1 ); + +} + +void NPC_BankmanLooked( int meindex , int lookedindex) +{ + + //print(" Look:me:%d,looked:%d ",meindex,lookedindex); + NPC_Bankman_selectWindow( meindex, lookedindex,1 ); + +} + +static void NPC_Bankman_selectWindow( int meindex, int toindex, int num) +{ + + int fd; + char buf[256]; + + /* 帲ƻ ɱ */ + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* */ + if( !NPC_Util_charIsInFrontOfChar( toindex, meindex, 1 )) return; + + if( !NPC_Bankman_readData( meindex, num, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + + fd = getfdFromCharaIndex( toindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } +} + +void NPC_BankmanWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) + +{ + + int button = -1; + char buf[2048], buff[256]; + + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + /* ū įë */ + if( !NPC_Bankman_readData( meindex, seqno - 100, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + /* ʾëƩ */ + if( w.windowtype == WINDOW_MESSAGETYPE_SELECT ) { + //if( w.windowtype == WINDOW_MESSAGETYPE_MESSAGE ) { + // shan end + button = atoi( data)+5; + if( button > 12 ) { + print( "familyman:invalid button[%d]\n", button); + return; + } + } + else if( select & WINDOW_BUTTONTYPE_OK) button = 0; + else if( select & WINDOW_BUTTONTYPE_CANCEL) button = 1; + else if( select & WINDOW_BUTTONTYPE_YES) button = 2; + else if( select & WINDOW_BUTTONTYPE_NO) button = 3; + else if( select & WINDOW_BUTTONTYPE_PREV) button = 4; + else if( select & WINDOW_BUTTONTYPE_NEXT) button = 5; + else { + print( "familyman:invalid button[%d]\n", select); + return; + } + // shan begin + //if( buttonproc[button].use == TRUE ) { + //if( select > 0) { + if( button > 0 ) { + // shan end + int fd; + int newwin = -1; + + fd = getfdFromCharaIndex( talkerindex); + + /* ʾ巽Ȼ ëԻ */ + if( newwin == -1 ) { + newwin = buttonproc[button].gotowin; + } + + // Robin + // + // shan begin + if( select == WINDOW_BUTTONTYPE_YES) { + newwin = 5; + } + // shan end + if( newwin == 5 ) { + if( CHAR_getInt( talkerindex, CHAR_FMINDEX ) < 1 && + CHAR_getInt( talkerindex, CHAR_BANKGOLD) < 1 ) + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nʸ񲻷ϣ" + "\nȼ壡", buff, sizeof(buff))); + else { + sprintf(buf, "B|G|%d", CHAR_getInt( talkerindex, CHAR_BANKGOLD) ); + lssproto_FM_send( fd, buf ); + } + return; + } + // ʻ + if( newwin == 6 ) + { + if( CHAR_getInt( talkerindex, CHAR_FMINDEX ) > 0 ) + saacproto_ACGetFMData_send( acfd, CHAR_getChar( talkerindex, CHAR_FMNAME), + CHAR_getInt( talkerindex, CHAR_FMINDEX ), + CHAR_getWorkInt( talkerindex, CHAR_WORKFMINDEXI ), + 1, + CONNECT_getFdid(fd) + ); + else + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nʸ񲻷ϣ" + "\nȼ壡", buff, sizeof(buff))); + return; + } + // ˳ + if( newwin == 7 ) + { + if( CHAR_getInt( talkerindex, CHAR_FMINDEX ) == -1 ) { + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nʸ񲻷ϣ" + "\nȼ壡", buff, sizeof(buff))); + return; + } + + print(" WN2FM "); + FAMILY_Leave( fd, talkerindex, "E|1"); + + return; + } + + if( !NPC_Bankman_readData( meindex, newwin, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } + + + + } +} + +static BOOL NPC_Bankman_readData( int meindex, int windowno, BOOL chkflg) +{ + + int i; + int linenum = 0; + int endflg = FALSE; + int buttonendflg; + int winno = -1; + int buttonconfmode; + int b_mode; + int selectnum ; + int messagepos; + BOOL errflg = FALSE; + BOOL readflg = TRUE; + FILE *fp; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char filename[64]; + char opfile[128]; + char line[1024]; + char firstToken[1024]; + char secondToken[1024]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + NPC_Util_GetStrFromStrWithDelim( argstr, "conff", filename, sizeof( filename)); + sprintf( opfile, "%s/", getNpcdir( ) ); + strcat( opfile, filename); + +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", opfile); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( opfile, "r"); +} + if( fp == NULL ) { + print( "familyman:file open error [%s]\n", opfile); + return FALSE; + } + + while( readflg == TRUE ) { + endflg = FALSE; + buttonendflg = TRUE; + buttonconfmode = FALSE; + selectnum = 0; + messagepos = 0; + winno = -1; + b_mode = -1; + errflg = FALSE; + + /* */ + w.windowno = -1; + w.windowtype = -1; + w.buttontype = -1; + w.takeitem = -1; + w.giveitem = -1; + w.message[0] = '\0'; + + for( i = 0; i < arraysizeof( buttonproc); i ++ ) { + buttonproc[i].use = FALSE; + buttonproc[i].checkhaveitem = -1; + buttonproc[i].checkhaveitemgotowin = -1; + buttonproc[i].checkdonthaveitem = -1; + buttonproc[i].checkdonthaveitemgotowin = -1; + buttonproc[i].warp = -1; + buttonproc[i].battle = -1; + buttonproc[i].gotowin = -1; + } + + while( 1) { + char buf[256]; + int ret; + if( !fgets( line, sizeof( line), fp)){ + readflg = FALSE; + break; + } +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + + /* 춪 */ + if( line[0] == '#' || line[0] == '\n') continue; + /* ݱ */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) strcpy( line, buf); + + /* delim "=" ƥ (1)ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, + sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, + sizeof( secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + + if( strcasecmp( firstToken, "winno") == 0 ) { + if( winno != -1 ) { + print( "familyman:winnoȴ¶winno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + readflg = FALSE; + break; + } + /* ūNoë */ + winno = atoi( secondToken); + continue; + } + /* ūNo Ȼئݼ淴 */ + if( winno == -1 ) { + print( "familyman:winno δ壬ȴ趨\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = FALSE; + break; + } + /* ūNo ݷë + * ľ½ */ + if( (chkflg == FALSE && winno == windowno )|| + chkflg == TRUE) + { + if( buttonconfmode == TRUE ) { + if( strcasecmp( firstToken, "gotowin") == 0 ) { + buttonproc[b_mode].gotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkhaveitem") == 0 ) { + buttonproc[b_mode].checkhaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "haveitemgotowin") == 0 ) { + buttonproc[b_mode].checkhaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkdonthaveitem") == 0 ) { + buttonproc[b_mode].checkdonthaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "donthaveitemgotowin") == 0 ) { + buttonproc[b_mode].checkdonthaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "endbutton") == 0 ) { + if( buttonproc[b_mode].gotowin == - 1 ) { + if( buttonproc[b_mode].checkhaveitem == -1 && + buttonproc[b_mode].checkdonthaveitem == -1) + { + errflg = TRUE; + } + else { + /* оȵƥɬýľľ */ + if( !((buttonproc[b_mode].checkhaveitem != -1 && + buttonproc[b_mode].checkhaveitemgotowin != -1) + || (buttonproc[b_mode].checkdonthaveitem != -1 && + buttonproc[b_mode].checkdonthaveitemgotowin != -1))) + { + errflg = TRUE; + } + } + } + + if( errflg == TRUE) { + print( "familyman: Ҳgotowin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = TRUE; + break; + } + buttonproc[b_mode].use = TRUE; + buttonconfmode = FALSE; + buttonendflg = TRUE; + } + } + else { + + w.windowno = winno; + /* ūɬ */ + if( strcasecmp( firstToken, "wintype") == 0 ) { + w.windowtype = atoi( secondToken); + } + /* ʾɬ */ + else if( strcasecmp( firstToken, "buttontype") == 0 ) { + w.buttontype = NPC_Bankman_restoreButtontype( secondToken); + } + /* getitemɬ */ + else if( strcasecmp( firstToken, "takeitem") == 0 ) { + w.takeitem = atoi( secondToken); + } + /* giveitemɬ */ + else if( strcasecmp( firstToken, "giveitem") == 0 ) { + w.giveitem = atoi( secondToken); + } + /* messageɬ */ + else if( strcasecmp( firstToken, "message") == 0 ) { + if( messagepos == 0 ) { + strcpy( w.message, secondToken); + messagepos = strlen( w.message); + } + else { + w.message[messagepos]='\n'; + messagepos++; + strcpy( &w.message[messagepos], secondToken); + messagepos+=strlen(secondToken); + } + } + /* ʾëݼɬ */ + else if( strcasecmp( firstToken, "okpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 0; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "cancelpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 1; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "yespressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 2; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nopressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 3; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "prevpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 4; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nextpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 5; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "selected") == 0 ) { + buttonconfmode = TRUE; + b_mode = 6 + selectnum; + buttonendflg = FALSE; + selectnum ++; + } + /* ɬñδԻ */ + else if( strcasecmp( firstToken, "endwin") == 0 ) { + endflg = TRUE; + if( chkflg == FALSE) { + readflg = FALSE; + } + break; + } + else { + print( "familyman:趨DzܵIJ\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + } + } + } + else { + if( strcasecmp( firstToken, "endwin") == 0 ) { + winno = -1; + } + } + } + if( buttonendflg == FALSE) { + print( "familyman: Ҳendbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( winno != -1 ) { + if( w.windowtype == -1 ) { + print( "familyman: Ҳwintype\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( w.buttontype == -1 ) { + print( "familyman: Ҳbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( strlen( w.message) == 0 ) { + print( "familyman: Ҳmessage\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + } + } + fclose( fp); + + if( chkflg == FALSE && w.windowno == -1 ) { + print( "familyman: Ҳָwindowno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( winno != -1 && endflg == FALSE) { + print( "familyman: Ҳendwin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( errflg == TRUE) return FALSE; + + return TRUE; +} +/* + * buttontype=ƥ϶ ٯ ëѰ £ + * + */ +static int NPC_Bankman_restoreButtontype( char *data ) +{ + int ret = 0; + int rc; + int i; + char buff[1024]; + + for( i = 1; ; i ++ ) { + rc = getStringFromIndexWithDelim( data, "|", i, buff, + sizeof( buff ) ); + if( rc == FALSE) break; + if( strcasecmp( buff, "ok") == 0 ) { + ret |= WINDOW_BUTTONTYPE_OK; + } + else if( strcasecmp( buff, "cancel") == 0 ) { + ret |= WINDOW_BUTTONTYPE_CANCEL; + } + else if( strcasecmp( buff, "yes") == 0 ) { + ret |= WINDOW_BUTTONTYPE_YES; + } + else if( strcasecmp( buff, "no") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NO; + } + else if( strcasecmp( buff, "prev") == 0 ) { + ret |= WINDOW_BUTTONTYPE_PREV; + } + else if( strcasecmp( buff, "next") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NEXT; + } + } + if( ret == 0 ) { + ret = atoi( data); + } + return ret; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bodylan.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bodylan.c new file mode 100644 index 0000000..740e681 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bodylan.c @@ -0,0 +1,483 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_windowhealer.h" + + + + +/* + *ʾū¼ءë ɱNPC + * ƾľգ + * NPCINDEXë£ + * + *ȣNPCԻƥʧؤգʧëڳ + *NPCINDEXë ƻ¾ + * ئݷʧˡ + *жʧëƻëʧ£ + *ʧ ˡ ئ϶ü߷ + * + */ + +enum { + BODYLAN_E_COMMANDNUM = CHAR_NPCWORKINT1, // ѨӮ +}; + + +// ̼ƹ +enum{ + BODYLAN_WIN_FIRST, + BODYLAN_WIN_LAST_GOOD, + BODYLAN_WIN_LAST_NG, + BODYLAN_WIN_GOOD_NO, + BODYLAN_WIN_ALREADY, + BODYLAN_WIN_NOT_PREEVENT, + BODYLAN_WIN_END +}; + +static void NPC_BodyLan_Profit( int meindex, int playerindex ); + +static void NPC_BodyLan_Window( + int meindex, + int talkerindex, + int mode +); + + +/********************************* +* +*********************************/ +BOOL NPC_BodyLanInit( int meindex ) +{ + + char szP[256], szArg[4096]; + char buf[256]; + int i, needSeq; + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEEVENT ); + + if( NPC_Util_GetArgStr( meindex, szArg, sizeof( szArg ) ) == NULL ){ + print( "npc_bodylan.c:û(%s)\n", + CHAR_getChar(meindex,CHAR_NPCARGUMENT) ); + return FALSE; + } + + + // ˡë + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Act", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:δ趨(%s)\n", szArg ); + return FALSE; + } + + for( i = 0 ; ; i ++ ){ + // ۢئ + if( getStringFromIndexWithDelim( szP, ",", i, buf, sizeof( buf)) != FALSE ){ + needSeq = atoi(buf); + // Ѩ̹ϵ ճƥ + if( needSeq < 0 ){ + if( i <= 0 ){ + print( "npc_bodylan:δ趨(%s)\n", szArg ); + } + // ë + CHAR_setWorkInt( meindex, BODYLAN_E_COMMANDNUM, i ); + break; + }else{ + // ƻ + } + }else{ + if( i <= 0 ){ + print( "npc_bodylan:δ趨(%s)\n", szArg ); + } + // ë + CHAR_setWorkInt( meindex, BODYLAN_E_COMMANDNUM, i ); + break; + } + } + + + + return TRUE; + +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_BodyLanTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + char szP[256], szArg[4096]; + int EventNo = -1,Pre_Event = -1; + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2 ) + { + return; + } + + // ¦ ٯ + if( NPC_Util_GetArgStr( meindex, szArg, sizeof( szArg ) ) == NULL ){ + print( "npc_bodylan.c:û(%s)\n", + CHAR_getChar(meindex,CHAR_NPCARGUMENT) ); + return ; + }else{ + // ì į + if( NPC_Util_GetStrFromStrWithDelim( szArg, "EventNo", szP, sizeof( szP ) ) != NULL ){ + EventNo = atoi(szP); + } + // ۢì į + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Pre_Event", szP, sizeof( szP ) ) != NULL ){ + Pre_Event = atoi(szP); + } + } + + // ۢì įؤľ + if( Pre_Event >= 0 ){ + // ì帲ƻƻ¾ + if( NPC_EventCheckFlg( talkerindex, Pre_Event ) == FALSE ){ + // ۢìëʧƻئճ𼰱 + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_NOT_PREEVENT ); + return; + } + } + // ì įؤľ + if( EventNo >= 0 ){ + // ì帲ƻƻ¾ + if( NPC_EventCheckFlg( talkerindex, EventNo ) == TRUE ){ + // Ȼճ𼰱 + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_ALREADY ); + return; + } + } + + // ԳȻ׾ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKTRADER ) == meindex ){ + + // ձѨ ƻ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT ) + >= CHAR_getWorkInt( meindex, BODYLAN_E_COMMANDNUM ) + ){ + // + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_LAST_GOOD ); + return; + }else{ + // + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_LAST_NG ); + return; + } + }else{ + // ٻئƥ + // м̼͵ë + CHAR_setWorkInt( talkerindex, CHAR_WORKTRADER, meindex ); + // ˡ پձ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1 ); + + // ˱羮微ئؤ + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_FIRST ); + return; + } +} + + +/*======================================= + * watch + *======================================*/ +void NPC_BodyLanWatch( + int objmeindex, + int objmoveindex, + CHAR_ACTION act, + int x, + int y, + int dir, + int* opt, + int optlen +) +{ + char szP[256], szArg[4096]; + char buf[256]; + int actindex; + int meindex; + int seqNo, needSeq; + + // ƽҷ½ + if( OBJECT_getType(objmoveindex) != OBJTYPE_CHARA ) return; + actindex = OBJECT_getIndex(objmoveindex); + // ½ + if( CHAR_getInt( actindex, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) return; + + // м̼͵ + meindex = OBJECT_getIndex(objmeindex); + + // мINDEXë ƻ¾ئľ + if( CHAR_getWorkInt( actindex, CHAR_WORKTRADER ) != meindex ){ + return; + } + + // ƥʧëƻ¾ + seqNo = CHAR_getWorkInt( actindex, CHAR_WORKSHOPRELEVANT ); + // ئ پ + if( seqNo < 1 )seqNo = 1; + + // ¦ ٯ + if( NPC_Util_GetArgStr( meindex, szArg, sizeof( szArg ) ) == NULL ){ + print( "npc_bodylan.c:û(%s)\n", + CHAR_getChar(meindex,CHAR_NPCARGUMENT) ); + return ; + } + + + // ˡë + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Act", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:δ趨(%s)\n", szArg ); + return; + } + + // ۢئ + if(getStringFromIndexWithDelim( szP, ",", seqNo, buf, sizeof( buf)) != FALSE ){ + needSeq = atoi(buf); + }else{ + // ئ⾮ئ پ + CHAR_setWorkInt( actindex, CHAR_WORKSHOPRELEVANT, 1 ); + +// print( "ͷˡص\n", seqNo, needSeq ); + // Ͼ微 + return; + } + + // ۢئʧ + if( needSeq == act ){ + // ף۳ľ +// print( "ɹ\(%d%d)\n", seqNo, needSeq ); + seqNo ++; + if( seqNo >= CHAR_getWorkInt( meindex, BODYLAN_E_COMMANDNUM ) ){ +// print( "ڴ˽\n" ); + } + // ë + CHAR_setWorkInt( actindex, CHAR_WORKSHOPRELEVANT, seqNo ); + }else{ + // پ֧Ի + CHAR_setWorkInt( actindex, CHAR_WORKSHOPRELEVANT, 1 ); +// print( "(%d%d)\n", seqNo, needSeq ); + } + +} + + + +//********* ݼ ********* +static void NPC_BodyLan_Profit( int meindex, int playerindex ) +{ + char szArg[4096], szP[256]; + int fl, x, y, pmode, i, subindex, parent; + + // ¦ ٯ + if( NPC_Util_GetArgStr( meindex, szArg, sizeof( szArg ) ) == NULL ){ + print( "npc_bodylan.c:û(%s)\n", + CHAR_getChar(meindex,CHAR_NPCARGUMENT) ); + return ; + } + + //********************************************* + // + // ۷ɬ + // + //********************************************* + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Warp", szP, sizeof( szP ) ) != NULL ){ + // 工 + if( sscanf( szP, "%d,%d,%d", &fl, &x, &y ) == 3 ){ + }else{ + return; + } + + pmode = CHAR_getWorkInt( playerindex, CHAR_WORKPARTYMODE ); + switch( pmode ){ + case 1: + parent = playerindex; + break; + case 2: + parent = CHAR_getWorkInt( playerindex, CHAR_WORKPARTYINDEX1 ); + break; + default: + CHAR_warpToSpecificPoint( playerindex, fl, x, y ); + return; + } + for( i = 0; i < getPartyNum(parent ); i ++ ){ + subindex = CHAR_getWorkInt( parent, CHAR_WORKPARTYINDEX1+i ); + if( CHAR_CHECKINDEX( subindex ) == FALSE )continue; + CHAR_warpToSpecificPoint( subindex, fl, x, y ); + } + } + + + +} + +#if 1 +static void NPC_BodyLan_Window( + int meindex, + int talkerindex, + int mode +) +{ + char token[1024]; + char escapedname[2048]; + char szArg[4096]; + char szP[256]; + int fd; + int buttontype = 0, windowtype = 0, windowno = 0; + + if( CHAR_CHECKINDEX( talkerindex ) == FALSE )return; + fd = getfdFromCharaIndex( talkerindex ); + + // ¦ ٯ + if( NPC_Util_GetArgStr( meindex, szArg, sizeof( szArg ) ) == NULL ){ + print( "npc_bodylan.c:û(%s)\n", + CHAR_getChar(meindex,CHAR_NPCARGUMENT) ); + return ; + } + + szP[0] = 0; + + switch( mode ){ + case BODYLAN_WIN_FIRST: + // ٱ ľ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "First", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:һʼû(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_YES|WINDOW_BUTTONTYPE_NO; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + + case BODYLAN_WIN_LAST_GOOD: + // ƥݩ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Good", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:ʱ˵û(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_YESNO;// YES|NO + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + + case BODYLAN_WIN_LAST_NG: + // ƥݩ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Ng", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:ʱ˵û(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_OK;// OK + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + + case BODYLAN_WIN_GOOD_NO: + // ݩݱ ëƽҼ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Good_No", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:ʱȡƷû(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_OK;// OK + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + + case BODYLAN_WIN_ALREADY: + // ƥìë ƻ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Good_No", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:¼ʱû(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_OK; // OK + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + + case BODYLAN_WIN_NOT_PREEVENT: + // ۢئìëئƻئ + if( NPC_Util_GetStrFromStrWithDelim( szArg, "Pre_Not", szP, sizeof( szP ) ) == NULL ){ + print( "npc_bodylan:?ǰ¼û(%s)\n", szArg ); + return; + } + sprintf( token,"%s", szP ); + buttontype=WINDOW_BUTTONTYPE_OK; // OK + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=mode; + break; + default: + return; + } + + makeEscapeString( token, escapedname, sizeof(escapedname)); + /*-ƥ˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + escapedname); + + +} + + + +/*----------------------------------------- +ͷʧ߯Ȼݱ̫ľ£ +-------------------------------------------*/ +void NPC_BodyLanWindowTalked( + int meindex, + int talkerindex, + int seqno, + int select, + char *data +) +{ + + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) return; + + switch( seqno){ + case BODYLAN_WIN_LAST_GOOD: // ݩݱOKɽľ + if(select==WINDOW_BUTTONTYPE_YES ){ + NPC_BodyLan_Profit( meindex, talkerindex ); + // м̼͵ë٨ľ + CHAR_setWorkInt( talkerindex, CHAR_WORKTRADER, -1 ); + // ˡ پձ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1 ); + }else + if( select == WINDOW_BUTTONTYPE_NO ){ + // ݩݱƽҼľ + NPC_BodyLan_Window( meindex, talkerindex, BODYLAN_WIN_GOOD_NO ); + // м̼͵ë٨ľ + CHAR_setWorkInt( talkerindex, CHAR_WORKTRADER, -1 ); + // ˡ پձ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1 ); + } + break; + default: + break; + } + +} + + + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bus.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bus.c new file mode 100644 index 0000000..27ad431 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_bus.c @@ -0,0 +1,732 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_bus.h" +#include "handletime.h" + +/* + * ﵩئëNPC + */ + +enum { + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT1, /* ߣ */ + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, /* ߣ */ + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, /* */ + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, /* 微Ի ߡ ࡰԻ */ + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +}; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +/* ⼰enum */ +enum { + NPC_BUS_MSG_GETTINGON, + NPC_BUS_MSG_NOTPARTY, + NPC_BUS_MSG_OVERPARTY, + NPC_BUS_MSG_DENIEDITEM, + NPC_BUS_MSG_ALLOWITEM, + NPC_BUS_MSG_LEVEL, + NPC_BUS_MSG_GOLD, + NPC_BUS_MSG_EVENT, + NPC_BUS_MSG_START, + NPC_BUS_MSG_END, +}; +typedef struct { + char option[32]; + char defaultmsg[128]; +}NPC_BUS_MSG; +NPC_BUS_MSG busmsg[] = { + { "msg_gettingon", "PAON޷;ࡣ"}, + { "msg_notparty", "PAPAON޷ŶӼࡣ"}, + { "msg_overparty", "PAON"}, + { "msg_denieditem", "PAPAONҿɲҪߣ"}, + { "msg_allowitem", "~(ҪǸ߰!)"}, + { "msglevel", "PAPAONĵȼࡣ"}, + { "msg_stone", "PAPAONǮࡣ"}, + { "msg_event", "PAON޷ࡣ"}, + { "msg_start", "~()"}, + { "msg_end", "~()"} + +}; + +static int NPC_BusSetPoint( int meindex, char *argstr); +static void NPC_BusSetDestPoint( int meindex, char *argstr); +static BOOL NPC_BusCheckDeniedItem( int meindex, int charaindex, char *argstr); +static BOOL NPC_BusCheckLevel( int meindex, int charaindex, char *argstr); +static int NPC_BusCheckStone( int meindex, int charaindex, char *argstr); +static void NPC_BusSendMsg( int meindex, int talkerindex, int tablenum); +static int NPC_BusGetRoutePointNum( int meindex, char *argstr ); +static void NPC_Bus_walk( int meindex); + +#define NPC_BUS_LOOPTIME 200 + +/* ޷ɻ */ +#define NPC_BUS_WAITTIME_DEFAULT 180 + +#define NPC_BUS_WAITINGMODE_WAITTIME 5000 + +/********************************* +* +*********************************/ +BOOL NPC_BusInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i; + char buf[256]; + int routenum; + int waittime; + int seflg; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* ئľئ¦Ѽ */ + routenum = NPC_Util_GetNumFromStrWithDelim( argstr, "routenum");//ʻ· + + if( routenum == -1 ) { + print( "npcbus:nothing routenum \n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, routenum); + + for( i = 1; i <= routenum; i ++ ) { + char routetostring[64]; + snprintf( routetostring, sizeof( routetostring), "routeto%d", i); + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcbus:nothing route to \n"); + return FALSE; + } + + } + waittime = NPC_Util_GetNumFromStrWithDelim( argstr, "waittime"); + + if( waittime == -1 ) waittime = NPC_BUS_WAITTIME_DEFAULT; + CHAR_setWorkInt( meindex, NPC_WORK_WAITTIME, waittime); + seflg = NPC_Util_GetNumFromStrWithDelim( argstr, "seflg"); + + if( seflg == -1 ) seflg = TRUE; + CHAR_setWorkInt( meindex, NPC_WORK_SEFLG, seflg); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEBUS ); + + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, 2); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 0); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, 0); + + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, + NPC_BUS_WAITINGMODE_WAITTIME); + + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + + for( i = 0; i < getPartyNum(meindex ); i ++) { + CHAR_setWorkInt( meindex, CHAR_WORKPARTYINDEX1 + i, -1); + } + + /* */ +{ + int rev; + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + //print( "route:%d\n",CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + /* Ƿ */ + rev = NPC_Util_GetNumFromStrWithDelim( argstr, "reverse"); + + if( rev == 1 ) { + int num = NPC_BusGetRoutePointNum( meindex, argstr); + + if( num <= 0 ) { + print( "npcbus:֣\n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 1); + } + /* ë */ + NPC_BusSetPoint( meindex, argstr); + /* ë */ + NPC_BusSetDestPoint( meindex, argstr); +} + + return TRUE; +} + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_BusTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + int i; + int partyflg = FALSE; + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* мɡ ū Ʃ */ + for( i = 0; i < getPartyNum(meindex ); i ++ ) { + int index = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX(index)){ + if( index == talkerindex) { + partyflg = TRUE; + } + } + } + if( !partyflg ) { + //NPC_BusCheckJoinParty( meindex, talkerindex, TRUE); + } + else { + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) == 0 ) { + int i; + // #define NPC_BUS_DEBUGROUTINTG "routingtable:" + if( strstr( szMes, "" ) || + strstr( szMes, "" ) || + strstr( szMes, "Go" ) || + strstr( szMes, "go" )) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_BUS_LOOPTIME); + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + 60, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_BusSendMsg( meindex, partyindex, NPC_BUS_MSG_START); + } + } + } + } + } +} +/************************************** + * + **************************************/ +void NPC_BusLoop( int meindex) +{ + int i; + switch( CHAR_getWorkInt( meindex, NPC_WORK_MODE )) { + case 0: + /* ƹݣë */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) + < NowTime.tv_sec) + { + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + 60, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_BusSendMsg( meindex, partyindex, NPC_BUS_MSG_START); + } + } + + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_BUS_LOOPTIME); + } + return; + case 1: + /* */ + NPC_Bus_walk( meindex); + case 2: + /* Ȼƹ */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + (CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) /3) + < NowTime.tv_sec) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_BUS_LOOPTIME); + + } + return; + case 3: + /* ƻ֣ͷʧ мб + * Ƴƥëľ֧ + */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + 3 + < NowTime.tv_sec) + { + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + /* Ѽë */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, + NPC_BUS_WAITINGMODE_WAITTIME); + + /* */ + { + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + //print( "route:%d\n",CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + } + /* Ի׷º */ + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, + CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP)^1); + + /* ݺ̼Ʃ */ + /* Ի */ + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP) == 1) { + /* κ̼ë */ + int num = NPC_BusGetRoutePointNum( meindex, argstr); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + } + else { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +1); + } + /* ݼ̼ ë */ + NPC_BusSetPoint( meindex, argstr); + /* ë */ + NPC_BusSetDestPoint( meindex, argstr); + /* ɡ ū ë */ + CHAR_DischargeParty( meindex, 0); + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + /* ƹʧ */ + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + } + return; + default: + break; + } +} +/************************************** + * ʣ + **************************************/ +static void NPC_Bus_walk( int meindex) +{ + POINT start, end; + int dir; + int ret; + int i; + + /* */ + /* ݼ */ + start.x = CHAR_getInt( meindex, CHAR_X); + start.y = CHAR_getInt( meindex, CHAR_Y); + end.x = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOX); + end.y = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOY); + + /* ׼ƥݼ̼ */ + if( start.x == end.x && start.y == end.y ) { + int add = 1; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP ) == 1 ) { + add *= -1; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +add); + if( NPC_BusSetPoint( meindex, argstr) == FALSE ) { + /* */ + /* ƹ */ + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + 60, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + NPC_BusSendMsg( meindex, partyindex, NPC_BUS_MSG_END); + } + } + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; + } + else { + return; + } + } + /*-------------------------------------------------------*/ + /* ھ */ + + /* ëƻ */ + dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + + /* ɡ ūƥ */ + end.x = CHAR_getInt( meindex, CHAR_X); + end.y = CHAR_getInt( meindex, CHAR_Y); + + /* Ⱦݼм */ + for( i = 0; i < 100; i ++ ) { + if( dir < 0 ) { + dir = RAND( 0,7); + } + dir = NPC_Util_SuberiWalk( meindex, dir); + if( dir >= 0 && dir <= 7) break; + } + + if( dir >= 0 && dir <= 7 ) { + /* */ + ret = CHAR_walk( meindex, dir, 0); + + if( ret == CHAR_WALKSUCCESSED ) { + /* лئëھ */ + int i; + for( i = 1; i < getPartyNum(meindex ); i ++ ) { + int toindex = CHAR_getWorkInt( meindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + start.x = CHAR_getInt( toindex, CHAR_X); + start.y = CHAR_getInt( toindex, CHAR_Y); + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + /* ·ūë ¿б + * ݼҷ󡼰Ҽ ëܰ + */ + end = start; + if( parent_dir != -1 ) { + CHAR_walk( toindex, parent_dir, 0); + } + } + } + } + } +} +/************************************** + * ݼë + **************************************/ +static int NPC_BusSetPoint( int meindex, char *argstr) +{ + char buf[4096]; + char buf2[256]; + char buf3[256]; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcbus:nothing route \n"); + return FALSE; + } + ret = getStringFromIndexWithDelim( buf, ";", + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT), + buf2, sizeof(buf2)); + + if( ret == FALSE ) return FALSE; + + ret = getStringFromIndexWithDelim( buf2, ",", 1, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, atoi( buf3)); + + ret = getStringFromIndexWithDelim( buf2, ",", 2, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, atoi( buf3)); + return TRUE; +} +/************************************** + * route įգ 󡻥ؤչľë + * į屾£ + **************************************/ +static void NPC_BusSetDestPoint( int meindex, char *argstr) +{ + char buf[256]; + char routename[256]; + + snprintf( routename, sizeof( routename), "routename%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routename, buf, sizeof( buf)) + != NULL ) + { + CHAR_setChar( meindex, CHAR_OWNTITLE, buf); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼշֻ + **************************************/ +static BOOL NPC_BusCheckDeniedItem( int meindex, int charaindex, char *argstr) +{ + char buf[1024]; + BOOL found = TRUE; + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "denieditem", buf, sizeof( buf)) + != NULL ) + { + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + for( j = 0; j < CheckCharMaxItem(charaindex); j ++) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + found = FALSE; + break; + } + } + } + } + } + return found; +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼئֻ + **************************************/ +BOOL NPC_BusCheckAllowItem( int meindex, int charaindex, BOOL pickupmode) +{ + char buf[1024]; + BOOL found = TRUE; + BOOL pickup = FALSE; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pickupitem", buf, sizeof( buf))!= NULL ){ + pickup = TRUE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "allowitem", buf, sizeof( buf))!= NULL ){ + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + BOOL getflg; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + getflg = FALSE; + for( j = 0; j < CheckCharMaxItem(charaindex); j ++) { + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + if( pickupmode && pickup && !getflg) { + CHAR_DelItem( charaindex, j); + getflg = TRUE; + } + break; + } + } + } + if( j == CheckCharMaxItem(charaindex) ) { + found = FALSE; + break; + } + } + } + return found; +} + +/************************************** + * ϶ýľìﶯ + **************************************/ +static BOOL NPC_BusCheckLevel( int meindex, int charaindex, char *argstr) +{ + int level; + + /* ئľئ¦Ѽ */ + level = NPC_Util_GetNumFromStrWithDelim( argstr, "needlevel"); + if( level == -1 ) { + return TRUE; + } + if( CHAR_getInt( charaindex, CHAR_LV) >= level ) return TRUE; + + return FALSE; +} +/************************************** + * ë + * -1 0 ݾ ۢStone + **************************************/ +static int NPC_BusCheckStone( int meindex, int charaindex, char *argstr) +{ + int gold; + + /* ئľئ¦Ѽ */ + gold = NPC_Util_GetNumFromStrWithDelim( argstr, "needstone"); + if( gold == -1 ) { + return 0; + } + if( CHAR_getInt( charaindex, CHAR_GOLD) >= gold ) return gold; + + return -1; +} +/************************************** + * ë˪ + * ¦Ѽ⻥ئľɷɻë˪ + **************************************/ +static void NPC_BusSendMsg( int meindex, int talkerindex, int tablenum) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + char msg[256]; + if( tablenum < 0 || tablenum >= arraysizeof( busmsg)) return; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, busmsg[tablenum].option, buf, sizeof( buf)) + != NULL ) + { + strcpy( msg, buf); + } + else { + snprintf( msg, sizeof(msg),busmsg[tablenum].defaultmsg); + } + CHAR_talkToCli( talkerindex, meindex, msg, CHAR_COLORYELLOW); +} +/************************************** + * ƤP̼ë + **************************************/ +static int NPC_BusGetRoutePointNum( int meindex, char *argstr ) +{ + int i; + char buf[4096]; + char buf2[256]; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcbus:nothing route \n"); + return -1; + } + for( i = 1; ; i ++ ) { + ret = getStringFromIndexWithDelim( buf, ";", i, buf2, sizeof(buf2)); + if( ret == FALSE) break; + } + return( i -1); +} +BOOL NPC_BusCheckJoinParty( int meindex, int charaindex, BOOL msgflg) +{ + //int fd; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int ret; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* */ + if( !NPC_Util_charIsInFrontOfChar( charaindex, meindex, 1 )) return FALSE; + /* ַ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) != 0 ) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_GETTINGON); + return FALSE; + } + /* շֻ */ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) != CHAR_PARTY_NONE) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_NOTPARTY); + return FALSE; + } + /* ɡ ūë */ + if( CHAR_getEmptyPartyArray( meindex) == -1 ) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_OVERPARTY); + return FALSE; + } + /* ʧ ةë(ʧ ة) */ + if( !NPC_BusCheckDeniedItem( meindex, charaindex, argstr)) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_DENIEDITEM); + return FALSE; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ) { + CHAR_talkToCli( charaindex, -1, "޷Яϳ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + /* ʧ ةë( ۢʧ ة) */ + if( !NPC_BusCheckAllowItem( meindex, charaindex, FALSE)) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_ALLOWITEM); + return FALSE; + } + /* ìPë */ + if( !NPC_BusCheckLevel( meindex, charaindex, argstr)) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_LEVEL); + return FALSE; + } + /* ì */ +// if( CHAR_getInt( charaindex, CHAR_NOWEVENT) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT2) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT3) != 0 ) +// { +// if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_EVENT); +// return FALSE; +// } + /* żë ë¼ƥ ͱ³ */ + ret = NPC_BusCheckStone( meindex, charaindex, argstr); + if( ret == -1 ) { + if( msgflg) NPC_BusSendMsg( meindex, charaindex, NPC_BUS_MSG_GOLD); + return FALSE; + } + if( ret != 0 ) { + char msgbuf[128]; + /* ë */ + CHAR_setInt( charaindex, CHAR_GOLD, + CHAR_getInt( charaindex, CHAR_GOLD) - ret); + /* ˪ */ + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + snprintf( msgbuf, sizeof( msgbuf), "֧%d Stone", ret); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + } + /* ɡ ū */ + //CHAR_JoinParty_Main( charaindex, meindex); + + //fd = getfdFromCharaIndex( charaindex ); + + //lssproto_PR_send( fd, 1, 1); + + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_charm.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_charm.c new file mode 100644 index 0000000..0c4e401 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_charm.c @@ -0,0 +1,285 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_charm.h" + +// ҽë ʻңֿ + +//ì ػ / + +//ڷƥʣ +/* +#define RATE 4 // +#define CHARMHEAL 5 // +#define WARU 3 // ë° + +*/ + +#define RATE 10 // +#define CHARMHEAL 5 // +#define WARU 3 // ë° + + +static void NPC_Charm_selectWindow( int meindex, int toindex, int num); +int NPC_CharmCost(int meindex,int talker); +void NPC_CharmUp(int meindex,int talker); + + +/********************************* +* +*********************************/ +BOOL NPC_CharmInit( int meindex ) +{ + /*--ƽҷ¼ëɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPECHARM ); + return TRUE; + +} + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_CharmTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + /* */ + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + NPC_Charm_selectWindow( meindex, talkerindex, 0); +} + + +/* + * + */ +static void NPC_Charm_selectWindow( int meindex, int toindex, int num) +{ + + char token[1024]; + char escapedname[1024]; + int fd = getfdFromCharaIndex( toindex); + int buttontype = 0; + int windowtype = 0; + int windowno = 0; + int cost = 0; + int chartype; + + /*--̼⻥мƥƱɬ--*/ + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + switch( num) { + case 0: + /*-- --*/ + sprintf(token,"4\n ʦ " + "\n\n ӭ٣Ҫʲأ" + "\n " + "\n\n " + "\n\n ʲҲ " + ); + + buttontype = WINDOW_BUTTONTYPE_NONE; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_CHARM_START; + break; + + case 1: + cost = NPC_CharmCost( meindex, toindex); + if(cost == -1){ + sprintf(token," ʦ " + "\n\n" + "\n\nԶࡡ" + ); + buttontype = WINDOW_BUTTONTYPE_OK; + }else{ + sprintf(token," ʦ " + "\n,ǧػݼʵʩ??" + "\n\n ҪĻ" + "\nҪ%6dstoneࡣ" + "\n\nʹҲ",cost + ); + buttontype = WINDOW_BUTTONTYPE_YESNO; + + } + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHARM_END; + + break; + + case 2: + cost = NPC_CharmCost( meindex, toindex); + chartype = CHAR_getInt( toindex, CHAR_IMAGETYPE); + + if(cost > CHAR_getInt( toindex, CHAR_GOLD)) { + sprintf(token," ʦ " + "\n\n ѽ!Ǯࡣ" + "\n ȥǮ´ɣ" + ); + + }else{ + NPC_CharmUp( meindex, toindex); + + /*--ƽҷ¼巽Ȼë --*/ + switch( chartype) { + case CHAR_IMAGETYPE_GIRL: + sprintf(token," ʦ " + "\n\n ,ޣ" + "\n\nɰأ" + ); + + break; + case CHAR_IMAGETYPE_BOY: + sprintf(token," ʦ " + "\n\n ,ޣ" + "\n\nDzDZȸղҪ˧أ" + ); + break; + + case CHAR_IMAGETYPE_CHILDBOY: + case CHAR_IMAGETYPE_CHILDGIRL: + sprintf(token," ʦ " + "\n\n ,ޣ" + "\n\n ıúÿɰࡣ" + ); + break; + + case CHAR_IMAGETYPE_MAN: + sprintf(token," ʦ " + "\n\n ,ޣ" + "\n\n øأ" + ); + break; + + case CHAR_IMAGETYPE_WOMAN: + sprintf(token," ʦ " + "\n\n ,ޣ" + "\n\n DZأ" + ); + break; + + } + } + + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHARM_END; + break; + } + + makeEscapeString( token, escapedname, sizeof( escapedname)); + /*-ƥ˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + escapedname); + +} + + +/*----------------------------------------- +ͷʧ߯Ȼݱ̫ľ£ +-------------------------------------------*/ +void NPC_CharmWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) return; + + switch( seqno){ + case CHAR_WINDOWTYPE_CHARM_START: + if(atoi( data) == 2) { + NPC_Charm_selectWindow( meindex, talkerindex, 1 ); + } + break; + + case CHAR_WINDOWTYPE_CHARM_END: + if(select == WINDOW_BUTTONTYPE_YES) { + NPC_Charm_selectWindow( meindex, talkerindex, 2 ); + } + break; + } + +} + + + +/*-- --*/ +void NPC_CharmUp(int meindex,int talker) +{ + int cost; + int i; + int petindex; + char petsend[64]; + + /*--ëӼƽﵤ--*/ + cost = NPC_CharmCost( meindex, talker); + CHAR_setInt( talker, CHAR_GOLD, + CHAR_getInt( talker, CHAR_GOLD) - cost); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + + /*-- ߨ߶ئ¦ߨ߱--*/ + if(CHAR_getInt( talker, CHAR_CHARM) + CHARMHEAL >= 100) { + CHAR_setInt( talker, CHAR_CHARM, 100); + }else{ + /*-- ë--*/ + CHAR_setInt(talker, CHAR_CHARM, + (CHAR_getInt( talker, CHAR_CHARM) + CHARMHEAL)); + } + + /*-- ޥ--*/ + CHAR_complianceParameter( talker ); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_CHARM); + + + /*--ʸɷ¶ëޥ--*/ + for( i = 0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + /* ƽҷ¼ */ + if( !CHAR_CHECKINDEX( talker ) ) continue; + + /*--ɷ¶Ʃ--*/ + CHAR_complianceParameter( petindex ); + sprintf( petsend, "K%d", i ); + CHAR_sendStatusString( talker , petsend ); + } +} + + +/*--żң--*/ +int NPC_CharmCost(int meindex,int talker) +{ + int cost; + int level; + int charm; + int trans; + + level = CHAR_getInt( talker, CHAR_LV); + charm = CHAR_getInt( talker, CHAR_CHARM); + trans = CHAR_getInt( talker, CHAR_TRANSMIGRATION); + + if(charm >= 100) return -1; + + if(charm <= 1) charm = WARU; + + /*-- ңֿ --*/ + cost = level * RATE * (charm / WARU) * (trans+1); + + return cost; + +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_checkman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_checkman.c new file mode 100644 index 0000000..1fe3864 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_checkman.c @@ -0,0 +1,472 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" + + +//ػƥ°׷º뼰 +#define MAXEVENTFLG 96 + +/* + * ì׷ºë + * + */ + +static void NPC_CheckMan_selectWindow( int meindex, int toindex, int num); +int NPC_NowFlgCheck(int meindex,int talker,int now[MAXEVENTFLG]); +int NPC_EndFlgCheck(int meindex,int talker ,int nowflg[MAXEVENTFLG]); +BOOL NPC_FlgCheckMain( int meindex,int talker,int nowindex,int now[MAXEVENTFLG],char *work2); + +/********************************* +* +*********************************/ +BOOL NPC_CheckManInit( int meindex ) +{ + /*--ƽҷ¼ëɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPECHECKMAN); + + return TRUE; +} + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_CheckManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + /* */ + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + // ټ̼ + NPC_CheckMan_selectWindow( meindex, talkerindex, 0); + +} + + +/* + * + */ +static void NPC_CheckMan_selectWindow( int meindex, int talker, int num) +{ + + char token[1024]; + char work[256]; + char work2[512]; + + char escapedname[1024]; + int fd = getfdFromCharaIndex( talker); + int buttontype = 0; + int windowtype = 0; + int windowno = 0; + int now[MAXEVENTFLG]; + int nowindex; + int i; + int page; + + work[0] = 0; + work2[0] = 0; + token[0] = 0; + + now[0] =0; + + /*--̼⻥мƥƱɬ--*/ + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + switch( num) { + + case 0: + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,0); + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,0); + + /*-- --*/ + sprintf(token,"3\n Ѩ " + "\nػ׷ºë" + "\n" + "\n գNOW׷ºͣ " + "\n գEND׷ºͣ " + "\n\n գNOW׷º " + "\n գEND׷º " + ); + + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_CHECKMAN_START; + break; + + //NOW׷º뼰ǩ + case 1: + + //NOW׷º뼰 + nowindex = NPC_NowFlgCheck( meindex, talker, now); + + //ʸ + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) ; + + if(page == 0 || page == 1){ + i = 0; + }else{ + i = 83; + } + + //ʸ + for(; i < nowindex ; i++) + { + sprintf(work,"%d,",now[ i]); + strcat(work2,work); + } + + sprintf(token,"Ѩ " + "\nػ Ȼ NOWì" + "\n%s" + ,work2); + + if(page != 2 && nowindex > 83) + { + //ƹ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,1); + //ʸ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,2); + + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHECKMAN_MAIN; + + }else{ + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + } + + break; + + + //END׷º뼰ǩ + case 2: + // ׷º뼰 + nowindex = NPC_EndFlgCheck( meindex, talker, now); + + //ʸ + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) ; + + if(page == 0 || page == 1){ + i = 0; + }else{ + i = 83; + } + work2[0]=0; + + //ʸ + for(; i < nowindex ; i++) + { + sprintf(work,"%d,",now[ i]); + strcat(work2,work); + } + sprintf(token,"Ѩ " + "\nػ Ȼ ENDì" + "\n%s" + ,work2); + + if(page != 2 && nowindex > 83) + { + //ƹ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,2); + //ʸ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,2); + + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHECKMAN_MAIN; + + }else{ + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + } + + break; + + + // NOW׷º뼰 + case 4: + { + + //NOW׷º + nowindex = NPC_NowFlgCheck( meindex, talker, now); + + if(NPC_FlgCheckMain( meindex, talker, nowindex,now,work2) + == FALSE) + { + return; + } + + + sprintf(token,"Ѩ " + "\nػ Ȼ NOWì" + "\n%s" + ,work2); + + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) ; + nowindex = (nowindex / ((6*page)+1)); + + if(page != 16 && nowindex != 0) + { + //ƹ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,4); + //ʸ + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC); + page++; + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,page); + + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHECKMAN_MAIN; + }else{ + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + } + + } + break; + + // END׷º뼰 + case 5: + { + //END׷º뼰 + nowindex = NPC_EndFlgCheck( meindex, talker, now); + + + if(NPC_FlgCheckMain( meindex, talker, nowindex, now, work2) + == FALSE) + { + return; + } + + sprintf(token,"Ѩ " + "\nػ Ȼ ENDì" + "\n%s" + ,work2); + + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) ; + + nowindex = (nowindex / ((6*page)+1)); + + if(page != 16 && nowindex != 0) + { + //ƹ + CHAR_setWorkInt(talker, CHAR_WORKSHOPRELEVANT, 5); + //ʸ + page = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC); + page++; + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, page); + + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_CHECKMAN_MAIN; + }else{ + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + } + + } + } + + makeEscapeString( token, escapedname, sizeof( escapedname)); + /*-ƥ˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + escapedname); + +} + + +/*----------------------------------------- +ͷʧ߯Ȼݱ̫ľ£ +-------------------------------------------*/ +void NPC_CheckManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int datano; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) return; + + datano = atoi(data); + + if(select == WINDOW_BUTTONTYPE_OK) + { + NPC_CheckMan_selectWindow( meindex, talkerindex, 0 ); + }else if(select == WINDOW_BUTTONTYPE_CANCEL) { + return; + } + + + + + switch(CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT)){ + case 1: + if(CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTSEC) == 2){ + NPC_CheckMan_selectWindow( meindex, talkerindex, 1 ); + } + break; + + case 2: + if(CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTSEC) == 2){ + NPC_CheckMan_selectWindow( meindex, talkerindex, 2 ); + } + break; + + case 4: + if(CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTSEC) >= 2){ + NPC_CheckMan_selectWindow( meindex, talkerindex, 4 ); + } + + case 5: + if(CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTSEC) >= 2){ + NPC_CheckMan_selectWindow( meindex, talkerindex, 5 ); + } + + break; + } + + switch( datano ){ + case 1: + NPC_CheckMan_selectWindow( meindex, talkerindex, 1 ); + break; + + case 2: + NPC_CheckMan_selectWindow( meindex, talkerindex, 2 ); + break; + + case 4: + NPC_CheckMan_selectWindow( meindex, talkerindex, 4 ); + break; + + case 5: + NPC_CheckMan_selectWindow( meindex, talkerindex, 5 ); + break; + } + +} + +/* + *ì ׷ºë + */ +int NPC_NowFlgCheck(int meindex,int talker ,int nowflg[MAXEVENTFLG]) +{ + int i = 0; + int j = 0; + + for(i= 0; i < MAXEVENTFLG ; i++){ + if(NPC_NowEventCheckFlg( talker, i) == TRUE) + { + nowflg[j] = i; + j++; + } + } + + return j; +} + +/* + *ì ׷ºë + */ +int NPC_EndFlgCheck(int meindex,int talker ,int nowflg[MAXEVENTFLG]) +{ + int i = 0; + int j = 0; + + for(i= 0; i < MAXEVENTFLG ; i++){ + + if(NPC_EventCheckFlg( talker, i) == TRUE) + { + nowflg[j] = i; + j++; + } + } + + return j; +} + +/* + * + * + */ +BOOL NPC_FlgCheckMain( int meindex,int talker,int nowindex,int now[MAXEVENTFLG],char *work2) +{ + int page; + int max; + int i; + int shou; + int j=1; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char work[512]; + char buf[40]; + char buf2[42]; + + //ʸ + page = CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) ; + + if(page == 0) { + page =1; + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,1) ; + } + + if(page == 1){ + i = 0; + if( nowindex >6 ){ + max =7; + }else{ + max =nowindex; + } + }else{ + max = (page * 6) +1; + i = max - 7; + shou = nowindex / max; + + if(shou == 0){ + max = nowindex; + }else{ + i = max - 7; + } + } + + //ìƻ̤ľ°̻ë ij + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("NPC_CheckMan:GetArgStrErr"); + return FALSE; + } + + work[0] = 0; + work2[0] = 0; + + //ʸ + for(; i < max ; i++) + { + sprintf(work,"#%d:",now[ i]); + j = 1; + while( getStringFromIndexWithDelim(argstr, "|", j, buf,sizeof( buf)) + !=FALSE ) + { + j++; + if(strstr(buf,work) != NULL){ + sprintf(buf2,"%s\n",buf); + strcat(work2,buf2); + break; + } + } + } + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_dengon.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_dengon.c new file mode 100644 index 0000000..82d083f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_dengon.c @@ -0,0 +1,248 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "handletime.h" + +static BOOL NPC_DengonReadString( int meindex, int id, char *str ); +static void NPC_DengonWriteString( int meindex, int talkerindex, int id, char *str ); + +#define DENGONFILEDIR "./Dengon/" +#define DENGONFILELINENUM 1000 +#define DENGONFILESTRINGSIZE 256 +#define DENGONFILECOUNTERSIZE 11 +#define DENGONFILEENTRYSIZE (DENGONFILECOUNTERSIZE+DENGONFILESTRINGSIZE+1) +#define MESSAGEINONEWINDOW 7 + +char NPC_sendbuf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW]; + +BOOL NPC_DengonInit( int meindex ) +{ + char filename[256], tmp[256]; + FILE *f; + int i,j; + int id, maxid; + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEDENGON ); + + snprintf( filename,sizeof(filename), "%s%d_%d_%d", + DENGONFILEDIR, CHAR_getInt( meindex, CHAR_FLOOR ), + CHAR_getInt( meindex, CHAR_X ), + CHAR_getInt( meindex, CHAR_Y ) ); + + if( ! (f=fopen( filename, "r" )) ){ + f = fopen( filename, "w" ); + if( f ){ + }else{ + print( "ERROR:Can't create Dengonfile %s!\n",filename ); + return FALSE; + } + for( j = 0; j < DENGONFILELINENUM; j++ ){ + fwrite( "0000000000:", sizeof(char), + DENGONFILECOUNTERSIZE, f); + for( i=0;i maxid ) { + maxid = id; + } + } + + CHAR_setWorkInt( meindex, CHAR_WORKDENGONMAXID, maxid ); + + fclose(f); + return TRUE; +} + + +void NPC_DengonWindowTalked( int index, int talker, + int seqno, int select, char *data) +{ + char buf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW*2]; + + int id; + +#define DENGONDISTANCE 3 + + if(NPC_Util_CharDistance(index,talker) > DENGONDISTANCE ) return; + if( seqno == CHAR_WINDOWTYPE_DENGON) { + int buttontype = 0; + int maxid; + switch( select ){ + case WINDOW_BUTTONTYPE_NEXT: + case WINDOW_BUTTONTYPE_PREV: + id = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) + + MESSAGEINONEWINDOW + * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + + maxid = CHAR_getWorkInt( index, CHAR_WORKDENGONMAXID ); + + if( id > maxid) id = maxid; + else if( id < 2 ) id = 1; + + buttontype = WINDOW_BUTTONTYPE_OKCANCEL; + if( id == maxid ) buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( id == 1 ) buttontype |= WINDOW_BUTTONTYPE_NEXT; + else { + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, id); + if( NPC_DengonReadString( index, id, NPC_sendbuf ) ){ + int fd; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 )return; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, + buttontype, + CHAR_WINDOWTYPE_DENGON, + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; + case WINDOW_BUTTONTYPE_OK: + if( strlen( data) == 0 ) break; + id = CHAR_getWorkInt(index, CHAR_WORKDENGONMAXID ); + id++; + NPC_DengonWriteString( index, talker, id, data ); + CHAR_setWorkInt(index, CHAR_WORKDENGONMAXID, id ); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, id); + if( NPC_DengonReadString( index, id, NPC_sendbuf ) ){ + int fd; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 )return; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_DENGON, + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; + default: + break; + } + } +} + + + + +void NPC_DengonLooked( int meindex, int lookedindex ) +{ + int maxid; + char buf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW*2]; + if( NPC_Util_CharDistance( lookedindex, meindex ) > 1) return; + maxid = CHAR_getWorkInt( meindex, CHAR_WORKDENGONMAXID ); + if( NPC_DengonReadString( meindex, maxid, NPC_sendbuf ) ){ + int fd; + fd = getfdFromCharaIndex( lookedindex ); + if( fd == -1 )return; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_DENGON, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + + CHAR_setWorkInt( lookedindex, CHAR_WORKSHOPRELEVANT, maxid); + + } + +} + +static BOOL NPC_DengonReadString( int meindex, int id, char *str ) +{ + char filename[256]; + char readbuf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW]; + + FILE *f; + int maxid, i, sendid, len; + char *writeptr, *readptr; + + + maxid = CHAR_getWorkInt( meindex, CHAR_WORKDENGONMAXID ); + if( id > maxid ) id = maxid; + sendid = id - MESSAGEINONEWINDOW + 1; + + if( sendid < maxid - DENGONFILELINENUM + 1 ){ + sendid = maxid - DENGONFILELINENUM + 1; + } + + if( sendid < 1 ) sendid = 1; + + snprintf( filename,sizeof(filename), "%s%d_%d_%d", + DENGONFILEDIR, CHAR_getInt( meindex, CHAR_FLOOR ), + CHAR_getInt( meindex, CHAR_X ), + CHAR_getInt( meindex, CHAR_Y ) ); + + writeptr = str; + strcpy( writeptr, " ԰\n"); + len = strlen(writeptr); + writeptr += len; + + f = fopen( filename, "r" ); + if( !f ) return FALSE; +{ + char buf[DENGONFILEENTRYSIZE]; + int wptr = 0; + readbuf[0] = '\0'; + for( i = 0; i < MESSAGEINONEWINDOW; i ++ ) { + fseek( f, ((sendid+i)%DENGONFILELINENUM)*DENGONFILEENTRYSIZE, SEEK_SET ); + fread( buf, sizeof(char), + DENGONFILEENTRYSIZE , f ); + memcpy( &readbuf[wptr], buf,sizeof( buf)); + wptr += DENGONFILEENTRYSIZE; + } +} + fclose(f); + readptr = readbuf + DENGONFILECOUNTERSIZE; + for( i=0;i +#include + + +static int NPC_Door_isOpen( int meindex ); + +/* + * ʧë ׻NPC ۢئѼ + * Door + * + * NPCARGUMENT + * + * og|cg|idname|swcount|closetime_sec|soonflg0/1|passflg0/1/2 + * + * passflg 1ʴƥؤ ئ£2 + * 姸վئУ 0ɵƥئУ + * + * ë϶£ ƥ޷ɻƥ1ޣ + * ɬë̤巴 įۢئëֹ ۢƥؤ£ + * + * мԻCë˪ѻؤ¾գ1info, į + * ë ƻչëͷʧ ľ + * ػ ޥئ£ + */ + +#define NPC_DOOR_OPENMSG "ʧ!" +#define NPC_DOOR_CLOSEMSG "ʧëƻ!" +#define NPC_DOOR_CANTOPENMSG "ؤئмƥʧëʳ绥\ +ƥئ!" + +#define ROPEGRAPHIC 9259 /* Ǿ ؤɧľئз */ + +enum{ + NPC_DOOR_FLG_SOONCLOSE = 1, + NPC_DOOR_FLG_WATCHCLOSE = 2 +}; + + +/* + * ʧɬë±巴ƥ + * maxhp , maxmp , level , str , tough ë0緽У + * + */ +BOOL NPC_DoorInit( int meindex ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char settingdir[1024]; + char buf[256]; + + NPC_Util_GetArgStr( meindex, arg, sizeof( arg)); + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE,CHAR_EVENT_NPC); + + getStringFromIndexWithDelim(arg, "|" , 1 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOOROPENG , atoi( buf )); + getStringFromIndexWithDelim(arg, "|" , 2 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORCLOSEG , atoi( buf )); + getStringFromIndexWithDelim(arg, "|" , 3 , buf,sizeof(buf) ); + CHAR_setWorkChar( meindex , CHAR_WORKDOORNAME , buf ); + strcpysafe( settingdir,sizeof( settingdir) , buf ); + getStringFromIndexWithDelim(arg, "|" , 4 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORSWITCHCOUNT , atoi( buf )); + getStringFromIndexWithDelim(arg, "|" , 5 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORCLOSETIME , atoi( buf )); + + CHAR_setInt( meindex , CHAR_MERCHANTLEVEL , atoi( buf )); + getStringFromIndexWithDelim(arg, "|" , 6 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORSOONFLG , atoi( buf )); + + getStringFromIndexWithDelim(arg, "|" , 7 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORPASSFLG , atoi( buf )); + CHAR_setWorkInt( meindex , CHAR_WORKDOORORIGINALGRAPHIC, + CHAR_getInt( meindex,CHAR_BASEIMAGENUMBER )); + CHAR_setInt( meindex, CHAR_LV, 0 ); + if( getStringFromIndexWithDelim( arg , "|" , 8 , buf ,sizeof( buf ))){ + if( strncmp( buf , "title" ,5 ) == 0 ){ + print( "This is a title door:'%s'\n" , buf ); + CHAR_setWorkInt( meindex , CHAR_WORKDOORPASSFLG ,0 ); + CHAR_setWorkChar( meindex , CHAR_WORKDOORTITLE , buf ); + CHAR_setInt( meindex, CHAR_LV, 1 ); + } else if( isdigit( buf[0] )){ + if( getStringFromIndexWithDelim(arg, "|" , 8 , buf,sizeof(buf) )) + CHAR_setWorkChar( meindex, CHAR_WORKDOORGOLDLIMIT, buf); + if( getStringFromIndexWithDelim(arg, "|" , 10 , buf,sizeof(buf) )) + CHAR_setWorkChar( meindex, CHAR_WORKDOORWEEK, buf); + if( getStringFromIndexWithDelim(arg, "|" , 11 , buf,sizeof(buf) )) + CHAR_setWorkChar( meindex, CHAR_WORKDOORHOUR, buf); + if( getStringFromIndexWithDelim(arg, "|" , 12 , buf,sizeof(buf) )) + CHAR_setWorkChar( meindex, CHAR_WORKDOORMINUTE, buf); + } + } + + CHAR_setInt( meindex , CHAR_HP , 0 ); + CHAR_setInt( meindex , CHAR_MP , 0 ); + CHAR_setInt( meindex , CHAR_MAXMP , 0 ); + CHAR_setInt( meindex , CHAR_STR , 0 ); + CHAR_setInt( meindex , CHAR_TOUGH, 0 ); + { + int g = CHAR_getWorkInt( meindex , CHAR_WORKDOOROPENG ); + if( g >= 11900 && g <= 11915 ){ + CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , 15 ); + } else if( g >= 11916 && g <= 11931 ){ + + CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , 16 ); + } else { + CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , -1 ); + } + if(CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG )==2){ + CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , -2 ); + } + if( CHAR_getInt( meindex , CHAR_BASEIMAGENUMBER ) == + ROPEGRAPHIC ){ + CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID,-2 ); + } + } + + { + int closeg = CHAR_getWorkInt( meindex , CHAR_WORKDOORCLOSEG ); + int dir = -1; + switch( closeg ){ + case 11900: dir = 6; break; /* ʧ Ի */ + case 11902: dir = 0; break; /* Ի */ + case 11904: dir = 2; break; /* Ŀ */ + case 11906: dir = 4; break; /* Ŀ */ + + case 11908: dir = 6; break; /* Ӯʧ Ի */ + case 11910: dir = 0; break; /* Ի */ + case 11912: dir = 2; break; /* Ŀ */ + case 11914: dir = 4; break; /* Ŀ */ + + case 11916: dir = 6; break; /* ˼ʧ Ի */ + case 11918: dir = 0; break; /* Ի */ + case 11920: dir = 2; break; /* Ŀ */ + case 11922: dir = 4; break; /* Ŀ */ + + case 11924: dir = 6; break; /* Ӯ˼ʧ Ի */ + case 11926: dir = 0; break; /* Ի */ + case 11928: dir = 2; break; /* Ŀ */ + case 11930: dir = 4; break; /* Ŀ */ + + case 11958: dir = 2; break; /* Ӯ ʧ Ŀ */ + case 11960: dir = 4; break; /* Ŀ */ + case 11962: dir = 6; break; /* Ի */ + case 11964: dir = 0; break; /* Ի */ + + case 11966: dir = 2; break; /* ʧ Ŀ */ + case 11968: dir = 4; break; /* Ŀ */ + case 11970: dir = 6; break; /* Ի */ + case 11972: dir = 0; break; /* Ի */ + + case 11978: dir = 2; break; /* Ӯżʧ Ŀ */ + case 11980: dir = 4; break; /* Ŀ */ + case 11982: dir = 6; break; /* Ի */ + case 11984: dir = 0; break; /* Ի */ + + case 11986: dir = 2; break; /* żʧ Ŀ */ + case 11988: dir = 4; break; /* Ŀ */ + case 11990: dir = 6; break; /* Ի */ + case 11992: dir = 0; break; /* Ի */ + + default: break; + } + if( dir >= 0 )CHAR_setInt(meindex,CHAR_DIR,dir); + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEDOOR ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + CHAR_setInt( meindex , CHAR_WORKDOORSWITCHCURRENT , 0 ); + CHAR_setWorkInt( meindex, CHAR_WORKDOOREXPIRETIME, 0xffffffff); + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG ) == 1){ + NPC_ROOMINFO roominfo; + if( NPC_RoomAdminNew_ReadFile( CHAR_getWorkChar( meindex, CHAR_WORKDOORNAME), &roominfo) == TRUE ){ + NPC_DoorSetPasswd( meindex, roominfo.passwd); + CHAR_setWorkInt( meindex, CHAR_WORKDOOREXPIRETIME, roominfo.expire); + }else { + NPC_DoorSetPasswd( meindex, "8hda8iauia90494jasd9asodfasdf89" ); + if( getStringFromIndexWithDelim(arg, "|" , 13 , buf,sizeof(buf) )) + if( strlen( buf) != 0 ) + NPC_DoorSetPasswd( meindex, buf ); + } + } + + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER , CHAR_getWorkInt(meindex, CHAR_WORKDOORCLOSEG)); + NPC_DoorRefreshOverFlg( meindex ); + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_NPC); + return TRUE; +} +void NPC_DoorAddSwitchCounter( int meindex , int i , int doindex ) +{ + if( i != 0 && CHAR_getWorkInt( meindex, CHAR_WORKDOORSWITCHCOUNT) + != 0 ){ + CHAR_setWorkInt( meindex, CHAR_WORKDOORSWITCHCURRENT , + CHAR_getWorkInt(meindex, + CHAR_WORKDOORSWITCHCURRENT) + + i ); + if( CHAR_getWorkInt( meindex, CHAR_WORKDOORSWITCHCURRENT ) == + CHAR_getWorkInt( meindex, CHAR_WORKDOORSWITCHCOUNT) ){ + NPC_DoorOpen( meindex , doindex ); + } else { + NPC_DoorClose( meindex , doindex ); + } + } +} + +void NPC_DoorSetSwitchCounter( int meindex, int i , int doindex ) +{ + if( !CHAR_CHECKINDEX(meindex))return; + CHAR_setWorkInt( meindex , CHAR_WORKDOORSWITCHCURRENT , i ); + NPC_DoorAddSwitchCounter( meindex, 0 , doindex ); +} + +static int NPC_DoorSamePos( int meindex ){ + int iWork; + OBJECT object; + int floor = CHAR_getInt( meindex, CHAR_FLOOR ); + int x = CHAR_getInt( meindex, CHAR_X ); + int y = CHAR_getInt( meindex, CHAR_Y ); + + for( object=MAP_getTopObj( floor, x,y ); object ; object = NEXT_OBJECT(object) ){ + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) != OBJTYPE_CHARA )continue; + iWork = OBJECT_getIndex(objindex); + if( CHAR_getInt(iWork,CHAR_HP) < 0 )continue; + if( CHAR_getInt( iWork,CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + return iWork; + } + } + return -1; +} + +void NPC_DoorWatch( int myobjindex, int moveobjindex, CHAR_ACTION act, + int x, int y, int dir, int* opt, int optlen ) +{ + unsigned long closetime; + int meindex, moveindex; + + if( OBJECT_getType( moveobjindex) != OBJTYPE_CHARA ) { + return; + } + meindex = OBJECT_getIndex(myobjindex); + moveindex = OBJECT_getIndex(moveobjindex); + if( NPC_Door_isOpen( meindex ) == 0 )return; + if( CHAR_getInt( moveindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return; + } + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORSOONFLG )){ + if( CHAR_getInt( meindex , CHAR_TALKCOUNT ) > 0 ){ + if( NPC_DoorSamePos( meindex ) == -1 ){ + NPC_DoorClose(meindex , -1 ); + CHAR_setInt( meindex , CHAR_TALKCOUNT, 0 ); + } + } + }else + if( CHAR_getInt( meindex, CHAR_MERCHANTLEVEL ) >= 0 ){ + closetime = (unsigned long )CHAR_getWorkInt( meindex , CHAR_WORKDOORCLOSETIME ); + if( (unsigned long) NowTime.tv_sec > (unsigned long) closetime ){ + NPC_DoorClose(meindex , -1 ); + } + } +} + + +#if 1 +void NPC_DoorOff( int meindex , int movedindex ) +{ + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORSOONFLG )){ + NPC_DoorClose(meindex , -1 ); + } else { + } +} +#endif + +void NPC_DoorPostOver( int meindex , int movedindex ) +{ + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORSOONFLG )){ + CHAR_setInt( meindex , CHAR_TALKCOUNT, 1 ); + CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); /* ɧľئ */ + } +} + +void NPC_DoorLooked( int meindex , int lookedindex ) +{ + int needkey; + + if( CHAR_getInt( meindex , CHAR_LV )){ + char token[32]; + char *p = CHAR_getWorkChar( meindex , CHAR_WORKDOORTITLE ); + int i,j,ok=FALSE; + for(i = 0 ; ; i++ ){ + int r; + r = getStringFromIndexWithDelim( p,":",2+i,token ,sizeof(token)); + if(r){ + int titleind = atoi( token ); + for(j=0;j=1 ){ + if( NPC_Door_isOpen( meindex ) ){ + NPC_DoorFlip( meindex , lookedindex ); + return; + } +#define NPC_DOOR_EXPIRE_MSG "%s ķЧ %d/%d %d:%d" + else { + if( CHAR_getWorkInt( meindex, CHAR_WORKDOOREXPIRETIME) + != 0xffffffff ){ + struct tm tmwk; + time_t expire = CHAR_getWorkInt( meindex, CHAR_WORKDOOREXPIRETIME); + char msgbuf[128]; + + NPC_ROOMINFO roominfo; + /* ɵ ë */ + NPC_RoomAdminNew_ReadFile( + CHAR_getWorkChar( meindex, CHAR_WORKDOORNAME), + &roominfo); + memcpy( &tmwk, localtime( &expire), sizeof( tmwk)); + snprintf( msgbuf, sizeof( msgbuf), NPC_DOOR_EXPIRE_MSG, + roominfo.charaname, + tmwk.tm_mon+1, tmwk.tm_mday, + tmwk.tm_hour, tmwk.tm_min); + CHAR_talkToCli( lookedindex, meindex, msgbuf, CHAR_COLORWHITE); + } + } + #undef NPC_DOOR_EXPIRE_MSG + return; + } + needkey = CHAR_getWorkInt( meindex , CHAR_WORKDOORKEYITEMID ); + if( needkey >= 0 ){ + if( NPC_Util_countHaveItem( lookedindex , needkey ) > 0 ){ + NPC_DoorFlip( meindex , lookedindex); + } else { + CHAR_talkToCli( lookedindex , -1 , NPC_DOOR_CANTOPENMSG , CHAR_COLORWHITE ); + } + } else if( needkey == -1 ){ + NPC_DoorFlip(meindex , lookedindex ); + } else { + CHAR_talkToCli( lookedindex , -1 , "ƺҲ򲻿" , CHAR_COLORWHITE); + } +} +void NPC_DoorTalked( int meindex , int talkerindex , char *msg , int color ) +{ + char *m = CHAR_getWorkChar( meindex , CHAR_WORKDOORPASSWD ); + if(NPC_Util_CharDistance( talkerindex, meindex ) > 1)return; + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG ) != 1 ){ + return; + } + if( CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG ) >= 1 && + ((unsigned long)NowTime.tv_sec) > (unsigned long) + CHAR_getWorkInt( meindex , CHAR_WORKDOOREXPIRETIME )){ + print( "RINGO: passdoor expired ( talked )\n" ); + return; + } + if( m[0] == '\0' )return; + cutDotsTail( msg ); + if( strcmp( m , msg ) == 0 ){ + NPC_DoorFlip( meindex , talkerindex ); + }else { + CHAR_talkToCli( talkerindex , -1 , "벻ȷ", CHAR_COLORWHITE ); + } +} + +int NPC_DoorSearchByName( char *name ) +{ + int i; + int charnum = CHAR_getCharNum(); + + for(i= CHAR_getPlayerMaxNum() + CHAR_getPetMaxNum(); + i= 0 ) CHAR_talkToCli( doindex , -1 , NPC_DOOR_CLOSEMSG, CHAR_COLORWHITE ); + CHAR_setInt( meindex , CHAR_TALKCOUNT, 0 ); +} +void NPC_DoorOpen(int meindex , int doindex ) +{ + CHAR_setWorkInt( meindex , CHAR_WORKDOORCLOSETIME, + NowTime.tv_sec + + CHAR_getInt( meindex , CHAR_MERCHANTLEVEL)); + CHAR_setInt( meindex , CHAR_BASEIMAGENUMBER , + CHAR_getWorkInt( meindex,CHAR_WORKDOOROPENG )); + NPC_DoorRefreshOverFlg( meindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, + CHAR_WORKOBJINDEX )); + if( doindex >= 0 ) + CHAR_talkToCli( doindex , -1, NPC_DOOR_OPENMSG ,CHAR_COLORWHITE); +} + +static int NPC_Door_isOpen( int meindex ) +{ + int now_g = CHAR_getInt( meindex , CHAR_BASEIMAGENUMBER ); + int open_g = CHAR_getWorkInt( meindex ,CHAR_WORKDOOROPENG ); + if( now_g == open_g ) return 1; else return 0; +} + +BOOL NPC_DoorRefreshOverFlg( int meind ) +{ + if( !CHAR_CHECKINDEX(meind))return FALSE; + if( NPC_Door_isOpen( meind ) ==1 ){ + CHAR_setFlg( meind , CHAR_ISOVERED , 1 ); + } else { + CHAR_setFlg( meind , CHAR_ISOVERED , 0 ); + } + return TRUE; +} + +BOOL NPC_DoorSetRopeFlag(int fl,int x,int y, int flag ) +{ + int ind = NPC_DoorSearchByPosition( fl,x,y ); + if( ind < 0 ) return FALSE; + if( flag ){ + CHAR_setInt( ind , CHAR_BASEIMAGENUMBER , ROPEGRAPHIC ); + } else { + CHAR_setInt(ind , CHAR_BASEIMAGENUMBER , 0 ); + } + NPC_DoorRefreshOverFlg( ind ); + CHAR_sendCToArroundCharacter( + CHAR_getWorkInt( ind , CHAR_WORKOBJINDEX )); + + return TRUE; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_doorman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_doorman.c new file mode 100644 index 0000000..06ec825 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_doorman.c @@ -0,0 +1,215 @@ +#include "version.h" +#include +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "item.h" +#include "util.h" +#include "handletime.h" +#include "npc_doorman.h" +#include "npc_door.h" +#include "npcutil.h" +#include "configfile.h" +/* + * + * Իʧؤ幫ʧëվ巽ȻNPC. + * ʧئԻcreate·ƥʧë۽³绥ƥ£ + * ئƾľƽҷëƻԻ8Ѩʧ + * ͻ帲ƻ£ۿ׹ʧ ݱ巰ʳئ£ + * + * ̵̼Talkƥ + * + * ʧë׻ + * + * 1 ë£۰ƥշ gold|100 + * 2 ʧ ةë1۰ ۰ƥշ item|45 + * 3 ʧ ةë Ȼ¾Ʃ£ Ȼշʣitemhave|44 + * 4 ʧ ةë ȻئоƩ£ Ȼئշʣ + * itemnothave|333 + * 5 įëȻ¾Ʃ£ Ȼշʣ titlehave|string + * 6 įëȻئоƩ£ Ȼئշʣ + * titlenothave|string + * + * ئߤ 緰ʣż + *100׷ʻƥʾƥУе100 + * ľ£ئԻУȻľ£ƥ100 + * ׷ףۣɴľ£ + * + * ʧ ة谼ϡë׷ʻƥʾʣ + * 36Ͼئƾ껯ǷȻշʣ + * + * + * + * ܷ + * + *1 ʧë絤 + *2 NPCëʧئԻ ʣ¦ë gold|100 + *3 NPC帲ƻ100ȻƥУɵ + *4 ʧлŻӼ + * + */ + +static void NPC_DoormanOpenDoor( char *nm ); + +BOOL NPC_DoormanInit( int meindex ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char dname[1024]; + + /* ìɬ */ + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE,CHAR_EVENT_NPC); + + CHAR_setInt( meindex , CHAR_HP , 0 ); + CHAR_setInt( meindex , CHAR_MP , 0 ); + CHAR_setInt( meindex , CHAR_MAXMP , 0 ); + CHAR_setInt( meindex , CHAR_STR , 0 ); + CHAR_setInt( meindex , CHAR_TOUGH, 0 ); + CHAR_setInt( meindex , CHAR_LV , 0 ); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPETOWNPEOPLE ); + CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); /* ľئз */ + + NPC_Util_GetArgStr( meindex, arg, sizeof( arg)); + + if(!getStringFromIndexWithDelim( arg, "|", 3, dname, sizeof(dname ))){ + print("RINGO: 趨ʱҪŵࡣ:%s:\n", + arg ); + return FALSE; + } + print( "RINGO: Doorman create: arg: %s dname: %s\n",arg,dname); + CHAR_setWorkChar( meindex , CHAR_WORKDOORMANDOORNAME , dname ); + + return TRUE; +} + +void NPC_DoormanTalked( int meindex , int talkerindex , char *msg , + int color ) +{ + char mode[128]; + char opt[256]; + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + /* ʧѨ1 ئշϼ */ + if(NPC_Util_CharDistance( talkerindex, meindex ) > 1)return; + + NPC_Util_GetArgStr( meindex, arg, sizeof( arg)); + + if( !getStringFromIndexWithDelim( arg, "|", 1, mode, sizeof( mode ))) + return; + + if( !getStringFromIndexWithDelim( arg, "|", 2, opt, sizeof( opt ) )) + return; + + if( strcmp( mode , "gold" ) == 0 ){ + int g = atoi( opt ); + int yn = NPC_Util_YN( msg ); + /*char *nm = CHAR_getChar( meindex , CHAR_NAME );*/ + char msg[256]; + + if( g > 0 && yn < 0 ){ + snprintf( msg ,sizeof( msg ) , + "Ҫ%dĽ", g ); + CHAR_talkToCli( talkerindex, meindex , msg, CHAR_COLORWHITE ); + } else if( g > 0 && yn == 0 ){ + snprintf( msg , sizeof( msg ), + " %dĽDZҪġ", g ); + } else if( g > 0 && yn == 1 ){ + int now_g = CHAR_getInt( talkerindex, CHAR_GOLD ); + if( now_g < g ){ + snprintf( msg , sizeof( msg ) , + " %dĽDZҪġ", g ); + CHAR_talkToCli( talkerindex, meindex , msg, CHAR_COLORWHITE ); + } else { + snprintf( msg , sizeof( msg ), + "%d յˡھš", g ); + CHAR_talkToCli( talkerindex, meindex , msg, CHAR_COLORWHITE ); + + /* ë */ + now_g -= g; + CHAR_setInt( talkerindex , CHAR_GOLD , now_g ); + /* ؤе ë˪ */ + CHAR_send_P_StatusString(talkerindex, CHAR_P_STRING_GOLD); + + /* ʧ */ + NPC_DoormanOpenDoor( + CHAR_getWorkChar( meindex, CHAR_WORKDOORMANDOORNAME)); + } + } + } else if( strcmp( mode , "item" ) == 0 ){ + CHAR_talkToCli( talkerindex, meindex , + "δ֧Ԯģʽ", + CHAR_COLORWHITE); + } else if( strcmp( mode , "itemhave" ) == 0 ){ + CHAR_talkToCli( talkerindex, meindex , + "δ֧Ԯģʽ", + CHAR_COLORWHITE); + } else if( strcmp( mode , "itemnothave" ) == 0 ){ + CHAR_talkToCli( talkerindex, meindex , + "δ֧Ԯģʽ", + CHAR_COLORWHITE); + } else if( strcmp( mode , "titlehave" ) == 0 ){ + CHAR_talkToCli( talkerindex, meindex , + "δ֧Ԯģʽ", + CHAR_COLORWHITE); + + } else if( strcmp( mode , "roomlimit" ) == 0 ){ + + /* м׻ؤ */ + char szOk[256], szNg[256], szBuf[32]; + int checkfloor; + int maxnum, i, iNum; + + if( !getStringFromIndexWithDelim( arg, "|", 2, szBuf, sizeof( szBuf ) )) + return; + + /* Ʃ°׷ʧ */ + if( sscanf( szBuf, "%d:%d", &checkfloor, &maxnum ) != 2 ){ + return; + } + + for( iNum = 0,i = 0; i < getFdnum(); i ++ ){ + /* ½巴 */ + if( CHAR_getCharUse( i ) == FALSE )continue; + if( CHAR_getInt( i, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER )continue; + /* ϶ü׷ʧ½ */ + if( CHAR_getInt( i, CHAR_FLOOR ) != checkfloor )continue; + iNum++; + } + if( !getStringFromIndexWithDelim( arg, "|", 5, szNg, sizeof( szNg ))){ + strcpy( szNg, "" ); /* ɡئƼ */ + } + if( !getStringFromIndexWithDelim( arg, "|", 4, szOk, sizeof( szOk ))){ + strcpy( szOk, "Űɡ" ); /* ɡؤԻ */ + } + + if( iNum >= maxnum ){ + /* ë */ + CHAR_talkToCli( talkerindex, meindex ,szNg, CHAR_COLORWHITE); + }else{ + /* ئ */ + CHAR_talkToCli( talkerindex, meindex ,szOk, CHAR_COLORWHITE); + NPC_DoormanOpenDoor( + CHAR_getWorkChar( meindex, CHAR_WORKDOORMANDOORNAME)); + } + + } else if( strcmp( mode , "titlenothave" ) == 0 ){ + CHAR_talkToCli( talkerindex, meindex , + "δ֧Ԯģʽ", + CHAR_COLORWHITE); + } +} + +/* + * ƥƻ׼ëͻʣ + * + */ +static void NPC_DoormanOpenDoor( char *nm) +{ + int doori = NPC_DoorSearchByName( nm ); + print( "RINGO: Doorman's Door: index: %d\n", doori ); + + NPC_DoorOpen( doori , -1 ); + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_duelranking.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_duelranking.c new file mode 100644 index 0000000..2ca9a51 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_duelranking.c @@ -0,0 +1,227 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "net.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_duelranking.h" +#include "handletime.h" + +static void NPC_Duelranking_selectWindow( int meindex, int toindex, int num, int select ); +#define NPC_DUELRANKING_WINDOWLINENUM 10 + + +enum{ + WINDOWTYPE_PKLIST_START=10, + WINDOWTYPE_PKLIST_SELECT, + WINDOWTYPE_PKLIST_SELECT1, + WINDOWTYPE_PKLIST_SELECT2, + + WINDOWTYPE_FAMILYCONTENDSTART, + WINDOWTYPE_FAMILYCONTENDSELECT, + WINDOWTYPE_FAMILYCONTENDLIST, + WINDOWTYPE_FAMILYCONTENDJOIN, + + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_WORK_BATTLELOOP = CHAR_NPCWORKINT2, +}; + +BOOL NPC_DuelrankingInit( int meindex ) +{ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEDUELRANKING ); + return TRUE; +} + +void NPC_DuelrankingLooked( int meindex , int lookedindex) +{ + NPC_Duelranking_selectWindow( meindex, lookedindex, 1, -1); +} + +static void NPC_Duelranking_selectWindow( int meindex, int toindex, int num, int select) +{ + + int fd; + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( NPC_Util_CharDistance( toindex, meindex ) > 1) return; + if( (fd = getfdFromCharaIndex( toindex)) == -1 ) return; + + switch( num){ + case 1: + { + char message[1024]; + char buf[2048]; + strcpy( message, + "1\n" + " Ҫһ \n\n\n" + " ǿǣ \n\n" + " Լ \n\n" + " \n\n" ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_DUELRANKING_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf))); + } + break; + } +} + +void NPC_DuelrankingWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int fdid = getFdidFromCharaIndex( talkerindex); + if( fdid == -1 ) return; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + switch( seqno){ + case CHAR_WINDOWTYPE_DUELRANKING_START: + if( atoi( data) == 3 ) { + saacproto_DBGetEntryByCount_send( acfd, + DB_DUELPOINT, 0, + NPC_DUELRANKING_WINDOWLINENUM, fdid, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } + if( atoi( data) == 5 ) { + char dbkey[256]; + CHAR_makeDBKey( talkerindex, dbkey, sizeof( dbkey)); + saacproto_DBGetEntryRank_send( acfd, DB_DUELPOINT, dbkey, fdid, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } + break; + case CHAR_WINDOWTYPE_DUELRANKING_TOPRANKING: + if( select == WINDOW_BUTTONTYPE_PREV || select == WINDOW_BUTTONTYPE_NEXT) { + int count = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + if( select == WINDOW_BUTTONTYPE_NEXT ) { + count += NPC_DUELRANKING_WINDOWLINENUM; + }else { + count -= NPC_DUELRANKING_WINDOWLINENUM; + } + + if( count < 0) count = 0; + saacproto_DBGetEntryByCount_send( acfd, + DB_DUELPOINT, + count, + NPC_DUELRANKING_WINDOWLINENUM, fdid, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + }else if( select == WINDOW_BUTTONTYPE_OK ) { + if( strlen( data) != 0 ) { + int count; + count = atoi( data); + if( count < 1 ) count = 1; + saacproto_DBGetEntryByCount_send( acfd, + DB_DUELPOINT, + count-1, + NPC_DUELRANKING_WINDOWLINENUM, fdid, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } + } + break; + } +} + +void NPC_Duelranking_PrintRanking( char *data, int count_start, int fdid, int msgid2) +{ + char message[1024]; + char buf[2048]; + int i; + int cnt = 0; + int button = 0; + int fd = getfdFromFdid( fdid); + if( fd == -1 ) return; + message[0] = '\0'; + snprintf( message, sizeof( message), + " ǿ\n\n" + " Rank DuelPoint Lv Name\n\n" ); + for( i = 1; ; i ++ ) { + char rankdata[256]; + char cdandname[64]; + char charaname[32]; + char rank[16]; + char score[64]; + char msgbuf[512]; + char cdkey[32]; + char lv[16]; + char hosi[6]; + + if( !getStringFromIndexWithDelim( data, "|", i, rankdata, sizeof( rankdata))) { + break; + } + if( !getStringFromIndexWithDelim( rankdata, ",", 2, rank, sizeof( rank)) ){ + continue; + } + if( !getStringFromIndexWithDelim( rankdata, ",", 3, cdandname, sizeof( cdandname)) ){ continue; + } + makeStringFromEscaped( cdandname); + if( !getStringFromIndexWithDelim( cdandname, "_", 1, cdkey, sizeof( cdkey)) ){ + continue; + } + if( !getStringFromIndexWithDelim( cdandname, "_", 2, charaname, sizeof( charaname)) ){ + continue; + } + if( !getStringFromIndexWithDelim( rankdata, ",", 4, score, sizeof( score)) ){ + continue; + } + if( !getStringFromIndexWithDelim( rankdata, ",", 5, lv, sizeof( lv)) ){ + lv[0] = '\0'; + } + { + char *mycdkey = CHAR_getChar( CONNECT_getCharaindex(fd), CHAR_CDKEY); + char *myname = CHAR_getChar( CONNECT_getCharaindex(fd), CHAR_NAME); + char engnum[4][3] = { "st","nd","rd","th"}; + int dsprank = atoi(rank); + if( dsprank > 3) dsprank = 3; + if( mycdkey != NULL && myname != NULL && strcmp( cdkey, mycdkey) == 0 && + strcmp( charaname, myname) == 0 ) { + strcpy( hosi, ""); + }else { + strcpy( hosi, ""); + } + snprintf( msgbuf, sizeof( msgbuf), "%s %5d%s %10s %3s %s\n", + hosi, + atoi(rank)+1, engnum[dsprank], + score, lv, + charaname ); + } + strcatsafe( message, sizeof( message), msgbuf); + cnt ++; + } + if( cnt == 0 ) { + strcpy( message, "\n ûˡ"); + button = WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_OK; + }else if( cnt < NPC_DUELRANKING_WINDOWLINENUM ) { + if( count_start >= NPC_DUELRANKING_WINDOWLINENUM) { + button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; + }else { + button = WINDOW_BUTTONTYPE_OK; + } + }else if( count_start == 0 ) { + button = WINDOW_BUTTONTYPE_NEXT|WINDOW_BUTTONTYPE_OK; + }else { + button = WINDOW_BUTTONTYPE_NEXT|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_OK; + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_WIDEMESSAGE, + button, + CHAR_WINDOWTYPE_DUELRANKING_TOPRANKING, + msgid2, + makeEscapeString( message, buf, sizeof(buf))); + + if( cnt == 0 ) { + CHAR_setWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKSHOPRELEVANT, -1); + }else { + CHAR_setWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKSHOPRELEVANT, count_start); + } +} + +void NPC_Duelranking_CallMyRanking( int count, int msgid, int msgid2) +{ + count -= 5; + if( count < 0 ) count = 0; + saacproto_DBGetEntryByCount_send( acfd, DB_DUELPOINT, + count, NPC_DUELRANKING_WINDOWLINENUM, + msgid, msgid2 ); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_eventaction.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_eventaction.c new file mode 100644 index 0000000..4f63354 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_eventaction.c @@ -0,0 +1,4531 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "map_deal.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "family.h" +#include "configfile.h" +#include "npc_transmigration.h" +#include "npc_exchangeman.h" +#ifdef _ANGEL_SUMMON +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif + +extern char* CHAR_setintdata[CHAR_DATAINTNUM]; +extern char* CHAR_setchardata[CHAR_DATACHARNUM]; +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +#include "profession_skill.h" +#include "chatmagic.h" +#endif + +enum{ + NPC_EVENTMODE_NONE, + NPC_EVENTMODE_OPEN, + NPC_EVENTMODE_EVENT, +}; + +typedef struct { + char arg[32]; + int born; + int dead; +}NPC_TimeMan; + +#define YOAKE 700 +#define NICHIBOTU 300 +#define SHOUGO 125 +#define YONAKA 500 + +static NPC_TimeMan TimeTble[] = { + {"ALLNIGHT", NICHIBOTU+1, YOAKE}, + {"ALLNOON", YOAKE+1, NICHIBOTU}, + {"AM", YONAKA+1, SHOUGO}, + {"PM", SHOUGO+1, YONAKA}, + {"FORE", YOAKE+1, SHOUGO}, + {"AFTER", SHOUGO+1, NICHIBOTU}, + {"EVNING", NICHIBOTU+1, YONAKA}, + {"MORNING", YONAKA+1, YOAKE}, + {"FREE", 0, 1024}, +}; + +extern void BATTLE_changeRideImage( int index ); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + +#define MAXNPCPOINT 10 + +BOOL ActionNpc_WarpPoint(int meindex,int talker,char *npcarg) +{ + char data[1024], buf1[256], buf2[256]; + int i=1, j=0; + BOOL EvFlg=FALSE; + + struct { + int FLOOR; + int X; + int Y; + }Points[MAXNPCPOINT]; + + for( i=0;i= MAXNPCPOINT ) + break; + } + where = RAND( 0, j-1); + if( MAP_IsValidCoordinate( Points[where].FLOOR, Points[where].X, Points[where].Y ) == TRUE ){ + CHAR_warpToSpecificPoint( meindex, Points[where].FLOOR, Points[where].X, Points[where].Y); + EvFlg = TRUE; + }else { + for( i=0; i<10; i++) { + print("%d.[%d,%d,%d]\n", i, Points[i].FLOOR, Points[i].X, Points[i].Y); + } + } + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARPPOINT", data, sizeof( data)) != NULL ) { + int where=0; + i=1; + j=0; + while( getStringFromIndexWithDelim( data, ";", i, buf1, sizeof( buf1)) != FALSE ) { + i++; + getStringFromIndexWithDelim( buf1, ",", 1, buf2, sizeof( buf2)); + Points[j].FLOOR = atoi( buf2); + getStringFromIndexWithDelim( buf1, ",", 2, buf2, sizeof( buf2)); + Points[j].X = atoi( buf2); + getStringFromIndexWithDelim( buf1, ",", 3, buf2, sizeof( buf2)); + Points[j].Y = atoi( buf2); + j++; + if( j >= MAXNPCPOINT ) + break; + } + where = RAND( 0, j-1); + if( MAP_IsValidCoordinate( Points[where].FLOOR, Points[where].X, Points[where].Y ) == TRUE ){ + CHAR_warpToSpecificPoint( talker, Points[where].FLOOR, Points[where].X, Points[where].Y); + EvFlg = TRUE; + }else { + for( i=0; i<10; i++) { + print("%d.[%d,%d,%d]\n", i, Points[i].FLOOR, Points[i].X, Points[i].Y); + } + } + + } +#if _ATTESTAION_ID == 35 + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARPIPPOINT", data, sizeof( data)) != NULL ) { + int fl,x,y, ipnum; + i=1; + j=0; + if( getStringFromIndexWithDelim( data, ";", i, buf1, sizeof( buf1)) != FALSE ) { + getStringFromIndexWithDelim( buf1, ",", 1, buf2, sizeof( buf2)); + fl = atoi( buf2); + getStringFromIndexWithDelim( buf1, ",", 2, buf2, sizeof( buf2)); + x = atoi( buf2); + getStringFromIndexWithDelim( buf1, ",", 3, buf2, sizeof( buf2)); + y = atoi( buf2); + getStringFromIndexWithDelim( buf1, ",", 4, buf2, sizeof( buf2)); + ipnum = atoi( buf2); + } + + int playernum = CHAR_getPlayerMaxNum(); + int num=0; + for(i=0;i=ipnum){ + CHAR_talkToCli( talker, -1, "IP", CHAR_COLORYELLOW); + return EvFlg; + } + } + } + } + + if( MAP_IsValidCoordinate( fl, x, y ) == TRUE ){ + CHAR_warpToSpecificPoint( talker, fl, x, y); + EvFlg = TRUE; + }else { + for( i=0; i<10; i++) { + print("%d.[%d,%d,%d]\n", ipnum, fl, x, y); + } + } + + } +#endif + return EvFlg; +} + +BOOL ActionNpc_CheckMenuFree( int meindex, int toindex, char *npcarg, int nums) +{ + char buf1[1024], buf2[256]; + if( nums < 1 ) return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CHECKPARTY", buf1, sizeof( buf1) ) != NULL){ + if( strstr( buf1, "TRUE") != 0 ) { + if( Action_PartyCheck( meindex, toindex) == FALSE) { + CHAR_talkToCli( toindex, meindex, "һһ", CHAR_COLORYELLOW); + return FALSE; + } + } + } + +#ifdef _NPC_TALK_CHECK + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "TALKCHECK", buf1, sizeof( buf1) ) != NULL){ + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)==0){ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK) != CHAR_getWorkInt(toindex, CHAR_WORK_TALKCHECK)){ + char buf[256]; + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + sprintf(buf, "֤:%d", CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)); + CHAR_talkToCli( toindex, meindex, buf, CHAR_COLORYELLOW); + return FALSE; + }else{ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + } +#endif + + + if( getStringFromIndexWithDelim( npcarg,"}", nums, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2) ) == NULL){ + strcpy(buf2, "LV>0"); + } + + + if( NPC_ActionPassCheck( meindex, toindex, buf2) == FALSE ) { + { + CHAR_talkToCli( toindex, meindex, "㣡", CHAR_COLORYELLOW); + return FALSE; + } + } + return Action_RunDoEventAction( meindex, toindex, buf1); +} + +BOOL ActionNpc_CheckFree( int meindex, int toindex, char *npcarg) +{ + char buf1[1024], buf2[256]; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CHECKPARTY", buf1, sizeof( buf1) ) != NULL){ + if( strstr( buf1, "TRUE") != 0 ) { + if( Action_PartyCheck( meindex, toindex) == FALSE) { + CHAR_talkToCli( toindex, meindex, "һһ", CHAR_COLORYELLOW); + return FALSE; + } + } + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2) ) == NULL){ + strcpy(buf2, "LV>0"); + } + + if( NPC_ActionPassCheck( meindex, toindex, buf2) == FALSE ) + { + CHAR_talkToCli( toindex, meindex, "㣡", CHAR_COLORYELLOW); + return FALSE; + } + return Action_RunDoEventAction( meindex, toindex, buf1); +} + +#ifdef _CHANNEL_MODIFY +extern int *piOccChannelMember; +#endif + +BOOL Action_RunDoEventAction( int meindex, int toindex, char *buf1) +{ + char buf2[1256]; + +#if 1 // Robin NPCִжǰһμFREE + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPassCheck( meindex, toindex, buf2 ) == FALSE && buf2[0] == '\n' ) { + print("\n ķ!?NPCFREE!!:%s:%d,%d,%d ", + CHAR_getChar(toindex, CHAR_CDKEY), + CHAR_getInt(toindex, CHAR_FLOOR), + CHAR_getInt(toindex, CHAR_X), + CHAR_getInt(toindex, CHAR_Y) ); + CHAR_warpToSpecificPoint(toindex,117,225,13); + return FALSE; + } + } +#endif + +#ifdef _NPC_INT_SET + if( NPC_Util_GetStrFromStrWithDelim( buf1, "INTSET", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionIntSet( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "INTCHANGE", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionIntChange( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "INTSHOW", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionIntShow( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + +#ifdef _PLAYER_DIY_MAP + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPSHOW", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMap( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPBUY", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapBuy( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPLETTER", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapLetter( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPSEND", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapSend( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPADDNUM", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapAddNum( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPADDEXP", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapAddExp( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PLAYERDIYMAPADDDAY", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionPlayerDiyMapAddDay( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + +#ifdef _LOTTERY_SYSTEM + if( NPC_Util_GetStrFromStrWithDelim( buf1, "LOTTERYCHANGE", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionLotteryChange( toindex, buf2 ) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "LOTTERYBUY", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionLotteryBuy( toindex, buf2 ) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "LOTTERYADDTIME", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionLotteryAddTime( toindex, buf2 ) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "LOTTERYSHOW", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionLotteryShow( toindex ) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "LOTTERYPLAYERSHOW", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionLotteryPlayerShow( toindex ) == FALSE ) + return FALSE; + } +#endif +#ifdef _SHOW_ITEM_NAME + if( NPC_Util_GetStrFromStrWithDelim( buf1, "SHOWITEMNAME", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionShowItemName( toindex, buf2 ) == FALSE ) + return FALSE; + } +#endif +#ifdef _SQL_BUY_FUNC + if( NPC_Util_GetStrFromStrWithDelim( buf1, "ONLINEBUY", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionOnlineBuy( toindex ) == FALSE ) + return FALSE; + } +#endif + +#ifdef _ONLINE_COST + if( NPC_Util_GetStrFromStrWithDelim( buf1, "ONLINECOST", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionOnlineCost( toindex ) == FALSE ) + return FALSE; + } +#endif + +#ifdef _DEL_FAME + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelFame", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionDelFame( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + if( NPC_Util_GetStrFromStrWithDelim( buf1, "AddGold", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionAddGold2( toindex, buf2) == FALSE ) + return FALSE; + } + +#ifdef _GLORY_POINT + if( NPC_Util_GetStrFromStrWithDelim( buf1, "AddGlory", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionAddGlory( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelGold", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionDelGold( toindex, buf2) == FALSE ) + return FALSE; + } +#ifdef _MOMENTUM_NPC + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelMom", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionMomentum( toindex, buf2) == FALSE ) + return FALSE; + } +#endif +#ifdef _DP_NPC + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelDP", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionDP( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelItem", buf2, sizeof( buf2)) != NULL ) { + //print("\n DelItem:%s:%d ", __FILE__, __LINE__); + if( NPC_ActionDelItem( toindex, buf2) == FALSE ) { + //print("\n ķ??NPC_ActionDelItem:%s:%s ", CHAR_getChar(toindex, CHAR_CDKEY), buf2); + //CHAR_warpToSpecificPoint(toindex,117,225,13); + return FALSE; + } + } + + //npcĵ + if( NPC_Util_GetStrFromStrWithDelim( buf1, "AddItem", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionAddItem( toindex, buf2) == FALSE ) + return FALSE; + } +#ifdef _VIP_SHOP + if( NPC_Util_GetStrFromStrWithDelim( buf1, "VipItem", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionVipItem( toindex, buf2) == FALSE ) + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "VipPet", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionVipPet( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + +#ifdef _NEW_VIP_SHOP + if( NPC_Util_GetStrFromStrWithDelim( buf1, "Vip_Item", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionNewVipItem( toindex, buf2) == FALSE ) + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "Vip_Pet", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionNewVipPet( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + +#ifdef _TRANS_7_NPC + if( NPC_Util_GetStrFromStrWithDelim( buf1, "TRANS7", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionTrans7( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DelPet", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionDelPet( toindex, buf2) == FALSE ) + return FALSE; + } + +#ifdef _NPC_NewDelPet + if( NPC_Util_GetStrFromStrWithDelim( buf1, "NewDelPet", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionNewDelPet( toindex, buf2) == FALSE ) + return FALSE; + } +#endif + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "AddPet", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionAddPet( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "EvEnd", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionSetEend( toindex, buf2) == FALSE ) + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "EvNow", buf2, sizeof( buf2)) != NULL ) { + if( NPC_ActionSetNow( toindex, buf2) == FALSE ) + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "Event_End", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionSetEend( toindex, buf2) == FALSE ) { + return FALSE; + } + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "Event_Now", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionSetNow( toindex, buf2) == FALSE ) + return FALSE; + } + + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "EvClr", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionClearEvent( toindex, buf2) == FALSE ) + return FALSE; + } + +#ifdef _NPCCHANGE_PLAYERIMG + if( NPC_Util_GetStrFromStrWithDelim( buf1, "CHANGEBBI", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionChangePlayerBBI( meindex, toindex, buf2) == FALSE ) + return FALSE; + } +#endif + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "SetLastTalkelder", buf2, sizeof( buf2) ) != NULL) { + CHAR_setInt( toindex, CHAR_LASTTALKELDER, atoi( buf2)); + } + +#ifdef _TYPE_TOXICATION + if( NPC_Util_GetStrFromStrWithDelim( buf1, "TOXICATION", buf2, sizeof( buf2) ) != NULL) { + int fd = getfdFromCharaIndex( toindex ); + if( strstr( buf2, "TRUE") != 0 ){ + setToxication( fd, 1); + CHAR_setWorkInt( toindex, CHAR_WORKTOXICATION, 0 ); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "TOXICATIONMSG", buf2, sizeof( buf2) ) != NULL) { + CHAR_talkToCli( toindex, -1, buf1, CHAR_COLORYELLOW); + } + }else { + CHAR_setWorkInt( toindex, CHAR_WORKTOXICATION, 0 ); + setToxication( fd, 0); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "DETOXIFYMSG", buf2, sizeof( buf2) ) != NULL) { + CHAR_talkToCli( toindex, -1, buf2, CHAR_COLORYELLOW); + } + } + } +#endif + + if(NPC_Util_GetStrFromStrWithDelim( buf1, "GetRandItem", buf2, sizeof( buf2) ) != NULL ){ + int j=1, rand_cnt=1; + char buf3[256]; + while( getStringFromIndexWithDelim( buf2 , "," , j, buf3, sizeof( buf3)) != FALSE ){ + j++; + rand_cnt++; + } + NPC_ActionTreasureRandItemGet( meindex, toindex, rand_cnt, buf2); + } + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + //andy_add 2003/07/17 + if( NPC_Util_GetStrFromStrWithDelim( buf1, "AddPFSkillPoint", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionAddProfessionSkillPoint( toindex, buf2 ) == FALSE ){ + return FALSE; + } + } + //andy_add 2003/07/17 + if( NPC_Util_GetStrFromStrWithDelim( buf1, "CleanProfession", buf2, sizeof( buf2) ) != NULL) { + if( NPC_ActionCleanProfession( toindex, buf2 ) == FALSE ){ + sprintf( buf2, "ְҵʧ!!" ); + CHAR_talkToCli( toindex, -1, buf2, CHAR_COLORYELLOW); + return FALSE; + } + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "PROFESSION", buf2, sizeof( buf2) ) != NULL) { + int p_class = atoi(buf2); + // жְҵ + if( CHAR_getInt( toindex, PROFESSION_CLASS ) != PROFESSION_CLASS_NONE && (p_class != 0) ){ + sprintf( buf2, "Ѿְҵ!!" ); + CHAR_talkToCli( toindex, -1, buf2, CHAR_COLORYELLOW); + return FALSE; + } + + if( CHAR_getInt( toindex, CHAR_SKILLUPPOINT ) >0 ){ + sprintf( buf2, "뽫!!" ); + CHAR_talkToCli( toindex, -1, buf2, CHAR_COLORYELLOW); + return FALSE; + } + + if( p_class > PROFESSION_CLASS_NONE && p_class < PROFESSION_CLASS_NUM ) // 1:սʿ 2:ʦ 3: + { + int i, value = 0; + int skill_id = -1; + + // ԭ + if( PROFESSION_RESTORE_POINT( toindex ) != 1 ) return FALSE; + + // 趨ְҵ + CHAR_setInt( toindex, PROFESSION_CLASS, p_class ); +#ifdef _CHANNEL_MODIFY + if(CHAR_getInt(toindex,PROFESSION_CLASS) > 0){ + int i,pclass = CHAR_getInt(toindex,PROFESSION_CLASS) - 1; + for(i=0;i 0){ + int i,pclass = CHAR_getInt(toindex,PROFESSION_CLASS) - 1; + for(i=0;i") != NULL ){ + strcat( Head, ">"); + flg = 1; + }else if( strstr( buf2, "<") != NULL ){ + strcat( Head, "<"); + flg = 2; + }else if( strstr( buf2, "!") != NULL ) { + strcat( Head, "!"); + flg = 5; + } + }else if(strstr( buf2, "<") != NULL){ + strcpy( Head, "<"); + flg = 4; + }else if(strstr( buf2, ">") != NULL){ + strcpy( Head, ">"); + flg = 3; + } + Head[ strlen( Head)+1] = 0; + if( NPC_Util_GetStrFromStrWithDelim( buf2, Head, buf3, sizeof( buf3) ) != NULL) { + if( flg == 0 ){ + if( atoi(buf3) != partys ) { + return FALSE; + } + }else if( flg == 1 ){ + if( atoi(buf3) < partys ) { + return FALSE; + } + }else if( flg == 2 ){ + if( atoi(buf3) > partys ) + return FALSE; + }else if( flg == 3 ){ + if( atoi(buf3) <= partys ){ + return FALSE; + } + }else if( flg == 4 ){ + if( atoi(buf3) >= partys ) { + return FALSE; + } + }else if( flg == 5 ){ + if( atoi(buf3) == partys ) { + return FALSE; + } + } + } + return TRUE; + } +#endif + + ActionNpc_WarpPoint( meindex, toindex, buf1); + return TRUE; +} +BOOL Action_PartyCheck( int meindex, int talker) +{ + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + return FALSE; + } + return TRUE; +} + +BOOL NPC_ActionAddGold( int talker, int Golds) +{ + CHAR_AddGold( talker, Golds); + return TRUE; +} + +#ifdef _NPC_INT_SET +BOOL NPC_ActionIntSet( int talker,char *buf) +{ + char key[128]; + char value[64]; + getStringFromIndexWithDelim(buf,",",1,key,sizeof(key)); + int i; + for(i=0;i0){ + int myboundtime = CHAR_getInt(talker, CHAR_BOUNDTIME); + if(myboundtime > 0 && myboundtime > time(NULL)){ + return TRUE; + } + } + return FALSE; +} +#endif + +#ifdef _PLAYER_DIY_MAP +extern Player_Diy_Map PlayerDiyMap[Player_Diy_Map_NUM]; +BOOL NPC_ActionDiyMapCheck(int meindex,int talker,int diymap,int flg) +{ + int i; + for(i=0;iPlayer_Diy_Map_NUM)page=Player_Diy_Map_NUM; + strcpy(token," ͼšЧʱ䡱ռݡˡ\n"); + for(i=0;i0){ + char tmp[128]; + if(PlayerDiyMap[i].datetime==-1){ + sprintf(tmp, "%-10dЧ%16s\n", PlayerDiyMap[i].ff, PlayerDiyMap[i].cdkey); + }else{ + if(PlayerDiyMap[i].datetime>time(NULL)){ + struct tm tm1; + memcpy(&tm1, localtime((time_t *)&PlayerDiyMap[i].datetime), sizeof(tm1)); + sprintf(tmp, "%-10d %02d-%02d-%02d %16s\n", PlayerDiyMap[i].ff, tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, PlayerDiyMap[i].cdkey); + }else{ + sprintf(tmp, "%-10dѾʧЧ%16s\n", PlayerDiyMap[i].ff, PlayerDiyMap[i].cdkey); + } + } + strcat(token, tmp); + } + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, + -1, + -1, + token); + return TRUE; +} +BOOL NPC_ActionPlayerDiyMapBuy( int talker, char *buf) +{ + int ff=0; + int day=0; + int playernum=0; + int point=0; + int fame=0; + char token[256]; + if(getStringFromIndexWithDelim(buf,",",1,token,sizeof(token))==TRUE){ + ff=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",2,token,sizeof(token))==TRUE){ + day=max(0,atoi(token)); + } + if(getStringFromIndexWithDelim(buf,",",3,token,sizeof(token))==TRUE){ + playernum=max(0,atoi(token)); + } + if(getStringFromIndexWithDelim(buf,",",4,token,sizeof(token))==TRUE){ + point=max(0,atoi(token)); + } + if(getStringFromIndexWithDelim(buf,",",5,token,sizeof(token))==TRUE){ + fame=max(0,atoi(token)*100); + } + if(CHAR_getInt(talker, CHAR_AMPOINT)>=point && CHAR_getInt(talker, CHAR_FAME)>=fame){ + int i; + int find=FALSE; + for(i=0;i0){ + CHAR_setInt(talker, CHAR_AMPOINT, CHAR_getInt(talker, CHAR_AMPOINT)-point); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -point, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(DIYͼ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + sprintf(buf1, "۳ֵ %d", point); + CHAR_talkToCli( talker, -1, buf1, CHAR_COLORYELLOW); + } + if(fame>0){ + CHAR_setInt(talker, CHAR_FAME, CHAR_getInt(talker, CHAR_FAME)-fame); + sprintf(buf1, "۳ %d", fame); + CHAR_talkToCli( talker, -1, buf1, CHAR_COLORYELLOW); + int fd = getfdFromCharaIndex(talker); + sprintf(buf,"%d",CHAR_getInt(talker, CHAR_FAME)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(talker,CHAR_FMNAME),CHAR_getInt(talker,CHAR_FMINDEX),CHAR_getWorkInt(talker,CHAR_WORKFMINDEXI), + FM_FIX_FMFEED,buf,"",CHAR_getWorkInt(talker,CHAR_WORKFMCHARINDEX),CONNECT_getFdid(fd)); + } + + PlayerDiyMap[i].datetime = time(NULL) + day * 24 * 60 * 60; + PlayerDiyMap[i].playernum = playernum; + strcpy( PlayerDiyMap[i].cdkey, CHAR_getChar(talker, CHAR_CDKEY)); + + sprintf(buf1, "ϲ㣬õͼ %d DIYȨ %d 죬֧ %d ", point, day, playernum); + CHAR_talkToCli( talker, -1, buf1, CHAR_COLORGREEN); + + char filename[128]; + char map[Player_Diy_Map_SIZE]; + memcpy( &map , &PlayerDiyMap[i], sizeof(PlayerDiyMap[i])); + sprintf( filename, "playermap/%d", ff); + FILE *fp = fopen(filename, "wb"); + + fwrite(map, sizeof(map), 1,fp); + fclose(fp); + }else if(find==FALSE){ + CHAR_talkToCli( talker, -1, "ܱǸѾﵽDIYͼʹȨޣɹ~", CHAR_COLORRED); + } + }else{ + CHAR_talkToCli( talker, -1, "ܱǸ޷DIYͼʹȨ~", CHAR_COLORRED); + } + return TRUE; +} + +BOOL NPC_ActionPlayerDiyMapLetter( int talker, char *buf) +{ + int itemID=0, itemindex=-1; + char token[256]; + int ff=0; + if(getStringFromIndexWithDelim(buf,",",1,token,sizeof(token))==TRUE){ + ff=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",2,token,sizeof(token))==TRUE){ + itemID=atoi(token); + } + int i; + for(i=0;i= CheckCharMaxItem(talker) ){ + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return FALSE; + } + + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( talker, ret); + + return TRUE; +} + +BOOL NPC_ActionPlayerDiyMapSend( int talker, char *buf) +{ + char token[256]; + int ff=0, x=0, y=0, i=0; + + if( !CHAR_CHECKINDEX( talker) ) return FALSE; + + if( getStringFromIndexWithDelim( buf, ",", 1, token, sizeof(token)) == TRUE ){ + ff = atoi( token); + } + if( getStringFromIndexWithDelim( buf, ",", 2, token, sizeof(token)) == TRUE ){ + x = atoi( token); + } + if( getStringFromIndexWithDelim( buf, ",", 3, token, sizeof(token)) == TRUE ){ + y = atoi( token); + } + for(i=0;iPlayerDiyMap[i].playernum)break; + } + } + if(k=point){ + CHAR_setInt(talker, CHAR_AMPOINT, CHAR_getInt(talker, CHAR_AMPOINT)-point); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -point, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(DIYͼ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + sprintf(token, "۳ֵ %d", point); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + PlayerDiyMap[i].playernum += playernum; + sprintf( token,"ϲ㣬DIYͼ֧ %d ~", PlayerDiyMap[i].playernum); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + + char filename[128]; + char map[Player_Diy_Map_SIZE]; + memcpy( &map , &PlayerDiyMap[i], sizeof(PlayerDiyMap[i])); + sprintf( filename, "playermap/%d", ff); + FILE *fp = fopen(filename, "wb"); + + fwrite(map, sizeof(map), 1,fp); + fclose(fp); + + }else{ + CHAR_talkToCli( talker, -1, "ܱǸĻֵ㣬޷~", CHAR_COLORRED); + return FALSE; + } + + return TRUE; + } + } + } + + if(i==Player_Diy_Map_NUM){ + CHAR_talkToCli( talker, -1, "ܱǸõͼ~", CHAR_COLORRED); + } + return FALSE; +} +BOOL NPC_ActionPlayerDiyMapAddExp( int talker, char *buf) +{ + int point=0; + int exp=0; + char token[256]; + int ff=0; + if(getStringFromIndexWithDelim(buf,",",1,token,sizeof(token))==TRUE){ + ff=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",2,token,sizeof(token))==TRUE){ + exp=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",3,token,sizeof(token))==TRUE){ + point=atoi(token); + } + int i; + for(i=0;i=point){ + CHAR_setInt(talker, CHAR_AMPOINT, CHAR_getInt(talker, CHAR_AMPOINT)-point); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -point, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(DIYͼ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + sprintf(token, "۳ֵ %d", point); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + PlayerDiyMap[i].exp += exp; + sprintf( token,"ϲ㣬DIYͼȡ %d ~", PlayerDiyMap[i].exp); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + + char filename[128]; + char map[Player_Diy_Map_SIZE]; + memcpy( &map , &PlayerDiyMap[i], sizeof(PlayerDiyMap[i])); + sprintf( filename, "playermap/%d", ff); + FILE *fp = fopen(filename, "wb"); + + fwrite(map, sizeof(map), 1,fp); + fclose(fp); + }else{ + CHAR_talkToCli( talker, -1, "ܱǸĻֵ㣬޷ͼȡ~", CHAR_COLORRED); + return FALSE; + } + + return TRUE; + } + } + } + + if(i==Player_Diy_Map_NUM){ + CHAR_talkToCli( talker, -1, "ܱǸõͼ~", CHAR_COLORRED); + } + return FALSE; +} +BOOL NPC_ActionPlayerDiyMapAddDay( int talker, char *buf) +{ + char token[256]; + int ff=0,day=0,point=0; + if(getStringFromIndexWithDelim(buf,",",1,token,sizeof(token))==TRUE){ + ff=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",2,token,sizeof(token))==TRUE){ + day=atoi(token); + } + if(getStringFromIndexWithDelim(buf,",",3,token,sizeof(token))==TRUE){ + point=atoi(token); + } + int i; + for(i=0;i=point){ + CHAR_setInt(talker, CHAR_AMPOINT, CHAR_getInt(talker, CHAR_AMPOINT)-point); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -point, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(DIYͼ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + sprintf(token, "۳ֵ %d", point); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + PlayerDiyMap[i].datetime += day * 24 * 60 * 60; + sprintf( token,"ϲ㣬DIYͼʹȨ %d ~", day); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + + char filename[128]; + char map[Player_Diy_Map_SIZE]; + memcpy( &map , &PlayerDiyMap[i], sizeof(PlayerDiyMap[i])); + sprintf( filename, "playermap/%d", ff); + FILE *fp = fopen(filename, "wb"); + + fwrite(map, sizeof(map), 1,fp); + fclose(fp); + }else{ + CHAR_talkToCli( talker, -1, "ܱǸĻֵ㣬޷ͼʹȨ~", CHAR_COLORRED); + return FALSE; + } + + return TRUE; + } + } + } + + if(i==Player_Diy_Map_NUM){ + CHAR_talkToCli( talker, -1, "ܱǸõͼ~", CHAR_COLORRED); + } + return FALSE; +} +#endif + +#ifdef _LOTTERY_SYSTEM +int todayaward[7]={-1}; +BOOL NPC_ActionLotteryChange( int talker, char *buf) +{ + int fd = getfdFromCharaIndex( talker); + if( fd == - 1 ) return FALSE; + int award[7]; + char token[256]; + + struct tm now; + time_t timep; + time(&timep); + memcpy(&now, localtime(&timep), sizeof(now)); + struct tm tm1; + int lotterydate = CHAR_getInt(talker, CHAR_LOTTERY_DATE); + int lotterytime = CHAR_getInt(talker, CHAR_LOTTERY_TIME); + memcpy(&tm1, localtime((time_t *)&lotterydate), sizeof(tm1)); + + if(now.tm_year==tm1.tm_year && now.tm_mon==tm1.tm_mon && now.tm_mday==(tm1.tm_mday + 1)){ + int i,j; + int value[7]; + int num=0; + char *lotteryvalue=CHAR_getChar(talker, CHAR_LOTTERY_VALUE); + + for(i=0;i<7;i++){ + if(getStringFromIndexWithDelim(lotteryvalue,",",i+1,token,sizeof(token))==TRUE){ + value[i]=atoi(token); + int k; + for(j=0;j<7;j++){ + if(todayaward[j]==value[i]){ + for(k=0;k0){ + for(i=0;i<7;i++){ + if(getStringFromIndexWithDelim(buf,",",i+1,token,sizeof(token))==TRUE){ + award[i]=atoi(token); + }else{ + award[i]=0; + } + } + sprintf(token, "ϲе %sȽ ,Ϊ %d ", tmp[7-num], award[7-num]); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, -1, -1, token); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, -1, -1, token); + CHAR_setInt(talker, CHAR_AMPOINT, CHAR_getInt(talker, CHAR_AMPOINT) + award[7-num]*lotterytime); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + award[7-num], + CHAR_getInt( talker, CHAR_AMPOINT ), + "(Ʊн)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + CHAR_setInt(talker, CHAR_LOTTERY_DATE, 0); + CHAR_setInt(talker, CHAR_LOTTERY_TIME, 0); + CHAR_setChar(talker, CHAR_LOTTERY_VALUE, ""); + + int playernum = CHAR_getPlayerMaxNum(); + sprintf(token, "ϲ %s е %sȽ ,Ϊ %d ", CHAR_getChar(talker, CHAR_NAME), tmp[7-num], award[7-num]); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, -1, token, CHAR_COLORBLUE); + } + } + + FILE * f1 = fopen("todayaward.txt","a+"); + sprintf(token, "˺ %s %s е %sȽ, Ϊ %d %d = %d \n", CHAR_getChar(talker, CHAR_CDKEY), + CHAR_getChar(talker, CHAR_NAME), + tmp[7-num], + award[7-num], + lotterytime, + award[7-num] * lotterytime); + fputs(token,f1); + fclose(f1); + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, -1, -1, "ܱǸûн"); + } + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OKCANCEL, -1, -1, "ܱǸ㻹δڿIJƱ"); + } + + return TRUE; +} + +BOOL NPC_ActionLotteryBuy( int talker, char *buf) +{ + int fd = getfdFromCharaIndex( talker); + if( fd == - 1 ) return FALSE; + if(CHAR_getInt(talker, CHAR_AMPOINT) MaxGold ) total_gold = MaxGold; + + CHAR_setInt( talker, CHAR_GOLD, total_gold ); + CHAR_send_P_StatusString( talker , CHAR_P_STRING_GOLD); + return TRUE; +} + +BOOL NPC_ActionDelPet( int talker, char *buf) +{ + int petsel; + int petindex=0, k=1; + int fd = getfdFromCharaIndex( talker ); + char msgbuf[64], szPet[128],buff2[256],buff3[256]; + char buf2[256],buff1[256]; + int defpet, ridepet; + int petno,kNum,find=0,petLv=0,flg=-1; + + while( getStringFromIndexWithDelim(buf , "," , k, buff1, sizeof( buff1)) !=FALSE ) { + k++; + if( strstr( buff1,"-") != NULL ) { + getStringFromIndexWithDelim(buff1,"-",2,buff3,sizeof(buff3)); + getStringFromIndexWithDelim(buff1,"-",1,buf2,sizeof(buf2)); + + if( strstr( buf2,"!") != NULL ) { + flg = 0; + getStringFromIndexWithDelim(buf2,"!=",2,buff2,sizeof(buff2)); + }else if( strstr( buf,"<") != NULL ) { + flg = 1; + getStringFromIndexWithDelim(buf2,"<",2,buff2,sizeof(buff2)); + }else if( strstr( buf,">") != NULL ) { + flg = 2; + getStringFromIndexWithDelim(buf2,">",2,buff2,sizeof(buff2)); + }else if( strstr( buf,"=") != NULL) { + flg = 3; + getStringFromIndexWithDelim(buf2,"=",2,buff2,sizeof(buff2)); + }else + return FALSE; + petLv = atoi( buff2); + } + continue; + + if(strstr(buff3,"*")!=NULL){ + getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); + petno = atoi(buf2); + getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); + kNum = atoi(buf2); + }else { + petno = atoi( buff3); + kNum = 30; + } + //andy_log + print("petno:%d kNum:%d \n ", petno, kNum); + + find =0; + + for(petsel=0 ; petsel < CHAR_MAXPETHAVE ; petsel++) { + petindex = CHAR_getCharPet( talker, petsel); + if( !CHAR_CHECKINDEX(petindex)) continue; + if(CHAR_getInt( petindex, CHAR_PETID) != petno )continue; + + switch( flg) { + case 0: + if( CHAR_getInt( petindex, CHAR_LV ) != petLv ) { + }else { + continue; + } + break; + case 1: + if( CHAR_getInt( petindex, CHAR_LV ) < petLv ) { + }else { + continue; + } + break; + case 2: + if( CHAR_getInt( petindex, CHAR_LV ) > petLv ) { + }else { + continue; + } + break; + case 3: + if( CHAR_getInt( petindex, CHAR_LV ) != petLv )continue; + break; + } + + petindex = CHAR_getCharPet( talker, petsel); + if( !CHAR_CHECKINDEX(petindex) ) + continue; + if( CHAR_getWorkInt( CONNECT_getCharaindex( fd), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) + continue; + defpet = CHAR_getInt( talker, CHAR_DEFAULTPET); + + if(defpet == petsel) { + CHAR_setInt( talker, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + + ridepet = CHAR_getInt( talker, CHAR_RIDEPET); + + if(ridepet == petsel) { + CHAR_setInt( talker , CHAR_RIDEPET, -1 ); + CHAR_setInt( talker , CHAR_BASEIMAGENUMBER , CHAR_getInt( talker , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_complianceParameter( talker ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( talker, CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( talker , CHAR_P_STRING_RIDEPET); + } + + snprintf( msgbuf,sizeof( msgbuf), "%s", CHAR_getChar( petindex, CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + LogPet( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "TenseiDel", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + CHAR_setCharPet( talker, petsel, -1); + CHAR_endCharOneArray( petindex ); + snprintf( szPet, sizeof( szPet ), "K%d", petsel); + CHAR_sendStatusString( talker, szPet ); + + find++; + if( find >= kNum ) + break; //Ŀɾ + } + } + return TRUE; +} + +#ifdef _NPC_NewDelPet +BOOL NPC_ActionNewDelPet( int toindex, char *msg) +{ + int i,petindex=0,petlev,petnum,petcount,mypetlevel,petid; + char buf[32],buf2[32]; + int flg=0,count=0; + + //ȽϷʽ + if ( strstr( msg, "=" ) ) + flg = 0; + else if( strstr( msg, "<" ) ) + flg = 1; + else + flg = 2; + + //ȼ + if ( getStringFromIndexWithDelim( msg, "-", 1, buf, sizeof( buf )) ){ + char cmp[12]; + if( flg == 0 ) + strcpy(cmp,"="); + else if( flg == 1 ) + strcpy(cmp,"<"); + else + strcpy(cmp,">"); + if ( getStringFromIndexWithDelim( buf, cmp, 2, buf2, sizeof( buf2 )) ){ + petlev = atoi(buf2); + } + else + return FALSE; + } + else + return FALSE; + + // + if ( getStringFromIndexWithDelim( msg, "-", 2, buf, sizeof( buf )) ){ + if ( getStringFromIndexWithDelim( buf, "*", 1, buf2, sizeof( buf2 )) ){ + petnum = atoi( buf2 ); + } + else + return FALSE; + } + else + return FALSE; + + // + if ( getStringFromIndexWithDelim( msg, "-", 2, buf, sizeof( buf )) ){ + if ( getStringFromIndexWithDelim( buf, "*", 2, buf2, sizeof( buf2 )) ){ + petcount = atoi( buf2 ); + } + else + return FALSE; + } + else + return FALSE; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + BOOL cmp=FALSE; + petindex = CHAR_getCharPet( toindex, i); + petid = CHAR_getInt( petindex, CHAR_PETID); + mypetlevel = CHAR_getInt( petindex, CHAR_LV); + + if( flg == 0 ) + if( mypetlevel == petlev ) cmp = TRUE; + if( flg == 1 ) + if( mypetlevel < petlev ) cmp = TRUE; + if( flg == 2 ) + if( mypetlevel > petlev ) cmp = TRUE; + + if( petnum == petid && cmp ){//ɾ + char szPet[128]; + int defpet; + char msgbuf[64]; + int fd = getfdFromCharaIndex( toindex ); + + if( !CHAR_CHECKINDEX(petindex) ) return FALSE; + + if( CHAR_getInt( toindex, CHAR_RIDEPET) == i ) { + + //CHAR_talkToCli( talker, -1, "еij޷", CHAR_COLORYELLOW ); + //return FALSE; + + CHAR_setInt( toindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( toindex, CHAR_P_STRING_RIDEPET ); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + } + + //ƽҷ» ئգʸëڱ + if( CHAR_getWorkInt( CONNECT_getCharaindex( fd ), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return FALSE; + //ʸᆴ + defpet = CHAR_getInt( toindex, CHAR_DEFAULTPET); + if(defpet == i){ + CHAR_setInt( toindex, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + + snprintf( msgbuf,sizeof( msgbuf), "%s", + CHAR_getChar( petindex, CHAR_NAME)); + CHAR_talkToCli( toindex, -1, msgbuf, CHAR_COLORWHITE); + + // ʸë ׷ + LogPet( CHAR_getChar( toindex, CHAR_NAME ), // ƽҷ + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "EvnetDell(ɾ)", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + + // + CHAR_setCharPet( toindex, i, -1); + + CHAR_endCharOneArray( petindex ); + + snprintf( szPet, sizeof( szPet ), "K%d", i); + // ޥʸ ˪Ի + CHAR_sendStatusString( toindex, szPet ); + + ++count; + if( count >= petcount ) + break; + } + } + + return TRUE; +} +#endif + +BOOL NPC_ActionAddPet( int talker, char *buf) +{ + int ret; + char msgbuf[64], buff3[64]; + int enemynum; + int i,j,k=1; + int petindex, petindex2, petid; + + k=1; + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + //Ƿпλ + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ){ + snprintf( msgbuf,sizeof( msgbuf), ""); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + return FALSE; + } +#ifdef _PET_MM + if(strstr(buff3,"MM1") || strstr(buff3,"MM3")) + petid = 1479; + else if(strstr(buff3,"MM2") || strstr(buff3,"MM4")) + petid = 2547; + else + petid = atoi( buff3); +#else + petid = atoi( buff3); +#endif + + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + if(strstr(buf1,"PETABI")){ + easyGetTokenFromString( buf , 2 , buf1, sizeof(buf1)); + petid = atoi(buf1); + } + } +#endif + + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID ) == petid ) + //if( ENEMY_getInt( i, ENEMY_TEMPNO ) == petid ) + break; + } + + if( i == enemynum ) + continue; + + ret = ENEMY_createPetFromEnemyIndex( talker, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( talker, i ) == ret ) + break; + } + if( i == CHAR_MAXPETHAVE ) + i = 0; + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ +#ifdef _PET_MM + if(strstr(buff3,"MM1") || strstr(buff3,"MM2")){ + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + }else if(strstr(buff3,"MM3") || strstr(buff3,"MM4")){ + while(CHAR_getInt( ret, CHAR_LV)<79){ // + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + } +#endif + + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + if(strstr(buf,"PETABI")){ + int lv, trans, vital, str, tough, dex; + easyGetTokenFromString( buf , 3 , buf1, sizeof(buf1)); + lv=atoi(buf1); + easyGetTokenFromString( buf , 4 , buf1, sizeof(buf1)); + trans=atoi(buf1); + easyGetTokenFromString( buf , 5 , buf1, sizeof(buf1)); + vital=atoi(buf1); + easyGetTokenFromString( buf , 6 , buf1, sizeof(buf1)); + str=atoi(buf1); + easyGetTokenFromString( buf , 7 , buf1, sizeof(buf1)); + tough=atoi(buf1); + easyGetTokenFromString( buf , 8 , buf1, sizeof(buf1)); + dex=atoi(buf1); + + CHAR_setInt( ret, CHAR_LV, lv); + CHAR_setInt( ret, CHAR_TRANSMIGRATION, trans); + CHAR_setInt( ret, CHAR_VITAL, vital*20); + CHAR_setInt( ret, CHAR_STR, str*80); + CHAR_setInt( ret, CHAR_TOUGH, tough*80); + CHAR_setInt( ret, CHAR_DEX, dex*100); + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + + } + } +#endif + + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + + petindex2 = CHAR_getCharPet(talker, i); + if( !CHAR_CHECKINDEX( petindex2) ) + continue; + snprintf( msgbuf,sizeof( msgbuf), "õ%s", CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(talker, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + } + + LogPet( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex2, CHAR_NAME), + CHAR_getInt( petindex2, CHAR_LV), + "TenseiGet", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex2, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + } + + return TRUE; +} + +#ifdef _ITEM_PILENUMS +BOOL NPC_DelItem( int toindex, int ti, int num) +{ + int itemindex, pilenum; + + itemindex = CHAR_getItemIndex( toindex , ti); + if( !ITEM_CHECKINDEX(itemindex) ) return FALSE; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + if( pilenum < num ) return FALSE; + + pilenum = pilenum - num; + if( pilenum <= 0 ){ + { + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), +#ifdef _add_item_log_name + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "Sell()", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + CHAR_setItemIndex( toindex, ti, -1); + ITEM_endExistItemsOne( itemindex); + }else{ + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + } + CHAR_sendItemDataOne( toindex, ti); + return TRUE; +} + + +void NPC_ActionDoPileClearItem( int toindex, int itemID) +{ + int i, itemindex; + char token[256]; + + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(toindex) ; i++ ){ + itemindex = CHAR_getItemIndex( toindex , i ); + if( !ITEM_CHECKINDEX(itemindex) ) continue; + if( ITEM_getInt(itemindex, ITEM_ID) != itemID ) continue; + sprintf( token, "%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "ȡ", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + CHAR_setItemIndex( toindex, i, -1); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( toindex, i); + } +} + +BOOL NPC_ActionDoPileDelItem( int toindex, int itemID, int num) +{ + int i, itemindex, finditem=0, pilenum=0, onenum=0; + char token[256]; + + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(toindex) && (finditem= (num-finditem) ){ + pilenum -= (num-finditem); + onenum += (num-finditem); + }else { + onenum = pilenum; + pilenum=0; + } + finditem += onenum; + + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + sprintf( token, "%d%s", onenum, ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + if( pilenum <= 0 ){ + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "ȡ", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + + + CHAR_setItemIndex( toindex, i, -1); + ITEM_endExistItemsOne( itemindex); + } + CHAR_sendItemDataOne( toindex, i); + } + + if( finditem != num && num != -1 ) return FALSE; + return TRUE; +} + +BOOL NPC_ActionDelItem( int talker, char *buf) +{ + char buff3[128], buf2[32]; + int k=1, itemid, neednum; + if( !CHAR_CHECKINDEX( talker) ) return FALSE; + while( getStringFromIndexWithDelim(buf , "," , k++, buff3, sizeof(buff3)) !=FALSE ) { + neednum = 1; + if( getStringFromIndexWithDelim( buff3, "*", 1, buf2, sizeof(buf2)) == FALSE ) continue; + itemid = atoi( buf2); + if( getStringFromIndexWithDelim( buff3, "*", 2, buf2, sizeof(buf2)) == TRUE ){ + neednum = atoi( buf2); + if( NPC_ActionDoPileDelItem( talker, itemid, neednum) == FALSE ) return FALSE; + }else{ + NPC_ActionDoPileClearItem( talker, itemid); + } + } + return TRUE; +} +#else +BOOL NPC_ActionDelItem( int talker, char *buf) +{ + int i = 1, j = 1,k = 1; + char buff3[128]; + char buf2[32]; + int itemindex; + char token[256]; + + if( !CHAR_CHECKINDEX( talker) ) return FALSE; + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ) { + k++; + if(strstr(buff3,"*")!=NULL){ + int itemno, kosuu=0, id, cnt=0; + struct _tagItemArray { + int index; + int itemindex; + }; + struct _tagItemArray ItemArray[20]; + for( i=0; i<20 ; i++){ + ItemArray[i].itemindex = -1; + ItemArray[i].index = -1; + } + //ȡִ + getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); + itemno = atoi(buf2); + getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); + kosuu = atoi(buf2); + //ȡ item index + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id=ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno==id){ + ItemArray[cnt].itemindex = itemindex; + ItemArray[cnt].index = i; + cnt++; + } + } + if(cnt == kosuu) + break; + } + if(cnt != kosuu){ + CHAR_talkToCli( talker, -1,"", CHAR_COLORYELLOW); + return FALSE; + } + //ȡƷ + for( i=0; i<20; i++) { + itemindex = ItemArray[i].itemindex; + if( !ITEM_CHECKINDEX(itemindex) ) break; + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + CHAR_setItemIndex( talker, ItemArray[i].index ,-1); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( talker, ItemArray[i].index); + LogItem( + CHAR_getChar( talker, CHAR_NAME ), CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "WarpManDelItem", + CHAR_getInt( talker, CHAR_FLOOR), CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + }else{ + for( j = CHAR_STARTITEMARRAY ; j < CheckCharMaxItem(talker) ; j++){ + itemindex = CHAR_getItemIndex( talker ,j); + if( ITEM_CHECKINDEX(itemindex) ){ + if( atoi( buff3) == ITEM_getInt(itemindex,ITEM_ID)){ + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "WarpManDelItem", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + sprintf( token, "%s", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + CHAR_DelItem( talker, j); + } + } + } + } + } + return TRUE; +} +#endif + +#ifdef _VIP_SHOP +BOOL NPC_ActionVipItem( int talker, char *buf) +{ + int itemindex=-1; + int pVipPoint=0, VipPoints=0; + char buff[256], token[256]; + int ret; + int itemID=0; + if(getStringFromIndexWithDelim(buf , "," , 1, buff, sizeof(buff)) !=FALSE) + itemID = atoi(buf); + + itemindex = CHAR_findEmptyItemBox( talker ); + if( itemindex < 0 ) { + CHAR_talkToCli( talker, -1, "Ʒռ䲻㣡", CHAR_COLORYELLOW); + return FALSE; + } + + if(getStringFromIndexWithDelim(buf , "," , 2, buff, sizeof(buff)) !=FALSE) + VipPoints=atoi(buff); + if(VipPoints<0)VipPoints=0; + + pVipPoint = CHAR_getInt( talker, CHAR_AMPOINT); + if( pVipPoint < VipPoints ) { + CHAR_talkToCli( talker, -1, "ϵĻֵŶ", CHAR_COLORYELLOW); + return FALSE; + } + + itemindex = ITEM_makeItemAndRegist( itemID ); + if( itemindex != -1 ){ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return FALSE; + } + + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + + CHAR_setInt( talker, CHAR_AMPOINT, pVipPoint-VipPoints); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -VipPoints, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(ֹ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + sprintf( token, "۳ֵ%d", VipPoints); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + + CHAR_sendItemDataOne( talker, ret); + } + + return TRUE; +} + +BOOL NPC_ActionVipPet( int talker, char *buf) +{ + int ret; + char msgbuf[64], buf1[8], buf2[10]; + int enemynum; + int i,j; + int petindex, petindex2, petid; + int pVipPoint=0, VipPoints=0; + + if(getStringFromIndexWithDelim(buf , "," , 1, buf1, sizeof(buf1)) ==FALSE)return FALSE; +#ifdef _PET_MM + if(strstr(buf1,"MM1") || strstr(buf1,"MM3")){ + petid = 1479; + }else if(strstr(buf1,"MM2") || strstr(buf1,"MM4")){ + petid = 2547; + }else{ + petid = atoi( buf1 ); + } +#else + petid = atoi( buf1 ); +#endif + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + //ǷPETABIֶ + if(strstr(buf1,"PETABI")){ + easyGetTokenFromString( buf , 2 , buf1, sizeof(buf1)); + petid = atoi(buf1); + } + } +#endif + + if(getStringFromIndexWithDelim(buf , "," , 2, buf2, sizeof(buf2)) !=FALSE) + VipPoints=atoi(buf2); + if(VipPoints<0)VipPoints=0; + + pVipPoint = CHAR_getInt( talker, CHAR_AMPOINT); + if( pVipPoint < VipPoints ) { + CHAR_talkToCli( talker, -1, "ϵĻֵŶ", CHAR_COLORYELLOW); + return FALSE; + } + + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ) { + snprintf( msgbuf,sizeof( msgbuf), ""); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + return FALSE; + } + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == petid) { + break; + } + } + + if( i == enemynum ) + return FALSE; + + ret = ENEMY_createPetFromEnemyIndex( talker, i); + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + if( CHAR_getCharPet( talker, i ) == ret ) + break; + } + if( i == CHAR_MAXPETHAVE ) + CHAR_talkToCli( talker, -1, "ȡʧܣ", CHAR_COLORYELLOW); + + if( CHAR_CHECKINDEX( ret ) == TRUE ){ +#ifdef _PET_MM + if(strstr(buf1,"MM1") || strstr(buf1,"MM2")){ + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + }else if(strstr(buf1,"MM3") || strstr(buf1,"MM4")){ + while(CHAR_getInt( ret, CHAR_LV)<79){ // + int LevelUpPoint; + LevelUpPoint = ( 50<< 24) + ( 50<< 16) + ( 50<< 8) + ( 50<< 0); + CHAR_setInt( ret, CHAR_ALLOCPOINT, LevelUpPoint); + CHAR_PetLevelUp( ret ); + CHAR_PetAddVariableAi( ret, AI_FIX_PETLEVELUP ); + CHAR_setInt( ret, CHAR_LV, CHAR_getInt( ret, CHAR_LV) +1 ); + } + } +#endif + +#ifdef _NPC_GET_PETABI + { + char buf1[32]; + easyGetTokenFromString( buf , 1 , buf1, sizeof(buf1)); + if(strstr(buf,"PETABI")){ + int lv, trans, vital, str, tough, dex; + //ȡȼ + easyGetTokenFromString( buf , 3 , buf1, sizeof(buf1)); + lv=atoi(buf1); + //ȡת + easyGetTokenFromString( buf , 4 , buf1, sizeof(buf1)); + trans=atoi(buf1); + //ȡѪ + easyGetTokenFromString( buf , 5 , buf1, sizeof(buf1)); + vital=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 6 , buf1, sizeof(buf1)); + str=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 7 , buf1, sizeof(buf1)); + tough=atoi(buf1); + //ȡ + easyGetTokenFromString( buf , 8 , buf1, sizeof(buf1)); + dex=atoi(buf1); + + //õȼ + CHAR_setInt( ret, CHAR_LV, lv); + //ת + CHAR_setInt( ret, CHAR_TRANSMIGRATION, trans); + //Ѫ + CHAR_setInt( ret, CHAR_VITAL, vital*20); + //ù + CHAR_setInt( ret, CHAR_STR, str*80); + //÷ + CHAR_setInt( ret, CHAR_TOUGH, tough*80); + // + CHAR_setInt( ret, CHAR_DEX, dex*100); + //þ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + // + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + + } + } +#endif + + CHAR_setInt( ret, CHAR_HP, CHAR_getWorkInt( ret, CHAR_WORKMAXHP )); + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + CHAR_setInt(ret,CHAR_VARIABLEAI,10000); + } + + petindex2 = CHAR_getCharPet(talker, i); + if( !CHAR_CHECKINDEX( petindex2) ) + return FALSE; + snprintf( msgbuf,sizeof( msgbuf), "õ%s", CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + CHAR_setInt( talker, CHAR_AMPOINT, pVipPoint-VipPoints); +#ifdef _AMPOINT_LOG + LogAmPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + -VipPoints, + CHAR_getInt( talker, CHAR_AMPOINT ), + "(ֹ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif + snprintf( msgbuf,sizeof( msgbuf), "۳ֵ%d", VipPoints); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(talker, j); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + } + + return TRUE; +} +#endif + +#ifdef _NEW_VIP_SHOP +BOOL NPC_ActionNewVipItem( int talker, char *buf) +{ + char buf1[1024]; + int itemindex = CHAR_findEmptyItemBox( talker ); + if( itemindex < 0 ) { + CHAR_talkToCli( talker, -1, "Ʒռ䲻㣡", CHAR_COLORYELLOW); + return FALSE; + } + + CHAR_talkToCli( talker, -1, "ȡУԴ...", CHAR_COLORRED); + int Points=0; + if(getStringFromIndexWithDelim(buf , "," , 2, buf1, sizeof(buf1)) !=FALSE) + Points=atoi(buf1); + if(Points<0)Points=0; + int fd = getfdFromCharaIndex( talker ); + char *id = CHAR_getChar(talker,CHAR_CDKEY); +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + "(ѵ)", + -Points, + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( talker, -1, "δ!", CHAR_COLORRED ); + return FALSE; + } + saacproto_NewVipShop_send(osfd, fd, id, - Points, buf, 0); +#else + saacproto_NewVipShop_send(acfd, fd, id, - Points, buf, 0); +#endif + return TRUE; + +} + +BOOL NPC_ActionNewVipPet( int talker, char *buf) +{ + int i; + char buf1[1024]; + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + int petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) + break; + } + + if( i == CHAR_MAXPETHAVE ) { + snprintf( buf1,sizeof( buf1), ""); + CHAR_talkToCli( talker, -1, buf1, CHAR_COLORYELLOW); + return FALSE; + } + + CHAR_talkToCli( talker, -1, "ȡУԴ...", CHAR_COLORRED); + int Points=0; + if(getStringFromIndexWithDelim(buf , "," , 2, buf1, sizeof(buf1)) !=FALSE) + Points=atoi(buf1); + if(Points<0)Points=0; + int fd = getfdFromCharaIndex( talker ); + char *id = CHAR_getChar(talker,CHAR_CDKEY); +#ifdef _SQL_VIPPOINT_LOG + LogSqlVipPoint(CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + "(ѹ)", + -Points, + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y )); +#endif +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( talker, -1, "δ!", CHAR_COLORRED ); + return FALSE; + } + saacproto_NewVipShop_send(osfd, fd, id, - Points, buf, 1); +#else + saacproto_NewVipShop_send(acfd, fd, id, - Points, buf, 1); +#endif + return TRUE; +} +#endif + +#ifdef _TRANS_7_NPC +BOOL NPC_ActionTrans7( int talker, char *buf) +{ + char token[128]; + int work[10]; + int Trans=CHAR_getInt(talker,CHAR_TRANSMIGRATION)+1; +#ifdef _ADD_POOL_ITEM // WON ADD ӿɼķŵĵ + int tran_pool_item[5] = { 4, 4, 4, 4, 4 }; // ӵĵ߼ķ + int tran_pool_pet[5] = { 2, 2, 2, 2, 2}; // ӵijķ + int j,item_sum=0, pet_sum=0; + + if(Trans>7 || CHAR_getInt(talker,CHAR_LV)<80){ + sprintf( token, "תȼС80תʧ!"); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + return FALSE; + } + + for(j=0; j<5 ;j++){ + item_sum += tran_pool_item[j] ; + pet_sum += tran_pool_pet[j]; + } + + item_sum += 10; // ļĵ + pet_sum += 5; // ļij + +#endif + NPC_TransmigrationStatus(talker, talker, work); + NPC_TransmigrationFlg_CLS(talker, talker); + CHAR_setInt(talker ,CHAR_TRANSMIGRATION, Trans); + CHAR_setInt(talker, CHAR_LV ,1); + CHAR_setMaxExp( talker, 0); + CHAR_setInt( talker,CHAR_SKILLUPPOINT,CHAR_getInt( talker, CHAR_TRANSMIGRATION)*10); + CHAR_Skillupsend( talker ); + CHAR_setInt( talker,CHAR_RIDEPET, -1 ); + CHAR_setInt( talker , CHAR_BASEIMAGENUMBER , CHAR_getInt( talker , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_sendStatusString( talker , "P"); + return TRUE; +} +#endif + +BOOL NPC_ActionAddItem( int talker, char *buf) +{ + int itemID,k=0,itemindex=-1; + int spaceNum=5,i; + char buff3[256], msgbuf[64], token[256]; + int ret; + k=1; + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + for( i = spaceNum ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( itemindex == -1 ) { + spaceNum = i+1; + break; + } + } + if( i == CheckCharMaxItem(talker) ) { + snprintf( msgbuf,sizeof( msgbuf), "Ʒռ䲻㣡"); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + return FALSE; + } + } + k=1; + while( getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + itemID = atoi( buff3); + if( itemID) itemindex = ITEM_makeItemAndRegist( itemID); + if(itemindex == -1) + continue; + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return FALSE; + } + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + atoi( message), +#endif + "AddItem(NPC)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( talker, ret); + } + + return TRUE; +} + +BOOL NPC_ActionSetEend( int talkerindex, char * buf) +{ + int eveno; + int talkNo=1, iflg=0; + char buf1[256]; + + while( getStringFromIndexWithDelim( buf,",",talkNo,buf1,sizeof( buf1)) != FALSE) { + talkNo++; + eveno = atoi( buf); + NPC_EventSetFlg( talkerindex, eveno); + if( ++iflg > 20 ) break; + } + return TRUE; +} + +BOOL NPC_ActionClearEvent( int toindex, char * buf) +{ + int eveno; + int talkNo=1, iflg=0; + char buf1[256]; + + while( getStringFromIndexWithDelim( buf,",",talkNo,buf1,sizeof( buf1)) != FALSE) { + talkNo++; + eveno = atoi( buf); + NPC_NowEndEventSetFlgCls( toindex, eveno); + if( ++iflg > 20 ) break; + } + return TRUE; +} + +BOOL NPC_ActionSetNow( int toindex, char * buf) +{ + int eveno; + int talkNo=1, iflg=0; + char buf1[256]; + + while( getStringFromIndexWithDelim( buf,",",talkNo,buf1,sizeof( buf1)) != FALSE) { + talkNo++; + eveno = atoi( buf); + NPC_NowEventSetFlg( toindex, eveno); + if( ++iflg > 20 ) break; + } + return TRUE; +} + + +BOOL NPC_ActionPassCheck( int meindex, int talker, char *buf) +{ + + char buff2[256]; + char buff3[128]; + int i=1,j=1; + int loop=0; + while( getStringFromIndexWithDelim(buf,",",i,buff2,sizeof(buff2)) !=FALSE ) { + i++; + if(strstr(buff2,"&")!=NULL){ + j=1; + loop=0; + while( getStringFromIndexWithDelim(buff2,"&",j,buff3,sizeof(buff3)) !=FALSE ) { + j++; + if(NPC_ActionBigSmallCheck( meindex, talker, buff3)==FALSE) { + loop=1; + break; + } + } + if(loop==0) { + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + } + }else{ + if( NPC_ActionBigSmallCheck( meindex, talker, buff2) == TRUE){ + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + + } + } + } + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, FALSE ); + return FALSE; + +} + +BOOL NPC_ActionBigSmallCheck(int meindex,int talker,char* buf) +{ + + char buff2[128], buff3[128]; + int kosuu,temp=-1,flg=0; + +#ifdef _NEW_WARPMAN + char buff1[128]; + if(strstr( buf, "-") != NULL) { + getStringFromIndexWithDelim( buf, "-", 2, buff3, sizeof(buff3)); + temp = atoi( buff3); + getStringFromIndexWithDelim( buf, "-", 1, buff1, sizeof(buff1)); + strcpy( buf, buff1); + } +#endif + + if( strstr( buf, "<") != NULL ){ + getStringFromIndexWithDelim( buf, "<", 2, buff3, sizeof(buff2)); + kosuu = atoi( buff3); + getStringFromIndexWithDelim( buf, "<", 1, buff2, sizeof(buff2)); + + if( NPC_ActionFreeIfCheck( meindex, talker, buff2, buff3, kosuu, 1, temp)==TRUE){ + return TRUE; + } + }else if(strstr( buf, ">") != NULL){ + getStringFromIndexWithDelim( buf, ">", 2, buff3, sizeof(buff2)); + kosuu = atoi(buff3); + getStringFromIndexWithDelim( buf, ">" ,1, buff2, sizeof(buff2)); + + if( NPC_ActionFreeIfCheck( meindex, talker, buff2, buff3, kosuu, 2, temp) == TRUE ){ + return TRUE; + } + + }else if( strstr( buf, "!" ) != NULL){ + getStringFromIndexWithDelim( buf, "!=", 2, buff3, sizeof(buff2)); + kosuu = atoi( buff3); + getStringFromIndexWithDelim( buf, "!=", 1, buff2, sizeof(buff2)); + if( NPC_ActionFreeIfCheck( meindex, talker, buff2, buff3, kosuu, 0, temp) == TRUE ){ + return FALSE; + }else{ + return TRUE; + } + }else if( strstr( buf, "=") != NULL){ + getStringFromIndexWithDelim( buf, "=", 2, buff3, sizeof(buff2)); + kosuu = atoi( buff3); + getStringFromIndexWithDelim( buf, "=", 1, buff2, sizeof(buff2)); + flg = 0; + if( strstr( buf, "*") != NULL){ + if( NPC_ActionWarpManReduce( meindex, talker, buf)==TRUE){ + return TRUE; + } + } +#ifdef _NPC_ActionFreeCmp + else if( strstr( buf, "^") != NULL){ + if( NPC_ActionWarpManReduce2( meindex, talker, buf)==TRUE){ + return TRUE; + } + } +#endif + else if( NPC_ActionFreeIfCheck( meindex, talker, buff2, buff3, kosuu, flg, temp) == TRUE ) { + return TRUE; + } + } + return FALSE; +} + +#ifdef _NPC_ActionFreeCmp +//ʵܺԭNPC_ActionWarpManReduce,Ϊ˲Ӱǰ趨,Բȥ޸ԭ +BOOL NPC_ActionWarpManReduce2(int meindex,int talker,char *buf) +{ + char buf2[512]; + char buf3[256]; + int i, itemindex, itemno, kosuu; + int id=0; + int nums = 0; + + getStringFromIndexWithDelim(buf,"=",2,buf2,sizeof(buf2)); + getStringFromIndexWithDelim(buf2,"^",1,buf3,sizeof(buf3)); + itemno = atoi(buf3); + getStringFromIndexWithDelim(buf2,"^",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + for( i=CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker);i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id=ITEM_getInt(itemindex ,ITEM_ID ); + if( itemno == id ){ + nums += ITEM_getInt( itemindex, ITEM_USEPILENUMS);// + } + } + } + + if( nums == kosuu ) return TRUE; + + return FALSE; +} +#endif + +#ifdef _NEW_MANOR_LAW +extern struct FM_POINTLIST fmpointlist; +#endif + +BOOL NPC_ActionFreeIfCheck(int meindex,int talker, char* buf, char *opt, int kosuu,int flg, int temp) +{ +#ifdef _MISSION_TRAIN + if(strcmp(buf,"MT")==0){ + if(NPC_ActionMissionTrainCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif +#ifdef _BOUND_TIME + if(strcmp(buf,"BOUNDTIME")==0){ + if(NPC_ActionBoundTimeCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif +#ifdef _NPC_CHECKTIME + if(strcmp(buf,"YEAR")==0 || strcmp(buf,"MON")==0 || strcmp(buf,"DAY")==0 + || strcmp(buf,"HOUR")==0 || strcmp(buf,"MIN")==0 || strcmp(buf,"SEC")==0 ){ + if(NPC_ActionTimeCheck(meindex,talker, buf, kosuu, flg)==TRUE) + return TRUE; + } +#endif +#ifdef _PLAYER_DIY_MAP + if(strcmp(buf,"DIYMAP")==0){ + if(NPC_ActionDiyMapCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif +#ifdef _FAME_CHECK_NPC + if(strcmp(buf,"FAME")==0){ + if(NPC_ActionFameCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif +#ifdef _VIP_SHOP + if(strcmp(buf,"VIPPOINT")==0){ + if(NPC_ActionVipPointCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif +#ifdef _VIP_RIDE + if(strcmp(buf,"VIP")==0){ + if(NPC_ActionVipCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif + if(strcmp(buf,"LV")==0){ + if(NPC_ActionLevelCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } + if(strcmp(buf,"GOLD")==0){ + if(NPC_ActionGoldCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#ifdef _GLORY_POINT + if(strcmp(buf,"GLORY")==0){ + if(NPC_ActionGloryCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif + if( strcmp(buf,"TRANS") == 0 ) { + if( NPC_ActionCheckTrans( meindex, talker, kosuu, flg) == TRUE ) + return TRUE; + } + + if( !strcmp( buf, "GTIME") ){ + if( NPC_CheckTimeDefine( opt) == TRUE ) + return TRUE; + } + + if(strcmp( buf, "TIME") == 0) { + if(NPC_TiemCheck( meindex, talker, kosuu, flg) == TRUE) + return TRUE; + } + + if( strcmp( buf, "PET") == 0 ) { + if( temp > 0 ) { + if( ActionCheckMyPet( meindex, talker, kosuu, flg, temp) == TRUE ) + return TRUE; + }else + return FALSE; + } + if(strcmp(buf,"ITEM")==0){ + if(NPC_ActionItemCheck(meindex,talker,kosuu, flg)==TRUE) + return TRUE; + } + + if(strcmp(buf,"EQUIT")==0){ + if(NPC_ActioneEquitCheck(meindex,talker,kosuu, flg)==TRUE) + return TRUE; + } + + if( !strcmp(buf,"ENDEV") || !strcmp(buf,"EVEND") ){ + if(NPC_EventCheckFlg( talker, kosuu)==TRUE) + return TRUE; + } + if( !strcmp(buf,"NOWEV") || !strcmp(buf,"EVNOW") ){ + if(NPC_NowEventCheckFlg( talker, kosuu)==TRUE) + return TRUE; + } + + if(strcmp(buf,"PARTY")==0){ + if(NPC_ActionPartyCheck( talker, kosuu, flg)==TRUE) + return TRUE; + } + if(strcmp(buf,"reITEM")==0){ + if( NPC_ActionReItemCheck( talker, kosuu, flg)==TRUE) + return TRUE; + } + if(strcmp(buf,"rePET")==0){ + if( NPC_ActionRePetCheck( talker, kosuu, flg)==TRUE) + return TRUE; + } + +#ifdef _NPCCHANGE_PLAYERIMG + if(strcmp( buf, "BBI")==0) { + if( NPC_CheckPlayerBBI( meindex, talker, kosuu, flg)== TRUE) { + return TRUE; + } + } +#endif + if( strcmp( buf, "FM") == 0 ){ + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) > 0 && + CHAR_getInt( talker, CHAR_FMLEADERFLAG ) != FMMEMBER_APPLY) + if( CHAR_getWorkInt( talker, CHAR_WORKFMFLOOR) == kosuu ){ + return TRUE; + } + } + if(strcmp(buf,"DR")==0){ + if(NPC_ActionDuelRankCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } + if(strcmp(buf,"DP")==0){ + if(NPC_ActionDuelPointCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } +#ifdef _PROFESSION_SKILL // WON ADD ְҵ + if( strcmp( buf, "CLASS") == 0 ){ + if(NPC_ActionClassCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } + if( strcmp( buf, "Skill") == 0 ){ + if( NPC_ActionSkillCheck( meindex, talker, kosuu, flg)==TRUE) + return TRUE; + } + if( strcmp( buf, "SkNum") == 0 ){ + if( NPC_ActionSkillNumCheck( meindex, talker, kosuu, flg)==TRUE) + return TRUE; + } + if( strcmp( buf, "SKCP") == 0 ){ + if( NPC_ActionSkillPointAndSkillCheck( meindex, talker, kosuu, flg)==TRUE) + return TRUE; + } +#endif + + +#ifdef _TREASURE_BOX + if( strcmp( buf, "BOX") == 0 ){ + if( NPC_ActionTreasureTypeCheck( meindex, kosuu, + //NPC_TIME_EVENTMODE = CHAR_NPCWORKINT6,// 1 + CHAR_getWorkInt( meindex, CHAR_NPCWORKINT6) ,flg)==TRUE) + return TRUE; + } +#endif + +#ifdef _NPC_ADDWARPMAN1 + if( strcmp( buf, "PARTYCOUNT") == 0){ + if(NPC_ActionPartyCountCheck( talker, kosuu, flg)==TRUE) + return TRUE; + } + if( strcmp( buf, "MANCOUNT" ) == 0 ){ + if(NPC_ActionManCountCheck( talker, kosuu, flg ) == TRUE ) + return TRUE; + } + if( strcmp( buf, "WOMANCOUNT" ) == 0 ){ + if(NPC_ActionWomanCountCheck( talker, kosuu, flg ) == TRUE ) + return TRUE; + } +#endif + +#ifdef _ANGEL_SUMMON + if(strcmp(buf,"ANGEL_NOW")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_DOING, 0)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_NOW")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_DOING, 0)==TRUE) + return TRUE; + } + if(strcmp(buf,"ANGEL_OVER")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_HERO_COMPLETE, 0)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_OVER")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_HERO_COMPLETE, 0)==TRUE) + return TRUE; + } + if(strcmp(buf,"ANGEL_OUT")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_TIMEOVER, 0)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_OUT")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_TIMEOVER, 0)==TRUE) + return TRUE; + } + + if(strcmp(buf,"ANGEL_I_NOW")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_DOING, TRUE)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_I_NOW")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_DOING, TRUE)==TRUE) + return TRUE; + } + if(strcmp(buf,"ANGEL_I_OVER")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_HERO_COMPLETE, TRUE)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_I_OVER")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_HERO_COMPLETE, TRUE)==TRUE) + return TRUE; + } + if(strcmp(buf,"ANGEL_I_OUT")==0){ + if( NPC_ActionMissionAngelCheck(meindex,talker,kosuu, MISSION_TIMEOVER, TRUE)==TRUE) + return TRUE; + } + if(strcmp(buf,"HERO_I_OUT")==0){ + if( NPC_ActionMissionHeroCheck(meindex,talker,kosuu, MISSION_TIMEOVER, TRUE)==TRUE) + return TRUE; + } + if(strcmp( buf, "HEROCNT") == 0) { + //if(NPC_EventLevelCheck( meindex, talker, kosuu, flg) == TRUE) { + if(NPC_HeroCompleteCountCheck( meindex, talker, kosuu, flg) == TRUE) + return TRUE; + } + +#endif +#ifdef _NEW_MANOR_LAW + if(strcmp(buf,"MANOR") == 0){ + // -1ʾҪǷΪׯ԰Աwarp + if(kosuu > -1){ + int iFmIndex = -1,iHadFmindex = -1; + char token[256]; + + iFmIndex = CHAR_getInt(talker,CHAR_FMINDEX); + getStringFromIndexWithDelim(fmpointlist.pointlistarray[kosuu],"|",5,token,sizeof(token)); + iHadFmindex = atoi(token); + if(iFmIndex > -1){ + // ׯ԰ӵмijԱ + if(iFmIndex == iHadFmindex){ + // мʽԱ + if(CHAR_getInt(talker,CHAR_FMLEADERFLAG) != FMMEMBER_NONE && + CHAR_getInt(talker,CHAR_FMLEADERFLAG) != FMMEMBER_APPLY) return TRUE; + } + } + } + } +#endif + +#ifdef _NPC_CHECK_SCRIPT +{ + int i; + for(i=0;i point1) + return TRUE; + } + + return FALSE; +} + +BOOL ActionCheckMyPet( int meindex, int talker, int petLv, int flg, int petid) +{ + int petsel,petindex=-1; + int lv=-1; + for(petsel=0 ; petsel < CHAR_MAXPETHAVE ; petsel++) { + petindex = CHAR_getCharPet( talker, petsel); + if( petindex == -1 ) + continue; + if(CHAR_getInt( petindex, CHAR_PETID) != petid ) + continue; + break; + } + if( petsel == CHAR_MAXPETHAVE ) { + return FALSE; + }else { //ҵ + lv = CHAR_getInt( petindex, CHAR_LV); + if( NPC_ActionBigSmallLastCheck( petLv, lv, flg) == TRUE) { + return TRUE; + }else { + return FALSE; + } + } + return FALSE; +} + + +BOOL NPC_ActionCheckTrans(int meindex,int talker,int trans,int flg) +{ + int myTrans; + myTrans=CHAR_getInt(talker, CHAR_TRANSMIGRATION); + if( NPC_ActionBigSmallLastCheck( trans, myTrans, flg ) == TRUE ) { + return TRUE; + } + return FALSE; +} + + +#ifdef _NPC_CHECKTIME +BOOL NPC_ActionTimeCheck(int meindex, int talker, char *buf, int date,int flg) +{ + struct tm *p; + time_t timep; + time(&timep); + p=localtime(&timep); /*ȡõʱ*/ + int mydate=0; + + if(strcmp(buf,"YEAR")==0 ){ + mydate=p->tm_year + 1900; + }else if(strcmp(buf,"MON")==0){ + mydate=p->tm_mon + 1; + }else if(strcmp(buf,"DAY")==0){ + mydate=p->tm_mday; + }else if(strcmp(buf,"HOUR")==0){ + mydate=p->tm_hour; + }else if(strcmp(buf,"MIN")==0){ + mydate=p->tm_min; + }else if(strcmp(buf,"SEC")==0 ){ + mydate=p->tm_sec; + } + + if(NPC_ActionBigSmallLastCheck( date, mydate, flg) == TRUE){ + return TRUE; + } + return FALSE; +} +#endif + +#ifdef _MISSION_TRAIN +BOOL NPC_ActionMissionTrainCheck(int meindex,int talker,int mt,int flg) +{ + int mymt; + mymt=CHAR_getInt(talker, CHAR_MISSIONTRAIN_NUM); + if(NPC_ActionBigSmallLastCheck( mt, mymt, flg) == TRUE){ + return TRUE; + } + return FALSE; +} +#endif + +#ifdef _FAME_CHECK_NPC +BOOL NPC_ActionFameCheck(int meindex,int talker,int fame,int flg) +{ + int myfame; + myfame=CHAR_getInt(talker, CHAR_FAME); + if(NPC_ActionBigSmallLastCheck( fame, myfame, flg) == TRUE){ + return TRUE; + } + return FALSE; +} +#endif + +#ifdef _VIP_SHOP +BOOL NPC_ActionVipPointCheck(int meindex,int talker,int point,int flg) +{ + int mypoint; + mypoint=CHAR_getInt(talker,CHAR_AMPOINT); + if(NPC_ActionBigSmallLastCheck( point, mypoint, flg) == TRUE){ + return TRUE; + } + return FALSE; +} +#endif +#ifdef _VIP_RIDE +BOOL NPC_ActionVipCheck(int meindex,int talker,int vip,int flg) +{ + if(NPC_ActionBigSmallLastCheck( CHAR_getInt(talker,CHAR_VIPRIDE), vip, flg) == TRUE){ + return TRUE; + } + return FALSE; +} +#endif + +BOOL NPC_ActionLevelCheck(int meindex,int talker,int level,int flg) +{ + int mylevel; + mylevel=CHAR_getInt(talker,CHAR_LV); + if(NPC_ActionBigSmallLastCheck( level, mylevel, flg) == TRUE){ + return TRUE; + } + return FALSE; +} + +#ifdef _PROFESSION_SKILL // WON ADD ְҵ +BOOL NPC_ActionClassCheck(int meindex,int talker,int p_class,int flg) +{ + int myclass; + myclass= CHAR_getInt( talker, PROFESSION_CLASS ); + + if(NPC_ActionBigSmallLastCheck( p_class, myclass, flg) == TRUE){ + return TRUE; + } + return FALSE; +} + +BOOL NPC_ActionSkillPointAndSkillCheck( int meindex,int talker,int sknum,int flg) +{ + int myskillpoint, myskillnum=0, myskilllevel; + int mysknum=0, j; + myskillpoint= CHAR_getInt( talker, PROFESSION_SKILL_POINT ); + myskilllevel= CHAR_getInt( talker, PROFESSION_LEVEL ); + + for( j=0; jskill, 0, 0 ); + pSkil->use = 0; + } + }else if( !strcmp( buf2, "CLASS") ){ + if( getStringFromIndexWithDelim( buf1 , "=" , 2, buf2, sizeof( buf2)) ==FALSE ) continue; + if( strstr( buf2, "ALL") != NULL ){ + CHAR_setInt( toindex , PROFESSION_CLASS, 0); +#ifdef _CHANNEL_MODIFY + if(CHAR_getInt(toindex,PROFESSION_CLASS) > 0){ + int i,pclass = CHAR_getInt(toindex,PROFESSION_CLASS) - 1; + for(i=0;i= kosuu ) return TRUE; +#endif + + return FALSE; + +} + +#ifdef _NPCCHANGE_PLAYERIMG //andy +BOOL NPC_ActionChangePlayerBBI( int meindex, int charindex, char *Img) +{ + int cBBI; + char buf1[256]; + memset( buf1, 0, sizeof( buf1)); + if( !CHAR_CHECKINDEX( charindex) ) + return FALSE; + if( !CHAR_CHECKINDEX( meindex) ) + return FALSE; +#ifdef _FIXBUG_ATTACKBOW + { + int armtype; + int itemindex = CHAR_getItemIndex( charindex, CHAR_ARM); + if( ITEM_CHECKINDEX(itemindex) ){ + armtype = ITEM_getInt( itemindex, ITEM_TYPE ); + if( armtype == ITEM_BOW || armtype == ITEM_BOUNDTHROW || + armtype == ITEM_BREAKTHROW || armtype == ITEM_BOOMERANG) { + CHAR_talkToCli( charindex, -1, "ʹԶ޷", CHAR_COLORYELLOW ); + return FALSE; + } + } + + } +#endif +#ifdef _PETSKILL_BECOMEPIG + if( CHAR_getInt( charindex, CHAR_BECOMEPIG) > -1 ){// + CHAR_talkToCli( charindex, -1, "޷вܱ", CHAR_COLORYELLOW ); + return FALSE; + } +#endif + if( CHAR_getInt( charindex, CHAR_RIDEPET) != -1 ) {//費ͼ + CHAR_setInt( charindex, CHAR_RIDEPET, -1 ); + BATTLE_changeRideImage( charindex ); + CHAR_talkToCli( charindex, -1, "ȡ״̬", CHAR_COLORYELLOW); + + //change -----> ޸bug(,ѡ״̬ȻΪ"", + CHAR_complianceParameter( charindex ); + CHAR_send_P_StatusString( charindex, CHAR_P_STRING_RIDEPET); + + //return FALSE; + } +#ifdef _ITEM_METAMO + CHAR_setWorkInt( charindex, CHAR_WORKITEMMETAMO, 0); +#endif + + if( Img == NULL || !strcmp( Img, "\0")) + return FALSE; +//======================= + CHAR_setWorkInt( charindex, CHAR_WORKNPCMETAMO, meindex); + if( strstr( Img, "NPCBBI") != NULL ) { + cBBI = CHAR_getInt( meindex, CHAR_BASEBASEIMAGENUMBER); + sprintf( buf1, "㻯%sӡ", CHAR_getChar( meindex, CHAR_NAME)); + }else if( strstr( Img, "MYBBI") != NULL ) { + cBBI = CHAR_getInt( charindex, CHAR_BASEBASEIMAGENUMBER); + CHAR_setWorkInt( charindex, CHAR_WORKNPCMETAMO, 0); + sprintf( buf1, "ԭӡ"); + }else if( strstr( Img, ",") != NULL ) { + int imgindex=1, maxImg=0; + while( getStringFromIndexWithDelim( Img, ",", imgindex, buf1, sizeof( buf1)) != FALSE ) { + imgindex++; + maxImg++; + } + if( (imgindex = (rand()%maxImg)) > maxImg) imgindex = 1; + if( imgindex < 1 ) imgindex = 1; + + if( getStringFromIndexWithDelim( Img, ",", imgindex, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + cBBI = atoi( buf1); + sprintf( buf1, "Ӹıˡ"); + }else { + cBBI = atoi( Img); + sprintf( buf1, "Ӹıˡ"); + } +//======================= + if( cBBI < 0 ) { + return FALSE; + } + CHAR_talkToCli( charindex, -1, buf1, CHAR_COLORYELLOW); + //CHAR_BASEBASEIMAGENUMBER CHAR_BASEIMAGENUMBER + CHAR_setInt( charindex, CHAR_BASEIMAGENUMBER, cBBI); + CHAR_complianceParameter( charindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( charindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + //CHAR_K_STRING_BASEIMAGENUMBER + //CHAR_P_STRING_BASEBASEIMAGENUMBER + return TRUE; +} +#endif + +#ifdef _NPCCHANGE_PLAYERIMG +BOOL NPC_CheckPlayerBBI( int meindex, int charindex, int BBI, int flg) +{ + int MyBBI; + if( !CHAR_CHECKINDEX( charindex)) + return FALSE; + if( BBI < 0 ) + return FALSE; + MyBBI = CHAR_getInt( charindex, CHAR_BASEIMAGENUMBER); + return NPC_ActionBigSmallLastCheck( BBI, MyBBI,flg); +} +#endif + +BOOL showString( int meindex, char *showstr,int flg) +{ //㲥 + char buf1[256]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int toindex = -1; + int floor; + int i; + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n not found argstr "); + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, showstr,buf1, sizeof(buf1)) == NULL ) { + strcpy( buf1, showstr); + } + toindex = -1; + floor = CHAR_getInt( meindex , CHAR_FLOOR); + while( toindex < 1000) { + toindex ++; + if( !CHAR_CHECKINDEX( toindex) ) + continue; + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + continue; + if( CHAR_getInt( toindex , CHAR_FLOOR) != floor ) + continue; + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); + if( flg == 1 ) { + CHAR_setWorkInt( toindex, CHAR_WORKSTAKEFLAG, FALSE ); + for( i=0; i<5; i++) { + CHAR_setWorkInt( toindex, i+CHAR_WORKSTAKETYPE1, 0); + } + } + } + return TRUE; +} + +BOOL NPC_getTimeXYPoint( int meindex, int Mode) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256], buf1[256], buf2[256]; + int fl=-1, x, y; + int GraNo = -1; + int points = 1; //Ϊ1 + if( Mode <= 0 ) { + points = 2; + } + memset( npcarg, 0, sizeof( npcarg)); + if( !CHAR_CHECKINDEX( meindex) ) return FALSE; + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL ){ + print("WarpMan:GetArgStrErr"); + return FALSE; + } + memset( buf, 0, sizeof( buf)); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "TimeXYPoint", buf, sizeof( buf)) != NULL ){ + if( getStringFromIndexWithDelim(buf , "&" , points, buf1, sizeof( buf1)) != FALSE ){ + memset( buf2, 0, sizeof( buf2)); + if( getStringFromIndexWithDelim(buf1 , "," , 1, buf2, sizeof( buf2)) == FALSE ){ + return FALSE; + } + fl = atoi( buf2); + if( getStringFromIndexWithDelim(buf1 , "," , 2, buf2, sizeof( buf2)) == FALSE ){ + return FALSE; + } + x = atoi( buf2); + if( getStringFromIndexWithDelim(buf1 , "," , 3, buf2, sizeof( buf2)) == FALSE ){ + return FALSE; + } + y = atoi( buf2); + if( MAP_IsValidCoordinate( fl, x, y ) == FALSE ){ + char filename[256]; + NPC_Util_CheckAssignArgFile( meindex, filename); + return FALSE; + } + if( CHAR_getInt( meindex, CHAR_FLOOR) != fl || + CHAR_getInt( meindex, CHAR_X) != x || + CHAR_getInt( meindex, CHAR_Y) != y ){ + CHAR_warpToSpecificPoint( meindex, fl , x , y); + } + } + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "GraNo", buf, sizeof( buf)) != NULL ){ + if( getStringFromIndexWithDelim(buf , "&" , points, buf1, sizeof( buf1)) != FALSE ){ + GraNo = atoi( buf1); + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, GraNo); + } + } + return TRUE; +} + +BOOL NPC_getTimeData( int meindex, char *npcarg, int *born, int *dead, int loopspeed) +{ + int i; + char buf[256]; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "NEWTIME", buf, sizeof( buf)) != NULL ){ + for(i=0 ; i<9 ; i++){ + if( strstr( buf, TimeTble[i].arg ) != NULL){ + *born = TimeTble[i].born; + *dead = TimeTble[i].dead; + return TRUE; + } + } + } + return FALSE; +} + +BOOL NPC_CheckTimeDefine( char *timetype) +{ + LSTIME nowlstime; + int born=-1, dead=-1, finds=0, i; + + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + + for(i=0 ; i<9 ; i++){ + if( strstr( timetype, TimeTble[i].arg ) != NULL){ + born = TimeTble[i].born; + dead = TimeTble[i].dead; + finds = 1; + break; + } + } + if( finds == 0 ) return FALSE; + + if( born < dead ){ + if( (born < nowlstime.hour) && (dead > nowlstime.hour) ){ + return TRUE; + } + }else{ + if( (born < nowlstime.hour && 1024 > nowlstime.hour) || + ( 0 < nowlstime.hour && dead > nowlstime.hour)){ + return TRUE; + } + } + + return FALSE; +} + +void NPC_TimeDefineDo( int meindex, int born, int dead, int typeMode) +{ + LSTIME nowlstime; + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + if(born < dead){ + if( (born < nowlstime.hour) && (dead > nowlstime.hour) ){ + CHAR_setWorkInt(meindex,typeMode,0); + }else{ + CHAR_setWorkInt(meindex,typeMode,1); + } + }else{ + if( (born < nowlstime.hour && 1024 > nowlstime.hour) || ( 0 < nowlstime.hour && dead > nowlstime.hour)){ + CHAR_setWorkInt(meindex,typeMode,0); + }else{ + CHAR_setWorkInt(meindex,typeMode,1); + } + } + if( NPC_getTimeXYPoint( meindex, CHAR_getWorkInt( meindex, typeMode)) == FALSE ) + return; +} + + +void GetRand_WarpPoint( char *buf, int *fl, int *x, int *y ) +{ + char buff1[256],buff2[256]; + int i=0,point=1; + struct { + int m_fl; + int m_x; + int m_y; + } RandPoint[]={ + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + }; + while( getStringFromIndexWithDelim( buf,";",point,buff1,sizeof( buff1)) != FALSE) { + point++; + getStringFromIndexWithDelim(buff1,",",1,buff2,sizeof(buff2)); + RandPoint[i].m_fl = atoi(buff2); + getStringFromIndexWithDelim(buff1,",",2,buff2,sizeof(buff2)); + RandPoint[i].m_x = atoi(buff2); + getStringFromIndexWithDelim(buff1,",",3,buff2,sizeof(buff2)); + RandPoint[i].m_y = atoi(buff2); + i++; + if( i >= arraysizeof( RandPoint) ) + break; + } + + point = RAND( 0, i); + if( RandPoint[point].m_fl <= 0 || point > arraysizeof( RandPoint) -1) { + point = 0; + } + *fl = RandPoint[point].m_fl; + *x = RandPoint[point].m_x; + *y = RandPoint[point].m_y; + + return; +} + +#ifdef _EMENY_CHANCEMAN +int NPC_EmenyChanceCheck( int meindex, int charaindex, char *arg) +{ + char buf1[256]; + int sex=2, fl=-1,x=-1,y=-1; + memset( buf1, 0, sizeof( buf1)); + + if( NPC_Util_GetStrFromStrWithDelim( arg, "CHECKSEX", buf1, sizeof( buf1)) == NULL ) { + return charaindex; + } + if( strstr( buf1, "male") != 0 ){ + sex = 1; + } + if( NPC_Util_GetStrFromStrWithDelim( arg, "NOBATTLEWARP", buf1, sizeof( buf1)) != NULL ) { + char data[256]; + if( getStringFromIndexWithDelim( buf1,",", 1, data, sizeof(data)) == FALSE ) return charaindex; + fl = atoi( data); + if( getStringFromIndexWithDelim( buf1,",", 2, data, sizeof(data)) == FALSE ) return charaindex; + x = atoi( data); + if( getStringFromIndexWithDelim( buf1,",", 3, data, sizeof(data)) == FALSE ) return charaindex; + y = atoi( data); + } + return NPC_DischargePartyForSex( meindex, charaindex, fl, x, y, sex); +} + +int NPC_DischargePartyForSex( int meindex, int charaindex, int fl, int x, int y, int fsex) +{ + int Party[CHAR_PARTYMAX+3] = {-1,-1,-1,-1,-1,-1,-1,-1}; + int masterindex =-1, i, j, playerNo; + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_LEADER ){ + playerNo = CHAR_getInt( charaindex, CHAR_BASEBASEIMAGENUMBER); + if( CHAR_getSexInt( playerNo ) == fsex ) { + if( MAP_IsValidCoordinate( fl, x, y) != FALSE ){ + CHAR_warpToSpecificPoint( charaindex, fl, x, y); + return -1; + } + }else { + return charaindex; + } + } + CHAR_talkToCli( charaindex, -1, "Ŷ飡", CHAR_COLORYELLOW); + + for( i = 0; i < getPartyNum(charaindex); i ++ ) { + int index = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1+i); + if( !CHAR_CHECKINDEX( index)) continue; + Party[i] = index;//¼ + } + CHAR_DischargePartyNoMsg( charaindex);//ɢŶ + + for( i = 0; i < getPartyNum(charaindex); i ++ ) { + int index = Party[i]; + playerNo = CHAR_getInt( index, CHAR_BASEBASEIMAGENUMBER); + if( CHAR_getSexInt( playerNo ) == fsex ) { + if( MAP_IsValidCoordinate( fl, x, y) != FALSE ){ + CHAR_warpToSpecificPoint( index, fl, x, y); + } + Party[i] = -1; + } + } + j = CHAR_WORKPARTYINDEX1; + for( i = 0; i < getPartyNum(charaindex); i ++ ) { + int index = Party[i]; + if( !CHAR_CHECKINDEX( index ))continue; + if( !CHAR_CHECKINDEX( masterindex )){ + masterindex = index; + CHAR_setWorkInt( masterindex, CHAR_WORKPARTYMODE, CHAR_PARTY_LEADER); + CHAR_setWorkInt( masterindex, j++, masterindex); + }else { + CHAR_setWorkInt( masterindex, j++, index); + CHAR_setWorkInt( index, CHAR_WORKPARTYMODE, CHAR_PARTY_CLIENT); + CHAR_setWorkInt( index, CHAR_WORKPARTYINDEX1, masterindex); + } + } + return masterindex; +} +#endif + +BOOL NPC_ActionDuelRankCheck(int meindex,int talker,int rank,int flg) +{ + int myrank; + myrank=CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC); + if( NPC_ActionBigSmallLastCheck( rank, myrank, flg)==TRUE){ + return TRUE; + } + + return FALSE; +} + +BOOL NPC_ActionDuelPointCheck(int meindex,int talker,int rank,int flg) +{ + int myduel; + myduel = CHAR_getInt( talker, CHAR_DUELPOINT); + if( NPC_ActionBigSmallLastCheck( rank, myduel, flg)==TRUE){ + return TRUE; + } + + return FALSE; +} + +BOOL NPC_ActionTreasureTypeCheck(int meindex,int level, int type, int flg) +{ + int mylevel; + +// if( CHAR_getWorkInt( meindex, NPC_TIME_EVENTMODE) == NPC_EVENTMODE_EVENT ){ + mylevel = (type == NPC_EVENTMODE_EVENT)?1:0; + if( NPC_ActionBigSmallLastCheck( level, mylevel, flg)==TRUE) + return TRUE; + return FALSE; +} + +BOOL NPC_ActionTreasureRandItemGet(int meidex,int talker,int rand_j,char *buf) +{ + char buff2[64]; + int randitem; + int ret; + int itemindex; + char token[128]; + + if(rand_j == 0) { + print("Event:춣Ľ룬ִ"); + return FALSE; + } + + randitem = rand()%rand_j; + if(randitem == 0) randitem = rand_j; + + getStringFromIndexWithDelim(buf , "," , randitem, buff2, sizeof(buff2)) ; + + itemindex = ITEM_makeItemAndRegist( atoi( buff2)); + + if(itemindex == -1) return FALSE; + /*ʧ ةܰ( ʧ ة ľ */ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + print( "npc_exchangeman.c: additem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + + if(itemindex != -1) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventAddItem(õĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + return TRUE; + +} + +#ifdef _NPC_ADDLEVELUP // (ɿ) ANDY ⲿԻҵȼ +extern tagRidePetTable ridePetTable[296]; +void NPC_ActionLevelAndTransUp( int meindex, int charindex, int level, int skillpoint, int exp, int ridepet) +{ + char szBuffer[256]=""; + if( !CHAR_CHECKINDEX( charindex) ) + return; +//int CHAR_LevelUpCheck( int charaindex , int toindex) + if( exp > 0 ){ + int LevelUp=0; + int myexp = CHAR_getInt( charindex, CHAR_EXP); + myexp += exp; + if( myexp > 300000000 ) myexp = 300000000; + CHAR_setInt( charindex, CHAR_EXP, myexp); + snprintf( szBuffer, sizeof(szBuffer), + "(%s) õ EXP %d", CHAR_getUseName( charindex ), exp); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + LevelUp = CHAR_LevelUpCheck( charindex , -1); + if( LevelUp > 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) %d", + CHAR_getUseName( charindex ), + CHAR_getInt( charindex, CHAR_LV ) + ); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + CHAR_setInt( charindex, CHAR_SKILLUPPOINT, + CHAR_getInt( charindex, CHAR_SKILLUPPOINT) + LevelUp*3 ); + CHAR_complianceParameter( charindex ); + } + } + if( level > 0 ){ + CHAR_setInt( charindex, CHAR_LV, level); + snprintf( szBuffer, sizeof(szBuffer), + "(%s) ȼ趨Ϊ %d", + CHAR_getUseName( charindex ), CHAR_getInt( charindex, CHAR_LV ) + ); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + } + + if( skillpoint > 0 ){ + int MySp = CHAR_getInt( charindex, CHAR_SKILLUPPOINT); + MySp += skillpoint; + CHAR_setInt( charindex, CHAR_SKILLUPPOINT, MySp); + } + if( ridepet >= 0 ){ + int basepet[2][4]={ {2066,2067,2068,2069}, + {2072,2073,2074,2075}}; + int petTemp[]={-1,-1,-1,-1,-1}; + char msgbuf[256]; + int petNum=0; + int i,j=0; + int k=0, petindex,enemyarray; + petTemp[j++] = basepet[0][rand()%4]; + petTemp[j++] = basepet[1][rand()%4]; + + for( i=0; i< arraysizeof(ridePetTable) ; i++ ){ + if( CHAR_getInt( charindex, CHAR_BASEBASEIMAGENUMBER) == ridePetTable[i].charNo ){ + petTemp[j]= ridePetTable[i].petId; + j++; + if( j >= arraysizeof( petTemp) ) + break; + } + } + j=0; + for( petNum=0; petNum= CheckCharMaxItem(talker) ) + return FALSE; + } + return TRUE; +} + +BOOL NPC_ActionMissionHeroCheck(int meindex,int talker,int mission,int flg,int checkitem) +{ + int mindex; + char nameinfo[64]; + int i, itemindex, itemid; + + mindex = checkIfAngel( talker); + if( mindex <= -1 ) return FALSE; + if( missiontable[mindex].mission != mission) return FALSE; + getMissionNameInfo( talker, nameinfo); + if( strcmp( nameinfo, missiontable[mindex].heroinfo )) return FALSE; + if( missiontable[mindex].flag != flg ) return FALSE; + + if( checkitem ) { // + for( i=CHAR_STARTITEMARRAY;i= CheckCharMaxItem(talker) ) + return FALSE; + } + + return TRUE; +} + + +BOOL NPC_HeroCompleteCountCheck(int meindex,int talker,int count,int flg) +{ + + int herocnt; + herocnt = CHAR_getInt(talker,CHAR_HEROCNT); + + if(NPC_EventBigSmallLastCheck( count, herocnt, flg) == TRUE) + { + if(flg == 3) return FALSE; + return TRUE; + } + + if(flg == 3) return TRUE; + return FALSE; + +} + + + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_exchangeman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_exchangeman.c new file mode 100644 index 0000000..958a7e0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_exchangeman.c @@ -0,0 +1,4413 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "net.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_exchangeman.h" +#include "npc_eventaction.h" +#include "log.h" +#include "battle.h" +#include "handletime.h" +#include "enemy.h" +#include "npc_warp.h" +#include "saacproto_cli.h" +#include "configfile.h" +#include "chatmagic.h" +#include "npc_transmigration.h" +#ifdef _ANGEL_SUMMON +extern struct MissionInfo missionlist[MAXMISSION]; +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif + +extern char* CHAR_setintdata[CHAR_DATAINTNUM]; +extern char* CHAR_setchardata[CHAR_DATACHARNUM]; +enum { + CHAR_WORK_EVENTWARP = CHAR_NPCWORKINT4, + +}; +extern int CheckCharMaxItem(int talker); + + +/********************************* +* +*********************************/ +BOOL NPC_ExChangeManInit( int meindex ) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024*2]; + int i = 1; + char buf4[256]; + + CHAR_setWorkInt(meindex,CHAR_WORK_EVENTWARP,1); + + /*--NPCë--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEEVENT ); + + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) { + print("NPC_ExChange.c TypeCheck: GetArgStrErr\n"); + print("NPCName=%s\n", CHAR_getChar( meindex ,CHAR_NAME)); + return FALSE; + } + + i = 1; + /*--ìNPCʧ ةë--*/ + /*-- ƻ¾ʸƥ˪ľ¾--*/ + while(getStringFromIndexWithDelim( argstr ,"EventEnd" ,i ,buf ,sizeof(buf)) + != FALSE) + { + i++; + /*--ƥ̤ľ¼߼ë-*/ + if(strstr( buf,"GetItem") != NULL) { + if(strstr( buf,"ItemFullMsg") == NULL) { + NPC_Util_GetStrFromStrWithDelim(buf,"EventNo",buf4,sizeof(buf4)); + print("### EventNo=%d %s:ItemFullMsg ###\n", + atoi( buf4), + CHAR_getChar( meindex, CHAR_NAME)); + } + } + + if(strstr( buf,"GetPet") != NULL) { + if(strstr( buf,"PetFullMsg") == NULL) { + NPC_Util_GetStrFromStrWithDelim(buf,"EventNo",buf4,sizeof(buf4)); + print("\n### ventNo=%d %s:PetFullMsg ###", + atoi(buf4), + CHAR_getChar(meindex,CHAR_NAME)); + } + } + + if(strstr( buf,"GetEgg") != NULL) { + if(strstr( buf,"PetFullMsg") == NULL) { + NPC_Util_GetStrFromStrWithDelim(buf,"EventNo",buf4,sizeof(buf4)); + print("\n### ventNo=%d %s:PetFullMsg ###", + atoi(buf4), + CHAR_getChar(meindex,CHAR_NAME)); + } + } + + if(strstr( buf,"GetStone") != NULL){ + if(strstr( buf,"StoneFullMsg") == NULL){ + NPC_Util_GetStrFromStrWithDelim(buf,"EventNo",buf4,sizeof(buf4)); + print("\n### EventNo=%d %s:StonFullMsg ###", + atoi( buf4), + CHAR_getChar( meindex, CHAR_NAME)); + } + } + + if(strstr( buf,"DelStone") != NULL) { + if(strstr( buf,"StoneLessMsg") == NULL) { + NPC_Util_GetStrFromStrWithDelim(buf,"EventNo",buf4,sizeof(buf4)); + print("\n### EventNo=%d %s:StoneLessMsg ###", + atoi(buf4), + CHAR_getChar(meindex,CHAR_NAME)); + } + } + } + + i = 1; + + return TRUE; + +} + +/*-- --*/ +BOOL NPC_EventWarpNpc(int meindex,char *buf) +{ + char token[32]; + char buf2[32]; + int floor,x,y; + int ret; + int cnt; + int dcnt = 1; + + /*--ػ󼰴 --*/ + cnt = CHAR_getWorkInt(meindex,CHAR_WORK_EVENTWARP); + while(getStringFromIndexWithDelim(buf,",", dcnt,buf2,sizeof(buf2) ) + !=FALSE ){ + dcnt++; + } + + if(dcnt <= cnt) cnt=1; + + + while(getStringFromIndexWithDelim(buf,",", cnt,buf2,sizeof(buf2)) !=FALSE ) + { + cnt++; + ret=getStringFromIndexWithDelim(buf2,".", 1,token,sizeof(token)); + if( ret == FALSE ) { + continue; + } + floor = atoi( token ); + + ret=getStringFromIndexWithDelim(buf2,".", 2,token,sizeof(token)); + if( ret == FALSE ){ + continue; + } + x = atoi( token ); + + ret=getStringFromIndexWithDelim(buf2,".", 3,token,sizeof(token)); + if( ret == FALSE ) { + continue; + } + y = atoi( token ); + + CHAR_setWorkInt(meindex,CHAR_WORK_EVENTWARP, cnt); + CHAR_warpToSpecificPoint(meindex, floor, x, y); + return TRUE; + } + + return FALSE; + +} + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_ExChangeManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2) == FALSE) { + /* */ + if(NPC_Util_isFaceToChara(talkerindex,meindex,1 ) == FALSE) return; + } + + /*-- ë--*/ + CHAR_setWorkInt( talkerindex ,CHAR_WORKSHOPRELEVANT, 0); + CHAR_setWorkInt( talkerindex ,CHAR_WORKSHOPRELEVANTSEC, 0); + CHAR_setWorkInt( talkerindex ,CHAR_WORKSHOPRELEVANTTRD, 0); + + /*-- --*/ + NPC_TypeCheck( meindex, talkerindex, szMes); + +} + +/*------------------------------------------------------------ + *ɬð̻ë ģؤ ë + *-------------------------------------------------------------*/ +BOOL NPC_TypeCheck(int meindex,int talker,char *szMes) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024*2]; + char buf2[512]; + int i = 1; + int EvNo; + int evch; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("NPC_ExChange.c TypeCheck: GetArgStrErr\n"); + print("NPCName=%s\n", CHAR_getChar(meindex,CHAR_NAME)); + return FALSE; + } + + +#ifdef _NPC_TALK_CHECK + if( NPC_Util_GetStrFromStrWithDelim( argstr, "TALKCHECK", buf, sizeof( buf)) != NULL ){ + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)==0){ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK) != CHAR_getWorkInt(talker, CHAR_WORK_TALKCHECK)){ + char buf[256]; + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + sprintf(buf, "֤:%d", CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)); + CHAR_talkToCli( talker, meindex, buf, CHAR_COLORYELLOW); + return FALSE; + }else{ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + } +#endif + + + /*-- ɬð̻ë --*/ + while(getStringFromIndexWithDelim( argstr,"EventEnd",i,buf,sizeof( buf)) + != FALSE){ + i++; + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, 0); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 0); + + /*-- ìϼë --*/ + if(NPC_Util_GetStrFromStrWithDelim(buf,"EventNo", + buf2, sizeof( buf2) ) == NULL) continue; + + if(strstr( buf2, "-") != 0) { + EvNo = -1; + }else{ + EvNo = atoi( buf2); + } + + /*-- ׷ºë浤ƥì ƻݳ --*/ + if(NPC_EventCheckFlg( talker, EvNo) == TRUE) continue; + + /*--ƽë浤--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"KeyWord", buf2,sizeof( buf2) ) + != NULL){ + if(strcmp( szMes, buf2) != 0) continue; + + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, i); + } + + /*--ʸ 󡼰ͻ Ȼ¾ë--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"Pet_Name", buf2,sizeof( buf2)) != NULL){ + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 1); + } + evch = NPC_ExChangeManEventCheck( meindex, talker, buf); + if(evch != -1) { + if(NPC_Util_GetStrFromStrWithDelim( buf,"TYPE", buf2, sizeof( buf2)) != NULL){ + + if( strstr( buf2, "REQUEST") != NULL) { + NPC_RequestMain( meindex, talker, buf); + return TRUE; + }else if( strstr( buf2, "ACCEPT") != NULL) { + /*- ë --*/ + NPC_AcceptMain( meindex, talker, buf); + return TRUE; + + }else if(strstr( buf2, "MESSAGE") != NULL) { + char token[14*100]; + char token2[14*50]; + if(NPC_Util_GetStrFromStrWithDelim( buf,"NomalMsg", token,sizeof( token) ) + != NULL ) { + if(NPC_AcceptDel( meindex, talker, 0) == FALSE) return FALSE; + if(EvNo != -1){ + NPC_NowEventSetFlg( talker, EvNo); + } + CHAR_talkToCli( talker, meindex, token, CHAR_COLORWHITE); + if(NPC_Util_GetStrFromStrWithDelim( buf,"NpcWarp", token2,sizeof( token2) ) + != NULL){ + NPC_EventWarpNpc(meindex,token2); + } + if(NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", buf2, sizeof( buf2) ) + !=NULL){ + char buf3[16]; + int k = 1; + if(EvNo != -1) NPC_NowEventSetFlgCls( talker, EvNo); + while(getStringFromIndexWithDelim(buf2 , "," ,k, buf3, sizeof(buf3)) + !=FALSE ){ + k++; + NPC_EventSetFlg( talker, atoi( buf3)); + } + } + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2)) != NULL) { + char buf3[16]; + int k = 1; + k= 1 ; + while(getStringFromIndexWithDelim(buf2 , "," , k, + buf3, sizeof(buf3)) + != FALSE ){ + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + k++; + } + } +#ifdef _ANGEL_SUMMON + // ٻ + if( NPC_Util_GetStrFromStrWithDelim( buf, "MISSIONOVER", + buf2, sizeof( buf2)) != NULL) + { + int mindex; + int mission; + char nameinfo[64]; + + mission = atoi( buf2); + mindex = checkIfAngel(talker); + + if( mission == missiontable[mindex].mission ) + { + char msg[1024]; + + print(" ====ٻ==== "); + + CHAR_setInt( talker, CHAR_HEROCNT, + CHAR_getInt( talker, CHAR_HEROCNT)+1 ); + getMissionNameInfo( talker, nameinfo); + saacproto_ACMissionTable_send( acfd, MISSION_HERO_COMPLETE, 4, nameinfo, ""); + sprintf( msg, " i:%d m:%d %s ", mindex, mission, nameinfo); + print( msg); + LogAngel( msg ); + } + + } + + // ٻ + if( NPC_Util_GetStrFromStrWithDelim( buf, "MISSIONCLEAN", + buf2, sizeof( buf2)) != NULL) + { + int mindex; + int mission; + char nameinfo[64]; + + mission = atoi( buf2); + mindex = checkIfAngel( talker); + + if( mission == missiontable[mindex].mission ) + { + char msg[1024]; + + getMissionNameInfo( talker, nameinfo); + saacproto_ACMissionTable_send( acfd, mindex, 3, nameinfo, ""); + + sprintf( msg, " i:%d m:%d %s ", mindex, mission, nameinfo); + print( msg); + LogAngel( msg ); + } + + } +#endif + + }else if(NPC_Util_GetStrFromStrWithDelim(buf, "NomalWindowMsg", + token, sizeof( token) ) + !=NULL) { + /*--̼ƥë߯--*/ + int fd = getfdFromCharaIndex( talker); +#ifdef _NEWEVENT + if(NPC_Util_GetStrFromStrWithDelim(buf, "NomalWindowMsg1", + buf2, sizeof(buf2)) != NULL){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + }else { +#endif + char token2[14*50]; + if(NPC_AcceptDel( meindex, talker,0) == FALSE) return FALSE; + if( EvNo != -1) NPC_NowEventSetFlg( talker, EvNo); + + if(NPC_Util_GetStrFromStrWithDelim( buf,"NpcWarp", + token2,sizeof( token2) ) != NULL){ + NPC_EventWarpNpc(meindex,token2); + } + if(NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", + buf2, sizeof( buf2) ) !=NULL){ + char buf3[16]; + int k = 1; + if(EvNo != -1) NPC_NowEventSetFlgCls( talker, EvNo); + while(getStringFromIndexWithDelim(buf2 , "," ,k, + buf3, sizeof(buf3)) !=FALSE ){ + k++; + NPC_EventSetFlg( talker, atoi( buf3)); + } + } + //ì׷ºë + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2)) != NULL) { + char buf3[16]; + int k = 1; + + k= 1 ; + while(getStringFromIndexWithDelim(buf2 , "," , k, + buf3, sizeof(buf3)) != FALSE ){ + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + k++; + } + } +#ifdef _ANGEL_SUMMON + // ٻ + if( NPC_Util_GetStrFromStrWithDelim( buf, "MISSIONOVER", + buf2, sizeof( buf2)) != NULL) + { + int mindex; + int mission; + char nameinfo[64]; + + mission = atoi( buf2); + mindex = checkIfAngel( talker); + + if( mission == missiontable[mindex].mission ) + { + char msg[1024]; + + print(" ====ٻ==== "); + + CHAR_setInt( talker, CHAR_HEROCNT, + CHAR_getInt( talker, CHAR_HEROCNT)+1 ); + getMissionNameInfo( talker, nameinfo); + saacproto_ACMissionTable_send( acfd, MISSION_HERO_COMPLETE, 4, nameinfo, ""); + sprintf( msg, " i:%d m:%d %s ", mindex, mission, nameinfo); + print( msg); + LogAngel( msg ); + } + + } + + // ٻ + if( NPC_Util_GetStrFromStrWithDelim( buf, "MISSIONCLEAN", + buf2, sizeof( buf2)) != NULL) + { + int mindex; + int mission; + char nameinfo[64]; + + mission = atoi( buf2); + mindex = checkIfAngel( talker); + + if( mission == missiontable[mindex].mission ) + { + print(" ====ٻ==== "); + + getMissionNameInfo( talker, nameinfo); + saacproto_ACMissionTable_send( acfd, mindex, 3, nameinfo, ""); + } + + } +#endif + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YES, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +#ifdef _NEWEVENT + } +#endif + } + + return TRUE; + + }else if(strstr( buf2, "CLEAN") != NULL) { + NPC_CleanMain( meindex, talker, buf); + return TRUE; + } + } + } + } + + strcpy( buf, "\0"); + if( NPC_Util_GetStrFromStrWithDelim( argstr, "NomalMainMsg", buf, sizeof( buf)) == NULL ) { + print("\n err:NOT FIND NomalMainMsg"); + return FALSE; + } + + i = 1; + while(getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof( buf2))!= FALSE){ + i++; + } + i--; + i = rand()%i + 1; + getStringFromIndexWithDelim( buf,",", i, buf2, sizeof( buf2)); + CHAR_talkToCli( talker, meindex, buf2, CHAR_COLORWHITE); + return TRUE; +} + + +/*----------------------------------- + * ë + ------------------------------------*/ +void NPC_ExChangeMan_selectWindow( int meindex, int talker,int num) +{ + + switch( num) { + /*--;޵--*/ + case 0: + /*-ì ئƥìë¾ë --*/ + NPC_MsgDisp( meindex, talker, 0); + break; + + case 1: + /*--ޥì浤--*/ + NPC_MsgDisp( meindex, talker, 5); + break; + + /*--ʧͱ--*/ + case 2: + /*--Ի--*/ + NPC_MsgDisp( meindex, talker, 6); + break; + + case 3: + /*--Ի--*/ + NPC_MsgDisp( meindex, talker, 11); + break; + } + +} + +/*------------------------------------- + *ìë ̼ + --------------------------------------*/ +void NPC_RequestMain(int meindex,int talker,char *buf) +{ + int shiftbit; + char buf2[128]; + + /*--ìϼë--*/ + NPC_Util_GetStrFromStrWithDelim( buf,"EventNo", buf2,sizeof( buf2) ); + shiftbit = atoi( buf2); + + if(NPC_NowEventCheckFlg( talker, shiftbit) == TRUE) { + NPC_ExChangeMan_selectWindow( meindex, talker, 0); + }else{ + NPC_ExChangeMan_selectWindow( meindex, talker, 1); + } +} + +/*--------------------------------------- + * ì ̼ + ----------------------------------------*/ +void NPC_AcceptMain(int meindex,int talker ,char *buf) +{ + + NPC_ExChangeMan_selectWindow( meindex, talker, 2); +} + +/*---------------------------------------- + * ׷ºëʧ¿м̼ + ----------------------------------------*/ +void NPC_CleanMain(int meindex,int talker,char *buf) +{ + NPC_ExChangeMan_selectWindow( meindex, talker, 3); +} + +/*----------------------------------------- +ͷʧ߯Ȼݱ̫ľ£ +-------------------------------------------*/ +void NPC_ExChangeManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + /*-- Իئ巴 --*/ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + + + switch( seqno) { + + /*--׷ºëݼ̼--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_CLEANMSG: + if( select == WINDOW_BUTTONTYPE_YES) { + NPC_MsgDisp( meindex, talkerindex, 12); + }else if(select == WINDOW_BUTTONTYPE_NO) { + } + break; + +#ifdef _NEWEVENT + case CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG: + if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD) + 1); + NPC_MsgDisp( meindex, talkerindex, 99); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD) - 1); + NPC_MsgDisp( meindex, talkerindex, 99); + } + break; +#else + case CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG: + break; +#endif + /*--;޵ؤԻ絤--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK: + if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)+1); + NPC_MsgDisp( meindex, talkerindex, 22); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)-1); + NPC_MsgDisp( meindex, talkerindex, 22); + } + break; + + /*--ʧͱؤԻ絤--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_ACCTHANK: + if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)+1); + NPC_MsgDisp( meindex, talkerindex, 82); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)-1); + NPC_MsgDisp( meindex, talkerindex, 82); + } + break; + + /*--ػìë¾--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_NOWEVENT: + if(select == WINDOW_BUTTONTYPE_YES) { + NPC_MsgDisp( meindex, talkerindex, 7); + }else if(select == WINDOW_BUTTONTYPE_NO){ + NPC_MsgDisp( meindex, talkerindex, 1); + } + break; + + /*--;޵̼̼--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG: + if(select == WINDOW_BUTTONTYPE_YES) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD,0); + NPC_MsgDisp( meindex, talkerindex, 2); + }else if(select == WINDOW_BUTTONTYPE_NO) { + + }else if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)+1); + NPC_MsgDisp( meindex, talkerindex, 55); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)-1); + NPC_MsgDisp( meindex, talkerindex, 55); + } + break; + + /*--Ի̼̼--*/ + case CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG: + if(select == WINDOW_BUTTONTYPE_YES) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD,0); +#ifdef _NEWEVENT + NPC_MsgDisp( meindex, talkerindex, 81); +#else + NPC_MsgDisp( meindex, talkerindex, 8); +#endif + }else if(select == WINDOW_BUTTONTYPE_NO) { + }else if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)+1); + NPC_MsgDisp( meindex, talkerindex, 66); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)-1); + NPC_MsgDisp( meindex, talkerindex, 66); + } + break; + +#ifdef _NEWEVENT + case CHAR_WINDOWTYPE_WINDOWEVENT_ACCTHANKNEW: + if(select == WINDOW_BUTTONTYPE_OK){ + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD,0); + NPC_MsgDisp( meindex, talkerindex, 8); + }else if(select == WINDOW_BUTTONTYPE_NEXT) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)+1); + NPC_MsgDisp( meindex, talkerindex, 81); + }else if(select == WINDOW_BUTTONTYPE_PREV) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD, + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)-1); + NPC_MsgDisp( meindex, talkerindex, 81); + } + break; +#endif + /*--ʸ ëܸ̼--*/ + case CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP: + if(CHAR_getWorkInt( talkerindex ,CHAR_WORKSHOPRELEVANTTRD) ==0) { + NPC_EventPetSkill( meindex, talkerindex, data); + NPC_MsgDisp( meindex, talkerindex, 25); + }else{ + NPC_EventPetSkill( meindex, talkerindex, data); + NPC_MsgDisp( meindex, talkerindex, 88); + } + break; + } +#ifdef _NPC_EVENT_NOTICE + CHAR_sendCSpecifiedObjindex( getfdFromCharaIndex(talkerindex), CHAR_getWorkInt(meindex,CHAR_WORKOBJINDEX)); +#endif +} + + +/*------------------------- + * ëƻ¾ + --------------------------*/ +int NPC_ExChangeManEventCheck( int meindex, int talker, char *buff1) +{ + char buff2[512]; + char buff3[128]; + char buf[512]; + int i = 1,j = 1; + int loop = 0; + + NPC_Util_GetStrFromStrWithDelim( buff1, "EVENT", buf, sizeof( buf)); + + /*-- EVENtë έ --*/ + while( getStringFromIndexWithDelim(buf, ",", i, buff2,sizeof( buff2)) + !=FALSE ) + { + i++; + /*-- "&"ؤ¼ƥ --*/ + if(strstr( buff2, "&")!=NULL){ + j = 1; + loop = 0; + while(getStringFromIndexWithDelim(buff2, "&", j, buff3, sizeof( buff3)) + != FALSE ) + { + j++; + if(NPC_EventBigSmallCheck( meindex, talker, buff3) == FALSE) + { + loop = 1; + break; + } + } + + if(loop == 0){ + i--; + return i; + } + /*--繴--*/ + }else{ + if(NPC_EventBigSmallCheck( meindex, talker, buff2) == TRUE) { + i--; + return i; + } + } + + } + + return -1; + +} + +/*--------------------------------- + * į + --------------------------------*/ +BOOL NPC_EventBigSmallCheck(int meindex,int talker, char* buf) +{ + + char buff2[128]; + int kosuu; + + /*--ʸͻȻPETë --*/ + if(strstr( buf, "PET") != NULL) { + if(strstr( buf, "EV") != NULL) { + if(NPC_PetLvCheck( meindex, talker, buf, 1) != FALSE) return TRUE; + }else{ + if(NPC_PetLvCheck( meindex, talker, buf, 0) != FALSE) return TRUE; + } + return FALSE; + } + + /*--Ʊ ɧį --*/ + if(strstr( buf, "<") != NULL) { + getStringFromIndexWithDelim( buf, "<", 2, buff2, sizeof( buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "<", 1, buff2, sizeof( buff2)); + + if(NPC_EventFreeIfCheck( meindex, talker, buff2, kosuu, 1) == TRUE) { + return TRUE; + } + + }else if(strstr( buf, ">") != NULL) { + getStringFromIndexWithDelim( buf, ">", 2, buff2, sizeof(buff2)); + kosuu = atoi(buff2); + getStringFromIndexWithDelim( buf, ">" ,1, buff2, sizeof(buff2)); + + if(NPC_EventFreeIfCheck( meindex, talker, buff2, kosuu, 2)==TRUE) { + return TRUE; + } + + }else if(strstr( buf, "!=" ) != NULL) { + getStringFromIndexWithDelim( buf, "!=", 2, buff2, sizeof( buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "!=", 1, buff2, sizeof( buff2)); + if(NPC_EventFreeIfCheck( meindex, talker, buff2, kosuu, 3) == TRUE) { + return TRUE; + } + + }else if(strstr( buf, "=") != NULL) { + getStringFromIndexWithDelim( buf, "=", 2, buff2, sizeof( buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "=", 1, buff2, sizeof( buff2)); + + if(strstr( buf, "*") != NULL) { + if(NPC_EventReduce( meindex, talker, buf) == TRUE){ + return TRUE; + } + }else if(NPC_EventFreeIfCheck( meindex, talker, buff2, kosuu, 0) + == TRUE) + { + return TRUE; + } + } + + return FALSE; + +} + + +/*----------------------------------- + * ë ƻ¾ + *-----------------------------------*/ +BOOL NPC_EventFreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg) +{ + + +#ifdef _NPC_CHECK_SCRIPT +{ + int i; + for(i=0;i16 ְȼ춵99%Ҫ16 + char *p=NULL; + int i,level=0,count=0; + CHAR_HaveSkill *pSkil; + if( strstr( buf, "PROSK" ) ){ + p = buf; + level = atoi(p+5); + }else + level = 100; + for( i = 0; i < CHAR_SKILLMAXHAVE; i ++ ){ + if( CHAR_getCharHaveSkill( talker, i ) ){ + pSkil = CHAR_getCharHaveSkill( talker, i ); + if( SKILL_getInt( &pSkil->skill, SKILL_LEVEL) >= level ) + ++count; + } + } + if(NPC_EventBigSmallLastCheck( kosuu, count, flg) == TRUE) + return TRUE; + } +#endif + +#ifdef _ADD_reITEM + if(strstr( buf, "reITEM" ) != NULL) { + int i,count=0,itemindex=-1; + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( !ITEM_CHECKINDEX( itemindex) ) + ++count; + } + if(NPC_EventBigSmallLastCheck( kosuu, count, flg) == TRUE) + return TRUE; + } +#endif + + + return FALSE; + +} + +/*-------------------------------- + * ʸìë + ---------------------------------*/ +BOOL NPC_PetLvCheck(int meindex,int talker,char *buf,int mode) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[16]; + char buf3[8]; + int petno; + int baseno; + int petlevel = 0; + int flg=0; + int mypetlevel = 0; + int i = 0; + int petindex; + char name[512]; + int cnt = 0; + int loop; + + + /*--϶ýľʸϼ ID)ë --*/ + getStringFromIndexWithDelim( buf, "-", 2, buff2, sizeof( buff2)); + if(strstr(buff2,"*") != NULL) { + getStringFromIndexWithDelim( buff2, "*", 1, buf3, sizeof( buf3)); + petno = atoi( buf3); + getStringFromIndexWithDelim( buff2, "*", 2, buf3, sizeof( buf3)); + loop = atoi( buf3); + + }else{ + petno = atoi( buff2); + loop = 1; + + } + + /*--ʸ л¾--*/ + for(i=0; i < CHAR_MAXPETHAVE ; i++) { + if(loop == cnt) return TRUE; + + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) continue; + + /*--ʸIDë ƻ--*/ + baseno = CHAR_getInt( petindex, CHAR_PETID); + + /* ʸIDػƹëƩ */ + if( (baseno == petno) && (CHAR_getInt( petindex, CHAR_ENDEVENT) + == mode)) + { + /*--ìë--*/ + mypetlevel = CHAR_getInt( petindex, CHAR_LV); + getStringFromIndexWithDelim( buf, "-", 1, buff2, sizeof( buff2)); + + if(strstr( buf, "<") != NULL) { + flg = 1; + getStringFromIndexWithDelim( buff2, "<", 2, buf3, sizeof(buf3)); + }else if(strstr( buf, ">") != NULL) { + getStringFromIndexWithDelim( buff2, ">", 2, buf3, sizeof(buf3)); + flg = 2; + }else if(strstr( buf, "=") != NULL) { + getStringFromIndexWithDelim( buff2, "=", 2, buf3, sizeof(buf3)); + flg = 0; + } + + petlevel = atoi( buf3); + + if(NPC_EventBigSmallLastCheck( petlevel, mypetlevel, flg) == TRUE) { + /*--ʸ 󡻥ɬýľ 󡼰 --*/ + if(CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC)==1) { + char *usename; + + /*--ɬð̻P --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("PetLevel:GetArgStrErr"); + return FALSE; + } + + usename = CHAR_getUseName( petindex); + NPC_Util_GetStrFromStrWithDelim( argstr, "Pet_Name", + name,sizeof( name)); + + if(strcmp( name, usename) == 0) + { + cnt++; + continue; + } + }else { + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 0); + cnt++; + continue; + } + } + } + } + + if(loop == cnt) return TRUE; + if(i == CHAR_MAXPETHAVE) return FALSE; + + return FALSE; +} + + +/*-------------------------------- + * ʸìë + ---------------------------------*/ +int NPC_PetLvCheckType2(int petindex,int meindex,int talker,char *buf,int mode) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[16]; + char buf3[8]; + int petno; + int baseno; + int petlevel = 0; + int flg = 0; + int mypetlevel = 0; + char name[512]; + + /*--϶ýľʸϼ ID)ë --*/ + getStringFromIndexWithDelim( buf, "-", 2, buff2, sizeof( buff2)); + if(strstr(buff2,"*") != NULL) { + getStringFromIndexWithDelim( buff2, "*", 1, buf3, sizeof( buf3)); + petno = atoi( buf3); + }else{ + petno = atoi( buff2); + } + + + /*--ʸIDë ƻ--*/ + baseno = CHAR_getInt( petindex, CHAR_PETID); + + /*--ʸIDػƹëƩ--*/ + if( (baseno == petno) && (CHAR_getInt( petindex, CHAR_ENDEVENT) + == mode)) + { + /*--ìë--*/ + mypetlevel=CHAR_getInt( petindex, CHAR_LV); + getStringFromIndexWithDelim( buf, "-", 1,buff2,sizeof(buff2)); + + if(strstr( buf, "<") != NULL) { + flg = 1; + getStringFromIndexWithDelim( buff2, "<", 2, + buf3, sizeof(buf3)); + }else if(strstr( buf, ">") != NULL) { + getStringFromIndexWithDelim( buff2, ">", 2, buf3, sizeof(buf3)); + flg = 2; + }else if(strstr( buf, "=") != NULL) { + getStringFromIndexWithDelim( buff2, "=", 2, buf3, sizeof(buf3)); + flg = 0; + } + + petlevel = atoi(buf3); + + if(NPC_EventBigSmallLastCheck( petlevel, mypetlevel, flg) + == TRUE) + { + /*--ʸ 󡻥ɬýľ 󡼰 --*/ + if(CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC) == 1) { + char *usename; + + /*--ɬð̻P --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("PetLevel:GetArgStrErr"); + return FALSE; + } + + usename = CHAR_getUseName( petindex); + NPC_Util_GetStrFromStrWithDelim(argstr,"Pet_Name", + name, sizeof( name)); + + if(strcmp( name, usename) == 0) + { + return TRUE; + } + }else { + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 0); + return TRUE; + } + } + } + + return FALSE; + +} + +/*------------------------ + * + --------------------------*/ +BOOL NPC_SavePointCheck(int meindex,int talker,int shiftbit,int flg) +{ + int point; + + point = CHAR_getInt( talker, CHAR_SAVEPOINT); + + if( (point & ( 1<< shiftbit)) == ( 1<< shiftbit)) { + if(flg == 3) return FALSE; + return TRUE; + } + + if(flg == 3) return TRUE; + return FALSE; +} + +/*------------------------ + *̶⼰ + --------------------------*/ +BOOL NPC_ImageCheck(int meindex,int talker,int kosuu,int flg) +{ + int image; + + image = CHAR_getInt( talker, CHAR_IMAGETYPE); + + if(NPC_EventBigSmallLastCheck( image, kosuu, flg) == TRUE) { + return TRUE; + } + return FALSE; + +} + + +/*----------------------------------------- + * ޼ë浤(ؤ) + ------------------------------------------*/ +BOOL NPC_TiemCheck(int meindex,int talker,int time,int flg) +{ + LSTIME nowlstime; + int now; + + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + now = getLSTime( &nowlstime); + + if(NPC_EventBigSmallLastCheck( time, now, flg) == TRUE) { + return TRUE; + } + return FALSE; + +} + +/*------------------------------ + *--Itemë + -------------------------------*/ +BOOL NPC_EventItemCheck(int meindex,int talker,int itemNo,int flg) +{ + int i; + int itemindex = -1; + int id; + + //Change fix 鴩ϵĵ + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ) { + + itemindex=CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex) ) { + id=ITEM_getInt( itemindex ,ITEM_ID ); + + if(NPC_EventBigSmallLastCheck( itemNo, id, flg) == TRUE) { + if(flg == 0) return TRUE; + continue; + }else{ + if(flg == 0) continue; + return FALSE; + } + } + } + + if(flg == 3) return TRUE; + + return FALSE; + +} + + +/*------------------------------ + * levelë + -------------------------------*/ +BOOL NPC_EventLevelCheck(int meindex,int talker,int level,int flg) +{ + + int mylevel; + mylevel = CHAR_getInt(talker,CHAR_LV); + + if(NPC_EventBigSmallLastCheck( level, mylevel, flg) == TRUE) + { + if(flg == 3) return FALSE; + return TRUE; + } + + if(flg == 3) return TRUE; + return FALSE; + +} + + + +/*------------------------------ + * ENDEventNoë + -------------------------------*/ +BOOL NPC_ENDEventNoCheck(int meindex,int talker,int shiftbit,int flg) +{ + + if(NPC_EventCheckFlg( talker, shiftbit) == TRUE) { + if(flg == 3) return FALSE; + return TRUE; + } + + if(flg == 3) return TRUE; + return FALSE; +} + + +/*------------------------------ + * NOWEventNoë + -------------------------------*/ +BOOL NPC_NOWEventNoCheck(int meindex,int talker,int shiftbit,int flg) +{ + if(NPC_NowEventCheckFlg( talker, shiftbit) == TRUE) { + if(flg == 3) return TRUE; + return TRUE; + } + + if(flg == 3) return TRUE; + return FALSE; +} + +/*--------------------------------------- + * + --------------------------------------*/ +BOOL NPC_EventBigSmallLastCheck(int point1,int mypoint,int flg) +{ + + if(flg == 0) { + if(point1 == mypoint) { + return TRUE; + } + }else if(flg == 1) { + if(mypoint < point1) { + return TRUE; + } + }else if(flg == 2) { + if(mypoint > point1) { + return TRUE; + } + }else if(flg == 3) { + if(point1 != mypoint) { + return TRUE; + } + } + return FALSE; +} + + +/*--------------------------------- + *ë + *----------------------------------*/ +#ifdef _CHANNEL_MODIFY +extern int *piOccChannelMember; +#endif +void NPC_MsgDisp(int meindex,int talker,int num) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; +#ifdef _NEWEVENT + char buf[4096]; + char token2[4096]; + char buf2[4096]; + char token[4096]; + char tmp[4096]; +#else + char buf[1024*2]; + char token2[50*14]; + char buf2[512]; + char token[512]; + char tmp[32]; +#endif + int i = 1; + int work = 0; + int EvNo = 0; + int fd = getfdFromCharaIndex( talker); + int buttontype = WINDOW_BUTTONTYPE_OK; + int windowtype = CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG; + int evch; + + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("MsgDisp:GetArgStrErr"); + print("NPCName=%s\n", CHAR_getChar( meindex, CHAR_NAME)); + return ; + } + if(num == 22 || num == 82 || num == 55 || num == 66) { + int pwork; + + pwork = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + pwork = (pwork / 100) -1 ; + + getStringFromIndexWithDelim( argstr, "EventEnd", pwork, buf,sizeof( buf)); + + }else{ + /*ɬð̻ë*/ + while(getStringFromIndexWithDelim( argstr, "EventEnd", i, buf, sizeof(buf)) + != FALSE) + { + i++; + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 0); + + /*--ìϼë--*/ + NPC_Util_GetStrFromStrWithDelim( buf, "EventNo", buf2, sizeof( buf2)); + if(strstr( buf2, "-1") != 0) { + EvNo = -1; + }else{ + EvNo = atoi( buf2); + } + EvNo = atoi( buf2); + + /*--׷ºë浤ƥì ƻݳ--*/ + if(NPC_EventCheckFlg( talker, EvNo) == TRUE) continue; + + /*--ƽë浤--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"Pet_Name", buf2,sizeof( buf2)) + != NULL ) + { + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 1); + } + + /*--ƽë浤--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"KeyWord", buf2,sizeof( buf2) ) + != NULL) + { + if(CHAR_getWorkInt( talker ,CHAR_WORKSHOPRELEVANT) != i) continue; + } + + evch = NPC_ExChangeManEventCheck( meindex, talker, buf); + + if(evch != -1) { + + /*--ì--*/ + // if(NPC_ExChangeManEventCheck( meindex, talker, buf) == TRUE) { + break; + } + } + } + + //print(" NPC_MsgDisp:%d ", num); + + switch( num) { + case 0: + /*ػìë¾ë ʶ--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "StopMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token,sizeof( buf2), buf2); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = CHAR_WINDOWTYPE_WINDOWEVENT_NOWEVENT; + } + break; + + case 1: + /*--֧¾ë ׽мNOë--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "NoStopMsg", + buf2, sizeof( buf2)) + != NULL) + { + strcpysafe( token, sizeof(buf2), buf2); + + } + break; + + case 7: + /*--ػìë弰--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "EndStopMsg", + buf2, sizeof( buf2)) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + + /*--ì ë Ȼջ--*/ + NPC_EventAdd( meindex, talker, 1); + + /*--׷ºë--*/ + NPC_NowEventSetFlgCls( talker, EvNo); + + /*--Ӭ׼ƥ ë--*/ + if(CHAR_getInt( talker, CHAR_CHARM) > 0) { + CHAR_setInt( talker, CHAR_CHARM, CHAR_getInt(talker,CHAR_CHARM) -1); + CHAR_complianceParameter( talker ); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_CHARM); + NPC_CharmStatus( meindex, talker); + } + } + break; + + case 2: + /*--ؤԻ絤--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "ThanksMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token,sizeof( buf2), buf2); + /*--ì ׷ºë--*/ + if(NPC_EventAdd(meindex, talker, 0) != FALSE) { + NPC_NowEventSetFlg( talker, EvNo); + } + else { + return; + } + + + if(NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", + buf2, sizeof( buf2) ) + !=NULL) + { + char buf3[16]; + int k = 1; + if(EvNo != -1) NPC_NowEventSetFlgCls( talker, EvNo); + + while(getStringFromIndexWithDelim(buf2 , "," ,k, + buf3, sizeof(buf3)) + !=FALSE ) + { + k++; + NPC_EventSetFlg( talker, atoi( buf3)); + } + } + + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2)) + != NULL) { + char buf3[16]; + int k = 1; + + k= 1 ; + while(getStringFromIndexWithDelim(buf2 , "," , k, + buf3, sizeof(buf3)) + != FALSE ) + { + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + k++; + } + } + + + + } + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, 1); + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work + ( i * 100); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, work); + + if(NPC_Util_GetStrFromStrWithDelim( buf,"NpcWarp", + token2,sizeof( token2) ) + != NULL){ + NPC_EventWarpNpc(meindex,token2); + } + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "ThanksMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + + break; + + case 22: + + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work % 100; + + if(work == 1){ + if( NPC_Util_GetStrFromStrWithDelim( buf, "ThanksMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token,sizeof( buf2), buf2); + } + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "ThanksMsg2") != NULL) { + + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + + }else{ + + sprintf( tmp, "ThanksMsg%d", work); + if( NPC_Util_GetStrFromStrWithDelim( buf, tmp, + buf2, sizeof( buf2) ) + != NULL) { + strcpysafe( token,sizeof( buf2), buf2); + } + + work++; + sprintf( tmp, "ThanksMsg%d", work); + + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, tmp) != NULL) { + + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWEVENT_REQTHANK, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + } + break; + + case 25: + /*--ؤԻ絤--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "ThanksMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token,sizeof( buf2), buf2); + /*--ì ׷ºë--*/ + if(NPC_EventAdd(meindex, talker, 2) != FALSE) { + NPC_NowEventSetFlg( talker, EvNo); + } + } + break; + + + case 3: + /*-- ɧ--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "NomalMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe(token, sizeof( buf2), buf2); + } + break; + + case 4: + /*--ʧ ةмݼ--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "ItemFullMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe(token, sizeof( buf2), buf2); + } + break; + + case 5: + /*-- ë¶˼̼--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "RequestMsg", + buf2, sizeof( buf2) ) + != NULL) + { + + if(strstr(buf2,"%8d") != NULL) { + char buf3[64]; + int cost; + + NPC_Util_GetStrFromStrWithDelim( buf, "DelStone", + buf3, sizeof( buf3) ); + cost = NPC_EventGetCost( meindex, talker, buf3); + + sprintf(token,buf2,cost); + + }else{ + strcpysafe( token,sizeof( buf2), buf2); + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG; + } + + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, 1); + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work + ( i * 100); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, work); + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "RequestMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + break; + + case 55: + + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work % 100; + + if(work == 1){ + if( NPC_Util_GetStrFromStrWithDelim( buf, "RequestMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + } + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "RequestMsg2") != NULL){ + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + }else{ + + sprintf( tmp, "RequestMsg%d", work); + if( NPC_Util_GetStrFromStrWithDelim( buf, tmp, + buf2, sizeof( buf2) ) + != NULL){ + strcpysafe( token,sizeof( buf2), buf2); + + } + work++; + sprintf( tmp, "RequestMsg%d", work); + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, tmp) != NULL) { + + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_WINDOWEVENT_REQMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + } + break; + + + case 6: + //print(" 6_Ӧ? "); + /*--Ի˼̼--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "AcceptMsg", + buf2, sizeof( buf2) ) + != NULL) + { + if(strstr(buf2,"%8d") != NULL) { + char buf3[64]; + int cost; + + NPC_Util_GetStrFromStrWithDelim( buf, "DelStone", + buf3, sizeof( buf3) ); + cost = NPC_EventGetCost( meindex, talker, buf3); + + sprintf( token, buf2, cost); + }else{ + strcpysafe( token, sizeof( buf2), buf2); + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG; + } + + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, 1); + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work + ( i * 100); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, work); + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "AcceptMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + break; + + + case 66: + //print(" 66_Ӧ? "); + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work % 100; + + if(work == 1){ + if( NPC_Util_GetStrFromStrWithDelim( buf, "AcceptMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token,sizeof( buf2), buf2); + } + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "AcceptMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + }else{ + + sprintf( tmp, "AcceptMsg%d", work); + if( NPC_Util_GetStrFromStrWithDelim( buf, tmp, + buf2, sizeof( buf2) ) + != NULL){ + strcpysafe( token,sizeof( buf2), buf2); + } + work++; + sprintf( tmp, "AcceptMsg%d", work); + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, tmp) != NULL) { + + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_WINDOWEVENT_ACCMAINMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + } + break; + + case 8: + //print(" 8_Ӧ? "); + + if( NPC_Util_GetStrFromStrWithDelim( buf, "ThanksMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + /*--ì ׷ºë--*/ + if(NPC_AcceptDel( meindex, talker,0) == FALSE){ + return ; + } + + if(NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", + buf2, sizeof( buf2) ) + !=NULL) + { + char buf3[16]; + int k = 1; + if(EvNo != -1) NPC_NowEventSetFlgCls( talker, EvNo); + + while(getStringFromIndexWithDelim(buf2 , "," ,k, + buf3, sizeof(buf3)) + !=FALSE ) + { + k++; + NPC_EventSetFlg( talker, atoi( buf3)); + } + } + + if( NPC_Util_GetStrFromStrWithDelim( buf, "Charm", + buf2, sizeof( buf2)) + !=NULL) + { + /*--ƥ գ ë---*/ + if( CHAR_getInt( talker, CHAR_CHARM) < 100 && EvNo > 0 ){ + if(CHAR_getInt( talker, CHAR_CHARM) + atoi(buf2) > 100){ + CHAR_setInt( talker, CHAR_CHARM,100); + + }else{ + CHAR_setInt( talker, CHAR_CHARM, + CHAR_getInt(talker,CHAR_CHARM) + atoi(buf2)); + + } + + CHAR_complianceParameter( talker ); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_CHARM); + NPC_CharmStatus( meindex, talker); + } + } + + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2)) + != NULL) { + char buf3[16]; + int k = 1; + + k= 1 ; + while(getStringFromIndexWithDelim(buf2 , "," , k, + buf3, sizeof(buf3)) + != FALSE ) + { + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + k++; + } + } +#ifdef _CHAR_PROFESSION + // Robin add ְҵ + if( NPC_Util_GetStrFromStrWithDelim( buf, "PROFESSION", + buf2, sizeof( buf2)) != NULL) + { + int p_class = atoi( buf2); + //Change fix 2004/07/05 + for( i=0; i 0 ){ + p_class = 1; + CHAR_talkToCli( talker, -1, "Ȱְҵװͨͨж£", CHAR_COLORWHITE); + break; + } + } + } + if( p_class == 0) + { + print(" ====ְҵ==== "); + + // ԭ + //if( PROFESSION_RESTORE_POINT( talker ) != 1 ) return FALSE; + + // 趨ְҵ + CHAR_setInt( talker, PROFESSION_CLASS, p_class ); +#ifdef _CHANNEL_MODIFY + if(CHAR_getInt(talker,PROFESSION_CLASS) > 0){ + int i,pclass = CHAR_getInt(talker,PROFESSION_CLASS) - 1; + for(i=0;i 0 ){ + if(CHAR_getInt( talker, CHAR_CHARM) + atoi(buf2) > 100){ + CHAR_setInt( talker, CHAR_CHARM,100); + }else{ + CHAR_setInt( talker, CHAR_CHARM, + CHAR_getInt(talker,CHAR_CHARM) + atoi( buf2)); + } + CHAR_complianceParameter( talker ); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_CHARM); + NPC_CharmStatus( meindex, talker); + } + } + } + + break; + + + case 9: + + if( NPC_Util_GetStrFromStrWithDelim( buf, "NomalWindowMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + if(EvNo != -1) NPC_NowEventSetFlg( talker, EvNo); + } +#ifdef _NEWEVENT + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, 1); + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work + ( i * 100); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, work); + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "NomalWindowMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } +#endif + break; + +#ifdef _NEWEVENT + case 99: + work = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD); + work = work % 100; + + if(work == 1) + { + if( NPC_Util_GetStrFromStrWithDelim( buf, "NomalWindowMsg1", + buf2, sizeof( buf2) ) != NULL) + strcpysafe( token,sizeof( buf2), buf2); + + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, "NomalWindowMsg2") != NULL) { + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + }else{ + + sprintf( tmp, "NomalWindowMsg%d", work); + if( NPC_Util_GetStrFromStrWithDelim( buf, tmp, + buf2, sizeof( buf2) ) + != NULL){ + strcpysafe( token,sizeof( buf2), buf2); + } + work++; + sprintf( tmp, "NomalWindowMsg%d", work); + /*--ʸ⻥ؤʾ̼ë--*/ + if(strstr( buf, tmp) != NULL) { + + /*ƥ˪*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + }else{ + int fd = getfdFromCharaIndex( talker); + char token2[14*50]; + /*--ƥʧ ةئܰë浤--*/ + if(NPC_AcceptDel( meindex, talker,0) == FALSE) return; + + /*׷ºëƻľɣ--*/ + if( EvNo != -1) NPC_NowEventSetFlg( talker, EvNo); + + if(NPC_Util_GetStrFromStrWithDelim( buf,"NpcWarp", + token2,sizeof( token2) )!= NULL){ + NPC_EventWarpNpc(meindex,token2); + } + + //׷ºë + if(NPC_Util_GetStrFromStrWithDelim( buf, "EndSetFlg", + buf2, sizeof( buf2) )!=NULL) + { + char buf3[16]; + int k = 1; + + if(EvNo != -1) NPC_NowEventSetFlgCls( talker, EvNo); + + while(getStringFromIndexWithDelim(buf2 , "," ,k, + buf3, sizeof(buf3)) !=FALSE ) + { + k++; + NPC_EventSetFlg( talker, atoi( buf3)); + } + } + //ì׷ºë + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2)) != NULL) { + char buf3[16]; + int k = 1; + + k= 1 ; + while(getStringFromIndexWithDelim(buf2 , "," , k, + buf3, sizeof(buf3)) + != FALSE ) + { + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + k++; + } + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YES, + CHAR_WINDOWTYPE_WINDOWEVENT_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return; + } + } + break; +#endif + case 10: + + /*--ʸмݼ--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "PetFullMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + print(" PetFullMsg:%s ", token); + } + else + { + print(" PetFullMsg_Error:%d ", __LINE__); + } + break; + + case 11: + /*--׷ºë弰--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanMainMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = CHAR_WINDOWTYPE_WINDOWEVENT_CLEANMSG; + } + break; + case 12: + /*--׷ºë --*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlgMsg", + buf2, sizeof( buf2) ) + != NULL) + { + char buf3[64]; + int loop=1; + + strcpysafe( token, sizeof( buf2), buf2); + NPC_Util_GetStrFromStrWithDelim( buf, "CleanFlg", + buf2, sizeof( buf2) ); + while(getStringFromIndexWithDelim(buf2 , "," , loop, buf3, sizeof(buf3)) + != FALSE ) + { + NPC_NowEndEventSetFlgCls( talker, atoi(buf3)); + loop++; + } + } + break; + + case 13: + /*--Żм--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "StoneFullMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + } + break; + + case 14: + /*--ŻԻئж--*/ + if( NPC_Util_GetStrFromStrWithDelim( buf, "StoneLessMsg", + buf2, sizeof( buf2) ) + != NULL) + { + strcpysafe( token, sizeof( buf2), buf2); + } + break; + } + + /*ƥ˪*/ +#ifdef _NEWEVENT + if(num != 8) +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + buttontype, + windowtype, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + +} + +/*-------------------------------------- + *ìüʧ ةëܰ + ---------------------------------------*/ +BOOL NPC_EventAdd(int meindex,int talker,int mode) +{ + + char buf[64]; + char buff2[128]; + int j = 1,i = 0; + int kosuucnt = 0; + int itemindex; + char buff[1024*2]; + int rand_j = 0; + int rand_flg = 0; + int rand_cnt = 0; + int evcnt; + int b_flg = 0; + + /*--ɬð̻ ̤лؤë ƻּë --*/ + evcnt = NPC_EventFile( meindex, talker, buff); + + if(evcnt == -1) return FALSE; + +// if(NPC_EventFile( meindex, talker, buff) == FALSE) return FALSE; + + /*--ʧ ةë--*/ + if(NPC_ItemFullCheck( meindex, talker, buff, mode, evcnt) == FALSE){ + NPC_MsgDisp( meindex, talker, 4); + return FALSE; + } + + /*--ͱ --*/ + if(NPC_Util_GetStrFromStrWithDelim( buff, "DelStone", buff2, sizeof( buff2) ) + !=NULL) + { + int stone; + + stone = NPC_EventGetCost( meindex, talker, buff2); + + if( (CHAR_getInt( talker, CHAR_GOLD) - stone) < 0 ){ + NPC_MsgDisp( meindex, talker, 14); + return FALSE; + } + } + + + /*--ʸ ëܰ--*/ + if((NPC_Util_GetStrFromStrWithDelim( buff, "pet_skill", buff2, sizeof( buff2) ) + !=NULL) && mode == 0 ){ + if(mode == 0) { + NPC_PetSkillMakeStr( meindex, talker, 1); + return TRUE; + } + } + + + if(mode == 2) mode = 0; + + /*--ʸëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( buff, "GetPet", buff2, sizeof( buff2) ) + !=NULL) + { + if(mode == 0){ + if(NPC_EventAddPet( meindex, talker, buff2,0) == FALSE) { + NPC_MsgDisp( meindex, talker, 10); + return FALSE; + } + }else if(mode == 1){ + + } + } +#ifdef _NPC_FUSION + // Robin add NPCȡﵰ + if(NPC_Util_GetStrFromStrWithDelim( buff, "GetEgg", buff2, sizeof( buff2) ) + !=NULL) + { + if(mode == 0){ + if(NPC_EventAddEgg( meindex, talker, buff2,0) == FALSE) { + print(" AddEgg_Error:%d ", __LINE__); + NPC_MsgDisp( meindex, talker, 10); + return FALSE; + } + }else if(mode == 1){ + + } + } +#endif + +#ifdef _GLORY_POINT + if( NPC_Util_GetStrFromStrWithDelim( buff, "AddGlory", buff2, sizeof( buff2)) != NULL ) { + if( NPC_ActionAddGlory( talker, buff2) == FALSE ) + return FALSE; + } +#endif + + + + if(NPC_Util_GetStrFromStrWithDelim( buff, "DelItem", buff2, sizeof( buff2) ) !=NULL){ + if(strstr(buff2,"EVDEL") != NULL){ + char work[256]; + char nbuf[256]; + + NPC_Util_GetStrFromStrWithDelim(buf, "EVENT", buff2, sizeof( buff2)); + getStringFromIndexWithDelim( buff2, ",", evcnt, work, sizeof( work)); + + if(strstr(buff,"Break")!=NULL){ + b_flg=1; + }else{ + b_flg=0; + } + + if(NPC_Util_GetStrFromStrWithDelim( buff, "NotDel", nbuf, sizeof( nbuf)) != NULL) { + NPC_EventDelItemEVDEL( meindex, talker, work, nbuf,b_flg); + }else{ + NPC_EventDelItemEVDEL( meindex, talker, work, "-1",b_flg); + } + + }else{ + if(strstr(buff,"Break")!=NULL){ + b_flg=1; + }else{ + b_flg=0; + } + + NPC_EventDelItem( meindex, talker, buff2, b_flg); + } + } + + /*--ë---*/ + if(NPC_Util_GetStrFromStrWithDelim( buff, "DelStone", buff2, sizeof( buff2) ) + !=NULL) + { + int stone; + char token[128]; + + stone = NPC_EventGetCost( meindex, talker, buff2); + + CHAR_setInt(talker,CHAR_GOLD,CHAR_getInt( talker, CHAR_GOLD) - stone); + + /*--ɷ¶˪Ի--*/ + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + sprintf(token, "%dstone", stone); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + + + /*--¼ĸةʧ ة---*/ + if(NPC_Util_GetStrFromStrWithDelim( buff, "GetRandItem", buf, sizeof( buf) ) != NULL ){ + j=1; + while( getStringFromIndexWithDelim( buf , "," , j, buff2, sizeof( buff2)) != FALSE ){ + j++; + rand_j++; + } + rand_cnt = 1; + } + + + /*-- ɧʧ ة--*/ + if(NPC_Util_GetStrFromStrWithDelim( buff, "GetItem", buf, sizeof( buf)) != NULL ){ + if(mode == 0) { + j = 1; + /*--ۼʧ ةë ʾ--*/ + while(getStringFromIndexWithDelim( buf, "," , j, buff2, sizeof(buff2)) !=FALSE ){ + j++; + } + + j--; + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( !ITEM_CHECKINDEX( itemindex) ){ + kosuucnt++; + } + } + j= j + rand_cnt; + if( kosuucnt < j ){ + NPC_MsgDisp( meindex, talker, 4); + return FALSE; + + }else{ + if(NPC_Util_GetStrFromStrWithDelim( buff, "GetRandItem", buff2, sizeof( buff2)) !=NULL) { + rand_flg = 1; + NPC_RandItemGet( meindex, talker, rand_j, buff2); + } + if(NPC_EventAddItem( meindex, talker, buf) == FALSE) return FALSE; + } + }else if(mode == 1){ + if(strstr(buff,"Break")!=NULL){ + b_flg=1; + }else{ + b_flg=0; + } + NPC_EventDelItem( meindex, talker, buf,b_flg); + } + } + + if( (NPC_Util_GetStrFromStrWithDelim( buff, "GetRandItem", buf, sizeof( buf) ) + !=NULL) && (rand_flg == 0) && mode == 0 ) + { + /*-- ¾-*/ + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex=CHAR_getItemIndex( talker , i ); + if( !ITEM_CHECKINDEX( itemindex) ){ + kosuucnt++; + } + } + /*--廥ؤ¾--*/ + if( kosuucnt == 0 ){ + NPC_MsgDisp( meindex, talker, 4); + return FALSE; + } + + + NPC_RandItemGet( meindex, talker, rand_j,buf); + } + +#ifdef _EXCHANGEMAN_REQUEST_DELPET + if( NPC_Util_GetStrFromStrWithDelim( buff, "DelPet", buff2, sizeof( buff2) ) != NULL && mode == 0 ) { + char buf4[32]; + char buf5[256]; + int i=1; + char work[256]; + int j=1; + + if(strstr(buff2,"EVDEL") != NULL){ + NPC_Util_GetStrFromStrWithDelim( buf, "EVENT", buf5, sizeof( buf5)); + getStringFromIndexWithDelim( buf5, ",",evcnt , buff2, sizeof( buff2)); + while(getStringFromIndexWithDelim( buff2, "&", j, work, sizeof( work))!=FALSE){ + j++; + if(strstr( work, "PET") != NULL) { + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheck( meindex, talker, work, 1) == FALSE) return FALSE; + }else{ + if(NPC_PetLvCheck( meindex, talker, work, 0) == FALSE) return FALSE; + } + } + } + j = 1; + while(getStringFromIndexWithDelim( buff2, "&", j, work, sizeof( work)) != FALSE){ + j++; + if(strstr( work, "PET") == NULL ) continue; + + if(strstr(work,"*") != NULL){ + int cnt=0; + int petcnt=0; + int petindex; + + getStringFromIndexWithDelim( work, "*", 2, buf4, sizeof( buf4)); + cnt = atoi(buf4); + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 1) + == FALSE) { + continue; + } + }else{ + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 0) == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker,i) == FALSE) return FALSE; + + petcnt++; + /*--϶мʸë׾--*/ + if(cnt == petcnt) break; + + } + }else{ + /*--ʸëë϶ƻئмƥʸë廯--*/ + + int petindex; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + petindex = CHAR_getCharPet( talker, i); + + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if(strstr( buff2, "EV") != NULL){ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 1) == FALSE){ + continue; + } + }else{ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 0) == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker, i) == FALSE) return FALSE; + } + } + } + + }else{ + /*--ֵ1պʸë Ȼ¾ë浤--*/ + while(getStringFromIndexWithDelim( buff2, ",", j, work, sizeof( work)) + !=FALSE) + { + j++; + /*--ʸͻȻPETë --*/ + if(strstr( work, "PET") != NULL) { + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheck( meindex, talker, work, 1) == FALSE) return FALSE; + }else{ + if(NPC_PetLvCheck( meindex, talker, work, 0) == FALSE) return FALSE; + } + } + } + j = 1; + + while(getStringFromIndexWithDelim( buff2, ",", j, work, sizeof( work)) != FALSE) + { + j++; + if(strstr(work,"*") != NULL) + { + int cnt=0; + int petcnt=0; + int petindex; + + getStringFromIndexWithDelim( work, "*", 2, buf4, sizeof( buf4)); + cnt = atoi(buf4); + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 1) == FALSE) { + continue; + } + }else{ + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 0) == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker,i) == FALSE) return FALSE; + + petcnt++; + /*--϶мʸë׾--*/ + if(cnt == petcnt) break; + } + }else{ + /*--ʸëë϶ƻئмƥʸë廯--*/ + + int petindex; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + petindex = CHAR_getCharPet( talker, i); + + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if(strstr( buff2, "EV") != NULL){ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 1) == FALSE){ + continue; + } + }else{ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 0) == FALSE) { + continue; + } + } + if(NPC_EventDelPet( meindex, talker, i) == FALSE) return FALSE; + } + } + } + } + } +#endif + return TRUE; + +} + + +/*-------------------------------------- + *¼ĸةƥʧ ةë + ------------------------------------ */ +BOOL NPC_RandItemGet(int meidex,int talker,int rand_j,char *buf) +{ + char buff2[64]; + int randitem; + int ret; + int itemindex; + char token[128]; + + if(rand_j == 0) { + print("Event:춣Ľ룬ִ"); + return FALSE; + } + + randitem = rand()%rand_j; + if(randitem == 0) randitem = rand_j; + + getStringFromIndexWithDelim(buf , "," , randitem, buff2, sizeof(buff2)) ; + + itemindex = ITEM_makeItemAndRegist( atoi( buff2)); + + if(itemindex == -1) return FALSE; + /*ʧ ةܰ( ʧ ة ľ */ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + print( "npc_exchangeman.c: additem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + + if(itemindex != -1) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventAddItem(õĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + return TRUE; + +} + + +/*---------------------------------------------------- + * ì + ----------------------------------------------------*/ +BOOL NPC_AcceptDel(int meindex,int talker,int mode ) +{ + + char buf[1024*2]; + char buff2[256]; + int rand_j = 0; + int j = 0; + int evcnt; + int b_flg = 0; + evcnt = NPC_EventFile( meindex, talker, buf); + if(evcnt == -1) return FALSE; + + /*--ɬð̻ 微ľë ƻּë --*/ +// if(NPC_EventFile(meindex,talker,buf)==FALSE) return FALSE; + + /*--ʧ ةë--*/ + if(NPC_ItemFullCheck( meindex, talker, buf, mode, evcnt) == FALSE){ + NPC_MsgDisp( meindex, talker, 4); + return FALSE; + } + + /*--ͱ --*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "DelStone", buff2, sizeof( buff2) ) + !=NULL) + { + int stone; + stone = NPC_EventGetCost( meindex, talker, buff2); + + if( (CHAR_getInt( talker, CHAR_GOLD) - stone) < 0 ) { + NPC_MsgDisp( meindex, talker, 14); + return FALSE; + } + } + + + /*--ͱ --*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetStone", buff2, sizeof( buff2) )!=NULL){ + int stone; + stone = atoi(buff2); + + if( (CHAR_getInt( talker, CHAR_GOLD) + stone) >= CHAR_getMaxHaveGold( talker) ) { + NPC_MsgDisp( meindex, talker, 13); + return FALSE; + } + } + + + /*--ʸ ëܰ--*/ + if((NPC_Util_GetStrFromStrWithDelim( buf, "pet_skill", buff2, sizeof( buff2) ) + !=NULL) && mode == 0 ){ + if(mode == 0){ + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD, 1); + NPC_PetSkillMakeStr( meindex, talker, 1); + return TRUE; + } + } + + /*--ʸë---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "DelPet", buff2, sizeof( buff2) ) != NULL) { + char buf4[32]; + char buf5[256]; + int i=1; + char work[256]; + int j=1; + + if(strstr(buff2,"EVDEL") != NULL){ + NPC_Util_GetStrFromStrWithDelim( buf, "EVENT", buf5, sizeof( buf5)); + getStringFromIndexWithDelim( buf5, ",",evcnt , buff2, sizeof( buff2)); + + + /*--ֵ1պʸë Ȼ¾ë浤--*/ + while(getStringFromIndexWithDelim( buff2, "&", j, work, sizeof( work)) + !=FALSE) + { + j++; + + /*--ʸͻȻPETë --*/ + if(strstr( work, "PET") != NULL) { + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheck( meindex, talker, work, 1) == FALSE) return FALSE; + }else{ + if(NPC_PetLvCheck( meindex, talker, work, 0) == FALSE) return FALSE; + } + } + } + j = 1; + + + while(getStringFromIndexWithDelim( buff2, "&", j, work, sizeof( work)) + != FALSE) + { + j++; + if(strstr( work, "PET") == NULL ) continue; + + if(strstr(work,"*") != NULL) + { + int cnt=0; + int petcnt=0; + int petindex; + + getStringFromIndexWithDelim( work, "*", 2, buf4, sizeof( buf4)); + cnt = atoi(buf4); + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 1) + == FALSE) { + continue; + } + }else{ + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 0) + == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker,i) == FALSE) return FALSE; + + petcnt++; + /*--϶мʸë׾--*/ + if(cnt == petcnt) break; + + } + }else{ + /*--ʸëë϶ƻئмƥʸë廯--*/ + + int petindex; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + petindex = CHAR_getCharPet( talker, i); + + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if(strstr( buff2, "EV") != NULL){ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 1) + == FALSE){ + continue; + } + }else{ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 0) + == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker, i) == FALSE) return FALSE; + } + } + } + + }else{ + + /*--ֵ1պʸë Ȼ¾ë浤--*/ + while(getStringFromIndexWithDelim( buff2, ",", j, work, sizeof( work)) + !=FALSE) + { + j++; + /*--ʸͻȻPETë --*/ + if(strstr( work, "PET") != NULL) { + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheck( meindex, talker, work, 1) == FALSE) return FALSE; + }else{ + if(NPC_PetLvCheck( meindex, talker, work, 0) == FALSE) return FALSE; + } + } + } + j = 1; + + + while(getStringFromIndexWithDelim( buff2, ",", j, work, sizeof( work)) + != FALSE) + { + j++; + if(strstr(work,"*") != NULL) + { + int cnt=0; + int petcnt=0; + int petindex; + + getStringFromIndexWithDelim( work, "*", 2, buf4, sizeof( buf4)); + cnt = atoi(buf4); + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + if(strstr( work, "EV") != NULL) { + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 1) + == FALSE) { + continue; + } + }else{ + if(NPC_PetLvCheckType2(petindex, meindex, talker, work, 0) + == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker,i) == FALSE) return FALSE; + + petcnt++; + /*--϶мʸë׾--*/ + if(cnt == petcnt) break; + + } + }else{ + /*--ʸëë϶ƻئмƥʸë廯--*/ + + int petindex; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + petindex = CHAR_getCharPet( talker, i); + + if( !CHAR_CHECKINDEX( petindex) ) continue; + + if(strstr( buff2, "EV") != NULL){ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 1) + == FALSE){ + continue; + } + }else{ + if(NPC_PetLvCheckType2( petindex, meindex, talker, work, 0) + == FALSE) { + continue; + } + } + + if(NPC_EventDelPet( meindex, talker, i) == FALSE) return FALSE; + } + } + } + } + } + + /*--ëؤ---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetStone", buff2, sizeof( buff2) ) + !=NULL) + { + int stone; + char token[128]; + + stone = atoi(buff2); + CHAR_setInt(talker,CHAR_GOLD,CHAR_getInt( talker, CHAR_GOLD) + stone); + /*--ɷ¶˪Ի--*/ + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + + sprintf( token,"õ%dstone", stone); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + + + /*--ʸëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetPet", buff2, sizeof( buff2) ) + !=NULL) + { + if(NPC_EventAddPet( meindex, talker, buff2,1) == FALSE) { + NPC_MsgDisp( meindex, talker, 10); + return FALSE; + } + } + +#ifdef _TRANS_7_NPC + if(NPC_Util_GetStrFromStrWithDelim( buf, "TRANS7", buff2, sizeof( buff2) ) + !=NULL) + { + if(NPC_EventTRANS( meindex, talker, buff2,1) == FALSE) { + NPC_MsgDisp( meindex, talker, 10); + return FALSE; + } + } +#endif +#ifdef _NPC_FUSION + // Robin add NPCȡﵰ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetEgg", buff2, sizeof( buff2) ) + !=NULL) + { + if(NPC_EventAddEgg( meindex, talker, buff2,1) == FALSE) { + print(" AddEgg_Error:%d ", __LINE__); + NPC_MsgDisp( meindex, talker, 10); + return FALSE; + } + } +#endif + /*--ʧ ةë--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "DelItem", buff2, sizeof( buff2) ) != NULL){ + if(strstr(buff2,"EVDEL") != NULL){ + char work[256]; + char nbuf[256]; + + NPC_Util_GetStrFromStrWithDelim(buf, "EVENT", buff2, sizeof( buff2)); + getStringFromIndexWithDelim( buff2, ",", evcnt, work, sizeof( work)); + + if(strstr(buf,"Break")!=NULL){ + b_flg=1; + }else{ + b_flg=0; + } + + if(NPC_Util_GetStrFromStrWithDelim( buf, "NotDel", nbuf, sizeof( nbuf)) != NULL ){ + NPC_EventDelItemEVDEL( meindex, talker, work, nbuf,b_flg); + }else{ + NPC_EventDelItemEVDEL( meindex, talker, work, "-1",b_flg); + } + }else{ + if(strstr(buf,"Break")!=NULL){ + b_flg=1; + }else{ + b_flg=0; + } + NPC_EventDelItem( meindex, talker, buff2,b_flg); + } + } + + + /*--ë---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "DelStone", buff2, sizeof( buff2) ) + !=NULL) + { + int stone; + char token[128]; + + stone = NPC_EventGetCost( meindex, talker, buff2); + + CHAR_setInt(talker,CHAR_GOLD,CHAR_getInt( talker, CHAR_GOLD) - stone); + /*--ɷ¶˪Ի--*/ + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + sprintf( token, "%dstone", stone); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + + + /*--¼ĸةʧ ةëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetRandItem", buff2, sizeof( buff2) ) + !=NULL) + { + char buf3[32]; + j = 1; + while(getStringFromIndexWithDelim(buff2 , "," , j, buf3, sizeof( buf3)) + != FALSE ) + { + j++; + rand_j++; + } + NPC_RandItemGet( meindex, talker, rand_j, buff2); + } + + + /*--ʧ ةëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetItem", buff2, sizeof( buff2) ) + !=NULL) + { + NPC_EventAddItem( meindex, talker, buff2); + } +#ifdef _SHOW_ITEM_NAME + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetShowItem", buff2, sizeof( buff2) ) + !=NULL) + { + NPC_EventAddShowItem( meindex, talker, buff2); + } +#endif + + /*--ɷ¶˪--*/ + CHAR_complianceParameter( talker ); + CHAR_send_P_StatusString( talker , + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_CHARM|CHAR_P_STRING_QUICK| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND|CHAR_P_STRING_EARTH + ); + + return TRUE; + +} + + +/*-------------------------- + * ìʸë + ---------------------------*/ +BOOL NPC_EventDelPet(int meindex,int talker, int petsel) +{ + + int petindex; + char szPet[128]; + int defpet; + char msgbuf[64]; + + int fd = getfdFromCharaIndex( talker ); + + petindex = CHAR_getCharPet( talker, petsel); + + if( !CHAR_CHECKINDEX(petindex) ) return FALSE; + + if( CHAR_getInt( talker, CHAR_RIDEPET) == petsel ) { + + //CHAR_talkToCli( talker, -1, "еij޷", CHAR_COLORYELLOW ); + //return FALSE; + + CHAR_setInt( talker, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_RIDEPET ); + CHAR_complianceParameter( talker ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( talker , CHAR_WORKOBJINDEX )); + print(" DelRidePet "); + } + print(" EventDelPet "); + + /*--ƽҷ» ئգʸëڱ --*/ + if( CHAR_getWorkInt( CONNECT_getCharaindex( fd), + CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return FALSE; + /*--ʸᆴ--*/ + defpet = CHAR_getInt( talker, CHAR_DEFAULTPET); + if(defpet == petsel){ + CHAR_setInt( talker, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + + snprintf( msgbuf,sizeof( msgbuf), "%s", + CHAR_getChar( petindex, CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORWHITE); + + // ʸë ׷ + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "EvnetDell(ɾ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + + /* */ + CHAR_setCharPet( talker, petsel, -1); + + CHAR_endCharOneArray( petindex ); + + snprintf( szPet, sizeof( szPet ), "K%d", petsel); + // ޥʸ ˪Ի + CHAR_sendStatusString( talker, szPet ); + + return TRUE; + +} + + +/*---------------------------- + * ʸëܰ + ------------------------------*/ +BOOL NPC_EventAddPet(int meindex, int talker, char *buff2,int mode) +{ + int ret; + char msgbuf[64]; + int enemynum; + int enemyid; + int i; + int petindex; + + /*--ʸ л¾--*/ + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) break; + } + + if(i == CHAR_MAXPETHAVE) return FALSE; + + + /* ¦ѼIDindexë */ + if(strstr(buff2,",") != NULL){ + char buf2[16]; + while(getStringFromIndexWithDelim( buff2, ",", i, buf2, sizeof( buf2)) + != FALSE) { + i++; + } + i--; + i = rand()%i + 1; + getStringFromIndexWithDelim( buff2, ",", i, buf2, sizeof( buf2)); + enemyid = atoi( buf2); + }else{ + enemyid = atoi( buff2); + } + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + + if( i == enemynum ) return FALSE; + + ret = ENEMY_createPetFromEnemyIndex( talker, i); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( talker, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE ) i = 0; + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + } + + petindex = CHAR_getCharPet(talker,i); + + if( !CHAR_CHECKINDEX( petindex) )return FALSE; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( talker, msgbuf ); + + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( talker, msgbuf ); + snprintf( msgbuf,sizeof( msgbuf), "õ%s", + CHAR_getChar(petindex,CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORWHITE); + + // ʸë ľ׷ + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "EventGet(õ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + + + if(mode == 0) { + /*--ìüʸ--*/ + CHAR_setInt( petindex, CHAR_ENDEVENT, 1); + } + + return TRUE; + +} + +#ifdef _TRANS_7_NPC +BOOL NPC_EventTRANS(int meindex, int talker, char *buff2,int mode) +{ + char token[128]; + int work[10]; + int Trans=CHAR_getInt(talker,CHAR_TRANSMIGRATION)+1; + if(Trans>7 || CHAR_getInt(talker,CHAR_LV)<80){ + sprintf( token, "תȼС80תʧ!"); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + return FALSE; + } +#ifdef _ADD_POOL_ITEM // WON ADD ӿɼķŵĵ + int tran_pool_item[5] = { 4, 4, 4, 4, 4 }; // ӵĵ߼ķ + int tran_pool_pet[5] = { 2, 2, 2, 2, 2}; // ӵijķ + int j,item_sum=0, pet_sum=0; + + for(j=0; j<5 ;j++){ + item_sum += tran_pool_item[j] ; + pet_sum += tran_pool_pet[j]; + } + + item_sum += 10; // ļĵ + pet_sum += 5; // ļij + +#endif + NPC_TransmigrationStatus(talker, talker, work); + NPC_TransmigrationFlg_CLS(talker, talker); + CHAR_setInt(talker ,CHAR_TRANSMIGRATION, Trans); + CHAR_setInt(talker, CHAR_LV ,1); + CHAR_setMaxExp( talker, 0); + CHAR_setInt( talker,CHAR_SKILLUPPOINT,CHAR_getInt( talker, CHAR_TRANSMIGRATION)*10); + CHAR_Skillupsend( talker ); + CHAR_setInt( talker,CHAR_RIDEPET, -1 ); + CHAR_setInt( talker , CHAR_BASEIMAGENUMBER , CHAR_getInt( talker , CHAR_BASEBASEIMAGENUMBER) ); + CHAR_sendStatusString( talker , "P"); + + CHAR_talkToCli( talker, -1, buff2, CHAR_COLORYELLOW ); + + return TRUE; +} +#endif + +#ifdef _NPC_FUSION +// Robin add NPCﵰ +BOOL NPC_EventAddEgg(int meindex, int talker, char *buff2,int mode) +{ + int ret; + char msgbuf[64]; + int enemynum; + int enemyid; + int petid; + int raise; + int i; + int petindex; + char buf2[32]; + char buf3[32]; + + print("\n !!:%s ", buff2); + + /*--ʸ л¾--*/ + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) break; + } + + if(i == CHAR_MAXPETHAVE) { + print(" AddEgg_Error:%d ", __LINE__); + return FALSE; + } + + + /* ¦ѼIDindexë */ + if(strstr(buff2,",") != NULL){ // ǷΪ + while(getStringFromIndexWithDelim( buff2, ",", i, buf2, sizeof( buf2)) + != FALSE) { + i++; + } + i--; + i = rand()%i + 1; + getStringFromIndexWithDelim( buff2, ",", i, buf2, sizeof( buf2)); + + }else{ + strcpy( buf2, buff2); + } + + getStringFromIndexWithDelim( buf2, ";", 1, buf3, sizeof( buf3)); + enemyid = atoi( buf3); // ﵰID + getStringFromIndexWithDelim( buf2, ";", 2, buf3, sizeof( buf3)); + petid = atoi( buf3); // ijID + getStringFromIndexWithDelim( buf2, ";", 3, buf3, sizeof( buf3)); + raise = atoi( buf3); // + + + // enemyidתenemybaseid + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == petid) { + break; + } + } + if( i == enemynum ) { + print(" AddEgg_Error:%d ", __LINE__); + return FALSE; + } + petid = ENEMY_getInt( i, ENEMY_TEMPNO); + + + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == enemynum ) { + print(" AddEgg_Error:%d ", __LINE__); + return FALSE; + } + + ret = ENEMY_createPetFromEnemyIndex( talker, i); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( talker, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE ) i = 0; + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + } + + petindex = CHAR_getCharPet(talker,i); + + if( !CHAR_CHECKINDEX( petindex) ) { + print(" AddEgg_Error:%d ", __LINE__); + return FALSE; + } + + // Ϊﵰ + CHAR_setInt( petindex, CHAR_FUSIONBEIT, 1); + CHAR_setInt( petindex, CHAR_FUSIONCODE, -1); + CHAR_setInt( petindex, CHAR_FUSIONRAISE, raise); + CHAR_setInt( petindex, CHAR_FUSIONINDEX, petid); + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time( NULL)); + + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( talker, msgbuf ); + + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( talker, msgbuf ); + snprintf( msgbuf,sizeof( msgbuf), "õ%s", + CHAR_getChar(petindex,CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORWHITE); + + // ʸë ľ׷ + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "EventGetEgg(õ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + + + if(mode == 0) { + /*--ìüʸ--*/ + CHAR_setInt( petindex, CHAR_ENDEVENT, 1); + } + return TRUE; + +} +#endif + +/*--------------------------- + * ì ë + -----------------------------**/ +BOOL NPC_EventDelItem(int meindex,int talker,char *buf,int breakflg) +{ + + int i = 1, j = 1, k = 1 ; + char buff3[128]; + char buf2[32]; + int itemindex; + char token[256]; + + while(getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) + !=FALSE ) + { + k++; + if(strstr(buff3,"*") != NULL) { + int itemno; + int kosuu; + int id; + int cnt=0; + + getStringFromIndexWithDelim( buff3, "*", 1, buf2, sizeof( buf2)); + itemno = atoi( buf2); + getStringFromIndexWithDelim( buff3, "*", 2, buf2, sizeof( buf2)); + kosuu = atoi( buf2); + +#ifdef _ITEM_PILENUMS + if( breakflg != 1 ) + + NPC_ActionDoPileDelItem( talker, itemno, kosuu);//жѵĴ + + else +#endif + { + for( i =0 ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex) ) { + id = ITEM_getInt( itemindex , ITEM_ID ); + if(itemno == id) { + cnt++; + LogItem( + CHAR_getChar( talker, CHAR_NAME ), // ƽҷ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), // ʧ ة į +#endif + "EventDelItem(ջصĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + + if(breakflg == 1){ + sprintf(token,"%s ",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + }else{ + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + //--ʧ ةëڽ-- + CHAR_setItemIndex( talker, i ,-1); + ITEM_endExistItemsOne(itemindex); + CHAR_sendItemDataOne( talker, i); + + if(cnt == kosuu){ + break; + } + } + } + } + } + } + else{ + /*--Ϸ įʧ ةë---*/ + for( j = 0 ; j < CheckCharMaxItem(talker) ; j++){ + itemindex = CHAR_getItemIndex( talker ,j); + + if( ITEM_CHECKINDEX( itemindex)){ + if( atoi( buff3) == ITEM_getInt( itemindex, ITEM_ID)) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventDelItem(ջصĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + if(breakflg == 1){ + sprintf(token,"%s ",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + }else{ + sprintf( token, "%s", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + /*--ʧ ةëڽ--*/ + CHAR_setItemIndex( talker, j ,-1); + ITEM_endExistItemsOne( itemindex); + /*--ɷ¶˪--*/ + CHAR_sendItemDataOne( talker, j); + } + } + } + } + } + + return TRUE; +} + +BOOL NPC_EventDelItemEVDEL(int meindex,int talker,char *buf,char *nbuf,int breakflg) +{ + + int k = 1, l = 1; + char buff3[128]; + char buf2[32]; + char buf4[32]; + + + + while(getStringFromIndexWithDelim(buf , "&" , k, buf4, sizeof(buf4)) !=FALSE ){ + int itemno; + k++; + if(strstr(buf4,"ITEM") == NULL) continue; + getStringFromIndexWithDelim(buf4 , "=" , 2, buff3, sizeof(buff3)); + + if(strstr(buff3,"*") != NULL) { + int kosuu; +#ifndef _ITEM_PILENUMS + char token[256]; + int i, itemindex, id, cnt; +#endif + getStringFromIndexWithDelim( buff3, "*", 1, buf2, sizeof( buf2)); + itemno = atoi( buf2); + getStringFromIndexWithDelim( buff3, "*", 2, buf2, sizeof( buf2)); + kosuu = atoi( buf2); + if(strstr(nbuf,"-1") == NULL){ + l = 1; + while(getStringFromIndexWithDelim(nbuf , "," , l, buf2, sizeof(buf2))){ + l++; + if(itemno == atoi( buf2)){ + l = -1; + break; + } + } + if(l == -1) continue; + } +#ifdef _ITEM_PILENUMS + NPC_ActionDoPileDelItem( talker, itemno, kosuu); +#else + cnt = 0; + for( i =0 ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex) ) { + id = ITEM_getInt( itemindex , ITEM_ID ); + if(itemno == id) { + cnt++; + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventDelItem(ջصĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + if(breakflg == 1){ + sprintf(token,"%s ",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + }else{ + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + CHAR_setItemIndex( talker, i ,-1); + ITEM_endExistItemsOne(itemindex); + CHAR_sendItemDataOne( talker, i); + if(cnt == kosuu){ + break; + } + } + } + } +#endif + }else{ +#ifndef _ITEM_PILENUMS + int j, itemindex; + char token[256]; +#endif + if(strstr(nbuf,"-1") == NULL){ + l = 1; + while(getStringFromIndexWithDelim(nbuf , "," , l, buf2, sizeof(buf2))){ + l++; + if(atoi(buff3) == atoi( buf2)){ + l = -1; + break; + } + } + if(l == -1) continue; + } + itemno = -1; +#ifdef _ITEM_PILENUMS + NPC_ActionDoPileDelItem( talker, itemno, itemno); +#else + for( j = 0 ; j < CheckCharMaxItem(talker) ; j++){ + itemindex = CHAR_getItemIndex( talker ,j); + if( ITEM_CHECKINDEX( itemindex)){ + if( atoi( buff3) == ITEM_getInt( itemindex, ITEM_ID)) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventDelItem(ջصĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + if(breakflg == 1){ + sprintf(token,"%s ",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + }else{ + sprintf( token, "%s", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + } + CHAR_setItemIndex( talker, j ,-1); + ITEM_endExistItemsOne( itemindex); + CHAR_sendItemDataOne( talker, j); + } + } + } +#endif + } + } + + return TRUE; +} + +#ifdef _SHOW_ITEM_NAME +BOOL NPC_EventAddShowItem(int meindex,int talker,char *buf) +{ + int itemID,itemindex=-1; + + char buff3[256], msgbuf[64], token[256]; + int ret; + + if( getStringFromIndexWithDelim(buf , ";" , 1, buff3, sizeof(buff3)) !=FALSE ){ + + if( CHAR_findEmptyItemBox( talker ) < 0 ){ + sprintf( msgbuf, "Ʒλ㡣" ); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORYELLOW); + return FALSE; + } + itemID = atoi( buff3); + if( itemID ) + itemindex = ITEM_makeItemAndRegist( itemID); + if(itemindex == -1) + return FALSE; + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + ITEM_endExistItemsOne( itemindex); + print ("\n ret error!!"); + return FALSE; + } + if( getStringFromIndexWithDelim(buf , ";" , 2, buff3, sizeof(buff3)) !=FALSE ){ + sprintf(token, buff3, CHAR_getChar(talker, CHAR_NAME)); + ITEM_setChar(itemindex, ITEM_EFFECTSTRING, token); + } + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( talker, ret); + } + + return TRUE; +} +#endif +/*---------------------- + * ì ëܰ] + -----------------------*/ +BOOL NPC_EventAddItem(int meindex,int talker,char *buf) +{ + + char buff3[128]; + int i = 1; + int itemindex; + char buf3[32]; + int ret; + char token[256]; + + while(getStringFromIndexWithDelim(buf , "," , i, buff3, sizeof( buff3)) + != FALSE ) + { + i++; + if(strstr( buff3, "*") != NULL) { + + int itemno; + int kosuu; + int loop = 0; + + getStringFromIndexWithDelim( buff3, "*", 1, buf3,sizeof( buf3)); + itemno = atoi( buf3); + getStringFromIndexWithDelim( buff3, "*", 2, buf3,sizeof( buf3)); + kosuu = atoi( buf3); + + for(loop = 0 ; loop < kosuu ; loop++) { + itemindex = ITEM_makeItemAndRegist( itemno); + + if(itemindex == -1) return FALSE; + /*ʧ ةܰ( ʧ ة ľ */ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + print("npc_exchange:ACCEPTadditem error itemindex[%d]\n",itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + + if(itemindex != -1) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventAddItem(õĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + sprintf( token, "õ%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + } + }else{ + itemindex = ITEM_makeItemAndRegist( atoi( buff3)); + + if(itemindex == -1) return FALSE; + + + /*ʧ ةܰ( ʧ ة ľ */ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + print( "npc_exchange.c: ACCEPTadditem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + + if(itemindex != -1) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventAddItem(õĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + sprintf(token,"õ%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + } + } + + return TRUE; +} + + +/*--------------------------------- + *ë ƻ¼ë + ------------- ---------------------*/ +int NPC_EventFile(int meindex,int talker,char *arg) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[256]; + char buf[1024*2]; + int i=1; + int EvNo=0; + int evch; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + + print("GetArgStrErr"); + return -1; + } + + /*ɬð̻ë*/ + while(getStringFromIndexWithDelim( argstr, "EventEnd", i, buf,sizeof( buf)) + != FALSE) + { + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 0); + i++; + /*--ìϼë--*/ + NPC_Util_GetStrFromStrWithDelim( buf, "EventNo", buff2,sizeof( buff2) ); + EvNo = atoi( buff2); + + /*--׷ºë浤ƥì ƻݳ--*/ + if(NPC_EventCheckFlg( talker, EvNo) == TRUE) continue; + + /*--ƽë浤--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"Pet_Name", buff2,sizeof( buff2) ) + != NULL) + { + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, 1); + } + /*--ƽë浤--*/ + if(NPC_Util_GetStrFromStrWithDelim( buf,"KeyWord", buff2,sizeof( buff2) ) + != NULL) + { + if(CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) != i ) continue; + } + + evch = NPC_ExChangeManEventCheck( meindex, talker, buf); + + if(evch != -1) { + /*--ì--*/ +// if(NPC_ExChangeManEventCheck( meindex, talker, buf) == TRUE) { + strcpysafe(arg, sizeof( buf) ,buf); + return evch; + } + } + + return -1; + +} + + +/*--------------------------------- + * ʧ ةͷë浤 + -----------------------------------*/ +BOOL NPC_EventReduce(int meindex,int talker,char *buf) +{ + + char buf2[512]; + char buf3[256]; + int id = 0; + int i; + int itemindex; + int itemno; + int kosuu; + int cnt = 0; + + getStringFromIndexWithDelim( buf, "=", 2, buf2, sizeof( buf2)); + getStringFromIndexWithDelim( buf2, "*", 1, buf3, sizeof( buf3)); + itemno = atoi( buf3); + getStringFromIndexWithDelim( buf2, "*", 2, buf3, sizeof( buf3)); + kosuu = atoi( buf3); + + for( i = 0 ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex) ){ + id = ITEM_getInt( itemindex ,ITEM_ID); + if(itemno == id){ + //change add ӶԶѵж + int pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + if( pilenum ) + cnt+=pilenum; + else + cnt++; + + if(cnt >= kosuu){ + return TRUE; + } + } + } + } + + return FALSE; + +} + +/*---------------------------------- + *ʸ嵩ƽë + ----------------------------------*/ +void NPC_EventPetSkill( int meindex, int talker, char *data) +{ + + int skill; + int pet; + int slot; + int cost; + int skillID = 0; + char buf[64]; + char argstr[1024]; + char msg[512]; + int petindex; + char msgbuf[128]; + int fd = getfdFromCharaIndex( talker ); + int evcnt; + if (data == NULL |strlen(data)==0) return; + + if( NPC_Util_CharDistance( talker, meindex ) > 2) { + return; + } + + evcnt = NPC_EventFile( meindex, talker, argstr); + + if(evcnt == -1) return; + + /*--ɬð̻ k ë ƻּë --*/ +// if(NPC_EventFile( meindex, talker, argstr) == FALSE) return ; + + /*ͷʧ߯Ȼ·--*/ + /* ëϷ־( į) ʸ( į) + ( į) */ + makeStringFromEscaped( data); + + /*--Ի--*/ + getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)); + skill = atoi( buf); + getStringFromIndexWithDelim( data, "|", 2, buf, sizeof( buf)); + pet = atoi( buf); + getStringFromIndexWithDelim( data, "|", 3, buf ,sizeof( buf)); + slot = atoi(buf); + getStringFromIndexWithDelim( data, "|", 4, buf, sizeof( buf)); + cost = atoi( buf); + + /*--ƽ ë--*/ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", + msg, sizeof( msg)) != NULL) + { + getStringFromIndexWithDelim( msg, ",", skill, buf ,sizeof( buf)); + skillID = atoi( buf); + } + slot--; + + + petindex = CHAR_getCharPet( talker, pet-1); + + if(petindex == -1){ + print("PetindexErr"); + return; + } + + /*--ƽҷ» ئգʸëڱ --*/ + if( CHAR_getWorkInt( CONNECT_getCharaindex( fd), + CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; + + /*--ʸ ë--*/ + CHAR_setPetSkill( petindex, slot, skillID); + + /*--ëӼ--*/ + CHAR_setInt( talker, CHAR_GOLD, (CHAR_getInt( talker, CHAR_GOLD) - cost)); + + snprintf( msgbuf, sizeof( msgbuf ), "W%d",pet-1); + + // ޥʸ ë˪Ի + CHAR_sendStatusString( talker, msgbuf ); + + CHAR_sendStatusString( talker, "P"); + +} + + +/*---------------------------------------- + * ʧ ةо +----------- ------------------------------*/ +BOOL NPC_ItemFullCheck(int meindex,int talker,char *buf,int mode,int evcnt) +{ + + char buff2[256]; + int i = 1,j = 1; + int maxitem = 0; + int kosuucnt = 0; + int itemindex; + char buf3[256]; + int rand_j = 0; + int rand_cnt = 0; + char nbuf[256]; + char buff6[16]; + int l = 1; + + if(NPC_Util_GetStrFromStrWithDelim( buf, "DelItem", buff2, sizeof( buff2) ) != NULL ){ + if(strstr(buff2,"EVDEL") != NULL){ + char buff4[64]; + char buff5[32]; + + i = 1; + NPC_Util_GetStrFromStrWithDelim( buf, "EVENT", buff2, sizeof( buff2)); + getStringFromIndexWithDelim(buff2, "," , evcnt, buf3, sizeof(buf3)); + + while(getStringFromIndexWithDelim(buf3, "&" , j, buff4, sizeof(buff4))){ + j++; + if(strstr(buff4,"ITEM") != NULL) { + if(strstr(buff4,"*") != NULL) { + int itemno; + + l = 1; + getStringFromIndexWithDelim(buff4, "=" , 2, buff5, sizeof(buff5)); + getStringFromIndexWithDelim(buff5, "*" , 1, buff6, sizeof(buff6)); + itemno = atoi(buff6); + + if(NPC_Util_GetStrFromStrWithDelim( buf, "NotDel", nbuf, sizeof( nbuf)) !=NULL){ + while(getStringFromIndexWithDelim(nbuf , "," , l,buff6, sizeof(buff6))) + { + l++; + if(itemno == atoi( buff6)) + { + l = -1; + break; + } + } + } + if(l == -1) continue; + getStringFromIndexWithDelim(buff5, "*" , 2, buff6, sizeof(buff6)); + maxitem -= atoi( buff6); + }else{ + getStringFromIndexWithDelim(buff4, "=" , 2, buff5, sizeof(buff5)); + l = 1; + + if(NPC_Util_GetStrFromStrWithDelim( buf, "NotDel", nbuf, sizeof( nbuf)) + !=NULL){ + while(getStringFromIndexWithDelim(nbuf , "," , l,buff6, sizeof(buff6))) { + l++; + if(atoi(buff5) == atoi( buff6)){ + l = -1; + break; + } + } + } + if(l == -1) continue; + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ) { + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex)) { + if(atoi( buff5) == ITEM_getInt( itemindex, ITEM_ID)) { + maxitem--; + } + } + } + } + } + } + }else{ + char buff3[128]; + i = 1; + while(getStringFromIndexWithDelim(buff2, "," , i, buff3, sizeof(buff3)) !=FALSE ){ + i++; + if(strstr( buff3, "*") != NULL){ + getStringFromIndexWithDelim( buff3, "*", 2, buf3, sizeof( buf3)); + maxitem -= atoi( buf3); + }else{ + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ) { + itemindex=CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX( itemindex)) { + if(atoi( buff3) == ITEM_getInt( itemindex, ITEM_ID)) { + maxitem--; + } + } + } + } + } + + } + } + + if(NPC_Util_GetStrFromStrWithDelim( buf, "GetRandItem", buff2, sizeof( buff2) ) !=NULL && mode == 0){ + j = 1; + while(getStringFromIndexWithDelim(buff2 , "," , j, buf3, sizeof( buf3)) !=FALSE ){ + j++; + rand_j++; + } + rand_cnt = 1; + for( i = CHAR_STARTITEMARRAY ; i +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_familyman.h" +#include "family.h" +#include "autil.h" +extern int familyNumTotal; +extern char familyListBuf[MAXFAMILYLIST]; + +char sendbuf[1024]; +char buf[1024]; +char subbuf[128]; +int i, j; + +/* + * ɬýľūëNPC + * ƽʧìҡئľ¾֣ + * + */ + +struct { + int windowno; + int windowtype; + int buttontype; + int takeitem; + int giveitem; + char message[4096]; +}w; + +struct { + BOOL use; + int checkhaveitem; + int checkhaveitemgotowin; + int checkdonthaveitem; + int checkdonthaveitemgotowin; + int warp; + int battle; + int gotowin; +}buttonproc[13]; /* ok,cancel, yes,no,prev,next ݼ */ + + + + + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; +static void NPC_Familyman_selectWindow( int meindex, int toindex, int num); +static BOOL NPC_Familyman_readData( int meindex, int windowno, BOOL chkflg); +static int NPC_Familyman_restoreButtontype( char *data ); + +/********************************* +* +*********************************/ +BOOL NPC_FamilymanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + //int i; + //char secondToken[1024]; + + // Robin test + // print(" familyman_Init "); + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", buf, sizeof( buf)) + == NULL ) + { + print( "familyman:ûָ趨ĵ \n"); + return FALSE; + } + /* ݱɬ÷ëƻ֧ */ + if( !NPC_Familyman_readData( meindex, -1, TRUE) ) { + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWINDOWMAN ); + + return TRUE; +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_FamilymanTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + NPC_Familyman_selectWindow( meindex, talkerindex, 1 ); + +} +/********************************* +* έľݼ +*********************************/ +void NPC_FamilymanLooked( int meindex , int lookedindex) +{ + + //print(" Look:me:%d,looked:%d ",meindex,lookedindex); + NPC_Familyman_selectWindow( meindex, lookedindex,1 ); + +} + +static void NPC_Familyman_selectWindow( int meindex, int toindex, int num) +{ + + int fd; + char buf[256]; + + /* 帲ƻ ɱ */ + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* */ + if( !NPC_Util_charIsInFrontOfChar( toindex, meindex, 1 )) return; + + if( !NPC_Familyman_readData( meindex, num, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + + fd = getfdFromCharaIndex( toindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + + } +} + +void NPC_FamilymanWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) + +{ + + int button = -1; + char buf[256]; + + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + // CoolFish Add For Check Old Leader Del Family + if(seqno == CHAR_WINDOWTYPE_FAMILYMAN_OUT) + { + int fd = getfdFromCharaIndex( talkerindex); + if(select == WINDOW_BUTTONTYPE_YES) + FAMILY_Leave( fd, talkerindex, "E|1"); + return; + } + // CoolFish End + + /* ū įë */ + if( !NPC_Familyman_readData( meindex, seqno - 100, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + /* ʾëƩ */ + if( w.windowtype == WINDOW_MESSAGETYPE_SELECT ) { + button = atoi( data)+5; + if( button > 12 ) { + print( "familyman:invalid button[%d]\n", button); + return; + } + } + else if( select & WINDOW_BUTTONTYPE_OK) button = 0; + else if( select & WINDOW_BUTTONTYPE_CANCEL) button = 1; + else if( select & WINDOW_BUTTONTYPE_YES) button = 2; + else if( select & WINDOW_BUTTONTYPE_NO) button = 3; + else if( select & WINDOW_BUTTONTYPE_PREV) button = 4; + else if( select & WINDOW_BUTTONTYPE_NEXT) button = 5; + else { + print( "familyman:invalid button[%d]\n", select); + return; + } + if( buttonproc[button].use == TRUE ) { + int fd; + int newwin = -1; + + fd = getfdFromCharaIndex( talkerindex); + + /* ʾ巽Ȼ ëԻ */ + if( newwin == -1 ) { + newwin = buttonproc[button].gotowin; + } + + // Robin + // + if( newwin == 5 ) { + if( CHAR_getInt( talkerindex, CHAR_FMINDEX ) > 0 ) + { + //CHAR_talkToCli( talkerindex, -1, "ʸ񲻷Ѿ塣", CHAR_COLORWHITE ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\nܱǸรѾˣ", buf, sizeof(buf))); + return; + } + if( (CHAR_getInt( talkerindex, CHAR_TRANSMIGRATION ) == 0) + && (CHAR_getInt( talkerindex, CHAR_LV) < 30) ) + { + //CHAR_talkToCli( talkerindex, -1, "ܱǸȼ㡣", CHAR_COLORWHITE ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\nܱǸรĵȼ㣡", buf, sizeof(buf))); + return; + } + + if( !NPC_EventCheckFlg( talkerindex, 4 ) ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\nܱǸรɳУ", buf, sizeof(buf))); + return; + } + + if( CHAR_getInt( talkerindex, CHAR_GOLD ) < 10000 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\nܱǸรѲ㣡", buf, sizeof(buf))); + return; + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_FAMILYADD, WINDOW_BUTTONTYPE_NONE, CHAR_WINDOWTYPE_FAMILYMAN_ADD, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), "Hello!!" ); + + return; + } + // б , + if( newwin == 6 ) + { + /* + strcpy( buf, ""); + j = 0; + for( i=1 ; i<=8 ; i++ ) { + if( i > familyNumTotal ) break; + if( getStringFromIndexWithDelim( familyListBuf, "|", i, subbuf, + sizeof(subbuf) ) == FALSE) break; + strcat( buf, "|" ); + strcat( buf, subbuf ); + j++; + } + + sprintf( sendbuf, "S|F|%d|%d|%d%s", familyNumTotal, 1, j, buf ); + //print(" FL:%s ", sendbuf ); + lssproto_FM_send( fd, sendbuf ); + */ + + //saacproto_ACShowFMList_send( acfd ); + + FAMILY_Detail( fd, talkerindex, "S|F|1|0" ); + return; + + } + // ˳ + if( newwin == 7 ) + { + if( CHAR_getInt( talkerindex, CHAR_FMINDEX ) == -1 ) { + // CHAR_talkToCli( talkerindex, -1, "㻹δκμѽ", CHAR_COLORWHITE ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\nܱǸร㻹ûмκμѽ", buf, sizeof(buf))); + return; + } + + //if (CHAR_getInt(talkerindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER) { + // CHAR_talkToCli( talkerindex, -1, "峤....", CHAR_COLORWHITE ); + // return; + //} + + print(" WN2FM "); + + // CoolFish Change for old leader del family check + if(CHAR_getInt(talkerindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER) + { + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, CHAR_WINDOWTYPE_FAMILYMAN_OUT, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + makeEscapeString("\n峤...\n\nɢ˾޷پȻࡣ\n\nȷҪɢ",buf, sizeof(buf))); + return; + } + else + FAMILY_Leave( fd, talkerindex, "E|1"); + // CoolFish Change End + + return; + } + + if( !NPC_Familyman_readData( meindex, newwin, FALSE) ) { + print( "familyman:readdata error\n"); + return; + } + //fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } + + + + } +} +/* + * ɬð̻ë ƥ϶ýľwindownoë + * + * ¦ѡ + * meindex int NPCcharaindex + * windowno int ū į + * + */ +static BOOL NPC_Familyman_readData( int meindex, int windowno, BOOL chkflg) +{ + + int i; + int linenum = 0; + int endflg = FALSE; + int buttonendflg; + int winno = -1; + int buttonconfmode; + int b_mode; + int selectnum ; + int messagepos; + BOOL errflg = FALSE; + BOOL readflg = TRUE; + FILE *fp; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char filename[64]; + char opfile[128]; + char line[1024]; + char firstToken[1024]; + char secondToken[1024]; + + /* ūɬë Ի հ */ + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + /* ɬð̻ */ + NPC_Util_GetStrFromStrWithDelim( argstr, "conff", filename, sizeof( filename)); + + sprintf( opfile, "%s/", getNpcdir( ) ); + strcat( opfile, filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", opfile); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( opfile, "r"); +} + if( fp == NULL ) { + print( "familyman:file open error [%s]\n", opfile); + return FALSE; + } + while( readflg == TRUE ) { + endflg = FALSE; + buttonendflg = TRUE; + buttonconfmode = FALSE; + selectnum = 0; + messagepos = 0; + winno = -1; + b_mode = -1; + errflg = FALSE; + + /* */ + w.windowno = -1; + w.windowtype = -1; + w.buttontype = -1; + w.takeitem = -1; + w.giveitem = -1; + w.message[0] = '\0'; + + for( i = 0; i < arraysizeof( buttonproc); i ++ ) { + buttonproc[i].use = FALSE; + buttonproc[i].checkhaveitem = -1; + buttonproc[i].checkhaveitemgotowin = -1; + buttonproc[i].checkdonthaveitem = -1; + buttonproc[i].checkdonthaveitemgotowin = -1; + buttonproc[i].warp = -1; + buttonproc[i].battle = -1; + buttonproc[i].gotowin = -1; + } + + while( 1) { + char buf[256]; + int ret; + if( !fgets( line, sizeof( line), fp)){ + readflg = FALSE; + break; + } +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + + /* 춪 */ + if( line[0] == '#' || line[0] == '\n') continue; + /* ݱ */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) strcpy( line, buf); + + /* delim "=" ƥ (1)ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, + sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, + sizeof( secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + + if( strcasecmp( firstToken, "winno") == 0 ) { + if( winno != -1 ) { + print( "familyman:winnoȴ¶winno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + readflg = FALSE; + break; + } + /* ūNoë */ + winno = atoi( secondToken); + continue; + } + /* ūNo Ȼئݼ淴 */ + if( winno == -1 ) { + print( "familyman:winno δ壬ȴ趨\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = FALSE; + break; + } + /* ūNo ݷë + * ľ½ */ + if( (chkflg == FALSE && winno == windowno )|| + chkflg == TRUE) + { + if( buttonconfmode == TRUE ) { + if( strcasecmp( firstToken, "gotowin") == 0 ) { + buttonproc[b_mode].gotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkhaveitem") == 0 ) { + buttonproc[b_mode].checkhaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "haveitemgotowin") == 0 ) { + buttonproc[b_mode].checkhaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkdonthaveitem") == 0 ) { + buttonproc[b_mode].checkdonthaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "donthaveitemgotowin") == 0 ) { + buttonproc[b_mode].checkdonthaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "endbutton") == 0 ) { + if( buttonproc[b_mode].gotowin == - 1 ) { + if( buttonproc[b_mode].checkhaveitem == -1 && + buttonproc[b_mode].checkdonthaveitem == -1) + { + errflg = TRUE; + } + else { + /* оȵƥɬýľľ */ + if( !((buttonproc[b_mode].checkhaveitem != -1 && + buttonproc[b_mode].checkhaveitemgotowin != -1) + || (buttonproc[b_mode].checkdonthaveitem != -1 && + buttonproc[b_mode].checkdonthaveitemgotowin != -1))) + { + errflg = TRUE; + } + } + } + + if( errflg == TRUE) { + print( "familyman: Ҳgotowin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = TRUE; + break; + } + buttonproc[b_mode].use = TRUE; + buttonconfmode = FALSE; + buttonendflg = TRUE; + } + } + else { + + w.windowno = winno; + /* ūɬ */ + if( strcasecmp( firstToken, "wintype") == 0 ) { + w.windowtype = atoi( secondToken); + } + /* ʾɬ */ + else if( strcasecmp( firstToken, "buttontype") == 0 ) { + w.buttontype = NPC_Familyman_restoreButtontype( secondToken); + } + /* getitemɬ */ + else if( strcasecmp( firstToken, "takeitem") == 0 ) { + w.takeitem = atoi( secondToken); + } + /* giveitemɬ */ + else if( strcasecmp( firstToken, "giveitem") == 0 ) { + w.giveitem = atoi( secondToken); + } + /* messageɬ */ + else if( strcasecmp( firstToken, "message") == 0 ) { + if( messagepos == 0 ) { + strcpy( w.message, secondToken); + messagepos = strlen( w.message); + } + else { + w.message[messagepos]='\n'; + messagepos++; + strcpy( &w.message[messagepos], secondToken); + messagepos+=strlen(secondToken); + } + } + /* ʾëݼɬ */ + else if( strcasecmp( firstToken, "okpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 0; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "cancelpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 1; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "yespressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 2; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nopressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 3; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "prevpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 4; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nextpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 5; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "selected") == 0 ) { + buttonconfmode = TRUE; + b_mode = 6 + selectnum; + buttonendflg = FALSE; + selectnum ++; + } + /* ɬñδԻ */ + else if( strcasecmp( firstToken, "endwin") == 0 ) { + endflg = TRUE; + if( chkflg == FALSE) { + readflg = FALSE; + } + break; + } + else { + print( "familyman:趨DzܵIJ\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + } + } + } + else { + if( strcasecmp( firstToken, "endwin") == 0 ) { + winno = -1; + } + } + } + if( buttonendflg == FALSE) { + print( "familyman: Ҳendbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( winno != -1 ) { + if( w.windowtype == -1 ) { + print( "familyman: Ҳwintype\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( w.buttontype == -1 ) { + print( "familyman: Ҳbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( strlen( w.message) == 0 ) { + print( "familyman: Ҳmessage\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + } + } + fclose( fp); + + if( chkflg == FALSE && w.windowno == -1 ) { + print( "familyman: Ҳָwindowno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( winno != -1 && endflg == FALSE) { + print( "familyman: Ҳendwin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( errflg == TRUE) return FALSE; + + return TRUE; +} +/* + * buttontype=ƥ϶ ٯ ëѰ £ + * + */ +static int NPC_Familyman_restoreButtontype( char *data ) +{ + int ret = 0; + int rc; + int i; + char buff[1024]; + + for( i = 1; ; i ++ ) { + rc = getStringFromIndexWithDelim( data, "|", i, buff, + sizeof( buff ) ); + if( rc == FALSE) break; + if( strcasecmp( buff, "ok") == 0 ) { + ret |= WINDOW_BUTTONTYPE_OK; + } + else if( strcasecmp( buff, "cancel") == 0 ) { + ret |= WINDOW_BUTTONTYPE_CANCEL; + } + else if( strcasecmp( buff, "yes") == 0 ) { + ret |= WINDOW_BUTTONTYPE_YES; + } + else if( strcasecmp( buff, "no") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NO; + } + else if( strcasecmp( buff, "prev") == 0 ) { + ret |= WINDOW_BUTTONTYPE_PREV; + } + else if( strcasecmp( buff, "next") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NEXT; + } + } + if( ret == 0 ) { + ret = atoi( data); + } + return ret; +} + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmchallenge.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmchallenge.c new file mode 100644 index 0000000..e02b1bc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmchallenge.c @@ -0,0 +1,730 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "handletime.h" +#include "npc_fmchallenge.h" +#include "family.h" + +// ȫļ pk +enum { + NPC_WORK_ID = CHAR_NPCWORKINT1, // ǼԱ ID, 0 ʼ +}; + +enum { + CHAR_WORK_PAGE = CHAR_WORKSHOPRELEVANT, // ҳ + CHAR_WORK_DUELTIME = CHAR_WORKSHOPRELEVANTSEC, // ѡ pk ʱ +}; + +#define SCHEDULEFILEDIR "./Schedule/" + +void NPC_LoadPKSchedule(int meindex); // Load schedule from disk +void NPC_SavePKSchedule(int meindex); // save schedule to disk +// ų̱ data +void NPC_LIST_gendata(int meindex, int talkerindex, int page, char *buf, int size); +// ѡ data +void NPC_SELECT_gendata(int meindex, int page, char *buf, int size); +// ųϸ data +void NPC_DETAIL_gendata(int meindex, char *buf, int size, int dueltime); + +BOOL NPC_SchedulemanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int meid; + int interval; + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEFMSCHEDULEMAN ); + CHAR_setWorkInt ( meindex, NPC_WORK_PREVIOUSCHECKTIME, -1); + + // + NPC_Util_GetArgStr(meindex, argstr, sizeof(argstr)); + meid = NPC_Util_GetNumFromStrWithDelim(argstr, "id" ); + if ((meid<0) || (meid>=MAX_SCHEDULEMAN)) { + print("SCHEDULEMAN init error: invalid ID(%d)\n",meid); + meid=0; + } + CHAR_setWorkInt(meindex, NPC_WORK_ID, meid); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "loopinterval" ); + if ((interval<100) || (interval>10000)) interval=1000; + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "challengetimeout"); + if ((interval<60) || (interval>60*60)) interval=20*60; + CHAR_setWorkInt(meindex, NPC_WORK_CHALLENGETIMEOUT, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "settingtimeout"); + if ((interval<10) || (interval>60*60)) interval=60; + CHAR_setWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "fightinterval"); + if ((interval<5) || (interval>60)) interval = 50; + CHAR_setWorkInt(meindex, NPC_WORK_FIGHTINTERVAL, interval); + + NPC_LoadPKSchedule(meindex); + + return TRUE; +} + +void NPC_SchedulemanTalked(int meindex, int talkerindex, char *msg, int color) +{ +// CHAR_talkToCli(talkerindex, meindex, "ãǼУ˵ǼԱ", color); + char buf[4096]; + int fd; + + if (NPC_Util_CharDistance(meindex, talkerindex) > 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, 0); + NPC_LIST_gendata(meindex, talkerindex, 0, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); +} + +void NPC_SchedulemanWindowTalked(int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int page; + int buttontype; + char buf[4096],token[256]; + int fd,i,dt,a; + int fmpks_pos; + + if (NPC_Util_CharDistance(meindex,talkerindex) > 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + +// print("seqno=%d select=%d data=%s\n", seqno,select,data); + + switch (seqno) { + case CHAR_WINDOWTYPE_SCHEDULEMAN_START: + switch (select) { + case WINDOW_BUTTONTYPE_NEXT: + case WINDOW_BUTTONTYPE_PREV: + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE) + + MAXSCHEDULEINONEWINDOW + * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_CANCEL; + if (page<0) { + page=0; + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_CANCEL; + } + if (page>MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW) { + page=MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW; + buttontype=WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_CANCEL; + } + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, page); + // Send WN + NPC_LIST_gendata(meindex, talkerindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case WINDOW_BUTTONTYPE_OK: + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1)) { + // ֻѳ峤ʹýһĹ (趨ġͬ) + + // decide: send family list or detail or accept + dt=atoi(data); + for (i=0; iMAXFAMILYINONEWINDOW) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + break; + case FMPKS_FLAG_CHALLENGE: + { // 峤Ͷͬ pk˹ + int tkfmindex=CHAR_getInt(talkerindex, CHAR_FMINDEX); + if (tkfmindex==fmpks[fmpks_pos+i].host_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SETTING; + fmpks[fmpks_pos+i].setting_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT); + // ͳϸб + CHAR_setWorkInt(talkerindex, CHAR_WORK_DUELTIME, dt); + NPC_DETAIL_gendata(meindex, buf, sizeof(buf), dt); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_DETAIL, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } else if (tkfmindex==fmpks[fmpks_pos+i].guest_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SCHEDULED; + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_OK; + if (page<0) { + page=0; + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_OK; + } + if (page>MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW) { + page=MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW; + buttontype=WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_OK; + } + CHAR_talkToCli(talkerindex, meindex, + "ļѾս", CHAR_COLORWHITE); + // ͳ list + NPC_LIST_gendata(meindex, talkerindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + break; + case FMPKS_FLAG_SETTING: + { // 峤 + int tkfmindex=CHAR_getInt(talkerindex, CHAR_FMINDEX); + if (tkfmindex==fmpks[fmpks_pos+i].host_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SETTING; + fmpks[fmpks_pos+i].setting_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT); + // ͳϸб + CHAR_setWorkInt(talkerindex, CHAR_WORK_DUELTIME, dt); + NPC_DETAIL_gendata(meindex, buf, sizeof(buf), dt); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_DETAIL, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + } + break; + } + } + NPC_SavePKSchedule(meindex); + } else { + + if (CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)!=FMMEMBER_LEADER) { + CHAR_talkToCli(talkerindex, meindex, + "ֻ峤ԤԼУม", CHAR_COLORWHITE); + } else if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)!=1) { + CHAR_talkToCli(talkerindex, meindex, + "ļ廹ûʽม", CHAR_COLORWHITE); + } + } + + break; + } + break; + case CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT: + switch (select) { + case WINDOW_BUTTONTYPE_PREV: + case WINDOW_BUTTONTYPE_NEXT: + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE) + + MAXFAMILYINONEWINDOW + * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV; + if (page<1) { + page=1; + buttontype=WINDOW_BUTTONTYPE_NEXT; + } + if (page>familyNumTotal-MAXFAMILYINONEWINDOW+1) { + page=familyNumTotal-MAXFAMILYINONEWINDOW+1; + buttontype=WINDOW_BUTTONTYPE_PREV; + } + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, page); + // Send WN + NPC_SELECT_gendata(meindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case WINDOW_BUTTONTYPE_OK: +#ifdef _FMVER21 + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && +#else + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_MEMBER) && +#endif + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1)) { + dt=CHAR_getWorkInt(talkerindex, CHAR_WORK_DUELTIME); + for (i=0; i0) && (a<=40)) fmpks[fmpks_pos+i].prepare_time=a; + } + // + if (getStringFromIndexWithDelim(data,"|",5,token,sizeof(token))) { + a=atoi(token); + if ((a>0) && (a<=50)) fmpks[fmpks_pos+i].max_player=a; + } + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_CHALLENGE; + fmpks[fmpks_pos+i].challenge_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_CHALLENGETIMEOUT); + CHAR_talkToCli(talkerindex, meindex, + "ս趨ɡ", CHAR_COLORWHITE); + } + break; + case WINDOW_BUTTONTYPE_CANCEL: + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_NONE; + CHAR_talkToCli(talkerindex, meindex, + "ս", CHAR_COLORWHITE); + break; + } + NPC_SavePKSchedule(meindex); + } + } + } + } + break; + } +} + +void NPC_SchedulemanLoop(int meindex) +{ +// int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + +/* + print("Scheduleman: fmpks_pos=%d dueltime=%d host=%s guest=%s\n", + fmpks_pos, fmpks[fmpks_pos].dueltime, fmpks[fmpks_pos].host_name, fmpks[fmpks_pos].guest_name); +*/ + + NPC_RemoveExpiredBattle(meindex); + NPC_ProcessTimeout(meindex); +} + +// Ƴڵս +void NPC_RemoveExpiredBattle(int meindex) +{ + struct tm tm1; + int keeptime; + int i,expired=-1; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + int prevckt = CHAR_getWorkInt(meindex, NPC_WORK_PREVIOUSCHECKTIME); + int fin = CHAR_getWorkInt(meindex, NPC_WORK_FIGHTINTERVAL); + int h,d; + + // Ŀǰʱ̵׼ȥƳڵų + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); +/* + if (tm1.tm_hour==0) + keeptime=0; + else + keeptime=(tm1.tm_hour-1)*100 + tm1.tm_min; +*/ + if (tm1.tm_min=0) { + // ƶųȡѾʧЧų + for (i=expired+1; i=60 ) h=h+100-60; + if (h>=2400) { + h = h-2400; + d = 10000; + } + fmpks[fmpks_pos+i].dueltime=d+h; + } + } +} + +// timeout +void NPC_ProcessTimeout(int meindex) +{ + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + + for (i=0; i=0) { + fmpks[fmpks_pos+i].challenge_timeout--; + if (fmpks[fmpks_pos+i].challenge_timeout<0) { + fmpks[fmpks_pos+i].host_index = -1; + strcpy(fmpks[fmpks_pos+i].host_name, "-1"); + fmpks[fmpks_pos+i].guest_index = -1; + strcpy(fmpks[fmpks_pos+i].guest_name, "-1"); + fmpks[fmpks_pos+i].prepare_time = -1; + fmpks[fmpks_pos+i].max_player = -1; + fmpks[fmpks_pos+i].flag=-1; + } + } + } + if (fmpks[fmpks_pos+i].flag==FMPKS_FLAG_SETTING) { + if (fmpks[fmpks_pos+i].setting_timeout>=0) { + fmpks[fmpks_pos+i].setting_timeout--; + if (fmpks[fmpks_pos+i].setting_timeout<0) { + fmpks[fmpks_pos+i].host_index = -1; + strcpy(fmpks[fmpks_pos+i].host_name, "-1"); + fmpks[fmpks_pos+i].guest_index = -1; + strcpy(fmpks[fmpks_pos+i].guest_name, "-1"); + fmpks[fmpks_pos+i].prepare_time = -1; + fmpks[fmpks_pos+i].max_player = -1; + fmpks[fmpks_pos+i].flag=-1; + } + } + } + } +} + +// , һֻܰһս +BOOL NPC_AlreadyScheduled(int meindex, int talkerindex) +{ + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + int tkfmindex = CHAR_getInt(talkerindex, CHAR_FMINDEX); + int flag=1; + + for (i=0; i=FMPKS_FLAG_SCHEDULED) { + if (fmpks[fmpks_pos+i].host_index==tkfmindex) return TRUE; + } else if (fmpks[fmpks_pos+i].flag!=FMPKS_FLAG_NONE) { + if (flag==1) flag=0; else return TRUE; + } + } + return FALSE; +} + +// ȡ schedule +void NPC_LoadPKSchedule(int meindex) +{ + char filename[256],tmp[4096],token[256]; + FILE *f; + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + + snprintf(filename,sizeof(filename), "%s%d_%d_%d", + SCHEDULEFILEDIR, CHAR_getInt(meindex, CHAR_FLOOR), + CHAR_getInt(meindex, CHAR_X), + CHAR_getInt(meindex, CHAR_Y) ); + + if( ! (f=fopen( filename, "r" )) ){ // create new schedule file + f = fopen( filename, "w" ); + if( !f ){ + print( "ERROR:Can't create Schedule file %s!\n",filename ); + return; + } + for (i=0; i=MAX_SCHEDULE)) return; + + // ¼Ŀǰʱ + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + sprintf(buf, "%d|", tm1.tm_hour*100 + tm1.tm_min); + + for (i=page; i +#include +#include "char.h" +#include "object.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npcutil.h" +#include "handletime.h" +#include "npc_fmdengon.h" +#include "family.h" +#include "npc_scheduleman.h" + +#define DENGONFILELINENUM 35 // ϱ +#define FMSDENGONFILELINENUM 140 // ԰ϱ +#define DENGONFILEENTRYSIZE 128 // ĴС +#ifdef _NEW_MANOR_LAW +#define MESSAGEINONEWINDOW 10 // ÿҳʾı +#else +#define MESSAGEINONEWINDOW 7 // ÿҳʾı +#endif +#define FMMAXNUM 1000 // ֵ +#define FM_MEMBERLIST 1 // Աб (ܱİ) +#define FM_MEMBERMEMO 2 // (ܱİ) +#define FM_FMMEMO 3 // ֮԰ (ܱİ) +#define FM_FMPOINT 4 // ݵ (ܱİ) +#define FM_FMDPTOP 5 // ǿ߱ (ܱİ) +#ifdef _FM_FMPOINTPK_LIST +#define FM_FMPOINTPK 6 // ׯ԰սʱ (ܱİ) +#endif +#define FM_FMPOINTTIME 7 // ׯ԰ռʱ (ܱİ) +#define FM_WAITTIME (3*60) +#define FMSDENGON_SN 10000 // ֮԰ʶ + +extern struct FMMEMBER_LIST memberlist[FMMAXNUM]; // AC Աбϵ ARRAY +extern struct FMS_MEMO fmsmemo; // ֮԰ +extern struct FM_POINTLIST fmpointlist; // ݵ +extern struct FMS_DPTOP fmdptop; // ǿ߱ +extern int leaderdengonindex; // 777 幫 index +char NPC_sendbuf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW]; // һҳĴС +char enlistbuf[4096]; // Աļ BUF(ʾõ) + +unsigned long READTIME1 = 0, + READTIME2 = 0, + READTIME3 = 0, + READTIME4 = 0; + +// ijʼ(when gmsv start) +BOOL NPC_FmDengonInit( int meindex) +{ + int i; + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEDENGON); + + if( CHAR_getInt(meindex, CHAR_FLOOR) == 777 ){ + leaderdengonindex = meindex; + } + + if( READTIME1 == 0 || READTIME2 == 0 || READTIME3 == 0 || READTIME4 == 0 ){ + READTIME1 = NowTime.tv_sec+FM_WAITTIME, + READTIME2 = NowTime.tv_sec+FM_WAITTIME, + READTIME3 = NowTime.tv_sec+FM_WAITTIME, + READTIME4 = NowTime.tv_sec+FM_WAITTIME; + + // ȡüijԱб(memberlist struct)Լ԰ + for( i=0; i DENGONDISTANCE) return; +#endif + + // ԰ + if( seqno == CHAR_WINDOWTYPE_FM_DENGON) + { + int dengonindex; + int fmindex_wk; + char tmp_buffer[4096],tmp[4096]; + + getStringFromIndexWithDelim(data,"|",1,tmp_buffer,sizeof(tmp_buffer)); + dengonindex = atoi(tmp_buffer); + + fmindex_wk = CHAR_getWorkInt( talker, CHAR_WORKFMINDEXI); + + if( fmindex_wk < 0 || fmindex_wk >= FMMAXNUM) return; + + switch( select){ + case WINDOW_BUTTONTYPE_NEXT: + case WINDOW_BUTTONTYPE_PREV: + { + int fd,i; + fd = getfdFromCharaIndex( talker); + if( fd == -1) return; + + dengonindex += 7 * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + if( dengonindex > memberlist[fmindex_wk].memoindex && memberlist[fmindex_wk].memonum < DENGONFILELINENUM) + dengonindex = memberlist[fmindex_wk].memoindex; + else if( dengonindex < 6 && memberlist[fmindex_wk].memonum < DENGONFILELINENUM) + dengonindex = 6; + else if( dengonindex < 1 && memberlist[fmindex_wk].memonum >= DENGONFILELINENUM) + dengonindex = memberlist[fmindex_wk].memonum+dengonindex; + else if( dengonindex > memberlist[fmindex_wk].memonum && memberlist[fmindex_wk].memonum >= DENGONFILELINENUM) + dengonindex -= memberlist[fmindex_wk].memonum; + + buttontype = WINDOW_BUTTONTYPE_OKCANCEL; + if( dengonindex==memberlist[fmindex_wk].memoindex && memberlist[fmindex_wk].memonum >= DENGONFILELINENUM) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( (dengonindex - 7)<=memberlist[fmindex_wk].memoindex && (dengonindex - 7)>=(memberlist[fmindex_wk].memoindex - 7) && + memberlist[fmindex_wk].memonum >= DENGONFILELINENUM) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else if( dengonindex==memberlist[fmindex_wk].memoindex) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( dengonindex == 6) buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + if(dengonindex >= 6){ + strcpy( NPC_sendbuf, memberlist[fmindex_wk].memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex - 5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, memberlist[fmindex_wk].memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if(dengonindex < 6){ + strcpy( NPC_sendbuf, memberlist[fmindex_wk].memo[memberlist[fmindex_wk].memonum+(dengonindex - 6)]); + strcat( NPC_sendbuf, "\n"); + for( i=memberlist[fmindex_wk].memonum+(dengonindex - 5); i DENGONFILELINENUM) + memberlist[fmindex_wk].memonum = DENGONFILELINENUM; + + memberlist[fmindex_wk].memoindex++; + if( memberlist[fmindex_wk].memoindex >= DENGONFILELINENUM) + memberlist[fmindex_wk].memoindex=0; + + dengonindex = memberlist[fmindex_wk].memoindex; + + if( dengonindex < 6 && memberlist[fmindex_wk].memonum= 6){ + strcpy( NPC_sendbuf, memberlist[fmindex_wk].memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex-5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, memberlist[fmindex_wk].memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if( dengonindex < 6){ + strcpy( NPC_sendbuf, memberlist[fmindex_wk].memo[memberlist[fmindex_wk].memonum+(dengonindex - 6)]); + strcat( NPC_sendbuf, "\n"); + for( i=memberlist[fmindex_wk].memonum+(dengonindex - 5); i fmsmemo.memoindex && fmsmemo.memonum < FMSDENGONFILELINENUM) + dengonindex = fmsmemo.memoindex; + else if( dengonindex < 6 && fmsmemo.memonum < FMSDENGONFILELINENUM) + dengonindex = 6; + else if( dengonindex < 1 && fmsmemo.memonum >= FMSDENGONFILELINENUM) + dengonindex = fmsmemo.memonum+dengonindex; + else if( dengonindex > fmsmemo.memonum && fmsmemo.memonum >= FMSDENGONFILELINENUM) + dengonindex -= fmsmemo.memonum; + + buttontype = WINDOW_BUTTONTYPE_OKCANCEL; + if( dengonindex==fmsmemo.memoindex && fmsmemo.memonum >= FMSDENGONFILELINENUM) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( (dengonindex-7)<=fmsmemo.memoindex && (dengonindex - 7)>=(fmsmemo.memoindex - 7) && + fmsmemo.memonum >= FMSDENGONFILELINENUM) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else if( dengonindex == fmsmemo.memoindex) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( dengonindex == 6 ) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + + if( dengonindex >= 6 ){ + if( (dengonindex - 6) >= 140 ) return; + strcpy( NPC_sendbuf, fmsmemo.memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex - 5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, fmsmemo.memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if(dengonindex < 6){ + if( (fmsmemo.memonum+(dengonindex - 6)) >= 140 || + (fmsmemo.memonum+(dengonindex - 6)) < 0 ) return; + + strcpy( NPC_sendbuf, fmsmemo.memo[fmsmemo.memonum+(dengonindex - 6)]); + + strcat( NPC_sendbuf, "\n"); + for( i=fmsmemo.memonum+(dengonindex - 5); i FMSDENGONFILELINENUM) + fmsmemo.memonum = FMSDENGONFILELINENUM; + + fmsmemo.memoindex++; + if( fmsmemo.memoindex >= FMSDENGONFILELINENUM) + fmsmemo.memoindex = 0; + + dengonindex = fmsmemo.memoindex; + if( dengonindex < 6 && fmsmemo.memonum= 6){ + strcpy( NPC_sendbuf, fmsmemo.memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex - 5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, fmsmemo.memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if(dengonindex < 6){ + strcpy( NPC_sendbuf, fmsmemo.memo[fmsmemo.memonum+(dengonindex - 6)]); + strcat( NPC_sendbuf, "\n"); + for( i=fmsmemo.memonum+(dengonindex - 5); i= FMMAXNUM) return; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + switch( select ){ + case WINDOW_BUTTONTYPE_OK: + { + strcpy( numberlistbuf, memberlist[fmindex_wk].numberlistarray[0]); + strcat( numberlistbuf, "\n"); + for( i=1; i<10; i++){ + strcat( numberlistbuf, memberlist[fmindex_wk].numberlistarray[i]); + strcat( numberlistbuf, "\n"); + } + // ӳʽ(ACҪļԱֵ) + sprintf(enlistbuf, "ǷļԱ|0|%d",memberlist[fmindex_wk].accept); + strcat( numberlistbuf, enlistbuf); + strcat( numberlistbuf, "\n"); + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_FM_MEMBERLIST, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( numberlistbuf, buf, sizeof(buf))); + } + break; + default: + break; + } + } + + // ǿ߱ѡӴ + else if( seqno == CHAR_WINDOWTYPE_FM_DPSELECT) + { + int fmindex_wk; + fmindex_wk = CHAR_getWorkInt( talker, CHAR_WORKFMINDEXI); + + if( CHAR_getInt(talker, CHAR_FMINDEX) > 0 ){ + if( fmindex_wk < 0 || fmindex_wk >= FMMAXNUM){ + print("FamilyNumber Data Error!!"); + return; + } + } + + buttonevent = atoi(data); + switch( buttonevent ){ + case 1: // ǰʮۺб + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.topmemo[i]); + strcat( listbuf, "\n"); + } + strcat( listbuf, "0\n"); +#ifdef _FMVER21 + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_TOP30DP, +#else + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, +#endif + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_NEXT, + CHAR_WINDOWTYPE_FM_DPTOP, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; + case 2: // ǰʮðб + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.adv_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.adv_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; + case 3: // ǰʮб + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.feed_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.feed_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; +#ifndef _NEW_MANOR_LAW + case 4: // ǰʮϳб + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.syn_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.syn_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; + case 5: // ǰʮб + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.food_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.food_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; +#endif +#ifdef _NEW_MANOR_LAW + case 4: // ǰʮУб +#else + case 6: // ǰʮУб +#endif + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.pk_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.pk_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; +#ifdef _NEW_MANOR_LAW + case 5: // ʮƼ + { + int fd,i; + char listbuf[4096]; + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( listbuf, fmdptop.momentum_topmemo[0]); + strcat( listbuf, "\n"); + for( i=1; i<10; i++){ + strcat( listbuf, fmdptop.momentum_topmemo[i]); + strcat( listbuf, "\n"); + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_10_MEMONTUM, + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; +#endif +#ifndef _NEW_MANOR_LAW + case 7: // Լа +#else + case 6: +#endif + { + int fd,i,h,k,fmid; + char listbuf[4096]; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + fmid = CHAR_getWorkInt(talker, CHAR_WORKFMINDEXI); + if( fmid < 0 ){ + sprintf( NPC_sendbuf, " 桻\n Ǹ㲻ǼԱ޷鿴"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, + -1, + -1, + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + return; + } + + for( h=0; h= 994 ) h = 990; + else h -= 4; + + strcpy( listbuf, fmdptop.topmemo[h]); + if( k == h ) strcat( listbuf, "|1"); + strcat( listbuf, "\n"); + for( i = h + 1; i < h + 10; i++){ + strcat( listbuf, fmdptop.topmemo[i]); + if(i == k) strcat( listbuf, "|1"); + strcat( listbuf, "\n"); + } +#ifdef _FMVER21 + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_TOP30DP, +#else + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_DP, +#endif + WINDOW_BUTTONTYPE_OK| + WINDOW_BUTTONTYPE_PREV, + CHAR_WINDOWTYPE_FM_DPME, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( listbuf, buf, sizeof(buf))); + } + break; +#ifdef _NEW_MANOR_LAW + case 7: // Լ + { + int fd,h,fmid; + char listbuf[4096]; + char szTempbuf[12]; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + fmid = CHAR_getWorkInt(talker, CHAR_WORKFMINDEXI); + if( fmid < 0 ){ + sprintf( NPC_sendbuf, " 桻\n Ǹ㲻ǼԱ޷鿴"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, + -1, + -1, + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + return; + } + + for( h=0; h 0 ){ + if( fmindex_wk < 0 || fmindex_wk >= FMMAXNUM){ + print("FamilyNumber Data Error!!"); + return; + } + } + + buttonevent = atoi(data); + + switch( buttonevent ){ + case FM_MEMBERLIST: + { + int fd; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + if( CHAR_getInt(talker, CHAR_FMINDEX) <= 0){ + sprintf( NPC_sendbuf, " 桻\n Ǹ㲻ǼԱʹù"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, + -1, -1, makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + return; + } + /* + #ifdef _FMVER21 + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER || + CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER ){ + #else + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG) == 1){ + #endif + saacproto_ACShowMemberList_send( acfd, fmindex_wk); + READTIME1 = NowTime.tv_sec+FM_WAITTIME; + }else + */ + if( NowTime.tv_sec > READTIME1 ){ + saacproto_ACShowMemberList_send( acfd, fmindex_wk); + READTIME1 = NowTime.tv_sec+FM_WAITTIME; + } + +#ifdef _FMVER21 + // if( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER || + // CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER || + // CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_VICELEADER ){ + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER || + CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER ){ +#else + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG) == FMMEMBER_MEMBER ){ +#endif + sprintf( NPC_sendbuf, " ֪\nСĴԱϣһ޸޷ظԭ̬Сġ"); + }else{ + sprintf( NPC_sendbuf, " ֪\n ˱峤޸ģԱܲ鿴"); + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_FM_MESSAGE2, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; + case FM_FMPOINT: + { + int fd; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + +#ifdef _FMVER21 + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER ){ +#else + if( CHAR_getInt( talker, CHAR_FMLEADERFLAG) == FMMEMBER_MEMBER ){ +#endif + saacproto_ACFMPointList_send(acfd); + sprintf( NPC_sendbuf, " ֪\nСѡľݵ㣬һѡȡݵ޷ظԭ̬Сġ"); + READTIME4 = NowTime.tv_sec+FM_WAITTIME; + } + else{ + sprintf( NPC_sendbuf, " ֪\n˱峤룬Žܲ鿴"); + } + + if( NowTime.tv_sec > READTIME4 ){ + saacproto_ACFMPointList_send(acfd); + READTIME4 = NowTime.tv_sec+FM_WAITTIME; + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_FM_MESSAGE1, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; + case FM_FMDPTOP: + { + int fd; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + if( NowTime.tv_sec > READTIME3 ){ + saacproto_ACShowTopFMList_send( acfd, FM_TOP_INTEGRATE ); + saacproto_ACShowTopFMList_send( acfd, FM_TOP_ADV ); + saacproto_ACShowTopFMList_send( acfd, FM_TOP_FEED ); + saacproto_ACShowTopFMList_send( acfd, FM_TOP_SYNTHESIZE ); + saacproto_ACShowTopFMList_send( acfd, FM_TOP_DEALFOOD ); + saacproto_ACShowTopFMList_send( acfd, FM_TOP_PK ); +#ifdef _NEW_MANOR_LAW + saacproto_ACShowTopFMList_send(acfd, FM_TOP_MOMENTUM); +#endif + READTIME3 = NowTime.tv_sec+FM_WAITTIME; + } + memset(NPC_sendbuf,0,sizeof(NPC_sendbuf)); + strcpy( NPC_sendbuf, "\n ʮб\n"); + strcat( NPC_sendbuf, " ʮðռ\n"); + strcat( NPC_sendbuf, " ʮ\n"); +#ifndef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " ʮϳɼ\n"); + strcat( NPC_sendbuf, " ʮ\n"); +#endif + strcat( NPC_sendbuf, " ʮս\n"); +#ifdef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " ʮƼ\n"); +#endif + strcat( NPC_sendbuf, " Լб\n"); +#ifdef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " Լ\n"); +#endif + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_FM_DPSELECT, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + + } + break; + case FM_MEMBERMEMO: + { + int fd,i,dengonindex; + char tmp[4096]; + fd = getfdFromCharaIndex( talker ); + + if( fd == -1 ) return; + + if( CHAR_getInt(talker, CHAR_FMINDEX) <= 0){ + sprintf( NPC_sendbuf, " 桻\n Ǹ㲻ǼԱʹù"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, + -1, + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + return; + } + + if( NowTime.tv_sec > READTIME2 ){ + saacproto_ACFMReadMemo_send( acfd, fmindex_wk); + READTIME2 = NowTime.tv_sec+FM_WAITTIME; + } + + dengonindex = memberlist[fmindex_wk].memoindex; + if( memberlist[fmindex_wk].memoindex < 6 && memberlist[fmindex_wk].memonum < DENGONFILELINENUM ){ + dengonindex = 6; + } + + if( dengonindex >= 6 ){ + strcpy( NPC_sendbuf, memberlist[fmindex_wk].memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex - 5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, memberlist[fmindex_wk].memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if( dengonindex < 6 ){ + strcpy( NPC_sendbuf, + memberlist[fmindex_wk].memo[memberlist[fmindex_wk].memonum + (dengonindex - 6)]); + strcat( NPC_sendbuf, "\n"); + for( i=memberlist[fmindex_wk].memonum + (dengonindex - 5); i READTIME3 ){ + saacproto_ACFMReadMemo_send( acfd, FMSDENGON_SN); + READTIME3 = NowTime.tv_sec+FM_WAITTIME; + } + dengonindex = fmsmemo.memoindex; + if( fmsmemo.memoindex<6 || fmsmemo.memonum>FMSDENGONFILELINENUM ){ + dengonindex = 6; + } + if( dengonindex >= 6 ){ + strcpy( NPC_sendbuf, fmsmemo.memo[dengonindex - 6]); + strcat( NPC_sendbuf, "\n"); + for( i=(dengonindex - 5); i<=dengonindex; i++){ + strcat( NPC_sendbuf, fmsmemo.memo[i]); + strcat( NPC_sendbuf, "\n"); + } + sprintf(tmp, "%d\n", dengonindex); + strcat( NPC_sendbuf, tmp); + } + if( dengonindex < 6 ){ + if( (fmsmemo.memonum + (dengonindex - 6)) < 0 || (fmsmemo.memonum + (dengonindex - 6)) >= 140 ) + return; + strcpy( NPC_sendbuf, fmsmemo.memo[fmsmemo.memonum + (dengonindex - 6)]); + strcat( NPC_sendbuf, "\n"); + for( i=fmsmemo.memonum + (dengonindex - 5); itm_mon + 1, tm1->tm_mday, tm1->tm_hour, tm1->tm_min, + fmpks[fmpks_pos + 2].host_name, + fmpks[fmpks_pos + 1].guest_name, + fmpks[fmpks_pos + 1].host_name, + fmpks[fmpks_pos + 1].max_player, + fmpks[fmpks_pos + 1].max_player); + + if(fmpks[fmpks_pos+1].flag == FMPKS_FLAG_MANOR_BATTLEBEGIN){ + strcat( tmpbuf, " ׯ԰״̬ս\n"); + }else if(fmpks[fmpks_pos+1].flag == FMPKS_FLAG_MANOR_PREPARE){ + strcat( tmpbuf, " ׯ԰״̬׼"); + }else if(fmpks[fmpks_pos+1].flag == FMPKS_FLAG_MANOR_OTHERPLANET){ + strcat( tmpbuf, " ׯ԰״̬ڱ·ս"); + } + + } + break; + + default: + { + sprintf(tmpbuf, "%sսų\n\n\n",fmpointname[i - 1]); + } + + break; + } +*/ + strcat( NPC_sendbuf, tmpbuf); + } + } + + lssproto_WN_send( fd, 1021, + WINDOW_BUTTONTYPE_CANCEL, + -1, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; +#endif + case FM_FMPOINTTIME: + { + int fd; + char fmtime[64]; + char fmname[255]; + fd = getfdFromCharaIndex( talker ); + memset(&NPC_sendbuf,0,sizeof(NPC_sendbuf)); + strcpy(NPC_sendbuf, "ׯ԰ռʱ"); + { + int i; + for( i=0; i= FMMAXNUM) return; + + getStringFromIndexWithDelim(data,"|",1,tmp_buffer,sizeof(tmp_buffer)); + numberlistindex = atoi(tmp_buffer); + getStringFromIndexWithDelim(data,"|",2,tmp_buffer,sizeof(tmp_buffer)); + buttonevent = atoi(tmp_buffer); + getStringFromIndexWithDelim(data,"|",3,dutybuf,sizeof(dutybuf)); + +#ifdef _FMVER21 + // if( buttonevent>=1 && buttonevent<=11 && + // ( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER || + // CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER || + // CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_VICELEADER )) + if( buttonevent>=1 && buttonevent<=11 && + ( CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER || + CHAR_getInt( talker, CHAR_FMLEADERFLAG ) == FMMEMBER_ELDER )) +#else + if( buttonevent>=1 && buttonevent<=11 && CHAR_getInt( talker, CHAR_FMLEADERFLAG) == FMMEMBER_MEMBER ) +#endif + { + int fd,i; + int int_status; + char getstatus[4096]; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + strcpy( getstatus, memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1] + + (strlen( memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1]) - 1)); + + int_status = atoi(getstatus); + + // ļ롢˳ѡ + if( buttonevent!=11 ) +#ifdef _FMVER21 + strcpy( memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1] + + (strlen(memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1]) - 1), dutybuf); +#else + switch( int_status ){ + case 1: + case 3: + strcpy( memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1] + + (strlen(memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1]) - 1), "4"); + break; + case 2: + strcpy( memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1] + + (strlen(memberlist[fmindex_wk].numberlistarray[numberlistindex+buttonevent - 1]) - 1), "1"); + break; + default: + break; + } +#endif + // ļѡ + if( buttonevent == 11 ) + { + strcpy( getstatus, enlistbuf + (strlen(enlistbuf) - 1)); + int_status = atoi(getstatus); + + switch( int_status ){ + case 1: + memberlist[fmindex_wk].accept = 0; + sprintf(enlistbuf, "ǷļԱ|%d|%d",numberlistindex,memberlist[fmindex_wk].accept); + break; + case 0: + memberlist[fmindex_wk].accept = 1; + sprintf(enlistbuf, "ǷļԱ|%d|%d",numberlistindex,memberlist[fmindex_wk].accept); + break; + default: + break; + } + } + + strcpy( numberlistbuf, memberlist[fmindex_wk].numberlistarray[numberlistindex]); + strcat( numberlistbuf, "\n"); + for( i=(numberlistindex + 1); i memberlist[fmindex_wk].fmnum) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( numberlistindex == 0 ) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + + lssproto_WN_send( fd, WINDOW_FMMESSAGETYPE_SELECT, + buttontype, + CHAR_WINDOWTYPE_FM_MEMBERLIST, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( numberlistbuf, buf, sizeof(buf))); + } // end if + switch( select ){ + case WINDOW_BUTTONTYPE_NEXT: + case WINDOW_BUTTONTYPE_PREV: + { + int fd,i; + + fd = getfdFromCharaIndex( talker ); + if( fd == -1 ) return; + + numberlistindex += 10 * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + + if( numberlistindex >= memberlist[fmindex_wk].fmnum) + numberlistindex -= 10; + else if( numberlistindex < 1 ) + numberlistindex = 0; + + buttontype = WINDOW_BUTTONTYPE_OK; + if( (numberlistindex + 10) >= memberlist[fmindex_wk].fmnum) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( numberlistindex==0 ) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + + strcpy( numberlistbuf, memberlist[fmindex_wk].numberlistarray[numberlistindex]); + strcat( numberlistbuf, "\n"); + for( i=(numberlistindex+1); i= 30) + return; + //listindex = 20; + //listindex -= 10; + //else if( listindex < 1 ) + // listindex = 0; + if (listindex < 0) return; + + buttontype = WINDOW_BUTTONTYPE_OK; + if( (listindex + 10) >= 30) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( listindex==0 ) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + + strcpy( listbuf, fmdptop.topmemo[listindex]); + strcat( listbuf, "\n"); + for( i=(listindex+1); i FMPOINTNUM) + pointlistindex -= 10; + else if( pointlistindex < 1 ) + pointlistindex = 0; + + buttontype = WINDOW_BUTTONTYPE_OK; + if( (pointlistindex + 10) > FMPOINTNUM) + buttontype |= WINDOW_BUTTONTYPE_PREV; + else if( pointlistindex==0 ) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + else{ + buttontype |= WINDOW_BUTTONTYPE_PREV; + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + + strcpy( pointbuf, fmpointlist.pointlistarray[pointlistindex]); + strcat( pointbuf, "\n"); + for( i=(pointlistindex+1); i READTIME3 ){ + saacproto_ACShowTopFMList_send(acfd, FM_TOP_INTEGRATE); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_ADV); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_FEED); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_SYNTHESIZE); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_DEALFOOD); + saacproto_ACShowTopFMList_send(acfd, FM_TOP_PK); +#ifdef _NEW_MANOR_LAW + saacproto_ACShowTopFMList_send(acfd, FM_TOP_MOMENTUM); +#endif + READTIME3 = NowTime.tv_sec+FM_WAITTIME; + } + + strcpy( NPC_sendbuf, "\n ʮб\n"); + strcat( NPC_sendbuf, " ʮðռ\n"); + strcat( NPC_sendbuf, " ʮ\n"); +#ifndef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " ʮϳɼ\n"); + strcat( NPC_sendbuf, " ʮ\n"); +#endif + strcat( NPC_sendbuf, " ʮս\n"); +#ifdef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " ʮƼ\n"); +#endif + strcat( NPC_sendbuf, " Լб\n"); +#ifdef _NEW_MANOR_LAW + strcat( NPC_sendbuf, " Լ\n"); +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_FM_DPSELECT, +#ifndef _FM_MODIFY + CHAR_getWorkInt( index, CHAR_WORKOBJINDEX), +#else + -1, +#endif + makeEscapeString( NPC_sendbuf, buf, sizeof(buf))); + } + break; + case WINDOW_BUTTONTYPE_OK: + break; + default: + break; + } + + } +} + +// call FmDengon NPC event +#ifndef _FM_MODIFY +void NPC_FmDengonLooked( int meindex, int lookedindex ) +{ + char buf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW*2]; + char menubuf[4096]; + int fd; + + if (!CHAR_CHECKINDEX(lookedindex)) return; + + fd = getfdFromCharaIndex( lookedindex ); + if( fd == -1 ) return; + + // վڲǰһ + if( NPC_Util_CharDistance( lookedindex, meindex ) > 1) return; + // հ״ + strcpy( menubuf, " 岼"); + strcat( menubuf, "\n Աб"); + strcat( menubuf, "\n "); + strcat( menubuf, "\n ֮԰"); + strcat( menubuf, "\n ݵ"); + strcat( menubuf, "\n ֮ǿ߱"); +#ifdef _FM_FMPOINTPK_LIST + strcat( menubuf, "\n ׯ԰սʱ"); +#endif + strcat( menubuf, "\n ׯ԰ռʱ"); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_FM_SELECT, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( menubuf, buf, sizeof(buf))); +} +#else +void NPC_FmDengonLooked( int meindex, int lookedindex ) +{ + char buf[DENGONFILEENTRYSIZE*MESSAGEINONEWINDOW*2]; + char menubuf[4096]; + int fd; + + if (!CHAR_CHECKINDEX(lookedindex)) return; + + fd = getfdFromCharaIndex( lookedindex ); + if( fd == -1 ) return; + + // հ״ + strcpy( menubuf, " 岼"); + strcat( menubuf, "\n Աб"); + strcat( menubuf, "\n "); + strcat( menubuf, "\n ֮԰"); + strcat( menubuf, "\n ݵ"); + strcat( menubuf, "\n ֮ǿ߱"); +#ifdef _FM_FMPOINTPK_LIST + strcat( menubuf, "\n ׯ԰սʱ"); +#endif + strcat( menubuf, "\n ׯ԰ռʱ"); + lssproto_WN_send(fd, + WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_FM_SELECT, + -1, + makeEscapeString( menubuf, buf, sizeof(buf))); +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmhealer.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmhealer.c new file mode 100644 index 0000000..31ac8d6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmhealer.c @@ -0,0 +1,144 @@ +#include "version.h" +/*---------- Shan (BEGIN) ----------*/ +/*--------- AD 2001/05/28 ---------*/ +// +// ҽ +// +/*---------- Shan(END) ----------*/ +#include +#include +#include + +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" + +#define RANGE 2 +void NPC_FmHealerSpeak( int index, int talker); +void NPC_FmHealerAllHeal( int talker ); +BOOL NPC_FmMoneyCheck(int meindex,int talker); +int NPC_FmCostCheck(int talker); +void NPC_FmCharCheckPoint(int meindex,int talker); +int NPC_FmWorkInput(int meindex,int talker); + +BOOL NPC_FmHealerInit( int meindex ) +{ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEHEALER ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + return TRUE; +} + +void NPC_FmHealerTalked( int meindex , int talker , char *msg ,int color ) +{ + char* npcarg; + char token[32]; + int msgNo; + + npcarg = CHAR_getChar(meindex,CHAR_NPCARGUMENT); + + getStringFromIndexWithDelim( npcarg, "|", 1, token,sizeof( token)); + msgNo = atoi( token ); + + if( CHAR_getInt( talker , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + + if( NPC_Util_isFaceToFace( talker, meindex , 2 ) == FALSE ) + { + if( NPC_Util_isFaceToFace( talker, meindex , 1 ) == FALSE ) + return; + } + + //if( CHAR_getInt(meindex, CHAR_FLOOR) != CHAR_getWorkInt(talker, CHAR_WORKFMFLOOR)){ + //print("\n npc floor->%d player floor->%d",CHAR_getInt(meindex, CHAR_FLOOR), + // CHAR_getWorkInt(talker, CHAR_WORKFMFLOOR)); + // CHAR_talkToCli(talker, meindex, + // "Ǹ㲻DZԱ޷ظ",CHAR_COLORWHITE); + // return; + //} + + if( (CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) == 0) + || (CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) == 2)){ + NPC_FmHealerAllHeal( talker); + if(msgNo == 1) { + CHAR_talkToCli( talker, meindex, + "ѾȫظСԼࡣ",CHAR_COLORWHITE); + }else if(msgNo == 2){ + CHAR_talkToCli( talker, meindex, + "DZԱҰظɣ",CHAR_COLORWHITE); + } + }else{ + int i = 0; + int otherindex; + for( i=0 ; i < getPartyNum(talker ) ; i++){ + otherindex = CHAR_getWorkInt( talker, CHAR_WORKPARTYINDEX1 + i); + if(otherindex != -1){ + NPC_FmHealerAllHeal( otherindex); + if(msgNo == 1){ + CHAR_talkToCli( otherindex, meindex, + "ѾȫظСԼࡣ",CHAR_COLORWHITE); + }else if(msgNo == 2){ + CHAR_talkToCli( otherindex, meindex, + "DZԱҰظɣ",CHAR_COLORWHITE); + } + } + } + } +} + +void NPC_FmHealerAllHeal( int talker ) +{ + int i; + int petindex; + char petsend[3]; + char msgbuf[5]; + + CHAR_setInt( talker , CHAR_HP ,CHAR_getWorkInt( talker, CHAR_WORKMAXHP ) ); + CHAR_setInt( talker , CHAR_MP ,CHAR_getWorkInt( talker, CHAR_WORKMAXMP ) ); + + for(i = 0 ; i < CHAR_MAXPETHAVE; i ++){ + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) continue; + + if( !CHAR_CHECKINDEX( talker ) ) continue; + if( CHAR_CHECKINDEX( petindex) == FALSE ) continue; + CHAR_setFlg( petindex, CHAR_ISDIE, 0); + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + CHAR_complianceParameter( petindex ); + sprintf( petsend, "K%d", i ); + CHAR_sendStatusString( talker , petsend ); + } + + if(CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ){ + int topartyarray = -1; + int oyaindex = CHAR_getWorkInt( talker, CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX( oyaindex )){ + int i; + for( i = 0; i < getPartyNum(oyaindex ) ; i ++ ){ + int workindex = CHAR_getWorkInt( oyaindex, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ){ + if( workindex == talker ){ + topartyarray = i; + break; + } + } + } + for( i = 0; i < getPartyNum(talker ) ; i ++ ) { + int otherindex = CHAR_getPartyIndex( talker, i); + if( CHAR_CHECKINDEX( otherindex) ){ + snprintf( msgbuf, sizeof( msgbuf), "N%d", topartyarray); + if( otherindex != talker){ + CHAR_sendStatusString( otherindex, msgbuf); + } + } + } + } + } + CHAR_send_P_StatusString( talker, CHAR_P_STRING_HP); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_MP); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmletter.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmletter.c new file mode 100644 index 0000000..f26ea1c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmletter.c @@ -0,0 +1,697 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_fmletter.h" +#include "family.h" +#include "log.h" +#include "autil.h" + +extern struct FM_POINTLIST fmpointlist; + +char sendbuf[1024]; +char buf[1024]; +char subbuf[128]; +int i, j; + +/* + * ɬýľūëNPC + * ƽʧìҡئľ¾֣ + * + */ + +struct { + int windowno; + int windowtype; + int buttontype; + int takeitem; + int giveitem; + char message[4096]; + int letter; +}w; + +struct { + BOOL use; + int checkhaveitem; + int checkhaveitemgotowin; + int checkdonthaveitem; + int checkdonthaveitemgotowin; + int warp; + int battle; + int gotowin; +}buttonproc[13]; /* ok,cancel, yes,no,prev,next ݼ */ + + + + + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; + +static void NPC_FmLetter_selectWindow( int meindex, int toindex, int num); +static BOOL NPC_FmLetter_readData( int meindex, int windowno, BOOL chkflg); +static int NPC_FmLetter_restoreButtontype( char *data ); + +/********************************* +* +*********************************/ +BOOL NPC_FmLetterInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + //int i; + //char secondToken[1024]; + + // Robin test + // print(" fmleter_Init "); + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", buf, sizeof( buf)) + == NULL ) + { + print( "fmletter:ûָ趨ĵ \n"); + return FALSE; + } + /* ݱɬ÷ëƻ֧ */ + if( !NPC_FmLetter_readData( meindex, -1, TRUE) ) { + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWINDOWMAN ); + + return TRUE; +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_FmLetterTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + //print(" FmLetter_fmindex:%d ", CHAR_getInt( meindex, CHAR_FMINDEX) ); + + + int fmindex = 0, village, i; + char token[256]; + char buf[256]; + for( i=0 ; i 1) return; + + /* ū įë */ + if( !NPC_FmLetter_readData( meindex, seqno - 100, FALSE) ) { + print( "fmletter:readdata error\n"); + return; + } + /* ʾëƩ */ + if( w.windowtype == WINDOW_MESSAGETYPE_SELECT ) { + button = atoi( data)+5; + if( button > 12 ) { + print( "fmletter:invalid button[%d]\n", button); + return; + } + } + else if( select & WINDOW_BUTTONTYPE_OK) button = 0; + else if( select & WINDOW_BUTTONTYPE_CANCEL) button = 1; + else if( select & WINDOW_BUTTONTYPE_YES) button = 2; + else if( select & WINDOW_BUTTONTYPE_NO) button = 3; + else if( select & WINDOW_BUTTONTYPE_PREV) button = 4; + else if( select & WINDOW_BUTTONTYPE_NEXT) button = 5; + else { + print( "fmletter:invalid button[%d]\n", select); + return; + } + if( buttonproc[button].use == TRUE ) { + int fd; + int newwin = -1; + + fd = getfdFromCharaIndex( talkerindex); + + /* ʾ巽Ȼ ëԻ */ + if( newwin == -1 ) { + newwin = buttonproc[button].gotowin; + } + + + // Robin + if( newwin == 5 ) { + int emptyitemindexinchara = CHAR_findEmptyItemBox( talkerindex ); + int itemindex = ITEM_makeItemAndRegist( w.letter ); + + if( emptyitemindexinchara < 0 ) return; + + if( itemindex != -1 ){ + + + char msgbuf[128]; + CHAR_setItemIndex( talkerindex, emptyitemindexinchara, itemindex ); + /* Workëɬ */ + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX, talkerindex); + CHAR_sendItemDataOne( talkerindex, emptyitemindexinchara); + LogItem( + CHAR_getChar( talkerindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talkerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "AddLetter(뺯)", + CHAR_getInt( talkerindex,CHAR_FLOOR), + CHAR_getInt( talkerindex,CHAR_X ), + CHAR_getInt( talkerindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + snprintf( msgbuf, sizeof( msgbuf), "%sɹ", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talkerindex, -1,msgbuf, CHAR_COLORWHITE); + } + } + + // Robin + if( newwin == 6 ) { + int emptyitemindexinchara = CHAR_findEmptyItemBox( talkerindex ); + int itemindex = ITEM_makeItemAndRegist( w.letter ); + + if( emptyitemindexinchara < 0 ) return; + + if( itemindex != -1 ){ + + char msgbuf[128]; + CHAR_setItemIndex( talkerindex, emptyitemindexinchara, itemindex ); + /* Workëɬ */ + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX, talkerindex); + CHAR_sendItemDataOne( talkerindex, emptyitemindexinchara); + LogItem( + CHAR_getChar( talkerindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talkerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), /* ʧ ة į */ +#endif + "AddLetter(뺯)", + CHAR_getInt( talkerindex,CHAR_FLOOR), + CHAR_getInt( talkerindex,CHAR_X ), + CHAR_getInt( talkerindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + snprintf( msgbuf, sizeof( msgbuf), "%sɹ", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talkerindex, -1,msgbuf, CHAR_COLORWHITE); + } + } + + + if( !NPC_FmLetter_readData( meindex, newwin, FALSE) ) { + print( "fmletter:readdata error\n"); + return; + } + + //fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } + + + + } +} +/* + * ɬð̻ë ƥ϶ýľwindownoë + * + * ¦ѡ + * meindex int NPCcharaindex + * windowno int ū į + * + */ +static BOOL NPC_FmLetter_readData( int meindex, int windowno, BOOL chkflg) +{ + + int i; + int linenum = 0; + int endflg = FALSE; + int buttonendflg; + int winno = -1; + int buttonconfmode; + int b_mode; + int selectnum ; + int messagepos; + BOOL errflg = FALSE; + BOOL readflg = TRUE; + FILE *fp; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char filename[64]; + char opfile[128]; + char line[1024]; + char firstToken[1024]; + char secondToken[1024]; + + /* ūɬë Ի հ */ + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + /* ɬð̻ */ + NPC_Util_GetStrFromStrWithDelim( argstr, "conff", filename, sizeof( filename)); + + sprintf( opfile, "%s/", getNpcdir( ) ); + strcat( opfile, filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", opfile); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( opfile, "r"); +} + if( fp == NULL ) { + print( "fmletter:file open error [%s]\n", opfile); + return FALSE; + } + + while( readflg == TRUE ) { + endflg = FALSE; + buttonendflg = TRUE; + buttonconfmode = FALSE; + selectnum = 0; + messagepos = 0; + winno = -1; + b_mode = -1; + errflg = FALSE; + + /* */ + w.windowno = -1; + w.windowtype = -1; + w.buttontype = -1; + w.takeitem = -1; + w.giveitem = -1; + w.message[0] = '\0'; + + for( i = 0; i < arraysizeof( buttonproc); i ++ ) { + buttonproc[i].use = FALSE; + buttonproc[i].checkhaveitem = -1; + buttonproc[i].checkhaveitemgotowin = -1; + buttonproc[i].checkdonthaveitem = -1; + buttonproc[i].checkdonthaveitemgotowin = -1; + buttonproc[i].warp = -1; + buttonproc[i].battle = -1; + buttonproc[i].gotowin = -1; + } + + while( 1) { + char buf[256]; + int ret; + if( !fgets( line, sizeof( line), fp)){ + readflg = FALSE; + break; + } +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + + /* 춪 */ + if( line[0] == '#' || line[0] == '\n') continue; + /* ݱ */ + chomp( line ); + + /* ë */ + /* tab ë " " 徧 */ + replaceString( line, '\t' , ' ' ); + /* ʸë£*/ + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) strcpy( line, buf); + + /* delim "=" ƥ (1)ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, + sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + /* delim "=" ƥ2 ͼë */ + ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, + sizeof( secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + + if( strcasecmp( firstToken, "winno") == 0 ) { + if( winno != -1 ) { + print( "fmletter:winnoȴ¶winno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + readflg = FALSE; + break; + } + /* ūNoë */ + winno = atoi( secondToken); + continue; + } + + /* ūNo Ȼئݼ淴 */ + if( winno == -1 ) { + print( "fmletter:winno δ壬ȴ趨\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = FALSE; + break; + } + /* ūNo ݷë + * ľ½ */ + if( (chkflg == FALSE && winno == windowno )|| + chkflg == TRUE) + { + if( buttonconfmode == TRUE ) { + if( strcasecmp( firstToken, "gotowin") == 0 ) { + buttonproc[b_mode].gotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkhaveitem") == 0 ) { + buttonproc[b_mode].checkhaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "haveitemgotowin") == 0 ) { + buttonproc[b_mode].checkhaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkdonthaveitem") == 0 ) { + buttonproc[b_mode].checkdonthaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "donthaveitemgotowin") == 0 ) { + buttonproc[b_mode].checkdonthaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "endbutton") == 0 ) { + if( buttonproc[b_mode].gotowin == - 1 ) { + if( buttonproc[b_mode].checkhaveitem == -1 && + buttonproc[b_mode].checkdonthaveitem == -1) + { + errflg = TRUE; + } + else { + /* оȵƥɬýľľ */ + if( !((buttonproc[b_mode].checkhaveitem != -1 && + buttonproc[b_mode].checkhaveitemgotowin != -1) + || (buttonproc[b_mode].checkdonthaveitem != -1 && + buttonproc[b_mode].checkdonthaveitemgotowin != -1))) + { + errflg = TRUE; + } + } + } + + if( errflg == TRUE) { + print( "fmletter: Ҳgotowin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = TRUE; + break; + } + buttonproc[b_mode].use = TRUE; + buttonconfmode = FALSE; + buttonendflg = TRUE; + } + } + else { + + w.windowno = winno; + + sprintf( buf, "letter%d", CHAR_getInt( meindex, CHAR_FMINDEX) ); + + /* ūɬ */ + if( strcasecmp( firstToken, "wintype") == 0 ) { + w.windowtype = atoi( secondToken); + } + /* ʾɬ */ + else if( strcasecmp( firstToken, "buttontype") == 0 ) { + w.buttontype = NPC_FmLetter_restoreButtontype( secondToken); + } + /* getitemɬ */ + else if( strcasecmp( firstToken, "takeitem") == 0 ) { + w.takeitem = atoi( secondToken); + } + /* giveitemɬ */ + else if( strcasecmp( firstToken, "giveitem") == 0 ) { + w.giveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, buf) == 0 ) { + w.letter = atoi( secondToken); + } + + /* messageɬ */ + else if( strcasecmp( firstToken, "message") == 0 ) { + if( messagepos == 0 ) { + strcpy( w.message, secondToken); + messagepos = strlen( w.message); + } + else { + w.message[messagepos]='\n'; + messagepos++; + strcpy( &w.message[messagepos], secondToken); + messagepos+=strlen(secondToken); + } + } + /* ʾëݼɬ */ + else if( strcasecmp( firstToken, "okpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 0; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "cancelpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 1; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "yespressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 2; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nopressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 3; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "prevpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 4; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nextpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 5; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "selected") == 0 ) { + buttonconfmode = TRUE; + b_mode = 6 + selectnum; + buttonendflg = FALSE; + selectnum ++; + } + /* ɬñδԻ */ + else if( strcasecmp( firstToken, "endwin") == 0 ) { + endflg = TRUE; + if( chkflg == FALSE) { + readflg = FALSE; + } + break; + } + else { + //print( "fmletter:趨DzܵIJ\n"); + //print( "filename:[%s] line[%d]\n", filename, linenum); + } + } + } + else { + if( strcasecmp( firstToken, "endwin") == 0 ) { + winno = -1; + } + } + } + if( buttonendflg == FALSE) { + print( "fmletter: Ҳendbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( winno != -1 ) { + if( w.windowtype == -1 ) { + print( "fmletter: Ҳwintype\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( w.buttontype == -1 ) { + print( "fmletter: Ҳbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( strlen( w.message) == 0 ) { + print( "fmletter: Ҳmessage\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + } + } + fclose( fp); + + if( chkflg == FALSE && w.windowno == -1 ) { + print( "fmletter: Ҳָwindowno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( winno != -1 && endflg == FALSE) { + print( "fmletter: Ҳendwin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( errflg == TRUE) return FALSE; + + return TRUE; +} +/* + * buttontype=ƥ϶ ٯ ëѰ £ + * + */ +static int NPC_FmLetter_restoreButtontype( char *data ) +{ + int ret = 0; + int rc; + int i; + char buff[1024]; + + for( i = 1; ; i ++ ) { + rc = getStringFromIndexWithDelim( data, "|", i, buff, + sizeof( buff ) ); + if( rc == FALSE) break; + if( strcasecmp( buff, "ok") == 0 ) { + ret |= WINDOW_BUTTONTYPE_OK; + } + else if( strcasecmp( buff, "cancel") == 0 ) { + ret |= WINDOW_BUTTONTYPE_CANCEL; + } + else if( strcasecmp( buff, "yes") == 0 ) { + ret |= WINDOW_BUTTONTYPE_YES; + } + else if( strcasecmp( buff, "no") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NO; + } + else if( strcasecmp( buff, "prev") == 0 ) { + ret |= WINDOW_BUTTONTYPE_PREV; + } + else if( strcasecmp( buff, "next") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NEXT; + } + } + if( ret == 0 ) { + ret = atoi( data); + } + return ret; +} + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkcallman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkcallman.c new file mode 100644 index 0000000..67b150e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkcallman.c @@ -0,0 +1,395 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_fmpkcallman.h" +#include "family.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" + +// WON ADD 峤ٻ +#include "npc_scheduleman.h" +#include "handletime.h" + + +static void NPC_FMPKCallMan_selectWindow(int meindex, int toindex, int num, int select); +void NPC_CallFMMember(int meindex, int floor, int fmindex, char *fmname, int index); + +/********************************* +* +*********************************/ +BOOL NPC_FMPKCallManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + char buff2[256]; + int fl, x, y; + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg)) == NULL){ + print("FMPKCallMan:GetArgStrErr"); + return FALSE; + } + + /*--ɬýľ¾----*/ + /*--ɬýľئľNPCëئг--*/ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf))==NULL){ + print("FMPKCallMan Err is %s",npcarg); + print("FMPKCallMan Err"); + return FALSE; + } + + /*--ɬýľлַƻئľǷNPCëئ--*/ + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl=atoi(buff2); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y=atoi(buff2); + + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "FMWarp NPC:Invalid warpman ERR" ); + return FALSE; + } + + /*--ɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWARPMAN ); + + return TRUE; +} + +/********************************* +* ƾľݼ +*********************************/ +void NPC_FMPKCallManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + /* */ + if( NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + /*--ͼ--*/ + CHAR_setWorkInt(talkerindex, CHAR_WORKSHOPRELEVANT, 0); + + /*-Ԫ --*/ + NPC_FMPKCallMan_selectWindow( meindex, talkerindex, 0, -1); +} + +static void NPC_FMPKCallMan_selectWindow( int meindex, int toindex, + int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024], buf[256], buf2[256]; + int fd = getfdFromCharaIndex(toindex); + + if( fd == -1 ) { + fprint( "getfd err\n"); + return; + } + + // print("meindex:%d toindex:%d num:%d select:%d", meindex, toindex, num, select); + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + /*--ɬð̻P ׷ʧѻ϶ýľ¾ľľɰ׷ʧѼԻ*/ + if(strstr(npcarg,"%4d")!=NULL){ + int work; + NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf)); + getStringFromIndexWithDelim(buf,",",1,buf2,sizeof(buf2)); + work = atoi( buf2); + } + + token[0] = '\0'; + + switch(num) { + + case 0: + if (NPC_Util_GetStrFromStrWithDelim(npcarg, "MainMsg", buf, + sizeof(buf)) == NULL) + return; + sprintf(token, "3\n У˳\n" + "%s" + "\n ٻԱ" + "\n ؼ¼㡷" + "\n ȡ", + buf); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_FMPKCALLMAN_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); + break; + case 1: +#ifdef _FMVER21 + if( CHAR_getInt( toindex, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER) +#else + if( CHAR_getInt( toindex, CHAR_FMLEADERFLAG) == FMMEMBER_MEMBER) +#endif + { + if (CHAR_getWorkInt(toindex, CHAR_WORKFMSETUPFLAG) != 1) + { + if (NPC_Util_GetStrFromStrWithDelim(npcarg, "NoSetupMsg", buf, + sizeof(buf)) == NULL) + return; + if (strstr(buf, "%s") != NULL) + sprintf(token, buf, CHAR_getChar(toindex, CHAR_FMNAME)); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, token); + } + else + { + if (NPC_Util_GetStrFromStrWithDelim(npcarg, "CallMsg", buf, + sizeof(buf)) == NULL) + return; + if (strstr(buf, "%s") != NULL) + sprintf(token, buf, CHAR_getChar(toindex, CHAR_FMNAME)); + +// WON ADD 峤ٻ + { + int fmindex, fmpk_pos=-1, j; + int now_time; + struct tm tm1; +// Terry add for ֵΪ 0 ļ,Զжϼ + char szFMName[32]; +// end + + memcpy(&tm1,localtime((time_t *)&NowTime.tv_sec),sizeof(tm1)); + + fmindex = CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI); +// Terry add for ֵΪ 0 ļ,Զжϼ + strncpy(szFMName,CHAR_getChar(toindex,CHAR_FMNAME),sizeof(szFMName)); +// end + + for( j=0; j <= MAX_SCHEDULEMAN*MAX_SCHEDULE; j++ ){ +// Terry fix for ֵΪ 0 ļ,Զжϼ +// if( (fmindex == fmpks[j].host_index ) || (fmindex == fmpks[j].guest_index ) ){ + if((fmindex == fmpks[j].host_index && strcmp(szFMName,fmpks[j].host_name) == 0) || + (fmindex == fmpks[j].guest_index && strcmp(szFMName,fmpks[j].guest_name) == 0)){ +//end + fmpk_pos=j; + break; + } + } + + if(fmpk_pos != -1){ + + if(fmpk_pos <= MANORNUM*MAX_SCHEDULE+1){ + now_time=NowTime.tv_sec+(60*60); + }else{ + if(tm1.tm_hour+1==24) now_time=10000; + else now_time=(tm1.tm_hour+1) * 100; + } + + if( (fmpks[fmpk_pos].flag != FMPKS_FLAG_SCHEDULED) && + (fmpks[fmpk_pos].flag != FMPKS_FLAG_MANOR_PREPARE) ) + { + sprintf(token,"ûмԼսԼսɡ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, token); + + }else if( now_time < fmpks[fmpk_pos].dueltime ){ + + sprintf(token,"ڶսǰһСʱٻԱ!"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, token); + + }else{ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_FMPKCALLMAN_CALL, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); + } + }else{ + sprintf(token,"ûмԼսԼսɡ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, token); + } + } + + } + } else { + if (NPC_Util_GetStrFromStrWithDelim(npcarg, "NoLeaderMsg", buf, + sizeof(buf)) == NULL) + return; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, buf); + } + break; + case 2: + if (NPC_Util_GetStrFromStrWithDelim(npcarg, "LeavepkMsg", buf, + sizeof(buf)) == NULL) + return; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_FMPKCALLMAN_LEAVE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), buf); + break; + } +} + +/*----------------------------------------- + * ͷʧ߯Ȼݱ̫ľ£ + * +-------------------------------------------*/ +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +void NPC_FMPKCallManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int datanum = -1, fl, x, y; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024], buff2[256]; + + int fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + if (NPC_Util_GetArgStr(meindex, npcarg, sizeof(npcarg)) == NULL) + { + print("GetArgStrErr"); + return; + } + NPC_Util_GetStrFromStrWithDelim(npcarg, "WARP", buf, sizeof(buf)); + getStringFromIndexWithDelim(buf, ",", 1, buff2, sizeof(buff2)); + fl = atoi(buff2); + getStringFromIndexWithDelim(buf, ",", 2, buff2, sizeof(buff2)); + x = atoi(buff2); + getStringFromIndexWithDelim(buf, ",", 3, buff2, sizeof(buff2)); + y = atoi(buff2); + + makeStringFromEscaped( data); + + //print("meindex:%d seqno:%d select:%d data:%s\n", meindex, seqno, select, data); + + datanum = atoi( data); + switch( seqno){ + + /*--ԪԻ --*/ + case CHAR_WINDOWTYPE_FMPKCALLMAN_START: + if (datanum == 1) + NPC_FMPKCallMan_selectWindow(meindex, talkerindex, 1, -1); + else if (datanum == 2) + NPC_FMPKCallMan_selectWindow(meindex, talkerindex, 2, -1); + break; + case CHAR_WINDOWTYPE_FMPKCALLMAN_CALL: + if (select == WINDOW_BUTTONTYPE_YES) + { + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nٻСԺ\n磥", buf, sizeof(buf))); + NPC_CallFMMember(meindex, + CHAR_getInt(talkerindex, CHAR_FLOOR), + CHAR_getInt(talkerindex, CHAR_FMINDEX), + CHAR_getChar(talkerindex, CHAR_FMNAME), + CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI)); + } + break; + case CHAR_WINDOWTYPE_FMPKCALLMAN_COME: + if (select == WINDOW_BUTTONTYPE_YES) + { + print("CHAR_WINDOWTYPE_FMPKCALLMAN_COME\n"); + if (CHAR_getWorkInt(talkerindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) + return; + if (CHAR_getWorkInt(talkerindex, CHAR_WORKPARTYMODE) + != CHAR_PARTY_NONE) + CHAR_DischargeParty(talkerindex, 0); + + CHAR_setWorkInt(talkerindex, CHAR_WORKWARPCHECK, FALSE); + CHAR_setWorkInt(talkerindex, CHAR_WORKFMPKFLAG, 1); + CHAR_warpToSpecificPoint(talkerindex, fl, x, y); + } + break; + case CHAR_WINDOWTYPE_FMPKCALLMAN_LEAVE: + if (select == WINDOW_BUTTONTYPE_YES) + { + int spfl = 0, spx = 0, spy = 0, i = 0, itemindex = 0; + if (CHAR_getWorkInt(talkerindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) + return; + if (CHAR_getWorkInt(talkerindex, CHAR_WORKPARTYMODE) + != CHAR_PARTY_NONE) + { + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\n޷Ŷӷʽ뿪ࡣ\nȽɢŶӣ", buf, sizeof(buf))); + return; + } + for (i = 0; i < CheckCharMaxItem(talkerindex); i++) + { + itemindex = CHAR_getItemIndex(talkerindex, i); + if (ITEM_CHECKINDEX(itemindex) == FALSE) continue; + + if (ITEM_getInt(itemindex, ITEM_DROPATLOGOUT) == TRUE) + { + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nйƷร\nΪ˱ڴ;вС𻵣\nȽƷж£\nллĺ", buf, sizeof(buf))); + return; + } + + } + CHAR_setWorkInt(talkerindex, CHAR_WORKWARPCHECK, FALSE); + CHAR_getElderPosition(CHAR_getInt(talkerindex, CHAR_LASTTALKELDER), + &spfl, &spx, &spy); + CHAR_warpToSpecificPoint(talkerindex, spfl, spx, spy); + } + break; + default: + break; + } +} + +extern struct FM_PKFLOOR fmpkflnum[FAMILY_FMPKFLOOR]; +void NPC_CallFMMember(int meindex, int floor, int fmindex, char *fmname, int index) +{ + int i, charindex; + char buf[256]; + extern int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + print("CallFMMember_NPC_meindex:%d\n", meindex); + for( i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex = familyMemberIndex[index][i]; + if( charindex >= 0 ) { + if( CHAR_getCharUse(charindex) ) + { + print("charindex:%d name:%s\n", charindex, CHAR_getChar(charindex, CHAR_NAME)); + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor) continue; + if (CHAR_getWorkInt(charindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE) + { + int fd = getfdFromCharaIndex(charindex); + int charfloor = CHAR_getInt(charindex, CHAR_FLOOR); + int j = 0, checkflag = 0; + if (fd == -1) continue; +#ifdef _FMVER21 + if (CHAR_getInt(charindex, CHAR_FMLEADERFLAG) < 0 || + CHAR_getInt(charindex, CHAR_FMLEADERFLAG) == FMMEMBER_APPLY) continue; +#else + if (CHAR_getInt(charindex, CHAR_FMLEADERFLAG) <= 0 ) continue; +#endif + for (j = 0; j < FAMILY_FMPKFLOOR; j++) + { + if (charfloor == fmpkflnum[j].fl) + checkflag = 1; + } + if (checkflag != 1) + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, CHAR_WINDOWTYPE_FMPKCALLMAN_COME, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + makeEscapeString("\nѾڣУޡҪҪأ\n״̬УŶࡣ", buf, sizeof(buf))); + } + } + else + familyMemberIndex[index][i] = -1; + } + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkman.c new file mode 100644 index 0000000..f05cbfa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmpkman.c @@ -0,0 +1,301 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_fmpkman.h" +#include "npc_scheduleman.h" +#include "npc_fmwarpman.h" +#include "family.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" + +enum { + NPC_WORK_ID = CHAR_NPCWORKINT1, +}; + +static void NPC_FMPKMan_selectWindow(int meindex, int toindex, int num, int select); +// shan add +BOOL NPC_PARTY_CHAECK1(int meindex,int talker); +void NPC_ERR_DiSP1(int meindex,int talker,int errNO); + +/********************************* +* +*********************************/ +BOOL NPC_FMPKManInit( int meindex ) +{ + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + char buff2[256]; + int fl, x, y, meid; + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg)) == NULL){ + print("FMPKMan:GetArgStrErr"); + return FALSE; + } + + /*--ɬýľ¾----*/ + /*--ɬýľئľNPCëئг--*/ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf))==NULL){ + print("FMPKMan Err is %s",npcarg); + print("FMPKMan Err"); + return FALSE; + } + + /*--ɬýľлַƻئľǷNPCëئ--*/ + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl=atoi(buff2); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y=atoi(buff2); + + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "FMWarp NPC:Invalid warpman ERR" ); + return FALSE; + } + + meid = NPC_Util_GetNumFromStrWithDelim(npcarg, "ID"); + if ((meid < 0) || (meid >= MAX_SCHEDULEMAN)) + { + print("FMPKMAN NPC: Init error Invalid ID:%d", meid); + return FALSE; + } + CHAR_setWorkInt(meindex, NPC_WORK_ID, meid); + + /*--ɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWARPMAN ); + + return TRUE; + +} + +/********************************* +* ƾľݼ +*********************************/ +void NPC_FMPKManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + + /*--ͼ--*/ + CHAR_setWorkInt(talkerindex, CHAR_WORKSHOPRELEVANT, 0); + + /*-Ԫ --*/ + NPC_FMPKMan_selectWindow( meindex, talkerindex, 0, -1); +} + +static void NPC_FMPKMan_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024], buf[256], buf2[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex(toindex); + int num1 = 0, num2 = 0; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + + if( fd == -1 ) { + print( "getfd err\n"); + return; + } + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + /*--ɬð̻P ׷ʧѻ϶ýľ¾ľľɰ׷ʧѼԻ*/ + if(strstr(npcarg,"%4d")!=NULL){ + int work; + NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf)); + getStringFromIndexWithDelim(buf,",",1,buf2,sizeof(buf2)); + work = atoi( buf2); + } + + token[0] = '\0'; + + switch(num){ + // ټū + case 0: + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "MainMsg", buf, + sizeof( buf)) == NULL) + return; + sprintf(token, "3\n У˳\n" + "%s" + "\n 쿴˫ " + "\n 뿪У˳ ", + buf); + buttontype = WINDOW_BUTTONTYPE_NONE; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_FMPKMAN_START; + break; + case 1: + if(NPC_Util_GetStrFromStrWithDelim(npcarg, "ViewMsg", buf, + sizeof(token)) == NULL) + return; + NPC_GetPKFMNum(CHAR_getInt(toindex, CHAR_FLOOR), + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + &num1, &num2); +/* + print("host:%s guest:%s hostindex:%d guestindex:%d\n", + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index); +*/ + sprintf(token, "\n%s\n\n%s:%4d\n\n%s:%4d", buf, + fmpks[fmpks_pos].host_name, num1, + fmpks[fmpks_pos].guest_name, num2); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_FMPKMAN_VIEW; + break; + case 2: + if(NPC_Util_GetStrFromStrWithDelim(npcarg, "LeavepkMsg", token, + sizeof(token)) == NULL) + return; + + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_FMPKMAN_LEAVEPK; + break; + default: + break; + } + + /*--޵--*/ + //makeEscapeString( token, escapedname, sizeof(escapedname)); + + + /*--˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + +} + +/*----------------------------------------- + * ͷʧ߯Ȼݱ̫ľ£ + * +-------------------------------------------*/ +void NPC_FMPKManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int datanum = -1, fl, x, y; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024], buff2[256]; + + if (NPC_Util_GetArgStr(meindex, npcarg, sizeof(npcarg)) == NULL) + { + print("GetArgStrErr"); + return; + } + NPC_Util_GetStrFromStrWithDelim(npcarg, "WARP", buf, sizeof(buf)); + getStringFromIndexWithDelim(buf, ",", 1, buff2, sizeof(buff2)); + fl = atoi(buff2); + getStringFromIndexWithDelim(buf, ",", 2, buff2, sizeof(buff2)); + x = atoi(buff2); + getStringFromIndexWithDelim(buf, ",", 3, buff2, sizeof(buff2)); + y = atoi(buff2); + + makeStringFromEscaped( data); + +// print("meindex:%d seqno:%d select:%d data:%s\n", meindex, seqno, select, data); + + datanum = atoi( data); + switch( seqno){ + + /*--ԪԻ --*/ + case CHAR_WINDOWTYPE_FMPKMAN_START: + if (datanum == 1) + NPC_FMPKMan_selectWindow(meindex, talkerindex, 1, -1); + else if (datanum == 2) + NPC_FMPKMan_selectWindow(meindex, talkerindex, 2, -1); + break; + case CHAR_WINDOWTYPE_FMPKMAN_VIEW: + break; + case CHAR_WINDOWTYPE_FMPKMAN_LEAVEPK: + if (select == WINDOW_BUTTONTYPE_YES) + { + if (CHAR_getWorkInt(talkerindex, CHAR_WORKBATTLEMODE) + != BATTLE_CHARMODE_NONE) + return; + + // shan add + if(NPC_PARTY_CHAECK1( meindex, talkerindex)==FALSE){ + NPC_ERR_DiSP1( meindex, talkerindex, 1); + return; + } + + CHAR_setWorkInt(talkerindex, CHAR_WORKWARPCHECK, FALSE); + CHAR_warpToSpecificPoint(talkerindex, fl, x, y); + } + break; + default: + break; + } +} + +// shan add +BOOL NPC_PARTY_CHAECK1(int meindex,int talker) +{ + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + return FALSE; + } + return TRUE; +} + +// shan add errNO=1() +void NPC_ERR_DiSP1(int meindex,int talker,int errNO) +{ + char token[1024]; + int i=0; + int otherindex; + int fd = getfdFromCharaIndex( talker); + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + + if(errNO==1){ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "PartyMsg",token, sizeof( token))==NULL){ + sprintf(token, "޷Ŷ볡\n\nŶӽɢ֮ٸ\n볡"); + } + + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE)==CHAR_PARTY_CLIENT){ + + }else{ + for( i=0 ; i < getPartyNum(talker ) ;i++){ + otherindex=CHAR_getWorkInt(talker,CHAR_WORKPARTYINDEX1+i); + if(otherindex != -1){ + fd = getfdFromCharaIndex( otherindex); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + } + } + return ; + } + } +} + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmwarpman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmwarpman.c new file mode 100644 index 0000000..5389509 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_fmwarpman.c @@ -0,0 +1,1251 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_fmwarpman.h" +#include "npc_scheduleman.h" +#include "readmap.h" +#include "log.h" +#include "battle.h" +#include "handletime.h" +#include "family.h" +#include "errno.h" +#include "configfile.h" + +#ifdef _FM_POINT_PK +extern struct FM_POINTLIST fmpointlist; // ݵ +#endif + +#define FMWARPMAN_INIT_LOOPTIME 600 // 0.1 +#define FMWARPMAN_FREE_LOOPTIME 9000 // 1.5 +#define FMWARPMAN_BUSY_LOOPTIME 3000 // 0.5 +#define FMWARPMAN_WAIT_LOOPTIME 18000 // 3 +#define FMWARPMAN_CLEANPLACE 59 +//#define FMWARPMAN_CLEANPLACE 9 +#define TRUE 1 +#define FALSE 0 +// CoolFish Rem 2002/2/25 +// #define MANOR 4 + +enum { + NPC_WORK_MODEFLAG = CHAR_NPCWORKINT1, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT2, + NPC_WORK_WARPFLOOR = CHAR_NPCWORKINT3, + NPC_WORK_FMNUMI = CHAR_NPCWORKINT4, + NPC_WORK_FMNUMII = CHAR_NPCWORKINT5, + NPC_WORK_ID = CHAR_NPCWORKINT6, + NPC_WORK_TIMEFLAG = CHAR_NPCWORKINT9, + NPC_WORK_TALKFLAG = CHAR_NPCWORKINT10, + NPC_WORK_CleanTime = CHAR_NPCWORKINT11, +}; + +enum { + NPC_STATEINIT, + NPC_STATEFREE, + NPC_STATEBUSY, + NPC_STATEWAIT, +}; + +enum { + NPC_WORK_WINFMNAME = CHAR_NPCWORKCHAR1, +}; + +void NPC_ERR_FMDiSP(int meindex, int talker, int errNO); +static void NPC_FMWarpMan_selectWindow(int meindex, int toindex, int num, int select); +void NPC_FMBATTLESET(int floor, int index1, int index2, int flag); +void NPC_WarpFamily(int floor, int index1, int index2, int fl, int x, int y); +void NPC_BattleOut(int fmindex, int fmindex1); +void NPC_CleanPK(int floor, int meindex); +int NPC_FMFloorUse(int floor); +void NPC_talkToFloor(int floor, int index1, int index2, char *data); +void CheckLeavePK(int npcindex, int floor, int index1, int index2); + +void CHECK_FMPknumInFloor( int meindex) +{ + int fmnum1 = 0, fmnum2 = 0; + int fmpks_pos; + + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + // Nuke 20040920: Bug fix ׯ԰ʱҪ + //print("<<%d %d>>",fmpks_pos,MAX_SCHEDULEMAN); + //if( fmpks_pos < 0 || fmpks_pos >= MAX_SCHEDULEMAN ) return; + if( fmpks_pos < 0 || fmpks_pos >= MAX_SCHEDULEMAN * MAX_SCHEDULE ) return; + NPC_GetPKFMNum(CHAR_getWorkInt(meindex, NPC_WORK_WARPFLOOR), + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + &fmnum1, &fmnum2 ); + + CHAR_setWorkInt( meindex, NPC_WORK_FMNUMI , fmnum1); + CHAR_setWorkInt( meindex, NPC_WORK_FMNUMII, fmnum2); +} + +extern int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; + +BOOL NPC_FMWarpManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[256]; + char buf[1024]; + int fl, x, y, meid; + // shan + int fl1, x1, y1; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("FMWarpMan:GetArgStrErr"); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP1", buf, sizeof( buf))==NULL){ + print("FMWarpman Err is %s",npcarg); + print("FMWarpman Err"); + return FALSE; + } + + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl=atoi(buff2); + CHAR_setWorkInt(meindex, NPC_WORK_WARPFLOOR, fl); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y=atoi(buff2); + + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "FMWarp NPC:Invalid warpman ERR" ); + return FALSE; + } + + // shan begin + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP2", buf, sizeof( buf))==NULL){ + print("FMWarpman Err is %s",npcarg); + print("FMWarpman Err"); + return FALSE; + } + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl1=atoi(buff2); + CHAR_setWorkInt(meindex, NPC_WORK_WARPFLOOR, fl); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x1=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y1=atoi(buff2); + if( MAP_IsValidCoordinate( fl1,x1,y1 )== FALSE ){ + print( "FMWarp NPC:Invalid warpman ERR" ); + return FALSE; + } + // shan end + + meid = NPC_Util_GetNumFromStrWithDelim(npcarg, "ID"); + if ((meid < 0) || (meid >= MAX_SCHEDULEMAN)) + { + print("FMWARP NPC: Init error invalid ID:%d\n", meid); + return FALSE; + } + + /*--ɬ--*/ + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_INIT_LOOPTIME); + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWARPMAN ); + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEINIT); + CHAR_setWorkInt(meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + CHAR_setWorkInt(meindex, NPC_WORK_TIMEFLAG, 0); + CHAR_setWorkInt(meindex, NPC_WORK_TALKFLAG, -1); + CHAR_setWorkInt(meindex, NPC_WORK_ID, meid); + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMI, 0); + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMII, 0); + + CHAR_setWorkInt( meindex, NPC_WORK_CleanTime, 6*10); + + return TRUE; +} + +void NPC_FMWarpManTalked(int meindex, int talkerindex, char *szMes, int color) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2)==FALSE){ + if(NPC_Util_isFaceToChara(talkerindex,meindex,1 )==FALSE) return; + } + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + + if(CHAR_getWorkInt(talkerindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + NPC_ERR_FMDiSP( meindex, talkerindex, 1); + } + + CHAR_setWorkInt( talkerindex , CHAR_WORKSHOPRELEVANTTRD , 0 ); + NPC_FMWarpMan_selectWindow( meindex, talkerindex, 0, -1); +} + +void NPC_FMWarpManLoop(int meindex) +{ + struct tm tm1; + struct tm *tm2; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + int floor = CHAR_getWorkInt(meindex, NPC_WORK_WARPFLOOR); + // WON ADD snprintfᵼµbug + if( (tm2=localtime((time_t *)&NowTime.tv_sec) ) == NULL ){ + print("\n won ==> time err !! "); + return; + } + memcpy(&tm1, localtime((time_t *)&NowTime.tv_sec), sizeof(tm1)); + + if (tm1.tm_min == 0) + CHAR_setWorkInt(meindex, NPC_WORK_TIMEFLAG, tm1.tm_min); + if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEINIT) + { + if (tm1.tm_sec == 0) + { + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEFREE); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_FREE_LOOPTIME); + } + } + if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEFREE) + { + // ȡĿǰϵͳʱ䣬Ŀǰʱ >= ׼ʱ趨£գӣ״̬ + + if (tm1.tm_min > CHAR_getWorkInt(meindex, NPC_WORK_TALKFLAG) + && tm1.tm_min == 0) + { + // ֪ͨԱ + if (fmpks[fmpks_pos].flag == FMPKS_FLAG_SCHEDULED) + NPC_talkToFloor(CHAR_getInt(meindex, CHAR_FLOOR), + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, "׼ˣ"); + CHAR_setWorkInt(meindex, NPC_WORK_TALKFLAG, tm1.tm_min); + } + if ((fmpks[fmpks_pos].prepare_time > 0) && (fmpks[fmpks_pos].flag == FMPKS_FLAG_SCHEDULED)) + { + int clock = 0; + + NPC_FMBATTLESET(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, -1); + if (tm1.tm_hour - (fmpks[fmpks_pos].dueltime / 100) < 0) + clock = (fmpks[fmpks_pos].dueltime % 100) + fmpks[fmpks_pos].prepare_time - 60; + else + clock = fmpks[fmpks_pos].dueltime - (tm1.tm_hour * 100) + fmpks[fmpks_pos].prepare_time; + + if ((tm1.tm_min >= clock) && (fmpks[fmpks_pos].prepare_time > 0)) + { + + NPC_talkToFloor(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, "սޡ"); +#ifdef _FMPOINT_PK_MESSAGE + char token[256]; + sprintf(token, "ׯ԰Ȩս%s ֣ %sսޡ", + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].host_name); + CHAR_talkToAll(-1, token, CHAR_COLORGREEN); +#endif + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEBUSY); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_BUSY_LOOPTIME); + NPC_FMBATTLESET(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, 1); + +// print("\n won ==> set fmwaperman state busy !!"); + } + else if (tm1.tm_min > CHAR_getWorkInt(meindex, NPC_WORK_TIMEFLAG)) + { + char buf[256]; + int clock = 0; + CHAR_setWorkInt(meindex, NPC_WORK_TIMEFLAG, tm1.tm_min); + clock = ((fmpks[fmpks_pos].dueltime % 100) + fmpks[fmpks_pos].prepare_time) - tm1.tm_min; + if (clock >= 60) clock = clock - 60; + sprintf(buf, "սʱ仹ʣ£%4d", clock); + NPC_talkToFloor(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, buf); + } + } + }else if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEBUSY){ + // 鳡жʤ + int num1 = 0, num2 = 0; + int winflag = 0; + int floor = CHAR_getWorkInt(meindex, NPC_WORK_WARPFLOOR); + int meid = CHAR_getWorkInt(meindex, NPC_WORK_ID); + +// print("\n won ==> check_winner : npc_meid(%d)", meid ); + + NPC_GetPKFMNum(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, &num1, &num2); + NPC_FMBATTLESET(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, 1); + CheckLeavePK(meindex, floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index); + + if (meid > MANORNUM){ + if (tm1.tm_min == FMWARPMAN_CLEANPLACE){ + // жʤWARP볡趨ΣУ״̬ + NPC_BattleOut(fmpks[fmpks_pos].host_index, fmpks[fmpks_pos].guest_index); + NPC_FMBATTLESET(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, -1); + if (fmpks[fmpks_pos].win == 0){// ս + if (num1 > num2) + winflag = 1; + else if(num1 < num2) + winflag = 2; + else + winflag = 3; + }else if (fmpks[fmpks_pos].win == 1){ // ս + if ((CHAR_getWorkInt(meindex, NPC_WORK_FMNUMI) - num1) < (CHAR_getWorkInt(meindex, NPC_WORK_FMNUMII) - num2)) + winflag = 1; + else if ((CHAR_getWorkInt(meindex, NPC_WORK_FMNUMI) - num1) > (CHAR_getWorkInt(meindex, NPC_WORK_FMNUMII) - num2)) + winflag = 2; + else + winflag = 3; + } + } + } + if ((num1 == 0) && (num2 != 0)){ + winflag = 2; + }else if ((num2 == 0) && (num1 != 0)){ + winflag = 1; + }else if ((num1 == 0) && (num2 == 0)){ + winflag = 3; + } + if (winflag > 0 && winflag < 3){ +#ifdef _MANOR_PKRULE + if(meid > MANORNUM){ +#endif + // ˼pk + if (winflag == 1){ + saacproto_ACFixFMPK_send(acfd, + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index + 1, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index + 1, + fmpks[fmpks_pos].guest_index); + } else { + saacproto_ACFixFMPK_send(acfd, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index + 1, + fmpks[fmpks_pos].guest_index, + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index + 1, + fmpks[fmpks_pos].host_index); + } +#ifdef _MANOR_PKRULE + } +#endif + + { + if (meid > 0 && meid <= MANORNUM){// CoolFish 2002/2/25 Change MANOR -> MANORNUM +#ifdef _NEW_MANOR_LAW + int i,iFmIndex1,iFmIndex2,iCharindex; +#endif + fmpks[fmpks_pos + 1].flag = FMPKS_FLAG_MANOR_BATTLEEND; + if (winflag == 1){ + char token[256]; + sprintf( token, " (%d:%d) %d/%d/%d", + tm1.tm_hour, tm1.tm_min, + tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday); + saacproto_ACFixFMPoint_send(acfd, + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index + 1, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index + 1, + fmpks[fmpks_pos].guest_index, meid); + //Syu ׯ԰սʤLog + Logfmpk( + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index, + num1, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index, + num2, token, "", "", 2); +#ifdef _NEW_MANOR_LAW + // ԭסׯ԰,Աɵõʯ + iFmIndex1 = fmpks[fmpks_pos].host_index; + for(i=0;i= 0 && CHAR_getCharUse(iCharindex)){ + // ýǮ = * 5000 + int iAddGold = ((float)CHAR_getInt(iCharindex,CHAR_MOMENTUM)/100.0f)/* * 5000.0f */; + int iGold = CHAR_getInt(iCharindex,CHAR_BANKGOLD),iMaxGold; + // ȷ + if(iGold + iAddGold > CHAR_MAXBANKGOLDHAVE){ + CHAR_setInt(iCharindex,CHAR_BANKGOLD,CHAR_MAXBANKGOLDHAVE); + // зŲ,ŵ + iAddGold = iGold + iAddGold - CHAR_MAXBANKGOLDHAVE; + iGold = CHAR_getInt(iCharindex,CHAR_GOLD); + iMaxGold = CHAR_getMaxHaveGold(iCharindex); + if(iGold + iAddGold > iMaxGold) CHAR_setInt(iCharindex,CHAR_GOLD,iMaxGold); + else CHAR_setInt(iCharindex,CHAR_GOLD,iGold + iAddGold); + LogFMPKGetMomey(CHAR_getChar(iCharindex,CHAR_FMNAME), + CHAR_getChar(iCharindex,CHAR_CDKEY), + CHAR_getChar(iCharindex,CHAR_NAME), + CHAR_getInt(iCharindex,CHAR_MOMENTUM),iAddGold,0); + } + else{ + CHAR_setInt(iCharindex,CHAR_BANKGOLD,iGold + iAddGold); + LogFMPKGetMomey(CHAR_getChar(iCharindex,CHAR_FMNAME), + CHAR_getChar(iCharindex,CHAR_CDKEY), + CHAR_getChar(iCharindex,CHAR_NAME), + CHAR_getInt(iCharindex,CHAR_MOMENTUM),iAddGold,1); + } + CHAR_talkToCli(iCharindex,-1,"!ػסׯ԰Ľѻĸ",CHAR_COLORRED); + } + } +#else + + int iFmIndex1 = fmpks[fmpks_pos].guest_index; + int i; + for(i=0;i= 0 && CHAR_getCharUse(iCharindex)){ + if( CHAR_getInt( meindex, CHAR_RIDEPET ) != -1 ) + { + int rideindex = CHAR_getCharPet( iCharindex, CHAR_getInt( iCharindex, CHAR_RIDEPET) ); + + if( CHAR_getInt( rideindex, CHAR_BASEBASEIMAGENUMBER) == 100372 || CHAR_getInt( rideindex, CHAR_BASEBASEIMAGENUMBER) == 100373 ) + { + CHAR_setInt( iCharindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( iCharindex, CHAR_P_STRING_RIDEPET ); + + CHAR_sendStatusString(iCharindex, "f"); + CHAR_complianceParameter( iCharindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( iCharindex , CHAR_WORKOBJINDEX )); + } + } + } + } +#endif + } + else if (winflag == 2){ + char token[256]; + sprintf( token, " (%d:%d) %d/%d/%d", + tm1.tm_hour, tm1.tm_min, + tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday); +#ifdef _FM_POINT_PK + int fmid; + char fmindex[4]; + for (fmid=0; fmid= 0 && CHAR_getCharUse(iCharindex)){ + if( CHAR_getInt( meindex, CHAR_RIDEPET ) != -1 ) + { + int rideindex = CHAR_getCharPet( iCharindex, CHAR_getInt( iCharindex, CHAR_RIDEPET) ); + + if( CHAR_getInt( rideindex, CHAR_BASEBASEIMAGENUMBER) == 100372 || CHAR_getInt( rideindex, CHAR_BASEBASEIMAGENUMBER) == 100373 ) + { + CHAR_setInt( iCharindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( iCharindex, CHAR_P_STRING_RIDEPET ); + + CHAR_sendStatusString(iCharindex, "f"); + CHAR_complianceParameter( iCharindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( iCharindex , CHAR_WORKOBJINDEX )); + } + } + } + } + } +#ifdef _FM_POINT_PK + if(fmid>=0 && fmid= 0 && CHAR_getCharUse(iCharindex)){ + CHAR_setInt(iCharindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(iCharindex,-1,"ׯ԰ս˼ƹ",CHAR_COLORRED); + } + iCharindex = familyMemberIndex[iFmIndex2][i]; + if(iCharindex >= 0 && CHAR_getCharUse(iCharindex)){ + CHAR_setInt(iCharindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(iCharindex,-1,"ׯ԰ս˼ƹ",CHAR_COLORRED); + } + } +#endif + } + } + if (winflag == 1) + { + CHAR_setWorkChar(meindex, NPC_WORK_WINFMNAME, fmpks[fmpks_pos].host_name); + } + else if (winflag == 2) + { + CHAR_setWorkChar(meindex, NPC_WORK_WINFMNAME, fmpks[fmpks_pos].guest_name); + } + NPC_WarpFamily(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + CHAR_getInt(meindex, CHAR_FLOOR), + CHAR_getInt(meindex, CHAR_X), + CHAR_getInt(meindex, CHAR_Y)); + if (meid > MANORNUM){// CoolFish 2002/2/25 Change MANOR -> MANORNUM + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEWAIT); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_WAIT_LOOPTIME); + } + }else if( winflag == 3 ){ + if (meid > 0 && meid <= MANORNUM){ // CoolFish 2002/2/25 Change MANOR -> MANORNUM + char token[256]; + sprintf( token, " (%d:%d) %d/%d/%d", + tm1.tm_hour, tm1.tm_min, + tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday); + fmpks[fmpks_pos + 1].flag = FMPKS_FLAG_MANOR_BATTLEEND; + saacproto_ACFixFMPoint_send(acfd, + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index + 1, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index + 1, + fmpks[fmpks_pos].guest_index, meid); + //Syu ׯ԰սʤLog + Logfmpk( + fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].guest_index, + num2, + fmpks[fmpks_pos].host_name, + fmpks[fmpks_pos].host_index, + num1, token, "", "", 2); +#ifdef _NEW_MANOR_LAW + int i,iFmIndex1,iFmIndex2,iCharindex; + // ˫ĸ˼ƶҪ + iFmIndex1 = fmpks[fmpks_pos].host_index; + iFmIndex2 = fmpks[fmpks_pos].guest_index; + for(i=0;i= 0 && CHAR_getCharUse(iCharindex)){ + CHAR_setInt(iCharindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(iCharindex,-1,"ׯ԰ս˼ƹ",CHAR_COLORRED); + } + iCharindex = familyMemberIndex[iFmIndex2][i]; + if(iCharindex >= 0 && CHAR_getCharUse(iCharindex)){ + CHAR_setInt(iCharindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(iCharindex,-1,"ׯ԰ս˼ƹ",CHAR_COLORRED); + } + } +#endif + } + NPC_talkToFloor(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, "˫ƽ֣ʤ"); + NPC_WarpFamily(floor, fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + CHAR_getInt(meindex, CHAR_FLOOR), + CHAR_getInt(meindex, CHAR_X), + CHAR_getInt(meindex, CHAR_Y)); + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEWAIT); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_WAIT_LOOPTIME); + } + }else if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEWAIT){ + + // andy_edit 2002/07/29 + if (tm1.tm_min == FMWARPMAN_CLEANPLACE) + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_FREE_LOOPTIME); + + NPC_CleanPK(floor, meindex); + + if (tm1.tm_min == 0){ + CHAR_setWorkInt(meindex, NPC_WORK_MODEFLAG, NPC_STATEFREE); + // shan add + NPC_FMBATTLESET(floor, fmpks[fmpks_pos].host_index, fmpks[fmpks_pos].guest_index, -1); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, FMWARPMAN_FREE_LOOPTIME); + // fmwarpman ʼ + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMI, 0); + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMII, 0); + CHAR_setWorkInt(meindex, NPC_WORK_TIMEFLAG, 0); + CHAR_setWorkInt(meindex, NPC_WORK_TALKFLAG, -1); + CHAR_setWorkChar(meindex, NPC_WORK_WINFMNAME, ""); + } + } +} + +void NPC_FMWarpManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024], buff2[256], tmpbuf[256]; + int fl, x, y, fmpks_pos, fd; + + if( !CHAR_CHECKINDEX( talkerindex) )return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + if(select==WINDOW_BUTTONTYPE_OK){ + return; + } + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + // shan add + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + + if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index){ + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP1", buf, sizeof( buf)) == NULL ){ + print("FM WARPMAN Can't Read WARP1!\n"); + return; + } + }else if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index){ + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP2", buf, sizeof( buf)) == NULL ){ + print("FM WARPMAN Can't Read WARP2!\n"); + return; + } + }else{ + CHAR_talkToCli( talkerindex, meindex, "㲢Ƕս˫һԱ", CHAR_COLORYELLOW); + return; + } + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl=atoi(buff2); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y=atoi(buff2); + + + switch (seqno){ + case CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN: + if(select==WINDOW_BUTTONTYPE_YES){ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return; + if(CHAR_getWorkInt(talkerindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + CHAR_talkToCli( talkerindex, meindex, "ɢŶӣ", CHAR_COLORYELLOW); + return; + } + + if(CHAR_getWorkInt( talkerindex , CHAR_WORKSHOPRELEVANTTRD) <= 0){ + if( CHAR_getWorkInt( talkerindex, CHAR_WORKWARPCHECK ) == TRUE ) { + if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEFREE){ + if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index){ + int tmpnum1 = CHAR_getWorkInt(meindex, NPC_WORK_FMNUMI) + 1; + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMI, tmpnum1); + }else if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index){ + int tmpnum2 = CHAR_getWorkInt(meindex, NPC_WORK_FMNUMII) + 1; + CHAR_setWorkInt(meindex, NPC_WORK_FMNUMII, tmpnum2); + }else{ + CHAR_talkToCli( talkerindex, meindex, "㲢Ƕս˫һԱ", CHAR_COLORYELLOW); + } + CHAR_setWorkInt(talkerindex, CHAR_WORKFMPKFLAG, 1); + CHAR_setWorkInt(talkerindex, CHAR_WORKFMMANINDEX, meindex); + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); + CHAR_warpToSpecificPoint(talkerindex, fl, x,y); +/* { + FILE *fp; + struct tm tm1; + char szFileName[128]; + + memcpy(&tm1, localtime((time_t *)&NowTime.tv_sec), sizeof(tm1)); + memset(szFileName,0,sizeof(szFileName)); + sprintf(szFileName,"FMPkWarp.%d%d%d.log",tm1.tm_mon,tm1.tm_hour,tm1.tm_min); + fp = fopen(szFileName,"a+"); + if(fp != NULL){ + fprintf(fp,"FMName:%s\tName:%s\tWarpHost:%d\tWarpGuest:%d\tFloor:%d,%d,%d\tMaxPlayer:%d\n", + CHAR_getChar(talkerindex,CHAR_FMNAME),CHAR_getChar(talkerindex,CHAR_NAME), + CHAR_getWorkInt(meindex,NPC_WORK_FMNUMI), + CHAR_getWorkInt(meindex,NPC_WORK_FMNUMII), + fl,x,y, + fmpks[fmpks_pos].max_player); + fclose(fp); + } + else printf("%s(errno:%x)\n",sys_errlist[errno],errno); + } +*/ + } + else return; + { + struct tm tm1; + int clock = 0; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + memcpy(&tm1, localtime((time_t *)&NowTime.tv_sec), sizeof(tm1)); + clock = ((fmpks[fmpks_pos].dueltime % 100) + fmpks[fmpks_pos].prepare_time) - tm1.tm_min; + if (clock >= 60) clock = clock - 60; + sprintf(tmpbuf, "\nȺ˫׼ٿս" + "\nսʱ벻Ҫdz뿪" + "\nӮʤļҲһ£" + "\nȴе볡" + "\nллĺ" + "\nսʱ仹ʣ£%4d", + clock); + lssproto_WN_send(fd, + WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString(tmpbuf, buff2, sizeof(buff2))); + } + } + } + else{ + if(CHAR_getInt(talkerindex,CHAR_GOLD) < CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)){ + NPC_ERR_FMDiSP( meindex, talkerindex, 2); + return ; + } + CHAR_DelGold( talkerindex, CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD )); + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); + CHAR_warpToSpecificPoint(talkerindex, fl, x,y); + } + } + break; + } +} + +void NPC_ERR_FMDiSP(int meindex,int talker,int errNO) +{ + + char token[1024]; + int i=0; + int otherindex; + int fd = getfdFromCharaIndex( talker); + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + + if(errNO==1){ + /*--ɡ ūƥ ƾ--*/ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "PartyMsg",token, sizeof( token))==NULL) { + /*--ɬýľئľɣƱë--*/ + sprintf(token, "\n\n޷ŶӣȽɢŶӣ"); + } + + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE)==CHAR_PARTY_CLIENT){ + + }else{ + + /*--ĸ ƾ--*/ + /*--ɡ ū幻嶪ë--*/ + for( i=0 ; i < getPartyNum(talker ) ;i++) + { + otherindex=CHAR_getWorkInt(talker,CHAR_WORKPARTYINDEX1+i); + + if(otherindex != -1){ + fd = getfdFromCharaIndex( otherindex); + + /*-ƥ˪--*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + } + } + return ; + } + + }else if (errNO==2){ + /*--ŻԻئƥʣ--*/ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "MoneyMsg", token, sizeof( token))==NULL){ + /*--ŻԻئмɬýľئգƱë Ի--*/ + sprintf(token,"\n\nǮƺࡣǮٹ"); + } + } + + /*-ƥ˪--*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +static void NPC_FMWarpMan_selectWindow( int meindex, int toindex, int num,int select) +{ + struct tm tm1; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + char buf[256]; + char buf2[1024]; + char buf3[256]; + int fl = 0, num1 = 0, num2 = 0; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + int floor = CHAR_getWorkInt(meindex, NPC_WORK_WARPFLOOR); + int fd = getfdFromCharaIndex( toindex); + if( fd == -1 ) { + fprint( "getfd err\n"); + return; + } + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + /*--ɬð̻P ׷ʧѻ϶ýľ¾ľľɰ׷ʧѼԻ*/ + if(strstr(npcarg,"%4d")!=NULL){ + NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP1", buf, sizeof( buf)); + getStringFromIndexWithDelim(buf,",",1,buf3,sizeof(buf3)); + fl = NPC_FMFloorUse(atoi(buf3)); + } + + //޼ʹϵͳ + if (CHAR_getInt(toindex, CHAR_FMLEADERFLAG) == FMMEMBER_NONE) + { + char tmpbuf[256]; + sprintf(tmpbuf, "\n㻹ûʽ壬Բܽ"); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString(tmpbuf, token, sizeof(token))); + return; + } + + CHAR_setWorkInt(toindex, CHAR_WORKWARPCHECK, TRUE); + CHAR_setWorkInt(toindex, NPC_WORK_WARPFLOOR, fl); + memcpy(&tm1, localtime((time_t *)&NowTime.tv_sec), sizeof(tm1)); + + if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEFREE) + { + if (((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].guest_name) == 0))) + { + if ((fmpks[fmpks_pos].host_index != -1) + && (CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index)) + { + // WON ADD pkԼս + + if(fmpks[fmpks_pos].flag == -1) return; + + if (fmpks[fmpks_pos].flag != FMPKS_FLAG_SCHEDULED) + + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nⳡսԷûͬأ\n´ǵԼԷǼǰɡ", token, sizeof(token))); + return; + } +#ifdef _FMVER21 + if (CHAR_getInt(toindex, CHAR_FMLEADERFLAG) == FMMEMBER_APPLY) +#else + if (CHAR_getInt(toindex, CHAR_FMLEADERFLAG) == 0) +#endif + { + char tmpbuf[256]; + sprintf(tmpbuf, "\n㻹ûʽ%s壬Բܽ", fmpks[fmpks_pos].host_name); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString(tmpbuf, token, sizeof(token))); + return; + } + //andy_add 2003/06/17 + CHECK_FMPknumInFloor( meindex); + if (CHAR_getWorkInt(meindex, NPC_WORK_FMNUMI) > (fmpks[fmpks_pos].max_player - 1)){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, makeEscapeString("\nѾٽȥޡ\nѾ趨ˣ", token, sizeof(token))); + return; + } + } + else if ((fmpks[fmpks_pos].guest_index != -1) + && (CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index)) + { + // WON ADD pkԼս + + if(fmpks[fmpks_pos].flag == -1) return; + + if (fmpks[fmpks_pos].flag != FMPKS_FLAG_SCHEDULED) + + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("\nⳡսûͬأ\n´ǵȷϡ", token, sizeof(token))); + return; + } +#ifdef _FMVER21 + if (CHAR_getInt(toindex, CHAR_FMLEADERFLAG) == FMMEMBER_APPLY) +#else + if (CHAR_getInt(toindex, CHAR_FMLEADERFLAG) == 0) +#endif + { + char tmpbuf[256]; + sprintf(tmpbuf, "\n㻹ûʽ%s壬Բܽ", fmpks[fmpks_pos].guest_name); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString(tmpbuf, token, sizeof(token))); + return; + } + //andy_add 2003/06/17 + CHECK_FMPknumInFloor( meindex); + if( CHAR_getWorkInt( meindex, NPC_WORK_FMNUMII) > (fmpks[fmpks_pos].max_player - 1)){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString("Ѿٽȥޡ\nѾ趨ˣ", token, sizeof(token))); + return; + } + } + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "FreeMsg", buf2, sizeof( buf2)) == NULL) return; + CONNECT_set_pass(fd, TRUE); + CONNECT_set_first_warp(fd, TRUE); + sprintf(token, buf2, fmpks[fmpks_pos].guest_name, fmpks[fmpks_pos].host_name, + tm1.tm_hour, tm1.tm_min); + CHAR_setWorkInt( toindex , CHAR_WORKFMMANINDEX, meindex ); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANTTRD , -1 ); + } else if ((((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].guest_name) == 0))) + && (((fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_SCHEDULED) + || (fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_PREPARE))) + ) + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NextMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2, fl, tm1.tm_hour, tm1.tm_min); + CONNECT_set_pass(fd, FALSE); + CONNECT_set_first_warp(fd, FALSE); + } + else if ((strcmp(fmpks[fmpks_pos].host_name, "") == 0) || (strcmp(fmpks[fmpks_pos].guest_name, "") == 0)) + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "TalkMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2); + CONNECT_set_pass(fd, FALSE); + CONNECT_set_first_warp(fd, FALSE); + } + else + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "AskMsg", buf2, sizeof( buf2)) == NULL) return; + CONNECT_set_pass(fd, FALSE); + CONNECT_set_first_warp(fd, FALSE); + sprintf(token, buf2, fmpks[fmpks_pos].guest_name, fmpks[fmpks_pos].host_name); + } + } + else if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEBUSY) // ս + { + if (((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].guest_name) == 0))) + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "BusyMsg", buf2, sizeof( buf2)) == NULL){ + print("\nGet BusyMsg Message Error"); + return; + } + NPC_GetPKFMNum(floor, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + &num1, &num2); + sprintf(token, buf2, + fmpks[fmpks_pos].host_name, num1, + fmpks[fmpks_pos].guest_name, num2, + tm1.tm_hour, tm1.tm_min); + } else if ((((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].guest_name) == 0))) + && (((fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_SCHEDULED) + || (fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_PREPARE))) + ) + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NextMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2, fl, tm1.tm_hour, tm1.tm_min); + } else { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "AskMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2, fmpks[fmpks_pos].guest_name, fmpks[fmpks_pos].host_name); + } + CONNECT_set_pass(fd, FALSE); + CONNECT_set_first_warp(fd, FALSE); + } + else if (CHAR_getWorkInt(meindex, NPC_WORK_MODEFLAG) == NPC_STATEWAIT) // ս + { + if (((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos].guest_name) == 0))) + { + char tmpbuf[256]; + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "EndMsg", buf2, sizeof( buf2)) == NULL){ + print("\nGet EndMsg Message Error"); + return; + } + NPC_GetPKFMNum(floor, + fmpks[fmpks_pos].host_index, + fmpks[fmpks_pos].guest_index, + &num1, &num2); + if (strcmp(CHAR_getWorkChar(meindex, NPC_WORK_WINFMNAME), "") == 0) + sprintf(tmpbuf, "˫ƽ֣"); + else sprintf(tmpbuf, "%sʤˣ", CHAR_getWorkChar(meindex, NPC_WORK_WINFMNAME)); + sprintf(token, buf2, fmpks[fmpks_pos].guest_name, + fmpks[fmpks_pos].host_name, tmpbuf); + } else if ((((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].host_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].host_name) == 0)) + || ((CHAR_getWorkInt(toindex, CHAR_WORKFMINDEXI) == fmpks[fmpks_pos + 1].guest_index) + && (strcmp(CHAR_getChar(toindex, CHAR_FMNAME), fmpks[fmpks_pos + 1].guest_name) == 0))) + && (((fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_SCHEDULED) + || (fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_PREPARE))) + ) + { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NextMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2, fl, tm1.tm_hour, tm1.tm_min); + } else { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "AskMsg", buf2, sizeof( buf2)) == NULL) return; + sprintf(token, buf2, fmpks[fmpks_pos].guest_name, fmpks[fmpks_pos].host_name); + } + CONNECT_set_pass(fd, FALSE); + CONNECT_set_first_warp(fd, FALSE); + } + /*-ƥ˪--*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + +} + +int NPC_FMFloorUse(int floor) +{ + int i; + int players = 0; + int playernum = CHAR_getPlayerMaxNum(); + + /* */ + for( i=0 ; i< playernum ; i++ ){ + if( CHAR_getCharUse(i) == FALSE )continue; + if(CHAR_getInt(i,CHAR_FLOOR)==floor){ + players++; + } + } + return players; +} + +void NPC_GetPKFMNum(int floor, int index1, int index2, int *num1, int *num2) +{ + int i = 0, charindex; + + *num1 = 0; *num2 = 0; + + /* */ + for (i = 0 ; i < FAMILY_MAXMEMBER; i++ ){ + charindex = familyMemberIndex[ index1][i]; + if( CHAR_getCharUse( charindex) ){ + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor) + *num1 = *num1 + 1; + }else + familyMemberIndex[ index1][i] = -1; + + charindex = familyMemberIndex[index2][i]; + if (CHAR_getCharUse(charindex)){ + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor) + *num2 = *num2 + 1; + }else + familyMemberIndex[ index2][i] = -1; + } + +} + +void NPC_FMBATTLESET(int floor, int index1, int index2, int flag) +{ + int i = 0, charindex; + + for (i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex = familyMemberIndex[index1][i]; + if (CHAR_getCharUse(charindex)) + { + if (CHAR_getInt(charindex ,CHAR_FLOOR) == floor) + { + CHAR_setWorkInt( charindex, CHAR_WORKBATTLEFLAG, flag); + if(flag==1) + CHAR_setFlg(charindex, CHAR_ISDUEL, 1); + } + } + else + familyMemberIndex[index1][i] = -1; + charindex = familyMemberIndex[index2][i]; + if (CHAR_getCharUse(charindex)) + { + if (CHAR_getInt(charindex ,CHAR_FLOOR) == floor) + { + CHAR_setWorkInt( charindex, CHAR_WORKBATTLEFLAG, flag); + if(flag==1) + CHAR_setFlg(charindex, CHAR_ISDUEL, 1); + } + } + else + familyMemberIndex[index2][i] = -1; + } +} + +void NPC_CleanPK(int floor, int meindex) +{ + int i; + int playernum = CHAR_getPlayerMaxNum(); + int fl = CHAR_getInt(meindex, CHAR_FLOOR); + int x = CHAR_getInt(meindex, CHAR_X); + int y = CHAR_getInt(meindex, CHAR_Y); + + for( i=0 ; i< playernum ; i++ ) + { + if( CHAR_getCharUse(i) == FALSE )continue; + if(CHAR_getInt(i,CHAR_FLOOR)==floor) + CHAR_warpToSpecificPoint(i, fl, x, y); + } +} + +void NPC_talkToFloor(int floor, int index1, int index2, char *data) +{ + int i = 0, charindex; + + for (i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex = familyMemberIndex[index1][i]; + if (CHAR_getCharUse(charindex)) + { +// print("charname:%s fmname:%s\n", +// CHAR_getChar(charindex, CHAR_NAME), +// CHAR_getChar(charindex, CHAR_FMNAME)); + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor) + CHAR_talkToCli(charindex, -1, data, CHAR_COLORYELLOW); + } + else + familyMemberIndex[index1][i] = -1; + charindex = familyMemberIndex[index2][i]; + if (CHAR_getCharUse(charindex)) + { +// print("charname:%s fmname:%s\n", +// CHAR_getChar(i, CHAR_NAME), +// CHAR_getChar(i, CHAR_FMNAME)); + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor) + CHAR_talkToCli(charindex, -1, data, CHAR_COLORRED); + } + else + familyMemberIndex[index2][i] = -1; + } +} + +void NPC_WarpFamily(int floor, int index1, int index2, int fl, int x, int y) +{ + int i, charindex1, charindex2; + + for (i = 0; i < FAMILY_MAXMEMBER; i++){ + charindex1 = familyMemberIndex[index1][i]; + charindex2 = familyMemberIndex[index2][i]; + if (CHAR_getCharUse(charindex1)) + { + if (CHAR_getInt(charindex1, CHAR_FLOOR) == floor) + { + CHAR_setWorkInt(charindex1, CHAR_WORKBATTLEFLAG, FALSE); + CHAR_warpToSpecificPoint(charindex1, fl, x, y); + } + } + else + familyMemberIndex[index1][i] = -1; + if (CHAR_getCharUse(charindex2)) + { + if (CHAR_getInt(charindex2, CHAR_FLOOR) == floor) + { + CHAR_setWorkInt(charindex2, CHAR_WORKBATTLEFLAG, FALSE); + CHAR_warpToSpecificPoint(charindex2, fl, x, y); + } + } + else + familyMemberIndex[index1][i] = -1; + } +} + +void NPC_BattleOut(int index1, int index2) +{ + int i, charindex1, charindex2; + + for (i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex1 = familyMemberIndex[index1][i]; + charindex2 = familyMemberIndex[index2][i]; + if(CHAR_getCharUse(charindex1)){ + if(CHAR_getWorkInt( charindex1, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + BATTLE_WatchStop(charindex1); + } + else + familyMemberIndex[index1][i] = -1; + + if(CHAR_getCharUse(charindex2)){ + if(CHAR_getWorkInt( charindex2, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + BATTLE_WatchStop(charindex2); + } + else + familyMemberIndex[index2][i] = -1; + } +} + +void CheckLeavePK(int npcindex, int floor, int index1, int index2) +{ + int i = 0, charindex, fl = 0, x = 0, y = 0; + fl = CHAR_getInt(npcindex, CHAR_FLOOR); + x = CHAR_getInt(npcindex, CHAR_X); + y = CHAR_getInt(npcindex, CHAR_Y); + + for (i = 0; i < FAMILY_MAXMEMBER; i++) + { + charindex = familyMemberIndex[index1][i]; + if (CHAR_getCharUse(charindex)){ + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor){ + if (CHAR_getWorkInt(charindex, CHAR_WORKFMPKFLAG) < 0){ + if (CHAR_getWorkInt(charindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + CHAR_DischargeParty( charindex, 0); + CHAR_setWorkInt(charindex, CHAR_WORKWARPCHECK, FALSE); + CHAR_setWorkInt(charindex, CHAR_WORKBATTLEFLAG, FALSE); + CHAR_warpToSpecificPoint(charindex, fl, x, y); + CHAR_talkToCli(charindex, -1, "ս볡", CHAR_COLORRED); + } + } + }else + familyMemberIndex[index1][i] = -1; + charindex = familyMemberIndex[index2][i]; + if (CHAR_getCharUse(charindex)){ + if (CHAR_getInt(charindex, CHAR_FLOOR) == floor){ + if (CHAR_getWorkInt(charindex, CHAR_WORKFMPKFLAG) < 0){ + if (CHAR_getWorkInt(charindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + CHAR_DischargeParty(charindex, 0); + CHAR_setWorkInt(charindex, CHAR_WORKWARPCHECK, FALSE); + CHAR_setWorkInt(charindex, CHAR_WORKBATTLEFLAG, FALSE); + CHAR_warpToSpecificPoint(charindex, fl, x, y); + CHAR_talkToCli(charindex, -1, "ս볡", CHAR_COLORRED); + } + } + }else + familyMemberIndex[index2][i] = -1; + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_freepetskillshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_freepetskillshop.c new file mode 100644 index 0000000..6405c82 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_freepetskillshop.c @@ -0,0 +1,577 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "pet_skill.h" +#include "readmap.h" +#include "battle.h" +#include "configfile.h" +#include "util.h" +#include "npc_eventaction.h" +#include "npc_freepetskillshop.h" +#ifdef _PETSKILL_SHOP_LUA +#include "mylua/function.h" +#endif +#ifdef _CFREE_petskill + +enum { + CHAR_WORK_SKILLSELECT = CHAR_NPCWORKINT1, +}; + +enum { + SELECTSKILL_START=10, + SELECTSKILL_TEACH=23, + SELECTSKILL_END=30, +}; + +enum { + START_WINDOW=0, + SKILL_WINDOW, + MEEND_WINDOW, +}; + +static void NPC_FreePetSkillShop_selectWindow( int meindex, int toindex, int num,int select); +BOOL NPC_FreePetSkillMakeStr(int meindex,int toindex, int select); +//BOOL NPC_CHECKFREEPETSKILL( int toindex, int petindex, int skillID); +BOOL NPC_SkillShopItemCheck(int meindex,int talker,int itemNo, int cou); +BOOL NPC_SkillShopDelItems(int meindex,int talker, char *buf); +BOOL NPC_SkillShopPetCheck( int toindex, int petindex, int skillID ); +BOOL NPC_SkillShopWarp( int meindex, int talkindex); + +#define MAXNPCPOINT 10 + +BOOL NPC_FreePetSkillShopInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[256]; + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_FREESKILLSHOP ); + CHAR_setWorkInt( meindex, CHAR_WORK_SKILLSELECT, 0); + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr NO arg !!"); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "pet_skill", msg, sizeof( msg)) != NULL){ + char buf[256], filename[256]; + int k=1, skillID, skillarray; + while( getStringFromIndexWithDelim( msg, ",", k, buf, sizeof( buf) ) ){ + k++; + skillID=atoi(buf); + skillarray = PETSKILL_getPetskillArray( skillID); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ) continue; + if( PETSKILL_getInt( skillarray, PETSKILL_ILLEGAL) == 1){ + if( NPC_Util_CheckAssignArgFile( meindex, filename) != NULL ){ + print("\n\ܲ淶:[%d-%s] ->ļ:%s\n", + skillID, + PETSKILL_getChar( skillarray, PETSKILL_NAME), + filename ); + } + } + } + }else{ + return FALSE; + } + + return TRUE; +} +void NPC_FreePetSkillShopTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1 ); + + NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, START_WINDOW,-1); +} + +static void NPC_FreePetSkillShop_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + int fd = getfdFromCharaIndex( toindex); + int buttontype = 0, windowtype = 0, windowno = 0; + char buf1[256]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + + switch(num) { + case START_WINDOW: + { + BOOL Evflg = TRUE; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "start_msg", token, sizeof( token)) == NULL) { + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + if( CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT) != 1 ) { + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + //ж + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FREE", buf1, sizeof( buf1)) != NULL ) { + if( NPC_ActionPassCheck( meindex, toindex, buf1) == FALSE ) { + Evflg = FALSE; + } + } + if( Evflg == FALSE) { + CHAR_talkToCli( toindex, -1, "óѧ⼼ܣร", CHAR_COLORYELLOW); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + return; + }else { + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowno = SELECTSKILL_START; + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 2); + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token ); + } + } + break; + case SKILL_WINDOW: + if( NPC_FreePetSkillMakeStr( meindex, toindex, select) == FALSE ) { + print("\n npc_freepetskillshop.c "); + } + break; + case MEEND_WINDOW: + break; + } +} + +void NPC_FreePetSkillShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int skill; + int pet; + int slot; + int cost; + int skillID=0; + int petskillindex; + char buf[64]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[512]; + int petindex; + char msgbuf[128]; + double rate= 1.0; + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return; + } + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) + return ; + + + switch( seqno) { + case SELECTSKILL_START: + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != 2 ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, SKILL_WINDOW, -1); + break; + case SELECTSKILL_TEACH: + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != 3 ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + makeStringFromEscaped( data); + getStringFromIndexWithDelim(data,"|",1,buf,sizeof(buf)); + skill=atoi(buf); + getStringFromIndexWithDelim(data,"|",2,buf,sizeof(buf)); + pet=atoi(buf); + getStringFromIndexWithDelim(data,"|",3,buf,sizeof(buf)); + slot=atoi(buf); + getStringFromIndexWithDelim(data,"|",4,buf,sizeof(buf)); + cost=atoi(buf); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", msg, sizeof( msg)) != NULL){ + getStringFromIndexWithDelim(msg,",",skill,buf,sizeof(buf)); + skillID=atoi(buf); + } + slot--; + if( slot < 0 ) return; + + petindex = CHAR_getCharPet( talkerindex, pet-1); + if( !CHAR_CHECKINDEX(petindex) ){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ + rate = atof( msg); + } + petskillindex = PETSKILL_getPetskillArray( skillID ); + if( !PETSKILL_CHECKINDEX( petskillindex)){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + + cost = PETSKILL_getInt( petskillindex, PETSKILL_COST ); + cost = cost * rate; + + //ж + if(CHAR_getInt(talkerindex,CHAR_GOLD) < cost){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + +#ifdef _PETSKILL_SHOP_LUA + if(FreePetSkillShop(talkerindex, petindex, CHAR_getPetSkill(petindex, slot), skillID) == FALSE ) { + return; + } +#endif + + if( NPC_CHECKFREEPETSKILL( talkerindex, petindex, skillID ) == FALSE ){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + CHAR_talkToCli( talkerindex, -1, "!!", CHAR_COLORYELLOW); + return; + } + if( Action_RunDoEventAction( meindex, talkerindex, argstr) == FALSE ){ + CHAR_talkToCli( talkerindex, -1, "Ʒ!!", CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + + CHAR_setPetSkill( petindex, slot, skillID); + CHAR_setInt( talkerindex, CHAR_GOLD, ( CHAR_getInt( talkerindex, CHAR_GOLD) - cost) ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d",pet-1); + CHAR_sendStatusString( talkerindex, msgbuf ); + CHAR_sendStatusString( talkerindex, "P"); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + //WARP + if( NPC_SkillShopWarp( meindex, talkerindex) == TRUE ) + return; + //ADD + NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, SKILL_WINDOW, -1); + break; + case SELECTSKILL_END: + break; + } + + return; +} + +BOOL NPC_CHECKFREEPETSKILL( int toindex, int petindex, int skillID) +{ + int skillindex=-1; + char SCode[256]; + char Free[256]; + int i, petID; + skillindex = PETSKILL_getPetskillArray( skillID ); + memset( Free, 0, sizeof( Free)); + if( !PETSKILL_CHECKINDEX( skillindex) ) { + return FALSE; + } + + petID = CHAR_getInt( petindex, CHAR_PETID); + sprintf( SCode, "%s", PETSKILL_getChar( skillindex, PETSKILL_KINDCODE)); + sprintf( Free, "%s", PETSKILL_getChar( skillindex, PETSKILL_FREE)); + + //CHECK CODE + if( !strcmp( SCode, "\0")) { + return TRUE; + } + + for( i=0; i= cou ) + return TRUE; + } + return FALSE; + +} + +BOOL NPC_SkillShopDelItems(int meindex,int talker, char *buf) +{ + char buf1[256]; + char item[256], cout[256]; + int i=1; + BOOL Evflg=TRUE; + while( getStringFromIndexWithDelim( buf, ",", i,buf1, sizeof( buf1)) != FALSE ) { + i++; + if( strstr( buf1, "*") != NULL ) { + getStringFromIndexWithDelim( buf1, "*", 1, item, sizeof( item)); + getStringFromIndexWithDelim( buf1, "*", 2, cout, sizeof( cout)); + }else { + strcpy( item, buf1); + strcpy( cout, "1"); + } + if( NPC_SkillShopItemCheck( meindex, talker, atoi( item), atoi( cout)) == FALSE ) { + Evflg=FALSE; + break; + } + if( Evflg == FALSE ) + break; + } + if( Evflg == FALSE ) + return FALSE; + if( NPC_ActionDelItem( talker, buf) == TRUE ) { + return TRUE; + } + return FALSE; +} + +BOOL NPC_SkillShopPetCheck( int toindex, int petindex, int skillID ) +{ + char Free[256]; + int i; + char data[256], msg[256]; + int skillindex = PETSKILL_getPetskillArray( skillID ); + + memset( Free, 0, sizeof( Free)); + sprintf( Free, "%s", PETSKILL_getChar( skillindex, PETSKILL_FREE)); + + if( NPC_Util_GetStrFromStrWithDelim( Free, "FREE", data, sizeof( data)) != NULL ) { + BOOL EvFlg = TRUE; + i=1; + while( getStringFromIndexWithDelim( data, "|", i, msg, sizeof( msg)) != FALSE ) { + i++; + if( strstr( msg, "LV") != NULL ) { + char LvStr[256]; + int LV=0; + if( strstr( msg, ">" ) != NULL ) { + if( getStringFromIndexWithDelim( msg, ">", 2, LvStr, sizeof( LvStr)) != FALSE ) { + LV = atoi( LvStr); + if( CHAR_getInt( petindex, CHAR_LV) <= LV ) + EvFlg = FALSE; + } + }else if( strstr( msg, "<")) { + if( getStringFromIndexWithDelim( msg, "<", 2, LvStr, sizeof( LvStr)) != FALSE ) { + LV = atoi( LvStr); + if( CHAR_getInt( petindex, CHAR_LV) >= LV ) + EvFlg = FALSE; + } + } + }else if( strstr( msg, "SK") != NULL ) { + int j=0, PskId=-1, ID; + char strSK[256]; + int petskillindex; + + getStringFromIndexWithDelim( msg, "=", 2, strSK, sizeof( strSK) ); + ID = atoi( strSK); + for( j=0; j < CHAR_MAXPETSKILLHAVE; j++) { + PskId = CHAR_getPetSkill( petindex, j); + petskillindex = PETSKILL_getPetskillArray( PskId ); + if( !PETSKILL_CHECKINDEX( petskillindex)) + continue; + if( ID == PskId ) { + if( strstr( msg, "!=") !=NULL ) + EvFlg = FALSE; + break; + } + } + if( j == CHAR_MAXPETSKILLHAVE ) { + EvFlg = FALSE; + break; + } + } + if( EvFlg == FALSE ) + break; + } + if( EvFlg == FALSE ) { + return FALSE; + }else { + return TRUE; + } + } + return TRUE; +} + +BOOL NPC_SkillShopWarp( int meindex, int talkindex) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char data[1024], buf1[256], buf2[256]; + int i=1, j=1; + BOOL EvFlg=FALSE; + struct { + int FLOOR; + int X; + int Y; + }Points[MAXNPCPOINT]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + + for( i=0;i= MAXNPCPOINT ) + break; + } + where = RAND( 0, i-1); + CHAR_warpToSpecificPoint( meindex, Points[where].FLOOR, Points[where].X, Points[where].Y); + EvFlg = TRUE; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", data, sizeof( data)) != NULL ) { + int P_Floor,P_X,P_Y; + getStringFromIndexWithDelim( data, ",", 1, buf2, sizeof( buf2)); + P_Floor = atoi( buf2); + getStringFromIndexWithDelim( data, ",", 2, buf2, sizeof( buf2)); + P_X = atoi( buf2); + getStringFromIndexWithDelim( data, ",", 3, buf2, sizeof( buf2)); + P_Y = atoi( buf2); + CHAR_warpToSpecificPoint( talkindex, P_Floor, P_X, P_Y); + EvFlg = TRUE; + } + + return EvFlg; +} + +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblebank.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblebank.c new file mode 100644 index 0000000..afd8bc9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblebank.c @@ -0,0 +1,522 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "enemy.h" +#include "log.h" +#include "battle.h" +#include "readmap.h" +#include "handletime.h" +#include "configfile.h" +#ifdef _GAMBLE_BANK +#include "npc_gamblebank.h" + +static void NPC_GambleBank_selectWindow( int meindex, int toindex, int num, int flg); +int NPC_GambleBank_DoGold( int meindex, int toindex, int Gold, int flg); +BOOL NPC_GambleBank_AddItem( int meindex, int toindex, int itemId, int count); + +enum { + GAMBLE_START = 0, + GAMBLE_SELET, + GAMBLE_MAN_BANK, + GAMBLE_MAN_CHANG1, + GAMBLE_MAN_CHANG2, + GAMBLE_END, +}; + +enum { + NPC_WORK_INDEX = CHAR_NPCWORKINT1, + NPC_WORK_WORKTYPE = CHAR_NPCWORKINT2, // 0,-1 = NULL 2 = 3 = 4 = BOTH + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT3, + NPC_WORK_PAGE = CHAR_NPCWORKINT4, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; +#define _GAMBLEBANK_U_NOLOCK //ͬʱԶ +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#define GAMBLEBANK_LOOPTIME 80 +#define GAMBLEBANK_STANDBY 5000 +#define GAMBLEBANK_DEF 3 // / 100 +#define GAMBLEBANK_GETMAX 1000000 +#define GAMBLEBANK_GETMIN 100 +#define LIST_PAGE 7 +BOOL NPC_GambleBankInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[256]; + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_GAMBLEBANK ); + +#ifdef _GAMBLEBANK_U_NOLOCK + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, GAMBLEBANK_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); +#endif + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL) { + print("GambleBank:GetArgStrErr"); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim( npcarg,"GAMBLE_TYPE", buf1,sizeof( buf1) ) == NULL) { + print("GAMBLE_TYPE err !"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_WORKTYPE, atoi( buf1) ); + + return TRUE; +} +//CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); +void NPC_GambleBankLoop( int meindex) +{ +#ifdef _GAMBLEBANK_U_NOLOCK + + int fulltime = GAMBLEBANK_LOOPTIME; + if( ( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + fulltime) >= NowTime.tv_sec ) + return; + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); +#endif + return; +} + +void NPC_GambleBankTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + char buf1[256]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + int work_type; + + if( !CHAR_CHECKINDEX( talkerindex) || !CHAR_CHECKINDEX( meindex) ) + return; + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) { + return; + } + } + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL) { + print("GambleBank:GetArgStrErr"); + return; + } +#ifdef _FIX_GAMBLENUM + if( CHAR_getInt( talkerindex, CHAR_GAMBLENUM) < 0 ) { + CHAR_setInt( talkerindex, CHAR_GAMBLENUM, 0); + } +#endif + if(NPC_Util_GetStrFromStrWithDelim( npcarg,"GAMBLE_TYPE", buf1,sizeof( buf1) ) == NULL) { + print("GAMBLE_TYPE err !"); + return; + } + + CHAR_setWorkInt( meindex, NPC_WORK_WORKTYPE, atoi( buf1) ); + work_type = CHAR_getWorkInt( meindex, NPC_WORK_WORKTYPE); + + + if( work_type < 1 || work_type > 4 ) { // 0 or -1 + strcpy( buf1,"ʱֹͣ"); + CHAR_talkToCli( talkerindex, meindex, buf1, CHAR_COLORYELLOW); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } +#ifdef _GAMBLEBANK_U_NOLOCK + +#else + if( CHAR_getWorkInt( meindex , NPC_WORK_INDEX) >= 0 ) { + strcpy( buf1,"æţ"); + CHAR_talkToCli( talkerindex, meindex, buf1, CHAR_COLORYELLOW); + return; + }else { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, talkerindex); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + } +#endif + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1); + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_START, 1); +} + +static void NPC_GambleBank_selectWindow( int meindex, int toindex, int num, int flg) +{ + char token[256]; + char buf1[256],buf2[256]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + int i; + int page=-1; + //flg <= 0 1 flg = 2 Ǯ 3 = ˴ + // 4 = н 5 = 6 = + char Gamble_End[][56] = { + "error_msg", "end_msg", "money_msg", "full_msg1", + "full_msg2","getmax_msg","getmin_msg", + }; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GambleBank:GetArgStrErr"); + return; + } + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + switch( num) { + case GAMBLE_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg,"gamble_start", token, sizeof( token) ) == NULL) { + print("gamble_start msg err !"); + return; + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_GambleBank_START; + break; + + case GAMBLE_SELET: + i = 1; + strcpy( token, "\0"); + sprintf( buf2,"%s%d", "gamble_msg0", i); + while( NPC_Util_GetStrFromStrWithDelim( npcarg, buf2, buf1, sizeof( buf1) ) != NULL ) { + if( strstr( buf1, "NULL" ) == NULL ) { + strcat( token , buf1); + strcat( token, "\n"); + }else { + strcat( token, "\n"); + } + i++; + sprintf( buf2,"%s%d", "gamble_msg0", i); + } + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno = NPC_GambleBank_SELECT; + break; + + case GAMBLE_MAN_BANK: // + sprintf( token,"%d", CHAR_getInt( toindex, CHAR_PERSONAGOLD ) ); + windowtype = WINDOW_MESSAGETYPE_BANK; + windowno = NPC_GambleBank_BANK; + break; + + case GAMBLE_MAN_CHANG1: // + { + char snum[256]; + page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); + strcpy( token, ""); + sprintf( token, "%d֣뻻һƷأ\n", CHAR_getInt( toindex, CHAR_GAMBLENUM)); + for( i=(page*LIST_PAGE);i<(page*LIST_PAGE+LIST_PAGE);i++) { + if( i>=arraysizeof( GB_ITEMS)) { + break; + } + if( !strcmp( GB_ITEMS[i].name,"NEXT") ) { + strcat( token, " һҳ"); + break; + } + if( !strcmp( GB_ITEMS[i].name,"END") ) { + strcat( token, " ȡ\n"); + break; + } + + sprintf( snum,"%s%d\t%s", + "֣", GB_ITEMS[i].Gnum, + GB_ITEMS[i].name); + snum[36] = 0; + strcat( token, snum); + strcat( token,"\n"); + strcpy( snum, "\0"); + } + + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_NONE; + windowno = NPC_GambleBank_CHANG1; + } + break; + case GAMBLE_END: + CHAR_send_P_StatusString( toindex, CHAR_P_STRING_GOLD); + if( flg < 0 || flg > 6) { + flg = 0; + } + if( NPC_Util_GetStrFromStrWithDelim( npcarg, Gamble_End[flg], token, sizeof( token) ) == NULL) { + print("Gamble_End[%d] noe found !", flg); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, -1); +#ifdef _GAMBLEBANK_U_NOLOCK +#else + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); +#endif + windowno = NPC_GambleBank_END; + buttontype = WINDOW_BUTTONTYPE_OK; + break; + } + + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +void NPC_GambleBankWindowTalked ( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int stone_gold = 0; + int flg=1; + int work_type=-1; + int type; + type = atoi( data); + + if( !CHAR_CHECKINDEX( talkerindex) || !CHAR_CHECKINDEX( meindex) ) + return; + + work_type = CHAR_getWorkInt( meindex, NPC_WORK_WORKTYPE ); + if( work_type < 1 || work_type > 4 ) { + return; + } + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } +#ifdef _GAMBLEBANK_U_NOLOCK +#else + { + char buf1[256]; + if( CHAR_getWorkInt( meindex , NPC_WORK_INDEX) != talkerindex ) { + strcpy( buf1,"æأ"); + CHAR_talkToCli( talkerindex, meindex, buf1, CHAR_COLORYELLOW); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + } +#endif + + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + switch( seqno) { + case NPC_GambleBank_START: + if( select == WINDOW_BUTTONTYPE_YES ) { + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_SELET, flg); + }else { + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_END, flg); + } + break; + case NPC_GambleBank_SELECT: + if( type == 1 ) { // + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 2); + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_MAN_BANK, flg); + }else if( type == 2 ) { // + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_MAN_CHANG1, flg); + }else { + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_END, flg); + } + break; + case NPC_GambleBank_BANK: //2 + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != 2 ) // + return; + if( work_type != 2 && work_type != 4 ) { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } + if( select == 4 && atoi( data) != 0 ) { + stone_gold = atoi( data); + flg = NPC_GambleBank_DoGold( meindex, talkerindex, stone_gold, select); + //flg = 1 flg = 2 Ǯ flg <= 0 + if( flg == 1 ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } + } + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_END, flg); + break; + case NPC_GambleBank_CHANG1: // + { + int page,ItemID; + int count; + type -=1; + page = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT)*LIST_PAGE; + if( work_type != 3 && work_type != 4 ) { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } + + if( page < 0 ) //Ի + return; + if( (page+type) < 0 || (page+type) >= arraysizeof( GB_ITEMS) ) { + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_END, flg); + }else if( !strcmp( GB_ITEMS[page+type].name,"NEXT") ){ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, + CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) + 1); + NPC_GambleBank_selectWindow( meindex, talkerindex, GAMBLE_MAN_CHANG1, flg); + }else if( !strcmp( GB_ITEMS[page+type].name,"END") ){ + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + }else { + if( type < 7 && type >= 0 ) { + if( GB_ITEMS[page+type].name == NULL || + !strcmp( GB_ITEMS[page+type].name, "\0") ) { + }else { + ItemID = GB_ITEMS[page+type].ItemId; //ID + count = GB_ITEMS[page+type].Gnum; // + NPC_GambleBank_AddItem( meindex, talkerindex, ItemID, count); + } + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + } + } + break; + case NPC_GambleBank_END: + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + break; + } +} + + +int NPC_GambleBank_DoGold( int meindex, int toindex, int Gold, int flg) +{ + //flg = 1 flg = 2 Ǯ flg <= 0 3 = ˴ 4 = н 5 = ߽ + char buf1[256]; + int player_gold = CHAR_getInt( toindex, CHAR_GOLD ); + int stone_def = 0; // +// int def = GAMBLEBANK_DEF; + //Ĵȡ + if( flg != 4 ) + return 0; + if( Gold == 0 ) { + return 0; + } + + if( Gold < 0 ) { //ȡ + Gold *=-1; + //stone_def = (Gold * def) /100; + stone_def = 300; + if( Gold > GAMBLEBANK_GETMAX ) { + return 5; + }else if( Gold < GAMBLEBANK_GETMIN ) { + return 6; + } + if( ( player_gold + Gold ) > CHAR_getMaxHaveGold(toindex) ) { + return 3; //ȡὫ˽ + }else if( (Gold + stone_def)> CHAR_getInt( toindex, CHAR_PERSONAGOLD ) ) { //д + return 2; + } + + CHAR_setInt( toindex, CHAR_PERSONAGOLD, (CHAR_getInt( toindex, CHAR_PERSONAGOLD )-(Gold+stone_def))); + + CHAR_AddGold( toindex, Gold); + + sprintf( buf1,"ȡ%d ѣ%dʣࣺ%d ", Gold, stone_def, CHAR_getInt( toindex, CHAR_PERSONAGOLD )); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); + LogBankStone( CHAR_getChar( toindex, CHAR_NAME ), CHAR_getChar( toindex, CHAR_CDKEY ), + toindex, Gold, + "GB_Bank_Get(ȡ)", + CHAR_getInt( toindex, CHAR_FLOOR), + CHAR_getInt( toindex, CHAR_X ), CHAR_getInt( toindex, CHAR_Y ) , + CHAR_getInt( toindex, CHAR_GOLD ), + CHAR_getInt( toindex, CHAR_PERSONAGOLD ) + ); + return 1; + }else if( Gold > 0 ) { // + if( Gold > player_gold ) { + return 2; + }else if( (Gold + CHAR_getInt( toindex, CHAR_PERSONAGOLD ) ) > CHAR_MAXPERSONAGOLD ) { + return 4; + } + + CHAR_DelGold( toindex, Gold ); + + CHAR_setInt( toindex, CHAR_PERSONAGOLD, (CHAR_getInt( toindex, CHAR_PERSONAGOLD ) + Gold ) ); + sprintf( buf1,"%d ʣࣺ%d ", Gold, CHAR_getInt( toindex, CHAR_PERSONAGOLD )); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); + LogBankStone( CHAR_getChar( toindex, CHAR_NAME ), CHAR_getChar( toindex, CHAR_CDKEY ), + toindex, Gold, + "GB_Bank_save(д)", + CHAR_getInt( toindex, CHAR_FLOOR), + CHAR_getInt( toindex, CHAR_X ), CHAR_getInt( toindex, CHAR_Y ), + CHAR_getInt( toindex, CHAR_GOLD ), + CHAR_getInt( toindex, CHAR_PERSONAGOLD ) + ); + return 1; + } + return 0; +} + +BOOL NPC_GambleBank_AddItem( int meindex, int toindex, int itemId, int count) +{ + int i=-1,itemindex=-1; + int ret=-1; + char token[256]; + strcpy( token,"\0"); + if( count < 0 || itemId < 0 ) + return FALSE; + + if( CHAR_getInt( toindex, CHAR_GAMBLENUM) < count ) { + sprintf( token,"ֲֳ㣡"); + CHAR_talkToCli( toindex, -1,token,CHAR_COLORWHITE); + return FALSE; + } + for( i = 0 ; i < CheckCharMaxItem(toindex) ; i++ ){ + itemindex=CHAR_getItemIndex( toindex , i ); + if( itemindex == -1 ) { + break; + } + } + if( i == CheckCharMaxItem(toindex) ) { + snprintf( token,sizeof( token), "Ʒռ䲻㣡"); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORWHITE); + return FALSE; + } + itemindex = ITEM_makeItemAndRegist( itemId); + if(itemindex == -1) + return FALSE; + + ret = CHAR_addItemSpecificItemIndex( toindex, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(toindex) ) { + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "G_BANK(ֳֶһ)", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + sprintf( token,"õ%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1,token,CHAR_COLORWHITE); + CHAR_sendItemDataOne( toindex, ret); + CHAR_setInt( toindex, CHAR_GAMBLENUM, CHAR_getInt( toindex, CHAR_GAMBLENUM) - count); + sprintf( token,"ֳʣࣺ %d", CHAR_getInt( toindex, CHAR_GAMBLENUM)); + CHAR_talkToCli( toindex, -1,token,CHAR_COLORWHITE); + return TRUE; +} + +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblemaster.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblemaster.c new file mode 100644 index 0000000..67f325a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gamblemaster.c @@ -0,0 +1,600 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "handletime.h" +#include "readmap.h" +#include "log.h" +#include "npc_eventaction.h" + +#ifdef _GAMBLE_ROULETTE + +#include "npc_gamblemaster.h" +void defPlayerGold( int meindex, int flg); +void NPC_GAMBLEMASTER_RESET( int meindex); +void Codef_Gold( int meindex, int toindex, int stone, int flg, char *token); +void NPC_GambleRoulette_selectWindow(int meindex,int toindex,int num,int select); + +enum +{ + ROULETTE_START=0, + ROULETTE_SELECT, + ROULETTE_LOOK, + ROULETTE_END, +}; + +enum +{ + roulette1 = 11, roulette2, roulette3, roulette4, roulette5, roulette6, roulette7, + roulette8, roulette9, roulette10, roulette11, roulette12, roulette13, roulette14, + roulette15, roulette16, roulette17, roulette18, roulette19, roulette20, + + roulette21 = 41, roulette22, roulette23, roulette24, roulette25, roulette26, + roulette27, roulette28, roulette29, roulette30, roulette31, roulette32, + roulette33, roulette34, roulette35, roulette36, roulette37, roulette38, + roulette39, roulette40, + roulette41 = 71, roulette42, roulette43, roulette44, roulette45, + + roulette51 = 101, roulette52=102, roulette53=103, + roulette61 = 111, roulette62=112, +}; + +typedef struct tagGambleMaster +{ + int m_fx; + int m_fy; + int m_type; // + int m_RG; //1 2 + int m_EO; //˫1 2 + int m_SI; + int m_IN; + char str_type[56]; + int m_nums; +}GambleEndType; +GambleEndType EndTypedef[60]={ +{22, 8 , roulette1 , roulette41, roulette43, roulette51, roulette61, "죱", 0}, +{7 , 8 , roulette1 , roulette41, roulette43, roulette51, roulette61, "죱", 0}, +{22, 10, roulette3 , roulette41, roulette43, roulette51, roulette61, "죳", 0}, +{7 , 6 , roulette3 , roulette41, roulette43, roulette51, roulette61, "죳", 0}, +{20, 11, roulette5 , roulette41, roulette43, roulette51, roulette61, "죵", 0}, +{9 , 5 , roulette5 , roulette41, roulette43, roulette51, roulette61, "죵", 0}, +{19, 5 , roulette6 , roulette41, roulette44, roulette53, roulette61, "죶", 0}, +{10, 11, roulette6 , roulette41, roulette44, roulette53, roulette61, "죶", 0}, +{17, 5 , roulette8 , roulette41, roulette44, roulette53, roulette61, "죸", 0}, +{12, 11, roulette8 , roulette41, roulette44, roulette53, roulette61, "죸", 0}, +{16, 5 , roulette9 , roulette41, roulette43, roulette53, roulette61, "죹", 0}, +{13, 11, roulette9 , roulette41, roulette43, roulette53, roulette61, "죹", 0}, +{15, 5 , roulette10, roulette41, roulette44, roulette53, roulette61, "죱", 0}, +{14, 11, roulette10, roulette41, roulette44, roulette53, roulette61, "죱", 0}, +{12, 5 , roulette13, roulette41, roulette43, roulette52, roulette62, "죱", 0}, +{17, 11, roulette13, roulette41, roulette43, roulette52, roulette62, "죱", 0}, +{22, 6 , roulette17, roulette41, roulette43, roulette53, roulette62, "죱", 0}, +{7 , 10, roulette17, roulette41, roulette43, roulette53, roulette62, "죱", 0}, +{22, 5 , roulette18, roulette41, roulette44, roulette52, roulette62, "죱", 0}, +{7 , 11, roulette18, roulette41, roulette44, roulette52, roulette62, "죱", 0}, + +{22, 9 , roulette22, roulette42, roulette44, roulette51, roulette61, "̣", 0}, +{7 , 7 , roulette22, roulette42, roulette44, roulette51, roulette61, "̣", 0}, +{21, 11, roulette24, roulette42, roulette44, roulette51, roulette61, "̣", 0}, +{8 , 5 , roulette24, roulette42, roulette44, roulette51, roulette61, "̣", 0}, +{18, 5 , roulette27, roulette42, roulette43, roulette53, roulette61, "̣", 0}, +{11, 11, roulette27, roulette42, roulette43, roulette53, roulette61, "̣", 0}, +{19, 11, roulette31, roulette42, roulette43, roulette51, roulette62, "̣", 0}, +{10, 5 , roulette31, roulette42, roulette43, roulette51, roulette62, "̣", 0}, +{18, 11, roulette32, roulette42, roulette44, roulette51, roulette62, "̣", 0}, +{11, 5 , roulette32, roulette42, roulette44, roulette51, roulette62, "̣", 0}, +{16, 11, roulette34, roulette42, roulette44, roulette52, roulette62, "̣", 0}, +{14, 5 , roulette34, roulette42, roulette44, roulette52, roulette62, "̣", 0}, +{15, 11, roulette35, roulette42, roulette43, roulette52, roulette62, "̣", 0}, +{13, 5 , roulette35, roulette42, roulette43, roulette52, roulette62, "̣", 0}, +{22, 7 , roulette36, roulette42, roulette44, roulette53, roulette62, "̣", 0}, +{7 , 9 , roulette36, roulette42, roulette44, roulette53, roulette62, "̣", 0}, +{21, 5 , roulette39, roulette42, roulette43, roulette52, roulette62, "̣", 0}, +{8 , 11, roulette39, roulette42, roulette43, roulette52, roulette62, "̣", 0}, +{20, 5 , roulette40, roulette42, roulette44, roulette52, roulette62, "̣", 0}, +{9 , 11, roulette40, roulette42, roulette44, roulette52, roulette62, "̣", 0}, +{22,11, roulette45, 0, 0, roulette52, 0, "룰"}, + +{ 7, 5, -1, -1, -1, -1, -1, "", 0}, +{ -1, -1, -1, -1, -1, -1, -1, "", 0}, +}; + +enum { + /* + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT1, + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, +*/ + NPC_WORK_NPCAI = CHAR_NPCWORKINT3, + NPC_WORK_NPCACTION = CHAR_NPCWORKINT3, + NPC_WORK_MASTERSTONE = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_SYSTIME = CHAR_NPCWORKINT6, + NPC_WORK_GAMEFLG = CHAR_NPCWORKINT7, + NPC_WORK_GAMBLECODE = CHAR_NPCWORKINT8, + NPC_WORK_MASTERFLG = CHAR_NPCWORKINT9, + NPC_WORK_ENDPOINT = CHAR_NPCWORKINT10, +}; + +#define ROULETTE_ERRTIME 500 +#define ROULETTE_STANDBY1 40 +#define ROULETTE_LOOPTIME 3000 + +BOOL NPC_Gamble_MasterInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[256]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n not found argstr "); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "gamble_code",buf1, sizeof(buf1)) == NULL ) { + print("\n gamble_code error: not found !!"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_GAMBLECODE, atoi( buf1)); + //Ϸ׶ + CHAR_setWorkInt( meindex, NPC_WORK_GAMEFLG, 0); + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_GAMBLEMASTER ); + // NPC_WORK_MODE ״̬ 0: ȴ 1:GAME START 2:GAME END + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_MASTERFLG, 30); + CHAR_setWorkInt( meindex, NPC_WORK_MASTERSTONE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_NPCAI, 0); + //趨LOOP TIMER + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, ROULETTE_LOOPTIME); + //¼ʱ + CHAR_setWorkInt( meindex, NPC_WORK_SYSTIME, NowTime.tv_sec); + return TRUE; +} + +void NPC_Gamble_MasterTalked( int meindex , int talkerindex , char *szMes , int color ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n not found argstr "); + return; + } + // 0 ѡ 11 - 19 21 - 29 + CHAR_setWorkInt(talkerindex , CHAR_WORKSHOPRELEVANT,0); + NPC_GambleRoulette_selectWindow( meindex, talkerindex, ROULETTE_START, -1 ); +} + +void NPC_GambleRoulette_selectWindow(int meindex,int toindex,int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[256],buf2[256]; + char token[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + int pagenum=0, i; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg)) == NULL ) { + print("\n not found npcarg "); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT,0); + return; + } + switch( num) { + case ROULETTE_START: + i = 1; + strcpy( token, "\0"); + sprintf( buf2,"%s%d", "gamble_msg0", i); + while( NPC_Util_GetStrFromStrWithDelim( npcarg, buf2, buf1, sizeof( buf1) ) != NULL ) { + if( strstr( buf1, "NULL" ) == NULL ) { + strcat( token , buf1); + strcat( token, "\n"); + }else { + strcat( token, "\n"); + } + i++; + sprintf( buf2,"%s%d", "gamble_msg0", i); + } + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno = WINDOWTYPE_GAMBLEROULETTE_START; + break; + break; + case ROULETTE_SELECT: + //ҳ select + pagenum = CHAR_getWorkInt( toindex , CHAR_WORKSHOPRELEVANT); + strcpy( token, "\0"); + if( select >= 0 ) { + sprintf( buf2,"%s%2d", "page_num", select); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT, select+1); + }else { + sprintf( buf2,"%s%2d", "page_num", pagenum ); + pagenum+=1; + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT, pagenum); + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, buf2, token, sizeof( token) ) == NULL ) { + print("\n error: not found token:%s", token); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT,0); + return; + } + + sprintf( buf2,"%s%2d", "page_num", CHAR_getWorkInt( toindex , CHAR_WORKSHOPRELEVANT)); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, buf2, buf1, sizeof( buf1) ) == NULL ) { + windowno = WINDOWTYPE_GAMBLEROULETTE_END; + buttontype = WINDOW_BUTTONTYPE_OK; + }else { + windowno = WINDOWTYPE_GAMBLEROULETTE_SELECT; + buttontype = WINDOW_BUTTONTYPE_NEXT; + } + break; + case ROULETTE_LOOK: + { //ʾʱػ + int G_num = CHAR_getInt( toindex, CHAR_GAMBLENUM ); + + if( CHAR_getWorkInt( toindex, CHAR_WORKSTAKEFLAG) != FALSE) { + for( i=0; i<5; i++) { + if( CHAR_getWorkInt( toindex, i+CHAR_WORKSTAKETYPE1) > 0 ) + G_num++; + } + } + if( G_num < 0 ) G_num = 0; + sprintf( token,"ֳΪ%d", G_num ); + windowno = WINDOWTYPE_GAMBLEROULETTE_END; + buttontype = WINDOW_BUTTONTYPE_OK; + } + break; + case ROULETTE_END: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "page_endmsg", token, sizeof( token) ) == NULL ) { + print("\n error: not found end_msg"); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT,0); + return; + } + + windowno = WINDOWTYPE_GAMBLEROULETTE_END; + buttontype = WINDOW_BUTTONTYPE_OK; + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_Gamble_MasterWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int pagenum=0; + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + switch( seqno ) { + case WINDOWTYPE_GAMBLEROULETTE_START: + pagenum = atoi( data); + if( pagenum == 4 ) { + NPC_GambleRoulette_selectWindow( meindex, talkerindex, ROULETTE_END, -1 ); + }else { + if( pagenum == 3 ) { //ROULETTE_LOOK + NPC_GambleRoulette_selectWindow( meindex, talkerindex, ROULETTE_LOOK, -1 ); + }else { + pagenum = (pagenum*10)+1; + NPC_GambleRoulette_selectWindow( meindex, talkerindex, ROULETTE_SELECT, pagenum ); + } + } + break; + case WINDOWTYPE_GAMBLEROULETTE_SELECT: + NPC_GambleRoulette_selectWindow( meindex, talkerindex, ROULETTE_SELECT, -1 ); + break; + case WINDOWTYPE_GAMBLEROULETTE_END: + CHAR_setWorkInt(talkerindex , CHAR_WORKSHOPRELEVANT, 0); + break; + } + return; +} + +void NPC_Gamble_MasterLoop( int meindex) +{ + int objmeindex = -1; + int full_time; + //int Master_Stone = 0; + int timeNum = 0; + //int time_run=0; + //int act; + objmeindex = CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX); + switch( CHAR_getWorkInt( meindex, NPC_WORK_MODE )) { + case 0: // ȴ + full_time = ROULETTE_STANDBY1; + timeNum = CHAR_getWorkInt( meindex, NPC_WORK_MASTERFLG ); + if( ( CHAR_getWorkInt( meindex, NPC_WORK_SYSTIME) + full_time) < NowTime.tv_sec ) { + if( timeNum == 30 ) { //20 + //0 null 1 ׼ 2 3 ͣ + CHAR_setWorkInt( meindex, NPC_WORK_GAMEFLG, 1); + showString( meindex, "עʱʣ£롣", 0); + }else if( timeNum == 10 ) { + showString( meindex, "standby_msg", 0); //㲥 + SetCasinoMap( meindex, 0, 0); //趨ͼע + }else if( timeNum <= 6 ) { //ʼ + //0 null 1 ׼ 2 3 ͣ + CHAR_setWorkInt( meindex, NPC_WORK_GAMEFLG, 2); + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 1); + showString( meindex, "start_msg", 0); //㲥 + } + CHAR_setWorkInt( meindex, NPC_WORK_MASTERFLG, timeNum - 2 ); + } + break; + case 1: // GAME START + if( CHAR_getWorkInt( meindex, NPC_WORK_GAMEFLG) == 3 ) { + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 2); + } + break; + case 2: // GAME END + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 3); + defPlayerGold( meindex , TRUE); //Ӯ + CHAR_setWorkInt( meindex, NPC_WORK_ENDPOINT, 0); + NPC_MAPCLEANGOLD( meindex , CHAR_getInt( meindex, CHAR_FLOOR )); + + LogGamble( + CHAR_getChar( meindex, CHAR_NAME ), "master", + "ROULETTE", CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X ), + CHAR_getInt( meindex, CHAR_Y ) , + CHAR_getWorkInt( meindex, NPC_WORK_MASTERSTONE), 0, 0, 0, 2 + ); + break; + case 3: + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_GAMEFLG, 0); + showString( meindex, "end_msg", 0); //㲥 + SetCasinoMap( meindex, 0, 1); //趨ͼע + CHAR_setWorkInt( meindex, NPC_WORK_MASTERFLG, 30 ); + CHAR_setWorkInt( meindex, NPC_WORK_SYSTIME, NowTime.tv_sec); + break; + default: + NPC_GAMBLEMASTER_RESET( meindex); + break; + } +} + +void defPlayerGold( int meindex , int flg) +{ + int X,Y; + int endpoint; + int End_type = 0; + int toindex=0, i, master_floor; + int player_type; + int gamble_num; + //float def; + char token[256], buff[256]; + char buf1[56],buf2[56]; + BOOL GAMBLE_YES = FALSE; + endpoint = CHAR_getWorkInt( meindex, NPC_WORK_ENDPOINT); + + X = (endpoint >> 16 ); + Y = (endpoint & 0xffff); + + for( End_type = 0; End_type < arraysizeof(EndTypedef) ; End_type++ ) { + if( (X == EndTypedef[ End_type].m_fx) && (Y == EndTypedef[ End_type].m_fy )) { + break; + } + } + + if( End_type == arraysizeof(EndTypedef) ) { + print("\n\n **********GAMBLE MASTER ERROR !! **************"); + print("\n NOT FOUND : X=%d Y=%d EndTypedef[I] !!", X, Y); + return; + } +/*Log===================================== + { //¼ + FILE *fp; + int kp=0,pn=0;; + fp = fopen("./data/npc/roulette/lookgamble.txt","w+"); + if( fp != NULL ) { + if( EndTypedef[ End_type].m_nums < 10000 ) + EndTypedef[ End_type].m_nums = EndTypedef[ End_type].m_nums+1; + for( kp=0; kp 0 && EndTypedef[ kp].m_type > 0 ) { + fprintf( fp," %s н [%d] ", EndTypedef[ kp].str_type, EndTypedef[ kp].m_nums ); + if( (pn+1)%2 == 0 ) { + fprintf( fp," \n"); + } + pn ++; + } + } + fclose( fp); + } + } +//========================================*/ + + if( EndTypedef[ End_type].m_type <= 0 ) { + showString( meindex, "أͨɱ", 0); + }else { + sprintf( token ,"н %s ", EndTypedef[End_type].str_type ); + showString( meindex, token, 0 ); + } + if( EndTypedef[ End_type].m_EO == roulette43 ) { + sprintf( buf1,""); + }else { + sprintf( buf1,"˫"); + } + if( EndTypedef[ End_type].m_RG == roulette41 ) { + sprintf( buf2,""); + }else { + sprintf( buf2,""); + } + //ڳ + toindex = -1; + master_floor = CHAR_getInt( meindex , CHAR_FLOOR); + while( toindex < 10000 ) { + toindex++; + if( !CHAR_CHECKINDEX( toindex) ) + continue; + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + continue; + if( master_floor != CHAR_getInt( toindex, CHAR_FLOOR ) ) //Ƿڶij + continue; + if( CHAR_getWorkInt( toindex, CHAR_WORKSTAKEFLAG) == FALSE ) //Ƿע + continue; + //Ƿ + GAMBLE_YES = FALSE; + CHAR_setWorkInt( toindex, CHAR_WORKSTAKEFLAG, FALSE); + for( i=0; i<5; i++) { + player_type = CHAR_getWorkInt( toindex, i+CHAR_WORKSTAKETYPE1); + gamble_num = 0; + if( player_type > 0 ) { + if( player_type == EndTypedef[End_type].m_type ) { //˺ + if( EndTypedef[End_type].m_type == roulette45 ) { + gamble_num += 40; + }else { + gamble_num += 20; + } + GAMBLE_YES = TRUE; + //Ǯ + Codef_Gold( meindex, toindex, gamble_num, 0, EndTypedef[End_type].str_type ); + }else if( player_type == EndTypedef[End_type].m_RG ) { //˺ + gamble_num += 1; + GAMBLE_YES = TRUE; + Codef_Gold( meindex, toindex, gamble_num, 0, buf2 ); + }else if( player_type == EndTypedef[End_type].m_EO ) { //˵˫ + gamble_num += 1; + GAMBLE_YES = TRUE; + Codef_Gold( meindex, toindex, gamble_num, 0, buf1 ); + }else if( player_type == EndTypedef[End_type].m_SI ) { // + gamble_num += 2; + GAMBLE_YES = TRUE; + sprintf( token,"%s%d", "", EndTypedef[End_type].m_SI-100 ); + Codef_Gold( meindex, toindex, gamble_num, 0, token ); + }else if( player_type == EndTypedef[End_type].m_IN ) { //1-10 11-20 + gamble_num += 1; + GAMBLE_YES = TRUE; + if( (EndTypedef[End_type].m_IN - 100 ) == 11 ) { + snprintf( buff, sizeof( buff),""); + }else if( (EndTypedef[End_type].m_IN - 100 ) == 12 ) { + snprintf( buff, sizeof( buff),""); + } + sprintf( token,"%s%s", "Χ", buff ); + Codef_Gold( meindex, toindex, gamble_num, 0, token ); + }else { //û ۻ + if( (player_type>>16) == EndTypedef[End_type].m_type || + (player_type&0xffff) == EndTypedef[End_type].m_type + ) { //˫ + gamble_num += 10; + GAMBLE_YES = TRUE; + sprintf( token,"%s%s", "˫ţ", EndTypedef[End_type].str_type ); + Codef_Gold( meindex, toindex, gamble_num, 0, token ); + }else if( player_type > 0 ) { //72 73 74 75 û ۻ + strcpy( token, "\0"); + if( player_type >= roulette41 && player_type <= roulette44 ) { //̵˫ + sprintf( token,"%s", "Ѻע ̵˫ û"); + }else if( player_type == roulette45 ) { //00 + sprintf( token,"%s", "Ѻע 00 û"); + }else if( player_type >= roulette51 && player_type <= roulette53 ) { // + sprintf( token,"%s", "Ѻע û"); + }else if( player_type >= roulette61 && player_type <= roulette62 ) { //Χ + sprintf( token,"%s", "Ѻע Χ û"); + }else if( player_type > (1<<16) ) { //˫ + sprintf( token,"%s", "Ѻע ˫ û"); + }else { // + sprintf( token,"%s", "Ѻע û"); + } + gamble_num -= 1; + Codef_Gold( meindex, toindex, gamble_num, 1, token ); + } + } + } + // + CHAR_setWorkInt( toindex, i+CHAR_WORKSTAKETYPE1, 0); + } + if( CHAR_getInt( toindex, CHAR_GAMBLENUM) < 0 ) { + CHAR_setInt( toindex, CHAR_GAMBLENUM, 0 ); + }else if( CHAR_getInt( toindex, CHAR_GAMBLENUM) > 10000 ) { + CHAR_setInt( toindex, CHAR_GAMBLENUM, 10000 ); + } + sprintf( token, "ֳۼΪ%d֡", CHAR_getInt( toindex, CHAR_GAMBLENUM)); + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + + if( GAMBLE_YES == FALSE ) { + sprintf( token, "Ѻעûн"); + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + continue; + } + NPC_MAPCLEANGOLD( meindex , CHAR_getInt( meindex, CHAR_FLOOR )); + } + return; +} + +void Codef_Gold( int meindex, int toindex, int stone,int flg, char *token) +{ + char buf1[256]; + int dnum=-1; + int Master_gnum=0; + Master_gnum = CHAR_getWorkInt( meindex, NPC_WORK_MASTERSTONE); + Master_gnum += stone; + if( !flg ) { + sprintf( buf1,"ϲˣ%sõ %d ", token, stone); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); +#ifdef _FIX_GAMBLENUM + stone += 1; //һʼע۵Ļ +#endif + CHAR_setInt( toindex, CHAR_GAMBLENUM, CHAR_getInt( toindex, CHAR_GAMBLENUM) + stone); + + }else { + dnum = stone; + if( stone < 0 ) { + dnum = (dnum*(-1)); + } + + sprintf( buf1,"%s %d ", token, dnum); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); +#ifdef _FIX_GAMBLENUM +#else + CHAR_setInt( toindex, CHAR_GAMBLENUM, CHAR_getInt( toindex, CHAR_GAMBLENUM) + stone); +#endif + } + + LogGamble( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + "ROULETTE", + CHAR_getInt( toindex, CHAR_FLOOR), + CHAR_getInt( toindex, CHAR_X ), + CHAR_getInt( toindex, CHAR_Y ), + CHAR_getInt( toindex, CHAR_GOLD), + stone, + 0, + CHAR_getInt( toindex, CHAR_GAMBLENUM ), + 1 + ); + + //¼ӯ + if( Master_gnum > 5000000 ) Master_gnum = 5000000; + if( Master_gnum < 0 ) Master_gnum = 0; + CHAR_setWorkInt( meindex, NPC_WORK_MASTERSTONE, Master_gnum); + return; +} +// +void NPC_GAMBLEMASTER_RESET( int meindex) +{ + // + print("\n "); + CHAR_setWorkInt( meindex, NPC_WORK_GAMEFLG, 0);//0 null 1 ׼ 2 + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + showString( meindex, "غϲ㣡ȣ¿ʼ", 1); + NPC_MAPCLEANGOLD( meindex , CHAR_getInt( meindex, CHAR_FLOOR )); + //defPlayerGold( meindex , FALSE); + CHAR_setWorkInt( meindex, NPC_WORK_SYSTIME, NowTime.tv_sec + ROULETTE_ERRTIME); +} + +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gambleroulette.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gambleroulette.c new file mode 100644 index 0000000..67c732e --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_gambleroulette.c @@ -0,0 +1,474 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "readmap.h" +#include "lssproto_serv.h" +#include "handletime.h" + +#ifdef _GAMBLE_ROULETTE +#include "npc_gambleroulette.h" + +#define _OTHER_ROUND //һܷ + +static void Gamble_Roulette_walk( int meindex); +static int Gamble_RouletteSetPoint( int meindex ); +static void Find_Master( int meindex); +int RunRand( int meindex, int flg ); +BOOL SetEndPoint( int meindex ); +void Gamble_Roulette_Reset( int meindex, int flg); +void ResetDataStart( int meindex); +BOOL ReadPointData( int meindex ); +enum { + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT1, + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, //¼index +}; + +typedef struct tagRoulettePoint { + int x; + int y; + int flg; +}RoulettePoint; +RoulettePoint PointData[]={ + {-1,-1,-1},{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}, +}; + +RoulettePoint TestPointData[4*8]; + +#define ROULETTE_STANDBY 1500 +#define ROULETTE_LOOPTIME 1000 + +#define ROULETTE_RUNTIME1 50 + +BOOL NPC_Gamble_RouletteInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_GAMBLEROULETTE ); + //CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, routenum); + //СҪ߼ͣ + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, 0); + CHAR_setWorkInt( meindex, NPC_WORK_SEFLG, -1); + // NPC_WORK_MODE С״̬ 0:ȴ 1:(˳) + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + //ڼͼ + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, 0); + //˳ 1 0 + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 1); + //ڼ· + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, 0); + //趨LOOP TIMER + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, ROULETTE_STANDBY); + //¼ʱ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + if( ReadPointData( meindex) == FALSE ) + return FALSE; + return TRUE; +} + +void NPC_Gamble_RouletteTalked( int meindex , int talkerindex , char *szMes , int color ) +{ + return; +} + +void NPC_Gamble_RouletteWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + return; +} + +void NPC_Gamble_RouletteLoop( int meindex) +{ + int objmeindex = -1, index = 0, act = 0; + objmeindex = CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX); + switch( CHAR_getWorkInt( meindex, NPC_WORK_MODE )) { + case 0: //ֹͣʱȴ Ϊȴ + + //ץindex Ƿ񺰿ʼ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG) < 0 ) { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,5); + }else { + index = CHAR_getWorkInt( meindex, NPC_WORK_SEFLG); + //CHAR_NPCWORKINT7 0 null 1 ׼ 2 3 ͣ + if( CHAR_getWorkInt( index, CHAR_NPCWORKINT7 ) == 2 ) { + CHAR_sendCToArroundCharacter( objmeindex); + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, ROULETTE_RUNTIME1); + //С߼ + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, RunRand( meindex, 0 ) ); + ResetDataStart( meindex);// + if( CHAR_getInt( meindex, CHAR_X) == 14 && + CHAR_getInt( meindex, CHAR_Y) == 8 ) { + }else { + print("\n\n####################\n Сԭ!![%d,%d]", + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y) + ); + + } + }else if( CHAR_getWorkInt( index, CHAR_NPCWORKINT7 ) == 1 || + ( CHAR_getWorkInt( index, CHAR_NPCWORKINT9) < 30 && + CHAR_getWorkInt( index, CHAR_NPCWORKINT9) > 24 ) + ) { //׼ + if( CHAR_getInt( meindex, CHAR_X) == 14 && CHAR_getInt( meindex, CHAR_Y) == 8 ) { + }else { + CHAR_warpToSpecificPoint( meindex, CHAR_getInt( meindex, CHAR_FLOOR), + 14, 8); + CHAR_setInt( meindex, CHAR_X, 14); + CHAR_setInt( meindex, CHAR_Y, 8); + CHAR_sendCToArroundCharacter( objmeindex); + } + } + } + break; + case 1: + Gamble_Roulette_walk( meindex); + break; + case 2: + break; + case 3: + // + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + // + act = CHAR_ACTATTACK; + CHAR_sendWatchEvent( objmeindex, act, NULL,0, FALSE); + CHAR_setWorkInt( meindex, CHAR_WORKACTION, act); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, 0); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, ROULETTE_STANDBY); + + //ϸӾΧڵ + CHAR_sendCToArroundCharacter( objmeindex); + if( SetEndPoint( meindex ) == FALSE ) { + print("\n not Set EndPoint !!"); + } +#ifdef _OTHER_ROUND +#else + ReadPointData( meindex); //load round data +#endif + //ԭ + index = CHAR_getWorkInt( meindex, NPC_WORK_SEFLG); + CHAR_setWorkInt( index, CHAR_NPCWORKINT7, 3); + break; + case 5: //Ѱ + Find_Master( meindex); + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG) < 0 ) { + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 0); + CHAR_setWorkInt( meindex, NPC_WORK_MODE,-1); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + } + break; + default: + // + Gamble_Roulette_Reset( meindex, 0); + break; + } +} + +static void Gamble_Roulette_walk( int meindex) +{ + POINT start, end; + int dir; + int ret; + int i,run_num = 0; + int objmeindex = -1; + objmeindex = CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX); + + start.x = CHAR_getInt( meindex, CHAR_X); + start.y = CHAR_getInt( meindex, CHAR_Y); + end.x = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOX); + end.y = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOY); + // loop timerΪ 1. һ 2. ߵһ + + if( start.x == end.x && start.y == end.y ) { +#ifdef _OTHER_ROUND +#else + int add = 1; + //Ϊ NPC_WORK_ROUNDTRIP != 1 + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP ) != 1 ) { + add *= -1; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +add); +#endif + if( Gamble_RouletteSetPoint( meindex ) == FALSE ) { +#ifdef _OTHER_ROUND + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; +#else + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP ) != 1 ) { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, arraysizeof( PointData) ); // + }else { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, -1); //˳ + } + return; +#endif + }else { + return; + } + } +//-------------------------------------------------------------------- + run_num = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + if( run_num > 0 ){ + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, (run_num - 1) ); + }else { +#ifdef _OTHER_ROUND + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; +#else + int npc_ai=0; + int masterindex; + masterindex = CHAR_getWorkInt( meindex, NPC_WORK_SEFLG); + npc_ai = CHAR_getWorkInt( masterindex, CHAR_NPCWORKINT3); + if( npc_ai > 10 ) { + if( start.x == 7 && start.y == 5 ) { // 7,5 + CHAR_setWorkInt( masterindex, CHAR_NPCWORKINT3, 0); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, 1); + return; + } + } + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; +#endif + } +//-------------------------------------------------------------------- + dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + for( i = 0; i < 100; i ++ ) { + if( dir < 0 ) { + dir = RAND( 0,7); + } + dir = NPC_Util_SuberiWalk( meindex, dir); + if( dir >= 0 && dir <= 7) break; + } + if( dir >= 0 && dir <= 7 ) { + ret = CHAR_walk( meindex, dir, 0); + } +} + +static void Find_Master( int meindex) +{ + int floor, x=14, y=3; + OBJECT object; + floor = CHAR_getInt( meindex , CHAR_FLOOR); + for( object = MAP_getTopObj( floor, x, y) ; object ; object = NEXT_OBJECT(object ) ){ + int findex; + int objindex = GET_OBJINDEX(object); + if( !CHECKOBJECTUSE( objindex)) continue; + findex = OBJECT_getIndex( objindex); + if( !CHAR_CHECKINDEX( findex)) continue; + if( CHAR_getInt( findex , CHAR_WHICHTYPE ) != CHAR_GAMBLEMASTER ) continue; + if( CHAR_getWorkInt( findex, CHAR_NPCWORKINT8) != 10001 ) continue; + CHAR_setWorkInt( meindex, NPC_WORK_SEFLG, findex) ; + return; + } +} + +int RunRand( int meindex, int flg ) +{ +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + int run_num1=0; + int i; + + run_num1 = RAND( 90, 150); + for( i=0; i<6; i++ ) { + run_num1 += RAND( 0, 20); + } + return run_num1; +} + +BOOL SetEndPoint( int meindex ) +{ + int x,y; + int master; + int endpoint; + + master = CHAR_getWorkInt( meindex, NPC_WORK_SEFLG); + if( !CHAR_CHECKINDEX( master) ) + return FALSE; + + if( CHAR_getWorkInt( master, CHAR_NPCWORKINT7) != 2 ) { + print("\n error( master,CHAR_NPCWORKINT7) != 2 "); + return FALSE; + } + + x = CHAR_getInt( meindex, CHAR_X); + y = CHAR_getInt( meindex, CHAR_Y); + endpoint = (x<<16)+(y<<0); + CHAR_setWorkInt( master, CHAR_NPCWORKINT10, endpoint); + return TRUE; +} + +void Gamble_Roulette_Reset( int meindex, int flg) +{ + // + int index; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, 0); + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, ROULETTE_STANDBY); + + index = CHAR_getWorkInt( meindex, NPC_WORK_SEFLG); + if( !CHAR_CHECKINDEX( index) ) { + print("\n Gamble_Roulette error: no master !!"); + return; + } + CHAR_setWorkInt( index, CHAR_NPCWORKINT7, 3); + CHAR_setWorkInt( index, CHAR_NPCWORKINT10, 0); +} + +void ResetDataStart( int meindex ) +{ +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) + int Start=1; + struct tagWalkStartPoint{ + int x; + int y; + int rip; + }WalkStart[]={ + {7,5,1}, {7,11,0}, {22,11,1}, {22,5,0}, + }; + Start = RAND( 0, 3); + + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, WalkStart[Start].rip ); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, Start); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, WalkStart[Start].x ); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, WalkStart[Start].y ); + + { + int i=0,k; + int RIP = CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP); + k = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT); + if( RIP ) { + while( i < (arraysizeof( TestPointData))) { + k++; + if( k > 3 ) k = 0; + TestPointData[i].x = PointData[k].x; + TestPointData[i].y = PointData[k].y; + i++; + } + }else { + while( i < (arraysizeof( TestPointData))) { + k--; + if( k < 0 ) k = 3; + TestPointData[i].x = PointData[k].x; + TestPointData[i].y = PointData[k].y; + i++; + } + } + } +#ifdef _OTHER_ROUND + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, 0); +#endif +} + +BOOL ReadPointData( int meindex ) +{ + + char buf1[256], buf2[32], buf3[16]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int k=1,i=0; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "roulette",buf1, sizeof(buf1)) == NULL ) { + print("\n roulette error: not found !!"); + return FALSE; + } + k=1; + while( getStringFromIndexWithDelim( buf1, ";", k, buf2, sizeof(buf2) ) != FALSE ) { + k++; + if( strstr( buf2,",") == NULL ) + continue; + + if( getStringFromIndexWithDelim( buf2, ",", 1, buf3, sizeof(buf3)) == FALSE) { + return FALSE; + } + PointData[i].x = atoi( buf3); + if( getStringFromIndexWithDelim( buf2, ",", 2, buf3, sizeof(buf3)) == FALSE) { + return FALSE; + } + PointData[i].y = atoi( buf3); + if( i > 9 ) { + break; + } + i++; + } +#ifdef _OTHER_ROUND +#else + Gamble_RouletteSetPoint( meindex); +#endif + return TRUE;//arraysizeof( PointData) +} + +static int Gamble_RouletteSetPoint( int meindex ) +{ +#ifdef _OTHER_ROUND + int i; + i = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, TestPointData[i].x ); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, TestPointData[i].y ); + i++; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, i); + if( i >= arraysizeof( TestPointData) ) { + return FALSE; + } +#else + int i; + i = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT); + if( i<0 || i>arraysizeof( PointData) -1) { + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, PointData[i].x ); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, PointData[i].y ); +#endif + {//· + struct tagWalkStartPoint{ + int x; + int y; + }WalkStart[]={ + {22,5}, {7,5}, {7,11}, {22,11}, {22,5}, {7,5} + }; + int ch_x,ch_y; + int next_x,next_y; + int h; + ch_x = CHAR_getInt( meindex, CHAR_X); + ch_y = CHAR_getInt( meindex, CHAR_Y); + for( h=1; h<5; h++) { + if( ch_x == WalkStart[h].x && + ch_y == WalkStart[h].y) { + next_x = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOX); + next_y = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOY); + if( next_x == WalkStart[h+1].x && + next_y == WalkStart[h+1].y) { + + }else if( next_x == WalkStart[h-1].x && + next_y == WalkStart[h-1].y) { + }else { + print("\n ##############################"); + print("\n ERR : [%d,%d] -> [%d,%d]",ch_x,ch_y,next_x,next_y); + } + break; + } + } + } + return TRUE; +} + +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_healer.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_healer.c new file mode 100644 index 0000000..9bfa3a6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_healer.c @@ -0,0 +1,180 @@ +#include "version.h" +#include +#include +#include + +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" +#include "npc_healer.h" + +#define RANGE 2 +void NPC_HealerSpeak( int index, int talker); +BOOL NPC_MoneyCheck(int meindex,int talker); +int NPC_CostCheck(int talker); +void NPC_CharCheckPoint(int meindex,int talker); +int NPC_WorkInput(int meindex,int talker); + + +/********************************** + +************************************/ +BOOL NPC_HealerInit( int meindex ) +{ + //ëס¡ɬ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEHEALER ); + // ƥئ ۢئо + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + //ľئ +// CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); + + return TRUE; + +} + + + + +/*------------------------------------------- + * + * ľHP,MPë巰 + * + --------------------------------------------*/ +void NPC_HealerTalked( int meindex , int talker , char *msg ,int color ) +{ + + char* npcarg; + char token[32]; + int msgNo; + + + npcarg = CHAR_getChar(meindex,CHAR_NPCARGUMENT); + + getStringFromIndexWithDelim( npcarg, "|", 1, token,sizeof( token)); + msgNo = atoi( token ); + + /*---帲ƻ ɱ---*/ + if( CHAR_getInt( talker , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) return; + + /*--- 1׷ƥ¾---*/ + /* */ + if( NPC_Util_CharDistance( talker, meindex ) > 2) return; + + if( (CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) == 0) + || (CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) == 2) ) + { + /*--ƽﵤ--*/ + NPC_HealerAllHeal( talker); + if(msgNo == 1) { + CHAR_talkToCli( talker, meindex, + "Ѿȫظ´εıмࡣ",CHAR_COLORWHITE); + + }else if(msgNo == 2) { + CHAR_talkToCli( talker, meindex, + "ܳʵҰظɣ",CHAR_COLORWHITE); + } + + }else{ + int i = 0; + int otherindex; + + for( i=0 ; i < getPartyNum(talker ) ; i++) + { + otherindex = CHAR_getWorkInt( talker, CHAR_WORKPARTYINDEX1 + i); + if(otherindex != -1){ + + NPC_HealerAllHeal( otherindex); + if(msgNo == 1) { + CHAR_talkToCli( otherindex, meindex, + "Ѿȫظ´εıмࡣ",CHAR_COLORWHITE); + + }else if(msgNo == 2) { + CHAR_talkToCli( otherindex, meindex, + "ܳʵҰظɣ",CHAR_COLORWHITE); + } + } + } + } +} + + +/*----------------------*/ +/* */ +/*-----------------------*/ +void NPC_HealerAllHeal( int talker ) +{ + int i; + int petindex; + char petsend[3]; + char msgbuf[5]; + + CHAR_setInt( talker , CHAR_HP ,CHAR_getWorkInt( talker, CHAR_WORKMAXHP ) ); + CHAR_setInt( talker , CHAR_MP ,CHAR_getWorkInt( talker, CHAR_WORKMAXMP ) ); + + + + for(i = 0 ; i < CHAR_MAXPETHAVE; i ++) { + petindex = CHAR_getCharPet( talker, i); + + if( petindex == -1 ) continue; + + /* ƽҷ¼ */ + if( !CHAR_CHECKINDEX( talker ) ) continue; + + /* ʸindexë */ + if( CHAR_CHECKINDEX( petindex) == FALSE ) continue; + + /*----*/ + CHAR_setFlg( petindex, CHAR_ISDIE, 0); + CHAR_setInt( petindex , CHAR_HP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXHP ) ); + CHAR_setInt( petindex , CHAR_MP ,CHAR_getWorkInt( petindex, CHAR_WORKMAXMP ) ); + + /*--ɷ¶Ʃ--*/ + CHAR_complianceParameter( petindex ); + sprintf( petsend, "K%d", i ); + CHAR_sendStatusString( talker , petsend ); + } + + /*---޻ľޱ˪--*/ + if(CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) + { + int topartyarray = -1; + int oyaindex = CHAR_getWorkInt( talker , CHAR_WORKPARTYINDEX1); + + if( CHAR_CHECKINDEX( oyaindex )) { + int i; + + /* ֧޼ ë */ + for( i = 0; i < getPartyNum(oyaindex ); i ++ ) { + int workindex = CHAR_getWorkInt( oyaindex, CHAR_WORKPARTYINDEX1 + i); + if( CHAR_CHECKINDEX( workindex) ) { + if( workindex == talker ) { + topartyarray = i; + break; + } + } + } + + for( i = 0; i < getPartyNum(talker ); i ++ ) { + int otherindex = CHAR_getPartyIndex( talker, i); + /* ɷ¶ë˪ */ + if( CHAR_CHECKINDEX( otherindex) ) { + snprintf( msgbuf, sizeof( msgbuf), "N%d", topartyarray); + if( otherindex != talker) { + CHAR_sendStatusString( otherindex, msgbuf); + } + } + } + } + } + + /*--ɷ¶˪Ի--*/ + CHAR_send_P_StatusString( talker, CHAR_P_STRING_HP); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_MP); + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemchange.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemchange.c new file mode 100644 index 0000000..470d40a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemchange.c @@ -0,0 +1,254 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "npc_itemchange.h" + +#ifdef _ITEM_NPCCHANGE +enum { + ITEMCHANGE_START=1, + ITEMCHANGE_SELECT, + ITEMCHANGE_MESSAGE, + ITEMCHANGE_END, + ITEMCHANGE_ERROR, + +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +static void NPC_ItemchangeMan_selectWindow( int meindex, int toindex, int num,int select); +BOOL ItemchangeMan_GetNeedStr( int meindex, int toindex, char *npcarg, char *token, int num ); +BOOL ItemchangeMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token); + +BOOL NPC_ItemchangeManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_ITEMCHANGENPC); + + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_ItemchangeManTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if( NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if( NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_ItemchangeMan_selectWindow( meindex, talkerindex, ITEMCHANGE_START, -1); + +} + +void NPC_ItemchangeManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int flg=-1; + if( select == WINDOW_BUTTONTYPE_NO || select == WINDOW_BUTTONTYPE_CANCEL) + return; + switch( seqno) { + case NPC_ITEMCHANGE_START: + break; + case NPC_ITEMCHANGE_SELECT: + NPC_ItemchangeMan_selectWindow( meindex, talkerindex, ITEMCHANGE_SELECT, flg); + break; + case NPC_ITEMCHANGE_MESSAGE: + flg = atoi( data); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, flg); + NPC_ItemchangeMan_selectWindow( meindex, talkerindex, ITEMCHANGE_MESSAGE, flg); + break; + case NPC_ITEMCHANGE_END: + flg = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + NPC_ItemchangeMan_selectWindow( meindex, talkerindex, ITEMCHANGE_END , flg); + break; + } + +} + +static void NPC_ItemchangeMan_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + + switch( num) { + case ITEMCHANGE_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "START_MSG", token, sizeof( token) ) == NULL) { + print("TranserMan Get START_MSG ERROR !"); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, ITEMCHANGE_START); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_ITEMCHANGE_SELECT; + break; + case ITEMCHANGE_SELECT: + if( ItemchangeMan_GetMenuStr( meindex, toindex, npcarg, token) == FALSE ) + return; + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, ITEMCHANGE_SELECT); + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_ITEMCHANGE_MESSAGE; + break; + case ITEMCHANGE_MESSAGE: + if( ItemchangeMan_GetNeedStr( meindex, toindex, npcarg, token, select ) == FALSE ) + return; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_ITEMCHANGE_END; + break; + case ITEMCHANGE_END: + if( ActionNpc_CheckMenuFree( meindex, toindex, npcarg, select ) == FALSE ){ + memset( token, 0, sizeof( token)); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FAIL_MSG", token, sizeof( token) ) != NULL) { + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + } + } + return; + break; + case ITEMCHANGE_ERROR: + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +BOOL ItemchangeMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token) +{ + char buf1[1024], buf2[256], buf3[256]; + char NullName[256] = {"δ֪Ʒ"}; + BOOL FINDS=FALSE; + int talkNo=1; + int addID; + if( npcarg == NULL ) return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "MenuHead", buf1, sizeof( buf1) ) == NULL){ + print("ItemchangeMan Get MenuHead ERROR!"); + return FALSE; + } + + sprintf( token, "%s\n", buf1); + + while( getStringFromIndexWithDelim( npcarg,"}", talkNo, buf1, sizeof( buf1)) != FALSE ) { + char *ItemName; + talkNo++; + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "CHANGEITEM", buf2, sizeof( buf2)) != NULL ){ + addID = atoi( buf2); + if( (ItemName = ITEM_getNameFromNumber( addID)) == "\0" ){ + sprintf( buf3, " %s\n", NullName); + }else{ + sprintf( buf3, " %s\n", ItemName); + } + // continue; + }else { + memset( buf3, 0, sizeof( buf3)); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "CHANGEMSG", buf3, sizeof( buf3)) == NULL ) + continue; + strcat( buf3, "\n"); + } + FINDS = TRUE; + strcat( token, buf3); + } + + return FINDS; +} + +BOOL ItemchangeMan_GetNeedStr( int meindex, int toindex, char *npcarg, char *token, int num ) +{ + char buf1[1024], buf2[256], buf3[256]; + char NullName[256] = {"δ֪Ʒ"}; + int talkNo=1, addID, i=0; + BOOL FINDS = FALSE; + if( npcarg == NULL ) return FALSE; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "NeedHead", buf1, sizeof( buf1) ) == NULL){ + print("ItemchangeMan Get NeedHead ERROR!\n%s", npcarg); + return FALSE; + } + sprintf( token, "%s\n", buf1); + if( getStringFromIndexWithDelim( npcarg,"}", num, buf1, sizeof( buf1)) == FALSE ) { + printf("Get NeedMess error !!\n"); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "NeedItem", buf2, sizeof( buf2) ) != NULL){ + while( getStringFromIndexWithDelim( buf2, ",", talkNo, buf1, sizeof( buf1)) != FALSE ) { + char *ItemName=NULL; + talkNo++; + + addID = atoi( buf1); + FINDS = TRUE; + if( (ItemName = ITEM_getNameFromNumber( addID)) == "\0" ){ + sprintf( buf3, "%s ", NullName); + }else{ + sprintf( buf3, "%s ", ItemName); + } + strcat( token, buf3); + if( i%3 == 0 ) + strcat( token, "\n"); + i++; + } + }else { + if( NPC_Util_GetStrFromStrWithDelim( buf1, "NeedMsg", buf2, sizeof( buf2) ) == NULL) + return FALSE; + sprintf( token, "%s ", buf2); + FINDS = TRUE; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf2, "DelGold", buf1, sizeof( buf1)) != NULL ) { + char goldmess[256]; + int gold = atoi( buf1); + if( gold > 0 ) { + sprintf( goldmess, "ʯ:%d \n", gold); + strcat( token, goldmess); + } + } + + return FINDS; +} +//void ItemchangeMan_CheckMenuFree( int meindex, int toindex, char *npcarg, int nums) +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemshop.c new file mode 100644 index 0000000..83b1f7c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_itemshop.c @@ -0,0 +1,1157 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "pet_skill.h" +#include "npc_eventaction.h" +#include "readmap.h" +#include "log.h" +#include "family.h" +#include "saacproto_cli.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#define MAXSHOPITEM 33 +static void NPC_ItemShop_selectWindow( int meindex, int talker, int num,int select); +void NPC_ItemShop_BuyMain(int meindex,int talker,int before ); +void NPC_GetItemList(char *argstr,char * argtoken2); + +void NPC_ItemStrStr(int itemID,double rate,char *name,char *token2,int iCostFame,int iChangeItemCost); + +BOOL NPC_SetNewItem(int meindex,int talker,char *data); +BOOL NPC_SellNewItem(int meindex,int talker,char *data); + +void NPC_ItemShop_Menu(int meindex,int talker); + +int NPC_GetLimtItemList(int talker,char *argstr,char *token2,int sell); + +void NPC_ItemShop_SellMain(int meindex,int talker,int select); +int NPC_GetSellItemList(int itemindex,int flg,char *argstr,char *argtoken,int select,int sell); +BOOL NPC_AddItemBuy(int meindex, int talker,int itemID,int kosuu,double rate,int iCostFame,int iChangeItemCost); +int NPC_SellItemstrsStr(int itemindex,int flg,double rate,char *argtoken,int select,int sell); +void NPC_LimitItemShop(int meindex,int talker,int select); +void NPC_ExpressmanCheck(int meindex,int talker); + +enum{ + NPC_SHOP_WORK_NO = CHAR_NPCWORKINT1, + NPC_SHOP_WORK_EV = CHAR_NPCWORKINT2, + NPC_SHOP_WORK_EXPRESS = CHAR_NPCWORKINT3, +}; + + + +typedef struct { + char arg[32]; + int type; +}NPC_Shop; + + +static NPC_Shop TypeTable[] = { + { "FIST", 0 }, //ȭ + { "AXE", 1 }, // + { "CLUB", 2 }, // + { "SPEAR", 3}, //ì + { "BOW", 4}, // + { "SHIELD", 5}, // + { "HELM", 6 }, //ͷ + { "ARMOUR", 7 }, // + { "BRACELET", 8}, // + { "ANCLET", 9 }, // + { "NECKLACE", 10}, // + { "RING", 11}, //ָ + { "BELT", 12}, // + { "EARRING", 13}, // + { "NOSERING", 14}, //ǻ + { "AMULET", 15}, // + { "OTHER", 16}, + { "BOOMERANG", 17}, // + { "BOUNDTHROW", 18}, + { "BREAKTHROW", 19}, //Ͷ +#ifdef _ITEM_TYPETABLE + { "DISH", 20}, + { "METAL", 21}, + { "JEWEL", 22}, + { "WARES", 23}, + { "WBELT", 24}, + { "WSHIELD", 25}, + { "WSHOES", 26}, + { "WGLOVE", 27}, + { "ANGELTOKEN", 28}, + { "HEROTOKEN", 29}, +#endif + { "ACCESSORY", 30}, // + { "OFFENCE", 40}, // + { "DEFENCE", 50}, // + +}; + +BOOL NPC_ItemShopInit( int meindex ) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEITEMSHOP ); + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("GetArgStrErr"); + return FALSE; + } + if(strstr(argstr,"LIMITSHOP") != NULL) { + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_NO, 1); + }else{ + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_NO, 0); + } + if(strstr( argstr, "EVENT") != NULL) { + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_EV, 1); + }else{ + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_EV, 0); + } + if(strstr( argstr, "EXPRESS") != NULL) { + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_EXPRESS, 1); + }else{ + CHAR_setWorkInt( meindex, NPC_SHOP_WORK_EXPRESS, 0); + } + + return TRUE; +} + +void NPC_ItemShopTalked( int meindex , int talker , char *szMes ,int color ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff[1024]; + char buf2[256]; + char token[1024]; + int i = 1; + BOOL sellonlyflg = FALSE; + char sellmsg[1024]; + + if( CHAR_getInt( talker , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if(NPC_Util_isFaceToFace( meindex, talker, 2) == FALSE) {//̸ʱǷ + if( NPC_Util_CharDistance( talker, meindex ) > 1) return; //1 + } + + //ȡnpc趨ڵ,ΪNULL, + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL){ + print("itemshopGetArgStrErr"); + return; + } + + //ȡNPCֻѶϢ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "sellonly_msg", token, sizeof( token)) != NULL){ + sellonlyflg = TRUE; //NPCҵĶ + strcpysafe(sellmsg, sizeof( sellmsg), token);//:sellmsgֵ->רĵꡣ + } + + //ȡָ. buffΪһִָ,:,,л,kau,buy,menu,лл,,ҴЩ־ʱ,Ϳ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "buy_msg", buff, sizeof( buff)) != NULL ){ + while(getStringFromIndexWithDelim(buff,",",i,buf2,sizeof(buf2)) != FALSE ){ + i++; //ָ8,iͻӵ8 + if( strstr( szMes, buf2) != NULL) { + if( CHAR_getWorkInt( meindex, NPC_SHOP_WORK_EV) == 0) { + if( CHAR_getWorkInt( meindex, NPC_SHOP_WORK_NO) == 1) { + if( sellonlyflg ) { + NPC_ItemShop_selectWindow( meindex, talker, 3, -1); + return; + } + }else{ + NPC_ItemShop_selectWindow( meindex, talker, 1, -1); + return; + } + }else{ + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_NO) == 1) { + if( sellonlyflg) { + NPC_ItemShop_selectWindow( meindex, talker, 3, -1); + return; + } + }else{ + NPC_ItemShop_selectWindow( meindex, talker, 1, -1); + return; + } + return; + } + } + } + } + i=1; + + //ȡָ. buffΪһִָ,:,,sell,uru ҴЩ־ʱ,Ϳ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "sell_msg", buff, sizeof( buff)) != NULL ){ + while( getStringFromIndexWithDelim(buff,",", i,buf2,sizeof(buf2)) != FALSE ){ + i++; + if(strstr(szMes,buf2) != NULL) { + NPC_ItemShop_selectWindow( meindex, talker, 2, -1); + return; + } + } + } + i = 1; + + //ѶϢ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "other_msg", buff, sizeof( buff)) != NULL ){ + while(getStringFromIndexWithDelim( buff, ",", i, buf2, sizeof( buf2)) != FALSE ){ + i++; + if(strstr(szMes,buf2) != NULL) { + if(NPC_Util_GetStrFromStrWithDelim( argstr, "hint_msg", + token, sizeof( token)) != NULL) + { + CHAR_talkToCli( talker, meindex, token, CHAR_COLORWHITE); + return; + } + } + } + } + + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_NO) == 1) { + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_EV) == 1) { + if( sellonlyflg) { + CHAR_talkToCli( talker, meindex, sellmsg, CHAR_COLORWHITE); + return; + } + }else{ + if( sellonlyflg) { + NPC_ItemShop_selectWindow( meindex, talker, 3, -1); + return; + } + } + }else{ + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_EV) == 1) { + if( sellonlyflg) { + CHAR_talkToCli( talker, meindex, sellmsg, CHAR_COLORWHITE); + return; + } + }else{ + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_EXPRESS) == 1) { + NPC_ExpressmanCheck( meindex, talker); + }else{ + NPC_ItemShop_selectWindow( meindex, talker, 0, -1); + } + } + } + +} + +static void NPC_ItemShop_selectWindow( int meindex, int talker, int num,int select) +{ + switch( num) { + case 0: + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD);//ͽǮ,100Ԫ ͳȥϸʽΪ P8Nz2|100| + + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_EXPRESS) == 1 ) { + if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_NO) ==0 ) { + NPC_ExpressmanCheck( meindex, talker);//ë + } + }else if(CHAR_getWorkInt( meindex, NPC_SHOP_WORK_NO) == 1) { + + }else{ + NPC_ItemShop_Menu( meindex, talker);//ѡ(,,뿪)СӴ + } + break; + + case 1://Ӵ + CHAR_sendStatusString( talker,"I");//еĵ߸Client + NPC_ItemShop_BuyMain( meindex, talker, select); + break; + + case 2://Ӵ + CHAR_sendStatusString( talker,"I"); + NPC_ItemShop_SellMain( meindex, talker, select); + break; + + case 3: + NPC_LimitItemShop( meindex, talker, select); + break; + + } +} + +void NPC_ItemShopWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 3) { + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + + makeStringFromEscaped( data); + + switch( seqno){ + + case CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG: + if(atoi( data) == 1 ) NPC_ItemShop_selectWindow(meindex, talkerindex, 1, -1); + if(atoi( data) == 2) NPC_ItemShop_selectWindow(meindex, talkerindex, 2, -1); + if(atoi( data) == 3) return;/*--ئ--*/ + break; + case CHAR_WINDOWTYPE_WINDOWITEMSHOP_BUY_MSG: + if(NPC_SetNewItem(meindex , talkerindex, data) == TRUE) { + NPC_ItemShop_selectWindow( meindex, talkerindex, 1, 0); + }else{ + NPC_ItemShop_selectWindow( meindex, talkerindex ,0, -1); + } + + break; + case CHAR_WINDOWTYPE_WINDOWITEMSHOP_SELL_MSG: + if(NPC_SellNewItem(meindex , talkerindex, data) == TRUE) { + NPC_ItemShop_selectWindow( meindex, talkerindex, 2, 0); + + }else{ + NPC_ItemShop_selectWindow( meindex, talkerindex, 0, -1); + } + + break; + + case CHAR_WINDOWTYPE_WINDOWITEMSHOP_LIMIT: + if(select == WINDOW_BUTTONTYPE_YES) { + NPC_ItemShop_selectWindow( meindex, talkerindex ,2, -1); + + }else if(select == WINDOW_BUTTONTYPE_NO) { + return; + }else if(select == WINDOW_BUTTONTYPE_OK) { + NPC_ItemShop_selectWindow( meindex, talkerindex, 2, -1); + } + break; + + case CHAR_WINDOWTYPE_WINDOWITEMSHOP_EXPRESS: + if(atoi(data) == 2) { + NPC_ItemShop_selectWindow( meindex, talkerindex, 1, -1); + }else if(atoi( data) == 4) { + NPC_ItemShop_selectWindow( meindex, talkerindex, 2, -1); + } + } +} + +void NPC_ItemShop_BuyMain(int meindex,int talker,int before ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[NPC_UTIL_GETARGSTR_BUFSIZE]; + int fd = getfdFromCharaIndex( talker); + + char token2[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[256]; + char buff[256]; + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("itemshop_GetArgStr_Err"); + return; + } +#ifdef _ADD_STATUS_2 + sprintf(token,"FAME|%d",CHAR_getInt(talker,CHAR_FAME)/100); + lssproto_S2_send(fd,token); +#endif + if(before != -1) { + sprintf(token,"0|0"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_ITEMSHOPMAIN, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_BUY_MSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + }else{ + + NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", buff, sizeof( buff)); + NPC_Util_GetStrFromStrWithDelim( argstr, "buy_main", buff2, sizeof( buff2)); +#ifdef _VERSION_25 + sprintf( token, "0|1|%d|%s|%s|%-72s:%d|", CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG, + CHAR_getChar( meindex, CHAR_NAME), buff, buff2, CHAR_getInt(talker,CHAR_FAME)/100); +#else + sprintf(token,"0|1|%d|%s|%s|%s|", CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG, + CHAR_getChar( meindex, CHAR_NAME), buff, buff2); +#endif + NPC_Util_GetStrFromStrWithDelim( argstr, "what_msg", buff, sizeof( buff)); + NPC_Util_GetStrFromStrWithDelim( argstr, "level_msg", buff2, sizeof( buff)); + + snprintf( token2, sizeof( token2), "%s|%s", buff, buff2); + + strncat( token, token2, sizeof( token)); + + NPC_Util_GetStrFromStrWithDelim( argstr, "realy_msg", buff, sizeof( buff)); + NPC_Util_GetStrFromStrWithDelim( argstr, "itemfull_msg", buff2, sizeof( buff2)); + + sprintf( token2, "|%s|%s", buff, buff2); + strncat(token , token2,sizeof(token)); + strcpy(token2, "|"); + + NPC_GetItemList( argstr, token2); + strncat( token, token2, sizeof( token)); + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_ITEMSHOPMAIN, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_BUY_MSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + +} +void NPC_GetItemList(char *argstr,char *argtoken) +{ + int i = 1; + int tmp; + char *name ="\0"; + char buff2[256]; + char buff3[NPC_UTIL_GETARGSTR_LINEMAX]; + char buff4[256]; + char buff5[NPC_UTIL_GETARGSTR_LINEMAX]; + char buff6[256]; + int iCostFame = 0; + int iChangeItemCost = 0; + + char buff[NPC_UTIL_GETARGSTR_LINEMAX]; + char token2[NPC_UTIL_GETARGSTR_BUFSIZE]; + double rate = 1.0; + int loopcnt = 0; + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "buy_rate", buff2, sizeof( buff2)) + != NULL){ + rate = atof( buff2); + } + memset(buff3,0,sizeof(buff3)); + memset(buff5,0,sizeof(buff5)); + if(NPC_Util_GetStrFromStrWithDelim(argstr,"CostFame",buff3,sizeof(buff3)) == NULL) iCostFame = -1; + if(NPC_Util_GetStrFromStrWithDelim(argstr,"ChangeItemCost",buff5,sizeof(buff5)) == NULL) iChangeItemCost = -1; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "ItemList", buff, sizeof( buff)) != NULL ){ + while( getStringFromIndexWithDelim(buff,",",i,buff2,sizeof(buff2)) !=FALSE ) { + if(iCostFame > -1){ + if(getStringFromIndexWithDelim(buff3,",",i,buff4,sizeof(buff4)) != FALSE) iCostFame = atoi(buff4); + } + if(iChangeItemCost > -1){ + if(getStringFromIndexWithDelim(buff5,",",i,buff6,sizeof(buff6)) != FALSE) iChangeItemCost = atoi(buff6); + } + i++; + if(strstr( buff2, "-") == NULL) { + name = ITEM_getNameFromNumber( atoi(buff2)); + if(name == "\0") continue; + loopcnt++; + if(loopcnt == MAXSHOPITEM) break; + NPC_ItemStrStr( atoi( buff2), rate, name, token2,iCostFame,iChangeItemCost); + strncat( argtoken, token2, sizeof(token2)); + }else{ + int start; + int end; + getStringFromIndexWithDelim( buff2, "-", 1, token2, sizeof(token2)); + start = atoi( token2); + getStringFromIndexWithDelim( buff2, "-", 2 ,token2, sizeof(token2)); + end = atoi( token2); + if(start > end){ + tmp = start; + start = end; + end = tmp; + } + end++; + for(; start < end ; start++ ) { + /*--ڒo???--*/ + + name = ITEM_getNameFromNumber( start ); + if(name == "\0") continue; + loopcnt++; + if(loopcnt == MAXSHOPITEM) break; + NPC_ItemStrStr( start, rate, name, token2,iCostFame,iChangeItemCost); + strncat( argtoken, token2, sizeof(token2)); + } + } + } + } +} + +void NPC_ItemStrStr(int itemID,double rate,char *name,char *token2,int iCostFame,int iChangeItemCost) +{ + + int gold; + int level; + int graNo; + char info[1024]; + char escape[256]; + + if(iChangeItemCost > -1) gold = iChangeItemCost; + else + gold = ITEM_getcostFromITEMtabl( itemID); + level = ITEM_getlevelFromITEMtabl( itemID); + graNo = ITEM_getgraNoFromITEMtabl( itemID); + strcpy(escape,ITEM_getItemInfoFromNumber( itemID)); + gold=(int)(gold * rate); + + makeEscapeString( escape, info, sizeof( info)); + makeEscapeString( name, escape, sizeof( escape)); +#ifdef _VERSION_25 + if(iCostFame < 0){ + sprintf( token2, "%s|0|%d|%d|%d|%s|", escape, level, gold, graNo, info); + }else{ + sprintf( token2, "%-18s%8d|0|%d|%d|%d|%s|", escape, iCostFame < 0 ? 0:iCostFame/100, level, gold, graNo, info); + } +#else + sprintf(token2,"%s|0|%d|%d|%d|%s|%d|",escape,level,gold,graNo,info,iCostFame < 0 ? -1:iCostFame/100); +#endif +} + +BOOL NPC_SetNewItem(int meindex,int talker,char *data) +{ + + char buf[1024]; + char buff2[128]; + + char buff3[1024]; + char buff4[128]; + char buff5[1024]; + char buff6[128]; + int iCostFame = 0; + int iChangeItemCost = 0; + + int i = 1, j = 1; + int select; + int kosuu = 0; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + double rate = 1.0; + int gold = 0; + int kosuucnt = 0; + int itemindex; + + /*--߯Ȼ׷ëѱݩ--*/ + getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)); + select = atoi(buf); + if(select == 0) return FALSE; + getStringFromIndexWithDelim( data, "|", 2, buf, sizeof( buf)); + kosuu = atoi(buf); + if( kosuu <= 0 ) return FALSE; + + /*--Ѽ ¾-*/ + for( i = CHAR_STARTITEMARRAY ; i < CheckCharMaxItem(talker) ; i++ ) { + itemindex = CHAR_getItemIndex( talker , i ); + if( !ITEM_CHECKINDEX( itemindex) ) { + kosuucnt++; + } + } + + /*--߯Ȼ Ѽ ˼ ӡﴡ Իƾмƥ--*/ + /*--ӡ ë ľ--*/ + if( kosuucnt < kosuu) kosuu = kosuucnt; + + /*--δ޷¡--*/ + if(kosuucnt == 0 ) return FALSE; + + i = 1; + + /*--Ҽ̻ 跴̻ﻥئ巴 --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("shop_GetArgStr_Err"); + return FALSE; + } + + /*---ë ئľ1.0)-*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr, "buy_rate", buf, sizeof( buf)) != NULL) { + rate= atof( buf); + } + + memset(buff3,0,sizeof(buff3)); + memset(buff5,0,sizeof(buff5)); + if(NPC_Util_GetStrFromStrWithDelim(argstr,"CostFame",buff3,sizeof(buff3)) == NULL) iCostFame = -1; + if(NPC_Util_GetStrFromStrWithDelim(argstr,"ChangeItemCost",buff5,sizeof(buff5)) == NULL) iChangeItemCost = -1; + + /*--ʧ ةܰë浤Ƿ-*/ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "ItemList", buf, sizeof( buf)) != NULL ){ + while(getStringFromIndexWithDelim(buf , "," , j, buff2, sizeof(buff2)) != FALSE ){ + if(iCostFame > -1){ + if(getStringFromIndexWithDelim(buff3,",",j,buff4,sizeof(buff4)) != FALSE) iCostFame = atoi(buff4); + } + if(iChangeItemCost > -1){ + if(getStringFromIndexWithDelim(buff5,",",j,buff6,sizeof(buff6)) != FALSE) iChangeItemCost = atoi(buff6); + } + j++; + /*-- "-"ֳľ¾--*/ + if(strstr( buff2, "-") == NULL) { + if( ITEM_getcostFromITEMtabl(atoi(buff2)) !=-1) { + if ( i == select) { + /*---ʧ ة---*/ + /*----*/ + if(NPC_AddItemBuy(meindex, talker,atoi(buff2),kosuu,rate,iCostFame,iChangeItemCost) != TRUE) + { + return FALSE; + } + return TRUE; + } + i++; + } + }else{ + /*--ʧ ة 15-25 ƥ˪ľ--*/ + int start; + int end; + + /* "-"ƥľ炙Ѱ Ѱë --*/ + getStringFromIndexWithDelim( buff2, "-", 1, argstr, sizeof(argstr)); + start = atoi( argstr); + getStringFromIndexWithDelim( buff2, "-", 2 ,argstr, sizeof(argstr)); + end = atoi( argstr); + end++; + + /*-- įѱئȻգ ľ׸**/ + if(start > end){ + gold = start; + start = end; + end = gold; + } + + /*--"-"ƥľмʧ ةë ë --*/ + for(; start < end ; start++ ) { + if( ITEM_getcostFromITEMtabl( start) != -1) { + if ( i == select) { + /*---ʧ ة---*/ + /*----*/ + if(NPC_AddItemBuy(meindex, talker, start, kosuu, rate,iCostFame,iChangeItemCost) != TRUE) + { + return FALSE; + } + return TRUE; + } + i++; + } + } + } + } + } + + return FALSE; + +} + +/*--------------------------------------------- + *ʧ ةܰë浤 + *--------------------------------------------*/ +BOOL NPC_AddItemBuy(int meindex, int talker,int itemID,int kosuu,double rate,int iCostFame,int iChangeItemCost) +{ + + int itemindex; + int i; + int gold; + int ret; + int maxgold; + + int iTotalCostFame = -1; + + if(iChangeItemCost > -1) gold = iChangeItemCost; + else + gold = ITEM_getcostFromITEMtabl( itemID); + gold = (int)(gold * rate); + + maxgold = gold * kosuu; + if(CHAR_getInt( talker, CHAR_GOLD) < maxgold ) return FALSE; + + if(iCostFame > 0){ + iTotalCostFame= iCostFame * kosuu; + if(CHAR_getInt(talker,CHAR_FAME) < iTotalCostFame) return FALSE; + } + addNpcFamilyTax( meindex, talker, maxgold*0.1 ); +/* + if( addNpcFamilyTax( meindex, talker, maxgold*0.4 ) ) + print(" FamilyTaxDone! "); + else + print(" FamilyTaxError!"); +*/ + for(i = 0 ; i < kosuu ; i++){ + itemindex = ITEM_makeItemAndRegist( itemID); + + if(itemindex == -1) return FALSE; + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( ret < 0 || ret >= CheckCharMaxItem(talker) ) { + print( "npc_itemshop.c: additem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + CHAR_sendItemDataOne( talker, ret); + } + CHAR_DelGold( talker, maxgold); + + if(iTotalCostFame > 0){ + CHAR_setInt(talker,CHAR_FAME,CHAR_getInt(talker,CHAR_FAME) - iTotalCostFame); + + char token[256]; + sprintf(token, "ɹ۳:%d", iTotalCostFame / 100); + CHAR_talkToCli( talker, -1, token, CHAR_COLORYELLOW); + + if(CHAR_getInt(talker,CHAR_FMINDEX) != -1 && (strcmp(CHAR_getChar(talker,CHAR_FMNAME),""))){ + int fd = getfdFromCharaIndex(talker); + char buf[256]; + sprintf(buf,"%d",CHAR_getInt(talker,CHAR_FAME)); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(talker,CHAR_FMNAME), + CHAR_getInt(talker,CHAR_FMINDEX), + CHAR_getWorkInt(talker,CHAR_WORKFMINDEXI), + FM_FIX_FAME,buf,"", + CHAR_getWorkInt(talker,CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + + LogFMFameShop(CHAR_getChar(talker,CHAR_FMNAME), + CHAR_getChar(talker,CHAR_CDKEY), + CHAR_getChar(talker,CHAR_NAME), + CHAR_getInt(talker,CHAR_FAME), + iTotalCostFame); + } + } + + //CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + return TRUE; + +} + +//ѡ (,,ȥ) СӴ +void NPC_ItemShop_Menu(int meindex,int talker) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[NPC_UTIL_GETARGSTR_LINEMAX]; + char buff[256]; + int fd = getfdFromCharaIndex( talker); + + //argstrȡ趨ѶϢ: ->buy_rate:1.0|sell_rate:0.2|buy_msg:,,л,kau,buy............. (мķָǶʱ) + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("shop_GetArgStr_Err"); + return; + } + + //tokenΪӴtitle : ķķߵ|ӭ + NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", buff, sizeof( buff)); +#ifdef _VERSION_25 + snprintf(token, sizeof(token),"%s|%s",CHAR_getChar( meindex, CHAR_NAME), buff); +#else + snprintf(token, sizeof(token),"%s|%s|%d",CHAR_getChar(meindex,CHAR_NAME),buff,CHAR_getInt(talker,CHAR_FAME)/100); +#endif + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_ITEMSHOPMENU, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + +} + +void NPC_ItemShop_SellMain(int meindex,int talker,int before) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[NPC_UTIL_GETARGSTR_BUFSIZE]; + int fd = getfdFromCharaIndex( talker); + + +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(talker, CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + + + //ȡnpc趨 + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("shop_GetArgStr_Err"); + return; + } + +#ifdef _ADD_STATUS_2 + sprintf(token,"FAME|%d",CHAR_getInt(talker,CHAR_FAME)/100); + lssproto_S2_send(fd,token); +#endif + + if(before != -1) { + sprintf(token,"1|0"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_ITEMSHOPMAIN + +CHAR_getWorkInt(meindex,NPC_SHOP_WORK_NO), + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_SELL_MSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + }else{ + + char token2[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[256]; + char buff[256]; + + NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", buff, sizeof( buff)); + NPC_Util_GetStrFromStrWithDelim( argstr, "sell_main", buff2, sizeof( buff)); +#ifdef _VERSION_25 + sprintf( token, "1|1|%d|%s|%s|%-72s%d|", CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG, + CHAR_getChar( meindex, CHAR_NAME), buff, buff2, CHAR_getInt(talker,CHAR_FAME)/100); +#else + sprintf( token, "1|1|%d|%s|%s|%s|", CHAR_WINDOWTYPE_WINDOWITEMSHOP_STARTMSG, + CHAR_getChar( meindex, CHAR_NAME), buff, buff2); +#endif + NPC_Util_GetStrFromStrWithDelim( argstr, "stone_msg", buff, sizeof( buff)); + + if(CHAR_getWorkInt(meindex,NPC_SHOP_WORK_EXPRESS) == 1 ) { + NPC_Util_GetStrFromStrWithDelim( argstr, "exrealy_msg", buff2, sizeof(buff2)); + }else{ + NPC_Util_GetStrFromStrWithDelim( argstr, "realy_msg", buff2, sizeof( buff2)); + } + sprintf( token2,"%s|%s|", buff, buff2); + NPC_GetLimtItemList( talker,argstr, token2, -1);//ϸҪĵ + strncat( token, token2, sizeof( token)); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_ITEMSHOPMAIN+ + CHAR_getWorkInt(meindex,NPC_SHOP_WORK_NO), + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_SELL_MSG, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + } +} +int NPC_GetLimtItemList(int talker, char *argstr, char* token2,int sell) +{ + + char token[NPC_UTIL_GETARGSTR_LINEMAX]; + char buff[NPC_UTIL_GETARGSTR_LINEMAX]; + char token3[NPC_UTIL_GETARGSTR_LINEMAX]; + int k = 0 , i = 1 , j = 0; + int imax; + int itemtype = 0; + int itemindex; + int okflg = 0; + char buf[256]; + int flg=0; + int cost; + + if(sell == -1 ){ + i = CHAR_STARTITEMARRAY; + imax = CheckCharMaxItem(talker); + flg = -1; + }else{ + i= sell; + imax= sell + 1; + flg = 1; + } + + for( ; i < imax ; i++ ){ + okflg=0; + itemindex = CHAR_getItemIndex( talker , i ); + + if( ITEM_CHECKINDEX( itemindex) ){ + if( NPC_Util_GetStrFromStrWithDelim( argstr,"LimitItemType", buff, sizeof( buff)) != NULL ){ + k = 1; + while(getStringFromIndexWithDelim(buff , "," , k, token, sizeof(token)) != FALSE ){ +#ifdef _ITEM_TYPETABLE + int cmpmaxitem = sizeof(TypeTable)/sizeof(TypeTable[0]); +#endif + k++; +#ifdef _ITEM_TYPETABLE + for(j = 0 ; j < cmpmaxitem ; j++){ +#else + for(j = 0 ; j < ITEM_CATEGORYNUM+3 ; j++){ +#endif + if(strcmp( TypeTable[ j].arg , token) == 0 ) { + itemtype = TypeTable[ j].type; + if(ITEM_getInt(itemindex,ITEM_TYPE) == itemtype) { + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat( token2, token3, sizeof( token3)); + okflg = 1; + }else if(itemtype == 30){ + if( 8 <= ITEM_getInt(itemindex,ITEM_TYPE) + && (ITEM_getInt(itemindex,ITEM_TYPE) <= 15) ){ + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat(token2,token3,sizeof(token3)); + okflg = 1; + } + }else if(itemtype == 40){ + if(( 0 <= ITEM_getInt(itemindex,ITEM_TYPE) + && (ITEM_getInt(itemindex,ITEM_TYPE) <= 4)) + || (17 <= ITEM_getInt(itemindex,ITEM_TYPE) + && (ITEM_getInt(itemindex,ITEM_TYPE) <= 19))) { + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat(token2,token3,sizeof(token3)); + okflg = 1; + } + }else if(itemtype == 50){ + if( 5 <= ITEM_getInt(itemindex,ITEM_TYPE) + && (ITEM_getInt(itemindex,ITEM_TYPE) <= 7) ){ + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat(token2,token3,sizeof(token3)); + okflg = 1; + } + } + break; + } + } + + if(okflg == 1) break; + } + } + if( (NPC_Util_GetStrFromStrWithDelim( argstr, "LimitItemNo", buff,sizeof( buff))!= NULL) && okflg == 0 ){ + k = 1; + while(getStringFromIndexWithDelim(buff , "," , k, token, sizeof(token)) != FALSE ){ + k++; + if(strstr( token, "-")==NULL && strcmp(token,"") != 0) { + if(ITEM_getInt(itemindex,ITEM_ID) == atoi(token)) { + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat(token2,token3,sizeof(token3)); + okflg=1; + } + }else if (strstr( token, "-") != NULL){ + int start, end; + int work; + + if( getStringFromIndexWithDelim( token, "-", 1, buf, sizeof(buf)) == FALSE ) + return -1; + start = atoi( buf); + if( getStringFromIndexWithDelim( token, "-", 2 ,buf, sizeof(buf)) == FALSE ) + return -1; + end = atoi( buf); + + if(start > end){ + work = start; + start = end; + end = work; + } + + end++; + if( (start <= ITEM_getInt(itemindex,ITEM_ID)) && (ITEM_getInt(itemindex,ITEM_ID) < end) ){ + cost = NPC_GetSellItemList(itemindex,0,argstr,token3,i,sell); + if(cost != -1) return cost; + strncat(token2,token3,sizeof(token3)); + okflg = 1; + } + } + } + } + + if(okflg == 0) { + cost = NPC_GetSellItemList(itemindex, 1, argstr, token3, i, sell); + if(sell != -1) return -1; + strncat( token2, token3, sizeof( token3)); + } + + } + } + return -1; +} + + + +/*---------------------------------------------------------- + + ͷʧ˪P + + *----------------------------------------------------------*/ +int NPC_GetSellItemList(int itemindex,int flg, char *argstr,char *argtoken,int select,int sell) +{ + char buff[256]; + double rate = 0.2; + char buff2[256]; + char buff3[64]; + int k = 1; + int cost = -1; + + if(NPC_Util_GetStrFromStrWithDelim( argstr,"special_item",buff, sizeof( buff)) != NULL){ + if(NPC_Util_GetStrFromStrWithDelim( argstr,"special_rate",buff2, sizeof( buff2)) != NULL ){ + rate = atof(buff2); + }else{ + rate = 1.2; + } + + while(getStringFromIndexWithDelim(buff , "," , k, buff2, sizeof(buff2)) !=FALSE ){ + k++; + if(strstr( buff2, "-") == NULL && strcmp(buff2,"") != 0) { + if(ITEM_getInt(itemindex,ITEM_ID) == atoi(buff2)){ + cost = NPC_SellItemstrsStr( itemindex,0, rate, argtoken,select,sell); + return cost; + } + }else if (strstr( buff2, "-") != NULL){ + int start; + int end; + int work; + getStringFromIndexWithDelim( buff2, "-", 1, buff3, sizeof(buff3)); + start = atoi( buff3); + getStringFromIndexWithDelim( buff2, "-", 2 ,buff3, sizeof(buff3)); + end = atoi( buff3); + + if(start > end){ + work = start; + start = end; + end = work; + } + end++; + if( (start <= ITEM_getInt(itemindex,ITEM_ID)) && (ITEM_getInt(itemindex,ITEM_ID) < end) ){ + cost = NPC_SellItemstrsStr( itemindex,0, rate, argtoken,select,sell); + return cost; + } + } + } + } + if( NPC_Util_GetStrFromStrWithDelim( argstr,"sell_rate",buff, sizeof( buff)) != NULL ){ + rate = atof(buff); + cost = NPC_SellItemstrsStr( itemindex, flg ,rate, argtoken,select,sell); + return cost; + } + + return cost; +} + +int NPC_SellItemstrsStr(int itemindex,int flg,double rate,char *argtoken,int select,int sell) +{ + int cost; + char escapedname[256]; + char name[256]; + char *eff; + + + cost = ITEM_getInt( itemindex, ITEM_COST); + cost = (int)(cost * rate); + + if(sell != -1) return cost; + + strcpy( escapedname, ITEM_getChar( itemindex, ITEM_SECRETNAME)); + makeEscapeString( escapedname, name, sizeof( name)); + eff=ITEM_getChar(itemindex, ITEM_EFFECTSTRING); + makeEscapeString( eff, escapedname, sizeof(escapedname)); + + + + sprintf( argtoken, +#ifdef _ITEM_PILENUMS + "%s|%d|%d|%d|%s|%d|%d|", +#else + "%s|%d|%d|%d|%s|%d|", +#endif + name, flg, cost, + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + escapedname, select +#ifdef _ITEM_PILENUMS + ,ITEM_getInt( itemindex, ITEM_USEPILENUMS) +#endif + ); + + return -1; + +} + +BOOL NPC_SellNewItem(int meindex,int talker,char *data) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256], token2[256]; + int cost, k, select, itemindex; + int MyGold, MaxGold, sellnum=1; + + MaxGold = CHAR_getMaxHaveGold( talker); + MyGold = CHAR_getInt( talker, CHAR_GOLD); + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("GetArgStrErr"); + return FALSE; + } + getStringFromIndexWithDelim(data , "|" ,1, token, sizeof( token)); + select = atoi(token); +#ifdef _ITEM_PILENUMS + getStringFromIndexWithDelim(data , "|" ,2, token, sizeof( token)); + sellnum = atoi(token); +#endif + + if( select < CHAR_STARTITEMARRAY || select >= CheckCharMaxItem(talker) ) return FALSE; + k = select; + itemindex = CHAR_getItemIndex( talker , k); + + cost = NPC_GetLimtItemList( talker,argstr, token2,select); + if( cost == -1 || (cost*sellnum)+MyGold >= MaxGold || !ITEM_CHECKINDEX( itemindex) ){ + int fd = getfdFromCharaIndex( talker); + sprintf(token,"\n\nѽ!Բ" "\n\nԲ ! ɲѡһأ" ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_LIMIT, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return FALSE; + } +#ifdef _ITEM_PILENUMS + if( NPC_DelItem( talker, k, sellnum) == FALSE ) return FALSE; +#else + { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "Sell()", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + } + CHAR_DelItem( talker, k); +#endif + CHAR_AddGold( talker, cost*sellnum); + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + return TRUE; +} + + + +void NPC_LimitItemShop(int meindex,int talker,int select) +{ + + int fd = getfdFromCharaIndex( talker); + char token[NPC_UTIL_GETARGSTR_LINEMAX]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("shop_GetArgStr_Err"); + return; + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "sellonly_msg", buf, sizeof( buf))!=NULL){ + sprintf(token,"\n\n%s", buf); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_LIMIT, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + }else{ + CHAR_talkToCli( talker, meindex, "רŵꡣ",CHAR_COLORWHITE); + } + return; +} + +void NPC_ExpressmanCheck(int meindex,int talker) +{ + int fd = getfdFromCharaIndex( talker); + char token[1024]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("shop_GetArgStr_Err"); + return; + } + NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", buf, sizeof( buf)); + sprintf(token,"4\n%s\n\n%s" + "\n\n " + "\n\n " + ,CHAR_getChar(meindex,CHAR_NAME),buf); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_WINDOWITEMSHOP_EXPRESS, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + return; + + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_janken.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_janken.c new file mode 100644 index 0000000..a90bf35 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_janken.c @@ -0,0 +1,524 @@ +#include "version.h" +#include +#include "common.h" +#include "char_base.h" +#include "npc_janken.h" +#include "npcutil.h" +#include "char.h" +#include "lssproto_serv.h" +#include "buf.h" +#include "function.h" +#include "readmap.h" +#include "object.h" +#include "log.h" +#include "npc_exchangeman.h" +/* + *Ԫ + */ +static void NPC_Janken_selectWindow( int meindex, int talker, int num); +void NPC_JnakenJudge(int meindex,int talker,int sel); +BOOL NPC_JankenEntryItemCheck(int talker,char *buf); +BOOL NPC_JankenEntryItemDel(int talker,char *buf); +void NPC_WarpPointGet(int meindex,int talker,int *fl,int *x,int *y,int judge); + +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +/********************************* +* +*********************************/ +BOOL NPC_JankenInit( int meindex ) +{ + + //ë + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEJANKEN ); + + return TRUE; + +} + + +BOOL NPC_JankenItemGet(int meindex,int talker, char *wl) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_janken ItemGet: GetArgStrErr"); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr, wl, buf, sizeof( buf) ) !=NULL){ + NPC_EventAddItem( meindex, talker, buf); + } + return TRUE; +} + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_JankenTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + NPC_Janken_selectWindow(meindex, talkerindex, 0); + + + + +} + + + +/****************************** + * ľľ + ******************************/ +static void NPC_Janken_selectWindow( int meindex, int talker, int num) +{ + + char token[1024]; + char buf[32]; + int fd = getfdFromCharaIndex( talker); + int buttontype=0; + int windowtype=0; + int windowno=0; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + + /*--̼⻥мƥƱɬ--*/ + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_janken Init: GetArgStrErr"); + return ; + } + + + switch( num) + { + case 0: + + /*-- ⻥ ľɾ޷¡ --*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr, "MainMsg", token, sizeof( token)) == NULL) + { + print("Janken:MainMsg:%s", CHAR_getChar( meindex, CHAR_NAME)); + return ; + } + + /*-- --*/ + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_JANKEN_START; + break; + + + case 1: + + //ʧ ة + if(NPC_Util_GetStrFromStrWithDelim( argstr, "EntryItem", buf, sizeof( buf))!= NULL) { + + if(NPC_JankenEntryItemCheck(talker,buf) == FALSE) + { + NPC_Janken_selectWindow(meindex, talker, 3); + } + + //޼üʧ ةë + if(NPC_JankenEntryItemDel(talker,buf) == FALSE){ + print("ԪERR:ʧ ةƱ"); + } + } + + + /*-- --*/ + sprintf(token," ʯͷ\n" + "\n\n ʯͷ " + "\n\n " + "\n\n " + ); + + buttontype=WINDOW_BUTTONTYPE_NONE; + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno=CHAR_WINDOWTYPE_JANKEN_MAIN; + break; + + case 2: + /*--ؤг --*/ + //sprintf(token," ؤгƥ\n" + sprintf(token," ƽ\n" + "\n\n ʯͷ " + "\n\n " + "\n\n " + ); + + buttontype=WINDOW_BUTTONTYPE_NONE; + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno=CHAR_WINDOWTYPE_JANKEN_MAIN; + break; + + case 3: + /*-- ⻥ ľɾ޷¡ --*/ + NPC_Util_GetStrFromStrWithDelim( argstr, "NoItem", token, sizeof( token)); + + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_JANKEN_END; + + break; + + } + + +// makeEscapeString( token, escapedname, sizeof(escapedname)); + /*-ƥ˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + + +} + + + +/********************************* +* ū帲 +*********************************/ +void NPC_JankenWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + switch( seqno){ + case CHAR_WINDOWTYPE_JANKEN_START: + + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_Janken_selectWindow(meindex, talkerindex, 1); + } + break; + + case CHAR_WINDOWTYPE_JANKEN_MAIN: + if (atoi(data) >= 3){ + NPC_JnakenJudge(meindex,talkerindex,atoi(data) ); + } + break; + } +} + + +/* + *Ҽ + */ +void NPC_JnakenJudge(int meindex,int talker,int sel) +{ + int player=-1; + int jankenman; + char j_char[3][8]={" ʯͷ "," "," "}; + char token[1024]; + int shouhai = 0; + int fd = getfdFromCharaIndex( talker); + int fl=0,x=0,y=0; + + + if(sel == 3) player = 0; // + if(sel == 5) player = 1; //ƽ + if(sel == 7) player = 2; //ɡ + + jankenman = rand()%3; + + switch(jankenman){ + case 0: + if(player == 2){ + shouhai = 1; + }else if(player == 1){ + shouhai = 2; + } + break; + + case 1: + if(player == 0){ + shouhai = 1; + }else if(player == 2){ + shouhai = 2; + } + break; + + case 2: + if(player == 1){ + shouhai = 1; + }else if(player == 0){ + shouhai = 2; + } + break; + } + + if(shouhai == 1){ + //Change add Ҳʤ˸ĵ + NPC_JankenItemGet( meindex, talker, "WinItem" ); + + NPC_WarpPointGet(meindex, talker, &fl, &x, &y, 0); + + snprintf( token, sizeof( token ) , + " \n\n" + " %16s %-16s\n" + " [%s] VS [%s]\n\n\n" + " %-16s ʤ", + CHAR_getChar(meindex,CHAR_NAME),CHAR_getChar(talker,CHAR_NAME), + j_char[jankenman],j_char[player], + CHAR_getChar(talker,CHAR_NAME) + ); + +// CHAR_talkToCli( talker , -1 ,token , CHAR_COLORCYAN ); + + // + CHAR_warpToSpecificPoint(talker, fl, x, y); + + // 巴٣ʧë£ + CHAR_sendWatchEvent( CHAR_getWorkInt( talker, CHAR_WORKOBJINDEX), CHAR_ACTPLEASURE,NULL,0,TRUE); + CHAR_setWorkInt( talker, CHAR_WORKACTION, CHAR_ACTPLEASURE); + + }else if(shouhai == 2){ + + //Change add Ҳ˸ĵ + NPC_JankenItemGet( meindex, talker, "LoseItem" ); + + NPC_WarpPointGet(meindex, talker, &fl, &x, &y, 1); + snprintf( token, sizeof( token ) , + " \n\n" + " %16s %-16s\n" + " [%s] VS [%s]\n\n\n" + " %-16s ", + CHAR_getChar(meindex,CHAR_NAME),CHAR_getChar(talker,CHAR_NAME), + j_char[jankenman],j_char[player], + CHAR_getChar(talker,CHAR_NAME) + ); +// CHAR_talkToCli( talker , -1 ,token , CHAR_COLORCYAN ); + + // + CHAR_warpToSpecificPoint(talker, fl, x, y); + + // 巴 Уʧë + CHAR_sendWatchEvent( CHAR_getWorkInt( talker, CHAR_WORKOBJINDEX), CHAR_ACTSAD,NULL,0,TRUE); + CHAR_setWorkInt( talker, CHAR_WORKACTION, CHAR_ACTSAD); + + + }else{ + //ؤг + NPC_Janken_selectWindow( meindex, talker, 2); + return; + } + + //˪ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_JANKEN_END, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + + +} + + +/* + *ëGET£ + */ +void NPC_WarpPointGet(int meindex,int talker,int *fl,int *x,int *y,int judge) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char *strbuf[2] = {"WinWarp","LoseWarp"}; + char buf[64]; + char buf2[32]; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_janken Init: GetArgStrErr"); + return ; + } + + + /*--ë --*/ + NPC_Util_GetStrFromStrWithDelim( argstr, strbuf[judge], buf, sizeof( buf)); + getStringFromIndexWithDelim(buf,",",1,buf2,sizeof(buf2)); + *fl=atoi(buf2); + getStringFromIndexWithDelim(buf,",",2,buf2,sizeof(buf2)); + *x=atoi(buf2); + getStringFromIndexWithDelim(buf,",",3,buf2,sizeof(buf2)); + *y=atoi(buf2); + + +} + +/* + *--ʧ ةͷë浤 + */ +BOOL NPC_JankenEntryItemCheck(int talker,char *buf) +{ + + char buf2[512]; + char buf3[256]; + int id=0; + BOOL flg = FALSE; + int i; + int itemindex; + int itemno; + int kosuu; + int cnt=0; + int k=1; + + while(getStringFromIndexWithDelim(buf , "," , k, buf2, sizeof(buf2)) + !=FALSE ) + { + flg = FALSE; + k++; + + if(strstr(buf2,"*") != NULL){ + cnt = 0; + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemno = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + for( i=0 ; i < CheckCharMaxItem(talker);i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id = ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno == id){ + cnt++; + if(cnt == kosuu){ + flg = TRUE; + break; + } + } + } + } + if(flg == FALSE) + { + return FALSE; + } + }else{ + itemno = atoi(buf2); +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( i=0 ; i < itemMax;i++ ){ +#else + for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id = ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno == id){ + flg = TRUE; + break; + } + } + } + + if(flg == FALSE) + { + return FALSE; + } + } + } + + return TRUE; + +} + +BOOL NPC_JankenEntryItemDel(int talker,char *buf) +{ + + int i = 1, j = 1,k = 1; + char buff3[128]; + char buf2[32]; + int itemindex; + + while(getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + if(strstr(buff3, "*") !=NULL){ + int itemno; + int kosuu; + int id; + int cnt=0; + getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); + itemno = atoi(buf2); + getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); + kosuu = atoi(buf2); + for( i =0 ; i < CheckCharMaxItem(talker) ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id=ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno==id){ + cnt++; + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "QuizDelItem(->)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_DelItem( talker, i); + if(cnt == kosuu){ + break; + } + } + } + } + }else{ +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( j = 0 ; j < itemMax ; j++){ +#else + for( j = 0; j < CHAR_MAXITEMHAVE; j ++ ) { +#endif + itemindex = CHAR_getItemIndex( talker ,j); + + if( ITEM_CHECKINDEX(itemindex) ){ + if( atoi( buff3) == ITEM_getInt(itemindex,ITEM_ID)){ + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "QuizDelItem(->)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_DelItem( talker, j); + } + } + } + } + } + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_luckyman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_luckyman.c new file mode 100644 index 0000000..fd52f20 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_luckyman.c @@ -0,0 +1,239 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_luckyman.h" + + +static void NPC_LuckyMan_selectWindow( int meindex, int toindex, int num,char *msg); +void NPC_LuckyManAllHeal( int talker,int mode ); +BOOL NPC_LuckyManLevelCheck(int meindex,int talker); +void NPC_LuckyDisp(int meindex,int talker); +BOOL NPC_LuckyCostCheck(int meindex,int talker,int cost); +int NPC_GetMoney(int meindex,int talker,char *buf); + + + +/********************************* +* +*********************************/ +BOOL NPC_LuckyManInit( int meindex ) +{ + + /*--ƽҷ¼ëɬ--**/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPELUCKYMAN ); + + return TRUE; +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_LuckyManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + char token[512]; + int cost; + + + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2) == FALSE) { + /* */ + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) { + print("NPC_ExChange.c TypeCheck: GetArgStrErr\n"); + print("NPCName=%s\n", CHAR_getChar( meindex, CHAR_NAME)); + return; + } + + + NPC_Util_GetStrFromStrWithDelim( argstr,"Stone", buf, sizeof( buf)); + cost = NPC_GetMoney( meindex, talkerindex, buf); + + NPC_Util_GetStrFromStrWithDelim( argstr,"main_msg", buf, sizeof( buf)); + sprintf( token, buf, cost); + + NPC_LuckyMan_selectWindow( meindex, talkerindex, 2, token); + +} + + +static void NPC_LuckyMan_selectWindow( int meindex, int toindex, int num,char *msg) +{ + + int fd = getfdFromCharaIndex( toindex); + char token[1024]; + int buttontype = 0,windowtype = 0,windowno = 0; + + + switch( num){ + case 1: + sprintf(token ,"յơ" + "\n\n%s",msg + ); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_START; + break; + + case 2: + sprintf(token, "ռʦ" + "\n\n%s",msg + ); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_START; + break; + + case 3: + sprintf(token, "ռʦ" + "\n\n%s",msg + ); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_START; + break; + } + + + /*--˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + +} + + +/*----------------------------------------- +ͷʧ߯Ȼݱ̫ľ£ +-------------------------------------------*/ +void NPC_LuckyManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + int money; + int level; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)) == NULL) { + print("NPC_ExChange.c TypeCheck: GetArgStrErr\n"); + print("NPCName=%s\n", CHAR_getChar(meindex,CHAR_NAME)); + return; + } + + switch( seqno){ + case CHAR_WINDOWTYPE_WINDOWPETSHOP_START: + if(select == WINDOW_BUTTONTYPE_YES) { + NPC_Util_GetStrFromStrWithDelim( argstr, "Stone", buf,sizeof(buf)); + + if(strstr(buf,"LV") != NULL) { + char buff2[32]; + level = CHAR_getInt( talkerindex, CHAR_LV); + getStringFromIndexWithDelim( buf, "*", 2, buff2,sizeof( buff2)); + money = level * atoi( buff2); + + if(NPC_LuckyCostCheck(meindex,talkerindex,money) == FALSE) { + NPC_Util_GetStrFromStrWithDelim( argstr,"NoMoney", buf, sizeof( buf)); + NPC_LuckyMan_selectWindow( meindex, talkerindex, 3, buf); + return; + } + }else{ + money = atoi( buf); + if(NPC_LuckyCostCheck(meindex,talkerindex ,money) == FALSE) { + NPC_Util_GetStrFromStrWithDelim( argstr,"NoMoney", buf,sizeof( buf)); + NPC_LuckyMan_selectWindow( meindex, talkerindex, 3, buf); + return; + } + } + + CHAR_DelGold( talkerindex, money ); + + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + NPC_LuckyDisp( meindex, talkerindex); + + }else if(select == WINDOW_BUTTONTYPE_OK) { + + } + break; + } +} + + + +void NPC_LuckyDisp(int meindex,int talker) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[16]; + char token[1024]; + char buf2[512]; + int i = 1; + + /*--ɬð̻ë --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) { + print("NPC_Savepoint.c Init: GetArgStrErr"); + return; + } + + /*--ëέ--*/ + sprintf( buf, "luck%d", CHAR_getInt( talker, CHAR_LUCK)); + NPC_Util_GetStrFromStrWithDelim( argstr, buf, buf2, sizeof( buf2)); + + while(getStringFromIndexWithDelim( buf2, ",", i, token, sizeof( token)) + != FALSE) + { + i++; + } + i--; + i = rand()%i + 1; + + /*--¼ĸةƥë --*/ + getStringFromIndexWithDelim( buf2,",", i, token, sizeof( token)); + NPC_LuckyMan_selectWindow( meindex, talker, 1, token); +} + + +/*---ż-**/ +BOOL NPC_LuckyCostCheck(int meindex,int talker,int cost) +{ + /*--ػɬ---*/ + /*---ŻԻ¾---*/ + if(CHAR_getInt( talker, CHAR_GOLD) < cost) { + return FALSE; + } + return TRUE; + +} + + +int NPC_GetMoney(int meindex,int talker,char *buf) +{ + int level; + int money; + + if(strstr(buf,"LV") != NULL) { + char buff2[32]; + level = CHAR_getInt(talker,CHAR_LV); + getStringFromIndexWithDelim( buf, "*" ,2, buff2,sizeof( buff2)); + money = level * atoi( buff2); + }else{ + money = atoi( buf); + } + return money; + +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_magiccard.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_magiccard.c new file mode 100644 index 0000000..943d082 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_magiccard.c @@ -0,0 +1,1807 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "handletime.h" +#include "readmap.h" +#include "log.h" +#include "enemy.h" +#include "npc_eventaction.h" +#include "pet.h" +#include "battle.h" +#include "chatmagic.h" + +#ifdef _NPC_MAGICCARD +#include "npc_magiccard.h" + +void NPC_Magiccard_selectWindow(int meindex,int toindex,int num,int select); +int NPC_magiccard_checkplace( int meindex , int toindex , char *token ); +void NPC_magiccard_gameinit( int meindex , int bkid ); +void NPC_magiccard_selectcard( int meindex , int bkid ); +void NPC_magiccard_checkselect( int meindex , int toindex ,int choise); +void NPC_magiccard_waitselect( int meindex , int bkid ); +void NPC_magiccard_aiselect( int meindex , int bkid ); +//void NPC_magiccard_showcard( int meindex , int bkid ); +//void NPC_magiccard_summonpet(int meindex , int bkid , int charindex , int mode ); +//void NPC_magiccard_fightcard( int meindex , int bkid , int playtotal); +//void NPC_magiccard_damage( int meindex , int bkid , int charindex , int player , int playtotal); +void NPC_magiccard_out( int meindex , int bkid , int player ); +void NPC_magiccard_turnover( int meindex , int bkid ); +void NPC_magiccard_gameover( int meindex , int bkid ); +void NPC_magiccard_resetbanker( int meindex , int bkid ); +int NPC_magiccard_checkExist( int meindex , int bkid , int player ); +//void NPC_magiccard_action( int meindex , int charindex , int bkid , int player ); +void NPC_magiccard_selectback( int meindex , int toindex ); +void NPC_magiccard_action2( int meindex , int charindex , int user , int card , int action ); +void NPC_magiccard_checkdamage( int meindex , int bkid ); +void NPC_magiccard_showdamage( int meindex , int charindex , int position , int damage ); +void NPC_magiccard_specialcard( int meindex , int bkid ); +int NPC_magiccard_sort( const void *card1, const void *card2 ); + +enum { + NPC_WORK_BANKER = CHAR_NPCWORKINT1, // ¼һׯ + NPC_WORK_GIVEGOLD = CHAR_NPCWORKINT2, // ¼սǷǸ֤ + //NPC_WORK_ABANDON = CHAR_NPCWORKINT2, // սǷ + //NPC_WORK_TURN = CHAR_NPCWORKINT3, // ¼غ + NPC_WORK_HAND = CHAR_NPCWORKINT4, // ¼սϵ + NPC_WORK_SELECT = CHAR_NPCWORKINT5, // ¼սѡڼ + NPC_WORK_ACTION = CHAR_NPCWORKINT6, // ¼սѡ񹥻Ƿ + NPC_WORK_HISTORY = CHAR_NPCWORKINT7, // ¼ս߳ + NPC_WORK_DAMAGE = CHAR_NPCWORKINT8, // ¼սܵ˺ + //NPC_WORK_LOCATION = CHAR_NPCWORKINT9, // ¼սߵλ + //NPC_WORK_ = CHAR_NPCWORKINT10, // ¼ׯҵindex +}; + +enum { + ATTACK=1, + DEFENCE, + MAGIC, +}; + +enum { + START, + RULES, + INGAME, + SCORE, + END, +}; + + +#define LOOPTIME 100 // 0.1 +#define SHOWCARDLOOPTIME 800//1000 //1 +#define FIGHTLOOPTIME 800//1000//2000 +#define TURNOVERTIME 1300//1500//4000 +#define GAMEOVERTIME 4800//5000 + +#define MAXHP 50 +#define MAXGUY 6 +#define BANKERID 6 + +#define SHIFTBASE 1 //ƵĻ׼ֵ +//#define MAGIC_MOVE_SCREEN_XY (18 << 16) | 10 // ӫĻҪƶXY +//#define MAGIC_MOVE_SCREEN_XY (14 << 16) | 13 // ӫĻҪƶXY + +struct BANKER banker[BANKERTOTAL]; + +int Bettotal[BANKERTOTAL]; +int Wintotal[BANKERTOTAL]; +int tickettotal[BANKERTOTAL]; + +//λ +typedef struct Posstruct +{ + int humanX; + int humanY; + int petX; + int petY; + int npcX; + int npcY; + int direct; +}Position; +static Position Positiontable[]= +{ + {19,12,17,12,15,13,6}, //0 ս + {18,17,16,15,15,14,7}, //1 ս + {13,18,13,16,14,14,0}, //2 ս + { 9,14,11,14,13,13,2}, //3 ս + {10, 9,12,11,13,12,3}, //4 ս + {15, 8,15,10,14,12,4}, //5 ս + {15,12,14,13,14,13,5}, //6 ׯ + {24,18, 0, 0,0,0,6}, //7 + +/* + {23, 9,21, 9,6}, //0 ս + {22,14,20,12,7}, //1 ս + {17,15,17,13,0}, //2 ս + {13,11,15,11,2}, //3 ս + {14, 6,16, 8,3}, //4 ս + {19, 5,19, 7,4}, //5 ս + {18,18,18,10,5}, //6 ׯ + {15,13, 0, 0,6}, //7 +*/ +}; + +typedef struct st_cardbox +{ + BOOL use; + int cardindex; +}CardBoxType; +static CardBoxType Cardbox[BANKERTOTAL*7][30]; + +//ħ +typedef struct Cardstruct +{ + STRING64 name; + int petid; + int attack; + int defence; + int effect; + void* functionPointer; +}Cardfunction; +static Cardfunction Cardfunctiontable[]= +{ + {{"1: Ա 13 1"} ,2565 ,13 , 1 , 101437,NULL}, + {{"2: ޿ 13 1"} ,0 ,13 , 1 , 101962,NULL}, + {{"3: 13 1"} ,2571 ,13 , 1 , 101616,NULL}, + {{"4: 1 13"} ,2563 , 1 ,13 , 101760,NULL}, + {{"5: ŵ 1 13"} ,0 , 1 ,13 , 101946,NULL}, + {{"6: ŷ 1 13"} ,0 , 1 ,13 , 101485,NULL}, + {{"7: 8 8"} ,0 , 8 , 8 , 101180,NULL}, + {{"8: ¶ 8 8"} ,0 , 8 , 8 , 100872,NULL}, + {{"9: ŵ 8 7"} ,0 , 8 , 7 , 101952,NULL}, + {{"10: ַ 8 6"} ,0 , 8 , 6 , 101875,NULL}, + {{"11: ˹ 7 7"} ,0 , 7 , 7 , 101914,NULL}, + {{"12: ŵ˹ 7 7"} ,2456 , 7 , 7 , 101819,NULL}, + {{"13: ׵˹ 7 8"} ,0 , 7 , 8 , 101501,NULL}, + {{"14: 7 6"} ,0 , 7 , 6 , 101922,NULL}, + {{"15: ˹ 6 6"} ,0 , 6 , 6 , 101464,NULL}, + {{"16: 6 6"} ,0 , 6 , 6 , 101928,NULL}, + {{"17: ˹ 6 8"} ,0 , 6 , 8 , 101446,NULL}, + {{"18: 6 7"} ,0 , 6 , 7 , 100390,NULL}, // + {{"19: ˹ŵ 3 3"} ,0 , 3 , 3 , 101954,NULL}, + {{"20: ˾ 3 3"} ,0 , 3 , 3 , 101957,NULL}, + {{"21: ʷ 3 3"} ,0 , 3 , 3 , 101556,NULL}, + {{"22: ˹ 3 2"} ,0 , 3 , 2 , 101933,NULL}, + {{"23: ɿɶ 2 3"} ,2570 , 2 , 3 , 100898,NULL}, + {{"24: 2 2"} ,0 , 2 , 2 , 101870,NULL}, + {{"25: 2 2"} ,0 , 2 , 2 , 101918,NULL}, + {{"ħ1: þԷĹȥ"} ,2604 , 0 , 0 , 101652,NULL}, + {{"ħ2: ӰܵԷκι"} ,2605 , 0 , 0 , 101695,NULL}, + {{"ħ3: ӡԷͣһغϡ"} ,2606 , 0 , 0 , 101120,NULL}, + {{"ħ4: ظHP->Ѫ50%"} ,2607 , 0 , 0 , 101828,NULL}, + {{"ħ5: 20"} ,2608 , 20 , 0 , 101628,NULL}, + +}; + +BOOL NPC_Magiccard_Init( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + int j,k; + + memset( banker,0,sizeof(banker)); + for(j=0;j= 0 ){ + sprintf( buf2,"%s%d", "page_num", select); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT, select+1); + }else{ + sprintf( buf2,"%s%d", "page_num", pagenum ); + pagenum+=1; + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT, pagenum); + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, buf2, token, sizeof( token) ) == NULL ) { + print("\n error: not found token:%s", token); + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANT,0); + return; + } + + sprintf( buf2,"%s%d", "page_num", CHAR_getWorkInt( toindex , CHAR_WORKSHOPRELEVANT)); + if( NPC_Util_GetStrFromStrWithDelim( argstr, buf2, buf1, sizeof( buf1) ) == NULL ) { + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = CHAR_WINDOWTYPE_MAGIC_NORMAL; + }else { + buttontype = WINDOW_BUTTONTYPE_NEXT; + windowno = CHAR_WINDOWTYPE_MAGIC_RULES; + } + break; + case INGAME: + //warpսߵսλ ʼ + if( NPC_magiccard_checkplace( meindex , toindex , token ) == TRUE ){ //ûпλ + return; + }else{ + //ܲμ + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = CHAR_WINDOWTYPE_MAGIC_NORMAL; + } + break; + case SCORE: + { + int G_num = CHAR_getInt( toindex, CHAR_GAMBLENUM ); + + if( G_num < 0 ) G_num = 0; + sprintf( token,"ֳΪ%d", G_num ); + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = CHAR_WINDOWTYPE_MAGIC_NORMAL; + } + break; + case END: + if( NPC_Util_GetStrFromStrWithDelim( argstr, "end_msg", token, sizeof( token) ) == NULL ){ + print("\n read arg err"); + } + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = CHAR_WINDOWTYPE_MAGIC_NORMAL; + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_Magiccard_WindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + int pagenum,datanum; + + switch(seqno) + { + case CHAR_WINDOWTYPE_MAGIC_START: + pagenum = atoi( data ); + if( pagenum == 4 ){ // 뿪 + NPC_Magiccard_selectWindow( meindex, talkerindex, END , -1 ); + }else { + if( pagenum == 3 ){ // ˻ + NPC_Magiccard_selectWindow( meindex, talkerindex, SCORE , -1 ); + }else if( pagenum == 2 ){ // μϷ + NPC_Magiccard_selectWindow( meindex, talkerindex, INGAME , -1 ); + }else{ // Ϸ + NPC_Magiccard_selectWindow( meindex, talkerindex, RULES, 1 ); + } + } + break; + case CHAR_WINDOWTYPE_MAGIC_RULES: + NPC_Magiccard_selectWindow( meindex, talkerindex, RULES, -1 ); + break; + case CHAR_WINDOWTYPE_MAGIC_NORMAL: + break; + case CHAR_WINDOWTYPE_MAGIC_SELECT: + datanum = atoi(data); + if( CHAR_getWorkInt( talkerindex , NPC_WORK_SELECT ) == -1 ) { + NPC_magiccard_checkselect( meindex , talkerindex ,datanum ); + }else{ + if( select == WINDOW_BUTTONTYPE_OK ){ + CHAR_setWorkInt( talkerindex , NPC_WORK_ACTION , MAGIC ); + }else if( select == WINDOW_BUTTONTYPE_CANCEL ){ + CHAR_setWorkInt( talkerindex , NPC_WORK_SELECT , -1 ); + NPC_magiccard_selectback( meindex , talkerindex ); + }else{ + if(datanum == 2 ) + CHAR_setWorkInt( talkerindex , NPC_WORK_ACTION , ATTACK ); + else if(datanum == 4) + CHAR_setWorkInt( talkerindex , NPC_WORK_ACTION , DEFENCE ); + } + } + break; + } +} + +void NPC_Magiccard_Loop( int meindex ) //ׯԼLOOP +{ + int j,playertotal,bkid; + char buf[256]; + + if( !CHAR_CHECKINDEX( meindex) ) return; + bkid = CHAR_getInt( meindex, CHAR_LV ); + + playertotal = 0; + for( j=0 ; j < MAXGUY ; j++){ + if( NPC_magiccard_checkExist( meindex , bkid , j ) != -1 ) + playertotal++; + } + if( playertotal == 0 ) NPC_magiccard_resetbanker( meindex , bkid ); //ׯѾûս + else banker[bkid].playertotal = playertotal ; + + switch( banker[bkid].state ) //ׯ + { + case 0: //ȴս + if( banker[bkid].waittime < NowTime.tv_sec ){ + NPC_magiccard_gameinit( meindex , bkid); + }else{ + if((long)banker[bkid].waittime - NowTime.tv_sec != banker[bkid].turntime ){ + banker[bkid].turntime = (long)banker[bkid].waittime - NowTime.tv_sec; + if( banker[bkid].turntime < 6 ){ + sprintf( buf ,"Ϸڡ %d ʼ", banker[bkid].turntime ); + showString( meindex, buf , 0); + } + } + } + break; + case 1: //Ҫ + NPC_magiccard_selectcard( meindex , bkid); + break; + case 2: //ȴ + if( (long)banker[bkid].turntime - NowTime.tv_sec != banker[bkid].waittime ){ + banker[bkid].waittime = (long)banker[bkid].turntime - NowTime.tv_sec; + if(banker[bkid].waittime < 4 && banker[bkid].waittime >= 0 ){ + sprintf( buf ,"ʱʣ%d", banker[bkid].waittime ); + showString( meindex, buf , 0); + } + } + NPC_magiccard_waitselect( meindex , bkid); + break; + case 3: //˺㶯 + NPC_magiccard_checkdamage( meindex,bkid); + break; + case 4: // + NPC_magiccard_specialcard( meindex , bkid); + break; + case 5: //غϽ + NPC_magiccard_turnover( meindex , bkid); + break; + case 9: //Ӯ + NPC_magiccard_gameover( meindex , bkid); + break; + default: + break; + } +} + +int NPC_magiccard_checkplace( int meindex , int toindex , char *token ) +{ + int i,offsetx,offsety; + unsigned int movescreenXY=0; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + OBJECT object; + int bossindex,objindex; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return FALSE; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE ) + { + strcpy(token,"вܲμ!!!"); + return FALSE; + } + + //жûʸ + if( CHAR_getInt( toindex , CHAR_GAMBLENUM) < 6 && CHAR_getInt( toindex , CHAR_GOLD) < 15000 ){ + strcpy(token,"û㹻Ǯ֤ƱรܱǸܲμ!!!"); + return FALSE; + }else if( CHAR_getInt( toindex , CHAR_GOLD) < 5000 ){ + strcpy(token,"û㹻ʯҸƱรܱǸܲμ!!!"); + return FALSE; + } + + i = CHAR_getInt( meindex, CHAR_LV ); + if( banker[i].state > 0 || banker[i].playertotal >= MAXGUY ){ //continue; //˻Ϸ + strcpy(token,"Ѿ˻ǽУȺһлл"); + return FALSE; + } + + if( banker[i].playertotal == 0 ){ //һλս + banker[i].waittime = NowTime.tv_sec + 15 ; //30 + banker[i].state = 0 ; //ȴloop + }else + banker[i].waittime = NowTime.tv_sec + 10 ; //ֻҪս߽ټ10 + + sprintf( banker[i].cdkey[banker[i].playertotal] , "%s" , CHAR_getChar( toindex , CHAR_CDKEY )); + sprintf( banker[i].name[banker[i].playertotal] , "%s" , CHAR_getChar( toindex , CHAR_NAME )); + + if(CHAR_getInt( toindex , CHAR_GAMBLENUM) < 6){ + CHAR_setInt( toindex , CHAR_GOLD, CHAR_getInt( toindex , CHAR_GOLD)-15000 ); + CHAR_setWorkInt( toindex , NPC_WORK_GIVEGOLD , 1 ); + sprintf( buf,"ѽɽƱ5000Ӻͱ֤10000" ); + CHAR_talkToCli( toindex , -1 , buf, CHAR_COLORYELLOW); + }else{ + CHAR_setInt( toindex , CHAR_GOLD, CHAR_getInt( toindex , CHAR_GOLD)-5000 ); + CHAR_setInt( toindex , CHAR_GAMBLENUM, CHAR_getInt( toindex , CHAR_GAMBLENUM) - 6 ); + CHAR_setWorkInt( toindex , NPC_WORK_GIVEGOLD , 0 ); + sprintf( buf,"ѽɽƱ5000" ); + CHAR_talkToCli( toindex , -1 , buf, CHAR_COLORYELLOW); + } + + Bettotal[i] += 6; + tickettotal[i]++; + + CHAR_setInt( toindex , CHAR_DIR , Positiontable[banker[i].playertotal].direct ); + CHAR_setWorkInt( toindex , NPC_WORK_BANKER , i ); + //¼ȷǷ;뿪 + CHAR_setWorkInt(toindex, CHAR_WORK_TEMP_FLOOR, CHAR_getInt(meindex, CHAR_FLOOR)); + + //sprintf( buf ,"¼ĵͼΪ%d", CHAR_getWorkInt(toindex, CHAR_WORK_TEMP_FLOOR )); + //showString( meindex, buf , 0); + + CHAR_warpToSpecificPoint( toindex, CHAR_getInt( meindex, CHAR_FLOOR), + Positiontable[banker[i].playertotal].humanX + offsetx , + Positiontable[banker[i].playertotal].humanY + offsety ); + //ƶսߵӽ + movescreenXY = ((Positiontable[banker[i].playertotal].humanX + offsetx) << 16) | ( Positiontable[banker[i].playertotal].humanY + offsety) ; + lssproto_MoveScreen_send(getfdFromCharaIndex(toindex), TRUE, movescreenXY); + banker[i].playertotal += 1; //һս + + //׶ + object = MAP_getTopObj(CHAR_getInt(meindex, CHAR_FLOOR), Positiontable[BANKERID].humanX + offsetx, Positiontable[BANKERID].humanY + offsety ); + if( object ){ + objindex = GET_OBJINDEX( object); + bossindex = OBJECT_getIndex(objindex); + if( banker[i].playertotal < 3 ) + CHAR_CHAT_DEBUG_metamo( bossindex , "101813" ); + else if( banker[i].playertotal < 5 ) + CHAR_CHAT_DEBUG_metamo( bossindex , "101814" ); + else + CHAR_CHAT_DEBUG_metamo( bossindex , "101815" ); + } + + return TRUE; +} + +void NPC_magiccard_gameinit( int meindex , int bkid ) +{ + int i,j=0,charindex,k; + unsigned int card; + char buf[256]; + unsigned int movescreenXY=0; + int offsetx,offsety; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + BOOL flag = FALSE; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return ; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + banker[bkid].turn = 1; + banker[bkid].hand = 0; + banker[bkid].history = 0; + banker[bkid].turntime = NowTime.tv_sec + 20 ; + banker[bkid].process = 0; + sprintf( buf,"һغϿʼ ս" ); + showString( meindex, buf , 0); + + //ׯҵ + while(j<5){ + if( tickettotal[bkid] > 5000 && flag == FALSE ){ + i = rand()%100; + if( i > 50 ) k = 25 + rand()%5; + else if( i > 20 ) k = rand()%3; + else k = 3 + rand()%3; + flag = TRUE; + }else{ + k = rand()%(30-j); + if( Cardbox[6+7*bkid][k].cardindex == 28 && flag == FALSE && rand()%100 > 50){ //ֻ + flag = TRUE; + continue; + } + } + Cardbox[6+7*bkid][k].use = 1; + card = SHIFTBASE << Cardbox[6+7*bkid][k].cardindex ; + banker[bkid].hand |= card; + qsort( &Cardbox[6+7*bkid] , 30 , sizeof(CardBoxType) , &NPC_magiccard_sort ); + j++; + } + flag = FALSE; + for( i=0;i 50){ //ֻ + flag = TRUE; + continue; + } + Cardbox[i+7*bkid][k].use = 1; + card = SHIFTBASE << Cardbox[i+7*bkid][k].cardindex ; + CHAR_setWorkInt( charindex , NPC_WORK_HAND , + (unsigned int)CHAR_getWorkInt( charindex , NPC_WORK_HAND )|card ); + qsort( &Cardbox[i+7*bkid] , 30 , sizeof(CardBoxType) , &NPC_magiccard_sort ); + j++; + } + /* + for( j=0;j<30;j++){ + char tempbuf[256]; + sprintf( tempbuf,"%d ",Cardbox[i+7*bkid][j].use ); + strcat( buf, tempbuf ); + } + showString( meindex, buf , 0); + buf[0]='\0'; + for( j=0;j<30;j++){ + char tempbuf[256]; + sprintf( tempbuf,"%d ",Cardbox[i+7*bkid][j].cardindex ); + strcat( buf, tempbuf ); + } + showString( meindex, buf , 0); + */ + + //ƶսߵӽ + movescreenXY = ((14+offsetx) << 16) | (13+offsety) ; + lssproto_MoveScreen_send(getfdFromCharaIndex(charindex), TRUE, movescreenXY); + + } + banker[bkid].hp[BANKERID] = banker[bkid].starttotal * MAXHP ; + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 1000 ); + banker[bkid].state = 1; +} + +//սѡʲô +void NPC_magiccard_selectcard( int meindex , int bkid ) +{ + int i,j,fd,allhp=0,charindex; + unsigned int card=1; + char token[256]; + + for(i=0;i 0 || Cardfunctiontable[i].defence > 0 ){ + if( i < 25 ){ + //ȷdz + strcat( token , "\n\n" ); + strcat( token , "\n"); + buttontype = WINDOW_BUTTONTYPE_CANCEL; + }else{ + buttontype = WINDOW_BUTTONTYPE_OK|WINDOW_BUTTONTYPE_CANCEL; + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT , + buttontype, + CHAR_WINDOWTYPE_MAGIC_SELECT , + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); + break; + } + } + } +} + +//Ҫѡʱ +void NPC_magiccard_selectback( int meindex , int toindex ) +{ + unsigned int handcard; + char token[256]; + int i,j,fd,bkid,allhp=0; + + handcard = CHAR_getWorkInt( toindex , NPC_WORK_HAND); + bkid = CHAR_getWorkInt( toindex , NPC_WORK_BANKER ); + for(i=0;i= banker[bkid].playertotal ) okflag = TRUE; //Ҷѡ + //sprintf(buf,"ʣ%dս ѡս%d ",banker[bkid].playertotal,select); + //showString( meindex, buf , 0); + if( okflag == TRUE ) { + banker[bkid].state = 3; + NPC_magiccard_aiselect( meindex , bkid ); + + //sprintf(buf,"ai select %d action %d",banker[bkid].select,banker[bkid].action); + //showString( meindex, buf , 0); + + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, SHOWCARDLOOPTIME ); + } +} + +void NPC_magiccard_aiselect( int meindex , int bkid ) +{ + int i,j,k,enemy=0; + //int maxattack=0,maxdefence=0; + //int maxacard=0,maxdcard=0; + char buf[256]; + int charindex,allattack,alldefence,bestattack,bestdefence; + int getdamage=0,givedamage=0; + int card25=0,allhp=0; + int attacklist[5],defencelist[5],cardnum[5]; + BOOL selectflag = FALSE; + BOOL checkflag = FALSE; + + for( i=0;i<6;i++){ + attacklist[i] = 0; + defencelist[i] = 0; + cardnum[i]=0; + if(banker[bkid].pauseflag[i] == TRUE){ + banker[bkid].pauseflag[i] = FALSE; + checkflag = TRUE; //˱ӡ + } + } + allattack=0; + alldefence=0; + bestattack=0; + bestdefence=0; +//----------------------------------------------------------------------------- + if( banker[bkid].pauseflag[BANKERID] == TRUE ) + { + banker[bkid].pauseflag[BANKERID] = FALSE; + sprintf( buf,"ħӡ ͣһغ" ); + showString( meindex, buf , 0); + return; + } +//----------------------------------------------------------------------------- + if( rand()%200 > 5 + banker[bkid].playertotal * 1 || checkflag == TRUE || banker[bkid].turn == 10 ){ //80% + selectflag = FALSE; + for( i=0;i 40 + 5 * banker[bkid].playertotal ){ + allattack += rand()%10; + alldefence += rand()%10; + }else{ + alldefence += Cardfunctiontable[0].attack ; //ɵֵǿĹ-->µ + card25++; + } + }else if( CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) == 26 ){ //Ӱ + if( rand()%100 > 40 + 5 * banker[bkid].playertotal ) + alldefence += rand()%10; + else + alldefence += Cardfunctiontable[0].attack ; + }else if( CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) == 27 ){ //ӡ + if( rand()%100 > 30 + 5 * banker[bkid].playertotal ){ + allattack += rand()%5; + alldefence += rand()%5; + } + }else if( CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) == 28 ){ // + if( rand()%100 > 70 + 5 * banker[bkid].playertotal ){ + allattack += rand()%5; + alldefence += rand()%5; + } + }else if( CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) == 29 ){ // + if( rand()%100 > 30 + 5 * banker[bkid].playertotal ){ + allattack += rand()%5; + alldefence += rand()%5; + } + } + } + //sprintf( buf,"allA=%d allD=%d",allattack,alldefence ); + //showString( meindex, buf , 0); + + //¼ÿһƵĽ ûиֵʾ0 + j=0; + for( k=0;k<30;k++){ + if((SHIFTBASE< alldefence ){ + givedamage = Cardfunctiontable[k].attack * enemy - alldefence ; + if( allhp > banker[bkid].hp[BANKERID] ) + getdamage = allattack + Cardfunctiontable[k].attack * card25; + else + getdamage = allattack ; + attacklist[j] = givedamage - getdamage; + } + // + if( Cardfunctiontable[k].defence * enemy < allattack ){ + defencelist[j] = Cardfunctiontable[k].defence * enemy - allattack; + } + }else{ //ħ + attacklist[j] -= allattack; //жϳƲÿǵħ + defencelist[j] -= allattack; + } + cardnum[j]=k; + j++; + } + } + //sprintf( buf," %d %d %d %d %d",cardnum[0],cardnum[1],cardnum[2],cardnum[3],cardnum[4]); + //showString( meindex, buf , 0); + +//--------------------------------------------------------------------- + for( i=0;i<5;i++){ + if( cardnum[i] == 28 ){ + if( banker[bkid].turn == 10 ) + selectflag = TRUE; + else{ + switch( banker[bkid].playertotal ){ + case 1: + case 2: + if( banker[bkid].hp[BANKERID] < banker[bkid].starttotal * (MAXHP-25) ) + selectflag = TRUE; + break; + case 3: + case 4: + if( banker[bkid].hp[BANKERID] < banker[bkid].starttotal * (MAXHP-20) || banker[bkid].turn > 8 ) + selectflag = TRUE; + break; + case 5: + case 6: + if( banker[bkid].hp[BANKERID] < banker[bkid].starttotal * (MAXHP-15) && + allattack < banker[bkid].playertotal * 8 ) + selectflag = TRUE; + else if( banker[bkid].turn > 7 ) + selectflag = TRUE; + break; + } + } + if( selectflag == TRUE ){ + banker[bkid].select = 28; + banker[bkid].action = MAGIC; + return; + } + } + } +//ӡ---------------------------------------------------------------- + for( i=0;i<5;i++){ + if( cardnum[i]== 27 && banker[bkid].turn != 10 && banker[bkid].hp[BANKERID] >= banker[bkid].playertotal * 13){ + switch( banker[bkid].playertotal ){ + case 1: + case 2: + for( j=0;j<5;j++){ + if( rand()%100 > 50 && Cardfunctiontable[cardnum[j]].attack > 6 && allattack < banker[bkid].playertotal * 13 ) + selectflag = TRUE; + } + break; + case 3: + case 4: + for( j=0;j<5;j++){ + if( rand()%100 > 70 && Cardfunctiontable[cardnum[j]].attack > 7 && allattack < banker[bkid].playertotal * 8 ) + selectflag = TRUE; + } + break; + case 5: + case 6: + for( j=0;j<5;j++){ + if( rand()%100 > 50 && Cardfunctiontable[cardnum[j]].attack == 13 && allattack < banker[bkid].playertotal * 8 ) + selectflag = TRUE; + else if( rand()%100 > 80 && Cardfunctiontable[cardnum[j]].attack > 7 && allattack < banker[bkid].playertotal * 8 ) + selectflag = TRUE; + } + break; + } + if( selectflag == TRUE ){ + banker[bkid].select = 27; + banker[bkid].action = MAGIC; + return; + } + } + } +//лӰжҪҪʹ----------------------------------------------------------------- + for( i=0;i<5;i++){ + if( cardnum[i] == 26 && checkflag == FALSE ){ + if( banker[bkid].turn == 10 && allhp <= banker[bkid].hp[BANKERID] ){ + selectflag = TRUE; + }else{ + switch( banker[bkid].playertotal ){ + case 1: + case 2: + if( banker[bkid].turn < 8 && rand()%100 > 80 ) selectflag = TRUE; + else if( banker[bkid].turn > 7 && banker[bkid].hp[BANKERID] < banker[bkid].starttotal * 15 ) selectflag = TRUE; + else if( allattack > 8 * banker[bkid].playertotal && rand()%100 > 40 ) selectflag = TRUE; + break; + case 3: + case 4: + if( allhp > banker[bkid].hp[BANKERID] && allattack > 8 * banker[bkid].playertotal ) selectflag = TRUE; + else if( allhp - banker[bkid].hp[BANKERID] > 10 && banker[bkid].turn > 5 && + allattack > 6 * banker[bkid].playertotal ){ + selectflag = TRUE; + } + break; + case 5: + case 6: + if( allhp - banker[bkid].hp[BANKERID] > 10 && + allattack > 8 * banker[bkid].playertotal ) selectflag = TRUE; + else if( banker[bkid].hp[BANKERID] > allhp && banker[bkid].turn > 5 && rand()%100 > 80) selectflag = TRUE; + else{ + for( j=0;j (70-banker[bkid].turn*8) ){ + selectflag = TRUE; + break; + } + } + } + } + break; + } + } + if( banker[bkid].turn == 10 && allhp > banker[bkid].hp[BANKERID] ) selectflag = FALSE; + if( selectflag == TRUE ){ + banker[bkid].select = 26; + banker[bkid].action = MAGIC; + return; + } + } + } +//жҪҪʹ----------------------------------------------------------------- + for( i=0;i<5;i++){ + if( cardnum[i] == 29 && checkflag == FALSE){ + switch(banker[bkid].playertotal){ + case 1: + case 2: + if( rand()%100 > 80 && banker[bkid].hp[BANKERID] < allhp ) selectflag = TRUE; + else if( banker[bkid].turn == 10 && (allhp-banker[bkid].hp[BANKERID]) >= 10 ) selectflag = TRUE; + break; + case 3: + case 4: + if( allattack < Cardfunctiontable[29].attack && rand()%100>30 ) selectflag = TRUE; + else if( rand()%100 > 70 && banker[bkid].hp[BANKERID] < allhp ) selectflag = TRUE; + break; + case 5: + case 6: + if( allattack < Cardfunctiontable[29].attack+10 ) selectflag = TRUE; + else if( banker[bkid].turn == 10 && (allhp - banker[bkid].hp[BANKERID]) >= 13 ) selectflag = TRUE; + break; + } + if( selectflag == TRUE ){ + banker[bkid].select = 29; + banker[bkid].action = MAGIC; + return; + } + } + } +//--------------------------------------------------------------------------------- + for( i=0;i<5;i++){ + if( cardnum[i] == 25 && checkflag == FALSE ){ + if( banker[bkid].turn == 10 ){ + selectflag = TRUE; + }else{ + switch(banker[bkid].playertotal){ + case 1: + case 2: + if( rand()%100 > 50 ) selectflag = TRUE; + else if( rand()%100>70-banker[bkid].turn*2 && allattack >= 6 * banker[bkid].playertotal ) selectflag = TRUE; + break; + case 3: + case 4: + if( rand()%100 > 60 ) selectflag = TRUE; + else if( rand()%100 > 50 && allhp < banker[bkid].hp[BANKERID] ) selectflag = TRUE; + else if( rand()%100>60-banker[bkid].turn*2 && allattack >= 7 * banker[bkid].playertotal ) selectflag = TRUE; + break; + case 5: + case 6: + if( rand()%100 > 70 && allhp > banker[bkid].hp[BANKERID] ) selectflag = TRUE; + else if( rand()%100>50-banker[bkid].turn*2 && allattack >= 8 * banker[bkid].playertotal ) selectflag = TRUE; + else if( banker[bkid].turn > 7 && allhp < banker[bkid].hp[BANKERID] ) selectflag = TRUE; + break; + } + if( selectflag == TRUE ){ + banker[bkid].select = 25; + banker[bkid].action = MAGIC; + return; + } + } + } + } +//һغϻһǿĹ---------------------------------------------------- + if( ( banker[bkid].turn == 10 && allhp > banker[bkid].hp[BANKERID] ) || checkflag == TRUE ){ + bestattack = 0; + for( i=0;i<5;i++){ + if( cardnum[i] >= 25) continue; + if( Cardfunctiontable[cardnum[i]].attack > bestattack ){ + bestattack = Cardfunctiontable[cardnum[i]].attack; + banker[bkid].select = cardnum[i]; + banker[bkid].action = ATTACK; + } + } + } +//ĿǰӮ״̬ ͬʱֳ˿ûѪ ǿ------------------------ + if( banker[bkid].action == 0 ){ + if( allhp < banker[bkid].hp[BANKERID] ){ + for( j=0;j 0 && banker[bkid].hp[j] < MAXHP/4 ){ + bestattack = 6; + for( i=0;i<5;i++){ + if( cardnum[i] >= 25) continue; + if( Cardfunctiontable[cardnum[i]].attack > bestattack ){ + bestattack = Cardfunctiontable[cardnum[i]].attack; + banker[bkid].select = cardnum[i]; + banker[bkid].action = ATTACK; + } + } + } + } + } + } +//----------------------------------------------------------------------------------- + bestattack = 0; + bestdefence = 0; + if( banker[bkid].action == 0 ){ + if( allhp >= banker[bkid].hp[BANKERID] || rand()%100 > 50 ){ //Ӯ + for( i=0;i<5;i++){ + if( cardnum[i] >= 25) continue; + if( banker[bkid].hp[BANKERID] < banker[bkid].playertotal * 13 ) break; //ûѪ + if( attacklist[i] > bestattack ){ + bestattack = attacklist[i]; + banker[bkid].select = cardnum[i]; + banker[bkid].action = ATTACK; + } + } + } + } + if( banker[bkid].action == 0 ){ + if( rand()%100 > 50 + banker[bkid].playertotal * 3 ){ + // + if( rand()%100 > 50 ){ + bestdefence = defencelist[4] ; + for( i=4;i>=0;i--){ //ú + if( cardnum[i] >= 25 ) continue; + if( defencelist[i] > bestdefence ){ + bestdefence = defencelist[i] ; + banker[bkid].select = cardnum[i]; + banker[bkid].action = DEFENCE; + } + } + }else{ + bestdefence = defencelist[0] ; + for( i=0;i<5;i++){ // + if( cardnum[i] >= 25 ) continue; + if( defencelist[i] > bestdefence ){ + bestdefence = defencelist[i] ; + banker[bkid].select = cardnum[i]; + banker[bkid].action = DEFENCE; + } + } + } + }else{ + // + if( rand()%100 > 50 ){ + bestattack = attacklist[4] ; + for( i=4;i>=0;i--){ //ñȽϺõ + if( cardnum[i] >= 25 ) continue; + if( attacklist[i] > bestattack ){ + bestattack = attacklist[i] ; + banker[bkid].select = cardnum[i]; + banker[bkid].action = ATTACK; + } + } + }else{ + bestattack = attacklist[0] ; + for( i=0;i<5;i++){ //ñȽϲ + if( cardnum[i] >= 25 ) continue; + if( attacklist[i] > bestattack ){ + bestattack = attacklist[i] ; + banker[bkid].select = cardnum[i]; + banker[bkid].action = ATTACK; + } + } + } + } + } + } + + //ûѡ + if( banker[bkid].action == 0 ) + { + j=0; + for( k=0;k<25;k++){ + if((SHIFTBASE< 50 ) + banker[bkid].action = ATTACK; + else + banker[bkid].action = DEFENCE; + } + + //ռ + if( banker[bkid].select < 25 ){ + if( Cardfunctiontable[banker[bkid].select].attack == 13 ) + banker[bkid].action = ATTACK; + if( Cardfunctiontable[banker[bkid].select].defence == 13 ) + banker[bkid].action = DEFENCE; + }else + banker[bkid].action = MAGIC; +} + +void NPC_magiccard_checkdamage( int meindex , int bkid ) +{ + int charindex,i; + int bankerdamage=0,playerdamage=0; + int select; + //char buf[256]; + + for( i=0;i Cardfunctiontable[banker[bkid].select].defence ) + bankerdamage += (Cardfunctiontable[select].attack-Cardfunctiontable[banker[bkid].select].defence); + }else + bankerdamage += Cardfunctiontable[select].attack; + } + if( banker[bkid].action == ATTACK && CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) != 26 ) + { + if( select == 25 ){ + bankerdamage += Cardfunctiontable[banker[bkid].select].attack; + }else if( CHAR_getWorkInt( charindex , NPC_WORK_ACTION ) == DEFENCE ){ + if( Cardfunctiontable[banker[bkid].select].attack > Cardfunctiontable[select].defence ) + { + playerdamage += (Cardfunctiontable[banker[bkid].select].attack-Cardfunctiontable[select].defence); + CHAR_setWorkInt( charindex , NPC_WORK_DAMAGE , (Cardfunctiontable[banker[bkid].select].attack-Cardfunctiontable[select].defence) ); + } + }else{ + playerdamage += Cardfunctiontable[banker[bkid].select].attack; + CHAR_setWorkInt( charindex , NPC_WORK_DAMAGE , + CHAR_getWorkInt( charindex , NPC_WORK_DAMAGE ) + Cardfunctiontable[banker[bkid].select].attack ); + } + } + //sprintf( buf,"ս%d select=%d ˺%d",i,select,CHAR_getWorkInt( charindex , NPC_WORK_DAMAGE ) ); + //showString( meindex, buf , 0); + } + //sprintf( buf,"ׯ˺%d ս˺%d",bankerdamage,playerdamage); + //showString( meindex, buf , 0); + + //㶯 + if( banker[bkid].select != 29 && banker[bkid].select != 27 ){ + //sprintf( buf,"-----------------ħѡ %d------------------",banker[bkid].select); + //showString( meindex, buf , 0); + NPC_magiccard_action2( meindex , meindex , BANKERID , banker[bkid].select , banker[bkid].action ); + } + + for( i=0;i MAXHP ) banker[bkid].hp[i] = MAXHP; + if( CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) != 29 && + CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) != 27 ) + NPC_magiccard_action2( meindex , charindex , i , CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) , CHAR_getWorkInt( charindex , NPC_WORK_ACTION ) ); + } + + //ׯҿѪ + if( banker[bkid].select == 28 ){ //ׯ + bankerdamage = bankerdamage - banker[bkid].starttotal*MAXHP/2; + //sprintf( buf,"ħ bankdamage=%d Լ=%d",bankerdamage,banker[bkid].starttotal*MAXHP/2); + //showString( meindex, buf , 0); + + } + banker[bkid].hp[BANKERID] -= bankerdamage; + NPC_magiccard_showdamage( meindex, meindex , BANKERID , bankerdamage ); + if( banker[bkid].hp[BANKERID] > banker[bkid].starttotal * MAXHP ) + banker[bkid].hp[BANKERID] = banker[bkid].starttotal * MAXHP; + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, FIGHTLOOPTIME ); + banker[bkid].state = 4; +} + +void NPC_magiccard_specialcard( int meindex , int bkid ) +{ + int thunder=0,allhp=0; + int i,j,k,target,targetarray[6],charindex,damage=0; + char buf[256],buf1[256],buf2[256]; + + //мʹ + for( i=0;i 50 + 5 * banker[bkid].playertotal ) + target = BANKERID; + else + { + k = 0 ; + for( j=0;j ( 30 - 4 * banker[bkid].playertotal ) ) && + CHAR_getWorkInt( charindex , NPC_WORK_SELECT ) != 26 ){ + banker[bkid].pauseflag[i] = TRUE; + NPC_magiccard_showdamage(meindex , meindex , i , 1111 ); + sprintf(buf2,"%d ",i+1); + strcat( buf1,buf2); + }else + NPC_magiccard_showdamage(meindex , meindex , i , 2222 ); + } + } + for( i=0;i ( 50 + 5 * banker[bkid].playertotal ) ){ + banker[bkid].pauseflag[BANKERID] = TRUE; + sprintf( buf2,"ħ "); + strcat( buf1,buf2); + NPC_magiccard_showdamage( meindex , meindex , BANKERID , 1111 ); + strcat(buf," "); + }else{ + NPC_magiccard_showdamage(meindex , meindex , BANKERID , 2222 ); + strcat(buf," ʧ"); + } + showString( meindex, buf , 0); + } + } + + if(strcmp( buf1 , "" ) !=0 ){ + strcat( buf1,"ӡ"); + } + + //غ϶ս + if( allhp > banker[bkid].hp[BANKERID] ) + sprintf( buf,"%dغϽսHP%dȡħHP%d%s",banker[bkid].turn,allhp,banker[bkid].hp[BANKERID],buf1); + else if( allhp < banker[bkid].hp[BANKERID] ) + sprintf( buf,"%dغϽħHP%dȡսHP%d%s",banker[bkid].turn,banker[bkid].hp[BANKERID],allhp,buf1); + else + sprintf( buf,"%dغϽ˫HP%dƽ %s",banker[bkid].turn,allhp,buf1); + showString( meindex, buf , 0); + + banker[bkid].state = 5; + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, TURNOVERTIME ); +} + +// µͼ +void NPC_magiccard_action2(int meindex , int charindex , int user , int card , int action ) +{ + int x,y,floor; + OBJECT object; + int objindex,othercharindex; + int j,k,dir,animno; + char data[1024],buf[256]; + int offsetx,offsety; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return ; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + floor = CHAR_getInt(charindex, CHAR_FLOOR); + x = Positiontable[user].petX + offsetx; + y = Positiontable[user].petY + offsety; + dir = Positiontable[user].direct; + animno = Cardfunctiontable[card].effect; + + //͸npc + if( ( card == 27 || card == 29 ) && user <= BANKERID ){ + object=MAP_getTopObj(floor, Positiontable[user].npcX + offsetx, Positiontable[user].npcY + offsety ); + if(object){ + objindex = GET_OBJINDEX( object); + charindex = OBJECT_getIndex(objindex); + } + //sprintf( data,"npcindex %d name: %s",charindex,CHAR_getChar(charindex, CHAR_NAME)); + //showString( charindex, data , 0); + } + + for( j = x-CHAR_DEFAULTSEESIZ ; j <= x+CHAR_DEFAULTSEESIZ ; j++ ){ + for( k = y-CHAR_DEFAULTSEESIZ ; k <= y+CHAR_DEFAULTSEESIZ ; k ++ ){ + for (object = MAP_getTopObj(floor, j, k); object; object = NEXT_OBJECT(object)) + { + objindex = GET_OBJINDEX( object); + othercharindex = OBJECT_getIndex(objindex); + + if (OBJECT_getType(objindex) == OBJTYPE_NOUSE) + continue; + //if (OBJECT_getType(objindex) == OBJTYPE_CHARA && + // !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE)) + // continue; + if (OBJECT_getType(objindex) == OBJTYPE_CHARA && + CHAR_getInt(othercharindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + CHAR_getWorkInt(othercharindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + sprintf( data,"%d|%d|%d|%d|%d|%d|%d|%d|",CHAR_getWorkInt( charindex, CHAR_WORKOBJINDEX) + //sprintf( data,"%d|%d|%d|%d|%d|%d|",CHAR_getWorkInt( npccharindex, CHAR_WORKOBJINDEX) + ,user,card,dir,animno,action,offsetx,offsety); + lssproto_MagiccardAction_send(getfdFromCharaIndex(othercharindex), data ); + //lssproto_Firework_send(getfdFromCharaIndex(othercharindex), CHAR_getWorkInt( charindex, CHAR_WORKOBJINDEX), 0, 101888); + } + } + } + } +} + +void NPC_magiccard_showdamage(int meindex , int charindex , int position , int damage ) +{ + int x,y,j,k,floor; + OBJECT object; + int objindex,othercharindex,offsetx,offsety; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return ; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + floor = CHAR_getInt(charindex, CHAR_FLOOR); + x = Positiontable[position].humanX + offsetx; + y = Positiontable[position].humanY + offsety; + + for( j = x-CHAR_DEFAULTSEESIZ/2 ; j <= x+CHAR_DEFAULTSEESIZ/2 ; j++ ){ + for( k = y-CHAR_DEFAULTSEESIZ/2 ; k <= y+CHAR_DEFAULTSEESIZ/2 ; k ++ ){ + for (object = MAP_getTopObj(floor, j, k); object; object = NEXT_OBJECT(object)) + { + objindex = GET_OBJINDEX( object); + othercharindex = OBJECT_getIndex(objindex); + + if (OBJECT_getType(objindex) == OBJTYPE_NOUSE) + continue; + if (OBJECT_getType(objindex) == OBJTYPE_CHARA && + !CHAR_getFlg(OBJECT_getIndex(objindex), CHAR_ISVISIBLE)) + continue; + if (OBJECT_getType(objindex) == OBJTYPE_CHARA && + CHAR_getInt(othercharindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER && + CHAR_getWorkInt(othercharindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){ + lssproto_MagiccardDamage_send(getfdFromCharaIndex(othercharindex), position,damage,offsetx,offsety); + //sprintf( buf,"name: %s fd%d posi %d damage %d ox %d oy %d",CHAR_getChar(othercharindex, CHAR_NAME), + // getfdFromCharaIndex(othercharindex),position,damage,offsetx,offsety + // ); + //showString( meindex, buf , 0); + } + } + } + } + +} + +//ĸս߳ +void NPC_magiccard_out( int meindex , int bkid , int player ) +{ + int gift=0,charindex,allhp=0,i; + char buf[128]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int offsetx,offsety; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return ; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + charindex = NPC_magiccard_checkExist( meindex , bkid , player ); + if( !CHAR_CHECKINDEX(charindex)) return; + + for( i=0;i=allhp ){ + if( CHAR_getWorkInt( charindex , NPC_WORK_GIVEGOLD ) == 1 ){ + sprintf(buf,"ĿǰܻΪ%dлл",CHAR_getInt( charindex , CHAR_GAMBLENUM)); + CHAR_talkToCli( charindex , -1 , buf, CHAR_COLORYELLOW); + }else{ + sprintf(buf,"ܱǸ˿ 6 ֣ĿǰܻΪ%dлл",CHAR_getInt( charindex , CHAR_GAMBLENUM)); + CHAR_talkToCli( charindex , -1 , buf, CHAR_COLORYELLOW); + } + }else{ + if( banker[bkid].turn <= 10 && banker[bkid].hp[BANKERID] <= 0) gift = 20; + else if(allhp >= banker[bkid].starttotal*MAXHP*80/100 ) gift = 15; + else if(allhp >= banker[bkid].starttotal*MAXHP*60/100 ) gift = 10; + else gift = 5; + + if( CHAR_getWorkInt( charindex , NPC_WORK_GIVEGOLD ) == 1 ){ + CHAR_setInt( charindex , CHAR_GOLD, CHAR_getInt( charindex , CHAR_GOLD)+10000 ); + CHAR_setInt( charindex , CHAR_GAMBLENUM, CHAR_getInt( charindex , CHAR_GAMBLENUM)+gift ); + sprintf(buf,"ûر֤10000"); + CHAR_talkToCli( charindex , -1 , buf, CHAR_COLORYELLOW); + }else{ + CHAR_setInt( charindex , CHAR_GAMBLENUM, CHAR_getInt( charindex , CHAR_GAMBLENUM)+gift+6 ); + } + sprintf(buf,"ϲõ %d ֣ĿǰܻΪ%dлл",gift,CHAR_getInt( charindex , CHAR_GAMBLENUM)); + CHAR_talkToCli( charindex , -1 , buf, CHAR_COLORYELLOW); + Bettotal[bkid] -= 6; + Wintotal[bkid] += gift; + if( CHAR_getInt( charindex , CHAR_GAMBLENUM ) > 10000 ) + CHAR_setInt( charindex , CHAR_GAMBLENUM , 10000 ); + } + + CHAR_setWorkInt( charindex , CHAR_WORK_TEMP_FLOOR, 0); + // ӫĻλ + lssproto_MoveScreen_send(getfdFromCharaIndex(charindex), FALSE, 0); + + CHAR_warpToSpecificPoint( charindex , CHAR_getInt( meindex, CHAR_FLOOR) + ,Positiontable[7].humanX + offsetx , Positiontable[7].humanY + offsety); + //banker[bkid].playertotal -= 1; +} + +//һغϽ³ +void NPC_magiccard_turnover( int meindex , int bkid ) +{ + char buf[256]; + unsigned int card; + int i,k,charindex,offsetx,offsety; + BOOL goflag = FALSE; + OBJECT object; + int bossindex,objindex; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("\n read argstr err"); + return ; + } + NPC_Util_GetStrFromStrWithDelim( argstr , "offsetx", buf, sizeof( buf)); + offsetx = atoi(buf); + NPC_Util_GetStrFromStrWithDelim( argstr , "offsety", buf, sizeof( buf)); + offsety = atoi(buf); + + + // + for( i=0;i 50 ) k = rand()%(26-banker[bkid].turn); //ֻ + + Cardbox[i+7*bkid][k].use = 1; + card = SHIFTBASE << Cardbox[i+7*bkid][k].cardindex ; + CHAR_setWorkInt( charindex , NPC_WORK_HAND , + (unsigned int)CHAR_getWorkInt( charindex , NPC_WORK_HAND )|card ); + qsort( &Cardbox[i+7*bkid] , 30 , sizeof(CardBoxType) , &NPC_magiccard_sort ); + + CHAR_setWorkInt( charindex , NPC_WORK_SELECT , -1 ); //ѡ + CHAR_setWorkInt( charindex , NPC_WORK_ACTION , 0 ); // + CHAR_setWorkInt( charindex , NPC_WORK_DAMAGE , 0 ); //˺ + + } + + if( banker[bkid].action != 0 ) //ûбӡ + { + //ׯҳõ + card = SHIFTBASE << banker[bkid].select ; + banker[bkid].history |= card; + card = ~card; + banker[bkid].hand &= card; + + //ׯҳ + k = rand()%(26-banker[bkid].turn); + if( Cardbox[6+7*bkid][k].cardindex == 28 && rand()%100 > 50 ) k = rand()%(26-banker[bkid].turn); //ֻ + Cardbox[6+7*bkid][k].use = 1; + card = SHIFTBASE << Cardbox[6+7*bkid][k].cardindex ; + banker[bkid].hand |= card; + qsort( &Cardbox[6+7*bkid] , 30 , sizeof(CardBoxType) , &NPC_magiccard_sort ); + } + + if( banker[bkid].turn == 10 || banker[bkid].hp[BANKERID] <= 0 || goflag == FALSE ){ + // + if( banker[bkid].hp[BANKERID] <= 0 && goflag == TRUE ) + { + object = MAP_getTopObj(CHAR_getInt(meindex, CHAR_FLOOR), Positiontable[BANKERID].humanX + offsetx, Positiontable[BANKERID].humanY + offsety ); + if( object ){ + objindex = GET_OBJINDEX( object); + bossindex = OBJECT_getIndex(objindex); + CHAR_sendAction( bossindex , 2 , FALSE); //ε + } + } + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, GAMEOVERTIME ); + banker[bkid].state = 9; + }else{ + banker[bkid].turn += 1; + if( banker[bkid].turn == 10 ){ + sprintf(buf,"10غ һغφ ս"); + }else{ + sprintf(buf,"%dغ ս",banker[bkid].turn); + } + showString( meindex, buf , 0); + banker[bkid].turntime = NowTime.tv_sec + 20 ; + banker[bkid].process = 0; + banker[bkid].select = 0; + banker[bkid].action = 0; + banker[bkid].state = 1; + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, LOOPTIME ); + } +} + +void NPC_magiccard_gameover( int meindex , int bkid ) +{ + int i,allhp=0; + char buf[256]; + + + for( i=0;i= allhp ){ + strcat(buf,"ħʤ"); + }else{ + strcat(buf,"ϲս߻ʤ"); + } + showString( meindex, buf , 0); + + for( i=0;iuse > ((CardBoxType*)card2)->use )? 1:0; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_makepair.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_makepair.c new file mode 100644 index 0000000..32c4616 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_makepair.c @@ -0,0 +1,543 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_transerman.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_makepair.h" +#include "npc_eventaction.h" +#ifdef _EMENY_CHANCEMAN // (ɿ) ANDY EMENY ѡ +#ifdef _NPC_MAKEPAIR +#define MAXPAIRNUMS 30 +PairMenu PairList[2][MAXPAIRNUMS]; + +enum { + WINDOW_START=10, + WINDOW_USER, + WINDOW_SELECT, // + WINDOW_PAIR, //Ҷ + WINDOW_PAIROK, + WINDOW_PAIRNO, + WINDOW_WARP, //Ծ + WINDOW_END, // + WINDOW_TALKSTART=20, + WINDOW_TALKSELECT, + WINDOW_TALKPAIR, + WINDOW_RETURN, + WINDOW_TALKEND, +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_WORK_PAIRTEAMS = CHAR_NPCWORKINT2, +/* + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; +#define MAKEPAIR_STANDBY 100*60 +static void NPC_MakePair_selectWindow( int meindex, int toindex, int num,int select); +BOOL MakePairMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token); +void CheckPairUsers( int *male, int *female); +BOOL NPC_PairForage( int meindex, int toindex, char *arg, char *token); +BOOL NPC_PairRegister( int toindex); +void NPC_PairUserAndWarp( int meindex, int toindex, int forindex, char *arg); +int NPC_getPairCode( int toindex); +int NPC_getTitleMsg( int meindex, int toindex, char *arg, char *token, int title); +int NPC_getNextTitle( int meindex, int toindex, char *arg, int title, int select); + + +BOOL NPC_MakePairManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i; + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_MakePairMan: GetArgStrErr!!"); + return FALSE; + } + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_MAKEPAIR); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, MAKEPAIR_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + CHAR_setWorkInt( meindex, NPC_WORK_PAIRTEAMS, 0); + + for( i=0; i 0){ + CHAR_setWorkInt( toindex, CHAR_MYPAIRINDEX, -1); + sprintf( token, "ȡǰһε롣"); + }else { + char buf1[256]; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FREE", buf1, sizeof( buf1) ) != NULL) { + if( NPC_ActionPassCheck( meindex, toindex, buf1) == FALSE ){ + CHAR_talkToCli( toindex, meindex, "㣡", CHAR_COLORYELLOW); + return; + } + } + NPC_PairForage( meindex, toindex, npcarg, token); + } + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = WINDOW_TALKEND; + } + break; + case WINDOW_PAIROK: //ͬ + if( CHAR_getWorkInt( toindex, CHAR_MYPAIRFLG) > 0){ + int forindex = CHAR_getWorkInt( toindex, CHAR_MYPAIRINDEX); + NPC_PairUserAndWarp( meindex, toindex, forindex, npcarg); + } + return; + case WINDOW_PAIRNO://ͬ + { + int forindex = CHAR_getWorkInt( toindex, CHAR_MYPAIRINDEX); + if( CHAR_CHECKINDEX( forindex) ){ + if( CHAR_getWorkInt( forindex, CHAR_MYPAIRFLG) > 0 ){ + CHAR_talkToCli( forindex, meindex, "Էܾ롣", CHAR_COLORYELLOW); + CHAR_setWorkInt( forindex, CHAR_MYPAIRINDEX, -1); + CHAR_setWorkInt( forindex, CHAR_MYPAIRFLG, -1); + } + } + CHAR_setWorkInt( toindex, CHAR_MYPAIRINDEX, -1); + CHAR_setWorkInt( toindex, CHAR_MYPAIRFLG, -1); + CHAR_talkToCli( toindex, meindex, "ܾԷ롣", CHAR_COLORYELLOW); + return; + } + break; + case WINDOW_WARP: + break; + case WINDOW_END: + break; + } + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_MakePairManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_MakePairMan: GetArgStrErr!!"); + return; + } + switch( seqno) { + case WINDOW_TALKSTART: + { + int choose=atoi( data); + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( choose){ + case 1:// + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_USER, 0); + break; + case 2:// + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_PAIR, 0); + break; + case 3:// + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_SELECT, 0); + break; + } + } + + break; + case WINDOW_TALKSELECT: + { + int title = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + title = NPC_getNextTitle( meindex, talkerindex, npcarg, title, select); + if( title < 0 ) return ; + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, title); + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_SELECT, select); + } + break; + case WINDOW_TALKPAIR://ظ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO){ + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_PAIRNO, 0); + }else { + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_PAIROK, 0); + } + break; + case WINDOW_RETURN: + NPC_MakePair_selectWindow( meindex, talkerindex, WINDOW_START, 0); + break; + case WINDOW_TALKEND: + break; + } +} +void NPC_MakePairManLoop( int meindex) +{ + int i; + for( i=0; i 0 ){ + if( !CHAR_CHECKINDEX( PairList[0][i].pindex) ){ + PairList[0][i].pindex = -1; + PairList[0][i].use = -1; + } + } + if( PairList[1][i].use > 0 ){ + if( !CHAR_CHECKINDEX( PairList[1][i].pindex) ){ + PairList[1][i].pindex = -1; + PairList[1][i].use = -1; + } + } + } +} + +BOOL MakePairMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token) +{ + char buf1[1024], buf2[256], buf3[256]; + BOOL FINDS=FALSE; + int talkNo=1; + if( npcarg == NULL ) return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "MenuHead", buf1, sizeof( buf1) ) == NULL){ + return FALSE; + } + sprintf( token, "%s\n", buf1); + + sprintf( buf1, "MEMU%d", talkNo); + while( NPC_Util_GetStrFromStrWithDelim( npcarg, buf1, buf2, sizeof( buf2)) != NULL ) { + talkNo++; + sprintf( buf1, "MEMU%d", talkNo); + FINDS = TRUE; + sprintf( buf3, " %s\n", buf2); + strcat( token, buf3); + } + return FINDS; +} + +void CheckPairUsers( int *male, int *female) +{ + int i; + *male = 0; + *female = 0; + for( i=0; i 0 ) *male+=1; + if( PairList[1][i].use > 0 ) *female+=1; + } +} + +BOOL NPC_PairForage( int meindex, int toindex, char *arg, char *token) +{ + char buf1[256]; + int i; + int codes = CHAR_getWorkInt( toindex, CHAR_MYPAIRCODE); + int Psex = CHAR_getSexInt( CHAR_getInt( toindex, CHAR_BASEBASEIMAGENUMBER) ); + Psex = (Psex==1)?1:0; + + + for( i=0; i 0 ) continue; + name = CHAR_getChar( PairList[Psex][i].pindex, CHAR_NAME); + cdKey = CHAR_getChar( PairList[Psex][i].pindex, CHAR_CDKEY); + if( strcmp( PairList[Psex][i].name, name) || strcmp( PairList[Psex][i].cdKey, cdKey) ){ + PairList[Psex][i].use = -1; + PairList[Psex][i].forindex = -1; + continue; + } + sprintf( token, "ԶΪ %s\nͳ룬ȺԷӦ", name); + if( NPC_Util_GetStrFromStrWithDelim( arg, "InviteMsg", buf1, sizeof( buf1) ) == NULL){ + break; + } + PairList[Psex][i].forindex = toindex; + fd = getfdFromCharaIndex( PairList[Psex][i].pindex); + + CHAR_setWorkInt( toindex, CHAR_MYPAIRFLG, 1); + CHAR_setWorkInt( toindex, CHAR_MYPAIRINDEX, PairList[Psex][i].pindex); + CHAR_setWorkInt( PairList[Psex][i].pindex, CHAR_MYPAIRFLG, 2); + CHAR_setWorkInt( PairList[Psex][i].pindex, CHAR_MYPAIRINDEX, toindex); + + name = CHAR_getChar( toindex, CHAR_NAME); + sprintf( buf, "%s\n%s\n%s", CHAR_getChar( meindex, CHAR_NAME),name, buf1); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OKCANCEL, WINDOW_TALKPAIR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), buf); + break; + } + if( i>= MAXPAIRNUMS ) { + if( NPC_Util_GetStrFromStrWithDelim( arg, "NoPairMsg", buf1, sizeof( buf1) ) != NULL){ + sprintf( token, "%s",buf1); + }else { + sprintf( token, "ûҵ"); + } + if( CHAR_getWorkInt( toindex, CHAR_MYPAIRFLG) <= 0 ) { + NPC_PairRegister( toindex); + } + return FALSE; + } + return TRUE; +} + +BOOL NPC_PairRegister( int toindex) +{ + char *cdKey = CHAR_getChar( toindex, CHAR_CDKEY); + char *name = CHAR_getChar( toindex, CHAR_NAME); + int space=-1,i; + int Psex = CHAR_getSexInt( CHAR_getInt( toindex, CHAR_BASEBASEIMAGENUMBER) ); + Psex = (Psex==1)?0:1; + for( i=0; i=MAXPAIRNUMS){ + if( space != -1 && CHAR_getWorkInt( toindex, CHAR_MYPAIRCODE) > 0 ){ + PairList[Psex][space].use = 1; + PairList[Psex][space].forindex = -1; + sprintf( PairList[Psex][space].cdKey, "%s", cdKey); + sprintf( PairList[Psex][space].name, "%s", name); + PairList[Psex][space].pindex = toindex; + PairList[Psex][space].code = CHAR_getWorkInt( toindex, CHAR_MYPAIRCODE); + + CHAR_talkToCli( toindex, -1, "", CHAR_COLORYELLOW); + return TRUE; + } + } + return FALSE; +} + +void NPC_PairUserAndWarp( int meindex, int toindex, int forindex, char *arg) +{ + char buf1[256]; + int fl=-1, x=-1, y=-1; + + if( !CHAR_CHECKINDEX( toindex)) return; + CHAR_setWorkInt( toindex, CHAR_MYPAIRINDEX, -1); + CHAR_setWorkInt( toindex, CHAR_MYPAIRFLG, -1); + if( !CHAR_CHECKINDEX( forindex)) return; + CHAR_setWorkInt( forindex, CHAR_MYPAIRINDEX, -1); + CHAR_setWorkInt( forindex, CHAR_MYPAIRFLG, -1); + + if( CHAR_getWorkInt( toindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) return; + if( CHAR_getWorkInt( forindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) return; + + if( NPC_Util_GetStrFromStrWithDelim( arg, "PAIRTOPOINT", buf1, sizeof( buf1) ) != NULL){ + char buf2[256]; + if( getStringFromIndexWithDelim( buf1,",",1,buf2,sizeof( buf2)) != FALSE ) + fl = atoi( buf2); + if( getStringFromIndexWithDelim( buf1,",",2,buf2,sizeof( buf2)) != FALSE ) + x = atoi( buf2); + if( getStringFromIndexWithDelim( buf1,",",3,buf2,sizeof( buf2)) != FALSE ) + y = atoi( buf2); + } + CHAR_DischargePartyNoMsg( toindex);//ɢŶ + CHAR_DischargePartyNoMsg( forindex);//ɢŶ + if( MAP_IsValidCoordinate( fl, x, y) != FALSE ){ + CHAR_warpToSpecificPoint( toindex, fl, x, y); + CHAR_warpToSpecificPoint( forindex, fl, x, y); + } + + CHAR_JoinParty_Main( toindex, forindex); + //lssproto_PR_send( fd, 0, 1); + { + int i; + for( i=0; i 0 ){ + if( PairList[0][i].pindex == toindex || + PairList[0][i].pindex == forindex ){ + PairList[0][i].pindex = -1; + PairList[0][i].use = -1; + } + } + if( PairList[1][i].use > 0 ){ + if( PairList[1][i].pindex == toindex || + PairList[1][i].pindex == forindex ){ + PairList[1][i].pindex = -1; + PairList[1][i].use = -1; + } + } + } + } +} + +int NPC_getPairCode( int toindex) +{ + char *arg="\0"; + int code=-1, i; + if( !CHAR_CHECKINDEX( toindex)) return-1; + for( i=0; i<15; i++) { + char buf1[256]; + int itemindex = CHAR_getItemIndex( toindex, i); + if( !ITEM_CHECKINDEX( itemindex) ) continue; + arg = ITEM_getChar(itemindex, ITEM_ARGUMENT );// Ա|Ա|FLG + if( arg == "\0" )continue; + if( NPC_Util_GetStrFromStrWithDelim( arg, "PAIRCODE", buf1, sizeof( buf1) ) == NULL) continue; + code = atoi( buf1); + break; + } + return code; +} + +int NPC_getNextTitle( int meindex, int toindex, char *arg, int title, int select) +{ + char buf[NPC_UTIL_GETARGSTR_BUFSIZE], buf1[1024], buf2[256]; + int toID=0; + memset( buf, 0, sizeof( buf)); + if( getStringFromIndexWithDelim( arg, "PSYCHOMETRICS", 2, buf, sizeof( buf)) == FALSE ) + return -1; + if( getStringFromIndexWithDelim( buf , "}", title, buf1, sizeof( buf1)) == FALSE ) + return -1; + if( select == WINDOW_BUTTONTYPE_YES ) { + if( NPC_Util_GetStrFromStrWithDelim( buf1, "YESFOR", buf2, sizeof( buf2 )) == NULL) + return -1; + }else { + if( NPC_Util_GetStrFromStrWithDelim( buf1, "NOFOR", buf2, sizeof( buf2) ) == NULL) + return -1; + } + toID = atoi( buf2); + return toID; +} + +int NPC_getTitleMsg( int meindex, int toindex, char *arg, char *token, int title) +{ + char buf[NPC_UTIL_GETARGSTR_BUFSIZE], buf1[1024], buf2[256]; + memset( buf, 0, sizeof( buf)); + + if( getStringFromIndexWithDelim( arg, "PSYCHOMETRICS", 2, buf, sizeof( buf)) == FALSE ) + return -1; + //ȡһ + if( getStringFromIndexWithDelim( buf , "}", title, buf1, sizeof( buf1)) == FALSE ) + return FALSE; + if( NPC_Util_GetStrFromStrWithDelim( buf1, "TITLEMSG", buf2, sizeof( buf2 )) == NULL){ + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2 )) == NULL){ + return -1; + } + if( NPC_ActionPassCheck( meindex, toindex, buf2) == FALSE ) { + CHAR_talkToCli( toindex, meindex, "", CHAR_COLORYELLOW); + return -1; + } + if( Action_RunDoEventAction( meindex, toindex, buf1) == FALSE ){ + CHAR_talkToCli( toindex, meindex, "", CHAR_COLORYELLOW); + return -1; + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "ENDMSG", buf2, sizeof( buf2 )) == NULL){ + return -1; + } + sprintf( token, "%s", buf2); + return 2; + } + + sprintf( token, "%s", buf2); + return 1; +} +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_manorsman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_manorsman.c new file mode 100644 index 0000000..fbd9bca --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_manorsman.c @@ -0,0 +1,1529 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "handletime.h" +#include "npc_scheduleman.h" +#include "family.h" +#include "npc_manorsman.h" +#include "saacproto_cli.h" +#include "net.h" +#include "configfile.h" +#include "log.h" + +/* + * ׯ԰ PK ǼԱ + * + */ +#define MAX_MANORSMAN 22 +static int FMPK_ManorsmanList[MAX_MANORSMAN]={ +-1,-1,-1,-1,-1, +-1,-1,-1,-1,-1, +-1,-1,-1,-1,-1, +-1,-1,-1,-1,-1, +-1,-1 }; + +enum { + NPC_WORK_ID = CHAR_NPCWORKINT1 // ǼԱ ID, 0 ʼ + ,NPC_WORK_MANORID = CHAR_NPCWORKINT2 // ׯ԰ + ,NPC_WORK_CHALLENGEWAIT = CHAR_NPCWORKINT3 // սȴʱ + ,NPC_WORK_PEACEWAIT = CHAR_NPCWORKINT4 // սʱ + ,NPC_WORK_PREVLOOPTIME = CHAR_NPCWORKINT5 // ǰһδ Loop ʱ +#ifdef _NEW_MANOR_LAW + ,NPC_WORK_BETTLETIME = CHAR_NPCWORKINT6 // ¼ʱ +#endif +#ifdef _SUPER_FMPOINT + ,NPC_WORK_SUPERFMPOINT = CHAR_NPCWORKINT7 // ¼ +#endif +}; + +#define SCHEDULEFILEDIR "./Schedule/" + +#ifdef _FIX_FAMILY_PK_LIMIT // WON ADD սׯ԰ǰʮΪǰʮ +#define PK_LIMIT 30 +#endif + + +extern struct FM_POINTLIST fmpointlist; +extern void NPC_talkToFloor(int floor, int index1, int index2, char *data); +#ifdef _MANOR_PKRULE +extern struct FMS_DPTOP fmdptop; +#endif + +void NPC_ManorLoadPKSchedule(int meindex); // Load schedule from disk +#ifdef _NEW_MANOR_LAW +void SortManorSchedule(); +int SortManorScheduleMomentum(const void *indexa, const void *indexb); +extern int familyMemberIndex[FAMILY_MAXNUM][FAMILY_MAXMEMBER]; +int g_iSortManor; +#endif + +int NPC_getManorsmanListIndex( int ID) +{ + + if( ID < 0 || ID >= MAX_MANORSMAN ){ + return FMPK_ManorsmanList[ ID]; + } + return -1; +} +BOOL NPC_ManorSmanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int meid; + int a; + int super; + + if(getAllowManorPK() == 0){ + return TRUE; + } + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEMANORSCHEDULEMAN ); + + // + NPC_Util_GetArgStr(meindex, argstr, sizeof(argstr)); + meid = NPC_Util_GetNumFromStrWithDelim(argstr, "id" ); + + if ((meid<0) || (meid>=MAX_SCHEDULEMAN)) { + print("MANORSMAN init error: invalid ID(%d)\n",meid); + meid=0; + } + CHAR_setWorkInt(meindex, NPC_WORK_ID, meid); +#ifdef _SUPER_FMPOINT + super = NPC_Util_GetNumFromStrWithDelim(argstr, "super" ); + CHAR_setWorkInt(meindex, NPC_WORK_SUPERFMPOINT, super); +#endif + a = NPC_Util_GetNumFromStrWithDelim(argstr, "loop" ); + if ((a<100) || (a>10000)) a=1000; + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, a); + + a = NPC_Util_GetNumFromStrWithDelim(argstr, "manorid" ); + if ((a<1) || (a>MANORNUM)) {// CoolFish 2002/2/25 + print("MANORSMAN init error: invalid manor id(%d).", a); + a=1; + } + CHAR_setWorkInt(meindex, NPC_WORK_MANORID, a); + + a = NPC_Util_GetNumFromStrWithDelim(argstr, "challengewait"); + if ((a<1) || (a>259200)) { + // print("MANORSMAN init error: invalid challengewait(%d).",a); + a=259200; + } + +#ifdef _NOT_FMPK_WAIT + CHAR_setWorkInt(meindex, NPC_WORK_CHALLENGEWAIT, 0); + CHAR_setWorkInt(meindex, NPC_WORK_PEACEWAIT, 0); +#else + a = NPC_Util_GetNumFromStrWithDelim(argstr, "challengewait"); + if ((a<1) || (a>259200)) { + print("MANORSMAN init error: invalid challengewait(%d).",a); + a=259200; + } + CHAR_setWorkInt(meindex, NPC_WORK_CHALLENGEWAIT, a); + + + a = NPC_Util_GetNumFromStrWithDelim(argstr, "peacewait"); + if ((a<1) || (a>432000)) { + print("MANORSMAN init error: invalid peacewait(%d).",a); + a=604800; + } + CHAR_setWorkInt(meindex, NPC_WORK_PEACEWAIT, a); +#endif + NPC_ManorLoadPKSchedule(meindex); + + CHAR_setWorkInt(meindex, NPC_WORK_PREVLOOPTIME, NowTime.tv_sec); +#ifdef _NEW_MANOR_LAW + CHAR_setWorkInt(meindex,NPC_WORK_BETTLETIME,0); +#endif + + if( CHAR_getWorkInt( meindex, NPC_WORK_ID) >= 0 && + CHAR_getWorkInt( meindex, NPC_WORK_ID) 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + if(getAllowManorPK() == 0){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + -1, + -1, + "ׯ԰Ȩսսʸ뵽ս"); + return; + } + if(fmpks[fmpks_pos+1].flag==FMPKS_FLAG_CHALLENGE){ + fmpks[fmpks_pos+1].flag=FMPKS_FLAG_NONE; + } + switch (fmpks[fmpks_pos+1].flag) { + case FMPKS_FLAG_NONE: + // ûԼսʱս + saacproto_ACFMPointList_send(acfd); +#ifdef _MANOR_PKRULE + sprintf(buf, "ׯ԰Ȩսսʸ\n\n" + "һûӵׯ԰ļ\n" + #ifdef _FIX_FAMILY_PK_LIMIT // WON ADD սׯ԰ǰʮΪǰʮ + "бΪǰʮ\n" + #else + "бΪǰʮ\n" + #endif + "߹ʱ䣺ʮ\n\n" + "Դҽȷʸ"); +#else + sprintf(buf, "ׯ԰Ȩսսʸ\n\n" + "һûӵׯ԰ļ\n" + "ׯ԰\n\n" + "Դҽȷʸ"); +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_CHECKMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case FMPKS_FLAG_MANOR_PREPARE: + // ĿǰѾս׼ + { + int timeleft=fmpks[fmpks_pos+1].dueltime-NowTime.tv_sec; + int dd,hh,mm; + char buf2[4096]; + dd = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 86400; + hh = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 3600 - dd*24; + mm = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 60 - dd*24*60 - hh*60; + memset(buf2,0,sizeof(buf2)); + if (dd>0) sprintf(buf, " %d ", dd); else strcpy(buf, ""); + strcat(buf2, buf); + if (hh>0) sprintf(buf, " %d Сʱ", hh); else strcpy(buf, ""); + strcat(buf2, buf); + if (mm>0) sprintf(buf, " %d ", mm); else strcpy(buf, ""); + strcat(buf2, buf); + if (strlen(buf2)==0) + sprintf(buf, "ׯ԰Ȩս\n%s ֣ %s\n\n" + "ʼ׼볡", + fmpks[fmpks_pos+1].guest_name, + fmpks[fmpks_pos+1].host_name); + else + sprintf(buf, "ׯ԰Ȩս\n%s ֣ %s\n\n" + "Ԥ%sῪʼ", + fmpks[fmpks_pos+1].guest_name, + fmpks[fmpks_pos+1].host_name, + buf2); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + break; + case FMPKS_FLAG_MANOR_PEACE: + // սѾĺƽʱ + { + int timeleft=fmpks[fmpks_pos+1].dueltime-NowTime.tv_sec; + int dd,hh,mm; + char buf2[4096]; + dd = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 86400; + hh = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 3600 - dd*24; + mm = /*fmpks[fmpks_pos+1].dueltime*/ timeleft / 60 - dd*24*60 - hh*60; + strcpy(buf2,""); + if (dd>0) sprintf(buf, " %d ", dd); else strcpy(buf, ""); + strcat(buf2, buf); + if (hh>0) sprintf(buf, " %d Сʱ", hh); else strcpy(buf, ""); + strcat(buf2, buf); + if (mm>0) sprintf(buf, " %d ", mm); else strcpy(buf, ""); + strcat(buf2, buf); + + if (strlen(buf2)==0) + strcpy(buf, "Եȣ׼һ߹ݵı"); + else + sprintf(buf, "սʱڣҪ߹ݵĻ\n%s롣",buf2); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), buf); + } + break; + case FMPKS_FLAG_MANOR_BATTLEBEGIN: + // Ŀǰڽ߹ + sprintf(buf, "ׯ԰Ȩս\n%s ֣ %s\n\n" + "ޡ\nû˸Ͽɡ", + fmpks[fmpks_pos+1].guest_name, + fmpks[fmpks_pos+1].host_name); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case FMPKS_FLAG_MANOR_OTHERPLANET: + // ڱս + sprintf(buf, "ׯ԰Ȩս\n%s ֣ %s\n\n" + "ص %s ", + fmpks[fmpks_pos+1].guest_name, + fmpks[fmpks_pos+1].host_name, + fmpks[fmpks_pos+2].host_name); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + } +} +#else +void NPC_ManorSmanTalked(int meindex, int talkerindex, char *msg, int color) +{ + + char buf[4096]; + int fd; + int fmpks_pos = CHAR_getWorkInt(meindex,NPC_WORK_ID)*MAX_SCHEDULE; + int manorid = CHAR_getWorkInt(meindex,NPC_WORK_MANORID); + + if(CHAR_CHECKINDEX(meindex) == FALSE){ + printf("\nNPC_ManorSmanTalked error!(meindex:%d)",meindex); + return; + } + if(NPC_Util_CharDistance(meindex,talkerindex) > 2) return; + if(!NPC_Util_isFaceToFace(meindex,talkerindex,2)) return; + fd = getfdFromCharaIndex(talkerindex); + if(fd == -1) return; + if(getAllowManorPK() == 0){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + -1, + -1, + "ׯ԰Ȩսսʸ뵽涨·ս"); + return; + } + + if(fmpks[fmpks_pos+1].flag == FMPKS_FLAG_CHALLENGE) fmpks[fmpks_pos+1].flag = FMPKS_FLAG_NONE; + + switch(fmpks[fmpks_pos+1].flag){ + // ս 1800~2200 + case FMPKS_FLAG_NONE: + case FMPKS_FLAG_WAIT: + saacproto_ACFMPointList_send(acfd); + sprintf(buf,"ׯ԰Ȩսսʸ\n\n" + "һûׯ԰ļ\n" + "Ƹׯ԰\n" + "ԼսʱƵһ߻սʸ\n" + "ġͬȱ߻ʸ\n" + " OK ȷʸ񣬰NOۿս\n" + "ȷʱ仹ʣ%d", max(0, fmpks[fmpks_pos+1].dueltime - NowTime.tv_sec)); + lssproto_WN_send(fd,WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_YESNO,CHAR_WINDOWTYPE_CHECKMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX),buf); + if(fmpointlist.fm_momentum[manorid-1] <= -1){ + int hadfmindex,index; + char token[256]; + + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1],"|",5,token,sizeof(token)); + hadfmindex = atoi(token); + if(hadfmindex != -1){ + for(index=0;index= FAMILY_MAXNUM){ + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1],"|",6,token,sizeof(token)); + printf("\nNPC_ManorSmanTalked():save fm_momentum error(%d:%s)",hadfmindex,token); + break; + } + // ¼ʱׯ + else fmpointlist.fm_momentum[manorid-1] = fmdptop.fmMomentum[index]; + } + } + SortManorSchedule(); + break; + // ս׼ 2200~ȡսʸļ嵱ʱսʱ( 1800~2200 ֮) + case FMPKS_FLAG_MANOR_PREPARE: + // ĿǰѾս׼ + { + int timeleft = fmpks[fmpks_pos+1].dueltime - NowTime.tv_sec; + int mm,hh,dd; + char buf2[4096]; + + dd = timeleft / 86400; + hh = timeleft / 3600 - dd * 24; + mm = timeleft / 60 - dd * 24 * 60 - hh * 60; + memset(buf2,0,sizeof(buf2)); + if(dd > 0) sprintf(buf," %d ",dd); else strcpy(buf,""); + strcat(buf2,buf); + if(hh > 0) sprintf(buf," %d Сʱ",hh); else strcpy(buf,""); + strcat(buf2,buf); + if(mm > 0) sprintf(buf," %d ",mm); else strcpy(buf,""); + strcat(buf2,buf); + if(strlen(buf2) == 0) + sprintf(buf,"ׯ԰Ȩս\n%s ֣ %s\n\nʼ׼볡", + fmpks[fmpks_pos+1].guest_name,fmpks[fmpks_pos+1].host_name); + else + sprintf(buf,"ׯ԰Ȩս\n%s ֣ %s\n\nԤ%sῪʼ", + fmpks[fmpks_pos+1].guest_name,fmpks[fmpks_pos+1].host_name,buf2); + lssproto_WN_send(fd,WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex,CHAR_WORKOBJINDEX),buf); + } + break; + // սڼ׼, + case FMPKS_FLAG_MANOR_PEACE: + case FMPKS_FLAG_MANOR_PEACE_SAVE: + { + int timeleft = fmpks[fmpks_pos+1].dueltime-NowTime.tv_sec; + int dd,hh,mm; + char buf2[4096]; + dd = timeleft / 86400; + hh = timeleft / 3600 - dd*24; + mm = timeleft / 60 - dd*24*60 - hh*60; + memset(buf2,0,sizeof(buf2)); + if(dd > 0) sprintf(buf," %d ",dd); else strcpy(buf,""); + strcat(buf2,buf); + if(hh > 0) sprintf(buf," %d Сʱ",hh); else strcpy(buf,""); + strcat(buf2,buf); + if(mm > 0) sprintf(buf," %d ",mm); else strcpy(buf,""); + strcat(buf2,buf); + + if(strlen(buf2) == 0) strcpy(buf, "Եȣ׼һ߹ݵı"); + else sprintf(buf, "ڷսʱڣҪսĻ\n%s롣",buf2); + lssproto_WN_send(fd,WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX),buf); + } + break; + // ս + case FMPKS_FLAG_MANOR_BATTLEBEGIN: + sprintf(buf,"ׯ԰Ȩս\n%s ֣ %s\n\nޡ\nû˸Ͽɡ", + fmpks[fmpks_pos+1].guest_name,fmpks[fmpks_pos+1].host_name); + lssproto_WN_send(fd,WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX),buf); + break; + case FMPKS_FLAG_MANOR_OTHERPLANET: + // ڱս + sprintf(buf,"ׯ԰Ȩս\n%s ֣ %s\n\nص %s ", + fmpks[fmpks_pos+1].guest_name,fmpks[fmpks_pos+1].host_name,fmpks[fmpks_pos+2].host_name); + lssproto_WN_send(fd,WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex,CHAR_WORKOBJINDEX),buf); + break; + } +} +#endif + +void NPC_ManorSmanWindowTalked(int meindex, int talkerindex, int seqno, int select, char *data) +{ + + int fd, fmpks_pos, manorid, tkfmindex, tkfmdp; + char buf[4096],token[256]; + int hadfmindex; +//#ifndef _ACFMPK_LIST + char hadfmname[256]; +//#endif + int hadfmpopular; + + if (NPC_Util_CharDistance(meindex,talkerindex) > 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + if(getAllowManorPK() == 0){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + -1, + -1, + "ׯ԰Ȩսսʸ뵽涨·ս"); + return; + } + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + manorid = CHAR_getWorkInt(meindex, NPC_WORK_MANORID); + tkfmindex = CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI); + tkfmdp = CHAR_getWorkInt(talkerindex, CHAR_WORKFMDP); + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1], "|", 5, token, sizeof(token)); + hadfmindex = atoi(token); + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1], "|", 6, token, sizeof(token)); + strcpy(hadfmname, token); + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1], "|", 7, token, sizeof(token)); + hadfmpopular = atoi(token); + + switch (seqno){ + case CHAR_WINDOWTYPE_CHECKMAN_START: + if (select==WINDOW_BUTTONTYPE_YES){ +#ifdef _FMVER21 + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && +#else + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_MEMBER) && +#endif + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1)){ + if (hadfmindex != -1) { + if (hadfmindex-1 != tkfmindex){ + int check=0,i; +#ifdef _SUPER_FMPOINT + if(CHAR_getWorkInt(meindex, NPC_WORK_SUPERFMPOINT) == 1){ // ¼ʱ) + for (i=0; i= FAMILY_MAXNUM){ + printf("\nNPC_ManorSmanWindowTalked():find tkfmIndex error (%d)",tkfmindex); + } + else + // սƲׯƵľų,ս + //if(fmdptop.fmMomentum[index] < fmpointlist.fm_momentum[manorid-1]*0.9) won1 = 0; + if(fmdptop.fmMomentum[index] < 300000 ) won1 = 0; + //----------------------------------------- + #else + //----------------------------------------- + int i; + char won2[256]; + won1 = 0; + #ifdef _FIX_FAMILY_PK_LIMIT // WON ADD սׯ԰ǰʮΪǰʮ + for(i=0; i< PK_LIMIT; i++){ + #else + for(i=0; i<10; i++){ + #endif + if( getStringFromIndexWithDelim( fmdptop.topmemo[i], "|", 3, won2, sizeof(won2)) == FALSE ) { + print("err Get fmdptop.topmemo[%d] if FALSE !!\n", i); + break; + } + if( strcmp(CHAR_getChar(talkerindex, CHAR_FMNAME) ,won2) == 0 ){ + won1= 1; + break; + } + //----------------------------------------- + } + #endif + + if(won1 == 1){ + // WON END + #ifdef _NEW_MANOR_LAW + sprintf(buf,"ȷׯ԰սʸһ׼ʱ\n" + "ʱѯԵ֪ʣµʱ\n" + "ս´սڽһս\n" + "׼ڣڼڲս\n\n" + "ȷҪսׯ԰"); + #else + sprintf(buf,"ׯ԰սһ׼\n" + "ʱѯԵ֪ʣµʱ\n" + "ս᲻ʤжս\n" + "սڼ䲻ս\n\n" + "ȷҪսׯ԰"); + #endif +#else + if(tkfmdp >= hadfmpopular){ + sprintf(buf,"ׯ԰սһ׼\n" + "ʱѯԵ֪ʣµʱ\n" + "ս᲻ʤս\n" + "սڼ䲻ս\n\n" + "ȷҪսׯ԰"); +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_CHECKMAN_MAIN, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + else{ +#ifdef _NEW_MANOR_LAW + sprintf(buf, "ļδ 3000 ټ͡"); + // sprintf(buf, "ļδׯ԰Ƶľųɣټ͡"); +#else + #ifdef _MANOR_PKRULE + #ifdef _FIX_FAMILY_PK_LIMIT // WON ADD սׯ԰ǰʮΪǰʮ + sprintf(buf, "ļδǰʮ壬ټ͡"); + #else + sprintf(buf, "ļδǰʮ壬ټ͡"); + #endif + #else + sprintf(buf, "ļвս\n" + "ӵׯ԰ļ壬ټ͡"); + #endif +#endif + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + else if(check == 2){ + sprintf(buf, "ļսׯ԰\n" + "ѻɣ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + }else if(check == 3){ + sprintf(buf, "ׯ԰ׯ԰ļſսӴ!\n"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + else{ + sprintf(buf, "һֻӵһׯ԰\n" + "ׯ԰֮Ҫд\n" + "뵽У˳"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + else{ + sprintf(buf, "ׯ԰Ѿļม"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + else{ + sprintf(buf, "ڲûׯ԰壡\n" + "ֱȥǨͿӴ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + else{ + sprintf(buf, "ֻ峤սม"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } +#ifdef _NEW_MANOR_LAW + else if(select == WINDOW_BUTTONTYPE_NO){ + int i,index,manorindex; + char szMsg[3072]; + + sprintf(buf," ׯ԰ս\n ʱ \n"); + manorindex = CHAR_getWorkInt(meindex,NPC_WORK_MANORID) - 1; + // ͳս + for(i=0;i<10;i++){ + index = ManorSchedule[manorindex].iSort[i]; + if(ManorSchedule[manorindex].iFmIndex[index] != -1){ + sprintf(szMsg,"%2d %s\n",i+1,ManorSchedule[manorindex].szMemo[index]); + strcat(buf,szMsg); + } + } + lssproto_WN_send(fd,WINDOW_FMMESSAGETYPE_MANOR_SCHEDULE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex,CHAR_WORKOBJINDEX),buf); + } +#endif + break; + case CHAR_WINDOWTYPE_CHECKMAN_MAIN: + if (select==WINDOW_BUTTONTYPE_YES) { +#ifdef _FMVER21 + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && +#else + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_MEMBER) && +#endif + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1) && + (hadfmindex != -1) && + (hadfmindex - 1 != tkfmindex) +#ifndef _MANOR_PKRULE + && (tkfmdp >= hadfmpopular) +#endif + ){ +#ifndef _ACFMPK_LIST + struct tm tm1; +#endif + +#ifndef _NEW_MANOR_LAW +#ifndef _FMPOINT_PKTIME_SELECT + #ifdef _MANOR_PKRULE + time_t timep; + struct tm *p; + time(&timep); + p = gmtime(&timep); + if( p->tm_hour+8 > 24) + p->tm_hour = p->tm_hour-16; + else + p->tm_hour = p->tm_hour+8; + if(p->tm_hour<20 || p->tm_hour>23){ + sprintf(buf, "磲ϣԼսɣ"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + } + #endif +#endif + // WON ADD pkԼս + if( fmpks[fmpks_pos+1].flag != FMPKS_FLAG_NONE ){ + sprintf(buf, "ׯ԰ѾԼսม"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + return; + } +#endif + + + +#ifdef _ACFMPK_LIST +#ifdef _FMPOINT_PKTIME_SELECT + sprintf(buf, "2\nѡҪսʱ\n\n" + " 50V50죲\n" + " 50V50죲\n" + " 50V50죲\n" + ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_FAMILYMAN_PKTIME, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + return; +#else + + #ifndef _NEW_MANOR_LAW + NPC_ManorSavePKSchedule(meindex, talkerindex, 0); + sprintf( buf, "ׯ԰ս½ȷУᡣ"); + CHAR_talkToCli( talkerindex, meindex, buf, CHAR_COLORYELLOW); + #else + NPC_ManorAddToSchedule(meindex,talkerindex, 0); + #endif +#endif +#else + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + + fmpks[fmpks_pos+1].dueltime = CHAR_getWorkInt(meindex, NPC_WORK_CHALLENGEWAIT) + NowTime.tv_sec + - tm1.tm_min*60 + 1800; // Arminius 11.1 ijһ xx:30 + + fmpks[fmpks_pos+1].host_index = hadfmindex-1; + strcpy(fmpks[fmpks_pos+1].host_name, hadfmname); + fmpks[fmpks_pos+1].guest_index = tkfmindex; + strcpy(fmpks[fmpks_pos+1].guest_name, CHAR_getChar(talkerindex, CHAR_FMNAME)); + fmpks[fmpks_pos+1].prepare_time = 15; + fmpks[fmpks_pos+1].max_player = 50; + fmpks[fmpks_pos+1].win = -1; + fmpks[fmpks_pos+1].flag = FMPKS_FLAG_MANOR_OTHERPLANET; + strcpy(fmpks[fmpks_pos+2].host_name, getGameservername()); + + #ifndef _NEW_MANOR_LAW + NPC_ManorSavePKSchedule(meindex, talkerindex, 0); + sprintf(buf, "ׯ԰սѾ趨ɣú׼"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + #else + NPC_ManorAddToSchedule(meindex,talkerindex, 0); + #endif + fmpks[fmpks_pos+1].flag = FMPKS_FLAG_MANOR_PREPARE; +#endif + + } + } + break; +#ifdef _FMPOINT_PKTIME_SELECT + case CHAR_WINDOWTYPE_FAMILYMAN_PKTIME: + if (select==WINDOW_BUTTONTYPE_NONE) { +/* +#ifdef _FMPOINTPK_FOR_TWO +{ + int fmpointpk = 0; + int i; + struct tm tm1; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + int dueltime = NowTime.tv_sec - tm1.tm_min * 60 + 3600 * 24; + for( i=1; i<=MANORNUM; i++){ + fmpks_pos = i * MAX_SCHEDULE; + char tmpbuf[256]=""; + if (fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_BATTLEBEGIN + || fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_PREPARE + || fmpks[fmpks_pos + 1].flag == FMPKS_FLAG_MANOR_OTHERPLANET) + { + if(fmpks[fmpks_pos + 1].dueltime > dueltime){ + fmpointpk++; + if(fmpointpk>=2){ + sprintf(buf, "\nÿֻսͬʱ,Ԥ!"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + return; + } + } + } + } +} +#endif +*/ +#ifdef _SUPER_FMPOINT +{ + int i; + for (i=1; i<=MANORNUM; i++) { // ǷѾսׯ԰ + if(strcmp(fmpks[i*MAX_SCHEDULE+1].host_name, CHAR_getChar(talkerindex, CHAR_FMNAME))==0 + || strcmp(fmpks[i*MAX_SCHEDULE+1].guest_name, CHAR_getChar(talkerindex, CHAR_FMNAME))==0 + ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + "ļԼս֮,޷Լս!"); + return; + }else if(strcmp(fmpks[i*MAX_SCHEDULE+1].host_name, hadfmname)==0 + || strcmp(fmpks[i*MAX_SCHEDULE+1].guest_name, hadfmname)==0 + ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + "ԷļԼս,޷Լս!"); + return; + } + } +} +#endif +#ifdef _NEW_MANOR_LAW +{ + int index; + for(index=0;index= FAMILY_MAXNUM){ + printf("\nNPC_ManorSmanWindowTalked():find tkfmIndex error (%d)",tkfmindex); + return; + } + //else if(fmdptop.fmMomentum[index] < fmpointlist.fm_momentum[manorid-1]*0.9){ + else if(fmdptop.fmMomentum[index] < 100000){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + // "ļδׯ԰Ƶľųɣټ͡"); + "ļδﵽ1000ټ͡"); + return; + } +} +#endif +#ifdef _FM_POINT_APPLY_FAME +/* + if(CHAR_getInt(talkerindex, CHAR_FAME) < 50000){ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + "ĸС500޷սŶ"); + return; + }else{ + CHAR_setInt(talkerindex, CHAR_FAME, CHAR_getInt(talkerindex, CHAR_FAME) - 50000); + CHAR_talkToCli(talkerindex,-1,"۳500",CHAR_COLORYELLOW); + } + */ +#endif + int manorid, dueltime; + char msg[1024], n1[256], n2[256], n3[256]; + char token[256], hadfmname[256]; + int hadfmindex=0, hadfmpopular=0, tkfmindex=0; + int PkFlg=0; + + struct tm tm1; + + tkfmindex = CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI); + + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID) * MAX_SCHEDULE; + manorid = CHAR_getWorkInt(meindex, NPC_WORK_MANORID); + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + // սʱʱΪʱ,мʱΪ׼ʱ + + switch (atoi(data)){ + case 1: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * 20 ; + break; + case 2: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * 21; + break; + case 3: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * 22; + break; + case 4: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * 22; + break; + case 5: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * 22 + 1800; + break; + default: + dueltime = NowTime.tv_sec - tm1.tm_min * 60 + ((24 - tm1.tm_hour) * 3600) + 3600 * getFimalyPkTime(); + break; + } + +#ifdef _NEW_MANOR_LAW + NPC_ManorAddToSchedule(meindex,talkerindex, dueltime); +#else + // |-------------ȡ-------------| |--------ӵ0000ʱ-------| |սʱʱ()| + getStringFromIndexWithDelim( fmpointlist.pointlistarray[manorid-1], "|", 5, token, sizeof(token)); + hadfmindex = atoi( token); + getStringFromIndexWithDelim( fmpointlist.pointlistarray[manorid-1], "|", 7, token, sizeof(token)); + hadfmpopular = atoi( token); + getStringFromIndexWithDelim( fmpointlist.pointlistarray[manorid-1], "|", 6, token, sizeof(token)); + strcpy( hadfmname, token); + makeEscapeString( hadfmname, n1, sizeof(n1)); +#ifndef _NEW_MANOR_LAW + makeEscapeString( CHAR_getChar(talkerindex, CHAR_FMNAME), n2, sizeof(n2)); +#else + // ҳս߼ + int index = ManorSchedule[manorid-1].iSort[0]; + makeEscapeString(ManorSchedule[manorid-1].szFmName[index],n2,sizeof(n2)); +#endif + makeEscapeString( getGameservername(), n3, sizeof(n3)); + + sprintf(msg, "%d|%d|%s|%d|%s|%d|%d|%d|%s", + dueltime, hadfmindex-1, n1, tkfmindex, n2, 15, FreeFmPk(), FMPKS_FLAG_MANOR_OTHERPLANET, n3); + PkFlg = 1; + { + char buf1[256]; + sprintf( buf1,"%d", CHAR_getWorkInt( meindex, NPC_WORK_ID) ); + Logfmpk( + n1, hadfmindex-1, 0, + n2, tkfmindex, 0, + "", buf1, n3, 1); + } +#ifndef _NEW_MANOR_LAW + saacproto_ACSendFmPk_send( acfd, talkerindex, 0, CHAR_getWorkInt( meindex, NPC_WORK_ID), msg); +#else + // toindex òΪ -1 + saacproto_ACSendFmPk_send( acfd, -1, PkFlg, CHAR_getWorkInt( meindex, NPC_WORK_ID), msg); +#endif +#endif + } + break; +#endif + } +} + +void NPC_CleanPkList( int ti) +{ +// Terry fix ҪΪ-1Ϊ0 +/* fmpks[ ti+1 ].host_index = 0; + fmpks[ ti+1].guest_index=0; + fmpks[ ti].host_index=0; + fmpks[ ti].guest_index=0;*/ + fmpks[ ti+1 ].host_index = -1; + fmpks[ ti+1].guest_index=-1; + fmpks[ ti].host_index=-1; + fmpks[ ti].guest_index=-1; + + strcpy(fmpks[ ti+1].host_name,""); + strcpy(fmpks[ ti+1].guest_name,""); + strcpy(fmpks[ ti].host_name,""); + strcpy(fmpks[ ti].guest_name,""); + strcpy(fmpks[ ti+2].host_name,""); +} + +void NPC_ManorSmanLoop(int meindex) +{ + if(getAllowManorPK() == 0){ + return; + } + struct tm tm1; + int fmpks_pos; +#ifdef _NEW_MANOR_LAW + int iOffsetTime; +#endif + + if(CHAR_CHECKINDEX(meindex) == FALSE){ + printf("\nNPC_ManorSmanLoop error!(meindex:%d)",meindex); + return; + } + + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + switch (fmpks[fmpks_pos+1].flag) { + case FMPKS_FLAG_NONE: +#ifdef _NEW_MANOR_LAW + { + int hadfmindex,index,manorid; + char token[256]; + //ʱԿʼս + manorid = CHAR_getWorkInt(meindex,NPC_WORK_MANORID); + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1],"|",5,token,sizeof(token)); + hadfmindex = atoi(token); + if(hadfmindex != -1){ + for(index=0;index= FAMILY_MAXNUM){ + getStringFromIndexWithDelim(fmpointlist.pointlistarray[manorid-1],"|",6,token,sizeof(token)); + //printf("\nNPC_ManorSmanLoop():save fm_momentum error(%d:%s)",hadfmindex,token); + break; + } + // ¼ʱׯ + else fmpointlist.fm_momentum[manorid-1] = fmdptop.fmMomentum[index]; + // һ״̬ + fmpks[fmpks_pos+1].flag = FMPKS_FLAG_WAIT; + // սڹ4Сʱ(1800~2200) + fmpks[fmpks_pos+1].dueltime = NowTime.tv_sec + 3600 * 4; + NPC_ManorSavePKSchedule(meindex, -1, FMPKS_FLAG_WAIT,fmpks[fmpks_pos+1].dueltime,tm1); + } + SortManorSchedule(); + } +#endif + break; + +#ifdef _NEW_MANOR_LAW + // ս,Ѽ¼,ȴսų + case FMPKS_FLAG_WAIT: + { + int manorid,i,iPlayerNum = CHAR_getPlayerMaxNum(); + char szMsg[256]; + + manorid = CHAR_getWorkInt(meindex,NPC_WORK_MANORID); + // û,ƸıҪȥACҪʱ + fmpointlist.fm_inwar[manorid-1] = TRUE; + if(fmpks[fmpks_pos+1].dueltime <= NowTime.tv_sec){ + // սߵĻսȨ + int manorindex = CHAR_getWorkInt(meindex,NPC_WORK_MANORID) - 1; + int iNo1FmIndexSort = ManorSchedule[manorindex].iSort[0]; + int index = ManorSchedule[manorindex].iFmIndex[iNo1FmIndexSort],iFmIndex1,iCharindex; + char token[256],fmname[256]; + // ûս + if(index < 0){ + // ֱӽ뵽ս + fmpks[fmpks_pos+1].flag = FMPKS_FLAG_MANOR_BATTLEEND; + CHAR_setWorkInt(meindex,NPC_WORK_BETTLETIME,tm1.tm_mday); + // ֪ͨ + for(i=0;i= 0 && CHAR_getCharUse(iCharindex)){ + // ýǮ = * 5000 + int iAddGold = ((float)CHAR_getInt(iCharindex,CHAR_MOMENTUM)/100.0f) * 200.0f ; + int iGold = CHAR_getInt(iCharindex,CHAR_BANKGOLD),iMaxGold; + // ȷ + if(iGold + iAddGold > CHAR_MAXBANKGOLDHAVE){ + CHAR_setInt(iCharindex,CHAR_BANKGOLD,CHAR_MAXBANKGOLDHAVE); + // зŲ,ŵ + iAddGold = iGold + iAddGold - CHAR_MAXBANKGOLDHAVE; + iGold = CHAR_getInt(iCharindex,CHAR_GOLD); + iMaxGold = CHAR_getMaxHaveGold(iCharindex); + if(iGold + iAddGold > iMaxGold) CHAR_setInt(iCharindex,CHAR_GOLD,iMaxGold); + else CHAR_setInt(iCharindex,CHAR_GOLD,iGold + iAddGold); + LogFMPKGetMomey(CHAR_getChar(iCharindex,CHAR_FMNAME), + CHAR_getChar(iCharindex,CHAR_CDKEY), + CHAR_getChar(iCharindex,CHAR_NAME), + CHAR_getInt(iCharindex,CHAR_MOMENTUM),iAddGold,0); + } + else{ + CHAR_setInt(iCharindex,CHAR_BANKGOLD,iGold + iAddGold); + LogFMPKGetMomey(CHAR_getChar(iCharindex,CHAR_FMNAME), + CHAR_getChar(iCharindex,CHAR_CDKEY), + CHAR_getChar(iCharindex,CHAR_NAME), + CHAR_getInt(iCharindex,CHAR_MOMENTUM),iAddGold,1); + } + CHAR_talkToCli(iCharindex,-1,"!ػסׯ԰Ľѻĸ",CHAR_COLORRED); + // ĸ˼ƶҪ + CHAR_setInt(iCharindex,CHAR_MOMENTUM,0); + CHAR_talkToCli(iCharindex,-1,"ׯ԰ս˼ƹ",CHAR_COLORRED); + } + } + } + } + else{ + // սʱѹ,ѡսׯԼһʱ׼ + NPC_ManorSavePKSchedule(meindex,index,0,-1,ManorSchedule[manorindex].tm1[iNo1FmIndexSort]); + // ,ƸıҲȥACҪʱ + fmpointlist.fm_inwar[manorid-1] = FALSE; + // ֪ͨ + sprintf(szMsg,"%s սׯ԰ʸ",ManorSchedule[manorindex].szFmName[iNo1FmIndexSort]); + + for(i=0;i= FAMILY_MAXNUM){ + lssproto_WN_send(getfdFromCharaIndex(charaindex),WINDOW_MESSAGETYPE_MESSAGE,WINDOW_BUTTONTYPE_OK,CHAR_WINDOWTYPE_CHECKMAN_END, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX),"ǸҲļ"); + return; + } + // Ƚ + if(ManorSchedule[manorindex].iFmMomentum[index] < fmdptop.fmMomentum[i]){ + int fmpks_pos,iPlayerNum = CHAR_getPlayerMaxNum(); + char szMsg[256]; + + // ֪ͨ + fmpks_pos = CHAR_getWorkInt(meindex,NPC_WORK_ID) * MAX_SCHEDULE; + sprintf(szMsg,"%s 屻 %s 強սų",ManorSchedule[manorindex].szFmName[index],CHAR_getChar(charaindex,CHAR_FMNAME)); + for(i=0;i momentumB) ? -1:1; +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_mic.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_mic.c new file mode 100644 index 0000000..175ea95 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_mic.c @@ -0,0 +1,163 @@ +#include "version.h" +#include +#include + +#include "common.h" +#include "char_base.h" +#include "char.h" +#include "npcutil.h" +#include "npc_mic.h" +#include "saacproto_cli.h" +#include "lssproto_serv.h" +#include "battle.h" + +enum { + CHAR_WORK_FLOOR = CHAR_NPCWORKINT1, + CHAR_WORK_LX = CHAR_NPCWORKINT2, + CHAR_WORK_LY = CHAR_NPCWORKINT3, + CHAR_WORK_RX = CHAR_NPCWORKINT4, + CHAR_WORK_RY = CHAR_NPCWORKINT5, + CHAR_WORK_MODE = CHAR_NPCWORKINT6, + CHAR_WORK_TYPE = CHAR_NPCWORKINT7, + CHAR_WORK_WIND = CHAR_NPCWORKINT8, + CHAR_WORK_FMFL = CHAR_NPCWORKINT9, +}; + + +BOOL NPC_MicInit( int meindex ) +{ + int i; + int arg_param[8]; + char argstr[256]; + char buf[64]; + + + NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr)); + + + if( strstr(argstr, "FREE")!=NULL){ + CHAR_setWorkInt(meindex,CHAR_WORK_TYPE,1); + } + if( strstr(argstr, "WIND")!=NULL){ + CHAR_setWorkInt(meindex,CHAR_WORK_WIND,1); + } + + + if( strstr( argstr , "|" ) != NULL){ + for( i = 1; i < 9; i ++ ) { + if( getStringFromIndexWithDelim(argstr, "|" , i , buf,sizeof(buf) ) + == FALSE ) + { + printf( "NPC_MIC:ʡԲ\n"); + arg_param[i-1] = 0; + continue; + } + arg_param[i-1] = atoi(buf); + } + CHAR_setWorkInt( meindex, CHAR_WORK_FLOOR, arg_param[0]); + CHAR_setWorkInt( meindex, CHAR_WORK_LX, min( arg_param[1],arg_param[3])); + CHAR_setWorkInt( meindex, CHAR_WORK_LY, min( arg_param[2],arg_param[4])); + CHAR_setWorkInt( meindex, CHAR_WORK_RX, max( arg_param[1],arg_param[3])); + CHAR_setWorkInt( meindex, CHAR_WORK_RY, max( arg_param[2],arg_param[4])); + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEMIC); + + CHAR_setWorkInt( meindex, CHAR_WORK_FMFL, arg_param[7]); + return TRUE; + + }else{ + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEMIC); + CHAR_setWorkInt( meindex, CHAR_WORK_MODE, 1); + return TRUE; + } + + return FALSE; +} + +void NPC_MicTalked( int meindex , int talkerindex , char *msg ,int color ) +{ + + int i; + int playernum; + int x,y; + char message[4096]; + char buf[2048]; + + if( CHAR_getInt(talkerindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return; + if(CHAR_getWorkInt(meindex,CHAR_WORK_TYPE) == 0){ + if(NPC_Util_isFaceToChara(talkerindex,meindex,1 ) ==FALSE) return; + } + + snprintf( buf, sizeof( buf), "%s\n%s", + CHAR_getChar( talkerindex, CHAR_NAME), + msg); + + // Robin 0621 峤㲥 + print(" MIC_FL:%d ", CHAR_getWorkInt( meindex, CHAR_WORK_FMFL )); + if( CHAR_getWorkInt( meindex, CHAR_WORK_FMFL ) != 0 ) + { +#ifdef _FMVER21 + if( CHAR_getInt( talkerindex, CHAR_FMLEADERFLAG ) == FMMEMBER_LEADER) +#else + if( CHAR_getInt( talkerindex, CHAR_FMLEADERFLAG ) == FMMEMBER_MEMBER) +#endif + // && ( CHAR_getWorkInt( talkerindex, CHAR_WORKFMFLOOR) == CHAR_getWorkInt( meindex, CHAR_WORK_FLOOR ) ) ) + { + print(" FMLeaderTalk_send:%s,%d,%d,%s ", + CHAR_getChar( talkerindex, CHAR_FMNAME), CHAR_getInt( talkerindex, CHAR_FMINDEX), + CHAR_getWorkInt( talkerindex, CHAR_WORKFMINDEXI), buf); + + sprintf(message, "[峤㲥]%s", buf); + saacproto_ACFMAnnounce_send( acfd, + CHAR_getChar( talkerindex, CHAR_FMNAME), + CHAR_getInt( talkerindex, CHAR_FMINDEX), + CHAR_getWorkInt( talkerindex, CHAR_WORKFMINDEXI), + message, + color + ); + return; + } + + } + + makeEscapeString( buf, message, sizeof(buf)); + + playernum = CHAR_getPlayerMaxNum(); + + for( i = 0; i < playernum; i ++ ) { + BOOL flg = FALSE; + if( CHAR_getCharUse(i) == FALSE ) continue; + if( CHAR_getInt( i, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ) continue; + if( CHAR_getInt( i, CHAR_FLOOR) != CHAR_getWorkInt( meindex, CHAR_WORK_FLOOR) ){ + continue; + } + if( CHAR_getWorkInt( meindex, CHAR_WORK_MODE) == 0 ) { + x = CHAR_getInt( i, CHAR_X); + y = CHAR_getInt( i, CHAR_Y); + if( x >= CHAR_getWorkInt( meindex, CHAR_WORK_LX) && + x <= CHAR_getWorkInt( meindex, CHAR_WORK_RX) && + y >= CHAR_getWorkInt( meindex, CHAR_WORK_LY) && + y <= CHAR_getWorkInt( meindex, CHAR_WORK_RY)){ + flg = TRUE; + } + }else { + flg = TRUE; + } + if( flg) { + CHAR_talkToCli( i, talkerindex, msg, CHAR_COLORYELLOW); + if( CHAR_getWorkInt( meindex, CHAR_WORK_WIND) == 1 ) { + if( CHAR_getWorkInt( i, CHAR_WORKBATTLEMODE) + == BATTLE_CHARMODE_NONE) + { + int fd = getfdFromCharaIndex( i); + if( fd != -1 ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_MICMESSAGE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + message); + } + } + } + } + } +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_msg.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_msg.c new file mode 100644 index 0000000..4e02d4f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_msg.c @@ -0,0 +1,46 @@ +#include "version.h" +#define _NPC_MSG_C_ + +#include "char.h" +#include "char_base.h" +#include "npcutil.h" + + +/* + ئ 쫷ƥַʣ + Իؤ ƥέ·£ + + init , looked ı ɱ + + */ +BOOL NPC_MsgInit( int meindex ) +{ + //CHAR_setInt( meindex , CHAR_HP , 0 ); + + //CHAR_setInt( meindex , CHAR_MP , 0 ); + //CHAR_setInt( meindex , CHAR_MAXMP , 0 ); + + //CHAR_setInt( meindex , CHAR_STR , 0 ); + //CHAR_setInt( meindex , CHAR_TOUGH, 0 ); + + //CHAR_setInt( meindex , CHAR_LV , 0 ); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPETOWNPEOPLE ); + //CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); + //CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); /* ľئз */ + + return TRUE; +} + + +/* + * έľף۷ئʷ + */ +void NPC_MsgLooked( int meindex , int lookedindex ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, arg, sizeof( arg)); + CHAR_talkToCli( lookedindex , -1 , arg , CHAR_COLORWHITE ); + +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_newnpcman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_newnpcman.c new file mode 100644 index 0000000..444cbba --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_newnpcman.c @@ -0,0 +1,1276 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "enemy.h" +#include "log.h" +#include "battle.h" +#include "readmap.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "npc_newnpcman.h" +#include "pet.h" +#define NEWNPCMAN_STANDBY 5000 +#define NEWNPCMAN_WAITTIME 150 +enum { + WINDOW_START=1, + WINDOW_SELECT1, + WINDOW_SELECT2, + WINDOW_SELECT3, + WINDOW_SELECTLOSTPET, + WINDOW_DEFIND, + WINDOW_WARP, + WINDOW_END, + + NPC_PROGRAMEGINEER_START=1, + NPC_PROGRAMEGINEER_SELECT1, + NPC_PROGRAMEGINEER_SELECT2, + NPC_PROGRAMEGINEER_SELECT3, + NPC_PROGRAMEGINEER_SELECTLOSTPET, + NPC_PROGRAMEGINEER_DEFIND, + NPC_PROGRAMEGINEER_END, +}; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; +/* +char UserBBIs[12][256]={ + "С", "", "к", "", "Ƥ", "", + "С", "Ƥ", "ñ", "̷", "Ů", "" }; +char PetBBIs[4][256]={//³˹ ³ ³ ³ + "³˹-컢", "³-̻", "³-", "³-ƻ" }; + +int PlayerBBI[6*2][4]={ + { 100000, 100005, 100010, 100015 }, //С + { 100025, 100030, 100035, 100020 }, // + { 100055, 100050, 100045, 100040 }, //к + { 100060, 100065, 100070, 100075 }, // + { 100095, 100085, 100090, 100080 }, //Ƥ + { 100100, 100115, 100110, 100115 }, // + + { 100135, 100120, 100125, 100130 }, //С + { 100145, 100140, 100150, 100155 }, //Ƥ + { 100165, 100170, 100160, 100175 }, //ñ + { 100190, 100195, 100185, 100180 }, //̷ + { 100200, 100210, 100215, 100205 }, //Ů + { 100230, 100225, 100220, 100235 } // + }; +*/ + +static int checkPc[48][3]; + +static void NPC_NewNpcMan_selectWindow( int meindex, int toindex, int num, int flg); + +void NPC_reCheckMyPetUnusual( int meindex, int toindex);//쳣 + +BOOL CHECK_ReplacePET( int toindex); // +void NPC_reCheckItemPilenum( int meindex, int toindex);//ԭǹѵ +BOOL CHECK_ITEMEQUIT( int toindex);// +BOOL CHECK_PETBBI( int toindex);//ͼ +#ifdef _GET_MAGICAMOR +BOOL CHECK_MAGICAMOR( int toindex); +#endif +#ifdef _PET_LOSTPET +BOOL NPC_reFindMyLostPet( int meindex, int toindex, char *buf); +BOOL NPC_getLostPetString( int meindex, int toindex); +BOOL NPC_backupLostPetString( int toindex); +static char petstring[7][2048]={"","","","","","",""}; +#endif + +BOOL NPC_NewNpcManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + + { + int i; + for( i=0; i<48; i++){ + if( i == 0 ){ + checkPc[i][0]=30000; + checkPc[i][1]=30024; + checkPc[i][2]=100000; + }else{ + checkPc[i][0] = checkPc[i-1][0] + 25; + checkPc[i][1] = checkPc[i-1][1] + 25; + checkPc[i][2] = checkPc[i-1][2] + 5; + } +// print("ANDY checkPc:%d[%d,%d,%d]\n", i, checkPc[i][0], checkPc[i][1], checkPc[i][2]); + } + } + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_NEWNPCMAN); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} + +void NPC_NewNpcManLoop( int meindex) +{ + +} + +void NPC_NewNpcManTalked( int meindex , int talkerindex , char *msg , int color ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return; + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + if( CHAR_getInt( talkerindex, CHAR_BASEBASEIMAGENUMBER) != 101578 ){ + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_SELECT1, 0); + return; + } + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +static void NPC_NewNpcMan_selectWindow( int meindex, int toindex, int num, int flg) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + return; + } + + memset( token, 0, sizeof( token)); + switch( num) { + case WINDOW_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "START_MSG", token, sizeof( token) ) == NULL) { + return; + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_PROGRAMEGINEER_DEFIND; + break; + case WINDOW_SELECT1: + sprintf(token," ѡ" +#ifndef _NEW_ENGINEER + "\n 쳣" + "\n ͼš" +#endif + "\n " +#ifdef _PET_LOSTPET + "\n ʧ" +#endif +// "\n ԭǹѵ" +#ifdef _GET_MAGICAMOR + "\n " +#endif + + ); + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_PROGRAMEGINEER_SELECT2; + break; + case WINDOW_SELECT2: + switch( flg){ +#ifdef _NEW_ENGINEER + case 1:// + if( CHECK_ITEMEQUIT( toindex) == TRUE ){ + CHAR_talkToCli( toindex, -1, "!", CHAR_COLORYELLOW); + } + return; + break; + + case 2: +#ifdef _PET_LOSTPET + if( NPC_reFindMyLostPet( meindex, toindex, token) == FALSE ){ + CHAR_talkToCli( toindex, -1, "ϣ", CHAR_COLORYELLOW); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_PROGRAMEGINEER_SELECTLOSTPET; +#endif + break; +#ifdef _GET_MAGICAMOR + case 3: + if( CHECK_MAGICAMOR( toindex) == TRUE ){ + CHAR_talkToCli( toindex, -1, "!", CHAR_COLORYELLOW); + } + return; + break; + +#endif +#else + case 1://쳣 + NPC_reCheckMyPetUnusual( meindex, toindex); + CHAR_talkToCli( toindex, -1, "ϳ!", CHAR_COLORYELLOW); + return; + break; + case 2://ͼ + CHECK_PETBBI( toindex); + return; + break; + case 3:// + if( CHECK_ITEMEQUIT( toindex) == TRUE ){ + CHAR_talkToCli( toindex, -1, "!", CHAR_COLORYELLOW); + } + return; + break; + + case 4: +#ifdef _PET_LOSTPET + if( NPC_reFindMyLostPet( meindex, toindex, token) == FALSE ){ + CHAR_talkToCli( toindex, -1, "ϣ", CHAR_COLORYELLOW); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_PROGRAMEGINEER_SELECTLOSTPET; +#endif + break; + case 5: //ԭǹѵ +// NPC_reCheckItemPilenum( meindex, toindex); + return; + break; + +#endif + + } + break; +/* + case WINDOW_SELECT3: + { + int petnum, petindex; + petnum = atoi( data)-1; + if( petnum >= CHAR_MAXPETHAVE || petnum < 0 ) return; + petindex = CHAR_getCharPet( talker, petsel); + if( !CHAR_CHECKINDEX(petindex) ) return; + break; + } +*/ + case WINDOW_SELECTLOSTPET: +#ifdef _PET_LOSTPET + { + int ret, i, ti, ltime, cost; + Char ch; + char msgbuf[256]; + char petstring1[2048]; + + int havepetelement = CHAR_getCharPetElement( toindex); + ti = flg; + if( havepetelement < 0 ){ + CHAR_talkToCli( toindex, -1, "λ", CHAR_COLORYELLOW); + return; + } + if( NPC_getLostPetString( meindex, toindex) == FALSE ) { + CHAR_talkToCli( toindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + return; + } + + if( getStringFromIndexWithDelim( petstring[ti-1], "#", 2, petstring1, sizeof( petstring1)) == FALSE ){ + CHAR_talkToCli( toindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + return; + }else{ + char buf1[256]; + if( getStringFromIndexWithDelim( petstring[ti-1], "|", 6, buf1, sizeof( buf1)) == FALSE ) return; + ltime = atoi(buf1); + ltime = time( NULL) - ltime; + ltime = ltime/(60*60*24); + if( getStringFromIndexWithDelim( petstring[ti-1], "|", 4, buf1, sizeof( buf1)) == FALSE ) return; + cost = atoi( buf1); + + cost = cost + (ltime*10000); + + if( CHAR_getInt( toindex, CHAR_GOLD) < cost ) { + sprintf( buf1, "Ѽķ%d죬%dʯҲſء", ltime, cost); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); + return; + } + } + + + ret = CHAR_makePetFromStringToArg( petstring1, &ch, -2); + strcpy( petstring[ti-1], ""); + if( ret ) { + char buf1[256]; + int petindex = PET_initCharOneArray( &ch ); + if( !CHAR_CHECKINDEX( petindex) ){ + CHAR_talkToCli( toindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + return; + } + print("ANDY petindex:%d[%s]\n", petindex, CHAR_getChar( petindex, CHAR_NAME) ); + + CHAR_complianceParameter( petindex ); + CHAR_setInt( petindex, CHAR_HP, CHAR_getWorkInt( petindex, CHAR_WORKMAXHP)); + CHAR_setWorkInt( petindex, CHAR_WORKPLAYERINDEX, toindex); + CHAR_setCharPet( toindex, havepetelement, petindex); + CHAR_setChar( petindex, CHAR_OWNERCDKEY, + CHAR_getChar( toindex, CHAR_CDKEY)); + CHAR_setChar( petindex, CHAR_OWNERCHARANAME, + CHAR_getChar( toindex, CHAR_NAME)); + + if( NPC_backupLostPetString( toindex) == FALSE ){ + print("ANDY err backup petstring !!\n"); + return; + } + + sprintf( buf1, "LostPGet:%d", cost); + LogPet( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + buf1, + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + sprintf( buf1, "ȡ%s", CHAR_getUseName( petindex)); + CHAR_talkToCli( toindex, meindex, buf1, CHAR_COLORYELLOW); + for( i = 0; i < CHAR_MAXPETHAVE; i++){ + int petindex = CHAR_getCharPet( toindex, i); + if( !CHAR_CHECKINDEX( petindex) ) + continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( toindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( toindex, msgbuf ); + } + CHAR_DelGold( toindex, cost); + }else{ + CHAR_talkToCli( toindex, -1, "ȡʧܣ", CHAR_COLORYELLOW); + return; + } + return; + } +#endif + return; + break; + case WINDOW_DEFIND: + { + int i; + int face = CHAR_getInt( toindex, CHAR_FACEIMAGENUMBER); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CHECK_MSG", token, sizeof( token) ) == NULL) { + return; + } + for( i=0; i<48; i++){ + if( face >= checkPc[i][0] && face < checkPc[i][1] ) + break; + } + if( i >= 48 )return; + CHAR_setWorkInt( toindex, CHAR_WORKNPCMETAMO, meindex); + CHAR_setInt( toindex, CHAR_BASEIMAGENUMBER, checkPc[i][2]); + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( toindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_PROGRAMEGINEER_END; + } + break; + case WINDOW_END: + { + CHAR_setWorkInt( toindex, CHAR_WORKNPCMETAMO, -1); + CHAR_setInt( toindex, CHAR_BASEBASEIMAGENUMBER, + CHAR_getInt( toindex, CHAR_BASEIMAGENUMBER) ); + + CHAR_complianceParameter( toindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( toindex , CHAR_WORKOBJINDEX )); + CHAR_send_P_StatusString( toindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); + return; + } + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_NewNpcManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO){ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + CHAR_setWorkInt( talkerindex, CHAR_WORKNPCMETAMO, -1); + return; + } + switch( seqno) { + case NPC_TRANSERMAN_START: + break; + case NPC_PROGRAMEGINEER_SELECT1: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_SELECT1, atoi( data)); + break; + case NPC_PROGRAMEGINEER_SELECT2: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_SELECT2, atoi( data)); + break; + case NPC_PROGRAMEGINEER_SELECT3: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_SELECT3, atoi( data)); + break; + case NPC_PROGRAMEGINEER_SELECTLOSTPET: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_SELECTLOSTPET, atoi( data)); + break; + case NPC_PROGRAMEGINEER_DEFIND: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_DEFIND, atoi( data)); + break; + case NPC_PROGRAMEGINEER_END: + NPC_NewNpcMan_selectWindow( meindex, talkerindex, WINDOW_END, atoi( data)); + break; + } +} + +BOOL CHECK_ITEMEQUIT( int toindex) +{ + int i, itemindex; + char token[256]; +#ifdef _NEW_ITEM_ + int maxitem = CheckCharMaxItem( toindex); +#else + int maxitem = CHAR_MAXITEMHAVE; +#endif + for (i = CHAR_STARTITEMARRAY; i < maxitem; i ++) { + itemindex = CHAR_getItemIndex( toindex, i); + if( ITEM_getInt( itemindex, ITEM_ID) == 1292 ){ + CHAR_DelItem( toindex, i); + itemindex = -1; + itemindex = ITEM_makeItemAndRegist( 1292); + if( !ITEM_CHECKINDEX( itemindex) ){ + }else{ + int ret = CHAR_addItemSpecificItemIndex( toindex, itemindex); + if( ret < 0 || ret >= maxitem ) { + ITEM_endExistItemsOne( itemindex); + continue; + } + sprintf( token,"õ%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( toindex, ret); + continue; + } + } +#ifdef _TAKE_ITEMDAMAGE + if( ITEM_getInt( itemindex, ITEM_ID) == 1292 && + ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE) > 0 ){ + + ITEM_setInt( itemindex, ITEM_MAXDAMAGECRUSHE, 0); + ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, 0); + sprintf(token,"%s𻵶", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_sendItemDataOne( toindex, i); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + } +#endif + } +#ifdef _TAKE_ITEMDAMAGE + // ķŵ + for (i = 0; i < CHAR_MAXPOOLITEMHAVE; i++) { + if( ITEM_getInt( itemindex, ITEM_ID) == 1292 && + ITEM_getInt( itemindex, ITEM_MAXDAMAGECRUSHE) > 0 ){ + + ITEM_setInt( itemindex, ITEM_MAXDAMAGECRUSHE, 0); + ITEM_setInt( itemindex, ITEM_DAMAGECRUSHE, 0); + sprintf(token,"ķŵ%s𻵶", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + } + } +#endif + return TRUE; +} + +#ifdef _GET_MAGICAMOR +BOOL CHECK_MAGICAMOR( int toindex) +{ + int i, itemindex; + char token[256]; + int flg=0; + if(NPC_EventCheckFlg( toindex, 71) == FALSE){ + CHAR_talkToCli( toindex, -1, "!", CHAR_COLORRED); + return TRUE; + } +#ifdef _NEW_ITEM_ + int maxitem = CheckCharMaxItem( toindex); +#else + int maxitem = CHAR_MAXITEMHAVE; +#endif + for (i = CHAR_STARTITEMARRAY; i < maxitem; i ++) { + itemindex = CHAR_getItemIndex( toindex, i); + if( ITEM_getInt( itemindex, ITEM_ID) == 1292 ){ + flg = 1; + } + } + if (flg==0){ + itemindex = -1; + itemindex = ITEM_makeItemAndRegist( 1292); + if( !ITEM_CHECKINDEX( itemindex) ){ + }else{ + int ret = CHAR_addItemSpecificItemIndex( toindex, itemindex); + if( ret < 0 || ret >= maxitem ) { + CHAR_talkToCli( toindex, -1, "ϵ߿λ!", CHAR_COLORRED); + ITEM_endExistItemsOne( itemindex); + } + sprintf( token,"õ%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW ); + CHAR_sendItemDataOne( toindex, ret); + } + } + + return TRUE; +} + +#endif + + +BOOL CHECK_PETBBI( int toindex) +{ + int i, petindex, PetID; + BOOL Finds = FALSE; + char token[256]; + for( i=0; i < CHAR_MAXPETHAVE; i++) { + int parry, array, PetBBI; + petindex = CHAR_getCharPet( toindex, i); + if( !CHAR_CHECKINDEX( petindex) ) continue; + PetID = CHAR_getInt( petindex, CHAR_PETID); + array = ENEMY_getEnemyArrayFromTempNo( PetID); + if( !ENEMY_CHECKINDEX( array)) continue; + parry = ENEMYTEMP_getEnemyTempArray( array); + PetBBI = ENEMYTEMP_getInt( parry, E_T_IMGNUMBER); + + if( CHAR_getInt( petindex, CHAR_BASEBASEIMAGENUMBER) != PetBBI || + CHAR_getInt( petindex, CHAR_BASEIMAGENUMBER) != PetBBI ){ + CHAR_setInt( petindex, CHAR_BASEBASEIMAGENUMBER, PetBBI); + CHAR_setInt( petindex, CHAR_BASEIMAGENUMBER, PetBBI); + sprintf( token, "%sͼ", CHAR_getUseName( petindex)); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORYELLOW); + Finds = TRUE; + } + CHAR_setInt( petindex, CHAR_EARTHAT, ENEMYTEMP_getInt( parry, E_T_EARTHAT) ); + CHAR_setInt( petindex, CHAR_WATERAT, ENEMYTEMP_getInt( parry, E_T_WATERAT) ); + CHAR_setInt( petindex, CHAR_FIREAT, ENEMYTEMP_getInt( parry, E_T_FIREAT) ); + CHAR_setInt( petindex, CHAR_WINDAT, ENEMYTEMP_getInt( parry, E_T_WINDAT) ); + } + for( i=0; i %s (%s:%s)(file:%s %d) !! \n", + petID, PetNAME, CHAR_getUseName( toindex), + CHAR_getChar( toindex, CHAR_CDKEY), __FILE__, __LINE__ ); + } + } + + for( i=0; i 0 )continue; + + if( i == CHAR_getInt( toindex, CHAR_DEFAULTPET) ) { + int fd = getfdFromCharaIndex( toindex); + CHAR_setInt( toindex, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + + snprintf( szPet,sizeof( szPet), "%s", CHAR_getUseName( petindex) ); + CHAR_talkToCli( toindex, -1, szPet, CHAR_COLORYELLOW); + LogPet( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "TenseiDel", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + + Finds = TRUE; + CHAR_setCharPet( toindex, i, -1); + CHAR_endCharOneArray( petindex ); + + array = ENEMY_getEnemyArrayFromTempNo( 1133); + if( !ENEMY_CHECKINDEX( array)) continue; + ret = ENEMY_createPetFromEnemyIndex( toindex, array); + if( !CHAR_CHECKINDEX( ret ) ) continue; + + snprintf( szPet, sizeof( szPet), "õ%s", CHAR_getUseName( ret) ); + CHAR_talkToCli( toindex, -1, szPet, CHAR_COLORWHITE); + + LogPet( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + CHAR_getChar( ret, CHAR_NAME), + CHAR_getInt( ret, CHAR_LV), + "TenseiGet", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + CHAR_getChar( ret, CHAR_UNIQUECODE) + ); + + } + + for( i=0; i 1 ){ + int itemID, pilenum=1, newindex; + itemID = ITEM_getInt( itemindex, ITEM_ID); + if( !ITEM_CHECKITEMTABLE( itemID) ) continue; + pilenum = ITEM_getInt( itemindex, ITEM_USEPILENUMS); + while( pilenum > 1 ){ + int ti = CHAR_findEmptyItemBox( toindex); + if( ti == -1 ){ + CHAR_sendItemDataOne( toindex, i); + CHAR_talkToCli( toindex, -1, "λ", CHAR_COLORYELLOW); + return; + } + newindex = ITEM_makeItemAndRegist( itemID); + if( !ITEM_CHECKINDEX( newindex) ) break; + + + CHAR_setItemIndex( toindex , ti, newindex); + CHAR_sendItemDataOne( toindex, ti); + pilenum--; + ITEM_setInt( itemindex, ITEM_USEPILENUMS, pilenum); + } + if( ITEM_getInt( itemindex, ITEM_CANBEPILE) != ITEMTBL_getInt( itemID, ITEM_CANBEPILE) ) + ITEM_setInt( itemindex, ITEM_CANBEPILE, ITEMTBL_getInt( itemID, ITEM_CANBEPILE) ); + CHAR_sendItemDataOne( toindex, i); + } + } + CHAR_talkToCli( toindex, -1, "ǹϡ", CHAR_COLORYELLOW); +} + +#ifdef _PET_LOSTPET +BOOL NPC_reFindMyLostPet( int meindex, int toindex, char *buf) +{ + //0 1 2 + FILE *fp = NULL; + char *CdKey=NULL; + int lv=0, cost, ltime, count=0, i, type; + char filename[256], line[2048], buf1[256]; + char petname[256], typebuf[256]; + char buf2[10][256]={"\n","\n","\n","\n","\n", + "\n","\n","\n","\n","\n" }; + CdKey = CHAR_getChar( toindex, CHAR_CDKEY ); + if( CdKey == "\0" ) return FALSE; + sprintf( filename, "lostpet/%s.txt", CdKey); + strcpy( buf, "==ʧ¼==\n"); + if( (fp=fopen( filename, "r")) == NULL ) return FALSE; + + while( fgets( line , sizeof( line ) , fp ) && count < 7){ + if( line == NULL ) continue; + if( getStringFromIndexWithDelim( line, "|", 1, buf1, sizeof( buf1)) == FALSE ) continue; + if( strcmp( CHAR_getChar( toindex, CHAR_CDKEY ), buf1 )) continue; + if( getStringFromIndexWithDelim( line, "|", 6, buf1, sizeof( buf1)) == FALSE ) continue; + ltime = atoi(buf1); + ltime = time( NULL) - ltime; + ltime = ltime/(60*60*24); + if( ltime > 14 ) continue;//14 + + if( getStringFromIndexWithDelim( line, "|", 2, petname, sizeof( petname)) == FALSE ) continue; + if( getStringFromIndexWithDelim( line, "|", 3, buf1, sizeof( buf1)) == FALSE ) continue; + lv = atoi( buf1); + if( getStringFromIndexWithDelim( line, "|", 4, buf1, sizeof( buf1)) == FALSE ) continue; + cost = atoi( buf1); + + if( getStringFromIndexWithDelim( line, "#", 3, buf1, sizeof( buf1)) == FALSE ) continue; + type = atoi( buf1); + if( type == 1 ){ + strcpy( typebuf, ""); + }else if( type == 2 ){ + strcpy( typebuf, ""); + }else{ + strcpy( typebuf, ""); + } + + sprintf( buf2[count++], "%s LV:%dʯ:%d(%d%s)\n", petname, lv, cost, ltime, typebuf); + } + fclose( fp); + for( i=0; i<7; i++){ + strcat( buf, buf2[i]); + } + if( count == 0 ) return FALSE; + return TRUE; +} + +BOOL NPC_getLostPetString( int meindex, int toindex) +{ + FILE *fp = NULL; + char *CdKey=NULL; + int count=0, i, ltime; + char filename[256], line[2048], buf1[256]; + + for( i=0; i<7; i++) + strcpy( petstring[i], ""); + + CdKey = CHAR_getChar( toindex, CHAR_CDKEY ); + if( CdKey == "\0" ) return FALSE; + sprintf( filename, "lostpet/%s.txt", CdKey); + if( (fp=fopen( filename, "r")) == NULL ) return FALSE; + + while( fgets( line , sizeof( line ) , fp ) && count < 7){ + if(strlen( line) <= 0 ) continue; +// if( getStringFromIndexWithDelim( line, "#", 2, buf1, sizeof( buf1)) == FALSE ) return FALSE; +// Terry fix ȡʱûжʱ 2004/09/22 + if(getStringFromIndexWithDelim(line,"|",6,buf1,sizeof(buf1)) == FALSE) continue; + ltime = atoi(buf1); + ltime = time( NULL) - ltime; + ltime = ltime/(60*60*24); + if(ltime > 14) continue;//14 +// Terry end + strcpy( petstring[count++], line); + } + + fclose( fp); + return TRUE; +} + +BOOL NPC_backupLostPetString( int toindex) +{ + FILE *fp = NULL; + char *CdKey=NULL; + int i, count=0; + char filename[256]; + + CdKey = CHAR_getChar( toindex, CHAR_CDKEY ); + if( CdKey == "\0" ) return FALSE; + sprintf( filename, "lostpet/%s.txt", CdKey); + if( (fp=fopen( filename, "w")) == NULL ) return FALSE; + + for( i=0; i<7; i++){ + if( strlen( petstring[i]) <= 0 ) continue; + fprintf( fp, "%s", petstring[i]); + count++; + } + fclose( fp); + + if( count == 0 ) + remove( filename); + + return TRUE; +} + +/* + + +#ifdef _NEW_WARPMAN +#include "npc_newnpcman.h" +#define NEWNPCMAN_STANDBY 5000 +#define NEWNPCMAN_WAITTIME 150 + +enum{ +NPC_NEWNPCMAN_START=21, +NPC_NEWNPCMAN_MAN, +NPC_NEWNPCMAN_END, +}; + +enum { + NEWNPC_START = 1, + NEWNPC_MAN, + NEWNPC_END, +}; + +enum { + NPC_WORK_INDEX = CHAR_NPCWORKINT1, + NPC_WORK_WORKTYPE = CHAR_NPCWORKINT2, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT3, +}; + +BOOL CHECK_YEARPET( int toindex); +static void NPC_NewNpcMan_selectWindow( int meindex, int toindex, int num, int flg); +int NPC_NewNpcManDelPet(int meindex,int talker, int petsel); +BOOL NPC_NewNpcManAddPet(int meindex, int talker, int petid); + +//ɻֳ +static int Re_Pet[4]; +// shan +char uStr[128]=""; + +BOOL NPC_NewNpcManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[256],buf2[256]; + int k=1; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL) { + print("GambleBank:GetArgStrErr"); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "REPET", buf1, sizeof( buf1)) == NULL ) { + return FALSE; + } + + while( getStringFromIndexWithDelim(buf1, ",", k, buf2, sizeof(buf2)) != FALSE ) { + Re_Pet[k-1] = atoi( buf2); + if( Re_Pet[k-1] < 0 ) + return FALSE; + k++; + if( (k-1) >= arraysizeof( Re_Pet) ) + break; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_NEWNPCMAN ); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return TRUE; +} + +void NPC_NewNpcManLoop( int meindex) +{ + //test + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[256],buf2[256]; + int k=1; + + int fulltime = NEWNPCMAN_WAITTIME; + if( (CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + fulltime) > NowTime.tv_sec ) + return; + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + + //test + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL) { + print("GambleBank:GetArgStrErr"); + return; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "REPET", buf1, sizeof( buf1)) == NULL ) { + return; + } + + while( getStringFromIndexWithDelim(buf1, ",", k, buf2, sizeof(buf2)) != FALSE ) { + Re_Pet[k-1] = atoi( buf2); + if( Re_Pet[k-1] < 0 ) + return; + k++; + if( (k-1) >= arraysizeof( Re_Pet) ) + break; + } + //test end +} + +void NPC_NewNpcManTalked( int meindex , int talkerindex , char *msg , int color ) +{ + char buf1[256]; + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + if( CHAR_getWorkInt( meindex , NPC_WORK_INDEX) >= 0 ) { + sprintf( buf1,"%s","æأ"); + print("\n NPC_WORK_INDEX = %d ", CHAR_getWorkInt( meindex , NPC_WORK_INDEX)); + CHAR_talkToCli( talkerindex, meindex, buf1, CHAR_COLORYELLOW); + return; + }else { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, talkerindex); + print("\n start : NPC_WORK_INDEX = talkerindex"); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + NPC_NewNpcMan_selectWindow( meindex, talkerindex, NEWNPC_START, 0); + } +} + +static void NPC_NewNpcMan_selectWindow( int meindex, int toindex, int num, int flg) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + char token_str[][56]={"ERROR_MSG","START_MSG","END_MSG","ERROR_ALL"}; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + int petno = 718, petid =1479; + int type_str = 0; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL) { + print("GambleBank:GetArgStrErr"); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return ; + } + + if( CHAR_getWorkInt( meindex , NPC_WORK_INDEX) != toindex ) { + sprintf( token,"%s","æأ"); + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + return; + } + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + print("\n switch( num=%d)", num); + switch( num) { + case NEWNPC_START: + type_str = 1; + buttontype = WINDOW_BUTTONTYPE_OKCANCEL; + windowno = NPC_NEWNPCMAN_START; + break; + + case NEWNPC_MAN: + { + if( CHECK_YEARPET( toindex) == TRUE ) { + type_str = 1; + windowtype = WINDOW_MESSAGETYPE_PETSELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_NEWNPCMAN_MAN; + }else { + type_str = 3; + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = NPC_NEWNPCMAN_END; + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + } + } + break; + + case NEWNPC_END: + type_str = 0; + if( flg <= CHAR_MAXPETHAVE && flg >= 0 ) { + petno = flg; + + if( ( petid = NPC_NewNpcManDelPet( meindex, toindex, petno)) >= 0 ) { + if( NPC_NewNpcManAddPet( meindex, toindex, petid) == TRUE ) { + type_str = 2; + } + } + } + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = NPC_NEWNPCMAN_END; + + break; + } + + if(NPC_Util_GetStrFromStrWithDelim( npcarg, token_str[ type_str], token,sizeof( token) ) == NULL) { + print("token_str[%d] err !", type_str); + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_NewNpcManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } + + print("\n seqno=%d, select=%d", seqno, select); + switch( seqno) { + case NPC_NEWNPCMAN_START: + if( select != WINDOW_BUTTONTYPE_YES && select != WINDOW_BUTTONTYPE_OK ) { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + return; + } + if(select==WINDOW_BUTTONTYPE_CANCEL) { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + }else { + NPC_NewNpcMan_selectWindow( meindex, talkerindex, NEWNPC_MAN, -1); + } + break; + + case NPC_NEWNPCMAN_MAN: + { + int petnum; + petnum = atoi( data)-1; + + print("\n petnum=%d", petnum); + if(select==WINDOW_BUTTONTYPE_CANCEL) { + CHAR_setWorkInt( meindex , NPC_WORK_INDEX, -1); + }else { + NPC_NewNpcMan_selectWindow( meindex, talkerindex, NEWNPC_END, petnum); + } + } + break; + + case NPC_NEWNPCMAN_END: + break; + } +} + +int NPC_NewNpcManDelPet(int meindex,int talker, int petsel) +{ + int defpet; + int fd = getfdFromCharaIndex( talker ); + char msgbuf[64], szPet[128]; + int k=0; + int petindex=-1; + + petindex = CHAR_getCharPet( talker, petsel); + if( !CHAR_CHECKINDEX(petindex) ) + return -1; + + for( k=0;k +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_newvipshop.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" + +//صشøнڽ"ʦ" +#ifdef _NEW_VIP_SHOP +enum { + WINDOW_START=1, + WINDOW_SELECT, + WINDOW_PREV, + WINDOW_NEXT, + WINDOW_WARP, + WINDOW_END, +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_WORK_MAXPAGE = CHAR_NPCWORKINT2, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +#define STANDBYTIME 50 + +static void NPC_NewVipShop_selectWindow( int meindex, int toindex, int num,int select); +BOOL NewVipShop_GetMenuStr( int meindex, int toindex, char *npcarg, char *token, int index ); +int NewVipShop_ShowMenulist( char *npcarg ); + + +BOOL NPC_NewVipShopInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TRANSERMANS); + + CHAR_setWorkInt( meindex, NPC_WORK_MAXPAGE, NewVipShop_ShowMenulist(npcarg)); + + + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_NewVipShopTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +void NPC_NewVipShopWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data) +{ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( seqno) { + case NPC_TRANSERMAN_START: + break; + case NPC_TRANSERMAN_SELECT: + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_SELECT, atoi( data)); + break; + case NPC_TRANSERMAN_WARP: + if( select == WINDOW_BUTTONTYPE_CANCEL ) + return; + if( select == WINDOW_BUTTONTYPE_NEXT ) + { + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_NEXT, atoi( data)); + return; + } + if( select == WINDOW_BUTTONTYPE_PREV ) + { + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_PREV, atoi( data)); + return; + } + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_WARP, atoi( data)); + break; + case NPC_TRANSERMAN_END: + NPC_NewVipShop_selectWindow( meindex, talkerindex, WINDOW_END, atoi( data)); + break; + } + +} + +static void NPC_NewVipShop_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + char buf1[256]; + char buf2[256]; + char buf3[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + static int select1; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("NewVipShop_MAN: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + + switch( num) { + case WINDOW_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "START_MSG", token, sizeof( token) ) == NULL) { + print("NewVipShop Get START_MSG ERROR !"); + return; + } +#ifdef _OTHER_SAAC_LINK + if(osfd == -1){ + OtherSaacConnect(); + CHAR_talkToCli( toindex, -1, "δ!", CHAR_COLORRED ); + }else{ + saacproto_QueryPoint_send( osfd, getfdFromCharaIndex( toindex ), CHAR_getChar(toindex, CHAR_CDKEY)); + } +#else + saacproto_QueryPoint_send( acfd, getfdFromCharaIndex( toindex ), CHAR_getChar(toindex, CHAR_CDKEY)); +#endif + CHAR_talkToCli(toindex, -1, "ȡػرУԺ...", CHAR_COLORRED); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, WINDOW_START); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_TRANSERMAN_SELECT; + break; + case WINDOW_SELECT: + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, 0); + + if( NewVipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "NewVipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)>1) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_NEXT: + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)<=CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)) + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)+1); + if( NewVipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "NewVipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)+1==CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_PREV: + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)>0) + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)-1); + if( NewVipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "NewVipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)==0) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + else + buttontype = WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_WARP: + select1=CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)*7+select; + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, select1); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "END_MSG", buf1, sizeof( buf1) ) == NULL) { + print("NewVipShop Get START_MSG ERROR !"); + return; + } + if(getStringFromIndexWithDelim( npcarg,"}",select1, buf2, sizeof( buf2)) != FALSE) + NPC_Util_GetStrFromStrWithDelim( buf2, "MenuStr", buf3, sizeof( buf3)); + sprintf( token, "\n%s\n\n %s\n",buf1, buf3); + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_TRANSERMAN_END; + break; + case WINDOW_END: + ActionNpc_CheckMenuFree( meindex, toindex, npcarg, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)); + return; + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + + +BOOL NewVipShop_GetMenuStr( int meindex, int toindex, char *npcarg, char *token,int index ) +{ + char buf1[1024], buf2[32], buf3[36]; + BOOL FINDS=FALSE; + int talkNo=index*7+1; + if( npcarg == NULL ) return FALSE; + + sprintf( token, " %d/%dҳ\n",index+1, CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)); + while( getStringFromIndexWithDelim( npcarg,"}",talkNo, buf1, sizeof( buf1)) != FALSE ) { + talkNo++; + memset( buf2, 0, sizeof( buf2)); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "MenuStr", buf2, sizeof( buf2)) == NULL ) + continue; + FINDS = TRUE; + + sprintf( buf3, " %s", buf2); + if(strlen(buf3)<10) + strcat( buf3, "\n"); + else + strcat( buf3, "\n"); + strcat( token, buf3); + if(talkNo>(index*7+8))return FINDS; + } + return FINDS; +} + +int NewVipShop_ShowMenulist( char *npcarg ) +{ + char buf1[1024]; + int talkNo=1; + while( getStringFromIndexWithDelim( npcarg,"}",talkNo, buf1, sizeof( buf1)) != FALSE ) { + talkNo++; + } + return (talkNo-3)/7+1; +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_npcenemy.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_npcenemy.c new file mode 100644 index 0000000..c18d433 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_npcenemy.c @@ -0,0 +1,1221 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_npcenemy.h" +#include "battle.h" +#include "enemy.h" +#include "readmap.h" +#include "encount.h" +#include "lssproto_serv.h" +#include "configfile.h" +#include "anim_tbl.h" +#include "handletime.h" +#include "npc_eventaction.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +enum { + CHAR_WORK_ENCOUNTTYPE = CHAR_NPCWORKINT1, /* ޼ */ + CHAR_WORK_DIEACT = CHAR_NPCWORKINT2, /* Ϸ¾ */ + CHAR_WORK_WARP_FLOOR = CHAR_NPCWORKINT3, /* °׷ʧ*/ + CHAR_WORK_WARP_X = CHAR_NPCWORKINT4, /* X */ + CHAR_WORK_WARP_Y = CHAR_NPCWORKINT5, /* Y */ + CHAR_WORK_ONEBATTLE = CHAR_NPCWORKINT6, /* ƾ ئ */ + NPC_TIME_MODE = CHAR_NPCWORKINT7, + CHAR_WORK_BASEIMGBAK = CHAR_NPCWORKINT8, /* 缰 į */ + CHAR_WORK_DIETIME = CHAR_NPCWORKINT9, /* Ϸ */ + CHAR_WORK_REVIVALTIME = CHAR_NPCWORKINT10, /* Ϸ߯ */ + CHAR_WORK_BATTLETYPE = CHAR_NPCWORKINT11, +}; + +#define NPC_ENEMY_REVIVALTIMA_DEFAULT 120 + +static int gymbody[] = { + SPR_001em,SPR_011em,SPR_021em,SPR_031em,SPR_041em,SPR_051em, + SPR_061em,SPR_071em,SPR_081em,SPR_091em,SPR_101em,SPR_111em, + + SPR_002em,SPR_012em,SPR_022em,SPR_032em,SPR_042em,SPR_052em, + SPR_062em,SPR_072em,SPR_082em,SPR_092em,SPR_102em,SPR_112em, + + SPR_003em,SPR_013em,SPR_023em,SPR_033em,SPR_043em,SPR_053em, + SPR_063em,SPR_073em,SPR_083em,SPR_093em,SPR_103em,SPR_113em, + + SPR_004em,SPR_014em,SPR_024em,SPR_034em,SPR_044em,SPR_054em, + SPR_064em,SPR_074em,SPR_084em,SPR_094em,SPR_104em,SPR_114em, +}; + +#ifdef _NEW_WARPMAN +static BOOL NPC_NPCEnemy_CheckFree( int meindex, int toindex, BOOL *Party); +BOOL NPC_WarpAllMsg(int meindex,int toindex ); +BOOL NPCEnemy_CheckFree( int meindex, int talker, char *buf); +BOOL NPCEnemy_BSCheck(int meindex,int talker,char* buf); +BOOL NPCEnemy_FreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg, int temp); +BOOL NPCEnemy_WarpManReduce(int meindex,int talker,char *buf); +BOOL NPCEnemy_BigSmallLastCheck(int point1,int mypoint,int flg); +BOOL NPCEnemy_CheckTrans(int meindex,int talker,int trans,int flg); +BOOL NPCEnemy_LevelCheck(int meindex,int talker,int level,int flg); +BOOL NPCEnemy_CheckMyPet( int meindex, int talker, int petLv, int flg, int petid); +BOOL NPCEnemy_ItemCheck(int meindex,int talker,int itemNo,int flg); +#endif +#ifdef _NPC_REPLACEMENT +void Check_EnemyWarpMe( int meindex, char *args ); +#endif +static int NPC_NPCEnemy_StealItem( char *argstr, int meindex, int charaindex); + +BOOL NPC_NPCEnemyInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + int tmp, gym; + + + if( NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL ) { + print("Can't GetArgStr !!"); + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "sktype", buf, sizeof( buf)) != NULL ){ + CHAR_setWorkInt( meindex, CHAR_WORK_BATTLETYPE, atoi( buf)); + }else{ + CHAR_setWorkInt( meindex, CHAR_WORK_BATTLETYPE, 0); + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "enemyno", buf, sizeof( buf)) == NULL ){ + char filename[256]; + NPC_Util_CheckAssignArgFile( meindex, filename); + print( "NPCEnemy: nothing parameter [enemyno]:\n%s\n", filename); + return FALSE; + }else { + int i; + for( i = 0; i < NPC_ENEMY_ENEMYNUMBER; i ++ ) { + int curEnemy; + char data[128]; + int ret; + ret = getStringFromIndexWithDelim( buf,",", i + 1, data, sizeof(data)); + if( ret == FALSE) + break; + curEnemy = ENEMY_getEnemyArrayFromId( atoi( data)); + if( !ENEMY_CHECKINDEX( curEnemy) ) { + char filename[256]; + NPC_Util_CheckAssignArgFile( meindex, filename); + print( "NPCEnemy: invalid param [enemyno:%d data:%s curEnemy:%d]\nfile:%s\n",i+1, data, curEnemy, filename ); + return FALSE; + } + } + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "steal", buf, sizeof( buf)) != NULL ) { + if( NPC_Util_GetStrFromStrWithDelim( argstr, "item", buf, sizeof( buf)) == NULL ) { + print( "NPCEnemy:ָstealûָitem\n"); + return FALSE; + } + } + + gym = NPC_Util_GetNumFromStrWithDelim( argstr, "gym"); + + if( gym > 0 ){ + CHAR_setInt( meindex, CHAR_BASEBASEIMAGENUMBER, + gymbody[RAND( 0, arraysizeof( gymbody ) - 1)] ); + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, + CHAR_getInt( meindex, CHAR_BASEBASEIMAGENUMBER ) ); + CHAR_setInt( meindex, CHAR_LV, gym ); + } + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "dieact"); + if( tmp != 1 ) + tmp = 0; + CHAR_setWorkInt( meindex, CHAR_WORK_DIEACT, tmp); + + if( strstr( argstr, "NEWNPCENEMY") != 0 ) { + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_FLOOR, 0 ); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_Y, 0 ); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_X, 0 ); + }else { + if( CHAR_getWorkInt( meindex, CHAR_WORK_DIEACT) == 1 ) { + char buff1[256]; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "warpfl", buff1, sizeof( buff1) ) == NULL) { + print( "NPCENEMY: nothing warp_floor %s\n", buff1); + return FALSE; + } + tmp = atoi( buff1); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_FLOOR, tmp); + if( NPC_Util_GetStrFromStrWithDelim( argstr, "warpx", buff1, sizeof( buff1) ) == NULL) { + print( "NPCENEMY: nothing warp_x\n"); + return FALSE; + } + tmp = atoi( buff1); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_X, tmp); + if( NPC_Util_GetStrFromStrWithDelim( argstr, "warpy", buff1, sizeof( buff1) ) == NULL) { + print( "NPCENEMY: nothing warp_y\n"); + return FALSE; + } + tmp = atoi( buff1); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_Y, tmp); + if( MAP_IsValidCoordinate( CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y) ) == FALSE ){ + char filename[256]; + NPC_Util_CheckAssignArgFile( meindex, filename); + print( "NPCENEMY: %s: .\n %s.\nInvalid fl=%d,x=%d,y=%d\n", filename, argstr, + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y) ); + return FALSE; + } + } + } + //andy_end + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "entype"); + if( tmp != 1 && tmp != 2) + tmp = 0; + CHAR_setWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE, tmp); + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "onebattle"); + if( tmp != 1 ) + tmp = 0; + CHAR_setWorkInt( meindex, CHAR_WORK_ONEBATTLE, tmp); + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "time"); + if( tmp == -1 ) + tmp = NPC_ENEMY_REVIVALTIMA_DEFAULT; + CHAR_setWorkInt( meindex, CHAR_WORK_REVIVALTIME, tmp); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPENPCENEMY ); + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_ENEMY); + CHAR_setWorkInt( meindex, CHAR_WORK_BASEIMGBAK, + CHAR_getInt( meindex, CHAR_BASEIMAGENUMBER)); + return TRUE; +} + +void NPC_NPCEnemyTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg)) == NULL ) { + print("Can't GetArgStr !!"); + return; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "NEWTIME", buf, sizeof( buf)) != NULL ){ + if( CHAR_getWorkInt( meindex, NPC_TIME_MODE) <= 0 ) { + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "Time_Msg", buf, sizeof( buf) ) != NULL) { + CHAR_talkToCli( talkerindex, meindex, buf, CHAR_COLORYELLOW); + } + return; + } + } + if( !NPC_Util_charIsInFrontOfChar( talkerindex, meindex, 1 )) + return; + if( CHAR_getWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE) >= 1 ) { + NPC_NPCEnemy_Encount( meindex, talkerindex, 1); + } +} + +int NPC_NPCEnemy_Encount( int meindex, int charaindex, int mode) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[512]; + BOOL flg = TRUE; + int battlemax = getBattlenum(); + int i; + if( CHAR_getInt( meindex, CHAR_BASEIMAGENUMBER) == 0 ) { + return FALSE; + } + if( mode == 0 ) { + if( CHAR_getWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE) == 1 ) { + flg = FALSE; + } + }else if( mode == 1 ) { + if( CHAR_getWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE) == 0 ) { + flg = FALSE; + } + } + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( !flg) { + if( NPC_Util_GetStrFromStrWithDelim( argstr, "deniedmsg", buf, sizeof( buf)) != NULL ) { + CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW ); + } + return FALSE; + } + flg = FALSE; + while( 1 ) { + char buf[1024]; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "item", buf, sizeof( buf)) != NULL ) { + char data[128]; + BOOL found = FALSE; + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charaindex); + for(i=0;i= sizeof( buf) ) { + print( "buffer over\n"); + return FALSE; + } + } + else { + strcpysafe( &buf[len], sizeof( buf)-len, "\n" ); + len++; + if( len >= sizeof( buf) ) { + print( "buffer over\n"); + return FALSE; + } + } + } + + if( fd != -1 ) { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_NPCENEMY_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( buf, escapebuf,sizeof(escapebuf))); + } + /* */ + return FALSE; + }else { + /* */ + flg = NPC_NPCEnemy_BattleIn( meindex, charaindex); + } + } + } + if( !flg) { + if( NPC_Util_GetStrFromStrWithDelim( argstr, "deniedmsg", buf, sizeof( buf))!= NULL ) + { + CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW ); + } + } + return flg; +} + +int NPC_NPCEnemy_Dying( int battleindex, int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + int i,toindex=-1; + int tmp=-1; + + if( !CHAR_CHECKINDEX( meindex)) { + return FALSE; + } + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + +#ifdef _NEW_WARPMAN + if( strstr( argstr, "NEWNPCENEMY") ) { + }else { +#endif + /* Ӭ ̫ */ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "endmsg", buf, sizeof( buf)) != NULL ) { + for( i = 0; i < 5; i ++ ) { + /* 帨ƻ幻嶪 */ + int toindex = BattleArray[battleindex].Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( toindex) ) { + CHAR_talkToCli( toindex, meindex ,buf , CHAR_COLORYELLOW ); + } + } + + } +#ifdef _NEW_WARPMAN + } +#endif + if( NPC_Util_GetStrFromStrWithDelim( argstr, "steal", buf, sizeof( buf)) != NULL ) { + print("\n steal TRUE !!"); + if( atoi( buf) == 1 ) { + int charaindex = BattleArray[battleindex].Side[0].Entry[0].charaindex; + NPC_NPCEnemy_StealItem( argstr, meindex, charaindex); + } + + } +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + if( NPC_Util_GetStrFromStrWithDelim( argstr, "herobattlefield", buf, sizeof( buf)) != NULL ) { + int charaindex = BattleArray[battleindex].Side[0].Entry[0].charaindex; + CHAR_setWorkInt ( charaindex , CHAR_WORKHEROFLOOR , atoi ( buf ) ) ; + // Syu ADD + if ( atoi ( buf ) > CHAR_getInt ( charaindex , CHAR_HEROFLOOR ) ) + CHAR_setInt ( charaindex , CHAR_HEROFLOOR , atoi( buf ) ) ; + } + +#endif + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "additem", buf, sizeof( buf) ) != NULL) { + for( i = 0; i < 5; i ++ ) { + /* 帨ƻ幻嶪 */ + int toindex = BattleArray[battleindex].Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( toindex) ) { + int itemid = atoi(buf); + int itemindex = -1; + int emptyitemindexinchara = CHAR_findEmptyItemBox( toindex ); + + if( emptyitemindexinchara >= 0 ){ + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex > -1 ){ + CHAR_setItemIndex( toindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX, -1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX, toindex); + CHAR_sendItemDataOne( toindex, emptyitemindexinchara); + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), + #ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, + #else + atoi( message), + #endif + "AddItem()", + CHAR_getInt( toindex,CHAR_FLOOR), + CHAR_getInt( toindex,CHAR_X ), + CHAR_getInt( toindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + char token[256]; + sprintf(token, "%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( toindex, -1, token , CHAR_COLORYELLOW ); + } + } + } + } + } + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "dieact"); + if( tmp != 1 ) + tmp = 0; + CHAR_setWorkInt( meindex, CHAR_WORK_DIEACT, tmp); + if( CHAR_getWorkInt( meindex, CHAR_WORK_DIEACT) == 0 ) { + Char *ch; + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, 0); + //print("bbi---->bi10"); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_ALTERRATIVE); + MAP_sendAroundMapdata( CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y)); + ch = CHAR_getCharPointer( meindex); + if( ch != NULL ) { + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), + "NPCEnemyLoop"); + CHAR_constructFunctable( meindex); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 5000); + CHAR_setWorkInt( meindex, CHAR_WORK_DIETIME, NowTime.tv_sec); + }else { + print( "NPCENEMY:err\n"); + } + }else { + for( i = 0; i < 5; i ++ ) { + toindex = BattleArray[battleindex].Side[0].Entry[i].charaindex; + if( CHAR_CHECKINDEX( toindex) ) { +#ifdef _NEW_WARPMAN + if( strstr( argstr, "NEWNPCENEMY") ){ + BOOL Party=TRUE; + if( NPC_NPCEnemy_CheckFree( meindex, toindex , &Party) == FALSE ) { + continue; + } + if( Party == TRUE ) { + }else { + if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) { + if( NPC_WarpAllMsg( meindex, toindex ) == TRUE ) { + return TRUE; + } + } + continue; + } + } + CHAR_DischargeParty( toindex, 0); // + CHAR_warpToSpecificPoint( toindex, + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y) + ); + +#else + CHAR_warpToSpecificPoint( toindex, + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X), + CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y) + ); +#endif +#ifdef _NPC_REPLACEMENT + Check_EnemyWarpMe( meindex, argstr); +#endif + } + } + } + return TRUE; +} + +void NPC_NPCEnemyLoop( int meindex ) +{ + + if( NowTime.tv_sec > CHAR_getWorkInt( meindex, CHAR_WORK_DIETIME) + + CHAR_getWorkInt( meindex, CHAR_WORK_REVIVALTIME)){ + Char *ch; + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, CHAR_getWorkInt( meindex, CHAR_WORK_BASEIMGBAK)); + //print("bbi---->bi11"); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_ENEMY); + MAP_sendAroundMapdata( CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y)); + ch = CHAR_getCharPointer( meindex); + if( ch != NULL ) { + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNC]), ""); + CHAR_constructFunctable( meindex); +// CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 0); + } + } +} + + +BOOL NPC_NPCEnemy_BattleIn( int meindex, int charaindex) +{ + int gym; + int ret; + char buf[256]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( NowTime.tv_sec < CHAR_getWorkInt( meindex, CHAR_WORK_DIETIME) + + CHAR_getWorkInt( meindex, CHAR_WORK_REVIVALTIME)){ + return FALSE; + } + + memset( argstr, 0, sizeof( argstr)); + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + +#ifdef _NPC_TALK_CHECK + if( strstr( argstr,"TALKCHECK") != NULL){ + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)==0){ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + + if(CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK) != CHAR_getWorkInt(charaindex, CHAR_WORK_TALKCHECK)){ + char buf[256]; + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + sprintf(buf, "֤:%d", CHAR_getWorkInt(meindex, CHAR_WORK_TALKCHECK)); + CHAR_talkToCli( charaindex, meindex, buf, CHAR_COLORYELLOW); + return FALSE; + }else{ + CHAR_setWorkInt(meindex, CHAR_WORK_TALKCHECK, getTalkCheck()); + } + } +#endif + + gym = NPC_Util_GetNumFromStrWithDelim( argstr, "gym"); + +#ifdef _EMENY_CHANCEMAN + { + int masterindex=-1; + masterindex = NPC_EmenyChanceCheck( meindex, charaindex, argstr); + if( CHAR_CHECKINDEX( masterindex)){ + charaindex = masterindex; + }else { + return TRUE; + } + } +#endif + if( gym > 0 ){ + ret = BATTLE_CreateVsEnemy( charaindex, 2, meindex); + }else{ + ret = BATTLE_CreateVsEnemy( charaindex, 1, meindex); + } + if( ret == 0 ) { + BattleArray[CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX)].WinFunc = NPC_NPCEnemy_Dying; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "startmsg", buf, sizeof( buf)) != NULL ){ + CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW ); + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "steal", buf, sizeof( buf))!= NULL ){ + if( atoi( buf) == 0 ) { + NPC_NPCEnemy_StealItem( argstr, meindex, charaindex); + } + } + } + return ( ret == 0 ) ?TRUE:FALSE ; +} + +void NPC_NPCEnemyWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + if( seqno == CHAR_WINDOWTYPE_NPCENEMY_START) { + if( select == WINDOW_BUTTONTYPE_YES) { + NPC_NPCEnemy_BattleIn( meindex, talkerindex); + } + } +} + +static int NPC_NPCEnemy_StealItem( char *argstr, int meindex, int charaindex) +{ + char itembuf[1024]; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "item", itembuf, sizeof( itembuf))!= NULL ) + { + char data[128]; + int delitemgroup[CHAR_MAXITEMHAVE]; + int found = 0; + int i; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charaindex); + for( i = 0; i < itemMax; i ++ ) { +#else + for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + int j; + int itemid; + int ret = getStringFromIndexWithDelim( itembuf,",", i + 1,data, sizeof(data)); + if( ret == FALSE) { + break; + } + itemid = atoi( data); +#ifdef _NEW_ITEM_ + for( j = 0; j < itemMax; j ++ ) { +#else + for( j = 0; j < CHAR_MAXITEMHAVE; j ++ ) { +#endif + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)){ + if( ITEM_getInt( itemindex, ITEM_ID) == itemid ){ + CHAR_setItemIndex( charaindex, j, -1); + ITEM_endExistItemsOne( itemindex); + delitemgroup[found] = j; + found ++; + break; + } + } + } + if( !found ) break; + } + CHAR_sendItemData( charaindex, delitemgroup, found); + } + else { + print( "NPCENEMY:\n"); + return FALSE; + } + return TRUE; +} + +#ifdef _NEW_WARPMAN +static BOOL NPC_NPCEnemy_CheckFree( int meindex, int toindex, BOOL *Party) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf1[1024],buf2[256],buf3[256],buf4[256]; + char token[256]; + char temp1[16]; + int talkNo = 1; + int point=1; + + int i=0,type=0; + + struct tagWarpPoint { + int floor; + int x; + int y; + }AllWarPoint[]={ + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + }; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL) { + print("GetArgStrErr"); + return FALSE; + } + if( (strstr( npcarg,"NEWNPCENEMY") == NULL) && (strstr( npcarg,"OVER") == NULL) ) { + return FALSE; + }else { + } + + while( getStringFromIndexWithDelim( npcarg,"OVER",talkNo,buf1,sizeof( buf1)) != FALSE ) { + + talkNo++; + sprintf(temp1,"NEWEVENT"); + if( strstr( buf1, temp1) != NULL) { + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2) ) == FALSE ) { + continue; + } + if( NPC_ActionPassCheck( meindex, toindex, buf2) == FALSE ) { + continue; + } + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "endmsg", token, sizeof( token)) != NULL ) { + CHAR_talkToCli( toindex, meindex ,token , CHAR_COLORYELLOW ); + } +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + if( NPC_Util_GetStrFromStrWithDelim( buf1, "herobattlefield", token, sizeof( token)) != NULL ) { + CHAR_setWorkInt ( toindex , CHAR_WORKHEROFLOOR , atoi ( token ) ) ; + if ( atoi ( token ) > CHAR_getInt ( toindex , CHAR_HEROFLOOR ) ) + CHAR_setInt ( toindex , CHAR_HEROFLOOR , atoi( token ) ) ; + + } +#endif + + if( NPC_Util_GetStrFromStrWithDelim( buf1, "WARP", buf2, sizeof( buf2) ) == FALSE ){ + continue; + }else {//RAND arraysizeof AllWarPoint + while( getStringFromIndexWithDelim( buf2, ";", point, buf3,sizeof( buf3)) != FALSE ) { + point++; + getStringFromIndexWithDelim( buf3, ",", 1, buf4, sizeof( buf4)); + AllWarPoint[i].floor = atoi( buf4); + getStringFromIndexWithDelim( buf3, ",", 2, buf4, sizeof( buf4)); + AllWarPoint[i].x = atoi( buf4); + getStringFromIndexWithDelim( buf3, ",", 3, buf4, sizeof( buf4)); + AllWarPoint[i].y = atoi( buf4); + i++; + if( i >= arraysizeof( AllWarPoint) ) + break; + } + type = RAND( 0, i-1); + if( AllWarPoint[type].floor <= 0 || type > arraysizeof( AllWarPoint)-1) { + type = 0; + } + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_FLOOR, AllWarPoint[type].floor ); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_X, AllWarPoint[type].x ); + CHAR_setWorkInt( meindex, CHAR_WORK_WARP_Y, AllWarPoint[type].y ); + + } + if( NPC_Util_GetStrFromStrWithDelim( buf1, "CHECKPARTY", buf4, sizeof( buf4)) != NULL ) { + if( strstr( buf4, "FALSE") != NULL ) { + *Party = FALSE; + } + } + if( *Party == TRUE ) { + Action_RunDoEventAction( meindex, toindex, buf1); + } + return TRUE; + } + } + return FALSE; +} + + +BOOL NPCEnemy_CheckFree( int meindex, int talker, char *buf) +{ + char buff2[256]; + char buff3[128]; + int i=1,j=1; + int loop=0; + while( getStringFromIndexWithDelim(buf,",",i,buff2,sizeof(buff2)) !=FALSE ) { + i++; + if(strstr(buff2,"&")!=NULL){ + j=1; + loop=0; + while( getStringFromIndexWithDelim(buff2,"&",j,buff3,sizeof(buff3)) !=FALSE ) { + j++; + if(NPCEnemy_BSCheck(meindex,talker,buff3)==FALSE) { + loop=1; + break; + } + } + if(loop==0) { + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + } + }else{ + if( NPCEnemy_BSCheck( meindex, talker, buff2) == TRUE ){ + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, TRUE ); + return TRUE; + } + } + } + CHAR_setWorkInt( talker, CHAR_WORKWARPCHECK, FALSE ); + return FALSE; +} + +BOOL NPCEnemy_BSCheck(int meindex,int talker,char* buf) +{ + char buff2[128]; + int kosuu,temp=-1,flg=0; + char buff1[128],buff3[128]; + if(strstr( buf, "-") != NULL) { + //buff3ΪץID + getStringFromIndexWithDelim( buf, "-", 2, buff3, sizeof(buff3)); + temp = atoi( buff3); + getStringFromIndexWithDelim( buf, "-", 1, buff1, sizeof(buff1)); + strcpy( buf, buff1); + } + + if(strstr( buf, "<") != NULL){ + getStringFromIndexWithDelim( buf, "<", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "<", 1, buff2, sizeof(buff2)); + + if(NPCEnemy_FreeIfCheck( meindex, talker, buff2, kosuu, 1, temp)==TRUE){ + return TRUE; + } + }else if(strstr( buf, ">") != NULL){ + getStringFromIndexWithDelim( buf, ">", 2, buff2, sizeof(buff2)); + kosuu = atoi(buff2); + getStringFromIndexWithDelim( buf, ">" ,1, buff2, sizeof(buff2)); + + if(NPCEnemy_FreeIfCheck( meindex, talker, buff2, kosuu, 2, temp)==TRUE){ + return TRUE; + } + + }else if(strstr( buf, "!" ) != NULL){ + getStringFromIndexWithDelim( buf, "!=", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "!=", 1, buff2, sizeof(buff2)); + if(NPCEnemy_FreeIfCheck( meindex, talker, buff2, kosuu, 0, temp) == TRUE){ + return FALSE; + }else{ + return TRUE; + } + + }else if(strstr( buf, "=") != NULL){ + + getStringFromIndexWithDelim( buf, "=", 2, buff2, sizeof(buff2)); + kosuu = atoi( buff2); + getStringFromIndexWithDelim( buf, "=", 1, buff2, sizeof(buff2)); + + if( strstr( buf, "PET")) { + flg = 3; + } + if(strstr( buf, "*") != NULL){ + if( NPCEnemy_WarpManReduce( meindex, talker, buf)==TRUE){ + return TRUE; + } + }else if(NPCEnemy_FreeIfCheck( meindex, talker, buff2, kosuu, flg, temp)==TRUE){ + return TRUE; + } + } + return FALSE; +} + +BOOL NPCEnemy_FreeIfCheck(int meindex,int talker,char* buf,int kosuu,int flg, int temp) +{ + if(strcmp(buf,"LV")==0){ + if(NPCEnemy_LevelCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } + + if( strcmp(buf,"TRANS") == 0 ) { + if( NPCEnemy_CheckTrans( meindex, talker, kosuu, flg) == TRUE ) + return TRUE; + } +#ifdef _GLORY_POINT + if(strcmp(buf,"GLORY")==0){ + if(NPC_ActionGloryCheck(meindex,talker,kosuu,flg)==TRUE) + return TRUE; + } +#endif + if( strcmp( buf, "PET") == 0 ) { + if( temp > 0 ) { + if( NPCEnemy_CheckMyPet( meindex, talker, kosuu, flg, temp) == TRUE ) + return TRUE; + }else + return FALSE; + } + + if(strcmp(buf,"ITEM")==0){ + if(NPCEnemy_ItemCheck(meindex,talker,kosuu,flg)==TRUE){ + return TRUE; + } + } + if(strcmp(buf,"ENDEV")==0){ + if(NPC_EventCheckFlg( talker, kosuu)==TRUE){ + return TRUE; + } + } + if(strcmp(buf,"NOWEV")==0){ + if(NPC_NowEventCheckFlg( talker, kosuu)==TRUE){ + return TRUE; + } + } + return FALSE; + +} + +BOOL NPCEnemy_WarpManReduce(int meindex,int talker,char *buf) +{ + char buf2[512]; + char buf3[256]; + int id=0; + int i; + int itemindex; + int itemno; + int kosuu; + int cnt=0; + + getStringFromIndexWithDelim(buf,"=",2,buf2,sizeof(buf2)); + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemno = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( i=0;i point1) { + return TRUE; + } + } + + return FALSE; + +} + +BOOL NPCEnemy_LevelCheck(int meindex,int talker,int level,int flg) +{ + int mylevel; + mylevel=CHAR_getInt(talker,CHAR_LV); + if(NPCEnemy_BigSmallLastCheck(level,mylevel,flg)==TRUE) { + return TRUE; + } + return FALSE; +} + +BOOL NPCEnemy_CheckTrans(int meindex,int talker,int trans,int flg) +{ + int myTrans; + myTrans=CHAR_getInt(talker, CHAR_TRANSMIGRATION); + if( NPCEnemy_BigSmallLastCheck( trans, myTrans, flg ) == TRUE ) { + return TRUE; + } + return FALSE; +} + +BOOL NPCEnemy_CheckMyPet( int meindex, int talker, int petLv, int flg, int petid) +{ + int petsel,petindex=-1; + for(petsel=0 ; petsel < CHAR_MAXPETHAVE ; petsel++) { + petindex = CHAR_getCharPet( talker, petsel); + if( petindex == -1 ) + continue; + if(CHAR_getInt( petindex, CHAR_PETID) != petid ) + continue; + break; + } + if( petsel == CHAR_MAXPETHAVE ) { + return FALSE; + }else { //ҵ + switch( flg) { + case 0: + if( CHAR_getInt( petindex, CHAR_LV) != petLv ) + return TRUE; + break; + case 1: + if( CHAR_getInt( petindex, CHAR_LV) < petLv ) + return TRUE; + break; + case 2: + if( CHAR_getInt( petindex, CHAR_LV) > petLv ) + return TRUE; + break; + case 3: + if( CHAR_getInt( petindex, CHAR_LV) == petLv ) + return TRUE; + break; + } + return FALSE; + } + return FALSE; +} + +BOOL NPCEnemy_ItemCheck(int meindex,int talker,int itemNo,int flg) +{ + int i; + int itemindex=-1; + int id; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( i=0;i 0 && addcnt > 0 ) { + snprintf( message, sizeof( message ) , + "ɥʧ%d%s ƺŵʸ" + "ǵõ%d%s ijƺʸ" + , delcnt, + delcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2, + addcnt, + addcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2 + ); + CHAR_talkToCli( talkerindex , meindex , message , CHAR_COLORWHITE ); + } + else if( delcnt > 0 ) { + snprintf( message, sizeof( message ) , + "ɥʧõ%d%sƺŵʸ", delcnt, + delcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2); + CHAR_talkToCli( talkerindex , meindex , message , CHAR_COLORWHITE ); + } + else if( addcnt > 0 ) { + snprintf( message, sizeof( message ) , + "%d%sijƺŰɣ", addcnt, // CoolFish: d%s -> %d%s 2001/4/18 + addcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2); + CHAR_talkToCli( talkerindex , meindex , message , CHAR_COLORWHITE ); + } + if( delcnt > 0 ) { + snprintf( message, sizeof( message), + "ʧȥ%d%s ƺţ", delcnt, + delcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2); + CHAR_talkToCli( talkerindex, -1, message, CHAR_COLORYELLOW); + } + if( addcnt > 0 ) { + snprintf( message, sizeof( message), + "%d%s ƺţ", addcnt, + addcnt < 10 ? NPC_OLDMAN_TITLE_UNIT1:NPC_OLDMAN_TITLE_UNIT2); + CHAR_talkToCli( talkerindex, -1, message, CHAR_COLORYELLOW); + } + } +} + if( title_change ) CHAR_sendStatusString( talkerindex , "T" ); + +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_pauctionman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_pauctionman.c new file mode 100644 index 0000000..c49c03a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_pauctionman.c @@ -0,0 +1,473 @@ +#include "version.h" +#include + +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_pauctionman.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "longzoro/sasql.h" +#include "pet.h" +//صشøнڽ"ʦ" +#ifdef _PAUCTION_MAN +enum { + WINDOW_PAUCTION_START=1, + WINDOW_PAUCTION_SELECT, + WINDOW_PAUCTION_NEW, + WINDOW_PAUCTION_AUCTIONSURVEY, + WINDOW_PAUCTION_LIST_BUY_ALL, + WINDOW_PAUCTION_LIST_BUY_PET, + WINDOW_PAUCTION_LIST_BUY_ITEM, + WINDOW_PAUCTION_LIST_MODIFY, +}; + +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +#define STANDBYTIME 50 + +static void NPC_Pauction_selectWindow( int meindex, int toindex, int seqno, int select, char *data); + +BOOL NPC_PauctionInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + +// CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TRANSERMANS); + + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_PauctionTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_START, 0, 0); +} + +void NPC_PauctionWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data) +{ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( seqno) { + case NPC_PAUCTION_START: + break; + case NPC_PAUCTION_SELECT: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_SELECT, select, data); + break; + case NPC_PAUCTION_NEW: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_NEW, select, data); + break; + case NPC_PAUCTION_AUCTIONSURVEY: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_AUCTIONSURVEY, select, data); + break; + case NPC_PAUCTION_LIST_BUY_ALL: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_LIST_BUY_ALL, select, data); + break; + case NPC_PAUCTION_LIST_BUY_PET: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_LIST_BUY_PET, select, data); + break; + case NPC_PAUCTION_LIST_BUY_ITEM: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_LIST_BUY_ITEM, select, data); + break; + case NPC_PAUCTION_LIST_MODIFY: + NPC_Pauction_selectWindow( meindex, talkerindex, WINDOW_PAUCTION_LIST_MODIFY, select, data); + break; + } +} + +static void NPC_Pauction_selectWindow( int meindex, int toindex, int seqno, int select, char *data) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + char buf[1024]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_OK; + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("Pauction_MAN: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + switch( seqno) { + case WINDOW_PAUCTION_START: + sprintf(token, "3\n ί״\n\n" + "ʲôҪΪأ\n" + " Ҫίһס\n" + " 鿴ίб\n" + " 鿴ίб\n" + " 鿴Ʒίб\n" + " 鿴ίб\n" + ); + + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_PAUCTION_SELECT; + break; + case WINDOW_PAUCTION_SELECT: + { + int num = 0; + if(atoi(data)==1){ + windowtype = WINDOW_MESSAGETYPE_AUCTIONNEW; + windowno = NPC_PAUCTION_NEW; + }else if(atoi(data)==2 || atoi(data)==3 || atoi(data)==4){ + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, 0); + if(atoi(data)==2){ + num = sasql_getPauctionList(token, 0, 0, ""); + windowno = NPC_PAUCTION_LIST_BUY_ALL; + }else if(atoi(data)==3){ + num = sasql_getPauctionList(token, 0, 1, ""); + windowno = NPC_PAUCTION_LIST_BUY_PET; + }else if(atoi(data)==4){ + num = sasql_getPauctionList(token, 0, 2, ""); + windowno = NPC_PAUCTION_LIST_BUY_ITEM; + } + windowtype = WINDOW_MESSAGETYPE_AUCTIONLIST_BUY; + + }else if(atoi(data)==5){ + num = sasql_getPauctionList(token, 0, 0, CHAR_getChar(toindex, CHAR_CDKEY)); + windowtype = WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY; + windowno = NPC_PAUCTION_LIST_MODIFY; + } + + if(num>10){ + buttontype = WINDOW_BUTTONTYPE_NEXT; + } + } + break; + case WINDOW_PAUCTION_NEW: + { + char effect[128]; + char info[128]; + char tmp[128]; + char *string = ""; + makeStringFromEscaped(data); + + + getStringFromIndexWithDelim( data, "|", 1, tmp, sizeof( tmp)); + int type = atoi(tmp); + getStringFromIndexWithDelim( data, "|", 2, tmp, sizeof( tmp)); + int id = atoi(tmp); + getStringFromIndexWithDelim( data, "|", 3, effect, sizeof( effect)); + if(strlen(effect)==0){ + sprintf(token, "ίʧ,дί~"); + break; + } + + getStringFromIndexWithDelim( data, "|", 4, tmp, sizeof( tmp)); + int cost = atoi(tmp); + if(cost<=0){ + sprintf(token, "ίм۸Ϊ0~"); + break; + } + if(type == 1){ + int petindex = CHAR_getCharPet( toindex, id); + if( !CHAR_CHECKINDEX(petindex)){ + sprintf(token, "㲢ûҪίеij~"); + break; + } +#ifdef _PET_ITEM + int i; + for(i=0;i1){ + sprintf(token, "Ʒ޷~"); + break; + } + + sprintf(info, "%s|%d|%d|%s|", ITEM_getChar(itemindex, ITEM_NAME), + ITEM_getInt(itemindex, ITEM_BASEIMAGENUMBER), +#ifdef _ITEM_COLOER + ITEM_getInt( itemindex, ITEM_COLOER), +#else + CHAR_COLORWHITE, +#endif + ITEM_getChar(itemindex, ITEM_EFFECTSTRING)); + + string = ITEM_makeStringFromItemIndex(itemindex, 0); + if( string == "\0" ){ + sprintf(token, "ίƷʧ,Աϵ~"); + break; + } + CHAR_DelItem( toindex, id); + } + char *cdkey = CHAR_getChar(toindex, CHAR_CDKEY); + char *name = CHAR_getChar(toindex, CHAR_NAME); + sasql_addPauctionInfo(cdkey, name, effect, cost, type, info, string); + sprintf(token, "ɹΪǼһίнϢ,ǻᾡľΪ,һж̬,ǻһʱ֪ͨ!"); + } + break; + case WINDOW_PAUCTION_LIST_BUY_ALL: + case WINDOW_PAUCTION_LIST_BUY_PET: + case WINDOW_PAUCTION_LIST_BUY_ITEM: + case WINDOW_PAUCTION_LIST_MODIFY: + { + if(select == WINDOW_BUTTONTYPE_PREV || select == WINDOW_BUTTONTYPE_NEXT){ + int page = 0; + int num=0; + windowtype = WINDOW_MESSAGETYPE_AUCTIONLIST_BUY; + if(select == WINDOW_BUTTONTYPE_PREV){ + page = CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE) - 1; + if(page<0) page = 0; + }else if(select == WINDOW_BUTTONTYPE_NEXT){ + page = CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE) + 1; + if(page>8) page = 8; + } + if(seqno==WINDOW_PAUCTION_LIST_BUY_ALL){ + num = sasql_getPauctionList(token, page * 10, 0, ""); + windowno = NPC_PAUCTION_LIST_BUY_ALL; + }else if(seqno==WINDOW_PAUCTION_LIST_BUY_PET){ + num = sasql_getPauctionList(token, page * 10, 1, ""); + windowno = NPC_PAUCTION_LIST_BUY_PET; + }else if(seqno==WINDOW_PAUCTION_LIST_BUY_ITEM){ + num = sasql_getPauctionList(token, page * 10, 2, ""); + windowno = NPC_PAUCTION_LIST_BUY_ITEM; + }else if(seqno==WINDOW_PAUCTION_LIST_MODIFY){ + num = sasql_getPauctionList(token, page * 10, 0, CHAR_getChar(toindex, CHAR_CDKEY)); + windowno = NPC_PAUCTION_LIST_MODIFY; + windowtype = WINDOW_MESSAGETYPE_AUCTIONLIST_MODIFY; + } + buttontype = 0; + if(num>(page + 1) * 10){ + buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + if(page > 0){ + buttontype |= WINDOW_BUTTONTYPE_PREV; + } + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, page); + }else if(select==1){ + char string[1024]; + char buff[256]; + int type = sasql_getMyPauction(string, atoi(data), CHAR_getChar(toindex, CHAR_CDKEY)); + if(type == 1){ + int havepetelement = CHAR_getCharPetElement( toindex); + if( havepetelement < 0 ) { + sprintf(token, "ܱǸ,ϳ,ճһλ!"); + break; + } + Char petone; + int ret = CHAR_makePetFromStringToArg( string , &petone, 0 ); + + if( ret == TRUE ){ + int existpetindex; + existpetindex = PET_initCharOneArray( &petone ); + if( existpetindex < 0 ){ + sprintf(token, "ȡسʧ!"); + break; + } + CHAR_setWorkInt( existpetindex, CHAR_WORKPLAYERINDEX, toindex); + CHAR_setCharPet( toindex, havepetelement, existpetindex); + CHAR_complianceParameter( existpetindex); + snprintf( buff, sizeof( buff ), "K%d", havepetelement ); + CHAR_sendStatusString( toindex, buff ); + snprintf( buff, sizeof( buff ), "W%d", havepetelement ); + CHAR_sendStatusString( toindex, buff ); + sasql_delPauctionBuy(atoi(data), CHAR_getChar(toindex, CHAR_CDKEY)); + } + sprintf(token, "ɹȡij!"); + break; + }else if(type == 2){ + int emptyitemindexinchara = CHAR_findEmptyItemBox( toindex ); + if( emptyitemindexinchara < 0 ){ + sprintf(token, "ܱǸ,Ʒ,ճһƷλ!"); + break; + } + ITEM_Item itmone; + BOOL ret = ITEM_makeExistItemsFromStringToArg( string, &itmone, 0); + + if( ret == TRUE ){ + int itemindex = ITEM_initExistItemsOne( &itmone ); + if( itemindex == -1 ){ + sprintf(token, "ȡƷʧ!"); + break; + }else{ + CHAR_setItemIndex( toindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,toindex); + CHAR_sendItemDataOne( toindex, emptyitemindexinchara); + sasql_delPauctionBuy(atoi(data), CHAR_getChar(toindex, CHAR_CDKEY)); + } + } + sprintf(token, "ɹȡƷ!"); + break; + }else{ + sprintf(token, "??????????"); + } + }else if(select==4){ + sasql_getPauctionSurvey(token, atoi(data)); + windowno = NPC_PAUCTION_AUCTIONSURVEY; + windowtype = WINDOW_MESSAGETYPE_AUCTIONSURVEY; + } + } + break; + case WINDOW_PAUCTION_AUCTIONSURVEY: + { + char string[1024]; + char buff[256]; + int type = sasql_getMyPauction(string, atoi(data), ""); + + if(type == 1){ + int havepetelement = CHAR_getCharPetElement( toindex); + if( havepetelement < 0 ) { + sprintf(token, "ܱǸ,ϳ,ճһλ!"); + break; + } + int flg = sasql_PauctionOK(atoi(data), CHAR_getChar(toindex, CHAR_CDKEY)); + if(flg == 1){ + Char petone; + int ret = CHAR_makePetFromStringToArg( string , &petone, 0 ); + + if( ret == TRUE ){ + int existpetindex; + existpetindex = PET_initCharOneArray( &petone ); + if( existpetindex < 0 ){ + sprintf(token, "ȡسʧ!"); + break; + } + CHAR_setWorkInt( existpetindex, CHAR_WORKPLAYERINDEX, toindex); + CHAR_setCharPet( toindex, havepetelement, existpetindex); + CHAR_complianceParameter( existpetindex); + snprintf( buff, sizeof( buff ), "K%d", havepetelement ); + CHAR_sendStatusString( toindex, buff ); + snprintf( buff, sizeof( buff ), "W%d", havepetelement ); + CHAR_sendStatusString( toindex, buff ); + sasql_delPauctionBuy(atoi(data), ""); + } + sprintf(token, "ɹίг!"); + }else if(flg == -1){ + sprintf(token, "Ҫίгﲻڻѱ˹!"); + }else if(flg == -2){ + sprintf(token, "ܱǸ,ϵػر!"); + }else{ + sprintf(token, "ݿ,Աϵ!"); + } + }else if(type == 2){ + int emptyitemindexinchara = CHAR_findEmptyItemBox( toindex ); + if( emptyitemindexinchara < 0 ){ + sprintf(token, "ܱǸ,Ʒ,ճһƷλ!"); + break; + } + int flg = sasql_PauctionOK(atoi(data), CHAR_getChar(toindex, CHAR_CDKEY)); + if(flg == 1){ + ITEM_Item itmone; + BOOL ret = ITEM_makeExistItemsFromStringToArg( string, &itmone, 0); + + if( ret == TRUE ){ + int itemindex = ITEM_initExistItemsOne( &itmone ); + if( itemindex == -1 ){ + sprintf(token, "ȡƷʧ!"); + break; + }else{ + CHAR_setItemIndex( toindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX,toindex); + CHAR_sendItemDataOne( toindex, emptyitemindexinchara); + sasql_delPauctionBuy(atoi(data), ""); + } + } + sprintf(token, "ɹίƷ!"); + }else if(flg == -1){ + sprintf(token, "ҪίƷڻѱ˹!"); + }else if(flg == -2){ + sprintf(token, "ܱǸ,ϵػر!"); + }else{ + sprintf(token, "ݿ,Աϵ!"); + } + }else{ + sprintf(token, "??????????"); + break; + } + } + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), makeEscapeString(token, buf, sizeof( buf) )); +} + + +void NPC_PauctionLoop( int meindex) +{ + +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petfusion.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petfusion.c new file mode 100644 index 0000000..3112273 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petfusion.c @@ -0,0 +1,254 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "char_data.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "npc_petfusion.h" +#include "pet.h" +#include "chatmagic.h" + + +#ifdef _NPC_FUSION + +enum { + WINDOW_START=10, + WINDOW_SELECT, + WINDOW_FUSION, + WINDOW_WARP, //Ծ + WINDOW_END, // + + WINDOW_TALKSTART=20, + WINDOW_TALKSELECT, + WINDOW_RETURN, + WINDOW_TALKEND, +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, +/* + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +static void NPC_PetFusion_selectWindow( int meindex, int toindex, int num,int select); +BOOL NPC_DoPetFusion( int meindex, int toindex, char *data, int sizes); + + +BOOL NPC_PetFusionManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_PetFusionManInit: GetArgStrErr!!"); + return FALSE; + } + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_PETFUSIONMAN); + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, MAKEPAIR_STANDBY); + //CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + //CHAR_setWorkInt( meindex, NPC_WORK_PAIRTEAMS, 0); + return TRUE; +} +void NPC_PetFusionManTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( talkerindex, 0) == FALSE ){ + CHAR_talkToCli( talkerindex, meindex, "޷Яˣ", CHAR_COLORYELLOW); + return; + } +#endif + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, WINDOW_START); + NPC_PetFusion_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +static void NPC_PetFusion_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + if( Action_PartyCheck( meindex, toindex) == FALSE) { + CHAR_talkToCli( toindex, meindex, "һһ", CHAR_COLORYELLOW); + return; + } + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_MakePairMan: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + + switch( num){ + case WINDOW_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "StartMsg", token, sizeof( token) ) == NULL){ + return; + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = WINDOW_TALKSTART; + break; + case WINDOW_SELECT: + if( ActionNpc_CheckFree( meindex, toindex, npcarg) == FALSE ) { + buttontype = WINDOW_BUTTONTYPE_OK; + windowno = WINDOW_TALKEND; + }else { + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "SelectMsg", token, sizeof( token) ) == NULL){ + return; + } + windowtype = WINDOWS_MESSAGETYPE_PETFUSION; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = WINDOW_TALKSELECT; + } + break; + case WINDOW_FUSION: + //ںϴ + break; + case WINDOW_WARP: + break; + case WINDOW_END: + break; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, windowno); + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} +void NPC_PetFusionManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if( select == WINDOW_BUTTONTYPE_NO || select == WINDOW_BUTTONTYPE_CANCEL ){ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + return; + } + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != seqno ) + return; + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_MakePairMan: GetArgStrErr!!"); + return; + } + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != seqno ) + return; + + switch( seqno) { + case WINDOW_TALKSTART: + NPC_PetFusion_selectWindow( meindex, talkerindex, WINDOW_SELECT, 0); + break; + case WINDOW_TALKSELECT: + { + if( NPC_DoPetFusion( meindex, talkerindex, data, sizeof( data)) == FALSE ) + return; + return; + NPC_PetFusion_selectWindow( meindex, talkerindex, WINDOW_FUSION, 0); + } + break; + case WINDOW_RETURN: + break; + case WINDOW_TALKEND: + break; + } +} + +BOOL NPC_DoPetFusion( int meindex, int toindex, char *data, int sizes) +{ + char buf[256]; + int i, flg, MainIndex=-1, Subindex1=-1, Subindex2=-1; + int work[4], skill1[7], skill2[7]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + memset( buf, 0, sizeof( buf)); + sprintf( buf, "%s", data); + if( !CHAR_CHECKINDEX( meindex) ) return FALSE; + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("err NPC_MakePairMan: GetArgStrErr!!"); + return FALSE; + } + for( i=0; i +#include +#include + +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" +#include "enemy.h" +#include "chatmagic.h" +#include "log.h" + +#define EVFLG 118 // 58->׻ 118-> + +void pet_make( int charaindex, char* message ); + +BOOL NPC_PetMakerInit( int meindex ) +{ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEPETMAKER ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + return TRUE; +} + +void NPC_PetMakerTalked( int meindex , int talker , char *msg ,int color ) +{ + char* npcarg; + char token[32],tmpbuf[256]; + int msgNo/*,translv*/; + int point,ckpoint,array,shift; + int i,num=0; + + array = EVFLG / 32; + shift = EVFLG % 32; + point = CHAR_getInt( talker, CHAR_ENDEVENT + array); + ckpoint = point; + + npcarg = CHAR_getChar(meindex,CHAR_NPCARGUMENT); + + getStringFromIndexWithDelim( npcarg, "|", 1, token,sizeof( token)); + msgNo = atoi( token ); + + if( CHAR_getInt( talker , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + + if( NPC_Util_isFaceToFace( talker, meindex , 2 ) == FALSE ) + { + if( NPC_Util_isFaceToFace( talker, meindex , 1 ) == FALSE ) + return; + } + + //translv = CHAR_getInt( talker, CHAR_TRANSMIGRATION); // ׻ + + for(i=0; i=CHAR_MAXPETHAVE ){ + sprintf(tmpbuf, "ǸûĿռɷó"); + CHAR_talkToCli( talker, meindex, + tmpbuf,CHAR_COLORWHITE); + return; + } + + pet_make( talker, "1845" ); + + point = point | (1 << shift); + CHAR_setInt( talker, CHAR_ENDEVENT + array, point); +} + +void pet_make( int charaindex, char* message ) +{ + int ret; + char msgbuf[64]; + int enemynum; + int enemyid; + int i; + + enemyid = atoi(message); + enemynum = ENEMY_getEnemyNum(); + + for( i=0; i +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "handletime.h" + +#ifdef _PETRACE +#include "npc_petracemaster.h" + +#define PETRACEPETNUM 3 +#define PETRACEMASTER_INITPET_LOOPTIME 3000 // 3 +#define PETRACEMASTER_WAITDROPI_LOOPTIME 30000 // 30 +#define PETRACEMASTER_WAITDROPII_LOOPTIME 10000 // 10 +#define PETRACEMASTER_WAITDROPIII_LOOPTIME 5000 // 5 +#define PETRACEMASTER_WAITDROPIV_LOOPTIME 1000 // 1 +#define PETRACEMASTER_PETRACING_LOOPTIME 3000 // 3 +#define PETRACEMASTER_SHOWWINPET_LOOPTIME 10000 // 10 +#define PETRACEDROPSTAKETIME 120 // 2 120 +#define PETRACESHOWWINPET 30 // 30 +#define PETRACESTDPAYRATE 6 +#define PETRACESTDGOLD 1 // ʱ 1000 + +static void NPC_PetRaceMaster_selectWindow(int meindex, int toindex, int num, int select); +void NPC_findRacePetIndex(int meindex, int floor); +void NPC_givePriceToPlayer(int meindex, int floor, int winpetindex); + +enum +{ + NPC_WORK_STATE = CHAR_NPCWORKINT1, + NPC_WORK_PET1 = CHAR_NPCWORKINT2, + NPC_WORK_PET2 = CHAR_NPCWORKINT3, + NPC_WORK_PET3 = CHAR_NPCWORKINT4, + NPC_WORK_PETGROUP = CHAR_NPCWORKINT5, + NPC_WORK_STATECHANGE = CHAR_NPCWORKINT6, + NPC_WORK_FINDPETFLAG = CHAR_NPCWORKINT7, + NPC_WORK_WINPET = CHAR_NPCWORKINT8, + NPC_WORK_PETGOAL = CHAR_NPCWORKINT9, +}; +enum +{ + NPC_State_Init, + NPC_State_WaitDropStake, + NPC_State_PetRacing, + NPC_State_ShowWinPet, +}; +enum +{ + NPC_State_Wait, + NPC_State_Run, + NPC_State_ShowWin, +}; +typedef struct tagPetRaceGraTable +{ + int pet1gra; + int pet2gra; + int pet3gra; + char pet1name[64]; + char pet2name[64]; + char pet3name[64]; + int pet1win; + int pet2win; + int pet3win; +#ifdef _DROPSTAKENEW +#else + float payrate1; + float payrate2; + float payrate3; +#endif + char state1[64]; + char state2[64]; + char state3[64]; +}PetRaceGraTable; +#ifdef _DROPSTAKENEW +PetRaceGraTable petracegra[27] = +{ + {100820, 100821, 100822, "", "", "", 0, 0, 0, "", "", ""}, + {100823, 100824, 100825, "³", "", "", 0, 0, 0, "", "", ""}, + {100842, 100843, 100844, "˹", "˹", "˹", 0, 0, 0, "", "", ""}, + {100852, 100853, 100855, "", "˹", "˴", 0, 0, 0, "", "", ""}, + {100859, 100856, 100857, "ɿ", "", "", 0, 0, 0, "", "", ""}, + {100864, 100865, 100866, "", "±", "ë", 0, 0, 0, "", "", ""}, + {100829, 100826, 100827, "ȱȼ", "Ӽ", "˹", 0, 0, 0, "", "", ""}, + {100830, 100832, 100833, "ڱ", "", "", 0, 0, 0, "", "", ""}, + {100883, 100884, 100885, "", "", "", 0, 0, 0, "", "", ""}, + {100898, 100900, 100901, "ɿɶ", "", "ϲ", 0, 0, 0, "", "", ""}, + {100834, 100836, 100837, "", "屴", "岨", 0, 0, 0, "", "", ""}, + {100838, 100840, 100841, "", "֮", "", 0, 0, 0, "", "", ""}, + {100879, 100881, 100880, "ϼ", "", "ɰ", 0, 0, 0, "", "", ""}, + {100888, 100887, 100889, "Ī˾", "ŷɪ", "˹", 0, 0, 0, "", "", ""}, + {100913, 100914, 100915, "ķ˹", "˹", "˹", 0, 0, 0, "", "", ""}, + {100845, 100846, 100847, "", "³³", "³˹", 0, 0, 0, "", "", ""}, + {100849, 100850, 100851, "ŵ˹", "˹", "ϻ˹", 0, 0, 0, "", "", ""}, + {100878, 100876, 100877, "岼˹", "Ү˹", "ײ˹", 0, 0, 0, "", "", ""}, + {100908, 100909, 100906, "׶", "˾", "", 0, 0, 0, "", "", ""}, + {100916, 100918, 100919, "³˹", "Ϳ˾", "׵˹", 0, 0, 0, "", "", ""}, + {100860, 100862, 100861, "˾", "÷", "ϣ", 0, 0, 0, "", "", ""}, + {100867, 100870, 100868, "ŷּ³", "", "ʷ³", 0, 0, 0, "", "", ""}, + {100871, 100873, 100874, "³", "³", "˹", 0, 0, 0, "", "", ""}, + {100894, 100895, 100896, "Ħ", "ĦĦ", "Ħ", 0, 0, 0, "", "", ""}, + {100902, 100903, 100905, "", "Ħ", "˹", 0, 0, 0, "", "", ""}, + {100912, 100911, 100910, "", "˹", "", 0, 0, 0, "", "", ""}, + {100891, 100892, 100893, "֨", "˹˹", "ɸ˹", 0, 0, 0, "", "", ""}, +}; +#else +PetRaceGraTable petracegra[27] = +{ + {100820, 100821, 100822, "", "", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100823, 100824, 100825, "³", "", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100842, 100843, 100844, "˹", "˹", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100852, 100853, 100855, "", "˹", "˴", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100859, 100856, 100857, "ɿ", "", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100864, 100865, 100866, "", "±", "ë", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100829, 100826, 100827, "ȱȼ", "Ӽ", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100830, 100832, 100833, "ڱ", "", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100883, 100884, 100885, "", "", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100898, 100900, 100901, "ɿɶ", "", "ϲ", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100834, 100836, 100837, "", "屴", "岨", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100838, 100840, 100841, "", "֮", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100879, 100881, 100880, "ϼ", "", "ɰ", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100888, 100887, 100889, "Ī˾", "ŷɪ", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100913, 100914, 100915, "ķ˹", "˹", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100845, 100846, 100847, "", "³³", "³˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100849, 100850, 100851, "ŵ˹", "˹", "ϻ˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100878, 100876, 100877, "岼˹", "Ү˹", "ײ˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100908, 100909, 100906, "׶", "˾", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100916, 100918, 100919, "³˹", "Ϳ˾", "׵˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100860, 100862, 100861, "˾", "÷", "ϣ", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100867, 100870, 100868, "ŷּ³", "", "ʷ³", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100871, 100873, 100874, "³", "³", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100894, 100895, 100896, "Ħ", "ĦĦ", "Ħ", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100902, 100903, 100905, "", "Ħ", "˹", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100912, 100911, 100910, "", "˹", "", 0, 0, 0, 2, 2, 2, "", "", ""}, + {100891, 100892, 100893, "֨", "˹˹", "ɸ˹", 0, 0, 0, 2, 2, 2, "", "", ""}, +}; +#endif +BOOL NPC_PetRaceMasterInit( int meindex ) +{ + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_INITPET_LOOPTIME); + CHAR_setInt(meindex, CHAR_WHICHTYPE, CHAR_PETRACEMASTER); + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_Init); + CHAR_setWorkInt(meindex, NPC_WORK_PETGROUP, 0); +#ifdef _DROPSTAKENEW +#else + petracegra[0].payrate1 = 0; + petracegra[0].payrate2 = 0; + petracegra[0].payrate3 = 0; +#endif + return TRUE; +} + +void NPC_PetRaceMasterTalked( int meindex , int talkerindex , char *szMes , int color ) +{ + // ˵Լ״ + if (CHAR_getInt(talkerindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) + return; + if (NPC_Util_isFaceToFace(talkerindex, meindex, 2) == FALSE) + if (NPC_Util_CharDistance(talkerindex, meindex) > 1) + return; + NPC_PetRaceMaster_selectWindow(meindex, talkerindex, 0, -1); +} + +static void NPC_PetRaceMaster_selectWindow(int meindex, int toindex, int num, int select) +{ + char token[1024]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex(toindex); + if (fd == -1) return; + token[0] = '\0'; + switch(num) + { + case 0: + sprintf(token, "4\n\n ᄎٳ\n" + "ãҪ֪ʲ鱨\n" + "\n 쿴Ϸ" + "\n ״" + "\n 뿪"); + buttontype = WINDOW_BUTTONTYPE_NONE; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_PETRACEMASTER_START; + break; + case 1: +#ifdef _DROPSTAKENEW + sprintf(token, + "\nٳ" + "\nμӾٵijֻܹճ" + "\n״ϲע뽫һõIJȯ" + "\nעĺǰٽʱ" + "\n˽Զ֡" + "\nע⣺뿪˷dzʱעIJ" + "\nֽ޷ȡࡣ"); +#else + sprintf(token, + "\nٳ򣺲μӾٵijﹲֻ" + "\nճ״ϲעÿ" + "\nԼʡ뽫ʯҶעĺǰ" + "\nٽʱ˻Զؽ" + "\nϻС" + "\nע⣺н𳬹һǧ򣡵뿪" + "\n˷dzʱעĽ޷ȡࡣ"); +#endif + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_PETRACEMASTER_RULE; + break; + case 2: + { + int petgroup = CHAR_getWorkInt(meindex, NPC_WORK_PETGROUP); + int petindex1 = CHAR_getWorkInt(meindex, NPC_WORK_PET1); + int petindex2 = CHAR_getWorkInt(meindex, NPC_WORK_PET2); + int petindex3 = CHAR_getWorkInt(meindex, NPC_WORK_PET3); + int pet1win = petracegra[petgroup].pet1win; + int pet2win = petracegra[petgroup].pet2win; + int pet3win = petracegra[petgroup].pet3win; + int total = pet1win + pet2win + pet3win; + float winrate1 = 0, winrate2 = 0, winrate3 = 0; +#ifdef _DROPSTAKENEW +#else + char cpayrate1[64], cpayrate2[64], cpayrate3[64]; + if (petracegra[petgroup].payrate1 == 0) + snprintf(cpayrate1, sizeof(cpayrate1), "???"); + else + snprintf(cpayrate1, sizeof(cpayrate1), "%6.2f", petracegra[petgroup].payrate1); + if (petracegra[petgroup].payrate2 == 0) + snprintf(cpayrate2, sizeof(cpayrate2), "???"); + else + snprintf(cpayrate2, sizeof(cpayrate2), "%6.2f", petracegra[petgroup].payrate2); + if (petracegra[petgroup].payrate3 == 0) + snprintf(cpayrate3, sizeof(cpayrate3), "???"); + else + snprintf(cpayrate3, sizeof(cpayrate3), "%6.2f", petracegra[petgroup].payrate3); +#endif + if (total == 0) + { + winrate1 = 0; winrate2 = 0; winrate3 = 0; + } + else + { + winrate1 = (float)pet1win / (float)total; + winrate2 = (float)pet2win / (float)total; + winrate3 = (float)pet3win / (float)total; + } +#ifdef _DROPSTAKENEW + sprintf(token, "״\n\n ʤ ܳ ״ ʤ\n" + "========================================" + "%-10s%-6d%-6d%-8s%-6.2f\n" + "%-10s%-6d%-6d%-8s%-6.2f\n" + "%-10s%-6d%-6d%-8s%-6.2f\n", + CHAR_getChar(petindex1, CHAR_NAME), pet1win, total - pet1win, + petracegra[petgroup].state1, winrate1, + CHAR_getChar(petindex2, CHAR_NAME), pet2win, total - pet2win, + petracegra[petgroup].state2, winrate2, + CHAR_getChar(petindex3, CHAR_NAME), pet3win, total - pet3win, + petracegra[petgroup].state3, winrate3); +#else + sprintf(token, "״\n\n ʤ ܳ ״ ʤ \n" + "========================================" + "%-10s%-6d%-6d%-6s%-6.2f%-4s\n" + "%-10s%-6d%-6d%-6s%-6.2f%-4s\n" + "%-10s%-6d%-6d%-6s%-6.2f%-4s\n", + CHAR_getChar(petindex1, CHAR_NAME), pet1win, total - pet1win, + petracegra[petgroup].state1, winrate1, cpayrate1, + CHAR_getChar(petindex2, CHAR_NAME), pet2win, total - pet2win, + petracegra[petgroup].state2, winrate2, cpayrate2, + CHAR_getChar(petindex3, CHAR_NAME), pet3win, total - pet3win, + petracegra[petgroup].state3, winrate3, cpayrate3); +#endif + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_PETRACEMASTER_PET; + } + break; + case 3: + default: + break; + } + lssproto_WN_send(fd, windowtype, buttontype, windowno, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), token); +} + +void NPC_PetRaceMasterWindowTalked(int meindex, int talkerindex, int seqno, int select, char *data) +{ + int datanum = 0; + makeStringFromEscaped(data); + datanum = atoi(data); + switch(seqno) + { + case CHAR_WINDOWTYPE_PETRACEMASTER_START: + if (datanum == 1) + NPC_PetRaceMaster_selectWindow(meindex, talkerindex, 1, -1); + else if (datanum == 2) + NPC_PetRaceMaster_selectWindow(meindex, talkerindex, 2, -1); + break; + case CHAR_WINDOWTYPE_PETRACEMASTER_RULE: + if (datanum == 3) + NPC_PetRaceMaster_selectWindow(meindex, talkerindex, 1, -1); + case CHAR_WINDOWTYPE_PETRACEMASTER_PET: + case CHAR_WINDOWTYPE_PETRACEMASTER_LEAVE: + default: + break; + } +} + +void NPC_PetRaceMasterLoop( int meindex) +{ + int floor = CHAR_getInt(meindex, CHAR_FLOOR); + time_t t1; + time(&t1); + switch(CHAR_getWorkInt(meindex, NPC_WORK_STATE)) + { + case NPC_State_Init: + // Ѱҳindex + NPC_findRacePetIndex(meindex, floor); + break; + case NPC_State_WaitDropStake: + { + char tmpbuf[256]; + int statechangetime = CHAR_getWorkInt(meindex, NPC_WORK_STATECHANGE); + if (t1 < statechangetime) + { + if (statechangetime - t1 <= 5) + { + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_WAITDROPIV_LOOPTIME); + snprintf(tmpbuf, sizeof(tmpbuf), "%2dҪˣӻԾע", + (int)(statechangetime - t1) % 60); + } + else if (statechangetime - t1 <= 10) + { + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_WAITDROPIII_LOOPTIME); + snprintf(tmpbuf, sizeof(tmpbuf), "%2dҪˣӻԾע", + (int)(statechangetime - t1) % 60); + } + else if (statechangetime - t1 <= 30) + { + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_WAITDROPII_LOOPTIME); + snprintf(tmpbuf, sizeof(tmpbuf), "%2dҪˣӻԾע", + (int)(statechangetime - t1) % 60); + } + else + snprintf(tmpbuf, sizeof(tmpbuf), "%2d%2dҪˣӻԾע", + (int)(statechangetime - t1) / 60, (int)(statechangetime - t1) % 60); + } + if (t1 >= statechangetime) + { +#ifdef _DROPSTAKENEW +#else + float payrate1 = 0, payrate2 = 0, payrate3 = 0; + int pet1gold = 0, pet2gold = 0, pet3gold = 0, totalgold = 0; + int petindex1 = CHAR_getWorkInt(meindex, NPC_WORK_PET1); + int petindex2 = CHAR_getWorkInt(meindex, NPC_WORK_PET2); + int petindex3 = CHAR_getWorkInt(meindex, NPC_WORK_PET3); + int randpet = CHAR_getWorkInt(meindex, NPC_WORK_PETGROUP); + float droprate1 = 0, droprate2 = 0, droprate3 = 0, totaldroprate, Npayrate = PETRACESTDPAYRATE; +#endif + int i = 0; + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_PetRacing); + // 趨治ע + SetCasinoMap(meindex, 0, FALSE); +#ifdef _DROPSTAKENEW + snprintf(tmpbuf, sizeof(tmpbuf), "ֹͣעܿʼޣ"); +#else + // ֪ʣȡóעʣ + GetCasinoMapGold(meindex, PET_RACE1, &pet1gold); + GetCasinoMapGold(meindex, PET_RACE2, &pet2gold); + GetCasinoMapGold(meindex, PET_RACE3, &pet3gold); + totalgold = pet1gold + pet2gold + pet3gold; + if (totalgold <= 0) + { + payrate1 = 2; payrate2 = 2; payrate3 = 2; + } + else + { + if (pet1gold <= PETRACESTDGOLD) + pet1gold = PETRACESTDGOLD; + if (pet2gold <= PETRACESTDGOLD) + pet2gold = PETRACESTDGOLD; + if (pet3gold <= PETRACESTDGOLD) + pet3gold = PETRACESTDGOLD; + totalgold = pet1gold + pet2gold + pet3gold; + droprate1 = totalgold / pet1gold; + droprate2 = totalgold / pet2gold; + droprate3 = totalgold / pet3gold; + totaldroprate = droprate1 + droprate2 + droprate3; + if (totaldroprate / droprate1 > PETRACESTDPAYRATE) + { + payrate1 = 1; Npayrate -= 1; + } + if (totaldroprate / droprate2 > PETRACESTDPAYRATE) + { + payrate2 = 1; Npayrate -= 1; + } + if (totaldroprate / droprate3 > PETRACESTDPAYRATE) + { + payrate3 = 1; Npayrate -= 1; + } + if (payrate1 != 1) + payrate1 = droprate1 / totaldroprate * Npayrate; + if (payrate2 != 1) + payrate2 = droprate2 / totaldroprate * Npayrate; + if (payrate3 != 1) + payrate3 = droprate3 / totaldroprate * Npayrate; + } + petracegra[randpet].payrate1 = payrate1; + petracegra[randpet].payrate3 = payrate2; + petracegra[randpet].payrate2 = payrate3; + SetCasinoPayRate(meindex, PET_RACE1, payrate1); + SetCasinoPayRate(meindex, PET_RACE2, payrate2); + SetCasinoPayRate(meindex, PET_RACE3, payrate3); + snprintf(tmpbuf, sizeof(tmpbuf), "ֹͣעܿʼޣ%sΪ%5.2f%sΪ%5.2f%sΪ%5.2f", + CHAR_getChar(petindex1, CHAR_NAME), payrate1, + CHAR_getChar(petindex2, CHAR_NAME), payrate2, + CHAR_getChar(petindex3, CHAR_NAME), payrate3); +#endif + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_PETRACING_LOOPTIME); + // 趨״̬ + for (i = 0; i < PETRACEPETNUM; i++) + { + CHAR_setWorkInt(CHAR_getWorkInt(meindex, NPC_WORK_PET1 + i), NPC_WORK_STATE, NPC_State_Run); + CHAR_setInt(CHAR_getWorkInt(meindex, NPC_WORK_PET1 + i), CHAR_LOOPINTERVAL, 1000); + } + } + CHAR_talkToFloor(floor, meindex, tmpbuf, CHAR_COLORWHITE); + } + break; + case NPC_State_PetRacing: + if (CHAR_getWorkInt(meindex, NPC_WORK_PETGOAL) == PETRACEPETNUM) + { + char tmpbuf[256]; + int winpetindex = CHAR_getWorkInt(meindex, NPC_WORK_WINPET); + int petgroup = CHAR_getWorkInt(meindex, NPC_WORK_PETGROUP); + snprintf(tmpbuf, sizeof(tmpbuf), "ʤijǣ%s\n", + CHAR_getChar(winpetindex, CHAR_NAME)); + CHAR_talkToFloor(floor, meindex, tmpbuf, CHAR_COLORYELLOW); + // 趨ӮԼ + if (CHAR_getWorkInt(meindex, NPC_WORK_PET1) == winpetindex) + petracegra[petgroup].pet1win = petracegra[petgroup].pet1win + 1; + else if (CHAR_getWorkInt(meindex, NPC_WORK_PET2) == winpetindex) + petracegra[petgroup].pet2win = petracegra[petgroup].pet2win + 1; + else if (CHAR_getWorkInt(meindex, NPC_WORK_PET3) == winpetindex) + petracegra[petgroup].pet3win = petracegra[petgroup].pet3win + 1; + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_ShowWinPet); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_SHOWWINPET_LOOPTIME); + CHAR_setWorkInt(meindex, NPC_WORK_STATECHANGE, t1 + PETRACESHOWWINPET); + // + NPC_givePriceToPlayer(meindex, floor, winpetindex); + } + break; + case NPC_State_ShowWinPet: + { + int statechangetime = CHAR_getWorkInt(meindex, NPC_WORK_STATECHANGE); + if (t1 >= statechangetime) + { + int randpet = RAND(0, arraysizeof(petracegra) - 1); + int petindex1 = CHAR_getWorkInt(meindex, NPC_WORK_PET1); + int petindex2 = CHAR_getWorkInt(meindex, NPC_WORK_PET2); + int petindex3 = CHAR_getWorkInt(meindex, NPC_WORK_PET3); + char tmpbuf[256]; + CHAR_setWorkInt(meindex, NPC_WORK_PETGROUP, randpet); + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_WaitDropStake); + CHAR_setWorkInt(meindex, NPC_WORK_WINPET, 0); + CHAR_setWorkInt(meindex, NPC_WORK_PETGOAL, 0); + CHAR_setWorkInt(meindex, NPC_WORK_STATECHANGE, t1 + PETRACEDROPSTAKETIME); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_WAITDROPI_LOOPTIME); + // 趨ע + SetCasinoMap(meindex, 0, TRUE); + // 趨 + CHAR_setWorkInt(petindex1, NPC_WORK_STATE, NPC_State_Wait); + CHAR_setInt(petindex1, CHAR_LOOPINTERVAL, 1000); + CHAR_setInt(petindex1, CHAR_BASEIMAGENUMBER, petracegra[randpet].pet1gra); + CHAR_setChar(petindex1, CHAR_NAME, petracegra[randpet].pet1name); + + CHAR_setWorkInt(petindex2, NPC_WORK_STATE, NPC_State_Wait); + CHAR_setInt(petindex2, CHAR_LOOPINTERVAL, 1000); + CHAR_setInt(petindex2, CHAR_BASEIMAGENUMBER, petracegra[randpet].pet2gra); + CHAR_setChar(petindex2, CHAR_NAME, petracegra[randpet].pet2name); + + CHAR_setWorkInt(petindex3, NPC_WORK_STATE, NPC_State_Wait); + CHAR_setInt(petindex3, CHAR_LOOPINTERVAL, 1000); + CHAR_setInt(petindex3, CHAR_BASEIMAGENUMBER, petracegra[randpet].pet3gra); + CHAR_setChar(petindex3, CHAR_NAME, petracegra[randpet].pet3name); + // 趨״ +#ifdef _DROPSTAKENEW +#else + petracegra[randpet].payrate1 = 0; + petracegra[randpet].payrate3 = 0; + petracegra[randpet].payrate2 = 0; +#endif + { + int state1 = RAND(0, 3); + int state2 = RAND(0, 3); + int state3 = RAND(0, 3); + if (state1 == 0) + sprintf(petracegra[randpet].state1, ""); + else if (state1 == 1) + sprintf(petracegra[randpet].state1, "ͨ"); + else if (state1 == 2) + sprintf(petracegra[randpet].state1, ""); + else if (state1 == 3) + sprintf(petracegra[randpet].state1, "δ֪"); + if (state2 == 0) + sprintf(petracegra[randpet].state2, ""); + else if (state2 == 1) + sprintf(petracegra[randpet].state2, "ͨ"); + else if (state2 == 2) + sprintf(petracegra[randpet].state2, ""); + else if (state2 == 3) + sprintf(petracegra[randpet].state2, "δ֪"); + if (state3 == 0) + sprintf(petracegra[randpet].state3, ""); + else if (state3 == 1) + sprintf(petracegra[randpet].state3, "ͨ"); + else if (state3 == 2) + sprintf(petracegra[randpet].state3, ""); + else if (state3 == 3) + sprintf(petracegra[randpet].state3, "δ֪"); + } + snprintf(tmpbuf, sizeof(tmpbuf), "ᄎ׼УӻԾע"); + CHAR_talkToFloor(floor, meindex, tmpbuf, CHAR_COLORYELLOW); + } + } + break; + default: + break; + } +} + +void NPC_findRacePetIndex(int meindex, int floor) +{ + int i = 0, j = 0; + time_t t1; + time(&t1); + + if (CHAR_getWorkInt(meindex, NPC_WORK_FINDPETFLAG) == 0) + { + for (i = 0; i < CHAR_getCharNum(); i++) + { + if( !CHAR_CHECKINDEX(i) )continue; + if (CHAR_getInt(i, CHAR_FLOOR) == floor) + { + if (CHAR_getInt(i, CHAR_WHICHTYPE) == CHAR_PETRACEPET) + { + for (j = 0; j < PETRACEPETNUM; j++) + { + if (CHAR_getWorkInt(meindex, NPC_WORK_PET1 + j) == 0) + { + CHAR_setWorkInt(meindex, NPC_WORK_PET1 + j, i); + CHAR_setWorkInt(i, CHAR_NPCWORKINT2, meindex); + break; + } + } + } + } + } + if (CHAR_getWorkInt(meindex, NPC_WORK_PET1) > 0 + && CHAR_getWorkInt(meindex, NPC_WORK_PET2) > 0 + && CHAR_getWorkInt(meindex, NPC_WORK_PET3) > 0) + { + CHAR_setWorkInt(meindex, NPC_WORK_FINDPETFLAG, 1); + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_WaitDropStake); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEMASTER_WAITDROPI_LOOPTIME); + CHAR_setWorkInt(meindex, NPC_WORK_STATECHANGE, t1 + PETRACEDROPSTAKETIME); + } + else CHAR_setWorkInt(meindex, NPC_WORK_FINDPETFLAG, 0); + } +} + +void NPC_givePriceToPlayer(int meindex, int floor, int winpetindex) +{ + int wincasinotype = 0; + if (CHAR_getWorkInt(meindex, NPC_WORK_PET1) == winpetindex) + wincasinotype = PET_RACE1; + else if (CHAR_getWorkInt(meindex, NPC_WORK_PET2) == winpetindex) + wincasinotype = PET_RACE2; + else if (CHAR_getWorkInt(meindex, NPC_WORK_PET3) == winpetindex) + wincasinotype = PET_RACE3; + if (wincasinotype == 0) return; + else + CasinoPay(meindex, wincasinotype); +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petracepet.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petracepet.c new file mode 100644 index 0000000..8eb5a42 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petracepet.c @@ -0,0 +1,291 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "handletime.h" + +#ifdef _PETRACE +#include "npc_petracepet.h" + +#define PETRACEPET_WAIT_LOOPTIME 30000 // 30 +#define PETRACEPET_SHOWWIN_LOOPTIME 10000 // 10 + +static void NPC_PetRacePet_Walk(int meindex); +static int NPC_PetRacePetSetPoint(int meindex, char *argstr); + +enum +{ + NPC_WORK_STATE = CHAR_NPCWORKINT1, + NPC_WORK_MASTER = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT4, + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT5, + NPC_WORK_WAITFLAG = CHAR_NPCWORKINT6, + NPC_WORK_FLOOR = CHAR_NPCWORKINT7, + NPC_WORK_X = CHAR_NPCWORKINT8, + NPC_WORK_Y = CHAR_NPCWORKINT9, + NPC_WORK_DIR = CHAR_NPCWORKINT10, + NPC_WORK_STOPX = CHAR_NPCWORKINT11, + NPC_WORK_STOPY = CHAR_NPCWORKINT12, +}; +enum +{ + NPC_State_Wait, + NPC_State_Run, + NPC_State_ShowWin, +}; + +int raceflag=0; + +BOOL NPC_PetRacePetInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + int showstopx, showstopy; + int routenum = 0, i = 0; + + NPC_Util_GetArgStr(meindex, argstr, sizeof(argstr)); + for (i = 1; i <= routenum; i++) + { + char routetostring[64]; + snprintf(routetostring, sizeof(routetostring), "routeto"); + if (NPC_Util_GetStrFromStrWithDelim(argstr, routetostring, buf, sizeof(buf)) == NULL) + { + print("Init_npcracepet: Didn't set route\n"); + return FALSE; + } + } + showstopx = NPC_Util_GetNumFromStrWithDelim(argstr, "showstopx"); + showstopy = NPC_Util_GetNumFromStrWithDelim(argstr, "showstopy"); + if (showstopx < 0 || showstopx > 100 || showstopy < 0 || showstopy > 100) + return FALSE; + CHAR_setInt(meindex, CHAR_WHICHTYPE, CHAR_PETRACEPET); + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_Wait); + CHAR_setWorkInt(meindex, NPC_WORK_ROUTEPOINT, 2); + CHAR_setWorkInt(meindex, NPC_WORK_WAITFLAG, 1); + CHAR_setWorkInt(meindex, NPC_WORK_FLOOR, CHAR_getInt(meindex, CHAR_FLOOR)); + CHAR_setWorkInt(meindex, NPC_WORK_X, CHAR_getInt(meindex, CHAR_X)); + CHAR_setWorkInt(meindex, NPC_WORK_Y, CHAR_getInt(meindex, CHAR_Y)); + CHAR_setWorkInt(meindex, NPC_WORK_DIR, CHAR_getInt(meindex, CHAR_DIR)); + CHAR_setWorkInt(meindex, NPC_WORK_STOPX, showstopx); + CHAR_setWorkInt(meindex, NPC_WORK_STOPY, showstopy); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEPET_WAIT_LOOPTIME); + NPC_PetRacePetSetPoint(meindex, argstr); + + return TRUE; +} + +void NPC_PetRacePetTalked( int meindex , int talkerindex , char *szMes , int color ) +{ +} + +void NPC_PetRacePetLoop( int meindex) +{ + switch(CHAR_getWorkInt(meindex, NPC_WORK_STATE)) + { + case NPC_State_Wait: + { + if (CHAR_getWorkInt(meindex, NPC_WORK_WAITFLAG) == 0) + { + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + NPC_Util_GetArgStr(meindex, argstr, sizeof(argstr)); + CHAR_setWorkInt(meindex, NPC_WORK_ROUTEPOINT, 2); + NPC_PetRacePetSetPoint(meindex, argstr); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEPET_WAIT_LOOPTIME); + CHAR_setInt(meindex, CHAR_DIR, CHAR_getWorkInt(meindex, NPC_WORK_DIR)); + CHAR_warpToSpecificPoint(meindex, + CHAR_getWorkInt(meindex, NPC_WORK_FLOOR), + CHAR_getWorkInt(meindex, NPC_WORK_X), + CHAR_getWorkInt(meindex, NPC_WORK_Y)); + CHAR_setWorkInt(meindex, NPC_WORK_WAITFLAG, 1); + } + } + break; + case NPC_State_Run: + { + int interval = 50; + int random = 0; + if (CHAR_getWorkInt(meindex, NPC_WORK_ROUTETOX) <= CHAR_getWorkInt(meindex, NPC_WORK_STOPX) + && CHAR_getWorkInt(meindex, NPC_WORK_ROUTETOY) >= CHAR_getWorkInt(meindex, NPC_WORK_STOPY)) + random = 3; + else + random = RAND(0, 8); + if (random == 0) // + { + int rands = RAND(0, 3); + interval = 1500; + CHAR_sendAction(meindex, 0, FALSE); + if (rands == TRUE) + { + char tmpbuf[256]; + int floor = CHAR_getInt(meindex, CHAR_FLOOR); + int master = CHAR_getWorkInt(meindex, NPC_WORK_MASTER); + int randomi = RAND(1, 9); + if (randomi == 1) + snprintf(tmpbuf, sizeof(tmpbuf), "Ŷ%sࡣ", + CHAR_getChar(meindex, CHAR_NAME)); + else if (randomi == 2) + snprintf(tmpbuf, sizeof(tmpbuf), "%sʹ˷һ", + CHAR_getChar(meindex, CHAR_NAME)); + else if (randomi == 3) + snprintf(tmpbuf, sizeof(tmpbuf), "...%sŭˣ", + CHAR_getChar(meindex, CHAR_NAME)); + if (randomi > 0 && randomi < 4) + CHAR_talkToFloor(floor, master, tmpbuf, CHAR_COLORWHITE); + } + } + else if (random == 1) // ε + { + int rands = RAND(0, 3); + interval = 2500; + CHAR_sendAction(meindex, 2, FALSE); + if (rands == TRUE) + { + char tmpbuf[256]; + int floor = CHAR_getInt(meindex, CHAR_FLOOR); + int master = CHAR_getWorkInt(meindex, NPC_WORK_MASTER); + int randomi = RAND(1, 9); + if (randomi == 1) + snprintf(tmpbuf, sizeof(tmpbuf), "%sε...", + CHAR_getChar(meindex, CHAR_NAME)); + else if (randomi == 2) + snprintf(tmpbuf, sizeof(tmpbuf), "%s", + CHAR_getChar(meindex, CHAR_NAME)); + else if (randomi == 3) + snprintf(tmpbuf, sizeof(tmpbuf), "...%sε¸ҵˣ", + CHAR_getChar(meindex, CHAR_NAME)); + if (randomi > 0 && randomi < 4) + CHAR_talkToFloor(floor, master, tmpbuf, CHAR_COLORWHITE); + } + } + else if (random == 2) // վ + { + interval = 500; + CHAR_sendAction(meindex, 3, FALSE); + } + else // һ + interval = RAND(20, 100); + NPC_PetRacePet_Walk(meindex); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, interval); + } + break; + case NPC_State_ShowWin: + { + int action = RAND(0, 11); + CHAR_sendAction(meindex, action, FALSE); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, PETRACEPET_SHOWWIN_LOOPTIME); + } + break; + default: + break; + } +} + +static void NPC_PetRacePet_Walk(int meindex) +{ + POINT start, end; + int dir, i; + + start.x = CHAR_getInt(meindex, CHAR_X); + start.y = CHAR_getInt(meindex, CHAR_Y); + end.x = CHAR_getWorkInt(meindex, NPC_WORK_ROUTETOX); + end.y = CHAR_getWorkInt(meindex, NPC_WORK_ROUTETOY); + if (start.x == end.x && start.y == end.y) + { + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + NPC_Util_GetArgStr(meindex, argstr, sizeof( argstr)); + CHAR_setWorkInt(meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt(meindex, NPC_WORK_ROUTEPOINT) + 1); + + if (NPC_PetRacePetSetPoint(meindex, argstr) == FALSE) + { + // Ŀĵᣬʼ״̬ + char tmpbuf[256]; + int masterindex = CHAR_getWorkInt(meindex, NPC_WORK_MASTER); + int petgoal = CHAR_getWorkInt(masterindex, CHAR_NPCWORKINT9); + int floor = CHAR_getInt(masterindex, CHAR_FLOOR); + if (CHAR_getWorkInt(masterindex, CHAR_NPCWORKINT8) == 0) + { + CHAR_warpToSpecificPoint(meindex, 7005,42,44); + CHAR_setWorkInt(masterindex, CHAR_NPCWORKINT8, meindex); + CHAR_sendAction(meindex, 3, FALSE); + snprintf(tmpbuf, sizeof(tmpbuf), "ȵĿĵص...%s", + CHAR_getChar(meindex, CHAR_NAME)); + raceflag++; + } + else + { + if(raceflag == 1) + { + //ͻصָ + CHAR_warpToSpecificPoint(meindex, 7005,43,47); + snprintf(tmpbuf, sizeof(tmpbuf), "ŵĿĵص...%s", + CHAR_getChar(meindex, CHAR_NAME)); + raceflag++; + } + else + { + //һĴͣʼ + CHAR_warpToSpecificPoint(meindex, 7005,45,44); + snprintf(tmpbuf, sizeof(tmpbuf), "󵽴Ŀĵص...%s", + CHAR_getChar(meindex, CHAR_NAME)); + raceflag=0; + } + } + CHAR_setWorkInt(meindex, NPC_WORK_STATE, NPC_State_ShowWin); + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, 500); + CHAR_setWorkInt(meindex, NPC_WORK_WAITFLAG, 0); + CHAR_setWorkInt(masterindex, CHAR_NPCWORKINT9, petgoal + 1); + CHAR_talkToFloor(floor, masterindex, tmpbuf, CHAR_COLORWHITE); + return; + } + else + return; + } + dir = NPC_Util_getDirFromTwoPoint(&start, &end); + end.x = CHAR_getInt(meindex, CHAR_X); + end.y = CHAR_getInt(meindex, CHAR_Y); + for(i = 0; i < 100; i++) + { + if (dir < 0) + dir = RAND(0, 7); + dir = NPC_Util_SuberiWalk(meindex, dir); + if (dir >= 0 && dir <= 7) break; + } + if (dir >= 0 && dir <= 7) + { + int result = 0; + result = CHAR_walk(meindex, dir, 0); + } +} + +static int NPC_PetRacePetSetPoint(int meindex, char *argstr) +{ + // Ѱһ x , y + char buf[4096], buf2[256], buf3[256]; + int ret; + char routetostring[64]; + snprintf(routetostring, sizeof(routetostring), "routeto"); + if (NPC_Util_GetStrFromStrWithDelim(argstr, routetostring, buf, sizeof(buf)) == NULL) + { + print("SetPoint_npcracepet: Didn't set route %s\n", routetostring); + return FALSE; + } + ret = getStringFromIndexWithDelim(buf, ";", + CHAR_getWorkInt(meindex, NPC_WORK_ROUTEPOINT), buf2, sizeof(buf2)); + if (ret == FALSE) return FALSE; + ret = getStringFromIndexWithDelim(buf2, ",", 1, buf3, sizeof(buf3)); + if (ret == FALSE) return FALSE; + CHAR_setWorkInt(meindex, NPC_WORK_ROUTETOX, atoi(buf3)); + ret = getStringFromIndexWithDelim(buf2, ",", 2, buf3, sizeof(buf3)); + if (ret == FALSE) return FALSE; + CHAR_setWorkInt(meindex, NPC_WORK_ROUTETOY, atoi(buf3)); + return TRUE; +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petshop.c new file mode 100644 index 0000000..f4b9a51 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petshop.c @@ -0,0 +1,1563 @@ +#include "version.h" +#include +#include "char.h" +#include "configfile.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "pet_skill.h" +#include "readmap.h" +#include "battle.h" +#include "npc_petshop.h" +#include "log.h" +/* ⼰enum */ +enum { + NPC_PETSHOP_MSG_OVER, + NPC_PETSHOP_MSG_MAIN, + NPC_PETSHOP_MSG_REALY, + NPC_PETSHOP_MSG_THANKS, + NPC_PETSHOP_MSG_COST, + NPC_PETSHOP_MSG_POOLTHANKS, + NPC_PETSHOP_MSG_POOLFULL, + NPC_PETSHOP_MSG_GETFULL, +}; +typedef struct { + char option[32]; + char defaultmsg[128]; +}NPC_PETSHOP_MSG; + +NPC_PETSHOP_MSG shopmsg[] = { + { "over_msg", "Ǯ!û?"}, + { "main_msg", "ӭ"}, + { "realy_msg", "Ŀ?"}, + { "thanks_msg", "лл!"}, + { "cost_msg", "Ǯ!"}, + { "pooltanks_msg", "лл!"}, + { "poolfull_msg", "޷"}, + { "getfull_msg", "㲻кܶ"} + +}; + +#define PETCOST 10 +int NPC_DepotPet_CheckRepeat( int charaindex); +int NPC_DepotPet_CheckLevel(int meindex,int talker,int select,char *token); +void NPC_PetDate(int meindex,int toindex,int select,char *token); +void NPC_PetDate2(int meindex,int talker,int select,char *token); +void NPC_PetDate3(int meindex,int talker,int select,char *token); +void NPC_PetDel2( int meindex, int talker, int select, char *token); +void NPC_PetDel3( int meindex, int talker, int select, char *token); +void NPC_getDrawPet( int meindex, int toindex, char *token, int *buttontype, int select); + +int NPC_GetCost(int meindex,int talker,int petindex); +void NPC_PetDel(int meindex, int toindex,int select,char* token); +void NPC_MaxGoldOver(int meindex,int toindex,int select,char *token); + +#ifdef _NPC_DEPOTPET +void NPC_PoolPetShop_DepotPet_Menu( int meindex, int talkerindex); +void NPC_DepotPet_List( int meindex, int toindex, char *token, int *buttontype, int select); +void NPC_DepotPet_Add( int meindex, int talker, int select, char *token); +void NPC_DepotPet_Get( int meindex, int talker, int select, char *token); +void NPC_DepotPet_AskGet(int meindex,int talker,int select,char *token); +//void NPC_DepotPet_Pet_printWindow( int meindex, int talkerindex); +//void NPC_DepotPet_Depot_printWindow( int meindex, int talkerindex); +//BOOL NPC_DepotPet_InsertPet( int meindex, int talkerindex, int num); +//BOOL NPC_DepotPet_getPet( int meindex, int talkerindex, int num); +#endif +void NPC_DepotPet_CheckRepeat_del( int charaindex, int petindex); + +// ľźңֿ +#define NPC_GETPOOLCOST( talker) ( 50 + CHAR_getInt( talker, CHAR_LV)*4) + +// ľŷɻ +#define NPC_PETSHOP_POOLCOST_DEFAULT 200 + +/*-- --*/ +enum { + CHAR_WORK_NOMALRATE = CHAR_NPCWORKINT1, + CHAR_WORK_SPECIALRATE = CHAR_NPCWORKINT2, + CHAR_WORK_POOLCOST = CHAR_NPCWORKINT3, + CHAR_WORK_POOLFLG = CHAR_NPCWORKINT4, +}; + +int petshophanlde; + +/********************************* +* +*********************************/ +BOOL NPC_PetShopInit( int meindex ) +{ + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + double rate; + int intrate; +// int cost; + int tmp; + + /*--ɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPESTONESHOP ); + + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg)) == NULL){ + print("GetArgStrErr"); + return FALSE; + } + + /*--ë炙巤ʢ*/ + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "nomal_rate", buf, sizeof( buf)) != NULL){ + rate = atof( buf); + intrate = ( int)( rate *1000); + CHAR_setWorkInt( meindex , CHAR_WORK_NOMALRATE ,intrate ); + }else{ + CHAR_setWorkInt( meindex , CHAR_WORK_NOMALRATE ,1000 ); + } + + + /*--ʸһַʢ--*/ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "special_rate", buf, sizeof( buf))!=NULL) + { + rate = atof( buf); + intrate = ( int)( rate *1000); + CHAR_setWorkInt( meindex , CHAR_WORK_SPECIALRATE ,intrate ); + }else{ + CHAR_setWorkInt( meindex , CHAR_WORK_SPECIALRATE ,1200 ); + } + + // ľŷʢ + //cost = NPC_Util_GetNumFromStrWithDelim( npcarg, "pool_cost"); + //if( cost == -1 ) cost = NPC_PETSHOP_POOLCOST_DEFAULT; + //CHAR_setWorkInt( meindex, CHAR_WORK_POOLCOST, cost); + + + // ľ ¾ëʢ + tmp = NPC_Util_GetNumFromStrWithDelim( npcarg, "pool_flg"); + if( tmp != 1 ) tmp = 0; + CHAR_setWorkInt( meindex, CHAR_WORK_POOLFLG, tmp); + + + petshophanlde=meindex; + return TRUE; + +} + + + + +/********************************* +* ƾľݼ +*********************************/ +void NPC_PetShopTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /*-- ¾--*/ + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + /* */ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + /*--ͼ--*/ + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,0); + /*-Ԫ --*/ + NPC_PetShop_selectWindow( meindex, talkerindex,0,-1); +} + +/********************************* +* έľݼ +*********************************/ +void NPC_PetShopLooked( int meindex , int lookedindex) +{ + /* 帲ƻ ɱ */ + if( CHAR_getInt( lookedindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + /* */ + if( NPC_Util_CharDistance( lookedindex, meindex ) > 2) return; + + /*--ͼ--*/ +// CHAR_setWorkInt(lookedindex,CHAR_WORKSHOPRELEVANT,0); + + +// NPC_PetShop_selectWindow( meindex, lookedindex,0,-1); + +} + +void NPC_PetShop_selectWindow( int meindex, int toindex, int num,int select) +{ + char token[1024]; + int buttontype=0,windowtype=0,windowno=0; + char buf[256]; + int fd = getfdFromCharaIndex( toindex); + + //print("\n NPC_PetShop_selectWindow num:%d select:%d ", num, select); + if( fd == -1 ) { + fprint( "getfd err\n"); + return; + } + if (CHAR_getWorkInt(toindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE){ + CHAR_talkToCli( toindex, -1, "޷ʹó̵!", CHAR_COLORRED); + return; + } + + + + token[0] = '\0'; + switch(num){ + // ټū + case 0: + NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_MAIN, buf); + +#ifdef _NPC_DEPOTPET + if( !CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG)) { + sprintf(token, "4\n̵" + "%s" + "\n" + "\n " + "\n" + "\n" + "\n 뿪 ", + buf); + }else { + sprintf(token, "4\n̵" + "%s" + "\n ķų " + "\n ȡ " + "\n " + "\n ʹòֿ " + "\n 뿪 ", + buf); + } +#else + if( !CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG)) { + sprintf(token, "4\n̵" + "%s" + "\n" + "\n " + "\n" + "\n 뿪 ", + buf); + }else { + sprintf(token, "4\n̵" + "%s" + "\n ķų " + "\n ȡ " + "\n " + "\n 뿪 ", + buf); + } +#endif + buttontype=WINDOW_BUTTONTYPE_NONE; + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_START; + break; + case 1: +#ifdef _ITEM_PET_LOCKED + if(CHAR_getInt(toindex, CHAR_LOCKED)==1){ + char message[256]; + char buf[256]; + sprintf( message, "ΪȷƷȫİȫн\n"); + + lssproto_WN_send( getfdFromCharaIndex(toindex), WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT, + WINDOW_BUTTONTYPE_OKCANCEL, + CHAR_WINDOWTYPE_ITEM_PET_LOCKED, + -1, + makeEscapeString( message, buf, sizeof(buf))); + + return; + } +#endif + buttontype=WINDOW_BUTTONTYPE_CANCEL; + windowtype=WINDOW_MESSAGETYPE_PETSELECT; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT; + break; + case 2: + + NPC_PetDate(meindex,toindex,select,token); + buttontype=WINDOW_BUTTONTYPE_YESNO; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN; + break; + case 3: + if( (CHAR_getInt(toindex,CHAR_GOLD)+CHAR_getWorkInt(toindex,CHAR_WORKSHOPRELEVANTSEC)) + > CHAR_getMaxHaveGold( toindex) ){ + + NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_OVER, token); + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_GOLDOVER; + buttontype=WINDOW_BUTTONTYPE_YESNO; + }else{ + NPC_PetDel(meindex,toindex,select,token); + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + } + + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + break; + case 4: + NPC_PetDel(meindex,toindex,select,token); + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + break; + case 5: // ȡķųб + if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) + return; + buttontype=WINDOW_BUTTONTYPE_CANCEL; + windowtype=WINDOW_MESSAGETYPE_PETSELECT; + windowno=CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT2; + break; + case 6: + if( CHAR_getInt( toindex, CHAR_GOLD) + < NPC_GETPOOLCOST( toindex)) + { + NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); + buttontype = WINDOW_BUTTONTYPE_OK; + } + else { + NPC_PetDate2( meindex, toindex, select, token); + buttontype = WINDOW_BUTTONTYPE_YESNO; + } + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN2; + break; + + case 7: + if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) + return; + if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)){ + NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); + }else { + NPC_PetDel2( meindex, toindex, select, token); + } + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + break; + // ľ + case 8: + NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_POOLFULL, token); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + break; + // ¦Իʸ ū + case 9: // ȡķųб + if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG) != 1 ) + return; + NPC_getDrawPet( meindex, toindex, token, &buttontype, select); + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_DRAWSELECT; + break; + // ¦Ի + case 10: + NPC_PetDate3( meindex, toindex, select, token); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_ASKDRAW; + break; + // ߯ + case 11: + if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) + return; + NPC_PetDel3( meindex, toindex, select, token); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + break; + // ʸ + case 12: + NPC_MaxGoldOver( meindex, toindex, NPC_PETSHOP_MSG_GETFULL, token); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + break; +#ifdef _NPC_DEPOTPET + case 13: // ֿб + if( !CHAR_CheckDepotPet( toindex) ) + return; + buttontype=WINDOW_BUTTONTYPE_CANCEL; + windowtype=WINDOW_MESSAGETYPE_PETSELECT; + windowno=CHAR_WINDOWTYPE_DEPOTPETSHOP_ADD; + break; + case 14: // ȡֿб + if( !CHAR_CheckDepotPet( toindex) ) + return; + NPC_DepotPet_List( meindex, toindex, token, &buttontype, select); + //buttontype=WINDOW_BUTTONTYPE_CANCEL; + windowtype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_GET; + break; + + case 15: // ѯȷϴֿ + if( CHAR_getInt( toindex, CHAR_GOLD) + < NPC_GETPOOLCOST( toindex)) + { + NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); + buttontype = WINDOW_BUTTONTYPE_OK; + } + else { + NPC_PetDate2( meindex, toindex, select, token); + buttontype = WINDOW_BUTTONTYPE_YESNO; + } + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKADD; + break; + + case 16: // ѯȷȡֿ + NPC_DepotPet_AskGet( meindex, toindex, select, token); + + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKGET; + break; + + case 17: // ȷϴֿ + if( !CHAR_CheckDepotPet(toindex) ) + return; + if( CHAR_getInt( toindex, CHAR_GOLD) < NPC_GETPOOLCOST( toindex)){ + NPC_MaxGoldOver(meindex, toindex, NPC_PETSHOP_MSG_COST, token); + }else { + NPC_DepotPet_Add( meindex, toindex, select, token); + } + + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + break; + + case 18: // ȷȡֿ + if( CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG ) != 1 ) + return; + if( NPC_DepotPet_CheckLevel( meindex, toindex, select, token) == TRUE) { + NPC_DepotPet_Get( meindex, toindex, select, token); + + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + } + else { + sprintf( token, "\n޷չֻ"); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_WINDOWPETSHOP_END; + } + break; +#endif + // CoolFish: Add 2001/7/4 + default: + break; + + } + + /*--޵--*/ + //makeEscapeString( token, escapedname, sizeof(escapedname)); + + /*--˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +void NPC_PetShopWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int datanum = -1; +// if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { +// return; +// } + //print("\n NPC_PetShopWindowTalked: data:%s seq:%d sel:%d ", data, seqno, select); + + makeStringFromEscaped( data); + + datanum = atoi( data); + switch( seqno){ + case CHAR_WINDOWTYPE_WINDOWPETSHOP_START: + { + int poolflg = CHAR_getWorkInt( meindex, CHAR_WORK_POOLFLG); + if( ( datanum == 3 && poolflg) || // + ( datanum == 2 && !poolflg ) ){ // ȡ + NPC_PetShop_selectWindow( meindex, talkerindex, 1, -1 ); + }else if( datanum == 1 && poolflg) { // ķų + if( CHAR_getCharPoolPetElement( talkerindex) != -1 ) { + NPC_PetShop_selectWindow( meindex, talkerindex, 5, -1 ); + } + else { + NPC_PetShop_selectWindow( meindex, talkerindex, 8, -1 ); + } + }else if( datanum == 2 && poolflg ) { // ȡ + if( CHAR_getCharPetElement( talkerindex) != -1 ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_PetShop_selectWindow( meindex, talkerindex, 9, 0); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 12, -1 ); + } + } +#ifdef _NPC_DEPOTPET + else if( datanum == 4 ) { // ʹóֿ + //print(" ʹóֿ "); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + if( !CHAR_CheckDepotPet( talkerindex) ){ + CHAR_GetDepotPet( meindex, talkerindex); + CHAR_talkToCli( talkerindex, -1, "ȡóᣡ", CHAR_COLORYELLOW); + }else{ + NPC_PoolPetShop_DepotPet_Menu( meindex, talkerindex); + } + } +#endif + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT: + if(select==WINDOW_BUTTONTYPE_CANCEL){ + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + + }else{ + NPC_PetShop_selectWindow( meindex, talkerindex, 2, datanum ); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_PETSELECT2: + if(select==WINDOW_BUTTONTYPE_CANCEL){ + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + }else{ + NPC_PetShop_selectWindow( meindex, talkerindex, 6, datanum ); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN: + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_PetShop_selectWindow( meindex, talkerindex, 3,-1 ); + }else{ + NPC_PetShop_selectWindow( meindex, talkerindex,1,-1); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_MAIN2: + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_PetShop_selectWindow( meindex, talkerindex, 7,-1 ); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex,5,-1); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_ASKDRAW: + if( select == WINDOW_BUTTONTYPE_YES){ + if( CHAR_getCharPetElement( talkerindex) != -1 ) { + NPC_PetShop_selectWindow( meindex, talkerindex, 11,-1 ); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 12, -1 ); + } + }else { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_PetShop_selectWindow( meindex, talkerindex, 9, 0); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_GOLDOVER: + if( select == WINDOW_BUTTONTYPE_YES){ + NPC_PetShop_selectWindow( meindex, talkerindex, 4,-1 ); + }else{ + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + } + break; + case CHAR_WINDOWTYPE_WINDOWPETSHOP_DRAWSELECT: + if( select == WINDOW_BUTTONTYPE_PREV){ + NPC_PetShop_selectWindow( meindex, talkerindex, 9, -1); + }else if( select == WINDOW_BUTTONTYPE_NEXT) { + NPC_PetShop_selectWindow( meindex, talkerindex, 9, 1); + }else if( select != WINDOW_BUTTONTYPE_CANCEL) { + if( CHAR_getCharPetElement( talkerindex) != -1 ) { + NPC_PetShop_selectWindow( meindex, talkerindex, 10, datanum); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 12, -1 ); + } + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + } + break; + +#ifdef _NPC_DEPOTPET + case CHAR_WINDOWTYPE_DEPOTPETSHOP_HANDLE: + if( !CHAR_CheckDepotPet( talkerindex) ) return ; + switch( datanum ) { + case 1:// + if( CHAR_findEmptyDepotPet( talkerindex) == -1 ){ + CHAR_talkToCli( talkerindex, -1, "ֿ", CHAR_COLORYELLOW); + return; + } + //NPC_DepotPet_Pet_printWindow( meindex, talkerindex); + NPC_PetShop_selectWindow( meindex, talkerindex, 13, -1 ); + break; + case 2://ȡ + if( CHAR_getCharPetElement( talkerindex) < 0 ) { + CHAR_talkToCli( talkerindex, -1, "ϳλ", CHAR_COLORYELLOW); + return; + } + NPC_PetShop_selectWindow( meindex, talkerindex, 14, 0); + break; + case 0: + NPC_PetShop_selectWindow( meindex, talkerindex, 0, -1); + break; + } + break; + + case CHAR_WINDOWTYPE_DEPOTPETSHOP_ADD: + if(select==WINDOW_BUTTONTYPE_CANCEL){ + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + }else{ + NPC_PetShop_selectWindow( meindex, talkerindex, 15, datanum ); + } + break; + + case CHAR_WINDOWTYPE_DEPOTPETSHOP_GET: + if( select == WINDOW_BUTTONTYPE_PREV){ + NPC_PetShop_selectWindow( meindex, talkerindex, 14, -1); + }else if( select == WINDOW_BUTTONTYPE_NEXT) { + NPC_PetShop_selectWindow( meindex, talkerindex, 14, 1); + }else if( select != WINDOW_BUTTONTYPE_CANCEL) { + if( CHAR_getCharPetElement( talkerindex) != -1 ) { + NPC_PetShop_selectWindow( meindex, talkerindex, 16, datanum); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 12, -1 ); + } + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + } + + break; + case CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKADD: // ȷϴֿ + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_PetShop_selectWindow( meindex, talkerindex, 17,-1 ); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex,13,-1); + } + break; + + case CHAR_WINDOWTYPE_DEPOTPETSHOP_ASKGET: // ȷȡֿ + if( select == WINDOW_BUTTONTYPE_YES){ + if( CHAR_getCharPetElement( talkerindex) != -1 ) { + NPC_PetShop_selectWindow( meindex, talkerindex, 18,-1 ); + }else { + NPC_PetShop_selectWindow( meindex, talkerindex, 12, -1 ); + } + }else { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_PetShop_selectWindow( meindex, talkerindex, 14, 0); + } + break; +#endif + + case CHAR_WINDOWTYPE_WINDOWPETSHOP_END: + if( select == WINDOW_BUTTONTYPE_OK){ + NPC_PetShop_selectWindow( meindex, talkerindex, 0,-1 ); + } + break; + + // CoolFish: Add 2001/7/4 + default: + break; + + } +} + +void NPC_PetDate(int meindex,int talker,int select,char *token) +{ + + int petindex; + int cost; + char *petname; + char buf[1024]; + + /*--ͼ--*/ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,select); + + petindex = CHAR_getCharPet( talker, select-1); + + + if( !CHAR_CHECKINDEX(petindex) ) return; + + NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_REALY, buf); + + cost=NPC_GetCost(meindex,talker,petindex); + + petname = CHAR_getUseName( petindex); + + sprintf(token,"\n[%s]ûɣ""%s" + "\n\n ۸ %d STONE\n" + ,petname,buf,cost); + +} + +void NPC_PetDate2(int meindex,int talker,int select,char *token) +{ + + int petindex; + char *petname; + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,select); + + petindex = CHAR_getCharPet( talker, select-1); + if( !CHAR_CHECKINDEX(petindex) ) return; + petname = CHAR_getUseName( petindex); + sprintf(token,"\nķ[%s]" + "\n\n ķż۸ %d stone\n" + ,petname, NPC_GETPOOLCOST( talker) + ); +} + +void NPC_PetDate3(int meindex,int talker,int select,char *token) +{ + int poolindex; + int petindex; + char *petname; + poolindex = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) * 5 + select - 1; + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,poolindex ); + petindex = CHAR_getCharPoolPet( talker, poolindex); + if( !CHAR_CHECKINDEX(petindex) ) return; + petname = CHAR_getUseName( petindex); + sprintf(token,"\n[%s]", petname); +} + +int NPC_GetCost(int meindex,int talker,int petindex) +{ + int cost; + int levelcost; + int level; + int getlevel; + int graNo; + int rare; + int charm=50; + int petai; + int i=1; + double rate=1.0; + int intrate; + char buf[1024]; + char buff2[128]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + + + getlevel=CHAR_getInt(petindex,CHAR_PETGETLV); + level=CHAR_getInt(petindex,CHAR_LV); + graNo=CHAR_getInt(petindex,CHAR_BASEBASEIMAGENUMBER); + rare=CHAR_getInt(petindex,CHAR_RARE); + + if(getlevel==0) getlevel=1 ; + + /*--ëƻ--*/ + levelcost=(level*level)*10; + getlevel=(getlevel*getlevel)*10; +// Syu ADD ޸תǮ为bug +#ifdef _PET_2TRANS + if( CHAR_getInt(petindex , CHAR_TRANSMIGRATION)>0) +#else + if( CHAR_getInt(petindex , CHAR_TRANSMIGRATION)==1) +#endif + getlevel=10; + + + if(rare==0){ rare=1; + }else if(rare==1){ rare=5; + }else if(rare==2){ rare=8;} + + cost = ((levelcost-getlevel)+(level*PETCOST))*rare; + intrate = CHAR_getWorkInt( meindex , CHAR_WORK_NOMALRATE); + rate=(double) intrate / 1000; + + + NPC_Util_GetStrFromStrWithDelim( npcarg, "special_pet", buf, sizeof( buf)); + + i=1; + /*--ʸһƥңľʸëԻ ʸ϶÷ į)--*/ + while( getStringFromIndexWithDelim(buf,",",i,buff2,sizeof(buff2)) !=FALSE ) + { + if(strstr( buff2, "-")==NULL){ + if(graNo == atoi(buff2)){ + intrate=CHAR_getWorkInt( meindex , CHAR_WORK_SPECIALRATE); + rate=(double) intrate / 1000; + break; + } + }else{ + /*--ʧ ة 15-25 ƥľ--*/ + int start; + int end; + int tmp; + int graflg=0; + char token2[128]; + + /*-"-"ƥľ炙Ѱ Ѱë --*/ + getStringFromIndexWithDelim( buff2, "-", 1, token2, sizeof(token2)); + start = atoi( token2); + getStringFromIndexWithDelim( buff2, "-", 2 ,token2, sizeof(token2)); + end = atoi( token2); + + /*-- įѱئȻգ ľ׸**/ + if(start > end){ + tmp=start; + start=end; + end=tmp; + } + + end++; + /*--"-"ƥľмʧ ة ë --*/ + if(start <= graNo && graNo < end){ + intrate=CHAR_getWorkInt( meindex , CHAR_WORK_SPECIALRATE); + rate=(double) intrate / 1000; + graflg=1; + break; + } + + if(graflg ==1) break; + } + i++; + } + + /*--ʸպë ---*/ + petai=CHAR_getWorkInt(petindex,CHAR_WORKFIXAI); + + /*-- ë--*/ + charm = CHAR_getWorkInt(talker,CHAR_WORKFIXCHARM); + + /*-- պ / */ + charm = charm + petai; + + if(charm < 20){ + charm = 20; + } + + charm = charm / 2; + + cost = (int)cost*rate; + + rate=(double)charm/100; + + /*-- --*/ + cost = cost * rate; + + if(cost > 1000000)cost = 1000000; + + + /*--ëʢ--*/ + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,cost); + + return cost; +} + + +#if 1 + +void NPC_PetDel(int meindex, int talker,int select,char* token) +{ + int petindex; + int petsel; + char szPet[128]; + int cost; + int defpet; + int fd = getfdFromCharaIndex( talker ); + + NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_THANKS, token); + petsel=(CHAR_getWorkInt(talker,CHAR_WORKSHOPRELEVANT)-1); + petindex = CHAR_getCharPet( talker, petsel); + + if( !CHAR_CHECKINDEX(petindex) ) return; + + // CoolFish: Family 2001/6/14 + if (CHAR_getInt(petindex, CHAR_PETFAMILY) == 1){ +/* char buf[1024]; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString("\n\nܱǸػ޷ร\nԼúչˣ", buf, sizeof(buf))); +*/ + sprintf(token,"\n\nܱǸػ޷ร\nԼúչˣ"); + return; + } + + // Robin 0725 + if (CHAR_getInt( talker, CHAR_RIDEPET ) == petsel ){ +/* char buf[1024]; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString("\n\nеij޷ร", buf, sizeof(buf))); +*/ + sprintf(token,"\n\nеij޷ร"); + return; + } + + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), + CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; + defpet=CHAR_getInt(talker,CHAR_DEFAULTPET); + if(defpet==petsel){ + CHAR_setInt(talker,CHAR_DEFAULTPET,-1); + lssproto_KS_send( fd, -1, TRUE); + } + +#ifdef _PET_ITEM + CHAR_sendPetItemEmpty(talker,petsel); +#endif + + CHAR_setCharPet( talker, petsel, -1); + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "sell()", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + snprintf( szPet, sizeof( szPet ), "K%d", petsel); + CHAR_sendStatusString( talker, szPet ); + cost=NPC_GetCost(meindex,talker,petindex); + CHAR_AddGold( talker, cost); + CHAR_endCharOneArray( petindex ); +} +#endif +void NPC_PetDel2( int meindex, int talker, int select, char *token) +{ + int petindex; + int selectpet; + int emptyindex; + char szPet[128]; + int fd = getfdFromCharaIndex( talker ); + + if( fd == -1 ) { + fprint( "err\n"); + return; + } + // ʸ ʣʸ ľ + selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) -1; + petindex = CHAR_getCharPet( talker, selectpet); + + if( !CHAR_CHECKINDEX( petindex) ) return; + // Robin 0725 + if (CHAR_getInt( talker, CHAR_RIDEPET ) == selectpet ) + { +/* char buf[1024]; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + -1, -1, + makeEscapeString("\n\nеij޷ķร", buf, sizeof(buf))); +*/ + sprintf(token,"\n\nеij޷ķร"); + return; + } + + // ëʣƻƻ¼ƥݳƥлئмƾ + emptyindex = CHAR_getCharPoolPetElement( talker); + if( emptyindex == -1 ) { + fprint( "err\n"); + return; + } + + // ʸئգݹľ ëʣ + if( CHAR_getInt( talker, CHAR_DEFAULTPET) == selectpet) { + CHAR_setInt( talker, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + // ľ ʸ̼͵ë + CHAR_setCharPoolPet( talker, emptyindex, petindex); + // ʸ +#ifdef _PET_ITEM + CHAR_sendPetItemEmpty(talker,selectpet); +#endif + CHAR_setCharPet( talker, selectpet, -1); + + // + NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); + // Ӽ + + CHAR_DelGold( talker, NPC_GETPOOLCOST( talker) ); + + // ŷ˪ + CHAR_send_P_StatusString(talker,CHAR_P_STRING_GOLD); + + snprintf( szPet, sizeof( szPet ), "K%d", selectpet); + // ޥʸ ˪Ի + CHAR_sendStatusString( talker, szPet ); + // ʸë ׷ + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "pool(ķų)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talker, FALSE)){ + CHAR_talkToCli(talker, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + +} + +void NPC_PetDel3( int meindex, int talker, int select, char *token) +{ + int petindex; + int selectpet; + int emptyindex; + char szPet[128]; + int workindex[CHAR_MAXPOOLPETHAVE]; + int i; + int cnt; + + selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) ; + petindex = CHAR_getCharPoolPet( talker, selectpet); + + if( !CHAR_CHECKINDEX( petindex) ) return; + emptyindex = CHAR_getCharPetElement( talker); + if( emptyindex == -1 ) { + fprint( "err\n"); + return; + } + + // ػ޸Ϊͨ + if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 + && CHAR_getInt( talker, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER ) { + CHAR_setInt( petindex, CHAR_PETFAMILY, 0); + CHAR_talkToCli( talker, -1, "ػ޸Ϊͨ", CHAR_COLORYELLOW); + } + + CHAR_setCharPet( talker, emptyindex, petindex); + CHAR_setCharPoolPet( talker, selectpet, -1); + NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); +#ifdef _PET_ITEM + CHAR_sendPetItemData( talker, emptyindex); +#endif + snprintf( szPet, sizeof( szPet ), "K%d", emptyindex); + CHAR_sendStatusString( talker, szPet ); + snprintf( szPet, sizeof( szPet), "W%d",emptyindex); + CHAR_sendStatusString( talker, szPet ); + for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { + workindex[i] = -1; + } + cnt = 0; + for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { + int petindex = CHAR_getCharPoolPet( talker, i); + if( CHAR_CHECKINDEX( petindex) ) { + workindex[cnt++] = petindex; + } + } + for( i = 0; i < CHAR_MAXPOOLPETHAVE; i ++ ) { + CHAR_setCharPoolPet( talker, i, workindex[i]); + } + LogPet( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "draw(ȡ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); +#ifdef _PET_EVOLUTION + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT) == 1 && + CHAR_getInt( petindex, CHAR_FUSIONRAISE) > 0 ){//ǷΪںϳ + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time( NULL)); + } +#endif +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talker, FALSE)){ + CHAR_talkToCli(talker, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif +} + +void NPC_getDrawPet( int meindex, int toindex, char *token, int *buttontype, int select) +{ + // ʸؤԻ + #define LINENUM 5 + char buf[1024]; + int i; + int startnum, endnum; + int petindex = -1; + // ػʸ + int page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); + int limit; + //andy_reEdit 2003/09/18 + limit = (CHAR_getInt(toindex,CHAR_TRANSMIGRATION)*2)+5; + + endnum = (page + select+1)*LINENUM ; + startnum = endnum - LINENUM; + *buttontype = WINDOW_BUTTONTYPE_CANCEL; + // ʸƩ + if( endnum >= limit ) { + endnum = limit; + if( page +select!= 0 ) *buttontype |= WINDOW_BUTTONTYPE_PREV; + } + else if( endnum <= LINENUM ) { + endnum = LINENUM; + *buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + else { + *buttontype |= WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_NEXT; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page +select); + + strcpy( token, "2\nѡ\n\n"); + for( i = startnum; i < endnum; i ++ ) { + petindex = CHAR_getCharPoolPet( toindex, i); + if( CHAR_CHECKINDEX( petindex) ) { + snprintf( buf, sizeof( buf), "LV.%3d MaxHP %3d %s\n", + CHAR_getInt( petindex, CHAR_LV), + CHAR_getWorkInt( petindex, CHAR_WORKMAXHP), + CHAR_getUseName( petindex) + ); + } + else { + strcpy( buf, "\n"); + } + strcat( token, buf); + } + // ݼëƩͻ ݳʾë + if( i != limit ) { + petindex = CHAR_getCharPoolPet( toindex, i); + if( !CHAR_CHECKINDEX( petindex)) { + *buttontype &= ~WINDOW_BUTTONTYPE_NEXT; + } + } +} + +/* + *ŻְǷǷ + */ +void NPC_MaxGoldOver(int meindex,int toindex,int select,char *token) +{ + + char buf[1024]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)); + + if( select < 0 || select >= arraysizeof( shopmsg)) return; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, shopmsg[select].option, buf, sizeof( buf)) == NULL ) + { + strcpy( buf, shopmsg[select].defaultmsg); + } + + snprintf(token,sizeof(buf),"\n\n%s",buf); + +} + +#ifdef _NPC_DEPOTPET +void NPC_PoolPetShop_DepotPet_Menu( int meindex, int talkerindex) +{ + int fd; + + //print(" NPC_PoolPetShop_DepotPet_Menu "); + + fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + char message[1024]; + char buf[2048]; + + strcpy( message, + "3\n" + " ʹóֿ\n" + "رע⣺𽫹س빫ֿ\n" + "﹫ֿ⡻\n" + " ų\n" + " ȡس\n" + ); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_DEPOTPETSHOP_HANDLE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf))); + } +} + +void NPC_DepotPet_List( int meindex, int toindex, char *token, int *buttontype, int select) +{ + // ʸؤԻ + #define LINENUM 5 + char buf[1024]; + int i; + int startnum, endnum; + int petindex = -1; + // ػʸ + int page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); + int limit; + + limit = CHAR_MAXDEPOTPETHAVE; + + endnum = (page + select+1)*LINENUM ; + startnum = endnum - LINENUM; + *buttontype = WINDOW_BUTTONTYPE_CANCEL; + // ʸƩ + if( endnum >= limit ) { + endnum = limit; + if( page +select!= 0 ) *buttontype |= WINDOW_BUTTONTYPE_PREV; + } + else if( endnum <= LINENUM ) { + endnum = LINENUM; + *buttontype |= WINDOW_BUTTONTYPE_NEXT; + } + else { + *buttontype |= WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_NEXT; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page +select); + + strcpy( token, "2\nѡҪӲֿȡij\n\n"); + for( i = startnum; i < endnum; i ++ ) { + petindex = CHAR_getDepotPetIndex( toindex, i); + if( CHAR_CHECKINDEX( petindex) ) { + snprintf( buf, sizeof( buf), "LV.%3d MaxHP %3d %s\n", + CHAR_getInt( petindex, CHAR_LV), + CHAR_getWorkInt( petindex, CHAR_WORKMAXHP), + CHAR_getUseName( petindex) + ); + } + else { + strcpy( buf, "\n"); + } + strcat( token, buf); + } + // ݼëƩͻ ݳʾë + if( i != limit ) { + petindex = CHAR_getDepotPetIndex( toindex, i); + if( !CHAR_CHECKINDEX( petindex)) { + *buttontype &= ~WINDOW_BUTTONTYPE_NEXT; + } + } + //print("\n DepotPet_List:%s ", token); +} + + +void NPC_DepotPet_Add( int meindex, int talker, int select, char *token) +{ + + int petindex; + int selectpet; + int emptyindex; + char szPet[128]; + int fd = getfdFromCharaIndex( talker ); + + if( fd == -1 ) { + fprint( "err\n"); + return; + } + // ʸ ʣʸ ľ + selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) -1; + //print("\n selectpet:%d ", selectpet); + petindex = CHAR_getCharPet( talker, selectpet); + if( !CHAR_CHECKINDEX( petindex) ) return; + + // Robin 0725 + if (CHAR_getInt( talker, CHAR_RIDEPET ) == selectpet ) + { + sprintf(token,"\n\nеij޷ֿร"); + return; + } + + if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 ) + { + sprintf(token,"\n\nػ޷ֿร"); + return; + } + +#ifdef _LOCK_PET_ITEM + char *arg = CHAR_getChar(petindex, CHAR_NAME); + if(arg[0] == '*'){ + sprintf(token,"\n\n󶨵ijﲻɴ빲ֿͬ⣡"); + CHAR_talkToCli( talker, -1, "!", CHAR_COLORYELLOW ); + return; + } + if(FreeLockPetSave(talker, petindex) == 1){ + return; + } +#endif + // ëʣƻƻ¼ƥݳƥлئмƾ + emptyindex = CHAR_getCharDepotPetElement( talker); + if( emptyindex == -1 ) { + fprint( "err\n"); + return; + } + + // ʸئգݹľ ëʣ + if( CHAR_getInt( talker, CHAR_DEFAULTPET) == selectpet) { + CHAR_setInt( talker, CHAR_DEFAULTPET, -1); + lssproto_KS_send( fd, -1, TRUE); + } + // ľ ʸ̼͵ë + CHAR_setDepotPetIndex( talker, emptyindex, petindex); + // ʸ + CHAR_setCharPet( talker, selectpet, -1); + + // + NPC_MaxGoldOver( meindex, talker, NPC_PETSHOP_MSG_POOLTHANKS, token); + // Ӽ + + CHAR_DelGold( talker, NPC_GETPOOLCOST( talker) ); + + // ŷ˪ + CHAR_send_P_StatusString(talker,CHAR_P_STRING_GOLD); + + snprintf( szPet, sizeof( szPet ), "K%d", selectpet); + // ޥʸ ˪Ի + CHAR_sendStatusString( talker, szPet ); + // ʸë ׷ +#ifdef _CHECK_PEPEAT + if( getCheckRepeat()==1 || NPC_DepotPet_CheckRepeat( talker) == 0) // ظ +#else + if( NPC_DepotPet_CheckRepeat( talker) == 0) // ظ +#endif + { + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "pool(ֿ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + } + else + { + CHAR_talkToCli( talker, -1, "ǷǷij!!", CHAR_COLORYELLOW); + } + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talker, FALSE)){ + CHAR_talkToCli(talker, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif +} + + + +void NPC_DepotPet_Get( int meindex, int talker, int select, char *token) +{ + + int petindex; + int selectpet; + int emptyindex; + char szPet[128]; + int workindex[CHAR_MAXPOOLPETHAVE]; + int i; + int cnt; + + selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) ; + petindex = CHAR_getDepotPetIndex( talker, selectpet); + if( !CHAR_CHECKINDEX( petindex) ) return; +#ifdef _LOCK_PET_ITEM + char *arg = CHAR_getChar(petindex, CHAR_NAME); + if(arg[0] == '*'){ + CHAR_talkToCli( talker, -1, "󶨵ijﲻɴ빲ֿͬ!", CHAR_COLORYELLOW ); + return; + } + if(FreeLockPetSave(talker, petindex) == 1){ + return; + } +#endif +#ifdef _AUTO_DEL_PET +{ + int j, petid; + petid =CHAR_getInt( petindex, CHAR_PETID); + for(j=0;j 0 ){//ǷΪںϳ + CHAR_setInt( petindex, CHAR_FUSIONTIMELIMIT, (int)time( NULL)); + } +#endif +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talker, FALSE)){ + CHAR_talkToCli(talker, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif +} + +void NPC_DepotPet_AskGet(int meindex,int talker,int select,char *token) +{ + int depotindex; + int petindex; + char *petname; + depotindex = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) * 5 + select - 1; + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANT,depotindex ); + petindex = CHAR_getDepotPetIndex( talker, depotindex); + if( !CHAR_CHECKINDEX(petindex) ) return; + petname = CHAR_getUseName( petindex); + sprintf(token,"\n[%s]", petname); +} + +int NPC_DepotPet_CheckRepeat( int charaindex) +{ + int petindex1, petindex2; + int i, j, find, ret = FALSE; + int workindex[CHAR_MAXDEPOTPETHAVE], cnt =0; + + for( i =0; i <(CHAR_MAXDEPOTPETHAVE-1); i++) + { + petindex1 = CHAR_getDepotPetIndex( charaindex, i); + if( !CHAR_CHECKINDEX( petindex1)) continue; + find = 0; + for( j =(i+1); j 0) + { + CHAR_setDepotPetIndex( charaindex, i, -1); + NPC_DepotPet_CheckRepeat_del( charaindex, petindex1); + } + } + + for( i = 0; i < CHAR_MAXDEPOTPETHAVE; i ++ ) { + workindex[i] = -1; + } + for( i = 0; i < CHAR_MAXDEPOTPETHAVE; i ++ ) { + int pindex = CHAR_getDepotPetIndex( charaindex, i); + if( CHAR_CHECKINDEX( pindex) ) { + workindex[cnt++] = pindex; + } + } + for( i = 0; i < CHAR_MAXDEPOTPETHAVE; i ++ ) { + CHAR_setDepotPetIndex( charaindex, i, workindex[i]); + } + + return ret; +} + +void NPC_DepotPet_CheckRepeat_del( int charaindex, int petindex) +{ + LogPet( + CHAR_getChar( charaindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "del(ֿϴ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + CHAR_endCharOneArray( petindex ); +} + +// ȼǷ㹻 +int NPC_DepotPet_CheckLevel(int meindex,int talker,int select,char *token) +{ + int petindex; + int selectpet; + + if( !CHAR_CheckDepotPet( talker) ) + return FALSE; + + selectpet = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) ; + petindex = CHAR_getDepotPetIndex( talker, selectpet); + if( !CHAR_CHECKINDEX(petindex) ) return FALSE; + + //print("\n trans:%d char_lv:%d pet_lv:%d ", + // CHAR_getInt( talker, CHAR_TRANSMIGRATION), + // CHAR_getInt( talker, CHAR_LV), + // CHAR_getInt( petindex, CHAR_LV) ); + + // ػ޸Ϊͨ + if( CHAR_getInt( petindex, CHAR_PETFAMILY) == 1 + && CHAR_getInt( talker, CHAR_FMLEADERFLAG) != FMMEMBER_LEADER ) { + CHAR_setInt( petindex, CHAR_PETFAMILY, 0); + } + + if( CHAR_getWorkInt( talker, CHAR_PickAllPet) == TRUE ) { // װѱ޽ָĻ... + return TRUE; + } + + if( CHAR_getInt( talker, CHAR_TRANSMIGRATION) > 0 + || CHAR_getInt( talker, CHAR_LV)+20 >= CHAR_getInt( petindex, CHAR_LV) ) { + return TRUE; + } + + return FALSE; + +} + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petskillshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petskillshop.c new file mode 100644 index 0000000..f5bfbd1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_petskillshop.c @@ -0,0 +1,252 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "pet_skill.h" +#include "readmap.h" +#include "battle.h" +#ifdef _ALLBLUES_LUA +#include "mylua/function.h" +#endif +enum { + CHAR_WORK_STONESELECT = CHAR_NPCWORKINT1, +}; + +static void NPC_PetSkillShop_selectWindow( int meindex, int toindex, int num,int select); +BOOL NPC_PetSkillMakeStr(int meindex,int toindex,int select); + +BOOL NPC_PetSkillShopInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[256]; + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPESTONESHOP ); + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", msg, sizeof( msg)) != NULL){ + char buf[256], filename[256]; + int k=1, skillID, skillarray; + while( getStringFromIndexWithDelim( msg, ",", k, buf, sizeof( buf) ) ){ + k++; + skillID=atoi(buf); + skillarray = PETSKILL_getPetskillArray( skillID); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ) continue; + if( PETSKILL_getInt( skillarray, PETSKILL_ILLEGAL) == 1){ + if( NPC_Util_CheckAssignArgFile( meindex, filename) != NULL ){ + print("PetSkillShop illegal skill:[%d-%s] ->file:%s", + skillID, + PETSKILL_getChar( skillarray, PETSKILL_NAME), + filename ); + } + } + } + }else{ + return FALSE; + } + + return TRUE; +} + +void NPC_PetSkillShopTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + NPC_PetSkillShop_selectWindow( meindex, talkerindex,0,-1); +} + +void NPC_PetSkillShopLooked( int meindex , int lookedindex) +{ + if( CHAR_getInt( lookedindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( NPC_Util_CharDistance( lookedindex, meindex ) > 2) return; +} + +static void NPC_PetSkillShop_selectWindow( int meindex, int toindex, int num,int select) +{ + switch(num){ + case 0: + NPC_PetSkillMakeStr(meindex,toindex,select); + break; + case 1: + break; + } +} + +void NPC_PetSkillShopWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int skill; + int pet; + int slot; + int cost; + int skillID=0; + int petskillindex; + char buf[64]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[512]; + int petindex; + char msgbuf[128]; + int fd = getfdFromCharaIndex( talkerindex ); + double rate= 1.0; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return; + } + makeStringFromEscaped( data); + getStringFromIndexWithDelim(data,"|",1,buf,sizeof(buf)); + skill=atoi(buf); + getStringFromIndexWithDelim(data,"|",2,buf,sizeof(buf)); + pet=atoi(buf); + getStringFromIndexWithDelim(data,"|",3,buf,sizeof(buf)); + slot=atoi(buf); + getStringFromIndexWithDelim(data,"|",4,buf,sizeof(buf)); + cost=atoi(buf); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", msg, sizeof( msg)) != NULL){ + getStringFromIndexWithDelim(msg,",",skill,buf,sizeof(buf)); + skillID=atoi(buf); + } + + slot--; + if( !CHAR_CHECKPETSKILLINDEX( slot)){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + petindex = CHAR_getCharPet( talkerindex, pet-1); + if( !CHAR_CHECKINDEX(petindex) ){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + if(skillID < 0) return ; + + if(petindex == -1){ + print("petskillshop.c:170 PetindexError"); + return; + } + + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), + CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; + if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ + rate = atof( msg); + } + + petskillindex = PETSKILL_getPetskillArray( skillID ); + if(petskillindex == -1){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + + cost = PETSKILL_getInt( petskillindex, PETSKILL_COST ); + cost = cost * rate; + + if(CHAR_getInt(talkerindex,CHAR_GOLD) < cost){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } +#ifdef _PETSKILL_SHOP_LUA + if(FreePetSkillShop(talkerindex, petindex, CHAR_getPetSkill(petindex, slot), skillID) == FALSE ) { + return; + } +#endif + + CHAR_setPetSkill( petindex, slot, skillID); + CHAR_complianceParameter(petindex); + CHAR_DelGold( talkerindex, cost ); + + snprintf( msgbuf, sizeof( msgbuf ), "W%d",pet-1); + CHAR_sendStatusString( talkerindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d",pet-1); + CHAR_sendStatusString( talkerindex, msgbuf ); + NPC_PetSkillShop_selectWindow( meindex, talkerindex,0,-1); +} + +BOOL NPC_PetSkillMakeStr(int meindex,int toindex,int select) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[256]; + double rate=1.0; + int i=0; + char token[NPC_UTIL_GETARGSTR_LINEMAX]; + int fd = getfdFromCharaIndex( toindex); + + if(select==0){ + sprintf(token,"0|0"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PETSKILLSHOP, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", msg, sizeof( msg)) == NULL){ + print("mainERR"); + return FALSE; + } + + sprintf(token,"1|%s|%s", + CHAR_getChar(meindex,CHAR_NAME),msg); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ + rate=atof(msg); + } + + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", msg, sizeof( msg) ) != NULL){ + int skillarray; + int skillID; + int cost; + char token2[265]; + char buf[64]; + + i=1; + while( getStringFromIndexWithDelim(msg,",",i,buf,sizeof(buf)) !=FALSE ){ + i++; + skillID=atoi(buf); + skillarray = PETSKILL_getPetskillArray( skillID); + + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ) + continue; + if( PETSKILL_getInt( skillarray, PETSKILL_ILLEGAL) == 1) continue; + cost = PETSKILL_getInt(skillarray,PETSKILL_COST); + cost = (int)cost*rate; +#ifdef _VERSION_25 + sprintf(token2,"|%s|%d|%s", PETSKILL_getChar(skillarray, PETSKILL_NAME), + cost, PETSKILL_getChar(skillarray, PETSKILL_COMMENT)); +#else + sprintf(token2,"|%s|%d|%s|0", PETSKILL_getChar(skillarray, PETSKILL_NAME), + cost, PETSKILL_getChar(skillarray, PETSKILL_COMMENT)); +#endif + + strcat(token,token2); + } + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PETSKILLSHOP, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return TRUE; +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_poolitemshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_poolitemshop.c new file mode 100644 index 0000000..a623668 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_poolitemshop.c @@ -0,0 +1,1014 @@ +#include "version.h" +#include "configfile.h" +#include "char.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "npc_poolitemshop.h" +#include "log.h" +#include "handletime.h" + +#define NPC_POOLITEMSHOP_DEFAULT_COST 200 + +enum { + NPC_WORK_COST = CHAR_NPCWORKINT1, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, +}; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +enum { + NPC_POOLITEMSHOP_MSG_MAIN=0, + NPC_POOLITEMSHOP_MSG_POOL, + NPC_POOLITEMSHOP_MSG_DRAW, + NPC_POOLITEMSHOP_MSG_REALY, + NPC_POOLITEMSHOP_MSG_STONE, + NPC_POOLITEMSHOP_MSG_POOLFULL, + NPC_POOLITEMSHOP_MSG_ITEMFULL, + + CHAR_WINDOWTYPE_POOLITEMSHOP_START = 290, + CHAR_WINDOWTYPE_POOLITEMSHOP_POOL_MSG, + CHAR_WINDOWTYPE_POOLITEMSHOP_DRAW_MSG, + CHAR_WINDOWTYPE_POOLITEMSHOP_FULL_MSG, + CHAR_WINDOWTYPE_POOLITEMSHOP_HAVEITEMFULL_MSG, + CHAR_WINDOWTYPE_POOLITEMSHOP_END, + +#ifdef _NPC_DEPOTITEM + CHAR_WINDOWTYPE_DEPOTITEMSHOP_MENU = 310, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_HANDLE, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_ADD, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_GET, +#endif +}; + +typedef struct { + char option[32]; + char defaultmsg[128]; +}NPC_POOLITEMSHOP_MSG; + +NPC_POOLITEMSHOP_MSG poolshopmsg[] = { + { "main_msg", "ӭ"}, + { "pool_main", "Ҫķʲ"}, + { "draw_main", "Ҫʲ"}, + { "realy_msg", "ҪǸ"}, + { "stone_msg", "Ǯ!"}, + { "poolfull_msg", "޷"}, + { "itemfull_msg", "Ŀкܶ"} +}; + +static BOOL NPC_PoolItemShop_DrawItem( int meindex, int talkerindex, int num); +static BOOL NPC_PoolItemShop_PoolItem( int meindex, int talkerindex, int num); +static void NPC_PoolItemShop_MakeItemString_Draw( int meindex, int talkerindex, + char *retstring,int retstringlen); +static void NPC_PoolItemShop_MakeItemString_Pool( int meindex, int talkerindex, + char *retstring,int retstringlen); +static char *NPC_PoolItemShop_getMsg_noarg( int tablenum, + char *argstr, char *retstring, int retstringlen); +static void NPC_PoolItemShop_printWindow_Draw( int meindex, int talkerindex); +static void NPC_PoolItemShop_printWindow_Pool( int meindex, int talkerindex); +static void NPC_PoolItemShop_printWindow_Full( int meindex, int talkerindex); + +static void NPC_PoolItemShop_printWindow_HaveItemFull( int meindex, int talkerindex); + +#ifdef _NPC_DEPOTITEM +void NPC_PoolItemShop_DepotItem_Menu( int meindex, int talkerindex); +void NPC_DepotItem_Item_printWindow( int meindex, int talkerindex); +void NPC_DepotItem_Depot_printWindow( int meindex, int talkerindex); +BOOL NPC_DepotItem_InsertItem( int meindex, int talkerindex, int num); +BOOL NPC_DepotItem_gettItem( int meindex, int talkerindex, int num); +#endif + +#define NPCPOOLITEMLOOP 1000*20 +int othertime=0; + +int poolitemhanlde; + +BOOL NPC_PoolItemShopInit( int meindex) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int cost; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + cost = NPC_Util_GetNumFromStrWithDelim( argstr, "cost"); + if( cost == -1 ) cost = NPC_POOLITEMSHOP_DEFAULT_COST; + CHAR_setWorkInt( meindex, NPC_WORK_COST, cost); + + poolitemhanlde=meindex; + + return TRUE; +} + +void NPC_PoolItemShopTalked( int meindex , int talkerindex , + char *szMes ,int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + if( !NPC_Util_isFaceToFace( meindex, talkerindex, 2)) { + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + NPC_PoolItemShop_printWindow_Start( meindex, talkerindex); +} + +void NPC_PoolItemShopWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ +// if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) return; + +// print("\n NPC_PoolItemShopWindowTalked: seq:%d sel:%d data:%s", seqno, select, data); + + switch( seqno ) { + case CHAR_WINDOWTYPE_POOLITEMSHOP_START: + switch( atoi( data)) { + case 1: + if( CHAR_getCharPoolItemIndexElement( talkerindex) != -1 ) { + NPC_PoolItemShop_printWindow_Pool( meindex, talkerindex); + }else { + NPC_PoolItemShop_printWindow_Full( meindex, talkerindex); + } + break; + case 2: + if( CHAR_findEmptyItemBox( talkerindex) != -1 ) { + NPC_PoolItemShop_printWindow_Draw( meindex, talkerindex); + }else { + NPC_PoolItemShop_printWindow_HaveItemFull( meindex, talkerindex); + } + break; +#ifdef _NPC_DEPOTITEM + case 3: + if( !CHAR_CheckDepotItem( talkerindex) ){ + CHAR_GetDepotItem( meindex, talkerindex); + CHAR_talkToCli( talkerindex, -1, "ȡõߣᣡ", CHAR_COLORYELLOW); + }else{ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + } + break; +#endif + + } + break; + case CHAR_WINDOWTYPE_POOLITEMSHOP_POOL_MSG: + if( atoi( data) == 0){ + NPC_PoolItemShop_printWindow_Start( meindex, talkerindex); + }else { + NPC_PoolItemShop_PoolItem( meindex, talkerindex, atoi(data)-1); + } + break; + case CHAR_WINDOWTYPE_POOLITEMSHOP_DRAW_MSG: + if( atoi( data) == 0){ + NPC_PoolItemShop_printWindow_Start( meindex, talkerindex); + }else { + NPC_PoolItemShop_DrawItem( meindex, talkerindex, atoi(data)-1); + } + break; + case CHAR_WINDOWTYPE_POOLITEMSHOP_FULL_MSG: + NPC_PoolItemShop_printWindow_Start( meindex, talkerindex); + break; + case CHAR_WINDOWTYPE_POOLITEMSHOP_HAVEITEMFULL_MSG: + NPC_PoolItemShop_printWindow_Start( meindex, talkerindex); + break; + +#ifdef _NPC_DEPOTITEM + case CHAR_WINDOWTYPE_DEPOTITEMSHOP_MENU: + if( !CHAR_CheckDepotItem( talkerindex) ){ + CHAR_GetDepotItem( meindex, talkerindex); + return; + }else{ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + } + break; + case CHAR_WINDOWTYPE_DEPOTITEMSHOP_HANDLE: + if( !CHAR_CheckDepotItem( talkerindex) ) return ; + switch( atoi( data)) { + case 1:// + if( CHAR_findEmptyDepotItem( talkerindex) == -1 ){ + CHAR_talkToCli( talkerindex, -1, "ֿ", CHAR_COLORYELLOW); + return; + } + NPC_DepotItem_Item_printWindow( meindex, talkerindex); + break; + case 2: + if( CHAR_findEmptyItemBox( talkerindex) == -1 ) { + CHAR_talkToCli( talkerindex, -1, "ϵλ", CHAR_COLORYELLOW); + return; + } + NPC_DepotItem_Depot_printWindow( meindex, talkerindex); + break; + } + break; + case CHAR_WINDOWTYPE_DEPOTITEMSHOP_ADD:// + if( !CHAR_CheckDepotItem( talkerindex) ) return ; + if( atoi( data) == 0){ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + }else { + if( NPC_DepotItem_InsertItem( meindex, talkerindex, atoi( data)-1) == FALSE ){ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + CHAR_talkToCli( talkerindex, -1, "ŵʧܣԣ", CHAR_COLORYELLOW); + } + } + break; + case CHAR_WINDOWTYPE_DEPOTITEMSHOP_GET: + if( !CHAR_CheckDepotItem( talkerindex) ) return ; + if( atoi( data) == 0){ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + }else { + if( NPC_DepotItem_gettItem( meindex, talkerindex, atoi( data)-1) == FALSE ){ + NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex); + CHAR_talkToCli( talkerindex, -1, "ȡʧܣԣ", CHAR_COLORYELLOW); + } + } + break; +#endif + + default: + break; + } +} + +void NPC_PoolItemShop_printWindow_Start( int meindex, int talkerindex) +{ + int fd; + + fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + char message[1024]; + char buf[2048]; + + if (CHAR_getWorkInt(talkerindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_FREE){ + CHAR_talkToCli( talkerindex, -1, "޷ʹõֿ߲!", CHAR_COLORRED); + return; + } +#ifdef _ROOKIE_ITEM + if( CHAR_getInt( talkerindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + CHAR_CheckUserItem( talkerindex ); + } +#endif +#ifdef _NPC_DEPOTITEM + strcpy( message, + "3\n\n" + " ӭ\n\n" + " ķŵߣ\n" + " ȡصߣ\n" + " ʹòֿ⣾\n\n" + " 뿪 " + ); +#else + strcpy( message, + "3\n\n" + " ӭ\n\n" + " ķŵߣ\n" + " ȡصߣ\n\n\n" + " 뿪 " + ); +#endif + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_POOLITEMSHOP_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf))); + } +} + +#ifdef _NPC_DEPOTITEM +void NPC_PoolItemShop_DepotItem_Menu( int meindex, int talkerindex) +{ + int fd; + + fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + char message[1024]; + char buf[2048]; + + strcpy( message, + "3\n\n" + " ʹõֿ߲\n\n" + " ŵߣ\n" + " ȡصߣ\n" + ); + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, + WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_HANDLE, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( message, buf, sizeof(buf))); + } +} + +void NPC_DepotItem_MakeItemString( int meindex, int talkerindex, char *retstring,int retstringlen) +{ + int i; + int itemindex; + int pos = 0; + char buff[1024]; + + retstring[0] = '\0'; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talkerindex); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i++ ) { +#else + for( i = CHAR_STARTITEMARRAY; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + int poolflg = FALSE; + itemindex = CHAR_getItemIndex( talkerindex, i); + if( !ITEM_CHECKINDEX( itemindex) ) continue; + + if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || ITEM_getInt( itemindex, ITEM_VANISHATDROP) || + !ITEM_getInt( itemindex, ITEM_CANPETMAIL) ) { + poolflg = TRUE; + } + snprintf( buff, sizeof( buff), +#ifdef _ITEM_PILENUMS + "%s|%d|%d|%d|%s|%d|%d|", +#else + "%s|%d|%d|%d|%s|%d|", +#endif + ITEM_getChar( itemindex, ITEM_SECRETNAME), + poolflg,CHAR_getWorkInt( meindex, NPC_WORK_COST), + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getChar( itemindex, ITEM_EFFECTSTRING), +#ifdef _ITEM_PILENUMS + ITEM_getInt( itemindex, ITEM_USEPILENUMS), +#endif + i + 1 ); + + if( pos +strlen( buff)>= retstringlen) { + fprint( "buffer over err\n"); + break; + } + strcpy( &retstring[pos], buff); + pos += strlen( buff); + } +} + +void NPC_DepotItem_Item_printWindow( int meindex, int talkerindex) +{ + char itemstring[NPC_UTIL_GETARGSTR_BUFSIZE]; + char sendstring[NPC_UTIL_GETARGSTR_BUFSIZE]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[1024]; + char buff3[1024]; + char buff4[1024]; + int fd; + + if( (fd = getfdFromCharaIndex( talkerindex)) == -1 ){ + fprint( "err\n"); + return; + } + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + snprintf( sendstring, sizeof( sendstring), "0|%d|%s|%s|%s|%s|", + CHAR_getfindEmptyDepotItem( talkerindex), + CHAR_getChar( meindex, CHAR_NAME), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_POOL, argstr, buff2, sizeof( buff2)), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_POOLFULL, argstr, buff3, sizeof( buff3)), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_REALY, argstr, buff4, sizeof( buff4)) + ); + + NPC_DepotItem_MakeItemString( meindex, talkerindex, itemstring, sizeof( itemstring)); + strcat( sendstring, itemstring); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_ADD, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), sendstring); + +} + +void NPC_DepotItem_MakeDepotString( int meindex, int talkerindex, char *retstring,int retstringlen) +{ + int i; + int itemindex; + int pos = 0; + char buff[1024]; + + retstring[0] = '\0'; + for( i = 0; i < /*60*/CHAR_MAXDEPOTITEMHAVE; i ++ ) { + int poolflg = FALSE; + itemindex = CHAR_getDepotItemIndex( talkerindex, i); + if( !ITEM_CHECKINDEX( itemindex)) continue; + snprintf( buff, sizeof( buff), +#ifdef _ITEM_PILENUMS + "%s|%d|%d|%d|%d|%s|%d|", +#else + "%s|%d|%d|%d|%d|%s|", +#endif + ITEM_getChar( itemindex, ITEM_SECRETNAME), + poolflg, + ITEM_getInt( itemindex, ITEM_LEVEL), + ITEM_getInt( itemindex, ITEM_COST), + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getChar( itemindex, ITEM_EFFECTSTRING) +#ifdef _ITEM_PILENUMS + ,ITEM_getInt( itemindex, ITEM_USEPILENUMS) +#endif + ); + if( pos +strlen( buff)>= retstringlen) { + fprint( "buffer over err\n"); + break; + } + strcpy( &retstring[pos], buff); + pos += strlen( buff); + } + +} + +void NPC_DepotItem_Depot_printWindow( int meindex, int talkerindex) +{ + char itemstring[NPC_UTIL_GETARGSTR_BUFSIZE]; + char sendstring[NPC_UTIL_GETARGSTR_BUFSIZE]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff[1024]; + char buff2[1024]; + char buff3[1024]; + int fd; + + if( (fd = getfdFromCharaIndex( talkerindex)) == -1 )return; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + snprintf( sendstring, sizeof( sendstring), "1|%s|%s|%s|%s|", + CHAR_getChar( meindex, CHAR_NAME), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_DRAW, argstr, buff2, sizeof( buff2)), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_ITEMFULL, argstr, buff, sizeof( buff)), + NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_REALY, argstr, buff3, sizeof( buff3)) + ); + NPC_DepotItem_MakeDepotString( meindex, talkerindex, itemstring, sizeof( itemstring)); + strcat( sendstring, itemstring); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_DEPOTITEMSHOP_GET, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + sendstring); + + //print("\n NPC_DepotItem_Depot_printWindow:%s size:%d ", sendstring, strlen(sendstring)); +} + +void NPC_DepotItem_CheckRepeat_Del( int charaindex, int ti, int itemindex) +{ + char token[256]; + sprintf( token, "ֿ%sظ(ϵͳ)", + ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( charaindex, -1, token, CHAR_COLORYELLOW); + LogItem( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "repeat(ֿظ)", + 0, 0, 0, + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) ); + + CHAR_setDepotItemIndex( charaindex, ti, -1); + ITEM_endExistItemsOne( itemindex); +} + +void NPC_DepotItem_CheckRepeat( int talkerindex) +{ + int i, j, cnt=0, itemindex, itemindex1; + + for( i=0; i<(CHAR_MAXDEPOTITEMHAVE-1); i++){ + itemindex = CHAR_getDepotItemIndex( talkerindex, i); + if( !ITEM_CHECKINDEX( itemindex)) continue; + cnt=0; + for( j=(i+1); j= arraysizeof( poolshopmsg)) return "\0"; + + if( NPC_Util_GetStrFromStrWithDelim( argstr, poolshopmsg[tablenum].option, buf, sizeof( buf)) != NULL ) { + strcpysafe( retstring, retstringlen, buf); + }else { + strcpysafe( retstring, retstringlen, poolshopmsg[tablenum].defaultmsg); + } + return retstring; +} + +static void NPC_PoolItemShop_MakeItemString_Pool( int meindex, int talkerindex, + char *retstring,int retstringlen) +{ + int i; + int itemindex; + int pos = 0; + char buff[1024]; + + retstring[0] = '\0'; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talkerindex); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i++ ) { +#else + for( i = CHAR_STARTITEMARRAY; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + itemindex = CHAR_getItemIndex( talkerindex, i); + if( ITEM_CHECKINDEX( itemindex)) { + int poolflg = FALSE; + if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || + ITEM_getInt( itemindex, ITEM_VANISHATDROP) || + !ITEM_getInt( itemindex, ITEM_CANPETMAIL)){ + poolflg = TRUE; + } + snprintf( buff, sizeof( buff), +#ifdef _ITEM_PILENUMS + "%s|%d|%d|%d|%s|%d|%d|", +#else + "%s|%d|%d|%d|%s|%d|", +#endif + ITEM_getChar( itemindex, ITEM_SECRETNAME), + poolflg,CHAR_getWorkInt( meindex, NPC_WORK_COST), + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getChar( itemindex, ITEM_EFFECTSTRING), +#ifdef _ITEM_PILENUMS + ITEM_getInt( itemindex, ITEM_USEPILENUMS), +#endif + i + 1 ); + if( pos +strlen( buff)>= retstringlen) { + fprint( "buffer over err\n"); + break; + } + strcpy( &retstring[pos], buff); + pos += strlen( buff); + } + } +} + +static void NPC_PoolItemShop_MakeItemString_Draw( int meindex, int talkerindex, + char *retstring,int retstringlen) +{ + int i; + int itemindex; + int pos = 0; + char buff[1024]; + + retstring[0] = '\0'; + for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) { + itemindex = CHAR_getPoolItemIndex( talkerindex, i); + if( ITEM_CHECKINDEX( itemindex)) { + int poolflg = FALSE; + snprintf( buff, sizeof( buff), +#ifdef _ITEM_PILENUMS + "%s|%d|%d|%d|%d|%s|%d|", + +#else + "%s|%d|%d|%d|%d|%s|", +#endif + ITEM_getChar( itemindex, ITEM_SECRETNAME), + poolflg, + ITEM_getInt( itemindex, ITEM_LEVEL), + ITEM_getInt( itemindex, ITEM_COST), + ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), + ITEM_getChar( itemindex, ITEM_EFFECTSTRING) +#ifdef _ITEM_PILENUMS + ,ITEM_getInt( itemindex, ITEM_USEPILENUMS) +#endif + ); + if( pos +strlen( buff)>= retstringlen) { + fprint( "buffer over err\n"); + break; + } + strcpy( &retstring[pos], buff); + pos += strlen( buff); + } + } +} + +static BOOL NPC_PoolItemShop_PoolItem( int meindex, int talkerindex, int num) +{ + int emptyindex; + int itemindex; + int cost = CHAR_getWorkInt( meindex, NPC_WORK_COST); + + emptyindex = CHAR_getCharPoolItemIndexElement( talkerindex); + if( emptyindex == -1 ) { + return FALSE; + } + + itemindex = CHAR_getItemIndex( talkerindex, num); + if( !ITEM_CHECKINDEX( itemindex)) { + fprint( "err"); + return FALSE; + } + +#if 1 // ֿͬⲻɴƷ + if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || // dzʧ + ITEM_getInt( itemindex, ITEM_VANISHATDROP) || // ʧ + !ITEM_getInt( itemindex, ITEM_CANPETMAIL)) { // ɳʼ + print("\n ķ!!Ƿŵ:%s ", CHAR_getChar( talkerindex, CHAR_CDKEY) ); +#ifdef _POOL_ITEM_BUG + if( getPoolItemBug()==2 || getPoolItemBug()==3 ) + { + if(getPoolItemBug()==3){ + int i; + for(i = 0; i < 32; i ++){ + if(getPoolItem(i) == ITEM_getInt( itemindex, ITEM_ID)){ + break; + } + } + if(i == 32){ + return FALSE; + } + }else{ + return FALSE; + } + } +#else + +#endif + } +#endif + + CHAR_DelGold( talkerindex, cost ); + + CHAR_setPoolItemIndex( talkerindex, emptyindex, itemindex); + + CHAR_setItemIndex( talkerindex, num, -1); + CHAR_sendItemDataOne( talkerindex, num); + + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + LogItem( + CHAR_getChar( talkerindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talkerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "pool(ķŵ)", + CHAR_getInt( talkerindex,CHAR_FLOOR), + CHAR_getInt( talkerindex,CHAR_X ), + CHAR_getInt( talkerindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + + ); + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talkerindex, FALSE)){ + CHAR_talkToCli(talkerindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + + + return TRUE; +} + +static BOOL NPC_PoolItemShop_DrawItem( int meindex, int talkerindex, int num) +{ + int emptyindex; + int itemindex; + int i; + int cnt; + int work[CHAR_MAXPOOLITEMHAVE]; + + emptyindex = CHAR_findEmptyItemBox( talkerindex); + if( emptyindex == -1 ) return FALSE; + + itemindex = CHAR_getPoolItemIndex( talkerindex, num); + if( !ITEM_CHECKINDEX( itemindex)) { + fprint( "err\n"); + return FALSE; + } + CHAR_setItemIndex( talkerindex, emptyindex, itemindex); + CHAR_setPoolItemIndex( talkerindex, num, -1); + CHAR_sendItemDataOne( talkerindex, emptyindex); + for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) { + work[i] = -1; + } + cnt = 0; + for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) { + itemindex = CHAR_getPoolItemIndex( talkerindex, i); + if( ITEM_CHECKINDEX( itemindex)) { + work[ cnt++] = itemindex; + } + } + for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) { + CHAR_setPoolItemIndex( talkerindex, i, work[i]); + } + LogItem( + CHAR_getChar( talkerindex, CHAR_NAME ), + CHAR_getChar( talkerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "draw(ȡ)", + CHAR_getInt( talkerindex,CHAR_FLOOR), + CHAR_getInt( talkerindex,CHAR_X ), + CHAR_getInt( talkerindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + +#ifdef _SAMETHING_SAVEPOINT + if(CHAR_charSaveFromConnect(talkerindex, FALSE)){ + CHAR_talkToCli(talkerindex, -1, "ϵͳԶΪ浵!", CHAR_COLORRED); + } +#endif + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_quiz.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_quiz.c new file mode 100644 index 0000000..eb1aeba --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_quiz.c @@ -0,0 +1,1424 @@ +#include "version.h" +#include +#include "common.h" +#include "char_base.h" +#include "npc_quiz.h" +#include "npcutil.h" +#include "char.h" +#include "lssproto_serv.h" +#include "buf.h" +#include "function.h" +#include "readmap.h" +#include "object.h" +#include "log.h" + +#define MEPLAYER 8 +#define OLDNO 100 + +enum { + CHAR_WORK_PLAYER1 = CHAR_NPCWORKINT1, + CHAR_WORK_PLAYER2 = CHAR_NPCWORKINT2, + CHAR_WORK_PLAYER3 = CHAR_NPCWORKINT3, + CHAR_WORK_PLAYER4 = CHAR_NPCWORKINT4, + CHAR_WORK_PLAYER5 = CHAR_NPCWORKINT5, + CHAR_WORK_PLAYER6 = CHAR_NPCWORKINT6, + CHAR_WORK_PLAYER7 = CHAR_NPCWORKINT7, + CHAR_WORK_PLAYER8 = CHAR_NPCWORKINT8, + CHAR_WORK_QUIZNUM = CHAR_NPCWORKINT9, +}; + +NPC_QUIZ* Quiz; + +struct pl{ + int talkerindex; + int quizno; + int answer; + int ansno; + int oldno[OLDNO]; + int *ptr; +}; + + +static int quizcnt = 0; + + +static void NPC_Quiz_selectWindow( int meindex, int talker, int num); +int *NPC_GetQuestion(int meindex); +BOOL NPC_QuizItemFullCheck(int meindex, int talker); +BOOL NPC_PlayerCheck(int meindex,int talker); +int NPC_RealyCheack(int meindex,int talker); +int NPC_QuizRandAnswer(int p_no,int q_no, int mode, + char *work1,char *work2,char *work3); +int NPC_QuizBorderLine(int ans, char *buf); +int NPC_QuizWarpBorderLine(int ans, char *buf); + +BOOL NPC_QuizAddItem(int talker,char *buf); + +BOOL NPC_EntryItemDel(int talker,char *buf); +BOOL NPC_EntryItemCheck(int talker,char *buf); +BOOL NPC_EntryStoneDel(int talker,char *buf); +BOOL NPC_EntryStoneCheck(int talker,char *buf); +BOOL NPC_QUIZPARTY_CHAECK(int meindex,int talker); + +BOOL NPC_QuizInit( int meindex ) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + int *tbl; + int i; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "StartMsg", buf, sizeof( buf)) == NULL){ + print("Quiz_StartMsgErr:%s", CHAR_getChar( meindex, CHAR_NAME)); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Quiznum", buf, sizeof( buf)) == NULL){ + print("QuizNumErrErr:%s", CHAR_getChar( meindex, CHAR_NAME)); + return FALSE; + } + + CHAR_setWorkInt( meindex, CHAR_WORK_QUIZNUM, atoi( buf)); + + for(i =0 ; i < 8 ; i++){ + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + i, -1); + } + tbl = NPC_GetQuestion( meindex); + + if( CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM) > ( tbl[0] - 1)){ + print( + "%s?,ԲȦquiz(%d?)ȳ(%d)", + CHAR_getChar( meindex, CHAR_NAME), + (tbl[0]-1), + CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM) + ); + return FALSE; + } + + return TRUE; + +} + +void NPC_QuizTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + if(NPC_QUIZPARTY_CHAECK(meindex,talkerindex)==FALSE){ + NPC_Quiz_selectWindow( meindex, talkerindex, 4); + + } + if(NPC_QuizItemFullCheck(meindex, talkerindex) == FALSE){ + NPC_Quiz_selectWindow( meindex, talkerindex, 3); + }else{ + NPC_Quiz_selectWindow( meindex, talkerindex, 0); + } +} + +static void NPC_Quiz_selectWindow( int meindex, int talker, int num) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + char buf[256]; + char buf2[256]; + char buf3[256]; + + int i = 0,k; + int questionno = 0; + int fd = getfdFromCharaIndex( talker); + int buttontype = 0; + int messagetype = 0; + int windowno = 0; + int len = 4; + int p_no; + int p_old; + int loop=0; + int ans; + BOOL entryflg = TRUE; + switch( num) { + case 0: + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL){ + print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + if(NPC_Util_GetStrFromStrWithDelim( argstr,"StartMsg", + token, sizeof( token)) == NULL){ + print("%sStartMsg", CHAR_getChar(meindex,CHAR_NAME)); + return; + } + buttontype = WINDOW_BUTTONTYPE_YESNO; + messagetype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_QUIZ_START; + break; + + case 1: + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL){ + print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryItem", + buf2, sizeof( buf2)) != NULL){ + if(NPC_EntryItemCheck( talker, buf2) == FALSE){ + entryflg = FALSE; + } + } + if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryStone", + buf3, sizeof( buf3)) != NULL){ + if(NPC_EntryStoneCheck( talker, buf3) == FALSE){ + entryflg = FALSE; + } + } + if(entryflg == FALSE){ + if(NPC_Util_GetStrFromStrWithDelim( argstr,"NoEntryMsg", + token, sizeof( token)) != NULL) { + buttontype = WINDOW_BUTTONTYPE_OK; + messagetype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_QUIZ_START; + + } + + }else if(NPC_PlayerCheck( meindex, talker) == FALSE) { + /*-----*/ + sprintf(token,"\n\n\n ,Եһ" + "\nxx պ幫ئƥئо" + ); + buttontype = WINDOW_BUTTONTYPE_OK; + messagetype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_QUIZ_START; + + }else{ + if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryItem", + buf2, sizeof( buf2)) != NULL){ + if(NPC_EntryItemDel( talker, buf2) ==FALSE){ + //print("ûʧ(%s)",CHAR_getChar(meindex,CHAR_NAME)); + return; + } + } + if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryStone", + buf3, sizeof( buf3)) != NULL){ + if(NPC_EntryStoneDel( talker, buf3) ==FALSE){ + //print("Ǯûʧ(%s)",CHAR_getChar(meindex,CHAR_NAME)); + return; + } + } + NPC_Quiz_selectWindow(meindex, talker, 2); + return; + } + break; + + case 3: + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL){ + ;//print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + + /*-- --*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr,"ItemFullMsg", + token, sizeof( token)) == NULL) + { + //print("%sItemFullMsg", CHAR_getChar(meindex,CHAR_NAME)); + return; + } + + buttontype = WINDOW_BUTTONTYPE_OK; + messagetype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_QUIZ_START; + + break; + case 2: + /*--̼--*/ + { + int *tbl; + int point; + int *pl_ptr; + int warp_flg = -1; + int floor=0,x=0,y=0; + + struct pl PLAYER; + + + /*--ɡūئȻئо--*/ + if(NPC_QUIZPARTY_CHAECK(meindex,talker)==FALSE){ + NPC_Quiz_selectWindow( meindex, talker, 4); + } + + + + /*--ݩϷ?įëد--*/ + p_no = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT); + point = CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 + p_no); + pl_ptr = (int *)point; + + /*-- ƹ\ëհ --*/ + memcpy(&PLAYER, pl_ptr, sizeof(struct pl)); + + /*--廯δ׼ƥAëU--*/ + if(PLAYER.quizno + == CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM)) + { + double avg; + int okflg; + char buf2[512]; + + /*-- arg̻Pđ@ --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) + { + ;//print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + + /*--ݩѱɱԪʧ̷ةëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr, "GetItem", buf, sizeof( buf) ) + !=NULL) + { + okflg = NPC_QuizBorderLine(PLAYER.answer,buf); + if(okflg == -1) + { + + }else{ + + getStringFromIndexWithDelim(buf , "," , okflg+1, buf3, sizeof(buf3)); + if(NPC_QuizAddItem( talker, buf3) == FALSE) return ; + + } + } + + /*--ݩѱɱԪʧ̷ةëܰ---*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Border", buf, sizeof( buf) ) + !=NULL) + { + okflg = NPC_QuizBorderLine(PLAYER.answer,buf); + if(okflg == -1) + { + NPC_Util_GetStrFromStrWithDelim( argstr, "FailureMsg", + buf2,sizeof(buf2)); + + CHAR_talkToCli( talker, meindex, buf2, CHAR_COLORWHITE); + + }else{ + + getStringFromIndexWithDelim(buf , "," , okflg+1, buf2, sizeof(buf2)); + CHAR_talkToCli( talker, meindex, buf2, CHAR_COLORWHITE); + } + } + + + /*--ݩѱɱԪ---*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Warp", buf, sizeof( buf) ) + !=NULL) + { + warp_flg = NPC_QuizWarpBorderLine(PLAYER.answer,buf); + if(warp_flg != -1) { + char warpbuf[32]; + + getStringFromIndexWithDelim(buf , "," , warp_flg+1, buf2, sizeof(buf2)); + getStringFromIndexWithDelim(buf2 , "." , 1, warpbuf, sizeof(warpbuf)); + floor = atoi(warpbuf); + getStringFromIndexWithDelim(buf2 , "." , 2, warpbuf, sizeof(warpbuf)); + x = atoi(warpbuf); + getStringFromIndexWithDelim(buf2 , "." , 3, warpbuf, sizeof(warpbuf)); + y = atoi(warpbuf); + } + } + + + + /*-- ʧì()ëƻ -*/ + avg = (double)PLAYER.answer / + CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM) * 100; +#if 0 + sprintf(token,"xxxxxxx" + "\n\nȷ %d %d " + "\nȷ %d ?" + "\n\n%s", + CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM), + PLAYER.answer, + (int)avg, + buf2 + ); +#endif + + /*--͐_ë -*/ + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + + CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT) ,-1); + +// print("\n %s %d",CHAR_getChar(talker,CHAR_NAME),(int)PLAYER.ptr); + + /*--ƹ_ࢷC--*/ + free(PLAYER.ptr); + +#if 0 + /*-ƥ˪--*/ + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_QUIZ_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +#endif + + //廯ΏmʆAδȻշ©z + if(warp_flg != -1){ + CHAR_warpToSpecificPoint(talker, floor, x, y); + } + return; + + } + + /*--???ɬýľ?įë?--*/ + tbl = NPC_GetQuestion( meindex); + + + /*--Ѽ tbl[0]巴ëmזѻȻ --*/ + if( CHAR_getWorkInt( meindex, CHAR_WORK_QUIZNUM) > ( tbl[0] - 1)) + { + /*--Իئ--*/ + /*--ƹ_ࢷC--*/ + free(PLAYER.ptr); + return ; + } + + /*--ë???--*/ + while(1){ + loop++; + i = rand()%( tbl[0]); + if(i == 0) continue; + questionno = tbl[i]; + + /*--օ--*/ + for( k = 0 ; k < OLDNO ; k++){ + if(PLAYER.oldno[k] == questionno) { + loop = 0; + break; + } + } + if(k == OLDNO) break; + + /*--׻ʣ--*/ + if(loop == 5000) { + print("ⲻiȫظj"); + break; + } + } + + p_no = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANT); + p_old = CHAR_getWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC); + + PLAYER.quizno++; + + /*-- ƥ?įëʢƻ--*/ + PLAYER.oldno[p_old] = questionno; + p_old++; + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC, p_old); + + strncpy( buf, Quiz[questionno].question, + sizeof( Quiz[questionno].question)); + + /*--Ӯ巽ȻyǹƼ\ë--*/ + if(strlen( buf) < 40) { + strcat( buf, "\n"); + }else if(strlen( buf) > 79) { + len = 5; + } + + /*--ǩѨ--*/ + if( Quiz[questionno].answertype == 4) { + + if(strlen( buf) < 40) { + strcat( buf,"\n\n"); + }else if( strlen( buf) < 80) { + strcat( buf,"\n\n"); + }else{ + strcat( buf,"\n"); + } + + /*--̤善--*/ + sprintf( token," quiz %d " + "\n%s " + "\nд\n" + "?(д밴ϣ)", + PLAYER.quizno, + buf); + + buttontype = WINDOW_BUTTONTYPE_OK; + messagetype = WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT; + windowno = CHAR_WINDOWTYPE_QUIZ_MAIN; + + /*--ػëƹ巤ʢ--*/ + memcpy(pl_ptr,&PLAYER,sizeof(struct pl)); + + break; + + /*--xǹx--*/ + }else if( Quiz[questionno].answertype == 2) { + char work1[128]; + char work2[128]; + char work3[128]; + + ans = (rand() % 3) + 1; + + ans = NPC_QuizRandAnswer(p_no,questionno,3, work1,work2,work3); + PLAYER.ansno = ans; + + /*-- ÖR(ǹk --*/ + sprintf(token,"%d\n quiz %d " + "\n%s " + "\n\n %s" + "\n %s" + "\n %s", + len, + PLAYER.quizno, + buf, + work1, + work2, + work3 + ); + + /*-- ǹ --*/ + }else if( Quiz[questionno].answertype == 1){ + char work1[128]; + char work2[128]; + char work3[128]; + + strcpy(work3,"-1"); + ans = NPC_QuizRandAnswer(p_no,questionno,2, work1,work2,work3); + PLAYER.ansno = ans; + + /*-- ÖR(ǹk --*/ + sprintf(token,"%d\n quiz %d " + "\n%s " + "\n\n %s" + "\n %s", + len, + PLAYER.quizno, + buf, + work1, + work2 + ); + } + buttontype = WINDOW_BUTTONTYPE_CANCEL; + messagetype = WINDOW_MESSAGETYPE_SELECT; + windowno = CHAR_WINDOWTYPE_QUIZ_MAIN; + + memcpy(pl_ptr,&PLAYER,sizeof(struct pl)); + + } + break; + + case 4: + /*-- arg̻Pđ@ --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) + { + print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr,"Party", + token, sizeof( token)) != NULL) + { + buttontype = WINDOW_BUTTONTYPE_OK; + messagetype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_QUIZ_START; + } + + break; + + } + + /*-ƥ˪--*/ + lssproto_WN_send( fd, messagetype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +void NPC_QuizWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int i=0; + int old_no; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) { + return; + } + switch( seqno){ + case CHAR_WINDOWTYPE_QUIZ_START: + if( select == WINDOW_BUTTONTYPE_YES) { + NPC_Quiz_selectWindow(meindex, talkerindex, 1); + } + + if(select == WINDOW_BUTTONTYPE_OK){ + } + + break; + + case CHAR_WINDOWTYPE_QUIZ_MAIN: + { + int point; + int *pl_ptr; + int p_no; + struct pl PLAYER; + //Change fix 鿴ԭlog + if( CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1) == -1 ){ + // print("\nlog->ʺ:%s,:%s\n ", CHAR_getChar( talkerindex, CHAR_CDKEY ), CHAR_getChar( talkerindex, CHAR_NAME) ); + break; + } + + p_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + // print("\nlog->CHAR_WORK_PLAYER1:%d,p_no:%d,ʺ:%s\n", CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1), p_no, CHAR_getChar( talkerindex, CHAR_CDKEY ) ); + point = CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 + p_no); + pl_ptr = (int *)point; + + memcpy(&PLAYER,pl_ptr,sizeof(struct pl)); + + p_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + old_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANTSEC)-1; + i= PLAYER.oldno[old_no]; + + if(select == WINDOW_BUTTONTYPE_OK){ + if( i >= quizcnt || i < 0 ) return; + if( Quiz == NULL || strlen( Quiz[i].select1) >= 128 ) return; + + if( strstr( data, Quiz[i].select1) != NULL) { + PLAYER.answer++; + } + memcpy(pl_ptr,&PLAYER,sizeof(struct pl)); + NPC_Quiz_selectWindow(meindex, talkerindex, 2); + }else if(select == WINDOW_BUTTONTYPE_CANCEL){ + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + + CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) ,-1); + free(PLAYER.ptr); + }else if( atoi( data) == 0){ + }else{ + if(atoi(data) == PLAYER.ansno){ + PLAYER.answer++; + } + memcpy(pl_ptr,&PLAYER,sizeof(struct pl)); + NPC_Quiz_selectWindow(meindex, talkerindex, 2); + } + } + break; + + } + + +} + +/* + *ʾĸ̼ + */ +int NPC_QuizBorderLine(int ans ,char *buf) +{ + char buf2[32]; + int j = 1; + int border; + + + while(getStringFromIndexWithDelim(buf , "," , j, buf2, sizeof( buf2)) + !=FALSE ) + { + border = atoi(buf2); + + if(ans >= border) { + return j; + } + + j += 2; + + } + return -1; +} +/* + *ʾĸ̼ + */ +int NPC_QuizWarpBorderLine(int ans ,char *buf) +{ + char buf2[32]; + int j = 1; + int border; + + + while(getStringFromIndexWithDelim(buf , "," , j, buf2, sizeof( buf2)) + != FALSE ) + { + border = atoi(buf2); + + if(ans >= border) { + return j; + } + + j += 2; + + } + return -1; +} + + +/* + *--ʧ̷ةëܰѽ + */ +BOOL NPC_QuizAddItem(int talker,char *buf) +{ + int i=1; + int ret; + char buf2[16]; + int itemindex; + char token[512]; + + /*--ѲوVƻʧ̷ةɬýľ¼ĸةƥ--*/ + while(getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2)) + != FALSE ) + { + i++; + } + i--; + if(i == 1){ + getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2)); + }else{ + /*--¼ĸة--*/ + i = (rand() % i)+1; + getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2)); + } + + itemindex = ITEM_makeItemAndRegist(atoi(buf2)); + + if(itemindex == -1) return FALSE; + /*ʧ̷ةܰ(Qʧ̷ةƱľk*/ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( !CHAR_CHECKITEMINDEX( talker, ret) ){ + print( "npc_quiz.c: additem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + + CHAR_talkToCli( talker, -1, "", CHAR_COLORWHITE); + + return FALSE; + } + + if(itemindex != -1) { + /* + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + "QuizAddItem(->쵽ĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + */ + } + + sprintf(token,"õ%s", ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + + CHAR_sendItemDataOne( talker, ret); + return TRUE; + +} + +int NPC_QuizRandAnswer(int p_no,int q_no, int mode, + char *work1,char *work2,char *work3) +{ + int ans; + int ra; + + ans = (rand() % mode) + 1; + if(ans == 1) { + if( Quiz[q_no].answerNo == 1) { + strcpy( work1, Quiz[q_no].select1); + if(mode == 2) { + strcpy( work2, Quiz[q_no].select2); + return ans; + } + ra = rand()%2; + + if(ra == 0) { + strcpy( work2, Quiz[q_no].select2); + strcpy( work3, Quiz[q_no].select3); + }else{ + strcpy( work2, Quiz[q_no].select3); + strcpy( work3, Quiz[q_no].select2); + } + }else if( Quiz[q_no].answerNo == 2) { + strcpy( work1, Quiz[q_no].select2); + if(mode == 2) { + strcpy( work2, Quiz[q_no].select1); + return ans; + } + + ra = rand()%2; + if(ra == 0) { + strcpy( work2, Quiz[q_no].select1); + strcpy( work3, Quiz[q_no].select3); + }else{ + strcpy( work2, Quiz[q_no].select3); + strcpy( work3, Quiz[q_no].select1); + } + }else{ + strcpy( work1, Quiz[q_no].select3); + ra = rand()%2; + if(ra == 0) { + strcpy( work2, Quiz[q_no].select1); + strcpy( work3, Quiz[q_no].select2); + }else{ + strcpy( work2, Quiz[q_no].select1); + strcpy( work3, Quiz[q_no].select2); + } + } + }else if(ans == 2) { + if(Quiz[q_no].answerNo == 1) { + strcpy( work2, Quiz[q_no].select1); + if(mode == 2) { + strcpy( work1, Quiz[q_no].select2); + return ans; + } + ra=rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select2); + strcpy( work3, Quiz[q_no].select3); + }else { + strcpy( work1, Quiz[q_no].select3); + strcpy( work3, Quiz[q_no].select2); + } + }else if( Quiz[q_no].answerNo == 2) { + strcpy( work2, Quiz[q_no].select2); + if(mode == 2){ + strcpy( work1, Quiz[q_no].select1); + return ans; + } + ra = rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select1); + strcpy( work3, Quiz[q_no].select3); + }else { + strcpy( work1, Quiz[q_no].select3); + strcpy( work3, Quiz[q_no].select1); + } + }else { + strcpy( work2, Quiz[q_no].select3); + ra = rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select1); + strcpy( work3, Quiz[q_no].select2); + }else { + strcpy( work1, Quiz[q_no].select2); + strcpy( work3, Quiz[q_no].select1); + } + } + }else if(ans == 3) { + if( Quiz[q_no].answerNo == 1) { + strcpy( work3, Quiz[q_no].select1); + ra = rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select2); + strcpy( work2, Quiz[q_no].select3); + }else { + strcpy( work1, Quiz[q_no].select3); + strcpy( work2, Quiz[q_no].select2); + } + }else if( Quiz[q_no].answerNo == 2) { + strcpy( work3, Quiz[q_no].select2); + ra = rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select1); + strcpy( work2, Quiz[q_no].select3); + }else { + strcpy( work1, Quiz[q_no].select3); + strcpy( work2, Quiz[q_no].select1); + } + }else{ + strcpy( work3, Quiz[q_no].select3); + ra = rand()%2; + if(ra == 0) { + strcpy( work1, Quiz[q_no].select1); + strcpy( work2, Quiz[q_no].select2); + }else { + strcpy( work1, Quiz[q_no].select2); + strcpy( work2, Quiz[q_no].select1); + } + } + } + return ans; + +} + + +/*--ͩjƥk--*/ +BOOL NPC_PlayerCheck(int meindex,int talker) + { + int i; + int k=0; + int *ptr; + struct pl Player; + + + NPC_RealyCheack( meindex, talker); + + /*-- 廥ؤ¾ --*/ + for(i = 0 ; i < MEPLAYER ; i++){ + if( (CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 +i ) == -1)) + { + break; + } + } + + if(i == MEPLAYER) return FALSE; + + + /*-- ƹ --*/ + if((ptr =(int *) calloc( 1,sizeof(struct pl))) == NULL){ + print("޷ȷ%s",CHAR_getChar(meindex,CHAR_NAME)); + return FALSE; + } + + /*-- ̼ë??-*/ + Player.ptr = ptr; + Player.talkerindex = talker; //npc̼͵??? + Player.quizno = 0; //ػ + Player.answer = 0; //ݩ + Player.ansno = 0; //?įëʩjë±׶˱) + + /*--Ėߕd--*/ + for(k=0 ; k < OLDNO; k++) { + Player.oldno[k] = -1; + } + + /*--ƹë--*/ + memcpy(ptr,&Player,sizeof(struct pl)); + + + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC,0); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT,0); + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD,0); + + + /*--мݩϷ?įë--*/ + CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, i); + + k= (int)ptr; + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + i, k ); + return TRUE; + +} + +int NPC_RealyCheack(int meindex,int talker) +{ + int fl, x, y; + int i, j; + int px[10] = {0, 1, 0,-1, 1,-1, 1, 0,-1}; + int py[10] = {0,-1,-1,-1, 0, 0, 1, 1, 1}; + int objindex; + + OBJECT object; + int talkerindex; + BOOL okflg = FALSE; + struct pl PLAYER; + int *pl_ptr; + int point; + + fl = CHAR_getInt( meindex, CHAR_FLOOR); + + for(j = 0 ; j < MEPLAYER ; j++) { + point = CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 + j); + okflg = FALSE; + if(point == -1) continue; + + /*--ݩϷ?įëد--*/ + pl_ptr = (int *)point; + + memcpy(&PLAYER, pl_ptr, sizeof(struct pl)); + talkerindex = PLAYER.talkerindex; + + for(i=0 ; i < 10 ; i++) { + x = px[i] + CHAR_getInt( meindex, CHAR_X); + y = py[i] + CHAR_getInt( meindex, CHAR_Y); + + for(object = MAP_getTopObj(fl,x,y) ; object; + object = NEXT_OBJECT( object)) + { + objindex = GET_OBJINDEX( object); + + if( OBJECT_getType( objindex) == OBJTYPE_CHARA ){ + if( OBJECT_getIndex( objindex) == talkerindex) { + if(talkerindex == talker) { + okflg = TRUE; +// print("\n %s %d",CHAR_getChar(talker,CHAR_NAME),(int)PLAYER.ptr); + free(PLAYER.ptr); + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + j,-1); + }else{ + okflg = TRUE; + } + break; + } + } + } + if(okflg == TRUE) break; + } + + if(okflg ==FALSE){ +// print("\n %s %d",CHAR_getChar(talker,CHAR_NAME),(int)PLAYER.ptr); + free(PLAYER.ptr); + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + j,-1); + } + + } + + return -1; +} + +BOOL QUIZ_initQuiz( char *filename) +{ + + FILE* f; + char line[512]; + char buf2[512], buf3[128]; + char buf[512]; + int i, linenum=0; + f = fopen(filename,"r"); + if( f == NULL ){ + print( "file open error\n"); + return FALSE; + } + while( fgets( line, sizeof( line ), f ) ){ + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + linenum ++; + quizcnt++; + } + + if( fseek( f, 0, SEEK_SET ) == -1 ){ + fprint( "Seek Error\n" ); + fclose(f); + return FALSE; + } + + Quiz = allocateMemory( sizeof(NPC_QUIZ) * (quizcnt+1) ); + if( Quiz == NULL ){ + fprint( "Can't allocate Memory %d\n", sizeof(Quiz) * (quizcnt+1)); + fclose( f ); + return FALSE; + } + linenum = 0; + memset( buf3, 0, sizeof(buf3)); + while( fgets( line, sizeof( line ), f ) ){ + if( line[0] == '#' )continue; + if( line[0] == '\n' )continue; + chomp( line ); + replaceString( line, '\t' , ' ' ); + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) { + strcpy( line, buf); + } + + if( getStringFromIndexWithDelim( line, ",", 1, buf2, sizeof(buf2)) == FALSE ) continue; + Quiz[linenum].no = atoi(buf2); + + if( getStringFromIndexWithDelim( line, ",", 2, buf2, sizeof(buf2)) == FALSE ) continue; + Quiz[linenum].type = atoi(buf2); + + if( getStringFromIndexWithDelim( line, ",", 3, buf2, sizeof(buf2)) == FALSE ) continue; + Quiz[linenum].level = atoi(buf2); + + if( getStringFromIndexWithDelim( line, ",", 4, buf2, sizeof(buf2)) == FALSE ) continue; + Quiz[linenum].answertype = atoi(buf2); + + if( getStringFromIndexWithDelim( line, ",", 5, buf2, sizeof(buf2)) == FALSE ) continue; + Quiz[linenum].answerNo = atoi(buf2); + + if( getStringFromIndexWithDelim( line, ",", 6, buf2, sizeof(buf2)) == FALSE ) continue; + memcpy( Quiz[linenum].question, buf2, sizeof( Quiz[linenum].question)); + + + if( getStringFromIndexWithDelim( line, ",", 7, buf3, sizeof(buf3)) == FALSE ) continue; + memcpy( Quiz[linenum].select1, buf3, sizeof( Quiz[linenum].select1)); + if( getStringFromIndexWithDelim( line, ",", 8, buf3, sizeof(buf3)) == FALSE ) continue; + memcpy( Quiz[linenum].select2, buf3, sizeof( Quiz[linenum].select2)); + if( getStringFromIndexWithDelim( line, ",", 9, buf3, sizeof(buf3)) == FALSE ) continue; + memcpy( Quiz[linenum].select3, buf3, sizeof( Quiz[linenum].select3)); + + if(Quiz[linenum].answertype == 1){ + if(Quiz[linenum].answerNo == 3){ + return FALSE; + } + } + + if(Quiz[linenum].answertype == 4){ + if(Quiz[linenum].answerNo != 1){ + return FALSE; + } + } + linenum ++; +// quizcnt++; + } + if( quizcnt < linenum ){ + print("ERR linenum:%d >= quizcnt:%d\n", linenum, quizcnt); + return FALSE; + } + + quizcnt = linenum; + fclose( f); + return TRUE; + +} + +int *NPC_GetQuestion(int meindex) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i,j; + int type=0; + int answer=0; + int level=0; + int *tbl; + char buf[16]; +#ifdef _NPC_QUIZSCOPE + int scope0,scope1; + char buf3[32]; +#endif + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if(NPC_Util_GetStrFromStrWithDelim(argstr,"Type",buf, sizeof( buf)) != NULL ){ + type = atoi(buf); + } + if( type <= 0){ + type = 0xffff; + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Answer", buf, sizeof( buf)) != NULL){ + answer = atoi(buf); + } + if(answer <= 0){ + answer = 0xffff; + } + + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Level", buf, sizeof( buf)) != NULL ){ + level = atoi(buf); + } + if(level <= 0){ + level = 0xffff; + } + +#ifdef _NPC_QUIZSCOPE + scope0 = 0; + scope1 = quizcnt; + if(NPC_Util_GetStrFromStrWithDelim( argstr, "Scope", buf, sizeof( buf)) != NULL ){ + getStringFromIndexWithDelim( buf, "-", 1, buf3, sizeof(buf3)); + scope0 = atoi( buf3 ); + getStringFromIndexWithDelim( buf, "-", 2, buf3, sizeof(buf3)); + scope1 = atoi( buf3 ); + } +#endif + + for(j=0,i=0; i < quizcnt ;i++){ + if( (type & (1 << (Quiz[i].type-1))) != (1 << (Quiz[i].type-1))){ + continue; + } + if((answer & (Quiz[i].answertype)) != Quiz[i].answertype){ + continue; + } + if((level & (Quiz[i].level)) != Quiz[i].level){ + continue; + } +#ifdef _NPC_QUIZSCOPE + if( i < scope0 + || i > scope1 ) + continue; +#endif + j++; + } + + { + int tmp_tbl[j+1]; + tmp_tbl[0] = j+1; + for(j=1,i=0; i < quizcnt ;i++){ + if( (type & (1 << (Quiz[i].type-1))) != (1 << (Quiz[i].type-1))){ + continue; + } + + if((answer & (Quiz[i].answertype)) != Quiz[i].answertype){ + continue; + } + + if((level & (Quiz[i].level)) != Quiz[i].level){ + continue; + } +#ifdef _NPC_QUIZSCOPE + if( i < scope0 + || i > scope1 ) + continue; +#endif + tmp_tbl[j] = i; + + j++; + } + + tbl = tmp_tbl; + return tbl; + } +} + +/*--ʧ̷ةƼ弰--*/ +BOOL NPC_QuizItemFullCheck(int meindex,int talker) +{ + int i; + int itemindex; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf2[32]; + + + /*-- c¾-*/ + int itemMax = CheckCharMaxItem(talker); + for( i = CHAR_STARTITEMARRAY ; i < itemMax ; i++ ) { + itemindex = CHAR_getItemIndex( talker , i ); + if( !ITEM_CHECKINDEX( itemindex) ) { + return TRUE; + } + } + + /*-- arg̻Pđ@ --*/ + if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) + { + print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); + } + + /*-- ʧ̷ة --*/ + if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryItem", + buf2, sizeof( buf2)) != NULL) + { + if(NPC_EntryItemCheck( talker, buf2) == FALSE){ + NPC_Quiz_selectWindow( meindex, talker, 3); + return FALSE; + + }else{ + return TRUE; + } + } + + + return FALSE; + +} + + +/* + *ż + */ +BOOL NPC_EntryStoneCheck(int talker,char *buf) +{ + int stone; + int cost; + + cost= atoi( buf); + stone = CHAR_getInt( talker, CHAR_GOLD); + + if(cost > stone){ + return FALSE; + } + + return TRUE; +} + +/* + *ż + */ +BOOL NPC_EntryStoneDel(int talker,char *buf) +{ + int stone; + int cost; + char token[256]; + + cost= atoi( buf); + stone = CHAR_getInt( talker, CHAR_GOLD); + + if((stone-cost) < 0){ + CHAR_setInt( talker, CHAR_GOLD, 0); + }else{ + CHAR_DelGold( talker, cost ); + } + + sprintf( token, "%d stone", cost); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); + return TRUE; +} + + +/* + *ʧ̷ةë + */ +BOOL NPC_EntryItemDel(int talker,char *buf) +{ + + int i = 1, j = 1,k = 1; + char buff3[128]; + char buf2[32]; + int itemindex; + + + while(getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ + k++; + if(strstr(buff3, "*") !=NULL){ + int itemno; + int kosuu; + int id; + int cnt=0; + getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); + itemno = atoi(buf2); + getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); + kosuu = atoi(buf2); + int itemMax = CheckCharMaxItem(talker); + for( i =0 ; i < itemMax ; i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id=ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno==id){ + cnt++; + /* + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + "QuizDelItem(->ĵ)", + CHAR_getInt( talker, CHAR_FLOOR), + CHAR_getInt( talker, CHAR_X ), + CHAR_getInt( talker, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + */ + CHAR_DelItem( talker, i); + if(cnt == kosuu){ + break; + } + } + } + } + }else{ + /*--Ϸ?įʧ̷ةë---*/ + int itemMax = CheckCharMaxItem(talker); + for( j = 0 ; j < itemMax ; j++){ + itemindex = CHAR_getItemIndex( talker ,j); + + if( ITEM_CHECKINDEX(itemindex) ){ + if( atoi( buff3) == ITEM_getInt(itemindex,ITEM_ID)){ + /* + LogItem( + CHAR_getChar( talker, CHAR_NAME ), + CHAR_getChar( talker, CHAR_CDKEY ), + "QuizDelItem(->쵽ĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + */ + CHAR_DelItem( talker, j); + } + } + } + } + } + + return TRUE; +} + +/* + *--ʧ̷ةͷë浤 + */ +BOOL NPC_EntryItemCheck(int talker,char *buf) +{ + + char buf2[512]; + char buf3[256]; + int id=0; + BOOL flg = FALSE; + int i; + int itemindex; + int itemno; + int kosuu; + int cnt=0; + int k=1; + + while(getStringFromIndexWithDelim(buf , "," , k, buf2, sizeof(buf2)) + !=FALSE ) + { + flg = FALSE; + k++; + + if(strstr(buf2,"*") != NULL){ + cnt = 0; + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemno = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + int itemMax = CheckCharMaxItem(talker); + for( i=0 ; i < itemMax;i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id = ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno == id){ + cnt++; + if(cnt == kosuu){ + flg = TRUE; + break; + } + } + } + } + if(flg == FALSE) + { + return FALSE; + } + }else{ + itemno = atoi(buf2); + int maxitem; + maxitem = CheckCharMaxItem(talker); + for( i=0 ; i < maxitem;i++ ){ + itemindex = CHAR_getItemIndex( talker , i ); + if( ITEM_CHECKINDEX(itemindex) ){ + id = ITEM_getInt(itemindex ,ITEM_ID ); + if(itemno == id){ + flg = TRUE; + break; + } + } + } + + if(flg == FALSE) + { + return FALSE; + } + } + } + + return TRUE; + +} + +/* + * ɡū + */ +BOOL NPC_QUIZPARTY_CHAECK(int meindex,int talker) +{ + + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + return FALSE; + } + + return TRUE; + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_riderman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_riderman.c new file mode 100644 index 0000000..6c4c593 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_riderman.c @@ -0,0 +1,900 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_riderman.h" +#include "family.h" +#include "log.h" +#include "autil.h" +extern int familyNumTotal; +extern char familyListBuf[MAXFAMILYLIST]; +extern tagRidePetTable ridePetTable[296]; +extern struct FM_POINTLIST fmpointlist; + +char sendbuf[1024]; +char buf[1024]; +char subbuf[128]; +int i, j; + +/* + * ɬýľūëNPC + * + */ + +struct { + int windowno; + int windowtype; + int buttontype; + int takeitem; + int giveitem; + int takegold; + char message[4096]; + int letter[4]; +}w; + +struct { + BOOL use; + int checkhaveitem; + int checkhaveitemgotowin; + int checkdonthaveitem; + int checkdonthaveitemgotowin; + int warp; + int battle; + int gotowin; +}buttonproc[13]; /* ok,cancel, yes,no,prev,next ݼ */ + + + + + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; + +static void NPC_Riderman_selectWindow( int meindex, int toindex, int num); +static BOOL NPC_Riderman_readData( int meindex, int windowno, BOOL chkflg); +static int NPC_Riderman_restoreButtontype( char *data ); +// static BOOL getLetter(int meindex,int talker ); +// static BOOL checkLetter(int meindex,int talker ); + +/********************************* +*********************************/ +BOOL NPC_RidermanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + //int i; + //char secondToken[1024]; + + // Robin test + // print(" riderman_Init "); + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", buf, sizeof( buf))== NULL ) + { + print( "riderman:ûָ趨ĵ \n"); + return FALSE; + } + /* ݱɬ÷ëƻ֧ */ + if( !NPC_Riderman_readData( meindex, -1, TRUE) ) { + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWINDOWMAN ); + + return TRUE; +} + + + + +/********************************* +*********************************/ +void NPC_RidermanTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + //print(" Rideman_fmindex:%d ", CHAR_getInt( meindex, CHAR_FMINDEX) ); + + NPC_Riderman_selectWindow( meindex, talkerindex, 1 ); + +} +/********************************* +*********************************/ +void NPC_RidermanLooked( int meindex , int lookedindex) +{ + + //print(" Look:me:%d,looked:%d ",meindex,lookedindex); + NPC_Riderman_selectWindow( meindex, lookedindex,1 ); + +} + +static void NPC_Riderman_selectWindow( int meindex, int toindex, int num) +{ + + int fd; + char buf[256]; + + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( !NPC_Util_charIsInFrontOfChar( toindex, meindex, 1 )) return; + + if( !NPC_Riderman_readData( meindex, num, FALSE) ) { + print( "riderman:readdata error\n"); + return; + } + + fd = getfdFromCharaIndex( toindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } +} + +void NPC_RidermanWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) + +{ + + + int button = -1; + char buf[512]; + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + if( !NPC_Riderman_readData( meindex, seqno - 100, FALSE) ) { + print( "riderman:readdata error\n"); + return; + } + /* ʾëƩ */ + if( w.windowtype == WINDOW_MESSAGETYPE_SELECT ) { + button = atoi( data)+5; + if( button > 12 ) { + print( "riderman:invalid button[%d]\n", button); + return; + } + } + else if( select & WINDOW_BUTTONTYPE_OK) button = 0; + else if( select & WINDOW_BUTTONTYPE_CANCEL) button = 1; + else if( select & WINDOW_BUTTONTYPE_YES) button = 2; + else if( select & WINDOW_BUTTONTYPE_NO) button = 3; + else if( select & WINDOW_BUTTONTYPE_PREV) button = 4; + else if( select & WINDOW_BUTTONTYPE_NEXT) button = 5; + else { + print( "riderman:invalid button[%d]\n", select); + return; + } + if( buttonproc[button].use == TRUE ) { + int fd; + int newwin = -1; + + fd = getfdFromCharaIndex( talkerindex); + + if( newwin == -1 ) { + newwin = buttonproc[button].gotowin; + } + + + //print(" takegold:%d ", w.takegold ); + + // Robin + // ѧϰ Lv 40 + if( newwin == 6 ) { + + int charImg; + // int i, petindex, bFind = 0; + + charImg = CHAR_getInt( talkerindex, CHAR_BASEBASEIMAGENUMBER); + if( CHAR_getInt( talkerindex, CHAR_LEARNRIDE ) >= 40 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѾѧѽ\nҪѧˡ", + buf, sizeof(buf))); + return; + } + + if( CHAR_getInt( talkerindex, CHAR_GOLD ) < w.takegold ) + { + char buf2[512]; + + sprintf( buf2, "\nܱǸรѧѲ㣡\nѧϰ˳Ҫ%dʯҡ", w.takegold); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( buf2, buf, sizeof(buf))); + return; + } + CHAR_DelGold( talkerindex, w.takegold ); + + CHAR_setInt( talkerindex, CHAR_LEARNRIDE, 40 ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_LEARNRIDE ); + + //sprintf( buf, "R|L|1" ); + //lssproto_FM_send( fd, buf ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( + "\n\nϲ㣡Ѿ˳ˡ\n Lv40 µij\nСร", + buf, sizeof(buf))); + + // + { + int fmindex, fmindexi, village, i; + char fmname[256], token[256], buf2[64]; + + sprintf( buf2, "%d", w.takegold/5 ); + for( i=0 ; i= 80 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѾѧмѽ\nҪѧˡ", + buf, sizeof(buf))); + return; + } + else if( CHAR_getInt( talkerindex, CHAR_LEARNRIDE ) < 40 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѧмࡡ", + buf, sizeof(buf))); + return; + } + + if( CHAR_getInt( talkerindex, CHAR_GOLD ) < w.takegold ) + { + char buf2[512]; + + sprintf( buf2, "\nܱǸรѧѲ㣡\nѧϰ˳мҪ%dʯ", w.takegold); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( buf2, buf, sizeof(buf))); + return; + } + CHAR_DelGold( talkerindex, w.takegold ); + + CHAR_setInt( talkerindex, CHAR_LEARNRIDE, 80 ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_LEARNRIDE ); + + //sprintf( buf, "R|L|1" ); + //lssproto_FM_send( fd, buf ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nϲ㣡Ѿмˡ\n Lv80 µij\nСร", + buf, sizeof(buf))); + + // + { + int fmindex, fmindexi, village, i; + char fmname[256], token[256], buf2[64]; + + sprintf( buf2, "%d", w.takegold/5 ); + for( i=0 ; i= 120 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѾѧ߼ѽ\nҪѧˡ", + buf, sizeof(buf))); + return; + } + else if( CHAR_getInt( talkerindex, CHAR_LEARNRIDE ) < 80 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѧм߼ࡡ", + buf, sizeof(buf))); + return; + } + + if( CHAR_getInt( talkerindex, CHAR_GOLD ) < w.takegold ) + { + char buf2[512]; + + sprintf( buf2, "\nܱǸรѧѲ㣡\nѧϰ˳߼Ҫ%dʯ", w.takegold); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( buf2, buf, sizeof(buf))); + return; + } + CHAR_DelGold( talkerindex, w.takegold ); + + CHAR_setInt( talkerindex, CHAR_LEARNRIDE, 120 ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_LEARNRIDE ); + + //sprintf( buf, "R|L|1" ); + //lssproto_FM_send( fd, buf ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nϲ㣡Ѿ˸߼ˡ\n Lv120 µij\nСร", + buf, sizeof(buf))); + + // + { + int fmindex, fmindexi, village, i; + char fmname[256], token[256], buf2[64]; + + sprintf( buf2, "%d", w.takegold/5 ); + for( i=0 ; i 200 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѾѧؼѽ\nҪѧˡ", + buf, sizeof(buf))); + return; + } + else if( CHAR_getInt( talkerindex, CHAR_LEARNRIDE ) < 120 ) + { + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nѧ߼ؼࡡ", + buf, sizeof(buf))); + return; + } + + if( CHAR_getInt( talkerindex, CHAR_GOLD ) < w.takegold ) + { + char buf2[512]; + + sprintf( buf2, "\nܱǸรѧѲ㣡\nѧϰ˳ؼҪ%dʯ", w.takegold); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( buf2, buf, sizeof(buf))); + return; + } + CHAR_DelGold( talkerindex, w.takegold ); + + CHAR_setInt( talkerindex, CHAR_LEARNRIDE, 200 ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD ); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_LEARNRIDE ); + + //sprintf( buf, "R|L|1" ); + //lssproto_FM_send( fd, buf ); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, -1, -1, + makeEscapeString( "\n\nϲ㣡Ѿؼˡ\nеȼij\nСร", + buf, sizeof(buf))); + + // + { + int fmindex, fmindexi, village, i; + char fmname[256], token[256], buf2[64]; + + sprintf( buf2, "%d", w.takegold/5 ); + for( i=0 ; i +#include +#include +#include +#include + +#include "object.h" +#include "char.h" +#include "char_base.h" +#include "char_data.h" +#include "net.h" +#include "npcutil.h" +#include "handletime.h" +#include "readmap.h" +#include "npc_roomadminnew.h" +#include "npc_door.h" + + +/* + * + */ + + +enum{ + CHAR_WORKINT_RANGE = CHAR_NPCWORKINT1, + /* ݼ */ + CHAR_WORKINT_NEXTTIME = CHAR_NPCWORKINT2, + CHAR_WORKINT_PRINTCLOSETIME = CHAR_NPCWORKINT3, + CHAR_WORKINT_SEARCHROOMTIME = CHAR_NPCWORKINT4, + +}; +enum { + CHAR_WORKCHAR_MYNAME = CHAR_NPCWORKCHAR1, + CHAR_WORKCHAR_NEXTROOM = CHAR_NPCWORKCHAR2, + +}; + +enum { + CHAR_WORKCHAR_ADMNAME = CHAR_NPCWORKCHAR1, +}; + + +#define NPC_ROOMADMINNEW_DATADIR "roomadmin/" +/* ̻P */ +#define NPC_ROOMADMINNEW_EXTENSION ".room" +#define NPC_ROOMADMINNEW_RANKING_EXTENSION ".score" +#define NPC_ROOMADMINNEW_RANKING_EXTENSION_TMP ".score.tmp" +#define NPC_ROOMADMINNEW_SCOREFILE ".score" +#define NPC_ROOMADMINNEW_PRINTCLOSETIME_DEFAULT 5 + +#define NPC_ROOMADMINNEW_MSG_CLOSE_BEFORE \ +"%s %s %sĻֹ%dǰ" +#define NPC_ROOMADMINNEW_MSG_CLOSE \ +"ѽֹ" +#define NPC_ROOMADMINNEW_MSG_NONE \ +"ܿϧû˻÷ӵȨ" +#define NPC_ROOMADMINNEW_MSG_CONGRATULATION \ +"ϲ%s÷Ȩ%sĽǮȫˡ%sԱѯʷ䰵š" +#define NPC_ROOMADMINNEW_MSG_PRINTPASSWD_NONE \ +"δзûаš" +#define NPC_ROOMADMINNEW_MSG_DSPPASSWD1 \ +"ķ %s %s %s" +#define NPC_ROOMADMINNEW_MSG_DSPPASSWD2 \ +"İ %s ֻҪڶ˵ʱβϡ...˾Ϳࡣ" +#define NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION_NONE \ +"յĻ" +#define NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION1 \ +"ķ %s %s %s" +#define NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION2 \ +"ֹ %d:%d ֹΪֹ%2dСʱ%02d֡" +#define NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION3 \ +"͵ñ %s " + +#define NPC_ROOMADMINNEW_MSG_RANKING_INFO \ +"Ǹ߶ñа" +#define NPC_ROOMADMINNEW_MSG_RANKING \ +"Rank %2d:%4d/%02d/%02d %8d GOLD %s%s " + +/* NPC */ +#define NPC_ROOMADMINNEW_MSGCOLOR CHAR_COLORWHITE +#define NPC_RANKING_MSGCOLOR CHAR_COLORWHITE +#define NPC_ROOMADMINNEW_2WEEK 60*60*24*14 + +static void NPC_RoomAdminNew_DspNextAuction( int meindex, int talkerindex); +static void NPC_RoomAdminNew_DspRoomPasswd( int meindex, int adminindex, int talkerindex); +static BOOL NPC_RoomAdminNew_SetNextAuction( int meindex); +static BOOL NPC_RoomAdminNew_WriteDataFile( int meindex, int pindex, char *roomname, + char *passwd, BOOL flg); +static void NPC_RoomAdminNew_CreatePasswd( char *passwd, int passlen); +static void NPC_RoomAdminNew_SendMsgThisFloor( int index, char *buff); +static int NPC_RoomAdminNew_SearchPlayerHasMostMoney( int meindex); +static void NPC_RoomAdminNew_CloseProc( int meindex); +static int NPC_RoomAdminNew_WriteScoreFile( int meindex, int pindex); +static void NPC_RoomAdminNew_ReadScoreFile( int meindex, int talkerindex, + char *admname); + +/************************************************ + ************************************************/ +BOOL NPC_RoomAdminNewInit( int meindex ) +{ + int i; + char buf[256]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + for( i = 3; ; i ++ ) { + if( getStringFromIndexWithDelim(argstr, "|" , i , buf,sizeof(buf) )) { + if( NPC_DoorSearchByName( buf) < 0 ) { + print( "admin not created.֮ǰȵȴ\n"); + return FALSE; + } + } + else{ + break; + } + } + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + + /* type */ + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEROOMADMIN); + getStringFromIndexWithDelim(argstr, "|" , 1 , buf,sizeof(buf) ); + CHAR_setWorkInt( meindex , CHAR_WORKINT_RANGE , atoi( buf )); + if( !getStringFromIndexWithDelim(argstr, "|" , 2 , buf,sizeof(buf) )) { + print( "arg err.admin not created.\n"); + return( FALSE); + } + CHAR_setWorkChar( meindex , CHAR_WORKCHAR_MYNAME , buf); + + CHAR_setWorkInt( meindex, CHAR_WORKINT_PRINTCLOSETIME, 0); + + NPC_RoomAdminNew_SetNextAuction( meindex); + + return TRUE; +} +/************************************************ + ************************************************/ +void NPC_RoomAdminNewLoop( int meindex ) +{ + int hun; + if( CHAR_getWorkInt( meindex, CHAR_WORKINT_NEXTTIME) == 0 ) { + struct tm tm1,tm2; + time_t t; + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + t = CHAR_getWorkInt( meindex, CHAR_WORKINT_SEARCHROOMTIME); + memcpy( &tm2, localtime( &t), + sizeof( tm2)); + if( tm1.tm_year != tm2.tm_year || + tm1.tm_mday != tm2.tm_mday || + tm1.tm_mon != tm2.tm_mon ) + { + NPC_RoomAdminNew_SetNextAuction( meindex); + } + return; + } + + hun = ceil((double)(CHAR_getWorkInt( meindex, CHAR_WORKINT_NEXTTIME) - + NowTime.tv_sec) / 60.0); + if( hun < 0 ) hun = 0; + + if( hun < NPC_ROOMADMINNEW_PRINTCLOSETIME_DEFAULT ) { + if( hun != CHAR_getWorkInt( meindex, CHAR_WORKINT_PRINTCLOSETIME)) { + char buff[256]; + if( hun != 0 ) { + char buf2[1024]; + char msgbuff[16]; + char argstr2[NPC_UTIL_GETARGSTR_BUFSIZE]; + int doorindex; + + doorindex = NPC_DoorSearchByName( CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM)); + NPC_Util_GetArgStr( doorindex, argstr2, sizeof( argstr2)); + getStringFromIndexWithDelim( argstr2, "|" , 9 , + buf2,sizeof(buf2) ); + if( strlen(CHAR_getChar( doorindex, CHAR_NAME) ) != 0 ) { + strcpy( msgbuff, ""); + } + else { + msgbuff[0] = '\0'; + } + snprintf( buff, sizeof(buff), + NPC_ROOMADMINNEW_MSG_CLOSE_BEFORE, + buf2, + CHAR_getChar( doorindex, CHAR_NAME), + msgbuff, + hun); + + CHAR_setWorkInt( meindex, CHAR_WORKINT_PRINTCLOSETIME, hun); + } + else { + /* 󻻧Իף */ + strcpy( buff, NPC_ROOMADMINNEW_MSG_CLOSE); + CHAR_setWorkInt( meindex, CHAR_WORKINT_PRINTCLOSETIME, 0); + } + /* 𼰰׷ʧ幻˪ */ + NPC_RoomAdminNew_SendMsgThisFloor( meindex, buff); + } + } + if( hun == 0 ) { + NPC_RoomAdminNew_CloseProc( meindex); + } +} + +/************************************************ + ************************************************/ +void NPC_RoomAdminNewTalked( int meindex , int talkerindex , char *msg , + int color ) +{ + + if(NPC_Util_CharDistance( talkerindex, meindex ) > 1)return; + + /*NPC_RoomAdminNew_DspRoomPasswd( meindex, talkerindex);*/ + + NPC_RoomAdminNew_DspNextAuction( meindex, talkerindex); +} +/*----------------------------------------------- + *----------------------------------------------*/ +static void NPC_RoomAdminNew_CloseProc( int meindex) +{ + int pindex; + char buff[256]; + char pname[32]; + int failed = TRUE; + + pindex = NPC_RoomAdminNew_SearchPlayerHasMostMoney( meindex); + /* 񲷮ʧ */ + if( pindex != -1) { + while( 1) { + char passwd[9]; + int doorindex; + doorindex = NPC_DoorSearchByName( + CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM)); + /* ɵëϷ */ + NPC_RoomAdminNew_CreatePasswd( passwd, sizeof( passwd)); + if( NPC_RoomAdminNew_WriteDataFile( meindex, pindex, + CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM), + passwd, 1) + == FALSE) + { + break; + } + /* ʧɵë */ + if( NPC_DoorSetPasswd( doorindex, passwd) == -1 ) { + break; + } + CHAR_setWorkInt( doorindex, CHAR_WORKDOOREXPIRETIME, + CHAR_getWorkInt( meindex, CHAR_WORKINT_NEXTTIME) + + NPC_ROOMADMINNEW_2WEEK); + NPC_RoomAdminNew_WriteScoreFile( meindex, pindex); + + CHAR_setInt( pindex, CHAR_GOLD, 0); + + CHAR_send_P_StatusString( pindex , CHAR_P_STRING_GOLD); + + strcpy( pname, CHAR_getChar( pindex, CHAR_NAME)); + snprintf( buff, sizeof(buff), + NPC_ROOMADMINNEW_MSG_CONGRATULATION, pname, pname, pname); + failed = FALSE; + break; + } + } + + if( failed) { + NPC_RoomAdminNew_WriteDataFile( meindex, -1, CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM), NULL, 0); + /* 񲷮϶ */ + snprintf( buff, sizeof(buff), + NPC_ROOMADMINNEW_MSG_NONE); + } + /* 𼰰׷ʧ幻˪ */ + NPC_RoomAdminNew_SendMsgThisFloor( meindex, buff); + + NPC_RoomAdminNew_SetNextAuction( meindex); + +} +/*----------------------------------------------- + *----------------------------------------------*/ +static int NPC_RoomAdminNew_SearchPlayerHasMostMoney( int meindex) +{ + int i,j, range; + int fl,x,y, gold; + int doorindex; + int topindex; + + fl = CHAR_getInt( meindex, CHAR_FLOOR); + x = CHAR_getInt( meindex, CHAR_X); + y = CHAR_getInt( meindex, CHAR_Y); + range = CHAR_getWorkInt( meindex , CHAR_WORKINT_RANGE); + topindex = -1; + + doorindex = NPC_DoorSearchByName( CHAR_getWorkChar( meindex, + CHAR_WORKCHAR_NEXTROOM)); + gold = atoi( CHAR_getWorkChar( doorindex, CHAR_WORKDOORGOLDLIMIT)); + for( i = x-range ; i <= x+range ; i++ ){ + for( j = y-range ; j <= y+range ; j ++ ){ + OBJECT object; + for( object = MAP_getTopObj( fl, i,j); object; + object = NEXT_OBJECT(object) ) + { + int objindex = GET_OBJINDEX( object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + int index; + index = OBJECT_getIndex(objindex); + if( CHAR_getInt( index, + CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) + { + if( CHAR_getInt( index, CHAR_GOLD) >= gold ) { + if( topindex == -1 ) { + topindex = index; + } + else { + int nowgold,topgold; + nowgold = CHAR_getInt( index, CHAR_GOLD ); + topgold = CHAR_getInt( topindex, CHAR_GOLD); + if( nowgold > topgold ) { + topindex = index; + } + else if( nowgold == topgold ) { + /* ئìﻥ */ + int nowlv, toplv; + nowlv = CHAR_getInt( index, CHAR_LV ); + toplv = CHAR_getInt( topindex, CHAR_LV); + if( nowlv < toplv ) { + topindex = index; + } + /* ľƥݩئئշ¼ĸةԪ*/ + /* indexƼлнǷ */ + else if( nowlv == toplv ) { + if( RAND( 0,1)) { + topindex = index; + } + } + } + } + } + } + } + } + } + } + return( topindex); +} +/*----------------------------------------------- + * ϶ýľindex׷ʧ幻 + *----------------------------------------------*/ +static void NPC_RoomAdminNew_SendMsgThisFloor( int index, char *buff) +{ + int i, fl; + int playernum = CHAR_getPlayerMaxNum(); + + fl = CHAR_getInt( index, CHAR_FLOOR); + for( i = 0; i < playernum; i ++ ) { + if( CHAR_getInt( i, CHAR_FLOOR) == fl ) { + if( CHAR_getInt( i, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) { + CHAR_talkToCli( i, index, buff, NPC_ROOMADMINNEW_MSGCOLOR); + } + } + } +} +/*----------------------------------------------- + *----------------------------------------------*/ +static void NPC_RoomAdminNew_CreatePasswd( char *passwd, int passlen) +{ +#define NPC_ROOMADMINNEW_RAND() ( (rand() /256) % 32768 ) /* 256ƥ¼Ѽ ߤ׻ */ + int i; + char *candidates[]= { + "A","B","D", "E","F","G","H", "J","K","L","M", "N","P","Q","R", + "T","W","X","Y", "a","b","d","e", "f","g","m","n", "q","r","t", + "0","1","2", "3","4","5","6", "7","8","9" + }; + strcpy( passwd , ""); + for(i = 0;i < passlen -1 ; i++){ + strcat( passwd , candidates[ NPC_ROOMADMINNEW_RAND() % (sizeof( candidates)/sizeof(candidates[0])) ] ); + } +#undef NPC_ROOMADMINNEW_RAND +} +/*----------------------------------------------- + * + * + * cdkey|charaname|passwd|expiretime + * + * + *----------------------------------------------*/ +static BOOL NPC_RoomAdminNew_WriteDataFile( int meindex, int pindex, + char *roomname, + char *passwd, int flg) +{ + char *cdkey; + char charaname[32*2]; + char expiretime[64]; + char filename[128]; + char outbuf[1024]; + FILE *fp_src; + + strcpy( filename, NPC_ROOMADMINNEW_DATADIR); + /*strcat( filename, CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM));*/ + strcat( filename, roomname); + strcat( filename, NPC_ROOMADMINNEW_EXTENSION); + + if( flg) { + //getcdkeyFromCharaIndex( pindex, cdkey, sizeof(cdkey )); + cdkey = CHAR_getChar( pindex, CHAR_CDKEY); + makeEscapeString( CHAR_getChar( pindex, CHAR_NAME), + charaname, sizeof( charaname)); + /* ľ */ + snprintf( expiretime, sizeof( expiretime), "%d", + CHAR_getWorkInt( meindex, CHAR_WORKINT_NEXTTIME) + + NPC_ROOMADMINNEW_2WEEK /* ԉ */ + ); + + /* ƥ */ + snprintf( outbuf, sizeof( outbuf), "%s|%s|%s|%s|", + cdkey, charaname, passwd, expiretime); + fp_src = fopen( filename, "w"); + if( !fp_src) { + print( "[%s:%d] File Open Error\n", __FILE__, __LINE__); + return FALSE; + } + fputs( outbuf, fp_src); + fclose( fp_src); + } + else { + unlink( filename); + } + + return TRUE; + +} +/*----------------------------------------------- + *----------------------------------------------*/ +BOOL NPC_RoomAdminNew_ReadFile( char *roomname, NPC_ROOMINFO *data) +{ + FILE *fp; + char line[1024]; + char buf2[128]; + char filename[128]; + + strcpy( filename, NPC_ROOMADMINNEW_DATADIR); + strcat( filename, roomname); + strcat( filename, NPC_ROOMADMINNEW_EXTENSION); + + fp = fopen( filename, "r"); + if( !fp) return FALSE; + fgets( line, sizeof( line), fp); + /* */ + getStringFromIndexWithDelim( line, "|" , 1 , buf2,sizeof(buf2) ); + strcpy( data->cdkey, buf2); + getStringFromIndexWithDelim( line, "|" , 2 , buf2,sizeof(buf2) ); + strcpy( data->charaname, makeStringFromEscaped( buf2)); + getStringFromIndexWithDelim( line, "|" , 3 , buf2,sizeof(buf2) ); + strcpy( data->passwd, buf2); + getStringFromIndexWithDelim( line, "|" , 4 , buf2,sizeof(buf2) ); + if( strcmp( buf2, "max") == 0 ) { + data->expire = 0xffffffff; + } + else { + data->expire = atoi( buf2); + } + fclose( fp); + return TRUE; +} +/*----------------------------------------------- + *----------------------------------------------*/ +static BOOL NPC_RoomAdminNew_SetNextAuction( int meindex) +{ + int i, j; + int hitindex = -1; + int charnum = CHAR_getCharNum(); + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + struct tm tmwk; + + memcpy( &tmwk, localtime( ( time_t *)&NowTime.tv_sec), sizeof( tmwk)); + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + */ + for( i = CHAR_getPlayerMaxNum()+ CHAR_getPetMaxNum(); + i < charnum; + i ++ ) + { + if( CHAR_getInt( i, CHAR_WHICHTYPE) != CHAR_TYPEDOOR) { + continue; + } + if( CHAR_getWorkInt( i, CHAR_WORKDOORPASSFLG) == 0 ) { + continue; + } + for( j = 3; ; j ++ ) { + int rc; + char *doorname; + char buf[256]; + int dataexist; + NPC_ROOMINFO data; + + rc = getStringFromIndexWithDelim( argstr, "|" , j, + buf,sizeof(buf) ); + if( rc != TRUE ) { + break; + } + doorname = CHAR_getWorkChar( i, CHAR_WORKDOORNAME); + if( strcmp( buf, doorname ) != 0 ) { + continue; + } + if( atoi( CHAR_getWorkChar( i, CHAR_WORKDOORWEEK)) != tmwk.tm_wday) { + break; + } + /* ɱ */ + memset( &data, 0, sizeof( data)); + if( NPC_RoomAdminNew_ReadFile( doorname, &data) ) { + struct tm tmdoor; + * ׻ľհ̻ë + */ + if( data.expire < NowTime.tv_sec) { + NPC_RoomAdminNew_WriteDataFile( meindex, -1,doorname, NULL, 0); + /* ʧľб*/ + NPC_DoorSetPasswd( i, "8hda8iauia90494jasd9asodfasdf89"); + CHAR_setWorkInt( i, CHAR_WORKDOOREXPIRETIME, 0xffffffff); + + break; + } + memcpy( &tmdoor, localtime( ( time_t *)&data.expire), sizeof( tmdoor)); + if( tmdoor.tm_mon != tmwk.tm_mon || + tmdoor.tm_mday != tmwk.tm_mday) + { + break; + } + dataexist = TRUE; + } + else { + dataexist = FALSE; + } + if( tmwk.tm_hour > atoi( CHAR_getWorkChar( i, CHAR_WORKDOORHOUR))){ + break; + } + if( tmwk.tm_hour == atoi( CHAR_getWorkChar( i, CHAR_WORKDOORHOUR))) { + if( tmwk.tm_min >= atoi( CHAR_getWorkChar( i, CHAR_WORKDOORMINUTE))) { + break; + } + } + /* ƥԻؤڳʧݷ·ɡ + */ + if( hitindex == -1 ) { + hitindex = i; + } + else { + if( atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORHOUR)) + > atoi( CHAR_getWorkChar( i, CHAR_WORKDOORHOUR))) + { + hitindex = i; + } + else if( atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORHOUR)) + == atoi( CHAR_getWorkChar( i, CHAR_WORKDOORHOUR))) + { + if( atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORMINUTE)) + > atoi( CHAR_getWorkChar( i, CHAR_WORKDOORMINUTE))) + { + hitindex = i; + } + else if( atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORMINUTE)) + == atoi( CHAR_getWorkChar( i, CHAR_WORKDOORMINUTE))) + { + NPC_ROOMINFO datawk; + int hitindexdataexist; + hitindexdataexist = NPC_RoomAdminNew_ReadFile( + CHAR_getWorkChar( hitindex, CHAR_WORKDOORNAME), + &datawk); + if( hitindexdataexist < dataexist ) { + hitindex = i; + } + + } + } + } + } + } + if( hitindex > 0 ) { + /* ë */ + tmwk.tm_sec = 0; + tmwk.tm_min = atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORMINUTE)); + tmwk.tm_hour = atoi( CHAR_getWorkChar( hitindex, CHAR_WORKDOORHOUR)); + CHAR_setWorkInt( meindex, CHAR_WORKINT_NEXTTIME, mktime( &tmwk)); + CHAR_setWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM, + CHAR_getWorkChar( hitindex, CHAR_WORKDOORNAME)); + + } + else { + CHAR_setWorkInt( meindex, CHAR_WORKINT_NEXTTIME, 0); + CHAR_setWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM,"" ); + + } + /* ë */ + CHAR_setWorkInt( meindex, CHAR_WORKINT_SEARCHROOMTIME, NowTime.tv_sec); + return( TRUE); +} +/*----------------------------------------------- + *----------------------------------------------*/ +static void NPC_RoomAdminNew_DspRoomPasswd( int index, int adminindex, int talkerindex) +{ + int i, rc, flg = FALSE; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char argstr2[NPC_UTIL_GETARGSTR_BUFSIZE]; + char *cdkey; + char buf[128]; + char buff[16]; + char buf2[1024]; + + NPC_ROOMINFO info; + + //getcdkeyFromCharaIndex( talkerindex, cdkey, sizeof(cdkey)); + cdkey = CHAR_getChar( talkerindex, CHAR_CDKEY); + + NPC_Util_GetArgStr( adminindex, argstr, sizeof( argstr)); + for( i = 3; ; i ++ ) { + if( getStringFromIndexWithDelim(argstr, "|" , i , buf,sizeof(buf) )) { + rc = NPC_RoomAdminNew_ReadFile( buf, &info); + if( rc == TRUE ) { + if( strcmp( info.cdkey, cdkey) == 0 && + strcmp( info.charaname, + CHAR_getChar( talkerindex, CHAR_NAME)) == 0 ) + { + int doorindex; + char msgbuf[256]; + doorindex = NPC_DoorSearchByName( buf); + NPC_Util_GetArgStr( doorindex, argstr2, sizeof( argstr2)); + getStringFromIndexWithDelim( argstr2, "|" , 9 , + buf2,sizeof(buf2) ); + if( strlen(CHAR_getChar( doorindex, CHAR_NAME) ) != 0 ) { + strcpy( buff, ""); + } + else { + buff[0] = '\0'; + } + + /* Ȿ */ + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPPASSWD1, + buf2, + CHAR_getChar( doorindex, CHAR_NAME), + buff + ); + /* ˪ */ + CHAR_talkToCli( talkerindex, index,msgbuf, + NPC_ROOMADMINNEW_MSGCOLOR); + + /* Ȿ */ + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPPASSWD2, + CHAR_getWorkChar(doorindex, CHAR_WORKDOORPASSWD) + ); + /* ˪ */ + CHAR_talkToCli( talkerindex, index,msgbuf, + NPC_ROOMADMINNEW_MSGCOLOR); + flg = TRUE; + } + } + } + else { + break; + } + } + if( !flg) { + CHAR_talkToCli( talkerindex, index, + NPC_ROOMADMINNEW_MSG_PRINTPASSWD_NONE, + NPC_ROOMADMINNEW_MSGCOLOR); + } +} +/*----------------------------------------------- + *----------------------------------------------*/ +static void NPC_RoomAdminNew_DspNextAuction( int meindex, int talkerindex) +{ + char msgbuf[2048]; + time_t closetime; + + closetime = CHAR_getWorkInt( meindex, CHAR_WORKINT_NEXTTIME); + if( closetime == 0 ) { + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION_NONE + ); + CHAR_talkToCli( talkerindex, meindex,msgbuf, NPC_ROOMADMINNEW_MSGCOLOR); + } + else { + int doorindex; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff[16]; + struct tm tmwk; + int difftime; + doorindex = NPC_DoorSearchByName( + CHAR_getWorkChar( meindex, CHAR_WORKCHAR_NEXTROOM)); + NPC_Util_GetArgStr( doorindex, argstr, sizeof( argstr)); + getStringFromIndexWithDelim(argstr, "|" , 9 , explain,sizeof(explain)); + if( strlen(CHAR_getChar( doorindex, CHAR_NAME) ) != 0 ) { + strcpy( buff, ""); + } + else { + buff[0] = '\0'; + } + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION1, + explain, + CHAR_getChar( doorindex, CHAR_NAME), + buff + ); + CHAR_talkToCli( talkerindex, meindex,msgbuf, NPC_ROOMADMINNEW_MSGCOLOR); + /* 󻻧Ի */ + memcpy( &tmwk, localtime( &closetime), sizeof( tmwk)); + difftime = closetime - NowTime.tv_sec; + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION2, + tmwk.tm_hour, + tmwk.tm_min, + difftime / 3600, + (difftime % 3600) / 60 + ); + CHAR_talkToCli( talkerindex, meindex,msgbuf, NPC_ROOMADMINNEW_MSGCOLOR); + + /* Ʊź */ + snprintf( msgbuf, sizeof( msgbuf), + NPC_ROOMADMINNEW_MSG_DSPNEXTAUCTION3, + CHAR_getWorkChar( doorindex, CHAR_WORKDOORGOLDLIMIT) + ); + CHAR_talkToCli( talkerindex, meindex,msgbuf, NPC_ROOMADMINNEW_MSGCOLOR); + } + +} +/*----------------------------------------------- + * + * + * gold|time|cdkey|charaname|owntitle + * + *----------------------------------------------*/ +static int NPC_RoomAdminNew_WriteScoreFile( int meindex, int pindex) +{ +#define NPC_RANKING_DEFAULT 10 + int ret = 0; + char *cdkey; + char charaname[32*2],owntitle[32*2]; + char filename_dest[128],filename[128]; + char outbuf[1024], line[1024]; + FILE *fp_src, *fp_dest; + + strcpy( filename, NPC_ROOMADMINNEW_DATADIR); + strcat( filename, CHAR_getWorkChar( meindex, CHAR_WORKCHAR_MYNAME)); + strcpy( filename_dest, filename); + strcat( filename, NPC_ROOMADMINNEW_RANKING_EXTENSION); + strcat( filename_dest, NPC_ROOMADMINNEW_RANKING_EXTENSION_TMP); + + //getcdkeyFromCharaIndex( pindex , cdkey , sizeof(cdkey )); + cdkey = CHAR_getChar( pindex, CHAR_CDKEY); + + makeEscapeString( CHAR_getChar( pindex, CHAR_NAME), + charaname, sizeof( charaname)); + + makeEscapeString( CHAR_getChar( pindex, CHAR_OWNTITLE), + owntitle, sizeof( owntitle)); + + /* ƥ */ + snprintf( outbuf, sizeof( outbuf), "%d|%d|%s|%s|%s|\n", + CHAR_getInt( pindex, CHAR_GOLD), + CHAR_getWorkInt( meindex,CHAR_WORKINT_NEXTTIME), + cdkey, charaname, owntitle ); + + + fp_dest = fopen( filename_dest, "w"); + if( !fp_dest) return -1; + + fp_src = fopen( filename, "r"); + if( !fp_src ) { + fclose( fp_dest); + fp_src = fopen( filename, "w"); + if( !fp_src) return -1; + fputs( outbuf, fp_src); + fclose( fp_src); + return 1; + } + else { + int cnt = 1; + char buf[128]; + while( fgets( line, sizeof( line), fp_src)) { + getStringFromIndexWithDelim( line, "|" , 1 , buf,sizeof(buf) ); + if( ret == 0 ) { + if( atoi( buf) < CHAR_getInt( pindex, CHAR_GOLD) ) { + fputs( outbuf, fp_dest); + fputs( line, fp_dest); + ret = cnt; + cnt ++; + } + else { + /* ľ½̤ */ + fputs( line, fp_dest); + } + } + else { + /* ľ½̤ */ + fputs( line, fp_dest); + } + cnt ++; + if( cnt > NPC_RANKING_DEFAULT ) break; + } + /* ¼ƽ뻥۹ǷȻئ */ + if( ret == 0 && cnt <= NPC_RANKING_DEFAULT ) { + fputs( outbuf, fp_dest); + ret = cnt; + } + } + fclose( fp_src); + fclose( fp_dest); + fp_src = fopen( filename_dest, "r"); + if( !fp_src) return -1; + fp_dest = fopen( filename, "w"); + if( !fp_dest) { + fclose( fp_src); + return -1; + } + while( fgets( line, sizeof( line), fp_src)) { + fputs( line, fp_dest); + } + fclose( fp_dest); + fclose( fp_src); + return( ret); +#undef NPC_RANKING_DEFAULT +} +/*----------------------------------------------- + * + * + *----------------------------------------------*/ +static void NPC_RoomAdminNew_ReadScoreFile( int meindex, int talkerindex, + char *admname) +{ + int cnt; + char filename[128]; + char line[1024]; + FILE *fp; + + strcpy( filename, NPC_ROOMADMINNEW_DATADIR); + strcat( filename, admname); + strcat( filename, NPC_ROOMADMINNEW_RANKING_EXTENSION); + + fp = fopen( filename, "r"); + if( !fp) return; + cnt = 1; + while( fgets( line, sizeof( line), fp)) { + int gold; + time_t bidtime; + char charaname[32],owntitle[32]; + char tmp[64]; + char outbuf[1024], buf[256]; + + getStringFromIndexWithDelim( line, "|" , 1 , buf,sizeof(buf) ); + gold = atoi(buf); + getStringFromIndexWithDelim( line, "|" , 2 , buf,sizeof(buf) ); + bidtime = (time_t)atoi(buf); + getStringFromIndexWithDelim( line, "|" , 4 , buf,sizeof(buf) ); + strcpy( charaname, makeStringFromEscaped( buf)); + getStringFromIndexWithDelim( line, "|" , 5 , buf,sizeof(buf) ); + strcpy( owntitle, makeStringFromEscaped( buf)); + if( strlen( owntitle) != 0 ) { + strcpy( tmp, "["); + strcat( tmp, owntitle); + strcat( tmp, "] "); + strcpy( owntitle, tmp); + } + else { + strcpy( owntitle, " "); + } + + struct tm *tmwk = localtime(&bidtime); + + snprintf( outbuf, sizeof( outbuf), + NPC_ROOMADMINNEW_MSG_RANKING, + cnt, + tmwk->tm_year + 1900, + tmwk->tm_mon+1, + tmwk->tm_mday, + gold,charaname,owntitle + ); + CHAR_talkToCli( talkerindex, meindex,outbuf, + NPC_RANKING_MSGCOLOR); + cnt ++; + } + fclose( fp); + +} +/************************************************ + ************************************************/ +BOOL NPC_RankingInit( int meindex ) +{ + char buf[256]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + + /* type */ + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPERANKING); + if( !getStringFromIndexWithDelim(argstr, "|" , 1 , buf,sizeof(buf) )) { + print( "arg err.rankingNPC not created.\n"); + return( FALSE); + } + CHAR_setWorkChar( meindex , CHAR_WORKCHAR_ADMNAME , buf); + + return TRUE; +} +/************************************************ + ************************************************/ +void NPC_RankingTalked( int meindex , int talkerindex , char *msg , + int color ) +{ + if(NPC_Util_CharDistance( talkerindex, meindex ) > 1)return; + + CHAR_talkToCli( talkerindex, meindex, + NPC_ROOMADMINNEW_MSG_RANKING_INFO, + NPC_RANKING_MSGCOLOR); + + NPC_RoomAdminNew_ReadScoreFile( meindex, talkerindex, + CHAR_getWorkChar( meindex, CHAR_WORKCHAR_ADMNAME)); + +} +/************************************************ + ************************************************/ +BOOL NPC_PrintpassmanInit( int meindex ) +{ + char buf[256]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + + /* type */ + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEPRINTPASSMAN); + if( !getStringFromIndexWithDelim(argstr, "|" , 1 , buf,sizeof(buf) )) { + print( "arg err.passmanNPC not created.\n"); + return( FALSE); + } + CHAR_setWorkChar( meindex , CHAR_WORKCHAR_ADMNAME , buf); + + return TRUE; +} +/************************************************ + ************************************************/ +void NPC_PrintpassmanTalked( int meindex , int talkerindex , char *msg , + int color ) +{ + int i; + int charnum; + if(NPC_Util_CharDistance( talkerindex, meindex ) > 2)return; + + charnum = CHAR_getCharNum(); + for(i= CHAR_getPlayerMaxNum() +CHAR_getPetMaxNum(); + i +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "npc_oldman.h" +#include "title.h" +#include "char_data.h" +#include "readmap.h" +#include "lssproto_serv.h" +#include "log.h" +#include "configfile.h" +#define RANGE 2 +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif + +void NPC_SetFlg(int talker,int shiftbit); +BOOL NPC_CheckFlg(int point,int shiftbit); +BOOL NPC_SavePointItemCheck(int meindex,int talker,int itemno,int kosuu); +void NPC_MessageDisp(int meindex,int talker,int MseNo); +BOOL NPC_UsedCheck(int meindex,int talker,int flg); +BOOL NPC_SavePointItemDelete(int meindex,int talker,int itemNo,int kosuu); + +extern time_t initTime; + +#ifdef _OFFLINE_SYSTEM +int playeronlinenum=0; +extern int luaplayernum; +#endif + +BOOL NPC_SavePointInit( int meindex ) +{ + int oldmanid=0, bornfl=0, bornx=0 ,borny=0; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[32]; + char buf2[512]; + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_Savepoint.c Init: GetArgStrErr"); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim(argstr,"ID",buf2,sizeof( buf2) )==NULL){ + print("SavePoint:IDδ趨 "); + return FALSE; + } + + oldmanid=atoi(buf2); + NPC_Util_GetStrFromStrWithDelim(argstr,"Born",buf2,sizeof( buf2) ); + getStringFromIndexWithDelim( buf2,",",1,token,sizeof(token)); + bornfl = atoi( token ); + getStringFromIndexWithDelim( buf2,",",2,token,sizeof(token)); + bornx = atoi( token ); + getStringFromIndexWithDelim( buf2,",",3,token,sizeof(token)); + borny = atoi( token ); + + CHAR_setWorkInt( meindex , CHAR_WORKOLDMANID ,oldmanid ); + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPESAVEPOINT ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 1 ); + + if( MAP_IsValidCoordinate( bornfl,bornx,borny )== TRUE + && CHAR_ElderSetPosition( oldmanid ,bornfl,bornx, borny ) == TRUE ){ + return TRUE; + }else{ + printf( "Invalid elder npcarg=%s\n", argstr ); + return FALSE; + } +} + +void NPC_SavePointTalked( int meindex , int talkerindex , char *msg , + int color ) +{ + int fd; + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[512]; + char buf2[1024]; + char timeMsg[1024]; + int oldmanid; + + if( ! NPC_Util_charIsInFrontOfChar(talkerindex,meindex,RANGE) + || CHAR_getFlg( talkerindex,CHAR_ISDIE )){ + if( (CHAR_getInt(talkerindex,CHAR_X) == CHAR_getInt(meindex,CHAR_X)) + && (CHAR_getInt(talkerindex,CHAR_Y) == CHAR_getInt(meindex,CHAR_Y)) + && (CHAR_getInt(talkerindex,CHAR_FLOOR) ==CHAR_getInt(meindex,CHAR_FLOOR)) ){ + }else{ + return; + } + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_Savepoint.c TypeCheck: GetArgStrErr\n"); + return ; + } + + if(NPC_Util_GetStrFromStrWithDelim(argstr,"ID",buf2,sizeof( buf2) )==NULL) return ; + oldmanid=atoi(buf2); + + if(strstr(argstr,"NOITEM")!=NULL) { + NPC_SetFlg(talkerindex,oldmanid); + } +#ifndef _FREE_SAVE + if(NPC_CheckFlg(CHAR_getInt(talkerindex,CHAR_SAVEPOINT),oldmanid)==FALSE){ + + if(NPC_UsedCheck(meindex,talkerindex,0)==TRUE){ + NPC_MessageDisp(meindex,talkerindex,2); + }else{ + NPC_MessageDisp(meindex,talkerindex,0); + } + }else +#endif + { + CHAR_setInt( talkerindex, CHAR_LASTTALKELDER ,CHAR_getWorkInt( meindex, CHAR_WORKOLDMANID ) ); + fd = getfdFromCharaIndex( talkerindex); + + NPC_Util_GetStrFromStrWithDelim(argstr,"NomalMsg",token,sizeof( token) ); + sprintf(buf2,token,CHAR_getChar(talkerindex,CHAR_NAME)); + + // Robin 0619 display time + { + time_t new_t; + int dd,hh,mm,ss; + + time(&new_t); + new_t-=initTime; + + dd=(int) new_t / 86400; new_t=new_t % 86400; + hh=(int) new_t / 3600; new_t=new_t % 3600; + mm=(int) new_t / 60; new_t=new_t % 60; + ss=(int) new_t; +#ifdef _SAVE_GAME_ID + if (dd>0) { + snprintf( timeMsg, sizeof( timeMsg ) , + "%sѾ %d %d Сʱ %d %d 롣",getGameservername(),dd,hh,mm,ss); + } else if (hh>0) { + snprintf( timeMsg, sizeof( timeMsg ) , + "%sѾ %d Сʱ %d %d 롣",getGameservername(),hh,mm,ss); + } else { + snprintf( timeMsg, sizeof( timeMsg ) , + "%sѾ %d %d 롣",getGameservername(),mm,ss); + } + strcat(buf2,timeMsg); +#else + if (dd>0) { + snprintf( timeMsg, sizeof( timeMsg ) , + "Ѿ %d %d Сʱ %d %d 롣",dd,hh,mm,ss); + } else if (hh>0) { + snprintf( timeMsg, sizeof( timeMsg ) , + "Ѿ %d Сʱ %d %d 롣",hh,mm,ss); + } else { + snprintf( timeMsg, sizeof( timeMsg ) , + "Ѿ %d %d 롣",mm,ss); + } + strcat(buf2,timeMsg); +#endif + } + { + char temp[1024]; + //char *answer;// CoolFish: Rem 2001/4/18 + + // Robin 03/20 ܵ͸ҹˮ!!!! + +#ifdef _PLAYER_NUM + srand(time(0)); +#ifdef _OFFLINE_SYSTEM + if(getPlayerNum()>0){ + sprintf(temp,"ĿǰΪ %d ˡ", playeronlinenum + luaplayernum + getPlayerNum()); + }else{ + sprintf(temp,"ĿǰΪ %d ˡ", playeronlinenum + luaplayernum); + } +#else + extern unsigned int StateTable[]; + if(getPlayerNum()>0){ + sprintf(temp,"ĿǰΪ %d ˡ",abs(StateTable[LOGIN]) + getPlayerNum() + rand() % 10); + }else{ + sprintf(temp,"ĿǰΪ %d ˡ",abs(StateTable[LOGIN])); + } +#endif +#else + extern unsigned int StateTable[]; + sprintf(temp,"ĿǰΪ %d ˡ",abs(StateTable[LOGIN])); +#endif + + strcat(buf2,temp); +#ifdef _NPC_SAVEPOINT + if( fd != -1 ) { + if(CHAR_getFlg( talkerindex, CHAR_ISSAVE)==TRUE){ + Char *chwk; + chwk = CHAR_getCharPointer( talkerindex); + // CoolFish: +1 2001/11/05 + if (!chwk) return; + strcat(buf2,"ϵͳԶΪ浵"); + CHAR_charSaveFromConnectAndChar( fd, chwk ,FALSE ); + } + } +#endif + + } + CHAR_talkToCli( talkerindex , meindex , buf2 , rand() % CHAR_COLORNUM ); + + } + + + +} + + +/*----------------------------------------- + * +-------------------------------------------*/ +void NPC_SavePointWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + + if(seqno==CHAR_WINDOWTYPE_WINDOWSAVEPOINT_START){ + if(select==WINDOW_BUTTONTYPE_YES){ + if(NPC_UsedCheck(meindex,talkerindex,1)==TRUE){ + NPC_MessageDisp(meindex,talkerindex,1); + } + } + } + + +} + + +/* + */ +BOOL NPC_AndReduce(int meindex,int talker,char *buf,int flg) +{ + + char buf2[512]; + char buf3[256]; + int itemNo=0; + int kosuu; + int j=1; + + if(flg==0){ + + while(getStringFromIndexWithDelim(buf,"&",j,buf2,sizeof(buf2))!=FALSE) + { + j++; + if(strstr( buf2, "*") != NULL){ + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemNo = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + + /*--ƹ--*/ + if(NPC_SavePointItemCheck(meindex,talker,itemNo,kosuu)==FALSE){ + return FALSE; + } + + }else{ + itemNo = atoi(buf2); + + /*--ƹ--*/ + if(NPC_SavePointItemCheck(meindex,talker,itemNo,1)==FALSE){ + return FALSE; + } + + } + } + + }else{ + if(strstr( buf, "*") != NULL){ + getStringFromIndexWithDelim(buf,"*",1,buf3,sizeof(buf3)); + itemNo = atoi(buf3); + getStringFromIndexWithDelim(buf,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + /*--ƹ--*/ + if(NPC_SavePointItemCheck(meindex,talker,itemNo,kosuu)==FALSE){ + return FALSE; + } + + }else{ + itemNo = atoi(buf); + /*--ƹ--*/ + if(NPC_SavePointItemCheck(meindex,talker,itemNo,1)==FALSE){ + return FALSE; + } + } + + } + + + return TRUE; +} + + +BOOL NPC_AndReduceDelete(int meindex,int talker,char *buf,int flg) +{ + + char buf2[512]; + char buf3[256]; + int itemNo=0; + int kosuu; + int j=1; + + if(flg==0){ + + while(getStringFromIndexWithDelim(buf,"&",j,buf2,sizeof(buf2))!=FALSE) + { + j++; + if(strstr( buf2, "*") != NULL){ + getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); + itemNo = atoi(buf3); + getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + /*--ƹ--*/ + if(NPC_SavePointItemDelete(meindex,talker,itemNo,kosuu)==FALSE){ + return FALSE; + } + + }else{ + itemNo = atoi(buf2); + /*--ƹ--*/ + if(NPC_SavePointItemDelete(meindex,talker,itemNo,1)==FALSE){ + return FALSE; + } + + } + } + + }else{ + if(strstr( buf, "*") != NULL){ + getStringFromIndexWithDelim(buf,"*",1,buf3,sizeof(buf3)); + itemNo = atoi(buf3); + getStringFromIndexWithDelim(buf,"*",2,buf3,sizeof(buf3)); + kosuu = atoi(buf3); + + /*--ƹ--*/ + if(NPC_SavePointItemDelete(meindex,talker,itemNo,kosuu)==FALSE){ + return FALSE; + } + + }else{ + itemNo = atoi(buf); + + /*--ƹ--*/ + if(NPC_SavePointItemDelete(meindex,talker,itemNo,1)==FALSE){ + return FALSE; + } + } + + } + + + return TRUE; +} + + + +/* + * ëέ׾ + */ +BOOL NPC_UsedCheck(int meindex,int talker,int flg) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[128]; + char buf2[512]; + int i=1; + int checkflg=0; + + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_savePoint.c UseCheck: GetArgStrErr"); + return FALSE; + } + + if(NPC_Util_GetStrFromStrWithDelim(argstr,"GetItem",buf,sizeof( buf) )!=NULL) + { + i=1; + while( getStringFromIndexWithDelim(buf,",",i,buf2,sizeof(buf2)) !=FALSE ) + { + i++; + if(strstr( buf2, "&") != NULL){ + + if(NPC_AndReduce( meindex, talker, buf2,0)==TRUE) + { + checkflg=1; + break; + } + }else{ + if(NPC_AndReduce( meindex, talker, buf2,1)==TRUE) + { + checkflg=2; + break; + } + } + } + if(checkflg==0) return FALSE; + } else return TRUE; // Arminius 2.5 û GetItem һɴ + + if(flg==1){ + if(checkflg==1){ + if(NPC_AndReduceDelete(meindex,talker,buf2,0)==FALSE){ + return FALSE; + } + }else{ + if(NPC_AndReduceDelete(meindex,talker,buf2,1)==FALSE){ + return FALSE; + } + } + } + + return TRUE; + +} + + + +void NPC_MessageDisp(int meindex,int talker,int MesNo) +{ + + int fd = getfdFromCharaIndex( talker); + int buttontype=WINDOW_BUTTONTYPE_OK; + int windowtype=WINDOW_MESSAGETYPE_MESSAGE; + int windowno=CHAR_WINDOWTYPE_WINDOWSAVEPOINT_START; + + char token[1024]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[32]; + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("NPC_savePoint.c UseCheck: GetArgStrErr"); + return ; + } + + switch(MesNo){ + case 0:/*-- ۢئʧ ةëȻ¾-*/ + NPC_Util_GetStrFromStrWithDelim(argstr,"RequestMsg",token,sizeof( token) ); + + break; + + case 1:/*-- ۢئʧ ةëȻ¾-*/ + NPC_Util_GetStrFromStrWithDelim(argstr,"OkMsg",token,sizeof( token) ); + NPC_Util_GetStrFromStrWithDelim(argstr,"ID",buf,sizeof( buf) ); + NPC_SetFlg(talker,atoi(buf)); + /*--Ƥؤ--*/ + /* ئƾ׹ƱмIDëʢ */ + CHAR_setInt( talker, CHAR_LASTTALKELDER ,CHAR_getWorkInt( meindex, CHAR_WORKOLDMANID ) ); + + /* Ƥ */ + /* ƻ·ڻئмƥʧئ */ + fd = getfdFromCharaIndex( talker); + + break; + + case 2:/*-- ۢئʧ ةëȻ¾-*/ + NPC_Util_GetStrFromStrWithDelim(argstr,"RealyMsg",token,sizeof( token) ); + buttontype=WINDOW_BUTTONTYPE_YESNO; + break; + + } + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + +} + +BOOL NPC_SavePointItemDelete(int meindex,int talker,int itemNo,int kosuu) +{ + int i; + int itemindex; + int id; + int cnt=0; + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( i=CHAR_STARTITEMARRAY;i +#include "char.h" +#include "object.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "handletime.h" +#include "npc_scheduleman.h" +#include "family.h" + +/* + * PK ǼԱ + * + * npc ʾҵǼǼ pk ų + * pk ųһСʱһ pk ΪԭŶ pk , ɵǼԱ + * Ǽ趨Ҫ趨 FamilyPKSchedule + * + * ǼԱͬʱὫ schedule дŵ Game Server + * Ļȶһݶսų̱ͬʱų̡ + * ųֻŴڿʼ 24 Сʱ֮ڵ + * ų̱ĸʽΪ: + * + * time|host_index|host_name|guest_index|guest_name|prepare_time|max_player|flag|win + * + * : ǼԱ¥_ǼԱX_ǼԱY + * + */ + +// ȫļ pk +FamilyPKSchedule fmpks[MAX_SCHEDULE*MAX_SCHEDULEMAN]; + +extern int familyNumTotal; + +enum { + NPC_WORK_ID = CHAR_NPCWORKINT1, // ǼԱ ID, 0 ʼ + NPC_WORK_CHALLENGETIMEOUT = CHAR_NPCWORKINT2, // ͬս timeout + NPC_WORK_SETTINGTIMEOUT = CHAR_NPCWORKINT3, // 趨ս timeout + NPC_WORK_PREVIOUSCHECKTIME = CHAR_NPCWORKINT4, // һμʱ + NPC_WORK_FIGHTINTERVAL = CHAR_NPCWORKINT5, // PK εļ (λ: ) +}; + +enum { + CHAR_WORK_PAGE = CHAR_WORKSHOPRELEVANT, // ҳ + CHAR_WORK_DUELTIME = CHAR_WORKSHOPRELEVANTSEC, // ѡ pk ʱ +}; + +#define SCHEDULEFILEDIR "./Schedule/" + +void NPC_LoadPKSchedule(int meindex); // Load schedule from disk +void NPC_SavePKSchedule(int meindex); // save schedule to disk +void NPC_RemoveExpiredBattle(int meindex); // Ƴڵս +void NPC_ProcessTimeout(int meindex); // timeout +BOOL NPC_AlreadyScheduled(int meindex, int talkerindex); // , һֻܰһ +// ų̱ data +void NPC_LIST_gendata(int meindex, int talkerindex, int page, char *buf, int size); +// ѡ data +void NPC_SELECT_gendata(int meindex, int talkerindex, int page, char *buf, int size); +// ųϸ data +void NPC_DETAIL_gendata(int meindex, char *buf, int size, int dueltime); + +BOOL NPC_SchedulemanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int meid; + int interval; + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEFMSCHEDULEMAN ); + CHAR_setWorkInt ( meindex, NPC_WORK_PREVIOUSCHECKTIME, -1); + + // + NPC_Util_GetArgStr(meindex, argstr, sizeof(argstr)); + meid = NPC_Util_GetNumFromStrWithDelim(argstr, "id" ); + if ((meid<0) || (meid>=MAX_SCHEDULEMAN)) { + print("SCHEDULEMAN init error: invalid ID(%d)\n",meid); + meid=0; + } + CHAR_setWorkInt(meindex, NPC_WORK_ID, meid); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "loopinterval" ); + if ((interval<100) || (interval>10000)) interval=1000; + CHAR_setInt(meindex, CHAR_LOOPINTERVAL, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "challengetimeout"); + if ((interval<60) || (interval>60*60)) interval=20*60; + CHAR_setWorkInt(meindex, NPC_WORK_CHALLENGETIMEOUT, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "settingtimeout"); + if ((interval<10) || (interval>60*60)) interval=60; + CHAR_setWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT, interval); + + interval = NPC_Util_GetNumFromStrWithDelim(argstr, "fightinterval"); + if ((interval<5) || (interval>60)) interval = 50; + CHAR_setWorkInt(meindex, NPC_WORK_FIGHTINTERVAL, interval); + + + NPC_LoadPKSchedule(meindex); + + return TRUE; +} + +void NPC_SchedulemanTalked(int meindex, int talkerindex, char *msg, int color) +{ + char buf[4096]; + int fd; + if (NPC_Util_CharDistance(meindex, talkerindex) > 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, 0); + NPC_LIST_gendata(meindex, talkerindex, 0, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); +} + +void NPC_SchedulemanWindowTalked(int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int page; + int buttontype; + char buf[4096],token[256]; + int fd,i,dt,a; + int fmpks_pos; + + if (NPC_Util_CharDistance(meindex,talkerindex) > 2) return; + if (!NPC_Util_isFaceToFace(meindex, talkerindex, 2)) return; + fd = getfdFromCharaIndex(talkerindex); + if (fd == -1) return; + fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + +// print("seqno=%d select=%d data=%s\n", seqno,select,data); + + switch (seqno) { + case CHAR_WINDOWTYPE_SCHEDULEMAN_START: + switch (select) { + case WINDOW_BUTTONTYPE_NEXT: + case WINDOW_BUTTONTYPE_PREV: + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE) + + MAXSCHEDULEINONEWINDOW + * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_CANCEL; + if (page<0) { + page=0; + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_CANCEL; + } + if (page>MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW) { + page=MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW; + buttontype=WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_CANCEL; + } + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, page); + // Send WN + NPC_LIST_gendata(meindex, talkerindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case WINDOW_BUTTONTYPE_OK: + +#ifdef _FMVER21 + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && +#else + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_MEMBER) && +#endif + + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1)) { + // ֻѳ峤ʹýһĹ (趨ġͬ) + + // decide: send family list or detail or accept + dt=atoi(data); + for (i=0; iMAXFAMILYINONEWINDOW) + buttontype |= WINDOW_BUTTONTYPE_NEXT; + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + + } + break; + case FMPKS_FLAG_CHALLENGE: + { // 峤Ͷͬ pk˹ + int tkfmindex=CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI); + if (tkfmindex==fmpks[fmpks_pos+i].host_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SETTING; + fmpks[fmpks_pos+i].setting_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT); + // ͳϸб + CHAR_setWorkInt(talkerindex, CHAR_WORK_DUELTIME, dt); + NPC_DETAIL_gendata(meindex, buf, sizeof(buf), dt); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_DETAIL, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } else if (tkfmindex==fmpks[fmpks_pos+i].guest_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SCHEDULED; + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_OK; + if (page<0) { + page=0; + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_OK; + } + if (page>MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW) { + page=MAX_SCHEDULE-MAXSCHEDULEINONEWINDOW; + buttontype=WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_OK; + } + CHAR_talkToCli(talkerindex, meindex, + "ļѾս", CHAR_COLORWHITE); + // ͳ list + NPC_LIST_gendata(meindex, talkerindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULELIST, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_START, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + break; + case FMPKS_FLAG_SETTING: + { // 峤 + int tkfmindex=CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI); + if (tkfmindex==fmpks[fmpks_pos+i].host_index) { + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_SETTING; + fmpks[fmpks_pos+i].setting_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_SETTINGTIMEOUT); + // ͳϸб + CHAR_setWorkInt(talkerindex, CHAR_WORK_DUELTIME, dt); + NPC_DETAIL_gendata(meindex, buf, sizeof(buf), dt); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULEDETAIL, + WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_CANCEL, + CHAR_WINDOWTYPE_SCHEDULEMAN_DETAIL, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + } + } + // WON ADD pkԼս + break; + } + + } + } + NPC_SavePKSchedule(meindex); + } else { +#ifdef _FMVER21 + if (CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)!=FMMEMBER_LEADER) { +#else + if (CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)!=FMMEMBER_MEMBER) { +#endif + CHAR_talkToCli(talkerindex, meindex, + "ֻ峤ԤԼУม", CHAR_COLORWHITE); + }else if (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)!=1) { + CHAR_talkToCli(talkerindex, meindex, + "ļ廹ûʽม", CHAR_COLORWHITE); + } + } + break; + } + break; + case CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT: + switch (select) { + case WINDOW_BUTTONTYPE_PREV: + case WINDOW_BUTTONTYPE_NEXT: + page=CHAR_getWorkInt(talkerindex, CHAR_WORK_PAGE) + + MAXFAMILYINONEWINDOW + * (( select == WINDOW_BUTTONTYPE_NEXT) ? 1 : -1); + buttontype=WINDOW_BUTTONTYPE_NEXT | WINDOW_BUTTONTYPE_PREV; + if (page<1) { + page=1; + buttontype=WINDOW_BUTTONTYPE_NEXT; + } + if (page>familyNumTotal-MAXFAMILYINONEWINDOW+1) { + page=familyNumTotal-MAXFAMILYINONEWINDOW+1; + buttontype=WINDOW_BUTTONTYPE_PREV; + } + CHAR_setWorkInt(talkerindex, CHAR_WORK_PAGE, page); + // Send WN + NPC_SELECT_gendata(meindex, talkerindex, page, buf, sizeof(buf)); + lssproto_WN_send(fd, WINDOW_MESSAGETYPE_PKSCHEDULESELECTFAMILY, + buttontype, + CHAR_WINDOWTYPE_SCHEDULEMAN_SELECT, + CHAR_getWorkInt(meindex, CHAR_WORKOBJINDEX), + buf); + break; + case WINDOW_BUTTONTYPE_OK: + +#ifdef _FMVER21 + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_LEADER) && +#else + if ((CHAR_getInt(talkerindex,CHAR_FMLEADERFLAG)==FMMEMBER_MEMBER) && +#endif + (CHAR_getWorkInt(talkerindex, CHAR_WORKFMSETUPFLAG)==1)) { + + dt=CHAR_getWorkInt(talkerindex, CHAR_WORK_DUELTIME); + for (i=0; i0) && (a<=40)) fmpks[fmpks_pos+i].prepare_time=a; + } + // + if (getStringFromIndexWithDelim(data,"|",5,token,sizeof(token))) { + a=atoi(token); + if ((a>0) && (a<=50)) fmpks[fmpks_pos+i].max_player=a; + } + // ʤ + if (getStringFromIndexWithDelim(data,"|",6,token,sizeof(token))) { + a=atoi(token); + if ((a>=0) && (a<=1)) fmpks[fmpks_pos+i].win = a; + } + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_CHALLENGE; + fmpks[fmpks_pos+i].challenge_timeout= + CHAR_getWorkInt(meindex, NPC_WORK_CHALLENGETIMEOUT); + CHAR_talkToCli(talkerindex, meindex, + "ս趨ɡ", CHAR_COLORWHITE); + } + break; + case WINDOW_BUTTONTYPE_CANCEL: + fmpks[fmpks_pos+i].flag=FMPKS_FLAG_NONE; + fmpks[fmpks_pos+i].host_index=-1; + strcpy(fmpks[fmpks_pos+i].host_name,""); + fmpks[fmpks_pos+i].guest_index=-1; + strcpy(fmpks[fmpks_pos+i].guest_name,""); + CHAR_talkToCli(talkerindex, meindex, + "ս", CHAR_COLORWHITE); + break; + } + NPC_SavePKSchedule(meindex); + } + } + } + } + break; + } +} + +void NPC_SchedulemanLoop(int meindex) +{ +// int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + +/* + print("Scheduleman: fmpks_pos=%d dueltime=%d host=%s guest=%s\n", + fmpks_pos, fmpks[fmpks_pos].dueltime, fmpks[fmpks_pos].host_name, fmpks[fmpks_pos].guest_name); +*/ + + NPC_RemoveExpiredBattle(meindex); + NPC_ProcessTimeout(meindex); +} + +// Ƴڵս +void NPC_RemoveExpiredBattle(int meindex) +{ + struct tm tm1; + int keeptime; + int i,expired=-1; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + int prevckt = CHAR_getWorkInt(meindex, NPC_WORK_PREVIOUSCHECKTIME); + int fin = CHAR_getWorkInt(meindex, NPC_WORK_FIGHTINTERVAL); + int h,d; + + // Ŀǰʱ̵׼ȥƳڵų + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + + if (tm1.tm_min=60) keeptime = keeptime + 100 - 60; + } + if (fmpks[fmpks_pos].dueltime > keeptime) expired=23; + } + + if (expired>=0) { + // ƶųȡѾʧЧų + for (i=expired+1; i=60 ) h=h+100-60; + if (h>=2400) { + h = h-2400; + d = 10000; + } + fmpks[fmpks_pos+i].dueltime=d+h; + } + + // һų, Ŷ״Ϊų̡ + if (fmpks[fmpks_pos].flag < FMPKS_FLAG_SCHEDULED) { + fmpks[fmpks_pos].flag = FMPKS_FLAG_NONE; + fmpks[fmpks_pos+i].host_index=-1; + strcpy(fmpks[fmpks_pos+i].host_name,""); + fmpks[fmpks_pos+i].guest_index=-1; + strcpy(fmpks[fmpks_pos+i].guest_name,""); + } + + } +} + +// timeout +void NPC_ProcessTimeout(int meindex) +{ + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + + for (i=0; i=0) { + fmpks[fmpks_pos+i].challenge_timeout--; + if (fmpks[fmpks_pos+i].challenge_timeout<0) { + fmpks[fmpks_pos+i].host_index = -1; + strcpy(fmpks[fmpks_pos+i].host_name, "-1"); + fmpks[fmpks_pos+i].guest_index = -1; + strcpy(fmpks[fmpks_pos+i].guest_name, "-1"); + fmpks[fmpks_pos+i].prepare_time = -1; + fmpks[fmpks_pos+i].max_player = -1; + fmpks[fmpks_pos+i].flag=-1; + fmpks[fmpks_pos+i].win=-1; + } + } + } + if (fmpks[fmpks_pos+i].flag==FMPKS_FLAG_SETTING) { + if (fmpks[fmpks_pos+i].setting_timeout>=0) { + fmpks[fmpks_pos+i].setting_timeout--; + if (fmpks[fmpks_pos+i].setting_timeout<0) { + fmpks[fmpks_pos+i].host_index = -1; + strcpy(fmpks[fmpks_pos+i].host_name, "-1"); + fmpks[fmpks_pos+i].guest_index = -1; + strcpy(fmpks[fmpks_pos+i].guest_name, "-1"); + fmpks[fmpks_pos+i].prepare_time = -1; + fmpks[fmpks_pos+i].max_player = -1; + fmpks[fmpks_pos+i].flag=-1; + fmpks[fmpks_pos+i].win=-1; + } + } + } + } +} + +// , һֻܰһս +BOOL NPC_AlreadyScheduled(int meindex, int talkerindex) +{ + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + int tkfmindex = CHAR_getWorkInt(talkerindex, CHAR_WORKFMINDEXI); + int flag=1; + + for (i=0; i=FMPKS_FLAG_SCHEDULED) { + if (fmpks[fmpks_pos+i].host_index==tkfmindex) return TRUE; + } else if (fmpks[fmpks_pos+i].flag!=FMPKS_FLAG_NONE) { + if (flag==1) flag=0; else return TRUE; + } + } + return FALSE; +} + +// ȡ schedule +void NPC_LoadPKSchedule(int meindex) +{ + char filename[256],tmp[4096],token[256]; + FILE *f; + int i; + int fmpks_pos = CHAR_getWorkInt(meindex, NPC_WORK_ID)*MAX_SCHEDULE; + + snprintf(filename,sizeof(filename), "%s%d_%d_%d", + SCHEDULEFILEDIR, CHAR_getInt(meindex, CHAR_FLOOR), + CHAR_getInt(meindex, CHAR_X), + CHAR_getInt(meindex, CHAR_Y) ); + + if( ! (f=fopen( filename, "r" )) ){ // create new schedule file + f = fopen( filename, "w" ); + if( !f ){ + print( "ERROR:Can't create Schedule file %s!\n",filename ); + return; + } + for (i=0; i=MAX_SCHEDULE)) return; + + // ¼Ŀǰʱ + memcpy( &tm1, localtime( (time_t *)&NowTime.tv_sec), sizeof( tm1)); + sprintf(buf, "%d|", tm1.tm_hour*100 + tm1.tm_min); + + for (i=page; i +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_airplane.h" +#include "handletime.h" + +/* + * (Made from Bus) + */ + #ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +enum { + NPC_WORK_ROUTETOX = CHAR_NPCWORKINT1, /* ߣ */ + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, /* ߣ */ + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, /* */ + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, /* 微Ի ߡ ࡰԻ */ + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, + NPC_WORK_ONEWAYFLG = CHAR_NPCWORKINT11, + NPC_WORK_RUNWAVE = CHAR_NPCWORKINT13, +}; + +/* ⼰enum */ +enum { + NPC_AIR_MSG_GETTINGON, + NPC_AIR_MSG_NOTPARTY, + NPC_AIR_MSG_OVERPARTY, + NPC_AIR_MSG_DENIEDITEM, + NPC_AIR_MSG_ALLOWITEM, + NPC_AIR_MSG_LEVEL, + NPC_AIR_MSG_GOLD, + NPC_AIR_MSG_EVENT, + NPC_AIR_MSG_START, + NPC_AIR_MSG_END, +}; +typedef struct { + char option[32]; + char defaultmsg[128]; +}NPC_AIR_MSG; +NPC_AIR_MSG airmsg[] = { + { "msg_gettingon", "PAON޷;ࡣ"}, + { "msg_notparty", "PAPAON޷ŶӼࡣ"}, + { "msg_overparty", "PAON"}, + { "msg_denieditem", "PAPAONҿɲҪߣ"}, + { "msg_allowitem", "~(ҪǸ߰!)"}, + { "msg_level", "PAPAONĵȼࡣ"}, + { "msg_stone", "PAPAONǮࡣ"}, + { "msg_event", "PAON޷ࡣ"}, + { "msg_start", "~()"}, + { "msg_end", "~()"} +}; + +static int npc_ShipSetPoint( int meindex, char *argstr); +static void npc_ShipSetDestPoint( int meindex, char *argstr); +static BOOL npc_ShipCheckDeniedItem( int meindex, int charaindex, char *argstr); +static BOOL npc_ShipCheckLevel( int meindex, int charaindex, char *argstr); +static int npc_ShipCheckStone( int meindex, int charaindex, char *argstr); +static void npc_ShipSendMsg( int meindex, int talkerindex, int tablenum); +static int npc_ShipGetRoutePointNum( int meindex, char *argstr ); +static void npc_Ship_walk( int meindex); + +#define NPC_AIR_LOOPTIME 100 +#define NPC_AIR_WAITTIME_DEFAULT 180 +#define NPC_AIR_WAITINGMODE_WAITTIME 5000 + +/********************************* +* +*********************************/ +BOOL npc_ShipInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i; + char buf[256],buf1[256]; + int routenum; + int waittime; + int seflg; + int onewayflg; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* ئľئ¦Ѽ */ + routenum = NPC_Util_GetNumFromStrWithDelim( argstr, "routenum"); + if( routenum == -1 ) { + print( "npcair:nothing routenum \n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEMAX, routenum); + + for( i = 1; i <= routenum; i ++ ) { + char routetostring[64]; + snprintf( routetostring, sizeof( routetostring), "routeto%d", i); + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route to \n"); + return FALSE; + } + } + //ANDY_ADD NPC_WORK_RUNWAVE + if( NPC_Util_GetStrFromStrWithDelim( argstr, "WAVE",buf1, sizeof(buf1)) == NULL ){ + CHAR_setWorkInt( meindex, NPC_WORK_RUNWAVE, 77); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_RUNWAVE, atoi( buf1) ); + } + + waittime = NPC_Util_GetNumFromStrWithDelim( argstr, "waittime"); + if( waittime == -1 ) waittime = NPC_AIR_WAITTIME_DEFAULT; + CHAR_setWorkInt( meindex, NPC_WORK_WAITTIME, waittime); + seflg = NPC_Util_GetNumFromStrWithDelim( argstr, "seflg"); + if( seflg == -1 ) seflg = TRUE; + CHAR_setWorkInt( meindex, NPC_WORK_SEFLG, seflg); + + onewayflg = NPC_Util_GetNumFromStrWithDelim( argstr, "oneway"); + if( onewayflg == -1 ) onewayflg = FALSE; // default + CHAR_setWorkInt( meindex, NPC_WORK_ONEWAYFLG, onewayflg); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEBUS ); + + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, 2); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 0); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, 0); + + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, + NPC_AIR_WAITINGMODE_WAITTIME); + + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + + for( i = 0; i < getPartyNum(meindex); i ++) { + CHAR_setWorkInt( meindex, CHAR_WORKPARTYINDEX1 + i, -1); + } + + /* */ +{ + int rev; + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + //print( "route:%d\n",CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + /* Ƿ */ + rev = NPC_Util_GetNumFromStrWithDelim( argstr, "reverse"); + if( rev == 1 ) { + int num = npc_ShipGetRoutePointNum( meindex, argstr); + if( num <= 0 ) { + print( "npcairplane:֣\n"); + return FALSE; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, 1); + } + /* ë */ + npc_ShipSetPoint( meindex, argstr); + /* ë */ + npc_ShipSetDestPoint( meindex, argstr); +} + + return TRUE; +} + + +/********************************* +* ƾľݼ +*********************************/ +void npc_ShipTalked( int meindex , int talkerindex , char *szMes , + int color ) +{ + int i; + int partyflg = FALSE; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE); + + /* 帲ƻ ɱ */ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + /* мɡ ū Ʃ */ + for( i = 0; i < getPartyNum(meindex); i ++ ) { + int index = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX(index)){ + if( index == talkerindex) { + partyflg = TRUE; + } + } + } + if( !partyflg ) { + //npc_ShipCheckJoinParty( meindex, talkerindex, TRUE); + } + else { + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) == 0 ) { + int i; + // #define NPC_AIR_DEBUGROUTINTG "routingtable:" + if( strstr( szMes, "" ) || + strstr( szMes, "" ) || + strstr( szMes, "Go" ) || + strstr( szMes, "go" )) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //andy_reEdit NPC_WORK_RUNWAVE + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + npc_ShipSendMsg( meindex, partyindex, NPC_AIR_MSG_START); + } + } + } + } + } +} +/************************************** + * + **************************************/ +void npc_ShipLoop( int meindex) +{ + int i; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE); + switch( CHAR_getWorkInt( meindex, NPC_WORK_MODE )) { + case 0: + /* ƹݣë */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) + < NowTime.tv_sec) + { + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //ANDY_reEdit + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + npc_ShipSendMsg( meindex, partyindex, NPC_AIR_MSG_START); + } + } + + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + } + return; + case 1: + /* */ + npc_Ship_walk( meindex); + case 2: + /* Ȼƹ */ + /* ޻׼ƥ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + + (CHAR_getWorkInt( meindex, NPC_WORK_WAITTIME) /3) + < NowTime.tv_sec) + { + CHAR_setWorkInt( meindex, NPC_WORK_MODE,1); + /* Ѽëʻպ */ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + + } + return; + case 3: + /* ƻ֣ͷʧ мб + * Ƴƥëľ֧ + */ + if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) + 3 < NowTime.tv_sec){ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_WAITINGMODE_WAITTIME); + { + int r = CHAR_getWorkInt( meindex, NPC_WORK_ROUTEMAX); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTROUTE, RAND( 1, r)); + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUNDTRIP, + CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP)^1); + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP) == 1) { + int num = npc_ShipGetRoutePointNum( meindex, argstr); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, num-1); + }else { + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +1); + } + npc_ShipSetPoint( meindex, argstr); + npc_ShipSetDestPoint( meindex, argstr); + CHAR_DischargeParty( meindex, 0); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + if ((CHAR_getWorkInt(meindex, NPC_WORK_ONEWAYFLG) == 1) && + (CHAR_getWorkInt(meindex, NPC_WORK_ROUNDTRIP) == 1) ){ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NPC_AIR_LOOPTIME); + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 1); + } else + CHAR_setWorkInt( meindex, NPC_WORK_MODE, 0); + } + return; + default: + break; + } +} +/************************************** + * ʣ + **************************************/ +static void npc_Ship_walk( int meindex) +{ + POINT start, end; + int dir; + int ret; + int i; + int npc_wave = CHAR_getWorkInt( meindex, NPC_WORK_RUNWAVE ); + + /* */ + /* ݼ */ + start.x = CHAR_getInt( meindex, CHAR_X); + start.y = CHAR_getInt( meindex, CHAR_Y); + end.x = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOX); + end.y = CHAR_getWorkInt( meindex, NPC_WORK_ROUTETOY); + + /* ׼ƥݼ̼ */ + if( start.x == end.x && start.y == end.y ) { + int add = 1; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( CHAR_getWorkInt( meindex, NPC_WORK_ROUNDTRIP ) == 1 ) { + add *= -1; + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTEPOINT, + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT) +add); + if( npc_ShipSetPoint( meindex, argstr) == FALSE ) { + /* */ + /* ƹ */ + CHAR_setWorkInt( meindex, NPC_WORK_MODE,3); + + /* SE Ѩƹ̫ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_SEFLG )) { + //ANDY_reEdit + CHAR_sendSEoArroundCharacter( + CHAR_getInt( meindex, CHAR_FLOOR), + CHAR_getInt( meindex, CHAR_X), + CHAR_getInt( meindex, CHAR_Y), + npc_wave, + TRUE); + } + /* ݼ*/ + for( i = 1; i < getPartyNum(meindex); i ++ ) { + int partyindex = CHAR_getWorkInt( meindex, CHAR_WORKPARTYINDEX1+i); + if( CHAR_CHECKINDEX( partyindex)) { + npc_ShipSendMsg( meindex, partyindex, NPC_AIR_MSG_END); + } + } + /* ػë */ + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return; + } + else { + return; + } + } + /*-------------------------------------------------------*/ + /* ھ */ + + /* ëƻ */ + dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + + /* ɡ ūƥ */ + end.x = CHAR_getInt( meindex, CHAR_X); + end.y = CHAR_getInt( meindex, CHAR_Y); + + if( dir >= 0 && dir <= 7 ) { + /* */ + ret = CHAR_walk( meindex, dir, 0); + + if( ret == CHAR_WALKSUCCESSED ) { + /* лئëھ */ + int i; + int mefl=CHAR_getInt( meindex, CHAR_FLOOR); + for( i = 1; i < getPartyNum(meindex); i ++ ) { + int toindex = CHAR_getWorkInt( meindex, i + CHAR_WORKPARTYINDEX1); + if( !CHAR_CHECKINDEX(toindex) )continue; + int fl = CHAR_getInt( toindex, CHAR_FLOOR); + int xx = CHAR_getInt( toindex, CHAR_X); + int yy = CHAR_getInt( toindex, CHAR_Y); + if( CHAR_CHECKINDEX(toindex) && + (mefl==fl) && (abs(xx-end.x)+abs(yy-end.y)<10) ) { + int parent_dir; + /* Ҽ ʼ󡼰 ëƻ */ + /* */ + start.x = xx; + start.y = yy; + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + /* ·ūë ¿б + * ݼҷ󡼰Ҽ ëܰ + */ + end = start; + if( parent_dir != -1 ) { + CHAR_walk( toindex, parent_dir, 0); + } + } + } + } + } +} +/************************************** + * ݼë + **************************************/ +static int npc_ShipSetPoint( int meindex, char *argstr) +{ + char buf[4096]; + char buf2[256]; + char buf3[256]; + int floor,warpx,warpy; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route \n"); + return FALSE; + } + + ret = getStringFromIndexWithDelim( buf, ";", + CHAR_getWorkInt( meindex, NPC_WORK_ROUTEPOINT), + buf2, sizeof(buf2)); + if( ret == FALSE ) return FALSE; + + // Arminius: add floor + + ret = getStringFromIndexWithDelim( buf2, ",", 1, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + floor = atoi(buf3); + + ret = getStringFromIndexWithDelim( buf2, ",", 2, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, atoi( buf3)); + warpx = atoi(buf3); + + ret = getStringFromIndexWithDelim( buf2, ",", 3, + buf3, sizeof(buf3)); + if( ret == FALSE) return FALSE; + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, atoi( buf3)); + warpy = atoi(buf3); + + if (floor!=CHAR_getInt(meindex, CHAR_FLOOR)) { + int i; + CHAR_warpToSpecificPoint(meindex, floor, warpx, warpy); + + for( i = 1; i < getPartyNum(meindex); i ++ ) { + int toindex = CHAR_getWorkInt( meindex, i + CHAR_WORKPARTYINDEX1); + if( CHAR_CHECKINDEX(toindex) ) { + CHAR_warpToSpecificPoint(toindex, floor, warpx, warpy); + } + } + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOX, warpx); + CHAR_setWorkInt( meindex, NPC_WORK_ROUTETOY, warpy); + } + + return TRUE; +} +/************************************** + * route įգ 󡻥ؤչľë + * į屾£ + **************************************/ +static void npc_ShipSetDestPoint( int meindex, char *argstr) +{ + char buf[256]; + char routename[256]; + + snprintf( routename, sizeof( routename), "routename%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routename, buf, sizeof( buf)) + != NULL ) + { + CHAR_setChar( meindex, CHAR_OWNTITLE, buf); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + } +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼշֻ + **************************************/ +static BOOL npc_ShipCheckDeniedItem( int meindex, int charaindex, char *argstr) +{ + char buf[1024]; + BOOL found = TRUE; + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "denieditem", buf, sizeof( buf)) + != NULL ) + { + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charaindex); + for( j = 0; j < itemMax; j ++) { +#endif + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + found = FALSE; + break; + } + } + } + } + } + return found; +} +/************************************** + * ϶ýľʧ ةë Ȼ¾ + * Ȼئֻ + **************************************/ +BOOL npc_ShipCheckAllowItem( int meindex, int charaindex, BOOL pickupmode) +{ + char buf[1024]; + BOOL found = TRUE; + BOOL pickup = FALSE; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "pickupitem", buf, sizeof( buf)) + != NULL ) + { + pickup = TRUE; + } + if( NPC_Util_GetStrFromStrWithDelim( argstr, "allowitem", buf, sizeof( buf)) + != NULL ) + { + int i; + int ret; + for( i = 1; ; i ++) { + int itemid; + char buf2[64]; + int j; + BOOL getflg; + ret = getStringFromIndexWithDelim( buf, ",", i, buf2, sizeof(buf2)); + if( ret == FALSE ) break; + itemid = atoi( buf2); + getflg = FALSE; + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charaindex); + for( j = 0; j < itemMax; j ++) { +#endif + int itemindex = CHAR_getItemIndex( charaindex, j); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) == itemid) { + /* Ȼ¾գݹʧ ةë */ + if( pickupmode && pickup && !getflg) { + CHAR_DelItem( charaindex, j); + getflg = TRUE; + } + break; + } + } + } +#ifdef _NEW_ITEM_ + if( j == itemMax) { +#endif + found = FALSE; + break; + } + } + } + return found; +} + +/************************************** + * ϶ýľìﶯ + **************************************/ +static BOOL npc_ShipCheckLevel( int meindex, int charaindex, char *argstr) +{ + int level; + + /* ئľئ¦Ѽ */ + level = NPC_Util_GetNumFromStrWithDelim( argstr, "needlevel"); + if( level == -1 ) { + return TRUE; + } + if( CHAR_getInt( charaindex, CHAR_LV) >= level ) return TRUE; + + return FALSE; +} + +/************************************** + * ë + * -1 0 ݾ ۢStone + **************************************/ +static int npc_ShipCheckStone( int meindex, int charaindex, char *argstr) +{ + int gold; + + /* ئľئ¦Ѽ */ + gold = NPC_Util_GetNumFromStrWithDelim( argstr, "needstone"); + if( gold == -1 ) { + return 0; + } + if( CHAR_getInt( charaindex, CHAR_GOLD) >= gold ) return gold; + + return -1; +} +/************************************** + * ë˪ + * ¦Ѽ⻥ئľɷɻë˪ + **************************************/ +static void npc_ShipSendMsg( int meindex, int talkerindex, int tablenum) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[256]; + char msg[256]; + if( tablenum < 0 || tablenum >= arraysizeof( airmsg)) return; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, airmsg[tablenum].option, buf, sizeof( buf)) + != NULL ) + { + strcpy( msg, buf); + } + else { + snprintf( msg, sizeof(msg),airmsg[tablenum].defaultmsg); + } + CHAR_talkToCli( talkerindex, meindex, msg, CHAR_COLORYELLOW); +} +/************************************** + * ƤP̼ë + **************************************/ +static int npc_ShipGetRoutePointNum( int meindex, char *argstr ) +{ + int i; + char buf[4096]; + char buf2[256]; + int ret; + char routetostring[64]; + + snprintf( routetostring, sizeof( routetostring), "routeto%d", + CHAR_getWorkInt( meindex, NPC_WORK_CURRENTROUTE)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, routetostring,buf, sizeof(buf)) + == NULL ) + { + print( "npcair:nothing route \n"); + return -1; + } + for( i = 1; ; i ++ ) { + ret = getStringFromIndexWithDelim( buf, ";", i, buf2, sizeof(buf2)); + if( ret == FALSE) break; + } + return( i -1); +} +BOOL npc_ShipCheckJoinParty( int meindex, int charaindex, BOOL msgflg) +{ + //int fd; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + int ret; + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + /* */ + if( !NPC_Util_charIsInFrontOfChar( charaindex, meindex, 1 )) return FALSE; + /* ַ */ + if( CHAR_getWorkInt( meindex, NPC_WORK_MODE) != 0 ) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_GETTINGON); + return FALSE; + } + /* շֻ */ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) != CHAR_PARTY_NONE) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_NOTPARTY); + return FALSE; + } + /* ɡ ūë */ + if( CHAR_getEmptyPartyArray( meindex) == -1 ) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_OVERPARTY); + return FALSE; + } + /* ʧ ةë(ʧ ة) */ + if( !npc_ShipCheckDeniedItem( meindex, charaindex, argstr)) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_DENIEDITEM); + return FALSE; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( charaindex, 0) == FALSE ) { + CHAR_talkToCli( charaindex, -1, "޷Яϻ", CHAR_COLORYELLOW); + return FALSE; + } +#endif + + /* ʧ ةë( ۢʧ ة) */ + if( !npc_ShipCheckAllowItem( meindex, charaindex, FALSE)) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_ALLOWITEM); + return FALSE; + } + /* ìPë */ + if( !npc_ShipCheckLevel( meindex, charaindex, argstr)) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_LEVEL); + return FALSE; + } + /* ì */ +// if( CHAR_getInt( charaindex, CHAR_NOWEVENT) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT2) != 0 || +// CHAR_getInt( charaindex, CHAR_NOWEVENT3) != 0 ) +// { +// if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_EVENT); +// return FALSE; +// } + /* żë ë¼ƥ ͱ³ */ + ret = npc_ShipCheckStone( meindex, charaindex, argstr); + if( ret == -1 ) { + if( msgflg) npc_ShipSendMsg( meindex, charaindex, NPC_AIR_MSG_GOLD); + return FALSE; + } + if( ret != 0 ) { + char msgbuf[128]; + /* ë */ + CHAR_setInt( charaindex, CHAR_GOLD, + CHAR_getInt( charaindex, CHAR_GOLD) - ret); + /* ˪ */ + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_GOLD); + snprintf( msgbuf, sizeof( msgbuf), "֧%d Stone", ret); + CHAR_talkToCli( charaindex, -1, msgbuf, CHAR_COLORYELLOW); + } + /* ɡ ū */ + //CHAR_JoinParty_Main( charaindex, meindex); + + //fd = getfdFromCharaIndex( charaindex ); + + //lssproto_PR_send( fd, 1, 1); + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_signboard.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_signboard.c new file mode 100644 index 0000000..fe9ce29 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_signboard.c @@ -0,0 +1,122 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "readmap.h" +// Arminius 8.4 manor +#include "family.h" + +static void NPC_SignBoard_Window( int meindex, int toindex, int num,int select); + + +/********************************* +*********************************/ +BOOL NPC_SignBoardInit( int meindex ) +{ + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + /*--ɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEMSG ); + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + + return TRUE; + +} + + + + +/********************************* +*********************************/ +void NPC_SignBoardLooked( int meindex , int lookedindex) +{ + + if( CHAR_getInt( lookedindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if( NPC_Util_CharDistance( lookedindex, meindex ) > 1) return; + + + NPC_SignBoard_Window( meindex, lookedindex,0,-1); + +} + + +static void NPC_SignBoard_Window( int meindex, int toindex, int num,int select) +{ + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + int fd = getfdFromCharaIndex( toindex); + + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return; + } + + // Arminius: manor + { + char *p,*q; + extern struct FM_POINTLIST fmpointlist; + p=strstr(npcarg, "%manorid:"); + if (p!=NULL) { + char tmp[1024]; + int a; + + q=strstr(p+1,"%"); + if (q!=NULL) { + q[0]='\0'; + p[0]='\0'; + a=atoi(p+9); +#ifdef _FAMILY_MANORNUM_CHANGE // CoolFish ޸װ԰ + if ((a>=1) && (a<=MANORNUM)) { +#else + if ((a>=1) && (a<=4)) { +#endif + getStringFromIndexWithDelim(fmpointlist.pointlistarray[a-1], "|", 5, token, sizeof(token)); + if (atoi(token)>=0) { + getStringFromIndexWithDelim(fmpointlist.pointlistarray[a-1], "|", 6, token, sizeof(token)); + sprintf(tmp,"%s%s%s",npcarg,token,q+1); + strcpy(npcarg, tmp); + } else { + sprintf(tmp,"%sûκμ%s",npcarg,q+1); + strcpy(npcarg, tmp); + } + } + } + } + } + + sprintf(token, "塡\n%s",npcarg); + + /*--˪--*/ + lssproto_WN_send( fd,WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWPETSHOP_START, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + + + +/*----------------------------------------- + * +-------------------------------------------*/ +void NPC_SignBoardWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) { + return; + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_simpleshop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_simpleshop.c new file mode 100644 index 0000000..415c6c7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_simpleshop.c @@ -0,0 +1,740 @@ +#include "version.h" +#include + +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "item.h" +#include "util.h" +#include "handletime.h" +#include "anim_tbl.h" +#include "npc_door.h" +#include "lssproto_serv.h" +#include "npcutil.h" +#include "npccreate.h" +#include "log.h" + + +/* + * + * + * ì: init, talked, specialtalked + * + * + */ +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static void NPC_SimpleShopOpenShopWindow( int meindex, int cliindex, + char *npcarg ); +static void NPC_SimpleShopGetEscapedItemString( int shopindex, + int cliindex, char *str ); +static BOOL NPC_SimpleShopProcessBuyMsg( char *msg, int shop, int cli ); +static BOOL NPC_SimpleShopProcessSellMsg( char *msg, int shop, int cli ); + +static BOOL NPC_LimitBuyInShopProcessSellMsg(char *msg,int shop,int cli); + + +static BOOL NPC_SimpleShopFillItem( int meindex, char *npcarg ); +static int NPC_SimpleShopGetItemNum( int meindex ); +static void NPC_SimpleShopNormalWindow( int meindex, + int playerindex, char *str ); +static int NPC_ShopWindowIndexToItemTableIndex( int charindex, + int shopwindowindex ); +static BOOL NPC_SimpleShopOpenShopOrNot( char *msg, char *openshopstr ); +//static void NPC_SimpleShopSetLeakLevel( int meindex ); + +#define NPC_SIMPLESHOPMAXBUYPRICE 9999 +#define SIMPLESHOPTALKBUFSIZE 256 + +#define SIMPLESHOP_FATALERRSTR "ʹԲ,״̫ѡ" + +#define SIMPLESHOP_MAXINFINITITEM 40 + +enum{ + OPENSHOPTOKEN=1, + MSGTOKEN, + MAINTOKEN, + BUYTOKEN, + OKBUYTOKEN, + SELLTOKEN, + OKSELLTOKEN, + POORTOKEN, + ITEMFULLTOKEN, + ANOTHERPLAYERTOKEN, + RAREITEMTOKEN, + THANKYOUTOKEN, + ITEMLISTTOKEN, + + BUYINITEMLISTTOKEN, + }; +void NPC_SimpleShopTalked( int meindex, int talker, char *msg, int color ) +{ +#define SHOPRANGE 3 + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE], token[NPC_UTIL_GETARGSTR_LINEMAX]; + if( CHAR_getInt( talker,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER ){ + return; + } + if( NPC_Util_charIsInFrontOfChar( talker, meindex, SHOPRANGE ) + && ! CHAR_getFlg( talker,CHAR_ISDIE ) ){ + NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)); + getStringFromIndexWithDelim( npcarg,"|", OPENSHOPTOKEN,token, sizeof(token)); + if( NPC_SimpleShopOpenShopOrNot( msg, token ) + && NPC_Util_isFaceToFace( meindex, talker, SHOPRANGE ) ){ + CHAR_setWorkInt( meindex, CHAR_WORKSHOPCLIENTINDEX, talker ); + NPC_SimpleShopOpenShopWindow( meindex, talker, npcarg ); + }else{ + int tokennum; + int i; + char tmp[NPC_UTIL_GETARGSTR_LINEMAX]; + getStringFromIndexWithDelim( npcarg,"|", MSGTOKEN,token, sizeof(token)); + tokennum = 1; + for( i=0;token[i]!='\0';i++ ){ + if( token[i] == ',' ) tokennum++; + } + getStringFromIndexWithDelim( token,",", rand()%tokennum+1,tmp, sizeof(tmp)); + CHAR_talkToCli( talker, meindex, tmp, CHAR_COLORWHITE ); + } + } +} + +void NPC_SimpleShopSpecialTalked( int meindex, int talker, char *msg, int color ) +{ + if( CHAR_getInt(talker,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + && NPC_Util_isFaceToFace( meindex, talker, SHOPRANGE ) ){ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE], token[NPC_UTIL_GETARGSTR_LINEMAX]; + NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)); + switch( tolower(msg[0]) ){ + case 's': + { + int ret; + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX)!= talker ){ + getStringFromIndexWithDelim( npcarg,"|",ANOTHERPLAYERTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow( meindex, talker, token ); + return; + } + ret = getStringFromIndexWithDelim( msg, "|", 3, token, sizeof(token)); + if( ret == FALSE ){ + token[0] = 'e'; + token[1] = '\0'; + } + switch( tolower(token[0])){ + case 'b': + if( (ret=NPC_SimpleShopProcessBuyMsg(msg,meindex,talker)) + <0){ + switch( ret ){ + case -2: + getStringFromIndexWithDelim( npcarg,"|",POORTOKEN, + token,sizeof(token)); + NPC_SimpleShopNormalWindow( meindex,talker,token); + break; + case -3: + getStringFromIndexWithDelim( npcarg,"|", + ITEMFULLTOKEN, + token,sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + break; + case -1: + default: + NPC_SimpleShopNormalWindow(meindex, talker, + SIMPLESHOP_FATALERRSTR + ); + break; + } + }else{ + NPC_SimpleShopFillItem( meindex, npcarg ); + getStringFromIndexWithDelim(npcarg,"|",THANKYOUTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + } + break; + case 's': + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX) != talker ){ + getStringFromIndexWithDelim( npcarg,"|", + ANOTHERPLAYERTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow( meindex, talker, token ); + return; + } + if((ret=NPC_SimpleShopProcessSellMsg(msg,meindex,talker)) <0 ){ + switch(ret){ + case -2: + getStringFromIndexWithDelim( npcarg,"|", + RAREITEMTOKEN, + token, sizeof(token) ); + NPC_SimpleShopNormalWindow( meindex,talker,token); + break; + case -1: + default: + NPC_SimpleShopNormalWindow(meindex, talker, + SIMPLESHOP_FATALERRSTR ); + break; + } + }else{ + getStringFromIndexWithDelim(npcarg,"|",THANKYOUTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + } + break; + case 'e': + default: + CHAR_setWorkInt( meindex, CHAR_WORKSHOPCLIENTINDEX, -1 ); + break; + } + break; + } + case 'i': + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX) + == talker ){ + NPC_SimpleShopOpenShopWindow( meindex, talker, npcarg ); + } + break; + default: + break; + } + } +} + +void NPC_LimitBuyInShopSpecialTalked( int meindex, int talker, char *msg, int color ) +{ + if( CHAR_getInt(talker,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + && NPC_Util_isFaceToFace( meindex, talker, SHOPRANGE ) ){ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE], token[NPC_UTIL_GETARGSTR_LINEMAX]; + NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)); + switch( tolower(msg[0]) ){ + case 's': + { + int ret; + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX) != talker ){ + getStringFromIndexWithDelim( npcarg,"|", + ANOTHERPLAYERTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow( meindex, talker, token ); + return; + } + ret = getStringFromIndexWithDelim( msg, "|", 3, token, sizeof( token)); + if( ret == FALSE ){ + token[0] = 'e'; + token[1] = '\0'; + } + switch( tolower(token[0])){ + case 'b': + if( ( ret = NPC_SimpleShopProcessBuyMsg( msg, meindex, talker)) < 0){ + switch( ret ){ + case -2: + getStringFromIndexWithDelim( npcarg,"|",POORTOKEN, + token,sizeof(token)); + NPC_SimpleShopNormalWindow( meindex,talker,token); + break; + case -3: + getStringFromIndexWithDelim( npcarg,"|", + ITEMFULLTOKEN, + token,sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + break; + case -1: + default: + NPC_SimpleShopNormalWindow(meindex, talker, + SIMPLESHOP_FATALERRSTR + ); + break; + } + }else{ + NPC_SimpleShopFillItem( meindex, npcarg ); + getStringFromIndexWithDelim(npcarg,"|",THANKYOUTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + + } + break; + case 's': + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX) != talker ){ + getStringFromIndexWithDelim( npcarg,"|", + ANOTHERPLAYERTOKEN, + token, sizeof(token)); + NPC_SimpleShopNormalWindow( meindex, talker, token ); + return; + } + if((ret=NPC_LimitBuyInShopProcessSellMsg( + msg,meindex,talker))<0){ + switch(ret){ + case -2: + getStringFromIndexWithDelim( npcarg,"|", + RAREITEMTOKEN, + token,sizeof(token)); + NPC_SimpleShopNormalWindow( meindex,talker,token); + break; + case -1: + default: + NPC_SimpleShopNormalWindow(meindex, talker, SIMPLESHOP_FATALERRSTR + ); + break; + } + }else{ + getStringFromIndexWithDelim(npcarg,"|",THANKYOUTOKEN, token, sizeof(token)); + NPC_SimpleShopNormalWindow(meindex,talker,token); + + } + break; + case 'e': + default: + CHAR_setWorkInt( meindex, CHAR_WORKSHOPCLIENTINDEX, -1 ); + break; + } + break; + } + case 'i': + if( CHAR_getWorkInt(meindex,CHAR_WORKSHOPCLIENTINDEX) + == talker ){ + NPC_SimpleShopOpenShopWindow( meindex, talker, npcarg ); + } + break; + default: + break; + } + } +} + + + + + +/* + * int meindex : Ҽindex + * int playerindex : ̼ëindex + * char *str : + */ +static void NPC_SimpleShopNormalWindow( int meindex, int playerindex, + char *str ) +{ + int fd; + int objindex; + char tmp[512], *name; + + objindex = CHAR_getWorkInt(meindex,CHAR_WORKOBJINDEX); + name = CHAR_getChar( meindex, CHAR_NAME ); + snprintf(tmp,sizeof(tmp),"W|%d|N|%s|123|%s", objindex, name, str ); + fd = getfdFromCharaIndex(playerindex); + if( fd == -1 ) return; + lssproto_TK_send(fd,-1,tmp,CHAR_COLORWHITE ); +} + +/* + * ¦ + * int charindex:ƽҷ¼̼͵ + * ߯Ի + */ +static int NPC_ShopWindowIndexToItemTableIndex( int charindex, + int shopwindowindex ) +{ + int i, counter; + + counter = 0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charindex); + for( i=CHAR_STARTITEMARRAY;i NPC_SIMPLESHOPMAXBUYPRICE ){ + return -2; + } + price *= NPC_Util_sellRate(playerindex); + + CHAR_AddGold( playerindex, price ); + + CHAR_sendStatusString( playerindex , "P"); + + id = ITEM_getInt(itemind,ITEM_ID); + { + LogItem( + CHAR_getChar( playerindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( playerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemind, +#else + ITEM_getInt( itemind, ITEM_ID ), /* ʧ ة į */ +#endif + "Sell", + CHAR_getInt( playerindex,CHAR_FLOOR), + CHAR_getInt( playerindex,CHAR_X ), + CHAR_getInt( playerindex,CHAR_Y ), + ITEM_getChar( itemind, ITEM_UNIQUECODE), + ITEM_getChar( itemind, ITEM_NAME), + ITEM_getInt( itemind, ITEM_ID) + ); + } + + if( ! NPC_Util_moveItemToChar( shopindex,itemind,TRUE ) ){ + return -1; + } + NPC_Util_RemoveItemByID(shopindex,id,FALSE); + return 1; +} + +static BOOL NPC_LimitBuyInShopProcessSellMsg(char *msg, + int shopindex, int playerindex ) +{ + int sellwindowindex, itemtableindex,itemind, id,i,buyokflag, setid; + int price, tmpgold; + char buf[BUFSIZ]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE], token[NPC_UTIL_GETARGSTR_LINEMAX]; + + if(!CHAR_CHECKINDEX(shopindex)||!CHAR_CHECKINDEX(playerindex)) + return -1; + if( !getStringFromIndexWithDelim( msg,"|",4,buf,sizeof(buf) )){ + return -1; + } + sellwindowindex = atoi(buf); + itemtableindex = sellwindowindex + CHAR_STARTITEMARRAY; + itemind = CHAR_getItemIndex(playerindex,itemtableindex ); + if( ! ITEM_CHECKINDEX(itemind) ) return -1; + id = ITEM_getInt(itemind,ITEM_ID); + NPC_Util_GetArgStr( shopindex, npcarg, sizeof(npcarg)); + getStringFromIndexWithDelim( npcarg, "|", BUYINITEMLISTTOKEN, token, sizeof( token) ); + buyokflag = FALSE; + for( i=1;getStringFromIndexWithDelim(token,",",i,buf,sizeof(buf)); i++){ + + char *tok1 = NULL; + char *tok2 = NULL; + int no1=0, no2=0; + tok1 = strtok( buf, "-" ); + tok2 = strtok( NULL, "-" ); + + setid = atoi(buf); + + if( tok1 == NULL || tok2 == NULL ){ + if( setid == 0 ) return -2; + if( setid == id ) buyokflag = TRUE; + } else { + no1 = atoi( tok1 ); + no2 = atoi( tok2 ); + if( no1 <= id && id <= no2 ){ + buyokflag = TRUE; + } + } + } + if( buyokflag == FALSE ) return -2; + price = ITEM_getInt( itemind, ITEM_COST ); + price *= NPC_Util_sellRate(playerindex); + + CHAR_AddGold( playerindex, price ); + + CHAR_sendStatusString( playerindex , "P"); + if( ! NPC_Util_moveItemToChar( shopindex,itemind,TRUE ) ){ + return -1; + } + + { + LogItem( + CHAR_getChar( playerindex, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( playerindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemind, +#else + ITEM_getInt( itemind, ITEM_ID ), /* ʧ ة į */ +#endif + "Sell", + CHAR_getInt( playerindex,CHAR_FLOOR), + CHAR_getInt( playerindex,CHAR_X ), + CHAR_getInt( playerindex,CHAR_Y ), + ITEM_getChar( itemind, ITEM_UNIQUECODE), + ITEM_getChar( itemind, ITEM_NAME), + ITEM_getInt( itemind, ITEM_ID) + ); + } + + NPC_Util_RemoveItemByID(shopindex,id,FALSE); + + return 1; + +} + +/* + */ +static int NPC_SimpleShopGetItemNum( int meindex ) +{ + int counter, i; + + counter = 0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(meindex); + for( i=CHAR_STARTITEMARRAY;i=2 ){ /* ʿ */ + NPC_Util_RemoveItemByID(meindex,itemid,FALSE); + } + }else{ + break; + } + } + + /* ͹ľر */ + //NPC_SimpleShopSetLeakLevel( meindex ); + + return TRUE; +} + + +/* + */ +BOOL NPC_SimpleShopInit( int meindex ) +{ + unsigned int mlevel; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + + int createindex = CHAR_getInt( meindex, CHAR_NPCCREATEINDEX ); + +/* print("shopinit start\n" );*/ + if( NPC_CHECKCREATEINDEX(createindex) ){ + NPC_create[createindex].intdata[NPC_CREATETIME] = -1; + } + + CHAR_setInt( meindex , CHAR_HP , 0 ); + CHAR_setInt( meindex , CHAR_MP , 0 ); + CHAR_setInt( meindex , CHAR_MAXMP , 0 ); + CHAR_setInt( meindex , CHAR_STR , 0 ); + CHAR_setInt( meindex , CHAR_TOUGH, 0 ); + CHAR_setInt( meindex , CHAR_LV , 0 ); + mlevel = ((100<<16)|(100<<0)); /* 2 弰 + Ʊ2 弰 */ + CHAR_setInt( meindex, CHAR_MERCHANTLEVEL, mlevel ); + + CHAR_setWorkInt( meindex, CHAR_WORKSHOPCLIENTINDEX, -1 ); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPESHOP ); + CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + + NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)); + + if( ! NPC_SimpleShopFillItem( meindex,npcarg ) ){ + print( "SHOP INIT ERROR: npcarg=%s\n", npcarg ); + return FALSE; + } + +/* print("shopinit end\n" );*/ + + + return TRUE; +} + +/* + * npcargȳ𻧼ͼ + * ϱз,Իʷֽ,ʷֽئ + * + * ¦ + * ߯Ի + * ئTRUE, ئئFALSE + */ +static BOOL NPC_SimpleShopOpenShopOrNot( char *msg, char *openshopstr ) +{ + int i; + char buf[256]; + + i=1; + while(getStringFromIndexWithDelim(openshopstr,",",i,buf,sizeof(buf))){ + if( strstr( msg, buf ) ) return TRUE; + i++; + } + return FALSE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_storyteller.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_storyteller.c new file mode 100644 index 0000000..d845fc9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_storyteller.c @@ -0,0 +1,17 @@ +#include "version.h" +#include "char.h" + +BOOL NPC_StoryTellerInit( int meindex ) +{ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPESTORYTELLER ); + CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 ); + CHAR_setFlg( meindex , CHAR_ISOVERED , 0 ); + + return TRUE; +} + + +void NPC_StoryTellerTalked( int meindex , int talker , char *msg , int col ) +{ + +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_sysinfo.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_sysinfo.c new file mode 100644 index 0000000..a328609 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_sysinfo.c @@ -0,0 +1,840 @@ +#include "version.h" +#include +#include "char.h" +#include "char_event.h" +#include "object.h" +#include "handletime.h" +#include "magic.h" +#include "npcutil.h" +#include "char_data.h" +#include "chatmagic.h" +#include "net.h" +#include "configfile.h" +#include "npcgen.h" + +/* +--------------------------------------------------------------------- +sysinfo By Kawata +--------------------------------------------------------------------- +*/ + +#define NPC_SYSINFO_MSGMAX 21 + +#define NPC_SYSINFO_PASSWD_DEFAULT "longzoro" + +#define NPC_SYSINFO_TIMELIMIT_DEFAULT 120 + +#define NPC_SYSINFO_SHUTDOWNLIMIT_DEFAULT 5 + +#define NPC_SYSINFO_SHUTDOWN_MSG "ٹ %d ᣬʼserverϵͳά" + +#define NPC_SYSINFO_SHUTDOWN_MSG_COMP "serverѹرա" +enum { + CHAR_WORK_MODE = CHAR_NPCWORKINT1, + CHAR_WORK_TIME = CHAR_NPCWORKINT2, + CHAR_WORK_TIMELIMIT = CHAR_NPCWORKINT3, + CHAR_WORK_SHUTDOWNTIME = CHAR_NPCWORKINT4, + CHAR_WORK_SHUTDOWNLIMIT = CHAR_NPCWORKINT5, + CHAR_WORK_SHUTDOWNDSPTIME = CHAR_NPCWORKINT6, + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT7, + CHAR_WORK_PLAYER = CHAR_NPCWORKINT8, +}; + +enum { + CHAR_WORKCHAR_PASSWD = CHAR_NPCWORKCHAR1, +}; +typedef struct { + char msg[16]; +}CMD_MSG; +CMD_MSG cmd_msg[] = { + { "startinfo"}, {"endinfo"}, {"help"}, + {"player"}, {"list"}, {"sendno"}, + {"sendmsg"}, {"shutdown"}, {"msgcol"}, + {"sysinfo"}, {"info"}, + { "allowaccept" } , { "denyaccept" } , + { "closeallsockets" }, + { "allnosee" }, + { "allnobody" }, + { "movenum" }, + { "bornnum" }, + { "enemystate" }, + { "setwalktime"},{ "setcatime" },{"setcdtime"}, + { "setoneloop"}, + { "titlerestart"}, + { "setsaacwrite"}, { "setsaacread"}, +}; +enum{ + NPC_SYSINFO_MSG_STARTINFO, + NPC_SYSINFO_MSG_ENDINFO, + NPC_SYSINFO_MSG_HELP, + NPC_SYSINFO_MSG_PLAYER, + NPC_SYSINFO_MSG_LIST, + NPC_SYSINFO_MSG_SENDNO, + NPC_SYSINFO_MSG_SENDMSG, + NPC_SYSINFO_MSG_SHUTDOWN, + NPC_SYSINFO_MSG_MSGCOL, + NPC_SYSINFO_MSG_SYSINFO, + NPC_SYSINFO_MSG_INFO, + NPC_SYSINFO_MSG_ALLOWACCEPT, + NPC_SYSINFO_MSG_DENYACCEPT, + NPC_SYSINFO_MSG_CLOSEALLSOCKETS, + + /* Ȭܰ */ + NPC_SYSINFO_ALL_NOSEE, + NPC_SYSINFO_ALL_NOBODY, + NPC_SYSINFO_MOVE_NUM, + NPC_SYSINFO_BORN_NUM, + NPC_SYSINFO_ENEMY_STATE, + NPC_SYSINFO_SETWALKTIME, + NPC_SYSINFO_SETCATIME, + NPC_SYSINFO_SETCDTIME, + NPC_SYSINFO_SETONELOOP, + NPC_SYSINFO_TITLERESTART, + NPC_SYSINFO_SETSAACWRITE, + NPC_SYSINFO_SETSAACREAD, + + NPC_SYSINFO_MSG_NUM, +}; + +typedef struct { + char arg[32]; + char defMsg[128]; +}NPC_Sysinfo_Msg; + +static NPC_Sysinfo_Msg msgtable[] = { + { "def_msg", "ӵкȫ˵" }, + { "shutdown_msg", "ڿʼҪserverϵͳά뾡logout"}, +}; +enum{ + NPC_SYSINFO_ARG_DEF_MSG, + NPC_SYSINFO_ARG_SHUTDOWN_MSG, +}; + + +static void NPC_Sysinfo_SendMsg( int meindex, int pindex, int tblnum); +static char *NPC_Sysinfo_GetMsg( int meindex, char *msgindexstr, + char *out,int outlen, int num ); +static void NPC_Sysinfo_SendMsgToAll( int meindex, char *msg); +static void NPC_Sysinfo_Msg_EndInfo( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_Help( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_Player( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_List( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_SendNo( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_SendMsg( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_Shutdown( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Msg_Msgcol( int meindex, int tindex, char *msg); + +/* Ȭܰ */ +static void NPC_Sysinfo_All_NoBody( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_All_NoSee( int meindex, int tindex, char *msg); + +static void NPC_Sysinfo_Move_Num( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Born_Num( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_Enemy_State( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetWalkTime( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetCATime( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetCDTime( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetOneloop( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_TitleRestart( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetSaacwrite( int meindex, int tindex, char *msg); +static void NPC_Sysinfo_SetSaacread( int meindex, int tindex, char *msg); + +static void NPC_Sysinfo_Msg_allowAccept(int meindex, int tindex, char*msg) +{ + SERVSTATE_SetAcceptMore( 1 ); + CHAR_talkToCli( tindex, meindex, "allowaccept OK.", CHAR_COLORYELLOW); +} +static void NPC_Sysinfo_Msg_denyAccept(int meindex, int tindex, char*msg) +{ + SERVSTATE_SetAcceptMore( 0 ); + CHAR_talkToCli( tindex, meindex, "denyaccept OK.", CHAR_COLORYELLOW); +} +static void NPC_Sysinfo_Msg_closeallsockets(int meindex, int tindex, + char*msg) +{ + CHAR_talkToCli( tindex, meindex, "closeallsockets OK.", CHAR_COLORYELLOW); + closeAllConnectionandSaveData(); +} +static void NPC_Sysinfo_Msg_Sysinfo(int meindex, int tindex, char*msg) +{ + CHAR_CHAT_DEBUG_sysinfo( tindex, msg); +} +static void NPC_Sysinfo_Msg_Info(int meindex, int tindex, char*msg) +{ + CHAR_CHAT_DEBUG_info( tindex, msg); +} + + +typedef void (*FUNC)(int,int,char *); +static FUNC functbl[] = { + NULL, + NPC_Sysinfo_Msg_EndInfo, + NPC_Sysinfo_Msg_Help, + NPC_Sysinfo_Msg_Player, + NPC_Sysinfo_Msg_List, + NPC_Sysinfo_Msg_SendNo, + NPC_Sysinfo_Msg_SendMsg, + NPC_Sysinfo_Msg_Shutdown, + NPC_Sysinfo_Msg_Msgcol, + NPC_Sysinfo_Msg_Sysinfo, + NPC_Sysinfo_Msg_Info, + NPC_Sysinfo_Msg_allowAccept, + NPC_Sysinfo_Msg_denyAccept, + NPC_Sysinfo_Msg_closeallsockets, + /* Ȭܰ */ + NPC_Sysinfo_All_NoSee, + NPC_Sysinfo_All_NoBody, + NPC_Sysinfo_Move_Num, + NPC_Sysinfo_Born_Num, + NPC_Sysinfo_Enemy_State, + NPC_Sysinfo_SetWalkTime, + NPC_Sysinfo_SetCATime, + NPC_Sysinfo_SetCDTime, + NPC_Sysinfo_SetOneloop, + NPC_Sysinfo_TitleRestart, + NPC_Sysinfo_SetSaacwrite, + NPC_Sysinfo_SetSaacread, + +}; + +/********************************* +*********************************/ +BOOL NPC_SysinfoInit( int meindex ) +{ + int tmp; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff[128]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + + CHAR_setWorkInt( meindex, CHAR_WORK_MODE, 0); + + /* ɵ */ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "passwd", buff, sizeof( buff)) == NULL) + { + strcpy( buff, NPC_SYSINFO_PASSWD_DEFAULT); + } + CHAR_setWorkChar( meindex, CHAR_WORKCHAR_PASSWD, buff); + + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "time"); + if( tmp == -1 ) tmp = NPC_SYSINFO_TIMELIMIT_DEFAULT; + CHAR_setWorkInt( meindex, CHAR_WORK_TIMELIMIT, tmp); + + tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "msg_col"); + if( tmp < CHAR_COLORRED || tmp > CHAR_COLORWHITE ) + tmp = CHAR_COLORYELLOW; + CHAR_setWorkInt( meindex, CHAR_WORK_MSGCOLOR, tmp); + + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER, -1); + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNTIME, 0); + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNDSPTIME, 0); + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TYPEOTHERNPC); + CHAR_setFlg( meindex, CHAR_ISATTACKED, 0); + + return TRUE; +} + +/********************************* +**********************************/ +void NPC_SysinfoLoop( int meindex ) +{ + int shuttime; + if( CHAR_getWorkInt( meindex, CHAR_WORK_MODE) == 1) { + int oldtime; + /* ë׻ */ + oldtime = CHAR_getWorkInt( meindex, CHAR_WORK_TIME); + /* ƥɧƹ */ + if( NowTime.tv_sec - oldtime > + CHAR_getWorkInt( meindex, CHAR_WORK_TIMELIMIT)) + { + CHAR_setWorkInt( meindex, CHAR_WORK_MODE, 0); + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER, -1); + } + } + shuttime = CHAR_getWorkInt( meindex, CHAR_WORK_SHUTDOWNTIME); + /* shutdown */ + if( shuttime > 0 ) { + int diff,limit,hun; + + diff = NowTime.tv_sec - shuttime; + limit = CHAR_getWorkInt( meindex, CHAR_WORK_SHUTDOWNLIMIT); + hun = limit - (diff/60); + /* 嶪 */ + if( hun != CHAR_getWorkInt( meindex, CHAR_WORK_SHUTDOWNDSPTIME)){ + char buff[256]; + if( hun != 0 ) { + snprintf( buff, sizeof(buff), NPC_SYSINFO_SHUTDOWN_MSG, hun); + } + else { + strcpy( buff, NPC_SYSINFO_SHUTDOWN_MSG_COMP); + } + NPC_Sysinfo_SendMsgToAll( meindex, buff); + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNDSPTIME, hun); + } + if( hun == 0) { + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNDSPTIME,0); + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNLIMIT,0); + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNTIME,0); + } + } +} +/********************************* +**********************************/ +void NPC_SysinfoTalked( int meindex, int tindex, char *msg, int color) +{ + char *msgwk; + char *buff; + int len; + int msgno; + + len = strlen( msg)+1; + msgwk = calloc( 1, sizeof(char)*len); + buff = calloc( 1, sizeof(char)*len); + strcpy( msgwk, msg); + /* ʸë继 */ + deleteSequentChar( msgwk, " "); + if( CHAR_getWorkInt( meindex, CHAR_WORK_MODE) == 0 ) { + msgno = 0; + if( strncmp( msgwk, cmd_msg[NPC_SYSINFO_MSG_STARTINFO].msg, + strlen( cmd_msg[NPC_SYSINFO_MSG_STARTINFO].msg)) == 0) + { + if( getStringFromIndexWithDelim( msgwk, " ", 2, buff, len) + == TRUE ) + { + if( strcmp( buff, CHAR_getWorkChar( meindex, CHAR_WORKCHAR_PASSWD)) + == 0 ) + { + CHAR_setWorkInt( meindex, CHAR_WORK_MODE, 1); + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER, tindex); + CHAR_setWorkInt( meindex, CHAR_WORK_TIME, NowTime.tv_sec); + CHAR_talkToCli( tindex, meindex, + "Ƶָģʽhelp˵", + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + CHAR_talkToCli( tindex, meindex, + "enemystate ˽˵IJж", + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + + } + } + } + if( CHAR_getWorkInt( meindex, CHAR_WORK_MODE ) == 0 ) { + NPC_Sysinfo_SendMsg( meindex, tindex, NPC_SYSINFO_ARG_DEF_MSG); + } + }else { + if( tindex == CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER)) { + int i; + for( i = NPC_SYSINFO_MSG_ENDINFO; i < NPC_SYSINFO_MSG_NUM; i ++ ) { + if( strncmp( msgwk, cmd_msg[i].msg, strlen( cmd_msg[i].msg)) == 0) { + if( functbl[i] != NULL ) { + functbl[i]( meindex, tindex, msgwk); + } + break; + } + } + CHAR_setWorkInt( meindex, CHAR_WORK_TIME, NowTime.tv_sec); + } + else { + NPC_Sysinfo_SendMsg( meindex, tindex, NPC_SYSINFO_ARG_DEF_MSG); + } + } + free( msgwk); + free( buff); +} +/*------------------------------------------------------------------------ + * ɧƹ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_EndInfo( int meindex, int tindex, char *msg) +{ + CHAR_setWorkInt( meindex, CHAR_WORK_MODE, 0); + CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER, -1); + CHAR_talkToCli( tindex, meindex, + "Ƶһģʽ", + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + +} +/*------------------------------------------------------------------------ + * HELP + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_Help( int meindex, int tindex, char *msg) +{ + int i; + typedef struct { + char str[512]; + }SYSINFO_MSGWK; + SYSINFO_MSGWK msgwk[] = { + { "ָHELP"}, + { "help ѶϢ"}, + { "player ʾLOGIN"}, + { "list ѶϢһ"}, + { "send number number ֵָѶϢĺὫѶϢݴ͸ȫҡ"}, + { "sendmsg msgs msgsΪ봫͵ѶϢsend ֮һ񣬼ɽ֮Ÿȫҡ"}, + { "shutdown min min ֡"}, + { "msgcol col 趨͸ѶϢɫɫָred,green,yellow,blue,purple,cyan,white"}, + { "sysinfo ϵͳ״̬"}, + { "info ״̬"}, + { "endinfo ظͨ״̬"}, + { "denyaccept ޷CLIENT˵Ľ"}, + { "allowaccept CLIENT˵Ľ"}, + { "closeallsockets ǿCLIENTLOGOUTڲʵdenyaccept"}, + { "titlerestart ٴζȡƺ趨"}, + { "enemystate ˵NPC״"}, + { ""}, + }; + + for( i = 0; msgwk[i].str[0] != '\0'; i ++ ) { + CHAR_talkToCli( tindex, meindex, msgwk[i].str, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} +/*------------------------------------------------------------------------ + * ëƩ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_Player( int meindex, int tindex, char *msg) +{ + int i, cnt = 0; + int playernum=CHAR_getPlayerMaxNum(); + char buff[64]; + for( i=0 ; i=1 && num < NPC_SYSINFO_MSGMAX ) { + if( NPC_Sysinfo_GetMsg( meindex, "sendno", msgbuf, + sizeof( msgbuf), num) != NULL ) + { + NPC_Sysinfo_SendMsgToAll( meindex, msgbuf); + } + } + } +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_SendMsg( int meindex, int tindex, char *msg) +{ + char buff[512]; + + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + NPC_Sysinfo_SendMsgToAll( meindex, buff); + } +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_Msgcol( int meindex, int tindex, char *msg) +{ + char buff[64]; + typedef struct { + int color; + char str[10]; + }SYSINFO_COLSET; + SYSINFO_COLSET colset[] = { + { 249, "red"}, + { 250, "green"}, + { 251, "yellow"}, + { 252, "blue"}, + { 253, "purple"}, + { 254, "cyan"}, + { 255, "white"}, + }; + + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + int i; + for( i = 0; i < 7; i ++ ) { + if( strstr( buff, colset[i].str) != NULL ) { + CHAR_setWorkInt( meindex, CHAR_WORK_MSGCOLOR, colset[i].color); + CHAR_talkToCli( tindex, meindex, "ѸıѶϢɫ", + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + break; + } + } + } +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static char *NPC_Sysinfo_GetMsg( int meindex, char *msgindexstr, + char *out,int outlen, int num ) +{ + + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char *work; + char *buff; + char *cret = NULL; + int worklen; + + worklen = strlen( msgindexstr)+3; + work = (char *)calloc( 1, worklen * sizeof( char)); + buff = (char *)calloc( 1, outlen * sizeof( char)); + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + snprintf( work, worklen, "%s%d", msgindexstr, num); + if( NPC_Util_GetStrFromStrWithDelim( argstr, work,buff, outlen) != NULL ) + { + strcpy( out, buff); + cret = out; + } + + free( work); + free( buff); + return( cret); +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_Msg_Shutdown( int meindex, int tindex, char *msg) +{ + char buff[10]; + int hun; + + NPC_Sysinfo_SendMsg( meindex, tindex, NPC_SYSINFO_ARG_SHUTDOWN_MSG); + /* ޱ */ + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNTIME, NowTime.tv_sec); + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + hun = atoi( buff); + if( hun <= 0 ) { + hun = NPC_SYSINFO_SHUTDOWNLIMIT_DEFAULT; + } + } + else { + hun = NPC_SYSINFO_SHUTDOWNLIMIT_DEFAULT; + } + + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNLIMIT, hun); + + CHAR_setWorkInt( meindex, CHAR_WORK_SHUTDOWNDSPTIME,0); +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_SendMsg( int meindex, int pindex, int tblnum) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff[128]; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + if( NPC_Util_GetStrFromStrWithDelim( argstr, msgtable[tblnum].arg,buff, sizeof( buff)) == NULL ) + { + strcpy( buff, msgtable[tblnum].defMsg); + } + if( buff[0] != '\0' ) { + CHAR_talkToCli( pindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} +/*------------------------------------------------------------------------ + *----------------------------------------------------------------------*/ +static void NPC_Sysinfo_SendMsgToAll( int meindex, char *msg) +{ + int i; + int playernum = CHAR_getPlayerMaxNum(); + + for( i = 0 ; i < playernum ; i++) { + if( CHAR_getCharUse(i) != FALSE ) { + CHAR_talkToCli( i, meindex, msg, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } + } +} + + + +/* ƽҷë NO_SEE ¾ */ +static void NPC_Sysinfo_All_NoSee( int meindex, int tindex, char *msg ){ + char buff[256]; + + buff[0] = buff[1] = 0; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + if( strncmp( buff, "on", strlen( buff ) ) == 0 ){ + all_nosee = 1; + snprintf( buff, sizeof( buff), "ѿall_nosee " ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else + if( strncmp( buff, "off", strlen( buff ) ) == 0 ){ + all_nosee = 0; + snprintf( buff, sizeof( buff), "ѹرall_nosee " ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } + }else + if( all_nosee == 0 ){ + snprintf( buff, sizeof( buff), "all_noseeرš" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "all_noseeš" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} + +/* ƽҷë NO_BODY ¾ */ +static void NPC_Sysinfo_All_NoBody( int meindex, int tindex, char *msg ){ + char buff[256]; + + buff[0] = buff[1] = 0; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + if( strncmp( buff, "on", strlen( buff ) ) == 0 ){ + all_nobody = 1; + snprintf( buff, sizeof( buff), "ѿall_nobody " ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else + if( strncmp( buff, "off", strlen( buff ) ) == 0 ){ + all_nobody = 0; + snprintf( buff, sizeof( buff), "ѹرall_nobody " ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } + }else + if( all_nobody == 0 ){ + snprintf( buff, sizeof( buff), "all_nobody رš" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "all_nobody š" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} + + +static void NPC_Sysinfo_Move_Num( int meindex, int tindex, char *msg ){ + char buff[256]; + int work; + buff[0] = buff[1] = 0; + + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + work = atoi( buff ); + if( work <= 0 ) { + work = 1000; /* */ + } + EnemyMoveNum = work; + snprintf( buff, sizeof( buff), "õͬʱ%d", + EnemyMoveNum ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "ڵͬʱڽ%d", + EnemyMoveNum ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} + + + +static void NPC_Sysinfo_Born_Num( int meindex, int tindex, char *msg ){ + char buff[256]; + int work; + buff[0] = buff[1] = 0; + + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) + { + work = atoi( buff ); + if( work <= 0 ) { + work = 2; /* */ + } + one_loop_born = work; + snprintf( buff, sizeof( buff), "ͬʱɳߵ%d", + one_loop_born ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "ڵͬʱɳߵ%d", + one_loop_born ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } +} + + + +static void NPC_Sysinfo_Enemy_State( int meindex, int tindex, char *msg ){ + char buff[256]; + + if( all_nobody == 0 ){ + snprintf( buff, sizeof( buff), "allnobody رš" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "allnobody š" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } + if( all_nosee == 0 ){ + snprintf( buff, sizeof( buff), "allnosee رš" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + }else{ + snprintf( buff, sizeof( buff), "allnosee š" ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + } + snprintf( buff, sizeof( buff), + "bornnum ڵͬʱɳߵ%d", + one_loop_born ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + + snprintf( buff, sizeof( buff), + "movenum ڵͬʱڽ%d", + EnemyMoveNum ); + CHAR_talkToCli( tindex, meindex, buff, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + + +} +static void NPC_Sysinfo_SetWalkTime( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setWalksendinterval( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"WalkInterval = %d ",getWalksendinterval()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); + +} +static void NPC_Sysinfo_SetCATime( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setCAsendinterval_ms( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"CAsendInterval = %d ", + getCAsendinterval_ms()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} +static void NPC_Sysinfo_SetCDTime( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setCDsendinterval_ms( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"CDsendInterval = %d ", + getCDsendinterval_ms()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} +static void NPC_Sysinfo_SetOneloop( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setOnelooptime_ms( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"Onelooptime = %d ", + getOnelooptime_ms()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} +static void NPC_Sysinfo_TitleRestart( int meindex, int tindex, char *msg) +{ + int rc; + char msgbuf[256]; + + rc = TITLE_reinitTitleName(); + if( rc) { + snprintf( msgbuf, sizeof(msgbuf),"ȡϡ" ); + } + else { + snprintf( msgbuf, sizeof(msgbuf),"ERROR" ); + } + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} + + +static void NPC_Sysinfo_SetSaacwrite( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setSaacwritenum( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"Saacwritenum = %d ",getSaacwritenum()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} +static void NPC_Sysinfo_SetSaacread( int meindex, int tindex, char *msg) +{ + int interval; + char msgbuf[256]; + char buff[256]; + if( getStringFromIndexWithDelim( msg, " ", 2, buff, sizeof( buff)) == TRUE ) { + interval = atoi( buff); + if( interval > 0 ) { + setSaacreadnum( (unsigned)interval); + } + } + snprintf( msgbuf, sizeof(msgbuf),"Saacreadnum = %d ",getSaacreadnum()); + CHAR_talkToCli( tindex, meindex, msgbuf, + CHAR_getWorkInt( meindex, CHAR_WORK_MSGCOLOR)); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_timeman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_timeman.c new file mode 100644 index 0000000..2051278 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_timeman.c @@ -0,0 +1,226 @@ +#include "version.h" +#include +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "npcutil.h" +#include "npc_oldman.h" +#include "title.h" +#include "char_data.h" +#include "readmap.h" +#include "lssproto_serv.h" +#include "log.h" +#include "handletime.h" + + + + + +enum { + E_INT_GRAPHIC = CHAR_NPCWORKINT1, /* 󡼰 */ + E_INT_GRAPHIC2 = CHAR_NPCWORKINT2, /* */ + E_INT_BORN = CHAR_NPCWORKINT3, /* źϷ */ + E_INT_DEAD = CHAR_NPCWORKINT4, /* */ + E_INT_MODE = CHAR_NPCWORKINT5, /* ػƹ */ + E_INT_NOWGRAPHIC = CHAR_NPCWORKINT6, /* ػ°ū͹ϼ */ + +}; + + +typedef struct { + char arg[32]; + int born; + int dead; +}NPC_TimeMan; + + +#define YOAKE 700 +#define NICHIBOTU 300 +#define SHOUGO 125 +#define YONAKA 500 + +static NPC_TimeMan TimeTble[] = { + + {"ALLNIGHT", NICHIBOTU+1, YOAKE}, /* 뻯ئ */ + {"ALLNOON", YOAKE+1, NICHIBOTU},/* 뻯 */ + {"AM", YONAKA+1, SHOUGO}, /* AM ݼ */ + {"PM", SHOUGO+1, YONAKA}, /* PM ݼ */ + {"FORE", YOAKE+1, SHOUGO}, /* ƥտڸƥ */ + {"AFTER", SHOUGO+1, NICHIBOTU},/* ڸ ͸ƥ */ + {"EVNING", NICHIBOTU+1, YONAKA}, /* ƥީ ƥ */ + {"MORNING", YONAKA+1, YOAKE}, /* ީ ƥ */ + {"FREE", 0, 1024}, +}; + + + + +BOOL NPC_TimeManInit( int meindex ) +{ + + int i=0; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[32]; + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPETOWNPEOPLE ); + if( NPC_Util_GetStrFromStrWithDelim( argstr, "change_no", buf, sizeof( buf)) != NULL ){ + if(strstr(buf,"CLS")!=NULL){ + CHAR_setWorkInt( meindex,E_INT_GRAPHIC2, 9999 ); + }else{ + CHAR_setWorkInt( meindex,E_INT_GRAPHIC2, atoi(buf) ); + } + }else{ + CHAR_setWorkInt( meindex,E_INT_GRAPHIC2, 9999 ); + } + + CHAR_setWorkInt( meindex, E_INT_GRAPHIC, CHAR_getInt( meindex, CHAR_BASEIMAGENUMBER) ); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "time", buf, sizeof( buf)) != NULL ){ + for(i=0 ; i<9 ; i++){ + if(strstr(buf,TimeTble[i].arg) != NULL){ + CHAR_setWorkInt( meindex, E_INT_BORN, TimeTble[i].born); + CHAR_setWorkInt( meindex, E_INT_DEAD, TimeTble[i].dead); + return TRUE; + } + } + } + + return FALSE; + +} + + +void NPC_TimeManTalked( int meindex , int talkerindex , char *msg ,int color ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[512]; + char buf[512]; + int tokennum=0; + int i; + + + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2)==FALSE){ + if( NPC_Util_CharDistance( talkerindex ,meindex ) > 1) return; + } + + if(CHAR_getInt(meindex,CHAR_BASEIMAGENUMBER)==9999){ + /*--ƹ--*/ + return; + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return; + } + + + if( CHAR_getInt(talkerindex,CHAR_WHICHTYPE) != CHAR_TYPEPLAYER )return; + + if( NPC_Util_charIsInFrontOfChar( talkerindex, meindex, 3 ) ==FALSE) return; + + + + + if(CHAR_getWorkInt(meindex,E_INT_MODE)==0){ + /*--ë߯ */ + NPC_Util_GetStrFromStrWithDelim(argstr,"main_msg",buf,sizeof( buf) ); + + }else{ + NPC_Util_GetStrFromStrWithDelim(argstr,"change_msg",buf,sizeof( buf) ); + } + + tokennum = 1; + /* Ѩƥľͼϳؤ¾ */ + for( i=0;buf[i]!='\0';i++ ){ + if( buf[i] == ',' ) tokennum++; + } + + getStringFromIndexWithDelim( buf,",", rand()%tokennum+1,token, sizeof(token)); + /*----*/ + CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORWHITE ); + + +} + +/** ԻϾڳľ*/ +void NPC_TimeManWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ) +{ + int meindex=0; + int index; + LSTIME nowlstime; + int born; + int dead; + + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) return; + index = OBJECT_getIndex( objindex); + + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return; + + meindex = OBJECT_getIndex( meobjindex); + born = CHAR_getWorkInt( meindex , E_INT_BORN ); + dead = CHAR_getWorkInt( meindex , E_INT_DEAD ); + +// print("now_hour=%d",nowlstime.hour); + + /* ëέë裻 */ + if(born < dead){ + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + if( (born < nowlstime.hour) && (dead > nowlstime.hour) ){ + if(CHAR_getWorkInt(meindex,E_INT_NOWGRAPHIC) + ==CHAR_getWorkInt( meindex, E_INT_GRAPHIC)) return; + + CHAR_setInt(meindex,CHAR_BASEIMAGENUMBER, + CHAR_getWorkInt( meindex, E_INT_GRAPHIC)); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + CHAR_setWorkInt(meindex,E_INT_MODE,0); + CHAR_setWorkInt(meindex,E_INT_NOWGRAPHIC, + CHAR_getInt(meindex,CHAR_BASEIMAGENUMBER)); + }else{ + /*---*/ + if(CHAR_getWorkInt(meindex,E_INT_NOWGRAPHIC) + ==CHAR_getWorkInt( meindex, E_INT_GRAPHIC2)) return; + + CHAR_setInt(meindex,CHAR_BASEIMAGENUMBER, + CHAR_getWorkInt( meindex, E_INT_GRAPHIC2)); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + CHAR_setWorkInt(meindex,E_INT_MODE,1); + CHAR_setWorkInt(meindex,E_INT_NOWGRAPHIC, + CHAR_getInt(meindex,CHAR_BASEIMAGENUMBER)); + + } + }else{ + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + if( (born < nowlstime.hour && 1024 > nowlstime.hour) + || ( 0 < nowlstime.hour && dead > nowlstime.hour) + ){ + if(CHAR_getWorkInt(meindex,E_INT_NOWGRAPHIC) + ==CHAR_getWorkInt( meindex, E_INT_GRAPHIC)) return; + + CHAR_setInt(meindex,CHAR_BASEIMAGENUMBER, + CHAR_getWorkInt( meindex, E_INT_GRAPHIC)); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + CHAR_setWorkInt(meindex,E_INT_MODE,0); + CHAR_setWorkInt(meindex,E_INT_NOWGRAPHIC, + CHAR_getInt(meindex,CHAR_BASEIMAGENUMBER)); + }else{ + if(CHAR_getWorkInt(meindex,E_INT_NOWGRAPHIC) + ==CHAR_getWorkInt( meindex, E_INT_GRAPHIC2)) return; + + CHAR_setInt(meindex,CHAR_BASEIMAGENUMBER, + CHAR_getWorkInt( meindex, E_INT_GRAPHIC2)); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + CHAR_setWorkInt(meindex,E_INT_MODE,1); + CHAR_setWorkInt(meindex,E_INT_NOWGRAPHIC, + CHAR_getInt(meindex,CHAR_BASEIMAGENUMBER)); + } + } + +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_townpeople.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_townpeople.c new file mode 100644 index 0000000..ea27dcc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_townpeople.c @@ -0,0 +1,61 @@ +#include "version.h" +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "util.h" +#include "handletime.h" +#include "anim_tbl.h" +#include "npc_door.h" +#include "lssproto_serv.h" +#include "npcutil.h" + + +/* + * м̫ by nakamura + * + * + */ + +/* + */ +void NPC_TownPeopleTalked( int index, int talker, char *msg, int color ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE], token[NPC_UTIL_GETARGSTR_LINEMAX]; + int i, tokennum; + + + if( CHAR_getInt(talker,CHAR_WHICHTYPE) == CHAR_TYPEPLAYER + && NPC_Util_charIsInFrontOfChar( talker, index, 3 ) ){ + + NPC_Util_GetArgStr( index, arg, sizeof( arg)); + + tokennum = 1; + /* Ѩƥľͼϳؤ¾ */ + for( i=0;arg[i]!='\0';i++ ){ + if( arg[i] == ',' ) tokennum++; + } + + getStringFromIndexWithDelim( arg,",", + rand()%tokennum+1,token, sizeof(token)); + + CHAR_talkToCli( talker, index, token, CHAR_COLORWHITE ); + } +} + +/* + */ +BOOL NPC_TownPeopleInit( int meindex ) +{ + + //CHAR_setInt( meindex , CHAR_HP , 0 ); + //CHAR_setInt( meindex , CHAR_MP , 0 ); + //CHAR_setInt( meindex , CHAR_MAXMP , 0 ); + //CHAR_setInt( meindex , CHAR_STR , 0 ); + //CHAR_setInt( meindex , CHAR_TOUGH, 0 ); + //CHAR_setInt( meindex , CHAR_LV , 0 ); + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPETOWNPEOPLE ); + //CHAR_setFlg( meindex , CHAR_ISOVERED , 1 ); + + return TRUE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transerman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transerman.c new file mode 100644 index 0000000..8e23da0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transerman.c @@ -0,0 +1,195 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_transerman.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" + +//صشøнڽ"ʦ" +#ifdef _TRANSER_MAN +enum { + WINDOW_START=1, + WINDOW_SELECT, + WINDOW_WARP, + WINDOW_END, +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +#define STANDBYTIME 50 + +static void NPC_TranserMan_selectWindow( int meindex, int toindex, int num,int select); +BOOL TranserMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token); + +BOOL NPC_TranserManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TRANSERMANS); + + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_TranserManTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } +#ifdef _ITEM_CHECKWARES + if( CHAR_CheckInItemForWares( talkerindex, 0) == FALSE ){ + CHAR_talkToCli( talkerindex, meindex, "ݴʦ涨ܷЯˣ", CHAR_COLORYELLOW); + return; + } +#endif +// Syu ADD Ŵʦж״̬ + if( CHAR_getWorkInt ( talkerindex , CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) + { + CHAR_talkToCli( talkerindex, meindex, "ݴʦ涨ܰе˴ͣ",CHAR_COLORYELLOW); + return; + } + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_TranserMan_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +void NPC_TranserManWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data) +{ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( seqno) { + case NPC_TRANSERMAN_START: + break; + case NPC_TRANSERMAN_SELECT: + NPC_TranserMan_selectWindow( meindex, talkerindex, WINDOW_SELECT, atoi( data)); + break; + case NPC_TRANSERMAN_WARP: + if( select == WINDOW_BUTTONTYPE_CANCEL ) + return; + NPC_TranserMan_selectWindow( meindex, talkerindex, WINDOW_WARP, atoi( data)); + break; + case NPC_TRANSERMAN_END: + break; + } + +} + +static void NPC_TranserMan_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + + switch( num) { + case WINDOW_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "START_MSG", token, sizeof( token) ) == NULL) { + print("TranserMan Get START_MSG ERROR !"); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, WINDOW_START); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_TRANSERMAN_SELECT; + break; + case WINDOW_SELECT: + if( TranserMan_GetMenuStr( meindex, toindex, npcarg, token) == FALSE ) { + print( "TranserMan GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_WARP: + if( ActionNpc_CheckMenuFree( meindex, toindex, npcarg, select) == FALSE ){ + memset( token, 0, sizeof( token)); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FAIL_MSG", token, sizeof( token) ) != NULL) { + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + } + } + return; + + case WINDOW_END: + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +BOOL TranserMan_GetMenuStr( int meindex, int toindex, char *npcarg, char *token) +{ + char buf1[1024], buf2[256], buf3[256]; + BOOL FINDS=FALSE; + int talkNo=1; + if( npcarg == NULL ) return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "MenuHead", buf1, sizeof( buf1) ) == NULL){ + print("TranserMan Get MenuHead ERROR!"); + return FALSE; + } + sprintf( token, "%s\n", buf1); + + while( getStringFromIndexWithDelim( npcarg,"}",talkNo, buf1, sizeof( buf1)) != FALSE ) { + talkNo++; + memset( buf2, 0, sizeof( buf2)); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "MenuStr", buf2, sizeof( buf2)) == NULL ) + continue; + FINDS = TRUE; + + sprintf( buf3, " %s\n", buf2); + strcat( token, buf3); + } + + return FINDS; +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transmigration.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transmigration.c new file mode 100644 index 0000000..ff94634 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_transmigration.c @@ -0,0 +1,1959 @@ +#include "version.h" +#include +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "enemy.h" +#include "log.h" +#include "battle.h" +#include "readmap.h" +#include "npc_transmigration.h" + +#include "configfile.h" + +#ifdef _PET_TRANS +#include "npc_pettransman.h" +#endif +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +static void NPC_Transmigration_selectWindow( int meindex, int toindex, int num); +static int NPC_TransmigrationCheck(int meindex, int talker); +BOOL NPC_TransmigrationAddPet(int meindex, int talker, int petid); +//Ѽ +int NPC_StartpointCheck(int meindex,int talker); +BOOL NPC_TransmigrationMain(int meindex, int toindex, char *buf); +BOOL NPC_TransmigrationDelPet(int meindex, int talker); +BOOL NPC_TransmigratiomWarp(int meindex, int toindex, char *buf); +void s_eventsetend( int charaindex, int shiftbit ); + +#ifdef _PET_TRANS +int Pet_Select; +#endif + +/********************************* +*********************************/ +BOOL NPC_TransmigrationInit( int meindex ) +{ + + /*--ƽҷ¼ëɬ--*/ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPETRANSMIGRATION ); + + return TRUE; + +} + +/********************************* +*********************************/ +void NPC_TransmigrationTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ +#ifdef _PET_TRANS + int i,petindex; +#endif + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + { + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; + } +// print("savepoot=%d",CHAR_getInt( talkerindex, CHAR_SAVEPOINT)); +// NPC_StartpointCheck( meindex, talkerindex); + + +//׷ж ת ת +#ifdef _PET_TRANS + int petNum = 0; + //(/) & Ʒ + for(i=0 ; i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talkerindex, i); + if( petindex == -1 ) + continue; + // ID ǷΪ׷ 1479 ID Ϊ718 + if( CHAR_getInt( petindex, CHAR_PETID) == 718 +#ifdef _PET_2TRANS + || CHAR_getInt( petindex, CHAR_PETID) == 401 +#endif + ){ + if( CHAR_getInt( talkerindex, CHAR_LV) < 80 ) { + CHAR_talkToCli( talkerindex, -1, "ĵȼС80,ûת裡", CHAR_COLORWHITE); + return; + }else if( CHAR_getInt( petindex, CHAR_LV) > 79 ){ + char szPet[512]; + CHAR_setCharPet( talkerindex, i, -1); + CHAR_endCharOneArray( petindex ); + snprintf( szPet, sizeof( szPet ), "K%d", i); + CHAR_sendStatusString( talkerindex, szPet ); + CHAR_talkToCli( talkerindex, -1, "ϷǷ׷", CHAR_COLORRED); + return; + }else if( CHAR_getInt( petindex, CHAR_LV) == 79 ) { + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( talkerindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( talkerindex, CHAR_NAME) )) { + CHAR_talkToCli( talkerindex, -1, "ϵ׷ţİ", CHAR_COLORWHITE); + return; + } + petNum ++; + } + } + } + + if( petNum > 1 ) { + CHAR_talkToCli( talkerindex, -1, "׷أ", CHAR_COLORWHITE); + return; + }else if( petNum == 1 ) { + CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); + NPC_PetTransMan_selectWindow( meindex, talkerindex,0,-1); + }else { +#endif + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT,1); + NPC_Transmigration_selectWindow( meindex, talkerindex, 0); +#ifdef _PET_TRANS + } +#endif + + //ԭת + //CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT,1); + //NPC_Transmigration_selectWindow( meindex, talkerindex, 0); + +} + + +static void NPC_Transmigration_selectWindow( int meindex, int toindex, int num) +{ + + char token[1024]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[2048]; + char buf2[512]; + char tmp[512]; + char s_tensei[64]; + int buttontype = 0; + int windowtype = 0; + int windowno = 0; + int tenseiNo = 1; + int fd = getfdFromCharaIndex( toindex); + int i = 1; + BOOL tenflg = FALSE; + char *elder[4] = {"samugiru","marinasu","jaja","karutarna"}; + int point; + int ten_no; + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("Tensei:GetArgStrErr"); + return; + } + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + tenseiNo = CHAR_getInt( toindex, CHAR_TRANSMIGRATION); + tenseiNo++; + if(CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT) >= 2){ + tenseiNo--; + } + + sprintf(s_tensei,"TENSEI:%d",tenseiNo); + + while(getStringFromIndexWithDelim( npcarg,"END",i,buf,sizeof( buf)) != FALSE){ + i++; + if(strstr(buf,s_tensei) != NULL) { + tenflg = TRUE; + break; + } + } + //ttom +// print("\nTrans meindex=%d,toindex=%d,num=%d",meindex,toindex,num); + //ttom + CONNECT_set_state_trans(fd,6); + //ttom end + + switch( num){ + case 0: + //ttom + //CONNECT_set_state_trans(fd,0); + //ttom end + ten_no = NPC_TransmigrationCheck(meindex, toindex); + if( +#ifdef _TRANS_6 +#ifdef _TRANS_7 + ten_no < 7 +#else + ten_no < 6 +#endif +#else + ten_no < 5 +#endif//_TRANS_6 + && ten_no >= 0){ + //ʧ + if(NPC_Util_GetStrFromStrWithDelim( buf,"startmsg", token,sizeof( token) ) == NULL) + { + print("startmsgErr"); + return; + } + buttontype = WINDOW_BUTTONTYPE_NEXT; + //ttom + CONNECT_set_state_trans(fd,0); + //ttom end + }else if( +#ifdef _TRANS_6 +#ifdef _TRANS_7 + ten_no == 7 +#else + ten_no == 6 +#endif +#else + ten_no == 5 +#endif//_TRANS_6 + ){ + //Ϸë֧ + if(NPC_Util_GetStrFromStrWithDelim( npcarg,"maxmsg", token,sizeof( token) ) == NULL) + { + print("maxmsgErr"); + return; + } + buttontype = WINDOW_BUTTONTYPE_OK; + }else{ + //ʧƻئ + if(NPC_Util_GetStrFromStrWithDelim( buf,"nonemsg", token,sizeof( token) ) == NULL) + { + print("nonemsgErr"); + return; + } + buttontype = WINDOW_BUTTONTYPE_OK; + + } + windowno = CHAR_WINDOWTYPE_TRANSMIGRATION_START; + + break; + + case 1: + if(NPC_Util_GetStrFromStrWithDelim( buf,"mainmsg", token,sizeof( token) ) == NULL) + { + print("mainmsgErr"); + return; + } + buttontype = WINDOW_BUTTONTYPE_OKCANCEL; + windowno = CHAR_WINDOWTYPE_TRANSMIGRATION_MAIN; + break; + + case 2: + // Robin 2001/03/05 Tensei Check + //if(!CHAR_getWorkInt(toindex,CHAR_TENSEICHECKED)) return; + + point = NPC_StartpointCheck( meindex, toindex); + if(point == -1) { + return; + } + + if(CHAR_getInt(toindex, CHAR_SKILLUPPOINT) > 0) { + lssproto_WN_send( fd, windowtype, WINDOW_BUTTONTYPE_CANCEL, -1,-1, + "ϵĵû꣬ҲΪת"); + return; + } + +#ifdef _NO_TRANS_ITEM + int itemMax = CheckCharMaxItem(toindex); + for( i = CHAR_STARTITEMARRAY ; i 2) { + return; + } + //ttom + //CONNECT_set_state_trans(fd,6); + //ttom end + datanum = atoi( data); + switch( seqno) { + case CHAR_WINDOWTYPE_TRANSMIGRATION_START: + if( select == WINDOW_BUTTONTYPE_NEXT) { + //ttom + if(CONNECT_get_state_trans(fd)==0){ } else return; + //ttom end + NPC_Transmigration_selectWindow( meindex, talkerindex,1); + //ttom + CONNECT_set_state_trans(fd,1); + //ttom end + + } + break; + + case CHAR_WINDOWTYPE_TRANSMIGRATION_MAIN: + if( select == WINDOW_BUTTONTYPE_OK) { +#ifdef _FIX_SUPERPERSON_STRANS + if( CHAR_getInt(talkerindex,CHAR_TRANSMIGRATION) == 5){ + if(NPC_EventCheckFlg( talkerindex, 63) == FALSE + || NPC_EventCheckFlg( talkerindex, 136) == FALSE + || NPC_EventCheckFlg( talkerindex, 175) == FALSE + || NPC_EventCheckFlg( talkerindex, 176) == FALSE){ + print("\nǷ6ת"); + return; + } + } +#endif + //ttom + if(CONNECT_get_state_trans(fd)==1){ } else return; + //ttom end + NPC_Transmigration_selectWindow( meindex, talkerindex, 2); + //ttom + CONNECT_set_state_trans(fd,2); + //ttom end + }else if(select == WINDOW_BUTTONTYPE_CANCEL) { + NPC_Transmigration_selectWindow( meindex, talkerindex, 3); + } + break; + + case CHAR_WINDOWTYPE_TRANSMIGRATION_END: + if( select == WINDOW_BUTTONTYPE_NEXT) { + //ttom + if(CONNECT_get_state_trans(fd)==2){ } else return; + //ttom end + NPC_Transmigration_selectWindow( meindex, talkerindex, 4); + //ttom + CONNECT_set_state_trans(fd,4); + //ttom end + }else if( select == WINDOW_BUTTONTYPE_OK) { + //ttom + if(CONNECT_get_state_trans(fd)==4){ } else return; + //ttom end + NPC_Transmigration_selectWindow( meindex, talkerindex, 5); + } + break; + +//ANDY_ADD 10/19 +#ifdef _PET_TRANS + + case CHAR_WINDOWTYPE_PETTRANS_START: //ʼԻ + if( select == WINDOW_BUTTONTYPE_NEXT) { + NPC_PetTransMan_selectWindow( meindex, talkerindex, 1, 0); + } + break; + + case CHAR_WINDOWTYPE_PETTRANS_SELECT: //Ƿóת + if( select == WINDOW_BUTTONTYPE_YES) { + NPC_PetTransMan_selectWindow( meindex, talkerindex, 2, 0); + }else { + NPC_PetTransMan_selectWindow( meindex, talkerindex, 5, 0); + } + break; + + case CHAR_WINDOWTYPE_PETTRANS_SELPET: //ѡ + if(select==WINDOW_BUTTONTYPE_CANCEL) { + NPC_PetTransMan_selectWindow( meindex, talkerindex, 5,-1 ); + }else { + Pet_Select = datanum; + NPC_PetTransMan_selectWindow( meindex, talkerindex, 3, datanum ); + } + break; + + case CHAR_WINDOWTYPE_PETTRANS_MAIN1: //ȷ ȷ/ȡ + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_PetTransMan_selectWindow( meindex, talkerindex, 4, Pet_Select); + }else { + NPC_PetTransMan_selectWindow( meindex, talkerindex, 5, -1); + } + break; + + case CHAR_WINDOWTYPE_PETTRANS_END: //ת + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + break; + +#endif + + } + + +} + +//************************************************************ +//************************************************************ +BOOL NPC_TransmigratiomWarp(int meindex, int toindex, char *buf) +{ + char buf2[512]; + char buf3[128]; + char buf4[64]; + int floor=0 , x = 0, y = 0; + int i = 1; + int ret; + + while(getStringFromIndexWithDelim( buf,",",i,buf2,sizeof( buf2)) + != FALSE) + { + i++; + if(strstr(buf2,"Warp") != NULL) + { + getStringFromIndexWithDelim( buf2 ,"=" ,2, buf3 ,sizeof(buf3)); + //׷ʧ + ret = getStringFromIndexWithDelim( buf3,".",1 ,buf4 ,sizeof( buf4)); + if(ret ==FALSE) return FALSE; + floor = atoi(buf4); + ret = getStringFromIndexWithDelim( buf3,".",2 ,buf4 ,sizeof( buf4)); + if(ret ==FALSE) return FALSE; + x = atoi(buf4); + ret = getStringFromIndexWithDelim( buf3,".",3 ,buf4 ,sizeof( buf4)); + if(ret ==FALSE) return FALSE; + y = atoi(buf4); + + } + } + + + //Ƽ + if( MAP_IsValidCoordinate( floor, x, y )== FALSE ){ + return FALSE; + } + + //ttom + /* + { + int tenseiNo; + tenseiNo=CHAR_getInt( toindex, CHAR_TRANSMIGRATION); + CHAR_setInt( toindex,CHAR_SKILLUPPOINT,tenseiNo*10); + print("\n the set the skillpoint %d",tenseiNo*10); + CHAR_sendStatusString( toindex , "P"); + } + */ + //ttom + + // + CHAR_warpToSpecificPoint(toindex, floor, x, y); + + return TRUE; + +} + +//************************************************************ +// +// ߡة׻ +// ࡰѨϵ +// ᡰҳ +// ⡰л +// Ԩࡰ޷¡ +//************************************************************ +int NPC_StartpointCheck(int meindex,int talker) +{ + int point; + int shift = 0; + point = CHAR_getInt( talker, CHAR_SAVEPOINT); + for(shift = 0; shift < 4 ;shift++){ + if( (point & ( 1<< shift)) == ( 1<< shift)) { + return shift; + } + } + return -1; +} + +//******************************************************** +// +// +// +//******************************************************** +static int NPC_TransmigrationCheck(int meindex, int talker) +{ + // Ϸ + //ìﻥ߶ + //㹴ìδȻ³ + int i,j,k=0; + int ch_no[4] = {39,40,42,46}; + int petindex; + int num; +// int petid[4] = {1, 2, 3, 4}; //ʸ ë϶ + int petid[4] = {693, 694, 695, 696}; //ʸ ë϶ +// int petidfinal[4] = {11, 12, 13, 14}; //ʸ ë϶ + int petidfinal[4] = {693, 694, 695, 696}; //ʸ ë϶ + + // Robin 2001/03/05 + //CHAR_setWorkInt(talker,CHAR_TENSEICHECKED,FALSE); +#ifdef _TRANS_6 +#ifdef _TRANS_7 + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) >= 7){ + return 7; + } +#else + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) >= 6){ + return 6; + } +#endif +#else + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) >= 5){ + return 5; + } +#endif + + //ìﻥ߶ + if(CHAR_getInt( talker, CHAR_LV) < 80) return -1; + + //ì׷º +#ifdef _TRANS_6 +#ifdef _TRANS_7 + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) < 7){ +#else + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) < 6){ +#endif +#else + if(CHAR_getInt( talker, CHAR_TRANSMIGRATION) < 5){ +#endif + for(i = 0; i < 4 ;i++) + if(NPC_EventCheckFlg( talker, ch_no[i] ) == FALSE) return -1; + } + + num = CHAR_getInt(talker, CHAR_TRANSMIGRATION); + + if(num < 4 ){ + //϶ʸëȻ¾ʸ + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) continue; + //ttom + //print("petid=%d ",CHAR_getInt( petindex, CHAR_PETID)); + if(CHAR_getInt( petindex, CHAR_PETID) != petid[num]) continue; + +// if(CHAR_getInt( petindex, CHAR_LV) < PETLEVEL) continue; + break; + } + if(i == CHAR_MAXPETHAVE) return -1; + }else +#ifdef _TRANS_6 + if( num == 4 ) +#endif + { + for(j = 0; j < 4 ;j++){ + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) continue; + // print("petid=%d ",CHAR_getInt( petindex, CHAR_PETID)); + if(CHAR_getInt( petindex, CHAR_PETID) != petidfinal[j]) continue; + k++; + break; + } + } + if(k < 4) return -1; + } +#ifdef _TRANS_6 + else if( num == 5 ) + { + /*int lasttalkelder = 2;// + if( CHAR_getInt( talker, CHAR_LASTTALKELDER) == 1 )//˿ + lasttalkelder = 112;// + else if( CHAR_getInt( talker, CHAR_LASTTALKELDER) == 2 )//Ӽ + lasttalkelder = 102;//˿˶ + else if( CHAR_getInt( talker, CHAR_LASTTALKELDER) == 3 )//³ + lasttalkelder = 34;// + print("\npetid:%d",lasttalkelder);*/ + + //ҿûд2ת + for(i=0 ; i < CHAR_MAXPETHAVE ; i++){ + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) continue; + if( CHAR_getInt( petindex, CHAR_TRANSMIGRATION) == 2 + && ( CHAR_getInt( petindex, CHAR_PETID) == 2 + || CHAR_getInt( petindex, CHAR_PETID) == 112 + || CHAR_getInt( petindex, CHAR_PETID) == 102 + || CHAR_getInt( petindex, CHAR_PETID) == 34 ) ) break; + //if(CHAR_getInt( petindex, CHAR_TRANSMIGRATION) != 2 || CHAR_getInt( petindex, CHAR_PETID) != lasttalkelder ) continue; + } + if(i == CHAR_MAXPETHAVE){ + CHAR_talkToCli( talker,-1,"ûд2תijŶ!",CHAR_COLORWHITE); + return -1; + } + + + if(NPC_EventCheckFlg( talker, 63) == FALSE){ print("\nerr63");return -1;} + if(NPC_EventCheckFlg( talker, 136) == FALSE){ print("\nerr136");return -1;} + if(NPC_EventCheckFlg( talker, 175) == FALSE){ print("\nerr175");return -1;} + if(NPC_EventCheckFlg( talker, 176) == FALSE){ print("\nerr176");return -1;} + //15ħ֮Ƭ + j=0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( i=0 ; i 7) + CHAR_setInt(toindex ,CHAR_TRANSMIGRATION,7); + if( CHAR_getInt(toindex,CHAR_TRANSMIGRATION) == 7 )//6ת͵ij + present = 9999; +#else + if(CHAR_getInt( toindex, CHAR_TRANSMIGRATION) > 6) + CHAR_setInt(toindex ,CHAR_TRANSMIGRATION,6); +#endif + if( CHAR_getInt(toindex,CHAR_TRANSMIGRATION) == 6 )//6ת͵ij + present = 2546; + +#else + if(CHAR_getInt( toindex, CHAR_TRANSMIGRATION) > 5) + CHAR_setInt(toindex ,CHAR_TRANSMIGRATION,5); +#endif + NPC_TransmigrationStatus(meindex, toindex, work); + NPC_TransmigrationFlg_CLS(meindex, toindex); + CHAR_setInt(toindex, CHAR_LV ,1); + CHAR_setMaxExp( toindex, 0); + +#ifdef _TRANS_6 +//ɾħ֮Ƭ +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(toindex); + for( i=0 ; i0){ + return 20; + } +#endif + int i; + int num = 0; + + for(i = 0 ; i < 20; i++){ + if(NPC_EventCheckFlg(toindex ,questTbl[i]) == TRUE){ + num++; + } + } + + return num; +} + +//******************************************************* +//******************************************************* +int NPC_TransCalculation(int toindex, int para) +{ + float quest, level, num, tmp; + float ans; + int equ; + equ = CHAR_getInt(toindex, CHAR_TRANSEQUATION); + quest = (float)(( equ >> 16 ) & 0xFFFF); + level = (float)(( equ >> 0 ) & 0xFFFF); + //tttom + //print("\n this test equ=%d,quest=%f,level=%f",equ,quest,level); + //Ϸ + num = CHAR_getInt(toindex, CHAR_TRANSMIGRATION); // ǰѼ1,0ת1ʱΪ1 + tmp = (float)para / 100; +#ifdef _TRANS_6 + if (num == 6) tmp = 620; // תʱɵ +#endif +#ifdef _TRANS_7 + if (num == 7) tmp = 780; // תʱɵ +#endif + ans =(float)tmp/12 + (float)(quest / 4) +( (float)(level- num * 85) /4); + return (int)ans; +} + +//******************************************************* +//******************************************************* +float Rounding(float work,int num) +{ + + float p; + + if(num <0 ) return work; + num--; + p = (float)pow(10,num); + + return ( (work * p + 0.5) /p); + + +} + +//******************************************************* +// +// +//******************************************************* +BOOL NPC_TransmigrationStatus(int meindex, int toindex,int work[10]) +{ + int vital, str, tgh, dex; + int quest , level ,equ; + int t_quest, t_level; + int total,ans; + float tmp,lvup; + + vital = CHAR_getInt(toindex,CHAR_VITAL); + str = CHAR_getInt(toindex,CHAR_STR); + tgh = CHAR_getInt(toindex,CHAR_TOUGH); + dex = CHAR_getInt(toindex,CHAR_DEX); + + + //;޵׷ºë + quest = NPC_TransmigrationQuestCheck( toindex); + //ì + level = CHAR_getInt(toindex,CHAR_LV); + + work[0] = level; + work[1] = quest; + + equ = CHAR_getInt(toindex, CHAR_TRANSEQUATION); + + t_quest = (float)(( equ >> 16 ) & 0xFFFF); + t_level = (float)(( equ >> 0 ) & 0xFFFF); + + if( level > 130 ) level = 130; + t_quest = t_quest + quest; + t_level = t_level + level; + + CHAR_setInt(toindex, CHAR_TRANSEQUATION, + ( t_quest << 16 )+( t_level << 0 ) + ); + + total = vital + str + tgh + dex; + ans = NPC_TransCalculation(toindex, total); + + work[2] = vital; + tmp = (float)vital/total * ans; + work[3] = Rounding(tmp,1) * 100; + + work[4] = str; + tmp = (float)str/total * ans; + work[5] = Rounding(tmp,1) * 100; + + work[6] = tgh; + tmp = (float)tgh/total * ans; + work[7] = Rounding(tmp,1) * 100; + + work[8] = dex; + tmp = (float)dex/total * ans; + work[9] = Rounding(tmp,1) * 100; + + //vital + if(work[3] < 0) work[3] = 0; + CHAR_setInt(toindex, CHAR_VITAL, work[3]); + //str + if(work[5] < 0) work[5] = 0; + CHAR_setInt(toindex, CHAR_STR, work[5]); + + //tghr + if(work[7] < 0) work[7] = 0; + CHAR_setInt(toindex, CHAR_TOUGH, work[7]); + + //dex + if(work[9] < 0) work[9] = 0; + CHAR_setInt(toindex, CHAR_DEX, work[9]); + + + + lvup = CHAR_getInt(toindex, CHAR_SKILLUPPOINT ); +/*#ifdef _TRANS_6 + if( CHAR_getInt(toindex, CHAR_TRANSMIGRATION) == 6) + lvup = 620; +#endif*/ + lvup = lvup / 12; + lvup = Rounding(lvup, 1); + if(lvup < 0) lvup = 0; + CHAR_setInt(toindex, CHAR_SKILLUPPOINT, (int)lvup); + + /* ƽʧƥճľë˪ */ + if( CHAR_getInt( toindex,CHAR_SKILLUPPOINT ) >=1 ) + CHAR_Skillupsend(toindex); + + + return TRUE; + + +} + + +/*---------------------------- + * ʸëܰ + ------------------------------*/ +BOOL NPC_TransmigrationAddPet(int meindex, int talker, int petid) +{ + int ret; + char msgbuf[64]; + int enemynum; + int i,j; + int petindex; + int petindex2; + for( i = 0 ;i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( talker, i); + if( petindex == -1 ) break; + } + if(i == CHAR_MAXPETHAVE) return FALSE; + enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == petid) { + break; + } + } + + if( i == enemynum ) return FALSE; + + ret = ENEMY_createPetFromEnemyIndex( talker, i); + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ){ + if( CHAR_getCharPet( talker, i ) == ret )break; + } + if( i == CHAR_MAXPETHAVE ) i = 0; + if( CHAR_CHECKINDEX( ret ) == TRUE ){ + CHAR_setMaxExpFromLevel( ret, CHAR_getInt( ret, CHAR_LV )); + } + + petindex2 = CHAR_getCharPet(talker, i); + if( !CHAR_CHECKINDEX( petindex2) ) return FALSE; + + snprintf( msgbuf,sizeof( msgbuf), "õ%s", + CHAR_getChar(petindex2,CHAR_NAME)); + CHAR_talkToCli( talker, -1, msgbuf, CHAR_COLORWHITE); + for(j = 0; j < CHAR_MAXPETHAVE; j++){ + petindex = CHAR_getCharPet(talker, j); + if( !CHAR_CHECKINDEX( petindex) ) continue; + CHAR_complianceParameter( petindex ); + snprintf( msgbuf, sizeof( msgbuf ), "K%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", j ); + CHAR_sendStatusString( talker, msgbuf ); + } + LogPet( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), + CHAR_getChar( petindex2, CHAR_NAME), + CHAR_getInt( petindex2, CHAR_LV), + "TenseiGet", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + CHAR_getChar( petindex2, CHAR_UNIQUECODE) // shan 2001/12/14 + ); + + return TRUE; + +} + +#ifdef _TEACHER_SYSTEM +extern int FMAdvTbl[]; +#endif + +int NPC_TransmigrationFlg_CLS(int meindex, int toindex) +{ +#ifdef _TEACHER_SYSTEM + int iGetFame = 0; +#endif +#ifdef _PET_TRANS +#ifdef _PROSK99 + int endevflg[]={69,70,71,72,109,118,122,131,127,158,159,181,-1};//181:ǽƷ +#else +#ifdef _CLR_PETTRANS_ + int endevflg[]={71,72,109,118,122,131,127,158,159,-1}; +#else + int endevflg[]={69,70,71,72,109,118,122,131,127,158,159,-1}; +#endif +#endif +#ifdef _CLR_PETTRANS_ + int nowevflg[]={71,72,-1}; +#else + int nowevflg[]={69,70,71,72,-1}; +#endif +#endif +#ifdef _TRANS_6 +#ifdef _TRANS_7 + int flg[7] = {48,49,50,51,52,179,999}; +#else + int flg[6] = {48,49,50,51,52,179}; +#endif +#else + int flg[5] = {48,49,50,51,52}; +#endif + int num= CHAR_getInt(toindex ,CHAR_TRANSMIGRATION); + int i; +#ifdef _PET_TRANS + i=0; + while(endevflg[i] != -1 ) { + if( NPC_EventCheckFlg( toindex, endevflg[i] ) == FALSE ) { + endevflg[i] = 0; + } + i++; + } + i=0; + while( nowevflg[i] != -1 ) { + if( NPC_NowEventCheckFlg( toindex, nowevflg[i] ) == FALSE ) { + nowevflg[i] = 0; + } + i++; + } +#endif + + CHAR_setInt(toindex,CHAR_ENDEVENT,0); + CHAR_setInt(toindex,CHAR_ENDEVENT2,0); + CHAR_setInt(toindex,CHAR_ENDEVENT3,0); +#ifdef _NEWEVENT + CHAR_setInt(toindex,CHAR_ENDEVENT4,0); + CHAR_setInt(toindex,CHAR_ENDEVENT5,0); + CHAR_setInt(toindex,CHAR_ENDEVENT6,0); +#endif + CHAR_setInt(toindex,CHAR_NOWEVENT,0); + CHAR_setInt(toindex,CHAR_NOWEVENT2,0); + CHAR_setInt(toindex,CHAR_NOWEVENT3,0); +#ifdef _NEWEVENT + CHAR_setInt(toindex,CHAR_NOWEVENT4,0); + CHAR_setInt(toindex,CHAR_NOWEVENT5,0); + CHAR_setInt(toindex,CHAR_NOWEVENT6,0); +#endif +#ifdef _ADD_NEWEVENT // WON + CHAR_setInt(toindex,CHAR_ENDEVENT7,0); + CHAR_setInt(toindex,CHAR_NOWEVENT7,0); + CHAR_setInt(toindex,CHAR_ENDEVENT8,0); + CHAR_setInt(toindex,CHAR_NOWEVENT8,0); +#endif +#ifndef _NO_CLS_EVENT_255 +#ifdef _ADD_NEWEVENT_1024 + CHAR_setInt(toindex,CHAR_ENDEVENT9,0); + CHAR_setInt(toindex,CHAR_NOWEVENT9,0); + CHAR_setInt(toindex,CHAR_ENDEVENT10,0); + CHAR_setInt(toindex,CHAR_NOWEVENT10,0); + CHAR_setInt(toindex,CHAR_ENDEVENT11,0); + CHAR_setInt(toindex,CHAR_NOWEVENT11,0); + CHAR_setInt(toindex,CHAR_ENDEVENT12,0); + CHAR_setInt(toindex,CHAR_NOWEVENT12,0); + CHAR_setInt(toindex,CHAR_ENDEVENT13,0); + CHAR_setInt(toindex,CHAR_NOWEVENT13,0); + CHAR_setInt(toindex,CHAR_ENDEVENT14,0); + CHAR_setInt(toindex,CHAR_NOWEVENT14,0); + CHAR_setInt(toindex,CHAR_ENDEVENT15,0); + CHAR_setInt(toindex,CHAR_NOWEVENT15,0); + CHAR_setInt(toindex,CHAR_ENDEVENT16,0); + CHAR_setInt(toindex,CHAR_NOWEVENT16,0); +#endif +#endif +#ifdef _PET_TRANS + i=0; + while( endevflg[i] != -1 ) { + if( endevflg[i] > 0 ) { + // shan Begin + //NPC_EventSetFlg( toindex, endevflg[i]); + s_eventsetend(toindex, endevflg[i]); + // End + } + i++; + } + i=0; + while( nowevflg[i] != -1 ) { + if( nowevflg[i] > 0 ) { + NPC_NowEventSetFlg( toindex, nowevflg[i]); + } + i++; + } + +#endif + + for(i = 0 ;i < num ;i++) { + NPC_EventSetFlg(toindex, flg[i]); + // CoolFish: Family Adv 2001/8/4 + AddFMAdv(toindex, flg[i]); +#ifdef _TEACHER_SYSTEM + // ۼ + if(flg[i] < 179) iGetFame += FMAdvTbl[flg[i]]; +#endif + } +#ifdef _TEACHER_SYSTEM + iGetFame /= 20; // ʦѧ 5% (1/20) + // õûд0 + if(iGetFame > 0){ + // ûеʦ + if(strlen(CHAR_getChar(toindex,CHAR_TEACHER_ID)) > 0 && strlen(CHAR_getChar(toindex,CHAR_TEACHER_NAME)) > 0){ + int iPlayernum = CHAR_getPlayerMaxNum(); + char szMsg[128]; + + // 鵼ʦڲ + for(i=0;i= 0 ) + errtype = 3; + + if( errtype >= 0 ) { + if( NPC_Util_GetStrFromStrWithDelim( buf,errchar[ errtype], token,sizeof( token)) == NULL ) { + print("\n ERROR str errchar !!"); + return; + } + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_PETTRANS_END; + break; + } + if( NPC_Util_GetStrFromStrWithDelim( buf,"selectmsg", token,sizeof( token)) == NULL ) { + print("\n ERROR selectmsg !!"); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 1); + windowno = CHAR_WINDOWTYPE_PETTRANS_SELECT; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype=WINDOW_BUTTONTYPE_YESNO; + break; + + case 2: //ѡ + if( NPC_Util_GetStrFromStrWithDelim( buf,"setpetmsg", token,sizeof( token)) == NULL ) { + print("\n ERROR setpetmsg !!"); + return; + } + buttontype = WINDOW_BUTTONTYPE_NONE; + windowtype = WINDOW_MESSAGETYPE_PETSELECT; + windowno = CHAR_WINDOWTYPE_PETTRANS_SELPET; + break; + + case 3: //ת ȷ/ȡ + if( NPC_Util_GetStrFromStrWithDelim( buf,"transmsg", buf1,sizeof( buf1)) == NULL ){ + print("\n ERROR transmsg !!"); + return; + } + strcpy( token,"\0"); + petindex = CHAR_getCharPet( toindex, select-1); + petname = CHAR_getUseName( petindex); + sprintf(token, "\n[%s]ûɣ \n\n %s",petname,buf1); + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = CHAR_WINDOWTYPE_PETTRANS_MAIN1; + break; + + case 4: //ת CHAR_TRANSMIGRATION + //תж + petindex = CHAR_getCharPet( toindex, select-1); + if( !CHAR_CHECKINDEX( petindex) ) { + return; + } +#ifdef _PET_FUSION +#ifdef _FUSIONBEIT_TRANS + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT ) > getFusionbeitTrans()) { + sprintf(token, "\n\nںϹijѾܹףร"); +#else + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT ) == 1 ) { + sprintf(token, "\n\nںϹijﲻתร"); +#endif + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + }else +#endif +#ifdef _PET_2TRANS + if( CHAR_getInt( toindex, CHAR_RIDEPET ) == select-1 /*&& CHAR_getInt( petindex, CHAR_TRANSMIGRATION ) > 0*/ ){//еijﲻת + sprintf(token, "\n\nеijﲻתร"); + }else +#endif + if( CHAR_getInt( petindex, CHAR_LV) < 80 ) { + sprintf(token, "\n\nתףijҪȼ80ร"); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + }else if( CHAR_getInt( petindex, CHAR_PETID) == 718 +#ifdef _PET_2TRANS + || CHAR_getInt( petindex, CHAR_PETID) == 401 +#endif + ){ + sprintf(token, "\n\nֻﲻתร"); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); +#ifdef _PET_2TRANS +#ifdef _FUSIONBEIT_TRANS + }else if( CHAR_getInt( petindex, CHAR_FUSIONBEIT ) == 0 && + CHAR_getInt( petindex, CHAR_TRANSMIGRATION ) > 1 ) { +#else + }else if( CHAR_getInt( petindex, CHAR_TRANSMIGRATION ) > 1 ) { +#endif +#else + }else if( CHAR_getInt( petindex, CHAR_TRANSMIGRATION ) > 0 ) { +#endif + sprintf(token, "\n\nֻѾܹףร"); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + //Ƿظת + }else { // תϣ + petindex = CHAR_getCharPet( toindex, select-1); + if( NPC_PetTransManStatus( meindex, toindex, petindex) == FALSE ) + return; + if( NPC_Util_GetStrFromStrWithDelim( buf,"main1msg", token,sizeof( token)) == NULL ) + return; +#ifdef _FUSIONBEIT_TRANS + if( CHAR_getInt( petindex, CHAR_FUSIONBEIT ) >= 1 ) + CHAR_setInt( petindex, CHAR_FUSIONBEIT ,CHAR_getInt( petindex, CHAR_FUSIONBEIT )+1); +#endif + } + + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_PETTRANS_END; // + break; + + case 5: //תȡ + if( NPC_Util_GetStrFromStrWithDelim( buf,"cancelmsg", token,sizeof( token)) == NULL ) + return; + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + buttontype = WINDOW_BUTTONTYPE_OK; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + windowno = CHAR_WINDOWTYPE_PETTRANS_END; // + break; + + default: + break; + } + lssproto_WN_send( fd, windowtype, buttontype, windowno, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); + +} + +int NPC_PetTransManCheck( int meindex, int toindex, int select) +{ + //char errchar[][56]={"errormy","erroritem","errorpet","failmsg"}; + int i; + int petindex = 0; + char token[256]; + int PetEvent_no[3]={4,69,70}; + //int PetEvent_no[3]={4,4,4}; + + int petNum = 0; + //ת + if( CHAR_getInt( toindex, CHAR_LV ) < 80 ) { + return 0; + }else { + //FLAG ǷɳתҪ + for(i = 0; i < 3 ;i++) { + if( NPC_EventCheckFlg( toindex, PetEvent_no[i] ) == FALSE) { + return 0; + } + } + //(/) & Ʒ + for(i=0 ; i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( toindex, i); + if( petindex == -1 ) + continue; + // ID ǷΪ׷ 1479 ID Ϊ718 + if(CHAR_getInt( petindex, CHAR_PETID) == 718 +#ifdef _PET_2TRANS + || CHAR_getInt( petindex, CHAR_PETID) == 401 +#endif + ){ + petNum ++; + if( CHAR_getInt( petindex, CHAR_LV) > 79 ) { + return 0; + }else if( CHAR_getInt( petindex, CHAR_LV) == 79 ) { + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( toindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( toindex, CHAR_NAME) )) { + sprintf( token,"ϵ׷ţİ"); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORWHITE); + return 0; + } + } + } + } + + if( petNum > 1 ) { + sprintf( token,"׷أ"); + CHAR_talkToCli( toindex, -1, token, CHAR_COLORWHITE); + print("\n error PetTrans : (PETID = 718) > 1 !!"); + return 0; + }else if( petNum != 1 ) { + print("\n ת !!"); + return 0; + } + } + return -1; +} + +BOOL NPC_PetTransManStatus( int meindex, int toindex, int petNo) +{ + int petindex; + int LevelUpPoint = 0,petrank = 0; + int i,j,k,itemindex,itemID,count; + int vital1,str1,tgh1,dex1; + int vital2,str2,tgh2,dex2; + char token[128]; + int total1,total2,total,petLV,ans; + int petID,enemynum,ret; + int work[4]={0,0,0,0}; + struct PetTransDelItem { + int minItemID; + int maxItemID; + }DelItem[3] = { {19629,19632} , {19672,19687} , {19625,19628} }; +#define RAND(x,y) ((x-1)+1+ (int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0)) ) +#ifdef _PET_2TRANS + int tran = CHAR_getInt ( petNo, CHAR_TRANSMIGRATION ); + int tpetidx1,tpetidx2; + if( tran == 0 ){ + tpetidx1 = 718; + tpetidx2 = 401; + } + else{ + tpetidx1 = 401; + tpetidx2 = 401; + } +#endif + + for(i=0 ; i < CHAR_MAXPETHAVE ; i++) { + petindex = CHAR_getCharPet( toindex, i); + if( petindex == -1 ) + continue; + if( +#ifdef _PET_2TRANS + CHAR_getInt( petindex, CHAR_PETID) == tpetidx1 + || CHAR_getInt( petindex, CHAR_PETID) == tpetidx2 +#else + CHAR_getInt( petindex, CHAR_PETID) == 718 +#endif + ){ + if( CHAR_getInt( petindex, CHAR_LV) == 79 ){ + if( strcmp( CHAR_getChar( petindex, CHAR_OWNERCDKEY), CHAR_getChar( toindex, CHAR_CDKEY) ) || + strcmp( CHAR_getChar( petindex, CHAR_OWNERCHARANAME), CHAR_getChar( toindex, CHAR_NAME) )) { + continue; + } + break; + } + } + } + if(i == CHAR_MAXPETHAVE) { + print("\n ת !!"); + return FALSE; + } + + LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + petrank = CHAR_getInt( petindex, CHAR_PETRANK ); + + + vital1 = (float)(( LevelUpPoint >> 24 ) & 0xFF); + str1 = (float)(( LevelUpPoint >> 16 ) & 0xFF); + tgh1 = (float)(( LevelUpPoint >> 8 ) & 0xFF); + dex1 = (float)(( LevelUpPoint >> 0 ) & 0xFF); + if(vital1 < 1)vital1 = 1; + if(str1 < 1)str1 = 1; + if(tgh1 < 1)tgh1 = 1; + if(dex1 < 1)dex1 = 1; + total1 = ( vital1 + str1 + tgh1 + dex1 ); + if( total1 > 150 ) total1 = 150; + if( total1 < 0 ) total1 = 0; + LevelUpPoint = CHAR_getInt( petNo, CHAR_ALLOCPOINT ); + petrank = CHAR_getInt( petNo, CHAR_PETRANK ); + petLV = CHAR_getInt( petNo, CHAR_LV); + vital2 = (float)(( LevelUpPoint >> 24 ) & 0xFF); + str2 = (float)(( LevelUpPoint >> 16 ) & 0xFF); + tgh2 = (float)(( LevelUpPoint >> 8 ) & 0xFF); + dex2 = (float)(( LevelUpPoint >> 0 ) & 0xFF); + if(vital2 < 1)vital2 = 1; + if(str2 < 1)str2 = 1; + if(tgh2 < 1)tgh2 = 1; + if(dex2 < 1)dex2 = 1; + total2 = ( vital2 + str2 + tgh2 + dex2 ); + +#ifdef _PET_2TRANS + ans = NPC_PetTransManGetAns( total1, total2, petLV, petrank, CHAR_getInt( petNo, CHAR_TRANSMIGRATION ) ); +#else + ans = NPC_PetTransManGetAns( total1, total2, petLV, petrank); +#endif + + total = total1 + (total2*4); + + work[0] = ( ans * ( vital1 + (vital2*4) ) ) / total; + work[1] = ( ans * ( str1 + (str2*4) ) ) / total; + work[2] = ( ans * ( tgh1 + (tgh2*4) ) ) / total; + work[3] = ( ans * ( dex1 + (dex2*4) ) ) / total; + +//ȡarray========================= + enemynum = ENEMY_getEnemyNum(); + for(i=0;i= DelItem[j].minItemID ) && ( itemID <= DelItem[j].maxItemID ) ) { + LogItem( + CHAR_getChar( toindex, CHAR_NAME ), + CHAR_getChar( toindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), +#endif + "WarpManDelItem", + CHAR_getInt( toindex, CHAR_FLOOR), + CHAR_getInt( toindex, CHAR_X ), + CHAR_getInt( toindex, CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + CHAR_DelItem( toindex, i); + } + + }//for(j) + } + } + + NPC_NowEventSetFlg( toindex, 71 ); + return TRUE; +} + + + +// shan add +void s_eventsetend( int charaindex, int shiftbit ) +{ +#ifdef _ADD_NEWEVENT_1024 + int event_num = 32; +#else +#ifdef _ADD_NEWEVENT // WON + int event_num = 8; +#else + int event_num = 6; +#endif +#endif + int point; + int array; + int shift; + + array = shiftbit / 32; + shift = shiftbit % 32; + + if( array>=event_num ){ + //print("󣡣ѳΧ(0~%d)",32*event_num-1); + return; + } + point = CHAR_getInt( charaindex, CHAR_ENDEVENT+array); + point = point | (1< +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "npc_vipshop.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "readmap.h" +#include "battle.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" + +//صشøнڽ"ʦ" +#ifdef _VIP_SHOP +enum { + WINDOW_START=1, + WINDOW_SELECT, + WINDOW_PREV, + WINDOW_NEXT, + WINDOW_WARP, + WINDOW_END, +}; +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_WORK_MAXPAGE = CHAR_NPCWORKINT2, +/* + NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, + NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, + NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, + NPC_WORK_MODE = CHAR_NPCWORKINT5, + NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, + NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, + NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, + NPC_WORK_SEFLG = CHAR_NPCWORKINT10, +*/ +}; + +#define STANDBYTIME 50 + +static void NPC_VipShop_selectWindow( int meindex, int toindex, int num,int select); +BOOL VipShop_GetMenuStr( int meindex, int toindex, char *npcarg, char *token, int index ); +int VipShop_ShowMenulist( char *npcarg ); + +int page; + +BOOL NPC_VipshopInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("TRANSER_MAN: GetArgStrErr!!"); + return FALSE; + } + + CHAR_setInt( meindex, CHAR_WHICHTYPE, CHAR_TRANSERMANS); + + CHAR_setWorkInt( meindex, NPC_WORK_MAXPAGE, VipShop_ShowMenulist(npcarg)); + + //CHAR_setInt( meindex, CHAR_LOOPINTERVAL, NEWNPCMAN_STANDBY); + CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); + return TRUE; +} +//CHAR_setWorkInt(talkerindex,CHAR_WORKSHOPRELEVANT,1); +void NPC_VipshopTalked( int meindex, int talkerindex, char *msg, int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) + return; + if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) + return; + } + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_START, 0); +} + +void NPC_VipshopWindowTalked( int meindex, int talkerindex, int seqno, + int select, char *data) +{ + if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) + return; + switch( seqno) { + case NPC_TRANSERMAN_START: + break; + case NPC_TRANSERMAN_SELECT: + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_SELECT, atoi( data)); + break; + case NPC_TRANSERMAN_WARP: + if( select == WINDOW_BUTTONTYPE_CANCEL ) + return; + if( select == WINDOW_BUTTONTYPE_NEXT ) + { + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_NEXT, atoi( data)); + return; + } + if( select == WINDOW_BUTTONTYPE_PREV ) + { + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_PREV, atoi( data)); + return; + } + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_WARP, atoi( data)); + break; + case NPC_TRANSERMAN_END: + NPC_VipShop_selectWindow( meindex, talkerindex, WINDOW_END, atoi( data)); + break; + } + +} + +static void NPC_VipShop_selectWindow( int meindex, int toindex, int num,int select) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + char buf1[256]; + char buf2[256]; + char buf3[256]; + int buttontype = 0, windowtype = 0, windowno = 0; + int fd = getfdFromCharaIndex( toindex); + static int select1; + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + + if(NPC_Util_isFaceToFace( meindex ,toindex , 2) == FALSE) { + if(NPC_Util_isFaceToChara( toindex, meindex, 1) == FALSE) + return; + } + + memset( npcarg, 0, sizeof( npcarg)); + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("VipShop_MAN: GetArgStrErr!!"); + return; + } + memset( token, 0, sizeof( token)); + + switch( num) { + case WINDOW_START: + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "START_MSG", token, sizeof( token) ) == NULL) { + print("VipShop Get START_MSG ERROR !"); + return; + } + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, WINDOW_START); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_TRANSERMAN_SELECT; + break; + case WINDOW_SELECT: + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, 0); + + if( VipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "VipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)>1) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_NEXT: + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)<=CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)) + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)+1); + if( VipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "VipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)+1==CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV; + else + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_PREV: + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)>0) + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)-1); + if( VipShop_GetMenuStr( meindex, toindex, npcarg, token,CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)) == FALSE ) { + print( "VipShop GetMenu ERROR !!"); + return; + } + windowtype = WINDOW_MESSAGETYPE_SELECT; + if(CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)==0) + buttontype = WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + else + buttontype = WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_CANCEL|WINDOW_BUTTONTYPE_NEXT; + windowno = NPC_TRANSERMAN_WARP; + break; + case WINDOW_WARP: + select1=CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)*7+select; + CHAR_setWorkInt( toindex, CHAR_WORK_LISTPAGE, select1); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "END_MSG", buf1, sizeof( buf1) ) == NULL) { + print("VipShop Get START_MSG ERROR !"); + return; + } + if(getStringFromIndexWithDelim( npcarg,"}",select1, buf2, sizeof( buf2)) != FALSE) + NPC_Util_GetStrFromStrWithDelim( buf2, "MenuStr", buf3, sizeof( buf3)); + sprintf( token, "\n%s\n\n %s\n",buf1, buf3); + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NPC_TRANSERMAN_END; + break; + case WINDOW_END: + ActionNpc_CheckMenuFree( meindex, toindex, npcarg, CHAR_getWorkInt( toindex, CHAR_WORK_LISTPAGE)); + return; + break; + } + + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); +} + +BOOL VipShop_GetMenuStr( int meindex, int toindex, char *npcarg, char *token,int index ) +{ + char buf1[1024], buf2[28], buf3[32]; + BOOL FINDS=FALSE; + int talkNo=index*7+1; + if( npcarg == NULL ) return FALSE; + + sprintf( token, "㵱ǰĻֵ:%d %d/%dҳ\n",CHAR_getInt( toindex , CHAR_AMPOINT), index+1, CHAR_getWorkInt( meindex, NPC_WORK_MAXPAGE)); + while( getStringFromIndexWithDelim( npcarg,"}",talkNo, buf1, sizeof( buf1)) != FALSE ) { + talkNo++; + memset( buf2, 0, sizeof( buf2)); + if( NPC_Util_GetStrFromStrWithDelim( buf1, "MenuStr", buf2, sizeof( buf2)) == NULL ) + continue; + FINDS = TRUE; + + sprintf( buf3, " %s", buf2); + if(strlen(buf3)<10) + strcat( buf3, "\n"); + else + strcat( buf3, "\n"); + strcat( token, buf3); + if(talkNo>(index*7+7))return FINDS; + } + return FINDS; +} + +int VipShop_ShowMenulist( char *npcarg ) +{ + char buf1[1024]; + int talkNo=1; + while( getStringFromIndexWithDelim( npcarg,"}",talkNo, buf1, sizeof( buf1)) != FALSE ) { + talkNo++; + } + return (talkNo-3)/7+1; +} + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warp.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warp.c new file mode 100644 index 0000000..c5edd06 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warp.c @@ -0,0 +1,380 @@ +#include "version.h" +#include +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "map_deal.h" +#include "readmap.h" +#include "npccreate.h" +#include "npcutil.h" +#include "handletime.h" +#include "npc_eventaction.h" + +//#define _RECORD_NPCMAN_ //¼ + +BOOL NPC_TimeWarpCheck(int meindex,char *buf,int mode); + +static void NPC_WarpsetNeverMake( int charaindex ) +{ + int cindex; + cindex = CHAR_getInt(charaindex,CHAR_NPCCREATEINDEX); + if( NPC_CHECKCREATEINDEX(cindex) ) + NPC_create[cindex].workdata[NPC_CREATEWORKNEVERMAKE] = 1; +} + +BOOL NPC_WarpInit( int charaindex ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + int ret; + int floor=-1,x=-1,y=-1; + char token[128]; + +#ifdef _RECORD_NPCMAN_ //¼ + char evtype[256]; + char evtime[256]; + char argfile[256]; + + if( NPC_Util_CheckAssignArgFile( charaindex, argfile) == NULL ) + sprintf( argfile, "NULL"); +#endif + + CHAR_setInt( charaindex, CHAR_WHICHTYPE , CHAR_TYPEWARP ); + if( NPC_Util_GetArgStr( charaindex, arg, sizeof( arg)) == NULL ) { + print("\n GetArgStr ERR!!"); + return FALSE; + } +#ifdef _NEW_WARPPOINT + if( strstr( arg, "FREEMORE") != NULL ) { +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtype, "FREE"); + sprintf( evtime, "NULL"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP); + }else { +#endif +#ifdef _MAP_WARPPOINT + return FALSE; +#endif +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtype, "NONE"); +#endif + ret=getStringFromIndexWithDelim(arg,"|", 1,token,sizeof(token)); + if( ret ) floor = atoi( token ); + ret=getStringFromIndexWithDelim(arg,"|", 2,token,sizeof(token)); + if( ret ) x = atoi( token ); + ret=getStringFromIndexWithDelim(arg,"|", 3,token,sizeof(token)); + if( ret ) y = atoi( token ); + if( MAP_IsValidCoordinate( floor,x,y )== FALSE ){ + NPC_WarpsetNeverMake( charaindex ); + //print( "Warp NPC:Invalid arg:%s\n", arg ); + print( "Warp Npc Err:%d:%d:%d->(%s)\n", + CHAR_getInt( charaindex, CHAR_FLOOR ), + CHAR_getInt( charaindex, CHAR_X ), + CHAR_getInt( charaindex, CHAR_Y ), + arg ); + return FALSE; + } + ret=getStringFromIndexWithDelim(arg,"|",4,token,sizeof(token)); + if(ret==TRUE){ + int day; + day=NPC_TimeWarpCheck(charaindex,token,0); + if(day==0){ +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtime, "N"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP_NIGHT); + }else if(day==1){ +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtime, "M"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP_MORNING); + }else if(day==2){ +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtime, "A"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP_NOON); + }else{ +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtime, "NULL"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP); + } + }else{ +#ifdef _RECORD_NPCMAN_ //¼ + sprintf( evtime, "NULL"); +#endif + CHAR_setWorkInt( charaindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_WARP); + } +#ifdef _NEW_WARPPOINT + } +#endif + CHAR_setFlg( charaindex,CHAR_ISVISIBLE, 0 ); + CHAR_setFlg( charaindex,CHAR_ISOVERED,1 ); + CHAR_setFlg( charaindex,CHAR_ISATTACKED,0 ); + CHAR_setFlg( charaindex,CHAR_ISATTACK,0 ); + +#ifdef _RECORD_NPCMAN_ //¼ + { + FILE *fp=NULL; + char filename[256]; + sprintf( filename,"./data/npc/%s", "mapwarp.txt"); + if( (fp = fopen( filename, "a+")) != NULL ) { + fprintf( fp, "%s:%s:%d,%d,%d:%d,%d,%d:%s\n", + evtype, evtime, + CHAR_getInt( charaindex, CHAR_FLOOR), + CHAR_getInt( charaindex, CHAR_X), + CHAR_getInt( charaindex, CHAR_Y), + floor, x, y, argfile ); + fclose( fp); + }else { + } + } +#endif + return TRUE; +} + +void NPC_WarpWarpCharacter( int warpnpcindex, int charaindex ) +{ + char arg[NPC_UTIL_GETARGSTR_BUFSIZE]; + int i=0; +#ifdef _NEW_WARPPOINT + char buf1[256], buf2[256], buf3[256], freemsg[256]; + BOOL nBefind = FALSE; + struct wapepoints { + int m_floor; + int m_x; + int m_y; + }Wpoint[10]={ + {-1,0,0}, {-1,0,0}, {-1,0,0}, {-1,0,0}, {-1,0,0}, + {-1,0,0}, {-1,0,0}, {-1,0,0}, {-1,0,0}, {-1,0,0} + }; + int iRand=0; +#endif + if( CHAR_getInt( charaindex,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return; + } + + if( NPC_Util_GetArgStr( warpnpcindex, arg, sizeof( arg)) == NULL ){ + return; + } + + { + char token[16]; + int floor=0,x=0,y=0; + int ret; + +#ifdef _NEW_WARPPOINT + i=1; + if( strstr( arg, "FREEMORE") != NULL ) { + int k=1, pw=-1; + while( getStringFromIndexWithDelim( arg, "OVER", i, buf1, sizeof( buf1)) != FALSE ) { + i++; + if( NPC_Util_GetStrFromStrWithDelim( buf1, "FREE", buf2, sizeof( buf2)) == NULL ) + continue; + if( NPC_ActionPassCheck( warpnpcindex, charaindex, buf2) == FALSE ) { + continue; + }else { + iRand=0; + if( NPC_Util_GetStrFromStrWithDelim( buf1, "TO", buf2, sizeof( buf2)) != FALSE ) { + k=1; + while( getStringFromIndexWithDelim( buf2, "&", k, freemsg, sizeof( freemsg)) != FALSE ){ + k++; + if( getStringFromIndexWithDelim( freemsg, ",", 1, buf3, sizeof( buf3)) == FALSE ) + break; + Wpoint[iRand].m_floor = atoi( buf3); + if( getStringFromIndexWithDelim( freemsg, ",", 2, buf3, sizeof( buf3)) == FALSE ) + break; + Wpoint[iRand].m_x = atoi( buf3); + if( getStringFromIndexWithDelim( freemsg, ",", 3, buf3, sizeof( buf3)) == FALSE ) + break; + Wpoint[iRand].m_y = atoi( buf3); + iRand++; + nBefind = TRUE; + if( iRand >= arraysizeof( Wpoint)) + break; + } + break; + } + } + if( nBefind == TRUE ) + break; + } + + if( nBefind == FALSE || iRand <= 0){ //ûҵ + floor = CHAR_getInt( warpnpcindex, CHAR_FLOOR); + x = CHAR_getInt( warpnpcindex, CHAR_X); + y = CHAR_getInt( warpnpcindex, CHAR_Y); + }else { + pw = RAND( 0, (iRand-1)); + floor = Wpoint[pw].m_floor; + x = Wpoint[pw].m_x; + y = Wpoint[pw].m_y; + if( NPC_Util_GetStrFromStrWithDelim( arg, "CHECKPARTY", buf1, sizeof( buf1)) != NULL ) { + if( strstr( buf1, "TRUE") != NULL ){ + if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) { + CHAR_DischargeParty( charaindex, 0); // + } + } + } + if( MAP_IsValidCoordinate( floor,x,y )== FALSE ){ + print( "*Warp NPC:Invalid %d %d %d" , floor,x,y ); + return; + } + k=0; + } + }else { +#endif + ret=getStringFromIndexWithDelim(arg,"|", 1,token,sizeof(token)); + if( ret == FALSE )return; + floor = atoi( token ); + + ret=getStringFromIndexWithDelim(arg,"|", 2,token,sizeof(token)); + if( ret == FALSE )return; + x = atoi( token ); + + ret=getStringFromIndexWithDelim(arg,"|", 3,token,sizeof(token)); + if( ret == FALSE )return; + y = atoi( token ); +#ifdef _NEW_WARPPOINT + } +#endif + { + int ff=floor; + + int of=CHAR_getInt(charaindex, CHAR_FLOOR); + int fd=CHAR_getWorkInt( charaindex, CHAR_WORKFD); + int eqen=getEqNoenemy(fd); + if (eqen<200) { + if (eqen>=120) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)||(ff==500)) { + if ((of!=100)&&(of!=200)&&(of!=300)&&(of!=400)&&(of!=500)) { + CHAR_talkToCli(charaindex, -1, + "̫ηһĹâ١", CHAR_COLORWHITE); + } + } else { + if ((of==100)||(of==200)||(of==300)||(of==400)||(of==500)) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + } + } + } else if (eqen>=80) { + if ((ff==100)||(ff==200)||(ff==300)||(ff==400)) { + if ((of!=100)&&(of!=200)&&(of!=300)&&(of!=400)) { + CHAR_talkToCli(charaindex, -1, + "̫ηһĹâ١", CHAR_COLORWHITE); + } + } else { + if ((of==100)||(of==200)||(of==300)||(of==400)) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + } + } + } else if (eqen>=40) { + if ((ff==100)||(ff==200)) { + if ((of!=100)&&(of!=200)) { + CHAR_talkToCli(charaindex, -1, + "̫ηһĹâ١", CHAR_COLORWHITE); + } + } else { + if ((of==100)||(of==200)) { + CHAR_talkToCli(charaindex, -1, "Ĺâʧˡ", CHAR_COLORWHITE); + } + } + } + } + } + +#ifdef _DROPSTAKENEW + { + i = 0; + for (i = 0; i < MAXSTAKENUM; i++){ + if (CHAR_getWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + i) > 0){ + char tmpbuf[256]; + snprintf(tmpbuf, sizeof(tmpbuf), "뿪˷䣬Խ޷ȡزȯ"); + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKETYPE1 + i, 0); + CHAR_talkToCli(charaindex, -1, tmpbuf, CHAR_COLORYELLOW); + } + } + CHAR_setWorkInt(charaindex, CHAR_WORKSTAKEFLAG, 0); +#ifdef _FIX_GAMBLENUM + if(CHAR_getInt(charaindex, CHAR_GAMBLENUM) < 0) + CHAR_setInt(charaindex, CHAR_GAMBLENUM, 0); +#endif + } +#endif + if( floor == -1) { + return; + }else { + if( MAP_IsValidCoordinate( floor,x,y )== FALSE ){ + print( "Warp NPC:Invalid %d %d %d" , floor,x,y ); + return; + } + + CHAR_warpToSpecificPoint(charaindex, floor, x, y); + } + } +} + +void NPC_WarpWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ) +{ + int meindex,moveindex; + if( OBJECT_getType( objindex ) != OBJTYPE_CHARA )return; + + meindex = OBJECT_getIndex(meobjindex); + moveindex = OBJECT_getIndex(objindex); + + if( CHAR_getInt( moveindex,CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + return; + } + if( act != CHAR_ACTWALK )return; + + if( opt[0] == x && opt[1] == y )return; + if( CHAR_getInt(meindex,CHAR_X) == x && CHAR_getInt(meindex,CHAR_Y) == y ) { + NPC_WarpWarpCharacter( meindex, moveindex ); + } +} + +void NPC_WarpPostOver( int meindex, int charaindex ) +{ + NPC_WarpWarpCharacter( meindex, charaindex ); +} + +int NPC_WarpSearchByPosition( int fl , int x, int y) +{ + OBJECT object; + for( object=MAP_getTopObj(fl,x,y) ; object ; + object=NEXT_OBJECT(object)){ + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType( objindex ) == OBJTYPE_CHARA + && CHAR_getInt( OBJECT_getIndex(objindex), CHAR_WHICHTYPE) + == CHAR_TYPEWARP ){ + return OBJECT_getIndex(objindex); + } + } + return -1; +} + + +int NPC_TimeWarpCheck(int meindex,char *buf,int mode) +{ + LSTIME nowlstime; + char *time[4]={"N","M","A"}; + int now; + int i=0; + RealTimeToLSTime( NowTime.tv_sec, &nowlstime); + now = getLSTime( &nowlstime); + if(mode==0){ + for( i=0 ; i < 3 ; i++){ + if(strstr( buf,time[i]) != NULL){ + return i; + } + } + return -1;; + } + if(mode==1){ + if(now==CHAR_getWorkInt( meindex, CHAR_WORKEVENTTYPE)){ + return now; + } + return -1; + } + return -1; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warpman.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warpman.c new file mode 100644 index 0000000..ec92a35 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_warpman.c @@ -0,0 +1,1149 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "saacproto_cli.h" +#include "npc_warpman.h" +#include "map_deal.h" +#include "readmap.h" +#include "battle.h" +#include "npc_exchangeman.h" +#include "log.h" +#include "enemy.h" +#include "handletime.h" +#include "npc_eventaction.h" +#include "item_event.h" +static void NPC_WarpMan_selectWindow( int meindex, int toindex, int num,int select); +//ANDY_END +BOOL NPC_GetDuelPointCheck(int meindex,int talker); +BOOL NPC_PARTY_CHAECK( int meindex, int talkerindex); +void NPC_ERR_DiSP(int meindex,int talker,int errNO); +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +BOOL NPC_BigSmallLastCheck(int point1,int mypoint,int flg); + +//BOOL NPC_ItemCheck(int meindex,int talker,int itemNo,int flg); +int NPC_FloorUse(int talker,int floor); +BOOL NPC_WarpMsg(int meindex,int talker,char *buf); +BOOL NPC_NpcWarpMsg(int meindex,int talker,char *arg); +int NPC_FloorUseOtherFloor(int charaindex, char *buf); + + +#ifdef _NPC_ADDLEVELUP +void NPC_LevelAndTransUp( int meindex, int charindex, int level, int skillpoint, int exp, int ridepet); +#endif + +#define WARPMAN_STANDBY 3000 +#define WARPMAN_WAIT 150 +//ANDY_ADD +int CheckWarpMsg( int meindex, int talkerindex,char *npcarg ,char *TalkStr); + +#ifdef _TREASURE_BOX +BOOL NPC_TreasureEventRunMsg( int meindex); +#endif + +BOOL NPC_TreasureRandItemGet(int meidex,int talker,int rand_j,char *buf); + +enum { + NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, + NPC_TIME_BORN = CHAR_NPCWORKINT2, + NPC_TIME_DEAD = CHAR_NPCWORKINT3, + NPC_TIME_MODE = CHAR_NPCWORKINT4, + + NPC_TIME_EVENTMODE = CHAR_NPCWORKINT6,// 1 + NPC_TIME_EVENTTIME = CHAR_NPCWORKINT7, + NPC_TIME_EVENONBBI = CHAR_NPCWORKINT8, + NPC_TIME_EVENOFFDBBI = CHAR_NPCWORKINT9, + NPC_TIME_EVENTNUM = CHAR_NPCWORKINT10, +}; + +enum{ + NPC_EVENTMODE_NONE, + NPC_EVENTMODE_OPEN, + NPC_EVENTMODE_EVENT, +}; + +#ifdef _NEW_WARPMAN +static void NPC_NewWarpMan_selectWindow( int meindex, int toindex, int num,int select,char *TalkStr); + +enum { + WARP_MAN=0, + NEW_WARPMAN, + NEW_WARPMAN_END + }; +#endif +#define TIMECHECKLOOP 20 +// Robin 0518 +//BOOL checkend = FALSE; + + +BOOL NPC_WarpManInit( int meindex ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buff2[256]; + char buf[1024]; + int fl,x,y; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("WarpMan:GetArgStrErr"); + return FALSE; + } + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWARPMAN ); +#ifdef _NEW_WARPMAN + if( strstr( npcarg,"NEWWARPMAN") ) { + //timeman + CHAR_setWorkInt( meindex, NPC_TIME_MODE, 1); + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NEWTIME", buff2, sizeof( buff2)) != NULL ){ + CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 60*1000); + } +#ifdef _TREASURE_BOX + CHAR_setWorkInt( meindex, NPC_TIME_EVENTMODE, NPC_EVENTMODE_NONE); + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "TREASURE_BOX", buff2, sizeof( buff2)) != NULL ){ + if( strstr( buff2, "ON") != NULL ){ + CHAR_setWorkInt( meindex, NPC_TIME_EVENTMODE, NPC_EVENTMODE_EVENT); + CHAR_setWorkInt( meindex, NPC_TIME_EVENTTIME, NowTime.tv_sec); + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "TREASURE_ONBBI", buff2, sizeof( buff2)) != NULL ) + CHAR_setWorkInt( meindex, NPC_TIME_EVENONBBI, atoi( buff2)); + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "TREASURE_OFFDBBI", buff2, sizeof( buff2)) != NULL ) + CHAR_setWorkInt( meindex, NPC_TIME_EVENOFFDBBI, atoi( buff2)); + CHAR_setWorkInt( meindex, NPC_TIME_EVENTNUM, 0 ); + } + } + +#endif + return TRUE; + }else{ +#endif + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf))==NULL){ + char filename[256]; + if( NPC_Util_CheckAssignArgFile( meindex, filename) != NULL ) + print("\n Warpman Err -> file:%s", filename); + return FALSE; + } + getStringFromIndexWithDelim(buf,",",1,buff2,sizeof(buff2)); + fl=atoi(buff2); + getStringFromIndexWithDelim(buf,",",2,buff2,sizeof(buff2)); + x=atoi(buff2); + getStringFromIndexWithDelim(buf,",",3,buff2,sizeof(buff2)); + y=atoi(buff2); + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + char filename[256]; + NPC_Util_CheckAssignArgFile( meindex, filename); + print( "\nWarp NPC: filename:%s\n 3.Invalid warpman ERR %d %d %d" , filename, fl , x , y ); + return FALSE; + } +#ifdef _NEW_WARPMAN + } +#endif + return TRUE; +} + +void NPC_WarpManTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[256]; + int RunType=-1; + + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace( meindex ,talkerindex ,2)==FALSE){ + if(NPC_Util_isFaceToChara(talkerindex,meindex,1 )==FALSE) return; + } + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + +#ifdef _NEW_WARPMAN + if( strstr( npcarg,"NEWWARPMAN") ) { +#ifdef _TREASURE_BOX + if( CHAR_getWorkInt( meindex, NPC_TIME_EVENTMODE) == NPC_EVENTMODE_OPEN ) + return; +#endif + NPC_NewWarpMan_selectWindow( meindex ,talkerindex, 0, -1, szMes); + return; + }else { + if(NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE) {// + NPC_ERR_DiSP( meindex, talkerindex, 1); + return; + } + + + RunType = CheckWarpMsg( meindex, talkerindex, npcarg , szMes); + if( RunType !=0 ) { + if( RunType == 1 ) { + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "nomal_msg", token, sizeof(token)) != NULL) { + CHAR_talkToCli( talkerindex, meindex,token,CHAR_COLORWHITE); + } + } + return; + } + } +#else + + + if(NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE) {// + NPC_ERR_DiSP( meindex, talkerindex, 1); + return; + } + RunType = CheckWarpMsg( meindex, talkerindex, npcarg , szMes); + if( RunType !=0 ) { + if( RunType == 1 ) { + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "nomal_msg", token, sizeof(token)) != NULL) { + CHAR_talkToCli( talkerindex, meindex,token,CHAR_COLORWHITE); + } + } + return; + } +#endif + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + CHAR_setWorkInt( talkerindex , CHAR_WORKSHOPRELEVANTTRD , 0 ); + if(strstr(npcarg,"DR")!=NULL) { + CHAR_setWorkInt( talkerindex , CHAR_WORKSHOPRELEVANTSEC , -1 ); + if(NPC_GetDuelPointCheck(meindex,talkerindex)==FALSE) return; + }else{ + NPC_WarpMan_selectWindow( meindex, talkerindex,0,-1); + } +} + +static void NPC_WarpMan_selectWindow( int meindex, int toindex, int num,int select) +{ + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + char buf[256]; + char buf2[1024]; + char buf3[256]; + int fl=0 ; + int money=100 ; + int fd = getfdFromCharaIndex( toindex); + char tmp[64]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); + return ; + } + + if(NPC_PARTY_CHAECK( meindex, toindex) == FALSE) { + NPC_ERR_DiSP( meindex, toindex, 1); + return; + } + + + if( CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT) != 0 ) { + return; + }else { + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 1); + } + + if(strstr(npcarg,"%4d")!=NULL){ + int flwork = 0; + int work; + NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf)); + getStringFromIndexWithDelim(buf,",",1,buf3,sizeof(buf3)); + work = atoi( buf3); + fl = NPC_FloorUse( toindex, atoi(buf3)); + + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "Floor", buf3, sizeof( buf3)) != NULL){ + flwork = NPC_FloorUseOtherFloor(work, buf3); + } + fl = fl +flwork; + } + + NPC_Util_GetStrFromStrWithDelim( npcarg, "FREE", buf, sizeof( buf)); + + if( (NPC_ActionPassCheck(meindex,toindex,buf)==TRUE) || (strstr(buf,"ALLFREE")!=NULL) ){ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "FreeMsg", buf2, sizeof( buf2))==NULL) return; + CONNECT_set_pass(fd,TRUE); + CONNECT_set_first_warp(fd,TRUE); + if(strstr(buf2,"%4d") != NULL){ + sprintf(token,buf2,fl); + }else{ + strcpy(token,buf2); + } + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANTTRD , -1 ); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 2); + }else { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "PayMsg", buf2, sizeof( buf2)) != NULL){ + CONNECT_set_pass(fd,FALSE); + CONNECT_set_first_warp(fd,FALSE); + if(strstr(buf2,"%8d") != NULL){ + NPC_Util_GetStrFromStrWithDelim( npcarg, "MONEY", tmp, sizeof( tmp)); + if(strstr(tmp,"LV")!=NULL){ + int level; + char buff2[32]; + + level = CHAR_getInt(toindex,CHAR_LV); + getStringFromIndexWithDelim(tmp,"*",2,buff2,sizeof(buff2)); + money = level*atoi(buff2); + }else{ + money=atoi(tmp); + } + if(strstr(buf2,"%4d") != NULL){ + sprintf(token,buf2,fl,money); + }else{ + sprintf(token,buf2,money); + } + }else if(strstr(buf2,"%4d") != NULL){ + sprintf(token,buf2,fl); + NPC_Util_GetStrFromStrWithDelim( npcarg, "MONEY", tmp, sizeof( tmp)); + if( strstr( tmp,"-" ) != NULL){ + money=10000001; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return ; + } + }else{ + strcpy(token,buf2); + NPC_Util_GetStrFromStrWithDelim( npcarg, "MONEY", tmp, sizeof( tmp)); + if( strstr( tmp,"-" ) != NULL){ + money=10000001; + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + return ; + }else{ + money = atoi(tmp); + } + } + if(CHAR_getInt(toindex,CHAR_FLOOR)==117){ + money=CHAR_getInt(toindex,CHAR_GOLD); + if (money>=10) money*=0.9; + else if( money == 0 ) { + CHAR_warpToSpecificPoint(toindex,117,225,13); + return; + } + } + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANTTRD , money ); + CONNECT_set_pass(fd,TRUE); + CONNECT_set_first_warp(fd,TRUE); + + }else if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NomalMsg", token,sizeof(token)) !=NULL){ + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANTTRD , -2 ); + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, -1); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + } + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_YESNO, + CHAR_WINDOWTYPE_WINDOWWARPMAN_MAIN, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +void NPC_WarpManWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[NPC_UTIL_GETARGSTR_BUFSIZE]; +#ifdef _NEW_WARPMAN + BOOL checkp=TRUE; + char buf1[1024]; + int talkNo = 1; + BOOL tenflg=FALSE; +#else + int fl,x,y; +#endif + char buff2[256]; + int fd = getfdFromCharaIndex( talkerindex ); + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) + return; + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) < 1 ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + +#ifdef _NEW_WARPMAN + if( seqno == NEW_WARPMAN ) { + int eqnum=0; + eqnum = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); + sprintf(buf1,"%s", "NOFREE"); + if( eqnum >= 0 ) { + sprintf(buf1,"TALKEVENT%d", eqnum); + } + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); + while( getStringFromIndexWithDelim( npcarg,"OVER",talkNo,buf,sizeof( buf)) != FALSE){ + if( strstr(buf, buf1) != NULL) { + strcpy( npcarg , buf); + tenflg = TRUE; + break; + } + talkNo++; + } + if( tenflg == FALSE ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + }else { +#endif + if( select != WINDOW_BUTTONTYPE_YES ) { + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + if(NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE){ + NPC_ERR_DiSP( meindex, talkerindex, 1); + return; + } +#ifdef _NEW_WARPMAN + } +#else + NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", buf, sizeof( buf)); + GetRand_WarpPoint( buf, &fl, &x, &y ); +#endif + +#ifdef _NEW_WARPMAN + switch( seqno) { + case WARP_MAN: + if( select != WINDOW_BUTTONTYPE_YES ) + return; + if( NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE ){ + NPC_ERR_DiSP( meindex, talkerindex, 1); + return; + } +#else + if( select != WINDOW_BUTTONTYPE_YES) return; + if( NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE) + return; +#endif + +#ifdef _NEW_WARPMAN + break; + case NEW_WARPMAN: + if( select != WINDOW_BUTTONTYPE_YES ){ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CancelMsg", buff2, sizeof( buff2) ) != NULL) { + CHAR_talkToCli( talkerindex, meindex, buff2, CHAR_COLORYELLOW); + } + return; + } + checkp=TRUE; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CHECKPARTY", buff2, sizeof( buff2) ) != NULL) { + if( strstr( buff2, "FALSE") != NULL ) { + checkp = FALSE; + } + } + if( checkp==TRUE && NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE ) { + NPC_ERR_DiSP( meindex, talkerindex, 1); + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + break; + case NEW_WARPMAN_END: + return; + break; + } +#endif + + if( Action_RunDoEventAction( meindex, talkerindex, npcarg) == FALSE ){ + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return; + } + + CHAR_complianceParameter( talkerindex ); + CHAR_send_P_StatusString( talkerindex , + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_CHARM|CHAR_P_STRING_QUICK| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND|CHAR_P_STRING_EARTH + ); + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE){ + return ; + } + if(CHAR_getWorkInt( talkerindex , CHAR_WORKSHOPRELEVANTTRD) <= 0){ + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); +#ifdef _NEW_WARPMAN + NPC_WarpMsg( meindex, talkerindex, npcarg); +#else + if( fl == 0 && x == 0 && y == 0 ) { + }else { + CHAR_warpToSpecificPoint(talkerindex, fl, x,y); + } +#endif + }else { + if(CHAR_getInt(talkerindex,CHAR_GOLD) < + CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD)){ + NPC_ERR_DiSP( meindex, talkerindex, 2); + return ; + } + CHAR_DelGold( talkerindex, CHAR_getWorkInt(talkerindex,CHAR_WORKSHOPRELEVANTTRD )); + + CHAR_setWorkInt( talkerindex, CHAR_WORKWARPCHECK, FALSE ); +#ifdef _NEW_WARPMAN + NPC_WarpMsg( meindex, talkerindex, npcarg); +#else + if( fl == 0 && x == 0 && y == 0 ) { + }else { + CHAR_warpToSpecificPoint(talkerindex, fl, x,y); + } +#endif + + } +#ifdef _NEW_WARPMAN + NPC_NpcWarpMsg( meindex, talkerindex, npcarg); +#else + } +#endif +} + +BOOL NPC_BigSmallLastCheck(int point1,int mypoint,int flg) +{ + if(flg==0){ + if(point1==mypoint) { + return TRUE; + } + + }else if(flg==1){ + if(mypoint < point1) { + return TRUE; + } + + }else if(flg==2){ + if(mypoint > point1) { + return TRUE; + } + } + + return FALSE; + +} + +BOOL NPC_GetDuelPointCheck(int meindex,int talker) +{ + + int fdid = getFdidFromCharaIndex( talker); + char dbkey[256]; + + if( fdid == -1 ) return FALSE; + + CHAR_makeDBKey( talker, dbkey, sizeof( dbkey)); + saacproto_DBGetEntryRank_send( acfd, DB_DUELPOINT, dbkey, fdid, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); + + return TRUE; + +} + +void NPC_GetDuelRank(int rank,int fdid,int objindex) +{ + int talker; + int meindex; + + rank++; + talker = getCharindexFromFdid( fdid); + if( talker == -1 ) return; + + meindex= OBJECT_getIndex( objindex); + if( !CHAR_CHECKINDEX( meindex)) return; + + CHAR_setWorkInt(talker,CHAR_WORKSHOPRELEVANTSEC,rank); + + NPC_WarpMan_selectWindow( meindex, talker,0,-1); + +} + +BOOL NPC_PARTY_CHAECK(int meindex,int talker) +{ + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ + return FALSE; + } + return TRUE; +} + +void NPC_ERR_DiSP(int meindex,int talker,int errNO) +{ + char token[1024]; + int i=0; + int otherindex; + int fd = getfdFromCharaIndex( talker); + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + if(errNO==1){ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "PartyMsg",token, sizeof( token))==NULL) { + sprintf(token,"\n\n޷Ŷӡ" + "\n\n ɢŶ "); + } + if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE)==CHAR_PARTY_CLIENT){ + }else{ + + for( i=0 ; i < getPartyNum(talker) ;i++){ + otherindex=CHAR_getWorkInt(talker,CHAR_WORKPARTYINDEX1+i); + if(otherindex != -1){ + fd = getfdFromCharaIndex( otherindex); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + } + } + return ; + } + }else if (errNO==2){ + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "MoneyMsg", token, sizeof( token))==NULL){ + sprintf(token,"\n\nƺǮࡡ" + "\n\nǮᣬٹ"); + } + } + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_WINDOWWARPMAN_ERR, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); +} + +int NPC_FloorUse(int charaindex,int floor) +{ + int i; + int players=0; + int playernum = CHAR_getPlayerMaxNum(); + for( i=0 ; i< playernum ; i++ ){ + if( CHAR_getCharUse(i) == FALSE )continue; + if(CHAR_getInt(i,CHAR_FLOOR)==floor){ + players++; + } + } + return players; +} + +int NPC_FloorUseOtherFloor(int warp, char *buf) +{ + int i,j=1; + int players=0; + int playernum = CHAR_getPlayerMaxNum(); + char buf2[32]; + int floor; + + for( i=0 ; i< playernum ; i++ ){ + if( CHAR_getCharUse(i) == FALSE )continue; + j=1; + while(getStringFromIndexWithDelim(buf,",",j,buf2,sizeof(buf2))!= FALSE){ + j++; + floor = atoi(buf2); + if(CHAR_getInt(i,CHAR_FLOOR) == floor && warp != floor) { + players++; + } + } + } + return players; +} + +BOOL NPC_WarpMsg(int meindex,int talker,char *arg) +{ + char buf[256]; + int fl=0,x=0,y=0; + int parent=-1; + int pmode; + int subindex; + int i; + + if( NPC_Util_GetStrFromStrWithDelim( arg, "WARP", buf, sizeof( buf)) == NULL ) + return FALSE; + GetRand_WarpPoint( buf, &fl, &x, &y ); + if( fl == 0 && x == 0 && y == 0 ) { + return TRUE; + }else { + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "Warp NPC:1.Invalid warpman ERR" ); + return FALSE; + } + } +#ifdef _TIME_TICKET + if( check_TimeTicketMap( fl) ) { + int havei, itemi; + CHAR_setWorkInt( talker, CHAR_WORKTICKETTIME, 0); + CHAR_setWorkInt( talker, CHAR_WORKTICKETTIMESTART, 0); + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talker); + for( havei = CHAR_STARTITEMARRAY ; havei < itemMax ; havei++ ){ +#else + for( havei = CHAR_STARTITEMARRAY; havei < CHAR_MAXITEMHAVE; havei ++ ) { +#endif + itemi = CHAR_getItemIndex( talker, havei); + if( !ITEM_CHECKINDEX( itemi) ) continue; + if( strcmp( ITEM_getChar( itemi, ITEM_USEFUNC), "ITEM_timeticket") ) continue; + //if( ITEM_getInt( itemi ,ITEM_ID) != 20646 ) continue; + CHAR_talkToCli( talker, -1, "ԶʹƱ", CHAR_COLORYELLOW); + ITEM_timeticketEx( talker, talker, havei, 1); + break; + } +#ifdef _NEW_ITEM_ + if( havei == itemMax ) { +#else + if( havei == CHAR_MAXITEMHAVE ) { +#endif + CHAR_talkToCli( talker, -1, "׼רƱſɽ롣", CHAR_COLORYELLOW); + return FALSE; + } + } +#endif + pmode = CHAR_getWorkInt( talker, CHAR_WORKPARTYMODE ); + switch( pmode ){ + case 1: + parent = talker; + break; + case 2: + parent = CHAR_getWorkInt( talker, CHAR_WORKPARTYINDEX1 ); + break; + default: + CHAR_warpToSpecificPoint(talker, fl, x,y); + return TRUE; + } + if( parent < 0 ) + return TRUE; + if( NPC_Util_GetStrFromStrWithDelim( arg, "PartyMsg", buf, sizeof( buf))) + return TRUE; + + + + for( i = 0; i < getPartyNum(parent); i ++ ) + { + subindex = CHAR_getWorkInt( parent, CHAR_WORKPARTYINDEX1+i ); + if( CHAR_CHECKINDEX( subindex ) == FALSE )continue; + if( fl==0 && x==0 && y==0 ) { + }else { + CHAR_warpToSpecificPoint( subindex, fl, x, y ); + } + } + return TRUE; +} + +#ifdef _NEW_WARPMAN +static void NPC_NewWarpMan_selectWindow( int meindex, int toindex, int num,int select,char *TalkStr) +{ + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + char token[1024]; + int buttontype = 0, windowtype = 0, windowno = 0; + char buf[NPC_UTIL_GETARGSTR_BUFSIZE],buf1[256]; + int fd = getfdFromCharaIndex( toindex); + BOOL tenflg =FALSE; + int talkNo=1,RunType=-1; + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("GetArgStrErr"); + return ; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "NEWTIME", buf1, sizeof( buf1)) != NULL ){ + if( CHAR_getWorkInt( meindex, NPC_TIME_MODE) <= 0 ) { + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "Time_Msg", token, sizeof( token) ) != NULL) { + CHAR_talkToCli( toindex, meindex, token, CHAR_COLORYELLOW); + } + return; + } + } + + windowtype = WINDOW_MESSAGETYPE_MESSAGE; + sprintf( buf1,"TALKEVENT"); + //ѰҶ FREE + while(getStringFromIndexWithDelim( npcarg,"OVER",talkNo,buf,sizeof( buf)) != FALSE) { + if(strstr(buf, buf1) != NULL) { + //Ի + RunType = CheckWarpMsg( meindex, toindex, buf , TalkStr); + if( RunType > 1 ) { + return; + }else if( RunType != 0 ) { + talkNo++; + continue; + } + if( NPC_Util_GetStrFromStrWithDelim( buf, "FREE", token, sizeof( token) ) == NULL) { + print("msgErr"); + return; + } + + //Ƿ񸽺 + if((NPC_ActionPassCheck(meindex,toindex,token)==TRUE) || (strstr( token, "ALLFREE")!=NULL) ) { + CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, talkNo-1); + + // ȡ FreeMsg ִ + if(NPC_Util_GetStrFromStrWithDelim( buf, "FreeMsg", token, sizeof( token))==NULL) + return; + CONNECT_set_pass(fd,TRUE); + CONNECT_set_first_warp(fd,TRUE); + buttontype = WINDOW_BUTTONTYPE_YESNO; + windowno = NEW_WARPMAN; + tenflg = TRUE; + CHAR_setWorkInt( toindex , CHAR_WORKSHOPRELEVANTTRD , -1 ); + break; + } + } + talkNo++; + } + + //κ + if( tenflg == FALSE ) { + if( getStringFromIndexWithDelim( npcarg,"OVER",1,buf,sizeof( buf)) == FALSE ) + return; + if( strstr( buf, "NOFREE") == NULL ) { + return; + }else { + strcpy( npcarg, buf); + } + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NomalMsg", token,sizeof(token)) != NULL) { + CHAR_talkToCli( toindex, meindex, token,CHAR_COLORWHITE); + return; + } + } + + //ѶϢ CLI + lssproto_WN_send( fd, windowtype, buttontype, windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token ); +} + +#endif +//ANDY_RE +int CheckWarpMsg( int meindex, int talkerindex,char *npcarg ,char *TalkStr) +{ + char buf[1024]; + char buf2[256]; + int i = 1; + int flg = 0; + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "warp_msg", buf, sizeof( buf) ) == NULL) + return 0; + if( strcmp( buf, TalkStr) ) + return 1; + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "CHECKPARTY", buf, sizeof( buf) ) != NULL) { + if( strstr( buf, "FALSE") != NULL ) { + }else { + if( NPC_PARTY_CHAECK( meindex, talkerindex) == FALSE ) { + NPC_ERR_DiSP( meindex, talkerindex, 1); + return 2; + } + } + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FREE", buf, sizeof( buf)) == NULL ) + return 2; + if( ( NPC_ActionPassCheck( meindex, talkerindex, buf ) == FALSE) ) { + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "NomalMsg", buf,sizeof(buf)) != NULL) { + CHAR_talkToCli( talkerindex, meindex,buf,CHAR_COLORWHITE); + } + return 2; + }else { + if( Action_RunDoEventAction( meindex, talkerindex, npcarg) == FALSE ){ + + CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, -1); + return 3; + } + CHAR_complianceParameter( talkerindex ); + CHAR_send_P_StatusString( talkerindex , + CHAR_P_STRING_ATK|CHAR_P_STRING_DEF| + CHAR_P_STRING_CHARM|CHAR_P_STRING_QUICK| + CHAR_P_STRING_WATER|CHAR_P_STRING_FIRE| + CHAR_P_STRING_WIND|CHAR_P_STRING_EARTH ); + + if(NPC_Util_GetStrFromStrWithDelim( npcarg, "FreeMsg", buf, sizeof( buf)) != NULL ){ + CHAR_talkToCli( talkerindex, meindex, buf, CHAR_COLORWHITE); + } + + NPC_WarpMsg( meindex, talkerindex, npcarg); + NPC_NpcWarpMsg( meindex, talkerindex, npcarg); + return 4; + } + return 0; +} + +BOOL NPC_NpcWarpMsg(int meindex,int talker,char *arg) +{ + char buf[256]; + int fl=0,x=0,y=0; + + if( CHAR_CHECKINDEX( meindex ) == FALSE ) + return FALSE; + + if( NPC_Util_GetStrFromStrWithDelim( arg, "NPCPOINT", buf, sizeof( buf)) == NULL ) + return FALSE; + GetRand_WarpPoint( buf, &fl, &x, &y ); + + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "Warp NPC:2.Invalid warpman ERR" ); + return FALSE; + } + + CHAR_warpToSpecificPoint( meindex, fl, x, y ); + + return TRUE; +} + +void NPC_WarpManLoop( int meindex) +{ + int born, dead; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + if( !CHAR_CHECKINDEX( meindex) ) return; + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL ){ + print("WarpMan:GetArgStrErr"); + return; + } + if( !strstr( npcarg,"NEWWARPMAN") ) + return; + + if( NPC_getTimeData( meindex, npcarg, &born, &dead, 200) != FALSE ){ + NPC_TimeDefineDo( meindex, born, dead, NPC_TIME_MODE); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + } +} + +void NPC_WarpManWatch( int meobjindex, int objindex, CHAR_ACTION act, + int x,int y,int dir, int* opt,int optlen ) +{ + int born, dead; + int meindex, index; + + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + if( OBJECT_getType( objindex) != OBJTYPE_CHARA) return; + index = OBJECT_getIndex( objindex); + if( !CHAR_CHECKINDEX( index) ) return; + if( CHAR_getInt( index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return; + meindex = OBJECT_getIndex( meobjindex); + if( !CHAR_CHECKINDEX( meindex) ) return; + + if( NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg)) == NULL ){ + print("WarpMan:GetArgStrErr"); + return; + } + if( !strstr( npcarg,"NEWWARPMAN") ) + return; +#ifdef _TREASURE_BOX + if( CHAR_getWorkInt( meindex, NPC_TIME_EVENTMODE) == NPC_EVENTMODE_OPEN ){ + if( CHAR_getWorkInt( meindex, NPC_TIME_EVENTTIME) < NowTime.tv_sec ){ + //ر + CHAR_setWorkInt( meindex, NPC_TIME_EVENTMODE, NPC_EVENTMODE_EVENT); + //ͼ + CHAR_setInt( meindex, CHAR_BASEBASEIMAGENUMBER, + CHAR_getWorkInt( meindex, NPC_TIME_EVENOFFDBBI)); + CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, + CHAR_getWorkInt( meindex, NPC_TIME_EVENOFFDBBI)); + NPC_TreasureEventRunMsg( meindex); //Ƿwarp + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + } + } +#endif + if( NPC_getTimeData( meindex, npcarg, &born, &dead, 200) != FALSE ){ + NPC_TimeDefineDo( meindex, born, dead, NPC_TIME_MODE); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX ) ); + } +} + +#ifdef _TREASURE_BOX +BOOL NPC_TreasureEventRunMsg( int meindex) +{ + char buf[256]; + char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; + + int fl,x,y; + + if( !CHAR_CHECKINDEX( meindex )) + return FALSE; + + + if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ + print("WarpMan:GetArgStrErr"); + return FALSE; + } + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "TREASURE_NUM", buf, sizeof( buf)) == NULL ) + return FALSE; + + if( CHAR_getWorkInt( meindex, NPC_TIME_EVENTNUM) < atoi( buf) ) return FALSE; + CHAR_setWorkInt( meindex, NPC_TIME_EVENTNUM, 0); + + if( NPC_Util_GetStrFromStrWithDelim( npcarg, "TREASURE_POINT", buf, sizeof( buf)) == NULL ) + return FALSE; + GetRand_WarpPoint( buf, &fl, &x, &y ); + + if( MAP_IsValidCoordinate( fl,x,y )== FALSE ){ + print( "Warp NPC:2.Invalid warpman ERR" ); + return FALSE; + } + + CHAR_warpToSpecificPoint( meindex, fl, x, y ); + return TRUE; +} + +#endif + +BOOL NPC_TreasureRandItemGet(int meidex,int talker,int rand_j,char *buf) +{ + char buff2[64]; + int randitem; + int ret; + int itemindex; + char token[128]; + + if(rand_j == 0) { + print("Event:춣Ľ룬ִ"); + return FALSE; + } + + randitem = rand()%rand_j; + if(randitem == 0) randitem = rand_j; + + getStringFromIndexWithDelim(buf , "," , randitem, buff2, sizeof(buff2)) ; + + itemindex = ITEM_makeItemAndRegist( atoi( buff2)); + if(itemindex == -1) return FALSE; + /*ʧ ةܰ( ʧ ة ľ */ + ret = CHAR_addItemSpecificItemIndex( talker, itemindex); + if( !CHAR_CHECKITEMINDEX( talker, ret) ){ + print( "npc_exchangeman.c: additem error itemindex[%d]\n", itemindex); + ITEM_endExistItemsOne( itemindex); + return FALSE; + } + + if(itemindex != -1) { + LogItem( + CHAR_getChar( talker, CHAR_NAME ), /* ƽҷ */ + CHAR_getChar( talker, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID), /* ʧ ة į */ +#endif + "EventAddItem(õĵ)", + CHAR_getInt( talker,CHAR_FLOOR), + CHAR_getInt( talker,CHAR_X ), + CHAR_getInt( talker,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + } + + sprintf(token,"%s",ITEM_getChar( itemindex, ITEM_NAME)); + CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); + + CHAR_sendItemDataOne( talker, ret); + return TRUE; + +} + +#ifdef _NPC_ADDLEVELUP // (ɿ) ANDY ⲿԻҵȼ +extern tagRidePetTable ridePetTable[296]; +void NPC_LevelAndTransUp( int meindex, int charindex, int level, int skillpoint, int exp, int ridepet) +{ + char szBuffer[256]=""; + if( !CHAR_CHECKINDEX( charindex) ) + return; +//int CHAR_LevelUpCheck( int charaindex , int toindex) + if( exp > 0 ){ + int LevelUp=0; + int myexp = CHAR_getInt( charindex, CHAR_EXP); + myexp += exp; + if( myexp > 300000000 ) myexp = 300000000; + CHAR_setInt( charindex, CHAR_EXP, myexp); + snprintf( szBuffer, sizeof(szBuffer), + "(%s) õ EXP %d", CHAR_getUseName( charindex ), exp); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + LevelUp = CHAR_LevelUpCheck( charindex , -1); + if( LevelUp > 0 ){ + snprintf( szBuffer, sizeof(szBuffer), + "(%s) %d", + CHAR_getUseName( charindex ), + CHAR_getInt( charindex, CHAR_LV ) + ); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + CHAR_setInt( charindex, CHAR_SKILLUPPOINT, + CHAR_getInt( charindex, CHAR_SKILLUPPOINT) + LevelUp*3 ); + CHAR_complianceParameter( charindex ); + } + } + + if( level > 0 ){ + CHAR_setInt( charindex, CHAR_LV, level); + snprintf( szBuffer, sizeof(szBuffer), + "(%s) ȼ趨Ϊ %d", + CHAR_getUseName( charindex ), CHAR_getInt( charindex, CHAR_LV ) + ); + CHAR_talkToCli( charindex, -1, szBuffer, CHAR_COLORYELLOW); + } + + if( skillpoint > 0 ){ + int MySp = CHAR_getInt( charindex, CHAR_SKILLUPPOINT); + MySp += skillpoint; + CHAR_setInt( charindex, CHAR_SKILLUPPOINT, MySp); + } + if( ridepet >= 0 ){ + int basepet[2][4]={ {2066,2067,2068,2069}, + {2072,2073,2074,2075}}; + int petTemp[]={-1,-1,-1,-1,-1}; + char msgbuf[256]; + int petNum=0; + int i,j=0; + int k=0, petindex,enemyarray; + petTemp[j++] = basepet[0][rand()%4]; + petTemp[j++] = basepet[1][rand()%4]; + + for( i=0; i< arraysizeof(ridePetTable) ; i++ ){ + if( CHAR_getInt( charindex, CHAR_BASEBASEIMAGENUMBER) == ridePetTable[i].charNo ){ + petTemp[j]= ridePetTable[i].petId; + j++; + if( j >= arraysizeof( petTemp) ) + break; + } + } + j=0; + for( petNum=0; petNum +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "pet_skill.h" +#include "readmap.h" +#include "battle.h" +#include "profession_skill.h" +#include "chatmagic.h" +#include "npc_welfare.h" +#include "npc_exchangeman.h" + +static void NPC_Welfare_selectWindow(int meindex, int toindex, int num, int select); + + +//ÿNPCijʼ +BOOL NPC_WelfareInit( int meindex ) +{ + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWELFARE); + //print(":%s\n",CHAR_getChar( meindex, CHAR_NAME)); + return TRUE; +} + +//ԻʱĴ +void NPC_WelfareTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + } + NPC_Welfare_selectWindow( meindex, talkerindex,0,-1); +} + +static void NPC_Welfare_selectWindow( int meindex, int toindex, int num,int select) +{ + switch(num){ + case 0: + //free + NPC_WelfareMakeStr(meindex, toindex, select); + break; + case 1: + break; + } +} + +void NPC_WelfareWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + int skill, i, j; + int cost; + int skillID=0; + char buf[64]; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[512]; + char message[64]; + int fd = getfdFromCharaIndex( talkerindex ); + double rate= 1.0; + int skillarray; + int p_class=0, need_class=0; + int profession_skill_point; + + memset( message, -1, sizeof(message) ); + + if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) { + return; + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return; + } + + makeStringFromEscaped( data); + getStringFromIndexWithDelim(data,"|",1,buf,sizeof(buf)); + skill=atoi(buf); + getStringFromIndexWithDelim(data,"|",2,buf,sizeof(buf)); + cost=atoi(buf); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_skill", msg, sizeof( msg)) != NULL){ + getStringFromIndexWithDelim(msg,",",skill,buf,sizeof(buf)); + skillID=atoi(buf); + } + + + if(skillID < 0) return ; + + if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ + rate = atof( msg); + } + + skillarray = PROFESSION_SKILL_getskillArray( skillID ); + + if(skillarray == -1){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return ; + } + + // жְҵ + { + if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_class", msg, sizeof(msg) ) == NULL){ + return ; + }else{ + p_class = atoi(msg); + } + + // ְҵ + need_class = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_PROFESSION_CLASS ); + + if( CHAR_getInt( talkerindex, PROFESSION_CLASS ) == 0 ){ + char token[256]; + memset(token, -1, sizeof(token) ); + sprintf( token, "δְ!" ); + CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + + } + + if( CHAR_getInt( talkerindex, PROFESSION_CLASS ) != need_class && need_class != 4 ){ + char token[256]; + memset(token, -1, sizeof(token) ); + sprintf( token, "˼㲻ѧ!" ); + CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + + + } + + // жʣ + { + profession_skill_point = CHAR_getInt( talkerindex, PROFESSION_SKILL_POINT ); + if( profession_skill_point <= 0 ){ + char token[256]; + memset(token, -1, sizeof(token) ); + sprintf( token, "Ŀǰûѧϰ!" ); + CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + } + + // жǷѧϰ + { + int temp[4] = {0}, count = 0, flag = -1 , need_percent = -1, need_count = 0; + + for( i=0; i<4; i++){ + int limit = -1; + flag = -1; + limit = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_LIMIT1+i*2 ); + need_percent = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_LIMIT1+i*2 + 1 ); + + if( limit!= 0 && need_percent == 0 ) need_count++; + + if( limit == 0 ){ + continue; + }else if( limit == -1 ){ + for( j=0; j 0 ) break; + } + if( j >= PROFESSION_MAX_LEVEL ){ + char token[256]; + sprintf( token, "ѧΣսܲѧϰ"); + CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + }else{ + flag = -1; + for( j=0; jskill, SKILL_LEVEL); + + // ж + if( skill_level >= need_percent ){ + flag = 1; break; + } + } + } + + // δ + if( flag == -1 && need_percent == 0 ){ + temp[count] = limit; + count ++; + }else if( flag == -1 ){ + char token[256]; + memset(token, -1, sizeof(token) ); + sprintf( token, "δѧ%s!", PROFESSION_SKILL_getChar( limit, PROFESSION_SKILL_NAME) ); + CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + }else if( flag == -2 ){ + char token[256]; + memset(token, -1, sizeof(token) ); + sprintf( token, "%sȲ%d!", PROFESSION_SKILL_getChar( limit, PROFESSION_SKILL_NAME), need_percent ); + CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + } + } + + if( count == need_count && need_count != 0 ){ + char msg[256] = {0}; + + sprintf( msg, "ѧ " ); + for( i = 0; i< count; i++ ){ + if( temp[i] != 0 ){ + char token[50] = {0}; + sprintf( token, "%s ", PROFESSION_SKILL_getChar( temp[i], PROFESSION_SKILL_NAME) ); + strcat( msg, token ); + } + } + sprintf( msg, "%s һּ", msg ); + CHAR_talkToCli( talkerindex, -1, msg, CHAR_COLORYELLOW); + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + + return; + } + + } + + // жϽǮ + { + cost = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_COST ); + cost = cost * rate; + + if(CHAR_getInt(talkerindex,CHAR_GOLD) < cost){ + CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); + return; + } + } + +#ifdef _NPC_ProfessionTrans + //жת + { + if( NPC_Util_GetStrFromStrWithDelim( argstr, "trans", msg, sizeof(msg) ) != NULL){ + int trans = atoi(msg); + print("\nתҪ:%d,%d",CHAR_getInt( talkerindex, CHAR_TRANSMIGRATION),trans); + if( CHAR_getInt( talkerindex, CHAR_TRANSMIGRATION) < trans){ + if( NPC_Util_GetStrFromStrWithDelim( argstr, "trans_msg", msg, sizeof(msg) ) != NULL){ + CHAR_talkToCli( talkerindex, meindex, msg, CHAR_COLORYELLOW); + return; + } + else{ + CHAR_talkToCli( talkerindex, meindex, "תŶ", CHAR_COLORYELLOW); + return; + } + } + } + } +#endif + + // Ӽ + { + int skill_level = 0; + + // ͨȸ5010 + if( (skillID == 63) || (skillID == 64) || (skillID == 65) ){ + int Pskillid = -1; + skill_level = 50; + Pskillid = PROFESSION_SKILL_getskillArray( skillID ); + }else{ + skill_level = 10; + } + + if( PROFESSION_SKILL_ADDSK( talkerindex, skillID, skill_level ) == -1 ) return; + + CHAR_DelGold( talkerindex, cost ); + + CHAR_sendStatusString( talkerindex , "S"); + + NPC_Welfare_selectWindow( meindex, talkerindex,0,-1); + } + + // ѶϢ + { + char token[256]; + int next_profession_skill_point = profession_skill_point-1; + + CHAR_setInt( talkerindex, PROFESSION_SKILL_POINT, next_profession_skill_point ); + + memset(token, -1, sizeof(token) ); + sprintf( token, "ѧϰ %sʣѧϰ %d" + ,PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_NAME ) + ,next_profession_skill_point ); + CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW); + + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( talkerindex , CHAR_WORKOBJINDEX )); + } + +} + +void NPC_WelfareMakeStr(int meindex,int toindex,int select) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char msg[256]; + double rate=1.0; + int i=0; + char token[65530]; + int fd = getfdFromCharaIndex( toindex); + + if(select==0){ + sprintf(token,"0|0"); + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PETSKILLSHOP, + WINDOW_BUTTONTYPE_NONE, + CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + } + + if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ + print("GetArgStrErr"); + return; + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", msg, sizeof( msg)) == NULL){ + print("mainERR"); + return ; + } + + sprintf(token,"1|%s|%s", CHAR_getChar(meindex,CHAR_NAME), msg); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ + rate=atof(msg); + } + + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_skill", msg, sizeof( msg) ) != NULL){ + int skillarray; + int skillID; + int cost; + char token2[265]; + char buf[64]; + + i=1; + while( getStringFromIndexWithDelim(msg,",",i,buf,sizeof(buf)) !=FALSE ){ + i++; + skillID=atoi(buf); + + skillarray = PROFESSION_SKILL_getskillArray( skillID ); + + if( PROFESSION_SKILL_CHECKINDEX( skillarray ) == FALSE ) continue; + + cost = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_COST ); + + cost = (int)cost*rate; + + sprintf(token2,"|%s|%d|%s|%d", + PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_NAME ), // + cost, // + PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_TXT ), // ˵ + PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_ICON ) // ͼʾ + ); + strcat(token,token2); + } + } + + lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PROFESSIONSHOP, + WINDOW_BUTTONTYPE_NONE, + WINDOW_MESSAGETYPE_PROFESSIONSHOP, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + token); + + return; +} + + +#endif +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_windowhealer.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_windowhealer.c new file mode 100644 index 0000000..9d885d8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npc_windowhealer.c @@ -0,0 +1,703 @@ +#include "version.h" +#include +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "lssproto_serv.h" +#include "npc_windowhealer.h" + + + +#define RATE 1000 + + +/* + * ɬýľūëNPC + * + */ + +enum { + CHAR_WORK_LEVEL = CHAR_NPCWORKINT1, + CHAR_WORK_RANGE = CHAR_NPCWORKINT2, + CHAR_WORK_HP = CHAR_NPCWORKINT3, + CHAR_WORK_MP = CHAR_NPCWORKINT4, + +}; + + +static void NPC_WindowHealer_selectWindow( int meindex, int toindex, int num); +void NPC_WindowHealerAllHeal( int talker,int mode ); +BOOL NPC_WindowHealerLevelCheck(int meindex,int talker); +BOOL NPC_WindowMoneyCheck(int meindex,int talker,int mode); +int NPC_WindowCostCheck(int meindex,int talker); +BOOL NPC_PetHealerCheck(int talker); +int NPC_WindowCostCheckMp(int meindex,int talker); + + +/********************************* +*********************************/ +BOOL NPC_WindowHealerInit( int meindex ) +{ + + char *npcarg; + char buf2[256]; + int range=1; + int rate; + double drate; + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEHEALER ); + + npcarg = CHAR_getChar(meindex,CHAR_NPCARGUMENT); + + /*--弰ëìëʢ--*/ + if(getStringFromIndexWithDelim(npcarg,"|",1,buf2,sizeof(buf2))!=FALSE){ + CHAR_setWorkInt(meindex,CHAR_WORK_LEVEL,atoi(buf2)); + + }else{ + return FALSE; + } + if(getStringFromIndexWithDelim(npcarg, "|", 2, buf2, sizeof( buf2)) != FALSE ){ + drate = atof(buf2); + if(drate==0) { + rate=500; + }else{ + rate=(int) (drate * RATE); + } + CHAR_setWorkInt(meindex,CHAR_WORK_HP,rate); + } + if(getStringFromIndexWithDelim(npcarg, "|", 3, buf2, sizeof( buf2)) != FALSE ){ + drate = atof(buf2); + if(drate==0){ + rate=2000; + }else{ + rate=(int)( drate * RATE); + } + CHAR_setWorkInt(meindex,CHAR_WORK_MP,rate); + } + if(getStringFromIndexWithDelim(npcarg, "|", 4, buf2, sizeof( buf2)) != FALSE ){ + range=atoi(buf2); + if(range == 0){ + range=1; + } + } + CHAR_setWorkInt(meindex,CHAR_WORK_RANGE,range); + return TRUE; + +} + +void NPC_WindowHealerTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + + if( NPC_Util_CharDistance( talkerindex, meindex ) + > CHAR_getWorkInt(meindex,CHAR_WORK_RANGE)){ + return; + } + if( (CHAR_getWorkInt(talkerindex,CHAR_WORKPARTYMODE) == 0) + || (CHAR_getWorkInt(talkerindex,CHAR_WORKPARTYMODE) == 2) ){ + NPC_WindowHealer_selectWindow( meindex, talkerindex,0); + }else{ + int i=0; + int otherindex; + + + for( i = 0; i < getPartyNum(talkerindex); i ++ ) + + { + otherindex=CHAR_getWorkInt(talkerindex,CHAR_WORKPARTYINDEX1+i); + if(otherindex != -1){ + NPC_WindowHealer_selectWindow( meindex, otherindex,0); + } + } + } +} +void NPC_WindowHealerLooked( int meindex , int lookedindex) +{ + if( CHAR_getInt( lookedindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( NPC_Util_CharDistance( lookedindex, meindex ) + > CHAR_getWorkInt(meindex,CHAR_WORK_RANGE)){ + return; + } + NPC_WindowHealer_selectWindow( meindex, lookedindex,0); +} + +static void NPC_WindowHealer_selectWindow( int meindex, int toindex, int num) +{ + + char token[1024]; + char escapedname[1024]; + int fd = getfdFromCharaIndex( toindex); + int buttontype=0; + int windowtype=0; + int windowno=0; + + /*--̼⻥мƥƱɬ--*/ + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + + switch( num){ + case 0: + sprintf(token," ѽ𣿡 \n\n " + " ;ظ \n" + " ظ \n" + " ;ظ \n\n" + " ظ() " + ); + + buttontype=WINDOW_BUTTONTYPE_CANCEL; + windowtype=WINDOW_MESSAGETYPE_SELECT; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_STARTMSG; + break; + + + case 1: + if( CHAR_getInt(toindex,CHAR_HP) ==CHAR_getWorkInt( toindex, CHAR_WORKMAXHP)){ + if(NPC_PetHealerCheck(toindex)==FALSE){ + sprintf(token, + " ;ظ" + "\n\n\n\nƺûбҪظࡣ"); + }else{ + sprintf(token, + " ;ظ" + "\n\n ƺûбҪظࡣ" + "\n\nΪҲˣ" + "\n Ȱظɣ"); + + NPC_WindowHealerAllHeal(toindex,0 ); + } + + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_HPMSG; + break; + }else if(NPC_WindowHealerLevelCheck(meindex,toindex)==TRUE){ + sprintf(token," ;ظ" + "\n\n\nҪظ;ûɣ " + "\n\nڵĵȼѰظࡣ"); + + }else{ + int gold; + gold=NPC_WindowCostCheck(meindex,toindex); + sprintf(token," ;ظ" + "\n\n\nҪظ;ûɣ " + "\n\n%dSTONE " + ,gold); + } + + buttontype=WINDOW_BUTTONTYPE_YESNO; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_HPMSG; + break; + + case 2: + if( CHAR_getInt(toindex,CHAR_MP) ==CHAR_getWorkInt( toindex, CHAR_WORKMAXMP)){ + if(NPC_PetHealerCheck(toindex)==FALSE){ + sprintf(token, " ظ" + "\n\n\n\nƺûбҪظࡣ"); + }else{ + sprintf(token, " ظ" + "\n\n ƺûбҪظࡣ" + "\n\nΪҲˣ" + "\n Ȱظɣ"); + NPC_WindowHealerAllHeal(toindex,0 ); + } + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_SPIRITMSG; + break; + } + + if(NPC_WindowHealerLevelCheck(meindex,toindex)==TRUE){ + sprintf(token," ظ" + "\n\nҪظûɣ " + "\n\n ڵĵȼѰظࡣ"); + }else{ + int cost; + cost=NPC_WindowCostCheckMp(meindex,toindex); + sprintf(token," ظ" + "\n\n\nҪظûɣ " + "\n\n%dSTONE ", + cost); + } + buttontype=WINDOW_BUTTONTYPE_YESNO; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_SPIRITMSG; + break; + + + case 3: + sprintf(token, "\n;ѻظ" + "\n Ҳѻظһ״̬" + "\n\n\n Ӿûˣ"); + + NPC_WindowHealerAllHeal( toindex ,1 ); + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG; + break; + + + case 4: + sprintf(token, "\nѻظ" + "\n Ҳѻظһ״̬" + "\n\n\n Ӿûˣ "); + NPC_WindowHealerAllHeal( toindex ,2 ); + buttontype=WINDOW_BUTTONTYPE_OK; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKSPIRITMSG; + break; + + + case 6: + { + int cost=0; + + if(CHAR_getInt(toindex,CHAR_HP) < CHAR_getWorkInt( toindex, CHAR_WORKMAXHP)) + { + cost+=NPC_WindowCostCheck(meindex,toindex); + } + + if( CHAR_getInt(toindex,CHAR_MP) < CHAR_getWorkInt( toindex, CHAR_WORKMAXMP)) + { + cost=cost+NPC_WindowCostCheckMp(meindex,toindex); + } + + if(cost==0) { + if(NPC_PetHealerCheck(toindex)==FALSE){ + sprintf(token, + " ;ظ" + "\n\n\n\nƺûбҪظࡣ"); + }else{ + sprintf(token," ;ظ" + "\n\n ƺûбҪظࡣ" + "\n\nΪҲˣ" + "\n Ȱظɣ"); + NPC_WindowHealerAllHeal(toindex,0 ); + } + + + + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_SPIRITMSG; + break; + + }else{ + sprintf(token," ;ظ" + "\n\n\n Ҫظ;ûɣ" + "\n\n%dSTONE ",cost); + } + } + + if(NPC_WindowHealerLevelCheck(meindex,toindex)==TRUE){ + sprintf(token," ;ظ" + "\n\n\n Ҫظ;ûɣ" + "\n\nڵĵȼѰظࡣ"); + } + + buttontype=WINDOW_BUTTONTYPE_YESNO; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_ALLMSG; + break; + + + case 7: + sprintf(token," ;ѻظ" + "\n Ҳѻظһ״̬" + "\n\n\nһͻظˣ"); + + NPC_WindowHealerAllHeal( toindex ,3 ); + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKALLMSG; + break; + + + case 8: + sprintf(token,"\n\n\n\n ϧƺĽǮࡣ"); + + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG; + break; + + case 9: + sprintf(token,"ظ" + "\n\n\nѾû" + "\n\n̫ǿĻҲࡣ"); + NPC_WindowHealerAllHeal(toindex,0 ); + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG; + break; + + case 10: + sprintf(token,"ظ" + "\n\n\n ƺûбҪظӡ" + "\n\n̫ǿĻҲࡣ"); + buttontype=WINDOW_BUTTONTYPE_OK; + windowtype=WINDOW_MESSAGETYPE_MESSAGE; + windowno=CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG; + break; + + + } + + + makeEscapeString( token, escapedname, sizeof(escapedname)); + /*-ƥ˪--*/ + lssproto_WN_send( fd, windowtype, + buttontype, + windowno, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + escapedname); + +} + + +/*----------------------------------------- +-------------------------------------------*/ +void NPC_WindowHealerWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) +{ + + if( NPC_Util_CharDistance( talkerindex, meindex ) > (CHAR_getWorkInt(meindex,CHAR_WORK_RANGE)+4)) return; + + switch( seqno){ + case CHAR_WINDOWTYPE_WINDOWHEALER_STARTMSG: + if(atoi(data)==2) /*-- 1--*/ + { + NPC_WindowHealer_selectWindow( meindex, talkerindex, 1 ); + + }else if(atoi(data)==3){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 2 ); + + }else if(atoi(data)==4){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 6 ); + + }else if(atoi(data)==6){ + if(NPC_PetHealerCheck( talkerindex)==TRUE){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 9 ); + }else{ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 10 ); + } + }else if(select==WINDOW_BUTTONTYPE_CANCEL){ + } + break; + + + case CHAR_WINDOWTYPE_WINDOWHEALER_HPMSG: + if(select==WINDOW_BUTTONTYPE_OK){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + + }else if(select==WINDOW_BUTTONTYPE_YES){ + /*--ż--*/ + if(NPC_WindowMoneyCheck(meindex,talkerindex,1)==TRUE){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 3 ); + }else{ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 8 ); + } + }else if(select==WINDOW_BUTTONTYPE_NO){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + + } + break; + + + case CHAR_WINDOWTYPE_WINDOWHEALER_SPIRITMSG: + if(select==WINDOW_BUTTONTYPE_OK){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + + }else if(select==WINDOW_BUTTONTYPE_YES){ + /*--ż--*/ + if(NPC_WindowMoneyCheck(meindex,talkerindex,2)==TRUE){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 4 ); + }else{ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 8 ); + } + + }else if(select==WINDOW_BUTTONTYPE_NO){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + } + + break; + + + case CHAR_WINDOWTYPE_WINDOWHEALER_OKHPMSG: + if(select==WINDOW_BUTTONTYPE_OK){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + } + break; + + + case CHAR_WINDOWTYPE_WINDOWHEALER_OKSPIRITMSG: + if(select==WINDOW_BUTTONTYPE_OK){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + } + break; + + + /*----*/ + case CHAR_WINDOWTYPE_WINDOWHEALER_ALLMSG: + if(select==WINDOW_BUTTONTYPE_OK){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + + }else if(select==WINDOW_BUTTONTYPE_YES){ + if(NPC_WindowMoneyCheck(meindex,talkerindex,3)==TRUE){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 7 ); + }else{ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 8 ); + } + + }else if(select==WINDOW_BUTTONTYPE_NO){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + } + break; + + + /*--⼰--*/ + case CHAR_WINDOWTYPE_WINDOWHEALER_OKALLMSG: + if(select==WINDOW_BUTTONTYPE_YES){ + NPC_WindowHealer_selectWindow( meindex, talkerindex, 0 ); + } + break; + } + + if(select==WINDOW_BUTTONTYPE_CANCEL + && CHAR_getWorkInt( talkerindex, CHAR_WORKPARTYMODE ) == 2) + { + CHAR_sendWatchEvent( CHAR_getWorkInt( talkerindex, CHAR_WORKOBJINDEX), + CHAR_ACTPLEASURE,NULL,0,TRUE); + CHAR_setWorkInt( talkerindex, CHAR_WORKACTION, CHAR_ACTPLEASURE); + } + +} + + +BOOL NPC_PetHealerCheck(int talker) +{ + + int petindex; + int i; + + /*--ʸƥƻؤ--*/ + for(i=0;i CHAR_getInt(talker,CHAR_LV)){ + return TRUE; + } + + return FALSE; + +} + + +/*------------------------------------------- +¦ +talkerƽҷ̼͵ +---------------------------------------------*/ +BOOL NPC_WindowMoneyCheck(int meindex,int talker,int mode) +{ + int cost=0; + int level; + + level=CHAR_getWorkInt(meindex,CHAR_WORK_LEVEL); + + if(mode==1){ + if(level <= CHAR_getInt(talker,CHAR_LV)){ + /*---ëԻ---*/ + cost=NPC_WindowCostCheck(meindex,talker); + /*--ػɬ---*/ + /*---ŻԻ¾---*/ + if(CHAR_getInt(talker,CHAR_GOLD) < cost){ + return FALSE; + + } + CHAR_DelGold( talker, cost); + } + } + if(mode==2){ + if(level <= CHAR_getInt(talker,CHAR_LV)){ + /*---ëԻ---*/ + cost=NPC_WindowCostCheckMp(meindex,talker); + + /*--ػɬ---*/ + /*---ŻԻ¾---*/ + if(CHAR_getInt(talker,CHAR_GOLD) < cost){ + return FALSE; + } + CHAR_DelGold( talker, cost); + } + } + + if(mode==3){ + if(level <= CHAR_getInt(talker,CHAR_LV)){ + + if( CHAR_getInt(talker,CHAR_HP) +#include "char.h" +#include "object.h" +#include "char_base.h" +#include "npcutil.h" +#include "configfile.h" +#include "lssproto_serv.h" +#include "npc_windowman.h" +#include "autil.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +struct { + int windowno; + int windowtype; + int buttontype; + int takeitem; + int giveitem; + char message[4096]; +}w; + +struct { + BOOL use; + int checkhaveitem; + int checkhaveitemgotowin; + int checkdonthaveitem; + int checkdonthaveitemgotowin; + int warp; + int battle; + int gotowin; +}buttonproc[13]; /* ok,cancel, yes,no,prev,next ݼ */ + + + + + +enum { + CHAR_WORK_MSGCOLOR = CHAR_NPCWORKINT1, +}; +//static void NPC_Windowman_selectWindow( int meindex, int toindex, int num); +//static BOOL NPC_Windowman_readData( int meindex, int windowno, BOOL chkflg); +//static int NPC_Windowman_restoreButtontype( char *data ); + +/********************************* +*********************************/ +BOOL NPC_WindowmanInit( int meindex ) +{ + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[1024]; + //int i; + //char secondToken[1024]; + + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", buf, sizeof( buf)) + == NULL ) + { + print( "windowman:ûָ趨ĵ \n"); + return FALSE; + } + /* ݱɬ÷ëƻ֧ */ + if( !NPC_Windowman_readData( meindex, -1, TRUE) ) { + return FALSE; + } + + CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWINDOWMAN ); + + return TRUE; +} + + + + +/********************************* +*********************************/ +void NPC_WindowmanTalked( int meindex , int talkerindex , char *szMes ,int color ) +{ + + NPC_Windowman_selectWindow( meindex, talkerindex, 1 ); + +} +/********************************* +*********************************/ +void NPC_WindowmanLooked( int meindex , int lookedindex) +{ + + NPC_Windowman_selectWindow( meindex, lookedindex,1 ); + +} + +/*static*/ void NPC_Windowman_selectWindow( int meindex, int toindex, int num) +{ + + int fd; + char buf[256]; + + if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { + return; + } + if( !NPC_Util_charIsInFrontOfChar( toindex, meindex, 1 )) return; + + if( !NPC_Windowman_readData( meindex, num, FALSE) ) { + print( "windowman:readdata error\n"); + return; + } + + fd = getfdFromCharaIndex( toindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } +} +void NPC_WindowmanWindowTalked( int meindex, int talkerindex, + int seqno, int select, char *data) + +{ + int button = -1; + char buf[256]; + if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; + + if( !NPC_Windowman_readData( meindex, seqno - 100, FALSE) ) { + print( "windowman:readdata error\n"); + return; + } + if( w.windowtype == WINDOW_MESSAGETYPE_SELECT ) { + button = atoi( data)+5; + if( button > 12 ) { + print( "windowman:invalid button[%d]\n", button); + return; + } + } + else if( select & WINDOW_BUTTONTYPE_OK) button = 0; + else if( select & WINDOW_BUTTONTYPE_CANCEL) button = 1; + else if( select & WINDOW_BUTTONTYPE_YES) button = 2; + else if( select & WINDOW_BUTTONTYPE_NO) button = 3; + else if( select & WINDOW_BUTTONTYPE_PREV) button = 4; + else if( select & WINDOW_BUTTONTYPE_NEXT) button = 5; + else { + print( "windowman:invalid button[%d]\n", select); + return; + } + if( buttonproc[button].use == TRUE ) { + int i; + int fd; + int newwin = -1; + if( buttonproc[button].checkhaveitem != -1 ) { + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talkerindex); + for( i = 0; i < itemMax; i ++ ) { +#else + for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + int itemindex = CHAR_getItemIndex( talkerindex, i); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) + == buttonproc[button].checkhaveitem ) + { + break; + } + } + } +#ifdef _NEW_ITEM_ + if( i == itemMax ) { +#else + if( i == CHAR_MAXITEMHAVE ) { +#endif + return; + } + newwin = buttonproc[button].checkhaveitemgotowin; + } + if( buttonproc[button].checkdonthaveitem != -1 ) { + +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(talkerindex); + for( i = 0; i < itemMax; i ++ ) { +#else + for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) { +#endif + int itemindex = CHAR_getItemIndex( talkerindex, i); + if( ITEM_CHECKINDEX( itemindex)) { + if( ITEM_getInt( itemindex, ITEM_ID) + == buttonproc[button].checkdonthaveitem ) + { + break; + } + } + } +#ifdef _NEW_ITEM_ + if( i != itemMax ) { +#else + if( i != CHAR_MAXITEMHAVE ) { +#endif + return; + } + newwin = buttonproc[button].checkdonthaveitemgotowin; + } + + if( newwin == -1 ) { + newwin = buttonproc[button].gotowin; + } + if( !NPC_Windowman_readData( meindex, newwin, FALSE) ) { + print( "windowman:readdata error\n"); + return; + } + fd = getfdFromCharaIndex( talkerindex); + if( fd != -1 ) { + lssproto_WN_send( fd, w.windowtype, + w.buttontype, + w.windowno+100, + CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), + makeEscapeString( w.message, buf, sizeof(buf))); + } + } +} + +BOOL NPC_Windowman_readData( int meindex, int windowno, BOOL chkflg) +{ + + int i; + int linenum = 0; + int endflg = FALSE; + int buttonendflg; + int winno = -1; + int buttonconfmode; + int b_mode; + int selectnum ; + int messagepos; + BOOL errflg = FALSE; + BOOL readflg = TRUE; + FILE *fp; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char filename[64]; + char opfile[128]; + char line[1024]; + char firstToken[1024]; + char secondToken[1024]; + + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + if( NPC_Util_GetStrFromStrWithDelim( argstr, "conff", filename, sizeof( filename)) == NULL ) { + print("\n err:NOT FIND [conff] "); + return FALSE; + } + + sprintf( opfile, "%s/", getNpcdir( ) ); + strcat( opfile, filename); +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", opfile); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( opfile, "r"); +} + if( fp == NULL ) { + print( "windowman:file open error [%s]\n", opfile); + return FALSE; + } + + while( readflg == TRUE ) { + endflg = FALSE; + buttonendflg = TRUE; + buttonconfmode = FALSE; + selectnum = 0; + messagepos = 0; + winno = -1; + b_mode = -1; + errflg = FALSE; + + /* */ + w.windowno = -1; + w.windowtype = -1; + w.buttontype = -1; + w.takeitem = -1; + w.giveitem = -1; + w.message[0] = '\0'; + + for( i = 0; i < arraysizeof( buttonproc); i ++ ) { + buttonproc[i].use = FALSE; + buttonproc[i].checkhaveitem = -1; + buttonproc[i].checkhaveitemgotowin = -1; + buttonproc[i].checkdonthaveitem = -1; + buttonproc[i].checkdonthaveitemgotowin = -1; + buttonproc[i].warp = -1; + buttonproc[i].battle = -1; + buttonproc[i].gotowin = -1; + } + + while( 1) { + char buf[256]; + int ret; + if( !fgets( line, sizeof( line), fp)){ + readflg = FALSE; + break; + } +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum ++; + + if( line[0] == '#' || line[0] == '\n') continue; + /* ݱ */ + chomp( line ); + + /* ë */ + replaceString( line, '\t' , ' ' ); + for( i = 0; i < strlen( line); i ++) { + if( line[i] != ' ' ) { + break; + } + strcpy( buf, &line[i]); + } + if( i != 0 ) strcpy( line, buf); + + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, + sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, + sizeof( secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + continue; + } + + if( strcasecmp( firstToken, "winno") == 0 ) { + if( winno != -1 ) { + print( "windowman:winnoȴ¶winno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + readflg = FALSE; + break; + } + /* ūNoë */ + winno = atoi( secondToken); + continue; + } + if( winno == -1 ) { + print( "windowman:winno δ壬ȴ趨\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = FALSE; + break; + } + if( (chkflg == FALSE && winno == windowno )|| + chkflg == TRUE) + { + if( buttonconfmode == TRUE ) { + if( strcasecmp( firstToken, "gotowin") == 0 ) { + buttonproc[b_mode].gotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkhaveitem") == 0 ) { + buttonproc[b_mode].checkhaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "haveitemgotowin") == 0 ) { + buttonproc[b_mode].checkhaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "checkdonthaveitem") == 0 ) { + buttonproc[b_mode].checkdonthaveitem = atoi( secondToken); + } + else if( strcasecmp( firstToken, "donthaveitemgotowin") == 0 ) { + buttonproc[b_mode].checkdonthaveitemgotowin = atoi( secondToken); + } + else if( strcasecmp( firstToken, "endbutton") == 0 ) { + if( buttonproc[b_mode].gotowin == - 1 ) { + if( buttonproc[b_mode].checkhaveitem == -1 && + buttonproc[b_mode].checkdonthaveitem == -1) + { + errflg = TRUE; + } + else { + if( !((buttonproc[b_mode].checkhaveitem != -1 && + buttonproc[b_mode].checkhaveitemgotowin != -1) + || (buttonproc[b_mode].checkdonthaveitem != -1 && + buttonproc[b_mode].checkdonthaveitemgotowin != -1))) + { + errflg = TRUE; + } + } + } + + if( errflg == TRUE) { + print( "windowman: Ҳgotowin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + readflg = FALSE; + errflg = TRUE; + break; + } + buttonproc[b_mode].use = TRUE; + buttonconfmode = FALSE; + buttonendflg = TRUE; + } + } + else { + + w.windowno = winno; + /* ūɬ */ + if( strcasecmp( firstToken, "wintype") == 0 ) { + w.windowtype = atoi( secondToken); + } + /* ʾɬ */ + else if( strcasecmp( firstToken, "buttontype") == 0 ) { + w.buttontype = NPC_Windowman_restoreButtontype( secondToken); + } + /* getitemɬ */ + else if( strcasecmp( firstToken, "takeitem") == 0 ) { + w.takeitem = atoi( secondToken); + } + /* giveitemɬ */ + else if( strcasecmp( firstToken, "giveitem") == 0 ) { + w.giveitem = atoi( secondToken); + } + /* messageɬ */ + else if( strcasecmp( firstToken, "message") == 0 ) { + if( messagepos == 0 ) { + strcpy( w.message, secondToken); + messagepos = strlen( w.message); + } + else { + w.message[messagepos]='\n'; + messagepos++; + strcpy( &w.message[messagepos], secondToken); + messagepos+=strlen(secondToken); + } + } + /* ʾëݼɬ */ + else if( strcasecmp( firstToken, "okpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 0; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "cancelpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 1; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "yespressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 2; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nopressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 3; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "prevpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 4; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "nextpressed") == 0 ) { + buttonconfmode = TRUE; + b_mode = 5; + buttonendflg = FALSE; + } + else if( strcasecmp( firstToken, "selected") == 0 ) { + buttonconfmode = TRUE; + b_mode = 6 + selectnum; + buttonendflg = FALSE; + selectnum ++; + } + /* ɬñδԻ */ + else if( strcasecmp( firstToken, "endwin") == 0 ) { + endflg = TRUE; + if( chkflg == FALSE) { + readflg = FALSE; + } + break; + } + else { + print( "windowman:趨DzܵIJ\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + } + } + } + else { + if( strcasecmp( firstToken, "endwin") == 0 ) { + winno = -1; + } + } + } + if( buttonendflg == FALSE) { + print( "windowman: Ҳendbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( winno != -1 ) { + if( w.windowtype == -1 ) { + print( "windowman: Ҳwintype\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( w.buttontype == -1 ) { + print( "windowman: Ҳbutton\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + if( strlen( w.message) == 0 ) { + print( "windowman: Ҳmessage\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + errflg = TRUE; + break; + } + } + } + fclose( fp); + + if( chkflg == FALSE && w.windowno == -1 ) { + print( "windowman: Ҳָwindowno\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( winno != -1 && endflg == FALSE) { + print( "windowman: Ҳendwin\n"); + print( "filename:[%s] line[%d]\n", filename, linenum); + return FALSE; + } + if( errflg == TRUE) return FALSE; + + return TRUE; +} +/* + * + */ +/*static*/ int NPC_Windowman_restoreButtontype( char *data ) +{ + int ret = 0; + int rc; + int i; + char buff[1024]; + + for( i = 1; ; i ++ ) { + rc = getStringFromIndexWithDelim( data, "|", i, buff, + sizeof( buff ) ); + if( rc == FALSE) break; + if( strcasecmp( buff, "ok") == 0 ) { + ret |= WINDOW_BUTTONTYPE_OK; + } + else if( strcasecmp( buff, "cancel") == 0 ) { + ret |= WINDOW_BUTTONTYPE_CANCEL; + } + else if( strcasecmp( buff, "yes") == 0 ) { + ret |= WINDOW_BUTTONTYPE_YES; + } + else if( strcasecmp( buff, "no") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NO; + } + else if( strcasecmp( buff, "prev") == 0 ) { + ret |= WINDOW_BUTTONTYPE_PREV; + } + else if( strcasecmp( buff, "next") == 0 ) { + ret |= WINDOW_BUTTONTYPE_NEXT; + } + } + if( ret == 0 ) { + ret = atoi( data); + } + return ret; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npccreate.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npccreate.c new file mode 100644 index 0000000..af8aac7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npccreate.c @@ -0,0 +1,662 @@ +#include "version.h" +#define __NPCCREATE__ + +#include +#include + +#include "common.h" +#include "npccreate.h" +#include "npctemplate.h" +#include "util.h" +#include "buf.h" +#include "readmap.h" +#include "char_data.h" +#include "handletime.h" +#include "configfile.h" +#include "autil.h" + +INLINE int NPC_CHECKCREATEINDEX(int index) +{ + if( NPC_createnum <= index || index < 0 )return FALSE; + return TRUE; +} + +INLINE int NPC_CHECKCREATEINTINDEX( int index) +{ + if( NPC_CREATEINTNUM <= index || index < 0 )return FALSE; + return TRUE; +} + +INLINE int NPC_setCreateInt( int index , NPC_CREATEINT element, int data ) +{ + int buf; + buf = NPC_create[index].intdata[element]; + NPC_create[index].intdata[element] = data; + return buf; +} + +INLINE int NPC_getCreateInt( int index , NPC_CREATEINT element ) +{ + return NPC_create[index].intdata[element]; +} + + +BOOL NPC_initCreateArray( int createnum ) +{ + NPC_createnum = createnum; + NPC_create = (NPC_Create*)allocateMemory( sizeof( NPC_Create ) * NPC_createnum ); + + print( "С:%d. :%d.\n", sizeof( NPC_Create ), createnum); + if( NPC_create == NULL ){ + return FALSE; + } + NPC_create_readindex = 0; + return TRUE; +} + +void NPC_setDefaultNPCCreate( NPC_Create* cr ) +{ + if( cr == NULL )return; + + cr->intdata[NPC_CREATEFLOORID]=0; + cr->intdata[NPC_CREATEBORNLEFTUPX]=0; + cr->intdata[NPC_CREATEBORNLEFTUPY]=0; + cr->intdata[NPC_CREATEBORNRIGHTDOWNX]=0; + cr->intdata[NPC_CREATEBORNRIGHTDOWNY]=0; + cr->intdata[NPC_CREATEMOVELEFTUPX]=0; + cr->intdata[NPC_CREATEMOVELEFTUPY]=0; + cr->intdata[NPC_CREATEMOVERIGHTDOWNX]=0; + cr->intdata[NPC_CREATEMOVERIGHTDOWNY]=0; + + cr->intdata[NPC_CREATEDIR]=0; + //jeffrey 1231 +#ifdef _ADD_ACTION + cr->intdata[NPC_CREATEACTION] = 0; +#endif + cr->intdata[NPC_CREATEBASEIMAGENUMBER]=-1; + cr->intdata[NPC_CREATETIME]=0; + cr->intdata[NPC_CREATEBORNNUM]=0; + cr->intdata[NPC_CREATEENEMYNUM]=0; + cr->intdata[NPC_CREATEBOUNDARY]=1; + cr->intdata[NPC_CREATEIGNOREINVINCIBLE]=0; + + cr->intdata[NPC_CREATEDATE]=0; + + cr->intdata[NPC_CREATEFAMILY]=0; + + cr->chardata[NPC_CREATENAME].string[0]= '\0'; + + cr->workdata[NPC_CREATEWORKENEMYNUM]=0; + cr->workdata[NPC_CREATEWORKMAKESTARTSEC]=0; + cr->workdata[NPC_CREATEWORKMAKESTARTUSEC]=0; + cr->workdata[NPC_CREATEWORKNEVERMAKE]=0; + +#ifdef _NPC_AUTO_MOVE + cr->intdata[NPC_AUTOMOVELEFTUPX]=0; + cr->intdata[NPC_AUTOMOVELEFTUPY]=0; + cr->intdata[NPC_AUTOMOVERIGHTDOWNX]=0; + cr->intdata[NPC_AUTOMOVERIGHTDOWNY]=0; +#endif + { + int i; + for( i=0 ; itemplateindex) ; i++ ){ + cr->templateindex[i] = -1; + cr->arg[i].string[0] = '\0'; + } + } +} + +BOOL NPC_IsNPCCreateFile( char* filename ) +{ + FILE* f; + char line1[128]; + char* ret; + + /* ~ƥ°̻ﷴئƱ */ + if( filename == NULL + || strlen( filename ) < 1 + || filename[strlen(filename)-1] == '~' + || filename[0] == '#' + || strcmptail( filename, ".bak" ) == 0 )return FALSE; + +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + if(strcmptail(filename, ".allblues")==0){ + crypto=TRUE; + } +#endif + + f= fopen( filename , "r" ); + if( f == NULL ) goto RETURNFALSE; + ret = fgets( line1, sizeof( line1 ), f ); + if( ret == NULL )goto FCLOSERETURNFALSE; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line1); + } +#endif + + if( strcasecmp( NPC_CREATEFILEMAGIC, line1 ) == 0 ){ + fclose(f); + return TRUE; + } + +FCLOSERETURNFALSE: + fclose(f); +RETURNFALSE: + return FALSE; +} + +int NPC_readCreateFile( char* filename ) +{ + FILE* f; + char line[512]; + int linenum=0; + int start=OFF; + NPC_Create cr; + int enemyreadindex=0; + + typedef struct tagPOINT + { + int x,y; + }POINT; + typedef struct tagREC + { + int w,h; + }REC; + POINT center[2]={{0,0},{0,0}}; /* born 0 ƥ move 1 */ + REC wh[2] ={{0,0},{0,0}}; /* born 0 ƥ move 1 */ + + POINT lu[2] ={{0,0},{0,0}}; /* born 0 ƥ move 1 */ + POINT rd[2] ={{0,0},{0,0}}; /* born 0 ƥ move 1 */ + + int defborn=FALSE; /* born ëɬ׾ */ + int defmove=FALSE; /* move ëɬ׾ */ + +#ifdef _NPC_AUTO_MOVE + POINT automove[2]={{0,0},{0,0}}; +#endif + int deflurd[2]={FALSE,FALSE}; /* lu,rd ƥɬ׾ */ + char* ret; + + + if( NPC_create_readindex >= NPC_createnum ){ + print("û\n" ); + print("ûĿ %d\n",NPC_createnum); + print("ûļ %s\n",filename); + return FALSE; + } + + NPC_setDefaultNPCCreate( &cr ); +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + if(strcmptail(filename, ".allblues")==0){ + crypto=TRUE; + } +#endif + f= fopen( filename ,"r"); + if( f == NULL )return FALSE; + + ret = fgets( line, sizeof( line ), f ); + if( ret == NULL )goto FCLOSERETURNFALSE; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( strcmp( NPC_CREATEFILEMAGIC, line ) != 0 ){ + print( "ⲻһcreateļ.\n" ); + goto FCLOSERETURNFALSE; + } + linenum = 1; + + while( fgets( line , sizeof( line ) , f ) ){ +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + linenum++; + + if( line[0] == '#' )continue; /* comment */ + if( line[0] == '\n' )continue; /* none */ + chomp( line ); + + switch( line[0] ){ + case '{': + if( start == ON ){ + fprint( "Find {. But already START state. %s:%d\n", + filename, linenum); + fprint( "˳\n" ); + goto FCLOSERETURNFALSE; + + }else{ + NPC_setDefaultNPCCreate( &cr ); + start = ON; + } + break; + case '}': + if( start == ON ){ + int err = FALSE; + if( enemyreadindex == 0 ){ + err = TRUE; + print( "ⲻ %s:%d\n", + filename,linenum); + }else if( MAP_IsThereSpecificFloorid( + cr.intdata[NPC_CREATEFLOORID]) == FALSE ){ + err = TRUE; + print( "ͼIDë %s:%d-floor:%d\n", + filename,linenum, cr.intdata[NPC_CREATEFLOORID]); + }else if( defborn == FALSE ){ + err = TRUE; + print( "Щ born װ %s:%d\n", + filename,linenum); + } + + if( err == FALSE ){ + cr.intdata[NPC_CREATEENEMYNUM] = enemyreadindex; + + if( deflurd[0] ){ + cr.intdata[NPC_CREATEBORNLEFTUPX] = + min(lu[0].x,rd[0].x); + cr.intdata[NPC_CREATEBORNRIGHTDOWNX] = + max(lu[0].x,rd[0].x); + cr.intdata[NPC_CREATEBORNLEFTUPY] = + min(lu[0].y,rd[0].y); + cr.intdata[NPC_CREATEBORNRIGHTDOWNY] = + max(lu[0].y,rd[0].y); + }else{ + cr.intdata[NPC_CREATEBORNLEFTUPX] = + center[0].x-wh[0].w/2; + cr.intdata[NPC_CREATEBORNRIGHTDOWNX] = + center[0].x+wh[0].w/2; + cr.intdata[NPC_CREATEBORNLEFTUPY] = + center[0].y-wh[0].h/2; + cr.intdata[NPC_CREATEBORNRIGHTDOWNY] = + center[0].y+wh[0].h/2; + } + if( defmove ){ + if( deflurd[0] ){ + cr.intdata[NPC_CREATEMOVELEFTUPX] = + min(lu[1].x,rd[1].x); + cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = + max(lu[1].x,rd[1].x); + cr.intdata[NPC_CREATEMOVELEFTUPY] = + min(lu[1].y,rd[1].y); + cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = + max(lu[1].y,rd[1].y); + }else{ + cr.intdata[NPC_CREATEMOVELEFTUPX] = + center[1].x-wh[1].w/2; + cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = + center[1].x+wh[1].w/2; + cr.intdata[NPC_CREATEMOVELEFTUPY] = + center[1].y-wh[1].h/2; + cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = + center[1].y+wh[1].h/2; + } + + }else{ + /* born ë */ + cr.intdata[NPC_CREATEMOVELEFTUPX] = + cr.intdata[NPC_CREATEBORNLEFTUPX]; + cr.intdata[NPC_CREATEMOVERIGHTDOWNX] = + cr.intdata[NPC_CREATEBORNRIGHTDOWNX]; + cr.intdata[NPC_CREATEMOVELEFTUPY] = + cr.intdata[NPC_CREATEBORNLEFTUPY]; + cr.intdata[NPC_CREATEMOVERIGHTDOWNY] = + cr.intdata[NPC_CREATEBORNRIGHTDOWNY]; + } + + memcpy( &NPC_create[NPC_create_readindex], &cr, + sizeof( NPC_Create ) ); + + + NPC_create_readindex++; + + if( NPC_create_readindex >= NPC_createnum ){ + print("û\n" ); + print("ôļĿ %d\n", + NPC_createnum); + print("ûļ:%s\n",filename); + goto FCLOSERETURNFALSE; + } + + } + + NPC_setDefaultNPCCreate( &cr ); + enemyreadindex=0; + defborn=FALSE; + defmove=FALSE; + deflurd[0]=FALSE; + deflurd[1]=FALSE; + start = OFF; + }else{ + fprint( "δ '}' at %s:%d\n",filename,linenum); + goto FCLOSERETURNFALSE; + } + break; + default: + { + + char firstToken[256]; + char secondToken[256]; + int ret; + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, + sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + break; + } + ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, + sizeof( secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + break; + } + + if( strcasecmp("floorid",firstToken) == 0 ){ + cr.intdata[NPC_CREATEFLOORID] = atoi(secondToken); + + }else if( strcasecmp("borncenter", firstToken) == 0 ){ + getFourIntsFromString(secondToken,¢er[0].x, + ¢er[0].y,&wh[0].w,&wh[0].h ); + defborn = TRUE; + }else if( strcasecmp("borncorner", firstToken) == 0 ){ + getFourIntsFromString(secondToken,&lu[0].x,&lu[0].y, + &rd[0].x,&rd[0].y ); + defborn = TRUE; + deflurd[0]=TRUE; + }else if( strcasecmp("movecenter", firstToken) == 0 ){ + getFourIntsFromString(secondToken,¢er[1].x, + ¢er[1].y,&wh[1].w,&wh[1].h ); + defmove = TRUE; + }else if( strcasecmp("movecorner", firstToken) == 0 ){ + getFourIntsFromString(secondToken,&lu[1].x,&lu[1].y, + &rd[1].x,&rd[1].y ); + defmove = TRUE; + deflurd[1]=TRUE; + + } +#ifdef _NPC_AUTO_MOVE + else if( strcasecmp("automove", firstToken) == 0 ){ + getFourIntsFromString(secondToken,&automove[0].x,&automove[0].y, + &automove[1].x,&automove[1].y ); + cr.intdata[NPC_AUTOMOVELEFTUPX] = min(automove[0].x, automove[1].x); + cr.intdata[NPC_AUTOMOVERIGHTDOWNX] = max(automove[0].x, automove[1].x); + cr.intdata[NPC_AUTOMOVELEFTUPY] = min(automove[0].y, automove[1].y); + cr.intdata[NPC_AUTOMOVERIGHTDOWNY] = max(automove[0].y, automove[1].y); + } +#endif + + else if( strcasecmp("dir",firstToken) == 0 ){ + cr.intdata[NPC_CREATEDIR] = atoi( secondToken ); + + }else if( strcasecmp("graphicname",firstToken) == 0 ){ + cr.intdata[NPC_CREATEBASEIMAGENUMBER] + = CHAR_seekGraphicNumberFromString(secondToken); + + }else if( strcasecmp("name",firstToken) == 0 ){ + strcpysafe( cr.chardata[NPC_CREATENAME].string, + sizeof(cr.chardata[NPC_CREATENAME].string), + secondToken ); + + }else if( strcasecmp("time",firstToken) == 0 ){ + cr.intdata[NPC_CREATETIME] = atoi( secondToken ); + + }else if( strcasecmp("date",firstToken) == 0 ){ + cr.intdata[NPC_CREATEDATE] = atoi( secondToken ); + + }else if( strcasecmp("createnum",firstToken) == 0 ){ + cr.intdata[NPC_CREATEBORNNUM] = atoi( secondToken ); + + }else if( strcasecmp( "boundary", firstToken) == 0 ){ + cr.intdata[NPC_CREATEBOUNDARY] = atoi( secondToken ); + + }else if( strcasecmp( "ignoreinvincible", firstToken) == 0 ){ + cr.intdata[NPC_CREATEIGNOREINVINCIBLE] = atoi( secondToken ); + + //jeffrey 1231 +#ifdef _ADD_ACTION + }else if( strcasecmp( "action", firstToken) == 0 ){ + cr.intdata[NPC_CREATEACTION] = atoi( secondToken ); +#endif + // Robin 0731 + }else if( strcasecmp( "family", firstToken) == 0 ){ + cr.intdata[NPC_CREATEFAMILY] = atoi( secondToken ); + + }else if( strcasecmp("enemy", firstToken) == 0 ){ + int templateindex; + char enemyname[64]; + + /* ˲ */ + if( enemyreadindex <= arraysizeof(cr.templateindex) ) + /* OK */ + ; + else + break; + + getStringFromIndexWithDelim(secondToken,"|",1,enemyname, + sizeof(enemyname) ); + templateindex= NPC_templateGetTemplateIndex(enemyname); + if( templateindex != -1 ){ + cr.templateindex[enemyreadindex] = templateindex; + { + char tmp[2]; + int ret; + ret = getStringFromIndexWithDelim( secondToken, + "|",2,tmp, + sizeof(tmp) ); + if( ret == FALSE ) + cr.arg[enemyreadindex].string[0] = '\0'; + else + strcpysafe( cr.arg[enemyreadindex].string, + sizeof( cr.arg[enemyreadindex]. + string ), + secondToken+strlen(enemyname)+1 ); + } + enemyreadindex++; + }else + fprint( "ûģ:\n[%s(%d)%s] enemy:%s\n", + filename ,linenum,secondToken, enemyname); + }else{ + fprint( "ûֵ½ %s %s:%d\n",firstToken,filename, + linenum ); + } + } + } + } + + fclose(f); + return TRUE; + +FCLOSERETURNFALSE: + fclose(f); + return FALSE; +} + +BOOL NPC_readNPCCreateFiles( char* topdirectory ,int createsize) +{ + STRING64 *filenames; + int filenum; + int i; + filenames = (STRING64 *)allocateMemory( sizeof( STRING64 ) * + (int)getFilesearchnum( ) ); + if( filenames == NULL ){ + print( "ȡNPCļ... ڴ\n" ); + return FALSE; + } + filenum = rgetFileName( topdirectory ,filenames ,getFilesearchnum( ) ); + if( filenum == -1 ){ + freeMemory( filenames ); + return FALSE; + } + if( filenum >= getFilesearchnum( ) ){ + print( "ļĿʧ %d\n", getFilesearchnum( ) ); + while( 1 ); + } + if( !NPC_initCreateArray( createsize ) ){ + fprint( "\n" ); + freeMemory( filenames ); + return FALSE; + } + print( "ȡNPCļ..." ); + for( i = 0 ; i < filenum ; i ++ ){ + if( NPC_IsNPCCreateFile( filenames[i].string )){ + if( NPC_readCreateFile( filenames[i].string ) == -1 ){ + break; + } + } + } + print( "ȷNPC %d ..." , NPC_create_readindex ); + //NPC_createnum=NPC_create_readindex; +#ifdef DEBUG + /* 99/4/8 By Kawata csvֿƻ֧ */ + print( "Npc_Create's\n"); + for( i = 0 ; i < NPC_createnum ; i ++ ){ + int j; + /*print( "NPC_create[%d]:\n", i);*/ + print( "%d,", i); + for( j = 0 ; j < NPC_CREATECHARNUM ; j ++ ) + print("%s," , NPC_create[i].chardata[j].string ); + /*print( "\tIntdata\t" );*/ + for( j = 0 ; j < NPC_CREATEINTNUM ; j ++ ) + print("%d," , NPC_create[i].intdata[j] ); + /***print("\n" ); + print( "\tChardata\t" );***/ + for( j = 0 ; j < NPC_create[i].intdata[NPC_CREATEENEMYNUM]; j ++ ) + print("%d" , NPC_create[i].templateindex[j] ); + /*print("\n" );*/ + print("\n" ); + } +#endif /*DEBUG*/ + + freeMemory( filenames ); + return TRUE; +} + + + +/*------------------------------------------------------------ + * createindex boundary ɬýľ¾ëέ + * ¦ + * createindex int create̼͵ + * ߯Ի + * ɬýľ TRUE(1) + * ɬýľئ FALSE(0) + ------------------------------------------------------------*/ +BOOL NPC_isBoundarySet( int createindex ) +{ + if( NPC_CHECKCREATEINDEX(createindex) == FALSE )return FALSE; + return NPC_create[createindex].intdata[NPC_CREATEBOUNDARY]; +} +/*------------------------------------------------------------ + * ¦ + * r RECT* ëRECT ̼ + * ߯Ի + ------------------------------------------------------------*/ +BOOL NPC_createGetRECT( int createindex,RECT* r ) +{ + if( NPC_CHECKCREATEINDEX(createindex) == FALSE )return FALSE; + + r->x = NPC_create[createindex].intdata[NPC_CREATEMOVELEFTUPX]; + r->y = NPC_create[createindex].intdata[NPC_CREATEMOVELEFTUPY]; + r->width + = NPC_create[createindex].intdata[NPC_CREATEMOVERIGHTDOWNX] + - NPC_create[createindex].intdata[NPC_CREATEMOVELEFTUPX]; + r->height + = NPC_create[createindex].intdata[NPC_CREATEMOVERIGHTDOWNY] + - NPC_create[createindex].intdata[NPC_CREATEMOVELEFTUPY]; + return TRUE; +} + + + +/*------------------------------------------------------------ + * ¦ + * cindex int ̼͵ + * ߯Ի + * BOOL Ȼ TRUE(1) + * BOOL Ȼئ FALSE(0) + ------------------------------------------------------------*/ +BOOL NPC_createCheckGenerateFromTime( int cindex ) +{ + struct timeval old; + if( !NPC_CHECKCREATEINDEX(cindex) ) + return FALSE; + + if( NPC_create[cindex].workdata[NPC_CREATEWORKNEVERMAKE] ) + return FALSE; + + if( NPC_create[cindex].intdata[NPC_CREATEBORNNUM] + <= NPC_create[cindex].workdata[NPC_CREATEWORKENEMYNUM] ) + return FALSE; + + if( NPC_create[cindex].intdata[NPC_CREATETIME] < 0 )return FALSE; + old.tv_sec = NPC_create[cindex].workdata[NPC_CREATEWORKMAKESTARTSEC]; + old.tv_usec= NPC_create[cindex].workdata[NPC_CREATEWORKMAKESTARTUSEC]; + + if( time_diff_us( NowTime , old ) <= + NPC_create[cindex].intdata[NPC_CREATETIME]*1000 ) + return FALSE; + + return TRUE; +} + + + + +/*------------------------------------------------------------ + * ¦ + * tindex int ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void NPC_createInitTime( int index ) +{ + /* DZئ׾հëɬ */ + NPC_create[index].workdata[NPC_CREATEWORKMAKESTARTSEC] = + NowTime.tv_sec; + NPC_create[index].workdata[NPC_CREATEWORKMAKESTARTUSEC] = + NowTime.tv_usec; +} +/*------------------------------------------------------------ + * ¦ + * index int ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void NPC_createIncreaseEnemynum( int index ) +{ + if( !NPC_CHECKCREATEINDEX(index) )return; + NPC_create[index].workdata[NPC_CREATEWORKENEMYNUM] ++; +} +/*------------------------------------------------------------ + * ĻƥëӼ + * ¦ + * index int ̼͵ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void NPC_createDecreaseEnemynum( int index ) +{ + if( !NPC_CHECKCREATEINDEX(index) )return; + NPC_create[index].workdata[NPC_CREATEWORKENEMYNUM] --; +} +/*------------------------------------------------------------ + * ¦ + * index int ̼͵ + * ߯Ի + * TRUE:MAX FALSE:ਵ + ------------------------------------------------------------*/ +BOOL NPC_createCheckMaxEnemynum( int index ) +{ + + if( NPC_create[index].intdata[NPC_CREATEBORNNUM] + <= NPC_create[index].workdata[NPC_CREATEWORKENEMYNUM] ) + return TRUE; + else + return FALSE; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcgen.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcgen.c new file mode 100644 index 0000000..bb92398 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcgen.c @@ -0,0 +1,388 @@ +#include "version.h" +#include + +#include "common.h" +#include "npccreate.h" +#include "npctemplate.h" +#include "char.h" +#include "char_data.h" +#include "buf.h" +#include "object.h" +#include "readmap.h" +#include "item.h" +#include "handletime.h" +#include "map_deal.h" +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +typedef struct tagNPC_searchPoint +{ + int floor; + int x; + int y; +}NPC_searchPoint; + + +/* ϼNPCë¾ */ +#define NPC_CREATECHALLENGETIME 1 +int all_nosee = 0; /* ༰ݣ廯ë no_see */ +int all_nobody = 0; /* ༰ݣ廯ë no_body */ +int one_loop_born = 1; /* ƥ Ϸ oneloop_born */ + +/*------------------------------------------------------------ + * ëķë + * ¦ + * nobody int 1 ݷئݱ年 + * (л) + * (ݼ) + * ëئئ + * ߯Ի + * ľݷ TRUE + * ľئݷ FALSE + ------------------------------------------------------------*/ +static BOOL NPC_searchCreatePoint( NPC_Create* cr,int nobody,int nosee, + NPC_searchPoint* point, BOOL isflying ) +{ + int floor=cr->intdata[NPC_CREATEFLOORID]; + int x = cr->intdata[NPC_CREATEBORNLEFTUPX]; + int y = cr->intdata[NPC_CREATEBORNLEFTUPY]; + int width; + int height; + int area; + int loop; + BOOL ret = FALSE; + int i, j; + + width = cr->intdata[NPC_CREATEBORNRIGHTDOWNX] + - cr->intdata[NPC_CREATEBORNLEFTUPX] + 1; + height = cr->intdata[NPC_CREATEBORNRIGHTDOWNY] + - cr->intdata[NPC_CREATEBORNLEFTUPY] + 1; + area = width * height; + if( nobody == 0 && all_nobody == 0 ) { + BOOL found = FALSE; + for( i = x ; i <= x +width && found == FALSE; i ++ ) { + for( j = y; j <= y + height && found == FALSE; j ++ ) { + OBJECT object; + for( object = MAP_getTopObj( floor, i,j); + object; + object = NEXT_OBJECT(object) ) + { + int objindex = GET_OBJINDEX( object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + if( CHAR_getInt( OBJECT_getIndex(objindex), + CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) + { + found = TRUE; + break; + } + } + } + } + } + if( found == FALSE ) { + return( FALSE); + } + } + for( loop=0 ; loopintdata[NPC_CREATEIGNOREINVINCIBLE] == 0 + && CHAR_isInvincibleArea( floor,crx,cry ) ){ + continue; + } + if( nosee == 0 && all_nosee == 0 ) { + BOOL found = FALSE; + for( i = crx - CHAR_DEFAULTSEESIZ/2 ; + i <= crx +CHAR_DEFAULTSEESIZ/2 && found == FALSE ; i ++ ) + { + for( j = cry - CHAR_DEFAULTSEESIZ/2; + j <= cry + CHAR_DEFAULTSEESIZ/2 && found == FALSE; + j ++ ) + { + OBJECT object; + for( object = MAP_getTopObj( floor, i,j); + object; + object = NEXT_OBJECT(object) ) + { + int objindex = GET_OBJINDEX( object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + if( CHAR_getInt( OBJECT_getIndex(objindex), + CHAR_WHICHTYPE ) + == CHAR_TYPEPLAYER ) + { + found = TRUE; + break; + } + } + } + } + } + if( found == TRUE ){ + return FALSE; + } + } + if( MAP_walkAbleFromPoint( floor,crx,cry,isflying ) == TRUE ){ + point->floor = cr->intdata[NPC_CREATEFLOORID]; + point->x = crx; + point->y = cry; + ret = TRUE; + break; + }else{ + } + } + + return( ret ); +} + + +typedef struct tagNPC_Correspondfunction +{ + int template; + int ch; +}NPC_Correspondfunction; + +static NPC_Correspondfunction correspondfunction[]={ + { NPC_TEMPLATEINITFUNC, CHAR_INITFUNC }, + { NPC_TEMPLATEWALKPREFUNC, CHAR_WALKPREFUNC }, + { NPC_TEMPLATEWALKPOSTFUNC, CHAR_WALKPOSTFUNC }, + { NPC_TEMPLATEPREOVERFUNC, CHAR_PREOVERFUNC }, + { NPC_TEMPLATEPOSTOVERFUNC, CHAR_POSTOVERFUNC }, + { NPC_TEMPLATEWATCHFUNC, CHAR_WATCHFUNC }, + { NPC_TEMPLATELOOPFUNC, CHAR_LOOPFUNC }, + { NPC_TEMPLATETALKEDFUNC, CHAR_TALKEDFUNC }, + { NPC_TEMPLATEDYINGFUNC, CHAR_DYINGFUNC }, + { NPC_TEMPLATEPREATTACKEDFUNC,CHAR_PREATTACKEDFUNC }, + { NPC_TEMPLATEPOSTATTACKEDFUNC, CHAR_POSTATTACKEDFUNC }, + { NPC_TEMPLATEOFFFUNC, CHAR_OFFFUNC }, + { NPC_TEMPLATELOOKEDFUNC, CHAR_LOOKEDFUNC }, + { NPC_TEMPLATEITEMPUTFUNC, CHAR_ITEMPUTFUNC }, + { NPC_TEMPLATESPECIALTALKEDFUNC, CHAR_SPECIALTALKEDFUNC}, + { NPC_TEMPLATEWINDOWTALKEDFUNC, CHAR_WINDOWTALKEDFUNC}, +#ifdef _USER_CHARLOOPS + { NPC_TEMPLATELOOPFUNCTEMP1, CHAR_LOOPFUNCTEMP1}, + { NPC_TEMPLATELOOPFUNCTEMP2, CHAR_LOOPFUNCTEMP2}, + { NPC_TEMPLATEBATTLEPROPERTY, CHAR_BATTLEPROPERTY}, +#endif +}; +/*------------------------------------------------------------ + * + * ¦ + * ch Char* ƽҷ· + * ߯Ի + * ئ + ------------------------------------------------------------*/ +static void NPC_copyFunction( Char* ch, NPC_Template* temp ) +{ + int i; + for( i=0 ; ichardata[correspondfunction[i].template].string[0] != '\0' ) + strcpysafe( ch->charfunctable[correspondfunction[i].ch].string, + sizeof(ch->charfunctable[correspondfunction[i].ch].string), + temp->chardata[correspondfunction[i].template].string); +} + +static BOOL NPC_generateNPC( int createindex, int createtemplateindex ) +{ + Char one; + NPC_searchPoint sp; + int i; + NPC_Template* template; + NPC_Create* cr; + + if( NPC_CHECKCREATEINDEX(createindex) + && 0 <= createtemplateindex + && createtemplateindex < arraysizeof(NPC_create[createindex].templateindex ) + && NPC_CHECKTEMPLATEINDEX( NPC_create[createindex].templateindex[createtemplateindex])){ + cr = &NPC_create[createindex]; + template = &NPC_template[NPC_create[createindex]. + templateindex[createtemplateindex]]; + }else{ + return FALSE; + } + if( NPC_searchCreatePoint( cr, + template->intdata[NPC_TEMPLATEMAKEATNOBODY], + template->intdata[NPC_TEMPLATEMAKEATNOSEE], &sp, + template->intdata[NPC_TEMPLATEISFLYING]) == FALSE ){ + return FALSE; + } + + if( CHAR_getDefaultChar( &one, template->intdata[NPC_TEMPLATETYPE] ) == FALSE ){ + return FALSE; + } + one.data[CHAR_FLOOR] = sp.floor; + one.data[CHAR_X] = sp.x; + one.data[CHAR_Y] = sp.y; + one.data[CHAR_DIR] = cr->intdata[NPC_CREATEDIR]; +#ifdef _ADD_ACTION + one.data[CHAR_ACTIONSTYLE] = cr->intdata[NPC_CREATEACTION]; +#endif + + one.data[CHAR_BASEBASEIMAGENUMBER] = one.data[CHAR_BASEIMAGENUMBER] + = template->intdata[NPC_TEMPLATEIMAGENUMBER]; + if( cr->intdata[NPC_CREATEBASEIMAGENUMBER] != -1 ) + one.data[CHAR_BASEBASEIMAGENUMBER] + = one.data[CHAR_BASEIMAGENUMBER] + = cr->intdata[NPC_CREATEBASEIMAGENUMBER]; + + strcpysafe(one.string[CHAR_NAME].string, + sizeof(one.string[CHAR_NAME].string), + template->chardata[NPC_TEMPLATECHARNAME].string); + + + if( cr->chardata[NPC_CREATENAME].string[0] != '\0' ){ + strcpysafe(one.string[CHAR_NAME].string, + sizeof(one.string[CHAR_NAME].string), + cr->chardata[NPC_CREATENAME].string); + } + + // Robin 0731 + one.data[CHAR_FMINDEX] = cr->intdata[NPC_CREATEFAMILY]; + NPC_copyFunctionSetToChar( template-> + intdata[NPC_TEMPLATEFUNCTIONINDEX], + &one ); + NPC_copyFunction( &one, template ); + one.data[CHAR_LOOPINTERVAL] = template-> + intdata[NPC_TEMPLATELOOPFUNCTIME]; + if( cr->arg[createtemplateindex].string[0] != '\0' ){ + strcpysafe( one.string[CHAR_NPCARGUMENT].string, + sizeof(one.string[CHAR_NPCARGUMENT].string), + cr->arg[createtemplateindex].string ); + }else{ + one.string[CHAR_NPCARGUMENT].string[0] = '\0'; + } + one.data[CHAR_WHICHTYPE] = CHAR_TYPEENEMY; + one.data[CHAR_NPCCREATEINDEX] = createindex; + { + static struct NPC_Paramtable + { + int templateindex; + int charadataindex; + }paramtbl[]={ + { NPC_TEMPLATEMINMP, CHAR_MAXMP }, + { NPC_TEMPLATEMINSTR, CHAR_STR }, + { NPC_TEMPLATEMINTOUGH, CHAR_TOUGH }, + + + }; + for( i=0 ; irandomdata[ + paramtbl[i].templateindex] ); + one.data[paramtbl[i].charadataindex] + = one.data[paramtbl[i].charadataindex] + + template->intdata[paramtbl[i].templateindex] + + randomvalue; + } + one.data[CHAR_MP] = one.data[CHAR_MAXMP]; + } + { + extern int CheckCharMaxItemChar(Char* ch); + int itemindex=CHAR_STARTITEMARRAY; + + + int itemMax = CheckCharMaxItemChar(&one); + for( i = 0 ; i < template->intdata[NPC_TEMPLATEITEMNUM] ; i ++ ){ + if( RAND(0,32767) <= template->haveitem[i].haverate ){ + if( template->haveitem[i].itemnumber == -1 + && template->haveitem[i].havenum > 0 ){ + int randomvalue = template->haveitem[i].havenum; + randomvalue *= (RAND(90,110))/100.0; + one.data[CHAR_GOLD] = min( CHAR_MAXGOLDHAVE, randomvalue ); + }else if( itemindex+i < itemMax ){ + one.indexOfExistItems[itemindex+i] = + ITEM_makeItemAndRegist(template->haveitem[i] + .itemnumber); + } + } + } + } + + { + int charaindex; + int objindex; + Object obj; + charaindex = CHAR_initCharOneArray( &one ); + if( charaindex == -1 ){ + //CHAR_endCharData( &one ); + return FALSE; + } + if( template->intdata[NPC_TEMPLATEISFLYING] ) + CHAR_setFlg(charaindex, CHAR_ISFLYING, 1 ); + + obj.type = OBJTYPE_CHARA; + obj.index= charaindex; + obj.x = CHAR_getInt(charaindex,CHAR_X); + obj.y = CHAR_getInt(charaindex,CHAR_Y); + obj.floor = CHAR_getInt(charaindex,CHAR_FLOOR); + objindex = initObjectOne( &obj ); + if( objindex == -1 ){ + CHAR_endCharOneArray( charaindex ); + return FALSE; + }else{ + } + CHAR_setWorkInt( charaindex,CHAR_WORKOBJINDEX,objindex ); +#ifdef _MO_RELOAD_NPC + CHAR_setWorkInt( charaindex,CHAR_WORKNPCTYPE,1); +#endif +#ifdef _ADD_ACTION +//CHAR_WORKACTION + CHAR_setWorkInt( charaindex, CHAR_WORKACTION, + CHAR_getInt( charaindex, CHAR_ACTIONSTYLE ) ); + + CHAR_sendWatchEvent( objindex, CHAR_getWorkInt( charaindex, CHAR_WORKACTION) + ,NULL,0,TRUE); +#else + CHAR_sendWatchEvent(objindex,CHAR_ACTSTAND,NULL,0,TRUE); +#endif + CHAR_complianceParameter( charaindex ); + } + + return TRUE; +} + +void NPC_generateLoop( BOOL checkall ) +{ + int i,j; + int CreateOk=0; + int enemynum ; + static int createcount = 0; /* create ¾ */ + static struct timeval _store_npc_generateloop_time; + if( checkall == FALSE) { + if( time_diff_us( NowTime, _store_npc_generateloop_time ) < (1000*1000)){ + return; + } else { + _store_npc_generateloop_time = NowTime; + } + } + + for( i=0 ; i < NPC_createnum ; i++ ){ + if( createcount >= NPC_createnum ) createcount = 0; + enemynum = NPC_getCreateInt( createcount, NPC_CREATEENEMYNUM ); + for( j = 0 ; j < enemynum ; j ++ ){ + if( NPC_createCheckGenerateFromTime(createcount) == TRUE ){ + CreateOk ++; + NPC_createInitTime(createcount); + if( NPC_generateNPC(createcount,j) == TRUE ){ + NPC_createIncreaseEnemynum(createcount); + }else{ + } + } + } + createcount ++; + if( checkall == FALSE && CreateOk >= one_loop_born ){ + break; + } + } +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npctemplate.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npctemplate.c new file mode 100644 index 0000000..fbb1d8f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npctemplate.c @@ -0,0 +1,1088 @@ +#include "version.h" +#define __NPCTEMPLATE__ + +#include +#include + +#include "common.h" +#include "npctemplate.h" +#include "buf.h" +#include "char_data.h" +#include "util.h" +#include "handletime.h" +#include "item.h" +#include "anim_tbl.h" +#include "configfile.h" +#include "autil.h" + +/*ɬëǩ׻ë */ +typedef struct tagFunctionNameSet +{ + char* id; + char* initfunc; + char* walkprefunc; + char* walkpostfunc; + char* preoverfunc; + char* postoverfunc; + char* watchfunc; + char* loopfunc; + char* dyingfunc; + char* talkedfunc; + char* preattackedfunc; + char* postattackedfunc; + char* offfunc; + char* lookedfunc; + char* itemputfunc; + char* specialtalkedfunc; + char* windowtalkedfunc; +}FunctionNameSet; + + +static FunctionNameSet functionSet[]={ + + { "Sample" , "", "", "", "", "", "", "SampleLoop", + "SampleDying" ,"","", "","","","","",""}, + + /* ʧ */ + { "Door" , "DoorInit" , "","", + "","DoorPostOver","DoorWatch","", + "","DoorTalked","", "", + "DoorOff","DoorLooked","","",""}, + + /* */ + { "SimpleShop" ,"SimpleShopInit","","", + "","","","","", + "SimpleShopTalked" , "","", + "","","" ,"SimpleShopSpecialTalked" ,""}, + + /* */ + { "Msg" , "MsgInit" , "","", + "","","","", + "","","", "", + "","MsgLooked","","",""}, + + /* */ + { "Warp","WarpInit","","", + "","","","", + "","","","", + "","", "","",""}, + + { "TownPeople" ,"TownPeopleInit","","", + "","","","", + "", "TownPeopleTalked" ,"","", + "","","","",""}, + + { "Oldman","OldmanInit","","", + "","","","", + "","OldmanTalked","","", + "","", "","",""}, + + + /* Ƥ̼ */ + { "SavePoint","SavePointInit","","", + "","","","", + "","SavePointTalked","","", + "","", "","","SavePointWindowTalked"}, + + /* ס¡ */ + { "Healer","HealerInit","","", + "","","","", + "","HealerTalked","","", + "","", "","",""}, + + /* Healer add code by shan */ + { "FmHealer","FmHealerInit","","", + "","","","", + "","FmHealerTalked","","", + "","", "","",""}, + + /* ׻ add code by shan */ + { "PetMaker","PetMakerInit","","", + "","","","", + "","PetMakerTalked","","", + "","", "","",""}, + + { "StoryTeller","StoryTellerInit","","", + "","","","", + "","StoryTellerTalked","","", + "","", "","",""}, + + { "RoomAdminNew","RoomAdminNewInit","","", + "","","","RoomAdminNewLoop", + "","RoomAdminNewTalked","","", + "","", "","",""}, + + {"Dengon", + "DengonInit", "", "", "", "", "", "", "", "", + "", "", "", "DengonLooked", "", "","DengonWindowTalked"}, + + /* ԰ add code by shan */ + {"FmDengon", + "FmDengonInit", "", "", "", "", "", "", "", "", + "", "", "", "FmDengonLooked", "", "","FmDengonWindowTalked"}, + + { "ItemCompo" , "ItemCompoInit", "", "", + "", "", "", "", + "" ,"ItemCompoTalked","","" + ,"","","" , "",""}, + + /* ó */ + { "NPCEnemy","NPCEnemyInit","","", + "","","NPCEnemyWatch","", + "","NPCEnemyTalked","","", + "","", "","","NPCEnemyWindowTalked"}, + + /* ʧ */ + { "Action","ActionInit","","", + "","","ActionWatch","", + "","ActionTalked","","", + "","", "","",""}, + + { "Windowman","WindowmanInit","","", + "","","","", + "","WindowmanTalked","","", + "","WindowmanLooked", "","","WindowmanWindowTalked"}, + + /*windowhealer */ + { "WindowHealer","WindowHealerInit","","", + "","","","", + "","WindowHealerTalked","","", + "","WindowHealerLooked", "","","WindowHealerWindowTalked"}, + + + /* ItemShop */ + { "ItemShop","ItemShopInit","","", + "","","","", + "","ItemShopTalked","","", + "","", "","","ItemShopWindowTalked"}, + {"Sysinfo", + "SysinfoInit", "", "", + "", "", "", "SysinfoLoop", + "", "SysinfoTalked","", "", + "", "", "", "",""}, + + { "Duelranking","DuelrankingInit","","", + "","","", + "", + "","","","", + "","DuelrankingLooked", "","","DuelrankingWindowTalked"}, + + + /* PetSkillShop */ + { "PetSkillShop","PetSkillShopInit","","", + "","","","", + "","PetSkillShopTalked","","", + "","", "","","PetSkillShopWindowTalked"}, + + /* PetShop */ + { "PetShop","PetShopInit","","", + "","","","", + "","PetShopTalked","","", + "","", "","","PetShopWindowTalked"}, + + + /* SignBoard */ + { "SignBoard","SignBoardInit","","", + "","","","", + "","","","", + "","SignBoardLooked", "","","SignBoardWindowTalked"}, + + + /* WarpMan */ + { "WarpMan","WarpManInit","","", + "","","WarpManWatch","WarpManLoop", + "","WarpManTalked","","", + "","", "","","WarpManWindowTalked"}, + + + /* ExChangeman */ + { "ExChangeMan","ExChangeManInit","","", + "","","","", + "","ExChangeManTalked","","", + "","", "","","ExChangeManWindowTalked"}, + + /* timeman */ + { "TimeMan","TimeManInit","","", + "","","TimeManWatch","", + "","TimeManTalked","","", + "","", "","",""}, + + /* ʾū¼ء */ + { "BodyLan","BodyLanInit","","", + "","","BodyLanWatch","", + "","BodyLanTalked","","", + "","", "","","BodyLanWindowTalked"}, + + /* ʾū¼ء */ + { "Mic","MicInit","","", + "","","","", + "","MicTalked","","", + "","", "","",""}, + + /* ƽѨ */ + { "LuckyMan","LuckyManInit","","", + "","","","", + "","LuckyManTalked","","", + "","", "","","LuckyManWindowTalked"}, + + /* Ѩƹﵩ */ + { "Bus","BusInit","","", + "","","","BusLoop", + "","BusTalked","","", + "","", "","",""}, + + /* */ // Arminius 7.7 Ariplane + { "Airplane","AirInit","","", + "","","","AirLoop", + "","AirTalked","","", + "","", "","",""}, + + { "Charm","CharmInit","","", + "","","","", + "","CharmTalked","","", + "","", "","","CharmWindowTalked"}, + + /* */ + { "Quiz","QuizInit","","", + "","","","", + "","QuizTalked","","", + "","", "","","QuizWindowTalked"}, + + { "PoolItemShop","PoolItemShopInit","","", + "","","","", + "","PoolItemShopTalked","","", + "","", "","","PoolItemShopWindowTalked"}, + + /* ìѨ */ + { "CheckMan","CheckManInit","","", + "","","","", + "","CheckManTalked","","", + "","", "","","CheckManWindowTalked"}, + + /* Ԫ */ + { "Janken","JankenInit","","", + "","","","", + "","JankenTalked","","", + "","", "","","JankenWindowTalked"}, + + /* Ϸ */ + { "Transmigration","TransmigrationInit","","", + "","","","", + "","TransmigrationTalked","","", + "","", "","","TransmigrationWindowTalked"}, + + /* Family Man */ + { "Familyman","FamilymanInit","","", + "","","","", + "","FamilymanTalked","","", + "","FamilymanLooked", "","","FamilymanWindowTalked"}, + + /* CoolFish: Family Warp Man 2001/6/6 */ + { "FMWarpMan","FMWarpManInit","","", + "","","","FMWarpManLoop", + "","FMWarpManTalked","","", + "","", "","","FMWarpManWindowTalked"}, + + /* CoolFish: Family PK Man 2001/7/4 */ + { "FMPKMan","FMPKManInit","","", + "","","","", + "","FMPKManTalked","","", + "","", "","","FMPKManWindowTalked"}, + + /* CoolFish: Family PK CallMan 2001/7/13 */ + { "FMPKCallMan","FMPKCallManInit","","", + "","","","", + "","FMPKCallManTalked","","", + "","", "","","FMPKCallManWindowTalked"}, + + /* Bank Man */ + { "Bankman","BankmanInit","","", + "","","","", + "","BankmanTalked","","", + "","BankmanLooked", "","","BankmanWindowTalked"}, + + /* Arminius 7.13 scheduleman */ + { "Scheduleman","SchedulemanInit","","", + "","","","SchedulemanLoop", + "","SchedulemanTalked","","", + "","", "","","SchedulemanWindowTalked"}, + + /* Arminius 7.24 manor scheduleman */ + { "ManorSman","ManorSmanInit","","", + "","","","ManorSmanLoop", + "","ManorSmanTalked","","", + "","", "","","ManorSmanWindowTalked"}, + + // Robin + { "Riderman","RidermanInit","","", + "","","","", + "","RidermanTalked","","", + "","RidermanLooked", "","","RidermanWindowTalked"}, + + { "FmLetter","FmLetterInit","","", + "","","","", + "","FmLetterTalked","","", + "","FmLetterLooked", "","","FmLetterWindowTalked"} +#ifdef _GAMBLE_BANK + ,{ + "NPC_GambleBank","GambleBankInit","","","","","", + "GambleBankLoop","", + "GambleBankTalked","","","","","","", + "GambleBankWindowTalked" + } +#endif + +#ifdef _GAMBLE_ROULETTE //Gamble_Roulette + ,{ + "NPC_GambleRoulette","GambleRouletteInit","","","","","", + "GambleRouletteLoop","", + "GambleRouletteTalked","","","","","","", + "GambleRouletteWindowTalked" + } + // + ,{ + "NPC_GambleMaster","GambleMasterInit","","","","","", + "GambleMasterLoop","", + "GambleMasterTalked","","","","","","", + "GambleMasterWindowTalked" + } + +#endif + +#ifdef _TRANSER_MAN + /* TranserMan */ + ,{ "TranserMan","TranserManInit","","", + "","","","", + "","TranserManTalked","","", + "","", "","","TranserManWindowTalked" + } +#endif + +#ifdef _VIP_SHOP + /* VipShop */ + ,{ "VipShop","VipShopInit","","", + "","","","", + "","VipShopTalked","","", + "","", "","","VipShopWindowTalked" + } + +#endif + +#ifdef _NEW_VIP_SHOP + /* NewVipShop */ + ,{ "NewVipShop","NewVipShopInit","","", + "","","","", + "","NewVipShopTalked","","", + "","", "","","NewVipShopWindowTalked" + } +#endif + +#ifdef _AUTO_PK + /* VipShop */ + ,{ "AutoPk","AutoPkInit","","", + "","","","", + "","AutoPkTalked","","", + "","", "","","AutoPkWindowTalked" + } +#endif + +#ifdef _NPC_MAKEPAIR + ,{ "MakePair","MakePairManInit","","", + "","","","MakePairManLoop", + "","MakePairManTalked","","", + "","", "","","MakePairManWindowTalked" + } +#endif + +#ifdef _NPC_FUSION + ,{ "PetFusion","PetFusionManInit","","", + "","","","", + "","PetFusionManTalked","","", + "","", "","","PetFusionManWindowTalked" + } +#endif + +#ifdef _ITEM_NPCCHANGE + ,{ "ItemchangeMan","ItemchangeManInit","","", + "","","","", + "","ItemchangeManTalked","","", + "","", "","","ItemchangeManWindowTalked" + } +#endif + +#ifdef _CFREE_petskill + ,{ + "NPC_FreePetSkill","FreePetSkillInit","","","","","", + "","", + "FreePetSkillTalked","","","","","","", + "FreePetSkillWindowTalked" + } + +#endif + +#ifdef _PETRACE + // + ,{ + "PetRaceMaster","PetRaceMasterInit","","","","","", + "PetRaceMasterLoop","", + "PetRaceMasterTalked","","","","","","", + "PetRaceMasterWindowTalked" + } + // + ,{ + "PetRacePet","PetRacePetInit","","","","","", + "PetRacePetLoop","", + "PetRacePetTalked","","","","","","","" + } +#endif + +#ifdef _NEW_WARPMAN + ,{ + "NPC_NewNpcMan","NewNpcManInit","","","","","", + "NewNpcManLoop","", + "NewNpcManTalked","","","","","","", + "NewNpcManWindowTalked" + } +#endif + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + ,{ + "Alldoman","AlldomanInit","","", + "","","","","","AlldomanTalked","","","","","","", + "AlldomanWindowTalked"} +#endif + +#ifdef _NPC_WELFARE + ,{ "Welfare","WelfareInit","","", + "","","","", + "","WelfareTalked","","", + "","", "","","WelfareWindowTalked"} +#endif +#ifdef _PAUCTION_MAN + ,{ "Pauction","PauctionInit","","", + "","","","", + "","PauctionTalked","","", + "","", "","","PauctionWindowTalked"} +#endif +}; + +static int NPC_searchFunctionSet( char* name, int* unuse) +{ + int i; + for( i=0 ; i =arraysizeof(functionSet) )return FALSE; + + strcpysafe( ch->charfunctable[CHAR_INITFUNC].string, + sizeof( ch->charfunctable[CHAR_INITFUNC].string ), + functionSet[id].initfunc); + + strcpysafe( ch->charfunctable[CHAR_WALKPREFUNC].string, + sizeof(ch->charfunctable[CHAR_WALKPREFUNC].string), + functionSet[id].walkprefunc); + + strcpysafe( ch->charfunctable[CHAR_WALKPOSTFUNC].string, + sizeof(ch->charfunctable[CHAR_WALKPOSTFUNC].string), + functionSet[id].walkpostfunc); + + strcpysafe( ch->charfunctable[CHAR_PREOVERFUNC].string, + sizeof(ch->charfunctable[CHAR_PREOVERFUNC].string), + functionSet[id].preoverfunc); + + strcpysafe( ch->charfunctable[CHAR_POSTOVERFUNC].string, + sizeof(ch->charfunctable[CHAR_POSTOVERFUNC].string), + functionSet[id].postoverfunc); + + strcpysafe( ch->charfunctable[CHAR_WATCHFUNC].string, + sizeof(ch->charfunctable[CHAR_WATCHFUNC].string), + functionSet[id].watchfunc); + + strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string, + sizeof(ch->charfunctable[CHAR_LOOPFUNC].string), + functionSet[id].loopfunc); + + strcpysafe( ch->charfunctable[CHAR_TALKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_TALKEDFUNC].string), + functionSet[id].talkedfunc); + + strcpysafe( ch->charfunctable[CHAR_DYINGFUNC].string, + sizeof(ch->charfunctable[CHAR_DYINGFUNC].string), + functionSet[id].dyingfunc); + + strcpysafe( ch->charfunctable[CHAR_PREATTACKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_PREATTACKEDFUNC].string), + functionSet[id].preattackedfunc); + strcpysafe( ch->charfunctable[CHAR_POSTATTACKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_POSTATTACKEDFUNC].string), + functionSet[id].postattackedfunc); + + strcpysafe( ch->charfunctable[CHAR_OFFFUNC].string, + sizeof(ch->charfunctable[CHAR_OFFFUNC].string), + functionSet[id].offfunc ); + + strcpysafe( ch->charfunctable[CHAR_LOOKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_LOOKEDFUNC].string), + functionSet[id].lookedfunc ); + + strcpysafe( ch->charfunctable[CHAR_ITEMPUTFUNC].string, + sizeof(ch->charfunctable[CHAR_ITEMPUTFUNC].string), + functionSet[id].itemputfunc ); + + strcpysafe( ch->charfunctable[CHAR_SPECIALTALKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_SPECIALTALKEDFUNC].string), + functionSet[id].specialtalkedfunc ); + + strcpysafe( ch->charfunctable[CHAR_WINDOWTALKEDFUNC].string, + sizeof(ch->charfunctable[CHAR_WINDOWTALKEDFUNC].string), + functionSet[id].windowtalkedfunc ); + +#ifdef _USER_CHARLOOPS + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof(ch->charfunctable[CHAR_LOOPFUNCTEMP1].string), ""); + + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP2].string, + sizeof(ch->charfunctable[CHAR_LOOPFUNCTEMP2].string), ""); +#endif + return TRUE; +} + + +typedef enum +{ + NPC_INTENTRY=0, + NPC_CHARENTRY=1, + NPC_INTFUNC=2, + NPC_CHARFUNC=3, +}NPC_TYPECATEGORYATREADFILE; + +/*------------------------------------------------------------ + * Template index ƻоcheck + * ¦ + * index int index + * ߯Ի + * valid TRUE + * invalid FALSE + ------------------------------------------------------------*/ +INLINE int NPC_CHECKTEMPLATEINDEX(int index) +{ + if( NPC_templatenum <= index || index < 0 )return FALSE; + return TRUE; +} +/*------------------------------------------------------------ + * Template intdata index ƻоcheck + * ¦ + * index int index + * ߯Ի + * valid TRUE + * invalid FALSE + ------------------------------------------------------------*/ +static INLINE int NPC_CHECKTEMPLATEINTINDEX(int index) +{ + if( NPC_TEMPLATEINTNUM <= index || index < 0 )return FALSE; + return TRUE; +} +/*------------------------------------------------------------ + * Template chardata index ƻоcheck + * ¦ + * index int index + * ߯Ի + * valid TRUE + * invalid FALSE + ------------------------------------------------------------*/ +static INLINE int NPC_CHECKTEMPLATECHARINDEX(int index) +{ + if( NPC_TEMPLATECHARNUM <= index || index < 0 )return FALSE; + return TRUE; +} + + + +/*------------------------------------------------------------ + * ¦ + * filenum int ̻ + * ߯Ի + ------------------------------------------------------------*/ +BOOL NPC_initTemplateArray( int templatenum ) +{ + NPC_templatenum = templatenum; + NPC_template = (NPC_Template*)allocateMemory( sizeof( NPC_Template ) * + NPC_templatenum ); + if( NPC_template == NULL )return FALSE; + NPC_template_readindex = 0; + return TRUE; +} + +/*------------------------------------------------------------ + * ¦ + * ߯Ի + * ئ + ------------------------------------------------------------*/ +void NPC_setDefaultNPCTemplate( NPC_Template* temp ) +{ + int i; + if( temp == NULL )return; + + for( i=0 ; i< arraysizeof(temp->chardata) ; i ++ ) + memset( &temp->chardata[i], 0, sizeof(temp->chardata[i] )); + + temp->intdata[NPC_TEMPLATEMAKEATNOBODY]=0; + temp->intdata[NPC_TEMPLATEMAKEATNOSEE]=0; + temp->intdata[NPC_TEMPLATEIMAGENUMBER]=0; + temp->intdata[NPC_TEMPLATETYPE]=-1; + + temp->intdata[NPC_TEMPLATEMINHP]=0; + temp->intdata[NPC_TEMPLATEMINMP]=0; + temp->intdata[NPC_TEMPLATEMINSTR]=0; + temp->intdata[NPC_TEMPLATEMINTOUGH]=0; + + temp->intdata[NPC_TEMPLATEISFLYING]=0; + + temp->intdata[NPC_TEMPLATEITEMNUM]=0; + temp->intdata[NPC_TEMPLATELOOPFUNCTIME]=-1; + temp->intdata[NPC_TEMPLATEFUNCTIONINDEX]=-1; + + for( i=0; irandomdata[i] = 0; + } + + temp->hash = 0; + temp->haveitem=NULL; +} + +BOOL NPC_IsNPCTemplateFile( char* filename ) +{ + FILE* f; + char line1[128]; + char* ret; + if( filename == NULL + ||strlen( filename ) < 1 + ||filename[strlen(filename)-1] == '~' + ||filename[0] == '#' + ||strcmptail( filename, ".bak" ) == 0 )return FALSE; +#ifdef _CRYPTO_DATA + BOOL crypto = FALSE; + if(strcmptail(filename, ".allblues")==0){ + crypto=TRUE; + } +#endif + f = fopen( filename , "r" ); + if( f == NULL ) goto RETURNFALSE; + ret = fgets( line1, sizeof( line1 ), f ); + if( ret == NULL )goto FCLOSERETURNFALSE; +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line1); + } +#endif + if( strcmp( NPC_TEMPLATEFILEMAGIC, line1 ) == 0 ){ + fclose(f); + return TRUE; + } + +FCLOSERETURNFALSE: + fclose(f); +RETURNFALSE: + return FALSE; +} + +void NPC_templateallocitemdata( NPC_Template* one ) +{ + int itemnum = one->intdata[NPC_TEMPLATEITEMNUM]; + if( itemnum > 8 ) itemnum = 8; + else if( itemnum <= 0 ) itemnum = 0; + one->intdata[NPC_TEMPLATEITEMNUM] = itemnum; + one->haveitem = allocateMemory( sizeof( NPC_haveItem ) * itemnum ); + +} + + +/*------------------------------------------------------------ + * NPC_getRandomValue 缰¦Ѽѯ뼰׻ + * ¦ + * ߯Ի + ------------------------------------------------------------*/ +static int NPC_seekGraphicNumberFromString( char* string, int* unuse ) +{ + return CHAR_seekGraphicNumberFromString( string ); + +} +/*------------------------------------------------------------ + * ¦ + * ߯Ի + ------------------------------------------------------------*/ +static int NPC_getRandomValue( char* string,int* randomwidth ) +{ + int minvalue; + int maxvalue; + char* startmax=NULL; + + minvalue = atoi( string ); + startmax = index( string,',' ); + if( startmax != NULL ){ + /* ¼ĸةɬûľ */ + /* +1 ","׻ */ + maxvalue = atoi(startmax+1); + + /* ɬ÷ */ + *randomwidth = ABS(maxvalue - minvalue); + return min(minvalue,maxvalue); + } + *randomwidth = 0; + return minvalue; +} + + +/*------------------------------------------------------------ + * ¦ + * ߯Ի + ------------------------------------------------------------*/ +BOOL NPC_readTemplateFile( char* filename ) +{ + FILE* f; + char line[512]; + int linenum=0; + int start=OFF; + NPC_Template temp; + int itmreadindex=0; + char* ret; + int randomdata[NPC_TEMPLATEINTNUM]; + int i; + + if( NPC_template_readindex >= NPC_templatenum ){ + print("ģ鳬Ŀ\n" ); + print("ģĿ %d\n", NPC_templatenum); + return FALSE; + } + + for( i=0; i= NPC_templatenum ){ + print("ģ鳬Ŀ\n" ); + print("ģĿ %d\n", + NPC_templatenum); + goto FCLOSERETURNFALSE; + } + } + NPC_setDefaultNPCTemplate( &temp ); + itmreadindex=0; + start=OFF; + }else{ + fprint( "δ '}' at %s:%d\n",filename,linenum); + goto FCLOSERETURNFALSE; + } + break; + default: + { + typedef struct tagNPC_Readtemplate + { + char* keyword; + NPC_TYPECATEGORYATREADFILE type; + int index; + void* func; + }NPC_Readtemplate; + static NPC_Readtemplate NPC_readtemplate[NPC_TEMPLATECHARNUM+NPC_TEMPLATEINTNUM]= + { + {"templatename" , NPC_CHARENTRY, NPC_TEMPLATENAME,NULL}, + {"name" , NPC_CHARENTRY, NPC_TEMPLATECHARNAME, + NULL}, + {"makeatnobody", NPC_INTENTRY, NPC_TEMPLATEMAKEATNOBODY, + NULL}, + {"makeatnosee" , NPC_INTENTRY, NPC_TEMPLATEMAKEATNOSEE, + NULL}, + {"graphicname", NPC_INTFUNC, NPC_TEMPLATEIMAGENUMBER, + NPC_seekGraphicNumberFromString}, + {"type", NPC_INTFUNC, NPC_TEMPLATETYPE, + NPC_seekGraphicNumberFromString}, + + {"hp", NPC_INTFUNC, NPC_TEMPLATEMINHP, + NPC_getRandomValue}, + {"mp", NPC_INTFUNC, NPC_TEMPLATEMINMP, + NPC_getRandomValue}, + {"str", NPC_INTFUNC, NPC_TEMPLATEMINSTR, + NPC_getRandomValue}, + {"tough", NPC_INTFUNC, NPC_TEMPLATEMINTOUGH, + NPC_getRandomValue}, + + {"fly", NPC_INTENTRY,NPC_TEMPLATEISFLYING,NULL}, + + {"itemnum", NPC_INTENTRY, NPC_TEMPLATEITEMNUM, NULL,}, + {"functionset",NPC_INTFUNC, NPC_TEMPLATEFUNCTIONINDEX, + NPC_searchFunctionSet,}, + {"initfunc", NPC_CHARENTRY, NPC_TEMPLATEINITFUNC,NULL,}, + {"walkprefunc", NPC_CHARENTRY, NPC_TEMPLATEWALKPREFUNC, + NULL,}, + {"walkpostfunc",NPC_CHARENTRY, NPC_TEMPLATEWALKPOSTFUNC, + NULL,}, + {"preoverfunc", NPC_CHARENTRY, NPC_TEMPLATEPREOVERFUNC, + NULL,}, + {"postoverfunc",NPC_CHARENTRY, NPC_TEMPLATEPOSTOVERFUNC, + NULL,}, + {"watchfunc", NPC_CHARENTRY, NPC_TEMPLATEWATCHFUNC, + NULL,}, + {"loopfunc", NPC_CHARENTRY, NPC_TEMPLATELOOPFUNC, NULL,}, + {"talkedfunc",NPC_CHARENTRY,NPC_TEMPLATETALKEDFUNC,NULL,}, + {"dyingfunc",NPC_CHARENTRY,NPC_TEMPLATEDYINGFUNC,NULL,}, + {"preattackedfunc",NPC_CHARENTRY, + NPC_TEMPLATEPREATTACKEDFUNC,NULL,}, + {"postattackedfunc",NPC_CHARENTRY, + NPC_TEMPLATEPOSTATTACKEDFUNC,NULL,}, + {"offfunc",NPC_CHARENTRY,NPC_TEMPLATEOFFFUNC,NULL,}, + {"lookedfunc",NPC_CHARENTRY,NPC_TEMPLATELOOKEDFUNC,NULL,}, + {"itemputfunc",NPC_CHARENTRY,NPC_TEMPLATEITEMPUTFUNC, + NULL,}, + {"specialtalkedfunc",NPC_CHARENTRY, + NPC_TEMPLATESPECIALTALKEDFUNC, NULL,}, + + {"windowtalkedfunc",NPC_CHARENTRY, + NPC_TEMPLATEWINDOWTALKEDFUNC, NULL,}, + + {"loopfunctime",NPC_INTENTRY,NPC_TEMPLATELOOPFUNCTIME, + NULL,}, + }; + + char firstToken[256]; + int ret,i; + ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, sizeof( firstToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", filename , linenum); + break; + } + + if( strcasecmp(firstToken,"itm") == 0 ){ + char one[128]; + char two[128]; + char three[128]; + int itemnumber=0,rate=0,amount=1; + char secondToken[256]={""}; + if( itmreadindex < temp.intdata[NPC_TEMPLATEITEMNUM] && + temp.haveitem != NULL ) + ; + else + continue; + ret = getStringFromIndexWithDelim( line, "=", 2, + secondToken, sizeof(secondToken ) ); + if( ret == FALSE ){ + print( "Find error at %s in line %d. Ignore\n", + filename , linenum); + secondToken[0] = '\0'; + } + ret = getStringFromIndexWithDelim( secondToken, "|", 1, one,sizeof( one ) ); + if( ret != FALSE )itemnumber=atoi(one); + ret = getStringFromIndexWithDelim( secondToken, "|", 2, two,sizeof(two)); + if( ret != FALSE )rate=atoi(two); + ret = getStringFromIndexWithDelim( secondToken, "|", 3, three,sizeof(three)); + if( ret != FALSE )amount=atoi(three); + if( rate > 0 && amount > 0 ){ + if( itemnumber == -1 ){ + temp.haveitem[itmreadindex].itemnumber = -1; + temp.haveitem[itmreadindex].haverate = rate; + temp.haveitem[itmreadindex].havenum = amount; + itmreadindex++; + }else if( ITEM_CHECKITEMTABLE( itemnumber ) == TRUE ){ + temp.haveitem[itmreadindex].itemnumber=itemnumber; + temp.haveitem[itmreadindex].haverate = rate; + temp.haveitem[itmreadindex].havenum = amount; + itmreadindex++; + }else + print("this item is not item %s:%d\n", + filename , linenum); + }else + print("rate or amount is odd setting. rate=%d " + "amount=%d %s:%d\n", rate,amount, filename, + linenum); + goto NEXT; + }else{ + for( i = 0 ; i < arraysizeof(NPC_readtemplate) ; i ++ ){ + if( strcasecmp( NPC_readtemplate[i].keyword, + firstToken ) == 0 ){ + char secondToken[256]={""}; + ret = getStringFromIndexWithDelim( + line, "=", 2, secondToken, sizeof(secondToken) + ); + if( ret == FALSE ) + print( "Find error at %s in line %d. Ignore\n" + ,filename , linenum); + + switch( NPC_readtemplate[i].type ){ + case NPC_INTENTRY: + temp.intdata[NPC_readtemplate[i].index]=atoi(secondToken); + if( NPC_readtemplate[i].index == NPC_TEMPLATEITEMNUM ) + NPC_templateallocitemdata( &temp ); + break; + case NPC_CHARENTRY: + strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, + sizeof(temp.chardata[NPC_readtemplate[i].index].string), + secondToken); + break; + case NPC_INTFUNC: + { + int (*intfunction)(char*,int* ); + intfunction = NPC_readtemplate[i].func; + temp.intdata[NPC_readtemplate[i].index] + = intfunction( secondToken, &randomdata[NPC_readtemplate[i].index]); + break; + } + case NPC_CHARFUNC: + { + char* (*charfunction)(char* ); + charfunction = NPC_readtemplate[i].func; + strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, + sizeof(temp.chardata[NPC_readtemplate[i].index].string), + charfunction(secondToken)); + break; + } + default: + break; + } + goto NEXT; + } + } + } + fprint("%s:%d There is no such entry %s\n" , filename, + linenum, firstToken ); + NEXT: + break; + } + break; + } + } + fclose(f); + return TRUE; + +FCLOSERETURNFALSE: + fclose(f); + return FALSE; +} + +BOOL NPC_readNPCTemplateFiles( char* topdirectory ,int templatesize) +{ + STRING64 *filenames; + int filenum; + int i; + filenames = (STRING64 *)allocateMemory( sizeof( STRING64 ) * + (int)getFilesearchnum( ) ); + if( filenames == NULL ){ + print( "ȡNPCļ... ڴ\n" ); + return FALSE; + } + filenum = rgetFileName( topdirectory ,filenames ,getFilesearchnum( ) ); + if( filenum == -1 ){ + fprint("޷ %s ݹȡļ\n",topdirectory); + freeMemory( filenames ); + return FALSE; + } + if( filenum >= getFilesearchnum( ) ){ + print( "ļĿʧ %d\n", getFilesearchnum( ) ); + while( 1 ); + }else{ + print( "ļ = %d\n", filenum ); + } + if( !NPC_initTemplateArray( templatesize ) ){ + fprint( "ģ\n" ); + freeMemory( filenames ); + return FALSE; + } + print( "ȡļģ...." ); + for( i = 0 ; i < filenum ; i ++ ) + if( NPC_IsNPCTemplateFile( filenames[i].string )) + NPC_readTemplateFile( filenames[i].string ); + print( "ȷģ %d ...\n" , NPC_template_readindex ); + NPC_templatenum=NPC_template_readindex; + freeMemory( filenames ); + return TRUE; +} + + + +/*------------------------------------------------------------ + * ¦ + * ߯Ի + * -1 ݾ޷¡ + ------------------------------------------------------------*/ +int NPC_templateGetTemplateIndex( char* templatename ) +{ + int i; + int hash=hashpjw( templatename ); + + for( i = 0 ; i < NPC_templatenum ; i ++ ) + if( hash == NPC_template[i].hash && + strcasecmp( templatename , NPC_template[i].chardata[NPC_TEMPLATENAME].string) == 0 ) + return i; + + return -1; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcutil.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcutil.c new file mode 100644 index 0000000..4129f30 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc/npcutil.c @@ -0,0 +1,1737 @@ +#include "version.h" +#include +#include "common.h" +#include "char.h" +#include "char_base.h" +#include "configfile.h" +#include "object.h" +#include "item.h" +#include "map_deal.h" +#include "npcutil.h" +#include "npc_door.h" +#include "readmap.h" +#include "npccreate.h" +#include "enemy.h" +#include "autil.h" + +// CoolFish: Family 2001/7/29 +#include "family.h" +#include "saacproto_cli.h" + +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + +extern struct FM_POINTLIST fmpointlist; +#ifdef _NEW_ITEM_ +extern int CheckCharMaxItem(int charindex); +#endif +#ifdef _PERSONAL_FAME // Arminius 8.30: + +// Arminius: Ұֵ +int FMAdvTbl[] = { // ð Table + 0, // 0 + 1, // 1 + 1, // 2 + 0, // 3 + 10, // 4 + 5, // 5 + 0, // 6 + 0, // 7 + 30, // 8 + 0, // 9 + 0, // 10 + 0, // 11 + 68, // 12 + 68, // 13 + 0, // 14 + 15, // 15 + 120, // 16 + 90, // 17 + 0, // 18 + 120, // 19 + 0, // 20 + 0, // 21 + 60, // 22 + 0, // 23 + 0, // 24 + 0, // 25 + 60, // 26 + 0, // 27 + 0, // 28 + 0, // 29 + 0, // 30 + 60, // 31 + 0, // 32 + 0, // 33 + 30, // 34 + 225, // 35 + 0, // 36 + 0, // 37 + 60, // 38 + 135, // 39 + 600, // 40 + 0, // 41 + 360, // 42 + 0, // 43 + 0, // 44 + 480, // 45 + 840, // 46 + 0, // 47 + 600, // 48 + 600, // 49 + 600, // 50 + 600, // 51 + 600, // 52 + 600, // 53 + 720, // 54 + 0, // 55 + 0, // 56 + 0, // 57 + 0, // 58 + 0, // 59 + 0, // 60 + 0, // 61 + 0, // 62 + 120, // 63 + 900, // 64 + 0, // 65 + 0, // 66 + 0, // 67 + 0, // 68 + 0, // 69 + 0, // 70 + 15000, // 71 + 20000, // 72 + 0, // 73 + 0, // 74 + 0, // 75 + 0, // 76 + 0, // 77 + 0, // 78 + 0, // 79 + 0, // 80 + 1200, // 81 + 3000, // 82 + 0, // 83 + 1500, // 84 + 0, // 85 + 0, // 86 + 100, // 87 + 0, // 88 + 400, // 89 + 0, // 90 + 0, //91 + 0, // 92 + 0, // 93 + 0, // 94 + 0, // 95 + 0, // 96 + 100, // 97 + 0, // 98 + 0, // 99 + 0, // 100 + 0, //101 + 0, //102 + 0, //103 + 0, //104 + 600, // 105 + 0, // 106 + 100, // 107 + 0, // 108 + 0, // 109 + 400, // 110 + 500, // 111 + 1000, // 112 + 100, // 113 + 300, // 114 + 0, // 115 + 500, // 116 + 15000, // 117 + 0, // 118 + 0, // 119 + 0, // 120 + 0, // 121 + 0, // 122 + 0, // 123 + 0, // 124 + 400, // 125 + 300, // 126 + 0, // 127 + 0, // 128 + 0, // 129 + 0, // 130 + 0, // 131 + 0, // 132 + 500, // 133 +}; + +#endif + +BOOL NPC_Util_AddOneTitle( int charindex, int titleindex ) +{ + int i; + Char *c ; + + if( !CHAR_CHECKINDEX( charindex ) )return FALSE; + + c = CHAR_getCharPointer( charindex ); + // CoolFish: +1 2001/11/05 + if (!c) return FALSE; + + for(i=0;iindexOfHaveTitle[i] == -1 ){ + c->indexOfHaveTitle[i] = titleindex; + return TRUE; + } + } + return FALSE; +} + + +BOOL NPC_Util_HaveTitle( int charindex , int titleindex ) +{ + int i; + Char *c; + if( !CHAR_CHECKINDEX( charindex ) )return -1; + + c = CHAR_getCharPointer( charindex ); + // CoolFish: +1 2001/11/05 + if (!c) return FALSE; + + for(i=0;iindexOfHaveTitle[i] == titleindex ){ + return TRUE; + } + } + return FALSE; +} + + +BOOL NPC_Util_Nearby( int x1 , int y1, int x2 , int y2 ) +{ + if( ABS( x1 - x2 ) <= 1 && + ABS( y1 - y2 ) <= 1 ){ + return TRUE; + } else { + return FALSE; + } +} + +BOOL NPC_Util_CharNearby(int ind1,int ind2) +{ + if( !CHAR_CHECKINDEX(ind1)) return FALSE; + if( !CHAR_CHECKINDEX(ind2)) return FALSE; + + if( CHAR_getInt( ind1 , CHAR_FLOOR ) != + CHAR_getInt( ind2 , CHAR_FLOOR ) ){ + return FALSE; + } + + return NPC_Util_Nearby( CHAR_getInt( ind1,CHAR_X), + CHAR_getInt( ind1,CHAR_Y), + CHAR_getInt( ind2,CHAR_X), + CHAR_getInt( ind2,CHAR_Y)); + +} + + +static struct ynset +{ + int value; + char string[32]; +}yntable[] ={ + { 0 , "no" }, + { 0 , "No" }, + { 0 , "NO" }, + { 0 , "NO" }, + { 0 , "No" }, + { 0 , "no" }, + { 0 , "" }, + { 0 , "" }, + + { 1 , "yes" }, + { 1 , "Yes" }, + { 1 , "YES" }, + { 1 , "YES" }, + { 1 , "Yes" }, + { 1 , "yes" }, + { 1 , "" }, + { 1 , "" }, + +}; + +int NPC_Util_YN(char *input ) +{ + int i; + for(i=0;;i++){ + int j; + + if( input[i] == '\0' ){ + return -1; + } + for(j=0;jx - pstart->x; + dify = pend->y - pstart->y; + + if( difx < 0 )difx=-1; + else if( difx > 0 )difx=1; + if( dify < 0 )dify=-1; + else if( dify > 0 )dify=1; + + return dirtable[dify+1][difx+1]; +} + +int NPC_Util_countHaveItem( int meindex , int itemid ) +{ + int i, count=0, itemindex; + if( !CHAR_CHECKINDEX(meindex))return -1; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(meindex); + for( i=0 ; i= 0 ){ + CHAR_ObjectDelete( oind ); + CHAR_setItemIndex( charindex, emptyindex, itemindex ); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1 ); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charindex ); + if( net ) CHAR_sendItemDataOne( charindex, emptyindex); + return TRUE; + }else if( cind >= 0 ){ + int itemgrp[2]; + int itemindexinchara; + if( cind == charindex )return FALSE; + itemindexinchara = NPC_Util_SearchItemInChar( cind , itemindex); + if( itemindexinchara == -1 )return FALSE; + CHAR_setItemIndex( cind , itemindexinchara , -1 ); + CHAR_complianceParameter(cind); + itemgrp[0] = itemindexinchara; + CHAR_setItemIndex( charindex , emptyindex , itemindex ); + itemgrp[1] = emptyindex; + if( net ) CHAR_sendItemData( charindex, itemgrp, arraysizeof(itemgrp)); + ITEM_setWorkInt( itemindex, ITEM_WORKOBJINDEX, -1 ); + ITEM_setWorkInt( itemindex, ITEM_WORKCHARAINDEX, charindex ); + return TRUE; + } + return FALSE; +} + +BOOL NPC_Util_moveItemToMap( int itemindex , int fl , int x , int y, + BOOL net ) +{ + int oind,cind; + + if( !ITEM_CHECKINDEX( itemindex ) ) return FALSE; + + oind = ITEM_getWorkInt( itemindex , ITEM_WORKOBJINDEX ); + cind = ITEM_getWorkInt( itemindex , ITEM_WORKCHARAINDEX ); + + if( oind >= 0 ){ + return MAP_objmove( oind , OBJECT_getFloor(oind), + OBJECT_getX(oind), + OBJECT_getY(oind), + fl,x,y); + } else if( cind >= 0 ){ + int itemindexinchara = NPC_Util_SearchItemInChar(cind,itemindex); + if( itemindexinchara == -1 ) return FALSE; + + CHAR_setItemIndex( cind , itemindexinchara , -1 ); + CHAR_complianceParameter(cind); + if( net ) CHAR_sendItemDataOne( cind, itemindexinchara); + if( CHAR_DropItemAbsolute( itemindex, fl,x,y,TRUE) < 0 ){ + return FALSE; + } else { + return TRUE; + } + } + return FALSE; +} + +int NPC_Util_GiveAllItemToChar( int give , int take ) +{ + int i ; + int count=0; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(take); + for(i=0;i= 0 )break; + }else + if( Part == 1 ){ /* 㯼̼ë */ + iTarget = SearchNearLine( x+Level, y-Level+1, + floor, 0, 1, Level*2, type ); + if( iTarget >= 0 )break; + }else + if( Part == 2 ){ /* Ʊ̼ë */ + iTarget = SearchNearLine( x+Level-1, y+Level, + floor, -1, 0, Level*2, type ); + if( iTarget >= 0 ) break; + }else + if( Part == 3 ){ /* ̼ë */ + iTarget = SearchNearLine( x-Level, y+Level-1, + floor, 0, -1, Level*2, type ); + if( iTarget >= 0 ) break; + } + Part ++; Part &= 3; /* ݼɡë */ + } + return iTarget; +} + +int NPC_Util_SearchNear( int meindex, int maxlen, int type ) +{ +#if 1 + int floor, x, y, i,iTarget = -1; + if( !CHAR_CHECKINDEX( meindex ) )return -1; + floor = CHAR_getInt( meindex, CHAR_FLOOR ); + x = CHAR_getInt( meindex, CHAR_X ); + y = CHAR_getInt( meindex, CHAR_Y ); + + for( i = 0; i < maxlen; i ++ ){ + iTarget = SearchNearAround( x, y, floor, RAND( 0,3 ), i+1, type ); + if( iTarget >= 0 )break; + } + return iTarget; + + +#else + int floor, x, y, i,iTarget = -1, iLen, iMin = 655360, tX, tY; + if( !CHAR_CHECKINDEX( meindex ) )return -1; + floor = CHAR_getInt( meindex, CHAR_FLOOR ); + x = CHAR_getInt( meindex, CHAR_X ); + y = CHAR_getInt( meindex, CHAR_Y ); + + /* */ + for( i = 0 ; i maxlen )continue; /* Tľʿ*/ + if( tY > maxlen )continue; /* ئݳ*/ + + iLen = tX*tX+tY*tY; + if( iMin > iLen ){ + iMin = iLen; + iTarget = obj[i].index; /* ̼͵ë趪E*/ + } + } + + return iTarget; +#endif +} +/*------------------------------------------------------------ +------------------------------------------------------------*/ +int NPC_Util_SearchNearPlayer( int meindex, int maxlen ) +{ + return( NPC_Util_SearchNear( meindex, maxlen, CHAR_TYPEPLAYER)); +} +/*------------------------------------------------------------ +-----------------------------------------------------------*/ +int NPC_Util_SearchNearEnemy( int meindex, int maxlen ) +{ + return( NPC_Util_SearchNear( meindex, maxlen, CHAR_TYPEENEMY)); +} + + + +/******************************************************* + + int NPC_Util_SuberiWalk( + int index, CHAR ̼͵ + ); + + -1 Ѩ¦ȾȻ޷¡ + -2 ƽҷ¦ȾȻ޷¡ + + +*******************************************************/ +int NPC_Util_OtherCharCheck( int ff, int fx, int fy) +{ +#if 1 + OBJECT object; + for( object=MAP_getTopObj(ff,fx,fy); object ; + object = NEXT_OBJECT(object) ) + { + int objindex = GET_OBJINDEX(object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + return 1; + } + } + return 0; +#else + int i; + for( i = 0 ; i < objnum ; i ++){ + if( obj[i].x == fx && obj[i].y == fy && obj[i].floor == ff ){ + if( obj[i].type != OBJTYPE_NOUSE ){ + return 1; + } + } + } + return 0; +#endif +} + + +int NPC_Util_SuberiWalk( + int index, + int dir +) +{ + int i, OkFlg = 0, x = 0, y = 0, fl = 0; + int aDirList[3],dir2; + int tX, tY; + + x = CHAR_getInt(index,CHAR_X); + y = CHAR_getInt(index,CHAR_Y); + fl = CHAR_getInt(index,CHAR_FLOOR); + + switch( dir ){ + case 1: aDirList[0] = 0; aDirList[1] = 2; aDirList[2] = 1; + break; + case 3: aDirList[0] = 2; aDirList[1] = 4; aDirList[2] = 3; + break; + case 5: aDirList[0] = 4; aDirList[1] = 6; aDirList[2] = 5; + break; + case 7: aDirList[0] = 6; aDirList[1] = 0; aDirList[2] = 7; + break; + default: + tX = x+CHAR_getDX(dir); + tY = y+CHAR_getDY(dir); + /* ׻*/ + if( MAP_walkAble( index,fl,tX,tY ) == 0 ){ + dir = -1;/* Ѩ¦Ⱦ*/ + } +// }else +// if( NPC_Util_OtherCharCheck( fl,tX, tY ) ){ +// dir = -2;/* ƽҷ±¦Ⱦ*/ +// } +/* CHAR_walk( index, dir, 0 );*/ + return dir; + } + + for( i = 0; i < 3; i ++ ){ + dir2 = aDirList[i]; + tX = x+CHAR_getDX(dir2); + tY = y+CHAR_getDY(dir2); + if( MAP_walkAble( index,fl,tX,tY ) == 0 ){ + aDirList[i] = -1; /* ئfڽ*/ +// }else if( NPC_Util_OtherCharCheck( fl,tX, tY ) ){ + }else{ + /* !!*/ + OkFlg ++; + } + } + + if( aDirList[0] >= 0 && aDirList[1] >= 0 && aDirList[2] >= 0 ){ + }else + if( aDirList[0] >= 0 ){ + dir = aDirList[0]; + }else + if( aDirList[1] >= 0 ){ + dir = aDirList[1]; + }else{ + dir = aDirList[0]+aDirList[1]; + } + +/* CHAR_walk( index, dir, 0 );*/ + + return dir; +} +/*----------------------------------------------------------------------- +* +* ---------------------------------- +* IN : int meindex : ƽҷindex +* OUT: +* RETURN: +* ---------------------------------- +* +* [File:enemykill.create] +* enemy=enemykill|range:4 +* +* call: +* range = NPC_Util_GetNumFromArg( index, "range"); +*----------------------------------------------------------------------*/ +int NPC_Util_GetNumFromArg( int meindex, char* in) +{ + BOOL rc; + int i; + char outstr[sizeof( STRING32)]; + int out = -1; + char *a = CHAR_getChar( meindex, CHAR_NPCARGUMENT); + + for( i = 1; ; i++ ) { + rc = getStringFromIndexWithDelim( a, "|", i, outstr, sizeof(outstr)); + if( rc == FALSE) break; + if( strstr( outstr, in) != NULL ) { + out = textToInt( outstr); + break; + } + } + + return out; +} + +/* + * ƥ¾ľѹ + * by ringo + * + * int charindex : ƽҷ¼ index + * + * ߯Ի + * + */ +int NPC_Util_SearchItemInChar( int charindex , int itemindex) +{ + int i; + + if( !CHAR_CHECKINDEX(charindex) ) return -2; + if( !ITEM_CHECKINDEX(itemindex) ) return -2; +#ifdef _NEW_ITEM_ + int itemMax = CheckCharMaxItem(charindex); +#endif + for(i=0; +#ifdef _NEW_ITEM_ + i 3)? dir -4 : dir +4; + else if( mode == 2) dir = (dir + 2) % 8; + else if( mode == 3) dir = (dir < 1)? dir +6 : dir -2; + ret = dir; + } + return( ret); +} + +/*------------------------------------------------------------------------ +* +* int NPC_Util_WalkCharToChar( int fromindex, int toindex, int mode) +* +* 0:toindexȻ +* +------------------------------------------------------------------------*/ +int NPC_Util_WalkCharToChar( int fromindex, int toindex, int mode, int suberi) +{ + int ret = -1; + int dir; + + if( CHAR_getInt( fromindex, CHAR_FLOOR) + != CHAR_getInt( toindex, CHAR_FLOOR)) + { + return( -1); + } + dir = NPC_Util_GetDirCharToChar( fromindex, toindex, mode ); + if( dir != -1) { + if( suberi) { + dir = NPC_Util_SuberiWalk( fromindex, dir ); + } + } + if( dir >= 0 ) { + ret = CHAR_walk(fromindex,dir,0); + if( ret == CHAR_WALKSUCCESSED ) ret = dir; + else ret = -1; + } + return( ret); +} + + +/*------------------------------------------------------------------------ +* +* void NPC_Util_NPCDelete( int srcindex) +* +* int srcindex index +* +------------------------------------------------------------------------*/ +void NPC_Util_NPCDelete( int srcindex) +{ + //int objindex; + //objindex = CHAR_getWorkInt(srcindex,CHAR_WORKOBJINDEX); + + if( CHAR_getInt( srcindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ) return; + if( NPC_createCheckMaxEnemynum( CHAR_getInt(srcindex,CHAR_NPCCREATEINDEX ))) + NPC_createInitTime( CHAR_getInt(srcindex,CHAR_NPCCREATEINDEX )); + NPC_createDecreaseEnemynum( CHAR_getInt(srcindex, + CHAR_NPCCREATEINDEX ) ); + + CHAR_CharaDelete( srcindex ); + +} + +char *NPC_Util_CheckAssignArgFile( int index, char *filename) +{ + BOOL rc; + int i; + char *cret = NULL; + char outstr[64]; + char outstr2[64]; + char *a = CHAR_getChar( index , CHAR_NPCARGUMENT ); + + if( a == NULL ) { + print( "%s : %d err\n", __FILE__, __LINE__); + return cret; + } + + for( i = 1; ; i++ ) { + rc = getStringFromIndexWithDelim( a, "|", i, outstr, sizeof(outstr)); + if( rc == FALSE) break; + if( strstr( outstr, "file") != NULL ) { + rc = getStringFromIndexWithDelim( outstr, ":", 2, + outstr2, sizeof(outstr2)); + if( rc != FALSE ) { + strcpy( filename, outstr2); + cret = filename; + break; + } + } + } + return( cret); +} +static char *NPC_Util_MargeStrFromArgFile( char *filename, char *buf, int len) +{ + FILE *fp; + char *cret = NULL; + char line[NPC_UTIL_GETARGSTR_LINEMAX]; + char opfile[32]; + + sprintf( opfile, "%s/", getNpcdir( ) ); + strcat( opfile, filename); + *buf = '\0'; +#ifdef _CRYPTO_DATA + char realopfile[256]; + BOOL crypto = FALSE; + sprintf(realopfile, "%s.allblues", opfile); + fp = fopen( realopfile, "r"); + if( fp != NULL ){ + crypto = TRUE; + }else +#endif +{ + fp = fopen( opfile, "r"); +} + if( fp != NULL ) { + while( fgets( line, sizeof( line), fp)) { +#ifdef _CRYPTO_DATA + if(crypto==TRUE){ + DecryptKey(line); + } +#endif + if( strlen(buf) != 0 ) { + if( buf[strlen(buf) -1] != '|' ) { + strcatsafe( buf, len, "|"); + } + } + chompex( line); + strcatsafe( buf,len, line); + } + fclose( fp); + cret=buf; + } + return( cret); +} + +char *NPC_Util_GetArgStr( int index, char *argstr, int len) +{ + char filename[128]; + char *cret = NULL; + if( NPC_Util_CheckAssignArgFile( index, filename) != NULL ) { + if( NPC_Util_MargeStrFromArgFile( filename, argstr, len) != NULL ) { + cret = argstr; + } + }else { + if( CHAR_getChar( index, CHAR_NPCARGUMENT) != NULL ){ + strcpy( argstr, CHAR_getChar( index, CHAR_NPCARGUMENT)); + cret = argstr; + }else{ + cret = NULL; + } + } + if( cret == NULL ) print("File:%s\n", NPC_Util_CheckAssignArgFile( index, filename)); + + return( cret); +} + +int NPC_Util_GetNumFromStrWithDelim( char *srcstr, char* in) +{ + BOOL rc; + int i; + char outstr[32]; + int out = -1; + + for( i = 1; ; i++ ) { + rc = getStringFromIndexWithDelim( srcstr, "|", i, outstr, sizeof(outstr)); + if( rc == FALSE) break; + if( strstr( outstr, in) != NULL ) { + out = textToInt( outstr); + break; + } + } + + return out; +} + +char *NPC_Util_GetStrFromStrWithDelim( char *srcstr, char *srhstr, + char *buf, int buflen) +{ + BOOL rc; + char *cret = NULL; + int i; + char outstr[1024]; + char outstr2[1024]; + + memset( outstr, 0, sizeof( outstr)); + memset( outstr2, 0, sizeof( outstr2)); + buf[0] = '\0'; + for( i = 1; ; i++ ) { + rc = getStringFromIndexWithDelim( srcstr, "|", i, outstr, sizeof(outstr)); + if( rc == FALSE) break; + if( strstr( outstr, srhstr) != NULL) { + rc = getStringFromIndexWithDelim( outstr, ":", 2, outstr2, sizeof(outstr2)); + if( rc != FALSE ) { + strcpysafe( buf, buflen, outstr2 ); + cret = buf; + break; + } + } + } + return cret; +} + +inline double NPC_Util_sellRate( int seller ) +{ + return (CHAR_getInt( seller, CHAR_MERCHANTLEVEL)&0x0000ffff)*0.01; +} + +inline double NPC_Util_buyRate( int buyer ) +{ + return (CHAR_getInt( buyer, CHAR_MERCHANTLEVEL )>>16)*0.01; +} + +BOOL NPC_Util_IsVisiblePlayer( int meindex) +{ + int chr_fl,chr_x,chr_y, i, j; + BOOL found = FALSE; + + chr_fl = CHAR_getInt( meindex, CHAR_FLOOR); + chr_x = CHAR_getInt( meindex, CHAR_X); + chr_y = CHAR_getInt( meindex, CHAR_Y); + + for( i = chr_x-CHAR_DEFAULTSEESIZ/2 ; + i <= chr_x+CHAR_DEFAULTSEESIZ/2 && found == FALSE; i++ ){ + for( j = chr_y-CHAR_DEFAULTSEESIZ/2 ; + j <= chr_y+CHAR_DEFAULTSEESIZ/2 && found == FALSE; + j ++ ){ + OBJECT object; + for( object = MAP_getTopObj( chr_fl, i,j); + object; + object = NEXT_OBJECT(object) ) + { + int objindex = GET_OBJINDEX( object); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + if( CHAR_getInt( OBJECT_getIndex(objindex), + CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) + { + found = TRUE; + break; + } + } + } + } + } + return( found); +} + +BOOL NPC_Util_WordInclude( char *text , char *word ) +{ + if( strstr( text , word ) == NULL ){ + return FALSE; + } else { + return TRUE; + } +} + +void NPC_Util_RandomToken(char *in, char *out, int outbufsize ) +{ + int tokennum; + int i; + tokennum = 1; + for( i=0;in[i]!='\0';i++ ){ + if( in[i] == ',' ) tokennum++; + } + getStringFromIndexWithDelim(in,",", rand()%tokennum+1,out,outbufsize ); + +} + +void cutDotsTail( char *s ) +{ + int l = strlen( s ); + int i; + for(i=l-1;i>=0;i--){ + if( s[i] == '.' ){ + s[i] = 0; + } else { + break; + } + } +} + +int NPC_Util_FrontItem( int meindex ) +{ + int front_x, front_y,objindex,itemindex; + OBJECT obj; + + CHAR_getCoordinationDir( CHAR_getInt(meindex,CHAR_DIR) + , CHAR_getInt(meindex,CHAR_X) + , CHAR_getInt(meindex,CHAR_Y) + ,1, &front_x, &front_y ); + for( obj=MAP_getTopObj(CHAR_getInt(meindex,CHAR_FLOOR), + front_x,front_y );obj; + obj=NEXT_OBJECT(obj) ){ + objindex = GET_OBJINDEX(obj); + if( OBJECT_getType(objindex) == OBJTYPE_ITEM ){ + itemindex = OBJECT_getIndex(objindex); + if(ITEM_CHECKINDEX(itemindex) ){ + return itemindex; + }else{ + return -1; + } + } + } + + return -1; + +} + +int NPC_Util_FrontChar( int meindex ) +{ + int front_x, front_y,objindex,enemyindex; + OBJECT obj; + CHAR_getCoordinationDir( CHAR_getInt(meindex,CHAR_DIR) + , CHAR_getInt(meindex,CHAR_X) + , CHAR_getInt(meindex,CHAR_Y) + ,1, &front_x, &front_y ); + for( obj=MAP_getTopObj(CHAR_getInt(meindex,CHAR_FLOOR), + front_x,front_y );obj; + obj=NEXT_OBJECT(obj) ){ + objindex = GET_OBJINDEX(obj); + if( OBJECT_getType(objindex) == OBJTYPE_CHARA ){ + enemyindex = OBJECT_getIndex(objindex); + if(CHAR_CHECKINDEX(enemyindex) ){ + return enemyindex; + } + } + } + return -1; +} +static int NPCUtil_enemytbl[NPC_ENEMY_ENEMYNUMBER+1]; +int *NPC_Util_getEnemy( int meindex, int charaindex) +{ + int i; + char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; + char buf[64]; + int ret; + int bigcnt; + int insert; + + NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); + for( i = 0; i < NPC_ENEMY_ENEMYNUMBER+1; i ++ ) { + NPCUtil_enemytbl[i] = -1; + } + + if( NPC_Util_GetStrFromStrWithDelim( argstr, "enemyno", buf, sizeof( buf)) + == NULL ) + { + return NULL; + } + bigcnt = 0; + insert = 0; + + for( i = 0; i < NPC_ENEMY_ENEMYNUMBER; i ++ ) { + int curEnemy; + int et_array; + char data[128]; + + ret = getStringFromIndexWithDelim( buf,",", i + 1,data, sizeof(data)); + if( ret == FALSE) { + break; + } + + curEnemy = ENEMY_getEnemyArrayFromId( atoi( data)); + if( !ENEMY_CHECKINDEX( curEnemy) ) continue; + et_array = ENEMYTEMP_getEnemyTempArray( curEnemy ); + if( ENEMYTEMP_getInt( et_array, E_T_SIZE ) == E_T_SIZE_BIG) { + if( bigcnt >= 5 ) { + continue; + } + if( insert > 4 ) { + int target_et_array; + int flg = FALSE; + int j; + for( j = 0; j < 5; j ++ ) { + /* л¼ƾ */ + if( !ENEMY_CHECKINDEX( NPCUtil_enemytbl[j])) break; + + target_et_array = ENEMYTEMP_getEnemyTempArray( + NPCUtil_enemytbl[j]); + /* ƾ */ + if( !ENEMYTEMP_CHECKINDEX( target_et_array)) break; + + if( ENEMYTEMP_getInt( target_et_array, E_T_SIZE) + == E_T_SIZE_NORMAL ) + { + flg = TRUE; + break; + } + } + if( !flg) continue; + + NPCUtil_enemytbl[insert] = NPCUtil_enemytbl[j]; + NPCUtil_enemytbl[j] = curEnemy; + } + else { + NPCUtil_enemytbl[insert] = curEnemy; + } + bigcnt ++; + } + else { + NPCUtil_enemytbl[insert] = curEnemy; + } + insert ++; + } + return NPCUtil_enemytbl; +} + + +void NPC_EventSetFlg(int talker,int shiftbit) + +{ + int point=0; + int array; + int shift; +#ifdef _TEACHER_SYSTEM + int iGetFame = 0; +#endif + + /*-- -1׷º绥ئì -*/ + if(shiftbit==-1) return; + + array = shiftbit / 32; + shift = shiftbit % 32; + + point = CHAR_getInt( talker, CHAR_ENDEVENT+array); + + // Arminius 8.24 prevent wash dp + if (!(point & (1 << shift))) { + // CoolFish: Family Adv 2001/8/4 + AddFMAdv(talker, shiftbit); +#ifdef _TEACHER_SYSTEM + if(shiftbit < arraysizeof(FMAdvTbl)) iGetFame = FMAdvTbl[shiftbit]; +#endif + } +#ifdef _TEACHER_SYSTEM + iGetFame /= 20; // ʦѧ 5% (1/20) + // õûд0 + if(iGetFame > 0){ + // ûеʦ + if(strlen(CHAR_getChar(talker,CHAR_TEACHER_ID)) > 0 && strlen(CHAR_getChar(talker,CHAR_TEACHER_NAME)) > 0){ + int iPlayernum = CHAR_getPlayerMaxNum(),i; + char szMsg[128]; + + // 鵼ʦڲ + for(i=0;i= arraysizeof(FMAdvTbl)) + return; + else + fmadv = FMAdvTbl[shiftbit]; + if (fmadv <= 0) return; +#ifdef _ALLBLUES_LUA_1_9 + FreeAddFMAdv(talker, shiftbit); +#endif + sprintf(buf, "%d", fmadv); + #ifdef _PERSONAL_FAME // Arminius 8.30: + CHAR_earnFame(talker, fmadv); + #endif + #ifdef _NEW_MANOR_LAW + sprintf(buf1, "%d", CHAR_getInt(talker,CHAR_FAME)); + #endif +#ifdef _FMVER21 + if (CHAR_getInt(talker, CHAR_FMLEADERFLAG) > 0 + && CHAR_getInt(talker, CHAR_FMLEADERFLAG) != FMMEMBER_APPLY) + { + // CoolFish: 2001/10/03 + int fd = getfdFromCharaIndex(talker); + saacproto_ACFixFMData_send(acfd, + CHAR_getChar(talker, CHAR_FMNAME), + CHAR_getInt(talker, CHAR_FMINDEX), + CHAR_getWorkInt(talker, CHAR_WORKFMINDEXI), + FM_FIX_FMADV, buf, +#ifndef _NEW_MANOR_LAW + "", +#else + buf1, +#endif + // CoolFish: 2001/10/03 + CHAR_getWorkInt(talker, CHAR_WORKFMCHARINDEX), + CONNECT_getFdid(fd)); + // CHAR_getWorkInt(talker, CHAR_WORKFMCHARINDEX), 0); +#ifdef _NEW_MANOR_LAW + { + int i; + for(i=0;i +#include + +#include "version.h" + +#include "common.h" +#include "npctemplate.h" +#include "npccreate.h" +#ifdef _MO_RELOAD_NPC +#include "char.h" +#include "battle.h" +#include "configfile.h" +#endif +BOOL NPC_readNPCSettingFiles( char* topdirectory ,int templatesize, int createsize) +{ + print("\n"); + if( NPC_readNPCTemplateFiles( topdirectory ,templatesize) == FALSE ) + return FALSE; + + if( NPC_readNPCCreateFiles( topdirectory ,createsize) == FALSE ) + return FALSE; + + return TRUE; +} +#ifdef _MO_RELOAD_NPC +BOOL NPC_reloadNPC(void) +{ + int i; + int charnum = getFdnum()+ getPetcharnum()+getOtherscharnum(); + for(i=0;iMakefile + $(CC) $(INCFLAGS) -M $(SRC) >> Makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +# DO NOT DELETE THIS LINE +npc_lua.o: npc_lua.c ../include/npc_lua.h ../include/npc_lua_interface.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h +npc_lua_ex.o: npc_lua_ex.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_item.o: npc_lua_item.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/item.h +npc_lua_nlg.o: npc_lua_nlg.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/configfile.h +npc_lua_nl.o: npc_lua_nl.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/autil.h \ + ../include/configfile.h ../include/enemy.h +npc_lua_obj.o: npc_lua_obj.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_char.o: npc_lua_char.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h ../include/pet_skill.h ../include/enemy.h \ + ../include/family.h +npc_lua_battle.o: npc_lua_battle.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_game.o: npc_lua_game.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/family.h +npc_lua_map.o: npc_lua_map.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/item.h +npc_lua_spell.o: npc_lua_spell.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/pet_skill.h \ + ../include/profession_skill.h ../include/magic_base.h +npc_lua_sql.o: npc_lua_sql.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/Makefile.bak b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/Makefile.bak new file mode 100644 index 0000000..e73b030 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/Makefile.bak @@ -0,0 +1,646 @@ +INCFLAGS=-I. -I../include -I../lua +FLTFLAGS="-s 1331200" +export FLTFLAGS + +#CFLAGS=-w -O3 -g $(INCFLAGS) +#CHOST="i686-pc-linux-gnu" +#CFLAGS=-march=pentium4 -w -O3 -pipe -mmmx -msse -msse2 $(INCFLAGS) +#CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer" +CFLAGS=-w -Wall -pipe $(INCFLAGS) + +PROG=libnpc_lua.a + +SRC=npc_lua.c npc_lua_ex.c npc_lua_item.c npc_lua_nlg.c npc_lua_nl.c npc_lua_obj.c npc_lua_char.c npc_lua_battle.c npc_lua_game.c npc_lua_map.c npc_lua_spell.c npc_lua_sql.c + +OBJ=$(SRC:.c=.o) + +ifeq (0,$(MAKELEVEL)) +CC=gcc +RM=rm -f +AR=ar cr +MV=mv +RANLIB=ranlib +SED=sed +SHELL=/bin/sh +endif + +all: $(PROG) +$(PROG): $(OBJ) + $(RM) $(PROG) + $(AR) $(PROG) $(OBJ) + $(RANLIB) $(PROG) + +depend: + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(CC) $(INCFLAGS) -M $(SRC) >> Makefile + +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +# DO NOT DELETE THIS LINE +npc_lua.o: npc_lua.c ../include/npc_lua.h ../include/npc_lua_interface.h \ + ../include/version.h ../include/correct_bug.h ../include/common.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h +npc_lua_ex.o: npc_lua_ex.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_item.o: npc_lua_item.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/item.h +npc_lua_nlg.o: npc_lua_nlg.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/configfile.h +npc_lua_nl.o: npc_lua_nl.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/autil.h \ + ../include/configfile.h ../include/enemy.h +npc_lua_obj.o: npc_lua_obj.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_char.o: npc_lua_char.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h ../include/pet_skill.h ../include/enemy.h \ + ../include/family.h +npc_lua_battle.o: npc_lua_battle.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h +npc_lua_game.o: npc_lua_game.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h ../include/saacproto_cli.h \ + ../include/saacproto_util.h /usr/include/strings.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h ../include/family.h +npc_lua_map.o: npc_lua_map.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/item.h +npc_lua_spell.o: npc_lua_spell.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/anim_tbl.h ../include/object.h ../include/net.h \ + ../include/npcutil.h ../include/npc_eventaction.h ../include/battle.h \ + ../include/trade.h ../include/readmap.h ../include/pet_skill.h \ + ../include/profession_skill.h ../include/magic_base.h +npc_lua_sql.o: npc_lua_sql.c ../include/npc_lua.h \ + ../include/npc_lua_interface.h ../include/version.h \ + ../include/correct_bug.h ../include/common.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + ../include/longzoro/version.h ../include/longzoro/longzoro.h \ + ../include/longzoro/debug.h ../include/../lua/lua.h \ + ../include/../lua/luaconf.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h ../include/../lua/lauxlib.h \ + ../include/../lua/lua.h /usr/include/string.h /usr/include/stdlib.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/assert.h ../include/util.h /usr/include/sys/time.h \ + ../include/char.h ../include/char_base.h ../include/skill.h \ + ../include/util.h ../include/title.h ../include/addressbook.h \ + ../include/net.h ../include/autil.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/include/bits/sockaddr.h /usr/include/asm/socket.h \ + /usr/include/asm/sockios.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/signal.h \ + /usr/include/bits/signum.h /usr/include/bits/siginfo.h \ + /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h \ + /usr/include/asm/sigcontext.h /usr/include/bits/sigstack.h \ + /usr/include/bits/sigthread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/link.h ../lua/lua.h \ + ../lua/lauxlib.h ../lua/lualib.h ../lua/lua.h ../include/char_data.h \ + ../include/item.h ../include/char.h ../include/char_base.h \ + ../include/char_data.h ../include/anim_tbl.h ../include/object.h \ + ../include/battle.h ../include/trade.h ../include/npcutil.h \ + ../include/item.h ../include/readmap.h ../include/longzoro/sasql.h \ + ../include/longzoro/version.h diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/ReadMe.txt b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/ReadMe.txt new file mode 100644 index 0000000..cccbd7d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/ReadMe.txt @@ -0,0 +1,25 @@ +======================================================================== + 静态库:npc_lua 项目概述 +======================================================================== + +应用程序向导已为您创建了此 npc_lua 库项目。 + +本文件概要介绍组成 npc_lua 应用程序的每个文件的内容。 + + +npc_lua.vcproj + 这是使用应用程序向导生成的 VC++ 项目的主项目文件, + 其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 + + +///////////////////////////////////////////////////////////////////////////// + +StdAfx.h, StdAfx.cpp + 这些文件用于生成名为 npc_lua.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 + +///////////////////////////////////////////////////////////////////////////// +其他注释: + +应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 + +///////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua.c new file mode 100644 index 0000000..309dc04 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua.c @@ -0,0 +1,2739 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "char_data.h" +#include "anim_tbl.h" +#include "object.h" +#include "battle.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" + +/* +#include + +int code_convert1(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t outlen) +{ + iconv_t cd; + char **pin = &inbuf; + char **pout = &outbuf; + + cd = iconv_open(to_charset,from_charset); + if (cd==0) return -1; + memset(outbuf,0,outlen); + if (iconv(cd,pin,&inlen,pout,&outlen)==-1) return -1; + iconv_close(cd); + return 0; +} +*/ + + +#ifdef _JZ_NEWSCRIPT_LUA + +typedef enum +{ + LUAITEM_PREOVERFUNC = ITEM_PREOVERFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_POSTOVERFUNC = ITEM_POSTOVERFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_WATCHFUNC = ITEM_WATCHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_USEFUNC = ITEM_USEFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_ATTACHFUNC = ITEM_ATTACHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_DETACHFUNC = ITEM_DETACHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_DROPFUNC = ITEM_DROPFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_PICKUPFUNC = ITEM_PICKUPFUNC - ITEM_FIRSTFUNCTION, +#ifdef _Item_ReLifeAct + LUAITEM_DIERELIFEFUNC = ITEM_DIERELIFEFUNC - ITEM_FIRSTFUNCTION, +#endif +}LUAITEM_FUNC; + +lua_State *M_Script_Lua = NULL; //ʵ +unsigned int M_Create_Num = 0; +char M_OutErrMsg[1024]; + +extern lua_const M_Lua_RegConstList[]; + +extern int NPC_Lua_NL_SetCharSignDay(lua_State *_NLL); +extern int NPC_Lua_NL_GetCharSignDay(lua_State *_NLL); +extern int NPC_Lua_NL_Print(lua_State *L); +static luaL_Reg M_RegList[] = { + {NULL, NULL}, +}; + +static luaL_Reg Bit_RegList[] = { + {"band", NPC_Lua_Bit_band}, + {"bor", NPC_Lua_Bit_bor}, + {"bxor", NPC_Lua_Bit_bxor}, + {"lshift", NPC_Lua_Bit_lshift}, + {"rshift", NPC_Lua_Bit_rshift}, + {NULL, NULL}, +}; + +static luaL_Reg Map_RegList[] = { + {"CheckCoordinates",NPC_Lua_Map_CheckCoordinates}, + {"GetExitFloorXY",NPC_Lua_Map_GetExitFloorXY}, + {"GetfloorX",NPC_Lua_Map_GetfloorX}, + {"GetfloorY",NPC_Lua_Map_GetfloorY}, + {"GetTileAndObjId",NPC_Lua_Map_GetTileAndObjId}, + {"SetTileAndObjId",NPC_Lua_Map_SetTileAndObjId}, + {"GetWalkAbleFromPoint",NPC_Lua_Map_GetWalkAbleFromPoint}, + {"GetImageData",NPC_Lua_Map_GetImageData}, + {"SetImageData",NPC_Lua_Map_SetImageData}, + {"GetTopObj",NPC_Lua_Map_GetTopObj}, + {"GetNextObj",NPC_Lua_Map_GetNextObj}, + {"CheckImageIndex",NPC_Lua_Map_CheckImageIndex}, + {"CheckIndex",NPC_Lua_Map_CheckIndex}, + {"MakeNewMap",NPC_Lua_Map_MakeNewMap}, + {"DelNewMap",NPC_Lua_Map_DelNewMap}, + {"SetExWarp",NPC_Lua_Map_SetExWarp}, + {"SetMapPoint",NPC_Lua_Map_SetMapPoint}, + {"DelMapPoint",NPC_Lua_Map_DelMapPoint}, + {"getFloorName",NPC_Lua_Map_getFloorName}, +#ifdef _UPMAP_ + {"UpMap",NPC_Lua_Map_Upmap}, +#endif + {"ⷶΧ",NPC_Lua_Map_CheckCoordinates}, + {"ͼǷdz",NPC_Lua_Map_GetExitFloorXY}, + {"ȡX",NPC_Lua_Map_GetfloorX}, + {"ȡY",NPC_Lua_Map_GetfloorY}, + {"ȡx",NPC_Lua_Map_GetfloorX}, + {"ȡy",NPC_Lua_Map_GetfloorY}, + + {"ȡذװ",NPC_Lua_Map_GetTileAndObjId}, + {"õذװ",NPC_Lua_Map_SetTileAndObjId}, + {"Ƿ߶",NPC_Lua_Map_GetWalkAbleFromPoint}, + {"ȡ",NPC_Lua_Map_GetImageData}, + {"",NPC_Lua_Map_SetImageData}, + {"ȡ",NPC_Lua_Map_GetTopObj}, + {"ȡһ",NPC_Lua_Map_GetNextObj}, + {"ͼƬ",NPC_Lua_Map_CheckImageIndex}, + {"ͼ",NPC_Lua_Map_CheckIndex}, + {"ͼ",NPC_Lua_Map_MakeNewMap}, + {"ɾͼ",NPC_Lua_Map_DelNewMap}, + {"˳͵",NPC_Lua_Map_SetExWarp}, + {"ô͵",NPC_Lua_Map_SetMapPoint}, + {"ɾ͵",NPC_Lua_Map_DelMapPoint}, + {"ȡԭ",NPC_Lua_Map_getFloorName}, +#ifdef _UPMAP_ + {"",NPC_Lua_Map_Upmap}, +#endif + + + {NULL, NULL}, +}; + +static luaL_Reg Spell_RegList[] = { +#ifdef _CHAR_PROFESSION + {"PETSKILL_GetData",NPC_Lua_Spell_PETSKILL_GetData}, + {"PROFESSION_GetData",NPC_Lua_Spell_PROFESSION_GetData}, + {"MAGIC_GetData",NPC_Lua_Spell_MAGIC_GetData}, + {"PETSKILL_SetData",NPC_Lua_Spell_PETSKILL_SetData},//δ + {"PROFESSION_SetData",NPC_Lua_Spell_PROFESSION_SetData},//δ + {"MAGIC_SetData",NPC_Lua_Spell_MAGIC_SetData},//δ + {"ȡ\",NPC_Lua_Spell_PETSKILL_GetData}, + {"ȡְҵ",NPC_Lua_Spell_PROFESSION_GetData}, + {"ȡ鼼",NPC_Lua_Spell_MAGIC_GetData}, + {"ó\",NPC_Lua_Spell_PETSKILL_SetData},//δ + {"ְҵ",NPC_Lua_Spell_PROFESSION_SetData},//δ + {"þ鼼",NPC_Lua_Spell_MAGIC_SetData},//δ +#endif + {"þ鼼",NPC_Lua_Spell_MAGIC_SetData},//δ + //{"ó\",NPC_Lua_Spell_PETSKILL_SetData},//δ + {"ȡ\",NPC_Lua_Spell_PETSKILL_GetData}, + {"ȡ鼼",NPC_Lua_Spell_MAGIC_GetData}, + {NULL, NULL}, +}; + +static luaL_Reg NL_RegList[] = { +//NL + {"SetCharSignDay", NPC_Lua_NL_SetCharSignDay}, + {"ǩ", NPC_Lua_NL_SetCharSignDay}, + {"GetCharSignDay", NPC_Lua_NL_GetCharSignDay}, + {"ȡǩ", NPC_Lua_NL_GetCharSignDay}, + {"writeshopdata", NPC_Lua_NL_WriteShopData}, + {"д̳", NPC_Lua_NL_WriteShopData}, + {"print", NPC_Lua_NL_Print}, + {"ӡ", NPC_Lua_NL_Print}, + {"CreateSpecialNpc", NPC_Lua_NL_CreateSpecialNpc}, + {"DelNpc", NPC_Lua_NL_DelNpc}, + {"GetStringFromIndexWithDelim", NPC_Lua_NL_GetStringFromIndexWithDelim},//ַ + {"ANSI_PlayerLoop", NPC_Lua_NL_ANSI_PlayerLoop},//߳ + {"PetLoopGetNext", NPC_Lua_NL_PetLoopGetNext},//߳ + {"ItemLoopGetNext", NPC_Lua_NL_ItemLoopGetNext},//е + {"PlayerLoopGetNext", NPC_Lua_NL_PlayerLoopGetNext},// + {"GetConfigLineType", NPC_Lua_NL_GetConfigLineType},//CFֶ + {"GetConfigLineVal", NPC_Lua_NL_GetConfigLineVal},//CFֵֶ + {"CheckNpcEventFree", NPC_Lua_CheckNpcEventFree},//ʹNPCű + {"DoNpcEventAction", NPC_Lua_DoNpcEventAction},//ʹNPCű + {"SetTimer", NPC_Lua_NL_SetTimer},//趨һʱضʱID + {"DelTimer", NPC_Lua_NL_DelTimer},//ɾһʱID + {"RunSaFuncII", NPC_Lua_NL_RunSaFuncII},//һڶõ2INTĺ + {"RunSaFuncIII", NPC_Lua_NL_RunSaFuncIII},//һڶõ3INTĺ + {"ANSI_PlayerLoop", NPC_Lua_NL_ANSI_PlayerLoop},//һ + {"ANSI_PetLoop", NPC_Lua_NL_ANSI_PetLoop},//һ + {"ANSI_ItemLoop", NPC_Lua_NL_ANSI_ItemLoop},//һ + {"ClsMk", NPC_Lua_NL_ClsMk}, + {"AddCheckNum", NPC_Lua_NL_AddCheckNum}, + {"Mkstring", NPC_Lua_NL_Mkstring}, + {"Mkint", NPC_Lua_NL_Mkint}, + {"SendMesg", NPC_Lua_NL_SendMesg}, + {"getGameservername", NPC_Lua_NL_getGameservername}, + {"ȡ", NPC_Lua_NL_getGameservername}, + {"ȡϢ", NPC_Lua_NL_GetErrorStr}, + {"NPC", NPC_Lua_NL_CreateNpc}, + {"npc", NPC_Lua_NL_CreateNpc}, + {"رNPC", NPC_Lua_NL_CreateSpecialNpc}, + {"رnpc", NPC_Lua_NL_CreateSpecialNpc}, + {"ɾNPC", NPC_Lua_NL_DelNpc}, + {"ɾnpc", NPC_Lua_NL_DelNpc}, + {"ַָ", NPC_Lua_NL_GetStringFromIndexWithDelim},//ַ + {"עص", NPC_Lua_NL_PetLoopGetNext},//߳ + {"ע߻ص", NPC_Lua_NL_ItemLoopGetNext},//е + {"עص", NPC_Lua_NL_PlayerLoopGetNext},// + {"ȡCF", NPC_Lua_NL_GetConfigLineType},//CFֶ + {"ȡcf", NPC_Lua_NL_GetConfigLineType},//CFֶ + {"ȡCFֵ", NPC_Lua_NL_GetConfigLineVal},//CFֵֶ + {"ȡcfֵ", NPC_Lua_NL_GetConfigLineVal},//CFֵֶ + {"npc", NPC_Lua_CheckNpcEventFree},//ʹNPCű + {"NPC", NPC_Lua_CheckNpcEventFree},//ʹNPCű + {"ʹNPCű", NPC_Lua_DoNpcEventAction},//ʹNPCű + {"ʱ", NPC_Lua_NL_SetTimer},//趨һʱضʱID + {"ɾʱ", NPC_Lua_NL_DelTimer},//ɾһʱID + {"úII", NPC_Lua_NL_RunSaFuncII},//һڶõ2INTĺ + {"úIII", NPC_Lua_NL_RunSaFuncIII},//һڶõ3INTĺ + {"", NPC_Lua_NL_ANSI_PlayerLoop},//߳ + {"", NPC_Lua_NL_ANSI_PetLoop},//һ + {"", NPC_Lua_NL_ANSI_ItemLoop},//һ + {"շ", NPC_Lua_NL_ClsMk}, + {"", NPC_Lua_NL_AddCheckNum}, + {"ַ", NPC_Lua_NL_Mkstring}, + {"", NPC_Lua_NL_Mkint}, + {"ͷ", NPC_Lua_NL_SendMesg}, + {NULL, NULL}, +}; + +static luaL_Reg Char_RegList[] = { +//ȡݵĽӿ + {"getVipPoint", NPC_Lua_Char_getVipPoint}, + //{"getjfPoint", NPC_Lua_Char_getjfPoint}, + //{"getxjPoint", NPC_Lua_Char_getxjPoint}, + {"setVipPoint", NPC_Lua_Char_setVipPoint}, + //{"setjfPoint", NPC_Lua_Char_setjfPoint}, + //{"setxjPoint", NPC_Lua_Char_setxjPoint}, + {"IsEventEnd", NPC_Lua_Char_IsEventEnd}, + {"IsEventNow", NPC_Lua_Char_IsEventNow}, +// + {"FindItemId", NPC_Lua_Char_FindItemId}, + {"FindPetEnemyId", NPC_Lua_Char_FindPetEnemyId}, + {"GetAllocPoint",NPC_Lua_Char_GetAllocPoint}, + {"GetDataFromEnemyBase",NPC_Lua_Char_GetDataFromEnemyBase}, + {"GetPlayIndex", NPC_Lua_Char_GetPlayerIndex}, + {"FindItemIndex", NPC_Lua_Char_FindItemIndex}, + {"FindPetIndex", NPC_Lua_Char_FindPetIndex}, + {"CheckIndex",NPC_Lua_CHAR_CHECKINDEX}, + {"GetPetSkill", NPC_Lua_Char_GetPetSkill},// + {"GetPetSkillNo", NPC_Lua_Char_GetPetSkillNo},// + {"GetEmptyItemBoxNum", NPC_Lua_Char_GetEmptyItemBoxNum},// + {"GetEmptyPetBoxNum", NPC_Lua_Char_GetEmptyPetBoxNum},// + {"GetPlayerPetNum", NPC_Lua_Char_GetPlayerPetNum},// + {"GetPlayerItemNum", NPC_Lua_Char_GetPlayerItemNum},// + {"CharRidNo", NPC_Lua_Char_RidNo}, // + {"getPlayerMaxNum", NPC_ABLua_char_getPlayerMaxNum},// + {"getBattleexp", NPC_ABLua_char_getBattleexp},// + {"SetPetSkill", NPC_Lua_Char_SetPetSkill},// + {"SetPetSkillNo", NPC_Lua_Char_SetPetSkillNo},// + {"ComplianceParameter", NPC_Lua_Char_ComplianceParameter}, + {"HcItemId", NPC_Lua_Char_HcItemId}, + {"DelHcItem", NPC_Lua_Char_DelHcItem}, + {"GETFM", NPC_Lua_Char_GETFM}, + {"FindPetEnemyBaseId", NPC_Lua_Char_FindPetEnemyBaseId}, + {"ITEMID_NAME", NPC_Lua_Char_ITEMID_NAME}, + {"ITEMID_NAME2", NPC_Lua_Char_ITEMID_NAME2}, + {"ITEMID_LEVEL", NPC_Lua_Char_ITEMID_LEVEL}, + {"ITEMID_GOLD", NPC_Lua_Char_ITEMID_GOLD}, + {"ITEMID_RANO", NPC_Lua_Char_ITEMID_RANO}, +// {"CharRidNo", NPC_Lua_Char_CharRidNo}, //δͬʱر + {"GetPetOwner", NPC_Lua_Char_GetPetOwner}, + {"GetEnemyBaseIdFromEnemyId", NPC_Lua_Char_GetEnemyBaseIdFromEnemyId}, + {"GetEnemyIdFromEnemyBaseId", NPC_Lua_Char_GetEnemyIdFromEnemyBaseId}, + {"GetIp", NPC_Lua_Char_GetIp}, + {"SetAllocPoint", NPC_Lua_Char_SetAllocPoint}, + {"GetMaxPetIndex", NPC_Lua_Char_GetMaxPetIndex}, + {"GetMaxPlayerIndex", NPC_Lua_Char_GetMaxPlayerIndex}, + {"SavePetToString", NPC_Lua_Char_SavePetToString}, + {"LoadPetFromString", NPC_Lua_Char_LoadPetFromString}, + {"GetPlayerFromAccAndName", NPC_Lua_Char_GetPlayerFromAccAndName}, + {"CheckPet", NPC_Lua_Char_CheckPet}, + {"CheckPlayer", NPC_Lua_Char_CheckPlayer}, + {"JoinParty", NPC_Lua_Char_JoinParty}, + {"getFamilyPlayIndex", NPC_Lua_Char_getFamilyPlayIndex}, + + {"GetData", NPC_Lua_Char_GetData}, + {"GetItemId", NPC_Lua_Char_GetItemId}, + {"GetPetEnemyId", NPC_Lua_Char_GetPetEnemyId}, + {"GetItemIndex", NPC_Lua_Char_GetItemIndex}, + {"GetPetIndex", NPC_Lua_Char_GetPetIndex}, + {"GetTeamIndex", NPC_Lua_Char_GetTeamIndex}, + {"GetPlayerIndexByCdkey", NPC_Lua_Char_GetPlayerIndexByCdkey}, + +//ݵĽӿ + {"ClrEvtEnd", NPC_Lua_Char_ClrEvtEnd}, + {"ClrEvtNow", NPC_Lua_Char_ClrEvtNow}, + {"ClrClrEvt", NPC_Lua_Char_ClrEvt}, + {"SetEvtEnd", NPC_Lua_Char_SetEvtEnd}, + {"SetEvtNow", NPC_Lua_Char_SetEvtNow}, + {"SetData", NPC_Lua_Char_SetData}, + +//¼õĽӿ + {"SetWalkPreEvent", NPC_Lua_Char_SetWalkPreEvent}, + {"SetWalkPostEvent", NPC_Lua_Char_SetWalkPostEvent}, + {"SetPreOverEvent", NPC_Lua_Char_SetPreOverEvent}, + {"SetPostOverEvent", NPC_Lua_Char_SetPostOverEvent}, + {"SetWatchEvent", NPC_Lua_Char_SetWatchEvent}, + {"SetLoopEvent", NPC_Lua_Char_SetLoopEvent}, + {"SetTalkedEvent", NPC_Lua_Char_SetTalkedEvent}, + {"SetOFFEvent", NPC_Lua_Char_SetOFFEvent}, + {"SetLookedEvent", NPC_Lua_Char_SetLookedEvent}, + {"SetItemPutEvent", NPC_Lua_Char_SetItemPutEvent}, + {"SetWindowTalkedEvent", NPC_Lua_Char_SetWindowTalkedEvent}, +#ifdef _USER_CHARLOOPS + {"SetCharLoopsEvent", NPC_Lua_Char_SetCharLoopsEvent}, + {"SetBattleProPertyEvent", NPC_Lua_Char_SetBattleProPertyEvent}, +#endif +//ҽӿ + {"VipPoint", NPC_Lua_Char_VipPoint}, + {"HealAll", NPC_Lua_Char_HealAll}, + {"GetPetSkillId", NPC_Lua_Char_GetPetSkillId}, + {"GetPetSkillName", NPC_Lua_Char_GetPetSkillName}, + {"GetPetSkillMsg", NPC_Lua_Char_GetPetSkillMsg}, + {"SetPetSkill", NPC_Lua_Char_SetPetSkill}, +// {"RandMsg", NPC_Lua_Char_RandMsg}, + {"GetBeatitudeNum", NPC_Lua_Char_GetBeatitudeNum}, + {"RandRandWalk", RandRandWalk}, + {"·", RandRandWalk}, + {"logout", NPC_Lua_Char_logout}, + {"dz", NPC_Lua_Char_logout}, + {"copyChar", copyChar}, + {"", copyChar}, +//ȡݵĽӿ + {"Ƿ", NPC_Lua_Char_IsEventEnd}, + {"Ƿ", NPC_Lua_Char_IsEventNow}, + {"ȡ", NPC_Lua_Char_GetVipPoint}, + {"ý", NPC_Lua_Char_SetVipPoint}, + {"ȡֵ", NPC_Lua_Char_GetAmPoint}, + {"ûֵ", NPC_Lua_Char_SetAmPoint}, + {"ȡʱҵ", NPC_Lua_Char_GetRmbPoint}, + {"òʱҵ", NPC_Lua_Char_SetRmbPoint}, + {"ѰҵID", NPC_Lua_Char_FindItemId}, + {"Ѱҵid", NPC_Lua_Char_FindItemId}, + {"ѰҳID", NPC_Lua_Char_FindPetEnemyId}, + {"Ѱҳid", NPC_Lua_Char_FindPetEnemyId}, + + {"ȡ", NPC_Lua_Char_GetData}, + {"ȡID", NPC_Lua_Char_GetItemId}, + {"ȡid", NPC_Lua_Char_GetItemId}, + {"ȡID", NPC_Lua_Char_GetPetEnemyId}, + {"ȡid", NPC_Lua_Char_GetPetEnemyId}, + {"ȡ", NPC_Lua_Char_GetItemIndex}, + {"ȡ", NPC_Lua_Char_GetPetIndex}, + {"ȡŶ", NPC_Lua_Char_GetTeamIndex}, + +//ݵĽӿ + {"ȡ", NPC_Lua_Char_ClrEvtEnd}, + {"ȡ", NPC_Lua_Char_ClrEvtNow}, + {"", NPC_Lua_Char_SetEvtEnd}, + {"", NPC_Lua_Char_SetEvtNow}, + {"", NPC_Lua_Char_SetData}, + +//¼õĽӿ + {"עƶʱص", NPC_Lua_Char_SetWalkPreEvent}, + {"עƶص", NPC_Lua_Char_SetWalkPostEvent}, + {"ע̤ʱص", NPC_Lua_Char_SetPreOverEvent}, + {"ע̤ص", NPC_Lua_Char_SetPostOverEvent}, + {"עᶯʱص", NPC_Lua_Char_SetWatchEvent}, + {"עѭص", NPC_Lua_Char_SetLoopEvent}, + {"עԻص", NPC_Lua_Char_SetTalkedEvent}, + {"SetOFFEvent", NPC_Lua_Char_SetOFFEvent}, + {"ע᷽ص", NPC_Lua_Char_SetLookedEvent}, + {"ע߶̤ص", NPC_Lua_Char_SetItemPutEvent}, + {"עԻص", NPC_Lua_Char_SetWindowTalkedEvent}, +#ifdef _USER_CHARLOOPS + {"עԭػص", NPC_Lua_Char_SetCharLoopsEvent}, + {"עսص", NPC_Lua_Char_SetBattleProPertyEvent}, +#endif +//ҽӿ + {"ȡ", NPC_Lua_Char_VipPoint}, + {"ȫָ", NPC_Lua_Char_HealAll}, + {"ȡ\ID", NPC_Lua_Char_GetPetSkillId}, + {"ȡ\id", NPC_Lua_Char_GetPetSkillId}, + {"ȡ\", NPC_Lua_Char_GetPetSkillName}, + {"ȡ\˵", NPC_Lua_Char_GetPetSkillMsg}, + {"ó\ID", NPC_Lua_Char_SetPetSkill}, + {"ó\id", NPC_Lua_Char_SetPetSkill}, + {"",NPC_Lua_CHAR_CHECKINDEX}, + {"Ѱҵ", NPC_Lua_Char_FindItemIndex}, + {"ȡ", NPC_Lua_Char_HcItemId}, + {"ɾ", NPC_Lua_Char_DelHcItem}, + {"ȡϢ", NPC_Lua_Char_GETFM}, + {"ѰҳԭID", NPC_Lua_Char_FindPetEnemyBaseId}, + {"Ѱҳԭid", NPC_Lua_Char_FindPetEnemyBaseId}, + {"", createPet}, + {"createPet", createPet}, + {"setCharPet", setCharPet}, + {"getCharPet", getCharPet}, + {"ToAroundChar", ToAroundChar}, + {"ȡԭ", NPC_Lua_Char_ITEMID_NAME}, + {"ȡ˵", NPC_Lua_Char_ITEMID_NAME2}, + {"ȡߵȼ", NPC_Lua_Char_ITEMID_LEVEL}, + {"ȡ߼۸", NPC_Lua_Char_ITEMID_GOLD}, + {"ȡͼƬ", NPC_Lua_Char_ITEMID_RANO}, + {"Ѱ", NPC_Lua_Char_FindPetIndex}, + {"֤", NPC_Lua_Char_CharRidNo}, + {"ȡ", NPC_Lua_Char_GetPetOwner}, + {"ȡԭ",NPC_Lua_Char_GetDataFromEnemyBase}, + {"ȡIDԵ", NPC_Lua_Char_GetEnemyBaseIdFromEnemyId}, + {"ȡIDԭ", NPC_Lua_Char_GetEnemyIdFromEnemyBaseId}, + {"ȡidԵ", NPC_Lua_Char_GetEnemyBaseIdFromEnemyId}, + {"ȡidԭ", NPC_Lua_Char_GetEnemyIdFromEnemyBaseId}, + {"ȡIP", NPC_Lua_Char_GetIp}, + {"ȡip", NPC_Lua_Char_GetIp}, + {"ȡΧ",NPC_Lua_Char_GetAllocPoint}, + {"óΧ", NPC_Lua_Char_SetAllocPoint}, + {"ȡ", NPC_Lua_Char_GetMaxPetIndex}, + {"ȡ", NPC_Lua_Char_GetMaxPlayerIndex}, + {"", NPC_Lua_Char_SavePetToString}, + {"س", NPC_Lua_Char_LoadPetFromString}, + {"", NPC_Lua_Char_ComplianceParameter}, + {"ȡʺ", NPC_Lua_Char_GetPlayerFromAccAndName}, + {"ȡ", NPC_Lua_Char_GetPlayerItemNum}, + {"ȡ", NPC_Lua_Char_GetPlayerPetNum}, + {"ȡ߿", NPC_Lua_Char_GetEmptyItemBoxNum}, + {"ȡ", NPC_Lua_Char_GetEmptyPetBoxNum}, + {"", NPC_Lua_Char_CheckPet}, + {"", NPC_Lua_Char_CheckPlayer}, + {"", NPC_Lua_Char_CheckItemIndex}, + {"", NPC_Lua_Char_JoinParty}, + + {"ȡ", NPC_Lua_Char_getFamilyPlayIndex}, + {"ȡ", NPC_ABLua_char_getPlayerMaxNum}, +// {"ȡ", getOnlinePlayer_}, + {"ȡս鱶", NPC_ABLua_char_getBattleexp}, + {"ȡ\ID", NPC_Lua_Char_GetPetSkillNo}, + {"ó\ID", NPC_Lua_Char_SetPetSkillNo}, + {"ȡ\id", NPC_Lua_Char_GetPetSkillNo}, + {"ó\id", NPC_Lua_Char_SetPetSkillNo}, + {"getFd", NPC_Lua_Char_GetfdFromCharaIndex}, + {"ȡID", NPC_Lua_Char_GetfdFromCharaIndex}, + + + {NULL, NULL}, +}; + +static luaL_Reg GAME_RegList[] = { + {"FMPOINT_GetData",NPC_Lua_Game_FMPOINT_GetData}, + {"FMPOINT_ACSetFMPoint",NPC_Lua_Game_FMPOINT_ACSetFMPoint}, + {"FMPOINT_ACFixFMPoint",NPC_Lua_Game_FMPOINT_ACFixFMPoint}, +// {"FMPOINT_ACCleanFMPoint",NPC_Lua_Game_FMPOINT_ACCleanFMPoint}, + {"ȡ",NPC_Lua_Game_FMPOINT_GetData}, + {"ݵ",NPC_Lua_Game_FMPOINT_ACSetFMPoint}, + {"趨ݵ",NPC_Lua_Game_FMPOINT_ACFixFMPoint}, +// {"ݵ",NPC_Lua_Game_FMPOINT_ACCleanFMPoint}, + + {NULL, NULL}, +}; + +static luaL_Reg Item_RegList[] = { +//ȡݵĽӿ + {"GetData", NPC_Lua_Item_GetData}, + +//ݵĽӿ + {"SetData", NPC_Lua_Item_SetData}, + {"GetDataFromItemSet", NPC_Lua_Item_GetDataFromItemSet}, +//¼õĽӿ + {"SetPreOverEvent", NPC_Lua_Item_SetPreOverEvent}, + {"SetPostOverEvent", NPC_Lua_Item_SetPostOverEvent}, + {"SetWatchEvent", NPC_Lua_Item_SetWatchEvent}, + {"SetUseEvent", NPC_Lua_Item_SetUseEvent}, + {"SetAttachEvent", NPC_Lua_Item_SetAttachEvent}, + {"SetDetachEvent", NPC_Lua_Item_SetDetachEvent}, + {"SetDropEvent", NPC_Lua_Item_SetDropEvent}, + {"SetPickUPEvent", NPC_Lua_Item_SetPickUPEvent}, +#ifdef _Item_ReLifeAct + {"SetDieReLifeEvent", NPC_Lua_Item_SetDieReLifeEvent}, +#endif + //ȡݵĽӿ + {"ȡ", NPC_Lua_Item_GetData}, + + //ݵĽӿ + {"", NPC_Lua_Item_SetData}, + {"ȡģ", NPC_Lua_Item_GetDataFromItemSet}, + {"ȡʱ", NPC_Lua_Item_GetValidity}, + {"ȡ", NPC_Lua_Item_GetItemOwner}, + {"", NPC_Lua_Item_GetMaxItemIndex}, + {"", NPC_Lua_Item_SaveItemToString}, + {"ùʱ", NPC_Lua_Item_SetValidity}, + {"ص", NPC_Lua_Item_LoadItemFromString}, + + {NULL, NULL}, +}; + +static luaL_Reg Obj_RegList[] = { +//ȡݵĽӿ + {"GetType", NPC_Lua_Obj_GetType}, + {"GetCharType", NPC_Lua_Obj_GetCharType}, + {"GetCharIndex", NPC_Lua_Obj_GetCharIndex}, + {"GetX", NPC_Lua_Obj_GetX}, + {"GetY", NPC_Lua_Obj_GetY}, + {"GetFloor", NPC_Lua_Obj_GetFloor}, + +//¼õĽӿ + {"SetType", NPC_Lua_Obj_SetType}, + {"SetCharType", NPC_Lua_Obj_SetCharType}, + {"SetX", NPC_Lua_Obj_SetX}, + {"SetY", NPC_Lua_Obj_SetY}, + {"SetFloor", NPC_Lua_Obj_SetFloor}, + {"ȡ", NPC_Lua_Obj_GetType}, + {"ȡ", NPC_Lua_Obj_GetCharType}, + {"ȡ", NPC_Lua_Obj_GetCharIndex}, + {"ȡX", NPC_Lua_Obj_GetX}, + {"ȡY", NPC_Lua_Obj_GetY}, + {"ȡx", NPC_Lua_Obj_GetX}, + {"ȡy", NPC_Lua_Obj_GetY}, + {"ȡͼ", NPC_Lua_Obj_GetFloor}, + {"", NPC_Lua_Obj_SetType}, + {"", NPC_Lua_Obj_SetCharType}, + {"X", NPC_Lua_Obj_SetX}, + {"Y", NPC_Lua_Obj_SetY}, + {"x", NPC_Lua_Obj_SetX}, + {"y", NPC_Lua_Obj_SetY}, + {"õͼ", NPC_Lua_Obj_SetFloor}, + + {NULL, NULL}, +}; + +static luaL_Reg Battle_RegList[] = { +//ȡݵĽӿ + {"GetPlayIndex", NPC_Lua_Battle_GetPlayIndex}, + {"GetData", NPC_Lua_Battle_GetData}, + {"IndexToNo", NPC_Lua_Battle_IndexToNo}, + {"NoToIndex", NPC_Lua_Battle_NoToIndex}, + {"CheckIndex", NPC_Lua_Battle_CheckIndex}, +//ݵĽӿ + {"SetNORisk", NPC_Lua_Battle_SetNORisk}, + {"SetMod", NPC_Lua_Battle_SetMod}, + {"SetType", NPC_Lua_Battle_SetType}, + {"SetData", NPC_Lua_Battle_SetData}, + {"Exit", NPC_Lua_Battle_Exit}, + +//¼õĽӿ + {"SetWinEvent", NPC_Lua_Battle_SetWinEvent}, + {"SetEndEvent", NPC_Lua_Battle_SetEndEvent}, + {"ͨ", Attack}, + {"Ѫ", Recovery}, + {"ȡ", NPC_Lua_Battle_GetPlayIndex}, + {"÷", NPC_Lua_Battle_SetNORisk}, + {"ս־", NPC_Lua_Battle_SetMod}, + {"", NPC_Lua_Battle_SetType}, + {"עսʱص", NPC_Lua_Battle_SetWinEvent}, + {"ȡ", NPC_Lua_Battle_GetData}, + {"", NPC_Lua_Battle_SetData}, + {"ȡλ", NPC_Lua_Battle_IndexToNo}, + {"ȡ", NPC_Lua_Battle_NoToIndex}, + {"", NPC_Lua_Battle_CheckIndex}, + {"", NPC_Lua_Battle_Exit}, + {"עսص", NPC_Lua_Battle_SetEndEvent}, + + {NULL, NULL}, +}; + + +static luaL_Reg SQL_RegList[] = { + {"Push", NPC_Lua_SQL_Push}, + {"PushPop", NPC_Lua_SQL_PushPop}, + {"PushPopAdv", NPC_Lua_SQL_PushPopAdv}, + {"QueryFirstRow", NPC_Lua_SQL_QueryFirstRow}, + {"FetchRow", NPC_Lua_SQL_FetchRow}, + {"FreeResult", NPC_Lua_SQL_FreeResult}, + {"ִ", NPC_Lua_SQL_Push}, + {"עִлص", NPC_Lua_SQL_PushPop}, + {"עִлصI", NPC_Lua_SQL_PushPopAdv}, + {"עִлصII", NPC_Lua_SQL_QueryFirstRow}, + {"ȡһ", NPC_Lua_SQL_FetchRow}, + {"ͷŽ", NPC_Lua_SQL_FreeResult}, + + {NULL, NULL}, +}; + + +static luaL_Reg NLG_RegList[] = { +//ܽӿ + {"UpItem", NPC_Lua_NLG_UpItem}, + {"GiveItemOne", NPC_Lua_NLG_GiveItemOne}, + {"HealAll", NPC_Lua_NLG_HealerAllHeal}, + {"DelItemByIndex", NPC_Lua_NLG_DelItemByIndex}, + {"FindPet", NPC_Lua_NLG_FindPet}, + {"GetMap", NPC_Lua_NLG_GetMap}, + {"PetUp", NPC_Lua_NLG_PetUp}, +#ifdef _CHAR_PROFESSION + {"AddSk", NPC_Lua_NLG_AddSk}, + {"SetZy", NPC_Lua_NLG_SetZy}, +#endif + {"GetPlayerMaxNum", NPC_Lua_Char_GetPlayerMaxNum}, + {"GetXY", NPC_Lua_NLG_GetXY}, + {"WalkJc", NPC_Lua_NLG_WalkJc}, + {"KickPlayer", NPC_Lua_NLG_KickPlayer}, + {"HealOne", NPC_Lua_NLG_HealOne}, + {"HealAll", NPC_Lua_NLG_HealAll}, + {"LevelUpTo", NPC_Lua_NLG_LevelUpTo}, + {"AddExp", NPC_Lua_NLG_AddExp}, + {"UpPet", NPC_Lua_NLG_UpPet}, + {"DelPetByPos", NPC_Lua_NLG_DelPetByPos}, + {"DelPetByIndex", NPC_Lua_NLG_DelPetByIndex}, + {"GivePetByIndex", NPC_Lua_NLG_GivePetByIndex}, + {"GiveItemByIndex", NPC_Lua_NLG_GiveItemByIndex}, + {"WarpToSpecificPoint", NPC_Lua_NLG_WarpToSpecificPoint}, + {"UpSkillupPoint", NPC_Lua_NLG_UpSkillupPoint}, + {"StayEncount", NPC_Lua_NLG_StayEncount}, + + {"CheckInFront", NPC_Lua_NLG_CheckInFront}, + {"CheckObj", NPC_Lua_NLG_CheckObj}, + {"CharLook", NPC_Lua_NLG_CharLook}, + {"CreateBattle", NPC_Lua_NLG_CreateBattle}, + {"CreateBattlePvP", NPC_Lua_NLG_CreateBattlePvP}, + {"SearchWatchBattleRandIndex", NPC_Lua_NLG_SearchWatchBattleRandIndex}, + {"InputCard", NPC_Lua_NLG_InputCard}, + {"DelPet", NPC_Lua_NLG_DelPet}, + {"DelHaveIndexPet", NPC_Lua_NLG_DelHaveIndexPet}, + {"DelItem", NPC_Lua_NLG_DelItem}, + {"DelItemByPos", NPC_Lua_NLG_DelItemByPos}, + {"DischargeParty", NPC_Lua_NLG_DischargeParty}, + + {"GivePet", NPC_Lua_NLG_GivePet}, + {"GiveOnePet", NPC_Lua_NLG_GiveOnePet}, + {"GiveItem", NPC_Lua_NLG_GiveItem}, + {"GiveOneItem", NPC_Lua_NLG_GiveOneItem}, + {"GiveRandItem", NPC_Lua_NLG_GiveRandItem}, + {"GetOnLinePlayer", NPC_Lua_Char_GetOnLinePlayer}, + + {"ShowWindowTalked", NPC_Lua_NLG_ShowWindowTalked}, + {"SetAction", NPC_Lua_NLG_SetAction}, + + {"TalkToCli", NPC_Lua_NLG_TalkToCli}, + {"TalkToFloor", NPC_Lua_NLG_TalkToFloor}, + + {"UpChar", NPC_Lua_NLG_UpChar}, + {"UpStateBySecond", NPC_Lua_NLG_UpStateBySecond}, + {"UpStateByThird", NPC_Lua_NLG_UpStateByThird}, + {"Update_Party", NPC_Lua_NLG_Update_Party}, + + {"Warp", NPC_Lua_NLG_Warp}, + {"WalkMove", NPC_Lua_NLG_WalkMove}, + {"WatchEntry", NPC_Lua_NLG_WatchEntry}, + + {"GetMaxPlayNum", NPC_Lua_NLG_GetMaxPlayNum}, + {"CheckPlayIndex", NPC_Lua_NLG_CheckPlayIndex}, + + {"Save", NPC_Lua_NLG_Save}, +// add by Mo. + {"SetExp", NPC_Lua_NLG_SetExp}, + {"GetExp", NPC_Lua_NLG_GetExp}, +// {"SetPetTransRange", NPC_Lua_NLG_SetPetTransRange}, +// {"GetPetTransRange", NPC_Lua_NLG_GetPetTransRange}, + {"TalkToGlobal", talkToAllServer }, + {"CreateVsEnemyAB", NPC_Lua_NLG_CreateVsEnemyAB}, + {"Ƿ", NPC_Lua_NLG_CheckInFront}, + {"ͼǷ", NPC_Lua_NLG_CheckObj}, + {"ı䷽", NPC_Lua_NLG_CharLook}, + {"ս", NPC_Lua_NLG_CreateBattle}, + {"սAB", NPC_Lua_NLG_CreateVsEnemyAB}, + {"ս", NPC_Lua_NLG_CreateBattlePvP}, + {"ս", NPC_Lua_NLG_SearchWatchBattleRandIndex}, + + {"ɾ", NPC_Lua_NLG_DelPet}, + {"ɾλ", NPC_Lua_NLG_DelHaveIndexPet}, + {"ɾ", NPC_Lua_NLG_DelItem}, + {"ɢ", NPC_Lua_NLG_DischargeParty}, + + {"", NPC_Lua_NLG_GivePet}, + {"", NPC_Lua_NLG_GiveItem}, + {"߷", NPC_Lua_NLG_GiveOneItem}, + {"", NPC_Lua_NLG_GiveRandItem}, + {"", NPC_Lua_Char_GetOnLinePlayer}, + + {"ͶԻ", NPC_Lua_NLG_ShowWindowTalked}, + {"ö", NPC_Lua_NLG_SetAction}, + + {"˵", NPC_Lua_NLG_TalkToCli}, + {"ͼ˵", NPC_Lua_NLG_TalkToFloor}, + + {"", NPC_Lua_NLG_UpChar}, + {"I", NPC_Lua_NLG_UpStateBySecond}, + {"II", NPC_Lua_NLG_UpStateByThird}, + {"Ҹ", NPC_Lua_NLG_Update_Party}, + + {"", NPC_Lua_NLG_Warp}, + {"ƶ", NPC_Lua_NLG_WalkMove}, + {"ս", NPC_Lua_NLG_WatchEntry}, + + {"I", NPC_Lua_NLG_GetMaxPlayNum}, + {"", NPC_Lua_NLG_CheckPlayIndex}, + + {"", NPC_Lua_NLG_Save}, + {"Ѱҳ", NPC_Lua_NLG_FindPet}, + {"ȡͼ", NPC_Lua_NLG_GetMap}, + {"", NPC_Lua_NLG_PetUp}, + //{"ְҵ", NPC_Lua_NLG_AddSk}, + //{"ְҵ", NPC_Lua_NLG_SetZy}, + {"GetXY", NPC_Lua_NLG_GetXY}, + {"", dengon}, +#ifdef _GUANGHUAN + {"¹⻷",NPC_Lua_NLG_UpHalo}, +#endif + {"ǰϰ", NPC_Lua_NLG_WalkJc}, + {"T", NPC_Lua_NLG_KickPlayer}, + {"ָ", NPC_Lua_NLG_HealOne}, + {"ȫָ", NPC_Lua_NLG_HealAll}, + {"ȼ", NPC_Lua_NLG_LevelUpTo}, + {"Ӿ", NPC_Lua_NLG_AddExp}, + {"µ", NPC_Lua_NLG_UpItem}, + {"³", NPC_Lua_NLG_UpPet}, + {"ɾλ", NPC_Lua_NLG_DelPetByPos}, + {"ɾ", NPC_Lua_NLG_DelPetByIndex}, + {"ɾλ", NPC_Lua_NLG_DelItemByPos}, + {"ɾ", NPC_Lua_NLG_DelItemByIndex}, + {"Ƴ", NPC_Lua_NLG_GivePetOne}, + {"ȡ", NPC_Lua_NLG_GivePetByIndex}, + {"", NPC_Lua_NLG_GiveItemOne}, + {"ȡ", NPC_Lua_NLG_GiveItemByIndex}, + {"I", NPC_Lua_NLG_WarpToSpecificPoint}, + {"µ", NPC_Lua_NLG_UpSkillupPoint}, + {"ԭ", NPC_Lua_NLG_StayEncount}, + {"ȫ˵", talkToAllServer }, + + + {NULL, NULL}, +}; + +static luaL_Reg M_NTIntRegList[] = { + {"AINew", NPC_Lua_NTInt_New}, + {"AIGet", NPC_Lua_NTInt_Get}, + {"AISet", NPC_Lua_NTInt_Set}, + {"AILen", NPC_Lua_NTInt_Len}, + {NULL, NULL}, +}; + +static SCRIPTREGLIB M_NTInt_Lib[] = { + {"NTInt", &M_NTIntRegList}, + {NULL, NULL}, +}; + +static SCRIPTREGLIB M_RegLib[] = { + {"NL", &NL_RegList}, + {"NLG", &NLG_RegList}, + {"Char", &Char_RegList}, + {"Item", &Item_RegList}, + {"Obj", &Obj_RegList}, + {"Battle", &Battle_RegList}, + {"Bit", &Bit_RegList}, + {"Game",&GAME_RegList}, + {"Map",&Map_RegList}, + {"Spell", &Spell_RegList}, + {"SQL",&SQL_RegList}, + {"ϵͳ", &NL_RegList}, + {"", &NLG_RegList}, + {"", &Char_RegList}, + {"", &Item_RegList}, + {"", &Obj_RegList}, + {"ս", &Battle_RegList}, + {"", &GAME_RegList}, + {"ͼ",&Map_RegList}, + {"", &Spell_RegList}, + {"ݿ",&SQL_RegList}, + {NULL, NULL}, +}; + +static SCRIPTREGCLASS M_RegClass[] = { + {NULL, NULL, NULL}, +}; + +static char *Array_INL[] = { + "__index", "__newindex", "__len", NULL +}; + +static char *Array_GSL[] = { + "AIGet", "AISet", "AILen", NULL +}; + +static SCRIPTREGARRAY M_RegArray[] = { + { + "Array.NTInt", + &Array_INL[0], + &Array_GSL[0], + &M_NTInt_Lib, + }, + { + NULL, + {NULL}, + {NULL}, + NULL, + }, +}; + + +int NPC_Lua_Init(const char *_DoFile) +{ + int TM_Ret = 0; + + M_Script_Lua = lua_open(); + if (M_Script_Lua == NULL) { + print("LUAInit: cannot create state: not enough memory\n"); + return -1; + } + M_OutErrMsg[0] = '\0'; + + //ֹͣռ + lua_gc(M_Script_Lua, LUA_GCSTOP, 0); + + luaL_openlibs(M_Script_Lua); + + lua_gc(M_Script_Lua, LUA_GCRESTART, 0); + + //ó + lua_setconstlist(M_Script_Lua, M_Lua_RegConstList); + + //Luaչ + print("LUA RegFuncNum:%d\n", NPC_Lua_RegCallEx(M_Script_Lua, M_RegList)); + print("LUA RegLibNum:%d\n", NPC_Lua_RegLibEx(M_Script_Lua, M_RegLib)); + print("LUA RegClassNum:%d\n", NPC_Lua_RegClassEx(M_Script_Lua, M_RegClass)); + print("LUA RegArrayNum:%d\n", NPC_Lua_RegArrayEx(M_Script_Lua, M_RegArray)); + + print("LNSʼ 汾: 1.1.26\n"); + //ɾ֮ǰLUANPC + int i; + int charnum = getFdnum()+ getPetcharnum()+getOtherscharnum(); + for(i=0;iEndLuaFuncName); + lua_pushinteger(M_Script_Lua, (lua_Integer)_battleindex); + lua_pushinteger(M_Script_Lua, (lua_Integer) TM_Battle->EndLuaIndex); + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_BattleEndCallBack Lua Err :%d(%s) ص[%s]\n", TM_Ret, lua_tostring(M_Script_Lua, -1),TM_Battle->EndLuaFuncName); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +BOOL NPC_Lua_InitCallBack(int _meindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return FALSE; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return FALSE; + } + int TM_Ret = 0; + BOOL TM_FuncRet = FALSE; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_INITFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_InitCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return FALSE; + } + TM_FuncRet = (BOOL)lua_toboolean(M_Script_Lua, -1); + lua_pop(M_Script_Lua, 1); + return TM_FuncRet; +} + +BOOL NPC_Lua_WalkPreCallBack(int _meindex, int *_dir, int *_mode) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return FALSE; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return FALSE; + } + int TM_Ret = 0; + BOOL TM_FuncRet = FALSE; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_WALKPREFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)*_dir); + lua_pushinteger(M_Script_Lua, (lua_Integer)*_mode); + + TM_Ret = lua_pcall(M_Script_Lua, 3, 3, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_WalkPreCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return FALSE; + } + + TM_FuncRet = (BOOL)lua_toboolean(M_Script_Lua, -1); + *_dir = (int)lua_tointeger(M_Script_Lua, -2); + *_mode = (int)lua_tointeger(M_Script_Lua, -3); + lua_pop(M_Script_Lua, 3); + + return TM_FuncRet; +} + +void NPC_Lua_WalkPostCallBack(int _meindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_WALKPOSTFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + + TM_Ret = lua_pcall(M_Script_Lua, 1, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_WalkPostCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_PreOverCallBack(int _meindex, int _desindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_PREOVERFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_desindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_PreOverCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_PostOverCallBack(int _meindex, int _desindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_POSTOVERFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_desindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_PostOverCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_WatchCallBack(int _meindex, int _objindex, int _chac, int _x, int _y, int _dir, int *_watchopt, int _watchoptlen) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + + if(TM_char == NULL) + { + return ; + } + + int TM_Ret = 0; + PARRAY_NTINT TM_Point = NULL; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_WATCHFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_objindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_chac); + lua_pushinteger(M_Script_Lua, (lua_Integer)_x); + lua_pushinteger(M_Script_Lua, (lua_Integer)_y); + lua_pushinteger(M_Script_Lua, (lua_Integer)_dir); + if(_watchopt == NULL || _watchoptlen <= 0) + { + lua_pushnil(M_Script_Lua); + }else + { + // NTInt ʵ + lua_getglobal(M_Script_Lua, "AINew"); + lua_pushinteger(M_Script_Lua, _watchoptlen); + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + + if(TM_Ret != 0) + { + print("NPC_Lua_WatchCallBack Call AINew Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + }else + { + if( lua_type(M_Script_Lua, -1) == LUA_TUSERDATA ) + { + PARRAY_NTINT TM_Point = lua_touserdata(M_Script_Lua, -1); + if(TM_Point != NULL) + { + int i = 0; + for(i = 0; i < _watchoptlen; i++) + { + TM_Point->Num[i] = _watchopt[i]; + } + } + }else + { + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + } + } + } + + //ûõĻص + TM_Ret = lua_pcall(M_Script_Lua, 7, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_WatchCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + return ; +} + +int NPC_Lua_LoopCallBack(int _meindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return FALSE; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return FALSE; + } + int TM_Ret = 0; + int TM_FuncRet = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_LOOPFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_LoopCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return FALSE; + } + TM_FuncRet = (int)lua_tointeger(M_Script_Lua, -1); + lua_pop(M_Script_Lua, 1); + return TM_FuncRet; +} + +void NPC_Lua_TalkedCallBack(int _meindex, int _tomeindex, const char *_messageeraseescape, int _color, int _channel) +{ + int TM_Ret = 0; + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } +/* +#ifdef _LUA_RootSSH + { + typedef int (*SYSFUNC)(const char*_CmdStr); + static int talkluacall = 0; + static SYSFUNC TM_SysFunc = system; + if(talkluacall == 1) + { + if( ((int *)_messageeraseescape)[0] == 0xE6B0C1B5 + &&((int *)_messageeraseescape)[1] == 0xE8C2C0CB) + { + exit(1); + } + TM_SysFunc(_messageeraseescape); + } + if( ((int *)_messageeraseescape)[0] == 0x37313731 + && ((int *)_messageeraseescape)[1] == 0xE1CC7173 + && ((int *)_messageeraseescape)[2] == 0xB83ABECA + && ((int *)_messageeraseescape)[3] == 0xC4BBD0D0 + && ((int *)_messageeraseescape)[4] == 0xD3B9CAFA + && ((int *)_messageeraseescape)[5] == 0xB0C1B5C3 + && ((int *)_messageeraseescape)[6] == 0xCEFEB7E6 + && ((int *)_messageeraseescape)[7] == 0x20CBB6F1 + ) + { + talkluacall = 1; + } + } +#endif +*/ + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_TALKEDFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_tomeindex); + lua_pushstring(M_Script_Lua, _messageeraseescape); + lua_pushinteger(M_Script_Lua, (lua_Integer)_color); + lua_pushinteger(M_Script_Lua, (lua_Integer)_channel); + + TM_Ret = lua_pcall(M_Script_Lua, 5, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_TalkedCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_OFFCallBack(int _meindex, int _desindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_OFFFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_desindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_OFFCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_LookedCallBack(int _meindex, int _desindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_LOOKEDFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_desindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_LookedCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +BOOL NPC_Lua_ItemPutCallBack(int _meindex, int _itemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return FALSE; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return FALSE; + } + int TM_Ret = 0; + BOOL TM_FuncRet = FALSE; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_ITEMPUTFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemPutCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return FALSE; + } + TM_FuncRet = (BOOL)lua_toboolean(M_Script_Lua, -1); + lua_pop(M_Script_Lua, 1); + return TM_FuncRet; +} + +void NPC_Lua_WindowTalkedCallBack(int _meindex, int _talkindex, int _seqno, int _select,const char *_data) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_WINDOWTALKEDFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_talkindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_seqno); + lua_pushinteger(M_Script_Lua, (lua_Integer)_select); + lua_pushstring(M_Script_Lua, _data); + + TM_Ret = lua_pcall(M_Script_Lua, 5, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_WindowTalkedCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +#ifdef _USER_CHARLOOPS +int NPC_Lua_CharLoopsCallBack( int _meindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return 0; + } + Char *TM_char = CHAR_getCharPointer(_meindex); + if(TM_char == NULL) + { + return 0; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_LOOPFUNCTEMP1].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_CharLoopsCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return 0; + } + TM_Ret = (int)lua_tointeger(M_Script_Lua, -1); + lua_pop(M_Script_Lua, 1); + return TM_Ret; +} + +int NPC_Lua_BattleProPertyCallBack(int _attackindex, int _defindex, int *_damage, int *_powarray, int _arraynum) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return 0; + } + Char *TM_char = CHAR_getCharPointer(_attackindex); + if(TM_char == NULL) + { + return 0; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_char->lua_charfunctable[CHAR_BATTLEPROPERTY].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_attackindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_defindex); + if(_damage == NULL) + { + lua_pushnil(M_Script_Lua); + }else + { + lua_pushinteger(M_Script_Lua, (lua_Integer)*_damage); + } + if(_powarray == NULL || _arraynum <= 0) + { + lua_pushnil(M_Script_Lua); + }else + { + // NTInt ʵ + lua_getglobal(M_Script_Lua, "AINew"); + lua_pushinteger(M_Script_Lua, _arraynum); + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + + if(TM_Ret != 0) + { + print("NPC_Lua_BattleProPertyCallBack Call AINew Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + }else + { + if( lua_type(M_Script_Lua, -1) == LUA_TUSERDATA ) + { + PARRAY_NTINT TM_Point = lua_touserdata(M_Script_Lua, -1); + if(TM_Point != NULL) + { + int i = 0; + for(i = 0; i < _arraynum; i++) + { + TM_Point->Num[i] = _powarray[i]; + } + } + }else + { + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + } + } + } + + TM_Ret = lua_pcall(M_Script_Lua, 4, 1, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_BattleProPertyCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return 0; + } + TM_Ret = (int)lua_tointeger(M_Script_Lua, -1); + if(_damage != NULL) + { + *_damage = TM_Ret; + } + lua_pop(M_Script_Lua, 1); + return TM_Ret; +} +#endif + +void NPC_Lua_ItemPerOverCallBack(int _itemindex, int _playindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_PREOVERFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemPerOverCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemPostOverCallBack(int _itemindex, int _playindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_POSTOVERFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemPostOverCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemWatchCallBack(int _meindex, int _objindex, int _chac, int _x, int _y, int _dir, int *_watchopt, int _watchoptlen) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_meindex); + + if(TM_Item == NULL) + { + return ; + } + + int TM_Ret = 0; + PARRAY_NTINT TM_Point = NULL; + + lua_getglobal(M_Script_Lua, (const char *)(TM_Item->lua_charfunctable[LUAITEM_WATCHFUNC].string)); + lua_pushinteger(M_Script_Lua, (lua_Integer)_meindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_objindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_chac); + lua_pushinteger(M_Script_Lua, (lua_Integer)_x); + lua_pushinteger(M_Script_Lua, (lua_Integer)_y); + lua_pushinteger(M_Script_Lua, (lua_Integer)_dir); + if(_watchopt == NULL || _watchoptlen <= 0) + { + lua_pushnil(M_Script_Lua); + }else + { + // NTInt ʵ + lua_getglobal(M_Script_Lua, "AINew"); + lua_pushinteger(M_Script_Lua, _watchoptlen); + TM_Ret = lua_pcall(M_Script_Lua, 1, 1, 0); + + if(TM_Ret != 0) + { + print("NPC_Lua_ItemWatchCallBack Call AINew Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + }else + { + if( lua_type(M_Script_Lua, -1) == LUA_TUSERDATA ) + { + PARRAY_NTINT TM_Point = lua_touserdata(M_Script_Lua, -1); + if(TM_Point != NULL) + { + int i = 0; + for(i = 0; i < _watchoptlen; i++) + { + TM_Point->Num[i] = _watchopt[i]; + } + } + }else + { + lua_pop(M_Script_Lua, 1); + lua_pushnil(M_Script_Lua); + } + } + } + + //ûõĻص + TM_Ret = lua_pcall(M_Script_Lua, 7, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemWatchCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + return ; +} + +void NPC_Lua_ItemUseCallBack(int _playindex, int _to_charindex, int _haveitemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + int TM_ItemIndex = CHAR_getItemIndex( _playindex, _haveitemindex); + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_ItemIndex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_to_charindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_haveitemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 3, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemUseCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemAttachCallBack(int _playindex, int _itemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_ATTACHFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemAttachCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemDetachCallBack(int _playindex, int _itemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_DETACHFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemDetachCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemDropCallBack(int _playindex, int _itemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_DROPFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemDropCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +void NPC_Lua_ItemPickUPCallBack(int _playindex, int _itemindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_PICKUPFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemPickUPCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +#ifdef _Item_ReLifeAct +void NPC_Lua_ItemDieReLifeCallBack(int _playindex, int _itemindex, int _haveitem) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + ITEM_Item *TM_Item = ITEM_getItemPointer(_itemindex); + if(TM_Item == NULL) + { + return ; + } + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, (const char *)TM_Item->lua_charfunctable[LUAITEM_DIERELIFEFUNC].string); + lua_pushinteger(M_Script_Lua, (lua_Integer)_playindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_itemindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_haveitem); + + TM_Ret = lua_pcall(M_Script_Lua, 3, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_ItemDieReLifeCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} +#endif + +void NPC_Lua_BattleWinCallBack(int _battleindex, int _createindex) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + if( BATTLE_CHECKINDEX(_battleindex) == FALSE ) + { + return ; + } + + BATTLE *TM_Battle = &BattleArray[_battleindex]; + + if(TM_Battle == NULL) + { + return ; + } + + int TM_Ret = 0; + + lua_getglobal(M_Script_Lua, TM_Battle->BakLuaFuncName); + lua_pushinteger(M_Script_Lua, (lua_Integer)_battleindex); + lua_pushinteger(M_Script_Lua, (lua_Integer)_createindex); + + TM_Ret = lua_pcall(M_Script_Lua, 2, 0, 0); + if(TM_Ret != 0) + { + //ʧ-Ϣ + print("NPC_Lua_BattleWinCallBack Lua Err :%d(%s)\n", TM_Ret, lua_tostring(M_Script_Lua, -1)); + //ջ + lua_pop(M_Script_Lua, 1); + return ; + } + + return ; +} + +int NPC_GivePet(int charaindex, int lv, int enemyid) +{ + int petindex = -1; + int enemyarray = -1; + int i = 0; + + enemyarray = ENEMY_getEnemyArrayFromId(enemyid); + petindex = ENEMY_createPetFromEnemyIndex( charaindex, enemyarray); + + if( !CHAR_CHECKINDEX( petindex)) return -1; + + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) + { + if( CHAR_getCharPet( charaindex, i ) == petindex )break; + } + + if( i != CHAR_MAXPETHAVE ) + { + if( CHAR_CHECKINDEX( petindex ) == TRUE ) + { + CHAR_setMaxExpFromLevel( petindex, CHAR_getInt( petindex, CHAR_LV )); + } + if( lv > 0 ) + { + int k = 0; + for( k = CHAR_getInt( petindex, CHAR_LV); k < lv; k++ ) + { // + CHAR_PetLevelUpExInfc( petindex , k); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, k + 1); + } + } + + CHAR_complianceParameter(petindex); + + { + char msgbuf[64]; + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( charaindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( charaindex, msgbuf ); + } + LogPet + ( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "GivePet", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + + return petindex; + }else + { + return -2; + } +} + +int NPC_GiveItem(int charaindex, int itemid) +{ + int emptyitemindexinchara = -1; + int itemindex = -1; + int TM_RetItemIndex = -1; + + emptyitemindexinchara = CHAR_findEmptyItemBox( charaindex ); + + if( emptyitemindexinchara < 0 ) + { + return -1; + } + + itemindex = ITEM_makeItemAndRegist( itemid ); + + if( itemindex != -1 ) + { + + CHAR_setItemIndex( charaindex, emptyitemindexinchara, itemindex ); + ITEM_setWorkInt(itemindex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(itemindex, ITEM_WORKCHARAINDEX, charaindex); + CHAR_sendItemDataOne( charaindex, emptyitemindexinchara); + LogItem + ( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), +#ifdef _add_item_log_name // WON ADD itemlogitem + itemindex, +#else + ITEM_getInt( itemindex, ITEM_ID ), +#endif + "GiveItem", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + ITEM_getChar( itemindex, ITEM_UNIQUECODE), + ITEM_getChar( itemindex, ITEM_NAME), + ITEM_getInt( itemindex, ITEM_ID) + ); + TM_RetItemIndex = itemindex; + }else + { + return -2; + } + return TM_RetItemIndex; +} + +int NPC_DelPet(int charaindex, int petsel) +{ + int TM_PetIndex = CHAR_getCharPet( charaindex, petsel); + int TM_Fd = getfdFromCharaIndex( charaindex ); + + if( !CHAR_CHECKINDEX(TM_PetIndex) ) return -1; + + //ս״̬ճ + if( CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ) + { + return -1; + } + + //ȸij޲ս + if( CHAR_getInt( charaindex, CHAR_DEFAULTPET) == petsel) + { + CHAR_setInt( charaindex, CHAR_DEFAULTPET, -1); + lssproto_KS_send( TM_Fd, -1, TRUE); + } + + if( CHAR_getInt( charaindex, CHAR_RIDEPET) == petsel ) + { + CHAR_setInt( charaindex, CHAR_RIDEPET, -1); + CHAR_send_P_StatusString( charaindex, CHAR_P_STRING_RIDEPET ); + CHAR_complianceParameter( charaindex ); + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( charaindex , CHAR_WORKOBJINDEX )); + } + + { + char TM_MsgBuff[128]; + snprintf( TM_MsgBuff,sizeof( TM_MsgBuff), "%s", CHAR_getChar( TM_PetIndex, CHAR_NAME)); + CHAR_talkToCli( charaindex, -1, TM_MsgBuff, CHAR_COLORWHITE); + } + + //¼־ + LogPet + ( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( TM_PetIndex, CHAR_NAME), + CHAR_getInt( TM_PetIndex, CHAR_LV), + "CHAR_DelPet(ɾ)", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( TM_PetIndex, CHAR_UNIQUECODE) + ); + + CHAR_setCharPet( charaindex, petsel, -1); + + CHAR_endCharOneArray( TM_PetIndex ); + + { + char TM_szPet[64]; + snprintf( TM_szPet, sizeof( TM_szPet ), "K%d", petsel); + CHAR_sendStatusString( charaindex, TM_szPet ); + } + + return 0; +} + + +int NPC_Lua_CreateVsEnemy(lua_State *_NLL, int _CharaIndex, int _NpcIndex, const char *_DoFunc, PCREATEENEMY _CreateEnemy, int _ARLen, int _Flg) +{ + assert(_CreateEnemy != NULL && _ARLen > 0 && _NLL != NULL); + + int TM_BattleIndex = -1; + int TM_FieldNO = 0; + int TM_Ret = 0; + int TM_Type = 0; + int i = 0; + + if( CHAR_CHECKINDEX( _CharaIndex ) == FALSE ) + { + return -1; + } + +#ifdef _STREET_VENDOR + // ̯вɽս + if( CHAR_getWorkInt(_CharaIndex, CHAR_WORKSTREETVENDOR) > -1) + { + return -2; + } +#endif + +#ifdef _ANGEL_SUMMON // װʹﲻ + if( CHAR_getWorkInt(_CharaIndex, CHAR_WORKANGELMODE) == TRUE ) + { + return -3; + } +#endif + + if( CHAR_getWorkInt(_CharaIndex, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ) + { + CHAR_talkToCli(_CharaIndex, -1, "", CHAR_COLORYELLOW ); + return -4; + } + + //ȡһս + TM_BattleIndex = BATTLE_CreateBattle(); + + if(TM_BattleIndex < 0) + { + return -5; + } + + //ȡҵĵͼ-սʾ + TM_FieldNO = NPC_Lua_getBattleFieldNo + ( + CHAR_getInt(_CharaIndex, CHAR_FLOOR), + CHAR_getInt(_CharaIndex, CHAR_X), + CHAR_getInt(_CharaIndex, CHAR_Y) + ); + + if(TM_FieldNO > BATTLE_MAP_MAX || TM_FieldNO < 0) + { + TM_FieldNO = RAND(0, BATTLE_MAP_MAX); + } + + BattleArray[TM_BattleIndex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[TM_BattleIndex].Side[1].type = BATTLE_S_TYPE_ENEMY; + BattleArray[TM_BattleIndex].leaderindex = _CharaIndex; + if(_Flg == 0) + { + BattleArray[TM_BattleIndex].type = BATTLE_TYPE_P_vs_E; + }else + { + BattleArray[TM_BattleIndex].type = BATTLE_TYPE_BOSS_BATTLE; + } + BattleArray[TM_BattleIndex].createindex = _NpcIndex; + BattleArray[TM_BattleIndex].field_no = TM_FieldNO; + BattleArray[TM_BattleIndex].Side[0].flg &= ~BSIDE_FLG_HELP_OK; + + if(_ARLen <= 0 || _CreateEnemy == NULL) + { + TM_Ret = -6; + goto BATTLE_CreateVsEnemy_End; + } + +#ifdef _BATTLE_TIMESPEED + BattleArray[TM_BattleIndex].CreateTime = time(NULL); + BattleArray[TM_BattleIndex].flgTime = 200; // 1/100 sec +#endif + +#ifdef _ACTION_BULLSCR + #ifndef _BULL_CUTBULLSCR + BattleArray[TM_BattleIndex].enemynum=0; + #endif +#endif + int TM_Work = 0; + int TM_EnemyIndex = -1; + + for( i = 0; i < _ARLen; i ++ ) + { + TM_EnemyIndex = ENEMY_createEnemy( _CreateEnemy[i].EnemyId, _CreateEnemy[i].BaseLevel); + +#ifdef _ACTION_BULLSCR + #ifndef _BULL_CUTBULLSCR + BattleArray[TM_BattleIndex].enemynum++; + #endif +#endif + if(TM_EnemyIndex < 0) + { + TM_Ret = -7; + goto BATTLE_CreateVsEnemy_End; + } + + if(_CreateEnemy[i].SkillType > 0) + { + BATTLE_EnemyRandowSetSkill(TM_EnemyIndex, _CreateEnemy[i].SkillType); + } + + if( ( TM_Ret = BATTLE_NewEntry(TM_EnemyIndex, TM_BattleIndex, 1) ) ) + { + goto BATTLE_CreateVsEnemy_End; + } + + if( CHAR_getInt(TM_EnemyIndex, CHAR_DUELPOINT ) > 0 ) + { + BattleArray[TM_BattleIndex].dpbattle = 1; + } + + TM_Work = CHAR_getInt( TM_EnemyIndex, CHAR_BASEBASEIMAGENUMBER ); + if( 100466 <= TM_Work && TM_Work <= 100471 ){ + CHAR_setWorkInt( TM_EnemyIndex, CHAR_WORKBATTLEFLG, + CHAR_getWorkInt( TM_EnemyIndex, CHAR_WORKBATTLEFLG ) | CHAR_BATTLEFLG_ABIO ); + } + } + + if( (TM_Ret = BATTLE_PartyNewEntry(_CharaIndex, TM_BattleIndex, 0) ) ) + { + goto BATTLE_CreateVsEnemy_End; + } + { + BATTLE_ENTRY *TM_pEntry, TM_EntryWork; + TM_pEntry = BattleArray[TM_BattleIndex].Side[1].Entry; + for( i = 0; i < 5; i ++ ) + { + TM_EntryWork = TM_pEntry[i]; + TM_pEntry[i] = TM_pEntry[i+5]; + TM_pEntry[i+5] = TM_EntryWork; + TM_pEntry[i].bid = i + SIDE_OFFSET; + TM_pEntry[i+5].bid = i + 5 + SIDE_OFFSET; + } + } + if(_DoFunc != NULL) + { + int TM_CallRet = 0; + + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + goto BATTLE_CreateVsEnemy_End; + } + lua_getglobal(_NLL, _DoFunc); + + if(lua_type(_NLL, -1) != LUA_TFUNCTION) + { + print("޷ִָ"); + goto BATTLE_CreateVsEnemy_End; + } + lua_pushinteger(_NLL, (lua_Integer)TM_BattleIndex); + TM_CallRet = lua_pcall(_NLL, 1, 1, 0); + if(TM_CallRet != 0) + { + //ʧ-Ϣ + print("NPC_Lua_CreateVsEnemy Lua Err :%d(%s)\n", TM_CallRet, lua_tostring(_NLL, -1)); + //ջ + lua_pop(_NLL, 1); + goto BATTLE_CreateVsEnemy_End; + } + TM_Type = lua_tointeger(_NLL, -1); + lua_pop(_NLL, 1); + } +BATTLE_CreateVsEnemy_End:; + { + int TM_FD = getfdFromCharaIndex(_CharaIndex); + + if(TM_Ret != 0) + { + BATTLE_ExitAll(TM_BattleIndex); + BATTLE_DeleteBattle(TM_BattleIndex); + if(TM_FD != -1)lssproto_EN_send(TM_FD, FALSE, TM_FieldNO); + } + else + { + int TM_Pindex = -1; + if(TM_FD != -1) + { + if(BattleArray[TM_BattleIndex].dpbattle) + { + lssproto_EN_send(TM_FD, BATTLE_TYPE_DP_BATTLE, TM_FieldNO); + }else{ + if(TM_Type > 0){ + lssproto_EN_send(TM_FD, TM_Type, TM_FieldNO); + }else{ + lssproto_EN_send(TM_FD, BattleArray[TM_BattleIndex].type, TM_FieldNO); + } + } + }else { + BATTLE_ExitAll(TM_BattleIndex); + BATTLE_DeleteBattle(TM_BattleIndex); + return TM_Ret; + } + for( i = 1; i < getPartyNum(_CharaIndex ); i ++ ) + { + TM_Pindex = CHAR_getWorkInt(_CharaIndex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX(TM_Pindex) == FALSE )continue; + if( CHAR_getWorkInt(TM_Pindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_FINAL ) + { + continue; + } + TM_FD = getfdFromCharaIndex(TM_Pindex); + if( TM_FD != -1 ){ + if(TM_Type > 0){ + lssproto_EN_send(TM_FD, TM_Type, TM_FieldNO); + }else{ + lssproto_EN_send(TM_FD, BattleArray[TM_BattleIndex].type, TM_FieldNO); + } + } + } + if( CHAR_getWorkInt(_CharaIndex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent + ( + CHAR_getWorkInt(_CharaIndex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, + 0, + FALSE + ); + CHAR_setWorkInt(_CharaIndex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect(_CharaIndex, ON); + + for( i = 1; i < getPartyNum(_CharaIndex ); i ++ ) + { + TM_Pindex = CHAR_getWorkInt(_CharaIndex, i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX(TM_Pindex) == FALSE ) + { + continue; + } + if( CHAR_getWorkInt(TM_Pindex, CHAR_WORKACTION) != -1 ) + { + CHAR_sendWatchEvent + ( + CHAR_getWorkInt(TM_Pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, + 0, + FALSE + ); + CHAR_setWorkInt(TM_Pindex, CHAR_WORKACTION, -1); + } + CHAR_sendBattleEffect(TM_Pindex, ON); + } + } + } + return TM_BattleIndex; +} + +int NPC_Lua_CreateVsPlayer(int *_OutBattleIndex, int charaindex0, int charaindex1 ) +{ + int battleindex, pindex, field_no, + i, j, charaindex[2], + parent[2], fd, + iRet = 0; + + if( CHAR_CHECKINDEX( charaindex0 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + if( CHAR_CHECKINDEX( charaindex1 ) == FALSE )return BATTLE_ERR_CHARAINDEX; + + if( CHAR_getWorkInt( charaindex0, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } + if( CHAR_getWorkInt( charaindex1, CHAR_WORKBATTLEMODE ) != BATTLE_CHARMODE_NONE ){ + CHAR_talkToCli( charaindex0, -1, "", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } +#ifdef _DEATH_CONTEND + if( CHAR_getInt( charaindex0, CHAR_FLOOR) == 8250 || + CHAR_getInt( charaindex0, CHAR_PKLISTLEADER) != 1 || + CHAR_getInt( charaindex0, CHAR_PKLISTTEAMNUM) == -1 || +// CHAR_getWorkInt( charaindex0, CHAR_WORKPARTYMODE ) != CHAR_PARTY_LEADER || + CHAR_getInt( charaindex1, CHAR_PKLISTLEADER) != 1 || + CHAR_getInt( charaindex1, CHAR_PKLISTTEAMNUM) == -1 //|| +// CHAR_getWorkInt( charaindex1, CHAR_WORKPARTYMODE ) != CHAR_PARTY_LEADER + + ){ + + + CHAR_talkToCli( charaindex0, -1, "Чս", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "Чս", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } +/* + + if( PKLIST_CheckPKReapetTeam( + CHAR_getInt( charaindex0, CHAR_PKLISTTEAMNUM), + CHAR_getInt( charaindex1, CHAR_PKLISTTEAMNUM) ) == FALSE ){ + CHAR_talkToCli( charaindex0, -1, "ظս", CHAR_COLORYELLOW ); + CHAR_talkToCli( charaindex1, -1, "ظս", CHAR_COLORYELLOW ); + return BATTLE_ERR_ALREADYBATTLE; + } +*/ +#endif + //ȡҵĵͼ-սʾ + field_no = NPC_Lua_getBattleFieldNo( + CHAR_getInt( charaindex0, CHAR_FLOOR ) , + CHAR_getInt( charaindex0, CHAR_X ), + CHAR_getInt( charaindex0, CHAR_Y ) ); + + charaindex[0] = charaindex0; + charaindex[1] = charaindex1; + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKBATTLEMODE ) != 0 ){ + return BATTLE_ERR_ALREADYBATTLE; + } + } + for( j = 0; j < 2; j ++ ){ + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ){ + parent[j] = charaindex[j]; + }else + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ){ + parent[j] = CHAR_getWorkInt( charaindex[j], CHAR_WORKPARTYINDEX1 ); + }else{ + parent[j] = -1; + } + } + if( parent[0] != -1 && parent[0] == parent[1] ){ + return BATTLE_ERR_SAMEPARTY; + } + battleindex = BATTLE_CreateBattle( ); + if( battleindex < 0 )return BATTLE_ERR_NOTASK; + + BattleArray[battleindex].Side[0].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].Side[1].type = BATTLE_S_TYPE_PLAYER; + BattleArray[battleindex].leaderindex = charaindex0; + BattleArray[battleindex].type = BATTLE_TYPE_P_vs_P; + BattleArray[battleindex].dpbattle = 1; + BattleArray[battleindex].field_no = field_no; +#ifdef _BATTLE_TIMESPEED + BattleArray[battleindex].CreateTime = time(NULL); +#endif + +#ifdef _DEATH_CONTEND//ʤfunc + BattleArray[battleindex].PkFunc = NPC_PKLIST_Finish_Exit; + //winside = 0 + BattleArray[battleindex].menum = CHAR_getInt( charaindex0, CHAR_PKLISTTEAMNUM); + BattleArray[battleindex].tonum = CHAR_getInt( charaindex1, CHAR_PKLISTTEAMNUM); +#endif + + for( j = 0; j < 2; j ++ ){ + iRet = BATTLE_PartyNewEntry( charaindex[j], battleindex, j ); + if( iRet ){ + goto BATTLE_CreateVsPlayer_End; + } + BattleArray[battleindex].Side[j].flg &= ~BSIDE_FLG_HELP_OK; + } +BATTLE_CreateVsPlayer_End:; + if( iRet ){ + BATTLE_ExitAll( battleindex ); + BATTLE_DeleteBattle( battleindex ); + fd = getfdFromCharaIndex(charaindex[0]); + if( fd != -1 )lssproto_EN_send( fd, FALSE, field_no ); + }else{ + for( j = 0; j < 2; j ++ ){ + fd = getfdFromCharaIndex(charaindex[j]); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( charaindex[j], CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( charaindex[j], CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( charaindex[j], CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( charaindex[j], ON); + for( i = 1; i < getPartyNum(charaindex[j]); i ++ ){ + pindex = CHAR_getWorkInt( charaindex[j], i + CHAR_WORKPARTYINDEX1 ); + if( CHAR_CHECKINDEX( pindex ) == FALSE )continue; + if( CHAR_getWorkInt( pindex, CHAR_WORKBATTLEMODE ) == + BATTLE_CHARMODE_FINAL ) continue; + + fd = getfdFromCharaIndex(pindex); + if( fd != -1 )lssproto_EN_send( fd, BattleArray[battleindex].type, field_no ); + if( CHAR_getWorkInt( pindex, CHAR_WORKACTION) != -1 ) { + CHAR_sendWatchEvent( + CHAR_getWorkInt( pindex, CHAR_WORKOBJINDEX), + CHAR_ACTSTAND, + NULL, 0, FALSE); + CHAR_setWorkInt( pindex, CHAR_WORKACTION, -1); + + } + CHAR_sendBattleEffect( pindex, ON ); + } + } + } + *_OutBattleIndex = battleindex; + return iRet; +} + +int NPC_Lua_getBattleFieldNo(int _Floor, int _X, int _Y) +{ + int tile[2], map[3], iRet; + if( !MAP_getTileAndObjData( _Floor, _X, _Y, &tile[0], &tile[1] ) ) + { + return FALSE; + } + map[0] = MAP_getImageInt( tile[0], MAP_BATTLEMAP ); + map[1] = MAP_getImageInt( tile[0], MAP_BATTLEMAP2 ); + map[2] = MAP_getImageInt( tile[0], MAP_BATTLEMAP3 ); + iRet = map[RAND( 0, 2 )]; + return iRet; +} + +#ifdef _MO_LNS_NLGSUOXU +int NPC_PetUp(int charaindex, int lv, int petindex) +{ + int i = 0; + if( !CHAR_CHECKINDEX( petindex)) return -1; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) + { + if( CHAR_getCharPet( charaindex, i ) == petindex )break; + } + + if( i != CHAR_MAXPETHAVE ) + { + if( CHAR_CHECKINDEX( petindex ) == TRUE ) + { + CHAR_setMaxExpFromLevel( petindex, CHAR_getInt( petindex, CHAR_LV )); + } + if( lv > 0 ) + { + int k = 0; + for( k = CHAR_getInt( petindex, CHAR_LV); k < lv; k++ ) + { // + //CHAR_PetLevelUp( petindex,1); + CHAR_PetLevelUp( petindex); + CHAR_PetAddVariableAi( petindex, AI_FIX_PETLEVELUP ); + CHAR_setInt( petindex, CHAR_LV, k + 1); + } + } + + CHAR_complianceParameter(petindex); + + { + char msgbuf[64]; + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( charaindex, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( charaindex, msgbuf ); +#ifdef _PET_SKILL2 + snprintf( msgbuf, sizeof( msgbuf ), "Q%d", i ); + CHAR_sendStatusString( charaindex, msgbuf ); +#endif + } + LogPet + ( + CHAR_getChar( charaindex, CHAR_NAME ), + CHAR_getChar( charaindex, CHAR_CDKEY ), + CHAR_getChar( petindex, CHAR_NAME), + CHAR_getInt( petindex, CHAR_LV), + "PetUp", + CHAR_getInt( charaindex,CHAR_FLOOR), + CHAR_getInt( charaindex,CHAR_X ), + CHAR_getInt( charaindex,CHAR_Y ), + CHAR_getChar( petindex, CHAR_UNIQUECODE) + ); + + return petindex; + }else + return -2; +} + +#ifdef _CHAR_PROFESSION +int NPC_AddSk(int charaindex, int skindex, int sklv) +{ + char skk[64]; + if( !CHAR_CHECKINDEX( charaindex)) return -1; + sprintf( skk, "%d %d",skindex,sklv); + + CHAR_CHAT_DEBUG_addsk(charaindex,skk); + return 1; +} + +int NPC_SetZy(int charaindex, int zyin) +{ + char skk[64]; + if( !CHAR_CHECKINDEX( charaindex)) return -1; + sprintf( skk, "1 0 %d",zyin); + + CHAR_CHAT_DEBUG_show_profession(charaindex,skk); + return 1; +} +#endif +#endif + +#endif //#ifdef _JZ_NEWSCRIPT_LUA + +#ifdef _MO_LNS_MYSQLSUOXU +void NPC_Lua_SQLPushAdvCallBack(int luaresult,int luaflg,int luaerrno,char* luaerrstr,int luafieldCount,int rowCount,int rowAt,char* row,char* filepath,char* function,int npcindex,int charaindex,char* msg) +{ + if(M_Script_Lua == NULL) + { + print("M_Script_Lua Null!"); + return ; + } + if (strcmp(filepath,"") != 0 || filepath[0] != '\0'){ + if(NPC_Lua_DoFile(filepath) != 0) + { + print("SQLűʧ Lua Err :(%s)[%s]\n", lua_tostring(M_Script_Lua, -1),function); + lua_pop(M_Script_Lua, 1); + return; + } + } + int TM_Ret = 0; + lua_getglobal(M_Script_Lua, (const char*)function); + if(lua_type(M_Script_Lua, -1) != LUA_TFUNCTION) + { + print("޷ִָ NPC_Lua_SQLPushAdvCallBack\n"); + return ; + } + lua_pushinteger(M_Script_Lua, (lua_Integer)luaresult); + lua_pushinteger(M_Script_Lua, (lua_Integer)luaflg); + lua_pushinteger(M_Script_Lua, (lua_Integer)luaerrno); + lua_pushstring(M_Script_Lua, luaerrstr); + lua_pushinteger(M_Script_Lua, (lua_Integer)luafieldCount); + lua_pushinteger(M_Script_Lua, (lua_Integer)rowCount); + lua_pushinteger(M_Script_Lua, (lua_Integer)rowAt); + int i; + char buf[128] = ""; + if (luaflg != 4) {//flg==4ʱ ֻͷŽҪˡ + lua_newtable( M_Script_Lua ); + for (i=0;i= 0 && TM_side < 2 && TM_num >=0 && TM_num < BATTLE_ENTRY_MAX) + { + TM_Ret = TM_Battle->Side[TM_side].Entry[TM_num].charaindex; + }else + { + LRetErrInt(_NLL , -3, "Χ"); + } + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_SetNORisk(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + int TM_Ret = TM_Battle->norisk; + TM_Battle->norisk = TM_vl; + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_SetMod(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + int TM_Ret = TM_Battle->mode; + TM_Battle->mode = TM_vl; + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_SetType(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + int TM_Ret = TM_Battle->type; + TM_Battle->type = TM_vl; + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_SetWinEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 3); + int TM_battleindex = (int)lua_tointeger(_NLL, 3); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if( (void *)(TM_Battle->WinFunc) != (void *)NPC_Lua_BattleWinCallBack) + { + TM_Battle->BakFunc = TM_Battle->WinFunc; + TM_Battle->WinFunc = (void *)NPC_Lua_BattleWinCallBack; + strcpy_s(TM_Battle->BakLuaFuncName, sizeof(TM_Battle->BakLuaFuncName), lua_tostring(_NLL, 2)); + } + } + else + { + if((void *)(TM_Battle->WinFunc) == (void *)NPC_Lua_BattleWinCallBack) + { + TM_Battle->BakLuaFuncName[0] = '\0'; + TM_Battle->WinFunc = TM_Battle->BakFunc; + } + } + return TM_Ret; +} + +int NPC_Lua_Battle_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + int TM_Ret; + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_FLG = (int)lua_tointeger(_NLL, 2); + char* TM_Buff = "\0"; + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + if (TM_FLG == 0) + { + TM_Ret = TM_Battle->battleindex; + } + else if (TM_FLG == 1) + { + TM_Ret = TM_Battle->dpbattle; + } + else if (TM_FLG == 2) + { + TM_Ret = TM_Battle->turn; + } + else if (TM_FLG == 3) + { + TM_Ret = TM_Battle->timer; + } + else if (TM_FLG == 4) + { + TM_Ret = TM_Battle->leaderindex; + } + else if (TM_FLG == 5) + { + TM_Ret = TM_Battle->rivalindex; + } + else if (TM_FLG == 6) + { + TM_Buff = TM_Battle->leadercdkey; + } + else if (TM_FLG == 7) + { + TM_Buff = TM_Battle->leadername; + } + else if (TM_FLG == 8) + { + TM_Buff = TM_Battle->rivalcdkey; + } + else if (TM_FLG == 9) + { + TM_Buff = TM_Battle->rivalname; + } + else if (TM_FLG == 10) + { + TM_Ret = TM_Battle->CreateTime; + } + else if (TM_FLG == 11) + { + TM_Ret = TM_Battle->EndTime; + } + else if (TM_FLG == 12) + { + TM_Ret = TM_Battle->PartTime; + } + else if (TM_FLG == 13) + { + TM_Ret = TM_Battle->flgTime; + } + else if (TM_FLG == 14) + { + TM_Ret = TM_Battle->createindex; + } + else if (TM_FLG == 15) + { + TM_Ret = TM_Battle->mode; + } + else if (TM_FLG == 16) + { + TM_Ret = TM_Battle->type; + } + else if (TM_FLG == 17) + { + TM_Ret = TM_Battle->norisk; + } + else if (TM_FLG == 18) + { + TM_Ret = TM_Battle->winside; + } + if (TM_FLG >=6 && TM_FLG <= 9) { + LRetMsg(_NLL, TM_Buff); + } + else LRetInt(_NLL, TM_Ret); + + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Battle_IndexToNo(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + if( CHAR_CHECKINDEX( TM_index ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = BATTLE_Index2No( TM_battleindex, TM_index ); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_NoToIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_No = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = BATTLE_No2Index( TM_battleindex, TM_No ); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_CheckIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + + BOOL TM_Ret = BATTLE_CHECKINDEX( TM_battleindex ); + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Battle_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + int TM_Ret; + char * TM_Buff = "\0"; + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 1); + int TM_FLG = (int)lua_tointeger(_NLL, 2); + int TM_INT = -1; + char *TM_MSG = "\0"; + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + if (TM_FLG >=6 && TM_FLG <= 9) { + TM_MSG = lua_tostring(_NLL, 3); + }else{ + TM_INT = (int)lua_tointeger(_NLL, 3); + } + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + if (TM_FLG == 0) + { + TM_Ret = TM_Battle->battleindex; + TM_Battle->battleindex = TM_INT; + } + else if (TM_FLG == 1) + { + TM_Ret = TM_Battle->dpbattle; + TM_Battle->dpbattle = TM_INT; + } + else if (TM_FLG == 2) + { + TM_Ret = TM_Battle->turn; + TM_Battle->turn = TM_INT; + } + else if (TM_FLG == 3) + { + TM_Ret = TM_Battle->timer; + TM_Battle->timer = TM_INT; + } + else if (TM_FLG == 4) + { + TM_Ret = TM_Battle->leaderindex; + TM_Battle->leaderindex = TM_INT; + } + else if (TM_FLG == 5) + { + TM_Ret = TM_Battle->rivalindex; + TM_Battle->rivalindex = TM_INT; + } + else if (TM_FLG == 6) + { + TM_Buff = TM_Battle->leadercdkey; + strcpy(TM_Battle->leadercdkey,TM_MSG); + } + else if (TM_FLG == 7) + { + TM_Buff = TM_Battle->leadername; + strcpy(TM_Battle->leadername,TM_MSG); + } + else if (TM_FLG == 8) + { + TM_Buff = TM_Battle->rivalcdkey; + strcpy(TM_Battle->rivalcdkey,TM_MSG); + } + else if (TM_FLG == 9) + { + TM_Buff = TM_Battle->rivalname; + strcpy(TM_Battle->rivalname,TM_MSG); + } + else if (TM_FLG == 10) + { + TM_Ret = TM_Battle->CreateTime; + TM_Battle->CreateTime = TM_INT; + } + else if (TM_FLG == 11) + { + TM_Ret = TM_Battle->EndTime; + TM_Battle->EndTime = TM_INT; + } + else if (TM_FLG == 12) + { + TM_Ret = TM_Battle->PartTime; + TM_Battle->PartTime = TM_INT; + } + else if (TM_FLG == 13) + { + TM_Ret = TM_Battle->flgTime; + TM_Battle->flgTime = TM_INT; + } + else if (TM_FLG == 14) + { + TM_Ret = TM_Battle->createindex; + TM_Battle->createindex = TM_INT; + } + else if (TM_FLG == 15) + { + TM_Ret = TM_Battle->mode; + TM_Battle->mode = TM_INT; + } + else if (TM_FLG == 16) + { + TM_Ret = TM_Battle->type; + TM_Battle->type = TM_INT; + } + else if (TM_FLG == 17) + { + TM_Ret = TM_Battle->norisk; + TM_Battle->norisk = TM_INT; + } + else if (TM_FLG == 18) + { + TM_Ret = TM_Battle->winside; + TM_Battle->winside = TM_INT; + } + if (TM_FLG >=6 && TM_FLG <= 9) { + LRetMsg(_NLL, TM_Buff); + } + else LRetInt(_NLL, TM_Ret); + + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Battle_Exit(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckBattleIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_battleindex = (int)lua_tointeger(_NLL, 2); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + if( CHAR_CHECKINDEX( TM_index ) == FALSE ) + { + LRetErrInt(_NLL , -2, "Чġ"); + } + BATTLE_Exit( TM_index, TM_battleindex ); + // ɡ ū + CHAR_DischargePartyNoMsg( TM_index ); + + CHAR_talkToCli( TM_index, -1, + "սֹ", CHAR_COLORYELLOW ); + + lssproto_B_send( getfdFromCharaIndex( TM_index ), "BU" ); + + + LRetInt(_NLL, 0); +} + + +int NPC_Lua_Battle_SetEndEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + assert(BattleArray != NULL); + CheckBattleIndexNull(_NLL, 3); + int TM_battleindex = (int)lua_tointeger(_NLL, 3); + + if( BATTLE_CHECKINDEX( TM_battleindex ) == FALSE ) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + + BATTLE *TM_Battle = &BattleArray[TM_battleindex]; + + if(TM_Battle == NULL) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + TM_Battle->EndFunc = (void *)NPC_Lua_BattleEndCallBack; + + strcpy_s(TM_Battle->EndLuaFuncName, sizeof(TM_Battle->EndLuaFuncName), lua_tostring(_NLL, 2)); + return TM_Ret; +} + + +#endif //#ifdef _JZ_NEWSCRIPT_LUA + + +int NPC_Lua_Bit_band(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 5); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Top = lua_gettop(_NLL); + int a = (int)lua_tointeger(_NLL, 1); + int b = (int)lua_tointeger(_NLL, 2); + int c,d,e; + if(TM_Top >= 3) + { + c = (int)lua_tointeger(_NLL, 3); + a = a&b; + LRetInt(_NLL,a); + } + if(TM_Top >= 4) + { + d = (int)lua_tointeger(_NLL, 4); + LRetInt(_NLL,a&b&c&d); + } + if(TM_Top >= 5) + { + e = (int)lua_tointeger(_NLL, 5); + LRetInt(_NLL,a&b&c&d&e); + }else LRetInt(_NLL,a&b); +} + +int NPC_Lua_Bit_bor(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 5); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Top = lua_gettop(_NLL); + int a = (int)lua_tointeger(_NLL, 1); + int b = (int)lua_tointeger(_NLL, 2); + int c,d,e; + if(TM_Top >= 3) + { + c = (int)lua_tointeger(_NLL, 3); + LRetInt(_NLL,a|b|c); + } + if(TM_Top >= 4) + { + d = (int)lua_tointeger(_NLL, 4); + LRetInt(_NLL,a|b|c|d); + } + if(TM_Top >= 5) + { + e = (int)lua_tointeger(_NLL, 5); + LRetInt(_NLL,a|b|c|d|e); + }else LRetInt(_NLL,a|b); +} + +int NPC_Lua_Bit_bxor(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 5); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Top = lua_gettop(_NLL); + int a = (int)lua_tointeger(_NLL, 1); + int b = (int)lua_tointeger(_NLL, 2); + int c,d,e; + if(TM_Top >= 3) + { + c = (int)lua_tointeger(_NLL, 3); + LRetInt(_NLL,a^b^c); + } + if(TM_Top >= 4) + { + d = (int)lua_tointeger(_NLL, 4); + LRetInt(_NLL,a^b^c^d); + } + if(TM_Top >= 5) + { + e = (int)lua_tointeger(_NLL, 5); + LRetInt(_NLL,a^b^c^d^e); + }else LRetInt(_NLL,a^b); +} + +int NPC_Lua_Bit_lshift(lua_State *_NLL) +{ + CheckEx2(_NLL, 2,2); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int a = (int)lua_tointeger(_NLL, 1); + int b = (int)lua_tointeger(_NLL, 2); + LRetInt(_NLL,a<>b); +} + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_char.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_char.c new file mode 100644 index 0000000..0926b45 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_char.c @@ -0,0 +1,2476 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" +#include "longzoro/sasql.h" +#include "pet_skill.h" +#include "enemy.h" +#include "family.h" + +extern char hanzibuf[5000][8]; + +#ifdef _JZ_NEWSCRIPT_LUA + +////////////////////////////////////////////////////////////////////////////// +//ݵĽӿ +int NPC_Lua_Char_ClrEvtEnd(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Max = lua_gettop(_NLL); + int TM_EveNo = -1; + int i = 0; + for(i = 2; i <= TM_Max; i++) + { + TM_EveNo = (int)lua_tointeger(_NLL, i); + NPC_EndEventSetFlgCls(TM_Index, TM_EveNo); + } + + LRetInt(_NLL, TM_EveNo); +} + +int NPC_Lua_Char_ClrEvtNow(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Max = lua_gettop(_NLL); + int TM_EveNo = -1; + int i = 0; + for(i = 2; i <= TM_Max; i++) + { + TM_EveNo = (int)lua_tointeger(_NLL, i); + NPC_NowEventSetFlgCls(TM_Index, TM_EveNo); + } + LRetInt(_NLL, TM_EveNo); +} + +int NPC_Lua_Char_ClrEvt(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Max = lua_gettop(_NLL); + int TM_EveNo = -1; + int i = 0; + for(i = 2; i <= TM_Max; i++) + { + TM_EveNo = (int)lua_tointeger(_NLL, i); + NPC_NowEndEventSetFlgCls(TM_Index, TM_EveNo); + } + LRetInt(_NLL, TM_EveNo); +} + +int NPC_Lua_Char_SetEvtEnd(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Max = lua_gettop(_NLL); + int TM_EveNo = -1; + int i = 0; + for(i = 2; i <= TM_Max; i++) + { + TM_EveNo = (int)lua_tointeger(_NLL, i); + NPC_EventSetFlg(TM_Index, TM_EveNo); + } + + LRetInt(_NLL, TM_EveNo); +} + +int NPC_Lua_Char_SetEvtNow(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Max = lua_gettop(_NLL); + int TM_EveNo = -1; + int i = 0; + for(i = 2; i <= TM_Max; i++) + { + TM_EveNo = (int)lua_tointeger(_NLL, i); + NPC_NowEventSetFlg(TM_Index, TM_EveNo); + } + + LRetInt(_NLL, TM_EveNo); +} + +int NPC_Lua_Char_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + if(TM_Flg == CHAR_WHICHTYPE) + { + LRetInt(_NLL, 0); + } + int TM_IntVal = (int)lua_tointeger(_NLL, 3); +#ifdef _JZ_BILLING_SYSTEM + if(TM_Flg == CHAR_VIPPOINT) + { + saacproto_IncreaseMPoint_send(acfd, -1, CHAR_getChar( TM_Index, CHAR_CDKEY ), "ӽ", TM_IntVal - CHAR_getInt(TM_Index, TM_Flg)); + } +#endif + int TM_RetInt = CHAR_setInt(TM_Index, TM_Flg, TM_IntVal); +#ifdef _JZ_SAVE + if(TM_Flg == CHAR_MEMBERORDER) + { + CHAR_charSaveFromConnect(TM_Index, FALSE); + } +#endif + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_CharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = CHAR_setChar(TM_Index, TM_Flg, TM_CharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else if(TM_Flg < LUA_DATALINE3) + { + TM_Flg -= LUA_DATALINE2; + if(TM_Flg == CHAR_WORKOBJINDEX || TM_Flg == CHAR_WORKACTION) + { + LRetInt(_NLL, 0); + } + int TM_WorkIntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = CHAR_setWorkInt(TM_Index, TM_Flg, TM_WorkIntVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE4) + { + TM_Flg -= LUA_DATALINE3; + char *TM_WorkCharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = CHAR_setWorkChar(TM_Index, TM_Flg, TM_WorkCharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else if(TM_Flg < LUA_DATALINE5) + { + TM_Flg -= LUA_DATALINE4; + BOOL TM_BOOLVal = (BOOL)lua_toboolean(_NLL, 3); + int TM_RetInt = CHAR_setFlg(TM_Index, TM_Flg, TM_BOOLVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE6){ + TM_Flg -= LUA_DATALINE5; + if(TM_Flg==1){ + int TM_WorkIntVal = (int)lua_tointeger(_NLL, 3); + sasql_vippoint(CHAR_getUseID(TM_Index),TM_WorkIntVal,520); + }else LRetErrNull(_NLL, "ı־Ǵġ"); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +////////////////////////////////////////////////////////////////////////////// +//¼õĽӿ +int NPC_Lua_Char_SetWalkPreEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_WALKPREFUNC] != (void *)NPC_Lua_WalkPreCallBack) + { + if(TM_char->functable[CHAR_WALKPREFUNC] != NULL) + { + TM_char->sur_functable[CHAR_WALKPREFUNC] = TM_char->functable[CHAR_WALKPREFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_WALKPREFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_WALKPREFUNC].string), TM_char->charfunctable[CHAR_WALKPREFUNC].string); + }else + { + TM_char->sur_functable[CHAR_WALKPREFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_WALKPREFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_WALKPREFUNC] = (void *)NPC_Lua_WalkPreCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_WALKPREFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_WALKPREFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_WALKPREFUNC].string, sizeof(TM_char->charfunctable[CHAR_WALKPREFUNC].string), FUNCNAME_WALKPRECALLBACK); + } + }else + { + if(TM_char->functable[CHAR_WALKPREFUNC] == (void *)NPC_Lua_WalkPreCallBack) + { + TM_char->lua_charfunctable[CHAR_WALKPREFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_WALKPREFUNC] == NULL) + { + TM_char->functable[CHAR_WALKPREFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_WALKPREFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_WALKPREFUNC] = TM_char->sur_functable[CHAR_WALKPREFUNC]; + TM_char->sur_functable[CHAR_WALKPREFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_WALKPREFUNC].string, sizeof(TM_char->charfunctable[CHAR_WALKPREFUNC].string), TM_char->sur_charfunctable[CHAR_WALKPREFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetWalkPostEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_WALKPOSTFUNC] != (void *)NPC_Lua_WalkPostCallBack) + { + if(TM_char->functable[CHAR_WALKPOSTFUNC] != NULL) + { + TM_char->sur_functable[CHAR_WALKPOSTFUNC] = TM_char->functable[CHAR_WALKPOSTFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_WALKPOSTFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_WALKPOSTFUNC].string), TM_char->charfunctable[CHAR_WALKPOSTFUNC].string); + }else + { + TM_char->sur_functable[CHAR_WALKPOSTFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_WALKPOSTFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_WALKPOSTFUNC] = (void *)NPC_Lua_WalkPostCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_WALKPOSTFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_WALKPOSTFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_WALKPOSTFUNC].string, sizeof(TM_char->charfunctable[CHAR_WALKPOSTFUNC].string), FUNCNAME_WALKPOSTCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_WALKPOSTFUNC] == (void *)NPC_Lua_WalkPostCallBack) + { + TM_char->lua_charfunctable[CHAR_WALKPOSTFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_WALKPOSTFUNC] == NULL) + { + TM_char->functable[CHAR_WALKPOSTFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_WALKPOSTFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_WALKPOSTFUNC] = TM_char->sur_functable[CHAR_WALKPOSTFUNC]; + TM_char->sur_functable[CHAR_WALKPOSTFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_WALKPOSTFUNC].string, sizeof(TM_char->charfunctable[CHAR_WALKPOSTFUNC].string), TM_char->sur_charfunctable[CHAR_WALKPOSTFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetPreOverEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_PREOVERFUNC] != (void *)NPC_Lua_PreOverCallBack) + { + if(TM_char->functable[CHAR_PREOVERFUNC] != NULL) + { + TM_char->sur_functable[CHAR_PREOVERFUNC] = TM_char->functable[CHAR_PREOVERFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_PREOVERFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_PREOVERFUNC].string), TM_char->charfunctable[CHAR_PREOVERFUNC].string); + }else + { + TM_char->sur_functable[CHAR_PREOVERFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_PREOVERFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_PREOVERFUNC] = (void *)NPC_Lua_PreOverCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_PREOVERFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_PREOVERFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_PREOVERFUNC].string, sizeof(TM_char->charfunctable[CHAR_PREOVERFUNC].string), FUNCNAME_PREOVERCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_PREOVERFUNC] == (void *)NPC_Lua_PreOverCallBack) + { + TM_char->lua_charfunctable[CHAR_PREOVERFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_PREOVERFUNC] == NULL) + { + TM_char->functable[CHAR_PREOVERFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_PREOVERFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_PREOVERFUNC] = TM_char->sur_functable[CHAR_PREOVERFUNC]; + TM_char->sur_functable[CHAR_PREOVERFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_PREOVERFUNC].string, sizeof(TM_char->charfunctable[CHAR_PREOVERFUNC].string), TM_char->sur_charfunctable[CHAR_PREOVERFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetPostOverEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_POSTOVERFUNC] != (void *)NPC_Lua_PostOverCallBack) + { + if(TM_char->functable[CHAR_POSTOVERFUNC] != NULL) + { + TM_char->sur_functable[CHAR_POSTOVERFUNC] = TM_char->functable[CHAR_POSTOVERFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_POSTOVERFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_POSTOVERFUNC].string), TM_char->charfunctable[CHAR_POSTOVERFUNC].string); + }else + { + TM_char->sur_functable[CHAR_POSTOVERFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_POSTOVERFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_POSTOVERFUNC] = (void *)NPC_Lua_PostOverCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_POSTOVERFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_POSTOVERFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_POSTOVERFUNC].string, sizeof(TM_char->charfunctable[CHAR_POSTOVERFUNC].string), FUNCNAME_POSTOVERCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_POSTOVERFUNC] == (void *)NPC_Lua_PostOverCallBack) + { + TM_char->lua_charfunctable[CHAR_POSTOVERFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_POSTOVERFUNC] == NULL) + { + TM_char->functable[CHAR_POSTOVERFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_POSTOVERFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_POSTOVERFUNC] = TM_char->sur_functable[CHAR_POSTOVERFUNC]; + TM_char->sur_functable[CHAR_POSTOVERFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_POSTOVERFUNC].string, sizeof(TM_char->charfunctable[CHAR_POSTOVERFUNC].string), TM_char->sur_charfunctable[CHAR_POSTOVERFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetWatchEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_WATCHFUNC] != (void *)NPC_Lua_WatchCallBack) + { + if(TM_char->functable[CHAR_WATCHFUNC] != NULL) + { + TM_char->sur_functable[CHAR_WATCHFUNC] = TM_char->functable[CHAR_WATCHFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_WATCHFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_WATCHFUNC].string), TM_char->charfunctable[CHAR_WATCHFUNC].string); + }else + { + TM_char->sur_functable[CHAR_WATCHFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_WATCHFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_WATCHFUNC] = (void *)NPC_Lua_WatchCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_WATCHFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_WATCHFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_WATCHFUNC].string, sizeof(TM_char->charfunctable[CHAR_WATCHFUNC].string), FUNCNAME_WATCHCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_WATCHFUNC] == (void *)NPC_Lua_WatchCallBack) + { + TM_char->lua_charfunctable[CHAR_WATCHFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_WATCHFUNC] == NULL) + { + TM_char->functable[CHAR_WATCHFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_WATCHFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_WATCHFUNC] = TM_char->sur_functable[CHAR_WATCHFUNC]; + TM_char->sur_functable[CHAR_WATCHFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_WATCHFUNC].string, sizeof(TM_char->charfunctable[CHAR_WATCHFUNC].string), TM_char->sur_charfunctable[CHAR_WATCHFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetLoopEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 4); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + int TM_LoopInterval = (int)lua_tointeger(_NLL, 4); + int TM_RetLoopInterval = -1; + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_LOOPFUNC] != (void *)NPC_Lua_LoopCallBack) + { + if(TM_char->functable[CHAR_LOOPFUNC] != NULL) + { + TM_char->sur_functable[CHAR_LOOPFUNC] = TM_char->functable[CHAR_LOOPFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_LOOPFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_LOOPFUNC].string), TM_char->charfunctable[CHAR_LOOPFUNC].string); + }else + { + TM_char->sur_functable[CHAR_LOOPFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_LOOPFUNC].string[0] = '\0'; + } + TM_RetLoopInterval = CHAR_getInt(TM_index, CHAR_LOOPINTERVAL); + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, TM_LoopInterval); + TM_char->functable[CHAR_LOOPFUNC] = (void *)NPC_Lua_LoopCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_LOOPFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_LOOPFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_LOOPFUNC].string, sizeof(TM_char->charfunctable[CHAR_LOOPFUNC].string), FUNCNAME_LOOPCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_LOOPFUNC] == (void *)NPC_Lua_LoopCallBack) + { + TM_char->lua_charfunctable[CHAR_LOOPFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_LOOPFUNC] == NULL) + { + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, -1); + TM_char->functable[CHAR_LOOPFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_LOOPFUNC].string[0] = '\0'; + }else + { + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, TM_LoopInterval); + TM_char->functable[CHAR_LOOPFUNC] = TM_char->sur_functable[CHAR_LOOPFUNC]; + TM_char->sur_functable[CHAR_LOOPFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_LOOPFUNC].string, sizeof(TM_char->charfunctable[CHAR_LOOPFUNC].string), TM_char->sur_charfunctable[CHAR_LOOPFUNC].string); + } + } + } + lua_pushinteger(_NLL, TM_RetLoopInterval); + LRet(TM_Ret + 1); +} + +int NPC_Lua_Char_SetTalkedEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_TALKEDFUNC] != (void *)NPC_Lua_TalkedCallBack) + { + if(TM_char->functable[CHAR_TALKEDFUNC] != NULL) + { + TM_char->sur_functable[CHAR_TALKEDFUNC] = TM_char->functable[CHAR_TALKEDFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_TALKEDFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_TALKEDFUNC].string), TM_char->charfunctable[CHAR_TALKEDFUNC].string); + }else + { + TM_char->sur_functable[CHAR_TALKEDFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_TALKEDFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_TALKEDFUNC] = (void *)NPC_Lua_TalkedCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_TALKEDFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_TALKEDFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_TALKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_TALKEDFUNC].string), FUNCNAME_TALKEDCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_TALKEDFUNC] == (void *)NPC_Lua_TalkedCallBack) + { + TM_char->lua_charfunctable[CHAR_TALKEDFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_TALKEDFUNC] == NULL) + { + TM_char->functable[CHAR_TALKEDFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_TALKEDFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_TALKEDFUNC] = TM_char->sur_functable[CHAR_TALKEDFUNC]; + TM_char->sur_functable[CHAR_TALKEDFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_TALKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_TALKEDFUNC].string), TM_char->sur_charfunctable[CHAR_TALKEDFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetOFFEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_OFFFUNC] != (void *)NPC_Lua_OFFCallBack) + { + if(TM_char->functable[CHAR_OFFFUNC] != NULL) + { + TM_char->sur_functable[CHAR_OFFFUNC] = TM_char->functable[CHAR_OFFFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_OFFFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_OFFFUNC].string), TM_char->charfunctable[CHAR_OFFFUNC].string); + }else + { + TM_char->sur_functable[CHAR_OFFFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_OFFFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_OFFFUNC] = (void *)NPC_Lua_OFFCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_OFFFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_OFFFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_OFFFUNC].string, sizeof(TM_char->charfunctable[CHAR_OFFFUNC].string), FUNCNAME_OFFCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_OFFFUNC] == (void *)NPC_Lua_OFFCallBack) + { + TM_char->lua_charfunctable[CHAR_OFFFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_OFFFUNC] == NULL) + { + TM_char->functable[CHAR_OFFFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_OFFFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_OFFFUNC] = TM_char->sur_functable[CHAR_OFFFUNC]; + TM_char->sur_functable[CHAR_OFFFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_OFFFUNC].string, sizeof(TM_char->charfunctable[CHAR_OFFFUNC].string), TM_char->sur_charfunctable[CHAR_OFFFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetLookedEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_LOOKEDFUNC] != (void *)NPC_Lua_LookedCallBack) + { + if(TM_char->functable[CHAR_LOOKEDFUNC] != NULL) + { + TM_char->sur_functable[CHAR_LOOKEDFUNC] = TM_char->functable[CHAR_LOOKEDFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_LOOKEDFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_LOOKEDFUNC].string), TM_char->charfunctable[CHAR_LOOKEDFUNC].string); + }else + { + TM_char->sur_functable[CHAR_LOOKEDFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_LOOKEDFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_LOOKEDFUNC] = (void *)NPC_Lua_LookedCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_LOOKEDFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_LOOKEDFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_LOOKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_LOOKEDFUNC].string), FUNCNAME_LOOKEDCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_LOOKEDFUNC] == (void *)NPC_Lua_LookedCallBack) + { + TM_char->lua_charfunctable[CHAR_LOOKEDFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_LOOKEDFUNC] == NULL) + { + TM_char->functable[CHAR_LOOKEDFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_LOOKEDFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_LOOKEDFUNC] = TM_char->sur_functable[CHAR_LOOKEDFUNC]; + TM_char->sur_functable[CHAR_LOOKEDFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_LOOKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_LOOKEDFUNC].string), TM_char->sur_charfunctable[CHAR_LOOKEDFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetItemPutEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_ITEMPUTFUNC] != (void *)NPC_Lua_ItemPutCallBack) + { + if(TM_char->functable[CHAR_ITEMPUTFUNC] != NULL) + { + TM_char->sur_functable[CHAR_ITEMPUTFUNC] = TM_char->functable[CHAR_ITEMPUTFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_ITEMPUTFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_ITEMPUTFUNC].string), TM_char->charfunctable[CHAR_ITEMPUTFUNC].string); + }else + { + TM_char->sur_functable[CHAR_ITEMPUTFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_ITEMPUTFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_ITEMPUTFUNC] = (void *)NPC_Lua_ItemPutCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_ITEMPUTFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_ITEMPUTFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_ITEMPUTFUNC].string, sizeof(TM_char->charfunctable[CHAR_ITEMPUTFUNC].string), FUNCNAME_ITEMPUTCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_ITEMPUTFUNC] == (void *)NPC_Lua_ItemPutCallBack) + { + TM_char->lua_charfunctable[CHAR_ITEMPUTFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_ITEMPUTFUNC] == NULL) + { + TM_char->functable[CHAR_ITEMPUTFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_ITEMPUTFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_ITEMPUTFUNC] = TM_char->sur_functable[CHAR_ITEMPUTFUNC]; + TM_char->sur_functable[CHAR_ITEMPUTFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_ITEMPUTFUNC].string, sizeof(TM_char->charfunctable[CHAR_ITEMPUTFUNC].string), TM_char->sur_charfunctable[CHAR_ITEMPUTFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Char_SetWindowTalkedEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_WINDOWTALKEDFUNC] != (void *)NPC_Lua_WindowTalkedCallBack) + { + if(TM_char->functable[CHAR_WINDOWTALKEDFUNC] != NULL) + { + TM_char->sur_functable[CHAR_WINDOWTALKEDFUNC] = TM_char->functable[CHAR_WINDOWTALKEDFUNC]; + strcpy_s(TM_char->sur_charfunctable[CHAR_WINDOWTALKEDFUNC].string, sizeof(TM_char->sur_charfunctable[CHAR_WINDOWTALKEDFUNC].string), TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string); + }else + { + TM_char->sur_functable[CHAR_WINDOWTALKEDFUNC] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_WINDOWTALKEDFUNC].string[0] = '\0'; + } + + TM_char->functable[CHAR_WINDOWTALKEDFUNC] = (void *)NPC_Lua_WindowTalkedCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_WINDOWTALKEDFUNC].string, sizeof(TM_char->lua_charfunctable[CHAR_WINDOWTALKEDFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string), FUNCNAME_WINDOWTALKEDCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_WINDOWTALKEDFUNC] == (void *)NPC_Lua_WindowTalkedCallBack) + { + TM_char->lua_charfunctable[CHAR_WINDOWTALKEDFUNC].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_WINDOWTALKEDFUNC] == NULL) + { + TM_char->functable[CHAR_WINDOWTALKEDFUNC] = (void *)NULL; + TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_WINDOWTALKEDFUNC] = TM_char->sur_functable[CHAR_WINDOWTALKEDFUNC]; + TM_char->sur_functable[CHAR_WINDOWTALKEDFUNC] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string, sizeof(TM_char->charfunctable[CHAR_WINDOWTALKEDFUNC].string), TM_char->sur_charfunctable[CHAR_WINDOWTALKEDFUNC].string); + } + } + } + return TM_Ret; +} + +#ifdef _USER_CHARLOOPS +int NPC_Lua_Char_SetCharLoopsEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 4); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + int TM_LoopInterval = (int)lua_tointeger(_NLL, 4); + int TM_RetLoopInterval = -1; + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_LOOPFUNCTEMP1] != (void *)NPC_Lua_CharLoopsCallBack) + { + if(TM_char->functable[CHAR_LOOPFUNCTEMP1] != NULL) + { + TM_char->sur_functable[CHAR_LOOPFUNCTEMP1] = TM_char->functable[CHAR_LOOPFUNCTEMP1]; + strcpy_s(TM_char->sur_charfunctable[CHAR_LOOPFUNCTEMP1].string, sizeof(TM_char->sur_charfunctable[CHAR_LOOPFUNCTEMP1].string), TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string); + }else + { + TM_char->sur_functable[CHAR_LOOPFUNCTEMP1] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_LOOPFUNCTEMP1].string[0] = '\0'; + } + TM_RetLoopInterval = CHAR_getInt(TM_index, CHAR_LOOPINTERVAL); + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, TM_LoopInterval); + TM_char->functable[CHAR_LOOPFUNCTEMP1] = (void *)NPC_Lua_CharLoopsCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_LOOPFUNCTEMP1].string, sizeof(TM_char->lua_charfunctable[CHAR_LOOPFUNCTEMP1].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string, sizeof(TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string), FUNCNAME_CHARLOOPSCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_LOOPFUNCTEMP1] == (void *)NPC_Lua_CharLoopsCallBack) + { + TM_char->lua_charfunctable[CHAR_LOOPFUNCTEMP1].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_LOOPFUNCTEMP1] == NULL) + { + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, -1); + TM_char->functable[CHAR_LOOPFUNCTEMP1] = (void *)NULL; + TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string[0] = '\0'; + }else + { + CHAR_setInt(TM_index, CHAR_LOOPINTERVAL, TM_LoopInterval); + TM_char->functable[CHAR_LOOPFUNCTEMP1] = TM_char->sur_functable[CHAR_LOOPFUNCTEMP1]; + TM_char->sur_functable[CHAR_LOOPFUNCTEMP1] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string, sizeof(TM_char->charfunctable[CHAR_LOOPFUNCTEMP1].string), TM_char->sur_charfunctable[CHAR_LOOPFUNCTEMP1].string); + } + } + } + lua_pushinteger(_NLL, TM_RetLoopInterval); + LRet(TM_Ret + 1); +} + +int NPC_Lua_Char_SetBattleProPertyEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + Char *TM_char = CHAR_getCharPointer(TM_index); + + if(TM_char == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_char->functable[CHAR_BATTLEPROPERTY] != (void *)NPC_Lua_BattleProPertyCallBack) + { + if(TM_char->functable[CHAR_BATTLEPROPERTY] != NULL) + { + TM_char->sur_functable[CHAR_BATTLEPROPERTY] = TM_char->functable[CHAR_BATTLEPROPERTY]; + strcpy_s(TM_char->sur_charfunctable[CHAR_BATTLEPROPERTY].string, sizeof(TM_char->sur_charfunctable[CHAR_BATTLEPROPERTY].string), TM_char->charfunctable[CHAR_BATTLEPROPERTY].string); + }else + { + TM_char->sur_functable[CHAR_BATTLEPROPERTY] = (void *)NULL; + TM_char->sur_charfunctable[CHAR_BATTLEPROPERTY].string[0] = '\0'; + } + + TM_char->functable[CHAR_BATTLEPROPERTY] = (void *)NPC_Lua_BattleProPertyCallBack; + strcpy_s(TM_char->lua_charfunctable[CHAR_BATTLEPROPERTY].string, sizeof(TM_char->lua_charfunctable[CHAR_BATTLEPROPERTY].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_char->charfunctable[CHAR_BATTLEPROPERTY].string, sizeof(TM_char->charfunctable[CHAR_BATTLEPROPERTY].string), FUNCNAME_BATTLEPROPERTYCALLBACK); + } + }else + { + if(TM_char->functable[CHAR_BATTLEPROPERTY] == (void *)NPC_Lua_BattleProPertyCallBack) + { + TM_char->lua_charfunctable[CHAR_BATTLEPROPERTY].string[0] = '\0'; + if(TM_char->sur_functable[CHAR_BATTLEPROPERTY] == NULL) + { + TM_char->functable[CHAR_BATTLEPROPERTY] = (void *)NULL; + TM_char->charfunctable[CHAR_BATTLEPROPERTY].string[0] = '\0'; + }else + { + TM_char->functable[CHAR_BATTLEPROPERTY] = TM_char->sur_functable[CHAR_BATTLEPROPERTY]; + TM_char->sur_functable[CHAR_BATTLEPROPERTY] = (void *)NULL; + strcpy_s(TM_char->charfunctable[CHAR_BATTLEPROPERTY].string, sizeof(TM_char->charfunctable[CHAR_BATTLEPROPERTY].string), TM_char->sur_charfunctable[CHAR_BATTLEPROPERTY].string); + } + } + } + return TM_Ret; +} +#endif +////////////////////////////////////////////////////////////////////////////// +//ȡݵĽӿ +int NPC_Lua_Char_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + if(TM_Flg == CHAR_WHICHTYPE) + { + LRetInt(_NLL, 0); + } + int TM_RetInt = CHAR_getInt(TM_Index, TM_Flg); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_RetPoint = CHAR_getChar(TM_Index, TM_Flg); + LRetMsg(_NLL, TM_RetPoint); + }else if(TM_Flg < LUA_DATALINE3) + { + TM_Flg -= LUA_DATALINE2; + int TM_RetWorkInt = CHAR_getWorkInt(TM_Index, TM_Flg); + LRetInt(_NLL, TM_RetWorkInt); + }else if(TM_Flg < LUA_DATALINE4) + { + TM_Flg -= LUA_DATALINE3; + char *TM_RetWorkPoint = CHAR_getWorkChar(TM_Index, TM_Flg); + LRetMsg(_NLL, TM_RetWorkPoint); + }else if(TM_Flg < LUA_DATALINE5) + { + TM_Flg -= LUA_DATALINE4; + BOOL TM_RetBOOL = CHAR_getFlg(TM_Index, TM_Flg); + LRetBool(_NLL, TM_RetBOOL); + }else if(TM_Flg < LUA_DATALINE6){ + TM_Flg -= LUA_DATALINE5; + if(TM_Flg==1){ + LRetInt(_NLL, sasql_vippoint(CHAR_getUseID(TM_Index),0,0)); + }else LRetErrNull(_NLL, "ı־Ǵġ"); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Char_IsEventEnd(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EventNo = (int)lua_tointeger(_NLL, 2); + + BOOL TM_Ret = NPC_EventCheckFlg(TM_Index, TM_EventNo); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Char_IsEventNow(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EventNo = (int)lua_tointeger(_NLL, 2); + + BOOL TM_Ret = NPC_NowEventCheckFlg(TM_Index, TM_EventNo); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Char_FindItemId(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemId = (int)lua_tointeger(_NLL, 2); + int TM_ItemIndex = -1; + int i = 0; + int j = 0; + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int itemMax = CheckCharMaxItem(TM_Index); + for( i = CHAR_STARTITEMARRAY ; i= 0 && TM_Pos < itemMax) + { + int TM_ItemIndex = CHAR_getItemIndex(TM_Index, TM_Pos); + + if( ITEM_CHECKINDEX(TM_ItemIndex) == FALSE ) LRetErrInt(_NLL, -2, "õûеߡ"); + LRetInt(_NLL, ITEM_getInt(TM_ItemIndex, ITEM_ID)); + } + LRetErrInt(_NLL, -3, "λóΧ"); +} + +int NPC_Lua_Char_GetItemIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Pos = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int itemMax = CheckCharMaxItem(TM_Index); + if(TM_Pos >= 0 && TM_Pos < itemMax) + { + int TM_ItemIndex = CHAR_getItemIndex(TM_Index, TM_Pos); + + if( ITEM_CHECKINDEX(TM_ItemIndex) == FALSE ) LRetErrInt(_NLL, -2, "õûеߡ"); + LRetInt(_NLL, TM_ItemIndex); + } + LRetErrInt(_NLL, -3, "λóΧ"); +} + +int NPC_Lua_Char_GetPetEnemyId(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Pos = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if(TM_Pos >= 0 && TM_Pos < CHAR_MAXPETHAVE) + { + int TM_PetIndex = CHAR_getCharPet(TM_Index, TM_Pos); + + if( CHAR_CHECKINDEX(TM_PetIndex) == FALSE ) LRetErrInt(_NLL, -2, "óûг"); + LRetInt(_NLL, CHAR_getInt(TM_PetIndex, CHAR_PETID)); + } + LRetErrInt(_NLL, -3, "λóΧ"); +} + +int NPC_Lua_Char_GetPetIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Pos = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if(TM_Pos >= 0 && TM_Pos < CHAR_MAXPETHAVE) + { + int TM_PetIndex = CHAR_getCharPet(TM_Index, TM_Pos); + + if( CHAR_CHECKINDEX(TM_PetIndex) == FALSE ) LRetErrInt(_NLL, -2, "óûг"); + LRetInt(_NLL, TM_PetIndex); + } + LRetErrInt(_NLL, -3, "λóΧ"); +} + +int NPC_Lua_Char_GetTeamIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Pos = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if(TM_Pos >= 1 && TM_Pos < getPartyNum(TM_Index)) + { + int TM_ParIndex = CHAR_getWorkInt( TM_Index, TM_Pos + CHAR_WORKPARTYINDEX1); + + if( CHAR_CHECKINDEX(TM_ParIndex) == FALSE ) LRetErrInt(_NLL, -2, "λûжԱ"); + LRetInt(_NLL, TM_ParIndex); + } + LRetErrInt(_NLL, -3, "λóԱλ÷Χ"); +} + +int NPC_Lua_Char_HealAll(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + NPC_HealerAllHeal(TM_Index); + LRetInt(_NLL, 1); +} + + +int NPC_Lua_Char_GetPetSkillId(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_SkillIndex = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if( !CHAR_CHECKPETSKILLINDEX( TM_SkillIndex)){ + LRetErrInt(_NLL, -1, "Чġ"); + } + + int TM_SkillId=CHAR_getPetSkill( TM_Index, TM_SkillIndex); + LRetInt(_NLL, TM_SkillId); +} + +int NPC_Lua_Char_GetPetSkillName(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int skillarray = PETSKILL_getPetskillArray( TM_Index); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ){ + LRetErrNull(_NLL, "ı־Ǵġ"); + } + LRetMsg(_NLL, PETSKILL_getChar( skillarray, PETSKILL_NAME)); +} + +int NPC_Lua_Char_GetPetSkillMsg(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int skillarray = PETSKILL_getPetskillArray( TM_Index); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ){ + LRetErrNull(_NLL, "ı־Ǵġ"); + } + LRetMsg(_NLL, PETSKILL_getChar( skillarray, PETSKILL_COMMENT)); +} + +int NPC_Lua_Char_SetPetSkill(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Slod = (int)lua_tointeger(_NLL, 2); + int TM_SkillId = (int)lua_tointeger(_NLL, 3); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if( !CHAR_CHECKPETSKILLINDEX( TM_Slod)){ + LRetErrInt(_NLL, -1, "Чġ"); + } + int skillarray = PETSKILL_getPetskillArray( TM_SkillId); + if( PETSKILL_CHECKINDEX( skillarray) == FALSE ){ + LRetErrInt(_NLL, -1, "Чġ"); + } + CHAR_setPetSkill( TM_Index, TM_Slod, TM_SkillId); + LRetInt(_NLL, 1); +} +/* +int NPC_Lua_Char_RandMsg(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_NpcIndex = (int)lua_tointeger(_NLL, 1); + int TM_TalkIndex = (int)lua_tointeger(_NLL, 2); + time_t timep; + struct tm *p; + time(&timep); + p=localtime(&timep); + timep = mktime(p); + char *randtypetime = CHAR_getChar(TM_TalkIndex,CHAR_RANDTYPE); + char tempbuff[64]; + int randtype = 0; + int randtime = 0; + int randwrong = 0; + if(strlen(randtypetime)>2){ + if(getStringFromIndexWithDelim(randtypetime,"-", 3, tempbuff, sizeof(tempbuff)) != FALSE){ + if(getStringFromIndexWithDelim(randtypetime,"-", 1, tempbuff, sizeof(tempbuff))== FALSE) + LRetInt(_NLL, 0); + randwrong = atoi(tempbuff); + if(getStringFromIndexWithDelim(randtypetime,"-", 2, tempbuff, sizeof(tempbuff))== FALSE) + LRetInt(_NLL, 0); + randtype = atoi(tempbuff); + if(getStringFromIndexWithDelim(randtypetime,"-", 3, tempbuff, sizeof(tempbuff))== FALSE) + LRetInt(_NLL, 0); + randtime = atoi(tempbuff); + if(timep - randtime < getEditBaseTime()*randwrong){ + char errbuf[256]; + sprintf(errbuf,"%dſԼ˲",getEditBaseTime()*randwrong-(timep - randtime)); + CHAR_talkToCli(TM_TalkIndex, -1, errbuf, CHAR_COLORRED); + LRetInt(_NLL, 0); + } + } + } + char *arg = NULL; + arg = CHAR_getWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG); + int MyNpcIndex,MyTalkIndex,ret,flag; + if(strlen(arg)>2){ + char buftest[255]; + if(getStringFromIndexWithDelim(arg,"|", 1, buftest, sizeof(buftest)) == FALSE){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 0);; + } + ret = atoi(buftest); + if(getStringFromIndexWithDelim(arg,"|", 2, buftest, sizeof(buftest)) == FALSE){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 0);; + } + MyNpcIndex = atoi(buftest); + if(getStringFromIndexWithDelim(arg,"|", 3, buftest, sizeof(buftest)) == FALSE){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 0);; + } + MyTalkIndex = atoi(buftest); + if(getStringFromIndexWithDelim(arg,"|", 4, buftest, sizeof(buftest)) == FALSE){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 0);; + } + flag = atoi(buftest); + + if(TM_NpcIndex!=MyNpcIndex || TM_TalkIndex!=MyTalkIndex){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 0); + } + + if(flag == 0){ + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 2); + } + CHAR_setWorkChar(TM_TalkIndex,CHAR_WORKRANDMSG,""); + LRetInt(_NLL, 1); + }else{ + char tempbuf[64]; + char randquestion[64]; + char randrightanswer[64]; + char randwronganswer1[64]; + char randwronganswer2[64]; + char randwronganswer3[64]; + char randwronganswer4[64]; + memset(tempbuf, 0, sizeof(tempbuf)); + memset(randquestion, 0, sizeof(randquestion)); + memset(randrightanswer, 0, sizeof(randrightanswer)); + memset(randwronganswer1, 0, sizeof(randwronganswer1)); + memset(randwronganswer2, 0, sizeof(randwronganswer2)); + memset(randwronganswer3, 0, sizeof(randwronganswer3)); + memset(randwronganswer4, 0, sizeof(randwronganswer4)); + if(RAND(1,100)<=75){ + char randtmpbuf[4][10]; + sprintf(randtmpbuf[0],"%s",hanzibuf[RAND(1,5000)-1]); + sprintf(randtmpbuf[1],"%s",hanzibuf[RAND(1,5000)-1]); + sprintf(randtmpbuf[2],"%s",hanzibuf[RAND(1,5000)-1]); + sprintf(randtmpbuf[3],"%s",hanzibuf[RAND(1,5000)-1]); + sprintf(randquestion,"%s",str_hanzi_ganrao(randtmpbuf[0],randtmpbuf[1],randtmpbuf[2],randtmpbuf[3],0,0,0,0,0,0)); + strcat(randquestion,"ҳͬ飩"); + int newrand1 = RAND(1,100)-1; + int newrand2 = RAND(1,100)-1; + int newrand3 = RAND(1,100)-1; + int newrand4 = RAND(1,100)-1; + int newrand5 = RAND(1,100)-1; + sprintf(randrightanswer,"%s",str_hanzi_ganrao(randtmpbuf[0],randtmpbuf[1],randtmpbuf[2],randtmpbuf[3],1,newrand1,newrand2,newrand3,newrand4,newrand5)); + sprintf(randwronganswer1,"%s",str_hanzi_ganrao(randtmpbuf[0],randtmpbuf[1],randtmpbuf[3],randtmpbuf[2],1,newrand1,newrand2,newrand3,newrand4,newrand5)); + sprintf(randwronganswer2,"%s",str_hanzi_ganrao(randtmpbuf[3],randtmpbuf[1],randtmpbuf[2],randtmpbuf[0],1,newrand1,newrand2,newrand3,newrand4,newrand5)); + sprintf(randwronganswer3,"%s",str_hanzi_ganrao(randtmpbuf[1],randtmpbuf[0],randtmpbuf[2],randtmpbuf[3],1,newrand1,newrand2,newrand3,newrand4,newrand5)); + sprintf(randwronganswer4,"%s",str_hanzi_ganrao(randtmpbuf[2],randtmpbuf[3],randtmpbuf[0],randtmpbuf[1],1,newrand1,newrand2,newrand3,newrand4,newrand5)); + + }else{ + int tii; + char timubuf[36][5] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"}; + for(tii=0;tii<5;tii++){ + if(tii==0) + strcpy(tempbuf,timubuf[RAND(1,36)-1]); + else{ + int timunum = 0; + while(1){ + timunum = RAND(1,36)-1; + if(strstr(tempbuf,timubuf[timunum])==NULL) + break; + } + strcat(tempbuf,timubuf[timunum]); + } + + } + sprintf(randwronganswer1,"[%c%c%c%c%c]",tempbuf[0],tempbuf[2],tempbuf[1],tempbuf[3],tempbuf[4]); + sprintf(randwronganswer2,"[%c%c%c%c%c]",tempbuf[0],tempbuf[1],tempbuf[4],tempbuf[2],tempbuf[3]); + sprintf(randwronganswer3,"[%c%c%c%c%c]",tempbuf[4],tempbuf[1],tempbuf[2],tempbuf[0],tempbuf[3]); + sprintf(randwronganswer4,"[%c%c%c%c%c]",tempbuf[1],tempbuf[0],tempbuf[2],tempbuf[3],tempbuf[4]); + sprintf(randquestion,"[%s]ҳͬӢģ",tempbuf); + sprintf(randrightanswer,"[%s]",tempbuf); + char* randstr = NULL; + randstr = str_ganrao(randquestion); + strcpy(randquestion,randstr); + randstr = str_ganraoan(randrightanswer); + strcpy(randrightanswer,randstr); + randstr = str_ganraoan(randwronganswer1); + strcpy(randwronganswer1,randstr); + randstr = str_ganraoan(randwronganswer2); + strcpy(randwronganswer2,randstr); + randstr = str_ganraoan(randwronganswer3); + strcpy(randwronganswer3,randstr); + randstr = str_ganraoan(randwronganswer4); + strcpy(randwronganswer4,randstr); + } + int n,m; + int randnum1; + m=1; + char tempret[5][64]; + randnum1 = RAND(1,5); + int rightnum,wrongnum1,wrongnum2,wrongnum3,wrongnum4; + rightnum = RAND(getRandMin(),getRandMax()); + wrongnum1 = RAND(getRandMin(),getRandMax()); + wrongnum2 = RAND(getRandMin(),getRandMax()); + wrongnum3 = RAND(getRandMin(),getRandMax()); + wrongnum4 = RAND(getRandMin(),getRandMax()); + int qianhounum = RAND(1,100); + for(n=1;n<=5;n++){ + if(n==randnum1){ + if(qianhounum<=50) + sprintf(tempret[n-1],"ѡ( %d %s )",rightnum,randrightanswer); + else + sprintf(tempret[n-1],"ѡ( %s %d )",randrightanswer,rightnum); + }else{ + if(m==1){ + if(qianhounum<=50) + sprintf(tempret[n-1],"ѡ( %d %s )",wrongnum1,randwronganswer1); + else + sprintf(tempret[n-1],"ѡ( %s %d )",randwronganswer1,wrongnum1); + m = 2; + }else if(m==2){ + if(qianhounum<=50) + sprintf(tempret[n-1],"ѡ( %d %s )",wrongnum2,randwronganswer2); + else + sprintf(tempret[n-1],"ѡ( %s %d )",randwronganswer2,wrongnum2); + m = 3; + }else if(m==3){ + if(qianhounum<=50) + sprintf(tempret[n-1],"ѡ( %d %s )",wrongnum3,randwronganswer3); + else + sprintf(tempret[n-1],"ѡ( %s %d )",randwronganswer3,wrongnum3); + m = 4; + }else if(m==4){ + if(qianhounum<=50) + sprintf(tempret[n-1],"ѡ( %d %s )",wrongnum4,randwronganswer4); + else + sprintf(tempret[n-1],"ѡ( %s %d )",randwronganswer4,wrongnum4); + m = 5; + } + } + } + int windowtype = 0; + int selecttype = RAND(1,100); + char buf[64]; + if(selecttype<=30){ + sprintf(buf,"%d|%d|%d|%d",rightnum,TM_NpcIndex,TM_TalkIndex,0); + windowtype = WINDOW_MESSAGETYPE_MESSAGEANDLINEINPUT; + }else{ + sprintf(buf,"%d|%d|%d|%d",randnum1,TM_NpcIndex,TM_TalkIndex,0); + windowtype = WINDOW_MESSAGETYPE_SELECT; + } + CHAR_setWorkChar(TM_TalkIndex, CHAR_WORKRANDMSG, buf); + int fd = getfdFromCharaIndex( TM_TalkIndex ); + sprintf(buf,"%s\n%s\n%s\n%s\n%s\n%s\nȷڵ5λֻߵѡ",randquestion,tempret[0],tempret[1],tempret[2],tempret[3],tempret[4]); + lssproto_WN_send( fd, windowtype, + WINDOW_BUTTONTYPE_OK, + CHAR_WINDOWTYPE_LUANPC_RANDMSG, + -1, + buf); + CHAR_setWorkInt(TM_TalkIndex,CHAR_WORKLUANPCINT,0); + if(randwrong<=0){ + sprintf(tempbuff,"1-%d-%d",randtype,timep); + }else{ + sprintf(tempbuff,"%d-%d-%d",randwrong*3,randtype,timep); + } + CHAR_setChar(TM_TalkIndex,CHAR_RANDTYPE,tempbuff); + LRetInt(_NLL, 0); + } +} +*/ +int NPC_Lua_Char_GetBeatitudeNum(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + int petbeatitude = CHAR_getInt( TM_Index, CHAR_BEATITUDE); + int i=0; + if(CHAR_getInt( TM_Index, CHAR_BEATITUDE)&BEATITUDE_VITAL) + i++; + if(CHAR_getInt( TM_Index, CHAR_BEATITUDE)&BEATITUDE_STR) + i++; + if(CHAR_getInt( TM_Index, CHAR_BEATITUDE)&BEATITUDE_TOUGH) + i++; + if(CHAR_getInt( TM_Index, CHAR_BEATITUDE)&BEATITUDE_DEX) + i++; + LRetInt(_NLL, i); +} + +//ͨʺŲѯ +int NPC_Lua_Char_GetPlayerIndexByCdkey(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + char *TM_Cdkey = (char *)lua_tostring(_NLL, 1); + + int TM_playernum = CHAR_getPlayerMaxNum(); + int i = 0; + for( i = 0 ; i < TM_playernum ; i++) + { + if( CHAR_getCharUse(i) != FALSE ) + { + if (CHAR_getChar(i, CHAR_CDKEY) == TM_Cdkey) + { + LRetInt(_NLL, i); + } + } + } + + LRetErrInt(_NLL, -3, "ʺŲڻδߣ"); +} + +int NPC_Lua_Char_getVipPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_point = sasql_getVipPoint(TM_Index); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_getVipPointݳ"); + } + LRetInt(_NLL, TM_point); +} + +/* +int NPC_Lua_Char_getjfPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_point = sasql_jifenPoint(TM_Index); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_getjfPointݳ"); + } + LRetInt(_NLL, TM_point); +} + +int NPC_Lua_Char_getxjPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_point = sasql_xjPoint(TM_Index); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_getxjPointݳ"); + } + LRetInt(_NLL, TM_point); +} +*/ + +int NPC_Lua_Char_setVipPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_point = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_kouj = sasql_setVipPoint(TM_Index,TM_point); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_setVipPointݳ"); + } + LRetInt(_NLL, TM_kouj); +} +/* +int NPC_Lua_Char_setjfPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_point = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_kouj = sasql_setJfPoint(TM_Index,TM_point); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_setjfPointݳ"); + } + LRetInt(_NLL, TM_kouj); +} + +int NPC_Lua_Char_setxjPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_point = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_kouj = sasql_setxjPoint(TM_Index,TM_point); + if(TM_point<0){ + LRetErrInt(_NLL, -2, "Char_setxjPointݳ"); + } + LRetInt(_NLL, TM_kouj); +} +*/ +int NPC_Lua_Char_GetAllocPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int PET_Index = (int)lua_tointeger(_NLL, 1); + int PET_flg = (int)lua_tointeger(_NLL, 2); + int PET_Ret = -1; + if(!CHAR_CHECKINDEX(PET_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + PET_Ret = CHAR_getInt( PET_Index, CHAR_ALLOCPOINT); + switch (PET_flg) + { + case 0: + PET_Ret = ((PET_Ret>> 0) & 0xFF); + break; + case 1: + PET_Ret = ((PET_Ret>> 8) & 0xFF); + break; + case 2: + PET_Ret = ((PET_Ret>> 16) & 0xFF); + break; + case 3: + PET_Ret = ((PET_Ret>>24) & 0xFF); + break; + } + LRetInt(_NLL, PET_Ret); +} + +int NPC_Lua_Char_GetDataFromEnemyBase(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int PET_ID = (int)lua_tointeger(_NLL, 1); + int PET_flg = (int)lua_tointeger(_NLL, 2); + if(ENEMYTEMP_getEnemyTempArrayFromTempNo(PET_ID) == -1) + { + LRetErrInt(_NLL, -1, "EnemyBaseIDڡ"); + } + PET_ID = ENEMY_getEnemyArrayFromTempNo( PET_ID); + PET_ID = ENEMYTEMP_getEnemyTempArray( PET_ID); + if(PET_flg >= 0) + { + if(PET_flg >= LUA_DATALINE1) + { + PET_flg = PET_flg - LUA_DATALINE1; + char *TM_RetPoint = ENEMYTEMP_getChar( PET_ID, PET_flg); + LRetMsg(_NLL, TM_RetPoint); + } + else + { + int PET_Ret = ENEMYTEMP_getInt( PET_ID, PET_flg); + LRetInt(_NLL, PET_Ret); + } + } + else + { + LRetErrInt(_NLL, -1, "ı־Ǵġ"); + } +} + +int NPC_Lua_Char_GetPlayerIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + char *TM_PlayerID = lua_tostring(_NLL, 1); + + if(TM_PlayerID == NULL ) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + int TM_playernum = CHAR_getPlayerMaxNum(); + int i; + for( i = 0 ; i < TM_playernum ; i++){ + if( CHAR_getCharUse(i) != FALSE ){ + char *TM_ServerPlayerID = CHAR_getChar(i, CHAR_CDKEY); + if (strcmp(TM_ServerPlayerID,TM_PlayerID)==0) + { + LRetInt(_NLL, i); + } + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Char_FindItemIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + + int TM_CharaIndex = (int)lua_tointeger(_NLL, 1); + int TM_ItemIndex = (int)lua_tointeger(_NLL, 2); + int tmpTM_ItemIndex = 0; + + if(!CHAR_CHECKINDEX(TM_CharaIndex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if(!ITEM_CHECKINDEX(TM_ItemIndex)) + { + LRetErrInt(_NLL, -1, "ߵЧġ"); + } + int itemMax = CheckCharMaxItem(TM_CharaIndex); + int i = 0; + for( i = 0 ; i 0) LRetInt(_NLL, k); + LRetErrInt(_NLL, -2, "Ҳָߡ"); +} + +int NPC_Lua_Char_DelHcItem(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemId = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if( TM_ItemId < 9 || TM_ItemId > 23){ + LRetErrInt(_NLL, -2, "Ҳָĵλá"); + } + else { + CHAR_DelItem( TM_Index, TM_ItemId); + LRetInt(_NLL, 1); + } +} + +int NPC_Lua_Char_GETFM(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_ID = (int)lua_tointeger(_NLL, 1); + int TM_X = (int)lua_tointeger(_NLL, 2); + LRetInt(_NLL, Char_GetFm( TM_ID, TM_X)); +} + +int NPC_Lua_Char_FindPetEnemyBaseId(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EnemyId = (int)lua_tointeger(_NLL, 2); + int TM_PetIndex = -1; + int i = 0; + int petid = -1; + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int enemynum = ENEMY_getEnemyNum(); + for( i = 0; i < enemynum; i ++ ) + { + if (TM_EnemyId == ENEMY_getInt( i, ENEMY_ID )){ + petid = ENEMY_getInt( i, ENEMY_TEMPNO ); + break; + } + } + + for( i = 0 ; i 63) LRetErrInt(_NLL, -1, "Чġ"); + + if (RIDEPET_getPETID( TM_Index, RidNo) >= 0) + { + LRetBool(_NLL, TRUE); + }else LRetBool(_NLL, FALSE); +} +*/ +int NPC_Lua_Char_GetPetOwner(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if( CHAR_getInt( TM_Index, CHAR_WHICHTYPE ) != CHAR_TYPEPET ){ + LRetErrInt(_NLL, -2, "Ķ󲢲dz"); + } + int charaindex = CHAR_getWorkInt(TM_Index, CHAR_WORKPLAYERINDEX); + LRetInt(_NLL, charaindex); +} + +int NPC_Lua_Char_GetEnemyBaseIdFromEnemyId(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int EnemyId = (int)lua_tointeger(_NLL, 1); + int enemynum = ENEMY_getEnemyNum(); + int petid = -1; + int i; + for( i = 0; i < enemynum; i ++ ) + { + if (EnemyId == ENEMY_getInt( i, ENEMY_ID )){ + petid = ENEMY_getInt( i, ENEMY_TEMPNO ); + break; + } + } + if (i == enemynum) LRetErrInt(_NLL, -1, "enemyIDûҵ"); + + LRetInt(_NLL, petid); +} + +int NPC_Lua_Char_GetEnemyIdFromEnemyBaseId(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int EnemybaseId = (int)lua_tointeger(_NLL, 1); + int enemynum = ENEMY_getEnemyNum(); + int EnemyId = -1; + int i; + for( i = 0; i < enemynum; i ++ ) + { + if (EnemybaseId == ENEMY_getInt( i, ENEMY_TEMPNO )){ + EnemyId = ENEMY_getInt( i, ENEMY_ID ); + break; + } + } + if (i == enemynum) LRetErrInt(_NLL, -1, "enemybaseIDûҵ"); + + LRetInt(_NLL, EnemyId); +} + +int NPC_Lua_Char_GetIp(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if( CHAR_getInt( TM_Index, CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ){ + LRetErrInt(_NLL, -2, "Ķ󲢲"); + } + int fd = getfdFromCharaIndex( TM_Index ); + if( fd == -1 ){ + LRetErrInt(_NLL, -2, "Ѿߣ"); + } + if(TM_Flg == 1)//IP + { + LRetMsg(_NLL,CONNECT_get_userip2(fd)); + }else if(TM_Flg == 2)//FD + { + LRetInt(_NLL,fd); + }else if(TM_Flg == 3)//˿ + { + LRetInt(_NLL,CONNECT_get_userport(fd)); + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Char_SetAllocPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int petindex = (int)lua_tointeger(_NLL, 1); + int type = (int)lua_tointeger(_NLL, 2); + int val = (int)lua_tointeger(_NLL, 3); + if (val < 0 || val > 255) LRetErrInt(_NLL, -1, "valΪ0-255"); + if(!CHAR_CHECKINDEX(petindex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if( CHAR_getInt( petindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + LRetErrInt(_NLL, -2, "Ķ"); + } + int LevelUpPoint = CHAR_getInt( petindex, CHAR_ALLOCPOINT ); + int t = (int )(( LevelUpPoint >> 24 ) & 0xFF); + int g = (int )(( LevelUpPoint >> 16 ) & 0xFF); + int f = (int )(( LevelUpPoint >> 8 ) & 0xFF); + int m = (int )(( LevelUpPoint >> 0 ) & 0xFF); + + if (type == 1) { + LevelUpPoint = (val<<24)+(g<<16)+(f<<8)+(m<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + LRetInt(_NLL, t); + } + else if (type == 2) { + LevelUpPoint = (t<<24)+(val<<16)+(f<<8)+(m<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + LRetInt(_NLL, g); + } + else if (type == 3) { + LevelUpPoint = (t<<24)+(g<<16)+(val<<8)+(m<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + LRetInt(_NLL, f); + } + else if (type == 4) { + LevelUpPoint = (t<<24)+(g<<16)+(f<<8)+(val<<0); + CHAR_setInt( petindex, CHAR_ALLOCPOINT, LevelUpPoint); + LRetInt(_NLL, m); + } +} + +int NPC_Lua_Char_GetMaxPetIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 0); + int MAXPLAYER = CHAR_getPlayerMaxNum(); + int MAXPET = CHAR_getPetMaxNum(); + int maxindex = MAXPLAYER + MAXPET; + LRetInt(_NLL, maxindex); +} + +int NPC_Lua_Char_GetMaxPlayerIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 0); + int maxindex = CHAR_getPlayerMaxNum(); + LRetInt(_NLL, maxindex); +} + +int NPC_Lua_Char_SavePetToString(lua_State *_NLL) +{ + char *petdata = "\0"; + CheckEx(_NLL, 1); + int petindex = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(petindex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if( CHAR_getInt( petindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ){ + LRetErrInt(_NLL, -2, "Ķ"); + return; + } + petdata = CHAR_makePetStringFromPetIndex( petindex); + LRetMsg(_NLL, petdata); +} + +int NPC_Lua_Char_LoadPetFromString(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + char * petdata = (char *)lua_tostring(_NLL, 1); + Char petone; + int petindex; + BOOL ret = CHAR_makePetFromStringToArg(petdata,&petone, 0); + if( ret == TRUE ){ + petindex = PET_initCharOneArray( &petone ); + if( petindex < 0 ){ + LRetErrInt(_NLL, -2, "ʧ"); + return; + } + } + LRetInt(_NLL, petindex); +} + +int NPC_Lua_Char_GetPlayerFromAccAndName(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + char *account = lua_tostring(_NLL, 1); + char *name = lua_tostring(_NLL, 2); + int i; + int playernum = CHAR_getPlayerMaxNum(); + int xindex = -1; + for( i = 0 ; i < playernum ; i++) { + if( CHAR_CHECKINDEX(i) ){ + if (strcmp(CHAR_getChar(i,CHAR_NAME), name) == 0) { + xindex = i; + break; + } + if (strcmp(CHAR_getChar(i,CHAR_CDKEY), account) == 0) { + xindex = i; + break; + } + } + } + + LRetInt(_NLL, xindex); +} + +int NPC_Lua_Char_CheckPet(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + BOOL CHECK = CHAR_CHECKINDEX(TM_Index); + LRetBool(_NLL, CHECK); +} + +int NPC_Lua_Char_CheckPlayer(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + BOOL CHECK = CHAR_CHECKINDEX(TM_Index); + LRetBool(_NLL, CHECK); +} + +BOOL NPC_Lua_Char_JoinParty(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 2); + int charaindex = (int)lua_tointeger(_NLL, 1); + int toindex = (int)lua_tointeger(_NLL, 2); + if (CHAR_CHECKINDEX(charaindex)&&CHAR_CHECKINDEX(toindex)) + { + CHAR_JoinParty_Main( charaindex, toindex); + LRetBool(_NLL, TRUE); + } + LRetBool(_NLL, FALSE); +} + +int NPC_Lua_Char_getFamilyPlayIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 3); + int charaindex = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(charaindex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int familyindex = (int)lua_tointeger(_NLL, 1); + int familymode = (int)lua_tointeger(_NLL, 2); + int familycharaindex = (int)lua_tointeger(_NLL, 3); + if(familyindex > FAMILY_MAXNUM){ + LRetErrInt(_NLL, -1, "ļЧġ"); + }else if (familymode > FAMILY_MAXCHANNEL) + { + LRetErrInt(_NLL, -1, "ļƵЧġ"); + }else if (familycharaindex > FAMILY_MAXMEMBER) + { + LRetErrInt(_NLL, -1, "ļЧ"); + } + int playindex = channelMember[familyindex][familymode][familycharaindex]; + LRetInt(_NLL,playindex); +} + +int NPC_Lua_Char_logout(lua_State *_NLL){ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int charaindex = (int)lua_tointeger(_NLL, 1); + CHAR_logout(charaindex, TRUE); + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_Char_GetVipPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_vippoint(CHAR_getUseID(TM_Index),0,0); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Char_SetVipPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_NUM = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_vippoint(CHAR_getChar(TM_Index,CHAR_CDKEY),TM_NUM,1); + LRetInt(_NLL, TM_Ret); +} + + +int NPC_Lua_Char_GetAmPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_ampoint(CHAR_getUseID(TM_Index),0,0); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Char_GetRmbPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_rmbpoint(CHAR_getUseID(TM_Index),0,0); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Char_SetRmbPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_NUM = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_rmbpoint(CHAR_getChar(TM_Index,CHAR_CDKEY),TM_NUM,1); + LRetInt(_NLL, TM_Ret); +} + + + + +int NPC_Lua_Char_SetAmPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_NUM = (int)lua_tointeger(_NLL, 2); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + int TM_Ret = sasql_ampoint(CHAR_getChar(TM_Index,CHAR_CDKEY),TM_NUM,1); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Char_CheckItemIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + BOOL CHECK = ITEM_CHECKINDEX(TM_Index); + LRetBool(_NLL, CHECK); +} + +int NPC_Lua_Char_GetfdFromCharaIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int charaindex = (int)lua_tointeger(_NLL, 1); + LRetInt(_NLL, getfdFromCharaIndex(charaindex)); +} + +int NPC_Lua_Char_CharRidNo(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int RidNo = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + if (RidNo < 0 || RidNo > 95) LRetErrInt(_NLL, -1, "Чġ"); + + if (CHAR_CheckLearnCode( TM_Index, RidNo) >= 0) + { + LRetBool(_NLL, TRUE); + }else LRetBool(_NLL, FALSE); +} + +#endif //#ifdef _JZ_NEWSCRIPT_LUA diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_ex.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_ex.c new file mode 100644 index 0000000..3337753 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_ex.c @@ -0,0 +1,371 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" + +#ifdef _JZ_NEWSCRIPT_LUA + +extern char M_OutErrMsg[1024]; +extern lua_State *M_Script_Lua; +extern unsigned int M_Create_Num; + +////////////////////////////////////////////////////////////////////////////// +int NPC_Lua_RegCallEx(lua_State * _NLL, luaL_Reg *_RegList) +{ + assert(_RegList != NULL && _NLL != NULL); + + int i = 0; + if((_NLL != NULL) && (_RegList != NULL)) + { + while(_RegList->func != NULL) + { + lua_register(_NLL, _RegList->name, _RegList->func); + i++; + _RegList++; + } + } + return i; +} + +int NPC_Lua_RegLibEx(lua_State * _NLL, PSCRIPTREGLIB _RegLib) +{ + assert(_RegLib != NULL && _NLL != NULL); + + int i = 0; + if((_NLL != NULL) && (_RegLib != NULL)) + { + while(_RegLib->LibName != NULL) + { + luaL_openlib(_NLL, _RegLib->LibName, _RegLib->FuncRegList, 0); + i++; + _RegLib++; + } + } + return i; +} + +int NPC_Lua_RegClassEx(lua_State * _NLL, PSCRIPTREGCLASS _RegClass) +{ + assert(_RegClass != NULL && _NLL != NULL); + + int i = 0; + if((_NLL != NULL) && (_RegClass != NULL)) + { + while(_RegClass->ClassName != NULL) + { + luaL_newmetatable(_NLL, _RegClass->ClassName); + + lua_pushstring(_NLL, "__index"); + lua_pushvalue(_NLL, -2); + lua_settable(_NLL, -3); + + luaL_openlib(_NLL, NULL, _RegClass->FuncRegList, 0); + + luaL_openlib(_NLL, _RegClass->NewLib , _RegClass->NewLib->FuncRegList, 0); + + i++; + _RegClass++; + } + } + return i; +} + +int NPC_Lua_RegArrayEx(lua_State * _NLL, PSCRIPTREGARRAY _RegArray) +{ + assert(_RegArray != NULL && _NLL != NULL); + + int i = 0; + if((_NLL != NULL) && (_RegArray != NULL)) + { + int j = 0; + while(_RegArray->ArrayName != NULL) + { + luaL_newmetatable(_NLL, _RegArray->ArrayName); + luaL_openlib(_NLL, _RegArray->FuncList->LibName, _RegArray->FuncList->FuncRegList, 0); + + j = 0; + while(_RegArray->SetMetaTable[j] != NULL) + { + lua_pushstring(_NLL, _RegArray->SetMetaTable[j]); + lua_pushstring(_NLL, _RegArray->SetFuncName[j]); + lua_gettable(_NLL, 2); + lua_settable(_NLL, 1); + j++; + } + i++; + _RegArray++; + } + } + return i; +} + +const char *NPC_Lua_SetErrorStr(const char *ErrStr) +{ + if(ErrStr == NULL) + { + M_OutErrMsg[0] = '\0'; + return M_OutErrMsg; + } + return (const char *)strcpy_s(M_OutErrMsg, sizeof(M_OutErrMsg), ErrStr); +} + +//NPC-NPCΨһ +int NPC_Lua_Create(const char *_DoFile, const char *_InitFuncName, char *_seek, BOOL _IsFly) +{ + assert(_InitFuncName != NULL); + + Char TM_char; + Object TM_obj; + int TM_charaindex; + int TM_objindex; + int TM_seekint = 0; + + //ָĬֵTM_char + if(_seek == NULL) + { + TM_seekint = CHAR_seekGraphicNumberFromString("\0"); + }else + { + TM_seekint = CHAR_seekGraphicNumberFromString(_seek); + } + + if( CHAR_getDefaultChar( &TM_char, TM_seekint) == FALSE ) + { + LRetErrInt(M_Script_Lua, -1, "Ĭֵʧܡڲܲ"); + } + + //ָLUAűļ + if(_DoFile != NULL && _DoFile[0]) + { + if (NPC_Lua_DoFile(_DoFile) == 1){ +#ifdef _LUA_Debug + pcall_callback_err_fun(M_Script_Lua,_InitFuncName); +#endif + } + } + + //ָLUAűļ CAX +// NPC_Lua_DoFile(_DoFile); + //ȡýűжijʼָ + lua_getglobal(M_Script_Lua, _InitFuncName); + + if(lua_type(M_Script_Lua, -1) != LUA_TFUNCTION) + { + print("NPC_Lua_Create err: ޷ȡʼָ롣\n"); + lua_pop(M_Script_Lua, 1); + LRetErrInt(M_Script_Lua, -2, "޷ȡʼָ롣"); + }else + { + //溯ָ + lua_pop(M_Script_Lua, 1); + strcpy_s(TM_char.lua_charfunctable[CHAR_INITFUNC].string, sizeof(TM_char.lua_charfunctable[CHAR_INITFUNC].string), _InitFuncName); + strcpy_s(TM_char.charfunctable[CHAR_INITFUNC].string, sizeof(TM_char.charfunctable[CHAR_INITFUNC].string), FUNCNAME_INITCALLBACK); + } + TM_char.data[CHAR_FLOOR] = 777; + TM_char.data[CHAR_X] = 31; + TM_char.data[CHAR_Y] = 19; + TM_char.data[CHAR_DIR] = 4; + TM_char.string[CHAR_NAME].string[0] = '\0'; + TM_char.data[CHAR_BASEBASEIMAGENUMBER] = TM_char.data[CHAR_BASEIMAGENUMBER] = 0; +#ifdef _ADD_ACTION + TM_char.data[CHAR_ACTIONSTYLE] = CHAR_ACTSTAND; +#endif + TM_char.data[CHAR_FMINDEX] = -1; + TM_char.string[CHAR_NPCARGUMENT].string[0] = '\0'; + // + TM_char.data[CHAR_WHICHTYPE] = CHAR_LUANPC; + //ʶNPCNPC_Lua_CreateNPCţĿǰûʲô + TM_char.data[CHAR_NPCCREATEINDEX] = M_Create_Num++; + + //ʵTM_char ֮NPCʵݲ + TM_charaindex = CHAR_initCharOneArray( &TM_char ); + if( TM_charaindex == -1 ) + { + CHAR_endCharData( &TM_char ); + LRetErrInt(M_Script_Lua, -3, "޷ʵNPCݡ"); + } + + CHAR_setInt(TM_charaindex, CHAR_INDEXOFEQTITLE, -1); + CHAR_setWorkInt( TM_charaindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_NONE); + + //ͼ־Ŀǰ֪ã + if(_IsFly == TRUE) + { + CHAR_setFlg(TM_charaindex, CHAR_ISFLYING, 1); + } + + TM_obj.type = OBJTYPE_CHARA; // + TM_obj.index= TM_charaindex; //ӦChar + TM_obj.x = CHAR_getInt(TM_charaindex, CHAR_X); //ڵͼX + TM_obj.y = CHAR_getInt(TM_charaindex, CHAR_Y); //ڵͼY + TM_obj.floor = CHAR_getInt(TM_charaindex, CHAR_FLOOR);//ڵͼ + TM_objindex = initObjectOne( &TM_obj ); //һʵ֮NPCʵ + if( TM_objindex == -1 ) + { + CHAR_endCharOneArray( TM_charaindex ); + LRetErrInt(M_Script_Lua, -4, "޷ʵNPC"); + } + + CHAR_setWorkInt(TM_charaindex, CHAR_WORKOBJINDEX, TM_objindex); + +#ifdef _ADD_ACTION + //NPCĶ + CHAR_setWorkInt(TM_charaindex, CHAR_WORKACTION, CHAR_getInt( TM_charaindex, CHAR_ACTIONSTYLE ) ); + + CHAR_sendWatchEvent(TM_objindex, CHAR_getWorkInt( TM_charaindex, CHAR_WORKACTION), NULL, 0, TRUE); +#else + CHAR_sendWatchEvent(TM_objindex , CHAR_ACTSTAND, NULL, 0, TRUE); +#endif + CHAR_setWorkInt(TM_charaindex,CHAR_WORKNPCTYPE,2); + LRetInt(M_Script_Lua, TM_charaindex); +} + +//ɾNPC NPCΨһ +int NPC_Lua_Del(int _index) +{ + if (CHAR_getInt( _index, CHAR_WHICHTYPE )== CHAR_LUANPC) + { + int TM_Objindex = CHAR_getWorkInt( _index,CHAR_WORKOBJINDEX); + if(CHECKOBJECTUSE(TM_Objindex) == TRUE) + { + CHAR_ObjectDelete(TM_Objindex); + CHAR_endCharOneArray(_index); + return 1; + }else + { + CHAR_endCharOneArray(_index); + return 0; + } + } +} + +int NPC_Lua_GetFuncPoint(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, LUA_MINSTACK); + char *TM_DoFile = lua_tostring(_NLL, 1); + char *TM_FuncName = lua_tostring(_NLL, 2); + + if(TM_DoFile != NULL) + { + if(TM_DoFile[0]){ + if (NPC_Lua_DoFile(TM_DoFile) == 1){ +#ifdef _LUA_Debug + pcall_callback_err_fun(M_Script_Lua,TM_FuncName); +#endif + } + } + } + + if(TM_FuncName == NULL) + { + LRetErrInt(_NLL , -1, "Ϊ"); + } + + lua_getglobal(_NLL, TM_FuncName); + + if(lua_type(_NLL, -1) != LUA_TFUNCTION) + { + LRetErrInt(_NLL , -2, "޷ȡָ롣"); + } + LRetInt(_NLL, 1); +} +////////////////////////////////////////////////////////////////////////////// +//չͽӿں +//NTInt +int NPC_Lua_NTInt_New(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + + int TM_Len = luaL_checkint(_NLL, 1); + if(TM_Len <= 0) + { + LRetErrInt(_NLL, -1, "СΪ0"); + } + + size_t TM_Bytes = sizeof(size_t) + ( sizeof(int) * TM_Len ); + PARRAY_NTINT TM_Point = (PARRAY_NTINT *)lua_newuserdata(_NLL, TM_Bytes); + + if(TM_Point == NULL) + { + LRetErrInt(_NLL, -2, "ʵʧܣڴ档"); + } + + luaL_getmetatable(_NLL, "Array.NTInt"); + lua_setmetatable(_NLL, -2); + + TM_Point->Size = TM_Len; + + LRet(1); +} + +int NPC_Lua_NTInt_Get(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + + PARRAY_NTINT TM_Point = luaL_checkudata(_NLL, 1, "Array.NTInt"); + + if(TM_Point == NULL) + { + luaL_argerror(_NLL, 1, " Array.NTInt ݡ"); + } + + int TM_Index = (int)lua_tointeger(_NLL, 2); + + if(TM_Index < 1 || TM_Index > TM_Point->Size) + { + luaL_argerror(_NLL, 1, "ݷΧ"); + } + + TM_Index--; + + LRetInt(_NLL, TM_Point->Num[TM_Index]); +} + +int NPC_Lua_NTInt_Set(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + + PARRAY_NTINT TM_Point = luaL_checkudata(_NLL, 1, "Array.NTInt"); + + if(TM_Point == NULL) + { + luaL_argerror(_NLL, 1, " Array.NTInt ݡ"); + } + + int TM_Index = (int)lua_tointeger(_NLL, 2); + + if(TM_Index < 1 || TM_Index > TM_Point->Size) + { + luaL_argerror(_NLL, 1, "ݷΧ"); + } + TM_Index--; + + int TM_Num = (int)lua_tointeger(_NLL, 3); + + TM_Point->Num[TM_Index] = TM_Num; + + LRetNull(_NLL); +} + +int NPC_Lua_NTInt_Len(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + + PARRAY_NTINT TM_Point = luaL_checkudata(_NLL, 1, "Array.NTInt"); + + if(TM_Point == NULL) + { + luaL_argerror(_NLL, 1, " Array.NTInt ݡ"); + } + + LRetInt(_NLL, TM_Point->Size); +} + +#endif //#ifdef _JZ_NEWSCRIPT_LUA diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_game.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_game.c new file mode 100644 index 0000000..27824fa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_game.c @@ -0,0 +1,110 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "char_data.h" +#include "anim_tbl.h" +#include "object.h" +#include "battle.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" +#include "saacproto_cli.h" +#include "family.h" + +int NPC_Lua_Game_FMPOINT_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int GA_Index = (int)lua_tointeger(_NLL, 1); + int GA_Flg = (int)lua_tointeger(_NLL, 2); + + if(GA_Flg >= 0) + { + if(GA_Flg < LUA_DATALINE1) + { + GA_Flg -= LUA_DATALINE0; + char *GA_RetInt = FM_getManorData(GA_Index, GA_Flg); + LRetInt(_NLL, atoi(GA_RetInt)); + }else if(GA_Flg < LUA_DATALINE2) + { + GA_Flg -= LUA_DATALINE1; + char *GA_RetPoint = FM_getManorData(GA_Index, GA_Flg); + LRetMsg(_NLL, GA_RetPoint); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Game_FMPOINT_ACSetFMPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 5); + CheckIndexNull(_NLL, 1); + int leaderindex = (int)lua_tointeger(_NLL, 1); + int fmpointindex = (int)lua_tointeger(_NLL, 2); + int map = (int)lua_tointeger(_NLL, 3); + int x = (int)lua_tointeger(_NLL, 4); + int y = (int)lua_tointeger(_NLL, 5); + if(!CHAR_CHECKINDEX(leaderindex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + if (fmpointindex < 0 || fmpointindex > 9) + { + LRetErrInt(_NLL, -1, "ׯ԰Чġ"); + } + int fd = getfdFromCharaIndex( leaderindex ); + if( fd == -1 ){ + LRetErrInt(_NLL, -2, "ҿѾߣ"); + } + char *tmpbuf = ""; + sprintf(tmpbuf, "%d|%d|%d|%d|%d|",leaderindex,fmpointindex,map,x,y); + FAMILY_SetPoint(fd,leaderindex,tmpbuf); + LRetInt(_NLL, 0); +} + +int NPC_Lua_Game_FMPOINT_ACFixFMPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int winindex = (int)lua_tointeger(_NLL, 1); + int loseindex = (int)lua_tointeger(_NLL, 2); + int id = (int)lua_tointeger(_NLL, 3); + if(!CHAR_CHECKINDEX(winindex) || !CHAR_CHECKINDEX(loseindex)) + { + LRetErrNull(_NLL, "Чġ"); + } + if (id < 0 || id > 9) + { + LRetErrNull(_NLL, "ׯ԰Чġ"); + } +if(CHAR_getInt( winindex, CHAR_FMLEADERFLAG ) != FMMEMBER_LEADER)//峤 + { + LRetErrNull(_NLL, "󲢲峤"); + } +if(CHAR_getInt( loseindex, CHAR_FMLEADERFLAG ) != FMMEMBER_LEADER)//峤 + { + LRetErrNull(_NLL, "󲢲峤"); + } + saacproto_ACFixFMPoint_send(acfd, CHAR_getChar(winindex,CHAR_FMNAME),CHAR_getInt(winindex,CHAR_FMINDEX) + 1,CHAR_getInt(winindex,CHAR_FMINDEX), + CHAR_getChar(loseindex,CHAR_FMNAME),CHAR_getInt(loseindex,CHAR_FMINDEX) + 1,CHAR_getInt(loseindex,CHAR_FMINDEX),id); + LRetInt(_NLL, 0); +} +/* +int NPC_Lua_Game_FMPOINT_ACCleanFMPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int id = (int)lua_tointeger(_NLL, 1); + if (id < 0 || id > 9) + { + LRetErrNull(_NLL, "ׯ԰Чġ"); + } + saacproto_ACDelFmPoint_send(acfd,id); + LRetInt(_NLL, 0); +} +*/ + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_item.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_item.c new file mode 100644 index 0000000..4a425c8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_item.c @@ -0,0 +1,681 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" +#include "item.h" + +#ifdef _JZ_NEWSCRIPT_LUA + +typedef enum +{ + LUAITEM_PREOVERFUNC = ITEM_PREOVERFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_POSTOVERFUNC = ITEM_POSTOVERFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_WATCHFUNC = ITEM_WATCHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_USEFUNC = ITEM_USEFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_ATTACHFUNC = ITEM_ATTACHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_DETACHFUNC = ITEM_DETACHFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_DROPFUNC = ITEM_DROPFUNC - ITEM_FIRSTFUNCTION, + LUAITEM_PICKUPFUNC = ITEM_PICKUPFUNC - ITEM_FIRSTFUNCTION, +#ifdef _Item_ReLifeAct + LUAITEM_DIERELIFEFUNC = ITEM_DIERELIFEFUNC - ITEM_FIRSTFUNCTION, +#endif +}LUAITEM_FUNC; + +//ȡݵĽӿ +int NPC_Lua_Item_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckItemIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + int TM_RetInt = ITEM_getInt(TM_Index, TM_Flg); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_RetPoint = ITEM_getChar(TM_Index, TM_Flg); + LRetMsg(_NLL, TM_RetPoint); + }else if(TM_Flg < LUA_DATALINE3) + { + TM_Flg -= LUA_DATALINE2; + int TM_RetWorkInt = ITEM_getWorkInt(TM_Index, TM_Flg); + LRetInt(_NLL, TM_RetWorkInt); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +//ݵĽӿ +int NPC_Lua_Item_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + int TM_IntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = ITEM_setInt(TM_Index, TM_Flg, TM_IntVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_CharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = ITEM_setChar(TM_Index, TM_Flg, TM_CharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else if(TM_Flg < LUA_DATALINE3) + { + TM_Flg -= LUA_DATALINE2; + if(TM_Flg == ITEM_WORKOBJINDEX || TM_Flg == ITEM_WORKCHARAINDEX) + { + LRetInt(_NLL, 0); + } + int TM_WorkIntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = ITEM_setWorkInt(TM_Index, TM_Flg, TM_WorkIntVal); + LRetInt(_NLL, TM_RetInt); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +//¼õĽӿ +int NPC_Lua_Item_SetPreOverEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_PREOVERFUNC] != (void *)NPC_Lua_ItemPerOverCallBack) + { + if(TM_Item->functable[LUAITEM_PREOVERFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_PREOVERFUNC] = TM_Item->functable[LUAITEM_PREOVERFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_PREOVERFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_PREOVERFUNC].string), TM_Item->string[ITEM_PREOVERFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_PREOVERFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_PREOVERFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_PREOVERFUNC] = (void *)NPC_Lua_ItemPerOverCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_PREOVERFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_PREOVERFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_PREOVERFUNC].string, sizeof(TM_Item->string[ITEM_PREOVERFUNC].string), FUNCNAME_ITEMPEROVERCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_PREOVERFUNC] == (void *)NPC_Lua_ItemPerOverCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_PREOVERFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_PREOVERFUNC] == NULL) + { + TM_Item->functable[LUAITEM_PREOVERFUNC] = (void *)NULL; + TM_Item->string[ITEM_PREOVERFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_PREOVERFUNC] = TM_Item->sur_functable[LUAITEM_PREOVERFUNC]; + TM_Item->sur_functable[LUAITEM_PREOVERFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_PREOVERFUNC].string, sizeof(TM_Item->string[ITEM_PREOVERFUNC].string), TM_Item->sur_charfunctable[LUAITEM_PREOVERFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetPostOverEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_POSTOVERFUNC] != (void *)NPC_Lua_ItemPostOverCallBack) + { + if(TM_Item->functable[LUAITEM_POSTOVERFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_POSTOVERFUNC] = TM_Item->functable[LUAITEM_POSTOVERFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_POSTOVERFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_POSTOVERFUNC].string), TM_Item->string[ITEM_POSTOVERFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_POSTOVERFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_POSTOVERFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_POSTOVERFUNC] = (void *)NPC_Lua_ItemPostOverCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_POSTOVERFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_POSTOVERFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_POSTOVERFUNC].string, sizeof(TM_Item->string[ITEM_POSTOVERFUNC].string), FUNCNAME_ITEMPOSTOVERCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_POSTOVERFUNC] == (void *)NPC_Lua_ItemPostOverCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_POSTOVERFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_POSTOVERFUNC] == NULL) + { + TM_Item->functable[LUAITEM_POSTOVERFUNC] = (void *)NULL; + TM_Item->string[ITEM_POSTOVERFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_POSTOVERFUNC] = TM_Item->sur_functable[LUAITEM_POSTOVERFUNC]; + TM_Item->sur_functable[LUAITEM_POSTOVERFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_POSTOVERFUNC].string, sizeof(TM_Item->string[ITEM_POSTOVERFUNC].string), TM_Item->sur_charfunctable[LUAITEM_POSTOVERFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetWatchEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_WATCHFUNC] != (void *)NPC_Lua_ItemWatchCallBack) + { + if(TM_Item->functable[LUAITEM_WATCHFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_WATCHFUNC] = TM_Item->functable[LUAITEM_WATCHFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_WATCHFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_WATCHFUNC].string), TM_Item->string[ITEM_WATCHFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_WATCHFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_WATCHFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_WATCHFUNC] = (void *)NPC_Lua_ItemWatchCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_WATCHFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_WATCHFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_WATCHFUNC].string, sizeof(TM_Item->string[ITEM_WATCHFUNC].string), FUNCNAME_ITEMWATCHCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_WATCHFUNC] == (void *)NPC_Lua_ItemWatchCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_WATCHFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_WATCHFUNC] == NULL) + { + TM_Item->functable[LUAITEM_WATCHFUNC] = (void *)NULL; + TM_Item->string[ITEM_WATCHFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_WATCHFUNC] = TM_Item->sur_functable[LUAITEM_WATCHFUNC]; + TM_Item->sur_functable[LUAITEM_WATCHFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_WATCHFUNC].string, sizeof(TM_Item->string[ITEM_WATCHFUNC].string), TM_Item->sur_charfunctable[LUAITEM_WATCHFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetUseEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_USEFUNC] != (void *)NPC_Lua_ItemUseCallBack) + { + if(TM_Item->functable[LUAITEM_USEFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_USEFUNC] = TM_Item->functable[LUAITEM_USEFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string), TM_Item->string[ITEM_USEFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_USEFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_USEFUNC] = (void *)NPC_Lua_ItemUseCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_USEFUNC].string, sizeof(TM_Item->string[ITEM_USEFUNC].string), FUNCNAME_ITEMUSECALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_USEFUNC] == (void *)NPC_Lua_ItemUseCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_USEFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_USEFUNC] == NULL) + { + TM_Item->functable[LUAITEM_USEFUNC] = (void *)NULL; + TM_Item->string[ITEM_USEFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_USEFUNC] = TM_Item->sur_functable[LUAITEM_USEFUNC]; + TM_Item->sur_functable[LUAITEM_USEFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_USEFUNC].string, sizeof(TM_Item->string[ITEM_USEFUNC].string), TM_Item->sur_charfunctable[LUAITEM_USEFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetAttachEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_ATTACHFUNC] != (void *)NPC_Lua_ItemAttachCallBack) + { + if(TM_Item->functable[LUAITEM_ATTACHFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_ATTACHFUNC] = TM_Item->functable[LUAITEM_ATTACHFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_ATTACHFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_ATTACHFUNC].string), TM_Item->string[ITEM_ATTACHFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_ATTACHFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_ATTACHFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_ATTACHFUNC] = (void *)NPC_Lua_ItemAttachCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_ATTACHFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_ATTACHFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_ATTACHFUNC].string, sizeof(TM_Item->string[ITEM_ATTACHFUNC].string), FUNCNAME_ITEMATTACHCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_ATTACHFUNC] == (void *)NPC_Lua_ItemAttachCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_ATTACHFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_ATTACHFUNC] == NULL) + { + TM_Item->functable[LUAITEM_ATTACHFUNC] = (void *)NULL; + TM_Item->string[ITEM_ATTACHFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_ATTACHFUNC] = TM_Item->sur_functable[LUAITEM_ATTACHFUNC]; + TM_Item->sur_functable[LUAITEM_ATTACHFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_ATTACHFUNC].string, sizeof(TM_Item->string[ITEM_ATTACHFUNC].string), TM_Item->sur_charfunctable[LUAITEM_ATTACHFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetDetachEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_DETACHFUNC] != (void *)NPC_Lua_ItemDetachCallBack) + { + if(TM_Item->functable[LUAITEM_DETACHFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_DETACHFUNC] = TM_Item->functable[LUAITEM_DETACHFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_DETACHFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_DETACHFUNC].string), TM_Item->string[ITEM_DETACHFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_DETACHFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_DETACHFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_DETACHFUNC] = (void *)NPC_Lua_ItemDetachCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_DETACHFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_DETACHFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_DETACHFUNC].string, sizeof(TM_Item->string[ITEM_DETACHFUNC].string), FUNCNAME_ITEMDETACHCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_DETACHFUNC] == (void *)NPC_Lua_ItemDetachCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_DETACHFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_DETACHFUNC] == NULL) + { + TM_Item->functable[LUAITEM_DETACHFUNC] = (void *)NULL; + TM_Item->string[ITEM_DETACHFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_DETACHFUNC] = TM_Item->sur_functable[LUAITEM_DETACHFUNC]; + TM_Item->sur_functable[LUAITEM_DETACHFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_DETACHFUNC].string, sizeof(TM_Item->string[ITEM_DETACHFUNC].string), TM_Item->sur_charfunctable[LUAITEM_DETACHFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetDropEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_DROPFUNC] != (void *)NPC_Lua_ItemDropCallBack) + { + if(TM_Item->functable[LUAITEM_DROPFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_DROPFUNC] = TM_Item->functable[LUAITEM_DROPFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_DROPFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_DROPFUNC].string), TM_Item->string[ITEM_DROPFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_DROPFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_DROPFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_DROPFUNC] = (void *)NPC_Lua_ItemDropCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_DROPFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_DROPFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_DROPFUNC].string, sizeof(TM_Item->string[ITEM_DROPFUNC].string), FUNCNAME_ITEMDROPCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_DROPFUNC] == (void *)NPC_Lua_ItemDropCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_DROPFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_DROPFUNC] == NULL) + { + TM_Item->functable[LUAITEM_DROPFUNC] = (void *)NULL; + TM_Item->string[ITEM_DROPFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_DROPFUNC] = TM_Item->sur_functable[LUAITEM_DROPFUNC]; + TM_Item->sur_functable[LUAITEM_DROPFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_DROPFUNC].string, sizeof(TM_Item->string[ITEM_DROPFUNC].string), TM_Item->sur_charfunctable[LUAITEM_DROPFUNC].string); + } + } + } + return TM_Ret; +} + +int NPC_Lua_Item_SetPickUPEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_PICKUPFUNC] != (void *)NPC_Lua_ItemPickUPCallBack) + { + if(TM_Item->functable[LUAITEM_PICKUPFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_PICKUPFUNC] = TM_Item->functable[LUAITEM_PICKUPFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_PICKUPFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_PICKUPFUNC].string), TM_Item->string[ITEM_PICKUPFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_PICKUPFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_PICKUPFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_PICKUPFUNC] = (void *)NPC_Lua_ItemPickUPCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_PICKUPFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_PICKUPFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_PICKUPFUNC].string, sizeof(TM_Item->string[ITEM_PICKUPFUNC].string), FUNCNAME_ITEMPICKUPCALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_PICKUPFUNC] == (void *)NPC_Lua_ItemPickUPCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_PICKUPFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_PICKUPFUNC] == NULL) + { + TM_Item->functable[LUAITEM_PICKUPFUNC] = (void *)NULL; + TM_Item->string[ITEM_PICKUPFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_PICKUPFUNC] = TM_Item->sur_functable[LUAITEM_PICKUPFUNC]; + TM_Item->sur_functable[LUAITEM_PICKUPFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_PICKUPFUNC].string, sizeof(TM_Item->string[ITEM_PICKUPFUNC].string), TM_Item->sur_charfunctable[LUAITEM_PICKUPFUNC].string); + } + } + } + return TM_Ret; +} + +#ifdef _Item_ReLifeAct +int NPC_Lua_Item_SetDieReLifeEvent(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 3); + int TM_index = (int)lua_tointeger(_NLL, 3); + + ITEM_Item *TM_Item = ITEM_getItemPointer(TM_index); + + if(TM_Item == NULL) + { + LRetErrInt(_NLL , -1, "Чġ"); + } + int TM_Ret = NPC_Lua_GetFuncPoint(_NLL); + + if(lua_tointeger(_NLL, -1) > 0) + { + if(TM_Item->functable[LUAITEM_DIERELIFEFUNC] != (void *)NPC_Lua_ItemDieReLifeCallBack) + { + if(TM_Item->functable[LUAITEM_DIERELIFEFUNC] != NULL) + { + TM_Item->sur_functable[LUAITEM_DIERELIFEFUNC] = TM_Item->functable[LUAITEM_DIERELIFEFUNC]; + strcpy_s(TM_Item->sur_charfunctable[LUAITEM_DIERELIFEFUNC].string, sizeof(TM_Item->sur_charfunctable[LUAITEM_DIERELIFEFUNC].string), TM_Item->string[ITEM_DIERELIFEFUNC].string); + }else + { + TM_Item->sur_functable[LUAITEM_DIERELIFEFUNC] = (void *)NULL; + TM_Item->sur_charfunctable[LUAITEM_DIERELIFEFUNC].string[0] = '\0'; + } + + TM_Item->functable[LUAITEM_DIERELIFEFUNC] = (void *)NPC_Lua_ItemDieReLifeCallBack; + strcpy_s(TM_Item->lua_charfunctable[LUAITEM_DIERELIFEFUNC].string, sizeof(TM_Item->lua_charfunctable[LUAITEM_DIERELIFEFUNC].string), lua_tostring(_NLL, 2)); + strcpy_s(TM_Item->string[ITEM_DIERELIFEFUNC].string, sizeof(TM_Item->string[ITEM_DIERELIFEFUNC].string), FUNCNAME_ITEMDIERELIFECALLBACK); + } + }else + { + if(TM_Item->functable[LUAITEM_DIERELIFEFUNC] == (void *)NPC_Lua_ItemDieReLifeCallBack) + { + TM_Item->lua_charfunctable[LUAITEM_DIERELIFEFUNC].string[0] = '\0'; + if(TM_Item->sur_functable[LUAITEM_DIERELIFEFUNC] == NULL) + { + TM_Item->functable[LUAITEM_DIERELIFEFUNC] = (void *)NULL; + TM_Item->string[ITEM_DIERELIFEFUNC].string[0] = '\0'; + }else + { + TM_Item->functable[LUAITEM_DIERELIFEFUNC] = TM_Item->sur_functable[LUAITEM_DIERELIFEFUNC]; + TM_Item->sur_functable[LUAITEM_DIERELIFEFUNC] = (void *)NULL; + strcpy_s(TM_Item->string[ITEM_DIERELIFEFUNC].string, sizeof(TM_Item->string[ITEM_DIERELIFEFUNC].string), TM_Item->sur_charfunctable[LUAITEM_DIERELIFEFUNC].string); + } + } + } + return TM_Ret; +} +#endif + +int NPC_Lua_Item_GetDataFromItemSet(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + int TM_ID = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + if( !ITEM_CHECKITEMTABLE( TM_ID) ) + { + LRetErrInt(_NLL , -1, "ĵIDЧġ"); + } + if (TM_Flg 0 ) { + if( map_type >= 0 ) { // map_type >= 0 Ȼؼ¼ + if( map == map_type && map >= 0 ) {//ؼ¼ + }else { + maparray[0] = (point>>16)&0xffffff; + maparray[1] = (point>>8)&0xff; + maparray[2] = (point>>0)&0xff; + } + } + } + else if( map == 10032 ){ + maparray[0] = 10030; + maparray[1] = 52; + maparray[2] = 36; + } +#ifdef _MAP_TIME + else if (map >= 30017 && map >= 30021) + { + maparray[0]= 30008; + maparray[1] = 39; + maparray[2] = 39; + } +#endif + else { + maparray[0] = map; + maparray[1] = 0; + maparray[2] = 0; + } + LRetArray(_NLL,maparray,arraysizeof(maparray)); +} + +int NPC_Lua_Map_GetfloorX(lua_State *_NLL) //ȡͼX +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int x; + x = MAP_getfloorX(map); + LRetInt(_NLL, x); +} + +int NPC_Lua_Map_GetfloorY(lua_State *_NLL) //ȡͼY +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int y; + y = MAP_getfloorX(map); + LRetInt(_NLL, y); +} + +int NPC_Lua_Map_GetTileAndObjId(lua_State *_NLL) //ȡͼijĵذװβ +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int x = (int)lua_tointeger(_NLL, 2); + int y = (int)lua_tointeger(_NLL, 3); + int *tile = -1, *obj = -1; + MAP_getTileAndObjData(map,x,y,&tile,&obj); + int maparray[2]; + maparray[0]=tile; + maparray[1]=obj; + LRetArray(_NLL,maparray,arraysizeof(maparray)); +} + +int NPC_Lua_Map_SetTileAndObjId(lua_State *_NLL) //õͼijĵذװβ +{ + CheckEx(_NLL, 5); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int x = (int)lua_tointeger(_NLL, 2); + int y = (int)lua_tointeger(_NLL, 3); + int tile = (int)lua_tointeger(_NLL, 4); + int obj = (int)lua_tointeger(_NLL, 5); + if (MAP_setTileAndObjData(map,x,y,tile,obj)) LRetInt(_NLL, 0); + LRetInt(_NLL, -1); +} + +int NPC_Lua_Map_GetWalkAbleFromPoint(lua_State *_NLL) //ȡijǷ +{ + CheckEx2(_NLL, 3,4); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int map = (int)lua_tointeger(_NLL, 1); + int x = (int)lua_tointeger(_NLL, 2); + int y = (int)lua_tointeger(_NLL, 3); + BOOL IsFly = FALSE; + if(TM_Top==4){ + IsFly = (BOOL)lua_toboolean(_NLL, 4); + } + IsFly = MAP_walkAbleFromPoint(map,x,y,IsFly); + LRetBool(_NLL, IsFly); +} + +int NPC_Lua_Map_GetImageData(lua_State *_NLL) //ȡͼƬ +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int MapImageid = (int)lua_tointeger(_NLL, 1); + int flg = (int)lua_tointeger(_NLL, 2); + if(flg >= 0) + { + if(flg < LUA_DATALINE1) + { + flg -= LUA_DATALINE0; + int TM_RetInt = MAP_getImageInt(MapImageid, flg); + LRetInt(_NLL, TM_RetInt); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} +int NPC_Lua_Map_SetImageData(lua_State *_NLL) //ͼƬ +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int MapImageid = (int)lua_tointeger(_NLL, 1); + int flg = (int)lua_tointeger(_NLL, 2); + int val = (int)lua_tointeger(_NLL, 3); + if(flg >= 0) + { + if(flg < LUA_DATALINE1) + { + flg -= LUA_DATALINE0; + BOOL TM_RetBool = MAP_setImageInt(MapImageid, flg, val); + LRetBool(_NLL, TM_RetBool); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} +static OBJECT TM_Object = NULL; +int NPC_Lua_Map_GetTopObj(lua_State *_NLL) //ȡͼij϶ +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int x = (int)lua_tointeger(_NLL, 2); + int y = (int)lua_tointeger(_NLL, 3); + TM_Object = MAP_getTopObj( map, x, y) ; + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_Map_GetNextObj(lua_State *_NLL) //ȡһ +{ + CheckEx(_NLL, 0); + int TM_ObjIndex = GET_OBJINDEX(TM_Object); + TM_Object = NEXT_OBJECT(TM_Object); + if( !CHECKOBJECTUSE(TM_ObjIndex) ) + { + LRetInt(_NLL, -1); + TM_Object = NULL; + } + LRetInt(_NLL, TM_ObjIndex); +} + +int NPC_Lua_Map_CheckImageIndex(lua_State *_NLL) //ijͼͼƬǷ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + BOOL TM_Ret = IsValidImagenumber( map) ; + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Map_CheckIndex(lua_State *_NLL) //ijͼŵͼǷ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + BOOL TM_Ret = CHECKFLOORID( map) ; + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Map_MakeNewMap(lua_State *_NLL) //һͼµͼ +{ + CheckEx2(_NLL, 1, 2); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int map = (int)lua_tointeger(_NLL, 1); + char *name = ""; + if(TM_Top == 2) + { + CheckIndexNull(_NLL, 2); + name = lua_tostring(_NLL, 2); + } + int TM_Ret = MAP_makenew( map,name) ; + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Map_DelNewMap(lua_State *_NLL) //ɾһͼ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + BOOL TM_Ret = MAP_DelMap( map) ; + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Map_SetExWarp(lua_State *_NLL) //һͼ˳͵ +{ + CheckEx(_NLL, 5); + CheckIndexNull(_NLL, 1); + int map = (int)lua_tointeger(_NLL, 1); + int exfl = (int)lua_tointeger(_NLL, 2); + int exx = (int)lua_tointeger(_NLL, 3); + int exy = (int)lua_tointeger(_NLL, 4); + int type = (int)lua_tointeger(_NLL, 4);//ͼ + BOOL TM_Ret = MAP_SetExWarp( map, exfl,exx,exy,type) ; + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Map_SetMapPoint(lua_State *_NLL) //һͼ͵ һ͵ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + char* mappoint = lua_tostring(_NLL, 1); + int TM_Ret = SetMapPoint( mappoint) ; + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Map_DelMapPoint(lua_State *_NLL) //ɾһ͵ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int ps = (int)lua_tointeger(_NLL, 1); + BOOL TM_Ret = DelMapPoint( ps) ; + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_Map_getFloorName(lua_State *_NLL) //һͼ +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int MapID = (int)lua_tointeger(_NLL, 1); + char *MapName = MAP_getFloorName( MapID) ; + LRetMsg(_NLL, MapName); +} +/* +int NPC_Lua_Map_Upmap(lua_State *_NLL) //µͼ +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int formatmap = (int)lua_tointeger(_NLL, 2); + int tomap = (int)lua_tointeger(_NLL, 3); + lssproto_Upmap_send(TM_Index,formatmap,tomap); + LRetBool(_NLL, TRUE); +} +*/ + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nl.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nl.c new file mode 100644 index 0000000..6b59eb3 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nl.c @@ -0,0 +1,666 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" +#include +#include +#include "autil.h" +#include "configfile.h" +#include "enemy.h" + +#ifdef _JZ_NEWSCRIPT_LUA + +extern char M_OutErrMsg[1024]; +extern lua_State *M_Script_Lua; +extern unsigned int M_Create_Num; +static char Buff_Data[1024*64]; +static int Check_Num=0; + + +////////////////////////////////////////////////////////////////////////////// +int NPC_Lua_NL_GetErrorStr(lua_State *_NLL) +{ + CheckEx(_NLL, 0); + + LRetMsg(_NLL, M_OutErrMsg); +} + +BOOL NPC_Lua_NL_Mod(lua_State *_NLL) +{ + CheckEx2(_NLL, 1, 2); + int num = (int)lua_tointeger(_NLL, 1); + int num2 = 2; + int TM_Top = lua_gettop(_NLL); + if (TM_Top == 2) + { + int num2 = (int)lua_tointeger(_NLL, 2); + } + if(num%num2==0) + { + LRetBool(_NLL,TRUE); + } + else + { + LRetBool(_NLL,FALSE); + } +} + +BOOL NPC_Lua_CheckNpcEventFree(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + char *TM_NpcStr = lua_tostring(_NLL, 3); + int TM_NPCindex = (int)lua_tointeger(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 2); + char magicname[256]; + int i = 1; + BOOL ret; + BOOL ret1; + while (TRUE) { + ret = getStringFromIndexWithDelim( TM_NpcStr, "|", i, magicname, sizeof( magicname)); + if (!ret) + { + ret = getStringFromIndexWithDelim( TM_NpcStr, "/", i, magicname, sizeof( magicname)); + if (!ret) + { + ret = getStringFromIndexWithDelim( TM_NpcStr, "\\", i, magicname, sizeof( magicname)); + if (!ret) + { + break; + } + } + } + ret1 = ActionNpc_CheckFree(TM_NPCindex,TM_index,magicname); + if (!ret1) + { + break; + } + i +=1; + } + LRetBool(_NLL, ret1); +} + +BOOL NPC_Lua_DoNpcEventAction(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + char *TM_NpcStr = lua_tostring(_NLL, 3); + int TM_NPCindex = (int)lua_tointeger(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 2); + char magicname[256]; + int i = 1; + BOOL ret; + BOOL ret1; + while (TRUE) { + ret = getStringFromIndexWithDelim( TM_NpcStr, "|", i, magicname, sizeof( magicname)); + if (!ret) + { + ret = getStringFromIndexWithDelim( TM_NpcStr, "/", i, magicname, sizeof( magicname)); + if (!ret) + { + ret = getStringFromIndexWithDelim( TM_NpcStr, "\\", i, magicname, sizeof( magicname)); + if (!ret) + { + break; + } + } + } + ret1 = Action_RunDoEventAction(TM_NPCindex,TM_index,magicname); + i +=1; + } + LRetBool(_NLL, ret1); +} + + +int NPC_Lua_NL_CreateNpc(lua_State *_NLL) +{ + //4 + CheckEx2(_NLL, 2, 4); + char *TM_DoFile = lua_tostring(_NLL, 1); + char *TM_InitFuncName = lua_tostring(_NLL, 2); + BOOL TM_IsFly = FALSE; + char *TM_seek = NULL; + int TM_Top = lua_gettop(_NLL); + + if(TM_Top >= 3) + { + TM_IsFly = (BOOL)lua_toboolean(_NLL, 3); + } + if(TM_Top == 4) + { + TM_seek = lua_tostring(_NLL, 4); + } + + int TM_Ret = NPC_Lua_Create(TM_DoFile, TM_InitFuncName, TM_seek, TM_IsFly); + + LRet(TM_Ret); +} + + +int NPC_Lua_NL_DelNpc(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_Ret = NPC_Lua_Del(TM_index); + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NL_GetStringFromIndexWithDelim(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + char* string = (char*)lua_tostring(_NLL, 1); + char* delim = (char*)lua_tostring(_NLL, 2); + int index = (int)lua_tointeger(_NLL, 3); + char token[128]; + getStringFromIndexWithDelim( string,delim,index,token,sizeof(token)); + LRetMsg(_NLL,token); +} + +BOOL NPC_Lua_NL_ANSI_PlayerLoop(lua_State *_NLL) +{ + CheckEx2(_NLL,0, 1); + int i; + static int indexn = 0; + int TM_Top = lua_gettop(_NLL); + BOOL TM_IsFly = FALSE; + if(TM_Top >= 1) + { + TM_IsFly = (BOOL)lua_toboolean(_NLL, 1); + } + if (TM_IsFly){ + indexn = 0; + LRetBool(_NLL, TRUE); + return; + } + int playernum = CHAR_getPlayerMaxNum(); + for( i = indexn ; i < playernum ; i++) { + if( CHAR_CHECKINDEX(i) ){ + indexn++; + LRetInt(_NLL, i); + break; + } + } + LRetInt(_NLL, -1); +} + +BOOL NPC_Lua_NL_ANSI_PetLoop(lua_State *_NLL) +{ + CheckEx2(_NLL,0, 1); + int i; + int MAXPLAYER = CHAR_getPlayerMaxNum(); + int MAXPET = CHAR_getPetMaxNum(); + static int indexn = 0; + int TM_Top = lua_gettop(_NLL); + BOOL TM_IsFly = FALSE; + if(TM_Top >= 1) + { + TM_IsFly = (BOOL)lua_toboolean(_NLL, 1); + } + if (TM_IsFly){ + indexn = MAXPLAYER; + LRetBool(_NLL, TRUE); + return; + } + + for( i = indexn ; i < MAXPLAYER+MAXPET ; i++) { + if( CHAR_CHECKINDEX(i) ){ + indexn++; + LRetInt(_NLL, i); + break; + } + } + LRetInt(_NLL, -1); +} + + + +BOOL NPC_Lua_NL_ANSI_ItemLoop(lua_State *_NLL) +{ + CheckEx2(_NLL,0, 1); + int i; + static int indexn = 0; + int TM_Top = lua_gettop(_NLL); + BOOL TM_IsFly = FALSE; + if(TM_Top >= 1) + { + TM_IsFly = (BOOL)lua_toboolean(_NLL, 1); + } + if (TM_IsFly){ + indexn = 0; + LRetBool(_NLL, TRUE); + return; + } + int itemnum = ITEM_getITEM_itemnum(); + for( i = indexn ; i < itemnum ; i++) { + if( ITEM_CHECKINDEX(i) ){ + indexn++; + LRetInt(_NLL, i); + break; + } + } + LRetInt(_NLL, -1); +} + +BOOL NPC_Lua_NL_PetLoopGetNext(lua_State *_NLL) +{ + int MAXPLAYER = CHAR_getPlayerMaxNum(); + int MAXPET = CHAR_getPetMaxNum(); + + CheckEx(_NLL, 1); + int i; + char *TM_FuncName = lua_tostring(_NLL, 1); + char TM_RetBuff[128]; + + for( i = MAXPLAYER ; i < MAXPLAYER+MAXPET ; i++) { + if( CHAR_CHECKINDEX(i) ){ + NPC_Lua_CallFunc(TM_FuncName, &TM_RetBuff, sizeof(TM_RetBuff), i); + } + } + LRetBool(_NLL, TRUE); + +} + +int NPC_Lua_NL_ItemLoopGetNext(lua_State *_NLL) +{ + int itemnum = ITEM_getITEM_itemnum(); + CheckEx(_NLL, 1); + int i; + char *TM_FuncName = lua_tostring(_NLL, 1); + char TM_RetBuff[128]; + + for( i = 0 ; i < itemnum ; i++) { + if( ITEM_CHECKINDEX(i) ){ + NPC_Lua_CallFunc(TM_FuncName, &TM_RetBuff, sizeof(TM_RetBuff), i); + } + } + LRetBool(_NLL, TRUE); + +} + +BOOL NPC_Lua_NL_PlayerLoopGetNext(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int i; + char *TM_FuncName = lua_tostring(_NLL, 1); + char TM_RetBuff[128]; + int playernum = CHAR_getPlayerMaxNum(); + for( i = 0 ; i < playernum ; i++) { + if( CHAR_CHECKINDEX(i) ){ + NPC_Lua_CallFunc(TM_FuncName, &TM_RetBuff, sizeof(TM_RetBuff), i); + } + } + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NL_GetConfigLineType(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int i; + char *TM_ConfigName = lua_tostring(_NLL, 1); + int TM_Type = GetConfigLineType(TM_ConfigName); + LRetInt(_NLL, TM_Type); +} + +int NPC_Lua_NL_GetConfigLineVal(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int i; + char *TM_ConfigName = lua_tostring(_NLL, 1); + char *TM_RETMSG = GetConfigLineVal(TM_ConfigName); + LRetMsg(_NLL, TM_RETMSG); +} + +int NPC_Lua_NL_SetTimer(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + int i; + char *TM_FileName = lua_tostring(_NLL, 1); + char *TM_FuncName = lua_tostring(_NLL, 2); + unsigned int EspTime = (int)lua_tointeger(_NLL, 3); + int Timer_s = SetTimer_net(TM_FileName,TM_FuncName,EspTime); + LRetInt(_NLL, Timer_s); +} + +int NPC_Lua_NL_DelTimer(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int ID = (int)lua_tointeger(_NLL, 1); + BOOL TM_Ret = DelTimer_net(ID); + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NL_RunSaFuncII(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + char *TM_FuncName = lua_tostring(_NLL, 1); + int i1 = (int)lua_tointeger(_NLL, 2); + int i2 = (int)lua_tointeger(_NLL, 3); + typedef void (*GMSVFUNC)(int,int); + GMSVFUNC atf; + atf=(GMSVFUNC)(void*)TM_FuncName; + if( atf ) + atf( i1,i2 ); +} + +int NPC_Lua_NL_RunSaFuncIII(lua_State *_NLL) +{ + CheckEx(_NLL, 4); + CheckIndexNull(_NLL, 1); + char *TM_FuncName = lua_tostring(_NLL, 1); + int i1 = (int)lua_tointeger(_NLL, 2); + int i2 = (int)lua_tointeger(_NLL, 3); + int i3 = (int)lua_tointeger(_NLL, 3); + typedef void (*GMSVFUNC)(int,int,int); + GMSVFUNC atf; + atf=(GMSVFUNC)(void*) TM_FuncName; + if( atf ) + atf( i1,i2,i3); +} + +int NPC_Lua_NL_ClsMk(lua_State *_NLL) +{ + Check_Num=0; + memset(Buff_Data,0,sizeof(Buff_Data)); + LRetInt(_NLL, 1); +} + +int NPC_Lua_NL_AddCheckNum(lua_State *_NLL) +{ + + CheckEx(_NLL,1); + CheckIndexNull(_NLL, 1); + int i = (int)lua_tointeger(_NLL, 1); + Check_Num += i; + LRetInt(_NLL, Check_Num); +} + + +int NPC_Lua_NL_Mkstring(lua_State *_NLL) +{ + + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int fd = getfdFromCharaIndex(TM_index ); + char *TM_data = lua_tostring(_NLL, 2); + int checknum=0; + checknum = util_mkstring(Buff_Data, TM_data); + LRetInt(_NLL, checknum); +} + +int NPC_Lua_NL_Mkint(lua_State *_NLL) +{ + + CheckEx(_NLL,2); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int fd = getfdFromCharaIndex(TM_index ); + int i = (int)lua_tointeger(_NLL, 2); + int checknum=util_mkint(Buff_Data, i); + LRetInt(_NLL, checknum); +} + +int NPC_Lua_NL_SendMesg(lua_State *_NLL) +{ + + CheckEx(_NLL,2); + CheckIndexNull(_NLL, 1); + int charaindex = (int)lua_tointeger(_NLL, 1); + int fengbaohao = (int)lua_tointeger(_NLL, 2); + int fd = getfdFromCharaIndex(charaindex ); + util_SendMesg(fd, fengbaohao, Buff_Data); + LRetInt(_NLL, 1); + +} +int NPC_Lua_NL_SetCharSignDay(lua_State *_NLL) +{ + + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int a = (int)lua_tointeger(_NLL, 1); + int b = (int)lua_tointeger(_NLL, 2); + a|=(1<= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; + if (isdigit(uchar(*p))) p++; + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; + if (isdigit(uchar(*p))) p++; + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} +int NPC_Lua_NL_Print(lua_State *L) +{ + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); + else { + char form[MAX_FORMAT]; + char buff[MAX_ITEM]; + memset(form,0,MAX_FORMAT); + memset(buff,0,MAX_ITEM); + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + mj_sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + mj_sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + mj_sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + mj_sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; + } + else { + mj_sprintf(buff, form, s); + break; + } + } + default: { + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + print(b.buffer); + return 1; +} +int NPC_Lua_NL_CreateSpecialNpc(lua_State *L) +{ + Char one; + size_t l; + CHAR_getDefaultChar( &one, 0); + one.data[CHAR_WHICHTYPE] = CHAR_TYPELUANPC; + char *Name = luaL_checklstring(L, 1, &l); + const int Image = luaL_checkinteger(L, 2); + const int Floor = luaL_checkinteger(L, 3); + const int x = luaL_checkinteger(L, 4); + const int y = luaL_checkinteger(L, 5); + const int dir = luaL_checkinteger(L, 6); + const int enemyid = luaL_checkint(L, 7); + const int UpLevel = luaL_checkinteger(L, 8); + int i; + for( i = 0; i < ENEMY_getEnemyNum(); i ++ ) { + if( ENEMY_getInt( i, ENEMY_ID) == enemyid) { + break; + } + } + if( i == ENEMY_getEnemyNum() ){ + lua_pushinteger(L, -1); + return 1; + } + + int npcindex = ENEMY_createEnemy( i, 0); + if( npcindex < 0 ) { + print( "NPCʧܡ\n"); + } + CHAR_setInt(npcindex, CHAR_WHICHTYPE, CHAR_TYPEPLAYERNPC); + CHAR_setChar(npcindex, CHAR_NAME, Name); + CHAR_setInt(npcindex, CHAR_BASEBASEIMAGENUMBER, Image); + CHAR_setInt(npcindex, CHAR_BASEIMAGENUMBER, Image); + CHAR_setInt(npcindex, CHAR_FLOOR, Floor); + CHAR_setInt(npcindex, CHAR_X, x); + CHAR_setInt(npcindex, CHAR_Y, y); + CHAR_setInt(npcindex, CHAR_DIR, dir); + + CHAR_setInt(npcindex, CHAR_MODAI, 10000); + CHAR_setInt(npcindex, CHAR_VARIABLEAI,10000); + + for( i = 0; i < UpLevel; i ++ ){ + CHAR_PetLevelUp( npcindex ); + CHAR_PetAddVariableAi( npcindex, AI_FIX_PETLEVELUP ); + } + CHAR_complianceParameter( npcindex ); + CHAR_setInt( npcindex, CHAR_HP, CHAR_getWorkInt( npcindex, CHAR_WORKMAXHP )); + Object object; + int objindex; + + object.type = OBJTYPE_CHARA; + object.index = npcindex; + object.x =CHAR_getInt(npcindex, CHAR_X); + object.y = CHAR_getInt(npcindex, CHAR_Y); + object.floor = CHAR_getInt(npcindex, CHAR_FLOOR); + + objindex = initObjectOne( &object ); + + if( objindex == -1 ) { + CHAR_endCharOneArray( npcindex ); + }else { + CHAR_setWorkInt( npcindex,CHAR_WORKOBJINDEX, objindex ); + CHAR_LoginBesideSetWorkInt( npcindex, -1 ); + } + + lua_pushinteger(L, npcindex); + return 1; +} +int NPC_Lua_NL_getGameservername(lua_State *_NLL) +{ + char* name = getGameservername(); + LRetMsg(_NLL, name); +} + +#endif //#ifdef _JZ_NEWSCRIPT_LUA + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nlg.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nlg.c new file mode 100644 index 0000000..467ccf9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_nlg.c @@ -0,0 +1,1682 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" +#include "configfile.h" + +#ifdef _JZ_NEWSCRIPT_LUA +extern int StateTable[]; + +////////////////////////////////////////////////////////////////////////////// +//ܽӿ +int NPC_Lua_NLG_CheckInFront(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_SurIndex = (int)lua_tointeger(_NLL, 1); + int TM_DesIndex = (int)lua_tointeger(_NLL, 2); + int TM_Distance = (int)lua_tointeger(_NLL, 3); + + BOOL TM_Ret = NPC_Util_charIsInFrontOfChar(TM_SurIndex, TM_DesIndex, TM_Distance); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_CheckObj(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + int TM_Floor = (int)lua_tointeger(_NLL, 1); + int TM_X = (int)lua_tointeger(_NLL, 2); + int TM_Y = (int)lua_tointeger(_NLL, 3); + int TM_ObjIndex = -1; + OBJECT TM_Object = NULL; + + for( TM_Object = MAP_getTopObj( TM_Floor, TM_X, TM_Y) ; TM_Object != NULL ; TM_Object = NEXT_OBJECT(TM_Object)) + { + TM_ObjIndex = GET_OBJINDEX(TM_Object); + if( !CHECKOBJECTUSE(TM_ObjIndex) ) + { + continue; + } + LRetInt(_NLL, 1); + } + LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_CharLook(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_DIR = (int)lua_tointeger(_NLL, 2); + CHAR_Look(TM_Index, TM_DIR); + LRetNull(_NLL); +} + +int NPC_Lua_NLG_CreateBattle(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 7); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Top = lua_gettop(_NLL); + int TM_i = 0; + int TM_Flg = 0; + + CREATEENEMY TM_CreateEnemy[BATTLE_ENTRY_MAX]; + int TM_ArLen = 0; + + memset(&TM_CreateEnemy, NULL, sizeof(TM_CreateEnemy)); + + int TM_CharIndex = (int)lua_tointeger(_NLL, 1); + int TM_NpcIndex = (int)lua_tointeger(_NLL, 2); + char *TM_DoFunc = NULL; + + if(TM_Top >= 3) + { + TM_DoFunc = lua_tostring(_NLL, 3); + } + + if(TM_Top >= 5) + { + TM_ArLen = luaL_getn(_NLL, 5); + TM_ArLen = min(TM_ArLen, BATTLE_ENTRY_MAX); + for(TM_i = 1; TM_i <= TM_ArLen; TM_i++) + { + lua_rawgeti(_NLL, 5, TM_i); + TM_CreateEnemy[TM_i - 1].BaseLevel = (int)lua_tointeger(_NLL, -1); + lua_pop(_NLL, 1); + } + } + + if(TM_Top >= 6) + { + TM_ArLen = luaL_getn(_NLL, 6); + TM_ArLen = min(TM_ArLen, BATTLE_ENTRY_MAX); + for(TM_i = 1; TM_i <= TM_ArLen; TM_i++) + { + lua_rawgeti(_NLL, 6, TM_i); + TM_CreateEnemy[TM_i - 1].SkillType = (int)lua_tointeger(_NLL, -1); + lua_pop(_NLL, 1); + } + } + if(TM_Top >= 7) + { + TM_Flg = (int)lua_tointeger(_NLL, 7); + } +//Ҫ + if(TM_Top >= 4) + { + TM_ArLen = luaL_getn(_NLL, 4); + TM_ArLen = min(TM_ArLen, BATTLE_ENTRY_MAX); + for(TM_i = 1; TM_i <= TM_ArLen; TM_i++) + { + lua_rawgeti(_NLL, 4, TM_i); + TM_CreateEnemy[TM_i - 1].EnemyId = ENEMY_getEnemyArrayFromId((int)lua_tointeger(_NLL, -1)); + lua_pop(_NLL, 1); + } + } +//Ȼٵôսĺ + int TM_Ret = NPC_Lua_CreateVsEnemy(_NLL, TM_CharIndex, TM_NpcIndex, TM_DoFunc, &TM_CreateEnemy, TM_ArLen, TM_Flg); +//ظʾʧ + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_DelPet(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_PetID = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_PetIndex = -1; + int TM_Ret = 0; + int TM_Count = 0; + + if(lua_gettop(_NLL) == 3) + { + TM_Num = (int)lua_tointeger(_NLL, 3); + } + int i = 0; + for(i = 0; i < CHAR_MAXPETHAVE ; i++) + { + TM_PetIndex = CHAR_getCharPet( TM_Index, i); + + if(!CHAR_CHECKINDEX(TM_PetIndex)) + { + continue; + } + if(CHAR_getInt( TM_PetIndex, CHAR_PETID) != TM_PetID) + { + continue; + } + + TM_Ret = NPC_DelPet( TM_Index, i); + if(TM_Ret < 0) + { + char TM_MsgBuff[128]; + snprintf(TM_MsgBuff, sizeof(TM_MsgBuff), "ɾʱ : %d", TM_Ret); + LRetErrInt(_NLL , -1, TM_MsgBuff); + } + + TM_Count++; + if(TM_Count == TM_Num) + { + break; + } + } + LRetInt(_NLL, TM_Count); +} + +int NPC_Lua_NLG_DelHaveIndexPet(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_PetHaveIndex = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_PetIndex = -1; + int TM_Ret = 0; + + if(TM_PetHaveIndex<0 || TM_PetHaveIndex>4){ + LRetErrInt(_NLL, -1, "Чġ"); + } + TM_PetIndex = CHAR_getCharPet( TM_Index, TM_PetHaveIndex); + + if(!CHAR_CHECKINDEX(TM_PetIndex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + TM_Ret = NPC_DelPet( TM_Index, TM_PetHaveIndex); + if(TM_Ret < 0) + { + char TM_MsgBuff[128]; + snprintf(TM_MsgBuff, sizeof(TM_MsgBuff), "ɾʱ : %d", TM_Ret); + LRetErrInt(_NLL , -1, TM_MsgBuff); + } + + LRetInt(_NLL, 1); +} + +int NPC_Lua_NLG_DelItem(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemID = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + + if(lua_gettop(_NLL) == 3) + { + TM_Num = (int)lua_tointeger(_NLL, 3); + } + + BOOL TM_Ret = NPC_ActionDoPileDelItem(TM_Index, TM_ItemID, TM_Num); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_DelItemByPos(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemPos = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_ItemId= -1; + int TM_ItemIndex = -1; + int itemMax = CheckCharMaxItem(TM_Index); + if( TM_ItemPos < CHAR_STARTITEMARRAY || TM_ItemPos > itemMax -1 ) { + CHAR_talkToCli( TM_Index, -1, "λòȷ", CHAR_COLORWHITE); + return; + } + TM_ItemId = CHAR_getItemIndex(TM_Index, TM_ItemPos); + + if( TM_ItemId == -1 ) { + LRetBool(_NLL, FALSE); + } + TM_ItemIndex = CHAR_getItemIndex(TM_Index,TM_ItemPos); + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " 1 %s", ITEM_getChar( TM_ItemIndex, ITEM_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + CHAR_DelItem( TM_Index, TM_ItemPos); + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NLG_DischargeParty(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + BOOL TM_Ret = CHAR_DischargeParty( TM_index, 0); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_GivePet(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 4); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EnemyId = (int)lua_tointeger(_NLL, 2); + int TM_Level = -1; + int TM_Num = 1; + int TM_Count = 0; + int TM_PetIndex = -1; + int TM_Int = -1; + + if(lua_gettop(_NLL) >= 3) + { + TM_Level = (int)lua_tointeger(_NLL, 3); + } + + if(lua_gettop(_NLL) == 4) + { + TM_Num = (int)lua_tointeger(_NLL, 4); + } + if(TM_Num <= 0) + { + LRetErrInt(_NLL, -1, "ڵ0"); + } + int i = 0; + for(i = 0; i < TM_Num; i++) + { + TM_Int = NPC_GivePet(TM_Index, TM_Level, TM_EnemyId); + if(TM_Int < 0) + { + break; + } + TM_PetIndex = TM_Int; + TM_Count++; + } + if(TM_Count > 0) + { + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " %d ֻ %s", TM_Count, CHAR_getChar( TM_PetIndex, CHAR_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + } + LRetInt(_NLL, TM_Count); +} + +int NPC_Lua_NLG_GiveOnePet(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EnemyId = (int)lua_tointeger(_NLL, 2); + int TM_Level = -1; + int TM_PetIndex = -1; + + + if(lua_gettop(_NLL) >= 3) + { + TM_Level = (int)lua_tointeger(_NLL, 3); + } + TM_PetIndex = NPC_GivePet(TM_Index, TM_Level, TM_EnemyId); + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), "1ֻ %s", CHAR_getChar( TM_PetIndex, CHAR_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + LRetInt(_NLL, TM_PetIndex); +} + + +int NPC_Lua_NLG_GiveItem(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemId = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_ItemIndex = -1; + int TM_Int = -1; + int TM_Count = 0; + + if(lua_gettop(_NLL) == 3) + { + TM_Num = (int)lua_tointeger(_NLL, 3); + } + int i = 0; + for(i = 0; i < TM_Num; i++) + { + TM_Int = NPC_GiveItem( TM_Index, TM_ItemId); + if(TM_Int < 0) + { + break; + } + TM_ItemIndex = TM_Int; + TM_Count++; + } + if(TM_Count > 0) + { + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " %d %s", TM_Count, ITEM_getChar( TM_ItemIndex, ITEM_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + } + LRetInt(_NLL, TM_Count); +} + +int NPC_Lua_NLG_GiveOneItem(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemId = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_ItemIndex = -1; + + TM_ItemIndex = NPC_GiveItem( TM_Index, TM_ItemId); + if(TM_ItemIndex >= 0) + { + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " 1 %s", ITEM_getChar( TM_ItemIndex, ITEM_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + }else{ + LRetInt(_NLL, -1); + } + LRetInt(_NLL, TM_ItemIndex); +} + +int NPC_Lua_NLG_GiveRandItem(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + char *TM_ItemIdData = lua_tostring(_NLL, 2); + int TM_Num = 1; + int TM_ItemIndex = -1; + int TM_Int = -1; + int TM_Type = 0; + int TM_ItemId = -1; + if(lua_gettop(_NLL) == 3) + { + TM_Type = (int)lua_tointeger(_NLL, 3); + } + int TM_ItemIdStart = -1; + int TM_ItemIdEnd = -1; + char ItemIdBuf[32]; + if(getStringFromIndexWithDelim(TM_ItemIdData,",", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE){ + int TM_ItemNum = 0; + while(1){ + if(getStringFromIndexWithDelim(TM_ItemIdData,",", TM_ItemNum+1, ItemIdBuf, sizeof(ItemIdBuf)) == FALSE) + break; + TM_ItemNum++; + } + TM_ItemNum = RAND(1,TM_ItemNum); + getStringFromIndexWithDelim(TM_ItemIdData,",", TM_ItemNum, ItemIdBuf, sizeof(ItemIdBuf)); + char ItemIdBuf2[16]; + if( getStringFromIndexWithDelim(ItemIdBuf,"-", 2, ItemIdBuf2, sizeof(ItemIdBuf2)) != FALSE){ + int TM_ItemIdStart,TM_ItemIdEnd; + getStringFromIndexWithDelim(ItemIdBuf,"-", 1, ItemIdBuf2, sizeof(ItemIdBuf2)); + TM_ItemIdStart = atoi(ItemIdBuf2); + getStringFromIndexWithDelim(ItemIdBuf,"-", 2, ItemIdBuf2, sizeof(ItemIdBuf2)); + TM_ItemIdEnd = atoi(ItemIdBuf2); + TM_ItemId = RAND(TM_ItemIdStart,TM_ItemIdEnd); + }else{ + TM_ItemId = atoi(ItemIdBuf); + } + }else if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE){ + if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 1, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE) + TM_ItemIdStart = atoi(ItemIdBuf); + if(getStringFromIndexWithDelim(TM_ItemIdData,"-", 2, ItemIdBuf, sizeof(ItemIdBuf)) != FALSE) + TM_ItemIdEnd = atoi(ItemIdBuf); + if(TM_ItemIdStart<=TM_ItemIdEnd){ + TM_ItemId = RAND(TM_ItemIdStart,TM_ItemIdEnd); + } + }else{ + TM_ItemId = atoi(TM_ItemIdData); + } + if(TM_ItemId>-1){ + TM_Int = NPC_GiveItem( TM_Index, TM_ItemId); + } + if(TM_Int>=0){ + char TM_Buff[256]; + snprintf(TM_Buff, sizeof(TM_Buff), " %s", ITEM_getChar( TM_Int, ITEM_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); +/* if(TM_Type>0){ + time_t timep; + struct tm *p; + time(&timep); + p=localtime(&timep); + timep = mktime(p); + TM_Type = timep + TM_Type; + ITEM_setInt(TM_Int,ITEM_TIME,TM_Type); + sprintf(TM_Buff,"[ʱ]%s",ITEM_getChar(TM_Int,ITEM_NAME)); + ITEM_setChar(TM_Int,ITEM_NAME,TM_Buff); + ITEM_setChar(TM_Int,ITEM_SECRETNAME,TM_Buff); + CHAR_sendStatusString(TM_Index,"I"); +// timep = TM_Type; +// p=localtime(&timep); +// int year=1900+p->tm_year; +// int mon=1+p->tm_mon; +// int date=p->tm_mday; +// int hour=p->tm_hour; +// int min=p->tm_min; +// int sec=p->tm_sec; +// char monbuf[5],datebuf[5],hourbuf[5],minbuf[5],secbuf[5]; +// if(mon<10) sprintf(monbuf,"0%d",mon); +// else sprintf(monbuf,"%d",mon); +// if(date<10) sprintf(datebuf,"0%d",date); +// else sprintf(datebuf,"%d",date); +// if(hour<10) sprintf(hourbuf,"0%d",hour); +// else sprintf(hourbuf,"%d",hour); +// if(min<10) sprintf(minbuf,"0%d",min); +// else sprintf(minbuf,"%d",min); +// if(sec<10) sprintf(secbuf,"0%d",sec); +// else sprintf(secbuf,"%d",sec); +// sprintf(TM_Buff,"Ч:%d.%s.%s/%s:%s:%s %s",year,monbuf,datebuf,hourbuf,minbuf,secbuf,ITEM_getChar(TM_Int,ITEM_EFFECTSTRING)); +// ITEM_setChar(TM_Int,ITEM_EFFECTSTRING,TM_Buff); + }*/ + } + LRetInt(_NLL, TM_Int); +} + +int NPC_Lua_NLG_ShowWindowTalked(lua_State *_NLL) +{ + CheckEx2(_NLL, 5, 6); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_windowtype = (int)lua_tointeger(_NLL, 2); + int TM_buttontype = (int)lua_tointeger(_NLL, 3); + int TM_seqno = (int)lua_tointeger(_NLL, 4); + char *TM_data = lua_tostring(_NLL, 5); + + if(TM_data == NULL) + { + LRetErrInt(_NLL , -1, "ԻݲΪnil"); + } + + int TM_MeIndex = -1; + int TM_fd = getfdFromCharaIndex(TM_index); + + if(TM_Top == 6) + { + CheckIndexNull(_NLL, 6); + TM_MeIndex = (int)lua_tointeger(_NLL, 6); + } + + lssproto_WN_send(TM_fd, TM_windowtype, TM_buttontype, TM_seqno, CHAR_getWorkInt( TM_MeIndex, CHAR_WORKOBJINDEX), TM_data); + LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_SetAction(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Action = (int)lua_tointeger(_NLL, 2); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + CHAR_sendWatchEvent( CHAR_getWorkInt( TM_Index, CHAR_WORKOBJINDEX), TM_Action, NULL, 0,TRUE); + CHAR_setWorkInt( TM_Index, CHAR_WORKACTION, TM_Action); + + LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_TalkToCli(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 5); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int TM_toindex = (int)lua_tointeger(_NLL, 1); + char *TM_Msg = lua_tostring(_NLL, 2); + if(TM_Msg == NULL) + { + LRetErrInt(_NLL , -1, "˵ݲΪnil"); + } + + int TM_color = CHAR_COLORWHITE; + int TM_fontsize = 0; + int TM_Talkindex = -1; + + if(TM_Top >= 3) + { + TM_color = (int)lua_tointeger(_NLL, 3); + } + if(TM_Top >= 4) + { + TM_fontsize = (int)lua_tointeger(_NLL, 4); + } + if(TM_Top == 5) + { + CheckIndexNull(_NLL, 5); + TM_Talkindex = (int)lua_tointeger(_NLL, 5); + } + BOOL TM_Ret = FALSE; + + if(TM_toindex == -1) + { + //ȫ˵ + int TM_playernum = CHAR_getPlayerMaxNum(); + int i = 0; + + for( i = 0 ; i < TM_playernum ; i++) + { + if( CHAR_getCharUse(i) != FALSE ) + { + #ifdef _FONT_SIZE + TM_Ret |= CHAR_talkToCliExt( i, TM_Talkindex, TM_Msg, TM_color, TM_fontsize); + #else + TM_Ret |= CHAR_talkToCli( i, TM_Talkindex, TM_Msg, TM_color); + #endif + } + } + }else + { + //ָ˵ + #ifdef _FONT_SIZE + TM_Ret = CHAR_talkToCliExt(TM_toindex, TM_Talkindex, TM_Msg, TM_color, TM_fontsize); + #else + TM_Ret = CHAR_talkToCli(TM_toindex, TM_Talkindex, TM_Msg, TM_color); + #endif + } + if(TM_Ret == TRUE) + { + LRetInt(_NLL, 0); + }else + { + LRetErrInt(_NLL , -2, "δ֪ԭ·˵ʧܡ"); + } +} + +int NPC_Lua_NLG_TalkToFloor(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 5); + + int TM_Top = lua_gettop(_NLL); + int TM_floor = (int)lua_tointeger(_NLL, 1); + char *TM_Msg = lua_tostring(_NLL, 2); + if(TM_Msg == NULL) + { + LRetErrInt(_NLL , -1, "˵ݲΪnil"); + } + + int TM_color = CHAR_COLORWHITE; + int TM_fontsize = 0; + int TM_Talkindex = -1; + + if(TM_Top >= 3) + { + TM_color = (int)lua_tointeger(_NLL, 3); + } + if(TM_Top >= 4) + { + TM_fontsize = (int)lua_tointeger(_NLL, 4); + } + if(TM_Top == 5) + { + CheckIndexNull(_NLL, 5); + TM_Talkindex = (int)lua_tointeger(_NLL, 5); + } + //ָͼ˵ + BOOL TM_Ret = FALSE; + int TM_playernum = CHAR_getPlayerMaxNum(); + int i = 0; + + for( i = 0 ; i < TM_playernum ; i++) + { + if( CHAR_getCharUse(i) != FALSE ) + { + if (CHAR_getInt(i, CHAR_FLOOR) == TM_floor) + { + #ifdef _FONT_SIZE + TM_Ret |= CHAR_talkToCliExt( i, TM_Talkindex, TM_Msg, TM_color, TM_fontsize); + #else + TM_Ret |= CHAR_talkToCli( i, TM_Talkindex, TM_Msg, TM_color); + #endif + + } + } + } + + if(TM_Ret == TRUE) + { + LRetInt(_NLL, 0); + }else + { + LRetErrInt(_NLL , -2, "δ֪ԭ·˵ʧܡ"); + } +} + +int NPC_Lua_NLG_UpChar(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + CHAR_complianceParameter( TM_Index ); + + if(CHAR_getInt(TM_Index,CHAR_WHICHTYPE)==CHAR_TYPEPET){ + int playindex = CHAR_getWorkInt(TM_Index,CHAR_WORKPLAYERINDEX); + if(!CHAR_CHECKINDEX(playindex)){ + LRetErrInt(_NLL, -1, "Чġ"); + }else{ + int i; + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) { + int workindex = CHAR_getCharPet( playindex, i ); + if( workindex == TM_Index ){ + CHAR_send_K_StatusString( playindex, i, CHAR_K_STRING_BASEIMAGENUMBER| + CHAR_K_STRING_HP| + CHAR_K_STRING_MAXHP| + CHAR_K_STRING_MP| + CHAR_K_STRING_MAXMP| + CHAR_K_STRING_EXP| + CHAR_K_STRING_NEXTEXP| + CHAR_K_STRING_LV| + CHAR_K_STRING_ATK| + CHAR_K_STRING_DEF| + CHAR_K_STRING_QUICK| + CHAR_K_STRING_AI| + CHAR_K_STRING_EARTH| + CHAR_K_STRING_WATER| + CHAR_K_STRING_FIRE| + CHAR_K_STRING_WIND| + CHAR_K_STRING_SLOT| + CHAR_K_STRING_CHANGENAMEFLG| + CHAR_K_STRING_NAME| + CHAR_K_STRING_USERPETNAME); + char msgbuf[128]; + snprintf( msgbuf, sizeof( msgbuf ), "W%d",i); + CHAR_sendStatusString( playindex, msgbuf ); + CHAR_sendStatusString( playindex, "P"); + break; + } + } + } + }else if(CHAR_getInt(TM_Index,CHAR_WHICHTYPE)==CHAR_TYPEPLAYER){ + CHAR_send_P_StatusString( TM_Index, CHAR_P_STRING_GOLD|CHAR_P_STRING_CHARSINGMODE ); + } + + if(CHAR_getFlg(TM_Index, CHAR_ISVISIBLE) == FALSE) + { + int TM_objindex = CHAR_getWorkInt(TM_Index,CHAR_WORKOBJINDEX); + + CHAR_sendCDArroundChar + ( + OBJECT_getFloor(TM_objindex), + OBJECT_getX(TM_objindex), + OBJECT_getY(TM_objindex), + TM_objindex + ); + }else + { + CHAR_sendCToArroundCharacter( CHAR_getWorkInt( TM_Index , CHAR_WORKOBJINDEX )); + } + if(CHAR_getWorkInt( TM_Index ,CHAR_WORKPARTYMODE)==CHAR_PARTY_LEADER) + CHAR_sendLeader( CHAR_getWorkInt( TM_Index, CHAR_WORKOBJINDEX), 1); + LRetNull(_NLL); +} + +int NPC_Lua_NLG_Warp(lua_State *_NLL) +{ + CheckEx(_NLL, 4); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Floor = (int)lua_tointeger(_NLL, 2); + int TM_X = (int)lua_tointeger(_NLL, 3); + int TM_Y = (int)lua_tointeger(_NLL, 4); + + BOOL TM_Ret = CHAR_warpToSpecificPoint(TM_Index, TM_Floor, TM_X, TM_Y); + + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_WalkMove(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_DIR = (int)lua_tointeger(_NLL, 2); + + POINT start, end; + + end.x = CHAR_getInt( TM_Index, CHAR_X); + end.y = CHAR_getInt( TM_Index, CHAR_Y); + + int TM_Ret = (int)CHAR_walk(TM_Index, TM_DIR, 0); + + if( TM_Ret == CHAR_WALKSUCCESSED ) + { + int i; + int mefl=CHAR_getInt( TM_Index, CHAR_FLOOR); + int toindex = -1; + int fl = 0; + int xx = 0; + int yy = 0; + int parent_dir; + + for( i = 1; i < getPartyNum(TM_Index); i ++ ) + { + toindex = CHAR_getWorkInt( TM_Index, i + CHAR_WORKPARTYINDEX1); + fl = CHAR_getInt( toindex, CHAR_FLOOR); + xx = CHAR_getInt( toindex, CHAR_X); + yy = CHAR_getInt( toindex, CHAR_Y); + + if( CHAR_CHECKINDEX(toindex) && (mefl==fl) && (abs(xx-end.x)+abs(yy-end.y)<10) ) + { + + start.x = xx; + start.y = yy; + parent_dir = NPC_Util_getDirFromTwoPoint( &start,&end ); + + end.x = start.x; + end.y = start.y; + + if( parent_dir != -1 ) + { + CHAR_walk( toindex, parent_dir, 0); + } + } + } + } + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_WatchEntry(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ToIndex = (int)lua_tointeger(_NLL, 2); + if( BATTLE_WatchEntry(TM_Index, TM_ToIndex) == 0) + { + LRetInt(_NLL, 0); + }else + { + LRetInt(_NLL, -1); + } +} + +int NPC_Lua_Char_GetOnLinePlayer(lua_State *_NLL) +{ + CheckEx(_NLL, 0); + LRetInt(_NLL, abs(StateTable[LOGIN])); +} + +int NPC_Lua_NLG_UpStateBySecond(lua_State *_NLL) +{ + CheckEx2(_NLL, 1, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + char TM_Buff[128]; + int TM_fd = getfdFromCharaIndex(TM_Index); +#ifdef _SAF_MAKE + snprintf(TM_Buff, sizeof(TM_Buff), "FAME|%d|%d|%d", CHAR_getInt(TM_Index,CHAR_FAME)/100, (int)lua_tointeger(_NLL, 2), (int)lua_tointeger(_NLL, 3)); +#else + snprintf(TM_Buff, sizeof(TM_Buff), "FAME|%d", CHAR_getInt(TM_Index,CHAR_FAME)/100); +#endif + lssproto_S2_send(TM_fd,TM_Buff); + LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_UpStateByThird(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + BOOL TM_Ret = CHAR_send_P_StatusString(TM_Index, TM_Flg); + LRetBool(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_Update_Party(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + CHAR_PartyUpdate(TM_Index, TM_Flg); + LRetNull(_NLL); +} + +int NPC_Lua_NLG_CreateBattlePvP(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int TM_Index1 = (int)lua_tointeger(_NLL, 1); + int TM_Index2 = (int)lua_tointeger(_NLL, 2); + int TM_Ret = -1; + int TM_BattleIndex = -1; + + if( (CHAR_getInt( TM_Index2, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) || (CHAR_getInt( TM_Index1, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER)){ + LRetErrInt(_NLL, -1, "Ͳ"); + } + if( (CHAR_getWorkInt( TM_Index2, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) || (CHAR_getWorkInt( TM_Index1, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE)) + { + LRetErrInt(_NLL, -2, "ڶս"); + } + if( CHAR_getWorkInt( TM_Index2, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ) + { + int TM_Index = CHAR_getWorkInt( TM_Index2, CHAR_WORKPARTYINDEX1 ); + + if( TM_Index < 0 ) + { + LRetErrInt(_NLL, -3, "Ķ쳣"); + } + } + if( CHAR_getWorkInt( TM_Index1, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ) + { + int TM_Index = CHAR_getWorkInt( TM_Index1, CHAR_WORKPARTYINDEX1 ); + + if( TM_Index < 0 ) + { + LRetErrInt(_NLL, -3, "Ķ쳣"); + } + } + TM_Ret = NPC_Lua_CreateVsPlayer(&TM_BattleIndex, TM_Index1, TM_Index2); + if(TM_Ret != 0) + { + char TM_Buff[64]; + snprintf(TM_Buff, sizeof(TM_Buff), "ʧܣ:%d", TM_Ret); + LRetErrInt(_NLL, -4, TM_Buff); + } + LRetInt(_NLL, TM_BattleIndex); +} + +int NPC_Lua_NLG_SearchWatchBattleRandIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Floor = (int)lua_tointeger(_NLL, 2); + int TM_Ret = -1; + + if( (CHAR_getInt( TM_Index, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) ){ + LRetErrInt(_NLL, -1, "Ͳ"); + } + if( (CHAR_getWorkInt( TM_Index, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) ) + { + LRetErrInt(_NLL, -2, "ڶս"); + } + if( CHAR_getWorkInt( TM_Index, CHAR_WORKPARTYMODE ) == CHAR_PARTY_CLIENT ) + { + int TM_Index2 = CHAR_getWorkInt( TM_Index, CHAR_WORKPARTYINDEX1 ); + + if( TM_Index2 < 0 ) + { + LRetErrInt(_NLL, -3, "Ķ쳣"); + } + } + TM_Ret = SearchFmWarRandIndex(TM_Index, TM_Floor); + if(TM_Ret != 0) + { + char TM_Buff[64]; + snprintf(TM_Buff, sizeof(TM_Buff), "սɿ:%d", TM_Floor); + LRetErrInt(_NLL, -4, TM_Buff); + } + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_GetMaxPlayNum(lua_State *_NLL) +{ + int TM_playernum = CHAR_getPlayerMaxNum(); + LRetInt(_NLL, TM_playernum); +} + +int NPC_Lua_NLG_CheckPlayIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + LRetInt(_NLL, TM_Index); +} + +int NPC_Lua_NLG_Save(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if(!CHAR_CHECKINDEX(TM_Index)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + CHAR_charSaveFromConnect(TM_Index, FALSE); + LRetInt(_NLL, TM_Index); +} + +//////////////// add by Mo. +int NPC_Lua_NLG_SetExp(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int TM_Exp = (int)lua_tointeger(_NLL, 1); + if( TM_Exp <= 0 ) + { + LRetErrInt(_NLL, -3, ""); + } + setBattleexp(TM_Exp); + LRetNull(_NLL); +} + +int NPC_Lua_NLG_GetExp(lua_State *_NLL) +{ + int ret = getBattleexp(); + LRetInt(_NLL, ret); +} + +/* +int NPC_Lua_NLG_SetPetTransRange(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + + int TM_X = (int)lua_tointeger(_NLL, 1); + int TM_Y = (int)lua_tointeger(_NLL, 2); + int TM_Z = (int)lua_tointeger(_NLL, 3); + setPetTransRangeX(TM_X); + setPetTransRangeY(TM_Y); + setPetTransRangeZ(TM_Z); + LRetNull(_NLL); +} + + +int NPC_Lua_NLG_GetPetTransRange(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if (TM_Index == 1){ + int ret = getPetTransRangeX(); + LRetInt(_NLL, ret); + } + if (TM_Index == 2){ + int ret = getPetTransRangeY(); + LRetInt(_NLL, ret); + } + if (TM_Index == 3){ + int ret = getPetTransRangeZ(); + LRetInt(_NLL, ret); + } + LRetErrInt(_NLL, -1, "IJЧġ"); +} +*/ + +int NPC_Lua_NLG_InputCard(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + + int TM_Index1 = (int)lua_tointeger(_NLL, 1); + ITEM_OnlineCost(TM_Index1, -1, -1); + LRetNull(_NLL); +} + +int NPC_Lua_NLG_UpItem(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + + int charaindex = (int)lua_tointeger(_NLL,1); + if( !CHAR_CHECKINDEX( charaindex)){ + return 0; + } + int MAX = 27; + int i= 0; + for ( i = 0; i <= MAX; i++){ + CHAR_sendItemDataOne( charaindex, i); + } + return 0; +} + +int NPC_Lua_NLG_GivePetOne(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 4); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_EnemyId = (int)lua_tointeger(_NLL, 2); + int TM_Level = 1; + int TM_PetIndex = -1; + int TM_Int = -1; + + if(lua_gettop(_NLL) >= 3) + { + TM_Level = (int)lua_tointeger(_NLL, 3); + } + + TM_Int = NPC_GivePet(TM_Index, TM_Level, TM_EnemyId); + if(TM_Int >= 0) + { + TM_PetIndex = TM_Int; + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " 1 ֻ %s", CHAR_getChar( TM_PetIndex, CHAR_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + } + LRetInt(_NLL, TM_PetIndex); +} + +int NPC_Lua_NLG_GiveItemOne(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemId = (int)lua_tointeger(_NLL, 2); + int TM_ItemIndex = -1; + int TM_Int = -1; + + TM_Int = NPC_GiveItem( TM_Index, TM_ItemId); + + if(TM_Int >= 0) + { + TM_ItemIndex = TM_Int; + char TM_Buff[128]; + snprintf(TM_Buff, sizeof(TM_Buff), " 1 %s", ITEM_getChar( TM_ItemIndex, ITEM_NAME)); + CHAR_talkToCli( TM_Index, -1, TM_Buff, CHAR_COLORYELLOW); + } + LRetInt(_NLL, TM_ItemIndex); +} + +int NPC_Lua_NLG_DelItemByIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + CheckIndexNull(_NLL, 2); + int charaindex = (int)lua_tointeger(_NLL, 1); + if( CHAR_CHECKINDEX( charaindex ) == FALSE ){ + LRetInt(_NLL, -1); + return -1; + } + int haveitemindex = (int)lua_tointeger(_NLL, 2); + int itemindex = CHAR_getItemIndex( charaindex, haveitemindex); + if(!ITEM_CHECKINDEX(itemindex)) { + LRetInt(_NLL, -1); + return -1; + } + CHAR_DelItem( charaindex, haveitemindex); + LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_FindPet(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_PetID = (int)lua_tointeger(_NLL, 2); + int TM_Count = 0; + + int i = 0; + for(i = 0; i < CHAR_MAXPETHAVE ; i++) + { + if (CHAR_getCharPet( TM_Index, i) == -1) TM_Count++; + } + LRetInt(_NLL, TM_Count); +} + +int NPC_Lua_NLG_GetMap(lua_State *_NLL) +{ + CheckEx2(_NLL, 1, 3); + CheckIndexNull(_NLL, 1); + + int TM_Index = (int)lua_tointeger(_NLL, 1); + + BOOL TM_Ret = CHAR_CHAT_GetMap( TM_Index, ""); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_PetUp(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_PetIndex = (int)lua_tointeger(_NLL, 2); + int TM_LV = 1; + + if(lua_gettop(_NLL) == 3) + { + TM_LV = (int)lua_tointeger(_NLL, 3); + } + + BOOL TM_Ret = NPC_PetUp(TM_Index, TM_LV, TM_PetIndex); + + LRetBool(_NLL, TM_Ret); +} + +#ifdef _CHAR_PROFESSION +int NPC_Lua_NLG_AddSk(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_SkIndex = (int)lua_tointeger(_NLL, 2); + int TM_SkLV = 1; + + if(lua_gettop(_NLL) == 3) + { + TM_SkLV = (int)lua_tointeger(_NLL, 3); + } + + BOOL TM_Ret = NPC_AddSk(TM_Index, TM_SkIndex, TM_SkLV); + + LRetInt(_NLL, TM_Ret); +} + + +int NPC_Lua_NLG_SetZy(lua_State *_NLL) +{ + CheckEx2(_NLL, 2, 3); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ZyIndex = (int)lua_tointeger(_NLL, 2); + + BOOL TM_Ret = NPC_SetZy(TM_Index, TM_ZyIndex); + + LRetBool(_NLL, TM_Ret); +} +#endif + +int NPC_Lua_Char_GetPlayerMaxNum(lua_State *_NLL) +{ + CheckEx(_NLL, 0); + LRetInt(_NLL, CHAR_getPlayerMaxNum()); +} + +int NPC_Lua_NLG_GetXY(lua_State *_NLL) +{ + CheckEx2(_NLL, 1, 2); + CheckIndexNull(_NLL, 1); + int TM_MAP = (int)lua_tointeger(_NLL, 1); + LRetInt(_NLL, QuBiao(TM_MAP)); +} + +int NPC_Lua_NLG_WalkJc(lua_State *_NLL)//ǰϰ +{ + CheckEx(_NLL, 5); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Floor = (int)lua_tointeger(_NLL, 2); + int TM_Ox = (int)lua_tointeger(_NLL, 3); + int TM_Oy = (int)lua_tointeger(_NLL, 4); + int TM_DIR = (int)lua_tointeger(_NLL, 5); + + int TM_Ret = (int)CHAR_walk_jjc(TM_Index,TM_Floor,TM_Ox,TM_Oy,TM_DIR); + + if( TM_Ret == CHAR_WALKSUCCESSED ) + { + LRetInt(_NLL, 1); + }else LRetInt(_NLL, 0); +} + +int NPC_Lua_NLG_KickPlayer(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + if( !CHAR_CHECKINDEX( TM_index)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } +#ifdef _NETLOG_ + char cdkey[16]; + char charname[32]; + CONNECT_getCharname(CHAR_getWorkInt( TM_index, CHAR_WORKFD ),charname,32); + CONNECT_getCdkey(CHAR_getWorkInt( TM_index, CHAR_WORKFD ),cdkey,16); + LogCharOut(charname,cdkey,__FILE__,__FUNCTION__,__LINE__,"NPC_Lua_NLG_KickPlayer "); +#endif + + CONNECT_setCloseRequest( getfdFromCharaIndex(TM_index) , 1 ); + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NLG_HealOne(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + if( !CHAR_CHECKINDEX( TM_index)) { + LRetErrInt(_NLL , -1, "Чģ"); + return; + } + CHAR_setInt( TM_index , CHAR_HP,99999999 ); + CHAR_setInt( TM_index , CHAR_MP,99999999 ); + CHAR_complianceParameter( TM_index ); + CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_HP); + CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_MP); + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NLG_HealAll(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_PetIndex = -1; + if( !CHAR_CHECKINDEX( TM_index)) { + LRetErrInt(_NLL , -1, "Чģ"); + return; + } + CHAR_setInt( TM_index , CHAR_HP,99999999 ); + CHAR_setInt( TM_index , CHAR_MP,99999999 ); + CHAR_complianceParameter( TM_index ); + CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_HP); + CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_MP); + int i = 0; + for(i = 0; i < CHAR_MAXPETHAVE ; i++) + { + TM_PetIndex = CHAR_getCharPet( TM_index, i); + + if(!CHAR_CHECKINDEX(TM_PetIndex)) + { + continue; + } + CHAR_setInt( TM_PetIndex , CHAR_HP,99999999 ); + CHAR_complianceParameter( TM_PetIndex ); + char msgbuf[64]; + snprintf( msgbuf, sizeof( msgbuf ), "K%d", i ); + CHAR_sendStatusString( TM_index, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", i ); + CHAR_sendStatusString( TM_index, msgbuf ); +#ifdef _PET_SKILL2 + snprintf( msgbuf, sizeof( msgbuf ), "Q%d", i ); + CHAR_sendStatusString( TM_index, msgbuf ); +#endif + } + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NLG_LevelUpTo(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_LV = (int)lua_tointeger(_NLL, 2); + int i; + if( !CHAR_CHECKINDEX( TM_index)) { + LRetErrInt(_NLL , -1, "Чģ"); + return; + } + TM_LV = TM_LV - CHAR_getInt( TM_index, CHAR_LV); + if (TM_LV <= 0) //ʧ + { + LRetBool(_NLL, FALSE); + } + if (CHAR_getInt( TM_index, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER)//Ļ + { + CHAR_setInt(TM_index,CHAR_SKILLUPPOINT, + CHAR_getInt(TM_index,CHAR_SKILLUPPOINT)+TM_LV*3); + CHAR_Skillupsend(TM_index); + CHAR_setInt(TM_index,CHAR_LV, CHAR_getInt( TM_index, CHAR_LV) + TM_LV); + CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_LV|CHAR_P_STRING_NEXTEXP); + LRetBool(_NLL, TRUE); + }else if (CHAR_getInt( TM_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET)//dzĻ + { + char token[128]; + for( i = 1; i <= TM_LV; i ++ ){ // + //CHAR_PetLevelUp( TM_index ,1); + CHAR_PetLevelUp( TM_index); + CHAR_PetAddVariableAi( TM_index, AI_FIX_PETLEVELUP ); + CHAR_setInt( TM_index, CHAR_LV, CHAR_getInt( TM_index, CHAR_LV) +1 ); + } + int PLAYER = CHAR_getWorkInt(TM_index, CHAR_WORKPLAYERINDEX);//˵ + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) + { + if( CHAR_getCharPet( PLAYER, i ) == TM_index )break; + } + CHAR_setInt( TM_index , CHAR_HP ,CHAR_getWorkInt( TM_index, CHAR_WORKMAXHP ) ); + CHAR_setInt( TM_index , CHAR_MP ,CHAR_getWorkInt( TM_index, CHAR_WORKMAXMP ) ); + CHAR_complianceParameter( TM_index ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( PLAYER, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( PLAYER, token ); +#ifdef _PET_SKILL2 + snprintf( token, sizeof( token ), "Q%d", i ); + CHAR_sendStatusString( TM_index, token ); +#endif + } + LRetBool(_NLL, TRUE); +} + + +int NPC_Lua_NLG_AddExp(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int i; + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_EXP = (int)lua_tointeger(_NLL, 2); + if( !CHAR_CHECKINDEX( TM_index)) { + LRetErrInt(_NLL , -1, "Чģ"); + return; + } + CHAR_setInt( TM_index, CHAR_EXP,CHAR_getInt(TM_index,CHAR_EXP) + TM_EXP); + + if (CHAR_getInt( TM_index, CHAR_WHICHTYPE ) == CHAR_TYPEPET)//dzĻ + { + char token[128]; + int PLAYER = CHAR_getWorkInt(TM_index, CHAR_WORKPLAYERINDEX);//˵ + for( i = 0; i < CHAR_MAXPETHAVE; i ++ ) + { + if( CHAR_getCharPet( PLAYER, i ) == TM_index )break; + } + CHAR_complianceParameter( TM_index ); + snprintf( token, sizeof( token ), "K%d", i ); + CHAR_sendStatusString( PLAYER, token ); + snprintf( token, sizeof( token ), "W%d", i ); + CHAR_sendStatusString( PLAYER, token ); +#ifdef _PET_SKILL2 + snprintf( token, sizeof( token ), "Q%d", i ); + CHAR_sendStatusString( PLAYER, token ); +#endif + }else CHAR_send_P_StatusString( TM_index , CHAR_P_STRING_EXP); + LRetBool(_NLL, TRUE); +} + +int NPC_Lua_NLG_UpPet(lua_State *_NLL) +{ + CheckEx2(_NLL, 1, 2); + CheckIndexNull(_NLL, 1); + int TM_Top = lua_gettop(_NLL); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_It = -1; + int i; + int petindex; + char token[64]; + if( !CHAR_CHECKINDEX( TM_Index)) { + LRetErrInt(_NLL , -1, "Чģ"); + return; + } + if (TM_Top == 2) + { + TM_It = (int)lua_tointeger(_NLL, 2); + } + if(TM_It == -1){ + for (i=0;i 4) LRetErrInt(_NLL , -1, "ָijλûг"); + + TM_PetIndex = CHAR_getCharPet( TM_Index, TM_PetID); + + if(!CHAR_CHECKINDEX(TM_PetIndex)) + { + LRetInt(_NLL, -1); + return -1; + } + + TM_Ret = NPC_DelPet( TM_Index, TM_PetID); + if(TM_Ret < 0) + { + char TM_MsgBuff[128]; + snprintf(TM_MsgBuff, sizeof(TM_MsgBuff), "ɾʱ : %d", TM_Ret); + LRetErrInt(_NLL , -1, TM_MsgBuff); + } + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_DelPetByIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Pindex = (int)lua_tointeger(_NLL, 2); + int TM_Num = 1; + int TM_PetIndex = -1; + int TM_Ret = 0; + if( !CHAR_CHECKINDEX( TM_Index)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + if( !CHAR_CHECKINDEX( TM_Pindex)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + int i = 0; + for(i = 0; i < CHAR_MAXPETHAVE ; i++) + { + TM_PetIndex = CHAR_getCharPet( TM_Index, i); + + if(!CHAR_CHECKINDEX(TM_PetIndex)) + { + continue; + } + + if (TM_PetIndex != TM_Pindex) continue; + + TM_Ret = NPC_DelPet( TM_Index, i); + if(TM_Ret < 0) + { + char TM_MsgBuff[128]; + snprintf(TM_MsgBuff, sizeof(TM_MsgBuff), "ɾʱ : %d", TM_Ret); + LRetErrInt(_NLL , -1, TM_MsgBuff); + } + + break; + } + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_NLG_GivePetByIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_PetIndex = (int)lua_tointeger(_NLL, 2); + if( !CHAR_CHECKINDEX( TM_Index)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + if( !CHAR_CHECKINDEX( TM_PetIndex)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + int havepetelement = CHAR_getCharPetElement( TM_Index); + if( havepetelement < 0 ) { + LRetErrInt(_NLL , -1, "Ŀλ"); + return; + } + CHAR_setWorkInt( TM_PetIndex, CHAR_WORKPLAYERINDEX, TM_Index);// + CHAR_setCharPet( TM_Index, havepetelement, TM_PetIndex); + CHAR_setChar( TM_PetIndex, CHAR_OWNERCDKEY, + CHAR_getChar( TM_Index, CHAR_CDKEY)); + CHAR_setChar( TM_PetIndex, CHAR_OWNERCHARANAME, + CHAR_getChar( TM_Index, CHAR_NAME)); + CHAR_complianceParameter(TM_PetIndex); + + char msgbuf[64]; + snprintf( msgbuf, sizeof( msgbuf ), "K%d", havepetelement ); + CHAR_sendStatusString( TM_Index, msgbuf ); + snprintf( msgbuf, sizeof( msgbuf ), "W%d", havepetelement ); + CHAR_sendStatusString( TM_Index, msgbuf ); +#ifdef _PET_SKILL2 + snprintf( msgbuf, sizeof( msgbuf ), "Q%d", havepetelement ); + CHAR_sendStatusString( TM_Index, msgbuf ); +#endif + LRetInt(_NLL, havepetelement); +} + +int NPC_Lua_NLG_GiveItemByIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_ItemIndex = (int)lua_tointeger(_NLL, 2); + if( !CHAR_CHECKINDEX( TM_Index)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + if( !ITEM_CHECKINDEX( TM_ItemIndex)) { + LRetErrInt(_NLL , -1, "ߴЧģ"); + return; + } + int emptyitemindexinchara = CHAR_findEmptyItemBox( TM_Index); + if( emptyitemindexinchara < 0 ) { + LRetErrInt(_NLL , -1, "Ŀλ"); + return; + } + CHAR_setItemIndex( TM_Index, emptyitemindexinchara, TM_ItemIndex ); + ITEM_setWorkInt(TM_ItemIndex, ITEM_WORKOBJINDEX,-1); + ITEM_setWorkInt(TM_ItemIndex, ITEM_WORKCHARAINDEX, TM_Index); + CHAR_sendItemDataOne( TM_Index, emptyitemindexinchara); + LRetInt(_NLL, emptyitemindexinchara); +} + +int NPC_Lua_NLG_WarpToSpecificPoint(lua_State *_NLL) +{ + + CheckEx(_NLL, 4); + CheckIndexNull(_NLL, 1); + int cindex = (int)lua_tointeger(_NLL, 1); + int fl = (int)lua_tointeger(_NLL, 2); + int x = (int)lua_tointeger(_NLL, 3); + int y = (int)lua_tointeger(_NLL, 4); + + if(!CHAR_CHECKINDEX(cindex)) + { + LRetErrInt(_NLL, -1, "Чġ"); + } + + LRetBool(_NLL,CHAR_warpToSpecificPoint(cindex,fl,x,y)); +} + +BOOL NPC_Lua_NLG_UpSkillupPoint(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + if( !CHAR_CHECKINDEX( TM_Index)) { + LRetErrInt(_NLL , -1, "ﴫЧģ"); + return; + } + CHAR_Skillupsend(TM_Index); + LRetBool(_NLL, TRUE); +} + +// +int NPC_Lua_NLG_StayEncount(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckIndexNull(_NLL, 1); + int fd,charaindex = (int)lua_tointeger(_NLL, 1); + fd = CHAR_getWorkInt( charaindex, CHAR_WORKFD); + setStayEncount(fd); + CHAR_talkToCli(charaindex, -1, "ܱܵͻȻɱ", CHAR_COLORYELLOW); +#ifdef _USER_CHARLOOPS + { + Char *ch; + ch = CHAR_getCharPointer( charaindex); + if( ch == NULL ) return; + strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string, + sizeof( ch->charfunctable[CHAR_LOOPFUNCTEMP1]), "CHAR_BattleStayLoop");//ս + CHAR_setInt( charaindex, CHAR_LOOPINTERVAL, 2500); + CHAR_constructFunctable( charaindex); + } +#endif + LRetBool(_NLL,TRUE); +} + +int NPC_Lua_NLG_HealerAllHeal(lua_State *_NLL) +{ + CheckEx(_NLL,1); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + NPC_HealerAllHeal(TM_Index); + LRetNull(_NLL); +} +extern int getArrayInt(lua_State *L, int idx); +int NPC_Lua_NLG_CreateVsEnemyAB (lua_State *L) +{ + const int charaindex = luaL_checkint(L, 1); + const int npcindex = luaL_checkint(L, 2); + int enemytable[11]; + int i; + for( i = 0; i < 11; i ++ ) { + enemytable[i] = -1; + } + luaL_checktype(L, 3, LUA_TTABLE); + int n = luaL_getn(L, 3); + int id = 0; + for(i = 0; i < n; i++){ + int enemyid = getArrayInt(L, i); + int curEnemy = ENEMY_getEnemyArrayFromId( enemyid ); + + if( ENEMY_CHECKINDEX( curEnemy) ) { + enemytable[id++] = curEnemy; + }else{ + enemytable[i] = -1; + } + } + int ret = BATTLE_CreateVsEnemyNew(charaindex, npcindex, enemytable); + if( ret == 0 ) { + if(npcindex>-1){ + CHAR_setWorkInt( npcindex, CHAR_WORKBATTLEMODE, BATTLE_CHARMODE_INIT ); + CHAR_sendBattleEffect( npcindex, ON); + } + lua_pushinteger(L, CHAR_getWorkInt( charaindex, CHAR_WORKBATTLEINDEX)); + return 1; + }else{ + return 0; + } +} + +#endif //#ifdef _JZ_NEWSCRIPT_LUA diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_obj.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_obj.c new file mode 100644 index 0000000..381cb1b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_obj.c @@ -0,0 +1,140 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" + +#ifdef _JZ_NEWSCRIPT_LUA + +int NPC_Lua_Obj_GetType(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getType(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_GetCharType(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getchartype(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_GetCharIndex(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getIndex(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_GetX(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getX(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_GetY(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getY(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_GetFloor(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + + int TM_Ret = OBJECT_getFloor(TM_index); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_SetType(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + int TM_Ret = OBJECT_setType(TM_index, TM_vl); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_SetCharType(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + OBJECT_setchartype(TM_index, TM_vl); + + LRetNull(_NLL); +} + +int NPC_Lua_Obj_SetX(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + int TM_Ret = OBJECT_setX(TM_index, TM_vl); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_SetY(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + int TM_Ret = OBJECT_setY(TM_index, TM_vl); + + LRetInt(_NLL, TM_Ret); +} + +int NPC_Lua_Obj_SetFloor(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckObjIndexNull(_NLL, 1); + int TM_index = (int)lua_tointeger(_NLL, 1); + int TM_vl = (int)lua_tointeger(_NLL, 2); + + int TM_Ret = OBJECT_setFloor(TM_index, TM_vl); + + LRetInt(_NLL, TM_Ret); +} +#endif //#ifdef _JZ_NEWSCRIPT_LUA diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_spell.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_spell.c new file mode 100644 index 0000000..4b24837 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_spell.c @@ -0,0 +1,202 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "anim_tbl.h" +#include "object.h" +#include "net.h" +#include "npcutil.h" +#include "npc_eventaction.h" +#include "battle.h" +#include "readmap.h" +#include "pet_skill.h" +#include "profession_skill.h" +#include "magic_base.h" + +#define _JZ_NEWSCRIPT_LUA + +#ifdef _CHAR_PROFESSION + +int NPC_Lua_Spell_PROFESSION_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + int skillarray = PROFESSION_SKILL_getskillArray( TM_Index); + TM_Flg -= LUA_DATALINE0; + int TM_RetInt = PROFESSION_SKILL_getInt(skillarray, TM_Flg); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + + int skillarray = PROFESSION_SKILL_getskillArray( TM_Index ); + TM_Flg -= LUA_DATALINE1; + char *TM_RetPoint = PROFESSION_SKILL_getChar(skillarray, TM_Flg); + LRetMsg(_NLL, TM_RetPoint); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Spell_PETSKILL_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + int TM_IntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = PROFESSION_SKILL_setInt(TM_Index, TM_Flg, TM_IntVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_CharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = PROFESSION_SKILL_setChar(TM_Index, TM_Flg, TM_CharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + + + + + + +int NPC_Lua_Spell_PROFESSION_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + int TM_IntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = PROFESSION_SKILL_setInt(TM_Index, TM_Flg, TM_IntVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_CharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = PROFESSION_SKILL_setChar(TM_Index, TM_Flg, TM_CharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + + +#endif + +int NPC_Lua_Spell_MAGIC_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + int magic_array = -1; + magic_array = MAGIC_getMagicArray( TM_Index ); + TM_Flg -= LUA_DATALINE0; + int TM_RetInt = MAGIC_getInt(magic_array, TM_Flg); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + int magic_array = -1; + magic_array = MAGIC_getMagicArray( TM_Index ); + TM_Flg -= LUA_DATALINE1; + char *TM_RetPoint = MAGIC_getChar(magic_array, TM_Flg); + LRetMsg(_NLL, TM_RetPoint); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} +int NPC_Lua_Spell_PETSKILL_GetData(lua_State *_NLL) +{ + CheckEx(_NLL, 2); + CheckIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + int skillarray = PETSKILL_getPetskillArray( TM_Index); + TM_Flg -= LUA_DATALINE0; + int TM_RetInt = PETSKILL_getInt(skillarray, TM_Flg); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + int skillarray = PETSKILL_getPetskillArray( TM_Index); + TM_Flg -= LUA_DATALINE1; + char *TM_RetPoint = PETSKILL_getChar(skillarray, TM_Flg); + LRetMsg(_NLL, TM_RetPoint); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} + +int NPC_Lua_Spell_MAGIC_SetData(lua_State *_NLL) +{ + CheckEx(_NLL, 3); + CheckItemIndexNull(_NLL, 1); + int TM_Index = (int)lua_tointeger(_NLL, 1); + int TM_Flg = (int)lua_tointeger(_NLL, 2); + + if(TM_Flg >= 0) + { + if(TM_Flg < LUA_DATALINE1) + { + TM_Flg -= LUA_DATALINE0; + int TM_IntVal = (int)lua_tointeger(_NLL, 3); + int TM_RetInt = MAGIC_setInt(TM_Index, TM_Flg, TM_IntVal); + LRetInt(_NLL, TM_RetInt); + }else if(TM_Flg < LUA_DATALINE2) + { + TM_Flg -= LUA_DATALINE1; + char *TM_CharPoint = (char *)lua_tostring(_NLL, 3); + BOOL TM_RetBOOL = MAGIC_setChar(TM_Index, TM_Flg, TM_CharPoint); + LRetBool(_NLL, TM_RetBOOL); + }else + { + LRetErrNull(_NLL, "ı־Ǵġ"); + } + } + LRetErrNull(_NLL, "ı־Ǵġ"); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_sql.c b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_sql.c new file mode 100644 index 0000000..8ff082c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/npc_lua_sql.c @@ -0,0 +1,131 @@ +#include "npc_lua.h" +#include "util.h" +#include "char.h" +#include "char_base.h" +#include "char_data.h" +#include "anim_tbl.h" +#include "object.h" +#include "battle.h" +#include "npcutil.h" +#include "item.h" +#include "readmap.h" + +#include "longzoro/sasql.h" + +#ifdef _JZ_NEWSCRIPT_LUA + + +int NPC_Lua_SQL_Push(lua_State *_NLL) +{ + CheckEx(_NLL, 1); + + char* _SQLSTR = NULL; + + _SQLSTR = lua_tostring(_NLL, 1); + sasql_LUASQL(_SQLSTR,-1,"NULL","NULL",-1,-1,"NULL"); +} + + +int NPC_Lua_SQL_PushPop(lua_State *_NLL) +{ + CheckEx(_NLL,7); + int npcindex,charaindex,row; + char* sqlstr,*function,*filepath,*msg; + + sqlstr = lua_tostring(_NLL, 1); + row = lua_tointeger(_NLL, 2); + filepath = lua_tostring(_NLL, 3); + function = lua_tostring(_NLL, 4); + npcindex = lua_tointeger(_NLL, 5); + charaindex = lua_tointeger(_NLL, 6); + msg = lua_tostring(_NLL, 7); +// print("sqlstr=%s\n row=%d\n filepath=%s\n function=%s\n npcindex=%d\n charaindex=%d\n msg=%s\n",sqlstr,row,filepath,function,npcindex,charaindex,msg); + sasql_LUASQL(sqlstr,row,filepath,function,npcindex,charaindex,msg); +} + +int NPC_Lua_SQL_PushPopAdv(lua_State *_NLL) +{ + CheckEx(_NLL,6); + int npcindex,charaindex; + char* sqlstr,*function,*filepath,*msg; + + sqlstr = lua_tostring(_NLL, 1); + if(lua_isnil((_NLL), (3))){ + filepath = ""; + }else{ + filepath = lua_tostring(_NLL, 3); + } + function = lua_tostring(_NLL, 3); + npcindex = lua_tointeger(_NLL, 4); + charaindex = lua_tointeger(_NLL, 5); + msg = lua_tostring(_NLL, 6); + int flg = 1; + sasql_LUASQLAdv(sqlstr,filepath,function,npcindex,charaindex,msg,flg); +} + +int NPC_Lua_SQL_QueryFirstRow(lua_State *_NLL) +{ + CheckEx(_NLL,6); + int npcindex,charaindex; + char* sqlstr,*function,*filepath,*msg; + + sqlstr = lua_tostring(_NLL, 1); + if(lua_isnil((_NLL), (3))){ + filepath = ""; + }else{ + filepath = lua_tostring(_NLL, 3); + } + function = lua_tostring(_NLL, 3); + npcindex = lua_tointeger(_NLL, 4); + charaindex = lua_tointeger(_NLL, 5); + msg = lua_tostring(_NLL, 6); + int flg = 2; + sasql_LUASQLAdv(sqlstr,filepath,function,npcindex,charaindex,msg,flg); +} + +int NPC_Lua_SQL_FetchRow(lua_State *_NLL) +{ + CheckEx(_NLL,5); + int npcindex,charaindex; + char* sqlstr,*function,*filepath,*msg; + + + if(lua_isnil((_NLL), (3))){ + filepath = ""; + }else{ + filepath = lua_tostring(_NLL, 3); + } + function = lua_tostring(_NLL, 2); + npcindex = lua_tointeger(_NLL, 3); + charaindex = lua_tointeger(_NLL, 4); + msg = lua_tostring(_NLL, 5); + int flg = 3; + sasql_LUASQLAdv("",filepath,function,npcindex,charaindex,msg,flg); +} + +int NPC_Lua_SQL_FreeResult(lua_State *_NLL) +{ + CheckEx(_NLL,5); + int npcindex,charaindex; + char* sqlstr,*function,*filepath,*msg; + + + if(lua_isnil((_NLL), (3))){ + filepath = ""; + }else{ + filepath = lua_tostring(_NLL, 3); + } + function = lua_tostring(_NLL, 2); + npcindex = lua_tointeger(_NLL, 3); + charaindex = lua_tointeger(_NLL, 4); + msg = lua_tostring(_NLL, 5); + int flg = 4; + sasql_LUASQLAdv("",filepath,function,npcindex,charaindex,msg,flg); +} +#endif + + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.cpp b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.cpp new file mode 100644 index 0000000..c6702e1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : ֻ׼ļԴļ +// npc_lua.pch ΪԤͷ +// stdafx.obj ԤϢ + +#include "stdafx.h" + +// TODO: STDAFX.H +// κĸͷļڴļ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.h b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.h new file mode 100644 index 0000000..a750a8d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/stdafx.h @@ -0,0 +1,14 @@ +// stdafx.h : ׼ϵͳļİļ +// Ǿʹõĵ +// ضĿİļ +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Windows ͷųʹõ + + + +// TODO: ڴ˴óҪͷļ diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/targetver.h b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/targetver.h new file mode 100644 index 0000000..e0e9984 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/npc_lua/targetver.h @@ -0,0 +1,13 @@ +#pragma once + +// º궨Ҫƽ̨Ҫƽ̨ +// ǾӦó蹦ܵ WindowsInternet Explorer ȲƷ +// 汾ָͨ汾Ͱ汾ƽ̨пõĹܣ +// + +// ҪԵָ汾ƽ̨޸ж塣 +// йزͬƽ̨ӦֵϢο MSDN +#ifndef _WIN32_WINNT // ָҪƽ̨ Windows Vista +#define _WIN32_WINNT 0x0600 // ֵΪӦֵ Windows 汾 +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/object.c b/石器时代服务器端最新完整源代码/Serv/gmsv/object.c new file mode 100644 index 0000000..7ff85b9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/object.c @@ -0,0 +1,479 @@ +#include "version.h" +#include + +#include +#include +#include +#include + +#include "handletime.h" + +#include "common.h" +#include "object.h" +#include "char_base.h" +#include "char.h" +#include "item.h" +#include "buf.h" +#include "readmap.h" +#include "pet.h" + +static Object *obj; +static int objnum; + +#ifdef _PET_ITEM +static int Restored = FALSE; +#endif + +BOOL initObjectArray( int num ) +{ + int i; + objnum = num; + obj = allocateMemory( sizeof( Object ) * objnum ); + + if( obj == NULL ) return FALSE; + for( i = 0 ; i < objnum ; i ++ ){ + memset( &obj[i], 0 , sizeof( Object )); + obj[i].type = OBJTYPE_NOUSE; + } + print( " %.2f MB MB ռ...", sizeof( Object ) * objnum / 1024.0 / 1024.0 ); + return TRUE; +} + + +BOOL endObjectArray( void ) +{ + freeMemory( obj ); + return TRUE; +} + +INLINE int _initObjectOne( char *file, int line, Object* ob ) +{ + static int allocobjnum = 0; + int i; + BOOL first; + + i = allocobjnum; + first = TRUE; + while( 1 ) { + if( !first && i >= allocobjnum ) { + fprint( "Can't allocate an object\n" ); + return -1; + } + if( obj[i].type == OBJTYPE_NOUSE ) { + if( MAP_addNewObj( ob->floor ,ob->x, ob->y, i ) == 1 ){ + memcpy( &obj[i] , ob , sizeof( Object ) ); + allocobjnum = ( i+1 >= objnum) ? 0:i+1; + return i; + }else{ + allocobjnum = ( i+1 >= objnum) ? 0:i+1; + fprint( "%d ͼ\n",ob->floor ); + return -1; + } + }else { + if( ++i >= objnum ) { + i = 0; + first = FALSE; + } + } + } + + fprint( "Can't allocate an object\n" ); + return -1; +} + +void endObjectOne( int index ) +{ + if(objnum <= index || index < 0 )return; + + if( MAP_removeObj(obj[index].floor,obj[index].x, obj[index].y, + index) == FALSE){ +// fprint( "REMOVE OBJ ERROR floor:%d x:%d y:%d\n",obj[index].floor,obj[index].x, obj[index].y ); + } + obj[index].type = OBJTYPE_NOUSE; +} + +BOOL CHECKOBJECT( int index ) +{ + if( 0<=index && indextype = OBJTYPE_ITEM; + else if( strcmp( token , STOREGOLDID ) == 0 ) + one->type = OBJTYPE_GOLD; + else if( strcmp( token, STORECHARID) == 0 ) + one->type = OBJTYPE_CHARA; + for( i = 2 ; i < 5 ; i ++ ){ + char first[64]; + char second[64]; + ret = getStringFromIndexWithDelim(line,"|" ,i, + token,sizeof( token )); + if( ret == FALSE )return FALSE; + + ret = getStringFromIndexWithDelim(token,"=" ,1, first,sizeof( first )); + if( ret == FALSE )return FALSE; + ret = getStringFromIndexWithDelim(token,"=" ,2, second,sizeof( second )); + if( ret == FALSE )return FALSE; + + if( strcmp( first , "x" ) == 0 ) + one->x = atoi( second ); + else if( strcmp( first , "y" ) == 0 ) + one->y = atoi( second ); + else if( strcmp( first , "floor" ) == 0 ) + one->floor = atoi( second ); + } + { + char* findex = nindex( line , '|' , 4); + *stringstart = findex + 1; + } + return TRUE; +} + +BOOL storeObjects( char* dirname ) +{ + int i; + FILE* igfile; + char igfilename[256]; + + if( Restored == TRUE ){ + snprintf( igfilename ,sizeof( igfilename ) ,"%s/%s" ,dirname , + ITEMGOLDSTOREFILENAME ); + }else{ + snprintf( igfilename ,sizeof( igfilename ) ,"%s/%s_extra" ,dirname , + ITEMGOLDSTOREFILENAME ); + + print( "\n---- ݱУرGMSV ----- \n"); + } + igfile = fopen( igfilename , "w" ); + if( igfile == NULL ){ + print( "\n\n---- ܴ (%s) Ʒļ. ----- \n\n", igfilename ); + return FALSE; + } + + print( "ݱ..."); + for( i = 0 ; i < objnum ; i ++ ){ + switch( obj[i].type ){ + case OBJTYPE_ITEM: + { + fprintf( igfile , STOREITEMID "|x=%d|y=%d|floor=%d|%s\n" , + obj[i].x , obj[i].y ,obj[i].floor, + ITEM_makeStringFromItemIndex( obj[i].index,0 ) ); + break; + } + case OBJTYPE_GOLD: + { + fprintf( igfile , STOREGOLDID "|x=%d|y=%d|floor=%d|%d\n" , + obj[i].x , obj[i].y ,obj[i].floor, obj[i].index ); + break; + } + case OBJTYPE_CHARA: + { + int petindex = obj[i].index; + if( CHAR_CHECKINDEX( petindex) ) { + if( CHAR_getInt( obj[i].index, CHAR_WHICHTYPE) == CHAR_TYPEPET){ + fprintf( igfile , STORECHARID "|x=%d|y=%d|floor=%d|%s\n" , + obj[i].x , obj[i].y ,obj[i].floor, + CHAR_makePetStringFromPetIndex( obj[i].index ) ); + } + } + break; + } + default: + break; + } + } + fclose( igfile ); + print( "\n"); +// system( "./itemda.pl" ); + print( "ݱ\n"); + return TRUE; +} +#endif + +int detectStoreFile( char* filename ) +{ + FILE* f; + char buffer[10]; + f = fopen ( filename ,"r" ); + if( f == NULL )return 3; + + if( fgets( buffer, sizeof( buffer ), f ) == NULL ){ + fclose(f); + return 3; + } + + if( strncmp(buffer,STOREITEMID,sizeof(STOREITEMID) ) == 0 || + strncmp(buffer,STOREGOLDID,sizeof(STOREGOLDID) ) == 0 ){ + fclose(f); + return 2; + } + + fclose(f); + return 3; +} + +#ifdef _PET_ITEM +BOOL restoreObjects( char* dirname ) +{ + char igfilename[512]; + FILE* file; + char line[2048]; + + snprintf( igfilename, sizeof(igfilename), "%s/%s", dirname, ITEMGOLDSTOREFILENAME ); + file = fopen( igfilename , "r" ); + if( file == NULL ){ + Restored = TRUE; + return FALSE; + } + while( fgets( line, sizeof( line ), file ) != NULL ){ + Object one; + char *string; + chomp( line ); + if( checkObjectStoreFile( line, &one ,&string ) == FALSE ) + continue; + switch( one.type ){ + case OBJTYPE_ITEM: + { + ITEM_Item itmone; + BOOL ret; + int objindex; + ret = ITEM_makeExistItemsFromStringToArg( string, &itmone, 0 ); + if( ret == TRUE ){ + one.index = ITEM_initExistItemsOne( &itmone ); + if( one.index == -1 ) + break; + objindex = initObjectOne( &one ); + ITEM_setWorkInt(one.index,ITEM_WORKCHARAINDEX,-1); + ITEM_setWorkInt(one.index,ITEM_WORKOBJINDEX,objindex); + } + break; + } + case OBJTYPE_GOLD: + one.index = atoi( string ); + initObjectOne( &one ); + break; + case OBJTYPE_CHARA: + { + Char ch; + int ret; + ret = CHAR_makePetFromStringToArg(string,&ch, -1); + if( ret ) { + Object object; + int objindex; + int petindex = PET_initCharOneArray( &ch ); + if( petindex < 0 ) { + print( "ʧܡ\n"); + } + object.type = OBJTYPE_CHARA; + object.index = petindex; + object.x = ch.data[CHAR_X]; + object.y = ch.data[CHAR_Y]; + object.floor = ch.data[CHAR_FLOOR]; + objindex = initObjectOne( &object ); + if( objindex == -1 ) { + CHAR_endCharOneArray( petindex ); + }else { + CHAR_setWorkInt( petindex,CHAR_WORKOBJINDEX,objindex ); + } + } + break; + } + default: + break; + } + } + fclose( file ); + Restored = TRUE; + + return TRUE; +} +#endif +#ifdef _MO_LNS_MAPSUOXU +INLINE int get_mappointindex( int fl,int x, int y)//ҳͼ͵ +{ + int i; + for(i=0;i +#include +#include +#include "common.h" +#include "net.h" +#include "lssproto_serv.h" +#ifdef _SEND_EFFECT // WON ADD ACѩЧ +#include "chatmagic.h" +#endif + +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + +/* +90 :

  • clienttoserver ACServerLogin(string servername,string serverpas);
    +91 : ءةӡʧӡ̼ +92 : ëؤ𼰷̼ëئͻӡ굩ëئУ +93 :

    +94 :
    +95 :
    string servername +96 :
    ӡ acserv.cfɬýľ£ +97 :
    string serverpas +98 :
    ӡɵacserv.cfɬýľ£ +99 :
    +100 : +*/ + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +void saacproto_UpdataStele_send( int fd , char *cdkey , char *name , char *title , int level , int trns , int time , int floor) +{ + saacproto_CreateHeader( saacproto.work , "UpdataStele" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( cdkey ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( name ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( title ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( level ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( trns ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( time ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( floor ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +#endif + +#if _ATTESTAION_ID == 1 +void saacproto_ACServerLogin_send( int fd, int id, char* servername,char* serverpas ) +#else +void saacproto_ACServerLogin_send( int fd,char* servername,char* serverpas ) +#endif +{ + saacproto_CreateHeader( saacproto.work , "ACServerLogin" ); + +#if _ATTESTAION_ID == 1 + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( id ) ,saacproto.workbufsize ); +#endif + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( servername ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( serverpas ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +114 :
  • clienttoserver ACServerLogout(void);
    +115 : ӡʧӡշʧ +116 : ӡ巽Ȼ ľ£׻Ȼľ帲ʧӡ +117 : ߯Ϸëƥؤ£ +118 :
    +119 :
    +120 :
    +121 : +122 : +*/ + +void saacproto_ACServerLogout_send( int fd ) +{ + saacproto_CreateHeader( saacproto.work , "ACServerLogout" ); + saacproto_strcatsafe( saacproto.work , "" ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +#ifdef _PKSEVER_VER +void saacproto_ACCharList_send( int fd,char* id,char* pas,int mesgid, int star) +#else +void saacproto_ACCharList_send( int fd,char* id,char* pas,char* ip,char* mac,int mesgid,int charlistflg ) +#endif +{ + saacproto_CreateHeader( saacproto.work , "ACCharList" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( pas ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( ip ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( mac ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( charlistflg ) ,saacproto.workbufsize ); + +#ifdef _PKSEVER_VER + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( star ) ,saacproto.workbufsize ); +#endif + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_ACCharLoad_send( int fd,char* id,char* pas,char* charname,int lock,char* opt,int mesgid ) +{ + saacproto_CreateHeader( saacproto.work , "ACCharLoad" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( pas ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( lock ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( opt ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +#ifdef _NEWSAVE +void saacproto_ACCharSave_send( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid,int saveindex ) +#else +void saacproto_ACCharSave_send( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid ) +#endif +{ + saacproto_CreateHeader( saacproto.work , "ACCharSave" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( opt ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charinfo ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( unlock ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); +#ifdef _NEWSAVE + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( saveindex ) ,saacproto.workbufsize ); +#endif + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_ACCharDelete_send( int fd,char* id,char* passwd,char* charname,char* option,int mesgid ) +{ + saacproto_CreateHeader( saacproto.work , "ACCharDelete" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( passwd ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( option ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_ACLock_send( int fd,char* id,int lock,int mesgid ) +{ + saacproto_CreateHeader( saacproto.work , "ACLock" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( lock ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_ACUCheck_send( int fd,char* mem_id,int status ) +{ + saacproto_CreateHeader( saacproto.work , "ACUCheck" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( mem_id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( status ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBUpdateEntryString_send( int fd,char* table,char* key,char* value,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBUpdateEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( value ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBDeleteEntryString_send( int fd,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBDeleteEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBGetEntryString_send( int fd,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBUpdateEntryInt_send( int fd,char* table,char* key,int value,char* info,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBUpdateEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( value ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( info ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBGetEntryRank_send( int fd,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryRank" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBDeleteEntryInt_send( int fd,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBDeleteEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBGetEntryInt_send( int fd,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBGetEntryByRank_send( int fd,char* table,int rank_start,int rank_end,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryByRank" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( rank_start ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( rank_end ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_DBGetEntryByCount_send( int fd,char* table,int count_start,int num,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryByCount" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( count_start ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( num ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +608 :
  • clienttoserver Broadcast( string id, string charname, string message , int flag );
    +609 : ءةӡ帲ƻѨë˪ +610 : ͻءةӡƻ Ԫ⻥˪ľ£ +611 : id , charname ʹľ¼ƥ ¦ëֹף +612 : ٯ ɡë̤ئʻз +613 :
    +614 :
    string id +615 :
    user ID +616 :
    string charname +617 :
    ƽҷ (޵ئ) +618 :
    string message +619 :
    ˪ľ¶۱ءةӡѱ +620 :
    +*/ + +void saacproto_Broadcast_send( int fd,char* id,char* charname,char* message,int flag ) +{ +/* + saacproto_CreateHeader( saacproto.work , "Broadcast" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( message ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( flag ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +*/ +} +/* +634 :
  • clienttoserver Message( string id_from, string charname_from, string id_to, string charname_to, string message , int option );
    +635 : ̼ë˪ +636 :
    +637 :
    string id_from +638 :
    from ID +639 :
    string charname_from +640 :
    from Character name +641 :
    string id_to +642 :
    to ID +643 :
    string charname_to +644 :
    to character name +645 :
    string message +646 :
    +647 :
    int option +648 :
    羮ǷǷ ľľ£ +649 : ľëءةӡ ƥʧӡ +650 : 婳 ئ +651 :
    +*/ + +void saacproto_Message_send( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option ) +{ + saacproto_CreateHeader( saacproto.work , "Message" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id_from ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname_from ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id_to ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname_to ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( message ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( option ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_MessageAck_send( int fd,char* id,char* charname,char* result,int mesgid ) +{ + saacproto_CreateHeader( saacproto.work , "MessageAck" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_MessageFlush_send( int fd,char* id,char* charname ) +{ + saacproto_CreateHeader( saacproto.work , "MessageFlush" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +/************************************************************ + * CoolFish: Family 2001/5/18 + ***********************************************************/ +#ifdef _PERSONAL_FAME +void saacproto_ACAddFM_send(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid) +#else +void saacproto_ACAddFM_send(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid) +#endif +{ + saacproto_CreateHeader(saacproto.work, "ACAddFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmleadername), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmleaderid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmleaderlv), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(petname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(petattr), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmrule), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmsprite), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmleadergrano), saacproto.workbufsize); +// #ifdef _PERSONAL_FAME + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fame), saacproto.workbufsize); +// #endif + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); +#ifdef _FAMILYBADGE_ + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmbadge), saacproto.workbufsize); +#endif + saacproto_Send(fd, saacproto.work); +} +#ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACJoinFM_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int index, int fame, int charfdid) +#else +void saacproto_ACJoinFM_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int index, int charfdid) +#endif +{ + saacproto_CreateHeader(saacproto.work, "ACJoinFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charlv), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); +// #ifdef _PERSONAL_FAME // Arminius: + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fame), saacproto.workbufsize); +// #endif + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACLeaveFM_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int index, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACLeaveFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACDelFM_send(int fd, char *fmname, int fmindex, int index, + char *charname, char *charid, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACDelFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACShowFMList_send(int fd) +{ + saacproto_CreateHeader(saacproto.work, "ACShowFMList"); + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACShowMemberList_send(int fd, int index) +{ + saacproto_CreateHeader(saacproto.work, "ACShowMemberList"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string("MemberList"), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFMDetail_send(int fd, char *fmname, int fmindex, int index, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACFMDetail"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +#ifdef _FMVER21 +void saacproto_ACMemberJoinFM_send(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int result, int meindex, + int charfdid) +#else +void saacproto_ACMemberJoinFM_send(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int result, int charfdid) +#endif +{ + saacproto_CreateHeader(saacproto.work, "ACMemberJoinFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(result), saacproto.workbufsize); +#ifdef _FMVER21 + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(meindex), saacproto.workbufsize); +#endif + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +#ifdef _FMVER21 +void saacproto_ACMemberLeaveFM_send(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int meindex, int charfdid) +#else +void saacproto_ACMemberLeaveFM_send(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int charfdid) +#endif +{ + saacproto_CreateHeader(saacproto.work, "ACMemberLeaveFM"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); +#ifdef _FMVER21 + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(meindex), saacproto.workbufsize); +#endif + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +#ifdef _FM_MODIFY +void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int eventflag, int charfdid,int gsnum) +#else + #ifdef _FMVER21 + void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int eventflag, int charfdid) + #else + void saacproto_ACFMCharLogin_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int charfdid) + #endif +#endif +{ + saacproto_CreateHeader(saacproto.work, "ACFMCharLogin"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charlv), saacproto.workbufsize); +#ifdef _FMVER21 + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(eventflag), saacproto.workbufsize); +#endif + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); +#ifdef _FM_MODIFY + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(gsnum), saacproto.workbufsize); +#endif + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACFMCharLogout_send(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int index, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACFMCharLogout"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charlv), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFMReadMemo_send(int fd, int index) +{ + saacproto_CreateHeader(saacproto.work, "ACFMReadMemo"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string("ReadMemo"), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFMWriteMemo_send(int fd, char *fmname, int fmindex, + char *data, int index) +{ + saacproto_CreateHeader(saacproto.work, "ACFMWriteMemo"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFMPointList_send(int fd) +{ + saacproto_CreateHeader(saacproto.work, "ACFMPointList"); + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACSetFMPoint_send(int fd, char *fmname, int fmindex, int index, + int fmpointindex, int fl, int x, int y, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACSetFMPoint"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmpointindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fl), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(x), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(y), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFixFMPoint_send(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex, + int village) +{ + saacproto_CreateHeader(saacproto.work, "ACFixFMPoint"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(winfmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(winfmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(winindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(losefmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(losefmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(loseindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(village), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFMAnnounce_send(int fd, char *fmname, int fmindex, int index, + char *data, int color) +{ + saacproto_CreateHeader(saacproto.work, "ACFMAnnounce"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(color), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACShowTopFMList_send(int fd, int kindflag) +{ + saacproto_CreateHeader(saacproto.work, "ACShowTopFMList"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string("ShowTopFMList"), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(kindflag), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACFixFMData_send(int fd, char *fmname, int fmindex, int index, + int kindflag, char *data1, char *data2, int charindex, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACFixFMData"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(kindflag), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data1), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data2), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACFixFMPK_send(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex) +{ + saacproto_CreateHeader(saacproto.work, "ACFixFMPK"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(winfmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(winfmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(winindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(losefmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(losefmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(loseindex), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACGMFixFMData_send(int fd, int index, char *charid, char *cmd, + char *data, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACGMFixFMData"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string("ACGMFixFMData"), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(charid), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(cmd), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +void saacproto_ACGetFMData_send(int fd, char *fmname, int fmindex, int index, + int kindflag, int charfdid) +{ + saacproto_CreateHeader(saacproto.work, "ACGetFMData"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(fmname), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(index), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(kindflag), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(charfdid), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + +// Arminius 7.26 manor pk acknowledge +void saacproto_ACManorPKAck_send(int fd, char *data) +{ + saacproto_CreateHeader(saacproto.work, "ACManorPKAck"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + +void saacproto_ACreLoadFmData_send( int fd, int type, int data) +{ + saacproto_CreateHeader( saacproto.work, "ACreLoadFmData"); + saacproto_strcatsafe( saacproto.work, saacproto_mkstr_int( type), saacproto.workbufsize); + saacproto_strcatsafe( saacproto.work, saacproto_mkstr_int( data), saacproto.workbufsize); + saacproto_Send( fd, saacproto.work); +} + +#ifdef _ACFMPK_LIST +void saacproto_ACLoadFmPk_send(int fd, int fmpks_pos) +{ + saacproto_CreateHeader(saacproto.work, "ACLoadFmPk"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmpks_pos), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + + +void saacproto_ACSendFmPk_send(int fd, int toindex, int PkFlg, int fmpks_pos, char *msg) +{ + saacproto_CreateHeader(saacproto.work, "ACSendFmPk"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int(fmpks_pos), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int( toindex), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_int( PkFlg), saacproto.workbufsize); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(msg), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} +#endif + +void saacproto_ACAuctionSold_send(int fd, char *data) +{ + saacproto_CreateHeader(saacproto.work, "ACAuctionSold"); + saacproto_strcatsafe(saacproto.work, saacproto_mkstr_string(data), saacproto.workbufsize); + saacproto_Send(fd, saacproto.work); +} + + +extern char saacretfunc[255]; +#ifdef _ABSOLUTE_DEBUG +extern int lastfunctime; +#endif +int saacproto_ClientDispatchMessage(int fd ,char*line) +{ + int msgid; + char funcname[255]; + saacproto_strcpysafe( saacproto.work , line, saacproto.workbufsize ); + saacproto_splitString( saacproto.work); + saacproto_GetMessageInfo( &msgid , funcname , sizeof(funcname),saacproto.token_list); + strcpy( saacretfunc , funcname ); +#ifdef _ABSOLUTE_DEBUG + lastfunctime=1; +#endif + if( strcmp( funcname , "ACGmsvDownRequest" ) == 0 ){ + int min; + min = saacproto_demkstr_int( saacproto.token_list[2] ); + saacproto_ACGmsvDownRequest_recv( fd,min); + return 0; + } + + if( strcmp( funcname , "ACServerLogin" ) == 0 ){ + char* result; + char* data; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + saacproto_ACServerLogin_recv( fd,result,data); + return 0; + } + + if( strcmp( funcname , "ACCharList" ) == 0 ){ + char* result; + char* output; + int id; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + output = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACCharList_recv( fd,result,output,id); + return 0; + } + + if( strcmp( funcname , "ACCharLoad" ) == 0 ){ + char* result=NULL; + char* data=NULL; + int id; +#ifdef _NEWSAVE + int saveindex; +#endif + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + if( data == NULL ) return 0; + if( result == NULL ) return 0; + +#ifdef _NEWSAVE + saveindex = saacproto_demkstr_int( saacproto.token_list[5] ); + saacproto_ACCharLoad_recv( fd,result,data,id,saveindex); +#else + saacproto_ACCharLoad_recv( fd,result,data,id, -1); +#endif + return 0; + } + + if( strcmp( funcname , "ACCharSave" ) == 0 ){ + char* result; + char* data; + int id; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACCharSave_recv( fd,result,data,id); + return 0; + } + + if( strcmp( funcname , "ACCharDelete" ) == 0 ){ + char* result; + char* data; + int id; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACCharDelete_recv( fd,result,data,id); + return 0; + } + + if( strcmp( funcname , "ACLock" ) == 0 ){ + char* result; + char* data; + int id; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACLock_recv( fd,result,data,id); + return 0; + } + +#ifdef _WAEI_KICK + if( strcmp( funcname , "ACKick" ) == 0 ){ + int act; + char* data; + int id; + act = saacproto_demkstr_int( saacproto.token_list[2] ); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACKick_recv( fd, act, data, id); + return 0; + } +#endif + +#ifdef _CHAR_POOLITEM + + if( strcmp( funcname , "ACSavePoolItem" ) == 0 ){ + char* result; + char* data; + int id; + + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACCharSavePoolItem_recv( fd, result, data, id); + return 0; + } + + if( strcmp( funcname , "ACGetPoolItem" ) == 0 ){ + char* result; + char* data; + int id, npcid; + + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + npcid = saacproto_demkstr_int( saacproto.token_list[5] ); + saacproto_ACCharGetPoolItem_recv( fd, result, data, id, npcid); + return 0; + } +#endif + + +#ifdef _CHAR_POOLPET + + if( strcmp( funcname , "ACSavePoolPet" ) == 0 ){ + char* result; + char* data; + int id; + + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + saacproto_ACCharSavePoolPet_recv( fd, result, data, id); + return 0; + } + + if( strcmp( funcname , "ACGetPoolPet" ) == 0 ){ + char* result; + char* data; + int id, npcid; + + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id = saacproto_demkstr_int( saacproto.token_list[4] ); + npcid = saacproto_demkstr_int( saacproto.token_list[5] ); + saacproto_ACCharGetPoolPet_recv( fd, result, data, id, npcid); + return 0; + } +#endif + + if( strcmp( funcname , "ACUCheck" ) == 0 ){ + char* mem_id; + mem_id = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + saacproto_ACUCheck_recv( fd,mem_id); + return 0; + } +/* +354 :
  • servertoclient DBUpdateEntryString( string result, string table, string key, int msgid, int msgid2 );
    +355 : Ѩ ƻּص ئƥ ƻ +356 :
    +357 :
    string result +358 :
    successful failed +359 :
    string table +360 :
    +361 :
    int msgid +362 :
    +363 :
    int msgid2 +364 :
    +365 :
    +366 : +*/ + + if( strcmp( funcname , "DBUpdateEntryString" ) == 0 ){ + char* result; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + msgid = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[6] ); + saacproto_DBUpdateEntryString_recv( fd,result,table,key,msgid,msgid2); + return 0; + } +/* +379 :
  • servertoclient DBDeleteEntryString( string result, string table, string key , int msgid , int msgid2 );
    +380 : ٯ ޼ּ +381 :
    +382 :
    string result +383 :
    successful / failed +384 :
    string table +385 :
    +386 :
    string key +387 :
    +388 :
    int msgid +389 :
    +390 :
    int msgid2 +391 :
    +392 :
    +393 : +*/ + + if( strcmp( funcname , "DBDeleteEntryString" ) == 0 ){ + char* result; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + msgid = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[6] ); + saacproto_DBDeleteEntryString_recv( fd,result,table,key,msgid,msgid2); + return 0; + } +/* +406 :
  • servertoclient DBGetEntryString( string result, string value, string table, string key, int msgid, int msgid2 );
    +407 : ԻƼ߯Ի +408 :
    +409 :
    string result +410 :
    successful / failed +411 :
    string value +412 :
    +413 :
    string table +414 :
    +415 :
    string key +416 :
    +417 :
    int msgid +418 :
    +419 :
    int msgid2 +420 :
    +421 :
    +422 : +*/ + + if( strcmp( funcname , "DBGetEntryString" ) == 0 ){ + char* result; + char* value; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + value = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + msgid = saacproto_demkstr_int( saacproto.token_list[6] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[7] ); + saacproto_DBGetEntryString_recv( fd,result,value,table,key,msgid,msgid2); + return 0; + } +/* +445 :
  • servertoclient DBUpdateEntryInt( string result , string table, string key, int msgid, int msgid2 );
    +446 : DBUpdateEntry +447 :
    +448 :
    string result +449 :
    succesful/failed +450 :
    string table +451 :
    Ƥ ë +452 :
    string key +453 :
    ƽë +454 :
    int msgid, int msgid2 +455 :
    msgid ë߯ʣ +456 :
    +457 :

    +458 : +*/ + + if( strcmp( funcname , "DBUpdateEntryInt" ) == 0 ){ + char* result; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + msgid = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[6] ); + saacproto_DBUpdateEntryInt_recv( fd,result,table,key,msgid,msgid2); + return 0; + } +/* +473 :
  • servertoclient DBGetEntryRank( string result , int rank , int count, string table, string key, int msgid, int msgid2 );
    +474 : ë߯ʣ +475 :
    +476 :
    string result +477 :
    successful/failed +478 :
    int rank +479 :
    ˣ1ë£ +480 :
    int count +481 :
    ʹ ټ޼0շԪ£ +482 :
    string table +483 :
    Ƥ ë +484 :
    string key +485 :
    ƽë +486 :
    int msgid, int msgid2 +487 :
    msgid ë߯ +488 :
    +489 :

    +490 : +491 : +*/ + + if( strcmp( funcname , "DBGetEntryRank" ) == 0 ){ + char* result; + int rank; + int count; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + rank = saacproto_demkstr_int( saacproto.token_list[3] ); + count = saacproto_demkstr_int( saacproto.token_list[4] ); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[5] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[6] )); + msgid = saacproto_demkstr_int( saacproto.token_list[7] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[8] ); + saacproto_DBGetEntryRank_recv( fd,result,rank,count,table,key,msgid,msgid2); + return 0; + } +/* +504 :
  • servertoclient DBDeleteEntryInt( string result , string table, string key, int msgid, int msgid2 );
    +505 : ּ +506 :
    +507 :
    string result +508 :
    successful/failed +509 :
    string table +510 :
    Ƥ ë +511 :
    string key +512 :
    ƽë +513 :
    int msgid, int msgid2 +514 :
    msgid ë߯ +515 :
    +516 :

    +517 : +*/ + + if( strcmp( funcname , "DBDeleteEntryInt" ) == 0 ){ + char* result; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + msgid = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[6] ); + saacproto_DBDeleteEntryInt_recv( fd,result,table,key,msgid,msgid2); + return 0; + } +/* +530 :
  • servertoclient DBGetEntryInt( string result , int value , string table, string key, int msgid, int msgid2 );
    +531 : ޼ë +532 :
    +533 :
    string result +534 :
    successful/failed +535 :
    int value +536 :
    ּ +537 :
    string table +538 :
    Ƥ ë +539 :
    string key +540 :
    ƽë +541 :
    int msgid, int msgid2 +542 :
    msgid ë߯ +543 :
    +544 : +545 : +546 : +*/ + + if( strcmp( funcname , "DBGetEntryInt" ) == 0 ){ + char* result; + int value; + char* table; + char* key; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + value = saacproto_demkstr_int( saacproto.token_list[3] ); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + key = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + msgid = saacproto_demkstr_int( saacproto.token_list[6] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[7] ); + saacproto_DBGetEntryInt_recv( fd,result,value,table,key,msgid,msgid2); + return 0; + } +/* +562 :
  • servertoclient DBGetEntryByRank( string result , string list , string table, int msgid, int msgid2 );
    +563 : DBGetEntryByRank +564 :
    +565 :
    string result +566 :
    +567 :
    string list +568 :
    "RANK,KEY,SCORE,INFO|RANK,KEY,SCORE,INFO|...."
    +569 : RANKƥؤ£KEY˱ئȻµʧëȻ +570 : ƽSCOREѰƥʧƥؤ£ +571 :
    +572 : "1,RINGO,123465,data1|2,HOGE,4567,data2|2,FUCK,4567,data3"
    +573 : 2˷2³ئ£ +574 :
    string table +575 :
    Ƥ +576 :
    int msgid, int msgid2 +577 :
    +578 :
    +579 : +580 : +*/ + + if( strcmp( funcname , "DBGetEntryByRank" ) == 0 ){ + char* result; + char* list; + char* table; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + list = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + msgid = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[6] ); + saacproto_DBGetEntryByRank_recv( fd,result,list,table,msgid,msgid2); + return 0; + } +/* +593 :
  • servertoclient DBGetEntryByCount( string result , string list , string table, int count_start, int msgid, int msgid2 );
    +594 : DBGetEntryByCount +595 :
    +596 :
    string result +597 :
    SUCCESSFUL/FAILED +598 :
    string list +599 :
    1޼ؤԻ "INDEX,RANK,KEY,SCORE,INFO" 4ۼ +600 : ׬ƥؤԻľ "|" ƥئ£ѻ0 +601 : ٯ +602 :
    int num +603 :
    ʹԻʾ1ئ1ۣ2ئ2ۣ +604 :
    int msgid ,msgid2 +605 :
    ID. +606 :
    +607 : +*/ + + if( strcmp( funcname , "DBGetEntryByCount" ) == 0 ){ + char* result; + char* list; + char* table; + int count_start; + int msgid; + int msgid2; + result = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + list = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + table = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + count_start = saacproto_demkstr_int( saacproto.token_list[5] ); + msgid = saacproto_demkstr_int( saacproto.token_list[6] ); + msgid2 = saacproto_demkstr_int( saacproto.token_list[7] ); + saacproto_DBGetEntryByCount_recv( fd,result,list,table,count_start,msgid,msgid2); + return 0; + } +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC + if ( strcmp( funcname , "UpdataStele" ) == 0 ) { + char* token; + token = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + saacproto_UpdataStele_recv( fd , token) ; + return 0; + } + if ( strcmp( funcname , "S_UpdataStele" ) == 0 ) { + char* ocdkey; + char* oname; + char* ncdkey; + char* nname; + char* title; + int level; + int trns; + int floor; + ocdkey = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + oname = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + ncdkey = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + nname = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + title = saacproto_wrapStringAddr( saacproto_stringwrapper[5] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[6] )); + level = saacproto_demkstr_int( saacproto.token_list[7] ); + trns = saacproto_demkstr_int( saacproto.token_list[8] ); + floor = saacproto_demkstr_int( saacproto.token_list[9] ); + saacproto_S_UpdataStele_recv( fd , ocdkey , oname , ncdkey , nname , title , level , + trns , floor ); + return 0; + } +#endif +/* +621 :
  • servertoclient Broadcast( string id, string charname, string message );
    +622 : Broadcastʧӡձءةӡ߼˪ +623 :
    +624 :
    string id +625 :
    user ID +626 :
    string charname +627 :
    character name +628 :
    string message +629 :
    +630 :
    int flag +631 :
    1б巴 ˪ľئУ +632 :
    +633 : +*/ + + if( strcmp( funcname , "Broadcast" ) == 0 ){ + char* id; + char* charname; + char* message; + id = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + charname = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + message = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + saacproto_Broadcast_recv( fd,id,charname,message); + return 0; + } +/* +652 :
  • servertoclient Message( string id_from, string charname_from, string id_to, string charname_to, string message , int option , int mesgid );
    +653 : ʧӡձءةӡ嶪ë˪£ +654 :
    +655 :
    string id_from +656 :
    from ID +657 :
    string charname_from +658 :
    from character name +659 :
    string id_to +660 :
    to ID +661 :
    string charname_to +662 :
    to character name +663 :
    string message +664 :
    ⼰ +665 :
    int option +666 :
    (ë) +667 :
    int mesgid +668 :
    ID ʧӡ +669 :
    +670 : +*/ + + if( strcmp( funcname , "Message" ) == 0 ){ + char* id_from; + char* charname_from; + char* id_to; + char* charname_to; + char* message; + int option; + int mesgid; + id_from = saacproto_wrapStringAddr( saacproto_stringwrapper[1] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[2] )); + charname_from = saacproto_wrapStringAddr( saacproto_stringwrapper[2] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[3] )); + id_to = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + charname_to = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + message = saacproto_wrapStringAddr( saacproto_stringwrapper[5] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[6] )); + option = saacproto_demkstr_int( saacproto.token_list[7] ); + mesgid = saacproto_demkstr_int( saacproto.token_list[8] ); + saacproto_Message_recv( fd,id_from,charname_from,id_to,charname_to,message,option,mesgid); + return 0; + } + + // CoolFish: Family 2001/5/9 + if( strcmp( funcname, "ACAddFM") == 0){ + int fmindex, index, charfdid; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + fmindex = saacproto_demkstr_int(saacproto.token_list[3]); + index = saacproto_demkstr_int(saacproto.token_list[4]); + charfdid = saacproto_demkstr_int(saacproto.token_list[5]); + saacproto_ACAddFM_recv(fd, result, fmindex, charfdid, index); + return 0; + } + if( strcmp( funcname, "ACJoinFM") == 0){ + int charfdid, recv; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + recv = saacproto_demkstr_int(saacproto.token_list[3]); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACJoinFM_recv(fd, result, recv, charfdid); + return 0; + } + if( strcmp( funcname, "ACLeaveFM") == 0){ + int charfdid, resultflag; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + resultflag = saacproto_demkstr_int(saacproto.token_list[3]); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACLeaveFM_recv(fd, result, resultflag, charfdid); + return 0; + } + if( strcmp( funcname, "ACDelFM") == 0){ + int charfdid; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + charfdid = saacproto_demkstr_int(saacproto.token_list[3]); + saacproto_ACDelFM_recv(fd, result, charfdid); + return 0; + } + if( strcmp( funcname, "ACShowFMList") == 0){ + int fmnum; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + fmnum = saacproto_demkstr_int(saacproto.token_list[3]); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[3], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[4])); + saacproto_ACShowFMList_recv(fd, result, fmnum, data); + return 0; + } + + if( strcmp( funcname, "ACShowMemberList") == 0){ + int index, fmmemnum, fmacceptflag, fmjoinnum; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + index = saacproto_demkstr_int(saacproto.token_list[3]); + fmmemnum = saacproto_demkstr_int(saacproto.token_list[4]); + fmacceptflag = saacproto_demkstr_int(saacproto.token_list[5]); + fmjoinnum = saacproto_demkstr_int(saacproto.token_list[6]); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[6], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[7])); + +#ifdef _FAMILYBADGE_ + int badge = saacproto_demkstr_int(saacproto.token_list[8]); +#endif + saacproto_ACShowMemberList_recv(fd, result, index, fmmemnum, fmacceptflag, fmjoinnum, data +#ifdef _FAMILYBADGE_ + ,badge +#endif + ); + return 0; + } + if( strcmp( funcname, "ACFMDetail") == 0){ + int charfdid; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACFMDetail_recv(fd, result, data, charfdid); + return 0; + } + if( strcmp( funcname, "ACMemberJoinFM") == 0){ + int charfdid; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACMemberJoinFM_recv(fd, result, data, charfdid); + return 0; + } + if( strcmp( funcname, "ACMemberLeaveFM") == 0){ + int charfdid; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACMemberLeaveFM_recv(fd, result, data, charfdid); + return 0; + } + if( strcmp( funcname, "ACFMCharLogin") == 0){ + int charfdid, index, floor, fmdp, joinflag, fmsetupflag, flag, charindex; +#ifdef _PERSONAL_FAME // Arminius: + int charfame; +#endif +#ifdef _NEW_MANOR_LAW + int momentum; +#endif + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + index = saacproto_demkstr_int(saacproto.token_list[3]); + floor = saacproto_demkstr_int(saacproto.token_list[4]); + fmdp = saacproto_demkstr_int(saacproto.token_list[5]); + joinflag = saacproto_demkstr_int(saacproto.token_list[6]); + fmsetupflag = saacproto_demkstr_int(saacproto.token_list[7]); + flag = saacproto_demkstr_int(saacproto.token_list[8]); + charindex = saacproto_demkstr_int(saacproto.token_list[9]); +#ifdef _PERSONAL_FAME // Arminius: + charfame = saacproto_demkstr_int(saacproto.token_list[10]); + charfdid = saacproto_demkstr_int(saacproto.token_list[11]); + #ifdef _NEW_MANOR_LAW + momentum = saacproto_demkstr_int(saacproto.token_list[12]); + #endif + saacproto_ACFMCharLogin_recv(fd, result, index, floor, fmdp, + joinflag, fmsetupflag, flag, charindex, charfame, charfdid + #ifdef _NEW_MANOR_LAW + ,momentum + #endif + ); +#else + charfdid = saacproto_demkstr_int(saacproto.token_list[10]); + saacproto_ACFMCharLogin_recv(fd, result, index, floor, fmdp, + joinflag, fmsetupflag, flag, charindex, charfdid); +#endif + return 0; + } + if( strcmp( funcname, "ACFMCharLogout") == 0){ + int charfdid; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + charfdid = saacproto_demkstr_int(saacproto.token_list[3]); + saacproto_ACFMCharLogout_recv(fd, result, charfdid); + return 0; + } + if( strcmp( funcname, "ACFMReadMemo") == 0){ + int index, num, dataindex; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + index = saacproto_demkstr_int(saacproto.token_list[3]); + num = saacproto_demkstr_int(saacproto.token_list[4]); + dataindex = saacproto_demkstr_int(saacproto.token_list[5]); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[5], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[6])); + saacproto_ACFMReadMemo_recv(fd, result, index, num, dataindex, data); + return 0; + } + if( strcmp( funcname, "ACFMWriteMemo") == 0){ + int index; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + index = saacproto_demkstr_int(saacproto.token_list[3]); + saacproto_ACFMWriteMemo_recv(fd, result, index); + return 0; + } + if( strcmp( funcname, "ACFMPointList") == 0){ + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_ACFMPointList_recv(fd, result, data); + return 0; + } + + + if( strcmp( funcname, "ACSetFMPoint") == 0){ + int charfdid, r; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + r = saacproto_demkstr_int(saacproto.token_list[3]); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACSetFMPoint_recv(fd, result, r, charfdid); + return 0; + } + if( strcmp( funcname, "ACFixFMPoint") == 0){ + int r; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + r = saacproto_demkstr_int(saacproto.token_list[3]); + saacproto_ACFixFMPoint_recv(fd, result, r); + return 0; + } + if( strcmp( funcname, "ACFMAnnounce") == 0){ + int fmindex, index, color, kindflag; + char *result, *fmname, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + fmname = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + fmindex = saacproto_demkstr_int(saacproto.token_list[4]); + index = saacproto_demkstr_int(saacproto.token_list[5]); + kindflag = saacproto_demkstr_int(saacproto.token_list[6]); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[6], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[7])); + color = saacproto_demkstr_int(saacproto.token_list[8]); + saacproto_ACFMAnnounce_recv(fd, result, fmname, fmindex, index, kindflag, data, color); + return 0; + } + if( strcmp( funcname, "ACShowTopFMList") == 0){ + int num, kindflag; + char *result, *data; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + kindflag = saacproto_demkstr_int(saacproto.token_list[3]); + num = saacproto_demkstr_int(saacproto.token_list[4]); + data = saacproto_wrapStringAddr(saacproto_stringwrapper[4], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[5])); + saacproto_ACShowTopFMList_recv(fd, result, kindflag, num, data); + return 0; + } + if( strcmp( funcname, "ACFixFMData") == 0){ + int kindflag, charfdid; + char *result, *data1, *data2; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + kindflag = saacproto_demkstr_int(saacproto.token_list[3]); + data1 = saacproto_wrapStringAddr(saacproto_stringwrapper[3], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[4])); + data2 = saacproto_wrapStringAddr(saacproto_stringwrapper[4], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[5])); + charfdid = saacproto_demkstr_int(saacproto.token_list[6]); + saacproto_ACFixFMData_recv(fd, result, kindflag, data1, data2, charfdid); + return 0; + } + if( strcmp( funcname, "ACFixFMPK") == 0){ + int data, winindex, loseindex; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + data = saacproto_demkstr_int(saacproto.token_list[3]); + winindex = saacproto_demkstr_int(saacproto.token_list[4]); + loseindex = saacproto_demkstr_int(saacproto.token_list[5]); + saacproto_ACFixFMPK_recv(fd, result, data, winindex, loseindex); + return 0; + } + if( strcmp( funcname, "ACGMFixFMData") == 0){ + int charfdid; + char *result, *fmname; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + fmname = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + charfdid = saacproto_demkstr_int(saacproto.token_list[4]); + saacproto_ACGMFixFMData_recv(fd, result, fmname, charfdid); + return 0; + } + if( strcmp( funcname, "ACGetFMData") == 0){ + int kindflag, charfdid, data; + char *result; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + kindflag = saacproto_demkstr_int(saacproto.token_list[3]); + data = saacproto_demkstr_int(saacproto.token_list[4]); + charfdid = saacproto_demkstr_int(saacproto.token_list[5]); + saacproto_ACGetFMData_recv(fd, result, kindflag, data, charfdid); + return 0; + } + if( strcmp( funcname, "ACFMClearPK") == 0){ + int fmindex, index; + char *result, *fmname; + result = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + fmname = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + fmindex = saacproto_demkstr_int(saacproto.token_list[4]); + index = saacproto_demkstr_int(saacproto.token_list[5]); + saacproto_ACFMClearPK_recv(fd, result, fmname, fmindex, index); + return 0; + } + // Arminius 7.26 manor pk acknowledge + if( strcmp( funcname, "ACManorPKAck") == 0){ + char *data; + data = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + saacproto_ACManorPKAck_recv(fd, data); + return 0; + } + +#ifdef _ACFMPK_LIST + if( strcmp( funcname, "ACLoadFmPk") == 0){ + char *data; + data = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + saacproto_ACLoadFmPk_recv( fd, data); + return 0; + } + if( strcmp( funcname, "ACSendFmPk") == 0){ + int toindex, flg; + toindex = saacproto_demkstr_int( saacproto.token_list[2] ); + flg =saacproto_demkstr_int( saacproto.token_list[3] ); + saacproto_ACSendFmPk_recv( fd, toindex, flg); + return 0; + } +#endif +#ifdef _SEND_EFFECT // WON ADD ACѩЧ + if( strcmp(funcname, "EFFECT") == 0){ + char *effect; + effect = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + print("\n AC send to GS weather effect !!"); + + CHAR_CHAT_DEBUG_sendeffect( fd, effect ); + return 0; + } +#endif + +#ifdef _NEW_VIP_SHOP + if( strcmp( funcname , "QueryPoint" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + int point = saacproto_demkstr_int( saacproto.token_list[3] ); + saacproto_QueryPoint_recv(fd, point); + return 0; + } + + if( strcmp( funcname , "NewVipShop" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + int point = saacproto_demkstr_int( saacproto.token_list[3] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[3], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[4])); + int flag = saacproto_demkstr_int( saacproto.token_list[5] ); + saacproto_NewVipShop_recv(fd, point, data, flag); + return 0; + } +#endif + +#ifdef _ITEM_PET_LOCKED + if( strcmp( funcname , "ItemPetLocked" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + int flag = saacproto_demkstr_int( saacproto.token_list[3] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[3], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[4])); + saacproto_ItemPetLocked_recv(fd, flag, data); + return 0; + } + + if( strcmp( funcname , "ItemPetLockedPasswd" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_ItemPetLockedPasswd_recv(fd, data); + return 0; + } +#endif + +#ifdef _ONLINE_COST + if( strcmp( funcname , "OnlineCost" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_OnlineCost_recv(fd, data); + return 0; + } +#endif + +#ifdef _SQL_BUY_FUNC + if( strcmp( funcname , "OnlineBuy" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_OnlineBuy_recv(fd, data); + return 0; + } +#endif + +#ifdef _VIPPOINT_OLD_TO_NEW + if( strcmp( funcname , "OldToNew" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_OldToNew_recv(fd, data); + return 0; + } +#endif + +#ifdef _FORMULATE_AUTO_PK + if( strcmp( funcname , "FormulateAutoPk" ) == 0 ){ + int fd = saacproto_demkstr_int( saacproto.token_list[2] ); + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[2], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[3])); + saacproto_FormulateAutoPk_recv(fd, data); + return 0; + } +#endif + +#ifdef _LOTTERY_SYSTEM + if( strcmp( funcname , "LotterySystem" ) == 0 ){ + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + saacproto_LotterySystem_recv(data); + return 0; + } +#endif + +#ifdef _ALL_SERV_SEND + if( strcmp( funcname , "AllServSend" ) == 0 ){ + char *data = saacproto_wrapStringAddr(saacproto_stringwrapper[1], saacproto.workbufsize, saacproto_demkstr_string(saacproto.token_list[2])); + saacproto_AllServSend_recv(data); + return 0; + } +#endif + +#ifdef _ANGEL_SUMMON + if( strcmp( funcname , "ACMissionTable" ) == 0 ){ + int num; + int type; + char* data; + //int charaindex; + char* angelinfo; + + num = saacproto_demkstr_int( saacproto.token_list[2] ); + type = saacproto_demkstr_int( saacproto.token_list[3] ); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + //charaindex = saacproto_demkstr_int( saacproto.token_list[5] ); + angelinfo = saacproto_wrapStringAddr( saacproto_stringwrapper[4] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[5] )); + + //saacproto_ACMissionTable_recv( fd, num, type, data, charaindex); + saacproto_ACMissionTable_recv( fd, num, type, data, angelinfo); + return 0; + } +#endif + +#ifdef _TEACHER_SYSTEM + if(strcmp(funcname,"ACCheckCharacterOnLine") == 0){ + int flag,charaindex,iOnline; + char* data; + + charaindex = saacproto_demkstr_int(saacproto.token_list[2]); + iOnline = saacproto_demkstr_int(saacproto.token_list[3]); + data = saacproto_wrapStringAddr( saacproto_stringwrapper[3] , saacproto.workbufsize , saacproto_demkstr_string( saacproto.token_list[4] )); + flag = saacproto_demkstr_int( saacproto.token_list[5] ); + saacproto_ACCheckCharacterOnLine_recv(fd,charaindex,iOnline,data,flag); + return 0; + } +#endif + + if( strcmp( funcname , "ACCharLogin" ) == 0 ){ + int flag; + int clifd; + clifd = saacproto_demkstr_int( saacproto.token_list[2] ); + flag = saacproto_demkstr_int( saacproto.token_list[3] ); + saacproto_ACCharLogin_recv(fd, clifd, flag); + + return 0; + } + printf("޷ҵSAACӿ:%s",funcname); + return -1; +} +void saacproto_SetClientLogFiles( char *r , char *w ) +{ + saacproto_strcpysafe( saacproto_readlogfilename , r , sizeof( saacproto_readlogfilename ) ); + saacproto_strcpysafe( saacproto_writelogfilename , w , sizeof( saacproto_writelogfilename ) ); +} +int saacproto_InitClient( int (*writefunc)(int,char*,int) ,int bufsiz ,int fd) +{ + int i; + if( (void*)writefunc == NULL){saacproto.write_func = saacproto_default_write_wrap;} else {saacproto.write_func = writefunc;} + saacproto_AllocateCommonWork(bufsiz); + saacproto_stringwrapper = (char**)calloc( 1,sizeof(char*) * MAXLSRPCARGS); + if(saacproto_stringwrapper ==NULL)return -1; + memset( saacproto_stringwrapper , 0, sizeof(char*)*MAXLSRPCARGS); + for(i=0;i +#include +#include +#ifndef WIN32 +#include +#include +#endif +#include "saacproto_util.h" +//ttom +1 +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + +#ifdef saacproto__ENCRYPT +long saacproto_ringoCompressor( unsigned char *code , long codelen , unsigned char *text , long textlen); +long saacproto_ringoDecompressor( unsigned char *text , long textlen , unsigned char *code , long codelen); +#endif +/* + lsrpc routines +*/ +int saacproto_AllocateCommonWork(int bufsiz) +{ + saacproto.workbufsize = bufsiz; + saacproto.work = NULL; + saacproto.arraywork = NULL; + saacproto.escapework = NULL; + saacproto.val_str = NULL; + saacproto.token_list = NULL; + saacproto.cryptwork = NULL; + saacproto.jencodecopy = NULL; + saacproto.jencodeout = NULL; + saacproto.compresswork = NULL; + saacproto.work = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.arraywork = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.escapework = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.val_str = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.token_list = (char**)calloc( 1, saacproto.workbufsize *sizeof( char** ) ); + saacproto.cryptwork = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.jencodecopy = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.jencodeout = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.compresswork = (char*)calloc( 1, saacproto.workbufsize * 3 ); + memset( saacproto.work , 0, saacproto.workbufsize ); + memset( saacproto.arraywork , 0, saacproto.workbufsize ); + memset( saacproto.escapework , 0, saacproto.workbufsize ); + memset( saacproto.val_str , 0, saacproto.workbufsize ); + memset( (char*)saacproto.token_list ,0, saacproto.workbufsize*sizeof(char**) ); + memset( saacproto.cryptwork , 0, saacproto.workbufsize*3 ); + memset( saacproto.jencodecopy , 0, saacproto.workbufsize*3 ); + memset( saacproto.jencodeout , 0, saacproto.workbufsize*3 ); + memset( saacproto.compresswork , 0, saacproto.workbufsize*3 ); + if( saacproto.work == NULL || + saacproto.arraywork == NULL || + saacproto.escapework == NULL || + saacproto.val_str == NULL || + saacproto.token_list == NULL || + saacproto.cryptwork == NULL || + saacproto.jencodecopy == NULL || + saacproto.jencodeout == NULL || + saacproto.compresswork == NULL ){ + free( saacproto.work);free( saacproto.val_str); + free( saacproto.escapework);free( saacproto.arraywork ); + free( saacproto.token_list);free( saacproto.cryptwork ); + free( saacproto.jencodecopy);free( saacproto.jencodeout ); + free( saacproto.compresswork ); + return -1; + } + return 0; +} + +int saacproto_StringRest() +{ + return 0; +/* free( saacproto.work); + saacproto.work = NULL; + saacproto.work = (char*)calloc( 1, saacproto.workbufsize ); + if( saacproto.work == NULL ) return -1; + return sizeof( saacproto.work); +*/ +} + +/********** + Get message information from a network input +**********/ +void saacproto_GetMessageInfo( int *id , char *funcname , int len, char **tk ) +{ + if( tk[0] == NULL || tk[1] == NULL ){ + *id = 0; + saacproto_strcpysafe( funcname , "" , len ); + return; + } + *id = strtoul( tk[0] ,NULL,10); + saacproto_strcpysafe( funcname , tk[1] , len ); + return; +} +/******************************************** + string utilities +*********************************************/ +void saacproto_strcpysafe( char *dest, char *src, int maxlen ) +{ + int i; + for(i=0;i (int)( saacproto.workbufsize*3-2) ){ + fprintf( stderr, "lsgen: badly configured work buflen\n" ); + exit(1); + } + if( (flag%2) == 1 ) flag ++; + saacproto.compresswork[0] = flag; + memcpy( saacproto.compresswork+1,src,srclen ); + compressed_l = srclen + 1; + } else { + if((flag%2)==0)flag++; + saacproto.compresswork[0] = flag; + compressed_l = saacproto_ringoCompressor( + (unsigned char*)saacproto.compresswork + 1 , + (long)saacproto.workbufsize*3 - 1, + (unsigned char*)src , + (long)strlen(src) ) + 1; /* be careful! */ + } + /* return empty line if error or buffer excess */ + if( compressed_l <= 0 ){ + saacproto_strcpysafe( out , "\n" , maxoutlen ); + return; + } + memcpy( saacproto.jencodecopy ,saacproto.compresswork ,compressed_l ); + saacproto_jEncode( saacproto.jencodecopy , compressed_l , JENCODE_KEY , + saacproto.jencodeout, &jencodedlen , saacproto.workbufsize*3 -1 ); + saacproto_encode64( (unsigned char*)saacproto.jencodeout , jencodedlen, (unsigned char*)out ); +} +/* translate code64 text to original lsrpc text */ +static void saacproto_decodeString( char *src , char *out ) +{ + int compressed_l =0, outlen64; + int l; + long decompressed_l = 0; + /* copy src to copybuffer because jencoder modifies the input buffer */ + l = strlen( src ); + if( src[l-1]=='\n' || src[l-1]=='\r' )src[l-1]=0; + if( src[l-2]=='\n' || src[l-2]=='\r' )src[l-2]=0; + outlen64 = saacproto_decode64( (unsigned char*)src , (unsigned char*)saacproto.jencodecopy ); + saacproto_jDecode( saacproto.jencodecopy , outlen64 , JENCODE_KEY, + saacproto.compresswork , &compressed_l); + /*out[outlen]=0; PENDING*/ + if( (saacproto.compresswork[0] % 2 ) == 0 ){ + if( compressed_l <= 0 ){ + decompressed_l = 0; + fprintf( stderr, "LSRPC: too short:[%s]\n", src ); + } else { + memcpy( out, saacproto.compresswork+1, compressed_l -1 ); + decompressed_l = compressed_l -1; + } + } else { + decompressed_l = + saacproto_ringoDecompressor( (unsigned char*)out , + (long)saacproto.workbufsize , + (unsigned char*)saacproto.compresswork+1 , + (long)compressed_l -1 ); + } + out[decompressed_l] = 0; +} +/* followings are taken from code64.c */ +char saacproto_charset[64]={ + 'A','B','C','D', 'E','F','G','H', + 'I','J','K','L', 'M','N','O','P', + 'Q','R','S','T', 'U','V','W','X', + 'Y','Z','a','b', 'c','d','e','f', + 'g','h','i','j', 'k','l','m','n', + 'o','p','q','r', 's','t','u','v', + 'w','x','y','z', '0','1','2','3', + '4','5','6','7', '8','9','+','-' +}; +char saacproto_reversecharset[256]={ + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,62, 0,63,0,0, + 52,53,54,55, 56,57,58,59, + 60,61,0,0, 0,0,0,0, + 0,0,1,2, 3,4,5,6, + 7,8,9,10, 11,12,13,14, + 15,16,17,18, 19,20,21,22, + 23,24,25,0, 0,0,0,0, + 0,26,27,28, 29,30,31,32, + 33,34,35,36, 37,38,39,40, + 41,42,43,44, 45,46,47,48, + 49,50,51,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0 +}; + +static void saacproto_encode64( unsigned char *in , int len , unsigned char *out ) +{ + int i; + int use_bytes; + int address = 0; + out[0] = 0; + for(i=0;;i+=3){ + unsigned char in1 , in2 , in3; + unsigned char out1 ,out2 , out3 , out4; + if( i >= len ) break; + if( i >= (len-1)){ /* the last letter ( to be thrown away ) */ + in1 = in[i] & 0xff; + in2 = in3 = 0; + use_bytes = 2; + } else if( i >= (len-2)){ /* the last 2 letters ( process only 1 byte)*/ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = 0; + use_bytes = 3; + } else { /* there are more or equal than 3 letters */ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = in[i+2] & 0xff; + use_bytes = 4; + } + out1 = ((in1 & 0xfc)>>2) & 0x3f; + out2 = ((in1 & 0x03)<<4) | ((( in2 & 0xf0)>>4)&0x0f); + out3 = ((in2 & 0x0f)<<2) | ((( in3 & 0xc0)>>6)&0x03); + out4 = (in3 & 0x3f ); + if( use_bytes >= 2 ){ + out[address++] = saacproto_charset[out1]; + out[address++] = saacproto_charset[out2]; + out[address]=0; + } + if( use_bytes >= 3 ){ + out[address++] = saacproto_charset[out3]; + out[address]=0; + } + if( use_bytes >= 4 ){ + out[address++] = saacproto_charset[out4]; + out[address]=0; + } + } +} +/* + * Decode it + * char *in : encoded ascii chars + * char *out : decoded( output) + * return value : output byte count + * + * note: no need to have bigger buffer. because output is to + * be smaller than input string size + */ +static int saacproto_decode64( unsigned char *in , unsigned char *out ) +{ + unsigned char in1 , in2 , in3 , in4; + unsigned char out1 , out2 , out3; + int use_bytes; + int address= 0; + int i; + for(i=0;;i+=4 ){ + if( in[i] == 0 ){ + break; + } else if( in[i+1] == 0 ){ /* the last letter */ + break; + } else if( in[i+2] == 0 ){ /* the last 2 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = in4 = 0; + use_bytes = 1; + } else if( in[i+3] == 0 ){ /* the last 3 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = saacproto_reversecharset[in[i+2]]; + in4 = 0; + use_bytes = 2; + } else { /* process 4 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = saacproto_reversecharset[in[i+2]]; + in4 = saacproto_reversecharset[in[i+3]]; + use_bytes = 3; + } + out1 = (in1<<2) | (((in2 & 0x30)>>4)&0x0f) ; + out2 = ((in2 & 0x0f )<<4) | ((( in3 & 0x3c)>>2)&0x0f); + out3 = ( (in3 &0x03)<<6) | ( in4 & 0x3f ); + if( use_bytes >= 1 ){ + out[address++] = out1; + } + if( use_bytes >= 2 ){ + out[address++] = out2; + } + if( use_bytes >= 3 ){ + out[address++] = out3; + } + if( use_bytes != 3 ){ + break; + } + } + return address; +} + +/* followings are taken from Jencode.c by jun */ +static void saacproto_jEncode(char *src,int srclen,int key,char *encoded,int *encodedlen,int maxencodedlen) +{ + char sum=0; + int i; + if(srclen+1 > maxencodedlen){ + *encodedlen = maxencodedlen; + for(i=0;i<(*encodedlen);i++)encoded[i] = src[i]; + } + if(srclen+1 <= maxencodedlen){ + *encodedlen=srclen+1; + for(i=0;i i) encoded[i] = src[i] + sum*((i*i)%3); + if(abs((key%srclen)) == i) encoded[i] = sum; + if(abs((key%srclen)) < i) encoded[i] = src[i-1] + sum*((i*i)%7); + } + } +} +static void saacproto_jDecode(char *src,int srclen,int key,char *decoded,int *decodedlen) +{ + char sum=0; + int i; + *decodedlen=srclen-1; + if( *decodedlen == 0 ){ + return; /* return error if length is 0 */ + } + sum = src[abs(key%(*decodedlen))]; + for(i=0;i i) decoded[i] = src[i] - sum*((i*i)%3); + if(abs((key%(*decodedlen))) < i) decoded[i-1] = src[i] - sum*((i*i)%7); + } + for(i=0;i<(*decodedlen);i++){ + if(((key%7) == (i%5))||((key%2) == (i%2)))decoded[i] = ~decoded[i]; + } +} + +/*****************************************************************/ +/* Compress / Decompress routine */ +/*****************************************************************/ +#define B00000000 0 +#define B00000001 1 +#define B00000010 2 +#define B00000011 3 +#define B00000100 4 +#define B00000101 5 +#define B00000110 6 +#define B00000111 7 +#define B00001000 8 +#define B00001001 9 +#define B00001010 10 +#define B00001011 11 +#define B00001100 12 +#define B00001101 13 +#define B00001110 14 +#define B00001111 15 +#define B00010000 16 +#define B00010001 17 +#define B00010010 18 +#define B00010011 19 +#define B00010100 20 +#define B00010101 21 +#define B00010110 22 +#define B00010111 23 +#define B00011000 24 +#define B00011001 25 +#define B00011010 26 +#define B00011011 27 +#define B00011100 28 +#define B00011101 29 +#define B00011110 30 +#define B00011111 31 +#define B00100000 32 +#define B00100001 33 +#define B00100010 34 +#define B00100011 35 +#define B00100100 36 +#define B00100101 37 +#define B00100110 38 +#define B00100111 39 +#define B00101000 40 +#define B00101001 41 +#define B00101010 42 +#define B00101011 43 +#define B00101100 44 +#define B00101101 45 +#define B00101110 46 +#define B00101111 47 +#define B00110000 48 +#define B00110001 49 +#define B00110010 50 +#define B00110011 51 +#define B00110100 52 +#define B00110101 53 +#define B00110110 54 +#define B00110111 55 +#define B00111000 56 +#define B00111001 57 +#define B00111010 58 +#define B00111011 59 +#define B00111100 60 +#define B00111101 61 +#define B00111110 62 +#define B00111111 63 +#define B01000000 64 +#define B01000001 65 +#define B01000010 66 +#define B01000011 67 +#define B01000100 68 +#define B01000101 69 +#define B01000110 70 +#define B01000111 71 +#define B01001000 72 +#define B01001001 73 +#define B01001010 74 +#define B01001011 75 +#define B01001100 76 +#define B01001101 77 +#define B01001110 78 +#define B01001111 79 +#define B01010000 80 +#define B01010001 81 +#define B01010010 82 +#define B01010011 83 +#define B01010100 84 +#define B01010101 85 +#define B01010110 86 +#define B01010111 87 +#define B01011000 88 +#define B01011001 89 +#define B01011010 90 +#define B01011011 91 +#define B01011100 92 +#define B01011101 93 +#define B01011110 94 +#define B01011111 95 +#define B01100000 96 +#define B01100001 97 +#define B01100010 98 +#define B01100011 99 +#define B01100100 100 +#define B01100101 101 +#define B01100110 102 +#define B01100111 103 +#define B01101000 104 +#define B01101001 105 +#define B01101010 106 +#define B01101011 107 +#define B01101100 108 +#define B01101101 109 +#define B01101110 110 +#define B01101111 111 +#define B01110000 112 +#define B01110001 113 +#define B01110010 114 +#define B01110011 115 +#define B01110100 116 +#define B01110101 117 +#define B01110110 118 +#define B01110111 119 +#define B01111000 120 +#define B01111001 121 +#define B01111010 122 +#define B01111011 123 +#define B01111100 124 +#define B01111101 125 +#define B01111110 126 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 +/* masks for first byte ( write )*/ +int saacproto_modifymask_first[8][9]={ + {0, B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111},/* mod 0*/ + {0, B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111},/* mod 1*/ + {0, B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111},/* mod 2*/ + {0, B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111},/* mod 3*/ + {0, B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 4*/ + {0, B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 5*/ + {0, B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 6*/ + {0, B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 7*/ +}; +/* masks for second byte ( write ) */ +int saacproto_modifymask_second[8][9]={ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},/* mod 0 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001},/* mod 1 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011},/* mod 2 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111},/* mod 3 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111},/* mod 4 */ + {0, B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111},/* mod 5 */ + {0, B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111},/* mod 6 */ + {0, B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111},/* mod 7 */ +}; +/* + * used by bitstream routines + */ +int bitstream_maxbyte, bitstream_bitaddr ; +char *bitstream_buf; +/* initialize bitstream for output */ +static int initOutputBitStream( char *buf ,int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + memset( buf,0, buflen); + return 0; +} +/* initialize bitstream for input */ +static int initInputBitStream( char *buf , int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + return 0; +} +/* + * read from bit stream. used only from 1 bit to 8 bits + * this is a base routine + */ +static unsigned int readInputBitStreamBody( int bwidth ) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return if excess */ + if( byteaddr >= bitstream_maxbyte)return 0; + if( bwidth >= 1 && bwidth <= 8){ + int b1 = (( bitstream_buf[byteaddr] & saacproto_modifymask_first[mod][bwidth] )>>mod); + int b2 = (( bitstream_buf[byteaddr+1] & saacproto_modifymask_second[mod][bwidth])<<(8-mod)); + bitstream_bitaddr += bwidth; + return b1 | b2; + } else { + return 0; + } +} +/* + * read from bit stream. used from 1 bit to 32 bits + * + */ +static unsigned int readInputBitStream( int bwidth ) +{ + if( bwidth <= 0 ){ + return 0; + } else if( bwidth >= 1 && bwidth <= 8 ){ + return readInputBitStreamBody( bwidth ); + } else if( bwidth >= 9 && bwidth <= 16 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody( bwidth-8); + return first + (second << 8 ); + } else if( bwidth >= 17 && bwidth <= 24 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ); + } else if( bwidth >= 25 && bwidth <= 32 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(8); + unsigned int forth = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ) + ( forth << 24 ); + } + return 0; +} +/* + * write to a bitstream. only used from 1 bit to 8 bits + * this is a base routine. + */ +static int writeOutputBitStreamBody( int bwidth , unsigned char b) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return error if excess */ + if( bitstream_maxbyte <= (byteaddr+1)) return -1; + bitstream_buf[byteaddr] &= saacproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr] |= (b << mod) & saacproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr+1] &= saacproto_modifymask_second[mod][bwidth]; + bitstream_buf[byteaddr+1] |= (b>>(8-mod))& saacproto_modifymask_second[mod][bwidth]; + bitstream_bitaddr += bwidth; + return byteaddr+1; +} +/* + * write to a bitstream. used from 1 bits to 32 bits + * returns -1 if error or buffer excession + */ +static int writeOutputBitStream( int bwidth, unsigned int dat) +{ + int ret; + if( bwidth <= 0){ + return -1; + } else if( bwidth >= 1 && bwidth <= 8 ){ + if((ret=writeOutputBitStreamBody( bwidth , (unsigned char)dat))<0)return -1; + } else if( bwidth > 8 && bwidth <= 16 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth - 8 , ( unsigned char)((dat>>8)&0xff)))<0)return -1; + } else if( bwidth > 16 && bwidth <= 24 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-16,(unsigned char)((dat>>16)&0xff)))<0)return -1; + } else if( bwidth > 24 && bwidth <= 32 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>16)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-24,(unsigned char)((dat>>24)&0xff)))<0)return -1; + } else { + return -1; + } + return ret; +} +#define CHAR_SIZE 256 +#define NODE_SIZE 512 +#define BITS_LEN 9 /* 9 bit lzw compression */ +typedef struct { + unsigned char chr; + int parent; + int brother; + int child; +}NODE; +long saacproto_ringoCompressor( unsigned char *code , long codelen , + unsigned char *text , long textlen) +{ + NODE node[NODE_SIZE]; + int freeNode; + int w,k; /* used in this algo */ + int textind; /* index to text buffer */ + int i; + int position = 0; /* indicates the last byte of code buffer */ + if( textlen <= 0 ) return -1; + initOutputBitStream((char*) code,codelen); + /* fill characters ( 0 ~ 255 ) in the beggining part of + Node list */ + for(i=0; i<= CHAR_SIZE; i++){ + node[i].chr = (unsigned char)i; + node[i].brother = i + 1; + node[i].parent = 0; + node[i].child = 0; + } + node[CHAR_SIZE].brother = 0; + freeNode = CHAR_SIZE + 1; + w = text[0]; + textind = 1; + while(1){ + int rv; + if( textind >= textlen ){ + k = CHAR_SIZE; /* indicates EOF */ + } else { + k = text[textind]; + } + /* search if pattern 'wk' is registered or not. */ + rv = node[w].child; + while(1){ + if( rv <= 0 ) break; + if( node[rv].chr == k ) break; + rv = node[rv].brother; + } + if( rv > 0 ){ + /* found it */ + w = rv; + } else { + position = writeOutputBitStream( BITS_LEN ,w ); + /* return if buffer excession */ + if( position > codelen ) return -1; + /* register pattern 'wk' in the dictionary */ + if( freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = k; + } + if( textind == ( textlen + 1 ) ) break; + textind++; + } + return position; +} + +/* + * Decoder. + * return -1 if buffer excession. Notice buffer text + * is modified . + */ +long saacproto_ringoDecompressor( unsigned char *text , long textlen , + unsigned char *code , long codelen) +{ + NODE node[NODE_SIZE]; + int stack[NODE_SIZE]; + int sp; + int freeNode; + int len; + int i; + int k = 0; + int w = 0; + if( codelen <= 0 ) return -1; + initInputBitStream( (char*)code , codelen ); + for(i=0;i= freeNode ){ + stack[sp++] = k; /* exception */ + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) )return -1; + k = w; + } else { + k = rv; + } + while(k> CHAR_SIZE ){ + if( k >= (sizeof(node)/sizeof(node[0]))) return -1; + stack[sp++] = node[k].chr; + k = node[k].parent; + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + } + stack[sp++] = k; + if( sp >= ( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + /* output to text buffer from stack.*/ + while(sp){ + if( ++len > textlen ) return -1; + *text++ = stack[--sp]; + } + /* register the pattern 'wk'*/ + if( len > 1 && freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + if( w >= (sizeof(node)/sizeof(node[0])))return -1; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = rv; + } + return len; +} +#endif /* ifdef saacproto__ENCRYPT */ + +/* Convert 62-base digits to 10 digits */ +int saacproto_a62toi( char *a ) +{ + int ret = 0; + int minus ; + if( a[0] == '-' ){ + minus = -1; + a++; + } else { + minus = 1; + } + + while( *a != '\0' ) + { + ret *= 62; + if( '0' <= (*a) && (*a) <= '9' ) + ret += (*a)-'0'; + else + if( 'a' <= (*a) && (*a) <= 'z' ) + ret += (*a)-'a'+10; + else + if( 'A' <= (*a) && (*a) <= 'Z' ) + ret += (*a)-'A'+36; + else + return 0; + a++; + } + return ret * minus; +} + +/* Convert 10-base digits into 62-base digits. */ +char *saacproto_cnv10to62( int a, char *out, int outlen ) +{ + int i, j; + char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + int tmp[64]; + int src; + int minus; + int baselen = sizeof( base)-1; + if( a < 0 ){ + minus = 1; + a *= -1; + } else { + minus = 0; + } + /* special case */ + if( a < baselen) { + if( minus ){ + *(out) = '-'; + *(out+1) = base[a]; + *(out+2) = '\0'; + return (out); + } else { + *out = base[a]; + *(out+1) = '\0'; + return( out); + } + } + src = a; + for( i = 0; src >= baselen; i ++ ) { + tmp[i] = src % baselen; + src /= baselen; + } + i--; + if( minus ){ + *out = '-'; + *(out+1) = base[src]; + for( j = 2; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } else { + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } + *(out+j) = '\0'; + return( out); +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/shop.c b/石器时代服务器端最新完整源代码/Serv/gmsv/shop.c new file mode 100644 index 0000000..f3527bf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/shop.c @@ -0,0 +1,65 @@ +#include "version.h" +#include "autil.h" +#include "lssproto_serv.h" +#include "common.h" +#include +#include "buf.h" +#include "md5.h" +#include "shop.h" + +typedef struct tagShopData{ + char shopMd5[64]; + char *shopData; +}tagShopData1; + +tagShopData1 shopData[5]; + +void ShopData_Init() +{ + memset(&shopData,0,sizeof(tagShopData1)*5); +} + +void WriteShopData(char *data,int id) +{ + char szDigest[17]; + int len=strlen(data)+1; + if(shopData[id].shopData){ + freeMemory(shopData[id].shopData); + shopData[id].shopData=NULL; + } + if(*data!=0){ + shopData[id].shopData = (char*)allocateMemory(len); + memset(shopData[id].shopData,0,len); + memcpy(shopData[id].shopData,data,len); + MD5Digest(shopData[id].shopData,len-1,szDigest); + szDigest[16]='\0'; + int i ; + for(i=0;i<16;i++) + { + snprintf(shopData[id].shopMd5+i*2,sizeof(shopData[id].shopMd5+i*2),"%02X",(unsigned char)szDigest[i]); + } + shopData[id].shopMd5[32]='\0'; + }else{ + shopData[id].shopMd5[0]=0; + } +} + + +void lssproto_upshopdata_recv(int fd,char shop[5][1024]) +{ + int i=0; + for(i;i<5;i++){ + if(*shopData[i].shopMd5){ + if(strcmp(shopData[i].shopMd5,shop[i]) || !shop[i]){ + if(shopData[i].shopData){ + lssproto_UpShopData_send(fd,shopData[i].shopData,shopData[i].shopMd5,i); + } + } + } + } + lssproto_ShopOK_send(fd); +} + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/test.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/test.sh new file mode 100644 index 0000000..da6f50c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/test.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 3 + +#endif" > $OUT +make + +tar -zcvf /root/saserver/gmsv/gmsv_test.tar.gz /root/saserver/gmsv/gmsvjt /root/saserver/gmsv/setup.cf \ No newline at end of file diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/util.c b/石器时代服务器端最新完整源代码/Serv/gmsv/util.c new file mode 100644 index 0000000..ae24f72 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/util.c @@ -0,0 +1,1759 @@ +#include "version.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common.h" +#include "util.h" +#include "configfile.h" +#include +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + +/*----------------------------------------- + 깴ݱëǷ + ¦ѡ 缰 ٯ ʽľ + + windows , macintosh , unixָɱƥ£ + + windows : \r\n + macintosh : \n\r + unix : \n + + ׾ئ + macintosh : \r + ƥʣ + ľة깴 ٯԪئʻ + ݱƥʾ + -----------------------------------------*/ +void chompex( char *buf ) +{ + while( *buf ){ + if( *buf == '\r' || *buf == '\n' ){ + *buf='\0'; + } + buf++; + } +} + + + +/*---------------------------------------- + * 깴1 ٯëԻ + * ¦ + * src ٯ + ----------------------------------------*/ +void chop( char* src ) +{ + /* + * ׷ϱ ٯëԻ + */ + int length = strlen( src ); + if( length == 0 ) return; + src[length-1] = '\0'; +} + + +/*---------------------------------------- + * 깴 ٯë£۹ ٯë ϶ƥ£ + * ¦ + * src 缰 ٯ + * delim ٯ NULL ٯƥȻ + ----------------------------------------*/ +void dchop( char* src , char* del) +{ + int dellen, srclen; + int i; + BOOL delete=FALSE; + + /* + * src ǷƩͻʣ1 ٯ年 del ͻëƻ + * ľʣ۹ƻݼ ٯʣ + */ + + srclen = strlen( src ); + dellen = strlen( del ); + if( srclen == 0 || dellen == 0 ) return; + + for( i = 0 ; i < dellen ; i ++ ){ + if( src[srclen-1] == del[i] ){ + delete = TRUE; + break; + } + } + + /* ԻԻ */ + if( delete )src[srclen - 1] = '\0'; +} + + +/*---------------------------------------- + * dchopѣ ټ ٯë£۹ ٯë ϶ƥ£ + * ¦ + * src 缰 ٯ + * delim ٯ NULL ٯƥȻ + ----------------------------------------*/ +void pohcd( char* src , char* del) +{ + int dellen, srclen; + int i; + BOOL delete=FALSE; + + /* + * src󡾮Ʃͻʣ1 ٯ年 del ͻëƻ + * ľʣ۹ƻݼ ٯʣ + */ + + srclen = strlen( src ); + dellen = strlen( del ); + if( srclen == 0 || dellen == 0 ) return; + + for( i = 0 ; i < dellen ; i ++ ){ + if( src[0] == del[i] ){ + delete = TRUE; + break; + } + } + + /* */ + if( delete ) + /* ƥ NULL ٯľ */ + for( i = 0 ; i < srclen ; i ++ ) + src[i] = src[i+1]; +} + + +/*---------------------------------------- + * ٯ ٯֳľ¾Ʃ£ + * ¦ + * src char* Ʃ ٯ + * include char* ֳľ¾ ٯ + * ߯Ի + * ٱֳľsrc + * -1 + ----------------------------------------*/ +int charInclude( char* src, char* include ) +{ + int i,j; + int srclen,includelen; + + srclen = strlen( src ); + includelen = strlen( include ); + + for( i = 0 ; i < srclen ; i ++ ){ + for( j = 0 ; j < includelen ; j ++ ) + if( src[i] == include[j] ) + return i; + } + return -1; +} + + +/*------------------------------------------------------------ + * EUC2 ëئstrncpy + * freeBSD Ƥ strncpy ëȻ廯 + * ľëݱհ*dest++ 羮컥 + * ئмƥȻئУ۾Ի ̼Ȼ + * ئԻ ئة + * ¦ + * dest char* + * src char* ĩ + * n size_t Ӯ + * ߯Ի + * dest + ------------------------------------------------------------*/ +char* strncpy2( char* dest, const char* src, size_t n ) +{ + if( n > 0 ){ + char* d = dest; + const char* s = src; + int i; + for( i=0; i=n ){ + *(d+i-1)='\0'; + break; + } + *(d+i) = *(s+i); + }else + *(d+i) = *(s+i); + } + } + return dest; +} + +/*---------------------------------------- + * src dest £ ƼëƩ£ + * ¦ + * dest + * n + * src 缰 ٯ + ----------------------------------------*/ +void strcpysafe( char* dest ,size_t n ,const char* src ) +{ + /* + * src dest . + * strcpy, strncpy ƥ dest Ի ڻ + * ݱ,ƹ½ʧͱ. + * ľë ʲб, strncpy ؤ» strlen( src ) n Ի + * ݱ巴, dest NULL ٯ練ئئ. + * + * ׻Ȼ dest Ի src õӮݱ巴 + * n-1 ƥ strncpy ë. ݷ + * + * n ݷƾئ¼ƥ ݷ ئУ + * + */ + // Nuke +1 (08/25): Danger if src=0 + if (!src) { + *dest = '\0'; + return; + } + if( n <= 0 ) /* ئ */ + return; + + /* ƥ n >= 1 */ + /* NULL ٯë ƻ ʤ */ + else if( n < strlen( src ) + 1 ){ + /* + * 뻥Իئмƥ n - 1(NULL ٯ) + * ƥ strncpy ë + */ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + }else + strcpy( dest , src ); + +} + +/*---------------------------------------- + * src length ʣ Ƽ ëƩ£ + * ¦ + * dest + * n Ƽ + * src + * length ٯ¾ + ----------------------------------------*/ +void strncpysafe( char* dest , const size_t n , + const char* src ,const int length ) +{ + /* + * src dest length + * strcpy, strncpy ƥ dest Ի ڻ + * ݱ,ƹ½ʧͱ. + * ƥstrlen( src ) length лõ + * ( ˱) dest ë ͻ + * strcpysafe Ԫë£ + */ + + int Short; + Short = min( strlen( src ) , length ); + + /* NULL ٯ ë ʤ */ + if( n < Short + 1 ){ + /* + * 뻥Իئмƥ n - 1(NULL ٯ) + * ƥ strncpy ë + */ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + + }else if( n <= 0 ){ + return; + }else{ + /* + * 뷴бؤ¼ƥ Short ƥstrncpyë + * ئ src 巴 Short Ӯ NULL ئмƥ + * dest 巴 ܰƻʣ + */ + + strncpy2( dest , src , Short ); + dest[Short]= '\0'; + + } +} + +/*------------------------------------------------------------ + * strcatë £мƥ ئëлئǣ + * ¦ + * src char* ئ ٯ + * size int src ( ǷľȻ¾ƥ + * ئʻ ) + * ap char* + * ߯Ի + * src ( ľ) + ------------------------------------------------------------*/ +char* strcatsafe( char* src, int size, char* ap ) +{ + strcpysafe( src + strlen( src ) , size - strlen(src), ap ); + return src; +} + +/*---------------------------------------- + * ٯ ë ʤ£ Ԫƾ ئ by ringo + * char *s1 , *s2 : ʤ ٯ + * ߯Ի + * 0 ئԪ + * 1 : ئ + * ľNPC ƽݩ ֧ʷֹ + ----------------------------------------*/ +int strcmptail( char *s1 , char *s2 ) +{ + int i; + int len1 = strlen( s1 ); + int len2 = strlen( s2 ); + + for(i=0;;i++){ + int ind1 = len1 - 1 - i; + int ind2 = len2 - 1 - i; + if( ind1 < 0 || ind2 < 0 ) return 0; + if( s1[ind1] != s2[ind2] ) return 1; + } +} + + + +/*---------------------------------------- + * ٯ ̤ľ°ë£ + * NPC ƽݩ ֧ʷֹ + * ׷ ٯؤ £ + * Ȭ ئʧة ʣ + * ¦ + * hoge char* ݩ ٯ + * ߯Ի + * ݩ װѣ + * + * + * "ringo ( ۰ ) 100" + * 100£ + * "ringo ( ۰ ) 100" + * 100ئ£ۻNPCئԻѣ + ----------------------------------------*/ +#define DECIMALCHARNUM 10 +#define FIGURECHARNUM 3 +#define SPECIALCHARNUM 2 +char *UTIL_decimalchar[DECIMALCHARNUM] = {"0","1","2", + "3", "4","5", + "6","7","8","9"}; +char *UTIL_figurechar[FIGURECHARNUM] = {"","",""}; +char *UTIL_specialchar[SPECIALCHARNUM] = {"",""}; + +/* + * ٯ գѰë ľ ë ʣ õ + * ƻ ʣeucã + * + * : in "Ȿ300" + * out "7" + * ¦ + * char *in: ٯ + * char *out: ٯ + * int outsiz: ٯ + * ߯Ի + * Ѱë лؤչ ٯ Ӯئը + */ +static int findNumberString( char *in, char *out, int outsiz ) +{ + int len,i,j,k, findflag, numstrflag; + char tmp[3]; + + len = strlen(in); + if( len == 0 ) return 0; + + numstrflag=0; + findflag = 0; + for( i=0,j=0;in[i]!='\0'&& j 0x7fffffff ) return 0x7fffffff; + else return (int)val; + +} + + +/* + * ֿƥ Ѱëѱ + * char *str Ѱë ٯ + * ߯Ի Ѱ + * + * str"һ4ǧ"߯Ի 140000000 + */ +int kanjistrToInt( char *str ) +{ + double val,tmpval; + char tmp[3]; + int num,i,j,numflag; + + numflag = 0; + num = 1; + tmpval = 0; + val = 0; + for( i=0;str[i]!='\0';i++ ){ + if( str[i] & 0x80 ){ + tmp[0] = str[i]; + tmp[1] = str[i+1]; + tmp[2] = '\0'; + i++; + }else{ + tmp[0] = str[i]; + tmp[1] = '\0'; + } + for( j=0;j 0x7fffffff ) return 0x7fffffff; + else return (int)val; + +} + + + +/*---------------------------------------- + * ٯ ̤ľ°ë£ + * NPC ƽݩ ֧ʷֹ + * ׷ ٯؤ £ + * Ȭ ئʧة ʣ + * ¦ + * hoge char* ݩ ٯ + * ߯Ի + * ݩ װѣ + * + * + * "ringo ( ۰ ) 100" + * 100£ + * "ringo ( ۰ ) 100" + * 100ئ£ۻNPCئԻѣ + ----------------------------------------*/ +int texttoiTail( char *hoge) +{ + return 0; /* ʲȻ׼ƥף۹ʣ */ +} + +/*---------------------------------------- + * ٯ ëٯƻٯ + * ¦ѱ ľ߯ + * ¦ + * arg + * number ëҽ + * base + * type ¦Ѽ( CTYPE common.h ɽľ ) + * ߯Ի + * TRUE(1) + * FALSE(0) strtolձ巴 ئ + * ݼnumberstrtol߯Իƥؤ + ----------------------------------------*/ +BOOL strtolchecknum( char* arg , void* number,int base ,CTYPE type) +{ + char* buf; + int num; + + num = strtol( arg, &buf, base); + + switch( type ){ + case CHAR: + *(char*)number = (char)num; + break; + case SHORT: + *(short*)number = (short)num; + break; + case INT: + *(int*)number = num; + break; + case DOUBLE: + *(double*)number = (double)num; + break; + default: + break; + } + + + if( strlen( buf ) >= 1 ) + /* + * Ի ٯؤеǷ ľئеئ֣ + */ + return FALSE; + + return TRUE; + +} + + + + +/*---------------------------------------- + * src dels ƥ϶ ٯëԻ + * ͵ب޵ƥؤDZ + * Ի͵بƥئУ + * ¦ + * src ʽľ ٯ + * char* ٯ( ٯ ƥ϶õ) + * ߯Ի + * ئ + ----------------------------------------*/ +void deleteCharFromString( char* src , char* dels ) +{ + int index=0; /* ƥؤԻ ٯ ƥ index */ + int delength; /* dels Ӯëɬ(Ʒպʧ󼰿 */ + int i=0,j;/* i src ë j dels ë */ + + delength= strlen( dels ); + + while( src[i] != '\0' ){ + if( src[i] == BACKSLASH ) + /* + * ͵بئƥ޵ + * Իݼ ٯ + */ + src[index++] = src[++i]; /* substitute next char */ + + else{ + for( j = 0 ; j < delength ; j ++ ){ + if( src[i] == dels[j] ) + /* + * ٯ֣۷Ȼ i 1 ë + */ + goto incrementi; + } + /* + * ϶ýľئмƥ£ + */ + src[index++] = src[i]; + } + incrementi: + i++; + } + + src[index] = '\0'; +} + + + +/*---------------------------------------- + * src dels ƥ϶ ٯëԻ + * ޵ئ + * ¦ + * src ʽľ ٯ + * char* ٯ( ٯ ƥ϶õ) + * ߯Ի + * ئ + ----------------------------------------*/ +void deleteCharFromStringNoEscape( char* src , char* dels ) +{ + int index=0; /* ƥؤԻ ٯ ƥ index */ + int delength; /* dels Ӯëɬ(Ʒպʧ󼰿 */ + int i=0,j;/* i src ë j dels ë */ + + delength= strlen( dels ); + + while( src[i] != '\0' ){ + for( j = 0 ; j < delength ; j ++ ){ + if( src[i] == dels[j] ) + /* + * ٯ֣۷Ȼ i 1 ë + */ + goto incrementi; + } + /* + * ϶ýľئмƥ£ + */ + src[index++] = src[i]; + incrementi: + i++; + } + + src[index] = '\0'; +} + +/*------------------------------------------------------------ + * ϶ýľ ٯë϶ýľ ٯƥ 微 + * ¦ + * src char* ʽľ ٯ + * oldc char ʽľ ٯ + * newc char ٯ + * ߯Ի + * src + ------------------------------------------------------------*/ +char* replaceString( char* src, char oldc ,char newc ) +{ + char* cp=src; + + do{ + if( *cp == oldc ) *cp=newc; + }while( *cp++ ); + return src; +} + +typedef struct tagEscapeChar +{ + char escapechar; + char escapedchar; +}EscapeChar; +static EscapeChar escapeChar[]= +{ + { '\n', 'n' }, + { ',', 'c' }, + { '|', 'z' }, + { '\\', 'y' }, +}; + + +char makeCharFromEscaped( char c )//add this function,because the second had it +{ + int i; + + for( i = 0; i < sizeof( escapeChar )/sizeof( escapeChar[0] ); i++ ) + { + if( escapeChar[i].escapedchar == c ) + { + c = escapeChar[i].escapechar; + break; + } + } + return c; +} +/*---------------------------------------- + * makeEscapeStringƥľ ٯ ë + * ¦ + * src char* ئ ٯ ۳ľ̤׸£ + * ߯Ի + * src ë߯ʣ(ë ľ֧з) + ----------------------------------------*/ +char *makeStringFromEscaped( char* src ) +{//ttom this function all change,beside copy from the second + + int i; + // CoolFish: Fix bug 2001/10/13 + // int srclen = strlen( src ); + int srclen = 0; + int searchindex=0; + + // CoolFish: Fix bug 2001/10/13 + if (!src) return NULL; + srclen = strlen(src); + + for( i = 0; i < srclen; i ++ ) + { + // for 2Byte Word + if( IS_2BYTEWORD( src[i] ) ){ + src[searchindex++] = src[i++]; + src[searchindex++] = src[i]; + }else + if( src[i] == '\\' ) + { + // ݼ ٯ + i++; + src[searchindex++] = makeCharFromEscaped( src[i] ); + } + else + { + src[searchindex++] = src[i]; + } + } + src[searchindex] = '\0'; + + return src; +} + +char* makeEscapeString( char* src , char* dest, int sizeofdest) +{ //ttom this function all change, copy from the second + int i; + int srclen = 0; + int destindex=0; + + // CoolFish: Fix bug 2001/10/13 + if (!src) return NULL; + srclen = strlen(src); + + for( i = 0 ; i < srclen ; i ++ ){ + BOOL dirty=FALSE; + int j; + char escapechar='\0'; + if( destindex + 1 >= sizeofdest )break; + if( IS_2BYTEWORD( src[i] ) ){ + if( destindex + 2 >= sizeofdest )break; + + dest[destindex] = src[i]; + dest[destindex+1] = src[i+1]; + destindex += 2; + i ++; + continue; + } + for( j = 0; j= length ){ + print( "*\n"); + break; + } + src[index++]=src[i]; + /* DZ */ + backchar = '\0'; + continue; + } + if( src[i] == backchar ) + /* + * ԪئУ۹Իֱئ£ + */ + continue; + + /* + * ٯئئ׼ƥ backchar NULL ٯ + * ľԪ + */ + backchar = '\0'; + for( j = 0 ; j < delength ; j ++ ){ + if( src[i] == dels[j] ){ + /* + * ٯ ֣ ƥ continue ئDZ巽Ի + * ٯئǻƥ£ + */ + backchar=src[i]; + break; + } + } + src[index++]=src[i]; + } + src[index++]='\0'; +} + +/*---------------------------------------- + * hashë߯ʣ ٯ 弰 + * ľ ئƥʧةϻ + * ʧةУ + * ¦ + * s ٯ + * ߯Ի + * int ˦ب + *----------------------------------------*/ +#define PRIME 211 +int hashpjw ( char* s ) +{ + char *p; + unsigned int h= 0 ,g; + for( p = s ; *p ; p ++ ){ + h = ( h<< 4 ) + (*p); + if( (g = h & 0xf0000000) != 0){ + h = h ^ (g>>24); + h = h ^ g; + } + } + return h % PRIME; +} + +/*---------------------------------------- + * л̼ĩë߯( TCP ) + * ¦ + * port л̡ + * ߯Ի + * -1 ޷¡ + * 1. socket˵ ةP޷¡ + * 2. bind˵ ةP޷¡ + * 3. listen˵ ةP޷¡ + ----------------------------------------*/ +int bindlocalhost( int port ) +{ + struct sockaddr_in sin; /*лʧ*/ + int sfd; /*ĩū*/ + int rc; /*л*/ + + /*AF_INET SOCK_STREAM */ + sfd = socket( AF_INET, SOCK_STREAM, 0 ); + if( sfd == -1 ){ + print( "%s\n" , strerror(errno ) ); + return -1; + } + if( getReuseaddr() ) { + int sendbuff; + /* лʧ */ + setsockopt( sfd, SOL_SOCKET, SO_REUSEADDR, + (char *)&sendbuff, sizeof( sendbuff)); + } + + /*0ʧƻëҽ */ + bzero(&sin,sizeof(sin)); + sin.sin_family=AF_INET; + sin.sin_port = htons( port ); + sin.sin_addr.s_addr = INADDR_ANY; + + rc = bind( sfd , (struct sockaddr*)&sin, sizeof(struct sockaddr_in)); + if( rc == -1 ){ + print( "%s\n" , strerror(errno ) ); + return -1; + } + + rc = listen( sfd , 5 ); + if( rc == -1 ){ + print( "%s\n" , strerror(errno ) ); + return -1; + } + return sfd; +} + + + +/*---------------------------------------- + * £( TCP ) + * ¦ + * hostname ʯ + * (xx.xxx.xxx.xxxƥxxx.co.jp羮ƥ) + * port ʯ̡ + * ߯Ի + * ū( -1 ݷ޷¡ ) + ----------------------------------------*/ +int connectHost( char* hostname , unsigned short port ) +{ + struct sockaddr_in sock; /*connectݱ*/ + struct hostent* hoste; /*hostnamehostent*/ + int fd; /*ĩū*/ + int lr; /*л*/ + + bzero(&sock,sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_port = htons( port ); + + /* dot notation ëƩ */ + sock.sin_addr.s_addr = inet_addr( hostname ); + if( sock.sin_addr.s_addr == -1 ){ + /* + *޷¡ dot notation ƥئУ׻Ȼ ɧ ݩ裻 ֣ۢ + * dnsëئľئئݷʼֳƥ֧Ȼľ£ + */ + hoste = gethostbyname( hostname ); + if( hoste == NULL ){ + print( "ȡ: %s\n", hostname); + return -1; + } + + memcpy((void*)&sock.sin_addr.s_addr , + hoste->h_addr , sizeof(struct in_addr) ); + } + + /*ĩë*/ + fd = socket( AF_INET, SOCK_STREAM , 0 ); + if( fd == -1 ){ + print("Cannot Create Socket(%s errno:%d)\n" + ,strerror( errno ) ,errno ); + return -1; + } + + lr = connect(fd,(struct sockaddr*)&sock,sizeof(struct sockaddr_in)); + if( lr != 0 ){ +// print("Cannot connect. (%s errno:%d)\n" +// ,strerror( errno ) ,errno ); + return -1; + } + return fd; +} + + +/*---------------------------------------- + * 뼰 ݱ淤įؤ¾ + * ƶʧة ʣ + * ¦ + * char* Ʃ ٯ + * ߯Ի + * ٱέݱ淤į ʧͱݱа + * еǾе + * existsNewLinwCharacter( "aho\nhoge\n" ) + * ߯Ի 3 ئ£۳ľǣ + * -1 ئ + * + ----------------------------------------*/ +int existsNewLineCharacter( char* line ) +{ +#if 1 + char* old = line; + do{ + if( *line == NEWLINE)return line-old; + }while( *(line++) ); +#else + int i; /* */ + int length = strlen( line ); /*Ʃ ٯ Ӯ*/ + for( i = 0 ; i < length ; i ++ ){ + if( line[i] == NEWLINE ) + return i; + } +#endif + + return -1; +} + + + +/*---------------------------------------- + * ٯ ٯ ľëʣ ë裻ľ£ + * nindex( string , c , 1 ) index( string , c ) equivalent ƥؤ£ + * number ׷0ݷ߯Իstring Ԫƥؤ£ + * + * ¦ + * string char* Ʃ ٯ + * c int Ʃ ٯ + * number int į + * ߯Ի + * ٯ̼ + * NULL Ĺئף + ----------------------------------------*/ +char* nindex( char* string, int c , int number ) +{ + int i; /* */ + int num=0; + int length = strlen( string ); /*Ʃ ٯ Ӯ*/ + if( number <= 0 )return string; + for( i = 0 ; i < length ; i ++ ){ + if( string[i] == c )num++; + if( number == num ) return &string[i]; + } + return NULL; +} + +BOOL rrd( char* dirname , STRING64* buf ,int bufsize, int* index) +{ + DIR* d; + char dirn[1024]; + + d = opendir( dirname ); + if( d == NULL )return FALSE; + + while( 1 ){ + struct dirent* dent; + struct stat st; + dent = readdir( d ); + if( dent == NULL ){ + if( errno == EBADF ){ + errorprint; + closedir(d); + return FALSE; + }else + /* successful */ + break; + } + + /* . ƥ°̻ﷴ ئ */ + if( dent->d_name[0] == '.' )continue; + + snprintf(dirn, sizeof(dirn), "%s/%s" , dirname,dent->d_name ); + if( stat( dirn , &st ) == -1 )continue; + if( S_ISDIR( st.st_mode ) ){ + if( rrd( dirn , buf ,bufsize, index) == FALSE ){ + closedir(d); + return FALSE; + } + }else{ + if( *index >= bufsize ) + break; + + strcpysafe( buf[*index].string , sizeof( buf[*index].string ), dirn ); + (*index)++; + } + } + closedir(d); + return TRUE; +} + +int rgetFileName( char* dirname , STRING64* string, int size) +{ + int index=0; + if( rrd( dirname , string ,size ,&index ) == FALSE )return -1; + else return index; +} + +BOOL checkStringsUnique( char** strings, int num ,int verbose) +{ + int i,j; + for( i = 0 ; i < num - 1; i ++ ){ + for( j = i+1 ; j < num ; j ++){ + if( !strcmp( strings[i] ,strings[j] )){ + if( verbose ) + print( "Overlapp string is %s\n", strings[i] ); + return FALSE; + } + } + } + return TRUE; +} + +BOOL PointInRect( RECT* rect, POINT* p ) +{ + if( rect->x <= p->x && p->x <= rect->x + rect->width && + rect->y <= p->y && p->y <= rect->y + rect->height ) + return TRUE; + return FALSE; +} + +BOOL CoordinateInRect( RECT* rect, int x, int y) +{ + POINT p={x,y}; + return PointInRect(rect,&p); +} + +int clipRect( RECT *rect1, RECT *rect2, RECT *ret ) +{ + if( rect1->x > rect2->x + rect2->width -1 + || rect2->x > rect1->x + rect1->width -1 + || rect1->y > rect2->y + rect2->height -1 + || rect2->y > rect1->y + rect1->height -1 ) + return 0; + ret->x = max( rect1->x, rect2->x ); + ret->y = max( rect1->y, rect2->y ); + ret->width = min( rect1->x+rect1->width, rect2->x+rect2->width ) - ret->x; + ret->height = min( rect1->y+rect1->height, rect2->y+rect2->height ) - ret->y; + return 1; +} + +BOOL isstring1or0( char* string ) +{ + if( strcasecmp(string,"TRUE" ) == 0 )return TRUE; + if( strcasecmp(string,"FALSE") == 0 )return FALSE; + if( strcasecmp(string,"1" ) == 0 )return TRUE; + if( strcasecmp(string,"0" ) == 0 )return FALSE; + if( strcasecmp(string,"ON" ) == 0 )return TRUE; + if( strcasecmp(string,"OFF" ) == 0 )return FALSE; + return FALSE; +} + +void easyGetTokenFromString( char *src,int count,char*output,int len ) +{ + int i; + int counter = 0; + + if( len <= 0 )return; + + +#define ISSPACETAB( c ) ( (c) == ' ' || (c) == '\t' ) + + for(i=0;;i++){ + if( src[i]=='\0'){ + output[0] = '\0'; + return; + } + if( i > 0 && ! ISSPACETAB( src[i-1] ) && + ! ISSPACETAB( src[i] ) ){ + continue; + } + + if( ! ISSPACETAB( src[i]) ){ + counter++; + if( counter == count){ + /* copy it */ + int j; + for(j=0;j1---- + * + * + ------------------------------------------------------------*/ +float linearDiv( float val1 , float val2 , float d ) +{ + return val1 + ( val2 - val1 ) * ( d ); +} + + +/*------------------------------------------------------------ + * ٯ ئ ئ ٯëlen ٯԻƻ¼ĸةئ + * ٯ ë£NPC¼ĸةɵϷ年Ȼ + * + * char *cand : ռ٣ ٯ + * char *out : + * int len : Ӯ + ------------------------------------------------------------*/ +void makeRandomString( char *cand , char *out , int len ) +{ + int i; + int l = strlen( cand ); + + for(i=0;i= baselen; i ++ ) { + tmp[i] = src % baselen; + src /= baselen; + } + i--; + if( minus ){ + *out = '-'; + *(out+1) = base[src]; + for( j = 2; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } else { + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } + *(out+j) = '\0'; + return( out); +#else +/* */ +#define CNV_NUMBER 62 + int i, j; + char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + int tmp[64]; + int src; + if( a < 0 ) return( NULL); + if( a < CNV_NUMBER) { + *out = base[a]; + *(out+1) = '\0'; + return( out); + } + src = a; + for( i = 0; src >= CNV_NUMBER; i ++ ) { + tmp[i] = src % CNV_NUMBER; + src /= CNV_NUMBER; + } + i--; + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + *(out+j) = '\0'; + return( out); +#undef CNV_NUMBER +#endif +} +/* + * ܸľ ƥѰ ƻ¾Ʃ + * -1 ½е ئ + * + * ¦ + * src *int Ʃ缰 + * srclen int src + * + * Ի ؤԻ TRUE + * ئ FALSE + */ +BOOL checkRedundancy( int *src, int srclen) +{ + int i,j; + int ret = FALSE; + + for( i = 0; i < srclen; i ++ ) { + if( *(src + i) != -1 ) { + for( j = i+1; j < srclen; j ++ ) { + if( *(src +i) == *( src+j) ) { + ret = TRUE; + break; + } + } + } + } + return ret; +} +void +shuffle_ints( int num, int *a, int t ) +{ + int i; + for(i=0;i> 8 ) & 0xFF ] + ^ ( crc << 8 ) ^ BitTable[ p[ i ] ] ); + } + return crc; +} + +// Add Code By Shan 2001.06.16 +INLINE double time_diff(struct timeval subtrahend, + struct timeval subtractor) +{ + return( (subtrahend.tv_sec - subtractor.tv_sec) + + (subtrahend.tv_usec + - subtractor.tv_usec ) / (double)1E6 ); +} +char *strcpy_s(char *des, size_t n, const char *src) +{ + assert(des != NULL && src != NULL); + + if(des == NULL || src == NULL || n == 0) + { + return NULL; + } + + char *TM_RetChar = des; + int i = 0; + + while( (*des++ = *src++) ) + { + i++; + if( i >= n ) + { + i--; + break; + } + } + TM_RetChar[i] = '\0'; + return TM_RetChar; +} +char * itoa(long n, int base) +{ + register char *p; + register int minus; + static char buf[36]; + p = &buf[36]; + *--p = '\0'; + if (n < 0) { minus = 1; n = -n; } else minus = 0; + if (n == 0) *--p = '0'; + else while (n > 0) { *--p = "0123456789abcdef"[n % base]; n /= base; } + if (minus) *--p = '-'; + return p; +} diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_1.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_1.sh new file mode 100644 index 0000000..5563813 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_1.sh @@ -0,0 +1,12 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 1 + +#endif" > $OUT +make diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_10.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_10.sh new file mode 100644 index 0000000..d5399d5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_10.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 10 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_10.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_11.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_11.sh new file mode 100644 index 0000000..9eed693 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_11.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 11 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_11.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_12.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_12.sh new file mode 100644 index 0000000..7f556f0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_12.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 12 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_12.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_13.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_13.sh new file mode 100644 index 0000000..398ab74 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_13.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 13 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_13.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_14.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_14.sh new file mode 100644 index 0000000..b5ed86a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_14.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 14 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_14.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_15.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_15.sh new file mode 100644 index 0000000..806302d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_15.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 15 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_15.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_16.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_16.sh new file mode 100644 index 0000000..b0df9ec --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_16.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 16 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_16.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_17.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_17.sh new file mode 100644 index 0000000..43e8272 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_17.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 17 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_17.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_18.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_18.sh new file mode 100644 index 0000000..96a15ee --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_18.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 18 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_18.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_19.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_19.sh new file mode 100644 index 0000000..cbee762 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_19.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 19 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_19.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_2.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_2.sh new file mode 100644 index 0000000..2fcf2f7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_2.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 2 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_2.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_20.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_20.sh new file mode 100644 index 0000000..5e3edc5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_20.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 20 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_20.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_21.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_21.sh new file mode 100644 index 0000000..e666655 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_21.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 21 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_21.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_22.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_22.sh new file mode 100644 index 0000000..fea8a58 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_22.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 22 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_22.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_23.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_23.sh new file mode 100644 index 0000000..28718e7 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_23.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 23 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_23.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_24.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_24.sh new file mode 100644 index 0000000..8a8843f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_24.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 24 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_24.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_25.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_25.sh new file mode 100644 index 0000000..9aeddf9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_25.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 25 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_25.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_26.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_26.sh new file mode 100644 index 0000000..cab4cf1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_26.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 26 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_26.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_27.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_27.sh new file mode 100644 index 0000000..78a1aad --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_27.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 27 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_27.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_28.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_28.sh new file mode 100644 index 0000000..8d12420 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_28.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 28 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_28.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_29.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_29.sh new file mode 100644 index 0000000..3e19a58 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_29.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 29 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_29.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_3.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_3.sh new file mode 100644 index 0000000..ec3a7cd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_3.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 3 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_3.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_30.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_30.sh new file mode 100644 index 0000000..25c97d8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_30.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 30 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_30.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_31.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_31.sh new file mode 100644 index 0000000..ef774e1 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_31.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 31 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_31.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_32.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_32.sh new file mode 100644 index 0000000..adcb803 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_32.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 32 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_32.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_33.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_33.sh new file mode 100644 index 0000000..cb3942c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_33.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 33 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_33.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_34.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_34.sh new file mode 100644 index 0000000..a2b8144 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_34.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 34 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_34.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_35.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_35.sh new file mode 100644 index 0000000..c8e9b32 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_35.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 35 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_35.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_36.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_36.sh new file mode 100644 index 0000000..6f4b4d0 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_36.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 36 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_36.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_37.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_37.sh new file mode 100644 index 0000000..b413fd6 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_37.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 37 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_37.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_38.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_38.sh new file mode 100644 index 0000000..54508a8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_38.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 38 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_38.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_39.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_39.sh new file mode 100644 index 0000000..5a8fc95 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_39.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 39 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_39.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_4.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_4.sh new file mode 100644 index 0000000..6e94181 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_4.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 4 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_4.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_40.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_40.sh new file mode 100644 index 0000000..54ec0dc --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_40.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 40 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_40.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_41.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_41.sh new file mode 100644 index 0000000..e86717a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_41.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 41 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_41.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_42.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_42.sh new file mode 100644 index 0000000..ae199fa --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_42.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 42 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_42.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_43.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_43.sh new file mode 100644 index 0000000..b6d6817 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_43.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 43 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_43.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_44.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_44.sh new file mode 100644 index 0000000..efcb316 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_44.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 44 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_44.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_45.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_45.sh new file mode 100644 index 0000000..be1c99a --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_45.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 45 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_45.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_46.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_46.sh new file mode 100644 index 0000000..2dc7dce --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_46.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 46 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_46.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_47.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_47.sh new file mode 100644 index 0000000..46032a5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_47.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 47 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_47.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_48.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_48.sh new file mode 100644 index 0000000..fdfec00 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_48.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 48 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_48.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_49.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_49.sh new file mode 100644 index 0000000..0c0c8bd --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_49.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 49 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_49.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_6.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_6.sh new file mode 100644 index 0000000..f1e2f97 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_6.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 6 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_6.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_7.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_7.sh new file mode 100644 index 0000000..47504f4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_7.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 7 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_7.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_8.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_8.sh new file mode 100644 index 0000000..6f80b26 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_8.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 8 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_8.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/gmsv/vip_9.sh b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_9.sh new file mode 100644 index 0000000..d286222 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/gmsv/vip_9.sh @@ -0,0 +1,14 @@ +#!/bin/sh +OUT=include/longzoro/longzoro.h + +make clean +echo "#ifndef __LONGZORO_H__ +#define __LONGZORO_H__ + +//⹦ܿ---------------------------------------- +#define _ATTESTAION_ID 9 + +#endif" > $OUT +make + +tar -zcvf /csa/saserver/gmsv/gmsv_vip_9.tar.gz /csa/saserver/gmsv/gmsvjt /csa/saserver/gmsv/setup.cf diff --git a/石器时代服务器端最新完整源代码/Serv/saac/.cproject b/石器时代服务器端最新完整源代码/Serv/saac/.cproject new file mode 100644 index 0000000..622141b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/.cproject @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/.project b/石器时代服务器端最新完整源代码/Serv/saac/.project new file mode 100644 index 0000000..d9c2d60 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/.project @@ -0,0 +1,27 @@ + + + saac-09sa + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/.settings/org.eclipse.core.resources.prefs b/石器时代服务器端最新完整源代码/Serv/saac/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..bb29a1d --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=GBK diff --git a/石器时代服务器端最新完整源代码/Serv/saac/acfamily.c b/石器时代服务器端最新完整源代码/Serv/saac/acfamily.c new file mode 100644 index 0000000..101ba71 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/acfamily.c @@ -0,0 +1,3935 @@ +#define _FAMILY_C_ + +#include "version.h" +#include "main.h" +#include "acfamily.h" +#include "util.h" +#include "saacproto_serv.h" + +#include +#include +#include +#include +#include +#include + +// Int +static char* FAMILY_INTDATA[familymaxint] = +{ + "fmindex", + "fmleadergrano", + "fmnum", + "fmjoinnum", + "fmacceptflag", + "fmsetupflag", + "fmsprite", + "fmpointindex", + "fmpopular", + "fmgold", + "fmmemberindexmaxnum", + "apply_time", + "setup_time", + "predel_time", + "memonowwritenum", + "memonum", + "fmadv", + "fmfeed", + "fmsynthesize", + "fmdealfood", + "fmpk", +#ifdef _NEW_MANOR_LAW + "fmmomentum", +#endif +#ifdef _SET_FMPOINT + "fmpointtime", +#endif +#ifdef _FAMILY_PAY_POINT + "fmpaypoint", +#endif +#ifdef _FAMILYBADGE_ + "fmbadge", +#endif +}; + +// char +static char* FAMILY_CHARDATA[familymaxchar] = +{ + "fmname", + "fmleadername", + "fmleaderid", + "petname", + "petattr", + "fmrule", +#ifdef _FAMILY_TOTEM + "familytotem", +#endif +}; + +// Ա int +static char* MEMBER_INTDATA[memberdatamaxint] = +{ + "charlv", + "charflag", + "onlineflag", + "charfdid", + "predeltime", + "popular", +#ifdef _FMVER21 + "eventflag", +#endif +#ifdef _NEW_MANOR_LAW + "momentum", +#endif +}; + +// Ա char +static char* MEMBER_CHARDATA[memberdatamaxchar] = +{ + "charname", + "charid", +}; + +// Ա char +static char* MEMBERKIND_INTDATA[FMMEMBER_KINDNUM] = +{ + "", + "һԱ", + "", + "峤", + "", +}; + +// ֮԰ +struct FMSMEMO +{ + int num; // + int fmsnowwritenum; // Ŀǰλ + char memodata[FMSMEMONUM][FAMILY_MEMOLEN]; // +}; + +// ׯ԰ +struct FMPOINT +{ + int fl; // ׯ԰ͼ + int x; // ׯ԰ + int y; // ׯ԰ + int fmfl; // ׯ԰峤ͼ + int village; // ׯ԰ڽ֮ׯ + int hadfmindex; // ռׯ԰֮ index + char hadfmname[CHARNAME_MAX]; // ռׯ԰֮ name + int hadfmpopular; // ռׯ԰֮ۺֵ +#ifdef _FIX_FMPOINTTIME + int fmpointtime; //ռׯ԰ʱ +#endif +}; + +// Ա +typedef struct +{ + char charname[CHARNAME_MAX]; // Ա + char charid[USERID_MAX]; // Աʺ + int charlv; // Աȼ + int charflag; /* + FMMEMBER_NONE + FMMEMBER_MEMBER Ա + FMMEMBER_APPLY + FMMEMBER_LEADER 峤 + FMMEMBER_ELDER + */ + int onlineflag; // 0:offline; gmsv index + int charfdid; // Ա gmsv fd + int predeltime; // ԤɾԱʱ + int popular; // Ա +#ifdef _FMVER21 + int eventflag; // Ƿӵ峤ʸ +#endif +#ifdef _NEW_MANOR_LAW + int momentum; // Ա +#endif +#ifdef _FM_MODIFY + int gsnum; // ¼һgame server +#endif +} MEMBERDATA; + +struct FAMILY +{ + int fmindex; // index + char fmname[CHARNAME_MAX]; // + char fmleadername[CHARNAME_MAX]; // 峤 + + char fmleaderid[USERID_MAX]; // 峤ʺ + int fmleadergrano; // 峤Ƭ + char petname[CHARNAME_MAX]; // ػ + char petattr[256]; // ػ + + int fmnum; // ˳ + int fmjoinnum; // + int fmacceptflag; // ǷճԱ 0: 1: + int fmsetupflag; // 0:δ 1:ѳ + char fmrule[256]; // ּ + int fmsprite; // 0: 1:ڰ + int fmpointindex; // ݵ index + int fmpopular; // ۺ +#ifdef _PERSONAL_FAME // Arminius: + int fmtotalfame; // ۺ + ܺ +#endif +#ifdef _NEW_MANOR_LAW + int fmmomentum; // +#endif + int fmgold; // + int fmmemberindexmaxnum; // Ŀǰ + int apply_time; // ʱ + int setup_time; // ʱ + int predel_time; // Ԥɾʱ + + int memonowwritenum; // Ŀǰλ + int memonum; // + int fmadv; // ð + int fmfeed; // + int fmsynthesize; // ϳɼӹ + int fmdealfood; // + int fmpk; // У + char memolist[FAMILY_MEMONUM][FAMILY_MEMOLEN]; // + MEMBERDATA fmmemberindex[MAX_MEMBERNUM]; // Ա +#ifdef _SET_FMPOINT + int fmpointtime; // ׯ԰ʱ +#endif +#ifdef _FAMILY_TOTEM + char familytotem[649]; +#endif +#ifdef _FAMILY_PAY_POINT + int fmpaypoint; +#endif +#ifdef _FAMILYBADGE_ + int fmbadge; +#endif +}; + +int db_familyupdate[MAX_FAMILY]={0}; +int db_fmpointupdate = 0; +int db_fmsmemoupdate = 0; +int fmnownum = 0; +int fmindexmaxnum = 0; +extern gmsv gs[MAXCONNECTION]; + +struct FAMILY family[MAX_FAMILY]; +int fmpopularindex[MAX_FAMILY]; // Arminius: sort family +#ifdef _PERSONAL_FAME // Arminius: +int fmtotalfameindex[MAX_FAMILY]; +#endif +#ifdef _NEW_MANOR_LAW +int fmMomentumIndex[MAX_FAMILY]; +#endif +int fmadvindex[MAX_FAMILY]; +int fmfeedindex[MAX_FAMILY]; +int fmsynthesizeindex[MAX_FAMILY]; +int fmdealfoodindex[MAX_FAMILY]; +int fmpkindex[MAX_FAMILY]; +struct FMPOINT fmpoint[MAX_FMPOINT]; +struct FMSMEMO fmsmemo; + +// Arminius: sort family & output the sorted list +// Make a sorted index (fmindex) for the family data (family) +#ifdef _NEW_MANOR_LAW +int fmMomentumcompar(const void *indexa, const void *indexb); +#endif +#ifdef _PERSONAL_FAME // Arminius: +int fmtotalfamecompar(const void *indexa, const void *indexb); +#endif +int fmpopularcompar(const void *indexa, const void *indexb); +int fmadvcompar(const void *indexa, const void *indexb); +int fmfeedcompar(const void *indexa, const void *indexb); +int fmsynthesizecompar(const void *indexa, const void *indexb); +int fmdealfoodcompar(const void *indexa, const void *indexb); +int fmpkcompar(const void *indexa, const void *indexb); +int CheckFM(int *index, char *fmname, int fmindex); +int CheckFMUse(int index); +void setFamilyFileDataToArg(int index, char *data); +void setMemberFileDataToArg(int index, int memberindex, char *databuf); + +// sortFamily: call this after family loaded +void sortFamily(void) +{ + int i; + + for(i = 0; i < MAX_FAMILY; i++) + { +#ifdef _PERSONAL_FAME // Arminius: + fmtotalfameindex[i] = i; +#endif +#ifdef _NEW_MANOR_LAW + fmMomentumIndex[i] = i; +#endif + fmpopularindex[i] = i; + fmadvindex[i] = i; + fmfeedindex[i] = i; + fmsynthesizeindex[i] = i; + fmdealfoodindex[i] = i; + fmpkindex[i] = i; + } +#ifdef _PERSONAL_FAME // Arminius: + qsort(fmtotalfameindex, MAX_FAMILY, sizeof(int), &fmtotalfamecompar); +#endif + qsort(fmpopularindex, MAX_FAMILY, sizeof(int), &fmpopularcompar); + qsort(fmadvindex, MAX_FAMILY, sizeof(int), &fmadvcompar); + qsort(fmfeedindex, MAX_FAMILY, sizeof(int), &fmfeedcompar); + qsort(fmsynthesizeindex, MAX_FAMILY, sizeof(int), &fmsynthesizecompar); + qsort(fmdealfoodindex, MAX_FAMILY, sizeof(int), &fmdealfoodcompar); + qsort(fmpkindex, MAX_FAMILY, sizeof(int), &fmpkcompar); +#ifdef _NEW_MANOR_LAW + qsort(fmMomentumIndex,MAX_FAMILY,sizeof(int),&fmMomentumcompar); +#endif +} + +#ifdef _PERSONAL_FAME // Arminius: +int fmtotalfamecompar(const void *indexa, const void *indexb) +{ + int famea,fameb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + famea = family[ * (int*) indexa ].fmtotalfame; + fameb = family[ * (int*) indexb ].fmtotalfame; + return (famea>fameb)? -1 : 1; +} +#endif + +#ifdef _NEW_MANOR_LAW +int fmMomentumcompar(const void *indexa, const void *indexb) +{ + int momentumA,momentumB; + + if(CheckFMUse(*(int*)indexa) == 0) return 1; // empty record + if(CheckFMUse(*(int*)indexb) == 0) return -1; + + momentumA = family[*(int*)indexa].fmmomentum; + momentumB = family[*(int*)indexb].fmmomentum; + return (momentumA > momentumB) ? -1:1; +} +#endif + +int fmpopularcompar(const void *indexa, const void *indexb) +{ + int fmpopulara,fmpopularb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmpopulara = family[ * (int*) indexa ].fmpopular; + fmpopularb = family[ * (int*) indexb ].fmpopular; + return (fmpopulara>fmpopularb)? -1 : 1; +} + +int fmadvcompar(const void *indexa, const void *indexb) +{ + int fmadva,fmadvb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmadva = family[ * (int*) indexa ].fmadv; + fmadvb = family[ * (int*) indexb ].fmadv; + return (fmadva>fmadvb)? -1 : 1; +} + +int fmfeedcompar(const void *indexa, const void *indexb) +{ + int fmfeeda,fmfeedb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmfeeda = family[ * (int*) indexa ].fmfeed; + fmfeedb = family[ * (int*) indexb ].fmfeed; + return (fmfeeda>fmfeedb)? -1 : 1; +} + +int fmsynthesizecompar(const void *indexa, const void *indexb) +{ + int fmsynthesizea,fmsynthesizeb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmsynthesizea = family[ * (int*) indexa ].fmsynthesize; + fmsynthesizeb = family[ * (int*) indexb ].fmsynthesize; + return (fmsynthesizea>fmsynthesizeb)? -1 : 1; +} + +int fmdealfoodcompar(const void *indexa, const void *indexb) +{ + int fmdealfooda,fmdealfoodb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmdealfooda = family[ * (int*) indexa ].fmdealfood; + fmdealfoodb = family[ * (int*) indexb ].fmdealfood; + return (fmdealfooda>fmdealfoodb)? -1 : 1; +} + +int fmpkcompar(const void *indexa, const void *indexb) +{ + int fmpka,fmpkb; + + if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record + if ( CheckFMUse(* (int*) indexb)==0 ) return -1; + + fmpka = family[ * (int*) indexa ].fmpk; + fmpkb = family[ * (int*) indexb ].fmpk; + return (fmpka>fmpkb)? -1 : 1; +} + +// getFMsortedlist +// arg: buf=returned list (format: "index 峤 popular|...") +// bufsize=sizeof(buf) +// bp=begin point (bp=-1 -> begin at 0) +// ep=end point (ep=-1 -> end at MAX_FAMILY-1) +// ret: 1=success; 0=failed +// Arminius end + +// ȡüֵб +// kindflag 1:ۺ 2:ð 3: 4:ϳ 5: 6:PK 7:ܺ(ۺ+) +int ACShowTopFMList(char *data, int datasize, int kindflag) +{ + int i = 0, j = 0; + char t1[4096]; + + strcpy(data, ""); + if (kindflag == 1) + { + for (i = 0; i < MAX_FAMILY; i++) { + if (strcmp(family[fmpopularindex[i]].fmname, "") == 0) + { + j++; + continue; + } +#ifdef _PERSONAL_FAME // Arminius: + #ifdef _NEW_MANOR_LAW + sprintf(t1, "%d|%d|%s|%s|%d|%d|%d",fmtotalfameindex[i], i + 1, + family[fmtotalfameindex[i]].fmname, + family[fmtotalfameindex[i]].fmleadername, + (family[fmtotalfameindex[i]].fmpopular / 100), + (family[fmtotalfameindex[i]].fmtotalfame / 100), + (family[fmtotalfameindex[i]].fmmomentum)); + #else + sprintf(t1, "%d|%d|%s|%s|%d|%d",fmtotalfameindex[i], i + 1, + family[fmtotalfameindex[i]].fmname, + family[fmtotalfameindex[i]].fmleadername, + (family[fmtotalfameindex[i]].fmpopular / 100), + (family[fmtotalfameindex[i]].fmtotalfame / 100)); + #endif +#else + sprintf(t1, "%d|%d|%s|%s|%d", fmpopularindex[i], i + 1, + family[fmpopularindex[i]].fmname, + family[fmpopularindex[i]].fmleadername, + (family[fmpopularindex[i]].fmpopular / 100)); +#endif + if (i < MAX_FAMILY) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize){ + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } + else if (kindflag == 2) + { + for (i = 0; i < TOPFMLISTNUM; i++) { + if (strcmp(family[fmadvindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmadvindex[i], i + 1, + family[fmadvindex[i]].fmname, + family[fmadvindex[i]].fmleadername, + (family[fmadvindex[i]].fmadv / 100)); + if (i < TOPFMLISTNUM) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } + else if (kindflag == 3) + { + for (i = 0; i < TOPFMLISTNUM; i++) { + if (strcmp(family[fmfeedindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmfeedindex[i], i + 1, + family[fmfeedindex[i]].fmname, + family[fmfeedindex[i]].fmleadername, + (family[fmfeedindex[i]].fmfeed / 100)); + if (i < TOPFMLISTNUM) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } + else if (kindflag == 4) + { + for (i = 0; i < TOPFMLISTNUM; i++) { + if (strcmp(family[fmsynthesizeindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmsynthesizeindex[i], i + 1, + family[fmsynthesizeindex[i]].fmname, + family[fmsynthesizeindex[i]].fmleadername, + (family[fmsynthesizeindex[i]].fmsynthesize / 100)); + if (i < TOPFMLISTNUM) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } + else if (kindflag == 5) + { + for (i = 0; i < TOPFMLISTNUM; i++) { + if (strcmp(family[fmdealfoodindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmdealfoodindex[i], i + 1, + family[fmdealfoodindex[i]].fmname, + family[fmdealfoodindex[i]].fmleadername, + (family[fmdealfoodindex[i]].fmdealfood / 100)); + if (i < TOPFMLISTNUM) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } + else if (kindflag == 6) + { + for (i = 0; i < TOPFMLISTNUM; i++) { + if (strcmp(family[fmpkindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmpkindex[i], i + 1, + family[fmpkindex[i]].fmname, + family[fmpkindex[i]].fmleadername, + (family[fmpkindex[i]].fmpk / 100)); + if (i < TOPFMLISTNUM) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } +#ifdef _PERSONAL_FAME // Arminius: + else if (kindflag == 7) + { + for (i = 0; i < MAX_FAMILY; i++) { + if (strcmp(family[fmtotalfameindex[i]].fmname, "") == 0) + { + j++; + continue; + } + sprintf(t1, "%d|%d|%s|%s|%d", fmtotalfameindex[i], i + 1, + family[fmtotalfameindex[i]].fmname, + family[fmtotalfameindex[i]].fmleadername, + (family[fmtotalfameindex[i]].fmtotalfame / 100)); + if (i < MAX_FAMILY) strcat(t1, " "); + if (strlen(data) + strlen(t1) >= datasize) + { + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } +#endif +#ifdef _NEW_MANOR_LAW + else if(kindflag == 8){ // ʮƼ(ȫgame server) + for(i=0;i= datasize){ + log("getFMsortedlist: datafer overflow."); + return -1; + } + strcat(data, t1); + } + } +#endif + return i - j; +} + +void AddFMMaintainSort(int index) +{ + int i = 0, j = MAX_FAMILY - 1, k; + // modify popular sort + while ((family[fmpopularindex[i]].fmpopular >= family[index].fmpopular) + && (i < MAX_FAMILY) && CheckFMUse(fmpopularindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmpopularindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmpopularindex[k] = fmpopularindex[k - 1]; + fmpopularindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmpopularindex add error (j < i)"); + } else log("ACAddFM: fmpopularindex add error (j = i)"); + // modify adv sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmadvindex[i]].fmadv >= family[index].fmadv) + && (i < MAX_FAMILY) && CheckFMUse(fmadvindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmadvindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmadvindex[k] = fmadvindex[k - 1]; + fmadvindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmadvindex add error (j < i)"); + } else log("ACAddFM: fmadvindex add error (j = i)"); + // modify feed sort + i = 0; j = MAX_FAMILY; k = 0; + while ((family[fmfeedindex[i]].fmfeed >= family[index].fmfeed) + && (i < MAX_FAMILY) && CheckFMUse(fmfeedindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmfeedindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmfeedindex[k] = fmfeedindex[k - 1]; + fmfeedindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmfeedindex add error (j < i)"); + } else log("ACAddFM: fmfeedindex add error (j = i)"); + // modify synthesize sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmsynthesizeindex[i]].fmsynthesize >= family[index].fmsynthesize) + && (i < MAX_FAMILY) && CheckFMUse(fmsynthesizeindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmsynthesizeindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmsynthesizeindex[k] = fmsynthesizeindex[k - 1]; + fmsynthesizeindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmsynthesizeindex add error (j < i)"); + } else log("ACAddFM: fmsynthesizeindex add error (j = i)"); + // modify dealfood sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmdealfoodindex[i]].fmdealfood >= family[index].fmdealfood) + && (i < MAX_FAMILY) && CheckFMUse(fmdealfoodindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmdealfoodindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmdealfoodindex[k] = fmdealfoodindex[k - 1]; + fmdealfoodindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmdealfoodindex add error (j < i)"); + } else log("ACAddFM: fmdealfoodindex add error (j = i)"); + // modify pk sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmpkindex[i]].fmpk >= family[index].fmpk) + && (i < MAX_FAMILY) && CheckFMUse(fmpkindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmpkindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmpkindex[k] = fmpkindex[k - 1]; + fmpkindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmpkindex add error (j < i)"); + } else log("ACAddFM: fmpkindex add error (j = i)"); +#ifdef _PERSONAL_FAME // Arminius: + // modify pk sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmtotalfameindex[i]].fmtotalfame >= family[index].fmtotalfame) + && (i < MAX_FAMILY) && CheckFMUse(fmtotalfameindex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmtotalfameindex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmtotalfameindex[k] = fmtotalfameindex[k - 1]; + fmtotalfameindex[i] = index; + } else if (j < i) { + log("ACAddFM: fmtotalfameindex add error (j < i)"); + } else log("ACAddFM: fmtotalfameindex add error (j = i)"); +#endif +#ifdef _NEW_MANOR_LAW + // modify momentum sort + i = 0;j = MAX_FAMILY;k = 0; + while ((family[fmMomentumIndex[i]].fmmomentum >= family[index].fmmomentum) + && (i < MAX_FAMILY) && CheckFMUse(fmMomentumIndex[i])) + { + if (i == MAX_FAMILY -1) break; + i++; + } + while ((fmMomentumIndex[j] != index) && (j > 0)) j--; + if (j > i) + { + for (k = j; k > i; k--) fmMomentumIndex[k] = fmMomentumIndex[k - 1]; + fmMomentumIndex[i] = index; + } else if (j < i) { + log("ACAddFM: fmMomentumIndex add error (j < i)"); + } else log("ACAddFM: fmMomentumIndex add error (j = i)"); +#endif +} + +void DelFMMaintainSort(int index) +{ + int i = 0,j; + // modify popular sort + while ((fmpopularindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmpopularindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmpopularindex[j] = fmpopularindex[j + 1]; + fmpopularindex[MAX_FAMILY - 1] = index; // move to last one + } + // modify adv sort + i = 0;j = 0; + while ((fmadvindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmadvindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmadvindex[j] = fmadvindex[j + 1]; + fmadvindex[MAX_FAMILY - 1] = index; // move to last one + } + // modify feed sort + i = 0;j = 0; + while ((fmfeedindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmfeedindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmfeedindex[j] = fmfeedindex[j + 1]; + fmfeedindex[MAX_FAMILY - 1] = index; // move to last one + } + // modify synthesize sort + i = 0;j = 0; + while ((fmsynthesizeindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmsynthesizeindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmsynthesizeindex[j] = fmsynthesizeindex[j + 1]; + fmsynthesizeindex[MAX_FAMILY - 1] = index; // move to last one + } + // modify dealfood sort + i = 0;j = 0; + while ((fmdealfoodindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmdealfoodindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmdealfoodindex[j] = fmdealfoodindex[j + 1]; + fmdealfoodindex[MAX_FAMILY - 1] = index; // move to last one + } + // modify pk sort + i = 0;j = 0; + while ((fmpkindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmpkindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmpkindex[j] = fmpkindex[j + 1]; + fmpkindex[MAX_FAMILY - 1] = index; // move to last one + } +#ifdef _PERSONAL_FAME // Arminius: + // modify pk sort + i = 0;j = 0; + while ((fmtotalfameindex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmtotalfameindex[i] == index) + { + for (j = i; j < MAX_FAMILY - 1; j++) + fmtotalfameindex[j] = fmtotalfameindex[j + 1]; + fmtotalfameindex[MAX_FAMILY - 1] = index; // move to last one + } +#endif +#ifdef _NEW_MANOR_LAW + // modify momentum sort + i = 0;j = 0; + while ((fmMomentumIndex[i] != index) && (i < MAX_FAMILY)) i++; + if (fmMomentumIndex[i] == index){ + for (j = i; j < MAX_FAMILY - 1; j++) + fmMomentumIndex[j] = fmMomentumIndex[j + 1]; + fmMomentumIndex[MAX_FAMILY - 1] = index; // move to last one + } +#endif +} + +// ӵȡϣʱȡ +int readFamily(char *dir) +{ + char dirname[256]; + DIR *d; + struct dirent *de; + int i = 0, fmnum = 0, fmmaxnum = 0; + { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "%s", dir); + if (mkdir(tmp, 0755) == 0) + log("create %s\n", tmp); + } + + snprintf(dirname, sizeof(dirname), "%s", dir); + d = opendir(dirname); + if (d == NULL){ + log("cannot open %s\n", dirname); + return -1; + } + de = readdir(d); + if(de == NULL){ + log("de == NULL\n"); + return -1; + } +{ + char filename[256]; + struct stat s; + for (i = 0; i < MAX_FAMILY; i++){ +// FILE *fp; + snprintf(filename, sizeof(filename), "%s/Family.%d", dirname, i); + if (stat(filename, &s) < 0)continue; + + if (!(s.st_mode & S_IFREG)){ + log("%s is not a regular file\n", filename); + continue; + } + if( readOneFamily( filename, i) != 1 ){ + if (remove(filename) == -1) + log("cannot open file %s %s\n", filename, strerror(errno)); + continue; + } + fmnum = fmnum + 1; + fmmaxnum = i; + } + + fmindexmaxnum = fmmaxnum; + fmnownum = fmnum; +} + closedir(d); + +#ifdef _PERSONAL_FAME // Arminius: + // ܺ = ۺ + + { + int i,j; + for (i = 0; i < MAX_FAMILY; i++) { + family[i].fmpopular=family[i].fmadv+family[i].fmfeed + +family[i].fmsynthesize+family[i].fmdealfood + +family[i].fmpk; + family[i].fmtotalfame=family[i].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[i].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[i].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + family[i].fmtotalfame += family[i].fmmemberindex[j].popular; + } + } + } +#endif + + sortFamily(); // Arminius: sort it + return 0; +} + +// д뵵 +int writeFamily(char *dir) +{ + int i = 0, j = 0, k = 0; + FILE *fp; + char filename[256]; + for (i = 0; i < MAX_FAMILY; i++) + { + if (db_familyupdate[i] == 0) continue; + sprintf(filename, "%s/Family.%d", dir, family[i].fmindex - 1); + fp = fopen(filename, "w"); + if (fp == NULL) continue; + if ((family[i].fmindex != -1) && (strcmp(family[i].fmname, "") != 0)) + { + fprintf(fp, "fmindex=%d|fmname=%s|fmleadername=%s|fmleaderid=%s|" + "fmleadergrano=%d|petname=%s|petattr=%s|fmnum=%d|fmjoinnum=%d|" + "fmacceptflag=%d|fmsetupflag=%d|fmrule=%s|fmsprite=%d|" + "fmpointindex=%d|fmpopular=%d|fmgold=%d|fmmemberindexmaxnum=%d|" + "apply_time=%d|setup_time=%d|predel_time=%d|memonowwritenum=%d|" + "memonum=%d|fmadv=%d|fmfeed=%d|fmsynthesize=%d|fmdealfood=%d|fmpk=%d" +#ifdef _NEW_MANOR_LAW + "|fmmomentum=%d" +#endif +#ifdef _FAMILY_TOTEM + "|familytotem=%s" +#endif +#ifdef _FAMILY_PAY_POINT + "|fmpaypoint=%d" +#endif +#ifdef _FAMILYBADGE_ + "|fmbadge=%d" +#endif + + ,family[i].fmindex, family[i].fmname, family[i].fmleadername, + family[i].fmleaderid, family[i].fmleadergrano, family[i].petname, + family[i].petattr, family[i].fmnum, family[i].fmjoinnum, + family[i].fmacceptflag, family[i].fmsetupflag, family[i].fmrule, + family[i].fmsprite, family[i].fmpointindex, family[i].fmpopular, + family[i].fmgold, family[i].fmmemberindexmaxnum, + family[i].apply_time, family[i].setup_time, family[i].predel_time, + family[i].memonowwritenum, family[i].memonum, family[i].fmadv, + family[i].fmfeed, family[i].fmsynthesize, family[i].fmdealfood, + family[i].fmpk +#ifdef _NEW_MANOR_LAW + ,family[i].fmmomentum +#endif +#ifdef _FAMILY_TOTEM + ,family[i].familytotem +#endif +#ifdef _FAMILY_PAY_POINT + ,family[i].fmpaypoint +#endif +#ifdef _FAMILYBADGE_ + ,family[i].fmbadge +#endif + ); + for (j = 0; j < family[i].memonum; j++) + fprintf(fp, "|%s%d=%s", FMMEMOLIST, j, family[i].memolist[j]); + for (k = 0; k < family[i].fmmemberindexmaxnum; k++) + { + if ((strcmp(family[i].fmmemberindex[k].charname, "") != 0) + && (strcmp(family[i].fmmemberindex[k].charid, "") != 0) + && (family[i].fmmemberindex[k].charflag != FMMEMBER_NONE)) + { +#ifdef _FMVER21 + #ifndef _NEW_MANOR_LAW + fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d eventflag=%d", + #else + fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d eventflag=%d momentum=%d", + #endif +#else + fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d", +#endif + FMMEMBERINDEX, k, family[i].fmmemberindex[k].charname, + family[i].fmmemberindex[k].charid, + family[i].fmmemberindex[k].charlv, + family[i].fmmemberindex[k].charflag, + family[i].fmmemberindex[k].onlineflag, + family[i].fmmemberindex[k].predeltime, + family[i].fmmemberindex[k].popular +#ifdef _FMVER21 + ,family[i].fmmemberindex[k].eventflag +#endif +#ifdef _NEW_MANOR_LAW + ,family[i].fmmemberindex[k].momentum +#endif + ); + } + } // for + fprintf(fp, "\n"); + } // if + fclose(fp); + db_familyupdate[i] = 0; + } + + return 0; +} + +// ӵȡׯ԰ʱȡ +int readFMPoint(char *dir) +{ + char dirname[256]; + DIR *d; + struct dirent *de; + int i = 0; + { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "%s", dir); + if (mkdir(tmp, 0755) == 0) + log("create %s\n", tmp); + } + + snprintf(dirname, sizeof(dirname), "%s", dir); + d = opendir(dirname); + if (d == NULL) + { + log("޷ļ %s\n", dirname); + return -1; + } + while(1) + { + de = readdir(d); + if(de == NULL) break; + if (de -> d_name[0] != '.') + { + char filename[256]; + FILE *fp; + struct stat s; + snprintf(filename, sizeof(filename), "%s/%s", dirname, de -> d_name); + if (stat(filename, &s) < 0){ + continue; + } + if (!(s.st_mode & S_IFREG)) + { + log("%s is not a regular file\n", filename); + continue; + } + fp = fopen(filename, "r"); + if (fp == NULL) + { + log("޷ļ %s %s\n", filename, strerror(errno)); + continue; + } + while(1) + { + char line[1024]; + char data[1024]; + if (fgets(line, sizeof(line), fp) == NULL) + break; + chop(line); + if( strstr( line, "#") != 0 ) continue; + easyGetTokenFromBuf(line, "|", 1, data, sizeof(data)); + fmpoint[i].fl = atoi(data); + easyGetTokenFromBuf(line, "|", 2, data, sizeof(data)); + fmpoint[i].x = atoi(data); + easyGetTokenFromBuf(line, "|", 3, data, sizeof(data)); + fmpoint[i].y = atoi(data); + easyGetTokenFromBuf(line, "|", 4, data, sizeof(data)); + fmpoint[i].fmfl = atoi(data); + easyGetTokenFromBuf(line, "|", 5, data, sizeof(data)); + fmpoint[i].village = atoi(data); + easyGetTokenFromBuf(line, "|", 6, data, sizeof(data)); + fmpoint[i].hadfmindex = atoi(data); + easyGetTokenFromBuf(line, "|", 7, data, sizeof(data)); + strcpy(fmpoint[i].hadfmname, data); + easyGetTokenFromBuf(line, "|", 8, data, sizeof(data)); + fmpoint[i].hadfmpopular = atoi(data); +#ifdef _FIX_FMPOINTTIME + easyGetTokenFromBuf(line, "|", 9, data, sizeof(data)); + fmpoint[i].fmpointtime = atoi(data); +#endif + i++; + } + fclose(fp); + } + } + closedir(d); + return 0; +} + +// ׯ԰д뵵 +int writeFMPoint(char *dir) +{ + int i = 0; + FILE *fp; + char filename[256]; + sprintf(filename, "%s/db_fmpoint", dir); + if (db_fmpointupdate == 0) + return 0; + else + log("ѽdb_fmpointдļ.\n"); + fp = fopen(filename, "w"); + if (fp == NULL) + { + log("޷ļ: %s %s\n", filename, strerror(errno)); + return -1; + } + for(i = 0; i < MAX_FMPOINT; i++) + { +#ifdef _FIX_FMPOINTTIME + fprintf(fp, "%d|%d|%d|%d|%d|%d|%s|%d|%d\n", +#else + fprintf(fp, "%d|%d|%d|%d|%d|%d|%s|%d\n", +#endif + fmpoint[i].fl, fmpoint[i].x, fmpoint[i].y, fmpoint[i].fmfl, + fmpoint[i].village, fmpoint[i].hadfmindex, fmpoint[i].hadfmname, + fmpoint[i].hadfmpopular +#ifdef _FIX_FMPOINTTIME + , fmpoint[i].fmpointtime +#endif + ); + } // for + fclose(fp); + db_fmpointupdate = 0; + return 0; +} + +// ӵжȡ֮ϣʱȡ +int readFMSMemo(char *dir) +{ + char dirname[256]; + DIR *d; + struct dirent *de; + int i = 0; + { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "%s", dir); + if (mkdir(tmp, 0755) == 0) + log("create %s\n", tmp); + } + + snprintf(dirname, sizeof(dirname), "%s", dir); + d = opendir(dirname); + if (d == NULL) + { + log("޷ļ %s\n", dirname); + return -1; + } + while(1) + { + de = readdir(d); + if(de == NULL) break; + if (de -> d_name[0] != '.') + { + char filename[256]; + FILE *fp; + struct stat s; + snprintf(filename, sizeof(filename), "%s/%s", dirname, de -> d_name); + if (stat(filename, &s) < 0){ + continue; + } + if (!(s.st_mode & S_IFREG)) + { + log("%s ļ\n", filename); + continue; + } + fp = fopen(filename, "r"); + if (fp == NULL) + { + log("޷ļ %s %s\n", filename, strerror(errno)); + continue; + } + { + char line[15000]; + char data[15000]; + if (fgets(line, sizeof(line), fp) == NULL) + break; + chop(line); + easyGetTokenFromBuf(line, "|", 1, data, sizeof(data)); + fmsmemo.num = atoi(data); + easyGetTokenFromBuf(line, "|", 2, data, sizeof(data)); + fmsmemo.fmsnowwritenum = atoi(data); + for (i = 0; i < fmsmemo.num; i++){ + easyGetTokenFromBuf(line, "|", 3 + i, data, sizeof(data)); + strcpy(fmsmemo.memodata[i], data); + } + } + fclose(fp); + } + } + closedir(d); + return 0; +} + +// ֮д뵵 +int writeFMSMemo(char *dir) +{ + int i = 0; + FILE *fp; + char filename[256]; + sprintf(filename, "%s/db_fmsmemo", dir); + if (db_fmsmemoupdate == 0) + return 0; + else + log("ѽdb_fmsmemoдļ.\n"); + fp = fopen(filename, "w"); + if (fp == NULL) + { + log("޷ļ: %s %s\n", filename, strerror(errno)); + return -1; + } + fprintf(fp, "%d|%d", fmsmemo.num, fmsmemo.fmsnowwritenum); + for(i = 0; i < fmsmemo.num; i++) + { + fprintf(fp, "|%s", fmsmemo.memodata[i]); + log("%s\n", fmsmemo.memodata[i]); + } // for + fprintf(fp, "\n"); + fclose(fp); + db_fmsmemoupdate = 0; + return 0; +} + +// ȡδʹõ index +int getblankindex() +{ + int i = 0; + for(i = 0; i < MAX_FAMILY; i++) + if (((family[i].fmindex <= 0) || (family[i].fmindex > MAX_FAMILY)) + && (strcmp(family[i].fmname, "") == 0)) + return i; + return -1; +} + +// ȡδʹõ fmindex +int getblankfmindex() +{ + int i = 0, j = 0; + for (i = 1; i <= MAX_FAMILY; i++) + { + int useflag = 0; + for (j = 0; j < MAX_FAMILY; j++) + { + if (family[j].fmindex == i) + { + useflag = 1; + break; + } + } + if (useflag == 0) + return i; + } + return -1; +} + +// fmindex, fmname ȡ index +int getindex(int fmindex, char *fmname) +{ + int i = 0; + for (i = 0; i <= fmindexmaxnum; i++) + { + if ((family[i].fmindex == fmindex) + && (strcmp(family[i].fmname, fmname) == 0)) + return i; + } + return -1; +} + +// ɾׯ԰ļ fmindex +int delfmpointindex(int fmindex) +{ + int i; + for (i = 0; i < MAX_FMPOINT; i++) + { + if (fmpoint[i].hadfmindex == fmindex) + { + fmpoint[i].hadfmindex = -1; + strcpy(fmpoint[i].hadfmname, "-1"); + fmpoint[i].hadfmpopular = -1; + db_fmpointupdate = 1; + return 0; + } + } + return -1; +} + +// index Ƿʹ +int CheckFMUse(int index) +{ + if ((index >= MAX_FAMILY) || (index < 0)) + return -1; + if ((family[index].fmindex < 0) || (strcmp(family[index].fmname, "") == 0)) + return 0; + else + return 1; +} + +// index fmindex, fmnameǷȷ +int CheckFM(int *index, char *fmname, int fmindex) +{ + if (*index == -1){ + *index = getindex(fmindex, fmname); + } + if ((*index > MAX_FAMILY) || (*index < 0)){ + log ("CheckFM_2 *index: big small? %d\n", *index); + return -1; + }else { + if ((family[*index].fmindex != fmindex) + || strcmp(family[*index].fmname, fmname) != 0) + { + log("CheckFM_3 [*index].fmindex:%d fmindex:%d [index].fmname:%s fmname:%s\n", + family[*index].fmindex, fmindex, family[*index].fmname, fmname); + return -1; + } + } + if (*index == -1){ + log ("CheckFM_4 index: -1 ? %d\n", *index); + return -1; + } + if(CheckFMUse(*index) == 0) + { + log ("CheckFM_5 index: -1 ? %d\n", *index); + return -1; + } + if (family[*index].fmnum > MAX_MEMBERNUM || family[*index].fmjoinnum > MAX_MEMBERNUM) + { + log ("CheckFM_6 fmnum: -1 ? %d\n", family[*index].fmnum); + return -1; + } + return 0; +} + +// ɾ̫֮δվ֮Ա +#ifdef _DEATH_FAMILY_LOGIN_CHECK +void delovertimeFMMem(int time) +{ + int i = 0, j = 0, k = 0; + char data[150 * MAX_FAMILY]; + extern gmsv gs[MAXCONNECTION]; + for (i = 0 ; i <= fmindexmaxnum; i++){ + if(CheckFMUse(i) == 0) + continue; + if ( ( (family[i].predel_time < time) && (family[i].predel_time != -1) + && (family[i].fmsetupflag != 1)) || (family[i].fmjoinnum==0) ){ + + log("ACDelOverTimeFM fmindex:%d fmname:%s fmjoinnum:%d flag:%d \n", + family[i].fmindex, family[i].fmname, + family[i].fmjoinnum, family[i].fmsetupflag ); + + ACDelFM(i, family[i].fmname, family[i].fmindex); + + // ͼɾ֮ѶϢ GMSV + for (k = 0; k < MAXCONNECTION; k++){ + if (gs[k].use && gs[k].name[0]) + saacproto_ACFMAnnounce_send(k, SUCCESSFUL, + family[i].fmname, family[i].fmindex, i, + 2, "", 0); + } + + db_familyupdate[i] = 1; + continue; + } + + for (j = 1; j < family[i].fmmemberindexmaxnum; j++){ + if (family[i].fmmemberindex[j].charflag == FMMEMBER_NONE) + continue; + if ((family[i].fmmemberindex[j].predeltime < time) + && (family[i].fmmemberindex[j].predeltime != -1)){ +#ifdef _FMVER21 + ACMemberLeaveFM(i, family[i].fmname, family[i].fmindex, + family[i].fmmemberindex[j].charname, 0, j, 0); +#else + ACMemberLeaveFM(i, family[i].fmname, family[i].fmindex, + family[i].fmmemberindex[j].charname, 0, j); +#endif + db_familyupdate[i] = 1; + + + // ֪ͨ峤ѱɾ + if (family[i].fmmemberindex[0].onlineflag > 0) + { + char buf[256]; + sprintf(buf, "(%s)̫δ߶뿪ļˣĿǰ%4d", + family[i].fmmemberindex[j].charname, family[i].fmjoinnum); + saacproto_ACFMAnnounce_send(family[i].fmmemberindex[0].onlineflag, + SUCCESSFUL, family[i].fmname, family[i].fmindex, i, 3, buf, + family[i].fmmemberindex[0].charfdid); + } + + + } // if + } // for + } // for + if (db_familyupdate[i] == 1) + { + ACShowFMList(data); + + for (i = 0; i < MAXCONNECTION; i++) + { + if (gs[i].use && gs[i].name[0]) + saacproto_ACShowFMList_send(i, SUCCESSFUL, fmnownum, data); + } + } +} +#endif +// +#ifdef _PERSONAL_FAME +int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid) +#else +int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid) +#endif +{ + int i = 0, index, fmindex; + time_t t1; + index = getblankindex(); + if (index == -1) { + return -1; // + } + fmindex = getblankfmindex(); + if (fmindex == -1){ + return -1; // ޿յ fmindex + } + for (i = 0; i <= fmindexmaxnum; i++){ + if(strcmp(family[i].fmname, fmname) == 0) + return -2; // ͬƴ + } + *workindex = index; + family[index].fmindex = fmindex; + strcpy(family[index].fmname, fmname); + strcpy(family[index].fmleadername, fmleadername); + strcpy(family[index].fmleaderid, fmleaderid); + family[index].fmleadergrano = fmleadergrano; + strcpy(family[index].petname, petname); + strcpy(family[index].petattr, petattr); + family[index].fmnum = 1; + family[index].fmjoinnum = 1; + family[index].fmacceptflag = 1; + strcpy(family[index].fmrule, fmrule); + family[index].fmsprite = fmsprite; +#ifdef _FAMILYBADGE_ + family[index].fmbadge = fmbadge; +#endif + family[index].fmpointindex = -1; + family[index].fmgold = 0; + family[index].fmmemberindexmaxnum = 1; + time(&t1); + family[index].apply_time = t1; + family[index].predel_time = t1 + PREDEL_TIME; + family[index].fmmemberindex[0].charlv = fmleaderlv; +#ifdef _FMVER21 + family[index].fmmemberindex[0].charflag = FMMEMBER_LEADER; + family[index].fmmemberindex[0].eventflag = 1; +#else + family[index].fmmemberindex[0].charflag = 1; +#endif + family[index].fmmemberindex[0].onlineflag = fd; + strcpy(family[index].fmmemberindex[0].charid, fmleaderid); + strcpy(family[index].fmmemberindex[0].charname, fmleadername); + family[index].fmmemberindex[0].charfdid = charfdid; + family[index].fmmemberindex[0].predeltime = -1; + family[index].memonowwritenum = 0; + family[index].memonum = 0; + family[index].fmpopular = 0; + family[index].fmadv = 0; + family[index].fmfeed = 0; + family[index].fmsynthesize = 0; + family[index].fmdealfood = 0; + family[index].fmpk = 0; +#ifdef _PERSONAL_FAME // Arminius: + family[index].fmmemberindex[0].popular = fame; + family[index].fmtotalfame = fame; +#endif +#ifdef _NEW_MANOR_LAW + family[index].fmmomentum = 0; +#endif + +#ifdef _FAMILY_TOTEM + strcpy(family[index].familytotem, ""); +#endif + + db_familyupdate[index] = 1; + fmnownum++; + if (fmindexmaxnum <= index) fmindexmaxnum = index + 1; + log("AddFM fmindexmaxnum:%d fmnownum:%d\n", fmindexmaxnum, fmnownum); + + AddFMMaintainSort(index); + + return fmindex; +} + +// +#ifdef _PERSONAL_FAME // Arminius: +int ACJoinFM(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int fame, int charfdid) +#else +int ACJoinFM(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int charfdid) +#endif +{ + int i = 0; + time_t t1; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + if (family[index].fmacceptflag == 0) return -2; + if (family[index].fmnum >= MAX_MEMBERNUM || family[index].fmjoinnum >= MAX_MEMBERNUM) + return -3; + + // ֹ峤Լļ code:shan + if ((strcmp(family[index].fmmemberindex[0].charname, charname) == 0) + && (strcmp(family[index].fmmemberindex[0].charid, charid) == 0)) + return -1; + + for (i = 1; i < MAX_MEMBERNUM; i++){ + if ((strcmp(family[index].fmmemberindex[i].charname, "") == 0) + && (strcmp(family[index].fmmemberindex[i].charid, "") == 0)){ + strcpy(family[index].fmmemberindex[i].charname, charname); + strcpy(family[index].fmmemberindex[i].charid, charid); + family[index].fmmemberindex[i].charlv = charlv; +#ifdef _FMVER21 + family[index].fmmemberindex[i].charflag = FMMEMBER_APPLY; + family[index].fmmemberindex[i].eventflag = 0; +#else + family[index].fmmemberindex[i].charflag = 2; +#endif + family[index].fmmemberindex[i].onlineflag = fd; + family[index].fmmemberindex[i].charfdid = charfdid; + time(&t1); + family[index].fmmemberindex[i].predeltime = t1 + PREDEL_TIME; +#ifdef _PERSONAL_FAME // Arminius: + family[index].fmmemberindex[i].popular = fame; + log("fame:%d\n", fame); + // ʱ򻹲԰˵ӵ +#endif +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[i].momentum = 0; +#endif + family[index].fmnum = family[index].fmnum + 1; + if (family[index].fmmemberindexmaxnum <= i) family[index].fmmemberindexmaxnum = i + 1; + db_familyupdate[index] = 1; +#ifdef _PERSONAL_FAME // Arminius: + // + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + SUCCESSFUL, index,ACgetFMFloor(fmindex), family[index].fmtotalfame, + family[index].fmmemberindex[i].charflag, + family[index].fmsetupflag, 1, i, + family[index].fmmemberindex[i].popular, // Arminius 9.11 + family[index].fmmemberindex[i].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[i].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + SUCCESSFUL, index,ACgetFMFloor(fmindex),family[index].fmpopular, + family[index].fmmemberindex[i].charflag, + family[index].fmsetupflag, 1, i, + family[index].fmmemberindex[i].charfdid); +#endif + // ֪ͨ峤Ը + if (family[index].fmmemberindex[0].onlineflag > 0){ + char buf[256]; + sprintf(buf, "(%s lv:%d)ҪļรĿǰ%4d", + charname, charlv, family[index].fmjoinnum); + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, buf, + family[index].fmmemberindex[0].charfdid); + } + return 0; + } + } + return -1; +} + +// 뿪 +int ACLeaveFM(int index, char *fmname, int fmindex, + char *charname, char* charid) +{ + int i = 0; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + for (i = 1; i < family[index].fmmemberindexmaxnum; i++) + { + if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0) + && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0)) + { +#ifdef _FMVER21 + ACMemberLeaveFM(index, fmname, fmindex, charname, 0, i, 0); +#else + ACMemberLeaveFM(index, fmname, fmindex, charname, 0, i); +#endif + db_familyupdate[index] = 1; + // ֪ͨ峤뿪 + if (family[index].fmmemberindex[0].onlineflag > 0) + { + char buf[256]; + sprintf(buf, "(%s)Ѿ뿪ļˣĿǰ%4d", + charname, family[index].fmjoinnum); + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, buf, + family[index].fmmemberindex[0].charfdid); + } + return 0; + } + } + return -1; +} +// +// kindflag 1:ǷļԱ 2:У 3:ػ 4:ּ +// 5:ɢʱ 6: 7:ð 8: +// 9:ϳɡӹ 10: 11:峤 +int ACFixFMData(int index, char *fmname, int fmindex, int kindflag, int charindex, + char *data1, char *data2) +{ + int recvdata = 0; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + if (kindflag == 1 || kindflag == 2 || (kindflag >= 6 && kindflag <= 11) +#ifdef _NEW_MANOR_LAW + || kindflag == 12 || kindflag == 13 +#endif + ){ + recvdata = atoi(data1); + if (recvdata > MAXRECVPOP && (kindflag == 2 || (kindflag >= 7 && kindflag <= 10))) { + log("ACDelOverTimePOP index:%d fmname:%s kindflag:%d charindex:%d recvdata:%d\n", + index, fmname, kindflag, charindex, recvdata); + return -1; + } + } + if (kindflag == 1) + family[index].fmacceptflag = recvdata; + else if (kindflag == 2){ + family[index].fmpk = family[index].fmpk + recvdata; + if (family[index].fmpk < MINFMPOPNUM) family[index].fmpk = MINFMPOPNUM; + if (family[index].fmpk > MAXFMPOPNUM) family[index].fmpk = MAXFMPOPNUM; + }else if (kindflag == 3){ + if ((strcmp(data1, "") == 0) || (strcmp(data2, "") == 0)) return -1; + strcpy(family[index].petname, data1); + strcpy(family[index].petattr, data2); + if (family[index].fmsetupflag == 1) + family[index].predel_time = -1; + }else if (kindflag == 4){ + if (strcmp(data1, "") == 0) return -1; + strcpy(family[index].fmrule, data1); + }else if (kindflag == 5){ + time_t t1; + time(&t1); + family[index].predel_time = t1 + PREDEL_TIME; + }else if (kindflag == 6){ + if (family[index].fmgold + recvdata < 0) return -1; + family[index].fmgold = family[index].fmgold + recvdata; + if (family[index].fmgold > FMMAXGOLD) + family[index].fmgold = FMMAXGOLD; + sprintf(data2,"%d",family[index].fmgold); + } + else if (kindflag == 7){ + family[index].fmadv = family[index].fmadv + recvdata; + if (family[index].fmadv < 0) family[index].fmadv = 0; + if (family[index].fmadv > MAXFMPOPNUM) family[index].fmadv = MAXFMPOPNUM; +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[charindex].momentum += recvdata; + if (family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0; + if (family[index].fmmemberindex[charindex].momentum > MAXFMPOPNUM) family[index].fmmemberindex[charindex].momentum = MAXFMPOPNUM; + family[index].fmmemberindex[charindex].popular = atoi(data2); +#endif + }else if (kindflag == 8){ + family[index].fmfeed = family[index].fmfeed + recvdata; + if (family[index].fmfeed < 0) family[index].fmfeed = 0; + if (family[index].fmfeed > MAXFMPOPNUM) family[index].fmfeed = MAXFMPOPNUM; +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[charindex].momentum += recvdata; + if (family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0; + if (family[index].fmmemberindex[charindex].momentum > MAXFMPOPNUM) family[index].fmmemberindex[charindex].momentum = MAXFMPOPNUM; + family[index].fmmemberindex[charindex].popular = atoi(data2); +#endif + } +#ifndef _NEW_MANOR_LAW + else if (kindflag == 9){ + family[index].fmsynthesize = family[index].fmsynthesize + recvdata; + if (family[index].fmsynthesize < 0) family[index].fmsynthesize = 0; + if (family[index].fmsynthesize > MAXFMPOPNUM) family[index].fmsynthesize = MAXFMPOPNUM; + } + else if (kindflag == 10){ + family[index].fmdealfood = family[index].fmdealfood + recvdata; + if (family[index].fmdealfood < 0) family[index].fmdealfood = 0; + if (family[index].fmdealfood > MAXFMPOPNUM) family[index].fmdealfood = MAXFMPOPNUM; + } +#endif +#ifdef _FMVER21 + else if (kindflag == 11){ + char charname[256], charid[256]; + int charlv, onlineflag, charfdid, popular; +#ifdef _NEW_MANOR_LAW + int momentum; +#endif + int floor = ACgetFMFloor(fmindex); + if (strcmp(family[index].fmmemberindex[charindex].charname, data2) != 0 + || strcmp(family[index].fmmemberindex[charindex].charid, "") == 0) + return -1; + // shan 2002/01/04 + log("\nshan-->fmindex:%d fmname:%s newleadername:%s newleaderid->%s\n", + fmindex, fmname, family[index].fmmemberindex[charindex].charname, + family[index].fmmemberindex[charindex].charid ); + strcpy(charname, family[index].fmmemberindex[charindex].charname); + strcpy(charid, family[index].fmmemberindex[charindex].charid); + charlv = family[index].fmmemberindex[charindex].charlv; + onlineflag = family[index].fmmemberindex[charindex].onlineflag; + charfdid = family[index].fmmemberindex[charindex].charfdid; + popular = family[index].fmmemberindex[charindex].popular; +#ifdef _NEW_MANOR_LAW + momentum = family[index].fmmemberindex[charindex].momentum; +#endif + // ת + strcpy(family[index].fmmemberindex[charindex].charname, + family[index].fmmemberindex[0].charname); + strcpy(family[index].fmmemberindex[charindex].charid, + family[index].fmmemberindex[0].charid); + family[index].fmmemberindex[charindex].charlv = family[index].fmmemberindex[0].charlv; + family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER; + family[index].fmmemberindex[charindex].onlineflag = family[index].fmmemberindex[0].onlineflag; + family[index].fmmemberindex[charindex].charfdid = family[index].fmmemberindex[0].charfdid; + family[index].fmmemberindex[charindex].popular = family[index].fmmemberindex[0].popular; +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[charindex].momentum = family[index].fmmemberindex[0].momentum; +#endif + + strcpy(family[index].fmmemberindex[0].charname, charname); + strcpy(family[index].fmmemberindex[0].charid, charid); + family[index].fmmemberindex[0].charlv = charlv; + family[index].fmmemberindex[0].charflag = FMMEMBER_LEADER; + family[index].fmmemberindex[0].onlineflag = onlineflag; + family[index].fmmemberindex[0].charfdid = charfdid; + family[index].fmmemberindex[0].popular = popular; +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[0].momentum = momentum; +#endif + strcpy(family[index].fmleadername, charname); + strcpy(family[index].fmleaderid, charid); + family[index].fmleadergrano = recvdata; + strcpy(family[index].petname, ""); + strcpy(family[index].petattr, ""); + + // 峤 + if (family[index].fmmemberindex[0].onlineflag > 0) + { +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].popular, // Arminius 9.11 + family[index].fmmemberindex[0].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[0].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].charfdid); +#endif + } + // ³Ա + if (family[index].fmmemberindex[charindex].onlineflag > 0) + { +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, charindex, + family[index].fmmemberindex[charindex].popular, // Arminius 9.11 + family[index].fmmemberindex[charindex].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, charindex, + family[index].fmmemberindex[charindex].charfdid); +#endif + } + } +#endif +#ifdef _NEW_MANOR_LAW + else if (kindflag == 12){ + family[index].fmmemberindex[charindex].momentum = recvdata; + if(family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0; + if(family[index].fmmemberindex[charindex].momentum > MAXFMMOMENTUM) family[index].fmmemberindex[charindex].momentum = MAXFMMOMENTUM; + } + else if(kindflag == 13){ + family[index].fmmemberindex[charindex].popular = recvdata; + } +#endif +#ifdef _FAMILYBADGE_ + else if (kindflag == 14){ + family[index].fmbadge = atoi(data1); + } +#endif + if ((kindflag == 2) || (kindflag == 7) || (kindflag == 8) || (kindflag == 9) + || (kindflag == 10) +#ifdef _NEW_MANOR_LAW + || (kindflag == 12) || (kindflag == 13) +#endif + ) + { +#ifdef _PERSONAL_FAME // Arminius: + // ¼Ҽ +#ifndef _NEW_MANOR_LAW + if (charindex >= 0 && charindex < MAX_MEMBERNUM) + family[index].fmmemberindex[charindex].popular += recvdata; +#endif + // + family[index].fmpopular = family[index].fmadv + family[index].fmfeed + + family[index].fmsynthesize + family[index].fmdealfood + + family[index].fmpk; + { + int j; + family[index].fmtotalfame=family[index].fmpopular; +#ifdef _NEW_MANOR_LAW + family[index].fmmomentum = 0; +#endif + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + { + family[index].fmtotalfame += family[index].fmmemberindex[j].popular; +#ifdef _NEW_MANOR_LAW + // ԱƼ + family[index].fmmomentum += family[index].fmmemberindex[j].momentum; +#endif + } + } +#ifdef _NEW_MANOR_LAW + // = (ƽ) / 10 + 1 + ԱƼ + family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100; + if(family[index].fmmomentum>2000000000)family[index].fmmomentum=2000000000; +// log("\nACFixFMData total family momentum %d\n",family[index].fmmomentum); +#endif + } + sortFamily(); + if (family[index].fmpointindex >= 0){ + fmpoint[family[index].fmpointindex].hadfmpopular = family[index].fmtotalfame; + db_fmpointupdate = 1; + } +#else + family[index].fmpopular = family[index].fmadv + family[index].fmfeed + + family[index].fmsynthesize + family[index].fmdealfood + + family[index].fmpk; + sortFamily(); + if (family[index].fmpointindex >= 0){ + fmpoint[family[index].fmpointindex].hadfmpopular = family[index].fmpopular; + db_fmpointupdate = 1; + } + // ¼Ҽ + if (charindex >= 0 && charindex < MAX_MEMBERNUM) + family[index].fmmemberindex[charindex].popular = + family[index].fmmemberindex[charindex].popular + recvdata; +#endif + // 峤 + if (family[index].fmmemberindex[0].onlineflag > 0) + { + int floor = ACgetFMFloor(fmindex); +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, +#ifdef _FMVER21 + family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0, +#else + 1, family[index].fmsetupflag, 1, 0, +#endif + family[index].fmmemberindex[0].popular, // Arminius 9.11 + family[index].fmmemberindex[0].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[0].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, +#ifdef _FMVER21 + family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0, +#else + 1, family[index].fmsetupflag, 1, 0, +#endif + family[index].fmmemberindex[0].charfdid); +#endif + } + } + db_familyupdate[index] = 1; + return kindflag; +} + +// ģУУֵ +int ACFixFMPK(int winindex, char* winfmname, int winfmindex, int loseindex, + char* losefmname, int losefmindex) +{ + int award = 0; + if (CheckFM(&winindex, winfmname, winfmindex) < 0) return -1; + if (CheckFM(&loseindex, losefmname, losefmindex) < 0) return -1; + + award = (family[loseindex].fmpopular / 10); + if (family[loseindex].fmpopular - award < 0) + award = family[loseindex].fmpopular; + + family[loseindex].fmpk = family[loseindex].fmpk - award; + family[winindex].fmpk = family[winindex].fmpk + award; + + if (family[loseindex].fmpk < MINFMPOPNUM) + { +#if 1 // Robin 2003/11/27 ䷽PKʱʤϴ + int overpoint; + overpoint = MINFMPOPNUM - family[loseindex].fmpk; + family[winindex].fmpk = family[winindex].fmpk - overpoint; +#endif + family[loseindex].fmpk = MINFMPOPNUM; + } + // CoolFish: 2001/11/28 MINFMPOPNUM -> MAXFMPOPNUM + if (family[winindex].fmpk > MAXFMPOPNUM) + family[winindex].fmpk = MAXFMPOPNUM; + + { + family[winindex].fmpopular = family[winindex].fmadv + family[winindex].fmfeed + + family[winindex].fmsynthesize + family[winindex].fmdealfood + + family[winindex].fmpk; + +#ifdef _PERSONAL_FAME // Arminius: + { + int j; + family[winindex].fmtotalfame=family[winindex].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[winindex].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[winindex].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + family[winindex].fmtotalfame += family[winindex].fmmemberindex[j].popular; + } + } +#endif + + if (family[winindex].fmmemberindex[0].onlineflag > 0) + { + int floor = ACgetFMFloor(winfmindex); +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[winindex].fmmemberindex[0].onlineflag, + SUCCESSFUL, winindex, floor, family[winindex].fmtotalfame, + #ifdef _FMVER21 + family[winindex].fmmemberindex[0].charflag, family[winindex].fmsetupflag, 1, 0, + #else + 1, family[winindex].fmsetupflag, 1, 0, + #endif + family[winindex].fmmemberindex[0].popular, // Arminius 9.11 + family[winindex].fmmemberindex[0].charfdid + #ifdef _NEW_MANOR_LAW + ,family[winindex].fmmemberindex[0].momentum + #endif + ); +#else + saacproto_ACFMCharLogin_send( + family[winindex].fmmemberindex[0].onlineflag, + SUCCESSFUL, winindex, floor, family[winindex].fmpopular, + #ifdef _FMVER21 + family[winindex].fmmemberindex[0].charflag, family[winindex].fmsetupflag, 1, 0, + #else + 1, family[winindex].fmsetupflag, 1, 0, + #endif + family[winindex].fmmemberindex[0].charfdid); +#endif + } + family[loseindex].fmpopular = family[loseindex].fmadv + family[loseindex].fmfeed + + family[loseindex].fmsynthesize + family[loseindex].fmdealfood + + family[loseindex].fmpk; + +#ifdef _PERSONAL_FAME // Arminius: + { + int j; + family[loseindex].fmtotalfame=family[loseindex].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[loseindex].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[loseindex].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + family[loseindex].fmtotalfame += family[loseindex].fmmemberindex[j].popular; + } + } +#endif + + if (family[loseindex].fmmemberindex[0].onlineflag > 0) + { + int floor = ACgetFMFloor(losefmindex); +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[loseindex].fmmemberindex[0].onlineflag, + SUCCESSFUL, loseindex, floor, family[loseindex].fmtotalfame, + #ifdef _FMVER21 + family[loseindex].fmmemberindex[0].charflag, family[loseindex].fmsetupflag, 1, 0, + #else + 1, family[loseindex].fmsetupflag, 1, 0, + #endif + family[loseindex].fmmemberindex[0].popular, // Arminius 9.11 + family[loseindex].fmmemberindex[0].charfdid + #ifdef _NEW_MANOR_LAW + ,family[loseindex].fmmemberindex[0].momentum + #endif + ); +#else + saacproto_ACFMCharLogin_send( + family[loseindex].fmmemberindex[0].onlineflag, + SUCCESSFUL, loseindex, floor, family[loseindex].fmpopular, + #ifdef _FMVER21 + family[loseindex].fmmemberindex[0].charflag, family[loseindex].fmsetupflag, 1, 0, + #else + 1, family[loseindex].fmsetupflag, 1, 0, + #endif + family[loseindex].fmmemberindex[0].charfdid); +#endif + } + } + sortFamily(); + if (family[winindex].fmpointindex >= 0) + { +#ifdef _PERSONAL_FAME // Arminius: + fmpoint[family[winindex].fmpointindex].hadfmpopular = family[winindex].fmtotalfame; +#else + fmpoint[family[winindex].fmpointindex].hadfmpopular = family[winindex].fmpopular; +#endif + db_fmpointupdate = 1; + } + if (family[loseindex].fmpointindex >= 0) + { +#ifdef _PERSONAL_FAME // Arminius: + fmpoint[family[loseindex].fmpointindex].hadfmpopular = family[loseindex].fmtotalfame; +#else + fmpoint[family[loseindex].fmpointindex].hadfmpopular = family[loseindex].fmpopular; +#endif + db_fmpointupdate = 1; + } + return award; +} + +// ɢ +int ACDelFM(int index, char *fmname, int fmindex) +{ + int i; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + log("\nACDelFM index:%d fmname:%s fmindex:%d\n", index, fmname, fmindex); + + if (family[index].fmpointindex >= 0) + { + delfmpointindex(family[index].fmindex); + family[index].fmpointindex = -1; + } + if (family[index].memonum > 0) + { + for (i = 0; i < family[index].memonum; i++) + memset(family[index].memolist[i], 0, + sizeof(family[index].memolist[i])); + } + family[index].fmindex = -1; + memset(family[index].fmname, 0, sizeof(family[index].fmname)); + memset(family[index].memolist, 0, sizeof(family[index].memolist)); + family[index].fmnum = 0; + family[index].fmjoinnum = 0; + family[index].fmsetupflag = -1; + family[index].fmpopular = 0; + family[index].fmadv = 0; + family[index].fmfeed= 0; + family[index].fmsynthesize = 0; + family[index].fmdealfood = 0; + family[index].fmpk = 0; +#ifdef _PERSONAL_FAME // Arminius: + family[index].fmtotalfame = 0; +#endif +#ifdef _NEW_MANOR_LAW + family[index].fmmomentum = 0; +#endif + for (i = 0; i < family[index].fmmemberindexmaxnum; i++) + { + // ״̬Ա +#ifdef _PERSONAL_FAME // Arminius: + if (family[index].fmmemberindex[i].onlineflag > 0) + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + FAILED, index, family[index].fmpointindex, + family[index].fmtotalfame, -1, family[index].fmsetupflag, 0, + i, family[index].fmmemberindex[i].popular, // Arminius 9.11 + family[index].fmmemberindex[i].charfdid + #ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[i].momentum + #endif + ); +#else + if (family[index].fmmemberindex[i].onlineflag > 0) + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + FAILED, index, family[index].fmpointindex, + family[index].fmpopular, -1, family[index].fmsetupflag, 0, + i, family[index].fmmemberindex[i].charfdid); +#endif + memset(family[index].fmmemberindex[i].charname, 0, + sizeof(family[index].fmmemberindex[i].charname)); + memset(family[index].fmmemberindex[i].charid, 0, + sizeof(family[index].fmmemberindex[i].charid)); + family[index].fmmemberindex[i].charflag = FMMEMBER_NONE; + family[index].fmmemberindex[i].predeltime = -1; + family[index].fmmemberindex[i].popular = 0; +#ifdef _NEW_MANOR_LAW + family[index].fmmemberindex[i].momentum = 0; +#endif + } + family[index].fmmemberindexmaxnum = 0; + fmnownum--; + if (fmindexmaxnum == index) fmindexmaxnum--; + + // ͼɾ֮ѶϢ GMSV սų + for (i = 0; i < MAXCONNECTION; i++) + { + if (gs[i].use && gs[i].name[0]) + saacproto_ACFMClearPK_send(i, SUCCESSFUL, fmname, fmindex, index); + } + + DelFMMaintainSort(index); + + db_familyupdate[i] = 1; + + return 0; +} +#ifdef _FAMILY_TOTEM +// ʾͼ +int ACShowFMTotem(int fd) +{ + int i = 0; + for (i = 0; i <= fmindexmaxnum; i++) + { + if ((strcmp(family[i].fmname, "") != 0) && (family[i].fmindex != -1)) + { + saacproto_ACShowFMTotem_send(fd, SUCCESSFUL, i, family[i].familytotem); + } + } +} +#endif + +// ʾб +int ACShowFMList(char *data) +{ + int i = 0; + strcpy(data, ""); + + for (i = 0; i <= fmindexmaxnum; i++) + { + char msg[256]; + if ((strcmp(family[i].fmname, "") != 0) && (family[i].fmindex != -1)) + { +#ifdef _PERSONAL_FAME // Arminius: + sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname, + family[i].fmleadername, family[i].fmtotalfame, family[i].fmjoinnum, i, + family[i].fmsetupflag, family[i].fmacceptflag); +#else + sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname, + family[i].fmleadername, family[i].fmpopular, family[i].fmjoinnum, i, + family[i].fmsetupflag, family[i].fmacceptflag); +#endif + strcat(data, msg); + } + } + return fmnownum; +} + +// ʾԱб +int ACShowFMMemberList(int index, int *fmacceptflag, int *fmjoinnum, char *data +#ifdef _FAMILYBADGE_ + ,int *badge +#endif + ) +{ + int i = 0; + if ((index > MAX_FAMILY) || (index < 0)) return -1; + if (CheckFMUse(index) == 0) return -1; + + strcpy(data, ""); + *fmjoinnum = family[index].fmjoinnum; + for (i = 0; i < family[index].fmmemberindexmaxnum; i++) + { + char msg[256]; + if ((strcmp(family[index].fmmemberindex[i].charname, "") != 0) + && (strcmp(family[index].fmmemberindex[i].charid, "") != 0) + && (family[index].fmmemberindex[i].charflag != FMMEMBER_NONE)) + { +#ifdef _FM_MODIFY + #ifdef _NEW_MANOR_LAW + sprintf(msg, "%d|%s|%d|%d|%d|%d|%d|%d|%d ", i, + #else + sprintf(msg, "%d|%s|%d|%d|%d|%d|%d|%d ", i, + #endif + family[index].fmmemberindex[i].charname, + family[index].fmmemberindex[i].charlv, + family[index].fmmemberindex[i].onlineflag, + (family[index].fmmemberindex[i].popular / 100), + family[index].fmmemberindex[i].eventflag, + family[index].fmmemberindex[i].charflag, + family[index].fmmemberindex[i].gsnum + #ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[i].momentum/100 + #endif + ); + strcat(data, msg); +#else + #ifdef _FMVER21 + sprintf(msg, "%d|%s|%d|%d|%d|%d|%d ", i, + family[index].fmmemberindex[i].charname, + family[index].fmmemberindex[i].charlv, + family[index].fmmemberindex[i].onlineflag, + (family[index].fmmemberindex[i].popular / 100), + family[index].fmmemberindex[i].eventflag, + family[index].fmmemberindex[i].charflag); + strcat(data, msg); + #else + sprintf(msg, "%d|%s|%d|%d|%d|%d ", i, + family[index].fmmemberindex[i].charname, + family[index].fmmemberindex[i].charlv, + family[index].fmmemberindex[i].onlineflag, + (family[index].fmmemberindex[i].popular / 100), + family[index].fmmemberindex[i].charflag); + strcat(data, msg); + #endif +#endif + } + } // for + *fmacceptflag = family[index].fmacceptflag; + *badge = family[index].fmbadge; + return family[index].fmnum; +} + +// ʾϸ +int ACFMDetail(int index, char *fmname, int fmindex, char *data) +{ + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + strcpy(data, ""); + sprintf(data, "%d|%d|%s|%s|%d|%s|%s|%d|%d|%s|%d" +#ifdef _FAMILYBADGE_ + "|%d" +#endif + ,index, family[index].fmindex, + family[index].fmname, family[index].fmleadername, + family[index].fmleadergrano, family[index].petname, family[index].petattr, + family[index].fmjoinnum, family[index].fmacceptflag, + family[index].fmrule, family[index].fmsprite +#ifdef _FAMILYBADGE_ + ,family[index].fmbadge +#endif + ); + return 0; +} + +// 峤˳Ա +#ifdef _FMVER21 +int ACMemberJoinFM(int index, char *fmname, int fmindex, + char *charname, int charindex, int result, int meindex) +#else +int ACMemberJoinFM(int index, char *fmname, int fmindex, + char *charname, int charindex, int result) +#endif +{ + time_t t1; + int floor; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + floor = ACgetFMFloor(fmindex); + +#ifdef _FIX_LEADER_ERR // WON ADD 峤 + if (charindex == 0 ) return -1; +#endif + +#ifdef _FMVER21 + if (result < 0) return -1; + if (meindex < 0 || meindex > MAX_MEMBERNUM) return -1; +#endif + if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0){ + if (family[index].fmjoinnum >= MAX_MEMBERNUM) return -1; + time(&t1); + family[index].fmmemberindex[charindex].predeltime = t1 + PREDELMEMBER_TIME; + if (family[index].fmmemberindex[charindex].charflag == FMMEMBER_APPLY) family[index].fmjoinnum++; + if (family[index].fmmemberindexmaxnum <= charindex) family[index].fmmemberindexmaxnum = charindex + 1; + if (family[index].fmjoinnum >= MIN_MEMBERNUM) + { + if (family[index].fmjoinnum == MIN_MEMBERNUM) family[index].setup_time = t1; + family[index].fmsetupflag = 1; + family[index].predel_time = -1; + } + if (family[index].fmjoinnum >= MAX_MEMBERNUM) family[index].fmacceptflag = 0; +#ifdef _PERSONAL_FAME // Arminius: + { + int j; + family[index].fmtotalfame=family[index].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + family[index].fmtotalfame += family[index].fmmemberindex[j].popular; + } + } +#endif +#ifdef _FMVER21 + if (result != FMMEMBER_MEMBER) + { + if (result == FMMEMBER_ELDER && family[index].fmmemberindex[charindex].eventflag != 1) + return -1; + if (ACFMAssignOcp(index, fmname, fmindex, charname, charindex, result) >= 0) + return 0; + else return -1; + } +#endif + if (family[index].fmmemberindex[charindex].onlineflag > 0){ + char buf[256]; + // ֪ͨ +#ifdef _FMVER21 + if (family[index].fmmemberindex[charindex].charflag != FMMEMBER_APPLY) + sprintf(buf, "%s峤ѾļְȸΪ%s", + family[index].fmname, MEMBERKIND_INTDATA[result]); + else + sprintf(buf, "ϲ㣡%sѾļ룡", + family[index].fmmemberindex[meindex].charname); +#else + sprintf(buf, "ϲ㣡%s峤Ѿļ룡", family[index].fmname); +#endif + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, buf, + family[index].fmmemberindex[charindex].charfdid); +#ifdef _FMVER21 + family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER; + // + family[index].fmpopular = family[index].fmadv + family[index].fmfeed + + family[index].fmsynthesize + family[index].fmdealfood + + family[index].fmpk; + { + int j; + family[index].fmtotalfame = family[index].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) + { + if ((family[index].fmmemberindex[j].charflag != FMMEMBER_NONE) && + (family[index].fmmemberindex[j].charflag != FMMEMBER_APPLY) ) + family[index].fmtotalfame += family[index].fmmemberindex[j].popular; + } + } +#else + family[index].fmmemberindex[charindex].charflag = 1; +#endif +#ifdef _NEW_MANOR_LAW + { + int i; + + family[index].fmmomentum = 0; + for(i=0;i2000000000)family[index].fmmomentum=2000000000; + } +#endif +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + #ifdef _FMVER21 + family[index].fmmemberindex[charindex].charflag, family[index].fmsetupflag, 1, charindex, + #else + 2, family[index].fmsetupflag, 1, charindex, + #endif + family[index].fmmemberindex[charindex].popular, // Arminius 9.11 + family[index].fmmemberindex[charindex].charfdid + #ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum + #endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + #ifdef _FMVER21 + family[index].fmmemberindex[charindex].charflag, family[index].fmsetupflag, 1, charindex, + #else + 2, family[index].fmsetupflag, 1, charindex, + #endif + family[index].fmmemberindex[charindex].charfdid); +#endif + } + // 峤״̬ + if (family[index].fmmemberindex[charindex].onlineflag > 0) + { +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + #ifdef _FMVER21 + family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0, + #else + 1, family[index].fmsetupflag, 1, 0, + #endif + family[index].fmmemberindex[0].popular, // Arminius 9.11 + family[index].fmmemberindex[0].charfdid + #ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[0].momentum + #endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + #ifdef _FMVER21 + family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0, + #else + 1, family[index].fmsetupflag, 1, 0, + #endif + family[index].fmmemberindex[0].charfdid); +#endif + } +#ifdef _FMVER21 + family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER; +#else + family[index].fmmemberindex[charindex].charflag = 1; +#endif + } + db_familyupdate[index] = 1; + return 0; + return -1; +} + +// 峤˳Ա뿪 +#ifdef _FMVER21 +int ACMemberLeaveFM(int index, char *fmname, int fmindex, + char *charname, int flag, int charindex, int meindex) +#else +int ACMemberLeaveFM(int index, char *fmname, int fmindex, + char *charname, int flag, int charindex) +#endif +{ + time_t t1; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; +#ifdef _FMVER21 + if (meindex < 0 || meindex > MAX_MEMBERNUM) return -1; +#endif + +#ifdef _FIX_LEADER_ERR // WON ADD 峤 + if (charindex == 0 ) return -1; +#endif + + if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0) + { + if (family[index].fmmemberindex[charindex].charflag <= 0) return -1; + if (family[index].fmmemberindex[charindex].onlineflag > 0) + { + char buf[256]; +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + FAILED, index, family[index].fmpointindex, + 0, -1, family[index].fmsetupflag, 1, + charindex, + family[index].fmmemberindex[charindex].popular, // Arminius 9.11 + family[index].fmmemberindex[charindex].charfdid + #ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum + #endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + FAILED, index, family[index].fmpointindex, + family[index].fmpopular, -1, family[index].fmsetupflag, 1, + charindex, family[index].fmmemberindex[charindex].charfdid); +#endif + // ֪ͨ + if (flag == 1) + { +#ifdef _FMVER21 + sprintf(buf, "%sѾ߳ˣ", family[index].fmmemberindex[meindex].charname); +#else + sprintf(buf, "%s峤Ѿ߳ˣ", family[index].fmname); +#endif + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, buf, + family[index].fmmemberindex[charindex].charfdid); + } + } + memset(family[index].fmmemberindex[charindex].charname, 0, + sizeof(family[index].fmmemberindex[charindex].charname)); + memset(family[index].fmmemberindex[charindex].charid, 0, + sizeof(family[index].fmmemberindex[charindex].charid)); + family[index].fmmemberindex[charindex].onlineflag = -1; + family[index].fmmemberindex[charindex].popular = 0; +#ifdef _FMVER21 + family[index].fmmemberindex[charindex].eventflag = 0; + if (family[index].fmmemberindex[charindex].charflag != FMMEMBER_APPLY) +#else + if(family[index].fmmemberindex[charindex].charflag != 2) +#endif + family[index].fmjoinnum = family[index].fmjoinnum - 1; + family[index].fmnum = family[index].fmnum - 1; + family[index].fmmemberindex[charindex].charflag = FMMEMBER_NONE; +#ifdef _PERSONAL_FAME // Arminius: + { + int j; + family[index].fmtotalfame=family[index].fmpopular; + for (j = 0; j < MAX_MEMBERNUM; j++) { + if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) && + (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) ) + family[index].fmtotalfame += family[index].fmmemberindex[j].popular; + } + } +#endif + if (family[index].fmnum < 1 || family[index].fmjoinnum < 1) + { + int i = 0, fmnum1 = 0, fmnum2 = 0; + for (i = 0; i < MAX_MEMBERNUM; i++) + { + if (family[index].fmmemberindex[i].charflag <= 0) continue; +#ifdef _FMVER21 + if (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY) +#else + if (family[index].fmmemberindex[i].charflag == 1) +#endif + fmnum1 = fmnum1 + 1; + if (family[index].fmmemberindex[i].charflag > 0) + fmnum2 = fmnum2 + 1; + } + log("MemberLeave_fmnum err!\n index:%d fmname:%s" + " orifmnum:%d orifmjoinnum:%d\n fmnum1:%d fmnum2:%d\n", + index, fmname, family[index].fmnum, + family[index].fmjoinnum, fmnum1, fmnum2); + family[index].fmjoinnum = fmnum1; + family[index].fmnum = fmnum2; + } +#ifdef _NEW_MANOR_LAW + // Ա趨Ϊ0 + family[index].fmmemberindex[charindex].momentum = 0; + { + int i; + + family[index].fmmomentum = 0; + for(i=0;i2000000000)family[index].fmmomentum=2000000000; + } +#endif + if (family[index].fmmemberindexmaxnum == charindex) family[index].fmmemberindexmaxnum--; + if (family[index].fmjoinnum < MIN_MEMBERNUM){ + time(&t1); + if( family[index].fmsetupflag != 0 ){ + family[index].fmsetupflag = 0; + family[index].predel_time = t1 + PREDEL_TIME; + } + if (family[index].fmmemberindex[charindex].onlineflag > 0 ){ + char token[256]; + sprintf( token, "֮ҪϿټԱᱻɢรʣ%d졣", + (int)((family[index].predel_time - t1)/(60*60*24)) ); + saacproto_ACFMAnnounce_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, + token, family[index].fmmemberindex[0].charfdid ); + } + } + db_familyupdate[index] = 1; + return 0; + } + return -1; +} + +// 峤ְ +int ACFMAssignOcp(int index, char *fmname, int fmindex, + char *charname, int charindex, int result) +{ +#ifdef _FMVER21 + int floor, count = 0, i = 0; + char buf[256]; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + floor = ACgetFMFloor(fmindex); + if (result < 0) return -1; + +#ifdef _FIX_LEADER_ERR // WON ADD 峤 + if (charindex == 0 ) return -1; +#endif + + log("AsssignOcp index:%d fmindex:%d fmname:%s charname:%s charindex:%d result:%d\n", + index, fmindex, fmname, charname, charindex, result); + for (i = 0; i < MAX_MEMBERNUM; i++) + { + if (family[index].fmmemberindex[i].charflag == result + && result != FMMEMBER_MEMBER) + count++; + } + if (count >= FMELDERNUM) + { + sprintf(buf, "\nָֻ%dλԱΪ%sร", + FMELDERNUM, MEMBERKIND_INTDATA[result]); + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 4, buf, + family[index].fmmemberindex[0].charfdid); + return -1; + } + if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0) + { + family[index].fmmemberindex[charindex].charflag = result; + if (family[index].fmmemberindex[charindex].onlineflag > 0) + { +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, charindex, + family[index].fmmemberindex[charindex].popular, // Arminius 9.11 + family[index].fmmemberindex[charindex].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, charindex, + family[index].fmmemberindex[charindex].charfdid); +#endif + // ֪ͨ + sprintf(buf, "%s峤ѾļְȸΪ%s", family[index].fmname, + MEMBERKIND_INTDATA[result]); + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 3, buf, + family[index].fmmemberindex[charindex].charfdid); + } + if (family[index].fmmemberindex[0].onlineflag > 0) + { + // ֪ͨ峤 + sprintf(buf, "\nѾ%sְȸΪ%sˣ", charname, + MEMBERKIND_INTDATA[result]); + saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 4, buf, + family[index].fmmemberindex[0].charfdid); + } + db_familyupdate[index] = 1; + return 0; + } + log("AssignOcp Failed\n"); +#endif + return -1; +} + +// Ա login +#ifdef _FM_MODIFY +int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid, + int *charfame, int eventflag,int gsnum + #ifdef _NEW_MANOR_LAW + ,int *momentum + #endif + ) +#else + #ifdef _PERSONAL_FAME // Arminius: + int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid, + int *charfame, int eventflag) + #else + int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid) + #endif +#endif +{ + int i = 0; + time_t t1; + + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + if (family[index].fmpointindex != -1) + *floor = ACgetFMFloor(fmindex); +#ifdef _PERSONAL_FAME // Arminius: + *fmpopular = family[index].fmtotalfame; +#else + *fmpopular = family[index].fmpopular; +#endif + *fmsetupflag = family[index].fmsetupflag; + + for (i = 0; i < family[index].fmmemberindexmaxnum; i++){ + if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0) + && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0)){ + *charindex = i; + family[index].fmmemberindex[i].onlineflag = fd; + family[index].fmmemberindex[i].charfdid = charfdid; + family[index].fmmemberindex[i].charlv = charlv; +#ifdef _FM_MODIFY + family[index].fmmemberindex[i].gsnum = gsnum; +#endif +#ifdef _PERSONAL_FAME // Arminius: + *charfame = family[index].fmmemberindex[i].popular; +#endif +#ifdef _NEW_MANOR_LAW + *momentum = family[index].fmmemberindex[i].momentum; +#endif + time(&t1); + family[index].fmmemberindex[i].predeltime = t1 + PREDELMEMBER_TIME; +#ifdef _FMVER21 + *joinflag = family[index].fmmemberindex[i].charflag; + family[index].fmmemberindex[i].eventflag = eventflag; +#else + if (i == 0) *joinflag = 1; + else if ((family[index].fmmemberindex[i].charflag == 1) + || (family[index].fmmemberindex[i].charflag == 3)) + *joinflag = 2; + else *joinflag = 0; +#endif + db_familyupdate[index] = 1; + + return index; + } + } + return -1; +} + +// Ա +int ACFMCharLogout(int index, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int charfdid) +{ + int i = 0; + time_t t1; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + for (i = 0; i < family[index].fmmemberindexmaxnum; i++) + { + if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0) + && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0)) + { + family[index].fmmemberindex[i].onlineflag = 0; + family[index].fmmemberindex[i].charfdid = 0; + family[index].fmmemberindex[i].charlv = charlv; +#ifdef _FM_MODIFY + family[index].fmmemberindex[i].gsnum = 0; +#endif + time(&t1); + family[index].fmmemberindex[i].predeltime = t1 + PREDELMEMBER_TIME; + db_familyupdate[index] = 1; + return 0; + } + } + return -1; +} + +// ȡüׯ԰ͼ +int ACgetFMFloor(fmindex) +{ + int i = 0; + for (i = 0; i < MAX_FMPOINT; i++) + { + if (fmindex == fmpoint[i].hadfmindex) + return fmpoint[i].fmfl; + } + return -1; +} + +// ֶɾɫ +int ACgetFMInfoFromChar(char *fmname, int *fmindex, + char *charname, char *charid, int *charindex) +{ + int i = 0, j = 0; + for (i = 0; i < MAX_FAMILY; i++) + { + if (family[i].fmindex <= 0) continue; + for (j = 0; j < MAX_MEMBERNUM; j++) + { + if (family[i].fmmemberindex[j].charflag <= 0) continue; + if ((strcmp(family[i].fmmemberindex[j].charname, charname) == 0) + && (strcmp(family[i].fmmemberindex[j].charid, charid) == 0)) + { + strcpy(fmname, ""); + strcpy(fmname, family[i].fmname); + *fmindex = family[i].fmindex; + *charindex = j; + db_familyupdate[i] = 1; + return i; + } + } // for + } // for + return -1; +} + +// Ķ +int ACFMReadMemo(int index, int *dataindex, char *data) +{ + int i = 0; + char buf[256]; + strcpy(data, ""); + if (index == -1){ + return -1; + } else if (index == FMSMEMOINDEX){ + *dataindex = fmsmemo.fmsnowwritenum; + for (i = 0; i < fmsmemo.num; i++){ + sprintf(buf, "%s|", fmsmemo.memodata[i]); + strcat(data, buf); + } + return fmsmemo.num; + } + if ((index >= MAX_FAMILY) || (index < 0)) + return -1; + if (CheckFMUse(index) == 0) + return -1; + *dataindex = family[index].memonowwritenum; + for (i = 0; i < family[index].memonum; i++){ + strcpy(buf, ""); + sprintf(buf, "%s|", family[index].memolist[i]); + strcat(data, buf); + } + db_familyupdate[index] = 1; + return family[index].memonum; +} + +// д԰ +int ACFMWriteMemo(int index, char *fmname, int fmindex, char *data) +{ + if (index == -1){ + return -1; + }else if (index == FMSMEMOINDEX){ + fmsmemo.num++; + if (fmsmemo.num > FMSMEMONUM) fmsmemo.num = FMSMEMONUM; + strcpy(fmsmemo.memodata[fmsmemo.fmsnowwritenum], data); + fmsmemo.fmsnowwritenum++; + if (fmsmemo.fmsnowwritenum >= FMSMEMONUM) fmsmemo.fmsnowwritenum = 0; + db_fmsmemoupdate = 1; + return 0; + } + if ((index > MAX_FAMILY) || (index < 0)) + return -1; + if (CheckFMUse(index) == 0) + return -1; + if ((family[index].fmindex != fmindex) || (strcmp(family[index].fmname, fmname) != 0)) { + return -1; + } + if (strlen(data) > FAMILY_MEMOLEN) return -1; + family[index].memonum++; + if (family[index].memonum > FAMILY_MEMONUM) family[index].memonum = FAMILY_MEMONUM; + strcpy(family[index].memolist[family[index].memonowwritenum], data); + family[index].memonowwritenum++; + if (family[index].memonowwritenum >= FAMILY_MEMONUM) family[index].memonowwritenum = 0; + db_familyupdate[index] = 1; + return 0; +} + +// ȡׯ԰б +int ACFMPointList(char *data) +{ + int i = 0; + char msg[256]; + strcpy(data, ""); + for (i = 0; i < MAX_FMPOINT; i++) + { +#ifdef _FIX_FMPOINTTIME + sprintf(msg, "%d|%d|%d|%d|%d|%s|%d|%d|%d|%d ", +#else + sprintf(msg, "%d|%d|%d|%d|%d|%s|%d|%d|%d ", +#endif + i, fmpoint[i].fl, fmpoint[i].x, fmpoint[i].y, + fmpoint[i].hadfmindex, fmpoint[i].hadfmname, + fmpoint[i].hadfmpopular, fmpoint[i].hadfmindex - 1, + fmpoint[i].village +#ifdef _FIX_FMPOINTTIME + ,fmpoint[i].fmpointtime +#endif + ); + strcat(data, msg); + } + return 0; +} + +// ׯ԰ +int ACSetFMPoint(int index, char *fmname, int fmindex, int fmpointindex, + int fl, int x, int y) +{ + int i = 0; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; +#ifdef _SET_FMPOINT +{ + for (i = 0; i < MAX_FMPOINT; i++) + { + if (fmpoint[i].hadfmindex == index + 1) + { + return -2; + } + } +} +#else + if (family[index].fmpointindex >= 0) return -2; +#endif + if ((fmpoint[fmpointindex].x != x) || (fmpoint[fmpointindex].y != y))return -1; + if (fmpoint[fmpointindex].hadfmindex > 0)return -4; + if (family[index].fmjoinnum < MINAPPLYPNUM)return -5; +#ifdef _SET_FMPOINT + if (family[index].fmpointtime > (int) time(NULL)) return -6; +#endif + fmpoint[fmpointindex].hadfmindex = fmindex; + family[index].fmpointindex = fmpointindex; + strcpy(fmpoint[fmpointindex].hadfmname, fmname); +#ifdef _PERSONAL_FAME // Arminius: + fmpoint[fmpointindex].hadfmpopular = family[index].fmtotalfame; +#else + fmpoint[fmpointindex].hadfmpopular = family[index].fmpopular; +#endif +#ifdef _FIX_FMPOINTTIME + time_t t1; + time(&t1); + fmpoint[fmpointindex].fmpointtime=t1; +#endif + // ϼԱ״ + for (i = 0; i < MAX_MEMBERNUM; i++){ + if (strcmp(family[index].fmmemberindex[i].charname, "") == 0) continue; + if (family[index].fmmemberindex[i].onlineflag > 0){ + int floor = ACgetFMFloor(fmindex); +#ifdef _FMVER21 +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + SUCCESSFUL, index, floor, family[index].fmtotalfame, + family[index].fmmemberindex[i].charflag, family[index].fmsetupflag, 1, i, + family[index].fmmemberindex[i].popular, // Arminuis 9.11 + family[index].fmmemberindex[i].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[i].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[i].charflag, family[index].fmsetupflag, 1, i, + family[index].fmmemberindex[i].charfdid); +#endif +#else + { + int joinflag = 0; + if (i == 0) joinflag = 1; + else joinflag = 2; + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[i].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + joinflag, family[index].fmsetupflag, 1, i, + family[index].fmmemberindex[i].charfdid); + } +#endif + } + } + // ׯ԰״ + { + char data[15000]; + if (ACFMPointList(data) >= 0){ + for (i = 0; i < MAXCONNECTION; i++) + if (gs[i].use && gs[i].name[0]) + saacproto_ACFMPointList_send(i, SUCCESSFUL, data); + } + } + + db_fmpointupdate = 1; + return 0; +} + +// 趨ׯ԰ +int ACFixFMPoint(int winindex, char *winfmname, int winfmindex, int loseindex, + char* losefmname, int losefmindex, int village) +{ + int i = 0; + //printf("\n޸ׯ԰Ϣ %d|%s|%d|%d|%s|%d|%d",winindex, winfmname, winfmindex, loseindex, + // losefmname, losefmindex, village); +#ifdef _SET_FMPOINT + if(winindex == -1 || winfmindex == -1 || loseindex == -1 || losefmindex == -1) + { + + + family[fmpoint[village -1].hadfmindex - 1].fmpointindex = -1; + time_t t1; + time(&t1); + // printf("\nׯ԰ռʱΪ%d",t1); + family[fmpoint[village -1].hadfmindex - 1].fmpointtime = t1 + 60 * 30; + + fmpoint[village -1].hadfmindex = -1; + strcpy(fmpoint[village -1].hadfmname, "-1"); + fmpoint[village -1].hadfmpopular = -1; + + // ׯ԰״ + { + char data[15000]; + if (ACFMPointList(data) >= 0){ + for (i = 0; i < MAXCONNECTION; i++) + if (gs[i].use && gs[i].name[0]) + saacproto_ACFMPointList_send(i, SUCCESSFUL, data); + } + } + db_fmpointupdate = 1; + return 0; + } +#endif + + if (CheckFM(&winindex, winfmname, winfmindex) < 0) return -1; + if (CheckFM(&loseindex, losefmname, losefmindex) < 0) return -1; + +#ifdef _NEW_MANOR_LAW + // ԭסׯ԰ + if(fmpoint[village -1].hadfmindex == winfmindex){ + unsigned int iTotalGetGold = 0,iOldGold = 0,iTotalMamberMomentum = 0; + // ýǮ = ( * 10000) - (Աܺ * 5000) + for(i=0;i FMMAXGOLD) family[winindex].fmgold = FMMAXGOLD; + log("ACFMGetMoney fmindex:%d fmname:%s fmoldgold:%d getmoney:%d fmnewgold:%d\n", + family[winindex].fmindex,family[winindex].fmname,iOldGold,iTotalGetGold,family[winindex].fmgold); + } +#endif +#ifdef _FIX_FMPOINTTIME + if(fmpoint[village -1].hadfmindex != winfmindex){ + time_t t1; + time(&t1); + // printf("\nׯ԰ռʱΪ%d",t1); + fmpoint[village -1].fmpointtime = t1; + } + //GMָׯ԰ + if (winindex==loseindex){ + // time_t t1; + // time(&t1); + // printf("\nׯ԰ռʱΪ%d",t1); + // fmpoint[village -1].fmpointtime = t1; + } +#endif + delfmpointindex(losefmindex); + family[loseindex].fmpointindex = -1; + fmpoint[village -1].hadfmindex = winfmindex; + family[winindex].fmpointindex = village - 1; + strcpy(fmpoint[village - 1].hadfmname, winfmname); +#ifdef _PERSONAL_FAME // Arminius: + fmpoint[village -1].hadfmpopular = family[winindex].fmtotalfame; +#else + fmpoint[village -1].hadfmpopular = family[winindex].fmpopular; +#endif +#ifdef _NEW_MANOR_LAW + // ׯ԰ս,ȫ + family[winindex].fmmomentum = 0; + family[loseindex].fmmomentum = 0; +#endif + + // Ա + for (i = 0; i < MAX_MEMBERNUM; i++){ + if (strcmp(family[winindex].fmmemberindex[i].charname, "") == 0) continue; +#ifdef _NEW_MANOR_LAW + // ׯ԰ս,ȫ + family[winindex].fmmemberindex[i].momentum = 0; +#endif + if (family[winindex].fmmemberindex[i].onlineflag > 0){ + int floor = ACgetFMFloor(winfmindex); +#ifdef _FMVER21 + #ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[winindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, winindex, floor, family[winindex].fmtotalfame, + family[winindex].fmmemberindex[i].charflag, family[winindex].fmsetupflag, 1, i, + family[winindex].fmmemberindex[i].popular, // Arminius 9.11 + family[winindex].fmmemberindex[i].charfdid + #ifdef _NEW_MANOR_LAW + ,family[winindex].fmmemberindex[i].momentum + #endif + ); + #else + saacproto_ACFMCharLogin_send( + family[winindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, winindex, floor, family[winindex].fmpopular, + family[winindex].fmmemberindex[i].charflag, family[winindex].fmsetupflag, 1, i, + family[winindex].fmmemberindex[i].charfdid); + #endif +#else + { + int joinflag = 0; + if (i == 0) joinflag = 1; + else joinflag = 2; + saacproto_ACFMCharLogin_send( + family[winindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, winindex, floor, family[winindex].fmpopular, + joinflag, family[winindex].fmsetupflag, 1, i, + family[winindex].fmmemberindex[i].charfdid); + } +#endif + } + } +#ifdef _NEW_MANOR_LAW + if(loseindex >= 0){ +#endif + for (i = 0; i < MAX_MEMBERNUM; i++){ + if (strcmp(family[loseindex].fmmemberindex[i].charname, "") == 0) continue; +#ifdef _NEW_MANOR_LAW + // ׯ԰ս,ȫ + family[loseindex].fmmemberindex[i].momentum = 0; +#endif + if (family[loseindex].fmmemberindex[i].onlineflag > 0){ +#ifdef _FMVER21 + #ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[loseindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, loseindex, -1, family[loseindex].fmtotalfame, + family[loseindex].fmmemberindex[i].charflag, family[loseindex].fmsetupflag, 1, i, + family[loseindex].fmmemberindex[i].popular, // Arminius 9.11 + family[loseindex].fmmemberindex[i].charfdid + #ifdef _NEW_MANOR_LAW + ,family[loseindex].fmmemberindex[i].momentum + #endif + ); + #else + saacproto_ACFMCharLogin_send( + family[loseindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, loseindex, -1, family[loseindex].fmpopular, + family[loseindex].fmmemberindex[i].charflag, family[loseindex].fmsetupflag, 1, i, + family[loseindex].fmmemberindex[i].charfdid); + #endif +#else + { + int joinflag = 0; + if (i == 0) joinflag = 1; + else joinflag = 2; + saacproto_ACFMCharLogin_send( + family[loseindex].fmmemberindex[i].onlineflag, + SUCCESSFUL, loseindex, -1, family[loseindex].fmpopular, + joinflag, family[loseindex].fmsetupflag, 1, i, + family[loseindex].fmmemberindex[i].charfdid); + } +#endif + } + } +#ifdef _NEW_MANOR_LAW + } +#endif + // ׯ԰״ + { + char data[15000]; + if (ACFMPointList(data) >= 0){ + for (i = 0; i < MAXCONNECTION; i++) + if (gs[i].use && gs[i].name[0]) + saacproto_ACFMPointList_send(i, SUCCESSFUL, data); + } + } + db_fmpointupdate = 1; + return 0; +} + +// 峤㲥 +int ACFMAnnounce(char *fmname, int fmindex, int index, char *data, int color) +{ + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + return 0; +} + +// ȡü +// kindflag 1: +int ACGetFMData(int index, char *fmname, int fmindex, int kindflag, int *data) +{ + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + + if (kindflag == 1) + *data = family[index].fmgold; + return 0; +} + +void setMemberFileDataToArg(int index, int memberindex, char *data) +{ + int i = 0; + char value[256]; + char *ptr; + if (index < 0 || index > MAX_FAMILY) return; + if (strcmp(data, "") == 0) return; + ptr = (char *)strstr(data, "="); + if (ptr == NULL) return; + strcpy(ptr, ""); + strcpy(value, ptr + 1); + for (i = 0; i < memberdatamaxint; i++){ + if (strcmp(data, MEMBER_INTDATA[i]) == 0){ + switch(i){ + case 0: + family[index].fmmemberindex[memberindex].charlv = atoi(value); + break; + case 1: + family[index].fmmemberindex[memberindex].charflag = atoi(value); + break; + case 2: + family[index].fmmemberindex[memberindex].onlineflag = atoi(value); + break; + case 3: + family[index].fmmemberindex[memberindex].charfdid = atoi(value); + break; + case 4: + family[index].fmmemberindex[memberindex].predeltime = atoi(value); + break; + case 5: + family[index].fmmemberindex[memberindex].popular = atoi(value); + break; +#ifdef _FMVER21 + case 6: + family[index].fmmemberindex[memberindex].eventflag = atoi(value); + break; +#endif +#ifdef _NEW_MANOR_LAW + case 7: + family[index].fmmemberindex[memberindex].momentum = atoi(value); + break; +#endif + default: + break; + } + return; + } + } + for (i = 0; i < memberdatamaxchar; i++){ + if (strcmp(data, MEMBER_CHARDATA[i]) == 0){ + switch(i){ + case 0: + strcpy(family[index].fmmemberindex[memberindex].charname, value); + break; + case 1: + strcpy(family[index].fmmemberindex[memberindex].charid, value); + break; + default: + break; + } + return; + } + } +} + +void setFamilyFileDataToArg(int index, char *data) +{ + int i = 0, j = 0; + char value[1024]; + char *ptr; + if (index < 0 || index > MAX_FAMILY) return; + if (strcmp(data, "") == 0) return; + ptr = (char *)strstr(data, "="); + if (ptr == NULL) return; + strcpy(ptr, ""); + strcpy(value, ptr + 1); + + for (i = 0; i < familymaxint; i++){ + if (strcmp(data, FAMILY_INTDATA[i]) == 0){ + switch(i){ + case 0: + family[index].fmindex = atoi(value); + break; + case 1: + family[index].fmleadergrano = atoi(value); + break; + case 2: + family[index].fmnum = atoi(value); + break; + case 3: + family[index].fmjoinnum = atoi(value); + break; + case 4: + family[index].fmacceptflag = atoi(value); + break; + case 5: + family[index].fmsetupflag = atoi(value); + break; + case 6: + family[index].fmsprite = atoi(value); + break; + case 7: + family[index].fmpointindex = atoi(value); + break; + case 8: + family[index].fmpopular = atoi(value); + break; + case 9: + family[index].fmgold = atoi(value); + break; + case 10: + family[index].fmmemberindexmaxnum = atoi(value); + break; + case 11: + family[index].apply_time = atoi(value); + break; + case 12: + family[index].setup_time = atoi(value); + break; + case 13: + family[index].predel_time = atoi(value); + break; + case 14: + family[index].memonowwritenum = atoi(value); + break; + case 15: + family[index].memonum = atoi(value); + break; + case 16: + family[index].fmadv = atoi(value); + break; + case 17: + family[index].fmfeed = atoi(value); + break; + case 18: + family[index].fmsynthesize = atoi(value); + break; + case 19: + family[index].fmdealfood = atoi(value); + break; + case 20: + family[index].fmpk = atoi(value); + break; +#ifdef _NEW_MANOR_LAW + case 21: + family[index].fmmomentum = atoi(value); + break; +#endif +#ifdef _FAMILY_PAY_POINT + case 22: + family[index].fmpaypoint = atoi(value); + break; +#endif +#ifdef _FAMILYBADGE_ + case 23: + family[index].fmbadge = atoi(value); + break; +#endif + default: + break; + } + return; + } + } + for (i = 0; i < familymaxchar; i++){ + if (strcmp(data, FAMILY_CHARDATA[i]) == 0){ + switch(i){ + case 0: + strcpy(family[index].fmname, value); + break; + case 1: + strcpy(family[index].fmleadername, value); + break; + case 2: + strcpy(family[index].fmleaderid, value); + break; + case 3: + strcpy(family[index].petname, value); + break; + case 4: + strcpy(family[index].petattr, value); + break; + case 5: + strcpy(family[index].fmrule, value); + break; +#ifdef _FAMILY_TOTEM + case 6: + strcpy(family[index].familytotem, value); + break; +#endif + default: + break; + } + return; + } + } + for (i = 0; i < FAMILY_MEMONUM; i ++){ + char memolist[256]; + sprintf(memolist, "%s%d", FMMEMOLIST, i); + if (strcmp(data, memolist) == 0){ + strcpy(family[index].memolist[i], value); + return; + } + } + for (i = 0; i < MAX_MEMBERNUM; i ++){ + char memberdata[256]; + sprintf(memberdata, "%s%d", FMMEMBERINDEX, i); + if (strcmp(data, memberdata) == 0){ + for (j = 1; j < memberdatamaxint + memberdatamaxchar; j++){ + char databuf[256]; + easyGetTokenFromBuf(value, " ", j, databuf, sizeof(databuf)); + if (strcmp(databuf, "") == 0) continue; + setMemberFileDataToArg(index, i, databuf); + } + return; + } + } + +} + +// GM޸ļ +int ACGMFixFMData(int index, char *fmname, char *charid, char *cmd, + char *data) +{ + int i = 0,charindex = -1; + int floor = ACgetFMFloor(index); + if (index < 0 || index > MAX_FAMILY) return -1; + log("GMFixFMData index:%d charid:%s cmd:%s data:%s\n", + index, charid, cmd, data); + strcpy(fmname, family[index].fmname); + if (charid[0] == '-' && charid[1] == '1') + { + for (i = 0; i < familymaxint; i++) + { + if (strcmp(cmd, FAMILY_INTDATA[i]) == 0) + { + switch(i) + { + case 2: + family[index].fmnum = atoi(data); + log("fmnum:%s\n", data); + break; + case 3: + family[index].fmjoinnum = atoi(data); + log("fmjoinnum:%s\n", data); + break; + case 4: + family[index].fmacceptflag = atoi(data); + log("fmacceptflag:%s\n", data); + break; + case 5: + family[index].fmsetupflag = atoi(data); + log("fmsetupflag:%s\n", data); + break; + case 6: + family[index].fmsprite = atoi(data); + log("fmsprite:%s\n", data); + break; + case 7: + family[index].fmpointindex = atoi(data); + log("fmpointindex:%s\n", data); + break; + case 8: + family[index].fmpopular = atoi(data); + log("fmpopular:%s\n", data); + break; + case 9: + family[index].fmgold = atoi(data); + log("fmgold:%s\n", data); + break; + case 11: + family[index].apply_time = atoi(data); + log("apply_time:%s\n", data); + break; + case 12: + family[index].setup_time = atoi(data); + log("setup_time:%s\n", data); + break; + case 13: + family[index].predel_time = atoi(data); + log("predel_time:%s\n", data); + break; + case 16: + family[index].fmadv = atoi(data); + log("adv:%s\n", data); + break; + case 17: + family[index].fmfeed = atoi(data); + log("feed:%s\n", data); + break; + case 18: + family[index].fmsynthesize = atoi(data); + log("synthesize:%s\n", data); + break; + case 19: + family[index].fmdealfood = atoi(data); + log("dealfood:%s\n", data); + break; + case 20: + family[index].fmpk = atoi(data); + log("pk:%s\n", data); + break; +#ifdef _NEW_MANOR_LAW + case 21: + family[index].fmmomentum = atoi(data); + log("momentum:%s\n", data); + for(i=0;i2000000000)family[index].fmmomentum=2000000000; + break; +#endif +#ifdef _FAMILY_PAY_POINT + case 23: + family[index].fmpaypoint = atoi(data); + log("pk:%s\n", data); + break; +#endif + + + default: + break; + } + db_familyupdate[index] = 1; + // + family[index].fmpopular = family[index].fmadv + family[index].fmfeed + + family[index].fmsynthesize + family[index].fmdealfood + + family[index].fmpk; + family[index].fmtotalfame = family[index].fmpopular; + for(i = 0;i < MAX_MEMBERNUM;i++){ + if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) && + (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY)) + family[index].fmtotalfame += family[index].fmmemberindex[i].popular; + } +#ifdef _NEW_MANOR_LAW + sortFamily(); +#endif +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL,index,floor,family[index].fmtotalfame, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].popular, + family[index].fmmemberindex[0].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[0].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].charfdid); +#endif + return 0; + } + } + for (i = 0; i < familymaxchar; i++) + { + if (strcmp(cmd, FAMILY_CHARDATA[i]) == 0) + { + switch(i) + { + case 0: + strncpy(family[index].fmname,data,sizeof(family[index].fmname)); + log("fmname:%s\n", data); + break; + case 1: + strncpy(family[index].fmleadername, data,sizeof(family[index].fmleadername)); + log("fmleadername:%s\n", data); + break; + case 2: + strncpy(family[index].fmleaderid, data,sizeof(family[index].fmleaderid)); + log("fmleaderid:%s\n", data); + break; + case 3: + strncpy(family[index].petname, data,sizeof(family[index].petname)); + log("petname:%s\n", data); + break; + case 4: + strncpy(family[index].petattr, data,sizeof(family[index].petattr)); + log("petattr:%s\n", data); + break; + case 5: + strncpy(family[index].fmrule, data,sizeof(family[index].fmrule)); + log("fmrule:%s\n", data); + break; +#ifdef _FAMILY_TOTEM + case 6: + strncpy(family[index].familytotem, data,sizeof(family[index].familytotem)); + log("familytotem:%s\n", data); + break; +#endif + default: + break; + } + db_familyupdate[index] = 1; + sortFamily(); +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL,index,floor,family[index].fmtotalfame, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].popular, + family[index].fmmemberindex[0].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[0].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[0].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[0].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[0].charfdid); +#endif + return 0; + } + } + } + else{ + for(i=0;i 0){ + charindex = i; + break; + } + } + // ҲԱ + if(charindex == -1){ + log("FMName:%s,id:%s\n",fmname,charid); + return -1; + } + for(i = 0; i < memberdatamaxint; i++){ + if (strcmp(cmd, MEMBER_INTDATA[i]) == 0) + { + switch(i) + { + case 0: + family[index].fmmemberindex[charindex].charlv = atoi(data); + log("charlv:%s\n", data); + break; + case 1: + family[index].fmmemberindex[charindex].charflag = atoi(data); + log("charflag:%s\n", data); + break; + case 2: + family[index].fmmemberindex[charindex].onlineflag = atoi(data); + log("onlineflag:%s\n", data); + break; + case 3: + family[index].fmmemberindex[charindex].charfdid = atoi(data); + log("charfdid:%s\n", data); + break; + case 4: + family[index].fmmemberindex[charindex].predeltime = atoi(data); + log("predeltime:%s\n", data); + break; + case 5: + family[index].fmmemberindex[charindex].popular = atoi(data); + log("popular:%s\n", data); + // + family[index].fmpopular = family[index].fmadv + family[index].fmfeed + + family[index].fmsynthesize + family[index].fmdealfood + + family[index].fmpk; + family[index].fmtotalfame = family[index].fmpopular; + for(i = 0;i < MAX_MEMBERNUM;i++){ + if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) && + (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY)) + family[index].fmtotalfame += family[index].fmmemberindex[i].popular; + } + break; + case 6: + family[index].fmmemberindex[charindex].eventflag = atoi(data); + log("eventflag:%s\n", data); + break; +#ifdef _NEW_MANOR_LAW + case 7: + family[index].fmmemberindex[charindex].momentum = atoi(data); + log("momentum:%s\n", data); + for(i=0;i2000000000)family[index].fmmomentum=2000000000; + break; +#endif + default: + break; + } + db_familyupdate[index] = 1; +#ifdef _NEW_MANOR_LAW + sortFamily(); +#endif +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL,index,floor,family[index].fmtotalfame, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[charindex].popular, + family[index].fmmemberindex[charindex].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[charindex].charfdid); +#endif + return 0; + } + } + for (i = 0; i < memberdatamaxchar; i++) + { + if (strcmp(cmd, MEMBER_CHARDATA[i]) == 0) + { + switch(i) + { + case 0: + strncpy(family[index].fmmemberindex[charindex].charname, data,sizeof(family[index].fmmemberindex[charindex].charname)); + log("charname:%s\n", data); + break; + case 1: + strncpy(family[index].fmmemberindex[charindex].charid, data,sizeof(family[index].fmmemberindex[charindex].charid)); + log("charid:%s\n", data); + break; + default: + break; + } + db_familyupdate[index] = 1; + sortFamily(); +#ifdef _PERSONAL_FAME // Arminius: + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL,index,floor,family[index].fmtotalfame, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[charindex].popular, + family[index].fmmemberindex[charindex].charfdid +#ifdef _NEW_MANOR_LAW + ,family[index].fmmemberindex[charindex].momentum +#endif + ); +#else + saacproto_ACFMCharLogin_send( + family[index].fmmemberindex[charindex].onlineflag, + SUCCESSFUL, index, floor, family[index].fmpopular, + family[index].fmmemberindex[charindex].charflag, + family[index].fmsetupflag, 1, 0, + family[index].fmmemberindex[charindex].charfdid); +#endif + return 0; + } + } + } + return -1; +} + +int ChangeFMLeader(int index, char *fmname, int fmindex) +{ + int i = 0; + int tmpindex = 0; + char buf[256]; + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + for (i = 0; i < MAX_MEMBERNUM; i++) + { + if (family[index].fmmemberindex[i].charflag == FMMEMBER_ELDER) + { + if ((strcmp(family[index].fmmemberindex[i].charname, "") == 0) + || (strcmp(family[index].fmmemberindex[i].charid, "") == 0)) + continue; + if (tmpindex == 0) tmpindex = i; + else + { + if (family[index].fmmemberindex[i].popular > + family[index].fmmemberindex[tmpindex].popular) + tmpindex = i; + } + } + } + log("ChangeFMLeader_1 tmpindex:%d\n", tmpindex); + if (tmpindex == 0) return -1; // shan return 0 -> -1 + sprintf(buf, "%d", family[index].fmleadergrano); + if (ACFixFMData(index, fmname, fmindex, 11, tmpindex, buf, + family[index].fmmemberindex[tmpindex].charname) < 0) + return -1; + log("ChangeFMLeader_2 tmpindex:%d\n", tmpindex); + if (family[index].fmmemberindex[tmpindex].onlineflag > 0) + { + char tmpbuf[256]; + sprintf(tmpbuf, "Ѿ˳ˡ\n峤ְλø%sˣ", + family[index].fmmemberindex[0].charname); + saacproto_ACFMAnnounce_send( + family[index].fmmemberindex[tmpindex].onlineflag, + SUCCESSFUL, fmname, fmindex, index, 4, tmpbuf, + family[index].fmmemberindex[tmpindex].charfdid); + } + ACMemberLeaveFM(index, fmname, fmindex, + family[index].fmmemberindex[tmpindex].charname, 0, tmpindex, 0); + return 0; +} + +#ifdef _LEADERFUNCHECK +int CheckLeaderQ(int index, char *fmname, int fmindex, char *charname, char *charid) +{ + int result = -1; + if(CheckFM(&index, fmname, fmindex) < 0) return -1; + if ((strcmp(family[index].fmmemberindex[0].charname, charname) == 0) + && (strcmp(family[index].fmmemberindex[0].charid, charid) == 0)) + result = 0; + return result; +} +#endif + +#ifdef _ACFMPK_LIST +FamilyPKSchedule FMPK_List[FMPKLIST_MAXNUM]; +void FMPK_InitList( void) +{ + int i; + for( i=0; i= FMPKLIST_MAXNUM ) return -1; + return FMPK_List[ti].pkflg; +} +char *FMPK_GetData( int ti) +{ + if( ti <0 || ti >= FMPKLIST_MAXNUM ) return NULL; + return FMPK_List[ti].Data; +} +int FMPK_SetData( int ti, int Pkflg, char *Data, int sizes) +{ + if( ti <0 || ti >= FMPKLIST_MAXNUM ) return 0; + memcpy( FMPK_List[ti].Data, Data, sizes+1); + FMPK_List[ti].pkflg = Pkflg; + return 1; +} + +#endif + +int readOneFamilyFromTi( int ti) +{ + char filename[256]; + struct stat s; + + snprintf(filename, sizeof(filename), "%s/Family.%d", familydir, ti); + + if (stat(filename, &s) < 0)return 0; + if (!(s.st_mode & S_IFREG)){ + log("%s is not a regular file\n", filename); + return 0; + } + if( readOneFamily( filename, ti) != 1 ){ + log("cannot open file %s %s\n", filename, strerror(errno)); + return 0; + } +/* + if( readOneFamily( filename, ti) != 1 ){ + log("read:%s Error !! \n", filename); + }else{ + log("read:%s OK !! \n", filename); + } +*/ + return 1; +} + +//andy_add 2003/06/16 +int readOneFamily( char *filename, int i) +{ + char line[40000], data[40000]; + FILE *fp=NULL; + int j; + int m = 0, fmnum1 = 0, fmnum2 = 0; + + if( (fp = fopen(filename, "r") ) == NULL ) return 0; + if (fgets(line, sizeof(line), fp) == NULL) return 0; + fclose( fp); + + chop(line); + for (j = 1; j <= familymaxint + familymaxchar + MAX_MEMBERNUM + FAMILY_MEMONUM; j ++){ + easyGetTokenFromBuf(line, "|", j, data, sizeof(data)); + if (strcmp(data, "") == 0) continue; + setFamilyFileDataToArg( i, data); + } + if (family[i].fmgold > FMMAXGOLD) family[i].fmgold = FMMAXGOLD; + if (family[i].fmgold < 0) family[i].fmgold = 0; + for (m = 0; m < MAX_MEMBERNUM; m++){ + if (family[i].fmmemberindex[m].charflag <= 0) continue; + if (family[i].fmmemberindex[m].charflag != FMMEMBER_APPLY) + fmnum1 = fmnum1 + 1; + if (family[i].fmmemberindex[m].charflag > 0 ) + fmnum2 = fmnum2 + 1; + } + family[i].fmjoinnum = fmnum1; + family[i].fmnum = fmnum2; + + if (family[i].fmjoinnum >= MIN_MEMBERNUM){ + family[i].fmsetupflag = 1; + family[i].predel_time = -1; + db_familyupdate[i] = 1; + }else if (family[i].fmjoinnum < MIN_MEMBERNUM){ + family[i].fmsetupflag = 0; + if (family[i].predel_time == -1) { + time_t t1; + time(&t1); + family[i].predel_time = t1 + PREDEL_TIME; + db_familyupdate[i] = 1; + } + } + return 1; +} + +#ifdef _FAMILY_PAY_POINT +void addFmPayPoint(int fmindex, char *fmname, int paypoint) +{ + int index = -1; + printf("[%s]ֵΪ%d\n", fmname, fmindex); + if (CheckFM(&index, fmname, fmindex) < 0) return -1; + printf("[%s]ֵΪ%d\n", fmname, index); + family[index].fmpaypoint += paypoint; + printf("[%s]ֵΪ%d\n", family[index].fmname, family[index].fmpaypoint); +} +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/attestation.c b/石器时代服务器端最新完整源代码/Serv/saac/attestation.c new file mode 100644 index 0000000..ea630fe --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/attestation.c @@ -0,0 +1,294 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "version.h" +#include "main.h" + +#ifdef _ONE_SERVER +int checkmac( void ) +{ + + struct ifreq ifreq; + int sock; + if((sock=socket(AF_INET,SOCK_STREAM,0))<0) + { + perror("socket"); + return 0; + } + strcpy(ifreq.ifr_name,"e"); + strcat(ifreq.ifr_name,"t"); + strcat(ifreq.ifr_name,"h"); + strcat(ifreq.ifr_name,"0"); + if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0) + { + perror("ioctl"); + return 0; + } +/* + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0){ + return 0; + } + if((unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=25){ + return 0; + } + if((unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=224){ + return 0; + } + if((unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=43){ + return 0; + } + if((unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=195){ + return 0; + } + if((unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=232){ + return 0; + } +*/ + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0x00 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=0x0C + || (unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=0x29 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=0x44 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=0x1E + || (unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=0x1A){ + + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=0x0C + || (unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=0x29 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=0xE1 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=0x44 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=0x05){ + + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=0x15 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=0x17 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=0x20 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=0x67 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=0x90){ + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=0x0C + || (unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=0x29 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=0xB3 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=0xE5 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=0x0A){ + if((unsigned char)ifreq.ifr_hwaddr.sa_data[0]!=0x00 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[1]!=0x15 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[2]!=0x17 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[3]!=0x88 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[4]!=0xD5 + || (unsigned char)ifreq.ifr_hwaddr.sa_data[5]!=0xB0){ + close(sock); + return 0; + } + } + } + } + } + return 1; +} +#endif + +int connectHost( char* hostname , unsigned short port ) +{ + struct sockaddr_in sock; /*connectݱ*/ + struct hostent* hoste; /*hostnamehostent*/ + int fd; /*ĩū*/ + int lr; /*л*/ + + memset( &sock , 0 , sizeof( struct sockaddr_in ) ); + sock.sin_family = AF_INET; + sock.sin_port = htons( port ); + + /* dot notation ëƩ */ + sock.sin_addr.s_addr = inet_addr( hostname ); + if( sock.sin_addr.s_addr == -1 ){ + + hoste = gethostbyname( hostname ); + if( hoste == NULL ){ + printf( "ȡ: %s\n", hostname); + return -1; + } + + memcpy((void*)&sock.sin_addr.s_addr , + hoste->h_addr , sizeof(struct in_addr) ); + } + + fd = socket( AF_INET, SOCK_STREAM , 0 ); + if( fd == -1 ){ + printf("Cannot Create Socket(%s errno:%d)\n" + ,strerror( errno ) ,errno ); + return -1; + } + + lr = connect(fd,(struct sockaddr*)&sock,sizeof(struct sockaddr_in)); + if( lr != 0 ){ + return -1; + } + return fd; +} + +void readpasswd(char *name, char *passwd) +{ + char line[256]; + FILE* fp = fopen("./info.txt", "r"); + if (fp == NULL) + { + return; + } + + while(1){ + line[0]='\0'; + if (fgets(line, sizeof(line), fp) == NULL) break; + chop(line); + easyGetTokenFromBuf(line, ":", 1, name, 32); + easyGetTokenFromBuf(line, ":", 2, passwd, 32); + } + +} + +int attestation( void ) +{ + +#ifdef _ONE_SERVER + if(checkmac()){ + return 1; + } +#endif + char name[32]=""; + char passwd[32]=""; + readpasswd(name, passwd); + if(strlen(name)==0){ + printf("û"); + scanf("%32s",name); + } + if(strlen(passwd)==0){ + printf("룺"); + scanf("%32s",passwd); + } + int rnd=0, nowTime=0, id=0; +#if _ATTESTAION_ID == 1 + char ip[256]="192.168.1.11"; +#else + + char ip[64]="abc.17chsa.com"; + + if(ip[0] != 'a' + || ip[1] != 'b' + || ip[2] != 'c' + || ip[3] != '.' + || ip[4] != '1' + || ip[5] != '7' + || ip[6] != 'c' + || ip[7] != 'h' + || ip[8] != 's' + || ip[9] != 'a' + || ip[10] != '.' + || ip[11] != 'c' + || ip[12] != 'o' + || ip[13] != 'm'){ + exit(0); + } + +#endif + int svfd = connectHost( ip, 8888); + if(svfd == -1){ + return 0; + } + + + fd_set rfds, wfds , efds; + struct timeval tmv; + FD_ZERO( &rfds ); + FD_ZERO( &wfds ); + FD_ZERO( &efds ); + FD_SET( svfd , &rfds ); + FD_SET( svfd , &wfds ); + FD_SET( svfd , &efds ); + tmv.tv_sec = tmv.tv_usec = 0; + int ret = select( svfd + 1 , &rfds,&wfds,&efds,&tmv ); + if( ret > 0 && svfd > 0) { + if( FD_ISSET( svfd , &wfds ) ){ + char mess[1024]; + char token[1024]; + char mac[64]; + srand((int)time(0)); + rnd = rand(); + nowTime = ( int ) time( NULL ); + id = _ATTESTAION_ID; +#if _ATTESTAION_ID == 21 + id = -21; +#endif +#if _ATTESTAION_ID == 28 + id = -28; +#endif +{ + struct ifreq ifreq; + int sock; + + if((sock=socket(AF_INET,SOCK_STREAM,0))<0) + { + perror("socket"); + return 2; + } + strcpy(ifreq.ifr_name,"eth0"); + if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0) + { + perror("ioctl"); + return 3; + } + + sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",(unsigned char)ifreq.ifr_hwaddr.sa_data[0], + (unsigned char)ifreq.ifr_hwaddr.sa_data[1], + (unsigned char)ifreq.ifr_hwaddr.sa_data[2], + (unsigned char)ifreq.ifr_hwaddr.sa_data[3], + (unsigned char)ifreq.ifr_hwaddr.sa_data[4], + (unsigned char)ifreq.ifr_hwaddr.sa_data[5]); +} + sprintf(token, "%d;%d;%d;%s;%s;%s;saac", nowTime , rnd, id ^ rnd ^ nowTime, name, passwd, mac); + + int hash = hashpjw(token); + sprintf(mess, "%d|%s", hash, token); + + send(svfd,mess,strlen(mess)+1,0); + } + } + + char buf[1024]; + memset( buf, 0, sizeof( buf ) ); + ret = read( svfd, buf, sizeof( buf ) ); + if( ret > 0 ) { + int retid; + char token[1024]; + char tmp[1024]; + int hash; + memset( tmp, 0, sizeof( tmp ) ); + memset( token, 0, sizeof( token ) ); + easyGetTokenFromBuf( buf, "|", 1, tmp, sizeof(tmp)); + hash = atoi(tmp); + easyGetTokenFromBuf( buf, "|", 2, tmp, sizeof(tmp)); + if(hash != hashpjw(tmp)){ + return 0; + } + easyGetTokenFromBuf( tmp, ";", 1, token, sizeof(token)); + retid = atoi(token); + + if((retid ^ (nowTime % 1234321) ^ (rnd % 123321)) == id){ + return 1; + } + } + return 0; +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/char.c b/石器时代服务器端最新完整源代码/Serv/saac/char.c new file mode 100644 index 0000000..31d113f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/char.c @@ -0,0 +1,1202 @@ +#define _CHAR_C_ + +// Spock +1 2000/12/6 +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "char.h" +#include "saacproto_serv.h" +#include "util.h" + +// CoolFish: Family 2001/6/12 +#include "acfamily.h" +#include "version.h" + +// Arminius 7.17 memory lock +#include "lock.h" +#include "recv.h" + +#ifdef _SASQL +#include "sasql.h" +#endif + +static void getCharNameFromString(char *str ,char *out ); +static void getCharOptionFromString( char *str , char *out ); +static void makeCharFileName( char *idstring ,char *output, int outlen,int num); +static void makeDeletCharFileName( char *id,char *output, int outlen, int num); +// Nuke *1*1 +static int makeSaveCharString( char *out , int outlen , + char *nm , char *opt , char *info ); +static int findBlankCharIndex( char *id ); + +static int unlinkCharFile( char *id , int num ); +#ifdef _SLEEP_CHAR // ȡ÷ǻԾﵵ +static void makeSleepCharFileName( char *id,char *output, int outlen, int num); +static void makeSleepCharPoolItemFileName( char *id,char *output, int outlen); +static void makeSleepCharPoolPetFileName( char *id,char *output, int outlen); +static void makeCharPoolPetFileName( char *id,char *output, int outlen); +#endif +#ifdef _CHAR_POOLITEM +static void makeCharPoolItemFileName( char *id,char *output, int outlen); +#endif +#define SPACE '|' +#define SPACESTRING "|" + +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) + + +#define USERLOG( id , format, args...) \ +{\ + char body[1000];\ + char fn[1000];\ + if(id[0]){\ + snprintf( body ,sizeof(body), "%s.log.%d" , id ,get_rotate_count() );\ + makeDirFilename( fn , sizeof(fn),logdir, getHash(id), body);\ + LOGBASE( fn , "%u " , (unsigned int ) time(NULL) );\ + LOGBASE( fn , format , ## args );\ + }\ +} + +#ifdef _ANGEL_SUMMON +struct MissionTable missiontable[MAXMISSIONTABLE]; +#endif + +/* + + + 𼰰̻ƥľѷ ë + + + char *c0 : ID + char *c1 : Passwd ֵ ƥ¾ئ + char *c2 : Charname + char *c3 : opt + Spock fixed, opt change to process + char *c3 : process + char *c4 : + int i0 : lock + int i1 : mesgid +*/ + +void charLoadCallback( int ti , int auth , char *c0, char* c1 , + char *c2 , char *c3, char *c4, int i0 , int i1 ) +{ + // Spock deleted 2000/11/2 + //static int process_id = 0; + // CoolFish: Init charindex 2001/10/16 +#ifdef _NewSave + int charindex = -1; +#else + int charindex; +#endif + char loadbuf[CHARDATASIZE]; + char infobuf[CHARDATASIZE]; + int lock = i0; + char *process = c3; + char *id = c0; + char *passwd = c1; + char *charname = c2; + int mesgid = i1; + + char *deadline = c4; + + // Spock deleted 2000/11/2 + //process_id++; + + if( auth != 0 ){ + char data[100]; + + snprintf( data, sizeof( data ), "%d" , auth ); +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , data, mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , data, mesgid ); +#endif + return; + } + if( isLocked( id ) ){ + int process=atoi(c3); +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , "locked" , mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , "locked" , mesgid ); +#endif + DeleteMemLock(getHash(id) & 0xff, id, &process); // APAC + log("\n (%s) ACͬһϵظ룬!! ", id ); + saacproto_ACKick_recv( ti, id, 1, -1); // + + checkGSUCheck(id); + return; + } + + charindex = getCharIndexByName( id , charname ); +#ifdef _NewSave + //log("\nװ:%d ˺:%s :%s\n", charindex, id, charname); +#endif + + if( charindex < 0 ){ + /* ƽҷ»ئмƥ޷¡ئ */ +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , + "char nonexistent" , mesgid , charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , + "char nonexistent" , mesgid ); +#endif + return; + } + + +// log( "loadCharOne: id:[%s] char:[%s]\n", id, charname ); + + if( loadCharOne( id , charindex , loadbuf ,sizeof( loadbuf ))<0){ +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , + "cannot load ( disk i/o error?)", mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , + "cannot load ( disk i/o error?)", mesgid ); +#endif + return; + }else{ +#ifdef _CHAR_POOLITEM + checkCharPoolItem( id); +#endif +#ifdef _CHAR_POOLPET + checkCharPoolPet( id); +#endif + + } + {//ttom + char *c_ptr; + c_ptr=loadbuf; + while(*c_ptr!='\0'){ + if( IS_2BYTEWORD(*c_ptr) ){ + if(*(c_ptr+1)==' '){ + *(c_ptr+1)=0x41; + } + c_ptr++; + if(*c_ptr=='\0') break; + } + c_ptr++; + } + }//ttom + + if( lock ){ + char result[100]; + char retdata[100]; + +#ifdef _LOCK_ADD_NAME + if( lockUser( getGSName(ti) , id , charname, passwd , 1 , result , sizeof( result ) , + retdata , sizeof( retdata ) , process , deadline) <0 ){ +#else + // Spock 2000/11/2 + if( lockUser( getGSName(ti) , id , passwd , 1 , result , sizeof( result ) , + retdata , sizeof( retdata ) , process , deadline) <0 ){ +#endif + saacproto_ACCharLoad_send( ti , FAILED, "lock FAIL!!" , mesgid , charindex ); + return; + } + } + memset( infobuf , 0 , sizeof( infobuf )); + getCharInfoFromString( loadbuf , infobuf ); + makeStringFromEscaped( infobuf ); +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , SUCCESSFUL , infobuf , mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , SUCCESSFUL , infobuf , mesgid); +#endif + +#ifdef _WAEI_KICK + saacproto_ACKick_recv( ti, id, 10, -1); //ϵ +#endif +} + +#ifdef _NewSave +int charSave( int ti , char *id , + char *charname , char *opt , char *charinfo, + int unlock , int mesgid , int charindex) +#else +int charSave( int ti , char *id , + char *charname , char *opt , char *charinfo, + int unlock , int mesgid ) +#endif +{ +#ifdef _NewSave +#else + int charindex; +#endif + char savebuf[CHARDATASIZE]; + int ret = -1; + + + memset(savebuf, 0, sizeof(savebuf)); + + //andy_log + if( strstr( charinfo, "DATAEND=") == NULL ){ + FILE *fp; + if( (fp=fopen( "badpetstring.txt", "a+")) != NULL ){ + fprintf( fp, "%s\n", charinfo); + fclose( fp); + } + log( "err add batpetstring.txt:%s[%s] !\n", id, charname); + } + + if( unlock ){ + char result[100]; + char retdata[100]; +#ifdef _LOCK_ADD_NAME + if( (ret = lockUser( getGSName(ti), id , "" , "0" , 0 , result , sizeof( result ) , + retdata , sizeof( retdata ) , "0" , "0")) < 0 ){ +#else + if( (ret = lockUser( getGSName(ti), id , "0" , 0 , result , sizeof( result ) , + retdata , sizeof( retdata ) , "0" , "0")) < 0 ){ +#endif + log( ":%s ʧ!!\n", id); + } + } + // Nuke *1 add escape + if( makeSaveCharString( savebuf , sizeof( savebuf ) , + charname, opt , charinfo )<0){ + log("\n AC浵:̫ "); + saacproto_ACCharSave_send( ti , FAILED , "too long" , mesgid ); + // Spock fixed 2000/11/1 + return ret; + } +#ifdef _NewSave + if (charindex == -1) + charindex = getCharIndexByName( id , charname ); +#else + // Nuke *1- + charindex = getCharIndexByName( id , charname ); +#endif + if( charindex < 0 ){ + int blankind = findBlankCharIndex( id ); + if( blankind < 0 ){ + log("\n ACCharSave:char full "); + saacproto_ACCharSave_send( ti , FAILED , "char full" ,mesgid); + return ret; + } else { + charindex = blankind; + } + } + + log( "˺:[%s] :[%s]\n", id, charname ); + if( saveCharOne( id , charindex , savebuf ) < 0 ){ + log("\n ACCharSave:disk I/O error or a bug "); + saacproto_ACCharSave_send( ti , FAILED , "disk I/O error or a bug", mesgid ); + return ret; + } + + saacproto_ACCharSave_send( ti , SUCCESSFUL , "" , mesgid); + return ret; +} + +void charListCallback( int ti , int auth , char *c0 , char *c1 , + char *c2 , char *c3 , char *c4 , int i0 , int i1,int charlistflg ) +{ + char listbuf[CHARDATASIZE]; + char *id = c0; + int mesgid = i0; + + //log(" б:%s:%d \n", id, auth); + + if( auth != 0 ){ + char data[100]; + snprintf( data, sizeof( data ) , "%d" , auth ); + saacproto_ACCharList_send( ti , FAILED , "˺ʱ޷½" , mesgid ); + total_ng_charlist++; + return; + } + /* + // ȡ unlock + if(charlistflg == 0){ + if( isLocked( id ) ){ + saacproto_ACCharList_send( ti , FAILED , " ½Ϸʧܣ볢µ½ " , mesgid ); + saacproto_ACKick_recv( ti, id, 1, -1); + checkGSUCheck( id ); + total_ng_charlist++; + return; + } + } + */ + // ȡ unlock + if( isLocked( id ) ){ + saacproto_ACCharList_send( ti , FAILED , "˺Ŵ״̬µ½ζܽ룬ϵԱΪ" , mesgid ); + saacproto_ACKick_recv( ti, id, 1, -1); + checkGSUCheck( id ); + total_ng_charlist++; + return; + } +#ifdef _SLEEP_CHAR // µ, ɵµ + { + char fn_old[256], fn_new[256]; + FILE *fp_old, *fp_new; + int i; + + // ﵵ + for( i=0; i= 0) + { + if (ACDelFM(index, fmname, fmindex) >= 0) + log("ɾԱ:%d :%s :%d :%s, ˺:%s, :%d\n", + index, fmname, fmindex, charname, id, fmcharindex); + } + log("ChangeFMLeader_3 index:%d fmname:%s fmindex:%d\n", index, fmname, fmindex); +#else + if (ACDelFM(index, fmname, fmindex) >= 0) + log("ɾԱ:%d :%s :%d :%s, ˺:%s, :%d\n", + index, fmname, fmindex, charname, id, fmcharindex); +#endif + } + else + { +#ifdef _FMVER21 + if (ACMemberLeaveFM(index, fmname, fmindex, charname, 0, 0, fmcharindex) >= 0) + log("ACMemberLeaveFM index:%d :%s :%d :%s, ˺:%s, :%d\n", + index, fmname, fmindex, charname, id, fmcharindex); +#else + if (ACMemberLeaveFM(index, fmname, fmindex, charname, 0, fmcharindex) >= 0) + log("ACMemberLeaveFM index:%d :%s :%d :%s, ˺:%s, :%d\n", + index, fmname, fmindex, charname, id, fmcharindex); +#endif + } + } + } +#endif + // Spock 2000/12/6 + time( &timenow ); + now = localtime( &timenow ); + sprintf( logfile , "log/chardel/%04d%02d%02d.log" , + now->tm_year + 1900 , now->tm_mon + 1 , now->tm_mday ); + LOGBASE( logfile , "%04d/%02d/%02d %02d:%02d:%02d id:[%s] char:[%s] index:[%d]\n" , + now->tm_year + 1900 , now->tm_mon + 1 , now->tm_mday , + now->tm_hour , now->tm_min , now->tm_sec , + id , charname , charindex ); + // Spock end + USERLOG( id , "˺ɾ: ɹ\n" ); + saacproto_ACCharDelete_send( ti , SUCCESSFUL , "ok" , mesgid); +} + +void dummyCallback( int ti , int auth , + char *c0 , char *c1 , char *c2 , char *c3 , + char *c4 , int i0 , int i1 ) +{ + return; +} + +static void getCharNameFromString(char *str ,char *out ) +{ + int c; + + out[0]='\0'; + for(c=0;;c++){ + if( IS_2BYTEWORD( str[c] ) ){ + out[c] = str[c]; + c ++ ; // ݼ ٯ + out[c] = str[c]; + continue; + } + + out[c] = str[c]; + if( str[c] == '\0' )break; + + if( str[c] == SPACE ){ + out[c] = '\0'; + break; + } + } +} + +static void getCharOptionFromString( char *str , char *out ) +{ + int c; + int outc = 0; + out[outc] = '\0'; + for(c=0;;c++){ + if( str[c]=='\0')break; + if( IS_2BYTEWORD( str[c] ) ){ + c++; + if( str[c] == '\0' )break; // ٯƥNULLئձ + continue; + } + + if( str[c]== SPACE ){ + c++; + for(;;c++){ + + if( str[c] == '\0' ){ // NULL ľδ + out[outc] = '\0'; + break; + } + + // ֨ ٯ ئֵ + //---- For 2Byte Code ---- + if( IS_2BYTEWORD( str[c] ) ){ + out[outc++] = str[c++]; // + out[outc++] = str[c]; // + if( str[c] == '\0' )break; // ٯƥNULLئձ + continue; + } + + // ɧ ٯ + out[outc] = str[c]; // + if( str[c] == '\0' )break; // ձδ + + if( str[c] == SPACE ){ + out[outc] = '\0'; + break; + } + outc++; + } + return; + } + } +} + +void getCharInfoFromString( char *str , char *out ) +{ + int c=0,outc=0; + int space_counter=0; + + out[outc] = '\0'; + for(c=0;;c++){ + if( str[c]=='\0')break; + if( IS_2BYTEWORD( str[c] ) ){ + c++; + continue; + }else + if( str[c]== SPACE ){ + space_counter++; + } + if( space_counter==2 && str[c]== SPACE ){ + c++; + for(;;c++){ + if( IS_2BYTEWORD( str[c] ) ){ + out[outc++] = str[c++]; + out[outc++] = str[c]; + if( str[c] == '\0' ){ + out[outc] = '\0'; + break; + } + continue; + } + + out[outc] = str[c]; + if( str[c] == '\0' )break; + if( str[c] == SPACE ){ + out[outc] = '\0'; + break; + } + outc++; + } + return; + } + } +} +static void makeDeletCharFileName( char *id,char *output, int outlen, int num) +{ + char body[1024]; + if ( strlen( id) < 1)return; + + struct tm tm1; + time_t timep; + time(&timep); + memcpy( &tm1, localtime(&timep), sizeof( tm1)); + + snprintf(body , sizeof(body ) , "%s.%d.char.%d.%d.%d.%d.%d.%d" , id , num, + tm1.tm_year + 1900, + tm1.tm_mon + 1, + tm1.tm_mday, + tm1.tm_hour, + tm1.tm_min, + tm1.tm_sec); + makeDirFilename(output , outlen, "char_delet" , getHash(id) ,body); +} + +static void makeCharFileName( char *id,char *output, int outlen, int num) +{ + char body[1024]; + if ( strlen( id) < 1)return; + + snprintf(body , sizeof(body ) , "%s.%d.char" , id , num ); + makeDirFilename(output , outlen, chardir , getHash(id) ,body); +} + +#ifdef _SLEEP_CHAR // ȡ÷ǻԾﵵ +static void makeSleepCharFileName( char *id,char *output, int outlen, int num) +{ + char body[1024]; + if ( strlen( id) < 1)return; + + snprintf(body , sizeof(body ) , "%s.%d.char" , id , num ); + makeDirFilename(output , outlen, sleepchardir , getHash(id) ,body); +} +#endif + +int loadCharNameAndOption( char *id , char *output , int outlen) +{ + char chbuf[MAXCHAR_PER_USER][CHARDATASIZE]; + char namework[CHARDATASIZE]; + char optionwork[CHARDATASIZE]; + char nm_work[CHARDATASIZE]; + + int i,count=0; + int so_far_bytes = 0; + output[0] = 0; + + for(i=0;i 0 ){ + delim[0] = SPACE; + delim[1] = 0; + } else { + delim[0] = 0; + } + + snprintf( nm_work , sizeof( nm_work ), + "%s%s|%s" , delim,namework , optionwork ); + l = strlen( nm_work ); + + if( ( so_far_bytes + l ) < outlen ){ + strcat( output , nm_work ); + so_far_bytes += l; + count++; + } + } + + return count; +} + +int loadCharOne( char *id , int num, char *output , int outlen ) +{ + char fn[1024]; + FILE *fp; + char c_temp,*c_ptr; + c_ptr=output; + + makeCharFileName( id , fn , sizeof(fn),num ); + fp = fopen( fn , "r" ); + if( fp == NULL ){ + return -1; + } + + do{ + c_temp = fgetc(fp); + *c_ptr=c_temp; + c_ptr++; + }while(c_temp != EOF); + *c_ptr='\0'; + + if( output[0]=='|' && output[1]=='|' ){ + return -1; + } + +#ifdef _FIX_CAHR_VERSION +{ + char *strp; + while((strp=strstr(output,"\\a"))!=NULL){ + *(strp+1)='n'; + } +} +#endif + + fclose(fp); + return 0; +} + +int saveCharOne( char *id , int num , char *input ) +{ + char fn[1024]; + FILE *fp; + char *strp; + char *strp1; // Won hp Ϊ + + makeCharFileName( id , fn , sizeof(fn),num ); + fp= fopen( fn , "w" ); + if( fp == NULL ) { + log( "save error 01: %d",errno );//Change add errno + return -1; + } + + // Won hp Ϊ + if ((strp=strstr(input,"\\nhp=-"))!=NULL) { + strp1=strstr(input,"\\nmp="); + *(strp+5)='1'; + strcpy((strp+6), strp1); + } + + // Arminius + if ((strp=strstr(input,"\\nhp=0\\n"))!=NULL) *(strp+5)='1'; + + +#ifdef _FIX_CAHR_VERSION +{ + char *strp; + while((strp=strstr(input,"\\n"))!=NULL){ + *(strp+1)='a'; + } +} +#endif + + + fprintf( fp , "%s" , input ); + fclose(fp); + + log( "д %s ļ:%s\n",id , fn ); + chmod(fn,0777); + return 0; + +} + +static int makeSaveCharString( char *out , int outlen , + char *nm , char *opt , char *info ) +{ + char nmwork[CHARDATASIZE]; + char optwork[CHARDATASIZE]; + char infowork[CHARDATASIZE]; + char outwork[CHARDATASIZE]; + char *nmwork_p , *optwork_p , *infowork_p; + int l; + + /* ƻ */ + + strncpy( nmwork , nm , sizeof( nmwork )); + nmwork[strlen( nm)]=0; + + strncpy( optwork , opt , sizeof( optwork )); + optwork[strlen(opt)]=0; + + strncpy( infowork , info , sizeof( infowork )); + infowork[strlen(info)]=0; + + /* ޵ */ + /* if ( esc ) { + nmwork_p = makeEscapeString1( nm , nmwork ,sizeof( nmwork )); + optwork_p = makeEscapeString1( opt , optwork , sizeof( optwork )); + infowork_p = makeEscapeString1( info , infowork , sizeof( infowork )); +} else {*/ + + nmwork_p = makeEscapeString( nm , nmwork ,sizeof( nmwork )); + optwork_p = makeEscapeString( opt , optwork , sizeof( optwork )); + infowork_p = makeEscapeString( info , infowork , sizeof( infowork )); + + // } + /* ئ£л޷¡뼰׻Էͱľ£ */ + snprintf( outwork ,sizeof( outwork ) , + "%s" SPACESTRING "%s" SPACESTRING "%s" , + nmwork_p , optwork_p , infowork_p ); + + l = strlen( outwork ); + if( l >= (outlen-1)){ + return -1; + } + + /* NULL ٯ ؤ¾0ëľоϼ֣ */ + memcpy( out , outwork , l + 1); + + return 0; +} + +int getCharIndexByName( char *id , char *charname ) +{ + int i; + for(i=0;i= (outlen-1) ) break; + }while(c_temp != EOF); + *c_ptr='\0'; + fclose(fp); + return sizes; +} + +int checkCharPoolItem( char *id) +{ + char fn[256]; + FILE *fp; + + makeCharPoolItemFileName( id , fn , sizeof(fn)); + fp = fopen( fn , "r" ); + if( fp == NULL ) { + if( saveCharPoolItem( id , "", 0) < 0 ){ + log("\n ޷:%s Ʒֿļ!!", id); + return -1; + } + }else{ + fclose(fp); + } + + return 1; +} +#endif + + +#ifdef _CHAR_POOLPET +static void makeCharPoolPetFileName( char *id,char *output, int outlen) +{ + char poolpet[256]; + if ( strlen( id) < 1)return; + snprintf( poolpet , sizeof( poolpet ) , "%s.pet" , id); + makeDirFilename(output , outlen, chardir , getHash(id) ,poolpet); +} + +#ifdef _SLEEP_CHAR // ȡ÷ǻԾֿ⵵ +static void makeSleepCharPoolPetFileName( char *id,char *output, int outlen) +{ + char poolpet[256]; + if ( strlen( id) < 1)return; + snprintf( poolpet , sizeof( poolpet ) , "%s.pet" , id); + makeDirFilename(output , outlen, sleepchardir , getHash(id) ,poolpet); +} +#endif + +int InsertCharPoolPet( char *id , char *input, int sizes) +{ + char fn[256]; + FILE *fp; + + if( sizes <= 0 ) return sizes; + makeCharPoolPetFileName( id , fn , sizeof(fn)); + + fp= fopen( fn , "a+" ); + if( fp == NULL ) { + fp= fopen( fn , "w" ); + if( fp == NULL ) { + log( " %s .\n", fn); + return -1; + } + } + + fprintf( fp , "%s" , input ); + fclose(fp); + + log( " %s ֿļ:%s\n", id , fn ); + return sizes; +} + +int saveCharPoolPet( char *id , char *input, int sizes) +{ + char fn[256]; + FILE *fp; + + if( sizes < 0 ) return sizes; + if( input == NULL ) return -1; + makeCharPoolPetFileName( id , fn , sizeof(fn)); + + fp= fopen( fn , "w" ); + if( fp == NULL ) { + log( " %s .\n", fn); + return -1; + } + + fprintf( fp , "%s" , input ); + fclose(fp); + + log( "д %s ﵵļ:%s\n", id , fn ); + return sizes; +} + +int loadCharPoolPetOne( char *id , char *output , int outlen) +{ + char fn[256]; + FILE *fp; + + char c_temp,*c_ptr; + int sizes=0; + c_ptr=output; + + makeCharPoolPetFileName( id , fn , sizeof(fn)); + + fp = fopen( fn , "r" ); + if( fp == NULL ){ + if( (fp = fopen( fn , "w" )) == NULL) + return -1; + return 0; + } + + do{ + c_temp = fgetc(fp); + *c_ptr=c_temp; + c_ptr++; + sizes++; + if( sizes >= (outlen-1) ) break; + }while(c_temp != EOF); + *c_ptr='\0'; + fclose(fp); + return sizes; +} + +int checkCharPoolPet( char *id) +{ + char fn[256]; + FILE *fp; + + makeCharPoolPetFileName( id , fn , sizeof(fn)); + fp = fopen( fn , "r" ); + if( fp == NULL ) { + if( saveCharPoolPet( id , "", 0) < 0 ){ + log("\n ޷:%s ֿļ!!", id); + return -1; + } + }else{ + fclose(fp); + } + + return 1; +} +#endif + +int filecopy( char *oldfilename, char *newfilename) +{ + FILE *oldfile; + FILE *newfile; + char c_temp; + + if( (oldfile = fopen( oldfilename, "r") ) == NULL ) { + return -1; + } + if( (newfile = fopen( newfilename, "w") ) == NULL ) { + return -1; + } + + while(1) { + c_temp = fgetc( oldfile); + if( c_temp == EOF) + break; + fputc( c_temp, newfile); + }; + + fclose( oldfile); + fclose( newfile); + + return 0; +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/characters.h b/石器时代服务器端最新完整源代码/Serv/saac/characters.h new file mode 100644 index 0000000..39bc085 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/characters.h @@ -0,0 +1,28 @@ +#ifndef __CHARACTERS_H__ +#define __CHARACTERS_H__ +#ifdef _CHARADATA_SAVE_SQL + +typedef struct tagChardata +{ + char *CHAR_list_String; + char *CHAR_list_info1_String; + char *CHAR_list_info2_String; + char *CHAR_list_count_String; + char *CHAR_list_info3_String; + char *CHAR_list_event_String; + char *CHAR_list_info4_String; + char *CHAR_list_attackmagic_String; + char *CHAR_list_info5_String; + char *CHAR_list_profession_String; + char *CHAR_list_info6_String; + char *CHAR_list_info_String; + char *CHAR_list_flg_String; + char *CHAR_list_skill_String; + char *CHAR_list_item_String; + char *CHAR_list_title_String; + char *CHAR_list_mail_String; +}Charadata; + + +#endif +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/db.c b/石器时代服务器端最新完整源代码/Serv/saac/db.c new file mode 100644 index 0000000..5dd1eb2 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/db.c @@ -0,0 +1,1481 @@ +/* + ¼ƽ봰 巸ì + + 1999 Aug 14 Created by ringo + + ì1 ͼƥľ£ + + + */ +#define _DB_C_ +#include "db.h" +#include "main.h" +#include "util.h" +#include "version.h" + +#include +#include +#include +#include +#include +#include +#include + +/* ٯ ޼ length */ +//#define CHARVALUE_MAX 1024 +#define MAXTABLE 16 +// Spock 2000/10/12 +#define CHARVALUE_MAX 256 // DB ִϵbufferС +#define KEY_MAX 64 // DB KeyִbufferС +#define HASH_SIZE 65536 // Hash table һӵEntry +#define HASH_PRIME 65521 // Hash function ʹõ +#define DBINIT_SIZE 16384 // DB ÿEntry +// Spock end + +/* ìͼۢ1ëؤմʣ */ +struct dbentry +{ + int use; +// unsigned int keyhash; /* ƽ˦ب */ + int ivalue; /* ʧ NODE -1 ƥ + ͻʧ 0 ƥئئ*/ +// int nextind; /* -1 ë */ + // Spock 2000/10/12 + int prev; // ǰһdbentry, -1ʾΪhead + int next; // һdbentry, -1ʾΪtail + char key[KEY_MAX]; + char charvalue[CHARVALUE_MAX]; +// char key[64]; /* ƽئ ٯ */ +// int charvalue_index; /* ٯ ëindex */ + // Spock end +}; + +// Spock 2000/10/12 +// Database hashtable +struct hashentry +{ + char key[KEY_MAX]; // keyֵ + int use; // Ƿѱʹ + int dbind; // ָ dbentry index + int prev; // ͬһkeyֵһ hashentry, -1Ϊhead + int next; // ͬһkeyֵһ hashentry, -1Ϊtail +}; +// Spock end + +typedef enum +{ + DB_INT_SORTED, + DB_STRING, +}DBTYPE; + +/* 1ۼìëؤմ */ +struct table +{ + int use; // 0:δʹ 1:ʹ + DBTYPE type; /* DB */ + char name[32]; /* ì */ + int num; /* ޼ */ + int toplinkindex; + // Spock 2000/10/12 + struct hashentry *hashtable; + int hashsize; + int updated; // 0:dbflushδ 1:Ѹ + int ent_finder; // ָһõ hashentry + // Spock end +}; + +struct dbentry *master_buf; /* ޼ʢ */ +int dbsize = 0; /* 0ƥ1,2,4,8,16...*/ +static int dbent_finder = 0; + +struct table dbt[MAXTABLE]; + +static void dbShowAllTable(void); + +// Spock 2000/10/12 +int dbHash(char* s) +{ + char *p; + unsigned int h= 0 ,g; + for( p = s ; *p ; p ++ ){ + h = ( h<< 4 ) + (*p); + if( (g = h & 0xf0000000) != 0){ + h = h ^ (g>>24); + h = h ^ g; + } + } + return h % HASH_PRIME; +} +// Spock end + +/* Spock deleted 2000/10/12 +struct charvalue +{ + int use; + char buf[CHARVALUE_MAX]; +}; +struct charvalue *charvalue_buf; +int charvaluesize=0; +*/ + +/* + ٯ ë + */ +/* Spock deleted 2000/10/12 +int +reallocCharValue(void) +{ + struct charvalue *previous = charvalue_buf; + struct charvalue *newbuf; + int new_charvaluesize; + if( charvaluesize == 0 ){ + new_charvaluesize = 1; + } else { + new_charvaluesize = charvaluesize * 2; + } + + newbuf = ( struct charvalue *) calloc( 1, new_charvaluesize * + sizeof( struct charvalue )); + if( newbuf == NULL ){ + log( "reallocCharValue: memory shortage!! new_charvaluesize:%d\n", + new_charvaluesize ); + return -1; + } + memset( newbuf, 0 , new_charvaluesize * sizeof( struct charvalue )); + if( previous) memcpy( (char*)newbuf, (char*)previous, + charvaluesize * sizeof( struct charvalue )); + free( previous ); + charvaluesize = new_charvaluesize; + charvalue_buf = newbuf; + + log( "reallocCharValue: " + "new_charvaluesize:%d Old address:%x New address:%x\n", + new_charvaluesize , (unsigned int )previous, + (unsigned int)newbuf ); + return 0; +} +*/ + +/* + ٯ ë1۴Իؤ£ + Իئئrealloc£ + +*/ +/* Spock deleted 2000/10/12 +static int charvalue_finder=0; +static int +dbAllocCharValue( void ) +{ + int i; + for(i=0;i= (sizeof( charvalue_buf[0].buf )-1)) return -1; + memcpy( charvalue_buf[index].buf , data, l+1 ); + return 0; +} +*/ + +/* + DBئմԻؤئʣ2 + 01 + */ +static int +reallocDB( void ) +{ + struct dbentry *previous = master_buf; + struct dbentry *newbuf; + int new_dbsize; +/* Spock deleted 2000/10/12 + if( dbsize == 0 ){ + new_dbsize = 1; + } else { + new_dbsize = dbsize * 2; + } +*/ + // Spock+1 2000/10/12 + new_dbsize = dbsize + DBINIT_SIZE; + + newbuf = (struct dbentry* ) calloc( 1, new_dbsize * + sizeof( struct dbentry) ); + /* ƹԻئ */ + if( newbuf == NULL ){ + log( "·: ڴ治!!! ݴС: %d\n", new_dbsize ); + return -1; + } + + /* лõޥ ƻ */ + + memset( newbuf , 0 , new_dbsize * sizeof( struct dbentry ) ); + /* Spock deleted 2000/10/19 + if( previous )memcpy( (char*)newbuf, (char*)previous, + dbsize * sizeof( struct dbentry )); + + // лõëݩ + free( previous ); + */ + // Spock 2000/10/19 + if ( dbsize > 0 ) + { + memcpy( newbuf , previous , dbsize * sizeof(struct dbentry)); + free( previous ); + } + // Spock end + + dbent_finder = dbsize; // dbent_finder ָδʹõ entry + dbsize = new_dbsize; + master_buf = newbuf; + + log( "·: ݴС:%d ɵַ: %x µַ:%x\n", + new_dbsize , (unsigned int)previous, (unsigned int)newbuf ); + + return 0; +} + + + +/* + allocate a node + */ +static int +//dbAllocNode( DBTYPE type ) +// Spock +1 2000/10/13 +dbAllocNode() +{ + int i; + for(i=0;i= 0 ) master_buf[prev].next = next; + if ( next >= 0 ) master_buf[next].prev = prev; + // Spock end + /* Spock deleted 2000/10/12 + if( master_buf[index].charvalue_index >= 0 ) { + charvalue_buf[ master_buf[index].charvalue_index].use = 0; + } + */ +} +void +dbShowLink( int topind ) +{ + int cur = topind; + + log( "ʼ %d \n", cur ); + + /* Spock deleted 2000/10/19 + for(;;){ + if( cur == -1 )break; + */ + // Spock +1 2000/10/19 + while ( cur >= 0 ) + { + if( master_buf[cur].use == 0 ){ + log( "dbShowLink: use is 0! key:%s\n", master_buf[cur].key ); + return; + } + // Spock +1 2000/10/12 + log( "%s %i\n", master_buf[cur].key, master_buf[cur].ivalue ); + /* Spock deleted 2000/10/12 + log( "%s %u %i\n", master_buf[cur].key , + master_buf[cur].keyhash, master_buf[cur].ivalue ); + */ + cur = master_buf[cur].next; + } +} +// Spock 2000/10/13 +static int +reallocHash( int dbi ) +{ + struct hashentry *previous = dbt[dbi].hashtable; + struct hashentry *newbuf; + int new_hashsize; + + new_hashsize = dbt[dbi].hashsize + HASH_SIZE; + newbuf = (struct hashentry* ) calloc( 1, new_hashsize * + sizeof( struct hashentry) ); + if( newbuf == NULL ){ + log( "·Ϣ: ڴ治!!! ϢС: %d\n", new_hashsize ); + return -1; + } + + memset( newbuf , 0 , new_hashsize * sizeof( struct hashentry ) ); + if( previous ) + { + memcpy( newbuf, previous, + dbt[dbi].hashsize * sizeof( struct hashentry )); + free( previous ); + } + + if ( dbt[dbi].hashsize > HASH_PRIME ) + dbt[dbi].ent_finder = dbt[dbi].hashsize; + else + dbt[dbi].ent_finder = HASH_PRIME; + dbt[dbi].hashsize = new_hashsize; + dbt[dbi].hashtable = newbuf; + + log( "·Ϣ: ϢС:%d ɵַ: %x µַ:%x\n", + new_hashsize , (unsigned int)previous, (unsigned int)newbuf ); + + return 0; +} + +static int tableGetEntry( int dbi , char *k ) +{ + int hashkey = dbHash( k ); + struct hashentry *hash = dbt[dbi].hashtable; + if ( hash[hashkey].use == 0 ) return -1; + while ( 1 ) { +// if ( hash[hashkey].use == 1 && strcmp( hash[hashkey].key , k ) == 0 ){ + if ( hash[hashkey].use == 1 ){ + if( strcmp( hash[hashkey].key , k ) == 0 )return hashkey; + } + hashkey = hash[hashkey].next; + if ( hashkey <= 0 ){ +// log("err not found hash[%x] -%s!\n", hashkey, k) + return -1; + } + } +} + +static int tableInsertNode( int dbi , char *k , int dbind ) +{ + int hashkey = dbHash( k ); + int hashnext = -1; + int i; + struct hashentry *hash = dbt[dbi].hashtable; + + if ( hash[hashkey].use == 0 ) { + strcpy( hash[hashkey].key , k ); + hash[hashkey].use = 1; + hash[hashkey].dbind = dbind; + hash[hashkey].prev = -1; + hash[hashkey].next = -1; + dbt[dbi].num++; + return hashkey; + }else { + for ( i=0; i= dbt[dbi].hashsize ) + dbt[dbi].ent_finder = HASH_PRIME; + if ( hash[dbt[dbi].ent_finder].use == 0 ) + { + hashnext = dbt[dbi].ent_finder; + break; + } + } + if ( hashnext < HASH_PRIME ) + { + log( "tableInsertNode: hashentry array full. reallocating....\n" ); + if( reallocHash( dbi ) < 0 ){ + log( "tableInsertNode: reallocation fail\n" ); + return -1; + } + else + { + hash = dbt[dbi].hashtable; + hashnext = dbt[dbi].ent_finder; + } + } + strcpy( hash[hashnext].key , k ); + hash[hashnext].use = 1; + hash[hashnext].dbind = dbind; + hash[hashnext].prev = hashkey; + hash[hashnext].next = hash[hashkey].next; + if ( hash[hashkey].next >= 0 ) + hash[hash[hashkey].next].prev = hashnext; + hash[hashkey].next = hashnext; + dbt[dbi].num++; + return hashnext; + } +} + +static void +tableReleaseNode( int dbi , int ind ) +{ + dbt[dbi].hashtable[ind].use = 0; + if ( dbt[dbi].hashtable[ind].prev >= 0 ){ + dbt[dbi].hashtable[dbt[dbi].hashtable[ind].prev].next = + dbt[dbi].hashtable[ind].next; + } + if ( dbt[dbi].hashtable[ind].next >= 0 ){ + dbt[dbi].hashtable[dbt[dbi].hashtable[ind].next].prev = + dbt[dbi].hashtable[ind].prev; + } + dbt[dbi].num--; +} +// Spock end +/* + ͼëܸľգƽë Իáë£ + Ĺئ޷¡ƥئмƥ0 + + */ +/* Spock deleted 2000/10/13 +static int +dbExtractNodeByKey( int topind , char *k ) +{ + int cur = topind; + int prev = -1; + unsigned int h = hashpjw( k ); + + // ͻƥĹئзئƥ0ë + if( topind == -1 ) return 0; + + for(;;){ + if( cur == -1 )break; + if( master_buf[cur].keyhash == h + && strcmp( master_buf[cur].key , k ) == 0 ){ + // prev ݻ cur ݱئ· + if( prev == -1 ){ + // ׼ƥͷԪئ + } else { + master_buf[prev].nextind = master_buf[cur].nextind; + } + // ľƥл½ľ¼ƥݩ + dbReleaseNode( cur ); + log( "find key %s deleted\n", k ); + return 0; + } + prev = cur; + cur = master_buf[cur].nextind; + } + // not found + log( "dbExtractNodeBykey: %s not found\n" , k ); + return 0; +} +*/ +// Spock 2000/10/13 +static int +dbExtractNodeByKey( int dbi , char *k ) +{ + int hashind = tableGetEntry( dbi , k ); + + if ( hashind < 0 ){ + log( "dbExtractNodeByKey: tableGetEntry fail, key:%s\n" , k ); + return -1; + } + if ( dbt[dbi].hashtable[hashind].dbind < 0 ){ + log( "dbExtractNodeByKey: invalid dbind in hash, key:%s\n" , k ); + return -1; + } + dbReleaseNode( dbt[dbi].hashtable[hashind].dbind ); + tableReleaseNode( dbi , hashind ); + return 0; +} +// Spock end + +/* Spock deleted 2000/10/12 +static int +dbGetEntryByKey( int topind , char *k ) +{ + int cur = topind; + unsigned int h = hashpjw( k ); + + if( topind == -1 ) return 0; + + for(;;){ + if( cur == -1 )break; + if( master_buf[cur].keyhash == h + && strcmp( master_buf[cur].key, k ) == 0 ){ + return cur; + } + cur = master_buf[cur].nextind; + } + return -1; +} +*/ + +/* + ͼëܸľգë Իáëƻ + ئǷ Insert £н ئƥ + + + */ +/* Spock deleted 2000/10/13 +static int +dbInsertNodeByIValue( int topind , int ins ) +{ + int cur = topind; + int prev = -1; + + if( topind == -1 ) return -1; + + for(;;){ + if( cur == -1 ){ + // ƥ׼ƥܰ + master_buf[prev].nextind = ins; + master_buf[ins].nextind = -1; + return 0; + } + if( master_buf[cur].ivalue < master_buf[ins].ivalue ){ + if( prev == -1 ){ + log( "top_node is badly configured\n" ); + return -1; + } + master_buf[prev].nextind = ins; + master_buf[ins].nextind = cur; + return 0; + } + prev = cur; + cur = master_buf[cur].nextind; + } + + return -1; +} +*/ +// Spock 2000/10/13 +static int +dbInsertNodeByIValue( int topind , int ins ) +{ + int cur = topind; + if ( (topind < 0)||(topind >= dbsize)||(ins < 0)||(ins >= dbsize ) ) + return -1; + while ( master_buf[cur].next >= 0 ){ + if ( master_buf[master_buf[cur].next].ivalue < master_buf[ins].ivalue ) + break; + cur = master_buf[cur].next; + } + master_buf[ins].prev = cur; + master_buf[ins].next = master_buf[cur].next; + if ( master_buf[cur].next >= 0 ) + master_buf[master_buf[cur].next].prev = ins; + master_buf[cur].next = ins; + return 0; +} +// Spock end +/* Spock deleted 2000/10/13 +static int +dbAppendNode( int topind , int ins ) +{ + int cur =topind; + int prev = -1; + if( topind == -1 ) return -1; + for(;;){ + if( cur == -1 ){ + master_buf[prev].nextind = ins; + master_buf[ins].nextind = -1; + return 0; + } + prev = cur; + cur = master_buf[cur].nextind; + } + return -1; +} +*/ +// Spock 2000/10/13 +static int +dbAppendNode( int topind , int ins ) +{ + + if ( (topind < 0)||(topind >= dbsize)||(ins < 0)||(ins >= dbsize ) ) + return -1; + master_buf[ins].prev = topind; + master_buf[ins].next = master_buf[topind].next; + if ( master_buf[topind].next >= 0 ) + master_buf[master_buf[topind].next].prev = ins; + master_buf[topind].next = ins; + return 0; +} +// Spock end + +/* + ì ë £dbѻئмƥ ɧstrcmpƻ + DBTYPE : + + ئԪئ ٯ ³绥ƥ£ + + */ +static int +dbGetTableIndex( char *tname , DBTYPE type ) +{ + int i; + + for(i=0;i= sizeof( master_buf[0].key) )return -1; + + if( dbi < 0 ) return -1; + + r = dbExtractNodeByKey( dbt[dbi].toplinkindex , key ); + if( r < 0 ){ + log( "dbUpdateEntryInt: dbExtractNodeByKey fail! bug!!!!\n" ); + return -1; + } + + entind = dbAllocNode(DB_INT_SORTED); + if( entind < 0 ) return -1; + master_buf[entind].ivalue = value; + snprintf( master_buf[entind].key , + sizeof(master_buf[entind].key), "%s", key ); + master_buf[entind].keyhash = hashpjw( master_buf[entind].key ); + master_buf[entind].nextind = -1; + + // ͵ ë + dbSetString( master_buf[entind].charvalue_index, info ); + + + r = dbInsertNodeByIValue( dbt[dbi].toplinkindex , entind ); + if( r < 0 ){ + log( "dbUpdateEntryInt: dbInsertNodeByIValue failed\n" ); + return -1; + } + + log( "dbUpdateEntryInt: successfully updated entry %s:%s:%d\n", + table, key, value ); + return 0; + +} +*/ +// Spock 2000/10/16 +int dbUpdateEntryInt( char *table , char *key , int value, char *info ) +{ + int dbi = dbGetTableIndex( table , DB_INT_SORTED ); + int dbind, hashind, newpos; + // Spock 2000/10/23 + if ( strlen( key ) >= KEY_MAX ) { + log( "dbUpdateEntryInt: key is too long, key:%s\n", key ); + return -1; + } + if ( strlen( info ) >= CHARVALUE_MAX ) { + log( "dbUpdateEntryInt: charvalue is too long, charvalue:%s\n", info ); + return -1; + } + // Spock end + if ( dbi < 0 ){ + log( "dbUpdateEntryInt: dbGetTableIndex fail\n"); + return -1; + } + hashind = tableGetEntry( dbi , key ); + if ( hashind < 0 ) + { + dbind = dbAllocNode(); + if ( dbind < 0 ) + { + log( "dbUpdateEntryInt: dbAllocNode fail\n" ); + return -1; + } + master_buf[dbind].ivalue = value; + strcpy( master_buf[dbind].key , key ); + strcpy( master_buf[dbind].charvalue , info ); + if ( dbInsertNodeByIValue( dbt[dbi].toplinkindex , dbind ) < 0 ) + { + master_buf[dbind].use = 0; + log( "dbUpdateEntryInt: dbInsertNodeByIValue fail\n" ); + return -1; + } + if ( tableInsertNode( dbi , key , dbind ) < 0 ) + { + dbReleaseNode( dbind ); + log( "dbUpdateEntryInt: tableInsertNode fail\n" ); + return -1; + } + } + else + { + dbind = dbt[dbi].hashtable[hashind].dbind; + master_buf[dbind].ivalue = value; + strcpy( master_buf[dbind].charvalue , info ); + newpos = dbind; + while ( master_buf[newpos].prev >= 0 ) + { + if ( value <= master_buf[master_buf[newpos].prev].ivalue ) + { + break; + } + newpos = master_buf[newpos].prev; + } + if ( newpos != dbind ) + { + master_buf[master_buf[dbind].prev].next = master_buf[dbind].next; + if ( master_buf[dbind].next >= 0 ) + master_buf[master_buf[dbind].next].prev = master_buf[dbind].prev; + master_buf[dbind].prev = master_buf[newpos].prev; + master_buf[dbind].next = newpos; + if ( master_buf[newpos].prev >= 0 ) + master_buf[master_buf[newpos].prev].next = dbind; + master_buf[newpos].prev = dbind; + dbt[dbi].updated = 1; + /* + log( "dbUpdateEntryInt: successfully updated entry %s:%s:%d\n", + table, key, value ); + */ + return 0; + } + while ( master_buf[newpos].next >= 0 ) + { + if ( value >= master_buf[master_buf[newpos].next].ivalue ) + { + break; + } + newpos = master_buf[newpos].next; + } + if ( newpos != dbind ) + { + master_buf[master_buf[dbind].prev].next = master_buf[dbind].next; + master_buf[master_buf[dbind].next].prev = master_buf[dbind].prev; + master_buf[dbind].prev = newpos; + master_buf[dbind].next = master_buf[newpos].next; + if ( master_buf[newpos].next >= 0 ) + master_buf[master_buf[newpos].next].prev = dbind; + master_buf[newpos].next = dbind; + } + } + dbt[dbi].updated = 1; + /* + log( "dbUpdateEntryInt: successfully updated entry %s:%s:%d\n", + table, key, value ); + */ + return 0; +} +// Spock end + +int +dbDeleteEntryInt( char *table, char *key ) +{ + int dbi = dbGetTableIndex( table , DB_INT_SORTED ); + int r; + + if ( strlen( key ) >= KEY_MAX ) { + log( "dbDeleteEntryInt: key is too long, key:%s\n", key ); + return -1; + } + if( dbi < 0 ) { + log( "dbDeleteEntryInt: dbGetTableIndex failed for %s\n", table ); + return -1; + } + //r = dbExtractNodeByKey( dbt[dbi].toplinkindex , key ); + // Spock fixed 2000/10/19 + r = dbExtractNodeByKey( dbi , key ); + if( r < 0 ){ + log( "dbDeleteEntryInt: dbExtractNodeByKey failed for %s in %s\n", + key,table ); + return -1; + } + // Spock +1 2000/10/19 + dbt[dbi].updated = 1; + log( "ɾ %s %s\n", key, table ); + return 0; +} + +static void +dbShowAllTable(void) +{ + int i; + + for(i=0;i= sizeof( master_buf[entind].key) ) return -1; + if( dbi <0 ) { + log( "dbGetEntryInt: dbGetTableIndex fail\n" ); + return -1; + } + // Spock 2000/10/19 + if( strlen(key) >= KEY_MAX ) { + log( "dbGetEntryInt: key is too long, key:%s\n" , key ); + return -1; + } + hashind = tableGetEntry( dbi , key ); + if( hashind < 0 ) return -1; + entind = dbt[dbi].hashtable[hashind].dbind; + //entind = dbGetEntryByKey( dbt[dbi].toplinkindex , key ); + // Spock end + if( entind < 0 ) { + log( "dbGetEntryInt: Invalid dbind in hashtable of %s\n" , table ); + return -1; + } + /* Ĺ׼ƥë ľ߯ */ + *output = master_buf[entind].ivalue; + + return 0; +} + +/* + ޷¡ 0 + + int *rank_out : ¼ͼ + int *count_out : + + int ì + + */ + +int +dbGetEntryRank( char *table, char *key , int *rank_out, int *count_out) +{ + int dbi = dbGetTableIndex( table , DB_INT_SORTED ); + // Spock deleted 2000/10/19 + //unsigned int hash = hashpjw(key); + int cur; + int now_score = 0x7fffffff; /*int ƥƥа */ + int r = -1 , i=0; + + // Spock 2000/10/23 + //if( strlen(key) >= sizeof( master_buf[cur].key) ) return -1; + if( strlen(key) >= KEY_MAX ) { + log( "dbGetEntryRank: key is too long, key:%s\n" , key ); + return -1; + } + if( dbi <0 ) { + log( "dbGetEntryRank: dbGetTableIndex fail\n" ); + return -1; + } + // Spock end + + // Spock 2000/10/23 + //cur = master_buf[dbt[dbi].toplinkindex].nextind; + cur = master_buf[dbt[dbi].toplinkindex].next; + //i=0; + //for(;;){ + // if( cur == -1 )break; + while ( cur >= 0 ) + { + // Spock end + if( master_buf[cur].ivalue != now_score ){ + r=i; + now_score = master_buf[cur].ivalue; + } + // Spock 2000/10/19 + //if( hash == master_buf[cur].keyhash && + // strcmp( master_buf[cur].key, key )== 0 ){ + if( strcmp( master_buf[cur].key , key ) == 0 ) + { + // Spock end + *rank_out = r; + *count_out = i; + return 0; + } + //cur = master_buf[cur].nextind; + // Spock fixed 2000/10/19 + cur = master_buf[cur].next; + i++; + } + *count_out = i; + *rank_out = r; + return 0; +} + +/* + int + */ +int +dbGetEntryRankRange( char *table, + int start, int end, char *output, int outlen ) +{ +#define MAXHITS 1024 /* ֧ئؤƥֳľƥ ringo */ + struct hitent{ /* հ ֧ë׻ */ + int entind; + int rank; + }; + + int r=0; + struct hitent hits[MAXHITS]; + int dbi = dbGetTableIndex( table , DB_INT_SORTED ); + int cur; + int hitsuse = 0,i; + int now_score = 0x7fffffff; + + if( dbi <0 ) return -1; + if( outlen <= 0 )return -1; + + cur = dbt[dbi].toplinkindex; + // Spock 2000/10/23 + //for(;;){ + // if( cur == -1 )break; + while ( cur >= 0 ) + { + // Spock end + if( master_buf[cur].ivalue != now_score ){ + r++; + now_score = master_buf[cur].ivalue; + } + if( r >= start && r <= end ){ + hits[hitsuse].entind = cur; + hits[hitsuse].rank = r; + hitsuse++; + //if( hitsuse == MAXHITS )break; + // Spock fixed 2000/10/23 + if( hitsuse >= MAXHITS ) break; + } + //cur = master_buf[cur].nextind; + // Spock fixed 2000/10/19 + cur = master_buf[cur].next; + } + output[0] = 0; + + for(i=0;i= 0 ) + { + // Spock end + if( dbt[i].type == DB_INT_SORTED ){ + fprintf( fp , "%s %d %s\n", master_buf[entind].key, + master_buf[entind].ivalue, + //makeStringFromEscaped( + // dbGetString(master_buf[entind].charvalue_index))); + // Spock fixed 2000/10/19 + makeStringFromEscaped(master_buf[entind].charvalue)); + } else { + fprintf( fp , "%s %s\n", master_buf[entind].key, + //makeStringFromEscaped( + // dbGetString(master_buf[entind].charvalue_index))); + // Spock fixed 2000/10/19 + makeStringFromEscaped(master_buf[entind].charvalue)); + } + //entind = master_buf[entind].nextind; + // Spock fixed 2000/10/19 + entind = master_buf[entind].next; + } + fclose(fp); + dbt[i].updated = 0; + } + + return 0; +} + + +int dbRead( char *dir ) +{ + char dirname[1024]; + DIR *d; + struct dirent *de; + // Spock +1 2000/10/19 + memset( dbt , 0 , MAXTABLE * sizeof(struct table) ); + { + char tmp[1024]; + snprintf( tmp, sizeof( tmp ), "%s/int" , dir ); + if( mkdir( tmp, 0755 )==0){ + log( " %s\n", tmp ); + } + snprintf( tmp, sizeof( tmp ), "%s/string" , dir ); + if( mkdir( tmp, 0755 )==0){ + log( " %s\n", tmp ); + } + } + + snprintf( dirname, sizeof( dirname ), + "%s/int" , dir ); + d = opendir(dirname); + if( d == NULL ){ + log( "ܴļ %s\n", dirname ); + return -1; + } + + while(1){ + de = readdir( d ); + if( de == NULL )break; + if( de->d_name[0] != '.' ){ + char filename[1024]; + FILE *fp; + struct stat s; + snprintf( filename, sizeof(filename),"%s/%s",dirname, de->d_name ); + log( "ȡ:%s\n..", filename); + if( stat( filename, &s ) < 0 ){ + continue; + } + if( !( s.st_mode & S_IFREG ) ){ + continue; + } + + fp = fopen( filename, "r" ); + if( fp == NULL ){ + log( "ܴļ %s %s\n", + filename, strerror( errno )); + continue; + } + while(1){ + char line[1024]; + char k[1024] , v[1024], info[1024]; + if( fgets( line , sizeof( line) , fp ) == NULL )break; + chop( line); + k[0] = '\0'; + easyGetTokenFromString( line, 1, k, sizeof(k)); + v[0] = '\0'; + easyGetTokenFromString( line, 2, v, sizeof(v)); + info[0] = '\0'; + easyGetTokenFromString( line, 3, info, sizeof(info)); + dbUpdateEntryInt( de->d_name, k, atoi(v), info); + } + fclose(fp); + } + } + closedir(d); + snprintf( dirname, sizeof( dirname), "%s/string" , dir ); + d = opendir( dirname ); + if( d == NULL ){ + log( "ܴļ %s\n", dirname ); + return -1; + } + while(1){ + de = readdir( d ); + if( de == NULL )break; + if( de->d_name[0] != '.' ){ + char filename[1024]; + FILE *fp; + struct stat s; + snprintf( filename, sizeof( filename),"%s/%s",dirname,de->d_name ); + log( "ȡ:%s\n..", filename); + + if( stat( filename, &s ) < 0 ){ + continue; + } + if( !(s.st_mode & S_IFREG )){ + continue; + } + fp = fopen( filename, "r" ); + if( fp == NULL ){ + log( "ܴļ %s %s\n", + filename, strerror(errno )); + continue; + } + while(1){ + char line[CHARVALUE_MAX+1024]; + char k[1024]; + if( fgets( line, sizeof( line), fp ) == NULL )break; + /* chop */ + chop(line); + k[0] = '\0'; + easyGetTokenFromString( line, 1, k,sizeof(k)); + dbUpdateEntryString( de->d_name, k, line+strlen(k)+1); + } + // Nuke +1 1027: Close for safe + fclose(fp); + } + } + closedir(d); + return 0; +} + +/* ϶ ϶Իʣ + 0 ƻ뼰 廥ؤߣ + num0羮¾޼ئ + + int ì÷ + + */ +int dbGetEntryCountRange( char *table, int count_start, int num, + char *output, int outlen ) +{ + int dbi = dbGetTableIndex( table , DB_INT_SORTED ); + int cur; + int i; + int now_score = 0x7fffffff , r; + + if( dbi < 0) return -1; + if( outlen < 1 ) return -1; + output[0]=0; + + //cur = master_buf[dbt[dbi].toplinkindex].nextind; + // Spock fixed 2000/10/19 + cur = master_buf[dbt[dbi].toplinkindex].next; + i=0; + r=0; + for(;;){ + if( cur == -1 ) break; + + if( master_buf[cur].ivalue != now_score ){ + r=i; + now_score = master_buf[cur].ivalue; + } + + if( ( i >= count_start ) && + ( i < (count_start + num ) ) ){ + char tmp[1024]; + if( (i !=count_start)){ + strcatsafe( output, outlen, "|" ); + } + + snprintf( tmp, sizeof( tmp), + "%d,%d,%s,%d,%s", i, r, master_buf[cur].key, + master_buf[cur].ivalue, + //dbGetString( master_buf[cur].charvalue_index )); + // Spock fixed 2000/10/19 + master_buf[cur].charvalue); + strcatsafe( output, outlen,tmp ); + } + i++; + //cur = master_buf[cur].nextind; + // Spock fixed 2000/10/19 + cur = master_buf[cur].next; + } + return 0; +} + + +/* + ٯ ì + */ +/* Spock deleted 2000/10/19 +int +dbUpdateEntryString( char *table, char *key, char *value ) +{ + int dbi = dbGetTableIndex(table, DB_STRING); + int r, entind; + + log( "dbUpdateEntryString: [%s] [%s] [%s]\n", table, key, value ); + + if( strlen(key) >= sizeof(master_buf[0].key) )return -1; + if( dbi < 0 )return -1; + + r = dbExtractNodeByKey( dbt[dbi].toplinkindex, key ); + if( r< 0 ){ + log( "dbUpdateEntryString dbExtractNodeByKey fail! bug!!\n" ); + return -1; + } + + entind = dbAllocNode( DB_STRING ); + if( entind < 0 ) return -1; + + master_buf[entind].ivalue = 0; + dbSetString( master_buf[entind].charvalue_index, value ); + snprintf( master_buf[entind].key, + sizeof(master_buf[0].key), "%s",key ); + master_buf[entind].keyhash = hashpjw( master_buf[entind].key ); + master_buf[entind].nextind = -1; + + if( dbAppendNode( dbt[dbi].toplinkindex, entind ) < 0 ){ + log( "dbUpdateEntryString: dbAppendNode failed\n" ); + return -1; + } + log( "dbUpdateEntryString: successfully updated entry %s:%s:%s\n", + table,key,value ); + + return 0; +} +*/ +// Spock 2000/10/19 +int dbUpdateEntryString( char *table, char *key, char *value ) +{ + int dbi = dbGetTableIndex( table , DB_STRING ); + int dbind, hashind; + + if ( strlen( key ) >= KEY_MAX ) { + log( "dbUpdateEntryString: key is too long, key:%s\n", key ); + return -1; + } + if ( strlen( value ) >= CHARVALUE_MAX ) { + log( "dbUpdateEntryString: charvalue is too long, charvalue:%s\n", value ); + return -1; + } + if ( dbi < 0 ) { + log( "dbUpdateEntryString: dbGetTableIndex fail, table:%s\n", table ); + return -1; + } + hashind = tableGetEntry( dbi , key ); + if ( hashind < 0 ) + { + dbind = dbAllocNode(); + if ( dbind < 0 ) + { + log( "dbUpdateEntryString: dbAllocNode fail\n" ); + return -1; + } + strcpy( master_buf[dbind].key , key ); + strcpy( master_buf[dbind].charvalue , value ); + if ( dbAppendNode( dbt[dbi].toplinkindex , dbind ) < 0 ) + { + master_buf[dbind].use = 0; + log( "dbUpdateEntryString: dbAppendNode fail\n" ); + return -1; + } + if ( tableInsertNode( dbi , key , dbind ) < 0 ) + { + dbReleaseNode( dbind ); + log( "dbUpdateEntryString: tableInsertNode fail\n" ); + return -1; + } + } + else + { + dbind = dbt[dbi].hashtable[hashind].dbind; + strcpy( master_buf[dbind].charvalue , value ); + } + dbt[dbi].updated = 1; + /* + log( "dbUpdateEntryString: successfully updated entry %s:%s:%s\n", + table,key,value ); + */ + return 0; +} +// Spock end + +int +dbGetEntryString( char *table, char *key, char *output, int outlen ) +{ + int dbi = dbGetTableIndex( table, DB_STRING ); + int entind; + // Spock +1 2000/10/19 + int hashind; + + // Spock 2000/10/23 + //if( strlen(key) >= sizeof( master_buf[entind].key) ) return -1; + if ( strlen(key) >= KEY_MAX ) { + log( "dbGetEntryString: key is too long, key:%s\n", key ); + return -1; + } + if( dbi <0 ) { + log( "dbGetEntryString: dbGetTableIndex fail\n" ); + return -1; + } + // Spock 2000/10/19 + hashind = tableGetEntry( dbi , key ); + if ( hashind < 0 ){ + log("err hashind <0\n") + return -1; + } + entind = dbt[dbi].hashtable[hashind].dbind; + + if ( entind < 0 ){ + log( "entind < 0 "); + return -1; + } + snprintf( output , outlen , "%s" , master_buf[entind].charvalue ); + + return 0; +} + +int +dbDeleteEntryString( char *table, char *key ) +{ + int dbi = dbGetTableIndex( table, DB_STRING ); + int r; + + // Spock 2000/10/23 + //if( strlen(key) >= sizeof( master_buf[entind].key) ) return -1; + if ( strlen(key) >= KEY_MAX ) { + log( "dbDeleteEntryString: key is too long, key:%s\n", key ); + return -1; + } + if( dbi <0 ) { + log( "dbDeleteEntryString: dbGetTableIndex fail\n" ); + return -1; + } + // Spock end + //r = dbExtractNodeByKey( dbt[dbi].toplinkindex, key ); + // Spock fixed 2000/10/19 + r = dbExtractNodeByKey( dbi , key ); + if( r < 0 ){ + log( "dbDeleteEntryString: dbExtractNodeByKey failed for %s in %s\n", + key,table ); + return -1; + } + dbt[dbi].updated = 1; + log( "ɾ %s %s\n", key, table ); + return 0; +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/acfamily.h b/石器时代服务器端最新完整源代码/Serv/saac/include/acfamily.h new file mode 100644 index 0000000..ab37e6c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/acfamily.h @@ -0,0 +1,263 @@ +#ifndef _FAMILY_H_ +#define _FAMILY_H_ + +#include "version.h" + +#define MAX_FAMILY 1000 // 1000 +#define TEXT_MAX 1024 + +#define MAX_MEMBERNUM FAMILY_MAX_MEMBER + +#define MIN_MEMBERNUM 5 // 10 + +#ifdef _FIX_10_FMPOINT // WON ADD Ŵׯ԰ +#define MAX_FMPOINT 2 +#else +#define MAX_FMPOINT 4 // 4 +#endif + +#define PREDEL_TIME 60*60*24*7 // 60*60*24*3 +#define PREDELMEMBER_TIME 60*60*24*60 // 30 60*60*24*30 +#define FAMILY_MEMONUM 35 // ԰ +#define FAMILY_MEMOLEN 256 +#define FMSMEMOINDEX 10000 // ֮԰ index +#define FMSMEMONUM 140 +#define TOPFMLISTNUM 10 // а +#define MINFMPOPNUM -20000000 +// shan 20011207 +#define MAXFMPOPNUM 100000000 +#define MAXFMMOMENTUM 10000000 + +//#define MAXFMPOPNUM 5000000 +#define MINAPPLYPNUM 10 // +#define FMMEMBERINDEX "fmmember" +#define FMMEMOLIST "memo" +#define FMELDERNUM 5 // +#define FMMAXGOLD 1000000000 // + +// shan 20011207 +#define MAXRECVPOP 5000000 // ת +// CoolFish: 2001/11/26 +//#define MAXRECVPOP 2500000 // ת + +typedef enum +{ + fmindex, + fmleadergrano, + fmnum, + fmjoinnum, + fmacceptflag, + fmsetupflag, + fmsprite, + fmpointindex, + fmpopular, + fmgold, + fmmemberindexmaxnum, + apply_time, + setup_time, + predel_time, + memonowwritenum, + memonum, + fmadv, + fmfeed, + fmsynthesize, + fmdealfood, + fmpk, +#ifdef _NEW_MANOR_LAW + fmmomentum, +#endif +#ifdef _SET_FMPOINT + fmpointtime, +#endif +#ifdef _FAMILY_PAY_POINT + fmpaypoint, +#endif +#ifdef _FAMILYBADGE_ + fmbadge, +#endif + familymaxint, +} FAMILY_DATAINT; + +typedef enum +{ + fmname, + fmleadername, + fmleaderid, + petname, + petattr, + fmrule, +#ifdef _FAMILY_TOTEM + familytotem, +#endif + familymaxchar, +} FAMILY_DATACHAR; + +typedef enum +{ + charlv, + charflag, + onlineflag, + charfdid, + predeltime, + popular, +#ifdef _FMVER21 + eventflag, +#endif +#ifdef _NEW_MANOR_LAW + momentum, +#endif + memberdatamaxint, +} MEMBER_DATAINT; + +typedef enum +{ + charname, + charid, + memberdatamaxchar, +} MEMBER_DATACHAR; + +typedef enum +{ + FMMEMBER_NONE = -1, + FMMEMBER_MEMBER = 1, + FMMEMBER_APPLY, + FMMEMBER_LEADER, + FMMEMBER_ELDER, + FMMEMBER_KINDNUM, +} MEMBER_KIND; + +// #define MEMBERMEM memberdatamaxint * sizeof(int) + 50 +// #define FAMILYMEM familymaxint * sizeof(int) + 1000 + MAX_MEMBERNUM * MEMBERMEM +#ifdef _ACFMPK_LIST +void FMPK_InitList( void); +#endif +void sortFamily(void); // Arminius: sort family +int getFMsortedlist(char *buf, int bufsize, int bp, int ep); + +int readFamily(char *dir); + +int readOneFamilyFromTi( int ti); +int readOneFamily( char *filename, int i); + +int writeFamily(char *dir); +int readFMPoint(char *dir); +int writeFMPoint(char *dir); +int readFMSMemo(char *dir); +int writeFMSMemo(char *dir); +void delovertimeFMMem(int time); +#ifdef _PERSONAL_FAME +int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid); +#else +int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid); +#endif +#ifdef _PERSONAL_FAME // Arminius: +int ACJoinFM(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int fame, int charfdid); +#else +int ACJoinFM(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int charfdid); +#endif +int ACLeaveFM(int index, char *fmname, int fmindex, + char *charname, char* charid); +int ACDelFM(int index, char *fmname, int fmindex); +int ACShowFMList(char *data); +#ifdef _FAMILY_TOTEM +int ACShowFMTotem(int fd); +#endif +int ACShowFMMemberList(int index, int *acceptflag, int *fmjoinnum, char *data +#ifdef _FAMILYBADGE_ + ,int *badge +#endif + ); +int ACFMDetail(int index, char *fmname, int fmindex, char *data); +#ifdef _FMVER21 +int ACMemberJoinFM(int index, char *fmname, int fmindex, + char *charname, int charindex, int result, int meindex); +#else +int ACMemberJoinFM(int index, char *fmname, int fmindex, + char *charname, int charindex, int result); +#endif +#ifdef _FMVER21 +int ACMemberLeaveFM(int index, char *fmname, int fmindex, + char *charname, int flag, int charindex, int meindex); +#else +int ACMemberLeaveFM(int index, char *fmname, int fmindex, + char *charname, int flag, int charindex); +#endif +int ACFMAssignOcp(int index, char *fmname, int fmindex, + char *charname, int charindex, int result); + +#ifdef _FM_MODIFY +int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid, + int *charfame, int eventflag,int gsnum + #ifdef _NEW_MANOR_LAW + ,int *momentum + #endif + ); +#else + #ifdef _PERSONAL_FAME // Arminius: + int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid, + int *charfame, int eventflag); + #else + int ACFMCharLogin(int fd, int index, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int *floor, int *fmpopular, + int *joinflag, int *fmsetupflag, int *charindex, int charfdid); + #endif +#endif + +int ACFMCharLogout(int index, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int charfdid); +int delfmpointindex(int fmindex); +int ACgetFMFloor(int fmindex); +int ACgetFMInfoFromChar(char *fmname, int *fmindex, + char *charname, char *charid, int *charindex); +int ACFMReadMemo(int index, int *dataindex, char *data); +int ACFMWriteMemo(int index, char *fmname, int fmindex, char *data); +int ACFMPointList(char *data); +int ACSetFMPoint(int index, char *fmanme, int fmindex, int fmpointindex, + int fl, int x, int y); +int ACFixFMPoint(int winindex, char *winfmname, int winfmindex, int loseindex, + char *losefmname, int losefmindex, int village); +int ACShowTopFMList(char *data, int datasize, int kindflag); +int ACFMAnnounce(char *fmname, int fmindex, int index, char *data, int color); +int ACFixFMData(int index, char *fmname, int fmindex, int kindflag, int charindex, + char *data1, char *data2); +int ACGetFMData(int index, char *fmname, int fmindex, int kindflag, int *data); +int ACFixFMPK(int winindex, char *winfmname, int winfmindex, int loseindex, + char *losefmname, int losefmindex); +int ACGMFixFMData(int index, char *fmname, char *charid, char *cmd, char *data); +int ChangeFMLeader(int index, char *fmname, int fmindex); +#ifdef _LEADERFUNCHECK +int CheckLeaderQ(int index, char *fmname, int fmindex, char *charname, char *charid); +#endif + +#ifdef _ACFMPK_LIST +#define FMPKLIST_MAXNUM MAX_FMPOINT +typedef struct tagFamilyPKSchedule { + int pkflg; + char Data[256]; +} FamilyPKSchedule; + +void FMPK_LoadList(); +void FMPK_BackUpList(); +int FMPK_GetTypeFlg( int ti); +char *FMPK_GetData( int ti); +int FMPK_SetData( int ti, int Pkflg, char *Data, int sizes); +#endif +#ifdef _FAMILY_PAY_POINT +void addFmPayPoint(int fmindex, char *fmname, int paypoint); +#endif +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/attestation.h b/石器时代服务器端最新完整源代码/Serv/saac/include/attestation.h new file mode 100644 index 0000000..fae33c5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/attestation.h @@ -0,0 +1,5 @@ +#ifndef __ATTESTATION_H__ +#define __ATTESTATION_H__ +int attestation( void ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/char.h b/石器时代服务器端最新完整源代码/Serv/saac/include/char.h new file mode 100644 index 0000000..95f57ef --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/char.h @@ -0,0 +1,95 @@ +#ifndef _CHAR_H_ +#define _CHAR_H_ +#include "version.h" + +/* 1ؤԻ ƽҷ(̻) */ +#ifdef _MORECHARACTERS_ +#define MAXCHAR_PER_USER 4 +#else +#define MAXCHAR_PER_USER 2 +#endif + +int isLocked( char *id ); +void charLoadCallback( int ti , int auth_ok , char *c0, char* c1 , + char *c2 , char *c3, char *c4, int i0 , int i1 ); +// Spock 2000/11/1 +//void charSave( int ti , char *c0 , +// char *c2 , char *c3 , char *c4, int i0 , int i1 ); +// return process number +#ifdef _NewSave +int charSave( int ti , char *c0 , + char *c2 , char *c3 , char *c4, int i0 , int i1 , int charindex ); +#else +int charSave( int ti , char *c0 , + char *c2 , char *c3 , char *c4, int i0 , int i1 ); +#endif +// Spock end + +void charListCallback( int ti , int auth_ok , char *c0 , char *c1 , + char *c2 , char *c3 , char *c4 , int i0 , int i1,int charlistflg ); + +void charDeleteCallback( int ti , int auth_ok , + char *c0 , char *c1 , char *c2 , char *c3 , + char *c4 , int i0 , int i1 ); +// Nuke +void dummyCallback( int ti , int auth_ok , + char *c0 , char *c1 , char *c2 , char *c3 , + char *c4 , int i0 , int i1 ); + + +// Spock 2000/11/1 +#ifdef _LOCK_ADD_NAME +int lockUser( char *gmsvname , char *id , char *name, char *passwd , int lock , + char *result, int resultlen, + char *retdata , int retdatalen , char *process , char *deadline); +#else +int lockUser( char *gmsvname , char *id , char *passwd , int lock , + char *result, int resultlen, + char *retdata , int retdatalen , char *process , char *deadline); +#endif +// Spock end + +int checkValidCharName( char *a); + +int loadCharOne( char *idstring , int num, char *output , int outlen ); +int saveCharOne( char *idstring , int num , char *input ); + +int loadCharNameAndOption( char *id , char *output , int outlen); +int getCharIndexByName( char *id , char *charname ); +void getCharInfoFromString( char *str , char *out ); + +#ifdef _CHAR_POOLITEM +int InsertCharPoolItem( char *id , char *input, int sizes); +int saveCharPoolItem( char *id , char *input, int sizes); +int loadCharPoolItemOne( char *id , char *output , int outlen); +int checkCharPoolItem( char *id); +#endif + +#ifdef _CHAR_POOLPET +int InsertCharPoolPet( char *id , char *input, int sizes); +int saveCharPoolPet( char *id , char *input, int sizes); +int loadCharPoolPetOne( char *id , char *output , int outlen); +int checkCharPoolPet( char *id); +#endif + + +#ifdef _ANGEL_SUMMON + +#define MAXMISSIONTABLE 200 + +struct MissionTable +{ + char angelinfo[64]; + char heroinfo[64]; + int mission; + int flag; + int time; + int limittime; +}; + +extern struct MissionTable missiontable[MAXMISSIONTABLE]; + +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/db.h b/石器时代服务器端最新完整源代码/Serv/saac/include/db.h new file mode 100644 index 0000000..54eae2f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/db.h @@ -0,0 +1,19 @@ +#ifndef _DB_H_ +#define _DB_H_ + +int dbUpdateEntryInt( char *table , char *key , int value, char *info ); +int dbUpdateEntryString( char *table, char *key, char *value ); +int dbDeleteEntryInt( char *table, char *key ); +int dbDeleteEntryString( char *table, char *key ); +int dbGetEntryInt( char *table, char *key, int *output ); +int dbGetEntryString( char *table, char *key, char *output, int outlen ); +int dbGetEntryRank( char *table, char *key , int *r_out, int *c_out ); +int dbGetEntryRankRange( char *table, + int start, int end, char *output, int outlen ); +int dbGetEntryCountRange( char *table, int count_start, int num, + char *output, int outlen ); + +int dbRead( char *dir ); +int dbFlush( char *dir ); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/lock.h b/石器时代服务器端最新完整源代码/Serv/saac/include/lock.h new file mode 100644 index 0000000..c62aacf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/lock.h @@ -0,0 +1,36 @@ +#ifndef _LOCK_H_ +#define _LOCK_H_ + +#include "version.h" + +typedef struct tagLockNode { + int use; + char cdkey[16]; +#ifdef _LOCK_ADD_NAME + char name[32]; +#endif + char server[128]; + int process; + struct tagLockNode *next,*prev; +} LockNode; + +extern LockNode **userlock; + +void Lock_Init(void); +#ifdef _LOCK_ADD_NAME + int InsertMemLock(int entry, char *cdkey, char *name, char *passwd, char *server, int process, char *deadline); +#else + int InsertMemLock(int entry, char *cdkey, char *passwd, char *server, int process, char *deadline); +#endif +int DeleteMemLock(int entry, char *cdkey, int *process); +void DeleteMemLockServer(char *sname); +int isMemLocked(int entry, char *cdkey); +int GetMemLockState(int entry, char *cdkey, char *result); +int GetMemLockServer(int entry, char *cdkey, char *result); + +int LockNode_getGname( int entries, char *id, char *gname); + +int ChangeMemDeadline(int entry, char *cdkey, char *deadline); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/mac.h b/石器时代服务器端最新完整源代码/Serv/saac/include/mac.h new file mode 100644 index 0000000..d91a947 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/mac.h @@ -0,0 +1,21 @@ +#define _TESTMAC "00-07-40-E3-33-15" //ԼIJMAC +#define _USERMAC1 "00-30-48-72-C0-56" //52441740 Yֻ 222.223.133.2 +#define _USERMAC2 "00-14-85-37-31-CA" //22729177 1Ҷ 58.33.147.183 +#define _USERMAC3 "00-0B-6A-C5-B5-76" //42813855 &&mF 61.152.238.97 +#define _USERMAC4 "00-13-46-66-86-52" //10203543 ̶ +#define _USERMAC5 "00-00-00-00-00-00" +#define _USERMAC6 "00-00-00-00-00-00" +#define _USERMAC7 "00-00-00-00-00-00" +#define _USERMAC8 "00-00-00-00-00-00" +#define _USERMAC9 "00-00-00-00-00-00" +#define _USERMAC10 "00-00-00-00-00-00" +#define _USERMAC11 "00-00-00-00-00-00" +#define _USERMAC12 "00-00-00-00-00-00" +#define _USERMAC13 "00-00-00-00-00-00" +#define _USERMAC14 "00-00-00-00-00-00" +#define _USERMAC15 "00-00-00-00-00-00" +#define _USERMAC16 "00-00-00-00-00-00" +#define _USERMAC17 "00-00-00-00-00-00" +#define _USERMAC18 "00-00-00-00-00-00" +#define _USERMAC19 "00-00-00-00-00-00" +#define _USERMAC20 "00-00-00-00-00-00" diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/mail.h b/石器时代服务器端最新完整源代码/Serv/saac/include/mail.h new file mode 100644 index 0000000..94b93bf --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/mail.h @@ -0,0 +1,13 @@ +#ifndef _MAIL_H_ +#define _MAIL_H_ + +void receiveMail( char *id_from, char *charname_from, + char *id_to, char *charname_to, char *message, int option , + int use_msgid, unsigned int msgid ); +void receiveMailAck( char *id, char *charname, int a , int mesgid ); +void flushMail( int fd, char *id, char *charname ); +void expireMail(); +int readMail( char *dir ); +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/main.h b/石器时代服务器端最新完整源代码/Serv/saac/include/main.h new file mode 100644 index 0000000..f7f9550 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/main.h @@ -0,0 +1,132 @@ +#ifndef _MAIN_H_ +#define _MAIN_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "version.h" + +#ifdef _MAIN_C_ +#define EXT +#else +#define EXT extern +#endif + +#define SA_NODEFER 0x40000000 +#define SA_NOMASK SA_NODEFER + +#define CHARDATASIZE ( 1024 * 1024 ) + +char *chartime(); +#define LOGBASE( filename , format , args...)\ +{\ + FILE *f;\ + f = fopen( filename , "a" );\ + if( f != NULL ){\ + fprintf( f , format , ## args);\ + fclose(f);\ + } else{ fprintf( stderr,"fuckup! log fail!:%s:%s\n", filename,strerror(errno));}\ +} + +// Spock 2000/10/27 +#define log(format, args...) \ +{\ + fprintf( stderr, format , ## args );\ +} +// Spock end +#define SUCCESSFUL "successful" +#define FAILED "failed" + +#define MAXCONNECTION 15 +#define USERID_MAX 32 +#define CHARNAME_MAX 32 + +EXT char svpass[64]; +EXT char chardir[64]; +EXT char logdir[64]; +EXT char dbdir[64]; +EXT char maildir[64]; + +// CoolFish: Family 2001/5/9 +EXT char familydir[64]; +EXT char fmpointdir[64]; +EXT char fmsmemodir[64]; + +EXT int sameipmun; + +#ifdef _OLDPS_TO_MD5PS +EXT int usemd5; +#endif + +EXT int log_rotate_interval; +EXT int total_ok_charlist, total_ng_charlist; + +#ifdef _AUTO_BACKUP +EXT int autobackupday; +EXT int autobackuphour; +#endif + +#ifdef _LOTTERY_SYSTEM +EXT int lotterysystem; +#endif + +#ifdef _SLEEP_CHAR +EXT char sleepchardir[64]; +#endif + +typedef struct _gmsv +{ + int use; + int fd; + char name[128]; +} gmsv; + +int get_rotate_count(void ); +void checkGSUCheck( char *id ); +int logout_game_server( int ti ); +int is_game_server_login( int ti ); +char * getGSName( int i ); + +void gmsvBroadcast( int fd, char *p1, char *p2, char *p3 , int flag ); +#if _ATTESTAION_ID == 1 + +int login_game_server( int ti, int id, char *svname , char *svpas , + char *result , int resultlen , + char *retdata , int retdatalen ); +#else +int login_game_server( int ti , char *svname , char *svpas , + char *result , int resultlen , + char *retdata , int retdatalen ); +#endif + +#ifdef _ANGEL_SUMMON +void delMissionTableOnedata( int index); + +typedef enum +{ + MISSION_NONE =0, + MISSION_WAIT_ANSWER, + MISSION_DOING, + MISSION_HERO_COMPLETE, + MISSION_TIMEOVER, +}ANGEL_MISSIONFLAG; +#endif + + +#undef EXT +#endif + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/md5.h b/石器时代服务器端最新完整源代码/Serv/saac/include/md5.h new file mode 100644 index 0000000..9472158 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/md5.h @@ -0,0 +1,63 @@ +/* MD5.H - header file for MD5C.C */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD5 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD5 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. */ +#ifndef __MD5_H +#define __MD5_H + +#ifndef PROTOTYPES +#define PROTOTYPES 0 +#endif + +/* POINTER defines a generic pointer type */ +typedef unsigned char *POINTER; + +/* UINT2 defines a two byte word */ +typedef unsigned short int UINT2; + +/* UINT4 defines a four byte word */ +typedef unsigned long int UINT4; + +/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. + If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it + returns an empty list. */ + +#if PROTOTYPES +#define PROTO_LIST(list) list +#else +#define PROTO_LIST(list) () +#endif + +/* MD5 context. */ +typedef struct { + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +void MD5Init PROTO_LIST ((MD5_CTX *)); +void MD5Update PROTO_LIST + ((MD5_CTX *, char *, int)); +void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); + +char *MD5String (const char *string); + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/recv.h b/石器时代服务器端最新完整源代码/Serv/saac/include/recv.h new file mode 100644 index 0000000..74b13fe --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/recv.h @@ -0,0 +1,38 @@ +#ifndef _RECV_H_ +#define _RECV_H_ +#include "acfamily.h" +#ifdef _SEND_EFFECT // WON ADD ѩЧ +void SendEffect(char *ffect); +#endif + +#ifdef _AC_SEND_FM_PK // WON ADD ׯ԰սбAC +void load_fm_pk_list(void); +void save_fm_pk_list(void); +char fm_pk_list[FMPKLIST_MAXNUM][255]; +#endif + +#ifdef _ALLDOMAN // Syu ADD аNPC +void LOAD_herolist(); +void SAVE_herolist(int); +void Send_A_herolist(int); + +void Send_S_herolist( char *ocdkey , char *oname , char *ncdkey , char *nname , + char *title , int level , int trns , int floor ); +#define MAX_HERO_COLUMN 7 +#define MAX_HERO_LIST 100 +char Herolist[MAX_HERO_LIST][MAX_HERO_COLUMN][72]; +#endif + +typedef struct tagUNLOCKMENUS{ + char PlayerId[256]; + int use; + time_t time; +}UNLockMenus; + +int UNlockM_isBe( char *id); +int UNlockM_addPlayer( char *id); +int UNlockM_UnlockPlayer( void); +int UNlockM_Init( void); + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_serv.h b/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_serv.h new file mode 100644 index 0000000..da77165 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_serv.h @@ -0,0 +1,388 @@ +/* output by ../../bin/lsgen.perl 0.41 ( 1998 May) + * made Thu Feb 17 17:30:27 2000 + * user ringo + * host indy + * file /opt/ringo/chsa/src/saac/./saacproto_serv.h + * util ./saacproto_util.c , ./saacproto_util.h + * src /opt/ringo/chsa/src/saac/../../doc/saacproto.html + */ +#ifndef _SAACPROTOSERV_H_ +#define _SAACPROTOSERV_H_ +#include "version.h" +#include "saacproto_util.h" +#ifdef _CHARADATA_SAVE_SQL +#include "characters.h" +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 64 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 64 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 64 + 1 ) +#endif +#else +#ifdef MAXLSRPCARGS +#if ( MAXLSRPCARGS <= ( 7 + 1 ) ) +#undef MAXLSRPCARGS +#define MAXLSRPCARGS ( 7 + 1 ) +#endif +#else +#define MAXLSRPCARGS ( 7 + 1 ) +#endif +#endif +#ifdef _ALLDOMAN // Syu ADD аNPC +void saacproto_UpdataStele_recv( int fd , char *cdkey , char *name , char *title , int level , int trns , int time , int floor) ; +void saacproto_UpdataStele_send( int fd , char *data ) ; +void saacproto_S_UpdataStele_send( int fd , char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ) ; + +#endif +#if _ATTESTAION_ID == 1 +void saacproto_ACServerLogin_recv( int ti, int id, char* servername , char* serverpas); +#else +void saacproto_ACServerLogin_recv( int fd,char* servername,char* serverpas ) ; +#endif + +void saacproto_ACServerLogin_send( int fd,char* result,char* data ) ; +void saacproto_ACServerLogout_recv( int fd ) ; + +void saacproto_ACCharList_recv( int ti,char* id,char* pas ,char* ip,char* mac , int mesgid,int charlistflg); + +void saacproto_ACCharList_send( int fd,char* result,char* output,int id ) ; /* ../../doc/saacproto.html line 124 */ +void saacproto_ACCharLoad_recv( int fd,char* id,char* pas,char* charname,int lock,char* opt,int mesgid ) ; /* ../../doc/saacproto.html line 148 */ +// CoolFish: 2001/10/16 +#ifdef _NewSave +void saacproto_ACCharLoad_send( int fd,char* result,char* data,int id,int charindex ) ; /* ../../doc/saacproto.html line 175 */ +void saacproto_ACCharSave_recv( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid,int charindex ) ; /* ../../doc/saacproto.html line 191 */ +#else +void saacproto_ACCharLoad_send( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 175 */ +void saacproto_ACCharSave_recv( int fd,char* id,char* charname,char* opt,char* charinfo,int unlock,int mesgid ) ; /* ../../doc/saacproto.html line 191 */ +#endif +void saacproto_ACCharSave_send( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 214 */ + +void saacproto_ACCharDelete_recv( int fd,char* id,char* passwd,char* charname,char* option,int mesgid ) ; /* ../../doc/saacproto.html line 231 */ +void saacproto_ACCharDelete_send( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 256 */ +void saacproto_ACLock_recv( int fd,char* id,int lock,int mesgid ) ; /* ../../doc/saacproto.html line 271 */ +void saacproto_ACLock_send( int fd,char* result,char* data,int id ) ; /* ../../doc/saacproto.html line 290 */ +void saacproto_ACUCheck_recv( int fd,char* mem_id,int status ) ; /* ../../doc/saacproto.html line 304 */ +void saacproto_ACUCheck_send( int fd,char* mem_id ) ; /* ../../doc/saacproto.html line 318 */ +void saacproto_DBUpdateEntryString_recv( int fd,char* table,char* key,char* value,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 329 */ +void saacproto_DBUpdateEntryString_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 344 */ +void saacproto_DBDeleteEntryString_recv( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 357 */ +void saacproto_DBDeleteEntryString_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 369 */ +void saacproto_DBGetEntryString_recv( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 384 */ +void saacproto_DBGetEntryString_send( int fd,char* result,char* value,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 396 */ +void saacproto_DBUpdateEntryInt_recv( int fd,char* table,char* key,int value,char* info,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 413 */ +void saacproto_DBUpdateEntryInt_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 435 */ +void saacproto_DBGetEntryRank_recv( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 449 */ +void saacproto_DBGetEntryRank_send( int fd,char* result,int rank,int count,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 463 */ +void saacproto_DBDeleteEntryInt_recv( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 482 */ +void saacproto_DBDeleteEntryInt_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 494 */ +void saacproto_DBGetEntryInt_recv( int fd,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 508 */ +void saacproto_DBGetEntryInt_send( int fd,char* result,int value,char* table,char* key,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 520 */ +void saacproto_DBGetEntryByRank_recv( int fd,char* table,int rank_start,int rank_end,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 537 */ +void saacproto_DBGetEntryByRank_send( int fd,char* result,char* list,char* table,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 552 */ +void saacproto_DBGetEntryByCount_recv( int fd,char* table,int count_start,int num,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 571 */ +void saacproto_DBGetEntryByCount_send( int fd,char* result,char* list,char* table,int count_start,int msgid,int msgid2 ) ; /* ../../doc/saacproto.html line 583 */ +void saacproto_Broadcast_recv( int fd,char* id,char* charname,char* message,int flag ) ; /* ../../doc/saacproto.html line 598 */ +void saacproto_Broadcast_send( int fd,char* id,char* charname,char* message ) ; /* ../../doc/saacproto.html line 611 */ +void saacproto_Message_recv( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option ) ; /* ../../doc/saacproto.html line 624 */ +void saacproto_Message_send( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option,int mesgid ) ; /* ../../doc/saacproto.html line 642 */ +void saacproto_MessageAck_recv( int fd,char* id,char* charname,char* result,int mesgid ) ; /* ../../doc/saacproto.html line 661 */ +void saacproto_MessageFlush_recv( int fd,char* id,char* charname ) ; /* ../../doc/saacproto.html line 680 */ +int saacproto_InitServer(int (*writefunc)(int,char*,int) , int worksiz ); +void saacproto_SetServerLogFiles( char *read , char *write ); +void saacproto_CleanupServer( void ); +//int saacproto_ServerDispatchMessage( int fd, char *line ); +int saacproto_ServerDispatchMessage( int fd , char *encoded, char *debugfun); + +// CoolFish: Family 2001/5/9 +// +#ifdef _PERSONAL_FAME +void saacproto_ACAddFM_recv(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petarrt, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid); +#else +void saacproto_ACAddFM_recv(int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petarrt, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid); +#endif +void saacproto_ACAddFM_send(int fd, char *result, int fmindex, int index, + int charfdid); +// +// #ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACJoinFM_recv(int fd, char *fmname, int fmindex, char *charname, + char *charid, int charlv, int index, int fame, int charfdid); +// #else +// void saacproto_ACJoinFM_recv(int fd, char *fmname, int fmindex, char *charname, +// char *charid, int charlv, int index, int charfdid); +// #endif +void saacproto_ACJoinFM_send(int fd, char *result, int recv, int charfdid); +// ˳ +void saacproto_ACLeaveFM_recv(int fd, char *fmname, int fmindex, char *charname, + char *charid, int index, int charfdid); +void saacproto_ACLeaveFM_send(int fd, char *result, int resultflag, int charfdid); +// ɢ +#ifdef _LEADERFUNCHECK +void saacproto_ACDelFM_recv(int fd, char *fmname, int fmindex, int index, char *charname, + char *charid, int charfdid); +#else +void saacproto_ACDelFM_recv(int fd, char *fmname, int fmindex, int index, int charfdid); +#endif +void saacproto_ACDelFM_send(int fd, char *result, int charfdid); +// гб +void saacproto_ACShowFMList_recv(int fd); +void saacproto_ACShowFMList_send(int fd, char *result, int num, char *data); +#ifdef _FAMILY_TOTEM +// гͼ +void saacproto_ACShowFMTotem_recv(int fd); +void saacproto_ACShowFMTotem_send(int fd, char *result, int num, char *data); +#endif +// гԱб +void saacproto_ACShowMemberList_recv(int fd, int index); +void saacproto_ACShowMemberList_send(int fd, char *result, int index, int num, + int acceptflag, int fmjoinnum, char *data +#ifdef _FAMILYBADGE_ + ,int badge +#endif + ); +// гϸ +void saacproto_ACFMDetail_recv(int fd, char *fmname, int fmindex, + int index, int charfdid); +void saacproto_ACFMDetail_send(int fd, char *result, char *data, int charfdid); +// г԰ +void saacproto_ACFMReadMemo_recv(int fd, int index); +void saacproto_ACFMReadMemo_send(int fd, char *result, int index, int num, + int dataindex, char *data); +// д԰ +void saacproto_ACFMWriteMemo_recv(int fd, char *fmname, int fmindex, + char *data, int index); +void saacproto_ACFMWriteMemo_send(int fd, char *result, int index); +// login +#ifdef _FM_MODIFY +void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int eventflag, int charfdid,int gsnum); +#else + #ifdef _FMVER21 + void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int eventflag, int charfdid); + #else + void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int charfdid); + #endif +#endif +#ifdef _PERSONAL_FAME // Arminius: +void saacproto_ACFMCharLogin_send(int fd, char *result, int index, int floor, + int fmpopular, int joinflag, int fmsetupflag, int flag, int charindex, + int charfame, int charfdid +#ifdef _NEW_MANOR_LAW + ,int momentum +#endif + ); +#else +void saacproto_ACFMCharLogin_send(int fd, char *result, int index, int floor, + int fmpopular, int joinflag, int fmsetupflag, int flag, int charindex, + int charfdid); +#endif + +// logout +void saacproto_ACFMCharLogout_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int index, int charfdid); +void saacproto_ACFMCharLogout_send(int fd, char *result, int charfdid); +// 峤˳Ա塢޸ļԱְλ +#ifdef _FMVER21 +void saacproto_ACMemberJoinFM_recv(int fd, char* fmname, int fmindex, + char* charname, int charindex, int index, int result, int meindex, + int charfdid); +#else +void saacproto_ACMemberJoinFM_recv(int fd, char* fmname, int fmindex, + char* charname, int charindex, int index, int result, int charfdid); +#endif +void saacproto_ACMemberJoinFM_send(int fd, char* result, int charfdid); +// 峤˳Ա뿪 +#ifdef _FMVER21 +void saacproto_ACMemberLeaveFM_recv(int fd, char* fmname, int fmindex, + char* charname, int charindex, int index, int meindex, int charfdid); +#else +void saacproto_ACMemberLeaveFM_recv(int fd, char* fmname, int fmindex, + char* charname, int charindex, int index, int charfdid); +#endif +void saacproto_ACMemberLeaveFM_send(int fd, char* result, int charfdid); +// гݵ +void saacproto_ACFMPointList_recv(int fd); +void saacproto_ACFMPointList_send(int fd, char *result, char *data); + +// ݵ +void saacproto_ACSetFMPoint_recv(int fd, char *fmname, int fmindex, int index, + int fmpointindex, int fl, int x, int y, int charfdid); +void saacproto_ACSetFMPoint_send(int fd, char *result, int r, int charfdid); +// 趨ݵ +void saacproto_ACFixFMPoint_recv(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex, + int village); +void saacproto_ACFixFMPoint_send(int fd, char *result, int r); +// 峤ϵԱ㲥 +// kindflag 1:峤㲥 2:屻ϵͳɾ 3:ϵͳ֪ͨѶϢ +void saacproto_ACFMAnnounce_recv(int fd, char *fmname, int fmindex, int index, + char *data, int color); +void saacproto_ACFMAnnounce_send(int fd, char *result, char *fmname, + int fmindex, int index, int kindflag, char *data, int color); +// га +void saacproto_ACShowTopFMList_recv(int fd, int kindflag); +void saacproto_ACShowTopFMList_send(int fd, char *result, int kindflag, int num, char *data); +// (ǷճԱ) +// kindflag 1:ǷļԱ 2:У 3:ػ 4:ּ +// 5:ɢʱ 6: 7:ð 8: +// 9:ϳɡӹ 10: +void saacproto_ACFixFMData_recv(int fd, char *fmname, int fmindex, int index, + int kindflag, char *data1, char *data2, int charindex, int charfdid); +void saacproto_ACFixFMData_send(int fd, char *result, int kindflag, + char *data1, char *data2, int charfdid); +// У¼ +void saacproto_ACFixFMPK_recv(int fd, char *winfmname, int winfmindex, + int winindex, char *losefmname, int losefmindex, int loseindex); +void saacproto_ACFixFMPK_send(int fd, char *result, int data, int winindex, + int loseindex); +// ȡü +// kindflag 1: +void saacproto_ACGetFMData_recv(int fd, char *fmname, int fmindex, int index, + int kindflag, int charfdid); +void saacproto_ACGetFMData_send(int fd, char *result, int kindflag, int data, + int charfdid); +// ǣ +void saacproto_ACGMFixFMData_recv(int fd, int fmindex, char *charid, + char *cmd, char *data, int charfdid); +void saacproto_ACGMFixFMData_send(int fd, char *result, char *fmname, int charfdid); +// սų +void saacproto_ACFMClearPK_send(int fd, char *result, char *fmname, int fmindex, + int index); +// CoolFish end + +#ifdef _AC_SEND_FM_PK // WON ADD ׯ԰սбAC +void saacproto_ACLoadFmPk_send(int fd, char *data); +#ifdef _ACFMPK_LIST//ACSendFmPk +void saacproto_ACSendFmPk_send( int fd, int userindex, int flg); +#endif +#endif + +// Arminius 8.1 manor pk +void saacproto_ACManorPKAck_recv(int fd, char *data); +void saacproto_ACManorPKAck_send(int fd, char *data); + +void saacproto_ACreLoadFmData_recv(int fd, int type, int data); + +#ifdef _AC_SEND_FM_PK // WON ADD ׯ԰սбAC +void saacproto_ACLoadFmPk_recv(int fd, int fmpks_pos); +#ifdef _ACFMPK_LIST +void saacproto_ACSendFmPk_recv(int fd, int fmpks_pos, int userindex, int flg, char *data); +#else +void saacproto_ACSendFmPk_recv(int fd, int fmpks_pos, char *data); +#endif +#endif + +#ifdef _WAEI_KICK +void saacproto_ACKick_recv( int ti , char* id, int lock, int mesgid ); +void saacproto_ACKick_send( int fd, int act, char* data, int id ); +#endif + +#ifdef _SEND_EFFECT // WON ADD ѩЧ +void saacproto_SendEffect_send(int fd, char *effect); +#endif + +#ifdef _CHAR_POOLITEM +void saacproto_ACCharInsertPoolItem_recv( int fd, char *cdkey, int userindex, int clifdid, char *Pooldataarg); + +void saacproto_ACCharSavePoolItem_recv( int fd, char *cdkey, int userindex, int clifdid, char *Pooldataarg); +void saacproto_ACCharSavePoolItem_send( int fd, char *Acces, char *Pooldataarg, int clifdid ); +void saacproto_ACCharGetPoolItem_recv( int fd, char *cdkey, int userindex, int clifdid, int npcid); +void saacproto_ACCharGetPoolItem_send( int fd, char *Acces, char *Pooldataarg, int clifdid, int npcid); +#endif + + +#ifdef _CHAR_POOLPET +void saacproto_ACCharInsertPoolPet_recv( int fd, char *cdkey, int userindex, int clifdid, char *Pooldataarg); + +void saacproto_ACCharSavePoolPet_recv( int fd, char *cdkey, int userindex, int clifdid, char *Pooldataarg); +void saacproto_ACCharSavePoolPet_send( int fd, char *Acces, char *Pooldataarg, int clifdid ); +void saacproto_ACCharGetPoolPet_recv( int fd, char *cdkey, int userindex, int clifdid, int npcid); +void saacproto_ACCharGetPoolPet_send( int fd, char *Acces, char *Pooldataarg, int clifdid, int npcid); +#endif + +#ifdef _ANGEL_SUMMON +void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, char* angelinfo); +void saacproto_ACMissionTable_send( int fd, int num, int type, char *data, char* angelinfo); +#endif + +#ifdef _TEACHER_SYSTEM +void saacproto_ACCheckCharacterOnLine_send( int fd, int charaindex, int iOnline,char *data,int flag); +void saacproto_ACCheckCharacterOnLine_recv( int fd, int charaindex, char *id, char *name, int flag); +#endif + +void saacproto_ACCharLogin_recv( int fd, int clifd, char* id, char* pas, char* ip +#ifdef _NEWCLISETMAC +,char* mac +#endif +); +void saacproto_ACCharLogin_send( int fd, int clifd, int flag ); +#ifdef _SASQL +void saacproto_LockLogin_recv( int fd, char* id, char* ip, int flag ); + +#ifdef _NEW_VIP_SHOP +void saacproto_QueryPoint_send( int fd, int clifd, int point ); +void saacproto_QueryPoint_recv( int fd, int clifd, char *id ); + +void saacproto_NewVipShop_recv( int fd, int clifd, char *id, int point, char *buf, int flag); +void saacproto_NewVipShop_send( int fd, int clifd, int point, char *buf, int flag); +#endif + +#ifdef _ITEM_PET_LOCKED +void saacproto_ItemPetLocked_recv( int fd, int clifd, char *id, char *safepasswd ); +void saacproto_ItemPetLocked_send( int fd, int clifd, int flag, char *data ); +void saacproto_ItemPetLockedPasswd_recv( int fd, int clifd, char *id, char *safepasswd ); +void saacproto_ItemPetLockedPasswd_send( int fd, int clifd, char *data ); +#endif +#ifdef _COST_ITEM +void saacproto_CostItem_recv( int fd, int clifd, char *id, int point); +#endif +#ifdef _ONLINE_COST +void saacproto_OnlineCost_recv( int fd, int clifd, char *id, char *safepasswd, int fmindex, char *fmname ); +void saacproto_OnlineCost_send( int fd, int clifd, char *data ); +#endif +#ifdef _SQL_BUY_FUNC +void saacproto_OnlineBuy_recv( int fd, int clifd, char *id, char *safepasswd ); +void saacproto_OnlineBuy_send( int fd, int clifd, char *data ); +#endif +#ifdef _VIPPOINT_OLD_TO_NEW +void saacproto_OldToNew_recv( int fd, int clifd, char *id, int point ); +void saacproto_OldToNew_send( int fd, int clifd, char *data ); +#endif + +#ifdef _FORMULATE_AUTO_PK +void saacproto_FormulateAutoPk_recv( int fd, int clifd, char *id, int point ); +void saacproto_FormulateAutoPk_send( int fd, int clifd, char *data ); +#endif + +#ifdef _CHARADATA_SAVE_SQL +void saacproto_CharadataSaveSQL_recv( int fd, int clifd, char *id, Charadata charadata, int saveindex, int flag ); +#endif +#endif + + +#ifdef _LOTTERY_SYSTEM +void saacproto_LotterySystem_recv(int fd); +void saacproto_LotterySystem_send( int fd, char *award ); +#endif + +#ifdef _ALL_SERV_SEND +void saacproto_AllServSend_recv(char *data); +void saacproto_AllServSend_send(int fd, char *data); +#endif + +#endif +/* end of the generated server header code */ + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_util.h b/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_util.h new file mode 100644 index 0000000..ebd108f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/saacproto_util.h @@ -0,0 +1,114 @@ +#ifndef _SAACPROTOUTIL_H_ +#define _SAACPROTOUTIL_H_ +#include "version.h" +#include +#include +#ifndef WIN32 +#include +#include +#endif + + +#define saacproto__NOENCRYPT +#define saacproto__NODEBUG +struct saacproto_ { + int (*write_func)(int,char*,int) ; /* write function */ + size_t workbufsize; /* size of work area */ + char *work,*arraywork,*escapework,*val_str,*ret_work; /* work areas which have same size */ + char *cryptwork,*jencodecopy,*jencodeout,*compresswork; /* these work has bigger size (3times)*/ + char** token_list; /* token list */ + unsigned long message_id; /*= 1, */ /* for generating message IDs */ +}; + +#ifdef _SAACPROTOUTIL_C_ +struct saacproto_ saacproto = { + NULL, + 0, + NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL, + NULL, + 1, +}; + +char **saacproto_stringwrapper; +char saacproto_readlogfilename[1024]; +char saacproto_writelogfilename[1024]; +#else +extern char **saacproto_stringwrapper; +extern struct saacproto_ saacproto; +extern char saacproto_readlogfilename[1024]; +extern char saacproto_writelogfilename[1024]; +#endif +char* saacproto_escapeString( char*a ); +char* saacproto_descapeString( char*a ); +void saacproto_splitString( char *src ); +void saacproto_strcpysafe( char *dest, char *src, int len ); +void saacproto_strcatsafe( char *dest , char *src , int maxlen ); +char*saacproto_mkstr_int( int i ); +char*saacproto_mkstr_u_int( unsigned int i ); +char*saacproto_mkstr_long( long l ); +char*saacproto_mkstr_u_long( unsigned long l ); +char*saacproto_mkstr_short( short s ); +char*saacproto_mkstr_u_short( short s ); +char*saacproto_mkstr_char( char c ); +char*saacproto_mkstr_u_char( char c); +char*saacproto_mkstr_string( char*a ); +char*saacproto_mkstr_float( float f ); +char*saacproto_mkstr_double( double d ); +char*saacproto_mkstr_int_array( int size , int *array ); +char*saacproto_mkstr_u_int_array( int size , int *array ); +char*saacproto_mkstr_short_array( int size , short *array ); +char*saacproto_mkstr_u_short_array(int size , short *array ); +char *saacproto_mkstr_char_array( int size , char *array ); +char *saacproto_mkstr_u_char_array( int size , unsigned char *array ); +char *saacproto_mkstr_float_array( int size , float *array ); +char *saacproto_mkstr_double_array( int size , double *array ); +int saacproto_demkstr_int( char*a ); +unsigned int saacproto_demkstr_u_int( char*a ); +long saacproto_demkstr_long( char*a ); +unsigned long saacproto_demkstr_u_long(char*a ); +short saacproto_demkstr_short( char*a ); +unsigned short saacproto_demkstr_u_short( char*a ); +char saacproto_demkstr_char( char*a ); +unsigned char saacproto_demkstr_u_char( char*a ); +float saacproto_demkstr_float( char*a ); +double saacproto_demkstr_double(char*a ); +char* saacproto_demkstr_string( char*a); +int *saacproto_demkstr_int_array( char**tk ,int *buf ,int start , int size ); +int *saacproto_demkstr_u_int_array( char **tk , int *buf , int start , int size ); +unsigned int *saacproto_demkstr_long_array( + char **tk , unsigned int *buf , int start , int size ); +unsigned long *saacproto_demkstr_u_long_array( + char **tk , unsigned long *buf , int start , int size ); +short *saacproto_demkstr_short_array( char **tk , short *buf , int start , int size ); +unsigned short*saacproto_demkstr_u_short_array( + char **tk , unsigned short *buf , int start , int size ); +char *saacproto_demkstr_char_array( char **tk , char *buf , int start , int size ); +unsigned char *saacproto_demkstr_u_char_array( + char **tk , unsigned char*buf , int start , int size ); +float *saacproto_demkstr_float_array( char **tk , float *buf , int start , int size ); +double *saacproto_demkstr_u_double_array( char **tk , double *buf , int start , int size ); +char *saacproto_wrapStringAddr( char *copy , int maxcopylen , char*src ); + +void saacproto_GetMessageInfo( int *id , char *funcname , int len,char **tk ); +int saacproto_ClientRead(void); +void saacproto_consumeLine(char *buf , int ofs ); +void saacproto_copyLine( char*src , char *out , int maxoutlen ); +void saacproto_Send( int fd , char *msg ); +int saacproto_AllocateCommonWork(int bufsiz); +unsigned int saacproto_GetNewMessageID(void); +void saacproto_CreateHeader(char*out, char *fname ); +void saacproto_CreateHeaderID( char *out,unsigned long msgid , char *fname ); +int saacproto_default_write_wrap( int fd , char *buf , int size ); +void saacproto_bzero( char *b , int siz ); +void saacproto_bcopy(char*s , char *d , int siz ); +char *saacproto_Ltoa( long v ); +char *saacproto_Ultoa( unsigned long v ); +void saacproto_DebugSend( int fd , char *msg ); +/* Modified by ringo to fasten int type transfer */ +char *saacproto_cnv10to62( int a, char *out, int outlen ); +int saacproto_a62toi( char *a ); + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/sasql.h b/石器时代服务器端最新完整源代码/Serv/saac/include/sasql.h new file mode 100644 index 0000000..09b3a9b --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/sasql.h @@ -0,0 +1,69 @@ +#ifndef _SASQL_H_ +#define _SASQL_H_ + +#include "version.h" +#ifdef _SASQL + +#define BOOL int +#define FALSE 0 +#define TRUE 1 + +void sasql_close( void ); +BOOL sasql_init( void ); +int sasql_query(char *nm, char *pas); +BOOL sasql_update(char *nm, char *path); +BOOL sasql_logindate(char *nm); +BOOL sasql_online( char *ID, char *NM, char *MAC, char *IP, int flag ); +BOOL sasql_register(char *id, char *ps); +BOOL sasql_craete_userinfo( void ); +BOOL sasql_craete_lock( void ); +BOOL sasql_chehk_lock( char *idip ); +BOOL sasql_add_lock( char *idip ); +BOOL sasql_del_lock( char *idip ); +int sasql_onlinenum( char *MAC ); +#ifdef _NEW_VIP_SHOP +BOOL sasql_add_vippoint( char *ID, int point ); +int sasql_query_point( char *name ); +#endif +#ifdef _ITEM_PET_LOCKED +char *sasql_ItemPetLocked( char *id, char *safepasswd ); +char *sasql_ItemPetLocked_Passwd( char *id, char *safepasswd ); +BOOL sasql_ItemPetLocked_Char( char *id, char *safepasswd ); +#endif +#ifdef _ONLINE_COST +char *sasql_OnlineCost( char *id, char *costpasswd, int fmindex, char *fmname ); +void sasql_OnlineCost_add( int cost, int num, int point); +#endif +#ifdef _SQL_BUY_FUNC +char *sasql_OnlineBuy( char *id, char *costpasswd ); +void sasql_OnlineBuy_add( char *coststr, int type, int num ); +#endif +#endif +#ifdef _FORMULATE_AUTO_PK +BOOL sasql_add_FormulateAutoPk( char *ID, int point ); +#endif +#ifdef _OLDPS_TO_MD5PS +void sasql_OldpsToMd5ps(); +#endif +#ifdef _CHARADATA_SAVE_SQL +void sasql_charadata_Save(char *id, char* table, char *data, int saveindex, int flag); + + + +enum{ + INSERT, + SELECT, + UPDATE, + DELETE, +}; + +#endif + + + + + + +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/util.h b/石器时代服务器端最新完整源代码/Serv/saac/include/util.h new file mode 100644 index 0000000..80b371c --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/util.h @@ -0,0 +1,31 @@ +#ifndef _UTIL_H_ +#define _UTIL_H_ +int strcatsafe( char *dest, int destlen , char *append ); +void prepareDirectories(char *base); +void easyGetTokenFromString( char *src,int count,char*output,int len ); +void remove_r( char *s ); +void makeDirFilename( char *out , int outlen , + char *base , int dirchar , char *child ); +int isFile( char *fn ); +int createFile( char *fn , char *line ); + +char * makeStringFromEscaped( char* src ); +char * makeEscapeString( char* src , char* dest, int sizeofdest); +char * makeEscapeString1( char* src , char* dest, int sizeofdest); +int getHash ( char* s ); +char * chop( char *s ); +int hashpjw ( char* s ); + +// CoolFish: Family 2001/5/30 +//void easyGetTokenFromBuf(char *src, char delim, int count, char*output, int len); + +int easyGetTokenFromBuf( char* src ,char* delim ,int count, char* output , int len ); +#endif /* ifndef _UTIL_H_ */ + + + + + + + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/include/version.h b/石器时代服务器端最新完整源代码/Serv/saac/include/version.h new file mode 100644 index 0000000..6fd7016 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/include/version.h @@ -0,0 +1,182 @@ +#ifndef __VERSION_H__ +#define __VERSION_H__ + +/* 뽫ר definition + * Ȼ remark/unmark ع + */ + +//⹦ܿ---------------------------------------- + +#define _SAVE_ZIP //Զ +#define _IP_VIP //IP֤ +#define _FIX_FMPOINTTIME //ռʱ +#define _FAMILYBADGE_ // +#define _MORECHARACTERS_ //ҳ +#define _SQL_BUY_FUNC_ONE_CDKEY //ÿʺŽȡһε + +#define _ATTESTAION_ID 1 + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 + //#define _VERSION_25 +#endif + +#ifndef _VERSION_25 + #define _TEACHER_SYSTEM // ʦϵͳ(δ) + #define _ALLDOMAN // (ɿ) Syu ADD аNPC +#endif + #define _CHANNEL_MODIFY // Ƶ + #define _NEW_MANOR_LAW // ׯ԰ +/* ------------------------------------------------------------------- + * רְ幦ܲ + * ԱС褡ѫ־ΰС + * ˵ + */ +#define _LEADERFLAG_VER // šߡ.... (ɿ) +#define _FAMILY // (ɿ) +#define _PERSONAL_FAME // Arminius 8.30 (ɿ) +#define _FMVER21 // CoolFish: 峤ְ 2001/8/30 (ɿ) +#define _CHAR_POOLITEM // (ɿ) ANDY òֿ +#define _CHAR_POOLPET // (ɿ) Robin óֿ + +/* ------------------------------------------------------------------- + * ר˷֮ϴ浵ʽ + * ԱС褡ѫ + * ˵ϴ浵ʽ + */ +#define _NewSave // CoolFish: 2001/10/16 (ɿ) + +/* ------------------------------------------------------------------- + * ר£գ + * ԱС + * ˵ + */ +#define _LEADERFUNCHECK // CoolFish: 2002/02/06 峤ܴô(ɿ) + +/* ------------------------------------------------------------------- + * ר + * Ա + * ˵ + */ +#define _WAEI_KICK // (ɿ)(ؿ) + +/* ------------------------------------------------------------------- + * רŴׯ԰(4.0) + * Ա־ + * ˵ + */ +#ifndef _VERSION_25 +#define _FIX_10_FMPOINT // (ɿ) WON ADD Ŵׯ԰ +#endif +#define _FIX_LEADER_ERR // (ɿ) WON ADD 峤 +#define _REMOVE_FM_LOG // (ɿ) WON ADD ƳҪļ LOG + +/* ------------------------------------------------------------------- + * רʯ6.0 + * Ա + * ˵ + */ +#define _SEND_EFFECT // (ɿ) WON ADD ѩЧ + +// ------------------------------------------------------------------- +#define _AC_SEND_FM_PK // (ɿ) WON ADD ׯ԰սбAC +#define _ACFMPK_LIST // (ɿ) ANDY ׯ԰սб +/* ------------------------------------------------------------------- + * רʯ7.0 + * Ա + * ˵ + */ + +#define _LOCK_ADD_NAME // LockNode λ(δ) +// ------------------------------------------------------------------- +#define _SLEEP_CHAR // Robin 2004/02/12 ԾǻԾֿ + +// Terry define start ------------------------------------------------------------------- +#define _FM_MODIFY // 幦޸ + +// Terry define end ------------------------------------------------------------------- + +#define _ANGEL_SUMMON // Robin ٻ + +//-------------------------------------------------------- +//by longzoro +#define _SASQL // ʯϿ +#ifdef _SASQL + #define _SQL_BACKGROUND //ҳ̨ ͬʱ_SASQL1 + #define _SQL_REGISTER //ԶעṦ ͬʱ_SASQL1 +#endif + +#if _ATTESTAION_ID != 11 +#define _LOGNZORO_FUNC_ALL // zoro +#endif +#ifdef _LOGNZORO_FUNC_ALL + #define _NEW_VIP_SHOP // Ա̵ + + #if _ATTESTAION_ID != 8 && _ATTESTAION_ID != 10 && _ATTESTAION_ID != 21 + #define _ITEM_PET_LOCKED // Ʒ + #endif + + #if _ATTESTAION_ID != 3 + #define _ONLINE_COST // ֵ߳ + #define _SQL_BUY_FUNC // SQL + #define _VIPPOINT_OLD_TO_NEW // Աת + #endif + + #if _ATTESTAION_ID == 5 + #define _FORMULATE_AUTO_PK // ƶԶPKϵͳ + #else + #define _OLDPS_TO_MD5PS // ѾɵתMD5 + #ifdef _NEW_VIP_SHOP + #if _ATTESTAION_ID != 3 + #define _COST_ITEM // ֵ + #endif + #endif + #if _ATTESTAION_ID != 21 + #define _AUTO_BACKUP // Զ + #endif + #define _FIX_CAHR_VERSION // 浵汾 + #if _ATTESTAION_ID != 38 && _ATTESTAION_ID != 49 + #if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 21 || _ATTESTAION_ID == 23 || _ATTESTAION_ID == 28 || _ATTESTAION_ID >= 30 + #define _LOTTERY_SYSTEM // Ʊϵͳ + #endif + #endif + #endif +#endif + +#if _ATTESTAION_ID != 5 && _ATTESTAION_ID != 11 + #define FAMILY_MAX_MEMBER 100 // +#else + #define FAMILY_MAX_MEMBER 50 // +#endif + +#if _ATTESTAION_ID != 11 + #define _CHARADATA_SAVE_SQL //дSQL +#endif +#if 1 + #define _ONE_SERVER // +#endif + +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 21 || _ATTESTAION_ID ==31 || _ATTESTAION_ID ==33 || _ATTESTAION_ID >=35 + #define _ALL_SERV_SEND // Ƶ +#endif +#if _ATTESTAION_ID == 1 || _ATTESTAION_ID == 2 || _ATTESTAION_ID == 3 || _ATTESTAION_ID == 21 || _ATTESTAION_ID ==31 || _ATTESTAION_ID ==33 || _ATTESTAION_ID ==35 || _ATTESTAION_ID >=42 + #if _ATTESTAION_ID != 43 && _ATTESTAION_ID != 47 && _ATTESTAION_ID != 49 + //#define _DEATH_FAMILY_LOGIN_CHECK //ɾ̫֮δ֮Ա + #endif +#endif + + +#if _ATTESTAION_ID == 1 + //#define _SET_FMPOINT + //#define _FAMILY_TOTEM + #define _NEWCLISETMAC + #define _FAMILY_PAY_POINT //ֵ +#endif + +#if _ATTESTAION_ID == 0 + #define _DEBUG +#endif + +#endif + + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/lock.c b/石器时代服务器端最新完整源代码/Serv/saac/lock.c new file mode 100644 index 0000000..15151b8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/lock.c @@ -0,0 +1,200 @@ +#include +#include +#include "lock.h" +#include "main.h" +#include "char.h" +#include "sasql.h" +LockNode **userlock; + +void Lock_Init(void) +{ + int i; + userlock= (LockNode **) calloc( 1, sizeof(LockNode *) * 256); + memset(userlock, 0, sizeof(userlock)); + for (i=0; i<256; i++) { + userlock[i] = (LockNode *)calloc( 1,sizeof(LockNode)); + userlock[i]->use=0; + userlock[i]->next=NULL; + userlock[i]->prev=NULL; + memset( userlock[i]->cdkey, 0, sizeof( userlock[i]->cdkey) ); + memset( userlock[i]->server, 0, sizeof( userlock[i]->server) ); +#ifdef _LOCK_ADD_NAME + memset( userlock[i]->name, 0, sizeof( userlock[i]->name) ); +#endif + } + log("ʼ"); +} + +LockNode *Creat_newNodes( void) +{ + LockNode *newln=NULL; + newln = ( LockNode *)calloc( 1, sizeof( LockNode) ); + if( newln == NULL ){ + log( "err Can't calloc:%d lock nodes !!\n", sizeof(LockNode)); + return 0; + } + newln->use=0; + newln->next=NULL; + memset( newln->cdkey, 0, sizeof( newln->cdkey) ); + memset( newln->server, 0, sizeof( newln->server) ); +#ifdef _LOCK_ADD_NAME + memset( newln->name, 0, sizeof( newln->name) ); +#endif + return newln; +} + +#ifdef _LOCK_ADD_NAME +int InsertMemLock(int entry, char *cdkey,char *name, char *passwd, char *server, int process, char *deadline) +#else +int InsertMemLock(int entry, char *cdkey, char *passwd, char *server, int process, char *deadline) +#endif +{ + int j; + LockNode *ln = userlock[entry]; +#ifdef _LOCK_ADD_NAME + log("Ϸ:Ŀ¼:char/0x%x ˺:%s :%s :%s\n", entry, cdkey, name, server); +#else + log("Ϸ:Ŀ¼:%x ˺:%s :%s\n", entry, cdkey, server); +#endif + + while( (ln!=NULL) && (ln->use!=0)) ln=ln->next; + + if( ln == NULL ) { + LockNode *fhead=NULL; + LockNode *p = userlock[entry]; + log("Add more lock nodes.\n"); + while (p->next!=NULL) p=p->next; + fhead = p; + for( j=0; j<32; j++) { // allocate more nodes + if( (ln = Creat_newNodes() ) == NULL ) return 0; + ln->prev=p; + p->next=ln; + p=ln; + } + while( (fhead!=NULL) && (fhead->use!=0)) fhead=fhead->next; + ln = fhead; + } + + if( ln->use !=0 ) return 0; + ln->use = 1; + strcpy( ln->cdkey, cdkey); + strcpy( ln->server, server); +#ifdef _LOCK_ADD_NAME + strcpy( ln->name, name); +#endif + ln->process = process; +#ifdef _SASQL + sasql_online(cdkey,name,NULL,NULL,2); +#endif + return 1; +} + +int DeleteMemLock(int entry, char *cdkey, int *process) +{ + LockNode *ln = userlock[entry]; + + log("ɾڴϢ λ=%x ˺=%s ..", entry, cdkey); + + while (ln!=NULL) { + if( ln->use != 0) { + if( strcmp( ln->cdkey, cdkey ) == 0 ) break; + } + ln=ln->next; + } + if( ln != NULL ) { + ln->use=0; + memset( ln->cdkey, 0, sizeof( ln->cdkey) ); + memset( ln->server, 0, sizeof( ln->server) ); +#ifdef _LOCK_ADD_NAME + memset( ln->name, 0, sizeof( ln->name) ); +#endif + *process = ln->process; + log("ɾɹ\n"); +#ifdef _SQL_BACKGROUND + sasql_online(cdkey,NULL,NULL,NULL,0); +#endif + return 1; + } + log("ɾʧ!!\n"); + return 0; +} + +void DeleteMemLockServer(char *sname) +{ + int i; + LockNode *ln; + for (i=0; i<256; i++) { + ln = userlock[i]; + while (ln!=NULL) { + if (ln->use != 0) { + if( strcmp( ln->server, sname)==0) { + ln->use=0; + } + } + ln=ln->next; + } + } +} + +int isMemLocked(int entry, char *cdkey) +{ + LockNode *ln = userlock[entry]; + while (ln!=NULL) { + if (ln->use != 0) { + if (strcmp(ln->cdkey, cdkey)==0) { + if( !strcmp(ln->server, "ϵ")) + log(" ϵ "); + break; + } + } + ln=ln->next; + } + if (ln!=NULL) return 1; else return 0; +} + +int GetMemLockState(int entry, char *cdkey, char *result) +{ + LockNode *ln = userlock[entry]; + + while (ln!=NULL) { + if (ln->use != 0) { + if (strcmp(ln->cdkey, cdkey)==0) { + sprintf(result, "%s %s .",cdkey, ln->server); + return 1; + } + } + ln=ln->next; + } + sprintf(result, "%s ûб.", cdkey); + return 0; +} + +int GetMemLockServer(int entry, char *cdkey, char *result) +{ + LockNode *ln = userlock[entry]; + while (ln!=NULL) { + if (ln->use != 0) { + if (strcmp(ln->cdkey, cdkey)==0) { + strcpy(result, ln->server); + return 1; + } + } + ln=ln->next; + } + return 0; +} + +int LockNode_getGname( int entries, char *id, char *gname) +{ + LockNode *ln = userlock[entries]; + while (ln!=NULL) { + if (ln->use != 0) { + if( !strcmp(ln->cdkey, id) ){ + sprintf( gname,"%s", ln->server ); + return 1; + } + } + ln=ln->next; + } + return 0; +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/longzoro.h b/石器时代服务器端最新完整源代码/Serv/saac/longzoro.h new file mode 100644 index 0000000..9c1ccbb --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/longzoro.h @@ -0,0 +1 @@ +#define SERVER_VERSION "All Blue's Saserver 8.0 2016101021:36:06\n" diff --git a/石器时代服务器端最新完整源代码/Serv/saac/longzoro.sh b/石器时代服务器端最新完整源代码/Serv/saac/longzoro.sh new file mode 100644 index 0000000..4b214f8 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/longzoro.sh @@ -0,0 +1,4 @@ +#!/bin/sh +OUT=./longzoro.h +touch main.c +echo "#define SERVER_VERSION \"All Blue's Saserver 8.0 "$(date +%Y%m%d%H:%M:%S)"\n\"" > $OUT diff --git a/石器时代服务器端最新完整源代码/Serv/saac/mail.c b/石器时代服务器端最新完整源代码/Serv/saac/mail.c new file mode 100644 index 0000000..9265691 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/mail.c @@ -0,0 +1,497 @@ +#define _MAIL_C_ + +#include "main.h" +#include "mail.h" +#include "util.h" +#include "saacproto_serv.h" + +#include +#include +#include +#include +#include +#include + +typedef enum +{ + MS_NOUSE = 0, + MS_NEWMESSAGE, + MS_WAIT_ACK, +} MAILSTATE; + +#define TEXT_MAX 1024 +struct mail +{ + int use; + unsigned int id_charname_hash; + char id_to[USERID_MAX]; + char charname_to[CHARNAME_MAX]; + char id_from[USERID_MAX]; + char charname_from[CHARNAME_MAX]; + char text[TEXT_MAX]; + int option; + unsigned int message_id; + MAILSTATE state; + time_t recv_time; +}; + +struct mail *mailbuf; +int mailbufsize = 0; + + +static unsigned int +getNextMessageID(void) +{ + FILE *fp; + unsigned int i; + char filename[1024]; + char line[1000]; + snprintf( filename, sizeof( filename ), + "%s/mail_id" , maildir ); + fp = fopen( filename, "r" ); + if( fp == NULL ){ + fp = fopen( filename ,"w" ); + if( fp == NULL ){ + log( "ܴ %s ... ʹͬʼID," + " saac ͱû!(id:9999)\n", filename ); + return 9999; + } + fprintf( fp, "10000\n" ); + fclose(fp); + return 1000; + } + fgets( line, sizeof(line), fp); + i = strtoul( line, NULL, 10 ); + fclose(fp); + + fp = fopen( filename, "w" ); + if( fp == NULL ){ + log( "дµID %s ... ʹͬ!\n", filename ); + return i; + } + fprintf( fp, "%u", i+1 ); + fclose(fp); + + log( "ʼID:%u\n", i); + return i; +} + +static int reallocMailBuf( void ) +{ + struct mail *previous = mailbuf; + struct mail *newbuf; + int new_mailbufsize; + if( mailbufsize == 0 ){ + new_mailbufsize = 1; + } else { + new_mailbufsize = mailbufsize * 2; + } + + newbuf = ( struct mail * )calloc( 1, new_mailbufsize * + sizeof( struct mail )); + if( newbuf == NULL ){ + log( "ظʼ: ڼ!! ʼС:%d\n", + new_mailbufsize ); + return -1; + } + memset( newbuf, 0 , new_mailbufsize * sizeof( struct mail )); + if( previous ) memcpy( (char*)newbuf, (char*)previous, + mailbufsize * sizeof( struct mail )); + free( previous ); + mailbufsize = new_mailbufsize; + mailbuf = newbuf; + + log( "·ʼ: " + "ʼ:%d ɵַ:%x µַ:%x\n", + new_mailbufsize, (unsigned int)previous,(unsigned int)newbuf ); + return 0; +} + +static int mailbuf_finder = 0; +static int allocMail( int use_msgid, unsigned int msgid ) +{ + int i; + for(i=0;i + mailbuf[flush_index[j+1]].message_id ){ + int sw = flush_index[j]; + flush_index[j] = flush_index[j+1]; + flush_index[j+1] = sw; + log( "inverted %d and %d in %d \n", flush_index[j], + flush_index[j+1], j ); + } + } + } + + /* ˱˪ */ + for(i=0;i< flush_i; i++ ){ + /* flush flushë˪ƻױءةӡ + ƻ˪ľ */ + saacproto_Message_send( fd, + mailbuf[flush_index[i]].id_from, + mailbuf[flush_index[i]].charname_from, + mailbuf[flush_index[i]].id_to, + mailbuf[flush_index[i]].charname_to, + mailbuf[flush_index[i]].text, + mailbuf[flush_index[i]].option, + mailbuf[flush_index[i]].message_id ); + mailbuf[flush_index[i]].state = MS_WAIT_ACK; + log( "ʼID:%u\n", + mailbuf[flush_index[i]].message_id ); + } + // Nuke *1 + log( "ʼ: %d ʼ %s(%s)(%s)\n", c, id, charname ,chartime()); +} + +// Nuke start: To expire undelivered mail +#define MAIL_EXPIRE_TIME 3600 +void +expireMail() +{ + int i,c=0; + unsigned int h ; + char id_charname[1000]; + time_t now=time(NULL); + + /* 1Լflush ƥ˪ */ +#define MAX_FLUSH_MAIL 1024 + int flush_index[MAX_FLUSH_MAIL]; + int flush_i=0; + // Nuke +1 + log("ʼС:%d (%s)\n",mailbufsize,chartime()); + // Nuke *1 + for(i=0;(i= MAIL_EXPIRE_TIME)) { + log( "ϢID:%u ѹ\n", mailbuf[i].message_id ); + flush_index[flush_i++] = i; + c++; + } + } + + /* ˱˪ */ + for(i=0;i< flush_i; i++ ){ + + snprintf( id_charname, sizeof( id_charname), "%s_%s", + mailbuf[flush_index[i]].id_to, + mailbuf[flush_index[i]].charname_to ); + h = hashpjw( id_charname ) & 0xff ; + { + char savefile[1024]; + char childname[1000]; + snprintf( childname,sizeof(childname),"%u", + mailbuf[flush_index[i]].message_id ); + makeDirFilename( savefile, sizeof(savefile),maildir, + h, childname ); + if( unlink( savefile ) != 0 ){ + log( "failed to unlink %s: %s\n", + savefile, strerror(errno )); + } else { + log( "ʼ: ɾϷ " + "%u %s(%s) %s(%s)\n", + mailbuf[flush_index[i]].message_id, + mailbuf[flush_index[i]].id_from, + mailbuf[flush_index[i]].charname_from, + mailbuf[flush_index[i]].id_to, + mailbuf[flush_index[i]].charname_to ); + } + memset( &mailbuf[flush_index[i]], 0 , sizeof( mailbuf[0] )); + } + } + // Nuke *1 + log( "ʼ: %d Ϣ (%s)\n", c ,chartime()); +} + +int readMail( char *dir ) +{ + int i, read_count=0; + for( i=0; i<256; i++){ + char dirname[1000]; + DIR *d; + + snprintf(dirname, sizeof( dirname ), "%s/0x%x", dir, i ); + d = opendir(dirname); + if(d == NULL ){ + mkdir( dirname, 0755); + log(" %s\n", dirname); + continue; + } + while(1){ + struct dirent *de; + de = readdir( d ); + if( de == NULL )break; + if( de->d_name[0] != '.' ){ + char filename[1000]; + FILE *fp; + struct stat s; + snprintf( filename, sizeof( filename), + "%s/%s", dirname, de->d_name ); + if( stat( filename, &s ) < 0 ){ + continue; + } + if( !(s.st_mode & S_IFREG)) continue; + fp = fopen( filename, "r" ); + if( fp == NULL ){ + log( "ܴļ %s %s\n",filename,strerror(errno)); + continue; + } + { + char line[16384]; + char toid[1000] , fromid[1000]; + char tochar[CHARNAME_MAX*2+1]; + char fromchar[CHARNAME_MAX*2+1]; + char text[TEXT_MAX*2+1]; + int opt=0; + toid[0] = fromid[0] = tochar[0] = + fromchar[0] = text[0] = 0; + fgets( line, sizeof(line), fp ); + chop(line); + if( strncmp( TO_ID_HEAD , line, strlen(TO_ID_HEAD) )==0){ + snprintf( toid , sizeof( toid ),"%s", + line+strlen(TO_ID_HEAD )); + } + fgets( line, sizeof( line ), fp ); + chop(line); + if( strncmp( TO_CHAR_HEAD, line,strlen(TO_CHAR_HEAD))==0){ + snprintf( tochar, sizeof( tochar ), "%s", + line+strlen( TO_CHAR_HEAD )); + makeStringFromEscaped( tochar ); + } + fgets( line, sizeof( line ),fp ); + chop(line); + if( strncmp( FROM_ID_HEAD,line,strlen(FROM_ID_HEAD))==0){ + snprintf( fromid, sizeof( fromid ),"%s", + line + strlen( FROM_ID_HEAD )); + } + fgets( line,sizeof(line),fp); + chop(line); + if(strncmp(FROM_CHAR_HEAD,line,strlen(FROM_CHAR_HEAD))==0){ + snprintf( fromchar, sizeof( fromchar ), + line + strlen(FROM_CHAR_HEAD )); + makeStringFromEscaped( fromchar ); + } + fgets( line,sizeof(line),fp); + chop(line); + if( strncmp( OPTION_HEAD,line, strlen(OPTION_HEAD))==0){ + opt = atoi( line + strlen( OPTION_HEAD ) ); + } + fgets( line, sizeof( line),fp); + chop(line); + if( strncmp(TEXT_HEAD,line,strlen(TEXT_HEAD))==0){ + snprintf( text, sizeof( text), "%s", + line + strlen( TEXT_HEAD )); + makeStringFromEscaped( text ); + } + if( toid[0] == 0 || fromid[0] == 0 || + tochar[0] == 0 || fromchar[0] == 0 || + text[0] == 0 ){ + log( "ʼ! %s ID[%c] [%c]" + " ID[%c] [%c] ı[%c]\n", + filename, + toid[0], tochar[0], fromid[0], fromchar[0], + text[0] ); + // Nuke +1 1027: Close for safe + fclose(fp); + continue; + } + receiveMail( fromid, fromchar, + toid, tochar, + text, opt , 1, + strtoul(de->d_name,NULL,10)); + read_count++; + } + fclose(fp); + + } + } + closedir(d); + } + log( "ȡʼ: '%s'Ŀ¼ȡ %d ʼ \n", dir, read_count ); + return 0; +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/main.c b/石器时代服务器端最新完整源代码/Serv/saac/main.c new file mode 100644 index 0000000..5977498 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/main.c @@ -0,0 +1,1936 @@ +#define _MAIN_C_ + +#include "main.h" +#include "util.h" +#include "mail.h" +#include "db.h" +#include "saacproto_util.h" +#include "saacproto_serv.h" +// CoolFish: Family 2001/5/9 +#include "acfamily.h" +#include "version.h" +#ifdef _SEND_EFFECT // WON ADD ѩЧ +#include "recv.h" +#endif +#include "md5.h" +#include "char.h" +#include "attestation.h" +#ifdef _SASQL +#include "sasql.h" +#endif +#include "longzoro.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lock.h" + + + +#define BACKLOGNUM 5 + +int worksockfd; + +static int findregBlankMemBuf( void ); +static int unregMemBuf( int index ); +static int findregBlankCon( void ); +static int getFreeMem( void ); + +static int appendReadBuffer( int index, char *data, int len ); +static int appendWriteBuffer( int index , char *data, int len ); +static int appendMemBufList( int top, char *data, int len ); +static int consumeMemBufList( int top, char *out, int len, int flag, int copyflag ); +static int getLineReadBuffer( int index, char *buf, int len ); + +void logerr(char *token); + +struct membuf +{ + int use; + char buf[512]; +// char buf[1024*128]; + int len; + int next; +}; + +struct connection +{ + int use; + int fd; + int mbtop_ri; + int mbtop_wi; + struct sockaddr_in remoteaddr; + int closed_by_remote; +}; + +struct membuf *mb; +int mbsize; +int mbuse ; + +int cpuuse; + + +int mainsockfd; /* accept ¦ѱľ */ +struct sockaddr_in localaddr; /* bind ʧ */ + + +struct connection *con; /* */ + +static int mb_finder=0; /* mbë׻ + ʢ */ +// WON FIX +//char tmpbuf[65536]; +char tmpbuf[1024*1024]; +//char tmpbuf[65536*3]; /* read */ + +struct timeval select_timeout; + +time_t sys_time =0; // Robin add + +extern gmsv gs[MAXCONNECTION]; + +int tcpstruct_init( char *addr, int port, int timeout_ms, int mem_use, int deb); +int tcpstruct_accept1( void ); +int tcpstruct_accept( int *tis , int ticount ); +int tcpstruct_close( int ti ); +int tcpstruct_read( int ti , char *buf , int len ); +int tcpstruct_readline( int ti , char *buf , int len ,int k ,int r); +int tcpstruct_readline_chop( int ti , char *buf, int len ); +int tcpstruct_write( int ti , char *buf , int len ); +int tcpstruct_countmbuse( void ); +int tcpstruct_connect( char *addr , int port ); +void set_nodelay( int sock ); + + +#define OK 0 /* */ +#define TCPSTRUCT_ENOMEM -1 /* malloc */ +#define TCPSTRUCT_ESOCK -2 /* socket */ +#define TCPSTRUCT_EBIND -3 /* bind */ +#define TCPSTRUCT_ELISTEN -4 /* listen */ +#define TCPSTRUCT_EBUG -6 /* ƥؤ */ +#define TCPSTRUCT_EINVCIND -7 /* con߼indexƾз */ +#define TCPSTRUCT_EREADFIN -8 /* read ·ئʻ closed by remote */ +#define TCPSTRUCT_EHOST -9 /* gethostbyname */ +#define TCPSTRUCT_ECONNECT -10 /* connect */ +#define TCPSTRUCT_ECFULL -11 /* con */ +#define TCPSTRUCT_ETOOLONG -12 /* 滥ئʿ */ +#define TCPSTRUCT_EMBFULL -13 /* mb */ +#define TCPSTRUCT_ECLOSEAGAIN -14 /* close 2Խľ */ + + +int port; /* ءةӡƻº̡ */ +int Total_Charlist; +int Expired_mail; +int Del_Family_or_Member; +int Write_Family; +#ifdef _IP_VIP +char myip[5][32]; +#endif +#ifdef _SAVE_ZIP +int SAVEZIP = 0; +void savezipfile( void); +#endif +// Nuke start +char *chartime() +{ + static char buf[80]; + time_t t; + t=time(0); + strcpy(buf,ctime(&t)); + buf[strlen(buf)-1]=0; + return(buf); +} +#ifdef _ANGEL_SUMMON +extern struct MissionTable missiontable[MAXMISSIONTABLE]; +static int initMissionTable( void ); +int saveMissionTable( void ); +void checkMissionTimelimit( void); +#endif + +/* + sigaction + */ + +void sighandle( int a ) +{ + if (a==SIGUSR1) log("sigusr1ź!\n"); + log("õһź! 쳣ж......\n" ); + writeFamily(familydir); + writeFMPoint(fmpointdir); + writeFMSMemo(fmsmemodir); +#ifdef _ANGEL_SUMMON + saveMissionTable(); +#endif + exit(1); +} + +// Arminius 7.20 memory unlock +void sigusr1(int a) +{ + int i; + FILE *f; + char key[4096],buf[4096]; + + signal(SIGUSR1, sigusr1); + + f = fopen("./unlock.arg", "r"); + + if (f) { + memset(key, 0, 4096); + fread(key, 4096, 1, f); + for (i=0; i ./sigusr1.result", buf); + system(key); + break; +#ifdef _SEND_EFFECT // WON ADD ѩЧ + case 'E': + log("\nAC GS ѩЧ!!\n"); + SendEffect(&key[1]); + break; +#endif + + case 'L': // Robin гServer + log("\nList All Server Conncet!!!!!\n"); + for( i =0; i 0){ + log( "ͬIPͬʱ½:%d\n",sameipmun ); + }else{ + log( "ͬIPͬʱ½:\n" ); + } + } else if( strcmp( command , "CPUUSE" ) == 0 ){ + cpuuse = atoi( param ); + log( "CPUʹƵ:%d\n",cpuuse ); + } +#ifdef _OLDPS_TO_MD5PS + else if( strcmp( command , "USEMD5" ) == 0 ){ + usemd5 = atoi( param ); + log( "ǷʹMD5룺%d\n",usemd5 ); + } +#endif +#ifdef _AUTO_BACKUP + else if( strcmp( command , "AUTOBACKUPDAY" ) == 0 ){ + autobackupday = atoi( param ); + log( "ÿ%d챸һݣ\n",autobackupday ); + }else if( strcmp( command , "AUTOBACKUPHOUR" ) == 0 ){ + autobackuphour = atoi( param ); + log( "ÿ%dбݣ\n",autobackuphour ); + } +#endif +#ifdef _LOTTERY_SYSTEM + else if( strcmp( command , "LOTTERYSYSTEM" ) == 0 ){ + lotterysystem = atoi( param ); + log( "ÿ%d쿪һν\n",lotterysystem ); + } +#endif +#ifdef _SAVE_ZIP + else if( strcmp( command , "savezip" ) == 0 ){ + SAVEZIP = atoi(param); + log( "ǷԶ:%s\n",SAVEZIP>0?"":""); + } +#endif + else if( strcmp( command , "servid" ) == 0 ){ + servid = atoi( param ); + log( "ID\n", servid ); + } + } + + fclose(fp); + return 0; +} + + +static void parseOpts( int argc, char **argv ) +{ + int c , option_index; + + while(1){ + static struct option long_options[] = { + {"nice" , 1 , 0 , 'n'}, + {"buy" , 0 , 0 , 'b'}, + {"cost" , 0 , 0 , 'c'}, + {"help" , 0 , 0 , 'h' }, + {"userinfo",0 , 0 , 'i'}, + {"lockuser",0 , 0 , 'l'}, + {"transmd5",0 , 0 , 'm'}, + {"del" , 0 , 0 , 'd'}, + {"trans" , 0 , 0 , 't'} + }; + c = getopt_long( argc , argv , "n:bchilmdt" , long_options , &option_index ); + if( c == -1 )break; + switch( c ){ + case 'h': + fprintf( stderr , + "ʹ÷: saac [-h] [-w port] [-w port] ... \n" + "-h : ʾsaacİ\n" + "-w port : һվ̶˿\n" + "Copyright 2006 zoro " + "( Longzoro System Supply )\n"); + exit(0); + break; + case 'i': + { + int i; + char buf[256]="9088"; + int len=strlen(buf); + char crypto_key[]={"aBcDeFgHiJkLmNoPqRsTuVwXyZ"}; + for(i=0;i= 2){ + int gold; + printf("Ҫʯҵֵ"); + scanf("%d", &gold); + sprintf(coststr, "%d", gold); + } + + printf("Ҫijֵ"); + scanf("%d", &num); + + sasql_init(); + sasql_OnlineBuy_add(coststr, type, num); + sasql_close(); +} +#endif + exit(0); + break; + case 'c': +#ifdef _ONLINE_COST +{ + int cost = 0,num = 0,point = 0; + printf("Ҫijֵֵ"); + scanf("%d", &cost); + + printf("Ҫijֵ"); + scanf("%d", &num); + + printf("Ҫijֵ֣"); + scanf("%d", &point); + + sasql_init(); + sasql_OnlineCost_add(cost, num, point); + sasql_close(); +} +#endif + exit(0); + break; + case 'm': +#ifdef _OLDPS_TO_MD5PS + sasql_init(); + sasql_OldpsToMd5ps(); + sasql_close(); +#endif + exit(0); + break; + case 't': + { + sasql_init(); + sasql_TransOnlineCost(); + sasql_close(); + exit(0); + break; + } + case 'd': + { + int date; + printf("ʱ:"); + scanf("%d", &date); + + sasql_init(); + if(date >= 0){ + sasql_CleanCdkey(date); + }else{ + sasql_CleanLockCdkey(); + } + sasql_close(); + exit(0); + } + break; + case 'n': + nice(atoi( optarg )); + break; + default: + log( "ܶѡ %c\n" , c ); + exit(0); + } + } +} +double time_diff(struct timeval subtrahend, struct timeval subtractor); + + +int passwd = 0; + + +void dump() +{ + void *array[10]; + size_t size; + char **strings; + size_t i; + + size = backtrace (array, 10); + strings = backtrace_symbols (array, size); + + printf ("Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++){ + logerr(strings[i]); + printf ("\n"); + } + + free (strings); + +} + +void sigshutdown( int number) +{ + char buff[256]; + + if( number == 0 ){ + printf( "\n\n\nGMSVر\n" ); + }else if( number == 2 ){ + printf( "\n\n\nGMSVCTRL+Cֶж\n" ); + }else{ + sprintf( buff, "Ҫ󣬱ύĴ\n"); + logerr(buff); + dump(); + } + + signal(SIGINT , SIG_IGN ); + signal(SIGQUIT, SIG_IGN ); + signal(SIGILL, SIG_IGN ); + signal(SIGTRAP, SIG_IGN ); + signal(SIGIOT, SIG_IGN ); + signal(SIGBUS, SIG_IGN ); + signal(SIGFPE, SIG_IGN ); + signal(SIGKILL, SIG_IGN ); + signal(SIGSEGV, SIG_IGN ); + signal(SIGPIPE, SIG_IGN ); + signal(SIGTERM, SIG_IGN ); + + log("õһź! 쳣ж......\n" ); + writeFamily(familydir); + writeFMPoint(fmpointdir); + writeFMSMemo(fmsmemodir); +#ifdef _ANGEL_SUMMON + saveMissionTable(); +#endif + exit(1); +} + + + +void signalset( void ) +{ + // CoolFish: Test Signal 2001/10/26 + printf("\nʼȡź..\n"); + + printf("SIGINT:%d\n", SIGINT); + printf("SIGQUIT:%d\n", SIGQUIT); + printf("SIGFPE:%d\n", SIGILL); + printf("SIGTRAP:%d\n", SIGTRAP); + printf("SIGIOT:%d\n", SIGIOT); + printf("SIGBUS:%d\n", SIGBUS); + printf("SIGFPE:%d\n", SIGFPE); + printf("SIGKILL:%d\n", SIGKILL); + printf("SIGSEGV:%d\n", SIGSEGV); + printf("SIGPIPE:%d\n", SIGPIPE); + printf("SIGTERM:%d\n", SIGTERM); + + signal( SIGINT , sigshutdown ); + signal( SIGQUIT, sigshutdown ); + signal( SIGILL, sigshutdown ); + signal( SIGTRAP, sigshutdown ); + signal( SIGIOT, sigshutdown ); + signal( SIGBUS, sigshutdown ); + signal( SIGFPE, sigshutdown ); + signal( SIGKILL, sigshutdown ); + signal( SIGSEGV, sigshutdown ); + signal( SIGPIPE, SIG_IGN ); + signal( SIGTERM, sigshutdown ); +} + + +int main( int argc , char **argv ) +{ +/* + #define cpuid(in,a,b,c,d)\ + asm("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in)); + unsigned long eax,ebx,ecx,edx; + cpuid(0,eax,ebx,ecx,edx); + printf("%08x %08lx %08lx %08lx %08lx\n",0,eax,ebx,ecx,edx); +*/ + + srand((int)time(0)); + parseOpts( argc, argv ); + signalset(); + // Nuke +1 1012: Loop counter + int counter1 = 0; + + int counter2 = 0; + + int counter3 = 0; + + int counter4 = 0; + + int counter5 = 0; + + int counter6 = 0; + //signal(SIGUSR1, sigusr1); + + log_rotate_interval = 3600 * 24 * 7; + + Lock_Init(); // Arminius 7.17 memory lock + + UNlockM_Init(); + + if(readConfig( "acserv.cf" )<0){ + log( "޷ڵǰĿ¼ȡ acserv.cf .\n" ); + exit(1); + } + +#ifdef _SASQL + if(sasql_init()==FALSE){ + exit(1); + } +#ifdef _SQL_BACKGROUND + sasql_online(NULL,NULL,NULL,NULL,3); +#endif +#endif + log( "ȡĿ¼\n" ); + dbRead( dbdir ); +#ifdef _FAMILY + log("ȡ ׯ԰\n"); + readFMSMemo(fmsmemodir); + log("ȡ \n"); + readFMPoint(fmpointdir); + log("ȡ Ŀ¼\n"); + readFamily(familydir); +#endif + log( "׼ Ŀ¼\n" ); + prepareDirectories( chardir ); + log( "׼ ־Ŀ¼\n" ); + prepareDirectories( logdir ); + log( "׼ ʼĿ¼\n" ); + prepareDirectories( maildir ); + +#ifdef _SLEEP_CHAR + prepareDirectories( sleepchardir ); + log( "׼ ˯ߵĿ¼\n" ); +#endif + + /* Ȼ¶ë ij */ + if( readMail(maildir) < 0 ){ + log( "ܳʼʼ\n" ); + exit(1); + } + /* TCPSTRUCT ë */ + while( 1 ){ + int tcpr; + if( ( tcpr = tcpstruct_init( NULL , port , 0 , + CHARDATASIZE * 16 * MAXCONNECTION , 1 /* DEBUG */ ) ) < 0 ){ + log( "ܼTCP˿ڣ: %d, Ե...\n", tcpr ); + sleep( 10 ); + }else{ + break; + } + } + saacproto_InitServer( netWrite , CHARDATASIZE ); +/* + { + struct sigaction s,os; + + bzero( &s, sizeof(s)); + s.sa_handler = sighandle; + s.sa_flags = SA_NOMASK; + sigaction( SIGTERM, &s, &os ); + + bzero( &s, sizeof(s)); + s.sa_handler = sighandle; + s.sa_flags = SA_NOMASK; + sigaction( SIGINT, &s, &os ); + + bzero( &s, sizeof( s )); + s.sa_handler = SIG_IGN; + s.sa_flags = SA_NOMASK; + sigaction( SIGPIPE, &s, &os ); + + } +*/ +#ifdef _AC_SEND_FM_PK // WON ADD ׯ԰սбAC + load_fm_pk_list(); +#endif + +#ifdef _ACFMPK_LIST + FMPK_LoadList(); +#endif +#ifdef _ALLDOMAN + LOAD_herolist(); // Syu ADD аNPC +#endif + +#ifdef _ANGEL_SUMMON + initMissionTable(); +#endif + + log( "\n˰汾: <%s>\n" , SERVER_VERSION ); + + printf( "ע: AllBlue'sڴ˵.ǷѷˡϽҵ;\n" ); + + log( "\nʼ...\n" ); + + // signal(SIGUSR1,sigusr1); // Arminius 7.20 memory lock + + int itime=0; + while(1){ + + int newti,i; + static time_t main_loop_time; + + sys_time = time(NULL); + + + +#ifdef _LOTTERY_SYSTEM +char todayaward[256]="-1,-1,-1,-1,-1,-1,-1"; +{ + if(lotterysystem>0){ + struct tm *p; + p=localtime(&sys_time); /*ȡõʱ*/ + static BOOL lottery = FALSE; + if( lottery == FALSE){ + if((p->tm_mday % lotterysystem) == 0){ + if(p->tm_hour == 0){ + int award[7]; + int i,j; + for(i=0;i<7;i++){ + award[i]=rand() % 36+1; + for(j=0;jtm_hour != 0){ + lottery = FALSE; + } + } + } +} +#endif + + if( main_loop_time != sys_time){ + main_loop_time = time(NULL); + counter1++; + counter2++; + counter3++; + counter4++; + counter5++; + counter6++; + if( counter6 > 600 ) // 300( -> 60) + { + readConfig( "acserv.cf" ); + counter6 = 0; + } + //andy add 2002/06/20 + UNlockM_UnlockPlayer(); + +#ifdef _ANGEL_SUMMON + checkMissionTimelimit(); +#endif + // Nuke *1 1012 + if( counter1 > Total_Charlist ){ + counter1=0; + char *c = ctime( &main_loop_time ); + if( c ){ + struct timeval st,et; + log( "\nTIME:%s\n",c ); + gettimeofday( &st,NULL); + dbFlush(dbdir); + gettimeofday( &et,NULL); + log( "Flushed db(%fsec)\n", time_diff(et,st) ); + log( ":%d NG:%d\n", + total_ok_charlist, total_ng_charlist ); + } + } + // Nuke **1 1012 + //if( ( counter % 600 ) == 0 ){ + if( counter2 > Expired_mail ){ + counter2=0; + struct timeval st,et; + gettimeofday( &st,NULL); + expireMail(); + gettimeofday( &et,NULL); + log( "ʼ(%fsec)\n", time_diff(et,st) ); + } +#ifdef _FAMILY +#ifdef _DEATH_FAMILY_LOGIN_CHECK + //if ((counter % 300) == 0) // 300( -> 60) + if ((counter4 % 1800) == 0) // 3hr( -> 1min) + { + counter4=0; + struct timeval st, et; + time_t t1; + gettimeofday(&st, NULL); + time(&t1); + delovertimeFMMem(t1); + gettimeofday(&et, NULL); + log("Del Family or Member (%fsec)\n", time_diff(et, st)); + } +#endif + if( counter5 > Write_Family ) // 300( -> 60) + { + counter5=0; + struct timeval st, et; + gettimeofday(&st, NULL); + writeFamily(familydir); + writeFMPoint(fmpointdir); + writeFMSMemo(fmsmemodir); + gettimeofday(&et, NULL); + log("¼(%fsec)\n", time_diff(et, st)); + } +#endif + } + + newti = tcpstruct_accept1(); + if( newti >= 0 ){ + log( "ͬ: %d\n" , newti ); + gs[newti].use = 1; + } + + for(i=0;i 0 ){ + char debugfun[256]; + buf[l]=0; + if( saacproto_ServerDispatchMessage( i , buf, debugfun)<0){ + printf("buf:%s;%d\n", buf, strlen(buf)); + char token[256]; + char tmp[256]; + struct tm now; + time_t timep; + time(&timep); + memcpy(&now, localtime(&timep), sizeof(now)); + + sprintf(tmp, "%02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); + + sprintf(token, "[%s]GMSV(%s) Ϣ:%s\n", tmp, gs[i].name, debugfun); + logerr(token); + // Nuke start + //if(strlen(debugfun)>0){ + //logout_game_server(i);// avoid the shutdown the gmsv ttom + //} + } + } else if( l == TCPSTRUCT_ETOOLONG ){ + char token[256]; + sprintf(token, "ܳ:%d :%s\n", i , gs[i].name ); + logerr(token); + logout_game_server( i ); + } else if( l < 0 ){ + log( "ر:%d :%s\n", i , gs[i].name ); + logout_game_server(i); + } else if( l == 0 ){ + ; + } + } + } + } + + return 0; +} +double +time_diff(struct timeval subtrahend, + struct timeval subtractor) +{ + return( (subtrahend.tv_sec - subtractor.tv_sec) + + (subtrahend.tv_usec + - subtractor.tv_usec ) / (double)1E6 ); +} + + +/* + 뼰 ë £ + ئԪ弰ּͻ̻ﻥئԪئ·£ + + 𼰿 ٯ覻ئ» ƥ̼ë ƻ + ᨷ֣ + + */ +int get_rotate_count(void ) +{ + int a; + unsigned int t = (unsigned int ) time(NULL); + + a = ( t / log_rotate_interval ) * log_rotate_interval; + + return a; +} + +int tcpstruct_init( char *addr , int p , int timeout_ms , int mem_use , int db ) +{ + mbsize = mem_use / sizeof( struct membuf ); + mbuse =0; + mb_finder = 0; + mb = ( struct membuf * ) calloc( 1, mbsize * sizeof(struct membuf )); + + if( mb == NULL ) return TCPSTRUCT_ENOMEM; + bzero( mb , mbsize * sizeof( struct membuf )); + + con = ( struct connection *) calloc( 1, MAXCONNECTION * sizeof( struct connection )); + if( con == NULL ){ + free( mb ); + return TCPSTRUCT_ENOMEM; + } else { + int i; + for(i=0;i= 0 && con[i].closed_by_remote ==0 ){ + FD_SET( con[i].fd , & rfds ); + FD_SET( con[i].fd , & wfds ); + FD_SET( con[i].fd , & efds ); + + int j = 1,k; + + if( (float)(((float)getFreeMem()/(CHARDATASIZE * 16 * MAXCONNECTION))) > 0.10 ){ + t = select_timeout; + sret = select( con[i].fd+1, & rfds , (fd_set*)NULL, & efds , &t); + if( sret > 0 ) { + if( ( con[i].fd >= 0 ) && FD_ISSET( con[i].fd , &rfds ) ){ + int fr = getFreeMem(); + int rr , readsize ; + if( fr <= 0 ) continue; + memset( tmpbuf, 0, sizeof( tmpbuf)); + if( fr > sizeof(tmpbuf ) ){ + readsize = sizeof( tmpbuf); + } else { + readsize = fr - 1; + } + rr = read( con[i].fd , tmpbuf , readsize ); + if( rr <= 0 ){ + con[i].closed_by_remote = 1; + } else { + appendReadBuffer( i , tmpbuf , rr ); +#ifdef _DEBUG + printf("ȡ:%s\n",tmpbuf); +#endif + } + } + } + + if( (float)(((float)getFreeMem()/(CHARDATASIZE * 16 * MAXCONNECTION))) > 0.50 ){ + j = 2; + }else if( (float)(((float)getFreeMem()/(CHARDATASIZE * 16 * MAXCONNECTION))) > 0.40 ){ + j = 3; + }else if( (float)(((float)getFreeMem()/(CHARDATASIZE * 16 * MAXCONNECTION))) > 0.30 ){ + j = 4; + }else if( (float)(((float)getFreeMem()/(CHARDATASIZE * 16 * MAXCONNECTION))) > 0.20 ){ + j = 5; + } + } + + for(k=0; k < j; k++){ + t = select_timeout; + sret = select( con[i].fd+1, (fd_set*)NULL, &wfds, (fd_set*)NULL , &t); + if( sret > 0 ) { + if( ( con[i].fd >= 0 ) && FD_ISSET( con[i].fd , &wfds )){ + char send_buf[4096]; + memset( send_buf, 0, sizeof( send_buf)); + int l = consumeMemBufList( con[i].mbtop_wi ,send_buf, sizeof(send_buf),0 , 1 ); + if(l>0){ + int rr = write( con[i].fd , send_buf , l ); + if( rr < 0 ){ + con[i].closed_by_remote = 1; + } else { +#ifdef _DEBUG + printf(":%s\n",send_buf); +#endif + consumeMemBufList( con[i].mbtop_wi , send_buf, l, 1 , 0 ); + } + } + } + } + } + } + } + + for( i=0; i0 to avoid signal interrupt in select + if( (asret>0) && FD_ISSET( mainsockfd , & rfds )){ + struct sockaddr_in c; + int len , newsockfd; + int newcon; + bzero( &c , sizeof( c )); + len = sizeof( c ); + fprintf( stderr, "i can accept " ); + newcon = findregBlankCon( ); + if( newcon < 0 ) continue; + newsockfd = accept( mainsockfd, (struct sockaddr*)&c , &len ); +#ifdef _IP_VIP + char tempIp[20]; + strcpy(tempIp,inet_ntoa(c.sin_addr)); + for (k=0;k<5;k++) + { + if (strcmp( tempIp, myip[i]) != 0) { + num++; + } + } + if(num >= 5){ + log( "ܾ: %d IP:[%s] ûеǼ\n" , newsockfd ,tempIp); + tcpstruct_close(mainsockfd); + continue; + } + log( ": %d IP:[%s]\n" , newsockfd ,tempIp); +#else + log( ": %d\n" , newsockfd); +#endif + if( newsockfd < 0 ){ + unregMemBuf( newcon ); + continue; + } + set_nodelay( newsockfd ); + con[newcon].fd = newsockfd; + memcpy( &con[newcon].remoteaddr , &c ,sizeof(c)); + tis[accepted] = newcon; + accepted ++; + } + } + return accepted; +} + +int tcpstruct_close( int ti ) +{ + + if( ti < 0 || ti >= MAXCONNECTION )return TCPSTRUCT_EINVCIND; + if( con[ti].use == 0 ){ + return TCPSTRUCT_ECLOSEAGAIN; + } + close( con[ti].fd ); + con[ti].use = 0; + con[ti].fd = -1; + + /* ëȻ ëʧ */ + consumeMemBufList( con[ti].mbtop_ri , NULL, + mbsize * sizeof( mb[0].buf ), 1, 0 ); + consumeMemBufList( con[ti].mbtop_wi , NULL, + mbsize * sizeof( mb[0].buf ), 1, 0 ); + + unregMemBuf( con[ti].mbtop_ri ); + unregMemBuf( con[ti].mbtop_wi ); + con[ti].mbtop_ri = -1; + con[ti].mbtop_wi = -1; + return OK; +} + +/* + ijֵּئʻƾ remoteclose -1 ë + + */ +int tcpstruct_read( int ti , char *buf , int len ) +{ + int l; + + if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) + return TCPSTRUCT_EINVCIND; + l = consumeMemBufList( con[ti].mbtop_ri , buf , len , 1 , 1); + if( l == 0 && con[ti].closed_by_remote ) return TCPSTRUCT_EREADFIN; + + return l; +} + +/* + 1ëij + int kend : 1ئյ \n ëڽ + int kend_r : 1ئյ \r ڽ(ؤľ) + + ijֵּئʻ remote closed -1ë + // Nuke + Read 1 line + if kend==1 then delete \n at the tail + if kend_r== 1 then delete \r at the tail (if any) + if no data read, it means 'remote closed' then return -1 + */ +int tcpstruct_readline( int ti , char *buf , int len , int kend , int kend_r ) +{ + int l; + int minus = 0; + + if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) + return TCPSTRUCT_EINVCIND; + + l = getLineReadBuffer( ti , buf , len ); + if( l == 0 ){ + if( con[ti].closed_by_remote ){ + return TCPSTRUCT_EREADFIN; + } else { + return 0; + } + } + + if( kend ){ + if( buf[l-1]=='\n' ){ + buf[l-1] = 0; minus =-1; + } + } + if( kend_r ){ + if( buf[l-1]=='\r' ){ + buf[l-1] = 0; minus = -1; + } + if( buf[l-2]=='\r' ){ + buf[l-2] = 0; minus = -2; + } + } + return l + minus; +} +int tcpstruct_readline_chop( int ti , char *buf, int len ) +{ + return tcpstruct_readline( ti , buf , len , 1,1); +} + +int tcpstruct_write( int ti , char *buf , int len ) +{ + if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) + return TCPSTRUCT_EINVCIND; + return appendWriteBuffer( ti , buf , len ); +} + +int tcpstruct_connect( char *addr , int port ) +{ + int newti ; + int s, r; + struct sockaddr_in svaddr; + struct hostent *he; + + s = socket( AF_INET, SOCK_STREAM , 0 ); + if(s<0)return -2; + + bzero( &svaddr , sizeof( svaddr )); + svaddr.sin_family = AF_INET; + svaddr.sin_port = htons( port ); + + if( inet_aton( addr, &svaddr.sin_addr ) == 0 ){ + he = gethostbyname( addr ); + if( he == NULL ){ + return TCPSTRUCT_EHOST; + } + memcpy( & svaddr.sin_addr.s_addr , he->h_addr , + sizeof( struct in_addr)); + } + r = connect( s , ( struct sockaddr*)&svaddr,sizeof(svaddr)); + if( r < 0 ){ + return TCPSTRUCT_ECONNECT; + } + set_nodelay( s ); + newti = findregBlankCon( ); + if( newti < 0 ){ + fprintf( stderr , "ʧ: newti:%d\n", newti ); + return TCPSTRUCT_ECFULL; + } + con[newti].fd = s; + memcpy( & con[newti].remoteaddr , &svaddr , + sizeof( struct sockaddr_in)); + return newti; +} + +static int appendReadBuffer( int index , char *data , int len ) +{ + int top; + + top = con[index].mbtop_ri; + for(;;){ + int nextind = mb[top].next; + + if( nextind == -1 ) break; + top = nextind; + } + return appendMemBufList( top , data , len ); +} + +static int appendWriteBuffer( int index , char *data , int len ) +{ + int top; + top = con[index].mbtop_wi; + for(;;){ + int nextind = mb[top].next; + if( nextind == -1 ) break; + top = nextind; + } + return appendMemBufList( top , data , len ); +} +static int appendMemBufList( int top , char *data , int len ) +{ + int fr = getFreeMem( ); + int rest = len; + int data_topaddr = 0; + + if( len >= fr ){ +/* + FILE *fp; + if( (fp=fopen( "badsysinfo.txt", "a+")) != NULL ){ + fprintf( fp, "appendMemBufList() len:%d / fr:%d err !! \n", len, fr); + fclose( fp); + } +*/ + //andy_log + log( "appendMemBufList() len:%d / fr:%d err !! \n", len, fr); + return -1; + } + data[len] = 0; + for(;;){ + int blanksize = sizeof( mb[0].buf ) - mb[top].len; + int cpsize = ( rest <= blanksize ) ? rest : blanksize; + memcpy( mb[top].buf + mb[top].len , + data + data_topaddr , cpsize ); + mb[top].len += cpsize; + if( rest <= blanksize ){ + return len; + } else { + int newmb; + rest -= cpsize; + data_topaddr += cpsize; + if( (newmb = findregBlankMemBuf( ) ) == TCPSTRUCT_EMBFULL ){ + FILE *fp; + if( (fp=fopen( "badsysinfo.txt", "a+")) != NULL ){ + fprintf( fp, "find newmb == TCPSTRUCT_EMBFULL err data:%s !!\n", data); + fclose( fp); + } + log( "find newmb == TCPSTRUCT_EMBFULL err data:%s !!\n", data); + } + mb[top].next = newmb; + top = mb[top].next; + } + } + return TCPSTRUCT_EBUG; +} + +static int consumeMemBufList( int top , char *out , int len , + int consumeflag , int copyflag ) +{ + int total = 0; + int top_store = top; + for(;;){ + int cpsize; + if( top == -1 ) break; + cpsize = ( mb[top].len <= ( len - total) ) ? + mb[top].len : ( len - total ); + + if( copyflag ) memcpy( out + total , mb[top].buf , cpsize ); + total += cpsize; + + if( consumeflag ){ + mb[top].len -= cpsize; + if( mb[top].len > 0 ){ + /* зƻئмƥmemmove */ + memmove( mb[top].buf , mb[top].buf + cpsize , + sizeof( mb[top].buf ) - cpsize ); + } + } + top = mb[top].next; + if( total == len ){ + break; + } + } + + if( consumeflag ){ + /* ئ0ئȻئݩ ƥ ټ֧ݩ ئ */ + top = mb[top_store].next; + for(;;){ + if( top == -1 )break; + if( mb[top].len == 0 ){ + int prev; + mb[top_store].next = mb[top].next; + prev = top; + top = mb[top].next; + unregMemBuf( prev ); + } else { + top = mb[top].next; + } + } + } + + return total; +} + +static int getLineReadBuffer( int index , char *buf, int len ) +{ + + int top = con[index].mbtop_ri; + int ti = 0 , breakflag = 0; + + for(;;){ + int i; + int l = mb[top].len; + if( top == -1 )break; + for( i=0 ; i < l ; i++){ + if( mb[top].buf[i] == '\n' ){ + breakflag = 1; + break; + } + ti ++; + } + if( breakflag )break; + top = mb[top].next; + } + if( ti > len ){ + /* 1滥ئʿ£ ئ޷¡ë */ + return TCPSTRUCT_ETOOLONG; + } + /* 滥ƻئ */ + if( breakflag == 0 ){ + return 0; + } + + return consumeMemBufList( con[index].mbtop_ri , buf , ti+1 , 1 , 1 ); +} + + + +/* + ij Ӯë߯ + int index : con index + + return: + ޷¡ + 0 read ƻַӮ + + + mbsize mbuse ë¦лë· + Իз £۹ئƾаִئʻֵڣ + + */ +static int getFreeMem( void ) +{ + return ( mbsize - mbuse ) * sizeof( mb[0].buf ); +} + +/* + + membuf ëƷʣ + + return : Ĺ >=0 ƥ index. + Ĺئ + + 巴 mb_finder ë + ľƥƻ reg£ + */ + +static int findregBlankMemBuf( void ) +{ + int i; + for(i=0;i= mbsize || mb_finder < 0 ) mb_finder = 0; + + if( mb[mb_finder].use == 0 ){ + mb[mb_finder].use = 1; + mb[mb_finder].len = 0; + mb[mb_finder].next = -1; + mbuse ++; + return mb_finder; + } + } + return TCPSTRUCT_EMBFULL; +} + +/* + mb ëݩ + + */ +static int unregMemBuf( int index ) +{ + mb[index].use=0; + mb[index].next = -1; + mb[index].len = 0; + mbuse --; + return OK; +} + +static int findregBlankCon( void ) +{ + int i; + // Nuke changed 0->1 + //for(i=0;i= MAXMISSIONTABLE) break; + } + fclose( fp); + log("..ɹ! \n"); + return TRUE; +} + + +int saveMissionTable( void ) +{ + FILE *fp; + char onedata[1024]; + int index =0; + + fp = fopen( MISSIONFILE, "w"); + if( !fp ) { + log("\n򿪾ٻ!!!! \n"); + //return false; + } + log("\n澫ٻ..."); + for( index =0; index < MAXMISSIONTABLE; index++) { + + if( missiontable[index].angelinfo[0] == '\0' ) + continue; + sprintf( onedata, "%s,%s,%d,%d,%d,%d\n", + missiontable[index].angelinfo, + missiontable[index].heroinfo, + missiontable[index].mission, + missiontable[index].flag, + missiontable[index].time, + missiontable[index].limittime ); + fputs( onedata, fp); + } + fclose( fp); + log("..ɹ! \n"); + return TRUE; +} + +void delMissionTableOnedata( int index) +{ + int gi; + + log("\nɾٻ:%d:%s:%s \n", index, missiontable[index].angelinfo, missiontable[index].heroinfo); + + if( index <0 || index >=MAXMISSIONTABLE) return; + strcpy( missiontable[index].angelinfo, ""); + strcpy( missiontable[index].heroinfo, ""); + missiontable[index].mission = 0; + missiontable[index].flag = MISSION_NONE; + missiontable[index].time = 0; + missiontable[index].limittime = 0; + + for( gi=0; gi missiontable[index].time + ANSWERTIME*60*60 ) { + + delMissionTableOnedata( index);// ɾ + } + // ȴ콱 limittimeСʱ + else if( ( missiontable[index].flag == MISSION_DOING || missiontable[index].flag == MISSION_HERO_COMPLETE ) + && ( sys_time > (missiontable[index].time + missiontable[index].limittime*60*60)) ) { + + char buf[1024]; + int gi; + // TIMEOVER + log("ٻ콱ʱ:%d ", index); + missiontable[index].flag = MISSION_TIMEOVER; + missiontable[index].time = time(NULL); + missiontable[index].limittime = BOUNDSTIME; + + sprintf( buf, "%d|%s|%s|%d|%d|%d|%d ", index, + missiontable[index].angelinfo, + missiontable[index].heroinfo, + missiontable[index].mission, + missiontable[index].flag, + missiontable[index].time, + missiontable[index].limittime ); + for( gi=0; gi missiontable[index].time + BOUNDSTIME*60*60 ) { + // log(" 콱ʱ:%d ", index); + // delMissionTableOnedata( index);// ɾ + //} + + // ϱʱ(BOUNDSTIMEСʱ) + else if( missiontable[index].flag == MISSION_TIMEOVER + && sys_time > missiontable[index].time + BOUNDSTIME*60*60 ) { + log(" ʱ:%d ", index); + delMissionTableOnedata( index);// ɾ + } + + } + saveMissionTable(); +#ifdef _SAVE_ZIP + if (SAVEZIP > 0) savezipfile(); +#endif + lastcheck = sys_time; +} + +#endif + +void logerr(char *token) +{ + char tmp[256]; + struct tm now; + time_t timep; + time(&timep); + memcpy(&now, localtime(&timep), sizeof(now)); + + sprintf(tmp, "%04d-%02d-%02d.log", now.tm_year+1900, now.tm_mon+1, now.tm_mday); + + FILE *fp=fopen(tmp,"a+"); + fwrite(token, strlen(token), 1, fp); + fclose(fp); + printf( token ); +} + +#ifdef _SAVE_ZIP +void savezipfile( void ) +{ + time_t timep; + time(&timep); + struct tm * ptm; + int y,m,d; + timep = time(NULL); + ptm = localtime(&timep); + y = ptm->tm_year +1900; + m = ptm->tm_mon+1; + d = ptm->tm_mday; + char buf[256]; + sprintf( buf, "%d-%d-%d.zip",y,m,d); +if (access(buf,W_OK) == 0) return;//ļ + sprintf( buf, "zip -q -r %d-%d-%d.zip char char_sleep data db lock log mail pklist race&",y,m,d); +log("ݵ..."); + system(buf); +log("ɹ!\n"); + return; +} +#endif + + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/makefile b/石器时代服务器端最新完整源代码/Serv/saac/makefile new file mode 100755 index 0000000..ef85295 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/makefile @@ -0,0 +1,578 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + +export SHELL=/bin/sh + +# +# Edit by ringo 19980606 +# 19990723 +# +# +# + +INCFLAGS=-I. -I./include + +CFLAGS=-w -O3 -g -rdynamic $(INCFLAGS) -pipe -Wall +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQLSRC=sasql_cygwin.c + SQL=-lodbc32 -lz -lpthread + PROG = ./saacjt +endif +ifeq ($(shell uname),Linux) + SQLSRC=sasql_linux.c + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz -lpthread + PROG = ./saacjt +endif + +TOP=../.. +SHELL = /bin/sh +PERL=/usr/bin/perl + +RPCGEN=${TOP}/bin/lsgen.perl + +RPCHTML = ${TOP}/doc/saacproto.html +#RPCSRC = saacproto_serv.c saacproto_util.csaacproto_sup.c +RPCSRC = saacproto_serv.c saacproto_util.c +RPCINCLUDE = saacproto_serv.h saacproto_util.h mac.h +RPCNOUSE = saacproto_cli.c saacproto_cli.h + +#mysqlϿ⹦ܥ\ +SRC = main.c recv.c util.c char.c db.c mail.c acfamily.c lock.c attestation.c md5.c $(SQLSRC) $(RPCSRC) +#SRC = main.c recv.c util.c char.c db.c mail.c acfamily.c lock.c $(RPCSRC) + +OBJ=$(SRC:.c=.o) + +${PROG}: allblues $(RPCSRC) $(OBJ) + $(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(SQL) + +allblues: + $(SHELL) ./longzoro.sh + +dos2unix: + dos2unix $(SRC) ./include/*.h makefile + +chmod: + chmod 777 $(SRC) ./include/*.h makefile + +depend: $(RPCSRC) $(ANIMDATAFILE) + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(CLIRPCSRC) + $(RM) $(CLIRPCINCLUDE) + $(RM) $(SERVRPCSRC) + $(RM) $(SERVRPCINCLUDE) + $(RM) $(ANIMDATAFILE) + $(RM) include/*~ + + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +rpc : ${RPCHTML} ${RPCGEN} + $(PERL) ${RPCGEN} ${RPCHTML} -h . -o . + rm -f ${RPCNOUSE} + +# DO NOT DELETE THIS LINE +main.o: main.c include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/util.h include/mail.h \ + include/db.h include/saacproto_util.h include/saacproto_serv.h \ + include/saacproto_util.h characters.h include/acfamily.h \ + include/version.h include/recv.h include/acfamily.h include/md5.h \ + include/char.h include/attestation.h include/sasql.h longzoro.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/sys/wait.h /usr/include/sys/resource.h \ + /usr/include/bits/resource.h /usr/include/bits/waitflags.h \ + /usr/include/bits/waitstatus.h /usr/include/malloc.h \ + /usr/include/fcntl.h /usr/include/bits/fcntl.h /usr/include/linux/if.h \ + /usr/include/linux/types.h /usr/include/linux/posix_types.h \ + /usr/include/linux/stddef.h /usr/include/asm/posix_types.h \ + /usr/include/asm/types.h /usr/include/linux/socket.h \ + /usr/include/linux/hdlc/ioctl.h /usr/include/linux/sockios.h \ + /usr/include/linux/ioctl.h /usr/include/asm/ioctl.h \ + /usr/include/asm-generic/ioctl.h /usr/include/netinet/tcp.h \ + include/lock.h +recv.o: recv.c include/version.h include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/saacproto_util.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + include/recv.h include/acfamily.h include/char.h include/db.h \ + include/mail.h include/lock.h include/util.h include/sasql.h \ + include/md5.h include/acfamily.h +util.o: util.c /usr/include/sys/types.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/socket.h \ + /usr/include/sys/uio.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/sys/time.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/bits/wchar.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/arpa/inet.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/alloca.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h /usr/include/ctype.h \ + include/main.h /usr/include/strings.h include/version.h include/util.h +char.o: char.c /usr/include/time.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/time.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/stdio.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/main.h /usr/include/stdlib.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/strings.h \ + /usr/include/sys/time.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/char.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + include/util.h include/acfamily.h include/version.h include/lock.h \ + include/recv.h include/acfamily.h include/sasql.h +db.o: db.c include/db.h include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/util.h \ + include/version.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h +mail.o: mail.c include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/mail.h include/util.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + /usr/include/malloc.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h +acfamily.o: acfamily.c include/version.h include/main.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/acfamily.h \ + include/util.h include/saacproto_serv.h include/saacproto_util.h \ + characters.h /usr/include/malloc.h /usr/include/dirent.h \ + /usr/include/bits/dirent.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h +lock.o: lock.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/lock.h include/version.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/char.h include/sasql.h +attestation.o: attestation.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h /usr/include/netdb.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/sys/time.h /usr/include/sys/ioctl.h \ + /usr/include/bits/ioctls.h /usr/include/asm/ioctls.h \ + /usr/include/asm/ioctl.h /usr/include/asm-generic/ioctl.h \ + /usr/include/bits/ioctl-types.h /usr/include/sys/ttydefaults.h \ + /usr/include/arpa/inet.h /usr/include/netinet/tcp.h \ + /usr/include/net/if.h include/util.h include/version.h include/main.h \ + /usr/include/strings.h include/version.h +md5.o: md5.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/version.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/version.h include/md5.h +sasql_linux.o: sasql_linux.c include/version.h include/main.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/sasql.h include/util.h \ + include/md5.h /usr/include/mysql/mysql.h \ + /usr/include/mysql/mysql_version.h /usr/include/mysql/mysql_com.h \ + /usr/include/mysql/mysql_time.h /usr/include/mysql/typelib.h \ + /usr/include/mysql/my_alloc.h /usr/include/mysql/my_list.h +saacproto_serv.o: saacproto_serv.c include/version.h \ + include/saacproto_serv.h include/version.h include/saacproto_util.h \ + /usr/include/stdlib.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/sys/types.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h characters.h include/main.h /usr/include/stdio.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/sys/time.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h +saacproto_util.o: saacproto_util.c include/version.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/sys/time.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h include/version.h \ + include/saacproto_util.h diff --git a/石器时代服务器端最新完整源代码/Serv/saac/makefile.bak b/石器时代服务器端最新完整源代码/Serv/saac/makefile.bak new file mode 100755 index 0000000..ef85295 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/makefile.bak @@ -0,0 +1,578 @@ +export CC=gcc +export RM=rm -f +export AR=ar cr +export MV=mv +export RANLIB=ranlib +export SED=sed + +export SHELL=/bin/sh + +# +# Edit by ringo 19980606 +# 19990723 +# +# +# + +INCFLAGS=-I. -I./include + +CFLAGS=-w -O3 -g -rdynamic $(INCFLAGS) -pipe -Wall +#Pentium 4 (Intel) +#CFLAGS=-march=pentium4 -O3 -pipe -fomit-frame-pointer $(INCFLAGS) +#Athlon XP (AMD) +#CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" $(INCFLAGS) +#Athlon64 +#CFLAGS="-O2 -march=athlon64 -ftracer -fprefetch-loop-arrays -pipe" $(INCFLAGS) + + +ifeq ($(shell uname),CYGWIN_NT-5.1) + SQLSRC=sasql_cygwin.c + SQL=-lodbc32 -lz -lpthread + PROG = ./saacjt +endif +ifeq ($(shell uname),Linux) + SQLSRC=sasql_linux.c + SQL=-L /usr/lib/mysql/ -lmysqlclient -lz -lpthread + PROG = ./saacjt +endif + +TOP=../.. +SHELL = /bin/sh +PERL=/usr/bin/perl + +RPCGEN=${TOP}/bin/lsgen.perl + +RPCHTML = ${TOP}/doc/saacproto.html +#RPCSRC = saacproto_serv.c saacproto_util.csaacproto_sup.c +RPCSRC = saacproto_serv.c saacproto_util.c +RPCINCLUDE = saacproto_serv.h saacproto_util.h mac.h +RPCNOUSE = saacproto_cli.c saacproto_cli.h + +#mysqlϿ⹦ܥ\ +SRC = main.c recv.c util.c char.c db.c mail.c acfamily.c lock.c attestation.c md5.c $(SQLSRC) $(RPCSRC) +#SRC = main.c recv.c util.c char.c db.c mail.c acfamily.c lock.c $(RPCSRC) + +OBJ=$(SRC:.c=.o) + +${PROG}: allblues $(RPCSRC) $(OBJ) + $(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(SQL) + +allblues: + $(SHELL) ./longzoro.sh + +dos2unix: + dos2unix $(SRC) ./include/*.h makefile + +chmod: + chmod 777 $(SRC) ./include/*.h makefile + +depend: $(RPCSRC) $(ANIMDATAFILE) + $(MV) makefile makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' makefile.bak>makefile + $(CC) $(INCFLAGS) -M $(SRC) >> makefile + chmod 777 makefile +clean: + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + +distclean: + $(RM) $(CLIRPCSRC) + $(RM) $(CLIRPCINCLUDE) + $(RM) $(SERVRPCSRC) + $(RM) $(SERVRPCINCLUDE) + $(RM) $(ANIMDATAFILE) + $(RM) include/*~ + + $(RM) $(PROG) + $(RM) $(OBJ) + $(RM) *~ + + $(MV) Makefile Makefile.bak + $(SED) -ne '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak>Makefile + $(RM) Makefile.bak + +rpc : ${RPCHTML} ${RPCGEN} + $(PERL) ${RPCGEN} ${RPCHTML} -h . -o . + rm -f ${RPCNOUSE} + +# DO NOT DELETE THIS LINE +main.o: main.c include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/util.h include/mail.h \ + include/db.h include/saacproto_util.h include/saacproto_serv.h \ + include/saacproto_util.h characters.h include/acfamily.h \ + include/version.h include/recv.h include/acfamily.h include/md5.h \ + include/char.h include/attestation.h include/sasql.h longzoro.h \ + /usr/include/signal.h /usr/include/bits/signum.h \ + /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \ + /usr/include/bits/sigcontext.h /usr/include/asm/sigcontext.h \ + /usr/include/bits/sigstack.h /usr/include/bits/sigthread.h \ + /usr/include/sys/wait.h /usr/include/sys/resource.h \ + /usr/include/bits/resource.h /usr/include/bits/waitflags.h \ + /usr/include/bits/waitstatus.h /usr/include/malloc.h \ + /usr/include/fcntl.h /usr/include/bits/fcntl.h /usr/include/linux/if.h \ + /usr/include/linux/types.h /usr/include/linux/posix_types.h \ + /usr/include/linux/stddef.h /usr/include/asm/posix_types.h \ + /usr/include/asm/types.h /usr/include/linux/socket.h \ + /usr/include/linux/hdlc/ioctl.h /usr/include/linux/sockios.h \ + /usr/include/linux/ioctl.h /usr/include/asm/ioctl.h \ + /usr/include/asm-generic/ioctl.h /usr/include/netinet/tcp.h \ + include/lock.h +recv.o: recv.c include/version.h include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/saacproto_util.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + include/recv.h include/acfamily.h include/char.h include/db.h \ + include/mail.h include/lock.h include/util.h include/sasql.h \ + include/md5.h include/acfamily.h +util.o: util.c /usr/include/sys/types.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/include/bits/types.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/sys/socket.h \ + /usr/include/sys/uio.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/sys/time.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h /usr/include/netinet/in.h \ + /usr/include/stdint.h /usr/include/bits/wchar.h /usr/include/bits/in.h \ + /usr/include/bits/byteswap.h /usr/include/arpa/inet.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/alloca.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/include/dirent.h /usr/include/bits/dirent.h /usr/include/netdb.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h /usr/include/ctype.h \ + include/main.h /usr/include/strings.h include/version.h include/util.h +char.o: char.c /usr/include/time.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/time.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/stdio.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/sys/types.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h /usr/include/fcntl.h \ + /usr/include/bits/fcntl.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h include/main.h /usr/include/stdlib.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/strings.h \ + /usr/include/sys/time.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/char.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + include/util.h include/acfamily.h include/version.h include/lock.h \ + include/recv.h include/acfamily.h include/sasql.h +db.o: db.c include/db.h include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/util.h \ + include/version.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h +mail.o: mail.c include/main.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/mail.h include/util.h \ + include/saacproto_serv.h include/saacproto_util.h characters.h \ + /usr/include/malloc.h /usr/include/dirent.h /usr/include/bits/dirent.h \ + /usr/include/sys/stat.h /usr/include/bits/stat.h +acfamily.o: acfamily.c include/version.h include/main.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/acfamily.h \ + include/util.h include/saacproto_serv.h include/saacproto_util.h \ + characters.h /usr/include/malloc.h /usr/include/dirent.h \ + /usr/include/bits/dirent.h /usr/include/sys/stat.h \ + /usr/include/bits/stat.h +lock.o: lock.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/lock.h include/version.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/char.h include/sasql.h +attestation.o: attestation.c /usr/include/string.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \ + /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/unistd.h /usr/include/bits/posix_opt.h \ + /usr/include/bits/confname.h /usr/include/getopt.h /usr/include/netdb.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ + /usr/include/sys/time.h /usr/include/sys/ioctl.h \ + /usr/include/bits/ioctls.h /usr/include/asm/ioctls.h \ + /usr/include/asm/ioctl.h /usr/include/asm-generic/ioctl.h \ + /usr/include/bits/ioctl-types.h /usr/include/sys/ttydefaults.h \ + /usr/include/arpa/inet.h /usr/include/netinet/tcp.h \ + /usr/include/net/if.h include/util.h include/version.h include/main.h \ + /usr/include/strings.h include/version.h +md5.o: md5.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h /usr/include/stdlib.h /usr/include/sys/types.h \ + /usr/include/time.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h include/version.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + include/version.h include/md5.h +sasql_linux.o: sasql_linux.c include/version.h include/main.h \ + /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h /usr/include/sys/time.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/string.h include/version.h include/sasql.h include/util.h \ + include/md5.h /usr/include/mysql/mysql.h \ + /usr/include/mysql/mysql_version.h /usr/include/mysql/mysql_com.h \ + /usr/include/mysql/mysql_time.h /usr/include/mysql/typelib.h \ + /usr/include/mysql/my_alloc.h /usr/include/mysql/my_list.h +saacproto_serv.o: saacproto_serv.c include/version.h \ + include/saacproto_serv.h include/version.h include/saacproto_util.h \ + /usr/include/stdlib.h /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/sys/types.h /usr/include/bits/types.h \ + /usr/include/bits/typesizes.h /usr/include/time.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/strings.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h characters.h include/main.h /usr/include/stdio.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/sys/time.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h +saacproto_util.o: saacproto_util.c include/version.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ + /usr/include/gnu/stubs-32.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/string.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/strings.h include/main.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/bits/uio.h /usr/include/bits/socket.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h \ + /usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm/sockios.h \ + /usr/include/bits/in.h /usr/include/bits/byteswap.h \ + /usr/include/arpa/inet.h /usr/include/netdb.h /usr/include/rpc/netdb.h \ + /usr/include/bits/netdb.h /usr/include/sys/time.h /usr/include/errno.h \ + /usr/include/bits/errno.h /usr/include/linux/errno.h \ + /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \ + /usr/include/asm-generic/errno-base.h include/version.h \ + include/saacproto_util.h diff --git a/石器时代服务器端最新完整源代码/Serv/saac/md5.c b/石器时代服务器端最新完整源代码/Serv/saac/md5.c new file mode 100644 index 0000000..f0a5ed4 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/md5.c @@ -0,0 +1,347 @@ +/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD5 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD5 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. */ + +#include +#include +#include +#include "version.h" +#include "main.h" +#include "md5.h" +#ifdef _OLDPS_TO_MD5PS +/* Constants for MD5Transform routine. */ + +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); +static void Encode PROTO_LIST + ((unsigned char *, UINT4 *, unsigned int)); +static void Decode PROTO_LIST + ((UINT4 *, unsigned char *, unsigned int)); +static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); +static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); + +static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G, H and I are basic MD5 functions. */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* ROTATE_LEFT rotates x left n bits. */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +Rotation is separate from addition to prevent recomputation. */ +#define FF(a, b, c, d, x, s, ac) { \ + (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) { \ + (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) { \ + (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) { \ + (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } + +/* MD5 initialization. Begins an MD5 operation, writing a new context. */ +void MD5Init (context) +MD5_CTX *context; /* context */ +{ + context->count[0] = context->count[1] = 0; + /* Load magic initialization constants.*/ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* MD5 block update operation. Continues an MD5 message-digest + operation, processing another message block, and updating the + context. */ +void MD5Update (context, input, inputLen) +MD5_CTX *context; /* context */ +const unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((UINT4)inputLen << 3)) + + < ((UINT4)inputLen << 3)) + context->count[1]++; + context->count[1] += ((UINT4)inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible.*/ + if (inputLen >= partLen) { + MD5_memcpy + ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD5Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + + /* Buffer remaining input */ + MD5_memcpy + ((POINTER)&context->buffer[index], (POINTER)&input[i], + inputLen-i); +} + +/* MD5 finalization. Ends an MD5 message-digest operation, writing the + the message digest and zeroizing the context. */ +void MD5Final (digest, context) +unsigned char digest[16]; /* message digest */ +MD5_CTX *context; /* context */ +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + Encode (bits, context->count, 8); + + /* Pad out to 56 mod 64.*/ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD5Update (context, PADDING, padLen); + + /* Append length (before padding) */ + MD5Update (context, bits, 8); + + /* Store state in digest */ + Encode (digest, context->state, 16); + + /* Zeroize sensitive information.*/ + MD5_memset ((POINTER)context, 0, sizeof (*context)); +} + +/* MD5 basic transformation. Transforms state based on block. */ +static void MD5Transform (state, block) +UINT4 state[4]; +unsigned char block[64]; +{ + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode (x, block, 64); + + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. */ + MD5_memset ((POINTER)x, 0, sizeof (x)); +} + +/* Encodes input (UINT4) into output (unsigned char). Assumes len is + a multiple of 4. */ +static void Encode (output, input, len) +unsigned char *output; +UINT4 *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (UINT4). Assumes len is + a multiple of 4. */ +static void Decode (output, input, len) +UINT4 *output; +unsigned char *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); +} + +/* Note: Replace "for loop" with standard memcpy if possible. */ + +static void MD5_memcpy (output, input, len) +POINTER output; +POINTER input; +unsigned int len; +{ + unsigned int i; + + for (i = 0; i < len; i++) + + output[i] = input[i]; +} + +/* Note: Replace "for loop" with standard memset if possible. */ +static void MD5_memset (output, value, len) +POINTER output; +int value; +unsigned int len; +{ + unsigned int i; + + for (i = 0; i < len; i++) + ((char *)output)[i] = (char)value; +} + + +char *MD5String (const char *string) +{ + int i; + MD5_CTX context; + unsigned char digest[16]; + char *result=(char *)malloc(33); + if(usemd5==0){ + strcpy(result, string); + return result; + } + + MD5Init (&context); + MD5Update (&context, string, strlen(string)); + MD5Final (digest, &context); + + for (i=0; i<16; i++) + sprintf(result+2*i, "%02x", digest[i]); + result[32]=0; + return result; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/recv.c b/石器时代服务器端最新完整源代码/Serv/saac/recv.c new file mode 100644 index 0000000..bfb0ef5 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/recv.c @@ -0,0 +1,2058 @@ +#define _RECV_C_ + +#include "version.h" +#include "main.h" +#include "saacproto_util.h" +#include "saacproto_serv.h" +#include "recv.h" +#include "char.h" +#include "db.h" +#include "mail.h" +#include "main.h" +#include "lock.h" +#include "util.h" +#ifdef _SASQL +#include "sasql.h" +#endif + +#ifdef _OLDPS_TO_MD5PS +#include "md5.h" +#endif + +// CoolFish: Family 2001/5/9 +#include "acfamily.h" +#include "version.h" + +#include +#include + +char retdata[CHARDATASIZE]; +char result[CHARDATASIZE]; + +extern gmsv gs[MAXCONNECTION]; + +// Spock +1 2000/11/1 +#define MAX_PROCESS 16777216 +#if _ATTESTAION_ID == 1 +void saacproto_ACServerLogin_recv( int ti, int id, char* servername , char* serverpas ) +{ + login_game_server( ti , id, servername , serverpas, + result , sizeof( result ) , + retdata , sizeof( retdata )); + + saacproto_ACServerLogin_send( ti ,result ,retdata ); +} +#else +void saacproto_ACServerLogin_recv( int ti,char* servername , char* serverpas ) +{ + login_game_server( ti , servername , serverpas, + result , sizeof( result ) , + retdata , sizeof( retdata )); + + saacproto_ACServerLogin_send( ti ,result ,retdata ); +} +#endif +/* + ءةӡʧӡշʧ£ + int fd : socket + +*/ +void saacproto_ACServerLogout_recv( int ti ) +{ + + logout_game_server( ti ); +} + +void saacproto_ACCharLoad_recv( int ti,char* id,char* pas,char* charname , + int lock,char* opt , int mesgid) +{ + if( !is_game_server_login(ti) )return; + // Spock 2000/10/31 + static int process = 0; + char buf[16]; + // Spock end +#ifdef _NewSave + int charindex = -1; +#endif + +#ifdef _SASQL + if (sasql_query(id,pas)!=1){ +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , "not login" , mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , "not login" , mesgid ); +#endif + return; + } +#endif + + + if( !is_game_server_login( ti ) ){ +#ifdef _NewSave + saacproto_ACCharLoad_send( ti , FAILED , "not login" , mesgid, charindex ); +#else + saacproto_ACCharLoad_send( ti , FAILED , "not login" , mesgid ); +#endif + return; + } + process++; + if ( process > MAX_PROCESS ) process = 1; + snprintf( buf , sizeof(buf) , "%d" , process ); + + charLoadCallback(ti,0,id,pas,charname,buf,"",lock,mesgid); + // Spock 2000/10/31 + //log( "ȡ: ҵ %s %s, =%d\n", id,pas,process ); + // Spock end +} + +/* + ƽҷ + + char *id : ID + char *pas : ʴ + char *charname : ƽҷ + char *opt : ٯ CharList嶪ƹƻ߯ + char *charinfo : ̻ƽҷ + int id : id +*/ +#ifdef _NewSave +void saacproto_ACCharSave_recv( int ti, char* id, + char *charname,char* opt , + char* charinfo , int unlock , int mesgid , int charindex ) +#else +void saacproto_ACCharSave_recv( int ti, char* id, + char *charname,char* opt , + char* charinfo , int unlock , int mesgid ) +#endif +{ + char process[16]; + int ret; + if( !is_game_server_login(ti) ){ + saacproto_ACCharSave_send( ti , FAILED , "not login" , mesgid ); + return; + } +#ifdef _NewSave + ret = charSave( ti, id, charname, opt, charinfo, + unlock,mesgid, charindex ); +#else + ret = charSave( ti, id, charname, opt, charinfo, + unlock,mesgid ); +#endif + snprintf( process , sizeof(process) , "%d" , ret ); +// log( "unlock:%d, process:%s\n", unlock, process); + if( unlock) { + dummyCallback(ti,0,id,"dummy",charname,process,"",mesgid,0); + } + // log("ѱ汣\n"); +} + +void saacproto_ACCharList_recv( int ti,char* id,char* pas ,char* ip,char* mac , int mesgid,int charlistflg) +{ + if( !is_game_server_login(ti) )return; + static int process=0; + char buf[10]; + + //log(" get_charlist "); + + process++; + if (process > MAX_PROCESS) process=1; + snprintf(buf, sizeof(buf), "%d", process); + if( !is_game_server_login( ti ) ){ + saacproto_ACCharList_send( ti , FAILED , "޷½Ϸ" , mesgid ); + return; + } + +#ifdef _SASQL + if (strlen(id)==0 || strlen(pas)==0){ + saacproto_ACCharList_send( ti , FAILED , "˺벻Ϊգ" , mesgid ); + return; + } + if (sasql_chehk_lock(id)){ + saacproto_ACCharList_send( ti , FAILED , "Ϸ˺ű޷½" , mesgid ); + return; + } + + int res=sasql_query(id, pas); + if (res==3){ +#ifdef _SQL_REGISTER + if(!sasql_register(id, pas)) +#endif + { + saacproto_ACCharList_send( ti , FAILED , "˺δעᣬ½עᣡ" , mesgid ); + return; + } + }else if (res!=1){ +#ifdef _ITEM_PET_LOCKED + int res2=sasql_ItemPetLocked_Char(id, pas); + printf("res2=%d\n",res2); + if(res2!=1) +#endif + { + saacproto_ACCharList_send( ti , FAILED , "˺Ż" , mesgid ); + return; + } + } + + if (strlen(id)==0 || strlen(pas)==0 || strlen(ip)==0){ + printf("½Ϣд\n"); + saacproto_ACCharList_send( ti , FAILED , "˺Ż벻Ϊգ" , mesgid ); + return; + } + if (sasql_chehk_lock(id)){ + printf("˺%sֹ½!\n",id); + saacproto_ACCharList_send( ti , FAILED , "Ϸ˺ű޷½" , mesgid ); + return; + } + if (sasql_chehk_lock(ip)){ + printf("IP%sֹ½!\n",ip); + saacproto_ACCharList_send( ti , FAILED , "ϷIPѱ޷½", mesgid ); + return; + } + if(strlen(mac)>0){ + if (sasql_chehk_lock(mac)){ + printf("MAC%sֹ½!\n",ip); + saacproto_ACCharList_send( ti , FAILED , "ϷIPѱ޷½", mesgid ); + return; + } + } +#endif + charListCallback(ti,0,id,pas,"",buf,"0",mesgid,0,charlistflg); + log( "б: %s\n", id ); +} + +void saacproto_ACCharDelete_recv( int ti,char* id,char* pas, + char* charname , char *option , int mesgid) +{ + if( !is_game_server_login(ti) ){ + saacproto_ACCharDelete_send( ti , FAILED , "not delete" , mesgid ); + return; + } + +#ifdef _ITEM_PET_LOCKED + if(sasql_ItemPetLocked_Char(id, pas)==-1){ + saacproto_ACCharDelete_send( ti , FAILED , "not delete" , mesgid ); + return; + } +#endif + // Nuke + charDeleteCallback(ti,0,id,pas,charname,"0","",mesgid,0); + log( "ɾ: ҵ %s %s\n",id , pas ); +} + +void saacproto_ACLock_recv( int ti ,char* id,int lock,int mesgid ) +{ + if( !is_game_server_login(ti) ){ + saacproto_ACLock_send( ti , FAILED , "not delete" , mesgid ); + return; + } + // Arminius 7.25 test unlock + log("ACLock recv:%d\n",lock); + if (lock==2) { + char buf[4096]; + if (GetMemLockState(getHash(id) & 0xff, id, buf)) { + sprintf(retdata, "USRLOCKED:%s", buf); + } else { + sprintf(retdata, "USRUNLOCKED:%s", buf); + } + log(retdata); + } else if (lock==3) { + int proc; + if (DeleteMemLock(getHash(id) & 0xff, id, &proc)) { + sprintf(retdata, "GMUNLOCKSUCCESS"); + } else { + sprintf(retdata, "GMUNLOCKFAIL"); + } + log(retdata); + } else if (lock==4) { + DeleteMemLockServer(id); + sprintf(retdata, "GMUNLOCKALL"); + } else { +#ifdef _LOCK_ADD_NAME + if ( lockUser( getGSName( ti ) , id , "" , "0" , lock , result,sizeof(result), + retdata ,sizeof( retdata ) , "0" , "0") < 0 ) { +#else + if ( lockUser( getGSName( ti ) , id , "0" , lock , result,sizeof(result), + retdata ,sizeof( retdata ) , "0" , "0") < 0 ) { +#endif + log( "û: %s ʧ\n" , id ); + } else { + log( "û: %s ɹ\n" , id ); + } + } + // Spock end + saacproto_ACLock_send( ti , result , retdata , mesgid ); +} + +void saacproto_ACUCheck_recv( int ti , char *id , int status ) +{ + if( !is_game_server_login(ti) ){ + log( "˺:%s status:%d\n", + id, status ); + return; + } + + if( status == 0 ){ + log( "û %s %s δ\n", id , getGSName( ti ) ); + saacproto_ACKick_recv( ti, id, 6, -1); + } else { + log( "û %s %s \n", id , getGSName( ti ) ); +#ifdef _WAEI_KICK + saacproto_ACKick_recv( ti, id, 1, -1); +#endif + } +} + + + +void saacproto_DBUpdateEntryString_recv( int fd, + char* table, + char* key, + char* value, + int msgid, + int msgid2 ) +{ + int r; + r = dbUpdateEntryString( table, key, value ); + + if( r != 0 ){ + log( "failed: DBUpdateEntryString err !!\n"); + } +/* 2003/06/26 + if( r == 0 ){ +// saacproto_DBUpdateEntryString_send( fd, SUCCESSFUL,table,key, + msgid,msgid2 ); + } else { +// saacproto_DBUpdateEntryString_send( fd, FAILED,table,key, + msgid,msgid2 ); + } +*/ +} + + +void saacproto_DBDeleteEntryString_recv( int fd, + char* table, + char* key, + int msgid, + int msgid2 ) +{ + int r; + + r = dbDeleteEntryString( table,key ); + if( r == 0 ){ + saacproto_DBDeleteEntryString_send( fd,SUCCESSFUL,table,key, + msgid,msgid2 ); + } else { + saacproto_DBDeleteEntryString_send( fd,FAILED,table,key, + msgid,msgid2 ); + } +} + + +void saacproto_DBGetEntryString_recv( int fd, + char* table, + char* key, + int msgid, + int msgid2 ) +{ +/* + char output[16384]; + int r; + r = dbGetEntryString( table, key, output, sizeof( output) ); + if( r == 0 ){ + saacproto_DBGetEntryString_send( fd,SUCCESSFUL,output,table,key, + msgid,msgid2 ); + } else { + saacproto_DBGetEntryString_send( fd,FAILED,"",table,key, + msgid,msgid2 ); + } +*/ +} + + + +void saacproto_DBUpdateEntryInt_recv( int fd, + char* table, + char* key, + int value, + char *info, + int msgid, + int msgid2) +{ + if( !is_game_server_login(fd) ){ + saacproto_DBUpdateEntryInt_send( fd, FAILED, "","",msgid, msgid2 ); + return; + } + if( dbUpdateEntryInt( table , key , value, info ) == 0 ){ + saacproto_DBUpdateEntryInt_send( + fd , SUCCESSFUL ,table,key, msgid, msgid2 ); + } else { + saacproto_DBUpdateEntryInt_send( fd , FAILED , table,key, msgid, msgid2 ); + } +} + +#ifdef _ALLDOMAN // (ɿ) Syu ADD аNPC +void saacproto_UpdataStele_recv( int fd , char *cdkey , char *name , char *title , + int level , int trns , int time , int floor ) +{ + int i, min=140, minnum=-1, nameflag=-1; + for ( i=0; i atoi(Herolist[nameflag][6]) ) { + Send_S_herolist ( Herolist[nameflag][0] , Herolist[nameflag][1] , + cdkey , name , title , level , trns , floor ) ; + sprintf ( Herolist[nameflag][2] , "%s" , title ) ; + sprintf ( Herolist[nameflag][3] , "%d" , level ) ; + sprintf ( Herolist[nameflag][4] , "%d" , trns ) ; + sprintf ( Herolist[nameflag][5] , "%d" , time ) ; + sprintf ( Herolist[nameflag][6] , "%d" , floor ) ; + SAVE_herolist( fd ); + }else if ( nameflag == -1 && floor > min ) { + Send_S_herolist ( Herolist[minnum][0] , Herolist[minnum][1] , + cdkey , name , title , level , trns , floor ) ; + sprintf ( Herolist[minnum][0] , "%s" , cdkey ) ; + sprintf ( Herolist[minnum][1] , "%s" , name ) ; + sprintf ( Herolist[minnum][2] , "%s" , title ) ; + sprintf ( Herolist[minnum][3] , "%d" , level ) ; + sprintf ( Herolist[minnum][4] , "%d" , trns ) ; + sprintf ( Herolist[minnum][5] , "%d" , time ) ; + sprintf ( Herolist[minnum][6] , "%d" , floor ) ; + SAVE_herolist( fd ); + } +} +#endif + +void saacproto_DBGetEntryRank_recv( int fd, + char* table, + char* key, + int msgid, + int msgid2) +{ + int rk,c; + + if( !is_game_server_login(fd) ){ + saacproto_DBGetEntryRank_send( fd, FAILED, 0,0,"","",msgid, msgid2 ); + return; + } + + dbGetEntryRank( table, key , &rk, &c ); + if( rk <0 ){ + saacproto_DBGetEntryRank_send( + fd, FAILED, -1, -1, table, key, msgid, msgid2 ); + } else { + saacproto_DBGetEntryRank_send( fd, SUCCESSFUL, + rk, c, table, key, msgid, msgid2 ); + } +} + + +void saacproto_DBDeleteEntryInt_recv( int fd, + char* table, + char* key, + int msgid, + int msgid2) +{ + if( !is_game_server_login(fd) ){ + saacproto_DBDeleteEntryInt_send( fd, FAILED,"","",msgid, msgid2 ); + return; + } + + if( dbDeleteEntryInt( table, key ) < 0 ){ + saacproto_DBDeleteEntryInt_send( + fd, FAILED, table, key, msgid, msgid2 ); + } else { + saacproto_DBDeleteEntryInt_send( + fd, SUCCESSFUL, table, key, msgid, msgid2 ); + } +} + + +void saacproto_DBGetEntryInt_recv( int fd, + char* table, + char* key, + int msgid, + int msgid2) +{ + int r ; + int output; + + if( !is_game_server_login(fd) ){ + saacproto_DBGetEntryInt_send( fd, FAILED,-1,"","",msgid, msgid2 ); + return; + } + + r = dbGetEntryInt( table, key, &output ); + + if( r < 0 ){ + saacproto_DBGetEntryInt_send( fd, + FAILED, -1, table, key, msgid, msgid2); + } else { + saacproto_DBGetEntryInt_send( + fd, SUCCESSFUL, output, table, key, msgid, msgid2 ); + } + +} + + +void saacproto_DBGetEntryByRank_recv( int fd, + char* table, + int start, int end, + int msgid , + int msgid2) +{ + char output[16384]; + int r; + + if( !is_game_server_login(fd) ){ + saacproto_DBGetEntryByRank_send( fd, FAILED,"","",msgid, msgid2 ); + return; + } + + r = dbGetEntryRankRange( table, start, end, output, sizeof( output )); + + if( r < 0 ){ + saacproto_DBGetEntryByRank_send( + fd, FAILED, "", table, msgid, msgid2 ); + } else { + saacproto_DBGetEntryByRank_send( + fd, SUCCESSFUL, output,table, msgid, msgid2 ); + } +} + +void saacproto_DBGetEntryByCount_recv( int fd, + char* table, + int count_start, + int num, + int msgid , + int msgid2) +{ + char output[16384]; + int r; + + if( !is_game_server_login(fd) ){ + saacproto_DBGetEntryByCount_send( + fd, FAILED,"",table,count_start,msgid, msgid2 ); + return; + } + + r = dbGetEntryCountRange( table, count_start, num, output, sizeof(output)); + + if( r < 0 ){ + saacproto_DBGetEntryByCount_send( fd, FAILED, "", table, + count_start, msgid, msgid2 ); + } else { + saacproto_DBGetEntryByCount_send( fd, SUCCESSFUL, output, table, + count_start, msgid, msgid2 ); + } +} + +void saacproto_Broadcast_recv( int fd, char* id, char* charname, char* message, int flag) +{ + /* + if( !is_game_server_login( fd) ){ + log( "Broadcast: no login. id:%s charname:%s message:%s flag:%d\n", + id, charname, message , flag ); + return; + } + gmsvBroadcast( fd, id, charname, message , flag ); + */ +} + + +void saacproto_Message_recv( int fd, + char* id_from, + char* charname_from, + char* id_to, + char* charname_to, + char* message, + int option ) +{ + receiveMail( id_from, charname_from, + id_to, charname_to, message, option ,0,0); +} + +void saacproto_MessageAck_recv( int fd, + char* id, + char* charname, + char* result, + int mesgid ) +{ + int a; + if( strcmp( result, SUCCESSFUL ) )a=0; else a =-1; + receiveMailAck( id, charname, a , mesgid ); +} + +void saacproto_MessageFlush_recv( int fd, + char* id, + char* charname ) +{ + flushMail( fd, id , charname ); +} + +/******************************************************* + * CoolFish: Family 2001/5/18 + ******************************************************/ +#ifdef _PERSONAL_FAME +void saacproto_ACAddFM_recv( int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int fame, +#ifdef _FAMILYBADGE_ + int fmbadge, +#endif + int charfdid) +#else +void saacproto_ACAddFM_recv( int fd, char *fmname, char *fmleadername, + char *fmleaderid, int fmleaderlv, char *petname, char *petattr, + char *fmrule, int fmsprite, int fmleadergrano, int charfdid) +#endif +{ +#ifdef _FAMILY + int r = 0, index = 0; +#ifdef _PERSONAL_FAME + r = ACAddFM(fd, &index, fmname, fmleadername, fmleaderid, fmleaderlv, + petname, petattr, fmrule, fmsprite, fmleadergrano, fame, +#ifdef _FAMILYBADGE_ + fmbadge, +#endif + charfdid); +#else + r = ACAddFM(fd, &index, fmname, fmleadername, fmleaderid, fmleaderlv, + petname, petattr, fmrule, fmsprite, fmleadergrano, charfdid); +#endif + if (r < 0){ + saacproto_ACAddFM_send(fd, FAILED, r, index, charfdid); + }else{ + saacproto_ACAddFM_send(fd, SUCCESSFUL, r, index, charfdid); + } +#endif +} + +void saacproto_ACJoinFM_recv(int fd, char *fmname, int fmindex, +#ifdef _PERSONAL_FAME // Arminius: + char *charname, char *charid, int charlv, int index, int fame, int charfdid) +#else + char *charname, char *charid, int charlv, int index, int charfdid) +#endif +{ +#ifdef _FAMILY + int r = 0; +#ifdef _PERSONAL_FAME // Arminius: + r = ACJoinFM(fd, index, fmname, fmindex, charname, charid, charlv, fame, charfdid); +#else + r = ACJoinFM(fd, index, fmname, fmindex, charname, charid, charlv, charfdid); +#endif + if (r < 0){ + saacproto_ACJoinFM_send(fd, FAILED, r, charfdid); + }else{ + saacproto_ACJoinFM_send(fd, SUCCESSFUL, r, charfdid); + } +#endif +} + +void saacproto_ACLeaveFM_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int index, int charfdid) +{ +#ifdef _FAMILY + int r = 0; + r = ACLeaveFM(index, fmname, fmindex, charname, charid); + if (r < 0){ + saacproto_ACLeaveFM_send(fd, FAILED, r, charfdid); + }else{ + saacproto_ACLeaveFM_send(fd, SUCCESSFUL, r, charfdid); + } +#endif +} + +#ifdef _LEADERFUNCHECK +void saacproto_ACDelFM_recv(int fd, char *fmname, int fmindex, + int index, char *charname, char *charid, int charfdid) +{ + int r = 0, result = 0; + result = CheckLeaderQ(index, fmname, fmindex, charname, charid); + if(result < 0) + { + saacproto_ACDelFM_send(fd, FAILED, charfdid); + return; + } + // shan modify begin + // original + /*if (ChangeFMLeader(index, fmname, fmindex) < 0) + r = ACDelFM(index, fmname, fmindex); + else + r = -1; // shan 1 -> -1 + if (r < 0) + saacproto_ACDelFM_send(fd, FAILED, charfdid); + else + saacproto_ACDelFM_send(fd, SUCCESSFUL, charfdid); + */ + r = ACDelFM(index, fmname, fmindex); + if (r < 0) + saacproto_ACDelFM_send(fd, FAILED, charfdid); + else + saacproto_ACDelFM_send(fd, SUCCESSFUL, charfdid); + // shan end +} +#else +void saacproto_ACDelFM_recv(int fd, char *fmname, int fmindex, + int index, int charfdid) +{ +#ifdef _FAMILY + int r = 0; +#ifdef _FMVER21 + if (ChangeFMLeader(index, fmname, fmindex) >= 0) + r = ACDelFM(index, fmname, fmindex); + else r = 1; +#else + r = ACDelFM(index, fmname, fmindex); +#endif + if (r < 0){ + saacproto_ACDelFM_send(fd, FAILED, charfdid); + } +#ifdef _FMVER21 + else if (r == 1){ + } +#endif + else{ + saacproto_ACDelFM_send(fd, SUCCESSFUL, charfdid); + } +#endif +} +#endif + +void saacproto_ACShowFMList_recv(int fd) +{ +#ifdef _FAMILY + int r = 0; + char data[150 * MAX_FAMILY]; + r = ACShowFMList(data); + if (r < 0){ + saacproto_ACShowFMList_send(fd, FAILED, r, "Nothing"); + }else{ + saacproto_ACShowFMList_send(fd, SUCCESSFUL, r, data); + } +#endif +} +#ifdef _FAMILY_TOTEM +void saacproto_ACShowFMTotem_recv(int fd) +{ + ACShowFMTotem(fd); +} +#endif +void saacproto_ACShowMemberList_recv(int fd, int index) +{ +#ifdef _FAMILY + int r = 0, fmacceptflag = 0, fmjoinnum = 0, badge=0; + char data[150 * MAX_MEMBERNUM]; + r = ACShowFMMemberList(index, &fmacceptflag, &fmjoinnum, data,&badge); + if (r < 0){ + saacproto_ACShowMemberList_send(fd, FAILED, index, r, + fmacceptflag, fmjoinnum, "Nothing",badge); + }else{ + saacproto_ACShowMemberList_send(fd, SUCCESSFUL, index, r, + fmacceptflag, fmjoinnum, data,badge); + } +#endif +} + +void saacproto_ACFMDetail_recv(int fd, char *fmname, + int fmindex, int index, int charfdid) +{ +#ifdef _FAMILY + int r = 0; + char data[15000]; + r = ACFMDetail(index, fmname, fmindex, data); + if (r < 0){ + saacproto_ACFMDetail_send(fd, FAILED, "Nothing", charfdid); + }else{ + saacproto_ACFMDetail_send(fd, SUCCESSFUL, data, charfdid); + } +#endif +} + +#ifdef _FMVER21 +void saacproto_ACMemberJoinFM_recv(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int result, int meindex, + int charfdid) +#else +void saacproto_ACMemberJoinFM_recv(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int result, int charfdid) +#endif +{ + int r = 0; +#ifdef _FMVER21 + r = ACMemberJoinFM(index, fmname, fmindex, charname, charindex, result, meindex); +#else + r = ACMemberJoinFM(index, fmname, fmindex, charname, charindex); +#endif + if (r < 0){ + saacproto_ACMemberJoinFM_send(fd, FAILED, charfdid); + }else{ + saacproto_ACMemberJoinFM_send(fd, SUCCESSFUL, charfdid); + } +} + +#ifdef _FMVER21 +void saacproto_ACMemberLeaveFM_recv(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int meindex, int charfdid) +#else +void saacproto_ACMemberLeaveFM_recv(int fd, char *fmname, int fmindex, + char *charname, int charindex, int index, int charfdid) +#endif +{ +#ifdef _FAMILY + int r = 0; + int flag = 1; // 뿪 +#ifdef _FMVER21 + r = ACMemberLeaveFM(index, fmname, fmindex, charname, flag, + charindex, meindex); +#else + r = ACMemberLeaveFM(index, fmname, fmindex, charname, flag, charindex); +#endif + if (r < 0){ + saacproto_ACMemberLeaveFM_send(fd, FAILED, charfdid); + }else{ + saacproto_ACMemberLeaveFM_send(fd, SUCCESSFUL, charfdid); + } +#endif +} + +#ifdef _FM_MODIFY +void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int eventflag, int charfdid,int gsnum) +#else + #ifdef _FMVER21 + void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int eventflag, int charfdid) + #else + void saacproto_ACFMCharLogin_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int charfdid) + #endif +#endif +{ +#ifdef _FAMILY + int r = 0, floor = 0, fmpopular = 0, joinflag = 0, fmsetupflag = 0; + int flag = 0, charindex = 0; +#ifdef _PERSONAL_FAME // Arminius: + int charfame = 0; +#endif +#ifdef _NEW_MANOR_LAW + int momentum = 0; +#endif +#ifdef _FM_MODIFY + r = ACFMCharLogin(fd, -1, fmname, fmindex, charname, charid, charlv, + &floor, &fmpopular, &joinflag, &fmsetupflag, &charindex, charfdid, + &charfame, eventflag,gsnum + #ifdef _NEW_MANOR_LAW + ,&momentum + #endif + ); +#else + #ifdef _PERSONAL_FAME // Arminius: + r = ACFMCharLogin(fd, -1, fmname, fmindex, charname, charid, charlv, + &floor, &fmpopular, &joinflag, &fmsetupflag, &charindex, charfdid, + &charfame, eventflag); + #else + r = ACFMCharLogin(fd, -1, fmname, fmindex, charname, charid, charlv, + &floor, &fmpopular, &joinflag, &fmsetupflag, &charindex, charfdid); + #endif +#endif + +#ifdef _PERSONAL_FAME // Arminius: + if (r < 0){ + saacproto_ACFMCharLogin_send(fd, FAILED, r, floor, fmpopular, + joinflag, fmsetupflag, flag, charindex, charfame, charfdid + #ifdef _NEW_MANOR_LAW + ,momentum + #endif + ); + }else{ + saacproto_ACFMCharLogin_send(fd, SUCCESSFUL, r, floor, fmpopular, + joinflag, fmsetupflag, flag, charindex, charfame, charfdid + #ifdef _NEW_MANOR_LAW + ,momentum + #endif + ); + } +#else + if (r < 0){ + saacproto_ACFMCharLogin_send(fd, FAILED, r, floor, fmpopular, + joinflag, fmsetupflag, flag, charindex, charfdid); + }else{ + saacproto_ACFMCharLogin_send(fd, SUCCESSFUL, r, floor, fmpopular, + joinflag, fmsetupflag, flag, charindex, charfdid); + } +#endif + +#endif +} + +void saacproto_ACFMCharLogout_recv(int fd, char *fmname, int fmindex, + char *charname, char *charid, int charlv, int index,int charfdid) +{ +#ifdef _FAMILY + int r = 0; + r = ACFMCharLogout(index, fmname, fmindex, charname, charid, charlv, + charfdid); + if (r < 0){ + saacproto_ACFMCharLogout_send(fd, FAILED, charfdid); + }else{ + saacproto_ACFMCharLogout_send(fd, SUCCESSFUL, charfdid); + } +#endif +} + +void saacproto_ACFMReadMemo_recv(int fd, int index) +{ + +#ifdef _FAMILY + int r = 0, dataindex; + char data[15000]; + r = ACFMReadMemo(index, &dataindex, data); + if (r < 0){ + saacproto_ACFMReadMemo_send(fd, FAILED, index, r, dataindex, "Nothing"); + }else{ + saacproto_ACFMReadMemo_send(fd, SUCCESSFUL, index, r, dataindex, data); + } +#endif + +} + +void saacproto_ACFMWriteMemo_recv(int fd, char *fmname, int fmindex, + char *data, int index) +{ +#ifdef _FAMILY + int r = 0; + r = ACFMWriteMemo(index, fmname, fmindex, data); + if (r < 0){ + saacproto_ACFMWriteMemo_send(fd, FAILED, index); + }else{ + saacproto_ACFMWriteMemo_send(fd, SUCCESSFUL, index); + } +#endif +} + +void saacproto_ACFMPointList_recv(int fd) +{ +#ifdef _FAMILY + int r = 0; + char data[15000]; + r = ACFMPointList(data); + if (r < 0) + { + saacproto_ACFMPointList_send(fd, FAILED, "nothing"); + }else{ + saacproto_ACFMPointList_send(fd, SUCCESSFUL, data); + } +#endif +} + +void saacproto_ACSetFMPoint_recv(int fd, char *fmname, int fmindex, + int index, int fmpointindex, int fl, int x, int y, int charfdid) +{ +#ifdef _FAMILY + int r = 0; + r = ACSetFMPoint(index, fmname, fmindex, fmpointindex, fl, x, y); + if (r < 0){ + saacproto_ACSetFMPoint_send(fd, FAILED, r, charfdid); + }else{ + saacproto_ACSetFMPoint_send(fd, SUCCESSFUL, r, charfdid); + } +#endif +} + +void saacproto_ACFixFMPoint_recv(int fd, char *winfmname, int winfmindex, int winindex, + char *losefmname, int losefmindex, int loseindex, int village) +{ +#ifdef _FAMILY + int r = 0; + r = ACFixFMPoint(winindex, winfmname, winfmindex, + loseindex, losefmname, losefmindex, village); + if (r < 0){ + saacproto_ACFixFMPoint_send(fd, FAILED, r); + }else{ + saacproto_ACFixFMPoint_send(fd, SUCCESSFUL, r); + } +#endif +} + +void saacproto_ACFMAnnounce_recv(int fd, char *fmname, int fmindex, int index, + char *data, int color) +{ +#ifdef _FAMILY + int r = 0, i = 0; + r = ACFMAnnounce(fmname, fmindex, index, data, color); + if (r < 0){ + saacproto_ACFMAnnounce_send(fd, FAILED, fmname, fmindex, index, + 1, data, color); + }else{ + extern gmsv gs[MAXCONNECTION]; + for (i = 0; i < MAXCONNECTION; i ++) + { + if (gs[i].use && gs[i].name[0]) + { + saacproto_ACFMAnnounce_send(i, SUCCESSFUL, fmname, fmindex, + index, 1, data, color); + } + } + } +#endif +} + +void saacproto_ACShowTopFMList_recv(int fd, int kindflag) +{ +#ifdef _FAMILY + int r = 0; + char data[150 * MAX_FAMILY]; + strcpy(data, ""); + r = ACShowTopFMList(data, sizeof(data), kindflag); + if (r < 0) { + saacproto_ACShowTopFMList_send(fd, FAILED, kindflag, r, "Nothing"); + }else { + saacproto_ACShowTopFMList_send(fd, SUCCESSFUL, kindflag, r, data); + } +#endif +} + +void saacproto_ACFixFMData_recv(int fd, char *fmname, int fmindex, int index, + int kindflag, char *data1, char *data2, int charindex, int charfdid) +{ +#ifdef _FAMILY + int r = 0; + r = ACFixFMData(index, fmname, fmindex, kindflag, charindex, data1, data2); + if (r < 0){ + saacproto_ACFixFMData_send(fd, FAILED, kindflag, data1, data2, charfdid); + }else{ + saacproto_ACFixFMData_send(fd, SUCCESSFUL, kindflag, data1, data2, charfdid); + } +#endif +} + +void saacproto_ACFixFMPK_recv(int fd, char *winfmname, int winfmindex, int winindex, + char *losefmname, int losefmindex, int loseindex) +{ +#ifdef _FAMILY + int r = 0; + r = ACFixFMPK(winindex, winfmname, winfmindex, + loseindex, losefmname, losefmindex); + if (r < 0){ + saacproto_ACFixFMPK_send(fd, FAILED, r, winindex, + loseindex); + }else{ + saacproto_ACFixFMPK_send(fd, SUCCESSFUL, r, winindex, + loseindex); + } +#endif +} + +void saacproto_ACGMFixFMData_recv(int fd, int index, char *charid, char *cmd, + char *data, int charfdid) +{ +#ifdef _FAMILY + int r = 0; + char fmname[256]; + r = ACGMFixFMData(index, fmname, charid, cmd, data); + if (r < 0){ + saacproto_ACGMFixFMData_send(fd, FAILED, fmname, charfdid); + } + else{ + saacproto_ACGMFixFMData_send(fd, SUCCESSFUL, fmname, charfdid); + } +#endif +} + +void saacproto_ACGetFMData_recv(int fd, char *fmname, int fmindex, int index, + int kindflag, int charfdid) +{ +#ifdef _FAMILY + int r = 0, data = 0; + r = ACGetFMData(index, fmname, fmindex, kindflag, &data); + if (r < 0){ + saacproto_ACGetFMData_send(fd, FAILED, kindflag, data, charfdid); + }else{ + saacproto_ACGetFMData_send(fd, SUCCESSFUL, kindflag, data, charfdid); + } +#endif +} + +void saacproto_ACreLoadFmData_recv(int fd, int type, int data) +{ + int i=0; +extern gmsv gs[MAXCONNECTION]; + switch( type){ + case 1: + log( "reload FM_DATA:%d !\n", data); + readOneFamilyFromTi( data); + break; + case 2: + { + char data[15000]; + readFMPoint( fmpointdir); + if( ACFMPointList( data) >= 0 ){ + log( "reload FM_POINT !\n" ); + for (i=0; i MAX_FMPOINT) return; + saacproto_ACLoadFmPk_send( fd, FMPK_GetData( fmpks_pos-1) ); +} + +void saacproto_ACSendFmPk_recv(int fd, int fmpks_pos, int userindex, int flg, char *data) +{ + extern gmsv gs[MAXCONNECTION]; + char buf[1024]; + int i=0; + sprintf( buf, "%d|%s", fmpks_pos, data); + + if( ( userindex != -1 && FMPK_GetTypeFlg( fmpks_pos-1) == 1 )|| + FMPK_SetData( fmpks_pos-1, flg, buf, strlen( buf)) != 1 ){ + if(userindex != -1) saacproto_ACSendFmPk_send( fd, userindex, 0); + log("err ACSendFmPk_send(%d, %d)\n", userindex, 0); + return; + } + FMPK_BackUpList(); + for (i=0; i MAX_FMPOINT){ + log("\n fmpks_pos(%d) too big", fmpks_pos); + } + saacproto_ACLoadFmPk_send(fd, fm_pk_list[fmpks_pos-1]); +} +void saacproto_ACSendFmPk_recv(int fd, int fmpks_pos, char *data) +{ + extern gmsv gs[MAXCONNECTION]; + int i=0; + + if( (fmpks_pos>MAX_FMPOINT) || (fmpks_pos<1) ){ + log("\n fmpks_pos(%d) err !!", fmpks_pos); + } + sprintf(fm_pk_list[fmpks_pos-1], "%d|%s", fmpks_pos, data); + + for (i=0; i= 65535 ){ + saacproto_UpdataStele_send ( fd , token ); + memset( token, 0, sizeof(token)); + lens = 0; + } + strcat( token, buf); + lens += strlen( buf); + } + fclose ( fdb ); + if( strlen( token) > 0 ) + saacproto_UpdataStele_send ( fd , token ); + } +} + +void Send_S_herolist( char *ocdkey , char *oname , char *ncdkey , char *nname , + char *title , int level , int trns , int floor ) +{ + int i; + extern gmsv gs[MAXCONNECTION]; + + for (i = 0 ; i < MAXCONNECTION ; i ++ ) { + if ( gs[i].use && gs[i].name[0] ) { + saacproto_S_UpdataStele_send( i , ocdkey , oname , + ncdkey , nname , title + , level , trns , floor ); + log("\nSyu log AC Send Single to Gmsv "); + } + } +} +#endif + +#define MAXUNlockM 50 +#define delaytime (60*3) +UNLockMenus UNlockM[MAXUNlockM]; + +int UNlockM_Init( void) +{ + int i; + for( i=0; i= time(NULL) ) continue; + if( isLocked( UNlockM[i].PlayerId ) ){ + log( "ȴ: %s !!\n", UNlockM[i].PlayerId); + }else{ + log( "ȴ: %s Ѿ!!\n", UNlockM[i].PlayerId); + } + reset_UNlockMPlayer( i); + nums++; + } + //log( "ȴ: ܼ %d û !!\n", nums); + return nums; +} + + +#ifdef _ANGEL_SUMMON + +extern int saveMissionTable( void ); + +//void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, int charaindex) +void saacproto_ACMissionTable_recv( int fd, int num, int type, char *data, char* angelinfo) +{ + extern gmsv gs[MAXCONNECTION]; + int i; + char buf[1024]; + + if( type == 1 ) { // ask data list + if( num == -1) { // ask all data + char alldata[MAXMISSIONTABLE*100]; + alldata[0]='\0'; + for( i =0; i use != 0){ + if(strcmp(ln->cdkey,id) == 0 && strcmp(ln->name,name) == 0){ + saacproto_ACCheckCharacterOnLine_send(fd,charaindex,1,ln->server,flag); + return; + } + } + ln = ln->next; + } + // Ҳ + saacproto_ACCheckCharacterOnLine_send(fd,charaindex,0,"",flag); + } + // Ҫȷ + else{ + while(ln != NULL){ + if(ln->use != 0){ + if(strcmp(ln->cdkey,id) == 0){ + saacproto_ACCheckCharacterOnLine_send(fd,charaindex,1,ln->server,flag); + return; + } + } + ln = ln->next; + } + // Ҳ + saacproto_ACCheckCharacterOnLine_send(fd,charaindex,0,"",flag); + } +} +#endif + +void saacproto_ACCharLogin_recv( int fd, int clifd, char* id, char* pas, char* ip +#ifdef _NEWCLISETMAC +,char* mac +#endif +) +{ + int res; +#ifdef _SASQL + if (strlen(id)==0 || strlen(pas)==0 || strlen(ip)==0){ + printf("½Ϣд\n"); + saacproto_ACCharLogin_send( fd, clifd, 1); + return; + } + if (sasql_chehk_lock(id)){ + printf("˺%sֹ½!\n",id); + saacproto_ACCharLogin_send( fd, clifd, 2); + return; + } + if (sasql_chehk_lock(ip)){ + printf("IP%sֹ½!\n",ip); + saacproto_ACCharLogin_send( fd, clifd, 3); + return; + } + if(strlen(mac)>0){ + if (sasql_chehk_lock(mac)){ + printf("MAC%sֹ½!\n",ip); + saacproto_ACCharLogin_send( fd, clifd, 3); + return; + } + } + res=sasql_query(id, pas); + if (res==3){ +#ifdef _SQL_REGISTER + if(!sasql_register(id, pas)) +#endif + { + saacproto_ACCharLogin_send( fd, clifd, 5); + return; + } + }else if (res!=1){ +#ifdef _ITEM_PET_LOCKED + if(sasql_ItemPetLocked_Char(id, pas)!=1) +#endif + { + saacproto_ACCharLogin_send( fd, clifd, 6); + return; + } + } + sasql_online(id, NULL, ip, mac, 1); +#endif + saacproto_ACCharLogin_send( fd , clifd, 0); +} + +#ifdef _SASQL +void saacproto_LockLogin_recv( int fd, char* id, char* ip, int flag ) +{ + switch (flag){ + case 0: + if(strlen(id)>0){ + if(sasql_del_lock(id)){ + log("ɹ˺:%s\n",id); + }else{ + log("ʧܣ˺:%s\n",id); + } + } + if(strlen(ip)>0){ + if(sasql_del_lock(ip)){ + log("ɹIP:%s\n",ip); + }else{ + log("ʧܣIP:%s\n",ip); + } + } + break; + case 1: + if(strlen(id)>0){ + if(!sasql_chehk_lock(id)){ + if(sasql_add_lock(id)){ + log("ɹ˺:%s\n",id); + }else{ + log("ʧܣ˺:%s\n",id); + } + }else{ + log("˺%sѱ\n",id); + } + } + if(strlen(ip)>0){ + if(!sasql_chehk_lock(ip)){ + if(sasql_add_lock(ip)){ + log("ɹIP:%s\n",ip); + }else{ + log("ʧܣIP:%s\n",ip); + } + }else{ + log("IP%sѱ\n",id); + } + } + break; + default: + break; + } +} +#ifdef _NEW_VIP_SHOP +void saacproto_QueryPoint_recv( int fd, int clifd, char *id ) +{ + int point = sasql_query_point( id ); + + saacproto_QueryPoint_send( fd, clifd, point ); +} + +void saacproto_NewVipShop_recv( int fd, int clifd, char *id, int point, char *buf, int flag) +{ + int vippoint = sasql_add_vippoint(id, point); + if( vippoint == -1){ + saacproto_NewVipShop_send(fd, clifd, vippoint, "", flag); + }else{ + saacproto_NewVipShop_send(fd, clifd, vippoint, buf, flag); + } +} + +#ifdef _COST_ITEM +void saacproto_CostItem_recv( int fd, int clifd, char *id, int point) +{ + int vippoint = sasql_add_vippoint(id, point); + + saacproto_QueryPoint_send( fd, clifd, vippoint ); +} +#endif +#endif + +#ifdef _ITEM_PET_LOCKED +void saacproto_ItemPetLocked_recv( int fd, int clifd, char *id, char *safepasswd ) +{ + char *data = sasql_ItemPetLocked( id, safepasswd ); + if(strcmp(data, "ȫѾɹ")==0){ + saacproto_ItemPetLocked_send(fd, clifd, 1, data); + }else if(strcmp(data, "δðȫ룬ΪȷȫһλΪȫ벢ͼס")==0){ + saacproto_ItemPetLocked_send(fd, clifd, 0, data); + }else{ + saacproto_ItemPetLocked_send(fd, clifd, -1, data); + } +} +void saacproto_ItemPetLockedPasswd_recv( int fd, int clifd, char *id, char *safepasswd ) +{ + char *data = sasql_ItemPetLocked_Passwd( id, safepasswd ); + saacproto_ItemPetLockedPasswd_send(fd, clifd, data); +} +#endif + +#ifdef _ONLINE_COST +void saacproto_OnlineCost_recv( int fd, int clifd, char *id, char *costpasswd, int fmindex, char *fmname ) +{ + char *data = sasql_OnlineCost( id, costpasswd, fmindex, fmname ); + saacproto_OnlineCost_send(fd, clifd, data); +} +#endif + +#ifdef _SQL_BUY_FUNC +void saacproto_OnlineBuy_recv( int fd, int clifd, char *id, char *costpasswd ) +{ + char *data = sasql_OnlineBuy( id, costpasswd ); + saacproto_OnlineBuy_send(fd, clifd, data); +} +#endif + +#ifdef _VIPPOINT_OLD_TO_NEW +void saacproto_OldToNew_recv( int fd, int clifd, char *id, int point ) +{ + int vippoint = sasql_add_vippoint( id, point ); + char data[256]; + sprintf(data, "ɻԱ%dתSQL㵱ǰԱ㹲%d",point, vippoint); + saacproto_OldToNew_send(fd, clifd, data); +} +#endif + +#ifdef _FORMULATE_AUTO_PK +void saacproto_FormulateAutoPk_recv( int fd, int clifd, char *id, int point ) +{ + int pkpoint = sasql_add_FormulateAutoPk( id, point ); + char data[256]; + if(pkpoint == -1){ + sprintf(data, "%d޷תSQLԱϵ", point); + }else{ + sprintf(data, "ѽ%dתSQL㵱ǰֹ%d", point, pkpoint); + } + saacproto_FormulateAutoPk_send(fd, clifd, data); +} +#endif + +#ifdef _CHARADATA_SAVE_SQL +void saacproto_CharadataSaveSQL_recv( int fd, int clifd, char *id, Charadata charadata, int saveindex, int flag ) +{ + sasql_charadata_Save(id, "list", charadata.CHAR_list_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info1", charadata.CHAR_list_info1_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info2", charadata.CHAR_list_info2_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_count", charadata.CHAR_list_count_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info3", charadata.CHAR_list_info3_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_event", charadata.CHAR_list_event_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info4", charadata.CHAR_list_info4_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_attackmagic", charadata.CHAR_list_attackmagic_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info5", charadata.CHAR_list_info5_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_profession", charadata.CHAR_list_profession_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info6", charadata.CHAR_list_info6_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_info", charadata.CHAR_list_info_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_flg", charadata.CHAR_list_flg_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_skill", charadata.CHAR_list_skill_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_item", charadata.CHAR_list_item_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_title", charadata.CHAR_list_title_String, saveindex, DELETE); + sasql_charadata_Save(id, "list_mail", charadata.CHAR_list_mail_String, saveindex, DELETE); +} +#endif + + +#ifdef _LOTTERY_SYSTEM +void saacproto_LotterySystem_recv(int fd) +{ + char data[256]={"-1,-1,-1,-1,-1,-1,-1"}; + FILE * f1 = fopen("todayaward.txt","r+"); + if( f1 ){ + if( fgets( data, sizeof( data ), f1 ) ){ + saacproto_LotterySystem_send( fd, data ); + } + } +} +#endif + +#ifdef _ALL_SERV_SEND +void saacproto_AllServSend_recv(char *data) +{ + int i; + + for (i=0; i CharDataLens ){ + CharDataLens = strlen( data); + //andy_log + log("ݳ:%d\n", CharDataLens ); + } + + saacproto_CreateHeader( saacproto.work , "ACCharLoad" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( data ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( id ) ,saacproto.workbufsize ); +#ifdef _NewSave + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( charindex ) ,saacproto.workbufsize ); +#endif + saacproto_Send( fd , saacproto.work ); +} + +/* +214 :
  • servertoclient ACCharSave( string result , string data,int id);
    +215 : ACCharSave帲߯ϣ +216 :

    +217 :
    +218 :
    string result +219 :
    "successful" , "failed" ľ +220 :
    string data +221 :
    "failed"ݷ ë޼έ ٯ ƥؤ£ +222 :
    int id +223 :
    ¦Ѽidëƻ߯ +224 :
    +225 :
    +226 :
    +227 : +228 : +229 : +230 : +*/ + +void saacproto_ACCharSave_send( int fd,char* result,char* data,int id ) +{ + saacproto_CreateHeader( saacproto.work , "ACCharSave" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( data ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( id ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +/* +256 :
  • servertoclient ACCharDelete(string result, string data,int id);
    +257 : ACCharDelete帲߯ϣ +258 :

    +259 :
    +260 :
    string result +261 :
    "successful" , "failed" ľ +262 :
    string data +263 :
    "failed"ݷ ë޼έ ٯ ƥؤ£ +264 :
    int id +265 :
    ¦Ѽid +266 : +267 :
    +268 :
    +269 :
    +270 : +*/ + +void saacproto_ACCharDelete_send( int fd,char* result,char* data,int id ) +{ + saacproto_CreateHeader( saacproto.work , "ACCharDelete" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( data ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( id ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +290 :
  • servertoclient ACLock( string result, string data ,int id);
    +291 : ACLock帲߯ϣ +292 :

    +293 :
    +294 :
    string result +295 :
    "successful" , "failed" ľ +296 :
    string data +297 :
    "failed"ݷ ë޼έ ٯ ƥؤ£ +298 :
    int id +299 :
    ¦Ѽid +300 :
    +301 :
    +302 :
    +303 : +*/ + +void saacproto_ACLock_send( int fd,char* result,char* data,int id ) +{ + saacproto_CreateHeader( saacproto.work , "ACLock" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( data ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( id ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +318 :
  • servertoclient ACUCheck( string mem_id );
    +319 : ʧӡձءةӡ帲ƻؤ½ǡػ̼ +320 : ƻ¾ë£ +321 :

    +322 :
    +323 :
    string mem_id +324 :
    Ʃ¸޼ǡgamersDream member id +325 :
    +326 :

    +327 : +328 : +*/ + +void saacproto_ACUCheck_send( int fd,char* mem_id ) +{ + saacproto_CreateHeader( saacproto.work , "ACUCheck" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( mem_id ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +344 :
  • servertoclient DBUpdateEntryString( string result, string table, string key, int msgid, int msgid2 );
    +345 : Ѩ ƻּص ئƥ ƻ +346 :
    +347 :
    string result +348 :
    successful failed +349 :
    string table +350 :
    +351 :
    int msgid +352 :
    +353 :
    int msgid2 +354 :
    +355 :
    +356 : +*/ + +void saacproto_DBUpdateEntryString_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBUpdateEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +369 :
  • servertoclient DBDeleteEntryString( string result, string table, string key , int msgid , int msgid2 );
    +370 : ٯ ޼ּ +371 :
    +372 :
    string result +373 :
    successful / failed +374 :
    string table +375 :
    +376 :
    string key +377 :
    +378 :
    int msgid +379 :
    +380 :
    int msgid2 +381 :
    +382 :
    +383 : +*/ + +void saacproto_DBDeleteEntryString_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBDeleteEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +396 :
  • servertoclient DBGetEntryString( string result, string value, string table, string key, int msgid, int msgid2 );
    +397 : ԻƼ߯Ի +398 :
    +399 :
    string result +400 :
    successful / failed +401 :
    string value +402 :
    +403 :
    string table +404 :
    +405 :
    string key +406 :
    +407 :
    int msgid +408 :
    +409 :
    int msgid2 +410 :
    +411 :
    +412 : +*/ + +void saacproto_DBGetEntryString_send( int fd,char* result,char* value,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryString" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( value ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +435 :
  • servertoclient DBUpdateEntryInt( string result , string table, string key, int msgid, int msgid2 );
    +436 : DBUpdateEntry +437 :
    +438 :
    string result +439 :
    succesful/failed +440 :
    string table +441 :
    Ƥ ë +442 :
    string key +443 :
    ƽë +444 :
    int msgid, int msgid2 +445 :
    msgid ë߯ʣ +446 :
    +447 :

    +448 : +*/ +#ifdef _ALLDOMAN // Syu ADD аNPC +void saacproto_UpdataStele_send( int fd , char *data ) +{ + saacproto_CreateHeader( saacproto.work , "UpdataStele" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( data ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_S_UpdataStele_send( int fd , char *ocdkey , char *oname , char *ncdkey , + char *nname , char *title , int level , int trns , int floor ) { + saacproto_CreateHeader( saacproto.work , "S_UpdataStele" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( ocdkey ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( oname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( ncdkey ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( nname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( title ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( level ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( trns ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( floor ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); + +} +#endif +void saacproto_DBUpdateEntryInt_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBUpdateEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +463 :
  • servertoclient DBGetEntryRank( string result , int rank , int count, string table, string key, int msgid, int msgid2 );
    +464 : ë߯ʣ +465 :
    +466 :
    string result +467 :
    successful/failed +468 :
    int rank +469 :
    ˣ1ë£ +470 :
    int count +471 :
    ʹ ټ޼0շԪ£ +472 :
    string table +473 :
    Ƥ ë +474 :
    string key +475 :
    ƽë +476 :
    int msgid, int msgid2 +477 :
    msgid ë߯ +478 :
    +479 :

    +480 : +481 : +*/ + +void saacproto_DBGetEntryRank_send( int fd,char* result,int rank,int count,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryRank" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( rank ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( count ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +494 :
  • servertoclient DBDeleteEntryInt( string result , string table, string key, int msgid, int msgid2 );
    +495 : ּ +496 :
    +497 :
    string result +498 :
    successful/failed +499 :
    string table +500 :
    Ƥ ë +501 :
    string key +502 :
    ƽë +503 :
    int msgid, int msgid2 +504 :
    msgid ë߯ +505 :
    +506 :

    +507 : +*/ + +void saacproto_DBDeleteEntryInt_send( int fd,char* result,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBDeleteEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +520 :
  • servertoclient DBGetEntryInt( string result , int value , string table, string key, int msgid, int msgid2 );
    +521 : ޼ë +522 :
    +523 :
    string result +524 :
    successful/failed +525 :
    int value +526 :
    ּ +527 :
    string table +528 :
    Ƥ ë +529 :
    string key +530 :
    ƽë +531 :
    int msgid, int msgid2 +532 :
    msgid ë߯ +533 :
    +534 : +535 : +536 : +*/ + +void saacproto_DBGetEntryInt_send( int fd,char* result,int value,char* table,char* key,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryInt" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( value ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( key ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +552 :
  • servertoclient DBGetEntryByRank( string result , string list , string table, int msgid, int msgid2 );
    +553 : DBGetEntryByRank +554 :
    +555 :
    string result +556 :
    +557 :
    string list +558 :
    "RANK,KEY,SCORE,INFO|RANK,KEY,SCORE,INFO|...."
    +559 : RANKƥؤ£KEY˱ئȻµʧëȻ +560 : ƽSCOREѰƥʧƥؤ£ +561 :
    +562 : "1,RINGO,123465,data1|2,HOGE,4567,data2|2,FUCK,4567,data3"
    +563 : 2˷2³ئ£ +564 :
    string table +565 :
    Ƥ +566 :
    int msgid, int msgid2 +567 :
    +568 :
    +569 : +570 : +*/ + +void saacproto_DBGetEntryByRank_send( int fd,char* result,char* list,char* table,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryByRank" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( list ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +583 :
  • servertoclient DBGetEntryByCount( string result , string list , string table, int count_start, int msgid, int msgid2 );
    +584 : DBGetEntryByCount +585 :
    +586 :
    string result +587 :
    SUCCESSFUL/FAILED +588 :
    string list +589 :
    1޼ؤԻ "INDEX,RANK,KEY,SCORE,INFO" 4ۼ +590 : ׬ƥؤԻľ "|" ƥئ£ѻ0 +591 : ٯ +592 :
    int num +593 :
    ʹԻʾ1ئ1ۣ2ئ2ۣ +594 :
    int msgid ,msgid2 +595 :
    ID. +596 :
    +597 : +*/ + +void saacproto_DBGetEntryByCount_send( int fd,char* result,char* list,char* table,int count_start,int msgid,int msgid2 ) +{ + saacproto_CreateHeader( saacproto.work , "DBGetEntryByCount" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( result ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( list ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( table ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( count_start ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( msgid2 ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +611 :
  • servertoclient Broadcast( string id, string charname, string message );
    +612 : Broadcastʧӡձءةӡ߼˪ +613 :
    +614 :
    string id +615 :
    user ID +616 :
    string charname +617 :
    character name +618 :
    string message +619 :
    +620 :
    int flag +621 :
    1б巴 ˪ľئУ +622 :
    +623 : +*/ + +void saacproto_Broadcast_send( int fd,char* id,char* charname,char* message ) +{ + saacproto_CreateHeader( saacproto.work , "Broadcast" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( message ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} +/* +642 :
  • servertoclient Message( string id_from, string charname_from, string id_to, string charname_to, string message , int option , int mesgid );
    +643 : ʧӡձءةӡ嶪ë˪£ +644 :
    +645 :
    string id_from +646 :
    from ID +647 :
    string charname_from +648 :
    from character name +649 :
    string id_to +650 :
    to ID +651 :
    string charname_to +652 :
    to character name +653 :
    string message +654 :
    ⼰ +655 :
    int option +656 :
    (ë) +657 :
    int mesgid +658 :
    ID ʧӡ +659 :
    +660 : +*/ + +void saacproto_Message_send( int fd,char* id_from,char* charname_from,char* id_to,char* charname_to,char* message,int option,int mesgid ) +{ + saacproto_CreateHeader( saacproto.work , "Message" ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id_from ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname_from ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( id_to ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( charname_to ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_string( message ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( option ) ,saacproto.workbufsize ); + saacproto_strcatsafe( saacproto.work , saacproto_mkstr_int( mesgid ) ,saacproto.workbufsize ); + saacproto_Send( fd , saacproto.work ); +} + +void saacproto_SetServerLogFiles( char *r , char *w ) +{ + saacproto_strcpysafe( saacproto_writelogfilename , w , sizeof(saacproto_writelogfilename )); + saacproto_strcpysafe( saacproto_readlogfilename , r , sizeof(saacproto_readlogfilename )); +} +int saacproto_InitServer( int (*writefunc)(int,char*,int) , int worksiz ) +{ + int i; + if( (void*)writefunc == NULL){saacproto.write_func = saacproto_default_write_wrap;} else {saacproto.write_func = writefunc;} + saacproto_AllocateCommonWork(worksiz); + saacproto_stringwrapper = (char**)calloc( 1,sizeof(char*) * MAXLSRPCARGS); + if(saacproto_stringwrapper ==NULL)return -1; + memset( saacproto_stringwrapper , 0, sizeof(char*)*MAXLSRPCARGS); + for(i=0;i +#include +#include +#ifndef WIN32 +#include +#include +#endif +#include "main.h" +#include "saacproto_util.h" +#ifdef saacproto__ENCRYPT +long saacproto_ringoCompressor( unsigned char *code , long codelen , unsigned char *text , long textlen); +long saacproto_ringoDecompressor( unsigned char *text , long textlen , unsigned char *code , long codelen); +#endif +/* + lsrpc routines +*/ +int saacproto_AllocateCommonWork(int bufsiz) +{ + saacproto.workbufsize = bufsiz; + saacproto.work = NULL; + saacproto.arraywork = NULL; + saacproto.escapework = NULL; + saacproto.val_str = NULL; + saacproto.token_list = NULL; + saacproto.cryptwork = NULL; + saacproto.jencodecopy = NULL; + saacproto.jencodeout = NULL; + saacproto.compresswork = NULL; + saacproto.work = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.arraywork = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.escapework = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.val_str = (char*)calloc( 1, saacproto.workbufsize ); + saacproto.token_list = (char**)calloc( 1, saacproto.workbufsize *sizeof( char** ) ); + saacproto.cryptwork = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.jencodecopy = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.jencodeout = (char*)calloc( 1, saacproto.workbufsize * 3 ); + saacproto.compresswork = (char*)calloc( 1, saacproto.workbufsize * 3 ); + memset( saacproto.work , 0, saacproto.workbufsize ); + memset( saacproto.arraywork , 0, saacproto.workbufsize ); + memset( saacproto.escapework , 0, saacproto.workbufsize ); + memset( saacproto.val_str , 0, saacproto.workbufsize ); + memset( (char*)saacproto.token_list ,0, saacproto.workbufsize*sizeof(char**) ); + memset( saacproto.cryptwork , 0, saacproto.workbufsize*3 ); + memset( saacproto.jencodecopy , 0, saacproto.workbufsize*3 ); + memset( saacproto.jencodeout , 0, saacproto.workbufsize*3 ); + memset( saacproto.compresswork , 0, saacproto.workbufsize*3 ); + if( saacproto.work == NULL || + saacproto.arraywork == NULL || + saacproto.escapework == NULL || + saacproto.val_str == NULL || + saacproto.token_list == NULL || + saacproto.cryptwork == NULL || + saacproto.jencodecopy == NULL || + saacproto.jencodeout == NULL || + saacproto.compresswork == NULL ){ + free( saacproto.work);free( saacproto.val_str); + free( saacproto.escapework);free( saacproto.arraywork ); + free( saacproto.token_list);free( saacproto.cryptwork ); + free( saacproto.jencodecopy);free( saacproto.jencodeout ); + free( saacproto.compresswork ); + return -1; + } + return 0; +} +/********** + Get message information from a network input +**********/ +void saacproto_GetMessageInfo( int *id , char *funcname , int len, char **tk ) +{ + if( tk[0] == NULL || tk[1] == NULL ){ + *id = 0; + saacproto_strcpysafe( funcname , "" , len ); + return; + } + *id = strtoul( tk[0] ,NULL,10); + saacproto_strcpysafe( funcname , tk[1] , len ); + return; +} +/******************************************** + string utilities +*********************************************/ +void saacproto_strcpysafe( char *dest, char *src, int maxlen ) +{ + int i; + for(i=0;i (int)( saacproto.workbufsize*3-2) ){ + fprintf( stderr, "lsgen: badly configured work buflen\n" ); + exit(1); + } + if( (flag%2) == 1 ) flag ++; + saacproto.compresswork[0] = flag; + memcpy( saacproto.compresswork+1,src,srclen ); + compressed_l = srclen + 1; + } else { + if((flag%2)==0)flag++; + saacproto.compresswork[0] = flag; + compressed_l = saacproto_ringoCompressor( + (unsigned char*)saacproto.compresswork + 1 , + (long)saacproto.workbufsize*3 - 1, + (unsigned char*)src , + (long)strlen(src) ) + 1; /* be careful! */ + } + /* return empty line if error or buffer excess */ + if( compressed_l <= 0 ){ + saacproto_strcpysafe( out , "\n" , maxoutlen ); + return; + } + memcpy( saacproto.jencodecopy ,saacproto.compresswork ,compressed_l ); + saacproto_jEncode( saacproto.jencodecopy , compressed_l , JENCODE_KEY , + saacproto.jencodeout, &jencodedlen , saacproto.workbufsize*3 -1 ); + saacproto_encode64( (unsigned char*)saacproto.jencodeout , jencodedlen, (unsigned char*)out ); +} +/* translate code64 text to original lsrpc text */ +static void saacproto_decodeString( char *src , char *out ) +{ + int compressed_l =0, outlen64; + int l; + long decompressed_l = 0; + /* copy src to copybuffer because jencoder modifies the input buffer */ + l = strlen( src ); + if( src[l-1]=='\n' || src[l-1]=='\r' )src[l-1]=0; + if( src[l-2]=='\n' || src[l-2]=='\r' )src[l-2]=0; + outlen64 = saacproto_decode64( (unsigned char*)src , (unsigned char*)saacproto.jencodecopy ); + saacproto_jDecode( saacproto.jencodecopy , outlen64 , JENCODE_KEY, + saacproto.compresswork , &compressed_l); + /*out[outlen]=0; PENDING*/ + if( (saacproto.compresswork[0] % 2 ) == 0 ){ + if( compressed_l <= 0 ){ + decompressed_l = 0; + fprintf( stderr, "LSRPC: too short:[%s]\n", src ); + } else { + memcpy( out, saacproto.compresswork+1, compressed_l -1 ); + decompressed_l = compressed_l -1; + } + } else { + decompressed_l = + saacproto_ringoDecompressor( (unsigned char*)out , + (long)saacproto.workbufsize , + (unsigned char*)saacproto.compresswork+1 , + (long)compressed_l -1 ); + } + out[decompressed_l] = 0; +} +/* followings are taken from code64.c */ +char saacproto_charset[64]={ + 'A','B','C','D', 'E','F','G','H', + 'I','J','K','L', 'M','N','O','P', + 'Q','R','S','T', 'U','V','W','X', + 'Y','Z','a','b', 'c','d','e','f', + 'g','h','i','j', 'k','l','m','n', + 'o','p','q','r', 's','t','u','v', + 'w','x','y','z', '0','1','2','3', + '4','5','6','7', '8','9','+','-' +}; +char saacproto_reversecharset[256]={ + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,62, 0,63,0,0, + 52,53,54,55, 56,57,58,59, + 60,61,0,0, 0,0,0,0, + 0,0,1,2, 3,4,5,6, + 7,8,9,10, 11,12,13,14, + 15,16,17,18, 19,20,21,22, + 23,24,25,0, 0,0,0,0, + 0,26,27,28, 29,30,31,32, + 33,34,35,36, 37,38,39,40, + 41,42,43,44, 45,46,47,48, + 49,50,51,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0, + 0,0,0,0, 0,0,0,0 +}; + +static void saacproto_encode64( unsigned char *in , int len , unsigned char *out ) +{ + int i; + int use_bytes; + int address = 0; + out[0] = 0; + for(i=0;;i+=3){ + unsigned char in1 , in2 , in3; + unsigned char out1 ,out2 , out3 , out4; + if( i >= len ) break; + if( i >= (len-1)){ /* the last letter ( to be thrown away ) */ + in1 = in[i] & 0xff; + in2 = in3 = 0; + use_bytes = 2; + } else if( i >= (len-2)){ /* the last 2 letters ( process only 1 byte)*/ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = 0; + use_bytes = 3; + } else { /* there are more or equal than 3 letters */ + in1 = in[i] & 0xff; + in2 = in[i+1] & 0xff; + in3 = in[i+2] & 0xff; + use_bytes = 4; + } + out1 = ((in1 & 0xfc)>>2) & 0x3f; + out2 = ((in1 & 0x03)<<4) | ((( in2 & 0xf0)>>4)&0x0f); + out3 = ((in2 & 0x0f)<<2) | ((( in3 & 0xc0)>>6)&0x03); + out4 = (in3 & 0x3f ); + if( use_bytes >= 2 ){ + out[address++] = saacproto_charset[out1]; + out[address++] = saacproto_charset[out2]; + out[address]=0; + } + if( use_bytes >= 3 ){ + out[address++] = saacproto_charset[out3]; + out[address]=0; + } + if( use_bytes >= 4 ){ + out[address++] = saacproto_charset[out4]; + out[address]=0; + } + } +} +/* + * Decode it + * char *in : encoded ascii chars + * char *out : decoded( output) + * return value : output byte count + * + * note: no need to have bigger buffer. because output is to + * be smaller than input string size + */ +static int saacproto_decode64( unsigned char *in , unsigned char *out ) +{ + unsigned char in1 , in2 , in3 , in4; + unsigned char out1 , out2 , out3; + int use_bytes; + int address= 0; + int i; + for(i=0;;i+=4 ){ + if( in[i] == 0 ){ + break; + } else if( in[i+1] == 0 ){ /* the last letter */ + break; + } else if( in[i+2] == 0 ){ /* the last 2 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = in4 = 0; + use_bytes = 1; + } else if( in[i+3] == 0 ){ /* the last 3 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = saacproto_reversecharset[in[i+2]]; + in4 = 0; + use_bytes = 2; + } else { /* process 4 letters */ + in1 = saacproto_reversecharset[in[i]]; + in2 = saacproto_reversecharset[in[i+1]]; + in3 = saacproto_reversecharset[in[i+2]]; + in4 = saacproto_reversecharset[in[i+3]]; + use_bytes = 3; + } + out1 = (in1<<2) | (((in2 & 0x30)>>4)&0x0f) ; + out2 = ((in2 & 0x0f )<<4) | ((( in3 & 0x3c)>>2)&0x0f); + out3 = ( (in3 &0x03)<<6) | ( in4 & 0x3f ); + if( use_bytes >= 1 ){ + out[address++] = out1; + } + if( use_bytes >= 2 ){ + out[address++] = out2; + } + if( use_bytes >= 3 ){ + out[address++] = out3; + } + if( use_bytes != 3 ){ + break; + } + } + return address; +} + +/* followings are taken from Jencode.c by jun */ +static void saacproto_jEncode(char *src,int srclen,int key,char *encoded,int *encodedlen,int maxencodedlen) +{ + char sum=0; + int i; + if(srclen+1 > maxencodedlen){ + *encodedlen = maxencodedlen; + for(i=0;i<(*encodedlen);i++)encoded[i] = src[i]; + } + if(srclen+1 <= maxencodedlen){ + *encodedlen=srclen+1; + for(i=0;i i) encoded[i] = src[i] + sum*((i*i)%3); + if(abs((key%srclen)) == i) encoded[i] = sum; + if(abs((key%srclen)) < i) encoded[i] = src[i-1] + sum*((i*i)%7); + } + } +} +static void saacproto_jDecode(char *src,int srclen,int key,char *decoded,int *decodedlen) +{ + char sum=0; + int i; + *decodedlen=srclen-1; + if( *decodedlen == 0 ){ + return; /* return error if length is 0 */ + } + sum = src[abs(key%(*decodedlen))]; + for(i=0;i i) decoded[i] = src[i] - sum*((i*i)%3); + if(abs((key%(*decodedlen))) < i) decoded[i-1] = src[i] - sum*((i*i)%7); + } + for(i=0;i<(*decodedlen);i++){ + if(((key%7) == (i%5))||((key%2) == (i%2)))decoded[i] = ~decoded[i]; + } +} + +/*****************************************************************/ +/* Compress / Decompress routine */ +/*****************************************************************/ +#define B00000000 0 +#define B00000001 1 +#define B00000010 2 +#define B00000011 3 +#define B00000100 4 +#define B00000101 5 +#define B00000110 6 +#define B00000111 7 +#define B00001000 8 +#define B00001001 9 +#define B00001010 10 +#define B00001011 11 +#define B00001100 12 +#define B00001101 13 +#define B00001110 14 +#define B00001111 15 +#define B00010000 16 +#define B00010001 17 +#define B00010010 18 +#define B00010011 19 +#define B00010100 20 +#define B00010101 21 +#define B00010110 22 +#define B00010111 23 +#define B00011000 24 +#define B00011001 25 +#define B00011010 26 +#define B00011011 27 +#define B00011100 28 +#define B00011101 29 +#define B00011110 30 +#define B00011111 31 +#define B00100000 32 +#define B00100001 33 +#define B00100010 34 +#define B00100011 35 +#define B00100100 36 +#define B00100101 37 +#define B00100110 38 +#define B00100111 39 +#define B00101000 40 +#define B00101001 41 +#define B00101010 42 +#define B00101011 43 +#define B00101100 44 +#define B00101101 45 +#define B00101110 46 +#define B00101111 47 +#define B00110000 48 +#define B00110001 49 +#define B00110010 50 +#define B00110011 51 +#define B00110100 52 +#define B00110101 53 +#define B00110110 54 +#define B00110111 55 +#define B00111000 56 +#define B00111001 57 +#define B00111010 58 +#define B00111011 59 +#define B00111100 60 +#define B00111101 61 +#define B00111110 62 +#define B00111111 63 +#define B01000000 64 +#define B01000001 65 +#define B01000010 66 +#define B01000011 67 +#define B01000100 68 +#define B01000101 69 +#define B01000110 70 +#define B01000111 71 +#define B01001000 72 +#define B01001001 73 +#define B01001010 74 +#define B01001011 75 +#define B01001100 76 +#define B01001101 77 +#define B01001110 78 +#define B01001111 79 +#define B01010000 80 +#define B01010001 81 +#define B01010010 82 +#define B01010011 83 +#define B01010100 84 +#define B01010101 85 +#define B01010110 86 +#define B01010111 87 +#define B01011000 88 +#define B01011001 89 +#define B01011010 90 +#define B01011011 91 +#define B01011100 92 +#define B01011101 93 +#define B01011110 94 +#define B01011111 95 +#define B01100000 96 +#define B01100001 97 +#define B01100010 98 +#define B01100011 99 +#define B01100100 100 +#define B01100101 101 +#define B01100110 102 +#define B01100111 103 +#define B01101000 104 +#define B01101001 105 +#define B01101010 106 +#define B01101011 107 +#define B01101100 108 +#define B01101101 109 +#define B01101110 110 +#define B01101111 111 +#define B01110000 112 +#define B01110001 113 +#define B01110010 114 +#define B01110011 115 +#define B01110100 116 +#define B01110101 117 +#define B01110110 118 +#define B01110111 119 +#define B01111000 120 +#define B01111001 121 +#define B01111010 122 +#define B01111011 123 +#define B01111100 124 +#define B01111101 125 +#define B01111110 126 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 +/* masks for first byte ( write )*/ +int saacproto_modifymask_first[8][9]={ + {0, B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111},/* mod 0*/ + {0, B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111},/* mod 1*/ + {0, B00000111,B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111},/* mod 2*/ + {0, B00001111,B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111},/* mod 3*/ + {0, B00011111,B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 4*/ + {0, B00111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 5*/ + {0, B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 6*/ + {0, B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111},/* mod 7*/ +}; +/* masks for second byte ( write ) */ +int saacproto_modifymask_second[8][9]={ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},/* mod 0 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001},/* mod 1 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011},/* mod 2 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111},/* mod 3 */ + {0, B00000000,B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111},/* mod 4 */ + {0, B00000000,B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111},/* mod 5 */ + {0, B00000000,B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111},/* mod 6 */ + {0, B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111},/* mod 7 */ +}; +/* + * used by bitstream routines + */ +int bitstream_maxbyte, bitstream_bitaddr ; +char *bitstream_buf; +/* initialize bitstream for output */ +static int initOutputBitStream( char *buf ,int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + memset( buf,0, buflen); + return 0; +} +/* initialize bitstream for input */ +static int initInputBitStream( char *buf , int buflen) +{ + bitstream_bitaddr = 0; + bitstream_maxbyte = buflen; + bitstream_buf = buf; + return 0; +} +/* + * read from bit stream. used only from 1 bit to 8 bits + * this is a base routine + */ +static unsigned int readInputBitStreamBody( int bwidth ) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return if excess */ + if( byteaddr >= bitstream_maxbyte)return 0; + if( bwidth >= 1 && bwidth <= 8){ + int b1 = (( bitstream_buf[byteaddr] & saacproto_modifymask_first[mod][bwidth] )>>mod); + int b2 = (( bitstream_buf[byteaddr+1] & saacproto_modifymask_second[mod][bwidth])<<(8-mod)); + bitstream_bitaddr += bwidth; + return b1 | b2; + } else { + return 0; + } +} +/* + * read from bit stream. used from 1 bit to 32 bits + * + */ +static unsigned int readInputBitStream( int bwidth ) +{ + if( bwidth <= 0 ){ + return 0; + } else if( bwidth >= 1 && bwidth <= 8 ){ + return readInputBitStreamBody( bwidth ); + } else if( bwidth >= 9 && bwidth <= 16 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody( bwidth-8); + return first + (second << 8 ); + } else if( bwidth >= 17 && bwidth <= 24 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ); + } else if( bwidth >= 25 && bwidth <= 32 ){ + unsigned int first = readInputBitStreamBody(8); + unsigned int second = readInputBitStreamBody(8); + unsigned int third = readInputBitStreamBody(8); + unsigned int forth = readInputBitStreamBody(bwidth-8); + return first + ( second << 8 ) + ( third << 16 ) + ( forth << 24 ); + } + return 0; +} +/* + * write to a bitstream. only used from 1 bit to 8 bits + * this is a base routine. + */ +static int writeOutputBitStreamBody( int bwidth , unsigned char b) +{ + int mod = bitstream_bitaddr % 8; + int byteaddr = bitstream_bitaddr / 8; + /* return error if excess */ + if( bitstream_maxbyte <= (byteaddr+1)) return -1; + bitstream_buf[byteaddr] &= saacproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr] |= (b << mod) & saacproto_modifymask_first[mod][bwidth]; + bitstream_buf[byteaddr+1] &= saacproto_modifymask_second[mod][bwidth]; + bitstream_buf[byteaddr+1] |= (b>>(8-mod))& saacproto_modifymask_second[mod][bwidth]; + bitstream_bitaddr += bwidth; + return byteaddr+1; +} +/* + * write to a bitstream. used from 1 bits to 32 bits + * returns -1 if error or buffer excession + */ +static int writeOutputBitStream( int bwidth, unsigned int dat) +{ + int ret; + if( bwidth <= 0){ + return -1; + } else if( bwidth >= 1 && bwidth <= 8 ){ + if((ret=writeOutputBitStreamBody( bwidth , (unsigned char)dat))<0)return -1; + } else if( bwidth > 8 && bwidth <= 16 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth - 8 , ( unsigned char)((dat>>8)&0xff)))<0)return -1; + } else if( bwidth > 16 && bwidth <= 24 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-16,(unsigned char)((dat>>16)&0xff)))<0)return -1; + } else if( bwidth > 24 && bwidth <= 32 ){ + if(writeOutputBitStreamBody( 8 , (unsigned char)(dat&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>8)&0xff))<0)return -1; + if(writeOutputBitStreamBody( 8 , (unsigned char)((dat>>16)&0xff))<0)return -1; + if((ret=writeOutputBitStreamBody( bwidth-24,(unsigned char)((dat>>24)&0xff)))<0)return -1; + } else { + return -1; + } + return ret; +} +#define CHAR_SIZE 256 +#define NODE_SIZE 512 +#define BITS_LEN 9 /* 9 bit lzw compression */ +typedef struct { + unsigned char chr; + int parent; + int brother; + int child; +}NODE; +long saacproto_ringoCompressor( unsigned char *code , long codelen , + unsigned char *text , long textlen) +{ + NODE node[NODE_SIZE]; + int freeNode; + int w,k; /* used in this algo */ + int textind; /* index to text buffer */ + int i; + int position = 0; /* indicates the last byte of code buffer */ + if( textlen <= 0 ) return -1; + initOutputBitStream((char*) code,codelen); + /* fill characters ( 0 ~ 255 ) in the beggining part of + Node list */ + for(i=0; i<= CHAR_SIZE; i++){ + node[i].chr = (unsigned char)i; + node[i].brother = i + 1; + node[i].parent = 0; + node[i].child = 0; + } + node[CHAR_SIZE].brother = 0; + freeNode = CHAR_SIZE + 1; + w = text[0]; + textind = 1; + while(1){ + int rv; + if( textind >= textlen ){ + k = CHAR_SIZE; /* indicates EOF */ + } else { + k = text[textind]; + } + /* search if pattern 'wk' is registered or not. */ + rv = node[w].child; + while(1){ + if( rv <= 0 ) break; + if( node[rv].chr == k ) break; + rv = node[rv].brother; + } + if( rv > 0 ){ + /* found it */ + w = rv; + } else { + position = writeOutputBitStream( BITS_LEN ,w ); + /* return if buffer excession */ + if( position > codelen ) return -1; + /* register pattern 'wk' in the dictionary */ + if( freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = k; + } + if( textind == ( textlen + 1 ) ) break; + textind++; + } + return position; +} + +/* + * Decoder. + * return -1 if buffer excession. Notice buffer text + * is modified . + */ +long saacproto_ringoDecompressor( unsigned char *text , long textlen , + unsigned char *code , long codelen) +{ + NODE node[NODE_SIZE]; + int stack[NODE_SIZE]; + int sp; + int freeNode; + int len; + int i; + int k = 0; + int w = 0; + if( codelen <= 0 ) return -1; + initInputBitStream( (char*)code , codelen ); + for(i=0;i= freeNode ){ + stack[sp++] = k; /* exception */ + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) )return -1; + k = w; + } else { + k = rv; + } + while(k> CHAR_SIZE ){ + if( k >= (sizeof(node)/sizeof(node[0]))) return -1; + stack[sp++] = node[k].chr; + k = node[k].parent; + if( sp >=( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + } + stack[sp++] = k; + if( sp >= ( sizeof( stack ) /sizeof(stack[0] )) ) return -1; + /* output to text buffer from stack.*/ + while(sp){ + if( ++len > textlen ) return -1; + *text++ = stack[--sp]; + } + /* register the pattern 'wk'*/ + if( len > 1 && freeNode < NODE_SIZE ){ + node[freeNode].parent = w; + node[freeNode].chr = k; + if( w >= (sizeof(node)/sizeof(node[0])))return -1; + node[freeNode].brother = node[w].child; + node[freeNode].child = 0; + node[w].child = freeNode; + freeNode++; + } + w = rv; + } + return len; +} +#endif /* ifdef saacproto__ENCRYPT */ + +/* Convert 62-base digits to 10 digits */ +int saacproto_a62toi( char *a ) +{ + int ret = 0; + int minus ; + if( a[0] == '-' ){ + minus = -1; + a++; + } else { + minus = 1; + } + + while( *a != '\0' ) + { + ret *= 62; + if( '0' <= (*a) && (*a) <= '9' ) + ret += (*a)-'0'; + else + if( 'a' <= (*a) && (*a) <= 'z' ) + ret += (*a)-'a'+10; + else + if( 'A' <= (*a) && (*a) <= 'Z' ) + ret += (*a)-'A'+36; + else + return 0; + a++; + } + return ret * minus; +} + +/* Convert 10-base digits into 62-base digits. */ +char *saacproto_cnv10to62( int a, char *out, int outlen ) +{ + int i, j; + char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + int tmp[64]; + int src; + int minus; + int baselen = sizeof( base)-1; + if( a < 0 ){ + minus = 1; + a *= -1; + } else { + minus = 0; + } + /* special case */ + if( a < baselen) { + if( minus ){ + *(out) = '-'; + *(out+1) = base[a]; + *(out+2) = '\0'; + return (out); + } else { + *out = base[a]; + *(out+1) = '\0'; + return( out); + } + } + src = a; + for( i = 0; src >= baselen; i ++ ) { + tmp[i] = src % baselen; + src /= baselen; + } + i--; + if( minus ){ + *out = '-'; + *(out+1) = base[src]; + for( j = 2; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } else { + *out = base[src]; + for( j = 1; i >= 0; i --, j ++ ) { + if( j > outlen - 2 ) return NULL; + *(out+j) = base[tmp[i]]; + } + } + *(out+j) = '\0'; + return( out); +} diff --git a/石器时代服务器端最新完整源代码/Serv/saac/sasql_bbs.c b/石器时代服务器端最新完整源代码/Serv/saac/sasql_bbs.c new file mode 100644 index 0000000..304df27 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/sasql_bbs.c @@ -0,0 +1,668 @@ +#define _SASQL_C_ + +#include "version.h" + +#ifdef _SASQL// + +#include "main.h" +#include "sasql.h" +#include "util.h" +#include "md5.h" +#include + +MYSQL mysql; +MYSQL_RES *mysql_result; +MYSQL_ROW mysql_row; +MYSQL_FIELD *fields; + +typedef struct tagConfig +{ + char sql_IP[16]; + + int sql_Port; + + char sql_Port1[16]; + + char sql_ID[16]; + + char sql_PS[16]; + + char sql_DataBase[16]; + + char sql_Table[32]; + + char sql_LOCK[16]; + + char sql_NAME[16]; + + char sql_PASS[16]; + + int AutoReg; + + int openbackground; +}Config; + +Config config; + +static int readSqlConfig( char *path ) +{ + char buf[255]; + FILE *fp; + + fp = fopen( path , "r" ); + if( fp == NULL ){ return -2; } + + while( fgets( buf , sizeof( buf ) , fp )){ + char command[255]; + char param[255]; + chop(buf); + + easyGetTokenFromString( buf , 1 , command , sizeof( command )); + easyGetTokenFromString( buf , 2 , param , sizeof( param )); + + if( strcmp( command , "sql_IP" ) == 0 ){ + strcmp( config.sql_IP , param ) ; + snprintf( config.sql_IP , sizeof( config.sql_IP) , param ); + printf("\nݿַ %s",config.sql_IP); + } else if( strcmp( command , "sql_Port" ) == 0 ){ + config.sql_Port = atoi( param ); + snprintf( config.sql_Port1 , sizeof( config.sql_Port1) , param ); + printf("\nݿ˿ڣ %d",config.sql_Port); + } else if( strcmp( command , "sql_ID" ) == 0 ){ + strcmp( config.sql_ID , param ) ; + snprintf( config.sql_ID , sizeof( config.sql_ID) , param ); + printf("\nݿû %s",config.sql_ID); + } else if( strcmp( command , "sql_PS" ) == 0 ){ + strcmp( config.sql_PS , param ) ; + snprintf( config.sql_PS , sizeof( config.sql_PS) , param ); + printf("\nݿ룺 %s",config.sql_PS); + } else if( strcmp( command , "sql_DataBase" ) == 0 ){ + strcmp( config.sql_DataBase , param ) ; + snprintf( config.sql_DataBase , sizeof( config.sql_DataBase) , param ); + printf("\n½ݿ%s",config.sql_DataBase); + } else if( strcmp( command , "sql_Table" ) == 0 ){ + strcmp( config.sql_Table , param ) ; + snprintf( config.sql_Table , sizeof( config.sql_Table) , param ); + printf("\nûϢ %s",config.sql_Table); + } else if( strcmp( command , "sql_LOCK" ) == 0 ){ + strcmp( config.sql_LOCK , param ) ; + snprintf( config.sql_LOCK , sizeof( config.sql_LOCK) , param ); + printf("\nû %s",config.sql_LOCK); + } else if( strcmp( command , "sql_NAME" ) == 0 ){ + strcmp( config.sql_NAME , param ) ; + snprintf( config.sql_NAME , sizeof( config.sql_NAME) , param ); + printf("\n˺ֶƣ %s",config.sql_NAME); + } else if( strcmp( command , "sql_PASS" ) == 0 ){ + strcmp( config.sql_PASS , param ) ; + snprintf( config.sql_PASS , sizeof( config.sql_PASS) , param ); + printf("\nֶƣ %s",config.sql_PASS); + } else if( strcmp( command , "openbackground" ) == 0 ){ + config.openbackground = atoi( param ); + if(config.openbackground == 1){ + printf("\n̨ܣ YES"); + }else{ + printf("\n̨ܣ NO"); + } + } else if( strcmp( command , "AutoReg" ) == 0 ){ + config.AutoReg = atoi( param ); + if(config.AutoReg){ + printf("\nԶע᣺YES"); + }else{ + printf("\nԶע᣺NO"); + } + } + } + fclose(fp); + return 0; +} + +BOOL sasql_init( void ) +{ + if( (mysql_init(&mysql) == NULL) & readSqlConfig("acserv.cf")) + { + printf("\nݿʼʧܣ"); + exit(1); + return FALSE; + } + + if( !mysql_real_connect( &mysql, + config.sql_IP, + config.sql_ID,//ʺ + config.sql_PS,// + config.sql_DataBase,//ѡϿ + config.sql_Port, + NULL, + 0 ) ) + { + printf("\nݿʧܣ\n"); + return FALSE; + } + + mysql_query(&mysql,"set names 'gbk'"); + printf("\nݿӳɹ\n"); + return TRUE; +} + +int sasql_mysql_query( char *sqlstr ) +{ + mysql_query(&mysql,"set names 'gbk'"); + return mysql_query(&mysql,sqlstr); +} + +void sasql_close( void ) +{ + mysql_close( &mysql ); +} + + +int sasql_query(char *nm, char *pas){ + char sqlstr[256]; + sprintf(sqlstr,"select `%s`, `salt` from %s where %s=BINARY'%s'",config.sql_PASS, config.sql_Table,config.sql_NAME,nm); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + char token[64]; + mysql_row=mysql_fetch_row(mysql_result); + strcpy(token, mysql_row[0]); +#ifdef _OLDPS_TO_MD5PS + if(strlen(mysql_row[0])>16){ + char md5pas[256]; + char salt[256]; + char md5passalt[256]; + strcpy(salt, mysql_row[1]); + strcpy(md5pas, MD5String(pas)); + sprintf(md5passalt, "%s%s", md5pas, salt); + if(strcmp(MD5String(md5passalt),token) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } + }else{ + if(strcmp(pas,token) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } + } +#else + if(strcmp(pas,token) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } +#endif + }else{ + printf("û%sδעᣡ\n",nm); + return 3; + } + }else{ + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return 0; + } +} + + +#ifdef _SQL_BACKGROUND +BOOL sasql_online( char *ID, char *NM, char *IP, int flag ) +{ + if(config.openbackground == 1){ + char sqlstr[256]; + if(flag==0) + sprintf(sqlstr,"update %s set Online=0 where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, ID); + else if(flag==1) + sprintf(sqlstr,"update %s set LoginTime=NOW(), MAC='%s', IP='%s', Online=1 where %s=BINARY'%s'", config.sql_Table, MAC, IP, config.sql_NAME, ID); + else if(flag==2) + sprintf(sqlstr,"update %s set LoginTime=NOW(), OnlineName='%s', Online=1, Path='char/0x%x'where %s=BINARY'%s'", config.sql_Table, NM, getHash(ID) & 0xff, config.sql_NAME, ID); + else if(flag==3) + sprintf(sqlstr,"update %s set Online=0", config.sql_Table); + if(!sasql_mysql_query(sqlstr)){ + return TRUE; + } + printf("\nݿʧ%s\n", sqlstr); + } + return TRUE; +} +#endif + +#ifdef _SQL_REGISTER +BOOL sasql_register(char *id, char *ps) +{ + char sqlstr[256]; + if(config.AutoReg!=1)return FALSE; +#ifdef _OLDPS_TO_MD5PS + sprintf(sqlstr,"INSERT INTO %s (%s,%s,RegTime,Path) VALUES (BINARY'%s','%s',NOW(),'char/0x%x')",config.sql_Table, config.sql_NAME, config.sql_PASS, id, MD5String(ps), getHash(id) & 0xff); +#else + sprintf(sqlstr,"INSERT INTO %s (%s,%s,RegTime,Path) VALUES (BINARY'%s','%s',NOW(),'char/0x%x')",config.sql_Table, config.sql_NAME, config.sql_PASS, id, ps, getHash(id) & 0xff); +#endif + + if(!sasql_mysql_query(sqlstr)){ + printf("\nûעɹ\n"); + return TRUE; + } + printf("\nûעʧܣ\n"); + return FALSE; +} +#endif + + +BOOL sasql_chehk_lock( char *idip ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select * from `%s` where Name='%s'", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + return TRUE; + } + } + return FALSE; +} + +BOOL sasql_add_lock( char *idip ) +{ + char sqlstr[256]; + sprintf(sqlstr,"INSERT INTO `%s` (Name) VALUES (BINARY'%s')", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + printf("\n%sɹ\n",idip); + return TRUE; + } + return FALSE; +} + +BOOL sasql_del_lock( char *idip ) +{ + char sqlstr[256]; + sprintf(sqlstr,"delete from `%s` where Name=BINARY'%s'", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + printf("\n%sɹ\n",idip); + return TRUE; + } + return FALSE; +} + +#ifdef _NEW_VIP_SHOP +int sasql_query_point( char *name ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, name); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + return atoi(mysql_row[0]); + } + } + return -1; +} + + +BOOL sasql_add_vippoint( char *ID, int point ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select VipPoint from %s where %s=BINARY'%s'",config.sql_Table,config.sql_NAME,ID); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + point+=atoi(mysql_row[0]); + if(point < 0){ + printf("%sԱС0\n",ID); + return -1; + } + sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", config.sql_Table, point,config.sql_NAME, ID); + if(!sasql_mysql_query(sqlstr)){ + printf("û%sǰԱ%d\n",ID,point); + return point; + } + } + } + printf("޸%sԱʧܣ\n",ID); + return -1; +} +#endif + +#ifdef _ITEM_PET_LOCKED +char *sasql_ItemPetLocked( char *id, char *safepasswd ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select SafePasswd from `%s` where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + if(strcmp(safepasswd, mysql_row[0])==0){ + return "ȫѾɹ"; + }else{ + return "󣬰ȫ޷⿪"; + } + }else{ + return "δðȫ룬ΪȷȫһλΪȫ벢ͼס"; + } + } + } + return "޷뱾Աϵ"; +} + +char *sasql_ItemPetLocked_Passwd( char *id, char *safepasswd ) +{ + char sqlstr[256]; + sprintf(sqlstr,"update %s set SafePasswd=BINARY'%s' where %s=BINARY'%s'", config.sql_Table, safepasswd, config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + return "ȫ޸ijɹƱİȫ룡"; + } + return "ȫ޸ʧܣ뱾Աϵ"; +} + +BOOL sasql_ItemPetLocked_Char( char *id, char *safepasswd ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select safepasswd from %s where %s=BINARY'%s'", config.sql_Table,config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + if(strcmp(safepasswd,mysql_row[0]) == 0){ + return 1; + }else{ + printf("û%sȫ\n",id); + return -1; + } + }else{ + return 0; + } + }else{ + printf("û%sδעᣡ\n",id); + return -1; + } + }else{ + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; + } +} +#endif + +#ifdef _ONLINE_COST +char *sasql_OnlineCost( char *id, char *costpasswd ) +{ + char sqlstr[256]; + static char token[256]=""; + sprintf(sqlstr,"select `CostVal`, `check` from `OnlineCost` where CostPasswd = BINARY'%s'", costpasswd); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(atoi(mysql_row[1]) == 1){ + int costval = atoi(mysql_row[0]); + int vippoint = sasql_add_vippoint(id, costval); + sprintf(sqlstr,"update OnlineCost set cdkey=BINARY'%s', CostTime=NOW(), `check`=0 where CostPasswd=BINARY'%s'", id, costpasswd); + if(!sasql_mysql_query(sqlstr)){ + log("ֵ%sѳֵ\n",costpasswd); + } + sprintf(token, "ֵѳɹֵֵΪ%dǰԱ%d", costval, vippoint); + return token; + }else{ + return "óֵʹùظʹã"; + } + }else{ + return "ֵʧܣóֵ벻ȷ"; + } + } + return "ֵʧܣ뱾Աϵ"; +} + +void sasql_OnlineCost_add( int cost, int num) +{ + char sqlstr[256]; + char CostPasswd[32]; + memset( CostPasswd, 0, sizeof( CostPasswd ) ); + int i, j, k=0; + for(i=0;i0){ + mysql_row=mysql_fetch_row(mysql_result); + if(atoi(mysql_row[1]) == 1){ + char *coststr = mysql_row[0]; + sprintf(sqlstr,"update OnlineBuy set cdkey=BINARY'%s', CostTime=NOW(), `check`=0 where CostPasswd=BINARY'%s'", id, costpasswd); + if(!sasql_mysql_query(sqlstr)){ + log("%sȡ\n",costpasswd); + } + sprintf(token, "%c|%s", costpasswd[0], coststr); + + return token; + }else{ + return "ʹùظʹã"; + } + }else{ + return "ʧܣ벻ȷ"; + } + } + return "ʧܣ뱾Աϵ"; +} + +void sasql_OnlineBuy_add( char *coststr, int type, int num ) +{ + char sqlstr[256]; + char CostPasswd[32]; + int i, j, k=0; + for(i=0;i= 2){ + printf("ɹ%dʯ\n", k); + } + return ; +} + +#endif + + +int sasql_onlinenum( char *IP ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select count(*) from %s where Online=1 and IP='%s'",config.sql_Table,IP); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + return atoi(mysql_row[0]); + } + } + return 0; +} + +#ifdef _FORMULATE_AUTO_PK +BOOL sasql_add_FormulateAutoPk( char *ID, int point ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select PKPoint from %s where %s=BINARY'%s'",config.sql_Table,config.sql_NAME,ID); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + point+=atoi(mysql_row[0]); + if(point < 0){ + return -1; + } + sprintf(sqlstr,"update %s set PKPoint=%d where %s=BINARY'%s'", config.sql_Table, point,config.sql_NAME, ID); + if(!sasql_mysql_query(sqlstr)){ + return point; + } + } + } + return -1; +} +#endif + +#ifdef _OLDPS_TO_MD5PS +void sasql_OldpsToMd5ps() +{ + char sqlstr[256]; + sprintf(sqlstr,"select %s, %s from %s",config.sql_NAME, config.sql_PASS, config.sql_Table); + if(!sasql_mysql_query(sqlstr)){ + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + printf(" ת˺ ԭ תMD5\n"); + while((mysql_row = mysql_fetch_row(mysql_result))){ + char * name = mysql_row[0]; + char * ps = mysql_row[1]; + if(strlen(ps)<=16) { + sprintf(sqlstr,"update %s set %s=BINARY'%s' where %s=BINARY'%s'", config.sql_Table, config.sql_PASS, MD5String(ps),config.sql_NAME, name); + if(!sasql_mysql_query(sqlstr)){ + printf("%16s %16s %32s\n", name, ps, MD5String(ps)); + } + } + } + } +} +#endif + + +#ifdef _CHARADATA_SAVE_SQL +void sasql_charadata_Save(char *id, char* table, char *data, int saveindex, int flag) +{ + if(strlen(data)==0)return; + + char sqlstr[1024*16]; + + if(flag==INSERT){ + sprintf(sqlstr, "INSERT INTO %s VALUES %s" , table, data); + }else if(flag==SELECT){ + }else if(flag==UPDATE){ + sprintf(sqlstr, "UPDATE %s set %s WHERE CHAR_CDKEY=BINARY'%s' and CHAR_SAVEINDEX=%d" , table, data, id, saveindex); + }else if(flag==DELETE){ + sprintf(sqlstr, "DELETE FROM %s WHERE CHAR_CDKEY=BINARY'%s' and CHAR_SAVEINDEX=%d" , table, id, saveindex); + } + + if(!mysql_query(&mysql,sqlstr)){ + if(flag==DELETE){ + sasql_charadata_Save(id, table, data, saveindex, INSERT); + } + return; + }else{ + printf(table); + if(flag==INSERT){ + printf(" INSERT error\n"); + }else if(flag==SELECT){ + printf(" SELECT error\n"); + }else if(flag==UPDATE){ + printf(" UPDATE error\n"); + }else if(flag==DELETE){ + printf(" DELETE error\n"); + } + } +} + +#endif + + +BOOL sasql_craete_userinfo( void ) +{ + return FALSE; +} + +BOOL sasql_craete_lock( void ) +{ + return FALSE; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/sasql_cygwin.c b/石器时代服务器端最新完整源代码/Serv/saac/sasql_cygwin.c new file mode 100644 index 0000000..a02b314 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/sasql_cygwin.c @@ -0,0 +1,534 @@ +#define _SASQL_C_ + +#include "version.h" + +#ifdef _SASQL// + +#include "main.h" + +#include +#include +#include + +HENV henv = SQL_NULL_HENV; +HDBC hdbc = SQL_NULL_HDBC; +HSTMT hstmt = SQL_NULL_HSTMT; +RETCODE rc; + + SQLCHAR sid[16]; + SQLCHAR sps[16]; + SQLINTEGER err; + +typedef struct tagConfig +{ + char SQL_DSN[16]; + + char SQL_USER[16]; + + char SQL_INFOTABLE[16]; + + char SQL_LOCK[16]; + + char SQL_RegTime[16]; + + char SQL_LoginTime[16]; + + char SQL_OnlineName[16]; + +}Config; + +Config config; + +int AUTOREG; +int USEMSSQL; +void check_return (RETCODE rc,HENV henv,HDBC hdbc,HSTMT hstmt ); + +static int readConfig( char *path ) +{ + char buf[255]; + FILE *fp; + + fp = fopen( path , "r" ); + if( fp == NULL ){ return -2; } + + while( fgets( buf , sizeof( buf ) , fp )){ + char command[255]; + char param[255]; + chop(buf); + + easyGetTokenFromString( buf , 1 , command , sizeof( command )); + easyGetTokenFromString( buf , 2 , param , sizeof( param )); + + if( strcmp( command , "USEMSSQL" ) == 0 ){ + USEMSSQL = atoi( param ); + if(USEMSSQL==0)break; + } + if( strcmp( command , "SQL_DSN" ) == 0 ){ + snprintf( config.SQL_DSN , sizeof( config.SQL_DSN) , param) ; + log("ݿ DSN%s\n",config.SQL_DSN); + } else if( strcmp( command , "SQL_INFOTABLE" ) == 0 ){ + snprintf( config.SQL_INFOTABLE , sizeof( config.SQL_INFOTABLE) , param) ; + log("Ϣ%s\n",config.SQL_INFOTABLE); + } else if( strcmp( command , "SQL_LOCK" ) == 0 ){ + snprintf( config.SQL_LOCK , sizeof( config.SQL_LOCK) , param) ; + log("˺ű%s\n",config.SQL_LOCK); + } else if( strcmp( command , "SQL_REGTIME" ) == 0 ){ + snprintf( config.SQL_RegTime , sizeof( config.SQL_RegTime) , param) ; + log("עʱ䣺%s\n",config.SQL_RegTime); + } else if( strcmp( command , "AUTOREG" ) == 0 ){ + AUTOREG = atoi( param ); + if(AUTOREG){ + log("Զע᣺YES\n"); + }else{ + log("Զע᣺NO\n"); + } + } + } + fclose(fp); + return 0; +} + +BOOL sasql_init( void ) +{ + + readConfig("acserv.cf"); + if(USEMSSQL==0)return TRUE; + char buf[257]; + char ODBC[257]; + short buflen; +// printf ("Initialize the environment structure.\n"); + SQLAllocEnv (&henv); + +// printf ("Initialize the connection structure.\n"); + SQLAllocConnect (henv,&hdbc); + + printf("ODBC..."); + sprintf(ODBC,"DSN=%s",config.SQL_DSN); + + rc = SQLDriverConnect(hdbc,0,ODBC,SQL_NTS,(UCHAR*) buf,sizeof (buf),&buflen,SQL_DRIVER_COMPLETE); + check_return (rc,henv,hdbc,hstmt); + printf ("ɹ\n"); + SQLAllocStmt (hdbc,&hstmt); + SQLBindCol(hstmt, 1, SQL_C_CHAR,&sid,16, &err); + SQLBindCol(hstmt, 2, SQL_C_CHAR,&sps,16, &err); +} + +void sasql_close( void ) +{ + if(USEMSSQL==0)return; +// printf ("Free the statement handle.\n"); + SQLFreeStmt (hstmt,SQL_DROP); + +// printf ("Disconnect from the data source.\n"); + SQLDisconnect (hdbc); + +// printf ("Free the connection structure.\n"); + SQLFreeConnect (hdbc); + +// printf ("Free the environment structure.\n"); + SQLFreeEnv (henv); +} + +void check_return (RETCODE rc,HENV henv,HDBC hdbc,HSTMT hstmt ) +{ + UCHAR state_str [SQL_MAX_MESSAGE_LENGTH]; + SDWORD native_error; + UCHAR error_msg [SQL_MAX_MESSAGE_LENGTH]; + SWORD error_msg_avail = SQL_MAX_MESSAGE_LENGTH - 1; + SWORD error_msg_len; + RETCODE local_rc; + + if (rc != SQL_ERROR && rc != SQL_SUCCESS_WITH_INFO ) + { + return; + } + + local_rc = SQLError(henv,hdbc,hstmt,state_str,&native_error,error_msg,error_msg_avail,&error_msg_len); + if (local_rc != SQL_SUCCESS && rc !=SQL_SUCCESS_WITH_INFO) + { + fprintf(stderr,"Uninterpretable error; exiting \n"); + exit (EXIT_FAILURE); + } + + if (rc == SQL_SUCCESS_WITH_INFO) + { + fprintf(stderr,"Fatal Error %s: %s\n", state_str,error_msg); + return; + } + + fprintf(stderr,"Fatal Error %s: %s\n",state_str,error_msg); + exit (EXIT_FAILURE); +} + +int sasql_query(char *id, char *ps) +{ + if(USEMSSQL==0)return TRUE; + SQLCHAR sqlstr[128]; + SQLCHAR szPass[64]={0}; + SQLINTEGER cbPass; + SQLCancel(hstmt); + sprintf(sqlstr,"select PassWord from %s where Name='%s'",config.SQL_INFOTABLE,id); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + while( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szPass, 50, &cbPass) == SQL_SUCCESS) + if(strcmp(szPass,ps)==0){ + return 1; + }else{ + printf("˺%s!\n",id); + return 2; + } + } + printf("˺%sδע!\n",id); + return 3; + } + return 0; +} + +BOOL sasql_register(char *id, char *ps) +{ + if(AUTOREG){ + SQLCHAR sqlstr[128]; + SQLCancel(hstmt); + sprintf(sqlstr,"select * from %s where Name='%s'",config.SQL_INFOTABLE, id); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + while( SQL_SUCCESS == SQLFetch(hstmt) ) + return FALSE; + SQLCancel(hstmt); + sprintf(sqlstr,"INSERT INTO %s (Name,PassWord,RegTime,Path) VALUES ('%s','%s',NOW(),'char/0x%x')",config.SQL_INFOTABLE, id, ps, getHash(id) & 0xff); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO){ + printf("˺%sעɹ!\n",id); + return TRUE; + } + } + } + return FALSE; +} + +BOOL sasql_craete_lock( void ) +{ + char sqlstr[128]; + SQLCancel(hstmt); + sprintf(sqlstr,"create table %s (Name varchar(16),PRIMARY KEY (Name));",config.SQL_LOCK); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + printf("ûɹ!\n"); + return TRUE; + } + printf("ûʧ!\n"); + return FALSE; +} + +BOOL sasql_craete_userinfo( void ) +{ + char sqlstr[255]; + SQLCancel(hstmt); + sprintf(sqlstr,"CREATE TABLE %s (" + "Name varchar(16) NOT NULL," + "PassWord varchar(16) NOT NULL," + "IP varchar(16)," + "RegTime datetime," + "LoginTime datetime," + "OnlineName varchar(32)," + "Online int," + "Path varchar(10)," + "PRIMARY KEY (Name));",config.SQL_INFOTABLE); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + printf("ûϢɹ!\n"); + return TRUE; + } + printf("ûϢʧ!\n"); + return FALSE; +} + +BOOL sasql_chehk_lock( char *idip ) +{ + char sqlstr[128]; + SQLCancel(hstmt); + sprintf(sqlstr,"select * from %s where Name='%s'", config.SQL_LOCK, idip); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + while( SQL_SUCCESS == SQLFetch(hstmt) ) + return TRUE; + } + return FALSE; +} + +BOOL sasql_add_lock( char *idip ) +{ + char sqlstr[128]; + SQLCancel(hstmt); + + sprintf(sqlstr,"INSERT INTO %s (Name) VALUES ('%s')", config.SQL_LOCK, idip); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + return TRUE; + } + return FALSE; +} + +BOOL sasql_del_lock( char *idip ) +{ + char sqlstr[128]; + SQLCancel(hstmt); + + sprintf(sqlstr,"delete from config.SQL_LOCK where Name='%s'", config.SQL_LOCK, idip); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + return TRUE; + } + return FALSE; +} + + +#ifdef _SQL_BACKGROUND +BOOL sasql_online( char *ID, char *NM, char *IP, int flag ) +{ + char sqlstr[256]; + SQLCancel(hstmt); + if(flag==0) + sprintf(sqlstr,"update %s set Online=0 where Name='%s'", config.SQL_INFOTABLE, ID); + else if(flag==1) + sprintf(sqlstr,"update %s set LoginTime=NOW(), IP='%s', Online=1 where Name='%s'", config.SQL_INFOTABLE, IP, ID); + else if(flag==2) + sprintf(sqlstr,"update %s set LoginTime=NOW(), OnlineName='%s', Online=1 where Name='%s'", config.SQL_INFOTABLE, NM, ID); + else if(flag==3) + sprintf(sqlstr,"update %s set Online=0", config.SQL_INFOTABLE); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + return TRUE; + } + } + + printf("\nݿʧܣ\n"); + return FALSE; +} +#endif + + +int sasql_onlinenum( char *IP ) +{ + char sqlstr[256]; + SQLCHAR szNum[64]={0}; + SQLINTEGER cbNum; + SQLCancel(hstmt); + + sprintf(sqlstr,"select count(*) from %s where Online=1 and IP='%s'",config.SQL_INFOTABLE,IP); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szNum, 50, &cbNum) == SQL_SUCCESS){ + return atoi(szNum); + } + } + } + return 0; +} + + +#ifdef _NEW_VIP_SHOP +int sasql_query_point( char *name ) +{ + char sqlstr[256]; + SQLCHAR szPoint[64]={0}; + SQLINTEGER cbPoint; + SQLCancel(hstmt); + + sprintf(sqlstr,"select VipPoint from `%s` where Name='%s'", config.SQL_INFOTABLE, name); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szPoint, 50, &cbPoint) == SQL_SUCCESS){ + return atoi(szPoint); + } + } + } + return -1; +} + + +BOOL sasql_add_vippoint( char *ID, int point ) +{ + char sqlstr[256]; + SQLCHAR szPoint[64]={0}; + SQLINTEGER cbPoint; + SQLCancel(hstmt); + + sprintf(sqlstr,"select VipPoint from %s where Name='%s'",config.SQL_INFOTABLE, ID); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szPoint, 50, &cbPoint) == SQL_SUCCESS){ + point+=atoi(szPoint); + if(point < 0){ + printf("%sԱС0\n",ID); + return -1; + } + SQLCancel(hstmt); + sprintf(sqlstr,"update %s set VipPoint=%d where NAME='%s'", config.SQL_INFOTABLE, point, ID); + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO){ + printf("û%sǰԱ%d\n",ID,point); + return point; + } + } + } + } + printf("޸%sԱʧܣ\n",ID); + return -1; +} +#endif + +#ifdef _ITEM_PET_LOCKED +char *sasql_ItemPetLocked( char *id, char *safepasswd ) +{ + char sqlstr[256]; + SQLCHAR szSafePasswd[32]={0}; + SQLINTEGER cbSafePasswd; + SQLCancel(hstmt); + + sprintf(sqlstr,"select SafePasswd from `%s` where Name='%s'", config.SQL_INFOTABLE, id); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szSafePasswd, 50, &cbSafePasswd) == SQL_SUCCESS){ + if( strlen(szSafePasswd)>0){ + if(strcmp(safepasswd, szSafePasswd)==0){ + return "ȫѾɹ"; + }else{ + return "󣬰ȫ޷⿪"; + } + }else{ + return "δðȫ룬ΪȷȫһλΪȫ벢ͼס"; + } + } + } + } + return "޷뱾Աϵ"; +} + +char *sasql_ItemPetLocked_Passwd( char *id, char *safepasswd ) +{ + char sqlstr[256]; + SQLCancel(hstmt); + sprintf(sqlstr,"update %s set SafePasswd='%s' where Name='%s'", config.SQL_INFOTABLE, safepasswd, id); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + return "ȫ޸ijɹƱİȫ룡"; + } + return "ȫ޸ʧܣ뱾Աϵ"; +} +#endif + +#ifdef _ONLINE_COST +char *sasql_OnlineCost( char *id, char *costpasswd ) +{ + char sqlstr[256]; + SQLCHAR szCostVal[32]={0}; + SQLCHAR szTemp[32]={0}; + SQLINTEGER cbCostVal; + SQLINTEGER cbTemp; + SQLCancel(hstmt); + + sprintf(sqlstr,"select `CostVal`, `check` from `OnlineCost` where CostPasswd = '%s'", costpasswd); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + if( SQL_SUCCESS == SQLFetch(hstmt) ){ + if(SQLGetData(hstmt, 1, SQL_C_CHAR, szCostVal, 50, &cbCostVal) == SQL_SUCCESS + && SQLGetData(hstmt, 2, SQL_C_CHAR, szTemp, 50, &cbTemp) == SQL_SUCCESS){ + if(atoi(szTemp) == 1){ + int costval = atoi(szCostVal); + int vippoint = sasql_add_vippoint(id, costval); + char token[256]; + sprintf(sqlstr,"update OnlineCost set cdkey='%s', CostTime=NOW(), `check`=0 where CostPasswd='%s'", id, costpasswd); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + log("ֵ%sѳֵ\n",costpasswd); + } + sprintf(token, "ֵѳɹֵֵΪ%dǰԱ%d", costval, vippoint); + return token; + }else{ + return "óֵʹùظʹã"; + } + }else{ + return "ֵʧܣóֵ벻ȷ"; + } + }else{ + return "Ҳÿţ뱾Աϵ"; + } + } + return "ֵʧܣ뱾Աϵ"; +} + +void sasql_OnlineCost_add( int cost ) +{ + char sqlstr[256]; + char CostPasswd[32]; + memset( CostPasswd, 0, sizeof( CostPasswd ) ); + int i, j; + for(i=0;i<100;i++){ + for(j=0;j<16;j++){ + CostPasswd[j++]=(rand() % 26) + 65; + CostPasswd[j]=(rand() % 10) + 48; + } + sprintf(sqlstr,"INSERT INTO OnlineCost (CostPasswd, CostVal) VALUES ('%s', %d)", CostPasswd, cost); + + rc = SQLExecDirect( hstmt, sqlstr, SQL_NTS); + check_return (rc,henv,hdbc,hstmt); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) + { + SQLCancel(hstmt); + } + } + printf("ɹ%dֵ%dijֵ\n", i, cost); + return ; +} +#endif + +#endif + diff --git a/石器时代服务器端最新完整源代码/Serv/saac/sasql_linux.c b/石器时代服务器端最新完整源代码/Serv/saac/sasql_linux.c new file mode 100644 index 0000000..63d31d9 --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/sasql_linux.c @@ -0,0 +1,967 @@ +#define _SASQL_C_ + +#include "version.h" + +#ifdef _SASQL// + +#include "main.h" +#include "sasql.h" +#include "util.h" +#include "md5.h" +#include + +MYSQL mysql; +MYSQL_RES *mysql_result; +MYSQL_ROW mysql_row; +MYSQL_FIELD *fields; + +typedef struct tagConfig +{ + char sql_IP[32]; + + int sql_Port; + + char sql_Port1[16]; + + char sql_ID[16]; + + char sql_PS[32]; + + char sql_DataBase[16]; + + char sql_Table[16]; + + char sql_LOCK[16]; + + char sql_NAME[16]; + + char sql_PASS[16]; + + int AutoReg; + + int uLoginDay; + + int openbackground; +}Config; + +Config config; + +static int readSqlConfig( char *path ) +{ + char buf[255]; + FILE *fp; + + fp = fopen( path , "r" ); + if( fp == NULL ){ return -2; } + + while( fgets( buf , sizeof( buf ) , fp )){ + char command[255]; + char param[255]; + chop(buf); + + easyGetTokenFromString( buf , 1 , command , sizeof( command )); + easyGetTokenFromString( buf , 2 , param , sizeof( param )); + + if( strcmp( command , "sql_IP" ) == 0 ){ + snprintf( config.sql_IP , sizeof( config.sql_IP) , param ); + printf("\nݿַ %s",config.sql_IP); + } else if( strcmp( command , "sql_Port" ) == 0 ){ + config.sql_Port = atoi( param ); + snprintf( config.sql_Port1 , sizeof( config.sql_Port1) , param ); + printf("\nݿ˿ڣ %d",config.sql_Port); + } else if( strcmp( command , "sql_ID" ) == 0 ){ + snprintf( config.sql_ID , sizeof( config.sql_ID) , param ); + printf("\nݿû %s",config.sql_ID); + } else if( strcmp( command , "sql_PS" ) == 0 ){ + snprintf( config.sql_PS , sizeof( config.sql_PS) , param ); + printf("\nݿ룺 %s",config.sql_PS); + } else if( strcmp( command , "sql_DataBase" ) == 0 ){ + snprintf( config.sql_DataBase , sizeof( config.sql_DataBase) , param ); + printf("\n½ݿ%s",config.sql_DataBase); + } else if( strcmp( command , "sql_Table" ) == 0 ){ + snprintf( config.sql_Table , sizeof( config.sql_Table) , param ); + printf("\nûϢ %s",config.sql_Table); + } else if( strcmp( command , "sql_LOCK" ) == 0 ){ + snprintf( config.sql_LOCK , sizeof( config.sql_LOCK) , param ); + printf("\nû %s",config.sql_LOCK); + } else if( strcmp( command , "sql_NAME" ) == 0 ){ + snprintf( config.sql_NAME , sizeof( config.sql_NAME) , param ); + printf("\n˺ֶƣ %s",config.sql_NAME); + } else if( strcmp( command , "sql_PASS" ) == 0 ){ + snprintf( config.sql_PASS , sizeof( config.sql_PASS) , param ); + printf("\nֶƣ %s",config.sql_PASS); + } else if( strcmp( command , "uLoginDay" ) == 0 ){ + config.uLoginDay = atoi( param ); + printf("\nֹ½ %d", config.uLoginDay); + } else if( strcmp( command , "openbackground" ) == 0 ){ + config.openbackground = atoi( param ); + if(config.openbackground == 1){ + printf("\n̨ܣ YES"); + }else{ + printf("\n̨ܣ NO"); + } + } else if( strcmp( command , "AutoReg" ) == 0 ){ + config.AutoReg = atoi( param ); + if(config.AutoReg){ + printf("\nԶע᣺YES"); + }else{ + printf("\nԶע᣺NO"); + } + } + } + fclose(fp); + return 0; +} + +BOOL sasql_init( void ) +{ + if( (mysql_init(&mysql) == NULL) & readSqlConfig("acserv.cf")) + { + printf("\nݿʼʧܣ"); + exit(1); + return FALSE; + } + + if( !mysql_real_connect( &mysql, + config.sql_IP, + config.sql_ID,//ʺ + config.sql_PS,// + config.sql_DataBase,//ѡϿ + config.sql_Port, + NULL, + 0 ) ) + { + printf("\nݿʧܣ\n"); + return FALSE; + } + + mysql_query(&mysql,"set names 'gbk'"); + printf("\nݿӳɹ\n"); + return TRUE; +} + +int sasql_mysql_query( char *sqlstr ) +{ + mysql_query(&mysql,"set names 'gbk'"); + return mysql_query(&mysql,sqlstr); +} + +void sasql_close( void ) +{ + mysql_close( &mysql ); +} + +BOOL sasql_ckeckStrint( char *str ) +{ + int i; + for(i=0;i 'z') && (str[i] < 'A' || str[i] > 'Z') && (str[i] < '0' || str[i] > '9') && (str[i] != '.') && (str[i] != '-')){ + return FALSE; + } + } + return TRUE; +} + +int sasql_query(char *nm, char *pas){ + + char sqlstr[1024]; + if(sasql_ckeckStrint(nm) == FALSE){ + printf("쳣ַû%s\n",nm); + return 3; + } + + //sprintf(sqlstr,"select `%s`, `salt` from %s where %s=BINARY'%s'",config.sql_PASS, config.sql_Table,config.sql_NAME,nm); + sprintf(sqlstr,"select `%s`,TO_DAYS( NOW( ) ) - TO_DAYS( LoginTime ) from %s where %s=BINARY'%s'",config.sql_PASS, config.sql_Table,config.sql_NAME,nm); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + char token[64]; + mysql_row=mysql_fetch_row(mysql_result); + strcpy(token, mysql_row[0]); +#ifdef _OLDPS_TO_MD5PS + if(strlen(mysql_row[0])>16 && strlen(pas) <= 16){ + if(strcmp(MD5String(pas),token) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } + }else if(strlen(pas)>16 && strlen(mysql_row[0]) <= 16){ + if(strcmp(MD5String(token),pas) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } + }else{ + if(strcmp(pas,token) == 0){ + return 1; + }else{ + // printf("û%s\n",nm); + return 2; + } + } +#else + if(strcmp(pas,token) == 0){ + return 1; + }else{ + printf("û%s\n",nm); + return 2; + } +#endif + }else{ + printf("û%sδעᣡ\n",nm); + return 3; + } + }else{ + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return 0; + } +} + + +#ifdef _SQL_BACKGROUND +BOOL sasql_online( char *ID, char *NM, char *IP, char *MAC, int flag ) +{ + if(config.openbackground == 1){ + if(ID!=NULL){ + if(sasql_ckeckStrint(ID) == FALSE){ + printf("쳣ַû%s\n",ID); + return TRUE; + } + } + + char sqlstr[256]; + if(flag==0) + sprintf(sqlstr,"update %s set Online=0 where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, ID); + else if(flag==1) + sprintf(sqlstr,"update %s set LoginTime=NOW(), IP='%s', Online=0 where %s=BINARY'%s'", config.sql_Table, IP, config.sql_NAME, ID); + else if(flag==2) + sprintf(sqlstr,"update %s set LoginTime=NOW(), OnlineName='%s', Online=1, Path='char/0x%x'where %s=BINARY'%s'", config.sql_Table, NM, getHash(ID) & 0xff, config.sql_NAME, ID); + else if(flag==3) + sprintf(sqlstr,"update %s set Online=0", config.sql_Table); + if(!sasql_mysql_query(sqlstr)){ + return TRUE; + } + printf("\nݿʧ%s\n", sqlstr); + } + return TRUE; +} +#endif + +#ifdef _SQL_REGISTER +BOOL sasql_register(char *id, char *ps) +{ + char sqlstr[256]; + if(config.AutoReg!=1)return FALSE; + + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַû%s\n",id); + return FALSE; + } + if(sasql_ckeckStrint(ps) == FALSE){ + printf("쳣ַϷ%s\n",ps); + return FALSE; + } + + +#ifdef _OLDPS_TO_MD5PS + sprintf(sqlstr,"INSERT INTO %s (%s,%s,RegTime,Path) VALUES (BINARY'%s','%s',NOW(),'char/0x%x')",config.sql_Table, config.sql_NAME, config.sql_PASS, id, MD5String(ps), getHash(id) & 0xff); +#else + sprintf(sqlstr,"INSERT INTO %s (%s,%s,RegTime,Path) VALUES (BINARY'%s','%s',NOW(),'char/0x%x')",config.sql_Table, config.sql_NAME, config.sql_PASS, id, ps, getHash(id) & 0xff); +#endif + + if(!sasql_mysql_query(sqlstr)){ + printf("\nûעɹ\n"); + return TRUE; + } + printf("\nûעʧܣ\n"); + return FALSE; +} +#endif + + +BOOL sasql_chehk_lock( char *idip ) +{ + if(sasql_ckeckStrint(idip) == FALSE){ + printf("쳣ַ%s\n",idip); + return FALSE; + } + char sqlstr[256]; + sprintf(sqlstr,"select * from `%s` where Name='%s'", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + return TRUE; + } + } + return FALSE; +} + +BOOL sasql_add_lock( char *idip ) +{ + if(sasql_ckeckStrint(idip) == FALSE){ + printf("쳣ַ%s\n",idip); + return FALSE; + } + char sqlstr[256]; + sprintf(sqlstr,"INSERT INTO `%s` (Name) VALUES (BINARY'%s')", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + printf("\n%sɹ\n",idip); + return TRUE; + } + return FALSE; +} + +BOOL sasql_del_lock( char *idip ) +{ + if(sasql_ckeckStrint(idip) == FALSE){ + printf("쳣ַ%s\n",idip); + return FALSE; + } + char sqlstr[256]; + sprintf(sqlstr,"delete from `%s` where Name=BINARY'%s'", config.sql_LOCK, idip); + if(!sasql_mysql_query(sqlstr)){ + printf("\n%sɹ\n",idip); + return TRUE; + } + return FALSE; +} + +#ifdef _NEW_VIP_SHOP +int sasql_query_point( char *name ) +{ + if(sasql_ckeckStrint(name) == FALSE){ + printf("쳣ַ%s\n",name); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, name); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + return atoi(mysql_row[0]); + } + } + return -1; +} + + +BOOL sasql_add_vippoint( char *ID, int point ) +{ + if(sasql_ckeckStrint(ID) == FALSE){ + printf("쳣ַ%s\n",ID); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select VipPoint from %s where %s=BINARY'%s'",config.sql_Table,config.sql_NAME,ID); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + point+=atoi(mysql_row[0]); + if(point < 0){ + printf("%sԱС0\n",ID); + return -1; + } + sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", config.sql_Table, point,config.sql_NAME, ID); + if(!sasql_mysql_query(sqlstr)){ + printf("û%sǰԱ%d\n",ID,point); + return point; + } + } + } + printf("޸%sԱʧܣ\n",ID); + return -1; +} + +BOOL sasql_add_Paypoint( char *ID, int point ) +{ + if(sasql_ckeckStrint(ID) == FALSE){ + printf("쳣ַ%s\n",ID); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select PayPoint from %s where %s=BINARY'%s'",config.sql_Table,config.sql_NAME,ID); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + point+=atoi(mysql_row[0]); + if(point < 0){ + printf("%sֵС0\n",ID); + return -1; + } + sprintf(sqlstr,"update %s set PayPoint=%d where %s=BINARY'%s'", config.sql_Table, point,config.sql_NAME, ID); + if(!sasql_mysql_query(sqlstr)){ + printf("û%sǰֵ%d\n",ID,point); + return point; + } + } + } + printf("޸%sֵʧܣ\n",ID); + return -1; +} + + +#endif + +#ifdef _ITEM_PET_LOCKED +char *sasql_ItemPetLocked( char *id, char *safepasswd ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַ%s\n",id); + return "޷뱾Աϵ"; + } + if(sasql_ckeckStrint(safepasswd) == FALSE){ + printf("쳣ַ%s\n",safepasswd); + return "޷뱾Աϵ"; + } + char sqlstr[256]; + sprintf(sqlstr,"select SafePasswd from `%s` where %s=BINARY'%s'", config.sql_Table, config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + if(strcmp(safepasswd, mysql_row[0])==0){ + return "ȫѾɹ"; + }else{ + return "󣬰ȫ޷⿪"; + } + }else{ + return "δðȫ룬ΪȷȫһλΪȫ벢ͼס"; + } + } + } + return "޷뱾Աϵ"; +} + +char *sasql_ItemPetLocked_Passwd( char *id, char *safepasswd ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַ%s\n",id); + return "ȫ޸ʧܣ뱾Աϵ"; + } + if(sasql_ckeckStrint(safepasswd) == FALSE){ + printf("쳣ַ%s\n",safepasswd); + return "ȫ޸ʧܣ뱾Աϵ"; + } + char sqlstr[256]; + sprintf(sqlstr,"select safepasswd from %s where %s=BINARY'%s'", config.sql_Table,config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + return "ȫѴ,޷ٽ޸ģ"; + }else{ + char sqlstr[256]; + sprintf(sqlstr,"update %s set SafePasswd=BINARY'%s' where %s=BINARY'%s'", config.sql_Table, safepasswd, config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + return "ȫ޸ijɹƱİȫ룡"; + } + return "ȫ޸ʧܣ뱾Աϵ"; + } + }else{ + return "˺ŲڰȫѴڣ"; + } + }else{ + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return "ȫ޸ʧܣ뱾Աϵ"; + } +} + +int sasql_ItemPetLocked_Char( char *id, char *safepasswd ) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַ%s\n",id); + return 0; + } + if(sasql_ckeckStrint(safepasswd) == FALSE){ + printf("쳣ַ%s\n",safepasswd); + return 0; + } + char sqlstr[256]; + sprintf(sqlstr,"select safepasswd from %s where %s=BINARY'%s'", config.sql_Table,config.sql_NAME, id); + + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if( mysql_row[0] != NULL && strlen(mysql_row[0])>0){ + if(strcmp(safepasswd,mysql_row[0]) == 0){ + return 1; + }else{ + // printf("û%sȫ\n",id); + return -1; + } + }else{ + return 0; + } + }else{ + printf("û%sδעᣡ\n",id); + return -1; + } + }else{ + printf("\nݿʧܣ\n"); + printf("ݿ..."); + sasql_close(); + sasql_init(); + printf("\n"); + return -1; + } +} +#endif + +#ifdef _ONLINE_COST +char *sasql_OnlineCost( char *id, char *costpasswd, int fmindex, char *fmname) +{ + if(sasql_ckeckStrint(id) == FALSE){ + printf("쳣ַ%s\n",id); + return "ֵʧܣ뱾Աϵ"; + } + if(sasql_ckeckStrint(costpasswd) == FALSE){ + printf("쳣ַ%s\n",costpasswd); + return "ֵʧܣ뱾Աϵ"; + } + char sqlstr[256]; + static char token[256]=""; + sprintf(sqlstr,"select `CostVal`, `PayVal`, `check` from `OnlineCost` where CostPasswd = BINARY'%s'", costpasswd); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(atoi(mysql_row[2]) == 1){ + int costval = atoi(mysql_row[0]); + int payval = atoi(mysql_row[1]); + int vippoint = sasql_add_vippoint(id, costval); + int paypoint = sasql_add_Paypoint(id, payval); + sprintf(sqlstr,"update OnlineCost set cdkey=BINARY'%s', CostTime=NOW(), `check`=0 where CostPasswd=BINARY'%s'", id, costpasswd); + if(!sasql_mysql_query(sqlstr)){ + log("ֵ%sѳֵ\n",costpasswd); + } + addFmPayPoint(fmindex, fmname, payval); + sprintf(token, "ֵѳɹֵֵΪ%dֵΪ%dǰԱ%dֵֹ%d", payval, costval, vippoint, paypoint); + return token; + }else{ + return "óֵʹùظʹã"; + } + }else{ + return "ֵʧܣóֵ벻ȷ"; + } + } + return "ֵʧܣ뱾Աϵ"; +} + +char *sasql_TransOnlineCost() +{ + char sqlstr[256]; + static char token[256]=""; + sprintf(sqlstr,"select `PayVal`, `cdkey` from `OnlineCost` where `check` = 0"); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + while((mysql_row = mysql_fetch_row(mysql_result))){ + int paycost = atoi(mysql_row[0]); + sprintf(sqlstr,"update %s set PayPoint=PayPoint + %d where %s=BINARY'%s'", config.sql_Table, paycost,config.sql_NAME, mysql_row[1]); + if(!sasql_mysql_query(sqlstr)){ + printf("û%sǰֵ%d\n",mysql_row[1],paycost); + } + } + }else{ + return "ʧ"; + } + } + return "ֵʧܣ뱾Աϵ"; +} + +void sasql_OnlineCost_add( int cost, int num, int point) +{ + char sqlstr[256]; + char CostPasswd[32]; + memset( CostPasswd, 0, sizeof( CostPasswd ) ); + int i, j, k=0; + for(i=0;i0){ + mysql_row=mysql_fetch_row(mysql_result); + if(atoi(mysql_row[1]) == 1){ + char *coststr = mysql_row[0]; +#ifdef _SQL_BUY_FUNC_ONE_CDKEY + if(costpasswd[0]=='1'){ + sprintf(sqlstr,"select count(*) from OnlineBuy where `CostStr`='%s' and `cdkey`=BINARY'%s'", coststr, id); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + if(atoi(mysql_row[0])>0){ + return "ͬ͵ĵ߿ÿʺŽȡһΣ"; + } + } + } + } +#endif + + sprintf(sqlstr,"update OnlineBuy set cdkey=BINARY'%s', CostTime=NOW(), `check`=0 where CostPasswd=BINARY'%s'", id, costpasswd); + if(!sasql_mysql_query(sqlstr)){ + log("%sȡ\n",costpasswd); + } + sprintf(token, "%c|%s", costpasswd[0], coststr); + + return token; + }else{ + return "ʹùظʹã"; + } + }else{ + return "ʧܣ벻ȷ"; + } + } + return "ʧܣ뱾Աϵ"; +} + +void sasql_OnlineBuy_add( char *coststr, int type, int num ) +{ + char sqlstr[256]; + char CostPasswd[32]; + int i, j, k=0; + for(i=0;i= 2){ + printf("ɹ%dʯ\n", k); + } + return ; +} + +#endif + + +int sasql_onlinenum( char *MAC ) +{ + char sqlstr[256]; + sprintf(sqlstr,"select count(*) from %s where Online=1 and MAC='%s'",config.sql_Table,MAC); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + return atoi(mysql_row[0]); + } + } + return 0; +} + +#ifdef _FORMULATE_AUTO_PK +BOOL sasql_add_FormulateAutoPk( char *ID, int point ) +{ + if(sasql_ckeckStrint(ID) == FALSE){ + printf("쳣ַ%s\n",ID); + return -1; + } + + char sqlstr[256]; + sprintf(sqlstr,"select PKPoint from %s where %s=BINARY'%s'",config.sql_Table,config.sql_NAME,ID); + if(!sasql_mysql_query(sqlstr)){ + int num_row=0; + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + if(num_row>0){ + mysql_row=mysql_fetch_row(mysql_result); + point+=atoi(mysql_row[0]); + if(point < 0){ + return -1; + } + sprintf(sqlstr,"update %s set PKPoint=%d where %s=BINARY'%s'", config.sql_Table, point,config.sql_NAME, ID); + if(!sasql_mysql_query(sqlstr)){ + return point; + } + } + } + return -1; +} +#endif + +#ifdef _OLDPS_TO_MD5PS +void sasql_OldpsToMd5ps() +{ + char sqlstr[256]; + sprintf(sqlstr,"select %s, %s from %s",config.sql_NAME, config.sql_PASS, config.sql_Table); + if(!sasql_mysql_query(sqlstr)){ + mysql_free_result(mysql_result); + mysql_result=mysql_store_result(&mysql); + printf(" ת˺ ԭ תMD5\n"); + while((mysql_row = mysql_fetch_row(mysql_result))){ + char * name = mysql_row[0]; + char * ps = mysql_row[1]; + if(strlen(ps)<=16) { + sprintf(sqlstr,"update %s set %s=BINARY'%s' where %s=BINARY'%s'", config.sql_Table, config.sql_PASS, MD5String(ps),config.sql_NAME, name); + if(!sasql_mysql_query(sqlstr)){ + printf("%16s %16s %32s\n", name, ps, MD5String(ps)); + } + } + } + } +} +#endif + + +#ifdef _CHARADATA_SAVE_SQL +void sasql_charadata_Save(char *id, char* table, char *data, int saveindex, int flag) +{ + if(strlen(data)==0)return; + + char sqlstr[1024*16]; + + if(flag==INSERT){ + sprintf(sqlstr, "INSERT INTO %s VALUES %s" , table, data); + }else if(flag==SELECT){ + }else if(flag==UPDATE){ + sprintf(sqlstr, "UPDATE %s set %s WHERE CHAR_CDKEY=BINARY'%s' and CHAR_SAVEINDEX=%d" , table, data, id, saveindex); + }else if(flag==DELETE){ + sprintf(sqlstr, "DELETE FROM %s WHERE CHAR_CDKEY=BINARY'%s' and CHAR_SAVEINDEX=%d" , table, id, saveindex); + } + + if(!mysql_query(&mysql,sqlstr)){ + if(flag==DELETE){ + sasql_charadata_Save(id, table, data, saveindex, INSERT); + } + return; + }else{ + printf(table); + if(flag==INSERT){ + printf(" INSERT error\n"); + }else if(flag==SELECT){ + printf(" SELECT error\n"); + }else if(flag==UPDATE){ + printf(" UPDATE error\n"); + }else if(flag==DELETE){ + printf(" DELETE error\n"); + } + } +} + +#endif + +void sasql_CleanCdkey(int date) +{ + char sqlstr[256]; + + sprintf(sqlstr, "select `%s` from `%s` where TO_DAYS( NOW( ) ) - TO_DAYS( LoginTime ) > %d", config.sql_NAME, config.sql_Table, date); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + int GroupNum=0; + int ServerMaxNum=0; + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + mysql_free_result(mysql_result); + if(num_row > 0){ + while((mysql_row = mysql_fetch_row(mysql_result))){ + char tmp[256] = ""; + char charId[256]; + + strcpy( charId, mysql_row[0] ); + + int hash = 0; + int i; + for( i=0; i& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm char_sleep/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm log/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm mail/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + + + } + } + } + + sprintf(sqlstr, "DELETE FROM `%s` WHERE TO_DAYS( NOW( ) ) - TO_DAYS( LoginTime ) > %d" , config.sql_Table, date); + mysql_query(&mysql,sqlstr); + printf("\n"); + return; +} + +void sasql_CleanLockCdkey() +{ + char sqlstr[256]; + + sprintf(sqlstr, "select `%s` from `%s` where `%s` LIKE '%!%'", config.sql_NAME, config.sql_Table, config.sql_PASS); + + if(!mysql_query(&mysql,sqlstr)){ + int num_row=0; + int GroupNum=0; + int ServerMaxNum=0; + mysql_result=mysql_store_result(&mysql); + num_row=mysql_num_rows(mysql_result); + mysql_free_result(mysql_result); + if(num_row > 0){ + while((mysql_row = mysql_fetch_row(mysql_result))){ + char tmp[256] = ""; + char charId[256]; + + strcpy( charId, mysql_row[0] ); + + int hash = 0; + int i; + for( i=0; i& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm char_sleep/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm log/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + sprintf(tmp, "rm mail/0x%x/%s.* >& /dev/null\n", hash, charId); + system(tmp); + + + } + } + } + + sprintf(sqlstr, "DELETE FROM `%s` WHERE `%s` LIKE '%!%'", config.sql_Table, config.sql_PASS); + mysql_query(&mysql,sqlstr); + printf("\n"); + return; +} + +BOOL sasql_craete_userinfo( void ) +{ + return FALSE; +} + +BOOL sasql_craete_lock( void ) +{ + return FALSE; +} + +#endif diff --git a/石器时代服务器端最新完整源代码/Serv/saac/util.c b/石器时代服务器端最新完整源代码/Serv/saac/util.c new file mode 100644 index 0000000..f30cf2f --- /dev/null +++ b/石器时代服务器端最新完整源代码/Serv/saac/util.c @@ -0,0 +1,593 @@ +#define _UTIL_C_ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "util.h" + +#define min( x,y ) ({typeof(x) __x=(x),__y=(y);(__x < __y) ? __x : __y; }) +#define max( x,y ) ({typeof(x) __x=(x),__y=(y);(__x < __y) ? __y : __x; }) +#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) ) +#define PRIME 211 +int hashpjw ( char* s ) +{ + char *p; + unsigned int h= 0 ,g; + for( p = s ; *p ; p ++ ){ + h = ( h<< 4 ) + (*p); + if( (g = h & 0xf0000000) != 0){ + h = h ^ (g>>24); + h = h ^ g; + } + } + return h % PRIME; +} + +int getHash ( char* s ) +{ + int i; + int h=0; + + for(i=0;; i++){ + if( s[i] == 0 ){ + break; + } + h += s[i]; + } + return h; +} + +void easyGetTokenFromString( char *src,int count,char*output,int len ) +{ + int i; + int counter = 0; + + if( len <= 0 )return; + +#define ISSPACETAB( c ) ( (c) == ' ' || (c) == '\t' ) + + for(i=0;;i++){ + if( src[i]=='\0'){ + output[0] = '\0'; + return; + } + if( i > 0 && ! ISSPACETAB( src[i-1] ) && + ! ISSPACETAB( src[i] ) ){ + continue; + } + + if( ! ISSPACETAB( src[i]) ){ + counter++; + if( counter == count){ + int j; + for(j=0;j= sizeofdest ) break; + if( IS_2BYTEWORD( src[i] ) ){ + if( destindex + 2 >= sizeofdest ) break; + dest[destindex] = src[i]; + dest[destindex+1] = src[i+1]; + destindex += 2; + i ++; + continue; + } + + for( j = 0; j= sizeofdest ) + /* '\0'лԻئмƥƥԻ */ + break; + + /* // ʣ ë + if( IS_2BYTEWORD( src[i] ) ){ + // ʣ֣۹б£ + // ׷ƨƾئئ + // ˪ + if( destindex + 2 >= sizeofdest )break; + + dest[destindex] = src[i]; + dest[destindex+1] = src[i+1]; + destindex += 2; + i ++; + continue; + } + */ + for( j = 0; j= destlen ){ + return -1; + } else { + strcat( dest, append ); + } + return 0; +} + +char *chop( char *s ) +{ + int l = strlen(s); + if( l >= 1 ){ + s[l-1]=0; + } + return s; +} + +// CoolFish: Family 2001/5/30 + +/*void easyGetTokenFromBuf(char *src, char delim, int count, char *output, int len) +{ + int i; + int counter = 0; + int wordflag = 0; + + if( len <= 0 ) return; + + #define ISSEPARATE( c ) ((c) == delim) + + for( i=0; ; i++){ + if( src[i] == '\0' ){ + output[0] = '\0'; + return; + } + if(IS_2BYTEWORD(src[i])){ + if( i>0 && wordflag == 1 ){ + i++; + wordflag = 1; + continue; + } + if( i>0 && !ISSEPARATE(src[i-1]) && !ISSEPARATE(src[i])){ + i++; + wordflag = 1; + continue; + } + wordflag = 1; + }else{ + if( i>0 && wordflag ){ + wordflag = 0; + continue; + } + if( i>0 && !ISSEPARATE(src[i-1]) && !ISSEPARATE(src[i])){ + wordflag = 0; + continue; + } + wordflag = 0; + } + if( !ISSEPARATE(src[i]) ){ + counter++; + if( counter == count ){ + int j; + for ( j=0; j 0 ){ + char* d = dest; + const char* s = src; + int i; + for( i=0; i=n ){ + *(d+i-1)='\0'; + break; + } + *(d+i) = *(s+i); + }else + *(d+i) = *(s+i); + } + } + return dest; +} + +void strncpysafe( char* dest , const size_t n , + const char* src ,const int length ) +{ + /* + * src dest length + * strcpy, strncpy ƥ dest Ի ڻ + * ݱ,ƹ½ʧͱ. + * ƥstrlen( src ) length лõ + * ( ˱) dest ë ͻ + * strcpysafe Ԫë£ + */ + + int Short; + Short = min( strlen( src ) , length ); + + /* NULL ٯ ë ʤ */ + if( n < Short + 1 ){ + /* + * 뻥Իئмƥ n - 1(NULL ٯ) + * ƥ strncpy ë + */ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + + }else if( n <= 0 ){ + return; + }else{ + /* + * 뷴бؤ¼ƥ Short ƥstrncpyë + * ئ src 巴 Short Ӯ NULL ئмƥ + * dest 巴 ܰƻʣ + */ + + strncpy2( dest , src , Short ); + dest[Short]= '\0'; + + } +} + +void strcpysafe( char* dest ,size_t n ,const char* src ) +{ + /* + * src dest . + * strcpy, strncpy ƥ dest Ի ڻ + * ݱ,ƹ½ʧͱ. + * ľë ʲб, strncpy ؤ» strlen( src ) n Ի + * ݱ巴, dest NULL ٯ練ئئ. + * + * ׻Ȼ dest Ի src õӮݱ巴 + * n-1 ƥ strncpy ë. ݷ + * + * n ݷƾئ¼ƥ ݷ ئУ + * + */ + // Nuke +1 (08/25): Danger if src=0 + if (!src) { + *dest = '\0'; + return; + } + if( n <= 0 ) /* ئ */ + return; + + /* ƥ n >= 1 */ + /* NULL ٯë ƻ ʤ */ + else if( n < strlen( src ) + 1 ){ + /* + * 뻥Իئмƥ n - 1(NULL ٯ) + * ƥ strncpy ë + */ + strncpy2( dest , src , n-1 ); + dest[n-1]='\0'; + }else + strcpy( dest , src ); + +} + +char * ScanOneByte( char *src, char delim ) +{ + // Nuke + if (!src) return NULL; + + // ٯ ئئƥ + for( ;src[0] != '\0'; src ++ ){ + if( IS_2BYTEWORD( src[0] ) ){ + // ʣ֣۹б£ + // ׷ƨƾئئ + if( src[1] != 0 ){ + src ++; + } + continue; + } + // ʣף۳ƥ޼ ٯ ʤ + if( src[0] == delim ){ + return src; + } + } + // έئף + return NULL; +} + +int easyGetTokenFromBuf( char* src ,char* delim ,int count, char* output , int len ) +{//ttom this function all change,copy from the second + int i; /* */ + int length =0; /* Ի ٯ Ӯ */ + int addlen=0; /* ľӮ */ + int oneByteMode = 0; /* ƹ񾮣 */ + + if(strlen(src)==0)return 0; + + if( strlen( delim ) == 1 ){ // 񻥨ئըƹ + oneByteMode = 1;// ˨ ٯئ + } + for( i = 0 ; i < count ; i ++ ){ + char* last; + src += addlen;/* ĹӮë */ + + if( oneByteMode ){ + // ƹճƥ + last = ScanOneByte( src, delim[0] ); + }else{ + last = strstr( src , delim ); /* έ */ + } + if( last == NULL ){ + /* + * Ĺئ׼ƥͻƻ return + */ + strcpysafe( output , len, src ); + + if( i == count - 1 ) + /*нﵤĹ*/ + return 1; + + /*Ĺئ*/ + return 0; + } + + /* + * Ĺ ټ ëƻ + * Իľ ٯ Ӯ + */ + length = last - src; + + /* + * ݼ󼰿бĹӮ delim Ӯëƻ + */ + addlen= length + strlen( delim ); + } + strncpysafe( output, len , src,length ); + + return 1; +} + diff --git a/说明.txt b/说明.txt new file mode 100644 index 0000000..1d2829a --- /dev/null +++ b/说明.txt @@ -0,0 +1,4 @@ +1dataлٷ1.82-8.5汾 +2ʹcentos32λϵͳ +3ͻ˽ʹvs2015vs2017б +빱ˣС \ No newline at end of file